Browse Source

HostDates fixed

Alexander Shiryaev 12 years ago
parent
commit
499d35b093
4 changed files with 42 additions and 36 deletions
  1. BIN
      BlackBox/Lin/Mod/Dates.odc
  2. 41 31
      BlackBox/Lin/Mod/Dates.txt
  3. 1 2
      BlackBox/tests
  4. 0 3
      TODO

BIN
BlackBox/Lin/Mod/Dates.odc


+ 41 - 31
BlackBox/Lin/Mod/Dates.txt

@@ -3,80 +3,90 @@ MODULE HostDates;
 	(* THIS IS TEXT COPY OF Dates.odc *)
 	(* DO NOT EDIT *)
 
-IMPORT	Dates, Strings, SYSTEM,Libc := LinLibc ;
-TYPE
-	DatesHook = POINTER TO RECORD (Dates.Hook) END;
-
+	IMPORT 
+		SYSTEM, LinLibc, Dates;
+	
+	(* Dates Hook *)
+	
+		TYPE
+		DatesHook = POINTER TO RECORD (Dates.Hook) END;
 	
 	(*
-	Some conversions are needed between the Linux and the BlackBox representations of  dates. The following table shows the differences:
+	
+	Some conversions are needed between the Linux and the BlackBox representations of  dates. The following
+	table shows the differences:
+	
 (!)		Linux	BlackBox
 	year	from year 1900	from year 0000
 	month	range 0-11	range 1-12
 	weekday	0:sunday - 6:satruday	0:monday - 6:sunday
 	(!)	*)
-		
+	
 	PROCEDURE (h: DatesHook) DateToString (d: Dates.Date; format: INTEGER; OUT str: ARRAY OF CHAR);
-		VAR sstr: ARRAY 64 OF SHORTCHAR; 
-			tm: Libc.tm; 
-			res: INTEGER; 
+		VAR tm: LinLibc.tmDesc; sstr: ARRAY 64 OF SHORTCHAR; res: LinLibc.size_t; 
 	BEGIN
+		ASSERT(format IN {Dates.short, Dates.abbreviated, Dates.long, Dates.plainAbbreviated, Dates.plainLong}, 20);
 		tm.tm_year := d.year - 1900; (* Linux counts years from 1900 but BlackBox from 0000 *)
 		tm.tm_mon := d.month - 1; tm.tm_mday := d.day;
 		tm.tm_wday := (Dates.DayOfWeek(d) + 1) MOD 7;		
-		CASE format OF
-		| Dates.short :	res := Libc.strftime(sstr, LEN(sstr), "%x", tm)
-		| Dates.abbreviated : res := Libc.strftime(sstr, LEN(sstr), "%a, %b %d, %Y", tm)
-		| Dates.long : 	res := Libc.strftime(sstr, LEN(sstr), "%A, %B %d, %Y", tm)
-		| Dates.plainAbbreviated :	res := Libc.strftime(sstr, LEN(sstr), "%b %d, %Y", tm)
-		| Dates.plainLong:	res := Libc.strftime(sstr, LEN(sstr), "%B %d, %Y", tm)
+		IF format = Dates.short THEN
+			res := LinLibc.strftime(sstr, LEN(sstr), "%x", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)))
+		ELSIF format = Dates.abbreviated THEN
+			res := LinLibc.strftime(sstr, LEN(sstr), "%a, %b %d, %Y", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)))
+		ELSIF format = Dates.long THEN
+			res := LinLibc.strftime(sstr, LEN(sstr), "%A, %B %d, %Y", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)))
+		ELSIF format = Dates.plainAbbreviated THEN
+			res := LinLibc.strftime(sstr, LEN(sstr), "%b %d, %Y", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)))
+		ELSE (* format = Dates.plainLong *)
+			res := LinLibc.strftime(sstr, LEN(sstr), "%B %d, %Y", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)))
 		END;
-		IF res > 0 THEN str := sstr$ ELSE str := "invalid date"  END
+		IF res > 0 THEN str := sstr$ELSE str := "invalid date"  END
 	END DateToString;
 
-		(** time **)
 	PROCEDURE (h: DatesHook) GetTime (OUT d: Dates.Date; OUT t: Dates.Time);
-		VAR time: Libc.time_t; tm: Libc.tm;
+		VAR time: LinLibc.time_t; tm: LinLibc.tm;
 	BEGIN
-		time := Libc.time(NIL);
-		tm := Libc.localtime(time);
+		time := LinLibc.time(NIL);
+		tm := LinLibc.localtime(time);
 		d.year := tm.tm_year + 1900; (* Linux counts years from 1900 but BlackBox from 0000 *)
 		d.month := tm.tm_mon + 1;  d.day := tm.tm_mday;
 		t.hour := tm.tm_hour; t.minute := tm.tm_min; t.second := tm.tm_sec
 	END GetTime;
 
 	PROCEDURE (h: DatesHook) GetUTCBias (OUT bias: INTEGER);
-		VAR time: Libc.time_t; tm: Libc.tm;
+		VAR time: LinLibc.time_t; tm: LinLibc.tm;
 	BEGIN
-		time := Libc.time(NIL);
-		tm := Libc.localtime(time); 
-		bias := tm.tm_gmtoff DIV 60;
+		time := LinLibc.time(NIL);
+		tm := LinLibc.localtime(time); (* call to localtime needed to make sure that timezone is set *)
+		bias := tm.tm_gmtoff DIV 60; (* Shiryaev A. V.: OpenBSD *)
 	END GetUTCBias; 
 
 	PROCEDURE (h: DatesHook) GetUTCTime (OUT d: Dates.Date; OUT t: Dates.Time);
-		VAR time: Libc.time_t; tm: Libc.tm;
+		VAR time: LinLibc.time_t; tm: LinLibc.tm;
 	BEGIN
-		time := Libc.time(NIL);
-		tm := Libc.gmtime(time);
+		time := LinLibc.time(NIL);
+		tm := LinLibc.gmtime(time);
 		d.year := tm.tm_year + 1900; (* Linux counts years from 1900 but BlackBox from 0000 *)
 		d.month := tm.tm_mon + 1;  d.day := tm.tm_mday;
 		t.hour := tm.tm_hour; t.minute := tm.tm_min; t.second := tm.tm_sec
 	END GetUTCTime;
 
 	PROCEDURE (h: DatesHook) TimeToString (t: Dates.Time; OUT str: ARRAY OF CHAR);
-		VAR tm: Libc.tm; sstr: ARRAY 64 OF SHORTCHAR; res: INTEGER;
+		VAR tm: LinLibc.tmDesc; sstr: ARRAY 64 OF SHORTCHAR; res: LinLibc.size_t;
 	BEGIN
 		tm.tm_hour := t.hour; tm.tm_min := t.minute; tm.tm_sec := t.second;
-		res := Libc.strftime(sstr, LEN(sstr), "%X", tm);
+		res := LinLibc.strftime(sstr, LEN(sstr), "%X", SYSTEM.VAL(LinLibc.tm, SYSTEM.ADR(tm)));
 		IF res > 0 THEN str := sstr$ELSE str := "invalid time"  END
 	END TimeToString;
 
+
 	PROCEDURE Init;
-	VAR 	datesHook: DatesHook; 
+		VAR 
+			datesHook: DatesHook;
 	BEGIN
 		NEW(datesHook); Dates.SetHook(datesHook);
 	END Init;
+
 BEGIN
 	Init
 END HostDates.
-

+ 1 - 2
BlackBox/tests

@@ -14,8 +14,7 @@ ConsCompiler.Compile('', 'HostFonts.txt')
 DevElfLinker.LinkDll libBB.so := Kernel+ Files HostFiles StdLoader
 DATA
 
-# what is source of TRAP???
 ./run-BlackBox <<DATA
 DevCompiler.CompileThis DevLinker
-#DevLinker.LinkDll BlackBox.exe := Kernel$+ Files HostFiles StdLoader
+DevLinker.LinkDll BlackBox.exe := Kernel$+ Files HostFiles StdLoader
 DATA

+ 0 - 3
TODO

@@ -2,9 +2,6 @@ By priority:
 	ConsCompiler can not compile HostFonts.txt
 		?????
 
-	runtime error on compiling DevLinker
-		?????
-
 	Services
 
 	Comm