Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
11 | mjames | 1 | /** |
2 | * $Id: cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ ** |
||
3 | Author: Kevin Ross (x6143) |
||
2 | mjames | 4 | |
11 | mjames | 5 | Philips Semiconductors Limited. |
2 | mjames | 6 | |
11 | mjames | 7 | Millbrook Industrial Estate, Southampton, SO9 7BH. England. |
2 | mjames | 8 | |
11 | mjames | 9 | Date: 31st March 1993 |
2 | mjames | 10 | |
11 | General command line to string or numeric variable reading |
||
12 | |||
13 | Modified for command line parsing for EPLD multi-fitter program |
||
14 | Mike James 7 Feb 1996 |
||
15 | |||
16 | * $Log: cmdutil.c,v $ |
||
17 | * Revision 1.1.1.1 2003/11/04 23:34:56 mjames |
||
18 | * Imported into local repositrory |
||
19 | * |
||
20 | * Revision 1.13 2002/09/09 10:26:56 mjames |
||
21 | * Removed set generic range and replaced it with a set generic value command |
||
22 | * that takes both integers and ranges. |
||
23 | * |
||
24 | * Revision 1.12 2002/08/14 11:56:13 mjames |
||
25 | * Removed NT specific file opening , as recent Cygwin DLL does not |
||
26 | * like the code I was using to protect NT from screwing up on opening |
||
27 | * read-only files for write (it crashes as the first byte is written) |
||
28 | * |
||
29 | * Revision 1.11 2002/08/06 12:52:59 mjames |
||
30 | * Merge in from latest version |
||
31 | * |
||
32 | * |
||
33 | Revision 1.12 2002/04/10 14:29:10 mjames |
||
34 | Moved setting debug level to cmdutil.c |
||
35 | |||
36 | Amended print external command to list all net names on socket pins |
||
37 | whether routed or not. |
||
38 | |||
39 | Revision 1.11 2002/03/21 17:14:15 mjames |
||
40 | Added search path to vertical file opening for read |
||
41 | |||
42 | Revision 1.10 2002/01/16 11:22:42 mjames |
||
43 | database.h header file is read in first as it undefined DLL stuff irrelevant |
||
44 | to HPUX |
||
45 | |||
46 | Revision 1.9 2001/12/13 22:14:25 mjames |
||
47 | Corrected nested command handlers to allow variable passing without corruption. |
||
48 | |||
49 | Revision 1.8 2001/11/19 10:41:52 mjames |
||
50 | Merged back DTC release |
||
51 | |||
52 | Revision 1.7.2.1 2001/11/16 15:08:13 mjames |
||
53 | Fixed incorrect printf specifier. |
||
54 | Added () barackets to conditional expressions |
||
55 | |||
56 | Revision 1.7 2001/10/31 22:20:01 mjames |
||
57 | Tidying up problematical comments caused by CVS |
||
58 | 'intelligent' comment guessing |
||
59 | |||
60 | Revision 1.6 2001/08/31 08:19:18 mjames |
||
61 | Added stuff to prevent errors with "sys/stat.h" |
||
62 | |||
63 | Revision 1.5 2001/06/20 13:43:33 mjames |
||
64 | Corrected logical expression required to open a file : need user rights to open this file |
||
65 | either 'r' and read rights or 'w' and write rights in trap_fopen call. |
||
66 | |||
67 | Revision 1.4 2001/06/19 05:19:52 mjames |
||
68 | Created a trap_fopen to overcome trying to write to read only files. |
||
69 | If this attempted in NT the file can be opened but not written to. |
||
70 | |||
71 | Revision 1.3 2001/06/06 12:10:24 mjames |
||
72 | Move from HPUX |
||
73 | |||
74 | Revision 1.2 2001/02/06 22:41:15 mjames |
||
75 | Added correct argument passing for 'read file comp_suffix arg0 arg1 arg2 ... |
||
76 | |||
77 | Revision 1.1.1.1 2000/10/19 21:58:35 mjames |
||
78 | Mike put it here |
||
79 | |||
80 | |||
81 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
||
82 | * COnversion to Vertical2, supports signals and components |
||
11 | mjames | 83 | * |
2 | mjames | 84 | * Revision 1.34 2000/10/04 10:37:03 10:37:03 mjames (Mike James) |
85 | * Part of Release PSAVAT01 |
||
11 | mjames | 86 | * |
2 | mjames | 87 | * Revision 1.33 2000/10/02 11:04:10 11:04:10 mjames (Mike James) |
88 | * new_vhdl |
||
11 | mjames | 89 | * |
2 | mjames | 90 | * Revision 1.32 2000/09/27 14:42:10 14:42:10 mjames (Mike James) |
91 | * Part of Release Sep_27_ST_2000 |
||
11 | mjames | 92 | * |
2 | mjames | 93 | * Revision 1.31 2000/09/21 10:15:40 10:15:40 mjames (Mike James) |
94 | * Part of Release Sep21Alpha |
||
11 | mjames | 95 | * |
2 | mjames | 96 | * Revision 1.30 2000/08/25 09:57:09 09:57:09 mjames (Mike James) |
97 | * Part of Release Aug25_alpha |
||
11 | mjames | 98 | * |
2 | mjames | 99 | * Revision 1.29 2000/08/16 08:57:26 08:57:26 mjames (Mike James) |
100 | * Part of Release CD01_Aug2000 |
||
11 | mjames | 101 | * |
2 | mjames | 102 | * Revision 1.28 2000/08/14 14:45:07 14:45:07 mjames (Mike James) |
103 | * Part of Release Aug_14_2000 |
||
11 | mjames | 104 | * |
2 | mjames | 105 | * Revision 1.27 2000/08/11 08:30:28 08:30:28 mjames (Mike James) |
106 | * Part of Release Aug_11_2000 |
||
11 | mjames | 107 | * |
2 | mjames | 108 | * Revision 1.26 2000/08/09 10:31:41 10:31:41 mjames (Mike James) |
109 | * Part of Release Aug__9_2000 |
||
11 | mjames | 110 | * |
2 | mjames | 111 | * Revision 1.25 2000/05/31 11:42:48 11:42:48 mjames (Mike James) |
112 | * Part of Release May_31_2000 |
||
11 | mjames | 113 | * |
2 | mjames | 114 | * Revision 1.24 2000/05/08 17:01:33 17:01:33 mjames (Mike James) |
115 | * Part of Release May__8_2000 |
||
11 | mjames | 116 | * |
2 | mjames | 117 | * Revision 1.23 2000/05/08 16:59:26 16:59:26 mjames (Mike James) |
118 | * Part of Release May__8_2000 |
||
11 | mjames | 119 | * |
2 | mjames | 120 | * Revision 1.22 2000/05/08 16:57:03 16:57:03 mjames (Mike James) |
121 | * Part of Release May__8_2000 |
||
11 | mjames | 122 | * |
2 | mjames | 123 | * Revision 1.21 2000/03/08 16:18:44 16:18:44 mjames (Mike James) |
124 | * New version including PC |
||
11 | mjames | 125 | * |
2 | mjames | 126 | * Revision 1.18 2000/01/20 15:58:41 15:58:41 mjames (Mike James) |
127 | * Part of Release R22 |
||
11 | mjames | 128 | * |
2 | mjames | 129 | * Revision 1.17 99/12/22 11:15:22 11:15:22 mjames (Mike James) |
130 | * Part of Release Dec_22_1999 |
||
11 | mjames | 131 | * |
2 | mjames | 132 | * Revision 1.16 99/06/25 14:34:40 14:34:40 mjames (Mike James) |
11 | mjames | 133 | * Added in reference to expression.h, but no changes made |
2 | mjames | 134 | * to the function of acfread yet. |
11 | mjames | 135 | * |
2 | mjames | 136 | * Revision 1.15 99/06/18 09:23:13 09:23:13 mjames (Mike James) |
11 | mjames | 137 | * |
2 | mjames | 138 | * Revision 1.14 1999/06/14 10:54:11 mjames |
139 | * *** empty log message *** |
||
140 | * |
||
141 | * Revision 1.14 1999/06/14 10:54:11 mjames |
||
142 | * *** empty log message *** |
||
143 | * |
||
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 |
||
11 | mjames | 146 | * |
2 | mjames | 147 | * Revision 1.12 98/02/11 11:25:47 11:25:47 mjames (Mike James) |
148 | * Checked in for version 6.2a |
||
11 | mjames | 149 | * |
2 | mjames | 150 | * Revision 1.11 97/04/23 08:42:47 08:42:47 mjames (Mike James) |
151 | * CHecked in for release rel23041997 |
||
11 | mjames | 152 | * |
2 | mjames | 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 |
||
11 | mjames | 155 | * |
2 | mjames | 156 | * Revision 1.9 1996/07/12 15:52:12 mjames |
157 | * Sorted out things like Alias and Jumpers |
||
158 | * Work Correctly |
||
159 | * Print COrrectly |
||
160 | * |
||
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 |
||
163 | * representation of reality. |
||
11 | mjames | 164 | * |
2 | mjames | 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 |
||
11 | mjames | 167 | * |
2 | mjames | 168 | * Revision 1.6 96/03/18 13:50:27 13:50:27 mjames (Mike James) |
169 | * Real Revision 2.1 |
||
11 | mjames | 170 | * |
2 | mjames | 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 |
||
11 | mjames | 173 | * |
2 | mjames | 174 | * Revision 1.3 96/02/08 15:28:12 15:28:12 mjames (Mike James) |
175 | * First release |
||
11 | mjames | 176 | * |
2 | mjames | 177 | * Revision 1.2 96/02/07 16:01:23 16:01:23 mjames (Mike James) |
178 | * Added correct RCS header |
||
11 | mjames | 179 | * |
2 | mjames | 180 | * Revision 1.1 96/02/07 15:49:47 15:49:47 mjames (Mike James) |
181 | * Initial revision |
||
11 | mjames | 182 | * |
183 | **********************************************************************************************************/ |
||
184 | |||
185 | #include <stdio.h> |
||
186 | #include <string.h> |
||
187 | #include <stdlib.h> |
||
188 | #include <ctype.h> |
||
189 | #include <sys/stat.h> |
||
190 | |||
191 | #include "vertcl_main.h" |
||
192 | #include "cmdparse.h" |
||
193 | #include "cmdutil.h" |
||
194 | #include "cmdlog.h" |
||
2 | mjames | 195 | #include "expression.h" |
196 | #include "generic.h" |
||
11 | mjames | 197 | #include "database.h" |
2 | mjames | 198 | #include "lx_support.h" |
199 | |||
11 | mjames | 200 | #ident "@(#)$Header: c:\\cygwin\\cvsroot/Vert03/cmdlib/cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $" |
2 | mjames | 201 | |
202 | /***************************************************************/ |
||
203 | /* this routine is used to trap opening read-only files for write */ |
||
204 | /* writing files is always into the current directory. Reading uses a search path */ |
||
205 | /* #if defined IS_HPUX */ |
||
206 | |||
207 | #if 1 |
||
208 | #define safe_fopen fopen |
||
11 | mjames | 209 | #else |
210 | #define safe_fopen nt_fopen |
||
2 | mjames | 211 | |
212 | /* and then define the NT protection function */ |
||
11 | mjames | 213 | FILE * nt_fopen(char * name, char * mode) |
214 | { |
||
215 | struct stat buf; |
||
216 | if(ISNULLSTR(name)) |
||
217 | { |
||
218 | return(NULL); |
||
219 | } |
||
220 | stat( name,&buf ); |
||
221 | if(level & 16) |
||
222 | { |
||
223 | printf("stat %08o '%s' '%s'\n",buf.st_mode,name,mode); |
||
224 | } |
||
225 | /* no file there attempt open anyway */ |
||
226 | if (buf.st_mode == 0) |
||
227 | { |
||
228 | return (fopen(name,mode)); |
||
229 | } |
||
230 | if (S_ISREG(buf.st_mode )) |
||
231 | { |
||
232 | if(((mode[0]=='w') && ((buf.st_mode & S_IRWXU)==S_IWUSR)) || |
||
233 | ((mode[0]=='r') && ((buf.st_mode & S_IRWXU)==S_IRUSR))) |
||
234 | { |
||
235 | return (fopen(name,mode)); |
||
236 | } |
||
237 | } |
||
238 | return NULL; |
||
239 | }; |
||
2 | mjames | 240 | #endif |
241 | |||
242 | /* we only search for 'r' mode files down the search path */ |
||
243 | /* or if name does not start with '.' or '/' and does not contain ':' on a PC */ |
||
11 | mjames | 244 | FILE * trap_fopen(char * name, char * mode) |
245 | { |
||
246 | FILE * f; |
||
2 | mjames | 247 | #if defined HP_UX |
11 | mjames | 248 | if (strcmp("r",mode)!=0 || name[0]=='/' || name[0] == '.' ) |
2 | mjames | 249 | #else |
11 | mjames | 250 | if (strcmp("r",mode)!=0 || name[0]=='/' || name[0] == '.' || strchr(name,':') ) |
2 | mjames | 251 | #endif |
11 | mjames | 252 | { |
253 | if(level & 16) |
||
254 | printf("Trying to open '%s' (no path) mode '%s'\n",name,mode); |
||
255 | f= (safe_fopen(name,mode)); |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | char * sp; |
||
260 | char pathbuff [MAXIDLEN]; |
||
261 | char namebuff [MAXIDLEN]; |
||
262 | expand_string( "$(VERTICAL_PATH)" ,pathbuff, 0, NULL) ; |
||
263 | f = NULL; |
||
2 | mjames | 264 | |
11 | mjames | 265 | for(sp=pathbuff;(f == NULL) && (sp=strtok(sp,";")) ;sp=NULL) |
266 | { |
||
267 | sprintf(namebuff,"%s/%s",sp,name); /* make up pathname */ |
||
268 | if(level & 16) |
||
269 | printf("Trying to open '%s' mode '%s'\n",namebuff,mode); |
||
270 | f = safe_fopen(namebuff,mode); |
||
271 | } |
||
272 | } |
||
273 | if(level & 16) |
||
274 | { |
||
275 | printf("File Pointer returned = %p\n",f); |
||
276 | } |
||
277 | return f; |
||
278 | }; |
||
2 | mjames | 279 | |
11 | mjames | 280 | /*********************************************************************************************************/ |
281 | int ConvertToDecimal (char *Input, long *Output) |
||
282 | { |
||
283 | int Base = 10, Stat = OKCMD; |
||
284 | char *CurrentChar, *End; |
||
2 | mjames | 285 | |
11 | mjames | 286 | CurrentChar = Input; |
287 | while(*CurrentChar && *CurrentChar ==' ') |
||
288 | { |
||
289 | CurrentChar++; |
||
290 | } |
||
291 | if (*CurrentChar == '0') |
||
292 | { |
||
293 | CurrentChar++; /* Read first character to calculate the base */ |
||
294 | switch(*CurrentChar) |
||
295 | { |
||
296 | case '\0' : *Output=0; return (OKCMD); /* Trap for single digit zero */ |
||
297 | case 'x' : Base=16; CurrentChar++; break; |
||
298 | case 'b' : Base=2; CurrentChar++; break; |
||
299 | default : Base=8; break; /* Default base is octal */ |
||
300 | } |
||
301 | } |
||
302 | else |
||
303 | { |
||
304 | if (isdigit(*CurrentChar)) |
||
305 | { |
||
306 | Base=10; |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | Stat =FAILED; |
||
311 | } |
||
312 | } |
||
313 | if(Stat==OKCMD) |
||
314 | { |
||
315 | *Output = strtol(CurrentChar, &End, Base); |
||
316 | } |
||
317 | if (*End != 0 ) |
||
318 | { |
||
319 | Stat = FAILED; |
||
320 | } |
||
321 | return(Stat); |
||
322 | } |
||
2 | mjames | 323 | |
11 | mjames | 324 | |
325 | void set_debug_level(int lev) |
||
326 | { |
||
327 | level = lev; |
||
328 | } |
||
329 |