/**********************************************************************
This file is part of Crack dot Com's free source code release of Golgotha.
for information about compiling & licensing issues visit this URL
 If that doesn't help, contact Jonathan Clark at 
  golgotha_source@usa.net (Subject should have "GOLG" in it) 
***********************************************************************/

#include "main/main.hh"
#include "main/win_main.hh"
#include "error/error.hh"
#include "error/alert.hh"
#include "file/file.hh"

// this global will be used by video/directx/directx.c when opening a window
#include 
#include 
#include 

w32           i4_global_argc;
i4_const_str *i4_global_argv;


HINSTANCE i4_win32_instance;
int       i4_win32_nCmdShow;
HWND      i4_win32_window_handle=0;
i4_win32_startup_options_struct i4_win32_startup_options;
void *i4_stack_base=0;

int i4_win32_alert(const i4_const_str &ret)
{
  char tmp[1024], *st;
  strcpy(tmp, "Alert : ");
  st=tmp+8;

  i4_const_str::iterator s=ret.begin();
  while (s!=ret.end())
  {
    *st=s.get().value();
    ++s;
    st++;
  }
  *st=0;
  strcat(tmp,"\n");
  OutputDebugString(tmp);
  setbuf(stdout,0);
  printf(tmp);
  return 1;
}


void i4_win32_startup_options_struct::check_option(char *opt)
{
  if (!strcmp(opt,"-no_full"))
    fullscreen=i4_F;
}


int i4_win32_error(const char *st)
{

  static int died = 0;

  if (died)
  {
    i4_debug->printf("recursive error : %s", st);
    return 1;  
  }

  died = 1;

  MessageBox(0, st, "Error!", MB_OK | MB_APPLMODAL);
  
  exit(0);

  return 1;
}



static FILE *debug_file=0;


int i4_windows_warning_function(const char *st)
{
  OutputDebugString(st);
  OutputDebugString("\n");

  return 1;
}

class i4_win32_debug_stream_class : public i4_file_class
{
public:
  virtual w32 read (void *buffer, w32 size) { return 0; }

  virtual w32 write(const void *buffer, w32 size) 
  {
    if (debug_file)
    {
      fwrite(buffer, 1, size, debug_file);
      fflush(debug_file);
    }

    char b[1024];
    if (size>1023)
    {
      b[1]=0;
      for (int i=0; i