;**********************************************
; ADDCR - ADD Carriage Return
; Usage: ADDCR
; by Dave Heyliger
;**********************************************

       SEARCH SYS                ; search normals
       SEARCH SYSSYM
       SEARCH TRM
       SEARCH AAA                ; for fancy stuff (aaa.unv)

       VMAJOR=1.                 ; define a version number
       VMINOR=0.
       VEDIT=100.

       PHDR -1,0,PH$REE!PH$REU   ; define a program header

       .OFINI                    ; define 2 variables....
       .OFDEF  IDDB,D.DDB        ; An Input DDB for input file
       .OFDEF  ODDB,D.DDB        ; An Output DDB for output file
       .OFSIZ  IMPSIZ            ; IMPSIZ is 2 X 150 (octal)

       GETIMP  IMPSIZ,A3         ; A3 points to variables
       LEA     A5,IDDB(A3)       ; A5 points to input file
       LEA     A4,ODDB(A3)       ; A4 point to output file

       PRTTAB  -1,0              ; clear screen
       PRTTAB  6,34              ; tab to here
       TYPE    <ADD CARRIAGE RETURN Utility:>
       PRTTAB  10,24             ; tab to here
       TYPE    <adds a CR to files that don't have them!>

       PRTTAB  12,20             ; tab to here
       TYPE    <Enter in the file needing CRs    : >
       KBD                       ; get input file
       FSPEC   @A5               ; fill DDB with input filespec
       PRTTAB  13,20             ; tab to here
       TYPE    <Enter in a name for updated file : >
       KBD                       ; get output filename
       FSPEC   @A4               ; place filespec in output DDB
       INIT    @A5               ; initialize both files
       INIT    @A4
       LOOKUP  @A5               ; if input file not found
       JNE     BOOBOO            ; error
       LOOKUP  @A4               ; if output file found
       JEQ     BOOBOO            ; error
       OPENI   @A5               ; open them
       OPENO   @A4
       PRTTAB  15,1              ; tab to here
       TYPE    <Working..>       ; gizmo effects!

BYB:    FILINB  @A5               ; get a byte
       TST     IDDB+D.SIZ(A3)    ; eof?
       BEQ     EOF               ; yup
       CMPB    D1,#12            ; at a LF?
       BNE     10$               ; nope
       MOVB    #15,D1            ; yup, get a CR
       FILOTB  @A4               ; write the CR
       MOVB    #12,D1            ; and get the LF
10$:    FILOTB  @A4               ; write out the LF
       TYPE    <.>               ; gizmo effects!
       BR      BYB               ; goto top

BOOBOO: PRTTAB  15,23             ; error routine
       TYPE    <File spec error or file already exists>
       MOV     #7,D1             ; get a bell
       TTY                       ; beep!
       BR      EXIT              ; back to dot

EOF:    CLOSE   @A5               ; eof, close both files
       CLOSE   @A4
EXIT:   TYPECR  <!>               ; gizmo!
       EXIT                      ; back to dot
       END                       ; end of source file