Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 11 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | * $Id: cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ ** |
2 | * $Id: cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ ** |
3 | Author: Kevin Ross (x6143) |
3 | Author: Kevin Ross (x6143) |
4 | 4 | ||
5 | Philips Semiconductors Limited. |
5 | Philips Semiconductors Limited. |
6 | 6 | ||
7 | Millbrook Industrial Estate, Southampton, SO9 7BH. England. |
7 | Millbrook Industrial Estate, Southampton, SO9 7BH. England. |
8 | 8 | ||
9 | Date: 31st March 1993 |
9 | Date: 31st March 1993 |
10 | 10 | ||
11 | General command line to string or numeric variable reading |
11 | General command line to string or numeric variable reading |
12 | 12 | ||
13 | Modified for command line parsing for EPLD multi-fitter program |
13 | Modified for command line parsing for EPLD multi-fitter program |
14 | Mike James 7 Feb 1996 |
14 | Mike James 7 Feb 1996 |
Line 78... | Line 78... | ||
78 | Mike put it here |
78 | Mike put it here |
79 | 79 | ||
80 | 80 | ||
81 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
81 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
82 | * COnversion to Vertical2, supports signals and components |
82 | * COnversion to Vertical2, supports signals and components |
83 | * |
83 | * |
84 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
84 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
85 | * Part of Release PSAVAT01 |
85 | * Part of Release PSAVAT01 |
86 | * |
86 | * |
87 | * Revision 1.33 2000/10/02 11:04:10 11:04:10 mjames (Mike James) |
87 | * Revision 1.33 2000/10/02 11:04:10 11:04:10 mjames (Mike James) |
88 | * new_vhdl |
88 | * new_vhdl |
89 | * |
89 | * |
90 | * Revision 1.32 2000/09/27 14:42:10 14:42:10 mjames (Mike James) |
90 | * Revision 1.32 2000/09/27 14:42:10 14:42:10 mjames (Mike James) |
91 | * Part of Release Sep_27_ST_2000 |
91 | * Part of Release Sep_27_ST_2000 |
92 | * |
92 | * |
93 | * Revision 1.31 2000/09/21 10:15:40 10:15:40 mjames (Mike James) |
93 | * Revision 1.31 2000/09/21 10:15:40 10:15:40 mjames (Mike James) |
94 | * Part of Release Sep21Alpha |
94 | * Part of Release Sep21Alpha |
95 | * |
95 | * |
96 | * Revision 1.30 2000/08/25 09:57:09 09:57:09 mjames (Mike James) |
96 | * Revision 1.30 2000/08/25 09:57:09 09:57:09 mjames (Mike James) |
97 | * Part of Release Aug25_alpha |
97 | * Part of Release Aug25_alpha |
98 | * |
98 | * |
99 | * Revision 1.29 2000/08/16 08:57:26 08:57:26 mjames (Mike James) |
99 | * Revision 1.29 2000/08/16 08:57:26 08:57:26 mjames (Mike James) |
100 | * Part of Release CD01_Aug2000 |
100 | * Part of Release CD01_Aug2000 |
101 | * |
101 | * |
102 | * Revision 1.28 2000/08/14 14:45:07 14:45:07 mjames (Mike James) |
102 | * Revision 1.28 2000/08/14 14:45:07 14:45:07 mjames (Mike James) |
103 | * Part of Release Aug_14_2000 |
103 | * Part of Release Aug_14_2000 |
104 | * |
104 | * |
105 | * Revision 1.27 2000/08/11 08:30:28 08:30:28 mjames (Mike James) |
105 | * Revision 1.27 2000/08/11 08:30:28 08:30:28 mjames (Mike James) |
106 | * Part of Release Aug_11_2000 |
106 | * Part of Release Aug_11_2000 |
107 | * |
107 | * |
108 | * Revision 1.26 2000/08/09 10:31:41 10:31:41 mjames (Mike James) |
108 | * Revision 1.26 2000/08/09 10:31:41 10:31:41 mjames (Mike James) |
109 | * Part of Release Aug__9_2000 |
109 | * Part of Release Aug__9_2000 |
110 | * |
110 | * |
111 | * Revision 1.25 2000/05/31 11:42:48 11:42:48 mjames (Mike James) |
111 | * Revision 1.25 2000/05/31 11:42:48 11:42:48 mjames (Mike James) |
112 | * Part of Release May_31_2000 |
112 | * Part of Release May_31_2000 |
113 | * |
113 | * |
114 | * Revision 1.24 2000/05/08 17:01:33 17:01:33 mjames (Mike James) |
114 | * Revision 1.24 2000/05/08 17:01:33 17:01:33 mjames (Mike James) |
115 | * Part of Release May__8_2000 |
115 | * Part of Release May__8_2000 |
116 | * |
116 | * |
117 | * Revision 1.23 2000/05/08 16:59:26 16:59:26 mjames (Mike James) |
117 | * Revision 1.23 2000/05/08 16:59:26 16:59:26 mjames (Mike James) |
118 | * Part of Release May__8_2000 |
118 | * Part of Release May__8_2000 |
119 | * |
119 | * |
120 | * Revision 1.22 2000/05/08 16:57:03 16:57:03 mjames (Mike James) |
120 | * Revision 1.22 2000/05/08 16:57:03 16:57:03 mjames (Mike James) |
121 | * Part of Release May__8_2000 |
121 | * Part of Release May__8_2000 |
122 | * |
122 | * |
123 | * Revision 1.21 2000/03/08 16:18:44 16:18:44 mjames (Mike James) |
123 | * Revision 1.21 2000/03/08 16:18:44 16:18:44 mjames (Mike James) |
124 | * New version including PC |
124 | * New version including PC |
125 | * |
125 | * |
126 | * Revision 1.18 2000/01/20 15:58:41 15:58:41 mjames (Mike James) |
126 | * Revision 1.18 2000/01/20 15:58:41 15:58:41 mjames (Mike James) |
127 | * Part of Release R22 |
127 | * Part of Release R22 |
128 | * |
128 | * |
129 | * Revision 1.17 99/12/22 11:15:22 11:15:22 mjames (Mike James) |
129 | * Revision 1.17 99/12/22 11:15:22 11:15:22 mjames (Mike James) |
130 | * Part of Release Dec_22_1999 |
130 | * Part of Release Dec_22_1999 |
131 | * |
131 | * |
132 | * Revision 1.16 99/06/25 14:34:40 14:34:40 mjames (Mike James) |
132 | * Revision 1.16 99/06/25 14:34:40 14:34:40 mjames (Mike James) |
133 | * Added in reference to expression.h, but no changes made |
133 | * Added in reference to expression.h, but no changes made |
134 | * to the function of acfread yet. |
134 | * to the function of acfread yet. |
135 | * |
135 | * |
136 | * Revision 1.15 99/06/18 09:23:13 09:23:13 mjames (Mike James) |
136 | * Revision 1.15 99/06/18 09:23:13 09:23:13 mjames (Mike James) |
137 | * |
137 | * |
138 | * Revision 1.14 1999/06/14 10:54:11 mjames |
138 | * Revision 1.14 1999/06/14 10:54:11 mjames |
139 | * *** empty log message *** |
139 | * *** empty log message *** |
140 | * |
140 | * |
141 | * Revision 1.14 1999/06/14 10:54:11 mjames |
141 | * Revision 1.14 1999/06/14 10:54:11 mjames |
142 | * *** empty log message *** |
142 | * *** empty log message *** |
143 | * |
143 | * |
144 | * Revision 1.13 98/03/16 11:37:05 11:37:05 mjames (Mike James) |
144 | * Revision 1.13 98/03/16 11:37:05 11:37:05 mjames (Mike James) |
145 | * Added LOG_ERROR to logging system . Allows output of serious errors to stderr |
145 | * Added LOG_ERROR to logging system . Allows output of serious errors to stderr |
146 | * |
146 | * |
147 | * Revision 1.12 98/02/11 11:25:47 11:25:47 mjames (Mike James) |
147 | * Revision 1.12 98/02/11 11:25:47 11:25:47 mjames (Mike James) |
148 | * Checked in for version 6.2a |
148 | * Checked in for version 6.2a |
149 | * |
149 | * |
150 | * Revision 1.11 97/04/23 08:42:47 08:42:47 mjames (Mike James) |
150 | * Revision 1.11 97/04/23 08:42:47 08:42:47 mjames (Mike James) |
151 | * CHecked in for release rel23041997 |
151 | * CHecked in for release rel23041997 |
152 | * |
152 | * |
153 | * Revision 1.10 96/07/19 14:38:13 14:38:13 mjames (Mike James) |
153 | * Revision 1.10 96/07/19 14:38:13 14:38:13 mjames (Mike James) |
154 | * Added list of objects to SET DEL EXT commands |
154 | * Added list of objects to SET DEL EXT commands |
155 | * |
155 | * |
156 | * Revision 1.9 1996/07/12 15:52:12 mjames |
156 | * Revision 1.9 1996/07/12 15:52:12 mjames |
157 | * Sorted out things like Alias and Jumpers |
157 | * Sorted out things like Alias and Jumpers |
158 | * Work Correctly |
158 | * Work Correctly |
159 | * Print COrrectly |
159 | * Print COrrectly |
160 | * |
160 | * |
161 | * Revision 1.8 96/05/21 14:14:52 14:14:52 mjames (Mike James) |
161 | * Revision 1.8 96/05/21 14:14:52 14:14:52 mjames (Mike James) |
162 | * Altered return codes form utilities to be a more accurate |
162 | * Altered return codes form utilities to be a more accurate |
163 | * representation of reality. |
163 | * representation of reality. |
164 | * |
164 | * |
165 | * Revision 1.7 96/03/29 14:46:03 14:46:03 mjames (Mike James) |
165 | * Revision 1.7 96/03/29 14:46:03 14:46:03 mjames (Mike James) |
166 | * Added VHDL netlist writing to the capabilities of ACFREAD |
166 | * Added VHDL netlist writing to the capabilities of ACFREAD |
167 | * |
167 | * |
168 | * Revision 1.6 96/03/18 13:50:27 13:50:27 mjames (Mike James) |
168 | * Revision 1.6 96/03/18 13:50:27 13:50:27 mjames (Mike James) |
169 | * Real Revision 2.1 |
169 | * Real Revision 2.1 |
170 | * |
170 | * |
171 | * Revision 1.4 96/02/13 09:13:13 09:13:13 mjames (Mike James) |
171 | * Revision 1.4 96/02/13 09:13:13 09:13:13 mjames (Mike James) |
172 | * Updated to be version 2.0 with net joining |
172 | * Updated to be version 2.0 with net joining |
173 | * |
173 | * |
174 | * Revision 1.3 96/02/08 15:28:12 15:28:12 mjames (Mike James) |
174 | * Revision 1.3 96/02/08 15:28:12 15:28:12 mjames (Mike James) |
175 | * First release |
175 | * First release |
176 | * |
176 | * |
177 | * Revision 1.2 96/02/07 16:01:23 16:01:23 mjames (Mike James) |
177 | * Revision 1.2 96/02/07 16:01:23 16:01:23 mjames (Mike James) |
178 | * Added correct RCS header |
178 | * Added correct RCS header |
179 | * |
179 | * |
180 | * Revision 1.1 96/02/07 15:49:47 15:49:47 mjames (Mike James) |
180 | * Revision 1.1 96/02/07 15:49:47 15:49:47 mjames (Mike James) |
181 | * Initial revision |
181 | * Initial revision |
182 | * |
182 | * |
183 | **********************************************************************************************************/ |
183 | **********************************************************************************************************/ |
184 | 184 | ||
- | 185 | #include <stdio.h> |
|
- | 186 | #include <string.h> |
|
185 | #include "cmdutil.h" |
187 | #include <stdlib.h> |
- | 188 | #include <ctype.h> |
|
- | 189 | #include <sys/stat.h> |
|
186 | 190 | ||
187 | #include "cmdlog.h" |
191 | #include "vertcl_main.h" |
188 | #include "cmdparse.h" |
192 | #include "cmdparse.h" |
189 | #include "database.h" |
193 | #include "cmdutil.h" |
- | 194 | #include "cmdlog.h" |
|
190 | #include "expression.h" |
195 | #include "expression.h" |
191 | #include "generic.h" |
196 | #include "generic.h" |
- | 197 | #include "database.h" |
|
192 | #include "lx_support.h" |
198 | #include "lx_support.h" |
193 | #include "vertcl_main.h" |
- | |
194 | 199 | ||
195 | #include <ctype.h> |
- | |
196 | #include <stdio.h> |
- | |
197 | #include <stdlib.h> |
- | |
198 | #include <string.h> |
- | |
199 | #include <sys/stat.h> |
- | |
200 | - | ||
201 | #ident \ |
- | |
202 | "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $" |
200 | #ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $" |
203 | 201 | ||
204 | /***************************************************************/ |
202 | /***************************************************************/ |
205 | /* this routine is used to trap opening read-only files for write */ |
203 | /* this routine is used to trap opening read-only files for write */ |
206 | /* writing files is always into the current directory. Reading uses a search path */ |
204 | /* writing files is always into the current directory. Reading uses a search path */ |
207 | /* #if defined IS_HPUX */ |
205 | /* #if defined IS_HPUX */ |
208 | 206 | ||
209 | #if 1 |
207 | #if 1 |
210 | #define safe_fopen fopen |
208 | #define safe_fopen fopen |
211 | #else |
209 | #else |
212 | #define safe_fopen nt_fopen |
210 | #define safe_fopen nt_fopen |
213 | 211 | ||
214 | /* and then define the NT protection function */ |
212 | /* and then define the NT protection function */ |
215 | FILE *nt_fopen (char *name, char *mode) |
213 | FILE * nt_fopen(char * name, char * mode) |
216 | { |
214 | { |
217 | struct stat buf; |
215 | struct stat buf; |
218 | if (ISNULLSTR (name)) |
216 | if(ISNULLSTR(name)) |
219 | { |
217 | { |
220 | return (NULL); |
218 | return(NULL); |
221 | } |
219 | } |
222 | stat (name, &buf); |
220 | stat( name,&buf ); |
223 | if (level & 16) |
221 | if(level & 16) |
224 | { |
222 | { |
225 | printf ("stat %08o '%s' '%s'\n", buf.st_mode, name, mode); |
223 | printf("stat %08o '%s' '%s'\n",buf.st_mode,name,mode); |
226 | } |
224 | } |
227 | /* no file there attempt open anyway */ |
225 | /* no file there attempt open anyway */ |
228 | if (buf.st_mode == 0) |
226 | if (buf.st_mode == 0) |
229 | { |
227 | { |
230 | return (fopen (name, mode)); |
228 | return (fopen(name,mode)); |
231 | } |
229 | } |
232 | if (S_ISREG (buf.st_mode)) |
230 | if (S_ISREG(buf.st_mode )) |
233 | { |
231 | { |
234 | if (((mode[0] == 'w') && ((buf.st_mode & S_IRWXU) == S_IWUSR)) || |
232 | if(((mode[0]=='w') && ((buf.st_mode & S_IRWXU)==S_IWUSR)) || |
235 | ((mode[0] == 'r') && ((buf.st_mode & S_IRWXU) == S_IRUSR))) |
233 | ((mode[0]=='r') && ((buf.st_mode & S_IRWXU)==S_IRUSR))) |
236 | { |
234 | { |
237 | return (fopen (name, mode)); |
235 | return (fopen(name,mode)); |
238 | } |
236 | } |
239 | } |
237 | } |
240 | return NULL; |
238 | return NULL; |
241 | }; |
239 | }; |
242 | #endif |
240 | #endif |
243 | 241 | ||
244 | /* we only search for 'r' mode files down the search path */ |
242 | /* we only search for 'r' mode files down the search path */ |
245 | /* or if name does not start with '.' or '/' and does not contain ':' on a PC */ |
243 | /* or if name does not start with '.' or '/' and does not contain ':' on a PC */ |
246 | FILE *trap_fopen (char *name, char *mode) |
244 | FILE * trap_fopen(char * name, char * mode) |
247 | { |
245 | { |
248 | FILE *f; |
246 | FILE * f; |
249 | #if defined HP_UX |
247 | #if defined HP_UX |
250 | if (strcmp ("r", mode) != 0 || name[0] == '/' || name[0] == '.') |
248 | if (strcmp("r",mode)!=0 || name[0]=='/' || name[0] == '.' ) |
251 | #else |
249 | #else |
252 | if (strcmp ("r", mode) != 0 || name[0] == '/' || name[0] == '.' || strchr (name, ':')) |
250 | if (strcmp("r",mode)!=0 || name[0]=='/' || name[0] == '.' || strchr(name,':') ) |
253 | #endif |
251 | #endif |
254 | { |
252 | { |
255 | if (level & 16) |
253 | if(level & 16) |
256 | printf ("Trying to open '%s' (no path) mode '%s'\n", name, mode); |
254 | printf("Trying to open '%s' (no path) mode '%s'\n",name,mode); |
257 | f = (safe_fopen (name, mode)); |
255 | f= (safe_fopen(name,mode)); |
258 | } |
256 | } |
259 | else |
257 | else |
260 | { |
258 | { |
261 | char *sp; |
259 | char * sp; |
262 | char pathbuff[MAXIDLEN]; |
260 | char pathbuff [MAXIDLEN]; |
263 | char namebuff[MAXIDLEN]; |
261 | char namebuff [MAXIDLEN]; |
264 | expand_string ("$(VERTICAL_PATH)", pathbuff, 0, NULL); |
262 | expand_string( "$(VERTICAL_PATH)" ,pathbuff, 0, NULL) ; |
265 | f = NULL; |
263 | f = NULL; |
266 | 264 | ||
267 | for (sp = pathbuff; (f == NULL) && (sp = strtok (sp, ";")); sp = NULL) |
265 | for(sp=pathbuff;(f == NULL) && (sp=strtok(sp,";")) ;sp=NULL) |
268 | { |
266 | { |
269 | sprintf (namebuff, "%s/%s", sp, name); /* make up pathname */ |
267 | sprintf(namebuff,"%s/%s",sp,name); /* make up pathname */ |
270 | if (level & 16) |
268 | if(level & 16) |
271 | printf ("Trying to open '%s' mode '%s'\n", namebuff, mode); |
269 | printf("Trying to open '%s' mode '%s'\n",namebuff,mode); |
272 | f = safe_fopen (namebuff, mode); |
270 | f = safe_fopen(namebuff,mode); |
273 | } |
271 | } |
274 | } |
272 | } |
275 | if (level & 16) |
273 | if(level & 16) |
276 | { |
274 | { |
277 | printf ("File Pointer returned = %p\n", f); |
275 | printf("File Pointer returned = %p\n",f); |
278 | } |
276 | } |
279 | return f; |
277 | return f; |
280 | }; |
278 | }; |
281 | 279 | ||
282 | /*********************************************************************************************************/ |
280 | /*********************************************************************************************************/ |
283 | int ConvertToDecimal (char *Input, long *Output) |
281 | int ConvertToDecimal (char *Input, long *Output) |
284 | { |
282 | { |
285 | int Base = 10, Stat = OKCMD; |
283 | int Base = 10, Stat = OKCMD; |
286 | char *CurrentChar, *End; |
284 | char *CurrentChar, *End; |
287 | 285 | ||
288 | CurrentChar = Input; |
286 | CurrentChar = Input; |
289 | while (*CurrentChar && *CurrentChar == ' ') |
287 | while(*CurrentChar && *CurrentChar ==' ') |
290 | { |
288 | { |
291 | CurrentChar++; |
289 | CurrentChar++; |
292 | } |
290 | } |
293 | if (*CurrentChar == '0') |
291 | if (*CurrentChar == '0') |
294 | { |
292 | { |
295 | CurrentChar++; /* Read first character to calculate the base */ |
293 | CurrentChar++; /* Read first character to calculate the base */ |
296 | switch (*CurrentChar) |
294 | switch(*CurrentChar) |
297 | { |
295 | { |
298 | case '\0': |
- | |
299 | *Output = 0; |
- | |
300 | return (OKCMD); /* Trap for single digit zero */ |
296 | case '\0' : *Output=0; return (OKCMD); /* Trap for single digit zero */ |
301 | case 'x': |
- | |
302 | Base = 16; |
- | |
303 | CurrentChar++; |
297 | case 'x' : Base=16; CurrentChar++; break; |
304 | break; |
- | |
305 | case 'b': |
- | |
306 | Base = 2; |
- | |
307 | CurrentChar++; |
298 | case 'b' : Base=2; CurrentChar++; break; |
308 | break; |
- | |
309 | default: |
- | |
310 | Base = 8; |
- | |
311 | break; /* Default base is octal */ |
299 | default : Base=8; break; /* Default base is octal */ |
312 | } |
300 | } |
313 | } |
301 | } |
314 | else |
302 | else |
315 | { |
303 | { |
316 | if (isdigit (*CurrentChar)) |
304 | if (isdigit(*CurrentChar)) |
317 | { |
305 | { |
318 | Base = 10; |
306 | Base=10; |
319 | } |
307 | } |
320 | else |
308 | else |
321 | { |
309 | { |
322 | Stat = FAILED; |
310 | Stat =FAILED; |
323 | } |
311 | } |
324 | } |
312 | } |
325 | if (Stat == OKCMD) |
313 | if(Stat==OKCMD) |
326 | { |
314 | { |
327 | *Output = strtol (CurrentChar, &End, Base); |
315 | *Output = strtol(CurrentChar, &End, Base); |
328 | } |
316 | } |
329 | if (*End != 0) |
317 | if (*End != 0 ) |
330 | { |
318 | { |
331 | Stat = FAILED; |
319 | Stat = FAILED; |
332 | } |
320 | } |
333 | return (Stat); |
321 | return(Stat); |
- | 322 | } |
|
334 | } |
323 | |
335 | 324 | ||
336 | void set_debug_level (int lev) |
325 | void set_debug_level(int lev) |
337 | { |
326 | { |
338 | level = lev; |
327 | level = lev; |
- | 328 | } |
|
339 | } |
329 |