Skip to content

Commit

Permalink
readtags: experimental support for specifying -t multiple times
Browse files Browse the repository at this point in the history
  $ ~/bin/ctags -o podman.tags -R ~/var/podman
  $ ~/bin/ctags -o glibc.tags -R ~/var/glibc
  $ ~/bin/ctags -o coreutils832.tags -R /srv/sources9c/sources/c/coreutils/8.32-31.el9--srpm/pre-build/coreutils-8.32
  $ ./readtags -A -Q '(and (eq? $name "main") (#/.*user.*/ $input))' -t podman.tags -t glibc.tags -t coreutils832.tags -l
  main	/srv/sources9c/sources/c/coreutils/8.32-31.el9--srpm/pre-build/coreutils-8.32/gnulib-tests/test-userspec.c	/^main (void)$/
  main	/srv/sources9c/sources/c/coreutils/8.32-31.el9--srpm/pre-build/coreutils-8.32/lib/getusershell.c	/^main (void)$/
  main	/srv/sources9c/sources/c/coreutils/8.32-31.el9--srpm/pre-build/coreutils-8.32/lib/userspec.c	/^main (int argc, char **argv)$/
  main	/srv/sources9c/sources/c/coreutils/8.32-31.el9--srpm/pre-build/coreutils-8.32/src/users.c	/^main (int argc, char **argv)$/
  $ ./readtags -A -Q '(and (eq? $name "main") (#/.*container.*/ $input))' -t podman.tags -t glibc.tags -t coreutils832.tags -l
  main	/home/yamato/var/glibc/support/echo-container.c	/^main (int argc, const char **argv)$/
  main	/home/yamato/var/glibc/support/shell-container.c	/^main (int argc, const char **argv)$/
  main	/home/yamato/var/glibc/support/test-container.c	/^main (int argc, char **argv)$/
  main	/home/yamato/var/glibc/support/true-container.c	/^main (void)$/
  $ ./readtags -A -Q '(not (#/.*_test.*/ $input))' -t podman.tags -t glibc.tags -t coreutils832.tags 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_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]>
  • Loading branch information
masatake committed Sep 12, 2024
1 parent 044cd45 commit 953f035
Showing 1 changed file with 71 additions and 27 deletions.
98 changes: 71 additions & 27 deletions extra-cmds/readtags-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "htable.h"
#include "ptrarray.h"
#include "fname.h"
#include "ptrarray.h"

#include <string.h> /* strerror */
#include <stdlib.h> /* exit */
Expand Down Expand Up @@ -661,17 +662,36 @@ static void printVersion(void)
exit (0);
}

static void deleteInputSpec (void *data)
{
struct inputSpec *inputSpec = data;
if (inputSpec->tempFileName)
{
remove (inputSpec->tempFileName);
eFree (inputSpec->tempFileName);
}
eFree (data);
}

static void addInputSpec (ptrArray *inputSpecs, const char *name)
{
struct inputSpec *i = eMalloc (sizeof (struct inputSpec));

i->tagFileName = name;
i->tempFileName = NULL;

ptrArrayAdd (inputSpecs, i);
}

extern int main (int argc, char **argv)
{
int i;
bool ignore_prefix = false;

tagPrintOptions printOpts = {0};
readOptions readOpts = {0};
struct inputSpec inputSpec = {
.tagFileName = "tags",
.tempFileName = NULL,
};
ptrArray *inputSpecs = ptrArrayNew (deleteInputSpec);

struct actionSpec actionSpec = {
.action = ACTION_NONE,
.name = NULL,
Expand Down Expand Up @@ -755,7 +775,7 @@ extern int main (int argc, char **argv)
else if (strcmp (optname, "tag-file") == 0)
{
if (i + 1 < argc)
inputSpec.tagFileName = argv [++i];
addInputSpec (inputSpecs, argv[++i]);

Check warning on line 778 in extra-cmds/readtags-cmd.c

View check run for this annotation

Codecov / codecov/patch

extra-cmds/readtags-cmd.c#L778

Added line #L778 was not covered by tests
else
printUsage (stderr, 1);
}
Expand Down Expand Up @@ -888,11 +908,12 @@ extern int main (int argc, char **argv)
case 't':
if (arg [j+1] != '\0')
{
inputSpec.tagFileName = arg + j + 1;
j += strlen (inputSpec.tagFileName);
const char *tname = arg + j + 1;
addInputSpec (inputSpecs, tname);
j += strlen (tname);

Check warning on line 913 in extra-cmds/readtags-cmd.c

View check run for this annotation

Codecov / codecov/patch

extra-cmds/readtags-cmd.c#L911-L913

Added lines #L911 - L913 were not covered by tests
}
else if (i + 1 < argc)
inputSpec.tagFileName = argv [++i];
addInputSpec (inputSpecs, argv [++i]);
else
printUsage(stderr, 1);
break;
Expand Down Expand Up @@ -964,24 +985,55 @@ extern int main (int argc, char **argv)
exit (1);

Check warning on line 985 in extra-cmds/readtags-cmd.c

View check run for this annotation

Codecov / codecov/patch

extra-cmds/readtags-cmd.c#L985

Added line #L985 was not covered by tests
}

size_t input_count = ptrArrayCount(inputSpecs);
#ifndef READTAGS_DSL
if (input_count > 0)
{
/* mk_mingw.mak sets -DREADTAGS_DSL.
* mk_mvc.mak doesn't. */
fprintf (stderr,
"Processsing multiple tags is not supported with this (!READTAGS_DSL) build confiugraion.");
exit (1);
}
#endif

#ifdef READTAGS_DSL
if (Sorter)
if (Sorter || input_count > 0)
actionSpec.tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
#endif

if (actionSpec.action & ACTION_LIST_PTAGS)
if (ptrArrayIsEmpty (inputSpecs))
{
if (actionSpec.canonicalizing)
actionSpec.canon.ptags = true;
listTags (&inputSpec, true, &printOpts, &actionSpec);
if (actionSpec.canonicalizing)
actionSpec.canon.ptags = false;
addInputSpec (inputSpecs, "tags");
input_count++;

Check warning on line 1008 in extra-cmds/readtags-cmd.c

View check run for this annotation

Codecov / codecov/patch

extra-cmds/readtags-cmd.c#L1007-L1008

Added lines #L1007 - L1008 were not covered by tests
}

for (unsigned int i = 0; i < input_count; i++)
{
struct inputSpec *inputSpec = ptrArrayItem (inputSpecs, i);

if (actionSpec.action & ACTION_LIST_PTAGS)
{
if (actionSpec.canonicalizing)
actionSpec.canon.ptags = true;
listTags (inputSpec, true, &printOpts, &actionSpec);
if (actionSpec.canonicalizing)
actionSpec.canon.ptags = false;
}

if (actionSpec.action & ACTION_FIND)
findTag (inputSpec, actionSpec.name, &readOpts, &printOpts, &actionSpec);
else if (actionSpec.action & ACTION_LIST)
listTags (inputSpec, false, &printOpts, &actionSpec);

if (actionSpec.canon.cacheTable)
{
canonFnameCacheTableDelete (actionSpec.canon.cacheTable);
actionSpec.canon.cacheTable = NULL;
}
}

if (actionSpec.action & ACTION_FIND)
findTag (&inputSpec, actionSpec.name, &readOpts, &printOpts, &actionSpec);
else if (actionSpec.action & ACTION_LIST)
listTags (&inputSpec, false, &printOpts, &actionSpec);
ptrArrayDelete (inputSpecs);

if (actionSpec.tagEntryArray)
{
Expand All @@ -1008,13 +1060,5 @@ extern int main (int argc, char **argv)
f_destroy (Formatter);
#endif

if (actionSpec.canon.cacheTable)
canonFnameCacheTableDelete (actionSpec.canon.cacheTable);

if (inputSpec.tempFileName)
{
remove (inputSpec.tempFileName);
eFree (inputSpec.tempFileName);
}
return 0;
}

0 comments on commit 953f035

Please sign in to comment.