X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=lib-src%2Fellcc.c;h=53bd780eb679f0adfc89548704153f59b4747434;hp=acc3abe6cf58b1edfa9e6827f8e1f43e5669cae0;hb=1b70edcd9999965aafe4533453eb6b353b349898;hpb=f3ec20f455f3f1212d2c5ee4cadc984330da9c38 diff --git a/lib-src/ellcc.c b/lib-src/ellcc.c index acc3abe..53bd780 100644 --- a/lib-src/ellcc.c +++ b/lib-src/ellcc.c @@ -24,8 +24,8 @@ Please mail bugs and suggestions to the XEmacs maintainer. /* Here's the scoop. We would really like this to be a shell script, but -the various Windows platforms dont have reliable scripting that suits -our needs. We dont want to reply on perl or some other such language +the various Windows platforms don't have reliable scripting that suits +our needs. We don't want to rely on perl or some other such language so we have to roll our own executable to act as a front-end for the compiler. @@ -58,87 +58,32 @@ the lines of: See the samples for more details. */ +#include #include #include - -#ifdef MSDOS -# include -# include -# include -# ifndef HAVE_CONFIG_H -# define DOS_NT -# include -# endif -#endif /* MSDOS */ - -#ifdef WINDOWSNT -# include -# include -# include -# include -# define MAXPATHLEN _MAX_PATH -# ifdef HAVE_CONFIG_H -# undef HAVE_NTGUI -# else -# define DOS_NT -# define HAVE_GETCWD -# endif /* not HAVE_CONFIG_H */ -#endif /* WINDOWSNT */ - -#ifdef HAVE_CONFIG_H -# include - /* On some systems, Emacs defines static as nothing for the sake - of unexec. We don't want that here since we don't use unexec. */ -# undef static -#endif /* HAVE_CONFIG_H */ - -#if !defined (WINDOWSNT) && defined (STDC_HEADERS) -#include +#include #include -#endif +#include +#include +#include #ifdef HAVE_UNISTD_H # include -#else -# ifdef HAVE_GETCWD - extern char *getcwd (); -# endif #endif /* HAVE_UNISTD_H */ -#include -#include -#include -#ifndef errno - extern int errno; -#endif -#include -#include - #define EMODULES_GATHER_VERSION -#include "emodules.h" -#include "ellcc.h" - -#if !defined (S_ISREG) && defined (S_IFREG) -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -/* Exit codes for success and failure. */ -#ifdef VMS -# define GOOD 1 -# define BAD 0 -#else -# define GOOD 0 -# define BAD 1 -#endif +#include +#include /* Generated files must be included using <...> */ #define DEBUG #ifndef HAVE_SHLIB int -main() +main (int argc, char *argv[]) { fprintf (stderr, "Dynamic modules not supported on this platform\n"); - return (BAD); + return EXIT_FAILURE; } #else @@ -163,11 +108,12 @@ main() # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) # define xrnew(op,n,Type) ((Type *) xrealloc ((op), (n) * sizeof (Type))) #endif -long *xmalloc (), *xrealloc (); -void fatal (), pfatal (); -char *ellcc_strchr (), *ellcc_strrchr (); -void add_to_argv (); -void do_compile_mode(), do_link_mode(), do_init_mode(); +static void *xmalloc (size_t); +static void fatal (char *, char *); +static void add_to_argv (const char *); +static void do_compile_mode (void); +static void do_link_mode (void); +static void do_init_mode (void); #define SSTR(S) ((S)?(S):"") @@ -175,16 +121,19 @@ void do_compile_mode(), do_link_mode(), do_init_mode(); #define ELLCC_LINK_MODE 1 #define ELLCC_INIT_MODE 2 -int ellcc_mode = ELLCC_COMPILE_MODE; -char *progname; -char *mod_name = (char *)0, *mod_version = (char *)0, *mod_title = (char *)0; -char *mod_output = (char *)0; -int verbose = 0; -char **exec_argv; -int exec_argc = 1, *exec_args; -int real_argc = 0; -int prog_argc; -char **prog_argv; +static int ellcc_mode = ELLCC_COMPILE_MODE; +static char *progname; +static char *mod_name = NULL; +static char *mod_version = NULL; +static char *mod_title = NULL; +static char *mod_output = NULL; +static int verbose = 0; +static char **exec_argv; +static int exec_argc = 1; +static int *exec_args; +static int real_argc = 0; +static int prog_argc; +static char **prog_argv; /* * We allow the user to over-ride things in the environment @@ -196,9 +145,7 @@ char *ellcc, *ellld, *ellcflags, *ellldflags, *ellpicflags, *elldllflags; STR = DFLT int -main (argc, argv) - int argc; - char *argv[]; +main (int argc, char *argv[]) { char *tmp; int i, done_mode = 0; @@ -206,12 +153,12 @@ main (argc, argv) prog_argc = argc; prog_argv = argv; -#if defined(MSDOS) || defined(WINDOWSNT) - tmp = ellcc_strrchr (argv[0], '\\'); +#if defined(WIN32_NATIVE) + tmp = strrchr (argv[0], '\\'); if (tmp != (char *)0) tmp++; #elif !defined (VMS) - tmp = ellcc_strrchr (argv[0], '/'); + tmp = strrchr (argv[0], '/'); if (tmp != (char *)0) tmp++; #else @@ -248,7 +195,7 @@ main (argc, argv) char *modeopt = argv[i] + 7; if (done_mode && strcmp (modeopt, "verbose")) - fatal ("more than one mode specified"); + fatal ("more than one mode specified", (char *) 0); if (strcmp (modeopt, "link") == 0) { done_mode++; @@ -287,13 +234,13 @@ main (argc, argv) printf ("%s\n", ELLCC_CONFIG); return 0; } - else if (strncmp (argv[i], "--mod-name=", 10) == 0) + else if (strncmp (argv[i], "--mod-name=", 11) == 0) mod_name = argv[i] + 11; - else if (strncmp (argv[i], "--mod-title=", 11) == 0) + else if (strncmp (argv[i], "--mod-title=", 12) == 0) mod_title = argv[i] + 12; - else if (strncmp (argv[i], "--mod-version=", 13) == 0) + else if (strncmp (argv[i], "--mod-version=", 14) == 0) mod_version = argv[i] + 14; - else if (strncmp (argv[i], "--mod-output=", 12) == 0) + else if (strncmp (argv[i], "--mod-output=", 13) == 0) mod_output = argv[i] + 13; else { @@ -339,7 +286,7 @@ main (argc, argv) #endif if (exec_argc < 2) - fatal ("too few arguments"); + fatal ("too few arguments", (char *) 0); /* * Get the over-rides from the environment @@ -378,83 +325,23 @@ main (argc, argv) } /* Like malloc but get fatal error if memory is exhausted. */ -long * -xmalloc (size) - unsigned int size; -{ - long *result = (long *) malloc (size); - if (result == NULL) - fatal ("virtual memory exhausted", (char *)NULL); - return result; -} - -long * -xrealloc (ptr, size) - char *ptr; - unsigned int size; +static void * +xmalloc (size_t size) { - long *result = (long *) realloc (ptr, size); + void *result = malloc (size); if (result == NULL) - fatal ("virtual memory exhausted", (char *)NULL); + fatal ("virtual memory exhausted", (char *)0); return result; } /* Print error message and exit. */ -void -fatal (s1, s2) - char *s1, *s2; +static void +fatal (char *s1, char *s2) { fprintf (stderr, "%s: ", progname); fprintf (stderr, s1, s2); fprintf (stderr, "\n"); - exit (BAD); -} - -void -pfatal (s1) - char *s1; -{ - perror (s1); - exit (BAD); -} - -/* - * Return the ptr in sp at which the character c last - * appears; NULL if not found - * - * Identical to System V strrchr, included for portability. - */ -char * -ellcc_strrchr (sp, c) - register char *sp, c; -{ - register char *r; - - r = NULL; - do - { - if (*sp == c) - r = sp; - } while (*sp++); - return r; -} - -/* - * Return the ptr in sp at which the character c first - * appears; NULL if not found - * - * Identical to System V strchr, included for portability. - */ -char * -ellcc_strchr (sp, c) - register char *sp, c; -{ - do - { - if (*sp == c) - return sp; - } while (*sp++); - return NULL; + exit (EXIT_FAILURE); } /* @@ -462,14 +349,13 @@ ellcc_strchr (sp, c) * to the compiler or linker. We need to split individual words into * arguments, taking quoting into account. This can get ugly. */ -void -add_to_argv (str) - CONST char *str; +static void +add_to_argv (const char *str) { int sm = 0; - CONST char *s = (CONST char *)0; + const char *s = (const char *)0; - if ((str == (CONST char *)0) || (str[0] == '\0')) + if ((str == (const char *)0) || (str[0] == '\0')) return; while (*str) @@ -477,7 +363,7 @@ add_to_argv (str) switch (sm) { case 0: /* Start of case - string leading whitespace */ - if (isspace (*str)) + if (isspace ((unsigned char) *str)) str++; else { @@ -487,7 +373,7 @@ add_to_argv (str) break; case 1: /* Non-whitespace character. Mark the start */ - if (isspace (*str)) + if (isspace ((unsigned char) *str)) { /* Reached the end of the argument. Add it. */ int l = str-s; @@ -496,7 +382,7 @@ add_to_argv (str) exec_argv[real_argc][l] = '\0'; real_argc++; sm = 0; /* Back to start state */ - s = (CONST char *)0; + s = (const char *)0; break; } else if (*str == '\\') @@ -541,14 +427,14 @@ add_to_argv (str) } } - if (s != (CONST char *)0) + if (s != (const char *)0) { int l = str-s; exec_argv[real_argc] = xnew (l+2, char); strncpy (exec_argv[real_argc], s, l); exec_argv[real_argc][l] = '\0'; real_argc++; - s = (CONST char *)0; + s = (const char *)0; } } @@ -557,8 +443,8 @@ add_to_argv (str) * is build up the argument vector and exec() it. We must just make sure * that we get all of the required arguments in place. */ -void -do_compile_mode() +static void +do_compile_mode (void) { int i; char ts[4096]; /* Plenty big enough */ @@ -587,8 +473,8 @@ do_compile_mode() * all of the provided arguments, then the final post arguments. Once * all of this has been done, the argument vector is ready to run. */ -void -do_link_mode() +static void +do_link_mode (void) { int i,x; char *t, ts[4096]; /* Plenty big enough */ @@ -648,8 +534,8 @@ do_link_mode() * the header information first, as make-doc will append to the file by * special dispensation. */ -void -do_init_mode() +static void +do_init_mode (void) { int i; char ts[4096]; /* Plenty big enough */