1 /* Copyright 2010-2019 Free Software Foundation, Inc.
2 
3    This program is free software: you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation, either version 3 of the License, or
6    (at your option) any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
15 
16 #include <config.h>
17 #include "parser.h"
18 #include "convert.h"
19 #include "labels.h"
20 
21 /* Array of recorded labels. */
22 /* If looking through this array turns out to be slow, we might have to replace
23    it with some kind of hash table implementation. */
24 LABEL *labels_list = 0;
25 size_t labels_number = 0;
26 size_t labels_space = 0;
27 
28 /* Register a label, that is something that may be the target of a reference
29    and must be unique in the document.  Corresponds to @node, @anchor, and
30    second arg of @float. */
31 void
register_label(ELEMENT * current,ELEMENT * label)32 register_label (ELEMENT *current, ELEMENT *label)
33 {
34   if (labels_number == labels_space)
35     {
36       labels_space += 1;
37       labels_space *= 1.5;
38       labels_list = realloc (labels_list, labels_space * sizeof (LABEL));
39       if (!labels_list)
40         fatal ("realloc failed");
41     }
42   labels_list[labels_number++].target = current;
43 
44   if (label)
45     add_extra_contents (current, "node_content", label);
46 }
47 
48 void
reset_labels(void)49 reset_labels (void)
50 {
51   labels_number = 0;
52 }
53 
54 
55 
56 ELEMENT **internal_xref_list = 0;
57 size_t internal_xref_number = 0;
58 size_t internal_xref_space = 0;
59 
60 void
remember_internal_xref(ELEMENT * element)61 remember_internal_xref (ELEMENT *element)
62 {
63   if (internal_xref_number == internal_xref_space)
64     {
65       internal_xref_list = realloc (internal_xref_list,
66                              (internal_xref_space += 2)
67                              * sizeof (*internal_xref_list));
68     }
69   internal_xref_list[internal_xref_number++] = element;
70 }
71 
72 void
reset_internal_xrefs(void)73 reset_internal_xrefs (void)
74 {
75   internal_xref_number = 0;
76 }
77