home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / mincom15.zip / rwconf.c < prev    next >
C/C++ Source or Header  |  1993-10-09  |  5KB  |  198 lines

  1. /*
  2.  * This file is part of the Minicom Communications Program,
  3.  * written by Miquel van Smoorenburg 1991/1992/1993.
  4.  *
  5.  * rwconf.c    - routines to deal with ASCII configuration files.
  6.  *
  7.  */
  8. #include <string.h>
  9. #undef NULL
  10. #include <stdio.h>
  11. #include "config.h"
  12. #include "configsym.h"
  13.  
  14. #define ADM_CHANGE    1
  15. #define USR_CHANGE    2
  16.  
  17. #ifdef _ACK
  18. /*
  19.  * The Minix ACK compiler has problems with the initialization of
  20.  * fixed - size character arrays, such as the 'value[64]' array in
  21.  * the struct mpars. This array is _not_ given a length of 64, but
  22.  * the lenght of the initialization string - ofcourse this screws
  23.  * up the struct beyond human understanding :-).
  24.  * Therefore we invented a new structure, and in readpars() we copy
  25.  * the values to the (until then uninitialized) struct mpars...
  26.  */
  27. struct pars mpars[63];
  28. struct {
  29.   char *value;
  30.   int flags;
  31.   char *desc;
  32. } tmppars[] = {
  33. #else
  34. struct pars mpars[] = {
  35. #endif
  36.   /* Protocols */
  37.   /* Warning: minicom assumes the first 12 entries are these proto's ! */
  38.   { "YUNYzmodem",    PUBLIC,   "pname1" },
  39.   { "YUNYymodem",    PUBLIC,   "pname2" },
  40.   { "YUNYxmodem",    PUBLIC,   "pname3" },
  41.   { "NDNYzmodem",    PUBLIC,   "pname4" },
  42.   { "NDNYymodem",    PUBLIC,   "pname5" },
  43.   { "YDNYxmodem",    PUBLIC,   "pname6" },
  44.   { "YUYNkermit",    PUBLIC,   "pname7" },
  45.   { "NDYNkermit",    PUBLIC,   "pname8" },
  46.   { "",            PUBLIC,   "pname9" },
  47.   { "",            PUBLIC,   "pname10" },
  48.   { "",            PUBLIC,   "pname11" },
  49.   { "",            PUBLIC,   "pname12" },
  50.   { "/usr/bin/sz -vv",    PUBLIC,   "pprog1" },
  51.   { "/usr/bin/sb -vv",    PUBLIC,   "pprog2" },
  52.   { "/usr/bin/sx -vv",    PUBLIC,   "pprog3" },
  53.   { "/usr/bin/rz -vv",    PUBLIC,   "pprog4" },
  54.   { "/usr/bin/rb -vv",    PUBLIC,   "pprog5" },
  55.   { "/usr/bin/rx -vv",    PUBLIC,   "pprog6" },
  56.   { "/usr/bin/kermit -i -l %l -s", PUBLIC, "pprog7" },
  57.   { "/usr/bin/kermit -i -l %l -r", PUBLIC, "pprog8" },
  58.   { "",            PUBLIC,   "pprog9" },
  59.   { "",            PUBLIC,   "pprog10" },
  60.   { "",            PUBLIC,   "pprog11" },
  61.   { "",            PUBLIC,   "pprog12" },
  62.   /* Serial port & friends */
  63.   { DFL_PORT,        PRIVATE,  "port" },
  64.   { CALLIN,        PRIVATE,  "callin" },
  65.   { CALLOUT,        PRIVATE,  "callout" },
  66.   { UUCPLOCK,        PRIVATE,  "lock" },
  67.   { DEF_BAUD,        PUBLIC,   "baudrate" },
  68.   { "8",        PUBLIC,   "bits" },
  69.   { "N",        PUBLIC,   "parity" },
  70.   /* Kermit the frog */
  71.   { KERMIT,        PRIVATE,  "kermit" },
  72.   { "Yes",        PRIVATE,  "kermallow" },
  73.   { "No",        PRIVATE,  "kermreal" },
  74.   { "3",        PUBLIC,   "colusage" },
  75.   /* The script program */
  76.   { "",            PUBLIC,   "scriptprog" },
  77.   /* Modem parameters */
  78.   { "^MAT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0^M",   PUBLIC,   "minit" },
  79.   { "^M~ATZ^M~",    PUBLIC,   "mreset" },
  80.   { "ATDP",        PUBLIC,   "mdialpre" },
  81.   { "^M",        PUBLIC,   "mdialsuf" },
  82.   { "ATDT",        PUBLIC,   "mdialpre2" },
  83.   { "^M",        PUBLIC,   "mdialsuf2" },
  84.   { "ATX1DT",        PUBLIC,   "mdialpre3" },
  85.   { ";X4D^M",        PUBLIC,   "mdialsuf3" },
  86.   { "CONNECT",        PUBLIC,   "mconnect" },
  87.   { "NO CARRIER",    PUBLIC,   "mnocon1" },
  88.   { "BUSY",        PUBLIC,   "mnocon2" },
  89.   { "NO DIALTONE",    PUBLIC,   "mnocon3" },
  90.   { "VOICE",        PUBLIC,   "mnocon4" },
  91.   { "~~+++~~ATH^M",    PUBLIC,   "mhangup" },
  92.   { "^M",        PUBLIC,   "mdialcan" },
  93.   { "45",        PUBLIC,   "mdialtime" },
  94.   { "60",        PUBLIC,   "mrdelay" },
  95.   { "10",        PUBLIC,   "mretries" },
  96.   { "Yes",        PUBLIC,   "mautobaud" },
  97.   { "No",        PUBLIC,   "mdropdtr" },
  98.   { "",            PUBLIC,   "updir" },
  99.   { "",            PUBLIC,   "downdir" },
  100.   { "",            PUBLIC,   "scriptdir" },
  101.   { "^A",        PUBLIC,   "escape-key" },
  102.   { "BS",        PUBLIC,   "backspace" },
  103.   { "enabled",        PUBLIC,   "statusline" },
  104.   { "No",        PUBLIC,   "hasdcd" },
  105.   /* That's all folks */
  106.   { "",            0,       (char *)NULL },
  107. };
  108.  
  109.  
  110. /*
  111.  * Write the parameters to a file.
  112.  */
  113. int writepars(fp, all)
  114. FILE *fp;
  115. int all;
  116. {
  117.   struct pars *p;
  118.  
  119.   for(p = mpars; p->desc; p++)
  120.       if ((all && (p->flags & ADM_CHANGE)) ||
  121.          ((p->flags & PUBLIC) && (p->flags & USR_CHANGE)))
  122.           fprintf(fp, "%s %-16.16s %s\n",
  123.               p->flags & PUBLIC ? "pu" : "pr", p->desc, p->value);
  124.   return(0);
  125. }
  126.  
  127. /*
  128.  * Read the parameters from a file.
  129.  */
  130. int readpars(fp, init)
  131. FILE *fp;
  132. int init;
  133. {
  134.   struct pars *p;
  135.   char line[80];
  136.   char *s;
  137.   int public;
  138.  
  139. #ifdef _ACK
  140.   int i;
  141. #endif
  142.  
  143.   if (init) sprintf(P_SCRIPTPROG, "%s/runscript", LIBDIR);
  144.  
  145. #ifdef _ACK
  146.   if (init) {
  147.       for(i = 0; tmppars[i].desc != (char *)0; i++) {
  148.           strcpy(mpars[i].value, tmppars[i].value);
  149.           mpars[i].flags = tmppars[i].flags;
  150.           mpars[i].desc = tmppars[i].desc;
  151.       }
  152.       mpars[i].desc = (char *)0;
  153.   }
  154.   if (fp == (FILE *)NULL) return(0);
  155. #endif
  156.  
  157.   while(fgets(line, 80, fp) != (char *)0) {
  158.       s = strtok(line, "\n\t ");
  159.       /* Here we have pr for private and pu for public */
  160.       public = 0;
  161.       if (strcmp(s, "pr") == 0) {
  162.           public = 0;
  163.           s = strtok((char *)NULL, "\n\t ");
  164.       }
  165.       if (strcmp(line, "pu") == 0) {
  166.           public = 1;
  167.           s = strtok((char *)NULL, "\n\t ");
  168.       }
  169.       /* Don't read private entries if prohibited */
  170.       if (!init && public == 0) continue;
  171.  
  172.       for(p = mpars; p->desc != (char *)0; p++) {
  173.           if (strcmp(p->desc, s) == 0) {
  174.                   ;
  175.               /* Set value */
  176.               if ((s = strtok((char *)NULL, "\n")) == (char *)0)
  177.                   s = "";
  178.               while(*s && (*s == '\t' || *s == ' ')) s++;
  179.  
  180.               /* If the same as default, don't mark as changed */
  181.               if (strcmp(p->value, s) == 0) {
  182.                   p->flags = 0;
  183.               } else {
  184.                 if (init)
  185.                     p->flags = ADM_CHANGE;
  186.                 else
  187.                     p->flags = USR_CHANGE;
  188.                   strcpy(p->value, s);
  189.               }
  190.               /* Set flags */
  191.               p->flags |= (public ? PUBLIC : PRIVATE);
  192.               break;
  193.           }
  194.       }
  195.   }
  196.   return(0);
  197. }
  198.