cp-tree.def (PTRMEM_CST): New tree node.
[gcc.git] / gcc / cp / xref.c
1 /* Code for handling XREF output from GNU C++.
2 Copyright (C) 1992, 93-97, 1998 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "cp-tree.h"
27 #include "input.h"
28 #include "toplev.h"
29
30 extern char *getpwd PROTO((void));
31
32 /* The character(s) used to join a directory specification (obtained with
33 getwd or equivalent) with a non-absolute file name. */
34
35 #ifndef FILE_NAME_JOINER
36 #define FILE_NAME_JOINER "/"
37 #endif
38
39 /* Nonzero if NAME as a file name is absolute. */
40 #ifndef FILE_NAME_ABSOLUTE_P
41 #define FILE_NAME_ABSOLUTE_P(NAME) (NAME[0] == '/')
42 #endif
43
44 /* For cross referencing. */
45
46 int flag_gnu_xref;
47
48 /************************************************************************/
49 /* */
50 /* Common definitions */
51 /* */
52 /************************************************************************/
53
54 #ifndef TRUE
55 #define TRUE 1
56 #endif
57 #ifndef FALSE
58 #define FALSE 0
59 #endif
60
61 #define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
62
63
64 /* Return a malloc'd copy of STR. */
65 #define SALLOC(str) \
66 ((char *) ((str) == NULL ? NULL \
67 : (char *) strcpy ((char *) malloc (strlen ((str)) + 1), (str))))
68 #define SFREE(str) (str != NULL && (free(str),0))
69
70 #define STREQL(s1,s2) (strcmp((s1),(s2)) == 0)
71 #define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0)
72 #define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0)
73 #define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0)
74 #define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0)
75 #define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0)
76
77 /************************************************************************/
78 /* */
79 /* Type definitions */
80 /* */
81 /************************************************************************/
82
83
84 typedef struct _XREF_FILE * XREF_FILE;
85 typedef struct _XREF_SCOPE * XREF_SCOPE;
86
87 typedef struct _XREF_FILE
88 {
89 char *name;
90 char *outname;
91 XREF_FILE next;
92 } XREF_FILE_INFO;
93
94 typedef struct _XREF_SCOPE
95 {
96 int gid;
97 int lid;
98 XREF_FILE file;
99 int start;
100 XREF_SCOPE outer;
101 } XREF_SCOPE_INFO;
102
103 /************************************************************************/
104 /* */
105 /* Local storage */
106 /* */
107 /************************************************************************/
108
109 static char doing_xref = 0;
110 static FILE * xref_file = NULL;
111 static char xref_name[1024];
112 static XREF_FILE all_files = NULL;
113 static char * wd_name = NULL;
114 static XREF_SCOPE cur_scope = NULL;
115 static int scope_ctr = 0;
116 static XREF_FILE last_file = NULL;
117 static tree last_fndecl = NULL;
118
119 /************************************************************************/
120 /* */
121 /* Forward definitions */
122 /* */
123 /************************************************************************/
124 static void gen_assign PROTO((XREF_FILE, tree));
125 static XREF_FILE find_file PROTO((char *));
126 static char * filename PROTO((XREF_FILE));
127 static char * fctname PROTO((tree));
128 static char * declname PROTO((tree));
129 static void simplify_type PROTO((char *));
130 static char * fixname PROTO((char *, char *));
131 static void open_xref_file PROTO((char *));
132
133 /* Start cross referencing. FILE is the name of the file we xref. */
134
135 void
136 GNU_xref_begin (file)
137 char *file;
138 {
139 doing_xref = 1;
140
141 if (file != NULL && STRNEQ (file,"-"))
142 {
143 open_xref_file(file);
144 GNU_xref_file(file);
145 }
146 }
147
148 /* Finish cross-referencing. ERRCNT is the number of errors
149 we encountered. */
150
151 void
152 GNU_xref_end (ect)
153 int ect;
154 {
155 XREF_FILE xf;
156
157 if (!doing_xref) return;
158
159 xf = find_file (input_filename);
160 if (xf == NULL) return;
161
162 while (cur_scope != NULL)
163 GNU_xref_end_scope(cur_scope->gid,0,0,0);
164
165 doing_xref = 0;
166
167 if (xref_file == NULL) return;
168
169 fclose (xref_file);
170
171 xref_file = NULL;
172 all_files = NULL;
173
174 if (ect > 0) unlink (xref_name);
175 }
176
177 /* Write out xref for file named NAME. */
178
179 void
180 GNU_xref_file (name)
181 char *name;
182 {
183 XREF_FILE xf;
184
185 if (!doing_xref || name == NULL) return;
186
187 if (xref_file == NULL)
188 {
189 open_xref_file (name);
190 if (!doing_xref) return;
191 }
192
193 if (all_files == NULL)
194 fprintf(xref_file,"SCP * 0 0 0 0 RESET\n");
195
196 xf = find_file (name);
197 if (xf != NULL) return;
198
199 xf = PALLOC (XREF_FILE_INFO);
200 xf->name = SALLOC (name);
201 xf->next = all_files;
202 all_files = xf;
203
204 if (wd_name == NULL)
205 wd_name = getpwd ();
206
207 if (FILE_NAME_ABSOLUTE_P (name) || ! wd_name)
208 xf->outname = xf->name;
209 else
210 {
211 char *nmbuf
212 = (char *) malloc (strlen (wd_name) + strlen (FILE_NAME_JOINER)
213 + strlen (name) + 1);
214 sprintf (nmbuf, "%s%s%s", wd_name, FILE_NAME_JOINER, name);
215 name = nmbuf;
216 xf->outname = nmbuf;
217 }
218
219 fprintf (xref_file, "FIL %s %s 0\n", name, wd_name);
220
221 filename (xf);
222 fctname (NULL);
223 }
224
225 /* Start a scope identified at level ID. */
226
227 void
228 GNU_xref_start_scope (id)
229 HOST_WIDE_INT id;
230 {
231 XREF_SCOPE xs;
232 XREF_FILE xf;
233
234 if (!doing_xref) return;
235 xf = find_file (input_filename);
236
237 xs = PALLOC (XREF_SCOPE_INFO);
238 xs->file = xf;
239 xs->start = lineno;
240 if (xs->start <= 0) xs->start = 1;
241 xs->gid = id;
242 xs->lid = ++scope_ctr;
243 xs->outer = cur_scope;
244 cur_scope = xs;
245 }
246
247 /* Finish a scope at level ID.
248 INID is ???
249 PRM is ???
250 KEEP is nonzero iff this scope is retained (nonzero if it's
251 a compiler-generated invisible scope).
252 TRNS is ??? */
253
254 void
255 GNU_xref_end_scope (id,inid,prm,keep)
256 HOST_WIDE_INT id;
257 HOST_WIDE_INT inid;
258 int prm,keep;
259 {
260 XREF_FILE xf;
261 XREF_SCOPE xs,lxs,oxs;
262 char *stype;
263
264 if (!doing_xref) return;
265 xf = find_file (input_filename);
266 if (xf == NULL) return;
267
268 lxs = NULL;
269 for (xs = cur_scope; xs != NULL; xs = xs->outer)
270 {
271 if (xs->gid == id) break;
272 lxs = xs;
273 }
274 if (xs == NULL) return;
275
276 if (inid != 0) {
277 for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) {
278 if (oxs->gid == inid) break;
279 }
280 if (oxs == NULL) return;
281 inid = oxs->lid;
282 }
283
284 if (prm == 2) stype = "SUE";
285 else if (prm != 0) stype = "ARGS";
286 else if (keep == 2 || inid != 0) stype = "INTERN";
287 else stype = "EXTERN";
288
289 fprintf (xref_file, "SCP %s %d %d %d ",
290 filename (xf), xs->start, lineno,xs->lid);
291 fprintf (xref_file, HOST_WIDE_INT_PRINT_DEC, inid);
292 fprintf (xref_file, " %s\n", stype);
293
294 if (lxs == NULL) cur_scope = xs->outer;
295 else lxs->outer = xs->outer;
296
297 free (xs);
298 }
299
300 /* Output a reference to NAME in FNDECL. */
301
302 void
303 GNU_xref_ref (fndecl,name)
304 tree fndecl;
305 char *name;
306 {
307 XREF_FILE xf;
308
309 if (!doing_xref) return;
310 xf = find_file (input_filename);
311 if (xf == NULL) return;
312
313 fprintf (xref_file, "REF %s %d %s %s\n",
314 filename (xf), lineno, fctname (fndecl), name);
315 }
316
317 /* Output a reference to DECL in FNDECL. */
318
319 void
320 GNU_xref_decl (fndecl,decl)
321 tree fndecl;
322 tree decl;
323 {
324 XREF_FILE xf,xf1;
325 char *cls = 0;
326 char *name;
327 char buf[10240];
328 int uselin;
329
330 if (!doing_xref) return;
331 xf = find_file (input_filename);
332 if (xf == NULL) return;
333
334 uselin = FALSE;
335
336 if (TREE_CODE (decl) == TYPE_DECL) cls = "TYPEDEF";
337 else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD";
338 else if (TREE_CODE (decl) == VAR_DECL)
339 {
340 if (fndecl == NULL && TREE_STATIC(decl)
341 && TREE_READONLY(decl) && DECL_INITIAL(decl) != 0
342 && !TREE_PUBLIC(decl) && !DECL_EXTERNAL(decl)
343 && DECL_MODE(decl) != BLKmode) cls = "CONST";
344 else if (DECL_EXTERNAL(decl)) cls = "EXTERN";
345 else if (TREE_PUBLIC(decl)) cls = "EXTDEF";
346 else if (TREE_STATIC(decl)) cls = "STATIC";
347 else if (DECL_REGISTER(decl)) cls = "REGISTER";
348 else cls = "AUTO";
349 }
350 else if (TREE_CODE (decl) == PARM_DECL) cls = "PARAM";
351 else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD";
352 else if (TREE_CODE (decl) == CONST_DECL) cls = "CONST";
353 else if (TREE_CODE (decl) == FUNCTION_DECL)
354 {
355 if (DECL_EXTERNAL (decl)) cls = "EXTERN";
356 else if (TREE_PUBLIC (decl)) cls = "EFUNCTION";
357 else cls = "SFUNCTION";
358 }
359 else if (TREE_CODE (decl) == LABEL_DECL) cls = "LABEL";
360 else if (TREE_CODE (decl) == UNION_TYPE)
361 {
362 cls = "UNIONID";
363 decl = TYPE_NAME (decl);
364 uselin = TRUE;
365 }
366 else if (TREE_CODE (decl) == RECORD_TYPE)
367 {
368 if (CLASSTYPE_DECLARED_CLASS (decl)) cls = "CLASSID";
369 else if (IS_SIGNATURE (decl)) cls = "SIGNATUREID";
370 else cls = "STRUCTID";
371 decl = TYPE_NAME (decl);
372 uselin = TRUE;
373 }
374 else if (TREE_CODE (decl) == ENUMERAL_TYPE)
375 {
376 cls = "ENUMID";
377 decl = TYPE_NAME (decl);
378 uselin = TRUE;
379 }
380 else if (TREE_CODE (decl) == TEMPLATE_DECL)
381 {
382 if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
383 cls = "CLASSTEMP";
384 else if (TREE_CODE (DECL_RESULT (decl)) == FUNCTION_DECL)
385 cls = "FUNCTEMP";
386 else if (TREE_CODE (DECL_RESULT (decl)) == VAR_DECL)
387 cls = "VARTEMP";
388 else
389 my_friendly_abort (358);
390 uselin = TRUE;
391 }
392 else cls = "UNKNOWN";
393
394 if (decl == NULL || DECL_NAME (decl) == NULL) return;
395
396 if (uselin && decl->decl.linenum > 0 && decl->decl.filename != NULL)
397 {
398 xf1 = find_file (decl->decl.filename);
399 if (xf1 != NULL)
400 {
401 lineno = decl->decl.linenum;
402 xf = xf1;
403 }
404 }
405
406 if (DECL_ASSEMBLER_NAME (decl))
407 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
408 else
409 name = IDENTIFIER_POINTER (DECL_NAME (decl));
410
411 strcpy (buf, type_as_string (TREE_TYPE (decl), 0));
412 simplify_type (buf);
413
414 fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n",
415 filename(xf), lineno, name,
416 (cur_scope != NULL ? cur_scope->lid : 0),
417 cls, fctname(fndecl), buf);
418
419 if (STREQL (cls, "STRUCTID") || STREQL (cls, "UNIONID")
420 || STREQL (cls, "SIGNATUREID"))
421 {
422 cls = "CLASSID";
423 fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n",
424 filename(xf), lineno,name,
425 (cur_scope != NULL ? cur_scope->lid : 0),
426 cls, fctname(fndecl), buf);
427 }
428 }
429
430 /* Output a reference to a call to NAME in FNDECL. */
431
432 void
433 GNU_xref_call (fndecl, name)
434 tree fndecl;
435 char *name;
436 {
437 XREF_FILE xf;
438 char buf[1024];
439 char *s;
440
441 if (!doing_xref) return;
442 xf = find_file (input_filename);
443 if (xf == NULL) return;
444 name = fixname (name, buf);
445
446 for (s = name; *s != 0; ++s)
447 if (*s == '_' && s[1] == '_') break;
448 if (*s != 0) GNU_xref_ref (fndecl, name);
449
450 fprintf (xref_file, "CAL %s %d %s %s\n",
451 filename (xf), lineno, name, fctname (fndecl));
452 }
453
454 /* Output cross-reference info about FNDECL. If non-NULL,
455 ARGS are the arguments for the function (i.e., before the FUNCTION_DECL
456 has been fully built). */
457
458 void
459 GNU_xref_function (fndecl, args)
460 tree fndecl;
461 tree args;
462 {
463 XREF_FILE xf;
464 int ct;
465 char buf[1024];
466
467 if (!doing_xref) return;
468 xf = find_file (input_filename);
469 if (xf == NULL) return;
470
471 ct = 0;
472 buf[0] = 0;
473 if (args == NULL) args = DECL_ARGUMENTS (fndecl);
474
475 GNU_xref_decl (NULL, fndecl);
476
477 for ( ; args != NULL; args = TREE_CHAIN (args))
478 {
479 GNU_xref_decl (fndecl,args);
480 if (ct != 0) strcat (buf,",");
481 strcat (buf, declname (args));
482 ++ct;
483 }
484
485 fprintf (xref_file, "PRC %s %d %s %d %d %s\n",
486 filename(xf), lineno, declname(fndecl),
487 (cur_scope != NULL ? cur_scope->lid : 0),
488 ct, buf);
489 }
490
491 /* Output cross-reference info about an assignment to NAME. */
492
493 void
494 GNU_xref_assign(name)
495 tree name;
496 {
497 XREF_FILE xf;
498
499 if (!doing_xref) return;
500 xf = find_file(input_filename);
501 if (xf == NULL) return;
502
503 gen_assign(xf, name);
504 }
505
506 static void
507 gen_assign(xf, name)
508 XREF_FILE xf;
509 tree name;
510 {
511 char *s;
512
513 s = NULL;
514
515 switch (TREE_CODE (name))
516 {
517 case IDENTIFIER_NODE :
518 s = IDENTIFIER_POINTER(name);
519 break;
520 case VAR_DECL :
521 s = declname(name);
522 break;
523 case COMPONENT_REF :
524 gen_assign(xf, TREE_OPERAND(name, 0));
525 gen_assign(xf, TREE_OPERAND(name, 1));
526 break;
527 case INDIRECT_REF :
528 case OFFSET_REF :
529 case ARRAY_REF :
530 case BUFFER_REF :
531 gen_assign(xf, TREE_OPERAND(name, 0));
532 break;
533 case COMPOUND_EXPR :
534 gen_assign(xf, TREE_OPERAND(name, 1));
535 break;
536 default :
537 break;
538 }
539
540 if (s != NULL)
541 fprintf(xref_file, "ASG %s %d %s\n", filename(xf), lineno, s);
542 }
543
544 static char*
545 classname (cls)
546 tree cls;
547 {
548 if (cls && TREE_CODE_CLASS (TREE_CODE (cls)) == 't')
549 cls = TYPE_NAME (cls);
550 if (cls && TREE_CODE_CLASS (TREE_CODE (cls)) == 'd')
551 cls = DECL_NAME (cls);
552 if (cls && TREE_CODE (cls) == IDENTIFIER_NODE)
553 return IDENTIFIER_POINTER (cls);
554 return "?";
555 }
556
557 /* Output cross-reference info about a class hierarchy.
558 CLS is the class type of interest. BASE is a baseclass
559 for CLS. PUB and VIRT give the access info about
560 the class derivation. FRND is nonzero iff BASE is a friend
561 of CLS.
562
563 ??? Needs to handle nested classes. */
564
565 void
566 GNU_xref_hier(cls, base, pub, virt, frnd)
567 tree cls;
568 tree base;
569 int pub;
570 int virt;
571 int frnd;
572 {
573 XREF_FILE xf;
574
575 if (!doing_xref) return;
576 xf = find_file(input_filename);
577 if (xf == NULL) return;
578
579 fprintf(xref_file, "HIE %s %d %s %s %d %d %d\n",
580 filename(xf), lineno, classname (cls), classname (base),
581 pub, virt, frnd);
582 }
583
584 /* Output cross-reference info about class members. CLS
585 is the containing type; FLD is the class member. */
586
587 void
588 GNU_xref_member(cls, fld)
589 tree cls;
590 tree fld;
591 {
592 XREF_FILE xf;
593 char *prot;
594 int confg, pure;
595 char *d;
596 #ifdef XREF_SHORT_MEMBER_NAMES
597 int i;
598 #endif
599 char buf[1024], bufa[1024];
600
601 if (!doing_xref) return;
602 xf = find_file(fld->decl.filename);
603 if (xf == NULL) return;
604
605 if (TREE_PRIVATE (fld)) prot = "PRIVATE";
606 else if (TREE_PROTECTED(fld)) prot = "PROTECTED";
607 else prot = "PUBLIC";
608
609 confg = 0;
610 if (TREE_CODE (fld) == FUNCTION_DECL && DECL_CONST_MEMFUNC_P(fld))
611 confg = 1;
612 else if (TREE_CODE (fld) == CONST_DECL)
613 confg = 1;
614
615 pure = 0;
616 if (TREE_CODE (fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld))
617 pure = 1;
618
619 d = IDENTIFIER_POINTER(cls);
620 sprintf(buf, "%d%s", (int) strlen(d), d);
621 #ifdef XREF_SHORT_MEMBER_NAMES
622 i = strlen(buf);
623 #endif
624 strcpy(bufa, declname(fld));
625
626 #ifdef XREF_SHORT_MEMBER_NAMES
627 for (p = &bufa[1]; *p != 0; ++p)
628 {
629 if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') {
630 if (strncmp(&p[2], buf, i) == 0) *p = 0;
631 break;
632 }
633 else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') {
634 if (strncmp(&p[3], buf, i) == 0) *p = 0;
635 break;
636 }
637 }
638 #endif
639
640 fprintf(xref_file, "MEM %s %d %s %s %s %d %d %d %d %d %d %d\n",
641 filename(xf), fld->decl.linenum, d, bufa, prot,
642 (TREE_CODE (fld) == FUNCTION_DECL ? 0 : 1),
643 (DECL_INLINE (fld) ? 1 : 0),
644 (DECL_LANG_SPECIFIC(fld) && DECL_FRIEND_P(fld) ? 1 : 0),
645 (DECL_VINDEX(fld) ? 1 : 0),
646 (TREE_STATIC(fld) ? 1 : 0),
647 pure, confg);
648 }
649
650 /* Find file entry given name. */
651
652 static XREF_FILE
653 find_file(name)
654 char *name;
655 {
656 XREF_FILE xf;
657
658 for (xf = all_files; xf != NULL; xf = xf->next) {
659 if (STREQL(name, xf->name)) break;
660 }
661
662 return xf;
663 }
664
665 /* Return filename for output purposes. */
666
667 static char *
668 filename(xf)
669 XREF_FILE xf;
670 {
671 if (xf == NULL) {
672 last_file = NULL;
673 return "*";
674 }
675
676 if (last_file == xf) return "*";
677
678 last_file = xf;
679
680 return xf->outname;
681 }
682
683 /* Return function name for output purposes. */
684
685 static char *
686 fctname(fndecl)
687 tree fndecl;
688 {
689 static char fctbuf[1024];
690 char *s;
691
692 if (fndecl == NULL && last_fndecl == NULL) return "*";
693
694 if (fndecl == NULL)
695 {
696 last_fndecl = NULL;
697 return "*TOP*";
698 }
699
700 if (fndecl == last_fndecl) return "*";
701
702 last_fndecl = fndecl;
703
704 s = declname(fndecl);
705 s = fixname(s, fctbuf);
706
707 return s;
708 }
709
710 /* Return decl name for output purposes. */
711
712 static char *
713 declname(dcl)
714 tree dcl;
715 {
716 if (DECL_NAME (dcl) == NULL) return "?";
717
718 if (DECL_ASSEMBLER_NAME (dcl))
719 return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (dcl));
720 else
721 return IDENTIFIER_POINTER (DECL_NAME (dcl));
722 }
723
724 /* Simplify a type string by removing unneeded parenthesis. */
725
726 static void
727 simplify_type(typ)
728 char *typ;
729 {
730 char *s;
731 int lvl, i;
732
733 i = strlen(typ);
734 while (i > 0 && ISSPACE((unsigned char) typ[i-1])) typ[--i] = 0;
735
736 if (i > 7 && STREQL(&typ[i-5], "const"))
737 {
738 typ[i-5] = 0;
739 i -= 5;
740 }
741
742 if (typ[i-1] != ')') return;
743
744 s = &typ[i-2];
745 lvl = 1;
746 while (*s != 0) {
747 if (*s == ')') ++lvl;
748 else if (*s == '(')
749 {
750 --lvl;
751 if (lvl == 0)
752 {
753 s[1] = ')';
754 s[2] = 0;
755 break;
756 }
757 }
758 --s;
759 }
760
761 if (*s != 0 && s[-1] == ')')
762 {
763 --s;
764 --s;
765 if (*s == '(') s[2] = 0;
766 else if (*s == ':') {
767 while (*s != '(') --s;
768 s[1] = ')';
769 s[2] = 0;
770 }
771 }
772 }
773
774 /* Fixup a function name (take care of embedded spaces). */
775
776 static char *
777 fixname(nam, buf)
778 char *nam;
779 char *buf;
780 {
781 char *s, *t;
782 int fg;
783
784 s = nam;
785 t = buf;
786 fg = 0;
787
788 while (*s != 0)
789 {
790 if (*s == ' ')
791 {
792 *t++ = '\36';
793 ++fg;
794 }
795 else *t++ = *s;
796 ++s;
797 }
798 *t = 0;
799
800 if (fg == 0) return nam;
801
802 return buf;
803 }
804
805 /* Open file for xreffing. */
806
807 static void
808 open_xref_file(file)
809 char *file;
810 {
811 char *s, *t;
812
813 #ifdef XREF_FILE_NAME
814 XREF_FILE_NAME (xref_name, file);
815 #else
816 s = rindex (file, '/');
817 if (s == NULL)
818 sprintf (xref_name, ".%s.gxref", file);
819 else
820 {
821 ++s;
822 strcpy (xref_name, file);
823 t = rindex (xref_name, '/');
824 ++t;
825 *t++ = '.';
826 strcpy (t, s);
827 strcat (t, ".gxref");
828 }
829 #endif /* no XREF_FILE_NAME */
830
831 xref_file = fopen(xref_name, "w");
832
833 if (xref_file == NULL)
834 {
835 error("Can't create cross-reference file `%s'", xref_name);
836 doing_xref = 0;
837 }
838 }