15 /****** ROBODoc/RB_Analyse_Document [3.0i]
17 * RB_Analyse_Document -- scan document for headers and store them
19 * RB_Analyse_Document (document)
20 * RB_Analyse_Document (FILE *)
22 * Searches the document for headers. Stores information about
23 * any headers that are found in a linked list. Information
24 * that is stored includes, the name of the header, its version
25 * number, and its contents.
27 * document - a pointer to a file with the document to be
29 * the gobal buffer line_buffer.
31 * 1) A linked list pointed to by the global variable
32 * first_header that contains information about each
35 * Using fseek and ftell because gcc doesn't know fgetpos and fsetpos,
36 * on the sun unix system that I use.
43 RB_Analyse_Document (FILE * document)
50 (header_type = RB_Find_Marker (document)) != NO_HEADER;
53 struct RB_header *new_header;
57 ((header_type == INTERNAL_HEADER) &&
58 !(course_of_action & (DO_INCLUDE_INTERNAL | DO_INTERNAL_ONLY)))
60 ((header_type != INTERNAL_HEADER) &&
61 (course_of_action & DO_INTERNAL_ONLY))
63 (header_type == BLANK_HEADER)
69 new_header = RB_Alloc_Header ();
70 RB_Insert_In_List (&first_header, new_header);
71 new_header->type = header_type;
72 if ((new_header->name = RB_Find_Header_Name ()) != NULL)
74 RB_Say ("found header [line %5d]: \"%s\"\n",
75 line_number, new_header->name);
76 if ((new_header->function_name
77 = RB_Function_Name (new_header->name)) == NULL)
79 RB_Panic ("Can't determine the \"function\" name.\n");
81 cur_file_pos = (long) ftell (document);
82 if ((real_size = RB_Find_End_Marker (document,
88 fseek (document, cur_file_pos, 0);
89 if ((contents = malloc ((new_header->size +
93 fread (contents, new_header->size, sizeof (char), document);
95 contents[real_size] = '\0';
96 new_header->contents = contents;
97 new_header->size = real_size;
100 RB_Panic ("out of memory! [Alloc Header Contents]\n");
104 RB_Panic ("found header with no end marker \"%s\"\n",
110 RB_Panic ("found header marker but no name [line %d]\n",
116 if (header_type != BLANK_HEADER)
118 if ((name = RB_Find_Header_Name ()) != NULL)
120 new_header = RB_Alloc_Header ();
122 RB_Find_End_Marker (document, &new_header->size))
125 RB_Free_Header (new_header);
126 RB_Panic ("found header with no end marker \"%s\"\n", name);
130 RB_Free_Header (new_header);
135 RB_Panic ("found header marker but no name [line %d]\n",
143 /****** END RB_Analyse_Document *******/
148 /****f* ROBODoc/RB_Function_Name [2.0x]
150 * RB_Function_Name -- get pointer to the function name.
152 * char *RB_NamePart(char *header_name)
154 * A header name is consists of two parts. The module name and
155 * the function name. This returns a pointer to the function name.
156 * The name "function name" is a bit obsolete. It is really the name
157 * of any of objects that can be documented; classes, methods,
158 * variables, functions, projects, etc.
163 RB_Function_Name (char *header_name)
170 if ((cur_char = header_name) != NULL)
172 for (; (c = *cur_char) != '\0'; ++cur_char)
174 if ('/' == *cur_char)
184 temp = malloc((strlen(name) + 1) * sizeof(char));
192 /*** RB_Name_Part ***/
196 /****** ROBODoc/RB_Find_Marker [3.0h]
198 * RB_Find_Marker -- Search for header marker in document.
200 * header_type = RB_Find_Marker (document)
201 * int RB_Find_Marker (FILE *)
203 * Read document file line by line, and search each line for the
204 * any of the headers defined in the array header_markers
206 * document - pointer to the file to be searched.
207 * the gobal buffer line_buffer.
211 * (1) NO_HEADER - no header found, end of file reached
214 * (4) INTERNAL_HEADER
216 * Bad use of feof(), fgets().
223 RB_Find_Marker (FILE * document)
226 int marker, marker_type;
227 char *cur_char, *cur_mchar;
229 marker_type = NO_HEADER;
232 while (!feof (document) && !found)
235 fgets (line_buffer, MAX_LINE_LEN, document);
236 if (!feof (document))
240 ((cur_mchar = header_markers[marker]) != NULL) && !found;
243 for (found = TRUE, cur_char = line_buffer;
244 *cur_mchar && *cur_char && found;
245 cur_mchar++, cur_char++)
247 if (tolower(*cur_mchar) != tolower(*cur_char))
256 marker_type = MAIN_HEADER;
259 marker_type = GENERIC_HEADER;
262 marker_type = INTERNAL_HEADER;
265 marker_type = FUNCTION_HEADER;
268 marker_type = STRUCT_HEADER;
271 marker_type = CLASS_HEADER;
274 marker_type = METHOD_HEADER;
277 marker_type = CONSTANT_HEADER;
280 marker_type = VARIABLE_HEADER;
283 RB_Say ("%s: WARNING, [line %d] undefined headertype,"
284 " using GENERIC\n", whoami, line_number);
285 marker_type = GENERIC_HEADER;
290 if (!found || feof (document))
292 marker_type = NO_HEADER;
294 else if (marker_type == GENERIC_HEADER)
296 skip_while (*cur_char == '*');
297 if (*cur_char == '/')
299 marker_type = BLANK_HEADER;
305 /******** END RB_Find_Marker ******/
308 /****** ROBODoc/RB_Find_End_Marker [3.0h]
310 * RB_Find_End_Marker -- Search for end marker in document.
312 * result = RB_Find_End_Marker (document)
313 * int RB_Find_End_Marker (FILE *)
315 * Searches line by line till any of the markers in the
316 * array: end_markers is found.
318 * document - pointer to the file to be searched.
319 * int *total_size - external size
320 * the gobal buffer line_buffer.
322 * real_size if end marker was found
323 * 0 - no end marker was found
330 RB_Find_End_Marker (FILE * document, int *total_size)
336 char *cur_char, *cur_mchar;
338 while (!feof (document) && !found)
340 cur_char = line_buffer;
342 fgets (cur_char, MAX_LINE_LEN, document);
343 ++line_number; /* global linecounter *koessi */
345 line_len = strlen (cur_char);
346 real_size += line_len;
348 if (!feof (document))
351 ((cur_mchar = end_markers[marker]) != NULL) && !found;
354 for (found = TRUE, cur_char = line_buffer;
355 *cur_mchar && *cur_char && found;
356 cur_mchar++, cur_char++)
358 if (tolower(*cur_mchar) != tolower(*cur_char))
365 *total_size = real_size;
367 return real_size - line_len;
372 /***** RB_Find_End_Marker *****/
375 /****** ROBODoc/RB_Find_Header_Name [3.0b]
377 * RB_Find_Header_Name -- search for header name
379 * result = RB_Find_Header_Name ()
380 * char *RB_Find_Header_Name ()
382 * Searches the line buffer for the header name.
383 * It assumes that the header name follows after the
384 * header marker, seperated by one or more spaces, and terminated
385 * by one or more spaces or a '\n'.
386 * It allocates an array of chars and copies the name to this array.
388 * the gobal buffer line_buffer.
390 * pointer to the allocated array of chars that contains the name,
391 * terminated with a '\0'.
392 * NULL if no header name was found.
393 * MODIFICATION HISTORY
394 * 8. August 1995 -- optimized by koessi
396 * RB_Find_Function_Name(), RB_WordLen(), RB_StrDup()
401 RB_Find_Header_Name (void)
405 cur_char = line_buffer;
406 skip_while (*cur_char != '*');
407 skip_while (!isspace (*cur_char));
408 skip_while (isspace (*cur_char));
411 char *end_char, old_char;
413 end_char = cur_char + RB_WordLen (cur_char);
414 old_char = *end_char;
416 cur_char = RB_StrDup (cur_char);
417 *end_char = old_char;
423 /***** RB_Find_Header_Name *****/
426 /****** ROBODoc/RB_Find_Item [3.0b]
428 * RB_Find_Item -- find item in header contents.
430 * item_type = RB_Find_Item (next_line,item_line)
432 * int RB_Find_Item (char **, char **)
434 * Searches the header contents line by line, looking
435 * for an item Indicator.
437 * next_line - pointer to a pointer that points to line
438 * at which the search will start.
440 * next_line - pointer to a pointer that points to begin of the line
441 * after the line the item was found on.
442 * item_line - pointer to a pointer that points to the line the item
445 * item_type - one of possible items indicators.
450 RB_Find_Item (char **next_line, char **item_line)
452 char *cur_char = *next_line;
455 for (item_type = NO_ITEM;
456 *cur_char && (item_type == NO_ITEM);
459 *item_line = cur_char;
460 cur_char = RB_Skip_Remark_Marker (cur_char);
462 skip_while (isspace (*cur_char) && *cur_char != '\n');
463 if (isupper (*cur_char))
465 char *item_begin = cur_char;
468 skip_while (isupper (*cur_char));
470 if (isspace (*cur_char) && *cur_char)
472 skip_while (isspace (*cur_char) && *cur_char != '\n');
474 /* Item consists of two words ? */
475 if (isupper (*cur_char) && *cur_char)
477 skip_while (isupper (*cur_char));
479 skip_while (isspace (*cur_char) && *cur_char != '\n');
481 if (*cur_char == '\n')
483 char old_char = *item_end;
486 item_type = RB_Get_Item_Type (item_begin);
487 *item_end = old_char;
492 if (item_type == NO_ITEM)
500 /* advance item_line to end of comment block when we have no more items */
501 if (item_type == NO_ITEM)
503 *item_line = cur_char;
505 *next_line = cur_char;
509 /***** RB_Find_Item *****/
512 /****** ROBODoc/RRB_Number_Duplicate_Headers
514 * RB_Number_Duplicate_Headers -- number duplicate headers
516 * RB_Number_Duplicate_Headers (void)
518 * Extends the function name with an additional number if there
519 * are several components with the same name.
520 * Otherwise there will be labels with the same name in HTML
521 * which confuses the browser.
526 RB_Number_Duplicate_Headers (void)
528 struct RB_header *cur_header;
529 struct RB_header *dup_header;
530 for (cur_header = first_header;
532 cur_header = cur_header->next_header)
536 for (dup_header = cur_header->next_header;
538 dup_header = dup_header->next_header)
540 if (strcmp(cur_header->function_name,
541 dup_header->function_name) == 0) {
544 sprintf(number, "(%d)", nr);
545 new_name = malloc ((strlen(number) + 1 +
546 strlen(dup_header->function_name) + 1 ) * sizeof(char));
547 if (new_name == NULL)
548 RB_Panic ("out of memory! [Number Duplicates]\n");
549 sprintf(new_name, "%s%s", dup_header->function_name,
551 free(dup_header->function_name);
552 dup_header->function_name = new_name;
561 /****** ROBODoc/RB_Make_Index_Tables [3.0b]
563 * RB_Make_Index_Tables
565 * void RB_Make_Index_Tables (void)
567 * Creates sorted index tables of headers and links to speed up
568 * matching links later on.
572 * Modifies header_index & link_index
579 RB_Make_Index_Tables ()
581 int nr_of_headers, header;
582 int nr_of_links, link;
583 struct RB_link *cur_link;
584 struct RB_header *cur_header;
586 for (cur_header = first_header, nr_of_headers = 0;
588 cur_header = cur_header->next_header)
591 for (cur_link = first_link, nr_of_links = 0;
593 cur_link = cur_link->next_link)
600 RB_Say ("Allocating Header Index Table\n");
601 header_index = malloc (nr_of_headers * sizeof (struct RB_header **));
603 header_index_size = nr_of_headers;
605 RB_Panic ("out of memory! [Make Index Tables]\n");
607 /* Fill Index Table */
608 for (cur_header = first_header, header = 0;
610 cur_header = cur_header->next_header, header++)
611 header_index[header] = cur_header;
613 /* Sort Index Table */
614 RB_Say ("Sorting Header Index Table\n");
615 for (sort1 = 0; sort1 < nr_of_headers; sort1++)
617 struct RB_header *temp;
619 for (sort2 = sort1; sort2 < nr_of_headers; sort2++)
621 if (strcmp (header_index[sort1]->function_name,
622 header_index[sort2]->function_name) > 0)
624 temp = header_index[sort1];
625 header_index[sort1] = header_index[sort2];
626 header_index[sort2] = temp;
635 RB_Say ("Allocating Link Index Table\n");
636 link_index = malloc (nr_of_links * sizeof (struct RB_link **));
638 link_index_size = nr_of_links;
640 RB_Panic ("out of memory! [Make Index Tables]\n");
642 /* Fill Index Table */
643 for (cur_link = first_link, link = 0;
645 cur_link = cur_link->next_link, link++)
647 link_index[link] = cur_link;
650 /* Sort Index Table */
651 RB_Say ("Sorting Link Index Table\n");
652 for (sort1 = 0; sort1 < nr_of_links; sort1++)
654 struct RB_link *temp;
656 for (sort2 = sort1; sort2 < nr_of_links; sort2++)
658 if (strcmp (link_index[sort1]->label_name,
659 link_index[sort2]->label_name) > 0)
661 temp = link_index[sort1];
662 link_index[sort1] = link_index[sort2];
663 link_index[sort2] = temp;
670 /****** RB_Make_Index_Tables *****/