[Orxonox-commit 2717] r7422 - code/trunk/src/libraries/core/command
adrfried at orxonox.net
adrfried at orxonox.net
Sun Sep 12 07:55:04 CEST 2010
Author: adrfried
Date: 2010-09-12 07:55:04 +0200 (Sun, 12 Sep 2010)
New Revision: 7422
Modified:
code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
Log:
Improve getTerminalSize
Width and height never get 0 anymore, this fixes a bug with a division
by zero in a special terminal reporting zero width.
Modified: code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
===================================================================
--- code/trunk/src/libraries/core/command/IOConsolePOSIX.cc 2010-09-11 22:47:30 UTC (rev 7421)
+++ code/trunk/src/libraries/core/command/IOConsolePOSIX.cc 2010-09-12 05:55:04 UTC (rev 7422)
@@ -318,13 +318,15 @@
void IOConsole::getTerminalSize()
{
+ this->terminalWidth_ = 0;
+ this->terminalHeight_ = 0;
+
#ifdef TIOCGSIZE
struct ttysize win;
if (!ioctl(STDIN_FILENO, TIOCGSIZE, &win))
{
this->terminalWidth_ = win.ts_cols;
this->terminalHeight_ = win.ts_lines;
- return;
}
#elif defined TIOCGWINSZ
struct winsize win;
@@ -332,17 +334,18 @@
{
this->terminalWidth_ = win.ws_col;
this->terminalHeight_ = win.ws_row;
- return;
}
-#else
- const char* s = getenv("COLUMNS");
- this->terminalWidth_ = s ? strtol(s, NULL, 10) : 80;
- s = getenv("LINES");
- this->terminalHeight_ = s ? strtol(s, NULL, 10) : 24;
- return;
#endif
- this->terminalWidth_ = 80;
- this->terminalHeight_ = 24;
+
+ const char* s;
+ if (!this->terminalWidth_ && (s = getenv("COLUMNS")))
+ this->terminalWidth_ = strtol(s, NULL, 10);
+ if (!this->terminalWidth_)
+ this->terminalWidth_ = 80;
+ if (!this->terminalHeight_ && (s = getenv("LINES")))
+ this->terminalHeight_ = strtol(s, NULL, 10);
+ if (!this->terminalHeight_)
+ this->terminalHeight_ = 24;
}
inline bool IOConsole::willPrintStatusLines()
More information about the Orxonox-commit
mailing list