00001
00002
00003
00004 #include "cddefines.h"
00005 #include "input.h"
00006 #include "trace.h"
00007 #include "path.h"
00008 #include "parse.h"
00009
00010 void ParseInit(char *chCard )
00011 {
00012 char *ipEndL;
00013 char chLine[FILENAME_PATH_LENGTH_2],
00014 chName[FILENAME_PATH_LENGTH_2];
00015 long int ip,
00016 k;
00017 FILE *ioInitFile;
00018
00019 DEBUG_ENTRY( "ParseInit()" );
00020
00021
00022
00023
00024 if( nMatch( "\'" , chCard ) )
00025 {
00026 fprintf( ioQQQ,
00027 " ParseInit found a single quote on this line. This was used for file names in C90, but double quotes are used now.\n");
00028 fprintf( ioQQQ, " The single quote has been ignored.\n");
00029 }
00030
00031 if( nMatch( "\"" , chCard ) )
00032 {
00033
00034
00035
00036
00037
00038 GetQuote(chName , chCard , true );
00039 }
00040 else
00041 {
00042
00043 strcpy( chName, "cloudy.ini" );
00044 }
00045
00046
00047
00048
00049
00050 if( lgDataPathSet && nMatch("PATH",chCard) )
00051 {
00052
00053 strcpy( chLine , chDataPath );
00054 strcat( chLine , chName );
00055 }
00056 else
00057 {
00058
00059 strcpy( chLine , chName );
00060 }
00061
00062
00063 if( (ioInitFile = fopen( chLine , "r" ) ) == NULL )
00064 {
00065 if( !lgDataPathSet )
00066 {
00067
00068 fprintf( ioQQQ,
00069 " ParseInit could not find initialization file %s\n" ,
00070 chName);
00071 fprintf( ioQQQ, " The path I tried follows:\n" );
00072 fprintf( ioQQQ, " %s\n", chLine );
00073
00074 path_not_set();
00075 puts( "[Stop in ParseInit]" );
00076 cdEXIT(EXIT_FAILURE);
00077 }
00078 else
00079 {
00080
00081 strcpy( chLine , chDataPath );
00082 strcat( chLine , chName );
00083 if( (ioInitFile = fopen( chLine , "r" ) ) == NULL )
00084 {
00085
00086 fprintf( ioQQQ, " ParseInit could not find initialization file %s\n",chName );
00087 fprintf( ioQQQ, " I tried local dir first, then on the path.\n" );
00088 fprintf( ioQQQ, " The path I tried follows:\n" );
00089 fprintf( ioQQQ, " %s\n", chLine );
00090 fprintf( ioQQQ, " The path as set was:\n" );
00091 fprintf( ioQQQ, " %s\n", chDataPath );
00092 fprintf( ioQQQ, " The name was:\n" );
00093 fprintf( ioQQQ, " %s\n", chName );
00094
00095 path_not_set();
00096 puts( "[Stop in ParseInit]" );
00097 cdEXIT(EXIT_FAILURE);
00098 }
00099 }
00100 }
00101
00102
00103 input.nSaveIni = 1;
00104 ip = NKRD + 1 - input.nSaveIni;
00105 while( (fgets( input.chCardSav[ip-1],(int)sizeof(input.chCardSav[ip-1]),ioInitFile)!=NULL ) )
00106 {
00107
00108 ipEndL = strrchr( input.chCardSav[ip-1] , '\n' );
00109
00110 if(ipEndL == NULL )
00111 {
00112 fprintf(ioQQQ," ParseInit read in a init file line that did not end with a newline\n");
00113 fprintf(ioQQQ," line was the following=>%s<=\n",input.chCardSav[ip-1]);
00114 puts( "[Stop in ParseInit]" );
00115 cdEXIT(EXIT_FAILURE);
00116 }
00117
00118
00119 k = (long)(ipEndL - input.chCardSav[ip-1]);
00120
00121 input.chCardSav[ip-1][k] = ' ';
00122
00123 input.chCardSav[ip-1][k+1] = ' ';
00124
00125 input.chCardSav[ip-1][k+2] = '\0';
00126
00127 if( input.chCardSav[ip-1][0]==' ' ) break;
00128
00129
00130 if( lgInputComment(input.chCardSav[ip-1])
00131 )
00132 continue;
00133
00134
00135 if( trace.lgTraceInput )
00136 {
00137 fprintf( ioQQQ,"initt=%s=\n",input.chCardSav[ip-1] );
00138 }
00139
00140 input.nSaveIni += 1;
00141 ip = NKRD + 1 - input.nSaveIni;
00142 if( ip <= input.nSave )
00143 {
00144 fprintf( ioQQQ,
00145 " Too many ini lines. Total of all input and ini lines cannot exceed NKRD, presently%4i\n",
00146 NKRD );
00147 puts( "[Stop in ParseInit]" );
00148 cdEXIT(EXIT_FAILURE);
00149 }
00150 }
00151 fclose(ioInitFile);
00152
00153 input.nSaveIni -= 1;
00154
00155 DEBUG_EXIT( "ParseInit()" );
00156 return;
00157 }