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