summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shambarger <devel@shambarger.net>2019-11-05 17:00:32 +0000
committerAmadeusz Sławiński <amade@asmblr.net>2019-12-28 13:45:48 +0100
commit11a1fc82fb34e18832938d63c3a4471908dae017 (patch)
tree90481d1f11b36990d17e092a554d410ee2db589b
parentfa4f88614d3e5994cfb1372353e7316be7235060 (diff)
downloadscreen-11a1fc82fb34e18832938d63c3a4471908dae017.tar.gz
Create TERMCAP entries limited to 1023 bytes by default.
TERMCAP_BUF defaults to 1023 to create TERMCAP entries that work on most systems. To save space, TERMCAP is unwrapped, and vt220 extra keys are skipped (unless TERMCAP_BUF > 1023); navigation keys are still included. Entries larger than TERMCAP_BUF are now truncated, and no longer Panic screen. Termcap entries are still wrapped when saved to a file. Signed-off-by: Scott Shambarger <devel@shambarger.net>
-rw-r--r--src/dumptermcap.h6
-rw-r--r--src/fileio.c6
-rw-r--r--src/os.h2
-rw-r--r--src/term.c1
-rw-r--r--src/termcap.c51
5 files changed, 49 insertions, 17 deletions
diff --git a/src/dumptermcap.h b/src/dumptermcap.h
new file mode 100644
index 0000000..2e14039
--- /dev/null
+++ b/src/dumptermcap.h
@@ -0,0 +1,6 @@
+#ifndef SCREEN_DUMPTERMCAP_H
+#define SCREEN_DUMPTERMCAP_H
+
+void DumpTermcap (int, FILE *);
+
+#endif /* SCREEN_DUMPTERMCAP_H */
diff --git a/src/fileio.c b/src/fileio.c
index 4b63e65..75db976 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -44,6 +44,7 @@
#include "misc.h"
#include "process.h"
#include "termcap.h"
+#include "dumptermcap.h"
#include "encoding.h"
static char *CatExtra(char *, char *);
@@ -438,10 +439,7 @@ void WriteFile(struct acluser *user, char *fn, int dump)
}
break;
case DUMP_TERMCAP:
- if ((c = strchr(MakeTermcap(fore->w_aflag), '=')) != NULL) {
- fputs(++c, f);
- putc('\n', f);
- }
+ DumpTermcap(fore->w_aflag, f);
break;
case DUMP_EXCHANGE:
c = user->u_plop.buf;
diff --git a/src/os.h b/src/os.h
index 931617f..b350e43 100644
--- a/src/os.h
+++ b/src/os.h
@@ -148,7 +148,7 @@ typedef char* slot_t; /* used internally in utmp.c */
*/
#ifndef TERMCAP_BUFSIZE
-# define TERMCAP_BUFSIZE 2048
+# define TERMCAP_BUFSIZE 1023
#endif
/*
diff --git a/src/term.c b/src/term.c
index 5a4f21c..ec8c6b3 100644
--- a/src/term.c
+++ b/src/term.c
@@ -201,6 +201,7 @@ struct term term[T_N] =
{ "F1", T_STR }, KMAPDEF("\033[23~")
{ "F2", T_STR }, KMAPDEF("\033[24~")
/* extra keys for vt220 (David.Leonard@it.uq.edu.au) */
+/* define T_FEXTRA */
{ "F3", T_STR },
{ "F4", T_STR },
{ "F5", T_STR },
diff --git a/src/termcap.c b/src/termcap.c
index d7001a4..1a75f2f 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -62,11 +62,10 @@ char screenterm[MAXTERMLEN + 1]; /* new $TERM, usually "screen" */
char *extra_incap, *extra_outcap;
-static const char TermcapConst[] = "\\\n\
-\t:DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:UP=\\E[%dA:bs:bt=\\E[Z:\\\n\
-\t:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:ct=\\E[3g:\\\n\
-\t:do=^J:nd=\\E[C:pt:rc=\\E8:rs=\\Ec:sc=\\E7:st=\\EH:up=\\EM:\\\n\
-\t:le=^H:bl=^G:cr=^M:it#8:ho=\\E[H:nw=\\EE:ta=^I:is=\\E)0:";
+static const char TermcapConst[] = "DO=\\E[%dB:LE=\\E[%dD:RI=\\E[%dC:\
+UP=\\E[%dA:bs:bt=\\E[Z:cd=\\E[J:ce=\\E[K:cl=\\E[H\\E[J:cm=\\E[%i%d;%dH:\
+ct=\\E[3g:do=^J:nd=\\E[C:pt:rc=\\E8:rs=\\Ec:sc=\\E7:st=\\EH:up=\\EM:\
+le=^H:bl=^G:cr=^M:it#8:ho=\\E[H:nw=\\EE:ta=^I:is=\\E)0:";
char *gettermcapstring(char *s)
{
@@ -641,17 +640,12 @@ static void AddCap(char *s)
{
int n;
- if (tcLineLen + (n = strlen(s)) > 55 && Termcaplen < TERMCAP_BUFSIZE - 4 - 1) {
- strcpy(Termcap + Termcaplen, "\\\n\t:");
- Termcaplen += 4;
- tcLineLen = 0;
- }
+ n = strlen(s);
if (Termcaplen + n < TERMCAP_BUFSIZE - 1) {
strcpy(Termcap + Termcaplen, s);
Termcaplen += n;
tcLineLen += n;
- } else
- Panic(0, "TERMCAP overflow - sorry.");
+ }
}
/*
@@ -809,6 +803,12 @@ char *MakeTermcap(bool aflag)
if (i < T_OCAPS) {
if (i >= T_KEYPAD) /* don't put keypad codes in TERMCAP */
continue; /* - makes it too big */
+#if (TERMCAP_BUF < 1024)
+ if (i >= T_FEXTRA && i < T_BACKTAB) /* also skip extra vt220 keys */
+ continue;
+ if (i > T_BACKTAB && i < T_NAVIGATE) /* more vt220 keys */
+ continue;
+#endif
if (i >= T_CURSOR && i < T_OCAPS) {
act = &umtab[i - (T_CURSOR - T_OCAPS + T_CAPS)];
if (act->nr == RC_ILLEGAL)
@@ -854,6 +854,33 @@ char *MakeTermcap(bool aflag)
return Termcap;
}
+#define TERMCAP_MAX_WIDTH 63
+void DumpTermcap(int aflag, FILE *f)
+{
+ const char *p, *pe;
+ int n, col = 0;
+
+ if ((p = index(MakeTermcap(aflag), '=')) == NULL)
+ return;
+ p++;
+ /* write termcap entry with wrapping */
+ while ((pe = index(p, ':')))
+ {
+ n = pe - p + 1;
+ if ((col > 8) && ((col + n) > TERMCAP_MAX_WIDTH))
+ {
+ fwrite("\\\n\t:", 1, 4, f);
+ col = 8;
+ }
+ fwrite(p, 1, n, f);
+ col += n;
+ p = ++pe;
+ }
+ if(*p)
+ fwrite(p, 1, strlen(p), f);
+ fputc('\n', f);
+}
+
static void MakeString(char *cap, char *buf, int buflen, char *s)
{
char *p, *pmax;