add sdcard to raspi BE kernel
[AROS.git] / workbench / tools / Edit / Print.c
bloba1af3d7b76854686a1abbaac4cb3787870a25d50
1 /**************************************************************
2 **** Print.c : procedures for printing ****
3 **** Free software under GNU license, started on 2/2/2012 ****
4 **** © AROS Team ****
5 **************************************************************/
7 #include <intuition/intuition.h>
8 #include <libraries/asl.h>
9 #include <exec/memory.h>
10 #include <dos/dos.h>
11 #include <proto/exec.h>
13 #include "Gui.h"
14 #include "Project.h"
15 #include "Utility.h"
16 #include "ProtoTypes.h"
17 #include "Print.h"
18 #include "DiskIO.h"
20 #define CATCOMP_NUMBERS /* Error msg use strings id */
21 #include "strings.h"
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;
29 sio->io_Length = len;
30 return (DoIO(io) == 0 && sio->io_Actual == len) ? 1 : 0;
33 /* Print a file
35 BYTE print_file(LINE *svg, unsigned char eol)
37 STRPTR buf;
38 LONG i;
39 BYTE szeol = szEOL[eol];
40 LINE *ln;
41 BYTE retval = 0;
42 struct IORequest *io;
43 struct MsgPort *mp;
45 if ((mp = CreateMsgPort())) {
46 if ((io = CreateIORequest(mp, sizeof(struct IOStdReq)))) {
47 if (0 == OpenDevice("printer.device", print_unit(-1), io, 0)) {
48 BusyWindow(Wnd);
50 for(ln=svg, buf=NULL, i=0; ln; ln=ln->next)
52 if (i == 0)
53 buf = ln->stream;
55 /* An unmodified line (2nd cond. is for deleted lines) */
56 if (ln->max == 0 && ln->stream-buf == i) {
57 i+=ln->size+szeol;
58 } else {
59 /* Flush preceding unmodified buffer */
60 i -= szeol;
61 if( i>=0 && (PWrite(io, buf, i) != 1 ||
62 PWrite(io, &chEOL[eol], szeol) != 1 ) )
64 retval = 0;
65 break;
68 /* Writes the modified line */
69 if( PWrite(io, ln->stream, ln->size) != 1 || (ln->next != NULL &&
70 PWrite(io, &chEOL[eol], szeol) != 1 ) ) {
71 retval = 0;
72 break;
74 i=0;
77 /* Flush buffer */
78 if( i>szeol && PWrite(io, buf, i-szeol) !=1 ) {
79 retval = 0;
82 WakeUp(Wnd);
84 CloseDevice(io);
86 DeleteIORequest(io);
88 DeleteMsgPort(mp);
91 return retval;
94 /* Get/set current printer.device unit
95 * If unit < 0, do not change current unit
96 * Return:
97 * printer unit to be used for printing
100 BYTE print_unit(BYTE unit)
102 static BYTE current_unit = 0;
104 if (unit >= 0)
105 current_unit = unit;
107 return current_unit;