1: #ifndef lint
   2: static char *rcsid = "$Header: liszt.c 1.6 83/07/25 12:07:31 layer Exp $";
   3: #endif
   4: 
   5: /*
   6: **			-[Wed May  4 18:18:10 1983 by layer]-
   7: **
   8: **
   9: ** liszt :: interface to the lisp compiler
  10: **
  11: ** There are two reasons for having a C interface to the compiler:
  12: **	1) Fseek doesn't work properly from lisp, and there is no
  13: **	   lseek.
  14: **	2) To start up a process from a 1 Mb process, like when liszt forks
  15: **	   a /usr/lib/lisp/as to assemble the output of the compiler, takes
  16: **	   too long. (The compiler is 100 times larger than this program.)
  17: **
  18: **/
  19: 
  20: #include    <stdio.h>
  21: #include    "../../franz/h/aout.h"
  22: #include    "../../franz/h/config.h"
  23: 
  24: #ifndef LISZT
  25: #define LISZT   "/usr/ucb/xliszt"
  26: #endif
  27: 
  28: #ifndef AS
  29: #define AS  "/usr/lib/lisp/as"
  30: #endif
  31: 
  32: #ifndef OFFSET
  33: #define OFFSET      0x0
  34: #endif
  35: 
  36: main(argc,argv,envp)
  37:     register char *argv[], **envp;
  38: {
  39:     struct exec header;
  40:     register int autorun = 0;
  41:     register int no_assem = 0;
  42:     register char *p;
  43:     register int oflag = 0, cur;
  44:     register int objp;
  45:     register int slen;
  46:     char temp[20], tempfile[20], srcfile[20], outfile[20];
  47:     char *args_to_string();
  48:     char *flags_to_string();
  49:     char command[1024];
  50: 
  51:     /*
  52: 	**  process arguments :: check for -r and -S switches
  53: 	**
  54: 	**  -F is a special flag that means just to fix the offset in the
  55: 	** object file, and then quit.
  56: 	**
  57: 	**/
  58:     /* If no args, then give the user an interactive liszt */
  59:         if (argc == 1)
  60:     {
  61:         execle(LISZT, "liszt", 0, envp);
  62:         exit(100);
  63:     } else
  64:     {
  65:         for (cur = 1; cur < argc; cur++) {
  66:             if (*argv[cur] == '-')
  67:             {
  68:                 p = argv[cur];
  69:                 p++;
  70:                 if (*p == 'o')
  71:                 {
  72:                         strcpy(outfile,argv[++cur]);
  73:                         oflag++;
  74:                 }
  75:                 else if (*p == 'F')
  76:                 {
  77:                     strcpy(outfile,argv[++cur]);
  78:                     autorun = 1;
  79:                     goto fixit;
  80:                 }
  81:                 else
  82:                 {
  83:                         for (; *p; p++) {
  84:                         switch (*p)
  85:                         {
  86:                             case 'S':
  87:                                 no_assem++;
  88:                                 break;
  89:                             case 'r':
  90:                                 autorun++;
  91:                                 break;
  92:                             default:
  93:                                 break;
  94:                         }
  95:                         }
  96:                 }
  97:                 }
  98:             else
  99:             {   /* must be filename */
 100:                     strcpy(srcfile, argv[cur]);
 101:                 }
 102:             }
 103:         }
 104: 
 105:     if (no_assem)
 106:     {
 107:             sprintf(command, "%s %s", LISZT, args_to_string(argv));
 108: #ifdef debug
 109:             printf("%s\n", command);
 110: #else
 111:         exit(system(command));
 112: #endif
 113:     }
 114: 
 115:     sprintf(tempfile, "/tmp/Lzt%d.s", getpid());
 116: 
 117:     /* If output file not given, then we deduce it... */
 118:     if (oflag == 0)
 119:     {
 120:         strcpy(outfile,srcfile);
 121:         slen = strlen(outfile);
 122:         if (outfile[slen - 2] == '.')
 123:         {
 124:             outfile[slen - 1] = 'o';
 125:         }
 126:         else
 127:         {
 128:             strcpy(temp,outfile);
 129:             sprintf(outfile, "%s.o", temp);
 130:         }
 131:     }
 132: 
 133:     sprintf(command, "%s -S%s -o %s %s",
 134:              LISZT, flags_to_string(argc, argv), tempfile, srcfile);
 135: #ifdef debug
 136:     printf("%s\n", command);
 137: #else
 138:         if (system(command) != 0)
 139:     {
 140:         exit(101);
 141:         }
 142: #endif
 143: 
 144:     sprintf(command, "%s -o %s %s", AS, outfile, tempfile);
 145: #ifdef debug
 146:     printf("%s\n", command);
 147: #else
 148:     if (system(command) != 0)
 149:     {
 150:         exit(102);
 151:     }
 152:     unlink(tempfile);
 153: 
 154: fixit:
 155:         if (autorun)
 156:     {
 157:         if ((objp = open(outfile,2)) == -1)
 158:         {
 159:                 perror(outfile);
 160:                 exit(103);
 161:         }
 162:         if (read(objp,&header,sizeof header) != sizeof (struct exec))
 163:         {
 164:             perror("read failed");
 165:             exit(1);
 166:         }
 167: 
 168:         /* Change the offset to the correct value */
 169:         header.a_entry = OFFSET;
 170: 
 171:         /* seek back to beginning */
 172:         if (lseek(objp,0,0) != 0)
 173:         {
 174:                 perror("seek failed");
 175:                 exit(104);
 176:         }
 177: 
 178:         /* write the new a.out header... */
 179:         if (write(objp,&header,sizeof header) != sizeof(struct exec))
 180:         {
 181:                 perror("write failed");
 182:                 exit(105);
 183:         }
 184: 
 185:         /* make it executable */
 186:         chmod(outfile, 0755);
 187:         } else
 188:         exit(0);
 189: #endif
 190: }
 191: 
 192: char *
 193: args_to_string(pp)
 194:     char *pp[];
 195: {
 196:         char result[1024];
 197:         register int ii = 0,
 198:              jj = 1;
 199: 
 200:         for (; pp[jj]; ii++, jj++)
 201:     {
 202:         xstrcpy(&result[ii],pp[jj]);
 203:         ii = ii + strlen(pp[jj]);
 204:         }
 205:         result[ii++] = '\0';
 206:         return(result);
 207: }
 208: 
 209: char *
 210: flags_to_string(argc, argv)
 211:     int argc;
 212:     char *argv[];
 213: {
 214:         char result[128];
 215:         register int chari, word, skipnext = 0, out = 0;
 216: 
 217:     for (word = 1; word < argc; word++)
 218:     {
 219:         if (skipnext)
 220:         {
 221:             skipnext = 0;
 222:             word++;
 223:             continue;
 224:         }
 225:         if (*argv[word] == '-')
 226:             for (chari = 1; argv[word][chari]; chari++)
 227:                 if (argv[word][chari] == 'o')
 228:                     skipnext = 1;
 229:                 else
 230:                     result[out++] = argv[word][chari];
 231:     }
 232:         result[out] = '\0';
 233:         return(result);
 234: }
 235: 
 236: xstrcpy(s, t)
 237:     char *s, *t;
 238: {
 239:         while (*t != '\0')
 240:     {
 241:             *s++ = *t++;
 242:         }
 243:         *s = ' ';
 244: }

Defined functions

args_to_string defined in line 192; used 2 times
flags_to_string defined in line 209; used 2 times
main defined in line 36; never used
xstrcpy defined in line 236; used 1 times

Defined variables

rcsid defined in line 2; never used

Defined macros

AS defined in line 29; used 2 times
LISZT defined in line 25; used 4 times
OFFSET defined in line 33; used 2 times
Last modified: 1985-08-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1031
Valid CSS Valid XHTML 1.0 Strict