home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
australi
/
pscptclp.lzh
/
POSTSCPT.PRG
< prev
Wrap
Text File
|
1989-11-12
|
13KB
|
466 lines
PROCEDURE Post_scpt
*
* DOS-LEVEL POSTSCRIPT DRIVER - Clipper Version
* ╒══════════════════════════════════════════════════════════════════════════╕
* │ Written by G.C.Lesnie for PA Consulting Australia │
* │ │
* │ Any requests for improvement please refer back to: │
* │ Greg Lesnie, │
* │ 9 Linigen Pl. St.Ives │
* │ NSW. 2075. Australia. │
* │ (061) 02 449-6556 │
* │ │
* │ Similarly, if you make substantial improvements, please let me have │
* │ the revised source. │
* │ Regards: Greg Lesnie, November 1989. │
* ╘══════════════════════════════════════════════════════════════════════════╛
*
* ╒══════════════════════════════════════════════════════════════════════════╕
* │ The procedure outputs a preamble (postscript program) to the printer │
* │ or re-directed disk file. │
* │ It then takes a specified disk file, previously output by the clipper │
* │ program and translates it into postscript compatible form, embedding │
* │ calls for underlining, pitch and font etc. Its a little bit slow, │
* │ but it does the job. There may be still some 'anomalous features' │
* │ i.e. bugs because we ditched the development in favour of the │
* │ QuickBasic version due to the inferior speed of Clipper vs QuickBasic │
* │ │
* │ POST_SCPT emulates a limited subset of EPSON commands, selecting │
* │ COURIER Regular, with 10 pitch, 12 pitch, compressed, underline │
* │ originally compiled with QuickBasic 4.5, which runs 3 times as fast │
* │ The conversion exercise, using Brief as the editor, took 2 hours, so │
* │ if you're interested in language conversion QB4 to Clipper, take note.│
* ╘══════════════════════════════════════════════════════════════════════════╛
PARAMETERS File_Name, Out_File, New_Point, New_Margin
* ════════════════════════════════════════════════════════════════════════════
* Call post_scpt with parameters
* - Parameter Type Contents
* - File_name C Input Text file to be printed in postscript
* - Out_file C Optional Redirected output file
* - New_Point C Optional Initial Point Size - default is "10";
* Recognised sizes are "12", "10", "8", "7", "6", "5"
* - New_Margin C Optional Left Margin. Default "350" = 1/2 inch
* e.g.
* DO post_scpt with "inputfil.txt"
* DO post_scpt with "inputfil.txt",,"8","700"
* DO post_scpt with "inputfil.txt","outputfl.prn","8","700"
* ════════════════════════════════════════════════════════════════════════════
save screen
@ 23,00
@ 24,00
params = PCOUNT()
IF params <= 0
return
endif
if params > 1
Output_fil = Out_File
else
Output_fil = ''
endif
if params > 2
newpoint = new_point
else
newpoint = ''
endif
if params > 3
newmargin = new_margin
else
newmargin = ''
endif
@ 23,00 say "Input file "+file_name
Text_file = FOPEN(file_name,0)
Eof_Text = .F.
IF text_file < 0
RETURN
END
@ 23,12+len(file_name) say "Handle"+str(text_file,4)
RESTORE from postscpt additive
if "" <> Output_fil
set printer to &Output_fil
endif
set print on
set console off
* Movements
TopMargin = " 13000"
NTopMargin = VAL(TopMargin)
NLeftMargin = 350
LeftMargin = STR(NLeftMargin, 4)
LineSpace = -192
MaxLines = 62
Uline_Begin = "_U "
Uline_End = "_u "
Courier_Reg = "/CourierR"
Courier_Bold = "/Courier-BoldR"
Point_12 = " 600 _ff"
Point_10 = " 500 _ff"
Point_8 = " 400 _ff"
Point_7 = " 350 _ff"
Point_6 = " 300 _ff"
* Input Filters
Compress = CHR(15)
Crlf = CHR(13) + CHR(10)
Eoj = CHR(4)
Tb = CHR(9)
Lf = CHR(10)
Ff = CHR(12)
Cr = CHR(13)
So = CHR(14)
Nrml = CHR(18)
Dc4 = CHR(20)
Esc = CHR(27)
Fs = CHR(28)
InitPoint = 10
CInitPoint = Point_10
IF NewPoint = "10"
InitPoint = 10
CInitPoint = Point_10
LineSpace = -200
MaxLines = 62
ELSEIF NewPoint = "12"
InitPoint = 12
CInitPoint = Point_12
LineSpace = -208
MaxLines = 58
ELSEIF NewPoint = "8"
InitPoint = 8
CInitPoint = Point_8
LineSpace = -200
MaxLines = 62
ELSEIF NewPoint = "7"
InitPoint = 7
CInitPoint = Point_7
LineSpace = -200
MaxLines = 62
ELSEIF NewPoint = "6"
InitPoint = 6
CInitPoint = Point_6
LineSpace = -200
MaxLines = 62
ENDIF
NMargin = val(NewMargin)
IF NMargin > 3 .and. NMargin <= 18
NLeftMargin = 100 * NMargin
LeftMargin = STR(LeftMargin, 4)
END IF
Vertical = NTopMargin
LineCount = MaxLines
CurrentFont = Courier_Reg
PointSize = InitPoint
CPointSize = CInitPoint
EmptyPage = .T.
TEXT = ""
Next_char = ""
This_Char = ""
pages = 1
char_count = 0
line_total = 0
do preamble
DO WHILE .NOT. eof_text
IF "" = Next_Char
Next_Char = Read_char()
LOOP
ENDIF
This_Char = Next_Char
Next_Char = Read_char()
DO CASE
CASE This_Char $ "(\)"
TEXT = TEXT + "\" + This_Char
CASE This_Char >= " "
TEXT = TEXT + This_Char
CASE This_Char = Cr .and. Next_Char = Lf
This_Char = ""
* Discard so following Linefeed takes effect
CASE This_Char = Cr
DO Carriage
CASE This_Char = Lf
DO EndofLine
CASE This_Char = Ff
DO FormFeed
CASE This_Char = Compress
DO CondFound
CASE This_Char = Dc4
DO EnlargOff
CASE This_Char = EOJ
* DO EndofJob?
This_Char = ""
CASE This_Char = Esc
DO EscFound
CASE This_Char = Fs
DO FsFound
CASE This_Char = Nrml
DO NrmlFound
CASE This_Char = So
DO EnlargOff
CASE "" = This_Char
EXIT
* Should be impossible ??
OTHERWISE
This_Char = ""
* Discard if not printable?
ENDCASE
ENDDO
DO EndJob
FCLOSE(TEXT_FILE)
restore screen
RETURN
PROCEDURE FlushText
IF "" <> TEXT
? "("+TEXT+ ")_S "
EmptyPage = .F.
TEXT = ""
ENDIF
RETURN
PROCEDURE FormFeed
DO FlushText
This_Char = ""
DO EndPage
DO StartPage
RETURN
PROCEDURE EscFound
DO FlushText
EscCmd = Next_Char
This_Char = ""
Next_Char = ""
InsertCmd = ""
IF EscCmd $ "!/3ACJNQRSUijlps%I"
EscOprnd = read_char()
RETURN
ENDIF
IF EscCmd $ "?"
EscOprnd = read_char()
EscOprnd = read_char()
RETURN
ENDIF
IF EscCmd $ ":"
EscOprnd = read_char()
EscOprnd = read_char()
EscOprnd = read_char()
RETURN
ENDIF
IF EscCmd $ "BbD%"
EscOprnd = read_char()
DO WHILE EscOprnd <> CHR(0) .and. EscOprnd <> ""
EscOprnd = read_char()
ENDDO
RETURN
ENDIF
IF EscCmd $ "&KLY*^"
RETURN
ENDIF
IF EscCmd = "-"
EscOprnd = read_char()
Uline = ASC(EscOprnd + CHR(0))
IF Uline = 0 .OR. Uline = 48
InsertCmd = " _u "
ENDIF
IF Uline = 1 .OR. Uline = 49
InsertCmd = " _U "
ENDIF
ELSEIF EscCmd = "W"
EscOprnd = read_char()
Enlarge = ASC(EscOprnd + CHR(0))
IF Enlarge = 0 .OR. Enlarge = 48
InsertCmd = " " + CurrentFont + CPointSize
ENDIF
IF Enlarge = 1 .OR. Enlarge = 49
InsertCmd = " " + Courier_Bold + CPointSize
ELSE
Enlarge = 0
ENDIF
ELSEIF EscCmd = "E" .OR. EscCmd = "G" .OR. EscCmd = CHR(14)
InsertCmd = " " + Courier_Bold + CPointSize
ELSEIF EscCmd = "F" .OR. EscCmd = "H"
InsertCmd = " " + CurrentFont + CPointSize
ELSEIF EscCmd = "M"
* 10 point
PointSize = 10
CPointSize = Point_10
InsertCmd = " " + CurrentFont + CPointSize
ELSEIF EscCmd = "P"
* 12 point
PointSize = 12
CPointSize = Point_12
InsertCmd = " " + CurrentFont + CPointSize
ELSE
InsertCmd = ""
ENDIF
IF "" <> InsertCmd
? InsertCmd
endif
RETURN
PROCEDURE FsFound
DO FlushText
This_Char = ""
Next_Char = ""
RETURN
PROCEDURE EnlargOff
DO FlushText
This_Char = ""
IF Enlarge
InsertCmd = " " + CurrentFont + CPointSize
Enlarge = 0
? InsertCmd
ELSE
RETURN
ENDIF
RETURN
PROCEDURE Carriage
DO FlushText
This_Char = ""
? LeftMargin + " " + STR(Vertical)+ " _m"
* Reposition at start of Line
RETURN
PROCEDURE CondFound
DO FlushText
This_Char = ""
IF PointSize = 10
PointSize = 6
CPointSize = Point_6
InsertCmd = " " + CurrentFont + CPointSize
? InsertCmd
ELSEIF PointSize = 12
PointSize = 8
CPointSize = Point_8
InsertCmd = " " + CurrentFont + CPointSize
? InsertCmd
ENDIF
RETURN
PROCEDURE NrmlFound
DO FlushText
This_Char = ""
IF PointSize = 8
PointSize = 12
CPointSize = Point_12
InsertCmd = " " + CurrentFont + CPointSize
? InsertCmd
ELSEIF PointSize = 6
PointSize = 10
CPointSize = Point_10
InsertCmd = " " + CurrentFont + CPointSize
? InsertCmd
ENDIF
RETURN
PROCEDURE StartPage
? "_bp "+ CurrentFont+ CPointSize
? "0 14032 9922 _ornt "+ LeftMargin + TopMargin+" _m"
EmptyPage = .T.
Vertical = NTopMargin
LineCount = MaxLines
Pages = Pages + 1
@ 24,40 SAY Pages PICTURE "999"
RETURN
PROCEDURE EndofLine
line_total = line_total + 1
@ 24,58 SAY char_count PICTURE "999999"
@ 24,72 SAY line_total PICTURE "999999"
DO FlushText
LineCount = LineCount - 1
IF LineCount <= 0
DO EndPage
DO StartPage
ELSE
Vertical = Vertical + LineSpace
? LeftMargin + " " + STR(Vertical) + " _m"
ENDIF
RETURN
PROCEDURE EndPage
? "_ep"
LineCount = 0
RETURN
PROCEDURE EndJob
DO FlushText
IF .NOT. EmptyPage
DO EndPage
ENDIF
? "_ed end"
? EOJ
set print off
set console on
RETURN
PROCEDURE Preamble
eodata = 0
Eoj = CHR(4)
@ 24,00 SAY "Downloading Program "
? ps_start
? "_bd a4 _bp 0 14032 9922 _ornt /CourierR 500 _ff"
? "0 14032 9922 _ornt 350 13000 _m"
@ 24,00 SAY "Finished Download Printing Page: Chr.Count Lines "
@ 24,40 SAY Pages PICTURE "999"
@ 24,58 SAY char_count PICTURE "999999"
@ 24,72 SAY line_total PICTURE "999999"
RETURN
FUNCTION read_char
if eof_text
return ""
ENDIF
char_count = char_count + 1
char = " "
bytes_read = FREAD(text_file,@char,1)
if ferror() <> 0
@ 23,50 say "fread() error "
@ 23,64 say ferror() picture "9999"
endif
if bytes_read <= 0 .or. len(char) <=0
eof_text = .T.
return ""
ENDIF
return char