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 # as declared by XBT_LOG_NEW_SUBCATEGORY and XBT_LOG_NEW_DEFAULT_SUBCATEGORY
14 # ie, when the channel toto is initialized (does not work under windows)
16 # $desc{"toto"} is its description
18 # $c_ancestor{"toto"} is the ancestor of the toto channel, as declared by XBT_LOG_CONNECT
19 # ie, in a initialization function (only way to do so under windows)
20 # we want $ancestor{"toto"} == $c_ancestor{"toto"} for each toto, or bad things will happen under windows
23 my $ctn = shift; # cleanup the content of a macro call
25 $ctn =~ s/,\s*"/,"/gs;
28 my @elms_tmp=split (/,/,$ctn);
30 print "ctn=$ctn\n" if $debug > 1;
31 # There may be some ',' in the description. Remerge the stuff like: "description, really"
33 my $acc = shift @elms_tmp;
34 last unless defined $acc;
35 if ($acc =~ /^"/) { # ") {
36 while (shift @elms_tmp) {
39 die "Unparsable content: $ctn\n"
40 unless ($acc =~ s/^"(.*)"$/$1/);
42 print " seen $acc\n" if $debug > 1;
45 if (scalar(@elms) eq 3) {
46 # Perfect, we got 0->name; 1->anc; 2->desc
47 } elsif (scalar(@elms) eq 2) {
48 # Mmm. got no ancestor. Add the default one.
49 $elms[2] = $elms[1]; # shift the desc
50 $elms[1] = "XBT_LOG_ROOT_CAT";
52 my $l = scalar(@elms);
54 map {$s .= $_;} @elms;
55 die "Unparsable content: $ctn (length=$l) (content=$s)\n";
58 $elms[0] =~ s/^\s*(\S*)\s*$/$1/; # trim
59 $elms[1] =~ s/^\s*(\S*)\s*$/$1/; # trim
70 print "Parse $filename\n" if $debug;
71 open IN, "$filename" || die "Cannot read $filename: $!\n";
77 # Purge $data from C comments
78 $data =~ s|/\*.*?\*/||sg;
80 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
83 my $connect_data = $data; # save a copy for second parsing phase
84 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
85 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]);
87 my ($name,$anc,$desc) = cleanup_ctn($1);
89 # build the tree, checking for name conflict
90 die "ERROR: Category name conflict: $name used several times\n"
91 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
92 defined ($desc{$name}) && $desc{$name} ne $desc;
93 $ancestor{$name}=$anc;
96 print " $name -> $anc\n" if $debug;
99 # Now, look for XBT_LOG_CONNECT calls
100 $data = $connect_data;
101 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
103 $data =~ s/([^\)]*)\)//s || die "unparsable macro: $data"; # ]]);
104 my ($name, $ignoreme, $anc) = cleanup_ctn($1);
106 # build the tree, checking for name conflict
107 $c_ancestor{$name}=$anc;
109 print STDERR " $name -> $anc\n" if $debug;
112 # Retrieve all the file names, and add their content to $data
114 open FILES, "find -name '*.c'|" || die "Cannot search for the source file names: $!\n";
115 while (my $file=<FILES>) {
121 # Display the tree, looking for disconnected elems
124 sub display_subtree {
129 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
130 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
132 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
133 display_subtree($cat,"$indent ");
137 display_subtree("XBT_LOG_ROOT_CAT","");
139 sub check_connection {
142 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
143 unless ($ancestor{$cat} eq "XBT_LOG_ROOT_CAT" || (defined($c_ancestor{$cat}) && $c_ancestor{$cat} eq $name)) {
144 warn "Category $cat will be disconnected under windows. Add the following to an initialization function:\n XBT_LOG_CONNECT($cat, $ancestor{$cat});\n";
146 warn "Correctly connected, even under windows: Category $cat.\n" if $debug;
148 check_connection($cat);
151 check_connection("XBT_LOG_ROOT_CAT");
152 map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor;