summaryrefslogtreecommitdiff
path: root/macros/texinfo/texinfo/tp/Texinfo/XS/parsetexi/extra.c
blob: ccdb7fe5c0bb50fccdbd5c43b452afc9beaf6bc3 (plain)
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
/* Copyright 2010-2019 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <config.h>
#include <string.h>

#include "parser.h"

static void
add_extra_key (ELEMENT *e, char *key, ELEMENT *value,
               enum extra_type type)
{
  int i;
  for (i = 0; i < e->extra_number; i++)
    {
      if (!strcmp (e->extra[i].key, key))
        break;
    }
  if (i == e->extra_number)
    {
      if (e->extra_number == e->extra_space)
        {
          e->extra = realloc (e->extra,
                              (e->extra_space += 5) * sizeof (KEY_PAIR));
          if (!e->extra)
            fatal ("realloc failed");
        }
      e->extra_number++;
    }

  e->extra[i].key = key;
  e->extra[i].value = value;
  e->extra[i].type = type;
}

/* Add an extra key that is a reference to another element (for example, 
   'associated_section' on a node command element. */
void
add_extra_element (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_element);
}

/* Add an extra key that is a reference to another element that is
   out-of-tree, i.e., not referenced anywhere in the tree. */
void
add_extra_element_oot (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_element_oot);
}

/* Add an extra key that is a reference to the contents array of another
   element (for example, 'node_content' on a node command element). */
void
add_extra_contents (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_contents);
}

/* Like add_extra_contents but all of the contents are out-of-tree. */
void
add_extra_contents_oot (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_contents_oot);
}

/* An array of content arrays. */
void
add_extra_contents_array (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_contents_array);
}

/* Add an extra key that is a reference to the text field of another
   element. */
void
add_extra_text (ELEMENT *e, char *key, ELEMENT *value)
{
  add_extra_key (e, key, value, extra_text);
}

#if 0
/* Function not used */
void
add_extra_index_entry (ELEMENT *e, char *key, INDEX_ENTRY_REF *value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_index_entry);
}
#endif

void
add_extra_misc_args (ELEMENT *e, char *key, ELEMENT *value)
{
  if (!value) return;
  add_extra_key (e, key, value, extra_misc_args);
}

void
add_extra_node_spec (ELEMENT *e, char *key, NODE_SPEC_EXTRA *value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_node_spec);
}

/* Used for 'node_manuals' array for the arguments given on a
   @node line.  Argument is a null-terminated array of pointers. */
void
add_extra_node_spec_array (ELEMENT *e, char *key, NODE_SPEC_EXTRA **value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_node_spec_array);
}

void
add_extra_def_info (ELEMENT *e, char *key, DEF_INFO *value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_def_info);
}

void
add_extra_float_type (ELEMENT *e, char *key, EXTRA_FLOAT_TYPE *value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_float_type);
}

void
add_extra_string (ELEMENT *e, char *key, char *value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_string);
}

void
add_extra_string_dup (ELEMENT *e, char *key, char *value)
{
  add_extra_key (e, key, (ELEMENT *) strdup (value), extra_string);
}

void
add_extra_integer (ELEMENT *e, char *key, long value)
{
  add_extra_key (e, key, (ELEMENT *) value, extra_integer);
}

KEY_PAIR *
lookup_extra (ELEMENT *e, char *key)
{
  int i;
  for (i = 0; i < e->extra_number; i++)
    {
      if (!strcmp (e->extra[i].key, key))
        return &e->extra[i];
    }
  return 0;
}