lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev [PATCH 2.8.5-dev14] Cut&paste on unix


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.5-dev14] Cut&paste on unix
Date: Tue, 18 Feb 2003 22:33:31 -0800
User-agent: Mutt/1.4i

This is slightly reworked patch to GNU readlien of mine.  If
RL_PASTE_CMD and RL_CLCOPY_CMD are defined in the environment, lynx
will use them as commands to do cut&paste.

The simplest such commands could just store/retrieve things from
/tmp/.clipboard_user-name; more advanced ones could use X clipboard.

Enjoy,
Ilya

--- ./WWW/Library/Implementation/HTUtils.h-pre  Wed Jan 22 01:43:12 2003
+++ ./WWW/Library/Implementation/HTUtils.h      Tue Feb 18 19:03:40 2003
@@ -168,7 +168,7 @@ typedef unsigned short mode_t;
 #  define NO_EMPTY_HREFLESS_A
 #endif
 
-#if  defined(__EMX__) || defined(WIN_EX)
+#if  defined(__EMX__) || defined(WIN_EX) || defined(HAVE_POPEN)
 #  define CAN_CUT_AND_PASTE
 #endif
 
--- ./src/LYUtils.c-ppre        Wed Jan 22 01:43:12 2003
+++ ./src/LYUtils.c     Tue Feb 18 19:02:04 2003
@@ -7309,6 +7319,92 @@ PUBLIC void get_clip_release NOARGS
     clip_open = 0;
     unmorph_PM();
 }
+
+#else  /* !( defined __EMX__ ) */ 
+
+#  if !defined(WIN_EX) && defined(HAVE_POPEN)
+
+#    define xfree free
+#    define xmalloc malloc
+#    define xrealloc realloc
+
+static FILE* paste_handle = 0;
+static char *paste_buf = NULL;
+
+PUBLIC void get_clip_release NOARGS
+{
+  if (paste_handle >= 0)
+    pclose(paste_handle);
+  if (paste_buf)
+    xfree (paste_buf);
+}
+
+PRIVATE int clip_grab NOARGS
+{
+  char *cmd = getenv ("RL_PASTE_CMD");
+
+  if (paste_handle)
+    pclose(paste_handle);
+  if (!cmd)
+    return 0;
+
+  paste_handle = popen(cmd, "rt");
+  if (!paste_handle)
+    return 0;
+  return 1;
+}
+
+#define PASTE_BUFFER 1008
+#define CF_TEXT 0                      /* Not used */
+
+PUBLIC char* get_clip_grab NOARGS
+{
+  char *ClipData;
+  int len, size = PASTE_BUFFER;
+  int off = 0;
+
+  if (!clip_grab())
+     return NULL;
+  if (!paste_handle)
+    return NULL;  
+  if (paste_buf)
+    xfree (paste_buf);
+  paste_buf = (char*)xmalloc (PASTE_BUFFER);
+  while (1)
+    {
+      len = fread (paste_buf + off, 1, PASTE_BUFFER - 1, paste_handle);
+      paste_buf[off + len] = '\0';
+      if (len < PASTE_BUFFER - 1)
+       break;
+      if (strchr (paste_buf + off, '\r') || strchr (paste_buf + off, '\n'))
+       break;
+      paste_buf = xrealloc (paste_buf, size += PASTE_BUFFER - 1);
+      off += len;
+    } 
+  return paste_buf;
+}
+
+PUBLIC int
+put_clip (s)
+     char * s;
+{
+  char *cmd = getenv ("RL_CLCOPY_CMD");
+  FILE *fh;
+  int l = strlen(s), res;
+
+  if (!cmd)
+    return -1;
+
+  fh = popen (cmd, "wt");
+  if (!fh)
+    return -1;
+  res = fwrite (s, 1, l, fh);
+  if (pclose (fh) != 0 || res != l)
+    return -1;
+  return 0;
+}
+
+#  endif       /* !defined(WIN_EX) && defined(HAVE_POPEN) */ 
 
 #endif
 

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]