예제 #1
0
파일: main-test.c 프로젝트: SayCV/geda-pcb
int
main (int argc, char *argv[])
{
  initialize_units ();
  pcb_printf_register_tests ();

  g_test_init (&argc, &argv, NULL);
  g_test_run ();
  return 0;
}
예제 #2
0
파일: main.c 프로젝트: bert/pcb-rnd
int
main (int argc, char *argv[])
{
  int i;

  /* init application:
   * - make program name available for error handlers
   * - evaluate special options
   * - initialize toplevel shell and resources
   * - create an empty PCB with default symbols
   * - initialize all other widgets
   * - update screen and get size of drawing area
   * - evaluate command-line arguments
   * - register 'call on exit()' function
   */

  setbuf (stdout, 0);
  InitPaths (argv[0]);

#ifdef LOCALEDIR
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  textdomain(GETTEXT_PACKAGE);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  setlocale(LC_ALL,"");
#endif

  srand ( time(NULL) ); /* Set seed for rand() */

  initialize_units();
  polygon_init ();
  hid_init ();

  hid_load_settings ();

  program_name = argv[0];
  program_basename = strrchr (program_name, PCB_DIR_SEPARATOR_C);
  if (program_basename)
    {
      program_directory = strdup (program_name);
      *strrchr (program_directory, PCB_DIR_SEPARATOR_C) = 0;
      program_basename++;
    }
  else
    {
      program_directory = ".";
      program_basename = program_name;
    }
  Progname = program_basename;

  /* Print usage or version if requested.  Then exit.  */  
  if (argc > 1 &&
      (strcmp (argv[1], "-h") == 0 ||
       strcmp (argv[1], "-?") == 0 ||
       strcmp (argv[1], "--help") == 0))
    usage ();
  if (argc > 1 && strcmp (argv[1], "-V") == 0)
    print_version ();
  /* Export pcb from command line if requested.  */
  if (argc > 1 && strcmp (argv[1], "-p") == 0)
    {
      exporter = gui = hid_find_printer ();
      argc--;
      argv++;
    }
  else if (argc > 2 && strcmp (argv[1], "-x") == 0)
    {
      exporter = gui = hid_find_exporter (argv[2]);
      argc -= 2;
      argv += 2;
    }
    /* Otherwise start GUI. */
  else if (argc > 2 && strcmp (argv[1], "--gui") == 0)
  {
    gui = hid_find_gui (argv[2]);
    if (gui == NULL) {
      Message("Can't find the gui requested.\n");
      exit(1);
    }
    argc -= 2;
    argv += 2;
  }
  else {
    const char **g;

    gui = NULL;
    for(g = try_gui_hids; (*g != NULL) && (gui == NULL); g++) {
      gui = hid_find_gui (*g);
    }

    /* try anything */
    if (gui == NULL) {
      Message("Warning: can't find any of the preferred GUIs, falling back to anything available...\n");
      gui = hid_find_gui (NULL);
    }
  }

  /* Exit with error if GUI failed to start. */
  if (!gui)
    exit (1);

/* Initialize actions only when the gui is already known so only the right
   one is registered (there can be only one GUI). */
#include "action_list.h"


  /* Set up layers. */
  for (i = 0; i < MAX_LAYER; i++)
    {
      char buf[20];
      sprintf (buf, "signal%d", i + 1);
      Settings.DefaultLayerName[i] = strdup (buf);
      Settings.LayerColor[i] = "#c49350";
      Settings.LayerSelectedColor[i] = "#00ffff";
    }

  gui->parse_arguments (&argc, &argv);

  if (show_help || (argc > 1 && argv[1][0] == '-'))
    usage ();
  if (show_version)
    print_version ();
  if (show_defaults)
    print_defaults ();
  if (show_copyright)
    copyright ();

  settings_post_process ();


  if (show_actions)
    {
      print_actions ();
      exit (0);
    }

  if (do_dump_actions)
    {
      extern void dump_actions (void);
      dump_actions ();
      exit (0);
    }

  set_fontfile();

  /* Create a new PCB object in memory */
  PCB = CreateNewPCB ();

	if (PCB == NULL) {
		Message("Can't load the default pcb (%s) for creating an empty layout\n", Settings.DefaultPcbFile);
		exit(1);
	}

  /* Add silk layers to newly created PCB */
  CreateNewPCBPost (PCB, 1);
  if (argc > 1)
    command_line_pcb = argv[1];

  ResetStackAndVisibility ();

  if (gui->gui)
    InitCrosshair ();
  InitHandler ();
  InitBuffers ();
  SetMode (ARROW_MODE);

  if (command_line_pcb)
    {
      /* keep filename even if initial load command failed;
       * file might not exist
       */
      if (LoadPCB (command_line_pcb))
	PCB->Filename = strdup (command_line_pcb);
    }

  if (Settings.InitialLayerStack
      && Settings.InitialLayerStack[0])
    {
      LayerStringToLayerStack (Settings.InitialLayerStack);
    }

  /* This must be called before any other atexit functions
   * are registered, as it configures an atexit function to
   * clean up and free various items of allocated memory,
   * and must be the last last atexit function to run.
   */
  leaky_init ();

  /* Register a function to be called when the program terminates.
   * This makes sure that data is saved even if LEX/YACC routines
   * abort the program.
   * If the OS doesn't have at least one of them,
   * the critical sections will be handled by parse_l.l
   */
  atexit (EmergencySave);

  /* read the library file and display it if it's not empty
   */
  if (!ReadLibraryContents () && Library.MenuN)
    hid_action ("LibraryChanged");

#ifdef HAVE_LIBSTROKE
  stroke_init ();
#endif

  if (Settings.ScriptFilename)
    {
      Message (_("Executing startup script file %s\n"),
	       Settings.ScriptFilename);
      hid_actionl ("ExecuteFile", Settings.ScriptFilename, NULL);
    }
  if (Settings.ActionString)
    {
      Message (_("Executing startup action %s\n"), Settings.ActionString);
      hid_parse_actions (Settings.ActionString);
    }

  if (gui->printer || gui->exporter)
    {
      // Workaround to fix batch output for non-C locales
      setlocale(LC_NUMERIC,"C");
      gui->do_export (0);
      exit (0);
    }

#if HAVE_DBUS
  pcb_dbus_setup();
#endif

  EnableAutosave ();

#ifdef DEBUG
  printf ("Settings.FontPath            = \"%s\"\n", 
          Settings.FontPath);
  printf ("Settings.ElementPath         = \"%s\"\n", 
          Settings.ElementPath);
  printf ("Settings.LibrarySearchPaths  = \"%s\"\n", 
          Settings.LibrarySearchPaths);
  printf ("Settings.LibraryShell        = \"%s\"\n", 
          Settings.LibraryShell);
  printf ("Settings.MakeProgram = \"%s\"\n",
          UNKNOWN (Settings.MakeProgram));
  printf ("Settings.GnetlistProgram = \"%s\"\n",
          UNKNOWN (Settings.GnetlistProgram));
#endif

	buildin_init();

  gui->do_export (0);
#if HAVE_DBUS
  pcb_dbus_finish();
#endif

  return (0);
}