Generator/Generate_Item [ Functions ]
SYNOPSIS
static void Generate_Item( FILE *f, struct RB_header *header, struct RB_Item *cur_item, char *docname )
FUNCTION
Generate the documentation for a single item.
NOTE
This function is way too long...
SOURCE
{ static int dot_nr = 1; int line_nr; char *dot_type = NULL; FILE *tool = NULL; // Pipe handler to the tool we use enum ItemType item_type = cur_item->type; char *name = configuration.items.names[item_type]; Generate_Item_Name( f, item_type ); RB_Generate_Item_Begin( f, name ); for ( line_nr = 0; line_nr < cur_item->no_lines; ++line_nr ) { struct RB_Item_Line *item_line = cur_item->lines[line_nr]; char *line = item_line->line; // Plain item lines if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_PLAIN ) ) { Format_Line( f, item_line->format ); Generate_Item_Line( f, line, item_type, docname, header ); } // Last line else if ( item_line->kind == ITEM_LINE_END ) { Format_Line( f, item_line->format ); } // Normal Pipes else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_PIPE ) ) { Format_Line( f, item_line->format ); if ( item_line->pipe_mode == output_mode ) { Pipe_Line( f, line ); } } // Tool start else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_TOOL_START ) ) { Format_Line( f, item_line->format ); // Change to docdir RB_Change_To_Docdir( docname ); // Open pipe to tool tool = RB_Open_Pipe( line ); // Get back to working dir RB_Change_Back_To_CWD( ); } // Tool (or DOT) body else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_TOOL_BODY ) ) { if ( tool != NULL ) { fprintf( tool, "%s\n", line ); } } // Tool end else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_TOOL_END ) ) { // Close pipe RB_Close_Pipe( tool ); tool = NULL; } // DOT start else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_DOT_START ) ) { Format_Line( f, item_line->format ); // Get DOT file type dot_type = RB_Get_DOT_Type( ); if ( dot_type ) { char pipe_str[TEMP_BUF_SIZE]; // Change to docdir RB_Change_To_Docdir( docname ); snprintf( pipe_str, sizeof( pipe_str ), "%s -T%s -o%s%d.%s", dot_name, dot_type, DOT_GRAPH_NAME, dot_nr, dot_type ); tool = RB_Open_Pipe( pipe_str ); } } // DOT end else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_DOT_END ) ) { if ( tool ) { // Close pipe RB_Close_Pipe( tool ); tool = NULL; // Generate link to image RB_Generate_DOT_Image_Link( f, dot_nr, dot_type ); // Get back to working dir RB_Change_Back_To_CWD( ); // Increment dot file number dot_nr++; } } // DOT file include else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_DOT_FILE ) ) { Format_Line( f, item_line->format ); // Get DOT file type dot_type = RB_Get_DOT_Type( ); if ( dot_type ) { FILE *in = NULL, *dot_pipe = NULL; char str[TEMP_BUF_SIZE]; // Open the dot source snprintf( str, sizeof( str ), "%s%s", header->owner->filename->path->name, line ); in = RB_Open_File( str, "r" ); // Change to docdir RB_Change_To_Docdir( docname ); // Open a pipe to DOT snprintf( str, sizeof( str ), "%s -T%s -o%s%d.%s", dot_name, dot_type, DOT_GRAPH_NAME, dot_nr, dot_type ); dot_pipe = RB_Open_Pipe( str ); // Pipe data to DOT while ( fgets( str, sizeof( str ), in ) != NULL ) fputs( str, dot_pipe ); // Close file handlers RB_Close_File( in ); RB_Close_Pipe( dot_pipe ); // Generate link to image RB_Generate_DOT_Image_Link( f, dot_nr, dot_type ); // Get back to working dir RB_Change_Back_To_CWD( ); // Increment dot file number dot_nr++; } } // Exec item else if ( !Works_Like_SourceItem( item_type ) && ( item_line->kind == ITEM_LINE_EXEC ) ) { Format_Line( f, item_line->format ); // Change to docdir RB_Change_To_Docdir( docname ); // Execute line system( line ); // Get back to working dir RB_Change_Back_To_CWD( ); } // Source lines else if ( Works_Like_SourceItem( item_type ) ) { Format_Line( f, item_line->format ); // Generate line numbers for SOURCE like items RB_Generate_Item_Line_Number( f, item_line->line_number, cur_item->max_line_number ); // Generate item line Generate_Item_Line( f, line, item_type, docname, header ); } else { /* This item line is ignored */ } } RB_Generate_Item_End( f, name ); }