]>
Commit | Line | Data |
---|---|---|
ac884b6a | 1 | // |
503b54c9 | 2 | // PPD file import utility for the CUPS PPD Compiler. |
ac884b6a | 3 | // |
503b54c9 MS |
4 | // Copyright 2007-2011 by Apple Inc. |
5 | // Copyright 2002-2005 by Easy Software Products. | |
ac884b6a | 6 | // |
e3101897 | 7 | // Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ac884b6a MS |
8 | // |
9 | ||
10 | // | |
11 | // Include necessary headers... | |
12 | // | |
13 | ||
38e73f87 | 14 | #include "ppdc-private.h" |
ac884b6a MS |
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 | |
32 | main(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 | ||
61cf44e2 MS |
41 | _cupsSetLocale(argv); |
42 | ||
ac884b6a MS |
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... | |
e4572d57 | 103 | src->release(); |
ac884b6a MS |
104 | |
105 | // Return with no errors. | |
106 | return (0); | |
107 | } | |
108 | ||
109 | ||
110 | // | |
111 | // 'usage()' - Show usage and exit. | |
112 | // | |
113 | ||
114 | static void | |
115 | usage(void) | |
116 | { | |
0837b7e8 MS |
117 | _cupsLangPuts(stdout, _("Usage: ppdi [options] filename.ppd [ ... " |
118 | "filenameN.ppd ]")); | |
119 | _cupsLangPuts(stdout, _("Options:")); | |
84315f46 MS |
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).")); | |
ac884b6a MS |
124 | |
125 | exit(1); | |
126 | } |