12 FILE *xreffiles_file = NULL;
13 FILE *xref_file = NULL;
14 int link_index_size = 0;
15 struct RB_link **link_index = NULL;
17 /****f* ROBODoc/RB_Analyse_Xrefs [3.0b]
19 * RB_Analyse_Xrefs -- scan the xref files.
21 * RB_Analyse_Xrefs (xreffiles_file)
22 * RB_Analyse_Xrefs (FILE *)
24 * Scan the file xreffiles_file. This file contains the
25 * names of one or more xref files. All the references in the
26 * files are scaned and stored in a link list of the type
27 * RB_link. These xref files can be generated with robodoc.
29 * xreffiles_file - a file pointer to the file with xref file
34 * Might fail if there are syntax errors in one of the xref
36 * Bad use of feof() and fgets().
38 * RB_Generate_xrefs, RB_Add_Link
43 RB_Analyse_Xrefs (FILE * xreffiles_file)
45 while (!feof (xreffiles_file))
47 fgets (line_buffer, MAX_LINE_LEN, xreffiles_file);
48 if (!feof (xreffiles_file))
52 cur_char = line_buffer;
54 if (*cur_char == '\n')
56 if (strlen (line_buffer) > 1)
59 (cur_char != line_buffer) && isspace (*cur_char);
62 if ((xref_file = fopen (line_buffer, "r")) != NULL)
64 int xrefs_found = FALSE;
65 int end_of_xrefs = FALSE;
67 while (!feof (xref_file) && !xrefs_found)
69 fgets (line_buffer, MAX_LINE_LEN, xref_file);
70 if (!feof (xref_file) && !strncmp ("XREF:",
75 while (!feof (xref_file) && !end_of_xrefs)
77 fgets (line_buffer, MAX_LINE_LEN, xref_file);
78 if (!feof (xref_file))
80 cur_char = line_buffer;
82 if (*cur_char == '\"')
92 RB_Panic ("could not open xref file \"%s\"\n", line_buffer);
101 /****f* ROBODoc/RB_Slow_Sort_Links
103 * RB_Slow_Sort_Links -- sort all links according to label name.
108 RB_Slow_Sort_Links (void)
110 struct RB_link *cur_link, *unsorted_links, *bigger_link;
112 if ((unsorted_links = first_link) != NULL)
113 { /* additional check koessi */
114 for (first_link = NULL;
115 unsorted_links->next_link;)
117 for (bigger_link = unsorted_links,
118 cur_link = bigger_link->next_link;
120 cur_link = cur_link->next_link)
122 if (strcmp (cur_link->label_name, bigger_link->label_name) > 0)
123 bigger_link = cur_link;
125 RB_Remove_From_List ((struct RB_header **) &unsorted_links,
126 (struct RB_header *) bigger_link);
127 RB_Insert_In_List ((struct RB_header **) &first_link,
128 (struct RB_header *) bigger_link);
130 RB_Insert_In_List ((struct RB_header **) &first_link,
131 (struct RB_header *) unsorted_links);
136 /****f* ROBODoc/RB_Add_Link [3.0b]
138 * RB_Add_Link -- add a reference link to the list
140 * void RB_Add_Link ()
142 * Adds a reference from a xref file to the linked list
145 * Uses the global variable line_buffer and first_link.
147 * Makes sneaky use of the function RB_Insert_In_List.
149 * RB_Analyse_Xrefs, RB_link.
156 char *label_name, *file_name;
157 struct RB_link *new_link;
158 char *cur_char = line_buffer;
161 label_name = ++cur_char;
165 file_name = ++cur_char;
170 RB_Say ("adding xref link \"%s\"->\"%s\"\n", label_name, file_name);
172 new_link = RB_Alloc_Link (label_name, file_name);
173 new_link->type = atoi (cur_char);
174 RB_Insert_In_List ((struct RB_header **) &first_link,
175 (struct RB_header *) new_link);
178 /*** RB_Add_Link ***/
182 /****f* ROBODoc/RB_Generate_xrefs [2.0]
186 * RB_Generate_xrefs (dest_doc, source_name, dest_name)
188 * RB_Generate_xrefs (FILE *, char *, char *)
190 * Generates a xref file for the document that has been
191 * analysed by ROBODoc.
193 * dest_doc - pointer to the file to which the xrefs will be
195 * source_name - pointer to the name of the document that has
196 * been analysed by robodoc
197 * dest_name - pointer to the name of the document robodoc will
198 * write the documentation to.
199 * first_header - global variable, the list with function
205 RB_Generate_xrefs (FILE * dest_doc, char *source_name, char *dest_name)
207 struct RB_header *cur_header;
209 fprintf (dest_doc, "/* XREF-File generated by ROBODoc v" VERSION
211 fprintf (dest_doc, "\nXREF:\n");
212 fprintf (dest_doc, " \"%s\" \"%s\" 0\n", source_name, dest_name);
213 for (cur_header = first_header;
215 cur_header = cur_header->next_header
218 if (cur_header->function_name)
219 fprintf (dest_doc, " \"%s\" \"%s\" %d\n",
220 cur_header->function_name, dest_name, cur_header->type);
222 fprintf (dest_doc, "\n/* End of XREF-File */\n");
225 /*** RB_Generate_xrefs ***/
229 /****f* ROBODoc/RB_Find_Link [3.0h]
231 * RB_Find_Link -- try to match word with a link
233 * result = RB_Find_Link (word_begin, label_name, file_name)
234 * int RB_Find_Link (char *, char **, char **)
236 * Searches for the given word in the list of links and
237 * headers. There are three passes (or four, when the C option
238 * is selected). Each pass uses a different definition of "word".
239 * In the first pass it is any thing that ends with a 'space', a '.'
241 * In the second pass it is any string that consists of alpha
242 * numerics, '_', ':', '.', or '-'.
243 * In the third pass (for C) it is any string that consists
244 * of alpha numerics or '_'.
245 * In the last pass it is any string that consists of alpha
248 * word_begin - pointer to a word (a string).
249 * label_name - pointer to a pointer to a string
250 * file_name - pointer to a pointer to a string
252 * label_name & file_name are modified
254 * label_name -- points to the label if a match was found,
256 * file_name -- points to the file name if a match was found,
258 * TRUE -- a match was found.
259 * FALSE -- no match was found.
261 * This is a rather sensitive algorithm.
267 RB_Find_Link (char *word_begin, char **label_name, char **file_name)
269 char *cur_char, old_char;
270 int low_index, high_index, cur_index, state, pass;
273 for (pass = 0; pass < 4; pass++)
280 for (cur_char = word_begin;
281 isalnum (*cur_char) || ispunct (*cur_char);
283 if (((*(cur_char-1)) == ',') || ((*(cur_char-1)) == '.'))
289 for (cur_char = word_begin;
290 isalnum (*cur_char) || (*cur_char == '_') ||
291 (*cur_char == '-') || (*cur_char == '.') ||
298 if (extra_flags & C_MODE) {
299 for (cur_char = word_begin;
300 isalnum(*cur_char) || (*cur_char == '_');
308 for (cur_char = word_begin;
315 old_char = *cur_char;
316 *cur_char = '\0'; /* End the word with a '\0' */
317 /* RB_Say ("Testing \"%s\"\n", word_begin); */
319 /* Search in header table */
320 for (cur_index = 0, low_index = 0, high_index = header_index_size - 1;
321 high_index >= low_index;)
323 cur_index = (high_index - low_index) / 2 + low_index;
324 state = strcmp (word_begin, header_index[cur_index]->function_name);
326 high_index = cur_index - 1;
328 low_index = cur_index + 1;
331 *label_name = header_index[cur_index]->function_name;
333 RB_Say ("linking \"%s\"->\"%s\"\n", word_begin, *label_name);
334 *cur_char = old_char;
339 /* Search in the link table */
340 for (cur_index = 0, low_index = 0, high_index = link_index_size - 1;
341 high_index >= low_index;)
343 cur_index = (high_index - low_index) / 2 + low_index;
344 state = strcmp (word_begin, link_index[cur_index]->label_name);
347 high_index = cur_index - 1;
351 *label_name = link_index[cur_index]->label_name;
352 *file_name = link_index[cur_index]->file_name;
353 RB_Say ("linking \"%s\"->\"%s\" form \"%s\"\n",
354 word_begin, *label_name, *file_name);
355 *cur_char = old_char;
360 low_index = cur_index + 1;
363 *cur_char = old_char;
375 /****f* ROBODoc/RB_Alloc_Link [2.01]
377 * RB_Alloc_Link -- oop
379 * struct RB_link *RB_Alloc_Link( char *label_name, char *file_name )
381 * allocate struct + strings
383 * char *label_name -- strings to copy into the link
386 * struct RB_link * -- ready-to-use
390 * RB_StrDup(), RB_Free_Link()
395 RB_Alloc_Link (char *label_name, char *file_name)
397 struct RB_link *new_link;
398 if ((new_link = malloc (sizeof (struct RB_link))) != NULL)
400 memset (new_link, 0, sizeof (struct RB_link));
403 new_link->file_name = RB_StrDup (file_name);
405 new_link->label_name = RB_StrDup (label_name);
408 RB_Panic ("out of memory! [Alloc Link]\n");
414 /****f* ROBODoc/RB_Free_Link [2.01]
416 * RB_Free_Link -- oop
418 * void RB_Free_Link( struct RB_link *link )
420 * free struct + strings
422 * struct RB_link *link
426 * RB_Alloc_Link(), RB_Close_The_Shop()
432 RB_Free_Link (struct RB_link *link)
436 if (link->label_name)
437 free (link->label_name);
439 free (link->file_name);