Analyser/Grab_Header [ Functions ]
FUNCTION
Grab a header from a source file, that is scan a source file until the start of a header is found. Then search for the end of a header and store all the lines in between. SYNPOPSIS
INPUTS
- sourcehandle -- an opened source file.
OUTPUT
- sourcehandle -- will point to the line following the end marker.
RESULT
0 if no header was found, or a pointer to a new header otherwise.
SOURCE
{ struct RB_header *new_header = NULL; int is_internal = 0; struct RB_HeaderType *header_type = NULL; int good_header = FALSE; int reuse = FALSE; do { good_header = FALSE; header_type = RB_Find_Marker( sourcehandle, &is_internal, reuse ); reuse = FALSE; if ( header_type ) { struct RB_header *duplicate_header = NULL; long previous_line = 0; new_header = RB_Alloc_Header( ); new_header->htype = header_type; new_header->is_internal = is_internal; if ( Find_Header_Name( sourcehandle, new_header ) ) { new_header->line_number = line_number; RB_Say( "found header [line %5d]: \"%s\"\n", SAY_DEBUG, line_number, new_header->name ); duplicate_header = RB_Document_Check_For_Duplicate( arg_document, new_header ); if ( duplicate_header ) { /* Duplicate headers do not crash the program so * we accept them. But we do warn the user. */ RB_Warning ( "A header with the name \"%s\" already exists.\n See %s(%d)\n", new_header->name, Get_Fullname( duplicate_header->owner->filename ), duplicate_header->line_number ); } if ( ( new_header->function_name = Function_Name( new_header->name ) ) == NULL ) { RB_Warning( "Can't determine the \"function\" name.\n" ); RB_Free_Header( new_header ); new_header = NULL; } else { if ( ( new_header->module_name = Module_Name( new_header->name ) ) == NULL ) { RB_Warning ( "Can't determine the \"module\" name.\n" ); RB_Free_Header( new_header ); new_header = NULL; } else { previous_line = line_number; if ( Find_End_Marker( sourcehandle, new_header ) == 0 ) { RB_Warning ( "found header on line %d with name \"%s\"\n" " but I can't find the end marker\n", previous_line, new_header->name ); /* Reuse the current line while finding the next * Marking using RB_Find_Marker() */ reuse = TRUE; RB_Free_Header( new_header ); new_header = NULL; } else { RB_Say( "found end header [line %5d]:\n", SAY_DEBUG, line_number ); /* Good header found, we can stop */ good_header = TRUE; } } } } else { RB_Warning( "found header marker but no name\n" ); RB_Free_Header( new_header ); new_header = NULL; } } else { /* end of the file */ good_header = TRUE; } } while ( !good_header ); return new_header; }