Blame
Date:
Fri Aug 26 22:03:55 2022 UTC
Message:
refactor the parsing into the module change the mscan format string to siplify the parsing, and refactor the parsing code into the module for reuse. pe is an exception in that it doesn't care about the format string, it just need to decide if the current line starts a new thread or not, that's why it doesn't use the newly introduced `parse'. The new format simplifies pe too though.
01
2022-08-25
op
#!/usr/bin/env perl
02
2022-08-25
op
03
2022-08-25
op
use open ":std", ":encoding(UTF-8)";
04
2022-08-25
op
use strict;
05
2022-08-25
op
use warnings;
06
2022-08-25
op
use v5.32;
07
2022-08-25
op
use IO::Poll qw(POLLOUT);
08
2022-08-25
op
09
2022-08-25
op
use OpenBSD::Pledge;
10
2022-08-25
op
use OpenBSD::Unveil;
11
2022-08-25
op
12
2022-08-25
op
my $jobs = $ENV{'MAKE_JOBS'} // 1;
13
2022-08-25
op
14
2022-08-25
op
my $poll = IO::Poll->new();
15
2022-08-25
op
for (1..$jobs) {
16
2022-08-25
op
open(my $kid, '|-', './mexp') or die "can't exec ./mexp: $!";
17
2022-08-25
op
$poll->mask($kid => POLLOUT);
18
2022-08-25
op
}
19
2022-08-25
op
20
2022-08-25
op
sub process {
21
2022-08-25
op
die "poll: $!" if $poll->poll() == -1;
22
2022-08-25
op
my @handles = $poll->handles(POLLOUT) or die "no procs ready?";
23
2022-08-25
op
my $handle = $handles[int(rand(@handles))];
24
2022-08-26
op
print $handle $_ foreach @_;
25
2022-08-25
op
}
26
2022-08-25
op
27
2022-08-25
op
unveil("./mexp", "rx") or die "unveil mexp: $!";
28
2022-08-25
op
pledge("stdio proc exec") or die "pledge: $!";
29
2022-08-25
op
30
2022-08-25
op
my @thread;
31
2022-08-25
op
while (<>) {
32
2022-08-25
op
print; # continue the pipeline
33
2022-08-25
op
34
2022-08-26
op
my $new_thread = m/^-/;
35
2022-08-26
op
if ($new_thread && @thread) {
36
2022-08-25
op
process @thread;
37
2022-08-25
op
@thread = ();
38
2022-08-25
op
}
39
2022-08-25
op
40
2022-08-25
op
push @thread, $_;
41
2022-08-25
op
}
42
2022-08-25
op
43
2022-08-25
op
process @thread if @thread;
Omar Polo