1 | /* xref.c -- Manage cross references
|
---|
2 | Copyright (c) 1993-1999 Eberhard Mattes
|
---|
3 |
|
---|
4 | This file is part of emxdoc.
|
---|
5 |
|
---|
6 | emxdoc is free software; you can redistribute it and/or modify it
|
---|
7 | under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | emxdoc is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with emxdoc; see the file COPYING. If not, write to
|
---|
18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
19 | Boston, MA 02111-1307, USA. */
|
---|
20 |
|
---|
21 |
|
---|
22 | #include <stdio.h>
|
---|
23 | #include <stdlib.h>
|
---|
24 | #include <string.h>
|
---|
25 | #include <ctype.h>
|
---|
26 | #include "emxdoc.h"
|
---|
27 | #include "xref.h"
|
---|
28 |
|
---|
29 | #ifndef _MAX_FNAME
|
---|
30 |
|
---|
31 | /* Quick and dirty implementation of a subset of _splitpath() for
|
---|
32 | systems which don't have _splitpath(). */
|
---|
33 |
|
---|
34 | #include <sys/param.h>
|
---|
35 | #include <assert.h>
|
---|
36 | #define _MAX_FNAME MAXPATHLEN
|
---|
37 |
|
---|
38 | static void _splitpath (const char *src, char *drv, char *dir,
|
---|
39 | char *base, char *ext)
|
---|
40 | {
|
---|
41 | const char *p, *q;
|
---|
42 | size_t n;
|
---|
43 |
|
---|
44 | assert (drv == NULL); assert (dir == NULL); assert (ext == NULL);
|
---|
45 | assert (src != NULL); assert (base != NULL);
|
---|
46 |
|
---|
47 | p = strrchr (src, '/');
|
---|
48 | if (p == NULL)
|
---|
49 | p = src;
|
---|
50 | q = strchr (p, '.');
|
---|
51 | if (q == NULL)
|
---|
52 | n = strlen (p);
|
---|
53 | else
|
---|
54 | n = q - p;
|
---|
55 | assert (n < _MAX_FNAME);
|
---|
56 | memcpy (base, p, n);
|
---|
57 | base[n] = 0;
|
---|
58 | }
|
---|
59 |
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | static int first_keyword_flag = TRUE;
|
---|
63 | static char inf_name[_MAX_FNAME] = "";
|
---|
64 |
|
---|
65 |
|
---|
66 | void write_keyword (const uchar *p)
|
---|
67 | {
|
---|
68 | int len;
|
---|
69 |
|
---|
70 | if (*p != 0 && strpbrk (p, " ,") == NULL)
|
---|
71 | {
|
---|
72 | if (first_keyword_flag)
|
---|
73 | {
|
---|
74 | if (title != NULL)
|
---|
75 | fprintf (output_file, "DESCRIPTION: %s\n", title);
|
---|
76 | else
|
---|
77 | fprintf (output_file, "DESCRIPTION: %s.inf\n", inf_name);
|
---|
78 | first_keyword_flag = FALSE;
|
---|
79 | }
|
---|
80 | len = strlen (p);
|
---|
81 | if (len > 2 && p[len-2] == '(' && p[len-1] == ')')
|
---|
82 | len -= 2;
|
---|
83 | fprintf (output_file, "(%.*s, view %s ~)\n", len, p, inf_name);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | static void gather_define (struct word *wp)
|
---|
89 | {
|
---|
90 | fprintf (output_file, "d %d %s\n", wp->ref, wp->str);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | static void gather_reference (const uchar *p)
|
---|
95 | {
|
---|
96 | struct word *wp;
|
---|
97 |
|
---|
98 | fprintf (output_file, "r %s\n", p);
|
---|
99 | wp = word_add (p);
|
---|
100 | wp->ref = -1;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | struct word *define_label (const uchar *p, int ref, const char *msg)
|
---|
105 | {
|
---|
106 | struct word *wp;
|
---|
107 |
|
---|
108 | wp = word_add (p);
|
---|
109 | if (wp->ref != 0)
|
---|
110 | {
|
---|
111 | if (wp->database == NULL || wp->ref != ref)
|
---|
112 | fatal ("%s:%d: %s %s multiply defined", input_fname, line_no, msg, p);
|
---|
113 | }
|
---|
114 | else
|
---|
115 | {
|
---|
116 | wp->ref = ref;
|
---|
117 | if (opt_g)
|
---|
118 | gather_define (wp);
|
---|
119 | }
|
---|
120 | return wp;
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | struct word *use_reference (const uchar *p)
|
---|
125 | {
|
---|
126 | struct word *wp;
|
---|
127 |
|
---|
128 | wp = word_find (p, word_hash (p));
|
---|
129 | if ((wp == NULL || wp->ref == 0) && mode != 'T' && mode != 'L')
|
---|
130 | {
|
---|
131 | if (!opt_g)
|
---|
132 | fatal ("%s:%d: Undefined label: %s", input_fname, line_no, p);
|
---|
133 | gather_reference (p);
|
---|
134 | return NULL;
|
---|
135 | }
|
---|
136 | else
|
---|
137 | return wp;
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /* Misuse the style field of struct word */
|
---|
142 |
|
---|
143 | #define STYLE_UNUSED STYLE_NORMAL
|
---|
144 | #define STYLE_USED STYLE_BOLD
|
---|
145 |
|
---|
146 | void make_global (const uchar *name)
|
---|
147 | {
|
---|
148 | struct word *wdb, *wp;
|
---|
149 | const uchar *p;
|
---|
150 | char *tmp;
|
---|
151 | long n;
|
---|
152 | char database[_MAX_FNAME];
|
---|
153 |
|
---|
154 | open_input (name);
|
---|
155 | init_file ();
|
---|
156 | wdb = NULL;
|
---|
157 | if (!out)
|
---|
158 | {
|
---|
159 | _splitpath (input_fname, NULL, NULL, database, NULL);
|
---|
160 | wdb = word_add (database);
|
---|
161 | }
|
---|
162 | read_line ();
|
---|
163 | while (!end_of_file)
|
---|
164 | {
|
---|
165 | p = input + 1;
|
---|
166 | while (isspace (*p))
|
---|
167 | ++p;
|
---|
168 | switch (input[0])
|
---|
169 | {
|
---|
170 | case 'd':
|
---|
171 | if (!out)
|
---|
172 | {
|
---|
173 | errno = 0;
|
---|
174 | n = strtol (p, &tmp, 10);
|
---|
175 | if (errno != 0 || *tmp != ' ')
|
---|
176 | fatal ("%s:%d: Invalid reference number",
|
---|
177 | input_fname, line_no);
|
---|
178 | p = tmp;
|
---|
179 | while (isspace (*p))
|
---|
180 | ++p;
|
---|
181 | wp = word_add (p);
|
---|
182 | if (wp->ref != 0)
|
---|
183 | fatal ("%s:%d: Label %s already defined",
|
---|
184 | input_fname, line_no, p);
|
---|
185 | wp->ref = (int)n;
|
---|
186 | wp->style = STYLE_UNUSED;
|
---|
187 | wp->database = wdb;
|
---|
188 | }
|
---|
189 | break;
|
---|
190 | case 'r':
|
---|
191 | if (out)
|
---|
192 | {
|
---|
193 | wp = word_find (p, word_hash (p));
|
---|
194 | if (wp == NULL || wp->ref == 0)
|
---|
195 | fatal ("%s:%d: Label %s not defined",
|
---|
196 | input_fname, line_no, p);
|
---|
197 | if (wp->style == STYLE_UNUSED)
|
---|
198 | {
|
---|
199 | fprintf (output_file, "x %d %s %s\n",
|
---|
200 | wp->ref, wp->database->str, p);
|
---|
201 | wp->style = STYLE_USED;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | break;
|
---|
205 | }
|
---|
206 | read_line ();
|
---|
207 | }
|
---|
208 | fclose (input_file);
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | void keywords_keyword (const uchar *s)
|
---|
213 | {
|
---|
214 | uchar word[512], *d;
|
---|
215 |
|
---|
216 | while (*s != 0)
|
---|
217 | {
|
---|
218 | d = word;
|
---|
219 | while (*s != 0 && !isspace (*s))
|
---|
220 | *d++ = *s++;
|
---|
221 | *d = 0;
|
---|
222 | write_keyword (word);
|
---|
223 | while (isspace (*s))
|
---|
224 | ++s;
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | void keywords_start (const char *fname)
|
---|
230 | {
|
---|
231 | _splitpath (fname, NULL, NULL, inf_name, NULL);
|
---|
232 | fprintf (output_file, "EXTENSIONS: *\n");
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | void read_xref (const char *fname, struct toc *th)
|
---|
237 | {
|
---|
238 | struct word *wp;
|
---|
239 | uchar database[512], *d;
|
---|
240 | const uchar *p;
|
---|
241 | char *tmp;
|
---|
242 | long n;
|
---|
243 | struct toc *tp;
|
---|
244 |
|
---|
245 | open_input (fname);
|
---|
246 | read_line ();
|
---|
247 | while (!end_of_file)
|
---|
248 | {
|
---|
249 | if (input[0] != 'x')
|
---|
250 | fatal ("%s:%d: Syntax error", fname, line_no);
|
---|
251 | p = input + 1;
|
---|
252 | while (isspace (*p))
|
---|
253 | ++p;
|
---|
254 | errno = 0;
|
---|
255 | n = strtol (p, &tmp, 10);
|
---|
256 | if (errno != 0 || *tmp != ' ')
|
---|
257 | fatal ("%s:%d: Syntax error", fname, line_no);
|
---|
258 | p = tmp;
|
---|
259 | while (isspace (*p))
|
---|
260 | ++p;
|
---|
261 | d = database;
|
---|
262 | while (*p != 0 && !isspace (*p))
|
---|
263 | *d++ = *p++;
|
---|
264 | *d = 0;
|
---|
265 | while (isspace (*p))
|
---|
266 | ++p;
|
---|
267 | if (d == database || *p == 0)
|
---|
268 | fatal ("%s:%d: Syntax error", fname, line_no);
|
---|
269 | if (out)
|
---|
270 | {
|
---|
271 | for (tp = th; tp != NULL; tp = tp->next)
|
---|
272 | if (tp->ref == (int)n)
|
---|
273 | tp->global = TRUE;
|
---|
274 | }
|
---|
275 | else
|
---|
276 | {
|
---|
277 | wp = word_add (p);
|
---|
278 | wp->database = word_add (database);
|
---|
279 | wp->ref = (int)n;
|
---|
280 | }
|
---|
281 | read_line ();
|
---|
282 | }
|
---|
283 | fclose (input_file);
|
---|
284 | }
|
---|