1: / lpd -- Line Printer daemon 2: 3: .globl fopen, getc 4: .globl fcreat, putc, flush 5: .globl switch 6: 7: sys signal; 1; 1 8: sys signal; 2; 1 9: sys signal; 3; 1 / ignore quit,intr,hup 10: sys stat; lock; buf 11: bec 2f 12: sys creat; lock; 0 13: bes 2f 14: sys open; lpd; 0 15: bes 3f 16: mov r0,r1 17: 1: 18: mov r1,r0 19: sys read; dbuf; 16. 20: bes 3f 21: tst r0 22: beq 3f 23: tst dbuf 24: beq 1b 25: cmp dbuf+2,$"df 26: bne 1b 27: sys fork 28: br retry 29: sys exit 30: 3: 31: sys unlink; lock 32: 2: 33: sys exit 34: 35: / get line printer 36: retry: 37: jsr r5,aclose 38: mov $lpr,r0 39: jsr r5,fcreat; print 40: bes error 41: sys chdir; lpd 42: bes error 43: sys open; lpd; 0 44: bes error 45: mov r0,dfi 46: br loop 47: 48: done: 49: sys unlink; lock 50: sys exit 51: 52: error: 53: jsr r5,aclose 54: mov $10.,r0 55: sys sleep 56: sys stat; lock; buf 57: bes done / die if lock is gone 58: br retry 59: 60: / look in directory for work 61: loop: 62: mov dfi,r0 63: sys seek; 0; 0 64: 65: 1: 66: mov dfi,r0 67: sys read; dbuf; 16. 68: bes error 69: tst r0 70: beq done / only non-error return 71: tst dbuf 72: beq 1b 73: mov $dbuf+2,r0 74: cmp (r0),$"df / look for daemon file 75: bne 1b 76: 77: / found prototype file 78: jsr r5,fopen; proto 79: bes 1b 80: 81: / copy a line into buf 82: / only work is expansion of tabs 83: loop1: 84: mov $buf,r1 85: 1: 86: jsr r5,getc; proto 87: bes eloop1 88: movb r0,(r1) 89: cmp r0,$'\t 90: beq 2f 91: cmpb (r1)+,$'\n 92: bne 1b 93: br 1f 94: 2: 95: movb $' ,(r1)+ 96: cmp r1,$buf+8. 97: beq 1b 98: cmp r1,$buf+16. 99: bhis 1b 100: br 2b 101: 1: 102: movb buf,r0 103: jsr r5,switch; sptab 104: 105: / done with a prototype file 106: / look for U's in second pass 107: eloop1: 108: mov proto,r0 109: sys seek; 0; 0 110: br 2f 111: 1: 112: jsr r5,getc; proto 113: bes 1f 114: 3: 115: cmp r0,$'\n 116: bne 1b 117: 2: 118: jsr r5,getc; proto 119: bes 1f 120: cmp r0,$'U 121: bne 3b 122: mov $buf,r1 123: 3: 124: jsr r5,getc; proto 125: bes 1f 126: movb r0,(r1)+ 127: cmp r0,$'\n 128: bne 3b 129: clrb -(r1) 130: sys unlink; buf 131: br 2b 132: 1: 133: mov proto,r0 134: sys close 135: sys unlink; dbuf+2 136: br loop 137: 138: / list of special characters 139: / switchout 140: sptab: 141: 'L; literal 142: 'B; binary 143: 'F; form 144: 'U; loop1 / unlink on second pass 145: 0; 0 146: 147: 148: literal: 149: jmp loop1 150: 151: form: 152: clrb -(r1) 153: mov $buf+1,r0 154: jsr r5,fopen; insert 155: bes loop1 156: mov $14,r0 157: jsr r5,putc; print 158: br 1f 159: 160: binary: 161: clrb -(r1) 162: mov $buf+1,r0 163: jsr r5,fopen; insert 164: bes loop1 165: 166: 1: 167: jsr r5,getc; insert 168: bes 1f 169: jsr r5,putc; print 170: br 1b 171: 1: 172: jsr r5,flush; print 173: mov insert,r0 174: sys close 175: br loop1 176: 177: aclose: 178: mov $9.,r1 179: 1: 180: mov r1,r0 181: sys close 182: dec r1 183: bge 1b 184: rts r5 185: 186: lpr: 187: </dev/lp\0> 188: lock: 189: </usr/lpd/lock\0> 190: lpd: 191: </usr/lpd\0> 192: .even 193: .bss 194: 195: ch: .=.+2 196: dfi: .=.+2 197: dbuf: .=.+18. 198: print: .=.+518. 199: proto: .=.+518. 200: insert: .=.+518. 201: buf: .=.+400. 202: sleep = 35. 203: signal = 48.