cloudy
trunk
|
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*ParseInit bring an initialization file into input stream before parse */ 00004 #include "cddefines.h" 00005 #include "input.h" 00006 #include "trace.h" 00007 #include "parse.h" 00008 00009 void ParseInit(char *chCard ) 00010 { 00011 char *ipEndL; 00012 char chName[FILENAME_PATH_LENGTH_2]; 00013 long int ip, 00014 k; 00015 FILE *ioInitFile; /* will use this as pointer to ini file */ 00016 00017 DEBUG_ENTRY( "ParseInit()" ); 00018 00019 /*bring an initialization file into input stream before parsing */ 00020 00021 /* check whether single quote on line, this was used in c90 */ 00022 if( nMatch( "\'" , chCard ) ) 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( nMatch( "\"" , chCard ) ) 00030 { 00031 /* 00032 * if a quote occurs on the line then get the ini file name 00033 * this will also set the name in chCard and OrgCard to spaces 00034 * so later keywords do not key off it 00035 */ 00036 GetQuote( chName, chCard, true ); 00037 } 00038 else 00039 { 00040 /* no quote appeared, so this is the default name, cloudy.ini */ 00041 strcpy( chName, "cloudy.ini" ); 00042 } 00043 00044 /* at this point we have init file name, now make full name 00045 * this can be a local file, or on the path if the key path appears */ 00046 00047 /* option to get cloudy.ini from a path */ 00048 if( nMatch("PATH",chCard) ) 00049 { 00050 ioInitFile = open_data( chName, "r" ); 00051 } 00052 else 00053 { 00054 /* just use file name, and try to open file in current directory first */ 00055 ioInitFile = open_data( chName, "r", AS_LOCAL_DATA ); 00056 } 00057 00058 /* at this point the init file is open, now bring it into the command stack */ 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 /* add extra space to be trailing space, needed for commands that end with space */ 00064 ipEndL = strrchr( input.chCardSav[ip-1] , '\n' ); 00065 /* make sure that we found the newline */ 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 /* >>chng 01 oct 22, add cast */ 00073 /* find offset to end of line, the cr */ 00074 k = (long)(ipEndL - input.chCardSav[ip-1]); 00075 /* replace cr with space */ 00076 input.chCardSav[ip-1][k] = ' '; 00077 /* add extra space */ 00078 input.chCardSav[ip-1][k+1] = ' '; 00079 /* finally null terminate the line */ 00080 input.chCardSav[ip-1][k+2] = '\0'; 00081 /* line starting with space is one way to end input stream */ 00082 if( input.chCardSav[ip-1][0]==' ' ) break; 00083 /* totally ignore these lines 00084 * >>chng 06 sep 04 use routine to check for comments */ 00085 if( lgInputComment(input.chCardSav[ip-1]) /*input.chCardSav[ip-1][0]=='#' || input.chCardSav[ip-1][0]=='*' || 00086 input.chCardSav[ip-1][0]=='%' || input.chCardSav[ip-1][0]=='/'*/ ) 00087 continue; 00088 00089 /* print input lines if trace specified */ 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 /* last one with real data is NKRD+1-nSaveIni */ 00107 input.nSaveIni -= 1; 00108 return; 00109 }