Merge branch 'tmp-doc-fixes' into 'master'

Doc fixes.  Version handling fixes.

See merge request gnutls/libtasn1!86
diff --git a/README.md b/README.md
index 20abcf2..b0305b9 100644
--- a/README.md
+++ b/README.md
@@ -35,18 +35,17 @@
 Debian/Ubuntu:
 ```
 sudo apt-get install make git autoconf automake libtool bison
-sudo apt-get install texinfo texlive texlive-extra-utils
-sudo apt-get install help2man gtk-doc-tools valgrind abigail-tools
+sudo apt-get install texinfo help2man gtk-doc-tools valgrind abigail-tools
 ```
 
-Debian <= stretch:
+PDF manual - Debian <= stretch:
 ```
-sudo apt-get install texlive-generic-recommended
+sudo apt-get install texlive-generic-recommended texlive texlive-extra-utils
 ```
 
-Debian >= buster:
+PDF manual - Debian >= buster:
 ```
-sudo apt-get install texlive-plain-generic
+sudo apt-get install texlive-plain-generic texlive texlive-extra-utils
 ```
 
 The next step is to run autoreconf, ./configure, etc:
diff --git a/configure.ac b/configure.ac
index 5389656..4df249c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@
 
 AC_SUBST([MAJOR_VERSION], [`echo $PACKAGE_VERSION|cut -d'.' -f1`])
 AC_SUBST([MINOR_VERSION], [`echo $PACKAGE_VERSION|cut -d'.' -f2`])
-AC_SUBST([PATCH_VERSION], [`echo $PACKAGE_VERSION|cut -d'.' -f3`])
+AC_SUBST([PATCH_VERSION], [`echo $PACKAGE_VERSION.0|cut -d. -f3|cut -d- -f1`])
 AC_SUBST([NUMBER_VERSION], [`printf '0x%02x%02x%02x' $MAJOR_VERSION $MINOR_VERSION $PATCH_VERSION`])
 
 AC_MSG_NOTICE([$PACKAGE_NAME $PACKAGE_VERSION $PACKAGE_TARNAME $MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION $NUMBER_VERSION $LT_CURRENT:$LT_REVISION:$LT_AGE $DLL_VERSION])
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 2032420..a0171a5 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -20,34 +20,45 @@
 SUBDIRS = reference
 endif
 
-EXTRA_DIST = gdoc TODO libtasn1.html libtasn1.ps libtasn1.pdf stamp_docs \
-	COPYING COPYING.LESSER
+EXTRA_DIST = gdoc TODO stamp_docs COPYING COPYING.LESSER
 
 info_TEXINFOS = libtasn1.texi
-libtasn1_TEXINFOS = fdl-1.3.texi texinfo.css $(gdoc_TEXINFOS)
+libtasn1_TEXINFOS = fdl-1.3.texi $(gdoc_TEXINFOS)
+libtasn1_TEXINFOS += asn1Coding-help.texi asn1Decoding-help.texi asn1Parser-help.texi
 
-AM_MAKEINFOHTMLFLAGS = $(AM_MAKEINFOFLAGS) \
-	--no-split --number-sections --css-include=texinfo.css
+AM_MAKEINFOHTMLFLAGS = --no-split $(AM_MAKEINFOFLAGS)
 
 dist_man_MANS = $(gdoc_MANS) asn1Parser.1 asn1Coding.1 asn1Decoding.1
 
 HELP2MAN_OPTS = --info-page libtasn1
 
-asn1Parser.1: $(top_srcdir)/src/asn1Parser.c $(top_srcdir)/configure.ac
-	$(HELP2MAN) $(HELP2MAN_OPTS) \
-		--name="ASN.1 syntax tree generator for libtasn1" \
-		--output=$@ $(top_builddir)/src/asn1Parser$(EXEEXT)
-
-asn1Coding.1: $(top_srcdir)/src/asn1Coding.c $(top_srcdir)/configure.ac
-	$(HELP2MAN) $(HELP2MAN_OPTS) \
+asn1Coding.1: $(top_srcdir)/src/asn1Coding.c $(top_srcdir)/.version
+	$(AM_V_GEN)$(HELP2MAN) $(HELP2MAN_OPTS) \
 		--name="ASN.1 DER encoder" \
 		--output=$@ $(top_builddir)/src/asn1Coding$(EXEEXT)
 
-asn1Decoding.1: $(top_srcdir)/src/asn1Decoding.c $(top_srcdir)/configure.ac
-	$(HELP2MAN) $(HELP2MAN_OPTS) \
+asn1Decoding.1: $(top_srcdir)/src/asn1Decoding.c $(top_srcdir)/.version
+	$(AM_V_GEN)$(HELP2MAN) $(HELP2MAN_OPTS) \
 		--name="ASN.1 DER decoder" \
 		--output=$@ $(top_builddir)/src/asn1Decoding$(EXEEXT)
 
+asn1Parser.1: $(top_srcdir)/src/asn1Parser.c $(top_srcdir)/.version
+	$(AM_V_GEN)$(HELP2MAN) $(HELP2MAN_OPTS) \
+		--name="ASN.1 syntax tree generator for libtasn1" \
+		--output=$@ $(top_builddir)/src/asn1Parser$(EXEEXT)
+
+asn1Coding-help.texi: $(top_srcdir)/src/asn1Coding.c
+	$(AM_V_GEN)$(top_builddir)/src/asn1Coding$(EXEEXT) --help > tmp-$@ && \
+		mv tmp-$@ asn1Coding-help.texi
+
+asn1Decoding-help.texi: $(top_srcdir)/src/asn1Decoding.c
+	$(AM_V_GEN)$(top_builddir)/src/asn1Decoding$(EXEEXT) --help > tmp-$@ && \
+		mv tmp-$@ asn1Decoding-help.texi
+
+asn1Parser-help.texi: $(top_srcdir)/src/asn1Parser.c
+	$(AM_V_GEN)$(top_builddir)/src/asn1Parser$(EXEEXT) --help > tmp-$@ && \
+		mv tmp-$@ asn1Parser-help.texi
+
 gdoc_MANS =
 gdoc_MANS += man/asn1_get_length_der.3
 gdoc_MANS += man/asn1_get_tag_der.3
@@ -172,7 +183,7 @@
 clean-local:
 	-rm -f stamp_docs
 
-stamp_docs:
+stamp_docs: $(top_srcdir)/.version
 	$(mkdir_p) man texi; \
 	for i in `$(srcdir)/gdoc -listfunc $(GDOC_SRC)`; do \
 		echo -n "Creating documentation for $$i... " && \
diff --git a/doc/gdoc b/doc/gdoc
index e3db762..d109399 100755
--- a/doc/gdoc
+++ b/doc/gdoc
@@ -1,8 +1,8 @@
-eval '(exit $?0)' && eval 'exec perl "$0" ${1+"$@"}'
-  & eval 'exec perl "$0" $argv:q'
+eval '(exit $?0)' && eval 'exec perl -S "$0" ${1+"$@"}'
+    & eval 'exec perl -S "$0" $argv:q'
     if 0;
 
-## Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Simon Josefsson
+## Copyright (c) 2002-2021 Simon Josefsson
 ##                    added -texinfo, -listfunc, -pkg-name
 ##                    man page revamp
 ##                    various improvements
@@ -104,14 +104,14 @@
 #  * my_function - does my stuff
 #  * @my_arg: its mine damnit
 #  *
-#  * Does my stuff explained. 
+#  * Does my stuff explained.
 #  */
 #
 #  or, could also use:
 # /**
 #  * my_function - does my stuff
 #  * @my_arg: its mine damnit
-#  * Description: Does my stuff explained. 
+#  * Description: Does my stuff explained.
 #  */
 # etc.
 #
@@ -303,7 +303,7 @@
 #  parameters => %parameter descriptions
 #  sectionlist => @list of sections
 #  sections => %descriont descriptions
-#  
+#
 
 sub just_highlight {
     my $contents = join "\n", @_;
@@ -1062,7 +1062,7 @@
 
 		$state = 0;
 	    }
-    
+
 	}
     }
 
diff --git a/doc/libtasn1.texi b/doc/libtasn1.texi
index 2879d28..c6dbfa4 100644
--- a/doc/libtasn1.texi
+++ b/doc/libtasn1.texi
@@ -313,16 +313,7 @@
 generates a
 file with an array to use with libtasn1 functions.
 
-@verbatim
-Usage:  asn1Parser [options] file
-
-Options:
- -h : shows the help message.
- -v : shows version information and exit.
- -c : checks the syntax only.
- -o file : output file.
- -n name : array name.
-@end verbatim
+@verbatiminclude asn1Parser-help.texi
 
 @node Invoking asn1Coding
 @section Invoking asn1Coding
@@ -349,16 +340,7 @@
 
 The output file is a binary file with the DER encoding.
 
-@verbatim
-Usage:  asn1Coding [options] file1 file2
- file1 : file with ASN1 definitions.
- file2 : file with assignments.
-Options:
- -h : shows the help message.
- -v : shows version information and exit.
- -c : checks the syntax only.
- -o file : output file.
-@end verbatim
+@verbatiminclude asn1Coding-help.texi
 
 For example, consider an ASN.1 definitions file as follows:
 
@@ -423,16 +405,7 @@
 ASN.1
 definitions and a binary file with a DER encoding.
 
-@verbatim
-Usage:  asn1Decoding [options] file1 file2 type
- file1 : file with ASN1 definitions.
- file2 : binary file with a DER encoding.
- type : ASN1 definition name.
-Options:
- -h : shows the help message.
- -v : shows version information and exit.
- -o file : output file.
-@end verbatim
+@verbatiminclude asn1Decoding-help.texi
 
 For example, after generating the @file{assign.out} file from the
 example section of the @command{asn1Coding} command above, the
diff --git a/tests/reproducers.c b/tests/reproducers.c
index daac910..cac6296 100644
--- a/tests/reproducers.c
+++ b/tests/reproducers.c
@@ -34,8 +34,8 @@
  * The following translates into a single node with all pointers
  * (right,left,down) set to NULL. */
 const asn1_static_node endless_asn1_tab[] = {
-  { "TEST_TREE", 536875024, NULL },
-  { NULL, 0, NULL }
+  {"TEST_TREE", 536875024, NULL},
+  {NULL, 0, NULL}
 };
 
 /* produces memory leak (fixed by f16d1ff9):
@@ -46,10 +46,10 @@
  *    by 0x10923B: main (single_node.c:67)
  */
 const asn1_static_node tab[] = {
-{ "a", CONST_DOWN, "" },
-{ "b", 0, "" },
-{ "c", 0, "" },
-{ NULL, 0, NULL }
+  {"a", CONST_DOWN, ""},
+  {"b", 0, ""},
+  {"c", 0, ""},
+  {NULL, 0, NULL}
 };
 
 int
@@ -58,6 +58,62 @@
   int result, verbose = 0;
   asn1_node definitions = NULL;
   char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE];
+  char *out = errorDescription;
+  int i;
+
+  printf ("Header version %s library version %s\n",
+	  ASN1_VERSION, asn1_check_version (NULL));
+
+  if (!asn1_check_version (ASN1_VERSION))
+    {
+      printf ("asn1_check_version failure\n");
+      exit (EXIT_FAILURE);
+    }
+
+  if (!asn1_check_version ("4.17.0"))
+    {
+      printf ("asn1_check_version(4.17.0) failure\n");
+      exit (EXIT_FAILURE);
+    }
+
+  if (!asn1_check_version ("4.17"))
+    {
+      printf ("asn1_check_version(4.17) failure\n");
+      exit (EXIT_FAILURE);
+    }
+
+  if (strcmp (ASN1_VERSION, asn1_check_version (NULL)) != 0)
+    {
+      printf ("header version mismatch library version\n");
+      exit (EXIT_FAILURE);
+    }
+
+  i = ASN1_VERSION_MAJOR * 256 * 256 +
+    ASN1_VERSION_MINOR * 256 + ASN1_VERSION_PATCH;
+
+  snprintf (out, ASN1_MAX_ERROR_DESCRIPTION_SIZE - 1, "%d.%d.%d",
+	    ASN1_VERSION_MAJOR, ASN1_VERSION_MINOR, ASN1_VERSION_PATCH);
+
+  printf ("Header version %s number %x derived %x\n", out,
+	  (unsigned) ASN1_VERSION_NUMBER, (unsigned) i);
+
+  if (ASN1_VERSION_NUMBER != i)
+    {
+      printf ("header version number mismatch\n");
+      exit (EXIT_FAILURE);
+    }
+
+  if (!asn1_check_version (out))
+    {
+      printf ("asn1_check_version(%s) failure\n", out);
+      exit (EXIT_FAILURE);
+    }
+
+  if (strncmp (ASN1_VERSION, out, strlen (out)) != 0)
+    {
+      printf ("header version numbers mismatch library version\n");
+      exit (EXIT_FAILURE);
+    }
 
   if (argc > 1)
     verbose = 1;