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

📄 regex.c

📁 大名鼎鼎的路由器源码。程序分ZEBRA、OSPFRIP等3个包。程序框架采用一个路由协议一个进程的方式
💻 C
📖 第 1 页 / 共 5 页
字号:
	  printf ("/wordbound");	  break;	case notwordbound:	  printf ("/notwordbound");          break;	case wordbeg:	  printf ("/wordbeg");	  break;	case wordend:	  printf ("/wordend");# ifdef emacs	case before_dot:	  printf ("/before_dot");          break;	case at_dot:	  printf ("/at_dot");          break;	case after_dot:	  printf ("/after_dot");          break;	case syntaxspec:          printf ("/syntaxspec");	  mcnt = *p++;	  printf ("/%d", mcnt);          break;	case notsyntaxspec:          printf ("/notsyntaxspec");	  mcnt = *p++;	  printf ("/%d", mcnt);	  break;# endif /* emacs */	case wordchar:	  printf ("/wordchar");          break;	case notwordchar:	  printf ("/notwordchar");          break;	case begbuf:	  printf ("/begbuf");          break;	case endbuf:	  printf ("/endbuf");          break;        default:          printf ("?%d", *(p-1));	}      putchar ('\n');    }  printf ("%d:\tend of pattern.\n", p - start);}voidprint_compiled_pattern (bufp)    struct re_pattern_buffer *bufp;{  unsigned char *buffer = bufp->buffer;  print_partial_compiled_pattern (buffer, buffer + bufp->used);  printf ("%ld bytes used/%ld bytes allocated.\n",	  bufp->used, bufp->allocated);  if (bufp->fastmap_accurate && bufp->fastmap)    {      printf ("fastmap: ");      print_fastmap (bufp->fastmap);    }  printf ("re_nsub: %d\t", bufp->re_nsub);  printf ("regs_alloc: %d\t", bufp->regs_allocated);  printf ("can_be_null: %d\t", bufp->can_be_null);  printf ("newline_anchor: %d\n", bufp->newline_anchor);  printf ("no_sub: %d\t", bufp->no_sub);  printf ("not_bol: %d\t", bufp->not_bol);  printf ("not_eol: %d\t", bufp->not_eol);  printf ("syntax: %lx\n", bufp->syntax);  /* Perhaps we should print the translate table?  */}voidprint_double_string (where, string1, size1, string2, size2)    const char *where;    const char *string1;    const char *string2;    int size1;    int size2;{  int this_char;  if (where == NULL)    printf ("(null)");  else    {      if (FIRST_STRING_P (where))        {          for (this_char = where - string1; this_char < size1; this_char++)            putchar (string1[this_char]);          where = string2;        }      for (this_char = where - string2; this_char < size2; this_char++)        putchar (string2[this_char]);    }}voidprintchar (c)     int c;{  putc (c, stderr);}#else /* not DEBUG */# undef assert# define assert(e)# define DEBUG_STATEMENT(e)# define DEBUG_PRINT1(x)# define DEBUG_PRINT2(x1, x2)# define DEBUG_PRINT3(x1, x2, x3)# define DEBUG_PRINT4(x1, x2, x3, x4)# define DEBUG_PRINT_COMPILED_PATTERN(p, s, e)# define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2)#endif /* not DEBUG *//* Set by `re_set_syntax' to the current regexp syntax to recognize.  Can   also be assigned to arbitrarily: each pattern buffer stores its own   syntax, so it can be changed between regex compilations.  *//* This has no initializer because initialized variables in Emacs   become read-only after dumping.  */reg_syntax_t re_syntax_options;/* Specify the precise syntax of regexps for compilation.  This provides   for compatibility for various utilities which historically have   different, incompatible syntaxes.   The argument SYNTAX is a bit mask comprised of the various bits   defined in regex.h.  We return the old syntax.  */reg_syntax_tre_set_syntax (syntax)    reg_syntax_t syntax;{  reg_syntax_t ret = re_syntax_options;  re_syntax_options = syntax;#ifdef DEBUG  if (syntax & RE_DEBUG)    debug = 1;  else if (debug) /* was on but now is not */    debug = 0;#endif /* DEBUG */  return ret;}#ifdef _LIBCweak_alias (__re_set_syntax, re_set_syntax)#endif/* This table gives an error message for each of the error codes listed   in regex.h.  Obviously the order here has to be same as there.   POSIX doesn't require that we do anything for REG_NOERROR,   but why not be nice?  */static const char re_error_msgid[] =  {#define REG_NOERROR_IDX	0    gettext_noop ("Success")	/* REG_NOERROR */    "\0"#define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success")    gettext_noop ("No match")	/* REG_NOMATCH */    "\0"#define REG_BADPAT_IDX	(REG_NOMATCH_IDX + sizeof "No match")    gettext_noop ("Invalid regular expression") /* REG_BADPAT */    "\0"#define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression")    gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */    "\0"#define REG_ECTYPE_IDX	(REG_ECOLLATE_IDX + sizeof "Invalid collation character")    gettext_noop ("Invalid character class name") /* REG_ECTYPE */    "\0"#define REG_EESCAPE_IDX	(REG_ECTYPE_IDX + sizeof "Invalid character class name")    gettext_noop ("Trailing backslash") /* REG_EESCAPE */    "\0"#define REG_ESUBREG_IDX	(REG_EESCAPE_IDX + sizeof "Trailing backslash")    gettext_noop ("Invalid back reference") /* REG_ESUBREG */    "\0"#define REG_EBRACK_IDX	(REG_ESUBREG_IDX + sizeof "Invalid back reference")    gettext_noop ("Unmatched [ or [^")	/* REG_EBRACK */    "\0"#define REG_EPAREN_IDX	(REG_EBRACK_IDX + sizeof "Unmatched [ or [^")    gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */    "\0"#define REG_EBRACE_IDX	(REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")    gettext_noop ("Unmatched \\{") /* REG_EBRACE */    "\0"#define REG_BADBR_IDX	(REG_EBRACE_IDX + sizeof "Unmatched \\{")    gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */    "\0"#define REG_ERANGE_IDX	(REG_BADBR_IDX + sizeof "Invalid content of \\{\\}")    gettext_noop ("Invalid range end")	/* REG_ERANGE */    "\0"#define REG_ESPACE_IDX	(REG_ERANGE_IDX + sizeof "Invalid range end")    gettext_noop ("Memory exhausted") /* REG_ESPACE */    "\0"#define REG_BADRPT_IDX	(REG_ESPACE_IDX + sizeof "Memory exhausted")    gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */    "\0"#define REG_EEND_IDX	(REG_BADRPT_IDX + sizeof "Invalid preceding regular expression")    gettext_noop ("Premature end of regular expression") /* REG_EEND */    "\0"#define REG_ESIZE_IDX	(REG_EEND_IDX + sizeof "Premature end of regular expression")    gettext_noop ("Regular expression too big") /* REG_ESIZE */    "\0"#define REG_ERPAREN_IDX	(REG_ESIZE_IDX + sizeof "Regular expression too big")    gettext_noop ("Unmatched ) or \\)"), /* REG_ERPAREN */  };static const size_t re_error_msgid_idx[] =  {    REG_NOERROR_IDX,    REG_NOMATCH_IDX,    REG_BADPAT_IDX,    REG_ECOLLATE_IDX,    REG_ECTYPE_IDX,    REG_EESCAPE_IDX,    REG_ESUBREG_IDX,    REG_EBRACK_IDX,    REG_EPAREN_IDX,    REG_EBRACE_IDX,    REG_BADBR_IDX,    REG_ERANGE_IDX,    REG_ESPACE_IDX,    REG_BADRPT_IDX,    REG_EEND_IDX,    REG_ESIZE_IDX,    REG_ERPAREN_IDX  };/* Avoiding alloca during matching, to placate r_alloc.  *//* Define MATCH_MAY_ALLOCATE unless we need to make sure that the   searching and matching functions should not call alloca.  On some   systems, alloca is implemented in terms of malloc, and if we're   using the relocating allocator routines, then malloc could cause a   relocation, which might (if the strings being searched are in the   ralloc heap) shift the data out from underneath the regexp   routines.   Here's another reason to avoid allocation: Emacs   processes input from X in a signal handler; processing X input may   call malloc; if input arrives while a matching routine is calling   malloc, then we're scrod.  But Emacs can't just block input while   calling matching routines; then we don't notice interrupts when   they come in.  So, Emacs blocks input around all regexp calls   except the matching calls, which it leaves unprotected, in the   faith that they will not malloc.  *//* Normally, this is fine.  */#define MATCH_MAY_ALLOCATE/* When using GNU C, we are not REALLY using the C alloca, no matter   what config.h may say.  So don't take precautions for it.  */#ifdef __GNUC__# undef C_ALLOCA#endif/* The match routines may not allocate if (1) they would do it with malloc   and (2) it's not safe for them to use malloc.   Note that if REL_ALLOC is defined, matching would not use malloc for the   failure stack, but we would still use it for the register vectors;   so REL_ALLOC should not affect this.  */#if (defined C_ALLOCA || defined REGEX_MALLOC) && defined emacs# undef MATCH_MAY_ALLOCATE#endif/* Failure stack declarations and macros; both re_compile_fastmap and   re_match_2 use a failure stack.  These have to be macros because of   REGEX_ALLOCATE_STACK.  *//* Number of failure points for which to initially allocate space   when matching.  If this number is exceeded, we allocate more   space, so it is not a hard limit.  */#ifndef INIT_FAILURE_ALLOC# define INIT_FAILURE_ALLOC 5#endif/* Roughly the maximum number of failure points on the stack.  Would be   exactly that if always used MAX_FAILURE_ITEMS items each time we failed.   This is a variable only so users of regex can assign to it; we never   change it ourselves.  */#ifdef INT_IS_16BIT# if defined MATCH_MAY_ALLOCATE/* 4400 was enough to cause a crash on Alpha OSF/1,   whose default stack limit is 2mb.  */long int re_max_failures = 4000;# elselong int re_max_failures = 2000;# endifunion fail_stack_elt{  unsigned char *pointer;  long int integer;};typedef union fail_stack_elt fail_stack_elt_t;typedef struct{  fail_stack_elt_t *stack;  unsigned long int size;  unsigned long int avail;		/* Offset of next open position.  */} fail_stack_type;#else /* not INT_IS_16BIT */# if defined MATCH_MAY_ALLOCATE/* 4400 was enough to cause a crash on Alpha OSF/1,   whose default stack limit is 2mb.  */int re_max_failures = 20000;# elseint re_max_failures = 2000;# endifunion fail_stack_elt{  unsigned char *pointer;  int integer;};typedef union fail_stack_elt fail_stack_elt_t;typedef struct{  fail_stack_elt_t *stack;  unsigned size;  unsigned avail;			/* Offset of next open position.  */} fail_stack_type;#endif /* INT_IS_16BIT */#define FAIL_STACK_EMPTY()     (fail_stack.avail == 0)#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0)#define FAIL_STACK_FULL()      (fail_stack.avail == fail_stack.size)/* Define macros to initialize and free the failure stack.   Do `return -2' if the alloc fails.  */#ifdef MATCH_MAY_ALLOCATE# define INIT_FAIL_STACK()						\  do {									\    fail_stack.stack = (fail_stack_elt_t *)				\      REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \									\    if (fail_stack.stack == NULL)					\      return -2;							\									\    fail_stack.size = INIT_FAILURE_ALLOC;				\    fail_stack.avail = 0;						\  } while (0)# define RESET_FAIL_STACK()  REGEX_FREE_STACK (fail_stack.stack)#else# define INIT_FAIL_STACK()						\  do {									\    fail_stack.avail = 0;						\  } while (0)# define RESET_FAIL_STACK()#endif/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items.   Return 1 if succeeds, and 0 if either ran out of memory   allocating space for it or it was already too large.   REGEX_REALLOCATE_STACK requires `destination' be declared.   */#define DOUBLE_FAIL_STACK(fail_stack)					\  ((fail_stack).size > (unsigned) (re_max_failures * MAX_FAILURE_ITEMS)	\   ? 0									\   : ((fail_stack).stack = (fail_stack_elt_t *)				\        REGEX_REALLOCATE_STACK ((fail_stack).stack, 			\          (fail_stack).size * sizeof (fail_stack_elt_t),		\          ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)),	\									\      (fail_stack).stack == NULL					\      ? 0								\      : ((fail_stack).size <<= 1, 					\         1)))

⌨️ 快捷键说明

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