8 print "/* Generated file, do not edit */\n";
9 print "/** \\addtogroup XBT_log_cats\n";
12 # Search for calls to macros defining new channels, and prepare the tree representation
15 # $ancestor{"toto"} is the ancestor of the toto channel
16 # as declared by XBT_LOG_NEW_SUBCATEGORY and XBT_LOG_NEW_DEFAULT_SUBCATEGORY
17 # ie, when the channel toto is initialized (does not work under windows)
19 # $desc{"toto"} is its description
21 # $c_ancestor{"toto"} is the ancestor of the toto channel, as declared by XBT_LOG_CONNECT
22 # ie, in a initialization function (only way to do so under windows)
23 # we want $ancestor{"toto"} == $c_ancestor{"toto"} for each toto, or bad things will happen under windows
26 my $ctn = shift; # cleanup the content of a macro call
28 $ctn =~ s/,\s*"/,"/gs;
31 my @elms_tmp=split (/,/,$ctn);
33 print "ctn=$ctn\n" if $debug > 1;
34 # There may be some ',' in the description. Remerge the stuff like: "description, really"
36 my $acc = shift @elms_tmp;
37 last unless defined $acc;
38 if ($acc =~ /^"/) { # ") {
39 while (shift @elms_tmp) {
42 die "Unparsable content: $ctn\n"
43 unless ($acc =~ s/^"(.*)"$/$1/);
45 print " seen $acc\n" if $debug > 1;
48 if (scalar(@elms) eq 3) {
49 # Perfect, we got 0->name; 1->anc; 2->desc
50 } elsif (scalar(@elms) eq 2) {
51 # Mmm. got no ancestor. Add the default one.
52 $elms[2] = $elms[1]; # shift the desc
53 $elms[1] = "XBT_LOG_ROOT_CAT";
55 my $l = scalar(@elms);
57 map {$s .= $_;} @elms;
58 die "Unparsable content: $ctn (length=$l) (content=$s)\n";
61 $elms[0] =~ s/^\s*(\S*)\s*$/$1/; # trim
62 $elms[1] =~ s/^\s*(\S*)\s*$/$1/; # trim
73 print "Parse $filename\n" if $debug;
74 open IN, "$filename" || die "Cannot read $filename: $!\n";
80 # Purge $data from C comments
81 $data =~ s|/\*.*?\*/||sg;
83 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
86 my $connect_data = $data; # save a copy for second parsing phase
87 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
88 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]);
90 my ($name,$anc,$desc) = cleanup_ctn($1);
92 # build the tree, checking for name conflict
93 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
94 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
95 defined ($desc{$name}) && $desc{$name} ne $desc;
96 $ancestor{$name}=$anc;
99 print " $name -> $anc\n" if $debug;
102 # Now, look for XBT_LOG_CONNECT calls
103 $data = $connect_data;
104 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
106 $data =~ s/([^\)]*)\)//s || die "unparsable macro: $data"; # ]]);
107 my ($name, $ignoreme, $anc) = cleanup_ctn($1);
109 # build the tree, checking for name conflict
110 $c_ancestor{$name}=$anc;
112 print STDERR " $name -> $anc\n" if $debug;
115 # Retrieve all the file names, and add their content to $data
117 open FILES, "find src/ tools/ include/ -name '*.c'|" || die "Cannot search for the source file names: $!\n";
118 while (my $file=<FILES>) {
124 # Display the tree, looking for disconnected elems
127 sub display_subtree {
132 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
133 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
135 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
136 display_subtree($cat,"$indent ");
140 display_subtree("XBT_LOG_ROOT_CAT","");
142 sub check_connection {
145 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
146 unless ($ancestor{$cat} eq "XBT_LOG_ROOT_CAT" || (defined($c_ancestor{$cat}) && $c_ancestor{$cat} eq $name)) {
147 warn "Category $cat will be disconnected under windows. Add the following to an initialization function:\n XBT_LOG_CONNECT($cat, $ancestor{$cat});\n";
149 warn "Correctly connected, even under windows: Category $cat.\n" if $debug;
151 check_connection($cat);
154 check_connection("XBT_LOG_ROOT_CAT");
155 map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor;