]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdi.cxx
Merge CUPS 1.4svn-r7319.
[thirdparty/cups.git] / ppdc / ppdi.cxx
1 //
2 // "$Id$"
3 //
4 // PPD file import utility for the CUPS PPD Compiler.
5 //
6 // Copyright 2007 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.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 // Scan the command-line...
53 srcfile = NULL;
54 src = NULL;
55
56 for (i = 1; i < argc; i ++)
57 if (argv[i][0] == '-')
58 {
59 for (opt = argv[i] + 1; *opt; opt ++)
60 switch (*opt)
61 {
62 case 'o' : // Output file
63 if (srcfile || src)
64 usage();
65
66 i ++;
67 if (i >= argc)
68 usage();
69
70 srcfile = argv[i];
71 break;
72
73 case 'I' : // Include dir
74 i ++;
75 if (i >= argc)
76 usage();
77
78 ppdcSource::add_include(argv[i]);
79 break;
80
81 default : // Unknown
82 usage();
83 break;
84 }
85 }
86 else
87 {
88 // Open and load the driver info file...
89 if (!srcfile)
90 srcfile = "ppdi.drv";
91
92 if (!src)
93 {
94 if (access(srcfile, 0))
95 src = new ppdcSource();
96 else
97 src = new ppdcSource(srcfile);
98 }
99
100 // Import the PPD file...
101 src->import_ppd(argv[i]);
102 }
103
104 // If no drivers have been loaded, display the program usage message.
105 if (!src)
106 usage();
107
108 // Write the driver info file back to disk...
109 src->write_file(srcfile);
110
111 // Delete the printer driver information...
112 delete src;
113
114 // Return with no errors.
115 return (0);
116 }
117
118
119 //
120 // 'usage()' - Show usage and exit.
121 //
122
123 static void
124 usage(void)
125 {
126 puts("Usage: ppdi [options] filename.ppd [ ... filenameN.ppd ]");
127 puts("Options:");
128 puts(" -I include-dir");
129 puts(" -o filename.drv");
130
131 exit(1);
132 }
133
134
135 //
136 // End of "$Id$".
137 //