summaryrefslogtreecommitdiff
path: root/include/patmatch.h
blob: 20ddc778b16d405ca6f84b37813f4ce928d7b2a2 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * This file has been modified for the cdrkit suite.
 *
 * The behaviour and appearence of the program code below can differ to a major
 * extent from the version distributed by the original author(s).
 *
 * For details, see Changelog file distributed with the cdrkit package. If you
 * received this file from another source then ask the distributing person for
 * a log of modifications.
 *
 */

/* @(#)patmatch.h	1.10 03/08/24 Copyright 1985 J. Schilling */

#ifndef	_PATMATCH_H
#define	_PATMATCH_H
/*
 *	Definitions for the pattern matching functions.
 *
 *	Copyright (c) 1985,1995 J. Schilling
 */
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * 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; see the file COPYING.  If not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
 *	The pattern matching functions are based on the algorithm
 *	presented by Martin Richards in:
 *
 *	"A Compact Function for Regular Expression Pattern Matching",
 *	Software-Practice and Experience, Vol. 9, 527-534 (1979)
 *
 *	Several changes have been made to the original source which has been
 *	written in BCPL:
 *
 *	'/'	is replaced by	'!'		(to allow UNIX filenames)
 *	'(',')' are replaced by	'{', '}'
 *	'\''	is replaced by	'\\'		(UNIX compatible quote)
 *
 *	Character classes have been added to allow "[<character list>]"
 *	to be used.
 *	Start of line '^' and end of line '$' have been added.
 *
 *	Any number in the following comment is zero or more occurrencies
 */
#ifndef _MCONFIG_H
#include <mconfig.h>
#endif
#ifndef _PROTOTYP_H
#include <prototyp.h>
#endif

#ifdef	__cplusplus
extern "C" {
#endif

#define	ALT	'!'	/* Alternation in match i.e. this!that!the_other */
#define	REP	'#'	/* Any number of occurrences of the following expr */
#define	NIL	'%'	/* Empty string (exactly nothing) */
#define	STAR	'*'	/* Any number of any character (equivalent of #?) */
#define	ANY	'?'	/* Any one character */
#define	QUOTE	'\\'	/* Quotes the next character */
#define	LBRACK	'{'	/* Begin of precedence grouping */
#define	RBRACK	'}'	/* End of precedence grouping */
#define	LCLASS	'['	/* Begin of character set */
#define	RCLASS	']'	/* End of character set */
#define	NOT	'^'	/* If first in set: invert set content */
#define	RANGE	'-'	/* Range notation in sets */
#define	START	'^'	/* Begin of a line */
#define	END	'$'	/* End of a line */

/*
 * A list of case statements that may be used for a issimple() or ispattern()
 * funtion that checks whether a string conrtains characters that need the
 * pattern matcher.
 *
 * Note that this list does not contain NOT or RANGE because you need
 * LCLASS and RCLASS in addition.
 */
#define	casePAT	case ALT: case REP: case NIL: case STAR: case ANY:	\
		case QUOTE: case LBRACK: case RBRACK:			\
		case LCLASS: case RCLASS: case START: case END:


#define	MAXPAT	128	/* Maximum length of pattern */

extern	int patcompile(const unsigned char *__pat, int __patlen, int *__aux);

extern	unsigned char *opatmatch(const unsigned char *__pat, const int *__aux,
											 const unsigned char *__str, int __soff, 
											 int __slen, int __alt);
extern	unsigned char *opatlmatch(const unsigned char *__pat, const int *__aux,
											  const unsigned char *__str, int __soff, 
											  int __slen, int __alt);
extern	unsigned char *patmatch(const unsigned char *__pat, const int *__aux,
											const unsigned char *__str, int __soff, 
											int __slen, int __alt, int __state[]);
extern	unsigned char *patlmatch(const unsigned char *__pat, const int *__aux,
											 const unsigned char *__str, int __soff, 
											 int __slen, int __alt, int __state[]);

#ifdef	__cplusplus
}
#endif

#endif	/* _PATMATCH_H */