C:Print - Print using datatypes.library
[AROS.git] / workbench / c / Print.c
blob10679656a1d5afe75ed7ecc706a02086d9815b46
1 /*
2 Copyright © 2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 Print
15 SYNOPSIS
17 QUIET/S,UNIT/K/N,FILE/S
19 LOCATION
23 FUNCTION
25 Print a file, using datatypes.library
27 INPUTS
29 QUIET -- Don't indicate when the print is complete
31 UNIT=n -- printer.device unit to print to
33 FILE f -- Filename to print
35 RESULT
37 Unless QUIET, print out when a print job has been completed:
39 [<filename> printed on printer.device <n>]
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 HISTORY
54 ******************************************************************************/
56 #include <exec/memory.h>
57 #include <datatypes/datatypesclass.h>
58 #include <proto/exec.h>
59 #include <proto/dos.h>
60 #include <proto/alib.h>
61 #include <proto/datatypes.h>
63 #define DEBUG 0
64 #include <aros/debug.h>
66 #include <aros/shcommands.h>
68 AROS_SH3H(Print, 44.0, "Print a file using DataTypes\n",
69 AROS_SHAH(BOOL , ,QUIET ,/S,FALSE, "Don't say when the print is complete"),
70 AROS_SHAH(ULONG *, ,UNIT ,/N/K,NULL, "Select the printer.device unit (default 0)"),
71 AROS_SHAH(STRPTR, ,FILE , ,NULL , "File to print\n") )
73 AROS_SHCOMMAND_INIT
75 struct Library *DataTypesBase;
76 BOOL quiet = SHArg(QUIET);
77 ULONG unit = (SHArg(UNIT) ? *SHArg(UNIT) : 0);
78 STRPTR file = SHArg(FILE);
80 SetIoErr(RETURN_FAIL);
82 if (file != NULL) {
83 if ((DataTypesBase = OpenLibrary("datatypes.library", 0))) {
84 Object *o;
85 if ((o = NewDTObject(file, TAG_END))) {
86 struct dtPrint msg;
87 struct MsgPort *mp;
88 struct IORequest *io;
89 if ((mp = CreateMsgPort())) {
90 if ((io = CreateIORequest(mp, sizeof(union printerIO)))) {
91 if (0 == OpenDevice("printer.device", unit, io, 0)) {
92 msg.MethodID = DTM_PRINT;
93 msg.dtp_GInfo = NULL;
94 msg.dtp_PIO = (union printerIO *)io;
95 msg.dtp_AttrList = NULL;
96 if (0 == DoDTMethodA(o, NULL, NULL, (Msg)&msg)) {
97 if (!quiet)
98 Printf("[%s printed to printer.device %ld]\n", file, unit);
99 SetIoErr(0);
100 } else {
101 if (!quiet)
102 Printf("[%s failed to print to printer.device %ld]\n", file, unit);
103 SetIoErr(RETURN_FAIL);
105 CloseDevice(io);
106 } else {
107 Printf("Can't open printer.device %ld\n", unit);
109 DeleteIORequest(io);
110 } else {
111 Printf("Can't create IO request\n");
113 DeleteMsgPort(mp);
114 } else {
115 Printf("Can't create message port\n");
117 DisposeDTObject(o);
118 } else {
119 Printf("Can't open %s as a DataType object\n", file);
121 CloseLibrary(DataTypesBase);
122 } else {
123 Printf("Can't open datatypes.library\n");
125 } else {
126 /* No file supplied - quiet success */
127 SetIoErr(0);
130 return IoErr();
132 AROS_SHCOMMAND_EXIT