xref: /kernel/linux/linux-6.6/tools/testing/selftests/kselftest/prefix.pl
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /kernel/linux/linux-6.6/tools/testing/selftests/kselftest/
162306a36Sopenharmony_ci#!/usr/bin/env perl
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
362306a36Sopenharmony_ci# Prefix all lines with "# ", unbuffered. Command being piped in may need
462306a36Sopenharmony_ci# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
562306a36Sopenharmony_ciuse strict;
662306a36Sopenharmony_ciuse IO::Handle;
762306a36Sopenharmony_ci
862306a36Sopenharmony_cibinmode STDIN;
962306a36Sopenharmony_cibinmode STDOUT;
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciSTDOUT->autoflush(1);
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cimy $needed = 1;
1462306a36Sopenharmony_ciwhile (1) {
1562306a36Sopenharmony_ci	my $char;
1662306a36Sopenharmony_ci	my $bytes = sysread(STDIN, $char, 1);
1762306a36Sopenharmony_ci	exit 0 if ($bytes == 0);
1862306a36Sopenharmony_ci	if ($needed) {
1962306a36Sopenharmony_ci		print "# ";
2062306a36Sopenharmony_ci		$needed = 0;
2162306a36Sopenharmony_ci	}
2262306a36Sopenharmony_ci	print $char;
2362306a36Sopenharmony_ci	$needed = 1 if ($char eq "\n");
2462306a36Sopenharmony_ci}
25

Indexes created Thu Nov 07 10:32:03 CST 2024