File: docme

package info (click to toggle)
mcl 1%3A14-137-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 10,704 kB
  • ctags: 5,125
  • sloc: ansic: 53,217; sh: 4,448; perl: 3,967; makefile: 422
file content (162 lines) | stat: -rwxr-xr-x 3,655 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/local/bin/perl -w

#  This program matches
#  A)
#     "progname --help"
#  output with
#  B)
#     defopt, defkvp                                  (azm OPTIONS section)
#     synoptopt, synreqopt, synoptkvp, synreqkvp      (azm SYNOPSIS section)
#
#  and looks for unsupported or undocumented options.

use Getopt::Long;
use strict;

my @ARGV_COPY  = @ARGV;
my $n_args = @ARGV;

$::amoixa =  0;
$::silent =  0;
$::exclude = "";
$::nosynopsis = 0;
$::doc_exceed = 0;

my %exclude = ();

if
(! GetOptions
   (  "--amoixa"        =>   \$::amoixa
   ,  "--silent"        =>   \$::silent
   ,  "--exclude=s"     =>   \$::exclude
   ,  "--doc-exceed=i"  =>   \$::doc_exceed
   ,  "--ignore-synopsis"   =>   \$::nosynopsis
   )
)
   {  print STDERR "option processing failed\n";
      exit(1);
   }

die "need <program-name> <zoem-manual>" unless @ARGV == 2;
my ($progname, $azm) =  @ARGV;

my $flag_apropos = $::amoixa ? "--amoixa" : "--help";
%exclude = map { ($_, 1) } split ",", $::exclude;

my $marker = '=' x 40;


my %apropos
=  
   map { /\-{1,2}([^=\s]+)(.*)/; ($1, $2); }

   grep { /^\s*\-{1,2}[^-]/; }

   `$progname $flag_apropos`;


die "program [$progname] failed\n" if $?; 

my %def
=  map
   {  /def(opt|kvp)\{-+(.*?)\}/
   ?  ($2, 1)
   :     /item_def(opt|kvp)_(\w+)/
      ?  ($2, 1)
      :  ();
   }
   grep { ! /nodef/ }
   `grep 'def\\(opt\\|kvp\\)\{' $azm`; 

die "grep $azm failed (def)\n" if $?; 

my %syn
=  map
   {  /syn(opt|req)(opt|kvp)\{-+(.*?)\}/
   ?  ($3, 1)
   :     /syn(opt|req)(opt|kvp)_(\w+)/
      ?  ($3, 1)
      :  ();
   }
   grep { ! /nosyn/ }
   `grep 'syn\\(opt\\|req\\)\\(opt\\|kvp\\){' $azm`; 

die "grep $azm failed (syn)\n" if $?; 

   #{ ($_, 1) }
   #`grep '\\syn\\(opt\\|\\req\\)\\(opt\\|kvp\\){' $azm`; 
   #`grep 'synoptopt' $azm`; 

# print "here comes:\n";
# local $, = ' ';
# print %syn;
# print "--\n";
# print %def;
# print "--\n";
# print %apropos;
# print "--\n";

for my $k (keys %exclude) {
   delete($apropos{$k});
   delete($def{$k});
   delete($syn{$k});
}


my @undocumented = grep { !defined($def{$_}) } sort keys %apropos;
print $marker . " Undocumented options:\n" unless $::silent && !@undocumented;
for my $k (@undocumented) {
   print "$k ## $apropos{$k}\n";
}


my @unsupported = grep { !defined($apropos{$_}) } sort keys %def;
my $n_us = @unsupported;

my @unsupported2 = grep { !defined($apropos{$_}) } sort keys %syn;
my $n_us2 = @unsupported2;

if ($::doc_exceed) {
   my %u1 = map { ($_, 1); } @unsupported;
   my %u2 = map { ($_, 1); } @unsupported2;
   my @isect = grep { defined($u1{$_}) } keys %u2;

   if (@isect >= $::doc_exceed) {
      $#isect =  @isect - $::doc_exceed -1;     # remove arbitrary lot.
   }
   @unsupported = (@isect, grep { !defined($u2{$_}) } keys %u1);
   @unsupported2 = (@isect, grep { !defined($u1{$_}) } keys %u2);
}

print $marker . " Unsupported options ($n_us):\n" unless $::silent && !@unsupported;
for my $k (@unsupported) {
   print "$k\n";
}


print $marker . " Unsupported options synopsis ($n_us2):\n" unless $::silent && !@unsupported2;
for my $k (@unsupported2) {
   print "$k\n";
}


my @unsynopsed = ();
unless ($::nosynopsis) {
   if (!@undocumented) {
      @unsynopsed = grep { !defined($syn{$_}) } sort keys %apropos;
      print $marker . " Undocumented options - synopsis\n"
                              unless $::silent && !@unsynopsed;
      for my $k (@unsynopsed) {
         print "$k $apropos{$k}\n";
      }
   }
   else {
      print $marker . " Skipped synopsis section (fix defs first)\n" unless $::silent;
   }
}


my $total = @unsupported + @undocumented + @unsupported2 + @unsynopsed;
exit $total ? 1 : 0;