예제 #1
0
파일: cond.c 프로젝트: AMDmi3/zsh
mod_export int
cond_match(char **args, int num, char *str)
{
    char *s = args[num];

    singsub(&s);

    return matchpat(str, s);
}
예제 #2
0
/* Find explicit connection patterns and amalgamate the involved dragons. */
void
find_connections(void)
{
  int m, n;
  for (m = 0; m < board_size; m++)
    for (n = 0; n < board_size; n++)
      if (p[m][n])
	matchpat(m, n, conn_callback, p[m][n], 0, conn);
}
예제 #3
0
파일: testscan.c 프로젝트: npe9/harvey
int
matcher(char *action, Pattern *p, char *message, Resub *m)
{
	if(matchpat(p, message, m)){
		if(p->action != Lineoff)
			xprint(1, action, m);
		return 1;
	}
	return 0;
}
예제 #4
0
파일: scanmail.c 프로젝트: npe9/harvey
int
matcher(char *action, Pattern *p, char *message, Resub *m)
{
    char *cp;
    String *s;

    for(cp = message; matchpat(p, cp, m); cp = m->ep) {
        switch(p->action) {
        case SaveLine:
            if(vflag)
                xprint(2, action, m);
            saveline(linefile, sender, m);
            break;
        case HoldHeader:
        case Hold:
            if(nflag)
                continue;
            if(vflag)
                xprint(2, action, m);
            *qdir = holdqueue;
            if(hflag && qname) {
                cp = strchr(sender, '!');
                if(cp) {
                    *cp = 0;
                    *qname = strdup(sender);
                    *cp = '!';
                } else
                    *qname = strdup(sender);
            }
            return 1;
        case Dump:
            if(vflag)
                xprint(2, action, m);
            *(m->ep) = 0;
            if(!tflag) {
                s = s_new();
                s_append(s, sender);
                s = unescapespecial(s);
                syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->sp,
                       s_to_c(s_restart(recips)));
                s_free(s);
            }
            tflag = 1;
            if(sflag)
                cout = opendump(sender);
            return 1;
        default:
            break;
        }
    }
    return 0;
}
예제 #5
0
int c0x_matchfilename(const char *path, const char *pattern)
{
#if DEBUGS
    printf("$ matchfilename(path=%08p='%.9999s', pattern=%08p='%.9999s'\n",
        path, (path != NULL ? path : ""),
        pattern, (pattern != NULL ? pattern : ""));
#endif

    /* Match a pathname to a filename pattern */
    if (path[0] == '\0'  and  pattern[0] != '\0')
        return (-1);
    if (matchpat(path, pattern) >= 0)
        return (0);

#if DEBUGS
    printf("$ matchfilename: fail\n");
#endif

    errno = ENOENT;
    return (-1);
}
예제 #6
0
int
mmv_get_pairs_xnn(mmv_t *mmv, FILE *f)
{
    int rv;
    size_t rlen;

    mmv->encoding = ENCODE_XNN;
    while (true) {
        rv = get_filename_xnn(f, mmv->from, MAXPATLEN, &rlen);
        if (rv == EOF) {
            rv = 0;
            break;
        }
        if (rv) {
            break;
        }
        mmv->fromlen = rlen;
        rv = get_filename_xnn(f, mmv->to, MAXPATLEN, &rlen);
        if (rv == EOF) {
            rv = 0;
            break;
        }
        if (rv) {
            break;
        }
        mmv->tolen = rlen;
        dbg_println_str("from=", mmv->from);
        dbg_println_str("to  =", mmv->to);

        matchpat(mmv);
        if (mmv->paterr) {
            return (-1);
        }
    }

    return (rv);
}
예제 #7
0
static int
find_free_handicap_pattern()
{
  int k;
  int highest_value = -1;
  int sum_values = 0;
  int r;
  int anchor;
  struct pattern *pattern;
  int ll;
  int move;

  number_of_matches = 0;
  matchpat(free_handicap_callback, BLACK, &handipat_db, NULL, NULL);

  if (number_of_matches == 0)
    return 0;

  /* Find the highest value among the matched patterns. */
  for (k = 0; k < number_of_matches; k++)
    if (highest_value < handicap_matches[k].value)
      highest_value = handicap_matches[k].value;

  /* Replace the values by 2^(value - highest_value + 10) and compute
   * the sum of these values. Fractional values are discarded.
   */
  for (k = 0; k < number_of_matches; k++) {
    if (handicap_matches[k].value < highest_value - 10)
      handicap_matches[k].value = 0;
    else
      handicap_matches[k].value = 1 << (handicap_matches[k].value
					- highest_value + 10);
    sum_values += handicap_matches[k].value;
  }

  /* Pick a random number between 0 and sum_values. Don't bother with
   * the fact that lower numbers will tend to be very slightly
   * overrepresented.
   */
  r = gg_rand() % sum_values;
  
  /* Find the chosen pattern. */
  for (k = 0; k < number_of_matches; k++) {
    r -= handicap_matches[k].value;
    if (r < 0)
      break;
  }

  /* Place handicap stones according to pattern k. */
  anchor = handicap_matches[k].anchor;
  pattern = handicap_matches[k].pattern;
  ll = handicap_matches[k].ll;
  
  /* Pick up the location of the move */
  move = AFFINE_TRANSFORM(pattern->move_offset, ll, anchor);
  add_stone(move, BLACK);
  remaining_handicap_stones--;

  /* Add stones at all '!' in the pattern. */
  for (k = 0; k < pattern->patlen; k++) { 
    if (pattern->patn[k].att == ATT_not) {
      int pos = AFFINE_TRANSFORM(pattern->patn[k].offset, ll, anchor);
      add_stone(pos, BLACK);
      remaining_handicap_stones--;
    }
  }

  return 1;
}
예제 #8
0
int findpatn(int *i, int *j, int *val)
/* find pattern to match for next move */
{
 int m, n;
 int ti, tj, tval;
 static int cnd, mtype;  /* game tree node number, move type */
/* mtype = 0, basic; 1, inverted; 2, reflected; 3, inverted & reflected */

/* open game then occupy corners */
 if (opn[4])   /* continue last move */
   {
    opn[4] = 0;  /* clear flag */
    if (opening(i, j, &cnd, mtype)) opn[4] = 1; /* more move then reset flag */
    if (p[*i][*j] == EMPTY)  /* valid move */
      {
       *val = 80;
       return 1;
     }
    else
      opn[4] = 0;
  }

 if (opn[0])   /* Northwest corner */
   {
    opn[0] = 0;  /* clear flag */
    if (openregion(0, 0, 5, 5))
      {
       cnd = 0;
       mtype = 0;
       opening(i, j, &cnd, mtype);  /* get new node for next move */
       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
       *val = 80;
       return 1;
     }
 }

 if (opn[1])   /* Southwest corner */
   {
    opn[1] = 0;
    if (openregion(13, 0, 18, 5))
      {
       cnd = 0;
       mtype = 1;
       opening(i, j, &cnd, mtype);  /* get new node for next move */
       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
       *val = 80;
       return 1;
     }
  }

 if (opn[2])   /* Northeast corner */
   {
    opn[2] = 0;
    if (openregion(0, 13, 5, 18))
      {
       cnd = 0;
       mtype = 2;
       opening(i, j, &cnd, mtype);  /* get new node for next move */
       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
       *val = 80;
       return 1;
     }
  }

 if (opn[3])   /* Northeast corner */
   {
    opn[3] = 0;
    if (openregion(13, 13, 18, 18))
      {
       cnd = 0;
       mtype = 3;
       opening(i, j, &cnd, mtype);  /* get new node for next move */
       if (opening(i, j, &cnd, mtype)) opn[4] = 1;
       *val = 80;
       return 1;
     }
  }

/* occupy edges */
 if (opn[5])   /* North edge */
   {
    opn[5] = 0;
    if (openregion(0, 6, 4, 11))
      {
       *i = 3;
       *j = 9;
       *val = 80;
       return 1;
     }
  }

 if (opn[6])   /* South edge */
   {
    opn[6] = 0;
    if (openregion(18, 6, 14, 11))
      {
       *i = 15;
       *j = 9;
       *val = 80;
       return 1;
     }
  }

 if (opn[7])   /* West edge */
   {
    opn[7] = 0;
    if (openregion(6, 0, 11, 4))
      {
       *i = 9;
       *j = 3;
       *val = 80;
       return 1;
     }
  }

 if (opn[8])   /* East edge */
   {
    opn[8] = 0;
    if (openregion(6, 18, 11, 14))
      {
       *i = 9;
       *j = 15;
       *val = 80;
       return 1;
     }
  }

 *i = -1;
 *j = -1;
 *val = -1;

/* find local pattern */
 for (m = 0; m < 19; m++)
   for (n = 0; n < 19; n++)
     if ((p[m][n] == mymove) &&
         (matchpat(m, n, &ti, &tj, &tval) && (tval > *val)))
       {
        *val = tval;
        *i = ti;
        *j = tj;
      }
 if (*val > 0)  /* pattern found */
    return 1;
 else  /* no match found */
    return 0;
}  /* end findpatn */
예제 #9
0
static int matchpat(const char *path, const char *pattern)
{
#if defined(_unix)
    /* Match a pathname to a filename pattern */
    return (fnmatch(pattern, path, FNM_PATHNAME) == 0 ? 0 : -1);

#elif defined(_WIN32)
    size_t	fi =	0;
    size_t	pi =	0;

    /* Match a pathname to a filename pattern */
    for (;;)
    {
        int	fch;

        fch = path[fi];
        switch (pattern[pi++])
        {
        case '?':
            // Match any single filename character
            if (fch == '\0'  or  fch == '\\'  or  fch == '/')
                return (-1);
            fi++;
            break;

        case '*':
            // Match zero or more filename characters
            while (pattern[pi] == '*')
                pi++;
            do
            {
                if (matchpat(path+fi, pattern+pi) >= 0)
                    return (0);
                fi++;
            } while (path[fi-1] != '\0');
            return (-1);

        case '\\':
        case '/':
            // Match a directory separator
            if (fch != '\\'  and  fch != '/')
                return (-1);
            fi++;
            break;

        case '\0':
            // Match the end of the filename
            return (fch == '\0' ? 0 : -1);

        default:
            // Match a regular filename character
            if (tolower(fch) != tolower(pattern[pi-1]))
                return (-1);
            fi++;
            break;
        }
    }

#else
    #error Unsupported OS

#endif
}