1 /* regextype.c -- Decode the name of a regular expression syntax into am
4 Copyright 2005 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* Written by James Youngman, <jay@gnu.org>. */
29 #include "regextype.h"
39 # define _(Text) gettext (Text)
44 # define N_(String) gettext_noop (String)
46 /* See locate.c for explanation as to why not use (String) */
47 # define N_(String) String
52 struct tagRegexTypeMap
58 struct tagRegexTypeMap regex_map
[] =
61 { "findutils-default", RE_SYNTAX_EMACS
|RE_DOT_NEWLINE
},
63 { "emacs", RE_SYNTAX_EMACS
},
64 { "posix-basic", RE_SYNTAX_POSIX_BASIC
},
65 { "posix-extended", RE_SYNTAX_POSIX_EXTENDED
},
66 { "awk", RE_SYNTAX_AWK
},
67 { "gnu-awk", RE_SYNTAX_GNU_AWK
},
68 { "posix-awk", RE_SYNTAX_POSIX_AWK
},
69 { "grep", RE_SYNTAX_GREP
},
70 { "egrep", RE_SYNTAX_EGREP
},
71 { "posix-egrep", RE_SYNTAX_POSIX_EGREP
}
74 { "ed", RE_SYNTAX_ED
},
75 { "sed", RE_SYNTAX_SED
},
76 /* ,{ "posix-common", _RE_SYNTAX_POSIX_COMMON } */
77 { "posix-minimal-basic", RE_SYNTAX_POSIX_MINIMAL_BASIC
}
80 enum { N_REGEX_MAP_ENTRIES
= sizeof(regex_map
)/sizeof(regex_map
[0]) };
83 get_regex_type(const char *s
)
90 for (i
=0u; i
<N_REGEX_MAP_ENTRIES
; ++i
)
92 if (0 == strcmp(regex_map
[i
].name
, s
))
93 return regex_map
[i
].option_val
;
95 msglen
+= strlen(quote(regex_map
[i
].name
)) + 2u;
98 /* We didn't find a match for the type of regular expression that the
99 * user indicated they wanted. Tell them what the options are.
101 p
= buf
= xmalloc(1u + msglen
);
102 for (i
=0u; i
<N_REGEX_MAP_ENTRIES
; ++i
)
109 p
+= sprintf(p
, "%s", quote(regex_map
[i
].name
));
112 error(1, 0, _("Unknown regular expression type %s; valid types are %s."),
121 get_regex_type_name(int ix
)
123 if (ix
< N_REGEX_MAP_ENTRIES
)
124 return regex_map
[ix
].name
;
130 get_regex_type_flags(int ix
)
132 if (ix
< N_REGEX_MAP_ENTRIES
)
133 return regex_map
[ix
].option_val
;
139 int get_regex_type_synonym(int ix
)
142 if (ix
>= N_REGEX_MAP_ENTRIES
)
145 int flags
= regex_map
[ix
].option_val
;
146 for (i
=0u; i
<ix
; ++i
)
148 if (flags
== regex_map
[i
].option_val
)