]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
quake3/help: move away from termcap
authorAntoine Fontaine <antoine.fontaine@epfl.ch>
Mon, 3 May 2021 19:52:15 +0000 (21:52 +0200)
committerThomas Debesse <dev@illwieckz.net>
Mon, 3 May 2021 21:28:31 +0000 (23:28 +0200)
termcap is old and crusty. terminfo seems more recent (lol), but maybe
we can get away without adding any dependency :)

On my system, no -ltermcap exists. (Well, except a compat one provided
by zsh for some reason.)

tools/quake3/CMakeLists.txt
tools/quake3/q3map2/help.c

index 4b30535a3477fd2656598d5444d55bc099cc9b30..638d867c4969dd48053d2e6454ec00fac739f98c 100644 (file)
@@ -193,4 +193,4 @@ if (UNIX)
     target_link_libraries(q3data m)
 endif ()
 
     target_link_libraries(q3data m)
 endif ()
 
-target_link_libraries(q3map2 termcap)
+target_link_libraries(q3map2)
index fc77050a1025dfa68fff11161678993b13ac16fa..f4fd717b7ba9e856aa9c11c3bdcec29ac79c240e 100644 (file)
@@ -31,9 +31,8 @@
 /* dependencies */
 #include "q3map2.h"
 
 /* dependencies */
 #include "q3map2.h"
 
-
-
-unsigned terminalColumns = 80;
+#include <sys/ioctl.h>
+static unsigned terminalColumns = 80;
 
 struct HelpOption
 {
 
 struct HelpOption
 {
@@ -41,6 +40,7 @@ struct HelpOption
        const char* description;
 };
 
        const char* description;
 };
 
+// FIXME: low column width cause an endless loop
 void HelpOptions(const char* group_name, int indentation, int width, struct HelpOption* options, int count)
 {
        indentation *= 2;
 void HelpOptions(const char* group_name, int indentation, int width, struct HelpOption* options, int count)
 {
        indentation *= 2;
@@ -457,18 +457,16 @@ void HelpGames()
        printf("\n\n");
 }
 
        printf("\n\n");
 }
 
-#include <termcap.h>
-
 void HelpMain(const char* arg)
 {
        printf("Usage: q3map2 [stage] [common options...] [stage options...] [stage source file]\n");
        printf("       q3map2 -help [stage]\n");
        printf("       q3map2 -help all\n\n");
 
 void HelpMain(const char* arg)
 {
        printf("Usage: q3map2 [stage] [common options...] [stage options...] [stage source file]\n");
        printf("       q3map2 -help [stage]\n");
        printf("       q3map2 -help all\n\n");
 
-       static char termbuf[2048];
-       char *termtype = getenv("TERM");
-       if (tgetent(termbuf, termtype) >= 0) {
-               terminalColumns = tgetnum("co");
+       struct winsize ws;
+       ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+       if (ws.ws_col > 60) {
+               terminalColumns = ws.ws_col;
        }
 
        HelpCommon();
        }
 
        HelpCommon();