[PATCH] gendocs: update copyright footer year

2022-01-30 Thread Mike Frysinger
* doc/gendocs_template: Change 2020 to 2022.
---
 doc/gendocs_template | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/gendocs_template b/doc/gendocs_template
index c8c8fc610010..0415d947be65 100644
--- a/doc/gendocs_template
+++ b/doc/gendocs_template
@@ -87,7 +87,7 @@ the FSF.  Broken links and other corrections or suggestions 
can be sent
 to mailto:%%EMAIL%%";><%%EMAIL%%>.
 
 
-Copyright © 2020 Free Software Foundation, Inc.
+Copyright © 2022 Free Software Foundation, Inc.
 
 This page is licensed under a https://creativecommons.org/licenses/by-nd/3.0/us/";>Creative
-- 
2.34.1




Re: [PATCH] gendocs: update copyright footer year

2022-01-30 Thread Bruno Haible
> * doc/gendocs_template: Change 2020 to 2022.

Thanks. Applied.






Re: snippets/unused-parameter

2022-01-30 Thread Bruno Haible
Paul Eggert wrote:
> > My question is: What should i do w/ this module?
> > (a) Leave it alone -- "obsolete" is not "broken".
> 
> That's OK in the short term but in the long run I suggest using 
> _GL_UNUSED instead.

I would advise against that. Identifiers that begin with _GL are
Gnulib-private. That means, they can change their meaning or their
spelling, or go away entirely, at any moment. They are not part
of the formal interface of any module.

Instead, I would suggest to use a proper module with a defined
interface, namely the 'attribute' module. This module exports a
macro 'MAYBE_UNUSED', which is documented in attribute.h.

Bruno






new modules termcap, termcap-h

2022-01-30 Thread Bruno Haible
Another GNU package starts to make use of libtermcap [1][2]. By doing
so, it exhibits the usual portability problems:
  - It assumes that  exists. But these platforms don't have
it:
AIX, HP-UX, IRIX, Solaris, Android, Cygwin (opt.), mingw, MSVC.
  - It recognizes libtermcap and libcurses only when installed in
system location (which in particular does not allow testing with
the newest libncurses).

I'm adding modules 'termcap' and 'termcap-h', that fix these problems.
Taken from GNU gettext.

[1] 
https://git.savannah.gnu.org/gitweb/?p=poke.git;a=commitdiff;h=e8f74462660a40e73f1d0f5b0105309217e222e0
[2] 
https://git.savannah.gnu.org/gitweb/?p=poke.git;a=commitdiff;h=9146dc5305dd166c55e16c2998578aced15263f5


2022-01-30  Bruno Haible  

termcap: Add tests.
* tests/test-termcap.c: New file.
* modules/termcap-tests: New file.

termcap, termcap-h: New modules.
* lib/termcap.h: New file, from GNU gettext.
* lib/tparm.c: New file, from GNU gettext.
* lib/tputs.c: New file, from GNU gettext.
* m4/termcap.m4: New file, from GNU gettext.
* m4/curses.m4: New file, from GNU gettext.
* modules/termcap: New file, from GNU gettext.
* modules/termcap-h: New file, from GNU gettext.

>From b5443f091c678733b01e467632d0837458560918 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 30 Jan 2022 15:06:22 +0100
Subject: [PATCH 1/2] termcap, termcap-h: New modules.

* lib/termcap.h: New file, from GNU gettext.
* lib/tparm.c: New file, from GNU gettext.
* lib/tputs.c: New file, from GNU gettext.
* m4/termcap.m4: New file, from GNU gettext.
* m4/curses.m4: New file, from GNU gettext.
* modules/termcap: New file, from GNU gettext.
* modules/termcap-h: New file, from GNU gettext.
---
 ChangeLog |  11 +
 lib/termcap.h | 118 ++
 lib/tparm.c   | 897 ++
 lib/tputs.c   |  41 +++
 m4/curses.m4  |  16 +
 m4/termcap.m4 | 222 
 modules/termcap   |  29 ++
 modules/termcap-h |  21 ++
 8 files changed, 1355 insertions(+)
 create mode 100644 lib/termcap.h
 create mode 100644 lib/tparm.c
 create mode 100644 lib/tputs.c
 create mode 100644 m4/curses.m4
 create mode 100644 m4/termcap.m4
 create mode 100644 modules/termcap
 create mode 100644 modules/termcap-h

diff --git a/ChangeLog b/ChangeLog
index 11ab41d52b..9834bf973a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-01-30  Bruno Haible  
+
+	termcap, termcap-h: New modules.
+	* lib/termcap.h: New file, from GNU gettext.
+	* lib/tparm.c: New file, from GNU gettext.
+	* lib/tputs.c: New file, from GNU gettext.
+	* m4/termcap.m4: New file, from GNU gettext.
+	* m4/curses.m4: New file, from GNU gettext.
+	* modules/termcap: New file, from GNU gettext.
+	* modules/termcap-h: New file, from GNU gettext.
+
 2022-01-29  Bruno Haible  
 
 	doc: Clarify MSVC support.
diff --git a/lib/termcap.h b/lib/termcap.h
new file mode 100644
index 00..859c8994ce
--- /dev/null
+++ b/lib/termcap.h
@@ -0,0 +1,118 @@
+/* Information about terminal capabilities.
+   Copyright (C) 2006-2022 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation, either version 3 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see .  */
+
+/* Written by Bruno Haible , 2006.  */
+
+#ifndef _TERMCAP_H
+#define _TERMCAP_H
+
+/* Including  or  is dangerous, because it also declares
+   a lot of junk, such as variables PC, UP, and other.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if HAVE_TERMCAP
+
+/* Gets the capability information for terminal type TYPE.
+   BP must point to a buffer, at least 2048 bytes large.
+   Returns 1 if successful, 0 if TYPE is unknown, -1 on other error.  */
+extern int tgetent (char *bp, const char *type);
+
+/* Retrieves the value of a numerical capability.
+   Returns -1 if it is not available.  */
+extern int tgetnum (const char *id);
+
+/* Retrieves the value of a boolean capability.
+   Returns 1 if it available, 0 otherwise.  */
+extern int tgetflag (const char *id);
+
+/* Retrieves the value of a string capability.
+   Returns NULL if it is not available.
+   Also, if AREA != NULL, stores it at *AREA and advances *AREA.  */
+extern const char * tgetstr (const char *id, char **area);
+
+#endif
+
+#if HAVE_TERMINFO
+
+/* Gets the capability information for terminal type TYPE and prepares FD.
+   Returns 0 if successful, -1

new modules terminfo, terminfo-h

2022-01-30 Thread Bruno Haible
The module 'termcap' implements the old-style approach to terminal
capabilities. Since ca. 1997, the preferred approach is 'terminfo',
because:

  - 'termcap' has a buffer overflow problem in the API.
See 
section "Pitfalls of Long Entries".

  - The mnemonics of termcap capabilities are hard to remember.
See 
section 16.1.

  - Over time, new capabilities get added to 'terminfo' but not
to 'termcap'. Similarly, 'termcap' often does not know about
TERM=xterm256-color, but 'terminfo' does.

  - The traditional implementation of 'termcap' reads a huge
file with hundreds of terminal descriptions, although only one
is needed.

Therefore it's better to prefer 'terminfo' over 'termcap'. These
modules implement it.


2022-01-30  Bruno Haible  

terminfo: Add tests.
* tests/test-terminfo.c: New file.
* modules/terminfo-tests: New file.

terminfo, terminfo-h: New modules.
* lib/terminfo.h: New file, from GNU gettext.
* m4/terminfo.m4: New file, from GNU gettext.
* modules/terminfo: New file, from GNU gettext.
* modules/terminfo-h: New file, from GNU gettext.

>From a539037f3bf78ac6cd607cc21490bad587fa94b7 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Sun, 30 Jan 2022 16:44:27 +0100
Subject: [PATCH 1/2] terminfo, terminfo-h: New modules.

* lib/terminfo.h: New file, from GNU gettext.
* m4/terminfo.m4: New file, from GNU gettext.
* modules/terminfo: New file, from GNU gettext.
* modules/terminfo-h: New file, from GNU gettext.
---
 ChangeLog  |   8 +
 lib/terminfo.h | 116 +
 m4/terminfo.m4 | 401 +
 modules/terminfo   |  29 
 modules/terminfo-h |  21 +++
 5 files changed, 575 insertions(+)
 create mode 100644 lib/terminfo.h
 create mode 100644 m4/terminfo.m4
 create mode 100644 modules/terminfo
 create mode 100644 modules/terminfo-h

diff --git a/ChangeLog b/ChangeLog
index e4cd2b65e6..16e2955418 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-01-30  Bruno Haible  
+
+	terminfo, terminfo-h: New modules.
+	* lib/terminfo.h: New file, from GNU gettext.
+	* m4/terminfo.m4: New file, from GNU gettext.
+	* modules/terminfo: New file, from GNU gettext.
+	* modules/terminfo-h: New file, from GNU gettext.
+
 2022-01-30  Bruno Haible  
 
 	termcap: Add tests.
diff --git a/lib/terminfo.h b/lib/terminfo.h
new file mode 100644
index 00..d542ef2d55
--- /dev/null
+++ b/lib/terminfo.h
@@ -0,0 +1,116 @@
+/* Information about terminal capabilities.
+   Copyright (C) 2006-2022 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation, either version 3 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see .  */
+
+/* Written by Bruno Haible , 2006.  */
+
+#ifndef _TERMINFO_H
+#define _TERMINFO_H
+
+/* Including  or  is dangerous, because it also declares
+   a lot of junk, such as variables PC, UP, and other.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if HAVE_TERMINFO
+
+/* Gets the capability information for terminal type TYPE and prepares FD.
+   Returns 0 if successful, -1 upon error.  If ERRP is non-NULL, also returns
+   an error indicator in *ERRP; otherwise an error is signalled.  */
+extern int setupterm (const char *type, int fd, int *errp);
+
+/* Retrieves the value of a numerical capability.
+   Returns -1 if it is not available, -2 if ID is invalid.  */
+extern int tigetnum (const char *id);
+
+/* Retrieves the value of a boolean capability.
+   Returns 1 if it available, 0 if not available, -1 if ID is invalid.  */
+extern int tigetflag (const char *id);
+
+/* Retrieves the value of a string capability.
+   Returns NULL if it is not available, (char *)(-1) if ID is invalid.  */
+extern const char * tigetstr (const char *id);
+
+#elif HAVE_TERMCAP
+
+/* Gets the capability information for terminal type TYPE.
+   BP must point to a buffer, at least 2048 bytes large.
+   Returns 1 if successful, 0 if TYPE is unknown, -1 on other error.  */
+extern int tgetent (char *bp, const char *type);
+
+/* Retrieves the value of a numerical capability.
+   Returns -1 if it is not available.  */
+extern int tgetnum (const char *id);
+
+/* Retrieves the value of a boolean capability.
+   Returns 1 if it available, 0 otherwise.  */
+extern int tgetflag (const char *id);
+
+

argmatch: add variants that only match full argument

2022-01-30 Thread Pádraig Brady
I would like a more constrained argument matching
to improve forward compatibility and robustness.

For example I would like `cksum -a sha3` to _not_
be equivalent to `cksum -a sha386`, so that a user
specifying `-a sha3` on an older cksum would not be surprised.
Also argmatch() is used when parsing tags from lines like:
SHA3 (filename) = abcedf
so it's more robust that older cksum instances to fail
earlier in the parsing process, when parsing output from
possible future cksum implementations that might support SHA3.





[PATCH] argmatch: add variants that only match full argument

2022-01-30 Thread Pádraig Brady
* lib/argmatch.h (argmatch_exact, [X]ARGMATCH_EXACT): New interfaces
that don't support abbreviations.
* lib/argmatch.c (argmatch_exact, __xargmatch_exact_internal): Likewise.
* tests/test-argmatch.c: Add tests.
---
 ChangeLog |  8 
 lib/argmatch.c| 37 +
 lib/argmatch.h| 17 +
 tests/test-argmatch.c | 23 +++
 4 files changed, 85 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 4c9a1e7989..e51a00190a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-01-30  Pádraig Brady  
+
+   argmatch: add variants that only match full argument
+   * lib/argmatch.h (argmatch_exact, [X]ARGMATCH_EXACT): New interfaces
+   that don't support abbreviations.
+   * lib/argmatch.c (argmatch_exact, __xargmatch_exact_internal): Likewise.
+   * tests/test-argmatch.c: Add tests.
+
 2022-01-30  Bruno Haible  
 
terminfo: Add tests.
diff --git a/lib/argmatch.c b/lib/argmatch.c
index 9e3232f947..71059e8f7e 100644
--- a/lib/argmatch.c
+++ b/lib/argmatch.c
@@ -120,6 +120,24 @@ argmatch (const char *arg, const char *const *arglist,
 return matchind;
 }
 
+ptrdiff_t
+argmatch_exact (const char *arg, const char *const *arglist)
+{
+  size_t i;
+
+  /* Test elements for exact match.  */
+  for (i = 0; arglist[i]; i++)
+{
+  if (!strcmp (arglist[i], arg))
+{
+  /* Exact match found.  */
+  return i;
+}
+}
+
+  return -1;
+}
+
 /* Error reporting for argmatch.
CONTEXT is a description of the type of entity that was being matched.
VALUE is the invalid value that was given.
@@ -189,6 +207,25 @@ __xargmatch_internal (const char *context,
   return -1; /* To please the compilers. */
 }
 
+ptrdiff_t
+__xargmatch_exact_internal (const char *context,
+const char *arg, const char *const *arglist,
+const void *vallist, size_t valsize,
+argmatch_exit_fn exit_fn)
+{
+  ptrdiff_t res = argmatch_exact (arg, arglist);
+  if (res >= 0)
+/* Success. */
+return res;
+
+  /* We failed.  Explain why. */
+  argmatch_invalid (context, arg, res);
+  argmatch_valid (arglist, vallist, valsize);
+  (*exit_fn) ();
+
+  return -1; /* To please the compilers. */
+}
+
 /* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
return the first corresponding argument in ARGLIST */
 const char *
diff --git a/lib/argmatch.h b/lib/argmatch.h
index a2364b5a2e..c6d24d981c 100644
--- a/lib/argmatch.h
+++ b/lib/argmatch.h
@@ -52,9 +52,15 @@ extern "C" {
 ptrdiff_t argmatch (char const *arg, char const *const *arglist,
 void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
 
+ptrdiff_t argmatch_exact (char const *arg, char const *const *arglist)
+  _GL_ATTRIBUTE_PURE;
+
 # define ARGMATCH(Arg, Arglist, Vallist) \
   argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist))
 
+# define ARGMATCH_EXACT(Arg, Arglist) \
+  argmatch_exact (Arg, Arglist)
+
 /* xargmatch calls this function when it fails.  This function should not
return.  By default, this is a function that calls ARGMATCH_DIE which
in turn defaults to 'exit (exit_failure)'.  */
@@ -91,6 +97,11 @@ ptrdiff_t __xargmatch_internal (char const *context,
 void const *vallist, size_t valsize,
 argmatch_exit_fn exit_fn);
 
+ptrdiff_t __xargmatch_exact_internal (char const *context,
+char const *arg, char const *const *arglist,
+void const *vallist, size_t valsize,
+argmatch_exit_fn exit_fn);
+
 /* Programmer friendly interface to __xargmatch_internal. */
 
 # define XARGMATCH(Context, Arg, Arglist, Vallist)  \
@@ -99,6 +110,12 @@ ptrdiff_t __xargmatch_internal (char const *context,
 sizeof *(Vallist),  \
 argmatch_die)])
 
+# define XARGMATCH_EXACT(Context, Arg, Arglist, Vallist)\
+  ((Vallist) [__xargmatch_exact_internal (Context, Arg, Arglist,\
+(void const *) (Vallist),   \
+sizeof *(Vallist),  \
+argmatch_die)])
+
 /* Convert a value into a corresponding argument. */
 
 char const *argmatch_to_argument (void const *value,
diff --git a/tests/test-argmatch.c b/tests/test-argmatch.c
index 8345150002..46a7f07153 100644
--- a/tests/test-argmatch.c
+++ b/tests/test-argmatch.c
@@ -125,37 +125,60 @@ main (int argc, char *argv[])
   } \
   } while (0)
 
+#define CHECK_EXACT(Input, Output)  \
+  do {  \
+ASSERT (ARGMATCH_EXACT (Input, backup_arg

Re: [PATCH] argmatch: add variants that only match full argument

2022-01-30 Thread Bruno Haible
Pádraig Brady wrote:
> * lib/argmatch.h (argmatch_exact, [X]ARGMATCH_EXACT): New interfaces
> that don't support abbreviations.
> * lib/argmatch.c (argmatch_exact, __xargmatch_exact_internal): Likewise.
> * tests/test-argmatch.c: Add tests.

The code looks correct. But I see some code duplication:
__xargmatch_exact_internal and __xargmatch_internal are very similar.
Given that both of these functions are only invoked through macros, how
about merging them into a single function? Namely, by adding an argument
of type 'bool exactp'.

Bruno






Re: [PATCH] argmatch: add variants that only match full argument

2022-01-30 Thread Pádraig Brady

On 30/01/2022 18:58, Bruno Haible wrote:

Pádraig Brady wrote:

* lib/argmatch.h (argmatch_exact, [X]ARGMATCH_EXACT): New interfaces
that don't support abbreviations.
* lib/argmatch.c (argmatch_exact, __xargmatch_exact_internal): Likewise.
* tests/test-argmatch.c: Add tests.


The code looks correct. But I see some code duplication:
__xargmatch_exact_internal and __xargmatch_internal are very similar.
Given that both of these functions are only invoked through macros, how
about merging them into a single function? Namely, by adding an argument
of type 'bool exactp'.

Bruno


Good call.
I pushed with that adjustment.

Thanks for the review.
Pádraig