]>
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...
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
66 // Scan the command-line...
73 src
= new ppdcSource();
77 for (i
= 1; i
< argc
; i
++)
78 if (argv
[i
][0] == '-')
80 for (opt
= argv
[i
] + 1; *opt
; opt
++)
83 case 'D' : // Define variable
88 if ((value
= strchr(argv
[i
], '=')) != NULL
)
92 src
->set_variable(argv
[i
], value
);
95 src
->set_variable(argv
[i
], "1");
98 case 'I' : // Include directory...
104 printf("ppdc: Adding include directory \"%s\"...\n", argv
[i
]);
106 ppdcSource::add_include(argv
[i
]);
109 case 'c' : // Message catalog...
115 printf("ppdc: Loading messages from \"%s\"...\n", argv
[i
]);
118 catalog
= new ppdcCatalog("en");
120 if (catalog
->load_messages(argv
[i
]))
123 "ppdc: Unable to load localization file \"%s\" - %s\n",
124 argv
[i
], strerror(errno
));
129 case 'd' : // Output directory...
135 printf("ppdc: Writing PPD files to directory \"%s\"...\n",
141 case 'l' : // Language(s)...
146 if (strchr(argv
[i
], ','))
148 // Comma-delimited list of languages...
149 char temp
[1024], // Copy of language list
150 *start
, // Start of current locale name
151 *end
; // End of current locale name
154 locales
= new ppdcArray();
156 strlcpy(temp
, argv
[i
], sizeof(temp
));
157 for (start
= temp
; *start
; start
= end
)
159 if ((end
= strchr(start
, ',')) != NULL
)
162 end
= start
+ strlen(start
);
165 locales
->add(new ppdcString(start
));
171 printf("ppdc: Loading messages for locale \"%s\"...\n",
177 catalog
= new ppdcCatalog(argv
[i
]);
179 if (catalog
->messages
->count
== 0)
182 "ppdc: Unable to find localization for \"%s\" - %s\n",
183 argv
[i
], strerror(errno
));
189 case 'm' : // Use ModelName for filename
193 case 't' : // Test PPDs instead of generating them
197 case 'v' : // Be verbose...
201 case 'z' : // Compress files...
205 case '-' : // --option
206 if (!strcmp(opt
, "-lf"))
209 opt
+= strlen(opt
) - 1;
212 else if (!strcmp(opt
, "-cr"))
215 opt
+= strlen(opt
) - 1;
218 else if (!strcmp(opt
, "-crlf"))
221 opt
+= strlen(opt
) - 1;
232 // Open and load the driver info file...
234 printf("ppdc: Loading driver information file \"%s\"...\n", argv
[i
]);
236 src
->read_file(argv
[i
]);
240 if (src
->drivers
->count
> 0)
242 // Create the output directory...
243 if (mkdir(outdir
, 0777))
247 fprintf(stderr
, "ppdc: Unable to create output directory %s: %s\n",
248 outdir
, strerror(errno
));
253 // Write PPD files...
254 for (d
= (ppdcDriver
*)src
->drivers
->first();
256 d
= (ppdcDriver
*)src
->drivers
->next())
260 // Test the PPD file for this driver...
261 int pid
, // Process ID
262 fds
[2]; // Pipe file descriptors
267 fprintf(stderr
, "ppdc: Unable to create output pipes: %s\n",
272 if ((pid
= fork()) == 0)
274 // Child process comes here...
281 execlp("cupstestppd", "cupstestppd", "-", (char *)0);
283 fprintf(stderr
, "ppdc: Unable to execute cupstestppd: %s\n",
289 fprintf(stderr
, "ppdc: Unable to execute cupstestppd: %s\n",
295 fp
= cupsFileOpenFd(fds
[1], "w");
299 // Write the PPD file for this driver...
301 outname
= d
->model_name
->value
;
302 else if (d
->file_name
)
303 outname
= d
->file_name
->value
;
305 outname
= d
->pc_file_name
->value
;
307 if (strstr(outname
, ".PPD"))
309 // Convert PCFileName to lowercase...
311 outname
[j
] && j
< (int)(sizeof(pcfilename
) - 1);
313 pcfilename
[j
] = tolower(outname
[j
] & 255);
315 pcfilename
[j
] = '\0';
319 // Leave PCFileName as-is...
320 strlcpy(pcfilename
, outname
, sizeof(pcfilename
));
323 // Open the PPD file for writing...
325 snprintf(filename
, sizeof(filename
), "%s/%s.gz", outdir
, pcfilename
);
327 snprintf(filename
, sizeof(filename
), "%s/%s", outdir
, pcfilename
);
329 fp
= cupsFileOpen(filename
, comp
? "w9" : "w");
332 fprintf(stderr
, "ppdc: Unable to create PPD file \"%s\" - %s.\n",
333 filename
, strerror(errno
));
338 printf("ppdc: Writing %s...\n", filename
);
342 * Write the PPD file...
345 if (d
->write_ppd_file(fp
, catalog
, locales
, src
, le
))
357 // Delete the printer driver information...
360 // Message catalog...
364 // Return with no errors.
370 // 'usage()' - Show usage and exit.
376 puts("Usage: ppdc [options] filename.drv [ ... filenameN.drv ]");
378 puts(" -D name=value Set named variable to value.");
379 puts(" -I include-dir Add include directory to search path.");
380 puts(" -c catalog.po Load the specified message catalog.");
381 puts(" -d output-dir Specify the output directory.");
382 puts(" -l lang[,lang,...] Specify the output language(s) (locale).");
383 puts(" -m Use the ModelName value as the filename.");
384 puts(" -t Test PPDs instead of generating them.");
385 puts(" -v Be verbose (more v's for more verbosity).");
386 puts(" -z Compress PPD files using GNU zip.");
387 puts(" --cr End lines with CR (Mac OS 9).");
388 puts(" --crlf End lines with CR + LF (Windows).");
389 puts(" --lf End lines with LF (UNIX/Linux/Mac OS X).");