VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.c@ 103503

Last change on this file since 103503 was 103503, checked in by vboxsync, 3 months ago

libs/xpcom/xpidl: Some cleanup, bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the NPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the NPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39 * Main xpidl program entry point.
40 */
41#include <iprt/initterm.h>
42
43#include "xpidl.h"
44
45static ModeData modes[] = {
46 {"header", "Generate C++ header", "h", xpidl_header_dispatch},
47 {"typelib", "Generate XPConnect typelib", "xpt", xpidl_typelib_dispatch},
48 {"doc", "Generate HTML documentation", "html", xpidl_doc_dispatch},
49 {"java", "Generate Java interface", "java", xpidl_java_dispatch},
50 {0, 0, 0, 0}
51};
52
53static ModeData *
54FindMode(char *mode)
55{
56 int i;
57 for (i = 0; modes[i].mode; i++) {
58 if (!strcmp(modes[i].mode, mode))
59 return &modes[i];
60 }
61 return NULL;
62}
63
64gboolean enable_debug = FALSE;
65gboolean enable_warnings = FALSE;
66gboolean verbose_mode = FALSE;
67gboolean emit_typelib_annotations = FALSE;
68gboolean explicit_output_filename = FALSE;
69
70/* The following globals are explained in xpt_struct.h */
71PRUint8 major_version = XPT_MAJOR_VERSION;
72PRUint8 minor_version = XPT_MINOR_VERSION;
73
74static char xpidl_usage_str[] =
75"Usage: %s -m mode [-w] [-v] [-t version number]\n"
76" [-I path] [-o basename | -e filename.ext] filename.idl\n"
77" -a emit annotations to typelib\n"
78" -w turn on warnings (recommended)\n"
79" -v verbose mode (NYI)\n"
80" -t create a typelib of a specific version number\n"
81" -I add entry to start of include path for ``#include \"nsIThing.idl\"''\n"
82" -o use basename (e.g. ``/tmp/nsIThing'') for output\n"
83" -e use explicit output filename\n"
84" -m specify output mode:\n";
85
86static void
87xpidl_usage(int argc, char *argv[])
88{
89 int i;
90 fprintf(stderr, xpidl_usage_str, argv[0]);
91 for (i = 0; modes[i].mode; i++) {
92 fprintf(stderr, " %-12s %-30s (.%s)\n", modes[i].mode,
93 modes[i].modeInfo, modes[i].suffix);
94 }
95}
96
97int main(int argc, char *argv[])
98{
99 RTR3InitExeNoArguments(0);
100
101 int i;
102 IncludePathEntry *inc, *inc_head, **inc_tail;
103 char *file_basename = NULL;
104 ModeData *mode = NULL;
105 gboolean create_old_typelib = FALSE;
106
107 /* turn this on for extra checking of our code */
108/* IDL_check_cast_enable(TRUE); */
109
110 inc_head = xpidl_malloc(sizeof *inc);
111 inc_head->directory = ".";
112 inc_head->next = NULL;
113 inc_tail = &inc_head->next;
114
115 for (i = 1; i < argc; i++) {
116 if (argv[i][0] != '-')
117 break;
118 switch (argv[i][1]) {
119 case '-':
120 argc++; /* pretend we didn't see this */
121 /* fall through */
122 case 0: /* - is a legal input filename (stdin) */
123 goto done_options;
124 case 'a':
125 emit_typelib_annotations = TRUE;
126 break;
127 case 'w':
128 enable_warnings = TRUE;
129 break;
130 case 'v':
131 verbose_mode = TRUE;
132 break;
133 case 't':
134 {
135 /* Parse for "-t version number" and store it into global boolean
136 * and string variables.
137 */
138 const gchar* typelib_version_string = NULL;
139
140 /*
141 * If -t is the last argument on the command line, we have a problem
142 */
143
144 if (i + 1 == argc) {
145 fprintf(stderr, "ERROR: missing version number after -t\n");
146 xpidl_usage(argc, argv);
147 return 1;
148 }
149
150 /* Do not allow more than one "-t" definition */
151 if (create_old_typelib) {
152 fprintf(stderr,
153 "ERROR: -t argument used twice. "
154 "Cannot specify more than one version\n");
155 xpidl_usage(argc, argv);
156 return 1;
157 }
158
159 /*
160 * Assume that the argument after "-t" is the version number string
161 * and search for it in our internal list of acceptable version
162 * numbers.
163 */
164 switch (XPT_ParseVersionString(argv[++i], &major_version,
165 &minor_version)) {
166 case XPT_VERSION_CURRENT:
167 break;
168 case XPT_VERSION_OLD:
169 create_old_typelib = TRUE;
170 break;
171 case XPT_VERSION_UNSUPPORTED:
172 fprintf(stderr, "ERROR: version \"%s\" not supported.\n",
173 argv[i]);
174 xpidl_usage(argc, argv);
175 return 1;
176 case XPT_VERSION_UNKNOWN:
177 default:
178 fprintf(stderr, "ERROR: version \"%s\" not recognised.\n",
179 argv[i]);
180 xpidl_usage(argc, argv);
181 return 1;
182 }
183 break;
184 }
185 case 'I':
186 if (argv[i][2] == '\0' && i == argc) {
187 fputs("ERROR: missing path after -I\n", stderr);
188 xpidl_usage(argc, argv);
189 return 1;
190 }
191 inc = xpidl_malloc(sizeof *inc);
192 if (argv[i][2] == '\0') {
193 /* is it the -I foo form? */
194 inc->directory = argv[++i];
195 } else {
196 /* must be the -Ifoo form. Don't preincrement i. */
197 inc->directory = argv[i] + 2;
198 }
199#ifdef DEBUG_shaver_includes
200 fprintf(stderr, "adding %s to include path\n", inc->directory);
201#endif
202 inc->next = NULL;
203 *inc_tail = inc;
204 inc_tail = &inc->next;
205 break;
206 case 'o':
207 if (i == argc) {
208 fprintf(stderr, "ERROR: missing basename after -o\n");
209 xpidl_usage(argc, argv);
210 return 1;
211 }
212 file_basename = argv[++i];
213 explicit_output_filename = FALSE;
214 break;
215 case 'e':
216 if (i == argc) {
217 fprintf(stderr, "ERROR: missing basename after -e\n");
218 xpidl_usage(argc, argv);
219 return 1;
220 }
221 file_basename = argv[++i];
222 explicit_output_filename = TRUE;
223 break;
224 case 'm':
225 if (i + 1 == argc) {
226 fprintf(stderr, "ERROR: missing modename after -m\n");
227 xpidl_usage(argc, argv);
228 return 1;
229 }
230 if (mode) {
231 fprintf(stderr,
232 "ERROR: must specify exactly one mode "
233 "(first \"%s\", now \"%s\")\n", mode->mode,
234 argv[i + 1]);
235 xpidl_usage(argc, argv);
236 return 1;
237 }
238 mode = FindMode(argv[++i]);
239 if (!mode) {
240 fprintf(stderr, "ERROR: unknown mode \"%s\"\n", argv[i]);
241 xpidl_usage(argc, argv);
242 return 1;
243 }
244 break;
245 default:
246 fprintf(stderr, "unknown option %s\n", argv[i]);
247 xpidl_usage(argc, argv);
248 return 1;
249 }
250 }
251 done_options:
252 if (!mode) {
253 fprintf(stderr, "ERROR: must specify output mode\n");
254 xpidl_usage(argc, argv);
255 return 1;
256 }
257 if (argc != i + 1) {
258 fprintf(stderr, "ERROR: extra arguments after input file\n");
259 }
260
261 /*
262 * Don't try to process multiple files, given that we don't handle -o
263 * multiply.
264 */
265 if (xpidl_process_idl(argv[i], inc_head, file_basename, mode))
266 return 0;
267
268 return 1;
269}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use