PageRenderTime 37ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/arm-gp2x-linux-glibc-2.3.6/glibc-2.3.6/posix/transbug.c

#
C | 142 lines | 109 code | 19 blank | 14 comment | 14 complexity | 2e6425367622e60259a7cffccef20949 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <errno.h>
  4. #include <locale.h>
  5. #include <regex.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <string.h>
  9. /* lowercase chars mapped to uppercase */
  10. static const char casetable[] = {
  11. '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
  12. '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
  13. '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
  14. '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
  15. /* ' ' '!' '"' '#' '$' '%' '&' ''' */
  16. '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
  17. /* '(' ')' '*' '+' ',' '-' '.' '/' */
  18. '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
  19. /* '0' '1' '2' '3' '4' '5' '6' '7' */
  20. '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
  21. /* '8' '9' ':' ';' '<' '=' '>' '?' */
  22. '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
  23. /* '@' 'A' 'B' 'C' 'D' 'E' 'F' 'G' */
  24. '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  25. /* 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' */
  26. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  27. /* 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' */
  28. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  29. /* 'X' 'Y' 'Z' '[' '\' ']' '^' '_' */
  30. '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
  31. /* '`' 'a' 'b' 'c' 'd' 'e' 'f' 'g' */
  32. '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
  33. /* 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' */
  34. '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
  35. /* 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' */
  36. '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
  37. /* 'x' 'y' 'z' '{' '|' '}' '~' */
  38. '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
  39. /* Latin 1: */
  40. '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
  41. '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
  42. '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
  43. '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
  44. '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
  45. '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
  46. '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
  47. '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
  48. '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  49. '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  50. '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\327',
  51. '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\337',
  52. '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
  53. '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
  54. '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
  55. '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
  56. };
  57. static int
  58. run_test (const char *pattern, struct re_registers *regs)
  59. {
  60. static char text[] = "1111AAAA2222bbbb";
  61. struct re_pattern_buffer pat;
  62. const char *err;
  63. int res;
  64. int start2;
  65. memset (&pat, '\0', sizeof (pat));
  66. memset (regs, '\0', 2 * sizeof (regs[0]));
  67. pat.allocated = 0; /* regex will allocate the buffer */
  68. pat.fastmap = (char *) malloc (256);
  69. if (pat.fastmap == NULL)
  70. {
  71. puts ("out of memory");
  72. exit (1);
  73. }
  74. pat.translate = (char *) casetable;
  75. err = re_compile_pattern (pattern, strlen (pattern), &pat);
  76. if (err != NULL)
  77. {
  78. fprintf (stderr, "/%s/: %s\n", pattern, err);
  79. exit (1);
  80. }
  81. res = re_search (&pat, text, strlen (text), 0, strlen (text), &regs[0]);
  82. if (res < 0)
  83. printf ("search 1: res = %d\n", res);
  84. else
  85. printf ("search 1: res = %d, start = %d, end = %d\n",
  86. res, regs[0].start[0], regs[0].end[0]);
  87. if (regs[0].end == NULL)
  88. start2 = 8;
  89. else
  90. start2 = regs[0].end[0] + 1;
  91. regs[1] = regs[0];
  92. res = re_search (&pat, text, strlen (text), start2, strlen (text), &regs[1]);
  93. if (res < 0)
  94. printf ("search 2: res = %d\n", res);
  95. else
  96. printf ("search 2: res = %d, start = %d, end = %d\n",
  97. res, regs[1].start[0], regs[1].end[0]);
  98. return res < 0 ? 1 : 0;
  99. }
  100. static int
  101. do_test (void)
  102. {
  103. static const char lower[] = "[[:lower:]]+";
  104. static const char upper[] = "[[:upper:]]+";
  105. struct re_registers regs[4];
  106. setlocale (LC_ALL, "C");
  107. (void) re_set_syntax (RE_SYNTAX_GNU_AWK);
  108. int result;
  109. #define CHECK(exp) \
  110. if (exp) { puts (#exp); result = 1; }
  111. result = run_test (lower, regs);
  112. result |= run_test (upper, &regs[2]);
  113. if (! result)
  114. {
  115. CHECK (regs[0].start[0] != regs[2].start[0]);
  116. CHECK (regs[0].end[0] != regs[2].end[0]);
  117. CHECK (regs[1].start[0] != regs[3].start[0]);
  118. CHECK (regs[1].end[0] != regs[3].end[0]);
  119. }
  120. return result;
  121. }
  122. #define TEST_FUNCTION do_test ()
  123. #include "../test-skeleton.c"