⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tregress.c

📁 正则表达式库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* tregress.c: reported bugs.  The `t' just makes the filename not have   a common prefix with `regex.c', so completion works better.  */#include "test.h"boolean pause_at_error = true;char *itoa (i)    int i;{  char *a = xmalloc (21); /* sign + 19 digits (enough for 64 bits) + null */    sprintf (a, "%d", i);  return a;}static voidsimple_fail (routine, pat, buf, str, ret)    const char *routine;    const char *pat;    struct re_pattern_buffer *buf;    const char *str;    char *ret;{  fprintf (stderr, "Failed %s (return = %s).\n", routine, ret);  if (str && *str) fprintf (stderr, "   String = %s\n", str);  fprintf (stderr, "  Pattern = %s\n", pat);  print_compiled_pattern (buf);    if (pause_at_error)    {      fprintf (stderr, "RET to continue: ");      (void) getchar ();    }}/* Abbreviate the most common calls.  */static voidsimple_compile (pat, buf)    const char *pat;    struct re_pattern_buffer *buf;{  const char *ret = re_compile_pattern (pat, strlen (pat), buf);    if (ret != NULL) simple_fail ("compile", pat, buf, NULL, ret);}static voidsimple_fastmap (pat)    const char *pat;{  struct re_pattern_buffer buf;  char fastmap[256];  int ret;    buf.allocated = 0;  buf.buffer = buf.translate = NULL;  buf.fastmap = fastmap;    simple_compile (pat, &buf);    ret = re_compile_fastmap (&buf);  if (ret != 0) simple_fail ("fastmap compile", pat, &buf, NULL, itoa (ret));}#define SIMPLE_MATCH(pat, str) do_match (pat, str, strlen (str))#define SIMPLE_NONMATCH(pat, str) do_match (pat, str, -1)static voiddo_match (pat, str, expected)    const char *pat, *str;    int expected;{  int ret;  unsigned len;  struct re_pattern_buffer buf;  buf.allocated = 0;  buf.buffer = buf.translate = buf.fastmap = NULL;    simple_compile (pat, &buf);  len = strlen (str);    ret = re_match_2 (&buf, NULL, 0, str, len, 0, NULL, len);    if (ret != expected) simple_fail ("match", pat, &buf, str, itoa (ret));}static voidsimple_search (pat, str, correct_startpos)    const char *pat, *str;    int correct_startpos;{  int ret;  unsigned len;  struct re_pattern_buffer buf;  buf.allocated = 0;  buf.buffer = buf.translate = buf.fastmap = NULL;    simple_compile (pat, &buf);  len = strlen (str);    ret = re_search_2 (&buf, NULL, 0, str, len, 0, len, NULL, len);    if (ret != correct_startpos)    simple_fail ("match", pat, &buf, str, itoa (ret));}/* Past bugs people have reported.  */voidtest_regress (){  extern char upcase[];  struct re_pattern_buffer buf;  unsigned len;  struct re_registers regs;  int ret;  char *fastmap = xmalloc (256);      buf.translate = NULL;  buf.fastmap = NULL;  buf.allocated = 0;  buf.buffer = NULL;  printf ("\nStarting regression tests.\n");  t = regress_test;  test_should_match = true;  re_set_syntax (RE_SYNTAX_EMACS);  /* enami@sys.ptg.sony.co.jp  10 Nov 92 15:19:02 JST  */  buf.translate = upcase;  SIMPLE_MATCH ("[A-[]", "A");  buf.translate = NULL;    /* meyering@cs.utexas.edu  Nov  6 22:34:41 1992  */  simple_search ("\\w+", "a", 0);     /* jimb@occs.cs.oberlin.edu  10 Sep 92 00:42:33  */  buf.translate = upcase;  SIMPLE_MATCH ("[\001-\377]", "\001");  SIMPLE_MATCH ("[\001-\377]", "a");  SIMPLE_MATCH ("[\001-\377]", "\377");  buf.translate = NULL;  /* mike@skinner.cs.uoregon.edu  1 Sep 92 01:45:22  */  SIMPLE_MATCH ("^^$", "^");    /* pclink@qld.tne.oz.au  Sep  7 22:42:36 1992  */  re_set_syntax (RE_INTERVALS);  SIMPLE_MATCH ("^a\\{3\\}$", "aaa");  SIMPLE_NONMATCH ("^a\\{3\\}$", "aa");  re_set_syntax (RE_SYNTAX_EMACS);    /* pclink@qld.tne.oz.au, 31 Aug 92.  (conjecture) */  re_set_syntax (RE_INTERVALS);  simple_search ("a\\{1,3\\}b", "aaab", 0);  simple_search ("a\\{1,3\\}b", "aaaab", 1);  re_set_syntax (RE_SYNTAX_EMACS);  /* trq@dionysos.thphys.ox.ac.uk, 31 Aug 92.  (simplified) */  simple_fastmap ("^.*\n[  ]*");    /* wind!greg@plains.NoDak.edu, 25 Aug 92.  (simplified) */  re_set_syntax (RE_INTERVALS);  SIMPLE_MATCH ("[a-zA-Z]*.\\{5\\}", "xN0000");  SIMPLE_MATCH ("[a-zA-Z]*.\\{5\\}$", "systemxN0000");  SIMPLE_MATCH ("\\([a-zA-Z]*\\).\\{5\\}$", "systemxN0000");  re_set_syntax (RE_SYNTAX_EMACS);    /* jimb, 18 Aug 92.  Don't use \000, so `strlen' (in our testing     routines) will work.  (This still tickles the bug jimb reported.)  */  SIMPLE_MATCH ("[\001-\377]", "\001");  SIMPLE_MATCH ("[\001-\377]", "a");  SIMPLE_MATCH ("[\001-\377]", "\377");  /* jimb, 13 Aug 92.  */  SIMPLE_MATCH ("[\001-\177]", "\177");  /* Tests based on bwoelfel's below.  */  SIMPLE_MATCH ("\\(a\\|ab\\)*", "aab");  SIMPLE_MATCH ("\\(a\\|ab\\)+", "aab");  SIMPLE_MATCH ("\\(a*\\|ab\\)+", "aab");  SIMPLE_MATCH ("\\(a+\\|ab\\)+", "aab");  SIMPLE_MATCH ("\\(a?\\|ab\\)+", "aab");  /* bwoelfel@widget.seas.upenn.edu, 25 Jul 92.  */  SIMPLE_MATCH ("^\\([ab]+\\|bc\\)+", "abc");  /* jla, 3 Jul 92.  Core dump in re_search_2.  */  buf.fastmap = fastmap;  buf.translate = upcase;#define DATEDUMP_PATTERN " *[0-9]*:"  if (re_compile_pattern (DATEDUMP_PATTERN, strlen (DATEDUMP_PATTERN), &buf)      != NULL)    printf ("date dump compile failed.\n");  regs.num_regs = 0;  regs.start = regs.end = NULL;  if (re_search_2 (&buf, NULL, 0, "Thu Jul  2 18:34:18 1992",                   24, 3, 21, &regs, 24) != 10)    printf ("date dump search failed.\n");  buf.fastmap = 0;  buf.translate = 0;  /* rms, 4 Jul 1992.  Pattern is much slower in Emacs 19.  Fastmap     should be only a backslash.  */#define BEGINEND_PATTERN "\\(\\\\begin\\s *{\\)\\|\\(\\\\end\\s *{\\)"  test_fastmap (BEGINEND_PATTERN, "\\", false, 0);  /* kaoru@is.s.u-tokyo.ac.jp, 27 Jun 1992.  Code for [a-z] (in regex.c)     should translate the whole set.  */  buf.translate = upcase;#define CASE_SET_PATTERN "[ -`]"  if (re_compile_pattern (CASE_SET_PATTERN, strlen (CASE_SET_PATTERN), &buf)      != NULL)    printf ("case set compile failed.\n");  if (re_match_2 (&buf, "K", 1, "", 0, 0, NULL, 1) != 1)    printf ("case set match failed.\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -