]>
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...
28 #include <sys/types.h>
29 #include <cups/i18n.h>
36 static void usage(void);
40 // 'main()' - Main entry for the PPD compiler.
43 int // O - Exit status
44 main(int argc
, // I - Number of command-line arguments
45 char *argv
[]) // I - Command-line arguments
47 int i
, j
; // Looping vars
48 ppdcCatalog
*catalog
; // Message catalog
49 const char *outdir
; // Output directory
50 ppdcSource
*src
; // PPD source file data
51 ppdcDriver
*d
; // Current driver
52 cups_file_t
*fp
; // PPD file
53 char *opt
, // Current option
54 *value
, // Value in option
55 *outname
, // Output filename
57 // Lowercase pcfilename
58 filename
[1024]; // PPD filename
60 do_test
, // Test PPD files
61 use_model_name
, // Use ModelName for filename
63 ppdcLineEnding le
; // Line ending to use
64 ppdcArray
*locales
; // List of locales
69 // Scan the command-line...
76 src
= new ppdcSource();
80 for (i
= 1; i
< argc
; i
++)
81 if (argv
[i
][0] == '-')
83 for (opt
= argv
[i
] + 1; *opt
; opt
++)
86 case 'D' : // Define variable
91 if ((value
= strchr(argv
[i
], '=')) != NULL
)
95 src
->set_variable(argv
[i
], value
);
98 src
->set_variable(argv
[i
], "1");
101 case 'I' : // Include directory...
107 _cupsLangPrintf(stdout
,
108 _("ppdc: Adding include directory \"%s\"...\n"),
111 ppdcSource::add_include(argv
[i
]);
114 case 'c' : // Message catalog...
120 _cupsLangPrintf(stdout
,
121 _("ppdc: Loading messages from \"%s\"...\n"),
125 catalog
= new ppdcCatalog("en");
127 if (catalog
->load_messages(argv
[i
]))
129 _cupsLangPrintf(stderr
,
130 _("ppdc: Unable to load localization file "
131 "\"%s\" - %s\n"), argv
[i
], strerror(errno
));
136 case 'd' : // Output directory...
142 _cupsLangPrintf(stdout
,
143 _("ppdc: Writing PPD files to directory "
144 "\"%s\"...\n"), argv
[i
]);
149 case 'l' : // Language(s)...
154 if (strchr(argv
[i
], ','))
156 // Comma-delimited list of languages...
157 char temp
[1024], // Copy of language list
158 *start
, // Start of current locale name
159 *end
; // End of current locale name
162 locales
= new ppdcArray();
164 strlcpy(temp
, argv
[i
], sizeof(temp
));
165 for (start
= temp
; *start
; start
= end
)
167 if ((end
= strchr(start
, ',')) != NULL
)
170 end
= start
+ strlen(start
);
173 locales
->add(new ppdcString(start
));
179 _cupsLangPrintf(stdout
,
180 _("ppdc: Loading messages for locale "
181 "\"%s\"...\n"), argv
[i
]);
186 catalog
= new ppdcCatalog(argv
[i
]);
188 if (catalog
->messages
->count
== 0)
190 _cupsLangPrintf(stderr
,
191 _("ppdc: Unable to find localization for "
192 "\"%s\" - %s\n"), argv
[i
], strerror(errno
));
198 case 'm' : // Use ModelName for filename
202 case 't' : // Test PPDs instead of generating them
206 case 'v' : // Be verbose...
210 case 'z' : // Compress files...
214 case '-' : // --option
215 if (!strcmp(opt
, "-lf"))
218 opt
+= strlen(opt
) - 1;
221 else if (!strcmp(opt
, "-cr"))
224 opt
+= strlen(opt
) - 1;
227 else if (!strcmp(opt
, "-crlf"))
230 opt
+= strlen(opt
) - 1;
241 // Open and load the driver info file...
243 _cupsLangPrintf(stdout
,
244 _("ppdc: Loading driver information file \"%s\"...\n"),
247 src
->read_file(argv
[i
]);
251 if (src
->drivers
->count
> 0)
253 // Create the output directory...
254 if (mkdir(outdir
, 0777))
258 _cupsLangPrintf(stderr
,
259 _("ppdc: Unable to create output directory %s: %s\n"),
260 outdir
, strerror(errno
));
265 // Write PPD files...
266 for (d
= (ppdcDriver
*)src
->drivers
->first();
268 d
= (ppdcDriver
*)src
->drivers
->next())
272 // Test the PPD file for this driver...
273 int pid
, // Process ID
274 fds
[2]; // Pipe file descriptors
279 _cupsLangPrintf(stderr
,
280 _("ppdc: Unable to create output pipes: %s\n"),
285 if ((pid
= fork()) == 0)
287 // Child process comes here...
294 execlp("cupstestppd", "cupstestppd", "-", (char *)0);
296 _cupsLangPrintf(stderr
,
297 _("ppdc: Unable to execute cupstestppd: %s\n"),
303 _cupsLangPrintf(stderr
,
304 _("ppdc: Unable to execute cupstestppd: %s\n"),
310 fp
= cupsFileOpenFd(fds
[1], "w");
314 // Write the PPD file for this driver...
316 outname
= d
->model_name
->value
;
317 else if (d
->file_name
)
318 outname
= d
->file_name
->value
;
320 outname
= d
->pc_file_name
->value
;
322 if (strstr(outname
, ".PPD"))
324 // Convert PCFileName to lowercase...
326 outname
[j
] && j
< (int)(sizeof(pcfilename
) - 1);
328 pcfilename
[j
] = tolower(outname
[j
] & 255);
330 pcfilename
[j
] = '\0';
334 // Leave PCFileName as-is...
335 strlcpy(pcfilename
, outname
, sizeof(pcfilename
));
338 // Open the PPD file for writing...
340 snprintf(filename
, sizeof(filename
), "%s/%s.gz", outdir
, pcfilename
);
342 snprintf(filename
, sizeof(filename
), "%s/%s", outdir
, pcfilename
);
344 fp
= cupsFileOpen(filename
, comp
? "w9" : "w");
347 _cupsLangPrintf(stderr
,
348 _("ppdc: Unable to create PPD file \"%s\" - %s.\n"),
349 filename
, strerror(errno
));
354 _cupsLangPrintf(stdout
, _("ppdc: Writing %s...\n"), filename
);
358 * Write the PPD file...
361 if (d
->write_ppd_file(fp
, catalog
, locales
, src
, le
))
373 // Delete the printer driver information...
376 // Message catalog...
380 // Return with no errors.
386 // 'usage()' - Show usage and exit.
392 _cupsLangPuts(stdout
,
393 _("Usage: ppdc [options] filename.drv [ ... filenameN.drv ]\n"
395 " -D name=value Set named variable to value.\n"
396 " -I include-dir Add include directory to search "
398 " -c catalog.po Load the specified message catalog.\n"
399 " -d output-dir Specify the output directory.\n"
400 " -l lang[,lang,...] Specify the output language(s) "
402 " -m Use the ModelName value as the "
404 " -t Test PPDs instead of generating "
406 " -v Be verbose (more v's for more "
408 " -z Compress PPD files using GNU zip.\n"
409 " --cr End lines with CR (Mac OS 9).\n"
410 " --crlf End lines with CR + LF (Windows).\n"
411 " --lf End lines with LF (UNIX/Linux/Mac "