2 Copyright © 1995-2010, 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>
54 /****************************************************************************************/
56 #define ARG_TEMPLATE "FILE/A,USB/S,QUIET/S"
64 /****************************************************************************************/
66 struct MsgPort
*ParMP
;
67 struct IOStdReq
*ParIO
;
70 struct RDArgs
*myargs
;
74 STRPTR devicename
= "parallel.device";
76 /****************************************************************************************/
78 static void cleanup(char *msg
, ULONG retcode
)
80 if (msg
&& !args
[ARG_QUIET
])
82 fprintf(stderr
, "CopyToPAR: %s\n", msg
);
86 if (myargs
) FreeArgs(myargs
);
88 if (ParOpen
) CloseDevice((struct IORequest
*)ParIO
);
89 if (ParIO
) DeleteIORequest((struct IORequest
*)ParIO
);
90 if (ParMP
) DeleteMsgPort(ParMP
);
95 /****************************************************************************************/
97 static void getarguments(void)
99 if (!(myargs
= ReadArgs(ARG_TEMPLATE
, args
, 0)))
101 Fault(IoErr(), 0, s
, 255);
102 cleanup(s
, RETURN_FAIL
);
106 /****************************************************************************************/
108 static void openpar(void)
110 ParMP
= CreateMsgPort();
111 if (!ParMP
) cleanup("Failed to create msgport", RETURN_ERROR
);
113 ParIO
= (struct IOStdReq
*)CreateIORequest(ParMP
, sizeof(struct IOExtPar
));
114 if (!ParIO
) cleanup("Failed to create IO request", RETURN_ERROR
);
118 devicename
= "usbparallel.device";
121 if (OpenDevice(devicename
, 0, (struct IORequest
*)ParIO
, 0))
123 cleanup("Failed to open (usb)parallel.device", RETURN_ERROR
);
129 /****************************************************************************************/
131 static void openfile(void)
133 fh
= Open((STRPTR
)args
[ARG_FILE
], MODE_OLDFILE
);
136 Fault(IoErr(), 0, s
, 255);
137 cleanup(s
, RETURN_FAIL
);
141 /****************************************************************************************/
143 static BOOL
WritePAR(APTR buf
, ULONG size
)
145 ParIO
->io_Command
= CMD_WRITE
;
146 ParIO
->io_Data
= buf
;
147 ParIO
->io_Length
= size
;
149 return (DoIO((struct IORequest
*)ParIO
) == 0) ? TRUE
: FALSE
;
152 /****************************************************************************************/
154 static void docopy(void)
160 size
= Read(fh
, buf
, BUFSIZE
);
163 Fault(IoErr(), 0, s
, 255);
164 cleanup(s
, RETURN_FAIL
);
167 if (!WritePAR(buf
, size
))
169 cleanup("Error writing to (usb)parallel.device", RETURN_FAIL
);
172 } while (size
== BUFSIZE
);
176 /****************************************************************************************/