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