summaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-12 19:06:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-12 19:06:50 -0800
commitfdb885e3ac75f901e3d51a0bf5bcef9a8969e847 (patch)
tree53b5d8824e4703f9d1baf66e82e24529b52c16e2 /debug.c
parent2484f339278a684bab095d5c21d85b21d18b3d06 (diff)
downloadtxr-fdb885e3ac75f901e3d51a0bf5bcef9a8969e847.tar.gz
txr-fdb885e3ac75f901e3d51a0bf5bcef9a8969e847.tar.bz2
txr-fdb885e3ac75f901e3d51a0bf5bcef9a8969e847.zip
* debug.c (breakpoints, last_command): linkage changed to static.
(cols): New static variable. (debug): Print context intelligently, fitting into the width of the screen. (debug_init): Try to get terminal width, from the COLUMNS variable.
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/debug.c b/debug.c
index 1e9edb2a..55e7fb4e 100644
--- a/debug.c
+++ b/debug.c
@@ -19,8 +19,9 @@ int debug_depth;
val debug_block_s;
static int step_mode;
static int next_depth = -1;
-val breakpoints;
-val last_command;
+static val breakpoints;
+static val last_command;
+static int cols = 80;
static void help(val stream)
{
@@ -81,8 +82,17 @@ val debug(val form, val bindings, val data, val line, val pos, val base)
if (print_data) {
if (data && pos) {
- val prefix = sub_str(data, zero, pos);
- val suffix = sub_str(data, pos, nil);
+ val half = num((cols - 8) / 2);
+ val full = num((cols - 8));
+ val prefix, suffix;
+
+ if (lt(pos, half)) {
+ prefix = sub_str(data, zero, pos);
+ suffix = sub_str(data, pos, full);
+ } else {
+ prefix = sub_str(data, minus(pos, half), pos);
+ suffix = sub_str(data, pos, plus(pos, half));
+ }
format(std_output, lit("data (~s:~s):\n~s . ~s\n"),
line, plus(pos, base), prefix, suffix, nao);
@@ -169,4 +179,11 @@ void debug_init(void)
step_mode = 1;
protect(&breakpoints, &last_command, (val *) 0);
debug_block_s = intern(lit("debug-block"), system_package);
+ {
+ char *columns = getenv("COLUMNS");
+ if (columns)
+ cols = atoi(columns);
+ if (cols < 40)
+ cols = 40;
+ }
}