PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/harbour-2.0.0/include/hbregex.h

#
C Header | 145 lines | 76 code | 19 blank | 50 comment | 0 complexity | 2aaac8769edcd08b5bbc4145d29c0187 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 12753 2009-10-23 07:25:36Z druzus $
  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_HAS_PCRE )
  56. # include <pcre.h>
  57. # undef HB_POSIX_REGEX
  58. #elif defined( HB_OS_UNIX )
  59. # include <sys/types.h>
  60. # include <regex.h>
  61. # define HB_POSIX_REGEX
  62. #elif defined( __BORLANDC__ )
  63. # include <pcreposi.h>
  64. # define HB_POSIX_REGEX
  65. #else
  66. # error pcre component required, but not available
  67. #endif
  68. typedef struct
  69. {
  70. BOOL fFree;
  71. int iFlags;
  72. int iEFlags;
  73. #if defined( HB_HAS_PCRE )
  74. pcre * re_pcre;
  75. #elif defined( HB_POSIX_REGEX )
  76. regex_t reg;
  77. #endif
  78. } HB_REGEX;
  79. typedef HB_REGEX * PHB_REGEX;
  80. #if defined( HB_HAS_PCRE )
  81. #define HB_REGMATCH int
  82. #define HB_REGMATCH_SIZE( n ) ( ( n ) * 3 )
  83. #define HB_REGMATCH_SO( p, n ) ( p )[ ( n ) * 2 ]
  84. #define HB_REGMATCH_EO( p, n ) ( p )[ ( n ) * 2 + 1 ]
  85. #elif defined( HB_POSIX_REGEX )
  86. #define HB_REGMATCH regmatch_t
  87. #define HB_REGMATCH_SIZE( n ) ( n )
  88. #define HB_REGMATCH_SO( p, n ) ( p )[ n ].rm_so
  89. #define HB_REGMATCH_EO( p, n ) ( p )[ n ].rm_eo
  90. #else
  91. #define HB_REGMATCH int
  92. #define HB_REGMATCH_SIZE( n ) ( ( n ) * 2 )
  93. #define HB_REGMATCH_SO( p, n ) ( p )[ ( n ) * 2 ]
  94. #define HB_REGMATCH_EO( p, n ) ( p )[ ( n ) * 2 + 1 ]
  95. #endif
  96. typedef void ( * HB_REG_FREE )( PHB_REGEX );
  97. typedef int ( * HB_REG_COMP )( PHB_REGEX, const char * );
  98. typedef int ( * HB_REG_EXEC )( PHB_REGEX, const char *, ULONG, int, HB_REGMATCH * );
  99. extern void hb_regexInit( HB_REG_FREE pFree, HB_REG_COMP pComp, HB_REG_EXEC pExec );
  100. extern BOOL hb_regexIs( PHB_ITEM pItem );
  101. #ifndef REG_EXTENDED
  102. # define REG_EXTENDED 0x00
  103. #endif
  104. #ifndef REG_NOSUB
  105. # define REG_NOSUB 0x00
  106. #endif
  107. #else
  108. typedef void * PHB_REGEX;
  109. #endif /* _HB_REGEX_INTERNAL_ */
  110. #define HBREG_ICASE 0x01
  111. #define HBREG_NEWLINE 0x02
  112. #define HBREG_NOTBOL 0x04
  113. #define HBREG_NOTEOL 0x08
  114. #define HBREG_EXTENDED 0x10
  115. #define HBREG_NOSUB 0x20
  116. #define HBREG_DOTALL 0x40
  117. #ifndef REGEX_MAX_GROUPS
  118. # define REGEX_MAX_GROUPS 16
  119. #endif
  120. HB_EXTERN_BEGIN
  121. extern HB_EXPORT PHB_REGEX hb_regexCompile( const char * szRegEx, ULONG ulLen, int iFlags );
  122. extern HB_EXPORT PHB_REGEX hb_regexGet( PHB_ITEM pRegExItm, int iFlags );
  123. extern HB_EXPORT void hb_regexFree( PHB_REGEX pRegEx );
  124. extern HB_EXPORT BOOL hb_regexMatch( PHB_REGEX pRegEx, const char * szString, ULONG UlLen, BOOL fFull );
  125. HB_EXTERN_END
  126. #endif /* HB_REGEX_H_ */