HTML_Generator/RB_HTML_Generate_TOC_Section [ Functions ]

FUNCTION

Create a table of contents based on the hierarchy of the headers starting for a particular point in this hierarchy (the parent).

SYNOPSIS

void RB_HTML_Generate_TOC_Section(
    FILE *dest_doc,
    char *dest_name,
    struct RB_header *parent,
    struct RB_header **headers,
    int count,
    int depth )

INPUTS

NOTES

This is a recursive function and tricky stuff.

SOURCE

{
    struct RB_header   *header;
    int                 i, n, once = 0;

    ++sectiontoc_counters[depth];

    for ( i = depth + 1; i < MAX_SECTION_DEPTH; ++i )
    {
        sectiontoc_counters[i] = 0;
    }

    // List item start
    fprintf( dest_doc, "<li>" );

    // Do not generate section numbers if sectionnameonly
    if ( !( course_of_action.do_sectionnameonly ) )
    {
        for ( i = 1; i <= depth; ++i )
        {
            fprintf( dest_doc, "%d.", sectiontoc_counters[i] );
        }
        fprintf( dest_doc, " " );
    }


    // Generate Link to first reference name
    RB_HTML_Generate_Link( dest_doc, dest_name, parent->file_name,
                           parent->unique_name,
                           // only generate function name if sectionnameonly
                           ( course_of_action.do_sectionnameonly ) ?
                           parent->function_name : parent->name, 0 );

    // Generate links to further reference names
    for ( n = 1; n < parent->no_names; n++ )
    {
        RB_HTML_Generate_String( dest_doc, ", " );
        RB_HTML_Generate_Link( dest_doc, dest_name, parent->file_name,
                               parent->unique_name, parent->names[n], 0 );
    }

    // List item end
    fprintf( dest_doc, "</li>\n" );

    for ( i = 0; i < count; ++i )
    {
        header = headers[i];
        if ( header->parent == parent )
        {
            // Generate better TOC level hiearchy (Thuffir)
            // We only generate <ul> once for a level
            if ( !once )
            {
                once = 1;
                fprintf( dest_doc, "<ul>\n" );
            }
            RB_HTML_Generate_TOC_Section( dest_doc, dest_name, header,
                                          headers, count, depth + 1 );
        }
        else
        {
            /* Empty */
        }
    }
    // If we have generated an <ul> before, generate the closing one too.
    if ( once )
        fprintf( dest_doc, "</ul>\n" );
}