1998-05-12 20:30:45 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// initialize cout
|
1999-03-06 00:33:35 +00:00
|
|
|
#include <ostream.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifndef XP_MAC
|
1998-05-12 20:30:45 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1999-03-06 00:33:35 +00:00
|
|
|
#else
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stat.h>
|
|
|
|
#include <iostream.h>
|
|
|
|
#endif
|
|
|
|
|
1999-06-27 09:34:52 +00:00
|
|
|
#if !defined XP_UNIX && !defined XP_MAC && ! defined XP_BEOS
|
1998-05-12 20:30:45 +00:00
|
|
|
#include <direct.h>
|
1998-12-15 03:24:59 +00:00
|
|
|
#endif
|
1999-03-06 00:33:35 +00:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#include <console.h>
|
|
|
|
#endif
|
|
|
|
|
1998-05-12 20:30:45 +00:00
|
|
|
#include "IdlParser.h"
|
|
|
|
#include "Exceptions.h"
|
|
|
|
#include "IdlSpecification.h"
|
1998-05-19 05:21:21 +00:00
|
|
|
#include "XPCOMGen.h"
|
1998-06-03 23:32:26 +00:00
|
|
|
#include "JSStubGen.h"
|
1998-05-12 20:30:45 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
1998-05-19 05:21:21 +00:00
|
|
|
int gen_xpcom = 0;
|
|
|
|
int gen_js = 0;
|
|
|
|
int gen_idl = 0;
|
1998-07-03 00:48:06 +00:00
|
|
|
int is_global = 0;
|
1998-05-19 05:21:21 +00:00
|
|
|
int op_dir = 0;
|
|
|
|
int op_dir_arg;
|
|
|
|
|
1999-03-06 00:33:35 +00:00
|
|
|
#ifdef XP_MAC
|
|
|
|
argc = ccommand(&argv);
|
|
|
|
#endif
|
|
|
|
|
1998-05-12 20:30:45 +00:00
|
|
|
// extract filenames from argv
|
|
|
|
if (argc >= 2) {
|
1998-05-19 05:21:21 +00:00
|
|
|
int arg_cnt = 1;
|
1998-05-12 20:30:45 +00:00
|
|
|
|
1998-05-19 05:21:21 +00:00
|
|
|
while ((arg_cnt < argc) && (*argv[arg_cnt] == '-')) {
|
|
|
|
switch (*(argv[arg_cnt]+1)) {
|
|
|
|
case 'd':
|
|
|
|
op_dir = 1;
|
|
|
|
op_dir_arg = ++arg_cnt;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
gen_xpcom = 1;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
gen_js = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
gen_idl = 1;
|
|
|
|
break;
|
1998-07-03 00:48:06 +00:00
|
|
|
case 'g':
|
|
|
|
is_global = 1;
|
|
|
|
break;
|
1998-05-12 20:30:45 +00:00
|
|
|
}
|
1998-05-19 05:21:21 +00:00
|
|
|
++arg_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op_dir) {
|
|
|
|
struct stat sb;
|
|
|
|
if (stat(argv[op_dir_arg], &sb) == 0) {
|
1999-06-27 09:34:52 +00:00
|
|
|
#if defined XP_UNIX || defined XP_MAC || defined XP_BEOS
|
1998-12-15 03:24:59 +00:00
|
|
|
if (!(sb.st_mode & S_IFDIR)) {
|
|
|
|
#else
|
1998-05-19 05:21:21 +00:00
|
|
|
if (!(sb.st_mode & _S_IFDIR)) {
|
1998-12-15 03:24:59 +00:00
|
|
|
#endif
|
1998-05-19 05:21:21 +00:00
|
|
|
cout << "Creating directory " << argv[op_dir_arg] << " ...\n";
|
1999-06-27 09:34:52 +00:00
|
|
|
#if defined XP_UNIX || defined XP_BEOS
|
1998-12-15 03:24:59 +00:00
|
|
|
if (mkdir(argv[op_dir_arg],S_IWGRP | S_IWOTH) < 0) {
|
1999-03-06 00:33:35 +00:00
|
|
|
#elif defined XP_MAC
|
|
|
|
if (mkdir(argv[op_dir_arg], 0) < 0) { // mode is ignored
|
1998-12-15 03:24:59 +00:00
|
|
|
#else
|
1998-05-19 05:21:21 +00:00
|
|
|
if (mkdir(argv[op_dir_arg]) < 0) {
|
1998-12-15 03:24:59 +00:00
|
|
|
#endif
|
1998-05-19 05:21:21 +00:00
|
|
|
cout << "WARNING: cannot create output directory [" << argv[op_dir_arg] << "]\n";
|
|
|
|
cout << "++++++++ using current directory\n";
|
1998-05-12 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-19 05:21:21 +00:00
|
|
|
for (int i = arg_cnt; i < argc; i++) {
|
1998-05-15 18:49:17 +00:00
|
|
|
|
1998-05-12 20:30:45 +00:00
|
|
|
// create a specification object. On parser termination it will
|
|
|
|
// contain all parsed interfaces
|
|
|
|
IdlSpecification *specification = new IdlSpecification();
|
|
|
|
|
|
|
|
// initialize and run the parser
|
|
|
|
IdlParser *parser = new IdlParser();
|
1998-06-12 22:34:39 +00:00
|
|
|
try {
|
1998-05-12 20:30:45 +00:00
|
|
|
parser->Parse(argv[i], *specification);
|
|
|
|
} catch(AbortParser &exc) {
|
|
|
|
cout << exc;
|
|
|
|
delete parser;
|
|
|
|
return -1;
|
1998-05-19 05:21:21 +00:00
|
|
|
} catch(FileNotFoundException &exc) {
|
|
|
|
cout << exc;
|
|
|
|
delete parser;
|
|
|
|
return -1;
|
1998-05-12 20:30:45 +00:00
|
|
|
} catch(...) {
|
|
|
|
cout << "Unknown Exception. Parser Aborted.";
|
|
|
|
}
|
1998-05-15 18:49:17 +00:00
|
|
|
|
1998-05-19 05:21:21 +00:00
|
|
|
if (gen_idl) {
|
|
|
|
cout << *specification;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gen_xpcom) {
|
|
|
|
XPCOMGen *xpcomgen = new XPCOMGen();
|
|
|
|
|
1998-06-12 22:34:39 +00:00
|
|
|
cout << "Generating XPCOM headers for " << argv[i] << ".\n";
|
|
|
|
try {
|
1998-12-15 03:24:59 +00:00
|
|
|
xpcomgen->Generate(argv[i], op_dir ? argv[op_dir_arg] :(char*)NULL,
|
1998-07-03 00:48:06 +00:00
|
|
|
*specification, is_global);
|
1998-05-19 05:21:21 +00:00
|
|
|
}
|
|
|
|
catch(CantOpenFileException &exc) {
|
|
|
|
cout << exc;
|
|
|
|
delete xpcomgen;
|
|
|
|
delete parser;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
delete xpcomgen;
|
|
|
|
}
|
1998-05-15 18:49:17 +00:00
|
|
|
|
1998-06-03 23:32:26 +00:00
|
|
|
if (gen_js) {
|
|
|
|
JSStubGen *jsgen = new JSStubGen();
|
|
|
|
|
1998-06-12 22:34:39 +00:00
|
|
|
cout << "Generating JavaScript stubs for " << argv[i] << ".\n";
|
1998-06-03 23:32:26 +00:00
|
|
|
try {
|
1998-12-15 03:24:59 +00:00
|
|
|
jsgen->Generate(argv[i], op_dir ? argv[op_dir_arg] : (char*)NULL,
|
1998-07-03 00:48:06 +00:00
|
|
|
*specification, is_global);
|
1998-06-03 23:32:26 +00:00
|
|
|
}
|
|
|
|
catch(CantOpenFileException &exc) {
|
|
|
|
cout << exc;
|
|
|
|
delete jsgen;
|
|
|
|
delete parser;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
delete jsgen;
|
|
|
|
}
|
|
|
|
|
1998-05-12 20:30:45 +00:00
|
|
|
delete parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-05-19 05:21:21 +00:00
|
|
|
cout << "+++ERROR: no file specified\n";
|
|
|
|
goto usage;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
usage:
|
|
|
|
cout << "Usage: [options] [-d outputdir] filename [filename...]\n";
|
|
|
|
cout << "Options:\n";
|
|
|
|
cout << "-x Spit out XPCOM interfaces\n";
|
|
|
|
cout << "-j Spit out JavaScript stub files\n";
|
|
|
|
cout << "-p Echo normalized idl to stdout\n";
|
1999-05-28 01:25:31 +00:00
|
|
|
cout << "-g used for global objects\n";
|
1998-05-12 20:30:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|