annotate src/buffer.h @ 446:1ccc32a20af4 r21-2-38

Import from CVS: tag r21-2-38
author cvs
date Mon, 13 Aug 2007 11:37:21 +0200
parents 576fb035e263
children 3078fd1074e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Header file for the buffer manipulation primitives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Authorship:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 FSF: long ago.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 JWZ: separated out bufslots.h, early in Lemacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 Ben Wing: almost completely rewritten for Mule, 19.12.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
32 #ifndef INCLUDED_buffer_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
33 #define INCLUDED_buffer_h_
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "mule-charset.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
39 #include "casetab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
40 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
41
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 /* definition of Lisp buffer object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 /* Note: we keep both Bytind and Bufpos versions of some of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 important buffer positions because they are accessed so much.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 If we didn't do this, we would constantly be invalidating the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 bufpos<->bytind cache under Mule.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 Note that under non-Mule, both versions will always be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 same so we don't really need to keep track of them. But it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 simplifies the logic to go ahead and do so all the time and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 the memory loss is insignificant. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 /* Formerly, it didn't much matter what went inside the struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 and what went outside it. Now it does, with the advent of "indirect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 buffers" that share text with another buffer. An indirect buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 shares the same *text* as another buffer, but has its own buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 variables, its own accessible region, and its own markers and extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (Due to the nature of markers, it doesn't actually matter much whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 we stick them inside or out of the struct buffer_text -- the user won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 notice any difference -- but we go ahead and put them outside for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 consistency and overall saneness of algorithm.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 FSFmacs gets away with not maintaining any "children" pointers from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 a buffer to the indirect buffers that refer to it by putting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 markers inside of the struct buffer_text, using markers to keep track
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 of BEGV and ZV in indirect buffers, and relying on the fact that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 all intervals (text properties and overlays) use markers for their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 start and end points. We don't do this for extents (markers are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 inefficient anyway and take up space), so we have to maintain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 children pointers. This is not terribly hard, though, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 code to maintain this is just like the code already present in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 extent-parent and extent-children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 Bufbyte *beg; /* Actual address of buffer contents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 Bytind gpt; /* Index of gap in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 Bytind z; /* Index of end of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Bufpos bufz; /* Equivalent as a Bufpos. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 int gap_size; /* Size of buffer's gap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 int end_gap_size; /* Size of buffer's end gap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 long modiff; /* This counts buffer-modification events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 for this buffer. It is incremented for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 each such event, and never otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 long save_modiff; /* Previous value of modiff, as of last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 time buffer visited or saved a file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 /* We keep track of a "known" region for very fast access.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 This information is text-only so it goes here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Bufpos mule_bufmin, mule_bufmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 Bytind mule_bytmin, mule_bytmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 int mule_shifter, mule_three_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* And we also cache 16 positions for fairly fast access near those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 positions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 Bufpos mule_bufpos_cache[16];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 Bytind mule_bytind_cache[16];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 /* Similar to the above, we keep track of positions for which line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 number has last been calculated. See line-number.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 Lisp_Object line_number_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 /* Change data that goes with the text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 struct buffer_text_change_data *changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 struct buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 struct lcrecord_header header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 /* This structure holds the coordinates of the buffer contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 in ordinary buffers. In indirect buffers, this is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 struct buffer_text own_text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* This points to the `struct buffer_text' that is used for this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 In an ordinary buffer, this is the own_text field above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 In an indirect buffer, this is the own_text field of another buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 struct buffer_text *text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 Bytind pt; /* Position of point in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 Bufpos bufpt; /* Equivalent as a Bufpos. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 Bytind begv; /* Index of beginning of accessible range. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 Bufpos bufbegv; /* Equivalent as a Bufpos. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 Bytind zv; /* Index of end of accessible range. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 Bufpos bufzv; /* Equivalent as a Bufpos. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 int face_change; /* This is set when a change in how the text should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 be displayed (e.g., font, color) is made. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 /* change data indicating what portion of the text has changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 since the last time this was reset. Used by redisplay.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 Logically we should keep this with the text structure, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 redisplay resets it for each buffer individually and we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 want interference between an indirect buffer and its base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 struct each_buffer_change_data *changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 /* If the long line scan cache is enabled (i.e. the buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 variable cache-long-line-scans is non-nil), newline_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 points to the newline cache, and width_run_cache points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 width run cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 The newline cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 known *not* to contain newlines, so that they can be skipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 quickly when we search for newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 The width run cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 known to contain characters whose widths are all the same. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 the width run cache maps a character to a value > 0, that value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 is the character's width; if it maps a character to zero, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 don't know what its width is. This allows compute_motion to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 process such regions very quickly, using algebra instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 inspecting each character. See also width_table, below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 struct region_cache *newline_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 struct region_cache *width_run_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 #endif /* REGION_CACHE_NEEDS_WORK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 /* The markers that refer to this buffer. This is actually a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 marker -- successive elements in its marker `chain' are the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 markers referring to this buffer */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
172 Lisp_Marker *markers;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 /* The buffer's extent info. This is its own type, an extent-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 object (done this way for ease in marking / finalizing). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 Lisp_Object extent_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 /* ----------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* All the stuff above this line is the responsibility of insdel.c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 with some help from marker.c and extents.c.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 All the stuff below this line is the responsibility of buffer.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 /* In an indirect buffer, this points to the base buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 In an ordinary buffer, it is 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 We DO mark through this slot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 struct buffer *base_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 /* List of indirect buffers whose base is this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 If we are an indirect buffer, this will be nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 Do NOT mark through this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 Lisp_Object indirect_children;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* Flags saying which DEFVAR_PER_BUFFER variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 are local to this buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 int local_var_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 /* Set to the modtime of the visited file when read or written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 -1 means visited file was nonexistent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 0 means visited file modtime unknown; in no case complain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 about any mismatch on next save attempt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 int modtime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 /* the value of text->modiff at the last auto-save. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
204 long auto_save_modified;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* The time at which we detected a failure to auto-save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 Or -1 if we didn't have a failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 int auto_save_failure_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 /* Position in buffer at which display started
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 the last time this buffer was displayed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 int last_window_start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* Everything from here down must be a Lisp_Object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 #define MARKED_SLOT(x) Lisp_Object x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 #include "bufslots.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 #undef MARKED_SLOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 DECLARE_LRECORD (buffer, struct buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 #define XBUFFER(x) XRECORD (x, buffer, struct buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 #define XSETBUFFER(x, p) XSETRECORD (x, p, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 #define BUFFERP(x) RECORDP (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #define CHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 CHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 #define CONCHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 CONCHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 x = wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 variable that gets the buffer values (beginning with the base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 buffer, then the children), and MPS_BUFCONS should be a temporary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 Lisp_Object variable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #define MAP_INDIRECT_BUFFERS(mps_buf, mps_bufvar, mps_bufcons) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 for (mps_bufcons = Qunbound, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 mps_bufvar = BUFFER_BASE_BUFFER (mps_buf); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 UNBOUNDP (mps_bufcons) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (mps_bufcons = mps_bufvar->indirect_children, \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 1) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 : (!NILP (mps_bufcons) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 && (mps_bufcons = XCDR (mps_bufcons), 1)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /* working with raw internal-format data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 /* NOTE: In all the following macros, we follow these rules concerning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 multiple evaluation of the arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 1) Anything that's an lvalue can be evaluated more than once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 2) Anything that's a Lisp Object can be evaluated more than once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 This should probably be changed, but this follows the way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 that all the macros in lisp.h do things.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 3) 'struct buffer *' arguments can be evaluated more than once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 4) Nothing else can be evaluated more than once. Use inline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 functions, if necessary, to prevent multiple evaluation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 5) An exception to (4) is that there are some macros below that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 may evaluate their arguments more than once. They are all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 denoted with the word "unsafe" in their name and are generally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 meant to be called only by other macros that have already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 stored the calling values in temporary variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 Use the following functions/macros on contiguous strings of data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 If the text you're operating on is known to come from a buffer, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 the buffer-level functions below -- they know about the gap and may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 be more efficient.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (A) For working with charptr's (pointers to internally-formatted text):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 -----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 VALID_CHARPTR_P (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 Given a charptr, does it point to the beginning of a character?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 ASSERT_VALID_CHARPTR (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 If error-checking is enabled, assert that the given charptr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 points to the beginning of a character. Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 INC_CHARPTR (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 Given a charptr (assumed to point at the beginning of a character),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 modify that pointer so it points to the beginning of the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 DEC_CHARPTR (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 Given a charptr (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 character or at the very end of the text), modify that pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 so it points to the beginning of the previous character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 VALIDATE_CHARPTR_BACKWARD (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 Make sure that PTR is pointing to the beginning of a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 If not, back up until this is the case. Note that there are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 too many places where it is legitimate to do this sort of thing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 It's an error if you're passed an "invalid" char * pointer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 NOTE: PTR *must* be pointing to a valid part of the string (i.e.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 not the very end, unless the string is zero-terminated or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 something) in order for this function to not cause crashes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 VALIDATE_CHARPTR_FORWARD (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 Make sure that PTR is pointing to the beginning of a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 If not, move forward until this is the case. Note that there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 are not too many places where it is legitimate to do this sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 of thing. It's an error if you're passed an "invalid" char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 pointer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (B) For working with the length (in bytes and characters) of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 section of internally-formatted text:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 --------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 bytecount_to_charcount (ptr, nbi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 Given a pointer to a text string and a length in bytes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 return the equivalent length in characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 charcount_to_bytecount (ptr, nch):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 Given a pointer to a text string and a length in characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 return the equivalent length in bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 charptr_n_addr (ptr, n):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 Return a pointer to the beginning of the character offset N
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (in characters) from PTR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (C) For retrieving or changing the character pointed to by a charptr:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 ---------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 charptr_emchar (ptr):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 Retrieve the character pointed to by PTR as an Emchar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 charptr_emchar_n (ptr, n):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 Retrieve the character at offset N (in characters) from PTR,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 as an Emchar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 set_charptr_emchar (ptr, ch):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 Store the character CH (an Emchar) as internally-formatted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 text starting at PTR. Return the number of bytes stored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 charptr_copy_char (ptr, ptr2):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 Retrieve the character pointed to by PTR and store it as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 internally-formatted text in PTR2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (D) For working with Emchars:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 -----------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 [Note that there are other functions/macros for working with Emchars
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 in mule-charset.h, for retrieving the charset of an Emchar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 and such. These are only valid when MULE is defined.]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 valid_char_p (ch):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 Return whether the given Emchar is valid.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 CHARP (ch):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 Return whether the given Lisp_Object is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 CHECK_CHAR_COERCE_INT (ch):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 Signal an error if CH is not a valid character or integer Lisp_Object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 If CH is an integer Lisp_Object, convert it to a character Lisp_Object,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 but merely by repackaging, without performing tests for char validity.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 MAX_EMCHAR_LEN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 Maximum number of buffer bytes per Emacs character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 /* ---------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 /* (A) For working with charptr's (pointers to internally-formatted text) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 /* ---------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 # define VALID_CHARPTR_P(ptr) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 #ifdef ERROR_CHECK_BUFPOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 # define ASSERT_VALID_CHARPTR(ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 /* Note that INC_CHARPTR() and DEC_CHARPTR() have to be written in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 completely separate ways. INC_CHARPTR() cannot use the DEC_CHARPTR()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 trick of looking for a valid first byte because it might run off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 method because it doesn't have easy access to the first byte of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 the character it's moving over. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 #define REAL_INC_CHARPTR(ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
414 #define REAL_INC_CHARBYTIND(ptr, pos) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 #define REAL_DEC_CHARPTR(ptr) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (ptr)--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 } while (!VALID_CHARPTR_P (ptr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 #ifdef ERROR_CHECK_BUFPOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 #define INC_CHARPTR(ptr) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 ASSERT_VALID_CHARPTR (ptr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 REAL_INC_CHARPTR (ptr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
427 #define INC_CHARBYTIND(ptr, pos) do { \
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
428 ASSERT_VALID_CHARPTR (ptr); \
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
429 REAL_INC_CHARBYTIND (ptr, pos); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 #define DEC_CHARPTR(ptr) do { \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
433 const Bufbyte *dc_ptr1 = (ptr); \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
434 const Bufbyte *dc_ptr2 = dc_ptr1; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 REAL_DEC_CHARPTR (dc_ptr2); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 assert (dc_ptr1 - dc_ptr2 == \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
438 (ptr) = (Bufbyte *) dc_ptr2; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 #else /* ! ERROR_CHECK_BUFPOS */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442 #define INC_CHARBYTIND(ptr, pos) REAL_INC_CHARBYTIND (ptr, pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 #endif /* ! ERROR_CHECK_BUFPOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 while (!VALID_CHARPTR_P (ptr)) ptr--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 /* This needs to be trickier to avoid the possibility of running off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 the end of the string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 Bufbyte *vcf_ptr = (ptr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 if (vcf_ptr != (ptr)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (ptr) = vcf_ptr; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 INC_CHARPTR (ptr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 #define VALIDATE_CHARPTR_BACKWARD(ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 #define VALIDATE_CHARPTR_FORWARD(ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 /* -------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 /* (B) For working with the length (in bytes and characters) of a */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 /* section of internally-formatted text */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 /* -------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
476 INLINE_HEADER const Bufbyte *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
477 charptr_n_addr (const Bufbyte *ptr, Charcount offset);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
478 INLINE_HEADER const Bufbyte *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
479 charptr_n_addr (const Bufbyte *ptr, Charcount offset)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 return ptr + charcount_to_bytecount (ptr, offset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 /* -------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /* (C) For retrieving or changing the character pointed to by a charptr */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 /* -------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
494 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
496 Bytecount non_ascii_charptr_copy_char (const Bufbyte *src, Bufbyte *dst);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
498 INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
499 INLINE_HEADER Emchar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
500 charptr_emchar (const Bufbyte *ptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 return BYTE_ASCII_P (*ptr) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 simple_charptr_emchar (ptr) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 non_ascii_charptr_emchar (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
507 INLINE_HEADER Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
508 INLINE_HEADER Bytecount
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 set_charptr_emchar (Bufbyte *ptr, Emchar x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 return !CHAR_MULTIBYTE_P (x) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 simple_set_charptr_emchar (ptr, x) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 non_ascii_set_charptr_emchar (ptr, x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
516 /* Copy the character pointed to by SRC into DST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
517 Return the number of bytes copied. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
518 INLINE_HEADER Bytecount
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
519 charptr_copy_char (const Bufbyte *src, Bufbyte *dst);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
520 INLINE_HEADER Bytecount
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
521 charptr_copy_char (const Bufbyte *src, Bufbyte *dst)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
523 return BYTE_ASCII_P (*src) ?
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
524 simple_charptr_copy_char (src, dst) :
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
525 non_ascii_charptr_copy_char (src, dst);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 # define charptr_emchar(ptr) simple_charptr_emchar (ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 # define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 # define charptr_copy_char(ptr, ptr2) simple_charptr_copy_char (ptr, ptr2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 #define charptr_emchar_n(ptr, offset) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 charptr_emchar (charptr_n_addr (ptr, offset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 /* ---------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 /* (D) For working with Emchars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 /* ---------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 int non_ascii_valid_char_p (Emchar ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
548 INLINE_HEADER int valid_char_p (Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
549 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 valid_char_p (Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 #define valid_char_p(ch) ((unsigned int) (ch) <= 0xff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
565 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
566 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 XCHAR_OR_CHAR_INT (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 return CHARP (obj) ? XCHAR (obj) : XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 #define CHECK_CHAR_COERCE_INT(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 if (CHARP (x)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 ; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 else if (CHAR_INTP (x)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 x = make_char (XINT (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 x = wrong_type_argument (Qcharacterp, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 # define MAX_EMCHAR_LEN 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 # define MAX_EMCHAR_LEN 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 /* Accessor macros for important positions in a buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 /* We put them here because some stuff below wants them before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 place where we would normally put them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 /* None of these are lvalues. Use the settor macros below to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 the positions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 /* Beginning of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 #define BI_BUF_BEG(buf) ((Bytind) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 #define BUF_BEG(buf) ((Bufpos) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 /* Beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 #define BI_BUF_BEGV(buf) ((buf)->begv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 #define BUF_BEGV(buf) ((buf)->bufbegv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* End of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 #define BI_BUF_ZV(buf) ((buf)->zv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 #define BUF_ZV(buf) ((buf)->bufzv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 /* End of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 #define BI_BUF_Z(buf) ((buf)->text->z + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 #define BUF_Z(buf) ((buf)->text->bufz + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 /* Point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 #define BI_BUF_PT(buf) ((buf)->pt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 #define BUF_PT(buf) ((buf)->bufpt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 /* Converting between positions and addresses */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 /* Convert the address of a byte in the buffer into a position. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
623 INLINE_HEADER Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
624 INLINE_HEADER Bytind
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 return (ptr - buf->text->beg + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 - ((ptr - buf->text->beg + 1) > buf->text->gpt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 ? buf->text->gap_size : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 #define BUF_PTR_BYTE_POS(buf, ptr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 /* Address of byte at position POS in buffer. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
636 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
637 INLINE_HEADER Bufbyte *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 - 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 #define BUF_BYTE_ADDRESS(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 /* Address of byte before position POS in buffer. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
649 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
650 INLINE_HEADER Bufbyte *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 - 2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 /* Converting between byte indices and memory indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
665 INLINE_HEADER int valid_memind_p (struct buffer *buf, Memind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
666 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 valid_memind_p (struct buffer *buf, Memind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 return ((x >= 1 && x <= (Memind) buf->text->gpt) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 (x > (Memind) (buf->text->gpt + buf->text->gap_size) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 x <= (Memind) (buf->text->z + buf->text->gap_size)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
674 INLINE_HEADER Memind bytind_to_memind (struct buffer *buf, Bytind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
675 INLINE_HEADER Memind
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 bytind_to_memind (struct buffer *buf, Bytind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
682 INLINE_HEADER Bytind memind_to_bytind (struct buffer *buf, Memind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
683 INLINE_HEADER Bytind
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 memind_to_bytind (struct buffer *buf, Memind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 #ifdef ERROR_CHECK_BUFPOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 assert (valid_memind_p (buf, x));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 return (Bytind) ((x > (Memind) buf->text->gpt) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 x - buf->text->gap_size :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 #define memind_to_bufpos(buf, x) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 bytind_to_bufpos (buf, memind_to_bytind (buf, x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 #define bufpos_to_memind(buf, x) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 bytind_to_memind (buf, bufpos_to_bytind (buf, x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 /* These macros generalize many standard buffer-position functions to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 either a buffer or a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 /* Converting between Meminds and Bytinds, for a buffer-or-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 For strings, this is a no-op. For buffers, this resolves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 to the standard memind<->bytind converters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 #define buffer_or_string_bytind_to_memind(obj, ind) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (BUFFERP (obj) ? bytind_to_memind (XBUFFER (obj), ind) : (Memind) ind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 #define buffer_or_string_memind_to_bytind(obj, ind) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (BUFFERP (obj) ? memind_to_bytind (XBUFFER (obj), ind) : (Bytind) ind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 /* Converting between Bufpos's and Bytinds, for a buffer-or-string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 For strings, this maps to the bytecount<->charcount converters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 #define buffer_or_string_bufpos_to_bytind(obj, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 (BUFFERP (obj) ? bufpos_to_bytind (XBUFFER (obj), pos) : \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 (Bytind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 #define buffer_or_string_bytind_to_bufpos(obj, ind) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (BUFFERP (obj) ? bytind_to_bufpos (XBUFFER (obj), ind) : \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 /* Similar for Bufpos's and Meminds. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 #define buffer_or_string_bufpos_to_memind(obj, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 (BUFFERP (obj) ? bufpos_to_memind (XBUFFER (obj), pos) : \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (Memind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 #define buffer_or_string_memind_to_bufpos(obj, ind) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 (BUFFERP (obj) ? memind_to_bufpos (XBUFFER (obj), ind) : \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 /* working with buffer-level data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (A) Working with byte indices:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 ------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 VALID_BYTIND_P(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 Given a byte index, does it point to the beginning of a character?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ASSERT_VALID_BYTIND_UNSAFE(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 If error-checking is enabled, assert that the given byte index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 is within range and points to the beginning of a character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 or to the end of the buffer. Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 If error-checking is enabled, assert that the given byte index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 is within range and satisfies ASSERT_VALID_BYTIND() and also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 does not refer to the beginning of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 backwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 If error-checking is enabled, assert that the given byte index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 is within range and satisfies ASSERT_VALID_BYTIND() and also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 does not refer to the end of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 forwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 VALIDATE_BYTIND_BACKWARD(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 of a character. If not, back up until this is the case. Note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 that there are not too many places where it is legitimate to do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 this sort of thing. It's an error if you're passed an "invalid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 VALIDATE_BYTIND_FORWARD(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 of a character. If not, move forward until this is the case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 Note that there are not too many places where it is legitimate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 to do this sort of thing. It's an error if you're passed an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 "invalid" byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 INC_BYTIND(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 of the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 DEC_BYTIND(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 of the previous character. Unlike for DEC_CHARPTR(), we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 do all the assert()s because there are sentinels at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 beginning of the gap and the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 BYTIND_INVALID:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 A constant representing an invalid Bytind. Valid Bytinds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 can never have this value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (B) Converting between Bufpos's and Bytinds:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 --------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 bufpos_to_bytind(buf, bu):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 Given a Bufpos, return the equivalent Bytind.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 bytind_to_bufpos(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 Given a Bytind, return the equivalent Bufpos.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 make_bufpos(buf, bi):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 Given a Bytind, return the equivalent Bufpos as a Lisp Object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 /* working with byte indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 # define VALID_BYTIND_P(buf, x) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 # define VALID_BYTIND_P(buf, x) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 #ifdef ERROR_CHECK_BUFPOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 assert (VALID_BYTIND_P (buf, x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 assert (VALID_BYTIND_P (buf, x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 assert (VALID_BYTIND_P (buf, x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 #else /* not ERROR_CHECK_BUFPOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 #endif /* not ERROR_CHECK_BUFPOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 # define VALIDATE_BYTIND_BACKWARD(buf, x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 Bufbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 while (!BUFBYTE_FIRST_BYTE_P (*VBB_ptr)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 VBB_ptr--, (x)--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 # define VALIDATE_BYTIND_BACKWARD(buf, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 # define VALIDATE_BYTIND_FORWARD(buf, x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 Bufbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 while (!BUFBYTE_FIRST_BYTE_P (*VBF_ptr)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 VBF_ptr++, (x)++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 # define VALIDATE_BYTIND_FORWARD(buf, x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 this crap reduces down to simply (x)++. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 #define INC_BYTIND(buf, x) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 ASSERT_VALID_BYTIND_FORWARD_UNSAFE (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /* Note that we do the increment first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 make sure that the pointer in \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 VALIDATE_BYTIND_FORWARD() ends up on \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (x)++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 VALIDATE_BYTIND_FORWARD (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 this crap reduces down to simply (x)--. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 #define DEC_BYTIND(buf, x) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 /* Note that we do the decrement first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 make sure that the pointer in \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 VALIDATE_BYTIND_BACKWARD() ends up on \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (x)--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 VALIDATE_BYTIND_BACKWARD (buf, x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
903 INLINE_HEADER Bytind prev_bytind (struct buffer *buf, Bytind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
904 INLINE_HEADER Bytind
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 prev_bytind (struct buffer *buf, Bytind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 DEC_BYTIND (buf, x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
911 INLINE_HEADER Bytind next_bytind (struct buffer *buf, Bytind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
912 INLINE_HEADER Bytind
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 next_bytind (struct buffer *buf, Bytind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 INC_BYTIND (buf, x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 #define BYTIND_INVALID ((Bytind) -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 /* Converting between buffer positions and byte indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 /* The basic algorithm we use is to keep track of a known region of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 characters in each buffer, all of which are of the same width. We
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 keep track of the boundaries of the region in both Bufpos and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 Bytind coordinates and also keep track of the char width, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 is 1 - 4 bytes. If the position we're translating is not in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 the known region, then we invoke a function to update the known
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 region to surround the position in question. This assumes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 locality of reference, which is usually the case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 Note that the function to update the known region can be simple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 or complicated depending on how much information we cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 For the moment, we don't cache any information, and just move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 linearly forward or back from the known region, with a few
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 shortcuts to catch all-ASCII buffers. (Note that this will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 thrash with bad locality of reference.) A smarter method would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 be to keep some sort of pseudo-extent layer over the buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 maybe keep track of the bufpos/bytind correspondence at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 beginning of each line, which would allow us to do a binary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 search over the pseudo-extents to narrow things down to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 correct line, at which point you could use a linear movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 method. This would also mesh well with efficiently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 implementing a line-numbering scheme.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 Note also that we have to multiply or divide by the char width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 in order to convert the positions. We do some tricks to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 ever actually having to do a multiply or divide, because that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 is typically an expensive operation (esp. divide). Multiplying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 or dividing by 1, 2, or 4 can be implemented simply as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 shift left or shift right, and we keep track of a shifter value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (0, 1, or 2) indicating how much to shift. Multiplying by 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 can be implemented by doubling and then adding the original
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 value. Dividing by 3, alas, cannot be implemented in any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 simple shift/subtract method, as far as I know; so we just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 do a table lookup. For simplicity, we use a table of size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 128K, which indexes the "divide-by-3" values for the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 64K non-negative numbers. (Note that we can increase the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 size up to 384K, i.e. indexing the first 192K non-negative
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 numbers, while still using shorts in the array.) This also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 means that the size of the known region can be at most
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 64K for width-three characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 extern short three_to_one_table[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
974 INLINE_HEADER int real_bufpos_to_bytind (struct buffer *buf, Bufpos x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
975 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 real_bufpos_to_bytind (struct buffer *buf, Bufpos x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 return (buf->text->mule_bytmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 return bufpos_to_bytind_func (buf, x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
986 INLINE_HEADER int real_bytind_to_bufpos (struct buffer *buf, Bytind x);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
987 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 real_bytind_to_bufpos (struct buffer *buf, Bytind x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 return (buf->text->mule_bufmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 ((buf->text->mule_three_p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 ? three_to_one_table[x - buf->text->mule_bytmin]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 return bytind_to_bufpos_func (buf, x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 # define real_bufpos_to_bytind(buf, x) ((Bytind) x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 # define real_bytind_to_bufpos(buf, x) ((Bufpos) x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 #ifdef ERROR_CHECK_BUFPOS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 Bytind bufpos_to_bytind (struct buffer *buf, Bufpos x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 #else /* not ERROR_CHECK_BUFPOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 #define bufpos_to_bytind real_bufpos_to_bytind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 #define bytind_to_bufpos real_bytind_to_bufpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 #endif /* not ERROR_CHECK_BUFPOS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 #define make_bufpos(buf, ind) make_int (bytind_to_bufpos (buf, ind))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 /* Converting between buffer bytes and Emacs characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 /* The character at position POS in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 #define BI_BUF_FETCH_CHAR(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 #define BUF_FETCH_CHAR(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 BI_BUF_FETCH_CHAR (buf, bufpos_to_bytind (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 /* The character at position POS in buffer, as a string. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 but is faster for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 /************************************************************************/
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1041 /* */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1042 /* Converting between internal and external format */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1043 /* */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 /************************************************************************/
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1045 /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1046 All client code should use only the two macros
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1048 TO_EXTERNAL_FORMAT (source_type, source, sink_type, sink, coding_system)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1049 TO_INTERNAL_FORMAT (source_type, source, sink_type, sink, coding_system)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1050
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1051 Typical use is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1053 TO_EXTERNAL_FORMAT (DATA, (ptr, len),
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1054 LISP_BUFFER, buffer,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1055 Qfile_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1057 The source or sink can be specified in one of these ways:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1059 DATA, (ptr, len), // input data is a fixed buffer of size len
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1060 ALLOCA, (ptr, len), // output data is in a alloca()ed buffer of size len
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1061 MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1062 C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1063 C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1064 C_STRING, ptr, // equivalent to DATA, (ptr, strlen (ptr) + 1) on input
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1065 LISP_STRING, string, // input or output is a Lisp_Object of type string
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1066 LISP_BUFFER, buffer, // output is written to (point) in lisp buffer
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1067 LISP_LSTREAM, lstream, // input or output is a Lisp_Object of type lstream
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1068 LISP_OPAQUE, object, // input or output is a Lisp_Object of type opaque
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1070 When specifying the sink, use lvalues, since the macro will assign to them,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1071 except when the sink is an lstream or a lisp buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1073 The macros accept the kinds of sources and sinks appropriate for
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1074 internal and external data representation. See the type_checking_assert
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1075 macros below for the actual allowed types.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1077 Since some sources and sinks use one argument (a Lisp_Object) to
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1078 specify them, while others take a (pointer, length) pair, we use
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1079 some C preprocessor trickery to allow pair arguments to be specified
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1080 by parenthesizing them, as in the examples above.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1082 Anything prefixed by dfc_ (`data format conversion') is private.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1083 They are only used to implement these macros.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1085 Using C_STRING* is appropriate for using with external APIs that take
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1086 null-terminated strings. For internal data, we should try to be
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1087 '\0'-clean - i.e. allow arbitrary data to contain embedded '\0'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1089 Sometime in the future we might allow output to C_STRING_ALLOCA or
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1090 C_STRING_MALLOC _only_ with TO_EXTERNAL_FORMAT(), not
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1091 TO_INTERNAL_FORMAT(). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1093 #define TO_EXTERNAL_FORMAT(source_type, source, sink_type, sink, coding_system) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1094 do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1095 dfc_conversion_type dfc_simplified_source_type; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1096 dfc_conversion_type dfc_simplified_sink_type; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1097 dfc_conversion_data dfc_source; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1098 dfc_conversion_data dfc_sink; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1099 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1100 type_checking_assert \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1101 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1102 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1103 DFC_TYPE_##source_type == DFC_TYPE_LISP_STRING || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1104 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1105 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1106 && \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1107 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1108 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1109 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1110 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1111 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1112 DFC_TYPE_##sink_type == DFC_TYPE_LISP_OPAQUE)); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1113 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1114 DFC_SOURCE_##source_type##_TO_ARGS (source); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1115 DFC_SINK_##sink_type##_TO_ARGS (sink); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1116 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1117 DFC_CONVERT_TO_EXTERNAL_FORMAT (dfc_simplified_source_type, &dfc_source, \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1118 coding_system, \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1119 dfc_simplified_sink_type, &dfc_sink); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1120 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1121 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1124 #define TO_INTERNAL_FORMAT(source_type, source, sink_type, sink, coding_system) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1125 do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1126 dfc_conversion_type dfc_simplified_source_type; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1127 dfc_conversion_type dfc_simplified_sink_type; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1128 dfc_conversion_data dfc_source; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1129 dfc_conversion_data dfc_sink; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1130 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1131 type_checking_assert \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1132 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1133 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1134 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1135 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1136 && \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1137 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1138 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1139 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1140 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1141 DFC_TYPE_##sink_type == DFC_TYPE_LISP_STRING || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1142 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1143 DFC_TYPE_##sink_type == DFC_TYPE_LISP_BUFFER)); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1144 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1145 DFC_SOURCE_##source_type##_TO_ARGS (source); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1146 DFC_SINK_##sink_type##_TO_ARGS (sink); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1147 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1148 DFC_CONVERT_TO_INTERNAL_FORMAT (dfc_simplified_source_type, &dfc_source, \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1149 coding_system, \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1150 dfc_simplified_sink_type, &dfc_sink); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1151 \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1152 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1155 #ifdef FILE_CODING
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1156 #define DFC_CONVERT_TO_EXTERNAL_FORMAT dfc_convert_to_external_format
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1157 #define DFC_CONVERT_TO_INTERNAL_FORMAT dfc_convert_to_internal_format
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1158 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1159 /* ignore coding_system argument */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1160 #define DFC_CONVERT_TO_EXTERNAL_FORMAT(a, b, coding_system, c, d) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1161 dfc_convert_to_external_format (a, b, c, d)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1162 #define DFC_CONVERT_TO_INTERNAL_FORMAT(a, b, coding_system, c, d) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1163 dfc_convert_to_internal_format (a, b, c, d)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1164 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1166 typedef union
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1167 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1168 struct { const void *ptr; size_t len; } data;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1169 Lisp_Object lisp_object;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1170 } dfc_conversion_data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1172 enum dfc_conversion_type
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1173 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1174 DFC_TYPE_DATA,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1175 DFC_TYPE_ALLOCA,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1176 DFC_TYPE_MALLOC,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1177 DFC_TYPE_C_STRING,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1178 DFC_TYPE_C_STRING_ALLOCA,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1179 DFC_TYPE_C_STRING_MALLOC,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1180 DFC_TYPE_LISP_STRING,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1181 DFC_TYPE_LISP_LSTREAM,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1182 DFC_TYPE_LISP_OPAQUE,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1183 DFC_TYPE_LISP_BUFFER
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1184 };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1185 typedef enum dfc_conversion_type dfc_conversion_type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1187 /* WARNING: These use a static buffer. This can lead to disaster if
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1188 these functions are not used *very* carefully. Another reason to only use
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1189 TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1190 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1191 dfc_convert_to_external_format (dfc_conversion_type source_type,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1192 dfc_conversion_data *source,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1193 #ifdef FILE_CODING
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1194 Lisp_Object coding_system,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1195 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1196 dfc_conversion_type sink_type,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1197 dfc_conversion_data *sink);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1198 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1199 dfc_convert_to_internal_format (dfc_conversion_type source_type,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1200 dfc_conversion_data *source,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1201 #ifdef FILE_CODING
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1202 Lisp_Object coding_system,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1203 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1204 dfc_conversion_type sink_type,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1205 dfc_conversion_data *sink);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1206 /* CPP Trickery */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1207 #define DFC_CPP_CAR(x,y) (x)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1208 #define DFC_CPP_CDR(x,y) (y)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1209
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1210 /* Convert `source' to args for dfc_convert_to_*_format() */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1211 #define DFC_SOURCE_DATA_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1212 dfc_source.data.ptr = DFC_CPP_CAR val; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1213 dfc_source.data.len = DFC_CPP_CDR val; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1214 dfc_simplified_source_type = DFC_TYPE_DATA; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 } while (0)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1216 #define DFC_SOURCE_C_STRING_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1217 dfc_source.data.len = \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1218 strlen ((char *) (dfc_source.data.ptr = (val))); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1219 dfc_simplified_source_type = DFC_TYPE_DATA; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1220 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1221 #define DFC_SOURCE_LISP_STRING_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1222 Lisp_Object dfc_slsta = (val); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1223 type_checking_assert (STRINGP (dfc_slsta)); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1224 dfc_source.lisp_object = dfc_slsta; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1225 dfc_simplified_source_type = DFC_TYPE_LISP_STRING; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1226 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1227 #define DFC_SOURCE_LISP_LSTREAM_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1228 Lisp_Object dfc_sllta = (val); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1229 type_checking_assert (LSTREAMP (dfc_sllta)); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1230 dfc_source.lisp_object = dfc_sllta; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1231 dfc_simplified_source_type = DFC_TYPE_LISP_LSTREAM; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1232 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1233 #define DFC_SOURCE_LISP_OPAQUE_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1234 Lisp_Opaque *dfc_slota = XOPAQUE (val); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1235 dfc_source.data.ptr = OPAQUE_DATA (dfc_slota); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1236 dfc_source.data.len = OPAQUE_SIZE (dfc_slota); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1237 dfc_simplified_source_type = DFC_TYPE_DATA; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1240 /* Convert `sink' to args for dfc_convert_to_*_format() */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1241 #define DFC_SINK_ALLOCA_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1242 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1243 #define DFC_SINK_C_STRING_ALLOCA_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1244 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1245 #define DFC_SINK_MALLOC_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1246 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1247 #define DFC_SINK_C_STRING_MALLOC_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1248 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1249 #define DFC_SINK_LISP_STRING_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1250 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1251 #define DFC_SINK_LISP_OPAQUE_TO_ARGS(val) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1252 dfc_simplified_sink_type = DFC_TYPE_DATA
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1253 #define DFC_SINK_LISP_LSTREAM_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1254 Lisp_Object dfc_sllta = (val); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1255 type_checking_assert (LSTREAMP (dfc_sllta)); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1256 dfc_sink.lisp_object = dfc_sllta; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1257 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1258 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1259 #define DFC_SINK_LISP_BUFFER_TO_ARGS(val) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1260 struct buffer *dfc_slbta = XBUFFER (val); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1261 dfc_sink.lisp_object = \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1262 make_lisp_buffer_output_stream \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1263 (dfc_slbta, BUF_PT (dfc_slbta), 0); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1264 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1267 /* Assign to the `sink' lvalue(s) using the converted data. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1268 typedef union { char c; void *p; } *dfc_aliasing_voidpp;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1269 #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1270 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1271 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1272 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1273 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1274 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1275 #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1276 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1277 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1278 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1279 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1280 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1281 #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1282 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1283 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1284 (sink) = (char *) dfc_sink_ret; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1285 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1286 #define DFC_C_STRING_MALLOC_USE_CONVERTED_DATA(sink) do { \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1287 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1288 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1289 (sink) = (char *) dfc_sink_ret; \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1290 } while (0)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1291 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1292 sink = make_string ((Bufbyte *) dfc_sink.data.ptr, dfc_sink.data.len)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1293 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1294 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1295 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1296 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1297 Lstream_delete (XLSTREAM (dfc_sink.lisp_object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1299 /* Someday we might want to distinguish between Qnative and Qfile_name
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1300 by using coding-system aliases, but for now it suffices to have
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1301 these be identical. Qnative can be used as the coding_system
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1302 argument to TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1303 #define Qnative Qfile_name
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1305 #if defined (WIN32_NATIVE) || defined (CYGWIN)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1306 /* #### kludge!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1307 Remove this as soon as my Mule code is integrated. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1308 #define Qmswindows_tstr Qnative
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1309 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1310
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1311 /* More stand-ins */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1312 #define Qcommand_argument_encoding Qnative
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1313 #define Qenvironment_variable_encoding Qnative
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1314
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1315 /* Convenience macros for extremely common invocations */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1316 #define C_STRING_TO_EXTERNAL(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1317 TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1318 #define C_STRING_TO_EXTERNAL_MALLOC(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1319 TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1320 #define EXTERNAL_TO_C_STRING(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1321 TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1322 #define EXTERNAL_TO_C_STRING_MALLOC(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1323 TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1324 #define LISP_STRING_TO_EXTERNAL(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1325 TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_ALLOCA, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1326 #define LISP_STRING_TO_EXTERNAL_MALLOC(in, out, coding_system) \
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1327 TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_MALLOC, out, coding_system)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1328
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 /* fake charset functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 /* used when MULE is not defined, so that Charset-type stuff can still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 be done */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 #ifndef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 #define Vcharset_ascii Qnil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 #define CHAR_CHARSET(ch) Vcharset_ascii
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 #define CHAR_LEADING_BYTE(ch) LEADING_BYTE_ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 #define LEADING_BYTE_ASCII 0x80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 #define NUM_LEADING_BYTES 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 #define MIN_LEADING_BYTE 0x80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 #define CHARSETP(cs) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 #define CHARSET_BY_LEADING_BYTE(lb) Vcharset_ascii
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 #define XCHARSET_LEADING_BYTE(cs) LEADING_BYTE_ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 #define XCHARSET_GRAPHIC(cs) -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 #define XCHARSET_COLUMNS(cs) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 #define XCHARSET_DIMENSION(cs) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 #define REP_BYTES_BY_FIRST_BYTE(fb) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 #define BREAKUP_CHAR(ch, charset, byte1, byte2) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (charset) = Vcharset_ascii; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (byte1) = (ch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (byte2) = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 #define BYTE_ASCII_P(byte) 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 #endif /* ! MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 /* higher-level buffer-position functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 /* Settor macros for important positions in a buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 /* Set beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 #define SET_BOTH_BUF_BEGV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 (buf)->begv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (buf)->bufbegv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 /* Set end of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 #define SET_BOTH_BUF_ZV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 (buf)->zv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 (buf)->bufzv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 /* Set point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 /* Since BEGV and ZV are almost never set, it's reasonable to enforce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 the restriction that the Bufpos and Bytind values must both be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 specified. However, point is set in lots and lots of places. So
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 we provide the ability to specify both (for efficiency) or just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 #define BI_BUF_SET_PT(buf, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 BOTH_BUF_SET_PT (buf, bytind_to_bufpos (buf, bival), bival)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 #define BUF_SET_PT(buf, value) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 BOTH_BUF_SET_PT (buf, value, bufpos_to_bytind (buf, value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 #if 0 /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 does too much stuff, such as moving out of invisible extents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 #define SET_BUF_PT(buf, value) ((buf)->pt = (value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 #endif /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 /* Miscellaneous buffer values */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 /* Number of characters in buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 /* Is this buffer narrowed? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 #define BUF_NARROWED(buf) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (BI_BUF_ZV (buf) != BI_BUF_Z (buf)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 /* Modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 #define BUF_MODIFF(buf) ((buf)->text->modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 /* Saved modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 /* Face changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 #define BUF_FACECHANGE(buf) ((buf)->face_change)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 #define POINT_MARKER_P(marker) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 (XMARKER (marker)->buffer != 0 && \
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
1433 EQ (marker, XMARKER (marker)->buffer->point_marker))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 #define BUF_MARKERS(buf) ((buf)->markers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 /* WARNING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 from the old ones (in FSF Emacs and XEmacs 19.11 and before).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 Conversion is as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 OLD_BI_CEILING_OF(n) = NEW_BI_CEILING_OF(n) - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 OLD_BI_FLOOR_OF(n) = NEW_BI_FLOOR_OF(n + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 The definitions were changed because the new definitions are more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 consistent with the way everything else works in Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 /* Properties of CEILING_OF and FLOOR_OF (also apply to BI_ variants):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 1) FLOOR_OF (CEILING_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 CEILING_OF (FLOOR_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 2) CEILING_OF (n) = n if and only if n = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 FLOOR_OF (n) = n if and only if n = BEGV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 3) CEILING_OF (CEILING_OF (n)) = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 FLOOR_OF (FLOOR_OF (n)) = BEGV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 4) The bytes in the regions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 are contiguous.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 /* Return the maximum index in the buffer it is safe to scan forwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 past N to. This is used to prevent buffer scans from running into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 the gap (e.g. search.c). All characters between N and CEILING_OF(N)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 are located contiguous in memory. Note that the character *at*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 CEILING_OF(N) is not contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 #define BI_BUF_CEILING_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 (b)->text->gpt : BI_BUF_ZV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 #define BUF_CEILING_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 bytind_to_bufpos (b, BI_BUF_CEILING_OF (b, bufpos_to_bytind (b, n)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 /* Return the minimum index in the buffer it is safe to scan backwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 past N to. All characters between FLOOR_OF(N) and N are located
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 contiguous in memory. Note that the character *at* N may not be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 #define BI_BUF_FLOOR_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (b)->text->gpt : BI_BUF_BEGV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 #define BUF_FLOOR_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 bytind_to_bufpos (b, BI_BUF_FLOOR_OF (b, bufpos_to_bytind (b, n)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 (b)->text->gpt : BI_BUF_Z (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 bytind_to_bufpos \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (b)->text->gpt : BI_BUF_BEG (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 bytind_to_bufpos \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 extern struct buffer *current_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 /* This is the initial (startup) directory, as used for the *scratch* buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 We're making this a global to make others aware of the startup directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 `initial_directory' is stored in external format.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 extern char initial_directory[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 extern void init_initial_directory (void); /* initialize initial_directory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 EXFUN (Fbuffer_disable_undo, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 EXFUN (Fbuffer_modified_p, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 EXFUN (Fbuffer_name, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 EXFUN (Fcurrent_buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 EXFUN (Ferase_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 EXFUN (Fget_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 EXFUN (Fget_buffer_create, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 EXFUN (Fget_file_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 EXFUN (Fkill_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 EXFUN (Fother_buffer, 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 EXFUN (Frecord_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 EXFUN (Fset_buffer, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 EXFUN (Fset_buffer_modified_p, 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 extern Lisp_Object QSscratch, Qafter_change_function, Qafter_change_functions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 extern Lisp_Object Qbefore_change_function, Qbefore_change_functions;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 extern Lisp_Object Qbuffer_or_string_p, Qdefault_directory, Qfirst_change_hook;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 extern Lisp_Object Qpermanent_local, Vafter_change_function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 extern Lisp_Object Vafter_change_functions, Vbefore_change_function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 extern Lisp_Object Vbefore_change_functions, Vbuffer_alist, Vbuffer_defaults;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 extern Lisp_Object Vinhibit_read_only, Vtransient_mark_mode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 /* This structure marks which slots in a buffer have corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 default values in Vbuffer_defaults.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 Each such slot has a nonzero value in this structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 The value has only one nonzero bit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 When a buffer has its own local value for a slot,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 the bit for that slot (found in the same slot in this structure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 is turned on in the buffer's local_var_flags slot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 If a slot in this structure is zero, then even though there may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 and the corresponding slot in Vbuffer_defaults is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 extern struct buffer buffer_local_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 /* Allocation of buffer data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1560 char *r_alloc (unsigned char **, size_t);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1561 char *r_re_alloc (unsigned char **, size_t);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 void r_alloc_free (unsigned char **);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 #define BUFFER_ALLOC(data, size) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 ((Bufbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 #define BUFFER_REALLOC(data, size) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 ((Bufbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 #else /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 #define BUFFER_ALLOC(data,size)\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 (data = xnew_array (Bufbyte, size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 #define BUFFER_REALLOC(data,size)\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 ((Bufbyte *) xrealloc (data, (size) * sizeof(Bufbyte)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 /* Avoid excess parentheses, or syntax errors may rear their heads. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 #define BUFFER_FREE(data) xfree (data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 #define R_ALLOC_DECLARE(var,data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 #endif /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 extern Lisp_Object Vbuffer_alist;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 void set_buffer_internal (struct buffer *b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 struct buffer *decode_buffer (Lisp_Object buffer, int allow_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 /* from editfns.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 void widen_buffer (struct buffer *b, int no_clip);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 int beginning_of_line_p (struct buffer *b, Bufpos pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 /* from insdel.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 void find_charsets_in_bufbyte_string (unsigned char *charsets,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1594 const Bufbyte *str,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 Bytecount len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 void find_charsets_in_emchar_string (unsigned char *charsets,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1597 const Emchar *str,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 Charcount len);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1599 int bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1600 int emchar_string_displayed_columns (const Emchar *str, Charcount len);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1601 void convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 Bytecount len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 Emchar_dynarr *dyn);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1604 Charcount convert_bufbyte_string_into_emchar_string (const Bufbyte *str,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 Bytecount len,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 Emchar *arr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 Bufbyte_dynarr *dyn);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 Bytecount *len_out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 /* from marker.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 void init_buffer_markers (struct buffer *b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 void uninit_buffer_markers (struct buffer *b);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 /* flags for get_buffer_pos_char(), get_buffer_range_char(), etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 /* At most one of GB_COERCE_RANGE and GB_NO_ERROR_IF_BAD should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 specified. At most one of GB_NEGATIVE_FROM_END and GB_NO_ERROR_IF_BAD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 should be specified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 #define GB_ALLOW_PAST_ACCESSIBLE (1 << 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 #define GB_ALLOW_NIL (1 << 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 #define GB_CHECK_ORDER (1 << 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 #define GB_COERCE_RANGE (1 << 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 #define GB_NO_ERROR_IF_BAD (1 << 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 #define GB_NEGATIVE_FROM_END (1 << 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 #define GB_HISTORICAL_STRING_BEHAVIOR (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 Bufpos get_buffer_pos_char (struct buffer *b, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 Bytind get_buffer_pos_byte (struct buffer *b, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 void get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 Bufpos *from_out, Bufpos *to_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 void get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 Bytind *from_out, Bytind *to_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 Charcount get_string_pos_char (Lisp_Object string, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 Bytecount get_string_pos_byte (Lisp_Object string, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 void get_string_range_char (Lisp_Object string, Lisp_Object from,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 Lisp_Object to, Charcount *from_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 Charcount *to_out, unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 void get_string_range_byte (Lisp_Object string, Lisp_Object from,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 Lisp_Object to, Bytecount *from_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 Bytecount *to_out, unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 Bufpos get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 Bytind get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 void get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 Lisp_Object to, Bufpos *from_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 Bufpos *to_out, unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 void get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 Lisp_Object to, Bytind *from_out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 Bytind *to_out, unsigned int flags);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 Bufpos buffer_or_string_accessible_begin_char (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 Bufpos buffer_or_string_accessible_end_char (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 Bytind buffer_or_string_accessible_begin_byte (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 Bytind buffer_or_string_accessible_end_byte (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 Bufpos buffer_or_string_absolute_begin_char (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 Bufpos buffer_or_string_absolute_end_char (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 Bytind buffer_or_string_absolute_begin_byte (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 Bytind buffer_or_string_absolute_end_byte (Lisp_Object object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 void record_buffer (Lisp_Object buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 Lisp_Object get_buffer (Lisp_Object name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 int error_if_deleted_or_does_not_exist);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 int map_over_sharing_buffers (struct buffer *buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 int (*mapfun) (struct buffer *buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 void *closure),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 void *closure);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 /* Case conversion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 /* A "trt" table is a mapping from characters to other characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 typically used to convert between uppercase and lowercase. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 compatibility reasons, trt tables are currently in the form of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 a Lisp string of 256 characters, specifying the conversion for each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 of the first 256 Emacs characters (i.e. the 256 Latin-1 characters).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 This should be generalized at some point to support conversions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 all of the allowable Mule characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 /* The _1 macros are named as such because they assume that you have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 already guaranteed that the character values are all in the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 0 - 255. Bad lossage will happen otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1692 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1693 INLINE_HEADER Emchar TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1694 INLINE_HEADER Emchar
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1695 TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1696 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1697 Lisp_Object TRT_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1698 TRT_char = get_char_table (ch, XCHAR_TABLE (table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1699 if (NILP (TRT_char))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1700 return ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1701 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1702 return XCHAR (TRT_char);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1703 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1704 #define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1705 Fput_char_table (make_char (ch1), make_char (ch2), table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1707 INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1708 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1711 return TRT_TABLE_CHAR_1 (trt, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 /* Macros used below. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1715 #define DOWNCASE_TABLE_OF(buf, c) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1716 TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (buf->case_table), c)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1717 #define UPCASE_TABLE_OF(buf, c) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
1718 TRT_TABLE_OF (XCASE_TABLE_UPCASE (buf->case_table), c)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 /* 1 if CH is upper case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1722 INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1723 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 UPPERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 return DOWNCASE_TABLE_OF (buf, ch) != ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 /* 1 if CH is lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1731 INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1732 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 LOWERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 return (UPCASE_TABLE_OF (buf, ch) != ch &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 DOWNCASE_TABLE_OF (buf, ch) == ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 /* 1 if CH is neither upper nor lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1741 INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1742 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 NOCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 return UPCASE_TABLE_OF (buf, ch) == ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 /* Upcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1750 INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1751 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 UPCASE (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 /* Upcase a character known to be not upper case. Unused. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 /* Downcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1765 /************************************************************************/
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1766 /* Lisp string representation convenience functions */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1767 /************************************************************************/
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1768 /* Because the representation of internally formatted data is subject to change,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1769 It's bad style to do something like strcmp (XSTRING_DATA (s), "foo")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1770 Instead, use the portable: bufbyte_strcmp (XSTRING_DATA (s), "foo")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1771 or bufbyte_memcmp (XSTRING_DATA (s), "foo", 3) */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1772
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1773 /* Like strcmp, except first arg points at internally formatted data,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1774 while the second points at a string of only ASCII chars. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1775 INLINE_HEADER int
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1776 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1777 INLINE_HEADER int
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1778 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1779 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1780 #ifdef MULE
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1781 while (1)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1782 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1783 int diff;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1784 type_checking_assert (BYTE_ASCII_P (*ascii_string));
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1785 if ((diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string) != 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1786 return diff;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1787 if (*ascii_string == '\0')
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1788 return 0;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1789 ascii_string++;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1790 INC_CHARPTR (bp);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1791 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1792 #else
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1793 return strcmp ((char *)bp, ascii_string);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1794 #endif
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1795 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1796
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1797
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1798 /* Like memcmp, except first arg points at internally formatted data,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1799 while the second points at a string of only ASCII chars. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1800 INLINE_HEADER int
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1801 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1802 INLINE_HEADER int
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1803 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1804 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1805 #ifdef MULE
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1806 while (len--)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1807 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1808 int diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1809 type_checking_assert (BYTE_ASCII_P (*ascii_string));
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1810 if (diff != 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1811 return diff;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1812 ascii_string++;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1813 INC_CHARPTR (bp);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1814 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1815 return 0;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1816 #else
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1817 return memcmp (bp, ascii_string, len);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1818 #endif
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1819 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1820
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1821 #endif /* INCLUDED_buffer_h_ */