Subversion Repositories Vertical

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  * $Id: cmdutil.c,v 1.1.1.1 2003/11/04 23:34:56 mjames Exp $ **
3
              Author: Kevin Ross (x6143)
4
 
5
                      Philips Semiconductors Limited.
6
 
7
                      Millbrook Industrial Estate, Southampton, SO9 7BH. England.
8
 
9
                Date: 31st March 1993
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
83
 *
84
 * Revision 1.34  2000/10/04  10:37:03  10:37:03  mjames (Mike James)
85
 * Part of Release PSAVAT01
86
 *
87
 * Revision 1.33  2000/10/02  11:04:10  11:04:10  mjames (Mike James)
88
 * new_vhdl
89
 *
90
 * Revision 1.32  2000/09/27  14:42:10  14:42:10  mjames (Mike James)
91
 * Part of Release Sep_27_ST_2000
92
 *
93
 * Revision 1.31  2000/09/21  10:15:40  10:15:40  mjames (Mike James)
94
 * Part of Release Sep21Alpha
95
 *
96
 * Revision 1.30  2000/08/25  09:57:09  09:57:09  mjames (Mike James)
97
 * Part of Release Aug25_alpha
98
 *
99
 * Revision 1.29  2000/08/16  08:57:26  08:57:26  mjames (Mike James)
100
 * Part of Release CD01_Aug2000
101
 *
102
 * Revision 1.28  2000/08/14  14:45:07  14:45:07  mjames (Mike James)
103
 * Part of Release Aug_14_2000
104
 *
105
 * Revision 1.27  2000/08/11  08:30:28  08:30:28  mjames (Mike James)
106
 * Part of Release Aug_11_2000
107
 *
108
 * Revision 1.26  2000/08/09  10:31:41  10:31:41  mjames (Mike James)
109
 * Part of Release Aug__9_2000
110
 *
111
 * Revision 1.25  2000/05/31  11:42:48  11:42:48  mjames (Mike James)
112
 * Part of Release May_31_2000
113
 *
114
 * Revision 1.24  2000/05/08  17:01:33  17:01:33  mjames (Mike James)
115
 * Part of Release May__8_2000
116
 *
117
 * Revision 1.23  2000/05/08  16:59:26  16:59:26  mjames (Mike James)
118
 * Part of Release May__8_2000
119
 *
120
 * Revision 1.22  2000/05/08  16:57:03  16:57:03  mjames (Mike James)
121
 * Part of Release May__8_2000
122
 *
123
 * Revision 1.21  2000/03/08  16:18:44  16:18:44  mjames (Mike James)
124
 * New version including PC
125
 *
126
 * Revision 1.18  2000/01/20  15:58:41  15:58:41  mjames (Mike James)
127
 * Part of Release R22
128
 *
129
 * Revision 1.17  99/12/22  11:15:22  11:15:22  mjames (Mike James)
130
 * Part of Release Dec_22_1999
131
 *
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
134
 * to the function of acfread yet.
135
 *
136
 * Revision 1.15  99/06/18  09:23:13  09:23:13  mjames (Mike James)
137
 *
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
146
 *
147
 * Revision 1.12  98/02/11  11:25:47  11:25:47  mjames (Mike James)
148
 * Checked in for version 6.2a
149
 *
150
 * Revision 1.11  97/04/23  08:42:47  08:42:47  mjames (Mike James)
151
 * CHecked in for release rel23041997
152
 *
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
155
 *
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.
164
 *
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
167
 *
168
 * Revision 1.6  96/03/18  13:50:27  13:50:27  mjames (Mike James)
169
 * Real Revision 2.1
170
 *
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
173
 *
174
 * Revision 1.3  96/02/08  15:28:12  15:28:12  mjames (Mike James)
175
 * First release
176
 *
177
 * Revision 1.2  96/02/07  16:01:23  16:01:23  mjames (Mike James)
178
 * Added correct RCS header
179
 *
180
 * Revision 1.1  96/02/07  15:49:47  15:49:47  mjames (Mike James)
181
 * Initial revision
182
 *
183
**********************************************************************************************************/
184
 
185
#include "cmdutil.h"
186
 
187
#include "cmdlog.h"
188
#include "cmdparse.h"
189
#include "database.h"
190
#include "expression.h"
191
#include "generic.h"
192
#include "lx_support.h"
193
#include "vertcl_main.h"
194
 
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 $"
203
 
204
/***************************************************************/
205
/* 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 */
207
/* #if defined IS_HPUX */
208
 
209
#if 1
210
#define safe_fopen fopen
211
#else
212
#define safe_fopen nt_fopen
213
 
214
/* and then define the NT protection function */
215
FILE *nt_fopen (char *name, char *mode)
216
{
217
        struct stat buf;
218
        if (ISNULLSTR (name))
219
        {
220
                return (NULL);
221
        }
222
        stat (name, &buf);
223
        if (level & 16)
224
        {
225
                printf ("stat %08o '%s' '%s'\n", buf.st_mode, name, mode);
226
        }
227
        /* no file there attempt open anyway */
228
        if (buf.st_mode == 0)
229
        {
230
                return (fopen (name, mode));
231
        }
232
        if (S_ISREG (buf.st_mode))
233
        {
234
                if (((mode[0] == 'w') && ((buf.st_mode & S_IRWXU) == S_IWUSR)) ||
235
                    ((mode[0] == 'r') && ((buf.st_mode & S_IRWXU) == S_IRUSR)))
236
                {
237
                        return (fopen (name, mode));
238
                }
239
        }
240
        return NULL;
241
};
242
#endif
243
 
244
/* 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 */
246
FILE *trap_fopen (char *name, char *mode)
247
{
248
        FILE *f;
249
#if defined HP_UX
250
        if (strcmp ("r", mode) != 0 || name[0] == '/' || name[0] == '.')
251
#else
252
        if (strcmp ("r", mode) != 0 || name[0] == '/' || name[0] == '.' || strchr (name, ':'))
253
#endif
254
        {
255
                if (level & 16)
256
                        printf ("Trying to open '%s' (no path) mode '%s'\n", name, mode);
257
                f = (safe_fopen (name, mode));
258
        }
259
        else
260
        {
261
                char *sp;
262
                char pathbuff[MAXIDLEN];
263
                char namebuff[MAXIDLEN];
264
                expand_string ("$(VERTICAL_PATH)", pathbuff, 0, NULL);
265
                f = NULL;
266
 
267
                for (sp = pathbuff; (f == NULL) && (sp = strtok (sp, ";")); sp = NULL)
268
                {
269
                        sprintf (namebuff, "%s/%s", sp, name); /* make up pathname */
270
                        if (level & 16)
271
                                printf ("Trying to open '%s' mode '%s'\n", namebuff, mode);
272
                        f = safe_fopen (namebuff, mode);
273
                }
274
        }
275
        if (level & 16)
276
        {
277
                printf ("File Pointer returned = %p\n", f);
278
        }
279
        return f;
280
};
281
 
282
/*********************************************************************************************************/
283
int ConvertToDecimal (char *Input, long *Output)
284
{
285
        int Base = 10, Stat = OKCMD;
286
        char *CurrentChar, *End;
287
 
288
        CurrentChar = Input;
289
        while (*CurrentChar && *CurrentChar == ' ')
290
        {
291
                CurrentChar++;
292
        }
293
        if (*CurrentChar == '0')
294
        {
295
                CurrentChar++; /* Read first character to calculate the base */
296
                switch (*CurrentChar)
297
                {
298
                case '\0':
299
                        *Output = 0;
300
                        return (OKCMD); /* Trap for single digit zero */
301
                case 'x':
302
                        Base = 16;
303
                        CurrentChar++;
304
                        break;
305
                case 'b':
306
                        Base = 2;
307
                        CurrentChar++;
308
                        break;
309
                default:
310
                        Base = 8;
311
                        break; /* Default base is octal */
312
                }
313
        }
314
        else
315
        {
316
                if (isdigit (*CurrentChar))
317
                {
318
                        Base = 10;
319
                }
320
                else
321
                {
322
                        Stat = FAILED;
323
                }
324
        }
325
        if (Stat == OKCMD)
326
        {
327
                *Output = strtol (CurrentChar, &End, Base);
328
        }
329
        if (*End != 0)
330
        {
331
                Stat = FAILED;
332
        }
333
        return (Stat);
334
}
335
 
336
void set_debug_level (int lev)
337
{
338
        level = lev;
339
}