2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Copy file to parallel.device
11 #include <devices/parallel.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
18 /****************************************************************************************/
20 #define ARG_TEMPLATE "FILE/A,QUIET/S"
27 /****************************************************************************************/
29 struct MsgPort
*ParMP
;
30 struct IOStdReq
*ParIO
;
33 struct RDArgs
*myargs
;
38 /****************************************************************************************/
40 static void cleanup(char *msg
, ULONG retcode
)
42 if (msg
&& !args
[ARG_QUIET
])
44 fprintf(stderr
, "CopyToPAR: %s\n", msg
);
48 if (myargs
) FreeArgs(myargs
);
50 if (ParOpen
) CloseDevice((struct IORequest
*)ParIO
);
51 if (ParIO
) DeleteIORequest((struct IORequest
*)ParIO
);
52 if (ParMP
) DeleteMsgPort(ParMP
);
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
);
86 /****************************************************************************************/
88 static void openfile(void)
90 fh
= Open((STRPTR
)args
[ARG_FILE
], MODE_OLDFILE
);
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)
117 size
= Read(fh
, buf
, BUFSIZE
);
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 /****************************************************************************************/