100 !TELFIX.BAS
120 !Reads in ASCII files received from a remote database, stored on disk.
140 !Pares each line down to 80 characters or less long.
160 !Future enhancement would be to clean up word breaks at end of line.
180 !Written by Robert M. Cohen 9/23/84  Last modified 4/13/87
200 !Written in Alpha Micro Basic (AlphaBASIC)
220 !Note that comment character is "!" and "?" is short for "Print"
240 !Copyright 1984, 1985 Robert M. Cohen.  All rights reserved.
260 !Limited permission granted for members of AMUS and LAWSIG to use on
280 !noncommercial basis.
300 !
320 !Next two lines are particular to AlphaBASIC.  Purpose is to declare a
340 !long string size.
360 MAP1 TEXT, S, 5000          ! Hope that line will not exceed 5000 bytes
380 MAP1 SEGMENT, S, 82
400 INPUT "Enter filename of input file (extension assumed to be .TXT): ",N$
420 N$ = UCS(N$)                ! make all input uppercase
440 !Next lines deal with filenames and might have to be modified in a
460 !non-Alpha Micro system
480 N1$ = N$ + ".TXT"           ! file being input
!500 N2$ = N$ + ".TMP"          ! file being output, using .TMP extension
500 N2$ = N$ + ".FMT"           ! use .FMT extension for output filename
520 !Next line looks at disk directory, returns 1 if file "N1$".TXT is found
540 LOOKUP N1$, CHK             ! make sure there is such a text file
560 IF CHK => 1 GOTO 620
575 ? : ? CHR(7)                ! beep for error
580 ? "There is no file named "N1$".  Enter filename again.":?:?:GOTO 400
600 !Modify the next lines as needed for particular version of BASIC
620 OPEN #1, N1$, INPUT
640 OPEN #2, N2$, OUTPUT
!640 OPEN #2, N2$, APPEND       ! Append new material to file if it exists
660 !OPEN #2, LEFT$(N$,6)+".LST", OUTPUT        ! variation; no need for .TMP
680 ! Read in input file, one line at a time
700 !Other BASICS call this function "INPUTLINE"
720 INPUT LINE #1, TEXT         ! a line is defined as all characters until CR
740 ! Check to see if we've reached end of input file
760 !Substitute another appropriate checking function for other BASICs
780 T = EOF(1)
800 IF T = 1 GOTO 1200          ! end of file reached; end this program
820 ! If line is 80 characters or less, no need to chop it, just output it
840 A = LEN(TEXT)
860 IF A <= 5000 GOTO 920
870 ? : ? "A line greater than 5000 characters was found."
880 ? "Some text has been lost.  Try re-running this program with a bigger"
900 ? "buffer size (the variable TEXT)." : ?
920 IF A > 80 GOTO 1040
940 ! line is 80 characters or less long
960 PRINT #2, TEXT              ! Output that line to textfile on disk
980 PRINT #0, "+";              ! Show a confidence character for each
1000                            ! unchanged line [channel 0 is always CRT]
1020 GOTO 720                   ! Get another line of text
1040 ! line is greater than 80 characters; keep chopping it into 80 char lines
1060 SEGMENT = LEFT$(TEXT,80)   ! Take first 80-char segment out of text string
1080 PRINT #2, SEGMENT          ! Output that text segment to textfile
1100 !On Alpha Micros, channel 0 is user's CRT
1120 PRINT #0, "/";             ! Show a different character showing that a
1140                            ! line has been split
1160 TEXT = RIGHT$(TEXT,A-80)   ! Reduce text string to bal after removing seg
1180 GOTO 840                   ! Repeat with balance of line
1200 ?:?:? "End of input file reached.":?
1220 CLOSE #1
1240 CLOSE #2
1260 ! The remainder is not needed if you want to make a .LST file instead
1280 ! of creating a new file with same .TXT extension and renaming original
1300 ! file to .BAK extension
1320 ! The purpose is to create an Alpha Micro command file, i.e., a text
1340 ! file containing a group of executable commands to perform system
1360 ! level functions without operator intervention.
!1380 OPEN #3, "TELREN.CMD", OUTPUT ! Command file must rename .TMP to .TXT
1400 !N3$ = N$ + ".BAK"
1420 !PRINT #3, "RENAME ";N3$;"=";N1$;"/D"
1440 !PRINT #3, "RENAME ";N1$;"=";N2$;"/D"
1460 ! Show the user what has happened:
!1480 ?#3, ":<This program produced the file ";N1$;" which can now be edited";
1480 ?#0, "This program produced the file ";N2$;" which can now be edited";
1500 ?#0, " or printed."
!1520 ?#0, ">"
1540 !CLOSE #3
1560 !Execute the command file that has just been made.
1580 !CHAIN "TELREN.CMD"
1600 END