2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Copy file to parallel.device
8 /*****************************************************************************
24 Copies (or sends a) file to parallel.device.
28 FILE -- Either a file, a directory or a pattern to match.
30 QUIET -- Suppresses any output to the shell.
34 Standard DOS return codes.
42 ******************************************************************************/
45 #include <devices/parallel.h>
46 #include <proto/exec.h>
47 #include <proto/dos.h>
52 /****************************************************************************************/
54 #define ARG_TEMPLATE "FILE/A,QUIET/S"
61 /****************************************************************************************/
63 struct MsgPort
*ParMP
;
64 struct IOStdReq
*ParIO
;
67 struct RDArgs
*myargs
;
72 /****************************************************************************************/
74 static void cleanup(char *msg
, ULONG retcode
)
76 if (msg
&& !args
[ARG_QUIET
])
78 fprintf(stderr
, "CopyToPAR: %s\n", msg
);
82 if (myargs
) FreeArgs(myargs
);
84 if (ParOpen
) CloseDevice((struct IORequest
*)ParIO
);
85 if (ParIO
) DeleteIORequest((struct IORequest
*)ParIO
);
86 if (ParMP
) DeleteMsgPort(ParMP
);
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
);
120 /****************************************************************************************/
122 static void openfile(void)
124 fh
= Open((STRPTR
)args
[ARG_FILE
], MODE_OLDFILE
);
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)
151 size
= Read(fh
, buf
, BUFSIZE
);
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 /****************************************************************************************/