static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_file_type ) { //gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); gchar *safe_user = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "username")->s ); gchar *safe_pass = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "password")->s ); gdouble lat, lon; if ( 2 != sscanf ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ), "%lf,%lf", &lat, &lon ) ) { g_warning (_("Broken input - using some defaults")); lat = a_vik_get_default_lat(); lon = a_vik_get_default_long(); } // Unix specific shell commands // 1. Remove geocache webpages (maybe be from different location) // 2, Gets upto n geocaches as webpages for the specified user in radius r Miles // 3. Converts webpages into a single waypoint file, ignoring zero location waypoints '-z' // Probably as they are premium member only geocaches and user is only a basic member // Final output is piped into GPSbabel - hence removal of *html is done at beginning of the command sequence *cmd = g_strdup_printf( "rm -f ~/.geo/caches/*html ; %s -P -n%d -r%.1fM -u %s -p %s %.4f %.4f ; %s -z ~/.geo/caches/*html ", GC_PROGRAM1, gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ), gtk_spin_button_get_value_as_float ( GTK_SPIN_BUTTON(widgets->miles_radius_spin) ), safe_user, safe_pass, lat, lon, GC_PROGRAM2 ); *input_file_type = NULL; //g_free ( safe_string ); g_free ( safe_user ); g_free ( safe_pass ); }
static void extract_to_callback (NautilusMenuItem *item, gpointer user_data) { GList *files; NautilusFileInfo *file; char *uri, *default_dir; GString *cmd; files = g_object_get_data (G_OBJECT (item), "files"); file = files->data; uri = nautilus_file_info_get_uri (file); default_dir = nautilus_file_info_get_parent_uri (file); cmd = g_string_new ("file-roller"); g_string_append_printf (cmd, " --default-dir=%s --extract %s", g_shell_quote (default_dir), g_shell_quote (uri)); #ifdef DEBUG g_print ("EXEC: %s\n", cmd->str); #endif g_spawn_command_line_async (cmd->str, NULL); g_string_free (cmd, TRUE); g_free (default_dir); g_free (uri); }
static void extract_backup_dirs (const gchar *filename, gchar **data_dir, gchar **config_dir) { GKeyFile *key_file; GError *error = NULL; g_return_if_fail (filename != NULL); g_return_if_fail (data_dir != NULL); g_return_if_fail (config_dir != NULL); key_file = g_key_file_new (); g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &error); if (error) { g_warning ("Failed to read '%s': %s", filename, error->message); g_error_free (error); } else { gchar *tmp; tmp = g_key_file_get_value (key_file, "dirs", "data", NULL); if (tmp) *data_dir = g_shell_quote (tmp); g_free (tmp); tmp = g_key_file_get_value (key_file, "dirs", "config", NULL); if (tmp) *config_dir = g_shell_quote (tmp); g_free (tmp); } g_key_file_free (key_file); }
GAppInfo *gen_app_info (const char* executable, GAppInfoCreateFlags flags) { GAppInfo *appinfo = NULL; GError* error = NULL; char* cmd_line = NULL; if (executable == NULL) { char* tmp1 = g_shell_quote(DESKTOP_DIR()); char* tmp2 = g_strdup_printf("cd %s && exec $SHELL", tmp1); g_free(tmp1); tmp1 = g_shell_quote(tmp2); g_free(tmp2); cmd_line = g_strconcat("sh -c ", tmp1, NULL); g_free(tmp1); } else { cmd_line = g_strdup(executable); } appinfo = g_app_info_create_from_commandline(cmd_line, NULL, flags, &error); g_free(cmd_line); if (error!=NULL) { g_debug("gen_app_info error: %s", error->message); g_error_free(error); return NULL; } error = NULL; return appinfo; }
static void pdf_set_metainfo(const gchar* filename, GData* metainfo) { gchar tempfile[] = "/tmp/metainfo-XXXXXX"; int fd = mkstemp(tempfile); if (fd < 0) return; // error FILE* f = fdopen(fd, "w"); g_datalist_foreach(&metainfo, print_metainfo, f); fclose(f); gchar* cmdline; { gchar* qf = g_shell_quote(filename); gchar* cmd = g_strdup_printf("set-meta %s; save", tempfile); gchar* qc = g_shell_quote(cmd); g_free(cmd); // "pdftk %s update_info %s output %s", filename, tempfile, new cmdline = g_strdup_printf("djvused %s -e %s", qf, qc); g_free(qf); g_free(qc); } system(cmdline); /* os.unlink(filename) os.rename(new, filename) */ }
static void datasource_google_get_cmd_string ( datasource_google_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ) { /* TODO: special characters handling!!! */ gchar *from_quoted, *to_quoted; gchar **from_split, **to_split; from_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) ) ); to_quoted = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) ) ); from_split = g_strsplit( from_quoted, " ", 0); to_split = g_strsplit( to_quoted, " ", 0); from_quoted = g_strjoinv( "%20", from_split); to_quoted = g_strjoinv( "%20", to_split); *cmd = g_strdup_printf( GOOGLE_DIRECTIONS_STRING, from_quoted, to_quoted ); *input_file_type = g_strdup("google"); options = NULL; g_free(last_from_str); g_free(last_to_str); last_from_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->from_entry) )); last_to_str = g_strdup( gtk_entry_get_text ( GTK_ENTRY(widgets->to_entry) )); g_free(from_quoted); g_free(to_quoted); g_strfreev(from_split); g_strfreev(to_split); }
static void add_callback (NautilusMenuItem *item, gpointer user_data) { GList *files, *scan; NautilusFileInfo *file; char *uri, *dir; GString *cmd; files = g_object_get_data (G_OBJECT (item), "files"); file = files->data; uri = nautilus_file_info_get_uri (file); dir = g_path_get_dirname (uri); cmd = g_string_new ("file-roller"); g_string_append (cmd, " --notify"); g_string_append_printf (cmd," --default-dir=%s", g_shell_quote (dir)); g_string_append (cmd," --add"); g_free (dir); g_free (uri); for (scan = files; scan; scan = scan->next) { NautilusFileInfo *file = scan->data; uri = nautilus_file_info_get_uri (file); g_string_append_printf (cmd, " %s", g_shell_quote (uri)); g_free (uri); } g_spawn_command_line_async (cmd->str, NULL); g_string_free (cmd, TRUE); }
/** * @param format The format string used. See below for possible syntax. * @param string The selected entry. * @param selected_line The selected line index. * @param filter The entered filter. * * Function that outputs the selected line in the user-specified format. * Currently the following formats are supported: * * i: Print the index (0-(N-1)) * * d: Print the index (1-N) * * s: Print input string. * * q: Print quoted input string. * * f: Print the entered filter. * * F: Print the entered filter, quoted * * This functions outputs the formatted string to stdout, appends a newline (\n) character and * calls flush on the file descriptor. */ static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter ) { for ( int i = 0; format && format[i]; i++ ) { if ( format[i] == 'i' ) { fprintf ( stdout, "%d", selected_line ); } else if ( format[i] == 'd' ) { fprintf ( stdout, "%d", ( selected_line + 1 ) ); } else if ( format[i] == 's' ) { fputs ( string, stdout ); } else if ( format[i] == 'q' ) { char *quote = g_shell_quote ( string ); fputs ( quote, stdout ); g_free ( quote ); } else if ( format[i] == 'f' ) { fputs ( filter, stdout ); } else if ( format[i] == 'F' ) { char *quote = g_shell_quote ( filter ); fputs ( quote, stdout ); g_free ( quote ); } else { fputc ( format[i], stdout ); } } fputc ( '\n', stdout ); fflush ( stdout ); }
static void extract_backup_data (const gchar *filename, gchar **restored_version, gchar **data_dir, gchar **config_dir) { GKeyFile *key_file; GError *error = NULL; g_return_if_fail (filename != NULL); g_return_if_fail (data_dir != NULL); g_return_if_fail (config_dir != NULL); key_file = g_key_file_new (); g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &error); if (error != NULL) { g_warning ("Failed to read '%s': %s", filename, error->message); g_error_free (error); /* This is the current format as of Evolution 3.6. */ } else if (g_key_file_has_group (key_file, KEY_FILE_GROUP)) { gchar *tmp; tmp = g_key_file_get_value ( key_file, KEY_FILE_GROUP, "Version", NULL); if (tmp != NULL) *restored_version = g_strstrip (g_strdup (tmp)); g_free (tmp); tmp = g_key_file_get_value ( key_file, KEY_FILE_GROUP, "UserDataDir", NULL); if (tmp != NULL) *data_dir = g_shell_quote (tmp); g_free (tmp); tmp = g_key_file_get_value ( key_file, KEY_FILE_GROUP, "UserConfigDir", NULL); if (tmp != NULL) *config_dir = g_shell_quote (tmp); g_free (tmp); /* This is the legacy format with no version information. */ } else if (g_key_file_has_group (key_file, "dirs")) { gchar *tmp; tmp = g_key_file_get_value (key_file, "dirs", "data", NULL); if (tmp) *data_dir = g_shell_quote (tmp); g_free (tmp); tmp = g_key_file_get_value (key_file, "dirs", "config", NULL); if (tmp) *config_dir = g_shell_quote (tmp); g_free (tmp); } g_key_file_free (key_file); }
static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_bin, const char* iface, const char* cfilter, unsigned long int count) { gchar* cmdline; ssh_channel channel; char* quoted_bin; char* quoted_iface; char* default_filter; char* quoted_filter; char* count_str = NULL; unsigned int remote_port = 22; if (!capture_bin) capture_bin = DEFAULT_CAPTURE_BIN; if (!iface) iface = "eth0"; channel = ssh_channel_new(sshs); if (!channel) return NULL; if (ssh_channel_open_session(channel) != SSH_OK) { ssh_channel_free(channel); return NULL; } ssh_options_get_port(sshs, &remote_port); /* escape parameters to go save with the shell */ quoted_bin = g_shell_quote(capture_bin); quoted_iface = g_shell_quote(iface); default_filter = local_interfaces_to_filter(remote_port); if (!cfilter) cfilter = default_filter; quoted_filter = g_shell_quote(cfilter); if (count > 0) count_str = g_strdup_printf("-c %lu", count); cmdline = g_strdup_printf("%s -i %s -P -w - -f %s %s", quoted_bin, quoted_iface, quoted_filter, count_str ? count_str : ""); verbose_print("Running: %s\n", cmdline); if (ssh_channel_request_exec(channel, cmdline) != SSH_OK) { ssh_channel_close(channel); ssh_channel_free(channel); channel = NULL; } g_free(quoted_bin); g_free(quoted_iface); g_free(default_filter); g_free(quoted_filter); g_free(cmdline); if (count_str) g_free(count_str); return channel; }
gboolean xfce_volstatus_remove_drive(GHalDrive *drive) { GList *volumes, *l; gboolean ret = TRUE; GError *error = NULL; gint exit_status = 0; g_return_val_if_fail(GHAL_IS_DRIVE(drive), FALSE); volumes = ghal_drive_list_volumes(drive); for(l = volumes; l; l = l->next) { GHalVolume *volume = l->data; if(ghal_volume_is_mounted(volume)) { gchar *udi_quoted = g_shell_quote(ghal_device_peek_udi(GHAL_DEVICE(volume))); gchar *cmd = g_strdup_printf("exo-unmount -n -u -h %s", udi_quoted); ret = g_spawn_command_line_sync(cmd, NULL, NULL, &exit_status, &error); g_free(udi_quoted); g_free(cmd); if(!ret || exit_status) break; } } g_list_foreach(volumes, (GFunc)g_object_unref, NULL); g_list_free(volumes); if(ghal_drive_requires_eject(drive)) { gchar *udi_quoted = g_shell_quote(ghal_device_peek_udi(GHAL_DEVICE(drive))); gchar *cmd = g_strdup_printf("exo-eject -n -e -h %s", udi_quoted); ret = g_spawn_command_line_sync(cmd, NULL, NULL, &exit_status, &error); g_free(udi_quoted); g_free(cmd); } if(!ret) { gchar *name = ghal_drive_get_display_name(drive); gchar *primary = g_strdup_printf(_("Unable to remove \"%s\""), name); xfce_message_dialog(NULL, _("Removal Failure"), GTK_STOCK_DIALOG_WARNING, primary, error ? error->message : _("Unknown error"), GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); g_free(name); g_free(primary); if(error) g_error_free(error); } return ret; }
static gboolean launch_previewer (void) { GString *cmd_str; gchar *cmd; gboolean retval = FALSE; GError *error = NULL; /* Rebuild the command line, ignoring options * not supported by the previewer and taking only * the first path given */ cmd_str = g_string_new ("evince-previewer"); if (print_settings) { gchar *quoted; quoted = g_shell_quote (print_settings); g_string_append_printf (cmd_str, " --print-settings %s", quoted); g_free (quoted); } if (unlink_temp_file) g_string_append (cmd_str, " --unlink-tempfile"); if (file_arguments) { gchar *quoted; quoted = g_shell_quote (file_arguments[0]); g_string_append_printf (cmd_str, " %s", quoted); g_free (quoted); } cmd = g_string_free (cmd_str, FALSE); if (!error) { GAppInfo *app; app = g_app_info_create_from_commandline (cmd, NULL, 0, &error); if (app != NULL) { retval = g_app_info_launch (app, NULL, NULL, &error); g_object_unref (app); } } if (error) { g_warning ("Error launching previewer: %s\n", error->message); g_error_free (error); } g_free (cmd); return retval; }
static gboolean launch_previewer (void) { GString *cmd_str; gchar *cmd; gint argc; gchar **argv; gboolean retval = FALSE; GError *error = NULL; /* Rebuild the command line, ignoring options * not supported by the previewer and taking only * the first path given */ cmd_str = g_string_new ("atril-previewer"); if (print_settings) { gchar *quoted; quoted = g_shell_quote (print_settings); g_string_append_printf (cmd_str, " --print-settings %s", quoted); g_free (quoted); } if (unlink_temp_file) g_string_append (cmd_str, " --unlink-tempfile"); if (file_arguments) { gchar *quoted; quoted = g_shell_quote (file_arguments[0]); g_string_append_printf (cmd_str, " %s", quoted); g_free (quoted); } cmd = g_string_free (cmd_str, FALSE); g_shell_parse_argv (cmd, &argc, &argv, &error); g_free (cmd); if (!error) { retval = gdk_spawn_on_screen (gdk_screen_get_default (), NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error); g_strfreev (argv); } if (error) { g_warning ("Error launching previewer: %s\n", error->message); g_error_free (error); } return retval; }
void xa_tar_add (XArchive *archive, GSList *file_list, gchar *compression) { GString *files; gchar *command; if (archive->location_path != NULL) archive->child_dir = g_strdup(archive->working_dir); files = xa_quote_filenames(file_list, NULL, TRUE); if (!g_file_test(archive->path[0], G_FILE_TEST_EXISTS)) { if (archive->type == XARCHIVETYPE_TAR) archive->path[2] = g_shell_quote(archive->path[0]); else { gchar *workfile; if (!xa_create_working_directory(archive)) { g_string_free(files, TRUE); return; } workfile = g_strconcat(archive->working_dir, "/xa-tmp.tar", NULL); archive->path[2] = g_shell_quote(workfile); g_free(workfile); } command = g_strconcat(archiver[XARCHIVETYPE_TAR].program[0], " -c --no-recursion --no-wildcards", archive->do_move ? " --remove-files" : "", " -f ", archive->path[2], files->str, NULL); } else command = g_strconcat(archiver[XARCHIVETYPE_TAR].program[0], archive->do_update ? " -u" : " -r", " --no-recursion --no-wildcards", archive->do_move ? " --remove-files" : "", " -f ", archive->path[2], files->str, NULL); if (archive->type != XARCHIVETYPE_TAR) { xa_run_command(archive, command); g_free(command); command = xa_gzip_et_al_get_command(archiver[xa_tar_get_compressor_type(archive)].program[0], archive->path[2], archive->path[0], archive->password, xa_tar_get_compressor_type(archive)); } g_string_free(files, TRUE); xa_run_command(archive, command); g_free(command); }
char * ve_shell_quote_filename (const char *name) { if (name[0] != '-') { return g_shell_quote (name); } else { char *fname = g_strconcat ("./", name, NULL); char *quoted = g_shell_quote (fname); g_free (fname); return quoted; } }
RESULT test_quote () { if (strcmp (g_shell_quote ("foo"), "'foo'")) return FAILED ("Should return 'foo'"); if (strcmp (g_shell_quote ("foo'bar"), "'foo'\\''bar'")) return FAILED ("Should return 'foo'\\''bar'"); if (strcmp (g_shell_quote ("foo bar"), "'foo bar'")) return FAILED ("Should return 'foo bar'"); return OK; }
/** * sokoke_prepare_command: * @command: the command, properly quoted * @argument: any arguments, properly quoted * @quote_command: if %TRUE, @command will be quoted * @quote_argument: if %TRUE, @argument will be quoted, ie. a URI or filename * * If @command contains %s, @argument will be quoted and inserted into * @command, which is left unquoted regardless of @quote_command. * * Return value: the command prepared for spawning **/ gchar* sokoke_prepare_command (const gchar* command, gboolean quote_command, const gchar* argument, gboolean quote_argument) { g_return_val_if_fail (command != NULL, FALSE); g_return_val_if_fail (argument != NULL, FALSE); if (midori_debug ("paths")) g_print ("Preparing command: %s %d %s %d\n", command, quote_command, argument, quote_argument); { gchar* uri_format; gchar* real_command; gchar* command_ready; /* .desktop files accept %u, %U, %f, %F as URI/ filename, we treat it like %s */ real_command = g_strdup (command); if ((uri_format = strstr (real_command, "%u")) || (uri_format = strstr (real_command, "%U")) || (uri_format = strstr (real_command, "%f")) || (uri_format = strstr (real_command, "%F"))) uri_format[1] = 's'; if (strstr (real_command, "%s")) { gchar* argument_quoted = quote_argument ? g_shell_quote (argument) : g_strdup (argument); command_ready = g_strdup_printf (real_command, argument_quoted); g_free (argument_quoted); } else if (quote_argument) { gchar* quoted_command = quote_command ? g_shell_quote (real_command) : g_strdup (real_command); gchar* argument_quoted = g_shell_quote (argument); command_ready = g_strconcat (quoted_command, " ", argument_quoted, NULL); g_free (argument_quoted); g_free (quoted_command); } else { gchar* quoted_command = quote_command ? g_shell_quote (real_command) : g_strdup (real_command); command_ready = g_strconcat (quoted_command, " ", argument, NULL); g_free (quoted_command); } g_free (real_command); return command_ready; } }
static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data ) { // TODO quoting is not right? Find description not very clear, need to check. struct RegexEvalArg *e = (struct RegexEvalArg *) data; gchar *match; // Get the match match = g_match_info_fetch ( info, 0 ); if ( match != NULL ) { switch ( match[1] ) { // Unsupported case 'f': case 'F': case 'u': case 'U': case 'i': // Deprecated case 'd': case 'D': case 'n': case 'N': case 'v': case 'm': break; case 'k': if ( e->e->path ) { char *esc = g_shell_quote ( e->e->path ); g_string_append ( res, esc ); g_free ( esc ); } break; case 'c': if ( e->e->name ) { char *esc = g_shell_quote ( e->e->name ); g_string_append ( res, esc ); g_free ( esc ); } break; // Invalid, this entry should not be processed -> throw error. default: e->success = FALSE; g_free ( match ); return TRUE; } g_free ( match ); } // Continue replacement. return FALSE; }
static void link_button_clicked_cb (GtkWidget *widget, LmplayerObject *lmplayer) { const char *uri; char *command, *browser, *escaped_uri; GError *error = NULL; uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (widget)); escaped_uri = g_shell_quote (uri); browser = gconf_client_get_string (lmplayer->gc, "/desktop/gnome/url-handlers/http/command", NULL); if (browser == NULL || browser[0] == '\0') { char *message; message = g_strdup_printf(_("Could not launch URL \"%s\": %s"), uri, _("Default browser not configured")); //lmplayer_interface_error (_("Error launching URI"), message, GTK_WINDOW (lmplayer->win)); g_free (message); } else { char *message; command = g_strdup_printf (browser, escaped_uri); if (g_spawn_command_line_async ((const char*) command, &error) == FALSE) { message = g_strdup_printf(_("Could not launch URL \"%s\": %s"), uri, error->message); //lmplayer_interface_error (_("Error launching URI"), message, GTK_WINDOW (lmplayer->win)); g_free (message); g_error_free (error); } g_free (command); } g_free (escaped_uri); g_free (browser); }
static char * try_terminal_command_argv (int argc, char **argv) { GString *string; int i; char *quoted, *result; if (argc == 0) { return NULL; } if (argc == 1) { return try_terminal_command (argv[0], NULL); } string = g_string_new (argv[1]); for (i = 2; i < argc; i++) { quoted = g_shell_quote (argv[i]); g_string_append_c (string, ' '); g_string_append (string, quoted); g_free (quoted); } result = try_terminal_command (argv[0], string->str); g_string_free (string, TRUE); return result; }
static gchar * _str_join_argv (gchar **argv) { GString *str_builder = g_string_new (""); gboolean first = TRUE; while (argv && *argv) { if (!first) g_string_append_c (str_builder, ' '); else first = FALSE; if (_shell_arg_need_quote (*argv)) { gchar *quoted = g_shell_quote (*argv); g_string_append (str_builder, quoted); g_free (quoted); } else { g_string_append (str_builder, *argv); } argv++; } return g_string_free (str_builder, FALSE); }
static void append_file_to_cmd(GFile* gf, GString* cmd) { char* file = g_file_get_path(gf); char* quote; if(file == NULL) /* trash:// gvfs is incomplete in resolving it */ { /* we can retrieve real path from GVFS >= 1.13.3 */ if(g_file_has_uri_scheme(gf, "trash")) { GFileInfo *inf; const char *orig_path; inf = g_file_query_info(gf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, G_FILE_QUERY_INFO_NONE, NULL, NULL); if(inf == NULL) /* failed */ return; orig_path = g_file_info_get_attribute_string(inf, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); if(orig_path != NULL) /* success */ file = g_filename_from_uri(orig_path, NULL, NULL); g_object_unref(inf); } if(file == NULL) return; } quote = g_shell_quote(file); g_string_append(cmd, quote); g_string_append_c(cmd, ' '); g_free(quote); g_free(file); }
void desktop_run_in_terminal(char* executable) { gboolean is_ok = FALSE; GSettings* s = g_settings_new("com.deepin.desktop.default-applications.terminal"); if (s != NULL) { char* terminal = g_settings_get_string(s, "exec"); g_object_unref(s); if (terminal != NULL && terminal[0] != '\0') { char* quoted_dir = g_shell_quote(DESKTOP_DIR()); char* exec = NULL; exec = g_strdup_printf("sh -c 'cd %s && %s'", quoted_dir, terminal); g_free(quoted_dir); g_free(terminal); is_ok = exec_app_info(exec, G_APP_INFO_CREATE_NONE); g_free(exec); if (!is_ok) { g_debug("exec app info failed!"); } return; } g_free(terminal); } is_ok = exec_app_info (executable, G_APP_INFO_CREATE_NEEDS_TERMINAL); if ( !is_ok ) { g_debug ("exec app info failed!"); /*exec_app_info (executable);*/ } return; }
static void dlg_response (GtkWidget *dlg, gint response, GCancellable *cancellable) { /* We will cancel only backup/restore * operations and not the check operation. */ g_cancellable_cancel (cancellable); /* If the response is not of delete_event then destroy the event. */ if (response != GTK_RESPONSE_NONE) gtk_widget_destroy (dlg); /* We will kill just the tar operation. Rest of * them will be just a second of microseconds.*/ run_cmd ("pkill tar"); if (bk_file && backup_op && response == GTK_RESPONSE_REJECT) { /* Backup was cancelled, delete the * backup file as it is not needed now. */ gchar *cmd, *filename; g_message ("Back up cancelled, removing partial back up file."); filename = g_shell_quote (bk_file); cmd = g_strconcat ("rm ", filename, NULL); run_cmd (cmd); g_free (cmd); g_free (filename); } gtk_main_quit (); }
static char * create_file_list (GList *file_list, GetFileDataValueFunc func, gboolean quote_value) { GString *s; GList *scan; s = g_string_new (""); for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; char *value; char *quoted; value = func (file_data); if (quote_value) quoted = g_shell_quote (value); else quoted = g_strdup (value); g_string_append (s, quoted); if (scan->next != NULL) g_string_append (s, " "); g_free (quoted); g_free (value); } return g_string_free (s, FALSE); }
static char * create_attribute_list (GList *file_list, char *match, gboolean quote_value) { GRegex *re; char **a; char *attribute = NULL; gboolean first_value = TRUE; GString *s; GList *scan; re = g_regex_new ("%attr\\{([^}]+)\\}", 0, 0, NULL); a = g_regex_split (re, match, 0); if (g_strv_length (a) >= 2) attribute = g_strstrip (a[1]); if (attribute == NULL) { g_strfreev (a); g_regex_unref (re); return NULL; } s = g_string_new (""); for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; char *value; char *quoted; value = gth_file_data_get_attribute_as_string (file_data, attribute); if (value == NULL) continue; if (value != NULL) { char *tmp_value; tmp_value = _g_utf8_replace (value, "[\r\n]", " "); g_free (value); value = tmp_value; } if (quote_value) quoted = g_shell_quote (value); else quoted = g_strdup (value); if (! first_value) g_string_append (s, " "); g_string_append (s, quoted); first_value = FALSE; g_free (quoted); g_free (value); } g_strfreev (a); g_regex_unref (re); return g_string_free (s, FALSE); }
/** * nemo_launch_application_from_command: * * Fork off a process to launch an application with a given uri as * a parameter. * * @command_string: The application to be launched, with any desired * command-line options. * @parameters: Passed as parameters to the application after quoting each of them. */ void nemo_launch_application_from_command_array (GdkScreen *screen, const char *command_string, gboolean use_terminal, const char * const * parameters) { char *full_command, *tmp; char *quoted_parameter; const char * const *p; full_command = g_strdup (command_string); if (parameters != NULL) { for (p = parameters; *p != NULL; p++) { quoted_parameter = g_shell_quote (*p); tmp = g_strconcat (full_command, " ", quoted_parameter, NULL); g_free (quoted_parameter); g_free (full_command); full_command = tmp; } } launch_application_from_command_internal (full_command, screen, use_terminal); g_free (full_command); }
/** * nemo_launch_application_from_command: * * Fork off a process to launch an application with a given uri as * a parameter. * * @command_string: The application to be launched, with any desired * command-line options. * @...: Passed as parameters to the application after quoting each of them. */ void nemo_launch_application_from_command (GdkScreen *screen, const char *command_string, gboolean use_terminal, ...) { char *full_command, *tmp; char *quoted_parameter; char *parameter; va_list ap; full_command = g_strdup (command_string); va_start (ap, use_terminal); while ((parameter = va_arg (ap, char *)) != NULL) { quoted_parameter = g_shell_quote (parameter); tmp = g_strconcat (full_command, " ", quoted_parameter, NULL); g_free (quoted_parameter); g_free (full_command); full_command = tmp; } va_end (ap); launch_application_from_command_internal (full_command, screen, use_terminal); g_free (full_command); }
/* Changes the current working directory of the VTE to the path of the given filename. * filename is expected to be in UTF-8 encoding. * filename can also be a path, then it is used directly. * If force is set to TRUE, it will always change the cwd */ void vte_cwd(const gchar *filename, gboolean force) { if (vte_info.have_vte && (vc->follow_path || force) && filename != NULL && g_path_is_absolute(filename)) { gchar *path; if (g_file_test(filename, G_FILE_TEST_IS_DIR)) path = g_strdup(filename); else path = g_path_get_dirname(filename); vte_get_working_directory(); /* refresh vte_info.dir */ if (! utils_str_equal(path, vte_info.dir)) { /* use g_shell_quote to avoid problems with spaces, '!' or something else in path */ gchar *quoted_path = g_shell_quote(path); gchar *cmd = g_strconcat(vc->send_cmd_prefix, "cd ", quoted_path, "\n", NULL); if (! vte_send_cmd(cmd)) { ui_set_statusbar(FALSE, _("Could not change the directory in the VTE because it probably contains a command.")); geany_debug( "Could not change the directory in the VTE because it probably contains a command."); } g_free(quoted_path); g_free(cmd); } g_free(path); } }
/* Changes the current working directory of the VTE to the path of the given filename. * filename is expected to be in UTF-8 encoding. * filename can also be a path, then it is used directly. * If force is set to TRUE, it will always change the cwd */ void vte_cwd(const gchar *filename, gboolean force) { if (vte_info.have_vte && (vc->follow_path || force) && filename != NULL && g_path_is_absolute(filename)) { gchar *path; if (g_file_test(filename, G_FILE_TEST_IS_DIR)) path = g_strdup(filename); else path = g_path_get_dirname(filename); vte_get_working_directory(); /* refresh vte_info.dir */ if (! utils_str_equal(path, vte_info.dir)) { /* use g_shell_quote to avoid problems with spaces, '!' or something else in path */ gchar *quoted_path = g_shell_quote(path); gchar *cmd = g_strconcat(vc->send_cmd_prefix, "cd ", quoted_path, "\n", NULL); if (! vte_send_cmd(cmd)) { const gchar *msg = _("Directory not changed because the terminal may contain some input (press Ctrl+C or Enter to clear it)."); ui_set_statusbar(FALSE, "%s", msg); geany_debug("%s", msg); } g_free(quoted_path); g_free(cmd); } g_free(path); } }