1998-12-03 09:33:59 +03:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
1998-11-28 19:52:24 +03:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1998-12-02 22:53:27 +03:00
|
|
|
/*
|
|
|
|
* Main xpidl program entry point.
|
|
|
|
*/
|
|
|
|
|
1998-11-24 00:02:31 +03:00
|
|
|
#include "xpidl.h"
|
|
|
|
|
1999-02-04 02:55:33 +03:00
|
|
|
static ModeData modes[] = {
|
1999-02-16 08:10:40 +03:00
|
|
|
{"header", "Generate C++ header", "h", xpidl_header_dispatch},
|
|
|
|
{"stub", "Generate C++ JS API stubs", "cpp", xpidl_stub_dispatch},
|
|
|
|
{"typelib", "Generate XPConnect typelib", "xpt", xpidl_typelib_dispatch},
|
|
|
|
{"doc", "Generate HTML documentation", "html", xpidl_doc_dispatch},
|
1999-02-04 02:55:33 +03:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static ModeData *
|
|
|
|
FindMode(char *mode)
|
|
|
|
{
|
|
|
|
int i;
|
1999-02-16 08:10:40 +03:00
|
|
|
for (i = 0; modes[i].mode; i++) {
|
|
|
|
if (!strcmp(modes[i].mode, mode))
|
1999-02-18 01:13:32 +03:00
|
|
|
return &modes[i];
|
1999-02-16 08:10:40 +03:00
|
|
|
}
|
1999-02-04 02:55:33 +03:00
|
|
|
return NULL;
|
1999-02-16 08:10:40 +03:00
|
|
|
}
|
1999-02-04 02:55:33 +03:00
|
|
|
|
1998-11-24 00:02:31 +03:00
|
|
|
gboolean enable_debug = FALSE;
|
|
|
|
gboolean enable_warnings = FALSE;
|
|
|
|
gboolean verbose_mode = FALSE;
|
|
|
|
|
1999-02-16 08:10:40 +03:00
|
|
|
static char xpidl_usage_str[] =
|
1999-03-29 02:01:33 +04:00
|
|
|
"Usage: %s [-m mode] [-w] [-v] [-I path] [-o basename] filename.idl\n"
|
1998-11-24 00:02:31 +03:00
|
|
|
" -w turn on warnings (recommended)\n"
|
1998-12-06 21:41:44 +03:00
|
|
|
" -v verbose mode (NYI)\n"
|
|
|
|
" -I add entry to start of include path for ``#include \"nsIThing.idl\"''\n"
|
1999-02-04 02:55:33 +03:00
|
|
|
" -o use basename (e.g. ``/tmp/nsIThing'') for output\n"
|
|
|
|
" -m specify output mode:\n";
|
1998-11-24 00:02:31 +03:00
|
|
|
|
1999-02-16 08:10:40 +03:00
|
|
|
static void
|
1998-11-24 00:02:31 +03:00
|
|
|
xpidl_usage(int argc, char *argv[])
|
|
|
|
{
|
1999-02-04 02:55:33 +03:00
|
|
|
int i;
|
1998-11-24 00:02:31 +03:00
|
|
|
fprintf(stderr, xpidl_usage_str, argv[0]);
|
1999-02-04 02:55:33 +03:00
|
|
|
for (i = 0; modes[i].mode; i++) {
|
|
|
|
fprintf(stderr, " %-12s %-30s (.%s)\n", modes[i].mode,
|
|
|
|
modes[i].modeInfo, modes[i].suffix);
|
|
|
|
}
|
1998-11-24 00:02:31 +03:00
|
|
|
}
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
/* XXXbe static */ char OOM[] = "ERROR: out of memory\n";
|
1999-02-16 08:10:40 +03:00
|
|
|
|
|
|
|
void *
|
|
|
|
xpidl_malloc(size_t nbytes)
|
|
|
|
{
|
|
|
|
void *p = malloc(nbytes);
|
|
|
|
if (!p) {
|
1999-02-18 01:13:32 +03:00
|
|
|
fputs(OOM, stderr);
|
|
|
|
exit(1);
|
1999-02-16 08:10:40 +03:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
xpidl_strdup(const char *s)
|
|
|
|
{
|
|
|
|
char *ns = strdup(s);
|
|
|
|
if (!ns) {
|
1999-02-18 01:13:32 +03:00
|
|
|
fputs(OOM, stderr);
|
|
|
|
exit(1);
|
1999-02-16 08:10:40 +03:00
|
|
|
}
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
1998-11-24 00:02:31 +03:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int i, idlfiles;
|
1999-02-16 08:10:40 +03:00
|
|
|
IncludePathEntry *inc, *inc_head, **inc_tail;
|
1998-12-14 21:47:39 +03:00
|
|
|
char *basename = NULL;
|
1999-02-04 02:55:33 +03:00
|
|
|
ModeData *mode = NULL;
|
1998-12-06 21:41:44 +03:00
|
|
|
|
1999-02-16 08:10:40 +03:00
|
|
|
inc_head = xpidl_malloc(sizeof *inc);
|
1998-12-06 21:41:44 +03:00
|
|
|
inc_head->directory = ".";
|
|
|
|
inc_head->next = NULL;
|
1999-02-16 08:10:40 +03:00
|
|
|
inc_tail = &inc_head->next;
|
1998-11-24 00:02:31 +03:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
1998-12-06 21:41:44 +03:00
|
|
|
if (argv[i][0] != '-')
|
|
|
|
break;
|
|
|
|
switch (argv[i][1]) {
|
1999-02-16 06:47:24 +03:00
|
|
|
case '-':
|
1999-02-18 20:43:38 +03:00
|
|
|
argc++; /* pretend we didn't see this */
|
1999-02-16 06:47:24 +03:00
|
|
|
/* fall through */
|
|
|
|
case 0: /* - is a legal input filename (stdin) */
|
|
|
|
goto done_options;
|
1998-12-06 21:41:44 +03:00
|
|
|
case 'w':
|
|
|
|
enable_warnings = TRUE;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose_mode = TRUE;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
if (i == argc) {
|
|
|
|
fputs("ERROR: missing path after -I\n", stderr);
|
1998-12-03 09:33:59 +03:00
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
1999-02-16 08:10:40 +03:00
|
|
|
inc = xpidl_malloc(sizeof *inc);
|
1999-02-17 04:17:52 +03:00
|
|
|
inc->directory = argv[++i];
|
1998-12-14 21:47:39 +03:00
|
|
|
#ifdef DEBUG_shaver_includes
|
1998-12-06 21:41:44 +03:00
|
|
|
fprintf(stderr, "adding %s to include path\n", inc->directory);
|
|
|
|
#endif
|
1999-02-16 08:10:40 +03:00
|
|
|
inc->next = NULL;
|
|
|
|
*inc_tail = inc;
|
1999-02-18 01:13:32 +03:00
|
|
|
inc_tail = &inc->next;
|
1998-12-06 21:41:44 +03:00
|
|
|
break;
|
1998-12-14 21:47:39 +03:00
|
|
|
case 'o':
|
|
|
|
if (i == argc) {
|
1999-02-04 02:55:33 +03:00
|
|
|
fprintf(stderr, "ERROR: missing basename after -o\n");
|
1998-12-14 21:47:39 +03:00
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
basename = argv[i + 1];
|
|
|
|
i++;
|
1999-01-11 19:56:45 +03:00
|
|
|
break;
|
1999-02-04 02:55:33 +03:00
|
|
|
case 'h': /* legacy stuff, already! */
|
|
|
|
mode = FindMode("header");
|
|
|
|
if (!mode) {
|
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (i == argc) {
|
|
|
|
fprintf(stderr, "ERROR: missing modename after -m\n");
|
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (mode) {
|
|
|
|
fprintf(stderr,
|
1999-02-17 04:17:52 +03:00
|
|
|
"ERROR: must specify exactly one mode "
|
1999-02-04 02:55:33 +03:00
|
|
|
"(first \"%s\", now \"%s\")\n", mode->mode,
|
|
|
|
argv[i + 1]);
|
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
mode = FindMode(argv[++i]);
|
|
|
|
if (!mode) {
|
|
|
|
fprintf(stderr, "ERROR: unknown mode \"%s\"\n", argv[i]);
|
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-12-06 21:41:44 +03:00
|
|
|
default:
|
1999-01-11 19:56:45 +03:00
|
|
|
fprintf(stderr, "unknown option %s\n", argv[i]);
|
1998-12-06 21:41:44 +03:00
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
1998-12-03 09:33:59 +03:00
|
|
|
}
|
1998-11-24 00:02:31 +03:00
|
|
|
}
|
1999-02-16 06:47:24 +03:00
|
|
|
done_options:
|
1999-02-04 02:55:33 +03:00
|
|
|
if (!mode) {
|
|
|
|
fprintf(stderr, "ERROR: must specify output mode\n");
|
1998-12-03 09:33:59 +03:00
|
|
|
xpidl_usage(argc, argv);
|
|
|
|
return 1;
|
1998-12-02 22:53:27 +03:00
|
|
|
}
|
|
|
|
|
1999-02-17 04:17:52 +03:00
|
|
|
for (idlfiles = 0; i < argc; i++)
|
1999-02-18 01:13:32 +03:00
|
|
|
idlfiles += xpidl_process_idl(argv[i], inc_head, basename, mode);
|
1999-02-16 08:10:40 +03:00
|
|
|
|
1998-12-14 21:47:39 +03:00
|
|
|
if (!idlfiles)
|
1998-12-03 09:33:59 +03:00
|
|
|
return 1;
|
1998-11-24 00:02:31 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|