Skip to content

Commit

Permalink
main: add --list-output-formats option
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Dec 14, 2024
1 parent ee4bdcc commit 5b29668
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/man/ctags.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ Output Format Options
the ctags executable is built with ``libjansson``.
See :ref:`ctags-json-output(5) <ctags-json-output(5)>` for more about ``json`` format.

See also ``--list-output-formats``.

``-e``
Same as ``--output-format=etags``.
Enable etags mode, which will create a tag file for use with the Emacs
Expand Down Expand Up @@ -1236,6 +1238,9 @@ Listing Options
definition.
See :ref:`ctags-optlib(7) <ctags-optlib(7)>`.

``--list-output-formats``
Lists the output formats that can be used in ``--output-format`` option.

``--list-params[=(<language>|all)]``
Lists the parameters for either the specified *<language>* or ``all``
languages, and then exits.
Expand Down
10 changes: 10 additions & 0 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ static optionDescription LongOptionDescription [] = {
{1,0," Output list of language mappings (both extensions and patterns)."},
{1,0," --list-mline-regex-flags"},
{1,0," Output list of flags which can be used in a multiline regex parser definition."},
{1,0," --list-output-formats"},
{1,0," Output list of output formats."},
{1,0," --list-params[=(<language>|all)]"},
{1,0," Output list of language parameters. This works with --machinable."},
{0,0," --list-pseudo-tags"},
Expand Down Expand Up @@ -2314,6 +2316,13 @@ static void processListOperators (const char *const option CTAGS_ATTR_UNUSED,
exit (0);
}

static void processListOutputFormatsOption(const char *const option CTAGS_ATTR_UNUSED,

Check warning on line 2319 in main/options.c

View check run for this annotation

Codecov / codecov/patch

main/options.c#L2319

Added line #L2319 was not covered by tests
const char *const parameter CTAGS_ATTR_UNUSED)
{
printOutputFormats (localOption.withListHeader, localOption.machinable, stdout);
exit (0);

Check warning on line 2323 in main/options.c

View check run for this annotation

Codecov / codecov/patch

main/options.c#L2322-L2323

Added lines #L2322 - L2323 were not covered by tests
}

static void freeSearchPathList (searchPathList** pathList)
{
stringListClear (*pathList);
Expand Down Expand Up @@ -2899,6 +2908,7 @@ static parametricOption ParametricOptions [] = {
{ "list-map-extensions", processListMapExtensionsOption, true, STAGE_ANY },
{ "list-map-patterns", processListMapPatternsOption, true, STAGE_ANY },
{ "list-mline-regex-flags", processListMultilineRegexFlagsOptions, true, STAGE_ANY },
{ "list-output-formats", processListOutputFormatsOption, true, STAGE_ANY },
{ "list-params", processListParametersOption, true, STAGE_ANY },
{ "list-pseudo-tags", processListPseudoTagsOptions, true, STAGE_ANY },
{ "list-regex-flags", processListRegexFlagsOptions, true, STAGE_ANY },
Expand Down
41 changes: 41 additions & 0 deletions main/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "general.h"

#include "colprint_p.h"
#include "debug.h"
#include "entry_p.h"
#include "options_p.h"
Expand Down Expand Up @@ -212,3 +213,43 @@ extern writerType getWrierForOutputFormat (const char *oformat)

return WRITER_UNKNOWN;
}

#define WRITER_COL_OFORMAT 0
#define WRITER_COL_AVAILABLE 1
#define WRITER_COL_NULLTAG 2

static int writerColprintCompareLines (struct colprintLine *a , struct colprintLine *b)

Check warning on line 221 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L221

Added line #L221 was not covered by tests
{
const char *a_oformat = colprintLineGetColumn (a, WRITER_COL_OFORMAT);
const char *b_oformat = colprintLineGetColumn (b, WRITER_COL_OFORMAT);

Check warning on line 224 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L223-L224

Added lines #L223 - L224 were not covered by tests

return strcmp(a_oformat, b_oformat);

Check warning on line 226 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L226

Added line #L226 was not covered by tests
}

extern struct colprintTable * writerColprintTableNew (void)

Check warning on line 229 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L229

Added line #L229 was not covered by tests
{
return colprintTableNew ("L:OFORMAT", "R:AVAILABLE", "R:NULLTAG", NULL);

Check warning on line 231 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L231

Added line #L231 was not covered by tests
}

extern void printOutputFormats (bool withListHeader, bool machinable, FILE *fp)

Check warning on line 234 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L234

Added line #L234 was not covered by tests
{
struct colprintTable * table = writerColprintTableNew ();

Check warning on line 236 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L236

Added line #L236 was not covered by tests

for (int i = 0; i < WRITER_COUNT; i++)

Check warning on line 238 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L238

Added line #L238 was not covered by tests
{
if (!writerTable[i])
continue;
if (!writerTable[i]->oformat)
continue;

Check warning on line 243 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L240-L243

Added lines #L240 - L243 were not covered by tests

struct colprintLine * line = colprintTableGetNewLine (table);
colprintLineAppendColumnCString (line, writerTable[i]->oformat);

Check warning on line 246 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L245-L246

Added lines #L245 - L246 were not covered by tests

colprintLineAppendColumnBool (line, writerTable[i]->writeEntry? true: false);
colprintLineAppendColumnBool (line, writerTable[i]->canPrintNullTag);

Check warning on line 249 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L248-L249

Added lines #L248 - L249 were not covered by tests
}

colprintTableSort (table, writerColprintCompareLines);
colprintTablePrint (table, 0, withListHeader, machinable, fp);
colprintTableDelete (table);
}

Check warning on line 255 in main/writer.c

View check run for this annotation

Codecov / codecov/patch

main/writer.c#L252-L255

Added lines #L252 - L255 were not covered by tests
1 change: 1 addition & 0 deletions main/writer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern void writerCheckOptions (bool fieldsWereReset);
extern bool writerPrintPtagByDefault (void);

extern writerType getWrierForOutputFormat (const char *oformat);
extern void printOutputFormats (bool withListHeader, bool machinable, FILE *fp);

#ifdef _WIN32
extern enum filenameSepOp getFilenameSeparator (enum filenameSepOp currentSetting);
Expand Down
5 changes: 5 additions & 0 deletions man/ctags.1.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ Output Format Options
the ctags executable is built with ``libjansson``.
See ctags-json-output(5) for more about ``json`` format.

See also ``--list-output-formats``.

``-e``
Same as ``--output-format=etags``.
Enable etags mode, which will create a tag file for use with the Emacs
Expand Down Expand Up @@ -1236,6 +1238,9 @@ Listing Options
definition.
See ctags-optlib(7).

``--list-output-formats``
Lists the output formats that can be used in ``--output-format`` option.

``--list-params[=(<language>|all)]``
Lists the parameters for either the specified *<language>* or ``all``
languages, and then exits.
Expand Down

0 comments on commit 5b29668

Please sign in to comment.