1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
//
// PPD to HTML utility for the CUPS PPD Compiler.
//
// Copyright 2007-2015 by Apple Inc.
// Copyright 2002-2005 by Easy Software Products.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more information.
//
//
// Include necessary headers...
//
#include "ppdc-private.h"
#include <sys/stat.h>
#include <sys/types.h>
//
// Local functions...
//
static void usage(void) _CUPS_NORETURN;
//
// 'main()' - Main entry for the PPD compiler.
//
int // O - Exit status
main(int argc, // I - Number of command-line arguments
char *argv[]) // I - Command-line arguments
{
int i; // Looping var
ppdcSource *src; // PPD source file data
ppdcDriver *d; // Current driver
ppdcGroup *g, // Current group
*composite; // Composite of all drivers
ppdcOption *o, // Current option
*compo; // Composite option
ppdcChoice *c; // Current choice
char *opt; // Current option char
ppdcMediaSize *size; // Current media size
char *value; // Value in option
_cupsSetLocale(argv);
// Scan the command-line...
src = new ppdcSource();
for (i = 1; i < argc; i ++)
if (argv[i][0] == '-')
{
for (opt = argv[i] + 1; *opt; opt ++)
switch (*opt)
{
case 'D' : // Define variable
i ++;
if (i >= argc)
usage();
if ((value = strchr(argv[i], '=')) != NULL)
{
*value++ = '\0';
src->set_variable(argv[i], value);
}
else
src->set_variable(argv[i], "1");
break;
case 'I' : // Include directory...
i ++;
if (i >= argc)
usage();
ppdcSource::add_include(argv[i]);
break;
default : // Unknown
usage();
break;
}
}
else
{
// Open and load the driver info file...
src->read_file(argv[i]);
}
if ((d = (ppdcDriver *)src->drivers->first()) != NULL)
{
// Create a composite group with all of the features from the
// drivers in the info file...
composite = new ppdcGroup("", "");
while (d != NULL)
{
for (g = (ppdcGroup *)d->groups->first(); g; g = (ppdcGroup *)d->groups->next())
for (o = (ppdcOption *)g->options->first(); o; o = (ppdcOption *)g->options->next())
{
if ((compo = composite->find_option(o->name->value)) == NULL)
composite->add_option(new ppdcOption(o));
}
d = (ppdcDriver *)src->drivers->next();
}
puts("<html>");
printf("<head><title>Driver Summary for %s</title></head>\n", argv[i]);
printf("<body><h1>Driver Summary for %s</h1>\n", argv[i]);
printf("<p><table border='1'><thead><tr><th>Printer</th><th>Media Size</th>");
for (compo = (ppdcOption *)composite->options->first(); compo; compo = (ppdcOption *)composite->options->next())
printf("<th>%s</th>", compo->text->value);
puts("</tr></thead><tbody>");
// Write HTML summary...
for (d = (ppdcDriver *)src->drivers->first(); d; d = (ppdcDriver *)src->drivers->next())
{
// Write the summary for this driver...
printf("<tr valign='top'><td nowrap>%s</td><td nowrap>", d->model_name->value);
for (size = (ppdcMediaSize *)d->sizes->first(); size;
size = (ppdcMediaSize *)d->sizes->next())
printf("%s<br>", size->text->value);
printf("</td>");
for (compo = (ppdcOption *)composite->options->first(); compo;
compo = (ppdcOption *)composite->options->next())
if ((o = d->find_option(compo->name->value)) != NULL)
{
printf("<td nowrap>");
for (c = (ppdcChoice *)o->choices->first(); c;
c = (ppdcChoice *)o->choices->next())
printf("%s<br>", c->text->value);
printf("</td>");
}
else
printf("<td>N/A</td>");
puts("</tr>");
}
puts("</tbody></table></p>");
puts("</body>");
puts("</html>");
// Delete the printer driver information...
composite->release();
}
else
{
// If no drivers have been loaded, display the program usage message.
usage();
}
src->release();
// Return with no errors.
return (0);
}
//
// 'usage()' - Show usage and exit.
//
static void
usage(void)
{
_cupsLangPuts(stdout, _("Usage: ppdhtml [options] filename.drv "
">filename.html"));
_cupsLangPuts(stdout, _("Options:"));
_cupsLangPuts(stdout, _(" -D name=value Set named variable to "
"value."));
_cupsLangPuts(stdout, _(" -I include-dir Add include directory "
"to search path."));
exit(1);
}
|