diff --git a/ChangeLog b/ChangeLog index 89e6bf00..4805ec41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,32 @@ 2007-11-29 James Youngman + Support the generation of regexprops-generic.texi. + * lib/regextype.h (get_regex_type_context): Used to indicate if a + particular type of regular expression is of interest for + regexprops.texi (which is findutils-specific) or + regexprops-generic.texi (which is not). The "context" is simply + a flag set in a word. + * lib/regextype.c (get_regex_type_context): Implement this. + (regex_map): Assign a context to each regular expression type. + * lib/regexprops.c: Use the context information from regextype.c + to decide which regular expression types to docuemnt in the + output. The selection is indicated on the command line; "generic" + and "findutils" are supported. + (copying): New function, which emits a copyright header into the + output. + (comment): New function for emitting a comment. + (ignore): New function which returns nonzero when the indicated + type of regular expression is not of interest for this version of + the document. + (menu): Miss out the non-interesteing regex types. + (get_next): Returns the regex type name for the "next" pointer, + taking into account which regex types are ignored. + (describe_all): Take into account which regex types are ignored, + and emit a copying header also. Include a comment indicating + which "context" was of interest when generating the output. + * doc/Makefile.am: Add regexprops-generic.texi. Generate this + file from regexprops.c. + Check gnulib out with native git, rather than git-cvspserver. This fixes Savannah bug #21568, for the second time. * import-gnulib.config (gnulib_version): Switch to using a git diff --git a/doc/Makefile.am b/doc/Makefile.am index 9ea014aa..2e085531 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -9,7 +9,7 @@ CLEANFILES = find.txt find_mono.html findutils.texi_html_node.tar.gz # binary. When this is the case, we use a workaround; don't delete the # file for 'make clean'. This fixes Savannah bug #19658. if !CROSS_COMPILING -CLEANFILES += regexprops.texi +CLEANFILES += regexprops.texi regexprops-generic.texi endif MAKEINFOTXT = $(MAKEINFO) --plaintext @@ -61,11 +61,15 @@ findutils.texi_html_node.tar.gz: find.html tar zcf $@ $< if CROSS_COMPILING -regexprops.texi: ../gnulib/lib/regex.h +regexprops.texi regexprops-generic.texi: ../gnulib/lib/regex.h echo "WARNING: $? is newer than $@ but $@ cannot be rebuilt because we are cross-compiling. Continuing anyway." >&2 else -regexprops.texi: ../gnulib/lib/regex.h +regexprops.texi: ../gnulib/lib/regex.h ../lib/regexprops.c cd ../lib && $(MAKE) $(AM_MAKEFLAGS) regexprops$(EXEEXT) - ../lib/regexprops$(EXEEXT) "Regular Expressions" > $@ + ../lib/regexprops$(EXEEXT) "Regular Expressions" findutils > $@ + rm ../lib/regexprops$(EXEEXT) +regexprops-generic.texi: ../gnulib/lib/regex.h ../lib/regexprops.c + cd ../lib && $(MAKE) $(AM_MAKEFLAGS) regexprops$(EXEEXT) + ../lib/regexprops$(EXEEXT) "Regular Expressions" generic > $@ rm ../lib/regexprops$(EXEEXT) endif diff --git a/lib/regexprops.c b/lib/regexprops.c index 9d7ef790..e6e89ed4 100644 --- a/lib/regexprops.c +++ b/lib/regexprops.c @@ -1,7 +1,7 @@ /* regexprops.c -- document the properties of the regular expressions understood by gnulib. - Copyright 2005 Free Software Foundation, Inc. + Copyright 2005, 2007 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,12 +17,20 @@ along with this program. If not, see . */ + +/* + The output of this program is included in the GNU findutils source + distribution. The copying conditions for that file are generated + by the copying() function below. +*/ + /* Written by James Youngman, . */ #include #include +#include #include #include @@ -61,6 +69,13 @@ static void directive(const char *s) output(s, 0); } +static void comment(const char *s) +{ + directive("@c "); + literal(s); + newline(); +} + static void enum_item(const char *s) { newline(); @@ -419,9 +434,35 @@ describe_regex_syntax(int options) } +static void copying(void) +{ + static const char *copy_para[]= + { + "Copyright (C) 1994, 1996, 1998, 2000, 2001, 2003, 2004, 2005, 2006, 2007" + ,"Free Software Foundation, Inc." + ,"" + ,"Permission is granted to copy, distribute and/or modify this document" + ,"under the terms of the GNU Free Documentation License, Version 1.2 or" + ,"any later version published by the Free Software Foundation; with no" + ,"Invariant Sections, with no Front-Cover Texts, and with no Back-Cover" + ,"Texts. A copy of the license is included in the ``GNU Free" + ,"Documentation License'' file as part of this distribution." + "" + ,NULL + }; + const char **s = copy_para; + while (*s) + comment(*s++); +} + +static int +ignore(int ix, const unsigned int context) +{ + return 0 == (get_regex_type_context(ix) & context); +} static void -menu(void) +menu(unsigned int context) { int i, options; const char *name; @@ -432,24 +473,56 @@ menu(void) name=get_regex_type_name(i); ++i) { - output("* ", 0); - output(name, 0); - content(" regular expression syntax"); - output("::", 0); - newline(); + if (!ignore(i, context)) + { + output("* ", 0); + output(name, 0); + content(" regular expression syntax"); + output("::", 0); + newline(); + } } output("@end menu\n", 0); } + +static const char * +get_next(unsigned int ix, unsigned int context) +{ + const char *next; + while (get_regex_type_name(ix)) + { + if (!ignore(ix, context)) + { + next = get_regex_type_name(ix); + if (NULL == next) + return ""; + else + return next; + } + ++ix; + } + return ""; +} + + static void -describe_all(const char *up) +describe_all(const char *contextname, + unsigned int context, + const char *up) { const char *name, *next, *previous; int options; int i, parent; - menu(); + copying(); + newline(); + literal("@c this regular expression description is for: "); + literal(contextname); + newline(); + newline(); + menu(context); previous = ""; @@ -458,7 +531,16 @@ describe_all(const char *up) name=get_regex_type_name(i); ++i) { - next = get_regex_type_name(i+1); + if (ignore(i, context)) + { + fprintf(stderr, + "Skipping regexp type %s for context %s\n", + name, contextname); + name = previous; + continue; + } + + next = get_next(i+1, context); if (NULL == next) next = ""; begin_subsection(name, next, previous, up); @@ -482,11 +564,31 @@ describe_all(const char *up) int main (int argc, char *argv[]) { const char *up = ""; + unsigned int context = CONTEXT_ALL; + const char *contextname = "all"; program_name = argv[0]; if (argc > 1) - up = argv[1]; + { + up = argv[1]; + } + if (argc > 2) + { + contextname = argv[2]; + if (0 == strcmp(contextname, "findutils")) + context = CONTEXT_FINDUTILS; + else if (0 == strcmp(contextname, "generic")) + context = CONTEXT_GENERIC; + else if (0 == strcmp(contextname, "all")) + context = CONTEXT_ALL; + else + { + fprintf(stderr, "Unexpected context %s", + contextname); + return 1; + } + } - describe_all(up); + describe_all(contextname, context, up); return 0; } diff --git a/lib/regextype.c b/lib/regextype.c index 73e4819b..e060244e 100644 --- a/lib/regextype.c +++ b/lib/regextype.c @@ -47,35 +47,29 @@ #endif - struct tagRegexTypeMap { char *name; + int context; int option_val; }; struct tagRegexTypeMap regex_map[] = { -#ifdef FINDUTILS - { "findutils-default", RE_SYNTAX_EMACS|RE_DOT_NEWLINE }, -#endif - { "awk", RE_SYNTAX_AWK }, - { "egrep", RE_SYNTAX_EGREP }, -#ifndef FINDUTILS - { "ed", RE_SYNTAX_ED }, -#endif - { "emacs", RE_SYNTAX_EMACS }, - { "gnu-awk", RE_SYNTAX_GNU_AWK }, - { "grep", RE_SYNTAX_GREP }, - { "posix-awk", RE_SYNTAX_POSIX_AWK }, - { "posix-basic", RE_SYNTAX_POSIX_BASIC }, - { "posix-egrep", RE_SYNTAX_POSIX_EGREP }, - { "posix-extended", RE_SYNTAX_POSIX_EXTENDED }, -#ifndef FINDUTILS - { "posix-minimal-basic", RE_SYNTAX_POSIX_MINIMAL_BASIC }, - { "sed", RE_SYNTAX_SED }, - /* ,{ "posix-common", _RE_SYNTAX_POSIX_COMMON } */ -#endif + { "findutils-default", CONTEXT_FINDUTILS, RE_SYNTAX_EMACS|RE_DOT_NEWLINE }, + { "awk", CONTEXT_ALL, RE_SYNTAX_AWK }, + { "egrep", CONTEXT_ALL, RE_SYNTAX_EGREP }, + { "ed", CONTEXT_GENERIC, RE_SYNTAX_ED }, + { "emacs", CONTEXT_ALL, RE_SYNTAX_EMACS }, + { "gnu-awk", CONTEXT_ALL, RE_SYNTAX_GNU_AWK }, + { "grep", CONTEXT_ALL, RE_SYNTAX_GREP }, + { "posix-awk", CONTEXT_ALL, RE_SYNTAX_POSIX_AWK }, + { "posix-basic", CONTEXT_ALL, RE_SYNTAX_POSIX_BASIC }, + { "posix-egrep", CONTEXT_ALL, RE_SYNTAX_POSIX_EGREP }, + { "posix-extended", CONTEXT_ALL, RE_SYNTAX_POSIX_EXTENDED }, + { "posix-minimal-basic", CONTEXT_GENERIC, RE_SYNTAX_POSIX_MINIMAL_BASIC }, + { "sed", CONTEXT_GENERIC, RE_SYNTAX_SED }, + /* ,{ "posix-common", CONTEXT_GENERIC, _RE_SYNTAX_POSIX_COMMON } */ }; enum { N_REGEX_MAP_ENTRIES = sizeof(regex_map)/sizeof(regex_map[0]) }; @@ -135,6 +129,13 @@ get_regex_type_flags(unsigned int ix) return -1; } +unsigned int get_regex_type_context(unsigned int ix) +{ + if (ix < N_REGEX_MAP_ENTRIES) + return regex_map[ix].context; + else + return 0u; +} int get_regex_type_synonym(unsigned int ix) { @@ -154,3 +155,6 @@ int get_regex_type_synonym(unsigned int ix) } return -1; } + + + diff --git a/lib/regextype.h b/lib/regextype.h index f0ebba20..6bd520d1 100644 --- a/lib/regextype.h +++ b/lib/regextype.h @@ -21,7 +21,15 @@ int get_regex_type(const char *s); +enum { + CONTEXT_FINDUTILS = 1u, + CONTEXT_GENERIC = 2u, + CONTEXT_ALL = CONTEXT_GENERIC|CONTEXT_FINDUTILS, +}; + + const char * get_regex_type_name(unsigned int ix); int get_regex_type_flags(unsigned int ix); int get_regex_type_synonym(unsigned int ix); +unsigned int get_regex_type_context(unsigned int ix);