/*	Primary module for FireSHell
 *
 *	Copyright (c) 2001 Daniel Foesch & Eric Zeitler
 */

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
 
#include "interp.h"
#include "sighandl.h"

#define module_name "fsh"

int main(int argc, char *argv[])
{
  FILE *fin = stdin;
  int i, ret;
  char temp[256];

  mkdir("~/.fsh", 0x700);	/* insure this directory exists... */

#ifdef __REISER_FS_OPTION
  sprintf(temp, "~/.fsh/%X", pid);
  mkdir(temp, 0x700);
#endif

  for(i=1;i<argc;i++)
  {
    if(!strncmp(argv[i], "-f", 2))
    {
      if(strcmp(argv[i], "-f")) //if that's not the only thing on the line
      {
        fin = fopen(argv[i]+2, "r");
        if(fin == NULL)
        {
          perror("fsh");
          return -1;
        }
      }
      else
      {
        if(++i >= argc)
        {
          fprintf(stderr, "fsh: missing argument\n");
          return -1;
        }

        fin = fopen(argv[i], "r");
        if(fin == NULL)
        {
          perror("fsh");
          return -1;
        }
      }

      interactive = 0;
    }
  }

  ret = interpreter(fin);

/* clean up */
#ifdef __REISER_FS
  //this should delete all the command-line stuff
#endif

  return ret;
}
