Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further cleanups to the cmake files. We now have a manual but properly working 'make...
[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=2;
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
26 my $line;
27 while (defined($line = <INPUT>)) {
28     chomp $line;
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/);
32     
33     if ($line =~ s/<platform(_description)? *>//) {
34         $fromversion = 0;
35         next if !$line =~ /\S/;
36     } elsif ($line =~ s/<platform(_description)? *version=['"]?([0-9.]*)["']?>//) {
37         $fromversion = $1;
38         if ($fromversion == $toversion) {
39             warn "Input platform file version is already $fromversion. This should be a no-op.\n";
40         }
41         if ($fromversion > $toversion) {
42             die "Input platform file version is more recent than this script (file version: $fromversion; script version: $toversion)\n";
43         }
44         next if !$line =~ /\S/;
45     }
46     
47     if ($fromversion == 0) {
48         while ($line =~ m|^(.*?)<cpu(.*?)power="([^"]*)"(.*)$|) {
49             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
50         }
51         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*)$/) {
52             $line = "$1<cpu${2}power=\"$3\"$4";
53         }
54         while ($line =~ m|^(.*?)<network_link(.*?)bandwidth="([^"]*)"(.*?)$|) {
55             $line = "$1TOTOTUTUTATA${2}TOTOTUTUTATA".($3*1000000)."TOTOTUTUTATA${4}";
56         }
57         while ($line =~ /^(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)TOTOTUTUTATA(.*?)$/) {
58             $line = "$1<network_link${2}bandwidth=\"$3\"$4";
59         }
60     }
61
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;
69     }
70     $output_string .=  "$line\n";
71 }
72
73 close INPUT;
74
75 if ($fromversion == -1) {
76     die "Cannot retrieve the platform version\n";
77 }
78
79 open OUTPUT, "> $ARGV[0]";
80 print OUTPUT $output_string;
81 close OUTPUT;