home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / lisp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-07  |  43.1 KB  |  1,279 lines

  1. /* Fundamental definitions for XEmacs Lisp interpreter.
  2.    Copyright (C) 1985-1987, 1992-1994 Free Software Foundation, Inc.
  3.    Copyright (C) 1994, 1995 Amdahl Corporation.
  4.  
  5. This file is part of XEmacs.
  6.  
  7. XEmacs is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with XEmacs; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Synched up with: FSF 19.28. */
  22.  
  23. #ifndef _XEMACS_LISP_H_
  24. #define _XEMACS_LISP_H_
  25.  
  26. /************************************************************************/
  27. /*                        general definitions                           */
  28. /************************************************************************/
  29.  
  30. /* We include the following generally useful header files so that you
  31.    don't have to worry about prototypes when using the standard C
  32.    library functions and macros.  These files shouldn't be excessively
  33.    large so they shouldn't cause that much of a slowdown. */
  34.  
  35. #include <stdlib.h>
  36. #include <unistd.h>
  37. #include <string.h>        /* primarily for memcpy, etc. */
  38. #include <stdio.h>        /* NULL, etc. */
  39. #include <ctype.h>
  40. #include <stdarg.h>
  41. #ifndef INCLUDED_FCNTL
  42. # define INCLUDED_FCNTL
  43. # include <fcntl.h>
  44. #endif /* INCLUDED_FCNTL */
  45.  
  46. #ifdef __lucid
  47. # include <sysent.h>
  48. #endif
  49.  
  50. #include "blocktype.h"        /* A generally useful include */
  51. #include "dynarr.h"        /* A generally useful include */
  52. #include "symsinit.h"        /* compiler warning suppression */
  53.  
  54. /* Also define min() and max(). (Some compilers put them in strange
  55.    places that won't be referenced by the above include files, such
  56.    as 'macros.h' under Solaris.) */
  57.  
  58. #ifndef min
  59. #define min(a,b) ((a) <= (b) ? (a) : (b))
  60. #endif
  61. #ifndef max
  62. #define max(a,b) ((a) > (b) ? (a) : (b))
  63. #endif
  64.  
  65. /* Emacs needs to use its own definitions of certain system calls on
  66.    some systems (like SunOS 4.1 and USG systems, where the read system
  67.    call is interruptible but Emacs expects it not to be; and under
  68.    MULE, where all filenames need to be converted to external format).
  69.    To do this, we #define read to be sys_read, which is defined in
  70.    sysdep.c.  We first #undef read, in case some system file defines
  71.    read as a macro.  sysdep.c doesn't encapsulate read, so the call to
  72.    read inside of sys_read will do the right thing.
  73.  
  74.    DONT_ENCAPSULATE is used in files such as sysdep.c that want to
  75.    call the actual system calls rather than the encapsulated versions.
  76.    Those files can call sys_read to get the (possibly) encapsulated
  77.    versions.
  78.  
  79.    IMPORTANT: the redefinition of the system call must occur *after* the
  80.    inclusion of any header files that declare or define the system call;
  81.    otherwise lots of unfriendly things can happen.  This goes for all
  82.    encapsulated system calls.
  83.  
  84.    We encapsulate the most common system calls here; we assume their
  85.    declarations are in one of the standard header files included above.
  86.    Other encapsulations are declared in the appropriate sys*.h file. */
  87.  
  88. #if defined (ENCAPSULATE_READ) && !defined (DONT_ENCAPSULATE)
  89. # undef read
  90. # define read sys_read
  91. #endif
  92. #if !defined (ENCAPSULATE_READ) && defined (DONT_ENCAPSULATE)
  93. # define sys_read read
  94. #endif
  95.  
  96. #if defined (ENCAPSULATE_WRITE) && !defined (DONT_ENCAPSULATE)
  97. # undef write
  98. # define write sys_write
  99. #endif
  100. #if !defined (ENCAPSULATE_WRITE) && defined (DONT_ENCAPSULATE)
  101. # define sys_write write
  102. #endif
  103.  
  104. #if defined (ENCAPSULATE_OPEN) && !defined (DONT_ENCAPSULATE)
  105. # undef open
  106. # define open sys_open
  107. #endif
  108. #if !defined (ENCAPSULATE_OPEN) && defined (DONT_ENCAPSULATE)
  109. # define sys_open open
  110. #endif
  111.  
  112. #if defined (ENCAPSULATE_CLOSE) && !defined (DONT_ENCAPSULATE)
  113. # undef close
  114. # define close sys_close
  115. #endif
  116. #if !defined (ENCAPSULATE_CLOSE) && defined (DONT_ENCAPSULATE)
  117. # define sys_close close
  118. #endif
  119.  
  120. /* Now the stdio versions ... */
  121.  
  122. #if defined (ENCAPSULATE_FREAD) && !defined (DONT_ENCAPSULATE)
  123. # undef fread
  124. # define fread sys_fread
  125. #endif
  126. #if !defined (ENCAPSULATE_FREAD) && defined (DONT_ENCAPSULATE)
  127. # define sys_fread fread
  128. #endif
  129.  
  130. #if defined (ENCAPSULATE_FWRITE) && !defined (DONT_ENCAPSULATE)
  131. # undef fwrite
  132. # define fwrite sys_fwrite
  133. #endif
  134. #if !defined (ENCAPSULATE_FWRITE) && defined (DONT_ENCAPSULATE)
  135. # define sys_fwrite fwrite
  136. #endif
  137.  
  138. #if defined (ENCAPSULATE_FOPEN) && !defined (DONT_ENCAPSULATE)
  139. # undef fopen
  140. # define fopen sys_fopen
  141. #endif
  142. #if !defined (ENCAPSULATE_FOPEN) && defined (DONT_ENCAPSULATE)
  143. # define sys_fopen fopen
  144. #endif
  145.  
  146. #if defined (ENCAPSULATE_FCLOSE) && !defined (DONT_ENCAPSULATE)
  147. # undef fclose
  148. # define fclose sys_fclose
  149. #endif
  150. #if !defined (ENCAPSULATE_FCLOSE) && defined (DONT_ENCAPSULATE)
  151. # define sys_fclose fclose
  152. #endif
  153.  
  154. /* generally useful */
  155. #define countof(x) (sizeof(x)/sizeof(x[0]))
  156. #define slot_offset(type, slot_name) \
  157.   ((unsigned) (((char *) (&(((type *)0)->slot_name))) - ((char *)0)))
  158. #define malloc_type(type) ((type *) xmalloc (sizeof (type)))
  159. #define malloc_type_and_zero(type) ((type *) xmalloc_and_zero (sizeof (type)))
  160.  
  161. /* also generally useful if you want to avoid arbitrary size limits
  162.    but don't need a full dynamic array.  Assumes that BASEVAR points
  163.    to a malloced array of TYPE objects (or possibly a NULL pointer,
  164.    if SIZEVAR is 0), with the total size stored in SIZEVAR.  This
  165.    macro will realloc BASEVAR as necessary so that it can hold at
  166.    least NEEDED_SIZE objects.  The reallocing is done by doubling,
  167.    which ensures constant amortized time per element. */
  168. #define DO_REALLOC(basevar, sizevar, needed_size, type)    do        \
  169. {                                    \
  170.   /* Avoid side-effectualness. */                    \
  171.   /* Dammit! Macros suffer from dynamic scope! */            \
  172.   /* We demand inline functions! */                    \
  173.   int do_realloc_needed_size = (needed_size);                \
  174.   int newsize = 0;                            \
  175.   while ((sizevar) < (do_realloc_needed_size)) {            \
  176.     newsize = 2*(sizevar);                        \
  177.     if (newsize < 32)                            \
  178.       newsize = 32;                            \
  179.     (sizevar) = newsize;                        \
  180.   }                                    \
  181.   if (newsize)                                \
  182.     (basevar) = (type *) xrealloc (basevar, (newsize)*sizeof(type));    \
  183. } while (0)
  184.  
  185. #ifdef ERROR_CHECK_MALLOC
  186. #define xfree(lvalue) do                        \
  187. {                                    \
  188.   void **ptr = (void **) &(lvalue);                    \
  189.   xfree_1 (*ptr);                            \
  190.   *ptr = (void *) 0xDEADBEEF;                        \
  191. } while (0)
  192. #else
  193. #define xfree_1 xfree
  194. #endif
  195.  
  196. /* We assume an ANSI C compiler and libraries and memcpy, memset, memcmp */
  197. /*  (This definition is here because system header file macros may want
  198.  *   to call bzero (eg FD_ZERO) */
  199. #ifndef bzero
  200. #define bzero(m, l) memset ((m), 0, (l))
  201. #endif
  202.  
  203. #ifndef DOESNT_RETURN
  204. # ifdef __GNUC__
  205. #  define DOESNT_RETURN void volatile /* eg extern DOESNT_RETURN abort (); */
  206. # else
  207. #  define DOESNT_RETURN void
  208. # endif
  209. #endif
  210.  
  211. #ifndef ALIGNOF
  212. # if defined (__GNUC__) && (__GNUC__ >= 2)
  213. #  define ALIGNOF(x) __alignof(x)
  214. # else
  215. #  define ALIGNOF(x) sizeof(x)
  216. # endif
  217. #endif
  218.  
  219. #ifdef QUANTIFY
  220. #include "quantify.h"
  221. #define QUANTIFY_START_RECORDING                \
  222.   do { quantify_start_recording_data (); } while (0)
  223. #define QUANTIFY_STOP_RECORDING                    \
  224.   do { quantify_stop_recording_data (); } while (0)
  225. #else /* !QUANTIFY */
  226. #define QUANTIFY_START_RECORDING
  227. #define QUANTIFY_STOP_RECORDING
  228. #endif /* !QUANTIFY */
  229.  
  230.  
  231. #ifndef DO_NOTHING
  232. #define DO_NOTHING do {} while (0)
  233. #endif
  234.  
  235. /* We define assert iff USE_ASSERTIONS or DEBUG_XEMACS is defined.
  236.    Otherwise we it to NULL.  Quantify has shown that the time the
  237.    assert checks take is measurable so let's not include them in
  238.    production binaries. */
  239.  
  240. #ifdef USE_ASSERTIONS
  241. /* Highly dubious kludge */
  242. /*   (thanks, Jamie, I feel better now -- ben) */
  243. extern void assert_failed (CONST char *, int, CONST char *);
  244. # define abort() (assert_failed (__FILE__, __LINE__, "abort()"))
  245. # define assert(x) ((x) ? (void) 0 : assert_failed (__FILE__, __LINE__, #x))
  246. #else
  247. # ifdef DEBUG_XEMACS
  248. #  define assert(x) ((x) ? (void) 0 : (void) abort ())
  249. # else
  250. #  define assert(x)
  251. # endif
  252. #endif
  253.  
  254. #ifdef DEBUG_XEMACS
  255. #define REGISTER
  256. #else
  257. #define REGISTER register
  258. #endif
  259.  
  260. #ifndef INT_MAX
  261. #define INT_MAX ((int) ((1U << (INTBITS - 1)) - 1))
  262. #endif
  263.  
  264. #if defined (__GNUC__) && (__GNUC__ >= 2)
  265. /* Entomological studies have revealed that the following junk is
  266.    necessary under GCC.  GCC has a compiler bug where incorrect
  267.    code will be generated if you use a global temporary variable
  268.    in a macro and the macro occurs twice in the same expression.
  269.    As it happens, we can avoid this problem using a GCC language
  270.    extension.  Thus we play weird games with syntax to avoid having
  271.    to provide two definitions for lots of macros.
  272.  
  273.    The approximate way this works is as follows:
  274.  
  275.    1. Use these macros whenever you want to avoid evaluating an
  276.       argument more than once in a macro. (It's almost always a
  277.       good idea to make your macros safe like this.)
  278.    2. Choose a name for the temporary variable you will store
  279.       the parameter in.  It should begin with `mactemp_' and
  280.       be distinguishing, since it will (or may) be a global
  281.       variable.
  282.    3. In the same header file as the macro, put in a
  283.       MAC_DECLARE_EXTERN for the temporary variable.  This
  284.       resolves to an external variable declaration for some
  285.       compilers.
  286.    4. Put a MAC_DEFINE for the variable in a C file somewhere.
  287.       This resolves to a variable definition for some compilers.
  288.    5. Write your macro with no semicolons or commas in it.
  289.       Remember to use parentheses to surround macro arguments,
  290.       but you do not need to surround each separate statement
  291.       or the temporary variable with parentheses.
  292.    6. Write your macro like this:
  293.  
  294. #define foo(bar,baz)                        \
  295. MAC_BEGIN                            \
  296.   MAC_DECLARE (struct frobozz *, mactemp_foobar, bar)        \
  297.   SOME_EXPRESSION                        \
  298.   MAC_SEP                            \
  299.   SOME OTHER EXPRESSION                        \
  300. MAC_END
  301.  
  302.    7. You only need to use MAC_SEP if you have more than one
  303.       expression in the macro, not counting any MAC_DECLARE
  304.       statements.
  305.  
  306.   DONT_DECLARE_MAC_VARS is used in signal.c, for asynchronous signals.
  307.   All functions that may be called from within an asynchronous signal
  308.   handler must declare local variables (with MAC_DECLARE_LOCAL) for
  309.   the (normally global) variables used in these sorts of macros.
  310.   Otherwise, a signal could occur in the middle of processing one
  311.   of these macros and the signal handler could use the same macro,
  312.   resulting in the global variable getting overwritten and yielding
  313.   nasty evil crashes that are very difficult to track down.
  314. */
  315. # define MAC_BEGIN ({
  316. # define MAC_DECLARE(type, var, value) type var = (value);
  317. # define MAC_SEP ;
  318. # define MAC_END ; })
  319. # define MAC_DECLARE_EXTERN(type, var)
  320. # define MAC_DECLARE_LOCAL(type, var)
  321. # define MAC_DEFINE(type, var)
  322. #else
  323. # define MAC_BEGIN (
  324. # define MAC_DECLARE(type, var, value) var = (value),
  325. # define MAC_SEP ,
  326. # define MAC_END )
  327. # ifdef DONT_DECLARE_MAC_VARS
  328. #  define MAC_DECLARE_EXTERN(type, var)
  329. # else
  330. #  define MAC_DECLARE_EXTERN(type, var) extern type var;
  331. # endif
  332. # define MAC_DECLARE_LOCAL(type, var) type var
  333. # define MAC_DEFINE(type, var) type var
  334. #endif
  335.  
  336.  
  337. /************************************************************************/
  338. /*                                typedefs                              */
  339. /************************************************************************/
  340.  
  341. /* We put typedefs here so that prototype declarations don't choke.
  342.    Note that we don't actually declare the structures here (except
  343.    maybe for simple structures like Dynarrs); that keeps them private
  344.    to the routines that actually use them. */
  345.  
  346. /* The data representing the text in a buffer is logically a set
  347.    of Bufbytes, declared as follows. */
  348.  
  349. typedef unsigned char Bufbyte;
  350.  
  351. /* To the user, a buffer is made up of characters, declared as follows.
  352.    In the non-Mule world, characters and Bufbytes are equivalent.
  353.    In the Mule world, a characters requires (typically) 1 to 4
  354.    Bufbytes for its representation in a buffer. */
  355.  
  356. typedef int Emchar;
  357.  
  358. /* Different ways of referring to a position in a buffer.  We use
  359.    the typedefs in preference to 'int' to make it clearer what
  360.    sort of position is being used.  See extents.c for a description
  361.    of the different positions.  We put them here instead of in
  362.    buffer.h (where they rightfully belong) to avoid syntax errors
  363.    in function prototypes. */
  364.  
  365. typedef int Bufpos;
  366. typedef int Bytind;
  367. typedef int Memind;
  368.  
  369. /* Counts of bytes or chars */
  370.  
  371. typedef int Bytecount;
  372. typedef int Charcount;
  373.  
  374. typedef struct lstream Lstream;
  375.  
  376. typedef unsigned int face_index;
  377. typedef struct face_cache_element_dynarr_type
  378. {
  379.   Dynarr_declare (struct face_cache_element);
  380. } face_cache_element_dynarr;
  381.  
  382. typedef unsigned int glyph_index;
  383. typedef struct glyph_cache_element_dynarr_type
  384. {
  385.   Dynarr_declare (struct glyph_cache_element);
  386. } glyph_cache_element_dynarr;
  387.  
  388. struct buffer;                  /* "buffer.h" */
  389. struct device;            /* device.h */
  390. struct extent_fragment;
  391. struct extent;
  392. struct frame;            /* "frame.h" */
  393. struct window;                  /* "window.h" */
  394. struct Lisp_Event;              /* "events.h" */
  395. struct Lisp_Process;            /* "process.c" */
  396. struct stat;                    /* <sys/stat.h> */
  397. struct Lisp_Color_Instance;
  398. struct Lisp_Font_Instance;
  399. struct Lisp_Image_Instance;
  400. struct font_metric_info;
  401.  
  402. typedef struct bufbyte_dynarr_type
  403. {
  404.   Dynarr_declare (Bufbyte);
  405. } bufbyte_dynarr;
  406.  
  407. typedef struct emchar_dynarr_type
  408. {
  409.   Dynarr_declare (Emchar);
  410. } emchar_dynarr;
  411.  
  412. typedef struct unsigned_char_dynarr_type
  413. {
  414.   Dynarr_declare (unsigned char);
  415. } unsigned_char_dynarr;
  416.  
  417. typedef struct int_dynarr_type
  418. {
  419.   Dynarr_declare (int);
  420. } int_dynarr;
  421.  
  422.  
  423. /************************************************************************/
  424. /*                   Definition of Lisp_Object data type                */
  425. /************************************************************************/
  426.  
  427. /* There's not any particular reason not to use lrecords for these; some
  428.    objects get slightly larger, but we get 3 bit tags instead of 4.
  429.  */
  430. #define LRECORD_SYMBOL
  431.  
  432.  
  433. /* Define the fundamental Lisp data structures */
  434.  
  435. /* This is the set of Lisp data types */
  436.  
  437. enum Lisp_Type
  438.   {
  439.     /* Integer.  XINT(obj) is the integer value. */
  440.     Lisp_Int                    /* 0  DTP-FIXNUM */
  441.  
  442.     /* XRECORD_LHEADER (object) points to a struct lrecord_header
  443.        lheader->implementation determines the type (and GC behaviour)
  444.        of the object. */
  445.     ,Lisp_Record                /* 1  DTP-OTHER-POINTER */
  446.  
  447.     /* Cons.  XCONS (object) points to a struct Lisp_Cons. */
  448.     ,Lisp_Cons                  /* 2  DTP-LIST */
  449.  
  450. /* LRECORD_STRING is NYI */
  451.     /* String.  XSTRING (object) points to a struct Lisp_String.
  452.        The length of the string, and its contents, are stored therein. */
  453.     ,Lisp_String                /* 3  DTP-STRING */
  454.  
  455. #ifndef LRECORD_VECTOR
  456.     /* Vector of Lisp objects.  XVECTOR(object) points to a struct Lisp_Vector.
  457.        The length of the vector, and its contents, are stored therein. */
  458.     ,Lisp_Vector                /* 4  DTP-SIMPLE-ARRAY */
  459. #endif
  460.  
  461. #ifndef LRECORD_SYMBOL
  462.     /* Symbol.  XSYMBOL (object) points to a struct Lisp_Symbol. */
  463.     ,Lisp_Symbol
  464. #endif /* !LRECORD_SYMBOL */
  465.   };
  466.  
  467. #define POINTER_TYPE_P(type) ((type) != Lisp_Int)
  468.  
  469. /* This should be the underlying type intowhich a Lisp_Object must fit.
  470.    In a strict ANSI world, this must be `int', since ANSI says you can't
  471.    use bitfields on any type other than `int'.  However, on a machine
  472.    where `int' and `long' are not the same size, this should be the
  473.    longer of the two.  (This also must be something into which a pointer
  474.    to an arbitrary object will fit, modulo any DATA_SEG_BITS cruft.)
  475.  */
  476. #if (LONGBITS > INTBITS)
  477. # define LISP_WORD_TYPE long
  478. #else
  479. # define LISP_WORD_TYPE int
  480. #endif
  481.  
  482. /* Cast pointers to this type to compare them.  Some machines want int.  */
  483. #ifndef PNTR_COMPARISON_TYPE
  484. # define PNTR_COMPARISON_TYPE unsigned int
  485. #endif
  486.  
  487. /* These values are overridden by the m- file on some machines.  */
  488. #ifndef GCTYPEBITS
  489. # define GCTYPEBITS 3L
  490. #endif
  491.  
  492. #ifndef VALBITS
  493. # define VALBITS ((LONGBITS)-((GCTYPEBITS)+1L))
  494. #endif
  495.  
  496. #ifdef NO_UNION_TYPE
  497. # include "lisp-disunion.h"
  498. #else /* !NO_UNION_TYPE */
  499. # include "lisp-union.h"
  500. #endif /* !NO_UNION_TYPE */
  501.  
  502. /* WARNING WARNING WARNING.  You must ensure on your own that proper
  503.    GC protection is provided for the elements in this array. */
  504. typedef struct lisp_dynarr_type
  505. {
  506.   Dynarr_declare (Lisp_Object);
  507. } lisp_dynarr;
  508.  
  509.  
  510. /************************************************************************/
  511. /*                   Definitions of basic Lisp objects                  */
  512. /************************************************************************/
  513.  
  514. #include "lrecord.h"
  515.  
  516. /********** unbound ***********/
  517.  
  518. /* Qunbound is a special Lisp_Object (actually of type
  519.    symbol-value-forward), that can never be visible to
  520.    the Lisp caller and thus can be used in the C code
  521.    to mean "no such value". */
  522.  
  523. #define UNBOUNDP(val) EQ (val, Qunbound)
  524.   
  525. /*********** cons ***********/
  526.  
  527. /* In a cons, the markbit of the car is the gc mark bit */
  528.  
  529. struct Lisp_Cons
  530.   {
  531.     Lisp_Object car, cdr;
  532.   };
  533.  
  534. #if 0 /* FSFmacs */
  535. /* Like a cons, but records info on where the text lives that it was read from */
  536. /* This is not really in use now */
  537.  
  538. struct Lisp_Buffer_Cons
  539.   {
  540.     Lisp_Object car, cdr;
  541.     struct buffer *buffer;
  542.     int bufpos;
  543.   };
  544. #endif
  545.  
  546. DECLARE_NONRECORD (cons, struct Lisp_Cons);
  547. #define XCONS(a) XNONRECORD (a, cons, Lisp_Cons, struct Lisp_Cons)
  548. #define XSETCONS(c, p) XSETOBJ (c, Lisp_Cons, p)
  549. #define CONSP(x) (XTYPE (x) == Lisp_Cons)
  550. #define CHECK_CONS(x, i) \
  551.   do { if (!CONSP (x)) x = wrong_type_argument (Qconsp, x); } while (0)
  552.  
  553. #define NILP(x)  EQ (x, Qnil)
  554. #define CHECK_LIST(x, i) \
  555.   do { if ((!CONSP (x)) && !NILP (x)) x = wrong_type_argument (Qlistp, x); } while (0)
  556. #define XCAR(a) (XCONS (a)->car)
  557. #define XCDR(a) (XCONS (a)->cdr)
  558.  
  559. /* For a list that's known to be in valid list format --
  560.    will abort() if the list is not in valid format */
  561. #define LIST_LOOP(consvar, list) \
  562.   for (consvar = list; !NILP (consvar); consvar = XCDR (consvar))
  563.  
  564. /* For a list that may not be in valid list format --
  565.    will signal an error if the list is not in valid format */
  566. #define EXTERNAL_LIST_LOOP(consvar, listp)                \
  567.   for (consvar = listp; !NILP (consvar); consvar = XCDR (consvar))    \
  568.      if (!CONSP (consvar))                        \
  569.        signal_simple_error ("Invalid list format", listp);        \
  570.      else
  571.  
  572. /* For a property list (alternating keywords/values) that may not be
  573.    in valid list format -- will signal an error if the list is not in
  574.    valid format.  CONSVAR is used to keep track of the iterations
  575.    without modifying LISTP.
  576.  
  577.    We have to be tricky to still keep the same C format.*/
  578. #define EXTERNAL_PROPERTY_LIST_LOOP(consvar, keyword, value, listp)    \
  579.   for (consvar = listp;                            \
  580.        (CONSP (consvar) && CONSP (XCDR (consvar)) ?            \
  581.     (keyword = XCAR (consvar), value = XCAR (XCDR (consvar))) :    \
  582.     (keyword = Qunbound, value = Qunbound)),            \
  583.        !NILP (consvar);                            \
  584.        consvar = XCDR (XCDR (consvar)))                    \
  585.     if (UNBOUNDP (keyword))                        \
  586.       signal_simple_error ("Invalid property list format", listp);    \
  587.     else
  588.  
  589. /*********** string ***********/
  590.  
  591. /* In a string or vector, the sign bit of the `size' is the gc mark bit */
  592.  
  593. /* (The size and data fields have underscores prepended to catch old
  594.    code that attempts to reference the fields directly) */
  595. struct Lisp_String
  596.   {
  597. #ifdef LRECORD_STRING
  598.     struct lrecord_header lheader;
  599. #endif
  600.     long _size;
  601.     Bufbyte *_data;
  602.     Lisp_Object plist;
  603.   };
  604.  
  605. #ifdef LRECORD_STRING
  606.  
  607. DECLARE_LRECORD (string, struct Lisp_String);
  608. #define XSTRING(x) XRECORD (x, string, struct Lisp_String)
  609. #define XSETSTRING(x, p) XSETRECORD (x, p, string)
  610. #define STRINGP(x) RECORDP (x, string)
  611. #define CHECK_STRING(x, i) CHECK_RECORD (x, string)
  612.  
  613. #else
  614.  
  615. DECLARE_NONRECORD (string, struct Lisp_String);
  616. #define XSTRING(x) XNONRECORD (x, string, Lisp_String, struct Lisp_String)
  617. #define XSETSTRING(x, p) XSETOBJ (x, Lisp_String, p)
  618. #define STRINGP(x) (XTYPE (x) == Lisp_String)
  619. #define CHECK_STRING(x, i) \
  620.   do { if (!STRINGP (x)) x = wrong_type_argument (Qstringp, x); } while (0)
  621.  
  622. #endif
  623.  
  624. #define string_length(s) ((s)->_size)
  625. #define string_data(s) ((s)->_data + 0)
  626. #define string_byte(s, i) ((s)->_data[i] + 0)
  627. #define set_string_length(s, len) do { (s)->_size = (len); } while (0)
  628. #define set_string_data(s, ptr) do { (s)->_data = (ptr); } while (0)
  629. #define set_string_byte(s, i, c) do { (s)->_data[i] = (c); } while (0)
  630. #define string_dups(s) string_getprop (s, Qdup_list, Qnil)
  631. #define set_string_dups(s, list) string_putprop (s, Qdup_list, list)
  632.  
  633. #ifdef MULE
  634. # define string_char_length(s)    ---- no Mule support yet ----
  635. # define string_ext_length(s)    ---- no Mule support yet ----
  636. # define string_char(s, i)    ---- no Mule support yet ----
  637. # define set_string_char(s, i, c)    ---- no Mule support yet ----
  638. #else
  639. # define string_char_length(s) string_length (s)
  640. # define string_ext_length(s) string_length (s)
  641. # define string_char(s, i) ((Emchar) string_byte (s, i))
  642. # define set_string_char(s, i, c) set_string_byte (s, i, c)
  643. #endif /* MULE */
  644.  
  645. extern char *string_ext_data_static (struct Lisp_String *s, int bin);
  646. extern char *string_ext_data_malloc (struct Lisp_String *s);
  647.  
  648. #define string_ext_data(s) string_ext_data_static (s, 0)
  649. #define string_ext_data2(s) string_ext_data_static (s, 1)
  650. #define string_ext_data3(s) string_ext_data_static (s, 2)
  651. #define string_ext_data4(s) string_ext_data_static (s, 3)
  652. #define string_ext_data5(s) string_ext_data_static (s, 4)
  653.  
  654. /*********** vector ***********/
  655.  
  656. struct Lisp_Vector
  657.   {
  658. #ifdef LRECORD_VECTOR
  659.     struct lrecord_header lheader;
  660. #endif
  661.     long size;
  662.     /* next is now chained through v->contents[size], terminated by Qzero.
  663.      * This means that pure vectors don't need a "next" */
  664.     /* struct Lisp_Vector *next; */
  665.     Lisp_Object contents[1];
  666.   };
  667.  
  668. #ifdef LRECORD_VECTOR
  669.  
  670. DECLARE_LRECORD (vector, struct Lisp_Vector);
  671. #define XVECTOR(x) XRECORD (x, vector, struct Lisp_Vector)
  672. #define XSETVECTOR(x, p) XSETRECORD (x, p, vector)
  673. #define VECTORP(x) RECORDP (x, vector)
  674. #define CHECK_VECTOR(x, i) CHECK_RECORD (x, vector)
  675.  
  676. #else
  677.  
  678. DECLARE_NONRECORD (vector, struct Lisp_Vector);
  679. #define XVECTOR(x) XNONRECORD (x, vector, Lisp_Vector, struct Lisp_Vector)
  680. #define XSETVECTOR(x, p) XSETOBJ (x, Lisp_Vector, p)
  681. #define VECTORP(x) (XTYPE (x) == Lisp_Vector)
  682. #define CHECK_VECTOR(x, i) \
  683.   do { if (!VECTORP (x)) x = wrong_type_argument (Qvectorp, x); } while(0)
  684.  
  685. #endif
  686.  
  687. #define vector_length(v) ((v)->size)
  688. #define vector_data(v) ((v)->contents)
  689. #define vector_next(v) ((v)->contents[(v)->size])
  690.  
  691. /*********** symbol ***********/
  692.  
  693. /* In a symbol, the markbit of the plist is used as the gc mark bit */
  694.  
  695. struct Lisp_Symbol
  696.   {
  697. #ifdef LRECORD_SYMBOL
  698.     struct lrecord_header lheader;
  699. #endif
  700.     /* next symbol in this obarray bucket */
  701.     struct Lisp_Symbol *next;
  702.     struct Lisp_String *name;
  703.     Lisp_Object value;
  704.     Lisp_Object function;
  705.     Lisp_Object plist;
  706.   };
  707.  
  708. #define SYMBOL_IS_KEYWORD(sym) (string_byte (XSYMBOL(sym)->name, 0) == ':')
  709. #define KEYWORDP(obj) (SYMBOLP (obj) && SYMBOL_IS_KEYWORD (obj))
  710.  
  711. #ifdef LRECORD_SYMBOL
  712.  
  713. DECLARE_LRECORD (symbol, struct Lisp_Symbol);
  714. #define XSYMBOL(x) XRECORD (x, symbol, struct Lisp_Symbol)
  715. #define XSETSYMBOL(x, p) XSETRECORD (x, p, symbol)
  716. #define SYMBOLP(x) RECORDP (x, symbol)
  717. #define CHECK_SYMBOL(x, i) CHECK_RECORD (x, symbol)
  718.  
  719. #else
  720.  
  721. DECLARE_NONRECORD (symbol, struct Lisp_Symbol);
  722. #define XSYMBOL(x) XNONRECORD (x, symbol, Lisp_Symbol, struct Lisp_Symbol)
  723. #define XSETSYMBOL(s, p) XSETOBJ ((s), Lisp_Symbol, (p))
  724. #define SYMBOLP(x) (XTYPE (x) == Lisp_Symbol)
  725. #define CHECK_SYMBOL(x, i) \
  726.   do { if (!SYMBOLP (x)) x = wrong_type_argument (Qsymbolp, x); } while(0)
  727.  
  728. #endif
  729.  
  730. #define symbol_next(s) ((s)->next)
  731.  
  732. /*********** subr ***********/
  733.  
  734. struct Lisp_Subr
  735.   {
  736.     struct lrecord_header lheader;
  737.     short min_args, max_args;
  738.     CONST char *prompt;
  739.     CONST char *doc;
  740.     CONST char *name;
  741.     Lisp_Object (*subr_fn) ();
  742.   };
  743.  
  744. DECLARE_LRECORD (subr, struct Lisp_Subr);
  745. #define XSUBR(x) XRECORD (x, subr, struct Lisp_Subr)
  746. #define XSETSUBR(x, p) XSETRECORD (x, p, subr)
  747. #define SUBRP(x) RECORDP (x, subr)
  748. #define CHECK_SUBR(x, i) CHECK_RECORD (x, subr)
  749.  
  750. #define subr_function(subr) (subr)->subr_fn
  751. #define subr_name(subr) (subr)->name
  752.  
  753. /*********** marker ***********/
  754.  
  755. struct Lisp_Marker
  756.   {
  757.     struct lrecord_header lheader;
  758.     struct Lisp_Marker *next;
  759.     struct buffer *buffer;
  760.     Memind memind;
  761.   };
  762.  
  763. DECLARE_LRECORD (marker, struct Lisp_Marker);
  764. #define XMARKER(x) XRECORD (x, marker, struct Lisp_Marker)
  765. #define XSETMARKER(x, p) XSETRECORD (x, p, marker)
  766. #define MARKERP(x) RECORDP (x, marker)
  767. #define CHECK_MARKER(x, i) CHECK_RECORD (x, marker)
  768.  
  769. /* The second check was looking for GCed markers still in use */
  770. /* if (INTP (XMARKER (x)->lheader.next.v)) abort (); */
  771.  
  772. #define marker_next(m) ((m)->next)
  773.  
  774. /*********** float ***********/
  775.  
  776. #ifdef LISP_FLOAT_TYPE
  777.  
  778. struct Lisp_Float
  779.   {
  780.     struct lrecord_header lheader;
  781.     union { double d; struct Lisp_Float *next; } data;
  782.   };
  783.  
  784. DECLARE_LRECORD (float, struct Lisp_Float);
  785. #define XFLOAT(x) XRECORD (x, float, struct Lisp_Float)
  786. #define XSETFLOAT(x, p) XSETRECORD (x, p, float)
  787. #define FLOATP(x) RECORDP (x, float)
  788. #define CHECK_FLOAT(x, i) CHECK_RECORD (x, float)
  789.  
  790. #define float_next(f) ((f)->data.next)
  791. #define float_data(f) ((f)->data.d)
  792.  
  793. #ifndef DBL_DIG
  794. # define DBL_DIG 16
  795. #endif
  796.  
  797. #define XFLOATINT(n) extract_float (n)
  798.  
  799. #define CHECK_INT_OR_FLOAT(x, i)                \
  800.   do { if ( !INTP (x) && !FLOATP (x))                \
  801.        x = wrong_type_argument (Qnumberp, (x)); } while (0)
  802.  
  803. #define CHECK_INT_OR_FLOAT_COERCE_MARKER(x, i)                \
  804.   do { if (INTP (x) || FLOATP (x))                    \
  805.          ;                                \
  806.        else if (MARKERP (x))                        \
  807.          x = make_number (marker_position (x));                \
  808.        else                                \
  809.          x = wrong_type_argument (Qnumber_or_marker_p, x); } while (0)
  810.  
  811. # define INT_OR_FLOATP(x) (INTP (x) || FLOATP (x))
  812.  
  813. #else /* not LISP_FLOAT_TYPE */
  814.  
  815. #define XFLOAT(x) --- error!  No float support. ---
  816. #define XSETFLOAT(x, p) --- error!  No float support. ---
  817. #define FLOATP(x) 0
  818. #define CHECK_FLOAT(x, i) --- error!  No float support. ---
  819.  
  820. #define XFLOATINT(n) XINT(n)
  821. #define CHECK_INT_OR_FLOAT CHECK_INT
  822. #define CHECK_INT_OR_FLOAT_COERCE_MARKER CHECK_INT_COERCE_MARKER
  823. #define INT_OR_FLOATP(x) (INTP (x))
  824.  
  825. #endif /* not LISP_FLOAT_TYPE */
  826.  
  827. #define INTP(x) (XTYPE (x) == Lisp_Int)
  828.  
  829. #define CHECK_INT(x, i) \
  830.   do { if (!INTP (x)) x = wrong_type_argument (Qintegerp, x); } while (0)
  831.  
  832. #define NATNUMP(x) (INTP (x) && XINT (x) >= 0)
  833.  
  834. #define CHECK_NATNUM(x, i) \
  835.   do { if (!NATNUMP (x)) x = wrong_type_argument (Qnatnump, x); } while (0)
  836.  
  837. #ifdef MULE
  838. extern int valid_emchar_p (Emchar ch);
  839. #define CHARP(x) (INTP (x) && valid_emchar_p (XINT (x)))
  840. #else
  841. /* #### Ugh, backward compatibility: should check for a range of 0 - 255 */
  842. #define CHARP(x) INTP (x)
  843. #endif
  844.  
  845. #ifdef MULE
  846. #define COERCE_CHAR(x)
  847. #else
  848. #define COERCE_CHAR(x) \
  849.   do { XSETINT (x, XINT (x) & 0xFF); } while (0)
  850. #endif
  851.   
  852.  
  853. #define CHECK_COERCE_CHAR(x, i)                        \
  854.   do { if (!CHARP (x)) x = wrong_type_argument (Qcharacterp, x);    \
  855.        COERCE_CHAR (x); } while (0)
  856.  
  857. #define CHECK_INT_COERCE_MARKER(x, i)                    \
  858.   do { if (INTP (x))                            \
  859.          ;                                \
  860.        else if (MARKERP (x))                        \
  861.          x = make_number (marker_position (x));                \
  862.        else                                \
  863.          x = wrong_type_argument (Qinteger_or_marker_p, x); } while (0)
  864.  
  865.  
  866. /*********** pure space ***********/
  867.  
  868. #define CHECK_IMPURE(obj) \
  869.   do { if (purified (obj)) pure_write_error (); } while (0)
  870.  
  871.  
  872. /************************************************************************/
  873. /*         Definitions of primitive Lisp functions and variables        */
  874. /************************************************************************/
  875.  
  876. /* Define a built-in function for calling from Lisp.
  877.  `lname' should be the name to give the function in Lisp,
  878.     as a null-terminated C string.
  879.  `fnname' should be the name of the function in C.
  880.     By convention, it starts with F.
  881.  `sname' should be the name for the C constant structure
  882.     that records information on this function for internal use.
  883.     By convention, it should be the same as `fnname' but with S instead of F.
  884.     It's too bad that C macros can't compute this from `fnname'.
  885.  `minargs' should be a number, the minimum number of arguments allowed.
  886.  `maxargs' should be a number, the maximum number of arguments allowed,
  887.     or else MANY or UNEVALLED.
  888.     MANY means pass a vector of evaluated arguments,
  889.      in the form of an integer number-of-arguments
  890.      followed by the address of a vector of Lisp_Objects
  891.      which contains the argument values.
  892.     UNEVALLED means pass the list of unevaluated arguments
  893.  `prompt' says how to read arguments for an interactive call.
  894.     This can be zero or a C string.
  895.     Zero means that interactive calls are not allowed.
  896.     A string is interpreted in a hairy way:
  897.      it should contain one line for each argument to be read, terminated by \n.
  898.      The first character of the line controls the type of parsing:
  899.        s  --  read a string.
  900.        S  --  read a symbol.
  901.        k  --  read a key sequence and return it as a string.
  902.        a  --  read a function name (symbol) with completion.
  903.        C  --  read a command name (symbol) with completion.
  904.        v  --  read a variable name (symbol) with completion.
  905.        b  --  read a buffer name (a string) with completion.
  906.        B  --  buffer name, may be existing buffer or may not be.
  907.        f  --  read a file name, file must exist.
  908.        F  --  read a file name, file need not exist.
  909.        n  --  read a number.
  910.        c  --  read a character and return it as a number.
  911.        p  --  use the numeric value of the prefix argument.
  912.        P  --  use raw value of prefix - can be nil, -, (NUMBER) or NUMBER.
  913.        x  --  read a Lisp object from the minibuffer.
  914.        X  --  read a Lisp form from the minibuffer and use its value.
  915.     A null string means call interactively with no arguments.
  916.  `doc' is documentation for the user.
  917. */
  918.  
  919. #define SUBR_MAX_ARGS 8
  920. #define MANY -2
  921. #define UNEVALLED -1
  922.  
  923. /* Can't be const, because then subr->doc is read-only and
  924.  *  FSnarf_documentation chokes */
  925. #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \
  926.   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; /* See below */ \
  927.   static struct Lisp_Subr sname \
  928.      = { { lrecord_subr }, minargs, maxargs, prompt, 0, lname, fnname }; \
  929.   Lisp_Object fnname
  930.  
  931. /* Scary ANSI C preprocessor hackery by Felix Lee <flee@guardian.cse.psu.edu>
  932.    to get DEFUN to declare a prototype that matches maxargs, so that the
  933.    compiler can complain if the "real" arglist doesn't match.  Clever hack
  934.    or repulsive kludge?  You be the judge.
  935.  */
  936.  
  937. /* WARNING: If you add defines below for higher values of maxargs,
  938.    make sure to also fix the clauses in funcall_subr() */
  939.  
  940. #define DEFUN_ARGS_MANY (int, Lisp_Object *)
  941. #define DEFUN_ARGS_UNEVALLED (Lisp_Object)
  942. #define DEFUN_ARGS_0 (void)
  943. #define DEFUN_ARGS_1 (Lisp_Object)
  944. #define DEFUN_ARGS_2 (Lisp_Object, Lisp_Object)
  945. #define DEFUN_ARGS_3 (Lisp_Object, Lisp_Object, Lisp_Object)
  946. #define DEFUN_ARGS_4 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
  947. #define DEFUN_ARGS_5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  948.               Lisp_Object)
  949. #define DEFUN_ARGS_6 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  950.               Lisp_Object, Lisp_Object)
  951. #define DEFUN_ARGS_7 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  952.               Lisp_Object, Lisp_Object, Lisp_Object)
  953. #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  954.               Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
  955. #define DEFUN_ARGS_9 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  956.               Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  957.               Lisp_Object)
  958. #define DEFUN_ARGS_10 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  959.                Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  960.                Lisp_Object, Lisp_Object)
  961. #define DEFUN_ARGS_11 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  962.                Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  963.                Lisp_Object, Lisp_Object, Lisp_Object)
  964. #define DEFUN_ARGS_12 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  965.                Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \
  966.                Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
  967.  
  968. #include "symeval.h"
  969.  
  970. /* Depth of special binding/unwind-protect stack.  Use as arg to unbind_to */
  971. extern int specpdl_depth (void);
  972.  
  973.  
  974. /************************************************************************/
  975. /*                         Checking for QUIT                            */
  976. /************************************************************************/
  977.  
  978. /* Asynchronous events set something_happened, and then are processed
  979.    within the QUIT macro.  At this point, we are guaranteed to not be in
  980.    any sensitive code. */
  981.  
  982. extern volatile int something_happened;
  983. extern int check_what_happened (void);
  984.  
  985. extern volatile int quit_check_signal_happened;
  986. extern volatile int quit_check_signal_tick_count;
  987. extern int check_quit (void);
  988.  
  989. extern void signal_quit (void);
  990.  
  991. /* Nonzero if ought to quit now.  */
  992. #define QUITP ((quit_check_signal_happened ? check_quit () : 0), \
  993.            (!NILP (Vquit_flag) && (NILP (Vinhibit_quit) \
  994.                        || EQ (Vquit_flag, Qcritical))))
  995.  
  996. /* QUIT used to call QUITP, but there are some places where QUITP
  997.    is called directly, and check_what_happened() should only be called
  998.    when Emacs is actually ready to quit because it could do things
  999.    like switch threads. */
  1000. #define INTERNAL_QUITP                            \
  1001.   ((something_happened ? check_what_happened () : 0),            \
  1002.    (!NILP (Vquit_flag) &&                        \
  1003.     (NILP (Vinhibit_quit) || EQ (Vquit_flag, Qcritical))))
  1004.  
  1005. #define INTERNAL_REALLY_QUITP                        \
  1006.   (check_what_happened (),                        \
  1007.    (!NILP (Vquit_flag) &&                        \
  1008.     (NILP (Vinhibit_quit) || EQ (Vquit_flag, Qcritical))))
  1009.  
  1010. /* Check quit-flag and quit if it is non-nil.  Also do any other things
  1011.    that might have gotten queued until it was safe. */
  1012. #define QUIT                                 \
  1013.   do { if (INTERNAL_QUITP) signal_quit (); } while (0)
  1014.  
  1015. #define REALLY_QUIT                            \
  1016.   do { if (INTERNAL_REALLY_QUITP) signal_quit (); } while (0)
  1017.  
  1018.  
  1019. /************************************************************************/
  1020. /*                               hashing                                */
  1021. /************************************************************************/
  1022.  
  1023. /* #### for a 64-bit machine, we should substitute a prime just over
  1024.    2^32 */
  1025. #define GOOD_HASH_VALUE 65599 /* prime number just over 2^16;
  1026.                  Dragon book, p. 435 */
  1027. #define HASH2(a, b) ((a) * GOOD_HASH_VALUE + (b))
  1028. #define HASH3(a, b, c) (HASH2 (a, b) * GOOD_HASH_VALUE + (c))
  1029. #define HASH4(a, b, c, d) (HASH3 (a, b, c) * GOOD_HASH_VALUE + (d))
  1030. #define HASH5(a, b, c, d, e) (HASH4 (a, b, c, d) * GOOD_HASH_VALUE + (e))
  1031. #define HASH6(a, b, c, d, e, f) (HASH5 (a, b, c, d, e) * GOOD_HASH_VALUE + (f))
  1032. #define HASH7(a, b, c, d, e, f, g) \
  1033.   (HASH6 (a, b, c, d, e, f) * GOOD_HASH_VALUE + (g))
  1034. #define HASH8(a, b, c, d, e, f, g, h) \
  1035.   (HASH7 (a, b, c, d, e, f, g) * GOOD_HASH_VALUE + (h))
  1036. #define HASH9(a, b, c, d, e, f, g, h, i) \
  1037.   (HASH8 (a, b, c, d, e, f, g, h) * GOOD_HASH_VALUE + (i))
  1038.  
  1039. /* Enough already! */
  1040.  
  1041. #define LISP_HASH(obj) ((unsigned long) LISP_TO_VOID (obj))
  1042. unsigned long string_hash (CONST void *xv);
  1043. unsigned long memory_hash (CONST void *xv, int size);
  1044. unsigned long internal_hash (Lisp_Object obj, int depth);
  1045.  
  1046.  
  1047. /************************************************************************/
  1048. /*                       String translation                             */
  1049. /************************************************************************/
  1050.  
  1051. #ifdef I18N3
  1052.  
  1053. # if 0
  1054. #  include <libintl.h>    /* SunOS 4 doesn't have this loser */
  1055. # else
  1056. extern char *dgettext (CONST char *, CONST char *);
  1057. extern char *gettext (CONST char *);
  1058. extern char *textdomain (CONST char *);
  1059. extern char *bindtextdomain (CONST char *, CONST char *);
  1060. # endif
  1061.  
  1062. # define GETTEXT(x)  gettext (x)
  1063. # define LISP_GETTEXT(x)  Fgettext (x)
  1064. #else /* !I18N3 */
  1065. # define GETTEXT(x)  (x)
  1066. # define LISP_GETTEXT(x)  (x)
  1067. #endif /* !I18N3 */
  1068.  
  1069. /* DEFER_GETTEXT is used to identify strings which are translated when
  1070.    they are referenced instead of when they are defined.
  1071.    These include Qerror_messages and initialized arrays of strings.
  1072. */
  1073. #define DEFER_GETTEXT(x) (x)
  1074.  
  1075.  
  1076.  
  1077. /************************************************************************/
  1078. /*                         Case conversion                              */
  1079. /************************************************************************/
  1080.  
  1081. /* A "trt" table is a mapping from characters to other characters,
  1082.    typically used to convert between uppercase and lowercase.  For
  1083.    compatibility reasons, trt tables are currently in the form of
  1084.    a Lisp string of 256 characters, specifying the conversion for each
  1085.    of the first 256 Emacs characters (i.e. the 256 extended-ASCII
  1086.    characters).  This should be generalized at some point to support
  1087.    conversions for all of the allowable Mule characters.
  1088.    */
  1089.  
  1090. MAC_DECLARE_EXTERN (Emchar, mactemp_trt_ch)
  1091.  
  1092. #define EMACS_TO_C_CHAR(c) ((Bufbyte) (c))
  1093. #define C_TO_EMACS_CHAR(c) ((Emchar) (c))
  1094. #define IN_TRT_TABLE_DOMAIN(c) ((c) >= 0 && (c) < 0400)
  1095.  
  1096. #define TRT_TABLE_OF(trt, c)                        \
  1097. MAC_BEGIN                                \
  1098.   MAC_DECLARE (Emchar, mactemp_trt_ch, c)                \
  1099.   IN_TRT_TABLE_DOMAIN (mactemp_trt_ch) ?                \
  1100.     C_TO_EMACS_CHAR (string_char (XSTRING (trt),            \
  1101.                   EMACS_TO_C_CHAR (mactemp_trt_ch))) :    \
  1102.     mactemp_trt_ch                            \
  1103. MAC_END
  1104.  
  1105. MAC_DECLARE_EXTERN (Emchar, mactemp_case_ch)
  1106.  
  1107. /* Macros used below. */
  1108. #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c)
  1109. #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c)
  1110.  
  1111. /* For Lo, the Lord didst appear and look upon the face of the code,
  1112.    and the Lord was unhappy with the strange syntax that had come
  1113.    into vogue with the cryptic name of "C".  And so the Lord didst
  1114.    decree, that from now on all programmers shall use Pascal syntax,
  1115.    a syntax truly and in sooth ordained in heaven.  Amen. */
  1116.  
  1117. /* 1 if CH is upper case.  */
  1118.  
  1119. #define UPPERCASEP(buf, ch)                    \
  1120. MAC_BEGIN                            \
  1121.   MAC_DECLARE (Emchar, mactemp_case_ch, ch)            \
  1122.   DOWNCASE_TABLE_OF (buf, mactemp_case_ch) != mactemp_case_ch    \
  1123. MAC_END
  1124.  
  1125. /* 1 if CH is lower case.  */
  1126.  
  1127. #define LOWERCASEP(buf, ch)                        \
  1128. MAC_BEGIN                                \
  1129.   MAC_DECLARE (Emchar, mactemp_case_ch, ch)                \
  1130.   UPCASE_TABLE_OF (buf, mactemp_case_ch) != mactemp_case_ch &&        \
  1131.     DOWNCASE_TABLE_OF (buf, mactemp_case_ch) == mactemp_case_ch        \
  1132. MAC_END
  1133.  
  1134. /* 1 if CH is neither upper nor lower case.  */
  1135.  
  1136. #define NOCASEP(buf, ch)                    \
  1137. MAC_BEGIN                            \
  1138.   MAC_DECLARE (Emchar, mactemp_case_ch, ch)            \
  1139.   UPCASE_TABLE_OF (buf, mactemp_case_ch) == mactemp_case_ch    \
  1140. MAC_END
  1141.  
  1142. /* Upcase a character, or make no change if that cannot be done.  */
  1143.  
  1144. #define UPCASE(buf, ch)                        \
  1145. MAC_BEGIN                            \
  1146.   MAC_DECLARE (Emchar, mactemp_case_ch, ch)            \
  1147.   DOWNCASE_TABLE_OF (buf, mactemp_case_ch) == mactemp_case_ch ?    \
  1148.     UPCASE_TABLE_OF (buf, mactemp_case_ch) : mactemp_case_ch    \
  1149. MAC_END
  1150.  
  1151. /* Upcase a character known to be not upper case.  */
  1152.  
  1153. #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)
  1154.  
  1155. /* Downcase a character, or make no change if that cannot be done. */
  1156.  
  1157. #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch)
  1158.  
  1159.  
  1160. /************************************************************************/
  1161. /*                   Garbage collection / GC-protection                 */
  1162. /************************************************************************/
  1163.  
  1164. /* number of bytes of structure consed since last GC */
  1165.  
  1166. extern int consing_since_gc;
  1167.  
  1168. /* threshold for doing another gc */
  1169.  
  1170. extern int gc_cons_threshold;
  1171.  
  1172. /* Structure for recording stack slots that need marking */
  1173.  
  1174. /* This is a chain of structures, each of which points at a Lisp_Object
  1175.    variable whose value should be marked in garbage collection.
  1176.    Normally every link of the chain is an automatic variable of a function,
  1177.    and its `val' points to some argument or local variable of the function.
  1178.    On exit to the function, the chain is set back to the value it had on
  1179.    entry.  This way, no link remains in the chain when the stack frame
  1180.    containing the link disappears. 
  1181.  
  1182.    Every function that can call Feval must protect in this fashion all
  1183.    Lisp_Object variables whose contents will be used again. */
  1184.  
  1185. extern struct gcpro *gcprolist;
  1186.  
  1187. struct gcpro
  1188.   {
  1189.     struct gcpro *next;
  1190.     Lisp_Object *var;        /* Address of first protected variable */
  1191.     int nvars;            /* Number of consecutive protected variables */
  1192.   };
  1193.  
  1194. #ifdef DEBUG_GCPRO
  1195.  
  1196. extern void debug_gcpro1(), debug_gcpro2(), debug_gcpro3(), debug_gcpro4(),
  1197.   debug_gcpro_5(), debug_ungcpro();
  1198.  
  1199. #define GCPRO1(v) \
  1200.  debug_gcpro1 (__FILE__, __LINE__,&gcpro1,&v)
  1201. #define GCPRO2(v1,v2) \
  1202.  debug_gcpro2 (__FILE__, __LINE__,&gcpro1,&gcpro2,&v1,&v2)
  1203. #define GCPRO3(v1,v2,v3) \
  1204.  debug_gcpro3 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&v1,&v2,&v3)
  1205. #define GCPRO4(v1,v2,v3,v4) \
  1206.  debug_gcpro4 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,\
  1207.            &v1,&v2,&v3,&v4)
  1208. #define GCPRO5(v1,v2,v3,v4,v5) \
  1209.  debug_gcpro5 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,&gcpro5,\
  1210.            &v1,&v2,&v3,&v4,&v5)
  1211. #define UNGCPRO \
  1212.  debug_ungcpro(__FILE__, __LINE__,&gcpro1)
  1213.  
  1214. #else /* ! DEBUG_GCPRO */
  1215.  
  1216. #define GCPRO1(varname) \
  1217.  {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
  1218.   gcprolist = &gcpro1; }
  1219.  
  1220. #define GCPRO2(varname1, varname2) \
  1221.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  1222.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  1223.   gcprolist = &gcpro2; }
  1224.  
  1225. #define GCPRO3(varname1, varname2, varname3) \
  1226.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  1227.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  1228.   gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
  1229.   gcprolist = &gcpro3; }
  1230.  
  1231. #define GCPRO4(varname1, varname2, varname3, varname4) \
  1232.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  1233.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  1234.   gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
  1235.   gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
  1236.   gcprolist = &gcpro4; }
  1237.  
  1238. #define GCPRO5(varname1, varname2, varname3, varname4, varname5) \
  1239.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  1240.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  1241.   gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
  1242.   gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
  1243.   gcpro5.next = &gcpro4; gcpro5.var = &varname5; gcpro5.nvars = 1; \
  1244.   gcprolist = &gcpro5; }
  1245.  
  1246. #define UNGCPRO (gcprolist = gcpro1.next)
  1247.  
  1248. #endif /* ! DEBUG_GCPRO */
  1249.  
  1250. /* There was a special version here for the SunPro C compiler
  1251.    (i.e. without the do and while (0)), because that compiler
  1252.    reports bogus extra warnings here.  However, that special
  1253.    version is unsafe and could lead to all sorts of strange
  1254.    behavior.  I don't want to have to think about this kludge
  1255.    when coding, so you'll just have to live with those extra
  1256.    warnings. (Or tell the compiler writers to fix this!)
  1257.  */
  1258.  
  1259. /* Evaluate expr, UNGCPRO, and then return the value of expr.  */
  1260. #define RETURN_UNGCPRO(expr)         \
  1261.   do                     \
  1262.     {                     \
  1263.       Lisp_Object ret_ungc_val = (expr); \
  1264.       UNGCPRO;                 \
  1265.       return ret_ungc_val;         \
  1266.     }                     \
  1267.   while (0)
  1268.  
  1269. /* Call staticpro (&var) to protect static variable `var'. */
  1270. extern void staticpro (Lisp_Object *);
  1271.  
  1272. /* Nonzero means Emacs has already been initialized.
  1273.    Used during startup to detect startup of dumped Emacs.  */
  1274. extern int initialized;
  1275.  
  1276. #include "emacsfns.h"
  1277.  
  1278. #endif /* _XEMACS_LISP_H_ */
  1279.