use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / iprefs / printerprefs.c
blob4a9b553fc5a5c679405d4aaed7cc2961ba5fb765
1 /*
2 Copyright © 1995-2019, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #define DEBUG 0
14 #include <aros/debug.h>
15 #include <aros/macros.h>
16 #include <datatypes/pictureclass.h>
17 #include <prefs/prefhdr.h>
18 #include <prefs/printertxt.h>
19 #include <prefs/printergfx.h>
21 #include <intuition/iprefs.h>
22 #include <proto/datatypes.h>
24 #define DEV_EXT_LEN 7
26 /*********************************************************************************************/
28 static LONG stopchunks[] =
30 ID_PREF, ID_PTXT,
31 ID_PREF, ID_PGFX
34 void PrinterPrefs_Handler(STRPTR filename)
36 struct IFFHandle *iff;
37 struct PrinterTxtPrefs *ptp;
38 struct PrinterGfxPrefs *pgp;
39 char *devname;
40 ULONG devnamelen;
41 BOOL name_too_long = FALSE;
43 D(bug("[PrinterPrefs] filename=%s\n", filename));
45 iff = CreateIFF(filename, stopchunks, 2);
46 if (iff)
48 struct Preferences prefs;
49 GetPrefs(&prefs, sizeof(prefs));
51 while(ParseIFF(iff, IFFPARSE_SCAN) == 0)
53 struct ContextNode *cn = CurrentChunk(iff);
54 switch(cn->cn_ID)
56 case ID_PTXT:
57 ptp = LoadChunk(iff, sizeof(struct PrinterTxtPrefs), MEMF_ANY);
58 if (ptp)
60 devname = FilePart(ptp->pt_Driver);
61 devnamelen = strlen(devname);
62 if (devnamelen < DEVNAME_SIZE + DEV_EXT_LEN)
64 if (devnamelen >= DEV_EXT_LEN && !strcmp(
65 &devname[devnamelen - DEV_EXT_LEN], ".device"))
67 CopyMem(devname, prefs.PrtDevName, devnamelen - DEV_EXT_LEN);
68 prefs.PrtDevName[devnamelen - DEV_EXT_LEN] = '0';
70 else if (devnamelen < DEVNAME_SIZE)
72 strncpy(prefs.PrtDevName, devname, sizeof(prefs.PrtDevName) - 1);
74 else
75 name_too_long = TRUE;
77 else
78 name_too_long = TRUE;
80 if (name_too_long)
81 bug("[IPREFS] ERROR: printer device name (%s) "
82 "is too long!", devname);
84 prefs.PrinterPort = ptp->pt_Port;
85 prefs.PaperType = AROS_BE2WORD(ptp->pt_PaperType);
86 prefs.PaperSize = AROS_BE2WORD(ptp->pt_PaperSize);
87 prefs.PaperLength = AROS_BE2WORD(ptp->pt_PaperLength);
88 prefs.PrintPitch = AROS_BE2WORD(ptp->pt_Pitch);
89 prefs.PrintSpacing = AROS_BE2WORD(ptp->pt_Spacing);
90 prefs.PrintLeftMargin = AROS_BE2WORD(ptp->pt_LeftMargin);
91 prefs.PrintRightMargin = AROS_BE2WORD(ptp->pt_RightMargin);
92 prefs.PrintQuality = AROS_BE2WORD(ptp->pt_Quality);
94 FreeVec(ptp);
96 break;
97 case ID_PGFX:
98 pgp = LoadChunk(iff, sizeof(struct PrinterGfxPrefs), MEMF_ANY);
99 if (pgp)
101 prefs.PrintAspect = AROS_BE2WORD(pgp->pg_Aspect);
102 prefs.PrintShade = AROS_BE2WORD(pgp->pg_Shade);
103 prefs.PrintImage = AROS_BE2WORD(pgp->pg_Image);
104 prefs.PrintThreshold = AROS_BE2WORD(pgp->pg_Threshold);
105 //prefs.ColorCorrect = pgp->pg_ColorCorrect;
106 //prefs.Dimensions = pgp->pg_Dimensions;
107 //prefs.Dithering = pgp->pg_Dithering;
108 //prefs.GraphicFlags = AROS_BE2WORD(pgp->pg_GraphicFlags);
109 prefs.PrintDensity = pgp->pg_PrintDensity;
110 prefs.PrintMaxWidth = AROS_BE2WORD(pgp->pg_PrintMaxWidth);
111 prefs.PrintMaxHeight = AROS_BE2WORD(pgp->pg_PrintMaxHeight);
112 prefs.PrintXOffset = pgp->pg_PrintXOffset;
113 //prefs.PrintYOffset = pgp->pg_PrintYOffset;
115 FreeVec(pgp);
117 break;
120 KillIFF(iff);
121 SetPrefs(&prefs, sizeof(prefs), TRUE);