コード例 #1
0
ファイル: ev-previewer.c プロジェクト: GNOME/evince
gint
main (gint argc, gchar **argv)
{
    GtkApplication  *application;
    GOptionContext  *context;
    GError          *error = NULL;
    gchar           *path;
    int              status = 1;

#ifdef G_OS_WIN32
    if (fileno (stdout) != -1 &&
            _get_osfhandle (fileno (stdout)) != -1)
    {
        /* stdout is fine, presumably redirected to a file or pipe */
    }
    else
    {
        typedef BOOL (* WINAPI AttachConsole_t) (DWORD);

        AttachConsole_t p_AttachConsole =
            (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");

        if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS))
        {
            freopen ("CONOUT$", "w", stdout);
            dup2 (fileno (stdout), 1);
            freopen ("CONOUT$", "w", stderr);
            dup2 (fileno (stderr), 2);

        }
    }
#endif

#ifdef ENABLE_NLS
    /* Initialize the i18n stuff */
    bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir());
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
#endif

    context = g_option_context_new (_("GNOME Document Previewer"));
    g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
    g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);

    g_option_context_add_group (context, gtk_get_option_group (TRUE));

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_printerr ("Error parsing command line arguments: %s\n", error->message);
        g_error_free (error);
        g_option_context_free (context);
        return 1;
    }
    g_option_context_free (context);

    if (argc < 2) {
        g_printerr ("File argument is required\n");
        return 1;
    } else if (argc > 2) {
        g_printerr ("Too many files\n");
        return 1;
    }

    path = g_filename_from_uri (argv[1], NULL, NULL);
    if (!g_file_test (argv[1], G_FILE_TEST_IS_REGULAR) && !g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
        g_printerr ("Filename \"%s\" does not exist or is not a regular file\n", argv[1]);
        return 1;
    }
    g_free (path);

    if (!ev_init ())
        return 1;

    ev_stock_icons_init ();

    g_set_application_name (_("GNOME Document Previewer"));
    gtk_window_set_default_icon_name ("evince");

    application = gtk_application_new (NULL,
                                       G_APPLICATION_NON_UNIQUE |
                                       G_APPLICATION_HANDLES_OPEN);
    g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL);
    g_signal_connect (application, "open", G_CALLBACK (open_cb), NULL);

    status = g_application_run (G_APPLICATION (application), argc, argv);

    if (unlink_temp_file)
        ev_previewer_unlink_tempfile (argv[1]);
    if (print_settings)
        ev_previewer_unlink_tempfile (print_settings);

    ev_shutdown ();
    ev_stock_icons_shutdown ();

    return status;
}
コード例 #2
0
ファイル: memory-test.c プロジェクト: Codeminded/tinymail
int 
main (int argc, char **argv)
{
	GOptionContext *context;
	TnyAccountStore *account_store;
	TnyList *accounts;
	TnyStoreAccount *account;
	TnyIterator *iter, *topiter;
	TnyList *folders, *topfolders;
	TnyFolder *inbox;

	free (malloc (10));
	g_type_init ();

	context = g_option_context_new ("- The tinymail functional tester");
	g_option_context_add_main_entries (context, options, "tinymail");
	g_option_context_parse (context, &argc, &argv, NULL);

	account_store = tny_test_account_store_new (online, cachedir);

	if (cachedir)
		g_print ("Using %s as cache directory\n", cachedir);

	g_option_context_free (context);
	accounts = tny_simple_list_new ();

	tny_account_store_get_accounts (account_store, accounts, 
		TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
	g_object_unref (G_OBJECT (account_store));
	iter = tny_list_create_iterator (accounts);
	account = (TnyStoreAccount*) tny_iterator_get_current (iter);

	topfolders = tny_simple_list_new ();
	folders = tny_simple_list_new ();

	tny_folder_store_get_folders (TNY_FOLDER_STORE (account), topfolders, NULL, TRUE, NULL);
	topiter = tny_list_create_iterator (topfolders);
	inbox = TNY_FOLDER (tny_iterator_get_current (topiter));

	tny_folder_store_get_folders (TNY_FOLDER_STORE (inbox), folders, NULL, TRUE, NULL);

	if (iter)
		g_object_unref (iter);
	iter = tny_list_create_iterator (folders);

	while (!tny_iterator_is_done (iter))
	{
		TnyFolder *folder = (TnyFolder*) tny_iterator_get_current (iter);

		printf ("NAME=%s\n", tny_folder_get_name (folder));

		if (online)
			do_get_folder (folder);
		if (!justget)
			do_test_folder (folder);
		g_object_unref (G_OBJECT (folder));
		tny_iterator_next (iter);
	}

	g_object_unref (G_OBJECT (iter));
	g_object_unref (G_OBJECT (folders));

	g_object_unref (G_OBJECT (inbox));
	g_object_unref (G_OBJECT (topiter));
	g_object_unref (G_OBJECT (topfolders));

	g_object_unref (G_OBJECT (account));
	g_object_unref (G_OBJECT (accounts));

	return 0;
}
コード例 #3
0
int
main(int argc, char **argv)
{
  {
    GOptionContext *context;
    GError *error = NULL;

    context = g_option_context_new("cat without buffer");
    g_option_context_add_main_entries(context, entries, NULL);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
      g_print("failed to parse options: %s\n", error->message);
      g_error_free(error);
      g_option_context_free(context);
      return EXIT_FAILURE;
    }
    g_option_context_free(context);
  }

  {
    GTimer *timer;
    int i;

    timer = g_timer_new();
    for (i = 1; i < argc; i++) {
      const gchar *file_name = argv[i];
      int fd;

      fd = open(file_name, O_RDONLY);
      if (!fd) {
        continue;
      }

      {
        while (TRUE) {
          gchar *chunk;
          ssize_t read_size;
          chunk = g_malloc(chunk_size);
          read_size = read(fd, chunk, chunk_size);
          if (read_size == 0) {
            g_free(chunk);
            break;
          } else if (read_size == -1) {
            perror("read");
            g_free(chunk);
            break;
          } else {
            write(STDOUT_FILENO, chunk, read_size);
          }
          g_free(chunk);
        }
      }

      close(fd);
    }

    fprintf(stderr, "%f\n", g_timer_elapsed(timer, NULL));
    g_timer_destroy(timer);
  }

  return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: main.c プロジェクト: frankzhao/storaged
int
main (int    argc,
      char **argv)
{
  GError *error;
  GOptionContext *opt_context;
  gint ret;
  guint name_owner_id;
  guint sigint_id;

  ret = 1;
  loop = NULL;
  opt_context = NULL;
  name_owner_id = 0;
  sigint_id = 0;

  /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
  if (!g_setenv ("GIO_USE_VFS", "local", TRUE))
    {
      g_printerr ("Error setting GIO_USE_GVFS\n");
      goto out;
    }

  opt_context = g_option_context_new ("storaged storage daemon");
  g_option_context_add_main_entries (opt_context, opt_entries, NULL);
  error = NULL;
  if (!g_option_context_parse (opt_context, &argc, &argv, &error))
    {
      g_printerr ("Error parsing options: %s\n", error->message);
      g_error_free (error);
      goto out;
    }

  /* TODO: this hammer is too big - it would be a lot better to configure the
   *       logging routines and avoid printf(3) overhead and so on
   */
  if (opt_no_debug)
    {
      gint dev_null_fd;
      dev_null_fd = open ("/dev/null", O_RDWR);
      if (dev_null_fd >= 0)
        {
          dup2 (dev_null_fd, STDIN_FILENO);
          dup2 (dev_null_fd, STDOUT_FILENO);
          dup2 (dev_null_fd, STDERR_FILENO);
          close (dev_null_fd);
        }
      else
        {
          storaged_warning ("Error opening /dev/null: %m");
        }
    }

  if (g_getenv ("PATH") == NULL)
    g_setenv ("PATH", "/usr/bin:/bin:/usr/sbin:/sbin", TRUE);

  storaged_notice ("storaged daemon version %s starting", PACKAGE_VERSION);

  loop = g_main_loop_new (NULL, FALSE);

  sigint_id = 0;
  if (!opt_no_sigint)
    {
      sigint_id = g_unix_signal_add_full (G_PRIORITY_DEFAULT,
                                          SIGINT,
                                          on_sigint,
                                          NULL,  /* user_data */
                                          NULL); /* GDestroyNotify */
    }

  name_owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
                                  "org.storaged.Storaged",
                                  G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
                                    (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
                                  on_bus_acquired,
                                  on_name_acquired,
                                  on_name_lost,
                                  NULL,
                                  NULL);


  storaged_debug ("Entering main event loop");

  g_main_loop_run (loop);

  ret = 0;

 out:
  if (sigint_id > 0)
    g_source_remove (sigint_id);
  if (the_daemon != NULL)
    g_object_unref (the_daemon);
  if (name_owner_id != 0)
    g_bus_unown_name (name_owner_id);
  if (loop != NULL)
    g_main_loop_unref (loop);
  if (opt_context != NULL)
    g_option_context_free (opt_context);

  storaged_notice ("storaged daemon version %s exiting", PACKAGE_VERSION);

  return ret;
}
コード例 #5
0
ファイル: gtkdialog.c プロジェクト: alexis-82/gtkdialog
/*
 * FIXME: we maybe should break these options to some groups...
 */
void 
gtkdialog_init(
		int   argc, 
		char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    static GOptionEntry entries[] = {
	{ 
		"version", 'v', 
		0, G_OPTION_ARG_NONE, &option_version, 
		"Print version information and exit.", NULL
	},
	{ 
		"debug", 'd', 
		0, G_OPTION_ARG_NONE, &option_debug, 
		"Debug mode prints the processed characters.", NULL
	},
	{ 
		"program", 'p', 
		0, G_OPTION_ARG_STRING, &option_input_variable, 
		"Get the GUI description from the environment.", "variable"
	},
#if HAVE_GLADE_LIB
	{ 
		"glade-xml", 'g', 
		0, G_OPTION_ARG_STRING, &option_glade_file, 
		"Get the GUI description from this Glade file.", "filename"
	},
#else
	{ 
		"glade-xml", 'g', 
		0, G_OPTION_ARG_STRING, &option_ignored, 
		"Ignored, since no Glade library found.", "filename"
	},
#endif
	{ 
		"file", 'f', 
		0, G_OPTION_ARG_STRING, &option_input_file, 
		"Get the GUI description from a regular file.", "filename"
	},
	{ 
		"include", 'i', 
		0, G_OPTION_ARG_STRING, &option_include_file, 
		"Include the given file when executing.", "filename"
	},
	{ 
		"event-driven", 'e', 
		0, G_OPTION_ARG_STRING, &option_event_file, 
		"Execute the file as an event driven program.", "filename"
	},
	{ 
		"stdin", 's', 
		0, G_OPTION_ARG_NONE, &option_input_stdin, 
		"Get the GUI description from standard input.", NULL
	},
	{ 
		"no-warning", 'w', 
		0, G_OPTION_ARG_NONE, &option_no_warning, 
		"Suppress warning messages.", NULL
	},
	{ 
		"geometry", 'G', 
		G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &option_geometry, 
		"The placement and the size of the window.", "[XxY][+W+H]"
	},
	{ 
		"center", 'c', 
		0, G_OPTION_ARG_NONE, &option_centering, 
		"Center the windows on the screen.", NULL
	},
	{ 
		"print-ir", '\0', 
		0, G_OPTION_ARG_NONE, &option_print_ir, 
		"Print the internal representation and exit.", NULL
	},
	{ 
		"space-expand", '\0', 
		0, G_OPTION_ARG_STRING, &option_space_expand, 
		"The \"expand\" state for packing all widgets.", "state"
	},
	{ 
		"space-fill", '\0', 
		0, G_OPTION_ARG_STRING, &option_space_fill, 
		"The \"fill\" state for packing all widgets.", "state"
	},
	{
		NULL
	}
    };

#ifdef DEBUG
	{
		gint deb;
		PIP_DEBUG("argc: %d", argc);
		for (deb = 0; deb < argc; ++deb)
			PIP_DEBUG("  argv[%d] = '%s'", deb, argv[deb]);
	}
#endif
	/*
	 * Maybe the command line options are coming from the kernel and it did
	 * not slice it.
	 */
	if (argc > 1 && g_utf8_strchr(argv[1], -1, ' ') != NULL) {
		gint   optionindex;
		gchar *tmp;
		gchar *command_line;

		PIP_DEBUG("Must re-slice the options.");
		/*
		 * The most simple solution is to reassemble the whole command
		 * line and slice it again.
		 */
		tmp = g_strdup(argv[0]);
		for (optionindex = 1; optionindex < argc; ++optionindex) {
			PIP_DEBUG("argv[%d] = '%s'", optionindex, 
					argv[optionindex]);
			command_line = g_strconcat(
					tmp, 
					" ", 
					argv[optionindex], 
					NULL);
			g_free(tmp);
			tmp = command_line;
		}
		/* 
		 * Splitting the command line again.
		 */
		PIP_DEBUG("Full command line: '%s'", command_line);
		argv = g_strsplit_set(command_line, " \t", 256);
		g_free(command_line);
		/*
		 * Re-calculating argc.
		 */
		argc = 0;
		while (argv[argc] != NULL)
			++argc;
#ifdef DEBUG
		{
			gint deb;
			PIP_DEBUG("Re sliced...");
			PIP_DEBUG("argc: %d", argc);
			for (deb = 0; deb < argc; ++deb)
				PIP_DEBUG("  argv[%d] = '%s'", deb, argv[deb]);
		}
#endif
	}
	

	context = g_option_context_new(
"\n"
"Create dialog boxes and windows according to the given dialog description.\n"
"For more information try 'info gtkdialog'."
);

	g_option_context_add_main_entries(context, entries, PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group(FALSE));

	if (!g_option_context_parse(context, &argc, &argv, &error)) 
		g_error("Error parsing command line options: %s", 
				error->message);

	g_option_context_free(context);
}
コード例 #6
0
ファイル: main.c プロジェクト: 273657127/HandBrake
int
main (int argc, char *argv[])
{
	signal_user_data_t *ud;
	GValue *preset;
	GError *error = NULL;
	GOptionContext *context;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	if (!g_thread_supported())
		g_thread_init(NULL);
	context = g_option_context_new ("- Rip and encode DVD or MPEG file");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
#if !defined(_WIN32)
	g_option_context_add_group (context, gst_init_get_option_group ());
#endif
	g_option_context_parse (context, &argc, &argv, &error);
	g_option_context_free(context);

	if (argc > 1 && dvd_device == NULL && argv[1][0] != '-')
	{
		dvd_device = argv[1];
	}
	
	gtk_set_locale ();
	gtk_init (&argc, &argv);
	gtk_rc_parse_string(hud_rcstyle);
	g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON));
	g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL);
#if !defined(_WIN32)
	notify_init("HandBrake");
#endif
	ghb_register_transforms();
	ghb_resource_init();
	ghb_load_icons();

#if !defined(_WIN32)
	dbus_g_thread_init();
#endif
	ghb_udev_init();

	ghb_write_pid_file();
	ud = g_malloc0(sizeof(signal_user_data_t));
	ud->debug = ghb_debug;
	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud);
	g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud);
	//g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud);
	ud->settings = ghb_settings_new();
	ud->builder = create_builder_or_die (BUILDER_NAME);
	// Enable events that alert us to media change events
	watch_volumes (ud);

	//GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom");
	//gtk_entry_set_inner_border(widget, 2);

	// Since GtkBuilder no longer assigns object ids to widget names
	// Assign a few that are necessary for style overrides to work
	GtkWidget *widget;
#if defined(_NO_UPDATE_CHECK)
	widget = GHB_WIDGET(ud->builder, "check_updates_box");
	gtk_widget_hide(widget);
#endif

	widget = GHB_WIDGET(ud->builder, "preview_hud");
	gtk_widget_set_name(widget, "preview_hud");
	widget = GHB_WIDGET(ud->builder, "preview_window");
	gtk_widget_set_name(widget, "preview_window");

	// Set up the "hud" control overlay for the preview window
	GtkWidget *draw, *hud, *blender, *align;

	align = GHB_WIDGET(ud->builder, "preview_window_alignment");
	draw = GHB_WIDGET(ud->builder, "preview_image_align");
	hud = GHB_WIDGET(ud->builder, "preview_hud");

	// Set up compositing for hud
	blender = ghb_compositor_new();

	gtk_container_add(GTK_CONTAINER(align), blender);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1);
	ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85);
	gtk_widget_show(blender);

	// Redirect stderr to the activity window
	ghb_preview_init(ud);
	IoRedirect(ud);
	ghb_log( "%s - %s - %s",
		HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE );
	ghb_init_dep_map();

	// Need to connect x264_options textview buffer to the changed signal
	// since it can't be done automatically
	GtkTextView *textview;
	GtkTextBuffer *buffer;
	textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "x264Option"));
	buffer = gtk_text_view_get_buffer (textview);
	g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud);

	ghb_combo_init(ud);

	g_debug("ud %p\n", ud);
	g_debug("ud->builder %p\n", ud->builder);

	bind_audio_tree_model(ud);
	bind_subtitle_tree_model(ud);
	bind_presets_tree_model(ud);
	bind_queue_tree_model(ud);
	bind_chapter_tree_model(ud);
	// Connect up the signals to their callbacks
	// I wrote my own connector so that I could pass user data
	// to the callbacks.  Builder's standard autoconnect doesn't all this.
	gtk_builder_connect_signals_full (ud->builder, MyConnect, ud);

	// Load all internal settings
	ghb_settings_init(ud);
	// Load the presets files
	ghb_presets_load(ud);
	ghb_prefs_load(ud);

	ghb_prefs_to_ui(ud);

	gint logLevel;
	logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel");
	ghb_backend_init(logLevel);

	if (ghb_settings_get_boolean(ud->settings, "hbfd"))
	{
		ghb_hbfd(ud, TRUE);
	}
	gchar *source = ghb_settings_get_string(ud->settings, "default_source");
	ghb_dvd_set_current(source, ud);
	g_free(source);

	// Parsing x264 options "" initializes x264 widgets to proper defaults
	ghb_x264_parse_options(ud, "");

	// Populate the presets tree view
	ghb_presets_list_init(ud, NULL, 0);
	// Get the first preset name
	if (arg_preset != NULL)
	{
		preset = ghb_parse_preset_path(arg_preset);
		if (preset)
		{
			ghb_select_preset(ud->builder, preset);
			ghb_value_free(preset);
		}
	}
	else
	{
		ghb_select_default_preset(ud->builder);
	}

	// Grey out widgets that are dependent on a disabled feature
	ghb_check_all_depencencies (ud);

	if (dvd_device != NULL)
	{
		// Source overridden from command line option
		ghb_settings_set_string(ud->settings, "scan_source", dvd_device);
		g_idle_add((GSourceFunc)ghb_idle_scan, ud);
	}
	// Reload and check status of the last saved queue
	g_idle_add((GSourceFunc)ghb_reload_queue, ud);

	// Start timer for monitoring libhb status, 500ms
	g_timeout_add (500, ghb_timer_cb, (gpointer)ud);

	// Add dvd devices to File menu
	ghb_volname_cache_init();
	g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL);

	GtkStatusIcon *si;
	si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

	gtk_status_icon_set_visible(si,
			ghb_settings_get_boolean(ud->settings, "show_status"));

#if GTK_CHECK_VERSION(2, 16, 0)
	gtk_status_icon_set_has_tooltip(si, TRUE);
	g_signal_connect(si, "query-tooltip", 
					status_icon_query_tooltip_cb, ud);
#else
	gtk_status_icon_set_tooltip(si, "HandBrake");
#endif

	// Ugly hack to keep subtitle table from bouncing around as I change
	// which set of controls are visible
	GtkRequisition req;
	gint height;
	
	widget = GHB_WIDGET(ud->builder, "SrtCodeset");
	gtk_widget_size_request( widget, &req );
	height = req.height;
	widget = GHB_WIDGET(ud->builder, "srt_code_label");
	gtk_widget_size_request( widget, &req );
	height += req.height;
	widget = GHB_WIDGET(ud->builder, "subtitle_table");
	gtk_widget_set_size_request(widget, -1, height);
	
	// Everything should be go-to-go.  Lets rock!

	gtk_main ();
	gtk_status_icon_set_visible(si, FALSE);
	ghb_backend_close();
	if (ud->queue)
		ghb_value_free(ud->queue);
	ghb_value_free(ud->settings);
	g_io_channel_unref(ud->activity_log);
	ghb_settings_close();
#if !defined(_WIN32)
	notify_uninit();
#endif
	g_free(ud);

	return 0;
}
int
main (int argc, char *argv[])
{
  GError *error = NULL;
  GOptionContext *context;
  JsonGenerator *gen;
  JsonNode *root;
  JsonObject *obj;
  JsonArray *array;
  int i;
  char *data;

  context = g_option_context_new ("- ISOM parsing test");
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gst_init_get_option_group ());
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_print ("option parsing failed: %s", error->message);
    exit (1);
  }
  g_option_context_free (context);

  if (argc < 2) {
    g_print ("need filename\n");
    exit (1);
  }

  array = json_array_new ();
  for (i = 1; i < argc; i++) {
    GssIsomParser *file;
    GssIsomTrack *video_track;
    GssIsomTrack *audio_track;
    JsonObject *object;
    JsonObject *o;
    gboolean ret;

    file = gss_isom_parser_new ();

    ret = gss_isom_parser_parse_file (file, argv[i]);
    if (!ret) {
      g_print ("parse failed");
      continue;
    }

    video_track = gss_isom_movie_get_video_track (file->movie);
    audio_track = gss_isom_movie_get_audio_track (file->movie);

    object = json_object_new ();
    json_object_set_string_member (object, "filename", argv[i]);
    if (video_track) {
      char *codec;

      o = json_object_new ();
      json_object_set_int_member (o, "track_id", video_track->tkhd.track_id);
      json_object_set_int_member (o, "bitrate", video_track->esds.avg_bitrate);
      codec = g_strdup_printf ("avc1.%02x%02x%02x",
          video_track->esds.codec_data[1],
          video_track->esds.codec_data[2], video_track->esds.codec_data[3]);
      json_object_set_string_member (o, "codec", codec);
      g_free (codec);
      json_object_set_string_member (o, "iv", random_iv_string ());
      json_object_set_object_member (object, "video", o);
    }
    if (audio_track) {
      o = json_object_new ();
      json_object_set_int_member (o, "track_id", audio_track->tkhd.track_id);
      json_object_set_int_member (o, "bitrate", audio_track->esds.avg_bitrate);
      json_object_set_string_member (o, "codec", "mp4a.40.2");  /* AAC LC */
      json_object_set_string_member (o, "iv", random_iv_string ());
      json_object_set_object_member (object, "audio", o);
    }

    json_array_add_object_element (array, object);

    gss_isom_parser_free (file);
  }

  obj = json_object_new ();
  json_object_set_int_member (obj, "version", 0);
  json_object_set_array_member (obj, "media", array);

  root = json_node_new (JSON_NODE_OBJECT);
  json_node_take_object (root, obj);
  gen = g_object_new (JSON_TYPE_GENERATOR,
      "root", root, "pretty", TRUE, "indent", 2, NULL);
  data = json_generator_to_data (gen, NULL);
  g_object_unref (gen);
  json_node_free (root);

  g_print ("%s\n", data);

  return 0;
}
コード例 #8
0
/* Main program */
gint
main (gint argc, gchar **argv)
{
  GError *error = NULL;
  GOptionContext *context = NULL;
  gint i;

  context = g_option_context_new ("- run Grilo plugin as UPnP service");
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, grl_init_get_option_group ());
  g_option_context_parse (context, &argc, &argv, &error);
  g_option_context_free (context);

  if (error) {
    g_printerr ("Invalid arguments, %s\n", error->message);
    g_clear_error (&error);
    return -1;
  }

  /* Adjust limits */
  limit = CLAMP (limit, 0, G_MAXINT);
  if (limit == 0) {
    limit = G_MAXINT;
  }

  /* Initialize grilo */
  grl_init (&argc, &argv);
  registry = grl_registry_get_default ();
  if (!registry) {
    g_printerr ("Unable to load Grilo registry\n");
    return -1;
  }

  /* Register a key to store parent */
  GRL_METADATA_KEY_GRILO_MS2_PARENT =
    grl_registry_register_metadata_key (registry,
                                        g_param_spec_string ("grilo-mediaserver2-parent",
                                                             "GriloMediaServer2Parent",
                                                             "Object path to parent container",
                                                             NULL,
                                                             G_PARAM_READWRITE),
                                        GRL_METADATA_KEY_INVALID,
                                        NULL);

  if (GRL_METADATA_KEY_GRILO_MS2_PARENT == GRL_METADATA_KEY_INVALID) {
    g_error ("Unable to register Parent key");
    return 1;
  }

  /* Load configuration */
  load_config ();

  /* Initialize <grilo-plugin, ms2-server> pairs */
  servers = g_hash_table_new_full (g_str_hash,
                                   g_str_equal,
                                   g_free,
                                   g_object_unref);

  g_signal_connect (registry, "source-added",
                    G_CALLBACK (source_added_cb), NULL);

  g_signal_connect (registry, "source-removed",
                    G_CALLBACK (source_removed_cb), NULL);

  if (!args || !args[0]) {
    grl_registry_load_all_plugins (registry, TRUE, NULL);
  } else {
    for (i = 0; args[i]; i++) {
      grl_registry_load_plugin (registry, args[i], NULL);
    }
  }

  g_main_loop_run (g_main_loop_new (NULL, FALSE));
}
コード例 #9
0
ファイル: nmtui.c プロジェクト: heftig/NetworkManager
int
main (int argc, char **argv)
{
	gboolean got_connections = FALSE;
	GOptionContext *opts;
	GError *error = NULL;
	NmtuiStartupData startup_data;
	const char *prgname;
	int i;

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

	opts = g_option_context_new (NULL);
	g_option_context_add_main_entries (opts, entries, NULL);

	if (!g_option_context_parse (opts, &argc, &argv, &error)) {
		g_printerr ("%s: %s: %s\n",
		            argv[0],
		            _("Could not parse arguments"),
		            error->message);
		exit (1);
	}
	g_option_context_free (opts);

	nm_editor_bindings_init ();

	nm_client = nm_client_new ();
	if (!nm_client_get_manager_running (nm_client)) {
		g_printerr ("%s\n", _("NetworkManager is not running."));
		exit (1);
	}

	nm_settings = nm_remote_settings_new (NULL);
	g_signal_connect (nm_settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
	                  G_CALLBACK (connections_read), &got_connections);
	while (!got_connections)
		g_main_context_iteration (NULL, TRUE);

	if (sleep_on_startup)
		sleep (5);

	startup_data.subprogram = NULL;
	prgname = g_get_prgname ();
	if (g_str_has_prefix (prgname, "lt-"))
		prgname += 3;
	if (!strcmp (prgname, "nmtui")) {
		if (argc > 1) {
			for (i = 0; i < num_subprograms; i++) {
				if (!strcmp (argv[1], subprograms[i].name)) {
					argc--;
					argv[0] = (char *) subprograms[i].shortcut;
					memmove (&argv[1], &argv[2], argc * sizeof (char *));
					startup_data.subprogram = subprograms[i].func;
					break;
				}
			}
		} else
			startup_data.subprogram = nmtui_main;
	} else {
		for (i = 0; i < num_subprograms; i++) {
			if (!strcmp (prgname, subprograms[i].shortcut)) {
				startup_data.subprogram = subprograms[i].func;
				break;
			}
		}
	}
	if (!startup_data.subprogram)
		usage ();

	if (!noinit)
		nmt_newt_init ();

	startup_data.argc = argc;
	startup_data.argv = argv;
	g_idle_add (idle_run_subprogram, &startup_data);
	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	if (!noinit)
		nmt_newt_finished ();

	g_object_unref (nm_client);
	g_object_unref (nm_settings);

	return 0;
}
コード例 #10
0
ファイル: mdmflexiserver.c プロジェクト: RavetcoFX/mdm
int
main (int argc, char *argv[])
{
	GtkWidget *dialog;
	char *ret;
	const char *message;
	GOptionContext *ctx;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	/* Option parsing */
	ctx = g_option_context_new ("- New mdm login");
	g_option_context_add_main_entries (ctx, options, _("main options"));
	g_option_context_parse (ctx, &argc, &argv, NULL);
	g_option_context_free (ctx);

	mdm_log_init ();
	mdm_log_set_debug (debug_in);

	if (send_command != NULL) {
		if ( ! mdmcomm_is_daemon_running (FALSE)) {
			mdm_common_error (_("Error: MDM (MDM Display Manager) is not running."));
			mdm_common_error (_("You might be using a different display manager."));
			return 1;
		}
	} else {
		/*
		 * The --command argument does not display anything, so avoid
		 * running gtk_init until it finishes.  Sometimes the
		 * --command argument is used when there is no display so it
		 * will fail and cause the program to exit, complaining about
		 * "no display".
		 */
		gtk_init (&argc, &argv);

		if ( ! mdmcomm_is_daemon_running (TRUE)) {
			return 1;
		}
	}
	
	mdmcomm_open_connection_to_daemon ();

	/* Process --command option */

	g_type_init ();

	if (send_command != NULL) {

		/* gdk_init is needed for cookie code to get display */
		gdk_init (&argc, &argv);
		if (authenticate)
			auth_cookie = mdmcomm_get_auth_cookie ();

		/*
		 * If asking for a translatable config value, then try to get
		 * the translated value first.  If this fails, then go ahead
		 * and call the normal sockets command.
		 */
		if (strncmp (send_command, MDM_SUP_GET_CONFIG " ",
		    strlen (MDM_SUP_GET_CONFIG " ")) == 0) {
			gchar *value = NULL;
			const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")];

			if (is_key (MDM_KEY_WELCOME, key)) {
				value = mdm_config_get_translated_string ((gchar *)key);
				if (value != NULL) {
					ret = g_strdup_printf ("OK %s", value);
				}
			}

			/*
			 * If the above didn't return a value, then must be a
			 * different key, so call the daemon.
			 */
			if (value == NULL)
				ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5);
		} else {
			ret = mdmcomm_send_cmd_to_daemon_with_args (send_command, auth_cookie, 5);
		}

		/* At this point we are done using the socket, so close it */
		mdmcomm_close_connection_to_daemon ();

		if (ret != NULL) {
			g_print ("%s\n", ret);
			return 0;
		} else {
			dialog = hig_dialog_new (NULL /* parent */,
						 GTK_DIALOG_MODAL /* flags */,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_OK,
						 _("Cannot communicate with MDM "
						   "(The MDM Display Manager)"),
						 _("Perhaps you have an old version "
						   "of MDM running."));
			gtk_widget_show_all (dialog);
			gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);
			return 1;
		}
	}

	/*
	 * Always attempt to get cookie and authenticate.  On remote
	 * servers
	 */
	auth_cookie = mdmcomm_get_auth_cookie ();
	
	/* check for other displays/logged in users */
	check_for_users ();

	if (auth_cookie == NULL) {

		/* At this point we are done using the socket, so close it */
		mdmcomm_close_connection_to_daemon ();

		dialog = hig_dialog_new (NULL /* parent */,
					 GTK_DIALOG_MODAL /* flags */,
					 GTK_MESSAGE_ERROR,
					 GTK_BUTTONS_OK,
					 _("You do not seem to be logged in on the "
					   "console"),
					 _("Starting a new login only "
					   "works correctly on the console."));
		gtk_dialog_set_has_separator (GTK_DIALOG (dialog),
					      FALSE);
		gtk_widget_show_all (dialog);
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
		return 1;
	}
	
	ret = mdmcomm_send_cmd_to_daemon_with_args (MDM_SUP_FLEXI_XSERVER, auth_cookie, 5);

	g_free (auth_cookie);
	g_strfreev (args_remaining);

	/* At this point we are done using the socket, so close it */
	mdmcomm_close_connection_to_daemon ();

	if (ret != NULL &&
	    strncmp (ret, "OK ", 3) == 0) {

		/* if we switched to a different screen as a result of this,
		 * lock the current screen */
		if ( ! no_lock ) {
			maybe_lock_screen ();
		}

		/* all fine and dandy */
		g_free (ret);
		return 0;
	}

	message = mdmcomm_get_error_message (ret);

	dialog = hig_dialog_new (NULL /* parent */,
				 GTK_DIALOG_MODAL /* flags */,
				 GTK_MESSAGE_ERROR,
				 GTK_BUTTONS_OK,
				 _("Cannot start new display"),
				 message);

	gtk_widget_show_all (dialog);
	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);
	g_free (ret);

	return 1;
}
コード例 #11
0
int
main (int argc, char *argv[])
{
  static gboolean print_all = FALSE;
  static gboolean print_aii = FALSE;
  GOptionEntry options[] = {
    {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all,
        N_("Print all elements"), NULL},
    {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii,
        N_("Print a machine-parsable list of features the specified plugin "
              "provides.\n                                       "
              "Useful in connection with external automatic plugin "
              "installation mechanisms"), NULL},
    GST_TOOLS_GOPTION_VERSION,
    {NULL}
  };
  GOptionContext *ctx;
  GError *err = NULL;

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

  if (!g_thread_supported ())
    g_thread_init (NULL);

  ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
  g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
  g_option_context_add_group (ctx, gst_init_get_option_group ());
  if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
    g_print ("Error initializing: %s\n", err->message);
    exit (1);
  }
  g_option_context_free (ctx);

  gst_tools_print_version ("gst-inspect");

  if (print_all && argc > 2) {
    g_print ("-a requires no extra arguments\n");
    return 1;
  }

  /* if no arguments, print out list of elements */
  if (argc == 1 || print_all) {
    print_element_list (print_all);
    /* else we try to get a factory */
  } else {
    GstElementFactory *factory;
    GstPlugin *plugin;
    const char *arg = argv[argc - 1];
    int retval;

    factory = gst_element_factory_find (arg);
    /* if there's a factory, print out the info */
    if (factory) {
      retval = print_element_info (factory, print_all);
      gst_object_unref (factory);
    } else {
      retval = print_element_features (arg);
    }

    /* otherwise check if it's a plugin */
    if (retval) {
      plugin = gst_default_registry_find_plugin (arg);

      /* if there is such a plugin, print out info */
      if (plugin) {
        if (print_aii) {
          print_plugin_automatic_install_info (plugin);
        } else {
          print_plugin_info (plugin);
          print_plugin_features (plugin);
        }
      } else {
        GError *error = NULL;

        if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
          plugin = gst_plugin_load_file (arg, &error);

          if (plugin) {
            if (print_aii) {
              print_plugin_automatic_install_info (plugin);
            } else {
              print_plugin_info (plugin);
              print_plugin_features (plugin);
            }
          } else {
            g_print (_("Could not load plugin file: %s\n"), error->message);
            g_error_free (error);
            return -1;
          }
        } else {
          g_print (_("No such element or plugin '%s'\n"), arg);
          return -1;
        }
      }
    }
  }

  return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: zonbrisad/makeplates
int main(int argc, char *argv[]) {
	GError *error = NULL;
	GOptionContext *context;
	
  atexit(safeExit);

	// init log system
	gp_log_init(APP_LOGFILE);
  
  // Get some application/host data
  appInfo();
/*
  if (isAppRunning()) {
    printf("Application is already running\n");
    exit(0);
    g_critical("Application is already running");
  }
  */
  // parse command line arguments
  context = g_option_context_new (APP_DESCRIPTION);
  g_option_context_add_main_entries (context, entries, NULL);
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_print ("option parsing failed: %s\n", error->message);
    exit (1);
  }

	// enable verbose mode
	if (opt_verbose) {
	  gp_log_set_verbose(TRUE);  
	}
  
  g_message("Program start\n");
	
  // print version information
	if (opt_version) {
		printf("Program version %s\nBuild ("__DATE__" "__TIME__")\n", APP_VERSION);
		exit(0);
	}
	
	
	// Error Test
	if (opt_errorTest) {
		errorTest();
		exit(0);
	}
	
	// thread test
	if (opt_threadTest) { 
		threadTest();
		exit(0);
	}
  
	// info test
	if (opt_info) { 
		infoTest();
		exit(0);
	}

	// daemon test
	if (opt_daemonTest) { 
		daemonTest();
		exit(0);
	}
	
	// queue test
	if (opt_queueTest) {
	  queueTest();
		exit(0);
	}

	// pipe test
	 if (opt_pipeTest) {
	  pipeTest();
		exit(0);
	}
	
	// domain socket test 
	if (opt_domainTest) {
	  domainTest();
		exit(0);
	}
	

	return 0;
}
コード例 #13
0
int
main (int argc, char *argv[])
{
  CORBA_ORB orb;
  CORBA_Environment ev;
  CosNaming_NamingContext context;
  const char*		progname = "matecorba-name-server";
  
#ifdef HAVE_SYSLOG
  openlog(progname, LOG_NDELAY | LOG_PID, LOG_DAEMON);
  syslog(LOG_INFO,"starting");
#endif

#ifdef HAVE_SIGACTION
  {
  	sigset_t empty_mask;
  	struct sigaction act;
  	sigemptyset(&empty_mask);
  	act.sa_handler = signal_handler;
  	act.sa_mask    = empty_mask;
  	act.sa_flags   = 0;
  
  	sigaction(SIGINT,  &act, NULL);
  	sigaction(SIGHUP,  &act, NULL);
  	sigaction(SIGSEGV, &act, NULL);
  	sigaction(SIGABRT, &act, NULL);
  
  	act.sa_handler = SIG_IGN;
  	sigaction(SIGPIPE, &act, NULL);
  }
#else
  signal(SIGINT, signal_handler);
#ifdef SIGHUP
  signal(SIGHUP, signal_handler);
#endif
  signal(SIGSEGV, signal_handler);
  signal(SIGABRT, signal_handler);
#ifdef SIGPIPE
  signal(SIGPIPE, SIG_IGN);
#endif
#endif

  CORBA_exception_init (&ev);
  orb = CORBA_ORB_init (&argc, argv, "matecorba-local-orb", &ev);
  
  {
        GOptionContext *context;
        GError *error = NULL;
        gboolean result;

        context = g_option_context_new("");
        g_option_context_add_main_entries(context, goptions, GETTEXT_PACKAGE);

        result = g_option_context_parse(context, &argc, &argv, &error);
        g_option_context_free(context);

        if (!result) {
            g_warning("%s: bad arguments: %s\n",
                      progname, error->message);
            g_error_free(error);
	    exit(1);
        }
  }

  {
  	PortableServer_POA root_poa;
      	PortableServer_POAManager pm;
  	root_poa = (PortableServer_POA)
    	  CORBA_ORB_resolve_initial_references (orb, "RootPOA", &ev);
  	context = MateCORBA_CosNaming_NamingContextExt_create (root_poa, &ev);
      	pm = PortableServer_POA__get_the_POAManager (root_poa, &ev);
      	PortableServer_POAManager_activate (pm, &ev);
      	CORBA_Object_release((CORBA_Object)pm, &ev);
  	CORBA_Object_release((CORBA_Object)root_poa, &ev);
  }

  {
      	CORBA_char *objstr;
      	objstr = CORBA_ORB_object_to_string (orb, context, &ev);
      	g_print ("%s\n", objstr);
      	fflush (stdout);
      	CORBA_free(objstr);
  }
  if ( opt_corbaloc_key ) {
	CORBA_sequence_CORBA_octet	okey;
	okey._length = strlen(opt_corbaloc_key);
	okey._buffer = opt_corbaloc_key;
  	MateCORBA_ORB_forw_bind(orb, &okey, context, &ev);
  }


  CORBA_ORB_run (orb, &ev);

  /* Don't release until done (dont know why) */
  CORBA_Object_release (context, &ev);

#ifdef HAVE_SYSLOG
  syslog(LOG_INFO, "exiting");
#endif
  return 0;
}
コード例 #14
0
ファイル: mysql-proxy-cli.c プロジェクト: vinchen/mysql-proxy
/**
 * This is the "real" main which is called both on Windows and UNIX platforms.
 * For the Windows service case, this will also handle the notifications and set
 * up the logging support appropriately.
 */
int main_cmdline(int argc, char **argv) {
	chassis *srv = NULL;
#ifdef HAVE_SIGACTION
	static struct sigaction sigsegv_sa;
#endif
	/* read the command-line options */
	GOptionContext *option_ctx = NULL;
	GOptionEntry *main_entries = NULL;
	chassis_frontend_t *frontend = NULL;
	chassis_options_t *opts = NULL;

	GError *gerr = NULL;
	chassis_log *log = NULL;

	/* a little helper macro to set the src-location that we stepped out at to exit */
#define GOTO_EXIT(status) \
	exit_code = status; \
	exit_location = G_STRLOC; \
	goto exit_nicely;

	int exit_code = EXIT_SUCCESS;
	const gchar *exit_location = G_STRLOC;

	if (chassis_frontend_init_glib()) { /* init the thread, module, ... system */
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* start the logging ... to stderr */
	log = chassis_log_new();
	log->min_lvl = G_LOG_LEVEL_MESSAGE; /* display messages while parsing or loading plugins */
	g_log_set_default_handler(chassis_log_func, log);

#ifdef _WIN32
	if (chassis_win32_is_service() && chassis_log_set_event_log(log, g_get_prgname())) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	if (chassis_frontend_init_win32()) { /* setup winsock */
		GOTO_EXIT(EXIT_FAILURE);
	}
#endif

	/* may fail on library mismatch */
	if (NULL == (srv = chassis_new())) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	srv->log = log; /* we need the log structure for the log-rotation */

	frontend = chassis_frontend_new();
	option_ctx = g_option_context_new("- MySQL Proxy");
	/**
	 * parse once to get the basic options like --defaults-file and --version
	 *
	 * leave the unknown options in the list
	 */
	if (chassis_frontend_init_base_options(option_ctx,
				&argc, &argv,
				&(frontend->print_version),
				&(frontend->default_file),
				&gerr)) {
		g_critical("%s: %s",
				G_STRLOC,
				gerr->message);
		g_clear_error(&gerr);

		GOTO_EXIT(EXIT_FAILURE);
	}

	if (frontend->default_file) {
		srv->default_file = g_strdup(frontend->default_file); //add by vinchen/CFR
		if (!(frontend->keyfile = chassis_frontend_open_config_file(frontend->default_file, &gerr))) {
			g_critical("%s: loading config from '%s' failed: %s",
					G_STRLOC,
					frontend->default_file,
					gerr->message);
			g_clear_error(&gerr);
			GOTO_EXIT(EXIT_FAILURE);
		}
	}

	/* print the main version number here, but don't exit
	 * we check for print_version again, after loading the plugins (if any)
	 * and print their version numbers, too. then we exit cleanly.
	 */
	if (frontend->print_version) {
#ifndef CHASSIS_BUILD_TAG
#define CHASSIS_BUILD_TAG PACKAGE_STRING
#endif
		g_print("%s" CHASSIS_NEWLINE, CHASSIS_BUILD_TAG); 
		chassis_frontend_print_version();
	}
	
	/* add the other options which can also appear in the configfile */
	opts = chassis_options_new();
	chassis_frontend_set_chassis_options(frontend, opts);
	main_entries = chassis_options_to_g_option_entries(opts);
	g_option_context_add_main_entries(option_ctx, main_entries, NULL);

	/**
	 * parse once to get the basic options 
	 *
	 * leave the unknown options in the list
	 */
	if (FALSE == g_option_context_parse(option_ctx, &argc, &argv, &gerr)) {
		g_critical("%s", gerr->message);

		GOTO_EXIT(EXIT_FAILURE);
	}

	if (frontend->keyfile) {
		if (chassis_keyfile_to_options(frontend->keyfile, "mysql-proxy", main_entries)) {
			GOTO_EXIT(EXIT_FAILURE);
		}
	}

	//add by vinchen/CFR
	if (frontend->base_dir != NULL)
		srv->base_dir_org = g_strdup(frontend->base_dir);

	if (chassis_frontend_init_basedir(argv[0], &(frontend->base_dir))) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* basic setup is done, base-dir is known, ... */
	frontend->lua_subdirs = g_new(char *, 2);
	frontend->lua_subdirs[0] = g_strdup("mysql-proxy");
	frontend->lua_subdirs[1] = NULL;

	if (chassis_frontend_init_lua_path(frontend->lua_path, frontend->base_dir, frontend->lua_subdirs)) {
		GOTO_EXIT(EXIT_FAILURE);
	}
	
	if (chassis_frontend_init_lua_cpath(frontend->lua_cpath, frontend->base_dir, frontend->lua_subdirs)) {
		GOTO_EXIT(EXIT_FAILURE);
	}

	/* assign the mysqld part to the */
	network_mysqld_init(srv); /* starts the also the lua-scope, LUA_PATH and LUA_CPATH have to be set before this being called */


#ifdef HAVE_SIGACTION
	/* register the sigsegv interceptor */

	memset(&sigsegv_sa, 0, sizeof(sigsegv_sa));
	sigsegv_sa.sa_handler = sigsegv_handler;
	sigemptyset(&sigsegv_sa.sa_mask);

	srv->invoke_dbg_on_crash = frontend->invoke_dbg_on_crash;	//add by vinchen/CFR

	if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
		sigaction(SIGSEGV, &sigsegv_sa, NULL);
	}
#endif

	/*
	 * some plugins cannot see the chassis struct from the point
	 * where they open files, hence we must make it available
	 */
	srv->base_dir = g_strdup(frontend->base_dir);

	if (frontend->plugin_dir)			//vinchen/CFR
		srv->plugin_dir_org = g_strdup(frontend->plugin_dir);
	if (frontend->pid_file)
		srv->pid_file_org	= g_strdup(frontend->pid_file);
	if (frontend->log_filename)
		srv->log_file_name_org	= g_strdup(frontend->log_filename);
	if (frontend->lua_path)
		srv->lua_path_org		= g_strdup(frontend->lua_path);
	if (frontend->lua_cpath)
		srv->lua_cpath_org		= g_strdup(frontend->lua_cpath);
	srv->max_files_number	= frontend->max_files_number;

	chassis_frontend_init_plugin_dir(&frontend->plugin_dir, srv->base_dir);
	
	/* 
	 * these are used before we gathered all the options
	 * from the plugins, thus we need to fix them up before
	 * dealing with all the rest.
	 */
	chassis_resolve_path(srv->base_dir, &frontend->log_filename);
	chassis_resolve_path(srv->base_dir, &frontend->pid_file);
	chassis_resolve_path(srv->base_dir, &frontend->plugin_dir);

	/*
	 * start the logging
	 */
	if (frontend->log_filename) {
		log->log_filename = g_strdup(frontend->log_filename);
	}

	log->use_syslog = frontend->use_syslog;

	if (log->log_filename && log->use_syslog) {
		g_critical("%s: log-file and log-use-syslog were given, but only one is allowed",
				G_STRLOC);
		GOTO_EXIT(EXIT_FAILURE);
	}

	if (log->log_filename && FALSE == chassis_log_open(log)) {
		g_critical("can't open log-file '%s': %s", log->log_filename, g_strerror(errno));

		GOTO_EXIT(EXIT_FAILURE);
	}

	/* handle log-level after the config-file is read, just in case it is specified in the file */
	if (frontend->log_level) {
		if (0 != chassis_log_set_level(log, frontend->log_level)) {
			g_critical("--log-level=... failed, level '%s' is unknown ",
					frontend->log_level);

			GOTO_EXIT(EXIT_FAILURE);
		}
	} else {
		/* if it is not set, use "critical" as default */
		log->min_lvl = G_LOG_LEVEL_CRITICAL;
	}

	/*
	 * the MySQL Proxy should load 'admin' and 'proxy' plugins
	 */
	if (!frontend->plugin_names) {
		frontend->plugin_names = g_new(char *, 2);

		frontend->plugin_names[0] = g_strdup("proxy");
		frontend->plugin_names[1] = NULL;
	}
コード例 #15
0
ファイル: arvfakegvcamera.c プロジェクト: Amomum/aravis
int
main (int argc, char **argv)
{
	ArvFakeGvCamera *gv_camera;
	int n_events;
	GInputVector input_vector;
	GOptionContext *context;
	GError *error = NULL;

	arv_g_thread_init (NULL);
	arv_g_type_init ();

	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, "Fake GigEVision camera.");
	g_option_context_set_description (context, "Example: 'arv-fake-gv-camera-" ARAVIS_API_VERSION " -i eth0'");
	g_option_context_add_main_entries (context, arv_option_entries, NULL);

	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_option_context_free (context);
		g_print ("Option parsing failed: %s\n", error->message);
		g_error_free (error);
		return EXIT_FAILURE;
	}

	g_option_context_free (context);

	arv_debug_enable (arv_option_debug_domains);

	gv_camera = arv_fake_gv_camera_new (arv_option_interface_name);
	if (gv_camera == NULL) {
		g_print ("Can't instantiate a new fake camera.\n");
		g_print ("An existing instance may already use the '%s' interface.\n", arv_option_interface_name);
		return EXIT_FAILURE;
	}

	input_vector.buffer = g_malloc0 (ARV_FAKE_GV_CAMERA_BUFFER_SIZE);
	input_vector.size = ARV_FAKE_GV_CAMERA_BUFFER_SIZE;

	signal (SIGINT, set_cancel);

	do {
		n_events = g_poll (gv_camera->gvcp_fds, 2, 1000);
		g_print ("n_events = %d\n", n_events);
		if (n_events > 0) {
			GSocketAddress *remote_address;
			int count;

			count = g_socket_receive_message (gv_camera->gvcp_socket,
							  &remote_address, &input_vector, 1, NULL, NULL,
							  G_SOCKET_MSG_NONE, NULL, NULL);
			if (count > 0)
				handle_control_packet (gv_camera, gv_camera->gvcp_socket,
						       remote_address, input_vector.buffer, count);

			if (gv_camera->discovery_socket != NULL) {
				count = g_socket_receive_message (gv_camera->discovery_socket,
								  &remote_address, &input_vector, 1, NULL, NULL,
								  G_SOCKET_MSG_NONE, NULL, NULL);
				if (count > 0)
					handle_control_packet (gv_camera, gv_camera->discovery_socket,
							       remote_address, input_vector.buffer, count);
			}
		}
	} while (!cancel);

	g_free (input_vector.buffer);

	arv_fake_gv_camera_free (gv_camera);

	return EXIT_SUCCESS;
}
コード例 #16
0
gint dock_manager_preferences_bin_main (gchar** argv, int argv_length1) {
	gint result = 0;
	GOptionContext* _tmp0_ = NULL;
	GOptionContext* context;
	GOptionGroup* _tmp1_ = NULL;
	DockManagerPreferencesBin* _tmp2_ = NULL;
	DockManagerPreferencesBin* prefs_bin;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_option_context_new (" - Dockmanager-settings Options");
	context = _tmp0_;
	g_option_context_add_main_entries (context, DOCK_MANAGER_options, NULL);
	_tmp1_ = gtk_get_option_group (FALSE);
	g_option_context_add_group (context, _tmp1_);
	g_option_context_parse (context, &argv_length1, &argv, &_inner_error_);
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (context);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	gtk_init (&argv_length1, &argv);
	desktop_agnostic_vfs_init (&_inner_error_);
	if (_inner_error_ != NULL) {
		goto __catch1_g_error;
	}
	_tmp2_ = dock_manager_preferences_bin_new ();
	prefs_bin = g_object_ref_sink (_tmp2_);
	gtk_widget_show ((GtkWidget*) prefs_bin);
	if (dock_manager_EMBED_XID == 0) {
		GtkWindow* _tmp3_ = NULL;
		GtkWindow* window;
		_tmp3_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
		window = g_object_ref_sink (_tmp3_);
		gtk_window_set_title (window, "Dockmanager preferences");
		gtk_container_add ((GtkContainer*) window, (GtkWidget*) prefs_bin);
		gtk_window_set_default_size (window, 400, 450);
		gtk_container_set_border_width ((GtkContainer*) window, (guint) 12);
		g_signal_connect ((GtkObject*) window, "destroy", (GCallback) _gtk_main_quit_gtk_object_destroy, NULL);
		gtk_widget_show ((GtkWidget*) window);
		_g_object_unref0 (window);
	} else {
		GtkPlug* _tmp4_ = NULL;
		GtkPlug* plug;
		_tmp4_ = (GtkPlug*) gtk_plug_new ((GdkNativeWindow) 0);
		plug = g_object_ref_sink (_tmp4_);
		g_signal_connect ((GtkWidget*) plug, "delete-event", (GCallback) __lambda4__gtk_widget_delete_event, NULL);
		gtk_container_add ((GtkContainer*) plug, (GtkWidget*) prefs_bin);
		gtk_plug_construct (plug, (GdkNativeWindow) dock_manager_EMBED_XID);
		gtk_widget_show ((GtkWidget*) plug);
		_g_object_unref0 (plug);
	}
	gtk_main ();
	desktop_agnostic_vfs_shutdown (&_inner_error_);
	if (_inner_error_ != NULL) {
		_g_object_unref0 (prefs_bin);
		goto __catch1_g_error;
	}
	_g_object_unref0 (prefs_bin);
	goto __finally1;
	__catch1_g_error:
	{
		GError * err;
		err = _inner_error_;
		_inner_error_ = NULL;
		g_warning ("dockmanager-settings.vala:327: %s", err->message);
		_g_error_free0 (err);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (context);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	result = 0;
	_g_option_context_free0 (context);
	return result;
}
int
main (int argc, char **argv)
{
	GnomeProgram   *program;
	GConfClient    *client;
	GladeXML       *dialog;
	GtkWidget      *dialog_win, *w;
	GOptionContext *context;
	gchar *start_page = NULL;

	GOptionEntry cap_options[] = {
		{"show-page", 'p', G_OPTION_FLAG_IN_MAIN,
		 G_OPTION_ARG_STRING,
		 &start_page,
		 /* TRANSLATORS: don't translate the terms in brackets */
		 N_("Specify the name of the page to show (general|accessibility)"),
		 N_("page") },
		{NULL}
	};

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	context = g_option_context_new (_("- GNOME Mouse Preferences"));
	g_option_context_add_main_entries (context, cap_options,
					   GETTEXT_PACKAGE);

	program = gnome_program_init ("gnome-mouse-properties", VERSION,
				      LIBGNOMEUI_MODULE, argc, argv,
				      GNOME_PARAM_GOPTION_CONTEXT, context,
				      GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR,
				      NULL);

	capplet_init_stock_icons ();

	activate_settings_daemon ();

	client = gconf_client_get_default ();
	gconf_client_add_dir (client, "/desktop/gnome/peripherals/mouse", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);

	dialog = create_dialog ();

	if (dialog) {
		setup_dialog (dialog, NULL);
		setup_accessibility (dialog, client);

		dialog_win = WID ("mouse_properties_dialog");
		g_signal_connect (dialog_win, "response",
				  G_CALLBACK (dialog_response_cb), NULL);

		if (start_page != NULL) {
			gchar *page_name;

			page_name = g_strconcat (start_page, "_vbox", NULL);
			g_free (start_page);

			w = WID (page_name);
			if (w != NULL) {
				GtkNotebook *nb;
				gint pindex;

				nb = GTK_NOTEBOOK (WID ("prefs_widget"));
				pindex = gtk_notebook_page_num (nb, w);
				if (pindex != -1)
					gtk_notebook_set_current_page (nb, pindex);
			}
			g_free (page_name);
		}

		capplet_set_icon (dialog_win, "gnome-dev-mouse-optical");
		gtk_widget_show (dialog_win);

		gtk_main ();

		g_object_unref (dialog);
	}

	g_object_unref (client);
	g_object_unref (program);

	return 0;
}
コード例 #18
0
ファイル: main.c プロジェクト: flotter/mesaprocessframework
int main(int argc, char *argv[])
{

/* Commandline parameter parsing */

   gchar *opt_address=NULL;
   gchar *opt_port=NULL;
   gboolean opt_debug=FALSE;
   GError *error=NULL;
   GOptionContext *opt_context;

   GOptionEntry opt_entries[] = {
      { "remote-dbus-ip", 'i', 0, G_OPTION_ARG_STRING, &opt_address, "TCP IP address <xxx.xxx.xxx.xxx>", NULL },
      { "remote-dbus-port", 'p', 0, G_OPTION_ARG_STRING, &opt_port, "TCP port (default is 55556)", NULL },
      { "debug", 'd', 0, G_OPTION_ARG_NONE, &opt_debug, "Enable verbose debug messages", NULL },
      { NULL }
   };

   opt_context = g_option_context_new ("MESA Process Framework Example");
   error = NULL;

   g_option_context_add_main_entries (opt_context, opt_entries, NULL);

   if (!g_option_context_parse (opt_context, &argc, &argv, &error))
   {
      g_printerr ("Error parsing options: %s\n", error->message);
      g_error_free (error);
   }
   else
   {

      g_print("Ctrl-C to exit ...\n");

      /* Init Services */

      dbusSvc_init(opt_address,opt_port);

      /* Start Services */

      dbusSvc_start();


      Distance odometer = (Distance)0u;
      EngSpd rpm = (EngSpd)0u;
      Speed speed = (Speed)0u;

      while(1) {

         sleep(2);

         paramSvc_parameterGet(PARAM_STRUCT_SYS_STDPARAM_ODO,&odometer,sizeof(odometer));
         paramSvc_parameterGet(PARAM_STRUCT_SYS_STDPARAM_SPEED,&speed,sizeof(speed));
         paramSvc_parameterGet(PARAM_STRUCT_SYS_STDPARAM_RPM,&rpm,sizeof(rpm));

         g_print("PARAM GETs:\n");
         g_print("--------------------\n");
         g_print("Odo: %d\n",odometer);
         g_print("Speed: %d\n",speed);
         g_print("RPM: %d\n",rpm);
         g_print("--------------------\n");

         speed = 1000;
         g_print("PARAM SET:\n");
         g_print("--------------------\n");
         paramSvc_parameterSet(PARAM_STRUCT_SYS_STDPARAM_SPEED,&speed,sizeof(speed));
         g_print("Speed: %d\n",speed);
         g_print("--------------------\n");

         g_print("PARAM GETs:\n");
         g_print("--------------------\n");
         g_print("Odo: %d\n",odometer);
         g_print("Speed: %d\n",speed);
         g_print("RPM: %d\n",rpm);
         g_print("--------------------------------------------------------------\n");

      } ;

      dbusSvc_destroy();

   }

   return 0;
}
コード例 #19
0
ファイル: nautilus-cd-burner.c プロジェクト: joshlong/dac
int
main (int argc, char *argv[])
{
        GConfClient              *gc;
        GtkWidget                *dialog;
        NcbSelection             *selection;
        NcbSelectionDialogSource  source_type;
        char                     *source_name;
        char                     *last_device;
        static char              *source_device;
        static char              *source_iso;
        static char              *source_cue;
        GOptionContext           *context;
        GnomeProgram             *program;
        static const GOptionEntry options []  = {
                { "source-device", 0, 0, G_OPTION_ARG_FILENAME, &source_device,
                  N_("Use CD/DVD device as source instead of burn:///"), N_("DEVICE") },
                { "source-iso", 0, 0, G_OPTION_ARG_FILENAME, &source_iso,
                  N_("Use ISO image as source instead of burn:///"), N_("FILENAME") },
                { "source-cue", 0, 0, G_OPTION_ARG_FILENAME, &source_cue,
                  N_("Use CUE/TOC file as source instead of burn:///"), N_("FILENAME") },
                { NULL}
        };

        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        context = g_option_context_new (NULL);

        g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

        program = gnome_program_init ("nautilus-cd-burner", VERSION,
                                      LIBGNOMEUI_MODULE, argc, argv,
                                      GNOME_PARAM_GOPTION_CONTEXT, context,
                                      GNOME_PARAM_APP_DATADIR, SHAREDIR,
                                      GNOME_PARAM_NONE);

        nautilus_burn_init ();

        dialog = ncb_selection_dialog_new ();
        g_signal_connect (dialog, "response", G_CALLBACK (selection_dialog_response), NULL);
        gtk_widget_show (dialog);

        if (source_iso != NULL) {
                char *path;

                path = expand_path_input (source_iso);
                if (path == NULL) {
                        goto out;
                }

                source_type = NCB_SELECTION_DIALOG_SOURCE_ISO;
                source_name = path;
        } else if (source_cue != NULL) {
                char *path;

                path = expand_path_input (source_cue);
                if (path == NULL) {
                        goto out;
                }

                source_type = NCB_SELECTION_DIALOG_SOURCE_CUE;
                source_name = path;
        } else if (source_device != NULL) {
                source_type = NCB_SELECTION_DIALOG_SOURCE_DEVICE;
                source_name = g_strdup (source_device);
        } else {
                source_type = NCB_SELECTION_DIALOG_SOURCE_BURN_FOLDER;
                source_name = NULL;
        }

        selection = ncb_selection_dialog_get_selection (NCB_SELECTION_DIALOG (dialog));
        ncb_selection_set_source (selection, source_type, source_name);

        gc = gconf_client_get_default ();
        last_device = gconf_load_device (gc);
        if (last_device != NULL) {
                NautilusBurnDrive *drive;

                drive = nautilus_burn_drive_monitor_get_drive_for_device (nautilus_burn_get_drive_monitor (),
                                                                          last_device);
                ncb_selection_set_drive (selection, drive);
                if (drive != NULL) {
                        g_object_unref (drive);
                } else {
                        g_warning ("Drive not found for saved device: %s", last_device);
                }
                g_free (last_device);
        }

        g_object_unref (selection);

        g_object_unref (gc);

        g_free (source_name);

        gtk_main ();

 out:
        g_object_unref (program);
        nautilus_burn_shutdown ();

        return 0;
}
コード例 #20
0
ファイル: skk.c プロジェクト: pkg-ime/libskk
gint skk_tool_main (gchar** args, int args_length1) {
	gint result = 0;
	const gchar* _tmp0_ = NULL;
	GOptionContext* _tmp1_;
	GOptionContext* option_context;
	GOptionContext* _tmp2_;
	gboolean _tmp7_;
	GeeArrayList* _tmp19_;
	GeeArrayList* dictionaries;
	const gchar* _tmp20_;
	const gchar* _tmp30_;
	const gchar* _tmp58_;
	GeeArrayList* _tmp86_;
	gint _tmp87_ = 0;
	gpointer* _tmp88_ = NULL;
	SkkDict** _tmp89_;
	gint _tmp89__length1;
	SkkContext* _tmp90_;
	SkkContext* _tmp91_;
	SkkContext* context;
	const gchar* _tmp92_;
	SkkContext* _tmp102_;
	SkkSkkTool* _tmp103_;
	SkkSkkTool* tool;
	SkkSkkTool* _tmp104_;
	gboolean _tmp105_ = FALSE;
	GError * _inner_error_ = NULL;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = _ ("- emulate SKK input method on the command line");
	_tmp1_ = g_option_context_new (_tmp0_);
	option_context = _tmp1_;
	_tmp2_ = option_context;
	g_option_context_add_main_entries (_tmp2_, SKK_TOOL_options, "libskk");
	{
		GOptionContext* _tmp3_;
		_tmp3_ = option_context;
		g_option_context_parse (_tmp3_, &args_length1, &args, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch0_g_option_error;
			}
			_g_option_context_free0 (option_context);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp4_;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		fprintf (_tmp4_, "%s\n", _tmp6_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (option_context);
		return result;
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (option_context);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	skk_init ();
	_tmp7_ = skk_tool_list_typing_rules;
	if (_tmp7_) {
		gint _tmp8_ = 0;
		SkkRuleMetadata* _tmp9_ = NULL;
		SkkRuleMetadata* rules;
		gint rules_length1;
		gint _rules_size_;
		SkkRuleMetadata* _tmp10_;
		gint _tmp10__length1;
		_tmp9_ = skk_rule_list (&_tmp8_);
		rules = _tmp9_;
		rules_length1 = _tmp8_;
		_rules_size_ = rules_length1;
		_tmp10_ = rules;
		_tmp10__length1 = rules_length1;
		{
			SkkRuleMetadata* rule_collection = NULL;
			gint rule_collection_length1 = 0;
			gint _rule_collection_size_ = 0;
			gint rule_it = 0;
			rule_collection = _tmp10_;
			rule_collection_length1 = _tmp10__length1;
			for (rule_it = 0; rule_it < _tmp10__length1; rule_it = rule_it + 1) {
				SkkRuleMetadata _tmp11_ = {0};
				SkkRuleMetadata rule = {0};
				skk_rule_metadata_copy (&rule_collection[rule_it], &_tmp11_);
				rule = _tmp11_;
				{
					FILE* _tmp12_;
					SkkRuleMetadata _tmp13_;
					const gchar* _tmp14_;
					SkkRuleMetadata _tmp15_;
					const gchar* _tmp16_;
					SkkRuleMetadata _tmp17_;
					const gchar* _tmp18_;
					_tmp12_ = stdout;
					_tmp13_ = rule;
					_tmp14_ = _tmp13_.name;
					_tmp15_ = rule;
					_tmp16_ = _tmp15_.label;
					_tmp17_ = rule;
					_tmp18_ = _tmp17_.description;
					fprintf (_tmp12_, "%s - %s: %s\n", _tmp14_, _tmp16_, _tmp18_);
					skk_rule_metadata_destroy (&rule);
				}
			}
		}
		result = 0;
		rules = (_vala_SkkRuleMetadata_array_free (rules, rules_length1), NULL);
		_g_option_context_free0 (option_context);
		return result;
	}
	_tmp19_ = gee_array_list_new (SKK_TYPE_DICT, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL);
	dictionaries = _tmp19_;
	_tmp20_ = skk_tool_user_dict;
	if (_tmp20_ != NULL) {
		{
			const gchar* _tmp21_;
			SkkUserDict* _tmp22_;
			SkkUserDict* _tmp23_;
			GeeArrayList* _tmp24_;
			SkkUserDict* _tmp25_;
			_tmp21_ = skk_tool_user_dict;
			_tmp22_ = skk_user_dict_new (_tmp21_, "UTF-8", &_inner_error_);
			_tmp23_ = _tmp22_;
			if (_inner_error_ != NULL) {
				goto __catch1_g_error;
			}
			_tmp24_ = dictionaries;
			_tmp25_ = _tmp23_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp24_, (SkkDict*) _tmp25_);
			_g_object_unref0 (_tmp25_);
		}
		goto __finally1;
		__catch1_g_error:
		{
			GError* e = NULL;
			FILE* _tmp26_;
			const gchar* _tmp27_;
			GError* _tmp28_;
			const gchar* _tmp29_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp26_ = stderr;
			_tmp27_ = skk_tool_user_dict;
			_tmp28_ = e;
			_tmp29_ = _tmp28_->message;
			fprintf (_tmp26_, "can't open user dict %s: %s", _tmp27_, _tmp29_);
			result = 1;
			_g_error_free0 (e);
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			return result;
		}
		__finally1:
		if (_inner_error_ != NULL) {
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
	}
	_tmp30_ = skk_tool_file_dict;
	if (_tmp30_ != NULL) {
		const gchar* _tmp31_;
		gboolean _tmp32_ = FALSE;
		_tmp31_ = skk_tool_file_dict;
		_tmp32_ = g_str_has_suffix (_tmp31_, ".cdb");
		if (_tmp32_) {
			{
				const gchar* _tmp33_;
				SkkCdbDict* _tmp34_;
				SkkCdbDict* _tmp35_;
				GeeArrayList* _tmp36_;
				SkkCdbDict* _tmp37_;
				_tmp33_ = skk_tool_file_dict;
				_tmp34_ = skk_cdb_dict_new (_tmp33_, "EUC-JP", &_inner_error_);
				_tmp35_ = _tmp34_;
				if (_inner_error_ != NULL) {
					goto __catch2_g_error;
				}
				_tmp36_ = dictionaries;
				_tmp37_ = _tmp35_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp36_, (SkkDict*) _tmp37_);
				_g_object_unref0 (_tmp37_);
			}
			goto __finally2;
			__catch2_g_error:
			{
				GError* e = NULL;
				FILE* _tmp38_;
				const gchar* _tmp39_;
				GError* _tmp40_;
				const gchar* _tmp41_;
				e = _inner_error_;
				_inner_error_ = NULL;
				_tmp38_ = stderr;
				_tmp39_ = skk_tool_file_dict;
				_tmp40_ = e;
				_tmp41_ = _tmp40_->message;
				fprintf (_tmp38_, "can't open CDB dict %s: %s", _tmp39_, _tmp41_);
				result = 1;
				_g_error_free0 (e);
				_g_object_unref0 (dictionaries);
				_g_option_context_free0 (option_context);
				return result;
			}
			__finally2:
			if (_inner_error_ != NULL) {
				_g_object_unref0 (dictionaries);
				_g_option_context_free0 (option_context);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return 0;
			}
		} else {
			{
				const gchar* _tmp42_;
				SkkFileDict* _tmp43_;
				SkkFileDict* _tmp44_;
				GeeArrayList* _tmp45_;
				SkkFileDict* _tmp46_;
				_tmp42_ = skk_tool_file_dict;
				_tmp43_ = skk_file_dict_new (_tmp42_, "EUC-JP", &_inner_error_);
				_tmp44_ = _tmp43_;
				if (_inner_error_ != NULL) {
					goto __catch3_g_error;
				}
				_tmp45_ = dictionaries;
				_tmp46_ = _tmp44_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp45_, (SkkDict*) _tmp46_);
				_g_object_unref0 (_tmp46_);
			}
			goto __finally3;
			__catch3_g_error:
			{
				GError* e = NULL;
				FILE* _tmp47_;
				const gchar* _tmp48_;
				GError* _tmp49_;
				const gchar* _tmp50_;
				e = _inner_error_;
				_inner_error_ = NULL;
				_tmp47_ = stderr;
				_tmp48_ = skk_tool_file_dict;
				_tmp49_ = e;
				_tmp50_ = _tmp49_->message;
				fprintf (_tmp47_, "can't open file dict %s: %s", _tmp48_, _tmp50_);
				result = 1;
				_g_error_free0 (e);
				_g_object_unref0 (dictionaries);
				_g_option_context_free0 (option_context);
				return result;
			}
			__finally3:
			if (_inner_error_ != NULL) {
				_g_object_unref0 (dictionaries);
				_g_option_context_free0 (option_context);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return 0;
			}
		}
	} else {
		gchar* _tmp51_ = NULL;
		gchar* _tmp52_;
		SkkFileDict* _tmp53_;
		SkkFileDict* _tmp54_;
		SkkFileDict* _tmp55_;
		GeeArrayList* _tmp56_;
		SkkFileDict* _tmp57_;
		_tmp51_ = g_build_filename (DATADIR, "skk", "SKK-JISYO.L", NULL);
		_tmp52_ = _tmp51_;
		_tmp53_ = skk_file_dict_new (_tmp52_, "EUC-JP", &_inner_error_);
		_tmp54_ = _tmp53_;
		_g_free0 (_tmp52_);
		_tmp55_ = _tmp54_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp56_ = dictionaries;
		_tmp57_ = _tmp55_;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp56_, (SkkDict*) _tmp57_);
		_g_object_unref0 (_tmp57_);
	}
	_tmp58_ = skk_tool_skkserv;
	if (_tmp58_ != NULL) {
		const gchar* _tmp59_;
		gint _tmp60_ = 0;
		gint index;
		gchar* host = NULL;
		guint16 port = 0U;
		gint _tmp61_;
		_tmp59_ = skk_tool_skkserv;
		_tmp60_ = string_last_index_of (_tmp59_, ":", 0);
		index = _tmp60_;
		_tmp61_ = index;
		if (_tmp61_ < 0) {
			const gchar* _tmp62_;
			gchar* _tmp63_;
			_tmp62_ = skk_tool_skkserv;
			_tmp63_ = g_strdup (_tmp62_);
			_g_free0 (host);
			host = _tmp63_;
			port = (guint16) 1178;
		} else {
			const gchar* _tmp64_;
			gint _tmp65_;
			gchar* _tmp66_ = NULL;
			const gchar* _tmp67_;
			gint _tmp68_;
			const gchar* _tmp69_;
			gint _tmp70_;
			gint _tmp71_;
			gchar* _tmp72_ = NULL;
			gchar* _tmp73_;
			gint _tmp74_ = 0;
			_tmp64_ = skk_tool_skkserv;
			_tmp65_ = index;
			_tmp66_ = string_slice (_tmp64_, (glong) 0, (glong) _tmp65_);
			_g_free0 (host);
			host = _tmp66_;
			_tmp67_ = skk_tool_skkserv;
			_tmp68_ = index;
			_tmp69_ = skk_tool_skkserv;
			_tmp70_ = strlen (_tmp69_);
			_tmp71_ = _tmp70_;
			_tmp72_ = string_slice (_tmp67_, (glong) (_tmp68_ + 1), (glong) _tmp71_);
			_tmp73_ = _tmp72_;
			_tmp74_ = atoi (_tmp73_);
			port = (guint16) _tmp74_;
			_g_free0 (_tmp73_);
		}
		{
			const gchar* _tmp75_;
			guint16 _tmp76_;
			SkkSkkServ* _tmp77_;
			SkkSkkServ* _tmp78_;
			GeeArrayList* _tmp79_;
			SkkSkkServ* _tmp80_;
			_tmp75_ = host;
			_tmp76_ = port;
			_tmp77_ = skk_skk_serv_new (_tmp75_, _tmp76_, "EUC-JP", &_inner_error_);
			_tmp78_ = _tmp77_;
			if (_inner_error_ != NULL) {
				goto __catch4_g_error;
			}
			_tmp79_ = dictionaries;
			_tmp80_ = _tmp78_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp79_, (SkkDict*) _tmp80_);
			_g_object_unref0 (_tmp80_);
		}
		goto __finally4;
		__catch4_g_error:
		{
			GError* e = NULL;
			FILE* _tmp81_;
			const gchar* _tmp82_;
			guint16 _tmp83_;
			GError* _tmp84_;
			const gchar* _tmp85_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp81_ = stderr;
			_tmp82_ = host;
			_tmp83_ = port;
			_tmp84_ = e;
			_tmp85_ = _tmp84_->message;
			fprintf (_tmp81_, "can't connect to skkserv at %s:%d: %s", _tmp82_, (gint) _tmp83_, _tmp85_);
			result = 1;
			_g_error_free0 (e);
			_g_free0 (host);
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			return result;
		}
		__finally4:
		if (_inner_error_ != NULL) {
			_g_free0 (host);
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_g_free0 (host);
	}
	_tmp86_ = dictionaries;
	_tmp88_ = gee_abstract_collection_to_array ((GeeAbstractCollection*) _tmp86_, &_tmp87_);
	_tmp89_ = _tmp88_;
	_tmp89__length1 = _tmp87_;
	_tmp90_ = skk_context_new (_tmp89_, _tmp87_);
	_tmp91_ = _tmp90_;
	_tmp89_ = (_vala_array_free (_tmp89_, _tmp89__length1, (GDestroyNotify) g_object_unref), NULL);
	context = _tmp91_;
	_tmp92_ = skk_tool_typing_rule;
	if (_tmp92_ != NULL) {
		{
			const gchar* _tmp93_;
			SkkRule* _tmp94_;
			SkkRule* _tmp95_;
			SkkContext* _tmp96_;
			SkkRule* _tmp97_;
			_tmp93_ = skk_tool_typing_rule;
			_tmp94_ = skk_rule_new (_tmp93_, &_inner_error_);
			_tmp95_ = _tmp94_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
					goto __catch5_skk_rule_parse_error;
				}
				_g_object_unref0 (context);
				_g_object_unref0 (dictionaries);
				_g_option_context_free0 (option_context);
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return 0;
			}
			_tmp96_ = context;
			_tmp97_ = _tmp95_;
			skk_context_set_typing_rule (_tmp96_, _tmp97_);
			_g_object_unref0 (_tmp97_);
		}
		goto __finally5;
		__catch5_skk_rule_parse_error:
		{
			GError* e = NULL;
			FILE* _tmp98_;
			const gchar* _tmp99_;
			GError* _tmp100_;
			const gchar* _tmp101_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp98_ = stderr;
			_tmp99_ = skk_tool_typing_rule;
			_tmp100_ = e;
			_tmp101_ = _tmp100_->message;
			fprintf (_tmp98_, "can't load rule \"%s\": %s\n", _tmp99_, _tmp101_);
			result = 1;
			_g_error_free0 (e);
			_g_object_unref0 (context);
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			return result;
		}
		__finally5:
		if (_inner_error_ != NULL) {
			_g_object_unref0 (context);
			_g_object_unref0 (dictionaries);
			_g_option_context_free0 (option_context);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
	}
	_tmp102_ = context;
	_tmp103_ = skk_skk_tool_new (_tmp102_);
	tool = _tmp103_;
	_tmp104_ = tool;
	_tmp105_ = skk_tool_run ((SkkTool*) _tmp104_);
	if (!_tmp105_) {
		result = 1;
		_g_object_unref0 (tool);
		_g_object_unref0 (context);
		_g_object_unref0 (dictionaries);
		_g_option_context_free0 (option_context);
		return result;
	}
	result = 0;
	_g_object_unref0 (tool);
	_g_object_unref0 (context);
	_g_object_unref0 (dictionaries);
	_g_option_context_free0 (option_context);
	return result;
}
コード例 #21
0
ファイル: ev-previewer.c プロジェクト: mate-desktop/atril
gint
main (gint argc, gchar **argv)
{
	GtkWidget       *window;
	GOptionContext  *context;
	const gchar     *filename;
	EvDocumentModel *model;
	GError          *error = NULL;

#ifdef ENABLE_NLS
	/* Initialize the i18n stuff */
	bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir());
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif
	
	context = g_option_context_new (_("MATE Document Previewer"));
	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
	g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);

	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_warning ("Error parsing command line arguments: %s", error->message);
		g_error_free (error);
		g_option_context_free (context);

		return 1;
	}
	g_option_context_free (context);

	if (!filenames) {
		g_warning ("File argument is required");
		
		return 1;
	}

	filename = filenames[0];
	
	if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
		g_warning ("Filename \"%s\" does not exist or is not a regular file", filename);

		return 1;
	}

	if (!ev_init ())
		return 1;

	ev_stock_icons_init ();

	g_set_application_name (_("MATE Document Previewer"));
	gtk_window_set_default_icon_name ("atril");

	model = ev_document_model_new ();
	window = ev_previewer_window_new (model);
	ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename);
	ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings);
	g_signal_connect (window, "delete-event",
			  G_CALLBACK (gtk_main_quit), NULL);
	g_signal_connect (window, "destroy",
			  G_CALLBACK (gtk_main_quit), NULL);
	gtk_widget_show (window);

	ev_previewer_load_document (filename, model);
	
	gtk_main ();

	if (unlink_temp_file)
		ev_previewer_unlink_tempfile (filename);
	if (print_settings)
		ev_previewer_unlink_tempfile (print_settings);

	ev_shutdown ();
	ev_stock_icons_shutdown ();
	g_object_unref (model);
	
	return 0;
}
コード例 #22
0
/**
 * main:
 **/
int
main (int argc, char **argv)
{
	GOptionContext *context;
	const gchar *subsystems[] = { "usb", NULL };
	gboolean verbose = FALSE;
	int status = EXIT_SUCCESS;
	_cleanup_object_unref_ GUdevClient *udev_client = NULL;
	g_autoptr(GError) error = NULL;
	g_autoptr(GCancellable) cancellable = NULL;

	const GOptionEntry options[] = {
		{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
			/* TRANSLATORS: command line option */
			_("Show extra debugging information"), NULL },
		{ NULL}
	};

	/* make this predictable */
	g_random_set_seed (0xdead);

	/* TRANSLATORS: A program to copy the LiveUSB image onto USB hardware */
	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, options, NULL);
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		status = EXIT_FAILURE;
		g_print ("Failed to parse command line: %s\n", error->message);
		goto out;
	}

	if (verbose)
		g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);

	/* valid arguments */
	if (argc != 2 || !gmw_probe_is_block_device_valid (argv[1])) {
		status = EXIT_FAILURE;
		g_print ("Block device required as argument\n");
		goto out;
	}

	/* already mounted */
	if (gmw_probe_is_block_device_mounted (argv[1])) {
		status = EXIT_FAILURE;
		g_print ("Partition mounted from block device\n");
		goto out;
	}

	/* probe device */
	cancellable = g_cancellable_new ();
	udev_client = g_udev_client_new (subsystems);
	if (!gmw_probe_use_device (udev_client, argv[1], cancellable, &error)) {
		status = EXIT_FAILURE;
		if (g_error_matches (error, GMW_ERROR, GMW_ERROR_IS_FAKE)) {
			g_print ("Device is FAKE: %s\n", error->message);
		} else {
			g_print ("Failed to scan device: %s\n", error->message);
		}
		goto out;
	}
	g_print ("Device is GOOD\n");
out:
	g_option_context_free (context);
	return status;
}
コード例 #23
0
ファイル: gio-tool-mount.c プロジェクト: caomw/glib-1
int
handle_mount (int argc, char *argv[], gboolean do_help)
{
  GOptionContext *context;
  gchar *param;
  GError *error = NULL;
  GFile *file;
  int i;

  g_set_prgname ("gio mount");

  /* Translators: commandline placeholder */
  param = g_strdup_printf ("[%s...]", _("LOCATION"));
  context = g_option_context_new (param);
  g_free (param);
  g_option_context_set_help_enabled (context, FALSE);
  g_option_context_set_summary (context, _("Mount or unmount the locations."));
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);

  if (do_help)
    {
      show_help (context, NULL);
      return 0;
    }

  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      show_help (context, error->message);
      g_error_free (error);
      return 1;
    }

  g_option_context_free (context);

  main_loop = g_main_loop_new (NULL, FALSE);

  if (mount_list)
    list_monitor_items ();
  else if (mount_device_file != NULL)
    mount_with_device_file (mount_device_file);
  else if (unmount_scheme != NULL)
    unmount_all_with_scheme (unmount_scheme);
  else if (mount_monitor)
    monitor ();
  else if (argc > 1)
    {
      for (i = 1; i < argc; i++)
        {
          file = g_file_new_for_commandline_arg (argv[i]);
          if (mount_unmount)
            unmount (file);
          else if (mount_eject)
            eject (file);
          else
            mount (file);
          g_object_unref (file);
        }
    }

  if (outstanding_mounts > 0)
    g_main_loop_run (main_loop);

  return success ? 0 : 2;
}
コード例 #24
0
ファイル: tny-main.c プロジェクト: Codeminded/tinymail
/**
 * main:
 * @argc: Amount of arguments
 * @argv: The arguments
 *
 * Main entry point of the application
 *
 * Return value: application return value (0 on success)
 **/
int 
main (int argc, char **argv)
{
	GtkWidget *view = NULL, *window = NULL;
	TnyPlatformFactory *platfact;
	GOptionContext *context;
	static gint plug = 0;
	TnyAccountStore *account_store;

	static GOptionEntry entries[] = {
		{ "plug", 'p', 0, G_OPTION_ARG_INT, &plug,
			"Socket ID of an XEmbed socket to plug into", NULL },
		{ NULL }
	};

	context = g_option_context_new (" - libtinymail demo application");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group (context, gtk_get_option_group (TRUE));
	g_option_context_parse (context, &argc, &argv, NULL);

	if (!g_thread_supported ()) 
		g_thread_init (NULL);
	gdk_threads_init ();

	gdk_threads_enter ();

	gtk_init (&argc, &argv);

#ifdef GNOME
	gnome_vfs_init ();
#endif

	bindtextdomain(GETTEXT_PACKAGE, TNY_LOCALE_DIR);

#if PLATFORM==1
	platfact = tny_gnome_platform_factory_get_instance ();
#endif
    
#if PLATFORM==2
	platfact = tny_maemo_platform_factory_get_instance ();    
#endif

#if PLATFORM==3
	platfact = tny_gpe_platform_factory_get_instance ();    
#endif

#if PLATFORM==4
	platfact = tny_olpc_platform_factory_get_instance ();    
#endif

	view = GTK_WIDGET (tny_demoui_summary_view_new ());

	if (plug > 0) {
		g_message ("Plugging into socket %d", plug);
		window = gtk_plug_new (plug);
	} else {
		window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
		gtk_window_set_title (GTK_WINDOW (window), "Demo ui");
	}

	gtk_container_add (GTK_CONTAINER (window), view);
	
	account_store = tny_platform_factory_new_account_store (platfact);
	tny_account_store_view_set_account_store (
		TNY_ACCOUNT_STORE_VIEW (view), account_store);
	g_object_unref (G_OBJECT (account_store));
	
	g_signal_connect (window, "destroy",
		G_CALLBACK (gtk_main_quit), 0);

	gtk_widget_show (view);
	gtk_widget_show (window);

	gtk_main();

	gdk_threads_leave ();

	return 0;
}
コード例 #25
0
int
main (int argc, char **argv)
{
	GnomeVFSAsyncHandle *handle;
	gchar *text_uri;
	GTimer *timer;
	CallbackData callback_data;

	GOptionContext *ctx = NULL;
	GError *error = NULL;

	g_printf("Initializing gnome-libs...");

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	if (argc != 2 || argv[1] == NULL) {
		g_printerr("Usage: %s [<options>] <uri>\n", argv[0]);
		return 1;
	}

	text_uri = g_strdup(argv[1]);

	puts ("Initializing gnome-vfs...");
	gnome_vfs_init ();

	printf ("%d item(s) per notification\n", items_per_notification);

	if (measure_speed) {
		timer = g_timer_new ();
		g_timer_start (timer);
	} else {
		timer = NULL;
	}

	callback_data.num_entries_read = 0;
	callback_data.parent_uri = text_uri;
	async_task_counter = 1;
	gnome_vfs_async_load_directory
		(&handle,
		 text_uri,
		 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
		 items_per_notification,
		 0,
		 directory_load_callback,
		 &callback_data);

	if (!measure_speed)
		puts ("main loop running.");

	main_loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (main_loop);
	g_main_loop_unref (main_loop);

	if (measure_speed) {
		gdouble elapsed_seconds;

		g_timer_stop (timer);
		elapsed_seconds = g_timer_elapsed (timer, NULL);
		printf ("%.5f seconds for %d entries, %.5f entries/sec.\n",
			elapsed_seconds, callback_data.num_entries_read,
			(double) callback_data.num_entries_read / elapsed_seconds);
	}

	if (!measure_speed)
		puts ("GTK+ main loop finished."); fflush (stdout);

	puts ("All done");

	gnome_vfs_shutdown ();

	return 0;
}
コード例 #26
0
ファイル: tagsistant.c プロジェクト: rowhit/Tagsistant
/**
 * Tagsistant main function, where everything starts...
 *
 * @param argc command line argument number
 * @param argv command line argument list
 * @return 0 when unmounted, a positive error number if something prevents the mount
 */
int main(int argc, char *argv[])
{
    struct fuse_args args = { 0, NULL, 0 };
	int res;

#ifndef MACOSX
	char *destfile = getenv("MALLOC_TRACE");
	if (destfile != NULL && strlen(destfile)) {
		fprintf(stderr, "\n *** logging g_malloc() calls to %s ***\n", destfile);
		mtrace();
	}
#endif

	/*
	 * set some values inside tagsistant context structure
	 */
	tagsistant.progname = argv[0];
	tagsistant.debug = FALSE;

	/*
	 * zero all the debug options
	 */
	int i = 0;
	for (; i < 128; i++) tagsistant.dbg[i] = 0;

	/*
	 * parse command line options
	 */
	GError *error = NULL;
	GOptionContext *context = g_option_context_new ("[repository path] <mount point>");
	g_option_context_add_main_entries (context, tagsistant_options, NULL);
	g_option_context_set_help_enabled (context, FALSE);
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		fprintf(stderr, "\n *** option parsing failed: %s\n", error->message);
		exit (1);
	}

	/*
	 * print the help screen
	 */
	if (tagsistant.show_help) {
		tagsistant_usage(argv[0], tagsistant.verbose);

		if (tagsistant.verbose) {
			fuse_opt_add_arg(&args, argv[0]);
			fuse_opt_add_arg(&args, "--help");
			tagsistant_fuse_main(&args, &tagsistant_oper);
		}

		exit(0);
	}

	/*
	 * show Tagsistant and FUSE version
	 */
	if (tagsistant.show_version) {
		fprintf(stderr, "Tagsistant (tagfs) v.%s (codename: %s)\nBuild: %s FUSE_USE_VERSION: %d\n",
			PACKAGE_VERSION, TAGSISTANT_CODENAME, TAGSISTANT_BUILDNUMBER, FUSE_USE_VERSION);

		fuse_opt_add_arg(&args, "-V");
		fuse_opt_add_arg(&args, "--version");
		tagsistant_fuse_main(&args, &tagsistant_oper);

		exit(0);
	}

	/*
	 * look for a mount point (and a repository too)
	 */
	if (tagsistant.remaining_opts && *tagsistant.remaining_opts) {
		if (tagsistant.remaining_opts[1] && *(tagsistant.remaining_opts[1])) {
			tagsistant.repository = *tagsistant.remaining_opts;
			tagsistant.mountpoint = *(tagsistant.remaining_opts + 1);

			// fprintf(stderr, "\n *** repository %s *** \n\n", tagsistant.repository);
			// fprintf(stderr, "\n *** mountpoint %s *** \n\n", tagsistant.mountpoint);
		} else {
			tagsistant.mountpoint = *tagsistant.remaining_opts;

			// fprintf(stderr, "\n *** mountpoint %s *** \n\n", tagsistant.mountpoint);
		}
	} else {
		fprintf(stderr, "\n *** No mountpoint provided *** \n");
		tagsistant_usage(argv[0], 0);
		exit(2);
	}

	/*
	 * default repository
	 */
	if (!tagsistant.repository) {
		tagsistant.repository = g_strdup_printf("%s/.tagsistant/", g_getenv("HOME"));
	}

	/*
	 * default tag-listing suffix
	 */
	if (!tagsistant.tags_suffix) {
		tagsistant.tags_suffix = g_strdup(TAGSISTANT_DEFAULT_TAGS_SUFFIX);
	}

	/*
	 * compute the triple tag detector regexp
	 */
	if (tagsistant.namespace_suffix) {
		tagsistant.triple_tag_regex = g_strdup_printf("\\%s$", tagsistant.namespace_suffix);
	} else {
		tagsistant.triple_tag_regex = g_strdup(TAGSISTANT_DEFAULT_TRIPLE_TAG_REGEX);
	}

	/* do some tuning on FUSE options */
//	fuse_opt_add_arg(&args, "-s");
//	fuse_opt_add_arg(&args, "-odirect_io");
	fuse_opt_add_arg(&args, "-obig_writes");
	fuse_opt_add_arg(&args, "-omax_write=32768");
	fuse_opt_add_arg(&args, "-omax_read=32768");
	fuse_opt_add_arg(&args, "-ofsname=tagsistant");
//	fuse_opt_add_arg(&args, "-ofstype=tagsistant");
//	fuse_opt_add_arg(&args, "-ouse_ino,readdir_ino");
//	fuse_opt_add_arg(&args, "-oallow_other");

#ifdef MACOSX
	fuse_opt_add_arg(&args, "-odefer_permissions");
	gchar *volname = g_strdup_printf("-ovolname=%s", tagsistant.mountpoint);
	fuse_opt_add_arg(&args, volname);
	g_free_null(volname);
#else
	/* fuse_opt_add_arg(&args, "-odefault_permissions"); */
#endif

	/*
	 * parse debugging flags
	 */
	if (tagsistant.debug_flags) {
		char *dbg_ptr = tagsistant.debug_flags;
		while (*dbg_ptr) {
			tagsistant.dbg[(int) *dbg_ptr] = 1;
			dbg_ptr++;
		}
	}

	/*
	 * Will run as a single threaded application?
	 */
	if (tagsistant.singlethread) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** operating in single thread mode ***\n");
		fuse_opt_add_arg(&args, "-s");
	}

	/*
	 * Will run readonly?
	 */
	if (tagsistant.readonly) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** mounting tagsistant read-only ***\n");
		fuse_opt_add_arg(&args, "-r");
	}

	/*
	 * Will run in foreground?
	 *
	 * A little explanation is required here. Many users reported tha autotagging
	 * does not work when Tagsistant is started without -f. FUSE -f switch just
	 * tells FUSE to not fork in the background. This means that Tagsistant keeps
	 * the console busy and never detaches. It's very useful for debugging but
	 * very annoying in everyday life. However when FUSE send Tagsistant in the
	 * background, something wrong happens with the scheduling of the autotagging
	 * thread. On the other hand, when the -f switch is used, autotagging works
	 * as expected.
	 *
	 * As a workaround, FUSE is always provided with the -f switch, while the
	 * background is reached by Tagsistant itself with a fork() call.
	 */
	fuse_opt_add_arg(&args, "-f");
	if (tagsistant.foreground) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** will run in foreground ***\n");
	}

	/*
	 * Will be verbose?
	 */
	if (tagsistant.verbose) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** will log verbosely ***\n");
		fuse_opt_add_arg(&args, "-d");
	}

	/*
	 * Have received DB options?
	 */
	if (tagsistant.dboptions) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** connecting to %s\n", tagsistant.dboptions);
	}

	/*
	 * The repository was provided?
	 */
	if (tagsistant.repository) {
		if (!tagsistant.quiet)
			fprintf(stderr, " *** saving repository in %s\n", tagsistant.repository);
	}

	/*
	 * add FUSE options
	 */
	gchar **fuse_opt = tagsistant.fuse_opts;
	while (fuse_opt && *fuse_opt) {
		fprintf(stderr, " *** Adding FUSE options %s\n", *fuse_opt);
		gchar *fuse_opt_string = g_strdup_printf("-o%s", *fuse_opt);
		fuse_opt_add_arg(&args, fuse_opt_string);
		fuse_opt++;
	}

	/*
	 * checking if mount point exists or can be created
	 */
	struct stat mst;
	if ((lstat(tagsistant.mountpoint, &mst) == -1) && (errno == ENOENT)) {
		if (mkdir(tagsistant.mountpoint, S_IRWXU|S_IRGRP|S_IXGRP) != 0) {
			// tagsistant_usage(tagsistant.progname);
			if (!tagsistant.quiet)
				fprintf(stderr, "\n *** Mountpoint %s does not exists and can't be created! ***\n", tagsistant.mountpoint);
			if (!tagsistant.show_config)
				exit(1);
		}
	}

	if (!tagsistant.quiet)
		fprintf(stderr, "\n"
		" Tagsistant (tagfs) v.%s (codename: %s)\n"
		" Build: %s FUSE_USE_VERSION: %d\n"
		" (c) 2006-2014 Tx0 <*****@*****.**>\n"
		" For license informations, see %s -h\n\n"
		, PACKAGE_VERSION, TAGSISTANT_CODENAME, TAGSISTANT_BUILDNUMBER
		, FUSE_USE_VERSION, tagsistant.progname
	);

	/* checking repository */
	if (!tagsistant.repository || (strcmp(tagsistant.repository, "") == 0)) {
		if (strlen(getenv("HOME"))) {
			g_free_null(tagsistant.repository);
			tagsistant.repository = g_strdup_printf("%s/.tagsistant", getenv("HOME"));
			if (!tagsistant.quiet)
				fprintf(stderr, " Using default repository %s\n", tagsistant.repository);
		} else {
			// tagsistant_usage(tagsistant.progname);
			if (!tagsistant.show_config) {
				if (!tagsistant.quiet)
					fprintf(stderr, "\n *** No repository provided with -r ***\n");
				exit(2);
			}
		}
	}

	/* removing last slash */
	int replength = strlen(tagsistant.repository) - 1;
	if (tagsistant.repository[replength] == '/') {
		tagsistant.repository[replength] = '\0';
	}

	/* checking if repository path begings with ~ */
	if (tagsistant.repository[0] == '~') {
		char *home_path = getenv("HOME");
		if (home_path != NULL) {
			char *relative_path = g_strdup(tagsistant.repository + 1);
			g_free_null(tagsistant.repository);
			tagsistant.repository = g_strdup_printf("%s%s", home_path, relative_path);
			g_free_null(relative_path);
			dbg('b', LOG_INFO, "Repository path is %s", tagsistant.repository);
		} else {
			dbg('b', LOG_ERR, "Repository path starts with '~', but $HOME was not available!");
		}
	} else 

	/* checking if repository is a relative path */
	if (tagsistant.repository[0] != '/') {
		dbg('b', LOG_ERR, "Repository path is relative [%s]", tagsistant.repository);
		char *cwd = getcwd(NULL, 0);
		if (cwd == NULL) {
			dbg('b', LOG_ERR, "Error getting working directory, will leave repository path as is");
		} else {
			gchar *absolute_repository = g_strdup_printf("%s/%s", cwd, tagsistant.repository);
			g_free_null(tagsistant.repository);
			tagsistant.repository = absolute_repository;
			dbg('b', LOG_ERR, "Repository path is %s", tagsistant.repository);
		}
	}

	struct stat repstat;
	if (lstat(tagsistant.repository, &repstat) == -1) {
		if(mkdir(tagsistant.repository, 755) == -1) {
			if (!tagsistant.quiet)
				fprintf(stderr, "\n *** REPOSITORY: Can't mkdir(%s): %s ***\n", tagsistant.repository, strerror(errno));
			exit(2);
		}
	}
	chmod(tagsistant.repository, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);

	/* opening (or creating) SQL tags database */
	tagsistant.tags = g_strdup_printf("%s/tags.sql", tagsistant.repository);

	/* tags.sql is also used by getattr() as a guaranteed file when asked for stats/ files */
	struct stat tags_st;
	if (-1 == stat(tagsistant.tags, &tags_st)) {
		int tags_fd = creat(tagsistant.tags, S_IRUSR|S_IWUSR);
		if (tags_fd) close(tags_fd);
	}

	/* checking file archive directory */
	tagsistant.archive = g_strdup_printf("%s/archive/", tagsistant.repository);

	if (lstat(tagsistant.archive, &repstat) == -1) {
		if(mkdir(tagsistant.archive, 755) == -1) {
			if (!tagsistant.quiet)
				fprintf(stderr, "\n *** ARCHIVE: Can't mkdir(%s): %s ***\n", tagsistant.archive, strerror(errno));
			exit(2);
		}
	}
	chmod(tagsistant.archive, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);

	dbg('b', LOG_INFO, "Debug is enabled: %s", tagsistant.debug ? "yes" : "no");

	umask(0);

#ifdef _DEBUG_SYSLOG
	tagsistant_init_syslog();
#endif

#if REGISTER_CLEANUP
	signal(2,  cleanup); /* SIGINT */
	signal(11, cleanup); /* SIGSEGV */
	signal(15, cleanup); /* SIGTERM */
#endif

#if !(GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 32)
	/*
	 * init the threading library
	 */
	g_thread_init(NULL);
#endif

	/*
	 * load repository.ini
	 */
	tagsistant_manage_repository_ini();

	/*
	 * loading plugins
	 */
	tagsistant_plugin_loader();

	/*
	 * fix the archive
	 */
	tagsistant_fix_archive();

	dbg('b', LOG_INFO, "Mounting filesystem");

	dbg('b', LOG_INFO, "Fuse options:");
	int fargc = args.argc;
	while (fargc) {
		dbg('b', LOG_INFO, "%.2d: %s", fargc, args.argv[fargc]);
		fargc--;
	}

	/*
	 * Send Tagsistant in the background, if applies
	 */
	if (!tagsistant.foreground) {
		pid_t pid = fork();
		if (pid) {
			if (!tagsistant.quiet)
				fprintf(stderr, "\n *** going in the background (PID: %d) ***\n", pid);
			exit(0);
		}
	}

	/*
	 * initialize db connection, SQL schema,
	 * an other subsystems
	 */
	tagsistant_db_init();
	tagsistant_create_schema();
	tagsistant_wal_sync();
	tagsistant_path_resolution_init();
	tagsistant_reasoner_init();
	tagsistant_utils_init();
	tagsistant_deduplication_init();

	/* SQLite requires tagsistant to run in single thread mode */
	if (tagsistant.sql_database_driver == TAGSISTANT_DBI_SQLITE_BACKEND) {
		// tagsistant.singlethread = TRUE;
		// fuse_opt_add_arg(&args, "-s");
	}

	/*
	 * print configuration if requested
	 */
	if (tagsistant.show_config) tagsistant_show_config();

	/* add the mount point */
	fuse_opt_add_arg(&args, tagsistant.mountpoint);

#if HAVE_SYS_XATTR_H
	if (tagsistant.enable_xattr) {
		tagsistant_oper.setxattr    = tagsistant_setxattr;
		tagsistant_oper.getxattr    = tagsistant_getxattr;
		tagsistant_oper.listxattr   = tagsistant_listxattr;
		tagsistant_oper.removexattr = tagsistant_removexattr;
	}
#endif

	/*
	 * run FUSE main event loop
	 */
	res = tagsistant_fuse_main(&args, &tagsistant_oper);
	fuse_opt_free_args(&args);

	/*
	 * unloading plugins
	 */
	tagsistant_plugin_unloader();

	/* free memory to better perform memory leak profiling */
	g_free_null(tagsistant.dboptions);
	g_free_null(tagsistant.repository);
	g_free_null(tagsistant.archive);
	g_free_null(tagsistant.tags);

	return(res);
}
コード例 #27
0
int main(int argc, char **argv)
{
  unsigned i;
  GError *error = NULL;
  GOptionContext *op_context;
  unsigned line_no = 0;
  GHashTable *contexts_by_str;
  GPtrArray *all_contexts;
  GHashTable *code_points_by_line;
  GPtrArray *all_code_points;
  char *tmp_fname;
  char **files;
  guint n_files;
  AllocInfo *total_by_time;
  op_context = g_option_context_new (NULL);
  g_option_context_set_summary (op_context, "gsk-analyze-successive-memdumps");
  g_option_context_add_main_entries (op_context, op_entries, NULL);
  if (!g_option_context_parse (op_context, &argc, &argv, &error))
    gsk_fatal_user_error ("error parsing command-line options: %s", error->message);
  g_option_context_free (op_context);

  contexts_by_str = g_hash_table_new (g_str_hash, g_str_equal);
  code_points_by_line = g_hash_table_new (g_str_hash, g_str_equal);
  all_contexts = g_ptr_array_new ();
  all_code_points = g_ptr_array_new ();

  if (dir_name == NULL)
    g_error ("missing argument directory");

  n_files = argc - 1;
  files = argv + 1;
  g_printerr ("Scanning %u input files... ", n_files);
  total_by_time = g_new0 (AllocInfo, n_files);
  for (i = 0; i < n_files; i++)
    {
      FILE *fp = fopen (files[i], "r");
      char buf[4096];
      GString *context_str = g_string_new ("");
      AllocInfo ai;
      Context *context;
      update_percent_bar (i, n_files);
      if (fp == NULL)
        gsk_fatal_user_error ("opening %s failed: %s",
	                      files[i], g_strerror (errno));
      do
        {
          if (!fgets (buf, sizeof (buf), fp))
            gsk_fatal_user_error ("file %s: unexpected eof", files[i]);
          line_no++;
        }
      while (is_preamble_line (buf));
next_block_start:
      if (g_str_has_prefix (buf, "Summary: "))
        goto done_file;
      if (sscanf (buf, "%u bytes allocated in %u blocks from:",
                      &ai.n_bytes, &ai.n_blocks) != 2)
        gsk_fatal_user_error ("error parsing line %u from %s",
                              line_no, files[i]);
      g_string_set_size (context_str, 0);
      for (;;)
        {
          if (fgets (buf, sizeof (buf), fp) == NULL)
            gsk_fatal_user_error ("file %s: unexpected eof", files[i]);
          line_no++;
          if (buf[0] != ' ')
            break;
          g_string_append (context_str, buf + 2);
        }

      /* find or create context */
      context = g_hash_table_lookup (contexts_by_str, context_str->str);
      if (context == NULL)
        {
          context = g_new (Context, 1);
          context->str = g_strdup (context_str->str);
          context->alloc_infos = g_new0 (AllocInfo, n_files);
          g_hash_table_insert (contexts_by_str, context->str, context);
          context->total_bytes = 0;
          g_ptr_array_add (all_contexts, context);
        }
      context->alloc_infos[i] = ai;
      context->total_bytes += ai.n_bytes;
      total_by_time[i].n_bytes += ai.n_bytes;
      total_by_time[i].n_blocks += ai.n_blocks;
      goto next_block_start;

done_file:
      fclose (fp);
    }
  update_percent_bar (i, n_files);

  g_ptr_array_sort (all_contexts, compare_p_context_by_total_bytes_descending);
  if (!gsk_mkdir_p (dir_name, 0755, &error))
    gsk_fatal_user_error ("error making directory %s: %s", dir_name, error->message);
  static const char *subdirs[] = { "data", "images", "code-points" };
  for (i = 0; i < G_N_ELEMENTS (subdirs); i++)
    {
      tmp_fname = g_strdup_printf ("%s/%s", dir_name, subdirs[i]);
      if (!gsk_mkdir_p (tmp_fname, 0755, &error))
        g_error ("error mkdir(%s): %s", tmp_fname, error->message);
      g_free (tmp_fname);
    }
  FILE *gnuplot_script_fp, *index_html_fp, *main_html_fp;
  tmp_fname = g_strdup_printf ("%s/gnuplot.input", dir_name);
  gnuplot_script_fp = fopen (tmp_fname, "w");
  if (gnuplot_script_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  g_free (tmp_fname);
  fprintf (gnuplot_script_fp,
           "set terminal png\n\n");
  index_html_fp = NULL;

  {
    FILE *fp;
    tmp_fname = g_strdup_printf ("%s/data/total.data", dir_name);
    fp = fopen (tmp_fname, "w");
    if (fp == NULL)
      g_error ("creating %s failed", tmp_fname);
    g_free (tmp_fname);
    for (i = 0; i < n_files; i++)
      fprintf (fp, "%u %u %u\n", i,
               total_by_time[i].n_bytes,
               total_by_time[i].n_blocks);
    fclose (fp);

    fprintf (gnuplot_script_fp,
             "set output \"%s/images/total.png\"\n", dir_name);
    fprintf (gnuplot_script_fp,
             "plot \"%s/data/total.data\" using 1:2 title \"bytes\", \"%s/data/total.data\" using 1:3 title \"blocks\"\n",
             dir_name, dir_name);
  }

  tmp_fname = g_strdup_printf ("%s/index.html", dir_name);
  main_html_fp = fopen (tmp_fname, "w");
  if (main_html_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  fprintf (main_html_fp, "<html><body>\n"
                         "Total:\n<br/><img src=\"images/total.png\" /><br/>\n"
                         "<ul>\n");

  g_printerr ("Writing data files for %u contexts... ", all_contexts->len);
  for (i = 0; i < all_contexts->len; i++)
    {
      FILE *fp;
      Context *context = all_contexts->pdata[i];
      guint j;
      update_percent_bar (i, all_contexts->len);
      if (i % 100 == 0)
        {
          if (index_html_fp != NULL)
            {
              fprintf (index_html_fp, "</body></html>\n");
              fclose (index_html_fp);
            }
          tmp_fname = g_strdup_printf ("%s/index-%03u.html", dir_name, i / 100);
          index_html_fp = fopen (tmp_fname, "w");
          if (index_html_fp == NULL)
            g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
          g_free (tmp_fname);
          fprintf (index_html_fp, "<html><body>\n");
          fprintf (index_html_fp, "<h1>Contexts %u .. %u</h1>\n", i, MIN (i + 99, all_contexts->len - 1));

          fprintf (main_html_fp, "<li><a href=\"index-%03u.html\">Contexts %u .. %u</a></li>\n",
                   i / 100,  i, MIN (i + 99, all_contexts->len - 1));
        }

      tmp_fname = g_strdup_printf ("%s/data/context-%05u.data", dir_name, i);
      fp = fopen (tmp_fname, "w");
      if (fp == NULL)
        g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
      for (j = 0; j < n_files; j++)
        fprintf (fp, "%u %u %u\n", j,
                 context->alloc_infos[j].n_bytes,
                 context->alloc_infos[j].n_blocks);
      fclose (fp);
      fprintf (gnuplot_script_fp,
               "set output \"%s/images/context-%05u.png\"\n", dir_name, i);
      fprintf (gnuplot_script_fp,
               "plot \"%s/data/context-%05u.data\" using 1:2 title \"bytes\", \"%s/data/context-%05u.data\" using 1:3 title \"blocks\"\n",
               dir_name, i,
               dir_name, i);

      pr_context (index_html_fp, i, context, "images");
    }
  update_percent_bar (i, all_contexts->len);
  fprintf (main_html_fp, "</ul>\n"
                         "<h1>Code Point Index</h1>\n"
                          "<a href=\"index-by-code-point.html\">here</a>\n");
  if (index_html_fp != NULL)
    {
      fprintf (index_html_fp, "</body></html>\n");
      fclose (index_html_fp);
    }
  fprintf (main_html_fp, "</body></html>\n");
  fclose (main_html_fp);

  g_printerr ("Calculating code-points... ");
  for (i = 0; i < all_contexts->len; i++)
    {
      Context *context = all_contexts->pdata[i];
      CodePoint *cp;
      char **strs = g_strsplit (context->str, "\n", 0);
      unsigned j;
      for (j = 0; strs[j] != NULL; j++)
        {
          g_strstrip (strs[j]);
          if (strs[j][0] != 0)
            {
              cp = g_hash_table_lookup (code_points_by_line, strs[j]);
              if (cp == NULL)
                {
                  cp = g_new (CodePoint, 1);
                  cp->line = g_strdup (strs[j]);
                  cp->context_indices = g_array_new (FALSE, FALSE, sizeof (guint));
                  g_hash_table_insert (code_points_by_line, cp->line, cp);
                  g_ptr_array_add (all_code_points, cp);
                }
              if (cp->context_indices->len == 0
               || g_array_index (cp->context_indices, guint, cp->context_indices->len - 1) != i)
                g_array_append_val (cp->context_indices, i);
            }
        }
      g_strfreev (strs);
    }
  g_printerr (" done [%u code points].\n", all_code_points->len);
  g_ptr_array_sort (all_code_points, compare_p_code_point_by_line);
  tmp_fname = g_strdup_printf ("%s/index-by-code-point.html", dir_name);
  main_html_fp = fopen (tmp_fname, "w");
  if (main_html_fp == NULL)
    g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
  g_free (tmp_fname);
  fprintf (main_html_fp,
           "<html><body><h1>Code Points</h1>\n");
  fprintf (main_html_fp,
           "<ul>\n");
  AllocInfo *totals;
  totals = g_new (AllocInfo, n_files);
  g_printerr ("Creating code-point data... ");
  for (i = 0; i < all_code_points->len; i++)
    {
      CodePoint *cp = all_code_points->pdata[i];
      FILE *fp;
      unsigned j;
      update_percent_bar (i, all_code_points->len);
      memset (totals, 0, sizeof (AllocInfo) * n_files);
      for (j = 0; j < cp->context_indices->len; j++)
        {
          guint context_index = g_array_index (cp->context_indices, guint, j);
          Context *context = all_contexts->pdata[context_index];
          guint k;
          for (k = 0; k < n_files; k++)
            {
              totals[k].n_bytes += context->alloc_infos[k].n_bytes;
              totals[k].n_blocks += context->alloc_infos[k].n_blocks;
            }
        }
      tmp_fname = g_strdup_printf ("%s/data/codepoint-%05u.data", dir_name, i);
      fp = fopen (tmp_fname, "w");
      for (j = 0; j < n_files; j++)
        fprintf (fp, "%u %u %u\n", j,
                 totals[j].n_bytes,
                 totals[j].n_blocks);
      fclose (fp);

      fprintf (gnuplot_script_fp,
               "set output \"%s/images/codepoint-%05u.png\"\n", dir_name, i);
      fprintf (gnuplot_script_fp,
               "plot \"%s/data/codepoint-%05u.data\" using 1:2 title \"bytes\", \"%s/data/codepoint-%05u.data\" using 1:3 title \"blocks\"\n",
               dir_name, i,
               dir_name, i);

      fprintf (main_html_fp, "<li>Code point %05u: <a href=\"code-points/%05u.html\">%s</a> (%u contexts)</li>\n",
               i, i, cp->line, cp->context_indices->len);
      tmp_fname = g_strdup_printf ("%s/code-points/%05u.html", dir_name, i);
      fp = fopen (tmp_fname, "w");
      if (fp == NULL)
        g_error ("error creating %s: %s", tmp_fname, g_strerror (errno));
      g_free (tmp_fname);



      fprintf (fp, "<html><body><h1>Code Point %u</h1>\n"
               "<b><pre>\n"
               "%s\n"
               "</pre>\n"
               "</b>\n", i, cp->line);
      fprintf (fp, "<p>Summary<br /><img src=\"../images/codepoint-%05u.png\" /></p>\n", i);
      for (j = 0; j < MIN (cp->context_indices->len, 100); j++)
        pr_context (fp, g_array_index (cp->context_indices, guint, j),
                    all_contexts->pdata[g_array_index (cp->context_indices, guint, j)],
                    "../images");
      if (j < cp->context_indices->len)
        fprintf (fp, "<p><b>%u Contexts omitted</b></p>\n",
                 (guint)(cp->context_indices->len - j));
      fprintf (fp,
               "</body></html>\n");
      fclose (fp);
    }
  update_percent_bar (i, all_code_points->len);
  fprintf (main_html_fp,
           "</ul>\n"
           "</body></html>\n");
  fclose (main_html_fp);

  fclose (gnuplot_script_fp);

  g_printerr ("Running gnuplot... ");
  tmp_fname = g_strdup_printf ("gnuplot < %s/gnuplot.input", dir_name);
  if (system (tmp_fname) != 0)
    gsk_fatal_user_error ("error running gnuplot");
  g_free (tmp_fname);
  g_printerr (" done.\n");

  return 0;
}
コード例 #28
0
int
main (int argc, char *argv[])
{
	GOptionContext *opt_ctx;
	GError *error = NULL;
	NMConnectionList *list;
	DBusGConnection *bus;
	char *type = NULL;
	gboolean create = FALSE;
	gboolean show = FALSE;
	gboolean success;
	char *uuid = NULL;
	NMCEService *service = NULL;
	DBusGProxy *proxy = NULL;
	gboolean show_list;

	GOptionEntry entries[] = {
		{ ARG_TYPE,   't', 0, G_OPTION_ARG_STRING, &type,   "Type of connection to show or create", NM_SETTING_WIRED_SETTING_NAME },
		{ ARG_CREATE, 'c', 0, G_OPTION_ARG_NONE,   &create, "Create a new connection", NULL },
		{ ARG_SHOW,   's', 0, G_OPTION_ARG_NONE,   &show,   "Show a given connection type page", NULL },
		{ "edit",     'e', 0, G_OPTION_ARG_STRING, &uuid,   "Edit an existing connection with a given UUID", "UUID" },
		{ NULL }
	};

	bindtextdomain (GETTEXT_PACKAGE, NMALOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	gtk_init (&argc, &argv);
	textdomain (GETTEXT_PACKAGE);

	opt_ctx = g_option_context_new (NULL);
	g_option_context_set_summary (opt_ctx, "Allows users to view and edit network connection settings");
	g_option_context_add_main_entries (opt_ctx, entries, NULL);
	success = g_option_context_parse (opt_ctx, &argc, &argv, &error);
	g_option_context_free (opt_ctx);

	if (!success) {
		g_warning ("%s\n", error->message);
		g_error_free (error);
		return 1;
	}

	/* Just one page for both CDMA & GSM, handle that here */
	if (type && g_strcmp0 (type, NM_SETTING_CDMA_SETTING_NAME) == 0)
		type = (char *) NM_SETTING_GSM_SETTING_NAME;

	/* Inits the dbus-glib type system too */
	bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
	if (bus) {
		proxy = dbus_g_proxy_new_for_name (bus,
		                                   "org.freedesktop.DBus",
		                                   "/org/freedesktop/DBus",
		                                   "org.freedesktop.DBus");
		g_assert (proxy);

		/* Check for an existing instance on the bus, and if there
		 * is one, send the arguments to it and exit instead of opening
		 * a second instance of the connection editor.
		 */
		if (try_existing_instance (bus, proxy, type, create, show, uuid))
			return 0;
	}

	loop = g_main_loop_new (NULL, FALSE);

	list = nm_connection_list_new ();
	if (!list) {
		g_warning ("Failed to initialize the UI, exiting...");
		return 1;
	}
	g_signal_connect_swapped (list, "done", G_CALLBACK (g_main_loop_quit), loop);

	/* Create our single-instance-app service if we can */
	if (proxy)
		service = nm_ce_service_new (bus, proxy, list);

	/* Show the dialog */
	g_signal_connect_swapped (list, "done", G_CALLBACK (g_main_loop_quit), loop);

	/* Figure out what page or editor window we'll show initially */
	show_list = handle_arguments (list, type, create, show, uuid, (create || show || uuid));
	if (show_list)
		nm_connection_list_present (list);

	setup_signals ();
	g_main_loop_run (loop);

	/* Cleanup */
	g_object_unref (list);
	if (service)
		g_object_unref (service);
	if (proxy)
		g_object_unref (proxy);
	if (bus)
		dbus_g_connection_unref (bus);
	return 0;
}
コード例 #29
0
ファイル: main.c プロジェクト: eaglexmw/pnmixer
/**
 * Program entry point. Initializes gtk+, calls the widget creating
 * functions and starts the main loop. Also connects 'popup-menu',
 * 'activate' and 'button-release-event' to the tray_icon.
 *
 * @param argc count of arguments
 * @param argv string array of arguments
 * @return 0 for success, otherwise error code
 */
int
main(int argc, char *argv[])
{
	GError *error = NULL;
	GOptionContext *context;
	want_debug = FALSE;

#ifdef ENABLE_NLS
	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
#endif

	DEBUG_PRINT("[Debugging Mode Build]\n");

	setlocale(LC_ALL, "");
	context = g_option_context_new(_("- A mixer for the system tray."));
	g_option_context_add_main_entries(context, args, GETTEXT_PACKAGE);
	g_option_context_add_group(context, gtk_get_option_group(TRUE));
	g_option_context_parse(context, &argc, &argv, &error);
	gtk_init(&argc, &argv);

	g_option_context_free(context);

	if (version) {
		printf(_("%s version: %s\n"), PACKAGE, VERSION);
		exit(0);
	}

	popup_window = NULL;

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

	prefs_ensure_save_dir();
	prefs_load();
	cards = NULL;		// so we don't try and free on first run
	alsa_init();
	init_libnotify();
	create_popup_window();
	create_popup_menu();
	add_filter();

	tray_icon = create_tray_icon();

	g_signal_connect(G_OBJECT(tray_icon), "popup-menu",
			 G_CALLBACK(popup_callback), popup_menu);
	g_signal_connect(G_OBJECT(tray_icon), "activate",
			 G_CALLBACK(tray_icon_on_click), NULL);
	g_signal_connect(G_OBJECT(tray_icon), "button-release-event",
			 G_CALLBACK(tray_icon_button), NULL);
	mute_check_popup_menu_handler =
		g_signal_connect(G_OBJECT(mute_check_popup_menu),
				"toggled", G_CALLBACK(on_mute_clicked), NULL);
	mute_check_popup_window_handler =
		g_signal_connect(G_OBJECT(mute_check_popup_window),
				"toggled", G_CALLBACK(on_mute_clicked), NULL);

	apply_prefs(0);

	gtk_main();
	uninit_libnotify();
	alsa_close();
	return 0;
}
コード例 #30
0
ファイル: main.c プロジェクト: krzyzanowskim/Gnome-Gadu
int
main (int argc, char **argv)
{
	GOptionContext *option_context;
	GnomeProgram *gnomegadu_app;
	gchar **remaining_args = NULL;
	
	GOptionEntry option_entries[] = {
		{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
		 &remaining_args,
		 "Special option that collects any remaining arguments for us"},
		{NULL}
	};


	gg_debug_level = 255;

	option_context = g_option_context_new ("gnomegadu-app");

	g_option_context_add_main_entries (option_context, option_entries,
					   NULL);

	gnomegadu_app = gnome_program_init (PACKAGE_NAME, PACKAGE_VERSION,
					    LIBGNOMEUI_MODULE, argc, argv,
					    GNOME_PARAM_GOPTION_CONTEXT,
					    option_context,
					    GNOME_PARAM_HUMAN_READABLE_NAME,
					    PACKAGE_READABLE_NAME,
					    GNOME_PARAM_NONE);



	if (remaining_args != NULL)
	{
		gint i, num_args;

		num_args = g_strv_length (remaining_args);
		for (i = 0; i < num_args; ++i)
		{
			/*
			 * process remaining_args[i] here 
			 */
		}
		g_strfreev (remaining_args);
		remaining_args = NULL;
	}


	gnomegadu_conf_init (gnomegadu_app);

	if (gconf_client_get_bool (gconf, g_strconcat(gnomegadu_gconf_relative_path, "/sound",NULL), NULL))
		gnome_sound_init (NULL);

	gnomegadu_ui_init ();

	if (!notify_is_initted())
		notify_init(PACKAGE);


	gnomegadu_protocol_is_connected	= FALSE;
	//gnomegadu_galago_init();
	
	gtk_main ();

	g_object_unref (gnomegadu_app);

	return 0;
}