OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.26/] [lcc/] [etc/] [lcc.c] - Diff between revs 4 and 270

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 270
/*
/*
 * lcc [ option ]... [ file | -llib ]...
 * lcc [ option ]... [ file | -llib ]...
 * front end for the ANSI C compiler
 * front end for the ANSI C compiler
 */
 */
static char rcsid[] = "$Id: lcc.c,v 4.33 2001/06/28 22:19:58 drh Exp $";
static char rcsid[] = "$Id: lcc.c,v 4.33 2001/06/28 22:19:58 drh Exp $";
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include <signal.h>
#include <signal.h>
 
 
#ifndef TEMPDIR
#ifndef TEMPDIR
#define TEMPDIR "/tmp"
#define TEMPDIR "/tmp"
#endif
#endif
 
 
typedef struct list *List;
typedef struct list *List;
struct list {           /* circular list nodes: */
struct list {           /* circular list nodes: */
        char *str;              /* option or file name */
        char *str;              /* option or file name */
        List link;              /* next list element */
        List link;              /* next list element */
};
};
 
 
static void *alloc(int);
static void *alloc(int);
static List append(char *,List);
static List append(char *,List);
extern char *basepath(char *);
extern char *basepath(char *);
static int callsys(char *[]);
static int callsys(char *[]);
extern char *concat(char *, char *);
extern char *concat(char *, char *);
static int compile(char *, char *);
static int compile(char *, char *);
static void compose(char *[], List, List, List);
static void compose(char *[], List, List, List);
static void error(char *, char *);
static void error(char *, char *);
static char *exists(char *);
static char *exists(char *);
static char *first(char *);
static char *first(char *);
static int filename(char *, char *);
static int filename(char *, char *);
static List find(char *, List);
static List find(char *, List);
static void help(void);
static void help(void);
static void initinputs(void);
static void initinputs(void);
static void interrupt(int);
static void interrupt(int);
static void opt(char *);
static void opt(char *);
static List path2list(const char *);
static List path2list(const char *);
extern int main(int, char *[]);
extern int main(int, char *[]);
extern char *replace(const char *, int, int);
extern char *replace(const char *, int, int);
static void rm(List);
static void rm(List);
extern char *strsave(const char *);
extern char *strsave(const char *);
extern char *stringf(const char *, ...);
extern char *stringf(const char *, ...);
extern int suffix(char *, char *[], int);
extern int suffix(char *, char *[], int);
extern char *tempname(char *);
extern char *tempname(char *);
 
 
extern int access(char *, int);
extern int access(char *, int);
extern int getpid(void);
extern int getpid(void);
 
 
extern char *cpp[], *include[], *com[], *as[],*ld[], inputs[], *suffixes[];
extern char *cpp[], *include[], *com[], *as[],*ld[], inputs[], *suffixes[];
extern int option(char *);
extern int option(char *);
 
 
static int errcnt;              /* number of errors */
static int errcnt;              /* number of errors */
static int Eflag;               /* -E specified */
static int Eflag;               /* -E specified */
static int Sflag;               /* -S specified */
static int Sflag;               /* -S specified */
static int cflag;               /* -c specified */
static int cflag;               /* -c specified */
static int verbose;             /* incremented for each -v */
static int verbose;             /* incremented for each -v */
static List llist[2];           /* loader files, flags */
static List llist[2];           /* loader files, flags */
static List alist;              /* assembler flags */
static List alist;              /* assembler flags */
static List clist;              /* compiler flags */
static List clist;              /* compiler flags */
static List plist;              /* preprocessor flags */
static List plist;              /* preprocessor flags */
static List ilist;              /* list of additional includes from LCCINPUTS */
static List ilist;              /* list of additional includes from LCCINPUTS */
static List rmlist;             /* list of files to remove */
static List rmlist;             /* list of files to remove */
static char *outfile;           /* ld output file or -[cS] object file */
static char *outfile;           /* ld output file or -[cS] object file */
static int ac;                  /* argument count */
static int ac;                  /* argument count */
static char **av;               /* argument vector */
static char **av;               /* argument vector */
char *tempdir = TEMPDIR;        /* directory for temporary files */
char *tempdir = TEMPDIR;        /* directory for temporary files */
static char *progname;
static char *progname;
static List lccinputs;          /* list of input directories */
static List lccinputs;          /* list of input directories */
 
 
main(int argc, char *argv[]) {
main(int argc, char *argv[]) {
        int i, j, nf;
        int i, j, nf;
 
 
        progname = argv[0];
        progname = argv[0];
        ac = argc + 50;
        ac = argc + 50;
        av = alloc(ac*sizeof(char *));
        av = alloc(ac*sizeof(char *));
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                signal(SIGINT, interrupt);
                signal(SIGINT, interrupt);
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
                signal(SIGTERM, interrupt);
                signal(SIGTERM, interrupt);
#ifdef SIGHUP
#ifdef SIGHUP
        if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
        if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
                signal(SIGHUP, interrupt);
                signal(SIGHUP, interrupt);
#endif
#endif
        if (getenv("TMP"))
        if (getenv("TMP"))
                tempdir = getenv("TMP");
                tempdir = getenv("TMP");
        else if (getenv("TEMP"))
        else if (getenv("TEMP"))
                tempdir = getenv("TEMP");
                tempdir = getenv("TEMP");
        else if (getenv("TMPDIR"))
        else if (getenv("TMPDIR"))
                tempdir = getenv("TMPDIR");
                tempdir = getenv("TMPDIR");
        assert(tempdir);
        assert(tempdir);
        i = strlen(tempdir);
        i = strlen(tempdir);
        for (; i > 0 && tempdir[i-1] == '/' || tempdir[i-1] == '\\'; i--)
        for (; i > 0 && tempdir[i-1] == '/' || tempdir[i-1] == '\\'; i--)
                tempdir[i-1] = '\0';
                tempdir[i-1] = '\0';
        if (argc <= 1) {
        if (argc <= 1) {
                help();
                help();
                exit(0);
                exit(0);
        }
        }
        plist = append("-D__LCC__", 0);
        plist = append("-D__LCC__", 0);
        initinputs();
        initinputs();
        if (getenv("LCCDIR"))
        if (getenv("LCCDIR"))
                option(stringf("-lccdir=%s", getenv("LCCDIR")));
                option(stringf("-lccdir=%s", getenv("LCCDIR")));
        for (nf = 0, i = j = 1; i < argc; i++) {
        for (nf = 0, i = j = 1; i < argc; i++) {
                if (strcmp(argv[i], "-o") == 0) {
                if (strcmp(argv[i], "-o") == 0) {
                        if (++i < argc) {
                        if (++i < argc) {
                                if (suffix(argv[i], suffixes, 2) >= 0) {
                                if (suffix(argv[i], suffixes, 2) >= 0) {
                                        error("-o would overwrite %s", argv[i]);
                                        error("-o would overwrite %s", argv[i]);
                                        exit(8);
                                        exit(8);
                                }
                                }
                                outfile = argv[i];
                                outfile = argv[i];
                                continue;
                                continue;
                        } else {
                        } else {
                                error("unrecognized option `%s'", argv[i-1]);
                                error("unrecognized option `%s'", argv[i-1]);
                                exit(8);
                                exit(8);
                        }
                        }
                } else if (strcmp(argv[i], "-target") == 0) {
                } else if (strcmp(argv[i], "-target") == 0) {
                        if (argv[i+1] && *argv[i+1] != '-')
                        if (argv[i+1] && *argv[i+1] != '-')
                                i++;
                                i++;
                        continue;
                        continue;
                } else if (*argv[i] == '-' && argv[i][1] != 'l') {
                } else if (*argv[i] == '-' && argv[i][1] != 'l') {
                        opt(argv[i]);
                        opt(argv[i]);
                        continue;
                        continue;
                } else if (*argv[i] != '-' && suffix(argv[i], suffixes, 3) >= 0)
                } else if (*argv[i] != '-' && suffix(argv[i], suffixes, 3) >= 0)
                        nf++;
                        nf++;
                argv[j++] = argv[i];
                argv[j++] = argv[i];
        }
        }
        if ((cflag || Sflag) && outfile && nf != 1) {
        if ((cflag || Sflag) && outfile && nf != 1) {
                fprintf(stderr, "%s: -o %s ignored\n", progname, outfile);
                fprintf(stderr, "%s: -o %s ignored\n", progname, outfile);
                outfile = 0;
                outfile = 0;
        }
        }
        argv[j] = 0;
        argv[j] = 0;
        for (i = 0; include[i]; i++)
        for (i = 0; include[i]; i++)
                plist = append(include[i], plist);
                plist = append(include[i], plist);
        if (ilist) {
        if (ilist) {
                List b = ilist;
                List b = ilist;
                do {
                do {
                        b = b->link;
                        b = b->link;
                        plist = append(b->str, plist);
                        plist = append(b->str, plist);
                } while (b != ilist);
                } while (b != ilist);
        }
        }
        ilist = 0;
        ilist = 0;
        for (i = 1; argv[i]; i++)
        for (i = 1; argv[i]; i++)
                if (strcmp(argv[i], "-l") == 0 && argv[i+1] && *argv[i+1] != '-') {      /* -l file */
                if (strcmp(argv[i], "-l") == 0 && argv[i+1] && *argv[i+1] != '-') {      /* -l file */
                        llist[1] = append(argv[i++], llist[1]);
                        llist[1] = append(argv[i++], llist[1]);
                        llist[1] = append(argv[i],   llist[1]);
                        llist[1] = append(argv[i],   llist[1]);
                } else if (*argv[i] == '-')
                } else if (*argv[i] == '-')
                        opt(argv[i]);
                        opt(argv[i]);
                else {
                else {
                        char *name = exists(argv[i]);
                        char *name = exists(argv[i]);
                        if (name) {
                        if (name) {
                                if (strcmp(name, argv[i]) != 0
                                if (strcmp(name, argv[i]) != 0
                                || nf > 1 && suffix(name, suffixes, 3) >= 0)
                                || nf > 1 && suffix(name, suffixes, 3) >= 0)
                                        fprintf(stderr, "%s:\n", name);
                                        fprintf(stderr, "%s:\n", name);
                                filename(name, 0);
                                filename(name, 0);
                        } else
                        } else
                                error("can't find `%s'", argv[i]);
                                error("can't find `%s'", argv[i]);
                }
                }
        if (errcnt == 0 && !Eflag && !Sflag && !cflag && llist[1]) {
        if (errcnt == 0 && !Eflag && !Sflag && !cflag && llist[1]) {
                compose(ld, llist[0], llist[1],
                compose(ld, llist[0], llist[1],
                        append(outfile ? outfile : concat("a", first(suffixes[4])), 0));
                        append(outfile ? outfile : concat("a", first(suffixes[4])), 0));
                if (callsys(av))
                if (callsys(av))
                        errcnt++;
                        errcnt++;
        }
        }
        rm(rmlist);
        rm(rmlist);
        return errcnt ? EXIT_FAILURE : EXIT_SUCCESS;
        return errcnt ? EXIT_FAILURE : EXIT_SUCCESS;
}
}
 
 
/* alloc - allocate n bytes or die */
/* alloc - allocate n bytes or die */
static void *alloc(int n) {
static void *alloc(int n) {
        static char *avail, *limit;
        static char *avail, *limit;
 
 
        n = (n + sizeof(char *) - 1)&~(sizeof(char *) - 1);
        n = (n + sizeof(char *) - 1)&~(sizeof(char *) - 1);
        if (n >= limit - avail) {
        if (n >= limit - avail) {
                avail = malloc(n + 4*1024);
                avail = malloc(n + 4*1024);
                assert(avail);
                assert(avail);
                limit = avail + n + 4*1024;
                limit = avail + n + 4*1024;
        }
        }
        avail += n;
        avail += n;
        return avail - n;
        return avail - n;
}
}
 
 
/* append - append a node with string str onto list, return new list */
/* append - append a node with string str onto list, return new list */
static List append(char *str, List list) {
static List append(char *str, List list) {
        List p = alloc(sizeof *p);
        List p = alloc(sizeof *p);
 
 
        p->str = str;
        p->str = str;
        if (list) {
        if (list) {
                p->link = list->link;
                p->link = list->link;
                list->link = p;
                list->link = p;
        } else
        } else
                p->link = p;
                p->link = p;
        return p;
        return p;
}
}
 
 
/* basepath - return base name for name, e.g. /usr/drh/foo.c => foo */
/* basepath - return base name for name, e.g. /usr/drh/foo.c => foo */
char *basepath(char *name) {
char *basepath(char *name) {
        char *s, *b, *t = 0;
        char *s, *b, *t = 0;
 
 
        for (b = s = name; *s; s++)
        for (b = s = name; *s; s++)
                if (*s == '/' || *s == '\\') {
                if (*s == '/' || *s == '\\') {
                        b = s + 1;
                        b = s + 1;
                        t = 0;
                        t = 0;
                } else if (*s == '.')
                } else if (*s == '.')
                        t = s;
                        t = s;
        s = strsave(b);
        s = strsave(b);
        if (t)
        if (t)
                s[t-b] = 0;
                s[t-b] = 0;
        return s;
        return s;
}
}
 
 
#ifdef WIN32
#ifdef WIN32
#include <process.h>
#include <process.h>
#else
#else
#define _P_WAIT 0
#define _P_WAIT 0
extern int fork(void);
extern int fork(void);
extern int wait(int *);
extern int wait(int *);
extern int execv(const char *, char *[]);
extern int execv(const char *, char *[]);
 
 
static int _spawnvp(int mode, const char *cmdname, const char *const argv[]) {
static int _spawnvp(int mode, const char *cmdname, const char *const argv[]) {
        int pid, n, status;
        int pid, n, status;
 
 
        switch (pid = fork()) {
        switch (pid = fork()) {
        case -1:
        case -1:
                fprintf(stderr, "%s: no more processes\n", progname);
                fprintf(stderr, "%s: no more processes\n", progname);
                return 100;
                return 100;
        case 0:
        case 0:
                execv(cmdname, (char **)argv);
                execv(cmdname, (char **)argv);
                fprintf(stderr, "%s: ", progname);
                fprintf(stderr, "%s: ", progname);
                perror(cmdname);
                perror(cmdname);
                fflush(stdout);
                fflush(stdout);
                exit(100);
                exit(100);
        }
        }
        while ((n = wait(&status)) != pid && n != -1)
        while ((n = wait(&status)) != pid && n != -1)
                ;
                ;
        if (n == -1)
        if (n == -1)
                status = -1;
                status = -1;
        if (status&0377) {
        if (status&0377) {
                fprintf(stderr, "%s: fatal error in %s\n", progname, cmdname);
                fprintf(stderr, "%s: fatal error in %s\n", progname, cmdname);
                status |= 0400;
                status |= 0400;
        }
        }
        return (status>>8)&0377;
        return (status>>8)&0377;
}
}
#endif
#endif
 
 
/* callsys - execute the command described by av[0...], return status */
/* callsys - execute the command described by av[0...], return status */
static int callsys(char **av) {
static int callsys(char **av) {
        int i, status = 0;
        int i, status = 0;
        static char **argv;
        static char **argv;
        static int argc;
        static int argc;
 
 
        for (i = 0; av[i] != NULL; i++)
        for (i = 0; av[i] != NULL; i++)
                ;
                ;
        if (i + 1 > argc) {
        if (i + 1 > argc) {
                argc = i + 1;
                argc = i + 1;
                if (argv == NULL)
                if (argv == NULL)
                        argv = malloc(argc*sizeof *argv);
                        argv = malloc(argc*sizeof *argv);
                else
                else
                        argv = realloc(argv, argc*sizeof *argv);
                        argv = realloc(argv, argc*sizeof *argv);
                assert(argv);
                assert(argv);
        }
        }
        for (i = 0; status == 0 && av[i] != NULL; ) {
        for (i = 0; status == 0 && av[i] != NULL; ) {
                int j = 0;
                int j = 0;
                char *s;
                char *s;
                for ( ; av[i] != NULL && (s = strchr(av[i], '\n')) == NULL; i++)
                for ( ; av[i] != NULL && (s = strchr(av[i], '\n')) == NULL; i++)
                        argv[j++] = av[i];
                        argv[j++] = av[i];
                if (s != NULL) {
                if (s != NULL) {
                        if (s > av[i])
                        if (s > av[i])
                                argv[j++] = stringf("%.*s", s - av[i], av[i]);
                                argv[j++] = stringf("%.*s", s - av[i], av[i]);
                        if (s[1] != '\0')
                        if (s[1] != '\0')
                                av[i] = s + 1;
                                av[i] = s + 1;
                        else
                        else
                                i++;
                                i++;
                }
                }
                argv[j] = NULL;
                argv[j] = NULL;
                if (verbose > 0) {
                if (verbose > 0) {
                        int k;
                        int k;
                        fprintf(stderr, "%s", argv[0]);
                        fprintf(stderr, "%s", argv[0]);
                        for (k = 1; argv[k] != NULL; k++)
                        for (k = 1; argv[k] != NULL; k++)
                                fprintf(stderr, " %s", argv[k]);
                                fprintf(stderr, " %s", argv[k]);
                        fprintf(stderr, "\n");
                        fprintf(stderr, "\n");
                }
                }
                if (verbose < 2)
                if (verbose < 2)
                        status = _spawnvp(_P_WAIT, argv[0], (const char * const *)argv);
                        status = _spawnvp(_P_WAIT, argv[0], (const char * const *)argv);
                if (status == -1) {
                if (status == -1) {
                        fprintf(stderr, "%s: ", progname);
                        fprintf(stderr, "%s: ", progname);
                        perror(argv[0]);
                        perror(argv[0]);
                }
                }
        }
        }
        return status;
        return status;
}
}
 
 
/* concat - return concatenation of strings s1 and s2 */
/* concat - return concatenation of strings s1 and s2 */
char *concat(char *s1, char *s2) {
char *concat(char *s1, char *s2) {
        int n = strlen(s1);
        int n = strlen(s1);
        char *s = alloc(n + strlen(s2) + 1);
        char *s = alloc(n + strlen(s2) + 1);
 
 
        strcpy(s, s1);
        strcpy(s, s1);
        strcpy(s + n, s2);
        strcpy(s + n, s2);
        return s;
        return s;
}
}
 
 
/* compile - compile src into dst, return status */
/* compile - compile src into dst, return status */
static int compile(char *src, char *dst) {
static int compile(char *src, char *dst) {
        compose(com, clist, append(src, 0), append(dst, 0));
        compose(com, clist, append(src, 0), append(dst, 0));
        return callsys(av);
        return callsys(av);
}
}
 
 
/* compose - compose cmd into av substituting a, b, c for $1, $2, $3, resp. */
/* compose - compose cmd into av substituting a, b, c for $1, $2, $3, resp. */
static void compose(char *cmd[], List a, List b, List c) {
static void compose(char *cmd[], List a, List b, List c) {
        int i, j;
        int i, j;
        List lists[3];
        List lists[3];
 
 
        lists[0] = a;
        lists[0] = a;
        lists[1] = b;
        lists[1] = b;
        lists[2] = c;
        lists[2] = c;
        for (i = j = 0; cmd[i]; i++) {
        for (i = j = 0; cmd[i]; i++) {
                char *s = strchr(cmd[i], '$');
                char *s = strchr(cmd[i], '$');
                if (s && isdigit(s[1])) {
                if (s && isdigit(s[1])) {
                        int k = s[1] - '0';
                        int k = s[1] - '0';
                        assert(k >=1 && k <= 3);
                        assert(k >=1 && k <= 3);
                        if (b = lists[k-1]) {
                        if (b = lists[k-1]) {
                                b = b->link;
                                b = b->link;
                                av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1);
                                av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1);
                                strncpy(av[j], cmd[i], s - cmd[i]);
                                strncpy(av[j], cmd[i], s - cmd[i]);
                                av[j][s-cmd[i]] = '\0';
                                av[j][s-cmd[i]] = '\0';
                                strcat(av[j], b->str);
                                strcat(av[j], b->str);
                                strcat(av[j++], s + 2);
                                strcat(av[j++], s + 2);
                                while (b != lists[k-1]) {
                                while (b != lists[k-1]) {
                                        b = b->link;
                                        b = b->link;
                                        assert(j < ac);
                                        assert(j < ac);
                                        av[j++] = b->str;
                                        av[j++] = b->str;
                                };
                                };
                        }
                        }
                } else if (*cmd[i]) {
                } else if (*cmd[i]) {
                        assert(j < ac);
                        assert(j < ac);
                        av[j++] = cmd[i];
                        av[j++] = cmd[i];
                }
                }
        }
        }
        av[j] = NULL;
        av[j] = NULL;
}
}
 
 
/* error - issue error msg according to fmt, bump error count */
/* error - issue error msg according to fmt, bump error count */
static void error(char *fmt, char *msg) {
static void error(char *fmt, char *msg) {
        fprintf(stderr, "%s: ", progname);
        fprintf(stderr, "%s: ", progname);
        fprintf(stderr, fmt, msg);
        fprintf(stderr, fmt, msg);
        fprintf(stderr, "\n");
        fprintf(stderr, "\n");
        errcnt++;
        errcnt++;
}
}
 
 
/* exists - if `name' readable return its path name or return null */
/* exists - if `name' readable return its path name or return null */
static char *exists(char *name) {
static char *exists(char *name) {
        List b;
        List b;
 
 
        if ( (name[0] == '/' || name[0] == '\\' || name[2] == ':')
        if ( (name[0] == '/' || name[0] == '\\' || name[2] == ':')
        && access(name, 4) == 0)
        && access(name, 4) == 0)
                return name;
                return name;
        if (!(name[0] == '/' || name[0] == '\\' || name[2] == ':')
        if (!(name[0] == '/' || name[0] == '\\' || name[2] == ':')
        && (b = lccinputs))
        && (b = lccinputs))
                do {
                do {
                        b = b->link;
                        b = b->link;
                        if (b->str[0]) {
                        if (b->str[0]) {
                                char buf[1024];
                                char buf[1024];
                                sprintf(buf, "%s/%s", b->str, name);
                                sprintf(buf, "%s/%s", b->str, name);
                                if (access(buf, 4) == 0)
                                if (access(buf, 4) == 0)
                                        return strsave(buf);
                                        return strsave(buf);
                        } else if (access(name, 4) == 0)
                        } else if (access(name, 4) == 0)
                                return name;
                                return name;
                } while (b != lccinputs);
                } while (b != lccinputs);
        if (verbose > 1)
        if (verbose > 1)
                return name;
                return name;
        return 0;
        return 0;
}
}
 
 
/* first - return first component in semicolon separated list */
/* first - return first component in semicolon separated list */
static char *first(char *list) {
static char *first(char *list) {
        char *s = strchr(list, ';');
        char *s = strchr(list, ';');
 
 
        if (s) {
        if (s) {
                char buf[1024];
                char buf[1024];
                strncpy(buf, list, s-list);
                strncpy(buf, list, s-list);
                buf[s-list] = '\0';
                buf[s-list] = '\0';
                return strsave(buf);
                return strsave(buf);
        } else
        } else
                return list;
                return list;
}
}
 
 
/* filename - process file name argument `name', return status */
/* filename - process file name argument `name', return status */
static int filename(char *name, char *base) {
static int filename(char *name, char *base) {
        int status = 0;
        int status = 0;
        static char *stemp, *itemp;
        static char *stemp, *itemp;
 
 
        if (base == 0)
        if (base == 0)
                base = basepath(name);
                base = basepath(name);
        switch (suffix(name, suffixes, 4)) {
        switch (suffix(name, suffixes, 4)) {
        case 0:  /* C source files */
        case 0:  /* C source files */
                compose(cpp, plist, append(name, 0), 0);
                compose(cpp, plist, append(name, 0), 0);
                if (Eflag) {
                if (Eflag) {
                        status = callsys(av);
                        status = callsys(av);
                        break;
                        break;
                }
                }
                if (itemp == NULL)
                if (itemp == NULL)
                        itemp = tempname(first(suffixes[1]));
                        itemp = tempname(first(suffixes[1]));
                compose(cpp, plist, append(name, 0), append(itemp, 0));
                compose(cpp, plist, append(name, 0), append(itemp, 0));
                status = callsys(av);
                status = callsys(av);
                if (status == 0)
                if (status == 0)
                        return filename(itemp, base);
                        return filename(itemp, base);
                break;
                break;
        case 1: /* preprocessed source files */
        case 1: /* preprocessed source files */
                if (Eflag)
                if (Eflag)
                        break;
                        break;
                if (Sflag)
                if (Sflag)
                        status = compile(name, outfile ? outfile : concat(base, first(suffixes[2])));
                        status = compile(name, outfile ? outfile : concat(base, first(suffixes[2])));
                else if ((status = compile(name, stemp?stemp:(stemp=tempname(first(suffixes[2]))))) == 0)
                else if ((status = compile(name, stemp?stemp:(stemp=tempname(first(suffixes[2]))))) == 0)
                        return filename(stemp, base);
                        return filename(stemp, base);
                break;
                break;
        case 2: /* assembly language files */
        case 2: /* assembly language files */
                if (Eflag)
                if (Eflag)
                        break;
                        break;
                if (!Sflag) {
                if (!Sflag) {
                        char *ofile;
                        char *ofile;
                        if (cflag && outfile)
                        if (cflag && outfile)
                                ofile = outfile;
                                ofile = outfile;
                        else if (cflag)
                        else if (cflag)
                                ofile = concat(base, first(suffixes[3]));
                                ofile = concat(base, first(suffixes[3]));
                        else
                        else
                                ofile = tempname(first(suffixes[3]));
                                ofile = tempname(first(suffixes[3]));
                        compose(as, alist, append(name, 0), append(ofile, 0));
                        compose(as, alist, append(name, 0), append(ofile, 0));
                        status = callsys(av);
                        status = callsys(av);
                        if (!find(ofile, llist[1]))
                        if (!find(ofile, llist[1]))
                                llist[1] = append(ofile, llist[1]);
                                llist[1] = append(ofile, llist[1]);
                }
                }
                break;
                break;
        case 3: /* object files */
        case 3: /* object files */
                if (!find(name, llist[1]))
                if (!find(name, llist[1]))
                        llist[1] = append(name, llist[1]);
                        llist[1] = append(name, llist[1]);
                break;
                break;
        default:
        default:
                if (Eflag) {
                if (Eflag) {
                        compose(cpp, plist, append(name, 0), 0);
                        compose(cpp, plist, append(name, 0), 0);
                        status = callsys(av);
                        status = callsys(av);
                }
                }
                llist[1] = append(name, llist[1]);
                llist[1] = append(name, llist[1]);
                break;
                break;
        }
        }
        if (status)
        if (status)
                errcnt++;
                errcnt++;
        return status;
        return status;
}
}
 
 
/* find - find 1st occurrence of str in list, return list node or 0 */
/* find - find 1st occurrence of str in list, return list node or 0 */
static List find(char *str, List list) {
static List find(char *str, List list) {
        List b;
        List b;
 
 
        if (b = list)
        if (b = list)
                do {
                do {
                        if (strcmp(str, b->str) == 0)
                        if (strcmp(str, b->str) == 0)
                                return b;
                                return b;
                } while ((b = b->link) != list);
                } while ((b = b->link) != list);
        return 0;
        return 0;
}
}
 
 
/* help - print help message */
/* help - print help message */
static void help(void) {
static void help(void) {
        static char *msgs[] = {
        static char *msgs[] = {
"", " [ option | file ]...\n",
"", " [ option | file ]...\n",
"       except for -l, options are processed left-to-right before files\n",
"       except for -l, options are processed left-to-right before files\n",
"       unrecognized options are taken to be linker options\n",
"       unrecognized options are taken to be linker options\n",
"-A     warn about nonANSI usage; 2nd -A warns more\n",
"-A     warn about nonANSI usage; 2nd -A warns more\n",
"-b     emit expression-level profiling code; see bprint(1)\n",
"-b     emit expression-level profiling code; see bprint(1)\n",
#ifdef sparc
#ifdef sparc
"-Bstatic -Bdynamic     specify static or dynamic libraries\n",
"-Bstatic -Bdynamic     specify static or dynamic libraries\n",
#endif
#endif
"-Bdir/ use the compiler named `dir/rcc'\n",
"-Bdir/ use the compiler named `dir/rcc'\n",
"-c     compile only\n",
"-c     compile only\n",
"-dn    set switch statement density to `n'\n",
"-dn    set switch statement density to `n'\n",
"-Dname -Dname=def      define the preprocessor symbol `name'\n",
"-Dname -Dname=def      define the preprocessor symbol `name'\n",
"-E     run only the preprocessor on the named C programs and unsuffixed files\n",
"-E     run only the preprocessor on the named C programs and unsuffixed files\n",
"-g     produce symbol table information for debuggers\n",
"-g     produce symbol table information for debuggers\n",
"-help or -?    print this message on standard error\n",
"-help or -?    print this message on standard error\n",
"-Idir  add `dir' to the beginning of the list of #include directories\n",
"-Idir  add `dir' to the beginning of the list of #include directories\n",
"-lx    search library `x'\n",
"-lx    search library `x'\n",
"-M     emit makefile dependencies; implies -E\n",
"-M     emit makefile dependencies; implies -E\n",
"-N     do not search the standard directories for #include files\n",
"-N     do not search the standard directories for #include files\n",
"-n     emit code to check for dereferencing zero pointers\n",
"-n     emit code to check for dereferencing zero pointers\n",
"-O     is ignored\n",
"-O     is ignored\n",
"-o file        leave the output in `file'\n",
"-o file        leave the output in `file'\n",
"-P     print ANSI-style declarations for globals on standard error\n",
"-P     print ANSI-style declarations for globals on standard error\n",
"-p -pg emit profiling code; see prof(1) and gprof(1)\n",
"-p -pg emit profiling code; see prof(1) and gprof(1)\n",
"-S     compile to assembly language\n",
"-S     compile to assembly language\n",
"-static        specify static libraries (default is dynamic)\n",
"-static        specify static libraries (default is dynamic)\n",
"-dynamic       specify dynamically linked libraries\n",
"-dynamic       specify dynamically linked libraries\n",
"-t -tname      emit function tracing calls to printf or to `name'\n",
"-t -tname      emit function tracing calls to printf or to `name'\n",
"-target name   is ignored\n",
"-target name   is ignored\n",
"-tempdir=dir   place temporary files in `dir/'", "\n"
"-tempdir=dir   place temporary files in `dir/'", "\n"
"-Uname undefine the preprocessor symbol `name'\n",
"-Uname undefine the preprocessor symbol `name'\n",
"-v     show commands as they are executed; 2nd -v suppresses execution\n",
"-v     show commands as they are executed; 2nd -v suppresses execution\n",
"-w     suppress warnings\n",
"-w     suppress warnings\n",
"-Woarg specify system-specific `arg'\n",
"-Woarg specify system-specific `arg'\n",
"-W[pfal]arg    pass `arg' to the preprocessor, compiler, assembler, or linker\n",
"-W[pfal]arg    pass `arg' to the preprocessor, compiler, assembler, or linker\n",
        0 };
        0 };
        int i;
        int i;
        char *s;
        char *s;
 
 
        msgs[0] = progname;
        msgs[0] = progname;
        for (i = 0; msgs[i]; i++) {
        for (i = 0; msgs[i]; i++) {
                fprintf(stderr, "%s", msgs[i]);
                fprintf(stderr, "%s", msgs[i]);
                if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir)
                if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir)
                        fprintf(stderr, "; default=%s", tempdir);
                        fprintf(stderr, "; default=%s", tempdir);
        }
        }
#define xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s)
#define xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s)
        xx(LCCINPUTS);
        xx(LCCINPUTS);
        xx(LCCDIR);
        xx(LCCDIR);
#ifdef WIN32
#ifdef WIN32
        xx(include);
        xx(include);
        xx(lib);
        xx(lib);
#endif
#endif
#undef xx
#undef xx
}
}
 
 
/* initinputs - if LCCINPUTS or include is defined, use them to initialize various lists */
/* initinputs - if LCCINPUTS or include is defined, use them to initialize various lists */
static void initinputs(void) {
static void initinputs(void) {
        char *s = getenv("LCCINPUTS");
        char *s = getenv("LCCINPUTS");
        List list, b;
        List list, b;
 
 
        if (s == 0 && (s = inputs)[0] == 0)
        if (s == 0 && (s = inputs)[0] == 0)
                s = ".";
                s = ".";
        if (s) {
        if (s) {
                lccinputs = path2list(s);
                lccinputs = path2list(s);
                if (b = lccinputs)
                if (b = lccinputs)
                        do {
                        do {
                                b = b->link;
                                b = b->link;
                                if (strcmp(b->str, ".") != 0) {
                                if (strcmp(b->str, ".") != 0) {
                                        ilist = append(concat("-I", b->str), ilist);
                                        ilist = append(concat("-I", b->str), ilist);
                                        if (strstr(com[1], "win32") == NULL)
                                        if (strstr(com[1], "win32") == NULL)
                                                llist[0] = append(concat("-L", b->str), llist[0]);
                                                llist[0] = append(concat("-L", b->str), llist[0]);
                                } else
                                } else
                                        b->str = "";
                                        b->str = "";
                        } while (b != lccinputs);
                        } while (b != lccinputs);
        }
        }
#ifdef WIN32
#ifdef WIN32
        if (list = b = path2list(getenv("include")))
        if (list = b = path2list(getenv("include")))
                do {
                do {
                        int n;
                        int n;
                        b = b->link;
                        b = b->link;
                        n = strlen(b->str);
                        n = strlen(b->str);
                        if (b->str[n-1] == '\\')
                        if (b->str[n-1] == '\\')
                                b->str[n-1] = '/';
                                b->str[n-1] = '/';
                        ilist = append(stringf("-I\"%s\"", b->str), ilist);
                        ilist = append(stringf("-I\"%s\"", b->str), ilist);
                } while (b != list);
                } while (b != list);
#endif
#endif
}
}
 
 
/* interrupt - catch interrupt signals */
/* interrupt - catch interrupt signals */
static void interrupt(int n) {
static void interrupt(int n) {
        rm(rmlist);
        rm(rmlist);
        exit(n = 100);
        exit(n = 100);
}
}
 
 
/* opt - process option in arg */
/* opt - process option in arg */
static void opt(char *arg) {
static void opt(char *arg) {
        switch (arg[1]) {       /* multi-character options */
        switch (arg[1]) {       /* multi-character options */
        case 'W':       /* -Wxarg */
        case 'W':       /* -Wxarg */
                if (arg[2] && arg[3])
                if (arg[2] && arg[3])
                        switch (arg[2]) {
                        switch (arg[2]) {
                        case 'o':
                        case 'o':
                                if (option(&arg[3]))
                                if (option(&arg[3]))
                                        return;
                                        return;
                                break;
                                break;
                        case 'p':
                        case 'p':
                                plist = append(&arg[3], plist);
                                plist = append(&arg[3], plist);
                                return;
                                return;
                        case 'f':
                        case 'f':
                                if (strcmp(&arg[3], "-C") == 0 && !option("-b"))
                                if (strcmp(&arg[3], "-C") == 0 && !option("-b"))
                                        break;  /* -C requires that -b is supported */
                                        break;  /* -C requires that -b is supported */
                                clist = append(&arg[3], clist);
                                clist = append(&arg[3], clist);
                                if (strcmp(&arg[3], "-unsigned_char=1") == 0) {
                                if (strcmp(&arg[3], "-unsigned_char=1") == 0) {
                                        plist = append("-D__CHAR_UNSIGNED__", plist);
                                        plist = append("-D__CHAR_UNSIGNED__", plist);
                                        plist = append("-U_CHAR_IS_SIGNED", plist);
                                        plist = append("-U_CHAR_IS_SIGNED", plist);
                                }
                                }
#define xx(name,k) \
#define xx(name,k) \
                                if (strcmp(&arg[3], "-wchar_t=" #name) == 0) \
                                if (strcmp(&arg[3], "-wchar_t=" #name) == 0) \
                                        plist = append("-D_WCHAR_T_SIZE=" #k, plist);
                                        plist = append("-D_WCHAR_T_SIZE=" #k, plist);
xx(unsigned_char,1)
xx(unsigned_char,1)
xx(unsigned_short,2)
xx(unsigned_short,2)
xx(unsigned_int,4)
xx(unsigned_int,4)
#undef xx
#undef xx
                                return;
                                return;
                        case 'a':
                        case 'a':
                                alist = append(&arg[3], alist);
                                alist = append(&arg[3], alist);
                                return;
                                return;
                        case 'l':
                        case 'l':
                                llist[0] = append(&arg[3], llist[0]);
                                llist[0] = append(&arg[3], llist[0]);
                                return;
                                return;
                        }
                        }
                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                return;
                return;
        case 'd':       /* -dn -dynamic */
        case 'd':       /* -dn -dynamic */
                if (strcmp(arg, "-dynamic") == 0) {
                if (strcmp(arg, "-dynamic") == 0) {
                        if (!option(arg))
                        if (!option(arg))
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                } else {
                } else {
                        arg[1] = 's';
                        arg[1] = 's';
                        clist = append(arg, clist);
                        clist = append(arg, clist);
                }
                }
                return;
                return;
        case 't':       /* -t -tname -tempdir=dir */
        case 't':       /* -t -tname -tempdir=dir */
                if (strncmp(arg, "-tempdir=", 9) == 0)
                if (strncmp(arg, "-tempdir=", 9) == 0)
                        tempdir = arg + 9;
                        tempdir = arg + 9;
                else
                else
                        clist = append(arg, clist);
                        clist = append(arg, clist);
                return;
                return;
        case 'p':       /* -p -pg */
        case 'p':       /* -p -pg */
                if (option(arg))
                if (option(arg))
                        clist = append(arg, clist);
                        clist = append(arg, clist);
                else
                else
                        fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        fprintf(stderr, "%s: %s ignored\n", progname, arg);
                return;
                return;
        case 'D':       /* -Dname -Dname=def */
        case 'D':       /* -Dname -Dname=def */
        case 'U':       /* -Uname */
        case 'U':       /* -Uname */
        case 'I':       /* -Idir */
        case 'I':       /* -Idir */
                plist = append(arg, plist);
                plist = append(arg, plist);
                return;
                return;
        case 'B':       /* -Bdir -Bstatic -Bdynamic */
        case 'B':       /* -Bdir -Bstatic -Bdynamic */
#ifdef sparc
#ifdef sparc
                if (strcmp(arg, "-Bstatic") == 0 || strcmp(arg, "-Bdynamic") == 0)
                if (strcmp(arg, "-Bstatic") == 0 || strcmp(arg, "-Bdynamic") == 0)
                        llist[1] = append(arg, llist[1]);
                        llist[1] = append(arg, llist[1]);
                else
                else
#endif  
#endif  
                {
                {
                static char *path;
                static char *path;
                if (path)
                if (path)
                        error("-B overwrites earlier option", 0);
                        error("-B overwrites earlier option", 0);
                path = arg + 2;
                path = arg + 2;
                if (strstr(com[1], "win32") != NULL)
                if (strstr(com[1], "win32") != NULL)
                        com[0] = concat(replace(path, '/', '\\'), concat("rcc", first(suffixes[4])));
                        com[0] = concat(replace(path, '/', '\\'), concat("rcc", first(suffixes[4])));
                else
                else
                        com[0] = concat(path, "rcc");
                        com[0] = concat(path, "rcc");
                if (path[0] == 0)
                if (path[0] == 0)
                        error("missing directory in -B option", 0);
                        error("missing directory in -B option", 0);
                }
                }
                return;
                return;
        case 'h':
        case 'h':
                if (strcmp(arg, "-help") == 0) {
                if (strcmp(arg, "-help") == 0) {
                        static int printed = 0;
                        static int printed = 0;
        case '?':
        case '?':
                        if (!printed)
                        if (!printed)
                                help();
                                help();
                        printed = 1;
                        printed = 1;
                        return;
                        return;
                }
                }
                break;
                break;
        case 's':
        case 's':
                if (strcmp(arg, "-static") == 0) {
                if (strcmp(arg, "-static") == 0) {
                        if (!option(arg))
                        if (!option(arg))
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        return;
                        return;
                }
                }
                break;
                break;
        }
        }
        if (arg[2] == 0)
        if (arg[2] == 0)
                switch (arg[1]) {       /* single-character options */
                switch (arg[1]) {       /* single-character options */
                case 'S':
                case 'S':
                        Sflag++;
                        Sflag++;
                        return;
                        return;
                case 'O':
                case 'O':
                        fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        return;
                        return;
                case 'A': case 'n': case 'w': case 'P':
                case 'A': case 'n': case 'w': case 'P':
                        clist = append(arg, clist);
                        clist = append(arg, clist);
                        return;
                        return;
                case 'g': case 'b':
                case 'g': case 'b':
                        if (option(arg))
                        if (option(arg))
                                clist = append(arg[1] == 'g' ? "-g2" : arg, clist);
                                clist = append(arg[1] == 'g' ? "-g2" : arg, clist);
                        else
                        else
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        return;
                        return;
                case 'G':
                case 'G':
                        if (option(arg)) {
                        if (option(arg)) {
                                clist = append("-g3", clist);
                                clist = append("-g3", clist);
                                llist[0] = append("-N", llist[0]);
                                llist[0] = append("-N", llist[0]);
                        } else
                        } else
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                        return;
                        return;
                case 'E':
                case 'E':
                        Eflag++;
                        Eflag++;
                        return;
                        return;
                case 'c':
                case 'c':
                        cflag++;
                        cflag++;
                        return;
                        return;
                case 'M':
                case 'M':
                        Eflag++;        /* -M implies -E */
                        Eflag++;        /* -M implies -E */
                        plist = append(arg, plist);
                        plist = append(arg, plist);
                        return;
                        return;
                case 'N':
                case 'N':
                        if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
                        if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
                                plist = append("-nostdinc", plist);
                                plist = append("-nostdinc", plist);
                        include[0] = 0;
                        include[0] = 0;
                        ilist = 0;
                        ilist = 0;
                        return;
                        return;
                case 'v':
                case 'v':
                        if (verbose++ == 0) {
                        if (verbose++ == 0) {
                                if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
                                if (strcmp(basepath(cpp[0]), "gcc-cpp") == 0)
                                        plist = append(arg, plist);
                                        plist = append(arg, plist);
                                clist = append(arg, clist);
                                clist = append(arg, clist);
                                fprintf(stderr, "%s %s\n", progname, rcsid);
                                fprintf(stderr, "%s %s\n", progname, rcsid);
                        }
                        }
                        return;
                        return;
                }
                }
        if (cflag || Sflag || Eflag)
        if (cflag || Sflag || Eflag)
                fprintf(stderr, "%s: %s ignored\n", progname, arg);
                fprintf(stderr, "%s: %s ignored\n", progname, arg);
        else
        else
                llist[1] = append(arg, llist[1]);
                llist[1] = append(arg, llist[1]);
}
}
 
 
/* path2list - convert a colon- or semicolon-separated list to a list */
/* path2list - convert a colon- or semicolon-separated list to a list */
static List path2list(const char *path) {
static List path2list(const char *path) {
        List list = NULL;
        List list = NULL;
        char sep = ':';
        char sep = ':';
 
 
        if (path == NULL)
        if (path == NULL)
                return NULL;
                return NULL;
        if (strchr(path, ';'))
        if (strchr(path, ';'))
                sep = ';';
                sep = ';';
        while (*path) {
        while (*path) {
                char *p, buf[512];
                char *p, buf[512];
                if (p = strchr(path, sep)) {
                if (p = strchr(path, sep)) {
                        assert(p - path < sizeof buf);
                        assert(p - path < sizeof buf);
                        strncpy(buf, path, p - path);
                        strncpy(buf, path, p - path);
                        buf[p-path] = '\0';
                        buf[p-path] = '\0';
                } else {
                } else {
                        assert(strlen(path) < sizeof buf);
                        assert(strlen(path) < sizeof buf);
                        strcpy(buf, path);
                        strcpy(buf, path);
                }
                }
                if (!find(buf, list))
                if (!find(buf, list))
                        list = append(strsave(buf), list);
                        list = append(strsave(buf), list);
                if (p == 0)
                if (p == 0)
                        break;
                        break;
                path = p + 1;
                path = p + 1;
        }
        }
        return list;
        return list;
}
}
 
 
/* replace - copy str, then replace occurrences of from with to, return the copy */
/* replace - copy str, then replace occurrences of from with to, return the copy */
char *replace(const char *str, int from, int to) {
char *replace(const char *str, int from, int to) {
        char *s = strsave(str), *p = s;
        char *s = strsave(str), *p = s;
 
 
        for ( ; (p = strchr(p, from)) != NULL; p++)
        for ( ; (p = strchr(p, from)) != NULL; p++)
                *p = to;
                *p = to;
        return s;
        return s;
}
}
 
 
/* rm - remove files in list */
/* rm - remove files in list */
static void rm(List list) {
static void rm(List list) {
        if (list) {
        if (list) {
                List b = list;
                List b = list;
                if (verbose)
                if (verbose)
                        fprintf(stderr, "rm");
                        fprintf(stderr, "rm");
                do {
                do {
                        if (verbose)
                        if (verbose)
                                fprintf(stderr, " %s", b->str);
                                fprintf(stderr, " %s", b->str);
                        if (verbose < 2)
                        if (verbose < 2)
                                remove(b->str);
                                remove(b->str);
                } while ((b = b->link) != list);
                } while ((b = b->link) != list);
                if (verbose)
                if (verbose)
                        fprintf(stderr, "\n");
                        fprintf(stderr, "\n");
        }
        }
}
}
 
 
/* strsave - return a saved copy of string str */
/* strsave - return a saved copy of string str */
char *strsave(const char *str) {
char *strsave(const char *str) {
        return strcpy(alloc(strlen(str)+1), str);
        return strcpy(alloc(strlen(str)+1), str);
}
}
 
 
/* stringf - format and return a string */
/* stringf - format and return a string */
char *stringf(const char *fmt, ...) {
char *stringf(const char *fmt, ...) {
        char buf[1024];
        char buf[1024];
        va_list ap;
        va_list ap;
        int n;
        int n;
 
 
        va_start(ap, fmt);
        va_start(ap, fmt);
        n = vsprintf(buf, fmt, ap);
        n = vsprintf(buf, fmt, ap);
        va_end(ap);
        va_end(ap);
        return strsave(buf);
        return strsave(buf);
}
}
 
 
/* suffix - if one of tails[0..n-1] holds a proper suffix of name, return its index */
/* suffix - if one of tails[0..n-1] holds a proper suffix of name, return its index */
int suffix(char *name, char *tails[], int n) {
int suffix(char *name, char *tails[], int n) {
        int i, len = strlen(name);
        int i, len = strlen(name);
 
 
        for (i = 0; i < n; i++) {
        for (i = 0; i < n; i++) {
                char *s = tails[i], *t;
                char *s = tails[i], *t;
                for ( ; t = strchr(s, ';'); s = t + 1) {
                for ( ; t = strchr(s, ';'); s = t + 1) {
                        int m = t - s;
                        int m = t - s;
                        if (len > m && strncmp(&name[len-m], s, m) == 0)
                        if (len > m && strncmp(&name[len-m], s, m) == 0)
                                return i;
                                return i;
                }
                }
                if (*s) {
                if (*s) {
                        int m = strlen(s);
                        int m = strlen(s);
                        if (len > m && strncmp(&name[len-m], s, m) == 0)
                        if (len > m && strncmp(&name[len-m], s, m) == 0)
                                return i;
                                return i;
                }
                }
        }
        }
        return -1;
        return -1;
}
}
 
 
/* tempname - generate a temporary file name in tempdir with given suffix */
/* tempname - generate a temporary file name in tempdir with given suffix */
char *tempname(char *suffix) {
char *tempname(char *suffix) {
        static int n;
        static int n;
        char *name = stringf("%s/lcc%d%d%s", tempdir, getpid(), n++, suffix);
        char *name = stringf("%s/lcc%d%d%s", tempdir, getpid(), n++, suffix);
 
 
        if (strstr(com[1], "win32") != NULL)
        if (strstr(com[1], "win32") != NULL)
                name = replace(name, '/', '\\');
                name = replace(name, '/', '\\');
        rmlist = append(name, rmlist);
        rmlist = append(name, rmlist);
        return name;
        return name;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.