/
        PROGRAM jplget


        con.0==0
        con.a==1
        con.b==2
        con.c==3
        con.d==4
        con.e==5
        con.f==6
        con.g==7
        con.h==10
        con.i==11
        con.j==12
        con.k==13
        con.l==14
        con.m==15
        con.n==16
        con.o==17
        con.p==20
        con.q==21
        con.r==22
        con.s==23
        con.t==24
        con.u==25
        con.v==26
        con.w==27
        con.x==30
        con.y==31
        con.z==32

        esc==33
        tab==9.
        space==40
        rub==177
        nl==12
        lf==12
        uparo==136
        bs==10
        cr==15
        con.qq==37

        .mcall qiow$,dir$,qiow$s
;Oh how I just love this new qio we have (Even Unix didn't have this)
read:   qiow$   io.rtt!tf.tmo,5,5,,qios,,<qioin,84.,180.,tbl>

;
;             0 a b c  d  e  f   g   h   i    j    k    l     cr    n     o
tbl:    .word 1+2+4+10+20+40+100+000+400+0000+2000+4000+10000+20000+40000+100000
;
;             p q r s  t  u  v   w   x   y    z    esc
        .word 1+2+4+10+20+40+100+200+400+1000+2000+4000+100000
        .word 0,0,0,0
        .word 0,100000,0,0              ;rubout
        .word 0,0,0,0,0,0

ios:    .word        0,0
qios:
ok:     .byte        0         ;1 = ok
term:   .byte        0         ;terminator character
len:    .word        0         ;length of input

qioin:  .blkb        84.
inp:    .word

linf:   .asciz    <lf>                  ;
rb:     .asciz    <bs><space><bs>       ;rub out stuff
clear:  .asciz    <cr><esc>'K'          ;clear line on control u
clear1: .asciz    <uparo>'u'<cr><lf>    ;this if a slow terminal
        .even

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;        auto s[84.]
;function main[argc,argv]
;        let r0 = line[&s,#300.]
;        printf "_<cr>__<lf>_ term=%o line=(%s)" r0 &s
;        ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function line[s,speed,prm]              ;get an input line; return
	inp := s                        ;with line asciz and the terminator
        clrb @inp
        call outprompt
        do forever
            dir$ #read
            ifb ok = #2
                jmp timout              ;timeout is built into the qio
            fi
            call apinput
	    select case term of         ;see if we must process this or done
            caseb #rub                  ; rubout - thats ours
                if inp hi s
                    dec inp
                    mov #rb,r0
                    call outstr
                fi
                clrb @inp
                break
            caseb #con.r                ;control r is us too
                call outprompt
                r0 := s
                call outstr
                break
            caseb #con.u                ;control u is either fancy
                inp := s                ;i.e. make it look like lots of
                clrb @inp               ;rubouts    or
                if speed gt #300.       ; if a slow terminal
                    mov #clear,r0       ;we do it the old way
                else
                    mov #clear1,r0
                fi
                call outstr
                mov prm(r5),r0
                call outstr
                break
            caseb #con.o                ;just trap these, less confusion
                break
            default                     ;otherwise we are done
                movb term,r0            ;return the terminator
                bic #177400,r0
                ret
            esac

        od
timout:

        ret  #-1                        ;return -1 on timeout
apinput:
        mov #qioin,r3
        loop for r2 = #1 to len
            movb (r3)+,@inp
            if inp lo <s + #79.>
                inc inp
            fi
            clrb @inp
        next r2
        rts pc



outprompt:                              ;output the prompt
        mov #linf,r0
        call outstr
        r0 := prm
        call outstr
        rts pc
outstr::                                ;output a string
        push  r0
        push  r1
        mov r0,r1

10$:
        tstb (r0)+                      ;compute length
        bne 10$
        sub r1,r0
        dec r0

        qiow$s #io.wvb,#5,#5,,#ios,,<r1,r0,#0>
        pop r1
        pop r0
        rts pc
        .end
