X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=ppdc%2Fppdc.cxx;h=78752e5ec878696f629f3e12c1aac72af4be96b8;hb=a6580b70a3a761889a51320960961c0198a03491;hp=c4d6be1e01fa810bc4a0156a774dd34aeb92b41c;hpb=bdd6c45b5e42206a5add7bf770196531dd8ad811;p=thirdparty%2Fcups.git diff --git a/ppdc/ppdc.cxx b/ppdc/ppdc.cxx index c4d6be1e0..78752e5ec 100644 --- a/ppdc/ppdc.cxx +++ b/ppdc/ppdc.cxx @@ -1,28 +1,21 @@ // -// "$Id$" +// PPD file compiler main entry for the CUPS PPD Compiler. // -// PPD file compiler main entry for the CUPS PPD Compiler. +// Copyright 2007-2014 by Apple Inc. +// Copyright 2002-2007 by Easy Software Products. // -// Copyright 2007 by Apple Inc. -// Copyright 2002-2007 by Easy Software Products. -// -// These coded instructions, statements, and computer programs are the -// property of Apple Inc. and are protected by Federal copyright -// law. Distribution and use rights are outlined in the file "LICENSE.txt" -// which should have been included with this file. If this file is -// file is missing or damaged, see the license at "http://www.cups.org/". -// -// Contents: -// -// main() - Main entry for the PPD compiler. -// usage() - Show usage and exit. +// These coded instructions, statements, and computer programs are the +// property of Apple Inc. and are protected by Federal copyright +// law. Distribution and use rights are outlined in the file "LICENSE.txt" +// which should have been included with this file. If this file is +// file is missing or damaged, see the license at "http://www.cups.org/". // // // Include necessary headers... // -#include "ppdc.h" +#include "ppdc-private.h" #include #include #include @@ -52,27 +45,35 @@ main(int argc, // I - Number of command-line arguments char *opt, // Current option *value, // Value in option *outname, // Output filename + make_model[1024], + // Make and model pcfilename[1024], // Lowercase pcfilename filename[1024]; // PPD filename int comp, // Compress do_test, // Test PPD files + single_language,// Generate single-language files use_model_name, // Use ModelName for filename verbose; // Verbosity ppdcLineEnding le; // Line ending to use ppdcArray *locales; // List of locales + cups_array_t *filenames; // List of generated filenames + _cupsSetLocale(argv); + // Scan the command-line... - catalog = NULL; - comp = 0; - do_test = 0; - le = PPDC_LFONLY; - locales = NULL; - outdir = "ppd"; - src = new ppdcSource(); - use_model_name = 0; - verbose = 0; + catalog = NULL; + comp = 0; + do_test = 0; + le = PPDC_LFONLY; + locales = NULL; + outdir = "ppd"; + single_language = 0; + src = new ppdcSource(); + use_model_name = 0; + verbose = 0; + filenames = cupsArrayNew((cups_array_func_t)_cups_strcasecmp, NULL); for (i = 1; i < argc; i ++) if (argv[i][0] == '-') @@ -101,7 +102,9 @@ main(int argc, // I - Number of command-line arguments usage(); if (verbose > 1) - printf("ppdc: Adding include directory \"%s\"...\n", argv[i]); + _cupsLangPrintf(stdout, + _("ppdc: Adding include directory \"%s\"."), + argv[i]); ppdcSource::add_include(argv[i]); break; @@ -112,16 +115,18 @@ main(int argc, // I - Number of command-line arguments usage(); if (verbose > 1) - printf("ppdc: Loading messages from \"%s\"...\n", argv[i]); + _cupsLangPrintf(stdout, + _("ppdc: Loading messages from \"%s\"."), + argv[i]); if (!catalog) catalog = new ppdcCatalog("en"); if (catalog->load_messages(argv[i])) { - fprintf(stderr, - "ppdc: Unable to load localization file \"%s\" - %s\n", - argv[i], strerror(errno)); + _cupsLangPrintf(stderr, + _("ppdc: Unable to load localization file " + "\"%s\" - %s"), argv[i], strerror(errno)); return (1); } break; @@ -132,8 +137,9 @@ main(int argc, // I - Number of command-line arguments usage(); if (verbose > 1) - printf("ppdc: Writing PPD files to directory \"%s\"...\n", - argv[i]); + _cupsLangPrintf(stdout, + _("ppdc: Writing PPD files to directory " + "\"%s\"."), argv[i]); outdir = argv[i]; break; @@ -167,20 +173,23 @@ main(int argc, // I - Number of command-line arguments } else { + single_language = 1; + if (verbose > 1) - printf("ppdc: Loading messages for locale \"%s\"...\n", - argv[i]); + _cupsLangPrintf(stdout, + _("ppdc: Loading messages for locale " + "\"%s\"."), argv[i]); if (catalog) - delete catalog; + catalog->release(); catalog = new ppdcCatalog(argv[i]); - if (catalog->messages->count == 0) + if (catalog->messages->count == 0 && strcmp(argv[i], "en")) { - fprintf(stderr, - "ppdc: Unable to find localization for \"%s\" - %s\n", - argv[i], strerror(errno)); + _cupsLangPrintf(stderr, + _("ppdc: Unable to find localization for " + "\"%s\" - %s"), argv[i], strerror(errno)); return (1); } } @@ -197,7 +206,7 @@ main(int argc, // I - Number of command-line arguments case 'v' : // Be verbose... verbose ++; break; - + case 'z' : // Compress files... comp = 1; break; @@ -221,7 +230,7 @@ main(int argc, // I - Number of command-line arguments opt += strlen(opt) - 1; break; } - + default : // Unknown usage(); break; @@ -231,7 +240,9 @@ main(int argc, // I - Number of command-line arguments { // Open and load the driver info file... if (verbose > 1) - printf("ppdc: Loading driver information file \"%s\"...\n", argv[i]); + _cupsLangPrintf(stdout, + _("ppdc: Loading driver information file \"%s\"."), + argv[i]); src->read_file(argv[i]); } @@ -244,7 +255,8 @@ main(int argc, // I - Number of command-line arguments { if (errno != EEXIST) { - fprintf(stderr, "ppdc: Unable to create output directory %s: %s\n", + _cupsLangPrintf(stderr, + _("ppdc: Unable to create output directory %s: %s"), outdir, strerror(errno)); return (1); } @@ -264,30 +276,31 @@ main(int argc, // I - Number of command-line arguments if (pipe(fds)) { - fprintf(stderr, "ppdc: Unable to create output pipes: %s\n", - strerror(errno)); + _cupsLangPrintf(stderr, + _("ppdc: Unable to create output pipes: %s"), + strerror(errno)); return (1); } if ((pid = fork()) == 0) { // Child process comes here... - close(0); - dup(fds[0]); + dup2(fds[0], 0); close(fds[0]); close(fds[1]); execlp("cupstestppd", "cupstestppd", "-", (char *)0); - fprintf(stderr, "ppdc: Unable to execute cupstestppd: %s\n", - strerror(errno)); + _cupsLangPrintf(stderr, + _("ppdc: Unable to execute cupstestppd: %s"), + strerror(errno)); return (errno); } else if (pid < 0) { - fprintf(stderr, "ppdc: Unable to execute cupstestppd: %s\n", - strerror(errno)); + _cupsLangPrintf(stderr, _("ppdc: Unable to execute cupstestppd: %s"), + strerror(errno)); return (errno); } @@ -298,7 +311,21 @@ main(int argc, // I - Number of command-line arguments { // Write the PPD file for this driver... if (use_model_name) - outname = d->model_name->value; + { + if (!_cups_strncasecmp(d->model_name->value, d->manufacturer->value, + strlen(d->manufacturer->value))) + { + // Model name already starts with the manufacturer... + outname = d->model_name->value; + } + else + { + // Add manufacturer to the front of the model name... + snprintf(make_model, sizeof(make_model), "%s %s", + d->manufacturer->value, d->model_name->value); + outname = make_model; + } + } else if (d->file_name) outname = d->file_name->value; else @@ -310,7 +337,7 @@ main(int argc, // I - Number of command-line arguments for (j = 0; outname[j] && j < (int)(sizeof(pcfilename) - 1); j ++) - pcfilename[j] = tolower(outname[j] & 255); + pcfilename[j] = (char)tolower(outname[j] & 255); pcfilename[j] = '\0'; } @@ -326,28 +353,53 @@ main(int argc, // I - Number of command-line arguments else snprintf(filename, sizeof(filename), "%s/%s", outdir, pcfilename); + if (cupsArrayFind(filenames, filename)) + _cupsLangPrintf(stderr, + _("ppdc: Warning - overlapping filename \"%s\"."), + filename); + else + cupsArrayAdd(filenames, strdup(filename)); + fp = cupsFileOpen(filename, comp ? "w9" : "w"); if (!fp) { - fprintf(stderr, "ppdc: Unable to create PPD file \"%s\" - %s.\n", - filename, strerror(errno)); + _cupsLangPrintf(stderr, + _("ppdc: Unable to create PPD file \"%s\" - %s."), + filename, strerror(errno)); return (1); } if (verbose) - printf("ppdc: Writing %s...\n", filename); + _cupsLangPrintf(stdout, _("ppdc: Writing %s."), filename); } /* * Write the PPD file... */ - if (d->write_ppd_file(fp, catalog, locales, src, le)) + ppdcArray *templocales = locales; + + if (!templocales && !single_language) + { + templocales = new ppdcArray(); + for (ppdcCatalog *tempcatalog = (ppdcCatalog *)src->po_files->first(); + tempcatalog; + tempcatalog = (ppdcCatalog *)src->po_files->next()) + { + tempcatalog->locale->retain(); + templocales->add(tempcatalog->locale); + } + } + + if (d->write_ppd_file(fp, catalog, templocales, src, le)) { cupsFileClose(fp); return (1); } + if (templocales != locales) + templocales->release(); + cupsFileClose(fp); } } @@ -355,11 +407,11 @@ main(int argc, // I - Number of command-line arguments usage(); // Delete the printer driver information... - delete src; + src->release(); // Message catalog... if (catalog) - delete catalog; + catalog->release(); // Return with no errors. return (0); @@ -373,25 +425,32 @@ main(int argc, // I - Number of command-line arguments static void usage(void) { - puts("Usage: ppdc [options] filename.drv [ ... filenameN.drv ]"); - puts("Options:"); - puts(" -D name=value Set named variable to value."); - puts(" -I include-dir Add include directory to search path."); - puts(" -c catalog.po Load the specified message catalog."); - puts(" -d output-dir Specify the output directory."); - puts(" -l lang[,lang,...] Specify the output language(s) (locale)."); - puts(" -m Use the ModelName value as the filename."); - puts(" -t Test PPDs instead of generating them."); - puts(" -v Be verbose (more v's for more verbosity)."); - puts(" -z Compress PPD files using GNU zip."); - puts(" --cr End lines with CR (Mac OS 9)."); - puts(" --crlf End lines with CR + LF (Windows)."); - puts(" --lf End lines with LF (UNIX/Linux/Mac OS X)."); + _cupsLangPuts(stdout, _("Usage: ppdc [options] filename.drv [ ... " + "filenameN.drv ]")); + _cupsLangPuts(stdout, _("Options:")); + _cupsLangPuts(stdout, _(" -D name=value Set named variable to " + "value.")); + _cupsLangPuts(stdout, _(" -I include-dir Add include directory to " + "search path.")); + _cupsLangPuts(stdout, _(" -c catalog.po Load the specified " + "message catalog.")); + _cupsLangPuts(stdout, _(" -d output-dir Specify the output " + "directory.")); + _cupsLangPuts(stdout, _(" -l lang[,lang,...] Specify the output " + "language(s) (locale).")); + _cupsLangPuts(stdout, _(" -m Use the ModelName value " + "as the filename.")); + _cupsLangPuts(stdout, _(" -t Test PPDs instead of " + "generating them.")); + _cupsLangPuts(stdout, _(" -v Be verbose.")); + _cupsLangPuts(stdout, _(" -z Compress PPD files using " + "GNU zip.")); + _cupsLangPuts(stdout, _(" --cr End lines with CR (Mac " + "OS 9).")); + _cupsLangPuts(stdout, _(" --crlf End lines with CR + LF " + "(Windows).")); + _cupsLangPuts(stdout, _(" --lf End lines with LF " + "(UNIX/Linux/macOS).")); exit(1); } - - -// -// End of "$Id$". -//