📄 cc.c
字号:
#ifndef lintstatic char *sccsid = "@(#)cc.c 4.2 (ULTRIX) 11/9/90";#endif/* * cc - front end for C compiler */#include <sys/param.h>#include <stdio.h>#include <ctype.h>#include <signal.h>#include <sys/dir.h>/************************************************************************ * * * Copyright (c) 1984, 1987, 1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//************************************************************************ * Modification History * * * * Jim McHale, 22-Oct-90; added -bswitch to gen heap switches (seperate * cmp/jbr instead of casel); fixes cld 153/qar 6081. * * Jim McHale, 15-Oct-90; added -v. * * Lee Miller, 19-Sep-1990 for qar 5752 * * 015 create Jflag so that the -J option for the assembler can be passed * * in from the cc command line. * * * * Jon Reeves, 9-May-1989 for Sid Maxwell * * 014 On cpp error, continue to compile (not just preprocess). * * Code from 4.3-Tahoe. * * * * Mark Parenti, 8-Jun-1988 * * 013 Change signal handlers to void. * * * * Jon Reeves, 7-Dec-1987 * * 012 Integrate BSD4.3 features: clean up on SIGHUP, pass -L through * * to linker * * * * Jon Reeves, 23-Nov-1987 * * 011 Expanded definition of -Y option to -YSYSTEM_FIVE, -YBSD, or * * -YPOSIX. Major changes to 007. * * * * Lu Anne Van de Pas, 20-Jun-1986 * * 010 Added check to see if multiple files were specified with the -Em* * switch, if so don't output "filename:". * * * * Lu Anne Van de Pas, 21-Jan-1986 * * 009 Added -f flag so we do do single precision arithmetic in single * * precision instead of promoting it to double. * * * * David L Ballenger, 7-Jun-1985 * * 008 Check PROG_ENV environment variable instead of SYSTYPE, for * * System V environment. Also select appropriate math library * * when using System V environment. * * * * David L. Ballenger, 31-Mar-1985 * * 007- Add System V environment support. * * Also add handling for alternate assembler and loader to -t * * switch, ie. -t[alp012]. * * * * David L. Ballenger, 7-Nov-1984 * * 006- Allow the -M flag to be passed to the loader. * * * * 005- David L Ballenger, 23-Aug-1984 * * If the -Mg flag is specified, use -lcg instead of -lc as the * * library argument to ld. This causes the loader to use the * * GFLOAT version of libc. * * * * Rich Phillips, 01-Aug-84 * * 004- Issue a warning when -o is used with -S or -c, since the loader * * will not be called in either case. * * * * Stephen Reilly, 16-Apr-84 * * 003- Changed the symbol MVAXI to GFLOAT * * * * Stephen Reilly, 04-Apr-84 * * 002- Changed the symbol MicroVAX to MVAXI. Also added new flag "-b" * * when specified will not pass -lc to the loader. * * * * Stephen Reilly, 21-Oct-83: * * 001- Add code for the -Mx flag. This flag indicates that gfloat * * instructions are to be emited instead of dfloat instructions * * * ************************************************************************/char *cpp = "/lib/cpp";char *ccom = "/lib/ccom";char *c2 = "/lib/c2";char *as = "/bin/as";char *ld = "/bin/ld";char *crt0 = "/lib/crt0.o";char tmp0[30]; /* big enough for /tmp/ctm%05.5d */char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5;char *outfile;char *savestr(), *strspl(), *setsuf();void idexit();char **av, **clist, **llist, **plist;int cflag, eflag, oflag, pflag, sflag, wflag, Rflag, exflag, proflag;int gflag, Gflag;int vflag = 0; /* jpm */int Jflag = 0; /*lrm015*/int bswitch = 0; /* jpm: fix cld 153 */int fflag = 0; /* do single precision arithmetic lvp009*/ int bflag; /* slr002 Don't pass -lc to loader */int makedepend = 0; /* vdp010 don't print file names if -Em*/# ifdef GFLOAT /* slr003 changed from MVAXI to GFLOAT */int Mflag = 1; /* slr001 default for MicroVAX is gfloat */# elseint Mflag; /* slr001 default for VAX is dfloat */# endifint Yflag; /* jlr011 Set if -Y was given */char *dflag;int exfail;char *chpass;char *npassname;enum run_mode {bsd, sys_v, posix} mode = bsd; /* jlr011 Desired run mode */ /* assume bsd for compatibility */int nc, nl, np, nxo, na;#define cunlink(s) if (s) unlink(s)main(argc, argv) char **argv;{ char *t; char *assource; int i, j, c; char *penv, *getenv(); /* ld currently adds upto 5 args; 10 is room to spare */ av = (char **)calloc(argc+10, sizeof (char **)); clist = (char **)calloc(argc, sizeof (char **)); llist = (char **)calloc(argc, sizeof (char **)); plist = (char **)calloc(argc, sizeof (char **)); /* * Check the PROG_ENV environment variable to see what environment * we should use. (jlr011) */ if ( strcmp("SYSTEM_FIVE", penv = getenv("PROG_ENV")) == 0) mode = sys_v; else if ( strcmp("POSIX", penv) == 0) mode = posix; else if ( strcmp("BSD", penv) == 0) mode = bsd; for (i = 1; i < argc; i++) { if (*argv[i] == '-') switch (argv[i][1]) { case 'S': sflag++; cflag++; continue; case 'o': if (++i < argc) { outfile = argv[i]; switch (getsuf(outfile)) { case 'c': case 'o': error("-o would overwrite %s", outfile); exit(8); } } continue; /* * When -Mx flag is set it indicates that user wants * to override default. If x is not either g or d * then stay with default */ case 'M': /* slr001 */ /* * See what the argument after the -M is */ switch ( argv[i][2] ) { case 'g': /* slr001 if g then gfloat */ /* * Set flag indicating gfloat for * MicroVAX and define MVAXI for * cpp. */ Mflag = 1; /* slr001 */ plist[np++] = "-DGFLOAT"; /* slr003 */ continue; case 'd': /* slr001 if d then dfloat */ Mflag = 0; /* slr001 set flag for dfloat */ continue; } /* If the flag wasn't -Md or -Mg then break so * the -M flag can be passed on to the loader. */ break; /* DLB006 */ case 'b': /* '-b' alone dictates that the user does not want * the -lc flag passed to the loader. * * -bswitch says to never generate casel instructions. */ if (argv[i][2] == '\0') /* if just -b */ { bflag++; /* slr002 */ } else if (strcmp( "bswitch", &argv[i][1] ) == 0) /* jpm: cld 153 */ { bswitch++; } continue; case 'f': fflag++; /*vdp009*/ continue; case 'J': /*lrm015*/ Jflag++; continue; case 'R': Rflag++; continue; case 'O': oflag++; continue; case 'p': proflag++; crt0 = "/lib/mcrt0.o"; if (argv[i][2] == 'g') crt0 = "/usr/lib/gcrt0.o"; continue; case 'g': if (argv[i][2] == 'o') { Gflag++; /* old format for -go */ } else { gflag++; /* new format for -g */ } continue; case 'v': ++vflag; continue; case 'w': wflag++; continue; case 'E': exflag++; if (argv[i][2] == 'm') makedepend++; case 'P': pflag++; if (argv[i][1]=='P') fprintf(stderr, "cc: warning: -P option obsolete; you should use -E instead\n"); plist[np++] = argv[i]; case 'c': cflag++; continue; case 'D': case 'I': case 'U': case 'C': plist[np++] = argv[i]; continue; case 'L': llist[nl++] = argv[i]; continue; case 't': if (chpass) error("-t overwrites earlier option", 0); chpass = argv[i]+2; if (chpass[0]==0) chpass = "012p"; continue; case 'B': if (npassname) error("-B overwrites earlier option", 0); npassname = argv[i]+2; if (npassname[0]==0) npassname = "/usr/c/o"; continue; case 'd': dflag = argv[i]; continue; case 'Y': if (argv[i][2] == '\0') { mode = sys_v; /* For pre-V2.4 compatibility */ Yflag++; } else if (strcmp("SYSTEM_FIVE", &argv[i][2]) == 0) { mode = sys_v; Yflag++; } else if (strcmp("POSIX", &argv[i][2]) == 0) { mode = posix; Yflag++; } else if (strcmp("BSD", &argv[i][2]) == 0) { mode = bsd; Yflag++; } else (void) fprintf(stderr, "cc: warning: bad -Y argument %s ignored\n", &argv[i][2]); continue; } t = argv[i]; c = getsuf(t); if (c=='c' || c=='s' || exflag) { clist[nc++] = t; t = setsuf(t, 'o'); } if (nodup(llist, t)) { if (mode == sys_v) { /* Select System V math library, if * math library is being used. */ if (strcmp(t,"-lm") == 0) llist[nl++] = "-lmV"; else if (strcmp(t,"-lmg") == 0) llist[nl++] = "-lmVg" ; else if (strcmp(t,"-lm_p") == 0) llist[nl++] = "-lmV_p" ; else llist[nl++] = t; } else llist[nl++] = t; if (getsuf(t)=='o') nxo++; } } switch (mode) { case sys_v: plist[np++] = "-DSYSTEM_FIVE" ; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -