...<command> argument (but still resolve tilde).
This makes it easier to write sh -c '' constructs without turning labwc
into a shell parser in order to expand environment variables, whilst
respecting single quotes and escaped characters as well as ignoring
subshells syntax like $(foo) and backticks.
Also, fix bug where buffer length+alloc get out-of-sync
Execute command. Note that in the interest of backward compatibility,
labwc supports <execute> as an alternative to <command> even though
openbox documentation states that it is deprecated.
+ Note: Tilde (~) is expanded in the command before passing to execvp()
*<action name="Exit" />*
Exit labwc.
cursor size/theme here; see environment variable section below for details. Note
that the environment file is treated differently by openbox where it is simply
sourced prior to running openbox.
+Note: Tilde (~) and environment variables in the value are expanded, but
+subshell syntax and apostrophes are ignored.
The *menu.xml* file defines the context/root-menus and is described in
labwc-menu(5).
};
/**
- * buf_expand_shell_variables - expand $foo, ${foo} and ~ in buffer
+ * buf_expand_tilde - expand ~ in buffer
+ * @s: buffer
+ */
+void buf_expand_tilde(struct buf *s);
+
+/**
+ * buf_expand_shell_variables - expand $foo and ${foo} in buffer
* @s: buffer
* Note: $$ is not handled
*/
struct buf cmd;
buf_init(&cmd);
buf_add(&cmd, action_str_from_arg(arg));
- buf_expand_shell_variables(&cmd);
+ buf_expand_tilde(&cmd);
spawn_async_no_shell(cmd.buf);
free(cmd.buf);
}
#include "common/buf.h"
#include "common/mem.h"
+static void
+buf_add_one_char(struct buf *s, char ch)
+{
+ if (s->alloc <= s->len + 1) {
+ s->alloc = s->alloc * 3 / 2 + 16;
+ s->buf = xrealloc(s->buf, s->alloc);
+ }
+ s->buf[s->len++] = ch;
+ s->buf[s->len] = '\0';
+}
+
+void
+buf_expand_tilde(struct buf *s)
+{
+ struct buf new;
+ buf_init(&new);
+ for (int i = 0 ; i < s->len ; i++) {
+ if (s->buf[i] == '~') {
+ buf_add(&new, getenv("HOME"));
+ } else {
+ buf_add_one_char(&new, s->buf[i]);
+ }
+ }
+ free(s->buf);
+ s->buf = new.buf;
+ s->len = new.len;
+ s->alloc = new.alloc;
+}
+
static void
strip_curly_braces(char *s)
{
if (p) {
buf_add(&new, p);
}
- } else if (s->buf[i] == '~') {
- /* expand tilde */
- buf_add(&new, getenv("HOME"));
} else {
- /* just add one character at a time */
- if (new.alloc <= new.len + 1) {
- new.alloc = new.alloc * 3 / 2 + 16;
- new.buf = xrealloc(new.buf, new.alloc);
- }
- new.buf[new.len++] = s->buf[i];
- new.buf[new.len] = '\0';
+ buf_add_one_char(&new, s->buf[i]);
}
}
free(environment_variable.buf);
free(s->buf);
s->buf = new.buf;
+ s->len = new.len;
+ s->alloc = new.alloc;
}
void
buf_init(&value);
buf_add(&value, string_strip(++p));
buf_expand_shell_variables(&value);
+ buf_expand_tilde(&value);
if (string_empty(key) || !value.len) {
goto error;
}