2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Copy file to parallel.device
8 /*****************************************************************************
24 Copies (or sends) a file to parallel.device or usbparallel.device.
28 FILE -- Either a file, a directory or a pattern to match.
30 USB -- Use usbparallel.device.
32 QUIET -- Suppresses any output to the shell.
36 Standard DOS return codes.
44 ******************************************************************************/
47 #include <devices/parallel.h>
48 #include <proto/exec.h>
49 #include <proto/dos.h>
51 /****************************************************************************************/
53 #define ARG_TEMPLATE "FILE/A,USB/S,QUIET/S"
61 /****************************************************************************************/
63 struct MsgPort
*ParMP
;
64 struct IOStdReq
*ParIO
;
67 struct RDArgs
*myargs
;
71 STRPTR devicename
= "parallel.device";
73 /****************************************************************************************/
75 static void cleanup(char *msg
)
77 if (msg
&& !args
[ARG_QUIET
])
79 Printf("CopyToPAR: %s\n", msg
);
83 if (myargs
) FreeArgs(myargs
);
85 if (ParOpen
) CloseDevice((struct IORequest
*)ParIO
);
86 if (ParIO
) DeleteIORequest((struct IORequest
*)ParIO
);
87 if (ParMP
) DeleteMsgPort(ParMP
);
90 /****************************************************************************************/
92 static ULONG
getarguments(void)
94 if (!(myargs
= ReadArgs(ARG_TEMPLATE
, args
, 0)))
96 Fault(IoErr(), 0, s
, 255);
103 /****************************************************************************************/
105 static ULONG
openpar(void)
107 ParMP
= CreateMsgPort();
110 cleanup("Failed to create msgport");
114 ParIO
= (struct IOStdReq
*)CreateIORequest(ParMP
, sizeof(struct IOExtPar
));
117 cleanup("Failed to create IO request");
123 devicename
= "usbparallel.device";
126 if (OpenDevice(devicename
, 0, (struct IORequest
*)ParIO
, 0))
128 cleanup("Failed to open (usb)parallel.device");
136 /****************************************************************************************/
138 static ULONG
openfile(void)
140 fh
= Open((STRPTR
)args
[ARG_FILE
], MODE_OLDFILE
);
143 Fault(IoErr(), 0, s
, 255);
150 /****************************************************************************************/
152 static BOOL
WritePAR(APTR buf
, ULONG size
)
154 ParIO
->io_Command
= CMD_WRITE
;
155 ParIO
->io_Data
= buf
;
156 ParIO
->io_Length
= size
;
158 return (DoIO((struct IORequest
*)ParIO
) == 0) ? TRUE
: FALSE
;
161 /****************************************************************************************/
163 static ULONG
docopy(void)
169 size
= Read(fh
, buf
, BUFSIZE
);
172 Fault(IoErr(), 0, s
, 255);
177 if (!WritePAR(buf
, size
))
179 cleanup("Error writing to (usb)parallel.device");
183 } while (size
== BUFSIZE
);
188 /****************************************************************************************/