Skip to content

Commit

Permalink
Merge pull request #2773 from masatake/update-libreadtags
Browse files Browse the repository at this point in the history
Update libreadtags
  • Loading branch information
masatake committed Dec 27, 2020
2 parents 13d5446 + 4adb68e commit 09e9513
Show file tree
Hide file tree
Showing 31 changed files with 1,476 additions and 213 deletions.
91 changes: 86 additions & 5 deletions extra-cmds/readtags-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ static QCode *Qualifier;
static SCode *Sorter;
#endif

static const char* tagsStrerror (int err)
{
if (err > 0)
return strerror (err);
else if (err < 0)
{
switch (err)
{
case TagErrnoUnexpectedSortedMethod:
return "Unexpected sorted method";
case TagErrnoUnexpectedFormat:
return "Unexpected format number";
case TagErrnoUnexpectedLineno:
return "Unexpected value for line: field";
case TagErrnoInvalidArgument:
return "Unexpected argument passed to the API function";
default:
return "Unknown error";
}
}
else
return "no error";
}

static void printTag (const tagEntry *entry)
{
tagPrintOptions opts = {
Expand Down Expand Up @@ -214,6 +238,14 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
(* actionfn) (first_entry);
} while ( (*nextfn) (file, first_entry) == TagSuccess);

int err = tagsGetErrno (file);
if (err != 0)
{
fprintf (stderr, "%s: error in walktTags(): %s\n",
ProgramName,
tagsStrerror (err));
exit (1);
}

if (a)
{
Expand All @@ -231,6 +263,15 @@ static void walkTags (tagFile *const file, tagEntry *first_entry,
do
(* actionfn) (first_entry);
while ( (*nextfn) (file, first_entry) == TagSuccess);

int err = tagsGetErrno (file);
if (err != 0)
{
fprintf (stderr, "%s: error in walktTags(): %s\n",
ProgramName,
tagsStrerror (err));
exit (1);
}
}
#endif

Expand All @@ -239,21 +280,41 @@ static void findTag (const char *const name, const int options)
tagFileInfo info;
tagEntry entry;
tagFile *const file = tagsOpen (TagFileName, &info);
if (file == NULL)
if (file == NULL || !info.status.opened)
{
fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
ProgramName, strerror (info.status.error_number), TagFileName);
ProgramName, tagsStrerror (info.status.error_number), TagFileName);
if (file)
tagsClose (file);
exit (1);
}
else
{
int err = 0;
if (SortOverride)
tagsSetSortType (file, SortMethod);
{
if (tagsSetSortType (file, SortMethod) != TagSuccess)
{
err = tagsGetErrno (file);
fprintf (stderr, "%s: cannot set sort type to %d: %s\n",
ProgramName,
SortMethod,
tagsStrerror (err));
exit (1);
}
}
if (debugMode)
fprintf (stderr, "%s: searching for \"%s\" in \"%s\"\n",
ProgramName, name, TagFileName);
if (tagsFind (file, &entry, name, options) == TagSuccess)
walkTags (file, &entry, tagsFindNext, printTag);
else if ((err = tagsGetErrno (file)) != 0)
{
fprintf (stderr, "%s: error in tagsFind(): %s\n",
ProgramName,
tagsStrerror (err));
exit (1);
}
tagsClose (file);
}
}
Expand All @@ -263,22 +324,42 @@ static void listTags (int pseudoTags)
tagFileInfo info;
tagEntry entry;
tagFile *const file = tagsOpen (TagFileName, &info);
if (file == NULL)
if (file == NULL || !info.status.opened)
{
fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
ProgramName, strerror (info.status.error_number), TagFileName);
ProgramName,
tagsStrerror (info.status.error_number),
TagFileName);
if (file)
tagsClose (file);
exit (1);
}
else if (pseudoTags)
{
int err = 0;
if (tagsFirstPseudoTag (file, &entry) == TagSuccess)
walkTags (file, &entry, tagsNextPseudoTag, printPseudoTag);
else if ((err = tagsGetErrno (file)) != 0)
{
fprintf (stderr, "%s: error in tagsFirstPseudoTag(): %s\n",
ProgramName,
tagsStrerror (err));
exit (1);
}
tagsClose (file);
}
else
{
int err = 0;
if (tagsFirst (file, &entry) == TagSuccess)
walkTags (file, &entry, tagsNext, printTag);
else if ((err = tagsGetErrno (file)) != 0)
{
fprintf (stderr, "%s: error in tagsFirst(): %s\n",
ProgramName,
tagsStrerror (err));
exit (1);
}
tagsClose (file);
}
}
Expand Down
4 changes: 4 additions & 0 deletions libreadtags/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.deps
.libs
*.gcda
*.gcno
*.gcov
*.la
*.lo
*.o
Expand Down Expand Up @@ -29,6 +32,7 @@ test-driver
tests/*.log
tests/*.trs
tests/test-api-tagsFind
tests/test-api-tagsFirst
tests/test-api-tagsFirstPseudoTag
tests/test-api-tagsOpen
tests/test-fix-null-deref
Expand Down
5 changes: 4 additions & 1 deletion libreadtags/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ ACLOCAL_AMFLAGS = -I m4

AM_CFLAGS=-Wall

EXTRA_DIST = README.md NEWS.md

lib_LTLIBRARIES = libreadtags.la
libreadtags_la_LDFLAGS = -no-undefined -version-info $(LT_VERSION)
libreadtags_la_CFLAGS = $(GCOV_CFLAGS)

libreadtags_la_SOURCES = readtags.c readtags.h
nobase_include_HEADERS = readtags.h

EXTRA_DIST = libreadtags.pc.in
EXTRA_DIST += libreadtags.pc.in
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libreadtags.pc

Expand Down
16 changes: 16 additions & 0 deletions libreadtags/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Version 0.1.0

- propagate internal errors to caller

- LT_VERSION 1:0:0

- extend the API for the error propagation

- add tagsGetErrno function
- add tagErrno eum type

- break the API

- rename sortType to tagSortType for avoiding name conflictions
However, sortType is still defined as a macro.
See readtags.h
15 changes: 11 additions & 4 deletions libreadtags/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# libreadtags
libreadtags is a library for reading tags files generated by ctags.
libreadtags assumes the tags file format explained in [tags(5)](https://docs.ctags.io/en/latest/man/tags.5.html)
of Universal-ctags.

THIS REPOSITORY IS FOR TESTING.
DON'T FORK ME. THIS REPOSITORY WILL BE
DELETED AFTER TESTING.
See the comments at the top of readtags.h about the license and copyright.
libreadtags was derived from readtags.c of Exuberant-ctags.

NEWS.md describes note worty changes.

If you are looking for command line interface for tags files,
you will like [readtags command](https://docs.ctags.io/en/latest/man/readtags.1.html)
shipped as part of Universal-ctags. It uses libreadtags extensively.
32 changes: 29 additions & 3 deletions libreadtags/configure.ac
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# -*- Autoconf -*-
AC_INIT(libreadtags, 0.0.0)
AC_INIT(libreadtags, 0.1.0)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([readtags.c])

AM_INIT_AUTOMAKE
AC_PROG_LIBTOOL

# libtool -version-info
AC_SUBST(LT_VERSION, [0:0:0])
# LT_VERSION => CURRENT[:REVISION[:AGE]]
#
# (the following instructions are taken from configure.ac in libskk)
#
# If library source has changed since last release, increment revision
# If public symbols have been added, removed or changed since last release,
# increment current and set revision to 0
# If public symbols have been added since last release, increment age
# If public symbols have been removed since last release, set age to 0
#
# Revision history
#
# 0:0:0
# initial version; API is the same as readtags.h in Exuberant-ctags.
#
# 1:0:0
# introduced tagsGetErrno() and tagErrno.
# rename sortType to tagSortType.

AC_SUBST(LT_VERSION, [1:0:0])

AC_ARG_ENABLE([gcov],
[AS_HELP_STRING([--enable-gcov],
[enable 'gcov' coverage testing tool [no]])])
if test "${enable_gcov}" = "yes"; then
GCOV_CFLAGS="--coverage"
fi
AC_SUBST([GCOV_CFLAGS])

AC_PROG_CC_C99

Expand Down
Loading

0 comments on commit 09e9513

Please sign in to comment.