示例#1
0
/* Compile a regexp and signal a Lisp error if anything goes wrong.  */
void
compile_pattern (Lisp_Object pattern, struct re_pattern_buffer *bufp, char *translate, int backward)
{
  char *val;
  Lisp_Object dummy;

  if (EQ (pattern, last_regexp)
      && translate == bufp->translate /* 92.4.10 by K.Handa */
      /* 93.7.13 by K.Handa */
      && NILP (current_buffer->mc_flag) == !bufp->mc_flag
      && (!bufp->syntax_version
	  || bufp->syntax_version == syntax_table_version)
      && (!bufp->category_version
	  || bufp->category_version == category_table_version))
    return;

  if (CONSP (pattern))			/* pre-compiled regexp */
    {
      Lisp_Object compiled;

      val = 0;
      pattern = XCONS (pattern)->car;
      if (CONSP (pattern)
	  && (compiled = backward ? XCONS(pattern)->cdr : XCONS(pattern)->car)
	  && XTYPE (compiled) == Lisp_Vector
	  && XVECTOR (compiled)->size == 4) {
	/* set_pattern will set bufp->allocated to NULL */
	set_pattern (compiled, bufp, translate);
	return;
      }

      val = "Invalied pre-compiled regexp";
      goto invalid_regexp;
    }

  CHECK_STRING (pattern, 0);

  last_regexp = Qnil;
  bufp->translate = translate;
  bufp->syntax_version = bufp->category_version = 0; /* 93.7.13 by K.Handa */
  /* 92.7.10 by T.Enami
     'bufp->allocated == 0' means bufp->buffer points to pre-compiled pattern
     in a lisp string, which should not be 'realloc'ed. */
  if (bufp->allocated == 0) bufp->buffer = 0; 

  val = re_compile_pattern (XSTRING (pattern)->data,
			    XSTRING (pattern)->size,
			    bufp);

  if (val)
    {
    invalid_regexp:
      dummy = build_string (val);
      while (1)
	Fsignal (Qinvalid_regexp, Fcons (dummy, Qnil));
    }
  last_regexp = pattern;
  return;
}
示例#2
0
/* analyze given string and return protocol id */
static XTYPE(PROTOCOLS) GetChannelProtocol(char *proto)
{
  XTYPE(PROTOCOLS) p;

  proto = g_strstrip(proto);
  for(p = 0; p < XSIZE(PROTOCOLS); ++p)
    if(g_ascii_strcasecmp(XSTR(PROTOCOLS, p), proto) == 0) return p;
  return -1;
}
示例#3
0
/*
 * return keyword and update given "value" with extracted value
 * spaces will be trimmed from "value"
 */
static XTYPE(KEYWORDS) GetKey(char *key)
{
  XTYPE(KEYWORDS) k;

  key = g_strstrip(key);
  for(k = 0; k < XSIZE(KEYWORDS); ++k)
    if(g_strcmp0(XSTR(KEYWORDS, k), key) == 0) return k;
  return -1;
}
示例#4
0
/* parse the name and append to given array of names as connection or string */
static void ParseName(char *name, GPtrArray *names)
{
  char **tokens;
  XTYPE(PROTOCOLS) proto;

  name = g_strstrip(name);
  tokens = g_strsplit(name, CONNECTION_DELIMITER, ConnectionTokensNumber);
  proto = GetChannelProtocol(tokens[Protocol]);

  if(proto == -1)
  {
    struct File *f;
    ZLOGFAIL(tokens[1] != NULL, EFAULT, "invalid channel name");
    ZLOGFAIL(!g_path_is_absolute(name), EFAULT,
        "only absolute path channels are allowed");


    f = g_malloc0(sizeof *f);
    f->protocol = ProtoRegular; /* just in case (will be set later) */
    f->name = g_strdup(name);
    f->handle = NULL;
    g_ptr_array_add(names, f);
  }
  else
  {
    struct Connection *c = g_malloc0(sizeof *c);

    /* TODO(d'b): fix "invalid_name_server_type.manifest" bug here */
    ZLOGFAIL(tokens[ConnectionTokensNumber] != NULL || tokens[Host] == NULL,
        EFAULT, "invalid channel url");

    c->protocol = proto;
    c->host = ExtractHost(tokens[Host], &c->flags);
    c->port = ToInt(tokens[Port]);
    c->handle = NULL;
    g_ptr_array_add(names, c);
  }

  g_strfreev(tokens);
}
示例#5
0
/* pattern is a list of strings:
	compiled_code, fastmap, syntax_fastmap, category_fastmap */
void
set_pattern (Lisp_Object pattern, struct re_pattern_buffer *bufp, char *translate)
{
  Lisp_Object temp;

  if (bufp->allocated != 0) {
/*
  Coming here means that this buffer was used to hold
  an old-style pattern.  Because new-style pattern is not
  self-destructive, we only have to set pointer.
  Instead, to avoid it being freed later,
  bufp->allocated should be set to 0.
*/
    free (bufp->buffer);
    bufp->allocated = 0;
  }
  temp = XVECTOR (pattern)->contents[0];
  bufp->buffer = (char *)XSTRING (temp)->data;
  bufp->used = XSTRING (temp)->size;
  bufp->translate = translate;
  /* 93.7.13 by K.Handa -- set fastmap */
  bufp->mc_flag = !NILP (current_buffer->mc_flag);
  {
    Lisp_Object fmap, syntax_fmap, category_fmap;
    char *fastmap = bufp->fastmap;
    int i;
    unsigned char ch;

    bufp->fastmap_accurate = 1;

    fmap = XVECTOR (pattern)->contents[1];
    if (NILP (fmap) && NILP (syntax_fmap) && NILP (category_fmap)) {
      bufp->can_be_null = 1;
    } else {
      bufp->can_be_null = 0;
      bzero (fastmap, 256);
      if (XTYPE (fmap) == Lisp_String) /* 93.7.19 by K.Handa */
	bcopy (XSTRING (fmap)->data, fastmap, XSTRING (fmap)->size);

      syntax_fmap = XVECTOR (pattern)->contents[2];
      if (XTYPE (syntax_fmap) == Lisp_String) {
	for (ch = 0; ch < 0x80; ch++)
	  if (!fastmap[ch]
	      && XSTRING (syntax_fmap)->data[syntax_code_spec[(char) SYNTAX (ch)]])
	    fastmap[ch] = 1;
	bufp->syntax_version = syntax_table_version;
      } else
	bufp->syntax_version = 0;

      category_fmap = XVECTOR (pattern)->contents[3];
      if (XTYPE (category_fmap) == Lisp_String) {
	char str[96], *p;
	int not_category_spec = 0;

	for (i = 32; i < 128; i++)
	  if (XSTRING (category_fmap)->data[i] == 2) {
	    not_category_spec = 1;
	    break;
	  }
	for (ch = 0; ch < 0x80; ch++) {
	  if (!fastmap[ch]) {
	    pack_mnemonic_string
	      (char_category (ch, current_buffer->category_table), str);
	    if (not_category_spec) {
	      for (p = str; *p; p++)
		if (XSTRING (category_fmap)->data[*p] != 2) {
		  fastmap[ch] = 1;
		  break;
		}
	    } else {
	      for (p = str; *p; p++)
		if (XSTRING (category_fmap)->data[*p] == 1) {
		  fastmap[ch] = 1;
		  break;
		}
	    }
	  }
	}
	bufp->category_version = category_table_version;
      } else
	bufp->category_version = 0;

      if (bufp->mc_flag
	  && (XTYPE (syntax_fmap) == Lisp_String
	      || XTYPE (category_fmap) == Lisp_String)) {
	for (ch = 0x80; ch < 0xA0; ch++)
	  fastmap[ch] = 1;
      }
    }
  }
/* 92.7.10 by T.Enami
   Force 're-compile-pattern' when compile_pattern is called next time. */
  last_regexp = Qnil;
}