Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleaning graphicator include headers and code
[simgrid.git] / tools / simgrid_update_xml.pl
1 #! /usr/bin/perl
2
3 # This script updates the simgrid XML file passed as argument (modification in place)
4 # It is built to do the conversion incrementally.
5
6 # Copyright (C) 2006-2010. The SimGrid team. All rights reserved.
7 #
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.
11
12 use strict;
13
14 my $fromversion=-1;
15 my $toversion=3;
16
17 my($output_string);
18
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";
21
22 $output_string = "<?xml version='1.0'?>\n".
23     "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n".
24     "<platform version=\"$toversion\">\n";
25
26
27 my($AS_opened)=0;
28
29 my $line;
30 while (defined($line = <INPUT>)) {
31     chomp $line;
32     # eat the header, whatever form it has
33     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
34     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
35     
36     if ($line =~ s/<platform(_description)? *>//) {
37         $fromversion = 0;
38         print "version 0\n";
39         next if !$line =~ /\S/;
40     } elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//) {
41         $fromversion = $1;
42         print "version $fromversion\n";
43         if ($fromversion == $toversion) {
44             die "Input platform file version is already $fromversion. This should be a no-op.\n";
45         }
46         if ($fromversion > $toversion) {
47             die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
48         }
49         next if !$line =~ /\S/;
50     }
51     
52     if ($fromversion == 0) {
53         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
54             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
55         }
56         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
57             $line = "$1<cpu${2}power=\"$3\"$4";
58         }
59         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
60             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
61         }
62         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
63             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
64         }
65     }
66
67     if ($fromversion < 2)  {
68         # The renamings (\b=zero-width word boundary check)
69         $line =~ s/\bplatform_description\b/platform/g;
70         $line =~ s/\bname\b/id/g;
71         $line =~ s/\bcpu\b/host/g;
72         $line =~ s/\bnetwork_link\b/link/g;
73         $line =~ s/\broute_element\b/link:ctn/g;
74     }
75     
76     if ($fromversion < 3)  {
77         $line =~ s/\blink:ctn\b/link_ctn/g;
78         $line =~ s/\btrace:connect\b/trace_connect/g;
79
80         if($AS_opened && (($line=~ /<\/platform>/) || ($line=~ /<process/))) {
81             $output_string .= "</AS>\n";
82             $AS_opened = 0;
83         }
84
85         if( (!$AS_opened) && (
86                 ($line =~ /<host/)    ||
87                 ($line =~ /<link/)    ||
88                 ($line =~ /<cluster/) ||
89                 ($line =~ /<router/)
90             )) {
91             $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
92             $AS_opened=1;
93         }
94     }
95         
96         if($line=~/<route /){$line =~ s/\<route/\<route symmetrical=\"NO\"/g;}
97     $output_string .= "$line\n";
98 }
99
100 close INPUT;
101
102 if ($fromversion == -1) {
103     die "Cannot retrieve the platform version\n";
104 }
105
106 open OUTPUT, "> $ARGV[0]";
107 print OUTPUT $output_string;
108 close OUTPUT;