comparison src/buffer.h @ 867:804517e16990

[xemacs-hg @ 2002-06-05 09:54:39 by ben] Textual renaming: text/char names abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, charset.h, chartab.c, chartab.h, cmds.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console-x.h, console.h, data.c, device-msw.c, device-x.c, dialog-msw.c, dired-msw.c, dired.c, doc.c, doprnt.c, editfns.c, eldap.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-unixoid.c, events.c, events.h, file-coding.c, file-coding.h, fileio.c, filelock.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, glyphs-eimage.c, glyphs-msw.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-x.c, gui-x.h, gui.c, gui.h, hpplay.c, indent.c, insdel.c, insdel.h, intl-win32.c, keymap.c, line-number.c, line-number.h, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, md5.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, ndir.h, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-tty.c, objects-x.c, objects.c, objects.h, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, procimpl.h, realpath.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, search.c, select-common.h, select-gtk.c, select-x.c, sound.h, symbols.c, syntax.c, syntax.h, sysdep.c, sysdep.h, sysdir.h, sysfile.h, sysproc.h, syspwd.h, systime.h, syswindows.h, termcap.c, tests.c, text.c, text.h, toolbar-common.c, tooltalk.c, ui-gtk.c, unexnt.c, unicode.c, win32.c: Text/char naming rationalization. [a] distinguish between "charptr" when it refers to operations on the pointer itself and when it refers to operations on text; and [b] use consistent naming for everything referring to internal format, i.e. Itext == text in internal format Ibyte == a byte in such text Ichar == a char as represented in internal character format thus e.g. set_charptr_emchar -> set_itext_ichar The pre and post tags on either side of this change are: pre-internal-format-textual-renaming post-internal-format-textual-renaming See the Internals Manual for details of exactly how this was done, how to handle the change in your workspace, etc.
author ben
date Wed, 05 Jun 2002 09:58:45 +0000
parents 6728e641994e
children e22b0213b713
comparison
equal deleted inserted replaced
866:613552a02607 867:804517e16990
74 extent-parent and extent-children. 74 extent-parent and extent-children.
75 */ 75 */
76 76
77 struct buffer_text 77 struct buffer_text
78 { 78 {
79 Intbyte *beg; /* Actual address of buffer contents. */ 79 Ibyte *beg; /* Actual address of buffer contents. */
80 Bytebpos gpt; /* Index of gap in buffer. */ 80 Bytebpos gpt; /* Index of gap in buffer. */
81 Bytebpos z; /* Index of end of buffer. */ 81 Bytebpos z; /* Index of end of buffer. */
82 Charbpos bufz; /* Equivalent as a Charbpos. */ 82 Charbpos bufz; /* Equivalent as a Charbpos. */
83 Bytecount gap_size;/* Size of buffer's gap */ 83 Bytecount gap_size;/* Size of buffer's gap */
84 Bytecount end_gap_size;/* Size of buffer's end gap */ 84 Bytecount end_gap_size;/* Size of buffer's end gap */
327 /* Validating byte positions */ 327 /* Validating byte positions */
328 /*----------------------------------------------------------------------*/ 328 /*----------------------------------------------------------------------*/
329 329
330 /* Address of byte at position POS in buffer, no error checking. */ 330 /* Address of byte at position POS in buffer, no error checking. */
331 DECLARE_INLINE_HEADER ( 331 DECLARE_INLINE_HEADER (
332 Intbyte * 332 Ibyte *
333 BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (struct buffer *buf, Bytebpos pos) 333 BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (struct buffer *buf, Bytebpos pos)
334 ) 334 )
335 { 335 {
336 return (buf->text->beg + 336 return (buf->text->beg +
337 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) 337 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
347 ) 347 )
348 { 348 {
349 switch (BUF_FORMAT (buf)) 349 switch (BUF_FORMAT (buf))
350 { 350 {
351 case FORMAT_DEFAULT: 351 case FORMAT_DEFAULT:
352 return intbyte_first_byte_p (*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x)); 352 return ibyte_first_byte_p (*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x));
353 case FORMAT_16_BIT_FIXED: 353 case FORMAT_16_BIT_FIXED:
354 return ((x - 1) & 1) == 0; 354 return ((x - 1) & 1) == 0;
355 case FORMAT_32_BIT_FIXED: 355 case FORMAT_32_BIT_FIXED:
356 return ((x - 1) & 3) == 0; 356 return ((x - 1) & 3) == 0;
357 default: 357 default:
411 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \ 411 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \
412 switch (BUF_FORMAT (buf)) \ 412 switch (BUF_FORMAT (buf)) \
413 { \ 413 { \
414 case FORMAT_DEFAULT: \ 414 case FORMAT_DEFAULT: \
415 { \ 415 { \
416 Intbyte *VBB_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ 416 Ibyte *VBB_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \
417 while (!intbyte_first_byte_p (*VBB_ptr)) \ 417 while (!ibyte_first_byte_p (*VBB_ptr)) \
418 VBB_ptr--, (x)--; \ 418 VBB_ptr--, (x)--; \
419 } \ 419 } \
420 break; \ 420 break; \
421 case FORMAT_16_BIT_FIXED: \ 421 case FORMAT_16_BIT_FIXED: \
422 if (((x - 1) & 1) != 0) \ 422 if (((x - 1) & 1) != 0) \
443 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \ 443 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \
444 switch (BUF_FORMAT (buf)) \ 444 switch (BUF_FORMAT (buf)) \
445 { \ 445 { \
446 case FORMAT_DEFAULT: \ 446 case FORMAT_DEFAULT: \
447 { \ 447 { \
448 Intbyte *VBF_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ 448 Ibyte *VBF_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \
449 while (!intbyte_first_byte_p (*VBF_ptr)) \ 449 while (!ibyte_first_byte_p (*VBF_ptr)) \
450 VBF_ptr++, (x)++; \ 450 VBF_ptr++, (x)++; \
451 } \ 451 } \
452 break; \ 452 break; \
453 case FORMAT_16_BIT_FIXED: \ 453 case FORMAT_16_BIT_FIXED: \
454 if (((x - 1) & 1) != 0) \ 454 if (((x - 1) & 1) != 0) \
489 VALIDATE_BYTEBPOS_FORWARD (buf, x); \ 489 VALIDATE_BYTEBPOS_FORWARD (buf, x); \
490 } while (0) 490 } while (0)
491 491
492 /* Given a byte position (assumed to point at the beginning of a 492 /* Given a byte position (assumed to point at the beginning of a
493 character), modify that value so it points to the beginning of the 493 character), modify that value so it points to the beginning of the
494 previous character. Unlike for DEC_CHARPTR(), we can do all the 494 previous character. Unlike for DEC_IBYTEPTR(), we can do all the
495 assert()s because there are sentinels at the beginning of the gap and 495 assert()s because there are sentinels at the beginning of the gap and
496 the end of the buffer. 496 the end of the buffer.
497 497
498 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this 498 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this
499 crap reduces down to simply (x)--. */ 499 crap reduces down to simply (x)--. */
824 /*----------------------------------------------------------------------*/ 824 /*----------------------------------------------------------------------*/
825 825
826 /* Convert the address of a byte in the buffer into a position. */ 826 /* Convert the address of a byte in the buffer into a position. */
827 DECLARE_INLINE_HEADER ( 827 DECLARE_INLINE_HEADER (
828 Bytebpos 828 Bytebpos
829 BYTE_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr) 829 BYTE_BUF_PTR_BYTE_POS (struct buffer *buf, Ibyte *ptr)
830 ) 830 )
831 { 831 {
832 Bytebpos retval = (ptr - buf->text->beg + 1 832 Bytebpos retval = (ptr - buf->text->beg + 1
833 - ((ptr - buf->text->beg + 1) > buf->text->gpt 833 - ((ptr - buf->text->beg + 1) > buf->text->gpt
834 ? buf->text->gap_size : (Bytebpos) 0)); 834 ? buf->text->gap_size : (Bytebpos) 0));
839 #define BUF_PTR_BYTE_POS(buf, ptr) \ 839 #define BUF_PTR_BYTE_POS(buf, ptr) \
840 bytebpos_to_charbpos (buf, BYTE_BUF_PTR_BYTE_POS (buf, ptr)) 840 bytebpos_to_charbpos (buf, BYTE_BUF_PTR_BYTE_POS (buf, ptr))
841 841
842 /* Address of byte at position POS in buffer. */ 842 /* Address of byte at position POS in buffer. */
843 DECLARE_INLINE_HEADER ( 843 DECLARE_INLINE_HEADER (
844 Intbyte * 844 Ibyte *
845 BYTE_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos) 845 BYTE_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos)
846 ) 846 )
847 { 847 {
848 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); 848 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos);
849 return BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos); 849 return BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos);
852 #define BUF_BYTE_ADDRESS(buf, pos) \ 852 #define BUF_BYTE_ADDRESS(buf, pos) \
853 BYTE_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos)) 853 BYTE_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos))
854 854
855 /* Address of byte before position POS in buffer. */ 855 /* Address of byte before position POS in buffer. */
856 DECLARE_INLINE_HEADER ( 856 DECLARE_INLINE_HEADER (
857 Intbyte * 857 Ibyte *
858 BYTE_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos) 858 BYTE_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos)
859 ) 859 )
860 { 860 {
861 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); 861 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos);
862 return (buf->text->beg + 862 return (buf->text->beg +
872 /*----------------------------------------------------------------------*/ 872 /*----------------------------------------------------------------------*/
873 873
874 /* The character at position POS in buffer. */ 874 /* The character at position POS in buffer. */
875 875
876 #define BYTE_BUF_FETCH_CHAR(buf, pos) \ 876 #define BYTE_BUF_FETCH_CHAR(buf, pos) \
877 charptr_emchar_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf), \ 877 itext_ichar_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf), \
878 wrap_buffer (buf)) 878 wrap_buffer (buf))
879 #define BUF_FETCH_CHAR(buf, pos) \ 879 #define BUF_FETCH_CHAR(buf, pos) \
880 BYTE_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos)) 880 BYTE_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos))
881 881
882 /* The "raw value" of the character at position POS in buffer. 882 /* The "raw value" of the character at position POS in buffer.
883 See emchar_to_raw(). */ 883 See ichar_to_raw(). */
884 884
885 #define BYTE_BUF_FETCH_CHAR_RAW(buf, pos) \ 885 #define BYTE_BUF_FETCH_CHAR_RAW(buf, pos) \
886 charptr_emchar_raw_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf)) 886 itext_ichar_raw_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf))
887 #define BUF_FETCH_CHAR_RAW(buf, pos) \ 887 #define BUF_FETCH_CHAR_RAW(buf, pos) \
888 BYTE_BUF_FETCH_CHAR_RAW (buf, charbpos_to_bytebpos (buf, pos)) 888 BYTE_BUF_FETCH_CHAR_RAW (buf, charbpos_to_bytebpos (buf, pos))
889 889
890 /* The character at position POS in buffer, as a string. This is 890 /* The character at position POS in buffer, as a string. This is
891 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos)) 891 equivalent to set_itext_ichar (str, BUF_FETCH_CHAR (buf, pos))
892 but is faster for Mule. */ 892 but is faster for Mule. */
893 893
894 # define BYTE_BUF_CHARPTR_COPY_EMCHAR(buf, pos, str) \ 894 # define BYTE_BUF_ITEXT_COPY_ICHAR(buf, pos, str) \
895 (BUF_FORMAT (buf) == FORMAT_DEFAULT ? \ 895 (BUF_FORMAT (buf) == FORMAT_DEFAULT ? \
896 charptr_copy_emchar (BYTE_BUF_BYTE_ADDRESS (buf, pos), str) : \ 896 itext_copy_ichar (BYTE_BUF_BYTE_ADDRESS (buf, pos), str) : \
897 set_charptr_emchar (str, BYTE_BUF_FETCH_CHAR (buf, pos))) 897 set_itext_ichar (str, BYTE_BUF_FETCH_CHAR (buf, pos)))
898 #define BUF_CHARPTR_COPY_EMCHAR(buf, pos, str) \ 898 #define BUF_ITEXT_COPY_ICHAR(buf, pos, str) \
899 BYTE_BUF_CHARPTR_COPY_EMCHAR (buf, charbpos_to_bytebpos (buf, pos), str) 899 BYTE_BUF_ITEXT_COPY_ICHAR (buf, charbpos_to_bytebpos (buf, pos), str)
900 900
901 901
902 /************************************************************************/ 902 /************************************************************************/
903 /* */ 903 /* */
904 /* higher-level buffer-position functions */ 904 /* higher-level buffer-position functions */
1057 1057
1058 while (pos < to) 1058 while (pos < to)
1059 { 1059 {
1060 Bytebpos ceil = BYTE_BUF_CEILING_OF (buf, pos); 1060 Bytebpos ceil = BYTE_BUF_CEILING_OF (buf, pos);
1061 ceil = min (to, ceil); 1061 ceil = min (to, ceil);
1062 process_intbyte_string (BYTE_BUF_BYTE_ADDRESS (buf, pos), ceil - pos); 1062 process_ibyte_string (BYTE_BUF_BYTE_ADDRESS (buf, pos), ceil - pos);
1063 pos = ceil; 1063 pos = ceil;
1064 } 1064 }
1065 } 1065 }
1066 1066
1067 Currently there will be at most two iterations in the loop, but it is 1067 Currently there will be at most two iterations in the loop, but it is
1113 limits respected, you need to impose them yourself. 1113 limits respected, you need to impose them yourself.
1114 1114
1115 NOTE: This must be surrounded with braces! */ 1115 NOTE: This must be surrounded with braces! */
1116 1116
1117 #define BUFFER_TEXT_LOOP(buf, pos, len, runptr, runlen) \ 1117 #define BUFFER_TEXT_LOOP(buf, pos, len, runptr, runlen) \
1118 Intbyte *runptr; \ 1118 Ibyte *runptr; \
1119 Bytecount runlen; \ 1119 Bytecount runlen; \
1120 Bytebpos BTL_pos = (pos); \ 1120 Bytebpos BTL_pos = (pos); \
1121 Bytebpos BTL_len = (len); \ 1121 Bytebpos BTL_len = (len); \
1122 for (runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ 1122 for (runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \
1123 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ 1123 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \
1152 char *r_alloc (unsigned char **, size_t); 1152 char *r_alloc (unsigned char **, size_t);
1153 char *r_re_alloc (unsigned char **, size_t); 1153 char *r_re_alloc (unsigned char **, size_t);
1154 void r_alloc_free (unsigned char **); 1154 void r_alloc_free (unsigned char **);
1155 1155
1156 #define BUFFER_ALLOC(data, size) \ 1156 #define BUFFER_ALLOC(data, size) \
1157 ((Intbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte))) 1157 ((Ibyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte)))
1158 #define BUFFER_REALLOC(data, size) \ 1158 #define BUFFER_REALLOC(data, size) \
1159 ((Intbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte))) 1159 ((Ibyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte)))
1160 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data)) 1160 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
1161 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) 1161 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
1162 1162
1163 #else /* !REL_ALLOC */ 1163 #else /* !REL_ALLOC */
1164 1164
1165 #define BUFFER_ALLOC(data,size)\ 1165 #define BUFFER_ALLOC(data,size)\
1166 (data = xnew_array (Intbyte, size)) 1166 (data = xnew_array (Ibyte, size))
1167 #define BUFFER_REALLOC(data,size)\ 1167 #define BUFFER_REALLOC(data,size)\
1168 ((Intbyte *) xrealloc (data, (size) * sizeof(Intbyte))) 1168 ((Ibyte *) xrealloc (data, (size) * sizeof(Ibyte)))
1169 /* Avoid excess parentheses, or syntax errors may rear their heads. */ 1169 /* Avoid excess parentheses, or syntax errors may rear their heads. */
1170 #define BUFFER_FREE(data) xfree (data) 1170 #define BUFFER_FREE(data) xfree (data)
1171 #define R_ALLOC_DECLARE(var,data) 1171 #define R_ALLOC_DECLARE(var,data)
1172 1172
1173 #endif /* !REL_ALLOC */ 1173 #endif /* !REL_ALLOC */
1185 already guaranteed that the character values are all in the range 1185 already guaranteed that the character values are all in the range
1186 0 - 255. Bad lossage will happen otherwise. */ 1186 0 - 255. Bad lossage will happen otherwise. */
1187 1187
1188 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) 1188 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric)
1189 DECLARE_INLINE_HEADER ( 1189 DECLARE_INLINE_HEADER (
1190 Emchar 1190 Ichar
1191 TRT_TABLE_OF (Lisp_Object table, Emchar ch) 1191 TRT_TABLE_OF (Lisp_Object table, Ichar ch)
1192 ) 1192 )
1193 { 1193 {
1194 Lisp_Object TRT_char; 1194 Lisp_Object TRT_char;
1195 TRT_char = get_char_table (ch, table); 1195 TRT_char = get_char_table (ch, table);
1196 if (NILP (TRT_char)) 1196 if (NILP (TRT_char))
1217 1217
1218 /* 1 if CH is upper case. */ 1218 /* 1 if CH is upper case. */
1219 1219
1220 DECLARE_INLINE_HEADER ( 1220 DECLARE_INLINE_HEADER (
1221 int 1221 int
1222 UPPERCASEP (struct buffer *buf, Emchar ch) 1222 UPPERCASEP (struct buffer *buf, Ichar ch)
1223 ) 1223 )
1224 { 1224 {
1225 return DOWNCASE_TABLE_OF (buf, ch) != ch; 1225 return DOWNCASE_TABLE_OF (buf, ch) != ch;
1226 } 1226 }
1227 1227
1228 /* 1 if CH is lower case. */ 1228 /* 1 if CH is lower case. */
1229 1229
1230 DECLARE_INLINE_HEADER ( 1230 DECLARE_INLINE_HEADER (
1231 int 1231 int
1232 LOWERCASEP (struct buffer *buf, Emchar ch) 1232 LOWERCASEP (struct buffer *buf, Ichar ch)
1233 ) 1233 )
1234 { 1234 {
1235 return (UPCASE_TABLE_OF (buf, ch) != ch && 1235 return (UPCASE_TABLE_OF (buf, ch) != ch &&
1236 DOWNCASE_TABLE_OF (buf, ch) == ch); 1236 DOWNCASE_TABLE_OF (buf, ch) == ch);
1237 } 1237 }
1238 1238
1239 /* 1 if CH is neither upper nor lower case. */ 1239 /* 1 if CH is neither upper nor lower case. */
1240 1240
1241 DECLARE_INLINE_HEADER ( 1241 DECLARE_INLINE_HEADER (
1242 int 1242 int
1243 NOCASEP (struct buffer *buf, Emchar ch) 1243 NOCASEP (struct buffer *buf, Ichar ch)
1244 ) 1244 )
1245 { 1245 {
1246 return UPCASE_TABLE_OF (buf, ch) == ch; 1246 return UPCASE_TABLE_OF (buf, ch) == ch;
1247 } 1247 }
1248 1248
1249 /* Upcase a character, or make no change if that cannot be done. */ 1249 /* Upcase a character, or make no change if that cannot be done. */
1250 1250
1251 DECLARE_INLINE_HEADER ( 1251 DECLARE_INLINE_HEADER (
1252 Emchar 1252 Ichar
1253 UPCASE (struct buffer *buf, Emchar ch) 1253 UPCASE (struct buffer *buf, Ichar ch)
1254 ) 1254 )
1255 { 1255 {
1256 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; 1256 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
1257 } 1257 }
1258 1258