]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
2 * "$Id: testppd.c 6159 2006-12-19 20:08:42Z mike $"
4 * PPD test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry.
32 * Include necessary headers...
37 #include <cups/string.h>
52 static const char *default_code
=
54 "%%BeginFeature: *PageRegion Letter\n"
57 "} stopped cleartomark\n"
59 "%%BeginFeature: *InputSlot Tray\n"
62 "} stopped cleartomark\n"
64 "%%BeginFeature: *IntOption None\n"
66 "} stopped cleartomark\n"
68 "%%BeginFeature: *StringOption None\n"
70 "} stopped cleartomark\n";
72 static const char *custom_code
=
74 "%%BeginFeature: *CustomPageSize True\n"
82 "} stopped cleartomark\n"
84 "%%BeginFeature: *InputSlot Tray\n"
87 "} stopped cleartomark\n"
89 "%%BeginFeature: *IntOption None\n"
91 "} stopped cleartomark\n"
93 "%%BeginFeature: *StringOption None\n"
95 "} stopped cleartomark\n";
99 * 'main()' - Main entry.
102 int /* O - Exit status */
103 main(int argc
, /* I - Number of command-line arguments */
104 char *argv
[]) /* I - Command-line arguments */
106 ppd_file_t
*ppd
; /* PPD file loaded from disk */
107 int status
; /* Status of tests (0 = success, 1 = fail) */
108 int conflicts
; /* Number of conflicts */
109 char *s
; /* String */
116 fputs("ppdOpenFile: ", stdout
);
118 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
122 ppd_status_t err
; /* Last error in file */
123 int line
; /* Line number in file */
127 err
= ppdLastError(&line
);
129 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
132 fputs("ppdMarkDefaults: ", stdout
);
133 ppdMarkDefaults(ppd
);
135 if ((conflicts
= ppdConflicts(ppd
)) == 0)
140 printf("FAIL (%d conflicts)\n", conflicts
);
143 fputs("ppdEmitString (defaults): ", stdout
);
144 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
145 !strcmp(s
, default_code
))
149 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
150 (int)strlen(default_code
));
159 fputs("ppdEmitString (custom size): ", stdout
);
160 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
162 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
163 !strcmp(s
, custom_code
))
167 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
168 (int)strlen(custom_code
));
181 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
183 ppd_status_t err
; /* Last error in file */
184 int line
; /* Line number in file */
188 err
= ppdLastError(&line
);
190 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
194 int i
, j
, k
; /* Looping vars */
195 ppd_attr_t
*attr
; /* Current attribute */
196 ppd_group_t
*group
; /* Option group */
197 ppd_option_t
*option
; /* Option */
198 ppd_coption_t
*coption
; /* Custom option */
199 ppd_cparam_t
*cparam
; /* Custom parameter */
200 char lang
[255]; /* LANG environment variable */
205 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
211 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
215 printf("%s (%s):\n", group
->name
, group
->text
);
217 for (j
= group
->num_options
, option
= group
->options
;
221 printf(" %s (%s):\n", option
->keyword
, option
->text
);
223 for (k
= 0; k
< option
->num_choices
; k
++)
224 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
225 option
->choices
[k
].text
);
227 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
229 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
231 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
233 switch (cparam
->type
)
235 case PPD_CUSTOM_CURVE
:
236 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
237 cparam
->name
, cparam
->text
,
238 cparam
->minimum
.custom_curve
,
239 cparam
->maximum
.custom_curve
);
242 case PPD_CUSTOM_INT
:
243 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
244 cparam
->name
, cparam
->text
,
245 cparam
->minimum
.custom_int
,
246 cparam
->maximum
.custom_int
);
249 case PPD_CUSTOM_INVCURVE
:
250 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
251 cparam
->name
, cparam
->text
,
252 cparam
->minimum
.custom_invcurve
,
253 cparam
->maximum
.custom_invcurve
);
256 case PPD_CUSTOM_PASSCODE
:
257 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
258 cparam
->name
, cparam
->text
,
259 cparam
->minimum
.custom_passcode
,
260 cparam
->maximum
.custom_passcode
);
263 case PPD_CUSTOM_PASSWORD
:
264 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
265 cparam
->name
, cparam
->text
,
266 cparam
->minimum
.custom_password
,
267 cparam
->maximum
.custom_password
);
270 case PPD_CUSTOM_POINTS
:
271 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
272 cparam
->name
, cparam
->text
,
273 cparam
->minimum
.custom_points
,
274 cparam
->maximum
.custom_points
);
277 case PPD_CUSTOM_REAL
:
278 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
279 cparam
->name
, cparam
->text
,
280 cparam
->minimum
.custom_real
,
281 cparam
->maximum
.custom_real
);
284 case PPD_CUSTOM_STRING
:
285 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
286 cparam
->name
, cparam
->text
,
287 cparam
->minimum
.custom_string
,
288 cparam
->maximum
.custom_string
);
298 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
300 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
301 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
302 attr
->text
, attr
->value
? attr
->value
: "");
311 * End of "$Id: testppd.c 6159 2006-12-19 20:08:42Z mike $".