pjs/dom/tools/main.cpp

168 строки
4.3 KiB
C++
Исходник Обычный вид История

1998-05-13 00:30:45 +04: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
#include "ostream.h"
#include "string.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifndef XP_UNIX
1998-05-13 00:30:45 +04:00
#include <direct.h>
#endif
1998-05-13 00:30:45 +04:00
#include "IdlParser.h"
#include "Exceptions.h"
#include "IdlSpecification.h"
1998-05-19 09:21:21 +04:00
#include "XPCOMGen.h"
1998-06-04 03:32:26 +04:00
#include "JSStubGen.h"
1998-05-13 00:30:45 +04:00
int main(int argc, char *argv[])
{
1998-05-19 09:21:21 +04:00
int gen_xpcom = 0;
int gen_js = 0;
int gen_idl = 0;
int is_global = 0;
1998-05-19 09:21:21 +04:00
int op_dir = 0;
int op_dir_arg;
1998-05-13 00:30:45 +04:00
// extract filenames from argv
if (argc >= 2) {
1998-05-19 09:21:21 +04:00
int arg_cnt = 1;
1998-05-13 00:30:45 +04:00
1998-05-19 09:21:21 +04: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;
case 'g':
is_global = 1;
break;
1998-05-13 00:30:45 +04:00
}
1998-05-19 09:21:21 +04:00
++arg_cnt;
}
if (op_dir) {
struct stat sb;
if (stat(argv[op_dir_arg], &sb) == 0) {
#ifdef XP_UNIX
if (!(sb.st_mode & S_IFDIR)) {
#else
1998-05-19 09:21:21 +04:00
if (!(sb.st_mode & _S_IFDIR)) {
#endif
1998-05-19 09:21:21 +04:00
cout << "Creating directory " << argv[op_dir_arg] << " ...\n";
#ifdef XP_UNIX
if (mkdir(argv[op_dir_arg],S_IWGRP | S_IWOTH) < 0) {
#else
1998-05-19 09:21:21 +04:00
if (mkdir(argv[op_dir_arg]) < 0) {
#endif
1998-05-19 09:21:21 +04:00
cout << "WARNING: cannot create output directory [" << argv[op_dir_arg] << "]\n";
cout << "++++++++ using current directory\n";
1998-05-13 00:30:45 +04:00
}
}
}
}
1998-05-19 09:21:21 +04:00
for (int i = arg_cnt; i < argc; i++) {
1998-05-15 22:49:17 +04:00
1998-05-13 00:30:45 +04: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();
try {
1998-05-13 00:30:45 +04:00
parser->Parse(argv[i], *specification);
} catch(AbortParser &exc) {
cout << exc;
delete parser;
return -1;
1998-05-19 09:21:21 +04:00
} catch(FileNotFoundException &exc) {
cout << exc;
delete parser;
return -1;
1998-05-13 00:30:45 +04:00
} catch(...) {
cout << "Unknown Exception. Parser Aborted.";
}
1998-05-15 22:49:17 +04:00
1998-05-19 09:21:21 +04:00
if (gen_idl) {
cout << *specification;
}
if (gen_xpcom) {
XPCOMGen *xpcomgen = new XPCOMGen();
cout << "Generating XPCOM headers for " << argv[i] << ".\n";
try {
xpcomgen->Generate(argv[i], op_dir ? argv[op_dir_arg] :(char*)NULL,
*specification, is_global);
1998-05-19 09:21:21 +04:00
}
catch(CantOpenFileException &exc) {
cout << exc;
delete xpcomgen;
delete parser;
return -1;
}
delete xpcomgen;
}
1998-05-15 22:49:17 +04:00
1998-06-04 03:32:26 +04:00
if (gen_js) {
JSStubGen *jsgen = new JSStubGen();
cout << "Generating JavaScript stubs for " << argv[i] << ".\n";
1998-06-04 03:32:26 +04:00
try {
jsgen->Generate(argv[i], op_dir ? argv[op_dir_arg] : (char*)NULL,
*specification, is_global);
1998-06-04 03:32:26 +04:00
}
catch(CantOpenFileException &exc) {
cout << exc;
delete jsgen;
delete parser;
return -1;
}
delete jsgen;
}
1998-05-13 00:30:45 +04:00
delete parser;
}
return 0;
}
1998-05-19 09:21:21 +04: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";
1998-05-13 00:30:45 +04:00
return -1;
}