mirror of https://github.com/CGAL/cgal
Extensions and better command line interface.
This commit is contained in:
parent
01b3d2a6be
commit
c4e09ed6ca
|
|
@ -15,8 +15,19 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stream.h>
|
||||
#include <config.h>
|
||||
#include <database.h>
|
||||
#include <config.h>
|
||||
|
||||
typedef char Switch;
|
||||
|
||||
#define NO_SWITCH 0
|
||||
#define MINUS_SWITCH 1
|
||||
#define PLUS_SWITCH 2
|
||||
|
||||
Switch trace_switch = NO_SWITCH;
|
||||
Switch noc_switch = NO_SWITCH;
|
||||
Switch nomc_switch = NO_SWITCH;
|
||||
Switch nosc_switch = NO_SWITCH;
|
||||
|
||||
|
||||
/* Declarations from syntax.y */
|
||||
|
|
@ -29,6 +40,147 @@ void yyparse();
|
|||
void init_scanner( FILE* in);
|
||||
|
||||
|
||||
/* Name the scanned file */
|
||||
/* ===================== */
|
||||
const char* file_name = "<stdin>";
|
||||
|
||||
|
||||
/* Taylored semantic functions used in syntax.y */
|
||||
/* ============================================ */
|
||||
|
||||
void handleMainComment( const Text& T) {
|
||||
if ( noc_switch || nomc_switch)
|
||||
return;
|
||||
if ( indentation_number() > 0) {
|
||||
cout << outdent;
|
||||
printComment( cout, T, true);
|
||||
cout << indent;
|
||||
} else {
|
||||
printComment( cout, T, true);
|
||||
}
|
||||
}
|
||||
|
||||
void handleComment( const Text& T) {
|
||||
if ( noc_switch || nosc_switch)
|
||||
return;
|
||||
cout << indent;
|
||||
printComment( cout, T, false);
|
||||
cout << outdent;
|
||||
}
|
||||
|
||||
void handleClass( const char* classname) {
|
||||
cout << newline;
|
||||
cout << "class " << classname << " {" << newline;
|
||||
cout << "public:" << newline;
|
||||
cout << indent;
|
||||
}
|
||||
|
||||
void handleClassEnd( void) {
|
||||
cout << outdent;
|
||||
cout << newline;
|
||||
cout << "}" << newline;
|
||||
}
|
||||
|
||||
void handleClassTemplate( const char* classname) {
|
||||
cout << newline;
|
||||
cout << "template < class ";
|
||||
const char* s = classname;
|
||||
while ( *s != 0 && *s != '<') s++;
|
||||
if ( *s == 0)
|
||||
printErrorMessage( TemplateParamExpectedError);
|
||||
else {
|
||||
int nesting = 0;
|
||||
s++;
|
||||
while ( nesting >= 0 && *s != 0) {
|
||||
switch ( *s) {
|
||||
case '<':
|
||||
nesting ++;
|
||||
cout << *s;
|
||||
break;
|
||||
case '>':
|
||||
nesting --;
|
||||
if ( nesting >= 0)
|
||||
cout << *s;
|
||||
break;
|
||||
case ',':
|
||||
if ( nesting == 0)
|
||||
cout << ", class ";
|
||||
else
|
||||
cout << *s;
|
||||
break;
|
||||
default:
|
||||
cout << *s;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if ( nesting >= 0)
|
||||
printErrorMessage( MalformedTemplateParamError);
|
||||
}
|
||||
cout << " >" << newline;
|
||||
cout << "class ";
|
||||
s = classname;
|
||||
while ( *s != 0 && *s != '<') {
|
||||
cout << *s;
|
||||
s++;
|
||||
}
|
||||
cout << " {" << newline;
|
||||
cout << "public:" << newline;
|
||||
cout << indent;
|
||||
}
|
||||
|
||||
void handleClassTemplateEnd( void) {
|
||||
cout << outdent;
|
||||
cout << newline;
|
||||
cout << "}" << newline;
|
||||
}
|
||||
|
||||
|
||||
void handleDeclaration( const char* decl) {
|
||||
cout << endl << newline;
|
||||
cout << decl;
|
||||
}
|
||||
|
||||
void handleFunctionDeclaration( const char* decl) {
|
||||
cout << endl << newline;
|
||||
cout << decl;
|
||||
}
|
||||
|
||||
void handleFunctionTemplateDeclaration( const char* templ, const char* decl) {
|
||||
cout << endl << newline;
|
||||
cout << "template < class ";
|
||||
const char* s = templ;
|
||||
int nesting = 0;
|
||||
while ( *s != 0) {
|
||||
switch ( *s) {
|
||||
case '<':
|
||||
nesting ++;
|
||||
cout << *s;
|
||||
break;
|
||||
case '>':
|
||||
nesting --;
|
||||
if ( nesting >= 0)
|
||||
cout << *s;
|
||||
break;
|
||||
case ',':
|
||||
if ( nesting == 0)
|
||||
cout << ", class ";
|
||||
else
|
||||
cout << *s;
|
||||
break;
|
||||
default:
|
||||
cout << *s;
|
||||
break;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if ( nesting != 0)
|
||||
printErrorMessage( MalformedTemplateParamError);
|
||||
cout << " >" << newline;
|
||||
cout << decl;
|
||||
}
|
||||
|
||||
|
||||
/* main */
|
||||
/* ==== */
|
||||
|
||||
|
|
@ -36,14 +188,6 @@ void init_scanner( FILE* in);
|
|||
#define MaxOptionalParameters 1000
|
||||
#define ErrParameters 10000
|
||||
|
||||
typedef char Switch;
|
||||
|
||||
#define NO_SWITCH 0
|
||||
#define MINUS_SWITCH 1
|
||||
#define PLUS_SWITCH 2
|
||||
|
||||
Switch trace_switch = NO_SWITCH;
|
||||
|
||||
/* this macro opens a block, in which the switch is detected */
|
||||
/* it must be closed with the macro endDetect() */
|
||||
#define detectSwitch( var, text) \
|
||||
|
|
@ -80,6 +224,13 @@ main( int argc, char **argv) {
|
|||
yydebug = 1;
|
||||
endDetect();
|
||||
|
||||
detectSwitch( noc_switch, "noc");
|
||||
endDetect();
|
||||
detectSwitch( nomc_switch, "nomc");
|
||||
endDetect();
|
||||
detectSwitch( nosc_switch, "nosc");
|
||||
endDetect();
|
||||
|
||||
detectSwitch( help_switch, "h");
|
||||
endDetect();
|
||||
detectSwitch( help_switch, "H");
|
||||
|
|
@ -101,7 +252,10 @@ main( int argc, char **argv) {
|
|||
(nParameters > MaxParameters) || (help_switch != NO_SWITCH)) {
|
||||
if (help_switch == NO_SWITCH)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: cgal_extact [-trace] [<infile> ...]" << endl;
|
||||
cerr << "Usage: cgal_extract [<options>] [<infile> ...]" << endl;
|
||||
cerr << " -nomc no main comments" << endl;
|
||||
cerr << " -nosc no sub comments" << endl;
|
||||
cerr << " -noc no comments (main and sub)" << endl;
|
||||
cerr << " -trace sets the `yydebug' variable of bison"
|
||||
<< endl;
|
||||
exit(1);
|
||||
|
|
@ -111,10 +265,12 @@ main( int argc, char **argv) {
|
|||
for ( i = 0; i < nParameters; i++) {
|
||||
FILE* in;
|
||||
if ( (in = fopen( parameters[i], "r")) == NULL) {
|
||||
fprintf( stderr, "\nbinsort: error: cannot open infile %s.\n",
|
||||
parameters[0]);
|
||||
fprintf( stderr,
|
||||
"\ncgal_extract: error: cannot open infile %s.\n",
|
||||
parameters[i]);
|
||||
exit(1);
|
||||
}
|
||||
file_name = parameters[i];
|
||||
init_scanner( in);
|
||||
yyparse();
|
||||
fclose( in);
|
||||
|
|
|
|||
Loading…
Reference in New Issue