annotate extra/soundsoftware/doxysafe.pl @ 228:3c084a25d8ab feature_20

Make use of doxysafe
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 17 Feb 2011 17:46:14 +0000
parents 5b028aef59a7
children df89e7aa3ce8
rev   line source
chris@226 1 #!/usr/bin/perl -w
chris@226 2
chris@226 3 # Read a Doxyfile and print it out again to stdout, with only
chris@226 4 # whitelisted keys in it and with some keys set to pre-fixed values.
chris@226 5 #
chris@226 6 # Note that OUTPUT_DIRECTORY is not included; it should be added by
chris@226 7 # the caller
chris@226 8
chris@226 9 use strict;
chris@226 10
chris@226 11 my $txt = join "", <>;
chris@226 12 $txt =~ s/^\s*#.*$//gm;
chris@226 13 $txt =~ s/\\\n//gs;
chris@226 14 $txt =~ s/\r//g;
chris@226 15 $txt =~ s/\n\s*\n/\n/gs;
chris@226 16
chris@226 17 my %fixed = (
chris@226 18 FULL_PATH_NAMES => "NO",
chris@226 19 SYMBOL_CACHE_SIZE => 2,
chris@226 20 EXCLUDE_SYMLINKS => "YES",
chris@226 21 GENERATE_HTML => "YES",
chris@226 22 PERL_PATH => "/usr/bin/perl",
chris@226 23 HAVE_DOT => "YES",
chris@226 24 HTML_OUTPUT => ".",
chris@228 25 HTML_DYNAMIC_SECTIONS => "NO",
chris@226 26 SEARCHENGINE => "NO",
chris@226 27 DOT_FONTNAME => "FreeMono",
chris@226 28 DOT_FONTSIZE => 10,
chris@226 29 DOT_FONTPATH => "/usr/share/fonts/truetype/freefont",
chris@226 30 DOT_IMAGE_FORMAT => "png",
chris@226 31 DOT_PATH => "/usr/bin/dot",
chris@226 32 DOT_TRANSPARENT => "YES",
chris@226 33 );
chris@226 34
chris@226 35 my @safe = qw(
chris@226 36 DOXYFILE_ENCODING
chris@226 37 PROJECT_NAME
chris@226 38 PROJECT_NUMBER
chris@226 39 CREATE_SUBDIRS
chris@226 40 OUTPUT_LANGUAGE
chris@226 41 BRIEF_MEMBER_DESC
chris@226 42 REPEAT_BRIEF
chris@226 43 ABBREVIATE_BRIEF
chris@226 44 ALWAYS_DETAILED_SEC
chris@226 45 INLINE_INHERITED_MEMB
chris@226 46 STRIP_FROM_PATH
chris@226 47 STRIP_FROM_INC_PATH
chris@226 48 JAVADOC_AUTOBRIEF
chris@226 49 QT_AUTOBRIEF
chris@226 50 MULTILINE_CPP_IS_BRIEF
chris@226 51 INHERIT_DOCS
chris@226 52 SEPARATE_MEMBER_PAGES
chris@226 53 TAB_SIZE
chris@226 54 ALIASES
chris@226 55 OPTIMIZE_OUTPUT_FOR_C
chris@226 56 OPTIMIZE_OUTPUT_JAVA
chris@226 57 OPTIMIZE_FOR_FORTRAN
chris@226 58 OPTIMIZE_OUTPUT_VHDL
chris@226 59 EXTENSION_MAPPING
chris@226 60 BUILTIN_STL_SUPPORT
chris@226 61 CPP_CLI_SUPPORT
chris@226 62 SIP_SUPPORT
chris@226 63 IDL_PROPERTY_SUPPORT
chris@226 64 DISTRIBUTE_GROUP_DOC
chris@226 65 SUBGROUPING
chris@226 66 TYPEDEF_HIDES_STRUCT
chris@226 67 EXTRACT_ALL
chris@226 68 EXTRACT_PRIVATE
chris@226 69 EXTRACT_STATIC
chris@226 70 EXTRACT_LOCAL_CLASSES
chris@226 71 EXTRACT_LOCAL_METHODS
chris@226 72 EXTRACT_ANON_NSPACES
chris@226 73 HIDE_UNDOC_MEMBERS
chris@226 74 HIDE_UNDOC_CLASSES
chris@226 75 HIDE_FRIEND_COMPOUNDS
chris@226 76 HIDE_IN_BODY_DOCS
chris@226 77 INTERNAL_DOCS
chris@226 78 HIDE_SCOPE_NAMES
chris@226 79 SHOW_INCLUDE_FILES
chris@226 80 FORCE_LOCAL_INCLUDES
chris@226 81 INLINE_INFO
chris@226 82 SORT_MEMBER_DOCS
chris@226 83 SORT_BRIEF_DOCS
chris@226 84 SORT_MEMBERS_CTORS_1ST
chris@226 85 SORT_GROUP_NAMES
chris@226 86 SORT_BY_SCOPE_NAME
chris@226 87 GENERATE_TODOLIST
chris@226 88 GENERATE_TESTLIST
chris@226 89 GENERATE_BUGLIST
chris@226 90 GENERATE_DEPRECATEDLIST
chris@226 91 ENABLED_SECTIONS
chris@226 92 MAX_INITIALIZER_LINES
chris@226 93 SHOW_USED_FILES
chris@226 94 SHOW_DIRECTORIES
chris@226 95 SHOW_FILES
chris@226 96 SHOW_NAMESPACES
chris@226 97 QUIET
chris@226 98 WARNINGS
chris@226 99 WARN_IF_UNDOCUMENTED
chris@226 100 WARN_IF_DOC_ERROR
chris@226 101 WARN_NO_PARAMDOC
chris@226 102 INPUT_ENCODING
chris@226 103 RECURSIVE
chris@226 104 EXCLUDE
chris@226 105 EXCLUDE_SYMLINKS
chris@226 106 EXCLUDE_PATTERNS
chris@226 107 EXCLUDE_SYMBOLS
chris@226 108 EXAMPLE_RECURSIVE
chris@226 109 SOURCE_BROWSER
chris@226 110 INLINE_SOURCES
chris@226 111 STRIP_CODE_COMMENTS
chris@226 112 REFERENCED_BY_RELATION
chris@226 113 REFERENCES_RELATION
chris@226 114 REFERENCES_LINK_SOURCE
chris@226 115 VERBATIM_HEADERS
chris@226 116 ALPHABETICAL_INDEX
chris@226 117 COLS_IN_ALPHA_INDEX
chris@226 118 IGNORE_PREFIX
chris@226 119 HTML_TIMESTAMP
chris@226 120 HTML_ALIGN_MEMBERS
chris@226 121 ENABLE_PREPROCESSING
chris@226 122 MACRO_EXPANSION
chris@226 123 EXPAND_ONLY_PREDEF
chris@226 124 SEARCH_INCLUDES
chris@226 125 PREDEFINED
chris@226 126 EXPAND_AS_DEFINED
chris@226 127 SKIP_FUNCTION_MACROS
chris@226 128 ALLEXTERNALS
chris@226 129 EXTERNAL_GROUPS
chris@226 130 CLASS_DIAGRAMS
chris@226 131 HIDE_UNDOC_RELATIONS
chris@226 132 CLASS_GRAPH
chris@226 133 COLLABORATION_GRAPH
chris@226 134 GROUP_GRAPHS
chris@226 135 UML_LOOK
chris@226 136 TEMPLATE_RELATIONS
chris@226 137 INCLUDE_GRAPH
chris@226 138 INCLUDED_BY_GRAPH
chris@226 139 CALL_GRAPH
chris@226 140 CALLER_GRAPH
chris@226 141 GRAPHICAL_HIERARCHY
chris@226 142 DIRECTORY_GRAPH
chris@226 143 DOT_GRAPH_MAX_NODES
chris@226 144 MAX_DOT_GRAPH_DEPTH
chris@226 145 DOT_MULTI_TARGETS
chris@226 146 DOT_CLEANUP
chris@226 147 );
chris@226 148
chris@226 149 my %safehash;
chris@226 150 for my $sk (@safe) { $safehash{$sk} = 1; }
chris@226 151
chris@226 152 my @lines = split "\n", $txt;
chris@226 153
chris@226 154 my %settings;
chris@226 155
chris@226 156 sub is_safe {
chris@226 157 my $key = shift;
chris@226 158 defined $safehash{$key} and $safehash{$key} == 1;
chris@226 159 }
chris@226 160
chris@226 161 sub has_file_path {
chris@226 162 # Returns true if the given key expects a file path as a value.
chris@226 163 # We only need to test keys that are safe; unsafe keys have been
chris@226 164 # rejected already.
chris@226 165 my $key = shift;
chris@226 166 $key eq "INPUT" or
chris@226 167 $key =~ /^OUTPUT_/ or
chris@226 168 $key =~ /_PATH$/ or
chris@226 169 $key =~ /_PATTERNS$/;
chris@226 170 }
chris@226 171
chris@226 172 sub is_safe_file_path {
chris@226 173 my $value = shift;
chris@226 174 not $value =~ /^\// and not $value =~ /\.\./;
chris@226 175 }
chris@226 176
chris@226 177 foreach my $line (@lines) {
chris@226 178
chris@226 179 chomp $line;
chris@226 180 my ($key, $value) = split /\s*=\s*/, $line;
chris@226 181
chris@226 182 next if !defined $key;
chris@226 183
chris@226 184 if ($key =~ /^GENERATE_/ and not $key =~ /LIST$/) {
chris@226 185 print STDERR "NOTE: Setting $key explicitly to NO\n";
chris@226 186 $settings{$key} = "NO";
chris@226 187 next;
chris@226 188 }
chris@226 189
chris@226 190 if (!is_safe($key)) {
chris@226 191 print STDERR "NOTE: Skipping non-whitelisted key $key\n";
chris@226 192 next;
chris@226 193 }
chris@226 194
chris@226 195 if (has_file_path($key) and !is_safe_file_path($value)) {
chris@226 196 print STDERR "ERROR: Unsafe file path \"$value\" for key $key\n";
chris@226 197 exit 1;
chris@226 198 }
chris@226 199
chris@226 200 $settings{$key} = $value;
chris@226 201 }
chris@226 202
chris@228 203 foreach my $key (keys %fixed) {
chris@228 204 my $value = $fixed{$key};
chris@228 205 print STDERR "NOTE: Setting $key to fixed value $value\n";
chris@228 206 $settings{$key} = $value;
chris@228 207 }
chris@228 208
chris@226 209 print join "\n", map { "$_ = $settings{$_}" } keys %settings;
chris@226 210 print "\n";