diff --git a/CHANGES b/CHANGES index d7ed109..740f0a4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +2021-08-02 Thomas E. Dickey + + * main.c, yacc.1: add "-h" option + + * test/btyacc/no_b_opt.error, test/btyacc/no_output2.error, test/btyacc/no_p_opt.error, test/btyacc/big_b.error, test/btyacc/big_l.error, test/btyacc/help.error, test/btyacc/nostdin.error, test/yacc/big_b.error, test/yacc/big_l.error, test/yacc/help.error, test/yacc/no_b_opt.error, test/yacc/no_output2.error, test/yacc/no_p_opt.error, test/yacc/nostdin.error: + regen + + * main.c: + map any of bison's long-options which have a corresponding yacc option + into the latter, without depending upon getopt_long(). + + * main.c: suggested patch: + From: Boris Kolpackov + Subject: Re: [PATCH] support bison's --defines and --output options in byacc + + * VERSION, package/byacc.spec, package/debian/changelog, package/mingw-byacc.spec, package/pkgsrc/Makefile: + bump + 2021-08-01 Thomas E. Dickey * test/btyacc/inherit2.tab.c, test/btyacc/btyacc_destroy2.tab.c, test/btyacc/btyacc_destroy3.tab.c, test/btyacc/err_inherit3.tab.c, test/btyacc/err_inherit4.tab.c, test/btyacc/btyacc_demo.tab.c, test/btyacc/btyacc_destroy1.tab.c: diff --git a/MANIFEST b/MANIFEST index 21a2217..97fb32a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,4 +1,4 @@ -MANIFEST for byacc, version t20210801 +MANIFEST for byacc, version t20210802 -------------------------------------------------------------------------------- MANIFEST this file ACKNOWLEDGEMENTS original version of byacc - 1993 diff --git a/VERSION b/VERSION index 53bb87b..eb77dcf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -20210801 +20210802 diff --git a/main.c b/main.c index 4922e2b..8582f20 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.70 2020/09/10 17:32:55 tom Exp $ */ +/* $Id: main.c,v 1.72 2021/08/03 00:01:28 tom Exp $ */ #include #if !defined(_WIN32) || defined(__MINGW32__) @@ -201,40 +201,89 @@ set_signals(void) #endif } +#define SIZEOF(v) (sizeof(v) / sizeof((v)[0])) + +/* + * Long options are provided only as a compatibility aid for scripters. + */ +/* *INDENT-OFF* */ +static const struct { + const char long_opt[16]; + const char yacc_arg; + const char yacc_opt; +} long_opts[] = { + { "defines", 1, 'H' }, + { "file-prefix", 1, 'b' }, + { "graph", 0, 'g' }, + { "help", 0, 'h' }, + { "name-prefix", 1, 'p' }, + { "no-lines", 0, 'l' }, + { "output", 1, 'o' }, + { "version", 0, 'V' } +}; +/* *INDENT-ON* */ + +/* + * Usage-message is designed for 80 columns, with some unknowns. Account for + * those in the maximum width so that the usage message uses no relocatable + * pointers. + */ +#define USAGE_COLS (80 + sizeof(DEFINES_SUFFIX) + sizeof(OUTPUT_SUFFIX)) + static void usage(void) { - static const char *msg[] = + /* *INDENT-OFF* */ + static const char msg[][USAGE_COLS] = { - "" - ,"Options:" - ," -b file_prefix set filename prefix (default \"y.\")" - ," -B create a backtracking parser" - ," -d write definitions (" DEFINES_SUFFIX ")" - ," -H defines_file write definitions to defines_file" - ," -i write interface (y.tab.i)" - ," -g write a graphical description" - ," -l suppress #line directives" - ," -L enable position processing, e.g., \"%locations\"" - ," -o output_file (default \"" OUTPUT_SUFFIX "\")" - ," -p symbol_prefix set symbol prefix (default \"yy\")" - ," -P create a reentrant parser, e.g., \"%pure-parser\"" - ," -r produce separate code and table files (y.code.c)" - ," -s suppress #define's for quoted names in %token lines" - ," -t add debugging support" - ," -v write description (y.output)" - ," -V show version information and exit" + { " -b file_prefix set filename prefix (default \"y.\")" }, + { " -B create a backtracking parser" }, + { " -d write definitions (" DEFINES_SUFFIX ")" }, + { " -h print this help-message" }, + { " -H defines_file write definitions to defines_file" }, + { " -i write interface (y.tab.i)" }, + { " -g write a graphical description" }, + { " -l suppress #line directives" }, + { " -L enable position processing, e.g., \"%locations\"" }, + { " -o output_file (default \"" OUTPUT_SUFFIX "\")" }, + { " -p symbol_prefix set symbol prefix (default \"yy\")" }, + { " -P create a reentrant parser, e.g., \"%pure-parser\"" }, + { " -r produce separate code and table files (y.code.c)" }, + { " -s suppress #define's for quoted names in %token lines" }, + { " -t add debugging support" }, + { " -v write description (y.output)" }, + { " -V show version information and exit" }, }; + /* *INDENT-ON* */ unsigned n; fflush(stdout); fprintf(stderr, "Usage: %s [options] filename\n", myname); - for (n = 0; n < sizeof(msg) / sizeof(msg[0]); ++n) + + fprintf(stderr, "\nOptions:\n"); + for (n = 0; n < SIZEOF(msg); ++n) + { fprintf(stderr, "%s\n", msg[n]); + } + + fprintf(stderr, "\nLong options:\n"); + for (n = 0; n < SIZEOF(long_opts); ++n) + { + fprintf(stderr, " --%-20s-%c\n", + long_opts[n].long_opt, + long_opts[n].yacc_opt); + } exit(EXIT_FAILURE); } +static void +invalid_option(const char *option) +{ + fprintf(stderr, "invalid option: %s\n", option); + usage(); +} + static void setflag(int ch) { @@ -313,17 +362,66 @@ getargs(int argc, char *argv[]) int i; #ifdef HAVE_GETOPT int ch; +#endif + /* + * Map bison's long-options into yacc short options. + */ + for (i = 1; i < argc; ++i) + { + char *a = argv[i]; + + if (!strncmp(a, "--", 2)) + { + char *eqls; + size_t lc; + size_t len; + + if ((len = strlen(a)) == 2) + break; + + if ((eqls = strchr(a, '=')) != NULL) + { + len = (size_t)(eqls - a); + if (len == 0 || eqls[1] == '\0') + invalid_option(a); + } + + for (lc = 0; lc < SIZEOF(long_opts); ++lc) + { + if (!strncmp(long_opts[lc].long_opt, a + 2, len - 2)) + { + if (eqls != NULL && !long_opts[lc].yacc_arg) + invalid_option(a); + *a++ = '-'; + *a++ = long_opts[lc].yacc_opt; + *a = '\0'; + if (eqls) + { + while ((*a++ = *++eqls) != '\0') /* empty */ ; + } + break; + } + } + if (!strncmp(a, "--", 2)) + invalid_option(a); + } + } + +#ifdef HAVE_GETOPT if (argc > 0) myname = argv[0]; - while ((ch = getopt(argc, argv, "Bb:dgH:ilLo:Pp:rstVvy")) != -1) + while ((ch = getopt(argc, argv, "Bb:dghH:ilLo:Pp:rstVvy")) != -1) { switch (ch) { case 'b': file_prefix = optarg; break; + case 'h': + usage(); + break; case 'H': dflag = dflag2 = 1; defines_file_name = optarg; @@ -509,7 +607,7 @@ create_file_names(void) if (suffix != NULL) { - len = (size_t) (suffix - output_file_name); + len = (size_t)(suffix - output_file_name); file_prefix = TMALLOC(char, len + 1); NO_SPACE(file_prefix); strncpy(file_prefix, output_file_name, len)[len] = 0; diff --git a/package/byacc.spec b/package/byacc.spec index f203ea9..6fe5ae9 100644 --- a/package/byacc.spec +++ b/package/byacc.spec @@ -1,9 +1,9 @@ Summary: byacc - public domain Berkeley LALR Yacc parser generator %define AppProgram byacc %define AltProgram btyacc -%define AppVersion 20210801 +%define AppVersion 20210802 %define UseProgram yacc -# $Id: byacc.spec,v 1.57 2021/08/01 19:30:22 tom Exp $ +# $Id: byacc.spec,v 1.58 2021/08/02 20:50:01 tom Exp $ Name: %{AppProgram} Version: %{AppVersion} Release: 1 diff --git a/package/debian/changelog b/package/debian/changelog index f2d0dc0..710f758 100644 --- a/package/debian/changelog +++ b/package/debian/changelog @@ -1,3 +1,9 @@ +byacc (20210802) unstable; urgency=low + + * maintenance updates + + -- Thomas E. Dickey Mon, 02 Aug 2021 16:50:01 -0400 + byacc (20210801) unstable; urgency=low * maintenance updates diff --git a/package/mingw-byacc.spec b/package/mingw-byacc.spec index a5adf02..6e2da47 100644 --- a/package/mingw-byacc.spec +++ b/package/mingw-byacc.spec @@ -1,8 +1,8 @@ Summary: byacc - public domain Berkeley LALR Yacc parser generator %define AppProgram byacc -%define AppVersion 20210801 +%define AppVersion 20210802 %define UseProgram yacc -# $Id: mingw-byacc.spec,v 1.35 2021/08/01 19:30:22 tom Exp $ +# $Id: mingw-byacc.spec,v 1.36 2021/08/02 20:50:01 tom Exp $ Name: %{AppProgram} Version: %{AppVersion} Release: 1 diff --git a/package/pkgsrc/Makefile b/package/pkgsrc/Makefile index 659f90a..c686873 100644 --- a/package/pkgsrc/Makefile +++ b/package/pkgsrc/Makefile @@ -1,7 +1,7 @@ # $NetBSD: Makefile,v 1.9 2008/07/24 17:13:00 tonnerre Exp $ # -DISTNAME= byacc-20210801 +DISTNAME= byacc-20210802 PKGREVISION= 1 CATEGORIES= devel MASTER_SITES= ftp://ftp.invisible-island.net/byacc/ diff --git a/test/btyacc/big_b.error b/test/btyacc/big_b.error index 6710162..7f74f49 100644 --- a/test/btyacc/big_b.error +++ b/test/btyacc/big_b.error @@ -4,6 +4,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -17,3 +18,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/big_l.error b/test/btyacc/big_l.error index 6710162..7f74f49 100644 --- a/test/btyacc/big_l.error +++ b/test/btyacc/big_l.error @@ -4,6 +4,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -17,3 +18,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/help.error b/test/btyacc/help.error index f69a74a..c4d890b 100644 --- a/test/btyacc/help.error +++ b/test/btyacc/help.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/no_b_opt.error b/test/btyacc/no_b_opt.error index f69a74a..c4d890b 100644 --- a/test/btyacc/no_b_opt.error +++ b/test/btyacc/no_b_opt.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/no_output2.error b/test/btyacc/no_output2.error index f69a74a..c4d890b 100644 --- a/test/btyacc/no_output2.error +++ b/test/btyacc/no_output2.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/no_p_opt.error b/test/btyacc/no_p_opt.error index f69a74a..c4d890b 100644 --- a/test/btyacc/no_p_opt.error +++ b/test/btyacc/no_p_opt.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/btyacc/nostdin.error b/test/btyacc/nostdin.error index 6710162..7f74f49 100644 --- a/test/btyacc/nostdin.error +++ b/test/btyacc/nostdin.error @@ -4,6 +4,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -17,3 +18,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/big_b.error b/test/yacc/big_b.error index 7019fde..6c3442b 100644 --- a/test/yacc/big_b.error +++ b/test/yacc/big_b.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/big_l.error b/test/yacc/big_l.error index be9f02a..8ca4221 100644 --- a/test/yacc/big_l.error +++ b/test/yacc/big_l.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/help.error b/test/yacc/help.error index f69a74a..c4d890b 100644 --- a/test/yacc/help.error +++ b/test/yacc/help.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/no_b_opt.error b/test/yacc/no_b_opt.error index f69a74a..c4d890b 100644 --- a/test/yacc/no_b_opt.error +++ b/test/yacc/no_b_opt.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/no_output2.error b/test/yacc/no_output2.error index f69a74a..c4d890b 100644 --- a/test/yacc/no_output2.error +++ b/test/yacc/no_output2.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/no_p_opt.error b/test/yacc/no_p_opt.error index f69a74a..c4d890b 100644 --- a/test/yacc/no_p_opt.error +++ b/test/yacc/no_p_opt.error @@ -5,6 +5,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -18,3 +19,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/test/yacc/nostdin.error b/test/yacc/nostdin.error index 6710162..7f74f49 100644 --- a/test/yacc/nostdin.error +++ b/test/yacc/nostdin.error @@ -4,6 +4,7 @@ Options: -b file_prefix set filename prefix (default "y.") -B create a backtracking parser -d write definitions (.tab.h) + -h print this help-message -H defines_file write definitions to defines_file -i write interface (y.tab.i) -g write a graphical description @@ -17,3 +18,13 @@ Options: -t add debugging support -v write description (y.output) -V show version information and exit + +Long options: + --defines -H + --file-prefix -b + --graph -g + --help -h + --name-prefix -p + --no-lines -l + --output -o + --version -V diff --git a/yacc.1 b/yacc.1 index 8fab760..9173d20 100644 --- a/yacc.1 +++ b/yacc.1 @@ -1,4 +1,4 @@ -.\" $Id: yacc.1,v 1.36 2021/03/28 16:39:46 tom Exp $ +.\" $Id: yacc.1,v 1.37 2021/08/02 23:55:03 tom Exp $ .\" .\" .TH YACC 1 "July\ 15,\ 1990" .\" .UC 6 @@ -31,7 +31,7 @@ .SH NAME \*N \- an LALR(1) parser generator .SH SYNOPSIS -.B \*n [ \-BdgilLPrtvVy ] [ \-b +.B \*n [ \-BdghilLPrtvVy ] [ \-b .I file_prefix .B ] [ \-H .I defines_file @@ -72,6 +72,9 @@ causes the header file to be written. It contains #define's for the token identifiers. .TP +.B \-h +print a usage message. +.TP \fB\-H \fP\fIdefines_file\fR causes #define's for the token identifiers to be written to the given \fIdefines_file\fP rather @@ -204,6 +207,7 @@ A single \fIfilename\fP parameter is expected after a \*(``\-\-\*('' marker. .B \*N provides some extensions for compatibility with bison and other implementations of yacc. +It accepts several \fIlong options\fP which have equivalents in \*n. The \fB%destructor\fP and \fB%locations\fP features are available only if \fB\*n\fP has been configured and compiled to support the back-tracking (\fBbtyacc\fP) functionality.