Imported Robodoc.
[robodoc.git] / Source / part.c
1 /*
2 Copyright (C) 1994-2007  Frans Slothouber, Jacco van Weert, Petteri Kettunen,
3 Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
4 Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
5
6 This file is part of ROBODoc
7
8 ROBODoc is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 */
22
23 /****h* ROBODoc/Part
24  * FUNCTION
25  *   Structures and functions that deal with documentation parts.  A
26  *   part links a sourcefile to the documentation file and contains
27  *   all the headers found in a sourcefile.  Parts (in the form of
28  *   struct RB_Part) are stored in a RB_Document structure.
29  *****
30  */
31
32 #include <stdlib.h>
33 #include <assert.h>
34 #include "headers.h"
35 #include "file.h"
36 #include "part.h"
37 #include "util.h"
38
39
40 #ifdef DMALLOC
41 #include <dmalloc.h>
42 #endif
43
44
45 /****f* Part/RB_Get_RB_Part
46  * FUNCTION
47  *   Create a new RB_Part and initialize it.
48  * SYNOPSIS
49  */
50 struct RB_Part* RB_Get_RB_Part( void  )
51 /*
52  * RESULT
53  *   A freshly allocated and initializedand RB_Part.
54  * SOURCE
55  */
56 {
57     struct RB_Part     *part = NULL;
58     part = ( struct RB_Part * ) malloc( sizeof( struct RB_Part ) );
59     if ( part )
60     {
61         part->next = NULL;
62         part->filename = NULL;
63         part->headers = NULL;
64         part->last_header = NULL;
65     }
66     else
67     {
68         RB_Panic( "Out of memory! RB_Get_RB_Part()" );
69     }
70     return part;
71 }
72
73 /******/
74
75
76
77 /****f* Part/RB_Free_RB_Part
78  * FUNCTION
79  *   Free the memory used by an RB_Part.  Most of this is handled in
80  *   other functions.
81  * SYNOPSIS
82  */
83 void RB_Free_RB_Part( struct RB_Part *part )
84 /*
85  * INPUTS
86  *   o part  -- the part to be freed.
87  * SOURCE
88  */
89 {
90     /* part->filename  is freed by RB_Directory */
91     /* part->headers.  Headers are freed by the document */
92     free( part );
93 }
94
95 /*******/
96
97 /****f* Part/RB_Open_Source
98  * FUNCTION
99  *   Open the sourcefile of this part.
100  * SYNOPSIS
101  */
102 FILE* RB_Open_Source( struct RB_Part *part )
103 /*
104  * INPUTS
105  *   o part -- the part for which the file is opened.
106  * SOURCE
107  */
108 {
109     char               *sourcefilename = NULL;
110     FILE               *result;
111
112     assert( part );
113     assert( part->filename );
114     sourcefilename = Get_Fullname( part->filename );
115     result = fopen( sourcefilename, "r" );
116     if ( result ) 
117     {
118         /* OK */
119     }
120     else
121     {
122         RB_Panic( "can't open %s!", sourcefilename );
123     }
124     return result;
125 }
126
127 /******/
128
129
130 /* TODO Documentation */
131 FILE* RB_Open_Documentation( struct RB_Part * part )
132 {
133     char               *docfilename = NULL;
134     FILE               *result;
135
136     assert( part );
137     assert( part->filename );
138     docfilename = RB_Get_FullDocname( part->filename );
139     RB_Say( "Creating file %s\n", SAY_DEBUG, docfilename );
140     result = fopen( docfilename, "w" );
141     if ( result ) 
142     {
143         /* OK */
144     }
145     else
146     {
147         RB_Panic( "can't open %s!", docfilename );
148     }
149     return result;
150 }
151
152
153 /* TODO Documentation */
154 void
155 RB_Part_Add_Source( struct RB_Part *part, struct RB_Filename *sourcefilename )
156 {
157     /* One sourcefile per part. */
158     part->filename = sourcefilename;
159 }
160
161 struct RB_Filename *RB_Part_Get_Source( struct RB_Part *part )
162 {
163     return part->filename;
164 }
165
166 /* TODO Documentation */
167 void
168 RB_Part_Add_Header( struct RB_Part *part, struct RB_header *header )
169 {
170     assert( header );
171     assert( header->module_name );
172     assert( header->function_name );
173
174     header->owner = part;
175     if ( part->last_header )
176     {
177         header->next = NULL;
178         part->last_header->next = header;
179         part->last_header = header;
180     }
181     else
182     {
183         header->next = NULL;
184         part->headers = header;
185         part->last_header = header;
186     }
187 }