3 # Copyright (c) 2008-2021. 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\n";
15 print ".. _logging_categories:\n\n";
16 print "Existing categories\n";
17 print "===================\n\n";
19 # Search for calls to macros defining new channels, and prepare the tree representation
22 # $ancestor{"toto"} is the ancestor of the toto channel as declared by XBT_LOG_NEW_SUBCATEGORY and
23 # XBT_LOG_NEW_DEFAULT_SUBCATEGORY ie, when the channel toto is initialized (does not work under windows)
25 # $desc{"toto"} is its description
28 my $ctn = shift; # cleanup the content of a macro call
29 $ctn =~ s/^\s*(.*)\s*$/$1/gs;
31 print STDERR "ctn=$ctn\n" if $debug > 1;
32 if ($ctn =~ m/^(\w+)\s*,\s*(\w+)\s*,\s*"?([^"]*)"?$/s) {
33 # Perfect, we got 0->name; 1->anc; 2->desc
37 } elsif ($ctn =~ m/^(\w+)\s*,\s*"?([^"]*)"?$/s) {
38 # Mmm. got no ancestor. Add the default one.
40 $elms[1] = "XBT_LOG_ROOT_CAT";
43 die "Unparsable content: $ctn\n";
45 $elms[2] =~ s/\\\\/\\/gs;
54 print STDERR "Parse $filename\n" if $debug;
55 open IN, "$filename" || die "Cannot read $filename: $!\n";
61 # Purge $data from C and C++ comments
62 $data =~ s|/\*.*?\*/||sg;
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 && defined ($desc{$name}) && $desc{$name} ne $desc;
73 $ancestor{$name}=$anc;
76 print STDERR " $name -> $anc\n" if $debug;
79 # Retrieve all the file names
80 my $path = $ARGV[0] // "..";
81 open FILES, "find $path/src/ $path/tools/ $path/include/ -name '*.c' -o -name '*.cpp' |" || die "Cannot search for the source file names: $!\n";
82 while (my $file=<FILES>) {
86 parse_file("$path/include/xbt/sysdep.h");
89 # Display the tree, looking for disconnected elems
97 unless ($name eq "XBT_LOG_ROOT_CAT") { # do not display the root
98 print "$indent - $name: ".($desc{$name}|| "(undocumented)")."\n";
101 my $state = 0; # 0: before the sublist; 1, within; 2: after
102 foreach my $cat (grep {$ancestor{$_} eq $name} sort keys %ancestor) {
107 display_subtree($cat, $name eq "XBT_LOG_ROOT_CAT" ? $indent: "$indent ");
114 display_subtree("XBT_LOG_ROOT_CAT","");
117 warn "Category $_ does not seem to be connected to the root (anc=$ancestor{$_})\n";
118 } grep {!defined $used{$_}} sort keys %ancestor;