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