summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-10-03 23:32:26 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-10-03 23:32:26 +0000
commit7ba01f68437e43538da1c7be96140709ddb00d77 (patch)
treebdafea75a00c8d03cb5a027d2b0472e76c1e798b /window.c
parentc3e049c5a9343138be44c9ab8f77c36293871424 (diff)
New window command.
Diffstat (limited to 'window.c')
-rw-r--r--window.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/window.c b/window.c
index ced59ffa..18fbd887 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.17 2007-10-03 13:07:42 nicm Exp $ */
+/* $Id: window.c,v 1.18 2007-10-03 23:32:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -52,13 +52,14 @@ struct windows windows;
/* Create a new window. */
struct window *
-window_create(const char *cmd, const char **environ, u_int sx, u_int sy)
+window_create(
+ const char *name, const char *cmd, const char **environ, u_int sx, u_int sy)
{
struct window *w;
struct winsize ws;
struct termios tio;
int fd, mode;
- char *ptr, *name;
+ char *ptr, *copy;
const char **entry;
memset(&ws, 0, sizeof ws);
@@ -104,25 +105,28 @@ window_create(const char *cmd, const char **environ, u_int sx, u_int sy)
screen_create(&w->screen, sx, sy);
input_init(&w->ictx, &w->screen);
- /* XXX */
- if (strncmp(cmd, "exec ", (sizeof "exec ") - 1) == 0)
- name = xstrdup(cmd + sizeof "exec ");
- else
- name = xstrdup(cmd);
- if ((ptr = strchr(name, ' ')) != NULL) {
- if (ptr != name && ptr[-1] != '\\')
- *ptr = '\0';
- else {
- while ((ptr = strchr(ptr + 1, ' ')) != NULL) {
- if (ptr[-1] != '\\') {
- *ptr = '\0';
- break;
+ if (name == NULL) {
+ /* XXX */
+ if (strncmp(cmd, "exec ", (sizeof "exec ") - 1) == 0)
+ copy = xstrdup(cmd + sizeof "exec ");
+ else
+ copy = xstrdup(cmd);
+ if ((ptr = strchr(copy, ' ')) != NULL) {
+ if (ptr != copy && ptr[-1] != '\\')
+ *ptr = '\0';
+ else {
+ while ((ptr = strchr(ptr + 1, ' ')) != NULL) {
+ if (ptr[-1] != '\\') {
+ *ptr = '\0';
+ break;
+ }
}
}
}
- }
- strlcpy(w->name, xbasename(name), sizeof w->name);
- xfree(name);
+ w->name = xstrdup(xbasename(copy));
+ xfree(copy);
+ } else
+ w->name = xstrdup(name);
window_add(&windows, w);
w->references = 1;
@@ -186,6 +190,8 @@ window_destroy(struct window *w)
buffer_destroy(w->in);
buffer_destroy(w->out);
+
+ xfree(w->name);
xfree(w);
}