int main(int argc, char *argv[]) { char packet[] = {0x00, 0x00, 0x00}; float temp, hum; int error_count = 0; int count = 1; GError *error = NULL; GOptionContext *context; context = g_option_context_new ("- collect temperature and humidity readings"); 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); } g_option_context_free(context); set_debug(debug); hid_device *handle; gboolean found = search_for_device(); if(!found) { g_printerr("Sensor not found, aborting.\n"); exit(-1); } // Open the device using the VID and PID handle = open_lascar(); if(handle == NULL) { g_printerr("Error opening sensor.\n"); exit(-1); } SoupSession *session = NULL; int channel; gchar *channel_name; gchar *room; GString *uri, *body; /* parse config file */ GKeyFile *gkf = g_key_file_new(); g_key_file_load_from_data_dirs(gkf,"templogger.conf",NULL,G_KEY_FILE_NONE,&error); if(error!=NULL) { g_printerr("Can't load configuration file, not uploading to server.\n"); g_key_file_free(gkf); } else { gchar *url = g_key_file_get_string(gkf,"influx","url",NULL); channel = g_key_file_get_integer(gkf,"channel","channel_num",NULL); channel_name = g_key_file_get_string(gkf,"channel","channel_name",NULL); room = g_key_file_get_string(gkf,"channel","room",NULL); int port = g_key_file_get_integer(gkf,"influx","port",NULL); gchar *db = g_key_file_get_string(gkf,"influx","database",NULL); gchar *username = g_key_file_get_string(gkf,"influx","username",NULL); gchar *password = g_key_file_get_string(gkf,"influx","password",NULL); g_key_file_free(gkf); /* open session */ session = soup_session_new(); uri = g_string_new("http://"); g_string_append_printf(uri,"%s:%d/write?db=%s&u=%s&p=%s",url,port,db,username,password); g_message(uri->str); body = g_string_new(""); g_print("Uploading as channel %d, name %s, room %s",channel, channel_name, room); } FILE *logfile = NULL; if(log_local) { logfile = fopen("log.txt","a"); } const int upload_freq = floor(UPLOAD_TIME/SLEEP_TIME); while(1) { int ret = get_reading(handle, packet, &temp, &hum, TRUE); if(ret >= 0) { gint64 t = 1000*g_get_real_time(); if(log_local) { fprintf(logfile,"%" G_GINT64_FORMAT "\t%.1f\t%.1f\n",t, temp, hum); fflush(logfile); } if(debug) g_print("%" G_GINT64_FORMAT "\t%.1f\t%.1f\n",t, temp, hum); if(session && (count % upload_freq == 0)) { SoupRequestHTTP *request = soup_session_request_http(session,"POST",uri->str,NULL); SoupMessage *message = soup_request_http_get_message(request); g_string_append_printf(body,"temp,channel=%d,channel_name=%s,room=%s",channel,channel_name,room); g_string_append_printf(body," value=%.1f %" G_GINT64_FORMAT,temp,t); g_string_append_printf(body,"\n"); g_string_append_printf(body,"hum,channel=%d,channel_name=%s,room=%s",channel,channel_name,room); g_string_append_printf(body," value=%.1f %" G_GINT64_FORMAT,hum,t); g_string_append_printf(body,"\n"); if(debug) g_message(body->str); if(!testing) { soup_message_set_request(message,"application/binary",SOUP_MEMORY_COPY,body->str,body->len); guint session_status = soup_session_send_message(session,message); if(session_status == 204) { /* message was received */ //g_print("received status %d\n",session_status); g_string_erase(body,0,-1); /* clear the string */ } else { g_print("no connection to server"); } /* otherwise, keep it and attempt to resend next time */ } g_object_unref(message); } count ++; /* reset the error count on successful read */ error_count = 0; } else if(error_count > MAX_ERRORS) { g_printerr("Too many errors to continue\n"); exit(-1); } else { error_count++; } if(testing && count>60) break; g_usleep(SLEEP_TIME*1000000); } if(session) { g_string_free(uri,TRUE); g_string_free(body,TRUE); g_object_unref(session); } hid_close(handle); hid_exit(); return 0; }
int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; EmpathyAuthFactory *factory; TpDebugSender *debug_sender; TpSimpleClientFactory *tp_factory; TpDBusDaemon *dbus; context = g_option_context_new (N_(" — Empathy authentication client")); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command " "line options.\n", error->message, argv[0]); g_warning ("Error in empathy-auth-client init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (context); empathy_gtk_init (); gnutls_global_init (); g_set_application_name (_("Empathy authentication client")); /* Make empathy and empathy-auth-client appear as the same app in * gnome-shell */ g_set_prgname ("empathy"); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); /* There is no 'main' UI window so just use the default GdkScreen */ empathy_set_css_provider (NULL); #ifdef ENABLE_DEBUG /* Set up debug sender */ debug_sender = tp_debug_sender_dup (); g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN); #endif dbus = tp_dbus_daemon_dup (NULL); tp_factory = tp_simple_client_factory_new (dbus); tp_simple_client_factory_add_account_features_varargs (tp_factory, TP_ACCOUNT_FEATURE_STORAGE, 0); factory = empathy_auth_factory_new (tp_factory); g_object_unref (tp_factory); g_object_unref (dbus); g_signal_connect (factory, "new-server-tls-handler", G_CALLBACK (auth_factory_new_tls_handler_cb), NULL); g_signal_connect (factory, "new-server-sasl-handler", G_CALLBACK (auth_factory_new_sasl_handler_cb), NULL); g_signal_connect (factory, "auth-password-failed", G_CALLBACK (auth_factory_auth_passsword_failed), NULL); if (!empathy_auth_factory_register (factory, &error)) { g_critical ("Failed to register the auth factory: %s\n", error->message); g_error_free (error); g_object_unref (factory); return EXIT_FAILURE; } DEBUG ("Empathy auth client started."); if (g_getenv ("EMPATHY_PERSIST") != NULL) { DEBUG ("Timed-exit disabled"); use_timer = FALSE; } /* Wait for the migration code to be done before starting the timer */ empathy_sanity_checking_run_async (sanity_cb, NULL); gtk_main (); g_object_unref (factory); g_object_unref (debug_sender); return EXIT_SUCCESS; }
int main (int argc, char **argv) { GstPlay *play; GPtrArray *playlist; gboolean print_version = FALSE; gboolean interactive = TRUE; gboolean gapless = FALSE; gboolean shuffle = FALSE; gdouble volume = -1; gchar **filenames = NULL; gchar *audio_sink = NULL; gchar *video_sink = NULL; gchar **uris; guint num, i; GError *err = NULL; GOptionContext *ctx; gchar *playlist_file = NULL; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, N_("Print version information and exit"), NULL}, {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink, N_("Video sink to use (default is autovideosink)"), NULL}, {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink, N_("Audio sink to use (default is autoaudiosink)"), NULL}, {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless, N_("Enable gapless playback"), NULL}, {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle, N_("Shuffle playlist"), NULL}, {"no-interactive", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &interactive, N_("Disable interactive control via the keyboard"), NULL}, {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume, N_("Volume"), NULL}, {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file, N_("Playlist file containing input media files"), NULL}, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, N_("Do not print any output (apart from errors)"), NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; setlocale (LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif g_set_prgname ("gst-play-" GST_API_VERSION); ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."); 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", GST_STR_NULL (err->message)); return 1; } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play"); if (print_version) { gchar *version_str; version_str = gst_version_string (); g_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION); g_print ("%s\n", version_str); g_print ("%s\n", GST_PACKAGE_ORIGIN); g_free (version_str); g_free (audio_sink); g_free (video_sink); g_free (playlist_file); return 0; } playlist = g_ptr_array_new (); if (playlist_file != NULL) { gchar *playlist_contents = NULL; gchar **lines = NULL; if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) { lines = g_strsplit (playlist_contents, "\n", 0); num = g_strv_length (lines); for (i = 0; i < num; i++) { if (lines[i][0] != '\0') { GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]); add_to_playlist (playlist, lines[i]); } } g_strfreev (lines); g_free (playlist_contents); } else { g_printerr ("Could not read playlist: %s\n", err->message); g_clear_error (&err); } g_free (playlist_file); playlist_file = NULL; } if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) { g_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."), "gst-play-" GST_API_VERSION); g_printerr ("\n\n"), g_printerr ("%s\n\n", _("You must provide at least one filename or URI to play.")); /* No input provided. Free array */ g_ptr_array_free (playlist, TRUE); g_free (audio_sink); g_free (video_sink); return 1; } /* fill playlist */ if (filenames != NULL && *filenames != NULL) { num = g_strv_length (filenames); for (i = 0; i < num; ++i) { GST_LOG ("command line argument: %s", filenames[i]); add_to_playlist (playlist, filenames[i]); } g_strfreev (filenames); } num = playlist->len; g_ptr_array_add (playlist, NULL); uris = (gchar **) g_ptr_array_free (playlist, FALSE); if (shuffle) shuffle_uris (uris, num); /* prepare */ play = play_new (uris, audio_sink, video_sink, gapless, volume); if (play == NULL) { g_printerr ("Failed to create 'playbin' element. Check your GStreamer installation.\n"); return EXIT_FAILURE; } if (interactive) { if (gst_play_kb_set_key_handler (keyboard_cb, play)) { g_print (_("Press 'k' to see a list of keyboard shortcuts.\n")); atexit (restore_terminal); } else { g_print ("Interactive keyboard handling in terminal not available.\n"); } } /* play */ do_play (play); /* clean up */ play_free (play); g_free (audio_sink); g_free (video_sink); g_print ("\n"); return 0; }
int main (int argc, char **argv) { GOptionContext *opts; const char *url; SoupURI *proxy_uri, *parsed; GError *error = NULL; SoupLogger *logger = 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); url = argv[1]; parsed = soup_uri_new (url); if (!parsed) { g_printerr ("Could not parse '%s' as a URL\n", url); exit (1); } soup_uri_free (parsed); session = g_object_new (SOUP_TYPE_SESSION, SOUP_SESSION_SSL_CA_FILE, ca_file, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_COOKIE_JAR, SOUP_SESSION_USER_AGENT, "get ", SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL); if (ntlm) soup_session_add_feature_by_type (session, SOUP_TYPE_AUTH_NTLM); if (debug) { logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } if (proxy) { proxy_uri = soup_uri_new (proxy); if (!proxy_uri) { g_printerr ("Could not parse '%s' as URI\n", proxy); exit (1); } g_object_set (G_OBJECT (session), SOUP_SESSION_PROXY_URI, proxy_uri, NULL); soup_uri_free (proxy_uri); } if (!synchronous) loop = g_main_loop_new (NULL, TRUE); get_url (url); if (!synchronous) g_main_loop_unref (loop); return 0; }
int main (int argc, char *argv[]) { gchar *target_times = NULL; gchar *ev_option = NULL; gchar *fn_option = NULL; GOptionEntry options[] = { {"ev-compensation", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &ev_option, "EV compensation for source element GstPhotography interface", NULL}, {"aperture", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &aperture, "Aperture (size of lens opening) for source element GstPhotography interface", NULL}, {"flash-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &flash_mode, "Flash mode for source element GstPhotography interface", NULL}, {"scene-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &scene_mode, "Scene mode for source element GstPhotography interface", NULL}, {"exposure", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT64, &exposure, "Exposure time (in ms) for source element GstPhotography interface", NULL}, {"iso-speed", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &iso_speed, "ISO speed for source element GstPhotography interface", NULL}, {"white-balance-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &wb_mode, "White balance mode for source element GstPhotography interface", NULL}, {"colour-tone-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &color_mode, "Colour tone mode for source element GstPhotography interface", NULL}, {"directory", '\0', 0, G_OPTION_ARG_STRING, &fn_option, "Directory for capture file(s) (default is current directory)", NULL}, {"mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &mode, "Capture mode (default = 0 (image), 1 = video)", NULL}, {"capture-time", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &capture_time, "Time to capture video in seconds (default = 10)", NULL}, {"capture-total", '\0', 0, G_OPTION_ARG_INT, &capture_total, "Total number of captures to be done (default = 1)", NULL}, {"flags", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &flags, "Flags for camerabin, (default = 0x9)", NULL}, {"mute", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &mute, "Mute audio", NULL}, {"zoom", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &zoom, "Zoom (100 = 1x (default), 200 = 2x etc.)", NULL}, {"audio-src", '\0', 0, G_OPTION_ARG_STRING, &audiosrc_name, "Audio source used in video recording", NULL}, {"audio-bitrate", '\0', 0, G_OPTION_ARG_INT, &audio_bitrate, "Audio bitrate (default 128000)", NULL}, {"audio-samplerate", '\0', 0, G_OPTION_ARG_INT, &audio_samplerate, "Audio samplerate (default 48000)", NULL}, {"audio-channels", '\0', 0, G_OPTION_ARG_INT, &audio_channels, "Audio channels (default 1)", NULL}, {"video-src", '\0', 0, G_OPTION_ARG_STRING, &videosrc_name, "Video source used in still capture and video recording", NULL}, {"audio-enc", '\0', 0, G_OPTION_ARG_STRING, &audioenc_name, "Audio encoder used in video recording", NULL}, {"video-enc", '\0', 0, G_OPTION_ARG_STRING, &videoenc_name, "Video encoder used in video recording", NULL}, {"image-enc", '\0', 0, G_OPTION_ARG_STRING, &imageenc_name, "Image encoder used in still capture", NULL}, {"image-pp", '\0', 0, G_OPTION_ARG_STRING, &imagepp_name, "List of image post-processing elements separated with comma", NULL}, {"image-formatter", '\0', 0, G_OPTION_ARG_STRING, &imageformatter_name, "Image metadata formatter used in still image capture", NULL}, {"video-mux", '\0', 0, G_OPTION_ARG_STRING, &videomux_name, "Muxer used in video recording", NULL}, {"viewfinder-sink", '\0', 0, G_OPTION_ARG_STRING, &vfsink_name, "Viewfinder sink (default = fakesink)", NULL}, {"image-width", '\0', 0, G_OPTION_ARG_INT, &image_width, "Width for image capture", NULL}, {"image-height", '\0', 0, G_OPTION_ARG_INT, &image_height, "Height for image capture", NULL}, {"view-framerate-num", '\0', 0, G_OPTION_ARG_INT, &view_framerate_num, "Framerate numerator for viewfinder", NULL}, {"view-framerate-den", '\0', 0, G_OPTION_ARG_INT, &view_framerate_den, "Framerate denominator for viewfinder", NULL}, {"src-colorspace", '\0', 0, G_OPTION_ARG_STRING, &src_csp, "Colorspace format for video source (e.g. YUY2, UYVY)", NULL}, {"src-format", '\0', 0, G_OPTION_ARG_STRING, &src_format, "Video format for video source", NULL}, {"preview-caps", '\0', 0, G_OPTION_ARG_STRING, &preview_caps_name, "Preview caps (e.g. video/x-raw-rgb,width=320,height=240)", NULL}, {"video-source-filter", '\0', 0, G_OPTION_ARG_STRING, &video_src_filter, "Video filter to process all frames from video source", NULL}, {"viewfinder-filter", '\0', 0, G_OPTION_ARG_STRING, &viewfinder_filter, "Filter to process all frames going to viewfinder sink", NULL}, {"x-width", '\0', 0, G_OPTION_ARG_INT, &x_width, "X window width (default = 320)", NULL}, {"x-height", '\0', 0, G_OPTION_ARG_INT, &x_height, "X window height (default = 240)", NULL}, {"no-xwindow", '\0', 0, G_OPTION_ARG_NONE, &no_xwindow, "Do not create XWindow", NULL}, {NULL} }; GOptionContext *ctx; GError *err = NULL; if (!g_thread_supported ()) g_thread_init (NULL); ctx = g_option_context_new ("\n\ncamerabin command line test application."); 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); } g_option_context_free (ctx); /* if we fail to create xwindow should we care? */ if (!no_xwindow) create_host_window (); GST_DEBUG_CATEGORY_INIT (camerabin_test, "camerabin-test", 0, "camerabin test"); /* FIXME: error handling */ if (ev_option != NULL) ev_compensation = strtod (ev_option, (char **) NULL); if (vfsink_name == NULL) vfsink_name = g_strdup ("fakesink"); filename = g_string_new (fn_option); if (filename->len == 0) filename = g_string_append (filename, "."); timer = g_timer_new (); /* init */ if (setup_pipeline ()) { loop = g_main_loop_new (NULL, FALSE); g_idle_add ((GSourceFunc) run_pipeline, NULL); g_main_loop_run (loop); cleanup_pipeline (); g_main_loop_unref (loop); } /* free */ g_string_free (filename, TRUE); g_free (ev_option); g_free (audiosrc_name); g_free (videosrc_name); g_free (audioenc_name); g_free (videoenc_name); g_free (imageenc_name); g_free (imageformatter_name); g_free (imagepp_name); g_free (videomux_name); g_free (vfsink_name); g_free (src_csp); g_free (src_format); g_free (target_times); g_timer_destroy (timer); if (window) XDestroyWindow (display, window); if (display) XCloseDisplay (display); return 0; }
static void commandline_free(GOptionContext *context) { g_option_context_free(context); }
/** * This function parses command line options. It sets the options in this * order. It means that the value used for an option is the one set in the * lastest step. * 0) default values are set into the options_t * structure * 1) reads the default configuration file if any. * 2) reads the configuration file mentionned on the command line. * 3) sets the command line options (except for the list of directories, * all other values are replaced by thoses in the command line) * @param argc : number of arguments given on the command line. * @param argv : an array of strings that contains command line arguments. * @returns options_t structure malloc'ed and filled upon choosen command * line's option */ static options_t *manage_command_line_options(int argc, char **argv) { gboolean version = FALSE; /** True if -v was selected on the command line */ gint debug = -4; /** 0 == FALSE and other values == TRUE */ gchar *configfile = NULL; /** filename for the configuration file if any */ gchar *ip = NULL; /** IP address where is located server's program */ gint port = 0; /** Port number on which to send things to the server */ gchar *list = NULL; /** Should contain a filename or a directory to filter out */ gchar *restore = NULL; /** Must contain a filename or a directory name to be restored */ gchar *date = NULL; /** date at which we want to restore a file or directory */ gchar *where = NULL; /** Contains the directory where to restore a file / directory */ gchar *afterdate = NULL; /** afterdate: we want to restore a file that has its mtime after this date */ gchar *beforedate = NULL; /** beforedate: we want to restore a file that has its mtime before this date */ GOptionEntry entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Prints program version."), NULL}, { "list", 'l', 0, G_OPTION_ARG_FILENAME, &list, N_("Gives a list of saved files that correspond to the given REGEX."), "REGEX"}, { "restore", 'r', 0, G_OPTION_ARG_FILENAME, &restore, N_("Restores requested filename (REGEX) (by default latest version)."), "REGEX"}, { "date", 't', 0, G_OPTION_ARG_STRING, &date, N_("Restores the selected file at that specific DATE (YYYY-MM-DD HH:MM:SS format)."), "DATE"}, { "after", 'a', 0, G_OPTION_ARG_STRING, &afterdate, N_("Restores the selected file with mtime after DATE (YYYY-MM-DD HH:MM:SS format)."), "DATE"}, { "before", 'b', 0, G_OPTION_ARG_STRING, &beforedate, N_("Restores the selected file with mtime before DATE (YYYY-MM-DD HH:MM:SS format)."), "DATE"}, { "debug", 'd', 0, G_OPTION_ARG_INT, &debug, N_("Activates (1) or desactivates (0) debug mode."), N_("BOOLEAN")}, { "configuration", 'c', 0, G_OPTION_ARG_STRING, &configfile, N_("Specify an alternative configuration file."), N_("FILENAME")}, { "where", 'w', 0, G_OPTION_ARG_STRING, &where, N_("Specify a DIRECTORY where to restore a file."), N_("DIRECTORY")}, { "ip", 'i', 0, G_OPTION_ARG_STRING, &ip, N_("IP address where server program is."), "IP"}, { "port", 'p', 0, G_OPTION_ARG_INT, &port, N_("Port NUMBER on which server program is listening."), N_("NUMBER")}, { NULL } }; GError *error = NULL; GOptionContext *context; options_t *opt = NULL; /** Structure to manage program's options */ gchar *bugreport = NULL; /** Bug Report message */ gchar *summary = NULL; /** Abstract for the program */ gchar *defaultconfigfilename = NULL; bugreport = g_strconcat(_("Please report bugs to: "), PACKAGE_BUGREPORT, NULL); summary = g_strdup(_("This program is restoring files from cdpfglserver's server.\n")); context = g_option_context_new(""); set_debug_mode(ENABLE_DEBUG); set_option_context_options(context, entries, TRUE, bugreport, summary); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print(_("Option parsing failed: %s\n"), error->message); exit(EXIT_FAILURE); } /* 0) Setting default values */ opt = (options_t *) g_malloc0(sizeof(options_t)); opt->configfile = NULL; opt->list = NULL; opt->restore = NULL; opt->ip = g_strdup("localhost"); opt->port = SERVER_PORT; opt->where = NULL; /* 1) Reading options from default configuration file * note: restore option will never be read into the configuration * file. */ defaultconfigfilename = get_probable_etc_path(PROGRAM_NAME, "restore.conf"); read_from_configuration_file(opt, defaultconfigfilename); defaultconfigfilename = free_variable(defaultconfigfilename); /* 2) Reading the configuration from the configuration file specified * on the command line (if any). * note: same note than 1) applies here too. */ if (configfile != NULL) { read_from_configuration_file(opt, configfile); } /* 3) retrieving other options from the command line. */ set_debug_mode_upon_cmdl(debug); opt->version = version; /* only TRUE if -v or --version was invoked */ if (date != NULL) { opt->date = g_strdup(date); } if (afterdate != NULL) { opt->afterdate = g_strdup(afterdate); } if (beforedate != NULL) { opt->beforedate = g_strdup(beforedate); } if (list != NULL) { opt->list = g_strdup(list); } if (restore != NULL) { opt->restore = g_strdup(restore); } if (ip != NULL) { free_variable(opt->ip); opt->ip = g_strdup(ip); } if (port > 1024 && port < 65535) { opt->port = port; } if (where != NULL) { opt->where = g_strdup(where); } g_option_context_free(context); free_variable(ip); free_variable(bugreport); free_variable(summary); free_variable(list); free_variable(restore); free_variable(date); free_variable(afterdate); free_variable(beforedate); free_variable(where); return opt; }
int main (int argc, char *argv[]) { PkDirectPrivate *priv = NULL; const gchar *destdir; gboolean ret = TRUE; gint retval = EXIT_SUCCESS; g_autoptr(GError) error = NULL; g_autofree gchar *backend_name = NULL; g_autofree gchar *cmd_descriptions = NULL; g_autofree gchar *conf_filename = NULL; g_autoptr(GKeyFile) conf = NULL; const GOptionEntry options[] = { { "backend", '\0', 0, G_OPTION_ARG_STRING, &backend_name, /* TRANSLATORS: a backend is the system package tool, e.g. dnf, apt */ _("Packaging backend to use, e.g. dummy"), NULL }, { NULL } }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* create priv object */ priv = g_new0 (PkDirectPrivate, 1); /* add commands */ priv->cmd_array = g_ptr_array_new_with_free_func ((GDestroyNotify) pk_direct_item_free); pk_direct_add (priv->cmd_array, "refresh", NULL, /* TRANSLATORS: command description */ _("Refresh the cache"), pk_direct_refresh); pk_direct_add (priv->cmd_array, "refresh-force", NULL, /* TRANSLATORS: command description */ _("Refresh the cache (forced)"), pk_direct_refresh_force); pk_direct_add (priv->cmd_array, "search-name", "[SEARCH]", /* TRANSLATORS: command description */ _("Search by names"), pk_direct_search_names); pk_direct_add (priv->cmd_array, "search-detail", "[SEARCH]", /* TRANSLATORS: command description */ _("Search by details"), pk_direct_search_details); pk_direct_add (priv->cmd_array, "search-file", "[SEARCH]", /* TRANSLATORS: command description */ _("Search by files"), pk_direct_search_files); pk_direct_add (priv->cmd_array, "install", "[PKGID]", /* TRANSLATORS: command description */ _("Install package"), pk_direct_install); pk_direct_add (priv->cmd_array, "remove", "[PKGID]", /* TRANSLATORS: command description */ _("Remove package"), pk_direct_remove); pk_direct_add (priv->cmd_array, "repo-set-data", "[REPO] [KEY] [VALUE]", /* TRANSLATORS: command description */ _("Set repository options"), pk_direct_repo_set_data); /* sort by command name */ g_ptr_array_sort (priv->cmd_array, (GCompareFunc) pk_sort_command_name_cb); /* get a list of the commands */ priv->context = g_option_context_new (NULL); cmd_descriptions = pk_direct_get_descriptions (priv->cmd_array); g_option_context_set_summary (priv->context, cmd_descriptions); /* TRANSLATORS: program name */ g_set_application_name (_("PackageKit")); g_option_context_add_main_entries (priv->context, options, NULL); g_option_context_add_group (priv->context, pk_debug_get_option_group ()); ret = g_option_context_parse (priv->context, &argc, &argv, &error); if (!ret) { /* TRANSLATORS: the user didn't read the man page */ g_print ("%s: %s\n", _("Failed to parse arguments"), error->message); goto out; } /* get values from the config file */ conf = g_key_file_new (); conf_filename = pk_util_get_config_filename (); ret = g_key_file_load_from_file (conf, conf_filename, G_KEY_FILE_NONE, &error); if (!ret) { /* TRANSLATORS: probably not yet installed */ g_print ("%s: %s\n", _("Failed to load the config file"), error->message); retval = EXIT_FAILURE; goto out; } /* support DESTDIR */ destdir = g_getenv ("DESTDIR"); if (destdir != NULL) g_key_file_set_string (conf, "Daemon", "DestDir", destdir); /* override the backend name */ if (backend_name != NULL) g_key_file_set_string (conf, "Daemon", "DefaultBackend", backend_name); /* resolve 'auto' to an actual name */ backend_name = g_key_file_get_string (conf, "Daemon", "DefaultBackend", NULL); if (backend_name == NULL || g_strcmp0 (backend_name, "auto") == 0) { if (!pk_util_set_auto_backend (conf, &error)) { g_print ("Failed to resolve auto: %s\n", error->message); retval = EXIT_FAILURE; goto out; } } /* do stuff on ctrl-c */ priv->loop = g_main_loop_new (NULL, FALSE); g_unix_signal_add_full (G_PRIORITY_DEFAULT, SIGINT, pk_direct_sigint_cb, &priv, NULL); /* load the backend */ priv->backend = pk_backend_new (conf); if (!pk_backend_load (priv->backend, &error)) { /* TRANSLATORS: cannot load the backend the user specified */ g_print ("%s: %s\n", _("Failed to load the backend"), error->message); retval = EXIT_FAILURE; goto out; } /* set up the job */ priv->job = pk_backend_job_new (conf); pk_backend_job_set_cache_age (priv->job, G_MAXUINT); pk_backend_job_set_backend (priv->job, priv->backend); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_FINISHED, pk_direct_finished_cb, priv); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_PERCENTAGE, pk_direct_percentage_cb, priv); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_STATUS_CHANGED, pk_direct_status_changed_cb, priv); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_PACKAGE, pk_direct_package_cb, priv); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_ERROR_CODE, pk_direct_error_cb, priv); pk_backend_job_set_vfunc (priv->job, PK_BACKEND_SIGNAL_ITEM_PROGRESS, pk_direct_item_progress_cb, priv); /* run the specified command */ ret = pk_direct_run (priv, argv[1], (gchar**) &argv[2], &error); if (!ret) { if (g_error_matches (error, PK_ERROR, PK_ERROR_NO_SUCH_CMD)) { g_autofree gchar *tmp = NULL; tmp = g_option_context_get_help (priv->context, TRUE, NULL); g_print ("%s", tmp); } else { g_print ("%s\n", error->message); } goto out; } /* unload backend */ if (!pk_backend_unload (priv->backend)) { /* TRANSLATORS: cannot unload the backend the user specified */ g_print ("%s\n", _("Failed to unload the backend")); retval = EXIT_FAILURE; goto out; } out: if (priv->cmd_array != NULL) g_ptr_array_unref (priv->cmd_array); if (priv->backend != NULL) g_object_unref (priv->backend); if (priv->job != NULL) g_object_unref (priv->job); if (priv->loop != NULL) g_main_loop_unref (priv->loop); g_option_context_free (priv->context); g_free (priv); return retval; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *err = NULL; struct sigaction sa; #ifdef HAVE_CAPNG /* Drop capabilities */ capng_clear(CAPNG_SELECT_BOTH); capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED, CAP_NET_BIND_SERVICE, CAP_NET_ADMIN, CAP_NET_RAW, CAP_IPC_LOCK, -1); capng_apply(CAPNG_SELECT_BOTH); #endif context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) { if (err != NULL) { g_printerr("%s\n", err->message); g_error_free(err); } else g_printerr("An unknown error occurred\n"); exit(1); } g_option_context_free(context); if (option_detach == TRUE) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); } } umask(0077); openlog("hcitrace", LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_DAEMON); syslog(LOG_INFO, "HCI trace deamon %s", VERSION); memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = sig_term; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); sa.sa_handler = sig_debug; sigaction(SIGUSR2, &sa, NULL); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); if (option_debug == TRUE) { syslog(LOG_INFO, "Enabling debug information"); } event_loop = g_main_loop_new(NULL, FALSE); debug("Entering main loop"); g_main_loop_run(event_loop); g_main_loop_unref(event_loop); syslog(LOG_INFO, "Exit"); closelog(); return 0; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *err = NULL; guint signal; set_version(); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) { if (err != NULL) { g_printerr("%s\n", err->message); g_error_free(err); } else g_printerr("An unknown error occurred\n"); exit(EXIT_FAILURE); } g_option_context_free(context); if (option_version == TRUE) { printf("%s\n", VERSION); exit(EXIT_SUCCESS); } signal = setup_signalfd(); if (!signal) return EXIT_FAILURE; if (option_dbg || option_mgmt_dbg) __btd_log_init("*", 0); else __btd_log_init(NULL, 0); if (!set_capabilities()) { __btd_log_cleanup(); g_source_remove(signal); return EXIT_FAILURE; } quit_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS, quit_eventloop, NULL); if (quit_timeout == 0) { error("Failed to init startup timeout"); __btd_log_cleanup(); g_source_remove(signal); return EXIT_FAILURE; } if (!bt_bluetooth_start(option_index, option_mgmt_dbg, adapter_ready)) { __btd_log_cleanup(); g_source_remove(quit_timeout); g_source_remove(signal); return EXIT_FAILURE; } /* Use params: mtu = 0, flags = 0 */ start_sdp_server(0, 0); DBG("Entering main loop"); event_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(event_loop); g_source_remove(signal); if (quit_timeout > 0) g_source_remove(quit_timeout); cleanup_services(); stop_sdp_server(); bt_bluetooth_cleanup(); g_main_loop_unref(event_loop); /* If no adapter was initialized, hal_ipc is NULL */ if (hal_ipc) { ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE); ipc_cleanup(hal_ipc); } info("Exit"); __btd_log_cleanup(); free(config_vendor); free(config_model); free(config_name); free(config_serial); free(config_fw_rev); free(config_hw_rev); return EXIT_SUCCESS; }
int main (int argc, char **argv) { AppearanceData *data; GtkWidget *w; gchar *install_filename = NULL; gchar *start_page = NULL; gchar **wallpaper_files = NULL; GOptionContext *option_context; GOptionEntry option_entries[] = { { "install-theme", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_FILENAME, &install_filename, N_("Specify the filename of a theme to install"), N_("filename") }, { "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 (theme|background|fonts|interface)"), N_("page") }, { G_OPTION_REMAINING, 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_FILENAME_ARRAY, &wallpaper_files, NULL, N_("[WALLPAPER...]") }, { NULL } }; option_context = g_option_context_new (NULL); g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE); /* init */ data = init_appearance_data (&argc, &argv, option_context); if (!data) return 1; /* init tabs */ themes_init (data); style_init (data); desktop_init (data, (const gchar **) wallpaper_files); g_strfreev (wallpaper_files); font_init (data); /* init support for other window managers */ support_init (data); /* prepare the main window */ w = appearance_capplet_get_widget (data, "appearance_window"); capplet_set_icon (w, "preferences-desktop-theme"); gtk_widget_show_all (w); g_signal_connect_after (w, "response", (GCallback) main_window_response, data); /* default to background page if files were given on the command line */ if (wallpaper_files && !install_filename && !start_page) start_page = g_strdup ("background"); if (start_page != NULL) { gchar *page_name; page_name = g_strconcat (start_page, "_vbox", NULL); g_free (start_page); w = appearance_capplet_get_widget (data, page_name); if (w != NULL) { GtkNotebook *nb; gint pindex; nb = GTK_NOTEBOOK (appearance_capplet_get_widget (data, "main_notebook")); pindex = gtk_notebook_page_num (nb, w); if (pindex != -1) gtk_notebook_set_current_page (nb, pindex); } g_free (page_name); } if (install_filename != NULL) { GFile *inst = g_file_new_for_commandline_arg (install_filename); g_free (install_filename); mate_theme_install (inst, GTK_WINDOW (w)); g_object_unref (inst); } g_option_context_free (option_context); /* start the mainloop */ gtk_main (); gdk_threads_leave (); /* free stuff */ g_free (data); return 0; }
int main(int argc, char **argv) { int nmenu; int imenu; GError *error = NULL; GOptionContext *context; gebr_libinit("libgebr"); gebr_geoxml_init(); /* Summary */ context = g_option_context_new(NULL); g_option_context_set_summary(context, "Edit tags of menu files for GeBR. Many menu files can\n" "be edited at once, but using the same tag values to all menus."); /* Description */ g_option_context_set_description(context, "Parameter --created set menu's creation date. It accepts \"now\" or\n" "a full qualified UTC date, like \"2008-09-23 21:12\".\n\n" "If iprog is 0, then title and description options refers to menu's\n" "title and description. If iprog > 0, then ith program is edited.\n" "Copyright (C) 2008-2010 Ricardo Biloti <*****@*****.**>"); g_option_context_add_main_entries(context, entries, NULL); /* Complain about unknown options */ g_option_context_set_ignore_unknown_options(context, FALSE); /* Parse command line */ if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { fprintf(stderr, "%s: syntax error\n", argv[0]); fprintf(stderr, "Try %s --help\n", argv[0]); return EXIT_FAILURE; } g_option_context_free(context); /* End of command line parse */ if (menu == NULL) return 0; nmenu = 0; while (menu[++nmenu] != NULL) ; for (imenu = 0; imenu < nmenu; imenu++) { GebrGeoXmlDocument *doc; GebrGeoXmlFlow *flow; GebrGeoXmlSequence *seq; GebrGeoXmlProgram *prog; gint nprog; if (gebr_geoxml_document_load((GebrGeoXmlDocument **) (&flow), menu[imenu], TRUE, NULL) != GEBR_GEOXML_RETV_SUCCESS) { fprintf(stderr, "Unable to load %s\n", menu[imenu]); break; } doc = GEBR_GEOXML_DOC(flow); nprog = gebr_geoxml_flow_get_programs_number(flow); if (author != NULL) gebr_geoxml_document_set_author(doc, author); if (email != NULL) gebr_geoxml_document_set_email(doc, email); if (date != NULL) { if (strcmp(date, "now") == 0) { gebr_geoxml_document_set_date_created(doc, gebr_iso_date()); } else { static gchar datestr[100]; struct tm tm; if (strptime(date, "%Y-%m-%d%H:%M", &tm) == NULL) { printf("Date parse error. See help for accepted formats.\n"); break; } strftime(datestr, 100, "%Y-%m-%dT%H:%M:00Z", &tm); gebr_geoxml_document_set_date_created(doc, datestr); } } if (iprog == 0) { if (title != NULL) gebr_geoxml_document_set_title(doc, title); if (desc != NULL) gebr_geoxml_document_set_description(doc, desc); if (url || binary || version) printf("To set URL, binary, or binary's version you must specify iprog\n"); if (helpdel) gebr_geoxml_document_set_help(doc, ""); gchar *help; if (fnhelp) { help = help_load (GEBR_GEOXML_OBJECT (doc), fnhelp); gebr_geoxml_document_set_help (doc, help); } else if (!helpdel) { help = help_update (GEBR_GEOXML_OBJECT (doc)); gebr_geoxml_document_set_help (doc, help); } } else { if (iprog > nprog) { printf("Invalid program index for menu %s\n", menu[imenu]); goto out; } gebr_geoxml_flow_get_program(flow, &seq, iprog - 1); prog = GEBR_GEOXML_PROGRAM(seq); if (title != NULL) gebr_geoxml_program_set_title(prog, title); if (desc != NULL) gebr_geoxml_program_set_description(prog, desc); if (binary != NULL) gebr_geoxml_program_set_binary(prog, binary); if (version != NULL) gebr_geoxml_program_set_version(prog, version); if (url != NULL) gebr_geoxml_program_set_url(prog, url); if (helpdel) gebr_geoxml_program_set_help(prog, ""); gchar *help; if (fnhelp) { help = help_load (GEBR_GEOXML_OBJECT (prog), fnhelp); gebr_geoxml_program_set_help (prog, help); } else if (!helpdel) { help = help_update (GEBR_GEOXML_OBJECT (prog)); gebr_geoxml_program_set_help (prog, help); } } out: gebr_geoxml_document_set_date_modified(doc, gebr_iso_date()); if (gebr_geoxml_document_save(doc, menu[imenu], FALSE) != GEBR_GEOXML_RETV_SUCCESS) fprintf(stderr, "Unable to save %s\n", menu[imenu]); gebr_geoxml_document_free(doc); } gebr_geoxml_finalize(); return 0; }
/** * main: */ gint main (gint argc, gchar *argv[]) { LiHelperDaemon helper; guint id; GOptionContext *opt_context; GError *error = NULL; gint res = 0; const GOptionEntry daemon_options[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &optn_show_version, "Show the program version", NULL }, { "verbose", 0, 0, G_OPTION_ARG_NONE, &optn_verbose_mode, "Display verbose output", NULL }, { NULL } }; opt_context = g_option_context_new ("- Limba daemon"); g_option_context_set_help_enabled (opt_context, TRUE); g_option_context_add_main_entries (opt_context, daemon_options, NULL); g_option_context_parse (opt_context, &argc, &argv, &error); if (error != NULL) { g_print ("%s\n", error->message); g_printerr ("Invalid command line options."); g_error_free (error); res = 1; goto out; } if (optn_show_version) { g_print ("Limba version: %s", VERSION "\n"); goto out; } /* just a hack, we might need proper message handling later */ if (optn_verbose_mode) { g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); } /* initialize helper */ helper.loop = g_main_loop_new (NULL, FALSE); helper.exit_idle_time = 30; helper.timer = g_timer_new (); helper.job = li_daemon_job_new (); id = g_bus_own_name (G_BUS_TYPE_SYSTEM, "org.freedesktop.Limba", G_BUS_NAME_OWNER_FLAGS_REPLACE, (GBusAcquiredCallback) on_bus_acquired, (GBusNameAcquiredCallback) on_name_acquired, (GBusNameLostCallback) on_name_lost, &helper, NULL); helper.timer_id = g_timeout_add_seconds (5, (GSourceFunc) li_daemon_timeout_check_cb, &helper); g_source_set_name_by_id (helper.timer_id, "[LiDaemon] main poll"); g_main_loop_run (helper.loop); /* cleanup */ g_bus_unown_name (id); g_timer_destroy (helper.timer); g_main_loop_unref (helper.loop); g_object_unref (helper.job); if (helper.timer_id > 0) g_source_remove (helper.timer_id); if (helper.authority != NULL) g_object_unref (helper.authority); out: g_option_context_free (opt_context); return res; }
/** * Parses argc and argv and returns the * arguments that Metacity understands in meta_args. * * The strange call signature has to be written like it is so * that g_option_context_parse() gets a chance to modify argc and * argv. * * \param argc Pointer to the number of arguments Metacity was given * \param argv Pointer to the array of arguments Metacity was given * \param meta_args The result of parsing the arguments. **/ static void meta_parse_options (int *argc, char ***argv, MetaArguments *meta_args) { MetaArguments my_args = {NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, FALSE}; GOptionEntry options[] = { { "sm-disable", 0, 0, G_OPTION_ARG_NONE, &my_args.disable_sm, N_("Disable connection to session manager"), NULL }, { "replace", 0, 0, G_OPTION_ARG_NONE, &my_args.replace_wm, N_("Replace the running window manager with Metacity"), NULL }, { "sm-client-id", 0, 0, G_OPTION_ARG_STRING, &my_args.client_id, N_("Specify session management ID"), "ID" }, { "display", 'd', 0, G_OPTION_ARG_STRING, &my_args.display_name, N_("X Display to use"), "DISPLAY" }, { "sm-save-file", 0, 0, G_OPTION_ARG_FILENAME, &my_args.save_file, N_("Initialize session from savefile"), "FILE" }, { "version", 0, 0, G_OPTION_ARG_NONE, &my_args.print_version, N_("Print version"), NULL }, { "sync", 0, 0, G_OPTION_ARG_NONE, &my_args.sync, N_("Make X calls synchronous"), NULL }, { "composite", 'c', COMPOSITE_OPTS_FLAGS, G_OPTION_ARG_NONE, &my_args.composite, N_("Turn compositing on"), NULL }, { "no-composite", 0, COMPOSITE_OPTS_FLAGS, G_OPTION_ARG_NONE, &my_args.no_composite, N_("Turn compositing off"), NULL }, { "no-force-fullscreen", 0, COMPOSITE_OPTS_FLAGS, G_OPTION_ARG_NONE, &my_args.no_force_fullscreen, N_("Don't make fullscreen windows that are maximized and have no decorations"), NULL }, {NULL} }; GOptionContext *ctx; GError *error = NULL; ctx = g_option_context_new (NULL); g_option_context_add_main_entries (ctx, options, "metacity"); if (!g_option_context_parse (ctx, argc, argv, &error)) { g_print ("metacity: %s\n", error->message); exit(1); } g_option_context_free (ctx); /* Return the parsed options through the meta_args param. */ *meta_args = my_args; }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionContext *context = NULL; GFile *file; gchar *summary; gchar *description; int i; gchar *param; gboolean res; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); param = g_strdup_printf (("%s..."), _("FILE")); /* Translators: this message will appear after the usage string */ /* and before the list of options. */ summary = _("Concatenate files and print to the standard output."); description = g_strconcat (_("gvfs-cat works just like the traditional cat utility, but using gvfs\n" "locations instead of local files: for example you can use something\n" "like smb://server/resource/file.txt as location."), "\n\n", _("Note: just pipe through cat if you need its formatting options\n" "like -n, -T or other."), NULL); context = g_option_context_new (param); g_option_context_set_summary (context, summary); g_option_context_set_description (context, description); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); g_free (param); g_free (description); if (error != NULL) { g_printerr (_("Error parsing commandline options: %s\n"), error->message); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); g_error_free (error); return 1; } if (!locations) { /* Translators: the %s is the program name. This error message */ /* means the user is calling gvfs-cat without any argument. */ g_printerr (_("%s: missing locations"), g_get_prgname ()); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } res = TRUE; i = 0; do { file = g_file_new_for_commandline_arg (locations[i]); res = cat (file) && res; g_object_unref (file); } while (locations[++i] != NULL); return res ? 0 : 2; }
int main (int argc, char **argv) { GHashTable *candidates; gchar *dir; gchar *base; gchar *highest = NULL; gchar *binary; /* actual binary we're going to run */ gchar *path = NULL; /* and its path */ gchar *desc; GOptionContext *ctx; GError *err = NULL; /* detect stuff */ dir = get_dir_of_binary (argv[0]); base = g_path_get_basename (argv[0]); /* parse command line options */ desc = g_strdup_printf ("wrapper to call versioned %s", base); ctx = g_option_context_new (desc); g_free (desc); g_option_context_set_ignore_unknown_options (ctx, TRUE); g_option_context_add_main_entries (ctx, wrapper_options, GETTEXT_PACKAGE); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); /* unmangle libtool if necessary */ unmangle_libtool (&dir, &base); #ifdef G_OS_WIN32 /* remove .exe suffix, otherwise we'll be looking for gst-blah.exe-*.* */ if (strlen (base) > 4 && g_str_has_suffix (base, ".exe")) { base[strlen (base) - 4] = '\0'; } #endif /* get all candidate binaries */ candidates = get_candidates (dir, base); g_free (dir); /* only look for 0.10, we don't want 0.11 tools to be picked up accidentally * (and from 0.11 on the unversioned tools are discontinued anyway) */ if (_arg_mm == NULL) _arg_mm = GST_MAJORMINOR; if (_arg_mm) { /* if a version was forced, look it up in the hash table */ dir = g_hash_table_lookup (candidates, _arg_mm); if (!dir) { g_print ("ERROR: Major/minor %s of tool %s not found.\n", _arg_mm, base); return 1; } binary = g_strdup_printf ("%s-%s", base, _arg_mm); } else { highest = NULL; /* otherwise, just look up the highest version */ if (candidates) { g_hash_table_foreach (candidates, (GHFunc) find_highest_version, &highest); } if (highest == NULL) { g_print ("ERROR: No version of tool %s found.\n", base); return 1; } dir = g_hash_table_lookup (candidates, highest); binary = g_strdup_printf ("%s-%s", base, highest); } g_free (base); path = g_build_filename (dir, binary, NULL); g_free (binary); /* print out list of major/minors we found if asked for */ /* FIXME: do them in order by creating a GList of keys and sort them */ if (_arg_list_mm) { g_hash_table_foreach (candidates, (GHFunc) hash_print_key, NULL); g_hash_table_destroy (candidates); return 0; } /* print out command line if asked for */ argv[0] = path; if (_print) { int i; for (i = 0; i < argc; ++i) { g_print ("%s", argv[i]); if (i < argc - 1) g_print (" "); } g_print ("\n"); } /* execute */ if (execv (path, argv) == -1) { g_warning ("Error executing %s: %s (%d)", path, g_strerror (errno), errno); } g_free (path); return 0; }
int main (int argc, char **argv) { GOptionContext *context; CheeseDbus *dbus_server; GError *error = NULL; GOptionEntry options[] = { {"verbose", 'v', 0, G_OPTION_ARG_NONE, &CheeseOptions.verbose, _("Be verbose"), NULL}, {"wide", 'w', 0, G_OPTION_ARG_NONE, &CheeseOptions.wide_mode, _("Enable wide mode"), NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &CheeseOptions.version, _("output version information and exit"), NULL}, {NULL} }; bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_rc_parse (APPNAME_DATA_DIR G_DIR_SEPARATOR_S "gtkrc"); g_thread_init (NULL); gdk_threads_init (); /* initialize rsvg */ /* needed to load the camera icon for the countdown widget */ rsvg_init (); g_set_application_name (_("Cheese")); context = g_option_context_new (N_("- Take photos and videos with your webcam, with fun graphical effects")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_group (context, gst_init_get_option_group ()); 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); return -1; } g_option_context_free (context); if (CheeseOptions.version) { g_print ("Cheese " VERSION " \n"); return 0; } dbus_server = cheese_dbus_new (); if (dbus_server == NULL) { gdk_notify_startup_complete (); return -1; } g_set_print_handler ((GPrintFunc) cheese_print_handler); g_print ("Cheese " VERSION " \n"); gtk_window_set_default_icon_name ("cheese"); gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), APPNAME_DATA_DIR G_DIR_SEPARATOR_S "icons"); CheeseWindow *window = g_object_new (CHEESE_TYPE_WINDOW, "startup-wide", CheeseOptions.wide_mode, NULL); cheese_dbus_set_window (window); gtk_widget_show (GTK_WIDGET (window)); gdk_threads_enter (); gtk_main (); gdk_threads_leave (); /* cleanup rsvg */ /* Note: this function is bad with multithread applications as it * calls xmlCleanupParser() and should be only called right before * exit */ rsvg_term (); return 0; }
static gboolean ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GOptionContext *context; glnx_unref_object OstreeRepo *repo = NULL; context = g_option_context_new ("Generate static delta files"); if (!ostree_option_context_parse (context, generate_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) goto out; if (argc >= 3 && opt_to_rev == NULL) opt_to_rev = argv[2]; if (argc < 3 && opt_to_rev == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "TO revision must be specified"); goto out; } else { const char *from_source; g_autofree char *from_resolved = NULL; g_autofree char *to_resolved = NULL; g_autofree char *from_parent_str = NULL; g_autoptr(GVariantBuilder) parambuilder = NULL; g_assert (opt_to_rev); if (opt_empty) { if (opt_from_rev) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot specify both --empty and --from=REV"); goto out; } from_source = NULL; } else if (opt_from_rev == NULL) { from_parent_str = g_strconcat (opt_to_rev, "^", NULL); from_source = from_parent_str; } else { from_source = opt_from_rev; } if (from_source) { if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error)) goto out; } if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error)) goto out; parambuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); if (opt_min_fallback_size) g_variant_builder_add (parambuilder, "{sv}", "min-fallback-size", g_variant_new_uint32 (g_ascii_strtoull (opt_min_fallback_size, NULL, 10))); if (opt_max_bsdiff_size) g_variant_builder_add (parambuilder, "{sv}", "max-bsdiff-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_bsdiff_size, NULL, 10))); if (opt_max_chunk_size) g_variant_builder_add (parambuilder, "{sv}", "max-chunk-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_chunk_size, NULL, 10))); if (opt_disable_bsdiff) g_variant_builder_add (parambuilder, "{sv}", "bsdiff-enabled", g_variant_new_boolean (FALSE)); g_variant_builder_add (parambuilder, "{sv}", "verbose", g_variant_new_boolean (TRUE)); g_print ("Generating static delta:\n"); g_print (" From: %s\n", from_resolved ? from_resolved : "empty"); g_print (" To: %s\n", to_resolved); if (!ostree_repo_static_delta_generate (repo, OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR, from_resolved, to_resolved, NULL, g_variant_builder_end (parambuilder), cancellable, error)) goto out; } ret = TRUE; out: if (context) g_option_context_free (context); return ret; }
int main (int argc, char **argv) { GMainLoop *loop; GConfDefaults *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; GOptionContext *options; GError *error = NULL; ret = 1; if (! g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); options = g_option_context_new (NULL); g_option_context_add_main_entries (options, entries, NULL); if (!g_option_context_parse (options, &argc, &argv, &error)) { g_warning ("Failed to parse options: %s\n", error->message); g_error_free (error); } g_option_context_free (options); g_log_set_default_handler (log_default_handler, NULL); if (debug) { log_levels = log_levels | G_LOG_LEVEL_DEBUG; } connection = get_system_bus (); if (connection == NULL) { g_warning ("Could not get system bus connection; bailing out"); goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } mechanism = gconf_defaults_new (); if (mechanism == NULL) { goto out; } if (!acquire_name_on_proxy (bus_proxy)) { g_warning ("Could not acquire name; bailing out"); goto out; } loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (mechanism); g_main_loop_unref (loop); ret = 0; out: return ret; }
/* The main () */ int main (int argc, char ** argv, char ** /*envp*/) { GOptionContext *context = NULL; Ekiga::ServiceCorePtr service_core(new Ekiga::ServiceCore); gchar *path = NULL; gchar *url = NULL; int debug_level = 0; /* Globals */ #ifndef WIN32 if (!XInitThreads ()) exit (1); #endif #if !GLIB_CHECK_VERSION(2,36,0) g_type_init (); #endif #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(); #endif /* GTK+ initialization */ gtk_init (&argc, &argv); #ifndef WIN32 signal (SIGPIPE, SIG_IGN); #endif /* Gettext initialization */ path = g_build_filename (DATA_DIR, "locale", NULL); textdomain (GETTEXT_PACKAGE); bindtextdomain (GETTEXT_PACKAGE, path); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); g_free (path); /* Application name */ g_set_application_name (_("Ekiga Softphone")); #ifndef WIN32 setenv ("PULSE_PROP_application.name", _("Ekiga Softphone"), true); #endif /* initialize platform-specific code */ gm_platform_init (); #ifdef WIN32 // plugins (i.e. the audio/video ptlib/opal codecs) are searched in ./plugins chdir (win32_datadir ()); #endif /* Configuration backend initialization */ gm_conf_init (); /* Arguments initialization */ GOptionEntry arguments [] = { { "debug", 'd', 0, G_OPTION_ARG_INT, &debug_level, N_("Prints debug messages in the console (level between 1 and 8)"), NULL }, { "call", 'c', 0, G_OPTION_ARG_STRING, &url, N_("Makes Ekiga call the given URI"), NULL }, { NULL, 0, 0, (GOptionArg)0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, arguments, PACKAGE_NAME); g_option_context_set_help_enabled (context, TRUE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); #ifndef WIN32 char* text_label = g_strdup_printf ("%d", debug_level); setenv ("PTLIB_TRACE_CODECS", text_label, TRUE); g_free (text_label); #else char* text_label = g_strdup_printf ("PTLIB_TRACE_CODECS=%d", debug_level); _putenv (text_label); g_free (text_label); if (debug_level != 0) { std::string desk_path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); if (!desk_path.empty ()) std::freopen((desk_path + "\\ekiga-stderr.txt").c_str (), "w", stderr); } #endif #if PTRACING if (debug_level != 0) PTrace::Initialise (PMAX (PMIN (8, debug_level), 0), NULL, PTrace::Timestamp | PTrace::Thread | PTrace::Blocks | PTrace::DateAndTime); #endif #ifdef HAVE_DBUS if (!ekiga_dbus_claim_ownership ()) { ekiga_dbus_client_show (); if (url != NULL) ekiga_dbus_client_connect (url); exit (0); } #endif /* Ekiga initialisation */ // should come *after* ptrace initialisation, to track codec loading for ex. GnomeMeeting instance; Ekiga::Runtime::init (); engine_init (service_core, argc, argv); PTRACE (1, "Ekiga version " << MAJOR_VERSION << "." << MINOR_VERSION << "." << BUILD_NUMBER); #ifdef EKIGA_REVISION PTRACE (1, "Ekiga git revision: " << EKIGA_REVISION); #endif PTRACE (1, "PTLIB version " << PTLIB_VERSION); PTRACE (1, "OPAL version " << OPAL_VERSION); #if defined HAVE_XV || defined HAVE_DX PTRACE (1, "Accelerated rendering support enabled"); #else PTRACE (1, "Accelerated rendering support disabled"); #endif #ifdef HAVE_DBUS PTRACE (1, "DBUS support enabled"); #else PTRACE (1, "DBUS support disabled"); #endif #ifdef HAVE_GCONF PTRACE (1, "GConf support enabled"); #else PTRACE (1, "GConf support disabled"); #endif boost::shared_ptr<GtkFrontend> gtk_frontend = service_core->get<GtkFrontend>("gtk-frontend"); GtkWidget *main_window = GTK_WIDGET (gtk_frontend->get_main_window ()); const int schema_version = MAJOR_VERSION * 1000 + MINOR_VERSION * 10 + BUILD_NUMBER; int crt_version = gm_conf_get_int (GENERAL_KEY "version"); if (crt_version < schema_version) { gmconf_upgrade_version (); // show the assistant if there is no config file if (crt_version == 0) gtk_widget_show_all (GTK_WIDGET (gtk_frontend->get_assistant_window ())); /* Update the version number */ gm_conf_set_int (GENERAL_KEY "version", schema_version); } /* Show the main window */ gtk_widget_show (main_window); /* Call the given host if needed */ if (url) { boost::shared_ptr<Ekiga::CallCore> call_core = service_core->get<Ekiga::CallCore> ("call-core"); call_core->dial (url); } #ifdef HAVE_DBUS EkigaDBusComponent *dbus_component = ekiga_dbus_component_new (*service_core); #endif // from now on, things should have taken their final place service_core->close (); /* The GTK loop */ gtk_main (); #ifdef HAVE_DBUS g_object_unref (dbus_component); #endif /* Exit Ekiga */ GnomeMeeting::Process ()->Exit (); service_core.reset (); Ekiga::Runtime::quit (); /* Save and shutdown the configuration */ gm_conf_save (); gm_conf_shutdown (); /* deinitialize platform-specific code */ gm_platform_shutdown (); return 0; }
/** * main: **/ int main (int argc, char **argv) { gint retval = EXIT_FAILURE; guint i; GOptionContext *context; gboolean opt_dump = FALSE; gboolean opt_wakeups = FALSE; gboolean opt_enumerate = FALSE; gboolean opt_monitor = FALSE; gchar *opt_show_info = FALSE; gboolean opt_version = FALSE; gboolean ret; GError *error = NULL; gchar *text = NULL; UpClient *client; UpDevice *device; const GOptionEntry entries[] = { { "enumerate", 'e', 0, G_OPTION_ARG_NONE, &opt_enumerate, _("Enumerate objects paths for devices"), NULL }, { "dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump, _("Dump all parameters for all objects"), NULL }, { "wakeups", 'w', 0, G_OPTION_ARG_NONE, &opt_wakeups, _("Get the wakeup data"), NULL }, { "monitor", 'm', 0, G_OPTION_ARG_NONE, &opt_monitor, _("Monitor activity from the power daemon"), NULL }, { "monitor-detail", 0, 0, G_OPTION_ARG_NONE, &opt_monitor_detail, _("Monitor with detail"), NULL }, { "show-info", 'i', 0, G_OPTION_ARG_STRING, &opt_show_info, _("Show information about object path"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, "Print version of client and daemon", NULL }, { NULL } }; g_type_init (); context = g_option_context_new ("UPower tool"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); loop = g_main_loop_new (NULL, FALSE); client = up_client_new (); if (opt_version) { gchar *daemon_version; g_object_get (client, "daemon-version", &daemon_version, NULL); g_print ("UPower client version %s\n" "UPower daemon version %s\n", PACKAGE_VERSION, daemon_version); g_free (daemon_version); retval = 0; goto out; } /* wakeups */ if (opt_wakeups) { up_tool_show_wakeups (); retval = EXIT_SUCCESS; goto out; } if (opt_enumerate || opt_dump) { GPtrArray *devices; ret = up_client_enumerate_devices_sync (client, NULL, &error); if (!ret) { egg_warning ("failed to enumerate: %s", error->message); goto out; } devices = up_client_get_devices (client); for (i=0; i < devices->len; i++) { device = (UpDevice*) g_ptr_array_index (devices, i); if (opt_enumerate) { g_print ("%s\n", up_device_get_object_path (device)); } else { g_print ("Device: %s\n", up_device_get_object_path (device)); text = up_device_to_text (device); g_print ("%s\n", text); g_free (text); } } g_ptr_array_unref (devices); if (opt_dump) { g_print ("Daemon:\n"); up_client_print (client); } retval = EXIT_SUCCESS; goto out; } if (opt_monitor || opt_monitor_detail) { ret = up_client_enumerate_devices_sync (client, NULL, &error); if (!ret) { egg_warning ("failed to enumerate: %s", error->message); goto out; } if (!up_tool_do_monitor (client)) goto out; retval = EXIT_SUCCESS; goto out; } if (opt_show_info != NULL) { device = up_device_new (); ret = up_device_set_object_path_sync (device, opt_show_info, NULL, &error); if (!ret) { g_print ("failed to set path: %s\n", error->message); g_error_free (error); } else { text = up_device_to_text (device); g_print ("%s\n", text); g_free (text); } g_object_unref (device); retval = EXIT_SUCCESS; goto out; } out: g_object_unref (client); return retval; }
/** * @brief Main entry to the Reversi C endgame solver implementation. * * @todo Documentation has to be completly developed. */ int main (int argc, char *argv[]) { GamePositionDb *db; GamePositionDbSyntaxErrorLog *syntax_error_log; FILE *fp; GError *error; gchar *source; int number_of_errors; GOptionContext *context; GOptionGroup *option_group; GamePositionDbEntry *entry; int solver_index; error = NULL; entry = NULL; solver_index = -1; /* GLib command line options and argument parsing. */ option_group = g_option_group_new("name", "description", "help_description", NULL, NULL); context = g_option_context_new("- Solve an endgame position"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_add_group(context, option_group); g_option_context_set_description(context, program_documentation_string); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print("Option parsing failed: %s\n", error->message); return -1; } /* Checks command line options for consistency. */ if (input_file) { source = g_strdup(input_file); } else { g_print("Option -f, --file is mandatory.\n."); return -2; } if (solver) { for (int index = 0; index < solvers_count; index++) { if (g_strcmp0(solver, solvers[index]) == 0) solver_index = index; } if (solver_index == -1) { g_print("Option -s, --solver is out of range.\n."); return -8; } if (solver_index == 2) { // solver == random if (repeats < 1) { g_print("Option -n, --repeats is out of range.\n."); return -9; } } } else { g_print("Option -s, --solver is mandatory.\n."); return -5; } /* Opens the source file for reading. */ fp = fopen(source, "r"); if (!fp) { g_print("Unable to open database resource for reading, file \"%s\" does not exist.\n", source); return -3; } /* Loads the game position database. */ db = gpdb_new(g_strdup(source)); syntax_error_log = NULL; error = NULL; gpdb_load(fp, source, db, &syntax_error_log, &error); fclose(fp); /* Compute the number of errors logged. */ number_of_errors = gpdb_syntax_error_log_length(syntax_error_log); if (number_of_errors != 0) { g_print("The database resource, file \"%s\" contains errors, debug it using the gpdb_verify utility.\n", source); return -4; } /* Lookup for a given key. */ if (lookup_entry) { entry = gpdb_lookup(db, lookup_entry); if (entry) { gchar *tmp = gpdb_entry_print(entry); g_print("%s", tmp); g_free(tmp); } else { g_print("Entry %s not found in file %s.\n", lookup_entry, source); return -6; } } else { g_print("No entry provided.\n"); return -7; } /* Initialize the board module. */ board_module_init(); /* Solving the position. */ GamePosition *gp = entry->game_position; ExactSolution *solution = NULL; g_print("Solving game position %s, from source %s, using solver %s ...\n", entry->id, source, solvers[solver_index]); switch (solver_index) { case 0: solution = game_position_solve(gp, log_file); break; case 1: solution = game_position_ifes_solve(gp, log_file); break; case 2: solution = game_position_random_sampler(gp, log_file, repeats); break; case 3: solution = game_position_minimax_solve(gp, log_file); break; case 4: solution = game_position_rab_solve(gp, log_file, repeats); break; case 5: solution = game_position_ab_solve(gp, log_file); break; default: g_print("This should never happen! solver_index = %d. Aborting ...\n", solver_index); return -9; } /* Printing results. */ gchar *solution_to_string = exact_solution_to_string(solution); printf("\n%s\n", solution_to_string); g_free(solution_to_string); /* Frees the resources. */ g_free(error); gpdb_free(db, TRUE); if (syntax_error_log) gpdb_syntax_error_log_free(syntax_error_log); g_option_context_free(context); g_free(source); exact_solution_free(solution); return 0; }
int main(int argc, char *args[]) { GtkApplication *application = gtk_application_new(NULL, 0); g_application_register(G_APPLICATION(application), NULL, NULL); struct capplication_handler *application_handler = alloc_application_handler(application); // Handle option context. GOptionEntry option_entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &application_handler->version, "Show the version of the program.", NULL }, { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &application_handler->file_name, "A file containing a matrix for sequence alignment.", NULL }, { "help", 'h', 0, G_OPTION_ARG_NONE, &application_handler->help, "Show this help description.", NULL }, {NULL} }; g_option_context_add_main_entries(application_handler->option_context, option_entries, _PROGRAM_NAME_); g_option_context_set_help_enabled(application_handler->option_context, TRUE); g_option_context_set_ignore_unknown_options(application_handler->option_context, TRUE); // Parse options. GError *error = NULL; gboolean context_result = FALSE; context_result = g_option_context_parse(application_handler->option_context, &argc, &args, &error); if (context_result) { if (application_handler->version) { g_printf("%s version %s.\n", _PROGRAM_NAME_, _PROGRAM_VERSION_); g_printf("Copyright © %s %s. All rights reserved.\n", _PROGRAM_YEAR_, _PROGRAM_AUTHOR_); } } else if (error) { printf("EE Failed to parser arguments.\n"); } g_option_context_free(application_handler->option_context); struct cwindow_handler *window_handler = alloc_window_handler(application_handler); if (gtk_application_prefers_app_menu(GTK_APPLICATION(application_handler->application))) { //gtk_application_set_app_menu(GTK_APPLICATION(application_handler->application), G_MENU_MODEL(window_handler->menu_model)); } gtk_application_add_window(GTK_APPLICATION(application_handler->application), GTK_WINDOW(window_handler->window)); gtk_widget_show_all(GTK_WIDGET(window_handler->window)); gtk_window_present(GTK_WINDOW(window_handler->window)); initialize_lua(window_handler, application_handler); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(window_handler->notebook), application_handler->tabs_position); gtk_widget_set_visible(GTK_WIDGET(window_handler->action_bar), application_handler->show_action_bar); //gtk_widget_set_visible(window_handler->menu_bar, application_handler->show_menu_bar); gtk_widget_set_visible(GTK_WIDGET(window_handler->search_and_replace_bar), FALSE); if (application_handler->file_name) { gint i = 0; while (application_handler->file_name[i]) { g_printf("MM Open file \"%s\".\n", application_handler->file_name[i]); FILE *file = fopen(application_handler->file_name[i], "r"); fseek(file, 0, SEEK_END); int size = ftell(file); char *text = (char *)malloc(sizeof(char) * size + 1); memset(text, 0, sizeof(char) * size + 1); fseek(file, 0, SEEK_SET); fread(text, sizeof(char), size, file); create_page(window_handler, application_handler->file_name[i], text); fclose(file); i++; } } update_editor(window_handler); gtk_main(); g_printf("MM Closing Lua state.\n"); lua_close(application_handler->lua); return 0; }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionContext *context = NULL; GFile *file; gchar *summary; int i; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); g_type_init (); /* Translators: this message will appear immediately after the */ /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ context = g_option_context_new (_("LOCATION... - concatenate LOCATIONS " "to standard output.")); /* Translators: this message will appear after the usage string */ /* and before the list of options. */ summary = g_strconcat (_("Concatenate files at locations and print to the " "standard output. Works just like the traditional " "cat utility, but using gvfs location instead " "local files: for example you can use something " "like smb://server/resource/file.txt as location " "to concatenate."), "\n\n", _("Note: just pipe through cat if you need its " "formatting option like -n, -T or other."), NULL); g_option_context_set_summary (context, summary); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); g_free (summary); if (error != NULL) { g_printerr (_("Error parsing commandline options: %s\n"), error->message); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); g_error_free(error); return 1; } if (!locations) { /* Translators: the %s is the program name. This error message */ /* means the user is calling gvfs-cat without any argument. */ g_printerr (_("%s: missing locations"), g_get_prgname ()); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } i = 0; do { file = g_file_new_for_commandline_arg (locations[i]); cat (file); g_object_unref (file); } while (locations[++i] != NULL); return 0; }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; int exit_status = EXIT_SUCCESS; GSList *list, *cnc_list = NULL; context = g_option_context_new ("[DSN|connection string]..."); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Can't parse arguments: %s\n", error->message); exit_status = EXIT_FAILURE; goto cleanup; } g_option_context_free (context); gda_init (); ask_pass = !ask_pass; config = g_new0 (HtmlConfig, 1); html_init_config (HTML_CONFIG (config)); config->index = html_file_new (HTML_CONFIG (config), "index.html", "Providers status"); config->dir = g_strdup ("."); /* parse command line arguments for connections */ if (argc > 1) { gint i; for (i = 1; i < argc; i++) { /* open connection */ GdaConnection *cnc; cnc = open_connection (argv[i], &error); if (!cnc) { g_print ("Can't open connection to '%s': %s\n", argv[i], error && error->message ? error->message : "No detail"); exit_status = EXIT_FAILURE; goto cleanup; } cnc_list = g_slist_append (cnc_list, cnc); } } else { if (getenv ("GDA_SQL_CNC")) { GdaConnection *cnc; cnc = open_connection (getenv ("GDA_SQL_CNC"), &error); if (!cnc) { g_print ("Can't open connection defined by GDA_SQL_CNC: %s\n", error && error->message ? error->message : "No detail"); exit_status = EXIT_FAILURE; goto cleanup; } cnc_list = g_slist_append (cnc_list, cnc); } else { /* report status for all providers */ GdaDataModel *providers; gint i, nb; providers = gda_config_list_providers (); nb = gda_data_model_get_n_rows (providers); for (i = 0; i < nb; i++) { GdaServerProvider *prov = NULL; const gchar *pname; const GValue *cvalue; cvalue = gda_data_model_get_value_at (providers, 0, i, &error); if (!cvalue) g_error ("Can't load next provider: %s\n", error && error->message ? error->message : "No detail"); pname = g_value_get_string (cvalue); prov = gda_config_get_provider (pname, &error); if (!prov) g_error ("Can't load the '%s' provider: %s\n", pname, error && error->message ? error->message : "No detail"); if (!report_provider_status (prov, NULL)) { exit_status = EXIT_FAILURE; goto cleanup; } } g_object_unref (providers); } } /* report provider's status for all the connections */ for (list = cnc_list; list; list = list->next) { if (!report_provider_status (NULL, GDA_CONNECTION (list->data))) { exit_status = EXIT_FAILURE; goto cleanup; } } g_slist_foreach (HTML_CONFIG (config)->all_files, (GFunc) html_file_write, config); /* cleanups */ cleanup: g_slist_foreach (cnc_list, (GFunc) g_object_unref, NULL); g_slist_free (cnc_list); return exit_status; }
/** * main: * @argc: default arguments * @argv: default arguments * * Parses the options, daemonizes, starts HKP, DBus and Avahi * * Returns: 0 on success */ int main(int argc, char* argv[]) { GOptionContext *octx = NULL; GError *error = NULL; seahorse_secure_memory_init (); octx = g_option_context_new (""); g_option_context_add_main_entries (octx, options, GETTEXT_PACKAGE); g_option_context_add_group (octx, egg_sm_client_get_option_group ()); if (!gtk_init_with_args (&argc, &argv, _("Encryption Daemon (Seahorse)"), (GOptionEntry *)options, GETTEXT_PACKAGE, &error)) { g_printerr ("seahorse-daemon: %s\n", error->message); g_error_free (error); exit (1); } g_signal_connect (egg_sm_client_get (), "quit", G_CALLBACK (smclient_quit), NULL); /* * All functions after this point have to print messages * nicely and not just called exit() */ daemonize (); /* Handle some signals */ seahorse_unix_signal_register (SIGINT, unix_signal); seahorse_unix_signal_register (SIGTERM, unix_signal); /* We log to the syslog */ prepare_logging (); /* Insert Icons into Stock */ seahorse_gtkstock_init (); /* Make the default SeahorseContext */ seahorse_context_new (SEAHORSE_CONTEXT_APP | SEAHORSE_CONTEXT_DAEMON); /* Load the various components */ seahorse_pgp_module_init (); seahorse_context_refresh_auto (NULL); /* Initialize the various daemon components */ seahorse_dbus_server_init (); /* Sometimes we've already gotten a quit signal */ if(!daemon_quit) { daemon_running = TRUE; gtk_main (); g_message ("left gtk_main\n"); } seahorse_dbus_server_cleanup (); g_option_context_free (octx); seahorse_context_destroy (SCTX_APP ()); return 0; }
int main(int argc, char *argv[]) { struct configuration conf= { NULL, NULL, NULL, 0 }; GError *error= NULL; GOptionContext *context; g_thread_init(NULL); init_mutex= g_mutex_new(); if(db == NULL && source_db != NULL){ db = g_strdup(source_db); } context= g_option_context_new("multi-threaded MySQL loader"); GOptionGroup *main_group= g_option_group_new("main", "Main Options", "Main Options", NULL, NULL); g_option_group_add_entries(main_group, entries); g_option_group_add_entries(main_group, common_entries); g_option_context_set_main_group(context, main_group); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print("option parsing failed: %s, try --help\n", error->message); exit(EXIT_FAILURE); } g_option_context_free(context); //prompt for password if it's NULL if ( sizeof(password) == 0 || ( password == NULL && askPassword ) ){ password = passwordPrompt(); } if (program_version) { g_print("myloader %s, built against MySQL %s\n", VERSION, MYSQL_VERSION_STR); exit(EXIT_SUCCESS); } set_verbose(verbose); if (!directory) { g_critical("a directory needs to be specified, see --help\n"); exit(EXIT_FAILURE); } else { char *p= g_strdup_printf("%s/metadata", directory); if (!g_file_test(p, G_FILE_TEST_EXISTS)) { g_critical("the specified directory is not a mydumper backup\n"); exit(EXIT_FAILURE); } } MYSQL *conn; conn= mysql_init(NULL); configure_connection(conn,"myloader"); if (!mysql_real_connect(conn, hostname, username, password, NULL, port, socket_path, 0)) { g_critical("Error connection to database: %s", mysql_error(conn)); exit(EXIT_FAILURE); } if (mysql_query(conn, "SET SESSION wait_timeout = 2147483")){ g_warning("Failed to increase wait_timeout: %s", mysql_error(conn)); } if (!enable_binlog) mysql_query(conn, "SET SQL_LOG_BIN=0"); mysql_query(conn, "/*!40014 SET FOREIGN_KEY_CHECKS=0*/"); conf.queue= g_async_queue_new(); conf.ready= g_async_queue_new(); guint n; GThread **threads= g_new(GThread*, num_threads); struct thread_data *td= g_new(struct thread_data, num_threads); for (n= 0; n < num_threads; n++) { td[n].conf= &conf; td[n].thread_id= n+1; threads[n]= g_thread_create((GThreadFunc)process_queue, &td[n], TRUE, NULL); g_async_queue_pop(conf.ready); } g_async_queue_unref(conf.ready); g_message("%d threads created", num_threads); restore_databases(&conf, conn); for (n= 0; n < num_threads; n++) { struct job *j= g_new0(struct job, 1); j->type = JOB_SHUTDOWN; g_async_queue_push(conf.queue, j); } for (n= 0; n < num_threads; n++) { g_thread_join(threads[n]); } restore_schema_post(conn); restore_schema_view(conn); restore_schema_triggers(conn); g_async_queue_unref(conf.queue); mysql_close(conn); mysql_thread_end(); mysql_library_end(); g_free(directory); g_free(td); g_free(threads); return errors ? EXIT_FAILURE : EXIT_SUCCESS; }
/** * main: **/ int main (int argc, char *argv[]) { gboolean ret; GError *error = NULL; GPtrArray *added_repos = NULL; GPtrArray *package_ids_recognised = NULL; GPtrArray *package_ids_to_install = NULL; guint i; guint retval = 0; gchar *package_id; gchar *name; gchar *name_debuginfo; gboolean simulate = FALSE; gboolean no_depends = FALSE; gboolean quiet = FALSE; gboolean noninteractive = FALSE; GOptionContext *context; const gchar *repo_id; gchar *repo_id_debuginfo; PkDebuginfoInstallPrivate *priv = NULL; guint step = 1; const GOptionEntry options[] = { { "simulate", 's', 0, G_OPTION_ARG_NONE, &simulate, /* command line argument, simulate what would be done, but don't actually do it */ _("Don't actually install any packages, only simulate what would be installed"), NULL }, { "no-depends", 'n', 0, G_OPTION_ARG_NONE, &no_depends, /* command line argument, do we skip packages that depend on the ones specified */ _("Do not install dependencies of the core packages"), NULL }, { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, /* command line argument, do we operate quietly */ _("Do not display information or progress"), NULL }, { "noninteractive", 'y', 0, G_OPTION_ARG_NONE, &noninteractive, /* command line argument, do we ask questions */ _("Install the packages without asking for confirmation"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 31) if (! g_thread_supported ()) g_thread_init (NULL); #endif #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35) g_type_init (); #endif context = g_option_context_new (NULL); /* TRANSLATORS: tool that gets called when the command is not found */ g_option_context_set_summary (context, _("PackageKit Debuginfo Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, pk_debug_get_option_group ()); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* new private struct */ priv = g_new0 (PkDebuginfoInstallPrivate, 1); /* no input */ if (argv[1] == NULL) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: the use needs to specify a list of package names on the command line */ g_print (_("ERROR: Specify package names to install.")); g_print ("\n"); } /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED; goto out; } /* store as strings */ priv->enabled = g_ptr_array_new (); priv->disabled = g_ptr_array_new (); added_repos = g_ptr_array_new (); package_ids_to_install = g_ptr_array_new (); package_ids_recognised = g_ptr_array_new (); /* create #PkClient */ priv->client = PK_CLIENT(pk_task_text_new ()); /* we are not asking questions, so it's pointless simulating */ if (noninteractive) { g_object_set (priv->client, "simulate", FALSE, NULL); } /* use text progressbar */ priv->progress_bar = pk_progress_bar_new (); pk_progress_bar_set_size (priv->progress_bar, 25); pk_progress_bar_set_padding (priv->progress_bar, 60); /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we are getting the list of repositories */ g_print (_("Getting sources list")); g_print ("..."); } /* get all enabled repos */ ret = pk_debuginfo_install_get_repo_list (priv, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: we're failed to enable the sources, detailed error follows */ g_print ("Failed to enable sources list: %s", error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_ENABLE; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user what we found */ g_print (_("Found %i enabled and %i disabled sources."), priv->enabled->len, priv->disabled->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're finding repositories that match out pattern */ g_print (_("Finding debugging sources")); g_print ("..."); } /* find all debuginfo repos for repos that are enabled */ for (i=0; i<priv->enabled->len; i++) { /* is already a -debuginfo */ repo_id = g_ptr_array_index (priv->enabled, i); if (g_str_has_suffix (repo_id, "-debuginfo")) { g_debug ("already enabled: %s", repo_id); continue; } /* has a debuginfo repo */ repo_id_debuginfo = g_strjoin ("-", repo_id, "debuginfo", NULL); ret = pk_debuginfo_install_in_array (priv->disabled, repo_id_debuginfo); if (ret) { /* add to list to change back at the end */ g_ptr_array_add (added_repos, g_strdup (repo_id_debuginfo)); } else { g_debug ("no debuginfo repo for %s", repo_id_debuginfo); } g_free (repo_id_debuginfo); } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user what we found */ g_print (_("Found %i disabled debuginfo repos."), added_repos->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're now enabling all the debug sources we found */ g_print (_("Enabling debugging sources")); g_print ("..."); } /* enable all debuginfo repos we found */ ret = pk_debuginfo_install_enable_repos (priv, added_repos, TRUE, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: we're failed to enable the sources, detailed error follows */ g_print ("Failed to enable debugging sources: %s", error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_ENABLE; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user how many we enabled */ g_print (_("Enabled %i debugging sources."), added_repos->len); g_print ("\n"); /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we're now finding packages that match in all the repos */ g_print (_("Finding debugging packages")); g_print ("..."); } /* parse arguments and resolve to packages */ for (i=1; argv[i] != NULL; i++) { name = pk_get_package_name_from_nevra (argv[i]); /* resolve name */ package_id = pk_debuginfo_install_resolve_name_to_id (priv, name, &error); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the package name, non-fatal */ g_print (_("Failed to find the package %s: %s"), name, error->message); g_print ("\n"); g_error_free (error); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL) { g_debug ("going to try to install: %s", package_id); g_ptr_array_add (package_ids_recognised, package_id); } else { goto not_found; } /* convert into basename */ name_debuginfo = pk_debuginfo_install_name_to_debuginfo (name); g_debug ("install %s [%s]", argv[i], name_debuginfo); /* resolve name */ package_id = pk_debuginfo_install_resolve_name_to_id (priv, name_debuginfo, &error); if (package_id == NULL) { /* TRANSLATORS: we couldn't find the debuginfo package name, non-fatal */ g_print (_("Failed to find the debuginfo package %s: %s"), name_debuginfo, error->message); g_print ("\n"); g_error_free (error); /* don't quit, this is non-fatal */ error = NULL; } /* add to array to install */ if (package_id != NULL && !g_str_has_suffix (package_id, "installed")) { g_debug ("going to try to install: %s", package_id); g_ptr_array_add (package_ids_to_install, g_strdup (package_id)); } g_free (name_debuginfo); not_found: g_free (package_id); g_free (name); } /* no packages? */ if (package_ids_to_install->len == 0) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: no debuginfo packages could be found to be installed */ g_print (_("Found no packages to install.")); g_print ("\n"); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_NOTHING_TO_DO; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: tell the user we found some packages, and then list them */ g_print (_("Found %i packages:"), package_ids_to_install->len); g_print ("\n"); } /* optional */ if (!no_depends) { /* save for later logic */ i = package_ids_to_install->len; /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: tell the user we are searching for deps */ g_print (_("Finding packages that depend on these packages")); g_print ("..."); } ret = pk_debuginfo_install_add_deps (priv, package_ids_recognised, package_ids_to_install, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: could not install, detailed error follows */ g_print (_("Could not find dependent packages: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_FIND_DEPS; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); if (i < package_ids_to_install->len) { /* TRANSLATORS: tell the user we found some more packages */ g_print (_("Found %i extra packages."), package_ids_to_install->len - i); g_print ("\n"); } else { /* TRANSLATORS: tell the user we found some more packages */ g_print (_("No extra packages required.")); g_print ("\n"); } } } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: tell the user we found some packages (and deps), and then list them */ g_print (_("Found %i packages to install:"), package_ids_to_install->len); g_print ("\n"); } /* print list */ if (!quiet) pk_debuginfo_install_print_array (package_ids_to_install); /* simulate mode for testing */ if (simulate) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: simulate mode is a testing mode where we quit before the action */ g_print (_("Not installing packages in simulate mode")); g_print ("\n"); } goto out; } /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step++); /* TRANSLATORS: we are now installing the debuginfo packages we found earlier */ g_print (_("Installing packages")); g_print ("...\n"); } /* install */ ret = pk_debuginfo_install_packages_install (priv, package_ids_to_install, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: could not install, detailed error follows */ g_print (_("Could not install packages: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_INSTALL; goto out; } /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print (_("OK.")); g_print ("\n"); } out: if (package_ids_to_install != NULL) { g_ptr_array_foreach (package_ids_to_install, (GFunc) g_free, NULL); g_ptr_array_free (package_ids_to_install, TRUE); } if (package_ids_recognised != NULL) { g_ptr_array_foreach (package_ids_recognised, (GFunc) g_free, NULL); g_ptr_array_free (package_ids_recognised, TRUE); } if (added_repos != NULL) { /* should be vocal? */ if (!quiet) { /* starting this section */ g_print ("%i. ", step); /* TRANSLATORS: we are now disabling all debuginfo repos we previously enabled */ g_print (_("Disabling sources previously enabled")); g_print ("..."); } /* disable all debuginfo repos we previously enabled */ ret = pk_debuginfo_install_enable_repos (priv, added_repos, FALSE, &error); if (!ret) { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: operation was not successful */ g_print ("%s ", _("FAILED.")); } /* TRANSLATORS: no debuginfo packages could be found to be installed, detailed error follows */ g_print (_("Could not disable the debugging sources: %s"), error->message); g_print ("\n"); g_error_free (error); /* return correct failure retval */ retval = PK_DEBUGINFO_EXIT_CODE_FAILED_TO_DISABLE; } else { /* should be vocal? */ if (!quiet) { /* TRANSLATORS: all completed 100% */ g_print ("%s ", _("OK.")); /* TRANSLATORS: we disabled all the debugging repos that we enabled before */ g_print (_("Disabled %i debugging sources."), added_repos->len); g_print ("\n"); } } g_ptr_array_foreach (added_repos, (GFunc) g_free, NULL); g_ptr_array_free (added_repos, TRUE); } if (priv->enabled != NULL) { g_ptr_array_foreach (priv->enabled, (GFunc) g_free, NULL); g_ptr_array_free (priv->enabled, TRUE); } if (priv->disabled != NULL) { g_ptr_array_foreach (priv->disabled, (GFunc) g_free, NULL); g_ptr_array_free (priv->disabled, TRUE); } if (priv->client != NULL) g_object_unref (priv->client); if (priv->progress_bar != NULL) g_object_unref (priv->progress_bar); g_free (priv); return retval; }
int main(int argc, char **argv) { if (argc == 2 && 0 == g_strcmp0(argv[1], "-d")) g_setenv("G_MESSAGES_DEBUG", "all", FALSE); GOptionContext *context = g_option_context_new("- Deepin Installer"); g_option_context_add_main_entries(context, entries, "INSTALLER"); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, NULL)) { g_warning ("context parse failed\n"); } if (auto_conf_path != NULL && !g_file_test(auto_conf_path, G_FILE_TEST_IS_REGULAR)) { g_warning("the configure is valid: %s", auto_conf_path); exit(1); } g_option_context_free(context); redirect_log(log_path); gtk_init (&argc, &argv); setlocale(LC_MESSAGES, ""); textdomain("INSTALLER"); if (geteuid () != 0) { g_warning ("must run installer as root\n"); exit (0); } if (installer_is_running ()) { g_warning ("another instance of installer is running\n"); exit (0); } signal (SIGTERM, sigterm_cb); signal (SIGINT, sigterm_cb); signal (SIGQUIT, sigterm_cb); signal (SIGKILL, sigterm_cb); signal (SIGTSTP, sigterm_cb); installer_container = create_web_container (FALSE, TRUE); gtk_window_set_decorated (GTK_WINDOW (installer_container), FALSE); GtkWidget *webview = d_webview_new_with_uri (INSTALLER_HTML_PATH); g_signal_connect (webview, "draw", G_CALLBACK (erase_background), NULL); gtk_container_add (GTK_CONTAINER (installer_container), GTK_WIDGET (webview)); WebKitWebSettings *setting = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview)); g_object_set(G_OBJECT(setting), "enable-default-context-menu", FALSE, NULL); if (nowm) { fix_without_wm(webview); } else { g_signal_connect (installer_container, "button-press-event", G_CALLBACK (move_window), NULL); gtk_window_set_position (GTK_WINDOW (installer_container), GTK_WIN_POS_CENTER); } gtk_window_set_default_size (GTK_WINDOW (installer_container), INSTALLER_WIN_WIDTH, INSTALLER_WIN_HEIGHT); gtk_window_set_resizable (GTK_WINDOW (installer_container), FALSE); GdkGeometry geometry; geometry.min_width = INSTALLER_WIN_WIDTH; geometry.max_width = INSTALLER_WIN_WIDTH; geometry.base_width = INSTALLER_WIN_WIDTH; geometry.min_height = INSTALLER_WIN_HEIGHT; geometry.max_height = INSTALLER_WIN_HEIGHT; geometry.base_height = INSTALLER_WIN_HEIGHT; gtk_window_set_geometry_hints (GTK_WINDOW (installer_container), webview, &geometry, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE); gtk_widget_show_all (installer_container); /*#ifndef NDEBUG*/ /*monitor_resource_file("installer", webview);*/ /*#endif*/ gtk_main (); return 0; }
gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *policy_name; gs_unref_object GFile *subpath = NULL; const char *prefix = NULL; gs_unref_object OstreeSePolicy *sepolicy = NULL; gs_unref_ptrarray GPtrArray *deployments = NULL; OstreeDeployment *first_deployment; GOptionContext *context = NULL; gs_unref_object OstreeSysroot *sysroot = NULL; gs_unref_object GFile *deployment_path = NULL; context = g_option_context_new ("[SUBPATH PREFIX] - relabel all or part of a deployment"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_load (sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); if (deployments->len == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); goto out; } first_deployment = deployments->pdata[0]; deployment_path = ostree_sysroot_get_deployment_directory (sysroot, first_deployment); if (argc >= 2) { subpath = g_file_new_for_path (argv[1]); prefix = argv[2]; } else { subpath = g_object_ref (deployment_path); prefix = ""; } sepolicy = ostree_sepolicy_new (deployment_path, cancellable, error); if (!sepolicy) goto out; policy_name = ostree_sepolicy_get_name (sepolicy); if (policy_name) { g_print ("Relabeling using policy '%s'\n", policy_name); if (!selinux_relabel_dir (sepolicy, subpath, prefix, cancellable, error)) goto out; } else g_print ("No SELinux policy found in deployment '%s'\n", gs_file_get_path_cached (deployment_path)); ret = TRUE; out: if (context) g_option_context_free (context); return ret; }