]> git.ipfire.org Git - thirdparty/cups.git/blame - ppdc/ppdhtml.cxx
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / ppdc / ppdhtml.cxx
CommitLineData
ac884b6a 1//
d25e43cf 2// PPD to HTML utility for the CUPS PPD Compiler.
ac884b6a 3//
d25e43cf
MS
4// Copyright 2007-2015 by Apple Inc.
5// Copyright 2002-2005 by Easy Software Products.
ac884b6a 6//
d25e43cf
MS
7// These coded instructions, statements, and computer programs are the
8// property of Apple Inc. and are protected by Federal copyright
9// law. Distribution and use rights are outlined in the file "LICENSE.txt"
10// which should have been included with this file. If this file is
57b7b66b 11// missing or damaged, see the license at "http://www.cups.org/".
ac884b6a
MS
12//
13
14//
15// Include necessary headers...
16//
17
38e73f87 18#include "ppdc-private.h"
ac884b6a
MS
19#include <sys/stat.h>
20#include <sys/types.h>
21
22
23//
24// Local functions...
25//
26
27static void usage(void);
28
29
30//
31// 'main()' - Main entry for the PPD compiler.
32//
33
34int // O - Exit status
35main(int argc, // I - Number of command-line arguments
36 char *argv[]) // I - Command-line arguments
37{
38 int i; // Looping var
39 ppdcSource *src; // PPD source file data
40 ppdcDriver *d; // Current driver
41 ppdcGroup *g, // Current group
42 *composite; // Composite of all drivers
43 ppdcOption *o, // Current option
44 *compo; // Composite option
45 ppdcChoice *c; // Current choice
46 char *opt; // Current option char
47 ppdcMediaSize *size; // Current media size
61cf44e2 48 char *value; // Value in option
ac884b6a
MS
49
50
61cf44e2
MS
51 _cupsSetLocale(argv);
52
ac884b6a 53 // Scan the command-line...
d25e43cf 54 src = new ppdcSource();
ac884b6a
MS
55
56 for (i = 1; i < argc; i ++)
57 if (argv[i][0] == '-')
58 {
59 for (opt = argv[i] + 1; *opt; opt ++)
60 switch (*opt)
61 {
61cf44e2
MS
62 case 'D' : // Define variable
63 i ++;
64 if (i >= argc)
65 usage();
66
67 if ((value = strchr(argv[i], '=')) != NULL)
68 {
69 *value++ = '\0';
70
71 src->set_variable(argv[i], value);
72 }
73 else
74 src->set_variable(argv[i], "1");
75 break;
76
ac884b6a
MS
77 case 'I' : // Include directory...
78 i ++;
79 if (i >= argc)
80 usage();
81
82 ppdcSource::add_include(argv[i]);
83 break;
84
85 default : // Unknown
86 usage();
87 break;
88 }
89 }
90 else
91 {
92 // Open and load the driver info file...
d25e43cf
MS
93 src->read_file(argv[i]);
94 }
95
96 if ((d = (ppdcDriver *)src->drivers->first()) != NULL)
97 {
98 // Create a composite group with all of the features from the
99 // drivers in the info file...
100 composite = new ppdcGroup("", "");
101
102 while (d != NULL)
103 {
104 for (g = (ppdcGroup *)d->groups->first(); g; g = (ppdcGroup *)d->groups->next())
105 for (o = (ppdcOption *)g->options->first(); o; o = (ppdcOption *)g->options->next())
106 {
107 if ((compo = composite->find_option(o->name->value)) == NULL)
108 composite->add_option(new ppdcOption(o));
109 }
110
111 d = (ppdcDriver *)src->drivers->next();
ac884b6a
MS
112 }
113
d25e43cf
MS
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
152 // Delete the printer driver information...
153 composite->release();
154 }
155 else
156 {
157 // If no drivers have been loaded, display the program usage message.
ac884b6a 158 usage();
d25e43cf
MS
159 }
160
161 src->release();
ac884b6a
MS
162
163 // Return with no errors.
164 return (0);
165}
166
167
168//
169// 'usage()' - Show usage and exit.
170//
171
172static void
173usage(void)
174{
0837b7e8
MS
175 _cupsLangPuts(stdout, _("Usage: ppdhtml [options] filename.drv "
176 ">filename.html"));
177 _cupsLangPuts(stdout, _("Options:"));
84315f46 178 _cupsLangPuts(stdout, _(" -D name=value Set named variable to "
0837b7e8 179 "value."));
84315f46
MS
180 _cupsLangPuts(stdout, _(" -I include-dir Add include directory "
181 "to search path."));
ac884b6a
MS
182
183 exit(1);
184}