int main(int ac, char **av) { t_all all; int ret; all.elem = NULL; all.win.nb_elem = 0; all.show = 1; if (ac > 1 && av[1] != NULL) { ft_signal(); if (init_term(&all)) return (-1); if ((ret = init_lst(&(all.elem), av, &all)) == TRUE) { memoire(&all, 0); ret = ft_select(&all); } if (reset_term(&all) == -1) return (-1); if (ret == -2) print_select(&all); if (all.win.nb_elem > 0) freelst(&all); } return (0); }
static void lint2(void) { char *path, **args; args = xcalloc(1, sizeof (char *)); if (!Bflag) { path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2") + strlen(target_prefix)); (void)sprintf(path, "%s/%slint2", PATH_LIBEXEC, target_prefix); } else { /* * XXX Unclear whether we should be using target_prefix * XXX here. [email protected] */ path = xmalloc(strlen(libexec_path) + sizeof ("/lint2")); (void)sprintf(path, "%s/lint2", libexec_path); } appcstrg(&args, path); applst(&args, l2flags); applst(&args, l2libs); applst(&args, p2in); runchild(path, args, p2out, -1); free(path); freelst(&args); free(args); }
/* * Read a file name from the command line * and pass it through lint1 if it is a C source. */ static void fname(const char *name) { const char *bn, *suff; char **args, *ofn, *p, *pathname; size_t len; int is_stdin; int fd; is_stdin = (strcmp(name, "-") == 0); bn = lbasename(name, '/'); suff = lbasename(bn, '.'); if (strcmp(suff, "ln") == 0) { /* only for lint2 */ if (!iflag) appcstrg(&p2in, name); return; } if (!is_stdin && strcmp(suff, "c") != 0 && (strncmp(bn, "llib-l", 6) != 0 || bn != suff)) { warnx("unknown file type: %s\n", name); return; } if (!iflag || !first) (void)printf("%s:\n", is_stdin ? "{standard input}" : Fflag ? name : bn); /* build the name of the output file of lint1 */ if (oflag) { ofn = outputfn; outputfn = NULL; oflag = 0; } else if (iflag) { if (is_stdin) { warnx("-i not supported without -o for standard input"); return; } ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2)); len = bn == suff ? strlen(bn) : (size_t)((suff - 1) - bn); (void)sprintf(ofn, "%.*s", (int)len, bn); (void)strcat(ofn, ".ln"); } else { ofn = xmalloc(strlen(tmpdir) + sizeof ("lint1.XXXXXX")); (void)sprintf(ofn, "%slint1.XXXXXX", tmpdir); fd = mkstemp(ofn); if (fd == -1) { warn("can't make temp"); terminate(-1); } close(fd); } if (!iflag) appcstrg(&p1out, ofn); args = xcalloc(1, sizeof (char *)); /* run cc */ if (getenv("CC") == NULL) { pathname = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc")); (void)sprintf(pathname, "%s/cc", PATH_USRBIN); appcstrg(&args, pathname); } else { pathname = strdup(getenv("CC")); for (p = strtok(pathname, " \t"); p; p = strtok(NULL, " \t")) appcstrg(&args, p); } applst(&args, cflags); applst(&args, lcflags); appcstrg(&args, name); /* we reuse the same tmp file for cpp output, so rewind and truncate */ if (lseek(cppoutfd, (off_t)0, SEEK_SET) != 0) { warn("lseek"); terminate(-1); } if (ftruncate(cppoutfd, (off_t)0) != 0) { warn("ftruncate"); terminate(-1); } runchild(pathname, args, cppout, cppoutfd); free(pathname); freelst(&args); /* run lint1 */ if (!Bflag) { pathname = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") + strlen(target_prefix)); (void)sprintf(pathname, "%s/%slint1", PATH_LIBEXEC, target_prefix); } else { /* * XXX Unclear whether we should be using target_prefix * XXX here. [email protected] */ pathname = xmalloc(strlen(libexec_path) + sizeof ("/lint1")); (void)sprintf(pathname, "%s/lint1", libexec_path); } appcstrg(&args, pathname); applst(&args, l1flags); appcstrg(&args, cppout); appcstrg(&args, ofn); runchild(pathname, args, ofn, -1); free(pathname); freelst(&args); appcstrg(&p2in, ofn); free(ofn); free(args); }
int main(int argc, char *argv[]) { int c; char flgbuf[3], *s; const char *tmp; size_t len; if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) { tmpdir = _PATH_TMP; } else { s = xmalloc(len + 2); (void)sprintf(s, "%s%s", tmp, tmp[len - 1] == '/' ? "" : "/"); tmpdir = s; } cppout = xmalloc(strlen(tmpdir) + sizeof ("lint0.XXXXXX")); (void)sprintf(cppout, "%slint0.XXXXXX", tmpdir); cppoutfd = mkstemp(cppout); if (cppoutfd == -1) { warn("can't make temp"); terminate(-1); } p1out = xcalloc(1, sizeof (char *)); p2in = xcalloc(1, sizeof (char *)); cflags = xcalloc(1, sizeof (char *)); lcflags = xcalloc(1, sizeof (char *)); l1flags = xcalloc(1, sizeof (char *)); l2flags = xcalloc(1, sizeof (char *)); l2libs = xcalloc(1, sizeof (char *)); deflibs = xcalloc(1, sizeof (char *)); libs = xcalloc(1, sizeof (char *)); libsrchpath = xcalloc(1, sizeof (char *)); appcstrg(&cflags, "-E"); appcstrg(&cflags, "-x"); appcstrg(&cflags, "c"); #if 0 appcstrg(&cflags, "-D__attribute__(x)="); appcstrg(&cflags, "-D__extension__(x)=/*NOSTRICT*/0"); #else appcstrg(&cflags, "-U__GNUC__"); appcstrg(&cflags, "-undef"); #endif #if 0 appcstrg(&cflags, "-Wp,-$"); #endif appcstrg(&cflags, "-Wp,-C"); appcstrg(&cflags, "-Wcomment"); appcstrg(&cflags, "-D__LINT__"); appcstrg(&cflags, "-Dlint"); /* XXX don't def. with -s */ appdef(&cflags, "lint"); appcstrg(&deflibs, "c"); if (signal(SIGHUP, terminate) == SIG_IGN) (void)signal(SIGHUP, SIG_IGN); (void)signal(SIGINT, terminate); (void)signal(SIGQUIT, terminate); (void)signal(SIGTERM, terminate); while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:SU:VX:")) != -1) { switch (c) { case 'a': case 'b': case 'c': case 'e': case 'g': case 'r': case 'v': case 'w': case 'z': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); break; case 'F': Fflag = 1; /* FALLTHROUGH */ case 'u': case 'h': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); appcstrg(&l2flags, flgbuf); break; case 'X': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); appcstrg(&l1flags, optarg); break; case 'i': if (Cflag) usage(); iflag = 1; break; case 'n': freelst(&deflibs); break; case 'p': appcstrg(&lcflags, "-Wtraditional"); appcstrg(&lcflags, "-Wno-system-headers"); appcstrg(&l1flags, "-p"); appcstrg(&l2flags, "-p"); if (*deflibs != NULL) { freelst(&deflibs); appcstrg(&deflibs, "c"); } break; case 's': if (tflag) usage(); freelst(&lcflags); appcstrg(&lcflags, "-trigraphs"); appcstrg(&lcflags, "-Wtrigraphs"); appcstrg(&lcflags, "-pedantic"); appcstrg(&lcflags, "-D__STRICT_ANSI__"); appcstrg(&l1flags, "-s"); appcstrg(&l2flags, "-s"); sflag = 1; break; case 'S': if (tflag) usage(); appcstrg(&l1flags, "-S"); Sflag = 1; break; #if !HAVE_CONFIG_H case 't': if (sflag) usage(); freelst(&lcflags); appcstrg(&lcflags, "-traditional"); appstrg(&lcflags, concat2("-D", MACHINE)); appstrg(&lcflags, concat2("-D", MACHINE_ARCH)); appcstrg(&l1flags, "-t"); appcstrg(&l2flags, "-t"); tflag = 1; break; #endif case 'x': appcstrg(&l2flags, "-x"); break; case 'C': if (Cflag || oflag || iflag) usage(); Cflag = 1; appstrg(&l2flags, concat2("-C", optarg)); p2out = xmalloc(sizeof ("llib-l.ln") + strlen(optarg)); (void)sprintf(p2out, "llib-l%s.ln", optarg); freelst(&deflibs); break; case 'd': if (dflag) usage(); dflag = 1; appcstrg(&cflags, "-nostdinc"); appcstrg(&cflags, "-idirafter"); appcstrg(&cflags, optarg); break; case 'D': case 'I': case 'M': case 'U': (void)sprintf(flgbuf, "-%c", c); appstrg(&cflags, concat2(flgbuf, optarg)); break; case 'l': appcstrg(&libs, optarg); break; case 'o': if (Cflag || oflag) usage(); oflag = 1; outputfn = xstrdup(optarg); break; case 'L': appcstrg(&libsrchpath, optarg); break; case 'H': appcstrg(&l2flags, "-H"); break; case 'B': Bflag = 1; libexec_path = xstrdup(optarg); break; case 'V': Vflag = 1; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; /* * To avoid modifying getopt(3)'s state engine midstream, we * explicitly accept just a few options after the first source file. * * In particular, only -l<lib> and -L<libdir> (and these with a space * after -l or -L) are allowed. */ while (argc > 0) { const char *arg = argv[0]; if (arg[0] == '-') { char ***list; /* option */ switch (arg[1]) { case 'l': list = &libs; break; case 'L': list = &libsrchpath; break; default: usage(); /* NOTREACHED */ } if (arg[2]) appcstrg(list, arg + 2); else if (argc > 1) { argc--; appcstrg(list, *++argv); } else usage(); } else { /* filename */ fname(arg); first = 0; } argc--; argv++; } if (first) usage(); if (iflag) terminate(0); if (!oflag) { if ((tmp = getenv("LIBDIR")) == NULL || strlen(tmp) == 0) tmp = PATH_LINTLIB; appcstrg(&libsrchpath, tmp); findlibs(libs); findlibs(deflibs); } (void)printf("Lint pass2:\n"); lint2(); if (oflag) cat(p2in, outputfn); if (Cflag) p2out = NULL; terminate(0); /* NOTREACHED */ }