Skip to content

Commit 663753d

Browse files
committed
readtags,refactor: pass the actionSpec to action functions instead of the canonWorkArea
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent b2dc711 commit 663753d

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

extra-cmds/readtags-cmd.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int compareTagEntry (const void *a, const void *b)
229229
static void walkTags (tagFile *const file, tagEntry *first_entry,
230230
tagResult (* nextfn) (tagFile *const, tagEntry *),
231231
void (* actionfn) (const tagEntry *, void *), void *data,
232-
struct canonWorkArea *canon)
232+
struct actionSpec *actionSpec)
233233
{
234234
struct tagEntryArray *a = NULL;
235235

@@ -240,13 +240,13 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
240240
{
241241
tagEntry *shadow = first_entry;
242242
tagEntry shadowRec;
243-
if (canon
244-
&& (canon->ptags == false
243+
if (actionSpec->canonicalizing
244+
&& (actionSpec->canon.ptags == false
245245
|| strcmp (first_entry->name, "!_TAG_PROC_CWD") == 0))
246246
{
247247
shadowRec = *first_entry;
248248
shadow = &shadowRec;
249-
shadow->file = canonicalizeFileName (canon->cacheTable,
249+
shadow->file = canonicalizeFileName (actionSpec->canon.cacheTable,
250250
first_entry->file);
251251
}
252252

@@ -292,19 +292,19 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
292292
static void walkTags (tagFile *const file, tagEntry *first_entry,
293293
tagResult (* nextfn) (tagFile *const, tagEntry *),
294294
void (* actionfn) (const tagEntry *, void *), void *data,
295-
struct canonWorkArea *canon)
295+
struct actionSpec *actionSpec)
296296
{
297297
do
298298
{
299299
tagEntry *shadow = first_entry;
300300
tagEntry shadowRec;
301-
if (canon
302-
&& (canon->ptags == false
301+
if (actionSpec->canonicalizing
302+
&& (actionSpec->canon.ptags == false
303303
|| strcmp (first_entry->name, "!_TAG_PROC_CWD") == 0))
304304
{
305305
shadow = &shadowRec;
306306
shadowRec = *first_entry;
307-
shadow->file = canonicalizeFileName (canon->cacheTable,
307+
shadow->file = canonicalizeFileName (actionSpec->canon.cacheTable,
308308
first_entry->file);
309309
}
310310

@@ -472,7 +472,7 @@ static int hasPsuedoTag (tagFile *const file,
472472

473473
static void findTag (struct inputSpec *inputSpec,
474474
const char *const name, readOptions *readOpts,
475-
tagPrintOptions *printOpts, struct canonWorkArea *canon)
475+
tagPrintOptions *printOpts, struct actionSpec *actionSpec)
476476
{
477477
tagEntry entry;
478478
int err = 0;
@@ -486,8 +486,8 @@ static void findTag (struct inputSpec *inputSpec,
486486
exit (1);
487487
}
488488

489-
if (canon && canon->cacheTable == NULL)
490-
canon->cacheTable = makeCanonFnameCacheTable (fileX, canon->absoluteOnly);
489+
if (actionSpec->canonicalizing && actionSpec->canon.cacheTable == NULL)
490+
actionSpec->canon.cacheTable = makeCanonFnameCacheTable (fileX, actionSpec->canon.absoluteOnly);
491491

492492
if (printOpts->escaping)
493493
{
@@ -518,7 +518,7 @@ static void findTag (struct inputSpec *inputSpec,
518518
Formatter? printTagWithFormatter:
519519
#endif
520520
printTag, printOpts,
521-
canon);
521+
actionSpec);
522522
else if ((err = tagsGetErrno (fileX->tagFile)) != 0)
523523
{
524524
fprintf (stderr, "%s: error in tagsFind(): %s\n",
@@ -530,7 +530,7 @@ static void findTag (struct inputSpec *inputSpec,
530530
}
531531

532532
static void listTags (struct inputSpec* inputSpec, int pseudoTags, tagPrintOptions *printOpts,
533-
struct canonWorkArea *canon)
533+
struct actionSpec *actionSpec)
534534
{
535535
tagEntry entry;
536536
int err = 0;
@@ -545,8 +545,9 @@ static void listTags (struct inputSpec* inputSpec, int pseudoTags, tagPrintOptio
545545
exit (1);
546546
}
547547

548-
if (canon && canon->cacheTable == NULL)
549-
canon->cacheTable = makeCanonFnameCacheTable (fileX, canon->absoluteOnly);
548+
if (actionSpec->canonicalizing && actionSpec->canon.cacheTable == NULL)
549+
actionSpec->canon.cacheTable = makeCanonFnameCacheTable (fileX,
550+
actionSpec->canon.absoluteOnly);
550551

551552
if (printOpts->escaping)
552553
{
@@ -560,7 +561,7 @@ static void listTags (struct inputSpec* inputSpec, int pseudoTags, tagPrintOptio
560561
{
561562
if (tagsFirstPseudoTag (fileX->tagFile, &entry) == TagSuccess)
562563
walkTags (fileX->tagFile, &entry, tagsNextPseudoTag, printPseudoTag, printOpts,
563-
canon);
564+
actionSpec);
564565
else if ((err = tagsGetErrno (fileX->tagFile)) != 0)
565566
{
566567
fprintf (stderr, "%s: error in tagsFirstPseudoTag(): %s\n",
@@ -577,7 +578,7 @@ static void listTags (struct inputSpec* inputSpec, int pseudoTags, tagPrintOptio
577578
Formatter? printTagWithFormatter:
578579
#endif
579580
printTag, printOpts,
580-
canon);
581+
actionSpec);
581582
else if ((err = tagsGetErrno (fileX->tagFile)) != 0)
582583
{
583584
fprintf (stderr, "%s: error in tagsFirst(): %s\n",
@@ -1164,18 +1165,15 @@ extern int main (int argc, char **argv)
11641165
{
11651166
if (actionSpec.canonicalizing)
11661167
actionSpec.canon.ptags = true;
1167-
listTags (inputSpec, 1, &printOpts,
1168-
actionSpec.canonicalizing? &actionSpec.canon: NULL);
1168+
listTags (inputSpec, 1, &printOpts, &actionSpec);
11691169
if (actionSpec.canonicalizing)
11701170
actionSpec.canon.ptags = false;
11711171
}
11721172

11731173
if (actionSpec.action & ACTION_FIND)
1174-
findTag (inputSpec, actionSpec.name, &readOpts, &printOpts,
1175-
actionSpec.canonicalizing? &actionSpec.canon: NULL);
1174+
findTag (inputSpec, actionSpec.name, &readOpts, &printOpts, &actionSpec);
11761175
else if (actionSpec.action & ACTION_LIST)
1177-
listTags (inputSpec, 0, &printOpts,
1178-
actionSpec.canonicalizing? &actionSpec.canon: NULL);
1176+
listTags (inputSpec, 0, &printOpts, &actionSpec);
11791177

11801178
if (actionSpec.canon.cacheTable)
11811179
{

0 commit comments

Comments
 (0)