diff options
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-x | src/chroot-tools/indent | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/chroot-tools/indent b/src/chroot-tools/indent index ffec4d5..9a6247f 100755 --- a/src/chroot-tools/indent +++ b/src/chroot-tools/indent @@ -20,6 +20,7 @@ use warnings; use strict; + use constant BUFFER_SIZE => 40; binmode(STDIN); binmode(STDOUT); @@ -27,7 +28,11 @@ binmode(STDOUT); exit(1) if ($#ARGV != 0); my $indent = $ARGV[0]; -my $print_indent = 1; +# 0: no indent has been printed for this line, an indent WILL need to be printed +# 1: an indent needs to be printed for this line IFF there is any more output on it +# 2: no indent (currently) needs to be printed for this line +my $print_indent = 0; + my $buffer; my $size; my $c; @@ -37,16 +42,16 @@ while (1) { for (0..$size-1) { $c = substr($buffer, $_, 1); if ($c eq "\n") { - syswrite(STDOUT, $indent) if ($print_indent); + syswrite(STDOUT, $indent) if ($print_indent == 0); syswrite(STDOUT, $c, 1); - $print_indent = 1; + $print_indent = 0; } elsif ($c eq "\r") { syswrite(STDOUT, $c, 1); $print_indent = 1; } else { - syswrite(STDOUT, $indent) if ($print_indent); + syswrite(STDOUT, $indent) if ($print_indent < 2); syswrite(STDOUT, $c, 1); - $print_indent = 0; + $print_indent = 2; } } } |