コード例 #1
0
ファイル: fast-export.c プロジェクト: 7sOddities/git
static const char *find_encoding(const char *begin, const char *end)
{
	const char *needle = "\nencoding ";
	char *bol, *eol;

	bol = memmem(begin, end ? end - begin : strlen(begin),
		     needle, strlen(needle));
	if (!bol)
		return git_commit_encoding;
	bol += strlen(needle);
	eol = strchrnul(bol, '\n');
	*eol = '\0';
	return bol;
}
コード例 #2
0
ファイル: fast-export.c プロジェクト: PKRoma/git-for-windows
/*
 * We anonymize each component of a path individually,
 * so that paths a/b and a/c will share a common root.
 * The paths are cached via anonymize_mem so that repeated
 * lookups for "a" will yield the same value.
 */
static void anonymize_path(struct strbuf *out, const char *path,
			   struct hashmap *map,
			   void *(*generate)(const void *, size_t *))
{
	while (*path) {
		const char *end_of_component = strchrnul(path, '/');
		size_t len = end_of_component - path;
		const char *c = anonymize_mem(map, generate, path, &len);
		strbuf_add(out, c, len);
		path = end_of_component;
		if (*path)
			strbuf_addch(out, *path++);
	}
}
コード例 #3
0
static GList*
split_string_on_char(const char *str, char ch)
{
    GList *list = NULL;
    for (;;)
    {
        const char *delim = strchrnul(str, ch);
        list = g_list_prepend(list, xstrndup(str, delim - str));
        if (*delim == '\0')
            break;
        str = delim + 1;
    }
    return g_list_reverse(list);
}
コード例 #4
0
ファイル: log-tree.c プロジェクト: NitzanDavari/ios-perl
static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
{
    const char *color, *reset, *eol;

    color = diff_get_color_opt(&opt->diffopt,
                               status ? DIFF_WHITESPACE : DIFF_FRAGINFO);
    reset = diff_get_color_opt(&opt->diffopt, DIFF_RESET);
    while (*bol) {
        eol = strchrnul(bol, '\n');
        printf("%s%.*s%s%s", color, (int)(eol - bol), bol, reset,
               *eol ? "\n" : "");
        bol = (*eol) ? (eol + 1) : eol;
    }
}
コード例 #5
0
ファイル: qnikst.c プロジェクト: dim13/lor-contest
char *
undebugq3(char *in, char *needle)
{
	char *p = NULL;
	char *pt = in -1;// temporary pointer
	do {
        p = pt + 1;
		if ((pt = strmatch(p, needle)) != NULL) {
			if (*pt == ' ') {
                char *ip   = pt + 1;
                char *ipt  = NULL;
                size_t nsize = pt - p;
                do {
                  ipt = strchrnul(ip,' ');
                  if (*ipt == ' ') {
                    if ( backcmp(ipt - nsize, needle, nsize) ) {
                      ip = ipt;
                      continue;
                    } else {
                      user_memmove(p, pt+1, ipt-pt-1-nsize);
                      p += ipt-pt-1-nsize;
                      ip = ipt+1;
                      pt = ipt;
                      continue;
                    }
                  }
                  if (*ipt == '\0') {
                     if ( backcmp(ipt - nsize, needle, nsize) ) {
                        user_memmove(p, pt+1, ipt-pt);
                     } else {
                        user_memmove(p, pt+1, ipt - pt - nsize - 1);
                        p += ipt - pt - nsize - 1;
                        *p = '\0';
                     }
                     return in;
                  }
                } while(*(ip++));
                return in;
			} 
			if (*pt == '\0') {
				*p = '\0';
				return in;
			}
			p = pt;
		}
		pt = strchr(p, ' ');
	} while (pt);
	return in;
}
コード例 #6
0
enum debug_flag_t debug_flags_from_string(enum debug_flag_t initial,
                                          const _TCHAR * source_name,
                                          const _TCHAR * str)
{
     enum debug_flag_t rc = initial;

     while (str)
     {
          if (*str == _T('\0'))
               break;

          const char *envtokend = strchrnul(str, ',');

          bool found = false;
          bool remove = false;

          if ((str[0] == '-') || (str[0] == '+'))
          {
               remove = (str[0] == '-');
               str++;
          }

          for (size_t ii = 0; debug_flag_env_names[ii].df_env_name; ii++)
          {
               if (strncasecmp(str, debug_flag_env_names[ii].df_env_name, envtokend - str) == 0)
               {
                    found = true;

                    if (remove)
                         rc = (enum debug_flag_t) (rc & ~debug_flag_env_names[ii].df);
                    else
                         rc = (enum debug_flag_t) (rc | debug_flag_env_names[ii].df);

                    break;
               }
          }

          if (!found)
          {
               dscwritef(DF_ALWAYS, ("Unknown debug flag while parsing ~cs, starting here: ~cs\n", source_name, str));
               show_debug_flags();
               panic("Aborting Run");
          }

          str = (char *) ((*envtokend == '\0') ? NULL : envtokend + 1);
     }

     return rc;
}
コード例 #7
0
ファイル: reported_to.c プロジェクト: scottgfhong/libreport
static void foreach_reported_to_line(const char *reported_to, foreach_reported_to_line_cb_type callback, void *user_data)
{
    const char *p = reported_to;
    unsigned lineno = 0;
    while (*p)
    {
        ++lineno;

        const char *record = p;
        const char *record_label_end = strchrnul(p, ':');
        const size_t label_len = record_label_end - p;
        const char *record_end = strchrnul(p, '\n');

        p = record_end + (record_end[0] != '\0');

        if (label_len == 0 || record_label_end[0] == '\0' || record_end < record_label_end)
        {
            log_notice("Miss formatted 'reported_to' record on line %d", lineno);
            continue;
        }

        callback(record, label_len, user_data);
    }
}
コード例 #8
0
ファイル: utf8.c プロジェクト: Advael/git
static void strbuf_add_indented_text(struct strbuf *buf, const char *text,
				     int indent, int indent2)
{
	if (indent < 0)
		indent = 0;
	while (*text) {
		const char *eol = strchrnul(text, '\n');
		if (*eol == '\n')
			eol++;
		strbuf_addchars(buf, ' ', indent);
		strbuf_add(buf, text, eol - text);
		text = eol;
		indent = indent2;
	}
}
コード例 #9
0
ファイル: qnikst.c プロジェクト: dim13/lor-contest
char *
undebugq2(char *in, char *needle)
{
	char *p = NULL;
	char *pt = in-1;  // temporary pointer
	do {
        p = pt + 1;
		if ((pt = strmatch(p, needle)) != NULL) {
			if (*pt == ' ') {
                char *ip   = pt + 1;
                char *ipt  = NULL;
                do {
                  if ((ipt = strmatch(ip, needle)) != NULL) {
                    if (*ipt == ' ') {
                        user_memmove(p, pt+1, ip-pt-1);
                        p += ip-pt-1;
                        ip = ipt+1;
                        pt = ipt;
                    }
                    if (*ipt == '\0') {
                        if (ip - pt - 1) {
                          user_memmove(p, pt+1, ip-pt-1);
                          p += ip-pt-2;
                        }
                        *p = '\0';
                        return in;
                    }
                    ip = ipt;
                  }
                  ip   = strchrnul(ip, ' ');
                  if (!(*ip)) {
                      user_memmove(p, pt+1, ip-pt);
                      return in;
                  } 
                  ip++;
                } while (*ip);
                return in;
			} 
			if (*pt == '\0') {
				*p = '\0';
				return in;
			}
			p = pt;
		}
		pt = strchr(p, ' ');
	} while (pt);
	return in;
}
コード例 #10
0
ファイル: exec.cpp プロジェクト: eccstartup/darling
static const char* findInPath(const char* file)
{
	static __thread char buffer[DARWIN_MAXPATHLEN];
	
	if (*file == '/')
		return file;
	
	if (strchr(file, '/') != 0)
	{
		// No PATH resolution, only fix the case
		strcpy(buffer, file);
		translatePathCI(buffer);
		return buffer;
	}
	
	const char* path = getenv("PATH");
	if (!path)
	{
		// Get the default path.
		size_t len = confstr(_CS_PATH, 0, 0);
		char* buf = reinterpret_cast<char*>( alloca(len + 1) );
		buf[0] = ':';
		
		confstr(_CS_PATH, buf + 1, len);
		
		path = buf;
	}

	const char* p = path;
	do
	{
		const char* end = strchrnul(p, ':');
		size_t len = end-p;
		memcpy(buffer, p, len);
		if (buffer[len-1] != '/')
			buffer[len++] = '/';
		
		strcpy(buffer+len, file);
		
		translatePathCI(buffer);
		
		if (::access(buffer, X_OK) == 0)
			return buffer;
	}
	while (*p++);

	return 0;
}
コード例 #11
0
static void http_auth_init(const char *url)
{
	char *at, *colon, *cp, *slash, *decoded;
	int len;

	cp = strstr(url, "://");
	if (!cp)
		return;

	/*
	 * Ok, the URL looks like "proto://something".  Which one?
	 * "proto://<user>:<pass>@<host>/...",
	 * "proto://<user>@<host>/...", or just
	 * "proto://<host>/..."?
	 */
	cp += 3;
	at = strchr(cp, '@');
	colon = strchr(cp, ':');
	slash = strchrnul(cp, '/');
	if (!at || slash <= at)
		return; /* No credentials */
	if (!colon || at <= colon) {
		/* Only username */
		len = at - cp;
		user_name = xmalloc(len + 1);
		memcpy(user_name, cp, len);
		user_name[len] = '\0';
		decoded = url_decode(user_name);
		free(user_name);
		user_name = decoded;
		user_pass = NULL;
	} else {
		len = colon - cp;
		user_name = xmalloc(len + 1);
		memcpy(user_name, cp, len);
		user_name[len] = '\0';
		decoded = url_decode(user_name);
		free(user_name);
		user_name = decoded;
		len = at - (colon + 1);
		user_pass = xmalloc(len + 1);
		memcpy(user_pass, colon + 1, len);
		user_pass[len] = '\0';
		decoded = url_decode(user_pass);
		free(user_pass);
		user_pass = decoded;
	}
}
コード例 #12
0
ファイル: ws.c プロジェクト: foggg7777/git
unsigned parse_whitespace_rule(const char *string)
{
	unsigned rule = WS_DEFAULT_RULE;

	while (string) {
		int i;
		size_t len;
		const char *ep;
		int negated = 0;

		string = string + strspn(string, ", \t\n\r");
		ep = strchrnul(string, ',');
		len = ep - string;

		if (*string == '-') {
			negated = 1;
			string++;
			len--;
		}
		if (!len)
			break;
		for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++) {
			if (strncmp(whitespace_rule_names[i].rule_name,
				    string, len))
				continue;
			if (negated)
				rule &= ~whitespace_rule_names[i].rule_bits;
			else
				rule |= whitespace_rule_names[i].rule_bits;
			break;
		}
		if (strncmp(string, "tabwidth=", 9) == 0) {
			unsigned tabwidth = atoi(string + 9);
			if (0 < tabwidth && tabwidth < 0100) {
				rule &= ~WS_TAB_WIDTH_MASK;
				rule |= tabwidth;
			}
			else
				warning("tabwidth %.*s out of range",
					(int)(len - 9), string + 9);
		}
		string = ep;
	}

	if (rule & WS_TAB_IN_INDENT && rule & WS_INDENT_WITH_NON_TAB)
		die("cannot enforce both tab-in-indent and indent-with-non-tab");
	return rule;
}
コード例 #13
0
ファイル: mailmap.c プロジェクト: 00027jang27/git
static void read_mailmap_buf(struct string_list *map,
			     const char *buf, unsigned long len,
			     char **repo_abbrev)
{
	while (len) {
		const char *end = strchrnul(buf, '\n');
		unsigned long linelen = end - buf + 1;
		char *line = xmemdupz(buf, linelen);

		read_mailmap_line(map, line, repo_abbrev);

		free(line);
		buf += linelen;
		len -= linelen;
	}
}
コード例 #14
0
ファイル: strchrnul.c プロジェクト: charlie-wong/wlc
int main(void)
{
	char string[N];
	char c;

	printf("Input a string!\n");
	gets(string);
	printf("Input a character to look up for!\n");
	scanf("%c",&c);

	char *rp = strchrnul(string,c);

	printf("The 1th character '%c' that found, the next character is '%c'\n",*rp,*(rp+1));

	return 0;
}
コード例 #15
0
bool is_in_comma_separated_list(const char *value, const char *list)
{
    if (!list)
        return false;
    unsigned len = strlen(value);
    while (*list)
    {
        const char *comma = strchrnul(list, ',');
        if ((comma - list == len) && strncmp(value, list, len) == 0)
            return true;
        if (!*comma)
            break;
        list = comma + 1;
    }
    return false;
}
コード例 #16
0
ファイル: http_cookies.c プロジェクト: chinnurtb/ribs2
static inline void add_cookie(struct hashtable *ht, const char *str) {
    const char *name = str;
    const char *name_end = strchrnul(str, '=');
    const char *val = *name_end ? name_end + 1 : name_end;

    /* get rid of quotes */
    const char *val_st = val, *val_st_end = val + strlen(val);
    if ('"' == *val_st)
        ++val_st;
    if (val_st != val_st_end && '"' == *(val_st_end - 1))
        --val_st_end;

    size_t l = val_st_end - val_st;
    uint32_t loc = hashtable_insert(ht, name, name_end - name, val_st, l + 1);
    *(char *)(hashtable_get_val(ht, loc) + l) = 0;
}
コード例 #17
0
ファイル: logging.c プロジェクト: dirkmueller/pacemaker
static void
crm_log_filter(struct qb_log_callsite *cs)
{
    int lpc = 0;
    static int need_init = 1;
    static const char *trace_fns = NULL;
    static const char *trace_tags = NULL;
    static const char *trace_fmts = NULL;
    static const char *trace_files = NULL;
    static const char *trace_blackbox = NULL;

    if (need_init) {
        need_init = 0;
        trace_fns = getenv("PCMK_trace_functions");
        trace_fmts = getenv("PCMK_trace_formats");
        trace_tags = getenv("PCMK_trace_tags");
        trace_files = getenv("PCMK_trace_files");
        trace_blackbox = getenv("PCMK_trace_blackbox");

        if (trace_tags != NULL) {
            uint32_t tag;
            char token[500];
            const char *offset = NULL;
            const char *next = trace_tags;

            do {
                offset = next;
                next = strchrnul(offset, ',');
                snprintf(token, 499, "%.*s", (int)(next - offset), offset);

                tag = g_quark_from_string(token);
                crm_info("Created GQuark %u from token '%s' in '%s'", tag, token, trace_tags);

                if (next[0] != 0) {
                    next++;
                }

            } while (next != NULL && next[0] != 0);
        }
    }

    cs->targets = 0;            /* Reset then find targets to enable */
    for (lpc = QB_LOG_SYSLOG; lpc < QB_LOG_TARGET_MAX; lpc++) {
        crm_log_filter_source(lpc, trace_files, trace_fns, trace_fmts, trace_tags, trace_blackbox,
                              cs);
    }
}
コード例 #18
0
ファイル: rerere.c プロジェクト: LittleForker/git
static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
{
	struct rerere_io_mem *io = (struct rerere_io_mem *)io_;
	char *ep;
	size_t len;

	strbuf_release(sb);
	if (!io->input.len)
		return -1;
	ep = strchrnul(io->input.buf, '\n');
	if (*ep == '\n')
		ep++;
	len = ep - io->input.buf;
	strbuf_add(sb, io->input.buf, len);
	strbuf_remove(&io->input, 0, len);
	return 0;
}
コード例 #19
0
ファイル: pretty.c プロジェクト: Advael/git
static void parse_signature_lines(struct format_commit_context *ctx)
{
	const char *buf = ctx->signature.gpg_output;
	int i;

	for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
		const char *found = strstr(buf, signature_check[i].check);
		const char *next;
		if (!found)
			continue;
		ctx->signature.good_bad = signature_check[i].result;
		found += strlen(signature_check[i].check);
		next = strchrnul(found, '\n');
		ctx->signature.signer = xmemdupz(found, next - found);
		break;
	}
}
コード例 #20
0
ファイル: cache-tree.c プロジェクト: 9b/git
static int do_invalidate_path(struct cache_tree *it, const char *path)
{
	/* a/b/c
	 * ==> invalidate self
	 * ==> find "a", have it invalidate "b/c"
	 * a
	 * ==> invalidate self
	 * ==> if "a" exists as a subtree, remove it.
	 */
	const char *slash;
	int namelen;
	struct cache_tree_sub *down;

#if DEBUG
	fprintf(stderr, "cache-tree invalidate <%s>\n", path);
#endif

	if (!it)
		return 0;
	slash = strchrnul(path, '/');
	namelen = slash - path;
	it->entry_count = -1;
	if (!*slash) {
		int pos;
		pos = subtree_pos(it, path, namelen);
		if (0 <= pos) {
			cache_tree_free(&it->down[pos]->cache_tree);
			free(it->down[pos]);
			/* 0 1 2 3 4 5
			 *       ^     ^subtree_nr = 6
			 *       pos
			 * move 4 and 5 up one place (2 entries)
			 * 2 = 6 - 3 - 1 = subtree_nr - pos - 1
			 */
			memmove(it->down+pos, it->down+pos+1,
				sizeof(struct cache_tree_sub *) *
				(it->subtree_nr - pos - 1));
			it->subtree_nr--;
		}
		return 1;
	}
	down = find_subtree(it, path, namelen, 0);
	if (down)
		do_invalidate_path(down->cache_tree, slash + 1);
	return 1;
}
コード例 #21
0
ファイル: ima_template.c プロジェクト: 19Dan01/linux
static int template_desc_init_fields(const char *template_fmt,
				     struct ima_template_field ***fields,
				     int *num_fields)
{
	const char *template_fmt_ptr;
	struct ima_template_field *found_fields[IMA_TEMPLATE_NUM_FIELDS_MAX];
	int template_num_fields = template_fmt_size(template_fmt);
	int i, len;

	if (template_num_fields > IMA_TEMPLATE_NUM_FIELDS_MAX) {
		pr_err("format string '%s' contains too many fields\n",
		       template_fmt);
		return -EINVAL;
	}

	for (i = 0, template_fmt_ptr = template_fmt; i < template_num_fields;
	     i++, template_fmt_ptr += len + 1) {
		char tmp_field_id[IMA_TEMPLATE_FIELD_ID_MAX_LEN + 1];

		len = strchrnul(template_fmt_ptr, '|') - template_fmt_ptr;
		if (len == 0 || len > IMA_TEMPLATE_FIELD_ID_MAX_LEN) {
			pr_err("Invalid field with length %d\n", len);
			return -EINVAL;
		}

		memcpy(tmp_field_id, template_fmt_ptr, len);
		tmp_field_id[len] = '\0';
		found_fields[i] = lookup_template_field(tmp_field_id);
		if (!found_fields[i]) {
			pr_err("field '%s' not found\n", tmp_field_id);
			return -ENOENT;
		}
	}

	if (fields && num_fields) {
		*fields = kmalloc_array(i, sizeof(*fields), GFP_KERNEL);
		if (*fields == NULL)
			return -ENOMEM;

		memcpy(*fields, found_fields, i * sizeof(*fields));
		*num_fields = i;
	}

	return 0;
}
コード例 #22
0
ファイル: virdnsmasq.c プロジェクト: Archer-sys/libvirt
static int
dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf)
{
    const char *p;

    caps->noRefresh = true;

    p = STRSKIP(buf, DNSMASQ_VERSION_STR);
    if (!p)
       goto fail;
    virSkipSpaces(&p);
    if (virParseVersionString(p, &caps->version, true) < 0)
        goto fail;

    if (strstr(buf, "--bind-dynamic"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_BIND_DYNAMIC);

    /* if this string is a part of the --version output, dnsmasq
     * has been patched to use SO_BINDTODEVICE when listening,
     * so that it will only accept requests that arrived on the
     * listening interface(s)
     */
    if (strstr(buf, "--bind-interfaces with SO_BINDTODEVICE"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_BINDTODEVICE);

    if (strstr(buf, "--ra-param"))
        dnsmasqCapsSet(caps, DNSMASQ_CAPS_RA_PARAM);

    VIR_INFO("dnsmasq version is %d.%d, --bind-dynamic is %spresent, "
             "SO_BINDTODEVICE is %sin use, --ra-param is %spresent",
             (int)caps->version / 1000000,
             (int)(caps->version % 1000000) / 1000,
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_BIND_DYNAMIC) ? "" : "NOT ",
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_BINDTODEVICE) ? "" : "NOT ",
             dnsmasqCapsGet(caps, DNSMASQ_CAPS_RA_PARAM) ? "" : "NOT ");
    return 0;

 fail:
    p = strchrnul(buf, '\n');
    virReportError(VIR_ERR_INTERNAL_ERROR,
                   _("cannot parse %s version number in '%.*s'"),
                   caps->binaryPath, (int) (p - buf), buf);
    return -1;

}
コード例 #23
0
ファイル: fmt-merge-msg.c プロジェクト: CCorreia/git
static void add_branch_desc(struct strbuf *out, const char *name)
{
	struct strbuf desc = STRBUF_INIT;

	if (!read_branch_desc(&desc, name)) {
		const char *bp = desc.buf;
		while (*bp) {
			const char *ep = strchrnul(bp, '\n');
			if (*ep)
				ep++;
			strbuf_addf(out, "  : %.*s", (int)(ep - bp), bp);
			bp = ep;
		}
		if (out->buf[out->len - 1] != '\n')
			strbuf_addch(out, '\n');
	}
	strbuf_release(&desc);
}
コード例 #24
0
ファイル: parsing.c プロジェクト: tim-nordell-lpd/cgit
static void parse_user(const char *t, char **name, char **email, unsigned long *date, int *tz)
{
	struct ident_split ident;
	unsigned email_len;

	if (!split_ident_line(&ident, t, strchrnul(t, '\n') - t)) {
		*name = substr(ident.name_begin, ident.name_end);

		email_len = ident.mail_end - ident.mail_begin;
		*email = xmalloc(strlen("<") + email_len + strlen(">") + 1);
		sprintf(*email, "<%.*s>", email_len, ident.mail_begin);

		if (ident.date_begin)
			*date = strtoul(ident.date_begin, NULL, 10);
		if (ident.tz_begin)
			*tz = atoi(ident.tz_begin);
	}
}
コード例 #25
0
ファイル: advice.c プロジェクト: LinTeX9527/git
void advise(const char *advice, ...)
{
	struct strbuf buf = STRBUF_INIT;
	va_list params;
	const char *cp, *np;

	va_start(params, advice);
	strbuf_vaddf(&buf, advice, params);
	va_end(params);

	for (cp = buf.buf; *cp; cp = np) {
		np = strchrnul(cp, '\n');
		fprintf(stderr,	_("hint: %.*s\n"), (int)(np - cp), cp);
		if (*np)
			np++;
	}
	strbuf_release(&buf);
}
コード例 #26
0
ファイル: branch.c プロジェクト: KarthikNayak/git
static const char *quote_literal_for_format(const char *s)
{
	static struct strbuf buf = STRBUF_INIT;

	strbuf_reset(&buf);
	while (*s) {
		const char *ep = strchrnul(s, '%');
		if (s < ep)
			strbuf_add(&buf, s, ep - s);
		if (*ep == '%') {
			strbuf_addstr(&buf, "%%");
			s = ep + 1;
		} else {
			s = ep;
		}
	}
	return buf.buf;
}
コード例 #27
0
bool is_in_comma_separated_list_of_glob_patterns(const char *value, const char *list)
{
    if (!list)
        return false;
    while (*list)
    {
        const char *comma = strchrnul(list, ',');
        char *pattern = xstrndup(list, comma - list);
        int match = !fnmatch(pattern, value, /*flags:*/ 0);
        free(pattern);
        if (match)
            return true;
        if (!*comma)
            break;
        list = comma + 1;
    }
    return false;
}
コード例 #28
0
ファイル: log.c プロジェクト: lkunemail/libqb
static int32_t
_cs_matches_filter_(struct qb_log_callsite *cs,
		    enum qb_log_filter_type type,
		    const char *text,
		    uint8_t high_priority,
		    uint8_t low_priority)
{
	int32_t match = QB_FALSE;

	if (cs->priority > low_priority ||
	    cs->priority < high_priority) {
		return QB_FALSE;
	}
	if (strcmp(text, "*") == 0) {
		return QB_TRUE;
	}
	if (type == QB_LOG_FILTER_FILE ||
	    type == QB_LOG_FILTER_FUNCTION) {
		char token[500];
		const char *offset = NULL;
		const char *next = text;

		do {
			offset = next;
			next = strchrnul(offset, ',');
			snprintf(token, 499, "%.*s", (int)(next - offset), offset);

			if (type == QB_LOG_FILTER_FILE) {
				match = (strstr(cs->filename, token) != NULL);
			} else {
				match = (strstr(cs->function, token) != NULL);
			}
			if (!match && next[0] != 0) {
				next++;
			}

		} while (match == QB_FALSE && next != NULL && next[0] != 0);
	} else if (type == QB_LOG_FILTER_FORMAT) {
		if (strstr(cs->format, text)) {
			match = QB_TRUE;
		}
	}
	return match;
}
コード例 #29
0
ファイル: cmdline.c プロジェクト: jollywho/nav
static void cmdline_tokenize(Cmdline *cmdline)
{
  char ch[] = {0,'\0'};
  int st, ed, pos;
  char *str = cmdline->line;
  bool esc = false;

  st = ed = pos = 0;
  for (;;) {
    ch[0] = str[pos++];
    if (ch[0] == '\0') {
      create_token(cmdline->tokens, str, st, ed, false);
      break;
    }
    else if (ch[0] == '\\' && !esc) {
      esc = true;
      continue;
    }
    else if ((ch[0] == '\"' || ch[0] == '\'') && !esc) {
      char *closech = strchrnul(&str[pos], ch[0]);
      if (closech[-1] != '\\') {
        int end = (closech - &str[pos]) + pos;
        bool quote = str[end] == '\0';
        pos = quote ? pos-1 : pos;
        create_token(cmdline->tokens, str, pos, end, !quote);
        st = pos = quote ? end : ++end;
      }
    }
    else if (strpbrk(ch, TOKENCHARS) && !esc) {
      create_token(cmdline->tokens, str, st, ed, false);
      if (*ch != ' ') {
        create_token(cmdline->tokens, str, pos-1, pos, false);
        ed = pos;
      }
      st = pos;
    }
    else
      ed = pos;

    esc = false;
  }

  cmdline->cont = esc;
}
コード例 #30
0
std::string find_executable (const std::string &exe)
{
	std::string result;
	if (exe.empty ()) {
		// Empty input. Return empty string
	}
	else if (memchr (exe.data (), '/', exe.length ())) {
		// exe is a full/relative pathname
		if (exe[0] == '~') {
			result = home_expand_pathname (exe);
		}
		else {
			result = exe;
		}
		if ((get_file_attr (result) & (FILE_ATTR_DIRECTORY|FILE_ATTR_EXECUTABLE))
				!= FILE_ATTR_EXECUTABLE) {
			result.clear ();
		}
	}
	else if (const char *path = getenv ("PATH")) {
		// exe is a "bare" filename
		for (;;) {
			const char *colon = strchrnul (path, ':');
			if (path == colon) {
				result = '.';
			}
			else {
				result.assign (path, colon);
			}
			result += '/';
			result += exe;
			if ((get_file_attr (result) & (FILE_ATTR_DIRECTORY|FILE_ATTR_EXECUTABLE))
					== FILE_ATTR_EXECUTABLE) {
				break;
			}
			if (*colon != ':') {
				result.clear ();
				break;
			}
			path = colon+1;
		}
	}
	return result;
}