]> git.ipfire.org Git - thirdparty/cups.git/blob - ppdc/ppdi.cxx
Merge pull request #4792 from OdyX/fix-spelling-error-in-ipp-var
[thirdparty/cups.git] / ppdc / ppdi.cxx
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 // These coded instructions, statements, and computer programs are the
8 // property of Apple Inc. and are protected by Federal copyright
9 // law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 // which should have been included with this file. If this file is
11 // file is missing or damaged, see the license at "http://www.cups.org/".
12 //
13
14 //
15 // Include necessary headers...
16 //
17
18 #include "ppdc-private.h"
19 #include <unistd.h>
20 #include <sys/stat.h>
21 #include <sys/types.h>
22
23
24 //
25 // Local functions...
26 //
27
28 static void usage(void);
29
30
31 //
32 // 'main()' - Main entry for the PPD import utility.
33 //
34
35 int // O - Exit status
36 main(int argc, // I - Number of command-line arguments
37 char *argv[]) // I - Command-line arguments
38 {
39 int i; // Looping var
40 char *opt; // Current option
41 const char *srcfile; // Output file
42 ppdcSource *src; // PPD source file data
43
44
45 _cupsSetLocale(argv);
46
47 // Scan the command-line...
48 srcfile = NULL;
49 src = NULL;
50
51 for (i = 1; i < argc; i ++)
52 if (argv[i][0] == '-')
53 {
54 for (opt = argv[i] + 1; *opt; opt ++)
55 switch (*opt)
56 {
57 case 'o' : // Output file
58 if (srcfile || src)
59 usage();
60
61 i ++;
62 if (i >= argc)
63 usage();
64
65 srcfile = argv[i];
66 break;
67
68 case 'I' : // Include dir
69 i ++;
70 if (i >= argc)
71 usage();
72
73 ppdcSource::add_include(argv[i]);
74 break;
75
76 default : // Unknown
77 usage();
78 break;
79 }
80 }
81 else
82 {
83 // Open and load the driver info file...
84 if (!srcfile)
85 srcfile = "ppdi.drv";
86
87 if (!src)
88 {
89 if (access(srcfile, 0))
90 src = new ppdcSource();
91 else
92 src = new ppdcSource(srcfile);
93 }
94
95 // Import the PPD file...
96 src->import_ppd(argv[i]);
97 }
98
99 // If no drivers have been loaded, display the program usage message.
100 if (!src)
101 usage();
102
103 // Write the driver info file back to disk...
104 src->write_file(srcfile);
105
106 // Delete the printer driver information...
107 src->release();
108
109 // Return with no errors.
110 return (0);
111 }
112
113
114 //
115 // 'usage()' - Show usage and exit.
116 //
117
118 static void
119 usage(void)
120 {
121 _cupsLangPuts(stdout, _("Usage: ppdi [options] filename.ppd [ ... "
122 "filenameN.ppd ]"));
123 _cupsLangPuts(stdout, _("Options:"));
124 _cupsLangPuts(stdout, _(" -I include-dir Add include directory to "
125 "search path."));
126 _cupsLangPuts(stdout, _(" -o filename.drv Set driver information "
127 "file (otherwise ppdi.drv)."));
128
129 exit(1);
130 }