コード例 #1
0
ファイル: simple-proxy.c プロジェクト: DrGore/libsoup
int
main (int argc, char **argv)
{
	GOptionContext *opts;
	GMainLoop *loop;
	GError *error = NULL;

	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 ("Could not parse arguments: %s\n",
			    error->message);
		g_printerr ("%s",
			    g_option_context_get_help (opts, TRUE, NULL));
		exit (1);
	}

	if (argc != 2) {
		g_printerr ("%s",
			    g_option_context_get_help (opts, TRUE, NULL));
		exit (1);
	}
	g_option_context_free (opts);

	signal (SIGINT, quit);

	server = soup_server_new (SOUP_SERVER_PORT, port,
				  NULL);
	if (!server) {
		g_printerr ("Unable to bind to server port %d\n", port);
		exit (1);
	}
	soup_server_add_handler (server, NULL,
				 server_callback, NULL, NULL);
	if (require_auth) {
		SoupAuthDomain *auth_domain;

		auth_domain = soup_auth_domain_basic_new (
			SOUP_AUTH_DOMAIN_REALM, "simple-proxy",
			SOUP_AUTH_DOMAIN_PROXY, TRUE,
			SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, auth_callback,
			NULL);
		soup_server_add_auth_domain (server, auth_domain);
		g_object_unref (auth_domain);
	}

	g_print ("\nStarting proxy on port %d\n",
		 soup_server_get_port (server));
	soup_server_run_async (server);

	session = soup_session_async_new ();

	g_print ("\nWaiting for requests...\n");

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

	return 0;
}
コード例 #2
0
ファイル: bin-search.c プロジェクト: rlugojr/ia-bin-tools
static void
parse_command_line (int    *argc,
                    char ***argv)
{
  GOptionContext *context = g_option_context_new ("STRING FILE...");
  GError *error = NULL;

  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_set_summary (context, "Perform binary search of sorted text file(s).");
  g_option_context_set_description (context, "Input file MUST have specified column in normal \"sort\" order, or may be in \"sort -r\" order when using \"-r\" option."
      "\n\nStrings are compared according to their native byte values, so the files need to have been sorted with LC_COLLATE=C (or LC_ALL=C)."
      "\n\nAssumes lines are terminated by a single newline character '\\n'."
      "\n\nProgram will binary search the file, looking for a(ny) line that begins with the string.\n");

  if (!g_option_context_parse (context, argc, argv, &error))
    {
      g_printerr ("bin-search: %s\n\n", error->message);
      g_printerr ("%s", g_option_context_get_help (context, TRUE, NULL));
      exit (1);
    }

  if (*argc < 3)
    {
      g_printerr ("bin-search: error: You must specify a search string and at least one file to search\n\n");
      g_printerr ("%s", g_option_context_get_help (context, TRUE, NULL));
      exit (2);
    }

  g_option_context_free (context);
}
コード例 #3
0
ファイル: layer_unload_bash_cmds.c プロジェクト: frdcms/mfext
int main(int argc, char *argv[])
{
    int result = 1;
    GOptionContext *context;
    setlocale(LC_ALL, "");
    context = g_option_context_new("LAYER_LABEL OR LAYER_HOME - output bash commands to eval to unload the given layer");
    g_option_context_add_main_entries(context, entries, NULL);
    if (!g_option_context_parse(context, &argc, &argv, NULL)) {
        g_print(g_option_context_get_help(context, TRUE, NULL));
        exit(1);
    }
    if (argc != 2) {
        g_print(g_option_context_get_help(context, TRUE, NULL));
        exit(1);
    }
    layerapi2_init(debug_mode);
    const gchar *label_or_home = argv[1];
    GString *gs = g_string_new(NULL);
    gboolean res = layerapi2_layer_unload(label_or_home, &gs);
    if (res) {
        gchar *bash_cmds = g_string_free(gs, FALSE);
        g_printf(bash_cmds);
        g_free(bash_cmds);
        result = 0;
    } else {
        g_string_free(gs, TRUE);
    }
    layerapi2_destroy();
    return result;
}
コード例 #4
0
ファイル: echo_clean.c プロジェクト: frdcms/mfcom
int main(int argc, char *argv[])
{
    /**
     * Variables globales
     */
    GError *error = NULL;
    GOptionContext *context;
    int res = 0;

    /**
     * Parsing de la ligne de commande
     */
    setlocale(LC_ALL, "");
    context = g_option_context_new(" - clean waiting status");
    g_option_context_add_main_entries(context, entries, NULL);
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_print(g_option_context_get_help(context, TRUE, NULL));
        fprintf(stderr, "ERROR WHEN COMMAND LINE PARSING\n");
    }
    if (argc > 1) {
        g_print(g_option_context_get_help(context, TRUE, NULL));
        fprintf(stderr, "ERROR WHEN COMMAND LINE PARSING\n");
    }

    /**
     * Appel
     */
    synutil_echo_clean();

    /**
     * Libération / sortie
     */
    return res;
}
コード例 #5
0
int main (int argc, char **argv)
{
	GOptionContext *context;

	setlocale (LC_ALL, "");

	context = g_option_context_new (NULL);
	g_option_context_set_summary (context, "xplayer-pl-parser libquvi Helper");
	g_option_context_add_main_entries (context, options, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);

	if (url == NULL) {
		char *txt;

		txt = g_option_context_get_help (context, FALSE, NULL);
		g_print ("%s", txt);
		g_free (txt);

		g_option_context_free (context);

		return 1;
	}
	g_option_context_free (context);

	if (check) {
		g_print ("%s", supports_uri (url) ? "TRUE" : "FALSE");
		return 0;
	}

	parse_videosite (url);

	return 0;
}
コード例 #6
0
ファイル: Settings.c プロジェクト: ExPixel/visualboyadvance
void settings_display_usage() {
	GOptionContext *context = g_option_context_new(NULL);
	gchar *usage = g_option_context_get_help(context, FALSE, NULL);
	g_option_context_free(context);
	g_print("%s", usage);
	g_free(usage);
}
コード例 #7
0
ファイル: red2test.c プロジェクト: montsuqi/monpe
int main(int argc, char *argv[])
{
  gchar *dfile;
  GError *error = NULL;
  GOptionContext *ctx;
  gchar *buf;
  char *nargv[3];

  ctx = g_option_context_new("<.red>");
  g_option_context_add_main_entries(ctx, entries, NULL);
  if (!g_option_context_parse(ctx,&argc,&argv,&error)) {
    g_print("option parsing failed:%s\n",error->message);
    exit(1);
  }
  if (argc < 2) {
    g_print("%s",g_option_context_get_help(ctx,TRUE,NULL));
    exit(1);
  }
  dfile = g_strdup_printf("/tmp/red2test.%d.dat",(int)getpid());
  red2fill(argv[1],imagepath,dfile);
  nargv[0] = "";
  nargv[1] = argv[1];
  nargv[2] = dfile;
  buf = red2embed(3,nargv);
  remove(dfile);
  if (outfile != NULL) {
    if (!g_file_set_contents(outfile,buf,strlen(buf),NULL)) {
      g_error("Error: unable to write file:%s\n",outfile);
    }
  } else {
    printf("%s",buf);
  }
  return 0;
}
コード例 #8
0
ファイル: mu-config.c プロジェクト: Popsch/mu
void
mu_config_show_help (MuConfigCmd cmd)
{
	GOptionContext *ctx;
	GOptionGroup *group;
	char *cleanhelp;

	g_return_if_fail (mu_config_cmd_is_valid(cmd));

	ctx = g_option_context_new ("");
	g_option_context_set_main_group	(ctx, config_options_group_mu());

	group = get_option_group (cmd);
	if (group)
		g_option_context_add_group (ctx, group);

	g_option_context_set_description (ctx,
					  get_help_string (cmd, TRUE));
	cleanhelp = massage_help
		(g_option_context_get_help (ctx, TRUE, group));

	g_print ("usage:\n\t%s\n%s",
		 get_help_string (cmd, FALSE), cleanhelp);

	g_free (cleanhelp);
}
コード例 #9
0
static void
usage (gint argc, gchar ** argv, GOptionContext * ctx)
{
  gchar *help = g_option_context_get_help (ctx, TRUE, NULL);
  puts (help);
  g_free (help);
}
コード例 #10
0
ファイル: emoji-parser.c プロジェクト: Archer-sys/ibus
int
main (int argc, char *argv[])
{
    gchar *prgname;
    gchar *json_file = NULL;
    gchar *xml_file = NULL;
    gchar *output = NULL;
    GOptionEntry     entries[] = {
        { "json", 'j', 0, G_OPTION_ARG_STRING, &json_file,
          "Parse Emoji One JSON file",
          "JSON"
        },
        { "out", 'o', 0, G_OPTION_ARG_STRING, &output,
          "Save the emoji dictionary as FILE",
          "FILE"
        },
        { "xml", 'x', 0, G_OPTION_ARG_STRING, &xml_file,
          "Parse Unocode.org ANNOTATIONS file",
          "ANNOTATIONS"
        },
        { NULL }
    };
    GOptionContext *context;
    GError *error = NULL;
    GHashTable *dict;

    prgname = g_path_get_basename (argv[0]);
    g_set_prgname (prgname);
    g_free (prgname);

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

    if (argc < 3) {
        g_print ("%s", g_option_context_get_help (context, TRUE, NULL));
        g_option_context_free (context);
        return -1;
    }

    if (!g_option_context_parse (context, &argc, &argv, &error)) {
        g_warning ("Failed options: %s", error->message);
        g_error_free (error);
        return -1;
    }
    g_option_context_free (context);

    dict = g_hash_table_new_full (g_str_hash,
                                  g_str_equal,
                                  g_free,
                                  free_dict_words);
    if (xml_file)
        unicode_annotations_parse_xml_file (xml_file, dict);
    if (json_file)
        emojione_parse_json_file (json_file, dict);
    if (g_hash_table_size (dict) > 0 && output)
        ibus_emoji_dict_save (output, dict);
    g_hash_table_destroy (dict);

    return 0;
}
コード例 #11
0
int main (int argc, char **argv)
{
	GOptionGroup *options;
	GOptionContext *context;
	GError *error = NULL;
	GMainLoop *loop;
	GstElement *play;

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

	g_set_application_name (_("Audio Preview"));
	g_setenv("PULSE_PROP_application.icon_name", "totem", TRUE);
	g_setenv("PULSE_PROP_media.role", "music", TRUE);

	context = g_option_context_new ("Plays audio passed on the standard input or the filename passed on the command-line");
	options = gst_init_get_option_group ();
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group (context, options);

	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print ("couldn't parse command-line options: %s\n", error->message);
		g_error_free (error);
		return 1;
	}

	if (g_fatal_warnings) {
		GLogLevelFlags fatal_mask;

		fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
		fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
		g_log_set_always_fatal (fatal_mask);
	}

	if (show_mimetype == TRUE) {
		print_mimetypes ();
		return 0;
	}

	if (filenames != NULL && g_strv_length (filenames) != 1) {
		char *help;
		help = g_option_context_get_help (context, FALSE, NULL);
		g_print ("%s", help);
		g_free (help);
		return 1;
	}

	play = gst_element_factory_make ("playbin", "play");
	setup_play (play);
	setup_filename (play);
	setup_errors (play);
	totem_resources_monitor_start (NULL, -1);
	gst_element_set_state (play, GST_STATE_PLAYING);

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);

	return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: aalex/gtranscoder
int main(int argc, char *argv[])
{
    bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
    
    g_set_application_name (_("Gtranscoder"));

    GtranscoderOptions *options = g_new0(GtranscoderOptions, 1);;
    GOptionEntry entries[] =
    {
        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &options->verbose, N_("Print debug info"), NULL },
        { "version", 'V', 0, G_OPTION_ARG_NONE, &options->show_version, N_("Show version number and exit"), NULL },
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
    };

    GError *error = NULL;
    GOptionContext *context;
  
    context = g_option_context_new(N_("- Movie transcoding program"));
    g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    if (g_option_context_parse(context, &argc, &argv, &error) == FALSE)
    {
        gchar *help_text = g_option_context_get_help (context, TRUE, NULL);
        g_print ("%s\n\n%s", error->message, help_text);
        g_free (help_text);
        g_error_free (error);
        g_option_context_free (context);
        g_free(options);
        return 1;
    }
    if (options->show_version)
    {
        g_print("Gtranscoder " VERSION " \n");
        return 0;
    }

    g_option_context_free (context);
    gtk_init(&argc, &argv);
    
    gboolean has_ffmpeg = check_for_ffmpeg();
    if (! has_ffmpeg)
    {
        gchar *error_mess = N_("Gtranscoder could not find the ffmpeg executable. Aborting.");
        g_critical("%s", error_mess);
        gtranscoder_show_error_dialog_without_main_loop(error_mess);
        g_error("%s", N_("ffmpeg is required."));
        return 1;
    }
    else
    {
        g_debug("%s", N_("Found ffmpeg"));
        run_main_window(options);
        gtk_main();
    }
    g_free(options);
    return 0;
}
コード例 #13
0
int
main (int argc, char **argv)
{
  GError *err = NULL;
  GOptionContext *ctx;
  GESPipeline *pipeline;
  GMainLoop *mainloop;
  gdouble duration = DEFAULT_DURATION;
  char *path = NULL, *text;
  guint64 color;
  gdouble xpos = DEFAULT_POS, ypos = DEFAULT_POS;

  GOptionEntry options[] = {
    {"duration", 'd', 0, G_OPTION_ARG_DOUBLE, &duration,
        "duration of segment", "seconds"},
    {"path", 'p', 0, G_OPTION_ARG_STRING, &path,
        "path to file", "path"},
    {"text", 't', 0, G_OPTION_ARG_STRING, &text,
        "text to render", "text"},
    {"color", 'c', 0, G_OPTION_ARG_INT64, &color,
        "color of the text", "color"},
    {"xpos", 'x', 0, G_OPTION_ARG_DOUBLE, &xpos,
        "horizontal position of the text", "color"},
    {"ypos", 'y', 0, G_OPTION_ARG_DOUBLE, &ypos,
        "vertical position of the text", "color"},
    {NULL}
  };

  ctx = g_option_context_new ("- file segment playback with text overlay");
  g_option_context_add_main_entries (ctx, options, NULL);
  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);
  }

  if (argc > 1) {
    g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
    exit (0);
  }

  g_option_context_free (ctx);

  ges_init ();

  if (path == NULL)
    g_error ("Must specify --path=/path/to/media/file option\n");

  pipeline = make_timeline (path, duration, text, color, xpos, ypos);

  mainloop = g_main_loop_new (NULL, FALSE);
  g_timeout_add_seconds ((duration) + 1, (GSourceFunc) g_main_loop_quit,
      mainloop);
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  g_main_loop_run (mainloop);

  return 0;
}
コード例 #14
0
int
main (int argc, char *argv[])
{
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMountPoints *mounts;
  GstRTSPMediaFactory *factory;
  GOptionContext *optctx;
  GError *error = NULL;

  optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n"
      "Example: \"( decodebin name=depay0 ! autovideosink )\"");
  g_option_context_add_main_entries (optctx, entries, NULL);
  g_option_context_add_group (optctx, gst_init_get_option_group ());
  if (!g_option_context_parse (optctx, &argc, &argv, &error)) {
    g_printerr ("Error parsing options: %s\n", error->message);
    return -1;
  }

  if (argc < 2) {
    g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL));
    return 1;
  }
  g_option_context_free (optctx);

  loop = g_main_loop_new (NULL, FALSE);

  /* create a server instance */
  server = gst_rtsp_server_new ();

  /* get the mount points for this server, every server has a default object
   * that be used to map uri mount points to media factories */
  mounts = gst_rtsp_server_get_mount_points (server);

  /* make a media factory for a test stream. The default media factory can use
   * gst-launch syntax to create pipelines.
   * any launch line works as long as it contains elements named depay%d. Each
   * element with depay%d names will be a stream */
  factory = gst_rtsp_media_factory_new ();
  gst_rtsp_media_factory_set_transport_mode (factory,
      GST_RTSP_TRANSPORT_MODE_RECORD);
  gst_rtsp_media_factory_set_launch (factory, argv[1]);
  gst_rtsp_media_factory_set_latency (factory, 2000);

  /* attach the test factory to the /test url */
  gst_rtsp_mount_points_add_factory (mounts, "/test", factory);

  /* don't need the ref to the mapper anymore */
  g_object_unref (mounts);

  /* attach the server to the default maincontext */
  gst_rtsp_server_attach (server, NULL);

  /* start serving */
  g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port);
  g_main_loop_run (loop);

  return 0;
}
コード例 #15
0
ファイル: rsvg-dimensions.c プロジェクト: brion/librsvg
static void
show_help (GOptionContext *context)
{
    char *help;
    help = g_option_context_get_help (context, TRUE, NULL);
    perror (help);
    g_free (help), help = NULL;
}
コード例 #16
0
ファイル: rspamadm.c プロジェクト: jeromelebleu/rspamd
static void
rspamadm_usage (GOptionContext *context)
{
	gchar *help_str;

	help_str = g_option_context_get_help (context, TRUE, NULL);
	printf ("%s", help_str);
}
コード例 #17
0
ファイル: ot-opt-utils.c プロジェクト: endlessm/ostree
void
ot_util_usage_error (GOptionContext *context, const char *message, GError **error)
{
  gchar *help = g_option_context_get_help (context, TRUE, NULL);
  g_printerr ("%s\n", help);
  g_free (help);
  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
}
コード例 #18
0
ファイル: ot-builtin-checkout.c プロジェクト: 14rcole/ostree
gboolean
ostree_builtin_checkout (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  GOptionContext *context;
  glnx_unref_object OstreeRepo *repo = NULL;
  gboolean ret = FALSE;
  const char *commit;
  const char *destination;
  g_autofree char *resolved_commit = NULL;

  context = g_option_context_new ("COMMIT [DESTINATION] - Check out a commit into a filesystem tree");

  if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
    goto out;

  if (opt_disable_fsync)
    ostree_repo_set_disable_fsync (repo, TRUE);

  if (argc < 2)
    {
      gchar *help = g_option_context_get_help (context, TRUE, NULL);
      g_printerr ("%s\n", help);
      g_free (help);
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "COMMIT must be specified");
      goto out;
    }

  if (opt_from_stdin || opt_from_file)
    {
      destination = argv[1];

      if (!process_many_checkouts (repo, destination, cancellable, error))
        goto out;
    }
  else
    {
      commit = argv[1];
      if (argc < 3)
        destination = commit;
      else
        destination = argv[2];

      if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error))
        goto out;

      if (!process_one_checkout (repo, resolved_commit, opt_subpath,
                                 destination,
                                 cancellable, error))
        goto out;
    }

  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  return ret;
}
コード例 #19
0
ファイル: syslog-ng-ctl.c プロジェクト: balabit/syslog-ng
static gint
slng_passwd_add(int argc, char *argv[], const gchar *mode, GOptionContext *ctx)
{
  gchar *answer;
  gint remaining_unused_index = 0;


  if (!credentials_key)
    credentials_key = consume_next_from_remaining(credentials_remaining, &remaining_unused_index);

  if (!credentials_key)
    {
      gchar *usage = g_option_context_get_help(ctx, TRUE, NULL);
      fprintf(stderr, "Error: missing arguments!\n%s\n", usage);
      g_free(usage);
      return 1;
    }

  if (!is_syslog_ng_running())
    return 1;

  if (!credentials_secret)
    credentials_secret = consume_next_from_remaining(credentials_remaining, &remaining_unused_index);

  gchar *secret_to_store;
  if (credentials_secret)
    {
      secret_to_store = g_strdup(credentials_secret);
      if (!secret_to_store)
        g_assert_not_reached();
    }
  else
    {
      gsize buff_size = 256;
      secret_to_store = g_malloc0(buff_size);
      if (!secret_to_store)
        g_assert_not_reached();

      read_password_from_stdin(secret_to_store, &buff_size);
    }

  gint retval = asprintf(&answer, "PWD %s %s %s", "add", credentials_key, secret_to_store);
  if (retval == -1)
    g_assert_not_reached();

  secret_storage_wipe(secret_to_store, strlen(secret_to_store));
  g_free(secret_to_store);

  if (credentials_secret)
    secret_storage_wipe(credentials_secret, strlen(credentials_secret));

  gint result = _dispatch_command(answer);

  secret_storage_wipe(answer, strlen(answer));
  g_free(answer);

  return result;
}
コード例 #20
0
ファイル: main.c プロジェクト: pwithnall/bendy-bus
static void
print_help_text (GOptionContext *context)
{
	gchar *help_text;

	help_text = g_option_context_get_help (context, TRUE, NULL);
	puts (help_text);
	g_free (help_text);
}
コード例 #21
0
ファイル: flatpak-main.c プロジェクト: anssih/flatpak
gboolean
usage_error (GOptionContext *context, const char *message, GError **error)
{
  g_autofree gchar *help = g_option_context_get_help (context, TRUE, NULL);

  g_printerr ("%s", help);
  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
  return FALSE;
}
コード例 #22
0
ファイル: builder-main.c プロジェクト: cosimoc/flatpak
int
usage (GOptionContext *context, const char *message)
{
  g_autofree gchar *help = g_option_context_get_help (context, TRUE, NULL);

  g_printerr ("%s\n", message);
  g_printerr ("%s", help);
  return 1;
}
コード例 #23
0
ファイル: test-download.c プロジェクト: Endz0/uget
int main (int argc, char* argv[])
{
	const UgOptionEntry*	uoentry;
	UgDataset*		dataset;
	UgetCommon*	common;
	UgPlugin*		plugin;

	GOptionContext*	context;
	GOptionGroup*	group;
	GError*			error = NULL;

#ifdef _WIN32	//	curl_global_init() will do this
	WSADATA WSAData;

	WSAStartup (MAKEWORD (2, 2), &WSAData);
#endif

	uglib_init ();

	// parse command-line options
	context = g_option_context_new ("[URL]");
	group	= g_option_group_new (NULL, NULL, NULL, NULL, NULL);
	uoentry = ug_option_get_main_entry ();
	g_option_group_add_entries (group, uoentry->entry);
	g_option_context_set_main_group (context, group);
	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print ("Option parsing failed : %s\n", error->message);
		exit (EXIT_FAILURE);		// EXIT_FAILURE == 1
	}

	// get URL from remained arguments
	if (argc == 1) {
		g_print ("%s", g_option_context_get_help (context, TRUE, NULL));
		exit (EXIT_FAILURE);		// EXIT_FAILURE == 1
	}
	dataset = ug_dataset_new ();
	ug_option_entry_get (uoentry, dataset);
	common = ug_dataset_realloc (dataset, UgetCommonInfo, 0);
	common->url = g_strdup (argv[1]);

	plugin = ug_plugin_new_by_data (dataset);
	ug_dataset_unref (dataset);
	if (plugin) {
		ug_plugin_set_state (plugin, UG_STATE_ACTIVE);
		while (ug_plugin_dispatch (plugin, plugin_callback, NULL))
			ug_plugin_delay (plugin, 1000);
		ug_plugin_unref (plugin);
	}

	uglib_finalize ();
#ifdef _WIN32
	WSACleanup ();
#endif

	return EXIT_SUCCESS;		// EXIT_SUCCESS == 0
}
コード例 #24
0
ファイル: data-validator.c プロジェクト: Codeminded/tracker
gint
main (gint argc, gchar **argv)
{
	GOptionContext *context;
	TrackerTurtleReader *reader;
	GError *error = NULL;

	g_type_init ();

	/* Translators: this messagge will apper immediately after the  */
	/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>     */
	context = g_option_context_new ("- Validate a turtle file against the ontology");

	/* Translators: this message will appear after the usage string */
	/* and before the list of options.                              */
	g_option_context_add_main_entries (context, entries, NULL);
	g_option_context_parse (context, &argc, &argv, NULL);

	if (!ontology_dir || !ttl_file) {
		gchar *help;

		g_printerr ("%s\n\n",
		            "Ontology directory and turtle file are mandatory");

		help = g_option_context_get_help (context, TRUE, NULL);
		g_option_context_free (context);
		g_printerr ("%s", help);
		g_free (help);

		return -1;
	}

	//"/home/ivan/devel/codethink/tracker-ssh/data/services"
	load_ontology_files (ontology_dir);

	reader = tracker_turtle_reader_new (ttl_file, NULL);

	while (error == NULL && tracker_turtle_reader_next (reader, &error)) {
		turtle_statement_handler (tracker_turtle_reader_get_subject (reader),
		                          tracker_turtle_reader_get_predicate (reader),
		                          tracker_turtle_reader_get_object (reader));
	}

	g_object_unref (reader);

	if (error) {
		g_message ("Turtle parse error: %s", error->message);
		g_error_free (error);
	}

	if (!error_flag) {
		g_debug ("%s seems OK.", ttl_file);
	}

	return 0;
}
コード例 #25
0
void
milter_manager_init (int *argc, char ***argv)
{
    GOptionContext *option_context;
    GOptionGroup *milter_group;
    GError *error = NULL;
    MilterManager *manager;
    MilterManagerConfiguration *config;

    if (initialized)
        return;

    initialized = TRUE;

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

    milter_init();
    milter_client_init();
    milter_server_init();
    milter_manager_log_handler_id = MILTER_GLIB_LOG_DELEGATE("milter-manager");

    option_context = g_option_context_new(NULL);
    g_option_context_add_main_entries(option_context, option_entries,
                                      GETTEXT_PACKAGE);

    _milter_manager_configuration_init();
    config = milter_manager_configuration_new(NULL);
    manager = milter_manager_new(config);
    g_object_unref(config);
    milter_group = milter_client_get_option_group(MILTER_CLIENT(manager));
    g_option_context_add_group(option_context, milter_group);

    if (!g_option_context_parse(option_context, argc, argv, &error)) {
        g_print("%s\n", error->message);

        if (g_error_matches(error,
                            G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION)) {
            gchar *help;
            help = g_option_context_get_help(option_context, TRUE, NULL);
            g_print("\n%s", help);
            g_free(help);
        }

        g_error_free(error);
        g_option_context_free(option_context);
        g_object_unref(manager);

        exit(EXIT_FAILURE);
    }

    g_option_context_free(option_context);
    the_manager = manager;
}
コード例 #26
0
void _openslide_tools_usage(const struct openslide_tools_usage_info *info) {
  GOptionContext *octx = make_option_context(info);

  gchar *help = g_option_context_get_help(octx, TRUE, NULL);
  fprintf(stderr, "%s", help);
  g_free(help);

  g_option_context_free(octx);
  exit(2);
}
コード例 #27
0
ファイル: imgclip.c プロジェクト: shibumi/teiler
int main(int argc, char **argv) {
    int ret = EXIT_FAILURE;
    GtkClipboard *cb = NULL;
    GdkPixbuf *image = NULL;
    GError *e = NULL;
    GOptionContext *opt_ctx = NULL;
    char *help = NULL;
    static int timeout;
    static const GOptionEntry entries[] = {
        { "timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Timeout", "secs" }, 
        { NULL, 0, 0, 0, NULL, NULL, NULL }
    };

    opt_ctx = g_option_context_new("<file>");

    g_option_context_add_main_entries(opt_ctx, entries, NULL);
    if (!g_option_context_parse(opt_ctx, &argc, &argv, &e)) {
        fprintf(stderr, "%s\n", e->message);
        goto error_out;
    }

    if (argc == 1 || !g_file_test(argv[1], G_FILE_TEST_EXISTS)) {
        help = g_option_context_get_help(opt_ctx, TRUE, NULL);
        fprintf(stderr, "%s", help);
        g_free(help);
        goto error_out;
    }

    image = gdk_pixbuf_new_from_file(argv[1], &e);
    if (image == NULL) {
        fprintf(stderr, "%s\n", e->message);
        goto error_out;
    }

    gtk_init(&argc, &argv);

    cb = gtk_clipboard_get(GDK_NONE);
    gtk_clipboard_set_image(cb, image);
    g_signal_connect(G_OBJECT(cb), "owner-change", G_CALLBACK(on_owner_change), NULL);

    if (timeout > 0) {
        g_timeout_add_seconds(timeout, (GSourceFunc)on_timeout_expired, NULL);
    }

    gtk_main();

    g_object_unref(image);

    ret = EXIT_SUCCESS;

error_out: 
    g_option_context_free(opt_ctx);

    return ret;
}
コード例 #28
0
int
main (int argc, char *argv[])
{
  GError *err = NULL;
  gint cpu_usage = 100;
  GstTranscoder *transcoder;
  gchar *src_uri, *dest_uri;
  GOptionContext *ctx;

  GOptionEntry options[] = {
    {"cpu-usage", 'c', 0, G_OPTION_ARG_INT, &cpu_usage,
        "The CPU usage to target in the transcoding process", NULL},
    {NULL}
  };

  g_set_prgname ("gst-play");

  ctx = g_option_context_new ("<source uri> <destination uri> "
      "<encoding target name>[/<encoding profile name>]");

  g_option_context_add_main_entries (ctx, options, NULL);
  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", GST_STR_NULL (err->message));
    g_clear_error (&err);
    g_option_context_free (ctx);
    return 1;
  }

  if (argc != 4) {
    g_print ("%s", g_option_context_get_help (ctx, TRUE, NULL));
    g_option_context_free (ctx);

    return -1;
  }
  g_option_context_free (ctx);

  src_uri = ensure_uri (argv[1]);
  dest_uri = ensure_uri (argv[2]);
  transcoder = gst_transcoder_new (src_uri, dest_uri, argv[3]);
  gst_transcoder_set_cpu_usage (transcoder, cpu_usage);
  g_signal_connect (transcoder, "position-updated",
      G_CALLBACK (position_updated_cb), NULL);

  g_assert (transcoder);

  gst_transcoder_run (transcoder, &err);

  if (err)
    GST_ERROR ("Badam %s", err->message);

  return 0;
}
コード例 #29
0
ファイル: main.c プロジェクト: chergert/egg-fmt
gint
main (gint   argc,
      gchar *argv[])
{
	GOptionContext *context;
	GIOChannel     *channel;
	GError         *error = NULL;
	EggFmtFunc      formatter;
	EggFmtIter      iter;

	/* Parse command line options for formatter */
	context = g_option_context_new ("[FILENAME] - egg-fmt example");
	g_option_context_add_main_entries (context, entries, NULL);
	if (!g_option_context_parse (context, &argc, &argv, &error)) {
		g_printerr ("%s\n", error->message);
		return EXIT_FAILURE;
	}

	/* make sure a filename was provided */
	if (argc < 2) {
		g_printerr ("%s", g_option_context_get_help (context, TRUE, NULL));
		return EXIT_FAILURE;
	}

	g_type_init ();

	/* we will read in a simple pipe delimited file for testing
	 * our data set.  It's format/types are known.
	 */
	if (!(channel = g_io_channel_new_file (argv [1], "r", &error))) {
		g_printerr ("Could not open file %s\n", argv [1]);
		return EXIT_FAILURE;
	}

	/* Set the proper output formatter */
	formatter = opt_csv ? egg_fmt_csv : (opt_html ? egg_fmt_html_table : egg_fmt_table);

	/* initialize the EggFmtIter for use */
	egg_fmt_iter_init (&iter,
	                   iter_func,
	                   "ID",        G_TYPE_INT,
	                   "State",     G_TYPE_STRING,
	                   "Sources",   G_TYPE_INT,
	                   "Program",   G_TYPE_STRING,
	                   "Arguments", G_TYPE_STRING,
	                   NULL);

	/* Write output to console */
	formatter (&iter, channel, NULL);

	return EXIT_SUCCESS;
}
コード例 #30
0
ファイル: gvfs-rename.c プロジェクト: gicmo/gvfs
static void
show_help (GOptionContext *context, const char *error)
{
  char *help;

  if (error)
    g_printerr (_("Error: %s"), error);

  help = g_option_context_get_help (context, TRUE, NULL);
  g_printerr ("%s", help);
  g_free (help);
  g_option_context_free (context);
}