Fix bugs with inappropriate mixing of Lisp_Object with int.
[bpt/emacs.git] / src / lisp.h
index 1d4d0fa..ecfc0b6 100644 (file)
@@ -15,12 +15,14 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 /* These are default choices for the types to use.  */
 #ifndef EMACS_INT
 #define EMACS_INT int
+#define BITS_PER_EMACS_INT BITS_PER_INT
 #endif
 #ifndef EMACS_UINT
 #define EMACS_UINT unsigned int
@@ -102,7 +104,7 @@ enum gdb_lisp_params
 {
   gdb_valbits = VALBITS,
   gdb_gctypebits = GCTYPEBITS,
-  gdb_emacs_intbits = sizeof (EMACS_INT) * INTBITS / sizeof (int),
+  gdb_emacs_intbits = sizeof (EMACS_INT) * BITS_PER_CHAR,
 #ifdef DATA_SEG_BITS
   gdb_data_seg_bits = DATA_SEG_BITS
 #else
@@ -179,12 +181,11 @@ Lisp_Object;
 #endif /* NO_UNION_TYPE */
 
 
-/* If union type is not wanted, define Lisp_Object as just a number
-   and define the macros below to extract fields by shifting */
+/* If union type is not wanted, define Lisp_Object as just a number.  */
 
 #ifdef NO_UNION_TYPE
-
 #define Lisp_Object EMACS_INT
+#endif /* NO_UNION_TYPE */
 
 #ifndef VALMASK
 #define VALMASK ((((EMACS_INT) 1)<<VALBITS) - 1)
@@ -226,21 +227,21 @@ Lisp_Object;
 enum pvec_type
 {
   PVEC_NORMAL_VECTOR = 0,
-  PVEC_BUFFER = 0x100,
   PVEC_PROCESS = 0x200,
   PVEC_FRAME = 0x400,
   PVEC_COMPILED = 0x800,
   PVEC_WINDOW = 0x1000,
   PVEC_WINDOW_CONFIGURATION = 0x2000,
   PVEC_SUBR = 0x4000,
-  PVEC_TYPE_MASK = 0x7f00,
+  PVEC_CHAR_TABLE = 0x8000,
+  PVEC_BOOL_VECTOR = 0x10000,
+  PVEC_BUFFER = 0x20000,
+  PVEC_TYPE_MASK = 0x3fe00,
   PVEC_FLAG = PSEUDOVECTOR_FLAG
 };
 
 /* For convenience, we also store the number of elements in these bits.  */
-#define PSEUDOVECTOR_SIZE_MASK 0xff
-
-#endif /* NO_UNION_TYPE */
+#define PSEUDOVECTOR_SIZE_MASK 0x1ff
 \f
 /* These macros extract various sorts of values from a Lisp_Object.
  For example, if tem is a Lisp_Object whose type is Lisp_Cons,
@@ -269,7 +270,7 @@ enum pvec_type
 /* Extract the value of a Lisp_Object as a signed integer.  */
 
 #ifndef XINT   /* Some machines need to do this differently.  */
-#define XINT(a) (((a) << (INTBITS-VALBITS)) >> (INTBITS-VALBITS))
+#define XINT(a) (((a) << (BITS_PER_INT-VALBITS)) >> (BITS_PER_INT-VALBITS))
 #endif
 
 /* Extract the value as an unsigned integer.  This is a basis
@@ -304,6 +305,11 @@ extern int pure_size;
    ((var) = ((EMACS_INT)(type) << VALBITS) + ((EMACS_INT) (ptr) & VALMASK))
 #endif
 
+/* Convert a C integer into a Lisp_Object integer.  */
+
+#define make_number(N)         \
+  ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS)
+
 /* During garbage collection, XGCTYPE must be used for extracting types
  so that the mark bit is ignored.  XMARKBIT accesses the markbit.
  Markbits are used only in particular slots of particular structure types.
@@ -314,7 +320,7 @@ extern int pure_size;
 #define XGCTYPE(a) ((enum Lisp_Type) (((a) >> VALBITS) & GCTYPEMASK))
 #endif
 
-#if VALBITS + GCTYPEBITS == INTBITS - 1
+#if VALBITS + GCTYPEBITS == BITS_PER_EMACS_INT - 1
 /* Make XMARKBIT faster if mark bit is sign bit.  */
 #ifndef XMARKBIT
 #define XMARKBIT(a) ((a) < 0)
@@ -352,7 +358,7 @@ extern int pure_size;
 
 #ifdef EXPLICIT_SIGN_EXTEND
 /* Make sure we sign-extend; compilers have been known to fail to do so.  */
-#define XINT(a) (((a).i << (INTBITS-VALBITS)) >> (INTBITS-VALBITS))
+#define XINT(a) (((a).i << (BITS_PER_INT-VALBITS)) >> (BITS_PER_INT-VALBITS))
 #else
 #define XINT(a) ((a).s.val)
 #endif /* EXPLICIT_SIGN_EXTEND */
@@ -363,6 +369,8 @@ extern int pure_size;
 #define XSET(var, vartype, ptr) \
    (((var).s.type = ((char) (vartype))), ((var).s.val = ((int) (ptr))))
 
+extern Lisp_Object make_number ();
+
 /* During garbage collection, XGCTYPE must be used for extracting types
  so that the mark bit is ignored.  XMARKBIT access the markbit.
  Markbits are used only in particular slots of particular structure types.
@@ -402,6 +410,8 @@ extern int pure_size;
 #define XWINDOW(a) ((struct window *) XPNTR(a))
 #define XSUBR(a) ((struct Lisp_Subr *) XPNTR(a))
 #define XBUFFER(a) ((struct buffer *) XPNTR(a))
+#define XCHAR_TABLE(a) ((struct Lisp_Char_Table *) XPNTR(a))
+#define XBOOL_VECTOR(a) ((struct Lisp_Bool_Vector *) XPNTR(a))
 
 
 /* Construct a Lisp_Object from a value or address.  */
@@ -427,6 +437,8 @@ extern int pure_size;
 #define XSETSUBR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUBR))
 #define XSETCOMPILED(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_COMPILED))
 #define XSETBUFFER(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BUFFER))
+#define XSETCHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_CHAR_TABLE))
+#define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
 \f
 #ifdef USE_TEXT_PROPERTIES
 /* Basic data type for use of intervals.  See the macros in intervals.h.  */
@@ -503,6 +515,21 @@ struct Lisp_Cons
     Lisp_Object car, cdr;
   };
 
+/* Take the car or cdr of something known to be a cons cell.  */
+#define XCAR(c) (XCONS ((c))->car)
+#define XCDR(c) (XCONS ((c))->cdr)
+
+/* Take the car or cdr of something whose type is not known.  */
+#define CAR(c)                                 \
+ (CONSP ((c)) ? XCAR ((c))                     \
+  : NILP ((c)) ? Qnil                          \
+  : wrong_type_argument (Qlistp, (c)))
+
+#define CDR(c)                                 \
+ (CONSP ((c)) ? XCDR ((c))                     \
+  : NILP ((c)) ? Qnil                          \
+  : wrong_type_argument (Qlistp, (c)))
+
 /* Like a cons, but records info on where the text lives that it was read from */
 /* This is not really in use now */
 
@@ -523,9 +550,10 @@ struct Lisp_String
   };
 
 /* If a struct is made to look like a vector, this macro returns the length
-   of that vector.  */
-#define VECSIZE(type) ((sizeof (type) - (sizeof (struct Lisp_Vector)   \
-                                        - sizeof (Lisp_Object)))       \
+   of the shortest vector that would hold that struct.  */
+#define VECSIZE(type) ((sizeof (type) - (sizeof (struct Lisp_Vector)  \
+                                         - sizeof (Lisp_Object))      \
+                        + sizeof(Lisp_Object) - 1) /* round up */     \
                       / sizeof (Lisp_Object))
 
 struct Lisp_Vector
@@ -535,6 +563,112 @@ struct Lisp_Vector
     Lisp_Object contents[1];
   };
 
+/* A char table is a kind of vectorlike, with contents are like a
+   vector but with a few other slots.  For some purposes, it makes
+   sense to handle a chartable with type struct Lisp_Vector.  An
+   element of a char table can be any Lisp objects, but if it is a sub
+   char-table, we treat it a table that contains information of a
+   group of characters of the same charsets or a specific character of
+   a charset.  A sub char-table has the same structure as a char table
+   except for that the former omits several slots at the tail.  A sub
+   char table appears only in an element of a char table, and there's
+   no way to access it directly from Emacs Lisp program.  */
+
+/* This is the number of slots that apply to characters or character
+   sets.  The first 128 are for ASCII, the next 128 are for 8-bit
+   European characters, and the last 128 are for multibyte characters.
+   The first 256 are indexed by the code itself, but the last 128 are
+   indexed by (charset-id + 128).  */
+#define CHAR_TABLE_ORDINARY_SLOTS 384
+
+/* This is the number of slots that apply to characters of ASCII and
+   8-bit Europeans only.  */
+#define CHAR_TABLE_SINGLE_BYTE_SLOTS 256
+
+/* This is the number of slots that every char table must have.  This
+   counts the ordinary slots and the top, defalt, parent, and purpose
+   slots.  */
+#define CHAR_TABLE_STANDARD_SLOTS (CHAR_TABLE_ORDINARY_SLOTS + 4)
+
+/* This is the number of slots that apply to position-code-1 and
+   position-code-2 of a multibyte character at the 2nd and 3rd level
+   sub char tables respectively.  */
+#define SUB_CHAR_TABLE_ORDINARY_SLOTS 128
+
+/* This is the number of slots that every sub char table must have.
+   This counts the ordinary slots and the top and defalt slot.  */
+#define SUB_CHAR_TABLE_STANDARD_SLOTS (SUB_CHAR_TABLE_ORDINARY_SLOTS + 2)
+
+/* Return the number of "extra" slots in the char table CT.  */
+
+#define CHAR_TABLE_EXTRA_SLOTS(CT)     \
+  (((CT)->size & PSEUDOVECTOR_SIZE_MASK) - CHAR_TABLE_STANDARD_SLOTS)
+
+/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
+   and 8-bit Europeans characters.  For these characters, do not check
+   validity of CT.  Do not follow parent.  */
+#define CHAR_TABLE_REF(CT, IDX)                                \
+  ((IDX) < CHAR_TABLE_SINGLE_BYTE_SLOTS                        \
+   ? (!NILP (XCHAR_TABLE (CT)->contents[IDX])          \
+      ? XCHAR_TABLE (CT)->contents[IDX]                        \
+      : XCHAR_TABLE (CT)->defalt)                      \
+   : Faref (CT, make_number (IDX)))
+
+/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
+   8-bit Europeans characters.  Do not check validity of CT.  */
+#define CHAR_TABLE_SET(CT, IDX, VAL)                   \
+  do {                                                 \
+    if (XFASTINT (IDX) < CHAR_TABLE_SINGLE_BYTE_SLOTS) \
+      XCHAR_TABLE (CT)->contents[XFASTINT (IDX)] = VAL;        \
+    else                                               \
+      Faset (CT, IDX, VAL);                            \
+  } while (0)
+
+struct Lisp_Char_Table
+  {
+    /* This is the vector's size field, which also holds the
+       pseudovector type information.  It holds the size, too.
+       The size counts the top, defalt, purpose, and parent slots.
+       The last three are not counted if this is a sub char table.  */
+    EMACS_INT size;
+    struct Lisp_Vector *next;
+    /* This holds a flag to tell if this is a top level char table (t)
+       or a sub char table (nil).  */
+    Lisp_Object top;
+    /* This holds a default value,
+       which is used whenever the value for a specific character is nil.  */
+    Lisp_Object defalt;
+    /* This holds an actual value of each element.  A sub char table
+       has only SUB_CHAR_TABLE_ORDINARY_SLOTS number of elements.  */
+    Lisp_Object contents[CHAR_TABLE_ORDINARY_SLOTS];
+
+    /* A sub char table doesn't has the following slots.  */
+
+    /* This points to another char table, which we inherit from
+       when the value for a specific character is nil.
+       The `defalt' slot takes precedence over this.  */
+    Lisp_Object parent;
+    /* This should be a symbol which says what kind of use
+       this char-table is meant for.
+       Typically now the values can be `syntax-table' and `display-table'.  */
+    Lisp_Object purpose;
+    /* These hold additional data.  */
+    Lisp_Object extras[1];
+  };
+
+/* A boolvector is a kind of vectorlike, with contents are like a string.  */
+struct Lisp_Bool_Vector
+  {
+    /* This is the vector's size field.  It doesn't have the real size,
+       just the subtype information.  */
+    EMACS_INT vector_size;
+    struct Lisp_Vector *next;
+    /* This is the size in bits.  */
+    EMACS_INT size;
+    /* This contains the actual bits, packed into bytes.  */
+    unsigned char data[1];
+  };
+
 /* In a symbol, the markbit of the plist is used as the gc mark bit */
 
 struct Lisp_Symbol
@@ -543,6 +677,7 @@ struct Lisp_Symbol
     Lisp_Object value;
     Lisp_Object function;
     Lisp_Object plist;
+    Lisp_Object obarray;
     struct Lisp_Symbol *next;  /* -> next symbol in this obarray bucket */
   };
 
@@ -553,7 +688,7 @@ struct Lisp_Symbol
    This type is treated in most respects as a pseudovector,
    but since we never dynamically allocate or free them,
    we don't need a next-vector field.  */
-   
+
 struct Lisp_Subr
   {
     EMACS_INT size;
@@ -574,18 +709,18 @@ struct Lisp_Free
     union Lisp_Misc *chain;
   };
 
-/* In a marker, the markbit of the chain field is used as the gc mark bit */
+/* In a marker, the markbit of the chain field is used as the gc mark bit */
 struct Lisp_Marker
-  {
-    int type : 16;     /* = Lisp_Misc_Marker */
-    int spacer : 15;
-    /* 1 means normal insertion at the marker's position
-       leaves the marker after the inserted text.  */
-    int insertion_type : 1;
-    struct buffer *buffer;
-    Lisp_Object chain;
-    int bufpos;
-  };
+{
+  int type : 16;               /* = Lisp_Misc_Marker */
+  int spacer : 15;
+  /* 1 means normal insertion at the marker's position
+     leaves the marker after the inserted text.  */
+  unsigned int insertion_type : 1;
+  struct buffer *buffer;
+  Lisp_Object chain;
+  int bufpos;
+};
 
 /* Forwarding pointer to an int variable.
    This is allowed only in the value cell of a symbol,
@@ -717,9 +852,9 @@ union Lisp_Misc
 /* Optional Lisp floating point type */
 struct Lisp_Float
   {
-    Lisp_Object type;          /* essentially used for mark-bit 
+    Lisp_Object type;          /* essentially used for mark-bit
                                   and chaining when on free-list */
-    double data;  
+    double data;
   };
 #endif /* LISP_FLOAT_TYPE */
 
@@ -750,6 +885,10 @@ typedef unsigned char UCHAR;
 #define CHAR_CTL   (0x4000000)
 #define CHAR_META  (0x8000000)
 
+/* Actually, the current Emacs uses 19 bits for the character value
+   itself.  */
+#define CHARACTERBITS 19
+
 #ifdef USE_X_TOOLKIT
 #ifdef NO_UNION_TYPE
 /* Use this for turning a (void *) into a Lisp_Object, as when the
@@ -781,26 +920,37 @@ typedef unsigned char UCHAR;
 \f
 /* The glyph datatype, used to represent characters on the display.  */
 
-/* The low eight bits are the character code, and the bits above them
-   are the numeric face ID.  If FID is the face ID of a glyph on a
-   frame F, then F->display.x->faces[FID] contains the description of
-   that face.  This is an int instead of a short, so we can support a
-   good bunch of face ID's; given that we have no mechanism for
-   tossing unused frame face ID's yet, we'll probably run out of 255
-   pretty quickly.  */
+/* The low 19 bits (CHARACTERBITS) are the character code, and the
+   bits above them except for the topmost two bits are the numeric
+   face ID.  If FID is the face ID of a glyph on a frame F, then
+   F->display.x->faces[FID] contains the description of that face.
+   This is an int instead of a short, so we can support a good bunch
+   of face ID's (i.e. 2^(32 - 19 - 2) = 2048 ID's) ; given that we
+   have no mechanism for tossing unused frame face ID's yet, we'll
+   probably run out of 255 pretty quickly.  */
 #define GLYPH unsigned int
 
+/* Mask bit for a glyph of a character which should be written from
+   right to left.  */
+#define GLYPH_MASK_REV_DIR 0x80000000
+/* Mask bit for a padding glyph of a multi-column character.  */
+#define GLYPH_MASK_PADDING 0x40000000
+/* Mask bits for face.  */
+#define GLYPH_MASK_FACE    0x3FF80000
+/* Mask bits for character code.  */
+#define GLYPH_MASK_CHAR    0x0007FFFF /* The lowest 19 bits */
+
 #ifdef HAVE_FACES
 /* The FAST macros assume that we already know we're in an X window.  */
 
 /* Given a character code and a face ID, return the appropriate glyph.  */
-#define FAST_MAKE_GLYPH(char, face) ((char) | ((face) << 8))
+#define FAST_MAKE_GLYPH(char, face) ((char) | ((face) << CHARACTERBITS))
 
 /* Return a glyph's character code.  */
-#define FAST_GLYPH_CHAR(glyph) ((glyph) & 0xff)
+#define FAST_GLYPH_CHAR(glyph) ((glyph) & GLYPH_MASK_CHAR)
 
 /* Return a glyph's face ID.  */
-#define FAST_GLYPH_FACE(glyph) (((glyph) >> 8) & ((1 << 24) - 1))
+#define FAST_GLYPH_FACE(glyph) (((glyph) & GLYPH_MASK_FACE) >> CHARACTERBITS)
 
 /* Slower versions that test the frame type first.  */
 #define MAKE_GLYPH(f, char, face) (FRAME_TERMCAP_P (f) ? (char) \
@@ -809,10 +959,17 @@ typedef unsigned char UCHAR;
 #define GLYPH_FACE(f, g) (FRAME_TERMCAP_P (f) ? (0) : FAST_GLYPH_FACE (g))
 #else /* not HAVE_FACES */
 #define MAKE_GLYPH(f, char, face) (char)
-#define GLYPH_CHAR(f, g) (g)
-#define GLYPH_FACE(f, g) (g)
+#define FAST_MAKE_GLYPH(char, face) (char)
+#define GLYPH_CHAR(f, g) ((g) & GLYPH_MASK_CHAR)
+#define FAST_GLYPH_CHAR(g) ((g) & GLYPH_MASK_CHAR)
+#define GLYPH_FACE(f, g) ((g) & GLYPH_MASK_FACE)
+#define FAST_GLYPH_FACE(g) ((g) & GLYPH_MASK_FACE)
 #endif /* not HAVE_FACES */
 
+/* Return 1 iff GLYPH contains valid character code.  */
+#define GLYPH_CHAR_VALID_P(glyph) \
+  ((GLYPH) (FAST_GLYPH_CHAR (glyph)) <= MAX_CHAR)
+
 /* The ID of the mode line highlighting face.  */
 #define GLYPH_MODE_LINE_FACE 1
 \f
@@ -899,19 +1056,14 @@ typedef unsigned char UCHAR;
 #define GC_COMPILEDP(x) GC_PSEUDOVECTORP (x, PVEC_COMPILED)
 #define BUFFERP(x) PSEUDOVECTORP (x, PVEC_BUFFER)
 #define GC_BUFFERP(x) GC_PSEUDOVECTORP (x, PVEC_BUFFER)
-
-#ifdef MULTI_FRAME
+#define CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_CHAR_TABLE)
+#define GC_CHAR_TABLE_P(x) GC_PSEUDOVECTORP (x, PVEC_CHAR_TABLE)
+#define BOOL_VECTOR_P(x) PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
+#define GC_BOOL_VECTOR_P(x) GC_PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
 #define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME)
 #define GC_FRAMEP(x) GC_PSEUDOVECTORP (x, PVEC_FRAME)
-#else
-#ifdef HAVE_MOUSE
-/* We could use this in the !HAVE_MOUSE case also, but we prefer a compile-time
-   error message in case FRAMEP is used.  */
-#define FRAMEP(x) (EQ (x, Fselected_frame ()))
-#define GC_FRAMEP(x) (GC_EQ (x, Fselected_frame ()))
-#endif
-#endif
 
+#define SUB_CHAR_TABLE_P(x) (CHAR_TABLE_P (x) && NILP (XCHAR_TABLE (x)->top))
 \f
 #define EQ(x, y) (XFASTINT (x) == XFASTINT (y))
 #define GC_EQ(x, y) (XGCTYPE (x) == XGCTYPE (y) && XPNTR (x) == XPNTR (y))
@@ -928,9 +1080,18 @@ typedef unsigned char UCHAR;
 #define CHECK_SYMBOL(x, i) \
   do { if (!SYMBOLP ((x))) x = wrong_type_argument (Qsymbolp, (x)); } while (0)
 
+#define CHECK_CHAR_TABLE(x, i) \
+  do { if (!CHAR_TABLE_P ((x)))        \
+        x = wrong_type_argument (Qchar_table_p, (x)); } while (0)
+
 #define CHECK_VECTOR(x, i) \
   do { if (!VECTORP ((x))) x = wrong_type_argument (Qvectorp, (x)); } while (0)
 
+#define CHECK_VECTOR_OR_CHAR_TABLE(x, i)                               \
+  do { if (!VECTORP ((x)) && !CHAR_TABLE_P ((x)))                      \
+        x = wrong_type_argument (Qvector_or_char_table_p, (x));        \
+     } while (0)
+
 #define CHECK_BUFFER(x, i) \
   do { if (!BUFFERP ((x))) x = wrong_type_argument (Qbufferp, (x)); } while (0)
 
@@ -938,7 +1099,7 @@ typedef unsigned char UCHAR;
   do { if (!WINDOWP ((x))) x = wrong_type_argument (Qwindowp, (x)); } while (0)
 
 /* This macro rejects windows on the interior of the window tree as
-   "dead", which is what we want; this is an argument-checking macro, and 
+   "dead", which is what we want; this is an argument-checking macro, and
    the user should never get access to interior windows.
 
    A window of any sort, leaf or interior, is dead iff the buffer,
@@ -1152,45 +1313,51 @@ extern char *stack_bottom;
 
 #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
 \f
-/* 1 if CH is upper case.  */
+/* Variables used locally in the following case handling macros.  */
+extern int case_temp1;
+extern Lisp_Object case_temp2;
 
-#define UPPERCASEP(CH) \
-  (XSTRING (current_buffer->downcase_table)->data[CH] != (CH))
+/* Current buffer's map from characters to lower-case characters.  */
 
-/* 1 if CH is lower case.  */
+#define DOWNCASE_TABLE current_buffer->downcase_table
 
-#define LOWERCASEP(CH) \
-  (!UPPERCASEP (CH) \
-   && XSTRING (current_buffer->upcase_table)->data[CH] != (CH))
+/* Current buffer's map from characters to upper-case characters.  */
 
-/* 1 if CH is neither upper nor lower case.  */
+#define UPCASE_TABLE current_buffer->upcase_table
 
-#define NOCASEP(CH) (XSTRING (current_buffer->upcase_table)->data[CH] == (CH))
+/* Downcase a character, or make no change if that cannot be done.  */
 
-/* Upcase a character, or make no change if that cannot be done.  */
+#define DOWNCASE(CH)                                           \
+  ((case_temp1 = (CH),                                         \
+    case_temp2 = CHAR_TABLE_REF (DOWNCASE_TABLE, case_temp1),  \
+    NATNUMP (case_temp2))                                      \
+   ? XFASTINT (case_temp2) : case_temp1)
 
-#define UPCASE(CH) \
-  (XSTRING (current_buffer->downcase_table)->data[CH] == (CH) \
-   ? UPCASE1 (CH) : (CH))
+/* 1 if CH is upper case.  */
 
-/* Upcase a character known to be not upper case.  */
+#define UPPERCASEP(CH) (DOWNCASE (CH) != (CH))
 
-#define UPCASE1(CH) (XSTRING (current_buffer->upcase_table)->data[CH])
+/* 1 if CH is neither upper nor lower case.  */
 
-/* Downcase a character, or make no change if that cannot be done.  */
+#define NOCASEP(CH) (UPCASE1 (CH) == (CH))
 
-#define DOWNCASE(CH) (XSTRING (current_buffer->downcase_table)->data[CH])
+/* 1 if CH is lower case.  */
 
-/* Current buffer's map from characters to lower-case characters.  */
+#define LOWERCASEP(CH) (!UPPERCASEP (CH) && !NOCASEP(CH))
 
-#define DOWNCASE_TABLE XSTRING (current_buffer->downcase_table)->data
+/* Upcase a character, or make no change if that cannot be done.  */
 
-/* Table mapping each char to the next char with the same lowercase version.
-   This mapping is a no-op only for characters that don't have case.  */
-#define UPCASE_TABLE XSTRING (current_buffer->upcase_table)->data
+#define UPCASE(CH) (!UPPERCASEP (CH) ? UPCASE1 (CH) : (CH))
+
+/* Upcase a character known to be not upper case.  */
 
-extern Lisp_Object Vascii_downcase_table, Vascii_upcase_table;
-extern Lisp_Object Vascii_canon_table, Vascii_eqv_table;
+#define UPCASE1(CH)                                            \
+  ((case_temp1 = (CH),                                         \
+    case_temp2 = CHAR_TABLE_REF (UPCASE_TABLE, case_temp1),    \
+    NATNUMP (case_temp2))                                      \
+   ? XFASTINT (case_temp2) : case_temp1)
+
+extern Lisp_Object Vascii_downcase_table;
 \f
 /* Number of bytes of structure consed since last GC.  */
 
@@ -1255,7 +1422,7 @@ struct gcpro
 /* Call staticpro (&var) to protect static variable `var'.  */
 
 void staticpro();
-  
+
 #define UNGCPRO (gcprolist = gcpro1.next)
 
 /* Evaluate expr, UNGCPRO, and then return the value of expr.  */
@@ -1288,6 +1455,7 @@ extern Lisp_Object Qsymbolp, Qlistp, Qconsp;
 extern Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
 extern Lisp_Object Qchar_or_string_p, Qmarkerp, Qvectorp;
 extern Lisp_Object Qinteger_or_marker_p, Qnumber_or_marker_p;
+extern Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
 extern Lisp_Object Qboundp, Qfboundp;
 extern Lisp_Object Qbuffer_or_string_p;
 extern Lisp_Object Qcdr;
@@ -1316,6 +1484,8 @@ extern Lisp_Object indirect_function (), Findirect_function ();
 extern Lisp_Object Ffset (), Fsetplist ();
 extern Lisp_Object Fsymbol_value (), find_symbol_value (), Fset ();
 extern Lisp_Object Fdefault_value (), Fset_default (), Fdefault_boundp ();
+extern Lisp_Object Fmake_local_variable ();
+extern Lisp_Object Flocal_variable_if_set_p ();
 
 extern Lisp_Object Faref (), Faset ();
 
@@ -1329,7 +1499,6 @@ extern Lisp_Object Flsh (), Fash ();
 
 extern Lisp_Object Fadd1 (), Fsub1 ();
 
-extern Lisp_Object make_number ();
 extern Lisp_Object   long_to_cons ();
 extern unsigned long cons_to_long ();
 extern void args_out_of_range ();
@@ -1347,6 +1516,11 @@ extern Lisp_Object Ffloat ();
 /* Defined in cmds.c */
 extern Lisp_Object Fend_of_line (), Fforward_char (), Fforward_line ();
 
+/* Defined in coding.c */
+extern Lisp_Object Fcoding_system_p (), Fcheck_coding_system ();
+extern Lisp_Object Fread_coding_system (), Fread_non_nil_coding_system ();
+extern Lisp_Object Ffind_coding_system ();
+
 /* Defined in syntax.c */
 extern Lisp_Object Fforward_word ();
 
@@ -1363,10 +1537,13 @@ extern Lisp_Object Freverse (), Fnreverse (), Fget (), Fput (), Fequal ();
 extern Lisp_Object Ffillarray (), Fnconc (), Fmapcar (), Fmapconcat ();
 extern Lisp_Object Fy_or_n_p (), do_yes_or_no_p ();
 extern Lisp_Object Ffeaturep (), Frequire () , Fprovide ();
-extern Lisp_Object concat2 (), nconc2 ();
+extern Lisp_Object concat2 (), concat3 (), nconc2 ();
 extern Lisp_Object assq_no_quit ();
 extern Lisp_Object Fcopy_alist ();
 extern Lisp_Object Fplist_get ();
+extern Lisp_Object Fset_char_table_parent ();
+extern Lisp_Object Fchar_table_extra_slot ();
+extern Lisp_Object Frassoc ();
 
 /* Defined in insdel.c */
 extern void move_gap ();
@@ -1388,6 +1565,10 @@ extern void prepare_to_modify_buffer ();
 extern void signal_before_change ();
 extern void signal_after_change ();
 
+/* Defined in dispnew.c */
+extern Lisp_Object Fding (), Fredraw_display ();
+extern Lisp_Object Fsleep_for ();
+
 /* Defined in xdisp.c */
 extern Lisp_Object Vmessage_log_max;
 extern void message ();
@@ -1409,6 +1590,9 @@ extern Lisp_Object Fpurecopy (), make_pure_string ();
 extern Lisp_Object pure_cons (), make_pure_vector ();
 extern Lisp_Object Fgarbage_collect ();
 extern Lisp_Object Fmake_byte_code ();
+extern Lisp_Object Fmake_bool_vector (), Fmake_char_table ();
+extern Lisp_Object make_sub_char_table ();
+extern Lisp_Object Qchar_table_extra_slots;
 extern struct Lisp_Vector *allocate_vectorlike ();
 extern int gc_in_progress;
 
@@ -1416,6 +1600,7 @@ extern int gc_in_progress;
 extern Lisp_Object Vprin1_to_string_buffer;
 extern Lisp_Object Fprin1 (), Fprin1_to_string (), Fprinc ();
 extern Lisp_Object Fterpri (), Fprint ();
+extern Lisp_Object Ferror_message_string ();
 extern Lisp_Object Vstandard_output, Qstandard_output;
 extern Lisp_Object Qexternal_debugging_output;
 extern void temp_output_buffer_setup (), temp_output_buffer_show ();
@@ -1430,7 +1615,7 @@ extern Lisp_Object Fintern (), Fintern_soft (), Fload ();
 extern Lisp_Object Fget_file_char (), Fread_char ();
 extern Lisp_Object read_filtered_event ();
 extern Lisp_Object Feval_current_buffer (), Feval_region ();
-extern Lisp_Object intern (), oblookup ();
+extern Lisp_Object intern (), make_symbol (), oblookup ();
 #define LOADHIST_ATTACH(x) \
  if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list)
 extern Lisp_Object Vcurrent_load_list;
@@ -1442,10 +1627,17 @@ extern Lisp_Object Vinhibit_quit, Qinhibit_quit, Vquit_flag;
 extern Lisp_Object Vmocklisp_arguments, Qmocklisp, Qmocklisp_arguments;
 extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vdebug_on_error;
-/* To run a normal hook, do
+/* To run a normal hook, use the appropriate function from the list below.
+   The calling convention:
+
    if (!NILP (Vrun_hooks))
-     call1 (Vrun_hooks, Qmy_funny_hook);  */
+     call1 (Vrun_hooks, Qmy_funny_hook);
+
+   should no longer be used.  */
 extern Lisp_Object Vrun_hooks;
+extern Lisp_Object Frun_hooks (), Frun_hook_with_args ();
+extern Lisp_Object Frun_hook_with_args_until_success ();
+extern Lisp_Object Frun_hook_with_args_until_failure ();
 extern Lisp_Object Fand (), For (), Fif (), Fprogn (), Fprog1 (), Fprog2 ();
 extern Lisp_Object Fsetq (), Fquote ();
 extern Lisp_Object Fuser_variable_p (), Finteractive_p ();
@@ -1473,8 +1665,12 @@ extern Lisp_Object Fgoto_char ();
 extern Lisp_Object Fpoint_min_marker (), Fpoint_max_marker ();
 extern Lisp_Object Fpoint_min (), Fpoint_max ();
 extern Lisp_Object Fpoint (), Fpoint_marker (), Fmark_marker ();
+extern Lisp_Object Fline_beginning_position (), Fline_end_position ();
 extern Lisp_Object Ffollowing_char (), Fprevious_char (), Fchar_after ();
-extern Lisp_Object Finsert ();
+extern Lisp_Object Finsert (), Finsert_and_inherit ();
+extern Lisp_Object Finsert_before_markers ();
+extern Lisp_Object Finsert_buffer_substring ();
+extern Lisp_Object Finsert_char ();
 extern Lisp_Object Feolp (), Feobp (), Fbolp (), Fbobp ();
 extern Lisp_Object Fformat (), format1 ();
 extern Lisp_Object make_buffer_string (), Fbuffer_substring ();
@@ -1484,6 +1680,7 @@ extern Lisp_Object save_excursion_save (), save_restriction_save ();
 extern Lisp_Object save_excursion_restore (), save_restriction_restore ();
 extern Lisp_Object Fchar_to_string ();
 extern Lisp_Object Fdelete_region (), Fnarrow_to_region (), Fwiden ();
+extern Lisp_Object Fuser_login_name (), Fsystem_name ();
 
 /* defined in buffer.c */
 extern Lisp_Object Foverlay_start (), Foverlay_end ();
@@ -1497,8 +1694,14 @@ extern Lisp_Object Fbarf_if_buffer_read_only ();
 extern Lisp_Object Fcurrent_buffer (), Fswitch_to_buffer (), Fpop_to_buffer ();
 extern Lisp_Object Fother_buffer ();
 extern Lisp_Object Foverlay_get ();
+extern Lisp_Object Fbuffer_modified_p (), Fset_buffer_modified_p ();
+extern Lisp_Object Fkill_buffer (), Fkill_all_local_variables ();
+extern Lisp_Object Fbuffer_disable_undo (), Fbuffer_enable_undo ();
+extern Lisp_Object Ferase_buffer ();
 extern Lisp_Object Qoverlayp;
+extern Lisp_Object get_truename_buffer ();
 extern struct buffer *all_buffers;
+extern Lisp_Object Fprevious_overlay_change ();
 
 /* defined in marker.c */
 
@@ -1521,6 +1724,9 @@ extern Lisp_Object Ffile_name_directory ();
 extern Lisp_Object expand_and_dir_to_file ();
 extern Lisp_Object Ffile_accessible_directory_p ();
 extern Lisp_Object Funhandled_file_name_directory ();
+extern Lisp_Object Ffile_directory_p ();
+extern Lisp_Object Fwrite_region ();
+extern Lisp_Object Ffile_readable_p (), Ffile_executable_p ();
 
 /* Defined in abbrev.c */
 
@@ -1537,34 +1743,42 @@ extern Lisp_Object Fskip_chars_forward (), Fskip_chars_backward ();
 /* defined in minibuf.c */
 
 extern Lisp_Object last_minibuf_string;
-extern Lisp_Object read_minibuf (), Fcompleting_read ();
+extern Lisp_Object Fcompleting_read ();
 extern Lisp_Object Fread_from_minibuffer ();
 extern Lisp_Object Fread_variable (), Fread_buffer (), Fread_key_sequence ();
 extern Lisp_Object Fread_minibuffer (), Feval_minibuffer ();
 extern Lisp_Object Fread_string (), Fread_file_name ();
 extern Lisp_Object Fread_no_blanks_input ();
+extern Lisp_Object get_minibuffer ();
 
 /* Defined in callint.c */
 
 extern Lisp_Object Qminus, Qplus, Vcurrent_prefix_arg;
 extern Lisp_Object Vcommand_history;
-extern Lisp_Object Qcall_interactively;
+extern Lisp_Object Qcall_interactively, Qmouse_leave_buffer_hook;
 extern Lisp_Object Fcall_interactively ();
 extern Lisp_Object Fprefix_numeric_value ();
 
 /* defined in casefiddle.c */
 
 extern Lisp_Object Fdowncase (), Fupcase (), Fcapitalize ();
+extern Lisp_Object Fupcase_region ();
 extern Lisp_Object Fupcase_initials (), Fupcase_initials_region ();
 
+/* defined in casetab.c */
+
+extern Lisp_Object Fset_case_table ();
+extern Lisp_Object Fset_standard_case_table ();
+
 /* defined in keyboard.c */
 
 extern Lisp_Object Qdisabled;
-extern Lisp_Object Vhelp_form, Vtop_level;
+extern Lisp_Object Vtty_erase_char, Vhelp_form, Vtop_level;
 extern Lisp_Object Fdiscard_input (), Frecursive_edit ();
 extern Lisp_Object Fcommand_execute (), Finput_pending_p ();
 extern Lisp_Object menu_bar_items ();
 extern Lisp_Object Qvertical_scroll_bar;
+extern Lisp_Object Fevent_convert_list ();
 #ifdef MULTI_KBOARD
 extern void delete_kboard ();
 #endif
@@ -1573,23 +1787,30 @@ extern void delete_kboard ();
 
 extern Lisp_Object Qkeymap, Qmenu_bar;
 extern Lisp_Object current_global_map;
+extern Lisp_Object Fdefine_key ();
 extern Lisp_Object Fkey_description (), Fsingle_key_description ();
 extern Lisp_Object Fwhere_is_internal ();
 extern Lisp_Object access_keymap (), store_in_keymap ();
-extern Lisp_Object get_keyelt (), get_keymap ();
+extern Lisp_Object get_keyelt (), get_keymap (), get_keymap_1 ();
 extern void describe_map_tree ();
 
 /* defined in indent.c */
 extern Lisp_Object Fvertical_motion (), Findent_to (), Fcurrent_column ();
+extern Lisp_Object Fmove_to_column ();
 
 /* defined in window.c */
 extern Lisp_Object Qwindowp, Qwindow_live_p;
+extern Lisp_Object Fselected_window ();
 extern Lisp_Object Fget_buffer_window ();
 extern Lisp_Object Fsave_window_excursion ();
 extern Lisp_Object Fset_window_configuration (), Fcurrent_window_configuration ();
 extern Lisp_Object Fcoordinates_in_window_p ();
 extern Lisp_Object Fwindow_at ();
+extern Lisp_Object Fpos_visible_in_window_p ();
 extern int window_internal_height (), window_internal_width ();
+extern Lisp_Object Frecenter ();
+extern Lisp_Object Fscroll_other_window ();
+extern Lisp_Object Fset_window_start ();
 
 /* defined in frame.c */
 extern Lisp_Object Qvisible;
@@ -1599,8 +1820,6 @@ extern Lisp_Object get_frame_param();
 extern Lisp_Object frame_buffer_predicate ();
 extern Lisp_Object Fframep ();
 extern Lisp_Object Fselect_frame ();
-extern Lisp_Object Ffocus_frame ();
-extern Lisp_Object Funfocus_frame ();
 extern Lisp_Object Fselected_frame ();
 extern Lisp_Object Fwindow_frame ();
 extern Lisp_Object Fframe_root_window ();
@@ -1626,6 +1845,9 @@ extern Lisp_Object Fset_frame_height ();
 extern Lisp_Object Fset_frame_width ();
 extern Lisp_Object Fset_frame_size ();
 extern Lisp_Object Fset_frame_position ();
+extern Lisp_Object Fraise_frame ();
+extern Lisp_Object Fredirect_frame_focus ();
+extern Lisp_Object frame_buffer_list ();
 
 /* defined in emacs.c */
 extern Lisp_Object decode_env_path ();
@@ -1665,16 +1887,22 @@ extern Lisp_Object Qexecute_kbd_macro;
 extern Lisp_Object Fexecute_kbd_macro ();
 
 /* defined in undo.c */
+extern Lisp_Object Qinhibit_read_only;
 extern Lisp_Object Fundo_boundary ();
 extern Lisp_Object truncate_undo_list ();
 
 /* defined in textprop.c */
 extern Lisp_Object Qmodification_hooks;
-extern Lisp_Object Qrear_nonsticky;
+extern Lisp_Object Qrear_nonsticky, Qfont;
 extern Lisp_Object Qinsert_in_front_hooks, Qinsert_behind_hooks;
 extern Lisp_Object Fnext_property_change ();
 extern Lisp_Object Fnext_single_property_change ();
 extern Lisp_Object Fprevious_single_property_change ();
+extern Lisp_Object Fget_text_property (), Fput_text_property ();
+extern Lisp_Object Fset_text_properties ();
+extern Lisp_Object Ftext_property_not_all ();
+extern Lisp_Object Fprevious_char_property_change ();
+extern Lisp_Object Fnext_char_property_change ();
 
 /* defined in intervals.c */
 extern Lisp_Object get_local_map ();
@@ -1695,7 +1923,7 @@ extern long *xmalloc (), *xrealloc ();
 extern void xfree ();
 
 extern char *egetenv ();
+
 /* Set up the name of the machine we're running on.  */
 extern void init_system_name ();
 
@@ -1703,6 +1931,10 @@ extern void init_system_name ();
    in addition to a device separator.  Default the path separator
    to '/', and don't test for a device separator in IS_ANY_SEP.  */
 
+#ifdef WINDOWSNT
+extern Lisp_Object Vdirectory_sep_char;
+#endif
+
 #ifndef DIRECTORY_SEP
 #define DIRECTORY_SEP '/'
 #endif