]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - usr.bin/grep/regex/glue.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / usr.bin / grep / regex / glue.h
1 /* $FreeBSD$ */
2
3 #ifndef GLUE_H
4 #define GLUE_H
5
6 #include <limits.h>
7 #undef RE_DUP_MAX
8 #include <regex.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #define TRE_WCHAR                       1
13 #define TRE_MULTIBYTE                   1
14 #define HAVE_MBSTATE_T                  1
15
16 #define TRE_CHAR(n) L##n
17 #define CHF "%lc"
18
19 #define tre_char_t                      wchar_t
20 #define tre_mbrtowc(pwc, s, n, ps)      (mbrtowc((pwc), (s), (n), (ps)))
21 #define tre_strlen                      wcslen
22 #define tre_isspace                     iswspace
23 #define tre_isalnum                     iswalnum
24
25 #define REG_OK                          0
26 #define REG_LITERAL                     0020
27 #define REG_WORD                        0100
28 #define REG_GNU                         0400
29
30 #define TRE_MB_CUR_MAX                  MB_CUR_MAX
31
32 #ifndef _GREP_DEBUG
33 #define DPRINT(msg)
34 #else                   
35 #define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/0)
36 #endif
37
38 #define MIN(a,b)                        ((a > b) ? (b) : (a))
39 #define MAX(a,b)                        ((a > b) ? (a) : (b))
40
41 typedef enum { STR_WIDE, STR_BYTE, STR_MBS, STR_USER } tre_str_type_t;
42
43 #define CALL_WITH_OFFSET(fn)                                            \
44   do                                                                    \
45     {                                                                   \
46       size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so);        \
47       size_t offset = pmatch[0].rm_so;                                  \
48       int ret;                                                          \
49                                                                         \
50       if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0)             \
51         return REG_NOMATCH;                                             \
52       ret = fn;                                                         \
53       for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\
54         {                                                               \
55           pmatch[i].rm_so += offset;                                    \
56           pmatch[i].rm_eo += offset;                                    \
57         }                                                               \
58       return ret;                                                       \
59     } while (0 /*CONSTCOND*/)
60
61 int
62 tre_convert_pattern(const char *regex, size_t n, tre_char_t **w,
63     size_t *wn);
64
65 void
66 tre_free_pattern(tre_char_t *wregex);
67 #endif