aboutsummaryrefslogtreecommitdiffstats
path: root/src/termcap.c
diff options
context:
space:
mode:
authorStefan Monnier2012-03-25 16:37:21 -0400
committerStefan Monnier2012-03-25 16:37:21 -0400
commit699c782b7668c44d0fa4446331b0590a6d5dac82 (patch)
tree5dcce364741d0761920a3d274b0fc8aba4103d45 /src/termcap.c
parent98fb480ee31bf74cf554044f60f21df16566dd7f (diff)
parente99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff)
downloademacs-pending.tar.gz
emacs-pending.zip
Merge from trunkpending
Diffstat (limited to 'src/termcap.c')
-rw-r--r--src/termcap.c69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/termcap.c b/src/termcap.c
index e191f6b3af3..10c195eebe2 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -338,8 +338,7 @@ static int name_match (char *line, char *name);
338 338
339#ifdef MSDOS /* MW, May 1993 */ 339#ifdef MSDOS /* MW, May 1993 */
340static int 340static int
341valid_filename_p (fn) 341valid_filename_p (char *fn)
342 char *fn;
343{ 342{
344 return *fn == '/' || fn[1] == ':'; 343 return *fn == '/' || fn[1] == ':';
345} 344}
@@ -401,7 +400,7 @@ tgetent (char *bp, const char *name)
401 if (termcap_name && (*termcap_name == '\\' 400 if (termcap_name && (*termcap_name == '\\'
402 || *termcap_name == '/' 401 || *termcap_name == '/'
403 || termcap_name[1] == ':')) 402 || termcap_name[1] == ':'))
404 dostounix_filename(termcap_name); 403 dostounix_filename (termcap_name);
405#endif 404#endif
406 405
407 filep = termcap_name && valid_filename_p (termcap_name); 406 filep = termcap_name && valid_filename_p (termcap_name);
@@ -481,7 +480,7 @@ tgetent (char *bp, const char *name)
481 /* If BP is malloc'd by us, make sure it is big enough. */ 480 /* If BP is malloc'd by us, make sure it is big enough. */
482 if (malloc_size) 481 if (malloc_size)
483 { 482 {
484 int offset1 = bp1 - bp, offset2 = tc_search_point - bp; 483 ptrdiff_t offset1 = bp1 - bp, offset2 = tc_search_point - bp;
485 malloc_size = offset1 + buf.size; 484 malloc_size = offset1 + buf.size;
486 bp = termcap_name = (char *) xrealloc (bp, malloc_size); 485 bp = termcap_name = (char *) xrealloc (bp, malloc_size);
487 bp1 = termcap_name + offset1; 486 bp1 = termcap_name + offset1;
@@ -620,7 +619,6 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
620 register char *end; 619 register char *end;
621 register int nread; 620 register int nread;
622 register char *buf = bufp->beg; 621 register char *buf = bufp->beg;
623 register char *tem;
624 622
625 if (!append_end) 623 if (!append_end)
626 append_end = bufp->ptr; 624 append_end = bufp->ptr;
@@ -637,14 +635,14 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
637 { 635 {
638 if (bufp->full == bufp->size) 636 if (bufp->full == bufp->size)
639 { 637 {
640 if ((PTRDIFF_MAX - 1) / 2 < bufp->size) 638 ptrdiff_t ptr_offset = bufp->ptr - buf;
641 memory_full (SIZE_MAX); 639 ptrdiff_t append_end_offset = append_end - buf;
642 bufp->size *= 2;
643 /* Add 1 to size to ensure room for terminating null. */ 640 /* Add 1 to size to ensure room for terminating null. */
644 tem = (char *) xrealloc (buf, bufp->size + 1); 641 ptrdiff_t size = bufp->size + 1;
645 bufp->ptr = (bufp->ptr - buf) + tem; 642 bufp->beg = buf = xpalloc (buf, &size, 1, -1, 1);
646 append_end = (append_end - buf) + tem; 643 bufp->size = size - 1;
647 bufp->beg = buf = tem; 644 bufp->ptr = buf + ptr_offset;
645 append_end = buf + append_end_offset;
648 } 646 }
649 } 647 }
650 else 648 else
@@ -669,9 +667,29 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
669 667
670#include <stdio.h> 668#include <stdio.h>
671 669
672main (argc, argv) 670static void
673 int argc; 671tprint (char *cap)
674 char **argv; 672{
673 char *x = tgetstr (cap, 0);
674 register char *y;
675
676 printf ("%s: ", cap);
677 if (x)
678 {
679 for (y = x; *y; y++)
680 if (*y <= ' ' || *y == 0177)
681 printf ("\\%0o", *y);
682 else
683 putchar (*y);
684 free (x);
685 }
686 else
687 printf ("none");
688 putchar ('\n');
689}
690
691int
692main (int argc, char **argv)
675{ 693{
676 char *term; 694 char *term;
677 char *buf; 695 char *buf;
@@ -693,27 +711,8 @@ main (argc, argv)
693 711
694 printf ("co: %d\n", tgetnum ("co")); 712 printf ("co: %d\n", tgetnum ("co"));
695 printf ("am: %d\n", tgetflag ("am")); 713 printf ("am: %d\n", tgetflag ("am"));
696}
697
698tprint (cap)
699 char *cap;
700{
701 char *x = tgetstr (cap, 0);
702 register char *y;
703 714
704 printf ("%s: ", cap); 715 return 0;
705 if (x)
706 {
707 for (y = x; *y; y++)
708 if (*y <= ' ' || *y == 0177)
709 printf ("\\%0o", *y);
710 else
711 putchar (*y);
712 free (x);
713 }
714 else
715 printf ("none");
716 putchar ('\n');
717} 716}
718 717
719#endif /* TEST */ 718#endif /* TEST */