📄 main.c
字号:
/* $XConsortium: main.c /main/84 1996/12/04 10:11:23 swick $ *//* $XFree86: xc/config/makedepend/main.c,v 3.11.2.1 1997/05/11 05:04:07 dawes Exp $ *//*Copyright (c) 1993, 1994 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*/#include "def.h"#ifdef hpux#define sigvec sigvector#endif /* hpux */#ifdef X_POSIX_C_SOURCE#define _POSIX_C_SOURCE X_POSIX_C_SOURCE#include <signal.h>#undef _POSIX_C_SOURCE#else#if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE)#include <signal.h>#else#define _POSIX_SOURCE#include <signal.h>#undef _POSIX_SOURCE#endif#endif#if NeedVarargsPrototypes#include <stdarg.h>#endif#ifdef MINIX#define USE_CHMOD 1#endif#ifdef DEBUGint _debugmask;#endifchar *ProgramName;char *directives[] = { "if", "ifdef", "ifndef", "else", "endif", "define", "undef", "include", "line", "pragma", "error", "ident", "sccs", "elif", "eject", "warning", NULL};#define MAKEDEPEND#include "imakemdep.h" /* from config sources */#undef MAKEDEPENDstruct inclist inclist[ MAXFILES ], *inclistp = inclist, maininclist;char *filelist[ MAXFILES ];char *includedirs[ MAXDIRS + 1 ];char *notdotdot[ MAXDIRS ];char *objprefix = "";char *objsuffix = OBJSUFFIX;char *startat = "# DO NOT DELETE";int width = 78;boolean append = FALSE;boolean printed = FALSE;boolean verbose = FALSE;boolean show_where_not = FALSE;boolean warn_multiple = FALSE; /* Warn on multiple includes of same file */void freefile();void redirect();#if !NeedVarargsPrototypesvoid fatalerr();void warning();void warning1();#endifstatic#ifdef SIGNALRETURNSINTint#elsevoid#endifcatch (sig) int sig;{ fflush (stdout); fatalerr ("got signal %d\n", sig);}#if defined(USG) || (defined(i386) && defined(SYSV)) || defined(WIN32) || defined(__EMX__) || defined(Lynx_22)#define USGISH#endif#ifndef USGISH#ifndef _POSIX_SOURCE#define sigaction sigvec#define sa_handler sv_handler#define sa_mask sv_mask#define sa_flags sv_flags#endifstruct sigaction sig_act;#endif /* USGISH */main(argc, argv) int argc; char **argv;{ register char **fp = filelist; register char **incp = includedirs; register char *p; register struct inclist *ip; char *makefile = NULL; struct filepointer *filecontent; struct symtab *psymp = predefs; char *endmarker = NULL; char *defincdir = NULL; char **undeflist = NULL; int numundefs = 0, i; ProgramName = argv[0]; while (psymp->s_name) { define2(psymp->s_name, psymp->s_value, &maininclist); psymp++; } if (argc == 2 && argv[1][0] == '@') { struct stat ast; int afd; char *args; char **nargv; int nargc; char quotechar = '\0'; nargc = 1; if ((afd = open(argv[1]+1, O_RDONLY)) < 0) fatalerr("cannot open \"%s\"\n", argv[1]+1); fstat(afd, &ast); args = (char *)malloc(ast.st_size + 1); if ((ast.st_size = read(afd, args, ast.st_size)) < 0) fatalerr("failed to read %s\n", argv[1]+1); args[ast.st_size] = '\0'; close(afd); for (p = args; *p; p++) { if (quotechar) { if (quotechar == '\\' || (*p == quotechar && p[-1] != '\\')) quotechar = '\0'; continue; } switch (*p) { case '\\': case '"': case '\'': quotechar = *p; break; case ' ': case '\n': *p = '\0'; if (p > args && p[-1]) nargc++; break; } } if (p[-1]) nargc++; nargv = (char **)malloc(nargc * sizeof(char *)); nargv[0] = argv[0]; argc = 1; for (p = args; argc < nargc; p += strlen(p) + 1) if (*p) nargv[argc++] = p; argv = nargv; } for(argc--, argv++; argc; argc--, argv++) { /* if looking for endmarker then check before parsing */ if (endmarker && strcmp (endmarker, *argv) == 0) { endmarker = NULL; continue; } if (**argv != '-') { /* treat +thing as an option for C++ */ if (endmarker && **argv == '+') continue; *fp++ = argv[0]; continue; } switch(argv[0][1]) { case '-': endmarker = &argv[0][2]; if (endmarker[0] == '\0') endmarker = "--"; break; case 'D': if (argv[0][2] == '\0') { argv++; argc--; } for (p=argv[0] + 2; *p ; p++) if (*p == '=') { *p = ' '; break; } define(argv[0] + 2, &maininclist); break; case 'I': if (incp >= includedirs + MAXDIRS) fatalerr("Too many -I flags.\n"); *incp++ = argv[0]+2; if (**(incp-1) == '\0') { *(incp-1) = *(++argv); argc--; } break; case 'U': /* Undef's override all -D's so save them up */ numundefs++; if (numundefs == 1) undeflist = malloc(sizeof(char *)); else undeflist = realloc(undeflist, numundefs * sizeof(char *)); if (argv[0][2] == '\0') { argv++; argc--; } undeflist[numundefs - 1] = argv[0] + 2; break; case 'Y': defincdir = argv[0]+2; break; /* do not use if endmarker processing */ case 'a': if (endmarker) break; append = TRUE; break; case 'w': if (endmarker) break; if (argv[0][2] == '\0') { argv++; argc--; width = atoi(argv[0]); } else width = atoi(argv[0]+2); break; case 'o': if (endmarker) break; if (argv[0][2] == '\0') { argv++; argc--; objsuffix = argv[0]; } else objsuffix = argv[0]+2; break; case 'p': if (endmarker) break; if (argv[0][2] == '\0') { argv++; argc--; objprefix = argv[0]; } else objprefix = argv[0]+2; break; case 'v': if (endmarker) break; verbose = TRUE;#ifdef DEBUG if (argv[0][2]) _debugmask = atoi(argv[0]+2);#endif break; case 's': if (endmarker) break; startat = argv[0]+2; if (*startat == '\0') { startat = *(++argv); argc--; } if (*startat != '#') fatalerr("-s flag's value should start %s\n", "with '#'."); break; case 'f': if (endmarker) break; makefile = argv[0]+2; if (*makefile == '\0') { makefile = *(++argv); argc--; } break; case 'm': warn_multiple = TRUE; break; /* Ignore -O, -g so we can just pass ${CFLAGS} to makedepend */ case 'O': case 'g': break; default: if (endmarker) break; /* fatalerr("unknown opt = %s\n", argv[0]); */ warning("ignoring option %s\n", argv[0]); } } /* Now do the undefs from the command line */ for (i = 0; i < numundefs; i++) undefine(undeflist[i], &maininclist); if (numundefs > 0) free(undeflist); if (!defincdir) {#ifdef PREINCDIR if (incp >= includedirs + MAXDIRS) fatalerr("Too many -I flags.\n"); *incp++ = PREINCDIR;#endif#ifdef __EMX__ { char *emxinc = getenv("C_INCLUDE_PATH"); /* can have more than one component */ if (emxinc) { char *beg, *end; beg= (char*)strdup(emxinc); for (;;) { end = (char*)strchr(beg,';'); if (end) *end = 0; if (incp >= includedirs + MAXDIRS) fatalerr("Too many include dirs\n"); *incp++ = beg; if (!end) break; beg = end+1; } } }#else /* !__EMX__, does not use INCLUDEDIR at all */ if (incp >= includedirs + MAXDIRS) fatalerr("Too many -I flags.\n"); *incp++ = INCLUDEDIR;#endif#ifdef POSTINCDIR if (incp >= includedirs + MAXDIRS) fatalerr("Too many -I flags.\n"); *incp++ = POSTINCDIR;#endif } else if (*defincdir) { if (incp >= includedirs + MAXDIRS) fatalerr("Too many -I flags.\n"); *incp++ = defincdir; } redirect(startat, makefile); /* * catch signals. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -