home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d01xx / d0128.lha / MRBackup / UserPrefs.c < prev   
C/C++ Source or Header  |  1988-01-02  |  4KB  |  208 lines

  1. /* MRBackup user preferences processing.
  2.  * Filename:    UserPrefs.c
  3.  * Date:        08/23/87
  4.  */
  5.  
  6. #include "MRBackup.h"
  7.  
  8. char *fgets();
  9.  
  10. extern struct Gadget backpathgad;
  11. extern struct Gadget excludepathgad;
  12. extern struct Gadget homepathgad;
  13. extern struct Gadget listpathgad;
  14. extern struct Requester *pathrequest;
  15. extern struct Window *pathwindow;
  16.  
  17. #define KEYMAX        20                /* max length of a keyword */
  18. #define NKEYWORD    7                /* number of keywords supported */
  19. #define PREFERENCES_FILE "S:MRBackup.init"
  20.  
  21. #define KW_HOME            0
  22. #define KW_BACKUP        1
  23. #define KW_LIST            2
  24. #define KW_EXCLUDE        3
  25. #define KW_COMPRESSION    4
  26. #define KW_LISTING      5
  27. #define KW_SPEECH        6
  28.  
  29. static char *keywords[NKEYWORD] = {
  30.     "home", "backup", "list", "exclude", 
  31.     "compression", "listing", "speech"
  32.     };
  33.  
  34. /* Process the user preferences file. */
  35.  
  36. GetUserPrefs()
  37. {
  38.     char c;
  39.     USHORT i;
  40.     char keyword[KEYMAX+1];
  41.     short keyindex;
  42.     USHORT keyleng;
  43.  
  44.     FILE *prefs;
  45.     char s[81];
  46.     char *s1, *s2, *s3;
  47.  
  48.     if (!(prefs = fopen(PREFERENCES_FILE,"r"))) {
  49.         WriteConsole("I couldn't get your preferences.\n");
  50.         return;
  51.     }
  52.  
  53.     while (fgets(s, 80, prefs)) {
  54.         if (*s == '#') continue;
  55.         WriteConsole(s);
  56.         s1 = s;
  57.         keyleng = 0;
  58.         while ((c = *s1++) && isalpha(c)) {
  59.             if (keyleng < KEYMAX) keyword[keyleng++] = tolower(c);
  60.             else {
  61. badkey:
  62.                 WriteConsole("Keyword error in preferences file.\n");
  63. err:
  64.                 goto done;
  65.             }
  66.         }
  67.         keyword[keyleng] = '\0';
  68.         for (keyindex = -1, i = 0; i < NKEYWORD; ++i) {
  69.             if (!strcmp(keyword, keywords[i])) {
  70.                 keyindex = i;        /* found it */
  71.                 break;
  72.             }
  73.         }
  74.         if (keyindex < 0) goto badkey;
  75.         while (c == ' ') c = *s1++;
  76.         if (c != '=') {
  77. badsyn:
  78.             WriteConsole("Syntax error in preferences file.\n");
  79.             goto done;
  80.         }
  81.  
  82.         /* Get the parameter field, minus any leading or trailing
  83.          * blanks.
  84.          */
  85.  
  86.         while ((c = *s1) == ' ') ++s1; /* skip leading blanks */
  87.         /* Delete trailing blanks. */
  88.         s2 = s3 = s1;
  89.         while (c && c != '\n') {
  90.             if (c != ' ') s2 = s3;     /* record non-blank end of string */
  91.             c = *s3++;
  92.         }
  93.         *s2 = '\0';                    /* truncate the string here */
  94.         SetUserPref(keyindex, s1);
  95.     }
  96. done:
  97.     fclose(prefs);
  98. }
  99.  
  100. /* Save the current program settings in the user preferences file. */
  101.  
  102. PutUserPrefs()
  103. {
  104.     WriteConsole("PutUserPrefs() is not implemented\n");
  105. }
  106.  
  107. /* Set/Clear checkmarks according to the item being set.  This routine
  108.  * is VERY application specific and assumes that the affected menu
  109.  * items are 
  110.  *                1. grouped in pairs (on/off)
  111.  *                2. adjacent (item, item+1)
  112.  *                3. ordered in on, off order (Listing, No Listing)
  113.  */
  114.  
  115. BOOL 
  116. SetMenuItem(item, value)
  117.     USHORT item; char *value;
  118. {
  119.     BOOL boolean;
  120.     LONG excludebits, excludemask;
  121.     LONG menu1, menu2;
  122.     struct MenuItem *item1, *item2;
  123.     short i;
  124.  
  125.     /* Get pointers and menu numbers for the affected items. */
  126.  
  127.     menu1 = SHIFTITEM((long) item) | SHIFTMENU((long) MENU_FLAGS);
  128.     item1 = ItemAddress(&Titles[0], menu1);
  129.  
  130.     menu2 = SHIFTITEM((long) item + 1) | SHIFTMENU((long) MENU_FLAGS);
  131.     item2 = ItemAddress(&Titles[0], menu2);
  132.  
  133.     if (item1 == NULL || item2 == NULL) {
  134.         WriteConsole("Null menu item in SetMenuItem - call Mark!!\n");
  135.         return false;
  136.     }
  137.  
  138.     boolean = ( tolower(*value) == 'y' );
  139.     if (boolean) {                /* true? */
  140.         item1->Flags |= CHECKED;
  141.         item2->Flags &= ~CHECKED;
  142.     }
  143.     else {                        /* false */
  144.         item1->Flags &= ~CHECKED;
  145.         item2->Flags |= CHECKED;
  146.     }
  147.     return boolean;
  148. }
  149.  
  150. void
  151. SetStringGadget(gadget, value)
  152.     struct Gadget *gadget; char *value;
  153. {
  154.     UBYTE *gs;                            /* pointer to gadget string */
  155.  
  156.     RemoveGadget(pathwindow, gadget);
  157.     gs = (UBYTE *) GadgetString(gadget);
  158.     strcpy(gs, value);
  159.     ResetStringInfo(gadget->SpecialInfo);
  160.     AddGadget(pathwindow, gadget, -1L);
  161.     DoGadget(pathwindow, GADGETUP, gadget);    /* simulate GADGETUP */
  162. }
  163.  
  164. /* Set one user preference item. 
  165.  * Called with:
  166.  *        kw:            keyword index
  167.  *        parm:        parameter string
  168.  */
  169.  
  170. SetUserPref(kw, parm)
  171.     USHORT kw; char *parm;
  172. {
  173.  
  174.     switch (kw) {
  175.     case KW_HOME:
  176.         SetStringGadget(&homepathgad, parm);
  177.         break;
  178.  
  179.     case KW_BACKUP:
  180.         SetStringGadget(&backpathgad, parm);
  181.         break;
  182.  
  183.     case KW_LIST:
  184.         SetStringGadget(&listpathgad, parm);
  185.         break;
  186.  
  187.     case KW_LISTING:
  188.         do_listing = SetMenuItem(ITEM_LIST, parm);
  189.         break;
  190.  
  191.     case KW_EXCLUDE:
  192.         SetStringGadget(&excludepathgad, parm);
  193.         break;
  194.  
  195.     case KW_COMPRESSION:
  196.         do_compress = SetMenuItem(ITEM_COMPRESS, parm);
  197.         break;
  198.  
  199.     case KW_SPEECH:
  200.         do_speech = SetMenuItem(ITEM_SPEECH, parm);
  201.         break;
  202.  
  203.     default:
  204.         break;
  205.     }
  206. }
  207.  
  208.