/* $Revision Header *** Header built automatically - do not edit! ***********
 *
 *	(C) Copyright 1992 by Metalworx
 *
 *	Name .....: _main.c
 *	Created ..: Wed 29-Apr-92 20:44
 *	Revision .: 0
 *
 *	Date		Author		Comment
 *	=========	========	====================
 *	19-Aug-91	Mtwx		Created this file!
 *
 * $Revision Header ********************************************************/
 #define REVISION 0

/* ------------------------------------------ */
/*   These are my modified startup routines   */
/* ------------------------------------------ */

/* entnommen von QuickReq.c, von FishDisk ??? */

/* ------------------------------- includes ----------------------------- */

#include <exec/types.h>
#include <ctype.h>
#include <stdio.h>

#define MAXARG 32
#define QUOTE '"'

/* ------------------------------- prototypes --------------------------- */

int ParseCommands(int , register char *, char *args[]);

/* ------------------------------- routines ----------------------------- */

VOID _main(line)
register char *line;
{
    int argc = 0;		     /* arg count */
    char *argv[MAXARG]; 	     /* arg pointers */

    argc = ParseCommands(0, line, argv);
    if(argc > MAXARG)
      XCEXIT(1);

    main(argc, argv);
    XCEXIT(0);
}

/* I have separated this to own routine, because I also use this to parse
   redirection file.
*/

int ParseCommands(int Start, register char *line, char *args[])
{
    register char **pargv;
    int argc;

    argc = Start;

    while (argc < MAXARG)
    {
	while (isspace(*line))  line++;
	if (*line == '\0')      break;
	pargv = &args[argc++];
	if (*line == QUOTE)
	    {
	    *pargv = ++line;  /* ptr inside quoted string */
	    while ((*line != '\0') && (*line != QUOTE)) line++;
	    if (*line == '\0') {
		return(MAXARG+1);
	    }
	    else		*line++ = '\0';  /* terminate arg */
	}
	else		/* non-quoted arg */
	{
	    *pargv = line;
	    while ((*line != '\0') && (!isspace(*line))) line++;
	    if (*line == '\0')  break;
	    else		*line++ = '\0';  /* terminate arg */
	}
    }  /* while */

    return(argc);
}
