1: #include <stdio.h>
   2: #include "../h/config.h"
   3: #define BIN IntBin
   4: #define ICONX Iconx
   5: #define MAXARGS 20
   6: #define PATHSIZE 100    /* maximum length of a fully qualified file name */
   7: #ifndef ITRAN
   8: #define ITRAN "%s/itran"
   9: #endif
  10: #ifndef ILINK
  11: #define ILINK "%s/ilink"
  12: #endif
  13: extern char **environ;
  14: char **rfiles;
  15: main(argc,argv)
  16: int argc; char **argv;
  17:    {
  18:    char **tfiles;
  19:    char **lfiles;
  20:    char **execlist;
  21:    char *tflags[MAXARGS];
  22:    char *lflags[MAXARGS];
  23:    char **xargs;
  24:    int ntf, nlf, nrf, ntflags, nlflags, cflag, quiet;
  25:    char **arg;
  26:    char *base, *getbase();
  27:    char *u1, *u2, *xfile;
  28:    char *rindex(), *mkname();
  29:    char cmd[PATHSIZE];
  30: 
  31:    ntf = nlf = nrf = ntflags = nlflags = cflag = quiet = 0;
  32:    rfiles = (char **)calloc(2*(argc+10), sizeof(char **));
  33:    tfiles = (char **)calloc(argc+10, sizeof(char **));
  34:    lfiles = (char **)calloc(argc+10, sizeof(char **));
  35:    execlist = (char **)calloc(2*(argc+10), sizeof(char **));
  36: 
  37:    tflags[ntflags++] = "itran";
  38:    lflags[nlflags++] = "ilink";
  39:    lflags[nlflags++] = "-i";
  40:    lflags[nlflags++] = ICONX;
  41:    rfiles[nrf++] = "rm";
  42:    rfiles[nrf++] = "-f";
  43:    xfile = "";
  44: 
  45:    for (arg = &argv[1]; arg <= &argv[argc-1]; arg++) {
  46:       if ((*arg)[0] == '-') switch ((*arg)[1]) {
  47:          case '\0': /* "-" */
  48:             tfiles[ntf++] = *arg;
  49:             lfiles[nlf++] = rfiles[nrf++]
  50:               = "stdin.u1";
  51:             rfiles[nrf++] = "stdin.u2";
  52:             break;
  53:          case 's':
  54:             tflags[ntflags++] = "-s";
  55:             quiet++;
  56:             break;
  57:          case 'o':
  58:             lfiles[nlf++] = "-o";
  59:             xfile = lfiles[nlf++] = *++arg;
  60:             break;
  61:          case 'x':
  62:             xargs = arg++;
  63:             goto argsdone;
  64:          case 'c':
  65:             cflag++;
  66:             break;
  67:          default:
  68:             lflags[nlflags++] = tflags[ntflags++] = *arg;
  69:             break;
  70:             }
  71:       else if (suffix(*arg,".icn")) {
  72:          tfiles[ntf++] = *arg;
  73:          base = getbase(*arg,".icn");
  74:          u1 = mkname(base,".u1");
  75:          u2 = mkname(base,".u2");
  76:          lfiles[nlf++] = rfiles[nrf++] = u1;
  77:          rfiles[nrf++] = u2;
  78:          }
  79:       else if (suffix(*arg,".u1")) {
  80:          lfiles[nlf++] = *arg;
  81:          }
  82:       else {
  83:          fprintf(stderr,"%s: bad argument '%s'\n",argv[0],*arg);
  84:          exit(1);
  85:          }
  86:       }
  87: argsdone:
  88:    if (nlf == 0)
  89:       usage(argv[0]);
  90:    if (!xfile[0])
  91:       xfile = getbase(lfiles[0],".u1");
  92: 
  93:    if (ntf != 0) {
  94:       lcat(execlist,tflags,tfiles);
  95:       sprintf(cmd,ITRAN,BIN);
  96:       runit(cmd,execlist,environ);
  97:       }
  98:    if (cflag) {
  99:       exit(0);
 100:       }
 101:    if (!quiet)
 102:       fprintf(stderr,"Linking:\n");
 103:    execlist[0] = 0;
 104:    lcat(execlist,lflags,lfiles);
 105:    sprintf(cmd,ILINK,BIN);
 106:    runit(cmd,execlist,environ);
 107:    docmd("/bin/rm",rfiles,environ);
 108:    chmod(xfile,0755);
 109:    if (xargs) {
 110:       if (!quiet)
 111:          fprintf(stderr,"Executing:\n");
 112:       xargs[0] = xfile;
 113: #ifdef DIREX
 114:       execv(xfile,xargs);
 115: #else DIREX
 116:       execlist[0] = "iconx";
 117:       execlist[1] = 0;
 118:       lcat(execlist,xargs,0);
 119:       execv(ICONX,execlist);
 120: #endif DIREX
 121:       }
 122:    }
 123: runit(c,a,e)
 124: char *c; char **a, **e;
 125:    {
 126:    int rc;
 127:    if ((rc = docmd(c,a,e)) != 0) {
 128:       docmd("/bin/rm",rfiles,e);
 129:       exit(1);
 130:       }
 131:    }
 132: suffix(name,suf)
 133: char *name,*suf;
 134:    {
 135:    return !strcmp(suf,rindex(name,'.'));
 136:    }
 137: char *
 138: mkname(name,suf)
 139: char *name,*suf;
 140:    {
 141:    char *p, *malloc();
 142: 
 143:    p = malloc(16);
 144:    strcpy(p,name);
 145:    strcat(p,suf);
 146:    return p;
 147:    }
 148: char *
 149: getbase(name,suf)
 150: char *name,*suf;
 151:    {
 152:    char *f,*e, *rindex(), *p, *malloc();
 153: 
 154:    if (!(f = rindex(name,'/')))
 155:       f = name;
 156:    else
 157:       f++;
 158:    e = rindex(f,'.');
 159:    p = malloc(16);
 160:    strncpy(p,f,e-f);
 161:    return p;
 162:    }
 163: lcat(c,a,b)
 164: int c[],a[],b[];
 165:    {
 166:    int cp,p;
 167: 
 168:    cp = p = 0;
 169:    while (c[cp])
 170:       cp++;
 171:    while (c[cp] = a[p++])
 172:       cp++;
 173:    p = 0;
 174:    if (b)
 175:       while (c[cp++] = b[p++]);
 176:    }
 177: usage(p)
 178: char *p;
 179:    {
 180:    fprintf(stderr,"usage: %s [-c] [-m] [-t] [-u] file ... [-x args]\n",p);
 181:    exit(1);
 182:    }
 183: docmd(cmd,argv,envp)
 184: char *cmd, **argv, **envp;
 185:    {
 186:    int rc, stat;
 187:    rc = FORK();
 188:    if (rc == -1) {
 189:       fprintf(stderr,"No more processes\n");
 190:       return 255;
 191:       }
 192:    if (rc == 0) {
 193:       execve(cmd,argv,envp);
 194:       fprintf(stderr,"exec failed on %s\n",cmd);
 195:       _exit(255);
 196:       }
 197:    while (rc != wait(&stat));
 198:    return (stat>>8) & 0xff;
 199:    }
 200: plist(title,list)
 201: char *title, **list;
 202:    {
 203:    char **p;
 204:    printf("\n%s\n",title);
 205:    for (p = list; *p; p++)
 206:       printf("'%s'\n",*p);
 207:    }

Defined functions

docmd defined in line 183; used 3 times
getbase defined in line 148; used 3 times
lcat defined in line 163; used 3 times
main defined in line 15; never used
mkname defined in line 137; used 3 times
plist defined in line 200; never used
runit defined in line 123; used 2 times
suffix defined in line 132; used 2 times
usage defined in line 177; used 1 times
  • in line 89

Defined variables

rfiles defined in line 14; used 9 times

Defined macros

BIN defined in line 3; used 2 times
ICONX defined in line 4; used 2 times
ILINK defined in line 11; used 2 times
ITRAN defined in line 8; used 2 times
  • in line 7, 95
MAXARGS defined in line 5; used 2 times
PATHSIZE defined in line 6; used 1 times
  • in line 29
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1168
Valid CSS Valid XHTML 1.0 Strict