10     REM
20     REM      This little program will ask the user for an input file
30     REM  and will read the input file, interpreting the first byte
40     REM  as IBM carriage control, corresponding to the following
50     REM  chart:
60     REM           1 = form feed        - = 2 LF, 1 CR
70     REM           + = 0 LF, 1 CR       0 = 3 LF, 1 CR
80     REM             = 1 LF, 1 CR
90     REM
100    REM  The file will be printed on the printer using these carriage
110    REM  control characters.  If the first byte of any record has a
120    REM  value which does not appear on the list, an error message
130    REM  will be printed on the screen, and the program will abend.
140    REM
150    REM  As it is now written, the program will have minimal functions,
160    REM  but can be enhanced as the need arises.
170    REM                                                 PBP  12-23-89
180    REM
190    REM    Variables:
200    REM
210    REM        I$ = input file name
220    REM         I = input file record counter
230    REM        L$ = line of input data
240    REM        O$ = line of output data
250    REM        C$ = carriage control char
260    REM         C = copies requested
265    REM         L = length of input string
270    REM
280    REM    Program layout:
290    REM
300    REM       10 - 500  comments, modification history
310    REM            700  interpret carriage control
320    REM            800  read input lines, write output (main loop)
330    REM            900  initialize
340    REM           4000  talk to user
350    REM           4200  get user input (no of copies, file name)
354    REM           4300  end of job processing
358    REM           4500  end of job
360    REM
370    REM  The program is designed upside down since greater efficiency
380    REM  can be obtained in basic by having the most often used code
390    REM  close to the beginning.  I don't know if that means that I
400    REM  should have typed all these silly comments at the end.
410    REM
490    REM  *************************************************************
492    REM  *                                                           *
494    REM  *                  PROGRAM START                            *
496    REM  *                                                           *
498    REM  *************************************************************
500    REM
510    GOSUB 4000 : REM  CLEAR SCREEN, TALK TO USER
520    GOSUB 4200 : REM  GET USER INPUT
530    FOR X = 1 TO C
540    GOSUB 900  : REM  INITIALIZE
550    GOSUB 800  : REM  GO READ INPUT LINES UNTIL EOF ON INPUT
560    NEXT X
570    GOTO 4300  : REM  GO DO EOJ PROCESS FOR GRACEFUL SHUTDOWN
700    REM
702    REM  **************************************************************
704    REM  *           700 INTERPRET CARRIAGE CONTROL                   *
706    REM  **************************************************************
710    IF C$ = "1" OR C$ = " " OR C$ = "+" OR C$ = "-" OR C$ = "0" THEN GOTO 750
720    PRINT "ERROR !  INPUT CARRIAGE CONTROL CHARACTER = " C$
730    PRINT "ERROR IS CONTAINED IN RECORD " I " OF INPUT FILE"
735    PRINT "PROGRAM IS ABENDING...."
740    GOTO 4500 : REM  ABEND PROGRAM
750    IF C$ = "1" THEN GOSUB 760:RETURN
752    IF C$ = " " THEN GOSUB 770:RETURN
754    IF C$ = "-" THEN GOSUB 780:RETURN
756    IF C$ = "0" THEN GOSUB 790:RETURN
758    REM  *** C$ MUST HAVE A "+", SO JUST SEND A CR AND GET OUT ***
759    PRINT#2, CHR$(13);:RETURN
760    REM  *** FOR A "1", WE SEND A FORM FEED AND GET OUT ***
762    PRINT#2, CHR$(12);:RETURN
770    REM  *** FOR A SPACE, WE SEND A CR LF PAIR AND GET OUT ***
772    PRINT#2, CHR$(13);CHR$(10);:RETURN
780    REM  *** FOR A "-", WE SEND ONE CR AND TWO LINE FEEDS AND GET OUT ***
782    PRINT#2, CHR$(13);CHR$(10);CHR$(10);:RETURN
790    REM  *** FOR A ZERO, WE SEND ONE CR AND THREE LF'S AND GET OUT ***
792    PRINT#2, CHR$(13);CHR$(10);CHR$(10);CHR$(10);:RETURN
800    REM
802    REM  **************************************************************
804    REM  *            800  READ INPUT LINES AND PRINT (MAIN LOOP)     *
806    REM  **************************************************************
808    REM
809    PRINT#2, CHR$(12);         : REM  SEND FORM FEED, IN CASE IN PAGE MIDDLE
810    IF EOF(1) THEN CLOSE #1:CLOSE # 2:RETURN
815    I = I + 1
820    LINE INPUT#1,L$          : REM  READ ONE LINE OF INPUT FILE
825    IF L$ = "" THEN GOTO 810 : REM IGNORE NULL LINES
830    C$ = LEFT$(L$,1)         : REM  C$ IS LEFTMOST BYTE OF L$
840    GOSUB 700
850    L = LEN(L$)              : REM  L VARIABLE GETS LENGTH OF INPUT LINE
860    Z$ = RIGHT$(L$,L-1)      : REM  Z$ IS ALL CHARS TO RIGHT OF C$
865    O$ = LEFT$(Z$,132)       : REM  WE ONLY WANT THE LEFTMOST 132 CHARS
870    PRINT#2, O$;               : REM  SEND LINE OF DATA TO PRINTER
880    GOTO 810
900    REM
902    REM  ***************************************************************
904    REM  *              900 INITIALIZE                                 *
906    REM  ***************************************************************
908    REM
910    WIDTH "LPT1:",255 : REM  DISABLE AUTO CR/LF ON PRINTER
915    OPEN "LPT1:" FOR OUTPUT AS #2
920    OPEN "I",#1,I$    : REM  OPEN INPUT FILE
930    RETURN
4000   REM
4002   REM  ***************************************************************
4004   REM  *              4000 TALK TO USER                              *
4006   REM  ***************************************************************
4008   REM
4010   CLS
4020   PRINT:PRINT "  *** IBM CARRIAGE CONTROL PRINTING PROGRAM *** "
4030   PRINT:PRINT
4040   PRINT "This program will accept a file name from you and will print"
4050   PRINT "the file on the printer.  This file MUST have an IBM carriage"
4060   PRINT "control character in the first byte of each record, or the "
4070   PRINT "program will just produce an error message and abend."
4080   PRINT:PRINT "The program can be stopped at any time by using "
4090   PRINT "Control-C..."
4100   PRINT:RETURN
4200   REM
4202   REM  ***************************************************************
4204   REM  *               4200  GET USER INPUT                          *
4206   REM  ***************************************************************
4208   REM
4210   PRINT "PLEASE ENTER THE NAME OF THE INPUT FILE NAME IN THE FORM"
4220   INPUT "X:\PATH\FILENAME.TYP ";I$
4230   IF I$ = " " OR I$ = "" THEN PRINT "INVALID INPUT, PROGRAM ENDING":GOTO 4500
4240   PRINT:INPUT "HOW MANY COPIES WOULD YOU LIKE TO PRINT?";C
4250   IF C = 0 THEN PRINT "ARE YOU TRYING TO BE FUNNY?  YOU'LL GET ONE!"
4255   IF C = 0 THEN C = 1
4260   IF C > 50 THEN PRINT "THAT'S A HIGH NUMBER, BUT I'M YOUR WILLING SLAVE"
4270   RETURN
4300   REM
4302   REM  ****************************************************************
4304   REM  *              4300 EOJ PROCESSING (SHUT DOWN GRACEFULLY)      *
4306   REM  ****************************************************************
4308   REM
4310   PRINT:PRINT "PROGRAM IS ENDING NORMALLY"
4320   PRINT "COPIES PRINTED = " C
4330   PRINT "INPUT FILE NUMBER OF RECORDS = "I
4340   PRINT
4500   REM
4502   REM  ****************************************************************
4504   REM  *            4500 - THE END                                    *
4506   REM  ****************************************************************
4508   REM
4510   END