From 817a506dd9f4992af539609c8a7d90a5c582c4cc Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 3 Feb 2008 17:21:27 +0200 Subject: [PATCH] Added options to make Robodoc more customizable. Added --module_index_menu to generate module index menu on a module page and to generate header index menu on a header page. Added --document_header option to specify file where to read document header. Added --document_footer option to specify file where to read document footer. Made other minor modifications mainly to the HTML generator. --- Source/generator.c | 87 +++++++++++++-- Source/globals.c | 30 +++++- Source/globals.h | 4 +- Source/html_generator.c | 229 ++++++++++++++++++++++++++++++++++------ Source/html_generator.h | 17 +++ Source/links.c | 41 ++++--- Source/optioncheck.c | 10 +- Source/robodoc.c | 96 ++++++++++++++--- Source/robodoc.h | 5 +- 9 files changed, 432 insertions(+), 87 deletions(-) diff --git a/Source/generator.c b/Source/generator.c index 491aa22..1d7dd41 100644 --- a/Source/generator.c +++ b/Source/generator.c @@ -999,6 +999,41 @@ void Generate_IndexMenu( } +void Generate_Header_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Part *owner, + struct RB_Document *document ) +{ + switch ( output_mode ) + { + case HTML: + RB_HTML_Generate_Header_IndexMenu( dest_doc, filename, + document, owner, NULL ); + break; + default: + break; + } + +} + +void Generate_Module_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Document *document ) +{ + switch ( output_mode ) + { + case HTML: + RB_HTML_Generate_Module_IndexMenu( dest_doc, filename, + document, NULL ); + break; + default: + break; + } + +} + void Generate_Begin_Extra( FILE *dest_doc ) { @@ -1043,7 +1078,7 @@ void RB_Generate_Nav_Bar( case XMLDOCBOOK: break; case HTML: - if ( course_of_action.do_one_file_per_header ) + if ( course_of_action.do_one_file_per_header ) { /* Nothing */ } @@ -1145,7 +1180,7 @@ void RB_Name_Headers( /****f* Generator/RB_Sort_Items * FUNCTION * Sort the items in all the headers according to the order - * specified in the 'item order' block in the robodoc.rc + * specified in the 'item order' block in the robodoc.rc * file. * SYNOPSIS */ @@ -1390,21 +1425,33 @@ void RB_Generate_MultiDoc( if ( i_part->headers == 0 ) continue; - if ( output_mode != TROFF ) { document_file = RB_Open_Documentation( i_part ); RB_Generate_Doc_Start( document, - document_file, srcname, srcname, 1, + document_file, srcname, + i_part->filename->name, 1, docname, document->charset ); Generate_Begin_Navigation( document_file ); if ( document->actions.do_one_file_per_header ) { - RB_HTML_Generate_Nav_Bar_One_File_Per_Header( document, - document_file, - i_part-> - headers ); + if ( document->actions.do_module_index_menu ) + { + if ( i_part->headers[0].htype->typeCharacter == 'h' ) + Generate_Module_IndexMenu( document_file, docname, + document ); + else + Generate_Header_IndexMenu( document_file, docname, + i_part, document ); + } + else + { + RB_HTML_Generate_Nav_Bar_One_File_Per_Header( document, + document_file, + i_part-> + headers ); + } } else { @@ -1421,6 +1468,17 @@ void RB_Generate_MultiDoc( i_part, docname ); } RB_Generate_Part( document_file, document, i_part ); + + if ( document->actions.do_header_toc && output_mode == HTML ) + { + if ( document->actions.do_one_file_per_header && + i_part->headers[0].htype->typeCharacter == 'h' ) + RB_HTML_Generate_TOC_Entries( document_file, + document->headers, + document->no_headers, + i_part, docname ); + } + Generate_End_Content( document_file ); RB_Generate_Doc_End( document_file, docname, srcname ); @@ -1518,6 +1576,16 @@ void RB_Generate_SingleDoc( } } + if ( document->actions.do_header_toc && output_mode == HTML ) + { + if ( i_part->headers[0].htype->typeCharacter == 'h' ) + RB_HTML_Generate_TOC_Entries( document_file, + document->headers, + document->no_headers, + i_part, + document->parts->filename->name ); + } + RB_Generate_Doc_End( document_file, "singledoc", document->srcroot->name ); fclose( document_file ); @@ -1721,7 +1789,6 @@ void RB_Generate_Part( RB_TROFF_Set_Param( document->compress, document->section ); } - for ( i_header = part->headers; i_header; i_header = i_header->next ) { RB_Say( "generating documentation for header \"%s\"\n", SAY_INFO, @@ -2487,7 +2554,7 @@ static void Generate_Item_Line( { if ( utf8_isspace( c ) ) { - /* We found the end of the string, so we go + /* We found the end of the string, so we go * back to the space skipping state */ state = SKIP_SPACE; diff --git a/Source/globals.c b/Source/globals.c index 9edb766..53ed7a3 100644 --- a/Source/globals.c +++ b/Source/globals.c @@ -49,7 +49,7 @@ char *current_file = 0; /****v* Globals/document_title * NAME - * documentat_title -- title for the documentation. + * document_title -- title for the documentation. * PURPOSE * Used as the title for master index files or for latex documentation. * SOURCE @@ -60,6 +60,32 @@ char *document_title = NULL; /******/ +/****v* Globals/document_header + * NAME + * document_header -- Header for the documentation. + * PURPOSE + * Used as the header of generated files + * SOURCE + */ + +char *document_header = NULL; + +/******/ + + +/****v* Globals/document_footer + * NAME + * document_footer -- Footer for the documentation. + * PURPOSE + * Used as the footer of generated files + * SOURCE + */ + +char *document_footer = NULL; + +/******/ + + /****v* Globals/output_mode [2.0] * NAME * output_mode -- the mode of output @@ -152,7 +178,7 @@ int line_number = 0; /*******/ /* - * Global variables + * Global variables */ /* TODO Document these. */ diff --git a/Source/globals.h b/Source/globals.h index c86e17b..b5de74a 100644 --- a/Source/globals.h +++ b/Source/globals.h @@ -57,8 +57,10 @@ along with this program. If not, see . // Default document title #define DEFAULT_DOCTITILE "API Reference" -// Document title +// Document title, header and footer extern char *document_title; +extern char *document_header; +extern char *document_footer; extern char *source_file; /* DCD */ diff --git a/Source/html_generator.c b/Source/html_generator.c index 145d5e6..e296f21 100644 --- a/Source/html_generator.c +++ b/Source/html_generator.c @@ -685,6 +685,48 @@ void RB_HTML_Generate_TOC_Section( /*******/ +void RB_HTML_Generate_TOC_Entries( + FILE *dest_doc, + struct RB_header **headers, + int count, + struct RB_Part *owner, + char *dest_name ) +{ + struct RB_header *header; + char *object_name, *label_name, *file_name; + int i, j; + +// fprintf( dest_doc, "

Table of Contents

\n" ); + fprintf( dest_doc, "

TABLE OF CONTENTS

\n" ); + fprintf( dest_doc, "\n" ); +} + + void RB_HTML_Generate_TOC_2( FILE *dest_doc, struct RB_header **headers, @@ -939,7 +981,7 @@ void RB_HTML_Generate_Doc_Start( /* * INPUTS * o dest_doc -- the output file. - * o src_name -- The file or directoryname from which + * o src_name -- The file or directoryname from which * this document is generated. * o name -- The title for this document * o dest_name -- the name of the output file. @@ -1024,16 +1066,21 @@ void RB_HTML_Generate_Doc_Start( // HTML_Generate_Div( dest_doc, "container" ); - /* Generate document title if available (Thuffir) */ - HTML_Generate_Div( dest_doc, "logo" ); - fprintf( dest_doc, "" ); - if ( document_title ) - RB_HTML_Generate_String( dest_doc, document_title ); - fprintf( dest_doc, "\n" ); - HTML_Generate_Div_End( dest_doc, "logo" ); - - - + /* Use user specified header if present */ + if ( document_header ) + { + fprintf ( dest_doc, document_header ); + } + else + { + /* Generate document title if available (Thuffir) */ + HTML_Generate_Div( dest_doc, "logo" ); + fprintf( dest_doc, "" ); + if ( document_title ) + RB_HTML_Generate_String( dest_doc, document_title ); + fprintf( dest_doc, "\n" ); + HTML_Generate_Div_End( dest_doc, "logo" ); + } } /******/ @@ -1056,26 +1103,35 @@ void RB_HTML_Generate_Doc_End( USE( name ); - - HTML_Generate_Div( dest_doc, "footer" ); - /* TODO This should be done with - * RB_Generate_Label() - */ - if ( course_of_action.do_nogenwith ) + /* Use user specified footer if present */ + if ( document_footer ) { - fprintf( dest_doc, "

Generated from %s on ", src_name ); - RB_TimeStamp( dest_doc ); - fprintf( dest_doc, "

\n" ); + fprintf ( dest_doc, document_footer ); } else { - fprintf( dest_doc, - "

Generated from %s with ROBODoc V%s on ", - src_name, VERSION ); - RB_TimeStamp( dest_doc ); - fprintf( dest_doc, "

\n" ); + HTML_Generate_Div( dest_doc, "footer" ); + + /* TODO This should be done with + * RB_Generate_Label() + */ + if ( course_of_action.do_nogenwith ) + { + fprintf( dest_doc, "

Generated from %s on ", src_name ); + RB_TimeStamp( dest_doc ); + fprintf( dest_doc, "

\n" ); + } + else + { + fprintf( dest_doc, + "

Generated from %s with ROBODoc V%s on ", + src_name, VERSION ); + RB_TimeStamp( dest_doc ); + fprintf( dest_doc, "

\n" ); + } + + HTML_Generate_Div_End( dest_doc, "footer" ); } - HTML_Generate_Div_End( dest_doc, "footer" ); // HTML_Generate_Div_End( dest_doc, "container" ); @@ -1206,7 +1262,7 @@ void RB_HTML_Generate_Header_Start( if ( cur_header->name && cur_header->function_name ) { - fprintf( dest_doc, "
\n" ); +/* fprintf( dest_doc, "
\n" ); */ RB_HTML_Generate_Label( dest_doc, cur_header->name ); fprintf( dest_doc, "

", cur_header->unique_name ); @@ -1327,6 +1383,110 @@ void RB_HTML_Generate_IndexMenu( } } +/****f* HTML_Generator/RB_HTML_Generate_Header_IndexMenu + * FUNCTION + * Generates a menu to jump to the header's entries. The menu is + * generated for each entry file. + * SYNOPSIS + */ +void RB_HTML_Generate_Header_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Document *document, + struct RB_Part *owner, + struct RB_HeaderType *cur_type ) + /* TODO Use cur_type */ +/* + * INPUTS + * * dest_doc -- the output file. + * * filename -- the name of the output file + * * document -- the gathered documention. + * * cur_headertype -- the header type that is to be highlighted. + ****** + */ +{ + struct RB_header *header; + char *object_name, *label_name, *file_name; + int i, j; + + for ( i = document->no_headers - 1; i >= 0; i-- ) + { + header = document->headers[i]; + + if ( !strcmp( owner->filename->name, header->owner->filename->name ) && + ( header->htype->typeCharacter == 'h' || + Find_Link( header->function_name, + &object_name, &label_name, + &file_name ) ) ) + { + for ( j = 0; j < header->no_names; j++ ) + { + if ( header->htype->typeCharacter == 'h' ) + { + RB_HTML_Generate_Link( dest_doc, + filename, + header->owner->filename->docname, + NULL, + header->function_name, + "menuitem" ); + fprintf( dest_doc, "\n" ); + } + else + { + RB_HTML_Generate_Link( dest_doc, + filename, + file_name, + "", + object_name, + "menuitem" ); + fprintf( dest_doc, "\n" ); + } + } + } + } +} + +/****f* HTML_Generator/RB_HTML_Generate_Module_IndexMenu + * FUNCTION + * Generates a menu to jump to the different modules. The menu is + * generated for each header file. + * SYNOPSIS + */ +void RB_HTML_Generate_Module_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Document *document, + struct RB_HeaderType *cur_type ) + /* TODO Use cur_type */ +/* + * INPUTS + * * dest_doc -- the output file. + * * filename -- the name of the output file + * * document -- the gathered documention. + * * cur_headertype -- the header type that is to be highlighted. + ****** + */ +{ + struct RB_Part *i_part; + + for ( i_part = document->parts; i_part != NULL; i_part = i_part->next ) + { + if ( !i_part->headers || + i_part->headers[0].htype->typeCharacter != 'h' || + !strcmp(i_part->headers[0].function_name, + "ROBODoc Cascading Style Sheet") ) + continue; + RB_HTML_Generate_Link( dest_doc, + filename, + i_part->filename->docname, + NULL, + i_part->headers[0].function_name, + "menuitem" ); + fprintf( dest_doc, "\n" ); + } +} + + /****f* HTML_Generator/RB_HTML_Generate_Index_Page * FUNCTION * Generate a single file with a index table for headers @@ -1362,7 +1522,7 @@ void RB_HTML_Generate_Index_Page( else { /* File opened, now we generate an index - * for the specified header type + * for the specified header type */ RB_HTML_Generate_Doc_Start( file, document->srcroot->name, @@ -1712,21 +1872,26 @@ void RB_HTML_Generate_Link( { fprintf( cur_doc, "", r, labelname ); RB_HTML_Generate_String( cur_doc, linkname ); fprintf( cur_doc, "" ); - } - else + else if (labelname) { fprintf( cur_doc, "href=\"#%s\">", labelname ); RB_HTML_Generate_String( cur_doc, linkname ); fprintf( cur_doc, "" ); } + else + { + fprintf( cur_doc, "href=\"%s\">", filename); + RB_HTML_Generate_String( cur_doc, linkname ); + fprintf( cur_doc, "" ); + } } /******/ @@ -1748,7 +1913,7 @@ char *RB_HTML_RelativeAddress( * The following two * this /sub1/sub2/sub3/f.html * that /sub1/sub2/g.html - * result in + * result in * ../g.html * * this /sub1/f.html diff --git a/Source/html_generator.h b/Source/html_generator.h index f9b752e..f95f607 100644 --- a/Source/html_generator.h +++ b/Source/html_generator.h @@ -38,6 +38,12 @@ void RB_HTML_Generate_Item_Begin( void RB_HTML_Generate_Item_End( FILE *dest_doc, char *name ); +void RB_HTML_Generate_TOC_Entries( + FILE *dest_doc, + struct RB_header **headers, + int count, + struct RB_Part *owner, + char *dest_name ); void RB_HTML_Generate_TOC_2( FILE *dest_doc, struct RB_header **headers, @@ -163,5 +169,16 @@ void RB_HTML_Generate_IndexMenu( char *filename, struct RB_Document *document, struct RB_HeaderType *cur_type ); +void RB_HTML_Generate_Header_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Document *document, + struct RB_Part *owner, + struct RB_HeaderType *cur_type ); +void RB_HTML_Generate_Module_IndexMenu( + FILE *dest_doc, + char *filename, + struct RB_Document *document, + struct RB_HeaderType *cur_type ); #endif /* ROBODOC_HTML_GENERATOR_H */ diff --git a/Source/links.c b/Source/links.c index db8b7e3..97ff93f 100644 --- a/Source/links.c +++ b/Source/links.c @@ -30,7 +30,7 @@ along with this program. If not, see . * In addition to the links derived from the headers links are * also derived from the names of all the sourcefiles. * MODIFICATION HISTORY - * ????-??-?? Frans Slothouber V1.0 + * ????-??-?? Frans Slothouber V1.0 * 2003-02-03 Frans Slothouber Refactoring ******* * $Header: /cvsroot/robodoc/robo/Source/links.c,v 1.43 2007/07/10 19:13:52 gumpu Exp $ @@ -99,12 +99,12 @@ char * function_name( char * full_name ) * SYNOPSIS */ void -RB_CollectLinks( struct RB_Document *document, +RB_CollectLinks( struct RB_Document *document, struct RB_header **headers, unsigned long count ) /* * INPUTS - * * document -- + * * document -- * * headers -- the array with headers. * * count -- number of headers in the array * OUTPUT @@ -118,7 +118,7 @@ RB_CollectLinks( struct RB_Document *document, int k; struct RB_Part *i_part; - for ( i = j = 0; i < count; ++i ) + for ( i = j = 0; i < count; ++i ) { j += headers[i]->no_names - 1; } @@ -131,7 +131,7 @@ RB_CollectLinks( struct RB_Document *document, { for ( i_part = document->parts; i_part; i_part = i_part->next ) { - if ( i_part->headers ) + if ( i_part->headers ) { link_index_size++; } @@ -155,8 +155,9 @@ RB_CollectLinks( struct RB_Document *document, assert( header->file_name ); for( k = 0; k < header->no_names; j++, k++ ) { - link = RB_Alloc_Link( header->unique_name, function_name(header->names[k]), - header->file_name ); + link = RB_Alloc_Link( header->unique_name, + header->function_name, + header->file_name ); link->htype = header->htype; link->is_internal = header->is_internal; link_index[j] = link; @@ -175,7 +176,7 @@ RB_CollectLinks( struct RB_Document *document, { for ( i_part = document->parts; i_part; i_part = i_part->next ) { - if ( i_part->headers ) + if ( i_part->headers ) { struct RB_link *link; @@ -273,18 +274,18 @@ int RB_Number_Of_Links( struct RB_HeaderType* header_type, char* file_name, int * Searches for the given word in the list of links and * headers. There are three passes (or four, when the C option * is selected). Each pass uses a different definition of "word": - * o In the first pass it is any thing that ends with a 'space', a '.' + * o In the first pass it is any thing that ends with a 'space', a '.' * or a ','. * o In the second pass it is any string that consists of alpha - * numerics, '_', ':', '.', or '-'. - * o In the third pass (for C) it is any string that consists + * numerics, '_', ':', '.', or '-'. + * o In the third pass (for C) it is any string that consists * of alpha numerics or '_'. * SYNOPSIS */ int -Find_Link( char *word_begin, - char **object_name, +Find_Link( char *word_begin, + char **object_name, char **label_name, char **file_name ) /* @@ -335,7 +336,7 @@ Find_Link( char *word_begin, case 2: { for ( cur_char = word_begin; - utf8_isalnum( *cur_char ) || ( *cur_char == '_'); + utf8_isalnum( *cur_char ) || ( *cur_char == '_'); cur_char++ ); break; } @@ -348,7 +349,7 @@ Find_Link( char *word_begin, old_char = *cur_char; *cur_char = '\0'; /* - * End the word with a '\0' + * End the word with a '\0' */ if ( strlen( word_begin ) == length ) { @@ -363,7 +364,7 @@ Find_Link( char *word_begin, length = strlen( word_begin ); /* RB_Say ("Testing (pass %d) \"%s\"\n", SAY_INFO, pass, word_begin); */ /* - * Search case sensitive for a link + * Search case sensitive for a link */ for ( cur_index = 0, low_index = 0, high_index = link_index_size - 1; high_index >= low_index; ) @@ -394,7 +395,7 @@ Find_Link( char *word_begin, * Search case insensitive for a link. * But only when the user asks for this. */ - if ( course_of_action.do_ignore_case_when_linking ) + if ( course_of_action.do_ignore_case_when_linking ) { for ( cur_index = 0, low_index = 0, high_index = @@ -443,7 +444,7 @@ Find_Link( char *word_begin, */ static struct RB_link * RB_Alloc_Link( char *label_name, char *object_name, char *file_name ) -/* +/* * INPUTS * char *label_name -- strings to copy into the link * char *file_name @@ -460,7 +461,6 @@ RB_Alloc_Link( char *label_name, char *object_name, char *file_name ) struct RB_link *new_link; assert( object_name ); - assert( label_name ); assert( file_name ); RB_Say( "Allocating a link (%s %s %s)\n", SAY_DEBUG, object_name, label_name, file_name ); new_link = malloc( sizeof( struct RB_link ) ); @@ -468,7 +468,7 @@ RB_Alloc_Link( char *label_name, char *object_name, char *file_name ) new_link->file_name = RB_StrDup( file_name ); new_link->object_name = RB_StrDup( object_name ); - new_link->label_name = RB_StrDup( label_name ); + new_link->label_name = label_name ? RB_StrDup( label_name ) : NULL; return ( new_link ); } @@ -508,4 +508,3 @@ void RB_Free_Link( struct RB_link *arg_link ) } /******/ - diff --git a/Source/optioncheck.c b/Source/optioncheck.c index 6067211..6df842d 100644 --- a/Source/optioncheck.c +++ b/Source/optioncheck.c @@ -48,7 +48,7 @@ void Print_Short_Use( /****t* UserInterface/Option_Test_Kind * FUNCTION - * Enumeration for the kind of tests that are carried out on the + * Enumeration for the kind of tests that are carried out on the * options that the user specifies. * SOURCE */ @@ -139,6 +139,8 @@ static char *ok_options[] = { "--singlefile", "--multidoc", "--one_file_per_header", + "--module_index_menu", + "--header_toc", "--first_section_level", "--sections", "--internal", @@ -181,6 +183,8 @@ static char *ok_options[] = { "--masterindex", "--sourceindex", "--header_breaks", + "--document_header", + "--document_footer", ( char * ) NULL }; @@ -226,7 +230,7 @@ static void Add_Option_Test( static void Add_Option_Name( struct RB_Option_Test *option_test, char *name ) -/* +/* * INPUTS * option_test -- the option test * name -- the name of the option @@ -425,7 +429,7 @@ static int Do_Mutual_Exlcude_Test( /****f* UserInterface/Do_Option_Tests * FUNCTION * Run a series of tests on the options that the user - * specified. These tests are specified in + * specified. These tests are specified in * option_tests. * SYNOPSIS */ diff --git a/Source/robodoc.c b/Source/robodoc.c index 2cf5332..1299b0f 100644 --- a/Source/robodoc.c +++ b/Source/robodoc.c @@ -32,7 +32,7 @@ along with this program. If not, see . * The whole ROBODoc process consists of three steps: scanning, * analysing, generating. * - * Scanning + * Scanning * * ROBODoc scans the source directory tree. This collects the names of * all the source files. @@ -45,7 +45,7 @@ along with this program. If not, see . * Generating * * In this step the headers are written to one or more documentation files. - * In addition + * In addition * * * The data collected during scanning and analysing is stored in a @@ -59,14 +59,14 @@ along with this program. If not, see . * another RB_Path structure that tells in which directory is a directory * located (of which directory it is a subdirectory). The only exception * is the root directory. - * + * * Besides the name of the sourcefile, the RB_Filename also stores the * name of the documentation file. - * + * * For each sourcefile there is an RB_Part structure. It contains a * pointer (filename) to the RB_Filename and a list (headers) of * RB_Header structure containing the headers found in the sourcefile. - * + * * Every RB_Header structure contains a pointer (owner) to the RB_Part * structure to which it belongs. Headers can form a hierarchy that is * used to create sections and subsections in the documentation. To @@ -75,25 +75,25 @@ along with this program. If not, see . * headers, SubModule is the parent of SubSubModule. * ****h* TopModule/SubModule * * - * **** - * + * **** + * * ****h* SubModule/SubSubModule * * - * **** - * + * **** + * * In the documentation this creates the sections * 1.TopModule * 1.1 SubModule * 1.1.1 SubSubModule - * + * * The RB_Directory and the linked list of RB_Part structures are * stored in a RB_Document structure. - * + * * During the generation of the documentation ROBODoc tries to create * cross links between the mention of a header's name (an object) and the * documentation generated from that header (the documentation for the * object). - * + * * To aid this proces there is an array of RB_link structures. This * array is sorted for quick searching. RB_link structures the name * of a header and the name of the label under which the documentation @@ -291,8 +291,16 @@ char use_options3[] = " Specify the tile and filename for master index page\n" " --sourceindex title,filename\n" " Specify the tile and filename for source files index page\n" + " --document_header filename\n" + " Read document header from specified file\n" + " --document_footer filename\n" + " Read document footer from specified file\n" " --one_file_per_header\n" " Create a separate documentation file for each header\n" + " --module_index_menu\n" + " Create a module menu when used with --one_file_per_header\n" + " --header_toc\n" + " Create a header TOC when used with --one_file_per_header\n" " --header_breaks NUMBER\n" " Insert a linebreak after every NUMBER header names\n" " (default value: 2, set to zero to disable)\n" "\n"; @@ -353,13 +361,17 @@ int main( struct RB_Directory *srctree = NULL; char *optstr = NULL; char *used_rc_file = NULL; + char *doc_h = NULL; + char *doc_f = NULL; + char buffer[8192]; + int r_len; long debug = 0; /* TODO, make setlocale work. char * loc; - if ( (loc = getenv("LC_CTYPE") ) != NULL ) + if ( (loc = getenv("LC_CTYPE") ) != NULL ) { printf( ".... %s\n", loc ); setlocale( LC_ALL, loc); @@ -429,6 +441,8 @@ int main( document->compress = Find_Parameterized_Option( "--compress" ); document->section = Find_Parameterized_Option( "--mansection" ); document_title = Find_Parameterized_Option( "--documenttitle" ); + doc_h = Find_Parameterized_Option( "--document_header" ); + doc_f = Find_Parameterized_Option( "--document_footer" ); optstr = Find_Parameterized_Option( "--first_section_level" ); if ( optstr ) { @@ -514,6 +528,46 @@ int main( return EXIT_FAILURE; } + /* Open header and footer files */ + if ( doc_h ) + { + FILE *dh = fopen( doc_h, "r" ); + if ( !dh ) + { + printf( "Error: '%s' no such file or directory\n", doc_h ); + Print_Short_Use( ); + return EXIT_FAILURE; + } + + memset( buffer, 0, sizeof( buffer ) ); + r_len = fread ( buffer, 1, sizeof( buffer ), dh ); + if ( r_len > 0 ) + { + document_header = calloc( r_len, sizeof( *document_header ) ); + memcpy( document_header, buffer, r_len ); + } + fclose( dh ); + } + if ( doc_f ) + { + FILE *df = fopen( doc_f, "r" ); + if ( !df ) + { + printf( "Error: '%s' no such file or directory\n", doc_f ); + Print_Short_Use( ); + return EXIT_FAILURE; + } + + memset( buffer, 0, sizeof( buffer ) ); + r_len = fread ( buffer, 1, sizeof( buffer ), df ); + if ( r_len > 0 ) + { + document_footer = calloc( r_len, sizeof( *document_footer ) ); + memcpy( document_footer, buffer, r_len ); + } + fclose( df ); + } + /* What mode are we using? */ if ( Find_Option( "--multidoc" ) ) { @@ -789,7 +843,7 @@ static char *Find_And_Fix_Path( * other function of robodoc that expect a '/'. * So to prevent this we replace all the '\' in a path * with '/' - * + * * In addition people sometimes add a '/' at the * end of the path. We remove it. * @@ -1132,6 +1186,16 @@ actions_t Find_Actions( { actions.do_one_file_per_header = TRUE; } + else if ( !RB_Str_Case_Cmp( configuration.options.names[parameter_nr], + "--module_index_menu" ) ) + { + actions.do_module_index_menu = TRUE; + } + else if ( !RB_Str_Case_Cmp( configuration.options.names[parameter_nr], + "--header_toc" ) ) + { + actions.do_header_toc = TRUE; + } else if ( !RB_Str_Case_Cmp( configuration.options.names[parameter_nr], "--sections" ) ) { @@ -1368,8 +1432,8 @@ char *Find_Parameterized_Option( * Search for an option of the form * --a_option_name a_value * in argv. The function is used to look for the - * --rc - * option that can be used to specify an + * --rc + * option that can be used to specify an * alternate robodoc configuration file. * SYNOPSIS */ diff --git a/Source/robodoc.h b/Source/robodoc.h index 086c904..573baf5 100644 --- a/Source/robodoc.h +++ b/Source/robodoc.h @@ -66,6 +66,8 @@ typedef struct actions_s int do_singlefile:1; int do_one_file_per_header:1; int do_no_subdirectories:1; + int do_module_index_menu:1; + int do_header_toc:1; // Latex options int do_altlatex:1; @@ -93,7 +95,7 @@ typedef struct actions_s * Enumeration for the various output formats that are * supported by ROBODoc. * NOTES - * These should be prefixed with RB_ + * These should be prefixed with RB_ * SOURCE */ @@ -138,4 +140,3 @@ actions_t No_Actions( void ); #endif /* ROBODOC_ROBODOC_H */ - -- 2.24.0