diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-11-30 08:28:39 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-11-30 08:28:39 -0500 |
| commit | 93b0c54145b52a510906d8787bb176902fe1e81a (patch) | |
| tree | 662e2c88d15d2d2c61ffa38819498b75a61be597 | |
| parent | 0c26ffc0ee06eff0e7ef77947be98e0756b3dfd6 (diff) | |
| download | sbo-maintainer-tools-93b0c54145b52a510906d8787bb176902fe1e81a.tar.gz | |
sbofixinfo: replace tab indents with 2 spaces each.
| -rwxr-xr-x | sbofixinfo | 442 |
1 files changed, 221 insertions, 221 deletions
@@ -148,58 +148,58 @@ B<sbolint>(1), B<sbopkglint>(1), B<sbodl>(1), B<sbopkg>(8), B<sboinstall>(1) ($SELF = $0) =~ s,.*/,,; @keyorder = qw{ - PRGNAM - VERSION - HOMEPAGE - DOWNLOAD - MD5SUM - DOWNLOAD_x86_64 - MD5SUM_x86_64 - REQUIRES - MAINTAINER - EMAIL + PRGNAM + VERSION + HOMEPAGE + DOWNLOAD + MD5SUM + DOWNLOAD_x86_64 + MD5SUM_x86_64 + REQUIRES + MAINTAINER + EMAIL }; sub fix_github_url { - my $url = shift; - return $url unless $url =~ m,/archive/,; + my $url = shift; + return $url unless $url =~ m,/archive/,; - $url =~ s,refs/tags/,,; + $url =~ s,refs/tags/,,; - (my $proto, undef, undef, $user, $proj, undef, $tag, $filename) = split /\//, $url; - return $url if defined $filename; + (my $proto, undef, undef, $user, $proj, undef, $tag, $filename) = split /\//, $url; + return $url if defined $filename; - return $url unless $tag =~ s,\.tar\.gz$,,; - my $ver = $tag; - $ver =~ s,^v(\d),$1,; + return $url unless $tag =~ s,\.tar\.gz$,,; + my $ver = $tag; + $ver =~ s,^v(\d),$1,; - $url = "https://github.com/$user/$proj/archive/$tag/$proj-$ver.tar.gz"; - return $url; + $url = "https://github.com/$user/$proj/archive/$tag/$proj-$ver.tar.gz"; + return $url; } ## main() $arg0 = @ARGV ? $ARGV[0] : undef; for($arg0) { - defined || last; - /^--?(?:v|ver.*)$/ && do { - print "$VERSION\n"; - exit 0; - }; - /^--?(?:h|help|doc)$/ && do { - exec("perldoc $0") || die "$SELF: can't exec perldoc\n"; - }; - /^--?(?:m|man)$/ && do { - exec("pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION $0") || - die "$SELF: can't exec pod2man\n"; - }; - # undocumented option: - /^--keytest/ && do { - while(<STDIN>) { - chomp; - fix_key($_); - } - exit 0; - }; + defined || last; + /^--?(?:v|ver.*)$/ && do { + print "$VERSION\n"; + exit 0; + }; + /^--?(?:h|help|doc)$/ && do { + exec("perldoc $0") || die "$SELF: can't exec perldoc\n"; + }; + /^--?(?:m|man)$/ && do { + exec("pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION $0") || + die "$SELF: can't exec pod2man\n"; + }; + # undocumented option: + /^--keytest/ && do { + while(<STDIN>) { + chomp; + fix_key($_); + } + exit 0; + }; } push @ARGV, "." unless @ARGV; @@ -209,191 +209,191 @@ fix_info($_) for @ARGV; exit $errcnt; sub fix_key { - my $key = shift; - my $newkey = fix_key_guts($key); - if($key ne $newkey) { - warn "$SELF: typo correction: $key => $newkey\n"; - } - return $newkey; + my $key = shift; + my $newkey = fix_key_guts($key); + if($key ne $newkey) { + warn "$SELF: typo correction: $key => $newkey\n"; + } + return $newkey; } sub fix_key_guts { - my $key = shift; - - # fix case if needed - $key =~ tr/-a-wXyz/_A-WxYZ/; # leave "x" lowercase! - - # if it's a recognized key, use it - if(grep { $_ eq $key } @keyorder) { - return $key; - } - - # if it's not a recognized key, try to detect typos. - # most of the keys look different enough that the matching algo - # below does OK with them, except if someone types MAIL in place - # of EMAIL (the algo will match MAINTAINER, not EMAIL). so special - # case it here: - if((length $key < 8) && ($key =~ /^[ME]+[AI]+.?L.?/)) { - return "EMAIL"; - } - - my $x64 = 0; - if(/_x|_\d|x\d|86|68|64|46/) { - $x64 = 1; - } - - my $bestmatch; - my $bmcount = 0; - - # typo-correction matching algorithm: - for my $candidate (@keyorder) { - next if $candidate =~ /x86/; - - #warn "checking $key against $candidate\n"; - - # if the first 2 characters match, assume the candidate is OK. - if(substr($key, 0, 2) eq substr($candidate, 0, 2)) { - $bestmatch = $candidate; - last; - } - - # get rid of extraneous characters (not in the candidate key). - my $trykey = eval "\$key =~ tr/$candidate//cdr"; - - # if nothing's left, this is obviously the wrong candidate. - next unless length $trykey; - - #warn " trykey is " . $trykey; - - if(length($trykey) > $bmcount) { - $bestmatch = $candidate; - $bmcount = length($trykey); - } - } - - if(defined $bestmatch) { - $key = $bestmatch; - if(($key eq 'DOWNLOAD') || ($key eq 'MD5SUM')) { - $key .= "_x86_64" if $x64; - } - } - - # if nothing matched, the key gets returned as-is. - return $key; + my $key = shift; + + # fix case if needed + $key =~ tr/-a-wXyz/_A-WxYZ/; # leave "x" lowercase! + + # if it's a recognized key, use it + if(grep { $_ eq $key } @keyorder) { + return $key; + } + + # if it's not a recognized key, try to detect typos. + # most of the keys look different enough that the matching algo + # below does OK with them, except if someone types MAIL in place + # of EMAIL (the algo will match MAINTAINER, not EMAIL). so special + # case it here: + if((length $key < 8) && ($key =~ /^[ME]+[AI]+.?L.?/)) { + return "EMAIL"; + } + + my $x64 = 0; + if(/_x|_\d|x\d|86|68|64|46/) { + $x64 = 1; + } + + my $bestmatch; + my $bmcount = 0; + + # typo-correction matching algorithm: + for my $candidate (@keyorder) { + next if $candidate =~ /x86/; + + #warn "checking $key against $candidate\n"; + + # if the first 2 characters match, assume the candidate is OK. + if(substr($key, 0, 2) eq substr($candidate, 0, 2)) { + $bestmatch = $candidate; + last; + } + + # get rid of extraneous characters (not in the candidate key). + my $trykey = eval "\$key =~ tr/$candidate//cdr"; + + # if nothing's left, this is obviously the wrong candidate. + next unless length $trykey; + + #warn " trykey is " . $trykey; + + if(length($trykey) > $bmcount) { + $bestmatch = $candidate; + $bmcount = length($trykey); + } + } + + if(defined $bestmatch) { + $key = $bestmatch; + if(($key eq 'DOWNLOAD') || ($key eq 'MD5SUM')) { + $key .= "_x86_64" if $x64; + } + } + + # if nothing matched, the key gets returned as-is. + return $key; } sub fix_info { - my $file = shift; - if(-d $file) { - my $dir = `realpath $file`; - chomp $dir; - (my $name = $dir) =~ s,.*/,,; - $file = "$dir/$name.info"; - } - open my $fh, "<$file" or do { - warn "$SELF: can't read $file: $!\n"; - $errcnt++; - return; - }; - - # this only gets used if the .info file is missing the PRGNAM key. - my $prgnam_guess = $file; - $prgnam_guess =~ s,.*/,,; - $prgnam_guess =~ s,\.[^.]*$,,; - - my $key = 'INVALID_STUFF'; - my %info; - - # read through the whole file, extracting the values of all the - # keys, stash them in a hashtable. Multi-valued keys will be stored - # with carriage returns as a delimiter (they're otherwise not allowed). - # Quotes, backslashes, etc aren't stored (only the actual values). - while(<$fh>) { - chomp; - s/\r//g; # no DOS line endings - next if /^\s*$/; # ignore blank lines entirely - - s/(?:^\s+|\s+$)//g; # remove leading/trailing spaces - s/^(\w+)\s*=\s*/$1=/; # remove spaces around = - - if(/^(\w+)=(.*)$/) { - $key = $1; - $val = $2; - $val =~ s,(?:^['"]|['"]$),,g; # remove quotes around value - $val =~ s,[\s\\]*$,,; # remove any line-continuation backslash - - $key = fix_key($key); - - if($key =~ /^MD5SUM/) { - $val =~ tr/A-Z/a-z/; - } - - # multiple valued keys all on the same line get split up into - # multi-line values. This only applies to download and md5sum - # values (which can't contain spaces anyway). - if($key =~ /^(?:DOWNLOAD|MD5SUM)/) { - $val =~ s/\s+/\r/g; - } - - $info{$key} = $val; - } else { - s,[\s\\\"]*$,,; - $info{$key} .= "\r$_"; - } - } - close $fh; - - # 20240331 bkw: fix github URLs, if needed. - for my $key (qw/DOWNLOAD DOWNLOAD_x86_64/) { - if($info{$key}) { - my @urls = split " ", $info{$key}; - my @newurls; - for my $url (@urls) { - my $newurl = $url; - if($url =~ m,https://github.com/,) { - $newurl = fix_github_url($url); - } - push @newurls, $newurl; - } - $info{$key} = join "\r", @newurls; - } - } - - system("mv $file $file.bak"); - - open $fh, ">$file" or do { - warn "$SELF: can't write $file: $!\n"; - $errcnt++; - return; - }; - - if(not defined $info{'PRGNAM'}) { - warn "$SELF: $file missing PRGNAM, guessing \"$prgnam_guess\" from filename.\n"; - $info{'PRGNAM'} = $prgnam_guess; - } - - # Reconstitute info file from the values, with correct indentation and - # quoting, backslashes, etc. - for $key (@keyorder) { - $info{$key} ||= ""; # avoid unitialized value on missing key - my @values = split /\r/, $info{$key}; - if(@values == 0) { - print $fh "$key=\"\"\n"; - } elsif(@values == 1) { - print $fh "$key=\"$values[0]\"\n"; - } else { - my $indent = " " x (length($key) + 2); - my $first = shift @values; - my $last = pop @values; - print $fh "$key=\"$first \\\n"; - print $fh "$indent$_ \\\n" for @values; - print $fh "$indent$last\"\n"; - } - } - - my $result = system("diff -u --color $file.bak $file"); - if($result == 0) { - unlink("$file.bak"); - warn "$SELF: no changes to $file\n"; - } + my $file = shift; + if(-d $file) { + my $dir = `realpath $file`; + chomp $dir; + (my $name = $dir) =~ s,.*/,,; + $file = "$dir/$name.info"; + } + open my $fh, "<$file" or do { + warn "$SELF: can't read $file: $!\n"; + $errcnt++; + return; + }; + + # this only gets used if the .info file is missing the PRGNAM key. + my $prgnam_guess = $file; + $prgnam_guess =~ s,.*/,,; + $prgnam_guess =~ s,\.[^.]*$,,; + + my $key = 'INVALID_STUFF'; + my %info; + + # read through the whole file, extracting the values of all the + # keys, stash them in a hashtable. Multi-valued keys will be stored + # with carriage returns as a delimiter (they're otherwise not allowed). + # Quotes, backslashes, etc aren't stored (only the actual values). + while(<$fh>) { + chomp; + s/\r//g; # no DOS line endings + next if /^\s*$/; # ignore blank lines entirely + + s/(?:^\s+|\s+$)//g; # remove leading/trailing spaces + s/^(\w+)\s*=\s*/$1=/; # remove spaces around = + + if(/^(\w+)=(.*)$/) { + $key = $1; + $val = $2; + $val =~ s,(?:^['"]|['"]$),,g; # remove quotes around value + $val =~ s,[\s\\]*$,,; # remove any line-continuation backslash + + $key = fix_key($key); + + if($key =~ /^MD5SUM/) { + $val =~ tr/A-Z/a-z/; + } + + # multiple valued keys all on the same line get split up into + # multi-line values. This only applies to download and md5sum + # values (which can't contain spaces anyway). + if($key =~ /^(?:DOWNLOAD|MD5SUM)/) { + $val =~ s/\s+/\r/g; + } + + $info{$key} = $val; + } else { + s,[\s\\\"]*$,,; + $info{$key} .= "\r$_"; + } + } + close $fh; + + # 20240331 bkw: fix github URLs, if needed. + for my $key (qw/DOWNLOAD DOWNLOAD_x86_64/) { + if($info{$key}) { + my @urls = split " ", $info{$key}; + my @newurls; + for my $url (@urls) { + my $newurl = $url; + if($url =~ m,https://github.com/,) { + $newurl = fix_github_url($url); + } + push @newurls, $newurl; + } + $info{$key} = join "\r", @newurls; + } + } + + system("mv $file $file.bak"); + + open $fh, ">$file" or do { + warn "$SELF: can't write $file: $!\n"; + $errcnt++; + return; + }; + + if(not defined $info{'PRGNAM'}) { + warn "$SELF: $file missing PRGNAM, guessing \"$prgnam_guess\" from filename.\n"; + $info{'PRGNAM'} = $prgnam_guess; + } + + # Reconstitute info file from the values, with correct indentation and + # quoting, backslashes, etc. + for $key (@keyorder) { + $info{$key} ||= ""; # avoid unitialized value on missing key + my @values = split /\r/, $info{$key}; + if(@values == 0) { + print $fh "$key=\"\"\n"; + } elsif(@values == 1) { + print $fh "$key=\"$values[0]\"\n"; + } else { + my $indent = " " x (length($key) + 2); + my $first = shift @values; + my $last = pop @values; + print $fh "$key=\"$first \\\n"; + print $fh "$indent$_ \\\n" for @values; + print $fh "$indent$last\"\n"; + } + } + + my $result = system("diff -u --color $file.bak $file"); + if($result == 0) { + unlink("$file.bak"); + warn "$SELF: no changes to $file\n"; + } } |
