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

Defined functions

docmd defined in line 182; used 3 times
getbase defined in line 147; used 3 times
lcat defined in line 162; used 3 times
main defined in line 14; never used
mkname defined in line 136; used 3 times
plist defined in line 199; never used
runit defined in line 122; used 2 times
suffix defined in line 131; used 2 times
usage defined in line 176; used 1 times
  • in line 88

Defined variables

rfiles defined in line 13; used 9 times

Defined macros

BIN defined in line 2; used 2 times
ICONX defined in line 3; used 2 times
ILINK defined in line 10; used 2 times
ITRAN defined in line 7; used 2 times
  • in line 6, 94
MAXARGS defined in line 4; used 2 times
PATHSIZE defined in line 5; used 1 times
  • in line 28
Last modified: 1986-05-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1562
Valid CSS Valid XHTML 1.0 Strict