From dc39575fb3ef90e5a2689babe7fb335cd88f6727 Mon Sep 17 00:00:00 2001 From: maxim nikonov Date: Thu, 5 Feb 2026 21:32:25 +0500 Subject: wip --- src/Fl_Native_File_Chooser_Zenity.cxx | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/Fl_Native_File_Chooser_Zenity.cxx') diff --git a/src/Fl_Native_File_Chooser_Zenity.cxx b/src/Fl_Native_File_Chooser_Zenity.cxx index c765b8827..b4a75b62e 100644 --- a/src/Fl_Native_File_Chooser_Zenity.cxx +++ b/src/Fl_Native_File_Chooser_Zenity.cxx @@ -36,8 +36,7 @@ bool Fl_Zenity_Native_File_Chooser_Driver::have_looked_for_zenity = false; Fl_Zenity_Native_File_Chooser_Driver::Fl_Zenity_Native_File_Chooser_Driver(int val) : Fl_Kdialog_Native_File_Chooser_Driver(val) { } -void Fl_Zenity_Native_File_Chooser_Driver::append_filter(std::string& ret_command) { - // TODO: This could probably be simplified + toughened with std::string -erco 1/10/24 +void Fl_Zenity_Native_File_Chooser_Driver::append_filter(char *ret_command, int *pos, int maxlen) { int l; int lcommand = 10000; char *command = new char[lcommand]; @@ -46,7 +45,7 @@ void Fl_Zenity_Native_File_Chooser_Driver::append_filter(std::string& ret_comman char *p = strtok(parsed_filter_copy, "\n"); while (p) { char *op = strchr(p, '('); - l = strlen(command); + l = (int)strlen(command); snprintf(command+l, lcommand-l, " --file-filter='%s|", p); char *cp = strchr(p, ')'); *cp = 0; @@ -55,28 +54,30 @@ void Fl_Zenity_Native_File_Chooser_Driver::append_filter(std::string& ret_comman *ob = 0; char *cb = strchr(ob+1, ']'); char aux[100]; - for (char *q = ob+1; q < cb; q++) { + char *q; + for (q = ob+1; q < cb; q++) { strcpy(aux, op+1); - int la = strlen(aux); + int la = (int)strlen(aux); aux[la++] = *q; - if (cb < cp-1) { strcpy(aux+la, cb+1); la += strlen(cb+1); } + if (cb < cp-1) { strcpy(aux+la, cb+1); la += (int)strlen(cb+1); } aux[la] = 0; - l = strlen(command); + l = (int)strlen(command); snprintf(command+l, lcommand-l, " %s", aux); } strcat(command, "'"); } else { - l = strlen(command); + l = (int)strlen(command); snprintf(command+l, lcommand-l, "%s'", op+1); } p = strtok(NULL, "\n"); } free(parsed_filter_copy); - ret_command += command; // append to parent's std::string + // append to ret_command + *pos += snprintf(ret_command + *pos, maxlen - *pos, "%s", command); delete [] command; } -void Fl_Zenity_Native_File_Chooser_Driver::build_command(std::string& command) { +void Fl_Zenity_Native_File_Chooser_Driver::build_command(char *command, int maxlen) { const char *option; switch (_btype) { case Fl_Native_File_Chooser::BROWSE_DIRECTORY: @@ -100,34 +101,33 @@ void Fl_Zenity_Native_File_Chooser_Driver::build_command(std::string& command) { } // Build preset - std::string preset; + char preset[FL_PATH_MAX * 2] = ""; if (_preset_file) { - std::string quoted_filename = _preset_file; shell_quote(quoted_filename); - preset = "--filename="; - preset += quoted_filename; + char quoted_filename[FL_PATH_MAX]; + shell_quote(_preset_file, quoted_filename, sizeof(quoted_filename)); + snprintf(preset, sizeof(preset), "--filename=%s", quoted_filename); } else if (_directory) { // This doesn't actually seem to do anything, but supply it anyway. - std::string quoted_dir = _directory; shell_quote(quoted_dir); - preset = "--filename="; - preset += quoted_dir; + char quoted_dir[FL_PATH_MAX]; + shell_quote(_directory, quoted_dir, sizeof(quoted_dir)); + snprintf(preset, sizeof(preset), "--filename=%s", quoted_dir); } // Build command - command = "zenity"; + int pos = 0; + pos += snprintf(command + pos, maxlen - pos, "zenity"); if (_title) { - std::string quoted_title = _title; shell_quote(quoted_title); - command += " --title "; - command += quoted_title; + char quoted_title[FL_PATH_MAX]; + shell_quote(_title, quoted_title, sizeof(quoted_title)); + pos += snprintf(command + pos, maxlen - pos, " --title %s", quoted_title); } - command += " "; - command += option; - if (preset != "") { - command += " "; - command += preset; + pos += snprintf(command + pos, maxlen - pos, " %s", option); + if (preset[0]) { + pos += snprintf(command + pos, maxlen - pos, " %s", preset); } - if (_parsedfilt) append_filter(command); - command += " 2> /dev/null"; // get rid of stderr - //printf("command = %s\n", command.c_str()); + if (_parsedfilt) append_filter(command, &pos, maxlen); + snprintf(command + pos, maxlen - pos, " 2> /dev/null"); + //printf("command = %s\n", command); } /** -- cgit v1.2.3