示例#1
0
static dlist *
config_parse(char *config)
{
	regex_t re_section, re_empty, re_entry;
	regmatch_t matches[5];
	char line[8192], *section = 0;
	int ix = 0, l_ix = 0;
	dlist *new_config = 0;
	
	regcomp(&re_section, "^[[:space:]]*\\[[[:space:]]*([[:alnum:]]*?)[[:space:]]*\\][[:space:]]*$", REG_EXTENDED);
	regcomp(&re_empty, "^[[:space:]]*#|^[[:space:]]*$", REG_EXTENDED);
	regcomp(&re_entry, "^[[:space:]]*([[:alnum:]]+)[[:space:]]*=[[:space:]]*(.*?)[[:space:]]*$", REG_EXTENDED);
	
	while(1)
	{
		if((config[ix] == '\0' || config[ix] == '\n'))
		{
			line[l_ix] = 0;
			if(regexec(&re_empty, line, 5, matches, 0) == 0) {
				/* do nothing */
			} else if(regexec(&re_section, line, 5, matches, 0) == 0) {
				if(section)
					free(section);
				section = copy_match(line, &matches[1]);
			} else if(section && regexec(&re_entry, line, 5, matches, 0) == 0) {
				char *key = copy_match(line, &matches[1]),
				     *value = copy_match(line, &matches[2]);
				new_config = entry_set(new_config, section, key, value);
			} else  {
				fprintf(stderr, "WARNING: Ignoring invalid line: %s\n", line);
			}
			l_ix = 0;
		} else {
			line[l_ix] = config[ix];
			l_ix++;
		}
		if(config[ix] == 0)
			break;
		++ix;
	}
	
	if(section)
		free(section);
	
	regfree(&re_section);
	regfree(&re_empty);
	regfree(&re_entry);
	
	return new_config;
}
示例#2
0
flux_msg_handler_t *flux_msg_handler_create (flux_t h,
                                             const struct flux_match match,
                                             flux_msg_handler_f cb, void *arg)
{
    struct dispatch *d = dispatch_get (h);
    flux_msg_handler_t *w = xzmalloc (sizeof (*w));

    w->magic = HANDLER_MAGIC;
    copy_match (&w->match, match);
    w->fn = cb;
    w->arg = arg;
    w->d = d;
    dispatch_usecount_incr (d);

    return w;
}
示例#3
0
int flux_sleep_on (flux_t h, struct flux_match match)
{
    struct dispatch *d = dispatch_get (h);
    int rc = -1;

    if (!d->current || !d->current->coproc) {
        errno = EINVAL;
        goto done;
    }
    flux_msg_handler_t *w = d->current;
    copy_match (&w->wait_match, match);
    if (zlist_append (d->waiters, w) < 0)
        oom ();
    if (coproc_yield (w->coproc) < 0)
        goto done;
    rc = 0;
done:
    return rc;
}