New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / CopyToPAR.c
blobaa3c9c99be12b6f5ffa1eac5e618913718b093f9
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Copy file to parallel.device
6 Lang: English
7 */
9 #include <exec/io.h>
10 #include <dos/dos.h>
11 #include <devices/parallel.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
15 #include <stdlib.h>
16 #include <stdio.h>
18 /****************************************************************************************/
20 #define ARG_TEMPLATE "FILE/A,QUIET/S"
21 #define ARG_FILE 0
22 #define ARG_QUIET 1
23 #define NUM_ARGS 2
25 #define BUFSIZE 4096
27 /****************************************************************************************/
29 struct MsgPort *ParMP;
30 struct IOStdReq *ParIO;
31 BOOL ParOpen;
32 BPTR fh;
33 struct RDArgs *myargs;
34 IPTR args[NUM_ARGS];
35 UBYTE s[256];
36 UBYTE buf[BUFSIZE];
38 /****************************************************************************************/
40 static void cleanup(char *msg, ULONG retcode)
42 if (msg && !args[ARG_QUIET])
44 fprintf(stderr, "CopyToPAR: %s\n", msg);
47 if (fh) Close(fh);
48 if (myargs) FreeArgs(myargs);
50 if (ParOpen) CloseDevice((struct IORequest *)ParIO);
51 if (ParIO) DeleteIORequest((struct IORequest *)ParIO);
52 if (ParMP) DeleteMsgPort(ParMP);
54 exit(retcode);
57 /****************************************************************************************/
59 static void getarguments(void)
61 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
63 Fault(IoErr(), 0, s, 255);
64 cleanup(s, RETURN_FAIL);
68 /****************************************************************************************/
70 static void openpar(void)
72 ParMP = CreateMsgPort();
73 if (!ParMP) cleanup("Failed to create msgport", RETURN_ERROR);
75 ParIO = (struct IOStdReq *)CreateIORequest(ParMP, sizeof(struct IOExtPar));
76 if (!ParIO) cleanup("Failed to create IO request", RETURN_ERROR);
78 if (OpenDevice("parallel.device", 0, (struct IORequest *)ParIO, 0))
80 cleanup("Failed to open parallel.device", RETURN_ERROR);
83 ParOpen = TRUE;
86 /****************************************************************************************/
88 static void openfile(void)
90 fh = Open((STRPTR)args[ARG_FILE], MODE_OLDFILE);
91 if (!fh)
93 Fault(IoErr(), 0, s, 255);
94 cleanup(s, RETURN_FAIL);
98 /****************************************************************************************/
100 static BOOL WritePAR(APTR buf, ULONG size)
102 ParIO->io_Command = CMD_WRITE;
103 ParIO->io_Data = buf;
104 ParIO->io_Length = size;
106 return (DoIO((struct IORequest *)ParIO) == 0) ? TRUE : FALSE;
109 /****************************************************************************************/
111 static void docopy(void)
113 LONG size;
117 size = Read(fh, buf, BUFSIZE);
118 if (size == -1)
120 Fault(IoErr(), 0, s, 255);
121 cleanup(s, RETURN_FAIL);
124 if (!WritePAR(buf, size))
126 cleanup("Error writing to parallel.device", RETURN_FAIL);
129 } while (size == BUFSIZE);
133 /****************************************************************************************/
135 int main(void)
137 getarguments();
138 openpar();
139 openfile();
140 docopy();
141 cleanup(NULL, 0);
143 return 0;