]>
git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdc.cxx
4 // PPD file compiler main entry for the CUPS PPD Compiler.
6 // Copyright 2007 by Apple Inc.
7 // Copyright 2002-2007 by Easy Software Products.
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/".
17 // main() - Main entry for the PPD compiler.
18 // usage() - Show usage and exit.
22 // Include necessary headers...
27 #include <sys/types.h>
34 static void usage(void);
38 // 'main()' - Main entry for the PPD compiler.
41 int // O - Exit status
42 main(int argc
, // I - Number of command-line arguments
43 char *argv
[]) // I - Command-line arguments
45 int i
, j
; // Looping vars
46 ppdcCatalog
*catalog
; // Message catalog
47 const char *outdir
; // Output directory
48 ppdcSource
*src
; // PPD source file data
49 ppdcDriver
*d
; // Current driver
50 cups_file_t
*fp
; // PPD file
51 char *opt
, // Current option
52 *value
, // Value in option
54 // Lowercase pcfilename
55 filename
[1024]; // PPD filename
56 int verbose
; // Verbosity
57 ppdcArray
*locales
; // List of locales
59 ppdcLineEnding le
; // Line ending to use
62 // Scan the command-line...
65 src
= new ppdcSource();
71 for (i
= 1; i
< argc
; i
++)
72 if (argv
[i
][0] == '-')
74 for (opt
= argv
[i
] + 1; *opt
; opt
++)
77 case 'c' : // Message catalog...
83 printf("ppdc: Loading messages from \"%s\"...\n", argv
[i
]);
86 catalog
= new ppdcCatalog("en");
88 if (catalog
->load_messages(argv
[i
]))
91 "ppdc: Unable to load localization file \"%s\" - %s\n",
92 argv
[i
], strerror(errno
));
97 case 'd' : // Output directory...
103 printf("ppdc: Writing PPD files to directory \"%s\"...\n",
109 case 'l' : // Language(s)...
114 if (strchr(argv
[i
], ','))
116 // Comma-delimited list of languages...
117 char temp
[1024], // Copy of language list
118 *start
, // Start of current locale name
119 *end
; // End of current locale name
122 locales
= new ppdcArray();
124 strlcpy(temp
, argv
[i
], sizeof(temp
));
125 for (start
= temp
; *start
; start
= end
)
127 if ((end
= strchr(start
, ',')) != NULL
)
130 end
= start
+ strlen(start
);
133 locales
->add(new ppdcString(start
));
139 printf("ppdc: Loading messages for locale \"%s\"...\n",
145 catalog
= new ppdcCatalog(argv
[i
]);
147 if (catalog
->messages
->count
== 0)
150 "ppdc: Unable to find localization for \"%s\" - %s\n",
151 argv
[i
], strerror(errno
));
157 case 'D' : // Define variable
162 if ((value
= strchr(argv
[i
], '=')) != NULL
)
166 src
->set_variable(argv
[i
], value
);
169 src
->set_variable(argv
[i
], "1");
172 case 'I' : // Include directory...
178 printf("ppdc: Adding include directory \"%s\"...\n", argv
[i
]);
180 ppdcSource::add_include(argv
[i
]);
183 case 'v' : // Be verbose...
187 case 'z' : // Compress files...
191 case '-' : // --option
192 if (!strcmp(opt
, "-lf"))
195 opt
+= strlen(opt
) - 1;
198 else if (!strcmp(opt
, "-cr"))
201 opt
+= strlen(opt
) - 1;
204 else if (!strcmp(opt
, "-crlf"))
207 opt
+= strlen(opt
) - 1;
218 // Open and load the driver info file...
220 printf("ppdc: Loading driver information file \"%s\"...\n", argv
[i
]);
222 src
->read_file(argv
[i
]);
226 if (src
->drivers
->count
> 0)
228 // Create the output directory...
229 if (mkdir(outdir
, 0777))
233 fprintf(stderr
, "ppdc: Unable to create output directory %s: %s\n",
234 outdir
, strerror(errno
));
239 // Write PPD files...
240 for (d
= (ppdcDriver
*)src
->drivers
->first();
242 d
= (ppdcDriver
*)src
->drivers
->next())
244 // Write the PPD file for this driver...
245 if (strstr(d
->pc_file_name
->value
, ".PPD"))
247 // Convert PCFileName to lowercase...
249 d
->pc_file_name
->value
[j
] && j
< (int)(sizeof(pcfilename
) - 1);
251 pcfilename
[j
] = tolower(d
->pc_file_name
->value
[j
]);
253 pcfilename
[j
] = '\0';
257 // Leave PCFileName as-is...
258 strlcpy(pcfilename
, d
->pc_file_name
->value
, sizeof(pcfilename
));
261 // Open the PPD file for writing...
263 snprintf(filename
, sizeof(filename
), "%s/%s.gz", outdir
, pcfilename
);
265 snprintf(filename
, sizeof(filename
), "%s/%s", outdir
, pcfilename
);
267 fp
= cupsFileOpen(filename
, comp
? "w9" : "w");
270 fprintf(stderr
, "ppdc: Unable to create PPD file \"%s\" - %s.\n",
271 filename
, strerror(errno
));
276 printf("ppdc: Writing %s...\n", filename
);
278 if (d
->write_ppd_file(fp
, catalog
, locales
, src
, le
))
290 // Delete the printer driver information...
293 // Message catalog...
297 // Return with no errors.
303 // 'usage()' - Show usage and exit.
309 puts("Usage: ppdc [options] filename.drv [ ... filenameN.drv ]");
311 puts(" -D name=value Set named variable to value.");
312 puts(" -I include-dir Add include directory to search path.");
313 puts(" -c catalog.po Load the specified message catalog.");
314 puts(" -d output-dir Specify the output directory.");
315 puts(" -l lang[,lang,...] Specify the output language(s) (locale).");
316 puts(" -v Be verbose (more v's for more verbosity).");
317 puts(" -z Compress PPD files using GNU zip.");
318 puts(" --cr End lines with CR (Mac OS 9).");
319 puts(" --crlf End lines with CR + LF (Windows).");
320 puts(" --lf End lines with LF (UNIX/Linux/Mac OS X).");