VirtualBox

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

Last change on this file since 4837 was 1, checked in by vboxsync, 54 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 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
42#include "xpidl.h"
43
44static ModeData modes[] = {
45 {"header", "Generate C++ header", "h", xpidl_header_dispatch},
46 {"typelib", "Generate XPConnect typelib", "xpt", xpidl_typelib_dispatch},
47 {"doc", "Generate HTML documentation", "html", xpidl_doc_dispatch},
48 {"java", "Generate Java interface", "java", xpidl_java_dispatch},
49 {0, 0, 0, 0}
50};
51
52static ModeData *
53FindMode(char *mode)
54{
55 int i;
56 for (i = 0; modes[i].mode; i++) {
57 if (!strcmp(modes[i].mode, mode))
58 return &modes[i];
59 }
60 return NULL;
61}
62
63gboolean enable_debug = FALSE;
64gboolean enable_warnings = FALSE;
65gboolean verbose_mode = FALSE;
66gboolean emit_typelib_annotations = FALSE;
67gboolean explicit_output_filename = FALSE;
68
69/* The following globals are explained in xpt_struct.h */
70PRUint8 major_version = XPT_MAJOR_VERSION;
71PRUint8 minor_version = XPT_MINOR_VERSION;
72
73static char xpidl_usage_str[] =
74"Usage: %s -m mode [-w] [-v] [-t version number]\n"
75" [-I path] [-o basename | -e filename.ext] filename.idl\n"
76" -a emit annotations to typelib\n"
77" -w turn on warnings (recommended)\n"
78" -v verbose mode (NYI)\n"
79" -t create a typelib of a specific version number\n"
80" -I add entry to start of include path for ``#include \"nsIThing.idl\"''\n"
81" -o use basename (e.g. ``/tmp/nsIThing'') for output\n"
82" -e use explicit output filename\n"
83" -m specify output mode:\n";
84
85static void
86xpidl_usage(int argc, char *argv[])
87{
88 int i;
89 fprintf(stderr, xpidl_usage_str, argv[0]);
90 for (i = 0; modes[i].mode; i++) {
91 fprintf(stderr, " %-12s %-30s (.%s)\n", modes[i].mode,
92 modes[i].modeInfo, modes[i].suffix);
93 }
94}
95
96#if defined(XP_MAC) && defined(XPIDL_PLUGIN)
97#define main xpidl_main
98int xpidl_main(int argc, char *argv[]);
99#endif
100
101int main(int argc, char *argv[])
102{
103 int i;
104 IncludePathEntry *inc, *inc_head, **inc_tail;
105 char *file_basename = NULL;
106 ModeData *mode = NULL;
107 gboolean create_old_typelib = FALSE;
108
109 /* turn this on for extra checking of our code */
110/* IDL_check_cast_enable(TRUE); */
111
112 inc_head = xpidl_malloc(sizeof *inc);
113#ifndef XP_MAC
114 inc_head->directory = ".";
115#else
116 inc_head->directory = "";
117#endif
118 inc_head->next = NULL;
119 inc_tail = &inc_head->next;
120
121 for (i = 1; i < argc; i++) {
122 if (argv[i][0] != '-')
123 break;
124 switch (argv[i][1]) {
125 case '-':
126 argc++; /* pretend we didn't see this */
127 /* fall through */
128 case 0: /* - is a legal input filename (stdin) */
129 goto done_options;
130 case 'a':
131 emit_typelib_annotations = TRUE;
132 break;
133 case 'w':
134 enable_warnings = TRUE;
135 break;
136 case 'v':
137 verbose_mode = TRUE;
138 break;
139 case 't':
140 {
141 /* Parse for "-t version number" and store it into global boolean
142 * and string variables.
143 */
144 const gchar* typelib_version_string = NULL;
145
146 /*
147 * If -t is the last argument on the command line, we have a problem
148 */
149
150 if (i + 1 == argc) {
151 fprintf(stderr, "ERROR: missing version number after -t\n");
152 xpidl_usage(argc, argv);
153 return 1;
154 }
155
156 /* Do not allow more than one "-t" definition */
157 if (create_old_typelib) {
158 fprintf(stderr,
159 "ERROR: -t argument used twice. "
160 "Cannot specify more than one version\n");
161 xpidl_usage(argc, argv);
162 return 1;
163 }
164
165 /*
166 * Assume that the argument after "-t" is the version number string
167 * and search for it in our internal list of acceptable version
168 * numbers.
169 */
170 switch (XPT_ParseVersionString(argv[++i], &major_version,
171 &minor_version)) {
172 case XPT_VERSION_CURRENT:
173 break;
174 case XPT_VERSION_OLD:
175 create_old_typelib = TRUE;
176 break;
177 case XPT_VERSION_UNSUPPORTED:
178 fprintf(stderr, "ERROR: version \"%s\" not supported.\n",
179 argv[i]);
180 xpidl_usage(argc, argv);
181 return 1;
182 case XPT_VERSION_UNKNOWN:
183 default:
184 fprintf(stderr, "ERROR: version \"%s\" not recognised.\n",
185 argv[i]);
186 xpidl_usage(argc, argv);
187 return 1;
188 }
189 break;
190 }
191 case 'I':
192 if (argv[i][2] == '\0' && i == argc) {
193 fputs("ERROR: missing path after -I\n", stderr);
194 xpidl_usage(argc, argv);
195 return 1;
196 }
197 inc = xpidl_malloc(sizeof *inc);
198 if (argv[i][2] == '\0') {
199 /* is it the -I foo form? */
200 inc->directory = argv[++i];
201 } else {
202 /* must be the -Ifoo form. Don't preincrement i. */
203 inc->directory = argv[i] + 2;
204 }
205#ifdef DEBUG_shaver_includes
206 fprintf(stderr, "adding %s to include path\n", inc->directory);
207#endif
208 inc->next = NULL;
209 *inc_tail = inc;
210 inc_tail = &inc->next;
211 break;
212 case 'o':
213 if (i == argc) {
214 fprintf(stderr, "ERROR: missing basename after -o\n");
215 xpidl_usage(argc, argv);
216 return 1;
217 }
218 file_basename = argv[++i];
219 explicit_output_filename = FALSE;
220 break;
221 case 'e':
222 if (i == argc) {
223 fprintf(stderr, "ERROR: missing basename after -e\n");
224 xpidl_usage(argc, argv);
225 return 1;
226 }
227 file_basename = argv[++i];
228 explicit_output_filename = TRUE;
229 break;
230 case 'm':
231 if (i + 1 == argc) {
232 fprintf(stderr, "ERROR: missing modename after -m\n");
233 xpidl_usage(argc, argv);
234 return 1;
235 }
236 if (mode) {
237 fprintf(stderr,
238 "ERROR: must specify exactly one mode "
239 "(first \"%s\", now \"%s\")\n", mode->mode,
240 argv[i + 1]);
241 xpidl_usage(argc, argv);
242 return 1;
243 }
244 mode = FindMode(argv[++i]);
245 if (!mode) {
246 fprintf(stderr, "ERROR: unknown mode \"%s\"\n", argv[i]);
247 xpidl_usage(argc, argv);
248 return 1;
249 }
250 break;
251 default:
252 fprintf(stderr, "unknown option %s\n", argv[i]);
253 xpidl_usage(argc, argv);
254 return 1;
255 }
256 }
257 done_options:
258 if (!mode) {
259 fprintf(stderr, "ERROR: must specify output mode\n");
260 xpidl_usage(argc, argv);
261 return 1;
262 }
263 if (argc != i + 1) {
264 fprintf(stderr, "ERROR: extra arguments after input file\n");
265 }
266
267 /*
268 * Don't try to process multiple files, given that we don't handle -o
269 * multiply.
270 */
271 if (xpidl_process_idl(argv[i], inc_head, file_basename, mode))
272 return 0;
273
274 return 1;
275}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use