예제 #1
0
static void
parse_arguments(int argc, char* argv[], char** command, char** directory, gboolean* keep, char** name, char** title)
{
    gboolean version = FALSE;   // show version?
    const GOptionEntry entries[] = {
        {"version",   'v', 0, G_OPTION_ARG_NONE,    &version,   "Display program version and exit.", 0},
        {"execute",   'e', 0, G_OPTION_ARG_STRING,  command,    "Execute command instead of default shell.", "COMMAND"},
        {"directory", 'd', 0, G_OPTION_ARG_STRING,  directory,  "Sets the working directory for the shell (or the command specified via -e).", "PATH"},
        {"keep",      'k', 0, G_OPTION_ARG_NONE,    keep,       "Don't exit the terminal after child process exits.", 0},
        {"name",      'n', 0, G_OPTION_ARG_STRING,  name,       "Set first value of WM_CLASS property; second value is always 'TinyTerm' (default: 'tinyterm')", "NAME"},
        {"title",     't', 0, G_OPTION_ARG_STRING,  title,      "Set value of WM_NAME property; disables window_title_cb (default: 'TinyTerm')", "TITLE"},
        { NULL }
    };

    GError* error = NULL;
    GOptionContext* context = g_option_context_new(NULL);
    g_option_context_set_help_enabled(context, TRUE);
    g_option_context_add_main_entries(context, entries, NULL);
    g_option_context_parse(context, &argc, &argv, &error);
    g_option_context_free(context);

    if (error) {
        g_printerr("option parsing failed: %s\n", error->message);
        g_error_free(error);
        exit(EXIT_FAILURE);
    }

    if (version) {
        g_print("tinyterm " TINYTERM_VERSION "\n");
        exit(EXIT_SUCCESS);
    }
}
예제 #2
0
파일: media.c 프로젝트: Bredun/libquvi
static gint opts_new(gint argc, gchar **argv)
{
  GOptionContext *c;
  GError *e;
  gint r;

  c = g_option_context_new("URL");
  r = EXIT_SUCCESS;
  e = NULL;

  g_option_context_set_help_enabled(c, TRUE);
  g_option_context_add_main_entries(c, entries, NULL);

  if (g_option_context_parse(c, &argc, &argv, &e) == FALSE)
    {
      g_printerr("error: %s\n", e->message);
      g_error_free(e);
      r = EXIT_FAILURE;
      e = NULL;
    }

  g_option_context_free(c);
  c = NULL;

  /* Check input. */

  if (opts.url == NULL)
    {
      g_printerr("error: no input URL\n");
      return (EXIT_FAILURE);
    }

  return (r);
}
예제 #3
0
int chassis_frontend_init_base_options(GOptionContext *option_ctx,
		int *argc_p, char ***argv_p,
		int *print_version,
		char **config_file,
		GError **gerr) {
	chassis_options_t *opts;
	GOptionEntry *base_main_entries;
	int ret = 0;

	opts = chassis_options_new();
	chassis_options_set_cmdline_only_options(opts, print_version, config_file);
	base_main_entries = chassis_options_to_g_option_entries(opts);

	g_option_context_add_main_entries(option_ctx, base_main_entries, NULL);
	g_option_context_set_help_enabled(option_ctx, FALSE);
	g_option_context_set_ignore_unknown_options(option_ctx, TRUE);

	if (FALSE == g_option_context_parse(option_ctx, argc_p, argv_p, gerr)) {
		ret = -1;
	}

	/* do not use chassis_options_free_g_options... here, we need to hang on to the data until the end of the program! */
	g_free(base_main_entries);
	chassis_options_free(opts);

	return ret;
}
예제 #4
0
static gboolean
parse_params (int *argcp, char ***argvp)
{
	GError *err;
	GOptionContext *context;
	gboolean rv;

	context = g_option_context_new("- mu general options");
	g_option_context_set_main_group(context, config_options_group_mu());
	g_option_context_set_help_enabled (context, TRUE);

	err = NULL;

	/* help is special */
	if (MU_CONFIG.cmd == MU_CONFIG_CMD_HELP) {
		rv = g_option_context_parse (context, argcp, argvp, &err) &&
			init_cmd_help (&err);
	} else {
		GOptionGroup *group;
		group = get_option_group (MU_CONFIG.cmd);
		if (group)
			g_option_context_add_group(context, group);
		rv = g_option_context_parse (context, argcp, argvp, &err);
	}

	g_option_context_free (context);
	if (!rv) {
		g_printerr ("mu: error in options: %s\n",
			    err ? err->message : "?");
		g_clear_error (&err);
		return FALSE;
	}

	return TRUE;
}
예제 #5
0
/**
 * gdict_debug_init:
 * @argc: FIXME
 * @argv: FIXME
 *
 * FIXME
 *
 * Since: 0.12
 */
void
gdict_debug_init (gint    *argc,
                  gchar ***argv)
{
  GOptionContext *option_context;
  GOptionGroup *gdict_group;
  GError *error = NULL;

  if (gdict_is_initialized)
    return;

  option_context = g_option_context_new (NULL);
  g_option_context_set_ignore_unknown_options (option_context, TRUE);
  g_option_context_set_help_enabled (option_context, FALSE); 

  gdict_group = gdict_get_option_group ();
  g_option_context_set_main_group (option_context, gdict_group);

  if (!g_option_context_parse (option_context, argc, argv, &error))
    {
      g_warning ("%s", error->message);
      g_error_free (error);
    }

  g_option_context_free (option_context);
}
예제 #6
0
파일: gdk.c 프로젝트: 3v1n0/gtk
/**
 * gdk_parse_args:
 * @argc: the number of command line arguments.
 * @argv: (inout) (array length=argc): the array of command line arguments.
 * 
 * Parse command line arguments, and store for future
 * use by calls to gdk_display_open().
 *
 * Any arguments used by GDK are removed from the array and @argc and @argv are
 * updated accordingly.
 *
 * You shouldn’t call this function explicitly if you are using
 * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
 *
 * Since: 2.2
 **/
void
gdk_parse_args (int    *argc,
                char ***argv)
{
  GOptionContext *option_context;
  GOptionGroup *option_group;
  GError *error = NULL;

  if (gdk_initialized)
    return;

  gdk_pre_parse ();

  option_context = g_option_context_new (NULL);
  g_option_context_set_ignore_unknown_options (option_context, TRUE);
  g_option_context_set_help_enabled (option_context, FALSE);
  option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
  g_option_context_set_main_group (option_context, option_group);

  g_option_group_add_entries (option_group, gdk_args);

  if (!g_option_context_parse (option_context, argc, argv, &error))
    {
      g_warning ("%s", error->message);
      g_error_free (error);
    }
  g_option_context_free (option_context);

  GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
}
예제 #7
0
static gboolean
parse_options (int *argc, char *argv[])
{
  GOptionContext *ctx;
  gboolean success;
  GError *error = NULL;

  ctx = g_option_context_new (" - encoder test options");
  if (!ctx)
    return FALSE;

  g_option_context_add_group (ctx, gst_init_get_option_group ());
  g_option_context_add_main_entries (ctx, g_options, NULL);
  g_option_context_set_help_enabled (ctx, TRUE);
  success = g_option_context_parse (ctx, argc, &argv, &error);
  if (!success) {
    g_printerr ("Option parsing failed: %s\n", error->message);
    g_error_free (error);
    goto bail;
  }

  if (!g_codec_str)
    g_codec_str = g_strdup ("h264");
  if (!g_output_file_name)
    g_output_file_name = generate_output_filename (g_codec_str);

bail:
  g_option_context_free (ctx);
  return success;
}
예제 #8
0
파일: mu-config.c 프로젝트: Popsch/mu
static gboolean
parse_params (int *argcp, char ***argvp, GError **err)
{
	GOptionContext *context;
	GOptionGroup *group;
	gboolean rv;

	context = g_option_context_new("- mu general options");
	g_option_context_set_help_enabled (context, TRUE);

	err = NULL;
	rv  = TRUE;

	g_option_context_set_main_group(context,
					config_options_group_mu());

	switch (MU_CONFIG.cmd) {
	case MU_CONFIG_CMD_NONE: show_usage(); break;
	case MU_CONFIG_CMD_HELP:
		/* 'help' is special; sucks in the options of the
		 * command after it */
		rv = g_option_context_parse (context, argcp, argvp, err) &&
			cmd_help ();
		break;
	default:
		group = get_option_group (MU_CONFIG.cmd);
		if (group)
			g_option_context_add_group(context, group);
		rv = g_option_context_parse (context, argcp, argvp, err);
	}
	g_option_context_free (context);

	return rv ? TRUE : FALSE;
}
int
main (int argc, char *argv[])
{
	NML2tpPlugin *plugin;
	GMainLoop *main_loop;
	gboolean persist = FALSE;
	GOptionContext *opt_ctx = NULL;

	GOptionEntry options[] = {
		{ "persist", 0, 0, G_OPTION_ARG_NONE, &persist, N_("Don't quit when VPN connection terminates"), NULL },
		{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable verbose debug logging (may expose passwords)"), NULL },
		{NULL}
	};

#if !GLIB_CHECK_VERSION (2, 35, 0)
	g_type_init ();
#endif

	/* locale will be set according to environment LC_* variables */
	setlocale (LC_ALL, "");

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

	/* Parse options */
	opt_ctx = g_option_context_new (NULL);
	g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE);
	g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
	g_option_context_set_help_enabled (opt_ctx, TRUE);
	g_option_context_add_main_entries (opt_ctx, options, NULL);

	g_option_context_set_summary (opt_ctx,
	    _("nm-l2tp-service provides L2TP VPN capability with optional IPSec support to NetworkManager."));

	g_option_context_parse (opt_ctx, &argc, &argv, NULL);
	g_option_context_free (opt_ctx);

	if (getenv ("NM_PPP_DEBUG"))
		debug = TRUE;

	if (debug)
		g_message ("nm-l2tp-service (version " DIST_VERSION ") starting...");

	plugin = nm_l2tp_plugin_new ();
	if (!plugin)
		exit (EXIT_FAILURE);

	main_loop = g_main_loop_new (NULL, FALSE);

	if (!persist)
		g_signal_connect (plugin, "quit", G_CALLBACK (quit_mainloop), main_loop);

	g_main_loop_run (main_loop);

	g_main_loop_unref (main_loop);
	g_object_unref (plugin);

	exit (EXIT_SUCCESS);
}
예제 #10
0
파일: gegl-init.c 프로젝트: Distrotech/gegl
void
gegl_init (gint    *argc,
           gchar ***argv)
{
  GOptionContext *context;
  GError         *error = NULL;
  static gboolean initialized = FALSE;

  if (initialized)
    return;

  initialized = TRUE;

  context = g_option_context_new (NULL);
  g_option_context_set_ignore_unknown_options (context, TRUE);
  g_option_context_set_help_enabled (context, FALSE);
  g_option_context_set_main_group (context, gegl_get_option_group ());

  if (!g_option_context_parse (context, argc, argv, &error))
    {
      g_warning ("%s", error->message);
      g_error_free (error);
    }

  g_option_context_free (context);
}
예제 #11
0
	int main(int argc, char * argv [])
	{
		quiet = FALSE;
		static GOptionEntry entries[] = {
			{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "show only whether the dictionary is OK or broken", NULL },
			{ NULL },
		};
		glib::OptionContext opt_cnt(g_option_context_new("[FILE | DIRECTORY]..."));
		g_option_context_add_main_entries(get_impl(opt_cnt), entries, NULL);
		g_option_context_set_help_enabled(get_impl(opt_cnt), TRUE);
		g_option_context_set_summary(get_impl(opt_cnt),
				"Verifies StarDict dictionary files.\n"
				"\n"
				"You may specify files and directories in the command line.\n"
				"Files should reference the particular dictionary to check, they must have .ifo extension.\n"
				"Directories are processed recursively, all encountered dictionary files will be verified.\n"
				"If you omit command line arguments, the utility will process known dictionary directories. "
				"That is directories where StarDict search for dictionaries by default.\n"
				"\n"
				"EXIT STATUS\n"
				"The utility exits with status 0 if all processed dictionaries are valid. "
				"If at least one dictionary is broken, the status will be non-zero.\n"
			);
		glib::Error err;
		if (!g_option_context_parse(get_impl(opt_cnt), &argc, &argv, get_addr(err))) {
			std::cerr << "Option parsing failed: " <<  err->message << std::endl;
			return EXIT_FAILURE;
		}
		files = argv+1;
		file_cnt = argc-1;
		return EXIT_SUCCESS;
	}
예제 #12
0
int
handle_tree (int argc, char *argv[], gboolean do_help)
{
  GOptionContext *context;
  GError *error = NULL;
  GFile *file;
  gchar *param;
  int i;

  g_set_prgname ("gio tree");

  /* 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,
      _("List contents of directories in a tree-like format."));
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);

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

  g_option_context_parse (context, &argc, &argv, &error);

  if (error != NULL)
    {
      show_help (context, error->message);
      g_error_free (error);
      return 1;
    }

  g_option_context_free (context);

  if (argc > 1)
    {
      for (i = 1; i < argc; i++)
        {
          file = g_file_new_for_commandline_arg (argv[i]);
          tree (file);
          g_object_unref (file);
        }
    }
  else
    {
      char *cwd;

      cwd = g_get_current_dir ();
      file = g_file_new_for_path (cwd);
      g_free (cwd);
      tree (file);
      g_object_unref (file);
    }

  return 0;
}
예제 #13
0
void tg_option_tests()
{

	GOptionContext *context;
	GOptionContext *context1;//for testing set main group
	GOptionContext *context2;//for testing add group
	gboolean retval;
	GError *error = NULL;
	gchar **argv;
	int argc;
	gchar **argv1;
	int argc1;
	GOptionEntry entries [] =
	    { { "test", 0, 0, G_OPTION_ARG_INT, &arg_test1_int, "test_description", "test_arg" },
	      { NULL } };
	GOptionEntry entries1 [] =
	    { { "try", 0, 0, G_OPTION_ARG_INT, &arg_test1_int, "try_description", "try_arg" },
	      { NULL } };
	GOptionEntry entries2 [] =
	    { { "again", 0, 0, G_OPTION_ARG_INT, &arg_test1_int, "again_description", "again_arg" },
	      { NULL } };
	
	GOptionGroup *main_group;
		
	context = g_option_context_new (NULL);
	context1 = g_option_context_new (NULL);
	context2 = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, entries, NULL);
	g_option_context_add_main_entries (context2, entries, NULL);
  	
  	main_group = g_option_context_get_main_group (context);
  	//Testing g_option_context_set_main_group with another context-context1
	g_option_group_add_entries (main_group,entries1);
	g_option_context_set_main_group(context1,main_group);

	//Testing g_option_context_set_help_enabled 
	//and g_option_context_get_help_enabled
	//and g_option_context_get_ignore_unknown_options
	g_option_context_set_help_enabled(context,TRUE);
	g_assert(g_option_context_get_help_enabled(context));
	g_assert(!g_option_context_get_ignore_unknown_options(context));
	
	/* Now try parsing on context1*/
	argv = split_string ("program --try 20 --try 30", &argc);
	  
	retval = g_option_context_parse (context1, &argc, &argv, &error);
	g_assert (retval);

	/* Last arg specified is the one that should be stored */
	g_assert (arg_test1_int == 30);

	g_option_group_set_error_hook (main_group, error_func);
	argv = split_string ("program --none 20 --none 30", &argc);
	retval = g_option_context_parse (context1, &argc, &argv, &error);
		
	g_strfreev (argv);
	g_option_context_free (context);
	  
}
예제 #14
0
void setKickstartHD(struct loaderData_s * loaderData, int argc,
                     char ** argv) {
    char *p;
    gchar *biospart = NULL, *partition = NULL, *dir = NULL;
    GOptionContext *optCon = g_option_context_new(NULL);
    GError *optErr = NULL;
    GOptionEntry ksHDOptions[] = {
        { "biospart", 0, 0, G_OPTION_ARG_STRING, &biospart, NULL, NULL },
        { "partition", 0, 0, G_OPTION_ARG_STRING, &partition, NULL, NULL },
        { "dir", 0, 0, G_OPTION_ARG_STRING, &dir, NULL, NULL },
        { NULL },
    };

    logMessage(INFO, "kickstartFromHD");

    g_option_context_set_help_enabled(optCon, FALSE);
    g_option_context_add_main_entries(optCon, ksHDOptions, NULL);

    if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
        startNewt();
        newtWinMessage(_("Kickstart Error"), _("OK"),
                       _("Bad argument to HD kickstart method "
                         "command: %s"), optErr->message);
        g_error_free(optErr);
        g_option_context_free(optCon);
        return;
    }

    g_option_context_free(optCon);

    if (biospart) {
        char * dev;

        p = strchr(biospart,'p');
        if(!p){
            logMessage(ERROR, "Bad argument for --biospart");
            return;
        }
        *p = '\0';
        dev = getBiosDisk(biospart);
        if (dev == NULL) {
            logMessage(ERROR, "Unable to location BIOS partition %s", biospart);
            return;
        }
        partition = malloc(strlen(dev) + strlen(p + 1) + 2);
        sprintf(partition, "%s%s", dev, p + 1);
    }

    loaderData->method = METHOD_HD;
    loaderData->stage2Data = calloc(sizeof(struct hdInstallData *), 1);
    if (partition)
        ((struct hdInstallData *)loaderData->stage2Data)->partition = partition;
    if (dir)
        ((struct hdInstallData *)loaderData->stage2Data)->directory = dir;

    logMessage(INFO, "results of hd ks, partition is %s, dir is %s", partition,
               dir);
}
예제 #15
0
/* nbd-ops -p pid -f fsname -c command */
int main(int argc, char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;
    context = g_option_context_new("- tapdisk ops...");
    g_option_context_add_main_entries(context, entries, NULL);
    g_option_context_set_help_enabled(context, TRUE);
    g_option_group_set_error_hook(g_option_context_get_main_group(context),
            					(GOptionErrorFunc)error_func);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_message("option parsing failed: %s\n", error->message);
        exit(EXIT_FAILURE);
    }

    g_message("fsname:      %s\n", fsname);
    g_message("cmd:        %s\n", cmd);
    g_message("param1: %d\n" ,param1);
    g_option_context_free(context);
    char ctrl_region_file[128];
    sprintf(ctrl_region_file,"%s%s%s","/tmp/",fsname,"-ctrl");
    int fd = open(ctrl_region_file,O_RDWR);
    if(fd == -1){
        return -1;
    }
//    int offset = sysconf(_SC_PAGE_SIZE);
    char *addr = mmap(NULL,sizeof(CTRL_REGION_T), PROT_WRITE, MAP_SHARED, fd, 0);
    if (addr == MAP_FAILED) {
	    g_message("%s -- mmap failed\n", __func__);
	    exit(EXIT_FAILURE);
    }
    g_assert(addr !=NULL);
    CTRL_REGION_T *ctrl_region;      
    ctrl_region = (CTRL_REGION_T*)addr;
    gint *_is_start_clean  = &ctrl_region->is_start_clean;
    gint *_copy_waterlevel = &ctrl_region->copy_waterlevel;
    if(0 == strncmp(cmd,"start_merge",strlen("start_merge"))){
        g_message("cmd is srart merge : %s",cmd);
        g_atomic_int_set(_is_start_clean,1);
    }else if(0 == strncmp(cmd,"stop_merge",strlen("stop_merge"))){
        g_message("cmd is stop merge  : %s",cmd);
        g_atomic_int_set(_is_start_clean,0);
    }else if (0 == strncmp(cmd, "set_copy_waterlevel", strlen("set_copy_waterlevel"))){
        g_message("cmd is set copy waterlevel: %s", cmd);
        g_atomic_int_set(_copy_waterlevel,param1);
    }else if (0 == strncmp(cmd, "query_stat", strlen("query_stat"))){
        g_message("cmd is query_stat: %s", cmd);
        g_message("is_start_clean:%d", ctrl_region->is_start_clean);
        g_message("copy_waterlevel:%d",ctrl_region->copy_waterlevel);
    }else{
        g_assert(0);
    }
    return 0;
}
예제 #16
0
void loadKickstartModule(struct loaderData_s * loaderData,
                         int argc, char **argv) {
    gchar *opts = NULL;
    gchar *module = NULL;
    gchar **args = NULL, **remaining = NULL;
    gboolean rc;
    GOptionContext *optCon = g_option_context_new(NULL);
    GError *optErr = NULL;
    GOptionEntry ksDeviceOptions[] = {
        { "opts", 0, 0, G_OPTION_ARG_STRING, &opts, NULL, NULL },
        {   G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
            NULL, NULL
        },
        { NULL },
    };

    g_option_context_set_help_enabled(optCon, FALSE);
    g_option_context_add_main_entries(optCon, ksDeviceOptions, NULL);

    if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
        startNewt();
        newtWinMessage(_("Kickstart Error"), _("OK"),
                       _("Bad argument to device kickstart method "
                         "command: %s"), optErr->message);
        g_error_free(optErr);
        g_option_context_free(optCon);
        return;
    }

    g_option_context_free(optCon);

    if ((remaining != NULL) && (g_strv_length(remaining) == 1)) {
        module = remaining[0];
    }

    if (!module) {
        startNewt();
        newtWinMessage(_("Kickstart Error"), _("OK"),
                       _("A module name must be specified for "
                         "the kickstart device command."));
        return;
    }

    if (opts) {
        args = g_strsplit(opts, " ", 0);
    }

    rc = mlLoadModule(module, args);
    g_strfreev(args);
    return;
}
예제 #17
0
/* Parse the argv array with GOptionContext, using the given argument
 * definitions, and return a command context structure containing
 * argument values.
 * Note: The lib doesn't like argv starting with a flag, so keep a
 * token before that to avoid problems.
 */
static command_context_t *
init_context_from_args (argument_t *argdefs, gint argc, gchar **argv)
{
	/* FIXME: look at the error! */
	command_context_t *ctx;
	GOptionContext *context;
	GError *error = NULL;
	gint i;

	ctx = command_context_init (argc, argv);

	for (i = 0; argdefs && argdefs[i].long_name; ++i) {
		command_argument_t *arg = g_new (command_argument_t, 1);

		switch (argdefs[i].arg) {
		case G_OPTION_ARG_NONE:
			arg->type = COMMAND_ARGUMENT_TYPE_BOOLEAN;
			arg->value.vbool = FALSE;
			argdefs[i].arg_data = &arg->value.vbool;
			break;

		case G_OPTION_ARG_INT:
			arg->type = COMMAND_ARGUMENT_TYPE_INT;
			arg->value.vint = -1;
			argdefs[i].arg_data = &arg->value.vint;
			break;

		case G_OPTION_ARG_STRING:
			arg->type = COMMAND_ARGUMENT_TYPE_STRING;
			arg->value.vstring = NULL;
			argdefs[i].arg_data = &arg->value.vstring;
			break;

		default:
			g_printf (_("Trying to register a flag '%s' of invalid type!"),
			          argdefs[i].long_name);
			break;
		}

		g_hash_table_insert (ctx->flags,
		                     g_strdup (argdefs[i].long_name), arg);
	}

	context = g_option_context_new (NULL);
	g_option_context_set_help_enabled (context, FALSE);  /* runs exit(0)! */
	g_option_context_add_main_entries (context, argdefs, NULL);
	g_option_context_parse (context, &ctx->argc, &ctx->argv, &error);
	g_option_context_free (context);

	return ctx;
}
예제 #18
0
파일: mu-config.c 프로젝트: Vykhod/mu
static gboolean
parse_params (int *argcp, char ***argvp, GError **err)
{
	GOptionContext *context;
	GOptionGroup *group;
	gboolean rv;

	context = g_option_context_new("- mu general options");

	g_option_context_set_help_enabled (context, TRUE);
	rv  = TRUE;

	g_option_context_set_main_group(context,
					config_options_group_mu());
	g_option_context_set_ignore_unknown_options (context, FALSE);

	switch (MU_CONFIG.cmd) {
	case MU_CONFIG_CMD_NONE:
		show_usage();
		break;
	case MU_CONFIG_CMD_HELP:
		/* 'help' is special; sucks in the options of the
		 * command after it */
		rv = g_option_context_parse (context, argcp, argvp, err) &&
			cmd_help ();
		break;
	case MU_CONFIG_CMD_SCRIPT:
		/* all unknown commands are passed to 'script' */
		g_option_context_set_ignore_unknown_options (context, TRUE);
		group = get_option_group (MU_CONFIG.cmd);
		g_option_context_add_group (context, group);
		rv  = g_option_context_parse (context, argcp, argvp, err);
		MU_CONFIG.script = g_strdup (MU_CONFIG.cmdstr);
		/* argvp contains the script parameters */
		MU_CONFIG.script_params = (const char**)&((*argvp)[1]);
		break;

	default:
		group = get_option_group (MU_CONFIG.cmd);
		if (group)
			g_option_context_add_group (context, group);

		rv = g_option_context_parse (context, argcp, argvp, err);
		break;
	}

	g_option_context_free (context);

	return rv ? TRUE : FALSE;
}
예제 #19
0
int main(int argc, char **argv)
{
  int valor;
  guint timer = 1000;

#if OPCIONES_LINEA
  const GOptionEntry entries[] = {
    { "timer", 't', 0, G_OPTION_ARG_INT, &timer, "Establece el intervalo del temporizador generador de ciclos, en milisegundos", "T" },
    { NULL }
  };  
  GOptionContext* contexto = g_option_context_new (" <pipeline> - ejecuta un pipeline definido en un XML válido");
  g_option_context_add_main_entries (contexto, entries, 0);
  g_option_context_add_group (contexto, gtk_get_option_group (TRUE));
  g_option_context_parse (contexto, &argc, &argv, 0);
  g_option_context_set_help_enabled (contexto, TRUE);
#endif

  if (argc < 2) {
    printf("Faltan argumentos. Uso: %s <pipeline>.\n", argv[0]);
    return -1;
  }  
  else {
    gtk_init(&argc, &argv);
    glade_init();
    xml = glade_xml_new("ventana_pipeline.glade", NULL, NULL);
    glade_xml_signal_autoconnect(xml);
    pipeline_t * p = pipeline_cargar(argv[1], g_get_current_dir(), funcion_error);
    if(p) {
      g_timeout_add(timer, tick, p);
      pipeline_iniciar(p);	
      gtk_main();
      pipeline_borrar(p);
      valor = 0;
    }
    else {
      valor = -1;
    }
  }

#if OPCIONES_LINEA
  g_option_context_free(contexto);
#endif 

  return valor;
}
예제 #20
0
파일: hlfs_rmfs.c 프로젝트: Aruiwen/cloudxy
/*  mkfs_rmfs -u uri */
int main(int argc, char *argv[])
{
//	if (log4c_init()) {
//		g_message("log4c_init failed!");
//	}
	GError *error = NULL;
	GOptionContext *context;
	context = g_option_context_new("-hlfs rmfs");
	g_option_context_add_main_entries(context, entries, NULL);
	g_option_context_set_help_enabled(context, TRUE);
	g_option_group_set_error_hook(g_option_context_get_main_group(context),
			(GOptionErrorFunc)error_func);
	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_message("option parsing failed: %s", error->message);
		exit(EXIT_FAILURE);
	}

	g_print("fs uri is :%s\n", uri);
	int ret = 0;
		
	struct back_storage *storage = init_storage_handler(uri);
	if (NULL == storage) {
		g_message("can not get storage handler for uri:%s", uri);
		ret = -1;
		goto out;
	}
    if (0 != hlfs_rmfs(storage)){
    	g_printf("Can not remove fs!\n");
    	ret = -1;
		goto out1;
    }

out1:
	deinit_storage_handler(storage);
out:
	g_free(uri);
	g_option_context_free(context);
//	if (log4c_fini()) {
//		g_message("log4c_fini failed!");
//	}
	return 0;
}
예제 #21
0
	int ParseCommandLine(int argc, char * argv [])
	{
		quiet_mode = FALSE;
		key_only = FALSE;
		static GOptionEntry entries[] = {
			{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet_mode, "no additional information, only index entries", NULL },
			{ "key-only", 'k', 0, G_OPTION_ARG_NONE, &key_only, "print only keys (implies --quiet option)", NULL },
			{ NULL },
		};
		glib::OptionContext opt_cnt(g_option_context_new("INDEX_FILE"));
		g_option_context_add_main_entries(get_impl(opt_cnt), entries, NULL);
		g_option_context_set_help_enabled(get_impl(opt_cnt), TRUE);
		g_option_context_set_summary(get_impl(opt_cnt),
			"Print context of StarDict index file in human readable form.\n"
			"\n"
			"Supported files: .idx, .ridx, .syn\n"
			);
		glib::Error err;
		if (!g_option_context_parse(get_impl(opt_cnt), &argc, &argv, get_addr(err))) {
			std::cerr << "Option parsing failed: " <<  err->message << std::endl;
			return EXIT_FAILURE;
		}
		if(argc == 1) {
			std::cerr << "Index file is not specified." << std::endl;
			return EXIT_FAILURE;
		}
		if(argc > 2) {
			std::cerr << "warning: only the first file will be processed." <<std::endl;
		}
		idx_file_name = argv[1];
		if(!g_str_has_suffix(idx_file_name.c_str(), ".idx")
				&& !g_str_has_suffix(idx_file_name.c_str(), ".syn")
				&& !g_str_has_suffix(idx_file_name.c_str(), ".ridx")) {
			std::cerr << "Unsupported index type." << std::endl;
			return EXIT_FAILURE;
		}
		syn_file = g_str_has_suffix(idx_file_name.c_str(), ".syn");
		if(key_only)
			quiet_mode = TRUE;
		return EXIT_SUCCESS;
	}
예제 #22
0
void air_option_context_set_help_enabled(
    AirOptionCtx *aoctx)
{
    g_assert(aoctx != NULL);
    g_assert(aoctx->octx != NULL);
#if USE_GOPTION
    g_option_context_set_help_enabled(aoctx->octx, TRUE);
#elif USE_POPT
    {
        struct poptOption poption;

        poption.longName   = NULL;
        poption.shortName  = '\0';
        poption.argInfo    = POPT_ARG_INCLUDE_TABLE;
        poption.arg        = poptHelpOptions;
        poption.val        = 0;
        poption.descrip    =  "Help options:";
        poption.argDescrip = NULL;
        g_array_append_val(aoctx->options,  poption);
    }
#endif
}
예제 #23
0
/**
 * gst_init_check:
 * @argc: (inout) (allow-none): pointer to application's argc
 * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
 * @err: pointer to a #GError to which a message will be posted on error
 *
 * Initializes the GStreamer library, setting up internal path lists,
 * registering built-in elements, and loading standard plugins.
 *
 * This function will return %FALSE if GStreamer could not be initialized
 * for some reason.  If you want your program to fail fatally,
 * use gst_init() instead.
 *
 * Returns: %TRUE if GStreamer could be initialized.
 */
gboolean
gst_init_check (int *argc, char **argv[], GError ** err)
{
  static GMutex init_lock;
#ifndef GST_DISABLE_OPTION_PARSING
  GOptionGroup *group;
  GOptionContext *ctx;
#endif
  gboolean res;

  g_mutex_lock (&init_lock);

  if (gst_initialized) {
    GST_DEBUG ("already initialized gst");
    g_mutex_unlock (&init_lock);
    return TRUE;
  }
#ifndef GST_DISABLE_OPTION_PARSING
  ctx = g_option_context_new ("- GStreamer initialization");
  g_option_context_set_ignore_unknown_options (ctx, TRUE);
  g_option_context_set_help_enabled (ctx, FALSE);
  group = gst_init_get_option_group ();
  g_option_context_add_group (ctx, group);
  res = g_option_context_parse (ctx, argc, argv, err);
  g_option_context_free (ctx);
#else
  init_pre (NULL, NULL, NULL, NULL);
  init_post (NULL, NULL, NULL, NULL);
  res = TRUE;
#endif

  gst_initialized = res;

  g_mutex_unlock (&init_lock);

  return res;
}
예제 #24
0
파일: kickstart.c 프로젝트: bsanders/stacki
static void setShutdown(struct loaderData_s * loaderData, int argc, 
                    char ** argv) {
    gint eject = 0, reboot = 0, halt = 0, poweroff = 0;
    GOptionContext *optCon = g_option_context_new(NULL);
    GError *optErr = NULL;
    GOptionEntry ksOptions[] = {
        { "eject", 'e', 0, G_OPTION_ARG_INT, &eject, NULL, NULL },
        { "reboot", 'r', 0, G_OPTION_ARG_INT, &reboot, NULL, NULL },
        { "halt", 'h', 0, G_OPTION_ARG_INT, &halt, NULL, NULL },
        { "poweroff", 'p', 0, G_OPTION_ARG_INT, &poweroff, NULL, NULL },
        { NULL },
    };

    g_option_context_set_help_enabled(optCon, FALSE);
    g_option_context_add_main_entries(optCon, ksOptions, NULL);

    if (!g_option_context_parse(optCon, &argc, &argv, &optErr)) {
        startNewt();
        newtWinMessage(_("Kickstart Error"), _("OK"),
                       _("Bad argument to shutdown kickstart method "
                         "command: %s"), optErr->message);
        g_error_free(optErr);
        g_option_context_free(optCon);
        return;
    }

    g_option_context_free(optCon);

    if (FL_NOKILL(flags)) {
        flags |= LOADER_FLAGS_HALT;
    } else  {
        if (poweroff)
            flags |= LOADER_FLAGS_POWEROFF;
        if ((!poweroff && !reboot) || (halt))
            flags |= LOADER_FLAGS_HALT;
    }
}
예제 #25
0
static void
ParseOptions(int *argc,                           // IN/OUT
             char ***argv)                        // IN/OUT
{
   GError *error = NULL;
   GOptionContext *context;

   context = g_option_context_new(NULL);
   g_option_context_add_main_entries(context, cmdOptions, NULL);
   /*
    * Turn off glib option parser help message in order to provide the
    * complete help messages compatible to those from the original perl
    * implementation script.
    */
   g_option_context_set_help_enabled(context, FALSE);

   if (!g_option_context_parse(context, argc, argv, &error)) {
      printf("Option parsing failed: %s\n", error->message);
      PrintUsage(g_get_prgname());
      exit(1);
   }

   g_option_context_free(context);
}
예제 #26
0
/**
 * gegl_init:
 * @argc: a pointer to the number of command line arguments.
 * @argv: a pointer to the array of command line arguments.
 *
 * Call this function before using any other GEGL functions. It will initialize
 * everything needed to operate GEGL and parses some standard command line
 * options.  @argc and @argv are adjusted accordingly so your own code will
 * never see those standard arguments.
 *
 * Note that there is an alternative ways to initialize GEGL: if you are
 * calling g_option_context_parse() with the option group returned by
 * gegl_get_option_group(), you don't have to call gegl_init().
 **/
void
gegl_init (gint    *argc,
           gchar ***argv)
{
  GOptionContext *context;
  GError         *error = NULL;
  if (config)
    return;

  /*  If any command-line actions are ever added to GEGL, then the commented
   *  out code below should be used.  Until then, we simply call the parse hook
   *  directly.
   */
#if 0
  gegl_post_parse_hook (NULL, NULL, NULL, NULL);
#else

  context = g_option_context_new (NULL);
  g_option_context_set_ignore_unknown_options (context, TRUE);
  g_option_context_set_help_enabled (context, FALSE);
  g_option_context_set_main_group (context, gegl_get_option_group ());

  if (!g_option_context_parse (context, argc, argv, &error))
    {
      g_warning ("%s", error->message);
      g_error_free (error);
    }

  g_option_context_free (context);
#endif

  /* Not the best place for this ... better to put it in post_parse and just
   * save argv[0] here.
   */
  vips_init (*argv[0]);
}
예제 #27
0
파일: xpad-app.c 프로젝트: abhinandh/xpad
static gboolean
process_remote_args (gint *argc, gchar **argv[], gboolean have_gtk)
{
	GError *error = NULL;
	GOptionContext *context;
	
	option_new = FALSE;
	option_files = NULL;
	option_quit = FALSE;
	option_smid = NULL;
	option_hide = FALSE;
	option_show = FALSE;
	option_toggle = FALSE;
	
	context = g_option_context_new (NULL);
	g_option_context_set_ignore_unknown_options (context, TRUE);
	g_option_context_set_help_enabled (context, FALSE);
	g_option_context_add_main_entries (context, remote_options, GETTEXT_PACKAGE);
	if (g_option_context_parse (context, argc, argv, &error))
	{
		if (have_gtk && option_smid)
			xpad_session_manager_set_id (option_smid);
		
		if (have_gtk && option_new)
		{
			GtkWidget *pad = xpad_pad_new (pad_group);
			gtk_widget_show (pad);
		}

		if (have_gtk && option_show)
		  xpad_pad_group_show_all (pad_group);
		
		if (have_gtk && option_hide)
		  xpad_pad_group_close_all (pad_group);
		
		if (have_gtk && option_toggle)
		  xpad_pad_group_toggle_hide (pad_group);

		if (have_gtk && option_files)
		{
			int i;
			for (i = 0; option_files[i]; i++)
			{
				GtkWidget *pad = xpad_pad_new_from_file (pad_group, option_files[i]);
				if (pad)
					gtk_widget_show (pad);
			}
		}
		
		if (option_quit)
		{
			if (have_gtk && gtk_main_level () > 0)
				gtk_main_quit ();
			else
				exit (0);
		}
	}
	else
	{
		fprintf (output, "%s\n", error->message);
		/* Don't quit.  Bad options passed to the main xpad program by other
		   iterations shouldn't close the main one. */
	}
	
	g_option_context_free (context);
	
	return(option_new || option_quit || option_smid || option_files ||
	       option_hide || option_show || option_toggle);
}
예제 #28
0
/* main */
int
main (int argc, char *argv[])
{
  GOptionContext *context;
  gboolean window_arg = FALSE;
  gboolean area_arg = FALSE;
  gboolean include_border_arg = FALSE;
  gboolean disable_border_arg = FALSE;
  gboolean interactive_arg = FALSE;
  gchar *border_effect_arg = NULL;
  guint delay_arg = 0;
  GError *error = NULL;

  const GOptionEntry entries[] = {
    { "window", 'w', 0, G_OPTION_ARG_NONE, &window_arg, N_("Grab a window instead of the entire screen"), NULL },
    { "area", 'a', 0, G_OPTION_ARG_NONE, &area_arg, N_("Grab an area of the screen instead of the entire screen"), NULL },
    { "include-border", 'b', 0, G_OPTION_ARG_NONE, &include_border_arg, N_("Include the window border with the screenshot"), NULL },
    { "remove-border", 'B', 0, G_OPTION_ARG_NONE, &disable_border_arg, N_("Remove the window border from the screenshot"), NULL },
    { "delay", 'd', 0, G_OPTION_ARG_INT, &delay_arg, N_("Take screenshot after specified delay [in seconds]"), N_("seconds") },
    { "border-effect", 'e', 0, G_OPTION_ARG_STRING, &border_effect_arg, N_("Effect to add to the border (shadow, border or none)"), N_("effect") },
    { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive_arg, N_("Interactively set options"), NULL },
    { NULL },
  };

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

  context = g_option_context_new (_("Take a picture of the screen"));
  g_option_context_set_ignore_unknown_options (context, FALSE);
  g_option_context_set_help_enabled (context, TRUE);
  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, &error);

  if (error) {
    g_critical ("Unable to parse arguments: %s", error->message);
    g_error_free (error);
    g_option_context_free (context);
    exit (1);
  }

  g_option_context_free (context);

  if (window_arg && area_arg) {
    g_printerr (_("Conflicting options: --window and --area should not be "
                  "used at the same time.\n"));
    exit (1);
  }

  gtk_window_set_default_icon_name (SCREENSHOOTER_ICON);
  screenshooter_init_stock_icons ();

  settings = g_settings_new (MATE_SCREENSHOT_SCHEMA);
  load_options ();
  /* allow the command line to override options */
  if (window_arg)
    take_window_shot = TRUE;

  if (area_arg)
    take_area_shot = TRUE;

  if (include_border_arg)
    include_border = TRUE;

  if (disable_border_arg)
    include_border = FALSE;

  if (border_effect_arg)
    {
      g_free (border_effect);
      border_effect = border_effect_arg;
    }

  if (delay_arg > 0)
    delay = delay_arg;

  /* interactive mode overrides everything */
  if (interactive_arg)
    {
      GtkWidget *dialog;
      gint response;

      dialog = create_interactive_dialog ();
      response = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);

      switch (response)
        {
        case GTK_RESPONSE_DELETE_EVENT:
        case GTK_RESPONSE_CANCEL:
          return EXIT_SUCCESS;
        case GTK_RESPONSE_OK:
          break;
        default:
          g_assert_not_reached ();
          break;
        }
    }

  if (((delay > 0 && interactive_arg) || delay_arg > 0) &&
      !take_area_shot)
    {      
      g_timeout_add (delay * 1000,
		     prepare_screenshot_timeout,
		     NULL);
    }
  else
    {
      if (interactive_arg)
        {
          /* HACK: give time to the dialog to actually disappear.
           * We don't have any way to tell when the compositor has finished 
           * re-drawing.
           */
          g_timeout_add (200,
                         prepare_screenshot_timeout, NULL);
        }
      else
        g_idle_add (prepare_screenshot_timeout, NULL);
    }

  gtk_main ();

  return EXIT_SUCCESS;
}
예제 #29
0
int
handle_mkdir (int argc, char *argv[], gboolean do_help)
{
    GOptionContext *context;
    gchar *param;
    GError *error = NULL;
    GFile *file;
    int retval = 0;
    int i;

    g_set_prgname ("gio mkdir");

    /* 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, _("Create directories."));
    g_option_context_set_description (context,
                                      _("gio mkdir is similar to the traditional mkdir utility, but using GIO\n"
                                        "locations instead of local files: for example, you can use something\n"
                                        "like smb://server/resource/mydir as location."));
    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;
    }

    if (argc < 2)
    {
        show_help (context, _("No locations gives"));
        return 1;
    }

    g_option_context_free (context);

    for (i = 1; i < argc; i++)
    {
        file = g_file_new_for_commandline_arg (argv[i]);
        error = NULL;
        if (parent)
        {
            if (!g_file_make_directory_with_parents (file, NULL, &error))
            {
                print_file_error (file, error->message);
                g_error_free (error);
                retval = 1;
            }
        }
        else
        {
            if (!g_file_make_directory (file, NULL, &error))
            {
                print_file_error (file, error->message);
                g_error_free (error);
                retval = 1;
            }
            g_object_unref (file);
        }
    }

    return retval;

}
예제 #30
0
int main(int argc,	char *argv[])
{
	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	setlocale(LC_ALL, "");

	char* domain = textdomain(PACKAGE_NAME);
	assert(domain != NULL);

	bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
	textdomain(PACKAGE_NAME);

	gint update_rate	= 100;
	gint cell_size		= 4;
	gboolean print_version = FALSE;

	GOptionEntry cmd_options[]	= {
									{"update-rate",	'u',	0,	G_OPTION_ARG_INT,	&update_rate,	_C("Update rate in msec"),	"100"},
									{"cell_size",	'c',	0,	G_OPTION_ARG_INT,	&cell_size,		_C("Cell size"),			"8"},
									{"version",		'v',	0,	G_OPTION_ARG_NONE, 	&print_version,	_C("Print version"),		NULL},
									{NULL}
								};


	GError *error				= NULL;

	GOptionContext *cmd_context	= g_option_context_new(NULL);
	g_option_context_set_help_enabled(cmd_context, TRUE);
	g_option_context_add_main_entries(cmd_context, cmd_options, NULL);


	gchar **cmd_line = g_strdupv(argv);
	gint cmd_count = argc;

	if(g_option_context_parse(cmd_context, &cmd_count, &cmd_line, &error) == FALSE)
	{
		fprintf(stderr, _C("ERROR: %s\n\n"), error->message);

		g_error_free(error);
	}
	else
	{
		if(print_version == TRUE)
		{
			printf("game-life: %s\n", PACKAGE_VERSION);
		}
		else
		{
			gtk_init(&argc, &argv);

			GdkScreen* default_screen	= gdk_screen_get_default();
			gint screen_height			= gdk_screen_get_height(default_screen);
			gint screen_width			= gdk_screen_get_width(default_screen);

			size_t world_height			= screen_height / (cell_size +1);
			size_t world_width			= screen_width / (cell_size +1);

			game_universe_t* universe = NULL;

			game_init_universe(&universe, world_width,  world_height, cell_size);
			game_set_random(universe);

			GtkWidget* main_wnd	= gtk_window_new(GTK_WINDOW_TOPLEVEL);
			GdkWindow* root_wnd	= gdk_screen_get_root_window(default_screen);
			gtk_widget_set_window(main_wnd, root_wnd);
			//gtk_window_fullscreen(GTK_WINDOW(main_wnd));
			gtk_widget_set_app_paintable(main_wnd, TRUE);

			g_signal_connect(main_wnd, "destroy", G_CALLBACK(gtk_main_quit),  NULL);
			g_signal_connect(main_wnd, "event", G_CALLBACK(event_cb),  NULL);
			g_signal_connect(main_wnd, "draw", G_CALLBACK(draw_cb),  universe);


			const char* remote_wnd_env = getenv("XSCREENSAVER_WINDOW");
			if(remote_wnd_env != NULL)	// FIXME what is this shit? i dont know
			{
				char* end = NULL;
				Window remote_wnd			= (Window)strtol(remote_wnd_env, &end, 0);
				GdkDisplay* default_display	= gdk_display_get_default();
				GdkWindow* window			= gdk_x11_window_foreign_new_for_display(default_display, remote_wnd);

				//GtkStyle* main_wnd_style	= gtk_widget_get_style(main_wnd);
				//gtk_style_set_background(main_wnd_style, window, GTK_STATE_NORMAL);

				gtk_widget_set_window(main_wnd, window);
				gtk_widget_set_realized(main_wnd, TRUE);

				gtk_window_resize(GTK_WINDOW(main_wnd), screen_width, screen_height);
			}


			gtk_widget_show_all(main_wnd);

			g_timeout_add(update_rate, update_image, main_wnd);

			gtk_main();
		}
	}

	g_option_context_free(cmd_context);

	g_strfreev(cmd_line);

	return 0;
}