pcre_info.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language.
  6. Written by Philip Hazel
  7. Copyright (c) 1997-2008 University of Cambridge
  8. -----------------------------------------------------------------------------
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. * Neither the name of the University of Cambridge nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. POSSIBILITY OF SUCH DAMAGE.
  30. -----------------------------------------------------------------------------
  31. */
  32. /* This module contains the external function pcre_info(), which gives some
  33. information about a compiled pattern. However, use of this function is now
  34. deprecated, as it has been superseded by pcre_fullinfo(). */
  35. #ifdef HAVE_CONFIG_H
  36. #include "config.h"
  37. #endif
  38. #include "pcre_internal.h"
  39. /*************************************************
  40. * (Obsolete) Return info about compiled pattern *
  41. *************************************************/
  42. /* This is the original "info" function. It picks potentially useful data out
  43. of the private structure, but its interface was too rigid. It remains for
  44. backwards compatibility. The public options are passed back in an int - though
  45. the re->options field has been expanded to a long int, all the public options
  46. at the low end of it, and so even on 16-bit systems this will still be OK.
  47. Therefore, I haven't changed the API for pcre_info().
  48. Arguments:
  49. argument_re points to compiled code
  50. optptr where to pass back the options
  51. first_byte where to pass back the first character,
  52. or -1 if multiline and all branches start ^,
  53. or -2 otherwise
  54. Returns: number of capturing subpatterns
  55. or negative values on error
  56. */
  57. PCRE_EXP_DEFN int
  58. pcre_info(const pcre *argument_re, int *optptr, int *first_byte)
  59. {
  60. real_pcre internal_re;
  61. const real_pcre *re = (const real_pcre *)argument_re;
  62. if (re == NULL) return PCRE_ERROR_NULL;
  63. if (re->magic_number != MAGIC_NUMBER)
  64. {
  65. re = _pcre_try_flipped(re, &internal_re, NULL, NULL);
  66. if (re == NULL) return PCRE_ERROR_BADMAGIC;
  67. }
  68. if (optptr != NULL) *optptr = (int)(re->options & PUBLIC_OPTIONS);
  69. if (first_byte != NULL)
  70. *first_byte = ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
  71. ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
  72. return re->top_bracket;
  73. }
  74. /* End of pcre_info.c */