Home | History | Annotate | Line # | Download | only in mantools
      1  1.1  tron #!/usr/bin/perl
      2  1.1  tron 
      3  1.1  tron # Extract parameter definitions from the sample-mumble.cf files in
      4  1.1  tron # order to build the postconf raw data file from which everything
      5  1.1  tron # will be regenerated.
      6  1.1  tron 
      7  1.1  tron $POSTCONF="postconf";
      8  1.1  tron 
      9  1.1  tron # Suck in the parameter definition text. Skip non-parameter blocks.
     10  1.1  tron # Strip all but the body text (i.e. strip off the non-comment line
     11  1.1  tron # that shows the default, since we will use postconf output to supply
     12  1.1  tron # the actual values).
     13  1.1  tron 
     14  1.1  tron while(<>) {
     15  1.1  tron     if (/^[^#]/) {
     16  1.1  tron 	if ($param_name && $saved_text) {
     17  1.1  tron 	    $saved_text =~ s/^(\n|#|\s)+//;
     18  1.1  tron 	    $saved_text =~ s/(\n|#|\s)+$//;
     19  1.1  tron 	    $saved_text =~ s/^# ?/\n/;
     20  1.1  tron 	    $saved_text =~ s/\n# ?/\n/g;
     21  1.1  tron 	    $definition{$param_name} = $saved_text;
     22  1.1  tron 	    $param_name = $saved_text = "";
     23  1.1  tron 	}
     24  1.1  tron 	next;
     25  1.1  tron     }
     26  1.1  tron     if (/^#/ && $param_name) {
     27  1.1  tron 	$saved_text .= $_;
     28  1.1  tron 	next;
     29  1.1  tron     }
     30  1.1  tron     if (/^# The (\S+) (configuration )?parameter/) {
     31  1.1  tron 	$param_name = $1;
     32  1.1  tron 	$saved_text = $_;
     33  1.1  tron     }
     34  1.1  tron }
     35  1.1  tron 
     36  1.1  tron # Read all the default parameter values. This also provides us with
     37  1.1  tron # a list of all the parameters that postconf knows about.
     38  1.1  tron 
     39  1.1  tron open(POSTCONF, "$POSTCONF -d|") || die "cannot run $POSTCONF: !$\n";
     40  1.1  tron while(<POSTCONF>) {
     41  1.1  tron     chop;
     42  1.1  tron     if (($name, $value) = split(/\s+=\s+/, $_, 2)) {
     43  1.1  tron 	$defaults{$name} = $value;
     44  1.1  tron     } else {
     45  1.1  tron 	warn "unexpected $POSTCONF output: $_\n";
     46  1.1  tron     }
     47  1.1  tron }
     48  1.1  tron close(POSTCONF) || die "$POSTCONF failed: $!\n"; 
     49  1.1  tron 
     50  1.1  tron # Print all parameter definition text that we found, and warn about
     51  1.1  tron # missing definition text.
     52  1.1  tron 
     53  1.1  tron for $param_name (sort keys %defaults) {
     54  1.1  tron    if (defined($definition{$param_name})) {
     55  1.1  tron 	print "#DEFINE $param_name\n\n";
     56  1.1  tron 	print $definition{$param_name};
     57  1.1  tron 	print "\n\n";
     58  1.1  tron    } else {
     59  1.1  tron 	warn "No definition found for $param_name\n";
     60  1.1  tron    }
     61  1.1  tron }
     62