/*
** wildstar.c
**
** '*' wildcard enabler
**
** $Id: wildstar.c,v 1.2 94/08/09 17:15:49 GF Exp Locker: GF $
**
**************************************************************************
**
** Copyright © 1994 by Gabriele Falcioni. All Rights Reserved.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** For inquiries, comments, donations, bug reports, write to:
**
** Gabriele Falcioni
** via E. Cialdini, 50
** I-60122 Ancona
** ITALY
**
**************************************************************************
**
** WILDSTAR: enable/disable the '*' wildcard
**
** REQUIREMENTS
**
** · "exec.library" V37+
** · "dos.library"  V37+
**
** · SAS DevSystem V6.x
** · Startup: "shellcres2.o"
*/

#define _CMDNAME	"WildStar"
#define _VER_REV	"1.2"
#define _CREATION	"(18.05.94)"
#define _TEMPLATE "ON/S,OFF/S"

/*
 * COMMAND
 * WildStar -- Enable/disable the '*' wildcard.
 *
 * TEMPLATE
 * ON/S,OFF/S
 *
 * DESCRIPTION
 * This command enables or disables the '*' wildcard for the standard
 * AmigaDOS pattern matching functions. If no arguments are specified
 * the current status of wildcard is printed to stdio.
 *
 * ARGUMENTS
 * ON/S  - enable '*' as wildcard.
 * OFF/S - disable '*' as wildcard.
 */

/* -------------------------------------------------------------------- */

#include <exec/types.h>
#include <dos/dosextens.h>

#include <proto/dos.h>
#include <proto/exec.h>

/* -------------------------------------------------------------------- */

/* a *slightly* nonstandard version string */
static UBYTE const EmbeddedVersionID[] = {
	"$VER: " _CMDNAME " " _VER_REV " " _CREATION
	" Copyright © 1994 by Gabriele Falcioni. FREE Software."
};

extern struct DosLibrary *DOSBase;

struct RDArgs *MyRdargs;
struct {
	ULONG on;
	ULONG off;
} MyArgs;

/* -------------------------------------------------------------------- */

VOID set_wildstar(BOOL ws)
{
	register LONG dosflags;

	Forbid();

	dosflags = DOSBase->dl_Root->rn_Flags;

	if (ws) dosflags |= RNF_WILDSTAR;
	else dosflags &= ~RNF_WILDSTAR;

	DOSBase->dl_Root->rn_Flags = dosflags;

	Permit();
}

/*
 * this is from file: "shellcres2.a" (cres-like custom startup module)
 *
 * Features:
 * · Smaller than standard one
 * · Makes C programs resident-able
 * · Permits Shell execution only
 * · Initializes SysBase and DOSBase
 * · Requires V37+ ROMs
 * (of course practical *only* for really small Shell utilities)
 *
 */

void late_exit(long);

/*
 * custom main function: void early_main(void)
 * called by "shellcres2.o" (custom startup module, see above)
 */

void __stdargs early_main(void)
{
	if (MyRdargs = ReadArgs(_TEMPLATE,(LONG *)&MyArgs,NULL)) {

		if (MyArgs.on)       set_wildstar(TRUE);
		else if (MyArgs.off) set_wildstar(FALSE);
		else Printf("The '*' wildcard is %s\n",
			(DOSBase->dl_Root->rn_Flags & RNF_WILDSTAR ?
			"enabled" : "disabled"));

		FreeArgs(MyRdargs);
	} else {
		PrintFault(IoErr(),"Bad args");
		late_exit(RETURN_FAIL);
	}

	late_exit(RETURN_OK);
}
