[w3m-dev 04149] w3m -remote
Hiroyuki Ito <[email protected]> Tue, 21 Jun 2005 23:20:11 +0900 (JST)
| Newsgroups | gmane.comp.web.w3m.devel |
|---|---|
| Message-ID | <[email protected]> |
w3m
w3m -v -enabel_remote ~/.w3m w3msock* (* pid)
w3m
w3m
Ruby
(w3m_remote)
w3m_remote "TAB_GOTO http://w3m.sourceforge.net/"
w3m
-----------------------
#!/bin/ruby
require 'socket'
sock = Dir.glob("#{ENV['HOME']}/.w3m/w3msock*")
exit if (sock.size < 1)
UNIXSocket.open(sock[0]) {|f|
ARGV.each {|cmd|
f.puts(cmd)
}
}
-----------------------
portability
socket
mozilla -remote w3m -remote
w3m
Index: acinclude.m4
===================================================================
RCS file: /cvsroot/w3m/w3m/acinclude.m4,v
retrieving revision 1.40
diff -u -r1.40 acinclude.m4
--- acinclude.m4 14 Feb 2005 16:36:30 -0000 1.40
+++ acinclude.m4 21 Jun 2005 13:51:01 -0000
@@ -70,6 +70,18 @@
AC_MSG_RESULT($enable_mouse)])
#
# ----------------------------------------------------------------
+# AC_W3M_REMOTE
+# ----------------------------------------------------------------
+AC_DEFUN([AC_W3M_REMOTE],
+[AC_SUBST(USE_MOUSE)
+AC_MSG_CHECKING(if remote operation enabled)
+AC_ARG_ENABLE(remote,
+ [ --disable-remote disable remote operation],,
+ [enable_remote="yes"])
+test x"$enable_remote" = xyes && AC_DEFINE(USE_REMOTE)
+AC_MSG_RESULT($enable_remote)])
+#
+# ----------------------------------------------------------------
# AC_W3M_COOKIE
# ----------------------------------------------------------------
AC_DEFUN([AC_W3M_COOKIE],
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/w3m/w3m/aclocal.m4,v
retrieving revision 1.41
diff -u -r1.41 aclocal.m4
--- aclocal.m4 14 Feb 2005 16:36:30 -0000 1.41
+++ aclocal.m4 21 Jun 2005 13:51:03 -0000
@@ -82,6 +82,18 @@
AC_MSG_RESULT($enable_mouse)])
#
# ----------------------------------------------------------------
+# AC_W3M_REMOTE
+# ----------------------------------------------------------------
+AC_DEFUN([AC_W3M_REMOTE],
+[AC_SUBST(USE_MOUSE)
+AC_MSG_CHECKING(if remote operation enabled)
+AC_ARG_ENABLE(remote,
+ [ --disable-remote disable remote operation],,
+ [enable_remote="yes"])
+test x"$enable_remote" = xyes && AC_DEFINE(USE_REMOTE)
+AC_MSG_RESULT($enable_remote)])
+#
+# ----------------------------------------------------------------
# AC_W3M_COOKIE
# ----------------------------------------------------------------
AC_DEFUN([AC_W3M_COOKIE],
Index: config.h.in
===================================================================
RCS file: /cvsroot/w3m/w3m/config.h.in,v
retrieving revision 1.16
diff -u -r1.16 config.h.in
--- config.h.in 26 Feb 2005 17:06:44 -0000 1.16
+++ config.h.in 21 Jun 2005 13:51:03 -0000
@@ -53,6 +53,7 @@
#undef USE_MIGEMO
#define USE_MARK
#undef USE_MOUSE
+#undef USE_REMOTE
#undef USE_GPM
#undef USE_SYSMOUSE
#undef USE_MENU
Index: configure
===================================================================
RCS file: /cvsroot/w3m/w3m/configure,v
retrieving revision 1.153
diff -u -r1.153 configure
--- configure 26 Feb 2005 17:13:58 -0000 1.153
+++ configure 21 Jun 2005 13:51:09 -0000
@@ -310,7 +310,7 @@
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE VERSION W3M W3M_LANG AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB PERL NKF MAN build build_cpu build_vendor build_os host host_cpu host_vendor host_os W3M_TARGET W3M_LIBS USE_M17N USE_UNICODE WCTARGET WCCFLAGS DISPLAY_CHARSET SYSTEM_CHARSET DOCUMENT_CHARSET POSUBST POLANG MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE LIBICONV LTLIBICONV INTLLIBS LIBINTL LTLIBINTL POSUB INTLTARGET NLSTARGET USE_COLOR USE_ANSI_COLOR USE_BG_COLOR USE_IMAGE USE_W3
MIMG_X11 USE_W3MIMG_FB W3MIMGDISPLAY_SETUID INSTALL_W3MIMGDISPLAY USE_GDKPIXBUF USE_GTK2 !
USE_IMLIB USE_IMLIB2 IMGTARGETS IMGOBJS IMGX11CFLAGS IMGX11LDFLAGS IMGFBCFLAGS IMGFBLDFLAGS USE_XFACE uncompface KEYMAP_FILE HELP_FILE KEYBIND USE_MENU USE_MOUSE USE_HISTORY USE_ALARM USE_COOKIE USE_DIGEST_AUTH USE_NNTP USE_GOPHER USE_DICT USE_HELP_CGI USE_EXTERNAL_URI_LOADER USE_W3MMAILER USE_MIGEMO DEF_MIGEMO_COMMAND DEF_EDITOR DEF_MAILER DEF_EXT_BROWSER INET6 HAVE_OLD_SS_FAMILY USE_SSL USE_SSL_VERIFY PKG_CONFIG SSL_CFLAGS SSL_LIBS USE_W3M USE_SYSMOUSE AUXBIN_TARGETS EGREP USE_BINMODE_STREAM HAVE_SYS_ERRLIST HAVE_SIGSETJMP RETSIGTYPE SIGNAL_RETURN HELP_DIR RC_DIR DOCDIRS CURRENT_VERSION LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE VERSION W3M W3M_LANG AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB PERL NKF MAN build build_cpu build_vendor build_os host host_cpu host_vendor host_os W3M_TARGET W3M_LIBS USE_M17N USE_UNICODE WCTARGET WCCFLAGS DISPLAY_CHARSET SYSTEM_CHARSET DOCUMENT_CHARSET POSUBST POLANG MKINSTALLDIRS USE_NLS MSGFMT GMSGFMT XGETTEXT MSGMERGE LIBICONV LTLIBICONV INTLLIBS LIBINTL LTLIBINTL POSUB INTLTARGET NLSTARGET USE_COLOR USE_ANSI_COLOR USE_BG_COLOR USE_IMAGE USE_W3
MIMG_X11 USE_W3MIMG_FB W3MIMGDISPLAY_SETUID INSTALL_W3MIMGDISPLAY USE_GDKPIXBUF USE_GTK2 !
USE_IMLIB USE_IMLIB2 IMGTARGETS IMGOBJS IMGX11CFLAGS IMGX11LDFLAGS IMGFBCFLAGS IMGFBLDFLAGS USE_XFACE uncompface KEYMAP_FILE HELP_FILE KEYBIND USE_MENU USE_MOUSE USE_REMOTE USE_HISTORY USE_ALARM USE_COOKIE USE_DIGEST_AUTH USE_NNTP USE_GOPHER USE_DICT USE_HELP_CGI USE_EXTERNAL_URI_LOADER USE_W3MMAILER USE_MIGEMO DEF_MIGEMO_COMMAND DEF_EDITOR DEF_MAILER DEF_EXT_BROWSER INET6 HAVE_OLD_SS_FAMILY USE_SSL USE_SSL_VERIFY PKG_CONFIG SSL_CFLAGS SSL_LIBS USE_W3M USE_SYSMOUSE AUXBIN_TARGETS EGREP USE_BINMODE_STREAM HAVE_SYS_ERRLIST HAVE_SIGSETJMP RETSIGTYPE SIGNAL_RETURN HELP_DIR RC_DIR DOCDIRS CURRENT_VERSION LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@@ -5424,6 +5424,22 @@
echo "$as_me:$LINENO: result: $enable_mouse" >&5
echo "${ECHO_T}$enable_mouse" >&6
+echo "$as_me:$LINENO: checking if remote operation enabled" >&5
+echo $ECHO_N "checking if remote operation enabled... $ECHO_C" >&6
+# Check whether --enable-remote or --disable-remote was given.
+if test "${enable_remote+set}" = set; then
+ enableval="$enable_remote"
+
+else
+ enable_remote="yes"
+fi;
+test x"$enable_remote" = xyes && cat >>confdefs.h <<\_ACEOF
+#define USE_REMOTE 1
+_ACEOF
+
+echo "$as_me:$LINENO: result: $enable_remote" >&5
+echo "${ECHO_T}$enable_remote" >&6
+
echo "$as_me:$LINENO: checking if URL history is enabled" >&5
echo $ECHO_N "checking if URL history is enabled... $ECHO_C" >&6
# Check whether --enable-history or --disable-history was given.
@@ -11011,6 +11027,7 @@
s,@KEYBIND@,$KEYBIND,;t t
s,@USE_MENU@,$USE_MENU,;t t
s,@USE_MOUSE@,$USE_MOUSE,;t t
+s,@USE_REMOTE@,$USE_REMOTE,;t t
s,@USE_HISTORY@,$USE_HISTORY,;t t
s,@USE_ALARM@,$USE_ALARM,;t t
s,@USE_COOKIE@,$USE_COOKIE,;t t
Index: configure.ac
===================================================================
RCS file: /cvsroot/w3m/w3m/configure.ac,v
retrieving revision 1.1
diff -u -r1.1 configure.ac
--- configure.ac 26 Feb 2005 17:13:59 -0000 1.1
+++ configure.ac 21 Jun 2005 13:51:09 -0000
@@ -67,6 +67,7 @@
AC_W3M_MOUSE
AC_W3M_HISTORY
AC_W3M_ALARM
+AC_W3M_REMOTE
AC_W3M_COOKIE
AC_W3M_DIGEST_AUTH
Index: main.c
===================================================================
RCS file: /cvsroot/w3m/w3m/main.c,v
retrieving revision 1.247
diff -u -r1.247 main.c
--- main.c 26 Feb 2005 17:06:44 -0000 1.247
+++ main.c 21 Jun 2005 13:51:09 -0000
@@ -14,6 +14,12 @@
#include "terms.h"
#include "myctype.h"
#include "regex.h"
+
+#ifdef USE_REMOTE
+#include <sys/socket.h>
+#include <sys/un.h>
+#endif
+
#ifdef USE_MOUSE
#ifdef USE_GPM
#include <gpm.h>
@@ -104,6 +110,15 @@
#define help() fusage(stdout, 0)
#define usage() fusage(stderr, 1)
+#ifdef USE_REMOTE
+static void init_remote(void);
+static void parse_sock_data(void);
+static Str SockName;
+static int SockFd, UseRemote = FALSE;
+struct sockaddr_un SockAddr;
+socklen_t SockLength;
+#endif
+
static void
fversion(FILE * f)
{
@@ -134,6 +149,9 @@
",sysmouse"
#endif
#endif
+#ifdef USE_REMOTE
+ ",remote"
+#endif
#ifdef USE_MENU
",menu"
#endif
@@ -229,6 +247,9 @@
#ifdef USE_MOUSE
fprintf(f, " -no-mouse don't use mouse\n");
#endif /* USE_MOUSE */
+#ifdef USE_REMOTE
+ fprintf(f, " -enable_remote use remote operation\n");
+#endif /* USE_MOUSE */
#ifdef USE_COOKIE
fprintf(f,
" -cookie use cookie (-no-cookie: don't use cookie)\n");
@@ -727,6 +748,11 @@
else if (!strcmp("-dummy", argv[i])) {
/* do nothing */
}
+#ifdef USE_REMOTE
+ else if (!strcmp("-enable_remote", argv[i])) {
+ UseRemote = TRUE;
+ }
+#endif
else if (!strcmp("-debug", argv[i]))
w3m_debug = TRUE;
else {
@@ -1028,6 +1054,13 @@
if (line_str) {
_goLine(line_str);
}
+
+#ifdef USE_REMOTE
+ if (UseRemote) {
+ init_remote();
+ }
+#endif
+
for (;;) {
if (add_download_list) {
add_download_list = FALSE;
@@ -1098,7 +1131,20 @@
} while (sleep_till_anykey(1, 0) <= 0);
}
#endif
+#ifdef USE_REMOTE
+ if (UseRemote) {
+ int n;
+ c = getch_select(SockFd, &n);
+ if (n == 1) {
+ parse_sock_data();
+ continue;
+ }
+ } else {
+ c = getch();
+ }
+#else
c = getch();
+#endif
#ifdef SIGWINCH
mySignal(SIGWINCH, resize_hook);
#endif
@@ -1130,6 +1176,92 @@
}
}
+#ifdef USE_REMOTE
+static void
+init_remote(void)
+{
+ SockName = Sprintf("%s/w3msock%d", rc_dir, CurrentPid);
+ if (sizeof(SockAddr.sun_path) <= SockName->length)
+ goto SockErr;
+
+ SockAddr.sun_family = AF_UNIX;
+ strcpy(SockAddr.sun_path, SockName->ptr);
+ SockLength = sizeof(SockAddr.sun_family) + strlen(SockAddr.sun_path);
+
+ if ((SockFd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
+ goto SockErr;
+
+ unlink(SockName->ptr);
+ if (bind(SockFd, (struct sockaddr *) &SockAddr, SockLength))
+ goto SockErr;
+
+ chmod(SockName->ptr, S_IRUSR | S_IWUSR);
+
+ if (listen(SockFd, 5))
+ goto SockErr;
+
+ fcntl(SockFd, F_SETFL, O_NONBLOCK);
+
+ return;
+
+ SockErr:
+ unlink(SockName->ptr);
+ if (SockFd >= 0) {
+ close(SockFd);
+ }
+ SockFd = -1;
+ UseRemote = FALSE;
+}
+
+static
+void parse_sock_data(void)
+{
+ Str data = NULL;
+ char buf[64];
+ char *p, *q, *s;
+ int l, f, i, conn;
+
+ if (!UseRemote || SockFd < 0) {
+ return;
+ }
+
+ if (!data)
+ data = Strnew();
+
+ conn = accept(SockFd, (struct sockaddr *) &SockAddr, &SockLength);
+
+ if (conn < 0)
+ return;
+
+ i = 0;
+ while ((l = read(conn, buf, sizeof(buf))) > 0) {
+ Strcat_charp_n(data, buf, l);
+ }
+
+ p = data->ptr;
+
+ while ((q = strchr(p, '\n'))) {
+ Str funcname = Strnew();
+ Str cmd = Strnew_charp_n(p, q - p);
+
+ s = cmd->ptr;
+ SKIP_BLANKS(s);
+ while (*s && !IS_SPACE(*s))
+ Strcat_char(funcname, *(s++));
+
+ SKIP_BLANKS(s);
+ f = getFuncList(funcname->ptr);
+ if (f >= 0) {
+ Str tmp = Strnew_charp(s);
+ Strchop(tmp);
+ pushEvent(f, tmp->ptr);
+ }
+ p = q + 1;
+ }
+ close(conn);
+}
+#endif
+
static void
keyPressEventProc(int c)
{
@@ -5714,6 +5846,11 @@
#ifdef USE_NNTP
disconnectNews();
#endif
+#ifdef USE_REMOTE
+ if (UseRemote) {
+ unlink(SockName->ptr);
+ }
+#endif
exit(i);
}
Index: proto.h
===================================================================
RCS file: /cvsroot/w3m/w3m/proto.h,v
retrieving revision 1.99
diff -u -r1.99 proto.h
--- proto.h 16 Apr 2004 18:47:19 -0000 1.99
+++ proto.h 21 Jun 2005 13:51:09 -0000
@@ -492,6 +492,9 @@
extern void flush_tty(void);
extern void toggle_stand(void);
extern char getch(void);
+#ifdef USE_REMOTE
+char getch_select(int fd, int *num);
+#endif
extern void bell(void);
extern int sleep_till_anykey(int sec, int purge);
#ifdef USE_IMAGE
Index: terms.c
===================================================================
RCS file: /cvsroot/w3m/w3m/terms.c,v
retrieving revision 1.53
diff -u -r1.53 terms.c
--- terms.c 18 Jan 2005 16:38:01 -0000 1.53
+++ terms.c 21 Jun 2005 13:51:09 -0000
@@ -1830,6 +1830,44 @@
return c;
}
+#ifdef USE_REMOTE
+char
+getch_select(int fd, int *num)
+{
+ int maxfd = tty;
+ fd_set rset;
+
+ if (fd < 0 || fd == tty) {
+ *num = 0;
+ return getch();
+ }
+
+ if (maxfd < fd)
+ maxfd = fd;
+
+ maxfd++;
+
+ FD_ZERO(&rset);
+ FD_SET(tty, &rset);
+ FD_SET(fd, &rset);
+
+ while (select(maxfd, &rset, NULL, NULL, NULL) < 1) {
+ FD_ZERO(&rset);
+ FD_SET(tty, &rset);
+ FD_SET(fd, &rset);
+ }
+
+ if (FD_ISSET(tty, &rset)) {
+ *num = 0;
+ return getch();
+ } else if (FD_ISSET(fd, &rset)) {
+ *num = 1;
+ }
+ return 0;
+}
+#endif
+
+
#ifdef USE_MOUSE
#ifdef USE_GPM
char