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