NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/cl.c File Reference
#include "./napa.h"
#include "./proto.h"

Go to the source code of this file.

Macros

#define EXTERN   extern
#define COMMAND_OPTION(x, a, b)
#define OPTION_00(x)
#define OPTION_01(x)
#define OPTION_02(x)
#define OPTION_03(x)
#define OPTION_04(x)
#define OPTION_05(x)
#define OPTION_06(x)
#define OPTION_07(x)
#define OPTION_08(x)
#define OPTION_09(x)
#define OPTION_10(x)

Functions

void tag_executable (const char *d, const char *t)
void print_usage (const char *command)
void print_identification (void)
void print_build_information (void)
void process_command_line (long c, char **v)

Macro Definition Documentation

◆ COMMAND_OPTION

#define COMMAND_OPTION ( x,
a,
b )
Value:
((0 == strcmp(x,a)) || (0 == strcmp(x,b))) /* case sensitive compare */

Definition at line 28 of file cl.c.

◆ EXTERN

#define EXTERN   extern

Definition at line 4 of file cl.c.

◆ OPTION_00

#define OPTION_00 ( x)
Value:
COMMAND_OPTION(x, "-?", "-help" ) /* help flag */
#define COMMAND_OPTION(x, a, b)
Definition cl.c:28

Definition at line 30 of file cl.c.

Referenced by process_command_line().

◆ OPTION_01

#define OPTION_01 ( x)
Value:
COMMAND_OPTION(x, "-h", "-hdr" ) /* header library path */

Definition at line 31 of file cl.c.

Referenced by process_command_line().

◆ OPTION_02

#define OPTION_02 ( x)
Value:
COMMAND_OPTION(x, "-n", "-net" ) /* cell library path */

Definition at line 32 of file cl.c.

Referenced by process_command_line().

◆ OPTION_03

#define OPTION_03 ( x)
Value:
COMMAND_OPTION(x, "-g", "-gen" ) /* generator library path */

Definition at line 33 of file cl.c.

Referenced by process_command_line().

◆ OPTION_04

#define OPTION_04 ( x)
Value:
COMMAND_OPTION(x, "-d", "-dir" ) /* all library path */

Definition at line 34 of file cl.c.

Referenced by process_command_line().

◆ OPTION_05

#define OPTION_05 ( x)
Value:
COMMAND_OPTION(x, "-u", "-user" ) /* user name or user ID */

Definition at line 35 of file cl.c.

Referenced by process_command_line().

◆ OPTION_06

#define OPTION_06 ( x)
Value:
COMMAND_OPTION(x, "-e", "-expand" ) /* input file expansion */

Definition at line 36 of file cl.c.

Referenced by process_command_line().

◆ OPTION_07

#define OPTION_07 ( x)
Value:
COMMAND_OPTION(x, "-l", "-list" ) /* list nodes and vars */

Definition at line 37 of file cl.c.

Referenced by process_command_line().

◆ OPTION_08

#define OPTION_08 ( x)
Value:
COMMAND_OPTION(x, "-v", "-verbose") /* verbose flag */

Definition at line 38 of file cl.c.

Referenced by process_command_line().

◆ OPTION_09

#define OPTION_09 ( x)
Value:
COMMAND_OPTION(x, "-a", "-author" ) /* program identification */

Definition at line 39 of file cl.c.

Referenced by process_command_line().

◆ OPTION_10

#define OPTION_10 ( x)
Value:
COMMAND_OPTION(x, "-b", "-built" ) /* built information */

Definition at line 40 of file cl.c.

Referenced by process_command_line().

Function Documentation

◆ print_build_information()

void print_build_information ( void )

Definition at line 99 of file cl.c.

99 {
100 (void) fprintf(STDERR, "\n NAPA COMPILER, VERSION %6s for %s", NAPA_COMPILER_VERSION, MACHINE);
101 (void) fprintf(STDERR, ", BINARY BUILT %s\n\n", NAPA_Identification_String);
102 return;
103}
#define MACHINE
Definition napa.h:91
#define STDERR
Definition napa.h:105
#define NAPA_COMPILER_VERSION
Definition napa.h:30
EXTERN char NAPA_Identification_String[35]
Definition napa.h:992

References MACHINE, NAPA_COMPILER_VERSION, NAPA_Identification_String, and STDERR.

Referenced by process_command_line().

◆ print_identification()

void print_identification ( void )

Definition at line 92 of file cl.c.

92 { /* identification not indicated in usage */
93 (void) fprintf(STDERR, "\n*** NAPA COMPILER, VERSION %6s,", NAPA_COMPILER_VERSION);
94 (void) fprintf(STDERR, " BINARY BUILT %s ***\n", NAPA_Identification_String);
95 return;
96}

References NAPA_COMPILER_VERSION, NAPA_Identification_String, and STDERR.

Referenced by process_command_line().

◆ print_usage()

void print_usage ( const char * command)

Definition at line 68 of file cl.c.

68 { /* verbose mode is not indicated in usage */
69 (void) fprintf(STDERR, "\n*** NAPA COMPILER, VERSION %6s FOR %s", NAPA_COMPILER_VERSION, MACHINE);
70 (void) fprintf(STDERR, " ***\n");
71 (void) fprintf(STDERR, "\n USAGE:\n");
72 (void) fprintf(STDERR, "\n %s fnam", command);
73 (void) fprintf(STDERR, " [-d dlib][-h hlib][-n nlib][-g glib][-u \"user\"][-l | -e | -a | -b]\n");
74 (void) fprintf(STDERR, " %s -?\n", command);
75 (void) fprintf(STDERR, "\n Where:\n");
76 (void) fprintf(STDERR, " 'fnam' Full pathname of the main netlist to compile in ANSI-C\n");
77 (void) fprintf(STDERR, " 'dlib' Default directory containing libraries 'Hdr', 'Net', 'Gen'\n");
78 (void) fprintf(STDERR, " 'hlib' Library of header files (reset default 'dlib/Hdr')\n");
79 (void) fprintf(STDERR, " 'nlib' Library of reusable cells (reset default 'dlib/Net')\n");
80 (void) fprintf(STDERR, " 'glib' Library of reusable generators (reset default 'dlib/Gen')\n");
81 (void) fprintf(STDERR, " 'user' User's name or ID\n");
82 (void) fprintf(STDERR, " '-a' Program identification\n");
83 (void) fprintf(STDERR, " '-b' Built information\n");
84 (void) fprintf(STDERR, " '-l' List the nodes and variables (no compilation, no expansion)\n");
85 (void) fprintf(STDERR, " '-e' Expand the input netlists (no compilation, no list )\n");
86 (void) fprintf(STDERR, " '-?' This usage\n");
87 (void) fprintf(STDERR, "\n*** Report bugs, suggestions to yves.leduc.be@gmail.com ***\n");
88 return;
89}

References MACHINE, NAPA_COMPILER_VERSION, and STDERR.

Referenced by process_command_line().

◆ process_command_line()

void process_command_line ( long c,
char ** v )

Definition at line 108 of file cl.c.

108 {
109 int hflag, nflag, gflag, fflag, dflag, uflag;
110 long i;
111 int n;
112 int sec;
113 char str[STRLENGTH] = {'\0'};
114 char buffer[STRLENGTH] = {'\0'};
115 char initials[3] = " ";
116 char *s = (char*) NULL;
117 char *command = (char*) NULL;
118 char *generic_name = (char*) NULL;
119 struct tm *tminfo;
120 (void) strcpy(buffer, NAPA_COMPILER_VERSION);
121 if ('X' == buffer[0]) { /* beta release warning */
122 buffer[0] = 'V';
123 (void) fprintf(STDERR, "\n\n **** *************************************************************\n");
124 (void) fprintf(STDERR, " **** *** BETA RELEASE of NAPA %-6s ***\n", buffer);
125 (void) fprintf(STDERR, " **** *** Contact Yves Leduc, yves.leduc.be@gmail.com ***\n");
126 (void) fprintf(STDERR, " **** *** to get a stable release. ***\n");
127 (void) fprintf(STDERR, " **** *************************************************************\n\n");
128 }
129 (void) time(&NAPA_Time);
130 (void) snprintf(NAPA_Compile_Time, (size_t) 25, "%s", ctime(&NAPA_Time)); /* <<<<<<< limit to 25 char to cut '\n' */
131 strcpy_alloc(&User_Name, "", NULL, NULL);
132 dflag = false;
133 fflag = false;
134 gflag = false;
135 hflag = false;
136 nflag = false;
137 uflag = false;
138 strcpy_alloc(&command, *v, NULL, NULL); /* to document error msg */
139 drop_pathname(command); /* remove pathname if any */
140 (void) strcpy(NAPA_Command_Line, command); /* command without pathname */
141 for (i = 1L; i < c; i++) {
142 (void) strcat(NAPA_Command_Line, " ");
143 (void) strcat(NAPA_Command_Line, v[i]);
144 }
145 c--;
146 v++;
147 if (0L == c) {
149 n = snprintf(str, (size_t) 159, "Type %s -help to get a short usage", command);
150 (void) fprintf(STDERR, "\n*** %s %*s ***\n", str, 64 -n, " ");
151 (void) fprintf(STDERR, "\nContact the author Yves Leduc (Email: yves.leduc.be@gmail.com) for further information.\n");
152 exit(EXIT_SUCCESS); /* normal termination, no other process */
153 }
154 while (0L < c) { /* analyze command line, token by token */
155 if (OPTION_01(*v)) { /* "-h", "-hdr" header library path */
156 c--;
157 v++;
158 if (0L >= c) {
159 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-h, -hdr]: header library pathname is missing.\n");
160 print_usage(command);
161 exit(EXIT_FAILURE);
162 }
163 strcpy_alloc(&Header_Lib_Name, *v, NULL, NULL);
164 c--;
165 v++;
166 if (!hflag) {
167 hflag = true;
168 } else {
169 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-h, -hdr]: only one header library pathname is allowed.\n");
170 exit(EXIT_FAILURE);
171 }
172 } else if (OPTION_02(*v)) { /* "-n", "-net" cell library path */
173 c--;
174 v++;
175 if (0L >= c) {
176 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-n, -net]: net library pathname is missing.\n");
177 print_usage(command);
178 exit(EXIT_FAILURE);
179 }
180 strcpy_alloc(&Net_Lib_Name, *v, NULL, NULL);
181 c--;
182 v++;
183 if (!nflag) {
184 nflag = true;
185 } else {
186 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-n, -net]: only one net library pathname is allowed.\n");
187 exit(EXIT_FAILURE);
188 }
189 } else if (OPTION_03(*v)) { /* "-g", "-gen" generator library path */
190 c--;
191 v++;
192 if (0L >= c) {
193 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-g, -gen]: generator library pathname is missing.\n");
194 print_usage(command);
195 exit(EXIT_FAILURE);
196 }
197 strcpy_alloc(&Generator_Lib_Name, *v, NULL, NULL);
198 c--;
199 v++;
200 if (!gflag) {
201 gflag = true;
202 } else {
203 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-g, -gen]: only one generator pathname library is allowed.\n");
204 exit(EXIT_FAILURE);
205 }
206 } else if (OPTION_04(*v)) { /* "-d", "-dir" all library path */
207 c--;
208 v++;
209 if (0L >= c) {
210 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-d, -dir]: generic library pathname is missing.\n");
211 print_usage(command);
212 exit(EXIT_FAILURE);
213 }
214 strcpy_alloc(&generic_name, *v, NULL, NULL);
215 c--;
216 v++;
217 if (!dflag) {
218 dflag = true;
219 } else {
220 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-d, -dir]: only one generic library pathname library is allowed.\n");
221 exit(EXIT_FAILURE);
222 }
223 } else if (OPTION_05(*v)) { /* "-u", "-user" user name or user ID */
224 c--;
225 v++;
226 if (0L >= c) {
227 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-u, -user]: user name is missing.\n");
228 print_usage(command);
229 exit(EXIT_FAILURE);
230 }
231 strcpy_realloc(&User_Name, *v, NULL, NULL);
232 for (i = 0L; i < LENGTH(User_Name); i++) {
233 if ('_' == User_Name[i]) { /* replace underscore by space */
234 User_Name[i] = ' ';
235 }
236 if (!isalpha((int) User_Name[i])) {
237 User_Name[i] = (char) tolower((int) User_Name[i]); /* convert to lower case */
238 continue;
239 }
240 }
241 User_Name[0] = (char) toupper((int) User_Name[0]);
242 initials[0] = User_Name[0];
243 for (i = 1L; i < LENGTH(User_Name); i++) {
244 if (' ' == User_Name[i-1L]) {
245 User_Name[i] = (char) toupper((int) User_Name[i]);
246 if (' ' == initials[1]) {
247 initials[1] = User_Name[i];
248 }
249 }
250 }
251 c--;
252 v++;
253 if (!uflag) {
254 uflag = true;
255 } else {
256 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-u, -user]: only one user name is allowed.\n");
257 exit(EXIT_FAILURE);
258 }
259 } else if (OPTION_06(*v)) { /* "-e", "-expand" input file expansion */
260 c--;
261 v++;
262 if (!List_Flag) {
263 Expand_Flag = true;
264 } else {
265 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-e, -expand]:");
266 (void) fprintf(STDERR, " file expansion and nodes/variables listing are not possible together.\n");
267 print_usage(command);
268 exit(EXIT_FAILURE);
269 }
270 } else if (OPTION_07(*v)) { /* "-l", "-list" list nodes and vars */
271 c--;
272 v++;
273 if (!Expand_Flag) {
274 List_Flag = true;
275 } else {
276 (void) fprintf(STDERR, "\nNAPA Command Line Error: [-l, -list]:");
277 (void) fprintf(STDERR, " nodes/variables listing and file expansion are not possible together.\n");
278 print_usage(command);
279 exit(EXIT_FAILURE);
280 }
281 } else if (OPTION_08(*v)) { /* "-v", "-verbose" verbose flag */
282 c--;
283 v++;
284 Verbose_Flag = true;
285 (void) fprintf(STDERR, "\n");
286 print_limits();
287 (void) fprintf(STDERR, "\n");
288 } else if (OPTION_09(*v)) { /* "-a", "-author" program identification */
290 (void) fprintf(STDERR, "\n*** AUTHOR: Yves Leduc (Email: yves.leduc.be@gmail.com) ***\n");
291 exit(EXIT_SUCCESS); /* normal termination, no other process */
292 } else if (OPTION_10(*v)) { /* "-b", "-build" build information */
294 exit(EXIT_SUCCESS); /* normal termination, no other process */
295 } else if (OPTION_00(*v)) { /* "-?", "-help" help flag */
296 print_usage(command);
297 exit(EXIT_SUCCESS); /* normal termination, no other process */
298 } else if ('-' == **v) {
299 (void) fprintf(STDERR, "\nNAPA Command Line Error: option '%s' is not recognized as a valid option.\n", *v);
300 print_usage(command);
301 exit(EXIT_FAILURE);
302 } else { /* name of the netlist file to compile */
303 strcpy_alloc(&Main_File_Name, *v, NULL, NULL);
304#if (IS_WIN64 == PLATFORM) /* for WINDOWS/DOS compatibility */
305 for (n = 0L; n < LENGTH(Main_File_Name); n++) {
306 if ('\\' == Main_File_Name[n]) {
307 Main_File_Name[n] = '/';
308 }
309 }
310#endif
311 if (':' == Main_File_Name[1]) { /* remove disk prefix if any */
312 s = Main_File_Name + 2;
313 (void) strcpy(Main_File_Name, s);
314 }
315 c--;
316 v++;
317 if (!fflag) {
318 fflag = true;
319 } else {
320 (void) fprintf(STDERR, "\nNAPA Command Line Error: only one main source file pathname is allowed.\n");
321 exit(EXIT_FAILURE);
322 }
323 }
324 }
325 if (!fflag) {
326 (void) fprintf(STDERR, "\nNAPA Command Line Error: main source file pathname is missing.\n");
327 print_usage(command);
328 exit(EXIT_FAILURE);
329 }
330 if ((!hflag) && (dflag)) { /* use default directory */
331 (void) snprintf(buffer, (size_t) (STRLENGTH-1L), "%s/Hdr", generic_name);
332 strcpy_alloc(&Header_Lib_Name, buffer, NULL, NULL);
333 }
334 if ((!nflag) && (dflag)) { /* use default directory */
335 (void) snprintf(buffer, (size_t) (STRLENGTH-1L), "%s/Net", generic_name);
336 strcpy_alloc(&Net_Lib_Name, buffer, NULL, NULL);
337 }
338 if ((!gflag) && (dflag)) { /* use default directory */
339 (void) snprintf(buffer, (size_t) (STRLENGTH-1L), "%s/Gen", generic_name);
340 strcpy_alloc(&Generator_Lib_Name, buffer, NULL, NULL);
341 }
342 if ((!hflag) && (!dflag)) { /* default directory is main directory */
343 strcpy_alloc(&Header_Lib_Name, ".", NULL, NULL);
344 }
345 if ((!nflag) && (!dflag)) { /* default directory is main directory */
346 strcpy_alloc(&Net_Lib_Name, ".", NULL, NULL);
347 }
348 if ((!gflag) && (!dflag)) { /* default directory is main directory */
349 strcpy_alloc(&Generator_Lib_Name, ".", NULL, NULL);
350 }
351 if ((Expand_Flag) || (List_Flag)) {
352 Verbose_Flag = false;
353 }
354 free(command);
355 if ((dflag) || (NULL != generic_name)) { /* free memory only if it was allocated ! */
356 free(generic_name);
357 }
358 tminfo = localtime(&NAPA_Time); /* create unique job id */
359 sec = ((*tminfo).tm_mday * 86400) + ((*tminfo).tm_hour * 3600) + ((*tminfo).tm_min * 60) + (*tminfo).tm_sec;
360 (void) snprintf(buffer, (size_t) 16, "%d%d%d", (*tminfo).tm_year-100, (*tminfo).tm_mon+1, sec);
361 if (0 == strcmp(initials, " ")) {
362 (void) snprintf(NAPA_Job_ID, (size_t) 16, "%s", buffer);
363 } else {
364 (void) snprintf(NAPA_Job_ID, (size_t) 18, "%s%s", initials, buffer);
365 }
366 return;
367}
#define OPTION_02(x)
Definition cl.c:32
#define OPTION_04(x)
Definition cl.c:34
#define OPTION_01(x)
Definition cl.c:31
#define OPTION_05(x)
Definition cl.c:35
void print_usage(const char *command)
Definition cl.c:68
#define OPTION_09(x)
Definition cl.c:39
#define OPTION_00(x)
Definition cl.c:30
#define OPTION_10(x)
Definition cl.c:40
void print_identification(void)
Definition cl.c:92
#define OPTION_03(x)
Definition cl.c:33
#define OPTION_07(x)
Definition cl.c:37
void print_build_information(void)
Definition cl.c:99
#define OPTION_08(x)
Definition cl.c:38
#define OPTION_06(x)
Definition cl.c:36
void print_limits(void)
Definition fc.c:56
void strcpy_alloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
Definition id.c:114
void strcpy_realloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
Definition id.c:129
EXTERN char * Generator_Lib_Name
Definition napa.h:913
EXTERN char NAPA_Compile_Time[33]
Definition napa.h:990
EXTERN char NAPA_Command_Line[2047L]
Definition napa.h:907
#define LENGTH(s)
Definition napa.h:397
EXTERN char NAPA_Job_ID[19]
Definition napa.h:993
EXTERN int Expand_Flag
Definition napa.h:854
EXTERN int Verbose_Flag
Definition napa.h:889
EXTERN time_t NAPA_Time
Definition napa.h:986
EXTERN char * Header_Lib_Name
Definition napa.h:914
EXTERN int List_Flag
Definition napa.h:864
EXTERN char * Main_File_Name
Definition napa.h:911
#define STRLENGTH
Definition napa.h:217
EXTERN char * User_Name
Definition napa.h:909
EXTERN char * Net_Lib_Name
Definition napa.h:915
void drop_pathname(char *pnam)
Definition tk.c:1526

References drop_pathname(), Expand_Flag, Generator_Lib_Name, Header_Lib_Name, LENGTH, List_Flag, Main_File_Name, NAPA_Command_Line, NAPA_Compile_Time, NAPA_COMPILER_VERSION, NAPA_Job_ID, NAPA_Time, Net_Lib_Name, OPTION_00, OPTION_01, OPTION_02, OPTION_03, OPTION_04, OPTION_05, OPTION_06, OPTION_07, OPTION_08, OPTION_09, OPTION_10, print_build_information(), print_identification(), print_limits(), print_usage(), STDERR, strcpy_alloc(), strcpy_realloc(), STRLENGTH, User_Name, and Verbose_Flag.

Referenced by main().

◆ tag_executable()

void tag_executable ( const char * d,
const char * t )

Definition at line 62 of file cl.c.

62 { /* used to identify the executable */
63 (void) snprintf(NAPA_Identification_String, (size_t) 32, "%s %s", d, t);
64 return;
65}

References NAPA_Identification_String.

Referenced by main().