wide_posix_api_check.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <stdio.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. #include <stdlib.h>
  24. #include <boost/regex.h>
  25. #include <wchar.h>
  26. #include <iostream>
  27. #include <iomanip>
  28. #ifndef BOOST_NO_WREGEX
  29. const wchar_t* expression = L"^";
  30. const wchar_t* text = L"\n ";
  31. regmatch_t matches[1];
  32. int flags = REG_EXTENDED | REG_BASIC | REG_NOSPEC | REG_ICASE | REG_NOSUB |
  33. REG_NEWLINE | REG_PEND | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS |
  34. REG_NEWLINE_ALT | REG_PERL | REG_AWK | REG_GREP | REG_EGREP;
  35. int main()
  36. {
  37. regex_t re;
  38. unsigned result;
  39. result = regcomp(&re, expression, REG_AWK);
  40. if(result > REG_NOERROR)
  41. {
  42. wchar_t buf[256];
  43. regerror(result, &re, buf, sizeof(buf));
  44. char nbuf[256];
  45. for(int i = 0; i < 256; ++i)
  46. nbuf[i] = static_cast<char>(buf[i]);
  47. printf("%s", nbuf);
  48. return result;
  49. }
  50. if(re.re_nsub != 0)
  51. {
  52. regfree(&re);
  53. exit(-1);
  54. }
  55. matches[0].rm_so = 0;
  56. matches[0].rm_eo = wcslen(text);
  57. result = regexec(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND);
  58. if(result > REG_NOERROR)
  59. {
  60. wchar_t buf[256];
  61. regerror(result, &re, buf, sizeof(buf));
  62. char nbuf[256];
  63. for(int i = 0; i < 256; ++i)
  64. nbuf[i] = static_cast<char>(buf[i]);
  65. printf("%s", nbuf);
  66. regfree(&re);
  67. return result;
  68. }
  69. if((matches[0].rm_so != matches[0].rm_eo) || (matches[0].rm_eo != 1))
  70. {
  71. regfree(&re);
  72. exit(-1);
  73. }
  74. regfree(&re);
  75. printf("%s", "no errors found\n");
  76. return 0;
  77. }
  78. #else
  79. #include <iostream>
  80. int main()
  81. {
  82. std::cout <<
  83. "\n<note>\n"
  84. "This platform does not provide the needed wide character support for this test.\n"
  85. "</note>\n";
  86. return 0;
  87. }
  88. #endif