[librep] use readline history in interactive mode -- properly exit the rep interpreter -- no c++ style commen



commit bc03b707c6af150f4837af219c0f483623d6acb5
Author: chrisb <zanghar freenet de>
Date:   Sat Aug 22 22:38:00 2009 +0200

    use readline history in interactive mode -- properly exit the rep interpreter -- no c++ style comments in c code

 ChangeLog      |    8 ++++++++
 config.h.in    |    3 +++
 man/news.texi  |    6 ++++++
 src/lisp.c     |   18 +++++++++---------
 src/readline.c |   20 ++++++++++++++++++++
 src/rep.c      |    6 ++++--
 src/utf8.c     |   44 ++++++++++++++++++++++----------------------
 7 files changed, 72 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2955337..f7c3847 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-08-22  Christopher Bratusek <zanghar freenet de>
+	* src/rep.c: properly terminate rep interpreter [Jürgen Hötzel]
+
+	* src/readline.c: save/load readline history in interactive mode [Jürgen Hötzel]
+
+	* src/lisp.c
+	* src/uft8.c: No C++ style comments in C code
+
 2009-07-25  Christopher Bratusek <zanghar freenet de>
 	* librep.pc.in: add -L$prefix to libs
 
diff --git a/config.h.in b/config.h.in
index b5bab1e..25803ee 100644
--- a/config.h.in
+++ b/config.h.in
@@ -303,6 +303,9 @@
 /* Define to the one symbol short name of this package. */
 #undef PACKAGE_TARNAME
 
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
diff --git a/man/news.texi b/man/news.texi
index 951681a..d24bfbc 100644
--- a/man/news.texi
+++ b/man/news.texi
@@ -7,6 +7,10 @@
 
 @itemize @bullet
 
+ item Properly terminate the rep interpreter [Jürgen Hötzel]
+
+ item Use readline history in interactive mode [Jürgen Hötzel]
+
 @item Tar file-handler does now support XZ compressed tarballs
 
 @item Tar file-handler does now support LZMA compressed tarballs
@@ -22,6 +26,8 @@
 @item Fixed an incomplete definition
 
 @item Added -L$prefix to libs section of the .pc file
+
+ item No C++ style comments in C code
 @end itemize
 
 @heading 0.90.0
diff --git a/src/lisp.c b/src/lisp.c
index ce9397a..c04473c 100644
--- a/src/lisp.c
+++ b/src/lisp.c
@@ -232,7 +232,7 @@ fast_getc (repv stream)
     else
 	return rep_stream_getc (stream);
 }
- 
+
 static repv
 signal_reader_error (repv type, repv stream, char *message)
 {
@@ -332,7 +332,7 @@ read_list(repv strm, register int *c_p)
 	case ']':
 	    *c_p = rep_stream_getc(strm);
 	    goto end;
-	    
+
 	case '.':
 	    *c_p = rep_stream_getc(strm);
 	    switch (*c_p)
@@ -851,7 +851,7 @@ readl(repv strm, register int *c_p, repv end_of_stream_error)
 	case '(':
 	    return read_list(strm, c_p);
 
-	case '\'': case '`': 
+	case '\'': case '`':
 	    /* 'X => (quote X)
 	       `X => (backquote X) */
 	    form = Fcons(*c_p == '\'' ? Qquote : Qbackquote,
@@ -1393,7 +1393,7 @@ bind_lambda_list(repv lambdaList, repv argList)
 
     /* Evaluate arguments, and stick them in the evalled_args array */
     copy_to_vector (argList, argc, argv);
-   
+
     return bind_lambda_list_1 (lambdaList, argv, argc);
 }
 
@@ -2078,10 +2078,10 @@ rep_call_lispn (repv fun, int argc, repv *argv)
 	rep_PUSH_CALL (lc);
 	rep_USE_FUNARG (fun);
 	bc_apply = rep_STRUCTURE (rep_structure)->apply_bytecode;
-	if (bc_apply == 0)
+	/* if (bc_apply == 0) */
 	    ret = rep_apply_bytecode (rep_FUNARG (fun)->fun, argc, argv);
-	else
-	    ret = bc_apply (rep_FUNARG (fun)->fun, argc, argv);
+	/* else
+        ret = bc_apply (rep_FUNARG (fun)->fun, argc, argv); */
 	rep_POP_CALL (lc);
 	return ret;
     }
@@ -2500,7 +2500,7 @@ handler.
 	fprintf (stderr, "\nLisp backtrace:\n");
 	Fbacktrace (Fstderr_file());
 	fputs ("\n", stderr);
-    }	
+    }
 
     errlist = Fcons(error, data);
     on_error = Fsymbol_value(Qdebug_on_error, Qt);
@@ -2841,7 +2841,7 @@ rep_lisp_init(void)
     rep_term_cell = Fcons(Qterm_interrupt, Qnil);
     rep_mark_static(&rep_term_cell);
 
-    rep_INTERN_SPECIAL(print_escape); 
+    rep_INTERN_SPECIAL(print_escape);
     rep_INTERN_SPECIAL(print_length);
     rep_INTERN_SPECIAL(print_level);
     Fset (Qprint_escape, Qnil);
diff --git a/src/readline.c b/src/readline.c
index 1ee0189..5977a6d 100644
--- a/src/readline.c
+++ b/src/readline.c
@@ -43,6 +43,7 @@ static repv completion_fun;
 static repv completions;
 
 #ifdef HAVE_LIBREADLINE
+static char *history_file = NULL;
 static char *
 completion_generator (char *word, int state)
 {
@@ -229,6 +230,14 @@ rep_dl_init(void)
 #ifdef HAVE_LIBREADLINE
     rl_completion_entry_function = (void *) completion_generator;
     rl_basic_quote_characters = "\"";
+    if (isatty (0) && getenv("HOME"))
+    {
+      history_file=(char*) malloc((uint) strlen(getenv("HOME")) + (uint) strlen("/.rep_history") +2);
+      if (history_file) {
+       sprintf(history_file, "%s/.rep_history",getenv("HOME"));
+       read_history(history_file);
+      }
+    }
     init_bouncing_parens();
 #endif
     tem = rep_push_structure ("rep.io.readline");
@@ -237,3 +246,14 @@ rep_dl_init(void)
     rep_ADD_SUBR(Sreadline);
     return rep_pop_structure (tem);
 }
+
+#ifdef HAVE_LIBREADLINE
+void
+rep_dl_kill (void)
+{
+  if (history_file) {
+    write_history(history_file);
+    free(history_file);
+  }  
+}
+#endif
diff --git a/src/rep.c b/src/rep.c
index 65e9f04..e1d8489 100644
--- a/src/rep.c
+++ b/src/rep.c
@@ -19,7 +19,7 @@ int
 main(int argc, char **argv)
 {
     DEFSTRING (rep, "rep/user");
-
+    int exit_status;
     char *prog_name = *argv++;
     argc--;
 
@@ -32,5 +32,7 @@ main(int argc, char **argv)
     rep_call_with_barrier (rep_load_environment, rep_VAL (&rep),
 			   rep_TRUE, 0, 0, 0);
 
-    return rep_top_level_exit ();
+    exit_status = rep_top_level_exit ();
+    rep_kill();
+    return exit_status;
 }
diff --git a/src/utf8.c b/src/utf8.c
index 0982269..35f8a66 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -23,7 +23,7 @@
  *
  */
 
-// More functions for utf-8 are available in glib-x.y.z/glib/gutf8.c.
+/* More functions for utf-8 are available in glib-x.y.z/glib/gutf8.c. */
 
 #define _GNU_SOURCE
 
@@ -47,7 +47,7 @@ const char * const utf8_skip = utf8_skip_data;
 long
 utf8_strlen (const char *p,
 	     int       max);
-long    
+long
 utf8_pointer_to_offset (const char *str,
 			const char *pos);
 char *
@@ -58,9 +58,9 @@ utf8_offset_to_pointer  (const char *str,
  * @p: pointer to the start of a UTF-8 encoded string.
  * @max: the maximum number of bytes to examine. If @max
  *       is less than 0, then the string is assumed to be
- *       nul-terminated. If @max is 0, @p will not be examined and 
+ *       nul-terminated. If @max is 0, @p will not be examined and
  *       may be %NULL.
- * 
+ *
  * Returns the length of the string in characters.
  *
  * Return value: the length of the string in characters
@@ -74,7 +74,7 @@ utf8_strlen (const char *p,
 
   if(p == NULL || max == 0)
        return 0;
-  
+
   if (max < 0)
     {
       while (*p)
@@ -87,13 +87,13 @@ utf8_strlen (const char *p,
     {
       if (max == 0 || !*p)
         return 0;
-      
-      p = utf8_next_char (p);          
+
+      p = utf8_next_char (p);
 
       while (p - start < max && *p)
         {
           ++len;
-          p = utf8_next_char (p);          
+          p = utf8_next_char (p);
         }
 
       /* only do the last len increment if we got a complete
@@ -111,23 +111,23 @@ utf8_strlen (const char *p,
  * utf8_pointer_to_offset:
  * @str: a UTF-8 encoded string
  * @pos: a pointer to a position within @str
- * 
+ *
  * Converts from a pointer to position within a string to a integer
  * character offset.
  *
  * this function allows @pos to be before @str, and returns
  * a negative offset in this case.
- * 
+ *
  * Return value: the resulting character offset
  **/
-long    
+long
 utf8_pointer_to_offset (const char *str,
 			  const char *pos)
 {
   const char *s = str;
-  long offset = 0;    
+  long offset = 0;
 
-  if (pos < str) 
+  if (pos < str)
     offset = - utf8_pointer_to_offset (pos, str);
   else
     while (s < pos)
@@ -135,7 +135,7 @@ utf8_pointer_to_offset (const char *str,
 	s = utf8_next_char (s);
 	offset++;
       }
-  
+
   return offset;
 }
 
@@ -143,32 +143,32 @@ utf8_pointer_to_offset (const char *str,
  * utf8_offset_to_pointer:
  * @str: a UTF-8 encoded string
  * @offset: a character offset within @str
- * 
+ *
  * Converts from an integer character offset to a pointer to a position
  * within the string.
- * 
+ *
  * this function allows to pass a negative @offset to
  * step backwards. It is usually worth stepping backwards from the end
- * instead of forwards if @offset is in the last fourth of the string, 
+ * instead of forwards if @offset is in the last fourth of the string,
  * since moving forward is about 3 times faster than moving backward.
- * 
+ *
  * Return value: the resulting pointer
  **/
 char *
 utf8_offset_to_pointer  (const char *str,
-			   long        offset)    
+			   long        offset)
 {
   const char *s = str;
 
-  if (offset > 0) 
+  if (offset > 0)
     while (offset--)
       s = utf8_next_char (s);
   else
     {
       const char *s1;
 
-      /* This nice technique for fast backwards stepping 
-       * through a UTF-8 string was dubbed "stutter stepping" 
+      /* This nice technique for fast backwards stepping
+       * through a UTF-8 string was dubbed "stutter stepping"
        * by its inventor, Larry Ewing.
        */
       while (offset)



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