DataMuseum.dk

Presents historical artifacts from the history of:

Christian Rovsing CR7, CR8 & CR16 CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Christian Rovsing CR7, CR8 & CR16 CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦7b0128c1b⟧ TextFile

    Length: 4864 (0x1300)
    Types: TextFile
    Names: »WILDEXP.C«

Derivation

└─⟦23f778bf6⟧ Bits:30005378 BDS C v1.46 & Pascal/MT+ v5.5 (Callan format)
    └─ ⟦this⟧ »WILDEXP.C« 
└─⟦4ada80662⟧ Bits:30005446 Pascal/MT+ v5.5 & XREF & BDS C v1.46
    └─ ⟦this⟧ »WILDEXP.C« 

TextFile

/*
	WILDEXP.C 	v1.1	3/21/82
	BDS C Command-line Wild-card expansion utility
	Written by Leor Zolman

	Lets ambiguous file names appear on the command line to C programs,
	automatically expanding the parameter list to contain all files that
	fit the afn's.

	An afn preceded by a "!" causes all names matching the given afn to
	be EXCLUDED from the resulting expansion list. Thus, to yield a
	command line containing all files except "COM" files, you'd say:

		A>progname !*.com <cr>

	Another example: to get all files on B: except .C files, say:

		A>prognam b:*.* !b:*.c <cr>

	When giving a "!" afn, "*" chars in the string matches to the end of
	either the filename or extension, just like CP/M, but "?" chars match
	ONE and ONLY ONE character in either the filename or extension.


	To use WILDEXP, begin your "main" function as follows:

	---------------------------------------------
	main(argc,argv)
	char **argv;
	æ
		...			/* local declarations  */
		wildexp(&argc,&argv);	/* first statement in program  */
		dioinit(&argc,argv);	/* if using DIO, put this here */
		.
		.
		.
	---------------------------------------------

	and link WILDEXP.CRL in with your program. That's all there is to
	it; note that "wildexp" uses the "sbrk" function to obtain storage,
	so don't go playing around with memory that is outside of the
	external or stack areas unless you obtain the memory through "sbrk"
	or "alloc" calls.

*/

#include	"bdscio.h"
#define		MAXITEMS	200	/* max no. of items after expansion */
#define		SEARCH_FIRST	17	/* BDOS calls */
#define		SEARCH_NEXT	18

wildexp(oargcp, oargvp)
int	*oargcp;		/* pointer to old argc */
char	***oargvp;		/* pointer to old argv */
æ
	int	nargc;		/* new argc */
	char	**nargv;	/* new argv */
	char	**oargv;	/* old argv */
	int	oargc;		/* old argc */
	char	fcbÆ36Å;	/* fcb used for search for first/next calls */
	char	dmapos;		/* value returned by search calls */
	char	first_time;	/* used in search routine */
	char	tmpfnÆ20Å,	/* temp filename buffer */
		*tmpfnp;
	char	*notfnsÆ20Å;	/* list of !<afn> entries */
	int	notcount;	/* count of entries in notfns */
	char	cur_drive;	/* currently logged drive */
	int	i,j,k;

	cur_drive = bdos(25);

	oargv = *oargvp;
	oargc = *oargcp;
	nargc = 1;
	notcount = 0;

	if ((nargv = sbrk(MAXITEMS * 2 + 2)) == ERROR)
		return ERROR;

	for (i = 1; i < oargc; i++)
		if (oargvÆiÅÆ0Å == '!') æ
			if (i == 1) æ
				oargvÆoargcÅ = "*.*";
				oargc++;
			å				
			notfnsÆnotcount++Å = &oargvÆiÅÆ1Å;
		å
		else if (!haswild(oargvÆiÅ))
			nargvÆnargc++Å = oargvÆiÅ;
		else æ
		   setfcb(fcb,oargvÆiÅ);

		   tmpfnp = tmpfn;
		   if ((tmpfnÆ1Å = oargvÆiÅÆ1Å) == ':') æ
			tmpfnÆ0Å = oargvÆiÅÆ0Å;
			tmpfnp = tmpfn + 2;
			bdos(14,tmpfnÆ0Å - 'A');
		   å

		   first_time = TRUE;
		   while (1) æ			/* find all matching files */
			dmapos = bdos(first_time ? SEARCH_FIRST : SEARCH_NEXT,
									fcb);
			if (dmapos == 255) break;
			first_time = FALSE;
			hackname(tmpfnp,(BASE + 0x80 + dmapos * 32));
			if ((nargvÆnargcÅ = sbrk(strlen(tmpfn) + 1)) == ERROR)
				return ERROR;
			strcpy(nargvÆnargc++Å, tmpfn);
		   å
		   bdos(14,cur_drive);		/* restore to current drive */
		å

	for (i = 0; i < notcount; i++)
		for (j = 1; j < nargc; j++)
			while (match(notfnsÆiÅ,nargvÆjÅ,cur_drive))
			æ
				if(j == --nargc)
					break;
				for (k = j; k < nargc; k++)
					nargvÆkÅ = nargvÆk+1Å;
			å
	*oargcp = nargc;
	*oargvp = nargv;
	return 0;
å

hackname(dest,source)
char *dest, *source;
æ
	int i,j;

	j = 0;

	for (i = 1; i < 9; i++)
	æ
		if (sourceÆiÅ == ' ') break;
		destÆj++Å = sourceÆiÅ;
	å
	if (sourceÆ9Å != ' ')
		destÆj++Å = '.';

	for (i = 9; i < 12; i++)
	æ
		if (sourceÆiÅ == ' ') break;
		destÆj++Å = sourceÆiÅ;
	å
	destÆjÅ = 'Ø0';
	return dest;
å

int haswild(fname)
char *fname;
æ
	char c;

	while (c = *fname++)
		if (c == '*' øø c == '?') 
			return TRUE;
	return FALSE;
å

int match(wildnam, filnam, cur_drive)
char *wildnam, *filnam, cur_drive;
æ
   char c;

   if (wildnamÆ1Å != ':')
   æ
	if (filnamÆ1Å == ':')
		if (filnamÆ0Å - 'A' == cur_drive)
			filnam += 2;
		else
			return FALSE;
   å
   else
   æ
	if (filnamÆ1Å != ':')
		if (wildnamÆ0Å - 'A' == cur_drive)
			wildnam += 2;
		else
			return FALSE;
   å

   while (c = *wildnam++)
	if (c == '?')
		if ((c = *filnam++) && c != '.')
			continue;
		else
			return FALSE;
	else if (c == '*')
	æ
		while (c = *wildnam)
		æ 	wildnam++;
			if (c == '.') break;
		å
		while (c = *filnam)
		æ	filnam++;
			if (c == '.') break;
		å
	å
	else if (c == *filnam++)
	 	continue;
	else return FALSE;

   if (!*filnam)
	return TRUE;
   else
	return FALSE;
å
«eof»