mirror of
git://git.sv.gnu.org/findutils.git
synced 2026-07-10 17:06:38 +02:00
Support the generation of regexprops-generic.texi.
This commit is contained in:
+114
-12
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
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, <jay@gnu.org>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+25
-21
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user