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

📄 regcomp.c

📁 硬盘各项性能的测试,如温度容量版本健康度型号
💻 C
📖 第 1 页 / 共 5 页
字号:
  return (int) ret;}#ifdef _LIBCweak_alias (__regcomp, regcomp)#endif/* Returns a message corresponding to an error code, ERRCODE, returned   from either regcomp or regexec.   We don't use PREG here.  */size_tregerror (errcode, preg, errbuf, errbuf_size)    int errcode;    const regex_t *preg;    char *errbuf;    size_t errbuf_size;{  const char *msg;  size_t msg_size;  if (BE (errcode < 0	  || errcode >= (int) (sizeof (__re_error_msgid_idx)			       / sizeof (__re_error_msgid_idx[0])), 0))    /* Only error codes returned by the rest of the code should be passed       to this routine.  If we are given anything else, or if other regex       code generates an invalid error code, then the program has a bug.       Dump core so we can fix it.  */    abort ();  msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);  msg_size = strlen (msg) + 1; /* Includes the null.  */  if (BE (errbuf_size != 0, 1))    {      if (BE (msg_size > errbuf_size, 0))	{#if defined HAVE_MEMPCPY || defined _LIBC	  *((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0';#else	  memcpy (errbuf, msg, errbuf_size - 1);	  errbuf[errbuf_size - 1] = 0;#endif	}      else	memcpy (errbuf, msg, msg_size);    }  return msg_size;}#ifdef _LIBCweak_alias (__regerror, regerror)#endifstatic voidfree_dfa_content (re_dfa_t *dfa){  int i, j;  re_free (dfa->subexps);  for (i = 0; i < dfa->nodes_len; ++i)    {      re_token_t *node = dfa->nodes + i;#ifdef RE_ENABLE_I18N      if (node->type == COMPLEX_BRACKET && node->duplicated == 0)	free_charset (node->opr.mbcset);      else#endif /* RE_ENABLE_I18N */	if (node->type == SIMPLE_BRACKET && node->duplicated == 0)	  re_free (node->opr.sbcset);    }  re_free (dfa->nexts);  for (i = 0; i < dfa->nodes_len; ++i)    {      if (dfa->eclosures != NULL)	re_node_set_free (dfa->eclosures + i);      if (dfa->inveclosures != NULL)	re_node_set_free (dfa->inveclosures + i);      if (dfa->edests != NULL)	re_node_set_free (dfa->edests + i);    }  re_free (dfa->edests);  re_free (dfa->eclosures);  re_free (dfa->inveclosures);  re_free (dfa->nodes);  for (i = 0; i <= dfa->state_hash_mask; ++i)    {      struct re_state_table_entry *entry = dfa->state_table + i;      for (j = 0; j < entry->num; ++j)	{	  re_dfastate_t *state = entry->array[j];	  free_state (state);	}      re_free (entry->array);    }  re_free (dfa->state_table);  if (dfa->word_char != NULL)    re_free (dfa->word_char);#ifdef DEBUG  re_free (dfa->re_str);#endif  re_free (dfa);}/* Free dynamically allocated space used by PREG.  */voidregfree (preg)    regex_t *preg;{  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;  if (BE (dfa != NULL, 1))    free_dfa_content (dfa);  re_free (preg->fastmap);}#ifdef _LIBCweak_alias (__regfree, regfree)#endif/* Entry points compatible with 4.2 BSD regex library.  We don't define   them unless specifically requested.  */#if defined _REGEX_RE_COMP || defined _LIBC/* BSD has one and only one pattern buffer.  */static struct re_pattern_buffer re_comp_buf;char *# ifdef _LIBC/* Make these definitions weak in libc, so POSIX programs can redefine   these names if they don't use our functions, and still use   regcomp/regexec above without link errors.  */weak_function# endifre_comp (s)     const char *s;{  reg_errcode_t ret;  char *fastmap;  if (!s)    {      if (!re_comp_buf.buffer)	return gettext ("No previous regular expression");      return 0;    }  if (re_comp_buf.buffer)    {      fastmap = re_comp_buf.fastmap;      re_comp_buf.fastmap = NULL;      __regfree (&re_comp_buf);      memset (&re_comp_buf, '\0', sizeof (re_comp_buf));      re_comp_buf.fastmap = fastmap;    }  if (re_comp_buf.fastmap == NULL)    {      re_comp_buf.fastmap = (char *) malloc (SBC_MAX);      if (re_comp_buf.fastmap == NULL)	return (char *) gettext (__re_error_msgid				 + __re_error_msgid_idx[(int) REG_ESPACE]);    }  /* Since `re_exec' always passes NULL for the `regs' argument, we     don't need to initialize the pattern buffer fields which affect it.  */  /* Match anchors at newlines.  */  re_comp_buf.newline_anchor = 1;  ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);  if (!ret)    return NULL;  /* Yes, we're discarding `const' here if !HAVE_LIBINTL.  */  return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);}#ifdef _LIBClibc_freeres_fn (free_mem){  __regfree (&re_comp_buf);}#endif#endif /* _REGEX_RE_COMP *//* Internal entry point.   Compile the regular expression PATTERN, whose length is LENGTH.   SYNTAX indicate regular expression's syntax.  */static reg_errcode_tre_compile_internal (preg, pattern, length, syntax)     regex_t *preg;     const char * pattern;     int length;     reg_syntax_t syntax;{  reg_errcode_t err = REG_NOERROR;  re_dfa_t *dfa;  re_string_t regexp;  /* Initialize the pattern buffer.  */  preg->fastmap_accurate = 0;  preg->syntax = syntax;  preg->not_bol = preg->not_eol = 0;  preg->used = 0;  preg->re_nsub = 0;  preg->can_be_null = 0;  preg->regs_allocated = REGS_UNALLOCATED;  /* Initialize the dfa.  */  dfa = (re_dfa_t *) preg->buffer;  if (preg->allocated < sizeof (re_dfa_t))    {      /* If zero allocated, but buffer is non-null, try to realloc	 enough space.  This loses if buffer's address is bogus, but	 that is the user's responsibility.  If ->buffer is NULL this	 is a simple allocation.  */      dfa = re_realloc (preg->buffer, re_dfa_t, 1);      if (dfa == NULL)	return REG_ESPACE;      preg->allocated = sizeof (re_dfa_t);    }  preg->buffer = (unsigned char *) dfa;  preg->used = sizeof (re_dfa_t);  err = init_dfa (dfa, length);  if (BE (err != REG_NOERROR, 0))    {      re_free (dfa);      preg->buffer = NULL;      preg->allocated = 0;      return err;    }#ifdef DEBUG  dfa->re_str = re_malloc (char, length + 1);  strncpy (dfa->re_str, pattern, length + 1);#endif  err = re_string_construct (&regexp, pattern, length, preg->translate,			     syntax & RE_ICASE);  if (BE (err != REG_NOERROR, 0))    {      re_free (dfa);      preg->buffer = NULL;      preg->allocated = 0;      return err;    }  /* Parse the regular expression, and build a structure tree.  */  preg->re_nsub = 0;  dfa->str_tree = parse (&regexp, preg, syntax, &err);  if (BE (dfa->str_tree == NULL, 0))    goto re_compile_internal_free_return;  /* Analyze the tree and collect information which is necessary to     create the dfa.  */  err = analyze (dfa);  if (BE (err != REG_NOERROR, 0))    goto re_compile_internal_free_return;  /* Then create the initial state of the dfa.  */  err = create_initial_state (dfa);  /* Release work areas.  */  free_workarea_compile (preg);  re_string_destruct (&regexp);  if (BE (err != REG_NOERROR, 0))    {    re_compile_internal_free_return:      free_dfa_content (dfa);      preg->buffer = NULL;      preg->allocated = 0;    }  return err;}/* Initialize DFA.  We use the length of the regular expression PAT_LEN   as the initial length of some arrays.  */static reg_errcode_tinit_dfa (dfa, pat_len)     re_dfa_t *dfa;     int pat_len;{  int table_size;  memset (dfa, '\0', sizeof (re_dfa_t));  dfa->nodes_alloc = pat_len + 1;  dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);  dfa->states_alloc = pat_len + 1;  /*  table_size = 2 ^ ceil(log pat_len) */  for (table_size = 1; table_size > 0; table_size <<= 1)    if (table_size > pat_len)      break;  dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);  dfa->state_hash_mask = table_size - 1;  dfa->subexps_alloc = 1;  dfa->subexps = re_malloc (re_subexp_t, dfa->subexps_alloc);  dfa->word_char = NULL;  if (BE (dfa->nodes == NULL || dfa->state_table == NULL	  || dfa->subexps == NULL, 0))    {      /* We don't bother to free anything which was allocated.  Very	 soon the process will go down anyway.  */      dfa->subexps = NULL;      dfa->state_table = NULL;      dfa->nodes = NULL;      return REG_ESPACE;    }  return REG_NOERROR;}/* Initialize WORD_CHAR table, which indicate which character is   "word".  In this case "word" means that it is the word construction   character used by some operators like "\<", "\>", etc.  */static reg_errcode_tinit_word_char (dfa)     re_dfa_t *dfa;{  int i, j, ch;  dfa->word_char = (re_bitset_ptr_t) calloc (sizeof (bitset), 1);  if (BE (dfa->word_char == NULL, 0))    return REG_ESPACE;  for (i = 0, ch = 0; i < BITSET_UINTS; ++i)    for (j = 0; j < UINT_BITS; ++j, ++ch)      if (isalnum (ch) || ch == '_')	dfa->word_char[i] |= 1 << j;  return REG_NOERROR;}/* Free the work area which are only used while compiling.  */static voidfree_workarea_compile (preg)     regex_t *preg;{  re_dfa_t *dfa = (re_dfa_t *) preg->buffer;  free_bin_tree (dfa->str_tree);  dfa->str_tree = NULL;  re_free (dfa->org_indices);  dfa->org_indices = NULL;}/* Create initial states for all contexts.  */static reg_errcode_tcreate_initial_state (dfa)     re_dfa_t *dfa;{  int first, i;  reg_errcode_t err;  re_node_set init_nodes;  /* Initial states have the epsilon closure of the node which is     the first node of the regular expression.  */  first = dfa->str_tree->first;  dfa->init_node = first;  err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);  if (BE (err != REG_NOERROR, 0))    return err;  /* The back-references which are in initial states can epsilon transit,     since in this case all of the subexpressions can be null.     Then we add epsilon closures of the nodes which are the next nodes of     the back-references.  */  if (dfa->nbackref > 0)    for (i = 0; i < init_nodes.nelem; ++i)      {	int node_idx = init_nodes.elems[i];	re_token_type_t type = dfa->nodes[node_idx].type;	int clexp_idx;	if (type != OP_BACK_REF)	  continue;	for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx)	  {	    re_token_t *clexp_node;	    clexp_node = dfa->nodes + init_nodes.elems[clexp_idx];	    if (clexp_node->type == OP_CLOSE_SUBEXP		&& clexp_node->opr.idx + 1 == dfa->nodes[node_idx].opr.idx)	      break;	  }	if (clexp_idx == init_nodes.nelem)	  continue;	if (type == OP_BACK_REF)	  {	    int dest_idx = dfa->edests[node_idx].elems[0];	    if (!re_node_set_contains (&init_nodes, dest_idx))	      {		re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);		i = 0;	      }	  }      }  /* It must be the first time to invoke acquire_state.  */  dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);  /* We don't check ERR here, since the initial state must not be NULL.  */  if (BE (dfa->init_state == NULL, 0))    return err;  if (dfa->init_state->has_constraint)    {      dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes,						       CONTEXT_WORD);      dfa->init_state_nl = re_acquire_state_context (&err, dfa, &init_nodes,						     CONTEXT_NEWLINE);      dfa->init_state_begbuf = re_acquire_state_context (&err, dfa,							 &init_nodes,							 CONTEXT_NEWLINE							 | CONTEXT_BEGBUF);      if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL	      || dfa->init_state_begbuf == NULL, 0))	return err;    }  else    dfa->init_state_word = dfa->init_state_nl      = dfa->init_state_begbuf = dfa->init_state;  re_node_set_free (&init_nodes);  return REG_NOERROR;}/* Analyze the structure tree, and calculate "first", "next", "edest",   "eclosure", and "inveclosure".  */static reg_errcode_tanalyze (dfa)     re_dfa_t *dfa;{  int i;  reg_errcode_t ret;  /* Allocate arrays.  */  dfa->nexts = re_malloc (int, dfa->nodes_alloc);  dfa->org_indices = re_malloc (int, dfa->nodes_alloc);  dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);  dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);  dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_alloc);  if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL	  || dfa->eclosures == NULL || dfa->inveclosures == NULL, 0))    return REG_ESPACE;  /* Initialize them.  */  for (i = 0; i < dfa->nodes_len; ++i)    {      dfa->nexts[i] = -1;      re_node_set_init_empty (dfa->edests + i);

⌨️ 快捷键说明

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