1 /**************************************************************
2 **** Print.c : procedures for printing ****
3 **** Free software under GNU license, started on 2/2/2012 ****
5 **************************************************************/
7 #include <intuition/intuition.h>
8 #include <libraries/asl.h>
9 #include <exec/memory.h>
11 #include <proto/exec.h>
16 #include "ProtoTypes.h"
20 #define CATCOMP_NUMBERS /* Error msg use strings id */
23 static inline BYTE
PWrite(struct IORequest
*io
, CONST_STRPTR buffer
, LONG len
)
25 struct IOStdReq
*sio
= (struct IOStdReq
*)io
;
27 sio
->io_Command
= CMD_WRITE
;
28 sio
->io_Data
= (APTR
)buffer
;
30 return (DoIO(io
) == 0 && sio
->io_Actual
== len
) ? 1 : 0;
35 BYTE
print_file(LINE
*svg
, unsigned char eol
)
39 BYTE szeol
= szEOL
[eol
];
45 if ((mp
= CreateMsgPort())) {
46 if ((io
= CreateIORequest(mp
, sizeof(struct IOStdReq
)))) {
47 if (0 == OpenDevice("printer.device", print_unit(-1), io
, 0)) {
50 for(ln
=svg
, buf
=NULL
, i
=0; ln
; ln
=ln
->next
)
55 /* An unmodified line (2nd cond. is for deleted lines) */
56 if (ln
->max
== 0 && ln
->stream
-buf
== i
) {
59 /* Flush preceding unmodified buffer */
61 if( i
>=0 && (PWrite(io
, buf
, i
) != 1 ||
62 PWrite(io
, &chEOL
[eol
], szeol
) != 1 ) )
68 /* Writes the modified line */
69 if( PWrite(io
, ln
->stream
, ln
->size
) != 1 || (ln
->next
!= NULL
&&
70 PWrite(io
, &chEOL
[eol
], szeol
) != 1 ) ) {
78 if( i
>szeol
&& PWrite(io
, buf
, i
-szeol
) !=1 ) {
94 /* Get/set current printer.device unit
95 * If unit < 0, do not change current unit
97 * printer unit to be used for printing
100 BYTE
print_unit(BYTE unit
)
102 static BYTE current_unit
= 0;