home *** CD-ROM | disk | FTP | other *** search
-
-
-
- #include <dos.h>
- #include <stdio.h>
- #include "config.h"
-
- /*
- ******************************************************************************
- Configuration file extractor
- ******************************************************************************
- */
-
- int DecodeConfigFile (char *FileName, struct CFG DataStore[], struct DataCFG DataInfo[])
- {
- FILE *Fp;
- int x,PNum,Index,Instruct,Pos;
- int ch;
- char Comm[30];
-
- int Flag,arr=0;
- char *Text;
-
- Index=0;
-
- if (Fp=fopen(FileName,"rt"))
- {
- do
- {
- ch=getc (Fp);
- if (isalpha(ch)!=0)
- {
- // *** Get Command ***
- Pos=0;
- do
- {
- Comm[Pos++]=(char)toupper(ch);
- ch=getc(Fp);
- }
- while ((isalpha(ch)!=0) || (isdigit(ch)!=0));
-
- Comm[Pos++]=0; //*** Null terminate command ***
-
- Instruct=0;
- Flag=0;
-
- // *** Is command a valid one? ***
- do
- {
- if (strcmp(Comm,DataInfo[Instruct].Command)==NULL)
- {
- Flag=1;
- break;
- }
- Instruct++;
- }
- while (strcmp(DataInfo[Instruct].Command,"ENDOFLIST")!=NULL);
-
- if (Flag==0)
- {
- while ( (ch!=0xa) && (ch!=EOF) )
- ch=getc (Fp);
-
- printf ("Command : %s is not recognised!\n",Comm);
- arr++;
- continue;
- }
-
- DataStore[Index].Command=DataInfo[Instruct].Signature;
-
- if (DataInfo[Instruct].Num==-1)
- {
- Text=DataInfo[Instruct].Pointer;
- PNum=0;
-
- /* Move to first parameter */
- do
- {
- if ( (ch==EOF) || (ch==27) )
- break;
- ch=getc (Fp);
- }
- while ( (ch<33) || (ch>126) );
-
- if ( (ch>32) && (ch<127) )
- do
- {
- Text[PNum++]=ch;
- ch=getc(Fp);
-
- while ( (ch<32) || (ch>127) )
- {
- ch=getc(Fp);
- if ( (ch==27) || (ch==EOF) )
- break;
-
- }
- }
- while ( (ch!=EOF) && (ch!=27) );
-
- Text[PNum]=0;
- }
-
- else
- {
- // *** Get Parameters ***
- PNum=0;
- Pos=0;
- do
- {
- /* Move to first parameter */
- do
- {
- if ((ch==0xa) || (ch==EOF))
- break;
- ch=getc (Fp);
- }
- while ( (ch<33) || (ch>126) );
-
- if ( (ch>32) && (ch<127) )
- {
- /* Read Parameter */
- do
- {
- DataStore[Index].Parameters[PNum][Pos++]=(char)ch;
- ch=getc(Fp);
- }
- while ( (ch>32) && (ch<127) );
-
- DataStore[Index].Parameters[PNum][Pos]=0;
-
- PNum++;
- Pos=0;
- }
- }
- while ((ch!=0xa) && (ch!=EOF));
-
-
- // *** Check command and parameters ***
-
- if (PNum!=DataInfo[Instruct].Num)
- {
- printf ("Command : %d ",DataStore[Index].Command);
- printf ("has %d parameters instead of %d.\n",PNum,DataInfo[Instruct].Num);
- arr++;
- break;
- }
- }
- Index++;
- }
- }
- while (ch!=EOF);
-
- if (arr!=0)
- {
- printf ("%d errors found\n",arr);
- return (0);
- }
- }
- return (Index);
- }
-
-