rem************************************************************************

rem		P R O P O R T I O N A L   S P A C I N G   F O N T

REM			F O R M A T T I N G    P R O G R A M

REM	For text formatting and right justification of text using the TI855
REM	Proportional Spacing (Modern) Print Font

rem	Copyright (c) 1984 St. Benedict's Farm, Waelder, TX 78959
rem	begun 11/6/84

rem**************************************************************************
DIM	cdots%(126)			REM FOR TRANSLATION TABLE INTO DOTS
DIM	gap%(70),tdots%(70)		REM FOR DOT SPACING BETWEEN WORDS
on error goto 9999
false%=0:true%=not false%
REM	INCLUDE PSNCLUDE HERE - NOLIST
%NOLIST
%INCLUDE PSNCLUDE		REM GETSTR,GETNUM,YESNO,PAUSE,PANIC
%LIST
print "TI-855 MODERN-PS FONT FORMATTING AND JUSTIFYING PROGRAM"
print "Copyright (c) November 1984 St. Benedict's Farm, Waelder, TX 78959"
print
5	input "Enter FILE to print <d:filename.typ>:";line a$:printfile$=a$
	if size(a$)=0 then print a$+" NOT ON DISK":goto 5
	justify%=true%:page.offset%=20:right.mar%=85:page.len%=66:page%=1
	page.numbering%=true%:page.pause%=false%:copies%=1:spacing%=1:font%=3
	margin.top%=5:margin.bottom%=6:heading.mar%=2:footing.mar%=3
	pitch.factor=1.0:header$="":footing$=""
print "****DEFAULT SETTINGS****"
15	if page.pause% then page.pause$="Y" ELSE page.pause$="N"
	if page.numbering% then page.numbering$="Y" ELSE page.numbering$="N"
print "**** CURRENT VALUES ****"
print "1. PS Font SLOT #  ";font%
print "2. Page Offset     ";str$(page.offset%)
print "3. Right Margin    ";str$(right.mar%)
print "4. Starting Page # ";str$(page%)
print "5. Page Numbering  ";page.numbering$
print "6. Page Pause ON   ";page.pause$
print "7. Number of Copies";str$(copies%)
print "8. Line Spacing    ";str$(spacing%)
print "9. Page Length     ";str$(page.len%)
print "10.Margin Top      ";str$(margin.top%)
print "11.Margin Bottom   ";str$(margin.bottom%)
print "12.Heading Margin  ";str$(heading.mar%)
print "13.Footing Margin  ";str$(footing.mar%)
print "14.Header String   ";header$
print "15.Footing String  ";footing$
setting%=getnum("Enter NUMBER to change (0=ALL OK):",0,15)
if setting%=0 then goto 30
on setting% gosub FT,PO,RM,SP,PN,PP,NUM,LNSP,PL,MT,MB,HM,FM,HS,FS:goto 15
FT:	font%=getnum("Enter SLOT NUMBER where PS Font is inserted:",1,3): \
	return
PO:	page.offset%=getnum("Enter Page Offset:",1,right.mar%-1)
RM:	right.mar%=getnum("Enter Right Margin:",10,132):return
SP:	page%=getnum("Enter Starting Page:",1,32765):return
PN:	if yesno("Number pages")="Y" then page.numbering%=true% \
		ELSE page.numbering%=false%
	return
PP:	if yesno("Pause Between Pages")="Y" then page.pause%=true% \
		ELSE page.pause%=false%
	return
NUM:	copies%=getnum("Enter Number of Copies to be printed:",1,32765):return
LNSP:	spacing%=getnum("Enter Line Spacing:",1,20):return
PL:	page.len%=getnum("Enter Page Length:",6,255):return
MT:	margin.top%=getnum("Enter Margin Top:",0,page.len%/2):return
MB:	margin.bottom%=getnum("Enter Margin Bottom:",0,page.len%/2):return
HM:	heading.mar%=getnum("Enter Heading Margin:",0,margin.top%):return
FM:	footing.mar%=getnum("Enter Footing Margin:",0,margin.bottom%):return
HS:	header$=getstr("Enter Header String:",0,right.mar%):return
FS:	footing$=getstr("Enter Footing String:",0,right.mar%):return

30	REM---------- SET PRINTER VALUES HERE BEFORE BEGINNING ------------
print "DOCUMENT IS READY FOR PRINTING"
print "PRINTER MUST BE ON-LINE -":call pause
print:print "Press ANY KEY to halt printing..."
LPRINTER
while copies.printed%<copies%
35	open printfile$ as 1
	a$=chr$(27)
	init$=a$+chr$(13)+chr$(80)		REM RESETS TO WP MODE
	init$=init$+a$+chr$(102)+chr$(3)	REM SELECTS FONT #3
	init$=init$+a$+chr$(122)		REM SELECTS 12 PITCH
	init$=init$+a$+chr$(9)+chr$(page.offset%)	REM SETS LEFT MARGIN
	init$=init$+a$+chr$(57)
	print init$;
	gosub PITCHSET
50	REM ----------- PROCESS TEXT - LINES AND PARAGRAPHS-----------------
	a$="":out$="":para$="":ldots%=false%:wrap%=true%:justify%=true%
	read #1;line a$				REM IF EOF-GOTO 9999-ERR="EF"
	if a$="" then out$=a$:gosub PRINTLINE:goto 50
	if left$(a$,1)="." then gosub DOTCMD:goto 50
	i%=asc(left$(a$,1))			REM CHECK FOR PITCH CHANGE HERE
		if i%=1 then \^A=12 PITCH - ESC z (122) @PRINTER
			print chr$(27)+chr$(122);: \
			pitch.factor=1.0:gosub PITCHSET:goto 50
		if i%=14 then \^N IN TEXT=10 PITCH - ESC y (121) @PRINTER
			print chr$(27)+chr$(121);: \
			pitch.factor=1.2:gosub PITCHSET:goto 50
		if i%=15 then \^O IN TEXT=cOmpressed print @ printer
			print chr$(15);: \
			pitch.factor=.72:gosub PITCHSET:goto 50
	while asc(right$(a$,1))=141		REM PARAGRAPH CONTINUES
		para$=para$+left$(a$,len(a$)-1)	REM STRIPS TRAILING CR (141)
		read #1;line a$
	wend
	para$=para$+a$
	x%=false%
	i%=match(" ",mid$(para$,len(para$)-x%,1),1)
	while i%			REM STRIPS TRAILING SPACES FROM PARA$
		x%=x%+1
		i%=match(" ",mid$(para$,len(para$)-x%,1),1)
	wend
	if a$="" then out$=a$:gosub PRINTLINE:goto 50
	if x% then \
		para$=left$(para$,len(para$)-x%)
	while wrap%
		gosub WORDWRAP
		gosub JUSTIFY
		gosub PRINTLINE
		CONSOLE:if constat% then call panic
		LPRINTER
	wend
goto 50						REM GET NEXT LINE TO PRINT
99	copies.printed%=copies.printed%+1
	close 1
wend
CONSOLE:print copies.printed%;" COPY(S) OF FILE PRINTED"
STOP

PITCHSET:
	if pitch.factor=.72 then filename$="PSVALUES.SML" \
		ELSE filename$="PSVALUES.LRG"
	if end #20 then .0000
	open filename$ as 20
	for x%=0 to 126
		read #20;i%,cdots%(x%),a$
	next x%
	close 20
DPLSET:			REM GRAPHIC DOTS(NULS) VALUE OF SPACE CHARACTER
	dpl%=cdots%(32)	REM WHICH IS TAKEN AS THE STANDARD "SPACE"
	dpl%=(right.mar%-page.offset%)*dpl%
	return

.0000	CONSOLE:print chr$(7)
	print filename$+" FILE NOT FOUND"
	stop


%INCLUDE PSWRAP
%INCLUDE PSJUST

PRINTLINE:	
	if lin%=0 then \
		if page%=1 then \NO HEADER ON FIRST PAGE(SEE NXT LINE)
			for x%=1 to margin.top%:print:next x% \PRINTS TOP.MAR
		ELSE gosub STARTPAGE
	if center.next.line% then \
		i%=dots.needed%/2:graphics$="": \
		for x%=1 to i%: \
			graphics$=graphics$+chr$(0): \
		next x%: \
		while i%>99: \
			out$=chr$(27)+chr$(106)+chr$(100)+chr$(0)+ \
				left$(graphics$,100)+out$: \
			i%=i%-100: \
			graphics$=right$(graphics$,len(graphics$)-100): \
		wend: \
		out$=chr$(27)+chr$(106)+chr$(i%)+chr$(0)+graphics$+out$: \
		center.next.line%=false%
	print out$
REM---------- RESET VALUES FOR NEXT LINE -----------------------------
	justify%=true%
	for x%=1 to space.place%
		gap%(x%)=false%
		tdots%(x%)=false%
	next x%
	ldots%=false%:space.place%=false%:space.found%=false%
	graph$="":graphics$="":last.graph$="":just$=""
REM-------------------------------------------------------------------
	lin%=lin%+1
	gosub END.OF.PAGE
	if lin%=0 then goto PRINTLINE.EXIT
	if spacing%>1 then \
		for dbl.spacing%=1 to spacing%-1: \
			print: \
			lin%=lin%+1: \
			gosub END.OF.PAGE: \
			if lin%=0 then goto PRINTLINE.EXIT: \
		next dbl.spacing%
PRINTLINE.EXIT:	return

STARTPAGE:
	for x%=1 to margin.top%-(heading.mar%+1)	
		print
	next x%
	i%=match("\#",header$,1)
	if i% and page.numbering% then \
		header$=left$(header$,i%-1)+str$(page%)+ \
			right$(header$,len(header$)-i%)
	print header$
	for x%=1 to heading.mar%
		print
	next x%
	lin%=0
STARTPAGE.EXIT:	return

END.OF.PAGE:	
	if lin%<page.len%-(margin.top%+margin.bottom%) then goto EOP.EXIT
FORCED.EOP:
	i%=page.len%-(margin.top%+margin.bottom%+lin%)
	if i% then \PRINT ANY NECESSARY BLANK LINES DOWN TO FOOTING OF PAGE
		for x%=1 to i%:print:next x%
	lin%=0
	for x%=1 to footing.mar%
		print
	next x%
	i%=match("\#",footing$,1)
	if i% and page.numbering% then \PAGE NUMBER IS CONTAINED IN FOOTING$
		bottom$=left$(footing$,i%-1)+str$(page%)+ \
			right$(footing$,len(footing$)-i%) \
		ELSE bottom$=footing$
	if footing$="" and page.numbering% then \CENTER PAGE NUMBER AT FOOT
		i%=((right.mar%-page.offset%)-len(str$(page%)))/2: \
		for x%=1 to i%: \
			bottom$=bottom$+" ": \
		next x%: \
		bottom$=bottom$+str$(page%)
	print bottom$:bottom$=nul$
	page%=page%+1
	if page.pause% then call pause \
	ELSE for x%=1 to margin.bottom%-(footing.mar%+1):print:next x%
EOP.EXIT:	return

%INCLUDE PSDOTCMD

9999	rem-------- error recovery ---------------------------------
	if ERR="EF" then \
		CONSOLE:print "END-OF-FILE":LPRINTER:gosub FORCED.EOP:goto 99
	if ERR="OE" or ERR="IF" then \
		print "Illegal file name or file not found": \
		print "Please reenter.":goto 5
	CONSOLE
	print "ERROR: "+ERR+" @LINE: ";ERRL
	goto 15
