1 // 2 // PPD file import utility for the CUPS PPD Compiler. 3 // 4 // Copyright © 2020-2024 by OpenPrinting. 5 // Copyright 2007-2011 by Apple Inc. 6 // Copyright 2002-2005 by Easy Software Products. 7 // 8 // Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 // 10 11 // 12 // Include necessary headers... 13 // 14 15 #include "ppdc-private.h" 16 #include <unistd.h> 17 #include <sys/stat.h> 18 #include <sys/types.h> 19 20 21 // 22 // Local functions... 23 // 24 25 static void usage(void) _CUPS_NORETURN; 26 27 28 // 29 // 'main()' - Main entry for the PPD import utility. 30 // 31 32 int // O - Exit status main(int argc,char * argv[])33main(int argc, // I - Number of command-line arguments 34 char *argv[]) // I - Command-line arguments 35 { 36 int i; // Looping var 37 char *opt; // Current option 38 const char *srcfile; // Output file 39 ppdcSource *src; // PPD source file data 40 41 42 _cupsSetLocale(argv); 43 44 // Scan the command-line... 45 srcfile = NULL; 46 src = NULL; 47 48 for (i = 1; i < argc; i ++) 49 if (argv[i][0] == '-') 50 { 51 for (opt = argv[i] + 1; *opt; opt ++) 52 switch (*opt) 53 { 54 case 'o' : // Output file 55 if (srcfile || src) 56 usage(); 57 58 i ++; 59 if (i >= argc) 60 usage(); 61 62 srcfile = argv[i]; 63 break; 64 65 case 'I' : // Include dir 66 i ++; 67 if (i >= argc) 68 usage(); 69 70 ppdcSource::add_include(argv[i]); 71 break; 72 73 default : // Unknown 74 usage(); 75 } 76 } 77 else 78 { 79 // Open and load the driver info file... 80 if (!srcfile) 81 srcfile = "ppdi.drv"; 82 83 if (!src) 84 { 85 if (access(srcfile, 0)) 86 src = new ppdcSource(); 87 else 88 src = new ppdcSource(srcfile); 89 } 90 91 // Import the PPD file... 92 src->import_ppd(argv[i]); 93 } 94 95 // If no drivers have been loaded, display the program usage message. 96 if (!src) 97 usage(); 98 99 // Write the driver info file back to disk... 100 src->write_file(srcfile); 101 102 // Delete the printer driver information... 103 src->release(); 104 105 // Return with no errors. 106 return (0); 107 } 108 109 110 // 111 // 'usage()' - Show usage and exit. 112 // 113 114 static void usage(void)115usage(void) 116 { 117 _cupsLangPuts(stdout, _("Usage: ppdi [options] filename.ppd [ ... " 118 "filenameN.ppd ]")); 119 _cupsLangPuts(stdout, _("Options:")); 120 _cupsLangPuts(stdout, _(" -I include-dir Add include directory to " 121 "search path.")); 122 _cupsLangPuts(stdout, _(" -o filename.drv Set driver information " 123 "file (otherwise ppdi.drv).")); 124 125 exit(1); 126 } 127