~kvik/ctags

fd1d6bfcbec103ccba27deeb5ac8fee6fe2acbfc — kvik 2 years ago acfd944 front
entry: add the 'L' extension field, holding the matching source text.

The only (reasonable) way to get the tag's source line was to use the
xref output format.  However, this format is fixed and doesn't allow
extension fields to be specified.

A more reasonable solution is to add the extension field to the tags
file format, holding the matched source line.  This can be used by
external tags file readers, along with any other fields they may need.
3 files changed, 12 insertions(+), 2 deletions(-)

M entry.c
M options.c
M options.h
M entry.c => entry.c +6 -0
@@ 765,6 765,12 @@ static int addExtensionFields (const tagEntryInfo *const tag)
			tag->extensionFields.signature != NULL)
		length += fprintf (TagFile.fp, "%s\tsignature:%s", sep,
				tag->extensionFields.signature);
				
	if (Option.extensionFields.line) {
		length += fprintf(TagFile.fp, "%s\tline:", sep);
		length += writeCompactSourceLine(TagFile.fp,
			readSourceLine (TagFile.vLine, tag->filePosition, NULL));
	}

	return length;
#undef sep

M options.c => options.c +5 -2
@@ 119,7 119,8 @@ optionValues Option = {
		FALSE,  /* -fields=n */
		TRUE,   /* -fields=s */
		FALSE,  /* -fields=S */
		TRUE    /* -fields=t */
		TRUE,   /* -fields=t */
		FALSE,  /* -fields=L */
	},
	NULL,       /* -I */
	FALSE,      /* -a */


@@ 210,7 211,7 @@ static optionDescription LongOptionDescription [] = {
 {1,"  --extra=[+|-]flags"},
 {1,"      Include extra tag entries for selected information (flags: \"fq\")."},
 {1,"  --fields=[+|-]flags"},
 {1,"      Include selected extension fields (flags: \"afmikKlnsStz\") [fks]."},
 {1,"      Include selected extension fields (flags: \"afmikKlLnsStz\") [fks]."},
 {1,"  --file-scope=[yes|no]"},
 {1,"       Should tags scoped only for a single file (e.g. \"static\" tags"},
 {1,"       be included in the output [yes]?"},


@@ 851,6 852,7 @@ static void processFieldsOption (
		field->language         = FALSE;
		field->scope            = FALSE;
		field->typeRef          = FALSE;
		field->line             = FALSE;
	}
	while ((c = *p++) != '\0') switch (c)
	{


@@ 864,6 866,7 @@ static void processFieldsOption (
		case 'k': field->kind           = mode; break;
		case 'K': field->kindLong       = mode; break;
		case 'l': field->language       = mode; break;
		case 'L': field->line           = mode; break;
		case 'n': field->lineNumber     = mode; break;
		case 's': field->scope          = mode; break;
		case 'S': field->signature      = mode; break;

M options.h => options.h +1 -0
@@ 78,6 78,7 @@ struct sExtFields {  /* extension field content control */
	boolean scope;
	boolean signature;
	boolean typeRef;
	boolean line;
};

/*  This stores the command line options.