3 # This script updates the simgrid XML file passed as argument (modification in place)
4 # It is built to do the conversion incrementally (even if for now, only 2 versions are defined)
6 # Copyright (C) 2006-2007. The SimGrid team. All rights reserved.
8 # This file is part of the SimGrid project. This is free software:
9 # You can redistribute and/or modify it under the terms of the
10 # GNU LGPL (v2.1) licence.
19 $ARGV[0] or die "simgrid_update_xml.pl <platform.xml>\n";
20 open INPUT, "$ARGV[0]" or die "Cannot open input file $ARGV[0]: $!\n";
22 $output_string .= "<?xml version='1.0'?>\n";
23 $output_string .= "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
24 $output_string .= "<platform version=\"$toversion\">\n";
27 while (defined($line = <INPUT>)) {
29 # eat the header, whatever form it has
30 next if ($line =~ s/<\?xml[^>]*>// && ! $line =~ /\S/); # just in case several tags are on the same line
31 next if ($line =~ s/<!DOCTYPE[^>]*>// && ! $line =~ /\S/);
33 if ($line =~ s/<platform(_description)? *>//) {
35 next if !$line =~ /\S/;
36 } elsif ($line =~ s/<platform(_description)? *version=['"]?([0-9.]*)["']?>//) {
38 if ($fromversion == $toversion) {
39 warn "Input platform file version is already $fromversion. This should be a no-op.\n";
41 if ($fromversion > $toversion) {
42 die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
44 next if !$line =~ /\S/;
47 if ($fromversion == 0) {
48 while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
49 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
51 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
52 $line = "$1<cpu${2}power=\"$3\"$4";
54 while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
55 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
57 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
58 $line = "$1<network_link${2}bandwidth=\"$3\"$4";
62 if ($fromversion < 2) {
63 # The renamings (\b=zero-width word boundary check)
64 $line =~ s/\bplatform_description\b/platform/g;
65 $line =~ s/\bname\b/id/g;
66 $line =~ s/\bcpu\b/host/g;
67 $line =~ s/\bnetwork_link\b/link/g;
68 $line =~ s/\broute_element\b/link:ctn/g;
70 $output_string .= "$line\n";
75 if ($fromversion == -1) {
76 die "Cannot retrieve the platform version\n";
79 open OUTPUT, "> $ARGV[0]";
80 print OUTPUT $output_string;