2 Copyright © 2013-2014, The AROS Development Team. All rights reserved.
9 /******************************************************************************
26 Print a file, using datatypes.library
30 FILE f -- Filename to print
31 PRTUNIT n -- Printer unit
35 Files will be printed to the specified printer unit
49 ******************************************************************************/
52 #include <aros/debug.h>
54 #include <exec/memory.h>
55 #include <proto/exec.h>
56 #include <proto/dos.h>
57 #include <proto/alib.h>
58 #include <proto/datatypes.h>
60 #include <datatypes/datatypesclass.h>
61 #include <datatypes/pictureclass.h>
63 #include <aros/shcommands.h>
65 static inline BOOL
isPrintable(struct Library
*DataTypesBase
, Object
*obj
)
69 for (dtm
= GetDTMethods(obj
); (SIPTR
)dtm
!= -1; dtm
++) {
70 if (*dtm
== DTM_PRINT
)
77 ULONG
doPrinting(struct ExecBase
*SysBase
, struct Library
*DataTypesBase
, Object
*dto
, int unit
)
81 struct IORequest
*pio
;
82 ULONG retval
= PDERR_CANCEL
;
83 struct Process
*pr
= (struct Process
*)FindTask(NULL
);
85 if ((mp
= CreateMsgPort())) {
86 if ((pio
= CreateIORequest(mp
, sizeof(union printerIO
)))) {
87 if (0 == OpenDevice("printer.device", unit
, pio
, 0)) {
88 msg
.MethodID
= DTM_PRINT
;
90 msg
.dtp_PIO
= (union printerIO
*)pio
;
91 msg
.dtp_AttrList
= NULL
;
93 retval
= DoDTMethodA(dto
, pr
->pr_WindowPtr
, NULL
, (Msg
)&msg
);
112 AROS_SH2H(Print
, 44.1, "Print a file using DataTypes\n",
113 AROS_SHAH(LONG
* , ,PRTUNIT
,/K
/N
, 0 , "Printer unit\n"),
114 AROS_SHAH(STRPTR
*, ,FILES
,/M
, NULL
, "File(s) to print\n"))
118 LONG result
= RETURN_FAIL
;
119 struct Library
*DataTypesBase
;
120 STRPTR
*files
= SHArg(FILES
);
121 LONG unit
= SHArg(PRTUNIT
) ? *SHArg(PRTUNIT
) : 0;
125 if ((DataTypesBase
= OpenLibrary("datatypes.library", 0))) {
128 for (; *files
; files
++) {
129 STRPTR file
= *files
;
130 if ((o
= NewDTObject(file
, PDTA_Remap
, FALSE
, TAG_END
))) {
131 if (isPrintable(DataTypesBase
, o
)) {
132 err
= doPrinting(SysBase
, DataTypesBase
, o
, unit
);
134 Printf("Can't print \"%s\": Printer Error %d\n", file
, err
);
135 result
= RETURN_FAIL
;
138 Printf("\"%s\" is not a DataType printable file\n", file
);
139 result
= RETURN_FAIL
;
143 Printf("Can't open %s as a DataType object\n", file
);
146 CloseLibrary(DataTypesBase
);
148 Printf("Can't open datatypes.library\n");
151 /* No file supplied - quiet success */