/*
 *     $Filename: main.c $
 *     $Revision: 1.4 $
 *     $Date: 1993/10/06 12:19:18 $
 *
 *     __main() is a replacement for the standard startup-code, usually
 *     linked to C programs. This one provides the unparsed commandline
 *     to the main program and does not support the Workbench message.
 *
 *
 *     © Copyright 1993 Peter Simons, Germany
 *       All Rights Reserved
 *
 *     $Id: main.c,v 1.4 1993/10/06 12:19:18 simons Exp simons $
 *
 * ------------------------------ log history ----------------------------
 * $Log: main.c,v $
 * Revision 1.4  1993/10/06  12:19:18  simons
 * Changed format of RCS-Header.
 *
 * Revision 1.3  1993/09/14  17:20:14  simons
 * Removed any Workbench-startup and commandline parsing stuff.
 * The `real' main() now gets the unparsed commandline.
 *
 * Revision 1.2  1993/09/14  17:10:14  simons
 * Added RCSId string and removed the TINY-stuff.
 *
 * Revision 1.1  1993/09/14  17:04:08  simons
 * Initial revision
 */

#include <stdio.h>
#include <fcntl.h>
#include <ios1.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <workbench/startup.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <exec/execbase.h>

extern int __fmode;

int main(char *);

        static const char __RCSId[] = "$Id: main.c,v 1.4 1993/10/06 12:19:18 simons Exp simons $";

void __stdargs __main(char *line)
{
        int ret, x;
        struct UFB  ufbs[3];


        /* Open standard files. */

        ufbs[0].ufbnxt = &ufbs[1];
        ufbs[1].ufbnxt = &ufbs[2];
        ufbs[2].ufbnxt = NULL;
        __ufbs = &ufbs[0];
        ufbs[0].ufbfn = NULL;
        ufbs[1].ufbfn = NULL;
        ufbs[2].ufbfn = NULL;
        ufbs[0].ufbflg = UFB_RA | O_RAW | UFB_NC;
        ufbs[1].ufbflg = UFB_WA | O_RAW | UFB_NC;
        ufbs[2].ufbflg = UFB_WA | O_RAW | UFB_NC | UFB_CLO;

        ufbs[0].ufbfh = Input();
        ufbs[1].ufbfh = Output();
        if ((ufbs[2].ufbfh = Open("*", MODE_OLDFILE)) == NULL)
                ufbs[2].ufbfh = Open("NIL:", MODE_OLDFILE);

        __nufbs += 3;

        x = (__fmode) ? 0 : _IOXLAT;
        stdin->_file = 0;
        stdin->_flag = _IOREAD | x;
        stdout->_file = 1;
        stdout->_flag = _IOWRT | _IOLBF | x;
        stderr->_file = 2;
        stderr->_flag = _IOWRT | _IOLBF | x;


        /* Call user's main program! */

        ret = main(line);                /* call main function */
        exit(ret);
}
