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