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";
43 $elms[2] =~ s/\\\\/\\/gs;
53 print "Parse $filename\n" if $debug;
54 open IN, "$filename" || die "Cannot read $filename: $!\n";
60 # Purge $data from C comments
61 $data =~ s|/\*.*?\*/||sg;
63 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
66 my $connect_data = $data; # save a copy for second parsing phase
67 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
68 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data"; # ]]);
70 my ($name,$anc,$desc) = cleanup_ctn($1);
72 # build the tree, checking for name conflict
73 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
74 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
75 defined ($desc{$name}) && $desc{$name} ne $desc;
76 $ancestor{$name}=$anc;
79 print " $name -> $anc\n" if $debug;
82 # Now, look for XBT_LOG_CONNECT calls
83 $data = $connect_data;
84 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
86 $data =~ s/([^\)]*)\)//s || die "unparsable macro: $data"; # ]]);
87 my ($name, $ignoreme, $anc) = cleanup_ctn($1);
89 # build the tree, checking for name conflict
90 $c_ancestor{$name}=$anc;
92 print STDERR " $name -> $anc\n" if $debug;
95 # Retrieve all the file names, and add their content to $data
97 open FILES, "find src/ tools/ include/ -name '*.c'|" || die "Cannot search for the source file names: $!\n";
98 while (my $file=<FILES>) {
104 # Display the tree, looking for disconnected elems
107 sub display_subtree {
112 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
113 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
115 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
116 display_subtree($cat,"$indent ");
120 display_subtree("XBT_LOG_ROOT_CAT","");
122 sub check_connection {
125 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
126 unless ($ancestor{$cat} eq "XBT_LOG_ROOT_CAT" || (defined($c_ancestor{$cat}) && $c_ancestor{$cat} eq $name)) {
127 warn "Category $cat will be disconnected under windows. Add the following to an initialization function:\n XBT_LOG_CONNECT($cat, $ancestor{$cat});\n";
129 warn "Correctly connected, even under windows: Category $cat.\n" if $debug;
131 check_connection($cat);
134 check_connection("XBT_LOG_ROOT_CAT");
135 map {warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";} grep {!defined $used{$_}} sort keys %ancestor;