Exemplo n.º 1
0
Arquivo: glob.c Projeto: muennich/rc3
extern List *glob(List *s) {
    List *top, *r;
    bool meta;
    s = expandtilde(s);
    for (r = s, meta = FALSE; r != NULL; r = r->n)
        if (r->m != NULL)
            meta = TRUE;
    if (!meta)
        return s; /* don't copy lists with no metacharacters in them */
    for (top = r = NULL; s != NULL; s = s->n) {
        if (s->m == NULL) { /* no metacharacters; just tack on to the return list */
            if (top == NULL)
                top = r = nnew(List);
            else
                r = r->n = nnew(List);
            r->w = s->w;
        } else {
            if (top == NULL)
                top = r = sort(doglob(s->w, s->m));
            else
                r->n = sort(doglob(s->w, s->m));
            while (r->n != NULL)
                r = r->n;
        }
    }
    r->n = NULL;
    return top;
}
Exemplo n.º 2
0
int parse() { token=getlex(); do { if (token <= 0) return 1;
    if (istoken('#')) {
      if (istoken(T_DEFINE)) dodefine();
      else if (istoken(T_INCLUDE)) doinclude();
      else error1("define oder include erwartet");
      } else{ typeName();  if (token=='(') dofunc();  else doglob(); } 
    } while(1); 
}
static int
matchfile(struct dirbuf *np, const char *fname, const char *pattern)
{
	struct dirbuf	name = *np;
	unsigned char	pc, fc;

	/* DEBUG(("* try \"%s\" ~ \"%s\"\n", fname, pattern)); */
	while (*pattern && *pattern != '/') {
		pc = *pattern++;
		fc = *fname;
		switch (pc) {
		case '?':
			if (!fc || !dirbuf_appendc(&name, fc))
				return 0;
			fname++;
			break;

		/* Match 0 or more characters. Try to match greedily
		 * i.e. as many characters as possible. */
		case '*': {
			struct dirbuf	temp;
			unsigned int	n, ok = 0;

			n = strlen(fname);
			do {
				temp = name;
				if (dirbuf_appends(&temp, fname, n)) {
					ok = matchfile(&temp, fname + n,
							pattern);
				}
			} while (!ok && n--);

			return ok;
			}

		/* Match character range */
		case LEFTBLOCKY: {
			unsigned char	from, to;
			int		ok = 0;

			if (fc == '\0')
				return 0;
			while (1) {
				to = from = *pattern++;
				if (from == RIGHTBLOCKY)
					break;
				if (from == '\0')
					return 0;

				if (*pattern == '-') {
					pattern++;
					to = *pattern++;
					if (to == '\0')
						return 0;
				}
				if (from <= fc && fc <= to)
					ok = 1;
			}
			if (!ok || !dirbuf_appendc(&name, fc))
				return 0;
			fname++;
			break;
			}

		case LEFTCURLY:
			/* Handle braces - icky ugly and bad */
			return dobraces(&name, fname, pattern);

		case '\\':
			if ((fc = *++fname) == '\0')
				return 0;
			/* fallthru */
		default:
			if (pc != fc || !dirbuf_appendc(&name, fc))
				return 0;
			fname++;
			break;
		}
	}

	/* Pattern exhausted - make sure we've matched the full
	 * filename! */
	if (*fname != '\0')
		return 0;

	return doglob(&name, pattern);
}
Exemplo n.º 4
0
static BUFFER *
gettagsfile(int n, int *endofpathflagp, int *did_read)
{
#ifdef MDCHK_MODTIME
    time_t current;
#endif
    char *tagsfile;
    BUFFER *tagbp;
    char tagbufname[NBUFN];
    char tagfilename[NFILEN];

    *endofpathflagp = FALSE;
    *did_read = FALSE;

    (void) lsprintf(tagbufname, TAGFILE_BufName, n + 1);

    /* is the buffer around? */
    if ((tagbp = find_b_name(tagbufname)) == NULL) {
	char *tagf = global_b_val_ptr(VAL_TAGS);

	nth_name(tagfilename, tagf, n);
	if (!doglob(tagfilename)
	    || tagfilename[0] == EOS) {
	    *endofpathflagp = TRUE;
	    return NULL;
	}

	/* look up the tags file */
	tagsfile = cfg_locate(tagfilename, LOCATE_TAGS);

	/* if it isn't around, don't sweat it */
	if (tagsfile == NULL) {
	    return NULL;
	}

	/* find the pointer to that buffer */
	if ((tagbp = bfind(tagbufname, BFINVS)) == NULL) {
	    mlforce("[Can't create tags buffer]");
	    return NULL;
	}

	if (readin(tagsfile, FALSE, tagbp, FALSE) != TRUE) {
	    zotbuf(tagbp);
	    return NULL;
	}
	*did_read = TRUE;
    }
#ifdef MDCHK_MODTIME
    /*
     * Re-read the tags buffer if we are checking modification-times and
     * find that the tags file's been changed. We check the global mode
     * value because it's too awkward to set the local mode value for a
     * scratch buffer.
     */
    if (global_b_val(MDCHK_MODTIME)
	&& get_modtime(tagbp, &current)
	&& tagbp->b_modtime != current) {
	if (!*did_read
	    && readin(tagbp->b_fname, FALSE, tagbp, FALSE) != TRUE) {
	    zotbuf(tagbp);
	    return NULL;
	}
	set_modtime(tagbp, tagbp->b_fname);
	*did_read = TRUE;
    }
#endif
    b_set_invisible(tagbp);
    return tagbp;
}