diff options
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/Makefile.in | 12 | ||||
-rw-r--r-- | lib-src/ebrowse.c | 2 | ||||
-rw-r--r-- | lib-src/emacsclient.c | 23 | ||||
-rw-r--r-- | lib-src/etags.c | 8 | ||||
-rw-r--r-- | lib-src/make-docfile.c | 97 | ||||
-rw-r--r-- | lib-src/movemail.c | 2 | ||||
-rw-r--r-- | lib-src/ntlib.c | 67 | ||||
-rw-r--r-- | lib-src/profile.c | 7 |
8 files changed, 149 insertions, 69 deletions
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index fa37d8ed85d..ecb9208a1cd 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in @@ -334,7 +334,7 @@ uninstall: fi mostlyclean: - rm -f core *.o *.res + rm -f core ./*.o ./*.res clean: mostlyclean rm -f ${EXE_FILES} @@ -345,7 +345,7 @@ distclean: clean bootstrap-clean maintainer-clean: distclean extraclean: maintainer-clean - rm -f *~ \#* + rm -f ./*~ \#* ## Test the contents of the directory. check: @@ -361,13 +361,9 @@ TAGS: etags${EXEEXT} ${tagsfiles} ../lib/libgnu.a: $(config_h) $(MAKE) -C ../lib all -regex.o: $(srcdir)/../src/regex.c $(srcdir)/../src/regex.h $(config_h) - $(AM_V_CC)$(CC) -c $(CPP_CFLAGS) $< - - -etags_deps = ${srcdir}/etags.c regex.o $(NTLIB) $(config_h) +etags_deps = ${srcdir}/etags.c $(NTLIB) $(config_h) etags_cflags = -DEMACS_NAME="\"GNU Emacs\"" -DVERSION="\"${version}\"" -o $@ -etags_libs = regex.o $(NTLIB) $(LOADLIBES) +etags_libs = $(NTLIB) $(LOADLIBES) etags${EXEEXT}: ${etags_deps} $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $(etags_cflags) $< $(etags_libs) diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index fa78c35a8b4..33af4f02daf 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -494,7 +494,7 @@ yyerror (const char *format, const char *s) /* Like malloc but print an error and exit if not enough memory is available. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (size_t nbytes) { void *p = malloc (nbytes); diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index b0243f99c26..4fe3a588b19 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -192,7 +192,7 @@ struct option longopts[] = /* Like malloc but get fatal error if memory is exhausted. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (size_t size) { void *result = malloc (size); @@ -219,7 +219,7 @@ xrealloc (void *ptr, size_t size) } /* Like strdup but get a fatal error if memory is exhausted. */ -char *xstrdup (const char *); +char *xstrdup (const char *) ATTRIBUTE_MALLOC; char * xstrdup (const char *s) @@ -261,7 +261,7 @@ get_current_dir_name (void) #endif ) { - buf = (char *) xmalloc (strlen (pwd) + 1); + buf = xmalloc (strlen (pwd) + 1); strcpy (buf, pwd); } else @@ -312,12 +312,15 @@ w32_get_resource (HKEY predefined, const char *key, LPDWORD type) if (RegOpenKeyEx (predefined, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS) { - if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS) + if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) + == ERROR_SUCCESS) { - result = (char *) xmalloc (cbData); + result = xmalloc (cbData); - if ((RegQueryValueEx (hrootkey, key, NULL, type, (LPBYTE)result, &cbData) != ERROR_SUCCESS) - || (*result == 0)) + if ((RegQueryValueEx (hrootkey, key, NULL, type, (LPBYTE) result, + &cbData) + != ERROR_SUCCESS) + || *result == 0) { free (result); result = NULL; @@ -369,7 +372,7 @@ w32_getenv (const char *envvar) if ((size = ExpandEnvironmentStrings (value, NULL, 0))) { - char *buffer = (char *) xmalloc (size); + char *buffer = xmalloc (size); if (ExpandEnvironmentStrings (value, buffer, size)) { /* Found and expanded. */ @@ -833,7 +836,7 @@ send_to_emacs (HSOCKET s, const char *data) static void quote_argument (HSOCKET s, const char *str) { - char *copy = (char *) xmalloc (strlen (str) * 2 + 1); + char *copy = xmalloc (strlen (str) * 2 + 1); const char *p; char *q; @@ -1845,7 +1848,7 @@ main (int argc, char **argv) careful to expand <relpath> with the default directory corresponding to <drive>. */ { - char *filename = (char *) xmalloc (MAX_PATH); + char *filename = xmalloc (MAX_PATH); DWORD size; size = GetFullPathName (argv[i], MAX_PATH, filename, NULL); diff --git a/lib-src/etags.c b/lib-src/etags.c index 588921bc700..102d867b387 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -85,7 +85,9 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; # define DEBUG true #else # define DEBUG false -# define NDEBUG /* disable assert */ +# ifndef NDEBUG +# define NDEBUG /* disable assert */ +# endif #endif #include <config.h> @@ -6401,7 +6403,7 @@ add_regex (char *regexp_pattern, language *lang) *patbuf = zeropattern; if (ignore_case) { - static char lc_trans[UCHAR_MAX + 1]; + static unsigned char lc_trans[UCHAR_MAX + 1]; int i; for (i = 0; i < UCHAR_MAX + 1; i++) lc_trans[i] = c_tolower (i); @@ -7304,7 +7306,7 @@ linebuffer_setlen (linebuffer *lbp, int toksize) } /* Like malloc but get fatal error if memory is exhausted. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (size_t size) { void *result = malloc (size); diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 61d53dc59d6..23728e7251e 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c @@ -43,6 +43,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include <string.h> #include <binary-io.h> +#include <c-ctype.h> #include <intprops.h> #include <min-max.h> #include <unlocked-io.h> @@ -122,7 +123,7 @@ memory_exhausted (void) /* Like malloc but get fatal error if memory is exhausted. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (ptrdiff_t size) { void *result = malloc (size); @@ -341,7 +342,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state) state->pending_newlines = 2; state->pending_spaces = 0; - /* Skip any whitespace between the keyword and the + /* Skip any spaces and newlines between the keyword and the usage string. */ int c; do @@ -361,6 +362,7 @@ scan_keyword_or_put_char (char ch, struct rcsoc_state *state) fatal ("Unexpected EOF after keyword"); } while (c != ' ' && c != ')'); + put_char ('f', state); put_char ('n', state); @@ -415,7 +417,7 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment, c = getc (infile); if (comment) - while (c == '\n' || c == '\r' || c == '\t' || c == ' ') + while (c_isspace (c)) c = getc (infile); while (c != EOF) @@ -425,15 +427,14 @@ read_c_string_or_comment (FILE *infile, int printflag, bool comment, if (c == '\\') { c = getc (infile); - if (c == '\n' || c == '\r') + switch (c) { + case '\n': case '\r': c = getc (infile); continue; + case 'n': c = '\n'; break; + case 't': c = '\t'; break; } - if (c == 'n') - c = '\n'; - if (c == 't') - c = '\t'; } if (c == ' ') @@ -504,10 +505,7 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) char c = *p; /* Notice when a new identifier starts. */ - if ((('A' <= c && c <= 'Z') - || ('a' <= c && c <= 'z') - || ('0' <= c && c <= '9') - || c == '_') + if ((c_isalnum (c) || c == '_') != in_ident) { if (!in_ident) @@ -550,11 +548,8 @@ write_c_args (char *func, char *buf, int minargs, int maxargs) else while (ident_length-- > 0) { - c = *ident_start++; - if (c >= 'a' && c <= 'z') - /* Upcase the letter. */ - c += 'A' - 'a'; - else if (c == '_') + c = c_toupper (*ident_start++); + if (c == '_') /* Print underscore as hyphen. */ c = '-'; putchar (c); @@ -960,7 +955,7 @@ scan_c_stream (FILE *infile) { c = getc (infile); } - while (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r'); + while (c == ',' || c_isspace (c)); /* Read in the identifier. */ do @@ -972,8 +967,8 @@ scan_c_stream (FILE *infile) fatal ("identifier too long"); c = getc (infile); } - while (! (c == ',' || c == ' ' || c == '\t' - || c == '\n' || c == '\r')); + while (! (c == ',' || c_isspace (c))); + input_buffer[i] = '\0'; memcpy (name, input_buffer, i + 1); @@ -981,7 +976,8 @@ scan_c_stream (FILE *infile) { do c = getc (infile); - while (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + while (c_isspace (c)); + if (c != '"') continue; c = read_c_string_or_comment (infile, -1, false, 0); @@ -1022,7 +1018,8 @@ scan_c_stream (FILE *infile) int scanned = 0; do c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); + while (c_isspace (c)); + if (c < 0) goto eof; ungetc (c, infile); @@ -1072,7 +1069,7 @@ scan_c_stream (FILE *infile) int d = getc (infile); if (d == EOF) goto eof; - while (1) + while (true) { if (c == '*' && d == '/') break; @@ -1087,13 +1084,14 @@ scan_c_stream (FILE *infile) if (c == EOF) goto eof; } - while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); + while (c_isspace (c)); + /* Check for 'attributes:' token. */ if (c == 'a' && stream_match (infile, "ttributes:")) { char *p = input_buffer; /* Collect attributes up to ')'. */ - while (1) + while (true) { c = getc (infile); if (c == EOF) @@ -1115,7 +1113,7 @@ scan_c_stream (FILE *infile) continue; } - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + while (c_isspace (c)) c = getc (infile); if (c == '"') @@ -1125,17 +1123,18 @@ scan_c_stream (FILE *infile) c = getc (infile); if (c == ',') { - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + do c = getc (infile); - while ((c >= 'a' && c <= 'z') || (c >= 'Z' && c <= 'Z')) + while (c_isspace (c)); + + while (c_isalpha (c)) c = getc (infile); if (c == ':') { doc_keyword = true; - c = getc (infile); - while (c == ' ' || c == '\n' || c == '\r' || c == '\t') + do c = getc (infile); + while (c_isspace (c)); } } @@ -1186,8 +1185,14 @@ scan_c_stream (FILE *infile) /* Copy arguments into ARGBUF. */ *p++ = c; do - *p++ = c = getc (infile); + { + c = getc (infile); + if (c < 0) + goto eof; + *p++ = c; + } while (c != ')'); + *p = '\0'; /* Output them. */ fputs ("\n\n", stdout); @@ -1243,25 +1248,32 @@ scan_c_stream (FILE *infile) static void skip_white (FILE *infile) { - char c = ' '; - while (c == ' ' || c == '\t' || c == '\n' || c == '\r') + int c; + do c = getc (infile); + while (c_isspace (c)); + ungetc (c, infile); } static void read_lisp_symbol (FILE *infile, char *buffer) { - char c; + int c; char *fillp = buffer; skip_white (infile); - while (1) + while (true) { c = getc (infile); if (c == '\\') - *(++fillp) = getc (infile); - else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')') + { + c = getc (infile); + if (c < 0) + return; + *fillp++ = c; + } + else if (c_isspace (c) || c == '(' || c == ')' || c < 0) { ungetc (c, infile); *fillp = 0; @@ -1381,7 +1393,7 @@ scan_lisp_file (const char *filename, const char *mode) /* Read the length. */ while ((c = getc (infile), - c >= '0' && c <= '9')) + c_isdigit (c))) { if (INT_MULTIPLY_WRAPV (length, 10, &length) || INT_ADD_WRAPV (length, c - '0', &length) @@ -1413,7 +1425,7 @@ scan_lisp_file (const char *filename, const char *mode) while (c == '\n' || c == '\r') c = getc (infile); /* Skip the following line. */ - while (c != '\n' && c != '\r') + while (! (c == '\n' || c == '\r' || c < 0)) c = getc (infile); } continue; @@ -1451,7 +1463,7 @@ scan_lisp_file (const char *filename, const char *mode) continue; } else - while (c != ')') + while (! (c == ')' || c < 0)) c = getc (infile); skip_white (infile); @@ -1595,7 +1607,8 @@ scan_lisp_file (const char *filename, const char *mode) } } skip_white (infile); - if ((c = getc (infile)) != '\"') + c = getc (infile); + if (c != '\"') { fprintf (stderr, "## autoload of %s unparsable (%s)\n", buffer, filename); diff --git a/lib-src/movemail.c b/lib-src/movemail.c index 4495c38f6ec..7a37e164dd0 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c @@ -145,7 +145,7 @@ static bool mbx_delimit_end (FILE *); || (!defined DISABLE_DIRECT_ACCESS && !defined MAIL_USE_SYSTEM_LOCK)) /* Like malloc but get fatal error if memory is exhausted. */ -static void * +static void * ATTRIBUTE_MALLOC xmalloc (size_t size) { void *result = malloc (size); diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c index 95512854839..4ca521d2775 100644 --- a/lib-src/ntlib.c +++ b/lib-src/ntlib.c @@ -31,6 +31,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include <ctype.h> #include <sys/timeb.h> #include <mbstring.h> +#include <locale.h> + +#include <nl_types.h> +#include <langinfo.h> #include "ntlib.h" @@ -423,3 +427,66 @@ sys_open (const char * path, int oflag, int mode) { return _open (path, oflag, mode); } + +/* Emulation of nl_langinfo that supports only CODESET. + Used in Gnulib regex.c. */ +char * +nl_langinfo (nl_item item) +{ + switch (item) + { + case CODESET: + { + /* Shamelessly stolen from Gnulib's nl_langinfo.c, modulo + CPP directives. */ + static char buf[2 + 10 + 1]; + char const *locale = setlocale (LC_CTYPE, NULL); + char *codeset = buf; + size_t codesetlen; + codeset[0] = '\0'; + + if (locale && locale[0]) + { + /* If the locale name contains an encoding after the + dot, return it. */ + char *dot = strchr (locale, '.'); + + if (dot) + { + /* Look for the possible @... trailer and remove it, + if any. */ + char *codeset_start = dot + 1; + char const *modifier = strchr (codeset_start, '@'); + + if (! modifier) + codeset = codeset_start; + else + { + codesetlen = modifier - codeset_start; + if (codesetlen < sizeof buf) + { + codeset = memcpy (buf, codeset_start, codesetlen); + codeset[codesetlen] = '\0'; + } + } + } + } + /* If setlocale is successful, it returns the number of the + codepage, as a string. Otherwise, fall back on Windows + API GetACP, which returns the locale's codepage as a + number (although this doesn't change according to what + the 'setlocale' call specified). Either way, prepend + "CP" to make it a valid codeset name. */ + codesetlen = strlen (codeset); + if (0 < codesetlen && codesetlen < sizeof buf - 2) + memmove (buf + 2, codeset, codesetlen + 1); + else + sprintf (buf + 2, "%u", GetACP ()); + codeset = memcpy (buf, "CP", 2); + + return codeset; + } + default: + return (char *) ""; + } +} diff --git a/lib-src/profile.c b/lib-src/profile.c index 3818d33e689..649eb04b374 100644 --- a/lib-src/profile.c +++ b/lib-src/profile.c @@ -30,20 +30,19 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ ** operations: reset_watch, get_time */ -#define INLINE EXTERN_INLINE #include <config.h> #include <inttypes.h> #include <stdlib.h> #include <intprops.h> -#include <systime.h> +#include <timespec.h> #include <unlocked-io.h> static struct timespec TV1; static int watch_not_started = 1; /* flag */ static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "." - + LOG10_TIMESPEC_RESOLUTION]; + + LOG10_TIMESPEC_HZ]; /* Reset the stopwatch to zero. */ @@ -66,7 +65,7 @@ get_time (void) int ns = TV2.tv_nsec; if (watch_not_started) exit (EXIT_FAILURE); /* call reset_watch first ! */ - sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_TIMESPEC_RESOLUTION, ns); + sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_TIMESPEC_HZ, ns); return time_string; } |