cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parse_init.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 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 "cddrive.h"
8 #include "parser.h"
9 
10 void ParseInit(Parser &p)
11 {
12  DEBUG_ENTRY( "ParseInit()" );
13 
14  /* bring an initialization file into input stream before parsing */
15 
16  /* check whether single quote on line, this was used in c90 */
17  if( p.nMatch( "\'" ) )
18  {
19  fprintf( ioQQQ,
20  " ParseInit found a single quote on this line. This was used"
21  " for file names in C90, but double quotes are used now.\n" );
22  fprintf( ioQQQ, " The single quote has been ignored.\n" );
23  }
24 
25  string chName;
26  if( p.nMatch( "\"" ) )
27  {
28  /*
29  * if a quote occurs on the line then get the ini file name
30  * this will also set the name in chCard and OrgCard to spaces
31  * so later keywords do not key off it
32  */
33  if( p.GetQuote( chName ) )
34  p.StringError();
35  }
36  else
37  {
38  /* no quote appeared, so this is the default name, cloudy.ini */
39  chName = "cloudy.ini";
40  }
41 
42  /* at this point we have init file name, now make full name
43  * this can be a local file, or on the path if the key path appears */
44 
45  FILE *ioInitFile;
46  /* option to get cloudy.ini from a path */
47  if( p.nMatch("PATH") )
48  {
49  ioInitFile = open_data( chName.c_str(), "r" );
50  }
51  else
52  {
53  /* just use file name, and try to open file in current directory first */
54  ioInitFile = open_data( chName.c_str(), "r", AS_LOCAL_DATA );
55  }
56 
58 
59  /* at this point the init file is open, now bring it into the command stack */
60  char chLocal[INPUT_LINE_LENGTH];
61  while( read_whole_line(chLocal,(int)sizeof(chLocal),ioInitFile) != NULL )
62  {
63  if( lgInputEOF(chLocal) )
64  break;
65 
66  /* stuff the command line into the internal stack */
67  (void)cdRead(chLocal);
68  }
69 
71 
72  fclose(ioInitFile);
73 }
bool nMatch(const char *chKey) const
Definition: parser.h:150
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition: cpu.cpp:765
t_input input
Definition: input.cpp:12
int curInclLevel
Definition: input.h:92
int GetQuote(string &chLabel)
Definition: parser.cpp:213
bool lgInputEOF(const char *chLine)
Definition: input.cpp:84
FILE * ioQQQ
Definition: cddefines.cpp:7
int cdRead(const char *chInputLine)
Definition: cddrive.cpp:1466
Definition: parser.h:43
NORETURN void StringError() const
Definition: parser.cpp:203
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
void ParseInit(Parser &p)
Definition: parse_init.cpp:10
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
Definition: service.cpp:70