2 Copyright © 2013, The AROS Development Team. All rights reserved.
9 /******************************************************************************
26 Print a file, using datatypes.library
30 FILE f -- Filename to play
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.0, "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 struct Library
*DataTypesBase
;
119 STRPTR
*files
= SHArg(FILES
);
120 LONG unit
= SHArg(PRTUNIT
) ? *SHArg(PRTUNIT
) : 0;
123 SetIoErr(RETURN_FAIL
);
126 if ((DataTypesBase
= OpenLibrary("datatypes.library", 0))) {
129 for (; *files
; files
++) {
130 STRPTR file
= *files
;
131 if ((o
= NewDTObject(file
, PDTA_Remap
, FALSE
, TAG_END
))) {
132 if (isPrintable(DataTypesBase
, o
)) {
133 err
= doPrinting(SysBase
, DataTypesBase
, o
, unit
);
135 Printf("Can't print \"%s\": Printer Error %d\n", file
, err
);
136 SetIoErr(RETURN_FAIL
);
139 Printf("\"%s\" is not a DataType printable file\n", file
);
140 SetIoErr(RETURN_FAIL
);
144 Printf("Can't open %s as a DataType object\n", file
);
147 CloseLibrary(DataTypesBase
);
149 Printf("Can't open datatypes.library\n");
152 /* No file supplied - quiet success */