[comp.binaries.ibm.pc.d] Unix command globbing for MS-DOS

skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) (05/16/91)

After checking out all the archive sites I've managed to pick up MS-DOS
equivalents of my favorite Unix commands. But the one thing I haven't
found is like a TSR that will allow Unix wildcard usage in MS-DOS, 
particularly, command globbing (being able to type "file*" instead of
"file*.*"). I use command globbing a lot on my Unix account here and
I really miss it on MS-DOS. I tried WILDUNIX but it didn't seem to work.
I still had to type *.* for a wildcard. Can anyone direct me to a handy
program that will allow the freedom of command globbing and Unix wildcards?

Thanks!

max@cellar.UUCP (Maxwell Smart) (05/17/91)

skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) writes:

> I still had to type *.* for a wildcard. Can anyone direct me to a handy
> program that will allow the freedom of command globbing and Unix wildcards?

One things you may want to look into is using 4dos to replace command.com.  I 
understand that better wildcarding is one of its many features.

---------------------------------------------------------------------------
"I think; therefore, I can't be a Socialist." - Thomas Landsberger

max@cellar.uucp - A public BBS with optional net access 215-336-9503 HST/V32

tim@netcom.COM (Tim Richardson) (05/17/91)

In article <1991May16.144701.10301@magnus.acs.ohio-state.edu> skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) writes:
=After checking out all the archive sites I've managed to pick up MS-DOS
=equivalents of my favorite Unix commands. But the one thing I haven't
=found is like a TSR that will allow Unix wildcard usage in MS-DOS, 
=particularly, command globbing (being able to type "file*" instead of
="file*.*"). I use command globbing a lot on my Unix account here and
=I really miss it on MS-DOS. I tried WILDUNIX but it didn't seem to work.
=I still had to type *.* for a wildcard. Can anyone direct me to a handy
=program that will allow the freedom of command globbing and Unix wildcards?
=
=Thanks!

I've seen several in simtel20, but I use the MKS toolkit myself and 
recommend it.
-- 
Tim Richardson
techNET
email: tim@netcom.com   {apple, amdahl, claris}!netcom!tim
*******************************************************************************
    "Those willing to give up a little liberty for a little security
     deserve neither security nor liberty".   ------   Benjamin Franklin
*******************************************************************************

pjh@mccc.edu (Pete Holsberg) (05/17/91)

In article <1991May16.235903.15847@netcom.COM> tim@netcom.COM (Tim Richardson) writes:
=In article <1991May16.144701.10301@magnus.acs.ohio-state.edu> skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) writes:
==I really miss it on MS-DOS. I tried WILDUNIX but it didn't seem to work.
==I still had to type *.* for a wildcard. Can anyone direct me to a handy
==program that will allow the freedom of command globbing and Unix wildcards?
==
=
=I've seen several in simtel20, but I use the MKS toolkit myself and 
=recommend it.

Are you saying that MKS Tools can ignore the "."?  I found that in
creating shell scripts with MKS Tools, say, one named 'doit', that I had
to type "doit." to get the MKS Korn shell operating under MSDOS to find
the script!

Pete
-- 
Prof. Peter J. Holsberg      Mercer County Community College
Voice: 609-586-4800          Engineering Technology, Computers and Math
UUCP:...!princeton!mccc!pjh  1200 Old Trenton Road, Trenton, NJ 08690
Internet: pjh@mccc.edu	     Trenton Computer Festival -- 4/??-??/92

dmm0t@holmes.acc.Virginia.EDU (Dave Meyer) (05/17/91)

In article <1991May16.144701.10301@magnus.acs.ohio-state.edu> skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) writes:
>I still had to type *.* for a wildcard. Can anyone direct me to a handy
>program that will allow the freedom of command globbing and Unix wildcards?

I don't know of a program that does this well in general - I don't
think 4DOS does it very well at all.  A partial solution is the
GNUish utilities - rm, cp, mv, and so on - will handle wildcards 
like you want them to.  You can get them from simtel20 (msdos.gnuish).

-- 
David M. Meyer                                   | dmm0t@virginia.edu
Department of Mechanical & Aerospace Engineering | (804) 924-7926
University of Virginia                           |

andy@mks.com (Andy Toy) (05/19/91)

In article <1991May17.134702.27916@mccc.edu> pjh@mccc.edu (Pete Holsberg) writes:
>Are you saying that MKS Tools can ignore the "."?  I found that in
>creating shell scripts with MKS Tools, say, one named 'doit', that I had
>to type "doit." to get the MKS Korn shell operating under MSDOS to find
>the script!

Yes, you are right.  If you type `doit' in the MKS Korn Shell then it
will search for `doit.com', `doit.exe', `doit.bat' and `doit.ksh'.  It
will only execute `doit' if you type `doit.' to signify that it has no
extension.
-- 
Andy Toy <andy@mks.com>                       UUCP: ...!uunet!watmath!mks!andy
Technical Support <support@mks.com>                     Phone: +1-519-884-2270
Mortice Kern Systems Inc. <inquiry@mks.com>             Phone: +1-519-884-2251
35 King Street North, Waterloo, Ontario N2J 2W9, CANADA   Fax: +1-519-884-8861

frotz@dri.com (Frotz) (05/19/91)

skesterk@magnus.acs.ohio-state.edu (Shane Kesterke) writes:

]After checking out all the archive sites I've managed to pick up MS-DOS
]equivalents of my favorite Unix commands. But the one thing I haven't
]found is like a TSR that will allow Unix wildcard usage in MS-DOS, 
]particularly, command globbing (being able to type "file*" instead of
]"file*.*"). I use command globbing a lot on my Unix account here and
]I really miss it on MS-DOS. I tried WILDUNIX but it didn't seem to work.
]I still had to type *.* for a wildcard. Can anyone direct me to a handy
]program that will allow the freedom of command globbing and Unix wildcards?

I know that you are looking for binaries, but I insist on building as
many of my tools as I can (less chance of virii, and more
opportunities to hack the code to my-way-of-thinking(tm)). 

Below is a code snippet that I include before Turbo C's
c0$(MEMORY_MODEL).obj in the link line.  This provides me with
Un*x-like Wildcarding... 

The original author doesn't believe in copyrights for personally
developed sources (I personally agree with him).  His name is Mark G.
Alexander currently of Borland (formerly of Digital Research, Inc.).
alexander@borland.com (or possibly alexande@borland.com)

Since this was written before the change in public domain status of
files posted to networks, there is no public domain notice, nor any
copyright notice.  Therefore, it is hereby released to the public
domain, with no rights reserved and no guarantee of merchantability...
--
John "Frotz" Fa'atuai	frotz@dri.com			(email@domain)
Digital Research, Inc.	uunet!drivax!frotz		(bang!email)
c/o MIS Dept.		408/647-6570 or 408/646-6287	(vmail)
80 Garden Court, CompRm	408/649-3896			(phone)
Monterey, CA  93940	408/646-6248			(fax)
----------------------------------------------------------------------
/*----------------------------------------------------------------------
 * _wmatch -
 * 
 * Match a wild card (w) string against a normal string (s).
 * Unix shell-style wildcards are supported, including '?',
 * multiple '*', and [].  Recursion is used to handle multiple '*'
 * characters.  One difference between this sort of wild card and the DOS
 * type is that "*" matches all files, even those that have an extension
 * (i.e. those with a '.').   Case is ignored because DOS filenames
 * may be passed in upper case.  The parameters are far pointers because
 * the function is called by startup code in Turbo C's setargv.asm.
 * A space or tab character if found in the wildcard string is treated
 * as a NULL, because Turbo C sometimes passes us a trailing space
 * or tab, unfortunately.
 * 
 * The function returns 0 if no match, 1 if match.
 */

#define IGNORECASE	1
#define DEBUG		0


#if 0
#include <dos.h>

dos_string(s)
char far *s;
{
    
    while (*s)
	dos_putc(*s++);
}

dos_putc(c)
int c;
{
	bdos(2,c,0);
}
#endif

int _wmatch(w,s)
char far *w;	/* the wild card string */
char far *s;	/* the filename to match against the string */
{
    char wc,sc,wc1;
    int found, negate, trueval, falseval;

#if 0
    dos_string(w);
    dos_putc(',');
    dos_string(s);
    dos_putc('\r');
    dos_putc('\n');
#endif
    /* Handle the FlexOS '^' character, which means negate the
     * result of the match.
     */
    if (*w == '^')
    {
	w++;
	trueval = 0;
	falseval = 1;
    }
    else
    {
	trueval = 1;
	falseval = 0;
    }

    /* If the name starts with a '.', it must be explicitly matched
     * by a '.' in the wildcard.
     */
    if (*s == '.')
    {
	if (*w != '.')
	    return (falseval);
	s++;
	w++;
    }

    for (;;)
    {
	wc = *w++;
	sc = *s++;
	if (wc == ' ' || wc == '\t')	/* whitespace terminates wildcard */
	    wc = 0;
	if (wc == 0 && sc == 0)		/* at end of both strings?	*/
	    return (trueval);
#if IGNORECASE
	if (wc >= 'A' && wc <= 'Z')
	    wc = wc - 'A' + 'a';
	if (sc >= 'A' && sc <= 'Z')
	    sc = sc - 'A' + 'a';
#endif
	if (wc == sc)			/* matched one character?	*/
	    continue;
	if (wc == '?')			/* ? matches any single char	*/
	    continue;
	if (wc == '[')			/* match any char within []	*/
	{
	    found = 0;
	    if ((negate = (*w == '!')) != 0)
		w++;
	    while ((wc = *w++) != ']')
	    {
		if (wc == 0)		/* missing right bracket?	*/
		    return (0);
		if (found)		/* already found a match?	*/
		    continue;
#if IGNORECASE
		if (wc >= 'A' && wc <= 'Z')
		    wc = wc - 'A' + 'a';
#endif
		if (*w == '-')		/* range of characters?		*/
		{
		    wc1 = *++w;		/* skip the '-'			*/
#if IGNORECASE
		    if (wc1 >= 'A' && wc1 <= 'Z')
			wc1 = wc1 - 'A' + 'a';
#endif
		    if (sc >= wc && sc <= wc1)
			found = 1;
		}
		else
		{
		    if (wc == sc)
			found = 1;
		}
	    }
	    if (found == negate)
		return (falseval);
	    continue;
	}
	if (wc == '*')
	{
	    /* A trailing * always matches
	     */
	    if (*w == 0 || *w == ' ' || *w == '\t')
		return (trueval);
	    s--;			/* back up string pointer	*/
	    for (;;)			/* check all substrings		*/
	    {
		if (_wmatch(w,s))	/* does this substring match?	*/
		    return (trueval);
		if (*s == 0)		/* reached end with no matches?	*/
		    return (falseval);
		s++;
	    }
	}		
	if (wc != sc)			/* found a mismatch?		*/
	    return (falseval);
    }
}

#if DEBUG

main(argc,argv)
int argc;
char *argv[];
{
    int i;

    if (argc < 3)
    {
	printf("usage: wmatch <wildcard string> <string>...\n");
	exit(1);
    }
    for (i = 2; i < argc; i++)
	printf("%s %s %s\n",
		argv[i],_wmatch(argv[1],argv[i]) ? "matches" : "doesn't match",
		argv[1]);

}
#endif

pjh@mccc.edu (Pete Holsberg) (05/21/91)

In article <1991May19.061321.25061@mks.com> andy@mks.com (Andy Toy) writes:
=In article <1991May17.134702.27916@mccc.edu> pjh@mccc.edu (Pete Holsberg) writes:
=>Are you saying that MKS Tools can ignore the "."?  I found that in
=>creating shell scripts with MKS Tools, say, one named 'doit', that I had
=>to type "doit." to get the MKS Korn shell operating under MSDOS to find
=>the script!
=
=Yes, you are right.  If you type `doit' in the MKS Korn Shell then it
=will search for `doit.com', `doit.exe', `doit.bat' and `doit.ksh'.  It
=will only execute `doit' if you type `doit.' to signify that it has no
=extension.

Hi, Andy!  Long time, no ...

I suggested to Gardner that he recommend to the reader who creates a
shell script called, say, "XXX", that he/she immediately create a Korn
shell alias
	alias XXX="XXX."
to make the operation more UNIX-like.

Does MKS "ls *" show all files or just the ones with filetypes?

Pete


-- 
Prof. Peter J. Holsberg      Mercer County Community College
Voice: 609-586-4800          Engineering Technology, Computers and Math
UUCP:...!princeton!mccc!pjh  1200 Old Trenton Road, Trenton, NJ 08690
Internet: pjh@mccc.edu	     Trenton Computer Festival -- 4/??-??/92