1: /*
   2:  *	dpr -- off line print via dataphone daemon to GCOS
   3:  *		normally invoked through opr
   4:  */
   5: 
   6: char    tfname[]    "/usr/lpd/tfaXXXXX";
   7: char    cfname[]    "/usr/lpd/cfaXXXXX";
   8: char    lfname[]    "/usr/lpd/lfaXXXXX";
   9: char    dfname[]    "/usr/lpd/dfaXXXXX";
  10: int nact;
  11: int tff;
  12: int mailflg;
  13: char    person[10];
  14: int inchar;
  15: int maxrec  1000;
  16: 
  17: main(argc, argv)
  18: int argc;
  19: char *argv[];
  20: {
  21:     register char *arg;
  22:     int c, f, flag;
  23:     int out();
  24: 
  25:     pidfn();
  26:     if((signal(1, 1) & 01) == 0)
  27:         signal(1, out);
  28:     if((signal(2, 1) & 01) == 0)
  29:         signal(2, out);
  30:     if((signal(3, 1) & 01) == 0)
  31:         signal(3, out);
  32:     flag = 0;
  33:     tff = nfile(tfname);
  34:     while (argc>1 && (arg = argv[1])[0]=='-') {
  35:         switch (arg[1]) {
  36: 
  37:         case 'c':
  38:             flag = '+';
  39:             break;
  40: 
  41:         case 'r':
  42:             flag = '-';
  43:             break;
  44: 
  45:         case 'm':
  46:             mailflg = 1;
  47:             break;
  48:         }
  49:         argc--;
  50:         argv++;
  51:     }
  52:     ident();
  53: 
  54:     if(argc == 1)
  55:         copy(0);
  56:     while(--argc) {
  57:         arg = *++argv;
  58:         if(flag == '+')
  59:             goto cf;
  60:         if(*arg == '/' && flag != '-') {
  61:             card('F', arg);
  62:             nact++;
  63:             continue;
  64:         }
  65:         if(link(arg, lfname) < 0)
  66:             goto cf;
  67:         card('F', lfname);
  68:         card('U', lfname);
  69:         lfname[inchar]++;
  70:         nact++;
  71:         goto df;
  72: 
  73:     cf:
  74:         f = open(arg, 0);
  75:         if(f < 0) {
  76:             printf("Cannot open %s\n", arg);
  77:             continue;
  78:         }
  79:         copy(f);
  80:         close(f);
  81: 
  82:     df:
  83:         if(flag == '-') {
  84:             f = unlink(arg);
  85:             if(f < 0)
  86:                 printf("Cannot remove %s\n", arg);
  87:         }
  88:     }
  89: 
  90:     if(nact) {
  91:         tfname[inchar]--;
  92:         f = link(tfname, dfname);
  93:         if(f < 0) {
  94:             printf("Cannot rename %s\n", dfname);
  95:             tfname[inchar]++;
  96:             out();
  97:         }
  98:         unlink(tfname);
  99:         execl("/etc/lpd", "lpd", 0);
 100:         dfname[inchar]++;
 101:     }
 102:     out();
 103: }
 104: 
 105: copy(f)
 106: int f;
 107: {
 108:     int ff, i, nr, nc;
 109:     static int buf[256];
 110: 
 111:     card('F', cfname);
 112:     card('U', cfname);
 113:     ff = nfile(cfname);
 114:     nc = 0;
 115:     nr = 0;
 116:     while((i = read(f, buf, 512)) > 0) {
 117:         write(ff, buf, i);
 118:         nc =+ i;
 119:         if(nc >= 512) {
 120:             nc =- 512;
 121:             nr++;
 122:             if(nr > maxrec) {
 123:                 printf("Copy file is too large\n");
 124:                 break;
 125:             }
 126:         }
 127:     }
 128:     close(ff);
 129:     nact++;
 130: }
 131: 
 132: card(c, s)
 133: int c;
 134: char s[];
 135: {
 136:     char *p1, *p2;
 137:     static char buf[512];
 138:     int col;
 139: 
 140:     p1 = buf;
 141:     p2 = s;
 142:     col = 0;
 143:     *p1++ = c;
 144:     while((c = *p2++) != '\0') {
 145:         *p1++ = c;
 146:         col++;
 147:     }
 148:     *p1++ = '\n';
 149:     write(tff, buf, col+2);
 150: }
 151: 
 152: ident()
 153: {
 154:     int c, n;
 155:     register char *b1p, *pp, *b2p;
 156:     static char b1[100], b2[100];
 157: 
 158:     b1p = b1;
 159:     if(getpw(getuid(), b1p)) {
 160:         b1p = "pdp::::m0000,m000:";
 161:     }
 162:     n = 0;
 163:     b2p = b2;
 164:     while(*b2p++ = "$	ident	"[n++]);
 165:     b2p--;
 166:     n = 5;
 167:     while(--n) while(*b1p++ != ':');
 168:     while((*b2p++ = *b1p++) != ':');
 169:     b2p[-1] = ',';
 170:     b1p = b1;
 171:     pp = person;
 172:     while((c = *b1p++) != ':') {
 173:         *b2p++ = c;
 174:         *pp++ = c;
 175:     }
 176:     *b2p++ = 0;
 177:     *pp++ = 0;
 178:     card('L', b2);
 179:     if (mailflg)
 180:         card('M', person);
 181: }
 182: 
 183: pidfn()
 184: {
 185:     register i, j, c;
 186:     int p;
 187: 
 188:     p = getpid();
 189:     i = 0;
 190:     while(tfname[i] != 'X')
 191:         i++;
 192:     i =+ 4;
 193:     for(j=0; j<5; j++) {
 194:         c = (p%10) + '0';
 195:         p =/ 10;
 196:         tfname[i] = c;
 197:         cfname[i] = c;
 198:         lfname[i] = c;
 199:         dfname[i] = c;
 200:         i--;
 201:     }
 202:     inchar = i;
 203: }
 204: 
 205: nfile(name)
 206: char *name;
 207: {
 208:     register f;
 209: 
 210:     f = creat(name, 0666);
 211:     if(f < 0) {
 212:         printf("Cannot create %s\n", name);
 213:         out();
 214:     }
 215:     name[inchar]++;
 216:     return(f);
 217: }
 218: 
 219: out()
 220: {
 221:     register i;
 222: 
 223:     signal(1, 1);
 224:     signal(1, 2);
 225:     signal(1, 3);
 226:     i = inchar;
 227:     while(tfname[i] != 'a') {
 228:         tfname[i]--;
 229:         unlink(tfname);
 230:     }
 231:     while(cfname[i] != 'a') {
 232:         cfname[i]--;
 233:         unlink(cfname);
 234:     }
 235:     while(lfname[i] != 'a') {
 236:         lfname[i]--;
 237:         unlink(lfname);
 238:     }
 239:     while(dfname[i] != 'a') {
 240:         dfname[i]--;
 241:         unlink(dfname);
 242:     }
 243:     exit();
 244: }

Defined functions

card defined in line 132; used 7 times
copy defined in line 105; used 2 times
ident defined in line 152; used 1 times
  • in line 52
main defined in line 17; never used
nfile defined in line 205; used 2 times
out defined in line 219; used 7 times
pidfn defined in line 183; used 1 times
  • in line 25

Defined variables

cfname defined in line 7; used 7 times
dfname defined in line 9; used 7 times
inchar defined in line 14; used 7 times
lfname defined in line 8; used 8 times
mailflg defined in line 12; used 2 times
maxrec defined in line 15; used 1 times
nact defined in line 10; used 4 times
person defined in line 13; used 2 times
tff defined in line 11; used 2 times
tfname defined in line 6; used 10 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1328
Valid CSS Valid XHTML 1.0 Strict