Copyright header fixes...
[anjuta-git-plugin.git] / tagmanager / entry.c
blob38629e686e145ec6953270bbfb1e2b2eb709c68e
1 /*
2 * $Id$
4 * Copyright (c) 1996-2002, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for creating tag entries.
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
17 #include <string.h>
18 #include <ctype.h> /* to define isspace () */
19 #include <errno.h>
21 #if defined (HAVE_SYS_TYPES_H)
22 # include <sys/types.h> /* to declare off_t on some hosts */
23 #endif
24 #if defined (HAVE_TYPES_H)
25 # include <types.h> /* to declare off_t on some hosts */
26 #endif
27 #if defined (HAVE_UNISTD_H)
28 # include <unistd.h> /* to declare close (), ftruncate (), truncate () */
29 #endif
31 /* These header files provide for the functions necessary to do file
32 * truncation.
34 #ifdef HAVE_FCNTL_H
35 # include <fcntl.h>
36 #endif
37 #ifdef HAVE_IO_H
38 # include <io.h>
39 #endif
41 #include "debug.h"
42 #include "ctags.h"
43 #include "entry.h"
44 #include "main.h"
45 #include "options.h"
46 #include "read.h"
47 #include "routines.h"
48 #include "sort.h"
49 #include "strlist.h"
52 * MACROS
54 #define PSEUDO_TAG_PREFIX "!_"
56 #define includeExtensionFlags() (Option.tagFileFormat > 1)
59 * Portability defines
61 #if !defined(HAVE_TRUNCATE) && !defined(HAVE_FTRUNCATE) && !defined(HAVE_CHSIZE)
62 # define USE_REPLACEMENT_TRUNCATE
63 #endif
65 /* Hack for rediculous practice of Microsoft Visual C++.
67 #if defined (WIN32) && defined (_MSC_VER)
68 # define chsize _chsize
69 # define open _open
70 # define close _close
71 # define O_RDWR _O_RDWR
72 #endif
75 * DATA DEFINITIONS
78 tagFile TagFile = {
79 NULL, /* tag file name */
80 NULL, /* tag file directory (absolute) */
81 NULL, /* file pointer */
82 { 0, 0 }, /* numTags */
83 { 0, 0, 0 }, /* max */
84 { NULL, NULL, 0 }, /* etags */
85 NULL /* vLine */
88 static boolean TagsToStdout = FALSE;
91 * FUNCTION PROTOTYPES
93 #ifdef NEED_PROTO_TRUNCATE
94 extern int truncate (const char *path, off_t length);
95 #endif
97 #ifdef NEED_PROTO_FTRUNCATE
98 extern int ftruncate (int fd, off_t length);
99 #endif
102 * FUNCTION DEFINITIONS
105 extern void freeTagFileResources (void)
107 if (TagFile.directory != NULL)
108 eFree (TagFile.directory);
109 vStringDelete (TagFile.vLine);
112 extern const char *tagFileName (void)
114 return TagFile.name;
118 * Pseudo tag support
121 static void rememberMaxLengths (const size_t nameLength, const size_t lineLength)
123 if (nameLength > TagFile.max.tag)
124 TagFile.max.tag = nameLength;
126 if (lineLength > TagFile.max.line)
127 TagFile.max.line = lineLength;
130 static void writePseudoTag (
131 const char *const tagName,
132 const char *const fileName,
133 const char *const pattern)
135 const int length = fprintf (
136 TagFile.fp, "%s%s\t%s\t/%s/\n",
137 PSEUDO_TAG_PREFIX, tagName, fileName, pattern);
138 ++TagFile.numTags.added;
139 rememberMaxLengths (strlen (tagName), (size_t) length);
142 static void addPseudoTags (void)
144 if (! Option.xref)
146 char format [11];
147 const char *formatComment = "unknown format";
149 sprintf (format, "%u", Option.tagFileFormat);
151 if (Option.tagFileFormat == 1)
152 formatComment = "original ctags format";
153 else if (Option.tagFileFormat == 2)
154 formatComment =
155 "extended format; --format=1 will not append ;\" to lines";
157 writePseudoTag ("TAG_FILE_FORMAT", format, formatComment);
158 writePseudoTag ("TAG_FILE_SORTED",
159 Option.sorted == SO_FOLDSORTED ? "2" :
160 (Option.sorted == SO_SORTED ? "1" : "0"),
161 "0=unsorted, 1=sorted, 2=foldcase");
162 writePseudoTag ("TAG_PROGRAM_AUTHOR", AUTHOR_NAME, AUTHOR_EMAIL);
163 writePseudoTag ("TAG_PROGRAM_NAME", PROGRAM_NAME, "");
164 writePseudoTag ("TAG_PROGRAM_URL", PROGRAM_URL, "official site");
165 writePseudoTag ("TAG_PROGRAM_VERSION", PROGRAM_VERSION, "");
169 static void updateSortedFlag (
170 const char *const line, FILE *const fp, fpos_t startOfLine)
172 const char *const tab = strchr (line, '\t');
174 if (tab != NULL)
176 const long boolOffset = tab - line + 1; /* where it should be */
178 if (line [boolOffset] == '0' || line [boolOffset] == '1')
180 fpos_t nextLine;
182 if (fgetpos (fp, &nextLine) == -1 || fsetpos (fp, &startOfLine) == -1)
183 /*error (WARNING, "Failed to update 'sorted' pseudo-tag");*/
184 return;
185 else
187 fpos_t flagLocation;
188 int c, d;
191 c = fgetc (fp);
192 while (c != '\t' && c != '\n');
193 fgetpos (fp, &flagLocation);
194 d = fgetc (fp);
195 if (c == '\t' && (d == '0' || d == '1') &&
196 d != (int) Option.sorted)
198 fsetpos (fp, &flagLocation);
199 fputc (Option.sorted == SO_FOLDSORTED ? '2' :
200 (Option.sorted == SO_SORTED ? '1' : '0'), fp);
202 fsetpos (fp, &nextLine);
208 /* Look through all line beginning with "!_TAG_FILE", and update those which
209 * require it.
211 static long unsigned int updatePseudoTags (FILE *const fp)
213 enum { maxEntryLength = 20 };
214 char entry [maxEntryLength + 1];
215 unsigned long linesRead = 0;
216 fpos_t startOfLine;
217 size_t entryLength;
218 const char *line;
220 sprintf (entry, "%sTAG_FILE", PSEUDO_TAG_PREFIX);
221 entryLength = strlen (entry);
222 Assert (entryLength < maxEntryLength);
224 fgetpos (fp, &startOfLine);
225 line = readLine (TagFile.vLine, fp);
226 while (line != NULL && line [0] == entry [0])
228 ++linesRead;
229 if (strncmp (line, entry, entryLength) == 0)
231 char tab, classType [16];
233 if (sscanf (line + entryLength, "%15s%c", classType, &tab) == 2 &&
234 tab == '\t')
236 if (strcmp (classType, "_SORTED") == 0)
237 updateSortedFlag (line, fp, startOfLine);
239 fgetpos (fp, &startOfLine);
241 line = readLine (TagFile.vLine, fp);
243 while (line != NULL) /* skip to end of file */
245 ++linesRead;
246 line = readLine (TagFile.vLine, fp);
248 return linesRead;
252 * Tag file management
255 static boolean isValidTagAddress (const char *const excmd)
257 boolean isValid = FALSE;
259 if (strchr ("/?", excmd [0]) != NULL)
260 isValid = TRUE;
261 else
263 char *address = xMalloc (strlen (excmd) + 1, char);
264 if (sscanf (excmd, "%[^;\n]", address) == 1 &&
265 strspn (address,"0123456789") == strlen (address))
266 isValid = TRUE;
267 eFree (address);
269 return isValid;
272 static boolean isCtagsLine (const char *const line)
274 enum fieldList { TAG, TAB1, SRC_FILE, TAB2, EXCMD, NUM_FIELDS };
275 boolean ok = FALSE; /* we assume not unless confirmed */
276 const size_t fieldLength = strlen (line) + 1;
277 char *const fields = xMalloc (NUM_FIELDS * fieldLength, char);
279 if (fields == NULL)
280 /* error (FATAL, "Cannot analyze tag file");*/
281 return FALSE;
282 else
284 #define field(x) (fields + ((size_t) (x) * fieldLength))
286 const int numFields = sscanf (
287 line, "%[^\t]%[\t]%[^\t]%[\t]%[^\r\n]",
288 field (TAG), field (TAB1), field (SRC_FILE),
289 field (TAB2), field (EXCMD));
291 /* There must be exactly five fields: two tab fields containing
292 * exactly one tab each, the tag must not begin with "#", and the
293 * file name should not end with ";", and the excmd must be
294 * accceptable.
296 * These conditions will reject tag-looking lines like:
297 * int a; <C-comment>
298 * #define LABEL <C-comment>
300 if (numFields == NUM_FIELDS &&
301 strlen (field (TAB1)) == 1 &&
302 strlen (field (TAB2)) == 1 &&
303 field (TAG) [0] != '#' &&
304 field (SRC_FILE) [strlen (field (SRC_FILE)) - 1] != ';' &&
305 isValidTagAddress (field (EXCMD)))
306 ok = TRUE;
308 eFree (fields);
310 return ok;
313 static boolean isEtagsLine (const char *const line)
315 boolean result = FALSE;
316 if (line [0] == '\f')
317 result = (boolean) (line [1] == '\n' || line [1] == '\r');
318 return result;
321 static boolean isTagFile (const char *const filename)
323 boolean ok = FALSE; /* we assume not unless confirmed */
324 FILE *const fp = fopen (filename, "rb");
326 if (fp == NULL && errno == ENOENT)
327 ok = TRUE;
328 else if (fp != NULL)
330 const char *line = readLine (TagFile.vLine, fp);
332 if (line == NULL)
333 ok = TRUE;
334 else
335 ok = (boolean) (isCtagsLine (line) || isEtagsLine (line));
336 fclose (fp);
338 return ok;
341 extern void copyBytes (FILE* const fromFp, FILE* const toFp, const long size)
343 enum { BufferSize = 1000 };
344 long toRead, numRead;
345 char* buffer = xMalloc (BufferSize, char);
346 long remaining = size;
349 toRead = (0 < remaining && remaining < BufferSize) ?
350 remaining : (long) BufferSize;
351 numRead = fread (buffer, (size_t) 1, (size_t) toRead, fromFp);
352 if (fwrite (buffer, (size_t)1, (size_t)numRead, toFp) < (size_t)numRead)
353 /* error (FATAL | PERROR, "cannot complete write");*/
354 return;
355 if (remaining > 0)
356 remaining -= numRead;
357 } while (numRead == toRead && remaining != 0);
358 eFree (buffer);
361 extern void copyFile (const char *const from, const char *const to, const long size)
363 FILE* const fromFp = fopen (from, "rb");
364 if (fromFp == NULL)
365 /*error (FATAL | PERROR, "cannot open file to copy");*/
366 return;
367 else
369 FILE* const toFp = fopen (to, "wb");
370 if (toFp == NULL)
371 /*error (FATAL | PERROR, "cannot open copy destination");*/
372 return;
373 else
375 copyBytes (fromFp, toFp, size);
376 fclose (toFp);
378 fclose (fromFp);
382 extern void openTagFile (void)
384 setDefaultTagFileName ();
385 TagsToStdout = isDestinationStdout ();
387 if (TagFile.vLine == NULL)
388 TagFile.vLine = vStringNew ();
390 /* Open the tags file.
392 if (TagsToStdout)
393 TagFile.fp = tempFile ("w", &TagFile.name);
394 else
396 boolean fileExists;
398 setDefaultTagFileName ();
399 TagFile.name = eStrdup (Option.tagFileName);
400 fileExists = doesFileExist (TagFile.name);
401 if (fileExists && ! isTagFile (TagFile.name))
402 /*error (FATAL,
403 "\"%s\" doesn't look like a tag file; I refuse to overwrite it.",
404 TagFile.name);*/
405 return;
407 if (Option.etags)
409 if (Option.append && fileExists)
410 TagFile.fp = fopen (TagFile.name, "a+b");
411 else
412 TagFile.fp = fopen (TagFile.name, "w+b");
414 else
416 if (Option.append && fileExists)
418 TagFile.fp = fopen (TagFile.name, "r+");
419 if (TagFile.fp != NULL)
421 TagFile.numTags.prev = updatePseudoTags (TagFile.fp);
422 fclose (TagFile.fp);
423 TagFile.fp = fopen (TagFile.name, "a+");
426 else
428 TagFile.fp = fopen (TagFile.name, "w");
429 if (TagFile.fp != NULL)
430 addPseudoTags ();
433 if (TagFile.fp == NULL)
435 /* error (FATAL | PERROR, "cannot open tag file");*/
436 return;
439 if (TagsToStdout)
440 TagFile.directory = eStrdup (CurrentDirectory);
441 else
442 TagFile.directory = absoluteDirname (TagFile.name);
445 #ifdef USE_REPLACEMENT_TRUNCATE
447 /* Replacement for missing library function.
449 static int replacementTruncate (const char *const name, const long size)
451 char *tempName = NULL;
452 FILE *fp = tempFile ("w", &tempName);
453 fclose (fp);
454 copyFile (name, tempName, size);
455 copyFile (tempName, name, WHOLE_FILE);
456 remove (tempName);
457 eFree (tempName);
459 return 0;
462 #endif
464 static void sortTagFile (void)
466 if (TagFile.numTags.added > 0L)
468 if (Option.sorted != SO_UNSORTED)
470 verbose ("sorting tag file\n");
471 #ifdef EXTERNAL_SORT
472 externalSortTags (TagsToStdout);
473 #else
474 internalSortTags (TagsToStdout);
475 #endif
477 else if (TagsToStdout)
478 catFile (tagFileName ());
480 if (TagsToStdout)
481 remove (tagFileName ()); /* remove temporary file */
484 static void resizeTagFile (const long newSize)
486 int result;
488 #ifdef USE_REPLACEMENT_TRUNCATE
489 result = replacementTruncate (TagFile.name, newSize);
490 #else
491 # ifdef HAVE_TRUNCATE
492 result = truncate (TagFile.name, (off_t) newSize);
493 # else
494 const int fd = open (TagFile.name, O_RDWR);
496 if (fd == -1)
497 result = -1;
498 else
500 # ifdef HAVE_FTRUNCATE
501 result = ftruncate (fd, (off_t) newSize);
502 # else
503 # ifdef HAVE_CHSIZE
504 result = chsize (fd, newSize);
505 # endif
506 # endif
507 close (fd);
509 # endif
510 #endif
511 if (result == -1)
512 fprintf (errout, "Cannot shorten tag file: errno = %d\n", errno);
515 static void writeEtagsIncludes (FILE *const fp)
517 if (Option.etagsInclude)
519 unsigned int i;
520 for (i = 0 ; i < stringListCount (Option.etagsInclude) ; ++i)
522 vString *item = stringListItem (Option.etagsInclude, i);
523 fprintf (fp, "\f\n%s,include\n", vStringValue (item));
528 extern void closeTagFile (const boolean resize)
530 long desiredSize, size;
532 if (Option.etags)
533 writeEtagsIncludes (TagFile.fp);
534 desiredSize = ftell (TagFile.fp);
535 fseek (TagFile.fp, 0L, SEEK_END);
536 size = ftell (TagFile.fp);
537 fclose (TagFile.fp);
538 if (resize && desiredSize < size)
540 DebugStatement (
541 debugPrintf (DEBUG_STATUS, "shrinking %s from %ld to %ld bytes\n",
542 TagFile.name, size, desiredSize); )
543 resizeTagFile (desiredSize);
545 sortTagFile ();
546 eFree (TagFile.name);
547 TagFile.name = NULL;
550 extern void beginEtagsFile (void)
552 TagFile.etags.fp = tempFile ("w+b", &TagFile.etags.name);
553 TagFile.etags.byteCount = 0;
556 extern void endEtagsFile (const char *const name)
558 const char *line;
560 fprintf (TagFile.fp, "\f\n%s,%ld\n", name, (long) TagFile.etags.byteCount);
561 if (TagFile.etags.fp != NULL)
563 rewind (TagFile.etags.fp);
564 while ((line = readLine (TagFile.vLine, TagFile.etags.fp)) != NULL)
565 fputs (line, TagFile.fp);
566 fclose (TagFile.etags.fp);
567 remove (TagFile.etags.name);
568 eFree (TagFile.etags.name);
569 TagFile.etags.fp = NULL;
570 TagFile.etags.name = NULL;
575 * Tag entry management
578 /* This function copies the current line out to a specified file. It has no
579 * effect on the fileGetc () function. During copying, any '\' characters
580 * are doubled and a leading '^' or trailing '$' is also quoted. End of line
581 * characters (line feed or carriage return) are dropped.
583 static size_t writeSourceLine (FILE *const fp, const char *const line)
585 size_t length = 0;
586 const char *p;
588 /* Write everything up to, but not including, a line end character.
590 for (p = line ; *p != '\0' ; ++p)
592 const int next = *(p + 1);
593 const int c = *p;
595 if (c == CRETURN || c == NEWLINE)
596 break;
598 /* If character is '\', or a terminal '$', then quote it.
600 if (c == BACKSLASH || c == (Option.backward ? '?' : '/') ||
601 (c == '$' && (next == NEWLINE || next == CRETURN)))
603 putc (BACKSLASH, fp);
604 ++length;
606 putc (c, fp);
607 ++length;
609 return length;
612 /* Writes "line", stripping leading and duplicate white space.
614 static size_t writeCompactSourceLine (FILE *const fp, const char *const line)
616 boolean lineStarted = FALSE;
617 size_t length = 0;
618 const char *p;
619 int c;
621 /* Write everything up to, but not including, the newline.
623 for (p = line, c = *p ; c != NEWLINE && c != '\0' ; c = *++p)
625 if (lineStarted || ! isspace (c)) /* ignore leading spaces */
627 lineStarted = TRUE;
628 if (isspace (c))
630 int next;
632 /* Consume repeating white space.
634 while (next = *(p+1) , isspace (next) && next != NEWLINE)
635 ++p;
636 c = ' '; /* force space character for any white space */
638 if (c != CRETURN || *(p + 1) != NEWLINE)
640 putc (c, fp);
641 ++length;
645 return length;
648 static int writeXrefEntry (const tagEntryInfo *const tag)
650 const char *const line =
651 readSourceLine (TagFile.vLine, tag->filePosition, NULL);
652 int length;
654 if (Option.tagFileFormat == 1)
655 length = fprintf (TagFile.fp, "%-16s %4lu %-16s ", tag->name,
656 tag->lineNumber, tag->sourceFileName);
657 else
658 length = fprintf (TagFile.fp, "%-16s %-10s %4lu %-16s ", tag->name,
659 tag->kindName, tag->lineNumber, tag->sourceFileName);
661 length += writeCompactSourceLine (TagFile.fp, line);
662 putc (NEWLINE, TagFile.fp);
663 ++length;
665 return length;
668 /* Truncates the text line containing the tag at the character following the
669 * tag, providing a character which designates the end of the tag.
671 static void truncateTagLine (
672 char *const line, const char *const token, const boolean discardNewline)
674 char *p = strstr (line, token);
676 if (p != NULL)
678 p += strlen (token);
679 if (*p != '\0' && ! (*p == '\n' && discardNewline))
680 ++p; /* skip past character terminating character */
681 *p = '\0';
685 static int writeEtagsEntry (const tagEntryInfo *const tag)
687 int length;
689 if (tag->isFileEntry)
690 length = fprintf (TagFile.etags.fp, "\177%s\001%lu,0\n",
691 tag->name, tag->lineNumber);
692 else
694 long seekValue;
695 char *const line =
696 readSourceLine (TagFile.vLine, tag->filePosition, &seekValue);
698 if (tag->truncateLine)
699 truncateTagLine (line, tag->name, TRUE);
700 else
701 line [strlen (line) - 1] = '\0';
703 length = fprintf (TagFile.etags.fp, "%s\177%s\001%lu,%ld\n", line,
704 tag->name, tag->lineNumber, seekValue);
706 TagFile.etags.byteCount += length;
708 return length;
711 static int addExtensionFields (const tagEntryInfo *const tag)
713 const char* const kindKey = Option.extensionFields.kindKey ? "kind:" : "";
714 boolean first = TRUE;
715 const char* separator = ";\"";
716 const char* const empty = "";
717 int length = 0;
718 /* "sep" returns a value only the first time it is evaluated */
719 #define sep (first ? (first = FALSE, separator) : empty)
721 if (tag->kindName != NULL && (Option.extensionFields.kindLong ||
722 (Option.extensionFields.kind && tag->kind == '\0')))
723 length += fprintf (TagFile.fp,"%s\t%s%s", sep, kindKey, tag->kindName);
724 else if (tag->kind != '\0' && (Option.extensionFields.kind ||
725 (Option.extensionFields.kindLong && tag->kindName == NULL)))
726 length += fprintf (TagFile.fp, "%s\t%s%c", sep, kindKey, tag->kind);
728 if (Option.extensionFields.lineNumber)
729 length += fprintf (TagFile.fp, "%s\tline:%ld", sep, tag->lineNumber);
731 if (Option.extensionFields.language && tag->language != NULL)
732 length += fprintf (TagFile.fp, "%s\tlanguage:%s", sep, tag->language);
734 if (Option.extensionFields.scope &&
735 tag->extensionFields.scope [0] != NULL &&
736 tag->extensionFields.scope [1] != NULL)
737 length += fprintf (TagFile.fp, "%s\t%s:%s", sep,
738 tag->extensionFields.scope [0],
739 tag->extensionFields.scope [1]);
741 if (Option.extensionFields.typeRef &&
742 tag->extensionFields.typeRef [0] != NULL &&
743 tag->extensionFields.typeRef [1] != NULL)
744 length += fprintf (TagFile.fp, "%s\ttyperef:%s:%s", sep,
745 tag->extensionFields.typeRef [0],
746 tag->extensionFields.typeRef [1]);
748 if (Option.extensionFields.fileScope && tag->isFileScope)
749 length += fprintf (TagFile.fp, "%s\tfile:", sep);
751 if (Option.extensionFields.inheritance &&
752 tag->extensionFields.inheritance != NULL)
753 length += fprintf (TagFile.fp, "%s\tinherits:%s", sep,
754 tag->extensionFields.inheritance);
756 if (Option.extensionFields.access && tag->extensionFields.access != NULL)
757 length += fprintf (TagFile.fp, "%s\taccess:%s", sep,
758 tag->extensionFields.access);
760 if (Option.extensionFields.implementation &&
761 tag->extensionFields.implementation != NULL)
762 length += fprintf (TagFile.fp, "%s\timplementation:%s", sep,
763 tag->extensionFields.implementation);
765 if (Option.extensionFields.signature &&
766 tag->extensionFields.signature != NULL)
767 length += fprintf (TagFile.fp, "%s\tsignature:%s", sep,
768 tag->extensionFields.signature);
770 return length;
771 #undef sep
774 static int writePatternEntry (const tagEntryInfo *const tag)
776 char *const line = readSourceLine (TagFile.vLine, tag->filePosition, NULL);
777 const int searchChar = Option.backward ? '?' : '/';
778 boolean newlineTerminated;
779 int length = 0;
781 if (tag->truncateLine)
782 truncateTagLine (line, tag->name, FALSE);
783 newlineTerminated = (boolean) (line [strlen (line) - 1] == '\n');
785 length += fprintf (TagFile.fp, "%c^", searchChar);
786 length += writeSourceLine (TagFile.fp, line);
787 length += fprintf (TagFile.fp, "%s%c", newlineTerminated ? "$":"", searchChar);
789 return length;
792 static int writeLineNumberEntry (const tagEntryInfo *const tag)
794 return fprintf (TagFile.fp, "%lu", tag->lineNumber);
797 static int writeCtagsEntry (const tagEntryInfo *const tag)
799 int length;
800 if (tag == NULL || tag->name == NULL ||
801 tag->sourceFileName == NULL) {
802 printf("**warning**: returning -1 from writeCtagsEntry()\n");
803 return -1;
806 length = fprintf (TagFile.fp, "%s\t%s\t",
807 tag->name, tag->sourceFileName);
809 if (tag->lineNumberEntry)
810 length += writeLineNumberEntry (tag);
811 else
812 length += writePatternEntry (tag);
814 if (includeExtensionFlags ())
815 length += addExtensionFields (tag);
817 length += fprintf (TagFile.fp, "\n");
819 return length;
822 extern void makeTagEntry (const tagEntryInfo *const tag)
824 Assert (tag->name != NULL);
825 if (tag->name [0] == '\0')
826 /*error (WARNING, "ignoring null tag in %s", vStringValue (File.name));*/
827 return;
828 else
830 int length = 0;
832 DebugStatement ( debugEntry (tag); )
834 if (NULL != TagEntryFunction) {
835 length = TagEntryFunction(tag);
837 else if (Option.xref)
839 if (! tag->isFileEntry)
840 length = writeXrefEntry (tag);
842 else if (Option.etags) {
843 // it should crash here. Infact no TagFile.fp is initialized right now.
844 // We're using ctags within tagmanager.
845 length = writeEtagsEntry (tag);
847 else {
848 length = writeCtagsEntry (tag);
851 ++TagFile.numTags.added;
852 rememberMaxLengths (strlen (tag->name), (size_t) length);
853 DebugStatement ( fflush (TagFile.fp); )
857 extern void initTagEntry (tagEntryInfo *const e, const char *const name)
859 Assert (File.source.name != NULL);
860 memset (e, 0, sizeof (tagEntryInfo));
861 e->lineNumberEntry = (boolean) (Option.locate == EX_LINENUM);
862 e->lineNumber = getSourceLineNumber ();
863 e->language = getSourceLanguageName ();
864 e->filePosition = getInputFilePosition ();
865 e->sourceFileName = getSourceFileTagPath ();
866 e->name = name;
869 /* vi:set tabstop=4 shiftwidth=4: */