home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / GLEN / LISTCNFG.ZIP / LISTCNFG.C next >
C/C++ Source or Header  |  1990-09-22  |  8KB  |  266 lines

  1. /*
  2.   LISTCNFG - Configure LIST.COM V 7.4a & UP
  3.          (c) L.Ottersbach,  GoodShit, Inc.
  4.     This program will configure some of the variables that are
  5.     not 'cloneable' in the classic LIST PLUS program LIST.COM
  6.     by Vernon D. Buerg. It eliminates the need to use DOS DEBUG.
  7.     It will save the configuration variables area for future use
  8.     (If Vern doesn't change their offsets) allowing an easy update
  9.     of your configuration in a later version of LIST.  It was written
  10.     as an exercise in the use of the CXL functions library.
  11.  
  12.   SYNTAX -
  13.     LISTCNFG [/B]
  14.       LISTCNFG creates a backup .CFG file of the cloneable area of
  15.       LIST.COM.  If the /B option is specified, LISTCNFG will use this
  16.       saved file to restore previous values to the current version of
  17.       LIST.COM.  It will always write out a new .CFG file.  Use the
  18.       ALT-C option in LIST to save the other configuration values, then
  19.       run LISTCNFG.
  20.  
  21.   COMPILER -
  22.     LISTCNFG was compiled using TURBO C++ V 1.0 and the CXL Function
  23.     Library V 5.2.
  24.  
  25. */
  26. #include <sys\stat.h>
  27. #include <string.h>
  28. #include <stdio.h>
  29. #include <fcntl.h>
  30. #include <io.h>
  31.  
  32. #include <cxlwin.h>
  33. #include <cxlvid.h>
  34. #include <cxlmou.h>
  35.  
  36. typedef enum {FALSE, TRUE} Boolean;
  37.  
  38. /* define offset of configuration variables */
  39. #define CONFIG 0x32
  40.  
  41. struct cnfg_vars {
  42.   char special;
  43.   char undef1;
  44.   char normal;
  45.   char undef3;
  46.   char bright;
  47.   char undef5;
  48.   char win1_color;
  49.   char win2_color;
  50.   char flag3;
  51.   char flag4;
  52.   int  find_row;
  53.   int  scroll_incr;
  54.   int  scroll_start;
  55.   int  tab_value;
  56.   int  tab_mask;
  57.   int  loudness;
  58.   char key_rate;
  59.   int  overlap;
  60.   char wildcard_esc;
  61.   int  altv_up;
  62.   char eye_catcher[4];
  63.   char com_port[2];
  64.   char sort_offset;
  65.   char undef35[2];
  66.   char modem_init[30];
  67.   char editor_name[8];
  68.   char undef75;
  69.   char modem_hangup[9];
  70.   char temp_varname[4];
  71. };
  72.  
  73. /* miscellaneous global variables */
  74. static int *savescrn, crow, ccol;
  75.  
  76. /* function declarations */
  77. int getopt(int argc, char *argv[], char *optionS);
  78. static void initialize(void);
  79. static void cleanup(void);
  80. void get_cnfg_vars(int handle1, struct cnfg_vars *);
  81.  
  82. main(int argc, char *argv[])
  83. {
  84.   int handle, handle1;
  85.   char editor[9], comport[2], init_str[31], hang_str[10], env_str[5];
  86.   char c_bg, c_fg, c_rev;
  87.   Boolean Use_backup = FALSE;
  88.   struct cnfg_vars list, cnfg;
  89.   int optCh;
  90.   extern char *optarg;  /* pointer to option string in getopt.c */
  91.   extern int optind;    /* option counter in getopt.c */
  92.   char *optionS = "Bb";  /* allowable command line options */
  93.  
  94.   /* this is set up to allow multiple command line options */
  95.   while ((optCh = getopt(argc, argv, optionS)) != EOF) {
  96.     switch (toupper(optCh)) {
  97.       case 'B': Use_backup = TRUE; break;
  98.     }
  99.   }
  100.  
  101.   /* open LIST.COM */
  102.   if ((handle = open("LIST.COM", O_RDWR | O_BINARY)) == -1) {
  103.     perror("Error:");
  104.     return 1;
  105.   }
  106.  
  107.   /* open LIST.CFG if it exists else create it */
  108.   if ((handle1 = open("LIST.CFG",
  109.        O_RDWR | O_CREAT | O_BINARY,
  110.        S_IREAD | S_IWRITE)) == -1) {
  111.     perror("Error:");
  112.     return 1;
  113.   }
  114.  
  115.   /* get the configuration variables from LIST.COM */
  116.   lseek(handle, CONFIG, SEEK_SET);
  117.   read(handle, &list, sizeof(list));
  118.  
  119.   /* get the configuration variables from LIST.CFG if needed */
  120.   if (Use_backup) get_cnfg_vars(handle1, &list);
  121.  
  122.   initialize();
  123.  
  124.   /* set up the data entry field values */
  125.   c_fg = (list.bright & 0x07) << 4;
  126.   c_bg = (list.bright & 0xf0) >> 4;
  127.   c_rev = c_fg | c_bg;
  128.  
  129.   strcpy(comport, (list.com_port[1] == '\x03') ? "1" : "2");
  130.   memcpy(init_str, list.modem_init, sizeof(list.modem_init));
  131.   init_str[30] = '\0';
  132.   memcpy(editor, list.editor_name, sizeof(list.editor_name));
  133.   editor[8] = '\0';
  134.   memcpy(hang_str, list.modem_hangup, sizeof(list.modem_hangup));
  135.   hang_str[9] = '\0';
  136.   memcpy(env_str, list.temp_varname, sizeof(list.temp_varname));
  137.   env_str[4]=  '\0';
  138.  
  139.   wopen(2,9,17,71,5,list.special,list.normal);
  140.   wshadow(LGREY|_BLACK);
  141.   wprints(0,0,list.special,
  142.       "      LIST Configuration Program - for Version 7.4a and up     ");
  143.   wprints(15,0,list.special,
  144.       "            [CNTL] Enter = Finished   [ESC] = Abort            ");
  145.  
  146.   winpbeg(CYAN|_BLACK,YELLOW|_BLACK);
  147.  
  148.   wprints(3,4,list.normal,"Editor: <");
  149.   wprints(3,21,list.normal,">");
  150.   winpdef(3,13,editor,"********",' ',2,NULL,0);
  151.  
  152.   wprints(5,4,list.normal,"COM Port: <");
  153.   wprints(5,16,list.normal,">");
  154.   winpdef(5,15,comport,"<12>",' ',2,NULL,0);
  155.  
  156.   wprints(7,4,list.normal,"Modem Init: <");
  157.   wprints(7,47,list.normal,">");
  158.   winpdef(7,17,init_str,"??????????????????????????????",' ',2,NULL,0);
  159.  
  160.   wprints(9,4,list.normal,"Modem Disconnect: <");
  161.   wprints(9,32,list.normal,">");
  162.   winpdef(9,23,hang_str,"?????????",' ',2,NULL,0);
  163.  
  164.  
  165.   wprints(11,4,list.normal,"Environment Variable: <");
  166.   wprints(11,31,list.normal,">");
  167.   winpdef(11,27,env_str,"****",' ',2,NULL,0);
  168.  
  169.   wprints(13,4,list.bright,"This is the current ");
  170.   wprints(13,24,c_rev,"FIND STRING");
  171.   wprints(13,35,list.bright," color set.");
  172.  
  173.   if(winpread()) {
  174.     cleanup();
  175.     return(1);
  176.   }
  177.  
  178.   /* move data entry fields into the configuration variables */
  179.   list.com_port[1] = (comport[0] == '1') ? '\x03' : '\x02';
  180.   memcpy(list.modem_init, init_str, sizeof(list.modem_init));
  181.   memcpy(list.editor_name, editor, sizeof(list.editor_name));
  182.   memcpy(list.modem_hangup, hang_str, sizeof(list.modem_hangup));
  183.   memcpy(list.temp_varname, env_str, sizeof(list.temp_varname));
  184.  
  185.   /* write the updated LIST.COM */
  186.   lseek(handle, CONFIG, SEEK_SET);
  187.   write(handle, &list, sizeof(list));
  188.   close(handle);
  189.  
  190.   /* write the updated LIST.CFG for later retrieval */
  191.   lseek(handle1, 0, SEEK_SET);
  192.   write(handle1, &list, sizeof(list));
  193.   close(handle1);
  194.  
  195.   cleanup();
  196.   return(0);
  197.  
  198. }  /* end main */
  199.  
  200. /*
  201.   Initialize CXL's video, mouse, keyboard, and help systems
  202. */
  203.  
  204. static void initialize(void)
  205. {
  206.     /* initialize the CXL video system and save current screen info */
  207.     videoinit();
  208.     readcur(&crow,&ccol);
  209.     if((savescrn=ssave())==NULL) exit(-1);
  210.  
  211.     /* if mouse exists, turn on full mouse support */
  212.     if(msinit()) mssupport(MS_FULL);
  213.  
  214. }  /* end initialize */
  215.  
  216. /*
  217.   This function restores the saved environment.
  218. */
  219. static void cleanup(void)
  220. {
  221.     srestore(savescrn);
  222.     gotoxy_(crow,ccol);
  223.     showcur();
  224. }  /* end cleanup */
  225.  
  226. /*
  227.   This function retrieves the backup configuration variables and copies
  228.   them to the original structure field by field because of undocumented
  229.   fields in the middle of the variables.  (*list = cnfg is much simpler)
  230. */
  231. void get_cnfg_vars(int handle1, struct cnfg_vars *list)
  232. {
  233.   struct cnfg_vars cnfg;
  234.  
  235.   lseek(handle1, 0, SEEK_SET);
  236.   read(handle1, &cnfg, sizeof(cnfg));
  237. /*
  238.   *list = cnfg;
  239. */
  240.   list->special = cnfg.special;
  241.   list->normal = cnfg.normal;
  242.   list->bright = cnfg.bright;
  243.   list->win1_color = cnfg.win1_color;
  244.   list->win2_color = cnfg.win2_color;
  245.   list->flag3 = cnfg.flag3;
  246.   list->flag4 = cnfg.flag4;
  247.   list->find_row = cnfg.find_row;
  248.   list->scroll_incr = cnfg.scroll_incr;
  249.   list->scroll_start = cnfg.scroll_start;
  250.   list->tab_value = cnfg.tab_value;
  251.   list->tab_mask = cnfg.tab_mask;
  252.   list->loudness = cnfg.loudness;
  253.   list->key_rate = cnfg.key_rate;
  254.   list->overlap = cnfg.overlap;
  255.   list->wildcard_esc = cnfg.wildcard_esc;
  256.   list->altv_up = cnfg.altv_up;
  257.   memcpy(list->eye_catcher, cnfg.eye_catcher, sizeof(cnfg.eye_catcher));
  258.   memcpy(list->com_port, cnfg.com_port, sizeof(cnfg.com_port));
  259.   list->sort_offset = cnfg.sort_offset;
  260.   memcpy(list->modem_init, cnfg.modem_init, sizeof(cnfg.modem_init));
  261.   memcpy(list->editor_name, cnfg.editor_name, sizeof(cnfg.editor_name));
  262.   memcpy(list->modem_hangup, cnfg.modem_hangup, sizeof(cnfg.modem_hangup));
  263.   memcpy(list->temp_varname, cnfg.temp_varname, sizeof(cnfg.temp_varname));
  264.  
  265. }  /* end get_cnfg_vars */
  266.