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
27 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
29 print "ctn=$ctn\n" if $debug > 1;
30 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
31 # Perfect, we got 0->name; 1->anc; 2->desc
35 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
36 # Mmm. got no ancestor. Add the default one.
38 $elms[1] = "XBT_LOG_ROOT_CAT";
41 die "Unparsable content: $ctn\n";
52 print "Parse $filename\n" if $debug;
53 open IN, "$filename" || die "Cannot read $filename: $!\n";
59 # Purge $data from C comments
60 $data =~ s|/\*.*?\*/||sg;
62 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
65 my $connect_data = $data; # save a copy for second parsing phase
66 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
67 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]);
69 my ($name,$anc,$desc) = cleanup_ctn($1);
71 # build the tree, checking for name conflict
72 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
73 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
74 defined ($desc{$name}) && $desc{$name} ne $desc;
75 $ancestor{$name}=$anc;
78 print " $name -> $anc\n" if $debug;
81 # Now, look for XBT_LOG_CONNECT calls
82 $data = $connect_data;
83 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
85 $data =~ s/([^\)]*)\)//s || die "unparsable macro: $data"; # ]]);
86 my ($name, $ignoreme, $anc) = cleanup_ctn($1);
88 # build the tree, checking for name conflict
89 $c_ancestor{$name}=$anc;
91 print STDERR " $name -> $anc\n" if $debug;
94 # Retrieve all the file names, and add their content to $data
96 open FILES, "find src/ tools/ include/ -name '*.c'|" || die "Cannot search for the source file names: $!\n";
97 while (my $file=<FILES>) {
103 # Display the tree, looking for disconnected elems
106 sub display_subtree {
111 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
112 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
114 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
115 display_subtree($cat,"$indent ");
119 display_subtree("XBT_LOG_ROOT_CAT","");
121 sub check_connection {
124 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
125 unless ($ancestor{$cat} eq "XBT_LOG_ROOT_CAT" || (defined($c_ancestor{$cat}) && $c_ancestor{$cat} eq $name)) {
126 warn "Category $cat will be disconnected under windows. Add the following to an initialization function:\n XBT_LOG_CONNECT($cat, $ancestor{$cat});\n";
128 warn "Correctly connected, even under windows: Category $cat.\n" if $debug;
130 check_connection($cat);
133 check_connection("XBT_LOG_ROOT_CAT");
134 map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor;