/* Z editor options :ma=1 :ts=6 :bk=0 :wm=0 */ /* This program, both executable and sources, are Copyright 1986, Jay Ts, Box 890 West Oneonta NY 13861. You may copy, distribute, alter, and use them, but absolutely no permission is granted to remove copyright notices from them or distribute them, in whole or in part, as, or as part of, a commercial product. */ /* put copyright notice in executable */ char copyright_notice[] = "\nCopyright 1986, Jay Ts\n"; #include "lc.h" extern int geterrs(); /* CLI command line used in DOS Execute()'s */ char cli[256]; /* option strings for the different phases */ char c1opts[128], c2opts[128], asopts[128]; /* lists of Assembly, C, and object files, and numbers of each */ #define MFIL 32 char afiles[MFIL][32], cfiles[MFIL][32], ofiles[MFIL][32]; int numcfiles = 0, numafiles = 0, numofiles = 0; char pname[64]; /* the name of the output executable program */ char qfile[64]; /* where to put the Lattice ".q" file (default in ram:) */ char errfile[32]; /* the error redirection file - gets filtered by geterrs() */ /* FLAGS */ int saveobj = 0; /* move object files from ram: when done; don't rm */ int printonly = 0; /* just print what is to be done; don't execute */ int linting = 0; /* check for errors only; don't compile/link */ int debugflag = 0; /* compile/link for debugging environment */ int fastlink = 0; /* link with "faster" option */ /* CorOfiles: if only assembling into an object file, and no C compiles or .o files from previous compiles are involved */ int CorOfiles = 1; int errors = 0; /* true if ran into errors */ main(argc,argv) int argc; char *argv[]; { int i, l; if(argc == 1 || argv[1][0] == '?') { Execute("more <* >* lc:src/lc.doc",0L,0L); exit(0); } /* initialize file names ... */ strcpy(errfile,"ram:lcom_errs"); strcpy(qfile,"ram:"); strcpy(pname,""); /* ... and file lists, and options strings */ for(i = 0; i < MFIL; i++) { strcpy(ofiles[i],""); strcpy(cfiles[i],""); strcpy(afiles[i],""); } strcpy(c1opts," -ilc:include/"); strcat(c1opts," -ilc:include/lattice/"); strcpy(c2opts,""); strcpy(asopts,"-i lc:include_asm/ "); /* process command line => options for (LC1 | LC2 | assem) or files (.c | .a | .o) */ for(i = 1; i < argc; i++) { if(argv[i][0] == '-') /* an option */ { switch(argv[i][1]) { case 'A': CorOfiles = 0; break; case 'C': saveobj = 1; break; case 'F': fastlink = 1; break; case 'P': printonly = 1; break; case 'L': linting = 1; break; case 'a': argv[i][1] = argv[i][2]; argv[i][2] = '\0'; strcat(asopts,argv[i]); strcat(asopts," "); strcat(asopts,argv[++i]); strcat(asopts," "); break; case 'b': case 'c': case 'i': case 'l': case 'n': case 'p': case 'u': case 'x': strcat(c1opts," "); strcat(c1opts,argv[i]); break; case 'q': strcpy(qfile, &argv[i][2]); break; case 'f': case 'o': case 'r': case 's': case 'v': strcat(c2opts," "); strcat(c2opts,argv[i]); break; case 'd': strcat(c1opts," "); strcat(c1opts,argv[i]); if(strlen(argv[i]) == 2) { debugflag = 1; strcat(c2opts," "); strcat(c2opts,argv[i]); } break; default: printf("unknown option: \"%s\"\n", argv[i]); exit(1); break; } } else /* a file - set pname if it's the first seen */ { l = strlen(argv[i]); if(argv[i][l-2] == '.') { switch(argv[i][l-1]) { case 'c': if(!numcfiles && !numafiles && !numofiles) { strncpy(pname,argv[i],l-2); pname[l-2] = '\0'; } if(numcfiles == MFIL) toomany(".c"); strncpy(cfiles[numcfiles],argv[i],l-2); cfiles[numcfiles][l-2] = '\0'; numcfiles++; break; case 'a': if(!numcfiles && !numafiles && !numofiles) { strncpy(pname,argv[i],l-2); pname[l-2] = '\0'; } if(numafiles == MFIL) toomany(".a"); strncpy(afiles[numafiles],argv[i],l-2); afiles[numafiles][l-2] = '\0'; numafiles++; break; case 'o': if(!numcfiles && !numafiles && !numofiles) { strncpy(pname,argv[i],l-2); pname[l-2] = '\0'; } if(numofiles == MFIL) toomany(".o"); strcpy(ofiles[numofiles],argv[i]); numofiles++; break; default: printf("not a .[cao] file: \"%s\"\n", argv[i]); exit(1); break; } } else { printf("not a .c or .a or .o file: \"%s\"\n", argv[i]); exit(1); } } } if(!numcfiles && !numafiles && !numofiles) { printf("no files to compile, assemble or link\n"); exit(1); } if(numcfiles == 0 && numofiles == 0) CorOfiles = 0; /* COMPILE */ strcat(c1opts," -o"); strcat(c1opts,qfile); for(i = 0; i < numcfiles; ++i) { /* Do PHASE 1 */ /* build CLI command string */ strcpy(cli,"lc:c/lc1 > "); strcat(cli,errfile); strcat(cli,c1opts); /* add options */ strcat(cli," "); strcat(cli,cfiles[i]); /* add file name */ if(printonly) printf("%s\n",cli); else { Execute(cli,0L,0L); errors = geterrs(errfile, cfiles[i], c1phase, linting); } if(errors || linting) /* lint: just do 1st file & quit */ { strcpy(cli,qfile); strcat(cli,cfiles[i]); strcat(cli,".q"); DeleteFile(cli); if(linting) { if(i == numcfiles-1) exit(0); errors = 0; continue; } else cleanup(10); } /* Do PHASE 2 */ /* build CLI command string */ strcpy(cli,"lc:c/lc2 > "); strcat(cli,errfile); strcat(cli,c2opts); /* add options */ strcat(cli," "); strcat(cli,qfile); /* input is phase 1 output - .q file */ strcat(cli,cfiles[i]); if(printonly) printf("%s\n",cli); else { Execute(cli,0L,0L); errors = geterrs(errfile,cfiles[i],c2phase,linting); } if(errors) cleanup(10); } /* ASSEMBLE */ for(i = 0; i < numafiles; i++) { /* build CLI command string */ strcpy(cli,"lc:c/assem "); strcat(cli,afiles[i]); /* file to assemble - source */ strcat(cli,".a "); strcat(cli,asopts); /* add options */ strcat(cli,"-v "); strcat(cli,errfile); strcat(cli," "); if(debugflag) strcat(cli,"-c S "); if( ! linting) /* want an output file */ { strcat(cli,"-o "); strcat(cli,qfile); strcat(cli,afiles[i]); strcat(cli,".o"); } if(printonly) printf("%s\n",cli); else { Execute(cli,0L,0L); errors = geterrs(errfile,afiles[i],asphase,linting); } if(linting) errors = 0; if(errors) cleanup(10); } if(linting) exit(0); if(saveobj) cleanup(0); /* LINK */ /* build command line */ strcpy(cli,"lc:c/alink > "); strcat(cli,errfile); strcat(cli," "); if(CorOfiles) strcat(cli,"lc:lib/LStartup.obj"); /* build list of .o files from C, Assy and .o files */ for(i = 0; i < numcfiles; i++) { strcat(cli, "+"); strcat(cli, qfile); strcat(cli, cfiles[i]); strcat(cli, ".o"); } for(i = 0; i < numafiles; i++) { if(CorOfiles || i > 0) strcat(cli, "+"); strcat(cli, qfile); strcat(cli, afiles[i]); strcat(cli, ".o"); } for(i = 0; i < numofiles; i++) { strcat(cli, "+"); strcat(cli, ofiles[i]); } strcat(cli, " TO "); strcat(cli, pname); strcat(cli, " LIB "); if(CorOfiles) strcat(cli,"lc:lib/lc.lib+"); strcat(cli,"lc:lib/amiga.lib"); if(debugflag) strcat(cli,"+lc:lib/debug.lib"); if(fastlink) strcat(cli," faster"); if(printonly) printf("%s\n",cli); else { Execute(cli,0L,0L); errors = geterrs(errfile,"link",lkphase,linting); } if(errors) cleanup(10); else cleanup(0); } cleanup(err) int err; { int i; if(err) DeleteFile(pname); if(saveobj) { /* save object files from ram: */ for(i = 0; i < numcfiles; ++i) { strcpy(cli,"copy "); strcat(cli,qfile); strcat(cli,cfiles[i]); strcat(cli,".o "); strcat(cli,cfiles[i]); strcat(cli,".o"); if(printonly) printf("%s\n",cli); else Execute(cli,0L,0L); } for(i = 0; i < numafiles; ++i) { strcpy(cli,"copy "); strcat(cli,qfile); strcat(cli,afiles[i]); strcat(cli,".o "); strcat(cli,afiles[i]); strcat(cli,".o"); if(printonly) printf("%s\n",cli); else Execute(cli,0L,0L); } } /* delete object files in ram: that were made by compile */ for(i = 0; i < numcfiles; i++) { strcpy(cli,qfile); strcat(cli,cfiles[i]); strcat(cli,".o"); if(printonly) printf("delete %s\n",cli); else DeleteFile(cli); } /* delete .o files in ram: made by assembler */ for(i = 0; i < numafiles; i++) { strcpy(cli,qfile); strcat(cli,afiles[i]); strcat(cli,".o"); if(printonly) printf("delete %s\n",cli); else DeleteFile(cli); } exit(err); } toomany(s) char *s; { printf("lc: can't handle more than %d ",MFIL); printf("%s files\n",s); exit(10); }