source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp/src/scanutil.c @ 3698

Last change on this file since 3698 was 2696, checked in by kanani, 7 years ago

Merge of branch palm4u into trunk

File size: 4.3 KB
Line 
1/******************************************************************************
2
3  KPP - The Kinetic PreProcessor
4        Builds simulation code for chemical kinetic systems
5
6  Copyright (C) 1995-1996 Valeriu Damian and Adrian Sandu
7  Copyright (C) 1997-2005 Adrian Sandu
8
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.
13
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.
18
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.
23
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
29
30******************************************************************************/
31
32
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"
40
41#define MAX_BUFFER 200
42
43void ScanError( char *fmt, ... )
44{
45Va_list args;
46char buf[ MAX_BUFFER ];
47
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++;
53}
54
55void ParserError( char *fmt, ...  )
56{
57Va_list args;
58char buf[ MAX_BUFFER ];
59
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++;
65}
66
67void ScanWarning( char *fmt, ...  )
68{
69Va_list args;
70char buf[ MAX_BUFFER ];
71
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++;
77}
78
79void ParserWarning( char *fmt, ...  )
80{
81Va_list args;
82char buf[ MAX_BUFFER ];
83
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++;
89}
90
91void Error( char *fmt, ...  )
92{
93Va_list args;
94char buf[ MAX_BUFFER ];
95
96  Va_start( args, fmt );
97  vsprintf( buf, fmt, args );
98  va_end( args );
99  fprintf( stdout, "Error : %s\n", buf );
100  nError++;
101}
102
103void Warning( char *fmt, ...  )
104{
105Va_list args;
106char buf[ MAX_BUFFER ];
107
108  Va_start( args, fmt );
109  vsprintf( buf, fmt, args );
110  va_end( args );
111  fprintf( stdout, "Warning : %s\n", buf );
112  nWarning++;
113}
114
115void Message( char *fmt, ...  )
116{
117Va_list args;
118char buf[ MAX_BUFFER ];
119
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 );
124}
125
126void FatalError( int status, char *fmt, ... )
127{
128Va_list args;
129char buf[ MAX_BUFFER ];
130
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);
136}
137
138char * FileName( char *fname, char *env, char *dir, char *ext )
139{
140static char pathname[MAX_PATH];
141char *path;
142char *crtpath;
143char *p;
144FILE *fp;
145static char name[MAX_PATH];
146int noext;
147
148  strcpy(name, fname);
149  p = name + strlen(name);
150  noext = 1;
151  while( p > name ) { 
152    if( *p == '.') {
153      noext = 0; 
154      break;
155    }
156    if( *p == '/' ) break;
157    p--;
158  } 
159
160  if( noext ) strcat(name, ext);
161
162  fp = fopen(name,"r");
163  if( fp ) {
164    fclose(fp);
165    return name;
166  } 
167   
168  path = getenv(env); 
169  if( path ) {
170    crtpath = path;
171    p = pathname;
172    while( 1 ) {
173      if( isspace(*crtpath) ) {
174        crtpath++;
175        continue;
176      }
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;
184        } 
185        if (*crtpath==0) break;
186        crtpath++;
187        p = pathname;
188        continue;
189      }
190      *p++ = *crtpath++;
191    }
192  }
193 
194  sprintf(pathname, "%s/%s/%s", Home, dir, name);
195  fp = fopen(pathname,"r");
196  if( fp ) {
197    fclose(fp);
198    return pathname;
199  } 
200   
201  return name;
202}
Note: See TracBrowser for help on using the repository browser.