Beispiel #1
0
extern int
checkheader(
	FILE  *fin,
	char  *fmt,
	FILE  *fout
)
{
	struct check	cdat;
	char	*cp;

	cdat.fp = fout;
	cdat.fs[0] = '\0';
	if (getheader(fin, mycheck, &cdat) < 0)
		return(-1);
	if (!cdat.fs[0])
		return(0);
	for (cp = fmt; *cp; cp++)		/* check for globbing */
		if ((*cp == '?') | (*cp == '*')) {
			if (globmatch(fmt, cdat.fs)) {
				strcpy(fmt, cdat.fs);
				return(1);
			} else
				return(-1);
		}
	return(strcmp(fmt, cdat.fs) ? -1 : 1);	/* literal match */
}
static int
addhline(			/* add a line to our info. header */
	char	*s,
	void	*p
)
{
	char	fmt[MAXFMTLEN];
	int	n;

	if (formatval(fmt, s))
		fmterr += !globmatch(PICFMT, fmt);
	else if (!strncmp(s, "FRAME=", 6))
		frameno = atoi(s+6);
	n = strlen(s);
	if (headlen)
		headlines = (char *)realloc((void *)headlines, headlen+n+1);
	else
		headlines = (char *)malloc(n+1);
	if (headlines == NULL) {
		perror(progname);
		exit(1);
	}
	strcpy(headlines+headlen, s);
	headlen += n;
	return(0);
}
Beispiel #3
0
static bool match_namecheck(const struct strlist *strings, const char *name) {
	int i;

	for (i = 0 ; i < strings->count ; i++) {
		if (globmatch(name, strings->values[i]))
			return true;
	}
	return false;
}
Beispiel #4
0
extern int
globmatch(			/* check for match of s against pattern p */
	char	*p,
	char	*s
)
{
	int	setmatch;

	do {
		switch (*p) {
		case '?':			/* match any character */
			if (!*s++)
				return(0);
			break;
		case '*':			/* match any string */
			while (p[1] == '*') p++;
			do
				if ( (p[1]=='?') | (p[1]==*s) &&
						globmatch(p+1,s) )
					return(1);
			while (*s++);
			return(0);
		case '[':			/* character set */
			setmatch = *s == *++p;
			if (!*p)
				return(0);
			while (*++p != ']') {
				if (!*p)
					return(0);
				if (*p == '-') {
					setmatch += (p[-1] <= *s && *s <= p[1]);
					if (!*++p)
						break;
				} else
					setmatch += (*p == *s);
			}
			if (!setmatch)
				return(0);
			s++;
			break;
		case '\\':			/* literal next */
			p++;
		/* fall through */
		default:			/* normal character */
			if (*p != *s)
				return(0);
			s++;
			break;
		}
	} while (*p++);
	return(1);
}
Beispiel #5
0
static int
headline(			/* check header line & echo if requested */
	char	*s,
	void	*p
)
{
	char	fmt[32];
	double	d;
	COLOR	ctmp;

	if (isheadid(s))			/* header id */
		return(0);	/* don't echo */
	if (formatval(fmt, s)) {		/* check format */
		if (globmatch(ourfmt, fmt)) {
			wrongformat = 0;
			strcpy(ourfmt, fmt);
		} else
			wrongformat = globmatch(PICFMT, fmt) ? 1 : -1;
		return(0);	/* don't echo */
	}
	if (isexpos(s)) {			/* exposure */
		d = exposval(s);
		scalecolor(input[nfiles].expos, d);
	} else if (iscolcor(s)) {		/* color correction */
		colcorval(ctmp, s);
		multcolor(input[nfiles].expos, ctmp);
	} else if (isaspect(s))
		input[nfiles].pa *= aspectval(s);
	else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0)
		gotview++;

	if (echoheader) {			/* echo line */
		putchar('\t');
		return(fputs(s, stdout));
	}
	return(0);
}
Beispiel #6
0
static inline bool check_field(enum term_comparison c, const char *value, const char *with) {
	if (c == tc_none) {
		return true;
	} else if (c == tc_globmatch) {
		return globmatch(value, with);
	} else if (c == tc_notglobmatch) {
		return !globmatch(value, with);
	} else {
		int i;
		i = strcmp(value, with);
		if (i < 0)
			return c == tc_strictless
				|| c == tc_lessorequal
				|| c == tc_notequal;
		else if (i > 0)
			return  c == tc_strictmore
				|| c == tc_moreorequal
				|| c == tc_notequal;
		else
			return c == tc_lessorequal
				|| c == tc_moreorequal
				|| c == tc_equal;
	}
}
Beispiel #7
0
static PICTURE *
openpicture(			/* open/check Radiance picture file */
	char	*fname
)
{
	FILE	*fp;
	register PICTURE	*pp;
	register char	*cp;
					/* check filename suffix */
	if (fname == NULL) return(NULL);
	for (cp = fname; *cp; cp++)
		;
	while (cp > fname && cp[-1] != '.')
		if (*--cp == '/') {
			cp = fname;
			break;
		}
	if (cp > fname && !strncmp(cp, "tif", 3))
		return(NULL);		/* assume it's a TIFF */
					/* else try opening it */
	if ((fp = fopen(fname, "r")) == NULL)
		return(NULL);
	SET_FILE_BINARY(fp);
					/* allocate struct */
	if ((pp = (PICTURE *)malloc(sizeof(PICTURE))) == NULL)
		return(NULL);		/* serious error -- should exit? */
	pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.;
					/* load header */
	if (getheader(fp, headline, pp) < 0) {
		closepicture(pp);
		return(NULL);
	}
	if (!pp->fmt[0])		/* assume RGBE if unspecified */
		strcpy(pp->fmt, COLRFMT);
	if (!globmatch(PICFMT, pp->fmt) || !fgetsresolu(&pp->rs, fp)) {
		closepicture(pp);	/* failed test -- close file */
		return(NULL);
	}
	rewind(fp);			/* passed test -- rewind file */
	return(pp);
}
Beispiel #8
0
static int
headline(			/* print line preceded by a tab */
	char	*s,
	void	*p
)
{
	char  fmt[32];

	if (isheadid(s))
		return(0);
	if (formatval(fmt, s)) {
		if (globmatch(ourfmt, fmt)) {
			wrongformat = 0;
			strcpy(ourfmt, fmt);
		} else
			wrongformat = 1;
	} else if (echoheader) {
		putc('\t', stdout);
		fputs(s, stdout);
	}
	return(0);
}
Beispiel #9
0
Datei: glob.c Projekt: tcava/bx2
/*
 * pattern matching function for filenames.  Each occurrence of the *
 * pattern causes a recursion level.
 */
static int globmatch		(	register Char *name,
					register Char *pat,
					register Char *patend, int nocase )
{
	int ok, negate_range;
	Char c, k;

	while (pat < patend) 
	{
		c = *pat++;
		switch (c & M_MASK) 
		{
		case M_ALL:
			if (pat == patend)
				return(1);
			do 
			    if (globmatch(name, pat, patend, nocase))
				    return(1);
			while (*name++ != EOS);
			return(0);

		case M_ONE:
			if (*name++ == EOS)
				return(0);
			break;
		case M_SET:
			ok = 0;
			if ((k = *name++) == EOS)
				return(0);
			if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
				++pat;
			while (((c = *pat++) & M_MASK) != M_END)
			{
				if ((*pat & M_MASK) == M_RNG) 
				{
					if (c <= k && k <= pat[1])
						ok = 1;
					pat += 2;
				} else if (c == k)
					ok = 1;
			}
			if (ok == negate_range)
				return(0);
			break;
		default:
		{
			if (nocase)
			{
				if (toupper((int)CHAR(*name)) != 
				    toupper((int)CHAR(c)))
					return 0;
			}
			else
			{
				if (*name != c)
					return 0;
			}
			name++;
			break;
		}
		}
	}

	if (*name == EOS)
		return 1;

	return 0;
}
Beispiel #10
0
Datei: glob.c Projekt: tcava/bx2
static int glob3		(	Char *pathbuf,
					Char *pathend,
					Char *pattern,
					Char *restpattern,
					glob_t *pglob			)
{
	register struct dirent *dp;
	DIR *dirp;
	int err;
	char buf[MAXPATHLEN];

	/*
	 * The readdirfunc declaration can't be prototyped, because it is
	 * assigned, below, to two functions which are prototyped in glob.h
	 * and dirent.h as taking pointers to differently typed opaque
	 * structures.
	 */
	struct dirent *(*readdirfunc)(DIR *);

	*pathend = EOS;
	errno = 0;

	if ((dirp = g_opendir(pathbuf, pglob)) == NULL)
	{
		/* TODO: don't call for ENOENT or ENOTDIR? */
		if (pglob->gl_errfunc) 
		{
			g_Ctoc(pathbuf, buf);
			if (pglob->gl_errfunc(buf, errno) ||
			    pglob->gl_flags & GLOB_ERR)
				return (GLOB_ABEND);
		}
		return(0);
	}

	err = 0;

	/* Search directory for matching names. */
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
		readdirfunc = (struct dirent *(*)(DIR *))pglob->gl_readdir;
	else
		readdirfunc = readdir;

	while ((dp = (*readdirfunc)(dirp))) 
	{
		register unsigned char *sc;
		register Char *dc;
		int	nocase = 0;

		/* Initial DOT must be matched literally. */
		if (dp->d_name[0] == DOT && *pattern != DOT)
			continue;
		for (sc = (unsigned char *) dp->d_name, dc = pathend; 
		     (*dc++ = *sc++) != EOS;)
			continue;


		if (pglob->gl_flags & GLOB_INSENSITIVE)
			nocase = 1;

		if (!globmatch(pathend, pattern, restpattern, nocase)) 
		{
			*pathend = EOS;
			continue;
		}
		err = glob2(pathbuf, --dc, restpattern, pglob);
		if (err)
			break;
	}

	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
		(*pglob->gl_closedir)(dirp);
	else
		closedir(dirp);
	return(err);
}