100 'Program to change hard carriage returns
101 '(Hex 0D) to soft ones (Hex 8D) so WordStar
102 'can reformat in its "D" mode a document that
103 'was written in its "N" mode.
104 '----------------------------------------------
105 'Program Copyright (c) Alan T. Chattaway
106 'Daybreak Communications, Vancouver, Canada 
107 '(604) 434-7739.  May be used free of charge,
108 'but may not be sold, rented, or otherwise 
109 'commercially exploited.
110 '----------------------------------------------
111 'The problem of hard carriage returns also 
112 'affects documents written with other editors 
113 'which do not use "soft" carriage returns, and 
114 'documents which have been processed using the
115 '"Z" option of PIP to make them viewable with
116 'CP/M's TYPE function.
117 '----------------------------------------------
118 'This program takes one character at a time
119 'from a named text file and sends it to another
120 'named file.  Carriage returns are all changed 
121 'from "hard" to "soft".  Afterwards it will be
122 'necessary to use WordStar to insert "hard" 
123 'returns where really needed, ie at the ends of 
124 'paragraphs, and only then to reformat the 
125 'document.  The program takes about 1 minute
126 'per 1K on long files.  To then remove unwanted 
127 'hard double spaces from the converted file, use 
128 'WordStar's search-and-replace function to put
129 'a single space wherever 2 or 3 are found.
130 '-----------------------------------------------
140 'You must edit the two lines near the start of
141 'the program that begin with "OPEN" and change
142 'FILEFROM.DOC to the name of the file to be
143 'changed, FILETO.DOC to a name under which you
144 'wish to save the result.  I've assumed these
145 'are both on drive B.  If so, be sure to type
146 'RESET <CR> before running this program, or you
147 'may find B is flagged as Read Only.
148 '-----------------------------------------------
149 'I've included copious comments to help novice
150 'programmers understand what's happening.
151 '-----------------------------------------------
598 '   Open source file as random access file #1
599 '   with record length 1 byte (= 1 character) 
600 OPEN "R",#1,"B:FILEFROM.DOC",1
550 '   Specify variable length (bytes) and name by 
560 '   which characters will be known when pulled 
570 '   from file #1
700 FIELD #1, 1 AS OLDCHARACTER$
710 '   Now open destination file same way as #2 
800 OPEN "R",#2,"B:FILETO.DOC",1
810 '   -and specify its variable name the same way
900 FIELD #2, 1 AS NEWCHARACTER$
950 '   Start counting characters from start of file
1000 CHARACTERNUMBER=0
1100 CHARACTERNUMBER=CHARACTERNUMBER+1
1150 '   Pull character from old file
1200 GET #1,CHARACTERNUMBER
1250 '   Not allowed by MBASIC to use name under
1260 '   which variable was pulled from file for 
1270 '   anything else.  So transfer to another
1280 '   variable name while manipulating it.
1300 TEMPORARY$=OLDCHARACTER$
1350 '   If it's a hard <CR>, change to a soft one. 
1400 IF ASC(TEMPORARY$)=&H0D THEN TEMPORARY$=CHR$(&H8D)
1450 '   Now assign the character to the variable name
1460 '   we declared when opening the second file
1500 LSET NEWCHARACTER$=TEMPORARY$
1547 '   and push it into the second file.
1600 PUT #2,CHARACTERNUMBER
1650 '   Text files usually end with CTL-Z so check
1660 '   for this value and end when it's found.
1700 ENDTEST=ASC(TEMPORARY$)
1800 IF ENDTEST=&H1A GOTO 2000
1850 '   If it's not the last character, get another
1900 GOTO 1100
1910 '   If it's the last character, close both 
1930 '   files and shut down.
2000 CLOSE #1
2100 CLOSE #2
2200 END
