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