aboutsummaryrefslogtreecommitdiffstats
path: root/src/termcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/termcap.c')
-rw-r--r--src/termcap.c114
1 files changed, 28 insertions, 86 deletions
diff --git a/src/termcap.c b/src/termcap.c
index 99bbfce27f5..be05828eea6 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -213,8 +213,8 @@ tgetst1 (char *ptr, char **area)
213 abbreviation expansion makes that effort a little more hairy than 213 abbreviation expansion makes that effort a little more hairy than
214 its worth; this is cleaner. */ 214 its worth; this is cleaner. */
215 { 215 {
216 register int last_p_param = 0; 216 int last_p_param = 0;
217 int remove_p_params = 1; 217 bool remove_p_params = 1;
218 struct { char *beg; int len; } cut[11]; 218 struct { char *beg; int len; } cut[11];
219 219
220 for (cut[0].beg = p = ret; p < r - 3; p++) 220 for (cut[0].beg = p = ret; p < r - 3; p++)
@@ -318,26 +318,26 @@ struct termcap_buffer
318 char *beg; 318 char *beg;
319 ptrdiff_t size; 319 ptrdiff_t size;
320 char *ptr; 320 char *ptr;
321 int ateof; 321 bool ateof;
322 ptrdiff_t full; 322 ptrdiff_t full;
323 }; 323 };
324 324
325/* Forward declarations of static functions. */ 325/* Forward declarations of static functions. */
326 326
327static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); 327static bool scan_file (char *, int, struct termcap_buffer *);
328static char *gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end); 328static char *gobble_line (int, struct termcap_buffer *, char *);
329static int compare_contin (register char *str1, register char *str2); 329static bool compare_contin (char *, char *);
330static int name_match (char *line, char *name); 330static bool name_match (char *, char *);
331 331
332#ifdef MSDOS /* MW, May 1993 */ 332static bool
333static int
334valid_filename_p (char *fn) 333valid_filename_p (char *fn)
335{ 334{
335#ifdef MSDOS
336 return *fn == '/' || fn[1] == ':'; 336 return *fn == '/' || fn[1] == ':';
337}
338#else 337#else
339#define valid_filename_p(fn) (*(fn) == '/') 338 return *fn == '/';
340#endif 339#endif
340}
341 341
342/* Find the termcap entry data for terminal type NAME 342/* Find the termcap entry data for terminal type NAME
343 and store it in the block that BP points to. 343 and store it in the block that BP points to.
@@ -360,10 +360,10 @@ tgetent (char *bp, const char *name)
360 char *tc_search_point; 360 char *tc_search_point;
361 char *term; 361 char *term;
362 ptrdiff_t malloc_size = 0; 362 ptrdiff_t malloc_size = 0;
363 register int c; 363 int c;
364 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ 364 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */
365 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */ 365 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */
366 int filep; 366 bool filep;
367 367
368#ifdef INTERNAL_TERMINAL 368#ifdef INTERNAL_TERMINAL
369 /* For the internal terminal we don't want to read any termcap file, 369 /* For the internal terminal we don't want to read any termcap file,
@@ -427,11 +427,7 @@ tgetent (char *bp, const char *name)
427 427
428 /* Here we know we must search a file and termcap_name has its name. */ 428 /* Here we know we must search a file and termcap_name has its name. */
429 429
430#ifdef MSDOS 430 fd = emacs_open (termcap_name, O_RDONLY | O_TEXT, 0);
431 fd = open (termcap_name, O_RDONLY|O_TEXT, 0);
432#else
433 fd = open (termcap_name, O_RDONLY, 0);
434#endif
435 if (fd < 0) 431 if (fd < 0)
436 return -1; 432 return -1;
437 433
@@ -459,7 +455,7 @@ tgetent (char *bp, const char *name)
459 /* Scan the file, reading it via buf, till find start of main entry. */ 455 /* Scan the file, reading it via buf, till find start of main entry. */
460 if (scan_file (term, fd, &buf) == 0) 456 if (scan_file (term, fd, &buf) == 0)
461 { 457 {
462 close (fd); 458 emacs_close (fd);
463 xfree (buf.beg); 459 xfree (buf.beg);
464 if (malloc_size) 460 if (malloc_size)
465 xfree (bp); 461 xfree (bp);
@@ -497,7 +493,7 @@ tgetent (char *bp, const char *name)
497 term = tgetst1 (tc_search_point, (char **) 0); 493 term = tgetst1 (tc_search_point, (char **) 0);
498 } 494 }
499 495
500 close (fd); 496 emacs_close (fd);
501 xfree (buf.beg); 497 xfree (buf.beg);
502 498
503 if (malloc_size) 499 if (malloc_size)
@@ -514,10 +510,10 @@ tgetent (char *bp, const char *name)
514 Return 1 if successful, with that line in BUFP, 510 Return 1 if successful, with that line in BUFP,
515 or 0 if no entry is found in the file. */ 511 or 0 if no entry is found in the file. */
516 512
517static int 513static bool
518scan_file (char *str, int fd, register struct termcap_buffer *bufp) 514scan_file (char *str, int fd, struct termcap_buffer *bufp)
519{ 515{
520 register char *end; 516 char *end;
521 517
522 bufp->ptr = bufp->beg; 518 bufp->ptr = bufp->beg;
523 bufp->full = 0; 519 bufp->full = 0;
@@ -548,13 +544,13 @@ scan_file (char *str, int fd, register struct termcap_buffer *bufp)
548 return 0; 544 return 0;
549} 545}
550 546
551/* Return nonzero if NAME is one of the names specified 547/* Return true if NAME is one of the names specified
552 by termcap entry LINE. */ 548 by termcap entry LINE. */
553 549
554static int 550static bool
555name_match (char *line, char *name) 551name_match (char *line, char *name)
556{ 552{
557 register char *tem; 553 char *tem;
558 554
559 if (!compare_contin (line, name)) 555 if (!compare_contin (line, name))
560 return 1; 556 return 1;
@@ -566,18 +562,18 @@ name_match (char *line, char *name)
566 return 0; 562 return 0;
567} 563}
568 564
569static int 565static bool
570compare_contin (register char *str1, register char *str2) 566compare_contin (char *str1, char *str2)
571{ 567{
572 register int c1, c2;
573 while (1) 568 while (1)
574 { 569 {
575 c1 = *str1++; 570 int c1 = *str1++;
576 c2 = *str2++; 571 int c2 = *str2++;
577 while (c1 == '\\' && *str1 == '\n') 572 while (c1 == '\\' && *str1 == '\n')
578 { 573 {
579 str1++; 574 str1++;
580 while ((c1 = *str1++) == ' ' || c1 == '\t'); 575 while ((c1 = *str1++) == ' ' || c1 == '\t')
576 continue;
581 } 577 }
582 if (c2 == '\0') 578 if (c2 == '\0')
583 { 579 {
@@ -651,57 +647,3 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
651 } 647 }
652 return end + 1; 648 return end + 1;
653} 649}
654
655#ifdef TEST
656
657#include <stdio.h>
658
659static void
660tprint (char *cap)
661{
662 char *x = tgetstr (cap, 0);
663 register char *y;
664
665 printf ("%s: ", cap);
666 if (x)
667 {
668 for (y = x; *y; y++)
669 if (*y <= ' ' || *y == 0177)
670 printf ("\\%0o", *y);
671 else
672 putchar (*y);
673 free (x);
674 }
675 else
676 printf ("none");
677 putchar ('\n');
678}
679
680int
681main (int argc, char **argv)
682{
683 char *term;
684 char *buf;
685
686 term = argv[1];
687 printf ("TERM: %s\n", term);
688
689 buf = (char *) tgetent (0, term);
690 if ((int) buf <= 0)
691 {
692 printf ("No entry.\n");
693 return 0;
694 }
695
696 printf ("Entry: %s\n", buf);
697
698 tprint ("cm");
699 tprint ("AL");
700
701 printf ("co: %d\n", tgetnum ("co"));
702 printf ("am: %d\n", tgetflag ("am"));
703
704 return 0;
705}
706
707#endif /* TEST */