| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | for $filename (@ARGV) { |
| 4 | open(SRC, $filename) || die "$filename: $!"; |
| 5 | $state = 0; |
| 6 | delete @tvars{keys %tvars}; |
| 7 | $module = ""; |
| 8 | while(<SRC>) { |
| 9 | chomp; |
| 10 | if(($state == 0) && /struct configvar/ && /\[\]/) { |
| 11 | $state = 1; |
| 12 | } |
| 13 | if(($state == 0) && /struct module/ && /=/) { |
| 14 | $state = 3; |
| 15 | } |
| 16 | if(($state == 1) && /^\s*\/\*\*/) { |
| 17 | $curdoc = ""; |
| 18 | $state = 2; |
| 19 | s/^\s*\/\*//; |
| 20 | } |
| 21 | if(($state == 1) && /\{CONF_VAR_(\w+), \"([^\"]*)\"/) { |
| 22 | $var = $2; $type = $1; $def = ""; |
| 23 | if($type eq "INT") { |
| 24 | ($def) = /\.num = (\d+)/; |
| 25 | } elsif($type eq "BOOL") { |
| 26 | ($def) = /\.num = (\d+)/; |
| 27 | if($def) { |
| 28 | $def = "true"; |
| 29 | } else { |
| 30 | $def = "false"; |
| 31 | } |
| 32 | } elsif($type eq "STRING") { |
| 33 | ($def) = /\.str = L\"([^\"]*)\"/; |
| 34 | $def = "\"$def\""; |
| 35 | } |
| 36 | $tvars{$var} = {"doc" => $curdoc, "type" => $type, "def" => $def}; |
| 37 | $curdoc = ""; |
| 38 | } |
| 39 | if(($state == 1) && /\s*\};$/) { |
| 40 | $state = 0; |
| 41 | } |
| 42 | if($state == 2) { |
| 43 | if(/\*\/$/) { |
| 44 | $state = 1; |
| 45 | s/\*\/$//; |
| 46 | } |
| 47 | s/^\s*\*\s*//; |
| 48 | s/\s*$//; |
| 49 | if(length($curdoc) > 0) { |
| 50 | $curdoc .= " "; |
| 51 | } |
| 52 | $curdoc .= $_; |
| 53 | } |
| 54 | if(($state == 3) && /\.name\s*=\s*\"([^\"]+)\"/) { |
| 55 | $module = $1; |
| 56 | } |
| 57 | if(($state == 3) && /\s*\};$/) { |
| 58 | $state = 0; |
| 59 | } |
| 60 | } |
| 61 | close SRC; |
| 62 | #$module = $filename; |
| 63 | #$module =~ s/^.*\///; |
| 64 | #$module =~ s/\..*$//; |
| 65 | if($module eq "") { |
| 66 | print STDERR "$filename is not a module\n"; |
| 67 | } else { |
| 68 | print STDERR ("$filename is module $module and has " . scalar(keys %tvars) . " variables\n"); |
| 69 | for $var (keys %tvars) { |
| 70 | $vars{"$module.$var"} = $tvars{$var}; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | print STDERR ("total number of variables: " . scalar(keys %vars) . "\n"); |
| 75 | |
| 76 | $types{"BOOL"} = "boolean"; |
| 77 | $types{"INT"} = "integer"; |
| 78 | $types{"STRING"} = "string"; |
| 79 | $types{"IPV4"} = "IPv4 address"; |
| 80 | while(<STDIN>) { |
| 81 | if(/\@DATE\@/) { |
| 82 | @lt = localtime time; |
| 83 | $date = sprintf("%04i-%02i-%02i", $lt[5] + 1900, $lt[4] + 1, $lt[3]); |
| 84 | s/\@DATE\@/$date/; |
| 85 | } |
| 86 | if(/\@VARIABLES\@/) { |
| 87 | $_ = ""; |
| 88 | for $var (sort keys %vars) { |
| 89 | $_ .= ".TP\n.BI $var \" "; |
| 90 | $_ .= $types{$vars{$var}->{"type"}}; |
| 91 | $_ .= "\"\n"; |
| 92 | $_ .= $vars{$var}->{"doc"}; |
| 93 | if(!($vars{$var}->{"type"} eq "IPV4")) { |
| 94 | $_ .= "\n\nDefault value: "; |
| 95 | $_ .= $vars{$var}->{"def"}; |
| 96 | } |
| 97 | $_ .= "\n"; |
| 98 | } |
| 99 | } |
| 100 | print; |
| 101 | } |