;*; Updated on 06-Dec-91 at 10:48 AM by Michele Tonti; edit time: 0:00:10
;*************************** AMUS Program Label ******************************
; Filename: WRAP.M68                                        Date: 12/6/91
; Category: UTIL         Hash Code: 304-132-200-010      Version: 1.0
; Initials: KUNI/AM      Name: RENE S. HOLLAN
; Company: UDISCO LTD.                             Telephone #: 5144818107
; Related Files:
; Min. Op. Sys.:                               Expertise Level:
; Special:
; Description: This program will wrap the input file at a specified column
; to an output file.  If no column specified, 80 is assumed.
;
;*****************************************************************************
;*************************************************************************
;*                                                                       *
;*                      WRAP   COMMAND PROGRAM - Ver. 1.0                *
;*                                                                       *
;*************************************************************************
;
;                                   NOTICE
;
;All    rights   reserved.  This software is the property of UDISCO LTD.  and
;the material contained herein is  the   proprietary   property   and   trade
;secrets    of    UDISCO  LTD.,  embodying  substantial  creative efforts and
;confidential information, ideas and expressions, no part of  which  may   be
;reproduced   or  transmitted  in  any  form  or  by  any  means, electronic,
;mechanical,  or  otherwise,  including  photocopying  or  input  into    any
;information   storage  or  retrieval  system  without  the  express  written
;permission of UDISCO LTD.
;
;CAUTION: Unauthorized distribution or reproduction  of  this  material   may
;subject you to legal action.
;
;
;       WRAP:           Program to wrap input file at specified column to
;               output file.
;
;       SYNTAX: WRAP <input file> <output file> <wrap column>
;
;               <wrap column> defaults to 80.
;
;       Author: Rene S. Hollan
;
;       COPYRIGHT (C) 1988 - Udisco Ltd., Montreal, Canada.
;
; Edit History
; ------------
;
; [100] 11 May, 1988
;       Coding starts. /RSH
;
;

       SEARCH  SYS
       SEARCH  SYSSYM

OFINI
OFDEF   IDDB,D.DDB                      ; Input DDB
OFDEF   ODDB,D.DDB                      ; Output DDB
OFDEF   LENGTH,4                        ; line length
OFSIZ   IMPSIZ                          ; impure area size


VMAJOR=1                                ; major version
VMINOR=0                                ; minor version
VSUB=0                                  ; sub version
VEDIT=100.                              ; edit version


LF=10.                                  ; line feed
CR=13.                                  ; carriage return

WRAP:   PHDR    -1,,PH$REU!PH$REE       ; program header
       GETIMP  IMPSIZ,A0               ; A0 --> impure area
       FSPEC   IDDB(A0)                ; FSPEC Input DDB
       FSPEC   ODDB(A0)                ; FSPEC Output DDB
       INIT    IDDB(A0)                ; INIT the Input DDB
       INIT    ODDB(A0)                ; INIT the Output DDB
       OPENI   IDDB(A0)                ; open files
       OPENO   ODDB(A0)
       BYP                             ; skip blanks
       MOV     #80.,D1                 ; assume nothing left
       TRM                             ; end of line
       BEQ     8$                      ; yup!

       GTDEC                           ; get wrap column

8$:     MOV     D1,LENGTH(A0)           ; and save it

10$:    CLR     D0                      ; clear character counter

20$:    CTRLC   EXIT                    ; in case bored
       FILINB  IDDB(A0)                ; read a character
       TST     IDDB+D.SIZ(A0)          ; end of file?
       BEQ     EXIT                    ; yup! - all done

       FILOTB  ODDB(A0)                ; and output it
       CMPB    D1,#LF                  ; is it a line feed?
       BEQ     10$                     ; yup! - restart counter

       INC     D0                      ; increment counter
       CMP     D0,LENGTH(A0)           ; too long?
       BLT     20$                     ; nope

       MOVB    #CR,D1                  ; CR-LF the file
       FILOTB  ODDB(A0)
       MOVB    #LF,D1
       FILOTB  ODDB(A0)
       BR      10$

EXIT:   CLOSE   IDDB(A0)                ; close files
       CLOSE   ODDB(A0)
       EXIT

       END