/*
 * Initial main.c file generated by Glade. Edit as required.
 * Glade will not overwrite this file.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "interface.h"
#include "support.h"
#include "startCube.h"
#include "readConfig.h"

const char * help = "General GTK+ commandline options\n\
--gtk-module module.  A list of modules to load in addition to those specified in the GTK_MODULES environment variable and the gtk-modules setting. \n\
--g-fatal-warnings.  Make GTK+ abort on all warnings. This is useful to stop on the first warning in a debugger, if your application is printing multiple warnings. It's almost always best to start debugging with the first warning that occurs. \n\
--gtk-debug options.  A list of debug options to turn on in addition to those specified in the GTK_DEBUG environment variable. This option is only available if GTK+ has been configured with --enable-debug=yes. \n\
--gtk-no-debug options.  A list of debug options to turn off. This option is only available if GTK+ has been configured with --enable-debug=yes. \n\
 The following options are really used by GDK, not by GTK+, but we list them here for completeness nevertheless. \n\
--class class.  Sets the program class; see gdk_set_program_class(). \n\
--name name.  Sets the program name. \n\
--gdk-debug options.  A list of debug options to turn on in addition to those specified in the GDK_DEBUG environment variable. This option is only available if GTK+ has been configured with --enable-debug=yes. \n\
--gdk-no-debug options.  A list of debug options to turn off. This option is only available if GTK+ has been configured with --enable-debug=yes.\n\n\
X11-specific commandline options\n\
--display display.  The name of the X display to open instead of the one specified in the DISPLAY environment variable.\n\
--screen screen_number.  The number of the screen within the default display. This overrides any screen number specified in the display name specified by by he --display command line option or the DISPLAY environment variable. If this screen cannot be opened, then GTK+ will fall back to the screen specified in the display name. This option is not useful interactively; the intended purposes is that when a program registers its command line with a session manager for later restarting, it can save the screen it is on, without having to worry if it might be restarted on a different display.\n\
--sync.  Makes all X requests synchronously. This is a useful option for debugging, but it will slow down the performance considerably.\n\
--gxid-host host.  The host to contact the gxid daemon on; overrides the GXID_HOST environment variable. \
--gxid-port port.  The port for the connection to gxid; overrides the GXID_PORT environment variable. This option is only available if GTK+ has been configured with --gdk-target=x11.\n\n\
Windows-specific commandline options\n\
--sync.  Don't batch GDI requests. This is a useful option for debugging, but it will slow down the performance considerably.\n\
--no-wintab, --ignore-wintab.  Don't use the Wintab API for tablet support. This is the default.\n\
--use-wintab.  Use the Wintab API for tablet support, if GTK+ has been compiled with the --with-wintab option.\n\
--max-colors number.  In 256 color mode, restrict the size of the color palette to the specified number of colors.\n";
const int MAX_LINE_LENGTH = 512;  // UNIX lines are 512 chars max
static int autoexec_present = 1;

int
main (int argc, char *argv[])
{

  if ((argc > 1) && ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0))) {
    printf(help);
    return 0;
  }
  FILE * input_stream;
  char * firstLine = calloc(MAX_LINE_LENGTH + 1, sizeof(char));
  char * currentChar = firstLine;
  int current_character;
  if ((input_stream = fopen("autoexec.cfg", "r")) == NULL) {
    autoexec_present = 0;
    fprintf(stderr, "autoexec.cfg is not present\n");
  } else {
    while (((current_character = fgetc(input_stream)) != EOF) && (current_character != '\n'))
    {
      * currentChar = current_character;
      currentChar++;
    }
    currentChar = '\0';
    if (strcmp(firstLine, "enable_gtk_config 0") == 0) {
      startCube();
      fclose(input_stream);
      return 0;
    }
    fclose(input_stream);
  }

  free(firstLine);

  GtkWidget *window1;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");

  /*
   * The following code was added by Glade to create one of each component
   * (except popup menus), just so that you see something after building
   * the project. Delete any components that you don't want shown initially.
   */
  window1 = create_window1 ();
  gtk_widget_show (window1);

  if (autoexec_present)
    read_config(window1);

  gtk_main ();
  return 0;
}

