3 # Copyright (c) 2008-2018. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
14 print "/* Generated file, do not edit */\n";
15 print "/** \\addtogroup XBT_log_cats\n";
18 # Search for calls to macros defining new channels, and prepare the tree representation
21 # $ancestor{"toto"} is the ancestor of the toto channel as declared by XBT_LOG_NEW_SUBCATEGORY and
22 # XBT_LOG_NEW_DEFAULT_SUBCATEGORY ie, when the channel toto is initialized (does not work under windows)
24 # $desc{"toto"} is its description
27 my $ctn = shift; # cleanup the content of a macro call
28 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
30 print STDERR "ctn=$ctn\n" if $debug > 1;
31 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
32 # Perfect, we got 0->name; 1->anc; 2->desc
36 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
37 # Mmm. got no ancestor. Add the default one.
39 $elms[1] = "XBT_LOG_ROOT_CAT";
42 die "Unparsable content: $ctn\n";
44 $elms[2] =~ s/\\\\/\\/gs;
53 print STDERR "Parse $filename\n" if $debug;
54 open IN, "$filename" || die "Cannot read $filename: $!\n";
60 # Purge $data from C and C++ comments
61 $data =~ s|/\*.*?\*/||sg;
64 while ($data =~ s/^.*?XBT_LOG_NEW(_DEFAULT)?_(SUB)?CATEGORY\(//s) {
65 $data =~ s/([^"]*"[^"]*")\)//s || die "unparsable macro: $data";
67 my ($name,$anc,$desc) = cleanup_ctn($1);
69 # build the tree, checking for name conflict
70 die "ERROR: Category name conflict: $name used several times (in $ancestor{$name} and $anc, last time in $filename)\n"
71 if defined ($ancestor{$name}) && $ancestor{$name} ne $anc && defined ($desc{$name}) && $desc{$name} ne $desc;
72 $ancestor{$name}=$anc;
75 print STDERR " $name -> $anc\n" if $debug;
78 # Retrieve all the file names
79 my $path = $ARGV[0] // "..";
80 open FILES, "find $path/src/ $path/tools/ $path/include/ -name '*.c' -o -name '*.cpp' |" || die "Cannot search for the source file names: $!\n";
81 while (my $file=<FILES>) {
85 parse_file("$path/include/xbt/sysdep.h");
88 # Display the tree, looking for disconnected elems
96 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
97 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
99 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
100 display_subtree($cat,"$indent ");
104 display_subtree("XBT_LOG_ROOT_CAT","");
107 warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";
108 } grep {!defined $used{$_}} sort keys %ancestor;