5 # xpostconf - extract parameter info from postconf prototype file
7 # Usage: xpostconf [options] protofile [parameter...]
9 # -b: Brief output: print only the first sentence of each definition
11 # -c: print the classes named on the command line (default: all).
13 # -h: print help message.
15 # -p: print the parameters named on the command line (default: all).
17 # -s specfile: process the entries listed in the named file: ordinary
18 # text is copied as is,
19 # %CLASS class-name mode
20 # %PARAM param-name mode
21 # are replaced by the respective information. Mode is b (brief)
22 # f (full) or i (ignore).
24 # If no -s is specified, extracts the named parameter text (all
25 # parameters by default).
34 die "Usage: $0 [-bcpv] [-s specfile] protofile [parameter...]\n"
35 unless $protofile = shift(@ARGV);
37 # Save one definition.
40 if ($category eq "PARAM") {
41 $param_text{$name} = $text;
43 printf "saving entry %s %.20s..\n", $name, $text;
45 } elsif ($category eq "CLASS") {
46 $class_text{$name} = $text;
48 printf "saving class %s %.20s..\n", $name, $text;
51 die "Unknown category: $category. Need PARAM or CLASS.\n";
55 # Read the whole file even if we want to print only one parameter.
57 open(POSTCONF
, $protofile) || die " cannot open $protofile: $!\n";
61 next if /^#/ && $text eq "";
62 next unless ($name || /\S/);
64 if (/^%(PARAM|CLASS)/) {
66 # Save the accumulated text.
72 # Reset the parameter name and accumulated text.
77 # Accumulate the parameter name and default value.
81 } while(($_ = <POSTCONF
>) && /\S/);
82 ($junk, $name, $junk) = split(/\s+/, $text, 3);
86 # Accumulate the text in the class or parameter definition.
92 # Save the last definition.
98 # If working from a spec file, emit output in the specified order.
101 open(SPEC
, "$opt_s") || die "cannot open $opt_s: $!\m";
104 ($category, $name, $mode) = split(/\s+/, substr($_, 1));
105 if ($category eq "CLASS") {
106 die "Unknown class name: $name.\n"
107 unless $text = $class_text{$name};
108 } elsif ($category eq "PARAM") {
109 die "Unknown parameter name: $name.\n"
110 unless $text = $param_text{$name};
112 die "Unknown category: $category. Need CLASS or PARAM\n";
116 } elsif ($mode eq "b") {
117 $text =~ s/\.\s.*/.\n\n/s;
118 } elsif ($mode ne "p") {
119 die "Unknown mode: $mode. Need b or p or i,\n";
129 # Print all the parameters.
132 $what = \
%class_text;
134 $what = \
%param_text;
138 for $name (sort keys %{$what}) {
139 $text = ${$what}{$name};
140 $text =~ s/\.\s.*/.\n\n/s if ($opt_b);
145 # Print parameters in the specified order.
149 $text = ${$what}{$name};
150 $text =~ s/\.\s.*/.\n\n/s if ($opt_b);