ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/util.pl
Revision: 1.16
Committed: Tue Jun 8 23:13:28 2004 UTC (19 years, 11 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.15: +6 -0 lines
Log Message:
date_string

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 date_string($) {
41 my ($timestamp) = @_;
42 use POSIX ();
43 return (POSIX::strftime "%Y-%m-%d %H:%M", localtime $timestamp);
44 }
45
46 sub parse_time($) {
47
48 my $time;
49 $time = $time * 60 + $_ for split /:/, $_[0];
50
51 $time;
52 }
53
54 # text to xml
55 sub toxml($) {
56 local $_ = shift;
57 s/&/&/g;
58 s/</&lt;/g;
59 s/]]>/]]&gt;/g;
60 $_;
61 }
62
63 # pseudo-"xml" to text
64 sub xmlto($) {
65 local $_ = shift;
66 s/&lt;/</g;
67 s/&amp;/&/g;
68 $_;
69 }
70
71 1;
72