home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 06 / dflat3 / config.c < prev    next >
Text File  |  1991-05-19  |  5KB  |  140 lines

  1. /* ------------- config.c ------------- */
  2.  
  3. #include <conio.h>
  4. #include <string.h>
  5. #include "dflat.h"
  6.  
  7. /* ----- default colors for color video system ----- */
  8. struct colors color = {
  9.     LIGHTGRAY, BLUE,  /* Application   */
  10.     LIGHTGRAY, BLACK, /* Normal        */
  11.     BLACK, CYAN,      /* Button        */
  12.     WHITE, CYAN,      /* ButtonSel     */
  13.     LIGHTGRAY, BLUE,  /* Dialog        */
  14.     YELLOW, RED,      /* ErrorBox      */
  15.     BLACK, LIGHTGRAY, /* MessageBox    */
  16.     BLACK, LIGHTGRAY, /* HelpBox       */
  17.     WHITE, CYAN,      /* InFocusTitle  */
  18.     BLACK, CYAN,      /* Title         */
  19.     GREEN, LIGHTGRAY, /* Dummy         */
  20.     BLACK, LIGHTGRAY, /* TextBox       */
  21.     LIGHTGRAY, BLACK, /* TextBoxSel    */
  22.     LIGHTGRAY, BLUE,  /* TextBoxFrame  */
  23.     BLACK, LIGHTGRAY, /* ListBox       */
  24.     LIGHTGRAY, BLACK, /* ListBoxSel    */
  25.     LIGHTGRAY, BLUE,  /* ListBoxFrame  */
  26.     BLACK, LIGHTGRAY, /* EditBox       */
  27.     LIGHTGRAY, BLACK, /* EditBoxSel    */
  28.     LIGHTGRAY, BLUE,  /* EditBoxFrame  */
  29.     BLACK, LIGHTGRAY, /* MenuBar       */
  30.     BLACK, CYAN,      /* MenuBarSel    */
  31.     BLACK, CYAN,      /* PopDown       */
  32.     BLACK, LIGHTGRAY, /* PopDownSel    */
  33.     DARKGRAY,         /* InactiveSelFG */
  34.     RED               /* ShortCutFG    */
  35. };
  36.  
  37. /* ----- default colors for mono video system ----- */
  38. struct colors bw = {
  39.     LIGHTGRAY, BLACK, /* Application   */
  40.     LIGHTGRAY, BLACK, /* Normal        */
  41.     BLACK, LIGHTGRAY, /* Button        */
  42.     WHITE, LIGHTGRAY, /* ButtonSel     */
  43.     LIGHTGRAY, BLACK, /* Dialog        */
  44.     LIGHTGRAY, BLACK, /* ErrorBox      */
  45.     LIGHTGRAY, BLACK, /* MessageBox    */
  46.     BLACK, LIGHTGRAY, /* HelpBox       */
  47.     BLACK, LIGHTGRAY, /* InFocusTitle  */
  48.     BLACK, LIGHTGRAY, /* Title         */
  49.     BLACK, LIGHTGRAY, /* Dummy         */
  50.     LIGHTGRAY, BLACK, /* TextBox       */
  51.     BLACK, LIGHTGRAY, /* TextBoxSel    */
  52.     LIGHTGRAY, BLACK, /* TextBoxFrame  */
  53.     LIGHTGRAY, BLACK, /* ListBox       */
  54.     BLACK, LIGHTGRAY, /* ListBoxSel    */
  55.     LIGHTGRAY, BLACK, /* ListBoxFrame  */
  56.     LIGHTGRAY, BLACK, /* EditBox       */
  57.     BLACK, LIGHTGRAY, /* EditBoxSel    */
  58.     LIGHTGRAY, BLACK, /* EditBoxFrame  */
  59.     LIGHTGRAY, BLACK, /* MenuBar       */
  60.     BLACK, LIGHTGRAY, /* MenuBarSel    */
  61.     BLACK, LIGHTGRAY, /* PopDown       */
  62.     LIGHTGRAY, BLACK, /* PopDownSel    */
  63.     DARKGRAY,         /* InactiveSelFG */
  64.     WHITE             /* ShortCutFG    */
  65. };
  66.  
  67. /* ----- default colors for reverse mono video ----- */
  68. struct colors reverse = {
  69.     BLACK, LIGHTGRAY, /* Application   */
  70.     BLACK, LIGHTGRAY, /* Normal        */
  71.     LIGHTGRAY, BLACK, /* Button        */
  72.     WHITE, LIGHTGRAY, /* ButtonSel     */
  73.     BLACK, LIGHTGRAY, /* Dialog        */
  74.     BLACK, LIGHTGRAY, /* ErrorBox      */
  75.     BLACK, LIGHTGRAY, /* MessageBox    */
  76.     LIGHTGRAY, BLACK, /* HelpBox       */
  77.     LIGHTGRAY, BLACK, /* InFocusTitle  */
  78.     LIGHTGRAY, BLACK, /* Title         */
  79.     LIGHTGRAY, BLACK, /* Dummy         */
  80.     BLACK, LIGHTGRAY, /* TextBox       */
  81.     LIGHTGRAY, BLACK, /* TextBoxSel    */
  82.     BLACK, LIGHTGRAY, /* TextBoxFrame  */
  83.     BLACK, LIGHTGRAY, /* ListBox       */
  84.     LIGHTGRAY, BLACK, /* ListBoxSel    */
  85.     BLACK, LIGHTGRAY, /* ListBoxFrame  */
  86.     BLACK, LIGHTGRAY, /* EditBox       */
  87.     LIGHTGRAY, BLACK, /* EditBoxSel    */
  88.     BLACK, LIGHTGRAY, /* EditBoxFrame  */
  89.     BLACK, LIGHTGRAY, /* MenuBar       */
  90.     LIGHTGRAY, BLACK, /* MenuBarSel    */
  91.     LIGHTGRAY, BLACK, /* PopDown       */
  92.     BLACK, LIGHTGRAY, /* PopDownSel    */
  93.     DARKGRAY,         /* InactiveSelFG */
  94.     WHITE             /* ShortCutFG    */
  95. };
  96.  
  97. #define SIGNATURE DFLAT_APPLICATION " " VERSION
  98.  
  99. /* ------ default configuration values ------- */
  100. CONFIG cfg = {
  101.     SIGNATURE,
  102.     0,               /* Color                       */
  103.     TRUE,            /* Editor Insert Mode          */
  104.     4,               /* Editor tab stops            */
  105.     TRUE,            /* Editor word wrap            */
  106.     TRUE,            /* Application Border          */
  107.     TRUE,            /* Application Title           */
  108.     TRUE,            /* Textured application window */
  109.     25               /* Number of screen lines      */
  110. };
  111.  
  112. /* ------ load a configuration file from disk ------- */
  113. int LoadConfig(void)
  114. {
  115.     FILE *fp = fopen(DFLAT_APPLICATION ".cfg", "rb");
  116.     if (fp != NULL)    {
  117.         fread(cfg.version, sizeof cfg.version+1, 1, fp);
  118.         if (strcmp(cfg.version, SIGNATURE) == 0)    {
  119.             fseek(fp, 0L, SEEK_SET);
  120.             fread(&cfg, sizeof(CONFIG), 1, fp);
  121.         }
  122.         else
  123.             strcpy(cfg.version, SIGNATURE);
  124.         fclose(fp);
  125.     }
  126.     return fp != NULL;
  127. }
  128.  
  129. /* ------ save a configuration file to disk ------- */
  130. void SaveConfig(void)
  131. {
  132.     FILE *fp = fopen(DFLAT_APPLICATION ".cfg", "wb");
  133.     if (fp != NULL)    {
  134.         cfg.InsertMode = GetCommandToggle(MainMenu, ID_INSERT);
  135.         cfg.WordWrap = GetCommandToggle(MainMenu, ID_WRAP);
  136.         fwrite(&cfg, sizeof(CONFIG), 1, fp);
  137.         fclose(fp);
  138.     }
  139. }
  140.