From eb5f8499f716001c8ece04f1a5f4a47de1851e87 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Tue, 2 Sep 2008 22:33:15 +0300 Subject: [PATCH] Working handling of XML (really) * Added some logic for XML variables in check_module(); * Printing also XML categories into makeopts. * Also read sounds/sounds.xml . * Parse XML var/val the same way as in XML files and in MODULEINFO. * Use hash reference instead of a has so attributes don't get accumulated. --- menuselect/menuselect | 76 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/menuselect/menuselect b/menuselect/menuselect index 8c19a6bcf..6c3a1bab1 100755 --- a/menuselect/menuselect +++ b/menuselect/menuselect @@ -85,6 +85,8 @@ my @RequiredModules = (); my @Subdirs = qw/apps cdr channels codecs formats funcs main pbx res utils/; +my @XmlCategories = 'cflags'; + # Modules should not bother building (PCRE patterns) my @ExcludedModules = (); @@ -99,6 +101,19 @@ sub warning($) { print STDERR "$0: Warning: $msg\n"; } +# Convert XML syntax to mail-header-like syntax: +# value --> Var: value +sub extract_xml_key($) { + my $xml_line = shift; + if ($xml_line !~ m{^\s*<([a-zA-Z0-9]*)>([^<]*)}) { + print STDERR "parsed empty value from XML line $xml_line\n"; + return ('', ''); # warn? + } + my ($var, $val) = ($1, $2); + $var =~ s{^[a-z]}{\u$&}; + return ($var, $val); +} + # Get information embedded in source files from a subdirectory. # First parameter is the subdirectory and further ones are the actual # source files. @@ -126,14 +141,9 @@ sub get_subdir_module_info { # At this point we can assume we're in the module # info section. chomp; + my ($var, $val) = extract_xml_key($_); - # Convert XML syntax to mail-header-like syntax: - # value --> Var: value - s{^\s*<([a-zA-Z0-9]*)>([^<]*)}{$1: $2}; - s{^[a-z]}{\u$&}; - - my ($var,$val) = split(/: +/, $_, 2); - if ($var =~ /^(depend|use)$/i) { + if ($var =~ /^(Depend|Use)$/i) { # use uppercase for dependency names; $val = uc($val); } @@ -166,43 +176,49 @@ sub parse_menuselect_xml_file($) { die "Failed opening XML file $file_name: $!.\n"; my $header = ; - $header =~ /^\s*){ next unless (m{^\s*<(/?[a-z]+)[>\s]}); my $tag = $1; if ($tag eq 'member') { - if (! m{^\s*}){ + if (! m{^\s*}){ warning "Bad XML member line: $_ ($file_name:$.)\n"; next; } my ($name, $display_name) = ($1, $2); - %member = ( + $member = { Type => 'XML', Dir => $category, Module => $1, DisplayName => $2, - Avail => 1, # TODO: is this right? + Avail => 1, - ); + }; } elsif ($tag eq '/member') { - $ModInfo{$member{Module}} = \%member; + print STDERR "Setting module $member->{Module} at $member->{Dir} ($member->{DisplayName})\n"; + $ModInfo{$member->{Module}} = $member; } elsif ($tag eq '/category') { last; } else { if (! m/^\s*<([a-z]+)>([^<]+){$key}) { + $member->{$key} = []; } - push @{$member{$key}}, ($val); + print STDERR "Adding key $key, value $val to member $member->{Module}\n"; + push @{$member->{$key}}, ($val); } } @@ -400,24 +416,33 @@ sub check_module($) { } # A library has no dependencies of its own. if ($ModInfo{$mod}{Type} eq 'lib') { - return $ModInfo{$mod}{Avail}; + return ($ModInfo{$mod}{Avail} || 0); } # An excluded module. if ($ModInfo{$mod}{Avail} == 0) { return 0; } + # XML inputs have a reversed logic: no 'defaultenabled' means 'no' + # And we need to actually print enabled ones, rather than disabled + # ones. + if ($ModInfo{$mod}{Type} eq 'XML') { + my $res = ((not exists $ModInfo{$mod}{Defaultenabled}) || + ($ModInfo{$mod}{Defaultenabled}[0] ne 'yes') ); + $ModInfo{$mod}{Checked} = $res; + return $res; + } # no dependencies to check: if (! exists $ModInfo{$mod}{Depend}) { $ModInfo{$mod}{Checked} = 1; return 1; } - my $deps_checked = 1; # may be set to below on failures: + my $deps_checked = 1; # may be reset below on failures: - if (exists $ModInfo{$mod}{Tested}) { - # this probably means a circular dependency of some sort. - warning "Got to module $mod that is already tested."; - } + if (exists $ModInfo{$mod}{Tested}) { + # this probably means a circular dependency of some sort. + warning "Got to module $mod that is already tested."; + } $ModInfo{$mod}{Tested} = 1; foreach my $dep_mod (@{$ModInfo{$mod}{Depend}} ) { @@ -453,7 +478,7 @@ sub gen_makeopts() { my %Subdirs; foreach my $mod (sort keys %ModInfo) { - next unless ($ModInfo{$mod}{Type} eq 'module'); + next unless ($ModInfo{$mod}{Type} =~ /^(module|XML)$/); next if ($ModInfo{$mod}{Checked}); my $dir = $ModInfo{$mod}{Dir}; if (! exists $Subdirs{$dir}) { @@ -478,6 +503,7 @@ read_conf(); extract_subdirs(@Subdirs); parse_menuselect_xml_file('build_tools/cflags.xml'); +parse_menuselect_xml_file('sounds/sounds.xml'); apply_random_drop(); -- 2.11.4.GIT