changeset 17038:f7a1e78fe210

Include charset.h. (Vload_source_file_function): New variable. (Fload): Call Vload_source_file_function if defined while loading an Emacs Lisp source file. */ (read_multibyte): New function. (read_escape): Handle multibyte characters. (read1): Correct the value of size_in_chars of a bool vector. Handle the case `?' is followed by a multibyte character. (Vload_source_file_function): New variable.
author Karl Heuer <kwzh@gnu.org>
date Thu, 20 Feb 1997 06:52:14 +0000
parents af637c0168ad
children b63ed55bed46
files src/lread.c
diffstat 1 files changed, 57 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lread.c	Thu Feb 20 06:51:43 1997 +0000
+++ b/src/lread.c	Thu Feb 20 06:52:14 1997 +0000
@@ -30,6 +30,7 @@
 
 #ifndef standalone
 #include "buffer.h"
+#include "charset.h"
 #include <paths.h>
 #include "commands.h"
 #include "keyboard.h"
@@ -109,6 +110,10 @@
 /* Nonzero means load should forcibly load all dynamic doc strings.  */
 static int load_force_doc_strings;
 
+/* Function to use for loading an Emacs lisp source file (not
+   compiled) instead of readevalloop.  */
+Lisp_Object Vload_source_file_function;
+
 /* List of descriptors now open for Fload.  */
 static Lisp_Object load_descriptor_list;
 
@@ -139,7 +144,11 @@
 
 /* Handle unreading and rereading of characters.
    Write READCHAR to read a character,
-   UNREAD(c) to unread c to be read again. */
+   UNREAD(c) to unread c to be read again.
+
+   These macros actually read/unread a byte code, multibyte characters
+   are not handled here.  The caller should manage them if necessary.
+ */
 
 #define READCHAR readchar (readcharfun)
 #define UNREAD(c) unreadchar (readcharfun, c)
@@ -468,6 +477,17 @@
 	}
       XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
     }
+  else
+    {
+      /* We are loading a source file (*.el).  */
+      if (!NILP (Vload_source_file_function))
+	{
+	  close (fd);
+	  return call3 (Vload_source_file_function, found, file,
+			NILP (noerror) ? Qnil : Qt,
+			NILP (nomessage) ? Qnil : Qt);
+	}
+    }
 
 #ifdef DOS_NT
   close (fd);
@@ -1085,6 +1105,27 @@
 static int read_buffer_size;
 static char *read_buffer;
 
+/* Read multibyte form and return it as a character.  C is a first
+   byte of multibyte form, and rest of them are read from
+   READCHARFUN.  */
+static int
+read_multibyte (c, readcharfun)
+     register int c;
+     Lisp_Object readcharfun;
+{
+  /* We need the actual character code of this multibyte
+     characters.  */
+  unsigned char str[MAX_LENGTH_OF_MULTI_BYTE_FORM];
+  int len = 0;
+
+  str[len++] = c;
+  while ((c = READCHAR) >= 0xA0
+	 && len < MAX_LENGTH_OF_MULTI_BYTE_FORM)
+    str[len++] = c;
+  UNREAD (c);
+  return STRING_CHAR (str, len);
+}
+
 static int
 read_escape (readcharfun)
      Lisp_Object readcharfun;
@@ -1239,6 +1280,8 @@
       }
 
     default:
+      if (BASE_LEADING_CODE_P (c))
+	c = read_multibyte (c, readcharfun);
       return c;
     }
 }
@@ -1523,9 +1566,10 @@
 	if (c < 0) return Fsignal (Qend_of_file, Qnil);
 
 	if (c == '\\')
-	  XSETINT (val, read_escape (readcharfun));
-	else
-	  XSETINT (val, c);
+	  c = read_escape (readcharfun);
+	else if (BASE_LEADING_CODE_P (c))
+	  c = read_multibyte (c, readcharfun);
+	XSETINT (val, c);
 
 	return val;
       }
@@ -2596,6 +2640,15 @@
 The default is nil, which means use the function `read'.");
   Vload_read_function = Qnil;
 
+  DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
+    "Function called in `load' for loading an Emacs lisp source file.\n\
+This function is for doing code conversion before reading the source file.\n\
+If nil, loading is done without any code conversion.\n\
+Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
+ FULLNAME is the full name of FILE.\n\
+See `load' for the meaning of the remaining arguments.");
+  Vload_source_file_function = Qnil;
+
   DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
      "Non-nil means `load' should force-load all dynamic doc strings.\n\
 This is useful when the file being loaded is a temporary copy.");