store the pre-alphacomposit hook and allow it to be queried.
[AROS.git] / workbench / devs / printer / prefs.c
blobc7bd32a99f7295597f0c87b47e899864b7b3b6c9
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
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
30 #else
31 #define GET_WORD(x) x
32 #define GET_LONG(x) x
33 #endif
35 /*********************************************************************************************/
37 #define PREFS_PATH_ENVARC "ENVARC:SYS/printer"
38 #define PREFS_PATH_ENV "ENV:SYS/printer"
40 /*********************************************************************************************/
42 struct FilePrefHeader
44 UBYTE ph_Version;
45 UBYTE ph_Type;
46 UBYTE ph_Flags[4];
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)
54 BOOL Printer_LoadPrefs(struct PrinterBase *PrinterBase, LONG unitnum, struct PrinterPrefs *prefs)
56 struct PrinterTxtPrefs txt = prefs->pp_Txt;
57 struct PrinterUnitPrefs unit = prefs->pp_Unit;
58 struct PrinterDeviceUnitPrefs devunit = prefs->pp_DeviceUnit;
59 struct PrinterGfxPrefs gfx = prefs->pp_Gfx;
60 BPTR fh;
61 TEXT envpath[64];
62 TEXT envarcpath[64];
64 struct IFFHandle *iff;
65 LONG chunk_map = 0;
66 LONG stop_chunks[] = {
67 ID_PREF, ID_PTXT,
68 ID_PREF, ID_PUNT,
69 ID_PREF, ID_PDEV,
70 ID_PREF, ID_PGFX,
73 AddPart(envpath, PREFS_PATH_ENV, sizeof(envpath));
74 AddPart(envarcpath, PREFS_PATH_ENVARC, sizeof(envarcpath));
75 if (unitnum) {
76 TEXT c[2] = { '0' + unitnum, 0 };
77 strncat(envpath, c, sizeof(envpath));
78 strncat(envarcpath, c, sizeof(envarcpath));
80 strncat(envpath, ".prefs", sizeof(envpath));
81 strncat(envarcpath, ".prefs", sizeof(envarcpath));
83 D(bug("%s: envpath \"%s\"\n", __func__, envpath));
84 D(bug("%s: envarcpath \"%s\"\n", __func__, envpath));
86 if (((fh = Open(envpath, MODE_OLDFILE)) == BNULL) &&
87 ((fh = Open(envarcpath, MODE_OLDFILE)) == BNULL))
88 return FALSE;
90 D(bug("LoadPrefs: Begin\n"));
92 if ((iff = AllocIFF()))
94 iff->iff_Stream = (IPTR)fh;
96 InitIFFasDOS(iff);
98 if (!OpenIFF(iff, IFFF_READ))
100 D(bug("LoadPrefs: OpenIFF okay.\n"));
102 if (!StopChunks(iff, stop_chunks, 4))
104 D(bug("LoadPrefs: StopChunks okay.\n"));
106 while (ParseIFF(iff, IFFPARSE_SCAN) == 0)
108 struct ContextNode *cn;
110 cn = CurrentChunk(iff);
112 D(bug("LoadPrefs: ParseIFF okay: 0x%04x 0x%04x\n", cn->cn_ID, cn->cn_Type));
114 if (cn->cn_ID == ID_PTXT && cn->cn_Size == sizeof(txt))
116 D(bug("LoadPrefs: ID_PTXT chunk size okay.\n"));
117 if (ReadChunkBytes(iff, &txt, sizeof(txt)) == sizeof(txt))
119 D(bug("LoadPrefs: Reading chunk successful.\n"));
121 chunk_map |= (1 << 0);
124 if (cn->cn_ID == ID_PUNT && cn->cn_Size == sizeof(unit))
126 D(bug("LoadPrefs: ID_PUNT chunk size okay.\n"));
127 if (ReadChunkBytes(iff, &unit, sizeof(unit)) == sizeof(unit))
129 D(bug("LoadPrefs: Reading chunk successful.\n"));
131 chunk_map |= (1 << 1);
134 if (cn->cn_ID == ID_PDEV && cn->cn_Size == sizeof(devunit))
136 D(bug("LoadPrefs: ID_PDEV chunk size okay.\n"));
137 if (ReadChunkBytes(iff, &devunit, sizeof(devunit)) == sizeof(devunit))
139 D(bug("LoadPrefs: Reading chunk successful.\n"));
141 chunk_map |= (1 << 2);
144 if (cn->cn_ID == ID_PGFX && cn->cn_Size == sizeof(gfx))
146 D(bug("LoadPrefs: ID_PGFX chunk size okay.\n"));
147 if (ReadChunkBytes(iff, &gfx, sizeof(gfx)) == sizeof(gfx))
149 D(bug("LoadPrefs: Reading chunk successful.\n"));
151 chunk_map |= (1 << 3);
156 CloseIFF(iff);
158 FreeIFF(iff);
160 Close(fh);
162 if (chunk_map & (1 << 0)) {
163 D(bug("LoadPrefs: PTXT\n"));
165 IMPORT_WORD(txt.pt_PaperType);
166 IMPORT_WORD(txt.pt_PaperSize);
167 IMPORT_WORD(txt.pt_PaperLength);
168 IMPORT_WORD(txt.pt_Pitch);
169 IMPORT_WORD(txt.pt_Spacing);
170 IMPORT_WORD(txt.pt_LeftMargin);
171 IMPORT_WORD(txt.pt_RightMargin);
172 IMPORT_WORD(txt.pt_Quality);
173 prefs->pp_Txt = txt;
176 if (chunk_map & (1 << 1)) {
177 D(bug("LoadPrefs: PUNT\n"));
179 IMPORT_LONG(unit.pu_UnitNum);
180 IMPORT_LONG(unit.pu_OpenDeviceFlags);
181 prefs->pp_Unit = unit;
184 if (chunk_map & (1 << 2)) {
185 D(bug("LoadPrefs: PDEV\n"));
187 IMPORT_LONG(devunit.pd_UnitNum);
188 prefs->pp_DeviceUnit = devunit;
191 if (chunk_map & (1 << 3)) {
192 D(bug("LoadPrefs: PGFX\n"));
194 IMPORT_WORD(gfx.pg_Aspect);
195 IMPORT_WORD(gfx.pg_Shade);
196 IMPORT_WORD(gfx.pg_Image);
197 IMPORT_WORD(gfx.pg_Threshold);
198 IMPORT_WORD(gfx.pg_GraphicFlags);
199 IMPORT_WORD(gfx.pg_PrintMaxWidth);
200 IMPORT_WORD(gfx.pg_PrintMaxHeight);
202 prefs->pp_Gfx = gfx;
205 D(bug("LoadPrefs: Done\n"));
206 return (chunk_map & (1 << 0)) ? TRUE : FALSE;