From 7398386ad57d974e2293883d69507a374d644241 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Sat, 3 Oct 2009 09:06:05 +0000 Subject: [PATCH] Allow ede-launch arguments to be quoted or unquoted --- ede-desktop/ede-desktop.cpp | 2 +- ede-launch/ede-launch.cpp | 47 +++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ede-desktop/ede-desktop.cpp b/ede-desktop/ede-desktop.cpp index 1c1bb5d..54e5f12 100644 --- a/ede-desktop/ede-desktop.cpp +++ b/ede-desktop/ede-desktop.cpp @@ -117,7 +117,7 @@ static void background_conf_cb(Fl_Widget*, void*) { } static void icons_conf_cb(Fl_Widget*, void*) { - edelib::run_async("ede-launch \"ede-desktop-conf --icons\""); + edelib::run_async("ede-launch ede-desktop-conf --icons"); } static int desktop_xmessage_handler(int event) { diff --git a/ede-launch/ede-launch.cpp b/ede-launch/ede-launch.cpp index 98ce05c..f0be089 100644 --- a/ede-launch/ede-launch.cpp +++ b/ede-launch/ede-launch.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include #include "icons/run.xpm" @@ -49,6 +51,7 @@ #define LaunchWindow edelib::Window EDELIB_NS_USING(Resource) +EDELIB_NS_USING(String) EDELIB_NS_USING(RES_USER_ONLY) EDELIB_NS_USING(run_sync) EDELIB_NS_USING(run_async) @@ -326,10 +329,46 @@ int main(int argc, char** argv) { if(argc == 1) return start_dialog(argc, argv); - if(argc == 2) - start_child(argv[1]); - else - help(); + + + if(argc > 1) { + /* do not see possible flags as commands */ + if(argv[1][0] == '-') { + help(); + return 0; + } + + String args; + unsigned int alen; + for(int i = 1; i < argc; i++) { + args += argv[i]; + args += ' '; + } + + alen = args.length(); + + /* remove start/ending quotes and spaces */ + if((args[0] == '"') || isspace(args[0]) || (args[alen - 1] == '"') || isspace(args[alen - 1])) { + int i; + char *copy = strdup(args.c_str()); + char *ptr = copy; + + /* remove ending first */ + for(i = (int)alen - 1; i > 0 && (ptr[i] == '"' || isspace(ptr[i])); i--) + ; + + ptr[i + 1] = 0; + + /* remove then starting */ + for(; *ptr && (*ptr == '"' || isspace(*ptr)); ptr++) + ; + + start_child(ptr); + free(copy); + } else { + start_child(args.c_str()); + } + } return 0; }