DEADSOFTWARE

Исправлено чтение и запсь в Files, Texts портирован из voc, добавлены типы SYSTEM...
[dsw-obn.git] / rtl / java / Files.java
index c201940c21cbb37cc41a3f0b85ee546288cea4b9..17694523dbba69ef510b4d21ffb0b4965c3f72df 100644 (file)
@@ -207,80 +207,48 @@ class Files
 
        public static void ReadInt(RECORD1 R[], int R$, short x[], int x$)
        {
-               RECORD1 rider = R[R$];
-               RandomAccessFile desc = rider.base.desc;
-
-               try
-               {
-                       rider.base.SetActive(rider);
-                       byte[] buf = new byte[2];
-                       rider.res[0] = desc.read(buf, 0, 2);
-                       rider.eof[0] = (rider.res[0] != 0);
-                       x[x$] = (short) (((buf[1] & 0xff) << 8) | (buf[0] & 0xff));
-                       rider.position += 2 - rider.res[0];
-               }
-               catch(IOException e)
-               {
-                       rider.res[0] = 2;
-                       rider.eof[0] = true;
-               }
+               byte[][] buf = new byte[1][2];
+               ReadBytes(R, R$, buf, 0, 2);
+               x[x$]  = (short) ((buf[0][1] & 0xff) << 8);
+               x[x$] |= (short) (buf[0][0] & 0xff);
        }
 
        public static void ReadLInt(RECORD1 R[], int R$, int x[], int x$)
        {
-               RECORD1 rider = R[R$];
-               RandomAccessFile desc = rider.base.desc;
+               byte[][] buf = new byte[1][4];
+               ReadBytes(R, R$, buf, 0, 4);
+               x[x$]  = (int) ((buf[0][3] & 0xff) << 24);
+               x[x$] |= (int) ((buf[0][2] & 0xff) << 16);
+               x[x$] |= (int) ((buf[0][1] & 0xff) << 8);
+               x[x$] |= (int) ((buf[0][0] & 0xff));
+       }
 
-               try
-               {
-                       rider.base.SetActive(rider);
-                       byte[] buf = new byte[4];
-                       rider.res[0] = desc.read(buf, 0, 4);
-                       rider.eof[0] = (rider.res[0] != 0);
-                       x[x$] = ((buf[3] & 0xff) << 24) | ((buf[2] & 0xff) << 16) | ((buf[1] & 0xff) << 8) | (buf[0] & 0xff);
-                       rider.position += 4 - rider.res[0];
-               }
-               catch(IOException e)
-               {
-                       rider.res[0] = 4;
-                       rider.eof[0] = true;
-               }
+       public static void ReadHInt(RECORD1 R[], int R$, long x[], int x$)
+       {
+               byte[][] buf = new byte[1][8];
+               ReadBytes(R, R$, buf, 0, 8);
+               x[x$]  = (buf[0][7] & 0xff) << 56;
+               x[x$] |= (buf[0][6] & 0xff) << 48;
+               x[x$] |= (buf[0][5] & 0xff) << 40;
+               x[x$] |= (buf[0][4] & 0xff) << 32;
+               x[x$] |= (buf[0][3] & 0xff) << 24;
+               x[x$] |= (buf[0][2] & 0xff) << 16;
+               x[x$] |= (buf[0][1] & 0xff) << 8;
+               x[x$] |= (buf[0][0] & 0xff);
        }
 
        public static void ReadReal(RECORD1 R[], int R$, float x[], int x$)
        {
-               RECORD1 rider = R[R$];
-               RandomAccessFile desc = rider.base.desc;
-
-               try
-               {
-                       rider.base.SetActive(rider);
-                       x[x$] = desc.readFloat();
-                       rider.position += 4;
-               }
-               catch(IOException e)
-               {
-                       rider.res[0] = 4;
-                       rider.eof[0] = true;
-               }
+               int[] i = new int[1];
+               ReadLInt(R, R$, i, 0);
+               x[x$] = Float.intBitsToFloat(i[0]);
        }
 
        public static void ReadLReal(RECORD1 R[], int R$, double x[], int x$)
        {
-               RECORD1 rider = R[R$];
-               RandomAccessFile desc = rider.base.desc;
-
-               try
-               {
-                       rider.base.SetActive(rider);
-                       x[x$] = desc.readDouble();
-                       rider.position += 8;
-               }
-               catch(IOException e)
-               {
-                       rider.res[0] = 8;
-                       rider.eof[0] = true;
-               }
+               long[] i = new long[1];
+               ReadHInt(R, R$, i, 0);
+               x[x$] = Double.longBitsToDouble(i[0]);
        }
 
        public static void ReadNum(RECORD1 R[], int R$, int x[], int x$)
@@ -319,21 +287,9 @@ class Files
 
        public static void ReadBool(RECORD1 R[], int R$, boolean x[], int x$)
        {
-               RECORD1 rider = R[R$];
-               RandomAccessFile desc = rider.base.desc;
-
-               try
-               {
-                       rider.base.SetActive(rider);
-                       int i = desc.read();
-                       x[x$] = (i != 0);
-                       rider.position += 1;
-               }
-               catch(IOException e)
-               {
-                       rider.res[0] = 1;
-                       rider.eof[0] = true;
-               }               
+               byte[] i = new byte[1];
+               Read(R, R$, i, 0);
+               x[x$] = (i[0] != 0);
        }
 
        public static void ReadBytes(RECORD1 r[], int r$, byte x[][], int x$, int n)
@@ -344,9 +300,10 @@ class Files
                try
                {
                        rider.base.SetActive(rider);
-                       rider.res[0] = desc.read(x[x$], 0, n);
+                       int readed = desc.read(x[x$], 0, n);
+                       rider.res[0] = (readed >= 0) ? (n - readed) : (0);
                        rider.eof[0] = (rider.res[0] != 0);
-                       rider.position += n - rider.res[0];
+                       rider.position += (readed >= 0) ? (readed) : (0);
                }
                catch(IOException e)
                {
@@ -377,18 +334,18 @@ class Files
        public static void WriteInt(RECORD1 R[], int R$, short x)
        {
                byte[][] i = new byte[1][2];
-               i[0][0] = (byte) ((x >>> 8) & 0xff);
-               i[0][1] = (byte) ((x) & 0xff);
+               i[0][1] = (byte) ((x >>> 8) & 0xff);
+               i[0][0] = (byte) ((x) & 0xff);
                WriteBytes(R, R$, i, 0, 2);
        }
 
        public static void WriteLInt(RECORD1 R[], int R$, int x)
        {
                byte[][] i = new byte[1][4];
-               i[0][0] = (byte) ((x >>> 24) & 0xff);
-               i[0][1] = (byte) ((x >>> 16) & 0xff);
-               i[0][2] = (byte) ((x >>> 8) & 0xff);
-               i[0][3] = (byte) ((x) & 0xff);
+               i[0][3] = (byte) ((x >>> 24) & 0xff);
+               i[0][2] = (byte) ((x >>> 16) & 0xff);
+               i[0][1] = (byte) ((x >>> 8) & 0xff);
+               i[0][0] = (byte) ((x) & 0xff);
                WriteBytes(R, R$, i, 0, 4);
        }
 
@@ -411,7 +368,7 @@ class Files
        {
                byte[][] i = new byte[1][];
                i[0] = x;
-               WriteBytes(R, R$, i, 0, SYSTEM.LEN(x));
+               WriteBytes(R, R$, i, 0, SYSTEM.LEN(x) + 1);
        }
 
        public static void WriteSet(RECORD1 R[], int R$, int x)