term: allow specifying command arguments
authorAli Gholami Rudi <ali@rudi.ir>
Tue, 13 Aug 2013 16:52:01 +0000 (13 21:22 +0430)
committerAli Gholami Rudi <ali@rudi.ir>
Tue, 13 Aug 2013 16:52:01 +0000 (13 21:22 +0430)
config.h
fbpad.c
fbpad.h
term.c

index 3e5aae2..62bed1c 100644 (file)
--- a/config.h
+++ b/config.h
@@ -1,8 +1,11 @@
+/* list of tags */
 #define TAGS           "xnlhtr01uiva-"
 #define TAGS_SAVED     ""
-#define SHELL          "ksh"
-#define MAIL           "mailx"
-#define EDITOR         "vi"
+
+/* programs mapped to m-c, m-m, m-e */
+#define SHELL          {"sh"}
+#define EDITOR         {"vi"}
+#define MAIL           {"mailx", "-f", "+inbox"}
 
 /* fbval_t should match framebuffer depth */
 typedef unsigned int fbval_t;
@@ -12,6 +15,7 @@ typedef unsigned int fbval_t;
 #define FI             NULL
 #define FB             NULL
 
+/* foreground and background colors */
 #define FGCOLOR                0
 #define BGCOLOR                7
 
diff --git a/fbpad.c b/fbpad.c
index 49f97d8..001b630 100644 (file)
--- a/fbpad.c
+++ b/fbpad.c
@@ -85,10 +85,10 @@ static struct term *mainterm(void)
        return NULL;
 }
 
-static void exec_cmd(char *file)
+static void exec_cmd(char **args)
 {
        if (!mainterm())
-               term_exec(file);
+               term_exec(args);
 }
 
 static int altterm(int n)
@@ -137,6 +137,9 @@ static void showtags(void)
 
 static void directkey(void)
 {
+       char *shell[32] = SHELL;
+       char *mail[32] = MAIL;
+       char *editor[32] = EDITOR;
        int c = readchar();
        if (PASS && locked) {
                if (c == '\r') {
@@ -153,13 +156,13 @@ static void directkey(void)
        if (c == ESC) {
                switch ((c = readchar())) {
                case 'c':
-                       exec_cmd(SHELL);
+                       exec_cmd(shell);
                        return;
                case 'm':
-                       exec_cmd(MAIL);
+                       exec_cmd(mail);
                        return;
                case 'e':
-                       exec_cmd(EDITOR);
+                       exec_cmd(editor);
                        return;
                case 'j':
                case 'k':
diff --git a/fbpad.h b/fbpad.h
index f0ce0aa..0900777 100644 (file)
--- a/fbpad.h
+++ b/fbpad.h
@@ -39,7 +39,7 @@ void term_save(struct term *term);
 
 void term_read(void);
 void term_send(int c);
-void term_exec(char *cmd);
+void term_exec(char **args);
 void term_end(void);
 void term_screenshot(void);
 
diff --git a/term.c b/term.c
index c87f98a..a36a315 100644 (file)
--- a/term.c
+++ b/term.c
@@ -295,7 +295,7 @@ static void execvep(char *cmd, char **argv, char **envp)
 }
 
 extern char **environ;
-void term_exec(char *cmd)
+void term_exec(char **args)
 {
        int master, slave;
        memset(term, 0, sizeof(*term));
@@ -305,11 +305,10 @@ void term_exec(char *cmd)
                return;
        if (!term->pid) {
                char *envp[MAXENV] = {"TERM=linux"};
-               char *argv[2] = {cmd};
                envcpy(envp + 1, environ);
                _login(slave);
                close(master);
-               execvep(cmd, argv, envp);
+               execvep(args[0], args, envp);
                exit(1);
        }
        close(slave);