From 86ee0a5da2a3a02d291ae40c8570bcd97ff066de Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 1 Oct 2013 20:21:07 -0400 Subject: libremakepkg: when prefixing output with ' | ', do better than sed. There are two downsizes to using sed; it line-buffers, and (the existing pattern) doesn't handle '\r'. So, now I've included a Perl helper program to do a better job. I'd originally written it in C, and while that version was faster (the Perl version stutters occasionally), it required recompilation for different architectures. I could have gotten around that with tcc, but I didn't want to add any dependencies. Which is why I settled on Perl. It's part of group=(base), and it is required by packages in group=(base-devel), so I can count on it always being there. It doesn't handle every movement character, just '\n' and '\r', but that's enough for curl and pacman. --- src/chroot-tools/indent | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 src/chroot-tools/indent (limited to 'src/chroot-tools/indent') diff --git a/src/chroot-tools/indent b/src/chroot-tools/indent new file mode 100755 index 0000000..5a7f654 --- /dev/null +++ b/src/chroot-tools/indent @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use constant BUFFER_SIZE => 40; +binmode(STDIN); +binmode(STDOUT); + +exit(1) if ($#ARGV != 0); +my $indent = $ARGV[0]; + +my $print_indent = 1; +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); + syswrite(STDOUT, $c, 1); + $print_indent = 1; + } elsif ($c eq "\r") { + syswrite(STDOUT, $c, 1); + $print_indent = 1; + } else { + syswrite(STDOUT, $indent) if ($print_indent); + syswrite(STDOUT, $c, 1); + $print_indent = 0; + } + } +} -- cgit v1.2.2