aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-03 03:52:38 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-03 03:52:38 +0000
commit44cf08ecf648210347191942b1664e36d46290c5 (patch)
treed7d418e449ac56965682793b51cc98e608e453c4
parentad04e6737e3267a502970acac8abb54b0c899db6 (diff)
Respect the COLUMNS environment variable for word-wrapping (so we get
word-wrapping by default in Emacs; yay!). Thanks, Daniel. Use LLVM's System layer rather than calling isatty() directly. Fix a thinko in printing the indentation string that was causing some weird output. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70654 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp3
-rw-r--r--tools/clang-cc/clang-cc.cpp17
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 017ead43e4..b8c10b536b 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -570,7 +570,8 @@ static bool PrintWordWrapped(llvm::raw_ostream &OS,
// This word does not fit on the current line, so wrap to the next
// line.
- OS << '\n' << IndentStr.begin();
+ OS << '\n';
+ OS.write(&IndentStr[0], Indentation);
OS.write(&Str[WordStart], WordLength);
Column = Indentation + WordLength;
Wrapped = true;
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index e26a1d9b3f..2ef1087e5c 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -60,12 +60,12 @@
#include "llvm/Support/Timer.h"
#include "llvm/System/Host.h"
#include "llvm/System/Path.h"
+#include "llvm/System/Process.h"
#include "llvm/System/Signals.h"
#include <cstdlib>
-#if HAVE_UNISTD_H
-# include <unistd.h>
-# include <sys/ioctl.h>
+#if HAVE_SYS_TYPES_H
# include <sys/types.h>
+# include <sys/ioctl.h>
#endif
using namespace clang;
@@ -1876,11 +1876,18 @@ InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
/// \returns the width of the terminal (in characters), if there is a
/// terminal. If there is no terminal, returns 0.
static unsigned getTerminalWidth() {
-#if HAVE_UNISTD_H
+ // If COLUMNS is defined in the environment, wrap to that many columns.
+ if (const char *ColumnsStr = std::getenv("COLUMNS")) {
+ int Columns = atoi(ColumnsStr);
+ if (Columns > 0)
+ return Columns;
+ }
+
// Is this a terminal? If not, don't wrap by default.
- if (!isatty(/* Standard Error=*/2))
+ if (!llvm::sys::Process::StandardErrIsDisplayed())
return 0;
+#if HAVE_SYS_TYPES_H
// Try to determine the width of the terminal.
struct winsize ws;
unsigned Columns = 80; // A guess, in case the ioctl fails.