
#include <intuition/intuisup.h>
#include <intuition/intuitionbase.h>
#include <libraries/dos.h>

#ifndef DEBUG
#include <proto/exec.h>
#include <proto/intuition.h>
#endif

extern struct WBStartup *WBenchMsg;

struct   IntuitionBase  *IntuitionBase;
struct   GfxBase        *GfxBase;
struct   IconBase       *IconBase;
struct   Library        *iSupBase;
struct   FileIOSupport  *fileio;
struct   Device         *ConsoleDevice;

UBYTE Error[2][30] =
   {
   "Unknown file type",
   "Can't acces that file"
   };

VOID main(argc, argv)
UBYTE argc, **argv;
{
   BYTE     filetype;
   UBYTE    name[80];
   struct   FileIOSupport *fileio;
   struct   Screen        wbscreen;

   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
   GfxBase       = (struct GfxBase *)OpenLibrary("graphics.library", 0);
   IconBase      = (struct IconBase *)OpenLibrary("icon.library", 0);
   iSupBase      = (struct iSupBase *)OpenLibrary("isup.library", 0);
   if ( !IntuitionBase || !GfxBase || !IconBase || !iSupBase) goto MAIN_DONE;

   if (argc)
      switch(ParseCLIArgs(argc, argv))
            {
            case 2:
               printf("Invalid arguments. Enter Smallbench -h for help\n");
            case 1:
               exit(0);
            }
   else ParseWBArgs(WBenchMsg);


   if (  !GetScreenData(&wbscreen, sizeof(struct Screen), WBENCHSCREEN, NULL)
      || !(fileio = GetFileIOSupport(NULL)) ) goto MAIN_DONE;

   fileio->ReqTitle    = (UBYTE *)"SmallBench v1.1, by -ghg-";
   fileio->ReqPattern  = "*";
   fileio->Flags      |= FR_AUTO_CLOSE_OFF | FR_REQUESTER_OFF;
   while (GetFileIOName(fileio, NULL, wbscreen.Width-FR_WIDTH(fileio)-10, 15))
         {
         BuildFileIOPathname(fileio, name);
         if ( (filetype = FileType(fileio->FRWindow, name))>=0 ) DisplayFile(fileio->FRWindow, name, filetype);
         else AutoSmartRequest(fileio->FRWindow, 1, Error[-filetype-1], 0, "Ok", NULL, NULL, NULL);
         }


   MAIN_DONE:
      if (fileio)           ReleaseFileIO(fileio);
      if (IntuitionBase)    CloseLibrary(IntuitionBase);
      if (GfxBase)          CloseLibrary(GfxBase);
      if (IconBase)         CloseLibrary(IconBase);
      if (iSupBase)         CloseLibrary(iSupBase);
}

