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