示例#1
0
/*
 *	Break the filename into path components, then let them
 *	be matched individually
 */
int dfnmatchEx(const char *fnam
	, const char *pattern
	, int (*matchfct)(const char *, const char *))
{	char n1[DFN_FILENAME_BUFFER_LENGTH], n2[DFN_FILENAME_BUFFER_LENGTH];
	int c1, c2;

#ifdef SUPPORT_UNC_PATH
#define NAME "dfnumatchEx"
#else
#define NAME "dfnmatchEx"
#endif

	DBG_ENTER(NAME, Suppl_dfn)

	assert(fnam);
	assert(pattern);
	assert(matchfct);

	DBG_ARGUMENTS( ("fnam=\"%s\", pattern=\"%s\"", fnam, pattern) )

#ifdef SUPPORT_UNC_PATHS
	if(isUNCpath(fnam) != isUNCpath(pattern))
		DBG_RETURN_I( 0)
#endif

	/* 1. Make sure both names start or don't start with a path delimiter */
	if(isPathDelim(*fnam)) {
		if(!isPathDelim(*pattern))
			DBG_RETURN_I( 0)
		while(isPathDelim(*++fnam));
		while(isPathDelim(*++pattern));
	}
	else if(isPathDelim(*pattern))
示例#2
0
int dfnmatchext(const char * const fnam , const char *pattern)
{	char *p;

	DBG_ENTER("dfnmatchext", Suppl_dfn)

	assert(fnam);
	assert(pattern);

	DBG_ARGUMENTS( ("fnam=\"%s\", pattern=\"%s\"", fnam, pattern) )

	/* find extension in filename */
	p = dfnfilenameext(fnam);
	assert(p);
	assert(*p == '\0' || *p == '.');
	if(!*p) {
		/* No dot --> no extension */
		DBG_RETURN_I(*pattern == 0);
	}

	if(*pattern == '.')		/* one dot is optional */
		++pattern;

#ifdef OS_DOS
	/* At most one extension in DOS mode */
	DBG_RETURN_BI(dfnmatchcomponent(p + 1, pattern))
#else
	/* Try each extension as the pattern may include the asterisk */
	do if(dfnmatchcomponent2(p + 1, pattern)) {
		DBG_RETURN_I(1)
	} while(0 != (p = strchr(p + 1, '.')));

	DBG_RETURN_I(0)
#endif
}
示例#3
0
int Fcopyto(FILE * const fdst, FILE * const fsrc, const fpos_t * const pos)
{	fpos_t cpos;
	dword dw_cpos, dw_topos;

	DBG_ENTER("Fcopyto", Suppl_supplio)

	assert(fdst);
	assert(fsrc);
	assert(pos);

	/* Because the (fpos_t) data type is a blackbox type completely,
		one would need to copy the stream character-by-character in
		order to ensure that the pos is reached.

		SUPPL assumes that there is a way to calculate the offset
		of data type (dword) from the (fpos_t) values, which is
		hidden into the Fpos2dword() function.
	*/
	if(FFgetpos(fsrc, cpos))			/* get current position */
		DBG_RETURN_I( 1)			/* general access error */

	Fpos2dword(cpos, dw_cpos);
	Fpos2dword(pos, dw_topos);

	if(longcmp1(dw_topos, dw_cpos) <= 0)
		DBG_RETURN_I( 0)	/* current position already behind end position */

	/* Amount of bytes to be copied */
	longsub(dw_topos, dw_cpos);

	DBG_RETURN_BI( Fcopyl(fdst, fsrc, dw_topos))
}
示例#4
0
int Fcopy(FILE * const fdst, FILE * const fsrc)
{	byte *buf;
	size_t len, i;
	int err;

	DBG_ENTER("Fcopy", Suppl_supplio)

	assert(fsrc);
	assert(fdst);

	chkHeap
	if(Fmaxbuf(&buf, &len))
		DBG_RETURN_I( 3)				/* out of memory */

	chkHeap
	while((err = Fcopybuf(fdst, fsrc, buf, len, &i)) == 0);

	chkHeap
	free(buf);
		/*	err == 0 --> impossible
			err == 1 --> read error, this is OK, if read had hit EOF
		*/
	chkHeap
	DBG_RETURN_BI(err < 2? Feof(fsrc) == 0: err)
}
示例#5
0
int _fMemiCmp(const byte far * dest, const byte far * src, unsigned length)
{	int d;

	DBG_ENTER("_fMemiCmp", Suppl_farmem)

	if(!length)
		DBG_RETURN_I( 0)

	if(dest == 0)
		DBG_RETURN_I(src != 0)
	if(src == 0)
		DBG_RETURN_I(-1)

	while((d = toUpper(*dest++) - toUpper(*src++)) == 0 && --length);

	DBG_RETURN_I( d)
}
示例#6
0
int MemiCmp(const byte *s, const byte *p, unsigned len)
{	int result;

	DBG_ENTER("MemiCmp", Suppl_nls)
	DBG_ARGUMENTS( ("s1=\"%s\", s2=\"%s\", len=%u", s, p, len) )

	if(!len)
		DBG_RETURN_I(0)

	if(p == 0)
		DBG_RETURN_I(s != 0)
	if(s == 0)
		DBG_RETURN_I(-1)

	while((result = toUpper(*s++) - toUpper(*p++)) == 0 && --len);

	DBG_RETURN_I( result)
}
示例#7
0
int _fMemiCmp(unsigned const dseg, unsigned dofs
 , unsigned const sseg, unsigned sofs, unsigned length)
{	int d;

	DBG_ENTER("_fMemiCmp", Suppl_farmem)

	if(!length)
		DBG_RETURN_I( 0)

	if((dseg | dofs) == 0)
		DBG_RETURN_I((sseg | sofs) != 0)
	if((sseg | sofs) == 0)
		DBG_RETURN_I(-1)

	while((d = toUpper(peekb(dseg, dofs++)) - toUpper(peekb(sseg, sofs++)))
	 == 0 && --length);

	DBG_RETURN_I( d)
}
示例#8
0
int Feof(FILE *fp)
{	
	DBG_ENTER("Feof", Suppl_supplio)

	assert(fp);

	if((fp->FILE_options & F_WRITE) != 0 || getc(fp) == EOF)
		DBG_RETURN_I( 1)

	/* ungetc() the read character */
	fseek(fp, -1, -1, SEEK_CUR);
	DBG_RETURN_I( 0)
}
示例#9
0
文件: env_nost.c 项目: FDOS/freecom
int env_nullStrings(word segm)
{	word ofs;

	DBG_ENTER("env_nullStrings", Suppl_env)
	DBG_ARGUMENTS( ("env=%u", segm) )

	chkMem
	
	unless_segm(segm)
		DBG_RETURN_I( ESUPPL_NOENV)

	DBG_ARGUMENTS( ("effective env=%u", segm) )

	ofs = env_endOfVars(segm) + 1;		/* offset of string counter word */
	if(mcb_length(segm) - 2 <= ofs)
		DBG_RETURN_I( ESUPPL_NOMEM)

	pokew(segm, ofs, 0);
	chkMem
	
	DBG_RETURN_I( ESUPPL_OK)
}
示例#10
0
int mcb_allParents(word mcb, MCB_WALKFUNC fct, void *arg)
{	word mcb1;

	DBG_ENTER("mcb_allParents", Suppl_mcb)
	DBG_ARGUMENTS( ("mcb=%u", mcb) )

	assert(fct);

	if(mcb) {
		if(!isPSP(mcb)) {
			DBG_STRING("Invalid MCB")
			DBG_RETURN_I( -1)
		}
	}
	else mcb = _psp;
示例#11
0
int dfnwrdir(const char * const fnam)
{	char *p;			/* temporary filename */

	DBG_ENTER("dfnwrdir", Suppl_dfn)
	DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) )

	assert(fnam);

	chkHeap
	if((p = dfnmktmp(fnam, 0)) == 0)		/* failed --> error */
		DBG_RETURN_I( 1)

	remove(p);			/* dfnmktmp() creates the file */
	free(p);

	chkHeap
	DBG_RETURN_I( 0)
}
示例#12
0
word mcb_owner(word mcb)
{	word mcb1;

	DBG_ENTER("mcb_owner", Suppl_mcb)
	DBG_ARGUMENTS( ("mcb=%u", mcb) )

	/* A PSP can be identified that the MCB has stored itself as the
		owner process. In some circumstances the "owner" field does
		not mention a process, but some other memory block allocated
		by a process. This loop resolves this situation and correctly
		returns a MCB of a PSP.

		Unused and system MCBs force this function to return with
		value "0" (zero) meaning "no owner found".
	*/
	do if((mcb1 = mcb) <= 0x40) {
		DBG_RETURN_I( 0)
	} while((mcb = peekw(mcb, MCB_OFF_OWNER)) != 0
	 && (mcb = SEG2MCB(mcb)) != mcb1);

	DBG_RETURN_I( mcb)
}
示例#13
0
int StrUnquoteTokenAppend(const char **s, const STR_QUOTES * const quotes
	, char ** const dst)
{
	const char *p;			/* temp pointer into s */
	size_t l;
	int ch;
	FLAG fullQuote;
	int endQuote;
	const char *q;

	DBG_ENTER("StrUnquoteToken", Suppl_dynstr)

	assert(quotes);
	assert(s);
	assert(dst);
	assert(!quotes->str_unpairyQuotes
	 || strlen(quotes->str_unpairyQuotes) % 2 == 0);

	DBG_ARGUMENTS( ("str=\"%s\"", s) )

	*dst = 0;
	if((p = *s) == 0 || (ch = *p) == 0) {
		DBG_RETURN_I(0)
	}

	if((l = Strspn(p, quotes->str_delimiters)) != 0) {
		/* Unquoted delimiter
			--> The token is a sequence of delimiters */
		/** Warning: Possible incorrect assignment **/
		DBG_RETURN_BI( (*dst = StrDupe(p, *s += l)) == 0)
	}

	fullQuote = endQuote = 0;
	do {
		if(endQuote) {
			/* within quoted string */
			if(endQuote == ch) {
				/* end of quote reached */
				endQuote = 0;
				continue;
			}
			if(!fullQuote && StrChr(quotes->str_singleQuotes, ch)) {
				/* A not-full quote does not quote single quotes
					--> regardless what the next character is (except NUL)
					it is appended to the string */
				if((ch = *++p) == NUL)	/* single quote @ EOS --> ign */
					break;
			}
		} else if(StrChr(quotes->str_singleQuotes, ch)) {
			if((ch = *++p) == NUL)	/* single quote @ EOS --> ign */
				break;
		} else if(StrChr(quotes->str_pairyQuotes, ch)) {
			endQuote = ch;
			fullQuote = StrChr(quotes->str_fullQuotes, ch) != 0;
			continue;
		} else if((q = StrChr(quotes->str_unpairyQuotes, ch)) != 0
		 && (q - quotes->str_unpairyQuotes) % 2 == 0) {
		 	endQuote = q[1];
			fullQuote = StrChr(quotes->str_fullQuotes, ch) != 0;
			continue;
		} else if(StrChr(quotes->str_delimiters, ch)) {
			/* Unquoted delimiter --> Stop here */
			break;
		}
		if(!StrAppChr_(dst, ch)) { /* allocation error */
			StrFree_(dst);
			DBG_RETURN_I(1)
		}
	} while((ch = *++p) != NUL);

	*s = p;
	DBG_RETURN_I(0)
}