1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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
15 * The Original Code is mozilla.org code.
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.
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 MPL, 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 MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 * Main xpidl program entry point.
44 static 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
},
56 for (i
= 0; modes
[i
].mode
; i
++) {
57 if (!strcmp(modes
[i
].mode
, mode
))
63 gboolean enable_debug
= FALSE
;
64 gboolean enable_warnings
= FALSE
;
65 gboolean verbose_mode
= FALSE
;
66 gboolean emit_typelib_annotations
= FALSE
;
67 gboolean explicit_output_filename
= FALSE
;
70 /* The following globals are explained in xpt_struct.h */
71 PRUint8 major_version
= XPT_MAJOR_VERSION
;
72 PRUint8 minor_version
= XPT_MINOR_VERSION
;
74 static char xpidl_usage_str
[] =
75 "Usage: %s -m mode [-w] [-v] [-t version number] [-d filename.pp]\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 " -d write dependencies (requires -e)\n"
85 " -m specify output mode:\n";
88 xpidl_usage(int argc
, char *argv
[])
91 fprintf(stderr
, xpidl_usage_str
, argv
[0]);
92 for (i
= 0; modes
[i
].mode
; i
++) {
93 fprintf(stderr
, " %-12s %-30s (.%s)\n", modes
[i
].mode
,
94 modes
[i
].modeInfo
, modes
[i
].suffix
);
98 int main(int argc
, char *argv
[])
101 IncludePathEntry
*inc
, *inc_head
, **inc_tail
;
102 char *file_basename
= NULL
;
103 ModeData
*mode
= NULL
;
104 gboolean create_old_typelib
= FALSE
;
106 /* turn this on for extra checking of our code */
107 /* IDL_check_cast_enable(TRUE); */
109 inc_head
= xpidl_malloc(sizeof *inc
);
110 inc_head
->directory
= ".";
111 inc_head
->next
= NULL
;
112 inc_tail
= &inc_head
->next
;
114 for (i
= 1; i
< argc
; i
++) {
115 if (argv
[i
][0] != '-')
117 switch (argv
[i
][1]) {
119 argc
++; /* pretend we didn't see this */
121 case 0: /* - is a legal input filename (stdin) */
124 emit_typelib_annotations
= TRUE
;
127 enable_warnings
= TRUE
;
134 /* Parse for "-t version number" and store it into global boolean
135 * and string variables.
137 const gchar
* typelib_version_string
= NULL
;
140 * If -t is the last argument on the command line, we have a problem
144 fprintf(stderr
, "ERROR: missing version number after -t\n");
145 xpidl_usage(argc
, argv
);
149 /* Do not allow more than one "-t" definition */
150 if (create_old_typelib
) {
152 "ERROR: -t argument used twice. "
153 "Cannot specify more than one version\n");
154 xpidl_usage(argc
, argv
);
159 * Assume that the argument after "-t" is the version number string
160 * and search for it in our internal list of acceptable version
163 switch (XPT_ParseVersionString(argv
[++i
], &major_version
,
165 case XPT_VERSION_CURRENT
:
167 case XPT_VERSION_OLD
:
168 create_old_typelib
= TRUE
;
170 case XPT_VERSION_UNSUPPORTED
:
171 fprintf(stderr
, "ERROR: version \"%s\" not supported.\n",
173 xpidl_usage(argc
, argv
);
175 case XPT_VERSION_UNKNOWN
:
177 fprintf(stderr
, "ERROR: version \"%s\" not recognised.\n",
179 xpidl_usage(argc
, argv
);
185 if (argv
[i
][2] == '\0' && i
== argc
) {
186 fputs("ERROR: missing path after -I\n", stderr
);
187 xpidl_usage(argc
, argv
);
190 inc
= xpidl_malloc(sizeof *inc
);
191 if (argv
[i
][2] == '\0') {
192 /* is it the -I foo form? */
193 inc
->directory
= argv
[++i
];
195 /* must be the -Ifoo form. Don't preincrement i. */
196 inc
->directory
= argv
[i
] + 2;
198 #ifdef DEBUG_shaver_includes
199 fprintf(stderr
, "adding %s to include path\n", inc
->directory
);
203 inc_tail
= &inc
->next
;
207 fprintf(stderr
, "ERROR: missing basename after -o\n");
208 xpidl_usage(argc
, argv
);
211 file_basename
= argv
[++i
];
212 explicit_output_filename
= FALSE
;
216 fprintf(stderr
, "ERROR: missing basename after -e\n");
217 xpidl_usage(argc
, argv
);
220 file_basename
= argv
[++i
];
221 explicit_output_filename
= TRUE
;
224 if (!explicit_output_filename
) {
225 fprintf(stderr
, "ERROR: -d requires -e\n");
226 xpidl_usage(argc
, argv
);
230 fprintf(stderr
, "ERROR: missing filename after -d\n");
231 xpidl_usage(argc
, argv
);
234 deps
= fopen(argv
[++i
], "w");
236 fprintf(deps
, "%s:", file_basename
);
240 fprintf(stderr
, "ERROR: missing modename after -m\n");
241 xpidl_usage(argc
, argv
);
246 "ERROR: must specify exactly one mode "
247 "(first \"%s\", now \"%s\")\n", mode
->mode
,
249 xpidl_usage(argc
, argv
);
252 mode
= FindMode(argv
[++i
]);
254 fprintf(stderr
, "ERROR: unknown mode \"%s\"\n", argv
[i
]);
255 xpidl_usage(argc
, argv
);
260 fprintf(stderr
, "unknown option %s\n", argv
[i
]);
261 xpidl_usage(argc
, argv
);
267 fprintf(stderr
, "ERROR: must specify output mode\n");
268 xpidl_usage(argc
, argv
);
273 * Don't try to process multiple files, given that we don't handle -o
277 i
= xpidl_process_idl(argv
[i
], inc_head
, file_basename
, mode
);
280 fprintf(stderr
, "ERROR: extra arguments after input file\n");
282 fprintf(stderr
, "ERROR: no file to process\n");