Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update the script for transform platform into v3.
[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 (even if for now, only 2 versions are defined)
5
6 # Copyright (C) 2006-2007. 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 $output_string .=  "<!DOCTYPE platform SYSTEM \"simgrid.dtd\">\n";
24 $output_string .=  "<platform version=\"$toversion\">\n";
25 $output_string .=  " <AS  id=\"AS0\"  routing=\"Full\">\n";
26
27 my $line;
28 while (defined($line = <INPUT>))
29 {
30     chomp $line;
31     # eat the header, whatever form it has
32     next if ($line =~ s/<\?xml[^>]*>//           && ! $line =~ /\S/); # just in case several tags are on the same line
33     next if ($line =~ s/<!DOCTYPE[^>]*>//        && ! $line =~ /\S/);
34     
35     if ($line =~ s/<platform(_description)? *>//)
36     {
37                 $fromversion = 0;
38                 print "version 0\n";
39                 next if !$line =~ /\S/;
40     }
41     elsif ($line =~ s/<platform.*version=["]*([0-9.])["]*>//)
42     {
43                 $fromversion = $1;
44                 print "version $fromversion\n";
45                 if ($fromversion == $toversion) 
46                 {
47                 die "Input platform file version is already $fromversion. This should be a no-op.\n";
48                 }
49                 if ($fromversion > $toversion)
50                 {
51                 die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
52                 }
53                 next if !$line =~ /\S/;
54     }
55     
56     if ($fromversion == 0)
57     {
58                 while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|)
59                 {
60                 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
61                 }
62                 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/)
63                 {
64                 $line = "$1<cpu${2}power=\"$3\"$4";
65                 }
66                 while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|)
67                 {
68                 $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
69                 }
70                 while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/)
71                 {
72                 $line = "$1<network_link${2}bandwidth=\"$3\"$4";
73                 }
74     }
75
76     if ($fromversion < 2) 
77     {
78                 # The renamings (\b=zero-width word boundary check)
79                 $line =~ s/\bplatform_description\b/platform/g;
80                 $line =~ s/\bname\b/id/g;
81                 $line =~ s/\bcpu\b/host/g;
82                 $line =~ s/\bnetwork_link\b/link/g;
83                 $line =~ s/\broute_element\b/link:ctn/g;
84     }
85     
86     if($line =~ /^(.*)<\/platform>(.*)$/)
87         {
88                 $output_string .=  " <\/AS>\n<\/platform>";
89         }
90         else
91         {
92         $output_string .=  "$line\n";
93         }
94 }
95
96 close INPUT;
97
98 if ($fromversion == -1) {
99     die "Cannot retrieve the platform version\n";
100 }
101
102 open OUTPUT, "> $ARGV[0]";
103 print OUTPUT $output_string;
104 close OUTPUT;