1 #!/usr/bin/env perl 1 #!/usr/bin/env perl 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # Prefix all lines with "# ", unbuffered. Comm 3 # Prefix all lines with "# ", unbuffered. Command being piped in may need 4 # to have unbuffering forced with "stdbuf -i0 4 # to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd". 5 use strict; 5 use strict; 6 use IO::Handle; 6 use IO::Handle; 7 7 8 binmode STDIN; 8 binmode STDIN; 9 binmode STDOUT; 9 binmode STDOUT; 10 10 11 STDOUT->autoflush(1); 11 STDOUT->autoflush(1); 12 12 13 my $needed = 1; 13 my $needed = 1; 14 while (1) { 14 while (1) { 15 my $char; 15 my $char; 16 my $bytes = sysread(STDIN, $char, 1); 16 my $bytes = sysread(STDIN, $char, 1); 17 exit 0 if ($bytes == 0); 17 exit 0 if ($bytes == 0); 18 if ($needed) { 18 if ($needed) { 19 print "# "; 19 print "# "; 20 $needed = 0; 20 $needed = 0; 21 } 21 } 22 print $char; 22 print $char; 23 $needed = 1 if ($char eq "\n"); 23 $needed = 1 if ($char eq "\n"); 24 } 24 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.