screen-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[screen-devel] [PATCH] Create TERMCAP entries limited to 1023 bytes by d


From: Marcin Cieślak
Subject: [screen-devel] [PATCH] Create TERMCAP entries limited to 1023 bytes by default.
Date: Tue, 5 Nov 2019 17:00:32 +0000

From: Scott Shambarger <address@hidden>

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 <address@hidden>
---
 src/dumptermcap.h |  6 ++++++
 src/fileio.c      |  6 ++----
 src/os.h          |  2 +-
 src/term.c        |  1 +
 src/termcap.c     | 51 ++++++++++++++++++++++++++++++++++++-----------
 5 files changed, 49 insertions(+), 17 deletions(-)
 create mode 100644 src/dumptermcap.h

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 df8df82..92bf844 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 1953a72..a39552d 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 f8edff9..4bd8077 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 (address@hidden) */
+/* define T_FEXTRA */
   { "F3", T_STR  },
   { "F4", T_STR  },
   { "F5", T_STR  },
diff --git a/src/termcap.c b/src/termcap.c
index 0253cf1..251be2b 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;
-- 
2.23.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]