Enclosed is a test formatting program I recently completed along with a pdf file that documents it.
I wrote the documentation on a NEC using the dot commands described in the documentation. I transferred it to my laptop via the serial port and pasted it into Notepad. I changed the font on Notepad to New Courier Bold and set the size to 12. I then printed it to the pdf file that is attached. I was planning on creating a folder on the Club100 Member Upload Library, but was having trouble logging on. In the meantime, here is the program and the documentation. Let me know if you try it , have trouble with it or if you have any comments. It has been tested on both my TRS-80 Model 100 and my NEC PC-8201A. Thanks Lloyd Johnson [email protected] <mailto:[email protected]>
10 REM Text Formatter 20 REM Lloyd Johnson 30 REM 5 June 2021 40 REM 50 REM INITIALIZATION 60 CLEAR 1023:MAXFILES=2 70 MC=50:CF=0:OL$="":FF=0:PS=0:TS=0 80 LM=0:PI=5:JF=0:CC$="." 90 DIM SA(10) 100 CLS:FILES:INPUT "Enter name of the document";D$ 110 PRINT "Input =";D$ 120 OPEN D$ FOR INPUT AS #1 130 INPUT "Enter the name of the output";OF$ 140 IF OF$="" THEN OF$="COM:" 150 PRINT "Output =";OF$ 160 OPEN OF$ FOR OUTPUT AS #2 170 REM 180 REM MAIN 190 LINE INPUT#1, T$ 200 GOSUB 310 210 IF EOF(1) THEN CLOSE#1 ELSE GOTO 180 220 REM 230 REM END PROGRAM 240 IF LEN(OL$)<MC THEN 260 250 GOSUB 310 260 IF OL$<>"" THEN SL$=OL$:JF=0:GOSUB 1000:CLOSE#2 270 END 280 ' 290 '***SUBROUTINES*** 300 ' 310 'Input Processing 320 IF LEFT$(T$,1)=CC$THEN GOSUB 560:RETURN:'Dot Command? 330 IF CF=1 THEN GOSUB 1280:PRINT#2,SL$:SL$="":RETURN 340 IF FF=0 THEN SL$=T$:GOSUB 1000:RETURN:'No Fill 350 REM Process text using Fill 360 IF NP=1 THEN MW=MC-PI ELSE MW=MC 370 IF RIGHT$(OL$,1)<>" " THEN OL$=OL$+" " 380 OL$=OL$+T$:T$="" 390 IF TS>0 AND JF=0 THEN GOSUB 1380 400 IF LEN(OL$)>MW THEN 440 410 IF LEN(OL$)=MW-1 THEN OL$=OL$+" " 420 IF LEN(OL$)<MW THEN RETURN 430 SL$=OL$:GOSUB1000:OL$="":RETURN:'LEN(OL$)=MW 440 'LEN(OL$)>MW 450 SS=0:FOR I=MWTO 1 STEP-1 460 IF MID$(OL$,I,1)<>" " THEN 480 470 SS=I:I=1 480 NEXT I 490 IF SS=0 THEN 520 500 SL$=LEFT$(OL$,SS-1):T$=RIGHT$(OL$,LEN(OL$)-SS) 510 OL$="":GOSUB1000:GOTO 350 520 SL$=LEFT(OL$,MW):GOSUB 1000 530 T$=RIGHT$(OL$,LEN(OL$)-MW):OL$="" 540 GOTO 350 550 ' 560 'Process Dot Commands 570 SL$=RIGHT$(T$,LEN(T$)-1) 580 GOSUB 1620:CS$=SL$:'Trim Right 590 IF CS$="F" THEN FF=1 600 IF CS$="NF"THEN JF=0:FF=0 610 IF CS$="NJ"THEN JF=0 620 IF CS$="NC" THEN CF=0 630 IF CS$="J" THEN JF=1:FF=1 640 IF CS$="P" THEN GOSUB 740 650 IF LEFT$(CS$,2)="P " THEN GOSUB 820 660 IF LEFT$(CS$,2)="PI" THEN GOSUB 870 670 IF LEFT$(CS$,2)="SM" THEN GOSUB 920 680 IF LEFT$(CS$,2)="LM" THEN GOSUB 960 690 IF LEFT$(CS$,2)="TS" THEN TS=VAL(RIGHT$(T$,LEN(CS$)-2)) 700 IF CS$="C" THEN CF=1:JF=0 710 IF LEFT$(CS$,2)="CC" AND LEN(CS$)=4 THEN CC$=RIGHT$(CS$,1) 720 RETURN 730 ' 740 '.P command 750 TJ=JF:JF=0:'Temporaily turn off justification 760 IF LEN(OL$)>0 THEN SL$=OL$:OL$="":GOSUB1000 770 JF=TJ 780 GOSUB 1330 790 NP=1 800 RETURN 810 ' 820 '.P n command 830 PS=VAL(RIGHT$(T$,LEN(T$)-2)) 840 GOSUB 740:'Do .P command 850 RETURN 860 ' 870 '.PI command 880 GOSUB 740:'Do .P command 890 PI=VAL(RIGHT$(T$,LEN(T$)-3)) 900 RETURN 910 ' 920 '.SM command 930 MC=VAL(RIGHT$(T$,LEN(T$)-3)) 940 RETURN 950 ' 960 '.LM command 970 LM=VAL(RIGHT$(T$,LEN(T$)-3)) 980 RETURN 990 ' 1000 'Output Line 1010 IF SL$=""OR FF=0 THEN 1070 1020 GOSUB 1570:'Trim left 1030 GOSUB 1620:'Trim right 1040 GOSUB 1500:'Get IA 1050 IF IA>0 THEN SL$=SPACE$(IA)+SL$ 1060 IF JF=1 THEN GOSUB 1120 1070 PRINT#2,SL$ 1080 SL$="" 1090 NP=0:'Clear NP Flag 1100 RETURN 1110 ' 1120 'Justify Text 1130 IF NP=0 THEN MW=MC ELSE MW=MC-PI 1140 IF LEN(SL$)=MW+IA THEN RETURN 1150 SC=0:'Space Count 1160 FOR I=IA+1 TO LEN(SL$)-1 1170 IF MID$(SL$,I,1)=" " THEN SA(SC)=I:SC=SC+1 1180 IF SC=10 THEN I=LEN(SL$):'Only use 1st 10 spaces 1190 NEXT I 1200 IF SC=0 THEN SL$=SL$+" ":GOTO1140 1210 SI=INT(RND(1)*SC):SS=SA(SI) 1220 S1$=LEFT$(SL$,SS):S2$=RIGHT$(SL$,LEN(SL$)+1-SS) 1230 SL$=S1$+S2$ 1240 FOR I=SI TO SC-1:SA(I)=SA(I)+1:NEXT I 1250 IF LEN(SL$)=MW+IA THEN RETURN 1260 GOTO 1210 1270 ' 1280 'Center Text 1290 IF LEN(T$)>MC THEN SL$=SPACE$(LM)+LEFT$(T$,MC):RETURN 1300 SL$=SPACE$(LM+(MC-LEN(T$))/2)+T$ 1310 RETURN 1320 ' 1330 'Space Paragraph 1340 IF PS=0 THEN RETURN 1350 FOR I=1 TO PS:PRINT#2,"":NEXT I 1360 RETURN 1370 ' 1380 'Process Tab Stop 1390 SL$=OL$:GOSUB1570:OL$=SL$ 1400 TP=INSTR(OL$,STRING$(1,9)) 1410 IF TP=0 THEN RETURN 1420 GOSUB 1500 1430 ES=TS-(IA+TP+1) 1440 OL$=LEFT$(OL$,TP-1)+" "+RIGHT$(OL$,LEN(OL$)-TP) 1450 IF TP+IA>TS-1 THEN RETURN 1460 OL$=LEFT$(OL$,TP)+SPACE$(ES)+RIGHT$(OL$,LEN(OL$)-TP+1) 1470 ES=IA+TP-TS 1480 RETURN 1490 ' 1500 'Calculate Indent Amount 1510 IFPI=0OR NP=0 THEN IA=LM:RETURN 1520 IA=LM+PI 1530 IF IA<0 THEN IA=0 1540 IF IA>MC-10 THEN IA=MC-10 1550 RETURN 1560 ' 1570 'Trim Left 1580 IF SL$="" THEN RETURN 1590 IF LEFT$(SL$,1)=" " THEN SL$=RIGHT$(SL$,LEN(SL$)-1):GOTO 1580 1600 RETURN 1610 ' 1620 'Trim Right 1630 IF SL$="" THEN RETURN 1640 IF RIGHT$(SL$,1)=" " THEN SL$=LEFT$(SL$,LEN(SL$)-1):GOTO 1630 1650 RETURN
TXTFOR_Documentation.pdf
Description: Adobe PDF document
