]>
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-2008 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...
25 #include "ppdc-private.h"
28 #include <sys/types.h>
35 static void usage(void);
39 // 'main()' - Main entry for the PPD compiler.
42 int // O - Exit status
43 main(int argc
, // I - Number of command-line arguments
44 char *argv
[]) // I - Command-line arguments
46 int i
, j
; // Looping vars
47 ppdcCatalog
*catalog
; // Message catalog
48 const char *outdir
; // Output directory
49 ppdcSource
*src
; // PPD source file data
50 ppdcDriver
*d
; // Current driver
51 cups_file_t
*fp
; // PPD file
52 char *opt
, // Current option
53 *value
, // Value in option
54 *outname
, // Output filename
56 // Lowercase pcfilename
57 filename
[1024]; // PPD filename
59 do_test
, // Test PPD files
60 use_model_name
, // Use ModelName for filename
62 ppdcLineEnding le
; // Line ending to use
63 ppdcArray
*locales
; // List of locales
68 // Scan the command-line...
75 src
= new ppdcSource();
79 for (i
= 1; i
< argc
; i
++)
80 if (argv
[i
][0] == '-')
82 for (opt
= argv
[i
] + 1; *opt
; opt
++)
85 case 'D' : // Define variable
90 if ((value
= strchr(argv
[i
], '=')) != NULL
)
94 src
->set_variable(argv
[i
], value
);
97 src
->set_variable(argv
[i
], "1");
100 case 'I' : // Include directory...
106 _cupsLangPrintf(stdout
,
107 _("ppdc: Adding include directory \"%s\"...\n"),
110 ppdcSource::add_include(argv
[i
]);
113 case 'c' : // Message catalog...
119 _cupsLangPrintf(stdout
,
120 _("ppdc: Loading messages from \"%s\"...\n"),
124 catalog
= new ppdcCatalog("en");
126 if (catalog
->load_messages(argv
[i
]))
128 _cupsLangPrintf(stderr
,
129 _("ppdc: Unable to load localization file "
130 "\"%s\" - %s\n"), argv
[i
], strerror(errno
));
135 case 'd' : // Output directory...
141 _cupsLangPrintf(stdout
,
142 _("ppdc: Writing PPD files to directory "
143 "\"%s\"...\n"), argv
[i
]);
148 case 'l' : // Language(s)...
153 if (strchr(argv
[i
], ','))
155 // Comma-delimited list of languages...
156 char temp
[1024], // Copy of language list
157 *start
, // Start of current locale name
158 *end
; // End of current locale name
161 locales
= new ppdcArray();
163 strlcpy(temp
, argv
[i
], sizeof(temp
));
164 for (start
= temp
; *start
; start
= end
)
166 if ((end
= strchr(start
, ',')) != NULL
)
169 end
= start
+ strlen(start
);
172 locales
->add(new ppdcString(start
));
178 _cupsLangPrintf(stdout
,
179 _("ppdc: Loading messages for locale "
180 "\"%s\"...\n"), argv
[i
]);
185 catalog
= new ppdcCatalog(argv
[i
]);
187 if (catalog
->messages
->count
== 0)
189 _cupsLangPrintf(stderr
,
190 _("ppdc: Unable to find localization for "
191 "\"%s\" - %s\n"), argv
[i
], strerror(errno
));
197 case 'm' : // Use ModelName for filename
201 case 't' : // Test PPDs instead of generating them
205 case 'v' : // Be verbose...
209 case 'z' : // Compress files...
213 case '-' : // --option
214 if (!strcmp(opt
, "-lf"))
217 opt
+= strlen(opt
) - 1;
220 else if (!strcmp(opt
, "-cr"))
223 opt
+= strlen(opt
) - 1;
226 else if (!strcmp(opt
, "-crlf"))
229 opt
+= strlen(opt
) - 1;
240 // Open and load the driver info file...
242 _cupsLangPrintf(stdout
,
243 _("ppdc: Loading driver information file \"%s\"...\n"),
246 src
->read_file(argv
[i
]);
250 if (src
->drivers
->count
> 0)
252 // Create the output directory...
253 if (mkdir(outdir
, 0777))
257 _cupsLangPrintf(stderr
,
258 _("ppdc: Unable to create output directory %s: %s\n"),
259 outdir
, strerror(errno
));
264 // Write PPD files...
265 for (d
= (ppdcDriver
*)src
->drivers
->first();
267 d
= (ppdcDriver
*)src
->drivers
->next())
271 // Test the PPD file for this driver...
272 int pid
, // Process ID
273 fds
[2]; // Pipe file descriptors
278 _cupsLangPrintf(stderr
,
279 _("ppdc: Unable to create output pipes: %s\n"),
284 if ((pid
= fork()) == 0)
286 // Child process comes here...
293 execlp("cupstestppd", "cupstestppd", "-", (char *)0);
295 _cupsLangPrintf(stderr
,
296 _("ppdc: Unable to execute cupstestppd: %s\n"),
302 _cupsLangPrintf(stderr
,
303 _("ppdc: Unable to execute cupstestppd: %s\n"),
309 fp
= cupsFileOpenFd(fds
[1], "w");
313 // Write the PPD file for this driver...
315 outname
= d
->model_name
->value
;
316 else if (d
->file_name
)
317 outname
= d
->file_name
->value
;
319 outname
= d
->pc_file_name
->value
;
321 if (strstr(outname
, ".PPD"))
323 // Convert PCFileName to lowercase...
325 outname
[j
] && j
< (int)(sizeof(pcfilename
) - 1);
327 pcfilename
[j
] = tolower(outname
[j
] & 255);
329 pcfilename
[j
] = '\0';
333 // Leave PCFileName as-is...
334 strlcpy(pcfilename
, outname
, sizeof(pcfilename
));
337 // Open the PPD file for writing...
339 snprintf(filename
, sizeof(filename
), "%s/%s.gz", outdir
, pcfilename
);
341 snprintf(filename
, sizeof(filename
), "%s/%s", outdir
, pcfilename
);
343 fp
= cupsFileOpen(filename
, comp
? "w9" : "w");
346 _cupsLangPrintf(stderr
,
347 _("ppdc: Unable to create PPD file \"%s\" - %s.\n"),
348 filename
, strerror(errno
));
353 _cupsLangPrintf(stdout
, _("ppdc: Writing %s...\n"), filename
);
357 * Write the PPD file...
360 if (d
->write_ppd_file(fp
, catalog
, locales
, src
, le
))
372 // Delete the printer driver information...
375 // Message catalog...
379 // Return with no errors.
385 // 'usage()' - Show usage and exit.
391 _cupsLangPuts(stdout
,
392 _("Usage: ppdc [options] filename.drv [ ... filenameN.drv ]\n"
394 " -D name=value Set named variable to value.\n"
395 " -I include-dir Add include directory to search "
397 " -c catalog.po Load the specified message catalog.\n"
398 " -d output-dir Specify the output directory.\n"
399 " -l lang[,lang,...] Specify the output language(s) "
401 " -m Use the ModelName value as the "
403 " -t Test PPDs instead of generating "
405 " -v Be verbose (more v's for more "
407 " -z Compress PPD files using GNU zip.\n"
408 " --cr End lines with CR (Mac OS 9).\n"
409 " --crlf End lines with CR + LF (Windows).\n"
410 " --lf End lines with LF (UNIX/Linux/Mac "