Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # process_xml - process xml dispatches xml files to the correct |
2 | # xml-processing program. All xml files should begin with a comment | |
3 | # line like the following: | |
4 | # | |
5 | # <!-- interpreter=program_name --> | |
6 | # | |
7 | # where program_name is the name of the program that should process | |
8 | # the xml file. process_xml assumes that the program is located in | |
9 | # the bin/ directory of the Riesling workspace, so only the name of | |
10 | # the program needs to be provided. | |
11 | use strict; | |
12 | use Getopt::Std; | |
13 | use vars qw( $opt_S $opt_I ); | |
14 | ||
15 | my $perl_interpreter = $^X; | |
16 | ||
17 | ||
18 | getopts('S:I:'); | |
19 | # S - source file destination path | |
20 | # I - include file destination path | |
21 | ||
22 | $opt_S = '-S ' . $opt_S if defined $opt_S; | |
23 | $opt_I = '-I ' . $opt_I if defined $opt_I; | |
24 | ||
25 | my $xmlFile = $ARGV[$#ARGV]; | |
26 | open ( XML_FILE, "$xmlFile" ) || die "Can't open XML file: $xmlFile\n"; | |
27 | while( <XML_FILE> ){ | |
28 | chomp; | |
29 | if( /interpreter=([\w\d\.]+)/ ){ | |
30 | my $extra_args; | |
31 | my $line = $_; | |
32 | close( XML_FILE ); | |
33 | my $fullpath = $0; | |
34 | my $program = $1; | |
35 | $extra_args = $1 if $line =~ /args=\'([\w\d\s\-]+)\'/; | |
36 | my $perl_lib; | |
37 | ( $perl_lib = $fullpath ) =~ s#bin/process_xml#lib/perl#g; | |
38 | $fullpath =~ s/process_xml/$program/g; | |
39 | ||
40 | my $r = system( "$perl_interpreter -I$perl_lib $fullpath $opt_S $opt_I $extra_args @ARGV " ); | |
41 | if( $r != 0 ){ | |
42 | die "$program returned with status $r\n"; | |
43 | } else { | |
44 | exit 0; | |
45 | } | |
46 | } | |
47 | } | |
48 | ||
49 | die "Couldn't locate an interpreter in $xmlFile\n"; | |
50 | ||
51 | __END__ | |
52 | ||
53 | =head1 NAME | |
54 | ||
55 | process_xml - A frontend to all Riesling XML-processing scripts. | |
56 | ||
57 | =head1 SYNOPSYS | |
58 | ||
59 | process_xml [script arguments] xml file | |
60 | ||
61 | =head1 DESCRIPTION | |
62 | ||
63 | process_xml is a frontend to all Rielsing XML-processing scripts. All XML specification | |
64 | files written for Riesling must have the following XML comment as their first nonblank line. | |
65 | ||
66 | <!-- interpreter=I<script_name> --> | |
67 | ||
68 | process_xml reads the XML file whose name was specified on the command line and invokes the | |
69 | the appropriate interpreter specified in the the XML comment line. The interpreter is assumed | |
70 | to be in the Riesling workspace's bin directory. | |
71 | ||
72 | Extra arguments can be passed to a script using the optional I<args> directive provided in | |
73 | an XML file's interpreter line. See the example below. This should be used to pass | |
74 | script-specific or file-specific arguments. | |
75 | ||
76 | <!-- interpreter=I<script_name> args='<extra_args>' --> | |
77 | ||
78 | If process_xml successfully invokes the specified interpreter, it will return the exit status | |
79 | of the interpreter. If the interpreter is not found, is not executable, or the interpretation | |
80 | directive in the XML file cannot be located, process_xml will issue and error message to | |
81 | stderr and exit with nonzero status. | |
82 | ||
83 | ||
84 | =head1 OPTIONS | |
85 | ||
86 | =item I<script arguments> | |
87 | ||
88 | All arguments passed to process_xml are passed-on to the specified interpreter. | |
89 | ||
90 | =head1 EXAMPLES | |
91 | ||
92 | process_xml -n Mmu -I /src/Riesling/include/mmu -S /src/Riesling/src/mmu MmuConfigReg.xml | |
93 | ||
94 | Here, process_xml is being invoked on the file MmuConfigReg.xml which is processes by xml2reg. | |
95 | All of the arguments passed to process_xml are passed on to xml2reg. |