diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.c | 41 | ||||
-rw-r--r-- | src/actions.h | 1 | ||||
-rw-r--r-- | src/main.c | 47 | ||||
-rw-r--r-- | src/ratpoison.h | 1 |
4 files changed, 61 insertions, 29 deletions
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); */ @@ -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 */ |