home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / edit / point20 / setup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-04  |  22.4 KB  |  1,005 lines

  1. #include "pt.h"
  2. #include "malloc.h"
  3. #include "string.h"
  4. #include "stdlib.h"
  5. #include "conio.h"
  6. #include "io.h"
  7.  
  8. static unsigned char *buffer, *fileBuffer;
  9. static int bufLeft = 0, bufferSize;
  10. static int lineNumber;
  11.  
  12. void pascal
  13. setGWBuffer( allocate )
  14.     int allocate;
  15. {
  16.     if( allocate ) {
  17.         bufferSize = 4096;
  18.         while( 1 ) {
  19.             fileBuffer = malloc(bufferSize);
  20.             if( fileBuffer != NULL )
  21.                 break;
  22.             bufferSize /= 2;
  23.         }
  24.     } else
  25.         free(fileBuffer);
  26. }
  27.  
  28. int pascal
  29. /* XTAG:setup */
  30. setup()
  31. {
  32.     extern unsigned char msgBuffer[];
  33.     extern unsigned char textBuffer[];
  34.     extern struct optionItem options[];
  35.     extern int debug;
  36.     extern union REGS rin, rout;
  37.     extern unsigned char textColor, selColor;
  38.     extern unsigned char bannerColor, borderColor, elevColor;
  39.     extern unsigned char topColor;
  40.     extern unsigned char windowPoints[];
  41.     extern struct colorCycle colorCycles[];
  42.     extern unsigned char maxTextCycles;
  43.     extern unsigned char maxBorderCycles;
  44.  
  45.     int i, j, fid;
  46.     register unsigned char *p;
  47.     register unsigned char *item;
  48.     int triedLocalIni;
  49.  
  50.     setGWBuffer(1);        /* allocate buffer space */
  51.  
  52.     triedLocalIni = 0;
  53.     p = findFile("pt.ini");
  54.     if( p == NULL )
  55.         return 1;
  56.     fid = openls(p, 0);
  57.  
  58. processLocalIni:
  59.     lineNumber = 1;
  60.     bufLeft = 0;
  61.     buffer = fileBuffer;
  62.  
  63.     while( 1 ) {
  64.         item = getWord(fid);
  65.         if( item == NULL )
  66.             break;
  67.         if( *item == '\0' )
  68.             continue;
  69.         p = strchr(item, '=');
  70.         if( p == NULL ) {
  71.             if( *item != '[' ) {
  72.                 cprintf(
  73.             "Missing '=' in pt%s.ini (line %d) item: \"%s\"\r\n",
  74.                     (triedLocalIni ? "local" : ""),
  75.                     lineNumber,
  76.                     item);
  77.                 goto contError;
  78.             }
  79.         } else
  80.             *p++ = '\0';
  81.         if( *item == '[' ) {
  82.             setMenu(item,  fid);
  83.             continue;
  84.         }
  85.         for(i = 0; options[i].index != OLASTITEM; i++) {
  86.             for(j = 0; options[i].name[j] != '\0'; j++) {
  87.                 if( tolower(options[i].name[j])
  88.                     != tolower(item[j]) )
  89.                     goto iContinue;
  90.             }
  91. /*************unixMode kludge -- temporary ***************/
  92. if( strncmp(item, "unix", 4) == 0 )  options[i].type = OINTEGER;
  93.             goto foundIt;
  94.         iContinue:
  95.             ;
  96.         }
  97.  
  98.         /* compute some things to check for invalid fields */
  99.         j = isdigit(*(item+1));    /* second char is a digit */
  100.         i = *(item+3) == '\0';    /* length is three */
  101.  
  102.         /* key definition? */
  103.         if( tolower(*item) == 'k' && j ) {
  104.             setKey(item, p);
  105.             continue;
  106.         }
  107.  
  108.         /* button definition? */
  109.         if( tolower(*item) == 'b' && i ) {
  110.             setButton(item, p);
  111.             continue;
  112.         }
  113.  
  114. #ifdef OVERLAYS
  115.         /* overlay command definition? */
  116.         if( tolower(*item) == 'c' && j ) {
  117.             setOverlay(item, p);
  118.             continue;
  119.         }
  120. #endif
  121.  
  122.         /* mouse motion 1 definition? */
  123.         if( tolower(*item) == 'm' && j ) {
  124.             setMMotion(1, item, p);
  125.             continue;
  126.         }
  127.  
  128.         /* mouse motion 2 definition? */
  129.         if( tolower(*item) == 'n' && j ) {
  130.             setMMotion(2, item, p);
  131.             continue;
  132.         }
  133.  
  134.         /* mouse motion quadrant definition? */
  135.         if( tolower(*item) == 'q' && j ) {
  136.             setMQuadrant(item, p);
  137.             continue;
  138.         }
  139.  
  140.         /* top line menu definition? */
  141.         if( tolower(*item) == 't' && i ) {
  142.             setTopline(item, p, 0);
  143.             continue;
  144.         }
  145.  
  146.         /* bottom line menu definition? */
  147.         if( tolower(*item) == 'l' && i ) {
  148.             setTopline(item, p, 1);
  149.             continue;
  150.         }
  151.  
  152.         /* window mouse point definition? */
  153.         if( tolower(*item) == 'w' && (*(item+4)=='\0') ) {
  154.             setWindowPoint(item, p);
  155.             continue;
  156.         }
  157.  
  158.         /* else we don't know what it is */
  159.         cprintf("Unknown option name [%s] in pt%s.ini (line %d)\r\n",
  160.             item, (triedLocalIni ? "local" : ""), lineNumber);
  161.     contError:
  162.         cprintf("Press any key to continue\r\n");
  163.         incon();
  164.         continue;
  165.     foundIt:
  166.         setOption(i, p, NULL);
  167.     }
  168.     closels(fid);
  169.     
  170.     /* see if there is a ptlocal.ini */
  171.     if( !triedLocalIni ) {
  172.         triedLocalIni = 1;
  173.         fid = openls("ptlocal.ini", 0);
  174.         if( fid >= 0 )
  175.             goto processLocalIni;
  176.     }
  177.     
  178.     /* set the first color cycle to the default colors */
  179.     colorCycles[0].textColor = textColor;
  180.     colorCycles[0].selColor = selColor;
  181.     colorCycles[0].bannerColor = bannerColor;
  182.     colorCycles[0].borderColor = borderColor;
  183.     colorCycles[0].elevColor = elevColor;
  184.     
  185.     /* set the default color modes */
  186.     if( maxTextCycles == 0 ) {
  187.         maxTextCycles = 1;
  188.         colorCycles[1].textColor = textColor;
  189.         colorCycles[1].selColor = selColor;
  190.     }
  191.     if( maxBorderCycles == 0 ) {
  192.         maxBorderCycles = 1;
  193.         colorCycles[1].bannerColor = bannerColor;
  194.         colorCycles[1].borderColor = borderColor;
  195.         colorCycles[1].elevColor = elevColor;
  196.     }
  197.  
  198.     setGWBuffer(0);        /* free buffer space */
  199.     bufLeft = 0;
  200.     return 0;
  201. }
  202.  
  203. void pascal
  204. /* XTAG:setTopline */
  205. setTopline(s, value, onBottom)
  206.     unsigned char *s, *value;
  207.     int onBottom;
  208. {
  209.     extern unsigned char toplineVector[];
  210.     extern int menuLine;
  211.     extern int firstTopMenu;
  212.     
  213.     int shifts, buttons, commandNumber, i;
  214.  
  215.     if( (onBottom && menuLine > 0)
  216.      || (!onBottom && menuLine < 0) ) {
  217.         cprintf("Mixing top and bottom menus in pt.ini\r\n");
  218.         cprintf("Press any key to continue\r\n");
  219.         incon();
  220.         onBottom = !onBottom;
  221.     }
  222.     commandNumber = atoi(value);
  223.     if( commandNumber == -1 )
  224.         commandNumber = FDONOTHING;
  225.     sscanf(&s[1], "%1x", &shifts);
  226.     sscanf(&s[2], "%1x", &buttons);
  227.     /* fix shifts so that either shift keys implies shift */
  228.     /* shift over bit1 and OR bit0 with it */
  229.     shifts = (shifts>>1) | (shifts&0x1);
  230.     i = ((shifts&0x7)<<3) + (buttons&0x7);
  231.     toplineVector[i] = (unsigned char)commandNumber;
  232.     if( onBottom )
  233.         --menuLine;
  234.     else
  235.         ++menuLine;
  236. }
  237.  
  238. void pascal
  239. /* XTAG:setButton */
  240. setButton(s, value)
  241.     unsigned char *s, *value;
  242. {
  243.     extern unsigned char buttonVector[];
  244.     
  245.     int shifts, buttons, commandNumber, i;
  246.     
  247.     commandNumber = atoi(value);
  248.     if( commandNumber == -1 )
  249.         commandNumber = FDONOTHING;
  250.     sscanf(&s[1], "%1x", &shifts);
  251.     sscanf(&s[2], "%1x", &buttons);
  252.     i = ((shifts&0x7)<<3) + (buttons&0x7);
  253.     buttonVector[i] = (unsigned char)commandNumber;
  254. }
  255.  
  256. void pascal
  257. /* XTAG:setMMotion */
  258. setMMotion(which, s, value)
  259.     int which;
  260.     unsigned char *s, *value;
  261. {
  262.     extern int mouseVec1[];
  263.     extern int mouseVec2[];
  264.     
  265.     int commandNumber, i;
  266.     
  267.     commandNumber = atoi(value);
  268.     if( commandNumber == -1 )
  269.         commandNumber = FDONOTHING;
  270.     i = *++s - '0';
  271.     if( i < 0 || i > 8 )
  272.         return;
  273.     if( which == 1 )
  274.         mouseVec1[i] = commandNumber;
  275.     else
  276.         mouseVec2[i] = commandNumber;
  277. }
  278.  
  279. void pascal
  280. /* XTAG:setWindowPoint */
  281. setWindowPoint(s, value)
  282.     register unsigned char *s;
  283.     unsigned char  *value;
  284. {
  285.     extern unsigned char msgBuffer[];
  286.     extern unsigned char windowPoints[];
  287.     
  288.     int commandNumber, n;
  289.     
  290.     commandNumber = atoi(value);
  291.     if( commandNumber == -1 )
  292.         commandNumber = FDONOTHING;
  293.     /* look at the second character of the string */
  294.     switch( *++s ) {
  295.         case 't': n = 0; break;    /* top left or right corner */
  296.         case 'b': n = 4; break;    /* bottom left or right corner */
  297.         default: n = 8; break;    /* right border */
  298.     }
  299.     ++s;    /* move to the third character in the string */
  300.     if( n == 8 ) {    /* right border */
  301.         /* skip the third character */
  302.         if( *++s == 'r' )    /* right button */
  303.             n = 9;
  304.     } else {    /* all 4 corners */
  305.         if( *s == 'r' )    /* top or bottom right corner */
  306.             n += 2;
  307.         if( *++s == 'm' )    /* middle button */
  308.             ++n;
  309.     }
  310.     windowPoints[n] = (unsigned char)commandNumber;
  311. }
  312.  
  313. void pascal
  314. /* XTAG:setMQuadrant */
  315. setMQuadrant(s, value)
  316.     unsigned char *s, *value;
  317. {
  318.     extern int quad22, quad45, quad67;
  319.     
  320.     int degrees;
  321.     
  322.     degrees = atoi(value);
  323.     if( s[1] == '1' )
  324.         quad67 = degrees;
  325.     else if( s[1] == '2' )
  326.         quad45 = degrees;
  327.     else
  328.         quad22 = degrees;
  329. }
  330.  
  331. void pascal
  332. /* XTAG:copyStringToMenuSpace */
  333. copyStringToMenuSpace(value)
  334.     unsigned char *value;
  335. {
  336.     extern unsigned char far *menuSpace;
  337.     extern unsigned char *userMessages[];
  338.     extern int nextSpace;
  339.     
  340.     while( 1 ) {
  341.         /* skip the initial " with the preincrement ++ */
  342.         menuSpace[nextSpace++] = *++value;
  343.         if( nextSpace >= MENUSPACE ) {
  344.             cprintf(userMessages[MENUSPMSG]);
  345.             break;
  346.         }
  347.         if( *value == '\0' ) {
  348.             --nextSpace;
  349.             /* eliminate the  final " (if there is one) */
  350.             if( menuSpace[nextSpace-1] == '"' )
  351.                 menuSpace[nextSpace-1] = '\0';
  352.             else
  353.                 ++nextSpace;
  354.             break;
  355.         }
  356.     }
  357. }
  358.  
  359. #ifdef OVERLAYS
  360. void pascal
  361. /* XTAG:setOverlay */
  362. setOverlay(s, value)
  363.     unsigned char *s, *value;
  364. {
  365.     extern unsigned char *overlayMap[];
  366.     extern unsigned char far *menuSpace;
  367.     extern unsigned char *userMessages[];
  368.     extern int nextSpace;
  369.     
  370.     int commandNumber;
  371.     
  372.     commandNumber = atoi(&s[1]) - 200;
  373.     if( commandNumber < 0 || commandNumber > 55 ) {
  374.         cprintf("command %d redefinition is out of range.\r\n",
  375.             commandNumber+200);
  376.         incon();
  377.         return;
  378.     }
  379.  
  380. IF WE EVER PUT BACK IN OVERLAYS, FIX THIS UP SINCE IT WILL NOT WORK
  381. NOW THAT WE HAVE MOVE THE menuSpace AREA OUT OF THE DATA SEGMENT
  382.     overlayMap[commandNumber] = &menuSpace[nextSpace];
  383.     copyStringToMenuSpace(value);
  384. }
  385. #endif
  386.  
  387. void pascal
  388. /* XTAG:setKey */
  389. setKey(s, value)
  390.     unsigned char *s, *value;
  391. {
  392.     extern int keyMap[];
  393.     extern int asciiMap[];
  394.     
  395.     int key, commandNumber;
  396.     
  397.     commandNumber = atoi(value);
  398.     if( commandNumber == -1 )
  399.         commandNumber = FDONOTHING;
  400.     key = atoi(&s[1]);
  401.     if( s[1] == '0' )
  402.         keyMap[key] = commandNumber;
  403.     else
  404.         asciiMap[key] = commandNumber;
  405. }
  406.  
  407. void pascal
  408. /* XTAG:setMenu */
  409. setMenu(s, fid)
  410.     unsigned char *s;
  411.     int fid;
  412. {
  413.     extern unsigned char msgBuffer[];
  414.     extern unsigned char far *menuSpace;
  415.     extern unsigned char *userMessages[];
  416.     extern struct menuBlock far *menus[];
  417.     extern int nextSpace;
  418.  
  419.     int n, menuNumber, itemNumber;
  420.     register unsigned char *item;
  421.     register unsigned char *p;
  422.  
  423.     menuNumber = atoi(&s[1]);
  424.  
  425.     /* see if the menu number is in the correct range */
  426.     if( menuNumber < 1 || menuNumber >= NMENUS ) {
  427.         cprintf("Menu number %d is out of range\r\n", menuNumber);
  428.     menuError:
  429.         cprintf("Press any key to continue\r\n");
  430.         incon();
  431.         return;
  432.     }
  433.  
  434.     /* Now allocate the space for the menu block */
  435.     if( menus[menuNumber] != (struct menuBlock far *)NULL ) {
  436.         /* FREE THE STRINGS IN THE MENUBLOCK ???????? */
  437.     } else {
  438.         menus[menuNumber] = (struct menuBlock far *)
  439.                     _fmalloc(sizeof(struct menuBlock));
  440.     }
  441.  
  442.     itemNumber = 0;
  443.     while( 1 ) {
  444.         item = getWord(fid);
  445.         if( item == NULL || *item == ']' )
  446.             break;
  447.         p = strchr(item, '=');
  448.         if( p == NULL ) {
  449.             cprintf("Missing '=' in pt.ini item: \"%s\"\r\n",
  450.                 item);
  451.             goto menuError;
  452.         }
  453.         *p++ = '\0';
  454.         menus[menuNumber]->cmdName[itemNumber] =
  455.                             &menuSpace[nextSpace];
  456.         copyStringToMenuSpace(item);
  457.         while( 1 ) {
  458.             /* skip the initial " with the preincrement ++ */
  459.             menuSpace[nextSpace++] = *++item;
  460.             if( nextSpace >= MENUSPACE ) {
  461.                 cprintf(userMessages[MENUSPMSG]);
  462.                 goto menuError;
  463.             }
  464.             if( *item == '\0' ) {
  465.                 --nextSpace;
  466.                 /* eliminate the  final " (if there is one) */
  467.                 if( menuSpace[nextSpace-1] == '"' )
  468.                     menuSpace[nextSpace-1] = '\0';
  469.                 else
  470.                     ++nextSpace;
  471.                 break;
  472.             }
  473.         }
  474.         menuSpace[nextSpace++] = '\0';
  475.         n = atoi(p);
  476.         if( n == -1 )
  477.             n = FDONOTHING;
  478.         menus[menuNumber]->cmdNumber[itemNumber] = n;
  479.         if( ++itemNumber >= MAXMENUITEMS ) {
  480.             cprintf("More than %d items in menu %d.  "
  481.                 "Extra items ignored.\r\n",
  482.                 MAXMENUITEMS, menuNumber);
  483.             /* skip to the end of this menu */
  484.             while( 1 ) {
  485.                 item = getWord(fid);
  486.                 if( item == NULL || *item == ']' )
  487.                     break;
  488.             }
  489.             menus[menuNumber]->nItems = itemNumber - 1;
  490.             cprintf("More than %d items on menu %d. "
  491.                 "Reduce menu size to %d or fewer",
  492.                 MAXMENUITEMS, menuNumber, MAXMENUITEMS);
  493.             goto menuError;
  494.         }
  495.     }
  496.     menus[menuNumber]->nItems = itemNumber;
  497. }
  498.  
  499. #ifdef OPTIONMENU
  500. void pascal
  501. /* XTAG:doOptions */
  502. doOptions(w)
  503.     struct window *w;
  504. {
  505.     extern unsigned char msgBuffer[];
  506.     extern unsigned char textBuffer[];
  507.     extern struct optionItem options[];
  508.     extern int menuRow, menuCol;
  509.     extern unsigned char far *menuSpace;
  510.     extern struct menuBlock far *menus[];
  511.     extern int nextSpace;
  512.     extern unsigned char msgColor, promptColor, errorColor, topColor;
  513.     extern int scrRows, scrCols;
  514.     
  515.     unsigned char *s, buffer[64];
  516.     int n, iMenu, iOption, option;
  517.  
  518.     menus[0]->cmdName[0] = (unsigned char far *)"OPTIONS";
  519.     menus[0]->cmdNumber[0] = 99;
  520.     iMenu = nextSpace;
  521.     iOption = 1;
  522.     for(n = 0; options[n].index != OLASTITEM; n++ ) {
  523.         switch( options[n].type ) {
  524.         case OBOOLEAN:
  525. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  526.             sprintf(&menuSpace[iMenu], "%s is %s",
  527.                 options[n].name,
  528.                 (*(options[n].variable) ? "On" : "Off") );
  529.             break;
  530.         case OINTEGER:
  531. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  532.             sprintf(&menuSpace[iMenu], "%s = %d",
  533.                 options[n].name, *(options[n].variable));
  534.             break;
  535.         case OSTRING:
  536. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  537.             sprintf(&menuSpace[iMenu], "%s = %s",
  538.                 options[n].name, options[n].variable);
  539.             break;
  540.         case OOTHERS:
  541.             switch(options[n].index) {
  542.             case OTEXTCOLORS:
  543.                 if( w == NULL )
  544.                     /* do not show this option */
  545.                     continue;
  546.                 else
  547. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  548.                     sprintf(&menuSpace[iMenu],
  549.                       "%s = %02X%02X", options[n].name,
  550.                       w->textColor, w->selColor);
  551.                 break;
  552.             case OBORDERCOLORS:
  553.                 if( w == NULL )
  554.                     /* do not show this option */
  555.                     continue;
  556.                 else
  557. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  558.                     sprintf(&menuSpace[iMenu],
  559.                       "%s = %02X%02X%02X",
  560.                       options[n].name, w->bannerColor,
  561.                       w->borderColor, w->elevColor);
  562.                 break;
  563.             case OMSGCOLORS:
  564.                 if( w == NULL )
  565.                     /* do not show this option */
  566.                     continue;
  567.                 else
  568. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  569.                     sprintf(&menuSpace[iMenu],
  570.                       "%s = %02X%02X%02X%02X",
  571.                       options[n].name, msgColor,
  572.                       promptColor, errorColor, topColor);
  573.                 break;
  574.             case OREDEFINE:
  575. THIS WILL NOT WORK SINCE WE MOVED menuSpace OUT OF THE DATA SEGMENT
  576.                 sprintf(&menuSpace[iMenu], "%s",
  577.                     options[n].name);
  578.             }
  579.             break;
  580.         default:
  581.             continue;
  582.         }
  583.         menus[0]->cmdName[iOption] =
  584.                 (unsigned char far *)&(menuSpace[iMenu]);
  585.         iMenu += strlen(&(menuSpace[iMenu])) + 1;
  586.         if( iMenu >= MENUSPACE ) {
  587.             msg("setup: Menu Overflow!!!", 3);
  588.             break;
  589.         }
  590.         menus[0]->cmdNumber[iOption] = n;
  591.         ++iOption;
  592.     }
  593.     menus[0]->nItems = iOption;
  594.     option = menu(menus[0], menuRow, menuCol);
  595.     if( option == 99 )
  596.         return;
  597.     n = options[option].type;
  598.     if( n == OINTEGER || n == OSTRING ) {
  599.         if( n == OINTEGER )
  600.             sprintf(buffer, "%d", *(options[option].variable));
  601.         else
  602.             strcpy(buffer,
  603.                 (unsigned char *)options[option].variable);
  604.         sprintf(textBuffer, "New value for option `%s': ",
  605.             options[option].name );
  606.         s = getInput(textBuffer, buffer, 0);
  607.         if( s == NULL ) {
  608.             msg("Option value not changed", 1);
  609.             return;
  610.         }
  611.     } else
  612.         s = NULL;
  613.     setOption(option, s, w);
  614.     redrawBox(0, 0, scrRows-1, scrCols-1);
  615.     updateScreen(0, scrRows-1);
  616. }
  617. #endif
  618.  
  619. void pascal
  620. /* XTAG:setOption */
  621. setOption(option, s, w)
  622.     int option;
  623.     unsigned char *s;
  624.     struct window *w;
  625. {
  626.     extern struct optionItem options[];
  627.     extern unsigned int dispMemory;
  628.     extern int cornerCols, cornerRows;
  629.     extern int nBuffers;
  630.     extern unsigned char msgColor, promptColor, errorColor;
  631.     extern unsigned char topColor;
  632.     extern unsigned char addFile[];
  633.     extern int undoSize;
  634.     extern int undoSize;
  635.     extern union REGS rin, rout;
  636.     extern int scrRows;
  637.     extern int debug;
  638.     extern int fileSort;
  639.     extern unsigned char msgBuffer[];
  640.     extern unsigned char textBuffer[];
  641.     extern unsigned char fsDirs[];
  642.     extern unsigned char fsPatterns[];
  643.     
  644.     int n;
  645.     
  646.     switch( options[option].type ) {
  647.  
  648.     case OBOOLEAN:
  649.         if( w != NULL || s == NULL )
  650.             *(options[option].variable) =
  651.                         !*(options[option].variable);
  652.         else {
  653.             if( isdigit(*s) )
  654.                 n = *s - '0';
  655.             else if( tolower(*s) == 'y' )
  656.                 n = 1;
  657.             else
  658.                 n = 0;
  659.             *(options[option].variable) = n;
  660.         }
  661.         if( options[option].index == O43LINES )
  662.             set43lines();
  663.         break;
  664.  
  665.     case OINTEGER:
  666.         *(options[option].variable) = atoi(s);
  667.         break;
  668.  
  669.     case OSTRING:
  670.         strcpy((unsigned char *)(options[option].variable), s);
  671.         break;
  672.  
  673.     case OOTHERS:
  674.     default:
  675.         switch( options[option].index ) {
  676.         case OFSDIRS:
  677.             strncpy(&fsDirs[0], s, 200);
  678.             break;
  679.         case OFSPATTERNS:
  680.             strncpy(&fsPatterns[0], s, 128);
  681.             break;
  682.         case OFILESORT:
  683.             switch( tolower(*s) ) {
  684.                 case 'u': fileSort = 0; break;
  685.                 case 'n': fileSort = 1; break;
  686.                 case 'e':
  687.                 default:  fileSort = 2; break;
  688.             }
  689.             break;
  690.         case OUNDOSIZE:
  691.             n = atoi(s);
  692.             if( n < 4 )
  693.                 undoSize = 4;
  694.             else if( n > 100 )
  695.                 undoSize = 100;
  696.             else
  697.                 undoSize = n;
  698.             break;
  699.         case ONBUFFERS:
  700.             nBuffers = atoi(s);
  701.             if( nBuffers < 5 )
  702.                 nBuffers = 5;
  703.             else if( nBuffers > NBUFFERS )
  704.                 nBuffers = NBUFFERS;
  705.             break;
  706.         case OTEXTCOLORS:
  707.             if( w != NULL )
  708.                 setColor(w);
  709.             else
  710.                 doTextColors(s);
  711.             break;
  712.         case OBORDERCOLORS:
  713.             if( w != NULL )
  714.                 setColor(w);
  715.             else
  716.                 doBorderColors(s);
  717.             break;
  718.         case OMSGCOLORS:
  719.             if( w != NULL )
  720.                 setColor(w);
  721.             else {
  722.                 msgColor = convert(&s[0]);
  723.                 promptColor = convert(&s[2]);
  724.                 errorColor = convert(&s[4]);
  725.                 topColor = convert(&s[6]);
  726.             }
  727.             break;
  728.         case OREDEFINE:
  729.             redefine();
  730.         }
  731.         break;
  732.     }
  733. }
  734.  
  735. void pascal
  736. /* XTAG:doTextColors */
  737. doTextColors(s)
  738.     unsigned char *s;
  739. {
  740.     extern struct colorCycle colorCycles[];
  741.     extern unsigned char textColor, selColor;
  742.     extern unsigned char maxTextCycles;
  743.  
  744.     register int i, cycle;
  745.  
  746.     textColor = convert(&s[0]);
  747.     selColor = convert(&s[2]);
  748.     if( s[4] == ';' )
  749.         i = 5;
  750.     else
  751.         i = 0;
  752.     cycle = 1;
  753.     while( cycle < NCOLORCYCLES ) {
  754.         colorCycles[cycle].textColor = convert(&s[i]);
  755.         colorCycles[cycle].selColor = convert(&s[i+2]);
  756.         if( s[i+4] != ',' )
  757.             break;
  758.         i += 5;
  759.         ++cycle;
  760.     }
  761.     maxTextCycles = (unsigned char)(cycle + 1);
  762. }
  763.  
  764. void pascal
  765. /* XTAG:doBorderColors */
  766. doBorderColors(s)
  767.     unsigned char *s;
  768. {
  769.     extern struct colorCycle colorCycles[];
  770.     extern unsigned char bannerColor, borderColor, elevColor;
  771.     extern unsigned char maxBorderCycles;
  772.  
  773.     register int cycle, i;
  774.  
  775.     bannerColor = convert(&s[0]);
  776.     borderColor = convert(&s[2]);
  777.     elevColor = convert(&s[4]);
  778.  
  779.     if( s[6] == ';' )
  780.         i = 7;
  781.     else
  782.         i = 0;
  783.     cycle = 1;
  784.     while( cycle < NCOLORCYCLES ) {
  785.         colorCycles[cycle].bannerColor = convert(&s[i]);
  786.         colorCycles[cycle].borderColor = convert(&s[i+2]);
  787.         colorCycles[cycle].elevColor = convert(&s[i+4]);
  788.         if( s[i+6] != ',' )
  789.             break;
  790.         i += 7;
  791.         ++cycle;
  792.     }
  793.     maxBorderCycles = (unsigned char)(cycle + 1);
  794. }
  795.  
  796. void pascal
  797. /* XTAG:set43lines */
  798. set43lines()
  799. {
  800.     extern unsigned int dispMemory;
  801.     extern struct window *windowList;
  802.     extern int menuLine;
  803.     extern int i43lines;
  804.     extern int debug;
  805.     extern int scrRows;
  806.     extern unsigned char msgBuffer[];
  807.     extern union REGS rin, rout;
  808.  
  809.     int row, col;
  810.     register struct window *w1;
  811.  
  812.     /* find out where the mouse is now so we can put it back */
  813.     /* there after the video reset in initMouse */
  814.     rin.x.ax = 3;
  815.     int86(51, &rin, &rout);
  816.     row = rout.x.dx>>3;
  817.     col = rout.x.cx>>3;
  818.     if( row > 24 )
  819.         row = 12 * row / 21;
  820.     initMouse(row, col, 1);
  821.  
  822.     row = (menuLine < 0 ? (scrRows-1) : 0);
  823.     updateScreen(row, row);
  824.  
  825.     if( i43lines ) {
  826.         /* resize all the windows */
  827.         w1 = windowList;
  828.         while( w1 != NULL ) {
  829.             w1->row1 = (21*w1->row1)/12;
  830.             w1->row2 = (21*w1->row2)/12;
  831.             w1 = w1->nextWindow;
  832.         }
  833.     } else {
  834.         /* resize all the windows */
  835.         w1 = windowList;
  836.         while( w1 != NULL ) {
  837.             w1->row1 = (12*w1->row1)/21;
  838.             if( menuLine > 0 && w1->row1 == 0 )
  839.                 w1->row1 = 1;
  840.             if( menuLine < 0 && w1->row2 == (scrRows-1) )
  841.                 --(w1->row2);
  842.             w1->row2 = (12*w1->row2)/21;
  843.             w1 = w1->nextWindow;
  844.         }
  845.     }
  846. }
  847.  
  848. unsigned char * pascal
  849. /* XTAG:findFile */
  850. findFile(name)
  851.     unsigned char *name;
  852. {
  853.     extern unsigned char textBuffer[];
  854.     
  855.     unsigned char *env;
  856.     int i;
  857.  
  858.     /* first look in the current directory */
  859.     if( access(name, 0) == 0 )
  860.         return name;
  861.     /* now look in the PATH directories */
  862.     env = getenv("PATH");
  863.     if( env == NULL )
  864.         return NULL;
  865.     while( *env != '\0' ) {
  866.         /* find the next directory name */
  867.         i = 0;
  868.         while( *env != ';' && *env != '\0' )
  869.             textBuffer[i++] = *env++;
  870.         if( textBuffer[i-1] != '\\' )
  871.             textBuffer[i++] = '\\';
  872.         textBuffer[i] = '\0';
  873.         strcat(textBuffer, name);
  874.         if( access(textBuffer, 0) == 0 )
  875.             return &textBuffer[0];
  876.         if( *env != '\0' )
  877.             ++env;
  878.     }
  879.     return NULL;
  880. }
  881.  
  882. unsigned char pascal
  883. /* XTAG:convert */
  884. convert(s)
  885.     unsigned char *s;
  886. {
  887.     register unsigned char n;
  888.     unsigned char ch;
  889.     
  890.     ch = *s++;
  891.     if( isdigit(ch) )
  892.         n = ch - '0';
  893.     else
  894.         n = tolower(ch) - 'a' + 10;
  895.     n *= 16;
  896.     ch = *s;
  897.     if( isdigit(ch) )
  898.         n += ch - '0';
  899.     else
  900.         n += tolower(ch) - 'a' + 10;
  901.     return n;
  902. }
  903.  
  904. /* getWord reads in the next word from the stram fid */
  905. /* It keeps initial white space. */
  906. /* It skips the rest of the line after a comment "-" symbol. */
  907. /* It gets all characters (including enbedded blanks) in */
  908. /*  double quotes as a single word. */
  909. unsigned char * pascal
  910. /* XTAG:getWord */
  911. getWord(fid)
  912.     int fid;
  913. {
  914.     extern int debug;
  915.  
  916.     static unsigned char word[256];
  917.     int i, n, inQuotes;
  918.     unsigned char ch, lastCh;
  919.  
  920.     /* first skip white space */
  921. startOver:
  922.     while( 1 ) {
  923.         if( bufLeft <= 0 ) {
  924.             buffer = fileBuffer;
  925.             n = readls(fid, buffer, MSGBUFFERSIZE);
  926.             if( n <= 0 ) {
  927.                 return NULL;
  928.             }
  929.             bufLeft = n;
  930.         }
  931.         ch = *buffer++;
  932.         --bufLeft;
  933.         switch( ch ) {
  934.         case '\n':
  935.             ++lineNumber;
  936.         case ' ':
  937.         case '\t':
  938.         case '\r':
  939.         case '\032':    /* control-Z */
  940.             break;
  941.         default:
  942.             goto pastWhite;
  943.         }
  944.     }
  945. pastWhite: 
  946.     /* now skip comments */
  947.     if( ch == '-' ) {
  948.         /* skip to the end of the line */
  949.         ++lineNumber;
  950.         while( 1 ) {
  951.             if( bufLeft <= 0 ) {
  952.                 buffer = fileBuffer;
  953.                 n = readls(fid, buffer, MSGBUFFERSIZE);
  954.                 if( n <= 0 ) {
  955.                     return NULL;
  956.                 }
  957.                 bufLeft = n;
  958.             }
  959.             ch = *buffer++;
  960.             --bufLeft;
  961.             if( ch == '\n' )
  962.                 goto startOver;
  963.         }
  964.     }
  965.     i = 0;
  966.     inQuotes = 0;
  967.     lastCh = 0;
  968.     while( 1 ) {
  969.         switch( ch ) {
  970.         case '\n':
  971.             ++lineNumber;
  972.         case ' ':
  973.         case '\t':
  974.         case '\r':
  975.         case '\032':    /* control-Z */
  976.             if( inQuotes )
  977.                 goto getChar;
  978.             goto done;
  979.         case '"':
  980.             inQuotes = !inQuotes;
  981.             /* two consecutive "s turns into one " */
  982.             if( lastCh == '"' )
  983.                 --i;
  984.         default:
  985.         getChar:
  986.             word[i++] = ch;
  987.             break;
  988.         }
  989.         if( bufLeft <= 0 ) {
  990.             buffer = fileBuffer;
  991.             n = readls(fid, buffer, MSGBUFFERSIZE);
  992.             if( n <= 0 ) {
  993.                 goto done;
  994.             }
  995.             bufLeft = n;
  996.         }
  997.         lastCh = ch;
  998.         ch = *buffer++;
  999.         --bufLeft;
  1000.     }
  1001. done:
  1002.     word[i] = '\0';
  1003.     return &word[0];
  1004. }
  1005.