summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsabetts <sabetts>2001-09-18 06:41:30 +0000
committersabetts <sabetts>2001-09-18 06:41:30 +0000
commit445978d53f43962da85830a396aaf3acd021219a (patch)
treeed20d6913b330da251e9adb24eb7666fd7c831c2
parent5d2d31925ea817577c9293c83349fe80cb500099 (diff)
downloadratpoison-445978d53f43962da85830a396aaf3acd021219a.zip
* src/ratpoison.h (xstrdup): new prototype
* src/main.c (xstrdup): new function. All calls to strdup replaced with calls to xstrdup. (main): Keep a list of all commands pasted in through the -c command-line option. (main): execute all commands pasted in through the -c command-line option. * src/actions.h (cmd_chdir): new prototype * src/actions.c (cmd_clock): rename to cmd_time. Dependant code updated. (user_commands): rename "clock" command to "time". (cmd_chdir): new function (user_commands): new command "chdir".
-rw-r--r--ChangeLog11
-rw-r--r--NEWS4
-rw-r--r--src/actions.c41
-rw-r--r--src/actions.h1
-rw-r--r--src/main.c47
-rw-r--r--src/ratpoison.h1
6 files changed, 76 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 3621cf0..c46892b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,19 @@
2001-09-17 shawn <sabetts@diggin.lamenet.tmp>
+ * src/ratpoison.h (xstrdup): new prototype
+
+ * src/main.c (xstrdup): new function. All calls to strdup replaced
+ with calls to xstrdup.
+ (main): Keep a list of all commands pasted in through the -c command-line option.
+ (main): execute all commands pasted in through the -c command-line option.
+
+ * src/actions.h (cmd_chdir): new prototype
+
* src/actions.c (cmd_clock): rename to cmd_time. Dependant code
updated.
(user_commands): rename "clock" command to "time".
+ (cmd_chdir): new function
+ (user_commands): new command "chdir".
2001-09-16 shawn <sabetts@diggin.lamenet.tmp>
diff --git a/NEWS b/NEWS
index dd0d9c7..87d32d8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
ratpoison NEWS --- history of user-visible changes. -*- outline -*-
* Changes since 1.0.0
+** Multiple commands passed to ratpoison via the command-line are now processed
+A stream of commands like, `ratpoison -c next -c prev -c next' are
+processed in order.
+
** clock command renamed to time
This was to improve screen compatibility.
diff --git a/src/actions.c b/src/actions.c
index 9f86de3..afa855a 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -66,6 +66,7 @@ static user_command user_commands[] =
{"vsplit", cmd_v_split, arg_VOID},
{"windows", cmd_windows, arg_VOID},
{"setenv", cmd_setenv, arg_STRING},
+ {"chdir", cmd_chdir, arg_STRING},
/* Commands to set default behavior. */
{"defbarloc", cmd_defbarloc, arg_STRING},
@@ -142,9 +143,9 @@ add_keybinding (KeySym keysym, int state, char *cmd)
key_actions[key_actions_last].key = keysym;
key_actions[key_actions_last].state = state;
- key_actions[key_actions_last].data = strdup (cmd); /* free this on
- shutdown, or
- re/unbinding */
+ key_actions[key_actions_last].data = xstrdup (cmd); /* free this on
+ shutdown, or
+ re/unbinding */
++key_actions_last;
}
@@ -634,7 +635,7 @@ cmd_select (int interactive, void *data)
if (data == NULL)
str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW);
else
- str = strdup ((char *) data);
+ str = xstrdup ((char *) data);
/* User aborted. */
if (str == NULL)
@@ -686,7 +687,7 @@ cmd_rename (int interactive, void *data)
if (data == NULL)
winname = get_input (MESSAGE_PROMPT_NEW_WINDOW_NAME);
else
- winname = strdup ((char *) data);
+ winname = xstrdup ((char *) data);
/* User aborted. */
if (winname == NULL)
@@ -762,7 +763,7 @@ command (int interactive, char *data)
return NULL;
/* get a writable copy for strtok() */
- input = strdup ((char *) data);
+ input = xstrdup ((char *) data);
cmd = strtok (input, " ");
@@ -835,7 +836,7 @@ cmd_exec (int interactive, void *data)
if (data == NULL)
cmd = get_input (MESSAGE_PROMPT_SHELL_COMMAND);
else
- cmd = strdup ((char *) data);
+ cmd = xstrdup ((char *) data);
/* User aborted. */
if (cmd == NULL)
@@ -891,7 +892,7 @@ cmd_newwm(int interactive, void *data)
if (data == NULL)
prog = get_input (MESSAGE_PROMPT_SWITCH_WM);
else
- prog = strdup ((char *) data);
+ prog = xstrdup ((char *) data);
/* User aborted. */
if (prog == NULL)
@@ -963,7 +964,7 @@ cmd_number (int interactive, void *data)
}
else
{
- str = strdup ((char *) data);
+ str = xstrdup ((char *) data);
}
if ((new_number = string_to_window_number (str)) >= 0)
@@ -1685,13 +1686,7 @@ cmd_defwinfmt (int interactive, void *data)
return NULL;
free (defaults.window_fmt);
- defaults.window_fmt = strdup (data);
-
- if (defaults.window_fmt == NULL)
- {
- PRINT_ERROR ("Not enough memory\n");
- exit (EXIT_FAILURE);
- }
+ defaults.window_fmt = xstrdup (data);
return NULL;
}
@@ -1815,3 +1810,17 @@ cmd_setenv (int interactive, void *data)
free (string);
return NULL;
}
+
+char *
+cmd_chdir (int interactive, void *data)
+{
+ if (!data)
+ {
+ char *homedir = getenv("HOME");
+ if (homedir)
+ chdir (homedir);
+ }
+
+ chdir ((char *)data);
+ return NULL;
+}
diff --git a/src/actions.h b/src/actions.h
index 3660a0c..0658c49 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -91,6 +91,7 @@ char * cmd_defwinname (int interactive, void *data);
char * cmd_deffgcolor (int interactive, void *data);
char * cmd_defbgcolor (int interactive, void *data);
char * cmd_setenv (int interactive, void *data);
+char * cmd_chdir (int interactive, void *data);
/* void cmd_xterm (void *data); */
diff --git a/src/main.c b/src/main.c
index 33589b3..72b1a02 100644
--- a/src/main.c
+++ b/src/main.c
@@ -115,6 +115,16 @@ xrealloc (void *ptr, size_t size)
return value;
}
+char *
+xstrdup (char *s)
+{
+ char *value;
+ value = strdup (s);
+ if (value == 0)
+ fatal ("Virtual memory exhausted");
+ return value;
+}
+
void
sighandler (int signum)
{
@@ -373,12 +383,7 @@ init_defaults ()
defaults.wait_for_key_cursor = 1;
- defaults.window_fmt = strdup ("%n%s%t");
- if (defaults.window_fmt == NULL)
- {
- PRINT_ERROR ("Not enough memory\n");
- exit (EXIT_FAILURE);
- }
+ defaults.window_fmt = xstrdup ("%n%s%t");
defaults.win_name = 0;
}
@@ -390,8 +395,8 @@ main (int argc, char *argv[])
int c;
int do_kill = 0;
int do_restart = 0;
- int do_command = 0;
- char *command = NULL;
+ char **command = NULL;
+ int cmd_count = 0;
myargv = argv;
@@ -418,9 +423,18 @@ main (int argc, char *argv[])
do_restart = 1;
break;
case 'c':
- command = xmalloc (strlen (optarg) + 1);
- strcpy (command, optarg);
- do_command = 1;
+ if (!command)
+ {
+ command = xmalloc (sizeof(char *));
+ cmd_count = 0;
+ }
+ else
+ {
+ command = xrealloc (command, sizeof (char *) * (cmd_count + 1));
+ }
+
+ command[cmd_count] = xstrdup (optarg);
+ cmd_count++;
break;
default:
exit (EXIT_FAILURE);
@@ -454,9 +468,16 @@ main (int argc, char *argv[])
XCloseDisplay (dpy);
return EXIT_SUCCESS;
}
- if (do_command)
+ if (cmd_count > 0)
{
- send_command (command);
+ int i;
+
+ for (i=0; i<cmd_count; i++)
+ {
+ send_command (command[i]);
+ free (command[i]);
+ }
+
free (command);
XCloseDisplay (dpy);
return EXIT_SUCCESS;
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 4defe46..f8c6c53 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -67,5 +67,6 @@ void read_rc_file (FILE *file);
void fatal (const char *msg);
void *xmalloc (size_t size);
void *xrealloc (void *ptr, size_t size);
+char *xstrdup (char *s);
#endif /* ! _RATPOISON_H */