summaryrefslogtreecommitdiff
path: root/src/Fl_Native_File_Chooser_Zenity.cxx
diff options
context:
space:
mode:
authormaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 21:32:25 +0500
committermaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 21:32:25 +0500
commitdc39575fb3ef90e5a2689babe7fb335cd88f6727 (patch)
tree24f6cef8f2b558ae6f1f812c75be0c09a53fe417 /src/Fl_Native_File_Chooser_Zenity.cxx
parent7d3793ce1d8cb26e7608bf859beca21359cec6e9 (diff)
wip
Diffstat (limited to 'src/Fl_Native_File_Chooser_Zenity.cxx')
-rw-r--r--src/Fl_Native_File_Chooser_Zenity.cxx58
1 files changed, 29 insertions, 29 deletions
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);
}
/**