/* 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"
#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;
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))
{
/* 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);
/* 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)
{
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++)
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;
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 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;