1: static char sccsid[] = "@(#)vpr.c	1.4	(Berkeley)	11/18/82";
   2: 
   3: #include <signal.h>
   4: #include <sys/param.h>
   5: #define BUFSIZ  MAXBSIZE
   6: 
   7: /*
   8:  * 	vpr -- varian and versatec (as printers) spooler
   9:  */
  10: 
  11: #define VAD     "/usr/lib/vad"
  12: #define VPD     "/usr/lib/vpd"
  13: char    VAtfname[] =    "/usr/spool/vad/tfaXXXXX";
  14: char    VAcfname[] =    "/usr/spool/vad/cfaXXXXX";
  15: char    VAdfname[] =    "/usr/spool/vad/dfaXXXXX";
  16: char    VPtfname[] =    "/usr/spool/vpd/tfaXXXXX";
  17: char    VPcfname[] =    "/usr/spool/vpd/cfaXXXXX";
  18: char    VPdfname[] =    "/usr/spool/vpd/dfaXXXXX";
  19: char    *tfname;
  20: char    *cfname;
  21: /* char	*lfname; */
  22: char    *dfname;
  23: int wide;
  24: int literal;
  25: int nact;
  26: int tff;
  27: int mailflg;
  28: char    person[10];
  29: int inchar;
  30: int maxrec  = 2000;
  31: char    *width = "-w106";
  32: int troffit;
  33: int     plotit;
  34: char    *fonts[4];
  35: 
  36: main(argc, argv)
  37:     int argc;
  38:     char *argv[];
  39: {
  40:     register char *arg, *remote;
  41:     int c, f, fv, flag;
  42:     int out();
  43: 
  44:     umask(0);
  45:     if (signal(SIGINT, SIG_IGN) == SIG_DFL)
  46:         signal(SIGINT, out);
  47:     if (signal(SIGQUIT, SIG_IGN) == SIG_DFL)
  48:         signal(SIGQUIT, out);
  49:     if (signal(SIGHUP, SIG_IGN) == SIG_DFL)
  50:         signal(SIGHUP, out);
  51:     if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
  52:         signal(SIGTERM, out);
  53:     remote = "$	remote	**,onl";
  54:     flag = 0;
  55:     wide = 0;
  56:     tfname = VAtfname;
  57:     cfname = VAcfname;
  58:     dfname = VAdfname;
  59:     while (argc>1 && (arg = argv[1])[0]=='-') {
  60:         if (arg[1] && arg[2]) {
  61:             remote[12] = arg[1];
  62:             remote[13] = arg[2];
  63:             remote[14] = 0;
  64:         } else switch (arg[1]) {
  65: 
  66:         case 'W':
  67:             wide++;
  68:             tfname = VPtfname;
  69:             cfname = VPcfname;
  70:             dfname = VPdfname;
  71:             break;
  72: 
  73:         case '-':
  74:             remote[12] = 'r';
  75:             remote[13] = '1';
  76:             remote[14] = '\0';
  77:             break;
  78: 
  79:         case 'c':
  80:             flag = '+';
  81:             break;
  82: 
  83:         case 'r':
  84:             flag = '-';
  85:             break;
  86: 
  87:                 case 'v':
  88:                         plotit = 1;
  89:                         width = 0;
  90:                         break;
  91: 
  92:         case 'm':
  93:             mailflg = 1;
  94:             break;
  95: 
  96:         case 't':
  97:             troffit = 1;
  98:             width = 0;
  99:             break;
 100: 
 101:         case '4':
 102:         case '3':
 103:         case '2':
 104:         case '1':
 105:             fonts[arg[1] - '1'] = argv[2];
 106:             troffit = 1;
 107:             argv++;
 108:             argc--;
 109:             break;
 110: 
 111:         case 'w':
 112:             if (troffit)
 113:                 break;
 114:             if (arg[2] == 0)
 115:                 width = 0;
 116:             else
 117:                 width = arg;
 118:             break;
 119: 
 120:         case 'l':
 121:             literal++;  /* Pass control chars through. */
 122:             break;
 123:         }
 124:         argc--;
 125:         argv++;
 126:     }
 127:     pidfn();
 128:     tff = nfile(tfname);
 129:     if (!wide)      /* varian doesn't use sidebyside. */
 130:         width = 0;
 131:     ident();
 132:     if(argc == 1)
 133:         copy(0);
 134:     while(--argc > 0) {
 135:         arg = *++argv;
 136: /*
 137: 		if(flag == '+')
 138: 			goto cf;
 139:  * This may not work because the daemon runs as someone else, so don't bother
 140: 		if(*arg == '/' && flag != '-') {
 141: 			card(literal ? 'G' : 'F', arg);
 142: 			nact++;
 143: 			continue;
 144: 		}
 145: 		if(link(arg, lfname) < 0)
 146: 			goto cf;
 147: 		card(literal ? 'G' : 'F', lfname);
 148: 		card('U', lfname);
 149: 		lfname[inchar]++;
 150: 		nact++;
 151: 		goto df;
 152:  */
 153: 
 154:     cf:
 155:         f = open(arg, 0);
 156:         if(f < 0) {
 157:             printf("Cannot open %s\n", arg);
 158:             if (plotit) {
 159:                 --argc;
 160:                 arg = *++argv;
 161:             }
 162:             continue;
 163:         }
 164:                 if (plotit) {
 165:             if (--argc > 0) {
 166:                 arg = *++argv;
 167:                 fv = open(arg, 0);
 168:                 if (fv < 0) {
 169:                     printf("Cannot open %s\n", arg);
 170:                     close(f);
 171:                     continue;
 172:                 }
 173:             }
 174:             else {
 175:                 printf("Versaplot requires parm and vector file\n");
 176:                 close(f);
 177:                 continue;
 178:             }
 179:             copy(fv);
 180:             close(fv);
 181:         }
 182:         copy(f);
 183:         close(f);
 184: 
 185:     df:
 186:         if(flag == '-') {
 187:             f = unlink(arg);
 188:             if(f < 0)
 189:                 printf("Cannot remove %s\n", arg);
 190:         }
 191:     }
 192: 
 193:     if(nact) {
 194:         tfname[inchar]--;
 195:         f = link(tfname, dfname);
 196:         if(f < 0) {
 197:             printf("Cannot rename %s\n", dfname);
 198:             tfname[inchar]++;
 199:             out();
 200:         }
 201:         unlink(tfname);
 202:         if (wide)
 203:             execl(VPD, "vpd", "-n", "-3", 0);
 204:         else
 205:             execl(VAD, "vad", "-n", "-3", 0);
 206:         dfname[inchar]++;
 207:         printf("Daemon doesn't exist\n");
 208:         exit(0);
 209:     }
 210:     out();
 211: }
 212: 
 213: copy(f)
 214: int f;
 215: {
 216:     int ff, i, nr, nc;
 217:     static char buf[BUFSIZ];
 218:     int status;
 219: 
 220:     for (i = 0; i < 3; i++)
 221:         if (fonts[i])
 222:             card('1' + i, fonts[i]);
 223:     if (troffit)
 224:         card('T', cfname);
 225:     else if (plotit)
 226:         card('P', cfname);
 227:     else
 228:         card(literal ? 'G' : 'F', cfname);
 229:     card('U', cfname);
 230:     ff = nfile(cfname);
 231:     nc = 0;
 232:     nr = 0;
 233:     if (width) {
 234:         int pvec[2];
 235:         pipe(pvec);
 236:         i = fork();
 237:         if (i < 0) {
 238:             printf("No more processes\n");
 239:             out();
 240:         }
 241:         if (i == 0) {
 242:             if (f != 0) {
 243:                 close(0);
 244:                 dup(f);
 245:             }
 246:             close(1);
 247:             dup(pvec[1]);
 248:             close(pvec[0]);
 249:             close(pvec[1]);
 250:             execl("/usr/lib/sidebyside", "sidebyside", width, 0);
 251:             perror("/usr/lib/sidebyside");
 252:             exit(1);
 253:         }
 254:         close(pvec[1]);
 255:         close(f);
 256:         f = pvec[0];
 257:     }
 258:     while((i = read(f, buf, BUFSIZ)) > 0) {
 259:         write(ff, buf, i);
 260:         nc += i;
 261:         if(nc >= BUFSIZ) {
 262:             nc -= BUFSIZ;
 263:             nr++;
 264:             if(nr > maxrec) {
 265:                 printf("Copy file is too large\n");
 266:                 break;
 267:             }
 268:         }
 269:     }
 270:     close(ff);
 271:     nact++;
 272:     wait(&status);
 273: }
 274: 
 275: card(c, s)
 276: int c;
 277: char s[];
 278: {
 279:     char *p1, *p2;
 280:     static char buf[BUFSIZ];
 281:     int col;
 282: 
 283:     p1 = buf;
 284:     p2 = s;
 285:     col = 0;
 286:     *p1++ = c;
 287:     while((c = *p2++) != '\0') {
 288:         *p1++ = c;
 289:         col++;
 290:     }
 291:     *p1++ = '\n';
 292:     write(tff, buf, col+2);
 293: }
 294: 
 295: ident()
 296: {
 297:     int c, n;
 298:     register char *b1p, *pp, *b2p;
 299:     static char b1[100], b2[100];
 300: 
 301:     b1p = b1;
 302:     if(getpw(getuid(), b1p)) {
 303:         b1p = "pdp::::m0000,m000:";
 304:     }
 305:     n = 0;
 306:     b2p = b2;
 307:     while(*b2p++ = "$	ident	"[n++]);
 308:     b2p--;
 309:     n = 5;
 310:     while(--n) while(*b1p++ != ':');
 311:     while((*b2p++ = *b1p++) != ':');
 312:     b2p[-1] = ',';
 313:     b1p = b1;
 314:     pp = person;
 315:     while((c = *b1p++) != ':') {
 316:         *b2p++ = c;
 317:         *pp++ = c;
 318:     }
 319:     *b2p++ = 0;
 320:     *pp++ = 0;
 321:     card('L', person);
 322:     if (mailflg)
 323:         card('M', person);
 324: }
 325: 
 326: pidfn()
 327: {
 328:     register i, j, c;
 329:     int s;
 330:     int p;
 331: 
 332:     s = p = getpid();
 333:     p &= 077777;
 334:     i = 0;
 335:     while(tfname[i] != 'X')
 336:         i++;
 337:     i += 4;
 338:     for(j=0; j<5; j++) {
 339:         c = (p%10) + '0';
 340:         if(s<0 && j==4)
 341:             c += 4;
 342:         p /= 10;
 343:         tfname[i] = c;
 344:         cfname[i] = c;
 345: /*
 346: 		lfname[i] = c;
 347: */
 348:         dfname[i] = c;
 349:         i--;
 350:     }
 351:     inchar = i;
 352: }
 353: 
 354: nfile(name)
 355: char *name;
 356: {
 357:     register f;
 358: 
 359:     f = creat(name, 0644);
 360:     if(f < 0) {
 361:         printf("Cannot create %s\n", name);
 362:         out();
 363:     }
 364:     name[inchar]++;
 365:     return(f);
 366: }
 367: 
 368: out()
 369: {
 370:     register i;
 371: 
 372:     signal(SIGINT, SIG_IGN);
 373:     signal(SIGQUIT, SIG_IGN);
 374:     signal(SIGHUP, SIG_IGN);
 375:     signal(SIGTERM, SIG_IGN);
 376:     i = inchar;
 377:     while(tfname[i] != 'a') {
 378:         tfname[i]--;
 379:         unlink(tfname);
 380:     }
 381:     while(cfname[i] != 'a') {
 382:         cfname[i]--;
 383:         unlink(cfname);
 384:     }
 385: /*
 386: 	while(lfname[i] != 'a') {
 387: 		lfname[i]--;
 388: 		unlink(lfname);
 389: 	}
 390: */
 391:     while(dfname[i] != 'a') {
 392:         dfname[i]--;
 393:         unlink(dfname);
 394:     }
 395:     exit(0);
 396: }

Defined functions

card defined in line 275; used 7 times
copy defined in line 213; used 3 times
ident defined in line 295; used 1 times
main defined in line 36; never used
nfile defined in line 354; used 2 times
out defined in line 368; used 9 times
pidfn defined in line 326; used 1 times

Defined variables

VAcfname defined in line 14; used 1 times
  • in line 57
VAdfname defined in line 15; used 1 times
  • in line 58
VAtfname defined in line 13; used 1 times
  • in line 56
VPcfname defined in line 17; used 1 times
  • in line 69
VPdfname defined in line 18; used 1 times
  • in line 70
VPtfname defined in line 16; used 1 times
  • in line 68
cfname defined in line 20; used 11 times
dfname defined in line 22; used 9 times
fonts defined in line 34; used 3 times
inchar defined in line 29; used 6 times
literal defined in line 24; used 2 times
mailflg defined in line 27; used 2 times
maxrec defined in line 30; used 1 times
nact defined in line 25; used 2 times
person defined in line 28; used 3 times
plotit defined in line 33; used 4 times
sccsid defined in line 1; never used
tff defined in line 26; used 2 times
tfname defined in line 19; used 12 times
troffit defined in line 32; used 4 times
wide defined in line 23; used 4 times
width defined in line 31; used 7 times

Defined macros

BUFSIZ defined in line 5; used 5 times
VAD defined in line 11; used 1 times
VPD defined in line 12; used 1 times
Last modified: 1982-11-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1017
Valid CSS Valid XHTML 1.0 Strict