grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / tools / InitPrinter.c
blob567404ba958a789943bd1900640140a936c68f09
1 /*
2 Copyright © 2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <devices/printer.h>
7 #include <dos/dos.h>
9 #include <proto/dos.h>
10 #include <proto/exec.h>
12 //#define DEBUG 1
13 #include <aros/debug.h>
15 const char version[] = "$VER: InitPrinter 1.0 (03.03.2012) © AROS Dev Team";
17 char __stdiowin[]="CON:/30/400/100/InitPrinter/AUTO/CLOSE/WAIT";
19 enum
21 ARG_UNIT,
22 ARG_COUNT
25 static BOOL init_printer(ULONG unit)
27 struct MsgPort *PrintMP;
28 struct IOPrtCmdReq *PrintIO;
29 BOOL success = FALSE;
31 if ((PrintMP = CreateMsgPort()))
33 if ((PrintIO = CreateIORequest(PrintMP, sizeof(struct IOPrtCmdReq))))
35 if (OpenDevice("printer.device", unit, (struct IORequest *)PrintIO, 0))
37 PutStr("Error: printer.device did not open\n");
39 else
41 D(bug("[InitPrinter] unit %d request %p msgport %p\n", unit, PrintIO, PrintMP));
42 PrintIO->io_PrtCommand = aRIN; // Initialize
43 PrintIO->io_Parm0 = 0;
44 PrintIO->io_Parm1 = 0;
45 PrintIO->io_Parm2 = 0;
46 PrintIO->io_Parm3 = 0;
47 PrintIO->io_Command = PRD_PRTCOMMAND;
49 if (DoIO((struct IORequest *)PrintIO))
51 Printf("Printer reset failed. Error: %d\n", (IPTR)PrintIO->io_Error);
53 else
55 success = TRUE;
57 CloseDevice((struct IORequest *)PrintIO);
59 DeleteIORequest(PrintIO);
61 else
63 PutStr("Error: Could not create I/O request\n");
65 DeleteMsgPort(PrintMP);
67 else
69 PutStr("Error: Could not create message port\n");
71 return success;
75 int main(void)
77 struct RDArgs *rda;
78 IPTR args[ARG_COUNT] = {0};
79 ULONG unit = 0;
80 ULONG retval = RETURN_ERROR;
82 if ((rda = ReadArgs("UNIT/N", args, NULL)))
84 if (args[ARG_UNIT])
86 unit = *(LONG *)args[ARG_UNIT];
88 if (init_printer(unit))
90 retval = RETURN_OK;
92 FreeArgs(rda);
94 else
96 PutStr("Error: Could not read arguments\n");
99 return retval;