OSDN Git Service

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