home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug106.arc
/
ENCODE6.LBR
/
ENCODE.BQS
/
ENCODE.BAS
Wrap
BASIC Source File
|
1979-12-31
|
10KB
|
262 lines
10 ' ENCODE.BAS Version 1.06 (C) Copyright 1985, 1986 by Merlin R. Null
20 ' To create pseudo compiled dBASE II .CMD files.
30 ' This program may not be sold separately or as part of any collection"
40 ' of programs without the written permission of the author:
50 ' Merlin R. Null, P.O. Box 9422, N. Hollywood, CA 91609, (818)762-1429
60 DEFINT A-Z
70 DIM TOKEN$(67),WORDLEN(67)
80 ON ERROR GOTO 2090 'Used mostly to detect incorrect filename
90 WIDTH LPRINT 255
100 BL$=CHR$(7)
110 OPEN "I",#1,"CLS.DAT"
120 WHILE NOT EOF(1)
130 LINE INPUT #1, A$
140 A=VAL(A$)
150 CLS$=CLS$+CHR$(A)
160 WEND
170 CLOSE #1
180 FOR I=1 TO 67
190 READ TOKEN$(I),WORDLEN(I)
200 NEXT I
210 ' Read CP/M Command Tail for Filename. Compiled Version Only.
220 CTLEN=PEEK(128)
230 IF CTLEN<2 THEN 290
240 FOR I=2 TO CTLEN
250 NF$=NF$+CHR$(PEEK(128+I))
260 NEXT I
270 CLFLAG=-1
280 GOTO 460
290 PRINT CLS$
300 PRINT"ENCODE version 1.06 3/2/86 (C) Copyright 1985, 1986 by ";
310 PRINT"Merlin R. Null"
320 PRINT STRING$(4,10)
330 PRINT"Option: N No console display of input file"
340 PRINT
350 PRINT"Examples: B:FOO.SRC N No console display"
360 PRINT" FOO Output to file with console display"
370 PRINT" A: Displays directory of A:"
380 PRINT" X Exit to system"
390 PRINT" ? Read the Help file"
400 PRINT" <RET> Redisplays this screen"
410 PRINT STRING$(4,10)
420 PRINT
430 LINE INPUT"Filename[.SRC] or Drive:? ";NF$
440 NFLEN=0:CONOFF=0:OPTFLAG=0:FULLNAME$=""
450 IF NF$="" THEN 290 'Redisplay start screen
460 IF NF$="?" THEN OPEN "I",#1,"ENCODE.HLP" ELSE 600
470 PRINT CLS$
480 FOR LINES=1 TO 20
490 IF EOF(1) THEN 540 ELSE LINE INPUT #1,HELP$
500 PRINT HELP$
510 NEXT
520 PRINT
530 PRINT TAB(7)"<Press any key to continue reading help file>"
540 PRINT TAB(12)"Press <ESC> to return to ENCODE ";
550 FINISHED$=INPUT$(1)
560 IF FINISHED$<>CHR$(27) THEN 470
570 CLOSE #1
580 CLFLAG=0
590 GOTO 290
600 FOR I=1 TO LEN(NF$) 'Convert lower to upper case & detect options
610 BYTE$=MID$(NF$,I,1)
620 IF ASC(BYTE$)>96 AND ASC(BYTE$)<123 THEN BYTE$=CHR$(ASC(BYTE$)-32)
630 IF BYTE$=" " THEN OPTFLAG=-1 'Flag start of options
640 IF NOT OPTFLAG THEN FULLNAME$=FULLNAME$+BYTE$
650 IF NOT OPTFLAG THEN 670
660 IF BYTE$="N" THEN CONOFF=-1 'Detect console off
670 NEXT
680 IF FULLNAME$="X" THEN PRINT CLS$:GOTO 1780
690 IF MID$(FULLNAME$,2,1)=";" THEN MID$(FULLNAME$,2,1)=":"
700 IF LEN(FULLNAME$)=2 AND MID$(FULLNAME$,2,1)=":" THEN PRINT CLS$ ELSE 750
710 DIR$=FULLNAME$+"*.*"
720 PRINT"Directory of drive ";FULLNAME$
730 FILES DIR$
740 GOTO 420
750 IF INSTR(FULLNAME$,".")=0 THEN FULLNAME$=FULLNAME$+".SRC"
760 IF RIGHT$(FULLNAME$,3)<>"SRC" THEN PRINT CLS$;STRING$(5,10) ELSE 790
770 PRINT BL$;FULLNAME$;" must have the extension .SRC - try again."
780 GOTO 420
790 FILENAME$=LEFT$(FULLNAME$,LEN(FULLNAME$)-4)
800 TMPNAME$=FILENAME$+".TMP"
810 CMDNAME$=FILENAME$+".CMD"
820 OLDNAME$=FILENAME$+".OLD"
830 OPEN "I",#1,CMDNAME$ 'See if <filename>.CMD exists
840 CLOSE #1 'Close, if found. Else error trap gets it
850 PRINT CLS$;STRING$(7,10);BL$
860 PRINT TAB(20)"[]=========[]"
870 PRINT TAB(20)"[] WARNING []"
880 PRINT TAB(20)"[]=========[]"
890 PRINT:PRINT
900 PRINT CMDNAME$;" already exists! If you answer NO, the old ";CMDNAME$
910 PRINT"will be renamed to ";OLDNAME$
920 PRINT STRING$(3,10)
930 PRINT"Do you wish to overwrite ";CMDNAME$;" (Yes/No/Quit)";
940 INPUT OVERWRITE$
950 IF LEFT$(OVERWRITE$,1)="Y" OR LEFT$(OVERWRITE$,1)="y" THEN 1020
960 IF LEFT$(OVERWRITE$,1)="Q" OR LEFT$(OVERWRITE$,1)="q" THEN 1780
970 IF LEFT$(OVERWRITE$,1)<>"N" AND LEFT$(OVERWRITE$,1)<>"n" THEN 850
980 RENAMECMD=-1
990 OPEN "I",#2,OLDNAME$ 'See if <filename>.OLD exists.
1000 CLOSE #2 'Close, if found. Else error trap gets it
1010 ERASEOLD=-1 'Flag to kill <filename>.OLD
1020 OPEN "I",#3,FULLNAME$
1030 OPEN "O",#1,TMPNAME$
1040 IF CONOFF THEN PRINT:PRINT" <No console output>" ELSE PRINT CLS$
1050 PRINT
1060 PRINT" ^S to Pause - ^C to Abort"
1070 PRINT
1080 LINES=0
1090 WHILE NOT EOF(3)
1100 LINES=LINES+1
1110 LINE INPUT #3,TXT$
1120 IF RIGHT$(TXT$,1)=";" THEN TXT$=LEFT$(TXT$,LEN(TXT$)-1) ELSE 1220
1130 LINE INPUT #3,MORE$
1140 BLANK=0
1150 LINES=LINES+1
1160 FOR CHR=1 TO LEN(MORE$)
1170 CHRVAL=ASC(MID$(MORE$,CHR,1))
1180 IF CHRVAL<>32 AND CHRVAL<>9 THEN TXT$=TXT$+MID$(MORE$,CHR)ELSE 1200
1190 CHR=LEN(MORE$)
1200 NEXT
1210 GOTO 1120
1220 TEMP$=TXT$:START=0:BLANK=0
1230 TEXTLEN=LEN(TXT$)
1240 FOR CHAR=1 TO TEXTLEN
1250 CHARVAL=ASC(MID$(TEMP$,CHAR,1))
1260 IF CHARVAL<123 AND CHARVAL>96 THEN MID$(TEMP$,CHAR,1)=CHR$(CHARVAL-32)
1270 IF START THEN 1290
1280 IF CHARVAL=32 OR CHARVAL=9 THEN BLANK=BLANK+1 ELSE START=CHAR
1290 IF CHAR-BLANK>8 THEN CHAR=TEXTLEN
1300 NEXT
1310 IF LEN(TXT$)-BLANK=0 AND TXT=0 THEN 1630
1320 IF TXT THEN PRN$=TXT$ ELSE 1350
1330 IF MID$(TEMP$,1+BLANK,4)="ENDT" THEN PRN$="ENDT":TXT=0
1340 GOTO 1610
1350 IF MID$(TXT$,1+BLANK,1)="*" OR MID$(TXT$,1+BLANK,4)="NOTE" THEN 1630
1360 IF MID$(TXT$,1+BLANK,1)="&" THEN PRN$=TXT$:GOTO 1610
1370 PRN$="":FOUND=0
1380 IF MID$(TEMP$,1+BLANK,4)="GOTO" THEN PRN$=PRN$+CHR$(160) ELSE 1410
1390 LENGTH=4
1400 GOTO 1540
1410 IF MID$(TEMP$,1+BLANK,7)="DO WHIL" THEN PRN$=PRN$+CHR$(136) ELSE 1440
1420 IF MID$(TEMP$,1+BLANK,8)="DO WHILE" THEN LENGTH=8 ELSE LENGTH =7
1430 GOTO 1540
1440 IF MID$(TEMP$,1+BLANK,7)="DO CASE" THEN PRN$=PRN$+CHR$(137) ELSE 1470
1450 LENGTH=7
1460 GOTO 1540
1470 FOR TOKEN=1 TO 67
1480 IF MID$(TEMP$,1+BLANK,WORDLEN(TOKEN))=TOKEN$(TOKEN) THEN
PRN$=PRN$+CHR$(TOKEN+127):LENGTH=WORDLEN(TOKEN):FOUND=TOKEN:TOKEN=67
:GOTO 1500
1490 IF MID$(TEMP$,1+BLANK,4)=LEFT$(TOKEN$(TOKEN),4) THEN
PRN$=PRN$+CHR$(TOKEN+127):LENGTH=4:FOUND=TOKEN:TOKEN=67
1500 NEXT
1510 IF FOUND=3 OR FOUND=5 OR FOUND=8 THEN 1610
1520 IF NOT TXT AND FOUND=62 THEN TXT=-1
1530 IF FOUND<1 THEN 1800
1540 BEGIN=BLANK+LENGTH+1
1550 FOR BYTE=BEGIN TO TEXTLEN
1560 CHARVAL=ASC(MID$(TXT$,BYTE,1))
1570 IF CHARVAL>128 THEN 1920
1580 IF BYTE=BEGIN AND CHARVAL=32 OR BYTE=BEGIN AND CHARVAL=9 THEN 1600
1590 PRN$=PRN$+CHR$(ASC(MID$(TXT$,BYTE,1))XOR 255)
1600 NEXT
1610 IF NOT CONOFF THEN PRINT TXT$
1620 PRINT #1, PRN$
1630 QUIT$=INKEY$:IF QUIT$<>"" THEN GOSUB 2040
1640 WEND
1650 CLOSE
1660 PRINT
1670 IF ERASEOLD THEN KILL OLDNAME$ ELSE 1690
1680 PRINT"Erasing ";OLDNAME$
1690 IF RENAMECMD THEN NAME CMDNAME$ AS OLDNAME$ ELSE 1710
1700 PRINT"Changing ";CMDNAME$;" to ";OLDNAME$
1710 IF OVERWRITE$="Y" OR OVERWRITE$="y" THEN KILL CMDNAME$ ELSE 1730
1720 PRINT"Erasing ";CMDNAME$
1730 NAME TMPNAME$ AS CMDNAME$:PRINT"Changing ";TMPNAME$;" to ";CMDNAME$
1740 PRINT
1750 IF CLFLAG THEN 1780
1760 INPUT"Are you finished";ANS$
1770 IF LEFT$(ANS$,1)<>"Y" AND LEFT$(ANS$,1)<>"y" THEN 290
1780 END
1790 CLOSE
1800 PRINT BL$
1810 PRINT"[]==============[] This file contains incorrect syntax for a";BL$
1820 PRINT"[] ABORTING [] dBASE II .CMD file. All lines not between"
1830 PRINT"[]==============[] TEXT and ENDTEXT must begin with a reserved"
1840 PRINT" word , '*' (remark) or '&' (macro character)
1850 PRINT
1860 PRINT"The error was found on line";LINES;"of ";FULLNAME$;", it reads:"
1870 PRINT
1880 PRINT "'";TXT$;"'"
1890 PRINT
1900 KILL TMPNAME$
1910 GOTO 1780
1920 CLOSE
1930 PRINT BL$
1940 PRINT"****ABORTING**** This file contains characters with the 8th bit set!"
1950 PRINT BL$
1960 PRINT"The error was in line";LINES;"of ";FULLNAME$;", it reads:"
1970 PRINT
1980 PRINT"'";TXT$;"'"
1990 KILL TMPNAME$
2000 PRINT
2010 GOTO 1780
2020 ' The ^C and ^S handling only works with BASCOM, not the interpreter.
2030 PRINT
2040 IF QUIT$=CHR$(3) THEN CLOSE ELSE 2070
2050 PRINT BL$;"****ABORTING**** ^C entered from keyboard. No files changed"
2060 GOTO 1780
2070 IF QUIT$=CHR$(19) THEN WHILE INKEY$="":WEND
2080 RETURN
2090 IF ERR=53 AND ERL=1020 THEN CLOSE #3 ELSE 2130
2100 PRINT CLS$;STRING$(5,10)
2110 PRINT CHR$(34);FULLNAME$;CHR$(34);" not found - try again.";BL$
2120 RESUME 420
2130 IF ERR=53 AND ERL=830 THEN CLOSE #1:RESUME 1020
2140 IF ERR=53 AND ERL=990 THEN CLOSE #2:RESUME 1020
2150 IF ERR=53 AND ERL=110 THEN CLOSE #1 ELSE 2390
2160 PRINT STRING$(18,10)
2170 PRINT BL$;"CLS.DAT, the clear screen data file, not found."
2180 PRINT"Please enter your clear screen sequence"
2190 PRINT"one byte at a time in Decimal numbers. End your"
2200 PRINT"entries with a <RETURN> to generate CLS.DAT"
2210 PRINT
2220 FOR I=1 TO 9
2230 PRINT"Clear Screen character";I;
2240 LINE INPUT C$
2250 IF C$="" AND I>1 THEN 2340
2260 IF C$="" THEN 2230
2270 IF LEN(C$)>3 THEN 2230
2280 FOR J=1 TO LEN(C$)
2290 IF ASC(MID$(C$,J,1))<48 OR ASC(MID$(C$,J,1))>57 THEN PRINT BL$;
"Whole decimal numbers only.":GOTO 2230
2300 NEXT
2310 IF I>1 THEN CLR$=CLR$+CHR$(13)+CHR$(10)
2320 CLR$=CLR$+C$
2330 NEXT
2340 PRINT"Writing CLS.DAT";
2350 OPEN "O",#1,"CLS.DAT"
2360 PRINT #1,CLR$
2370 CLOSE #1
2380 RESUME 100
2390 IF ERR=53 AND ERL=460 THEN PRINT CLS$;STRING$(5,10); ELSE 2420
2400 PRINT BL$;"The Help file, ENCODE.HLP, is not on this disk!";BL$
2410 RESUME 420
2420 IF ERR=64 THEN CLOSE ELSE 2460
2430 PRINT CLS$;STRING$(5,10)
2440 PRINT BL$;CHR$(34);FULLNAME$;CHR$(34);" is a bad file name - try again."
2450 RESUME 420
2460 ON ERROR GOTO 0
2470 DATA "IF",2,"ELSE",4,"ENDIF",5,"DO",2,"ENDDO",5,"CASE",4,"OTHERWISE",9
2480 DATA "ENDCASE",7,"DO WHILE",8,"DO CASE",7,"STORE",5,"?",1,"RELEASE",7
2490 DATA "RETURN",6,"SELECT",6,"@",1,"ACCEPT",6,"APPEND",6,"BROWSE",6,"CALL",4
2500 DATA "CANCEL",6,"CHANGE",6,"CLEAR",5,"COPY",4,"COUNT",5,"CREATE",6
2510 DATA "DELETE",6,"DISPLAY",7,"CONTINUE",8,"EDIT",4,"EJECT",5,"ERASE",5
2520 DATA "GO",2,"FIND",4,"HELP",4,"INDEX",5,"INPUT",5,"INSERT",6,"JOIN",4
2530 DATA "LIST",4,"LOAD",4,"LOCATE",6,"LOOP",4,"MODIFY",6,"PACK",4,"POKE",4
2540 DATA "QUIT",4,"READ",4,"RECALL",6,"REINDEX",7,"REMARK",6,"RENAME",6
2550 DATA "REPLACE",7,"REPORT",6,"RESET",5,"RESTORE",7,"SAVE",4,"SET",3
2560 DATA "SKIP",4,"SORT",4,"SUM",3,"TEXT",4,"TOTAL",5,"UNLOCK",6,"UPDATE",6
2570 DATA "USE",3,"WAIT",4
t o