1*c25ce589SFinn Behrens#!/usr/bin/env perl 25c069b6dSKees Cook# SPDX-License-Identifier: GPL-2.0 35c069b6dSKees Cook# Prefix all lines with "# ", unbuffered. Command being piped in may need 45c069b6dSKees Cook# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd". 55c069b6dSKees Cookuse strict; 64eac7344SSeongJae Parkuse IO::Handle; 75c069b6dSKees Cook 85c069b6dSKees Cookbinmode STDIN; 95c069b6dSKees Cookbinmode STDOUT; 105c069b6dSKees Cook 115c069b6dSKees CookSTDOUT->autoflush(1); 125c069b6dSKees Cook 135c069b6dSKees Cookmy $needed = 1; 145c069b6dSKees Cookwhile (1) { 155c069b6dSKees Cook my $char; 165c069b6dSKees Cook my $bytes = sysread(STDIN, $char, 1); 175c069b6dSKees Cook exit 0 if ($bytes == 0); 185c069b6dSKees Cook if ($needed) { 195c069b6dSKees Cook print "# "; 205c069b6dSKees Cook $needed = 0; 215c069b6dSKees Cook } 225c069b6dSKees Cook print $char; 235c069b6dSKees Cook $needed = 1 if ($char eq "\n"); 245c069b6dSKees Cook} 25