Example #1
0
void
globdir(uint8_t *p, uint8_t *namep)
{
	uint8_t *t, *newp;
	int f;
	/* scan the pattern looking for a component with a metacharacter in it */
	if(*p=='\0'){
		globv = newword(globname, globv);
		return;
	}
	t = namep;
	newp = p;
	while(*newp){
		if(*newp==GLOB)
			break;
		*t=*newp++;
		if(*t++=='/'){
			namep = t;
			p = newp;
		}
	}
	/* If we ran out of pattern, append the name if accessible */
	if(*newp=='\0'){
		*t='\0';
		if(access(globname, 0)==0)
			globv = newword(globname, globv);
		return;
	}
	/* read the directory and recur for any entry that matches */
	*namep='\0';
	if((f = Opendir(globname[0]?globname:"."))<0) return;
	while(*newp!='/' && *newp!='\0') newp++;
	while(Readdir(f, namep, *newp=='/')){
		if(matchfn(namep, p)){
			for(t = namep;*t;t++);
			globdir(newp, t);
		}
	}
	Closedir(f);
}
Example #2
0
File: mark.c Project: adsr/mlbuf
// Return the last occurrence of a match given a forward-searching matchfn
static char* mark_find_match_prev(char* haystack, bint_t haystack_len, bint_t look_offset, bint_t max_offset, mark_find_match_fn matchfn, void* u1, void* u2) {
    char* match;
    char* last_match;
    bint_t match_len;
    last_match = NULL;
    while (1) {
        match = matchfn(haystack, haystack_len, look_offset, max_offset, u1, u2, &match_len);
        if (match == NULL) {
            return last_match;
        }
        if (match - haystack > max_offset) {
            return last_match;
        }
        // Override match_len to 1. Reasoning: If we have a haystack like
        // 'banana' and our re is 'ana', using the actual match_len for the
        // next search offset would skip the 2nd 'ana' match.
        match_len = 1;
        look_offset = (bint_t)(match - haystack) + match_len;
        if (look_offset + match_len > haystack_len) {
            return match;
        }
        last_match = match;
    }
}