]> matita.cs.unibo.it Git - helm.git/blob - helm/hxsp/splitted/4.hash.p.pl
ocaml 3.09 transition
[helm.git] / helm / hxsp / splitted / 4.hash.p.pl
1 #################################################################################################
2 #################################################################################################
3 #################################################################################################
4 # Stylesheet hash check subrutines
5 #################################################################################################
6 #################################################################################################
7 #################################################################################################
8
9 #################################################################################################
10 # sub addcheckvalues
11 # Usage: addcheckvalues($key,$uri);
12 # Returns: error message or  0 if no errors found
13 # Do: check if key and uri are already loaded
14 # Used by: addvalues
15 # Uses : err_replace
16 #################################################################################################
17 sub addcheckvalues
18 {
19    my $ac_key = shift(@_);
20    my $ac_uri = shift(@_);
21    if (exists $stylesheet_hash{$ac_key})
22    {
23       return err_replace($error{"add_dup_key"},$ac_key,$ac_uri,"");
24    }
25    elsif (exists $by_name{$ac_uri})
26    {
27      return err_replace($error{"add_dup_value"},$ac_key,$ac_uri,$by_name{$ac_key});
28    }
29    else  {   return 0;  }
30 }
31 #################################################################################################
32
33 #################################################################################################
34 # sub recheckvalues
35 # Usage: recheckvalues($key);
36 # Returns: error message or  0 if no errors found
37 # Do: check if key are loaded
38 # Used by: remove, reloadvalues
39 # Uses : err_replace
40 #################################################################################################
41 sub recheckvalues
42 {
43    my $re_key = shift(@_);
44    if (not exists $stylesheet_hash{$re_key})
45    {
46      return err_replace($error{"re_inv_key"},$re_key,"","");
47    }
48    else { return 0; }
49 }
50 #################################################################################################
51
52 #################################################################################################
53 # sub applycheckvalues
54 # Usage: applycheckvalues(\@keys);
55 # Returns: error message or  0 if no errors found
56 # Do: check if keys in @keys are loaded
57 # Used by: remove, reloadvalues
58 # Uses : err_replace
59 #################################################################################################
60 sub applycheckvalues
61 {
62    my $applykeys_ptr = shift(@_);
63    foreach $applykey (@$applykeys_ptr)
64    {
65       if (not exists $stylesheet_hash{$applykey})
66       {
67          return err_replace($error{"apply_inv_key"},$applykey,"","");
68       }
69    }
70    return 0;
71 }
72 #################################################################################################
73
74 #################################################################################################
75 #################################################################################################
76 #################################################################################################
77 # Stylesheet hash modify subrutines
78 #################################################################################################
79 #################################################################################################
80 #################################################################################################
81
82 #################################################################################################
83 # sub addvalues
84 # Usage: if add_halt_on_errors is ON addvalues($key,$uri,@added);
85 #        else addvalues($key,$uri)
86 # Returns: error message or 0 on success,
87 #             if add_halt_on_errors is ON return all the added keys on @added
88 # Do: add the values to the stylesheet hash
89 # Used by: add
90 # Uses : addcheckvalues, loadstyle
91 #################################################################################################
92 sub addvalues
93 {
94    my $av_key = shift(@_);
95    my $av_uri = shift(@_);
96    my $av_stylesheet; #parsed stylesheet to be placed in hash
97    if (my $err = addcheckvalues($av_key,$av_uri)) { return $err; }
98    elsif (my $err = loadstyle($av_key, $av_uri, $av_stylesheet)) { return $err; }
99    else
100    {
101       $stylesheet_hash{$av_key}[0]=$av_uri;
102       $stylesheet_hash{$av_key}[1]=$av_stylesheet;
103       $by_name{$av_uri}=$av_key;
104       return 0;
105    }
106 }
107 #################################################################################################
108
109 #################################################################################################
110 # sub removevalues
111 # Usage: removevalues($key);
112 # Returns: message
113 # Do: remove the key specified and relative values from the stylesheet hash
114 # Used by: remove, do_remove
115 # Uses : ok_replace
116 #################################################################################################
117 sub removevalues
118 {
119    my $cr_key = shift(@_);
120    my $cr_uri = $stylesheet_hash{$cr_key}[0];
121    delete $stylesheet_hash{$cr_key};
122    delete $by_name{$cr_uri};
123    return ok_replace("$s_remove\n",$cr_key,$cr_uri);
124 }
125 #################################################################################################
126
127 #################################################################################################
128 # sub reloadvalues
129 # Usage: if add_halt_on_errors is ON reloadvalues($key.\%reloaded);
130 #        else reloadvalues($key);
131 # Returns: error message or 0 on success,
132 #             if add_halt_on_errors is ON return the old stylesheets in %reloaded
133 # Do: reload the stlylesheet with the key specified
134 # Used by: do_reload
135 # Uses : recheckvalues, loadstyle
136 #################################################################################################
137 sub reloadvalues
138 {
139    my $rv_key = shift(@_);
140    my $rv_uri = $stylesheet_hash{$rv_key}[0];
141    my $rv_stylesheet; #parsed stylesheet to be placed in hash
142    if (my $err = recheckvalues($rv_key)) { return $err; }
143    elsif (my $err = loadstyle($rv_key, $rv_uri, $rv_stylesheet)) { return $err; }
144    else
145    {
146       $stylesheet_hash{$rv_key}[1] = $rv_stylesheet;
147       return 0;
148    }
149 }
150 #################################################################################################