]> matita.cs.unibo.it Git - helm.git/blob - helm/hxsp/splitted/9.load.p.pl
ocaml 3.09 transition
[helm.git] / helm / hxsp / splitted / 9.load.p.pl
1 #################################################################################################
2 #################################################################################################
3 #################################################################################################
4 # Subrutines to load config files and templates
5 #################################################################################################
6 #################################################################################################
7 #################################################################################################
8
9 sub load_messages
10 {
11    if ($language eq "IT")
12    {
13        open(MESSAGE, "./msg/message.it") || die "Can't open config file '/msg/message.it' : $!";
14    }
15    else
16    {
17        open(MESSAGE, "./msg/message.en") || die "Can't open config file '/msg/message.en' : $!";
18    }
19    while(my $line = <MESSAGE>) {
20       # ignore comments and full line comments
21       $line =~ s/#.*$//;
22       next unless $line =~ /\S/;
23       $line =~ s/\{URL\}/$puwobo_url/g;
24       $line =~ s/\{VER\}/$ver/g;
25       if ($line =~ /^(home_message)\s*=\s*(.*)$/) {$home_message = $2; }
26       if ($line =~ /^(help_message)\s*=\s*(.*)$/) {$help_message = $2; }
27       if ($line =~ /^(s_add)\s*=\s*(.*)$/) {$s_add = $2; }
28       if ($line =~ /^(s_reload)\s*=\s*(.*)$/) {$s_reload = $2; }
29       if ($line =~ /^(s_remove)\s*=\s*(.*)$/) {$s_remove = $2; }
30       if ($line =~ /^(list)\s*=\s*(.*)$/) {$list = $2; }
31       if ($line =~ /^(empty)\s*=\s*(.*)$/) {$empty = $2; }
32       if ($line =~ /^(all_usage)\s*=\s*(.*)$/) {$all_usage = $2; }
33       if ($all_usage_synerr eq "ON")
34       {
35          $help_usage=$add_usage=$remove_usage=$list_usage=$reload_usage=$apply_usage=$all_usage;
36       }
37       else
38       {
39          if ($line =~ /^(help_usage)\s*=\s*(.*)$/) {$help_usage = $2; }
40          if ($line =~ /^(add_usage)\s*=\s*(.*)$/) {$add_usage = $2; }
41          if ($line =~ /^(remove_usage)\s*=\s*(.*)$/) {$remove_usage = $2; }
42          if ($line =~ /^(list_usage)\s*=\s*(.*)$/) {$list_usage = $2; }
43          if ($line =~ /^(reload_usage)\s*=\s*(.*)$/) {$reload_usage = $2; }
44          if ($line =~ /^(apply_usage)\s*=\s*(.*)$/) {$apply_usage = $2; }
45       }
46    }
47    close MESSAGE;
48 }
49
50 sub load_conf
51 {
52    open(CONFIG, "./config") || die "Can't open config file 'config' : $!";
53    while(my $line = <CONFIG>) {
54        # ignore comments and full line comments
55        $line =~ s/#.*$//;
56        next unless $line =~ /\S/;
57        if ($line =~ /^(working_path)\s*=\s*(.*)$/) {$working_path = $2; }
58        if ($line =~ /^(language)\s*=\s*(.*)$/) {$language = $2; }
59        if ($line =~ /^(port)\s*=\s*(.*)$/) {$port = $2; }
60        if ($line =~ /^(all_usage_synerr)\s*=\s*(.*)$/) {$all_usage_synerr = $2; }
61        if ($line =~ /^(expand_xinc)\s*=\s*(.*)$/) {$expand_xinc = $2; }
62        if ($line =~ /^(max_depth)\s*=\s*(.*)$/) {$max_depth = $2; }
63    }
64    close CONFIG;
65 }
66
67 sub load_err
68 {
69    if ($language eq "IT")
70    {
71       open(ERRO, "./msg/error.it") || die "Can't open config file '/msg/error.it' : $!";
72    }
73    else
74    {
75       open(ERRO, "./msg/error.en") || die "Can't open config file '/msg/error.en' : $!";
76    }
77    while(my $line = <ERRO>)
78    {
79       # ignore comments and full line comments
80       $line =~ s/#.*$//;
81        next unless $line =~ /\S/;
82        if ($line =~ /^(.*?)\s*=\s*(.*)$/) {$error{$1} = $2; }
83    }
84    close ERRO;
85 }
86
87 sub load_templates
88 {
89         # load ok template
90         open(OK_TPL, "./tpl/ok.tpl")
91         || die "Can't open template file '/tpl/ok.tpl' : $!";
92         while(my $line = <OK_TPL>) {$ok_tpl .= $line; }
93         close OK_TPL;
94
95         # load operror template
96         open(OPERROR_TPL, "./tpl/operror.tpl")
97         || die "Can't open template file '/tpl/operror.tpl' : $!";
98         while(my $line = <OPERROR_TPL>) {$operror_tpl .= $line; }
99         close OPERROR_TPL;
100
101         # load synerror template
102         open(SYNERROR_TPL, "./tpl/synerror.tpl")
103         || die "Can't open template file '/tpl/synerror.tpl' : $!";
104         while(my $line = <SYNERROR_TPL>) {$synerror_tpl .= $line; }
105         close SYNERROR_TPL;
106 }
107
108 #################################################################################################
109 #################################################################################################
110 #################################################################################################
111 # the LibXML callbacks follow
112 # these callbacks are used for both the original parse AND the XInclude (if set)
113 #################################################################################################
114 #################################################################################################
115 #################################################################################################
116
117 sub match_uri {
118     my $uri = shift;
119     return $uri !~ /:\/\// ? 1 : 0; # we handle only files
120 }
121
122 sub open_uri {
123     my $uri = shift;
124
125     my $handler = new IO::File;
126     if ( not $handler->open( "<$uri" ) ){
127         $file = 0;
128     }
129
130     return $file;
131 }
132
133 sub read_uri {
134     my $handler = shift;
135     my $length  = shift;
136     my $buffer = undef;
137     if ( $handler ) {
138         $handler->read( $rv , $length );
139     }
140     return $buffer;
141 }
142
143 sub close_uri {
144     my $handler = shift;
145     if ( $handler ) {
146         $handler->close();
147     }
148     return 1;
149 }