diff options
author | IronClawTrem <louie.nutman@gmail.com> | 2020-02-16 03:40:06 +0000 |
---|---|---|
committer | IronClawTrem <louie.nutman@gmail.com> | 2020-02-16 03:40:06 +0000 |
commit | 425decdf7e9284d15aa726e3ae96b9942fb0e3ea (patch) | |
tree | 6c0dd7edfefff1be7b9e75fe0b3a0a85fe1595f3 /src/tools/lcc/cpp/unix.c | |
parent | ccb0b2e4d6674a7a00c9bf491f08fc73b6898c54 (diff) |
create tremded branch
Diffstat (limited to 'src/tools/lcc/cpp/unix.c')
-rw-r--r-- | src/tools/lcc/cpp/unix.c | 215 |
1 files changed, 111 insertions, 104 deletions
diff --git a/src/tools/lcc/cpp/unix.c b/src/tools/lcc/cpp/unix.c index ff1496a..ee975aa 100644 --- a/src/tools/lcc/cpp/unix.c +++ b/src/tools/lcc/cpp/unix.c @@ -1,134 +1,141 @@ -#include <stdio.h> #include <stddef.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include "cpp.h" -extern int lcc_getopt(int, char *const *, const char *); -extern char *optarg, rcsid[]; -extern int optind; -int verbose; -int Mflag; /* only print active include files */ -char *objname; /* "src.$O: " */ -int Cplusplus = 1; +extern int lcc_getopt(int, char *const *, const char *); +extern char *optarg, rcsid[]; +extern int optind; +int verbose; +int Mflag; /* only print active include files */ +char *objname; /* "src.$O: " */ +int Cplusplus = 1; -void -setup(int argc, char **argv) +void setup(int argc, char **argv) { - int c, fd, i; - char *fp, *dp; - Tokenrow tr; - extern void setup_kwtab(void); - uchar *includeDirs[ NINCLUDE ] = { 0 }; - int numIncludeDirs = 0; + int c, fd, i; + char *fp, *dp; + Tokenrow tr; + extern void setup_kwtab(void); + uchar *includeDirs[NINCLUDE] = {0}; + int numIncludeDirs = 0; - setup_kwtab(); - while ((c = lcc_getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1) - switch (c) { - case 'N': - for (i=0; i<NINCLUDE; i++) - if (includelist[i].always==1) - includelist[i].deleted = 1; - break; - case 'I': - includeDirs[ numIncludeDirs++ ] = newstring( (uchar *)optarg, strlen( optarg ), 0 ); - break; - case 'D': - case 'U': - setsource("<cmdarg>", -1, optarg); - maketokenrow(3, &tr); - gettokens(&tr, 1); - doadefine(&tr, c); - unsetsource(); - break; - case 'M': - Mflag++; - break; - case 'v': - fprintf(stderr, "%s %s\n", argv[0], rcsid); - break; - case 'V': - verbose++; - break; - case '+': - Cplusplus++; - break; - default: - break; - } - dp = "."; - fp = "<stdin>"; - fd = 0; - if (optind<argc) { - dp = basepath( argv[optind] ); - fp = (char*)newstring((uchar*)argv[optind], strlen(argv[optind]), 0); - if ((fd = open(fp, 0)) <= 0) - error(FATAL, "Can't open input file %s", fp); - } - if (optind+1<argc) { - int fdo; + setup_kwtab(); + while ((c = lcc_getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1) + switch (c) + { + case 'N': + for (i = 0; i < NINCLUDE; i++) + if (includelist[i].always == 1) + includelist[i].deleted = 1; + break; + case 'I': + includeDirs[numIncludeDirs++] = newstring((uchar *)optarg, strlen(optarg), 0); + break; + case 'D': + case 'U': + setsource("<cmdarg>", -1, optarg); + maketokenrow(3, &tr); + gettokens(&tr, 1); + doadefine(&tr, c); + unsetsource(); + break; + case 'M': + Mflag++; + break; + case 'v': + fprintf(stderr, "%s %s\n", argv[0], rcsid); + break; + case 'V': + verbose++; + break; + case '+': + Cplusplus++; + break; + default: + break; + } + dp = "."; + fp = "<stdin>"; + fd = 0; + if (optind < argc) + { + dp = basepath(argv[optind]); + fp = (char *)newstring((uchar *)argv[optind], strlen(argv[optind]), 0); + if ((fd = open(fp, 0)) <= 0) + error(FATAL, "Can't open input file %s", fp); + } + if (optind + 1 < argc) + { + int fdo; #ifdef WIN32 - fdo = creat(argv[optind+1], _S_IREAD | _S_IWRITE); + fdo = creat(argv[optind + 1], _S_IREAD | _S_IWRITE); #else - fdo = creat(argv[optind+1], 0666); + fdo = creat(argv[optind + 1], 0666); #endif - if (fdo<0) - error(FATAL, "Can't open output file %s", argv[optind+1]); - dup2(fdo, 1); - } - if(Mflag) - setobjname(fp); - includelist[NINCLUDE-1].always = 0; - includelist[NINCLUDE-1].file = dp; + if (fdo < 0) + error(FATAL, "Can't open output file %s", argv[optind + 1]); + dup2(fdo, 1); + } + if (Mflag) + setobjname(fp); + includelist[NINCLUDE - 1].always = 0; + includelist[NINCLUDE - 1].file = dp; - for( i = 0; i < numIncludeDirs; i++ ) - appendDirToIncludeList( (char *)includeDirs[ i ] ); + for (i = 0; i < numIncludeDirs; i++) + appendDirToIncludeList((char *)includeDirs[i]); - setsource(fp, fd, NULL); + setsource(fp, fd, NULL); } - -char *basepath( char *fname ) +char *basepath(char *fname) { - char *dp = "."; - char *p; - if ((p = strrchr(fname, '/')) != NULL) { - int dlen = p - fname; - dp = (char*)newstring((uchar*)fname, dlen+1, 0); - dp[dlen] = '\0'; - } + char *dp = "."; + char *p; + if ((p = strrchr(fname, '/')) != NULL) + { + int dlen = p - fname; + dp = (char *)newstring((uchar *)fname, dlen + 1, 0); + dp[dlen] = '\0'; + } - return dp; + return dp; } /* memmove is defined here because some vendors don't provide it at all and others do a terrible job (like calling malloc) */ // -- ouch, that hurts -- ln -#ifndef __APPLE__ /* always use the system memmove() on Mac OS X. --ryan. */ +/* always use the system memmove() on Mac OS X. --ryan. */ +#if !defined(__APPLE__) && !defined(_MSC_VER) #ifdef memmove #undef memmove #endif -void * -memmove(void *dp, const void *sp, size_t n) +void *memmove(void *dp, const void *sp, size_t n) { - unsigned char *cdp, *csp; + unsigned char *cdp, *csp; - if (n<=0) - return dp; - cdp = dp; - csp = (unsigned char *)sp; - if (cdp < csp) { - do { - *cdp++ = *csp++; - } while (--n); - } else { - cdp += n; - csp += n; - do { - *--cdp = *--csp; - } while (--n); - } - return dp; + if (n <= 0) + return dp; + cdp = dp; + csp = (unsigned char *)sp; + if (cdp < csp) + { + do + { + *cdp++ = *csp++; + } while (--n); + } + else + { + cdp += n; + csp += n; + do + { + *--cdp = *--csp; + } while (--n); + } + return dp; } #endif |