/* Lisp parsing and input streams.
- Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 1998
+ Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 1999
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <sys/file.h>
#include <errno.h>
#include "lisp.h"
+#include "intervals.h"
#ifndef standalone
#include "buffer.h"
#include "charset.h"
-#include <paths.h>
+#include <epaths.h>
#include "commands.h"
#include "keyboard.h"
#include "termhooks.h"
#endif
#ifdef LISP_FLOAT_TYPE
-#ifdef STDC_HEADERS
-#include <stdlib.h>
-#endif
-
#include <math.h>
#endif /* LISP_FLOAT_TYPE */
#define O_RDONLY 0
#endif
+#ifdef HAVE_FTELLO
+#define file_offset off_t
+#define file_tell ftello
+#else
+#define file_offset long
+#define file_tell ftell
+#endif
+
extern int errno;
Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
/* Search path for files to be loaded. */
Lisp_Object Vload_path;
+/* File name of user's init file. */
+Lisp_Object Vuser_init_file;
+
/* This is the user-visible association list that maps features to
lists of defs in their load files. */
Lisp_Object Vload_history;
compiled) instead of readevalloop. */
Lisp_Object Vload_source_file_function;
+/* List of all DEFVAR_BOOL variables. Used by the byte optimizer. */
+Lisp_Object Vbyte_boolean_vars;
+
/* List of descriptors now open for Fload. */
static Lisp_Object load_descriptor_list;
/* Length of actual data in saved_doc_string. */
static int saved_doc_string_length;
/* This is the file position that string came from. */
-static int saved_doc_string_position;
+static file_offset saved_doc_string_position;
/* This contains the previous string skipped with #@.
We copy it from saved_doc_string when a new string
/* Length of actual data in prev_saved_doc_string. */
static int prev_saved_doc_string_length;
/* This is the file position that string came from. */
-static int prev_saved_doc_string_position;
+static file_offset prev_saved_doc_string_position;
/* Nonzero means inside a new-style backquote
with no surrounding parentheses.
Lisp_Object readcharfun;
{
Lisp_Object tem;
- register int c, mpos;
+ register int c;
if (BUFFERP (readcharfun))
{
static Lisp_Object read0 (), read1 (), read_list (), read_vector ();
static int read_multibyte ();
+static Lisp_Object substitute_object_recurse ();
+static void substitute_object_in_subtree (), substitute_in_interval ();
+
\f
/* Get a character from the tty. */
/* Convert certain symbols to their ASCII equivalents. */
if (SYMBOLP (val))
{
- Lisp_Object tem, tem1, tem2;
+ Lisp_Object tem, tem1;
tem = Fget (val, Qevent_symbol_element_mask);
if (!NILP (tem))
{
since it would try to load a directory as a Lisp file */
if (XSTRING (file)->size > 0)
{
- int size = XSTRING (file)->size;
+ int size = STRING_BYTES (XSTRING (file));
GCPRO1 (file);
return Qnil;
}
+ if (EQ (Qt, Vuser_init_file))
+ Vuser_init_file = found;
+
/* If FD is 0, that means openp found a magic file. */
if (fd == 0)
{
/* Load .elc files directly, but not when they are
remote and have no handler! */
- if (!bcmp (&(XSTRING (found)->data[XSTRING (found)->size - 4]),
+ if (!bcmp (&(XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 4]),
".elc", 4)
&& fd != 0)
{
fmode = "rb";
#endif /* DOS_NT */
stat ((char *)XSTRING (found)->data, &s1);
- XSTRING (found)->data[XSTRING (found)->size - 1] = 0;
+ XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 0;
result = stat ((char *)XSTRING (found)->data, &s2);
if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
{
message_with_string ("Source file `%s' newer than byte-compiled file",
found, 1);
}
- XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
+ XSTRING (found)->data[STRING_BYTES (XSTRING (found)) - 1] = 'c';
}
else
{
if (!NILP (Vload_source_file_function))
{
if (fd != 0)
- close (fd);
+ emacs_close (fd);
return call4 (Vload_source_file_function, found, file,
NILP (noerror) ? Qnil : Qt,
NILP (nomessage) ? Qnil : Qt);
}
#ifdef WINDOWSNT
- close (fd);
+ emacs_close (fd);
stream = fopen ((char *) XSTRING (found)->data, fmode);
#else /* not WINDOWSNT */
stream = fdopen (fd, fmode);
#endif /* not WINDOWSNT */
if (stream == 0)
{
- close (fd);
+ emacs_close (fd);
error ("Failure to create stdio stream for %s", XSTRING (file)->data);
}
GCPRO1 (file);
lispstream = Fcons (Qnil, Qnil);
- XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16);
- XSETFASTINT (XCONS (lispstream)->cdr, (EMACS_UINT)stream & 0xffff);
+ XSETFASTINT (XCAR (lispstream), (EMACS_UINT)stream >> 16);
+ XSETFASTINT (XCDR (lispstream), (EMACS_UINT)stream & 0xffff);
record_unwind_protect (load_unwind, lispstream);
record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
specbind (Qload_file_name, found);
load_unwind (stream) /* used as unwind-protect function in load */
Lisp_Object stream;
{
- fclose ((FILE *) (XFASTINT (XCONS (stream)->car) << 16
- | XFASTINT (XCONS (stream)->cdr)));
+ fclose ((FILE *) (XFASTINT (XCAR (stream)) << 16
+ | XFASTINT (XCDR (stream))));
if (--load_in_progress < 0) load_in_progress = 0;
return Qnil;
}
{
#ifndef WINDOWSNT
Lisp_Object tail;
- for (tail = load_descriptor_list; !NILP (tail); tail = XCONS (tail)->cdr)
- close (XFASTINT (XCONS (tail)->car));
+ for (tail = load_descriptor_list; !NILP (tail); tail = XCDR (tail))
+ emacs_close (XFASTINT (XCAR (tail)));
#endif
}
\f
/* Calculate maximum size of any filename made from
this path element/specified file name and any possible suffix. */
- want_size = strlen (suffix) + XSTRING (filename)->size + 1;
+ want_size = strlen (suffix) + STRING_BYTES (XSTRING (filename)) + 1;
if (fn_size < want_size)
fn = (char *) alloca (fn_size = 100 + want_size);
&& XSTRING (filename)->data[1] == ':')
{
strncpy (fn, XSTRING (filename)->data + 2,
- XSTRING (filename)->size - 2);
- fn[XSTRING (filename)->size - 2] = 0;
+ STRING_BYTES (XSTRING (filename)) - 2);
+ fn[STRING_BYTES (XSTRING (filename)) - 2] = 0;
}
else
{
- strncpy (fn, XSTRING (filename)->data, XSTRING (filename)->size);
- fn[XSTRING (filename)->size] = 0;
+ strncpy (fn, XSTRING (filename)->data,
+ STRING_BYTES (XSTRING (filename)));
+ fn[STRING_BYTES (XSTRING (filename))] = 0;
}
if (lsuffix != 0) /* Bug happens on CCI if lsuffix is 0. */
if (exec_only)
fd = (access (fn, X_OK) == 0) ? 1 : -1;
else
- fd = open (fn, O_RDONLY, 0);
+ fd = emacs_open (fn, O_RDONLY, 0);
if (fd >= 0)
{
#ifndef standalone
-DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 4, "",
+DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 5, "",
"Execute the current buffer as Lisp code.\n\
Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
BUFFER is the buffer to evaluate (nil means use current buffer).\n\
\n\
If the optional third argument FILENAME is non-nil,\n\
it specifies the file name to use for `load-history'.\n\
+The optional fourth argument UNIBYTE specifies `load-convert-to-unibyte'\n\
+for this invocation.\n\
+\n\
+The optional fifth argument DO-ALLOW-PRINT, if not-nil, specifies that\n\
+`print' and related functions should work normally even if PRINTFLAG is nil.\n\
\n\
This function preserves the position of point.")
- (buffer, printflag, filename, unibyte)
- Lisp_Object buffer, printflag, filename, unibyte;
+ (buffer, printflag, filename, unibyte, do_allow_print)
+ Lisp_Object buffer, printflag, filename, unibyte, do_allow_print;
{
int count = specpdl_ptr - specpdl;
Lisp_Object tem, buf;
if (NILP (buf))
error ("No such buffer");
- if (NILP (printflag))
+ if (NILP (printflag) && NILP (do_allow_print))
tem = Qsymbolp;
else
tem = printflag;
c = READCHAR;
if (c == '\\')
c = read_escape (readcharfun, 0);
- if ((c & 0177) == '?')
- return 0177 | c;
+ if ((c & ~CHAR_MODIFIER_MASK) == '?')
+ return 0177 | (c & CHAR_MODIFIER_MASK);
+ else if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
+ return c | ctrl_modifier;
/* ASCII control chars are made from letters (both cases),
as well as the non-letters within 0100...0137. */
else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
{
char *temp = saved_doc_string;
int temp_size = saved_doc_string_size;
- int temp_pos = saved_doc_string_position;
+ file_offset temp_pos = saved_doc_string_position;
int temp_len = saved_doc_string_length;
saved_doc_string = prev_saved_doc_string;
saved_doc_string_size);
}
- saved_doc_string_position = ftell (instream);
+ saved_doc_string_position = file_tell (instream);
/* Copy that many characters into saved_doc_string. */
for (i = 0; i < nskip && c >= 0; i++)
/* #n=object returns object, but associates it with n for #n#. */
if (c == '=')
{
+ /* Make a placeholder for #n# to use temporarily */
+ Lisp_Object placeholder;
+ Lisp_Object cell;
+
+ placeholder = Fcons(Qnil, Qnil);
+ cell = Fcons (make_number (n), placeholder);
+ read_objects = Fcons (cell, read_objects);
+
+ /* Read the object itself. */
tem = read0 (readcharfun);
- read_objects = Fcons (Fcons (make_number (n), tem), read_objects);
+
+ /* Now put it everywhere the placeholder was... */
+ substitute_object_in_subtree (tem, placeholder);
+
+ /* ...and #n# will use the real value from now on. */
+ Fsetcdr (cell, tem);
+
return tem;
}
/* #n# returns a previously read object. */
case '?':
{
- register Lisp_Object val;
-
c = READCHAR;
if (c < 0) return Fsignal (Qend_of_file, Qnil);
/* If an escape specifies a non-ASCII single-byte character,
this must be a unibyte string. */
- if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_META))
- && ! ASCII_BYTE_P (c))
+ if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK))
+ && ! ASCII_BYTE_P ((c & ~CHAR_MODIFIER_MASK)))
force_singlebyte = 1;
}
- if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_META)))
+ if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
{
unsigned char workbuf[4];
unsigned char *str = workbuf;
int length;
+ /* Any modifiers for a multibyte character are invalid. */
+ if (c & CHAR_MODIFIER_MASK)
+ error ("Invalid modifier in string");
length = non_ascii_char_to_string (c, workbuf, &str);
if (length > 1)
force_multibyte = 1;
else if (c == (CHAR_CTL | '?'))
c = 127;
+ if (c & CHAR_SHIFT)
+ {
+ /* Shift modifier is valid only with [A-Za-z]. */
+ if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
+ c &= ~CHAR_SHIFT;
+ else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
+ c = (c & ~CHAR_SHIFT) - ('a' - 'A');
+ }
+
if (c & CHAR_META)
/* Move the meta bit to the right place for a string. */
c = (c & ~CHAR_META) | 0x80;
}
}
\f
+
+/* List of nodes we've seen during substitute_object_in_subtree. */
+static Lisp_Object seen_list;
+
+static void
+substitute_object_in_subtree (object, placeholder)
+ Lisp_Object object;
+ Lisp_Object placeholder;
+{
+ Lisp_Object check_object;
+
+ /* We haven't seen any objects when we start. */
+ seen_list = Qnil;
+
+ /* Make all the substitutions. */
+ check_object
+ = substitute_object_recurse (object, placeholder, object);
+
+ /* Clear seen_list because we're done with it. */
+ seen_list = Qnil;
+
+ /* The returned object here is expected to always eq the
+ original. */
+ if (!EQ (check_object, object))
+ error ("Unexpected mutation error in reader");
+}
+
+/* Feval doesn't get called from here, so no gc protection is needed. */
+#define SUBSTITUTE(get_val, set_val) \
+{ \
+ Lisp_Object old_value = get_val; \
+ Lisp_Object true_value \
+ = substitute_object_recurse (object, placeholder,\
+ old_value); \
+ \
+ if (!EQ (old_value, true_value)) \
+ { \
+ set_val; \
+ } \
+}
+
+static Lisp_Object
+substitute_object_recurse (object, placeholder, subtree)
+ Lisp_Object object;
+ Lisp_Object placeholder;
+ Lisp_Object subtree;
+{
+ /* If we find the placeholder, return the target object. */
+ if (EQ (placeholder, subtree))
+ return object;
+
+ /* If we've been to this node before, don't explore it again. */
+ if (!EQ (Qnil, Fmemq (subtree, seen_list)))
+ return subtree;
+
+ /* If this node can be the entry point to a cycle, remember that
+ we've seen it. It can only be such an entry point if it was made
+ by #n=, which means that we can find it as a value in
+ read_objects. */
+ if (!EQ (Qnil, Frassq (subtree, read_objects)))
+ seen_list = Fcons (subtree, seen_list);
+
+ /* Recurse according to subtree's type.
+ Every branch must return a Lisp_Object. */
+ switch (XTYPE (subtree))
+ {
+ case Lisp_Vectorlike:
+ {
+ int i;
+ int length = Flength(subtree);
+ for (i = 0; i < length; i++)
+ {
+ Lisp_Object idx = make_number (i);
+ SUBSTITUTE (Faref (subtree, idx),
+ Faset (subtree, idx, true_value));
+ }
+ return subtree;
+ }
+
+ case Lisp_Cons:
+ {
+ SUBSTITUTE (Fcar_safe (subtree),
+ Fsetcar (subtree, true_value));
+ SUBSTITUTE (Fcdr_safe (subtree),
+ Fsetcdr (subtree, true_value));
+ return subtree;
+ }
+
+#ifdef USE_TEXT_PROPERTIES
+ case Lisp_String:
+ {
+ /* Check for text properties in each interval.
+ substitute_in_interval contains part of the logic. */
+
+ INTERVAL root_interval = XSTRING (subtree)->intervals;
+ Lisp_Object arg = Fcons (object, placeholder);
+
+ traverse_intervals (root_interval, 1, 0,
+ &substitute_in_interval, arg);
+
+ return subtree;
+ }
+#endif /* defined USE_TEXT_PROPERTIES */
+
+ /* Other types don't recurse any further. */
+ default:
+ return subtree;
+ }
+}
+
+/* Helper function for substitute_object_recurse. */
+static void
+substitute_in_interval (interval, arg)
+ INTERVAL interval;
+ Lisp_Object arg;
+{
+ Lisp_Object object = Fcar (arg);
+ Lisp_Object placeholder = Fcdr (arg);
+
+ SUBSTITUTE(interval->plist, interval->plist = true_value);
+}
+
+\f
#ifdef LISP_FLOAT_TYPE
#define LEAD_INT 1
error ("invalid byte code");
otem = XCONS (item);
- bytestr = XCONS (item)->car;
- item = XCONS (item)->cdr;
+ bytestr = XCAR (item);
+ item = XCDR (item);
free_cons (otem);
}
{
GCPRO2 (val, tail);
if (!NILP (tail))
- XCONS (tail)->cdr = read0 (readcharfun);
+ XCDR (tail) = read0 (readcharfun);
else
val = read0 (readcharfun);
read1 (readcharfun, &ch, 0);
{
/* Get a doc string from the file we are loading.
If it's in saved_doc_string, get it from there. */
- int pos = XINT (XCONS (val)->cdr);
+ int pos = XINT (XCDR (val));
/* Position is negative for user variables. */
if (pos < 0) pos = -pos;
if (pos >= saved_doc_string_position
? pure_cons (elt, Qnil)
: Fcons (elt, Qnil));
if (!NILP (tail))
- XCONS (tail)->cdr = tem;
+ XCDR (tail) = tem;
else
val = tem;
tail = tem;
(function, obarray)
Lisp_Object function, obarray;
{
- Lisp_Object tem;
-
if (NILP (obarray)) obarray = Vobarray;
obarray = check_obarray (obarray);
XMISCTYPE (val) = Lisp_Misc_Boolfwd;
XBOOLFWD (val)->boolvar = address;
XSYMBOL (sym)->value = val;
+ Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars);
}
/* Similar but define a variable whose value is the Lisp Object stored
char *normal;
int turn_off_warning = 0;
-#ifdef HAVE_SETLOCALE
- /* Make sure numbers are parsed as we expect. */
- setlocale (LC_NUMERIC, "C");
-#endif /* HAVE_SETLOCALE */
-
/* Compute the default load-path. */
#ifdef CANNOT_DUMP
normal = PATH_LOADSEARCH;
for (path_tail = Vload_path;
!NILP (path_tail);
- path_tail = XCONS (path_tail)->cdr)
+ path_tail = XCDR (path_tail))
{
Lisp_Object dirfile;
dirfile = Fcar (path_tail);
dirfile = Fdirectory_file_name (dirfile);
if (access (XSTRING (dirfile)->data, 0) < 0)
dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
- XCONS (path_tail)->car);
+ XCAR (path_tail));
}
}
}
"*List of directories to search for files to load.\n\
Each element is a string (directory name) or nil (try default directory).\n\
Initialized based on EMACSLOADPATH environment variable, if any,\n\
-otherwise to default specified by file `paths.h' when Emacs was built.");
+otherwise to default specified by file `epaths.h' when Emacs was built.");
DEFVAR_BOOL ("load-in-progress", &load_in_progress,
"Non-nil iff inside of `load'.");
"Full name of file being loaded by `load'.");
Vload_file_name = Qnil;
+ DEFVAR_LISP ("user-init-file", &Vuser_init_file,
+ "File name, including directory, of user's initialization file.");
+ Vuser_init_file = Qnil;
+
DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
"Used for internal purposes by `load'.");
Vcurrent_load_list = Qnil;
"List of files that were preloaded (when dumping Emacs).");
Vpreloaded_file_list = Qnil;
+ DEFVAR_LISP ("byte-boolean-vars", &Vbyte_boolean_vars,
+ "List of all DEFVAR_BOOL variables, used by the byte code optimizer.");
+ Vbyte_boolean_vars = Qnil;
+
/* Vsource_directory was initialized in init_lread. */
load_descriptor_list = Qnil;
staticpro (&read_objects);
read_objects = Qnil;
+ staticpro (&seen_list);
+
}