diff options
| author | Paul Eggert | 1994-11-29 16:25:39 +0000 |
|---|---|---|
| committer | Paul Eggert | 1994-11-29 16:25:39 +0000 |
| commit | facd2759c5d2f25f524c76f68466c4cf6eadde3d (patch) | |
| tree | 6be470610dff98fcfd42df4f021a65629ffa4fde /src | |
| parent | bcbb4a0a25e845e451657d308ee9d386fcf64078 (diff) | |
| download | emacs-facd2759c5d2f25f524c76f68466c4cf6eadde3d.tar.gz emacs-facd2759c5d2f25f524c76f68466c4cf6eadde3d.zip | |
(re_compile_pattern, re_comp, regerror): Add gettext wrapper.
(re_error_msgid): Renamed from `re_error_msg', for consistency
with other source files that declare arrays of message ids.
Identifiers ending in `msgid' are special to to some prototype
message-extracting utilities.
Make "Success" be the 0th entry, so it can be extracted too.
(re_comp): Replace "Memory exhausted" with
re_error_msgid[REG_ESPACE], to aid message consistency.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/regex.c b/src/regex.c index 86f7545d7b1..2bd2152f925 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -53,6 +53,14 @@ char *malloc (); | |||
| 53 | char *realloc (); | 53 | char *realloc (); |
| 54 | #endif | 54 | #endif |
| 55 | 55 | ||
| 56 | /* This is for other GNU distributions with internationalized messages. | ||
| 57 | The GNU C Library itself does not yet support such messages. */ | ||
| 58 | #if HAVE_LIBINTL_H | ||
| 59 | # include <libintl.h> | ||
| 60 | #else | ||
| 61 | # define gettext(msgid) (msgid) | ||
| 62 | #endif | ||
| 63 | |||
| 56 | 64 | ||
| 57 | /* We used to test for `BSTRING' here, but only GCC and Emacs define | 65 | /* We used to test for `BSTRING' here, but only GCC and Emacs define |
| 58 | `BSTRING', as far as I know, and neither of them use this code. */ | 66 | `BSTRING', as far as I know, and neither of them use this code. */ |
| @@ -860,10 +868,12 @@ re_set_syntax (syntax) | |||
| 860 | } | 868 | } |
| 861 | 869 | ||
| 862 | /* This table gives an error message for each of the error codes listed | 870 | /* This table gives an error message for each of the error codes listed |
| 863 | in regex.h. Obviously the order here has to be same as there. */ | 871 | in regex.h. Obviously the order here has to be same as there. |
| 872 | POSIX doesn't require that we do anything for REG_NOERROR, | ||
| 873 | but why not be nice? */ | ||
| 864 | 874 | ||
| 865 | static const char *re_error_msg[] = | 875 | static const char *re_error_msgid[] = |
| 866 | { NULL, /* REG_NOERROR */ | 876 | { "Success", /* REG_NOERROR */ |
| 867 | "No match", /* REG_NOMATCH */ | 877 | "No match", /* REG_NOMATCH */ |
| 868 | "Invalid regular expression", /* REG_BADPAT */ | 878 | "Invalid regular expression", /* REG_BADPAT */ |
| 869 | "Invalid collation character", /* REG_ECOLLATE */ | 879 | "Invalid collation character", /* REG_ECOLLATE */ |
| @@ -4952,7 +4962,9 @@ re_compile_pattern (pattern, length, bufp) | |||
| 4952 | 4962 | ||
| 4953 | ret = regex_compile (pattern, length, re_syntax_options, bufp); | 4963 | ret = regex_compile (pattern, length, re_syntax_options, bufp); |
| 4954 | 4964 | ||
| 4955 | return re_error_msg[(int) ret]; | 4965 | if (!ret) |
| 4966 | return NULL; | ||
| 4967 | return gettext (re_error_msgid[(int) ret]); | ||
| 4956 | } | 4968 | } |
| 4957 | 4969 | ||
| 4958 | /* Entry points compatible with 4.2 BSD regex library. We don't define | 4970 | /* Entry points compatible with 4.2 BSD regex library. We don't define |
| @@ -4972,7 +4984,7 @@ re_comp (s) | |||
| 4972 | if (!s) | 4984 | if (!s) |
| 4973 | { | 4985 | { |
| 4974 | if (!re_comp_buf.buffer) | 4986 | if (!re_comp_buf.buffer) |
| 4975 | return "No previous regular expression"; | 4987 | return gettext ("No previous regular expression"); |
| 4976 | return 0; | 4988 | return 0; |
| 4977 | } | 4989 | } |
| 4978 | 4990 | ||
| @@ -4980,12 +4992,12 @@ re_comp (s) | |||
| 4980 | { | 4992 | { |
| 4981 | re_comp_buf.buffer = (unsigned char *) malloc (200); | 4993 | re_comp_buf.buffer = (unsigned char *) malloc (200); |
| 4982 | if (re_comp_buf.buffer == NULL) | 4994 | if (re_comp_buf.buffer == NULL) |
| 4983 | return "Memory exhausted"; | 4995 | return gettext (re_error_msgid[(int) REG_ESPACE]); |
| 4984 | re_comp_buf.allocated = 200; | 4996 | re_comp_buf.allocated = 200; |
| 4985 | 4997 | ||
| 4986 | re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); | 4998 | re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); |
| 4987 | if (re_comp_buf.fastmap == NULL) | 4999 | if (re_comp_buf.fastmap == NULL) |
| 4988 | return "Memory exhausted"; | 5000 | return gettext (re_error_msgid[(int) REG_ESPACE]); |
| 4989 | } | 5001 | } |
| 4990 | 5002 | ||
| 4991 | /* Since `re_exec' always passes NULL for the `regs' argument, we | 5003 | /* Since `re_exec' always passes NULL for the `regs' argument, we |
| @@ -4996,8 +5008,11 @@ re_comp (s) | |||
| 4996 | 5008 | ||
| 4997 | ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); | 5009 | ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); |
| 4998 | 5010 | ||
| 4999 | /* Yes, we're discarding `const' here. */ | 5011 | if (!ret) |
| 5000 | return (char *) re_error_msg[(int) ret]; | 5012 | return NULL; |
| 5013 | |||
| 5014 | /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ | ||
| 5015 | return (char *) gettext (re_error_msgid[(int) ret]); | ||
| 5001 | } | 5016 | } |
| 5002 | 5017 | ||
| 5003 | 5018 | ||
| @@ -5201,19 +5216,14 @@ regerror (errcode, preg, errbuf, errbuf_size) | |||
| 5201 | size_t msg_size; | 5216 | size_t msg_size; |
| 5202 | 5217 | ||
| 5203 | if (errcode < 0 | 5218 | if (errcode < 0 |
| 5204 | || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) | 5219 | || errcode >= (sizeof (re_error_msgid) / sizeof (re_error_msgid[0]))) |
| 5205 | /* Only error codes returned by the rest of the code should be passed | 5220 | /* Only error codes returned by the rest of the code should be passed |
| 5206 | to this routine. If we are given anything else, or if other regex | 5221 | to this routine. If we are given anything else, or if other regex |
| 5207 | code generates an invalid error code, then the program has a bug. | 5222 | code generates an invalid error code, then the program has a bug. |
| 5208 | Dump core so we can fix it. */ | 5223 | Dump core so we can fix it. */ |
| 5209 | abort (); | 5224 | abort (); |
| 5210 | 5225 | ||
| 5211 | msg = re_error_msg[errcode]; | 5226 | msg = gettext (re_error_msgid[errcode]); |
| 5212 | |||
| 5213 | /* POSIX doesn't require that we do anything in this case, but why | ||
| 5214 | not be nice. */ | ||
| 5215 | if (! msg) | ||
| 5216 | msg = "Success"; | ||
| 5217 | 5227 | ||
| 5218 | msg_size = strlen (msg) + 1; /* Includes the null. */ | 5228 | msg_size = strlen (msg) + 1; /* Includes the null. */ |
| 5219 | 5229 | ||