Skip to content

Commit b9fe6fd

Browse files
committed
readtags: add an optoin (-X) for emitting an aggregate tag file
$ ./readtags -t podman.tags -t glibc.tags -t coreutils832.tags -X | tee tags !_READTAGS_INCLUDE podman.tags // !_READTAGS_INCLUDE glibc.tags // !_READTAGS_INCLUDE coreutils832.tags // !_TAG_FILE_FORMAT 2 // !_TAG_FILE_SORTED 1 // !_TAG_OUTPUT_EXCMD pattern // !_TAG_OUTPUT_FILESEP slash // !_TAG_OUTPUT_MODE u-ctags // !_TAG_OUTPUT_VERSION 0.0 /current.age/ !_TAG_PATTERN_LENGTH_LIMIT 0 // !_TAG_PROC_CWD /home/yamato/var/ctags-github // !_TAG_PROGRAM_AUTHOR Universal Ctags Team // !_TAG_PROGRAM_NAME readtags /with -X option/ !_TAG_PROGRAM_URL https://ctags.io/ /official site/ !_TAG_PROGRAM_VERSION 0.0.0 /TODO/ $ ./readtags -A rootful rootful /home/yamato/var/podman/pkg/machine/e2e/config_init_test.go /^ rootful bool$/ rootful /home/yamato/var/podman/pkg/machine/e2e/config_set_test.go /^ rootful bool$/ $ ./readtags -A rootless rootless /home/yamato/var/podman/pkg/rootless/rootless.go /^package rootless$/ rootless /home/yamato/var/podman/pkg/rootless/rootless_freebsd.go /^package rootless$/ rootless /home/yamato/var/podman/pkg/rootless/rootless_linux.go /^package rootless$/ rootless /home/yamato/var/podman/pkg/rootless/rootless_test.go /^package rootless$/ rootless /home/yamato/var/podman/pkg/rootless/rootless_unsupported.go /^package rootless$/ rootless /home/yamato/var/podman/vendor/github.com/containers/image/v5/internal/rootless/rootless.go /^package rootless$/ Signed-off-by: Masatake YAMATO <[email protected]>
1 parent d1eef9c commit b9fe6fd

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

extra-cmds/readtags-cmd.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <stdio.h> /* stderr */
2525
#include <stdbool.h>
2626

27+
#include <unistd.h>
28+
2729
typedef struct sReadOption {
2830
bool sortOverride;
2931
sortType sortMethod;
@@ -56,6 +58,7 @@ struct actionSpec {
5658
ACTION_LIST = 1 << 1,
5759
ACTION_LIST_PTAGS = 1 << 2,
5860
ACTION_LIST_INCLUDED = 1 << 3,
61+
ACTION_AGGREGATE = 1 << 4,
5962
} action;
6063
const char *name; /* for ACTION_FIND */
6164
bool canonicalizing;
@@ -609,6 +612,8 @@ static const char *const Usage =
609612
" List pseudo tags.\n"
610613
" -L | --list-included\n"
611614
" List included tag files.\n"
615+
" -X | --generate-aggregate-tag-file\n"
616+
" Generate an aggregate file includes tag files specified with -t option.\n"
612617
"Options:\n"
613618
" -d | --debug\n"
614619
" Turn on debugging output.\n"
@@ -764,6 +769,42 @@ static void loadIndirectTagFiles (struct inputSpec *inputSpec, ptrArray *inputSp
764769
deleteTagFileX (fileX);
765770
}
766771

772+
static void printMustPseudoTag(tagPrintOptions *opts, FILE *fp,
773+
const char *name, const char *file,const char *pattern)
774+
{
775+
tagEntry e;
776+
777+
memset (&e, 0, sizeof (e));
778+
779+
e.name = name;
780+
e.file = file;
781+
e.address.pattern = pattern;
782+
tagsPrintPseudoTag (&e, opts, NULL, fp);
783+
}
784+
785+
static void printMustPseudoTags(tagPrintOptions *opts, FILE *fp)
786+
{
787+
char buf[PATH_MAX];
788+
if (!getcwd(buf, sizeof(buf)))
789+
{
790+
fprintf(stderr, "Failed to get the current working directory\n");
791+
exit (1);
792+
}
793+
794+
printMustPseudoTag(opts, fp, "!_TAG_FILE_FORMAT", "2", "//");
795+
printMustPseudoTag(opts, fp, "!_TAG_FILE_SORTED", "1", "//");
796+
printMustPseudoTag(opts, fp, "!_TAG_OUTPUT_EXCMD", "pattern", "//");
797+
printMustPseudoTag(opts, fp, "!_TAG_OUTPUT_FILESEP", "slash", "//");
798+
printMustPseudoTag(opts, fp, "!_TAG_OUTPUT_MODE", "u-ctags", "//");
799+
printMustPseudoTag(opts, fp, "!_TAG_OUTPUT_VERSION", "0.0", "/current.age/");
800+
printMustPseudoTag(opts, fp, "!_TAG_PATTERN_LENGTH_LIMIT", "0", "//");
801+
printMustPseudoTag(opts, fp, "!_TAG_PROC_CWD", buf, "//");
802+
printMustPseudoTag(opts, fp, "!_TAG_PROGRAM_AUTHOR", "Universal Ctags Team", "//");
803+
printMustPseudoTag(opts, fp, "!_TAG_PROGRAM_NAME", "readtags", "/with -X option/");
804+
printMustPseudoTag(opts, fp, "!_TAG_PROGRAM_URL", "https://ctags.io/", "/official site/");
805+
printMustPseudoTag(opts, fp, "!_TAG_PROGRAM_VERSION", "0.0.0", "/TODO/");
806+
}
807+
767808
extern int main (int argc, char **argv)
768809
{
769810
int i;
@@ -901,6 +942,8 @@ extern int main (int argc, char **argv)
901942
actionSpec.canonicalizing = true;
902943
actionSpec.canon.absoluteOnly = false;
903944
}
945+
else if (strcmp (optname, "generate-aggregate-tag-file") == 0)
946+
actionSpec.action |= ACTION_AGGREGATE;
904947
#ifdef READTAGS_DSL
905948
else if (strcmp (optname, "filter") == 0)
906949
{
@@ -1022,6 +1065,9 @@ extern int main (int argc, char **argv)
10221065
actionSpec.canonicalizing = true;
10231066
actionSpec.canon.absoluteOnly = false;
10241067
break;
1068+
case 'X':
1069+
actionSpec.action |= ACTION_AGGREGATE;
1070+
break;
10251071
#ifdef READTAGS_DSL
10261072
case 'Q':
10271073
if (i + 1 == argc)
@@ -1075,6 +1121,23 @@ extern int main (int argc, char **argv)
10751121
if (ptrArrayIsEmpty (inputSpecs))
10761122
addInputSpec (inputSpecs, "tags", false);
10771123

1124+
if (actionSpec.action & ACTION_AGGREGATE)
1125+
{
1126+
tagEntry e;
1127+
for (unsigned int i = 0; i < ptrArrayCount (inputSpecs); i++)
1128+
{
1129+
struct inputSpec *inputSpec = ptrArrayItem (inputSpecs, i);
1130+
memset (&e, 0, sizeof (e));
1131+
e.name = "!_READTAGS_INCLUDE";
1132+
e.file = inputSpec->tagFileName;
1133+
e.address.pattern = "//";
1134+
tagsPrintPseudoTag (&e, &printOpts, NULL, stdout);
1135+
}
1136+
1137+
printMustPseudoTags (&printOpts, stdout);
1138+
goto out;
1139+
}
1140+
10781141
unsigned int start = 0;
10791142
unsigned int end = ptrArrayCount (inputSpecs);
10801143
while (1)
@@ -1124,6 +1187,7 @@ extern int main (int argc, char **argv)
11241187
}
11251188
}
11261189

1190+
out:
11271191
ptrArrayDelete (inputSpecs);
11281192

11291193
#ifdef READTAGS_DSL

0 commit comments

Comments
 (0)