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