summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2023-11-24 18:19:26 +0000
committerMarc Espie <espie@cvs.openbsd.org>2023-11-24 18:19:26 +0000
commit55dc24d62d3a56ae2898921e2e14b5416f8d563b (patch)
treef5bcee66e81b7a284b548186403d3879f4c49cfc /usr.sbin/pkg_add/OpenBSD
parent68c8ebc16bbfdf54bb15060d8fddf8dfee6a4ef2 (diff)
add glue to match usage against actual options, as a debugging facility
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/State.pm46
1 files changed, 45 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm
index cc671073f09..d21919c7ee5 100644
--- a/usr.sbin/pkg_add/OpenBSD/State.pm
+++ b/usr.sbin/pkg_add/OpenBSD/State.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.74 2023/06/13 09:07:17 espie Exp $
+# $OpenBSD: State.pm,v 1.75 2023/11/24 18:19:25 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
@@ -191,6 +191,47 @@ sub do_options($state, $sub)
};
}
+sub validate_usage($state, $string, @usage)
+{
+ my $h = {};
+ my $h2 = {};
+ my $previous;
+ for my $letter (split //, $string) {
+ if ($letter eq ':') {
+ $h->{$previous} = 1;
+ } else {
+ $previous = $letter;
+ $h->{$previous} = 0;
+ }
+ }
+ for my $u (@usage) {
+ while ($u =~ s/\[\-(.*?)\]//) {
+ my $opts = $1;
+ if ($opts =~ m/^[A-Za-z]+$/) {
+ for my $o (split //, $opts) {
+ $h2->{$o} = 0;
+ }
+ } else {
+ $opts =~ m/./;
+ $h2->{$&} = 1;
+ }
+ }
+ }
+ for my $k (keys %$h) {
+ if (!exists $h2->{$k}) {
+ $state->errsay("Option #1 #2is not in usage", $k,
+ $h->{$k} ? "(with params) " : "");
+ } elsif ($h2->{$k} != $h->{$k}) {
+ $state->errsay("Discrepancy for option #1", $k);
+ }
+ }
+ for my $k (keys %$h2) {
+ if (!exists $h->{$k}) {
+ $state->errsay("Option #1 does not exist", $k);
+ }
+ }
+}
+
sub handle_options($state, $opt_string, @usage)
{
require OpenBSD::Getopt;
@@ -218,6 +259,9 @@ sub handle_options($state, $opt_string, @usage)
$state->{signature_style} //= 'new';
}
+ if ($state->defines('VALIDATE_USAGE')) {
+ $state->validate_usage($opt_string.'vD:', @usage);
+ }
return if $state->{no_exports};
# TODO make sure nothing uses this
no strict "refs";