summaryrefslogtreecommitdiff
path: root/appl/lib
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2009-05-17 15:28:42 +0000
committerCharles.Forsyth <devnull@localhost>2009-05-17 15:28:42 +0000
commitaf1b61f55a195350b4491438e8b2c381c4ba34bc (patch)
tree1d21834680a5c02e205d176c32dcf2a6f5db79fb /appl/lib
parent8d8ff66ed15c0d625b78f11a4feeeef6516937be (diff)
20090517-1627
Diffstat (limited to 'appl/lib')
-rw-r--r--appl/lib/daytime.b43
1 files changed, 30 insertions, 13 deletions
diff --git a/appl/lib/daytime.b b/appl/lib/daytime.b
index 0e16073b..5fc62fc4 100644
--- a/appl/lib/daytime.b
+++ b/appl/lib/daytime.b
@@ -222,21 +222,26 @@ readtimezone(fname: string): ref Timezone
tz.stdiff = 0;
tz.stname = "GMT";
- fd: ref Sys->FD;
+ s: string;
if(fname == nil){
- fd = sys->open("/env/timezone", Sys->OREAD);
- if(fd == nil)
- fd = sys->open("/locale/timezone", Sys->OREAD);
- }else
- fd = sys->open("/locale/" + fname, sys->OREAD);
- if(fd == nil)
- return tz;
- buf := array[2048] of byte;
- cnt := sys->read(fd, buf, len buf);
- if(cnt <= 0)
+ s = readfile("/env/timezone");
+ if(s == nil)
+ s = readfile("/locale/timezone");
+ }else{
+ if(fname[0] != '/' && fname[0] != '#')
+ fname = "/locale/" + fname;
+ s = readfile(fname);
+ }
+ if(s == nil)
return tz;
-
- (n, val) := sys->tokenize(string buf[0:cnt], "\t \n\r");
+ if(s[0] == '/' || s[0] == '#'){
+ if(s[len s-1] == '\n')
+ s = s[0: len s-1];
+ s = readfile(s);
+ if(s == nil)
+ return tz;
+ }
+ (n, val) := sys->tokenize(s, "\t \n\r");
if(n < 4)
return tz;
@@ -255,6 +260,18 @@ readtimezone(fname: string): ref Timezone
return tz;
}
+readfile(name: string): string
+{
+ fd := sys->open(name, Sys->OREAD);
+ if(fd == nil)
+ return nil;
+ buf := array[2048] of byte;
+ n := sys->read(fd, buf, len buf);
+ if(n <= 0)
+ return nil;
+ return string buf[0:n];
+}
+
SEC2MIN: con 60;
SEC2HOUR: con 60*SEC2MIN;
SEC2DAY: con 24*SEC2HOUR;