aboutsummaryrefslogtreecommitdiffstats
path: root/etc.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2001-12-26 18:29:33 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2001-12-26 18:29:33 +0000
commite6b49bac2eed9c5ce7680bdbb4a677e4b82e77cc (patch)
tree914e0b0d4710bd4a2a7d49b3299464646c699701 /etc.c
parent[w3m-dev 02748] cleanup code for restoring cursor position (diff)
downloadw3m-e6b49bac2eed9c5ce7680bdbb4a677e4b82e77cc.tar.gz
w3m-e6b49bac2eed9c5ce7680bdbb4a677e4b82e77cc.zip
[w3m-dev 02749] cleanup code for editor,mailer,extbrowser
From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to '')
-rw-r--r--etc.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/etc.c b/etc.c
index c7596e2..6350fab 100644
--- a/etc.c
+++ b/etc.c
@@ -1,4 +1,4 @@
-/* $Id: etc.c,v 1.15 2001/12/25 18:15:00 ukai Exp $ */
+/* $Id: etc.c,v 1.16 2001/12/26 18:29:33 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -1059,6 +1059,68 @@ mySystem(char *command, int background)
system(command);
}
+Str
+myExtCommand(char *cmd, char *arg, int redirect)
+{
+ Str tmp = NULL;
+ char *p;
+ int set_arg = FALSE;
+
+ for (p = cmd; *p; p++) {
+ if (*p == '%' && *(p + 1) == 's' && !set_arg) {
+ if (tmp == NULL)
+ tmp = Strnew_charp_n(cmd, (int)(p - cmd));
+ Strcat_charp(tmp, arg);
+ set_arg = TRUE;
+ p++;
+ }
+ else {
+ if (tmp)
+ Strcat_char(tmp, *p);
+ }
+ }
+ if (!set_arg)
+ tmp = Strnew_m_charp(cmd, (redirect ? " < " : " "), arg, NULL);
+ return tmp;
+}
+
+Str
+myEditor(char *cmd, char *file, int line)
+{
+ Str tmp = NULL;
+ char *p;
+ int set_file = FALSE, set_line = FALSE;
+
+ for (p = cmd; *p; p++) {
+ if (*p == '%' && *(p + 1) == 's' && !set_file) {
+ if (tmp == NULL)
+ tmp = Strnew_charp_n(cmd, (int)(p - cmd));
+ Strcat_charp(tmp, file);
+ set_file = TRUE;
+ p++;
+ }
+ else if (*p == '%' && *(p + 1) == 'd' && !set_line && line > 0) {
+ if (tmp == NULL)
+ tmp = Strnew_charp_n(cmd, (int)(p - cmd));
+ Strcat(tmp, Sprintf("%d", line));
+ set_line = TRUE;
+ p++;
+ }
+ else {
+ if (tmp)
+ Strcat_char(tmp, *p);
+ }
+ }
+ if (!set_file) {
+ if (tmp == NULL)
+ tmp = Strnew_charp(cmd);
+ if (!set_line && line > 0 && strcasestr(cmd, "vi"))
+ Strcat(tmp, Sprintf(" +%d", line));
+ Strcat_m_charp(tmp, " ", file, NULL);
+ }
+ return tmp;
+}
+
char *
expandName(char *name)
{