9 # Search for calls to macros defining new channels, and prepare the tree representation
12 # $ancestor{"toto"} is the ancestor of the toto channel
13 # $desc{"toto"} is its description
20 print "Parse $filename\n" if $debug;
21 open IN, "$filename" || die "Cannot read $filename: $!\n";
27 # Purge $data from C comments
28 $data =~ s|/\*.*?\*/||sg;
30 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
33 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
34 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]);
39 $ctn =~ s/,\s*"/,"/gs;
42 my @elms_tmp=split (/,/,$ctn);
44 print "ctn=$ctn\n" if $debug > 1;
45 # There may be some ',' in the description. Remerge the stuff like: "description, really"
47 my $acc = shift @elms_tmp;
48 last unless defined $acc;
49 if ($acc =~ /^"/) { # ") {
50 while (shift @elms_tmp) {
53 die "Unparsable content: $ctn\n"
54 unless ($acc =~ s/^"(.*)"$/$1/);
56 print " seen $acc\n" if $debug > 1;
60 my ($name,$anc,$desc);
61 # build the tree, checking for name conflict
62 if (scalar(@elms) eq 3) {
66 } elsif (scalar(@elms) eq 2) {
68 $anc = "XBT_LOG_ROOT_CAT";
71 my $l = scalar(@elms);
73 map {$s .= $_;} @elms;
74 die "Unparsable content: $ctn (length=$l) (content=$s)\n";
76 $name =~ s/^\s*(\S*)\s*$/$1/; # trim
77 $anc =~ s/^\s*(\S*)\s*$/$1/; # trim
78 die "ERROR: Category name conflict: $name used several times\n"
79 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
80 defined ($desc{$name}) && $desc{$name} ne $desc;
81 $ancestor{$name}=$anc;
84 print " $name -> $anc\n" if $debug;
87 # Retrieve all the file names, and add their content to $data
89 open FILES, "find -name '*.c'|" || die "Cannot search for the source file names; $!\n";
90 while (my $file=<FILES>) {
96 # Display the tree, looking for disconnected elems
104 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
105 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
107 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
108 display_subtree($cat,"$indent ");
112 display_subtree("XBT_LOG_ROOT_CAT","");
114 map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor;