Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * -*- mode: c-mode; c-file-style: python -*-
  3.  */
  4.  
  5. #ifndef Py_REGEXPR_H
  6. #define Py_REGEXPR_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10.  
  11. /*
  12.  * regexpr.h
  13.  *
  14.  * Author: Tatu Ylonen <ylo@ngs.fi>
  15.  *
  16.  * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
  17.  *
  18.  * Permission to use, copy, modify, distribute, and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies.  This
  21.  * software is provided "as is" without express or implied warranty.
  22.  *
  23.  * Created: Thu Sep 26 17:15:36 1991 ylo
  24.  * Last modified: Mon Nov  4 15:49:46 1991 ylo
  25.  */
  26.  
  27. /* $Id$ */
  28.  
  29. #ifndef REGEXPR_H
  30. #define REGEXPR_H
  31.  
  32. #define RE_NREGS        100  /* number of registers available */
  33.  
  34. typedef struct re_pattern_buffer
  35. {
  36.         unsigned char *buffer;          /* compiled pattern */
  37.         int allocated;         /* allocated size of compiled pattern */
  38.         int used;              /* actual length of compiled pattern */
  39.         unsigned char *fastmap;         /* fastmap[ch] is true if ch can start pattern */
  40.         unsigned char *translate;       /* translation to apply during compilation/matching */
  41.         unsigned char fastmap_accurate; /* true if fastmap is valid */
  42.         unsigned char can_be_null;      /* true if can match empty string */
  43.         unsigned char uses_registers;   /* registers are used and need to be initialized */
  44.         int num_registers;     /* number of registers used */
  45.         unsigned char anchor;           /* anchor: 0=none 1=begline 2=begbuf */
  46. } *regexp_t;
  47.  
  48. typedef struct re_registers
  49. {
  50.         int start[RE_NREGS];  /* start offset of region */
  51.         int end[RE_NREGS];    /* end offset of region */
  52. } *regexp_registers_t;
  53.  
  54. /* bit definitions for syntax */
  55. #define RE_NO_BK_PARENS         1    /* no quoting for parentheses */
  56. #define RE_NO_BK_VBAR           2    /* no quoting for vertical bar */
  57. #define RE_BK_PLUS_QM           4    /* quoting needed for + and ? */
  58. #define RE_TIGHT_VBAR           8    /* | binds tighter than ^ and $ */
  59. #define RE_NEWLINE_OR           16   /* treat newline as or */
  60. #define RE_CONTEXT_INDEP_OPS    32   /* ^$?*+ are special in all contexts */
  61. #define RE_ANSI_HEX             64   /* ansi sequences (\n etc) and \xhh */
  62. #define RE_NO_GNU_EXTENSIONS   128   /* no gnu extensions */
  63.  
  64. #define TP_RE_NOERR             0
  65. #define TP_RE_UNKNOWN_OPCODE    (-1)
  66. #define TP_RE_JUMP_OUT_BOUNDS   1
  67. #define TP_RE_QUOTE_ERR         2
  68.  
  69. /* definitions for some common regexp styles */
  70. #define RE_SYNTAX_AWK   (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
  71. #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
  72. #define RE_SYNTAX_GREP  (RE_BK_PLUS_QM|RE_NEWLINE_OR)
  73. #define RE_SYNTAX_EMACS 0
  74.  
  75. #define Sword       1
  76. #define Swhitespace 2
  77. #define Sdigit      4
  78. #define Soctaldigit 8
  79. #define Shexdigit   16
  80.  
  81. /* Rename all exported symbols to avoid conflicts with similarly named
  82.    symbols in some systems' standard C libraries... */
  83.  
  84. #define re_syntax _Py_re_syntax
  85. #define re_syntax_table _Py_re_syntax_table
  86. #define re_compile_initialize _Py_re_compile_initialize
  87. #define re_set_syntax _Py_re_set_syntax
  88. #define re_compile_pattern _Py_re_compile_pattern
  89. #define re_match _Py_re_match
  90. #define re_search _Py_re_search
  91. #define re_compile_fastmap _Py_re_compile_fastmap
  92. #define re_comp _Py_re_comp
  93. #define re_exec _Py_re_exec
  94.  
  95. #ifdef HAVE_PROTOTYPES
  96.  
  97. extern int re_syntax;
  98. /* This is the actual syntax mask.  It was added so that Python could do
  99.  * syntax-dependent munging of patterns before compilation. */
  100.  
  101. extern unsigned char re_syntax_table[256];
  102.  
  103. void re_compile_initialize(void);
  104.  
  105. int re_set_syntax(int syntax);
  106. /* This sets the syntax to use and returns the previous syntax.  The
  107.  * syntax is specified by a bit mask of the above defined bits. */
  108.  
  109. char *re_compile_pattern(unsigned char *regex, int regex_size, regexp_t compiled);
  110. /* This compiles the regexp (given in regex and length in regex_size).
  111.  * This returns NULL if the regexp compiled successfully, and an error
  112.  * message if an error was encountered.  The buffer field must be
  113.  * initialized to a memory area allocated by malloc (or to NULL) before
  114.  * use, and the allocated field must be set to its length (or 0 if
  115.  * buffer is NULL).  Also, the translate field must be set to point to a
  116.  * valid translation table, or NULL if it is not used. */
  117.  
  118. int re_match(regexp_t compiled, unsigned char *string, int size, int pos,
  119.              regexp_registers_t old_regs);
  120. /* This tries to match the regexp against the string.  This returns the
  121.  * length of the matched portion, or -1 if the pattern could not be
  122.  * matched and -2 if an error (such as failure stack overflow) is
  123.  * encountered. */
  124.  
  125. int re_search(regexp_t compiled, unsigned char *string, int size, int startpos,
  126.               int range, regexp_registers_t regs);
  127. /* This searches for a substring matching the regexp.  This returns the
  128.  * first index at which a match is found.  range specifies at how many
  129.  * positions to try matching; positive values indicate searching
  130.  * forwards, and negative values indicate searching backwards.  mstop
  131.  * specifies the offset beyond which a match must not go.  This returns
  132.  * -1 if no match is found, and -2 if an error (such as failure stack
  133.  * overflow) is encountered. */
  134.  
  135. void re_compile_fastmap(regexp_t compiled);
  136. /* This computes the fastmap for the regexp.  For this to have any effect,
  137.  * the calling program must have initialized the fastmap field to point
  138.  * to an array of 256 characters. */
  139.  
  140. #else /* HAVE_PROTOTYPES */
  141.  
  142. extern int re_syntax;
  143. extern unsigned char re_syntax_table[256];
  144. void re_compile_initialize();
  145. int re_set_syntax();
  146. char *re_compile_pattern();
  147. int re_match();
  148. int re_search();
  149. void re_compile_fastmap();
  150.  
  151. #endif /* HAVE_PROTOTYPES */
  152.  
  153. #endif /* REGEXPR_H */
  154.  
  155.  
  156.  
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif /* !Py_REGEXPR_H */
  161.