diff options
Diffstat (limited to 'src/termcap.c')
| -rw-r--r-- | src/termcap.c | 108 |
1 files changed, 27 insertions, 81 deletions
diff --git a/src/termcap.c b/src/termcap.c index 7256eef9e81..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 | ||
| 327 | static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); | 327 | static bool scan_file (char *, int, struct termcap_buffer *); |
| 328 | static char *gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end); | 328 | static char *gobble_line (int, struct termcap_buffer *, char *); |
| 329 | static int compare_contin (register char *str1, register char *str2); | 329 | static bool compare_contin (char *, char *); |
| 330 | static int name_match (char *line, char *name); | 330 | static bool name_match (char *, char *); |
| 331 | 331 | ||
| 332 | #ifdef MSDOS /* MW, May 1993 */ | 332 | static bool |
| 333 | static int | ||
| 334 | valid_filename_p (char *fn) | 333 | valid_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, |
| @@ -455,7 +455,7 @@ tgetent (char *bp, const char *name) | |||
| 455 | /* 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. */ |
| 456 | if (scan_file (term, fd, &buf) == 0) | 456 | if (scan_file (term, fd, &buf) == 0) |
| 457 | { | 457 | { |
| 458 | close (fd); | 458 | emacs_close (fd); |
| 459 | xfree (buf.beg); | 459 | xfree (buf.beg); |
| 460 | if (malloc_size) | 460 | if (malloc_size) |
| 461 | xfree (bp); | 461 | xfree (bp); |
| @@ -493,7 +493,7 @@ tgetent (char *bp, const char *name) | |||
| 493 | term = tgetst1 (tc_search_point, (char **) 0); | 493 | term = tgetst1 (tc_search_point, (char **) 0); |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | close (fd); | 496 | emacs_close (fd); |
| 497 | xfree (buf.beg); | 497 | xfree (buf.beg); |
| 498 | 498 | ||
| 499 | if (malloc_size) | 499 | if (malloc_size) |
| @@ -510,10 +510,10 @@ tgetent (char *bp, const char *name) | |||
| 510 | Return 1 if successful, with that line in BUFP, | 510 | Return 1 if successful, with that line in BUFP, |
| 511 | or 0 if no entry is found in the file. */ | 511 | or 0 if no entry is found in the file. */ |
| 512 | 512 | ||
| 513 | static int | 513 | static bool |
| 514 | scan_file (char *str, int fd, register struct termcap_buffer *bufp) | 514 | scan_file (char *str, int fd, struct termcap_buffer *bufp) |
| 515 | { | 515 | { |
| 516 | register char *end; | 516 | char *end; |
| 517 | 517 | ||
| 518 | bufp->ptr = bufp->beg; | 518 | bufp->ptr = bufp->beg; |
| 519 | bufp->full = 0; | 519 | bufp->full = 0; |
| @@ -544,13 +544,13 @@ scan_file (char *str, int fd, register struct termcap_buffer *bufp) | |||
| 544 | return 0; | 544 | return 0; |
| 545 | } | 545 | } |
| 546 | 546 | ||
| 547 | /* Return nonzero if NAME is one of the names specified | 547 | /* Return true if NAME is one of the names specified |
| 548 | by termcap entry LINE. */ | 548 | by termcap entry LINE. */ |
| 549 | 549 | ||
| 550 | static int | 550 | static bool |
| 551 | name_match (char *line, char *name) | 551 | name_match (char *line, char *name) |
| 552 | { | 552 | { |
| 553 | register char *tem; | 553 | char *tem; |
| 554 | 554 | ||
| 555 | if (!compare_contin (line, name)) | 555 | if (!compare_contin (line, name)) |
| 556 | return 1; | 556 | return 1; |
| @@ -562,18 +562,18 @@ name_match (char *line, char *name) | |||
| 562 | return 0; | 562 | return 0; |
| 563 | } | 563 | } |
| 564 | 564 | ||
| 565 | static int | 565 | static bool |
| 566 | compare_contin (register char *str1, register char *str2) | 566 | compare_contin (char *str1, char *str2) |
| 567 | { | 567 | { |
| 568 | register int c1, c2; | ||
| 569 | while (1) | 568 | while (1) |
| 570 | { | 569 | { |
| 571 | c1 = *str1++; | 570 | int c1 = *str1++; |
| 572 | c2 = *str2++; | 571 | int c2 = *str2++; |
| 573 | while (c1 == '\\' && *str1 == '\n') | 572 | while (c1 == '\\' && *str1 == '\n') |
| 574 | { | 573 | { |
| 575 | str1++; | 574 | str1++; |
| 576 | while ((c1 = *str1++) == ' ' || c1 == '\t'); | 575 | while ((c1 = *str1++) == ' ' || c1 == '\t') |
| 576 | continue; | ||
| 577 | } | 577 | } |
| 578 | if (c2 == '\0') | 578 | if (c2 == '\0') |
| 579 | { | 579 | { |
| @@ -647,57 +647,3 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) | |||
| 647 | } | 647 | } |
| 648 | return end + 1; | 648 | return end + 1; |
| 649 | } | 649 | } |
| 650 | |||
| 651 | #ifdef TEST | ||
| 652 | |||
| 653 | #include <stdio.h> | ||
| 654 | |||
| 655 | static void | ||
| 656 | tprint (char *cap) | ||
| 657 | { | ||
| 658 | char *x = tgetstr (cap, 0); | ||
| 659 | register char *y; | ||
| 660 | |||
| 661 | printf ("%s: ", cap); | ||
| 662 | if (x) | ||
| 663 | { | ||
| 664 | for (y = x; *y; y++) | ||
| 665 | if (*y <= ' ' || *y == 0177) | ||
| 666 | printf ("\\%0o", *y); | ||
| 667 | else | ||
| 668 | putchar (*y); | ||
| 669 | free (x); | ||
| 670 | } | ||
| 671 | else | ||
| 672 | printf ("none"); | ||
| 673 | putchar ('\n'); | ||
| 674 | } | ||
| 675 | |||
| 676 | int | ||
| 677 | main (int argc, char **argv) | ||
| 678 | { | ||
| 679 | char *term; | ||
| 680 | char *buf; | ||
| 681 | |||
| 682 | term = argv[1]; | ||
| 683 | printf ("TERM: %s\n", term); | ||
| 684 | |||
| 685 | buf = (char *) tgetent (0, term); | ||
| 686 | if ((int) buf <= 0) | ||
| 687 | { | ||
| 688 | printf ("No entry.\n"); | ||
| 689 | return 0; | ||
| 690 | } | ||
| 691 | |||
| 692 | printf ("Entry: %s\n", buf); | ||
| 693 | |||
| 694 | tprint ("cm"); | ||
| 695 | tprint ("AL"); | ||
| 696 | |||
| 697 | printf ("co: %d\n", tgetnum ("co")); | ||
| 698 | printf ("am: %d\n", tgetflag ("am")); | ||
| 699 | |||
| 700 | return 0; | ||
| 701 | } | ||
| 702 | |||
| 703 | #endif /* TEST */ | ||