ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/util.pl
Revision: 1.11
Committed: Tue Jul 22 21:24:50 2003 UTC (20 years, 10 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: stable
Changes since 1.10: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package util;
2
3 use Storable ();
4 use Scalar::Util ();
5
6 my $staterc = "$ENV{HOME}/.kgsueme";
7
8 $stateversion = 1;
9
10 our $state = -r $staterc ? Storable::retrieve($staterc) : {};
11
12 if ($state->{version} != $stateversion) {
13 warn "$staterc has wrong version - ignoring it.\n";
14 $state = {};
15 }
16
17 $state->{version} = $stateversion;
18
19 $::config = $state->{config} ||= {};
20
21 $::config->{speed} = 0; #d# optimize for speed or memory? (0,1)
22 $::config->{conserve_memory} = 0; # try to conserve memory at the expense of speed (0,1,2)
23 $::config->{randomize} = 0; # randomize placement of stones (BROKEN)
24
25 sub save_config {
26 &gtk::save_state;
27 Storable::nstore($state, $staterc);
28 app::status("save_state", "layout saved");
29 }
30
31 sub format_time($) {
32 my ($time) = @_;
33
34 $time > 60*60
35 ? sprintf "%d:%02d:%02d", $time / (60 * 60), $time / 60 % 60, $time % 60
36 : sprintf "%d:%02d", $time / 60 % 60, $time % 60;
37 }
38
39 # text to xml
40 sub toxml($) {
41 local $_ = shift;
42 s/&/&/g;
43 s/</&lt;/g;
44 s/]]>/]]&gt;/g;
45 $_;
46 }
47
48 # pseudo-"xml" to text
49 sub xmlto($) {
50 local $_ = shift;
51 s/&lt;/</g;
52 s/&amp;/&/g;
53 $_;
54 }
55
56 1;
57