home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s2 / write.s < prev   
Encoding:
Text File  |  1975-05-13  |  2.1 KB  |  205 lines

  1. / write -- write to another user
  2.  
  3. .globl    ttyn
  4.  
  5.     cmp    (sp)+,$2
  6.     beq    1f
  7.     bgt    2f
  8.     mov    $1,r0
  9.     sys    write; argm; eargm-argm
  10.     sys    exit
  11. 2:
  12.     movb    *4(sp),ltty
  13. 1:
  14.     tst    (sp)+
  15.     mov    (sp)+,r5
  16.     sys    open; utmp; 0
  17.     bec    1f
  18.     mov    $1,r0
  19.     sys    write; film; efilm-film
  20.     sys    exit
  21. 1:
  22.     mov    r0,ufil
  23. 1:
  24.     mov    ufil,r0
  25.     sys    read; ubuf; 16.
  26.     tst    r0
  27.     bne    2f
  28.     jmp    8f
  29. 2:
  30.     tstb    ltty
  31.     beq    2f
  32.     cmpb    ltty,8.+ubuf
  33.     bne    1b
  34. 2:
  35.     mov    $ubuf,r3
  36.     mov    r5,r4
  37.     mov    $9.,r2
  38. 2:
  39.     dec    r2
  40.     beq    2f
  41.     cmpb    (r4)+,(r3)+
  42.     beq    2b
  43.     tstb    -1(r4)
  44.     bne    1b
  45.     cmpb    $' ,-1(r3)
  46.     bne    1b
  47. 2:
  48.     movb    8.+ubuf,ttyno
  49.     sys    open; ttyx; 1
  50.     bes    3f
  51.     sys    stat; ttyx; statbuf
  52.     bes    3f
  53.     bit    $2,statbuf+4
  54.     bne    2f
  55. 3:
  56.     mov    $1,r0
  57.     sys    write; dnymes; ednymes-dnymes
  58.     sys    exit
  59. 2:
  60.     mov    r0,ttyf
  61.     clr    r0
  62.     jsr    pc,ttyn
  63.     mov    r0,r3
  64.     mov    statbuf,r4
  65.     mov    ufil,r0
  66.     sys    seek; 0; 0
  67. 1:
  68.     mov    ufil,r0
  69.     sys    read; ubuf; 16.
  70.     tst    r0
  71.     beq    unknown
  72.     cmp    r3,ubuf+8.
  73.     bne    1b
  74.     mov    $ubuf,r0
  75.     mov    $8.,r1
  76. 1:
  77.     cmpb    $' ,(r0)+
  78.     beq    1f
  79.     dec    r1
  80.     bne    1b
  81. 1:
  82.     neg    r1
  83.     add    $8,r1
  84.     mov    r1,0f
  85. 6:
  86.     mov    ttyf,r0
  87.     sys    write; mesg; emesg-mesg
  88.     mov    ttyf,r0
  89.     sys    0; 5f
  90. .data
  91. 5:
  92.     sys    write; ubuf; 0:2
  93. .text
  94.     mov    ttyf,r0
  95.     sys    write; qnl; 4
  96.     sys    signal; 2; 9f
  97. 7:
  98.     clr    r0
  99.     sys    read; ch; 1
  100.     tst    r0
  101.     beq    9f
  102.     tst    nlflg
  103.     beq    1f
  104.     cmp    ch,$'!
  105.     bne    1f
  106.     sys    fork
  107.         br mshproc
  108.     sys    wait
  109.     mov    $1,r0
  110.     sys    write; excl; 2
  111.     br    7b
  112. 1:
  113.     clr    nlflg
  114.     cmp    ch,$'\n
  115.     bne    1f
  116.     inc    nlflg
  117. 1:
  118.     mov    ttyf,r0
  119.     sys    write; ch; 1
  120.     br    7b
  121. 8:
  122.     movb    (r5)+,ch
  123.     beq    8f
  124.     mov    $1,r0
  125.     sys    write; ch; 1
  126.     br    8b
  127. 8:
  128.     tstb    ltty
  129.     beq    8f
  130.     mov    $1,r0
  131.     sys    write; ltty-1; 2
  132. 8:
  133.     mov    $1,r0
  134.     sys    write; errmsg; eerrmsg-errmsg
  135.     sys    exit
  136. 9:
  137.     mov    ttyf,r0
  138.     sys    write; endmsg; eendmsg-endmsg
  139.     sys    exit
  140.  
  141. unknown:
  142.     mov    $"??,ubuf
  143.     br    6b
  144.  
  145. mshproc:
  146.     sys    exec; msh; mshp
  147.     sys    exit
  148.  
  149. .data
  150. nlflg:
  151.     1
  152. .text
  153.  
  154. mshp:
  155.     msh
  156.     minust
  157.     0
  158. msh:
  159.     </bin/sh\0>
  160. minust:
  161.     <-t\0>
  162. argm:
  163.     <Arg count\n>
  164. eargm:
  165. film:
  166.     <Cannot open utmp\n>
  167. efilm:
  168. .data
  169.     < >        / is ltty -1
  170. ltty:
  171.     .=.+1
  172. .text
  173. excl:
  174.     <!\n>
  175. qnl:
  176.     <...\n>
  177. .data
  178. ttyx:
  179.     </dev/ttyx\0>
  180. ttyno    = .-2
  181. .text
  182. utmp:
  183.     </etc/utmp\0>
  184. endmsg:
  185.     <EOT\n>
  186. eendmsg:
  187. errmsg:
  188.     < not logged in.\n>
  189. eerrmsg:
  190. mesg:
  191.     <\nMessage from >
  192. emesg:
  193. dnymes:
  194.     <Permission denied.\n>
  195. ednymes:
  196.     .even
  197.     .bss
  198.  
  199. ttyf:    .=.+2
  200. ubuf:    .=.+16.
  201. statbuf:.=.+40.
  202. ch:    .=.+2
  203. ufil:    .=.+2
  204. signal = 48.
  205.