Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / CopyToPAR.c
blob374d56dd294bc1a1e12bd002340040a279953862
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 */
8 /*****************************************************************************
10 NAME
12 CopytoPAR
14 SYNOPSIS
16 FILE/A,QUIET/S
18 LOCATION
20 Sys:c
22 FUNCTION
24 Copies (or sends a) file to parallel.device.
26 INPUTS
28 FILE -- Either a file, a directory or a pattern to match.
30 QUIET -- Suppresses any output to the shell.
32 RESULT
34 Standard DOS return codes.
36 NOTES
38 BUGS
40 INTERNALS
42 ******************************************************************************/
43 #include <exec/io.h>
44 #include <dos/dos.h>
45 #include <devices/parallel.h>
46 #include <proto/exec.h>
47 #include <proto/dos.h>
49 #include <stdlib.h>
50 #include <stdio.h>
52 /****************************************************************************************/
54 #define ARG_TEMPLATE "FILE/A,QUIET/S"
55 #define ARG_FILE 0
56 #define ARG_QUIET 1
57 #define NUM_ARGS 2
59 #define BUFSIZE 4096
61 /****************************************************************************************/
63 struct MsgPort *ParMP;
64 struct IOStdReq *ParIO;
65 BOOL ParOpen;
66 BPTR fh;
67 struct RDArgs *myargs;
68 IPTR args[NUM_ARGS];
69 UBYTE s[256];
70 UBYTE buf[BUFSIZE];
72 /****************************************************************************************/
74 static void cleanup(char *msg, ULONG retcode)
76 if (msg && !args[ARG_QUIET])
78 fprintf(stderr, "CopyToPAR: %s\n", msg);
81 if (fh) Close(fh);
82 if (myargs) FreeArgs(myargs);
84 if (ParOpen) CloseDevice((struct IORequest *)ParIO);
85 if (ParIO) DeleteIORequest((struct IORequest *)ParIO);
86 if (ParMP) DeleteMsgPort(ParMP);
88 exit(retcode);
91 /****************************************************************************************/
93 static void getarguments(void)
95 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
97 Fault(IoErr(), 0, s, 255);
98 cleanup(s, RETURN_FAIL);
102 /****************************************************************************************/
104 static void openpar(void)
106 ParMP = CreateMsgPort();
107 if (!ParMP) cleanup("Failed to create msgport", RETURN_ERROR);
109 ParIO = (struct IOStdReq *)CreateIORequest(ParMP, sizeof(struct IOExtPar));
110 if (!ParIO) cleanup("Failed to create IO request", RETURN_ERROR);
112 if (OpenDevice("parallel.device", 0, (struct IORequest *)ParIO, 0))
114 cleanup("Failed to open parallel.device", RETURN_ERROR);
117 ParOpen = TRUE;
120 /****************************************************************************************/
122 static void openfile(void)
124 fh = Open((STRPTR)args[ARG_FILE], MODE_OLDFILE);
125 if (!fh)
127 Fault(IoErr(), 0, s, 255);
128 cleanup(s, RETURN_FAIL);
132 /****************************************************************************************/
134 static BOOL WritePAR(APTR buf, ULONG size)
136 ParIO->io_Command = CMD_WRITE;
137 ParIO->io_Data = buf;
138 ParIO->io_Length = size;
140 return (DoIO((struct IORequest *)ParIO) == 0) ? TRUE : FALSE;
143 /****************************************************************************************/
145 static void docopy(void)
147 LONG size;
151 size = Read(fh, buf, BUFSIZE);
152 if (size == -1)
154 Fault(IoErr(), 0, s, 255);
155 cleanup(s, RETURN_FAIL);
158 if (!WritePAR(buf, size))
160 cleanup("Error writing to parallel.device", RETURN_FAIL);
163 } while (size == BUFSIZE);
167 /****************************************************************************************/
169 int main(void)
171 getarguments();
172 openpar();
173 openfile();
174 docopy();
175 cleanup(NULL, 0);
177 return 0;