; move comments over 1 tab	C/;/	;/
; move back 1 tab        	C/	;/;/
; find leading spaces and convert to tabs	4y5y6y
; get 24 leading	1,$c/^                        /			/4p
;      16        	1,$c/^                /		/5p
;       8         	1,$c/^        /	/6p
;
/
        PROGRAM Ee      ;spread out text
        mutask=1 
        .psect edi14
                
        .enabl lc
        .enabl ama
        .nlist sym
                
        .if df mutask
        .MACRO pure
        .psect pur,ro
        .ENDM 
                
        .MACRO impure
        .psect ipur,rw
        .ENDM 
        .iff 
        .MACRO pure
        .ENDM 
                
        .MACRO impure
        .ENDM 
        .endc 
                
                
        .globl fillit   ;Subroutine for Nf command
                
        impure 
                
                
; - - -	 macro library calls
;       .mcall dir$,callr
; - - -	 system	macros
; - - -	 local data and	symbols
                
dir:    .word 0         ;direction
i:      .word 0         ;index
j:      .word 0         ;index
nb:     .word 0         ;
ne:     .word 0         ;
nholes: .word 0         ;number of holes
                
outp:   .word 0         ;out pointer
nextra: .word 0         ;extra blanks
outwds: .word 0         ;out words
                
; temp:   .blkb 150.
        nl=12 
        cr=15 
        space=40 
        backspace=10           ;for computing the width function
        tab=11 
                
        pure 
                
                
;+
; fillit - spread out text in lbuf3
; input:
;
;       r0 = # of extra spaces
;       r1 = pointer into lbuf3
;       r2 = # of words on line
;       lbuf3 = ascii buffer to spread out
;-
                
fillit:  
        mov r0,nextra
        mov r1,outp
        mov r2,outwds
                
        IF nextra LE #0  OR   outwds LE #1
            rts pc
        FI 
                
        com dir
                
        mov nextra,ne
        LET nholes = outwds - #1
        LET i = outp - #1
                
        LET r1 = i + ne
        mov #lbs-2,r2           ;compute min of:
                
        IF r1 LT r2
            mov r1,j
        ELSE 
            mov r2,j
        FI 
                
        DO WHILE i LT j
                        
            LET r1 = #lbuf3-1 + i           ;lbuf(i)
            LET r2 = #lbuf3-1 + j           ;lbuf(j)
            movb (r1),(r2)                  ; buf(j) <- buf(i)
                        
            IFB (r1) = #space
                                
                IF dir = #0
                    LET r2 = ne - #1
                    LET r2 = r2 / nholes
                    inc r2
                ELSE 
                    LET r2 = ne / nholes
                FI 
                 
                mov r2,nb
                LET ne = ne - nb
                dec nholes
                 
; PRINTF #TEMP <dir=%d nb=%d nholes=%d i=%d j=%d ne=%d> dir nb nholes i j ne
                 
                                
                DO WHILE nb GT #0
                    dec j
                    LET r2 = #lbuf3-1 + j           ;lbuf(j)
                    movb #space,(r2)
                    dec nb
                OD 
            FI 
            dec i
            dec j
                        
        OD 
                
        rts pc
        .end 
