]>
Commit | Line | Data |
---|---|---|
ac884b6a MS |
1 | // |
2 | // "$Id$" | |
3 | // | |
4 | // PPD to HTML utility for the CUPS PPD Compiler. | |
5 | // | |
6 | // Copyright 2007 by Apple Inc. | |
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 | ||
25 | #include "ppdc.h" | |
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 | |
55 | ||
56 | ||
57 | // Scan the command-line... | |
58 | src = 0; | |
59 | ||
60 | for (i = 1; i < argc; i ++) | |
61 | if (argv[i][0] == '-') | |
62 | { | |
63 | for (opt = argv[i] + 1; *opt; opt ++) | |
64 | switch (*opt) | |
65 | { | |
66 | case 'I' : // Include directory... | |
67 | i ++; | |
68 | if (i >= argc) | |
69 | usage(); | |
70 | ||
71 | ppdcSource::add_include(argv[i]); | |
72 | break; | |
73 | ||
74 | default : // Unknown | |
75 | usage(); | |
76 | break; | |
77 | } | |
78 | } | |
79 | else | |
80 | { | |
81 | // Open and load the driver info file... | |
82 | src = new ppdcSource(argv[i]); | |
83 | ||
84 | // Create a composite group with all of the features from the | |
85 | // drivers in the info file... | |
86 | composite = new ppdcGroup("", ""); | |
87 | ||
88 | for (d = (ppdcDriver *)src->drivers->first(); d; d = (ppdcDriver *)src->drivers->next()) | |
89 | for (g = (ppdcGroup *)d->groups->first(); g; g = (ppdcGroup *)d->groups->next()) | |
90 | for (o = (ppdcOption *)g->options->first(); o; o = (ppdcOption *)g->options->next()) | |
91 | { | |
92 | if ((compo = composite->find_option(o->name->value)) == NULL) | |
93 | composite->add_option(new ppdcOption(o)); | |
94 | } | |
95 | ||
96 | puts("<html>"); | |
97 | printf("<head><title>Driver Summary for %s</title></head>\n", argv[i]); | |
98 | printf("<body><h1>Driver Summary for %s</h1>\n", argv[i]); | |
99 | printf("<p><table border='1'><thead><tr><th>Printer</th><th>Media Size</th>"); | |
100 | for (compo = (ppdcOption *)composite->options->first(); compo; compo = (ppdcOption *)composite->options->next()) | |
101 | printf("<th>%s</th>", compo->text->value); | |
102 | puts("</tr></thead><tbody>"); | |
103 | ||
104 | // Write HTML summary... | |
105 | for (d = (ppdcDriver *)src->drivers->first(); d; d = (ppdcDriver *)src->drivers->next()) | |
106 | { | |
107 | // Write the summary for this driver... | |
108 | printf("<tr valign='top'><td nowrap>%s</td><td nowrap>", d->model_name->value); | |
109 | for (size = (ppdcMediaSize *)d->sizes->first(); size; | |
110 | size = (ppdcMediaSize *)d->sizes->next()) | |
111 | printf("%s<br>", size->text->value); | |
112 | printf("</td>"); | |
113 | ||
114 | for (compo = (ppdcOption *)composite->options->first(); compo; | |
115 | compo = (ppdcOption *)composite->options->next()) | |
116 | if ((o = d->find_option(compo->name->value)) != NULL) | |
117 | { | |
118 | printf("<td nowrap>"); | |
119 | for (c = (ppdcChoice *)o->choices->first(); c; | |
120 | c = (ppdcChoice *)o->choices->next()) | |
121 | printf("%s<br>", c->text->value); | |
122 | printf("</td>"); | |
123 | } | |
124 | else | |
125 | printf("<td>N/A</td>"); | |
126 | ||
127 | puts("</tr>"); | |
128 | } | |
129 | ||
130 | puts("</tbody></table></p>"); | |
131 | puts("</body>"); | |
132 | puts("</html>"); | |
133 | // Delete the printer driver information... | |
134 | delete composite; | |
135 | delete src; | |
136 | } | |
137 | ||
138 | // If no drivers have been loaded, display the program usage message. | |
139 | if (!src) | |
140 | usage(); | |
141 | ||
142 | // Return with no errors. | |
143 | return (0); | |
144 | } | |
145 | ||
146 | ||
147 | // | |
148 | // 'usage()' - Show usage and exit. | |
149 | // | |
150 | ||
151 | static void | |
152 | usage(void) | |
153 | { | |
154 | puts("Usage: ppdhtml [options] filename.drv >filename.html"); | |
155 | puts("Options:"); | |
156 | puts(" -I include-dir Add include directory to search path."); | |
157 | ||
158 | exit(1); | |
159 | } | |
160 | ||
161 | ||
162 | // | |
163 | // End of "$Id$". | |
164 | // |