]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/help.c
q3map2/help: only read terminal columns using ioctl on Posix systems
[xonotic/netradiant.git] / tools / quake3 / q3map2 / help.c
index fc77050a1025dfa68fff11161678993b13ac16fa..60631e3d72f175a38c581b28a50df232ea8289ab 100644 (file)
 /* dependencies */
 #include "q3map2.h"
 
+#if GDEF_OS_POSIX
+#include <sys/ioctl.h>
+#endif // GDEF_OS_POSIX
 
-
-unsigned terminalColumns = 80;
+static unsigned terminalColumns = 80;
 
 struct HelpOption
 {
@@ -41,6 +43,7 @@ struct HelpOption
        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;
@@ -457,19 +460,19 @@ void HelpGames()
        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");
 
-       static char termbuf[2048];
-       char *termtype = getenv("TERM");
-       if (tgetent(termbuf, termtype) >= 0) {
-               terminalColumns = tgetnum("co");
+#if GDEF_OS_POSIX
+       struct winsize ws;
+       ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+       if (ws.ws_col > 60) {
+               terminalColumns = ws.ws_col;
        }
+#endif // GDEF_OS_POSIX
 
        HelpCommon();