diff options
| author | Kenichi Handa | 2008-11-08 13:02:38 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2008-11-08 13:02:38 +0000 |
| commit | ee107a899db8545e2c29cbf0d3d009c4a6aa4953 (patch) | |
| tree | eac8217a11c228236d86c44862cb4c8958d88123 /src/character.c | |
| parent | d73b58b55dc5bd13523d1876c7cb6a464097eb24 (diff) | |
| download | emacs-ee107a899db8545e2c29cbf0d3d009c4a6aa4953.tar.gz emacs-ee107a899db8545e2c29cbf0d3d009c4a6aa4953.zip | |
(Fget_byte): New function.
(syms_of_character): Defsubr Fget_byte.
Diffstat (limited to 'src/character.c')
| -rw-r--r-- | src/character.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/character.c b/src/character.c index c237d8fa405..38d4f6ac510 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -1027,6 +1027,63 @@ usage: (char-resolve-modifiers CHAR) */) | |||
| 1027 | return make_number (char_resolve_modifier_mask (c)); | 1027 | return make_number (char_resolve_modifier_mask (c)); |
| 1028 | } | 1028 | } |
| 1029 | 1029 | ||
| 1030 | DEFUN ("get-byte", Fget_byte, Sget_byte, 0, 2, 0, | ||
| 1031 | doc: /* Return a byte value of a character at point. | ||
| 1032 | Optional 1st arg POSITION, if non-nil, is a position of a character to get | ||
| 1033 | a byte value. | ||
| 1034 | Optional 2nd arg STRING, if non-nil, is a string of which first | ||
| 1035 | character is a target to get a byte value. In this case, POSITION, if | ||
| 1036 | non-nil, is an index of a target character in the string. | ||
| 1037 | |||
| 1038 | If the current buffer (or STRING) is multibyte, and the target | ||
| 1039 | character is not ASCII nor 8-bit character, an error is signalled. */) | ||
| 1040 | (position, string) | ||
| 1041 | Lisp_Object position, string; | ||
| 1042 | { | ||
| 1043 | int c; | ||
| 1044 | EMACS_INT pos; | ||
| 1045 | unsigned char *p; | ||
| 1046 | |||
| 1047 | if (NILP (string)) | ||
| 1048 | { | ||
| 1049 | if (NILP (position)) | ||
| 1050 | { | ||
| 1051 | p = PT_ADDR; | ||
| 1052 | } | ||
| 1053 | else | ||
| 1054 | { | ||
| 1055 | CHECK_NUMBER_COERCE_MARKER (position); | ||
| 1056 | if (XINT (position) < BEGV || XINT (position) >= ZV) | ||
| 1057 | args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); | ||
| 1058 | pos = XFASTINT (position); | ||
| 1059 | p = CHAR_POS_ADDR (pos); | ||
| 1060 | } | ||
| 1061 | } | ||
| 1062 | else | ||
| 1063 | { | ||
| 1064 | CHECK_STRING (string); | ||
| 1065 | if (NILP (position)) | ||
| 1066 | { | ||
| 1067 | p = SDATA (string); | ||
| 1068 | } | ||
| 1069 | else | ||
| 1070 | { | ||
| 1071 | CHECK_NATNUM (position); | ||
| 1072 | if (XINT (position) >= SCHARS (string)) | ||
| 1073 | args_out_of_range (string, position); | ||
| 1074 | pos = XFASTINT (position); | ||
| 1075 | p = SDATA (string) + string_char_to_byte (string, pos); | ||
| 1076 | } | ||
| 1077 | } | ||
| 1078 | c = STRING_CHAR (p, 0); | ||
| 1079 | if (CHAR_BYTE8_P (c)) | ||
| 1080 | c = CHAR_TO_BYTE8 (c); | ||
| 1081 | else if (! ASCII_CHAR_P (c)) | ||
| 1082 | error ("Not an ASCII nor an 8-bit character: %d", c); | ||
| 1083 | return make_number (c); | ||
| 1084 | } | ||
| 1085 | |||
| 1086 | |||
| 1030 | void | 1087 | void |
| 1031 | init_character_once () | 1088 | init_character_once () |
| 1032 | { | 1089 | { |
| @@ -1054,6 +1111,7 @@ syms_of_character () | |||
| 1054 | defsubr (&Sstring); | 1111 | defsubr (&Sstring); |
| 1055 | defsubr (&Sunibyte_string); | 1112 | defsubr (&Sunibyte_string); |
| 1056 | defsubr (&Schar_resolve_modifiers); | 1113 | defsubr (&Schar_resolve_modifiers); |
| 1114 | defsubr (&Sget_byte); | ||
| 1057 | 1115 | ||
| 1058 | DEFVAR_LISP ("translation-table-vector", &Vtranslation_table_vector, | 1116 | DEFVAR_LISP ("translation-table-vector", &Vtranslation_table_vector, |
| 1059 | doc: /* | 1117 | doc: /* |