On Thu, 24 May 2001, Wilbert Berendsen wrote:
> Well, maybe yes it's more elegant then to have blackbox launch the app
> directly; when you want, you can always type sh -c 'blabla | bla' in
> the bb menu file.
That is the easy way!
Can anyone share a routine or is there a exec()-type function where you
can pass one NULL-terminated string for the args and it will split it up
to arg0, arg1, arg2, ... ??
I made a simple patch. It adds a [shexec] menu option. This [shexec]
behaves like the current [exec]. The new (with patch) [exec] now doesn't
exec "sh -c".
I have one problem: my parsing code simply splits the line by spaces, so
"Midnight Blue"
which should be one argv[argument] becomes two
'"Midnight' and 'Blue"'.
To temporarily workaround this, I use [shexec] for any menu entries like
that.
Patch attached. Feel free to share any advice or opinions.
Also, I find the menu key number format strange. I printed it out to
find out that shexec becomes 640.
Jeremy C. Reed
.......................................................
ISP-FAQ.com -- find answers to your questions
http://www.isp-faq.com/
diff -u blackbox-0.61.1-orig/src/BaseDisplay.cc blackbox-0.61.1/src/BaseDisplaydiff -u
blackbox-0.61.1-orig/src/BaseDisplay.cc blackbox-0.61.1/src/BaseDisplay.cc
--- blackbox-0.61.1-orig/src/BaseDisplay.cc Thu Oct 5 14:05:40 2000
+++ blackbox-0.61.1/src/BaseDisplay.cc Thu May 24 12:58:47 2001
@@ -200,11 +200,34 @@
// convenience functions
#ifndef __EMX__
-void bexec(const char *command, char* displaystring) {
+void bshexec(const char *command, char* displaystring) {
if (! fork()) {
setsid();
putenv(displaystring);
execl("/bin/sh", "/bin/sh", "-c", command, NULL);
+ exit(0);
+ }
+}
+
+/* 24/May/2001 reed */
+void bexec(const char *command, char* displaystring) {
+ if (! fork()) {
+ char **newargv;
+ int arguments;
+
+ setsid();
+ putenv(displaystring);
+
+ newargv[0] = strtok(command, " \t");
+ arguments = 1;
+ newargv[1] = NULL;
+ while ((newargv[arguments] = strtok(NULL, " \t")) != NULL) {
+ arguments++;
+ }
+ newargv[arguments + 1] = NULL;
+/* fprintf (stderr, "command: %s, newargv[1]: %s\n", newargv[0], newargv[1]); */
+ execvp(newargv[0], newargv);
+ fprintf (stderr, "Could not execute: %s\n", newargv[0]);
exit(0);
}
}
diff -u blackbox-0.61.1-orig/src/BaseDisplay.hh blackbox-0.61.1/src/BaseDisplay.hh
--- blackbox-0.61.1-orig/src/BaseDisplay.hh Thu Oct 5 14:05:40 2000
+++ blackbox-0.61.1/src/BaseDisplay.hh Thu May 24 12:12:29 2001
@@ -64,6 +64,7 @@
#ifndef __EMX__
void bexec(const char *, char *);
+void bshexec(const char *, char *);
#endif // !__EMX__
char *bstrdup(const char *);
Only in blackbox-0.61.1/src: Makefile
diff -u blackbox-0.61.1-orig/src/Rootmenu.cc blackbox-0.61.1/src/Rootmenu.cc
--- blackbox-0.61.1-orig/src/Rootmenu.cc Mon Jun 26 15:36:15 2000
+++ blackbox-0.61.1/src/Rootmenu.cc Thu May 24 12:12:08 2001
@@ -63,6 +63,22 @@
if (item->function()) {
switch (item->function()) {
+ case BScreen::shExecute:
+ if (item->exec()) {
+#ifndef __EMX__
+ char displaystring[MAXPATHLEN];
+ sprintf(displaystring, "DISPLAY=%s",
+ DisplayString(screen->getBaseDisplay()->getXDisplay()));
+ sprintf(displaystring + strlen(displaystring) - 1, "%d",
+ screen->getScreenNumber());
+
+ bshexec(item->exec(), displaystring);
+#else // __EMX__
+ spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", item->exec(), NULL);
+#endif // !__EMX__
+ }
+ break;
+
case BScreen::Execute:
if (item->exec()) {
#ifndef __EMX__
diff -u blackbox-0.61.1-orig/src/Screen.cc blackbox-0.61.1/src/Screen.cc
--- blackbox-0.61.1-orig/src/Screen.cc Thu Oct 5 19:01:12 2000
+++ blackbox-0.61.1/src/Screen.cc Thu May 24 12:13:00 2001
@@ -1347,7 +1347,7 @@
sprintf(displaystring + strlen(displaystring) - 1, "%d",
getScreenNumber());
- bexec(value.addr, displaystring);
+ bshexec(value.addr, displaystring);
#else // __EMX__
spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", value.addr, NULL);
#endif // !__EMX__
@@ -2013,6 +2013,25 @@
}
menu->insert(label, configmenu);
+
+ break;
+
+ /* 24/May/2001 reed - [shexec] is same as old [exec] */
+ case 640: // shexec
+ if ((! *label) && (! *command)) {
+ fprintf(stderr,
+ i18n->getMessage(
+#ifdef NLS
+ ScreenSet, ScreenEXECError,
+#else // !NLS
+ 0, 0,
+#endif // NLS
+ "BScreen::parseMenuFile: [shexec] error, "
+ "no menu label and/or command defined\n"));
+ continue;
+ }
+
+ menu->insert(label, BScreen::shExecute, command);
break;
diff -u blackbox-0.61.1-orig/src/Screen.hh blackbox-0.61.1/src/Screen.hh
--- blackbox-0.61.1-orig/src/Screen.hh Sun Jun 18 20:55:33 2000
+++ blackbox-0.61.1/src/Screen.hh Thu May 24 12:41:53 2001
@@ -325,9 +325,9 @@
RightLeft, TopBottom, BottomTop };
enum { LeftJustify = 1, RightJustify, CenterJustify };
enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
- enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure,
- WindowShade, WindowIconify, WindowMaximize, WindowClose, WindowRaise,
- WindowLower, WindowStick, WindowKill, SetStyle };
+ enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, shExecute,
+ Reconfigure, WindowShade, WindowIconify, WindowMaximize, WindowClose,
+ WindowRaise, WindowLower, WindowStick, WindowKill, SetStyle };
};