1 // 2 // PPD file import utility for the CUPS PPD Compiler. 3 // 4 // Copyright 2007-2011 by Apple Inc. 5 // Copyright 2002-2005 by Easy Software Products. 6 // 7 // Licensed under Apache License v2.0. See the file "LICENSE" for more information. 8 // 9 10 // 11 // Include necessary headers... 12 // 13 14 #include "ppdc-private.h" 15 #include <unistd.h> 16 #include <sys/stat.h> 17 #include <sys/types.h> 18 19 20 // 21 // Local functions... 22 // 23 24 static void usage(void); 25 26 27 // 28 // 'main()' - Main entry for the PPD import utility. 29 // 30 31 int // O - Exit status main(int argc,char * argv[])32main(int argc, // I - Number of command-line arguments 33 char *argv[]) // I - Command-line arguments 34 { 35 int i; // Looping var 36 char *opt; // Current option 37 const char *srcfile; // Output file 38 ppdcSource *src; // PPD source file data 39 40 41 _cupsSetLocale(argv); 42 43 // Scan the command-line... 44 srcfile = NULL; 45 src = NULL; 46 47 for (i = 1; i < argc; i ++) 48 if (argv[i][0] == '-') 49 { 50 for (opt = argv[i] + 1; *opt; opt ++) 51 switch (*opt) 52 { 53 case 'o' : // Output file 54 if (srcfile || src) 55 usage(); 56 57 i ++; 58 if (i >= argc) 59 usage(); 60 61 srcfile = argv[i]; 62 break; 63 64 case 'I' : // Include dir 65 i ++; 66 if (i >= argc) 67 usage(); 68 69 ppdcSource::add_include(argv[i]); 70 break; 71 72 default : // Unknown 73 usage(); 74 break; 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