/******************************************************************************

    MODULE
	Yes.c

    DESCRIPTION
	Output an endless stream of 'y' lines

    NOTES
	Kickstart 2.0+ required
	compiles w/ SAS/C v6.51

    BUGS
	none known

    TODO

    EXAMPLES

    SEE ALSO

    INDEX

    HISTORY
	(12-02-95 b_noll T created .c.Template)
	(20-02-95 b_noll T added includes section)
	(21-02-95 b_noll T added version/format-prefix/offset)
	(20-03-95 b_noll T added args diagnostics)
	05-04-95 b_noll created

    AUTHOR
	Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
	b_noll@informatik.uni-kl.de

******************************************************************************/

/**************************************
	    Includes
**************************************/

#ifndef   EXEC_LIBRARIES_H
# include <exec/libraries.h>
#endif /* EXEC_LIBRARIES_H */

#ifndef   CLIB_EXEC_PROTOS_H
# include <clib/exec_protos.h>
#endif /* CLIB_EXEC_PROTOS_H */

#ifndef   DOS_DOS_H
# include <dos/dos.h>
#endif /* DOS_DOS_H */

#ifndef   CLIB_DOS_PROTOS_H
# include <clib/dos_protos.h>
#endif /* CLIB_DOS_PROTOS_H */

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

/* ******************** USER INCLUDES ******************** */


/* ******************** USER INCLUDES ******************** */

/**************************************
	 Defines & Structures
**************************************/

struct _arg {
/* ******************** USER FORMAT ******************** */
#define FORMAT "STRING,LINES/N/K"

    STRPTR string;
    ULONG *lines;

/* ******************** USER FORMAT ******************** */
}; /* struct _argv */

#define MAXPATHLEN 256
#define MAXLINELEN 256

#define VERSIONPREFIX	"$VER: "
#define VERSIONOFFSET	0
#define FORMATPREFIX	"$ARG: "
#define FORMATOFFSET	6

/**************************************
	    Implementation
**************************************/

long _main (void)
{
    const char* version = VERSIONPREFIX "Yes 1.0 " __AMIGADATE__ + VERSIONOFFSET;
    long retval = RETURN_FAIL;
    struct Library* SysBase = *((struct Library**)4L);
    struct Library* DOSBase;

    if (DOSBase = OpenLibrary (DOSNAME, 37)) {
	struct _arg argv = { 0 };
	APTR   args;
	retval	 = RETURN_ERROR;
	if (args = (void*)ReadArgs(FORMATPREFIX FORMAT + FORMATOFFSET, (LONG*)&argv, NULL)) {

	    retval = RETURN_OK;
/* ******************** USER BODY ******************** */
	    {
		STRPTR string;
		ULONG  count;
		string = argv.string ? argv.string : "y\n";
		count = argv.lines ? *argv.lines : ~0;
		while (!CheckSignal(SIGBREAKF_CTRL_C) && count--) {
		    if (PutStr(string) != 0) {
			retval = 10;
			break;
		    } /* if */
		} /* while */

	    }
/* ******************** USER BODY ******************** */
	    FreeArgs (args);
	} /* if */

	if (retval > RETURN_WARN)
	    PrintFault(IoErr(), "Yes");

	CloseLibrary (DOSBase);
    } /* if */
    return (retval);
} /* _main */

/******************************************************************************
*****  END Yes.c
******************************************************************************/
