|
Packit Service |
a2ae7a |
/*
|
|
Packit Service |
a2ae7a |
* regexp.h: wrappers for regexp handling
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* Copyright (C) 2009-2016 David Lutterkort
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
a2ae7a |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
a2ae7a |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
a2ae7a |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
a2ae7a |
* Lesser General Public License for more details.
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
a2ae7a |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
a2ae7a |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* Author: David Lutterkort <lutter@redhat.com>
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#ifndef REGEXP_H_
|
|
Packit Service |
a2ae7a |
#define REGEXP_H_
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <stdio.h>
|
|
Packit Service |
a2ae7a |
#include <regex.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp {
|
|
Packit Service |
a2ae7a |
unsigned int ref;
|
|
Packit Service |
a2ae7a |
struct info *info;
|
|
Packit Service |
a2ae7a |
struct string *pattern;
|
|
Packit Service |
a2ae7a |
struct re_pattern_buffer *re;
|
|
Packit Service |
a2ae7a |
unsigned int nocase : 1;
|
|
Packit Service |
a2ae7a |
};
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
void print_regexp(FILE *out, struct regexp *regexp);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Make a regexp with pattern PAT, which is not copied. Ownership
|
|
Packit Service |
a2ae7a |
* of INFO is taken.
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct regexp *make_regexp(struct info *info, char *pat, int nocase);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Make a regexp with pattern PAT, which is copied. Ownership of INFO is
|
|
Packit Service |
a2ae7a |
* taken. Escape sequences like \n in PAT are interpreted.
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct regexp *make_regexp_unescape(struct info *info, const char *pat,
|
|
Packit Service |
a2ae7a |
int nocase);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Return 1 if R is an empty pattern, i.e. one consisting of nothing but
|
|
Packit Service |
a2ae7a |
'(' and ')' characters, 0 otherwise */
|
|
Packit Service |
a2ae7a |
int regexp_is_empty_pattern(struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Make a regexp that matches TEXT literally; the string TEXT
|
|
Packit Service |
a2ae7a |
* is not used by the returned rgexp and must be freed by the caller
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct regexp *make_regexp_literal(struct info *info, const char *text);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Make a regexp from a glob pattern */
|
|
Packit Service |
a2ae7a |
struct regexp *make_regexp_from_glob(struct info *info, const char *glob);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Do not call directly, use UNREF instead */
|
|
Packit Service |
a2ae7a |
void free_regexp(struct regexp *regexp);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Compile R->PATTERN into R->RE; return -1 and print an error
|
|
Packit Service |
a2ae7a |
* if compilation fails. Return 0 otherwise
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
int regexp_compile(struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Check the syntax of R->PATTERN; return -1 if the pattern has a syntax
|
|
Packit Service |
a2ae7a |
* error, and a string indicating the error in *C. Return 0 if the pattern
|
|
Packit Service |
a2ae7a |
* is a valid regular expression.
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
int regexp_check(struct regexp *r, const char **msg);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Call RE_MATCH on R->RE and return its result; if R hasn't been compiled
|
|
Packit Service |
a2ae7a |
* yet, compile it. Return -3 if compilation fails
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
int regexp_match(struct regexp *r, const char *string, const int size,
|
|
Packit Service |
a2ae7a |
const int start, struct re_registers *regs);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Return 1 if R matches the empty string, 0 otherwise */
|
|
Packit Service |
a2ae7a |
int regexp_matches_empty(struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Return the number of subexpressions (parentheses) inside R. May cause
|
|
Packit Service |
a2ae7a |
* compilation of R; return -1 if compilation fails.
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
int regexp_nsub(struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_union(struct info *, struct regexp *r1, struct regexp *r2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_concat(struct info *, struct regexp *r1, struct regexp *r2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_union_n(struct info *, int n, struct regexp **r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_concat_n(struct info *, int n, struct regexp **r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_iter(struct info *info, struct regexp *r, int min, int max);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Return a new REGEXP that matches all the words matched by R1 but
|
|
Packit Service |
a2ae7a |
* not by R2
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *
|
|
Packit Service |
a2ae7a |
regexp_maybe(struct info *info, struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
struct regexp *regexp_make_empty(struct info *);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Free up temporary data structures, most importantly compiled
|
|
Packit Service |
a2ae7a |
regular expressions */
|
|
Packit Service |
a2ae7a |
void regexp_release(struct regexp *regexp);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Produce a printable representation of R. The result will in general not
|
|
Packit Service |
a2ae7a |
be equivalent to the passed regular expression, but be easier for
|
|
Packit Service |
a2ae7a |
humans to read. */
|
|
Packit Service |
a2ae7a |
char *regexp_escape(const struct regexp *r);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* If R is case-insensitive, expand its pattern so that it matches the same
|
|
Packit Service |
a2ae7a |
* string even when used in a case-sensitive match. */
|
|
Packit Service |
a2ae7a |
char *regexp_expand_nocase(struct regexp *r);
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/*
|
|
Packit Service |
a2ae7a |
* Local variables:
|
|
Packit Service |
a2ae7a |
* indent-tabs-mode: nil
|
|
Packit Service |
a2ae7a |
* c-indent-level: 4
|
|
Packit Service |
a2ae7a |
* c-basic-offset: 4
|
|
Packit Service |
a2ae7a |
* tab-width: 4
|
|
Packit Service |
a2ae7a |
* End:
|
|
Packit Service |
a2ae7a |
*/
|