(M21670): Unify GB, CNS and JIS.
[chise/xemacs-chise.git-] / info / internals.info-3
1 This is ../info/internals.info, produced by makeinfo version 4.0 from
2 internals/internals.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Internals: (internals).       XEmacs Internals Manual.
7 END-INFO-DIR-ENTRY
8
9    Copyright (C) 1992 - 1996 Ben Wing.  Copyright (C) 1996, 1997 Sun
10 Microsystems.  Copyright (C) 1994 - 1998 Free Software Foundation.
11 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
12
13    Permission is granted to make and distribute verbatim copies of this
14 manual provided the copyright notice and this permission notice are
15 preserved on all copies.
16
17    Permission is granted to copy and distribute modified versions of
18 this manual under the conditions for verbatim copying, provided that the
19 entire resulting derived work is distributed under the terms of a
20 permission notice identical to this one.
21
22    Permission is granted to copy and distribute translations of this
23 manual into another language, under the above conditions for modified
24 versions, except that this permission notice may be stated in a
25 translation approved by the Foundation.
26
27    Permission is granted to copy and distribute modified versions of
28 this manual under the conditions for verbatim copying, provided also
29 that the section entitled "GNU General Public License" is included
30 exactly as in the original, and provided that the entire resulting
31 derived work is distributed under the terms of a permission notice
32 identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that the section entitled "GNU General Public License"
37 may be included in a translation approved by the Free Software
38 Foundation instead of in the original English.
39
40 \1f
41 File: internals.info,  Node: Working With Character and Byte Positions,  Next: Conversion to and from External Data,  Prev: Character-Related Data Types,  Up: Coding for Mule
42
43 Working With Character and Byte Positions
44 -----------------------------------------
45
46    Now that we have defined the basic character-related types, we can
47 look at the macros and functions designed for work with them and for
48 conversion between them.  Most of these macros are defined in
49 `buffer.h', and we don't discuss all of them here, but only the most
50 important ones.  Examining the existing code is the best way to learn
51 about them.
52
53 `MAX_EMCHAR_LEN'
54      This preprocessor constant is the maximum number of buffer bytes
55      per Emacs character, i.e. the byte length of an `Emchar'.  It is
56      useful when allocating temporary strings to keep a known number of
57      characters.  For instance:
58
59           {
60             Charcount cclen;
61             ...
62             {
63               /* Allocate place for CCLEN characters. */
64               Bufbyte *buf = (Bufbyte *)alloca (cclen * MAX_EMCHAR_LEN);
65           ...
66
67      If you followed the previous section, you can guess that,
68      logically, multiplying a `Charcount' value with `MAX_EMCHAR_LEN'
69      produces a `Bytecount' value.
70
71      In the current Mule implementation, `MAX_EMCHAR_LEN' equals 4.
72      Without Mule, it is 1.
73
74 `charptr_emchar'
75 `set_charptr_emchar'
76      The `charptr_emchar' macro takes a `Bufbyte' pointer and returns
77      the `Emchar' stored at that position.  If it were a function, its
78      prototype would be:
79
80           Emchar charptr_emchar (Bufbyte *p);
81
82      `set_charptr_emchar' stores an `Emchar' to the specified byte
83      position.  It returns the number of bytes stored:
84
85           Bytecount set_charptr_emchar (Bufbyte *p, Emchar c);
86
87      It is important to note that `set_charptr_emchar' is safe only for
88      appending a character at the end of a buffer, not for overwriting a
89      character in the middle.  This is because the width of characters
90      varies, and `set_charptr_emchar' cannot resize the string if it
91      writes, say, a two-byte character where a single-byte character
92      used to reside.
93
94      A typical use of `set_charptr_emchar' can be demonstrated by this
95      example, which copies characters from buffer BUF to a temporary
96      string of Bufbytes.
97
98           {
99             Bufpos pos;
100             for (pos = beg; pos < end; pos++)
101               {
102                 Emchar c = BUF_FETCH_CHAR (buf, pos);
103                 p += set_charptr_emchar (buf, c);
104               }
105           }
106
107      Note how `set_charptr_emchar' is used to store the `Emchar' and
108      increment the counter, at the same time.
109
110 `INC_CHARPTR'
111 `DEC_CHARPTR'
112      These two macros increment and decrement a `Bufbyte' pointer,
113      respectively.  They will adjust the pointer by the appropriate
114      number of bytes according to the byte length of the character
115      stored there.  Both macros assume that the memory address is
116      located at the beginning of a valid character.
117
118      Without Mule support, `INC_CHARPTR (p)' and `DEC_CHARPTR (p)'
119      simply expand to `p++' and `p--', respectively.
120
121 `bytecount_to_charcount'
122      Given a pointer to a text string and a length in bytes, return the
123      equivalent length in characters.
124
125           Charcount bytecount_to_charcount (Bufbyte *p, Bytecount bc);
126
127 `charcount_to_bytecount'
128      Given a pointer to a text string and a length in characters,
129      return the equivalent length in bytes.
130
131           Bytecount charcount_to_bytecount (Bufbyte *p, Charcount cc);
132
133 `charptr_n_addr'
134      Return a pointer to the beginning of the character offset CC (in
135      characters) from P.
136
137           Bufbyte *charptr_n_addr (Bufbyte *p, Charcount cc);
138
139 \1f
140 File: internals.info,  Node: Conversion to and from External Data,  Next: General Guidelines for Writing Mule-Aware Code,  Prev: Working With Character and Byte Positions,  Up: Coding for Mule
141
142 Conversion to and from External Data
143 ------------------------------------
144
145    When an external function, such as a C library function, returns a
146 `char' pointer, you should almost never treat it as `Bufbyte'.  This is
147 because these returned strings may contain 8bit characters which can be
148 misinterpreted by XEmacs, and cause a crash.  Likewise, when exporting
149 a piece of internal text to the outside world, you should always
150 convert it to an appropriate external encoding, lest the internal stuff
151 (such as the infamous \201 characters) leak out.
152
153    The interface to conversion between the internal and external
154 representations of text are the numerous conversion macros defined in
155 `buffer.h'.  Before looking at them, we'll look at the external formats
156 supported by these macros.
157
158    Currently meaningful formats are `FORMAT_BINARY', `FORMAT_FILENAME',
159 `FORMAT_OS', and `FORMAT_CTEXT'.  Here is a description of these.
160
161 `FORMAT_BINARY'
162      Binary format.  This is the simplest format and is what we use in
163      the absence of a more appropriate format.  This converts according
164      to the `binary' coding system:
165
166        a. On input, bytes 0-255 are converted into characters 0-255.
167
168        b. On output, characters 0-255 are converted into bytes 0-255
169           and other characters are converted into `X'.
170
171 `FORMAT_FILENAME'
172      Format used for filenames.  In the original Mule, this is
173      user-definable with the `pathname-coding-system' variable.  For
174      the moment, we just use the `binary' coding system.
175
176 `FORMAT_OS'
177      Format used for the external Unix environment--`argv[]', stuff
178      from `getenv()', stuff from the `/etc/passwd' file, etc.
179
180      Perhaps should be the same as FORMAT_FILENAME.
181
182 `FORMAT_CTEXT'
183      Compound-text format.  This is the standard X format used for data
184      stored in properties, selections, and the like.  This is an 8-bit
185      no-lock-shift ISO2022 coding system.
186
187    The macros to convert between these formats and the internal format,
188 and vice versa, follow.
189
190 `GET_CHARPTR_INT_DATA_ALLOCA'
191 `GET_CHARPTR_EXT_DATA_ALLOCA'
192      These two are the most basic conversion macros.
193      `GET_CHARPTR_INT_DATA_ALLOCA' converts external data to internal
194      format, and `GET_CHARPTR_EXT_DATA_ALLOCA' converts the other way
195      around.  The arguments each of these receives are PTR (pointer to
196      the text in external format), LEN (length of texts in bytes), FMT
197      (format of the external text), PTR_OUT (lvalue to which new text
198      should be copied), and LEN_OUT (lvalue which will be assigned the
199      length of the internal text in bytes).  The resulting text is
200      stored to a stack-allocated buffer.  If the text doesn't need
201      changing, these macros will do nothing, except for setting LEN_OUT.
202
203      The macros above take many arguments which makes them unwieldy.
204      For this reason, a number of convenience macros are defined with
205      obvious functionality, but accepting less arguments.  The general
206      rule is that macros with `INT' in their name convert text to
207      internal Emacs representation, whereas the `EXT' macros convert to
208      external representation.
209
210 `GET_C_CHARPTR_INT_DATA_ALLOCA'
211 `GET_C_CHARPTR_EXT_DATA_ALLOCA'
212      As their names imply, these macros work on C char pointers, which
213      are zero-terminated, and thus do not need LEN or LEN_OUT
214      parameters.
215
216 `GET_STRING_EXT_DATA_ALLOCA'
217 `GET_C_STRING_EXT_DATA_ALLOCA'
218      These two macros convert a Lisp string into an external
219      representation.  The difference between them is that
220      `GET_STRING_EXT_DATA_ALLOCA' stores its output to a generic
221      string, providing LEN_OUT, the length of the resulting external
222      string.  On the other hand, `GET_C_STRING_EXT_DATA_ALLOCA' assumes
223      that the caller will be satisfied with output string being
224      zero-terminated.
225
226      Note that for Lisp strings only one conversion direction makes
227      sense.
228
229 `GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA'
230 `GET_CHARPTR_EXT_BINARY_DATA_ALLOCA'
231 `GET_STRING_BINARY_DATA_ALLOCA'
232 `GET_C_STRING_BINARY_DATA_ALLOCA'
233 `GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA'
234 `...'
235      These macros convert internal text to a specific external
236      representation, with the external format being encoded into the
237      name of the macro.  Note that the `GET_STRING_...' and
238      `GET_C_STRING...'  macros lack the `EXT' tag, because they only
239      make sense in that direction.
240
241 `GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA'
242 `GET_CHARPTR_INT_BINARY_DATA_ALLOCA'
243 `GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA'
244 `...'
245      These macros convert external text of a specific format to its
246      internal representation, with the external format being incoded
247      into the name of the macro.
248
249 \1f
250 File: internals.info,  Node: General Guidelines for Writing Mule-Aware Code,  Next: An Example of Mule-Aware Code,  Prev: Conversion to and from External Data,  Up: Coding for Mule
251
252 General Guidelines for Writing Mule-Aware Code
253 ----------------------------------------------
254
255    This section contains some general guidance on how to write
256 Mule-aware code, as well as some pitfalls you should avoid.
257
258 _Never use `char' and `char *'._
259      In XEmacs, the use of `char' and `char *' is almost always a
260      mistake.  If you want to manipulate an Emacs character from "C",
261      use `Emchar'.  If you want to examine a specific octet in the
262      internal format, use `Bufbyte'.  If you want a Lisp-visible
263      character, use a `Lisp_Object' and `make_char'.  If you want a
264      pointer to move through the internal text, use `Bufbyte *'.  Also
265      note that you almost certainly do not need `Emchar *'.
266
267 _Be careful not to confuse `Charcount', `Bytecount', and `Bufpos'._
268      The whole point of using different types is to avoid confusion
269      about the use of certain variables.  Lest this effect be
270      nullified, you need to be careful about using the right types.
271
272 _Always convert external data_
273      It is extremely important to always convert external data, because
274      XEmacs can crash if unexpected 8bit sequences are copied to its
275      internal buffers literally.
276
277      This means that when a system function, such as `readdir', returns
278      a string, you need to convert it using one of the conversion macros
279      described in the previous chapter, before passing it further to
280      Lisp.  In the case of `readdir', you would use the
281      `GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA' macro.
282
283      Also note that many internal functions, such as `make_string',
284      accept Bufbytes, which removes the need for them to convert the
285      data they receive.  This increases efficiency because that way
286      external data needs to be decoded only once, when it is read.
287      After that, it is passed around in internal format.
288
289 \1f
290 File: internals.info,  Node: An Example of Mule-Aware Code,  Prev: General Guidelines for Writing Mule-Aware Code,  Up: Coding for Mule
291
292 An Example of Mule-Aware Code
293 -----------------------------
294
295    As an example of Mule-aware code, we shall will analyze the `string'
296 function, which conses up a Lisp string from the character arguments it
297 receives.  Here is the definition, pasted from `alloc.c':
298
299      DEFUN ("string", Fstring, 0, MANY, 0, /*
300      Concatenate all the argument characters and make the result a string.
301      */
302             (int nargs, Lisp_Object *args))
303      {
304        Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN);
305        Bufbyte *p = storage;
306      
307        for (; nargs; nargs--, args++)
308          {
309            Lisp_Object lisp_char = *args;
310            CHECK_CHAR_COERCE_INT (lisp_char);
311            p += set_charptr_emchar (p, XCHAR (lisp_char));
312          }
313        return make_string (storage, p - storage);
314      }
315
316    Now we can analyze the source line by line.
317
318    Obviously, string will be as long as there are arguments to the
319 function.  This is why we allocate `MAX_EMCHAR_LEN' * NARGS bytes on
320 the stack, i.e. the worst-case number of bytes for NARGS `Emchar's to
321 fit in the string.
322
323    Then, the loop checks that each element is a character, converting
324 integers in the process.  Like many other functions in XEmacs, this
325 function silently accepts integers where characters are expected, for
326 historical and compatibility reasons.  Unless you know what you are
327 doing, `CHECK_CHAR' will also suffice.  `XCHAR (lisp_char)' extracts
328 the `Emchar' from the `Lisp_Object', and `set_charptr_emchar' stores it
329 to storage, increasing `p' in the process.
330
331    Other instructive examples of correct coding under Mule can be found
332 all over the XEmacs code.  For starters, I recommend
333 `Fnormalize_menu_item_name' in `menubar.c'.  After you have understood
334 this section of the manual and studied the examples, you can proceed
335 writing new Mule-aware code.
336
337 \1f
338 File: internals.info,  Node: Techniques for XEmacs Developers,  Prev: Coding for Mule,  Up: Rules When Writing New C Code
339
340 Techniques for XEmacs Developers
341 ================================
342
343    To make a quantified XEmacs, do: `make quantmacs'.
344
345    You simply can't dump Quantified and Purified images.  Run the image
346 like so:  `quantmacs -batch -l loadup.el run-temacs XEMACS-ARGS...'.
347
348    Before you go through the trouble, are you compiling with all
349 debugging and error-checking off?  If not try that first.  Be warned
350 that while Quantify is directly responsible for quite a few
351 optimizations which have been made to XEmacs, doing a run which
352 generates results which can be acted upon is not necessarily a trivial
353 task.
354
355    Also, if you're still willing to do some runs make sure you configure
356 with the `--quantify' flag.  That will keep Quantify from starting to
357 record data until after the loadup is completed and will shut off
358 recording right before it shuts down (which generates enough bogus data
359 to throw most results off).  It also enables three additional elisp
360 commands: `quantify-start-recording-data',
361 `quantify-stop-recording-data' and `quantify-clear-data'.
362
363    If you want to make XEmacs faster, target your favorite slow
364 benchmark, run a profiler like Quantify, `gprof', or `tcov', and figure
365 out where the cycles are going.  Specific projects:
366
367    * Make the garbage collector faster.  Figure out how to write an
368      incremental garbage collector.
369
370    * Write a compiler that takes bytecode and spits out C code.
371      Unfortunately, you will then need a C compiler and a more fully
372      developed module system.
373
374    * Speed up redisplay.
375
376    * Speed up syntax highlighting.  Maybe moving some of the syntax
377      highlighting capabilities into C would make a difference.
378
379    * Implement tail recursion in Emacs Lisp (hard!).
380
381    Unfortunately, Emacs Lisp is slow, and is going to stay slow.
382 Function calls in elisp are especially expensive.  Iterating over a
383 long list is going to be 30 times faster implemented in C than in Elisp.
384
385    To get started debugging XEmacs, take a look at the `.gdbinit' and
386 `.dbxrc' files in the `src' directory.  *Note Q2.1.15 - How to Debug an
387 XEmacs problem with a debugger: (xemacs-faq)Q2.1.15 - How to Debug an
388 XEmacs problem with a debugger.
389
390    After making source code changes, run `make check' to ensure that
391 you haven't introduced any regressions.  If you're feeling ambitious,
392 you can try to improve the test suite in `tests/automated'.
393
394    Here are things to know when you create a new source file:
395
396    * All `.c' files should `#include <config.h>' first.  Almost all
397      `.c' files should `#include "lisp.h"' second.
398
399    * Generated header files should be included using the `#include
400      <...>' syntax, not the `#include "..."' syntax.  The generated
401      headers are:
402
403      `config.h puresize-adjust.h sheap-adjust.h paths.h Emacs.ad.h'
404
405      The basic rule is that you should assume builds using `--srcdir'
406      and the `#include <...>' syntax needs to be used when the
407      to-be-included generated file is in a potentially different
408      directory _at compile time_.  The non-obvious C rule is that
409      `#include "..."' means to search for the included file in the same
410      directory as the including file, _not_ in the current directory.
411
412    * Header files should _not_ include `<config.h>' and `"lisp.h"'.  It
413      is the responsibility of the `.c' files that use it to do so.
414
415    * If the header uses `INLINE', either directly or through
416      `DECLARE_LRECORD', then it must be added to `inline.c''s includes.
417
418    * Try compiling at least once with
419
420           gcc --with-mule --with-union-type --error-checking=all
421
422    * Did I mention that you should run the test suite?
423           make check
424
425 \1f
426 File: internals.info,  Node: A Summary of the Various XEmacs Modules,  Next: Allocation of Objects in XEmacs Lisp,  Prev: Rules When Writing New C Code,  Up: Top
427
428 A Summary of the Various XEmacs Modules
429 ***************************************
430
431    This is accurate as of XEmacs 20.0.
432
433 * Menu:
434
435 * Low-Level Modules::
436 * Basic Lisp Modules::
437 * Modules for Standard Editing Operations::
438 * Editor-Level Control Flow Modules::
439 * Modules for the Basic Displayable Lisp Objects::
440 * Modules for other Display-Related Lisp Objects::
441 * Modules for the Redisplay Mechanism::
442 * Modules for Interfacing with the File System::
443 * Modules for Other Aspects of the Lisp Interpreter and Object System::
444 * Modules for Interfacing with the Operating System::
445 * Modules for Interfacing with X Windows::
446 * Modules for Internationalization::
447
448 \1f
449 File: internals.info,  Node: Low-Level Modules,  Next: Basic Lisp Modules,  Up: A Summary of the Various XEmacs Modules
450
451 Low-Level Modules
452 =================
453
454      config.h
455
456    This is automatically generated from `config.h.in' based on the
457 results of configure tests and user-selected optional features and
458 contains preprocessor definitions specifying the nature of the
459 environment in which XEmacs is being compiled.
460
461      paths.h
462
463    This is automatically generated from `paths.h.in' based on supplied
464 configure values, and allows for non-standard installed configurations
465 of the XEmacs directories.  It's currently broken, though.
466
467      emacs.c
468      signal.c
469
470    `emacs.c' contains `main()' and other code that performs the most
471 basic environment initializations and handles shutting down the XEmacs
472 process (this includes `kill-emacs', the normal way that XEmacs is
473 exited; `dump-emacs', which is used during the build process to write
474 out the XEmacs executable; `run-emacs-from-temacs', which can be used
475 to start XEmacs directly when temacs has finished loading all the Lisp
476 code; and emergency code to handle crashes [XEmacs tries to auto-save
477 all files before it crashes]).
478
479    Low-level code that directly interacts with the Unix signal
480 mechanism, however, is in `signal.c'.  Note that this code does not
481 handle system dependencies in interfacing to signals; that is handled
482 using the `syssignal.h' header file, described in section J below.
483
484      unexaix.c
485      unexalpha.c
486      unexapollo.c
487      unexconvex.c
488      unexec.c
489      unexelf.c
490      unexelfsgi.c
491      unexencap.c
492      unexenix.c
493      unexfreebsd.c
494      unexfx2800.c
495      unexhp9k3.c
496      unexhp9k800.c
497      unexmips.c
498      unexnext.c
499      unexsol2.c
500      unexsunos4.c
501
502    These modules contain code dumping out the XEmacs executable on
503 various different systems. (This process is highly machine-specific and
504 requires intimate knowledge of the executable format and the memory map
505 of the process.) Only one of these modules is actually used; this is
506 chosen by `configure'.
507
508      crt0.c
509      lastfile.c
510      pre-crt0.c
511
512    These modules are used in conjunction with the dump mechanism.  On
513 some systems, an alternative version of the C startup code (the actual
514 code that receives control from the operating system when the process is
515 started, and which calls `main()') is required so that the dumping
516 process works properly; `crt0.c' provides this.
517
518    `pre-crt0.c' and `lastfile.c' should be the very first and very last
519 file linked, respectively. (Actually, this is not really true.
520 `lastfile.c' should be after all Emacs modules whose initialized data
521 should be made constant, and before all other Emacs files and all
522 libraries.  In particular, the allocation modules `gmalloc.c',
523 `alloca.c', etc. are normally placed past `lastfile.c', and all of the
524 files that implement Xt widget classes _must_ be placed after
525 `lastfile.c' because they contain various structures that must be
526 statically initialized and into which Xt writes at various times.)
527 `pre-crt0.c' and `lastfile.c' contain exported symbols that are used to
528 determine the start and end of XEmacs' initialized data space when
529 dumping.
530
531      alloca.c
532      free-hook.c
533      getpagesize.h
534      gmalloc.c
535      malloc.c
536      mem-limits.h
537      ralloc.c
538      vm-limit.c
539
540    These handle basic C allocation of memory.  `alloca.c' is an
541 emulation of the stack allocation function `alloca()' on machines that
542 lack this. (XEmacs makes extensive use of `alloca()' in its code.)
543
544    `gmalloc.c' and `malloc.c' are two implementations of the standard C
545 functions `malloc()', `realloc()' and `free()'.  They are often used in
546 place of the standard system-provided `malloc()' because they usually
547 provide a much faster implementation, at the expense of additional
548 memory use.  `gmalloc.c' is a newer implementation that is much more
549 memory-efficient for large allocations than `malloc.c', and should
550 always be preferred if it works. (At one point, `gmalloc.c' didn't work
551 on some systems where `malloc.c' worked; but this should be fixed now.)
552
553    `ralloc.c' is the "relocating allocator".  It provides functions
554 similar to `malloc()', `realloc()' and `free()' that allocate memory
555 that can be dynamically relocated in memory.  The advantage of this is
556 that allocated memory can be shuffled around to place all the free
557 memory at the end of the heap, and the heap can then be shrunk,
558 releasing the memory back to the operating system.  The use of this can
559 be controlled with the configure option `--rel-alloc'; if enabled,
560 memory allocated for buffers will be relocatable, so that if a very
561 large file is visited and the buffer is later killed, the memory can be
562 released to the operating system.  (The disadvantage of this mechanism
563 is that it can be very slow.  On systems with the `mmap()' system call,
564 the XEmacs version of `ralloc.c' uses this to move memory around
565 without actually having to block-copy it, which can speed things up;
566 but it can still cause noticeable performance degradation.)
567
568    `free-hook.c' contains some debugging functions for checking for
569 invalid arguments to `free()'.
570
571    `vm-limit.c' contains some functions that warn the user when memory
572 is getting low.  These are callback functions that are called by
573 `gmalloc.c' and `malloc.c' at appropriate times.
574
575    `getpagesize.h' provides a uniform interface for retrieving the size
576 of a page in virtual memory.  `mem-limits.h' provides a uniform
577 interface for retrieving the total amount of available virtual memory.
578 Both are similar in spirit to the `sys*.h' files described in section
579 J, below.
580
581      blocktype.c
582      blocktype.h
583      dynarr.c
584
585    These implement a couple of basic C data types to facilitate memory
586 allocation.  The `Blocktype' type efficiently manages the allocation of
587 fixed-size blocks by minimizing the number of times that `malloc()' and
588 `free()' are called.  It allocates memory in large chunks, subdivides
589 the chunks into blocks of the proper size, and returns the blocks as
590 requested.  When blocks are freed, they are placed onto a linked list,
591 so they can be efficiently reused.  This data type is not much used in
592 XEmacs currently, because it's a fairly new addition.
593
594    The `Dynarr' type implements a "dynamic array", which is similar to
595 a standard C array but has no fixed limit on the number of elements it
596 can contain.  Dynamic arrays can hold elements of any type, and when
597 you add a new element, the array automatically resizes itself if it
598 isn't big enough.  Dynarrs are extensively used in the redisplay
599 mechanism.
600
601      inline.c
602
603    This module is used in connection with inline functions (available in
604 some compilers).  Often, inline functions need to have a corresponding
605 non-inline function that does the same thing.  This module is where they
606 reside.  It contains no actual code, but defines some special flags that
607 cause inline functions defined in header files to be rendered as actual
608 functions.  It then includes all header files that contain any inline
609 function definitions, so that each one gets a real function equivalent.
610
611      debug.c
612      debug.h
613
614    These functions provide a system for doing internal consistency
615 checks during code development.  This system is not currently used;
616 instead the simpler `assert()' macro is used along with the various
617 checks provided by the `--error-check-*' configuration options.
618
619      prefix-args.c
620
621    This is actually the source for a small, self-contained program used
622 during building.
623
624      universe.h
625
626    This is not currently used.
627
628 \1f
629 File: internals.info,  Node: Basic Lisp Modules,  Next: Modules for Standard Editing Operations,  Prev: Low-Level Modules,  Up: A Summary of the Various XEmacs Modules
630
631 Basic Lisp Modules
632 ==================
633
634      emacsfns.h
635      lisp-disunion.h
636      lisp-union.h
637      lisp.h
638      lrecord.h
639      symsinit.h
640
641    These are the basic header files for all XEmacs modules.  Each module
642 includes `lisp.h', which brings the other header files in.  `lisp.h'
643 contains the definitions of the structures and extractor and
644 constructor macros for the basic Lisp objects and various other basic
645 definitions for the Lisp environment, as well as some general-purpose
646 definitions (e.g. `min()' and `max()').  `lisp.h' includes either
647 `lisp-disunion.h' or `lisp-union.h', depending on whether
648 `USE_UNION_TYPE' is defined.  These files define the typedef of the
649 Lisp object itself (as described above) and the low-level macros that
650 hide the actual implementation of the Lisp object.  All extractor and
651 constructor macros for particular types of Lisp objects are defined in
652 terms of these low-level macros.
653
654    As a general rule, all typedefs should go into the typedefs section
655 of `lisp.h' rather than into a module-specific header file even if the
656 structure is defined elsewhere.  This allows function prototypes that
657 use the typedef to be placed into other header files.  Forward structure
658 declarations (i.e. a simple declaration like `struct foo;' where the
659 structure itself is defined elsewhere) should be placed into the
660 typedefs section as necessary.
661
662    `lrecord.h' contains the basic structures and macros that implement
663 all record-type Lisp objects - i.e. all objects whose type is a field
664 in their C structure, which includes all objects except the few most
665 basic ones.
666
667    `lisp.h' contains prototypes for most of the exported functions in
668 the various modules.  Lisp primitives defined using `DEFUN' that need
669 to be called by C code should be declared using `EXFUN'.  Other
670 function prototypes should be placed either into the appropriate
671 section of `lisp.h', or into a module-specific header file, depending
672 on how general-purpose the function is and whether it has
673 special-purpose argument types requiring definitions not in `lisp.h'.)
674 All initialization functions are prototyped in `symsinit.h'.
675
676      alloc.c
677      pure.c
678      puresize.h
679
680    The large module `alloc.c' implements all of the basic allocation and
681 garbage collection for Lisp objects.  The most commonly used Lisp
682 objects are allocated in chunks, similar to the Blocktype data type
683 described above; others are allocated in individually `malloc()'ed
684 blocks.  This module provides the foundation on which all other aspects
685 of the Lisp environment sit, and is the first module initialized at
686 startup.
687
688    Note that `alloc.c' provides a series of generic functions that are
689 not dependent on any particular object type, and interfaces to
690 particular types of objects using a standardized interface of
691 type-specific methods.  This scheme is a fundamental principle of
692 object-oriented programming and is heavily used throughout XEmacs.  The
693 great advantage of this is that it allows for a clean separation of
694 functionality into different modules - new classes of Lisp objects, new
695 event interfaces, new device types, new stream interfaces, etc. can be
696 added transparently without affecting code anywhere else in XEmacs.
697 Because the different subsystems are divided into general and specific
698 code, adding a new subtype within a subsystem will in general not
699 require changes to the generic subsystem code or affect any of the other
700 subtypes in the subsystem; this provides a great deal of robustness to
701 the XEmacs code.
702
703    `pure.c' contains the declaration of the "purespace" array.  Pure
704 space is a hack used to place some constant Lisp data into the code
705 segment of the XEmacs executable, even though the data needs to be
706 initialized through function calls.  (See above in section VIII for more
707 info about this.)  During startup, certain sorts of data is
708 automatically copied into pure space, and other data is copied manually
709 in some of the basic Lisp files by calling the function `purecopy',
710 which copies the object if possible (this only works in temacs, of
711 course) and returns the new object.  In particular, while temacs is
712 executing, the Lisp reader automatically copies all compiled-function
713 objects that it reads into pure space.  Since compiled-function objects
714 are large, are never modified, and typically comprise the majority of
715 the contents of a compiled-Lisp file, this works well.  While XEmacs is
716 running, any attempt to modify an object that resides in pure space
717 causes an error.  Objects in pure space are never garbage collected -
718 almost all of the time, they're intended to be permanent, and in any
719 case you can't write into pure space to set the mark bits.
720
721    `puresize.h' contains the declaration of the size of the pure space
722 array.  This depends on the optional features that are compiled in, any
723 extra purespace requested by the user at compile time, and certain other
724 factors (e.g. 64-bit machines need more pure space because their Lisp
725 objects are larger).  The smallest size that suffices should be used, so
726 that there's no wasted space.  If there's not enough pure space, you
727 will get an error during the build process, specifying how much more
728 pure space is needed.
729
730      eval.c
731      backtrace.h
732
733    This module contains all of the functions to handle the flow of
734 control.  This includes the mechanisms of defining functions, calling
735 functions, traversing stack frames, and binding variables; the control
736 primitives and other special forms such as `while', `if', `eval',
737 `let', `and', `or', `progn', etc.; handling of non-local exits,
738 unwind-protects, and exception handlers; entering the debugger; methods
739 for the subr Lisp object type; etc.  It does _not_ include the `read'
740 function, the `print' function, or the handling of symbols and obarrays.
741
742    `backtrace.h' contains some structures related to stack frames and
743 the flow of control.
744
745      lread.c
746
747    This module implements the Lisp reader and the `read' function,
748 which converts text into Lisp objects, according to the read syntax of
749 the objects, as described above.  This is similar to the parser that is
750 a part of all compilers.
751
752      print.c
753
754    This module implements the Lisp print mechanism and the `print'
755 function and related functions.  This is the inverse of the Lisp reader
756 - it converts Lisp objects to a printed, textual representation.
757 (Hopefully something that can be read back in using `read' to get an
758 equivalent object.)
759
760      general.c
761      symbols.c
762      symeval.h
763
764    `symbols.c' implements the handling of symbols, obarrays, and
765 retrieving the values of symbols.  Much of the code is devoted to
766 handling the special "symbol-value-magic" objects that define special
767 types of variables - this includes buffer-local variables, variable
768 aliases, variables that forward into C variables, etc.  This module is
769 initialized extremely early (right after `alloc.c'), because it is here
770 that the basic symbols `t' and `nil' are created, and those symbols are
771 used everywhere throughout XEmacs.
772
773    `symeval.h' contains the definitions of symbol structures and the
774 `DEFVAR_LISP()' and related macros for declaring variables.
775
776      data.c
777      floatfns.c
778      fns.c
779
780    These modules implement the methods and standard Lisp primitives for
781 all the basic Lisp object types other than symbols (which are described
782 above).  `data.c' contains all the predicates (primitives that return
783 whether an object is of a particular type); the integer arithmetic
784 functions; and the basic accessor and mutator primitives for the various
785 object types.  `fns.c' contains all the standard predicates for working
786 with sequences (where, abstractly speaking, a sequence is an ordered set
787 of objects, and can be represented by a list, string, vector, or
788 bit-vector); it also contains `equal', perhaps on the grounds that bulk
789 of the operation of `equal' is comparing sequences.  `floatfns.c'
790 contains methods and primitives for floats and floating-point
791 arithmetic.
792
793      bytecode.c
794      bytecode.h
795
796    `bytecode.c' implements the byte-code interpreter and
797 compiled-function objects, and `bytecode.h' contains associated
798 structures.  Note that the byte-code _compiler_ is written in Lisp.
799
800 \1f
801 File: internals.info,  Node: Modules for Standard Editing Operations,  Next: Editor-Level Control Flow Modules,  Prev: Basic Lisp Modules,  Up: A Summary of the Various XEmacs Modules
802
803 Modules for Standard Editing Operations
804 =======================================
805
806      buffer.c
807      buffer.h
808      bufslots.h
809
810    `buffer.c' implements the "buffer" Lisp object type.  This includes
811 functions that create and destroy buffers; retrieve buffers by name or
812 by other properties; manipulate lists of buffers (remember that buffers
813 are permanent objects and stored in various ordered lists); retrieve or
814 change buffer properties; etc.  It also contains the definitions of all
815 the built-in buffer-local variables (which can be viewed as buffer
816 properties).  It does _not_ contain code to manipulate buffer-local
817 variables (that's in `symbols.c', described above); or code to
818 manipulate the text in a buffer.
819
820    `buffer.h' defines the structures associated with a buffer and the
821 various macros for retrieving text from a buffer and special buffer
822 positions (e.g. `point', the default location for text insertion).  It
823 also contains macros for working with buffer positions and converting
824 between their representations as character offsets and as byte offsets
825 (under MULE, they are different, because characters can be multi-byte).
826 It is one of the largest header files.
827
828    `bufslots.h' defines the fields in the buffer structure that
829 correspond to the built-in buffer-local variables.  It is its own
830 header file because it is included many times in `buffer.c', as a way
831 of iterating over all the built-in buffer-local variables.
832
833      insdel.c
834      insdel.h
835
836    `insdel.c' contains low-level functions for inserting and deleting
837 text in a buffer, keeping track of changed regions for use by
838 redisplay, and calling any before-change and after-change functions
839 that may have been registered for the buffer.  It also contains the
840 actual functions that convert between byte offsets and character
841 offsets.
842
843    `insdel.h' contains associated headers.
844
845      marker.c
846
847    This module implements the "marker" Lisp object type, which
848 conceptually is a pointer to a text position in a buffer that moves
849 around as text is inserted and deleted, so as to remain in the same
850 relative position.  This module doesn't actually move the markers around
851 - that's handled in `insdel.c'.  This module just creates them and
852 implements the primitives for working with them.  As markers are simple
853 objects, this does not entail much.
854
855    Note that the standard arithmetic primitives (e.g. `+') accept
856 markers in place of integers and automatically substitute the value of
857 `marker-position' for the marker, i.e. an integer describing the
858 current buffer position of the marker.
859
860      extents.c
861      extents.h
862
863    This module implements the "extent" Lisp object type, which is like
864 a marker that works over a range of text rather than a single position.
865 Extents are also much more complex and powerful than markers and have a
866 more efficient (and more algorithmically complex) implementation.  The
867 implementation is described in detail in comments in `extents.c'.
868
869    The code in `extents.c' works closely with `insdel.c' so that
870 extents are properly moved around as text is inserted and deleted.
871 There is also code in `extents.c' that provides information needed by
872 the redisplay mechanism for efficient operation. (Remember that extents
873 can have display properties that affect [sometimes drastically, as in
874 the `invisible' property] the display of the text they cover.)
875
876      editfns.c
877
878    `editfns.c' contains the standard Lisp primitives for working with a
879 buffer's text, and calls the low-level functions in `insdel.c'.  It
880 also contains primitives for working with `point' (the default buffer
881 insertion location).
882
883    `editfns.c' also contains functions for retrieving various
884 characteristics from the external environment: the current time, the
885 process ID of the running XEmacs process, the name of the user who ran
886 this XEmacs process, etc.  It's not clear why this code is in
887 `editfns.c'.
888
889      callint.c
890      cmds.c
891      commands.h
892
893    These modules implement the basic "interactive" commands, i.e.
894 user-callable functions.  Commands, as opposed to other functions, have
895 special ways of getting their parameters interactively (by querying the
896 user), as opposed to having them passed in a normal function
897 invocation.  Many commands are not really meant to be called from other
898 Lisp functions, because they modify global state in a way that's often
899 undesired as part of other Lisp functions.
900
901    `callint.c' implements the mechanism for querying the user for
902 parameters and calling interactive commands.  The bulk of this module is
903 code that parses the interactive spec that is supplied with an
904 interactive command.
905
906    `cmds.c' implements the basic, most commonly used editing commands:
907 commands to move around the current buffer and insert and delete
908 characters.  These commands are implemented using the Lisp primitives
909 defined in `editfns.c'.
910
911    `commands.h' contains associated structure definitions and
912 prototypes.
913
914      regex.c
915      regex.h
916      search.c
917
918    `search.c' implements the Lisp primitives for searching for text in
919 a buffer, and some of the low-level algorithms for doing this.  In
920 particular, the fast fixed-string Boyer-Moore search algorithm is
921 implemented in `search.c'.  The low-level algorithms for doing
922 regular-expression searching, however, are implemented in `regex.c' and
923 `regex.h'.  These two modules are largely independent of XEmacs, and
924 are similar to (and based upon) the regular-expression routines used in
925 `grep' and other GNU utilities.
926
927      doprnt.c
928
929    `doprnt.c' implements formatted-string processing, similar to
930 `printf()' command in C.
931
932      undo.c
933
934    This module implements the undo mechanism for tracking buffer
935 changes.  Most of this could be implemented in Lisp.
936
937 \1f
938 File: internals.info,  Node: Editor-Level Control Flow Modules,  Next: Modules for the Basic Displayable Lisp Objects,  Prev: Modules for Standard Editing Operations,  Up: A Summary of the Various XEmacs Modules
939
940 Editor-Level Control Flow Modules
941 =================================
942
943      event-Xt.c
944      event-stream.c
945      event-tty.c
946      events.c
947      events.h
948
949    These implement the handling of events (user input and other system
950 notifications).
951
952    `events.c' and `events.h' define the "event" Lisp object type and
953 primitives for manipulating it.
954
955    `event-stream.c' implements the basic functions for working with
956 event queues, dispatching an event by looking it up in relevant keymaps
957 and such, and handling timeouts; this includes the primitives
958 `next-event' and `dispatch-event', as well as related primitives such
959 as `sit-for', `sleep-for', and `accept-process-output'.
960 (`event-stream.c' is one of the hairiest and trickiest modules in
961 XEmacs.  Beware!  You can easily mess things up here.)
962
963    `event-Xt.c' and `event-tty.c' implement the low-level interfaces
964 onto retrieving events from Xt (the X toolkit) and from TTY's (using
965 `read()' and `select()'), respectively.  The event interface enforces a
966 clean separation between the specific code for interfacing with the
967 operating system and the generic code for working with events, by
968 defining an API of basic, low-level event methods; `event-Xt.c' and
969 `event-tty.c' are two different implementations of this API.  To add
970 support for a new operating system (e.g. NeXTstep), one merely needs to
971 provide another implementation of those API functions.
972
973    Note that the choice of whether to use `event-Xt.c' or `event-tty.c'
974 is made at compile time!  Or at the very latest, it is made at startup
975 time.  `event-Xt.c' handles events for _both_ X and TTY frames;
976 `event-tty.c' is only used when X support is not compiled into XEmacs.
977 The reason for this is that there is only one event loop in XEmacs:
978 thus, it needs to be able to receive events from all different kinds of
979 frames.
980
981      keymap.c
982      keymap.h
983
984    `keymap.c' and `keymap.h' define the "keymap" Lisp object type and
985 associated methods and primitives. (Remember that keymaps are objects
986 that associate event descriptions with functions to be called to
987 "execute" those events; `dispatch-event' looks up events in the
988 relevant keymaps.)
989
990      keyboard.c
991
992    `keyboard.c' contains functions that implement the actual editor
993 command loop - i.e. the event loop that cyclically retrieves and
994 dispatches events.  This code is also rather tricky, just like
995 `event-stream.c'.
996
997      macros.c
998      macros.h
999
1000    These two modules contain the basic code for defining keyboard
1001 macros.  These functions don't actually do much; most of the code that
1002 handles keyboard macros is mixed in with the event-handling code in
1003 `event-stream.c'.
1004
1005      minibuf.c
1006
1007    This contains some miscellaneous code related to the minibuffer
1008 (most of the minibuffer code was moved into Lisp by Richard Mlynarik).
1009 This includes the primitives for completion (although filename
1010 completion is in `dired.c'), the lowest-level interface to the
1011 minibuffer (if the command loop were cleaned up, this too could be in
1012 Lisp), and code for dealing with the echo area (this, too, was mostly
1013 moved into Lisp, and the only code remaining is code to call out to
1014 Lisp or provide simple bootstrapping implementations early in temacs,
1015 before the echo-area Lisp code is loaded).
1016
1017 \1f
1018 File: internals.info,  Node: Modules for the Basic Displayable Lisp Objects,  Next: Modules for other Display-Related Lisp Objects,  Prev: Editor-Level Control Flow Modules,  Up: A Summary of the Various XEmacs Modules
1019
1020 Modules for the Basic Displayable Lisp Objects
1021 ==============================================
1022
1023      device-ns.h
1024      device-stream.c
1025      device-stream.h
1026      device-tty.c
1027      device-tty.h
1028      device-x.c
1029      device-x.h
1030      device.c
1031      device.h
1032
1033    These modules implement the "device" Lisp object type.  This
1034 abstracts a particular screen or connection on which frames are
1035 displayed.  As with Lisp objects, event interfaces, and other
1036 subsystems, the device code is separated into a generic component that
1037 contains a standardized interface (in the form of a set of methods) onto
1038 particular device types.
1039
1040    The device subsystem defines all the methods and provides method
1041 services for not only device operations but also for the frame, window,
1042 menubar, scrollbar, toolbar, and other displayable-object subsystems.
1043 The reason for this is that all of these subsystems have the same
1044 subtypes (X, TTY, NeXTstep, Microsoft Windows, etc.) as devices do.
1045
1046      frame-ns.h
1047      frame-tty.c
1048      frame-x.c
1049      frame-x.h
1050      frame.c
1051      frame.h
1052
1053    Each device contains one or more frames in which objects (e.g. text)
1054 are displayed.  A frame corresponds to a window in the window system;
1055 usually this is a top-level window but it could potentially be one of a
1056 number of overlapping child windows within a top-level window, using the
1057 MDI (Multiple Document Interface) protocol in Microsoft Windows or a
1058 similar scheme.
1059
1060    The `frame-*' files implement the "frame" Lisp object type and
1061 provide the generic and device-type-specific operations on frames (e.g.
1062 raising, lowering, resizing, moving, etc.).
1063
1064      window.c
1065      window.h
1066
1067    Each frame consists of one or more non-overlapping "windows" (better
1068 known as "panes" in standard window-system terminology) in which a
1069 buffer's text can be displayed.  Windows can also have scrollbars
1070 displayed around their edges.
1071
1072    `window.c' and `window.h' implement the "window" Lisp object type
1073 and provide code to manage windows.  Since windows have no associated
1074 resources in the window system (the window system knows only about the
1075 frame; no child windows or anything are used for XEmacs windows), there
1076 is no device-type-specific code here; all of that code is part of the
1077 redisplay mechanism or the code for particular object types such as
1078 scrollbars.
1079
1080 \1f
1081 File: internals.info,  Node: Modules for other Display-Related Lisp Objects,  Next: Modules for the Redisplay Mechanism,  Prev: Modules for the Basic Displayable Lisp Objects,  Up: A Summary of the Various XEmacs Modules
1082
1083 Modules for other Display-Related Lisp Objects
1084 ==============================================
1085
1086      faces.c
1087      faces.h
1088
1089      bitmaps.h
1090      glyphs-ns.h
1091      glyphs-x.c
1092      glyphs-x.h
1093      glyphs.c
1094      glyphs.h
1095
1096      objects-ns.h
1097      objects-tty.c
1098      objects-tty.h
1099      objects-x.c
1100      objects-x.h
1101      objects.c
1102      objects.h
1103
1104      menubar-x.c
1105      menubar.c
1106
1107      scrollbar-x.c
1108      scrollbar-x.h
1109      scrollbar.c
1110      scrollbar.h
1111
1112      toolbar-x.c
1113      toolbar.c
1114      toolbar.h
1115
1116      font-lock.c
1117
1118    This file provides C support for syntax highlighting - i.e.
1119 highlighting different syntactic constructs of a source file in
1120 different colors, for easy reading.  The C support is provided so that
1121 this is fast.
1122
1123      dgif_lib.c
1124      gif_err.c
1125      gif_lib.h
1126      gifalloc.c
1127
1128    These modules decode GIF-format image files, for use with glyphs.
1129
1130 \1f
1131 File: internals.info,  Node: Modules for the Redisplay Mechanism,  Next: Modules for Interfacing with the File System,  Prev: Modules for other Display-Related Lisp Objects,  Up: A Summary of the Various XEmacs Modules
1132
1133 Modules for the Redisplay Mechanism
1134 ===================================
1135
1136      redisplay-output.c
1137      redisplay-tty.c
1138      redisplay-x.c
1139      redisplay.c
1140      redisplay.h
1141
1142    These files provide the redisplay mechanism.  As with many other
1143 subsystems in XEmacs, there is a clean separation between the general
1144 and device-specific support.
1145
1146    `redisplay.c' contains the bulk of the redisplay engine.  These
1147 functions update the redisplay structures (which describe how the screen
1148 is to appear) to reflect any changes made to the state of any
1149 displayable objects (buffer, frame, window, etc.) since the last time
1150 that redisplay was called.  These functions are highly optimized to
1151 avoid doing more work than necessary (since redisplay is called
1152 extremely often and is potentially a huge time sink), and depend heavily
1153 on notifications from the objects themselves that changes have occurred,
1154 so that redisplay doesn't explicitly have to check each possible object.
1155 The redisplay mechanism also contains a great deal of caching to further
1156 speed things up; some of this caching is contained within the various
1157 displayable objects.
1158
1159    `redisplay-output.c' goes through the redisplay structures and
1160 converts them into calls to device-specific methods to actually output
1161 the screen changes.
1162
1163    `redisplay-x.c' and `redisplay-tty.c' are two implementations of
1164 these redisplay output methods, for X frames and TTY frames,
1165 respectively.
1166
1167      indent.c
1168
1169    This module contains various functions and Lisp primitives for
1170 converting between buffer positions and screen positions.  These
1171 functions call the redisplay mechanism to do most of the work, and then
1172 examine the redisplay structures to get the necessary information.  This
1173 module needs work.
1174
1175      termcap.c
1176      terminfo.c
1177      tparam.c
1178
1179    These files contain functions for working with the termcap
1180 (BSD-style) and terminfo (System V style) databases of terminal
1181 capabilities and escape sequences, used when XEmacs is displaying in a
1182 TTY.
1183
1184      cm.c
1185      cm.h
1186
1187    These files provide some miscellaneous TTY-output functions and
1188 should probably be merged into `redisplay-tty.c'.
1189