Ejemplo n.º 1
0
static int OSC_MatchBrackets (const char *pattern, const char *test,
                              const char*theWholePattern)
{
  int result;
  int negated = FALSE;
  const char *p = pattern;

  if (pattern[1] == 0) {
    z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"",
              theWholePattern);
    return FALSE;
  }

  if (pattern[1] == '!') {
    negated = TRUE;
    p++;
  }

  while (*p != ']') {
    if (*p == 0) {
      z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"",
                theWholePattern);
      return FALSE;
    }
    if (p[1] == '-' && p[2] != 0) {
      if (test[0] >= p[0] && test[0] <= p[2]) {
        result = !negated;
        goto advance;
      }
    }
    if (p[0] == test[0]) {
      result = !negated;
      goto advance;
    }
    p++;
  }

  result = negated;

advance:

  if (!result) {
    return FALSE;
  }

  while (*p != ']') {
    if (*p == 0) {
      z_verbose(1, "[matchbox]: unterminated [ in OSC-pattern \".../%s/...\"",
                theWholePattern);
      return FALSE;
    }
    p++;
  }

  return OSC_PatternMatch (p+1,test+1, theWholePattern);
}
Ejemplo n.º 2
0
Archivo: index.c Proyecto: Tzero2/pd
/* delete a symbol from the map (if it is in there) */
static void index_delete(t_index *x, t_symbol *s, int argc, t_atom*argv)
{
  int idx=-1;
  ZEXY_USEVAR(s);
  if(argc!=1){
    error("index :: delete what ?");
    return;
  } else {
    if(argv->a_type==A_FLOAT){
      idx=atom_getint(argv)-1;
    } else if (argv->a_type==A_SYMBOL){
      idx=find_item(atom_getsymbol(argv),x->names, x->maxentries);
    } else {
      error("index :: delete what ?");
      return;    
    }
  }

  if ( idx >= 0 && idx < x->maxentries) {
    x->names[idx]=0;
    x->entries--;
    outlet_float(x->x_obj.ob_outlet, 0.0);
  } else {
    z_verbose(1, "index :: couldn't find element");
    outlet_float(x->x_obj.ob_outlet, -1.0);
  }
}
Ejemplo n.º 3
0
Archivo: index.c Proyecto: Tzero2/pd
/* add a symbol to the map (if possible) */
static void index_add(t_index *x, t_symbol *s, t_float f)
{
  int newentry=(int)f;

  if (! (find_item(s, x->names, x->maxentries)+1) ) {
    if (x->auto_resize && (x->entries==x->maxentries || newentry>=x->maxentries)){
      /* do some resizing */
      int maxentries=(newentry>x->maxentries)?newentry:(x->maxentries*2);
      int i;
      t_symbol**buf=(t_symbol **)getbytes(sizeof(t_symbol *) * maxentries);
      if(buf!=0){
        memcpy(buf, x->names, sizeof(t_symbol *) * x->maxentries);
        for(i=x->maxentries; i<maxentries; i++)buf[i]=0;

        freebytes(x->names, sizeof(t_symbol *) * x->maxentries);

        x->names=buf;
        x->maxentries=maxentries;
      }
    }

    if ( x->entries < x->maxentries ) {
      if(newentry>0){
        newentry--;
        if(x->names[newentry]){ /* it is already taken! */
          z_verbose(1, "index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1);
          outlet_float(x->x_obj.ob_outlet, -1.f);
          return;
        }
      } else {
        newentry=find_free(x->names, x->maxentries);
      }
      if (newentry + 1) {
	x->entries++;
	x->names[newentry]=s;
	outlet_float(x->x_obj.ob_outlet, (t_float)newentry+1);
        return;

      } else error("index :: couldn't find any place for new entry");
    } else error("index :: max number of elements (%d) reached !", x->maxentries);
  } else  z_verbose(1, "index :: element '%s' already exists", s->s_name);
  /* couldn't add the symbol to our index table */
  outlet_float(x->x_obj.ob_outlet, -1.f);
}
Ejemplo n.º 4
0
static int OSC_PatternMatch (const char *  pattern, const char * test,
                             const char*theWholePattern)
{
  if (pattern == 0 || pattern[0] == 0) {
    return test[0] == 0;
  }

  if (test[0] == 0) {
    if (pattern[0] == '*') {
      return OSC_PatternMatch (pattern+1,test, theWholePattern);
    } else {
      return FALSE;
    }
  }

  switch (pattern[0]) {
  case 0      :
    return test[0] == 0;
  case '?'    :
    return OSC_PatternMatch (pattern + 1, test + 1, theWholePattern);
  case '*'    :
    if (OSC_PatternMatch (pattern+1, test, theWholePattern)) {
      return TRUE;
    } else {
      return OSC_PatternMatch (pattern, test+1, theWholePattern);
    }
  case ']'    :
  case '}'    :
    z_verbose(1, "[matchbox]: spurious %c in OSC-pattern \".../%s/...\"",
              pattern[0], theWholePattern);
    return FALSE;
  case '['    :
    return OSC_MatchBrackets (pattern,test, theWholePattern);
  case '{'    :
    return OSC_MatchList (pattern,test, theWholePattern);
  case '\\'   :
    if (pattern[1] == 0) {
      return test[0] == 0;
    } else if (pattern[1] == test[0]) {
      return OSC_PatternMatch (pattern+2,test+1, theWholePattern);
    } else {
      return FALSE;
    }
  default     :
    if (pattern[0] == test[0]) {
      return OSC_PatternMatch (pattern+1,test+1, theWholePattern);
    } else {
      return FALSE;
    }
  }
}
Ejemplo n.º 5
0
static void matchbox_add(t_matchbox*x, t_symbol*s, int argc, t_atom*argv)
{
  /* 1st match, whether we already have this entry */
  if(matchlistlist(0, x->x_lists, argc, argv, MATCHBOX_EXACT, FALSE)) {
    /* already there, skip the rest */
    z_verbose(1,
              "[matchbox]: refusing to add already existing list to buffer...");
    return;
  }

  /* 2nd if this is a new entry, add it */
  x->x_lists=addlistlist(x->x_lists, argc, argv);
  x->x_numlists++;
}
Ejemplo n.º 6
0
static int OSC_MatchList (const char *pattern, const char *test,
                          const char* theWholePattern)
{

  const char *restOfPattern, *tp = test;

  for(restOfPattern = pattern; *restOfPattern != '}'; restOfPattern++) {
    if (*restOfPattern == 0) {
      z_verbose(1, "[matchbox]: unterminated { in OSC-pattern \".../%s/...\"",
                theWholePattern);
      return FALSE;
    }
  }

  restOfPattern++; /* skip close curly brace */


  pattern++; /* skip open curly brace */

  while (1) {

    if (*pattern == ',') {
      if (OSC_PatternMatch (restOfPattern, tp, theWholePattern)) {
        return TRUE;
      } else {
        tp = test;
        ++pattern;
      }
    } else if (*pattern == '}') {
      return OSC_PatternMatch (restOfPattern, tp, theWholePattern);
    } else if (*pattern == *tp) {
      ++pattern;
      ++tp;
    } else {
      tp = test;
      while (*pattern != ',' && *pattern != '}') {
        pattern++;
      }
      if (*pattern == ',') {
        pattern++;
      }
    }
  }
}
Ejemplo n.º 7
0
static t_listlist*matchlistlist_regex(unsigned int*numresults,
                                      t_listlist*searchlist, int p_argc, t_atom*p_argv, int flags,
                                      int delete_results)
{
  regex_t**regexpressions=0;
  t_listlist*matchinglist=0, *sl;
  int i=0;
  int num=0;

  flags|=REG_EXTENDED;

  /* 1st compile the patterns */
  regexpressions=(regex_t**)getbytes(sizeof(regex_t*)*p_argc);
  for(i=0; i<p_argc; i++) {
    char*s_pattern=0;
    int pattern_size=0;
    t_atom*pattern=p_argv+i;
    if(pattern->a_type==A_SYMBOL) {
      s_pattern=pattern->a_w.w_symbol->s_name;
    } else {
      pattern_size=sizeof(char)*MAXPDSTRING;
      s_pattern=(char*)getbytes(pattern_size);
      atom_string(pattern, s_pattern, pattern_size);
    }
    regexpressions[i]=(regex_t*)getbytes(sizeof(regex_t));
    if(regcomp(regexpressions[i], s_pattern, flags)) {
      z_verbose(1, "[matchbox]: invalid regular expression: %s", s_pattern);
      if(regexpressions[i]) {
        freebytes(regexpressions[i], sizeof(regex_t));
      }
      regexpressions[i]=0;
    }
    if(pattern_size>0) {
      freebytes(s_pattern, pattern_size);
      s_pattern=0;
      pattern_size=0;
    }
  }

  /* match the patterns to the tests */
  if(FALSE==delete_results) {
    for(sl=searchlist; 0!=sl; sl=sl->next) {
      if(TRUE==listmatch_regex(p_argc, regexpressions, sl->argc, sl->argv)) {
        matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
        num++;
      }
    }
  } else if (TRUE==delete_results) {
    /* yummy: delete matching lists! */
    t_listlist*lastgood=searchlist;
    for(sl=searchlist; 0!=sl; sl=sl->next) {
      if(TRUE==listmatch_regex(p_argc, regexpressions, sl->argc, sl->argv)) {
        matchinglist=addlistlist(matchinglist, sl->argc, sl->argv);
        num++;

        sl=deletelistnext(lastgood);
      } else {
        lastgood=sl;
      }
    }
  }

  /* clear the patterns */
  for(i=0; i<p_argc; i++) {
    if(regexpressions[i]) {
      regfree(regexpressions[i]);
      freebytes(regexpressions[i], sizeof(regex_t));
    }
  }
  freebytes(regexpressions, sizeof(regex_t*)*p_argc);

  /* return the result */
  if(numresults!=0) {
    *numresults=num;
  }
  return matchinglist;
}
Ejemplo n.º 8
0
static void lifop_query(t_lifop*x)
{  
  z_verbose(1, "%d elements in lifo", (int)x->counter);
  
  outlet_float(x->x_infout, (t_float)x->counter);
}