home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / ISPSRC.ZIP / getsetup.c < prev    next >
Text File  |  1993-03-29  |  9KB  |  261 lines

  1. /*
  2.  * getsetup.c - get some settings from ispell.cfg. Added for OS/2 2.0
  3.  *
  4.  * void getsetup(int printoption, char *argv)
  5.  * Joe Huber, 1992
  6.  *
  7.  */
  8.  
  9. /*
  10.  * Revision 1.05 93/03/07 jbh
  11.  * DOS compatibility added.
  12.  *
  13.  * Revision 1.04  92/10/19  jbh
  14.  * getsetup will print the configuration file settings if passed a '1'. The 
  15.  * -vv command line switch calls getsetup with 1 and the setting are printed.
  16.  *
  17.  * Revision 1.03  92/10/01  jbh
  18.  * Fixed bug in configuration file parser. Previously, if EOF was encountered
  19.  * immediately after a keyword definition, the last character of the filename 
  20.  * was dropped.
  21.  *
  22.  * Ispell will now display an invalid line exactly as it is found in the 
  23.  * configuration file. Previously, an invlaid line was displayed with 
  24.  * all spaces removed.
  25.  * 
  26.  * Ispell now continues to scan the configuration file after a bad line is
  27.  * found.  Ispell displays any additional invalid lines and exits.
  28.  *
  29.  * 
  30.  * Revision 1.02  92/09/22  jbh 
  31.  * Added ISWORDS keyword, which allows the user to specify a system word list.  
  32.  *
  33.  * 
  34.  * Revision 1.01  92/09/10  jbh 
  35.  * Set cfhashname, cfpersonaldict, and cftempname to null before they are 
  36.  * used. Otherwise, they may contain junk and foul up statements that check 
  37.  * if these variables have been assigned values.  
  38.  * 
  39.  *
  40.  * Revision 1.00  92/09/01  jbh * Initial release 
  41.  * 
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #include <os2.h>
  48.  
  49. #include "config.h"
  50. #include "ispell.h"
  51. #include "msgs.h"
  52.  
  53.  
  54. /* GetLoadPath -- From Kai Uwe Rommel
  55.  * Function to get the full path name of the executing file.
  56.  * posted to USENET group comp.os.os2.programming  8/24/92
  57.  */
  58. char *GetLoadPath(void)
  59. {
  60.         PTIB pptib;
  61.         PPIB pppib;
  62.         char *szPath;
  63.  
  64.         DosGetInfoBlocks(&pptib, &pppib);
  65.  
  66.         szPath = pppib -> pib_pchenv;
  67.  
  68.         while (*szPath)
  69.                 szPath = strchr(szPath, 0) + 1;
  70.  
  71.         return szPath + 1;
  72. }
  73.  
  74.  
  75.  
  76. getsetup(int printoption, char *argv[])
  77. {       FILE *confile;
  78.         unsigned char confilename[MAXPATHLEN];
  79.         unsigned char Lang[MAXPATHLEN];
  80.         unsigned char conbuffom[MAXPATHLEN];
  81.         unsigned char conbuffo[MAXPATHLEN];
  82.         unsigned char conbuff[MAXPATHLEN];
  83.         unsigned char convar[MAXPATHLEN];
  84.         unsigned char consetting[MAXPATHLEN];
  85.         unsigned char contokensep[] = " \t";
  86.         unsigned char *contoken;
  87.         unsigned char convarlen;
  88.         unsigned char *chptr;
  89.         unsigned char badline;
  90.         int x;
  91.         size_t constrlen;
  92.  
  93.  
  94.         if(printoption == 1)
  95.         {
  96.                 printf("\nConfiguration file options:");
  97.                 printf("\n\thashed dictionary: %s", cfhashname);
  98.                 printf("\n\tpersonal dictionary: %s", cfpersonaldict);
  99.                 printf("\n\ttemporary files: %s", cftempname);
  100.                 printf("\n\tsystem dictionary: %s", cfsysdict);
  101.                 printf("\n\tsystem dictionary search command: %s\n", cfegrepcmd);
  102.                 return;
  103.         }
  104.  
  105.         /* make sure these variables are null in case they are not set here */
  106.         cfhashname[0] = '\0';    
  107.         cfpersonaldict[0] = '\0';
  108.         cftempname[0] = '\0';
  109.         cfsysdict[0] = '\0';
  110.         cfegrepcmd[0] = '\0';
  111.  
  112.         badline = '\0';
  113.  
  114.         /* get full pathname of executing file */
  115.         if( _emx_env & 0x0200)
  116.                 chptr = GetLoadPath();   /* OS/2 */
  117.         else
  118.                 chptr = argv[0];         /* DOS */
  119.  
  120.         strcpy(confilename, chptr);     
  121.         strcpy(cflibdir, chptr);             
  122.  
  123.         /* check for both type of slashes in ispell path */
  124.         if ( (chptr=strrchr(cflibdir, '\\')) == NULL)        
  125.                 chptr=strrchr(cflibdir, '/');          
  126.  
  127.         strcpy(chptr, "\0");            /* directory where ispell.exe is*/
  128.         chptr=strrchr(confilename, '.');        
  129.         strcpy(chptr+1, "cfg\0");  /* append cfg extension to base file name */
  130.  
  131.         if( (confile = fopen(confilename, "r") ) == NULL )
  132.                 {
  133.                 (void) fprintf(stderr, GSET_C_NO_CONFILE, confilename);
  134.                 exit(0);
  135.                 }
  136.  
  137.         while ( fgets(conbuffo, MAXPATHLEN, confile) != NULL )
  138.                 {
  139.  
  140.                 /* make of copy of the line that was just read - we may have
  141.                  * to print it out if it is invalid. Get rid of '\n' */
  142.                 strcpy(conbuffom, conbuffo);
  143.                 if  ( ( chptr = strchr(conbuffom, '\n') ) != NULL ) 
  144.                         *chptr = '\0';
  145.  
  146.  
  147.                 /* strip out all the blank spaces */
  148.                 contoken = strtok(conbuffo, contokensep);
  149.                 strcpy(conbuff, "\0");
  150.  
  151.                 while( contoken != NULL )
  152.                         {
  153.                         strcat(conbuff, contoken);
  154.                      /* printf("\nconbuffo: %s", conbuffo);
  155.                         printf("\ncontoken: %s", contoken);
  156.                         printf("\nconbuff: %s\n", conbuff); */
  157.                         contoken = ( strtok(NULL, contokensep) );
  158.                         }
  159.  
  160.                 if (conbuff[0] == '#' )     /* check for a comment */
  161.                         {
  162.                         /* fprintf("\ncomment: '%s'", conbuff);*/
  163.                         strcpy(convar, "COMMENT");
  164.                         }
  165.  
  166.                 /* check for a blank line */
  167.                 else if ( strcmp(conbuff, "\n") == 0) 
  168.                         {
  169.                         /* printf("\nblank line"); */
  170.                         strcpy(convar, "COMMENT");
  171.                         } 
  172.          
  173.                 /* Get address of '=' sign. If no '=' sign and not a blank
  174.                  * line, the line must be an invalid line */
  175.                 else if  ( ( chptr = strchr(conbuff, '=') ) == NULL ) 
  176.                                 {
  177.                                 (void) fprintf(stderr, GSET_C_BAD_LINE, conbuffom); 
  178.                                 badline = 1; 
  179.                                 }        
  180.  
  181.                 else    
  182.                         {
  183.                         constrlen = strlen(conbuff);    
  184.                                           /* get length of string */
  185.  
  186.                         convarlen = chptr - conbuff;        
  187.                                           /* length of the variable */
  188.           
  189.                         strncpy(convar, conbuff, convarlen);    
  190.         
  191.                         convar[convarlen] = '\0';          /*append a null */
  192.  
  193.                         strupr(convar);          
  194.                                 /* convert variable to upper case */  
  195.  
  196.  
  197.                          /* load variable setting and check for '\n' */
  198.                          if (conbuff[constrlen-1] == '\n')  
  199.                                /* normal line  - strip off '\n' */
  200.                                {
  201.                                strncpy(consetting, chptr+1, constrlen-convarlen-2);  
  202.                                consetting[constrlen-convarlen-2] = '\0'; 
  203.                                }
  204.                         else
  205.                                /* no '\n' - we must have hit the eof */
  206.                                {
  207.                                strncpy(consetting, chptr+1, constrlen-convarlen-1);  
  208.                                consetting[constrlen-convarlen-1] = '\0'; 
  209.                                }
  210.  
  211.  
  212.                         /*  It is possible that the user had a '#' and a    
  213.                          *  comment after the variable value. Check for this
  214.  
  215.                          *  a '\0'.
  216.                          */                         
  217.                          if  ( ( chptr = strchr(consetting, '#') ) != NULL ) 
  218.                                 *chptr = '\0';
  219.  
  220.                         } /* end else */        
  221.                         
  222.  
  223.                                         
  224.                         if ( strcmp(convar, "ISDEFLANG") == 0 )
  225.                                 strcpy(Lang, consetting);
  226.  
  227.                         else if ( strcmp(convar, "ISDEFHASH") == 0 ) 
  228.                                 strcpy(cfhashname, consetting);
  229.  
  230.                         else if ( strcmp(convar, "ISDEFPDICT") == 0 ) 
  231.                                 strcpy(cfpersonaldict, consetting);
  232.  
  233.                         else if ( strcmp(convar, "ISTEMPNAME") == 0 ) 
  234.                                 strcpy(cftempname, consetting);
  235.  
  236.                         else if ( strcmp(convar, "ISWORDS") == 0 ) 
  237.                                 {
  238.                                 strcpy(cfsysdict, consetting);
  239.                                 }
  240.                         else if ( strcmp(convar, "ISEGREPCMD") == 0 ) 
  241.                                 {
  242.                                 strcpy(cfegrepcmd, consetting);
  243.                                 }
  244.                         else if ( strcmp(convar, "COMMENT") != 0 ) 
  245.                                 {
  246.                                 (void) fprintf(stderr, GSET_C_BAD_OPTION, convar);
  247.                                 exit(0);
  248.                                 }
  249.                 } /* end while */
  250.  
  251.      
  252.  
  253.         if (badline)
  254.                 exit(0);
  255.  
  256.         return ;
  257.  
  258. }
  259.  
  260.  
  261.