📄 lcc.c
字号:
*p++ = "-q";
*p++ = assem;
*p = NULL;
xcallv("r86", rargv);
delete(assem);
}
char *find_file(char *buf, char *file)
{
int fd;
char *p, *d;
fd = -1;
strcpy(buf, file);
if ((fd = open(buf, 0)) < 0 && (p = getenv("PATH")) != NULL) {
while (*p) {
d = buf;
while (*p && *p != ';')
*d++ = *p++;
*d = '\0';
strcat(addsl(buf), file);
if ((fd = open(buf, 0)) >= 0)
break;
if (*p == ';')
p++;
}
}
if (fd < 0)
return (NULL);
close(fd);
return (buf);
}
void invoke_link()
{
FILE *fp;
char **p;
/* generate link command */
*pld = NULL;
fp = efopen("link.i", "w");
if (!Mslink) {
for (p = ldargv + 1; *p; p++) {
if ((*p)[0] == '-' && (*p)[1] == 'l')
fprintf(fp, "-l%c/%s ", MemModel, *p + 2);
else
fprintf(fp, "%s ", *p);
}
putc('\n', fp);
fclose(fp);
xcall("lld", "lld", "@link.i", NULL);
} else {
char *s;
char libdir[100];
bool first, map;
if (out[0] == '\0')
*suffix(strcpy(out, firstsrc)) = '\0';
map = Gflag;
if (Gflag)
fputs("/li", fp);
for (p = msopt; p < pmsop; p++)
fprintf(fp, "%s", *p);
fputs("/noi ", fp);
libdir[0] = '\0';
for (p = ldargv; *p; p++) {
if ((*p)[0] == '-' && (*p)[1] == 'L') {
addsl(strcpy(libdir, *p + 2));
s = libdir + strlen(libdir);
*s++ = MemModel;
*s++ = '\\';
*s = '\0';
}
}
first = YES;
for (p = ldargv; *p; p++) {
if ((*p)[0] == '-' && (*p)[1] == 'M')
map = YES;
else if (strcmpc(suffix(*p), ".obj") == 0) {
if ((*p)[0] == '-' && (*p)[1] == 'l')
strcat(strcpy(w, libdir), *p + 2);
else
strcpy(w, *p);
if (!first)
fprintf(fp, "+\n");
first = NO;
fprintf(fp, "%s", tobacksl(w));
}
}
fprintf(fp, "\n%s\n", tobacksl(out));
if (map) {
*suffix(out) = '\0';
fprintf(fp, "%s/map", out);
}
putc('\n', fp);
first = YES;
for (p = ldargv; *p; p++) {
if ((*p)[0] == '-' && (*p)[1] == 'l'
&& strcmpc(suffix(*p), ".obj") != 0)
strcat(strcpy(w, libdir), *p + 2);
else if (strcmpc(suffix(*p), ".lib") == 0)
strcpy(w, *p);
else
continue;
if (!first)
fprintf(fp, "+\n");
first = NO;
fprintf(fp, "%s", tobacksl(w));
}
fprintf(fp, ";\n");
fclose(fp);
xcall("link", "link", "@link.i", NULL);
}
if (State == 0 && no == 1 && strcmpc(suffix(firstsrc), ".obj") != 0)
delete(replace_suffix(w, firstsrc, ".obj"));
delete("link.i");
}
void warn_obsolete_option(char *s)
{
char newopt;
switch (s[1]) {
case 'A':
case 'C':
case 'd':
case 'G':
case 'H':
case 'i':
case 'J':
case 'K':
case 'M':
case 'N':
case 's':
case 't':
case 'V':
case 'W':
case 'x':
case 'Y':
newopt = s[1] ^ ('a' ^ 'A');
goto alternate;
case 'B':
case 'b':
newopt = 'L';
alternate:
fprintf(stderr, "%s: Warning: Option %s is obsolete; use -%c\n",
Program, s, newopt);
s[1] = newopt;
break;
case 'Q':
case 'q':
fprintf(stderr, "%s: Option -q is obsolete; use -O0\n",
Program);
xexit(1);
}
}
int main(int argc, char *argv[])
{
char *s;
char **xp, **p;
static char *xargv[1000];
argv++;
if (argv[0] == NULL) {
version();
usage();
xexit(1);
}
xp = xargv;
*xp = NULL;
if (strcmp(argv[0], "-noconf") == 0)
argv++;
else if (find_file(w, "_lcc"))
xp = addoptf(xp, w, &argv);
for (; *argv != NULL; argv++) {
if (**argv == '@')
xp = addoptf(xp, *argv + 1, NULL);
else
*xp++ = *argv;
}
*xp = NULL;
/* initialize options */
no = 0;
*pcpp++ = "cpp";
*pcf++ = "cf";
*pcg++ = "cg86";
*pr++ = "r86";
*pld++ = "lld";
#ifdef CPM
*pld++ = "-lccpm.obj";
#else
*pld++ = "-lcdos.obj";
#endif
out[0] = '\0';
for (xp = xargv; (s = *xp++) != NULL; ) {
if (strcmp(s, "-mslink") == 0)
Mslink = YES;
else if (strcmp(s, "-nomslink") == 0)
Mslink = NO;
else if (*s == '-') {
/* do options */
warn_obsolete_option(s);
switch (s[1]) {
case 'z':
Nonexec = YES;
break;
case 'n':
*pcf++ = s;
break;
case 'c':
switch (s[2]) {
case '\0':
Cflag = YES;
break;
case 'n':
case 'N':
CommentNest = YES;
break;
default:
*pcf++ = s;
}
break;
case 'S':
switch (s[2]) {
case 'T':
STflag = YES;
break;
case 'C':
SCflag = YES;
break;
case '\0':
break;
default:
goto badopt;
}
Sflag = YES;
Cflag = YES;
break;
case 'v':
switch (s[2]) {
case '0':
case '1':
case '2':
Verilev = s[2] - '0';
break;
default:
Verilev = 1;
}
break;
case 'w':
switch (s[2]) {
case '0':
case '1':
case '2':
Warnlev = s[2] - '0';
break;
case 'i':
ImplicitInt = YES;
break;
case 'x':
ImplicitInt = NO;
break;
default:
Warnlev = 0;
}
break;
case 'j':
Jap = s[2] - '0';
break;
case 'o':
*pld++ = s;
if (s[2] == '\0' && *xp != NULL) {
strcpy(out, *xp);
*pld++ = *xp++;
} else
strcpy(out, s + 2);
break;
case 'k':
if (s[2] == '\0' && *xp != NULL) {
if (Mslink)
*pmsop++ = *xp++;
else
*pld++ = *xp++;
} else {
if (Mslink)
*pmsop++ = s + 2;
else
*pld++ = s + 2;
}
break;
case 'X':
Exec_dir = s + 2;
break;
case 'T':
Temp_dir = s + 2;
break;
case 'g':
Gflag = YES;
/* fall thru */
case 'l':
case 'L':
*pld++ = s;
break;
case 'y':
*pcf++ = s;
/* fall thru */
case 'I':
case 'D':
*pcpp++ = s;
break;
case 'h':
*pcg++ = "-s";
break;
case 'm':
if (s[2] == 'a' || s[2] == '\0') {
*pld++ = "-M";
} else {
#ifdef SMALLONLY
goto badopt;
#else
*pcf++ = s;
*pcg++ = s;
MemModel = s[2];
switch (MemModel) {
case 'd':
case 'l':
*pcpp++ = "-D_D_FAR";
if (s[2] == 'd')
break;
/* fall thru */
case 'p':
*pcpp++ = "-D_P_FAR";
break;
case 's':
break;
default:
goto badopt;
}
#endif
}
break;
case 'O':
if (s[2])
Olevel = s[2] - '0';
else
Olevel = 1;
break;
case 'a':
if (s[2])
ldargv[1] = strsave(strcat(strcpy(w, "-l"), s + 2));
else
ldargv[1] = "";
break;
case 'p':
ldargv[1] = "-lcpro.obj";
Pflag = YES;
break;
default:
badopt:
fprintf(stderr, "%s: Bad option: %s\n",
Program, s);
usage();
xexit(1);
}
} else if (strcmpc(suffix(s), ".lib") == 0) {
/* add a library file */
*pld++ = s;
} else {
*pld++ = strsave(replace_suffix(w, s, ".obj"));
if (no == 0)
firstsrc = s;
no++;
/* check file type */
if (strcmpc(suffix(s), ".c") == 0 || *suffix(s) == 0) {
compile_c(s);
} else if (strcmpc(suffix(s), ".p86") == 0
|| strcmpc(suffix(s), ".a86") == 0) {
if (Sflag)
continue;
/* generate cpp, r86 command */
p = pcpp;
*p++ = "-o";
*p++ = strcat(addsl(strcpy(temp1, Temp_dir)), "1.$$$");
*p++ = s;
*p++ = NULL;
if (xcallv("cpp", cppargv) == 0) {
p = pr;
*p++ = "-o";
*p++ = objname(s);
*p++ = "-m";
*p++ = s;
if (Olevel == 0)
*p++ = "-q";
*p++ = temp1;
*p = NULL;
xcallv("r86", rargv);
}
delete(temp1);
#if 0
} else if (strcmpc(suffix(s), ".a86") == 0) {
if (Sflag)
continue;
/* generate r86 command */
p = pr;
*p++ = "-o";
*p++ = objname(s);
*p++ = "-m";
*p++ = s;
if (Olevel == 0)
*p++ = "-q";
*p++ = s;
*p++ = NULL;
xcallv("r86", rargv);
#endif
} else if (strcmpc(suffix(s), ".asm") == 0) {
if (Sflag)
continue;
/* generate masm command */
strcat(strcat(strcat(strcpy(w, s), ","), objname(s)), ";");
xcall("masm", "masm", "/mx", w, NULL);
} else if (strcmpc(suffix(s), ".obj") == 0) {
/* do nothing */
} else {
/* unknown file; error */
fprintf(stderr, "%s: can't handle: %s\n", Program, s);
xexit(1);
}
}
}
if (no <= 0) {
fprintf(stderr, "%s: no sourcefile\n", Program);
xexit(1);
}
if (State == 0 && !Cflag)
invoke_link();
xexit(State);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -