cloudy trunk
Loading...
Searching...
No Matches
parse_init.cpp
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2 * others. For conditions of distribution and use see copyright notice in license.txt */
3/*ParseInit bring an initialization file into input stream before parse */
4#include "cddefines.h"
5#include "input.h"
6#include "trace.h"
7#include "parser.h"
8
10{
11 char *ipEndL;
12 char chName[FILENAME_PATH_LENGTH_2];
13 long int ip,
14 k;
15 FILE *ioInitFile; /* will use this as pointer to ini file */
16
17 DEBUG_ENTRY( "ParseInit()" );
18
19 /*bring an initialization file into input stream before parsing */
20
21 /* check whether single quote on line, this was used in c90 */
22 if( p.nMatch( "\'" ) )
23 {
24 fprintf( ioQQQ,
25 " ParseInit found a single quote on this line. This was used for file names in C90, but double quotes are used now.\n");
26 fprintf( ioQQQ, " The single quote has been ignored.\n");
27 }
28
29 if( p.nMatch( "\"" ) )
30 {
31 /*
32 * if a quote occurs on the line then get the ini file name
33 * this will also set the name in chCard and OrgCard to spaces
34 * so later keywords do not key off it
35 */
36 p.GetQuote( chName, true );
37 }
38 else
39 {
40 /* no quote appeared, so this is the default name, cloudy.ini */
41 strcpy( chName, "cloudy.ini" );
42 }
43
44 /* at this point we have init file name, now make full name
45 * this can be a local file, or on the path if the key path appears */
46
47 /* option to get cloudy.ini from a path */
48 if( p.nMatch("PATH") )
49 {
50 ioInitFile = open_data( chName, "r" );
51 }
52 else
53 {
54 /* just use file name, and try to open file in current directory first */
55 ioInitFile = open_data( chName, "r", AS_LOCAL_DATA );
56 }
57
58 /* at this point the init file is open, now bring it into the command stack */
59 input.nSaveIni = 1;
60 ip = NKRD + 1 - input.nSaveIni;
61 while( (read_whole_line( input.chCardSav[ip-1],(int)sizeof(input.chCardSav[ip-1]),ioInitFile)!=NULL ) )
62 {
63 /* add extra space to be trailing space, needed for commands that end with space */
64 ipEndL = strrchr( input.chCardSav[ip-1] , '\n' );
65 /* make sure that we found the newline */
66 if(ipEndL == NULL )
67 {
68 fprintf(ioQQQ," ParseInit read in a init file line that did not end with a newline\n");
69 fprintf(ioQQQ," line was the following=>%s<=\n",input.chCardSav[ip-1]);
71 }
72 /* >>chng 01 oct 22, add cast */
73 /* find offset to end of line, the cr */
74 k = (long)(ipEndL - input.chCardSav[ip-1]);
75 /* replace cr with space */
76 input.chCardSav[ip-1][k] = ' ';
77 /* add extra space */
78 input.chCardSav[ip-1][k+1] = ' ';
79 /* finally null terminate the line */
80 input.chCardSav[ip-1][k+2] = '\0';
81 /* line starting with space is one way to end input stream */
82 if( input.chCardSav[ip-1][0]==' ' ) break;
83 /* totally ignore these lines
84 * >>chng 06 sep 04 use routine to check for comments */
85 if( lgInputComment(input.chCardSav[ip-1]) /*input.chCardSav[ip-1][0]=='#' || input.chCardSav[ip-1][0]=='*' ||
86 input.chCardSav[ip-1][0]=='%' || input.chCardSav[ip-1][0]=='/'*/ )
87 continue;
88
89 /* print input lines if trace specified */
90 if( trace.lgTrace )
91 {
92 fprintf( ioQQQ,"initt=%s=\n",input.chCardSav[ip-1] );
93 }
94
95 input.nSaveIni += 1;
96 ip = NKRD + 1 - input.nSaveIni;
97 if( ip <= input.nSave )
98 {
99 fprintf( ioQQQ,
100 " Too many ini lines. Total of all input and ini lines cannot exceed NKRD, presently%4i\n",
101 NKRD );
103 }
104 }
105 fclose(ioInitFile);
106 /* last one with real data is NKRD+1-nSaveIni */
107 input.nSaveIni -= 1;
108 return;
109}
FILE * ioQQQ
Definition cddefines.cpp:7
const int FILENAME_PATH_LENGTH_2
Definition cddefines.h:249
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
Definition service.cpp:70
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
bool nMatch(const char *chKey) const
Definition parser.h:135
int GetQuote(char *chLabel, bool lgABORT)
Definition parser.h:209
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition cpu.cpp:625
@ AS_LOCAL_DATA
Definition cpu.h:208
t_input input
Definition input.cpp:12
bool lgInputComment(const char *chLine)
Definition input.cpp:18
#define NKRD
Definition input.h:10
void ParseInit(Parser &p)
Definition parse_init.cpp:9
t_trace trace
Definition trace.cpp:5