home *** CD-ROM | disk | FTP | other *** search
/ תקליטור אוסף מעל 200 משחקים מרתקים / over-200-games-micro-a-media.iso / CITIZENS / DATA / PLOT / CONFIG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-12  |  3.0 KB  |  163 lines

  1.  
  2.  
  3.  
  4. #include <dos.h>
  5. #include <stdio.h>
  6. #include "config.h"
  7.  
  8. /*
  9. ******************************************************************************
  10.                       Configuration file extractor
  11. ******************************************************************************
  12. */
  13.  
  14. int DecodeConfigFile (char *FileName, struct CFG DataStore[], struct DataCFG DataInfo[])
  15. {
  16.     FILE    *Fp;
  17.     int    x,PNum,Index,Instruct,Pos;
  18.     int    ch;
  19.     char    Comm[30];
  20.  
  21.     int    Flag,arr=0;
  22.     char    *Text;
  23.  
  24.     Index=0;
  25.  
  26.     if (Fp=fopen(FileName,"rt"))
  27.         {
  28.         do
  29.             {
  30.             ch=getc (Fp);
  31.             if (isalpha(ch)!=0)
  32.                 {                
  33.                 // *** Get Command ***
  34.                 Pos=0;
  35.                 do
  36.                     {
  37.                     Comm[Pos++]=(char)toupper(ch);
  38.                     ch=getc(Fp);
  39.                     }
  40.                 while ((isalpha(ch)!=0) || (isdigit(ch)!=0)); 
  41.  
  42.                 Comm[Pos++]=0;             //*** Null terminate command ***
  43.  
  44.                 Instruct=0;
  45.                 Flag=0;
  46.  
  47.                 // *** Is command a valid one? ***
  48.                 do
  49.                     {
  50.                     if (strcmp(Comm,DataInfo[Instruct].Command)==NULL)
  51.                         {
  52.                         Flag=1;
  53.                         break;
  54.                         }
  55.                     Instruct++;
  56.                     }
  57.                 while (strcmp(DataInfo[Instruct].Command,"ENDOFLIST")!=NULL);
  58.  
  59.                 if (Flag==0)
  60.                     {
  61.                     while ( (ch!=0xa) && (ch!=EOF) )
  62.                         ch=getc (Fp);
  63.  
  64.                     printf ("Command : %s is not recognised!\n",Comm);
  65.                     arr++;
  66.                     continue;
  67.                     }
  68.  
  69.                 DataStore[Index].Command=DataInfo[Instruct].Signature;
  70.  
  71.                 if (DataInfo[Instruct].Num==-1)
  72.                     {
  73.                     Text=DataInfo[Instruct].Pointer;
  74.                     PNum=0;
  75.  
  76.                     /* Move to first parameter */
  77.                     do
  78.                         {
  79.                         if ( (ch==EOF) || (ch==27) )
  80.                             break;
  81.                         ch=getc (Fp);
  82.                         }
  83.                     while ( (ch<33) || (ch>126) );
  84.  
  85.                     if ( (ch>32) && (ch<127) )
  86.                         do
  87.                             {
  88.                             Text[PNum++]=ch;
  89.                             ch=getc(Fp);
  90.  
  91.                             while ( (ch<32) || (ch>127) )
  92.                                 {
  93.                                 ch=getc(Fp);
  94.                                 if ( (ch==27) || (ch==EOF) )
  95.                                     break;
  96.  
  97.                                 }
  98.                             }
  99.                         while ( (ch!=EOF) && (ch!=27) );
  100.  
  101.                     Text[PNum]=0;
  102.                     }
  103.  
  104.                 else
  105.                     {
  106.                     // *** Get Parameters ***
  107.                     PNum=0;
  108.                     Pos=0;
  109.                     do
  110.                         {
  111.                         /* Move to first parameter */
  112.                         do
  113.                             {
  114.                             if ((ch==0xa) || (ch==EOF))
  115.                                 break;
  116.                             ch=getc (Fp);
  117.                             }
  118.                         while ( (ch<33) || (ch>126) );
  119.  
  120.                         if ( (ch>32) && (ch<127) )
  121.                             {
  122.                             /* Read Parameter */
  123.                             do
  124.                                 {
  125.                                 DataStore[Index].Parameters[PNum][Pos++]=(char)ch;
  126.                                 ch=getc(Fp);
  127.                                 }
  128.                             while ( (ch>32) && (ch<127) );
  129.  
  130.                             DataStore[Index].Parameters[PNum][Pos]=0;
  131.                         
  132.                             PNum++;
  133.                             Pos=0;
  134.                             }
  135.                         }
  136.                     while ((ch!=0xa) && (ch!=EOF));
  137.  
  138.  
  139.                     // *** Check command and parameters ***
  140.  
  141.                     if (PNum!=DataInfo[Instruct].Num)
  142.                         {
  143.                         printf ("Command : %d  ",DataStore[Index].Command);
  144.                         printf ("has %d parameters instead of %d.\n",PNum,DataInfo[Instruct].Num);
  145.                         arr++;
  146.                         break;
  147.                         }
  148.                     }
  149.                 Index++;
  150.                 }
  151.             }
  152.         while (ch!=EOF);
  153.  
  154.         if (arr!=0)
  155.             {
  156.             printf ("%d errors found\n",arr);
  157.             return (0);
  158.             }
  159.         }    
  160.     return (Index);
  161. }
  162.  
  163.