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 # $connected{"toto"} is defined if XBT_LOG_CONNECT("toto") is used
24 my $ctn = shift; # cleanup the content of a macro call
25 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
27 print "ctn=$ctn\n" if $debug > 1;
28 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
29 # Perfect, we got 0->name; 1->anc; 2->desc
33 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
34 # Mmm. got no ancestor. Add the default one.
36 $elms[1] = "XBT_LOG_ROOT_CAT";
39 die "Unparsable content: $ctn\n";
41 $elms[2] =~ s/\\\\/\\/gs;
51 print "Parse $filename\n" if $debug;
52 open IN, "$filename" || die "Cannot read $filename: $!\n";
58 # Purge $data from C comments
59 $data =~ s|/\*.*?\*/||sg;
61 # C++ comments are forbiden in SG for portability reasons, but deal with it anyway
64 my $connect_data = $data; # save a copy for second parsing phase
65 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
66 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data";
68 my ($name,$anc,$desc) = cleanup_ctn($1);
70 # build the tree, checking for name conflict
71 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
72 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc &&
73 defined ($desc{$name}) && $desc{$name} ne $desc;
74 $ancestor{$name}=$anc;
77 print " $name -> $anc\n" if $debug;
80 # Now, look for XBT_LOG_CONNECT calls
81 $data = $connect_data;
82 while ($data =~ s/^.*?XBT_LOG_CONNECT\(//s) {
83 $data =~ s/\s*(\w+)\s*\)//s || die "unparsable macro: $data";
87 # Retrieve all the file names, and add their content to $data
89 open FILES, "find src/ tools/ include/ -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","");
115 warn "Category $_ does not seem to be connected. Use XBT_LOG_CONNECT($_).\n";
116 } grep {!defined $connected{$_}} sort keys %ancestor;
118 warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";
119 } grep {!defined $used{$_}} sort keys %ancestor;