added README_changes.txt
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / src.org / scanutil.c
blobcd992aee4e2205c472c8b1845500dd645ce9b9ac
1 /******************************************************************************
3 KPP - The Kinetic PreProcessor
4 Builds simulation code for chemical kinetic systems
6 Copyright (C) 1995-1996 Valeriu Damian and Adrian Sandu
7 Copyright (C) 1997-2005 Adrian Sandu
9 KPP is free software; you can redistribute it and/or modify it under the
10 terms of the GNU General Public License as published by the Free Software
11 Foundation (http://www.gnu.org/copyleft/gpl.html); either version 2 of the
12 License, or (at your option) any later version.
14 KPP is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, consult http://www.gnu.org/copyleft/gpl.html or
21 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
24 Adrian Sandu
25 Computer Science Department
26 Virginia Polytechnic Institute and State University
27 Blacksburg, VA 24060
28 E-mail: sandu@cs.vt.edu
30 ******************************************************************************/
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <malloc.h>
36 #include <unistd.h>
37 #include <string.h>
38 #include "gdata.h"
39 #include "scan.h"
41 #define MAX_BUFFER 200
43 void ScanError( char *fmt, ... )
45 Va_list args;
46 char buf[ MAX_BUFFER ];
48 Va_start( args, fmt );
49 vsprintf( buf, fmt, args );
50 va_end( args );
51 fprintf( stdout, "Error :%s:%d: %s\n", crt_filename, crt_line_no, buf );
52 nError++;
55 void ParserError( char *fmt, ... )
57 Va_list args;
58 char buf[ MAX_BUFFER ];
60 Va_start( args, fmt );
61 vsprintf( buf, fmt, args );
62 va_end( args );
63 fprintf( stdout, "Error :%s:%d: %s\n", crtFile, crtLine, buf );
64 nError++;
67 void ScanWarning( char *fmt, ... )
69 Va_list args;
70 char buf[ MAX_BUFFER ];
72 Va_start( args, fmt );
73 vsprintf( buf, fmt, args );
74 va_end( args );
75 fprintf( stdout, "Warning :%s:%d: %s\n", crt_filename, crt_line_no, buf );
76 nWarning++;
79 void ParserWarning( char *fmt, ... )
81 Va_list args;
82 char buf[ MAX_BUFFER ];
84 Va_start( args, fmt );
85 vsprintf( buf, fmt, args );
86 va_end( args );
87 fprintf( stdout, "Warning :%s:%d: %s\n", crtFile, crtLine, buf );
88 nWarning++;
91 void Error( char *fmt, ... )
93 Va_list args;
94 char buf[ MAX_BUFFER ];
96 Va_start( args, fmt );
97 vsprintf( buf, fmt, args );
98 va_end( args );
99 fprintf( stdout, "Error : %s\n", buf );
100 nError++;
103 void Warning( char *fmt, ... )
105 Va_list args;
106 char buf[ MAX_BUFFER ];
108 Va_start( args, fmt );
109 vsprintf( buf, fmt, args );
110 va_end( args );
111 fprintf( stdout, "Warning : %s\n", buf );
112 nWarning++;
115 void Message( char *fmt, ... )
117 Va_list args;
118 char buf[ MAX_BUFFER ];
120 Va_start( args, fmt );
121 vsprintf( buf, fmt, args );
122 va_end( args );
123 fprintf( stdout, " Message :%s:%d: %s\n", crt_filename, crt_line_no, buf );
126 void FatalError( int status, char *fmt, ... )
128 Va_list args;
129 char buf[ MAX_BUFFER ];
131 Va_start( args, fmt );
132 vsprintf( buf, fmt, args );
133 va_end( args );
134 fprintf( stdout, "\nFatal error : %s\nProgram aborted\n", buf );
135 exit(status);
138 char * FileName( char *fname, char *env, char *dir, char *ext )
140 static char pathname[MAX_PATH];
141 char *path;
142 char *crtpath;
143 char *p;
144 FILE *fp;
145 static char name[MAX_PATH];
146 int noext;
148 strcpy(name, fname);
149 p = name + strlen(name);
150 noext = 1;
151 while( p > name ) {
152 if( *p == '.') {
153 noext = 0;
154 break;
156 if( *p == '/' ) break;
157 p--;
160 if( noext ) strcat(name, ext);
162 fp = fopen(name,"r");
163 if( fp ) {
164 fclose(fp);
165 return name;
168 path = getenv(env);
169 if( path ) {
170 crtpath = path;
171 p = pathname;
172 while( 1 ) {
173 if( isspace(*crtpath) ) {
174 crtpath++;
175 continue;
177 if((*crtpath == ':')||(*crtpath==0)) {
178 *p = 0;
179 sprintf(pathname,"%s/%s",pathname,name);
180 fp = fopen(pathname,"r");
181 if( fp ) {
182 fclose(fp);
183 return pathname;
185 if (*crtpath==0) break;
186 crtpath++;
187 p = pathname;
188 continue;
190 *p++ = *crtpath++;
194 sprintf(pathname, "%s/%s/%s", Home, dir, name);
195 fp = fopen(pathname,"r");
196 if( fp ) {
197 fclose(fp);
198 return pathname;
201 return name;