ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/util.pl
Revision: 1.14
Committed: Sat Jun 5 15:58:00 2004 UTC (19 years, 11 months ago) by elmex
Content type: text/plain
Branch: MAIN
Changes since 1.13: +1 -0 lines
Log Message:
suppress_userpic config var

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 $::config->{suppress_userpic} = 0; # for omitting the userpic in the game window
25
26 sub save_config {
27 &gtk::save_state;
28 Storable::nstore ($state, $staterc);
29 app::status ("save_state", "layout saved");
30 }
31
32 sub format_time($) {
33 my ($time) = @_;
34
35 $time > 60*60
36 ? sprintf "%d:%02d:%02d", $time / (60 * 60), $time / 60 % 60, $time % 60
37 : sprintf "%d:%02d", $time / 60 % 60, $time % 60;
38 }
39
40 sub parse_time($) {
41
42 my $time;
43 $time = $time * 60 + $_ for split /:/, $_[0];
44
45 $time;
46 }
47
48 # text to xml
49 sub toxml($) {
50 local $_ = shift;
51 s/&/&/g;
52 s/</&lt;/g;
53 s/]]>/]]&gt;/g;
54 $_;
55 }
56
57 # pseudo-"xml" to text
58 sub xmlto($) {
59 local $_ = shift;
60 s/&lt;/</g;
61 s/&amp;/&/g;
62 $_;
63 }
64
65 1;
66