Browse Source

Added support for reading and writing raw sizes

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7999 8c9fc860-2736-0410-a75d-ab315db34111
eth.negelef 7 years ago
parent
commit
701266e27a
1 changed files with 16 additions and 0 deletions
  1. 16 0
      source/Streams.Mod

+ 16 - 0
source/Streams.Mod

@@ -220,6 +220,13 @@ TYPE
 			Char( CHR( x MOD 128 ) )
 			Char( CHR( x MOD 128 ) )
 		END RawNum;
 		END RawNum;
 
 
+	(** Write a size in a compressed format. *)
+		PROCEDURE RawSize*( x: SIZE );
+		BEGIN
+			WHILE (x < -64) OR (x > 63) DO Char( CHR( x MOD 128 + 128 ) );  x := x DIV 128 END;
+			Char( CHR( x MOD 128 ) )
+		END RawSize;
+
 		(** -- Write formatted data -- *)
 		(** -- Write formatted data -- *)
 
 
 	(** Write an ASCII end-of-line (CR/LF). *)
 	(** Write an ASCII end-of-line (CR/LF). *)
@@ -761,6 +768,15 @@ TYPE
 			x := ASH( LSH( LONGINT( ORD( ch ) ), 25 ), n - 25 ) + y
 			x := ASH( LSH( LONGINT( ORD( ch ) ), 25 ), n - 25 ) + y
 		END RawNum;
 		END RawNum;
 
 
+	(** Read a size in a compressed format. *)
+		PROCEDURE RawSize*( VAR x: SIZE );
+		VAR ch: CHAR;  n, y: SIZE;
+		BEGIN
+			n := 0;  y := 0;  ch := Get();
+			WHILE ch >= 80X DO INC( y, LSH( SIZE( ORD( ch ) ) - 128, n ) );  INC( n, 7 );  ch := Get() END;
+			x := ASH( LSH( SIZE( ORD( ch ) ), SIZE OF SIZE * 8 - 7 ), n - SIZE OF SIZE * 8 - 7 ) + y
+		END RawSize;
+
 		(** -- Read formatted data (uses Peek for one character lookahead) -- *)
 		(** -- Read formatted data (uses Peek for one character lookahead) -- *)
 
 
 	 (** Read an integer value in decimal or hexadecimal.  If hex = TRUE, recognize the "H" postfix for hexadecimal numbers. *)
 	 (** Read an integer value in decimal or hexadecimal.  If hex = TRUE, recognize the "H" postfix for hexadecimal numbers. *)