*** empty log message ***
[bpt/guile.git] / guile-readline / readline.c
index fb6b7d0..9480b3d 100644 (file)
@@ -1,6 +1,6 @@
 /* readline.c --- line editing support for Guile */
 
-/*     Copyright (C) 1997,1999 Free Software Foundation, Inc.
+/*     Copyright (C) 1997,1999, 2000 Free Software Foundation, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@
 #include <readline/history.h>
 #include <sys/time.h>
 
-#include "libguile/scm_validate.h"
+#include "libguile/validate.h"
 #include "readline.h"
 
 scm_option scm_readline_opts[] = {
@@ -48,7 +48,7 @@ scm_option scm_readline_opts[] = {
 
 extern void stifle_history (int max);
 
-GUILE_PROC (scm_readline_options, "readline-options-interface", 0, 1, 0, 
+SCM_DEFINE (scm_readline_options, "readline-options-interface", 0, 1, 0, 
             (SCM setting),
 "")
 #define FUNC_NAME s_scm_readline_options
@@ -125,14 +125,12 @@ static SCM before_read;
 static int
 current_input_getc (FILE *in)
 {
-  SCM ans;
   if (promptp && SCM_NIMP (before_read))
     {
       scm_apply (before_read, SCM_EOL, SCM_EOL);
       promptp = 0;
     }
-  ans = scm_getc (input_port);
-  return ans;
+  return scm_getc (input_port);
 }
 
 static void
@@ -152,7 +150,7 @@ static SCM handle_error (void *data, SCM tag, SCM args);
 static void reentry_barrier ();
 
 
-GUILE_PROC (scm_readline, "%readline", 0, 4, 0, 
+SCM_DEFINE (scm_readline, "%readline", 0, 4, 0, 
             (SCM text, SCM inp, SCM outp, SCM read_hook),
 "")
 #define FUNC_NAME s_scm_readline
@@ -319,13 +317,13 @@ scm_readline_init_ports (SCM inp, SCM outp)
 
 
 
-GUILE_PROC (scm_add_history, "add-history", 1, 0, 0, 
+SCM_DEFINE (scm_add_history, "add-history", 1, 0, 0, 
             (SCM text),
 "")
 #define FUNC_NAME s_scm_add_history
 {
   char* s;
-  SCM_VALIDATE_STRING(1,text);
+  SCM_VALIDATE_STRING (1,text);
   SCM_COERCE_SUBSTR (text);
 
   s = SCM_CHARS (text);
@@ -336,36 +334,36 @@ GUILE_PROC (scm_add_history, "add-history", 1, 0, 0,
 #undef FUNC_NAME
 
 
-GUILE_PROC (scm_read_history, "read-history", 1, 0, 0, 
+SCM_DEFINE (scm_read_history, "read-history", 1, 0, 0, 
             (SCM file),
 "")
 #define FUNC_NAME s_scm_read_history
 {
-  SCM_VALIDATE_STRING(1,file);
+  SCM_VALIDATE_STRING (1,file);
   return SCM_NEGATE_BOOL(read_history (SCM_ROCHARS (file)));
 }
 #undef FUNC_NAME
 
 
-GUILE_PROC (scm_write_history, "write-history", 1, 0, 0, 
+SCM_DEFINE (scm_write_history, "write-history", 1, 0, 0, 
             (SCM file),
 "")
 #define FUNC_NAME s_scm_write_history
 {
-  SCM_VALIDATE_STRING(1,file);
+  SCM_VALIDATE_STRING (1,file);
   return SCM_NEGATE_BOOL(write_history (SCM_ROCHARS (file)));
 }
 #undef FUNC_NAME
 
 
-GUILE_PROC (scm_filename_completion_function, "filename-completion-function", 2, 0, 0, 
+SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2, 0, 0, 
             (SCM text, SCM continuep),
 "")
 #define FUNC_NAME s_scm_filename_completion_function
 {
   char *s;
   SCM ans;
-  SCM_VALIDATE_STRING(1,text);
+  SCM_VALIDATE_STRING (1,text);
   SCM_COERCE_SUBSTR (text);
   s = filename_completion_function (SCM_CHARS (text), SCM_NFALSEP (continuep));
   ans = scm_makfrom0str (s);
@@ -409,18 +407,19 @@ completion_function (char *text, int continuep)
 
 /*Bouncing parenthesis (reimplemented by GH, 11/23/98, since readline is strict gpl)*/
 
-static void match_paren(int x, int k);
-static int find_matching_paren(int k);
-static void init_bouncing_parens();
+static int match_paren (int x, int k);
+static int find_matching_paren (int k);
+static void init_bouncing_parens ();
 
 static void
-init_bouncing_parens()
+init_bouncing_parens ()
 {
-  if(strncmp(rl_get_keymap_name(rl_get_keymap()), "vi", 2)) {
-    rl_bind_key(')', match_paren);
-    rl_bind_key(']', match_paren);
-    rl_bind_key('}', match_paren);
-  }
+  if (strncmp (rl_get_keymap_name (rl_get_keymap ()), "vi", 2))
+    {
+      rl_bind_key (')', match_paren);
+      rl_bind_key (']', match_paren);
+      rl_bind_key ('}', match_paren);
+    }
 }
 
 static int
@@ -455,44 +454,49 @@ find_matching_paren(int k)
        }
       else if (rl_line_buffer[i] == c)
        {
-         if (end_parens_found==0) return i;
+         if (end_parens_found==0)
+           return i;
          else --end_parens_found;
        }
     }
   return -1;
 }
 
-static void
-match_paren(int x, int k)
+static int
+match_paren (int x, int k)
 {
-  int tmp;
-  fd_set readset;
+  int tmp, fno;
+  SELECT_TYPE readset;
   struct timeval timeout;
   
-  rl_insert(x, k);
+  rl_insert (x, k);
   if (!SCM_READLINE_BOUNCE_PARENS)
-    return;
+    return 0;
 
   /* Did we just insert a quoted paren?  If so, then don't bounce.  */
   if (rl_point - 1 >= 1
       && rl_line_buffer[rl_point - 2] == '\\')
-    return;
+    return 0;
 
   tmp = 1000 * SCM_READLINE_BOUNCE_PARENS;
   timeout.tv_sec = tmp / 1000000;
   timeout.tv_usec = tmp % 1000000;
-  FD_ZERO(&readset);
-  FD_SET(fileno(rl_instream), &readset);
+  FD_ZERO (&readset);
+  fno = fileno (rl_instream);
+  FD_SET (fno, &readset);
   
-  if(rl_point > 1) {
-    tmp = rl_point;
-    rl_point = find_matching_paren(k);
-    if(rl_point > -1) {
-      rl_redisplay();
-      scm_internal_select(1, &readset, NULL, NULL, &timeout);
+  if (rl_point > 1)
+    {
+      tmp = rl_point;
+      rl_point = find_matching_paren (k);
+      if (rl_point > -1)
+       {
+         rl_redisplay ();
+         scm_internal_select (fno + 1, &readset, NULL, NULL, &timeout);
+       }
+      rl_point = tmp;
     }
-    rl_point = tmp;
-  }
+  return 0;
 }