wide_posix_api_check.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. *
  3. * Copyright (c) 1998-2002
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE wide_posix_api_compiler_check.c
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Verify that POSIX API calls compile: note this is a compile
  16. * time check only.
  17. */
  18. #define UNICODE
  19. #define _UNICODE
  20. #include <boost/regex.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. #include <stdlib.h>
  25. #ifndef BOOST_NO_WREGEX
  26. #include <wchar.h>
  27. const wchar_t* expression = L"^";
  28. const wchar_t* text = L"\n ";
  29. regmatch_t matches[1];
  30. int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
  31. REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS |
  32. REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP;
  33. int main()
  34. {
  35. regex_t re;
  36. int result;
  37. wchar_t buf[256];
  38. char nbuf[256];
  39. int i;
  40. result = regcomp(&re, expression, REG_AWK);
  41. if(result > (int)REG_NOERROR)
  42. {
  43. regerror(result, &re, buf, sizeof(buf));
  44. for(i = 0; i < 256; ++i)
  45. nbuf[i] = (char)(buf[i]);
  46. puts(nbuf);
  47. return result;
  48. }
  49. if(re.re_nsub != 0)
  50. {
  51. regfree(&re);
  52. exit(-1);
  53. }
  54. matches[0].rm_so = 0;
  55. matches[0].rm_eo = wcslen(text);
  56. result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
  57. if(result > (int)REG_NOERROR)
  58. {
  59. regerror(result, &re, buf, sizeof(buf));
  60. for(i = 0; i < 256; ++i)
  61. nbuf[i] = (char)(buf[i]);
  62. puts(nbuf);
  63. regfree(&re);
  64. return result;
  65. }
  66. if((matches[0].rm_so != matches[0].rm_eo) || (matches[0].rm_eo != 1))
  67. {
  68. regfree(&re);
  69. exit(-1);
  70. }
  71. regfree(&re);
  72. printf("no errors found\n");
  73. return 0;
  74. }
  75. #else
  76. # error "This library has not been configured for wide character support"
  77. #endif