Skip to content

Commit f12b4fa

Browse files
authored
Merge pull request #33 from jamessan/bigger-terminfo-files
Support terminfo files larger than 4K
2 parents bd01724 + d7cb8aa commit f12b4fa

7 files changed

Lines changed: 855 additions & 854 deletions

File tree

‎doc/unibi_from_fd.pod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unibi_from_fd - read a terminfo entry from a file descriptor
1212

1313
=head1 DESCRIPTION
1414

15-
This function reads up to 4096 bytes from I<fd>, then calls C<unibi_from_mem>.
15+
This function reads up to 32768 bytes from I<fd>, then calls C<unibi_from_mem>.
1616

1717
=head1 RETURN VALUE
1818

‎doc/unibi_from_fp.pod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ unibi_from_fp - read a terminfo entry from a FILE *
1212

1313
=head1 DESCRIPTION
1414

15-
This function reads up to 4096 bytes from I<fp>, then calls C<unibi_from_mem>.
15+
This function reads up to 32768 bytes from I<fp>, then calls C<unibi_from_mem>.
1616

1717
=head1 RETURN VALUE
1818

‎t/static_screen-256color.c‎

Lines changed: 70 additions & 155 deletions
Large diffs are not rendered by default.

‎t/static_screen.c‎

Lines changed: 66 additions & 78 deletions
Large diffs are not rendered by default.

‎t/static_tmux.c‎

Lines changed: 306 additions & 284 deletions
Large diffs are not rendered by default.

‎t/static_xterm-256color.c‎

Lines changed: 388 additions & 324 deletions
Large diffs are not rendered by default.

‎uniutil.c‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,56 @@ along with unibilium. If not, see <http://www.gnu.org/licenses/>.
4343
#error "internal error: TERMINFO_DIRS is not defined"
4444
#endif
4545

46-
enum {MAX_BUF = 4096};
46+
enum {MAX_BUF = 32768};
4747

4848
const char *const unibi_terminfo_dirs = TERMINFO_DIRS;
4949
const char *const unibi_terminfo = TERMINFO;
5050

5151
unibi_term *unibi_from_fp(FILE *fp) {
52-
char buf[MAX_BUF];
52+
char *buf = NULL;
53+
unibi_term *term = NULL;
5354
size_t n, r;
5455

55-
for (n = 0; n < sizeof buf && (r = fread(buf + n, 1, sizeof buf - n, fp)) > 0; ) {
56+
if (!(buf = malloc(MAX_BUF))) {
57+
return term;
58+
}
59+
60+
for (n = 0; n < MAX_BUF && (r = fread(buf + n, 1, MAX_BUF - n, fp)) > 0; ) {
5661
n += r;
5762

5863
if (feof(fp)) {
5964
break;
6065
}
6166
}
6267

63-
if (ferror(fp)) {
64-
return NULL;
68+
if (!ferror(fp)) {
69+
term = unibi_from_mem(buf, n);
6570
}
6671

67-
return unibi_from_mem(buf, n);
72+
free(buf);
73+
return term;
6874
}
6975

7076
unibi_term *unibi_from_fd(int fd) {
71-
char buf[MAX_BUF];
77+
char *buf = NULL;
78+
unibi_term *term = NULL;
7279
size_t n;
7380
ssize_t r;
7481

75-
for (n = 0; n < sizeof buf && (r = read(fd, buf + n, sizeof buf - n)) > 0; ) {
82+
if (!(buf = malloc(MAX_BUF))) {
83+
return term;
84+
}
85+
86+
for (n = 0; n < MAX_BUF && (r = read(fd, buf + n, MAX_BUF - n)) > 0; ) {
7687
n += r;
7788
}
7889

79-
if (r < 0) {
80-
return NULL;
90+
if (r >= 0) {
91+
term = unibi_from_mem(buf, n);
8192
}
8293

83-
return unibi_from_mem(buf, n);
94+
free(buf);
95+
return term;
8496
}
8597

8698
unibi_term *unibi_from_file(const char *file) {

0 commit comments

Comments
 (0)