Commit message: merge Ruby 1.9.2
CVE: CVE-2019-16162
Vulnerability description: Onigmo through 6.2.0 has an out-of-bounds read in parse_char_class because of missing codepoint validation in regenc.c.

Project: Onigmo

utf16be_mbc_enc_len(const UChar* p, const OnigUChar* e ARG_UNUSED,
		    OnigEncoding enc ARG_UNUSED)
{
  int byte = p[0];
  if (!UTF16_IS_SURROGATE(byte)) {
    if (2 <= e-p)
      return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2);
    else
      return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
  }
  if (UTF16_IS_SURROGATE_FIRST(byte)) {
    switch (e-p) {
      case 1: return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(3);
      case 2: return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(2);
      case 3:
        if (UTF16_IS_SURROGATE_SECOND(p[2]))
          return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
        break;
      default:
        if (UTF16_IS_SURROGATE_SECOND(p[2]))
          return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4);
        break;
    }
  }
  return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
}

Project: Onigmo

resize_property_list(int new_size, const OnigCodePoint*** plist, int* psize)
{
  size_t size;
  const OnigCodePoint **list = *plist;

  size = sizeof(OnigCodePoint*) * new_size;
  if (IS_NULL(list)) {
    list = (const OnigCodePoint** )xmalloc(size);
  }
  else {
    list = (const OnigCodePoint** )xrealloc((void* )list, size);
  }

  if (IS_NULL(list)) return ONIGERR_MEMORY;

  *plist = list;
  *psize = new_size;

  return 0;
}

Project: Onigmo

stat_col(void)
{
    char fname[10+sizeof(long)*3];
    FILE *f = fopen((snprintf(fname, sizeof(fname), "/tmp/col%ld", (long)getpid()), fname), "w");
    fprintf(f, "collision: %d / %d (%6.2f)\n", collision.all, collision.total,
	    ((double)collision.all / (collision.total)) * 100);
    fprintf(f, "num: %d, str: %d, strcase: %d\n", collision.num, collision.str, collision.strcase);
    fclose(f);
}

Project: Onigmo

st_hash_end(st_index_t h)
{
    h = murmur_step(h, 10);
    h = murmur_step(h, 17);
    return h;
}

Project: Onigmo

mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  int c, i, len;
  OnigCodePoint n;

  len = enclen(enc, p, end);
  n = (OnigCodePoint )*p++;
  if (len == 1) return n;

  for (i = 1; i < len; i++) {
    if (p >= end) break;
    c = *p++;
    n <<= 8;  n += c;
  }
  return n;
}

Project: Onigmo

st_hash_start(st_index_t h)
{
    return h;
}

Project: Onigmo

parse_exp(Node** np, OnigToken* tok, int term,
	  UChar** src, UChar* end, ScanEnv* env)
{
  int r, len, group = 0;
  Node* qn;
  Node** targetp;

  *np = NULL;
  if (tok->type == (enum TokenSyms )term)
    goto end_of_token;

  switch (tok->type) {
  case TK_ALT:
  case TK_EOT:
  end_of_token:
    *np = node_new_empty();
    return tok->type;

  case TK_SUBEXP_OPEN:
    r = parse_enclose(np, tok, TK_SUBEXP_CLOSE, src, end, env);
    if (r < 0) return r;
    if (r == 1) group = 1;
    else if (r == 2) { /* option only */
      Node* target;
      OnigOptionType prev = env->option;

      env->option = NENCLOSE(*np)->option;
      r = fetch_token(tok, src, end, env);
      if (r < 0) return r;
      r = parse_subexp(&target, tok, term, src, end, env);
      env->option = prev;
      if (r < 0) {
	onig_node_free(target);
	return r;
      }
      NENCLOSE(*np)->target = target;
      return tok->type;
    }
    break;

  case TK_SUBEXP_CLOSE:
    if (! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP))
      return ONIGERR_UNMATCHED_CLOSE_PARENTHESIS;

    if (tok->escaped) goto tk_raw_byte;
    else goto tk_byte;
    break;

  case TK_STRING:
  tk_byte:
    {
      *np = node_new_str(tok->backp, *src);
      CHECK_NULL_RETURN_MEMERR(*np);

      while (1) {
	r = fetch_token(tok, src, end, env);
	if (r < 0) return r;
	if (r != TK_STRING) break;

	r = onig_node_str_cat(*np, tok->backp, *src);
	if (r < 0) return r;
      }

    string_end:
      targetp = np;
      goto repeat;
    }
    break;

  case TK_RAW_BYTE:
  tk_raw_byte:
    {
      *np = node_new_str_raw_char((UChar )tok->u.c);
      CHECK_NULL_RETURN_MEMERR(*np);
      len = 1;
      while (1) {
	if (len >= ONIGENC_MBC_MINLEN(env->enc)) {
	  if (len == enclen(env->enc, NSTR(*np)->s, NSTR(*np)->end)) {
	    r = fetch_token(tok, src, end, env);
	    NSTRING_CLEAR_RAW(*np);
	    goto string_end;
	  }
	}

	r = fetch_token(tok, src, end, env);
	if (r < 0) return r;
	if (r != TK_RAW_BYTE) {
	  /* Don't use this, it is wrong for little endian encodings. */
#ifdef USE_PAD_TO_SHORT_BYTE_CHAR
	  int rem;
	  if (len < ONIGENC_MBC_MINLEN(env->enc)) {
	    rem = ONIGENC_MBC_MINLEN(env->enc) - len;
	    (void )node_str_head_pad(NSTR(*np), rem, (UChar )0);
	    if (len + rem == enclen(env->enc, NSTR(*np)->s)) {
	      NSTRING_CLEAR_RAW(*np);
	      goto string_end;
	    }
	  }
#endif
	  return ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
	}

	r = node_str_cat_char(*np, (UChar )tok->u.c);
	if (r < 0) return r;

	len++;
      }
    }
    break;

  case TK_CODE_POINT:
    {
      UChar buf[ONIGENC_CODE_TO_MBC_MAXLEN];
      int num = ONIGENC_CODE_TO_MBC(env->enc, tok->u.code, buf);
      if (num < 0) return num;
#ifdef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
      *np = node_new_str_raw(buf, buf + num);
#else
      *np = node_new_str(buf, buf + num);
#endif
      CHECK_NULL_RETURN_MEMERR(*np);
    }
    break;

  case TK_QUOTE_OPEN:
    {
      OnigCodePoint end_op[2];
      UChar *qstart, *qend, *nextp;

      end_op[0] = (OnigCodePoint )MC_ESC(env->syntax);
      end_op[1] = (OnigCodePoint )'E';
      qstart = *src;
      qend = find_str_position(end_op, 2, qstart, end, &nextp, env->enc);
      if (IS_NULL(qend)) {
	nextp = qend = end;
      }
      *np = node_new_str(qstart, qend);
      CHECK_NULL_RETURN_MEMERR(*np);
      *src = nextp;
    }
    break;

  case TK_CHAR_TYPE:
    {
      switch (tok->u.prop.ctype) {
      case ONIGENC_CTYPE_D:
      case ONIGENC_CTYPE_S:
      case ONIGENC_CTYPE_W:
	{
	    CClassNode* cc;
	    *np = node_new_cclass();
	    CHECK_NULL_RETURN_MEMERR(*np);
	    cc = NCCLASS(*np);
	    add_ctype_to_cc(cc, tok->u.prop.ctype, 0, env);
	    if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
	}
	break;

      case ONIGENC_CTYPE_WORD:
	*np = node_new_ctype(tok->u.prop.ctype, tok->u.prop.not);
	CHECK_NULL_RETURN_MEMERR(*np);
	break;

      case ONIGENC_CTYPE_SPACE:
      case ONIGENC_CTYPE_DIGIT:
      case ONIGENC_CTYPE_XDIGIT:
	{
	  CClassNode* cc;

#ifdef USE_SHARED_CCLASS_TABLE
          const OnigCodePoint *mbr;
	  OnigCodePoint sb_out;

          r = ONIGENC_GET_CTYPE_CODE_RANGE(env->enc, tok->u.prop.ctype,
					   &sb_out, &mbr);
          if (r == 0 &&
              ONIGENC_CODE_RANGE_NUM(mbr)
              >= THRESHOLD_RANGE_NUM_FOR_SHARE_CCLASS) {
            type_cclass_key  key;
            type_cclass_key* new_key;

            key.enc  = env->enc;
            key.not  = tok->u.prop.not;
            key.type = tok->u.prop.ctype;

            THREAD_ATOMIC_START;

            if (IS_NULL(OnigTypeCClassTable)) {
              OnigTypeCClassTable
                = onig_st_init_table_with_size(&type_type_cclass_hash, 10);
              if (IS_NULL(OnigTypeCClassTable)) {
                THREAD_ATOMIC_END;
                return ONIGERR_MEMORY;
              }
            }
            else {
              if (onig_st_lookup(OnigTypeCClassTable, (st_data_t )&key,
                                 (st_data_t* )np)) {
                THREAD_ATOMIC_END;
                break;
              }
            }

            *np = node_new_cclass_by_codepoint_range(tok->u.prop.not,
						     sb_out, mbr);
            if (IS_NULL(*np)) {
              THREAD_ATOMIC_END;
              return ONIGERR_MEMORY;
            }

            cc = NCCLASS(*np);
            NCCLASS_SET_SHARE(cc);
            new_key = (type_cclass_key* )xmalloc(sizeof(type_cclass_key));
	    xmemcpy(new_key, &key, sizeof(type_cclass_key));
            onig_st_add_direct(OnigTypeCClassTable, (st_data_t )new_key,
                               (st_data_t )*np);

            THREAD_ATOMIC_END;
          }
          else {
#endif
            *np = node_new_cclass();
            CHECK_NULL_RETURN_MEMERR(*np);
            cc = NCCLASS(*np);
            add_ctype_to_cc(cc, tok->u.prop.ctype, 0, env);
            if (tok->u.prop.not != 0) NCCLASS_SET_NOT(cc);
#ifdef USE_SHARED_CCLASS_TABLE
          }
#endif
	}
	break;

      default:
	return ONIGERR_PARSER_BUG;
	break;
      }
    }
    break;

  case TK_CHAR_PROPERTY:
    r = parse_char_property(np, tok, src, end, env);
    if (r != 0) return r;
    break;

  case TK_CC_OPEN:
    {
      CClassNode* cc;

      r = parse_char_class(np, tok, src, end, env);
      if (r != 0) return r;

      cc = NCCLASS(*np);
      if (IS_IGNORECASE(env->option)) {
	IApplyCaseFoldArg iarg;

	iarg.env      = env;
	iarg.cc       = cc;
	iarg.alt_root = NULL_NODE;
	iarg.ptail    = &(iarg.alt_root);

	r = ONIGENC_APPLY_ALL_CASE_FOLD(env->enc, env->case_fold_flag,
					i_apply_case_fold, &iarg);
	if (r != 0) {
	  onig_node_free(iarg.alt_root);
	  return r;
	}
	if (IS_NOT_NULL(iarg.alt_root)) {
          Node* work = onig_node_new_alt(*np, iarg.alt_root);
          if (IS_NULL(work)) {
            onig_node_free(iarg.alt_root);
            return ONIGERR_MEMORY;
          }
          *np = work;
	}
      }
    }
    break;

  case TK_ANYCHAR:
    *np = node_new_anychar();
    CHECK_NULL_RETURN_MEMERR(*np);
    break;

  case TK_ANYCHAR_ANYTIME:
    *np = node_new_anychar();
    CHECK_NULL_RETURN_MEMERR(*np);
    qn = node_new_quantifier(0, REPEAT_INFINITE, 0);
    CHECK_NULL_RETURN_MEMERR(qn);
    NQTFR(qn)->target = *np;
    *np = qn;
    break;

  case TK_BACKREF:
    len = tok->u.backref.num;
    *np = node_new_backref(len,
		   (len > 1 ? tok->u.backref.refs : &(tok->u.backref.ref1)),
			   tok->u.backref.by_name,
#ifdef USE_BACKREF_WITH_LEVEL
			   tok->u.backref.exist_level,
			   tok->u.backref.level,
#endif
			   env);
    CHECK_NULL_RETURN_MEMERR(*np);
    break;

#ifdef USE_SUBEXP_CALL
  case TK_CALL:
    {
      int gnum = tok->u.call.gnum;

      if (gnum < 0) {
	gnum = BACKREF_REL_TO_ABS(gnum, env);
	if (gnum <= 0)
	  return ONIGERR_INVALID_BACKREF;
      }
      *np = node_new_call(tok->u.call.name, tok->u.call.name_end, gnum);
      CHECK_NULL_RETURN_MEMERR(*np);
      env->num_call++;
    }
    break;
#endif

  case TK_ANCHOR:
    *np = onig_node_new_anchor(tok->u.anchor);
    break;

  case TK_OP_REPEAT:
  case TK_INTERVAL:
    if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS)) {
      if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS))
	return ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED;
      else
	*np = node_new_empty();
    }
    else {
      goto tk_byte;
    }
    break;

  default:
    return ONIGERR_PARSER_BUG;
    break;
  }

  {
    targetp = np;

  re_entry:
    r = fetch_token(tok, src, end, env);
    if (r < 0) return r;

  repeat:
    if (r == TK_OP_REPEAT || r == TK_INTERVAL) {
      if (is_invalid_quantifier_target(*targetp))
	return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;

      qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
			       (r == TK_INTERVAL ? 1 : 0));
      CHECK_NULL_RETURN_MEMERR(qn);
      NQTFR(qn)->greedy = tok->u.repeat.greedy;
      r = set_quantifier(qn, *targetp, group, env);
      if (r < 0) {
	onig_node_free(qn);
	return r;
      }

      if (tok->u.repeat.possessive != 0) {
	Node* en;
	en = node_new_enclose(ENCLOSE_STOP_BACKTRACK);
	if (IS_NULL(en)) {
	  onig_node_free(qn);
	  return ONIGERR_MEMORY;
	}
	NENCLOSE(en)->target = qn;
	qn = en;
      }

      if (r == 0) {
	*targetp = qn;
      }
      else if (r == 1) {
        onig_node_free(qn);
      }
      else if (r == 2) { /* split case: /abc+/ */
	Node *tmp;

	*targetp = node_new_list(*targetp, NULL);
	if (IS_NULL(*targetp)) {
	  onig_node_free(qn);
	  return ONIGERR_MEMORY;
	}
	tmp = NCDR(*targetp) = node_new_list(qn, NULL);
	if (IS_NULL(tmp)) {
	  onig_node_free(qn);
	  return ONIGERR_MEMORY;
	}
	targetp = &(NCAR(tmp));
      }
      goto re_entry;
    }
  }

  return r;
}

Project: Onigmo

utf16le_mbc_case_fold(OnigCaseFoldType flag,
		      const UChar** pp, const UChar* end, UChar* fold,
		      OnigEncoding enc)
{
  const UChar* p = *pp;

  if (ONIGENC_IS_ASCII_CODE(*p) && *(p+1) == 0) {
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
    if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
      if (*p == 0x49) {
	*fold++ = 0x31;
	*fold   = 0x01;
	(*pp) += 2;
	return 2;
      }
    }
#endif

    *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
    *fold   = 0;
    *pp += 2;
    return 2;
  }
  else
    return onigenc_unicode_mbc_case_fold(enc, flag, pp,
					 end, fold);
}

Project: Onigmo

gb18030_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  return onigenc_mb4_code_to_mbc(enc, code, buf);
}

Project: Onigmo

get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
		     const OnigCodePoint* ranges[], OnigEncoding enc ARG_UNUSED)
{
  if (ctype <= ONIGENC_MAX_STD_CTYPE) {
    return ONIG_NO_SUPPORT_CONFIG;
  }
  else {
    *sb_out = 0x80;

    PROPERTY_LIST_INIT_CHECK;

    ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
    if (ctype >= (OnigCtype )PropertyListNum)
      return ONIGERR_TYPE_BUG;

    *ranges = PropertyList[ctype];
    return 0;
  }
}

Project: Onigmo

gb18030_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  int c, i, len;
  OnigCodePoint n;

  len = enclen(enc, p, end);
  n = (OnigCodePoint )(*p++);
  if (len == 1) return n;

  for (i = 1; i < len; i++) {
    if (p >= end) break;
    c = *p++;
    n <<= 8;  n += c;
  }
  return n;
}

Project: Onigmo

mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
{
  int firstbyte = *p++;
  state_t s;
  s = trans[0][firstbyte];
  if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
                                  ONIGENC_CONSTRUCT_MBCLEN_INVALID();
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-1);
  s = trans[s][*p++];
  if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
                                  ONIGENC_CONSTRUCT_MBCLEN_INVALID();
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-2);
  s = trans[s][*p++];
  if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
                                  ONIGENC_CONSTRUCT_MBCLEN_INVALID();
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EmacsMule[firstbyte]-3);
  s = trans[s][*p++];
  return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4) :
                       ONIGENC_CONSTRUCT_MBCLEN_INVALID();
}

Project: Onigmo

left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
  /* In this encoding
     mb-trail bytes doesn't mix with single bytes.
  */
  const UChar *p;
  int len;

  if (s <= start) return (UChar* )s;
  p = s;

  while (!eucjp_islead(*p) && p > start) p--;
  len = enclen(enc, p, end);
  if (p + len > s) return (UChar* )p;
  p += len;
  return (UChar* )(p + ((s - p) & ~1));
}

Project: Onigmo

Init_gb2312(void)
{
    rb_enc_register("GB2312", rb_enc_find("EUC-KR"));
}

Project: Onigmo

st_memsize(const st_table *table)
{
    if (table->entries_packed) {
	return table->num_bins * sizeof (void *) + sizeof(st_table);
    }
    else {
	return table->num_entries * sizeof(struct st_table_entry) + table->num_bins * sizeof (void *) + sizeof(st_table);
    }
}

Project: Onigmo

euckr_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  return onigenc_mb2_code_to_mbc(enc, code, buf);
}

Project: Onigmo

koi8_r_apply_all_case_fold(OnigCaseFoldType flag,
			   OnigApplyAllCaseFoldFunc f,
			   void* arg, OnigEncoding enc ARG_UNUSED)
{
  return onigenc_apply_all_case_fold_with_map(
             sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
             flag, f, arg);
}

Project: Onigmo

onigenc_unicode_apply_all_case_fold(OnigCaseFoldType flag,
				    OnigApplyAllCaseFoldFunc f, void* arg,
				    OnigEncoding enc ARG_UNUSED)
{
  const CaseUnfold_11_Type* p11;
  OnigCodePoint code;
  int i, j, k, r;

  /* if (CaseFoldInited == 0) init_case_fold_table(); */

  for (i = 0; i < numberof(CaseUnfold_11); i++) {
    p11 = &CaseUnfold_11[i];
    for (j = 0; j < p11->to.n; j++) {
      code = p11->from;
      r = (*f)(p11->to.code[j], &code, 1, arg);
      if (r != 0) return r;

      code = p11->to.code[j];
      r = (*f)(p11->from, &code, 1, arg);
      if (r != 0) return r;

      for (k = 0; k < j; k++) {
	r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]), 1, arg);
	if (r != 0) return r;

	r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]), 1, arg);
	if (r != 0) return r;
      }
    }
  }

#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
  if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
    code = 0x0131;
    r = (*f)(0x0049, &code, 1, arg);
    if (r != 0) return r;
    code = 0x0049;
    r = (*f)(0x0131, &code, 1, arg);
    if (r != 0) return r;

    code = 0x0130;
    r = (*f)(0x0069, &code, 1, arg);
    if (r != 0) return r;
    code = 0x0069;
    r = (*f)(0x0130, &code, 1, arg);
    if (r != 0) return r;
  }
  else {
#endif
    for (i = 0; i < numberof(CaseUnfold_11_Locale); i++) {
      p11 = &CaseUnfold_11_Locale[i];
      for (j = 0; j < p11->to.n; j++) {
	code = p11->from;
	r = (*f)(p11->to.code[j], &code, 1, arg);
	if (r != 0) return r;

	code = p11->to.code[j];
	r = (*f)(p11->from, &code, 1, arg);
	if (r != 0) return r;

	for (k = 0; k < j; k++) {
	  r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]),
		   1, arg);
	  if (r != 0) return r;

	  r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]),
		   1, arg);
	  if (r != 0) return r;
	}
      }
    }
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
  }
#endif

  if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
    for (i = 0; i < numberof(CaseUnfold_12); i++) {
      for (j = 0; j < CaseUnfold_12[i].to.n; j++) {
	r = (*f)(CaseUnfold_12[i].to.code[j],
		 (OnigCodePoint* )CaseUnfold_12[i].from, 2, arg);
	if (r != 0) return r;

	for (k = 0; k < CaseUnfold_12[i].to.n; k++) {
	  if (k == j) continue;

	  r = (*f)(CaseUnfold_12[i].to.code[j],
		   (OnigCodePoint* )(&CaseUnfold_12[i].to.code[k]), 1, arg);
	  if (r != 0) return r;
	}
      }
    }

#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
    if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) == 0) {
#endif
      for (i = 0; i < numberof(CaseUnfold_12_Locale); i++) {
	for (j = 0; j < CaseUnfold_12_Locale[i].to.n; j++) {
	  r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
		   (OnigCodePoint* )CaseUnfold_12_Locale[i].from, 2, arg);
	  if (r != 0) return r;

	  for (k = 0; k < CaseUnfold_12_Locale[i].to.n; k++) {
	    if (k == j) continue;

	    r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
		     (OnigCodePoint* )(&CaseUnfold_12_Locale[i].to.code[k]),
		     1, arg);
	    if (r != 0) return r;
	  }
	}
      }
#ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
    }
#endif

    for (i = 0; i < numberof(CaseUnfold_13); i++) {
      for (j = 0; j < CaseUnfold_13[i].to.n; j++) {
	r = (*f)(CaseUnfold_13[i].to.code[j],
		 (OnigCodePoint* )CaseUnfold_13[i].from, 3, arg);
	if (r != 0) return r;

	for (k = 0; k < CaseUnfold_13[i].to.n; k++) {
	  if (k == j) continue;

	  r = (*f)(CaseUnfold_13[i].to.code[j],
		   (OnigCodePoint* )(&CaseUnfold_13[i].to.code[k]), 1, arg);
	  if (r != 0) return r;
	}
      }
    }
  }

  return 0;
}

Project: Onigmo

koi8_u_apply_all_case_fold(OnigCaseFoldType flag,
			   OnigApplyAllCaseFoldFunc f,
			   void* arg, OnigEncoding enc ARG_UNUSED)
{
  return onigenc_apply_all_case_fold_with_map(
             sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
             flag, f, arg);
}

Project: Onigmo

onig_reg_init(regex_t* reg, OnigOptionType option,
	      OnigCaseFoldType case_fold_flag,
	      OnigEncoding enc, const OnigSyntaxType* syntax)
{
  if (! onig_inited)
    onig_init();

  if (IS_NULL(reg))
    return ONIGERR_INVALID_ARGUMENT;

  if (ONIGENC_IS_UNDEF(enc))
    return ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED;

  if ((option & (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP))
      == (ONIG_OPTION_DONT_CAPTURE_GROUP|ONIG_OPTION_CAPTURE_GROUP)) {
    return ONIGERR_INVALID_COMBINATION_OF_OPTIONS;
  }

  (reg)->state = ONIG_STATE_MODIFY;

  if ((option & ONIG_OPTION_NEGATE_SINGLELINE) != 0) {
    option |= syntax->options;
    option &= ~ONIG_OPTION_SINGLELINE;
  }
  else
    option |= syntax->options;

  (reg)->enc              = enc;
  (reg)->options          = option;
  (reg)->syntax           = syntax;
  (reg)->optimize         = 0;
  (reg)->exact            = (UChar* )NULL;
  (reg)->int_map          = (int* )NULL;
  (reg)->int_map_backward = (int* )NULL;
  (reg)->chain            = (regex_t* )NULL;

  (reg)->p                = (UChar* )NULL;
  (reg)->alloc            = 0;
  (reg)->used             = 0;
  (reg)->name_table       = (void* )NULL;

  (reg)->case_fold_flag   = case_fold_flag;
  return 0;
}

Project: Onigmo

code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
{
  if (ONIGENC_IS_CODE_ASCII(code)) return 1;
  else if (code > 0xffffff) return 0;
  else if ((code & 0xff0000) >= 0x800000) return 3;
  else if ((code &   0xff00) >= 0x8000) return 2;
  else
    return ONIGERR_INVALID_CODE_POINT_VALUE;
}

Project: Onigmo

cp949_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
{
  const UChar c = *s;
  return (CP949_ISMB_TRAIL(c) ? FALSE : TRUE);
}

Project: Onigmo

gbk_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
  const UChar *p;
  int len;

  if (s <= start) return (UChar* )s;
  p = s;

  if (GBK_ISMB_TRAIL(*p)) {
    while (p > start) {
      if (! GBK_ISMB_FIRST(*--p)) {
	p++;
	break;
      }
    }
  }
  len = enclen(enc, p, end);
  if (p + len > s) return (UChar* )p;
  p += len;
  return (UChar* )(p + ((s - p) & ~1));
}

Project: Onigmo

next_state_val(CClassNode* cc, OnigCodePoint *vs, OnigCodePoint v,
	       int* vs_israw, int v_israw,
	       enum CCVALTYPE intype, enum CCVALTYPE* type,
	       enum CCSTATE* state, ScanEnv* env)
{
  int r;

  switch (*state) {
  case CCS_VALUE:
    if (*type == CCV_SB)
      BITSET_SET_BIT_CHKDUP(cc->bs, (int )(*vs));
    else if (*type == CCV_CODE_POINT) {
      r = add_code_range(&(cc->mbuf), env, *vs, *vs);
      if (r < 0) return r;
    }
    break;

  case CCS_RANGE:
    if (intype == *type) {
      if (intype == CCV_SB) {
        if (*vs > 0xff || v > 0xff)
          return ONIGERR_INVALID_CODE_POINT_VALUE;

	if (*vs > v) {
	  if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
	    goto ccs_range_end;
	  else
	    return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
	}
	bitset_set_range(env, cc->bs, (int )*vs, (int )v);
      }
      else {
	r = add_code_range(&(cc->mbuf), env, *vs, v);
	if (r < 0) return r;
      }
    }
    else {
#if 0
      if (intype == CCV_CODE_POINT && *type == CCV_SB) {
#endif
	if (*vs > v) {
	  if (IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC))
	    goto ccs_range_end;
	  else
	    return ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS;
	}
	bitset_set_range(env, cc->bs, (int )*vs, (int )(v < 0xff ? v : 0xff));
	r = add_code_range(&(cc->mbuf), env, (OnigCodePoint )*vs, v);
	if (r < 0) return r;
#if 0
      }
      else
	return ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE;
#endif
    }
  ccs_range_end:
    *state = CCS_COMPLETE;
    break;

  case CCS_COMPLETE:
  case CCS_START:
    *state = CCS_VALUE;
    break;

  default:
    break;
  }

  *vs_israw = v_israw;
  *vs       = v;
  *type     = intype;
  return 0;
}

Project: Onigmo

onig_match(regex_t* reg, const UChar* str, const UChar* end, const UChar* at, OnigRegion* region,
	    OnigOptionType option)
{
  long r;
  UChar *prev;
  OnigMatchArg msa;

#if defined(USE_RECOMPILE_API) && defined(USE_MULTI_THREAD_SYSTEM)
 start:
  THREAD_ATOMIC_START;
  if (ONIG_STATE(reg) >= ONIG_STATE_NORMAL) {
    ONIG_STATE_INC(reg);
    if (IS_NOT_NULL(reg->chain) && ONIG_STATE(reg) == ONIG_STATE_NORMAL) {
      onig_chain_reduce(reg);
      ONIG_STATE_INC(reg);
    }
  }
  else {
    int n;

    THREAD_ATOMIC_END;
    n = 0;
    while (ONIG_STATE(reg) < ONIG_STATE_NORMAL) {
      if (++n > THREAD_PASS_LIMIT_COUNT)
	return ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT;
      THREAD_PASS;
    }
    goto start;
  }
  THREAD_ATOMIC_END;
#endif /* USE_RECOMPILE_API && USE_MULTI_THREAD_SYSTEM */

  MATCH_ARG_INIT(msa, option, region, at);
#ifdef USE_COMBINATION_EXPLOSION_CHECK
  {
    int offset = at - str;
    STATE_CHECK_BUFF_INIT(msa, end - str, offset, reg->num_comb_exp_check);
  }
#endif

  if (region
#ifdef USE_POSIX_API_REGION_OPTION
      && !IS_POSIX_REGION(option)
#endif
      ) {
    r = onig_region_resize_clear(region, reg->num_mem + 1);
  }
  else
    r = 0;

  if (r == 0) {
    prev = (UChar* )onigenc_get_prev_char_head(reg->enc, str, at, end);
    r = match_at(reg, str, end,
#ifdef USE_MATCH_RANGE_MUST_BE_INSIDE_OF_SPECIFIED_RANGE
		 end,
#endif
		 at, prev, &msa);
  }

  MATCH_ARG_FREE(msa);
  ONIG_STATE_DEC_THREAD(reg);
  return r;
}

Project: Onigmo

koi8_r_get_case_fold_codes_by_str(OnigCaseFoldType flag,
		  const OnigUChar* p, const OnigUChar* end,
		  OnigCaseFoldCodeItem items[], OnigEncoding enc ARG_UNUSED)
{
  return onigenc_get_case_fold_codes_by_str_with_map(
	     sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
	     flag, p, end, items);
}

Project: Onigmo

left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
  const UChar *p;

  if (s <= start) return (UChar* )s;
  p = s;

  while (!emacsmule_islead(*p) && p > start) p--;
  return (UChar* )p;
}

Project: Onigmo

add_ctype_to_cc(CClassNode* cc, int ctype, int not, ScanEnv* env)
{
  int c, r;
  const OnigCodePoint *ranges;
  OnigCodePoint sb_out;
  OnigEncoding enc = env->enc;

  switch (ctype) {
  case ONIGENC_CTYPE_D:
  case ONIGENC_CTYPE_S:
  case ONIGENC_CTYPE_W:
    ctype ^= ONIGENC_CTYPE_SPECIAL_MASK;
    if (not != 0) {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (! ONIGENC_IS_ASCII_CODE_CTYPE((OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
      ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
    }
    else {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (ONIGENC_IS_ASCII_CODE_CTYPE((OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
    }
    return 0;
    break;
  }

  r = ONIGENC_GET_CTYPE_CODE_RANGE(enc, ctype, &sb_out, &ranges);
  if (r == 0) {
    return add_ctype_to_cc_by_range(cc, ctype, not, env, sb_out, ranges);
  }
  else if (r != ONIG_NO_SUPPORT_CONFIG) {
    return r;
  }

  r = 0;
  switch (ctype) {
  case ONIGENC_CTYPE_ALPHA:
  case ONIGENC_CTYPE_BLANK:
  case ONIGENC_CTYPE_CNTRL:
  case ONIGENC_CTYPE_DIGIT:
  case ONIGENC_CTYPE_LOWER:
  case ONIGENC_CTYPE_PUNCT:
  case ONIGENC_CTYPE_SPACE:
  case ONIGENC_CTYPE_UPPER:
  case ONIGENC_CTYPE_XDIGIT:
  case ONIGENC_CTYPE_ASCII:
  case ONIGENC_CTYPE_ALNUM:
    if (not != 0) {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
      ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
    }
    else {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
    }
    break;

  case ONIGENC_CTYPE_GRAPH:
  case ONIGENC_CTYPE_PRINT:
    if (not != 0) {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (! ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
    }
    else {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (ONIGENC_IS_CODE_CTYPE(enc, (OnigCodePoint )c, ctype))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
      ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
    }
    break;

  case ONIGENC_CTYPE_WORD:
    if (not == 0) {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
	if (IS_CODE_SB_WORD(enc, c)) BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
      ADD_ALL_MULTI_BYTE_RANGE(enc, cc->mbuf);
    }
    else {
      for (c = 0; c < SINGLE_BYTE_SIZE; c++) {
        if ((ONIGENC_CODE_TO_MBCLEN(enc, c) > 0) /* check invalid code point */
	    && ! ONIGENC_IS_CODE_WORD(enc, c))
	  BITSET_SET_BIT_CHKDUP(cc->bs, c);
      }
    }
    break;

  default:
    return ONIGERR_PARSER_BUG;
    break;
  }

  return r;
}

Project: Onigmo

CLOSE_BRACKET_WITHOUT_ESC_WARN(ScanEnv* env, UChar* c)
{
  if (onig_warn == onig_null_warn) return ;

  if (IS_SYNTAX_BV((env)->syntax, ONIG_SYN_WARN_CC_OP_NOT_ESCAPED)) {
      onig_syntax_warn(env, "regular expression has '%s' without escape", c);
  }
}

Project: Onigmo

fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
{
  int r, num;
  OnigCodePoint c;
  OnigEncoding enc = env->enc;
  const OnigSyntaxType* syn = env->syntax;
  UChar* prev;
  UChar* p = *src;
  PFETCH_READY;

 start:
  if (PEND) {
    tok->type = TK_EOT;
    return tok->type;
  }

  tok->type  = TK_STRING;
  tok->base  = 0;
  tok->backp = p;

  PFETCH(c);
  if (IS_MC_ESC_CODE(c, syn)) {
    if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;

    tok->backp = p;
    PFETCH(c);

    tok->u.c = c;
    tok->escaped = 1;
    switch (c) {
    case '*':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF)) break;
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 0;
      tok->u.repeat.upper = REPEAT_INFINITE;
      goto greedy_check;
      break;

    case '+':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_PLUS_ONE_INF)) break;
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 1;
      tok->u.repeat.upper = REPEAT_INFINITE;
      goto greedy_check;
      break;

    case '?':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_QMARK_ZERO_ONE)) break;
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 0;
      tok->u.repeat.upper = 1;
    greedy_check:
      if (!PEND && PPEEK_IS('?') &&
	  IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_NON_GREEDY)) {
	PFETCH(c);
	tok->u.repeat.greedy     = 0;
	tok->u.repeat.possessive = 0;
      }
      else {
      possessive_check:
	if (!PEND && PPEEK_IS('+') &&
	    ((IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT) &&
	      tok->type != TK_INTERVAL)  ||
	     (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL) &&
	      tok->type == TK_INTERVAL))) {
	  PFETCH(c);
	  tok->u.repeat.greedy     = 1;
	  tok->u.repeat.possessive = 1;
	}
	else {
	  tok->u.repeat.greedy     = 1;
	  tok->u.repeat.possessive = 0;
	}
      }
      break;

    case '{':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_BRACE_INTERVAL)) break;
      r = fetch_range_quantifier(&p, end, tok, env);
      if (r < 0) return r;  /* error */
      if (r == 0) goto greedy_check;
      else if (r == 2) { /* {n} */
	if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
	  goto possessive_check;

	goto greedy_check;
      }
      /* r == 1 : normal char */
      break;

    case '|':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_VBAR_ALT)) break;
      tok->type = TK_ALT;
      break;

    case '(':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
      tok->type = TK_SUBEXP_OPEN;
      break;

    case ')':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LPAREN_SUBEXP)) break;
      tok->type = TK_SUBEXP_CLOSE;
      break;

    case 'w':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_W;
      tok->u.prop.not   = 0;
      break;

    case 'W':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_W_WORD)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_W;
      tok->u.prop.not   = 1;
      break;

    case 'b':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
      tok->type = TK_ANCHOR;
      tok->u.anchor = ANCHOR_WORD_BOUND;
      break;

    case 'B':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break;
      tok->type = TK_ANCHOR;
      tok->u.anchor = ANCHOR_NOT_WORD_BOUND;
      break;

#ifdef USE_WORD_BEGIN_END
    case '<':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
      tok->type = TK_ANCHOR;
      tok->u.anchor = ANCHOR_WORD_BEGIN;
      break;

    case '>':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break;
      tok->type = TK_ANCHOR;
      tok->u.anchor = ANCHOR_WORD_END;
      break;
#endif

    case 's':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_S;
      tok->u.prop.not   = 0;
      break;

    case 'S':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_S_WHITE_SPACE)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_S;
      tok->u.prop.not   = 1;
      break;

    case 'd':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_D;
      tok->u.prop.not   = 0;
      break;

    case 'D':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_D_DIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_D;
      tok->u.prop.not   = 1;
      break;

    case 'h':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
      tok->u.prop.not   = 0;
      break;

    case 'H':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
      tok->u.prop.not   = 1;
      break;

    case 'A':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
    begin_buf:
      tok->type = TK_ANCHOR;
      tok->u.subtype = ANCHOR_BEGIN_BUF;
      break;

    case 'Z':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
      tok->type = TK_ANCHOR;
      tok->u.subtype = ANCHOR_SEMI_END_BUF;
      break;

    case 'z':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break;
    end_buf:
      tok->type = TK_ANCHOR;
      tok->u.subtype = ANCHOR_END_BUF;
      break;

    case 'G':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR)) break;
      tok->type = TK_ANCHOR;
      tok->u.subtype = ANCHOR_BEGIN_POSITION;
      break;

    case '`':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
      goto begin_buf;
      break;

    case '\'':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR)) break;
      goto end_buf;
      break;

    case 'x':
      if (PEND) break;

      prev = p;
      if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
	PINC;
	num = scan_unsigned_hexadecimal_number(&p, end, 8, enc);
	if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
	if (!PEND) {
          if (ONIGENC_IS_CODE_XDIGIT(enc, PPEEK))
            return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
        }

	if ((p > prev + enclen(enc, prev, end)) && !PEND && PPEEK_IS('}')) {
	  PINC;
	  tok->type   = TK_CODE_POINT;
	  tok->u.code = (OnigCodePoint )num;
	}
	else {
	  /* can't read nothing or invalid format */
	  p = prev;
	}
      }
      else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
	num = scan_unsigned_hexadecimal_number(&p, end, 2, enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type = TK_RAW_BYTE;
	tok->base = 16;
	tok->u.c  = num;
      }
      break;

    case 'u':
      if (PEND) break;

      prev = p;
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
	num = scan_unsigned_hexadecimal_number(&p, end, 4, enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type   = TK_CODE_POINT;
	tok->base   = 16;
	tok->u.code = (OnigCodePoint )num;
      }
      break;

    case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
      PUNFETCH;
      prev = p;
      num = onig_scan_unsigned_number(&p, end, enc);
      if (num < 0 || num > ONIG_MAX_BACKREF_NUM) {
        goto skip_backref;
      }

      if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_DECIMAL_BACKREF) &&
	  (num <= env->num_mem || num <= 9)) { /* This spec. from GNU regex */
	if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
	  if (num > env->num_mem || IS_NULL(SCANENV_MEM_NODES(env)[num]))
	    return ONIGERR_INVALID_BACKREF;
	}

	tok->type = TK_BACKREF;
	tok->u.backref.num     = 1;
	tok->u.backref.ref1    = num;
	tok->u.backref.by_name = 0;
#ifdef USE_BACKREF_WITH_LEVEL
	tok->u.backref.exist_level = 0;
#endif
	break;
      }

    skip_backref:
      if (c == '8' || c == '9') {
	/* normal char */
	p = prev; PINC;
	break;
      }

      p = prev;
      /* fall through */
    case '0':
      if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
	prev = p;
	num = scan_unsigned_octal_number(&p, end, (c == '0' ? 2:3), enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type = TK_RAW_BYTE;
	tok->base = 8;
	tok->u.c  = num;
      }
      else if (c != '0') {
	PINC;
      }
      break;

#ifdef USE_NAMED_GROUP
    case 'k':
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_K_NAMED_BACKREF)) {
	PFETCH(c);
	if (c == '<' || c == '\'') {
	  UChar* name_end;
	  int* backs;
	  int back_num;

	  prev = p;

#ifdef USE_BACKREF_WITH_LEVEL
	  name_end = NULL_UCHARP; /* no need. escape gcc warning. */
	  r = fetch_name_with_level((OnigCodePoint )c, &p, end, &name_end,
				    env, &back_num, &tok->u.backref.level);
	  if (r == 1) tok->u.backref.exist_level = 1;
	  else        tok->u.backref.exist_level = 0;
#else
	  r = fetch_name(&p, end, &name_end, env, &back_num, 1);
#endif
	  if (r < 0) return r;

	  if (back_num != 0) {
	    if (back_num < 0) {
	      back_num = BACKREF_REL_TO_ABS(back_num, env);
	      if (back_num <= 0)
		return ONIGERR_INVALID_BACKREF;
	    }

	    if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
	      if (back_num > env->num_mem ||
		  IS_NULL(SCANENV_MEM_NODES(env)[back_num]))
		return ONIGERR_INVALID_BACKREF;
	    }
	    tok->type = TK_BACKREF;
	    tok->u.backref.by_name = 0;
	    tok->u.backref.num  = 1;
	    tok->u.backref.ref1 = back_num;
	  }
	  else {
	    num = onig_name_to_group_numbers(env->reg, prev, name_end, &backs);
	    if (num <= 0) {
	      onig_scan_env_set_error_string(env,
			     ONIGERR_UNDEFINED_NAME_REFERENCE, prev, name_end);
	      return ONIGERR_UNDEFINED_NAME_REFERENCE;
	    }
	    if (IS_SYNTAX_BV(syn, ONIG_SYN_STRICT_CHECK_BACKREF)) {
	      int i;
	      for (i = 0; i < num; i++) {
		if (backs[i] > env->num_mem ||
		    IS_NULL(SCANENV_MEM_NODES(env)[backs[i]]))
		  return ONIGERR_INVALID_BACKREF;
	      }
	    }

	    tok->type = TK_BACKREF;
	    tok->u.backref.by_name = 1;
	    if (num == 1) {
	      tok->u.backref.num  = 1;
	      tok->u.backref.ref1 = backs[0];
	    }
	    else {
	      tok->u.backref.num  = num;
	      tok->u.backref.refs = backs;
	    }
	  }
	}
	else {
	    PUNFETCH;
	    onig_syntax_warn(env, "invalid back reference");
	}
      }
      break;
#endif

#ifdef USE_SUBEXP_CALL
    case 'g':
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_G_SUBEXP_CALL)) {
	PFETCH(c);
	if (c == '<' || c == '\'') {
	  int gnum;
	  UChar* name_end;

	  prev = p;
	  r = fetch_name((OnigCodePoint )c, &p, end, &name_end, env, &gnum, 1);
	  if (r < 0) return r;

	  tok->type = TK_CALL;
	  tok->u.call.name     = prev;
	  tok->u.call.name_end = name_end;
	  tok->u.call.gnum     = gnum;
	}
	else {
	    onig_syntax_warn(env, "invalid subexp call");
	    PUNFETCH;
	}
      }
      break;
#endif

    case 'Q':
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE)) {
	tok->type = TK_QUOTE_OPEN;
      }
      break;

    case 'p':
    case 'P':
      if (PPEEK_IS('{') &&
	  IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
	PINC;
	tok->type = TK_CHAR_PROPERTY;
	tok->u.prop.not = (c == 'P' ? 1 : 0);

	if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
	  PFETCH(c);
	  if (c == '^') {
	    tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
	  }
	  else
	    PUNFETCH;
	}
      }
      else {
	  onig_syntax_warn(env, "invalid Unicode Property \\%c", c);
      }
      break;

    default:
      PUNFETCH;
      num = fetch_escaped_value(&p, end, env);
      if (num < 0) return num;
      /* set_raw: */
      if (tok->u.c != num) {
	tok->type = TK_CODE_POINT;
	tok->u.code = (OnigCodePoint )num;
      }
      else { /* string */
	p = tok->backp + enclen(enc, tok->backp, end);
      }
      break;
    }
  }
  else {
    tok->u.c = c;
    tok->escaped = 0;

#ifdef USE_VARIABLE_META_CHARS
    if ((c != ONIG_INEFFECTIVE_META_CHAR) &&
	IS_SYNTAX_OP(syn, ONIG_SYN_OP_VARIABLE_META_CHARACTERS)) {
      if (c == MC_ANYCHAR(syn))
	goto any_char;
      else if (c == MC_ANYTIME(syn))
	goto anytime;
      else if (c == MC_ZERO_OR_ONE_TIME(syn))
	goto zero_or_one_time;
      else if (c == MC_ONE_OR_MORE_TIME(syn))
	goto one_or_more_time;
      else if (c == MC_ANYCHAR_ANYTIME(syn)) {
	tok->type = TK_ANYCHAR_ANYTIME;
	goto out;
      }
    }
#endif

    switch (c) {
    case '.':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_DOT_ANYCHAR)) break;
#ifdef USE_VARIABLE_META_CHARS
    any_char:
#endif
      tok->type = TK_ANYCHAR;
      break;

    case '*':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ASTERISK_ZERO_INF)) break;
#ifdef USE_VARIABLE_META_CHARS
    anytime:
#endif
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 0;
      tok->u.repeat.upper = REPEAT_INFINITE;
      goto greedy_check;
      break;

    case '+':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_PLUS_ONE_INF)) break;
#ifdef USE_VARIABLE_META_CHARS
    one_or_more_time:
#endif
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 1;
      tok->u.repeat.upper = REPEAT_INFINITE;
      goto greedy_check;
      break;

    case '?':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_QMARK_ZERO_ONE)) break;
#ifdef USE_VARIABLE_META_CHARS
    zero_or_one_time:
#endif
      tok->type = TK_OP_REPEAT;
      tok->u.repeat.lower = 0;
      tok->u.repeat.upper = 1;
      goto greedy_check;
      break;

    case '{':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACE_INTERVAL)) break;
      r = fetch_range_quantifier(&p, end, tok, env);
      if (r < 0) return r;  /* error */
      if (r == 0) goto greedy_check;
      else if (r == 2) { /* {n} */
	if (IS_SYNTAX_BV(syn, ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY))
	  goto possessive_check;

	goto greedy_check;
      }
      /* r == 1 : normal char */
      break;

    case '|':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_VBAR_ALT)) break;
      tok->type = TK_ALT;
      break;

    case '(':
      if (PPEEK_IS('?') &&
          IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_QMARK_GROUP_EFFECT)) {
        PINC;
        if (PPEEK_IS('#')) {
          PFETCH(c);
          while (1) {
            if (PEND) return ONIGERR_END_PATTERN_IN_GROUP;
            PFETCH(c);
            if (c == MC_ESC(syn)) {
              if (!PEND) PFETCH(c);
            }
            else {
              if (c == ')') break;
            }
          }
          goto start;
        }
        PUNFETCH;
      }

      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
      tok->type = TK_SUBEXP_OPEN;
      break;

    case ')':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LPAREN_SUBEXP)) break;
      tok->type = TK_SUBEXP_CLOSE;
      break;

    case '^':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
      tok->type = TK_ANCHOR;
      tok->u.subtype = (IS_SINGLELINE(env->option)
			? ANCHOR_BEGIN_BUF : ANCHOR_BEGIN_LINE);
      break;

    case '$':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break;
      tok->type = TK_ANCHOR;
      tok->u.subtype = (IS_SINGLELINE(env->option)
			? ANCHOR_SEMI_END_BUF : ANCHOR_END_LINE);
      break;

    case '[':
      if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_BRACKET_CC)) break;
      tok->type = TK_CC_OPEN;
      break;

    case ']':
      if (*src > env->pattern)   /* /].../ is allowed. */
	CLOSE_BRACKET_WITHOUT_ESC_WARN(env, (UChar* )"]");
      break;

    case '#':
      if (IS_EXTEND(env->option)) {
	while (!PEND) {
	  PFETCH(c);
	  if (ONIGENC_IS_CODE_NEWLINE(enc, c))
	    break;
	}
	goto start;
	break;
      }
      break;

    case ' ': case '\t': case '\n': case '\r': case '\f':
      if (IS_EXTEND(env->option))
	goto start;
      break;

    default:
      /* string */
      break;
    }
  }

#ifdef USE_VARIABLE_META_CHARS
 out:
#endif
  *src = p;
  return tok->type;
}

Project: Onigmo

onig_print_compiled_byte_code(FILE* f, UChar* bp, UChar* bpend, UChar** nextp,
                              OnigEncoding enc)
{
  int i, n, arg_type;
  RelAddrType addr;
  LengthType len;
  MemNumType mem;
  StateCheckNumType scn;
  OnigCodePoint code;
  UChar *q;

  fprintf(f, "[%s", op2name(*bp));
  arg_type = op2arg_type(*bp);
  if (arg_type != ARG_SPECIAL) {
    bp++;
    switch (arg_type) {
    case ARG_NON:
      break;
    case ARG_RELADDR:
      GET_RELADDR_INC(addr, bp);
      fprintf(f, ":(%d)", addr);
      break;
    case ARG_ABSADDR:
      GET_ABSADDR_INC(addr, bp);
      fprintf(f, ":(%d)", addr);
      break;
    case ARG_LENGTH:
      GET_LENGTH_INC(len, bp);
      fprintf(f, ":%d", len);
      break;
    case ARG_MEMNUM:
      mem = *((MemNumType* )bp);
      bp += SIZE_MEMNUM;
      fprintf(f, ":%d", mem);
      break;
    case ARG_OPTION:
      {
	OnigOptionType option = *((OnigOptionType* )bp);
	bp += SIZE_OPTION;
	fprintf(f, ":%d", option);
      }
      break;

    case ARG_STATE_CHECK:
      scn = *((StateCheckNumType* )bp);
      bp += SIZE_STATE_CHECK_NUM;
      fprintf(f, ":%d", scn);
      break;
    }
  }
  else {
    switch (*bp++) {
    case OP_EXACT1:
    case OP_ANYCHAR_STAR_PEEK_NEXT:
    case OP_ANYCHAR_ML_STAR_PEEK_NEXT:
      p_string(f, 1, bp++); break;
    case OP_EXACT2:
      p_string(f, 2, bp); bp += 2; break;
    case OP_EXACT3:
      p_string(f, 3, bp); bp += 3; break;
    case OP_EXACT4:
      p_string(f, 4, bp); bp += 4; break;
    case OP_EXACT5:
      p_string(f, 5, bp); bp += 5; break;
    case OP_EXACTN:
      GET_LENGTH_INC(len, bp);
      p_len_string(f, len, 1, bp);
      bp += len;
      break;

    case OP_EXACTMB2N1:
      p_string(f, 2, bp); bp += 2; break;
    case OP_EXACTMB2N2:
      p_string(f, 4, bp); bp += 4; break;
    case OP_EXACTMB2N3:
      p_string(f, 6, bp); bp += 6; break;
    case OP_EXACTMB2N:
      GET_LENGTH_INC(len, bp);
      p_len_string(f, len, 2, bp);
      bp += len * 2;
      break;
    case OP_EXACTMB3N:
      GET_LENGTH_INC(len, bp);
      p_len_string(f, len, 3, bp);
      bp += len * 3;
      break;
    case OP_EXACTMBN:
      {
	int mb_len;

	GET_LENGTH_INC(mb_len, bp);
	GET_LENGTH_INC(len, bp);
	fprintf(f, ":%d:%d:", mb_len, len);
	n = len * mb_len;
	while (n-- > 0) { fputc(*bp++, f); }
      }
      break;

    case OP_EXACT1_IC:
      len = enclen(enc, bp, bpend);
      p_string(f, len, bp);
      bp += len;
      break;
    case OP_EXACTN_IC:
      GET_LENGTH_INC(len, bp);
      p_len_string(f, len, 1, bp);
      bp += len;
      break;

    case OP_CCLASS:
      n = bitset_on_num((BitSetRef )bp);
      bp += SIZE_BITSET;
      fprintf(f, ":%d", n);
      break;

    case OP_CCLASS_NOT:
      n = bitset_on_num((BitSetRef )bp);
      bp += SIZE_BITSET;
      fprintf(f, ":%d", n);
      break;

    case OP_CCLASS_MB:
    case OP_CCLASS_MB_NOT:
      GET_LENGTH_INC(len, bp);
      q = bp;
#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
      ALIGNMENT_RIGHT(q);
#endif
      GET_CODE_POINT(code, q);
      bp += len;
      fprintf(f, ":%d:%d", (int )code, len);
      break;

    case OP_CCLASS_MIX:
    case OP_CCLASS_MIX_NOT:
      n = bitset_on_num((BitSetRef )bp);
      bp += SIZE_BITSET;
      GET_LENGTH_INC(len, bp);
      q = bp;
#ifndef PLATFORM_UNALIGNED_WORD_ACCESS
      ALIGNMENT_RIGHT(q);
#endif
      GET_CODE_POINT(code, q);
      bp += len;
      fprintf(f, ":%d:%d:%d", n, (int )code, len);
      break;

    case OP_CCLASS_NODE:
      {
        CClassNode *cc;

        GET_POINTER_INC(cc, bp);
        n = bitset_on_num(cc->bs);
        fprintf(f, ":%"PRIuPTR":%d", (uintptr_t)cc, n);
      }
      break;

    case OP_BACKREFN_IC:
      mem = *((MemNumType* )bp);
      bp += SIZE_MEMNUM;
      fprintf(f, ":%d", mem);
      break;

    case OP_BACKREF_MULTI_IC:
    case OP_BACKREF_MULTI:
      fputs(" ", f);
      GET_LENGTH_INC(len, bp);
      for (i = 0; i < len; i++) {
	GET_MEMNUM_INC(mem, bp);
	if (i > 0) fputs(", ", f);
	fprintf(f, "%d", mem);
      }
      break;

    case OP_BACKREF_WITH_LEVEL:
      {
	OnigOptionType option;
	LengthType level;

	GET_OPTION_INC(option, bp);
	fprintf(f, ":%d", option);
	GET_LENGTH_INC(level, bp);
	fprintf(f, ":%d", level);

	fputs(" ", f);
	GET_LENGTH_INC(len, bp);
	for (i = 0; i < len; i++) {
	  GET_MEMNUM_INC(mem, bp);
	  if (i > 0) fputs(", ", f);
	  fprintf(f, "%d", mem);
	}
      }
      break;

    case OP_REPEAT:
    case OP_REPEAT_NG:
      {
	mem = *((MemNumType* )bp);
	bp += SIZE_MEMNUM;
	addr = *((RelAddrType* )bp);
	bp += SIZE_RELADDR;
	fprintf(f, ":%d:%d", mem, addr);
      }
      break;

    case OP_PUSH_OR_JUMP_EXACT1:
    case OP_PUSH_IF_PEEK_NEXT:
      addr = *((RelAddrType* )bp);
      bp += SIZE_RELADDR;
      fprintf(f, ":(%d)", addr);
      p_string(f, 1, bp);
      bp += 1;
      break;

    case OP_LOOK_BEHIND:
      GET_LENGTH_INC(len, bp);
      fprintf(f, ":%d", len);
      break;

    case OP_PUSH_LOOK_BEHIND_NOT:
      GET_RELADDR_INC(addr, bp);
      GET_LENGTH_INC(len, bp);
      fprintf(f, ":%d:(%d)", len, addr);
      break;

    case OP_STATE_CHECK_PUSH:
    case OP_STATE_CHECK_PUSH_OR_JUMP:
      scn = *((StateCheckNumType* )bp);
      bp += SIZE_STATE_CHECK_NUM;
      addr = *((RelAddrType* )bp);
      bp += SIZE_RELADDR;
      fprintf(f, ":%d:(%d)", scn, addr);
      break;

    default:
      fprintf(stderr, "onig_print_compiled_byte_code: undefined code %d\n",
	      *--bp);
    }
  }
  fputs("]", f);
  if (nextp) *nextp = bp;
}

Project: Onigmo

murmur(st_index_t h, st_index_t k, int r)
{
    const st_index_t m = MurmurMagic;
#if MURMUR == 1
    h += k;
    h *= m;
    h ^= h >> r;
#elif MURMUR == 2
    k *= m;
    k ^= k >> r;
    k *= m;

    h *= m;
    h ^= k;
#endif
    return h;
}

Project: Onigmo

cp949_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  return onigenc_mbn_mbc_to_code(enc, p, end);
}

Project: Onigmo

rehash(register st_table *table)
{
    register st_table_entry *ptr, **new_bins;
    st_index_t i, new_num_bins, hash_val;

    new_num_bins = new_size(table->num_bins+1);
    new_bins = (st_table_entry**)
	xrealloc(table->bins, new_num_bins * sizeof(st_table_entry*));
    for (i = 0; i < new_num_bins; ++i) new_bins[i] = 0;
    table->num_bins = new_num_bins;
    table->bins = new_bins;

    if ((ptr = table->head) != 0) {
	do {
	    hash_val = ptr->hash % new_num_bins;
	    ptr->next = new_bins[hash_val];
	    new_bins[hash_val] = ptr;
	} while ((ptr = ptr->fore) != 0);
    }
}

Project: Onigmo

mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
{
  int firstbyte = *p++;
  state_t s;
  s = trans[0][firstbyte];
  if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
                                  ONIGENC_CONSTRUCT_MBCLEN_INVALID();
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-1);
  s = trans[s][*p++];
  if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
                                  ONIGENC_CONSTRUCT_MBCLEN_INVALID();
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-2);
  s = trans[s][*p++];
  return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
                       ONIGENC_CONSTRUCT_MBCLEN_INVALID();
}

Project: Onigmo

apply_all_case_fold(OnigCaseFoldType flag,
		    OnigApplyAllCaseFoldFunc f, void* arg,
		    OnigEncoding enc ARG_UNUSED)
{
  return onigenc_apply_all_case_fold_with_map(
             sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
             flag, f, arg);
}

Project: Onigmo

fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env)
{
  int num;
  OnigCodePoint c, c2;
  const OnigSyntaxType* syn = env->syntax;
  OnigEncoding enc = env->enc;
  UChar* prev;
  UChar* p = *src;
  PFETCH_READY;

  if (PEND) {
    tok->type = TK_EOT;
    return tok->type;
  }

  PFETCH(c);
  tok->type = TK_CHAR;
  tok->base = 0;
  tok->u.c  = c;
  tok->escaped = 0;

  if (c == ']') {
    tok->type = TK_CC_CLOSE;
  }
  else if (c == '-') {
    tok->type = TK_CC_RANGE;
  }
  else if (c == MC_ESC(syn)) {
    if (! IS_SYNTAX_BV(syn, ONIG_SYN_BACKSLASH_ESCAPE_IN_CC))
      goto end;

    if (PEND) return ONIGERR_END_PATTERN_AT_ESCAPE;

    PFETCH(c);
    tok->escaped = 1;
    tok->u.c = c;
    switch (c) {
    case 'w':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_W;
      tok->u.prop.not   = 0;
      break;
    case 'W':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_W;
      tok->u.prop.not   = 1;
      break;
    case 'd':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_D;
      tok->u.prop.not   = 0;
      break;
    case 'D':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_D;
      tok->u.prop.not   = 1;
      break;
    case 's':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_S;
      tok->u.prop.not   = 0;
      break;
    case 'S':
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_S;
      tok->u.prop.not   = 1;
      break;
    case 'h':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
      tok->u.prop.not   = 0;
      break;
    case 'H':
      if (! IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_H_XDIGIT)) break;
      tok->type = TK_CHAR_TYPE;
      tok->u.prop.ctype = ONIGENC_CTYPE_XDIGIT;
      tok->u.prop.not   = 1;
      break;

    case 'p':
    case 'P':
      c2 = PPEEK;
      if (c2 == '{' &&
	  IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) {
	PINC;
	tok->type = TK_CHAR_PROPERTY;
	tok->u.prop.not = (c == 'P' ? 1 : 0);

	if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) {
	  PFETCH(c2);
	  if (c2 == '^') {
	    tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0);
	  }
	  else
	    PUNFETCH;
	}
      }
      else {
	  onig_syntax_warn(env, "invalid Unicode Property \\%c", c);
      }
      break;

    case 'x':
      if (PEND) break;

      prev = p;
      if (PPEEK_IS('{') && IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_BRACE_HEX8)) {
	PINC;
	num = scan_unsigned_hexadecimal_number(&p, end, 8, enc);
	if (num < 0) return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
	if (!PEND) {
          c2 = PPEEK;
          if (ONIGENC_IS_CODE_XDIGIT(enc, c2))
            return ONIGERR_TOO_LONG_WIDE_CHAR_VALUE;
        }

	if (p > prev + enclen(enc, prev, end) && !PEND && (PPEEK_IS('}'))) {
	  PINC;
	  tok->type   = TK_CODE_POINT;
	  tok->base   = 16;
	  tok->u.code = (OnigCodePoint )num;
	}
	else {
	  /* can't read nothing or invalid format */
	  p = prev;
	}
      }
      else if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_X_HEX2)) {
	num = scan_unsigned_hexadecimal_number(&p, end, 2, enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type = TK_RAW_BYTE;
	tok->base = 16;
	tok->u.c  = num;
      }
      break;

    case 'u':
      if (PEND) break;

      prev = p;
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_U_HEX4)) {
	num = scan_unsigned_hexadecimal_number(&p, end, 4, enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type   = TK_CODE_POINT;
	tok->base   = 16;
	tok->u.code = (OnigCodePoint )num;
      }
      break;

    case '0':
    case '1': case '2': case '3': case '4': case '5': case '6': case '7':
      if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_OCTAL3)) {
	PUNFETCH;
	prev = p;
	num = scan_unsigned_octal_number(&p, end, 3, enc);
	if (num < 0) return ONIGERR_TOO_BIG_NUMBER;
	if (p == prev) {  /* can't read nothing. */
	  num = 0; /* but, it's not error */
	}
	tok->type = TK_RAW_BYTE;
	tok->base = 8;
	tok->u.c  = num;
      }
      break;

    default:
      PUNFETCH;
      num = fetch_escaped_value(&p, end, env);
      if (num < 0) return num;
      if (tok->u.c != num) {
	tok->u.code = (OnigCodePoint )num;
	tok->type   = TK_CODE_POINT;
      }
      break;
    }
  }
  else if (c == '[') {
    if (IS_SYNTAX_OP(syn, ONIG_SYN_OP_POSIX_BRACKET) && (PPEEK_IS(':'))) {
      OnigCodePoint send[] = { (OnigCodePoint )':', (OnigCodePoint )']' };
      tok->backp = p; /* point at '[' is readed */
      PINC;
      if (str_exist_check_with_esc(send, 2, p, end,
                                   (OnigCodePoint )']', enc, syn)) {
	tok->type = TK_POSIX_BRACKET_OPEN;
      }
      else {
	PUNFETCH;
	goto cc_in_cc;
      }
    }
    else {
    cc_in_cc:
      if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP)) {
	tok->type = TK_CC_CC_OPEN;
      }
      else {
	CC_ESC_WARN(env, (UChar* )"[");
      }
    }
  }
  else if (c == '&') {
    if (IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_CCLASS_SET_OP) &&
	!PEND && (PPEEK_IS('&'))) {
      PINC;
      tok->type = TK_CC_AND;
    }
  }

 end:
  *src = p;
  return tok->type;
}

Project: Onigmo

code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  UChar *p = buf;

  if ((code & 0xff000000) != 0) *p++ = (UChar )(((code >> 24) & 0xff));
  if ((code &   0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
  if ((code &     0xff00) != 0) *p++ = (UChar )(((code >>  8) & 0xff));
  *p++ = (UChar )(code & 0xff);

  if (enclen(enc, buf, p) != (p - buf))
    return ONIGERR_INVALID_CODE_POINT_VALUE;
  return (int)(p - buf);
}

Project: Onigmo

uniname2ctype_p (str, len)
     register const char *str;
     register unsigned int len;
{
  static const struct uniname2ctype_struct wordlist[] =
    {
#ifdef USE_UNICODE_PROPERTIES
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str3,                                        33},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str5,                                        23},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str7,                                       35},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str8,                                       24},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str10,                                       20},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str11,                                       36},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str12,                                       26},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str13,                                        17},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str16,                                       21},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str20,                                       18},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str21,                                      93},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str22,                                     93},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str23,                                    150},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str26,                                       59},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str29,                                    127},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str30,                                     142},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str31,                                    142},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str32,                                    113},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str34,                                  18},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str37,                                    147},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str40,                                  147},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str42,                                       51},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str44,                                    86},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str46,                                     74},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str47,                                     3},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str48,                                    74},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str51,                                     108},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str53,                                   79},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str54,                                    110},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str55,                                    115},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str60,                                    108},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str63,                                 115},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str66,                                       27},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str67,                                       49},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str69,                                    105},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str70,                                   184},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str71,                                       46},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str73,                                        50},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str74,                                  178},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str75,                                    151},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str76,                                    100},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str84,                                    157},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str88,                                    113},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str89,                                     81},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str90,                                     92},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str91,                       197},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str92,                                  91},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str93,                                   170},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str94,                                    14},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str95,                       42},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str98,                                    17},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str99,                             170},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str100,                                   81},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str101,                                    152},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str103,                                  182},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str105,                              36},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str106,                              26},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str109,                                     91},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str112,                                    119},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str114,                     38},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str115,                                        45},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str116,                                       69},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str117,                                      197},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str119,                                    195},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str120,                                      66},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str121,                                     190},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str122,                                       22},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str123,                                 152},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str124,                                     180},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str125,                                     99},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str126,                   161},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str128,                                 122},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str137,                                 188},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str143,                                     193},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str147,                               180},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str148,                                    200},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str149,                                     98},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str151,                      100},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str152,                                       53},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str153,                              49},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str156,                               110},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str161,                    162},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str162,                                 151},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str163,                            51},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str166,                            194},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str170,                                    194},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str171,                           177},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str172,                               113},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str174,                          182},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str175,                     174},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str176,                                     82},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str179,                         178},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str180,                                    179},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str181,                   184},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str183,                         195},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str187,                                   119},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str190,                              132},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str192,                               82},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str193,                                   23},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str195,                                       34},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str197,                                    187},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str198,                                    112},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str200,                          27},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str202,                                       43},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str203,                                    171},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str206,                                       38},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str209,                             35},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str212,                                       42},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str215,                                157},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str217,                                       32},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str218,                                  65},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str220,                               66},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str222,                                      65},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str223,                                     1},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str227,                                       30},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str229,                                  127},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str234,                               104},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str235,                                   73},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str236,                                     77},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str237,                                    127},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str243,                                    124},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str244,                                    159},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str245,                                    162},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str246,                                    161},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str250,                                 77},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str251,                                      192},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str252,                                 167},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str255,                              136},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str258,                                     87},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str261,                                    87},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str268,                                    58},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str269,                                    149},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str270,                       186},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str271,                                    140},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str275,          190},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str278,                                     7},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str286,                                    123},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str292,                                    154},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str294,                                     54},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str296,                                    120},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str297,                         40},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str301,                         43},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str303,                                    134},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str306,                                   175},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str307,                               154},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str308,                                       44},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str310,                                     79},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str311,                                    125},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str314,                                 150},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str317,                                 120},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str321,                                  140},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str322,                                    167},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str324,                                    158},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str325,                                    174},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str326,                              129},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str327,                               21},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str328,                                       40},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str335,                                 112},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str340,                                    166},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str341,                                    102},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str343,                               175},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str344,                                   102},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str345,                                     97},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str346,                                 98},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str349,                                       31},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str350,                                   198},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str353,                                50},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str355,                                     94},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str356,                                  111},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str358,                                117},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str359,                                    160},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str361,                                    128},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str367,                                  94},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str371,                                    111},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str372,                                    145},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str373,                                   97},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str374,                                  83},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str375,                                105},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str376,                                 125},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str379,                                     96},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str380,                                 201},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str381,                                 203},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str382,                                 210},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str383,                                 211},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str384,                                 208},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str385,                                        37},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str386,                                       39},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str388,                                    155},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str389,                                 202},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str390,                                 209},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str391,                                 212},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str392,                                 207},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str393,                                     5},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str395,                                    143},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str396,                                     9},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str397,                                 205},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str398,                                 206},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str399,                                     78},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str402,                                   169},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str405,                                 204},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str408,                             169},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str413,                   193},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str420,                                     88},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str422,                                       52},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str427,                                        29},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str430,                                       25},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str432,                      187},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str433,                                134},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str434,                                   189},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str436,                           53},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str438,                                    70},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str442,                                    13},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str443,                               163},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str445,                                     68},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str446,                                    186},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str447,                                    177},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str452,                                   19},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str456,                            59},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str457,                                130},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str459,                               139},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str462,                                     181},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str464,                              143},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str465,                       198},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str466,                                     4},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str474,                                    139},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str480,                            34},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str484,                                    107},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str485,                                       48},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str488,                          183},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str493,                             179},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str496,                                     67},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str497,                               20},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str502,                                 137},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str506,                               55},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str508,                                    118},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str512,                                   11},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str513,                                 67},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str516,                                    104},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str518,                              68},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str521,                                 16},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str523,                                    101},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str529,                                     138},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str530,                                    138},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str533,                                    141},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str534,                              191},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str535,                                  166},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str536,                                    137},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str538,                                    106},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str540,                                    144},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str542,                    60},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str543,                                181},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str550,                                     191},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str554,                                 141},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str562,                                      60},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str563,                             71},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str565,                                    136},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str573,                                    163},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str576,                                     8},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str577,                                    133},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str580,                                     6},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str586,                                   196},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str587,                                      109},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str588,                                    146},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str589,                                     76},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str591,                                  146},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str592,                         41},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str593,                                     86},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str594,                           70},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str596,                                  164},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str597,                                    132},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str598,                                    109},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str599,                                    164},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str601,                                 76},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str602,                                    129},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str605,                                  183},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str617,                                    117},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str620,                                      62},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str623,                                   33},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str625,                                    114},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str626,                                     89},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str627,                          24},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str628,                    62},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str629,                              192},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str632,                                    121},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str634,                                    131},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str636,                                       28},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str640,                                 114},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str643,                              133},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str644,                                     80},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str645,                                  89},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str646,                                     83},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str647,                                56},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str656,                                    122},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str659,                           199},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str660,                                   80},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str663,                                     12},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str667,                         159},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str672,                                121},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str675,                            31},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str677,                                 96},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str678,                                    148},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str681,                                  148},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str686,                             131},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str687,                                     85},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str692,                                    130},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str696,                           46},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str701,                                   0},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str705,                                107},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str706,                                  185},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str707,                                 99},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str708,                                 85},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str710,                               128},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str716,                          39},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str718,                         160},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str725,                                    10},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str732,                                       19},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str734,                                    116},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str735,                                  145},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str736,                     185},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str739,                           25},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str745,                           32},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str749,                    64},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str752,                                     29},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str757,                                22},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str765,                       52},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str767,                                   101},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str768,                                     176},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str772,                          28},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str777,                                176},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str778,                                     64},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str781,                                   71},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str782,                                    103},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str788,                        189},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str792,                                57},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str793,                                   103},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str795,                              30},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str797,                              168},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str806,                                  199},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str816,                                 124},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str818,                          44},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str821,                                    156},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str831,                                   116},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str840,                                    165},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str851,                                   45},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str856,                    61},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str857,                                 123},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str861,                                   118},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str868,                              37},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str872,                                  172},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str888,                               48},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str892,                                     75},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str898,                    63},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str902,                           173},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str903,                                    126},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str916,                               135},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str918,                                       41},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str927,                                     63},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str932,                                   156},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str940,                                     84},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str944,                                  168},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str951,                             158},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str976,                69},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str980,                           47},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str999,                                     90},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1007,                                     95},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1020,                                90},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1026,                                  95},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1032,                                   88},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1033,                                126},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1037,                                    135},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1093,                                       47},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1097,                                106},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1124,                                    153},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1146,                                      15},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1148,                                 144},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1190,                                      61},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1263,                                   173},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1329,                                     2},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1347,                                   72},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1358,                                   165},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1395,                                 200},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1410,                                    75},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
#endif /* USE_UNICODE_PROPERTIES */
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
#ifndef USE_UNICODE_PROPERTIES
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str7,                                     7},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str8,                                     8},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str9,                                     1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str10,                                    13},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str11,                                   11},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str12,                                   0},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str13,                                    10},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str14,                                    14},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str15,                                     3},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str16,                                     9},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str17,                                     12},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str18,                                     6},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str19,                                     5},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str20,                                     4},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str21,                                     2}
#else /* USE_UNICODE_PROPERTIES */
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1463,                             72},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1470,                                 84},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1556,                                   78},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1621,                     153},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
      {-1}, {-1},
      {(int)(long)&((struct uniname2ctype_pool_t *)0)->uniname2ctype_pool_str1741,                                     73}
#endif /* USE_UNICODE_PROPERTIES */
    };

  if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
    {
      register int key = uniname2ctype_hash (str, len);

      if (key <= MAX_HASH_VALUE && key >= 0)
        {
          register int o = wordlist[key].name;
          if (o >= 0)
            {
              register const char *s = o + uniname2ctype_pool;

              if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
                return &wordlist[key];
            }
        }
    }
  return 0;
}

Project: Onigmo

onig_memsize(const regex_t *reg)
{
    size_t size = sizeof(regex_t);
    if (IS_NOT_NULL(reg->p))                size += reg->alloc;
    if (IS_NOT_NULL(reg->exact))            size += reg->exact_end - reg->exact;
    if (IS_NOT_NULL(reg->int_map))          size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
    if (IS_NOT_NULL(reg->int_map_backward)) size += sizeof(int) * ONIG_CHAR_TABLE_SIZE;
    if (IS_NOT_NULL(reg->repeat_range))     size += reg->repeat_range_alloc * sizeof(OnigRepeatRange);
    if (IS_NOT_NULL(reg->chain))            size += onig_memsize(reg->chain);

    return size;
}

Project: Onigmo

uniname2ctype(const UChar *name, unsigned int len)
{
  const struct uniname2ctype_struct *p = uniname2ctype_p((const char *)name, len);
  if (p) return p->ctype;
  return -1;
}

Project: Onigmo

big5_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
{
  const UChar c = *s;

  return (BIG5_ISMB_TRAIL(c) ? FALSE : TRUE);
}

Project: Onigmo

gb18030_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
  return onigenc_mb4_is_code_ctype(enc, code, ctype);
}

Project: Onigmo

onig_error_code_to_str(s, code, va_alist)
  UChar* s;
  int code;
  va_dcl
#endif
{
  UChar *p, *q;
  OnigErrorInfo* einfo;
  size_t len;
  int is_over;
  UChar parbuf[MAX_ERROR_PAR_LEN];
  va_list vargs;

  va_init_list(vargs, code);

  switch (code) {
  case ONIGERR_UNDEFINED_NAME_REFERENCE:
  case ONIGERR_UNDEFINED_GROUP_REFERENCE:
  case ONIGERR_MULTIPLEX_DEFINED_NAME:
  case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
  case ONIGERR_INVALID_GROUP_NAME:
  case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
  case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
    einfo = va_arg(vargs, OnigErrorInfo*);
    len = to_ascii(einfo->enc, einfo->par, einfo->par_end,
		   parbuf, MAX_ERROR_PAR_LEN - 3, &is_over);
    q = onig_error_code_to_format(code);
    p = s;
    while (*q != '\0') {
      if (*q == '%') {
	q++;
	if (*q == 'n') { /* '%n': name */
	  xmemcpy(p, parbuf, len);
	  p += len;
	  if (is_over != 0) {
	    xmemcpy(p, "...", 3);
	    p += 3;
	  }
	  q++;
	}
	else
	  goto normal_char;
      }
      else {
      normal_char:
	*p++ = *q++;
      }
    }
    *p = '\0';
    len = p - s;
    break;

  default:
    q = onig_error_code_to_format(code);
    len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, q);
    xmemcpy(s, q, len);
    s[len] = '\0';
    break;
  }

  va_end(vargs);
  return (int)len;
}

Project: Onigmo

update_string_node_case_fold(regex_t* reg, Node *node)
{
  UChar *p, *q, *end, buf[ONIGENC_MBC_CASE_FOLD_MAXLEN];
  UChar *sbuf, *ebuf, *sp;
  int r, i, len;
  OnigDistance sbuf_size;
  StrNode* sn = NSTR(node);

  end = sn->end;
  sbuf_size = (end - sn->s) * 2;
  sbuf = (UChar* )xmalloc(sbuf_size);
  CHECK_NULL_RETURN_MEMERR(sbuf);
  ebuf = sbuf + sbuf_size;

  sp = sbuf;
  p = sn->s;
  while (p < end) {
    len = ONIGENC_MBC_CASE_FOLD(reg->enc, reg->case_fold_flag, &p, end, buf);
    q = buf;
    for (i = 0; i < len; i++) {
      if (sp >= ebuf) {
	sbuf = (UChar* )xrealloc(sbuf, sbuf_size * 2);
	CHECK_NULL_RETURN_MEMERR(sbuf);
	sp = sbuf + sbuf_size;
	sbuf_size *= 2;
	ebuf = sbuf + sbuf_size;
      }

      *sp++ = buf[i];
    }
  }

  r = onig_node_str_set(node, sbuf, sp);
  if (r != 0) {
    xfree(sbuf);
    return r;
  }

  xfree(sbuf);
  return 0;
}

Project: Onigmo

st_insert(register st_table *table, register st_data_t key, st_data_t value)
{
    st_index_t hash_val, bin_pos;
    register st_table_entry *ptr;

    if (table->entries_packed) {
        st_index_t i;
        for (i = 0; i < table->num_entries; i++) {
            if ((st_data_t)table->bins[i*2] == key) {
                table->bins[i*2+1] = (struct st_table_entry*)value;
                return 1;
            }
        }
        if (MORE_PACKABLE_P(table)) {
            i = table->num_entries++;
            table->bins[i*2] = (struct st_table_entry*)key;
            table->bins[i*2+1] = (struct st_table_entry*)value;
            return 0;
        }
        else {
            unpack_entries(table);
        }
    }

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	ADD_DIRECT(table, key, value, hash_val, bin_pos);
	return 0;
    }
    else {
	ptr->record = value;
	return 1;
    }
}

Project: Onigmo

euckr_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  return onigenc_mbn_mbc_to_code(enc, p, end);
}

Project: Onigmo

mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  int c, i, len;
  OnigCodePoint n;

  len = enclen(enc, p, end);
  c = *p++;
  n = c;
  if (len == 1) return n;

  for (i = 1; i < len; i++) {
    if (p >= end) break;
    c = *p++;
    n <<= 8;  n += c;
  }
  return n;
}

Project: Onigmo

property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
{
  hash_data_type ctype;
  UChar *s, *e;

  PROPERTY_LIST_INIT_CHECK;

  s = e = ALLOCA_N(UChar, end-p+1);
  for (; p < end; p++) {
    *e++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
  }

  if (onig_st_lookup_strend(PropertyNameTable, s, e, &ctype) == 0) {
    return onigenc_minimum_property_name_to_ctype(enc, s, e);
  }

  return (int)ctype;
}

Project: Onigmo

set_bm_skip(UChar* s, UChar* end, OnigEncoding enc ARG_UNUSED,
	    UChar skip[], int** int_skip)
{
  OnigDistance i, len;

  len = end - s;
  if (len < ONIG_CHAR_TABLE_SIZE) {
    for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = len;

    for (i = 0; i < len - 1; i++)
      skip[s[i]] = len - 1 - i;
  }
  else {
    if (IS_NULL(*int_skip)) {
      *int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
      if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
    }
    for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = (int)len;

    for (i = 0; i < len - 1; i++)
      (*int_skip)[s[i]] = (int)(len - 1 - i);
  }
  return 0;
}

Project: Onigmo

koi8_u_is_code_ctype(OnigCodePoint code, unsigned int ctype,
		     OnigEncoding enc ARG_UNUSED)
{
  if (code < 256)
    return ENC_IS_KOI8_U_CTYPE(code, ctype);
  else
    return FALSE;
}

Project: Onigmo

is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
{
  if (code < 256)
    return ENC_IS_ISO_8859_11_CTYPE(code, ctype);
  else
    return FALSE;
}

Project: Onigmo

st_numcmp(st_data_t x, st_data_t y)
{
    return x != y;
}

Project: Onigmo

cp949_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
                    UChar* lower, OnigEncoding enc)
{
  return onigenc_mbn_mbc_case_fold(enc, flag,
                                   pp, end, lower);
}

Project: Onigmo

onig_error_code_to_format(int code)
{
  const char *p;

  if (code >= 0) return (UChar* )0;

  switch (code) {
  case ONIG_MISMATCH:
    p = "mismatch"; break;
  case ONIG_NO_SUPPORT_CONFIG:
    p = "no support in this configuration"; break;
  case ONIGERR_MEMORY:
    p = "failed to allocate memory"; break;
  case ONIGERR_MATCH_STACK_LIMIT_OVER:
    p = "match-stack limit over"; break;
  case ONIGERR_TYPE_BUG:
    p = "undefined type (bug)"; break;
  case ONIGERR_PARSER_BUG:
    p = "internal parser error (bug)"; break;
  case ONIGERR_STACK_BUG:
    p = "stack error (bug)"; break;
  case ONIGERR_UNDEFINED_BYTECODE:
    p = "undefined bytecode (bug)"; break;
  case ONIGERR_UNEXPECTED_BYTECODE:
    p = "unexpected bytecode (bug)"; break;
  case ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED:
    p = "default multibyte-encoding is not setted"; break;
  case ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR:
    p = "can't convert to wide-char on specified multibyte-encoding"; break;
  case ONIGERR_INVALID_ARGUMENT:
    p = "invalid argument"; break;
  case ONIGERR_END_PATTERN_AT_LEFT_BRACE:
    p = "end pattern at left brace"; break;
  case ONIGERR_END_PATTERN_AT_LEFT_BRACKET:
    p = "end pattern at left bracket"; break;
  case ONIGERR_EMPTY_CHAR_CLASS:
    p = "empty char-class"; break;
  case ONIGERR_PREMATURE_END_OF_CHAR_CLASS:
    p = "premature end of char-class"; break;
  case ONIGERR_END_PATTERN_AT_ESCAPE:
    p = "end pattern at escape"; break;
  case ONIGERR_END_PATTERN_AT_META:
    p = "end pattern at meta"; break;
  case ONIGERR_END_PATTERN_AT_CONTROL:
    p = "end pattern at control"; break;
  case ONIGERR_META_CODE_SYNTAX:
    p = "invalid meta-code syntax"; break;
  case ONIGERR_CONTROL_CODE_SYNTAX:
    p = "invalid control-code syntax"; break;
  case ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE:
    p = "char-class value at end of range"; break;
  case ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE:
    p = "char-class value at start of range"; break;
  case ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS:
    p = "unmatched range specifier in char-class"; break;
  case ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED:
    p = "target of repeat operator is not specified"; break;
  case ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID:
    p = "target of repeat operator is invalid"; break;
  case ONIGERR_NESTED_REPEAT_OPERATOR:
    p = "nested repeat operator"; break;
  case ONIGERR_UNMATCHED_CLOSE_PARENTHESIS:
    p = "unmatched close parenthesis"; break;
  case ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS:
    p = "end pattern with unmatched parenthesis"; break;
  case ONIGERR_END_PATTERN_IN_GROUP:
    p = "end pattern in group"; break;
  case ONIGERR_UNDEFINED_GROUP_OPTION:
    p = "undefined group option"; break;
  case ONIGERR_INVALID_POSIX_BRACKET_TYPE:
    p = "invalid POSIX bracket type"; break;
  case ONIGERR_INVALID_LOOK_BEHIND_PATTERN:
    p = "invalid pattern in look-behind"; break;
  case ONIGERR_INVALID_REPEAT_RANGE_PATTERN:
    p = "invalid repeat range {lower,upper}"; break;
  case ONIGERR_TOO_BIG_NUMBER:
    p = "too big number"; break;
  case ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE:
    p = "too big number for repeat range"; break;
  case ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE:
    p = "upper is smaller than lower in repeat range"; break;
  case ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS:
    p = "empty range in char class"; break;
  case ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE:
    p = "mismatch multibyte code length in char-class range"; break;
  case ONIGERR_TOO_MANY_MULTI_BYTE_RANGES:
    p = "too many multibyte code ranges are specified"; break;
  case ONIGERR_TOO_SHORT_MULTI_BYTE_STRING:
    p = "too short multibyte code string"; break;
  case ONIGERR_TOO_BIG_BACKREF_NUMBER:
    p = "too big backref number"; break;
  case ONIGERR_INVALID_BACKREF:
#ifdef USE_NAMED_GROUP
    p = "invalid backref number/name"; break;
#else
    p = "invalid backref number"; break;
#endif
  case ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED:
    p = "numbered backref/call is not allowed. (use name)"; break;
  case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
    p = "too big wide-char value"; break;
  case ONIGERR_TOO_LONG_WIDE_CHAR_VALUE:
    p = "too long wide-char value"; break;
  case ONIGERR_INVALID_CODE_POINT_VALUE:
    p = "invalid code point value"; break;
  case ONIGERR_EMPTY_GROUP_NAME:
    p = "group name is empty"; break;
  case ONIGERR_INVALID_GROUP_NAME:
    p = "invalid group name <%n>"; break;
  case ONIGERR_INVALID_CHAR_IN_GROUP_NAME:
#ifdef USE_NAMED_GROUP
    p = "invalid char in group name <%n>"; break;
#else
    p = "invalid char in group number <%n>"; break;
#endif
  case ONIGERR_UNDEFINED_NAME_REFERENCE:
    p = "undefined name <%n> reference"; break;
  case ONIGERR_UNDEFINED_GROUP_REFERENCE:
    p = "undefined group <%n> reference"; break;
  case ONIGERR_MULTIPLEX_DEFINED_NAME:
    p = "multiplex defined name <%n>"; break;
  case ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL:
    p = "multiplex definition name <%n> call"; break;
  case ONIGERR_NEVER_ENDING_RECURSION:
    p = "never ending recursion"; break;
  case ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY:
    p = "group number is too big for capture history"; break;
  case ONIGERR_INVALID_CHAR_PROPERTY_NAME:
    p = "invalid character property name {%n}"; break;
  case ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION:
    p = "not supported encoding combination"; break;
  case ONIGERR_INVALID_COMBINATION_OF_OPTIONS:
    p = "invalid combination of options"; break;
  case ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT:
    p = "over thread pass limit count"; break;

  default:
    p = "undefined error code"; break;
  }

  return (UChar* )p;
}

Project: Onigmo

euckr_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
{
  const UChar c = *s;
  if (c <= 0x7e) return TRUE;
  else           return FALSE;
}

Project: Onigmo

mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
{
  int c, len;
  OnigCodePoint n;

  len = enclen(enc, p, end);
  c = *p++;
  if (len > 1) {
    len--;
    n = c & ((1 << (6 - len)) - 1);
    while (len--) {
      c = *p++;
      n = (n << 6) | (c & ((1 << 6) - 1));
    }
    return n;
  }
  else {
#ifdef USE_INVALID_CODE_SCHEME
    if (c > 0xfd) {
      return ((c == 0xfe) ? INVALID_CODE_FE : INVALID_CODE_FF);
    }
#endif
    return (OnigCodePoint )c;
  }
}

Project: Onigmo

strhash(st_data_t arg)
{
    register const char *string = (const char *)arg;
    register st_index_t hval = FNV1_32A_INIT;

    /*
     * FNV-1a hash each octet in the buffer
     */
    while (*string) {
	/* xor the bottom with the current octet */
	hval ^= (unsigned int)*string++;

	/* multiply by the 32 bit FNV magic prime mod 2^32 */
	hval *= FNV_32_PRIME;
    }
    return hval;
}

Project: Onigmo

gbk_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
{
  const UChar c = *s;
  return (GBK_ISMB_TRAIL(c) ? FALSE : TRUE);
}

Project: Onigmo

print_optimize_info(FILE* f, regex_t* reg)
{
  static const char* on[] = { "NONE", "EXACT", "EXACT_BM", "EXACT_BM_NOT_REV",
                              "EXACT_IC", "MAP" };

  fprintf(f, "optimize: %s\n", on[reg->optimize]);
  fprintf(f, "  anchor: "); print_anchor(f, reg->anchor);
  if ((reg->anchor & ANCHOR_END_BUF_MASK) != 0)
    print_distance_range(f, reg->anchor_dmin, reg->anchor_dmax);
  fprintf(f, "\n");

  if (reg->optimize) {
    fprintf(f, "  sub anchor: "); print_anchor(f, reg->sub_anchor);
    fprintf(f, "\n");
  }
  fprintf(f, "\n");

  if (reg->exact) {
    UChar *p;
    fprintf(f, "exact: [");
    for (p = reg->exact; p < reg->exact_end; p++) {
      fputc(*p, f);
    }
    fprintf(f, "]: length: %ld\n", (reg->exact_end - reg->exact));
  }
  else if (reg->optimize & ONIG_OPTIMIZE_MAP) {
    int c, i, n = 0;

    for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++)
      if (reg->map[i]) n++;

    fprintf(f, "map: n=%d\n", n);
    if (n > 0) {
      c = 0;
      fputc('[', f);
      for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) {
	if (reg->map[i] != 0) {
          if (c > 0)  fputs(", ", f);
          c++;
          if (ONIGENC_MBC_MAXLEN(reg->enc) == 1 &&
              ONIGENC_IS_CODE_PRINT(reg->enc, (OnigCodePoint )i))
            fputc(i, f);
          else
            fprintf(f, "%d", i);
        }
      }
      fprintf(f, "]\n");
    }
  }
}

Project: Onigmo

st_strncasecmp(const char *s1, const char *s2, size_t n)
{
    unsigned int c1, c2;

    while (n--) {
        c1 = (unsigned char)*s1++;
        c2 = (unsigned char)*s2++;
        if (c1 == '\0' || c2 == '\0') {
            if (c1 != '\0') return 1;
            if (c2 != '\0') return -1;
            return 0;
        }
        if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
        if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
        if (c1 != c2) {
            if (c1 > c2)
                return 1;
            else
                return -1;
        }
    }
    return 0;
}

Project: Onigmo

gbk_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  return onigenc_mb2_code_to_mbc(enc, code, buf);
}

Project: Onigmo

cp949_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
{
  return onigenc_mb2_is_code_ctype(enc, code, ctype);
}

Project: Onigmo

is_mbc_newline(const UChar* p, const UChar* end, OnigEncoding enc)
{
  if (p < end) {
    if (*p == 0x0a) return 1;

#ifdef USE_UNICODE_ALL_LINE_TERMINATORS
#ifndef USE_CRNL_AS_LINE_TERMINATOR
    if (*p == 0x0d) return 1;
#endif
    if (p + 1 < end) {
      if (*(p+1) == 0x85 && *p == 0xc2) /* U+0085 */
	return 1;
      if (p + 2 < end) {
	if ((*(p+2) == 0xa8 || *(p+2) == 0xa9)
	    && *(p+1) == 0x80 && *p == 0xe2)  /* U+2028, U+2029 */
	  return 1;
      }
    }
#endif
  }

  return 0;
}

Project: Onigmo

utf32be_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
		    OnigEncoding enc ARG_UNUSED)
{
  return 4;
}

Project: Onigmo

cp949_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  return onigenc_mb2_code_to_mbc(enc, code, buf);
}

Project: Onigmo

st_cleanup_safe(st_table *table, st_data_t never)
{
    st_table_entry *ptr, **last, *tmp;
    st_index_t i;

    if (table->entries_packed) {
	st_index_t i = 0, j = 0;
	while ((st_data_t)table->bins[i*2] != never) {
	    if (i++ == table->num_entries) return;
	}
	for (j = i; ++i < table->num_entries;) {
	    if ((st_data_t)table->bins[i*2] == never) continue;
	    table->bins[j*2] = table->bins[i*2];
	    table->bins[j*2+1] = table->bins[i*2+1];
	    j++;
	}
	table->num_entries = j;
	return;
    }

    for (i = 0; i < table->num_bins; i++) {
	ptr = *(last = &table->bins[i]);
	while (ptr != 0) {
	    if (ptr->key == never) {
		tmp = ptr;
		*last = ptr = ptr->next;
		free(tmp);
	    }
	    else {
		ptr = *(last = &ptr->next);
	    }
	}
    }
}

Project: Onigmo

utf32le_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
			      OnigEncoding enc ARG_UNUSED)
{
  ptrdiff_t rem;

  if (s <= start) return (UChar* )s;

  rem = (s - start) % 4;
  return (UChar* )(s - rem);
}

Project: Onigmo

euctw_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  return onigenc_mb4_code_to_mbc(enc, code, buf);
}

Project: Onigmo

gbk_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
{
  int firstbyte = *p++;
  state_t s = trans[0][firstbyte];
#define RETURN(n) \
    return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) : \
                         ONIGENC_CONSTRUCT_MBCLEN_INVALID()
  if (s < 0) RETURN(1);
  if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_GBK[firstbyte]-1);
  s = trans[s][*p++];
  RETURN(2);
#undef RETURN
}

Project: Onigmo

koi8_r_is_code_ctype(OnigCodePoint code, unsigned int ctype,
		     OnigEncoding enc ARG_UNUSED)
{
  if (code < 256)
    return ENC_IS_KOI8_R_CTYPE(code, ctype);
  else
    return FALSE;
}

Project: Onigmo

utf16le_mbc_enc_len(const UChar* p, const OnigUChar* e,
		    OnigEncoding enc ARG_UNUSED)
{
  int len = (int)(e - p);
  UChar byte;
  if (len < 2)
    return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(1);
  byte = p[1];
  if (!UTF16_IS_SURROGATE(byte)) {
    return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2);
  }
  if (UTF16_IS_SURROGATE_FIRST(byte)) {
    if (len < 4)
      return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(4-len);
    if (UTF16_IS_SURROGATE_SECOND(p[3]))
      return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(4);
  }
  return ONIGENC_CONSTRUCT_MBCLEN_INVALID();
}

Project: Onigmo

setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
{
  int type;
  int r = 0;

restart:
  type = NTYPE(node);
  switch (type) {
  case NT_LIST:
    {
      Node* prev = NULL_NODE;
      do {
	r = setup_tree(NCAR(node), reg, state, env);
	if (IS_NOT_NULL(prev) && r == 0) {
	  r = next_setup(prev, NCAR(node), reg);
	}
	prev = NCAR(node);
      } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
    }
    break;

  case NT_ALT:
    do {
      r = setup_tree(NCAR(node), reg, (state | IN_ALT), env);
    } while (r == 0 && IS_NOT_NULL(node = NCDR(node)));
    break;

  case NT_CCLASS:
    break;

  case NT_STR:
    if (IS_IGNORECASE(reg->options) && !NSTRING_IS_RAW(node)) {
      r = expand_case_fold_string(node, reg);
    }
    break;

  case NT_CTYPE:
  case NT_CANY:
    break;

#ifdef USE_SUBEXP_CALL
  case NT_CALL:
    break;
#endif

  case NT_BREF:
    {
      int i;
      int* p;
      Node** nodes = SCANENV_MEM_NODES(env);
      BRefNode* br = NBREF(node);
      p = BACKREFS_P(br);
      for (i = 0; i < br->back_num; i++) {
	if (p[i] > env->num_mem)  return ONIGERR_INVALID_BACKREF;
	BIT_STATUS_ON_AT(env->backrefed_mem, p[i]);
	BIT_STATUS_ON_AT(env->bt_mem_start, p[i]);
#ifdef USE_BACKREF_WITH_LEVEL
	if (IS_BACKREF_NEST_LEVEL(br)) {
	  BIT_STATUS_ON_AT(env->bt_mem_end, p[i]);
	}
#endif
	SET_ENCLOSE_STATUS(nodes[p[i]], NST_MEM_BACKREFED);
      }
    }
    break;

  case NT_QTFR:
    {
      OnigDistance d;
      QtfrNode* qn = NQTFR(node);
      Node* target = qn->target;

      if ((state & IN_REPEAT) != 0) {
        qn->state |= NST_IN_REPEAT;
      }

      if (IS_REPEAT_INFINITE(qn->upper) || qn->upper >= 1) {
	r = get_min_match_length(target, &d, env);
	if (r) break;
	if (d == 0) {
	  qn->target_empty_info = NQ_TARGET_IS_EMPTY;
#ifdef USE_MONOMANIAC_CHECK_CAPTURES_IN_ENDLESS_REPEAT
	  r = quantifiers_memory_node_info(target);
	  if (r < 0) break;
	  if (r > 0) {
	    qn->target_empty_info = r;
	  }
#endif
#if 0
	  r = get_max_match_length(target, &d, env);
	  if (r == 0 && d == 0) {
	    /*  ()* ==> ()?, ()+ ==> ()  */
	    qn->upper = 1;
	    if (qn->lower > 1) qn->lower = 1;
	    if (NTYPE(target) == NT_STR) {
	      qn->upper = qn->lower = 0;  /* /(?:)+/ ==> // */
	    }
	  }
#endif
	}
      }

      state |= IN_REPEAT;
      if (qn->lower != qn->upper)
	state |= IN_VAR_REPEAT;
      r = setup_tree(target, reg, state, env);
      if (r) break;

      /* expand string */
#define EXPAND_STRING_MAX_LENGTH  100
      if (NTYPE(target) == NT_STR) {
	if (!IS_REPEAT_INFINITE(qn->lower) && qn->lower == qn->upper &&
	    qn->lower > 1 && qn->lower <= EXPAND_STRING_MAX_LENGTH) {
	  OnigDistance len = NSTRING_LEN(target);
	  StrNode* sn = NSTR(target);

	  if (len * qn->lower <= EXPAND_STRING_MAX_LENGTH) {
	    int i, n = qn->lower;
	    onig_node_conv_to_str_node(node, NSTR(target)->flag);
	    for (i = 0; i < n; i++) {
	      r = onig_node_str_cat(node, sn->s, sn->end);
	      if (r) break;
	    }
	    onig_node_free(target);
	    break; /* break case NT_QTFR: */
	  }
	}
      }

#ifdef USE_OP_PUSH_OR_JUMP_EXACT
      if (qn->greedy && (qn->target_empty_info != 0)) {
	if (NTYPE(target) == NT_QTFR) {
	  QtfrNode* tqn = NQTFR(target);
	  if (IS_NOT_NULL(tqn->head_exact)) {
	    qn->head_exact  = tqn->head_exact;
	    tqn->head_exact = NULL;
	  }
	}
	else {
	  qn->head_exact = get_head_value_node(qn->target, 1, reg);
	}
      }
#endif
    }
    break;

  case NT_ENCLOSE:
    {
      EncloseNode* en = NENCLOSE(node);

      switch (en->type) {
      case ENCLOSE_OPTION:
	{
	  OnigOptionType options = reg->options;
	  reg->options = NENCLOSE(node)->option;
	  r = setup_tree(NENCLOSE(node)->target, reg, state, env);
	  reg->options = options;
	}
	break;

      case ENCLOSE_MEMORY:
	if ((state & (IN_ALT | IN_NOT | IN_VAR_REPEAT)) != 0) {
	  BIT_STATUS_ON_AT(env->bt_mem_start, en->regnum);
	  /* SET_ENCLOSE_STATUS(node, NST_MEM_IN_ALT_NOT); */
	}
        r = setup_tree(en->target, reg, state, env);
        break;

      case ENCLOSE_STOP_BACKTRACK:
	{
	  Node* target = en->target;
	  r = setup_tree(target, reg, state, env);
	  if (NTYPE(target) == NT_QTFR) {
	    QtfrNode* tqn = NQTFR(target);
	    if (IS_REPEAT_INFINITE(tqn->upper) && tqn->lower <= 1 &&
		tqn->greedy != 0) {  /* (?>a*), a*+ etc... */
	      int qtype = NTYPE(tqn->target);
	      if (IS_NODE_TYPE_SIMPLE(qtype))
		SET_ENCLOSE_STATUS(node, NST_STOP_BT_SIMPLE_REPEAT);
	    }
	  }
	}
	break;
      }
    }
    break;

  case NT_ANCHOR:
    {
      AnchorNode* an = NANCHOR(node);

      switch (an->type) {
      case ANCHOR_PREC_READ:
	r = setup_tree(an->target, reg, state, env);
	break;
      case ANCHOR_PREC_READ_NOT:
	r = setup_tree(an->target, reg, (state | IN_NOT), env);
	break;

/* allowed node types in look-behind */
#define ALLOWED_TYPE_IN_LB  \
  ( BIT_NT_LIST | BIT_NT_ALT | BIT_NT_STR | BIT_NT_CCLASS | BIT_NT_CTYPE | \
    BIT_NT_CANY | BIT_NT_ANCHOR | BIT_NT_ENCLOSE | BIT_NT_QTFR | BIT_NT_CALL )

#define ALLOWED_ENCLOSE_IN_LB       ( ENCLOSE_MEMORY )
#define ALLOWED_ENCLOSE_IN_LB_NOT   0

#define ALLOWED_ANCHOR_IN_LB \
( ANCHOR_LOOK_BEHIND | ANCHOR_BEGIN_LINE | ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION )
#define ALLOWED_ANCHOR_IN_LB_NOT \
( ANCHOR_LOOK_BEHIND | ANCHOR_LOOK_BEHIND_NOT | ANCHOR_BEGIN_LINE | ANCHOR_END_LINE | ANCHOR_BEGIN_BUF | ANCHOR_BEGIN_POSITION )

      case ANCHOR_LOOK_BEHIND:
	{
	  r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
			      ALLOWED_ENCLOSE_IN_LB, ALLOWED_ANCHOR_IN_LB);
	  if (r < 0) return r;
	  if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
	  r = setup_look_behind(node, reg, env);
	  if (r != 0) return r;
	  if (NTYPE(node) != NT_ANCHOR) goto restart;
	  r = setup_tree(an->target, reg, state, env);
	}
	break;

      case ANCHOR_LOOK_BEHIND_NOT:
	{
	  r = check_type_tree(an->target, ALLOWED_TYPE_IN_LB,
		      ALLOWED_ENCLOSE_IN_LB_NOT, ALLOWED_ANCHOR_IN_LB_NOT);
	  if (r < 0) return r;
	  if (r > 0) return ONIGERR_INVALID_LOOK_BEHIND_PATTERN;
	  r = setup_look_behind(node, reg, env);
	  if (r != 0) return r;
	  if (NTYPE(node) != NT_ANCHOR) goto restart;
	  r = setup_tree(an->target, reg, (state | IN_NOT), env);
	}
	break;
      }
    }
    break;

  default:
    break;
  }

  return r;
}

Project: Onigmo

onig_region_resize(OnigRegion* region, int n)
{
  region->num_regs = n;

  if (n < ONIG_NREGION)
    n = ONIG_NREGION;

  if (region->allocated == 0) {
    region->beg = (int* )xmalloc(n * sizeof(int));
    if (region->beg == 0)
      return ONIGERR_MEMORY;

    region->end = (int* )xmalloc(n * sizeof(int));
    if (region->end == 0) {
      xfree(region->beg);
      return ONIGERR_MEMORY;
    }

    region->allocated = n;
  }
  else if (region->allocated < n) {
    int *tmp;

    region->allocated = 0;
    tmp = (int* )xrealloc(region->beg, n * sizeof(int));
    if (tmp == 0) {
      xfree(region->beg);
      xfree(region->end);
      return ONIGERR_MEMORY;
    }
    region->beg = tmp;
    tmp = (int* )xrealloc(region->end, n * sizeof(int));
    if (tmp == 0) {
      xfree(region->beg);
      return ONIGERR_MEMORY;
    }
    region->end = tmp;

    if (region->beg == 0 || region->end == 0)
      return ONIGERR_MEMORY;

    region->allocated = n;
  }

  return 0;
}

Project: Onigmo

utf16be_code_to_mbclen(OnigCodePoint code,
		       OnigEncoding enc)
{
  return (code > 0xffff ? 4 : 2);
}

Project: Onigmo

code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
{
  UChar *p = buf;

  if ((code & 0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
  if ((code &   0xff00) != 0) *p++ = (UChar )(((code >>  8) & 0xff));
  *p++ = (UChar )(code & 0xff);

#if 1
  if (enclen(enc, buf, p) != (p - buf))
    return ONIGERR_INVALID_CODE_POINT_VALUE;
#endif
  return (int)(p - buf);
}

Project: Onigmo

mbc_case_fold(OnigCaseFoldType flag,
			  const UChar** pp, const UChar* end ARG_UNUSED,
			  UChar* lower, OnigEncoding enc ARG_UNUSED)
{
  const UChar* p = *pp;

  if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
    *lower++ = 's';
    *lower   = 's';
    (*pp)++;
    return 2;
  }

  *lower = ENC_ISO_8859_10_TO_LOWER_CASE(*p);
  (*pp)++;
  return 1;
}

Project: Onigmo

koi8_r_mbc_case_fold(OnigCaseFoldType flag ARG_UNUSED,
		     const UChar** pp, const UChar* end ARG_UNUSED,
		     UChar* lower, OnigEncoding enc ARG_UNUSED)
{
  const UChar* p = *pp;

  *lower = ENC_KOI8_R_TO_LOWER_CASE(*p);
  (*pp)++;
  return 1;
}