2 Copyright © 2012, The AROS Development Team. All rights reserved.
9 /******************************************************************************
17 QUIET/S,UNIT/K/N,FILE/S
25 Print a file, using datatypes.library
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
37 Unless QUIET, print out when a print job has been completed:
39 [<filename> printed on printer.device <n>]
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>
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") )
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
);
83 if ((DataTypesBase
= OpenLibrary("datatypes.library", 0))) {
85 if ((o
= NewDTObject(file
, TAG_END
))) {
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
;
94 msg
.dtp_PIO
= (union printerIO
*)io
;
95 msg
.dtp_AttrList
= NULL
;
96 if (0 == DoDTMethodA(o
, NULL
, NULL
, (Msg
)&msg
)) {
98 Printf("[%s printed to printer.device %ld]\n", file
, unit
);
102 Printf("[%s failed to print to printer.device %ld]\n", file
, unit
);
103 SetIoErr(RETURN_FAIL
);
107 Printf("Can't open printer.device %ld\n", unit
);
111 Printf("Can't create IO request\n");
115 Printf("Can't create message port\n");
119 Printf("Can't open %s as a DataType object\n", file
);
121 CloseLibrary(DataTypesBase
);
123 Printf("Can't open datatypes.library\n");
126 /* No file supplied - quiet success */