Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/env perl
0002 # SPDX-License-Identifier: GPL-2.0
0003 # Prefix all lines with "# ", unbuffered. Command being piped in may need
0004 # to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
0005 use strict;
0006 use IO::Handle;
0007 
0008 binmode STDIN;
0009 binmode STDOUT;
0010 
0011 STDOUT->autoflush(1);
0012 
0013 my $needed = 1;
0014 while (1) {
0015     my $char;
0016     my $bytes = sysread(STDIN, $char, 1);
0017     exit 0 if ($bytes == 0);
0018     if ($needed) {
0019         print "# ";
0020         $needed = 0;
0021     }
0022     print $char;
0023     $needed = 1 if ($char eq "\n");
0024 }