1226035Sgabor/* $FreeBSD$ */ 2226035Sgabor 3226035Sgabor#ifndef GLUE_H 4226035Sgabor#define GLUE_H 5226035Sgabor 6226035Sgabor#include <limits.h> 7226035Sgabor#undef RE_DUP_MAX 8226035Sgabor#include <regex.h> 9226035Sgabor#include <stdio.h> 10226035Sgabor#include <stdlib.h> 11226035Sgabor 12226035Sgabor#define TRE_WCHAR 1 13226035Sgabor#define TRE_MULTIBYTE 1 14226035Sgabor#define HAVE_MBSTATE_T 1 15226035Sgabor 16226035Sgabor#define TRE_CHAR(n) L##n 17226035Sgabor#define CHF "%lc" 18226035Sgabor 19226035Sgabor#define tre_char_t wchar_t 20226035Sgabor#define tre_mbrtowc(pwc, s, n, ps) (mbrtowc((pwc), (s), (n), (ps))) 21226035Sgabor#define tre_strlen wcslen 22226035Sgabor#define tre_isspace iswspace 23226035Sgabor#define tre_isalnum iswalnum 24226035Sgabor 25226035Sgabor#define REG_OK 0 26226035Sgabor#define REG_LITERAL 0020 27226035Sgabor#define REG_WORD 0100 28226035Sgabor#define REG_GNU 0400 29226035Sgabor 30226035Sgabor#define TRE_MB_CUR_MAX MB_CUR_MAX 31226035Sgabor 32226035Sgabor#ifndef _GREP_DEBUG 33226035Sgabor#define DPRINT(msg) 34226035Sgabor#else 35226035Sgabor#define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/0) 36226035Sgabor#endif 37226035Sgabor 38226035Sgabor#define MIN(a,b) ((a > b) ? (b) : (a)) 39226035Sgabor#define MAX(a,b) ((a > b) ? (a) : (b)) 40226035Sgabor 41226035Sgabortypedef enum { STR_WIDE, STR_BYTE, STR_MBS, STR_USER } tre_str_type_t; 42226035Sgabor 43226035Sgabor#define CALL_WITH_OFFSET(fn) \ 44226035Sgabor do \ 45226035Sgabor { \ 46226035Sgabor size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); \ 47226035Sgabor size_t offset = pmatch[0].rm_so; \ 48226035Sgabor int ret; \ 49226035Sgabor \ 50226035Sgabor if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0) \ 51226035Sgabor return REG_NOMATCH; \ 52226035Sgabor ret = fn; \ 53226035Sgabor for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\ 54226035Sgabor { \ 55226035Sgabor pmatch[i].rm_so += offset; \ 56226035Sgabor pmatch[i].rm_eo += offset; \ 57226035Sgabor } \ 58226035Sgabor return ret; \ 59226035Sgabor } while (0 /*CONSTCOND*/) 60226035Sgabor 61226035Sgaborint 62226035Sgabortre_convert_pattern(const char *regex, size_t n, tre_char_t **w, 63226035Sgabor size_t *wn); 64226035Sgabor 65226035Sgaborvoid 66226035Sgabortre_free_pattern(tre_char_t *wregex); 67226035Sgabor#endif 68