Init basesystem source codes.
[staging/basesystem.git] / systemservice / config / library / system_manager_config / last2order / tool / mklast2ordertbl.pl
1 #!/usr/bin/perl 
2 use strict;
3
4 use XML::XPath;
5
6 my $LOCAL_XML = "./last2order.xml.tmp";
7 my $LOCAL_DTD = "./last2order.dtd";
8
9 my $DTD = <<'EODTD';
10 <!ELEMENT last2order_tbl (last2order*) >
11
12 <!ELEMENT  last2order EMPTY>
13 <!ATTLIST last2order
14   front_video     CDATA "EMPTY"
15   front_sub_video CDATA "EMPTY"
16   front_audio     CDATA "EMPTY"
17   rear_video      CDATA "EMPTY"
18   rear_audio      CDATA "EMPTY"
19   ordername       CDATA #REQUIRED
20 >
21 EODTD
22
23 sub usage(){
24   print STDERR "USAGE:$0 *.xml *.cfo\n";
25 }
26
27 #==== MAIN ====
28 my $ret=system("which xmllint > /dev/null");
29 if($ret != 0){
30   die("xmllint is not installed \n");
31 }
32
33 if(2 != @ARGV){
34   usage();
35   exit 1;
36 }
37
38 my $inXmlFile= $ARGV[0];
39 my $outCfgXmlFile= $ARGV[1];
40
41
42 #ARG CHECK
43 if(! -e $inXmlFile){
44   die("$inXmlFile not found");
45
46
47
48 system("cp $inXmlFile $LOCAL_XML");
49
50 open FOUT,'>',$LOCAL_DTD or die("can't open $LOCAL_DTD");
51 print FOUT $DTD;
52 close FOUT;
53
54 $ret=system("xmllint --noout --valid $LOCAL_XML ");
55 if($ret != 0){
56   die("$inXmlFile is NOT VAILD");
57 }
58
59 my $xml = XML::XPath->new(filename=>$LOCAL_XML);
60
61 my $last2order_tbl = $xml->find('/last2order_tbl/last2order');
62
63 my @nodelist = $last2order_tbl->get_nodelist;
64 my $numOfElement = @nodelist;
65
66 printf("num of element :$numOfElement\n");
67
68 my $writeValue;
69 open FOUT,'+>',$outCfgXmlFile or die("can't open $outCfgXmlFile");
70 binmode(FOUT);
71
72 $writeValue = pack("A4","CTOO"); print FOUT $writeValue; 
73 $writeValue = pack("L",$numOfElement); print FOUT $writeValue; 
74
75 foreach my $last2order( @nodelist ) {
76   $writeValue = $last2order->findvalue('@front_video');
77   printf("FV:$writeValue  ");
78   $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 
79
80   $writeValue = $last2order->findvalue('@front_sub_video');
81   printf("FSV:$writeValue  ");
82   $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 
83
84   $writeValue = $last2order->findvalue('@front_audio');
85   printf("FA:$writeValue  ");
86   $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 
87
88   $writeValue = $last2order->findvalue('@rear_video');
89   printf("RV:$writeValue  ");
90   $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 
91
92   $writeValue = $last2order->findvalue('@rear_audio');
93   printf("RA:$writeValue  ");
94   $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 
95
96   $writeValue = $last2order->findvalue('@ordername');
97   printf("ON:$writeValue  ");
98   $writeValue = pack("a64",$writeValue); print FOUT $writeValue; 
99
100   printf("\n");
101 }
102
103 close(FOUT);
104
105 system("rm $LOCAL_XML $LOCAL_DTD");
106
107