-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreg_path_only
31 lines (25 loc) · 1.25 KB
/
reg_path_only
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl
# use case: accept a UTF-16LE .reg file for "all environment variables" and remove all variables/values except for "Path"
# oh the humanity!!! http://blogs.perl.org/users/yary/2016/01/utf-16-and-windows-crlf-oh-my.html
# oh the insanity!!! http://blogs.perl.org/users/yary/2016/01/utf-16-and-windows-crlf-oh-my.html
# this solution violates
# use strict;
# use warnings;
# so both must be removed.
# NB!!!!! input .reg file MUST be passed via STDIN!!! If you pass a filename, this program will not error out, but will write UNENCODED (invalid) output
# NB!!!!! input .reg file MUST be passed via STDIN!!! If you pass a filename, this program will not error out, but will write UNENCODED (invalid) output
# NB!!!!! input .reg file MUST be passed via STDIN!!! If you pass a filename, this program will not error out, but will write UNENCODED (invalid) output
my $varnm = shift @ARGV // "Path";
print STDERR "varnm $varnm\n";
binmode($_,':raw:encoding(UTF-16LE):crlf') for(STDIN,STDOUT);
my $q2 = '"';
while ( <> ) {
if( $. <= 3 ) { # first 3 lines of .reg file are necessary boilerplate
print;
next;
}
if( /^\Q${q2}${varnm}${q2}/io .. not /[0-9a-f]{2},\\$/ ) {
print;
next;
}
}