1 /*
   2  * Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  * 1. Redistributions of source code must retain the above copyright
  10  *    notice, this list of conditions and the following disclaimer.
  11  *
  12  * 2. Redistributions in binary form must reproduce the above copyright
  13  *    notice, this list of conditions and the following disclaimer in the
  14  *    documentation and/or other materials provided with the distribution.
  15  *
  16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
  17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
  20  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27  */
  28 
  29 #ifndef _TRE_H
  30 #define _TRE_H
  31 
  32 #include <sys/types.h>
  33 
  34 #include <locale.h>
  35 #include <wchar.h>
  36 #include <xlocale.h>
  37 
  38 #include "../../../../head/regex.h"
  39 
  40 #define RE_MAGIC ((('r'^0200)<<8) | 'e')
  41 
  42 typedef int reg_errcode_t;
  43 
  44 enum {
  45   TRE_CONFIG_APPROX,
  46   TRE_CONFIG_WCHAR,
  47   TRE_CONFIG_MULTIBYTE,
  48   TRE_CONFIG_SYSTEM_ABI,
  49   TRE_CONFIG_VERSION
  50 };
  51 
  52 typedef wchar_t tre_char_t;
  53 
  54 /* Approximate matching parameter struct. */
  55 typedef struct {
  56   int cost_ins;         /* Default cost of an inserted character. */
  57   int cost_del;         /* Default cost of a deleted character. */
  58   int cost_subst;       /* Default cost of a substituted character. */
  59   int max_cost;         /* Maximum allowed cost of a match. */
  60 
  61   int max_ins;          /* Maximum allowed number of inserts. */
  62   int max_del;          /* Maximum allowed number of deletes. */
  63   int max_subst;        /* Maximum allowed number of substitutes. */
  64   int max_err;          /* Maximum allowed number of errors total. */
  65 } regaparams_t;
  66 
  67 /* Approximate matching result struct. */
  68 typedef struct {
  69   size_t nmatch;        /* Length of pmatch[] array. */
  70   regmatch_t *pmatch;   /* Submatch data. */
  71   int cost;             /* Cost of the match. */
  72   int num_ins;          /* Number of inserts in the match. */
  73   int num_del;          /* Number of deletes in the match. */
  74   int num_subst;        /* Number of substitutes in the match. */
  75 } regamatch_t;
  76 
  77 typedef struct {
  78   int (*get_next_char)(tre_char_t *c, unsigned int *pos_add, void *context);
  79   void (*rewind)(size_t pos, void *context);
  80   int (*compare)(size_t pos1, size_t pos2, size_t len, void *context);
  81   void *context;
  82 } tre_str_source;
  83 
  84 #define REG_ENHANCED                    0x100000
  85 #define REG_MINIMAL                     0x200000
  86 #define REG_UNGREEDY                    0x200000
  87 
  88 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
  89 
  90 #ifndef MB_CUR_MAX_L
  91 unsigned char __mb_cur_max_l(locale_t);
  92 #define  MB_CUR_MAX_L(l) (__mb_cur_max_l(l))
  93 #endif
  94 
  95 #endif /* _TRE_H */