summaryrefslogtreecommitdiff
path: root/src/chroot-tools/indent
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/indent')
-rwxr-xr-xsrc/chroot-tools/indent57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/chroot-tools/indent b/src/chroot-tools/indent
new file mode 100755
index 0000000..0f047c6
--- /dev/null
+++ b/src/chroot-tools/indent
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+# Copyright (C) 2013 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# License: GNU GPLv3+
+#
+# This file is part of Parabola.
+#
+# Parabola is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Parabola is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
+
+use warnings;
+use strict;
+
+use constant BUFFER_SIZE => 40;
+binmode(STDIN);
+binmode(STDOUT);
+
+exit(1) if ($#ARGV != 0);
+my $indent = $ARGV[0];
+
+# 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;
+while (1) {
+ $size = sysread(STDIN, $buffer, BUFFER_SIZE);
+ last if ($size < 1);
+ for (0..$size-1) {
+ $c = substr($buffer, $_, 1);
+ if ($c eq "\n") {
+ syswrite(STDOUT, $indent) if ($print_indent == 0);
+ syswrite(STDOUT, $c, 1);
+ $print_indent = 0;
+ } elsif ($c eq "\r") {
+ syswrite(STDOUT, $c, 1);
+ $print_indent = 1 if ($print_indent == 2);
+ } else {
+ syswrite(STDOUT, $indent) if ($print_indent < 2);
+ syswrite(STDOUT, $c, 1);
+ $print_indent = 2;
+ }
+ }
+}