home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1985-12-06 | 4.1 KB | 128 lines |
- 10 '*************************************************************************
- 20 '*************************************************************************
- 30 '
- 40 'APPEND, Version 1.0
- 50 'Author: J. Crone
- 60 'Date: 1-25-82
- 70 '
- 80 'Copyright 1982 by Personal Computer Age. All rights reserved.
- 90 'This program is published for the personal use of readers of Personal
- 100 'Compurter Age. Commercial use is prohibited.
- 110 '
- 120 '*************************************************************************
- 130 '*************************************************************************
- 140 '
- 150 '
- 160 'Initialize.
- 170 DEFINT A-Z:KEY OFF:CLS
- 180 CLOSE 'any oper files.
- 190 'Set the following variable equal to a number slightly larger than
- 200 'the length of the average line in the files you will be appending.
- 210 AVG.LINE.LEN=140
- 220 ARRAY.SIZE = FRE(0)/(AVG.LINE.LEN + 1)
- 230 DIM TRANSFER$(ARRAY.SIZE)
- 240 '
- 250 '
- 260 'Display title and instructins.
- 261 DATA " FILE APPEND PROGRAM "
- 270 DATA "To append a file to an existing document, copy both files to"
- 280 DATA "floppy diskette (which should be in Drive a:), or to the main"
- 290 DATA "directory. "
- 300 DATA " "
- 310 DATA "Enter file names as requested. An output file is required"
- 320 DATA "and may be a new file or an existing file. Up to eight"
- 330 DATA "append files may be entered. "
- 331 DATA " "
- 332 DATA "After completion the output file will contain all files "
- 340 DATA "in the order entered. "
- 341 DATA " "
- 350 DATA "Type '/' as the last entry to start execution."
- 351 DATA " "
- 360 DATA "Note: this utility works on text files only, and assumes a"
- 365 DATA "maximum line length of 140 characters. Longer lines require a"
- 366 DATA "program change."
- 370 COLOR 0,7:READ TEXT$:LOCATE 3,(40-(LEN(TEXT$)/2)):PRINT TEXT$:COLOR 7,0
- 380 COL = 10:FOR I = 5 TO 15:LOCATE I,COL:READ TEXT$:PRINT TEXT$:NEXT I
- 390 PRINT:FOR I=17 TO 21:LOCATE I,COL:READ TEXT$:PRINT TEXT$:NEXT I
- 400 '
- 410 '
- 420 LOCATE 25,25:COLOR 8,1:INPUT "Press Return Key to continue!",I$:COLOR 0,1
- 430 'Get output file name.
- 440 ON ERROR GOTO 960
- 450 I = 1
- 460 CLS
- 470 COL=25:LOCATE 13,COL:LINE INPUT; "Output File Name - ",FILE.NAME$(I)
- 480 IF INSTR(FILE.NAME$(I),"/") THEN GOTO 870 'Abort.
- 490 OPEN FILE.NAME$(I) FOR APPEND AS #1
- 500 '
- 510 '
- 520 'Get append file names.
- 530 FOR I = 2 TO 9
- 540 LOCATE 25,1:PRINT SPC(79)
- 550 LOCATE 12 + I,COL: PRINT USING "Append File Name _## - ";(I-1);
- 560 LINE INPUT FILE.NAME$(I)
- 570 IF INSTR(FILE.NAME$(I),"/") THEN GOTO 650 'done.
- 580 'Test for good file specification.
- 590 OPEN FILE.NAME$(I) FOR INPUT AS #2:CLOSE #2
- 600 NEXT I
- 610 IF I = 10 THEN I = 9
- 620 ON ERROR GOTO 0
- 630 '
- 640 '
- 650 'Do the job.
- 660 LOCATE 25,1:PRINT SPC(79)
- 670 FOR J = 2 TO (I-1)
- 680 LOCATE 25,1:PRINT SPC(79);
- 690 COLOR 23,0:LOCATE 25.25:PRINT "Appending ",FILE.NAME$(J);:COLOR 7,0
- 700 OPEN FILE.NAME$(J) FOR INPUT AS #2
- 710 ERASE TRANSFER$ 'Garbage collection, the fast way.
- 720 DIM TRANSFER$(ARRAY.SIZE)
- 730 FOR K = 0 TO ARRAY.SIZE 'Read lines from input file.
- 740 IF EOF(2) THEN GOTO 770
- 750 LINE INPUT #2,TRANSFER$(K)
- 760 NEXT K
- 770 IF K = 0 THEN GOTO 820
- 780 FOR L = 0 TO (K-1) 'Write lines to output file.
- 790 PRINT #1, TRANSFER$(L)
- 800 NEXT L
- 810 GOTO 710
- 820 CLOSE #2 'Input file.
- 830 NEXT J
- 840 CLOSE #1 'Output file.
- 850 '
- 860 '
- 870 'More work to do?
- 880 LOCATE 25,1:PRINT SPC(79);:LOCATE 24,15
- 890 PRINT
- 891 LINE INPUT; "Job Complete. More files to transfer? (Y/N) ";RESPONSE$
- 900 IF LEFT$(RESPONSE$,1) = "Y" OR LEFT$(RESPONSE$,1) = "y" THEN GOTO 930
- 910 CLS:SYSTEM 'system 'Job complete, return to DOS.
- 920 'Erase screen and go again.
- 930 FOR I = 11 TO 25: LOCATE I,1:PRINT SPC(78);: NEXT I
- 940 GOTO 430
- 950 '
- 960 'Trap common errors.
- 970 BEEP
- 980 MSG52$ = "Last entry must be `\'"
- 990 MSG53$ = "That file does not exist. Please reenter."
- 1000 MSG64$ = "Incorrect file specification. Please reenter."
- 1010 MSG67$ = "Bad file name or too many files. Reenter or use a new disk."
- 1020 MSG70$ = "Remove write protect tab from disk."
- 1030 MSG71$ = "Put a disk in the drive and close the door."
- 1040 LOCATE 25,1:PRINT SPC(79);:LOCATE 25,1
- 1050 TRAP = 0
- 1060 IF ERR = 52 THEN PRINT MSG52$;:TRAP = 1
- 1070 IF ERR = 53 THEN PRINT MSG53$;: TRAP = 1
- 1080 IF ERR = 64 THEN PRINT MSG54$;: TRAP = 1
- 1090 IF ERR = 67 THEN PRINT MSG67$;: TRAP = 1
- 1100 IF ERR = 70 THEN PRINT MSG70$;: TRAP = 1
- 1110 IF ERR = 71 THEN PRINT MSG71$;: TRAP = 1
- 1120 IF TRAP = 0 THEN GOTO 1160
- 1130 'Found the problem. Go back and try again.
- 1140 LOCATE 12 + I,1:PRINT SPC(79);
- 1150 IF I = 1 THEN RESUME 470 ELSE RESUME 550
- 1160 'Not a common error. Let the system handle it.
- 1170 ON ERROR GOTO 0:CLOSE
- 1180 SAV.ERR = ERR:RESUME 1190
- 1190 ERROR SAV.ERR:SYSTEM
-