diff --git a/Packages/Manual_tools/src/Makefile b/Packages/Manual_tools/src/Makefile new file mode 100644 index 00000000000..87b97ea46d4 --- /dev/null +++ b/Packages/Manual_tools/src/Makefile @@ -0,0 +1,187 @@ +# Makefile +# =================================== +# V 1.00 17.08.1995 Lutz Kettner +# Project: CGAL merger tool for the specification task +# V 1.1 22.11.1996 Lutz Kettner +# Project: tools around the CGAL manual writing task. +# extract, check, HTML conversion. +# V 1.2 03.12.1996 Lutz Kettner +# Tools renamed from CGAL to CC. Relates to cc_manual.sty R2.1. +# +# $Release:$, $Date$ + +# ======================================================= +# Installation: chose the appropriate compiler and paths: +# ======================================================= + +# Installation directory (where to put the executables) +# Only necessary if the make target 'install' is used for installation. +#INSTALL_DIR = /usr/bin +INSTALL_DIR = $(PUBLIC)/$(SYSTEM)/bin # local settings on my machine + +# Include path (needs probably no adaption) +INCL = -I. + +# Path for the HTML conversion tools for the default configuration files. +# This path will be compiled into the cc_extract_html program and used for +# the installation. +# The same variable has to be configured in the cc_manual_to_html script. +# The path must terminate with a slash. +#HTML_DEFAULT_PATH = +HTML_DEFAULT_PATH = /pub/local/CGAL/Tools/html_config_files/ + +# Three supported C++ compilers: +# Gnu g++ 2.6.3 (or above) +# Sun Pro CC 4.0.1 (or above) +# SGI CC 4.0 (or above) +# The compiler call: +#CPP = g++ +CPP = CC + +# The C++ compiler options (optimization, debugging, warnings, includes) +#CPPOPT = -O -Wall $(INCL) # Gnu +#CPPOPT = -O +w $(INCL) # Sgi +CPPOPT = -O +w $(INCL) # Sun + +# A C compiler: +# Gnu gcc 2.6.3 (or above) +# System cc +#CC = gcc +CC = cc + +# The C compiler options +# CCOPT = $(CPPOPT) # Gnu +CCOPT = -O $(INCL) # Sun, SGI + +# flex, bison, compile and link commands +FLEX = flex -t -8 +BISON = bison -d -t -v +COMPILE = $(CPP) $(CPPOPT) -c +LINK = $(CPP) $(CPPOPT) + +# The flex and bison output might produce a lot of warnings with +# the C++ compiler (Sgi). Special options switch these messages off. +#XCOMPILE = $(COMPILE) # Gnu +#XCOMPILE = $(COMPILE) -woff 3203 # SGI +XCOMPILE = $(COMPILE) # Sun + +# Default targets to make: +ALL = cc_extract cc_build_checker cc_extract_html cc_index_sort + +# ======================================================= +# Installation: Nothing else below this line. +# ======================================================= + +# all the files that have to be copied into a directory in the $PATH +PROGRAM_FILES = cc_extract cc_build_checker cc_extract_html cc_index_sort + +# all the files that have to be moved into a directory in the $PATH +SCRIPT_FILES = cc_check cc_manual_to_html + +# all the files for the HTML config directory +HTML_CONFIG_FILES = html_config_files/* + # cc_anchor_footer cc_anchor_header cc_biblio_footer \ + # cc_biblio_header cc_index_footer cc_index_header \ + # cc_manual_footer cc_manual_header cc_toc_footer \ + # cc_toc_header + +# default rule +all: $(ALL) + + +# General Modules +# ========================== +database.o : database.C database.h config.h + $(COMPILE) -o database.o database.C + +# Extraction and Checking +# ========================== +# parser and scanner +# -------------------- +extract_lex.c : extract_lex.yy + $(FLEX) extract_lex.yy >extract_lex.c + +extract_syntax.tab.c extract_syntax.tab.h : extract_syntax.y + $(BISON) extract_syntax.y + +# modules +# -------------------- +extract_lex.o : extract_lex.c extract_syntax.tab.h database.h config.h + $(XCOMPILE) -o extract_lex.o extract_lex.c + +extract_syntax.o : extract_syntax.tab.c extract_syntax.tab.h \ + database.h config.h + $(XCOMPILE) -o extract_syntax.o extract_syntax.tab.c + +cc_extract.o : cc_extract.C database.h config.h + $(COMPILE) -o cc_extract.o cc_extract.C + +cc_build_checker.o : cc_build_checker.C database.h config.h + $(COMPILE) -o cc_build_checker.o cc_build_checker.C + +# program +# -------------------- +OBJ = extract_lex.o extract_syntax.o database.o +HEADER = extract_syntax.tab.h database.h config.h + +cc_extract : $(OBJ) $(HEADER) cc_extract.o + $(LINK) -o cc_extract cc_extract.o $(OBJ) + +cc_build_checker : $(OBJ) $(HEADER) cc_build_checker.o + $(LINK) -o cc_build_checker cc_build_checker.o $(OBJ) + + +# Converting to HTML +# ========================== +# parser and scanner +# -------------------- +html_lex.c : html_lex.yy + $(FLEX) html_lex.yy >html_lex.c + +html_syntax.tab.c html_syntax.tab.h : html_syntax.y + $(BISON) html_syntax.y + +# modules +# -------------------- +html_lex.o : html_lex.c html_syntax.tab.h database.h html_config.h + $(XCOMPILE) -o html_lex.o html_lex.c + +html_syntax.o : html_syntax.tab.c html_syntax.tab.h database.h html_config.h + $(XCOMPILE) -o html_syntax.o html_syntax.tab.c + +cc_extract_html.o : cc_extract_html.C database.h html_config.h + $(COMPILE) -DHTML_DEFAULT_PATH=\"$(HTML_DEFAULT_PATH)\" -o cc_extract_html.o cc_extract_html.C + + +# program +# -------------------- +OBJHTML = html_lex.o html_syntax.o database.o +HEADERHTML = html_syntax.tab.h database.h html_config.h + +cc_extract_html : $(OBJHTML) $(HEADERHTML) cc_extract_html.o + $(LINK) -o cc_extract_html cc_extract_html.o $(OBJHTML) + + +# Sort Program to Sort the Index +# ============================== +cc_index_sort : cc_index_sort.c + $(CC) $(CCOPT) -o cc_index_sort cc_index_sort.c + +# Installation Targets +# ==================== +install: + mv $(PROGRAM_FILES) $(INSTALL_DIR) + cp $(SCRIPT_FILES) $(INSTALL_DIR) + cp $(HTML_CONFIG_FILES) $(HTML_DEFAULT_PATH) + +# Auxiliary Targets +# ================= +clean : + rm *.o extract_lex.c extract_syntax.output extract_syntax.tab.h \ + extract_syntax.tab.c html_lex.c html_syntax.output \ + html_syntax.tab.h html_syntax.tab.c + +cleanall : clean + rm cc_build_checker cc_extract cc_extract_html + if (-d Templates.DB) rm -r Templates.DB + if (-d ii_files) rm -r ii_files diff --git a/Packages/Manual_tools/src/buffer.C b/Packages/Manual_tools/src/buffer.C new file mode 100644 index 00000000000..4b41e6ff048 --- /dev/null +++ b/Packages/Manual_tools/src/buffer.C @@ -0,0 +1,276 @@ +/************************************************************************** + + database.C + ============================================================= + Project : CGAL merger tool for the specification task + Function : Datastructures for the database extracted from + the TeX and C++ code mixed files. + System : C++ (g++) + Author : (c) 1995 Lutz Kettner + Revision : $Revision$ + Date : $Date$ + +**************************************************************************/ + +// Other modules needed: +// ===================== +#define ADT_INCLUDE_CC 1 +#include +#include + + +// Substitute old style malloc, realloc, strdup ... +// ================================================ +char* newstr( const char* src) { + ADT_Assert( src); + if ( ! src) + return 0; + char* s = new char[ strlen( src) + 1]; + strcpy( s, src); + return s; +} + + +// Class definitions: +// ============================================== +int printComment( ostream &out, const Text& T, bool leadingLine, bool HTML) { + InListFIter< TextToken> words( (Text&)T); + int width = MaxTextWidth - indentation_number() - 3; + int w = width; + int state = 0; // 0 = start, 1 = after token, 2 = spaces + // 3 = one newline (and spaces), 4 = newlines + ForAll( words) { + switch ( state) { + case 0: + if ( !words->isSpace) { + if ( leadingLine) + out << endl; + out << indNewline << (HTML ? "" : "// ") << words->string; + w -= words->len; + state = 1; + } + break; + case 1: + if ( !words->isSpace || words->len > 0) { + if ( !words->isSpace) { + if ((words->len > w) && (w != width)) { + w = width; + out << indNewline << (HTML ? "" : "// "); + } + out << words->string; + w -= words->len; + } else { + if ( words->string[0] == '\n') + state = 3; + else + state = 2; + } + } + break; + case 2: + if ( !words->isSpace || words->len > 0) { + if ( !words->isSpace) { + if ((words->len >= w) && (w != width)) { + w = width; + out << indNewline << (HTML ? "" : "// "); + } else { + out << ' '; + w--; + } + out << words->string; + w -= words->len; + state = 1; + } else { + if ( words->string[0] == '\n') + state = 3; + } + } + break; + case 3: + if ( !words->isSpace || words->len > 0) { + if ( !words->isSpace) { + if ((words->len >= w) && (w != width)) { + w = width; + out << indNewline << (HTML ? "" : "// "); + } else { + out << ' '; + w--; + } + out << words->string; + w -= words->len; + state = 1; + } else { + if ( words->string[0] == '\n') + state = 4; + } + } + break; + case 4: + if ( !words->isSpace || words->len > 0) { + if ( !words->isSpace) { + if (HTML) + out << indNewline << "

"; + out << indNewline << (HTML ? "" : "// "); + out << indNewline << (HTML ? "" : "// "); + w = width; + out << words->string; + w -= words->len; + state = 1; + } + } + break; + } + } + return state; +} + +int printTrueComment( ostream &out, const Text& T, bool leadingLine) { + InListFIter< TextToken> words( (Text&)T); + int state = 0; // 0 = start, 1 = spaces at start, 2 = at least one token + int spaces = 0; + ForAll( words) { + switch ( state) { + case 0: + if ( !words->isSpace) { + if ( leadingLine) + out << endl; + out << indNewline << "// " << words->string; + state = 1; + } else { + if ( words->string[0] != '\n') { + state = 1; + spaces = 1; + } + } + break; + case 1: + if ( !words->isSpace) { + if ( leadingLine) + out << endl; + out << indNewline << "// "; + while ( spaces--) + out << ' '; + out << words->string; + } else { + if ( words->string[0] == '\n') + state = 0; + else + spaces++; + } + break; + case 2: + if ( words->isSpace && ( words->string[0] == '\n')) + out << indNewline << "// "; + else + out << words->string; + break; + } + } + return state; +} + + +ostream& +operator<< (ostream& out, const TextToken& t) { + out << t.isSpace << ", "; + printString( out, t.string, t.len); + return out; +} + +istream& +operator>> (istream& in, TextToken& t) { + char c; + int e; + in >> e >> c; // c == ',' + t.isSpace = bool( e); + delete[] t.string; + t.len = scanString( in, t.string); + return in; +} + +ostream& +operator<< (ostream& out, const Declaration& d) { + out << "Declaration[" << indent << indNewline; + out << d.type << indNewline; + printString( out, d.returnType); + out << indNewline; + printString( out, d.name); + out << indNewline; + printString( out, d.templateParams); + out << indNewline; + printString( out, d.parameters); + out << indNewline; + out << d.comment << indNewline; + out << d.spec << outdent << indNewline; + out << ']'; + return out; +} + +istream& +operator>> (istream& in, Declaration& ) { + return in; +} + +ostream& +operator<< (ostream& out, const Specification& s) { + out << "Specification[" << indent << indNewline; + out << s.type << indNewline; + out << s.decl << indNewline; + out << s.comment << outdent << indNewline; + out << ']'; + return out; +} + +istream& +operator>> (istream& in, Specification& ) { + return in; +} + +// Auxiliary function definitions +// ============================================== +/* ... + char* catString( const char* r, const char* s, int l, int m) { + char *p; + if ( l < 0) + l = strlen( r); + if ( m < 0) + m = strlen( s); + p = (char *)malloc( l + m + 1); + ADT_Assert( p != NULL); + memcpy( p, r, l); + memcpy( p+l, s, m); + p[ l+m] = 0; + return( p); + } +... */ + +void printString( ostream &out, const char *s, int len) { + if ( len < 0) + len = strlen( s); + out << len; + if ( len > 0) + out << ", " << s; +} + +int scanString( istream &in, char*& s) { + int len; + int i; + in >> len; + if ( len > 0) { + s = new char[ len + 1]; + ADT_Assert( s != NULL); + in.get( s[0]); // the comma + in.get( s[0]); // the space + for ( i=0; i +#include +#undef LK_RestrictedOverloading +#define LK_RestrictedOverloading 0 +#include +#include + +// Class declarations: +// ============================================== +// Top Level Structure: +// typedef InList SpecificationList; // typedef is postponed. +struct Specification; + +// Parts of a specification: +struct Declaration; +class TextToken; +// typedef InList< TextToken> Text; // typedef is postponed. + + +// Substitute old style malloc, realloc, strdup ... +// ================================================ +template < class T, class I> +T* renew( const T* old, I old_size, I new_size); + +template < class T, class I> +T* renew( const T* old, I old_size, I new_size) { + ADT_Assert( old); + ADT_Assert( strlen( old) == size_t(old_size - 1)); + ADT_Assert( new_size > old_size); + T* cpy = new T[ size_t(new_size)]; + if ( old && old_size > 0) { + size_t min = ( old_size < new_size ? old_size : new_size); + memcpy( cpy, old, min * sizeof( T)); + // delete[] old; + } + return cpy; +} + +char* newstr( const char* src); + + +// Class specifications: +// ============================================== + +// Auxiliary class: +// ------------------------------------ +class Buffer { + size_t fibo1; // fibonacci numbers to increase buffer in + size_t fibo2; // the case of an overflow. + size_t len; + char* data; +public: + Buffer() { + fibo1 = 610; + fibo2 = 987; + len = 0; + data = new char[ fibo2]; + *data = '\0'; + // Assert( data != NULL); + } + ~Buffer() { + // ADT_Assert( fibo2 > fibo1); // SGI complains in the test_suit + // ADT_Assert( fibo2 > len); // Gnu complains in the test_suit + ADT_Assert( strlen( data) == len); + ADT_Assert( data[ len] == '\0'); + delete[] data; + } + Buffer( const Buffer& t) { + ADT_Assert( t.data[ t.len] == '\0'); + fibo1 = t.fibo1; + fibo2 = t.fibo2; + len = t.len; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + data = newstr( t.data); // ============== ?? FALSCH ERROR !!!! + cerr << "Error: Buffer copy constructor called." << endl; + exit( 6); + } + Buffer& operator=( const Buffer& t) { + if( this != &t) { // beware of this=t; see Stroustrup pp.238 + delete[] data; + t.data[ t.len] = '\0'; + fibo1 = t.fibo1; + fibo2 = t.fibo2; + len = t.len; + data = newstr( t.data);// ============== ?? FALSCH ERROR !!!! + } else { + fibo1 = 610; + fibo2 = 987; + len = 0; + data = new char[ fibo2]; + } + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + cerr << "Error: Buffer assignment operator called." << endl; + exit( 6); + return *this; + } + void add( const char* s, int l = -1) { + ADT_Assert( data[ len] == '\0'); + int tmp; + if ( l < 0) + l = strlen( s); + // ADT_Assert( l == (int)strlen( s)); // this is definitly wrong! + if ( len + l >= fibo2) { // increase buffer + do { + tmp = fibo2; + fibo2 += fibo1; + fibo1 = tmp; + } while ( len + l >= fibo2); // increase buffer + data = renew( data, fibo1, fibo2); + // Assert( data != NULL); + } + memcpy( data + len, s, l); + len += l; + data[ len] = '\0'; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + } + void add( const Buffer& buf) { + add( buf.string(), buf.length()); + } + void add( const Buffer* buf) { + add( buf->string(), buf->length()); + } + void add( char c) { + ADT_Assert( data[ len] == '\0'); + if ( len + 1 >= fibo2) { // increase buffer + int tmp = fibo2; + fibo2 += fibo1; + fibo1 = tmp; + data = renew( data, fibo1, fibo2); + // Assert( data != NULL); + } + data[ len++] = c; + data[ len] = '\0'; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + } + void prepend( const char* s, int l = -1) { + ADT_Assert( s); + ADT_Assert( data[ len] == '\0'); + int tmp; + if ( l < 0) + l = strlen( s); + ADT_Assert( l == (int)strlen( s)); + if ( len + l >= fibo2) { // increase buffer + do { + tmp = fibo2; + fibo2 += fibo1; + fibo1 = tmp; + } while ( len + l >= fibo2); // increase buffer + data = renew( data, fibo1, fibo2); + // Assert( data != NULL); + } + // relocate current text + int i; + for ( i = len-1; i >= 0; i--) + data[i+l] = data[ i]; + memcpy( data, s, l); + len += l; + data[ len] = '\0'; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + } + void prepend( char c) { + ADT_Assert( data[ len] == '\0'); + if ( len + 1 >= fibo2) { // increase buffer + int tmp = fibo2; + fibo2 += fibo1; + fibo1 = tmp; + data = renew( data, fibo1, fibo2); + // Assert( data != NULL); + } + // relocate current text + int i; + for ( i = len; i > 0; i--) + data[i] = data[ i-1]; + data[ 0] = c; + len++; + data[ len] = '\0'; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + } + void cut( int i) { + ADT_Assert( data[ len] == '\0'); + ADT_Assert( i >= 0); + if ( (int)len >= i) { + len -= i; + } + data[ len] = '\0'; + ADT_Assert( fibo2 > fibo1); + ADT_Assert( fibo2 > len); + } + const char* string() const { + ADT_Assert( data[ len] == '\0'); + ADT_Assert( len < fibo2); + return data; + } + void set( int i, char c) { + ADT_Assert( i >= 0); + ADT_Assert( size_t(i) < len); + data[i] = c; + } + int length() const { + ADT_Assert( data[ len] == '\0'); + ADT_Assert( len < fibo2); + return (int)len; + } + void flush() { + ADT_Assert( data[ len] == '\0'); + ADT_Assert( len < fibo2); + len = 0; + *data = '\0'; + } +}; + +class TextToken : public ListLink{ +public: + bool isSpace; + int len; + char* string; + TextToken() { + isSpace = false; + len = 0; + string = 0; + } + TextToken( const char* s, int l = -1, bool space = false) { + isSpace = space; + if ( s) { + if ( l < 0) + len = strlen( s); + else + len = l; + string = newstr( s); + } else { + string = newstr( ""); + len = 0; + } + } + TextToken( const TextToken& t) { + isSpace = t.isSpace; + len = t.len; + string = newstr( t.string); + } + ~TextToken() { + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + delete[] string; + } + TextToken& operator=( const TextToken& t) { + if( this != &t) { // beware of this=t; see Stroustrup pp.238 + delete[] string; + isSpace = t.isSpace; + len = t.len; + string = newstr( t.string); + } else { + string = NULL; + len = 0; + } + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + return *this; + } + TextToken& add( const TextToken& t) { + if ( t.len > 0) { + string = renew( string, len + 1, len + t.len + 1); + memcpy( string + len, t.string, t.len); + len += t.len; + string[len] = '\0'; + isSpace = isSpace && t.isSpace; + } + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + return *this; + } + TextToken& add( char c) { + string = renew( string, len + 1, len + 2); + string[ len] = c; + len ++; + string[ len] = '\0'; + isSpace = isSpace && (( c == ' ') || ( c == '\t')); + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + return *this; + } + TextToken& prepend( const TextToken& t) { + if ( t.len > 0) { + int i; + string = renew( string, len + 1, len + t.len + 1); + for( i=len; i>=0; i--) // 0 will also be copied + string[ i + t.len] = string[ i]; + memcpy( string, t.string, t.len); + len += t.len; + isSpace = isSpace && t.isSpace; + } + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + return *this; + } + TextToken& prepend( char c) { + int i; + string = renew( string, len + 1, len + 2); + for( i=len; i>=0; i--) // 0 will also be copied + string[ i + 1] = string[ i]; + *string = c; + len ++; + isSpace = isSpace && (( c == ' ') || ( c == '\t')); + ADT_Assert( (! string && len == 0) || (int)strlen( string) == len); + ADT_Assert( ! string || string[ len] == '\0'); + return *this; + } + friend ostream& operator<< (ostream& out, const TextToken& t); + friend istream& operator>> (istream& in, TextToken& t); +}; + +//class InList< TextToken>; + +typedef InList< TextToken> Text; + +int printComment( ostream& out, const Text& T, + bool leadingLine = false, bool HTML = false); +int printTrueComment( ostream& out, const Text& T, bool leadingLine = false); + +//class InList< Specification>; +typedef InList< Specification> SpecificationList; + + +enum DeclarationType { + EmptyDecl, + ClassDecl, + StructDecl, + ConstructorDecl, + MethodDecl, + FunctionDecl +}; + +struct Declaration { + DeclarationType type; + char* returnType; + char* name; // name without template parameter + char* templateParams; // template parameter list + char* parameters; // call parameters + Text comment; // written besides the declaration + SpecificationList spec; // for classes and structs. + Declaration() { + type = EmptyDecl; + returnType = name = templateParams = parameters = NULL; + } + Declaration( const Declaration& d) { + type = d.type; + returnType = newstr( d.returnType); + name = newstr( d.name); + templateParams = newstr( d.templateParams); + parameters = newstr( d.parameters); + comment = d.comment; + spec = d.spec; + } + ~Declaration() { + delete[] returnType; + delete[] name; + delete[] templateParams; + delete[] parameters; + } + Declaration& operator=( const Declaration& d) { + if( this != &d) { // beware of this=d; see Stroustrup pp.238 + delete[] returnType; + delete[] name; + delete[] templateParams; + delete[] parameters; + type = d.type; + returnType = newstr( d.returnType); + name = newstr( d.name); + templateParams = newstr( d.templateParams); + parameters = newstr( d.parameters); + comment = d.comment; + spec = d.spec; + } + return *this; + } + friend ostream& operator<< (ostream& out, const Declaration& d); + friend istream& operator>> (istream& in, Declaration& d); +}; + + +enum SpecificationType { + SpecNone, + SpecDecl, + SpecBoth, + SpecComment +}; + +struct Specification : public ListLink{ + SpecificationType type; + Declaration decl; + Text comment; // written below of the decl. + Specification() { + type = SpecNone; + } + // Specification( const Specification& s); // default + // ~Specification(); // default + // Specification& operator=( const Specification& s); // default + friend ostream& operator<< (ostream& out, const Specification& s); + friend istream& operator>> (istream& in, Specification& s); +}; + + +// Auxiliary function declarations +// ============================================== +/* ... + char* catString( const char* r, const char* s, int l = -1, int m = -1); +... */ + +void printString( ostream &out, const char* s, int len = -1); +int scanString( istream &in, char*& s); + + +#endif // MODULE_DATABASE // diff --git a/Packages/Manual_tools/src/cc_build_checker.C b/Packages/Manual_tools/src/cc_build_checker.C index d157ed9a67b..f3502d49e2d 100644 --- a/Packages/Manual_tools/src/cc_build_checker.C +++ b/Packages/Manual_tools/src/cc_build_checker.C @@ -94,7 +94,8 @@ ostream* p_out_errmessage; char char_tmp[2] = " "; char char_tricky_tmp[16] = "\"{ws}*\" \"{ws}*\""; -const char* patternText( char c, char d = 'X') { +// const char* patternText( char c, char d = 'X') { +const char* patternText( char c, char) { switch ( c) { case IDFIER_TAG: return "\"{idfier}\""; diff --git a/Packages/Manual_tools/src/cc_check b/Packages/Manual_tools/src/cc_check index 8bb75a312fa..067e8df0225 100755 --- a/Packages/Manual_tools/src/cc_check +++ b/Packages/Manual_tools/src/cc_check @@ -1,22 +1,37 @@ +#!/bin/csh -f +# ************************************************************************** +# +# cc_check +# =================== +# A script to check the consistency between a specification written +# in a TeX file with the cc_manual.sty and the implementation in +# a C++ header file. # -# cgal_check -# ========== +# The following programs are necessary to run this script # -# csh script to check consistency between specification and -# implementation of the CGAL library kernel. -# -# The following programs are necessary to run this script -# -# o cgal_build_checker +# o cc_build_checker # o flex # o cc / gcc # -# 1.1 30.10.95 Lutz Kettner, FU Berlin, Germany +# Author : (c) 1997 Lutz Kettner +# Revision : $Revision$ +# Date : $Date$ +# +# ************************************************************************** -if ( $?DEBUG) echo "# DEBUG defined; all commands will be echoed." -# optionally the gcc compiler can set here +# ============================================= +# Installation: chose the appropriate compiler: +# ============================================= +# A C compiler can be specified here. Normally cc or gcc should work. +# Note: cc does not work on SunOS 4.1.3 (BSD), but on SunOS 5... +#set CC = gcc set CC = cc +# ============================================= +# Installation: Nothing else below this line. +# ============================================= + +if ( $?DEBUG) echo "# DEBUG defined; all commands will be echoed." if ( $#argv < 1) goto usage set spec = "" @@ -27,40 +42,48 @@ while ($#argv > 0) if ( $#argv < 1) goto usage break endif + if ( "$1" == "-a") then + shift + if ( $#argv < 1) goto usage + break + endif set spec = "$spec $1" shift end -if ( $?DEBUG) echo "cgal_build_checker cgal_checker.yy cgal_checker.h $spec" -cgal_build_checker cgal_checker.yy cgal_checker.h $spec -if ( $?DEBUG) echo "flex -t -8 cgal_checker.yy > cgal_checker.c" -flex -t -8 cgal_checker.yy > cgal_checker.c -if ( $?DEBUG) echo "$CC -o cgal_checker cgal_checker.c" -$CC -o cgal_checker cgal_checker.c +if ( $?DEBUG) echo "cc_build_checker cc_checker.yy cc_checker.h $spec" +cc_build_checker cc_checker.yy cc_checker.h $spec +if ( $?DEBUG) echo "flex -t -8 cc_checker.yy > cc_checker.c" +flex -t -8 cc_checker.yy > cc_checker.c +if ( $?DEBUG) echo "$CC -o cc_checker cc_checker.c" +$CC -o cc_checker cc_checker.c if ( $?DEBUG) then - echo "# rm cgal_checker.yy cgal_checker.c cgal_checker.h cgal_checker.o" + echo "# rm cc_checker.yy cc_checker.c cc_checker.h cc_checker.o" else - rm cgal_checker.yy cgal_checker.c cgal_checker.h cgal_checker.o + rm cc_checker.yy cc_checker.c cc_checker.h + if ( -w cc_checker.o) rm cc_checker.o endif -if ( $?DEBUG) echo "cgal_checker $argv" -cgal_checker $argv +if ( $?DEBUG) echo "cc_checker $argv" +cc_checker $argv set returnvalue = $status if ( $returnvalue) then - echo '==> NOTE: The program call `cgal_checker '"$argv""' can be used to" - echo '==> check the sources again. Otherwise, remove it.' - if ( $returnvalue == 3) set returnvalue = 0 + echo '==> NOTE: The program call `cc_checker '"$argv""' can be used to" + echo '==> check the sources again. Otherwise, remove `cc_checker'"'." + if ( $returnvalue == 3) set returnvalue = 0 else - if ( $?DEBUG) then - echo "# rm cgal_checker" - else - rm cgal_checker - endif + if ( $?DEBUG) then + echo "# rm cc_checker" + else + rm cc_checker + endif endif exit $returnvalue usage: +echo "$0 "'$Revision$'" (c) Lutz Kettner" echo "Usage: $0 [-against [] ]" echo " or: $0 -against [] " +echo " -a short form for -against" echo " -fw recognize FunnelWeb or AnyWeb keywords" echo " -match print all matched text" echo " -unmatch print all unmatched text" diff --git a/Packages/Manual_tools/src/cc_extract.C b/Packages/Manual_tools/src/cc_extract.C index 6f360d36d5a..73c47152ca2 100644 --- a/Packages/Manual_tools/src/cc_extract.C +++ b/Packages/Manual_tools/src/cc_extract.C @@ -281,6 +281,7 @@ main( int argc, char **argv) { (nParameters > MaxParameters) || (help_switch != NO_SWITCH)) { if (help_switch == NO_SWITCH) cerr << "Error: in parameter list" << endl; + cerr << "cc_extract $Revision$ (c) Lutz Kettner" << endl; cerr << "Usage: cc_extract [] [ ...]" << endl; cerr << " -nomc no main comments" << endl; cerr << " -nosc no sub comments" << endl; diff --git a/Packages/Manual_tools/src/cc_extract_html.C b/Packages/Manual_tools/src/cc_extract_html.C index 80c7ac782dc..13ea27186b5 100644 --- a/Packages/Manual_tools/src/cc_extract_html.C +++ b/Packages/Manual_tools/src/cc_extract_html.C @@ -2,7 +2,7 @@ cc_extract_html.C ============================================================= - Project : CGAL merger tool for the specification task + Project : Tools for the CC manual writing task around cc_manual.sty. Function : main program, command line parameter parsing System : bison, flex, C++ (g++) Author : (c) 1995 Lutz Kettner @@ -17,9 +17,18 @@ #include #include #include +#include #include #include + +/* Constants: */ +/* ================================= */ +const char* prog_name = "cc_extract_html"; +const char* prog_release = "$Revision$"; + +/* Configurable command line options */ +/* ================================= */ typedef char Switch; #define NO_SWITCH 0 @@ -29,23 +38,145 @@ typedef char Switch; Switch trace_switch = NO_SWITCH; Switch line_switch = NO_SWITCH; +Switch config_switch = NO_SWITCH; -/* A couple of strings for tayloring */ -/* ================================= */ -// no newlines in here (because it is used in the index file) !! -const char* general_comment = - ""; +// This factor is multiplied to the actual width of an C++ declaration +// right before the test for multiple lines formatting occurs. +// A greater value forces declarations to be printed in multiple lines. +double stretch_factor = 1.6; // The command line option -strech multiplies + // a factor to this builtin default. -const char* general_navigation = - "Table of Contents,\n" - "Bibliography,\n" - "Index,\n" - "Title Page"; +// Path for the HTML conversion tools for the default configuration files. +// This path will be compiled into the cc_extract_html program. It is set +// in the Makefile. The same variable has to be configured in the +// cc_manual_to_html script. +#ifndef HTML_DEFAULT_PATH +#define HTML_DEFAULT_PATH NULL +#endif +const char* config_path = HTML_DEFAULT_PATH; -// no newlines in here (because it is used in the index file) !! -const char* html_address_trailer = - "


The " - "CGAL Project.
"; +// Manual date, release, title, and author used in filtering the config files. +const char* manual_date = NULL; +const char* manual_release = NULL; +const char* manual_title = NULL; +const char* manual_author = NULL; + +// Directory for the temporary files. A default is given. +// This directory is the output directory for this program. Usually, +// the script cc_manual_to_html makes a own tmp directory and removes +// it afterwards. The path must terminate with a slash. +const char* tmp_path = "/usr/tmp/"; + + +/* Customization tags for the style */ +/* ================================ */ +bool tag_chapter_author; +bool tag_replace_prefix; // not supported yet +bool tag_replace_include; // not supported yet +bool tag_long_param_layout; // not supported yet + +bool tag_rm_const_ref_pair; +bool tag_rm_eigen_class_name; +bool tag_operator_layout; +bool tag_rm_trailing_const; + +void tag_defaults() { + tag_chapter_author = true; + tag_replace_prefix = false; + tag_replace_include = false; + tag_long_param_layout = false; + + tag_rm_const_ref_pair = true; + tag_rm_eigen_class_name = true; + tag_operator_layout = true; + tag_rm_trailing_const = true; +} + +void tag_full_declarations() { + tag_rm_const_ref_pair = false; + tag_rm_eigen_class_name = false; + tag_operator_layout = false; + tag_rm_trailing_const = false; +} + +void handleNewCommand( char* idfier, char* body){ + // check the body for true or false + const char* p = body; + while ( *p && isspace( *p)) + p++; + bool tag = ( 0 == strncmp( p, "\\ccTrue", 7)); + + // check the different idfiers + p = idfier; + while ( *p && isspace( *p)) + p++; + if ( 0 == strncmp( p, "\\ccTagChapterAuthor", + strlen("\\ccTagChapterAuthor"))) + tag_chapter_author = tag; + if ( 0 == strncmp( p, "\\ccTagReplacePrefix", + strlen("\\ccTagReplacePrefix"))) + tag_replace_prefix = tag; + if ( 0 == strncmp( p, "\\ccTagReplaceInclude", + strlen("\\ccTagReplaceInclude"))) + tag_replace_include = tag; + if ( 0 == strncmp( p, "\\ccAlternateThreeColumn", // compatibility + strlen("\\ccAlternateThreeColumn"))) + tag_long_param_layout = !tag; + if ( 0 == strncmp( p, "\\ccLongParamLayout", + strlen("\\ccLongParamLayout"))) + tag_long_param_layout = tag; + if ( 0 == strncmp( p, "\\ccTagRmTrailingConst", + strlen("\\ccTagRmTrailingConst"))) + tag_rm_trailing_const = tag; + if ( 0 == strncmp( p, "\\ccTagRmEigenClassName", + strlen("\\ccTagRmEigenClassName"))) + tag_rm_eigen_class_name = tag; + if ( 0 == strncmp( p, "\\ccTagRmConstRefPair", + strlen("\\ccTagRmConstRefPair"))) + tag_rm_const_ref_pair = tag; + if ( 0 == strncmp( p, "\\ccTagOperatorLayout", + strlen("\\ccTagOperatorLayout"))) + tag_operator_layout = tag; + delete[] idfier; + delete[] body; +} + +/* Sort keys for the index */ +/* ================================== */ +// The index is organized in a set of fixed topics. + +// scramble is used to write index entries with scope in front. +// The scope is a class but it should not get hyperlinked for its own. +// Has to be same as in the cc_anchor_header. +const char* index_scramble = ""; + +// sort_keys are used to sort the index according to different sections. +// A sort_key is followed by a 0 to indicate the section title. +// A sort_key is followed by a 1 to indicate a normal entry. + +const char* sort_key_class = "

  • Classes

    " << endl; + out << sort_key_nested_type << "0 !>

  • Nested Types

    " << endl; + out << sort_key_struct << "0 !>

  • Structs

    " << endl; + out << sort_key_enum << "0 !>

  • Enums

    " << endl; + out << sort_key_enum_tags << "0 !>

  • Enum Tags

    " << endl; + out << sort_key_typedef << "0 !>

  • Typedefs

    " << endl; + out << sort_key_variable << "0 !>

  • Global Variables and " + "Consts

    " << endl; + out << sort_key_function << "0 !>

  • Functions

    " << endl; + // out << sort_key_member_function << "0 !>

  • Member Functions

    " + // << endl; +} /* table size and font size constants */ /* ================================== */ @@ -58,11 +189,6 @@ const int table_2c_second_col = 70; // in percent const double width_per_character = 5.5; -// This factor is multiplied to the actual width of an C++ declaration -// right before the test for multiple lines formatting occurs. -// A greater value forces declarations to be printed in multiple lines. -double stretch_factor = 1.6; - /* An empty List as empty comment for global declarations */ /* ====================================================== */ Text empty_comment; @@ -94,13 +220,25 @@ char* class_name = 0; char* template_class_name = 0; char* formatted_class_name = 0; char* formatted_template_class_name = 0; +char* scrambled_template_class_name = 0; -char* html_suffix = ".html"; -char* chapter_prefix = "Chapter_"; -char* anchor_filename = "anchor_rules"; -char* contents_filename = "contents.html"; -char* bib_filename = "biblio.html"; -char* index_filename = "manual_index.html"; +const char* html_suffix = ".html"; +const char* chapter_prefix = "Chapter_"; +const char* anchor_filename = "cc_anchor_rules"; +const char* contents_filename = "contents.html"; +const char* bib_filename = "biblio.html"; +const char* index_filename = "cc_index_body"; + +const char* cc_anchor_header = "cc_anchor_header"; +const char* cc_anchor_footer = "cc_anchor_footer"; +const char* cc_manual_header = "cc_manual_header"; +const char* cc_manual_footer = "cc_manual_footer"; +const char* cc_toc_header = "cc_toc_header"; +const char* cc_toc_footer = "cc_toc_footer"; +const char* cc_biblio_header = "cc_biblio_header"; +const char* cc_biblio_footer = "cc_biblio_footer"; +const char* cc_index_header = "cc_index_header"; +const char* cc_index_footer = "cc_index_footer"; ostream* main_stream = 0; ostream* class_stream = 0; @@ -145,19 +283,302 @@ char* addPrefix( const char* prefix, const char* name) { return fullname; } +/* Auxiliary functions for stream handling */ +/* ======================================= */ + +bool exist_file( const char* name){ + istream* in = new ifstream( name); + if ( ! *in) + return false; + return true; +} + +void assert_file_write( ostream& out, const char* name){ + if ( ! out) { + cerr << ' ' << endl + << prog_name << ": error: cannot write to file `" + << name << "'." << endl; + exit(1); + } +} + +bool exist_file_with_path( const char* path, const char* name){ + char* full_name = addPrefix( path, name); + istream* in = new ifstream( full_name); + delete[] full_name; + if ( ! *in) + return false; + return true; +} + +istream* open_file_for_read( const char* name){ + istream* in = new ifstream( name); + if ( ! *in) { + cerr << ' ' << endl + << prog_name << ": error: cannot open file `" << name + << "' for reading." << endl; + exit(1); + } + return in; +} + +istream* open_file_with_path_for_read( const char* path, const char* name){ + char* full_name = addPrefix( path, name); + istream* in = new ifstream( full_name); + if ( ! *in) { + cerr << ' ' << endl + << prog_name << ": error: cannot open file `" << full_name + << "' for reading." << endl; + exit(1); + } + delete[] full_name; + return in; +} + +ostream* open_file_with_path_for_write( const char* path, const char* name){ + char* full_name = addPrefix( path, name); + ostream* out = new ofstream( full_name); + if ( ! *out) { + cerr << ' ' << endl + << prog_name << ": error: cannot open file `" << full_name + << "' for writing." << endl; + exit(1); + } + delete[] full_name; + return out; +} + + +/* read a file into a buffer */ +/* The name has a trailing '}' */ +/* =========================== */ +Buffer* readFileInBuffer(const char* name) { + int len = strlen( name); + const char* p = name + len - 1; + while( p != name && ( *p == ' ' || *p == '}')) + p--; + char* filename = new char[p-name+2]; + strncpy( filename, name, p-name+1); + filename[p-name+1] = '\0'; + istream* in = open_file_for_read(filename); + delete[] filename; + char c; + Buffer* b = new Buffer; + while( in->get(c)) + b->add(c); + return b; +} + + +/* Filter a config file */ +/* ======================================= */ +/* Filtering means substituting of the variable names and */ +/* skipping of braces if the variable is undefined. */ + +void filter_config_file( istream& in, ostream& out) { + char c; + while( in.get(c)) { + if ( c == '}') + continue; + if ( c == '%' && in.get(c)) { + char d; + in.get(d); + if ( d == '{') { + bool is_empty = false; + switch( c) { + case 'c': + is_empty = class_name == NULL; + break; + case 'u': + is_empty = main_stream == &cout; + break; + case 'd': + is_empty = manual_date == NULL; + if ( !is_empty) + is_empty = (strlen(manual_date) == 0); + break; + case 'r': + is_empty = manual_release == NULL; + if ( !is_empty) + is_empty = (strlen(manual_release) == 0); + break; + case 't': + is_empty = manual_title == NULL; + if ( !is_empty) + is_empty = (strlen(manual_title) == 0); + break; + case 'a': + is_empty = manual_author == NULL; + if ( !is_empty) + is_empty = (strlen(manual_author) == 0); + break; + default: + cerr << prog_name << ": warning: unknown variable scope %" + << c << "{...} in a config file found." << endl; + out.put('%'); + out.put(c); + out.put(d); + } + if ( is_empty) { + // remove proper nested parantheses. Check for the + // escape sequence %{ or %}. + int nesting = 1; // count paranthesis nesting. + c = d; + while( in.get(d) && nesting > 0) { + if ( c != '%') { + if ( d == '{') + nesting ++; + if ( d == '}') + nesting --; + } + c = d; + } + } + } else { + switch( c) { + case '0': + out << prog_name; + break; + case 'p': + out << prog_release; + break; + case 'f': + out << current_filename; + break; + case 'c': + if ( class_name) + out << template_class_name; + break; + case 'u': + if ( main_stream != &cout) + out << main_filename; + break; + case 'd': + if ( manual_date ) + out << manual_date; + break; + case 'r': + if ( manual_release ) + out << manual_release; + break; + case 't': + if ( manual_title ) + out << manual_title; + break; + case 'a': + if ( manual_author ) + out << manual_author; + break; + case '%': + case '{': + case '}': + out.put(c); + break; + default: + cerr << prog_name << ": warning: unknown variable %" << c + << " in a config file found." << endl; + out.put('%'); + out.put(c); + } + out.put(d); + } + } else { + if ( in) + out.put(c); + else + out.put('%'); + } + } +} + + +/* Auxiliary functions to handle config files */ +/* ========================================== */ + +istream* open_config_file( const char* name){ + if ( config_switch == NO_SWITCH) { + // check if the file exists in the current directory + if ( exist_file( name)) + return (open_file_for_read( name)); + } + return( open_file_with_path_for_read( config_path, name)); +} + +void copy_and_filter_config_file( const char* name, ostream& out){ + istream* in = open_config_file( name); + filter_config_file( *in, out); + delete in; +} + +void copy_config_file( const char* name){ + istream* in = open_config_file( name); + ostream* out = open_file_with_path_for_write( tmp_path, name); + filter_config_file( *in, *out); + delete in; + assert_file_write( *out, name); + delete out; +} + + +/* Filter decl. before writing to the index comment */ +/* ================================================ */ + +void filter_for_index_comment( ostream& out, const char* text) { + while( *text) { + switch (*text) { + case '<': + out << '('; + break; + case '>': + out << ')'; + break; + case '&': + out << '_'; + break; + default: + out << *text; + } + text++; + } +} + +// Filter characters that might not be allowed in hyperlink anchors. +void filter_for_index_anchor( ostream& out, const char* text) { + while( *text) { + switch ( *text) { + case '<': + out << '('; + break; + case '>': + out << '('; + break; + case '"': + case '&': + case ' ': + out << '_'; + break; + default: + out << *text; + } + text++; + } +} + + /* HTML generating functions */ /* ========================= */ -void open_html( ostream& out, const char* classname) { - out << "\nThe CGAL Kernel Manual: " - << classname << "\n" - << general_comment - << "\n\n\n"; +void open_html( ostream& out) { + istream* in = open_config_file( cc_manual_header); + filter_config_file( *in, out); + delete in; } void close_html( ostream& out) { - out << "\n\n" << html_address_trailer << "\n\n" << endl; + istream* in = open_config_file( cc_manual_footer); + filter_config_file( *in, out); + delete in; } bool is_html_multi_character( char c) { @@ -186,13 +607,24 @@ void print_ascii_to_html( ostream& out, const char* txt) { } } +void print_ascii_len_to_html( ostream& out, const char* txt, int n) { + while( n) { + if ( is_html_multi_character( *txt)) + out << html_multi_character( *txt); + else + out << *txt; + ++txt; + n--; + } +} + // This version eliminates multiple spaces. void print_ascii_to_html_spc( ostream& out, const char* txt) { while( *txt) { if ( is_html_multi_character( *txt)) out << html_multi_character( *txt); else - if ( *txt > ' ' || txt[1] > ' ') + if ( *txt > ' ' || (*txt > '\0' && txt[1] > ' ')) out << *txt; ++txt; } @@ -211,6 +643,11 @@ int strlen_ascii_to_html( const char* txt) { } char* convert_ascii_to_html( const char* txt) { + if ( txt == NULL) { + char *q = new char[1]; + q[0] = '\0'; + return q; + } char* s = new char[ strlen_ascii_to_html( txt) + 1]; char* p = s; while( *txt) { @@ -226,10 +663,37 @@ char* convert_ascii_to_html( const char* txt) { return s; } +// A scope operator is also appended +char* convert_ascii_to_scrambled_html( const char* txt) { + char* s = new char[ strlen_ascii_to_html( txt) + 3 + + strlen( index_scramble)]; + char* p = s; + bool tag = true; + while( *txt) { + if ( is_html_multi_character( *txt)) { + const char* q = html_multi_character( *txt); + while ( *q) + *p++ = *q++; + } else + *p++ = *txt; + ++txt; + if ( tag) { + const char* q = index_scramble; + while ( *q) + *p++ = *q++; + tag = false; + } + } + *p++ = ':'; + *p++ = ':'; + *p = '\0'; + return s; +} + double estimate_html_size( const char* s) { int n = 0; while ( *s) { - if ( *s > ' ' || s[1] > ' ') + if ( *s > ' ' || (*s > '\0' && s[1] > ' ')) n++; ++s; } @@ -246,6 +710,12 @@ void three_cols_html_begin( ostream& out, bool big_col1) { << indNewline << "" << outdent << indNewline; } +void three_cols_html_premature_end( ostream& out) { + out << indent << indNewline <<"" << indNewline << ""; + out << "" << indNewline + << "" << outdent << outdent << indNewline; +} + void three_cols_html_second( ostream& out, bool big_col1, bool big_col2) { out << indent << indNewline <<"" << indNewline << ""; if ( big_col1) @@ -281,6 +751,12 @@ void two_cols_html_begin( ostream& out) { << indNewline << "" << outdent << indNewline; } +void two_cols_html_premature_end( ostream& out) { + out << indent << indNewline <<"" << indNewline << ""; + out << "" << indNewline + << "" << outdent << outdent << indNewline; +} + void two_cols_html_second( ostream& out, bool empty_col2) { out << indent << indNewline << "" << indNewline << ""; if ( ! empty_col2) @@ -422,11 +898,56 @@ int print_html_text_block( ostream &out, const Text& T, } -/* Formatting functions that work like the cgal_manual.sty */ -/* ======================================================= */ +/* template declarations for functions and others */ +/* ============================================== */ +/* It depends on the layout (2 or 3 columns) */ + +const char* handle_template_layout( ostream &out, + const char* decl, + bool three_col) { + const char* new_pos = decl; + const char* p = decl; + while ( *p && isspace( *p)) + p++; + if ( strncmp( "template", p, 8) == 0) { + p += 8; + while ( *p && isspace( *p)) + p++; + if ( *p == '<') { + p++; + // Here we know that it is a template declaration. Now we + // look for the end of the template params using a nesting counter. + int nesting = 1; + while ( *p && nesting > 0) { + if ( *p == '<') + nesting++; + else if ( *p == '>') + nesting --; + p++; + } + new_pos = p; + // Print the template declaration. + if ( three_col) + three_cols_html_begin( out, true); + else + two_cols_html_begin( out); + + print_ascii_len_to_html( out, decl, p - decl); + + if ( three_col) + three_cols_html_premature_end( out); + else + two_cols_html_premature_end( out); + } + } + return new_pos; +} + +/* Formatting functions that work like the cc_manual.sty */ +/* ===================================================== */ // This function separates the return value from the scope, the function name, -// the parameter list (without paranthesis) and the rest of the signature.. +// the parameter list (without paranthesis) and the rest of the signature. // Therefore, the string in signature will be parsed from the end // looking for the first ')' and then for the matching '(', using // a nesting count for '(', ')', '{', '}', '<', '>'. Then, the next token is @@ -563,7 +1084,7 @@ void split_function_declaration( const char* signature, return_value = 0; } -// This function separates a varible declaration around the variable name. +// This function separates a variable declaration around the variable name. // The rest might contain `)', array subscripts or an assignment. // The scope might be empty, the return_value should not be empty. // No fancy tricks like operators. @@ -668,6 +1189,8 @@ void split_variable_declaration( const char* signature, } void remove_const_ref_pair( char* s) { + if ( ! tag_rm_const_ref_pair) + return; int state = 0; // 0 = no const, 1 = c, 2 = co, 3 = con, 4 = cons, 5 = const int nesting = 0; char* q; // position of recently found const @@ -736,40 +1259,25 @@ void remove_const_ref_pair( char* s) { } void remove_own_classname( char* s, const char* classname) { + if ( ! tag_rm_eigen_class_name) + return; if ( ! classname) return; - int nesting = 0; // prepare to remove template params if necessary - int l = strlen( classname); - if ( ! l) - return; - while( *s) { - if ( strncmp( s, classname, l) == 0) { - while( l--) - *s++ = ' '; - while( *s && *s <= ' ') - ++s; - if ( *s == '<') { - // Classname with template params detected. Remove them. - while ( *s) { - if ( *s == '(' || *s == '<' || *s == '[' || *s == '{') - ++nesting; - if ( *s == ')' || *s == '>' || *s == ']' || *s == '}') - --nesting; - if (*s == '>' && nesting == 0) - break; - *s++ = ' '; - } - if ( nesting || *s != '>') { - printErrorMessage( MalformedTemplateParamError); - exit( 1); - } - *s = ' '; - } + // An easy algorithm (quadratic runtime worst case). + // The classname has to match exactly (and is removed at most once). + int l = strlen( s) - strlen( classname); + int l2 = strlen( classname); + int i; + for ( i = 0; i <= l; i++) { + if ( strncmp( s, classname, l2) == 0) break; - } - ++s; + s++; + } + if ( i <= l) { + // Classname found. Remove it. + for( ; l2 > 0; l2--) + *s++ = ' '; } - return; } // This function separates each parameter in a parameter list. @@ -827,8 +1335,10 @@ bool format_operators( int n, int& modifiable_n, double& exp_size, bool& ignore_params) { // Assume that the syntax is not malformed (error messages are - // provided elsewhere, namely compiler or cgal_manual.sty). + // provided elsewhere, namely compiler or cc_manual.sty). // Non matching operators are printed in functional notation. + if ( ! tag_operator_layout) + return false; if ( *op <= ' ') return false; if ( op[1] <= ' ') { // one character operators @@ -974,6 +1484,19 @@ bool format_operators( int n, int& modifiable_n, return true; } + +void print_rest( ostream& out, const char* txt){ + out << ' '; + while( *txt && *txt != ';') { + if ( is_html_multi_character( *txt)) + out << html_multi_character( *txt); + else + if ( *txt > ' ' || (*txt > '\0' && txt[1] > ' ')) + out << *txt; + ++txt; + } +} + void format_function( bool method, const char* signature, const Text& T) { char* return_value; char* scope; @@ -986,6 +1509,9 @@ void format_function( bool method, const char* signature, const Text& T) { // or (normal) function char* op_symbols; + while( *signature && *signature == ' ') + signature++; + split_function_declaration( signature, return_value, scope, @@ -1015,6 +1541,38 @@ void format_function( bool method, const char* signature, const Text& T) { three_cols_html_begin( *current_stream, exp_size_ret > table_width*table_first_col/100.0); + // --------- + // index + if ( !method) { + char* formatted_return = convert_ascii_to_html( return_value); + char* formatted_scope = convert_ascii_to_html( scope); + char* formatted_function = convert_ascii_to_html( function_name); + char* formatted_params = convert_ascii_to_html( parameter_list); + char* formatted_rest = convert_ascii_to_html( rest); + // Make only the function name a hyperlink. Types could be substituted + // according the rules. + *index_stream << sort_key_function << '1'; + filter_for_index_comment( *index_stream, function_name); + *index_stream << ' '; + filter_for_index_comment( *index_stream, signature); + *index_stream << "!>

    • " + << formatted_return << ' ' << formatted_scope + << "" << formatted_function << "" + << "( " << formatted_params << ")" << formatted_rest + << "
    " << endl; + *current_stream << "" << endl; + delete[] formatted_return; + delete[] formatted_scope; + delete[] formatted_function; + delete[] formatted_params; + delete[] formatted_rest; + } + // end index + // ---------- if ( return_value) print_ascii_to_html_spc( *current_stream, return_value); @@ -1034,11 +1592,14 @@ void format_function( bool method, const char* signature, const Text& T) { int m = n; while ( m--) { remove_const_ref_pair( p); - remove_own_classname( p, class_name); + remove_own_classname( p, template_class_name); exp_size += estimate_html_size( p) + width_per_character; p += strlen( p) + 1; // skip to next parameter } } + if (!tag_rm_trailing_const) + exp_size += estimate_html_size( rest); + bool failed = false; if ( normal_operator) { exp_size += estimate_html_size( op_symbols); @@ -1136,6 +1697,8 @@ void format_function( bool method, const char* signature, const Text& T) { *current_stream << " ()"; } } + if (!tag_rm_trailing_const) + print_rest( *current_stream, rest); bool is_empty_comment = is_text_block_empty( T); three_cols_html_third( *current_stream, exp_size > table_width * table_second_col / 100.0, @@ -1150,7 +1713,9 @@ void format_function( bool method, const char* signature, const Text& T) { is_empty_comment); } -void format_variable( const char* signature, const Text& T) { +void format_variable( const char* signature, + const Text& T, + bool is_typedef = false) { char* return_value; char* scope; char* variable_name; @@ -1163,27 +1728,6 @@ void format_variable( const char* signature, const Text& T) { rest); char* formatted_var = convert_ascii_to_html( variable_name); - if ( &T == &empty_comment) { - // generate a substitution rule for hyperlinking - *anchor_stream << "[a-zA-Z0-9_]\"" << formatted_var - << "\" { ECHO; }" << endl; - *anchor_stream << "\"" << formatted_var - << "\"[a-zA-Z0-9_] { ECHO; }" << endl; - *anchor_stream << '"' << formatted_var - << "\" { fputs( \"" << formatted_var << "\", stdout); }" - << endl; - - *current_stream << "" << endl; - - // index - *index_stream << "
    • " << formatted_var - << "
    " << endl; - } - double exp_size_ret = 0.0; double exp_size = 0.0; if ( return_value) { @@ -1194,6 +1738,47 @@ void format_variable( const char* signature, const Text& T) { three_cols_html_begin( *current_stream, exp_size_ret > table_width*table_first_col/100.0); + if ( class_name == NULL) { + // generate a substitution rule for hyperlinking + *anchor_stream << "[a-zA-Z0-9_]\"" << formatted_var + << "\" { ECHO; }" << endl; + *anchor_stream << "\"" << formatted_var + << "\"[a-zA-Z0-9_] { ECHO; }" << endl; + *anchor_stream << '"' << formatted_var + << "\" { fputs( \"" << formatted_var << "\", stdout); }" + << endl; + + // index + *index_stream << (is_typedef ? sort_key_typedef : + sort_key_variable) << '1'; + filter_for_index_comment( *index_stream, variable_name); + *index_stream << "!>
    • " << formatted_var + << "
    " << endl; + } else { + // index + char* scrambled_var = convert_ascii_to_scrambled_html( variable_name); + *index_stream << (is_typedef ? sort_key_typedef : + sort_key_variable) << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "::"; + filter_for_index_comment( *index_stream, variable_name); + *index_stream << "!>" << endl; + delete[] scrambled_var; + } + *current_stream << "" << endl; + // end index + if ( return_value) print_ascii_to_html_spc( *current_stream, return_value); @@ -1265,7 +1850,7 @@ void format_constructor( const char* signature, const Text& T) { int m = n; while ( m--) { remove_const_ref_pair( p); - remove_own_classname( p, class_name); + remove_own_classname( p, template_class_name); exp_size += estimate_html_size( p) + width_per_character; p += strlen( p) + 1; // skip to next parameter } @@ -1314,6 +1899,43 @@ void format_constructor( const char* signature, const Text& T) { two_cols_html_end( *current_stream, is_empty_comment); } +void format_nested_type( const char* nested_type_name, const Text& T) { + char* formatted_type = convert_ascii_to_html( nested_type_name); + char* scrambled_type = convert_ascii_to_scrambled_html( nested_type_name); + two_cols_html_begin( *current_stream); + + // index + *index_stream << sort_key_nested_type << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "::"; + filter_for_index_comment( *index_stream, nested_type_name); + *index_stream << "!>" << endl; + *current_stream << "" << endl; + // end index + + // first, estimate size + double exp_size = estimate_html_size( template_class_name) + + estimate_html_size( nested_type_name) + + 2 * width_per_character; + exp_size *= stretch_factor; + + print_ascii_to_html_spc( *current_stream, template_class_name); + *current_stream << "::"; + print_ascii_to_html_spc( *current_stream, nested_type_name); + + bool is_empty_comment = is_text_block_empty( T); + two_cols_html_second( *current_stream, is_empty_comment); + print_html_text_block( *current_stream, T); + *current_stream << indNewline << "

    "; + two_cols_html_end( *current_stream, is_empty_comment); + delete[] formatted_type; + delete[] scrambled_type; +} + void format_enum( const char* signature, const Text& T) { char* return_value; char* scope; @@ -1331,7 +1953,9 @@ void format_enum( const char* signature, const Text& T) { char* formatted_enum = convert_ascii_to_html( enum_name); - if ( &T == &empty_comment) { + two_cols_html_begin( *current_stream); + + if ( class_name == NULL) { // generate a substitution rule for hyperlinking *anchor_stream << "[a-zA-Z0-9_]\"" << formatted_enum << "\" { ECHO; }" << endl; @@ -1343,15 +1967,27 @@ void format_enum( const char* signature, const Text& T) { << formatted_enum << "\", stdout); }" << endl; - *current_stream << "" << endl; - // index - *index_stream << "

    • " << formatted_enum + *index_stream << sort_key_enum << '1'; + filter_for_index_comment( *index_stream, enum_name); + *index_stream << "!>
      • " << formatted_enum << "
      " << endl; + } else { + // index + char* scrambled_enum = convert_ascii_to_scrambled_html( enum_name); + *index_stream << sort_key_enum << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "::"; + filter_for_index_comment( *index_stream, enum_name); + *index_stream << "!>" << endl; + delete[] scrambled_enum; } + *current_stream << "" << endl; + // end index - two_cols_html_begin( *current_stream); // first, estimate size double exp_size = 0.0; if ( scope) @@ -1397,14 +2033,15 @@ void format_enum( const char* signature, const Text& T) { ++p; print_ascii_to_html_spc( *current_stream, p); - if ( &T == &empty_comment) { + if ( class_name == NULL) { // index: print enum tags with their (possible) initializers - *index_stream << "
      • "; + *index_stream << sort_key_enum_tags << '1' << p + << "!>
        • "; print_ascii_to_html_spc( *index_stream, p); *index_stream << "
        " << endl; // generate a substitution rule for hyperlinking - // Here, the initializer has to suppressed + // Here, the initializer has to be suppressed char* q = p; while( *q && *q != '=') ++q; @@ -1425,6 +2062,23 @@ void format_enum( const char* signature, const Text& T) { << endl; delete[] tmp_param; *q = c_tmp; // restore initializer + } else { + // index: print enum tags with their (possible) initializers + char* scrambled_tag = convert_ascii_to_scrambled_html( p); + *index_stream << sort_key_enum_tags << '1' << p + << "!>
        • "; + print_ascii_to_html_spc( *index_stream, p); + *index_stream << "
        " << endl; + + *index_stream << sort_key_enum_tags << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "::"; + filter_for_index_comment( *index_stream, p); + *index_stream << "!>" << endl; + delete[] scrambled_tag; } p += strlen( p) + 1; // skip to next parameter @@ -1453,6 +2107,127 @@ void format_enum( const char* signature, const Text& T) { } +void format_struct( const char* signature, const Text& T) { + char* return_value; + char* scope; + char* struct_name; + char* parameter_list; + const char* rest; + + split_function_declaration( signature, + return_value, + scope, + struct_name, + parameter_list, + rest, + true); + + char* formatted_struct = convert_ascii_to_html( struct_name); + two_cols_html_begin( *current_stream); + + if ( class_name == NULL) { + // generate a substitution rule for hyperlinking + *anchor_stream << "[a-zA-Z0-9_]\"" << formatted_struct + << "\" { ECHO; }" << endl; + *anchor_stream << "\"" << formatted_struct + << "\"[a-zA-Z0-9_] { ECHO; }" << endl; + *anchor_stream << '"' << formatted_struct + << "\" { fputs( \"" << formatted_struct << "\", stdout); }" + << endl; + // index + *index_stream << sort_key_struct << '1'; + filter_for_index_comment( *index_stream, struct_name); + *index_stream << "!>
        • " << formatted_struct + << "
        " << endl; + } else { + // index + char* scrambled_struct = convert_ascii_to_scrambled_html( struct_name); + *index_stream << sort_key_struct << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "::"; + filter_for_index_comment( *index_stream, struct_name); + *index_stream << "!>" << endl; + delete[] scrambled_struct; + } + *current_stream << "" << endl; + // end index + + // first, estimate size + double exp_size = 0.0; + if ( scope) + exp_size += estimate_html_size( scope); + if ( return_value) + exp_size += estimate_html_size( return_value); + + + exp_size += estimate_html_size( formatted_struct) + + 3.0 * width_per_character; + int n = 0; + if ( parameter_list) { + exp_size += 2 * width_per_character; + n = separate_parameter_list( parameter_list); + char* p = parameter_list; + int m = n; + while ( m--) { + exp_size += estimate_html_size( p) + width_per_character; + p += strlen( p) + 1; // skip to next parameter + } + } + exp_size *= stretch_factor; + if ( exp_size > table_width && parameter_list) + *current_stream << "" + "
        " + << indNewline; + + if ( return_value) { + print_ascii_to_html_spc( *current_stream, return_value); + *current_stream << ' '; + } + if ( scope) + print_ascii_to_html_spc( *current_stream, scope); + *current_stream << formatted_struct; + if ( parameter_list) { + *current_stream << " { "; + if ( exp_size > table_width) + *current_stream << "" + << indNewline; + char* p = parameter_list; + while ( n--) { + while ( *p && *p <= ' ') + ++p; + print_ascii_to_html_spc( *current_stream, p); + + p += strlen( p) + 1; // skip to next parameter + if ( n) { + *current_stream << ", "; + if ( exp_size > table_width) + *current_stream << "
        " << indNewline; + } + } + *current_stream << "};"; + if ( exp_size > table_width) + *current_stream << "
        " << indNewline; + } else + *current_stream << ';'; + + bool is_empty_comment = is_text_block_empty( T); + two_cols_html_second( *current_stream, is_empty_comment); + delete[] return_value; + delete[] scope; + delete[] formatted_struct; + delete[] struct_name; + delete[] parameter_list; + print_html_text_block( *current_stream, T); + *current_stream << indNewline << "

        "; + two_cols_html_end( *current_stream, is_empty_comment); +} + + /* Taylored semantic functions used in syntax.y */ /* ============================================ */ @@ -1489,12 +2264,7 @@ void handleChapter( const Text& T) { << main_filename << "\">" << chapter_title << "" << endl; close_html( *class_stream); - if ( ! *class_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << class_filename << "'." << endl; - exit(1); - } + assert_file_write( *class_stream, class_filename); delete class_stream; delete[] class_filename; class_stream = 0; @@ -1508,65 +2278,41 @@ void handleChapter( const Text& T) { << new_main_filename << "\">" << chapter_title << "" << endl; close_html( *main_stream); - if ( ! *main_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << main_filename << "'." << endl; - exit(1); - } + assert_file_write( *main_stream, main_filename); delete main_stream; delete[] main_filename; main_stream = 0; main_filename = 0; } main_filename = new_main_filename; - main_stream = new ofstream( main_filename); - if ( ! main_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open main chapter file `" - << main_filename << "'." << endl; - exit(1); - } + main_stream = open_file_with_path_for_write( tmp_path, main_filename); current_stream = main_stream; current_filename = main_filename; - open_html( *main_stream, chapter_title); - // print navigation header - *main_stream << general_navigation << "\n


        \n" << endl; + open_html( *main_stream); *main_stream << "

        " << chapter_title << "

        " << endl; // table of contents *contents_stream << "
      • " << chapter_title << "" << endl; - } void handleBiblio( const Text& T) { first_bibitem = true; - ofstream out( bib_filename); - if ( ! out) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open bibliography file `" - << bib_filename << "'." << endl; - exit(1); - } - open_html( out, "Bibliography"); + ostream* out = open_file_with_path_for_write( tmp_path, bib_filename); + istream* in = open_config_file( cc_biblio_header); + filter_config_file( *in, *out); - // print navigation header - out << general_navigation << "\n
        \n" << endl; - out << "

        Bibliography

        " << endl; + print_html_text_block( *out, T); + *out << "" << endl; - out << "" << endl; - print_html_text_block( out, T); + delete in; + in = open_config_file( cc_biblio_footer); + filter_config_file( *in, *out); - out << "
        " << endl; - close_html( out); - if ( ! out) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << bib_filename << "'." << endl; - exit(1); - } + assert_file_write( *out, bib_filename); + delete in; + delete out; } Buffer* handleCite( const char* l) { @@ -1659,7 +2405,7 @@ void handleSection( const Text& T) { } void handleLabel( const char* l) { - /* The lexical processing has removed the prantheses around */ + /* The lexical processing has removed the parantheses around */ /* \ref{...} macros from TeX, so here is the correct pattern match */ /* to find them in the pre-HTML text */ *anchor_stream << "[\\\\](page)?ref[ \\t]*\"" << l @@ -1677,10 +2423,6 @@ void handleLabel( const char* l) { << current_filename << "#" << l << "\\\">This Section\", stdout); }" << endl; - // index - /* ... - *index_stream << "
        • " << l << "
        " << endl; - ... */ } void handleText( const Text& T, bool check_nlnl) { @@ -1725,24 +2467,26 @@ void handleClasses( const char* classname, const char* template_cls) { template_class_name = newstr( template_cls); else template_class_name = newstr( classname); + assert( template_class_name); char* t_tmp_name = convert_ascii_to_html( template_class_name); formatted_template_class_name = new char[ strlen( t_tmp_name) + 12]; strcpy( formatted_template_class_name, ""); strcat( formatted_template_class_name, t_tmp_name); strcat( formatted_template_class_name, ""); delete[] t_tmp_name; + t_tmp_name = convert_ascii_to_scrambled_html( template_class_name); + scrambled_template_class_name = new char[ strlen( t_tmp_name) + 12]; + strcpy( scrambled_template_class_name, ""); + strcat( scrambled_template_class_name, t_tmp_name); + strcat( scrambled_template_class_name, ""); + delete[] t_tmp_name; if ( class_stream != 0) { // navigation footer *class_stream << "
        Next class declaration: " << formatted_template_class_name << endl; close_html( *class_stream); - if ( ! *class_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << class_filename << "'." << endl; - exit(1); - } + assert_file_write( *class_stream, class_filename); delete class_stream; delete[] class_filename; class_stream = 0; @@ -1756,30 +2500,23 @@ void handleClasses( const char* classname, const char* template_cls) { strcat( formatted_class_name, ""); class_filename = addSuffix( classname, html_suffix); - class_stream = new ofstream( class_filename); - if ( ! class_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open class file `" - << class_filename << "'." << endl; - exit(1); - } - open_html( *class_stream, classname); - // print navigation header + class_stream = open_file_with_path_for_write( tmp_path, class_filename); + open_html( *class_stream); + // Make a hyperlink in the chapter to the class file. if ( main_stream != &cout) { *main_stream << "
        • \nClass declaration for " << formatted_template_class_name << ".
        \n" << endl; - *class_stream << "Chapter,\n"; } - *class_stream << general_navigation << "\n
        \n" << endl; // table of contents *contents_stream << "
        • Class declaration of " << formatted_template_class_name << "
        " << endl; // index - *index_stream << "
        • " << formatted_template_class_name + *index_stream << sort_key_class << '1'; + filter_for_index_comment( *index_stream, template_class_name); + *index_stream << "!>
          • " << formatted_template_class_name << "
          " << endl; current_stream = class_stream; @@ -1821,15 +2558,17 @@ void handleClassEnd( void) { delete[] template_class_name; delete[] formatted_class_name; delete[] formatted_template_class_name; + delete[] scrambled_template_class_name; class_name = 0; formatted_class_name = 0; template_class_name = 0; formatted_template_class_name = 0; + scrambled_template_class_name = 0; /* ... Hack to implement the link from one class to the next class close_html( *class_stream); if ( ! *class_stream) { cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" + << prog_name << ": error: cannot write to file `" << class_filename << "'." << endl; exit(1); } @@ -1863,14 +2602,17 @@ void handleClassTemplateEnd( void) { void handleDeclaration( const char* ) {} void handleMethodDeclaration( const char* decl, const Text& T) { + decl = handle_template_layout( *current_stream, decl, true); format_function( true, decl, T); } void handleFunctionDeclaration( const char* decl, const Text& T) { + decl = handle_template_layout( *current_stream, decl, true); format_function( false, decl, T); } void handleConstructorDeclaration( const char* decl, const Text& T) { + decl = handle_template_layout( *current_stream, decl, false); format_constructor( decl, T); } @@ -1884,10 +2626,23 @@ void handleVariableDeclaration( const char* decl, const Text& T) { format_variable( decl, T); } +void handleTypedefDeclaration( const char* decl, const Text& T) { + format_variable( decl, T, true); +} + +void handleNestedTypeDeclaration( const char* decl, const Text& T) { + format_nested_type( decl, T); +} + void handleEnumDeclaration( const char* decl, const Text& T) { format_enum( decl, T); } +void handleStructDeclaration( const char* decl, const Text& T) { + decl = handle_template_layout( *current_stream, decl, false); + format_struct( decl, T); +} + /* main */ /* ==== */ @@ -1923,8 +2678,8 @@ main( int argc, char **argv) { int nParameters = 0; char *parameters[ MaxParameters + 1]; - Switch help_switch = NO_SWITCH; - + Switch help_switch = NO_SWITCH; + Switch dummy_switch; for (i = 1; i < argc; i++) { /* check switches */ @@ -1934,6 +2689,77 @@ main( int argc, char **argv) { detectSwitch( line_switch, "line"); endDetect(); + detectSwitch( dummy_switch, "date"); + i++; + if ( i < argc) + manual_date = argv[i]; + else { + cerr << "error: option -date needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( dummy_switch, "release"); + i++; + if ( i < argc) + manual_release = argv[i]; + else { + cerr << "error: option -release needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( dummy_switch, "title"); + i++; + if ( i < argc) + manual_title = argv[i]; + else { + cerr << "error: option -title needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( dummy_switch, "author"); + i++; + if ( i < argc) + manual_author = argv[i]; + else { + cerr << "error: option -author needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( config_switch, "config"); + i++; + if ( i < argc) { + config_path = argv[i]; + if ( config_path[ strlen( config_path) - 1] != '/') { + cerr << "error: option -config: a path must terminate " + "with a /" << endl; + nParameters = ErrParameters; + } + } else { + cerr << "error: option -config needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( dummy_switch, "tmp"); + i++; + if ( i < argc) { + tmp_path = argv[i]; + if ( tmp_path[ strlen( tmp_path) - 1] != '/') { + cerr << "error: option -tmp: a path must terminate " + "with a /" << endl; + nParameters = ErrParameters; + } + } else { + cerr << "error: option -tmp needs an additional parameter" + << endl; + nParameters = ErrParameters; + } + endDetect(); + detectSwitch( help_switch, "h"); endDetect(); detectSwitch( help_switch, "H"); @@ -1955,58 +2781,54 @@ 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_extract_html [] [...]" << endl; - cerr << " -trace sets the `yydebug' variable of bison" + cerr << prog_name << " " << prog_release << " (c) Lutz Kettner" + << endl; + cerr << "Usage: " << prog_name << " [] " + << endl; + cerr << " -date set a date for the manual." << endl; + cerr << " -release set a release number for the " + "manual." << endl; + cerr << " -title set a title text for the manual." + << endl; + cerr << " -author set an author address (email) for " + "the manual." << endl; + cerr << " -config set the path where to find the " + "config files." << endl; + cerr << " -tmp set the path where to put the " + "output files." << endl; + cerr << " -trace set `yydebug' for bison to true" << endl; - cerr << " -line prints parsed line numbers to cerr" - << endl; - cerr << " Infiles including suffixes." + cerr << " -line echo currently parsed line " + "numbers to cerr" << endl; + cerr << "(TeX-files with suffix: .tex or .bbl possible.)" << endl; exit(1); } + + // Initialization + tag_defaults(); + main_stream = &cout; + + // Filter config files for the index. + copy_config_file( cc_index_header); + copy_config_file( cc_index_footer); + + // Prepare several streams: // anchor_stream = new ofstream( anchor_filename, ios::out | ios::app); - anchor_stream = new ofstream( anchor_filename); - if ( ! *anchor_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open anchor file `" - << anchor_filename << "'." << endl; - exit(1); - } - contents_stream = new ofstream( contents_filename); - if ( ! *contents_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open contents file `" - << contents_filename << "'." << endl; - exit(1); - } - open_html( *contents_stream, "Table of Contents"); - *contents_stream << "

          The CGAL Kernel User Manual
          \n" - " Table of Contents


          \n" << endl; - *contents_stream << "
            " << endl; - *contents_stream << "
          1. Title Page" - << endl; - *contents_stream << "
          2. Table of Contents" << endl; - - index_stream = new ofstream( index_filename); - if ( ! *index_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot open index file `" - << index_filename << "'." << endl; - exit(1); - } - *index_stream << "The CGAL Kernel Manual: Index" - "" << general_comment << "" << endl; - *index_stream << "

            Index


            " << endl; - *index_stream << "" << endl; - *index_stream << "
              " << endl; - + anchor_stream = open_file_with_path_for_write( tmp_path, + anchor_filename); + contents_stream = open_file_with_path_for_write( tmp_path, + contents_filename); + copy_and_filter_config_file( cc_toc_header, *contents_stream); + index_stream = open_file_with_path_for_write( tmp_path, index_filename); + write_headers_to_index( *index_stream); + for ( i = 0; i < nParameters; i++) { FILE* in; if ( (in = fopen( parameters[i], "r")) == NULL) { cerr << ' ' << endl - << "cgal_extract_html: error: cannot open infile `" + << prog_name << ": error: cannot open infile `" << parameters[i] << "'." << endl; exit(1); } @@ -2022,31 +2844,16 @@ main( int argc, char **argv) { if ( class_stream != 0) { close_html( *class_stream); - if ( ! *class_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << class_filename << "'." << endl; - exit(1); - } + assert_file_write( *class_stream, class_filename); delete class_stream; delete[] class_filename; class_stream = 0; class_filename = 0; } - if ( ! *main_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << main_filename << "'." << endl; - exit(1); - } + assert_file_write( *main_stream, main_filename); if ( main_stream != &cout) { close_html( *main_stream); - if ( ! *main_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to file `" - << main_filename << "'." << endl; - exit(1); - } + assert_file_write( *main_stream, main_filename); delete main_stream; delete[] main_filename; main_stream = &cout; @@ -2054,53 +2861,16 @@ main( int argc, char **argv) { } } - // The index is organized in a set of fixed topics. - *index_stream << "
            • Classes

              " << endl; - *index_stream << "

            • Variables and Consts

              " - << endl; - *index_stream << "

            • Enums

              " << endl; - *index_stream << "

            • Enum Tags

              " << endl; - /* ... - *index_stream << "

            • References

              " << endl; - ... */ - *index_stream << "

            • " - "Table of Contents

              " << endl; - *index_stream << "

            • " - "Bibliography" << endl; - *index_stream << "
            " << endl; - *index_stream << "" << endl; - *index_stream << "" << html_address_trailer << endl; - *index_stream << "" << endl; - - if ( ! *index_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to index file `" - << index_filename << "'." << endl; - exit(1); - } + assert_file_write( *index_stream, index_filename); delete index_stream; - *contents_stream << "
          3. Bibliography" << endl; - *contents_stream << "
          4. Index" << endl; - *contents_stream << "
          " << endl; - close_html( *contents_stream); - if ( ! *contents_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to contents file `" - << contents_filename << "'." << endl; - exit(1); - } + copy_and_filter_config_file( cc_toc_footer, *contents_stream); + assert_file_write( *contents_stream, contents_filename); delete contents_stream; - if ( ! *anchor_stream) { - cerr << ' ' << endl - << "cgal_extract_html: error: cannot write to anchor file `" - << anchor_filename << "'." << endl; - exit(1); - } + + assert_file_write( *anchor_stream, anchor_filename); delete anchor_stream; - delete chapter_title; + delete[] chapter_title; cout << endl; return 0; diff --git a/Packages/Manual_tools/src/cc_index_sort.c b/Packages/Manual_tools/src/cc_index_sort.c new file mode 100644 index 00000000000..fe715fe7a82 --- /dev/null +++ b/Packages/Manual_tools/src/cc_index_sort.c @@ -0,0 +1,696 @@ +/************************************************************************** + + cc_index_sort.c + ============================================================= + Project : Tools for the CC manual writing task around cc_manual.sty. + Function : Reads an inputfile (or stdin) line by line, sorts them + according to the lexicographic order and binary order + of the characters (alternativly german character ordering). + System : Standard Ansi C + Author : (c) 1992 Lutz Kettner + History : This program is derived from binsort 1.05. It implements + a quicksort algorithm with a pivot chosen as the median + of three randomly chosen elements. Dynamic line management, + works as a filter, also for empty files. + Revision : $Revision$ + Date : $Date$ + +**************************************************************************/ + + +#include +#include +#include +#include + +#define FatalError( str) {\ + fprintf( stderr, "\ncc_index_sort: error: %s.\n", str);\ + exit(1);\ +} + +#define saveMalloc( text, len, ptr) {\ + (ptr) = malloc( len); \ + if ( (ptr) == NULL) { \ + fprintf( stderr, "\ncc_index_sort: error: cannot malloc space for %s.\n",text); \ + exit( 1); \ + } \ +} + +#define vPrintStr( s) if ( verbose) fputs( s, stderr) +#define vPrintInt( s) if ( verbose) fprintf( stderr, "%d", s) +#define vPrintLong( s) if ( verbose) fprintf( stderr, "%ld", s) +#define vNL if ( verbose) putc( '\n', stderr) +#define vDump( l) if ( verbose) writeLines( stderr, (l)) + + +/* Dynamic Line Management */ +/* ======================= */ +/* Lines are stored without trailing \n */ + +typedef struct sList{ + char *text; + struct sList *next; +} tList, *pList; + +typedef char *tIndex; + +typedef struct{ + long count; + pList list; + pList *last; + tIndex *index; +} tLines, *pLines; + + +pLines initLines( void) { + pLines l; + saveMalloc( "initLines", sizeof( tLines), l); + l->count = 0L; + l->list = NULL; + l->last = &( l->list); + l->index = NULL; + return( l); +} + +pLines freeLines( pLines l) { + pList p1, p2; + + if ( l == NULL) + return( l); + p1 = l->list; + while ( p1 != NULL) { + p2 = p1->next; + free( p1->text); + free( p1); + p1 = p2; + } + free( l->index); + free( l); + return( NULL); +} + +pLines appendLine( pLines l, char *text) { + register pList p; + long len; + + if ( l == NULL) + return( l); + len = strlen( text); + if ( text[ len - 1] == '\n') { + len --; + text[ len] = 0; + } + saveMalloc( "listStruct", sizeof( tList), p); + saveMalloc( "textSpace", len + 1, p->text); + p->next = NULL; + strcpy( p->text, text); + *(l->last) = p; + l->last = &( p->next); + l->count ++; + return( l); +} + +pLines makeLinesIndex( pLines l) { + long i; + pList p; + + if ( l == NULL) + return( l); + + free( l->index); + saveMalloc( "indexSpace", l->count * sizeof( tIndex), l->index); + p = l->list; + for ( i = 0; i < l->count; i++) { + l->index[ i] = p->text; + p = p->next; + } + return( l); +} + +pLines reverseLinesIndex( pLines l) { + long i; + tIndex tmp; + + if ( l == NULL) + return( l); + if ( l->index == NULL) + FatalError( "reverseLinesIndex: no index found"); + for ( i = 0; i < ( l->count) >> 1; i++) { + tmp = l->index[ i]; + l->index[ i] = l->index[ l->count - i - 1]; + l->index[ l->count - i - 1] = tmp; + } + return( l); +} + + + +/* Read and Write Dynamic Lines from and to Files */ +/* ============================================== */ + +#define MaxLineLength 32766 +char lineBuffer[ MaxLineLength + 1]; + +pLines readLines( FILE *inFile, pLines l) { + char *line; + + while( 1) { + line = fgets( lineBuffer, MaxLineLength, inFile); + if ( line == NULL) + break; + if ( strlen( line) >= MaxLineLength) + FatalError( "line length too long (>= 32766)"); + l = appendLine( l, line); + } + return( l); +} + +pLines writeLines( FILE *outFile, pLines l) { + long i; + pList p; + + if ( l == NULL) + return( l); + p = l->list; + for ( i = 0; i < l->count; i++) { + fputs( p->text, outFile); + fputc( '\n', outFile); + p = p->next; + } + return( l); +} + +pLines writeLinesByIndex( FILE *outFile, pLines l) { + long i; + + if ( l == NULL) + return( l); + if ( l->index == NULL) + FatalError( "writeLinesByIndex: no index found"); + for ( i = 0; i < l->count; i++) { + fputs( l->index[ i], outFile); + fputc( '\n', outFile); + } + return( l); +} + + +/* Sort Index of Dynamic Lines */ +/* ============================================= */ +/* comparefunction: strcmp( a, b) */ +/* evaluate to: -1 for ab */ +/* --------------------------------------------- */ + +typedef int (*compareFunction)(const char *, const char *); + + +/* Privat */ +/* ------ */ +long iQ, jQ; +int verbose; +tIndex *lineIndex; +compareFunction compare; +char *item, *swapTmp; +long item1, item2, item3, midItem, nItems; + + +void quickSort( long l, long r) { + do { + assert( l - r <= 0); + iQ = l; + jQ = r; + + /* randomisierter Quicksort mit dreier Stichprobe */ + nItems = r - l + 1; + if ( nItems - 10L > 0L) { + item1 = iQ + ( rand() % nItems); + item2 = iQ + ( rand() % nItems); + item3 = iQ + ( rand() % nItems); + if ( compare( lineIndex[ item1], lineIndex[ item2]) > 0) { + if ( compare( lineIndex[ item2], lineIndex[ item3]) > 0) + midItem = item2; + else { + if ( compare( lineIndex[ item1], lineIndex[ item3]) > 0) + midItem = item3; + else + midItem = item1; + } + } else { + if ( compare( lineIndex[ item3], lineIndex[ item2]) > 0) + midItem = item2; + else { + if ( compare( lineIndex[ item1], lineIndex[ item3]) > 0) + midItem = item1; + else + midItem = item3; + } + } + assert( iQ - midItem <= 0); + assert( midItem - jQ <= 0); + swapTmp = lineIndex[ midItem]; + lineIndex[ midItem] = lineIndex[ iQ]; + lineIndex[ iQ] = swapTmp; + } + item = lineIndex[ iQ]; + do { + while (( compare( lineIndex[jQ], item) > -1) && ( iQ - jQ < 0L)) jQ--; + lineIndex[iQ] = lineIndex[jQ]; + while (( compare( lineIndex[iQ], item) < 1) && ( iQ - jQ < 0L)) iQ++; + lineIndex[jQ] = lineIndex[iQ]; + } while( iQ != jQ); + lineIndex[iQ] = item; + jQ = l; + l = iQ + 1; + if ( jQ - iQ + 1 < 0L) + quickSort( jQ, iQ-1); /* linke Haelfte sortieren */ + } while ( l - r < 0L); /* rechte Haelfte durch Endrekursion sortieren */ +} + +pLines sortLines( pLines l, compareFunction f, int verb) { + if ( l == NULL) + return( l); + if ( l->index == NULL) + FatalError( "sortLines: no index found"); + + /* init privat global variables */ + compare = f; + verbose = verb; + lineIndex = l->index; + + vPrintStr( "sortLines()\n"); + if ( l->count > 0) + quickSort( 0L, l->count - 1); + return( l); +} + + +/* Other Comparefunctions */ +/* ====================== */ + +int germanTable[ 256]; + +void initGermanTable( void) { + germanTable[ 0] = 0; + germanTable[ 1] = 10; + germanTable[ 2] = 20; + germanTable[ 3] = 30; + germanTable[ 4] = 40; + germanTable[ 5] = 50; + germanTable[ 6] = 60; + germanTable[ 7] = 70; + germanTable[ 8] = 80; + germanTable[ 9] = 90; + germanTable[ 10] = 100; + germanTable[ 11] = 110; + germanTable[ 12] = 120; + germanTable[ 13] = 130; + germanTable[ 14] = 140; + germanTable[ 15] = 150; + germanTable[ 16] = 160; + germanTable[ 17] = 170; + germanTable[ 18] = 180; + germanTable[ 19] = 190; + germanTable[ 20] = 200; + germanTable[ 21] = 210; + germanTable[ 22] = 220; + germanTable[ 23] = 230; + germanTable[ 24] = 240; + germanTable[ 25] = 250; + germanTable[ 26] = 260; + germanTable[ 27] = 270; + germanTable[ 28] = 280; + germanTable[ 29] = 290; + germanTable[ 30] = 300; + germanTable[ 31] = 310; + germanTable[ 32] = 320; /* ' ' */ + germanTable[ 33] = 330; /* '!' */ + germanTable[ 34] = 340; /* '"' */ + germanTable[ 35] = 350; /* '#' */ + germanTable[ 36] = 360; /* '$' */ + germanTable[ 37] = 370; /* '%' */ + germanTable[ 38] = 380; /* '&' */ + germanTable[ 39] = 390; /* ''' */ + germanTable[ 40] = 400; /* '(' */ + germanTable[ 41] = 410; /* ')' */ + germanTable[ 42] = 420; /* '*' */ + germanTable[ 43] = 430; /* '+' */ + germanTable[ 44] = 440; /* ',' */ + germanTable[ 45] = 450; /* '-' */ + germanTable[ 46] = 460; /* '.' */ + germanTable[ 47] = 470; /* '/' */ + germanTable[ 48] = 480; /* '0' */ + germanTable[ 49] = 490; /* '1' */ + germanTable[ 50] = 500; /* '2' */ + germanTable[ 51] = 510; /* '3' */ + germanTable[ 52] = 520; /* '4' */ + germanTable[ 53] = 530; /* '5' */ + germanTable[ 54] = 540; /* '6' */ + germanTable[ 55] = 550; /* '7' */ + germanTable[ 56] = 560; /* '8' */ + germanTable[ 57] = 570; /* '9' */ + germanTable[ 58] = 580; /* ':' */ + germanTable[ 59] = 590; /* ';' */ + germanTable[ 60] = 600; /* '<' */ + germanTable[ 61] = 610; /* '=' */ + germanTable[ 62] = 620; /* '>' */ + germanTable[ 63] = 630; /* '?' */ + germanTable[ 64] = 640; /* '@' */ + germanTable[ 65] = 651; /* 'A' */ + germanTable[ 66] = 666; /* 'B' */ + germanTable[ 67] = 671; /* 'C' */ + germanTable[ 68] = 681; /* 'D' */ + germanTable[ 69] = 691; /* 'E' */ + germanTable[ 70] = 701; /* 'F' */ + germanTable[ 71] = 711; /* 'G' */ + germanTable[ 72] = 721; /* 'H' */ + germanTable[ 73] = 731; /* 'I' */ + germanTable[ 74] = 741; /* 'J' */ + germanTable[ 75] = 751; /* 'K' */ + germanTable[ 76] = 761; /* 'L' */ + germanTable[ 77] = 771; /* 'M' */ + germanTable[ 78] = 781; /* 'N' */ + germanTable[ 79] = 791; /* 'O' */ + germanTable[ 80] = 801; /* 'P' */ + germanTable[ 81] = 811; /* 'Q' */ + germanTable[ 82] = 821; /* 'R' */ + germanTable[ 83] = 831; /* 'S' */ + germanTable[ 84] = 841; /* 'T' */ + germanTable[ 85] = 851; /* 'U' */ + germanTable[ 86] = 861; /* 'V' */ + germanTable[ 87] = 871; /* 'W' */ + germanTable[ 88] = 881; /* 'X' */ + germanTable[ 89] = 891; /* 'Y' */ + germanTable[ 90] = 901; /* 'Z' */ + germanTable[ 91] = 910; /* '[' */ + germanTable[ 92] = 920; /* '\' */ + germanTable[ 93] = 930; /* ']' */ + germanTable[ 94] = 940; /* '^' */ + germanTable[ 95] = 950; /* '_' */ + germanTable[ 96] = 960; /* '`' */ + germanTable[ 97] = 650; /* 'a' */ + germanTable[ 98] = 665; /* 'b' */ + germanTable[ 99] = 670; /* 'c' */ + germanTable[100] = 680; /* 'd' */ + germanTable[101] = 690; /* 'e' */ + germanTable[102] = 700; /* 'f' */ + germanTable[103] = 710; /* 'g' */ + germanTable[104] = 720; /* 'h' */ + germanTable[105] = 730; /* 'i' */ + germanTable[106] = 740; /* 'j' */ + germanTable[107] = 750; /* 'k' */ + germanTable[108] = 760; /* 'l' */ + germanTable[109] = 770; /* 'm' */ + germanTable[110] = 780; /* 'n' */ + germanTable[111] = 790; /* 'o' */ + germanTable[112] = 800; /* 'p' */ + germanTable[113] = 810; /* 'q' */ + germanTable[114] = 820; /* 'r' */ + germanTable[115] = 830; /* 's' */ + germanTable[116] = 840; /* 't' */ + germanTable[117] = 850; /* 'u' */ + germanTable[118] = 860; /* 'v' */ + germanTable[119] = 870; /* 'w' */ + germanTable[120] = 880; /* 'x' */ + germanTable[121] = 890; /* 'y' */ + germanTable[122] = 900; /* 'z' */ + germanTable[123] = 1230; /* '{' */ + germanTable[124] = 1240; /* '|' */ + germanTable[125] = 1250; /* '}' */ + germanTable[126] = 1260; /* '~' */ + germanTable[127] = 1270; /* '' */ + germanTable[128] = 673; /* '€' */ + germanTable[129] = 852; /* '' */ + germanTable[130] = 691; /* '‚' */ + germanTable[131] = 654; /* 'ƒ' */ + germanTable[132] = 652; /* '„' */ + germanTable[133] = 655; /* '…' */ + germanTable[134] = 656; /* '†' */ + germanTable[135] = 672; /* '‡' */ + germanTable[136] = 692; /* 'ˆ' */ + germanTable[137] = 693; /* '‰' */ + germanTable[138] = 694; /* 'Š' */ + germanTable[139] = 732; /* '‹' */ + germanTable[140] = 733; /* 'Œ' */ + germanTable[141] = 734; /* '' */ + germanTable[142] = 653; /* 'Ž' */ + germanTable[143] = 657; /* '' */ + germanTable[144] = 695; /* '' */ + germanTable[145] = 660; /* '‘' */ + germanTable[146] = 658; /* '’' */ + germanTable[147] = 794; /* '“' */ + germanTable[148] = 792; /* '”' */ + germanTable[149] = 795; /* '•' */ + germanTable[150] = 854; /* '–' */ + germanTable[151] = 855; /* '—' */ + germanTable[152] = 892; /* '˜' */ + germanTable[153] = 793; /* '™' */ + germanTable[154] = 853; /* 'š' */ + germanTable[155] = 1550; /* '›' */ + germanTable[156] = 1560; /* 'œ' */ + germanTable[157] = 1570; /* '' */ + germanTable[158] = 1580; /* 'ž' */ + germanTable[159] = 1590; /* 'Ÿ' */ + germanTable[160] = 659; /* ' ' */ + germanTable[161] = 735; /* '¡' */ + germanTable[162] = 796; /* '¢' */ + germanTable[163] = 856; /* '£' */ + germanTable[164] = 782; /* '¤' */ + germanTable[165] = 783; /* '¥' */ + germanTable[166] = 1660; /* '¦' */ + germanTable[167] = 1670; /* '§' */ + germanTable[168] = 1680; /* '¨' */ + germanTable[169] = 1690; /* '©' */ + germanTable[170] = 1700; /* 'ª' */ + germanTable[171] = 1710; /* '«' */ + germanTable[172] = 1720; /* '¬' */ + germanTable[173] = 1730; /* '­' */ + germanTable[174] = 1740; /* '®' */ + germanTable[175] = 1750; /* '¯' */ + germanTable[176] = 1760; /* '°' */ + germanTable[177] = 1770; /* '±' */ + germanTable[178] = 1780; /* '²' */ + germanTable[179] = 1790; /* '³' */ + germanTable[180] = 1800; /* '´' */ + germanTable[181] = 1810; /* 'µ' */ + germanTable[182] = 1820; /* '¶' */ + germanTable[183] = 1830; /* '·' */ + germanTable[184] = 1840; /* '¸' */ + germanTable[185] = 1850; /* '¹' */ + germanTable[186] = 1860; /* 'º' */ + germanTable[187] = 1870; /* '»' */ + germanTable[188] = 1880; /* '¼' */ + germanTable[189] = 1890; /* '½' */ + germanTable[190] = 1900; /* '¾' */ + germanTable[191] = 1910; /* '¿' */ + germanTable[192] = 1920; /* 'À' */ + germanTable[193] = 1930; /* 'Á' */ + germanTable[194] = 1940; /* 'Â' */ + germanTable[195] = 1950; /* 'Ã' */ + germanTable[196] = 1960; /* 'Ä' */ + germanTable[197] = 1970; /* 'Å' */ + germanTable[198] = 1980; /* 'Æ' */ + germanTable[199] = 1990; /* 'Ç' */ + germanTable[200] = 2000; /* 'È' */ + germanTable[201] = 2010; /* 'É' */ + germanTable[202] = 2020; /* 'Ê' */ + germanTable[203] = 2030; /* 'Ë' */ + germanTable[204] = 2040; /* 'Ì' */ + germanTable[205] = 2050; /* 'Í' */ + germanTable[206] = 2060; /* 'Î' */ + germanTable[207] = 2070; /* 'Ï' */ + germanTable[208] = 2080; /* 'Ð' */ + germanTable[209] = 2090; /* 'Ñ' */ + germanTable[210] = 2100; /* 'Ò' */ + germanTable[211] = 2110; /* 'Ó' */ + germanTable[212] = 2120; /* 'Ô' */ + germanTable[213] = 2130; /* 'Õ' */ + germanTable[214] = 2140; /* 'Ö' */ + germanTable[215] = 2150; /* '×' */ + germanTable[216] = 2160; /* 'Ø' */ + germanTable[217] = 2170; /* 'Ù' */ + germanTable[218] = 2180; /* 'Ú' */ + germanTable[219] = 2190; /* 'Û' */ + germanTable[220] = 2200; /* 'Ü' */ + germanTable[221] = 2210; /* 'Ý' */ + germanTable[222] = 2220; /* 'Þ' */ + germanTable[223] = 2230; /* 'ß' */ + germanTable[224] = 2240; /* 'à' */ + germanTable[225] = 832; /* 'á' */ + germanTable[226] = 2260; /* 'â' */ + germanTable[227] = 2270; /* 'ã' */ + germanTable[228] = 2280; /* 'ä' */ + germanTable[229] = 2290; /* 'å' */ + germanTable[230] = 2300; /* 'æ' */ + germanTable[231] = 2310; /* 'ç' */ + germanTable[232] = 2320; /* 'è' */ + germanTable[233] = 2330; /* 'é' */ + germanTable[234] = 2340; /* 'ê' */ + germanTable[235] = 2350; /* 'ë' */ + germanTable[236] = 2360; /* 'ì' */ + germanTable[237] = 2370; /* 'í' */ + germanTable[238] = 2380; /* 'î' */ + germanTable[239] = 2390; /* 'ï' */ + germanTable[240] = 2400; /* 'ð' */ + germanTable[241] = 2410; /* 'ñ' */ + germanTable[242] = 2420; /* 'ò' */ + germanTable[243] = 2430; /* 'ó' */ + germanTable[244] = 2440; /* 'ô' */ + germanTable[245] = 2450; /* 'õ' */ + germanTable[246] = 2460; /* 'ö' */ + germanTable[247] = 2470; /* '÷' */ + germanTable[248] = 2480; /* 'ø' */ + germanTable[249] = 2490; /* 'ù' */ + germanTable[250] = 2500; /* 'ú' */ + germanTable[251] = 2510; /* 'û' */ + germanTable[252] = 2520; /* 'ü' */ + germanTable[253] = 2530; /* 'ý' */ + germanTable[254] = 2540; /* 'þ' */ + germanTable[255] = 2550; /* 'ÿ' */ +} + +int germanCompare( const char *s, const char *t) { + while( germanTable[ (int)(*s)] == germanTable[ (int)(*t)]) { + if ( *s == 0) { + if ( *t == 0) + return( 0); + else + return( -1); + } else if ( *t == 0) + return( 1); + s++; + t++; + } + if ( germanTable[ (int)(*s)] < germanTable[ (int)(*t)]) + return( -1); + return( 1); +} + + + + +/* main */ +/* ==== */ + +#define MaxParameters 2 +#define MaxOptionalParameters 2 +#define ErrParameters 10000 + +typedef char tSwitch; + +#define NoSwitch 0 +#define MinusSwitch 1 +#define PlusSwitch 2 + +tSwitch reverseSwitch = NoSwitch; +tSwitch germanSwitch = NoSwitch; +tSwitch verboseSwitch = NoSwitch; + + +/* this macro opens a block, in which the switch is detected */ +/* it must be closed with the macro endDetect() */ +#define detectSwitch( var, text) \ + if ( (( argv[i][0] == '/' ) || ( argv[i][0] == '-' ) || \ + ( argv[i][0] == '+' )) && ( strcmp( text, argv[i]+1) == 0)) { \ + if ( argv[i][0] == '+' ) \ + var = PlusSwitch; \ + else \ + var = MinusSwitch; + +#define endDetect() \ + if ( nParameters <= MaxParameters ) \ + continue; \ + else \ + break; \ + } + + +/* >main: main function with standard unix parameter input */ + +int main( int argc, char **argv) { + int i; + int err = 0; + int nParameters = 0; + char *parameters[ MaxParameters + 1]; + + tSwitch helpSwitch = NoSwitch; + + for (i = 1; i < argc; i++) { + + /* check switches */ + detectSwitch( reverseSwitch, "r"); + endDetect(); + detectSwitch( germanSwitch, "ger"); + endDetect(); + detectSwitch( verboseSwitch, "v"); + endDetect(); + + + detectSwitch( helpSwitch, "h"); + endDetect(); + detectSwitch( helpSwitch, "H"); + endDetect(); + detectSwitch( helpSwitch, "help"); + endDetect(); + + /* else get standard or optional paramters */ + if ( nParameters < MaxParameters ) { + parameters[nParameters ++] = argv[i]; + continue; + } + + nParameters = ErrParameters; + break; + } + + if ((nParameters < MaxParameters - MaxOptionalParameters) || + (nParameters > MaxParameters) || (helpSwitch != NoSwitch)) { + if (helpSwitch == NoSwitch) + fputs( "Error: in parameter list\n", stderr); + fputs( "cc_index_sort $Revision$ (c) Lutz Kettner\n", stderr); + fputs( "Usage: cc_index_sort [-r] [-ger] [-v] [ []]\n", stderr); + fputs( " -r reverse order\n", stderr); + fputs( " -ger german character ordering\n", stderr); + fputs( " -v verbose, print internals\n", stderr); + exit(1); + } + + { + FILE *in, + *out; + pLines lines; + + in = stdin; + out = stdout; + lines = initLines(); + initGermanTable(); + + if ( nParameters >= 1) + if ( (in = fopen( parameters[0], "r")) == NULL) { + fprintf( stderr, "\ncc_index_sort: error: cannot open infile %s.\n", + parameters[0]); + exit(1); + } + lines = readLines( in, lines); + if ( nParameters >= 1) + fclose( in); + + lines = makeLinesIndex( lines); + if ( germanSwitch) + lines = sortLines( lines, germanCompare, verboseSwitch); + else + lines = sortLines( lines, strcmp, verboseSwitch); + if ( reverseSwitch) + lines = reverseLinesIndex( lines); + + if ( nParameters == 2) + if ( (out = fopen( parameters[1], "w")) == NULL) { + fprintf( stderr, "cc_index_sort: error: cannot open outfile %s.\n", + parameters[1]); + exit(1); + } + lines = freeLines( writeLinesByIndex( out, lines)); + if ( nParameters == 2) + fclose( out); + } + return(err); +} diff --git a/Packages/Manual_tools/src/cc_manual_to_html b/Packages/Manual_tools/src/cc_manual_to_html new file mode 100755 index 00000000000..0cfee9a0cc0 --- /dev/null +++ b/Packages/Manual_tools/src/cc_manual_to_html @@ -0,0 +1,284 @@ +#!/bin/csh -f +# ************************************************************************** +# +# cc_manual_to_html +# =================== +# A script to convert a specification written in a TeX file with the +# cc_manual.sty into an online manual in HTML. +# +# It is a two step procedure: First all TeX files are converted into +# HTML. Meanwhile the necessary information for the cross links is +# collected as set of flex-rules. In the second step are the hyperlinks +# generated for all HTML files. +# +# The following programs are necessary to run this script +# +# o cc_extract_html +# o flex +# o cc / gcc +# o cc_index_sort +# +# Author : (c) 1997 Lutz Kettner +# Revision : $Revision$ +# Date : $Date$ +# +# ************************************************************************** + +# ======================================================= +# Installation: chose the appropriate compiler and paths: +# ======================================================= +# A C compiler can be specified here. Normally cc or gcc should work. +# Note: cc does not work on SunOS 4.1.3 (BSD), but on SunOS 5... +#set CC = gcc +set CC = cc + +# Path for the HTML conversion tools for the default configuration files. +# This path will be compiled into the cc_extract_html program. +# The same variable has to be configured here. (No slash / at the end!) +#set HTML_DEFAULT_PATH = +set HTML_DEFAULT_PATH = /home/kettner/topics/cgal/Tools/src/html_config_files + +# A couple of default settings that the cc_extract_html program does not know. +set DEFAULT_DATE = `date +"%a, %B %e, %Y"` +set DEFAULT_AUTHOR = "The CGAL Project" +set DEFAULT_TITLE = "The CGAL Kernel Manual" + +# ======================================================= +# Installation: Nothing else below this line. +# ======================================================= + +if ( $?DEBUG) echo "# DEBUG defined; all commands will be echoed." + +# Prepare local variables +# ----------------------- +set tmp_path = "/usr/tmp" +if ( ! -d ${tmp_path}) set = tmp_path = "." +if ($?TEMP) then + if (-d ${TEMP}) set tmp_path = $TEMP +endif +if ($?TMP) then + if (-d ${TMP}) set tmp_path = $TMP +endif + +set out_path = "." +set config_path = ${HTML_DEFAULT_PATH} + +set DEFAULT_RELEASE = + +set default_switch = 0 +set show_main_switch = 0 + +# Parse command line parameters +# ----------------------------- + +if ( $?DEBUG) echo "# command line parsing." + +if ( $#argv < 1) goto usage +set in_files = "" + +while ($#argv > 0) + if ( "$1" == "-h") goto usage + if ( "$1" == "-help") goto usage + + if ( "$1" == "-defaults") then + set default_switch = 1 + break + endif + + if ( "$1" == "-show_main") then + set show_main_switch = 1; + shift + continue + endif + if ( "$1" == "-config") then + shift + if ( $#argv < 1) then + echo "error: switch -config needs an additional parameter." + goto usage + endif + if ( ! -d $1) then + echo "error: switch -config needs a valid directory as parameter." + goto usage + endif + set config_path = "$1" + shift + continue + endif + if ( "$1" == "-tmp") then + shift + if ( $#argv < 1) then + echo "error: switch -tmp needs an additional parameter." + goto usage + endif + if ( ! -d $1) then + echo "error: switch -tmp needs a valid directory as parameter." + goto usage + endif + set tmp_path = "$1" + shift + continue + endif + if ( "$1" == "-o") then + shift + if ( $#argv < 1) then + echo "error: switch -o needs an additional parameter." + goto usage + endif + if ( ! -d $1) then + echo "error: switch -o needs a valid directory as parameter." + goto usage + endif + set out_path = "$1" + shift + continue + endif + if ( "$1" == "-date") then + shift + if ( $#argv < 1) then + echo "error: switch -date needs an additional parameter." + goto usage + endif + set DEFAULT_DATE = "$1" + shift + continue + endif + if ( "$1" == "-release") then + shift + if ( $#argv < 1) then + echo "error: switch -release needs an additional parameter." + goto usage + endif + set DEFAULT_RELEASE = "$1" + shift + continue + endif + if ( "$1" == "-title") then + shift + if ( $#argv < 1) then + echo "error: switch -title needs an additional parameter." + goto usage + endif + set DEFAULT_TITLE = "$1" + shift + continue + endif + if ( "$1" == "-author") then + shift + if ( $#argv < 1) then + echo "error: switch -author needs an additional parameter." + goto usage + endif + set DEFAULT_AUTHOR = "$1" + shift + continue + endif + + set in_files = "$in_files $1" + shift +end + +if ( $?DEBUG || $default_switch == 1) then + echo "The variable settings (including commmandline options) are:" + echo " HTML_DEFAULT_PATH = ${HTML_DEFAULT_PATH}" + echo " DEFAULT_DATE = ${DEFAULT_DATE}" + echo " DEFAULT_AUTHOR = ${DEFAULT_AUTHOR}" + echo " DEFAULT_TITLE = ${DEFAULT_TITLE}" + echo " DEFAULT_RELEASE = ${DEFAULT_RELEASE}" + echo " tmp_path = ${tmp_path}" + echo " out_path = ${out_path}" + echo " config_path = ${config_path}" + echo " input_files = ${in_files}" + echo "" +endif +if ( $default_switch) goto end_of_script + +if ( "$in_files" == "") goto usage + +# Make a subdirectory for the temp_path: +# -------------------------------------- +set tmp_name = "extract_html_tmp" +if ( $?DEBUG) echo "# Make a subdirectory 'extract_html_tmp' for the tmp_path." + +set new_tmp_path = ${tmp_path}/${tmp_name} +if ( -d ${new_tmp_path}) then + echo "error: the subdirectory 'extract_html_tmp' for the tmp_path exists already." + echo " type 'rm -r ${new_tmp_path}' to remove it." + goto usage +endif +mkdir ${new_tmp_path} + + +# Step 1: convert each LaTeX file into an HTML file. +# -------------------------------------------------- +if ( $?DEBUG) echo "# Step 1: convert each LaTeX file into an HTML file." +if ($show_main_switch) then + if ( $?DEBUG) echo "cc_extract_html -date "'"'"${DEFAULT_DATE}"'"'" -release "'"'"${DEFAULT_RELEASE}"'"'" -title "'"'"${DEFAULT_TITLE}"'"'" -author "'"'"${DEFAULT_AUTHOR}"'"'" -config ${config_path}/ -tmp ${new_tmp_path}/ ${in_files}" + cc_extract_html -date "${DEFAULT_DATE}" -release "${DEFAULT_RELEASE}" -title "${DEFAULT_TITLE}" -author "${DEFAULT_AUTHOR}" -config ${config_path}/ -tmp ${new_tmp_path}/ ${in_files} +else + if ( $?DEBUG) echo "cc_extract_html -date "'"'"${DEFAULT_DATE}"'"'" -release "'"'"${DEFAULT_RELEASE}"'"'" -title "'"'"${DEFAULT_TITLE}"'"'" -author "'"'"${DEFAULT_AUTHOR}"'"'" -config ${config_path}/ -tmp ${new_tmp_path}/ ${in_files} >/dev/null" + cc_extract_html -date "${DEFAULT_DATE}" -release "${DEFAULT_RELEASE}" -title "${DEFAULT_TITLE}" -author "${DEFAULT_AUTHOR}" -config ${config_path}/ -tmp ${new_tmp_path}/ ${in_files} >/dev/null +endif + +# Step 2: generate the hyperlinks. The anchor filter. +# --------------------------------------------------- +if ( $?DEBUG) echo "# Step 2: generate the hyperlinks. The anchor filter" + +if ( $?DEBUG) echo "cat ${config_path}/cc_anchor_header ${new_tmp_path}/cc_anchor_rules ${config_path}/cc_anchor_footer > ${new_tmp_path}/cc_anchor_filter.yy" +cat ${config_path}/cc_anchor_header ${new_tmp_path}/cc_anchor_rules ${config_path}/cc_anchor_footer > ${new_tmp_path}/cc_anchor_filter.yy + +if ( $?DEBUG) echo "flex -t -8 ${new_tmp_path}/cc_anchor_filter.yy > ${new_tmp_path}/cc_anchor_filter.c" +flex -t -8 ${new_tmp_path}/cc_anchor_filter.yy > ${new_tmp_path}/cc_anchor_filter.c + +if ( $?DEBUG) echo "cc -o ${new_tmp_path}/cc_anchor_filter ${new_tmp_path}/cc_anchor_filter.c" +cc -o ${new_tmp_path}/cc_anchor_filter ${new_tmp_path}/cc_anchor_filter.c +if (-r cc_anchor_filter.o) rm cc_anchor_filter.o + +# Filtering all HTML files. +# ------------------------- +if ( $?DEBUG) echo "# Filtering all HTML files." +foreach f (${new_tmp_path}/*.html) + if ( $?DEBUG) echo "${new_tmp_path}/cc_anchor_filter < $f > ${out_path}/$f:t" + ${new_tmp_path}/cc_anchor_filter < $f > ${out_path}/$f:t +end + +# Converting the index. +# --------------------- +if ( $?DEBUG) echo "# Converting the index." + +if ( $?DEBUG) echo "cc_index_sort -ger ${new_tmp_path}/cc_index_body | sed 's/[<][\!]sort[^\!]*[\!][>]//' > ${new_tmp_path}/cc_index_sorted" +cc_index_sort -ger ${new_tmp_path}/cc_index_body | sed 's/[<][\!]sort[^\!]*[\!][>]//' > ${new_tmp_path}/cc_index_sorted + +if ( $?DEBUG) echo "cat ${new_tmp_path}/cc_index_header ${new_tmp_path}/cc_index_sorted ${new_tmp_path}/cc_index_footer > ${new_tmp_path}/cc_index" +cat ${new_tmp_path}/cc_index_header ${new_tmp_path}/cc_index_sorted ${new_tmp_path}/cc_index_footer > ${new_tmp_path}/cc_index + +if ( $?DEBUG) echo "${new_tmp_path}/cc_anchor_filter < ${new_tmp_path}/cc_index > ${out_path}/manual_index.html" +${new_tmp_path}/cc_anchor_filter < ${new_tmp_path}/cc_index > ${out_path}/manual_index.html + + +# Cleanup +# ------- +if ( $?DEBUG) echo "# Cleanup and all done" +if ( $?DEBUG) then + echo "# rm -r ${new_tmp_path}" +else + rm -r ${new_tmp_path} +endif + +end_of_script: +exit + +usage: +echo "$0 "'$Revision$'" (c) Lutz Kettner" +echo "Usage: $0 [] " +echo " -defaults show the settings of the internal variables." +echo " -show_main show the translation result for the main file." +echo " -date set a date for the manual." +echo " -release set a release number for the manual." +echo " -title set a title text for the manual." +echo " -author set an author address (email) for the manual." +echo " -config set the path where to find the config files." +echo " -tmp set the path where to put the output files." +echo " " +echo " -o output directory for the generated HTML manual" +exit (1) + diff --git a/Packages/Manual_tools/src/config.h b/Packages/Manual_tools/src/config.h new file mode 100644 index 00000000000..7c42af3bb21 --- /dev/null +++ b/Packages/Manual_tools/src/config.h @@ -0,0 +1,59 @@ +/************************************************************************** + + config.h + ============================================================= + Project : CGAL merger tool for the specification task + Function : Configuration constants and variables + System : C++ (g++) + Author : (c) 1995 Lutz Kettner + Revision : $Revision$ + Date : $Date$ + +**************************************************************************/ + +#if ! defined( MODULE_CONFIG) +#define MODULE_CONFIG 1 + + +// Global declarations that are implemented in the main module. +// There they can be taylored to the specific application, i.e. +// extraction or checker. + +void handleComment( const Text& T); +void handleConstructorComment( const Text& T); +void handleMainComment( const Text& T); + +void handleClass( const char* classname); +void handleClassEnd( void); +void handleClassTemplate( const char* classname); +void handleClassTemplateEnd( void); + +void handleDeclaration( const char* decl); +void handleNestedType( const char* decl); +void handleMethodDeclaration( const char* decl); +void handleConstructorDeclaration( const char* decl); +void handleFunctionDeclaration( const char* decl); +void handleFunctionTemplateDeclaration( const char* templ, const char* decl); + +// Error messages and Numbers +// ========================== +enum ErrorNumber { + NoError, + ParseError, // must stay at position 1 + VariableUsedError, + ClassnameUsedError, + TemplateParamExpectedError, + MalformedTemplateParamError, + MalformedFunctionDeclaration, + SemicolonMissingError +}; + + +// Functions belonging to the Error messages +// ----------------------------------------- +// See their implementations in syntax.y + +const char* errorMessage( ErrorNumber n); +void printErrorMessage( ErrorNumber n); + +#endif // MODULE_CONFIG // diff --git a/Packages/Manual_tools/src/extract_lex.yy b/Packages/Manual_tools/src/extract_lex.yy new file mode 100644 index 00000000000..a6a404f2b0b --- /dev/null +++ b/Packages/Manual_tools/src/extract_lex.yy @@ -0,0 +1,611 @@ +/************************************************************************** + + extract_lex.yy + ============================================================= + Project : CGAL merger tool for the specification task + Function : lexical scanner for TeX and C++ code mixed files. + System : flex, bison, C++ (g++) + Author : (c) 1995 Lutz Kettner + Revision : $Revision$ + Date : $Date$ + +**************************************************************************/ + +%{ +#include +#include +#include +#include +#include +#include + +/* Set this flag to 1 to switch immediately to CCMode. */ +int set_CCMode = 0; +/* Set this flag to 1 to switch immediately to NestingMode. */ +int set_NestingMode = 0; +/* Set this flag to 1 to switch back to INITIAL. */ +int set_INITIAL = 0; + +/* Tag to mark the unchecked keyword */ +int unchecked_tag = 0; + +/* Count the linenumber for better errormessages. */ +int line_number = 1; + +/* store the creationvariable */ +char* creationvariable = NULL; + +/* remember the necessary stop character for \verb"..." */ +char stop_character; + +/* The classname and other state varaibles */ +char* global_classname = 0; +char* global_template_params = 0; + +/* Hack, to get rid of the yywrap. */ +#define YY_SKIP_YYWRAP 1 +#define yywrap() 1 + +%} + +/* The normal scanning mode parses TeX conventions. */ +/* In CCMode, it parses C++ conventions. */ +/* The NestingMode parses only (){}[] nested expressions */ +/* The VerbMode parses LaTeX \verb"..." statements as */ +/* a sequence of characters */ +%x CCMode +%x NestingMode +%x VerbMode + +letter [a-zA-Z] +digit [0-9] +CCletter [a-zA-Z_] +idfier {letter}+ +CCidfier ({CCletter}({CCletter}|{digit})*) +space [\t ] +w {space}* +ws {space}+ +escchar [\\] +sign [+-] +exp [eE] +number {digit}+ +signNumber ({sign}?{number}) +floatNumber ({signNumber}\.|{signNumber}\.{number}) +expNumber ({floatNumber}|{signNumber}){exp}{signNumber} +No ({signNumber}|{floatNumber}|{expNumber}) +operator [^a-zA-Z_0-9\n\r\t \\] +blockintro [\{][\\]((tt)|(em)|(it)|(sc)|(sl)) + +%% + /* Mode switching can be triggered from the parser */ + /* ----------------------------------------------- */ + if (set_CCMode) { + BEGIN( CCMode); + set_CCMode = 0; + } + if (set_NestingMode) { + BEGIN( NestingMode); + set_NestingMode = 0; + } + if (set_INITIAL) { + BEGIN( INITIAL); + set_INITIAL = 0; + } + + /* Count line numbers in all modes for better error messages */ + /* --------------------------------------------------------- */ +[\n] { + line_number++; + return NEWLINE; + } + + /* Rules for TeX conventions */ + /* ------------------------- */ +[\\]"%" { /* Avoid the quoted comment symbol */ + yylval.character = '%'; + return CHAR; + } +"%".*[\n]{w} { /* Match one line TeX comments */ + /* remove spaces in next line */ + unput( '\n'); + } +"%".* { /* Match one line TeX comments at the last line in file */ + } +[\\]verb[^a-zA-Z] { /* match LaTeX \verb"..." constructs */ + BEGIN( VerbMode); + stop_character = yytext[ yyleng-1]; + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; + } +{ws} { + yylval.string.text = yytext; + yylval.string.len = yyleng; + return SPACE; + } +. { + if ( yytext[0] == stop_character) { + BEGIN( INITIAL); + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; + } + yylval.character = yytext[0]; + return CHAR; + } + + /* Trigger on different keywords */ + /* ----------------------------- */ +[\\]begin{w}[\{]ccClass[\}]{w} { + BEGIN( CCMode); + return BEGINCLASS; + } +[\\]end{w}[\{]ccClass[\}] { + return ENDCLASS; + } +[\\]begin{w}[\{]ccClassTemplate[\}]{w} { + BEGIN( CCMode); + return BEGINCLASSTEMPLATE; + } +[\\]end{w}[\{]ccClassTemplate[\}] { + return ENDCLASSTEMPLATE; + } +[\\]ccCreationVariable{w}[\{]{w}.*{w}[\}] { + char *s = yytext + yyleng - 2; + while (( *s == ' ') || ( *s == '\t')) + s--; + char *r = yytext; + while ( *r != '{') + r++; + r++; + while (( *r == ' ') || ( *r == '\t')) + r++; + r[-1] = '`'; + s[1] = '\''; + s[2] = 0; + free( creationvariable); + creationvariable = strdup( r - 1); + s[1] = 0; + yylval.string.text = r; + yylval.string.len = s - r + 1; + return CREATIONVARIABLE; + } +[\\]ccConstructor{w} { /* constructor declaration: change to CCMode */ + BEGIN( CCMode); + return CONSTRUCTOR; + } +[\\]ccMemberFunction{w} { /* method declaration: change to CCMode */ + BEGIN( CCMode); + return METHOD; + } +[\\]ccMethod{w} { /* method declaration: change to CCMode */ + BEGIN( CCMode); + return METHOD; + } +[\\]ccFunction{w} { /* function declaration: change to CCMode */ + BEGIN( CCMode); + return FUNCTION; + } +[\\]ccFunctionTemplate{w} { /* function template declaration: + change to CCMode */ + BEGIN( CCMode); + return FUNCTIONTEMPLATE; + } +[\\]ccVariable{w} { /* variable declaration: change to CCMode */ + BEGIN( CCMode); + return VARIABLE; + } +[\\]ccTypedef{w} { /* typedef declaration: change to CCMode */ + BEGIN( CCMode); + return TYPEDEF; + } +[\\]ccNestedType{w} { /* nested type declaration: change to CCMode */ + BEGIN( CCMode); + return NESTEDTYPE; + } +[\\]ccEnum{w} { /* enum declaration: change to CCMode */ + BEGIN( CCMode); + return ENUM; + } +[\\]ccStruct{w} { /* struct declaration: change to CCMode */ + BEGIN( CCMode); + return STRUCT; + } +[\\]ccGlobalFunction{w} { /* function declaration: change to CCMode */ + BEGIN( CCMode); + return GLOBALFUNCTION; + } +[\\]ccGlobalFunctionTemplate{w} { /* function template declaration: + change to CCMode */ + BEGIN( CCMode); + return GLOBALFUNCTIONTEMPLATE; + } +[\\]ccGlobalVariable{w} { /* variable declaration: change to CCMode */ + BEGIN( CCMode); + return GLOBALVARIABLE; + } +[\\]ccGlobalTypedef{w} { /* typedef declaration: change to CCMode */ + BEGIN( CCMode); + return GLOBALTYPEDEF; + } +[\\]ccGlobalEnum{w} { /* enum declaration: change to CCMode */ + BEGIN( CCMode); + return GLOBALENUM; + } +[\\]ccGlobalStruct{w} { /* struct declaration: change to CCMode */ + BEGIN( CCMode); + return GLOBALSTRUCT; + } +[\\]ccDeclaration{w} { /* general declaration: change to CCMode */ + BEGIN( CCMode); + return DECLARATION; + } +[\\]ccHidden{w} { /* treat like a space */ + yylval.string.text = " "; + yylval.string.len = 7; + return SPACE; + } +[\\]ccUnchecked{w} { /* trigger a global boolean and treat it like a space */ + unchecked_tag = 1; + yylval.string.text = " "; + yylval.string.len = 10; + return SPACE; + } + + + /* Specialized keywords, partly TeX, partly from the manual style */ + /* -------------------------------------------------------------- */ +[\\]ccStyle{w} { /* CCstyle formatting: change to NestingMode */ + BEGIN( NestingMode); + return CCSTYLE; + } +[\\]cc(Pure)?Var{w} { + if ( creationvariable) { + yylval.string.text = creationvariable; + yylval.string.len = strlen( creationvariable); + } else { + printErrorMessage( VariableUsedError); + yylval.string.text = "Unknown creationvariable"; + yylval.string.len = strlen( yylval.string.text); + } + return STRING; + } +[\\]cc(Pure)?Class(Template)?Name{w} { + if ( global_classname) { + yylval.string.text = global_classname; + yylval.string.len = strlen( global_classname); + } else { + printErrorMessage( ClassnameUsedError); + yylval.string.text = "Unknown classname"; + yylval.string.len = strlen( yylval.string.text); + } + return STRING; + } +[\\]cc(Pure)?TemplateParameters{w} { + if ( global_template_params) { + yylval.string.text = global_template_params; + yylval.string.len = strlen( global_template_params); + } else { + printErrorMessage( ClassnameUsedError); + yylval.string.text = "Unknown template_params"; + yylval.string.len = strlen( yylval.string.text); + } + return STRING; + } +[\\]ccSection{w} { return CCSECTION; } +[\\]ccSubsection{w} { return CCSUBSECTION; } +[\\]ldots{w} { + yylval.string.text = "..."; + yylval.string.len = 3; + return STRING; + } +[\\]RCSdef{w} { + return GOBBLETWOPARAMS; + } +[\\]CC{w} { + yylval.string.text = "C++"; + yylval.string.len = 3; + return STRING; + } +[\\]gcc{w} { + yylval.string.text = "g++"; + yylval.string.len = 3; + return STRING; + } +[\\]nat{w} { + yylval.string.text = "|N"; + yylval.string.len = 2; + return STRING; + } +[\\]real{w} { + yylval.string.text = "|R"; + yylval.string.len = 2; + return STRING; + } +[\\]N{w} { + yylval.string.text = "|N"; + yylval.string.len = 2; + return STRING; + } +[\\]R{w} { + yylval.string.text = "|R"; + yylval.string.len = 2; + return STRING; + } +[\\]Q{w} { + yylval.string.text = "|Q"; + yylval.string.len = 2; + return STRING; + } +[\\]Z{w} { + yylval.string.text = "Z"; + yylval.string.len = 1; + return STRING; + } +[\\]E{w} { + yylval.string.text = "|E"; + yylval.string.len = 2; + return STRING; + } +[\\]leda{w} { + yylval.string.text = "LEDA"; + yylval.string.len = 4; + return STRING; + } +[\\]cgal{w} { + yylval.string.text = "CGAL"; + yylval.string.len = 4; + return STRING; + } +[\\]protocgal{w} { + yylval.string.text = "C++GAL"; + yylval.string.len = 6; + return STRING; + } +[\\]plageo{w} { + yylval.string.text = "PLAGEO"; + yylval.string.len = 6; + return STRING; + } +[\\]ccDefinition{w} { + yylval.string.text = "DEFINITION"; + yylval.string.len = -1; + return STRING; + } +[\\]ccParameters{w} { + yylval.string.text = "PARAMETERS"; + yylval.string.len = -1; + return STRING; + } +[\\]ccConstants{w} { + yylval.string.text = "CONSTANTS"; + yylval.string.len = -1; + return STRING; + } +[\\]ccTypes{w} { + yylval.string.text = "TYPES"; + yylval.string.len = -1; + return STRING; + } +[\\]ccCreation{w} { + yylval.string.text = "CREATION"; + yylval.string.len = -1; + return STRING; + } +[\\]ccOperations{w} { + yylval.string.text = "OPERATIONS"; + yylval.string.len = -1; + return STRING; + } +[\\]ccImplementation{w} { + yylval.string.text = "IMPLEMENTATION"; + yylval.string.len = -1; + return STRING; + } +[\\]ccExample{w} { + yylval.string.text = "EXAMPLE"; + yylval.string.len = -1; + return STRING; + } +[\\]ccHeading{w} { + return HEADING; + } +[\\]ccPrecond { + yylval.string.text = "Precondition:"; + yylval.string.len = -1; + return STRING; + } +[\\]ccPostcond { + yylval.string.text = "Postcondition:"; + yylval.string.len = -1; + return STRING; + } +[\\]ccCommentHeading{w} { + return COMMENTHEADING; + } +[\\]leq { + yylval.string.text = "<="; + yylval.string.len = 2; + return STRING; + } +[\\]geq { + yylval.string.text = ">="; + yylval.string.len = 2; + return STRING; + } +[\\]neq { + yylval.string.text = "!="; + yylval.string.len = 2; + return STRING; + } +[\\]ccSetTwoOfThreeColumns{w} { + return GOBBLETWOPARAMS; + } +[\\]ccSetThreeColumns{w} { + return GOBBLETHREEPARAMS; + } +[\\]ccSetOneOfTwoColumns{w} { + return GOBBLEONEPARAM; + } +[\\]ccSetTwoColumns{w} { + return GOBBLETWOPARAMS; + } +[\\]ccPropagateThreeToTwoColumns{w} { + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; +} +[\\]g?def{w}[\\]{idfier}{w} { + return GOBBLEONEPARAM; +} +[\\](re)?newcommand{w} { + return NEWCOMMAND; +} +[\\]ccTag((Defaults)|(FullDeclarations)){w} { + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; +} +[\\]ccChapterAuthor{w} { + return GOBBLEONEPARAM; +} + + /* HTML support */ + /* ----------------------------------- */ +[\\]ccAnchor{w} { + return GOBBLEONEPARAM; +} +[\\]ccTexHtml{w} { + return GOBBLEAFTERONEPARAM; +} +[\\]begin{w}[\{]ccTexOnly[\}]{w} { + return BEGINTEXONLY; + } +[\\]end{w}[\{]ccTexOnly[\}] { + return ENDTEXONLY; + } +[\\]begin{w}[\{]ccHtmlOnly[\}]{w} { + BEGIN( NestingMode); + return BEGINHTMLONLY; + } +[\\]end{w}[\{]ccHtmlOnly[\}] { + return ENDHTMLONLY; + } + + /* make the $ delimiters for math mode disappear: */ + /* -------------------------------------------------------------- */ +[$] {} +[\\]"&" { + yylval.character = '&'; + return CHAR; + } +[\\]"_" { + yylval.character = '_'; + return CHAR; + } +[\\]"^" { + yylval.character = '^'; + return CHAR; + } +[\\]"#" { + yylval.character = '#'; + return CHAR; + } +[~] { + yylval.string.text = " "; + yylval.string.len = 1; + return SPACE; + } +[\\][\\] { + yylval.string.text = " "; + yylval.string.len = 1; + return SPACE; + } + + + /* Grouping symbols */ + /* ---------------- */ +[\\][\{] { + yylval.character = '{'; + return CHAR; + } +[\\][\}] { + yylval.character = '}'; + return CHAR; + } + +[\{] { + return '{'; + } +[\}] { + return '}'; + } + +{blockintro} { /* A couple of TeX styles like {\tt ... */ + return BLOCKINTRO; + } + +[\[] { + return '['; + } +[\]] { + return ']'; + } + +[\(] { + return '('; + } +[\)] { + return ')'; + } +[\\]"&" { + yylval.character = '&'; + return CHAR; + } +[\\]"_" { + yylval.character = '_'; + return CHAR; + } +[\\]"^" { + yylval.character = '^'; + return CHAR; + } +[\\]"#" { + yylval.character = '#'; + return CHAR; + } + + /* The rest: spaces and single characters */ + /* -------------------------------------- */ +[\\]?{ws} { + if ( *yytext == '\\') { + yylval.string.text = yytext + 1; + yylval.string.len = yyleng - 1; + } else { + yylval.string.text = yytext; + yylval.string.len = yyleng; + } + return SPACE; + } +{ws} { + yylval.string.text = yytext; + yylval.string.len = yyleng; + return SPACE; + } +. { + yylval.character = yytext[0]; + return CHAR; + } +%% + +void init_scanner( FILE* in){ + line_number = 1; + set_CCMode = 0; + set_NestingMode = 0; + set_INITIAL = 0; + unchecked_tag = 0; + yyrestart( in); +} + + + diff --git a/Packages/Manual_tools/src/extract_syntax.y b/Packages/Manual_tools/src/extract_syntax.y new file mode 100644 index 00000000000..73ef2390fb4 --- /dev/null +++ b/Packages/Manual_tools/src/extract_syntax.y @@ -0,0 +1,715 @@ +/************************************************************************** + + extract_syntax.y + ============================================================= + Project : CGAL merger tool for the specification task + Function : grammatical parser for TeX and C++ code mixed files. + System : bison, flex, C++ (g++) + Author : (c) 1995 Lutz Kettner + Revision : $Revision$ + Date : $Date$ + +**************************************************************************/ + +%{ +#include +#include +#include + +/* Declarations from lex.yy */ +/* ======================== */ +extern int set_CCMode; +extern int set_NestingMode; +extern int set_INITIAL; +extern int line_number; + +extern const char* file_name; +extern char* creationvariable; + +extern char *yytext; + +int yylex( void); +void init_scanner( FILE* in); + + +/* Declarations for the parser */ +/* =========================== */ +/* This variable flags for bison that we are in the CCMode */ +int CCMode = 0; + +/* count the brace nesting level for debug purposes */ +int nesting = 0; + +/* Own prototypes */ +int yyerror( char *s); + +/* Datastructures for the parser */ +/* ============================= */ +#include +#include +%} + +%union { + struct { + char* text; /* a (meaningless) chunk of zero terminated text */ + int len; /* its length */ + } string; + char character; /* a (meaningless) character */ + Buffer* pBuffer; /* Buffer for collected strings and characters */ + TextToken* pTextToken; + Text* pText; +} + +/* Elementary data types */ +/* --------------------- */ +%token STRING +%token SPACE +%token CHAR +%token NEWLINE + +/* Keywords to trigger on */ +/* ---------------------- */ +%token BEGINCLASS +%token ENDCLASS +%token BEGINCLASSTEMPLATE +%token ENDCLASSTEMPLATE +%token CREATIONVARIABLE +%token CONSTRUCTOR +%token METHOD +%token FUNCTION +%token FUNCTIONTEMPLATE +%token VARIABLE +%token TYPEDEF +%token NESTEDTYPE +%token ENUM +%token STRUCT +%token GLOBALFUNCTION +%token GLOBALFUNCTIONTEMPLATE +%token GLOBALVARIABLE +%token GLOBALTYPEDEF +%token GLOBALENUM +%token GLOBALSTRUCT +%token DECLARATION +%token BEGINTEXONLY +%token ENDTEXONLY +%token BEGINHTMLONLY +%token ENDHTMLONLY + +/* Special action keywords */ +/* ----------------------- */ +%token CCSTYLE +%token CCSECTION +%token CCSUBSECTION +%token HEADING +%token COMMENTHEADING +%token GOBBLETHREEPARAMS +%token GOBBLETWOPARAMS +%token GOBBLEONEPARAM +%token GOBBLEAFTERONEPARAM +%token BLOCKINTRO +%token NEWCOMMAND + +/* handle LALR(1) restriction */ +/* -------------------------- */ +%token LALRRESTRICTION + +%type string +%type declaration classname template_params +%type cc_stmts cc_stmt cc_stmts_skip_space +%type comment_group comment_sequence +%type nested_token_sequence nested_token +%type compound_comment full_comment_sequence +%type non_empty_comment_sequence + +%type whitespaces optional_whitespaces + +%type comment_token non_empty_token whitespace + + + +%% +/* Grammar: Top Level */ +/* ================== */ + +input: /* empty */ + | input stmt +; + +stmt: string { delete $1;} + | SPACE {} + | NEWLINE + | BEGINCLASS + classname { handleClass( $2->string()); + delete $2;} + decl_sequence + ENDCLASS + { + handleClassEnd(); + free( creationvariable); + creationvariable = NULL; + delete $2; + } + | BEGINCLASSTEMPLATE + classname { handleClassTemplate( $2->string()); + delete $2;} + decl_sequence + ENDCLASSTEMPLATE + { + handleClassTemplateEnd(); + free( creationvariable); + creationvariable = NULL; + delete $2; + } + | CREATIONVARIABLE {} + | CCSTYLE '{' nested_token_sequence '}' { set_INITIAL = 1; } + | HEADING '{' comment_sequence '}' { delete $3; } + | COMMENTHEADING '{' comment_sequence '}' { delete $3; } + | BEGINTEXONLY nested_token_sequence ENDTEXONLY {;} + | BEGINHTMLONLY nested_token_sequence ENDHTMLONLY { + set_INITIAL = 1; } + | gobble_parameters + | GOBBLEAFTERONEPARAM reduced_group reduced_group + | global_tagged_declarator + | group +; + +group: '{' { nesting++; } + input + '}' { nesting--; } + | BLOCKINTRO { nesting++; } + input + '}' { nesting--; } +; + +reduced_group: '{' { nesting++; } + reduced_sequence + '}' { nesting--; } + | BLOCKINTRO { nesting++; } + reduced_sequence + '}' { nesting--; } +; + +reduced_sequence: /* empty */ + | reduced_sequence reduced_statement +; + +reduced_statement: + string { delete $1;} + | SPACE {} + | NEWLINE + | CREATIONVARIABLE {} + | CCSTYLE '{' nested_token_sequence '}' { set_INITIAL = 1; } + | HEADING '{' comment_sequence '}' { delete $3; } + | COMMENTHEADING '{' comment_sequence '}' { delete $3; } + | BEGINTEXONLY nested_token_sequence ENDTEXONLY {;} + | BEGINHTMLONLY nested_token_sequence ENDHTMLONLY { + set_INITIAL = 1; } + | gobble_parameters + | GOBBLEAFTERONEPARAM reduced_group reduced_group + | reduced_group +; + +/* Auxiliary Rules */ +/* =============================== */ +string: STRING { + $$ = new Buffer; + $$->add( $1.text, $1.len); + } + | CHAR { + $$ = new Buffer; + $$->add( $1); + } + | string STRING { + $1->add( $2.text, $2.len); + $$ = $1; + } + | string CHAR { + $1->add( $2); + $$ = $1; + } +; + +non_empty_token: string { $$ = new TextToken( + $1->string(), $1->length()); + delete $1; + } +; + +optional_whitespaces: /* empty */ { $$ = new Text( managed); } + | whitespaces { $$ = $1; } +; + +whitespaces: whitespace { $$ = new Text( * $1, managed); } + | GOBBLEAFTERONEPARAM comment_group comment_group { + $$ = $2; + } + | whitespaces whitespace { + $$ = $1; + $$->append( * $2); + } + | whitespaces GOBBLEAFTERONEPARAM comment_group comment_group { + $$ = $3; + } +; + +whitespace: SPACE { $$ = new TextToken( $1.text, $1.len, true); } + | NEWLINE { $$ = new TextToken( "\n", 1, true); } + | gobble_parameters + { $$ = new TextToken( " ", 1, true); } +; + + + +/* Class Declaration with Comments */ +/* =============================== */ +decl_sequence: comment_sequence { + handleMainComment( * $1); + } + | decl_sequence + tagged_declarator + comment_sequence { + handleMainComment( * $3); + } +; + +tagged_declarator: + global_tagged_declarator + | CONSTRUCTOR declaration comment_group { + handleFunctionDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | METHOD declaration comment_group { + handleMethodDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } +; + +global_tagged_declarator: + FUNCTION declaration comment_group { + handleFunctionDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | FUNCTIONTEMPLATE + template_params + optional_whitespaces + declaration + comment_group { + handleFunctionTemplateDeclaration( + $2->string(), + $4->string()); + delete $2; + delete $3; + delete $4; + handleComment( * $5); + } + | VARIABLE declaration comment_group { + handleDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | TYPEDEF declaration comment_group { + handleDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | NESTEDTYPE declaration comment_group { + handleNestedType( $2->string()); + delete $2; + handleComment( * $3); + } + | ENUM declaration comment_group { + handleDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | STRUCT declaration comment_group { + handleDeclaration( $2->string()); + delete $2; + handleComment( * $3); + } + | GLOBALFUNCTION declaration { + handleFunctionDeclaration( $2->string()); + delete $2; + } + | GLOBALFUNCTIONTEMPLATE + template_params + optional_whitespaces + declaration { + handleFunctionTemplateDeclaration( + $2->string(), + $4->string()); + delete $2; + delete $3; + delete $4; + } + | GLOBALVARIABLE declaration { + handleDeclaration( $2->string()); + delete $2; + } + | GLOBALTYPEDEF declaration { + handleDeclaration( $2->string()); + delete $2; + } + | GLOBALENUM declaration { + handleDeclaration( $2->string()); + delete $2; + } + | GLOBALSTRUCT declaration { + handleDeclaration( $2->string()); + delete $2; + } + | DECLARATION declaration { + handleDeclaration( $2->string()); + delete $2; + } +; + +/* A sequence of words forming a comment */ +/* ===================================== */ +comment_group: optional_whitespaces '{' comment_sequence '}' { + $$ = $3; + delete $1; + } + | optional_whitespaces BLOCKINTRO comment_sequence '}' { + $$ = $3; + delete $1; + } +; + +comment_sequence: optional_whitespaces { $$ = new Text(managed); } + | optional_whitespaces + non_empty_comment_sequence + optional_whitespaces { $$ = $2; } +; + +full_comment_sequence: /* empty */ { $$ = new Text(managed); } + | whitespaces { $$ = $1; } + | optional_whitespaces + non_empty_comment_sequence + optional_whitespaces { + $$ = $1; + $$->append( * $2); + $$->append( * $3); + delete $2; + delete $3; + } +; + +non_empty_comment_sequence: + comment_token { $$ = new Text( * $1, managed); } + | compound_comment { $$ = $1; } + | non_empty_comment_sequence optional_whitespaces comment_token { + $$ = $1; + $$->append( * $2); + $$->append( * $3); + delete $2; + } + | non_empty_comment_sequence + optional_whitespaces + compound_comment { + $$ = $1; + $$->append( * $2); + $$->append( * $3); + delete $2; + delete $3; + } +; + +comment_token: non_empty_token { $$ = $1; } + | comment_token non_empty_token { + $$ = $1; + $$->add( * $2); + delete $2; + } +; + +compound_comment: '{' full_comment_sequence '}' { + $$ = $2; + $$->cons( *new TextToken( "{", 1)); + $$->append( *new TextToken( "}", 1)); + } + | BLOCKINTRO full_comment_sequence '}' { + $$ = $2; + } + | CCSTYLE '{' nested_token_sequence '}' { + $$ = $3; + set_INITIAL = 1; + if ( $$->head().isSpace) // should not + $$->cons( *new TextToken( "`", 1)); + else + $$->head().prepend( "`"); + InListFIter< TextToken> ix( * $$); + ForAll( ix) { + if ( ix.isLast()) + if ( ix->isSpace) + $$->append( *new TextToken( + "'", 1)); + else + ix->add( "'"); + } + } + | BEGINTEXONLY nested_token_sequence ENDTEXONLY { + $$ = $2; + } + | BEGINHTMLONLY nested_token_sequence ENDHTMLONLY { + set_INITIAL = 1; } + | CCSECTION '{' comment_sequence '}' { + $$ = $3; + $$->cons( *new TextToken( " ", 1, true)); + $$->cons( *new TextToken( "SECTION:")); + $$->cons( *new TextToken( "\n", 1, true)); + $$->cons( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( + "====================================" + "====================================")); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + } + | CCSUBSECTION '{' comment_sequence '}' { + $$ = $3; + $$->cons( *new TextToken( " ", 1, true)); + $$->cons( *new TextToken( "Subsection:")); + $$->cons( *new TextToken( "\n", 1, true)); + $$->cons( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( + "------------------------------------" + "------------------------------------")); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + } + | HEADING '{' comment_sequence '}' { + $$ = $3; + } + | COMMENTHEADING '{' comment_sequence '}' { + $$ = $3; + } + | CREATIONVARIABLE { + $$ = new Text( managed); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( + "New creation variable is:")); + $$->append( *new TextToken( " ", 1, true)); + TextToken* t = new TextToken($1.text,$1.len); + t->prepend( "`"); + t->add( "'"); + $$->append( *t); + $$->append( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( "\n", 1, true)); + } +; + +/* Parsing of a C++ expression/statement with nested expressions */ +/* ============================================================= */ +nested_token_sequence: + /* empty */ { + $$ = new Text(managed); + } + | nested_token_sequence nested_token + { + $1->append( * $2); + free( $2); + $$ = $1; + } +; + +nested_token: string { + $$ = new Text(*new TextToken( + $1->string(), + $1->length()), + managed); + delete $1; + } + | SPACE { + $$ = new Text(*new TextToken( + $1.text, + $1.len, + true), + managed); + } + | NEWLINE { + $$ = new Text(*new TextToken( "\n", 1, true), + managed); + } + | '{' nested_token_sequence '}' { + $2->cons( *new TextToken( "{", 1)); + $2->append( *new TextToken( "}", 1)); + $$ = $2; + } + | BLOCKINTRO nested_token_sequence '}' { + $$ = $2; + } + | '[' nested_token_sequence ']' { + $2->cons( *new TextToken( "[", 1)); + $2->append( *new TextToken( "]", 1)); + $$ = $2; + } + | '(' nested_token_sequence ')' { + $2->cons( *new TextToken( "(", 1)); + $2->append( *new TextToken( ")", 1)); + $$ = $2; + } +; + +/* Parsing of a C++ Declaration (function, method ..., not class) */ +/* ============================================================== */ +declaration: '{' { nesting++; + CCMode = 1; + } + cc_stmts_skip_space + '}' { + nesting--; + set_INITIAL = 1; + CCMode = 0; + $$ = $3; + } +; + +classname: '{' { nesting++; + CCMode = 1; + } + cc_stmts_skip_space + '}' { + nesting--; + set_INITIAL = 1; + CCMode = 0; + $$ = $3; + } +; + +template_params: '{' { nesting++; + CCMode = 1; + } + cc_stmts_skip_space + '}' { + nesting--; + set_INITIAL = 1; + CCMode = 0; + $$ = $3; + } +; + +cc_stmts: /* empty */ + { $$ = new Buffer;} + | cc_stmts cc_stmt { + $$ = $1; + $$->add( $2); + delete $2; + } +; + +cc_stmt: string { $$ = $1; + } + | SPACE { $$ = new Buffer; + $$->add( ' '); + } + | NEWLINE { $$ = new Buffer; + $$->add( ' '); + } + | '{' { nesting++; } + cc_stmts + '}' { nesting--; + $$ = $3; + $$->prepend( '{'); + $$->add( '}'); + } +; + +cc_stmts_skip_space: + /* empty */ + { $$ = new Buffer;} + | string + cc_stmts { $$ = $1; + $$->add( $2); + delete $2; + } + | SPACE cc_stmts { $$ = $2;} + | NEWLINE cc_stmts { $$ = $2;} + | '{' { nesting++;} + cc_stmts + '}' { nesting--;} + cc_stmts { + $$ = $3; + $$->prepend( '{'); + $$->add( '}'); + $$->add( $6); + delete $6; + } +; + +/* Parse over non useful parameters */ +/* -------------------------------- */ +gobble_parameters: + GOBBLETHREEPARAMS reduced_group reduced_group reduced_group + | GOBBLETWOPARAMS reduced_group reduced_group + | GOBBLEONEPARAM reduced_group + | NEWCOMMAND reduced_group reduced_group + + + +/* End if Grammar */ +/* ============== */ +%% + +int yyerror( char *s) { + fprintf( stderr, + "error 1 in line %d in %s: in %s-code: nesting %d: %s.\n", + line_number, + file_name, + (CCMode ? "CC" : "TeX"), + nesting, + s); + return 0; +} + +// Functions belonging to the Error messages +// ----------------------------------------- +// See their implementations in parser.y + +const char* errorMessage( ErrorNumber n) { + switch ( n) { + case NoError: + return "NO ERROR"; + case ParseError: + return "parse error"; + case VariableUsedError: + return "The creationvariable was used but not defined"; + case ClassnameUsedError: + return "The classname was used but not defined"; + case TemplateParamExpectedError: + return "A template parameter is missing"; + case MalformedFunctionDeclaration: + return "The function declaration is malformed"; + case MalformedTemplateParamError: + return "The template parameter is malformed (<> nesting ..)"; + case SemicolonMissingError: + return "The declaration does not end in a semicolon"; + } + return "UNKNOWN ERROR MESSAGE NUMBER"; +} + +void printErrorMessage( ErrorNumber n){ + cerr << "error " << n << " in line " << line_number << " in `" + << file_name << "': " << errorMessage( n) << "." << endl; +} + + + + + + + + + + + + + + + + diff --git a/Packages/Manual_tools/src/html_config.h b/Packages/Manual_tools/src/html_config.h index dcf599583f6..d315a43a577 100644 --- a/Packages/Manual_tools/src/html_config.h +++ b/Packages/Manual_tools/src/html_config.h @@ -19,6 +19,26 @@ // There they can be taylored to the specific application, i.e. // extraction or checker. +/* Customization tags for the style */ +/* ================================ */ +extern bool tag_chapter_author; +extern bool tag_replace_prefix; +extern bool tag_replace_include; +extern bool tag_long_param_layout; + +extern bool tag_rm_const_ref_pair; +extern bool tag_rm_eigen_class_name; +extern bool tag_operator_layout; +extern bool tag_rm_trailing_const; + +void tag_defaults(); +void tag_full_declarations(); + + +/* read a file into a buffer */ +/* The name has a trailing '}' */ +Buffer* readFileInBuffer(const char* name); + /* An empty List as empty comment for global declarations */ /* ====================================================== */ extern Text empty_comment; @@ -60,8 +80,16 @@ void handleFunctionTemplateDeclaration( const char* templ, const Text& T = empty_comment); void handleVariableDeclaration( const char* decl, const Text& T = empty_comment); +void handleTypedefDeclaration( const char* decl, + const Text& T = empty_comment); +void handleNestedTypeDeclaration( const char* decl, + const Text& T = empty_comment); void handleEnumDeclaration( const char* decl, const Text& T = empty_comment); +void handleStructDeclaration( const char* decl, + const Text& T = empty_comment); + +void handleNewCommand( char* idfier, char* body); // Error messages and Numbers diff --git a/Packages/Manual_tools/src/html_lex.yy b/Packages/Manual_tools/src/html_lex.yy index 5940441b9c5..4688786d8aa 100644 --- a/Packages/Manual_tools/src/html_lex.yy +++ b/Packages/Manual_tools/src/html_lex.yy @@ -2,7 +2,7 @@ html_lex.yy ============================================================= - Project : CGAL merger tool for the specification task + Project : Tools for the CC manual writing task around cc_manual.sty. Function : lexical scanner for TeX and C++ code mixed files. Taylored for HTML manual generation. System : flex, bison, C++ (g++) @@ -22,6 +22,13 @@ extern "C" int yylex( void ); #include #include +// This flag indicates whether we are in a tabbing or tabular environment. +bool tab_tag = false; + +// This flag is true if we are inside a definition. here, \input and +// \include should not open a file. +bool ignore_input_tag = false; + /* Set this flag to 1 to switch immediately to CCMode. */ int set_CCMode = 0; /* Set this flag to 1 to switch immediately to NestingMode. */ @@ -31,7 +38,7 @@ int set_INITIAL = 0; int set_HTMLMODE = 0; int set_MMODE = 0; -/* Tag to mark the unchecked keyword */ +/* Tag to mark whenever the unchecked keyword occurs. */ int unchecked_tag = 0; /* Count the linenumber for better errormessages. */ @@ -101,6 +108,7 @@ noletter [^a-zA-Z] digit [0-9] CCletter [a-zA-Z_] idfier {letter}+ +texmacro [\\]{idfier} CCidfier ({CCletter}({CCletter}|{digit})*) filename [^ \t\n/\\\{\}\[\]()]+ space [\t ] @@ -115,6 +123,7 @@ floatNumber ({signNumber}\.|{signNumber}\.{number}) expNumber ({floatNumber}|{signNumber}){exp}{signNumber} No ({signNumber}|{floatNumber}|{expNumber}) operator [^a-zA-Z_0-9\n\r\t \\] +measure {signNumber}{letter}{letter} ttblockintro [\{][\\](tt) emblockintro [\{][\\](em) itblockintro [\{][\\]((it)|(sl)) @@ -165,7 +174,17 @@ bfblockintro [\{][\\](bf) /* Handle include files */ /* ------------------------- */ -[\\]((include)|(input))[\{]{w} { BEGIN ( INCLUDEMODE); } +[\\]((include)|(input))[\{]{w} { + if (ignore_input_tag) { + int c = yyinput(); + while( c && c != '}') + c = yyinput(); + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; + } + BEGIN ( INCLUDEMODE); +} {filename} { /* remove trailing characters from the input/include statement */ int c = yyinput(); @@ -294,21 +313,21 @@ bfblockintro [\{][\\](bf) /* Different keywords from the manual style triggering C++ formatting */ /* ------------------------------------------------------------------ */ -[\\]begin{w}[\{]class[\}]{w} { +[\\]begin{w}[\{]ccClass[\}]{w} { BEGIN( CCMode); return BEGINCLASS; } -[\\]end{w}[\{]class[\}] { +[\\]end{w}[\{]ccClass[\}] { return ENDCLASS; } -[\\]begin{w}[\{]classtemplate[\}]{w} { +[\\]begin{w}[\{]ccClassTemplate[\}]{w} { BEGIN( CCMode); return BEGINCLASSTEMPLATE; } -[\\]end{w}[\{]classtemplate[\}] { +[\\]end{w}[\{]ccClassTemplate[\}] { return ENDCLASSTEMPLATE; } -[\\]creationvariable{w}[\{]{w}[^\}]*{w}[\}] { +[\\]ccCreationVariable{w}[\{]{w}[^\}]*{w}[\}] { char *s = yytext + yyleng - 2; while (( *s == ' ') || ( *s == '\t')) s--; @@ -319,7 +338,8 @@ bfblockintro [\{][\\](bf) while (( *r == ' ') || ( *r == '\t')) r++; s[1] = 0; - delete[] creationvariable; + if ( creationvariable) + delete[] creationvariable; if ( formatted_creationvariable) delete[] formatted_creationvariable; creationvariable = newstr( r); @@ -332,78 +352,98 @@ bfblockintro [\{][\\](bf) yylval.string.len = s - r + 1; return CREATIONVARIABLE; } -[\\]constructor/{noletter} { /* constructor declaration: change to CCMode */ +[\\]ccConstructor/{noletter} { /* constructor declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return CONSTRUCTOR; } -[\\]method/{noletter} { /* method declaration: change to CCMode */ +[\\]ccMemberFunction/{noletter} { /* method declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return METHOD; } -[\\]function/{noletter} { /* function declaration: change to CCMode */ +[\\]ccMethod/{noletter} { /* method declaration: change to CCMode */ + skipspaces(); + BEGIN( CCMode); + return METHOD; + } +[\\]ccFunction/{noletter} { /* function declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return FUNCTION; } -[\\]functiontemplate/{noletter} { /* function template declaration: - change to CCMode */ +[\\]ccFunctionTemplate/{noletter} { /* function template declaration: + change to CCMode */ skipspaces(); BEGIN( CCMode); return FUNCTIONTEMPLATE; } -[\\]variable/{noletter} { /* variable declaration: change to CCMode */ +[\\]ccVariable/{noletter} { /* variable declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return VARIABLE; } -[\\]typedef/{noletter} { /* typedef declaration: change to CCMode */ +[\\]ccTypedef/{noletter} { /* typedef declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return TYPEDEF; } -[\\]enum/{noletter} { /* enum declaration: change to CCMode */ +[\\]ccNestedType/{noletter} { /* nested type declaration: change to CCMode */ + skipspaces(); + BEGIN( CCMode); + return NESTEDTYPE; + } +[\\]ccEnum/{noletter} { /* enum declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return ENUM; } -[\\]globalfunction/{noletter} { /* function declaration: change to CCMode */ +[\\]ccStruct/{noletter} { /* struct declaration: change to CCMode */ + skipspaces(); + BEGIN( CCMode); + return STRUCT; + } +[\\]ccGlobalFunction/{noletter} { /* function declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return GLOBALFUNCTION; } -[\\]globalfunctiontemplate/{noletter} { /* function template declaration: +[\\]ccGlobalFunctionTemplate/{noletter} { /* function template declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return GLOBALFUNCTIONTEMPLATE; } -[\\]globalvariable/{noletter} { /* variable declaration: change to CCMode */ +[\\]ccGlobalVariable/{noletter} { /* variable declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return GLOBALVARIABLE; } -[\\]globaltypedef/{noletter} { /* typedef declaration: change to CCMode */ +[\\]ccGlobalTypedef/{noletter} { /* typedef declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return GLOBALTYPEDEF; } -[\\]globalenum/{noletter} { /* enum declaration: change to CCMode */ +[\\]ccGlobalEnum/{noletter} { /* enum declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return GLOBALENUM; } -[\\]declaration/{noletter} { /* general declaration: change to CCMode */ +[\\]ccGlobalStruct/{noletter} { /* struct declaration: change to CCMode */ + skipspaces(); + BEGIN( CCMode); + return GLOBALSTRUCT; + } +[\\]ccDeclaration/{noletter} { /* general declaration: change to CCMode */ skipspaces(); BEGIN( CCMode); return DECLARATION; } -[\\]hidden/{noletter} { +[\\]ccHidden/{noletter} { skipspaces(); return HIDDEN; } -[\\]unchecked/{noletter} { +[\\]ccUnchecked/{noletter} { /* trigger a global boolean and treat it like a space */ skipspaces(); unchecked_tag = 1; @@ -422,21 +462,26 @@ bfblockintro [\{][\\](bf) BEGIN( INITIAL); return CPROGEND; } +[\\]"cprogfile{"[^\}]*"}" { + yylval.string.text = yytext + 11; + yylval.string.len = yyleng - 12; + return CPROGFILE; + } -[\\]"begin{HtmlOnly}" { +[\\]"begin{ccHtmlOnly}" { BEGIN( HTMLGROUPMode); return HTMLBEGIN; } -[\\]"end{HtmlOnly}" { +[\\]"end{ccHtmlOnly}" { BEGIN( INITIAL); return HTMLEND; } -[\\]"begin{TexOnly}" { +[\\]"begin{ccTexOnly}" { BEGIN( TEXONLYMODE); return TEXONLYBEGIN; } -[\\]"end{TexOnly}" { +[\\]"end{ccTexOnly}" { BEGIN( INITIAL); return TEXONLYEND; } @@ -444,10 +489,10 @@ bfblockintro [\{][\\](bf) yylval.character = yytext[0]; return CHAR; } -[\\]LatexHtml{w}[\{] { +[\\]ccTexHtml{w}[\{] { return LATEXHTML; } -[\\]Anchor{w}[\{] { +[\\]ccAnchor{w}[\{] { /* The first parameter is the URL, the second is the */ /* message that will be highlighted */ BEGIN( HTMLMODE); @@ -464,12 +509,12 @@ bfblockintro [\{][\\](bf) /* Specialized keywords from the manual style */ /* -------------------------------------------------------------- */ -[\\]CCstyle/{noletter} { /* CCstyle formatting: change to NestingMode */ +[\\]ccStyle/{noletter} { /* CCstyle formatting: change to NestingMode */ skipspaces(); BEGIN( NestingMode); return CCSTYLE; } -[\\]var/{noletter} { +[\\]ccVar/{noletter} { skipspaces(); if ( creationvariable) { yylval.string.text = formatted_creationvariable; @@ -481,7 +526,7 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]purevar/{noletter} { +[\\]ccPureVar/{noletter} { skipspaces(); if ( creationvariable) { yylval.string.text = creationvariable; @@ -493,7 +538,7 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]classname/{noletter} { +[\\]ccClassName/{noletter} { skipspaces(); if ( formatted_class_name) { yylval.string.text = formatted_class_name; @@ -505,7 +550,7 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]pureclassname/{noletter} { +[\\]ccPureClassName/{noletter} { skipspaces(); if ( class_name) { yylval.string.text = class_name; @@ -517,7 +562,7 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]classtemplatename/{noletter} { +[\\]ccClassTemplateName/{noletter} { skipspaces(); if ( formatted_template_class_name) { yylval.string.text = formatted_template_class_name; @@ -529,7 +574,7 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]puretemplatename/{noletter} { +[\\]ccPureClassTemplateName/{noletter} { skipspaces(); if ( template_class_name) { yylval.string.text = template_class_name; @@ -541,17 +586,21 @@ bfblockintro [\{][\\](bf) } return STRING; } -[\\]CCsection/{noletter} { +[\\]ccSection/{noletter} { skipspaces(); return CCSECTION; } +[\\]ccSubsection/{noletter} { + skipspaces(); + return CCSUBSECTION; + } [\\]CC/{noletter} { skipspaces(); yylval.string.text = "C++"; yylval.string.len = 3; return STRING; } -[\\]gg/{noletter} { +[\\]gcc/{noletter} { skipspaces(); yylval.string.text = "g++"; yylval.string.len = 3; @@ -581,6 +630,12 @@ bfblockintro [\{][\\](bf) yylval.string.len = -1; return STRING; } +[\\]Q/{noletter} { + skipspaces(); + yylval.string.text = "Q"; + yylval.string.len = -1; + return STRING; + } [\\]Z/{noletter} { skipspaces(); yylval.string.text = "Z"; @@ -621,50 +676,145 @@ bfblockintro [\{][\\](bf) yylval.string.len = -1; return STRING; } -[\\]definition/{noletter} { +[\\]ccDefinition/{noletter} { skipspaces(); yylval.string.text = "

          Definition

          "; yylval.string.len = -1; return STRING; } -[\\]creation/{noletter} { +[\\]ccParameters/{noletter} { + skipspaces(); + yylval.string.text = "

          Parameters

          "; + yylval.string.len = -1; + return STRING; + } +[\\]ccConstants/{noletter} { + skipspaces(); + yylval.string.text = "

          Constants

          "; + yylval.string.len = -1; + return STRING; + } +[\\]ccTypes/{noletter} { + skipspaces(); + yylval.string.text = "

          Types

          "; + yylval.string.len = -1; + return STRING; + } +[\\]ccCreation/{noletter} { skipspaces(); yylval.string.text = "

          Creation

          "; yylval.string.len = -1; return STRING; } -[\\]operations/{noletter} { +[\\]ccOperations/{noletter} { skipspaces(); yylval.string.text = "

          Operations

          "; yylval.string.len = -1; return STRING; } -[\\]implementation/{noletter} { +[\\]ccImplementation/{noletter} { skipspaces(); yylval.string.text = "

          Implementation

          "; yylval.string.len = -1; return STRING; } -[\\]example/{noletter} { +[\\]ccExample/{noletter} { skipspaces(); yylval.string.text = "

          Example

          "; yylval.string.len = -1; return STRING; } -[\\]precond/{noletter} { +[\\]ccHeading/{noletter} { + return HEADING; + } +[\\]ccPrecond/{noletter} { skipspaces(); yylval.string.text = "
          Precondition: "; yylval.string.len = -1; return STRING; } -[\\]threecolumns/{noletter} { +[\\]ccPostcond/{noletter} { + skipspaces(); + yylval.string.text ="
          Postcondition: "; + yylval.string.len = -1; + return STRING; + } +[\\]ccCommentHeading/{noletter} { + return COMMENTHEADING; + } +[\\]ccSetTwoOfThreeColumns/{noletter} { skipspaces(); return GOBBLETWOPARAMS; } -[\\]constructorcolumn/{noletter} { +[\\]ccSetThreeColumns/{noletter} { + skipspaces(); + return GOBBLETHREEPARAMS; + } +[\\]ccSetOneOfTwoColumns/{noletter} { skipspaces(); return GOBBLEONEPARAM; } +[\\]ccSetTwoColumns/{noletter} { + skipspaces(); + return GOBBLETWOPARAMS; + } +[\\]ccPropagateThreeToTwoColumns/{noletter} { + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; +} +[\\]g?def{w}[\\]{idfier}[^\{]* { + ignore_input_tag = true; + BEGIN( NestingMode); + return GOBBLEONEPARAM; +} +[\\](re)?newcommand{w} { + ignore_input_tag = true; + BEGIN( NestingMode); + return NEWCOMMAND; +} +[\\]ccTagDefaults{w} { + tag_defaults(); + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; +} +[\\]ccTagFullDeclarations{w} { + tag_full_declarations(); + yylval.string.text = " "; + yylval.string.len = 0; + return SPACE; +} +[\\]ccChapterAuthor{w} { + return CHAPTERAUTHOR; +} + + + + /* Try tabular and tabbing environments */ + /* -------------------------------------------------------------- */ + +[\\]begin[\{]((tabbing)|(eqnarray"*"?))[\}] | +[\\]begin[\{]((tabular)|(array))[\}][\{][^\}]*[\}] { + tab_tag = true; + yylval.string.text = + "
          "; + yylval.string.len = -1; + return STRING; + } +[\\]end[\{]((tabbing)|(tabular)|(eqnarray"*"?)|(array))[\}] { + tab_tag = false; + yylval.string.text = "
          "; + yylval.string.len = -1; + return STRING; + } +[\\][=>] { + yylval.string.text = + ""; + yylval.string.len = -1; + return STRING; + } + /* keywords from TeX/LaTeX that have an easy HTML counterpart */ /* -------------------------------------------------------------- */ @@ -770,7 +920,7 @@ bfblockintro [\{][\\](bf) yylval.string.len = 5; return STRING; } -[\\][_^#$] { +[\\][_^#$~%] { yylval.character = yytext[1]; return CHAR; } @@ -782,6 +932,12 @@ bfblockintro [\{][\\](bf) } [\\][\\] { skipoptionalparam(); + if ( tab_tag) { + yylval.string.text = + ""; + yylval.string.len = -1; + return STRING; + } yylval.string.text = " "; yylval.string.len = 1; return SPACE; @@ -895,12 +1051,13 @@ bfblockintro [\{][\\](bf) [\\]((smallskip)|(protect)|(sloppy))/{noletter} {} [\\]((maketitle)|(tableofcontents))/{noletter} {} [\\]((begin)|(end))[\{]document[\}] {} +[\\]((tiny)|(scriptsize)|(footnotesize)|(small)|(normalsize)|(large)|(Large))/{noletter} + [\\]newsavebox{w}[\{] | [\\]usebox{w}[\{] | [\\][*]?hspace{w}[\{] | -[\\][*]?vspace{w}[\{] | -[\\]g?def{w}[\\]{letter}+[^\{]*[\{] { +[\\][*]?vspace{w}[\{] { /* CCstyle formatting: change to NestingMode */ BEGIN( NestingMode); return IGNOREBLOCK; @@ -911,13 +1068,8 @@ bfblockintro [\{][\\](bf) BEGIN( NestingMode); return IGNOREBLOCK; } -[\\]((textwidth)|(textheight)|(topmargin)|(evensidemargin)|(oddsidemargin)|(headsep)|(parindent)|(parskip)){w}[-+0-9.]+{w}.. {} +[\\]((textwidth)|(textheight)|(topmargin)|(evensidemargin)|(oddsidemargin)|(headsep)|(parindent)|(parskip)|(beforecprogskip)|(aftercprogskip)){w}(({texmacro})|({measure})) {} -[\\]newcommand{w}[\{][^\}]*[\}]([\[][^\]]*[\]])[\{] { - /* CCstyle formatting: change to NestingMode */ - BEGIN( NestingMode); - return IGNOREBLOCK; - } [\\]((savebox)|(setlength)|(setcounter)){w}[\{] { /* CCstyle formatting: change to NestingMode */ BEGIN( NestingMode); @@ -961,19 +1113,19 @@ bfblockintro [\{][\\](bf) /* Grouping symbols */ /* ---------------- */ -[\\][\{] { +[\\][\{] { yylval.character = '{'; return CHAR; } -[\\][\}] { +[\\][\}] { yylval.character = '}'; return CHAR; } -[\\]left. { +[\\]left. { yylval.character = yytext[5]; return CHAR; } -[\\]right. { +[\\]right. { yylval.character = yytext[6]; return CHAR; } @@ -1027,6 +1179,19 @@ bfblockintro [\{][\\](bf) yylval.character = yytext[0]; return CHAR; } +[\\][/] {} +[&] { + if ( tab_tag) { + yylval.string.text = + ""; + yylval.string.len = -1; + return STRING; + } + yylval.string.text = html_multi_character(yytext[0]); + yylval.string.len = strlen( yylval.string.text); + return STRING; + } + . { yylval.character = yytext[0]; if ( is_html_multi_character( yylval.character)) { diff --git a/Packages/Manual_tools/src/html_syntax.y b/Packages/Manual_tools/src/html_syntax.y index 7abc5ba8fcd..1ab1ddf10b4 100644 --- a/Packages/Manual_tools/src/html_syntax.y +++ b/Packages/Manual_tools/src/html_syntax.y @@ -2,7 +2,7 @@ html_syntax.y ============================================================= - Project : CGAL merger tool for the specification task + Project : Tools for the CC manual writing task around cc_manual.sty. Function : grammatical parser for TeX and C++ code mixed files. Taylored for HTML manual generation. System : bison, flex, C++ (g++) @@ -20,6 +20,7 @@ /* Declarations from lex.yy */ /* ======================== */ + extern int set_CCMode; extern int set_NestingMode; extern int set_INITIAL; @@ -57,6 +58,10 @@ char* text_block_to_string( const Text& T); /* ==================== */ extern bool first_bibitem; +// This flag is true if we are inside a definition. here, \input and +// \include should not open a file. +extern bool ignore_input_tag; + /* Own prototypes */ /* ============== */ int yyerror( char *s); @@ -104,18 +109,22 @@ Text* blockintroProcessing( const char* text, int len, Text* t); %token FUNCTIONTEMPLATE %token VARIABLE %token TYPEDEF +%token NESTEDTYPE %token ENUM +%token STRUCT %token GLOBALFUNCTION %token GLOBALFUNCTIONTEMPLATE %token GLOBALVARIABLE %token GLOBALTYPEDEF %token GLOBALENUM +%token GLOBALSTRUCT %token DECLARATION /* Special action keywords */ /* ----------------------- */ %token CPROGBEGIN %token CPROGEND +%token CPROGFILE %token HIDDEN %token TEXONLYBEGIN @@ -127,10 +136,16 @@ Text* blockintroProcessing( const char* text, int len, Text* t); %token CCSTYLE %token CCSECTION +%token CCSUBSECTION +%token HEADING +%token COMMENTHEADING +%token CHAPTERAUTHOR %token GOBBLEONEPARAM %token GOBBLETWOPARAMS +%token GOBBLETHREEPARAMS %token IGNOREBLOCK %token IGNORETWOBLOCKS +%token NEWCOMMAND %token TTBLOCKINTRO %token EMBLOCKINTRO %token ITBLOCKINTRO @@ -176,17 +191,24 @@ input: /* empty */ | input stmt ; -stmt: string { handleBuffer( * $1); delete $1;} +stmt: string { handleBuffer( * $1); + delete $1; + } | whitespaces { handleText( * $1, true); delete $1; } - | verbatim_style { handleBuffer( * $1); delete $1;} + | verbatim_style { handleBuffer( * $1); + delete $1; + } | CHAPTER comment_sequence - '}' { handleChapter( * $2); delete $2;} + '}' { handleChapter( * $2); + delete $2; + } | BEGINCLASS classname { handleClass( $2->string()); - delete $2;} + delete $2; + } decl_sequence ENDCLASS { @@ -196,7 +218,8 @@ stmt: string { handleBuffer( * $1); delete $1;} } | BEGINCLASSTEMPLATE classname { handleClassTemplate( $2->string()); - delete $2;} + delete $2; + } decl_sequence ENDCLASSTEMPLATE { @@ -212,6 +235,26 @@ stmt: string { handleBuffer( * $1); delete $1;} handleString( ""); delete $3; } + | HEADING '{' comment_sequence '}' { + handleString( "

          "); + handleText( * $3); + handleString( "

          "); + delete $3; + } + | COMMENTHEADING '{' comment_sequence '}' { + handleString( "
          "); + handleText( * $3); + handleString( ""); + delete $3; + } + | CHAPTERAUTHOR '{' comment_sequence '}' { + if ( tag_chapter_author) { + handleString( "

          "); + handleText( * $3); + handleString( "

          "); + } + delete $3; + } | global_tagged_declarator | group ; @@ -329,14 +372,47 @@ whitespaces: whitespace { $$ = new Text( * $1, managed); } whitespace: SPACE { $$ = new TextToken( $1.text, $1.len, true); } | NEWLINE { $$ = new TextToken( "\n", 1, true); } + | GOBBLETHREEPARAMS comment_group comment_group comment_group + { $$ = new TextToken( " ", 1, true); + delete $2; + delete $3; + delete $4; + } | GOBBLETWOPARAMS comment_group comment_group { $$ = new TextToken( " ", 1, true); delete $2; delete $3; } | GOBBLEONEPARAM comment_group - { $$ = new TextToken( " ", 1, true); + { $$ = new TextToken( " ", 1, true); delete $2; + if ( ignore_input_tag) { + ignore_input_tag = false; + set_INITIAL = 1; + } + } + | NEWCOMMAND comment_group comment_group + { $$ = new TextToken( " ", 1, true); + handleNewCommand( text_block_to_string(*$2), + text_block_to_string(*$3)); + delete $2; + delete $3; + if ( ignore_input_tag) { + ignore_input_tag = false; + set_INITIAL = 1; + } + } + | NEWCOMMAND comment_group + '[' comment_sequence ']' + comment_group + { $$ = new TextToken( " ", 1, true); + delete $2; + delete $4; + delete $6; + if ( ignore_input_tag) { + ignore_input_tag = false; + set_INITIAL = 1; + } } | IGNOREBLOCK comment_sequence '}' { $$ = new TextToken( " ", 1, true); @@ -389,7 +465,9 @@ tagged_declarator: global_tagged_declarator: SECTION comment_sequence - '}' { handleSection( * $2); delete $2;} + '}' { handleSection( * $2); + ; //delete $2; + } | SUBSECTION comment_sequence '}' { @@ -408,7 +486,9 @@ global_tagged_declarator: } | BEGINBIBLIO comment_sequence - ENDBIBLIO { handleBiblio( * $2); delete $2;} + ENDBIBLIO { handleBiblio( * $2); + delete $2; + } | FUNCTION declaration comment_group { handleFunctionDeclaration( $2->string(), * $3); @@ -436,7 +516,14 @@ global_tagged_declarator: delete $3; } | TYPEDEF declaration comment_group { - handleVariableDeclaration( $2->string(), * $3); + handleTypedefDeclaration( + $2->string(), * $3); + delete $2; + delete $3; + } + | NESTEDTYPE declaration comment_group { + handleNestedTypeDeclaration( + $2->string(), * $3); delete $2; delete $3; } @@ -445,6 +532,11 @@ global_tagged_declarator: delete $2; delete $3; } + | STRUCT declaration comment_group { + handleStructDeclaration( $2->string(), * $3); + delete $2; + delete $3; + } | GLOBALFUNCTION declaration { handleFunctionDeclaration( $2->string()); delete $2; @@ -472,6 +564,10 @@ global_tagged_declarator: handleEnumDeclaration( $2->string()); delete $2; } + | GLOBALSTRUCT declaration { + handleEnumDeclaration( $2->string()); + delete $2; + } | DECLARATION declaration { handleDeclaration( $2->string()); delete $2; @@ -492,7 +588,9 @@ hidden_keys: CONSTRUCTOR | FUNCTION | VARIABLE | TYPEDEF + | NESTEDTYPE | ENUM + | STRUCT ; /* A sequence of words forming a comment */ @@ -604,6 +702,41 @@ compound_comment: '{' full_comment_sequence '}' { $$->append( *new TextToken( ")")); $$->append( *new TextToken( "\n", 1, true)); } + | CCSUBSECTION '{' comment_sequence '}' { + $$ = $3; + $$->cons( *new TextToken( " ", 1, true)); + $$->cons( *new TextToken( "

          ")); + $$->cons( *new TextToken( "\n", 1, true)); + $$->append( *new TextToken( " (")); + $$->append( *new TextToken( + formatted_class_name)); + $$->append( *new TextToken( ")

          ")); + $$->append( *new TextToken( "\n", 1, true)); + } + | HEADING '{' comment_sequence '}' { + $$ = $3; + $$->cons( *new TextToken( " ", 1, true)); + $$->cons( *new TextToken( "

          ")); + $$->append( *new TextToken( "

          ")); + $$->append( *new TextToken( "\n", 1, true)); + } + | COMMENTHEADING '{' comment_sequence '}' { + $$ = $3; + $$->cons( *new TextToken( " ", 1, true)); + $$->cons( *new TextToken( "
          ")); + $$->append( *new TextToken( "")); + $$->append( *new TextToken( "\n", 1, true)); + } + | CHAPTERAUTHOR comment_group { + if ( tag_chapter_author) { + $$ = $2; + $$->cons( *new TextToken( "

          ")); + $$->append( *new TextToken( "

          ")); + } else { + $$ = new Text( managed); + delete $2; + } + } | CREATIONVARIABLE { $$ = new Text( managed);} ; @@ -750,6 +883,11 @@ verbatim_style: CPROGBEGIN string_with_nl_or_mt CPROGEND { $$->prepend( "

          " , 5);
           				  $$->add(     "
          ", 6); } + | CPROGFILE { + $$ = readFileInBuffer($1.text); + $$->prepend( "
          " , 5);
          +				  $$->add(     "
          ", 6); + } | HTMLBEGIN string_with_nl_or_mt HTMLEND { $$ = $2; } @@ -774,8 +912,8 @@ verbatim_style: CPROGBEGIN string_with_nl_or_mt CPROGEND { char* s = text_block_to_string( * $4); $$->add( s); $$->add( ""); - delete s; - delete $4; + delete[] s; + delete $4; } ; texonly_style: TEXONLYBEGIN string_with_nl TEXONLYEND { @@ -918,3 +1056,4 @@ Text* blockintroProcessing( const char* text, int len, Text* t) { } return t; } +