comparison lib-src/ellcc.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 25e260cb7994
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
59 */ 59 */
60 60
61 #include <config.h> 61 #include <config.h>
62 #include <stdio.h> 62 #include <stdio.h>
63 #include <stdlib.h> 63 #include <stdlib.h>
64 #include <stddef.h>
64 #include <string.h> 65 #include <string.h>
65 #include <ctype.h> 66 #include <ctype.h>
66 #include <errno.h> 67 #include <errno.h>
67 #include <sys/types.h> 68 #include <sys/types.h>
68 69
107 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) 108 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
108 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type))) 109 # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type)))
109 #endif 110 #endif
110 static void *xmalloc (size_t); 111 static void *xmalloc (size_t);
111 static void fatal (char *, char *); 112 static void fatal (char *, char *);
112 static void add_to_argv (CONST char *); 113 static void add_to_argv (const char *);
113 static void do_compile_mode (void); 114 static void do_compile_mode (void);
114 static void do_link_mode (void); 115 static void do_link_mode (void);
115 static void do_init_mode (void); 116 static void do_init_mode (void);
116 117
117 #define SSTR(S) ((S)?(S):"") 118 #define SSTR(S) ((S)?(S):"")
118 119
119 #define ELLCC_COMPILE_MODE 0 120 #define ELLCC_COMPILE_MODE 0
120 #define ELLCC_LINK_MODE 1 121 #define ELLCC_LINK_MODE 1
121 #define ELLCC_INIT_MODE 2 122 #define ELLCC_INIT_MODE 2
122 123
123 int ellcc_mode = ELLCC_COMPILE_MODE; 124 static int ellcc_mode = ELLCC_COMPILE_MODE;
124 char *progname; 125 static char *progname;
125 char *mod_name = (char *)0, *mod_version = (char *)0, *mod_title = (char *)0; 126 static char *mod_name = NULL;
126 char *mod_output = (char *)0; 127 static char *mod_version = NULL;
127 int verbose = 0; 128 static char *mod_title = NULL;
128 char **exec_argv; 129 static char *mod_output = NULL;
129 int exec_argc = 1, *exec_args; 130 static int verbose = 0;
130 int real_argc = 0; 131 static char **exec_argv;
131 int prog_argc; 132 static int exec_argc = 1;
132 char **prog_argv; 133 static int *exec_args;
134 static int real_argc = 0;
135 static int prog_argc;
136 static char **prog_argv;
133 137
134 /* 138 /*
135 * We allow the user to over-ride things in the environment 139 * We allow the user to over-ride things in the environment
136 */ 140 */
137 char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags, *elldllflags; 141 char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags, *elldllflags;
147 int i, done_mode = 0; 151 int i, done_mode = 0;
148 152
149 prog_argc = argc; 153 prog_argc = argc;
150 prog_argv = argv; 154 prog_argv = argv;
151 155
152 #if defined(MSDOS) || defined(WINDOWSNT) 156 #if defined(WIN32_NATIVE)
153 tmp = strrchr (argv[0], '\\'); 157 tmp = strrchr (argv[0], '\\');
154 if (tmp != (char *)0) 158 if (tmp != (char *)0)
155 tmp++; 159 tmp++;
156 #elif !defined (VMS) 160 #elif !defined (VMS)
157 tmp = strrchr (argv[0], '/'); 161 tmp = strrchr (argv[0], '/');
344 * Add a string to the argument vector list that will be passed on down 348 * Add a string to the argument vector list that will be passed on down
345 * to the compiler or linker. We need to split individual words into 349 * to the compiler or linker. We need to split individual words into
346 * arguments, taking quoting into account. This can get ugly. 350 * arguments, taking quoting into account. This can get ugly.
347 */ 351 */
348 static void 352 static void
349 add_to_argv (CONST char *str) 353 add_to_argv (const char *str)
350 { 354 {
351 int sm = 0; 355 int sm = 0;
352 CONST char *s = (CONST char *)0; 356 const char *s = (const char *)0;
353 357
354 if ((str == (CONST char *)0) || (str[0] == '\0')) 358 if ((str == (const char *)0) || (str[0] == '\0'))
355 return; 359 return;
356 360
357 while (*str) 361 while (*str)
358 { 362 {
359 switch (sm) 363 switch (sm)
376 exec_argv[real_argc] = xnew (l+2, char); 380 exec_argv[real_argc] = xnew (l+2, char);
377 strncpy (exec_argv[real_argc], s, l); 381 strncpy (exec_argv[real_argc], s, l);
378 exec_argv[real_argc][l] = '\0'; 382 exec_argv[real_argc][l] = '\0';
379 real_argc++; 383 real_argc++;
380 sm = 0; /* Back to start state */ 384 sm = 0; /* Back to start state */
381 s = (CONST char *)0; 385 s = (const char *)0;
382 break; 386 break;
383 } 387 }
384 else if (*str == '\\') 388 else if (*str == '\\')
385 { 389 {
386 sm = 2; /* Escaped character */ 390 sm = 2; /* Escaped character */
421 str++; 425 str++;
422 break; 426 break;
423 } 427 }
424 } 428 }
425 429
426 if (s != (CONST char *)0) 430 if (s != (const char *)0)
427 { 431 {
428 int l = str-s; 432 int l = str-s;
429 exec_argv[real_argc] = xnew (l+2, char); 433 exec_argv[real_argc] = xnew (l+2, char);
430 strncpy (exec_argv[real_argc], s, l); 434 strncpy (exec_argv[real_argc], s, l);
431 exec_argv[real_argc][l] = '\0'; 435 exec_argv[real_argc][l] = '\0';
432 real_argc++; 436 real_argc++;
433 s = (CONST char *)0; 437 s = (const char *)0;
434 } 438 }
435 } 439 }
436 440
437 /* 441 /*
438 * For compile mode, things are pretty straight forward. All we need to do 442 * For compile mode, things are pretty straight forward. All we need to do