summaryrefslogtreecommitdiffstats
path: root/systemservice/config/library/system_manager_config/last2order/tool/mklast2ordertbl.pl
blob: 9b7dcabae6b597ea33ab2e3f997bf869366f2f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl 
use strict;

use XML::XPath;

my $LOCAL_XML = "./last2order.xml.tmp";
my $LOCAL_DTD = "./last2order.dtd";

my $DTD = <<'EODTD';
<!ELEMENT last2order_tbl (last2order*) >

<!ELEMENT  last2order EMPTY>
<!ATTLIST last2order
  front_video     CDATA "EMPTY"
  front_sub_video CDATA "EMPTY"
  front_audio     CDATA "EMPTY"
  rear_video      CDATA "EMPTY"
  rear_audio      CDATA "EMPTY"
  ordername       CDATA #REQUIRED
>
EODTD

sub usage(){
  print STDERR "USAGE:$0 *.xml *.cfo\n";
}

#==== MAIN ====
my $ret=system("which xmllint > /dev/null");
if($ret != 0){
  die("xmllint is not installed \n");
}

if(2 != @ARGV){
  usage();
  exit 1;
}

my $inXmlFile= $ARGV[0];
my $outCfgXmlFile= $ARGV[1];


#ARG CHECK
if(! -e $inXmlFile){
  die("$inXmlFile not found");
} 


system("cp $inXmlFile $LOCAL_XML");

open FOUT,'>',$LOCAL_DTD or die("can't open $LOCAL_DTD");
print FOUT $DTD;
close FOUT;

$ret=system("xmllint --noout --valid $LOCAL_XML ");
if($ret != 0){
  die("$inXmlFile is NOT VAILD");
}

my $xml = XML::XPath->new(filename=>$LOCAL_XML);

my $last2order_tbl = $xml->find('/last2order_tbl/last2order');

my @nodelist = $last2order_tbl->get_nodelist;
my $numOfElement = @nodelist;

printf("num of element :$numOfElement\n");

my $writeValue;
open FOUT,'+>',$outCfgXmlFile or die("can't open $outCfgXmlFile");
binmode(FOUT);

$writeValue = pack("A4","CTOO"); print FOUT $writeValue; 
$writeValue = pack("L",$numOfElement); print FOUT $writeValue; 

foreach my $last2order( @nodelist ) {
  $writeValue = $last2order->findvalue('@front_video');
  printf("FV:$writeValue  ");
  $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 

  $writeValue = $last2order->findvalue('@front_sub_video');
  printf("FSV:$writeValue  ");
  $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 

  $writeValue = $last2order->findvalue('@front_audio');
  printf("FA:$writeValue  ");
  $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 

  $writeValue = $last2order->findvalue('@rear_video');
  printf("RV:$writeValue  ");
  $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 

  $writeValue = $last2order->findvalue('@rear_audio');
  printf("RA:$writeValue  ");
  $writeValue = pack("a128",$writeValue); print FOUT $writeValue; 

  $writeValue = $last2order->findvalue('@ordername');
  printf("ON:$writeValue  ");
  $writeValue = pack("a64",$writeValue); print FOUT $writeValue; 

  printf("\n");
}

close(FOUT);

system("rm $LOCAL_XML $LOCAL_DTD");