Skip to content

Commit e751d3a

Browse files
committed
readtags,refactor: use bool instead of int
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent aefac5e commit e751d3a

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

extra-cmds/printtags.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
*/
1212

1313
#include "printtags.h"
14-
#include <stdio.h>
1514

15+
#include <stdbool.h>
16+
#include <stdio.h>
1617

1718
/*
1819
* DATA DEFINITIONS
@@ -48,7 +49,7 @@ static void ultostr (char dst [21], unsigned long d)
4849
dst [i] = '\0';
4950
}
5051

51-
static void printValue (const char *val, int printingWithEscaping,
52+
static void printValue (const char *val, bool printingWithEscaping,
5253
int (* print_str) (const char *, void *),
5354
int (* print_char) (int, void *),
5455
void *outfp)
@@ -103,7 +104,7 @@ static void printValue (const char *val, int printingWithEscaping,
103104
}
104105

105106
extern int tagsPrintValue (const char *val,
106-
int escaping,
107+
bool escaping,
107108
tagPrintProcs *procs,
108109
void *outfp)
109110
{
@@ -118,10 +119,10 @@ extern int tagsPrintValue (const char *val,
118119

119120
static void tagsPrintTag (const tagEntry *entry,
120121
int printingExtensionFields,
121-
int printingLineNumber,
122-
int printingWithEscaping,
123-
int printInputFieldWithEscaping,
124-
int pseudoTag,
122+
bool printingLineNumber,
123+
bool printingWithEscaping,
124+
bool printInputFieldWithEscaping,
125+
bool pseudoTag,
125126
int (* print_str) (const char *, void *),
126127
int (* print_char) (int, void *),
127128
void *outfp)
@@ -217,7 +218,7 @@ extern int tagsPrint (const tagEntry *entry,
217218
opt->lineNumber,
218219
opt->escaping,
219220
opt->escapingInputField,
220-
0,
221+
false,
221222
procs->printStr,
222223
procs->printChar,
223224
outfp);
@@ -235,7 +236,7 @@ extern int tagsPrintPseudoTag (const tagEntry *entry,
235236
opt->lineNumber,
236237
opt->escaping,
237238
opt->escapingInputField,
238-
1,
239+
true,
239240
procs->printStr,
240241
procs->printChar,
241242
outfp);

extra-cmds/printtags.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
* INCLUDE FILES
1818
*/
1919
#include "readtags.h"
20+
#include <stdbool.h>
2021

2122
/*
2223
* DATA DECLARATIONS
@@ -29,9 +30,9 @@ typedef struct {
2930

3031
typedef struct {
3132
int extensionFields;
32-
int lineNumber;
33-
int escaping;
34-
int escapingInputField;
33+
bool lineNumber;
34+
bool escaping;
35+
bool escapingInputField;
3536
} tagPrintOptions;
3637

3738
/*
@@ -46,7 +47,7 @@ extern int tagsPrint (const tagEntry *entry,
4647
extern int tagsPrintPseudoTag (const tagEntry *entry,
4748
tagPrintOptions *opts, tagPrintProcs *procs, void *outfp);
4849

49-
extern int tagsPrintValue (const char *val, int escaping, tagPrintProcs *procs, void *outfp);
50+
extern int tagsPrintValue (const char *val, bool escaping, tagPrintProcs *procs, void *outfp);
5051

5152
#ifdef __cplusplus
5253
};

extra-cmds/readtags-cmd.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@
2121
#include <string.h> /* strerror */
2222
#include <stdlib.h> /* exit */
2323
#include <stdio.h> /* stderr */
24+
#include <stdbool.h>
2425

2526
typedef struct sReadOption {
26-
int sortOverride;
27+
bool sortOverride;
2728
sortType sortMethod;
2829
/* options passed to libreadtags API functions.*/
2930
int matchOpts;
3031
} readOptions;
3132

3233
struct canonWorkArea {
3334
struct canonFnameCacheTable *cacheTable;
34-
int ptags;
35+
bool ptags;
3536
bool absoluteOnly;
3637
};
3738

@@ -231,7 +232,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
231232
tagEntry *shadow = first_entry;
232233
tagEntry shadowRec;
233234
if (canon
234-
&& (canon->ptags == 0
235+
&& (canon->ptags == false
235236
|| strcmp (first_entry->name, "!_TAG_PROC_CWD") == 0))
236237
{
237238
shadowRec = *first_entry;
@@ -289,7 +290,7 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
289290
tagEntry *shadow = first_entry;
290291
tagEntry shadowRec;
291292
if (canon
292-
&& (canon->ptags == 0
293+
&& (canon->ptags == false
293294
|| strcmp (first_entry->name, "!_TAG_PROC_CWD") == 0))
294295
{
295296
shadow = &shadowRec;
@@ -481,10 +482,10 @@ static void findTag (struct inputSpec *inputSpec,
481482

482483
if (printOpts->escaping)
483484
{
484-
printOpts->escapingInputField = 0;
485+
printOpts->escapingInputField = false;
485486
if (hasPsuedoTag (fileX->tagFile, "!_TAG_OUTPUT_MODE", "u-ctags")
486487
&& hasPsuedoTag (fileX->tagFile, "!_TAG_OUTPUT_FILESEP", "slash"))
487-
printOpts->escapingInputField = 1;
488+
printOpts->escapingInputField = true;
488489
}
489490

490491
if (readOpts->sortOverride)
@@ -540,10 +541,10 @@ static void listTags (struct inputSpec* inputSpec, int pseudoTags, tagPrintOptio
540541

541542
if (printOpts->escaping)
542543
{
543-
printOpts->escapingInputField = 0;
544+
printOpts->escapingInputField = false;
544545
if (hasPsuedoTag (fileX->tagFile, "!_TAG_OUTPUT_MODE", "u-ctags")
545546
&& hasPsuedoTag (fileX->tagFile, "!_TAG_OUTPUT_FILESEP", "slash"))
546-
printOpts->escapingInputField = 1;
547+
printOpts->escapingInputField = true;
547548
}
548549

549550
if (pseudoTags)
@@ -725,12 +726,12 @@ extern int main (int argc, char **argv)
725726

726727
struct canonWorkArea canonWorkArea = {
727728
.cacheTable = NULL,
728-
.ptags = 0,
729+
.ptags = false,
729730
.absoluteOnly = false,
730731
};
731732
struct canonWorkArea canonWorkAreaAbsForm = {
732733
.cacheTable = NULL,
733-
.ptags = 0,
734+
.ptags = false,
734735
.absoluteOnly = true,
735736
};
736737
struct canonWorkArea *canon = NULL;
@@ -791,17 +792,17 @@ extern int main (int argc, char **argv)
791792
else if (strcmp (optname, "version") == 0)
792793
printVersion ();
793794
else if (strcmp (optname, "escape-output") == 0)
794-
printOpts.escaping = 1;
795+
printOpts.escaping = true;
795796
else if (strcmp (optname, "extension-fields") == 0)
796-
printOpts.extensionFields = 1;
797+
printOpts.extensionFields = true;
797798
else if (strcmp (optname, "icase-match") == 0)
798799
readOpts.matchOpts |= TAG_IGNORECASE;
799800
else if (strcmp (optname, "prefix-match") == 0)
800801
readOpts.matchOpts |= TAG_PARTIALMATCH;
801802
else if (strcmp (optname, "list") == 0)
802803
actionSpec.action |= ACTION_LIST;
803804
else if (strcmp (optname, "line-number") == 0)
804-
printOpts.lineNumber = 1;
805+
printOpts.lineNumber = true;
805806
else if (strcmp (optname, "tag-file") == 0)
806807
{
807808
if (i + 1 < argc)
@@ -921,14 +922,14 @@ extern int main (int argc, char **argv)
921922
printUsage(stderr, 1);
922923
#endif
923924
case 'v': printVersion ();
924-
case 'E': printOpts.escaping = 1; break;
925-
case 'e': printOpts.extensionFields = 1; break;
925+
case 'E': printOpts.escaping = true; break;
926+
case 'e': printOpts.extensionFields = true; break;
926927
case 'i': readOpts.matchOpts |= TAG_IGNORECASE; break;
927928
case 'p': readOpts.matchOpts |= TAG_PARTIALMATCH; break;
928929
case 'l':
929930
actionSpec.action |= ACTION_LIST;
930931
break;
931-
case 'n': printOpts.lineNumber = 1; break;
932+
case 'n': printOpts.lineNumber = true; break;
932933
case 't':
933934
if (arg [j+1] != '\0')
934935
{
@@ -941,7 +942,7 @@ extern int main (int argc, char **argv)
941942
printUsage(stderr, 1);
942943
break;
943944
case 's':
944-
readOpts.sortOverride = 1;
945+
readOpts.sortOverride = true;
945946
++j;
946947
if (arg [j] == '\0')
947948
readOpts.sortMethod = TAG_SORTED;
@@ -1009,10 +1010,10 @@ extern int main (int argc, char **argv)
10091010
if (actionSpec.action & ACTION_LIST_PTAGS)
10101011
{
10111012
if (canon)
1012-
canon->ptags = 1;
1013+
canon->ptags = true;
10131014
listTags (&inputSpec, 1, &printOpts, canon);
10141015
if (canon)
1015-
canon->ptags = 0;
1016+
canon->ptags = false;
10161017
}
10171018

10181019
if (actionSpec.action & ACTION_FIND)

0 commit comments

Comments
 (0)