3 This file is part of the Free Pascal run time library
.
4 Copyright (c
) 1999-2000 by Michael Van Canneyt
,
5 member of the Free Pascal development team
.
7 See the file COPYING
.FPC
, included
in this distribution
,
8 for details about the copyright
.
10 This program is distributed
in the hope that it will be useful
,
11 but WITHOUT ANY WARRANTY
; without even the implied warranty of
12 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
.
14 **********************************************************************}
19 Started by Michael Van Canneyt
, 1996
20 (michael
@tfdec1.fys
.kuleuven
.ac
.be
)
22 Current
version is
0.9
24 Date Version Who Comments
25 1999-2000 by
0.8 Michael Initial implementation
26 11/97 0.9 Peter Vreman
<pfv
@worldonline.nl
>
27 Unit now depends on the
31 ---------------------------------------------------------------------}
37 {.$DEFINE PRINTERDEBUG
}
40 DefFile
= '/tmp/PID.lst';
45 Procedure
AssignLst ( Var F
: text
; ToFile
: string
);
47 Assigns to F a printing device
. ToFile is a string with the following form
:
48 '|filename options' : This sets up a pipe with the program filename
,
49 with the given options
50 'filename' : Prints to file filename
. Filename can contain the string
'PID'
51 (No Quotes
), which will be replaced by the PID of your program
.
52 When closing lst
, the file will be sent to lpr
and deleted
.
53 (lpr should be
in PATH
)
55 'filename|' Idem as previous
, only the file is NOT sent to lpr
, nor is it
57 (useful
for opening
/dev/printer
or for later printing
)
59 Lst is set up using
'/tmp/PID.lst'. You can change this behaviour at
60 compile time
, setting the DefFile constant
.
67 include definition of textrec
73 P_TOF
= 1; { Print to file
}
74 P_TOFNP
= 2; { Print to File
, don
't spool }
75 P_TOP = 3; { Print to Pipe }
78 Lpr : String[255]; { Contains path to lpr binary, including null char }
82 Procedure PrintAndDelete (f:string);
92 exit; { No printing was done. We leave the file where it is.}
95 { We're
in the child
}
106 { In trouble here
! }
111 { We
're in the parent. }
122 Procedure OpenLstPipe ( Var F : Text);
124 POpen (f,StrPas(textrec(f).name),'W
');
129 Procedure OpenLstFile ( Var F : Text);
133 {$IFDEF PRINTERDEBUG}
134 writeln ('Printer
: In OpenLstFile
');
136 If textrec(f).mode <> fmoutput then
138 textrec(f).userdata[15]:=0; { set Zero length flag }
139 i:=fdOpen(StrPas(textrec(f).name),(Open_WrOnly or Open_Creat), 438);
141 textrec(f).mode:=fmclosed
143 textrec(f).handle:=i;
148 Procedure CloseLstFile ( Var F : Text);
150 {$IFDEF PRINTERDEBUG}
151 writeln ('Printer
: In CloseLstFile
');
153 fdclose (textrec(f).handle);
154 { In case length is zero, don't print
: lpr would give an error
}
155 if (textrec(f
).userdata
[15]=0) and (textrec(f
).userdata
[16]=P_TOF
) then
157 Unlink(StrPas(textrec(f
).name
));
160 { Non empty
: needs printing
? }
161 if (textrec(f
).userdata
[16]=P_TOF
) then
162 PrintAndDelete (strpas(textrec(f
).name
));
163 textrec(f
).mode
:=fmclosed
168 Procedure
InOutLstFile ( Var F
: text
);
170 {$IFDEF PRINTERDEBUG
}
171 writeln ('Printer : In InOutLstFile');
173 If
textrec(f
).mode
<>fmoutput
then
175 if textrec(f
).bufpos
<>0 then
176 textrec(f
).userdata
[15]:=1; { Set it is
not empty
. Important
when closing
!!}
177 fdwrite(textrec(f
).handle
,textrec(f
).bufptr^
,textrec(f
).bufpos
);
178 textrec(f
).bufpos
:=0;
183 Procedure
SubstPidInName ( Var s
: string
);
194 {$IFDEF PRINTERDEBUG
}
195 writeln ('Print : Filename became : ',s
);
201 Procedure
AssignLst ( Var F
: text
; ToFile
: string
);
203 {$IFDEF PRINTERDEBUG
}
204 writeln ('Printer : In AssignLst');
208 textrec(f
).bufptr
:=@textrec(f
).buffer
;
209 textrec(f
).bufsize
:=128;
210 SubstPidInName (Tofile
);
211 if ToFile
[1]='|' then
213 Assign(f
,Copy(ToFile
,2,255));
214 textrec(f
).userdata
[16]:=P_TOP
;
215 textrec(f
).OpenFunc
:=@OpenLstPipe;
219 if Tofile
[Length(ToFile
)]='|' then
221 Assign(f
,Copy(ToFile
,1,length(Tofile
)-1));
222 textrec(f
).userdata
[16]:=P_TOFNP
;
227 textrec(f
).userdata
[16]:=P_TOF
;
229 textrec(f
).OpenFunc
:=@OpenLstFile;
230 textrec(f
).CloseFunc
:=@CloseLstFile;
231 textrec(f
).InoutFunc
:=@InoutLstFile;
232 textrec(f
).FlushFunc
:=@InoutLstFile;
238 Procedure PrinterExitProc
;
248 ExitProc
:=@PrinterExitProc;
249 AssignLst(Lst
,DefFile
);
257 Revision
1.1 2002/02/19 08:26:20 sasu
260 Revision
1.1.2.1 2000/09/14 13:38:26 marco
261 * Moved from Linux dir
. now start of generic unix dir
, from which the
262 really exotic features should be moved to the target specific dirs
.
264 Revision
1.1 2000/07/13 06:30:54 michael
267 Revision
1.7 2000/02/09 16:59:32 peter
270 Revision
1.6 2000/01/07 16:41:41 daniel
273 Revision
1.5 2000/01/07 16:32:28 daniel
274 * copyright
2000 added
276 Revision
1.4 1999/09/08 16:14:43 peter