summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/cio.cc
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/cio.cc')
-rw-r--r--crawl-ref/source/cio.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/crawl-ref/source/cio.cc b/crawl-ref/source/cio.cc
index e74e6dbd3e..2a3cfea496 100644
--- a/crawl-ref/source/cio.cc
+++ b/crawl-ref/source/cio.cc
@@ -184,6 +184,51 @@ void cursorxy(int x, int y)
#endif
}
+// cprintf that stops outputting when wrapped
+// Conceptually very similar to wrapcprintf()
+int nowrapcprintf( int wrapcol, const char *s, ... )
+{
+ char buf[1000]; // Hard max
+
+ va_list args;
+ va_start(args, s);
+ // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
+ const int len = vsnprintf(buf, sizeof buf, s, args);
+ va_end(args);
+
+ // Sanity checking to prevent buffer overflows
+ const int maxlen = std::min( std::max( wrapcol + 1 - wherex(), 0 ), len );
+
+ // Force the string to terminate at maxlen
+ buf[maxlen] = 0;
+
+ cprintf("%s", buf);
+ return std::min(len, maxlen);
+}
+
+// convenience wrapper (hah) for nowrapcprintf
+// FIXME: should pass off to nowrapcprintf() instead of doing it manually
+int nowrap_eol_cprintf( const char *s, ... )
+{
+ const int wrapcol = get_number_of_cols() - 1;
+ char buf[1000]; // Hard max
+
+ va_list args;
+ va_start(args, s);
+ // XXX: If snprintf isn't available, vsnprintf probably isn't, either.
+ const int len = vsnprintf(buf, sizeof buf, s, args);
+ va_end(args);
+
+ // Sanity checking to prevent buffer overflows
+ const int maxlen = std::min( std::max( wrapcol + 1 - wherex(), 0 ), len );
+
+ // Force the string to terminate at maxlen
+ buf[maxlen] = 0;
+
+ cprintf("%s", buf);
+ return std::min(len, maxlen);
+}
+
// cprintf that knows how to wrap down lines (primitive, but what the heck)
int wrapcprintf( int wrapcol, const char *s, ... )
{