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