PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/beta3/harbour/include/hbregex.h

#
C Header | 153 lines | 84 code | 19 blank | 50 comment | 3 complexity | 34991df11f18738e005f38c4a9ccb301 MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-3.0, GPL-2.0, LGPL-2.0, LGPL-2.1
  1. /*
  2. * $Id: hbregex.h 7547 2007-06-13 22:34:17Z $
  3. */
  4. /*
  5. * Harbour Project source code:
  6. *
  7. *
  8. * Copyright 2007 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
  9. * www - http://www.harbour-project.org
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2, or (at your option)
  14. * any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this software; see the file COPYING. If not, write to
  23. * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  24. * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
  25. *
  26. * As a special exception, the Harbour Project gives permission for
  27. * additional uses of the text contained in its release of Harbour.
  28. *
  29. * The exception is that, if you link the Harbour libraries with other
  30. * files to produce an executable, this does not by itself cause the
  31. * resulting executable to be covered by the GNU General Public License.
  32. * Your use of that executable is in no way restricted on account of
  33. * linking the Harbour library code into it.
  34. *
  35. * This exception does not however invalidate any other reasons why
  36. * the executable file might be covered by the GNU General Public License.
  37. *
  38. * This exception applies only to the code released by the Harbour
  39. * Project under the name Harbour. If you copy code from other
  40. * Harbour Project or Free Software Foundation releases into a copy of
  41. * Harbour, as the General Public License permits, the exception does
  42. * not apply to the code that you add in this way. To avoid misleading
  43. * anyone as to the status of such modified files, you must delete
  44. * this exception notice from them.
  45. *
  46. * If you write modifications of your own for Harbour, it is your choice
  47. * whether to permit this exception to apply to your modifications.
  48. * If you do not wish that, delete this exception notice.
  49. *
  50. */
  51. #ifndef HB_REGEX_H_
  52. #define HB_REGEX_H_
  53. #include "hbapi.h"
  54. #if defined( _HB_REGEX_INTERNAL_ )
  55. #if defined( HB_PCRE_REGEX_BCC )
  56. # include <pcreposi.h>
  57. # undef HB_PCRE_REGEX
  58. # if !defined( HB_POSIX_REGEX )
  59. # define HB_POSIX_REGEX
  60. # endif
  61. #elif defined( HB_PCRE_REGEX )
  62. # include <pcre.h>
  63. # undef HB_POSIX_REGEX
  64. #elif defined( HB_POSIX_REGEX )
  65. # include <sys/types.h>
  66. # include <regex.h>
  67. #else
  68. # define HB_PCRE_REGEX
  69. # define PCRE_STATIC
  70. # if defined(__XCC__) || defined(__LCC__)
  71. # include "source\hbpcre\pcre.h"
  72. # else
  73. # include "../source/hbpcre/pcre.h"
  74. # endif
  75. #endif
  76. typedef struct
  77. {
  78. BOOL fFree;
  79. int iFlags;
  80. int iEFlags;
  81. #if defined( HB_PCRE_REGEX )
  82. pcre * re_pcre;
  83. #elif defined( HB_POSIX_REGEX )
  84. regex_t reg;
  85. #endif
  86. } HB_REGEX;
  87. typedef HB_REGEX * PHB_REGEX;
  88. #if defined( HB_PCRE_REGEX )
  89. #define HB_REGMATCH int
  90. #define HB_REGMATCH_SIZE( n ) ( ( n ) * 3 )
  91. #define HB_REGMATCH_SO( p, n ) ( p )[ ( n ) * 2 ]
  92. #define HB_REGMATCH_EO( p, n ) ( p )[ ( n ) * 2 + 1 ]
  93. #elif defined( HB_POSIX_REGEX )
  94. #define HB_REGMATCH regmatch_t
  95. #define HB_REGMATCH_SIZE( n ) ( n )
  96. #define HB_REGMATCH_SO( p, n ) ( p )[ n ].rm_so
  97. #define HB_REGMATCH_EO( p, n ) ( p )[ n ].rm_eo
  98. #else
  99. #define HB_REGMATCH int
  100. #define HB_REGMATCH_SIZE( n ) ( ( n ) * 2 )
  101. #define HB_REGMATCH_SO( p, n ) ( p )[ ( n ) * 2 ]
  102. #define HB_REGMATCH_EO( p, n ) ( p )[ ( n ) * 2 + 1 ]
  103. #endif
  104. typedef void ( * HB_REG_FREE )( PHB_REGEX );
  105. typedef int ( * HB_REG_COMP )( PHB_REGEX, const char * );
  106. typedef int ( * HB_REG_EXEC )( PHB_REGEX, const char *, ULONG, int, HB_REGMATCH * );
  107. extern void hb_regexInit( HB_REG_FREE pFree, HB_REG_COMP pComp, HB_REG_EXEC pExec );
  108. extern HB_GARBAGE_FUNC( hb_regexRelease );
  109. #ifndef REG_EXTENDED
  110. # define REG_EXTENDED 0x00
  111. #endif
  112. #ifndef REG_NOSUB
  113. # define REG_NOSUB 0x00
  114. #endif
  115. #else
  116. typedef void * PHB_REGEX;
  117. #endif /* _HB_REGEX_INTERNAL_ */
  118. #define HBREG_ICASE 0x01
  119. #define HBREG_NEWLINE 0x02
  120. #define HBREG_NOTBOL 0x04
  121. #define HBREG_NOTEOL 0x08
  122. #define HBREG_EXTENDED 0x10
  123. #define HBREG_NOSUB 0x20
  124. #define HBREG_DOTALL 0x40
  125. #ifndef REGEX_MAX_GROUPS
  126. # define REGEX_MAX_GROUPS 16
  127. #endif
  128. HB_EXTERN_BEGIN
  129. extern HB_EXPORT PHB_REGEX hb_regexCompile( const char * szRegEx, ULONG ulLen, int iFlags );
  130. extern HB_EXPORT PHB_REGEX hb_regexGet( PHB_ITEM pRegExItm, int iFlags );
  131. extern HB_EXPORT void hb_regexFree( PHB_REGEX pRegEx );
  132. extern HB_EXPORT BOOL hb_regexMatch( PHB_REGEX pRegEx, const char * szString, ULONG UlLen, BOOL fFull );
  133. HB_EXTERN_END
  134. #endif /* HB_REGEX_H_ */