X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.h;h=2fffa70d600b0fe52ffe3fbd915bc9079edc6e57;hb=1d690aa7ebf4f6615db7796c9d1b4d6d15659de6;hp=7ed84ed7791cecabca4b26cb0507a5041dbc241b;hpb=c8aa261a7bf3eb1389d2e018be1d715f73cacd66;p=chise%2Fxemacs-chise.git- diff --git a/src/buffer.h b/src/buffer.h index 7ed84ed..2fffa70 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -35,6 +35,9 @@ Boston, MA 02111-1307, USA. */ #include "character.h" #include "multibyte.h" +#include "casetab.h" +#include "chartab.h" + /************************************************************************/ /* */ /* definition of Lisp buffer object */ @@ -137,6 +140,9 @@ struct buffer int face_change; /* This is set when a change in how the text should be displayed (e.g., font, color) is made. */ + /* Whether buffer specific face is specified. */ + int buffer_local_face_property; + /* change data indicating what portion of the text has changed since the last time this was reset. Used by redisplay. Logically we should keep this with the text structure, but @@ -201,7 +207,7 @@ struct buffer int modtime; /* the value of text->modiff at the last auto-save. */ - int auto_save_modified; + long auto_save_modified; /* The time at which we detected a failure to auto-save, Or -1 if we didn't have a failure. */ @@ -318,8 +324,8 @@ for (mps_bufcons = Qunbound, \ /*----------------------------------------------------------------------*/ /* Convert the address of a byte in the buffer into a position. */ -INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); -INLINE Bytind +INLINE_HEADER Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); +INLINE_HEADER Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) { return (ptr - buf->text->beg + 1 @@ -331,8 +337,8 @@ BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) /* Address of byte at position POS in buffer. */ -INLINE Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); -INLINE Bufbyte * +INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); +INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) { return (buf->text->beg + @@ -344,8 +350,8 @@ BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos)) /* Address of byte before position POS in buffer. */ -INLINE Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); -INLINE Bufbyte * +INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); +INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) { return (buf->text->beg + @@ -360,8 +366,8 @@ BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) /* Converting between byte indices and memory indices */ /*----------------------------------------------------------------------*/ -INLINE int valid_memind_p (struct buffer *buf, Memind x); -INLINE int +INLINE_HEADER int valid_memind_p (struct buffer *buf, Memind x); +INLINE_HEADER int valid_memind_p (struct buffer *buf, Memind x) { return ((x >= 1 && x <= (Memind) buf->text->gpt) || @@ -369,16 +375,16 @@ valid_memind_p (struct buffer *buf, Memind x) x <= (Memind) (buf->text->z + buf->text->gap_size))); } -INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x); -INLINE Memind +INLINE_HEADER Memind bytind_to_memind (struct buffer *buf, Bytind x); +INLINE_HEADER Memind bytind_to_memind (struct buffer *buf, Bytind x) { return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); } -INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); -INLINE Bytind +INLINE_HEADER Bytind memind_to_bytind (struct buffer *buf, Memind x); +INLINE_HEADER Bytind memind_to_bytind (struct buffer *buf, Memind x) { #ifdef ERROR_CHECK_BUFPOS @@ -598,16 +604,16 @@ memind_to_bytind (struct buffer *buf, Memind x) VALIDATE_BYTIND_BACKWARD (buf, x); \ } while (0) -INLINE Bytind prev_bytind (struct buffer *buf, Bytind x); -INLINE Bytind +INLINE_HEADER Bytind prev_bytind (struct buffer *buf, Bytind x); +INLINE_HEADER Bytind prev_bytind (struct buffer *buf, Bytind x) { DEC_BYTIND (buf, x); return x; } -INLINE Bytind next_bytind (struct buffer *buf, Bytind x); -INLINE Bytind +INLINE_HEADER Bytind next_bytind (struct buffer *buf, Bytind x); +INLINE_HEADER Bytind next_bytind (struct buffer *buf, Bytind x) { INC_BYTIND (buf, x); @@ -671,8 +677,8 @@ Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x); extern short three_to_one_table[]; #endif -INLINE int real_bufpos_to_bytind (struct buffer *buf, Bufpos x); -INLINE int +INLINE_HEADER int real_bufpos_to_bytind (struct buffer *buf, Bufpos x); +INLINE_HEADER int real_bufpos_to_bytind (struct buffer *buf, Bufpos x) { if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) @@ -688,8 +694,8 @@ real_bufpos_to_bytind (struct buffer *buf, Bufpos x) return bufpos_to_bytind_func (buf, x); } -INLINE int real_bytind_to_bufpos (struct buffer *buf, Bytind x); -INLINE int +INLINE_HEADER int real_bytind_to_bufpos (struct buffer *buf, Bytind x); +INLINE_HEADER int real_bytind_to_bufpos (struct buffer *buf, Bytind x) { if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) @@ -770,8 +776,8 @@ Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x); DATA, (ptr, len), // input data is a fixed buffer of size len ALLOCA, (ptr, len), // output data is in a alloca()ed buffer of size len MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len - C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output. - C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output. + C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output + C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output C_STRING, ptr, // equivalent to DATA, (ptr, strlen (ptr) + 1) on input LISP_STRING, string, // input or output is a Lisp_Object of type string LISP_BUFFER, buffer, // output is written to (point) in lisp buffer @@ -897,7 +903,7 @@ typedef enum dfc_conversion_type dfc_conversion_type; /* WARNING: These use a static buffer. This can lead to disaster if these functions are not used *very* carefully. Another reason to only use - TO_EXTERNAL_FORMATf() and TO_INTERNAL_FORMAT(). */ + TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */ void dfc_convert_to_external_format (dfc_conversion_type source_type, dfc_conversion_data *source, @@ -976,16 +982,17 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type, } while (0) /* Assign to the `sink' lvalue(s) using the converted data. */ +typedef union { char c; void *p; } *dfc_aliasing_voidpp; #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \ void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \ memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ - (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ + ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \ (DFC_CPP_CDR sink) = dfc_sink.data.len; \ } while (0) #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \ void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \ memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ - (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ + ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \ (DFC_CPP_CDR sink) = dfc_sink.data.len; \ } while (0) #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \ @@ -1012,170 +1019,29 @@ dfc_convert_to_internal_format (dfc_conversion_type source_type, argument to TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */ #define Qnative Qfile_name -#define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, ptr_out) do \ -{ \ - Extcount gcceda_ignored_len; \ - CONST Bufbyte *gcceda_ptr_in = (CONST Bufbyte *) (ptr); \ - Extbyte *gcceda_ptr_out; \ - \ - GET_CHARPTR_EXT_DATA_ALLOCA (gcceda_ptr_in, \ - strlen ((char *) gcceda_ptr_in), \ - fmt, \ - gcceda_ptr_out, \ - gcceda_ignored_len); \ - (ptr_out) = (char *) gcceda_ptr_out; \ -} while (0) - -#define GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out) -#define GET_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out) - -#define GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out) -#define GET_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out) - -#define GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out) -#define GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out) - -/* Maybe convert external charptr's data into internal format and store - the result in alloca()'ed space. - - You may wonder why this is written in this fashion and not as a - function call. With a little trickery it could certainly be - written this way, but it won't work because of those DAMN GCC WANKERS - who couldn't be bothered to handle alloca() properly on the x86 - architecture. (If you put a call to alloca() in the argument to - a function call, the stack space gets allocated right in the - middle of the arguments to the function call and you are unbelievably - hosed.) */ - -#ifdef MULE - -#define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ -{ \ - Extcount gcida_len_in = (Extcount) (len); \ - Bytecount gcida_len_out; \ - CONST Extbyte *gcida_ptr_in = (ptr); \ - Bufbyte *gcida_ptr_out = \ - convert_from_external_format (gcida_ptr_in, gcida_len_in, \ - &gcida_len_out, fmt); \ - /* If the new string is identical to the old (will be the case most \ - of the time), just return the same string back. This saves \ - on alloca()ing, which can be useful on C alloca() machines and \ - on stack-space-challenged environments. */ \ - \ - if (gcida_len_in == gcida_len_out && \ - !memcmp (gcida_ptr_in, gcida_ptr_out, gcida_len_out)) \ - { \ - (ptr_out) = (Bufbyte *) gcida_ptr_in; \ - } \ - else \ - { \ - (ptr_out) = (Extbyte *) alloca (1 + gcida_len_out); \ - memcpy ((void *) ptr_out, gcida_ptr_out, 1 + gcida_len_out); \ - } \ - (len_out) = gcida_len_out; \ -} while (0) - -#else /* ! MULE */ - -#define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ -{ \ - (ptr_out) = (Bufbyte *) (ptr); \ - (len_out) = (Bytecount) (len); \ -} while (0) - -#endif /* ! MULE */ - -#define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, ptr_out) do \ -{ \ - Bytecount gccida_ignored_len; \ - CONST Extbyte *gccida_ptr_in = (CONST Extbyte *) (ptr); \ - Bufbyte *gccida_ptr_out; \ - \ - GET_CHARPTR_INT_DATA_ALLOCA (gccida_ptr_in, \ - strlen ((char *) gccida_ptr_in), \ - fmt, \ - gccida_ptr_out, \ - gccida_ignored_len); \ - (ptr_out) = gccida_ptr_out; \ -} while (0) - -#define GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out) -#define GET_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out) - -#define GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out) -#define GET_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out) - -#define GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \ - GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out) -#define GET_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ - GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out) - - -/* Maybe convert Lisp string's data into ext-format and store the result in - alloca()'ed space. - - You may wonder why this is written in this fashion and not as a - function call. With a little trickery it could certainly be - written this way, but it won't work because of those DAMN GCC WANKERS - who couldn't be bothered to handle alloca() properly on the x86 - architecture. (If you put a call to alloca() in the argument to - a function call, the stack space gets allocated right in the - middle of the arguments to the function call and you are unbelievably - hosed.) */ - -#define GET_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out, len_out) do \ -{ \ - Extcount gseda_len_out; \ - struct Lisp_String *gseda_s = XSTRING (s); \ - Extbyte * gseda_ptr_out = \ - convert_to_external_format (string_data (gseda_s), \ - string_length (gseda_s), \ - &gseda_len_out, fmt); \ - (ptr_out) = (Extbyte *) alloca (1 + gseda_len_out); \ - memcpy ((void *) ptr_out, gseda_ptr_out, 1 + gseda_len_out); \ - (len_out) = gseda_len_out; \ -} while (0) - - -#define GET_C_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out) do \ -{ \ - Extcount gcseda_ignored_len; \ - Extbyte *gcseda_ptr_out; \ - \ - GET_STRING_EXT_DATA_ALLOCA (s, fmt, gcseda_ptr_out, \ - gcseda_ignored_len); \ - (ptr_out) = (char *) gcseda_ptr_out; \ -} while (0) - -#define GET_STRING_BINARY_DATA_ALLOCA(s, ptr_out, len_out) \ - GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out, len_out) -#define GET_C_STRING_BINARY_DATA_ALLOCA(s, ptr_out) \ - GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out) - -#define GET_STRING_FILENAME_DATA_ALLOCA(s, ptr_out, len_out) \ - GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out, len_out) -#define GET_C_STRING_FILENAME_DATA_ALLOCA(s, ptr_out) \ - GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out) - -#define GET_STRING_OS_DATA_ALLOCA(s, ptr_out, len_out) \ - GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out, len_out) -#define GET_C_STRING_OS_DATA_ALLOCA(s, ptr_out) \ - GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out) +#if defined (WIN32_NATIVE) || defined (CYGWIN) +/* #### kludge!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + Remove this as soon as my Mule code is integrated. */ +#define Qmswindows_tstr Qnative +#endif -#define GET_STRING_CTEXT_DATA_ALLOCA(s, ptr_out, len_out) \ - GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out, len_out) -#define GET_C_STRING_CTEXT_DATA_ALLOCA(s, ptr_out) \ - GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out) +/* More stand-ins */ +#define Qcommand_argument_encoding Qnative +#define Qenvironment_variable_encoding Qnative + +/* Convenience macros for extremely common invocations */ +#define C_STRING_TO_EXTERNAL(in, out, coding_system) \ + TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, coding_system) +#define C_STRING_TO_EXTERNAL_MALLOC(in, out, coding_system) \ + TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, coding_system) +#define EXTERNAL_TO_C_STRING(in, out, coding_system) \ + TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, coding_system) +#define EXTERNAL_TO_C_STRING_MALLOC(in, out, coding_system) \ + TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, coding_system) +#define LISP_STRING_TO_EXTERNAL(in, out, coding_system) \ + TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_ALLOCA, out, coding_system) +#define LISP_STRING_TO_EXTERNAL_MALLOC(in, out, coding_system) \ + TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_MALLOC, out, coding_system) /************************************************************************/ @@ -1408,22 +1274,22 @@ int beginning_of_line_p (struct buffer *b, Bufpos pt); /* from insdel.c */ void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos); void find_charsets_in_bufbyte_string (Charset_ID *charsets, - CONST Bufbyte *str, + const Bufbyte *str, Bytecount len); -void find_charsets_in_emchar_string (Charset_ID *charsets, - CONST Emchar *str, - Charcount len); -int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len); -int emchar_string_displayed_columns (CONST Emchar *str, Charcount len); -void convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, - Bytecount len, - Emchar_dynarr *dyn); -Charcount convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, +void find_charsets_in_charc_string (Charset_ID *charsets, + const Charc *str, + Charcount len); +int bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len); +int charc_string_displayed_columns (const Charc *str, Charcount len); +void convert_bufbyte_string_into_charc_dynarr (const Bufbyte *str, + Bytecount len, + Charc_dynarr *dyn); +Charcount convert_bufbyte_string_into_emchar_string (const Bufbyte *str, Bytecount len, Emchar *arr); -void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, - Bufbyte_dynarr *dyn); -Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, +void convert_charc_string_into_bufbyte_dynarr (Charc *arr, int nels, + Bufbyte_dynarr *dyn); +Bufbyte *convert_charc_string_into_malloced_string (Charc *arr, int nels, Bytecount *len_out); /* from marker.c */ void init_buffer_markers (struct buffer *b); @@ -1506,59 +1372,38 @@ int map_over_sharing_buffers (struct buffer *buf, already guaranteed that the character values are all in the range 0 - 255. Bad lossage will happen otherwise. */ -# define MAKE_TRT_TABLE() Fmake_string (make_int (256), make_char (0)) -# define TRT_TABLE_AS_STRING(table) XSTRING_DATA (table) -# define TRT_TABLE_CHAR_1(table, ch) \ - string_char (XSTRING (table), (Charcount) ch) -# define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ - set_string_char (XSTRING (table), (Charcount) ch1, ch2) - -#ifdef MULE -# define MAKE_MIRROR_TRT_TABLE() make_opaque (OPAQUE_CLEAR, 256) -# define MIRROR_TRT_TABLE_AS_STRING(table) ((Bufbyte *) XOPAQUE_DATA (table)) -# define MIRROR_TRT_TABLE_CHAR_1(table, ch) \ - ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch])) -# define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \ - (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2)) -#endif - -# define IN_TRT_TABLE_DOMAIN(c) (((EMACS_UINT) (c)) <= 255) - -#ifdef MULE -#define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \ - MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table) -#define MIRROR_UPCASE_TABLE_AS_STRING(buf) \ - MIRROR_TRT_TABLE_AS_STRING (buf->mirror_upcase_table) -#define MIRROR_CANON_TABLE_AS_STRING(buf) \ - MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_canon_table) -#define MIRROR_EQV_TABLE_AS_STRING(buf) \ - MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_eqv_table) -#else -#define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \ - TRT_TABLE_AS_STRING (buf->downcase_table) -#define MIRROR_UPCASE_TABLE_AS_STRING(buf) \ - TRT_TABLE_AS_STRING (buf->upcase_table) -#define MIRROR_CANON_TABLE_AS_STRING(buf) \ - TRT_TABLE_AS_STRING (buf->case_canon_table) -#define MIRROR_EQV_TABLE_AS_STRING(buf) \ - TRT_TABLE_AS_STRING (buf->case_eqv_table) -#endif +#define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) +INLINE_HEADER Emchar TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar c); +INLINE_HEADER Emchar +TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar ch) +{ + Lisp_Object TRT_char; + TRT_char = get_char_table (ch, XCHAR_TABLE (table)); + if (NILP (TRT_char)) + return ch; + else + return XCHAR (TRT_char); +} +#define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ + Fput_char_table (make_char (ch1), make_char (ch2), table); -INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); -INLINE Emchar +INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); +INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c) { - return IN_TRT_TABLE_DOMAIN (c) ? TRT_TABLE_CHAR_1 (trt, c) : c; + return TRT_TABLE_CHAR_1 (trt, c); } /* Macros used below. */ -#define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c) -#define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c) +#define DOWNCASE_TABLE_OF(buf, c) \ + TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (buf->case_table), c) +#define UPCASE_TABLE_OF(buf, c) \ + TRT_TABLE_OF (XCASE_TABLE_UPCASE (buf->case_table), c) /* 1 if CH is upper case. */ -INLINE int UPPERCASEP (struct buffer *buf, Emchar ch); -INLINE int +INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch); +INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch) { return DOWNCASE_TABLE_OF (buf, ch) != ch; @@ -1566,8 +1411,8 @@ UPPERCASEP (struct buffer *buf, Emchar ch) /* 1 if CH is lower case. */ -INLINE int LOWERCASEP (struct buffer *buf, Emchar ch); -INLINE int +INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch); +INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch) { return (UPCASE_TABLE_OF (buf, ch) != ch && @@ -1576,8 +1421,8 @@ LOWERCASEP (struct buffer *buf, Emchar ch) /* 1 if CH is neither upper nor lower case. */ -INLINE int NOCASEP (struct buffer *buf, Emchar ch); -INLINE int +INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch); +INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch) { return UPCASE_TABLE_OF (buf, ch) == ch; @@ -1585,8 +1430,8 @@ NOCASEP (struct buffer *buf, Emchar ch) /* Upcase a character, or make no change if that cannot be done. */ -INLINE Emchar UPCASE (struct buffer *buf, Emchar ch); -INLINE Emchar +INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch); +INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch) { return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; @@ -1600,4 +1445,60 @@ UPCASE (struct buffer *buf, Emchar ch) #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) +/************************************************************************/ +/* Lisp string representation convenience functions */ +/************************************************************************/ +/* Because the representation of internally formatted data is subject to change, + It's bad style to do something like strcmp (XSTRING_DATA (s), "foo") + Instead, use the portable: bufbyte_strcmp (XSTRING_DATA (s), "foo") + or bufbyte_memcmp (XSTRING_DATA (s), "foo", 3) */ + +/* Like strcmp, except first arg points at internally formatted data, + while the second points at a string of only ASCII chars. */ +INLINE_HEADER int +bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string); +INLINE_HEADER int +bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string) +{ +#ifdef MULE + while (1) + { + int diff; + type_checking_assert (BYTE_ASCII_P (*ascii_string)); + if ((diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string) != 0) + return diff; + if (*ascii_string == '\0') + return 0; + ascii_string++; + INC_CHARPTR (bp); + } +#else + return strcmp ((char *)bp, ascii_string); +#endif +} + + +/* Like memcmp, except first arg points at internally formatted data, + while the second points at a string of only ASCII chars. */ +INLINE_HEADER int +bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len); +INLINE_HEADER int +bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len) +{ +#ifdef MULE + while (len--) + { + int diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string; + type_checking_assert (BYTE_ASCII_P (*ascii_string)); + if (diff != 0) + return diff; + ascii_string++; + INC_CHARPTR (bp); + } + return 0; +#else + return memcmp (bp, ascii_string, len); +#endif +} + #endif /* INCLUDED_buffer_h_ */