X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/9f0b1513ad9b24e2f7dec87d3afb32cd6240ccad..acfa068f4a1a4652b784af1d7aaac92929399249:/src/termcap.c diff --git a/src/termcap.c b/src/termcap.c index e191f6b3af..e494cd113d 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -19,7 +19,6 @@ Boston, MA 02110-1301, USA. */ /* Emacs config.h may rename various library functions such as malloc. */ #include -#include #include #include #include @@ -30,10 +29,6 @@ Boston, MA 02110-1301, USA. */ #include "msdos.h" #endif -#ifndef NULL -#define NULL (char *) 0 -#endif - /* BUFSIZE is the initial size allocated for the buffer for reading the termcap file. It is not a limit. @@ -157,7 +152,7 @@ tgetst1 (char *ptr, char **area) p = ptr; while ((c = *p++) && c != ':' && c != '\n') ; - ret = (char *) xmalloc (p - ptr + 1); + ret = xmalloc (p - ptr + 1); } else ret = *area; @@ -338,8 +333,7 @@ static int name_match (char *line, char *name); #ifdef MSDOS /* MW, May 1993 */ static int -valid_filename_p (fn) - char *fn; +valid_filename_p (char *fn) { return *fn == '/' || fn[1] == ':'; } @@ -382,7 +376,7 @@ tgetent (char *bp, const char *name) if (!bp) { malloc_size = 1 + strlen (term); - bp = (char *) xmalloc (malloc_size); + bp = xmalloc (malloc_size); } strcpy (bp, term); goto ret; @@ -401,7 +395,7 @@ tgetent (char *bp, const char *name) if (termcap_name && (*termcap_name == '\\' || *termcap_name == '/' || termcap_name[1] == ':')) - dostounix_filename(termcap_name); + dostounix_filename (termcap_name); #endif filep = termcap_name && valid_filename_p (termcap_name); @@ -445,13 +439,13 @@ tgetent (char *bp, const char *name) buf.size = BUFSIZE; /* Add 1 to size to ensure room for terminating null. */ - buf.beg = (char *) xmalloc (buf.size + 1); + buf.beg = xmalloc (buf.size + 1); term = indirect ? indirect : (char *)name; if (!bp) { malloc_size = indirect ? strlen (tcenv) + 1 : buf.size; - bp = (char *) xmalloc (malloc_size); + bp = xmalloc (malloc_size); } tc_search_point = bp1 = bp; @@ -481,9 +475,9 @@ tgetent (char *bp, const char *name) /* If BP is malloc'd by us, make sure it is big enough. */ if (malloc_size) { - int offset1 = bp1 - bp, offset2 = tc_search_point - bp; + ptrdiff_t offset1 = bp1 - bp, offset2 = tc_search_point - bp; malloc_size = offset1 + buf.size; - bp = termcap_name = (char *) xrealloc (bp, malloc_size); + bp = termcap_name = xrealloc (bp, malloc_size); bp1 = termcap_name + offset1; tc_search_point = termcap_name + offset2; } @@ -509,7 +503,7 @@ tgetent (char *bp, const char *name) xfree (buf.beg); if (malloc_size) - bp = (char *) xrealloc (bp, bp1 - bp + 1); + bp = xrealloc (bp, bp1 - bp + 1); ret: term_entry = bp; @@ -620,7 +614,6 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) register char *end; register int nread; register char *buf = bufp->beg; - register char *tem; if (!append_end) append_end = bufp->ptr; @@ -637,14 +630,14 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) { if (bufp->full == bufp->size) { - if ((PTRDIFF_MAX - 1) / 2 < bufp->size) - memory_full (SIZE_MAX); - bufp->size *= 2; + ptrdiff_t ptr_offset = bufp->ptr - buf; + ptrdiff_t append_end_offset = append_end - buf; /* Add 1 to size to ensure room for terminating null. */ - tem = (char *) xrealloc (buf, bufp->size + 1); - bufp->ptr = (bufp->ptr - buf) + tem; - append_end = (append_end - buf) + tem; - bufp->beg = buf = tem; + ptrdiff_t size = bufp->size + 1; + bufp->beg = buf = xpalloc (buf, &size, 1, -1, 1); + bufp->size = size - 1; + bufp->ptr = buf + ptr_offset; + append_end = buf + append_end_offset; } } else @@ -663,15 +656,31 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) #ifdef TEST -#ifdef NULL -#undef NULL -#endif - #include -main (argc, argv) - int argc; - char **argv; +static void +tprint (char *cap) +{ + char *x = tgetstr (cap, 0); + register char *y; + + printf ("%s: ", cap); + if (x) + { + for (y = x; *y; y++) + if (*y <= ' ' || *y == 0177) + printf ("\\%0o", *y); + else + putchar (*y); + free (x); + } + else + printf ("none"); + putchar ('\n'); +} + +int +main (int argc, char **argv) { char *term; char *buf; @@ -693,27 +702,8 @@ main (argc, argv) printf ("co: %d\n", tgetnum ("co")); printf ("am: %d\n", tgetflag ("am")); -} -tprint (cap) - char *cap; -{ - char *x = tgetstr (cap, 0); - register char *y; - - printf ("%s: ", cap); - if (x) - { - for (y = x; *y; y++) - if (*y <= ' ' || *y == 0177) - printf ("\\%0o", *y); - else - putchar (*y); - free (x); - } - else - printf ("none"); - putchar ('\n'); + return 0; } #endif /* TEST */