?? imake.c
字號:
fprintf (inFile, "#define DefaultGccIncludeDir %s\n", buf);}#endifbooleandefine_os_defaults(inFile) FILE *inFile;{#if !defined(WIN32) && !defined(__EMX__)#if (defined(DEFAULT_OS_NAME) || defined(DEFAULT_OS_MAJOR_REV) || \ defined(DEFAULT_OS_MINOR_REV) || defined(DEFAUL_OS_TEENY_REV)) struct utsname name; char buf[SYS_NMLN * 5 + 1]; /* Obtain the system information. */ if (uname(&name) < 0) LogFatal("Cannot invoke uname", "");# ifdef DEFAULT_OS_NAME parse_utsname(&name, DEFAULT_OS_NAME, buf, "Bad DEFAULT_OS_NAME syntax %s");# ifdef DEFAULT_OS_NAME_FROB DEFAULT_OS_NAME_FROB(buf, sizeof buf);# endif if (buf[0] != '\0') fprintf(inFile, "#define DefaultOSName %s\n", buf);# endif# ifdef DEFAULT_OS_MAJOR_REV parse_utsname(&name, DEFAULT_OS_MAJOR_REV, buf, "Bad DEFAULT_OS_MAJOR_REV syntax %s");# ifdef DEFAULT_OS_MAJOR_REV_FROB DEFAULT_OS_MAJOR_REV_FROB(buf, sizeof buf);# endif fprintf(inFile, "#define DefaultOSMajorVersion %s\n", *buf ? trim_version(buf) : "0");# endif# ifdef DEFAULT_OS_MINOR_REV parse_utsname(&name, DEFAULT_OS_MINOR_REV, buf, "Bad DEFAULT_OS_MINOR_REV syntax %s");# ifdef DEFAULT_OS_MINOR_REV_FROB DEFAULT_OS_MINOR_REV_FROB(buf, sizeof buf);# endif fprintf(inFile, "#define DefaultOSMinorVersion %s\n", *buf ? trim_version(buf) : "0");# endif# ifdef DEFAULT_OS_TEENY_REV parse_utsname(&name, DEFAULT_OS_TEENY_REV, buf, "Bad DEFAULT_OS_TEENY_REV syntax %s");# ifdef DEFAULT_OS_TEENY_REV_FROB DEFAULT_OS_TEENY_REV_FROB(buf, sizeof buf);# endif fprintf(inFile, "#define DefaultOSTeenyVersion %s\n", *buf ? trim_version(buf) : "0");# endif# ifdef DEFAULT_MACHINE_ARCHITECTURE parse_utsname(&name, DEFAULT_MACHINE_ARCHITECTURE, buf, "Bad DEFAULT_MACHINE_ARCHITECTURE %s"); fprintf(inFile, "#ifndef %s\n# define %s\n#endif\n", buf, buf);# endif#endif#ifdef linux get_libc_version (inFile); get_ld_version(inFile);#endif get_gcc_incdir(inFile);#endif /* WIN32 */ return FALSE;}voidcppit(imakefile, template, masterc, outfd, outfname) char *imakefile; char *template; char *masterc; FILE *outfd; char *outfname;{ FILE *inFile; haveImakefileC = TRUE; inFile = fopen(masterc, "w"); if (inFile == NULL) LogFatal("Cannot open %s for output.", masterc); if (fprintf(inFile, "%s\n", ImakefileCHeader) < 0 || define_os_defaults(inFile) || optional_include(inFile, "IMAKE_LOCAL_DEFINES", "localdefines") || optional_include(inFile, "IMAKE_ADMIN_DEFINES", "admindefines") || fprintf(inFile, "#define %s <%s>\n", ImakeDefSym, imakefile) < 0 || fprintf(inFile, LocalDefineFmt, ImakeTmplSym, template) < 0 || fprintf(inFile, IncludeFmt, ImakeTmplSym) < 0 || optional_include(inFile, "IMAKE_ADMIN_MACROS", "adminmacros") || optional_include(inFile, "IMAKE_LOCAL_MACROS", "localmacros") || fflush(inFile) || fclose(inFile)) LogFatal("Cannot write to %s.", masterc); /* * Fork and exec cpp */ doit(outfd, cpp, cpp_argv); CleanCppOutput(outfd, outfname);}voidmakeit(){ doit(NULL, make_argv[0], make_argv);}char *CleanCppInput(imakefile) char *imakefile;{ FILE *outFile = NULL; FILE *inFile; char *buf, /* buffer for file content */ *pbuf, /* walking pointer to buf */ *punwritten, /* pointer to unwritten portion of buf */ *ptoken, /* pointer to # token */ *pend, /* pointer to end of # token */ savec; /* temporary character holder */ int count; struct stat st; /* * grab the entire file. */ if (!(inFile = fopen(imakefile, "r"))) LogFatal("Cannot open %s for input.", imakefile); if (fstat(fileno(inFile), &st) < 0) LogFatal("Cannot stat %s for size.", imakefile); buf = Emalloc((int)st.st_size+3); count = fread(buf + 2, 1, st.st_size, inFile); if (count == 0 && st.st_size != 0) LogFatal("Cannot read %s:", imakefile); fclose(inFile); buf[0] = '\n'; buf[1] = '\n'; buf[count + 2] = '\0'; punwritten = pbuf = buf + 2; while (*pbuf) { /* for compatibility, replace make comments for cpp */ if (*pbuf == '#' && pbuf[-1] == '\n' && pbuf[-2] != '\\') { ptoken = pbuf+1; while (*ptoken == ' ' || *ptoken == '\t') ptoken++; pend = ptoken; while (*pend && *pend != ' ' && *pend != '\t' && *pend != '\n') pend++; savec = *pend; *pend = '\0'; if (strcmp(ptoken, "define") && strcmp(ptoken, "if") && strcmp(ptoken, "ifdef") && strcmp(ptoken, "ifndef") && strcmp(ptoken, "include") && strcmp(ptoken, "line") && strcmp(ptoken, "else") && strcmp(ptoken, "elif") && strcmp(ptoken, "endif") && strcmp(ptoken, "error") && strcmp(ptoken, "pragma") && strcmp(ptoken, "undef")) { if (outFile == NULL) { tmpImakefile = Strdup(tmpImakefile); (void) mktemp(tmpImakefile); outFile = fopen(tmpImakefile, "w"); if (outFile == NULL) LogFatal("Cannot open %s for write.", tmpImakefile); } writetmpfile(outFile, punwritten, pbuf-punwritten, tmpImakefile); if (ptoken > pbuf + 1) writetmpfile(outFile, "XCOMM", 5, tmpImakefile); else writetmpfile(outFile, "XCOMM ", 6, tmpImakefile); punwritten = pbuf + 1; } *pend = savec; } pbuf++; } if (outFile) { writetmpfile(outFile, punwritten, pbuf-punwritten, tmpImakefile); fclose(outFile); return tmpImakefile; } return(imakefile);}voidCleanCppOutput(tmpfd, tmpfname) FILE *tmpfd; char *tmpfname;{ char *input; int blankline = 0; while(input = ReadLine(tmpfd, tmpfname)) { if (isempty(input)) { if (blankline++) continue; KludgeResetRule(); } else { blankline = 0; KludgeOutputLine(&input); writetmpfile(tmpfd, input, strlen(input), tmpfname); } writetmpfile(tmpfd, "\n", 1, tmpfname); } fflush(tmpfd);#ifdef NFS_STDOUT_BUG /* * On some systems, NFS seems to leave a large number of nulls at * the end of the file. Ralph Swick says that this kludge makes the * problem go away. */ ftruncate (fileno(tmpfd), (off_t)ftell(tmpfd));#endif}/* * Determine if a line has nothing in it. As a side effect, we trim white * space from the end of the line. Cpp magic cookies are also thrown away. * "XCOMM" token is transformed to "#". */booleanisempty(line) register char *line;{ register char *pend; /* * Check for lines of the form * # n "... * or * # line n "... */ if (*line == '#') { pend = line+1; if (*pend == ' ') pend++; if (*pend == 'l' && pend[1] == 'i' && pend[2] == 'n' && pend[3] == 'e' && pend[4] == ' ') pend += 5; if (isdigit(*pend)) { do { pend++; } while (isdigit(*pend)); if (*pend == '\n' || *pend == '\0') return(TRUE); if (*pend++ == ' ' && *pend == '"') return(TRUE); } while (*pend) pend++; } else { for (pend = line; *pend; pend++) { if (*pend == 'X' && pend[1] == 'C' && pend[2] == 'O' && pend[3] == 'M' && pend[4] == 'M' && (pend == line || pend[-1] == ' ' || pend[-1] == '\t') && (pend[5] == ' ' || pend[5] == '\t' || pend[5] == '\0')) { *pend = '#'; strcpy(pend+1, pend+5); }#ifdef MAGIC_MAKE_VARS if (*pend == 'X' && pend[1] == 'V' && pend[2] == 'A' && pend[3] == 'R') { char varbuf[5]; int i; if (pend[4] == 'd' && pend[5] == 'e' && pend[6] == 'f' && pend[7] >= '0' && pend[7] <= '9') { i = pend[7] - '0'; sprintf(varbuf, "%0.4d", xvariable); strncpy(pend+4, varbuf, 4); xvariables[i] = xvariable; xvariable = (xvariable + 1) % 10000; } else if (pend[4] == 'u' && pend[5] == 's' && pend[6] == 'e' && pend[7] >= '0' && pend[7] <= '9') { i = pend[7] - '0'; sprintf(varbuf, "%0.4d", xvariables[i]); strncpy(pend+4, varbuf, 4); } }#endif } } while (--pend >= line && (*pend == ' ' || *pend == '\t')) ; pend[1] = '\0'; return (*line == '\0');}/*ARGSUSED*/char *ReadLine(tmpfd, tmpfname) FILE *tmpfd; char *tmpfname;{ static boolean initialized = FALSE; static char *buf, *pline, *end; register char *p1, *p2; if (! initialized) {#ifdef WIN32 FILE *fp = tmpfd;#endif int total_red; struct stat st; /* * Slurp it all up. */ fseek(tmpfd, 0, 0); if (fstat(fileno(tmpfd), &st) < 0) LogFatal("cannot stat %s for size", tmpMakefile); pline = buf = Emalloc((int)st.st_size+1); total_red = fread(buf, 1, st.st_size, tmpfd); if (total_red == 0 && st.st_size != 0) LogFatal("cannot read %s", tmpMakefile); end = buf + total_red; *end = '\0'; fseek(tmpfd, 0, 0);#if defined(SYSV) || defined(WIN32) || defined(USE_FREOPEN) tmpfd = freopen(tmpfname, "w+", tmpfd);#ifdef WIN32 if (! tmpfd) /* if failed try again */ tmpfd = freopen(tmpfname, "w+", fp);#endif if (! tmpfd) LogFatal("cannot reopen %s\n", tmpfname);#else /* !SYSV */ ftruncate(fileno(tmpfd), (off_t) 0);#endif /* !SYSV */ initialized = TRUE; fprintf (tmpfd, "# Makefile generated by imake - do not edit!\n"); fprintf (tmpfd, "# %s\n", "$TOG: imake.c /main/97 1997/06/20 20:23:51 kaleb $"); } for (p1 = pline; p1 < end; p1++) { if (*p1 == '@' && *(p1+1) == '@' /* ignore ClearCase version-extended pathnames */ && !(p1 != pline && !isspace(*(p1-1)) && *(p1+2) == '/')) { /* soft EOL */ *p1++ = '\0'; p1++; /* skip over second @ */ break; } else if (*p1 == '\n') { /* real EOL */#ifdef WIN32 if (p1 > pline && p1[-1] == '\r') p1[-1] = '\0';#endif *p1++ = '\0'; break; } } /* * return NULL at the end of the file. */ p2 = (pline == p1 ? NULL : pline); pline = p1; return(p2);}voidwritetmpfile(fd, buf, cnt, fname) FILE *fd; int cnt; char *buf; char *fname;{ if (fwrite(buf, sizeof(char), cnt, fd) == -1) LogFatal("Cannot write to %s.", fname);}char *Emalloc(size) int size;{ char *p; if ((p = malloc(size)) == NULL) LogFatalI("Cannot allocate %d bytes", size); return(p);}#ifdef FIXUP_CPP_WHITESPACEvoidKludgeOutputLine(pline) char **pline;{ char *p = *pline; char quotechar = '\0'; switch (*p) { case '#': /*Comment - ignore*/ break; case '\t': /*Already tabbed - ignore it*/ break; case ' ': /*May need a tab*/ default:# ifdef INLINE_SYNTAX if (*p == '<' && p[1] == '<') { /* inline file close */ InInline--; InRule = TRUE; break; }# endif /* * The following cases should not be treated as beginning of * rules: * variable := name (GNU make) * variable = .*:.* (':' should be allowed as value) * sed 's:/a:/b:' (: used in quoted values) */ for (; *p; p++) { if (quotechar) { if (quotechar == '\\' || (*p == quotechar &&# ifdef WIN32 quotechar != ')' &&# endif p[-1] != '\\')) quotechar = '\0'; continue; } switch (*p) { case '\\': case '"': case '\'': quotechar = *p; break; case '(': quotechar = ')'; break; case '{': quotechar = '}'; break; case '[': quotechar = ']'; break; case '=':# ifdef REMOVE_CPP_LEADSPACE if (!InRule && **pline == ' ') { while (**pline == ' ') (*pline)++; }# endif goto breakfor;# ifdef INLINE_SYNTAX case '<': if (p[1] == '<') /* inline file start */ InInline++; break;# endif case ':': if (p[1] == '=') goto breakfor; while (**pline == ' ') (*pline)++; InRule = TRUE; return; } }breakfor: if (InRule && **pline == ' ') **pline = '\t'; break; }}voidKludgeResetRule(){ InRule = FALSE;}#endif /* FIXUP_CPP_WHITESPACE */char *Strdup(cp) register char *cp;{ register char *new = Emalloc(strlen(cp) + 1); strcpy(new, cp); return new;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -