1 /*
2 * Copyright (c) 1998-2002, Darren Hiebert
3 *
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
6 *
7 * External interface to entry.c
8 */
9
10 #include "general.h" /* must always come first */
11
12 #include "entry.h"
13 #include "field_p.h"
14 #include "fmt_p.h"
15 #include "mio.h"
16 #include "options_p.h"
17 #include "ptag_p.h"
18 #include "writer_p.h"
19
20 #include <string.h>
21
22
23 static int writeXrefEntry (tagWriter *writer CTAGS_ATTR_UNUSED,
24 MIO * mio, const tagEntryInfo *const tag,
25 void *clientData CTAGS_ATTR_UNUSED);
26 static int writeXrefPtagEntry (tagWriter *writer, MIO * mio, const ptagDesc *desc,
27 const char *const fileName,
28 const char *const pattern,
29 const char *const parserName,
30 void *clientData);
31
32 tagWriter xrefWriter = {
33 .writeEntry = writeXrefEntry,
34 .writePtagEntry = writeXrefPtagEntry,
35 .printPtagByDefault = false,
36 .preWriteEntry = NULL,
37 .postWriteEntry = NULL,
38 .rescanFailedEntry = NULL,
39 .treatFieldAsFixed = NULL,
40 .defaultFileName = NULL,
41 };
42
writeXrefPtagEntry(tagWriter * writer,MIO * mio,const ptagDesc * desc,const char * const fileName,const char * const pattern,const char * const parserName,void * clientData)43 static int writeXrefPtagEntry (tagWriter *writer, MIO * mio, const ptagDesc *desc,
44 const char *const fileName,
45 const char *const pattern,
46 const char *const parserName,
47 void *clientData)
48 {
49 tagEntryInfo e;
50 vString *name = vStringNewInit(PSEUDO_TAG_PREFIX);
51
52 memset (&e, 0, sizeof(e));
53
54 e.isPseudoTag = 1;
55
56 vStringCatS (name, desc->name);
57 if (parserName)
58 {
59 vStringCatS (name, PSEUDO_TAG_SEPARATOR);
60 vStringCatS (name, parserName);
61 }
62 e.name = vStringValue (name);
63 e.inputFileName = fileName;
64 e.pattern = pattern;
65
66 int length = writeXrefEntry (writer, mio, &e, clientData);
67
68 vStringDelete (name);
69
70 return length;
71 }
72
writeXrefEntry(tagWriter * writer CTAGS_ATTR_UNUSED,MIO * mio,const tagEntryInfo * const tag,void * clientData CTAGS_ATTR_UNUSED)73 static int writeXrefEntry (tagWriter *writer CTAGS_ATTR_UNUSED,
74 MIO * mio, const tagEntryInfo *const tag,
75 void *clientData CTAGS_ATTR_UNUSED)
76 {
77 int length;
78 static fmtElement *fmt1;
79 static fmtElement *fmt2;
80
81 if (Option.customXfmt)
82 length = fmtPrint (Option.customXfmt, mio, tag);
83 else
84 {
85 if (tag->isFileEntry)
86 return 0;
87
88 if (Option.tagFileFormat == 1)
89 {
90 if (fmt1 == NULL)
91 fmt1 = fmtNew ("%-16N %4n %-16F %C");
92 length = fmtPrint (fmt1, mio, tag);
93 }
94 else
95 {
96 if (fmt2 == NULL)
97 fmt2 = fmtNew ("%-16N %-10K %4n %-16F %C");
98 length = fmtPrint (fmt2, mio, tag);
99 }
100 }
101
102 mio_putc (mio, '\n');
103 length++;
104
105 return length;
106 }
107