summaryrefslogtreecommitdiff
path: root/lib/regextype.h
blob: 2bb9ab5995646a422aa29b0b3d62d56e070607f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* regextype.h -- Decode the name of a regular expression syntax.

   Copyright (C) 2005-2021 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
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
/* Written by James Youngman <jay@gnu.org>.
 */
#ifndef REGEXTPE_H
# define REGEXTPE_H

/* Translate a regular expression type name into an option mask.
 * This could convert "grep" into RE_SYNTAX_GREP, for example.
 * Return -1 if there is no match.
 */
int get_regex_type(const char *s);

enum {
  CONTEXT_FINDUTILS = 1u,
  CONTEXT_GENERIC   = 2u,
  CONTEXT_ALL = CONTEXT_GENERIC|CONTEXT_FINDUTILS,
};



/* Returns the regex type name corresponding to index IX.
 * Indexes start at 0.  Returns NULL if IX is too large.
 */
const char * get_regex_type_name(unsigned int ix);


/* Returns the option mask name corresponding to regular expresion
 * type index IX.  Indexes start at 0.  Behaviour is undefined if IX
 * has a value which would cause get_regex_type_name to return NULL.
 */
int get_regex_type_flags(unsigned int ix);

/* If regular expression type IX (which is a regular expression type
 * index) has one or more synonyms which is interesting in context
 * CONTEXT, return the index of one of them.  Otherwise, return -1.
 */
int get_regex_type_synonym(unsigned int ix, unsigned int context);

/* Returns one of CONTEXT_FINDUTILS, CONTEXT_GENERIC or CONTEXT_ALL.
 * This identifies whether this regular expression type index is relevant for,
 * respectively, findutils, general callers, or all callers.
 */
unsigned int get_regex_type_context(unsigned int ix);

#endif