2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
15 #include <aros/macros.h>
17 #include <aros/debug.h>
19 #include <proto/exec.h>
20 #include <proto/iffparse.h>
21 #include <proto/dos.h>
23 #include <prefs/prefhdr.h>
25 #include "printer_intern.h"
27 #ifdef BIGENDIAN_PREFS
28 #define GET_WORD AROS_BE2WORD
29 #define GET_LONG AROS_BE2LONG
35 /*********************************************************************************************/
37 #define PREFS_PATH_ENVARC "ENVARC:SYS/printer"
38 #define PREFS_PATH_ENV "ENV:SYS/printer"
40 /*********************************************************************************************/
49 /*********************************************************************************************/
51 #define IMPORT_WORD(x) do { x = AROS_BE2WORD(x); } while (0)
52 #define IMPORT_LONG(x) do { x = AROS_BE2LONG(x); } while (0)
55 #define EXTMAX 7 /* ".prefs" + 1 for unit num */
57 BOOL
Printer_LoadPrefs(struct PrinterBase
*PrinterBase
, LONG unitnum
, struct PrinterPrefs
*prefs
)
59 struct PrinterTxtPrefs txt
= prefs
->pp_Txt
;
60 struct PrinterUnitPrefs unit
= prefs
->pp_Unit
;
61 struct PrinterDeviceUnitPrefs devunit
= prefs
->pp_DeviceUnit
;
62 struct PrinterGfxPrefs gfx
= prefs
->pp_Gfx
;
64 TEXT envpath
[PATHMAX
+ 1];
65 TEXT envarcpath
[PATHMAX
+ 1];
67 struct IFFHandle
*iff
;
69 LONG stop_chunks
[] = {
76 AddPart(envpath
, PREFS_PATH_ENV
, PATHMAX
- EXTMAX
+ 1);
77 AddPart(envarcpath
, PREFS_PATH_ENVARC
, PATHMAX
- EXTMAX
+ 1);
79 TEXT c
[2] = { '0' + unitnum
, 0 };
81 strcat(envarcpath
, c
);
83 strcat(envpath
, ".prefs");
84 strcat(envarcpath
, ".prefs");
86 D(bug("%s: envpath \"%s\"\n", __func__
, envpath
));
87 D(bug("%s: envarcpath \"%s\"\n", __func__
, envarcpath
));
89 if (((fh
= Open(envpath
, MODE_OLDFILE
)) == BNULL
) &&
90 ((fh
= Open(envarcpath
, MODE_OLDFILE
)) == BNULL
))
93 D(bug("LoadPrefs: Begin\n"));
95 if ((iff
= AllocIFF()))
97 iff
->iff_Stream
= (IPTR
)fh
;
101 if (!OpenIFF(iff
, IFFF_READ
))
103 D(bug("LoadPrefs: OpenIFF okay.\n"));
105 if (!StopChunks(iff
, stop_chunks
, 4))
107 D(bug("LoadPrefs: StopChunks okay.\n"));
109 while (ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
111 struct ContextNode
*cn
;
113 cn
= CurrentChunk(iff
);
115 D(bug("LoadPrefs: ParseIFF okay: 0x%04x 0x%04x\n", cn
->cn_ID
, cn
->cn_Type
));
117 if (cn
->cn_ID
== ID_PTXT
&& cn
->cn_Size
== sizeof(txt
))
119 D(bug("LoadPrefs: ID_PTXT chunk size okay.\n"));
120 if (ReadChunkBytes(iff
, &txt
, sizeof(txt
)) == sizeof(txt
))
122 D(bug("LoadPrefs: Reading chunk successful.\n"));
124 chunk_map
|= (1 << 0);
127 if (cn
->cn_ID
== ID_PUNT
&& cn
->cn_Size
== sizeof(unit
))
129 D(bug("LoadPrefs: ID_PUNT chunk size okay.\n"));
130 if (ReadChunkBytes(iff
, &unit
, sizeof(unit
)) == sizeof(unit
))
132 D(bug("LoadPrefs: Reading chunk successful.\n"));
134 chunk_map
|= (1 << 1);
137 if (cn
->cn_ID
== ID_PDEV
&& cn
->cn_Size
== sizeof(devunit
))
139 D(bug("LoadPrefs: ID_PDEV chunk size okay.\n"));
140 if (ReadChunkBytes(iff
, &devunit
, sizeof(devunit
)) == sizeof(devunit
))
142 D(bug("LoadPrefs: Reading chunk successful.\n"));
144 chunk_map
|= (1 << 2);
147 if (cn
->cn_ID
== ID_PGFX
&& cn
->cn_Size
== sizeof(gfx
))
149 D(bug("LoadPrefs: ID_PGFX chunk size okay.\n"));
150 if (ReadChunkBytes(iff
, &gfx
, sizeof(gfx
)) == sizeof(gfx
))
152 D(bug("LoadPrefs: Reading chunk successful.\n"));
154 chunk_map
|= (1 << 3);
165 if (chunk_map
& (1 << 0)) {
166 D(bug("LoadPrefs: PTXT\n"));
168 IMPORT_WORD(txt
.pt_PaperType
);
169 IMPORT_WORD(txt
.pt_PaperSize
);
170 IMPORT_WORD(txt
.pt_PaperLength
);
171 IMPORT_WORD(txt
.pt_Pitch
);
172 IMPORT_WORD(txt
.pt_Spacing
);
173 IMPORT_WORD(txt
.pt_LeftMargin
);
174 IMPORT_WORD(txt
.pt_RightMargin
);
175 IMPORT_WORD(txt
.pt_Quality
);
179 if (chunk_map
& (1 << 1)) {
180 D(bug("LoadPrefs: PUNT\n"));
182 IMPORT_LONG(unit
.pu_UnitNum
);
183 IMPORT_LONG(unit
.pu_OpenDeviceFlags
);
184 prefs
->pp_Unit
= unit
;
187 if (chunk_map
& (1 << 2)) {
188 D(bug("LoadPrefs: PDEV\n"));
190 IMPORT_LONG(devunit
.pd_UnitNum
);
191 prefs
->pp_DeviceUnit
= devunit
;
194 if (chunk_map
& (1 << 3)) {
195 D(bug("LoadPrefs: PGFX\n"));
197 IMPORT_WORD(gfx
.pg_Aspect
);
198 IMPORT_WORD(gfx
.pg_Shade
);
199 IMPORT_WORD(gfx
.pg_Image
);
200 IMPORT_WORD(gfx
.pg_Threshold
);
201 IMPORT_WORD(gfx
.pg_GraphicFlags
);
202 IMPORT_WORD(gfx
.pg_PrintMaxWidth
);
203 IMPORT_WORD(gfx
.pg_PrintMaxHeight
);
208 D(bug("LoadPrefs: Done\n"));
209 return (chunk_map
& (1 << 0)) ? TRUE
: FALSE
;