Skip to content

Commit

Permalink
readtags,refactor: make Sorter work when multiple tags is given
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Sep 5, 2024
1 parent 6edc863 commit 3e67a0f
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions extra-cmds/readtags-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ struct actionSpec {
const char *name; /* for ACTION_FIND */
bool canonicalizing;
struct canonWorkArea canon;
ptrArray *tagEntryArray;
void (* walkerfn) (const tagEntry *, void *);
void *dataForWalkerFn;
};

static const char *ProgramName;
Expand Down Expand Up @@ -183,9 +186,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
void (* actionfn) (const tagEntry *, void *), void *data,
struct actionSpec *actionSpec)
{
ptrArray *a = NULL;
if (Sorter)
a = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);
ptrArray *a = actionSpec->tagEntryArray;

do
{
Expand Down Expand Up @@ -233,14 +234,8 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,

if (a)
{
ptrArraySort (a, compareTagEntry);
size_t count = ptrArrayCount(a);
for (unsigned int i = 0; i < count; i++)
{
tagEntry *e = ptrArrayItem (a, i);
(* actionfn) (e, data);
}
ptrArrayDelete (a);
actionSpec->walkerfn = actionfn;
actionSpec->dataForWalkerFn = data;
}
}
#else
Expand Down Expand Up @@ -774,6 +769,9 @@ extern int main (int argc, char **argv)
.ptags = false,
/* .absoluteOnly = false, */
},
.tagEntryArray = NULL,
.walkerfn = NULL,
.dataForWalkerFn = NULL,
};

memset (&printOpts, 0, sizeof (printOpts));
Expand Down Expand Up @@ -1106,7 +1104,14 @@ extern int main (int argc, char **argv)
break;
}

for (unsigned int i = 0; i < ptrArrayCount (inputSpecs); i++)
unsigned int count = ptrArrayCount (inputSpecs);
/* TODO: if Sorter == NULL but if count > 1 && sort is set to true in !_TAG_FILE_SORT,
* we have to sort as if !_TAG_FILE_SORT is true.
* Sorter must be build here. */
if (Sorter || count > 1)
actionSpec.tagEntryArray = ptrArrayNew ((ptrArrayDeleteFunc)freeCopiedTag);

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

Expand Down Expand Up @@ -1137,6 +1142,19 @@ extern int main (int argc, char **argv)
}
}

if (actionSpec.tagEntryArray)
{
if (Sorter)
ptrArraySort (actionSpec.tagEntryArray, compareTagEntry);
size_t count = ptrArrayCount(actionSpec.tagEntryArray);
for (unsigned int i = 0; i < count; i++)
{
tagEntry *e = ptrArrayItem (actionSpec.tagEntryArray, i);
actionSpec.walkerfn (e, actionSpec.dataForWalkerFn);
}
ptrArrayDelete (actionSpec.tagEntryArray);
}

out:
ptrArrayDelete (inputSpecs);

Expand Down

0 comments on commit 3e67a0f

Please sign in to comment.