Example #1
0
/* client_match - match host name and address against token */
static int client_match(char *tok,char *item)
{
    char **client = (char **)item;
    int     match;
	char invalid_char = '\0';

    /*
     * Try to match the address first. If that fails, try to match the host
     * name if available.
     */

    if ((match = string_match(tok, client[1], &invalid_char)) == 0) {
		if(invalid_char)
			DEBUG(0,("client_match: address match failing due to invalid character '%c' found in \
token '%s' in an allow/deny hosts line.\n", invalid_char, tok ));

		if (client[0][0] != 0)
			match = string_match(tok, client[0], &invalid_char);

		if(invalid_char)
			DEBUG(0,("client_match: address match failing due to invalid character '%c' found in \
token '%s' in an allow/deny hosts line.\n", invalid_char, tok ));
	}

    return (match);
}
Example #2
0
/* client_match - match host name and address against token */
bool client_match(const char *tok, const void *item)
{
	const char **client = (const char **)item;

	/*
	 * Try to match the address first. If that fails, try to match the host
	 * name if available.
	 */

	if (string_match(tok, client[ADDR_INDEX])) {
		return true;
	}

	if (strnequal(client[ADDR_INDEX],"::ffff:",7) &&
			!strnequal(tok, "::ffff:",7)) {
		/* client[ADDR_INDEX] is an IPv4 mapped to IPv6, but
 		 * the list item is not. Try and match the IPv4 part of
 		 * address only. This will happen a lot on IPv6 enabled
 		 * systems with IPv4 allow/deny lists in smb.conf.
 		 * Bug #5311. JRA.
 		 */
		if (string_match(tok, (client[ADDR_INDEX])+7)) {
			return true;
		}
	}

	if (client[NAME_INDEX][0] != 0) {
		if (string_match(tok, client[NAME_INDEX])) {
			return true;
		}
	}

	return false;
}
Example #3
0
File: peg.c Project: ctelfer/catlib
static int parse_paren_expr(struct peg_grammar_parser *pgp,
			    struct peg_cursor *pc, int *exprp)
{
	int rv;
	struct peg_cursor npc = *pc;
	int expr = -1;

	if ( !string_match(pgp, "(", &npc) )
		return 0;

	rv = parse_expr(pgp, &npc, &expr);
	if ( rv < 0 )
		return -1;
	if ( rv == 0 )
		goto err;
	if ( !string_match(pgp, ")", &npc) )
		goto err;

	*pc = npc;
	*exprp = expr;
	return 1;

err:
	peg_node_free(pgp->peg, expr);
	pgp->err = PEG_ERR_BAD_PAREXPR;
	pgp->eloc = npc;
	return -1;
}
Example #4
0
irom static io_i2c_t io_i2c_pin_from_string(const string_t *pin)
{
	if(string_match(pin, "sda"))
		return(io_i2c_sda);
	else if(string_match(pin, "scl"))
		return(io_i2c_scl);
	else
		return(io_i2c_error);
}
Example #5
0
//電卓関数モードで中間か逆ポーランドか選択可能
void calc(char* formula)
{
	printf("\tCalc Exec : Start\n");

	//エラーフラグのクリア
	error_flag = 0;

	#ifdef _Debug_enable
		//デバッグ用
		printf("\t\tDebug : calc -> mode set search start\n");
	#endif

	char tmp_buffer[BUFFER_LENGTH];
	my_strcpy(tmp_buffer,formula);
	string_trim(tmp_buffer);

	//コマンド部分に関する記述
	if(string_match(tmp_buffer,"set"))
	{
		printf("\tCalc Exec : detected \"set\"\n");
		if(string_match(tmp_buffer,"mode=IN"))
		{
			mode = IN_MODE;
			printf("\tCalc Exec : set Calc mode = IN_MODE\n");
			return;
		}
		else if(string_match(tmp_buffer,"mode=RPN"))
		{
			mode = RPN_MODE;
			printf("\tCalc Exec : set Calc mode = RPN_MODE\n");
			return;
		}
		else
		{
			printf("\tCalc Exec : Please retry set mode.\n");
			return;
		}
	}
	else if(string_match(tmp_buffer,"quit")||string_match(tmp_buffer,"exit"))
	{
		mode = EXIT_MODE;
		return;
	}

	#ifdef _Debug_enable
		//デバッグ用
		printf("\t\tDebug : calc -> mode = %d, fromula = \"%s\"\n",mode,formula);
	#endif

	//計算関数呼び出し
	switch(mode)
	{
		case RPN_MODE : rpn_calc(formula); break;
		case IN_MODE	: in_calc(formula); break;
	}
}
Example #6
0
irom static io_trigger_t string_to_trigger_type(const string_t *string)
{
	if(string_match(string, "off"))
		return(io_trigger_off);
	if(string_match(string, "on"))
		return(io_trigger_on);
	if(string_match(string, "down"))
		return(io_trigger_down);
	if(string_match(string, "up"))
		return(io_trigger_up);

	return(io_trigger_error);
}
irom static attr_pure config_flag_enum_t config_flag_to_id(const string_t *flag_name)
{
	const config_flag_t *entry;
	config_flag_enum_t current;

	for(current = 0; current < config_flag_size; current++)
	{
		entry = &config_flag[current];

		if(string_match(flag_name, entry->short_name) || string_match(flag_name, entry->long_name))
			break;
	}

	return(current);
}
Example #8
0
irom static bool pin_flag_from_string(const string_t *flag, io_config_pin_entry_t *pin_config, int value)
{
	if(string_match(flag, "autostart"))
		pin_config->flags.autostart = value;
	else if(string_match(flag, "repeat"))
		pin_config->flags.repeat = value;
	else if(string_match(flag, "pullup"))
		pin_config->flags.pullup = value;
	else if(string_match(flag, "reset-on-read"))
		pin_config->flags.reset_on_read = value;
	else
		return(false);

	return(true);
}
Example #9
0
/* client_match - match host name and address against token */
static int client_match(char *tok,char *item)
{
    char **client = (char **)item;
    int     match;

    /*
     * Try to match the address first. If that fails, try to match the host
     * name if available.
     */

    if ((match = string_match(tok, client[1])) == 0)
	if (client[0][0] != 0)
	    match = string_match(tok, client[0]);
    return (match);
}
Example #10
0
static int
from_match(const char *tok, const char *string)
{
    int     tok_len;
    int     str_len;

    /*
     * If a token has the magic value "ALL" the match always succeeds. Return
     * YES if the token fully matches the string. If the token is a domain
     * name, return YES if it matches the last fields of the string. If the
     * token has the magic value "LOCAL", return YES if the string does not
     * contain a "." character. If the token is a network number, return YES
     * if it matches the head of the string.
     */

    if (tok[0] == '@') {			/* netgroup */
        return (netgroup_match(tok + 1, string, NULL));
    } else if (string_match(tok, string)) {	/* ALL or exact match */
        return (YES);
    } else if (tok[0] == '.') {			/* domain: match last fields */
        if ((str_len = strlen(string)) > (tok_len = strlen(tok))
                && strcasecmp(tok, string + str_len - tok_len) == 0)
            return (YES);
    } else if (strcasecmp(tok, "LOCAL") == 0) {	/* local: no dots */
        if (strchr(string, '.') == 0)
            return (YES);
    } else if (tok[(tok_len = strlen(tok)) - 1] == '.'	/* network */
               && strncmp(tok, string, tok_len) == 0) {
        return (YES);
    }
    return (NO);
}
Example #11
0
/**
 * Processes the command-line options, filling in the members of the Options
 * structure corresponding to the switches
 */
int options_parse(Options *self, int argc, char *argv[])
{
  int arg = 1;

  while (arg < argc) {
    String s = string_from_c(argv[arg]);

    /* Debug: */
    if (!strcmp(argv[arg], "-d") || !strcmp(argv[arg], "--debug")) {
      self->debug = 1;

    /* Output filename: */
    } else if (!strcmp(argv[arg], "-o")) {
      ++arg;
      if (argc <= arg) return 0;
      self->name_out = string_from_c(argv[arg]);

    /* Output filename, smushed: */
    } else if (2 == string_match(s, string_from_k("-o"))) {
      self->name_out = string(s.p + 2, s.end);

    /* Input filename: */
    } else {
      if (string_size(self->name_in)) return 0;
      self->name_in = s;
    }
    ++arg;
  }

  if (!string_size(self->name_in))
    return 0;

  return 1;
}
Example #12
0
void match_list(dbref first, int local)
{
    char *namebuf;

    if (md.confidence >= CON_DBREF) {
	return;
    }

    DOLIST(first, first) {
	if (first == md.absolute_form) {
	    promote_match(first, CON_DBREF | local);
	    return;
	}

	/*
	 * Warning: make sure there are no other calls to Name() in
	 * promote_match or its called subroutines; they
	 * would overwrite Name()'s static buffer which is
	 * needed by string_match().
	 */
	namebuf = (char *) PureName(first);

	if (!string_compare(namebuf, md.string)) {
	    promote_match(first, CON_COMPLETE | local);
	} else if (string_match(namebuf, md.string)) {
	    promote_match(first, local);
	}
    }
}
Example #13
0
static int parse_cause(char *arg)
{
	const char *errstr;
	int cause;

	if (!arg || arg[0] == '?' || string_match(arg, "help")) {
		printf("Reset cause values:\n"
		       "  1   System OK\n"
		       "  2   PID failed subscribing\n"
		       "  3   PID failed kick\n"
		       "  4   PID failed unsubscribing\n"
		       "  5   PID failed to meet its deadline\n"
		       "  6   Forced reset\n"
		       "  7   Failed, unknown\n"
		       "  8   File descriptor leak\n"
		       "  9   Memory leak\n"
		       "  10  CPU overload\n");
		exit(1);
	}

	cause = strtonum(arg, 1, 10, &errstr);
	if (errstr)
		errx(1, "Error, reset cause is %s", errstr);

	return cause;
}
Example #14
0
int
gui_line_match_tags (struct t_gui_line_data *line_data,
                     int tags_count, char **tags_array)
{
    int i, j;

    if (!line_data)
        return 0;

    if (line_data->tags_count == 0)
        return 0;

    for (i = 0; i < tags_count; i++)
    {
        for (j = 0; j < line_data->tags_count; j++)
        {
            /* check tag */
            if (string_match (line_data->tags_array[j],
                              tags_array[i],
                              0))
                return 1;
        }
    }

    return 0;
}
Example #15
0
/* <obj> <pattern> .stringmatch <bool> */
static int
zstringmatch(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    bool result;

    check_read_type(*op, t_string);
    switch (r_type(op1)) {
        case t_string:
            check_read(*op1);
            goto cmp;
        case t_name:
            name_string_ref(imemory, op1, op1);	/* can't fail */
cmp:
            result = string_match(op1->value.const_bytes, r_size(op1),
                                  op->value.const_bytes, r_size(op),
                                  NULL);
            break;
        default:
            result = (r_size(op) == 1 && *op->value.bytes == '*');
    }
    make_bool(op1, result);
    pop(1);
    return 0;
}
Example #16
0
static int from_match(char *tok, struct login_info *item)
{
    char   *string = item->from;
    int     tok_len;
    int     str_len;

    /*
     * If a token has the magic value "ALL" the match always succeeds. Return
     * YES if the token fully matches the string. If the token is a domain
     * name, return YES if it matches the last fields of the string. If the
     * token has the magic value "LOCAL", return YES if the string does not
     * contain a "." character. If the token is a network number, return YES
     * if it matches the head of the string.
     */

    if (tok[0] == '@') {			/* netgroup */
	return (netgroup_match(tok + 1, string, (char *) 0));
    } else if (string_match(tok, string)) {	/* ALL or exact match */
	return (YES);
    } else if (tok[0] == '.') {			/* domain: match last fields */
	if ((str_len = strlen(string)) > (tok_len = strlen(tok))
	    && strcasecmp(tok, string + str_len - tok_len) == 0)
	    return (YES);
    } else if (strcasecmp(tok, "LOCAL") == 0) {	/* local: no dots */
	if (strchr(string, '.') == 0)
	    return (YES);
#ifdef BROKEN_NETWORK_MATCH
    } else if (tok[(tok_len = strlen(tok)) - 1] == '.'	/* network */
	       && strncmp(tok, string, tok_len) == 0) {
	return (YES);
#else /*  BROKEN_NETWORK_MATCH */
    } else if (tok[(tok_len = strlen(tok)) - 1] == '.') {
        /*
           The code below does a more correct check if the address specified
           by "string" starts from "tok".
                               1998/01/27  Andrey V. Savochkin <*****@*****.**>
         */

        struct hostent *h;
        char hn[3+1+3+1+3+1+3+1+1];
        int r;

        h = gethostbyname(string);
        if (h == NULL)
	    return (NO);
        if (h->h_addrtype != AF_INET)
	    return (NO);
        if (h->h_length != 4)
	    return (NO); /* only IPv4 addresses (SAW) */
        r = snprintf(hn, sizeof(hn), "%u.%u.%u.%u.",
		     (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1],
		     (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]);
        if (r < 0 || r >= sizeof(hn))
	    return (NO);
        if (!strncmp(tok, hn, tok_len))
	    return (YES);
#endif /*  BROKEN_NETWORK_MATCH */
    }
    return (NO);
}
Example #17
0
const char *SearchAndCheck(const char *keyword)
{
  char *status;
  int got_it = 0;
  char line[MAX_LINE_LENGTH] = "empty";

  rewind(FrcF);
  while (got_it == 0) {
    status = fgets( line, MAX_LINE_LENGTH, FrcF );
    if (status == NULL) {
      fprintf(stderr," Unable to find keyword '%s'\n",keyword);
      fprintf(stderr," Check consistency of forcefield name and class \n");
      fprintf(stderr," Exiting....\n");
      exit(1);
    }
    if (line[0] == '@') {
      if (string_match(strtok(line+1," '\t\n'("),keyword)) {
        got_it = 1;
        status = strtok(NULL," '\t\n(");
        if (status != NULL)
          return strdup(status);
      }
    }
  }
  return strdup("(unknown)");
}
Example #18
0
static int user_match(char *tok, struct login_info *item)
{
    char   *string = item->user->pw_name;
    struct login_info fake_item;
    struct group *group;
    int     i;
    char   *at;

    /*
     * If a token has the magic value "ALL" the match always succeeds.
     * Otherwise, return YES if the token fully matches the username, if the
     * token is a group that contains the username, or if the token is the
     * name of the user's primary group.
     */

    if ((at = strchr(tok + 1, '@')) != 0) {	/* split user@host pattern */
	*at = 0;
	fake_item.from = myhostname();
	return (user_match(tok, item) && from_match(at + 1, &fake_item));
    } else if (tok[0] == '@') {			/* netgroup */
	return (netgroup_match(tok + 1, (char *) 0, string));
    } else if (string_match(tok, string)) {	/* ALL or exact match */
	return (YES);
    } else if ((group = getgrnam(tok))) {	/* try group membership */
	if (item->user->pw_gid == group->gr_gid)
	    return (YES);
	for (i = 0; group->gr_mem[i]; i++)
	    if (strcasecmp(string, group->gr_mem[i]) == 0)
		return (YES);
    }
    return (NO);
}
Example #19
0
static int
user_match (pam_handle_t *pamh, char *tok, struct login_info *item)
{
    char   *string = item->user->pw_name;
    struct login_info fake_item;
    char   *at;
    int    rv;

    if (item->debug)
      pam_syslog (pamh, LOG_DEBUG,
		  "user_match: tok=%s, item=%s", tok, string);

    /*
     * If a token has the magic value "ALL" the match always succeeds.
     * Otherwise, return YES if the token fully matches the username, if the
     * token is a group that contains the username, or if the token is the
     * name of the user's primary group.
     */

    /* Try to split on a pattern (@*[^@]+)(@+.*) */
    for (at = tok; *at == '@'; ++at);

    if ((at = strchr(at, '@')) != NULL) {
        /* split user@host pattern */
	if (item->hostname == NULL)
	    return NO;
	memcpy (&fake_item, item, sizeof(fake_item));
	fake_item.from = item->hostname;
	fake_item.gai_rv = 0;
	fake_item.res = NULL;
	fake_item.from_remote_host = 1; /* hostname should be resolvable */
	*at = 0;
	if (!user_match (pamh, tok, item))
		return NO;
	rv = from_match (pamh, at + 1, &fake_item);
	if (fake_item.gai_rv == 0 && fake_item.res)
		freeaddrinfo(fake_item.res);
	return rv;
    } else if (tok[0] == '@') {			/* netgroup */
	const char *hostname = NULL;
	if (tok[1] == '@') {			/* add hostname to netgroup match */
		if (item->hostname == NULL)
		    return NO;
		++tok;
		hostname = item->hostname;
	}
        return (netgroup_match (pamh, tok + 1, hostname, string, item->debug));
    } else if (tok[0] == '(' && tok[strlen(tok) - 1] == ')')
      return (group_match (pamh, tok, string, item->debug));
    else if ((rv=string_match (pamh, tok, string, item->debug)) != NO) /* ALL or exact match */
      return rv;
    else if (item->only_new_group_syntax == NO &&
	     pam_modutil_user_in_group_nam_nam (pamh,
						item->user->pw_name, tok))
      /* try group membership */
      return YES;

    return NO;
}
Example #20
0
static
void module_load_event(void *dcontext, const module_data_t *data, bool loaded)
{
    if (string_match(dr_module_preferred_name(data), "client.flush.exe")) {
        start = data->start;
        end = data->end;
    }
}
Example #21
0
SANE_Status
sane_control_option (SANE_Handle h, SANE_Int opt, SANE_Action act,
		     void *val, SANE_Word * info)
{
  struct device *dev = h;

  DBG (3, "%s: %p, %d, <%d>, %p, %p\n", __FUNCTION__, h, opt, act, val, (void *)info);
  if (!dev || opt >= NUM_OPTIONS || opt < 0)
    return SANE_STATUS_INVAL;

  if (info)
    *info = 0;

  if (act == SANE_ACTION_GET_VALUE) { /* GET */
    if (dev->opt[opt].type == SANE_TYPE_STRING)
      strcpy(val, dev->val[opt].s);
    else
      *(SANE_Word *)val = dev->val[opt].w;
  } else if (act == SANE_ACTION_SET_VALUE) { /* SET */
    SANE_Parameters xpara = dev->para;
    SANE_Option_Descriptor xopt[NUM_OPTIONS];
    Option_Value xval[NUM_OPTIONS];
    int i;

    if (dev->opt[opt].constraint_type == SANE_CONSTRAINT_STRING_LIST) {
      dev->val[opt].s = string_match(dev->opt[opt].constraint.string_list, val);
      if (info && strcasecmp(dev->val[opt].s, val))
	*info |= SANE_INFO_INEXACT;
    } else if (opt == OPT_RESOLUTION)
      dev->val[opt].w = res_dpi_codes[dpi_to_code(*(SANE_Word *)val)];
    else
      dev->val[opt].w = *(SANE_Word *)val;

    memcpy(&xopt, &dev->opt, sizeof(xopt));
    memcpy(&xval, &dev->val, sizeof(xval));
    fix_window(dev);
    set_parameters(dev);

    /* check for side effects */
    if (info) {
      if (memcmp(&xpara, &dev->para, sizeof(xpara)))
	*info |= SANE_INFO_RELOAD_PARAMS;
      if (memcmp(&xopt, &dev->opt, sizeof(xopt)))
	*info |= SANE_INFO_RELOAD_OPTIONS;
      for (i = 0; i < NUM_OPTIONS; i++)
	if (xval[i].w != dev->val[i].w) {
	  if (i == opt)
	    *info |= SANE_INFO_INEXACT;
	  else
	    *info |= SANE_INFO_RELOAD_OPTIONS;
	}
    }
  }

  DBG (4, "%s: %d, <%d> => %08x, %x\n", __FUNCTION__, opt, act,
       val? *(SANE_Word *)val : 0, info? *info : 0);
  return SANE_STATUS_GOOD;
}
Example #22
0
/*
 * Check all filesystems in /etc/fstab with a fs_passno > 0
 */
static int fsck(int pass)
{
//	int save;
	struct fstab *fs;

	if (!setfsent()) {
		_pe("Failed opening fstab");
		return 1;
	}

//	if ((save = log_is_debug()))
//		log_debug();

	while ((fs = getfsent())) {
		char cmd[80];
		struct stat st;

		if (fs->fs_passno != pass)
			continue;

		errno = 0;
		if (stat(fs->fs_spec, &st) || !S_ISBLK(st.st_mode)) {
			if (!string_match(fs->fs_spec, "UUID=") && !string_match(fs->fs_spec, "LABEL=")) {
				_d("Cannot fsck %s, not a block device: %s", fs->fs_spec, strerror(errno));
				continue;
			}
		}

		if (fismnt(fs->fs_file)) {
			_d("Skipping fsck of %s, already mounted on %s.", fs->fs_spec, fs->fs_file);
			continue;
		}

		snprintf(cmd, sizeof(cmd), "fsck -a %s", fs->fs_spec);
		run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
	}

//	if (save)
//		log_debug();
	endfsent();

	return 0;
}
Example #23
0
/* user_match - match a username against one token */
static bool user_match (const char *tok, const char *string)
{
	struct group *group;

#ifdef PRIMARY_GROUP_MATCH
	struct passwd *userinf;
#endif
	char *at;

	/*
	 * If a token has the magic value "ALL" the match always succeeds.
	 * Otherwise, return true if the token fully matches the username, or if
	 * the token is a group that contains the username.
	 */
	at = strchr (tok + 1, '@');
	if (NULL != at) {	/* split user@host pattern */
		*at = '\0';
		return (   user_match (tok, string)
		        && from_match (at + 1, myhostname ()));
#if HAVE_INNETGR
	} else if (tok[0] == '@') {	/* netgroup */
		return (netgroup_match (tok + 1, (char *) 0, string));
#endif
	} else if (string_match (tok, string)) {	/* ALL or exact match */
		return true;
	/* local, no need for xgetgrnam */
	} else if ((group = getgrnam (tok)) != NULL) {	/* try group membership */
		int i;
		for (i = 0; NULL != group->gr_mem[i]; i++) {
			if (strcasecmp (string, group->gr_mem[i]) == 0) {
				return true;
			}
		}
#ifdef PRIMARY_GROUP_MATCH
		/*
		 * If the string is an user whose initial GID matches the token,
		 * accept it. May avoid excessively long lines in /etc/group.
		 * Radu-Adrian Feurdean <*****@*****.**>
		 *
		 * XXX - disabled by default for now.  Need to verify that
		 * getpwnam() doesn't have some nasty side effects.  --marekm
		 */
		/* local, no need for xgetpwnam */
		userinf = getpwnam (string);
		if (NULL != userinf) {
			if (userinf->pw_gid == group->gr_gid) {
				return true;
			}
		}
#endif
	}
	return false;
}
Example #24
0
/*
 * Older OF's require that when claiming a specific range of addresses,
 * we claim the physical space in the /memory node and the virtual
 * space in the chosen mmu node, and then do a map operation to
 * map virtual to physical.
 */
static int check_of_version(void)
{
	phandle oprom;
	char version[20];

	oprom = of1275_finddevice("/openprom");
	if (oprom == (phandle) (-1))
		return 0;
	if (of1275_getprop(oprom, "model", version, sizeof(version)) <= 0)
		return 0;
	if (!string_match(version, "Open Firmware, 1.")
	    && !string_match(version, "FirmWorks,3."))
		return 0;
	memory = (ihandle) call_prom("open", 1, 1, "/memory");
	if (memory == (ihandle) (-1)) {
		memory = (ihandle) call_prom("open", 1, 1, "/memory@0");
		if (memory == (ihandle) (-1))
			return 0;
	}
	return 1;
}
Example #25
0
mst_Boolean
string_match (char *pattern,
	      char *string,
	      int plen,
	      int slen)
{
  int i;

  for (;;)
    {
      /* If the string has ended, try to match trailing *'s in the
	 pattern.  */
      if (slen == 0)
	{
	  while (plen > 0 && *pattern == '*')
	    pattern++, plen--;

	  return (plen == 0);
	}

      /* If the pattern has ended, fail, because we know that slen > 0.  */
      if (plen == 0)
	return (false);

      switch (*pattern)
	{
	case '*':
	  /* Skip multiple * wildcards, they don't matter.  */
	  do
	    pattern++, plen--;
	  while (*pattern == '*');

	  /* Try to be greedy at first, then try shorter matches.  */
	  for (i = slen; i > 0; i--)
	    if (string_match (pattern, string + i, plen, slen - i))
	      return (true);

	  /* Continue with a void match for the *'s.  */
	  break;

	default:
	  /* Not a wildcard, match a single character.  */
	  if (*pattern != *string)
	    return (false);

	  /* fall through */

	case '#':
	  pattern++, string++, plen--, slen--;
	  break;
	}
    }
}
Example #26
0
File: peg.c Project: ctelfer/catlib
static int parse_def(struct peg_grammar_parser *pgp, struct peg_cursor *pc,
		     int *idp)
{
	struct peg_grammar *peg = pgp->peg;
	struct peg_cursor npc = *pc;
	int id = -1;
	int expr = -1;
	int def = -1;
	struct peg_node *pn;
	int rv;

	rv = parse_id(pgp, &npc, &id);
	if ( rv <= 0 )
		return rv;

	if ( NODE(peg, id)->pi_def >= 0 ) {
		pgp->err = PEG_ERR_DUP_DEF;
		pgp->eloc = *pc;
		return -1;
	}

	if ( !string_match(pgp, "<-", &npc) ) {
		peg_node_free(peg, id);
		return 0;
	}

	if ( (rv = parse_expr(pgp, &npc, &expr)) <= 0 ) {
		if ( rv == 0 )
			pgp->err = PEG_ERR_BAD_DEF;
		pgp->eloc = npc;
		peg_node_free(peg, id);
		return -1;
	}

	def = peg_node_new(peg, PEG_DEFINITION, pc->line);
	if ( def < 0 ) {
		peg_node_free(peg, id);
		peg_node_free(peg, expr);
		pgp->err = PEG_ERR_NOMEM;
		return -1;
	}

	pn = NODE(peg, def);
	pn->pd_id = id;
	pn->pd_expr = expr;
	pn = NODE(peg, id);
	pn->pi_def = def;

	*pc = npc;
	if ( idp != NULL )
		*idp = id;
	return 1;
}
Example #27
0
static int run_test(char *arg)
{
	int op = -1;
	struct { char *arg; int op; } opts[] = {
		{ "complete-cycle",    200 },
		{ "disable-enable",    201 },
		{ "false-ack",         202 },
		{ "false-unsubscribe", 203 },
		{ "failed-kick",       204 },
		{ "no-kick",           205 },
		{ "premature-trigger", 206 },
		{ NULL, 0 }
	};

	for (int i = 0; opts[i].arg; i++) {
		if (string_match(opts[i].arg, arg)) {
			op = opts[i].op;
			break;
		}
	}

	switch (op) {
		case 200:
			return testit();

		case 201:
			disable_enable = 1;
			return testit();

		case 202:
			false_ack = 1;
			return testit();

		case 203:
			false_unsubscribe = 1;
			return testit();

		case 204:
			failed_kick = 1;
			return testit();

		case 205:
			no_kick = 1;
			return testit();

		case 206:
			premature = 1;
			return testit();
	}

	return -1;
}
irom static app_action_t application_function_wlan_mode(const string_t *src, string_t *dst)
{
	if(parse_string(1, src, dst) != parse_ok)
	{
		string_cat(dst, "wlan-mode: supply mode: client or ap\n");
		return(app_action_error);
	}

	if(string_match(dst, "client"))
	{
		string_clear(dst);
		config.wlan_mode = config_wlan_mode_client;

		if(!wlan_init())
		{
			string_cat(dst, "wlan-mode: invalid mode\n");
			return(app_action_error);
		}

		return(app_action_disconnect);
	}

	if(string_match(dst, "ap"))
	{
		string_clear(dst);
		config.wlan_mode = config_wlan_mode_ap;

		if(!wlan_init())
		{
			string_cat(dst, "wlan-mode: invalid mode\n");
			return(app_action_error);
		}

		return(app_action_disconnect);
	}

	string_cat(dst, ": invalid wlan mode\n");
	return(app_action_error);
}
Example #29
0
void
upgrade_weechat_remove_file_cb (void *data, const char *filename)
{
    /* make C compiler happy */
    (void) data;

    if (string_match (filename, "*.upgrade", 1))
    {
        if (weechat_debug_core >= 2)
            gui_chat_printf (NULL, _("debug: removing file: %s"), filename);
        unlink (filename);
    }
}
Example #30
0
static int check_of_version(void)
{
	phandle oprom, chosen;
	char version[64];

	oprom = of_finddevice("/openprom");
	if (oprom == (phandle) -1)
		return 0;
	if (of_getprop(oprom, "model", version, sizeof(version)) <= 0)
		return 0;
	version[sizeof(version)-1] = 0;
	printf("OF version = '%s'\r\n", version);
	if (!string_match(version, "Open Firmware, 1.")
	    && !string_match(version, "FirmWorks,3."))
		return 0;
	chosen = of_finddevice("/chosen");
	if (chosen == (phandle) -1) {
		chosen = of_finddevice("/chosen@0");
		if (chosen == (phandle) -1) {
			printf("no chosen\n");
			return 0;
		}
	}
	if (of_getprop(chosen, "mmu", &chosen_mmu, sizeof(chosen_mmu)) <= 0) {
		printf("no mmu\n");
		return 0;
	}
	memory = (ihandle) of_call_prom("open", 1, 1, "/memory");
	if (memory == (ihandle) -1) {
		memory = (ihandle) of_call_prom("open", 1, 1, "/memory@0");
		if (memory == (ihandle) -1) {
			printf("no memory node\n");
			return 0;
		}
	}
	printf("old OF detected\r\n");
	return 1;
}