1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/****h* ROBODoc/Part
* FUNCTION
* Structures and functions that deal with documentation parts. A
* part links a sourcefile to the documentation file and contains
* all the headers found in a sourcefile. Parts (in the form of
* struct RB_Part) are stored in a RB_Document structure.
*****
*/
#include <stdlib.h>
#include <assert.h>
#include "headers.h"
#include "file.h"
#include "part.h"
#include "util.h"
#ifdef DMALLOC
#include <dmalloc.h>
#endif
/****f* Part/RB_Get_RB_Part
* FUNCTION
* Create a new RB_Part and initialize it.
* SYNOPSIS
*/
struct RB_Part* RB_Get_RB_Part( void )
/*
* RESULT
* A freshly allocated and initializedand RB_Part.
* SOURCE
*/
{
struct RB_Part *part = NULL;
part = ( struct RB_Part * ) malloc( sizeof( struct RB_Part ) );
if ( part )
{
part->next = NULL;
part->filename = NULL;
part->headers = NULL;
part->last_header = NULL;
}
else
{
RB_Panic( "Out of memory! RB_Get_RB_Part()" );
}
return part;
}
/******/
/****f* Part/RB_Free_RB_Part
* FUNCTION
* Free the memory used by an RB_Part. Most of this is handled in
* other functions.
* SYNOPSIS
*/
void RB_Free_RB_Part( struct RB_Part *part )
/*
* INPUTS
* o part -- the part to be freed.
* SOURCE
*/
{
/* part->filename is freed by RB_Directory */
/* part->headers. Headers are freed by the document */
free( part );
}
/*******/
/****f* Part/RB_Open_Source
* FUNCTION
* Open the sourcefile of this part.
* SYNOPSIS
*/
FILE* RB_Open_Source( struct RB_Part *part )
/*
* INPUTS
* o part -- the part for which the file is opened.
* SOURCE
*/
{
char *sourcefilename = NULL;
FILE *result;
assert( part );
assert( part->filename );
sourcefilename = Get_Fullname( part->filename );
result = fopen( sourcefilename, "r" );
if ( result )
{
/* OK */
}
else
{
RB_Panic( "can't open %s!", sourcefilename );
}
return result;
}
/******/
/* TODO Documentation */
FILE* RB_Open_Documentation( struct RB_Part * part )
{
char *docfilename = NULL;
FILE *result;
assert( part );
assert( part->filename );
docfilename = RB_Get_FullDocname( part->filename );
RB_Say( "Creating file %s\n", SAY_DEBUG, docfilename );
result = fopen( docfilename, "w" );
if ( result )
{
/* OK */
}
else
{
RB_Panic( "can't open %s!", docfilename );
}
return result;
}
/* TODO Documentation */
void
RB_Part_Add_Source( struct RB_Part *part, struct RB_Filename *sourcefilename )
{
/* One sourcefile per part. */
part->filename = sourcefilename;
}
struct RB_Filename *RB_Part_Get_Source( struct RB_Part *part )
{
return part->filename;
}
/* TODO Documentation */
void
RB_Part_Add_Header( struct RB_Part *part, struct RB_header *header )
{
assert( header );
assert( header->module_name );
assert( header->function_name );
header->owner = part;
if ( part->last_header )
{
header->next = NULL;
part->last_header->next = header;
part->last_header = header;
}
else
{
header->next = NULL;
part->headers = header;
part->last_header = header;
}
}
|