1// 2// "$Id: ppdhtml.cxx 3073 2011-03-23 00:21:01Z msweet $" 3// 4// PPD to HTML utility for the CUPS PPD Compiler. 5// 6// Copyright 2007-2011 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-private.h" 26#include <sys/stat.h> 27#include <sys/types.h> 28 29 30// 31// Local functions... 32// 33 34static void usage(void); 35 36 37// 38// 'main()' - Main entry for the PPD compiler. 39// 40 41int // O - Exit status 42main(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 char *value; // Value in option 56 57 58 _cupsSetLocale(argv); 59 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 { 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 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... 152 composite->release(); 153 src->release(); 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 169static void 170usage(void) 171{ 172 _cupsLangPuts(stdout, _("Usage: ppdhtml [options] filename.drv " 173 ">filename.html")); 174 _cupsLangPuts(stdout, _("Options:")); 175 _cupsLangPuts(stdout, _(" -D name=value Set named variable to " 176 "value.")); 177 _cupsLangPuts(stdout, _(" -I include-dir Add include directory " 178 "to search path.")); 179 180 exit(1); 181} 182 183 184// 185// End of "$Id: ppdhtml.cxx 3073 2011-03-23 00:21:01Z msweet $". 186// 187