00001
00002
00003
00004 #include "cddefines.h"
00005 #include "input.h"
00006 #include "trace.h"
00007 #include "parser.h"
00008
00009 void ParseInit(Parser &p)
00010 {
00011 char *ipEndL;
00012 char chName[FILENAME_PATH_LENGTH_2];
00013 long int ip,
00014 k;
00015 FILE *ioInitFile;
00016
00017 DEBUG_ENTRY( "ParseInit()" );
00018
00019
00020
00021
00022 if( p.nMatch( "\'" ) )
00023 {
00024 fprintf( ioQQQ,
00025 " ParseInit found a single quote on this line. This was used for file names in C90, but double quotes are used now.\n");
00026 fprintf( ioQQQ, " The single quote has been ignored.\n");
00027 }
00028
00029 if( p.nMatch( "\"" ) )
00030 {
00031
00032
00033
00034
00035
00036 p.GetQuote( chName, true );
00037 }
00038 else
00039 {
00040
00041 strcpy( chName, "cloudy.ini" );
00042 }
00043
00044
00045
00046
00047
00048 if( p.nMatch("PATH") )
00049 {
00050 ioInitFile = open_data( chName, "r" );
00051 }
00052 else
00053 {
00054
00055 ioInitFile = open_data( chName, "r", AS_LOCAL_DATA );
00056 }
00057
00058
00059 input.nSaveIni = 1;
00060 ip = NKRD + 1 - input.nSaveIni;
00061 while( (read_whole_line( input.chCardSav[ip-1],(int)sizeof(input.chCardSav[ip-1]),ioInitFile)!=NULL ) )
00062 {
00063
00064 ipEndL = strrchr( input.chCardSav[ip-1] , '\n' );
00065
00066 if(ipEndL == NULL )
00067 {
00068 fprintf(ioQQQ," ParseInit read in a init file line that did not end with a newline\n");
00069 fprintf(ioQQQ," line was the following=>%s<=\n",input.chCardSav[ip-1]);
00070 cdEXIT(EXIT_FAILURE);
00071 }
00072
00073
00074 k = (long)(ipEndL - input.chCardSav[ip-1]);
00075
00076 input.chCardSav[ip-1][k] = ' ';
00077
00078 input.chCardSav[ip-1][k+1] = ' ';
00079
00080 input.chCardSav[ip-1][k+2] = '\0';
00081
00082 if( input.chCardSav[ip-1][0]==' ' ) break;
00083
00084
00085 if( lgInputComment(input.chCardSav[ip-1])
00086 )
00087 continue;
00088
00089
00090 if( trace.lgTrace )
00091 {
00092 fprintf( ioQQQ,"initt=%s=\n",input.chCardSav[ip-1] );
00093 }
00094
00095 input.nSaveIni += 1;
00096 ip = NKRD + 1 - input.nSaveIni;
00097 if( ip <= input.nSave )
00098 {
00099 fprintf( ioQQQ,
00100 " Too many ini lines. Total of all input and ini lines cannot exceed NKRD, presently%4i\n",
00101 NKRD );
00102 cdEXIT(EXIT_FAILURE);
00103 }
00104 }
00105 fclose(ioInitFile);
00106
00107 input.nSaveIni -= 1;
00108 return;
00109 }