[w3m-dev 02749] cleanup code for editor,mailer,extbrowser

From: Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2001-12-26 18:29:33 +00:00
parent 91f74e09ec
commit e6b49bac2e
5 changed files with 115 additions and 115 deletions
+17 -1
View File
@@ -1,3 +1,19 @@
2001-12-27 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 02749] cleanup code for editor,mailer,extbrowser
* etc.c (myExtCommand): added
* etc.c (myEditor): added
* form.c (input_textarea): use myEditor()
* main.c (pipeBuf): use myExtCommand()
* main.c (editBf): use myEditor()
* main.c (editScr): use myEditor()
* main.c (followA): use myExtCommand()
* main.c (cmd_loadURL): use myExtCommand()
* main.c (invoke_browser): use myExtCommand()
* main.c (execdict): use myExtCommand()
* proto.h (myExtCommand): added
* proto.h (myEditor): added
2001-12-27 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp> 2001-12-27 Hironori Sakamoto <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 02748] cleanup code for restoring cursor position * [w3m-dev 02748] cleanup code for restoring cursor position
@@ -1655,4 +1671,4 @@
* release-0-2-1 * release-0-2-1
* import w3m-0.2.1 * import w3m-0.2.1
$Id: ChangeLog,v 1.183 2001/12/26 18:17:57 ukai Exp $ $Id: ChangeLog,v 1.184 2001/12/26 18:29:33 ukai Exp $
+63 -1
View File
@@ -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 "fm.h"
#include <pwd.h> #include <pwd.h>
#include "myctype.h" #include "myctype.h"
@@ -1059,6 +1059,68 @@ mySystem(char *command, int background)
system(command); 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 * char *
expandName(char *name) expandName(char *name)
{ {
+7 -18
View File
@@ -1,4 +1,4 @@
/* $Id: form.c,v 1.7 2001/11/29 09:34:14 ukai Exp $ */ /* $Id: form.c,v 1.8 2001/12/26 18:29:33 ukai Exp $ */
/* /*
* HTML forms * HTML forms
*/ */
@@ -453,14 +453,14 @@ form_fputs_decode(Str s, FILE * f)
void void
input_textarea(FormItemList *fi) input_textarea(FormItemList *fi)
{ {
Str tmpname = tmpfname(TMPF_DFL, NULL); char *tmpf = tmpfname(TMPF_DFL, NULL)->ptr;
Str tmp; Str tmp;
FILE *f; FILE *f;
#ifdef JP_CHARSET #ifdef JP_CHARSET
char code = DisplayCode, ic; char code = DisplayCode, ic;
#endif #endif
f = fopen(tmpname->ptr, "w"); f = fopen(tmpf, "w");
if (f == NULL) { if (f == NULL) {
disp_err_message("Can't open temporary file", FALSE); disp_err_message("Can't open temporary file", FALSE);
return; return;
@@ -468,25 +468,14 @@ input_textarea(FormItemList *fi)
if (fi->value) if (fi->value)
form_fputs_decode(fi->value, f); form_fputs_decode(fi->value, f);
fclose(f); fclose(f);
if (strcasestr(Editor, "%s"))
if (strcasestr(Editor, "%d"))
tmp = Sprintf(Editor, 1, tmpname->ptr);
else
tmp = Sprintf(Editor, tmpname->ptr);
else {
if (strcasestr(Editor, "%d"))
tmp = Sprintf(Editor, 1);
else
tmp = Strnew_charp(Editor);
Strcat_m_charp(tmp, " ", tmpname->ptr, NULL);
}
fmTerm(); fmTerm();
system(tmp->ptr); system(myEditor(Editor, tmpf, 1)->ptr);
fmInit(); fmInit();
if (fi->readonly) if (fi->readonly)
return; return;
f = fopen(tmpname->ptr, "r"); f = fopen(tmpf, "r");
if (f == NULL) { if (f == NULL) {
disp_err_message("Can't open temporary file", FALSE); disp_err_message("Can't open temporary file", FALSE);
return; return;
@@ -509,7 +498,7 @@ input_textarea(FormItemList *fi)
Strcat(fi->value, tmp); Strcat(fi->value, tmp);
} }
fclose(f); fclose(f);
unlink(tmpname->ptr); unlink(tmpf);
} }
void void
+23 -92
View File
@@ -1,4 +1,4 @@
/* $Id: main.c,v 1.49 2001/12/26 18:17:57 ukai Exp $ */ /* $Id: main.c,v 1.50 2001/12/26 18:29:33 ukai Exp $ */
#define MAINPROGRAM #define MAINPROGRAM
#include "fm.h" #include "fm.h"
#include <signal.h> #include <signal.h>
@@ -1656,11 +1656,7 @@ pipeBuf(void)
saveBuffer(Currentbuf, f); saveBuffer(Currentbuf, f);
fclose(f); fclose(f);
pushText(fileToDelete, tmpf); pushText(fileToDelete, tmpf);
if (strcasestr(cmd, "%s")) buf = getpipe(myExtCommand(cmd, tmpf, TRUE)->ptr);
cmd = Sprintf(cmd, tmpf)->ptr;
else
cmd = Sprintf("%s < %s", cmd, tmpf)->ptr;
buf = getpipe(cmd);
if (buf == NULL) { if (buf == NULL) {
disp_message("Execution failed", FALSE); disp_message("Execution failed", FALSE);
} }
@@ -2238,31 +2234,11 @@ editBf(void)
if (Currentbuf->frameset != NULL) if (Currentbuf->frameset != NULL)
fbuf = Currentbuf->linkBuffer[LB_FRAME]; fbuf = Currentbuf->linkBuffer[LB_FRAME];
copyBuffer(&sbuf, Currentbuf); copyBuffer(&sbuf, Currentbuf);
if (Currentbuf->edit) { if (Currentbuf->edit)
cmd = unquote_mailcap(Currentbuf->edit, cmd = unquote_mailcap(Currentbuf->edit, Currentbuf->real_type, fn,
Currentbuf->real_type,
fn,
checkHeader(Currentbuf, "Content-Type:"), NULL); checkHeader(Currentbuf, "Content-Type:"), NULL);
}
else {
char *file = shell_quote(fn);
int linenum = CUR_LINENUMBER(Currentbuf);
if (strcasestr(Editor, "%s")) {
if (strcasestr(Editor, "%d"))
cmd = Sprintf(Editor, linenum, file);
else else
cmd = Sprintf(Editor, file); cmd = myEditor(Editor, shell_quote(fn), CUR_LINENUMBER(Currentbuf));
}
else {
if (strcasestr(Editor, "%d"))
cmd = Sprintf(Editor, linenum);
else if (strcasestr(Editor, "vi"))
cmd = Sprintf("%s +%d", Editor, linenum);
else
cmd = Strnew_charp(Editor);
Strcat_m_charp(cmd, " ", file, NULL);
}
}
fmTerm(); fmTerm();
system(cmd->ptr); system(cmd->ptr);
fmInit(); fmInit();
@@ -2309,45 +2285,21 @@ editBf(void)
void void
editScr(void) editScr(void)
{ {
int lnum; char *tmpf;
Str cmd;
Str tmpf;
FILE *f; FILE *f;
tmpf = tmpfname(TMPF_DFL, NULL); tmpf = tmpfname(TMPF_DFL, NULL)->ptr;
f = fopen(tmpf->ptr, "w"); f = fopen(tmpf, "w");
if (f == NULL) { if (f == NULL) {
cmd = Sprintf("Can't open %s", tmpf->ptr); disp_err_message(Sprintf("Can't open %s", tmpf)->ptr, TRUE);
disp_err_message(cmd->ptr, TRUE);
return; return;
} }
saveBuffer(Currentbuf, f); saveBuffer(Currentbuf, f);
fclose(f); fclose(f);
if (Currentbuf->currentLine)
lnum = Currentbuf->currentLine->linenumber;
else
lnum = 1;
if (strcasestr(Editor, "%s")) {
if (strcasestr(Editor, "%d"))
cmd = Sprintf(Editor, lnum, tmpf->ptr);
else
cmd = Sprintf(Editor, tmpf->ptr);
}
else {
if (strcasestr(Editor, "%d"))
cmd = Sprintf(Editor, lnum);
else if (strcasestr(Editor, "vi"))
cmd = Sprintf("%s +%d", Editor, lnum);
else
cmd = Strnew_charp(Editor);
Strcat_m_charp(cmd, " ", tmpf->ptr, NULL);
}
fmTerm(); fmTerm();
system(cmd->ptr); system(myEditor(Editor, tmpf, CUR_LINENUMBER(Currentbuf))->ptr);
fmInit(); fmInit();
unlink(tmpf->ptr); unlink(tmpf);
gotoLine(Currentbuf, lnum);
arrangeCursor(Currentbuf);
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
} }
@@ -2652,14 +2604,9 @@ followA(void)
} }
if (!strncasecmp(a->url, "mailto:", 7)) { if (!strncasecmp(a->url, "mailto:", 7)) {
/* invoke external mailer */ /* invoke external mailer */
Str tmp;
char *to = shell_quote(url_unquote(a->url + 7));
if (strcasestr(Mailer, "%s"))
tmp = Sprintf(Mailer, to);
else
tmp = Strnew_m_charp(Mailer, " ", to, NULL);
fmTerm(); fmTerm();
system(tmp->ptr); system(myExtCommand(Mailer, shell_quote(url_unquote(a->url + 7)),
FALSE)->ptr);
fmInit(); fmInit();
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
return; return;
@@ -3595,14 +3542,9 @@ cmd_loadURL(char *url, ParsedURL *current)
if (!strncasecmp(url, "mailto:", 7)) { if (!strncasecmp(url, "mailto:", 7)) {
/* invoke external mailer */ /* invoke external mailer */
Str tmp;
char *to = shell_quote(url + 7);
if (strcasestr(Mailer, "%s"))
tmp = Sprintf(Mailer, to);
else
tmp = Strnew_m_charp(Mailer, " ", to, NULL);
fmTerm(); fmTerm();
system(tmp->ptr); system(myExtCommand(Mailer, shell_quote(url_unquote(url + 7)),
FALSE)->ptr);
fmInit(); fmInit();
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
return; return;
@@ -4302,7 +4244,7 @@ rFrame(void)
static void static void
invoke_browser(char *url) invoke_browser(char *url)
{ {
Str tmp; Str cmd;
char *browser = NULL; char *browser = NULL;
int bg = 0; int bg = 0;
@@ -4332,22 +4274,15 @@ invoke_browser(char *url)
} }
if (browser == NULL || *browser == '\0') if (browser == NULL || *browser == '\0')
return; return;
url = shell_quote(url);
if (strcasestr(browser, "%s")) { cmd = myExtCommand(browser, shell_quote(url), FALSE);
tmp = Sprintf(browser, url); Strremovetrailingspaces(cmd);
Strremovetrailingspaces(tmp); if (Strlastchar(cmd) == '&') {
if (Strlastchar(tmp) == '&') { Strshrink(cmd, 1);
Strshrink(tmp, 1);
bg = 1; bg = 1;
} }
}
else {
tmp = Strnew_charp(browser);
Strcat_char(tmp, ' ');
Strcat_charp(tmp, url);
}
fmTerm(); fmTerm();
mySystem(tmp->ptr, bg); mySystem(cmd->ptr, bg);
fmInit(); fmInit();
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
} }
@@ -4666,19 +4601,15 @@ static void
execdict(char *word) execdict(char *word)
{ {
Buffer *buf; Buffer *buf;
Str cmd;
MySignalHandler(*prevtrap) (); MySignalHandler(*prevtrap) ();
if (word == NULL || *word == '\0') { if (word == NULL || *word == '\0') {
displayBuffer(Currentbuf, B_NORMAL); displayBuffer(Currentbuf, B_NORMAL);
return; return;
} }
cmd = Strnew_charp(DICTCMD);
Strcat_char(cmd, ' ');
Strcat_charp(cmd, word);
prevtrap = signal(SIGINT, intTrap); prevtrap = signal(SIGINT, intTrap);
crmode(); crmode();
buf = getshell(cmd->ptr); buf = getshell(myExtCommand(DICTCMD, shell_quote(word), FALSE)->ptr);
buf->filename = word; buf->filename = word;
word = conv_from_system(word); word = conv_from_system(word);
buf->buffername = Sprintf("%s %s", DICTBUFFERNAME, word)->ptr; buf->buffername = Sprintf("%s %s", DICTBUFFERNAME, word)->ptr;
+3 -1
View File
@@ -1,4 +1,4 @@
/* $Id: proto.h,v 1.21 2001/12/26 18:17:57 ukai Exp $ */ /* $Id: proto.h,v 1.22 2001/12/26 18:29:33 ukai Exp $ */
/* /*
* This file was automatically generated by version 1.7 of cextract. * This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended. * Manual editing not recommended.
@@ -479,6 +479,8 @@ extern char *last_modified(Buffer *buf);
extern Str romanNumeral(int n); extern Str romanNumeral(int n);
extern Str romanAlphabet(int n); extern Str romanAlphabet(int n);
extern void mySystem(char *command, int background); extern void mySystem(char *command, int background);
extern Str myExtCommand(char *cmd, char *arg, int redirect);
extern Str myEditor(char *cmd, char *file, int line);
extern char *file_to_url(char *file); extern char *file_to_url(char *file);
extern char *expandName(char *name); extern char *expandName(char *name);
extern Str tmpfname(int type, char *ext); extern Str tmpfname(int type, char *ext);