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

📄 regparse.c

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 C
📖 第 1 页 / 共 5 页
字号:
  NQUALIFIER(node).is_refered        = 0;  return node;}static Node*node_new_effect(int type){  Node* node = node_new();  CHECK_NULL_RETURN(node);  node->type = N_EFFECT;  NEFFECT(node).type      = type;  NEFFECT(node).state     =  0;  NEFFECT(node).regnum    =  0;  NEFFECT(node).option    =  0;  NEFFECT(node).target    = NULL;  NEFFECT(node).call_addr = -1;  NEFFECT(node).opt_count =  0;  return node;}extern Node*onig_node_new_effect(int type){  return node_new_effect(type);}static Node*node_new_effect_memory(OnigOptionType option, int is_named){  Node* node = node_new_effect(EFFECT_MEMORY);  CHECK_NULL_RETURN(node);  if (is_named != 0)    SET_EFFECT_STATUS(node, NST_NAMED_GROUP);#ifdef USE_SUBEXP_CALL  NEFFECT(node).option = option;#endif  return node;}static Node*node_new_option(OnigOptionType option){  Node* node = node_new_effect(EFFECT_OPTION);  CHECK_NULL_RETURN(node);  NEFFECT(node).option = option;  return node;}extern intonig_node_str_cat(Node* node, const UChar* s, const UChar* end){  int addlen = end - s;  if (addlen > 0) {    int len  = NSTRING(node).end - NSTRING(node).s;    if (NSTRING(node).capa > 0 || (len + addlen > NODE_STR_BUF_SIZE - 1)) {      UChar* p;      int capa = len + addlen + NODE_STR_MARGIN;      if (capa <= NSTRING(node).capa) {	k_strcpy(NSTRING(node).s + len, s, end);      }      else {	if (NSTRING(node).s == NSTRING(node).buf)	  p = strcat_capa_from_static(NSTRING(node).s, NSTRING(node).end,				      s, end, capa);	else	  p = k_strcat_capa(NSTRING(node).s, NSTRING(node).end, s, end, capa);	CHECK_NULL_RETURN_VAL(p, ONIGERR_MEMORY);	NSTRING(node).s    = p;	NSTRING(node).capa = capa;      }    }    else {      k_strcpy(NSTRING(node).s + len, s, end);    }    NSTRING(node).end = NSTRING(node).s + len + addlen;  }  return 0;}static intnode_str_cat_char(Node* node, UChar c){  UChar s[1];  s[0] = c;  return onig_node_str_cat(node, s, s + 1);}extern voidonig_node_conv_to_str_node(Node* node, int flag){  node->type = N_STRING;  NSTRING(node).flag = flag;  NSTRING(node).capa = 0;  NSTRING(node).s    = NSTRING(node).buf;  NSTRING(node).end  = NSTRING(node).buf;}extern voidonig_node_str_clear(Node* node){  if (NSTRING(node).capa != 0 &&      IS_NOT_NULL(NSTRING(node).s) && NSTRING(node).s != NSTRING(node).buf) {    xfree(NSTRING(node).s);  }  NSTRING(node).capa = 0;  NSTRING(node).flag = 0;  NSTRING(node).s    = NSTRING(node).buf;  NSTRING(node).end  = NSTRING(node).buf;}static Node*node_new_str(const UChar* s, const UChar* end){  Node* node = node_new();  CHECK_NULL_RETURN(node);  node->type = N_STRING;  NSTRING(node).capa = 0;  NSTRING(node).flag = 0;  NSTRING(node).s    = NSTRING(node).buf;  NSTRING(node).end  = NSTRING(node).buf;  if (onig_node_str_cat(node, s, end)) {    onig_node_free(node);    return NULL;  }  return node;}extern Node*onig_node_new_str(const UChar* s, const UChar* end){  return node_new_str(s, end);}static Node*node_new_str_raw(UChar* s, UChar* end){  Node* node = node_new_str(s, end);  NSTRING_SET_RAW(node);  return node;}static Node*node_new_empty(){  return node_new_str(NULL, NULL);}static Node*node_new_str_raw_char(UChar c){  UChar p[1];  p[0] = c;  return node_new_str_raw(p, p + 1);}static Node*str_node_split_last_char(StrNode* sn, OnigEncoding enc){  const UChar *p;  Node* n = NULL_NODE;  if (sn->end > sn->s) {    p = onigenc_get_prev_char_head(enc, sn->s, sn->end);    if (p && p > sn->s) { /* can be splitted. */      n = node_new_str(p, sn->end);      if ((sn->flag & NSTR_RAW) != 0)	NSTRING_SET_RAW(n);      sn->end = (UChar* )p;    }  }  return n;}static intstr_node_can_be_split(StrNode* sn, OnigEncoding enc){  if (sn->end > sn->s) {    return ((enc_len(enc, sn->s) < sn->end - sn->s)  ?  1 : 0);  }  return 0;}extern intonig_scan_unsigned_number(UChar** src, const UChar* end, OnigEncoding enc){  unsigned int num, val;  OnigCodePoint c;  UChar* p = *src;  PFETCH_READY;  num = 0;  while (!PEND) {    PFETCH(c);    if (ONIGENC_IS_CODE_DIGIT(enc, c)) {      val = (unsigned int )DIGITVAL(c);      if ((INT_MAX_LIMIT - val) / 10UL < num)	return -1;  /* overflow */      num = num * 10 + val;    }    else {      PUNFETCH;      break;    }  }  *src = p;  return num;}static intscan_unsigned_hexadecimal_number(UChar** src, UChar* end, int maxlen,				 OnigEncoding enc){  OnigCodePoint c;  unsigned int num, val;  UChar* p = *src;  PFETCH_READY;  num = 0;  while (!PEND && maxlen-- != 0) {    PFETCH(c);    if (ONIGENC_IS_CODE_XDIGIT(enc, c)) {      val = (unsigned int )XDIGITVAL(enc,c);      if ((INT_MAX_LIMIT - val) / 16UL < num)	return -1;  /* overflow */      num = (num << 4) + XDIGITVAL(enc,c);    }    else {      PUNFETCH;      break;    }  }  *src = p;  return num;}static intscan_unsigned_octal_number(UChar** src, UChar* end, int maxlen,			   OnigEncoding enc){  OnigCodePoint c;  unsigned int num, val;  UChar* p = *src;  PFETCH_READY;  num = 0;  while (!PEND && maxlen-- != 0) {    PFETCH(c);    if (ONIGENC_IS_CODE_DIGIT(enc, c) && c < '8') {      val = ODIGITVAL(c);      if ((INT_MAX_LIMIT - val) / 8UL < num)	return -1;  /* overflow */      num = (num << 3) + val;    }    else {      PUNFETCH;      break;    }  }  *src = p;  return num;}#define BBUF_WRITE_CODE_POINT(bbuf,pos,code) \    BBUF_WRITE(bbuf, pos, &(code), SIZE_CODE_POINT)/* data format:     [n][from-1][to-1][from-2][to-2] ... [from-n][to-n]     (all data size is OnigCodePoint) */static intnew_code_range(BBuf** pbuf){#define INIT_MULTI_BYTE_RANGE_SIZE  (SIZE_CODE_POINT * 5)  int r;  OnigCodePoint n;  BBuf* bbuf;  bbuf = *pbuf = (BBuf* )xmalloc(sizeof(BBuf));  CHECK_NULL_RETURN_VAL(*pbuf, ONIGERR_MEMORY);  r = BBUF_INIT(*pbuf, INIT_MULTI_BYTE_RANGE_SIZE);  if (r) return r;  n = 0;  BBUF_WRITE_CODE_POINT(bbuf, 0, n);  return 0;}static intadd_code_range_to_buf(BBuf** pbuf, OnigCodePoint from, OnigCodePoint to){  int r, inc_n, pos;  int low, high, bound, x;  OnigCodePoint n, *data;  BBuf* bbuf;  if (from > to) {    n = from; from = to; to = n;  }  if (IS_NULL(*pbuf)) {    r = new_code_range(pbuf);    if (r) return r;    bbuf = *pbuf;    n = 0;  }  else {    bbuf = *pbuf;    GET_CODE_POINT(n, bbuf->p);  }  data = (OnigCodePoint* )(bbuf->p);  data++;  for (low = 0, bound = n; low < bound; ) {    x = (low + bound) >> 1;    if (from > data[x*2 + 1])      low = x + 1;    else      bound = x;  }  for (high = low, bound = n; high < bound; ) {    x = (high + bound) >> 1;    if (to >= data[x*2] - 1)      high = x + 1;    else      bound = x;  }  inc_n = low + 1 - high;  if (n + inc_n > ONIG_MAX_MULTI_BYTE_RANGES_NUM)    return ONIGERR_TOO_MANY_MULTI_BYTE_RANGES;  if (inc_n != 1) {    if (from > data[low*2])      from = data[low*2];    if (to < data[(high - 1)*2 + 1])      to = data[(high - 1)*2 + 1];  }  if (inc_n != 0 && (OnigCodePoint )high < n) {    int from_pos = SIZE_CODE_POINT * (1 + high * 2);    int to_pos   = SIZE_CODE_POINT * (1 + (low + 1) * 2);    int size = (n - high) * 2 * SIZE_CODE_POINT;    if (inc_n > 0) {      BBUF_MOVE_RIGHT(bbuf, from_pos, to_pos, size);    }    else {      BBUF_MOVE_LEFT_REDUCE(bbuf, from_pos, to_pos);    }  }  pos = SIZE_CODE_POINT * (1 + low * 2);  BBUF_ENSURE_SIZE(bbuf, pos + SIZE_CODE_POINT * 2);  BBUF_WRITE_CODE_POINT(bbuf, pos, from);  BBUF_WRITE_CODE_POINT(bbuf, pos + SIZE_CODE_POINT, to);  n += inc_n;  BBUF_WRITE_CODE_POINT(bbuf, 0, n);  return 0;}static intadd_code_range(BBuf** pbuf, ScanEnv* env, OnigCodePoint from, OnigCodePoint to){  if (from > to) {    if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))      return 0;    else      return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;  }  return add_code_range_to_buf(pbuf, from, to);}static intnot_code_range_buf(OnigEncoding enc, BBuf* bbuf, BBuf** pbuf){  int r, i, n;  OnigCodePoint pre, from, *data, to = 0;  *pbuf = (BBuf* )NULL;  if (IS_NULL(bbuf)) {  set_all:    return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);  }  data = (OnigCodePoint* )(bbuf->p);  GET_CODE_POINT(n, data);  data++;  if (n <= 0) goto set_all;  r = 0;  pre = MBCODE_START_POS(enc);  for (i = 0; i < n; i++) {    from = data[i*2];    to   = data[i*2+1];    if (pre <= from - 1) {      r = add_code_range_to_buf(pbuf, pre, from - 1);      if (r != 0) return r;    }    if (to == ~((OnigCodePoint )0)) break;    pre = to + 1;  }  if (to < ~((OnigCodePoint )0)) {    r = add_code_range_to_buf(pbuf, to + 1, ~((OnigCodePoint )0));  }  return r;}#define SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2) do {\  BBuf *tbuf; \  int  tnot; \  tnot = not1;  not1  = not2;  not2  = tnot; \  tbuf = bbuf1; bbuf1 = bbuf2; bbuf2 = tbuf; \} while (0)static intor_code_range_buf(OnigEncoding enc, BBuf* bbuf1, int not1,                  BBuf* bbuf2, int not2, BBuf** pbuf){  int r;  OnigCodePoint i, n1, *data1;  OnigCodePoint from, to;  *pbuf = (BBuf* )NULL;  if (IS_NULL(bbuf1) && IS_NULL(bbuf2)) {    if (not1 != 0 || not2 != 0)      return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);    return 0;  }  r = 0;  if (IS_NULL(bbuf2))    SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);  if (IS_NULL(bbuf1)) {    if (not1 != 0) {      return SET_ALL_MULTI_BYTE_RANGE(enc, pbuf);    }    else {      if (not2 == 0) {	return bbuf_clone(pbuf, bbuf2);      }      else {	return not_code_range_buf(enc, bbuf2, pbuf);      }    }  }  if (not1 != 0)    SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);  data1 = (OnigCodePoint* )(bbuf1->p);  GET_CODE_POINT(n1, data1);  data1++;  if (not2 == 0 && not1 == 0) { /* 1 OR 2 */    r = bbuf_clone(pbuf, bbuf2);  }  else if (not1 == 0) { /* 1 OR (not 2) */    r = not_code_range_buf(enc, bbuf2, pbuf);  }  if (r != 0) return r;  for (i = 0; i < n1; i++) {    from = data1[i*2];    to   = data1[i*2+1];    r = add_code_range_to_buf(pbuf, from, to);    if (r != 0) return r;  }  return 0;}static intand_code_range1(BBuf** pbuf, OnigCodePoint from1, OnigCodePoint to1,	        OnigCodePoint* data, int n){  int i, r;  OnigCodePoint from2, to2;  for (i = 0; i < n; i++) {    from2 = data[i*2];    to2   = data[i*2+1];    if (from2 < from1) {      if (to2 < from1) continue;      else {	from1 = to2 + 1;      }    }    else if (from2 <= to1) {      if (to2 < to1) {	if (from1 <= from2 - 1) {	  r = add_code_range_to_buf(pbuf, from1, from2-1);	  if (r != 0) return r;	}	from1 = to2 + 1;      }      else {	to1 = from2 - 1;      }    }    else {      from1 = from2;    }    if (from1 > to1) break;  }  if (from1 <= to1) {    r = add_code_range_to_buf(pbuf, from1, to1);    if (r != 0) return r;  }  return 0;}static intand_code_range_buf(BBuf* bbuf1, int not1, BBuf* bbuf2, int not2, BBuf** pbuf){  int r;  OnigCodePoint i, j, n1, n2, *data1, *data2;  OnigCodePoint from, to, from1, to1, from2, to2;  *pbuf = (BBuf* )NULL;  if (IS_NULL(bbuf1)) {    if (not1 != 0 && IS_NOT_NULL(bbuf2)) /* not1 != 0 -> not2 == 0 */      return bbuf_clone(pbuf, bbuf2);    return 0;  }  else if (IS_NULL(bbuf2)) {    if (not2 != 0)      return bbuf_clone(pbuf, bbuf1);    return 0;  }  if (not1 != 0)    SWAP_BBUF_NOT(bbuf1, not1, bbuf2, not2);  data1 = (OnigCodePoint* )(bbuf1->p);  data2 = (OnigCodePoint* )(bbuf2->p);  GET_CODE_POINT(n1, data1);  GET_CODE_POINT(n2, data2);  data1++;  data2++;  if (not2 == 0 && not1 == 0) { /* 1 AND 2 */    for (i = 0; i < n1; i++) {      from1 = data1[i*2];      to1   = data1[i*2+1];      for (j = 0; j < n2; j++) {	from2 = data2[j*2];	to2   = data2[j*2+1];	if (from2 > to1) break;	if (to2 < from1) continue;	from = MAX(from1, from2);	to   = MIN(to1, to2);	r = add_code_range_to_buf(pbuf, from, to);	if (r != 0) return r;      }    }  }  else if (not1 == 0) { /* 1 AND (not 2) */    for (i = 0; i < n1; i++) {      from1 = data1[i*2];      to1   = data1[i*2+1];      r = and_code_range1(pbuf, from1, to1, data2, n2);      if (r != 0) return r;    }  }  return 0;}static intclear_not_flag_cclass(CClassNode* cc, OnigEncoding enc){  BBuf *tbuf;  int r;  if (IS_CCLASS_NOT(cc)) {    bitset_invert(cc->bs);    if (! ONIGENC_IS_SINGLEBYTE(enc)) {      r = not_code_range_buf(enc, cc->mbuf, &tbuf);      if (r != 0) return r;      bbuf_free(cc->mbuf);

⌨️ 快捷键说明

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