Support for reading/writing files via FileInputStream and FileOutputStream.java classes.
authorbdemsky <bdemsky>
Tue, 24 Oct 2006 20:15:35 +0000 (20:15 +0000)
committerbdemsky <bdemsky>
Tue, 24 Oct 2006 20:15:35 +0000 (20:15 +0000)
Robust/src/ClassLibrary/FileInputStream.java [new file with mode: 0644]
Robust/src/ClassLibrary/FileOutputStream.java [new file with mode: 0644]
Robust/src/ClassLibrary/String.java
Robust/src/Main/Main.java
Robust/src/Runtime/file.c [new file with mode: 0644]
Robust/src/Tests/ReadFile.java [new file with mode: 0644]
Robust/src/buildscript
Robust/src/buildscriptrepair
Robust/src/buildscripttask

diff --git a/Robust/src/ClassLibrary/FileInputStream.java b/Robust/src/ClassLibrary/FileInputStream.java
new file mode 100644 (file)
index 0000000..0a17f99
--- /dev/null
@@ -0,0 +1,27 @@
+public class FileInputStream {
+    private int fd;
+
+    public FileInputStream(String pathname) {
+       fd=nativeOpen(pathname.getBytes());
+    }
+
+    private static native int nativeOpen(byte[] filename);
+    private static native int nativeRead(int fd, byte[] array, int numBytes);
+    private static native void nativeClose(int fd);
+    
+    public int read() {
+       byte b[]=new byte[1];
+       int retval=read(b);
+       if (retval==-1)
+           return -1;
+       return b[0];
+    }
+
+    public int read(byte[] b) {
+       return nativeRead(fd, b, b.length);
+    }
+
+    public void close() {
+       nativeClose(fd);
+    }
+}
diff --git a/Robust/src/ClassLibrary/FileOutputStream.java b/Robust/src/ClassLibrary/FileOutputStream.java
new file mode 100644 (file)
index 0000000..eea7eef
--- /dev/null
@@ -0,0 +1,25 @@
+public class FileOutputStream {
+    private int fd;
+
+    public FileOutputStream(String pathname) {
+       fd=nativeOpen(pathname.getBytes());
+    }
+
+    private static native int nativeOpen(byte[] filename);
+    private static native void nativeWrite(int fd, byte[] array);
+    private static native void nativeClose(int fd);
+    
+    public void write(int ch) {
+       byte b[]=new byte[1];
+       b[0]=(byte)ch;
+       write(b);
+    }
+
+    public void write(byte[] b) {
+       nativeWrite(fd, b);
+    }
+
+    public void close() {
+       nativeClose(fd);
+    }
+}
index 722f61f8e3f805cdef50ca68cced88c2fdf31275..ad1530b7c73bbf59eb6974bd146105e33737150f 100644 (file)
@@ -1,14 +1,17 @@
 public class String {
     char string[];
 
-    public String(char string[]) {
-       this.string=string;
+    public String(char str[]) {
+       char charstr[]=new char[str.length];
+       for(int i=0;i<str.length;i++)
+           charstr[i]=charstr[i];
+       this.string=charstr;
     }
 
     public String(byte str[]) {
        char charstr[]=new char[str.length];
        for(int i=0;i<str.length;i++)
-           charstr[i]=(char)charstr[i];
+           charstr[i]=(char)str[i];
        this.string=charstr;
     }
 
index 8dbe05dce9449d1895871af6273edd32e64bdc28..7aa8cbef2fda3da16531365fb1d6c18e2bc73362 100644 (file)
@@ -51,6 +51,8 @@ public class Main {
       readSourceFile(state, ClassLibraryPrefix+"Object.java");
       readSourceFile(state, ClassLibraryPrefix+"System.java");
       readSourceFile(state, ClassLibraryPrefix+"String.java");
+      readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java");
+      readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
       if (state.TASK) {
          readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
          readSourceFile(state, ClassLibraryPrefix+"Socket.java");
diff --git a/Robust/src/Runtime/file.c b/Robust/src/Runtime/file.c
new file mode 100644 (file)
index 0000000..a295465
--- /dev/null
@@ -0,0 +1,48 @@
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include "structdefs.h"
+#include "mem.h"
+
+
+void ___FileOutputStream______nativeWrite____I__AR_B(int fd, struct ArrayObject * ao) {
+  int length=ao->___length___;
+  char * string= (((char *)& ao->___length___)+sizeof(int));
+  int status=write(fd, string, length);
+}
+
+void ___FileOutputStream______nativeClose____I(int fd) {
+  close(fd);
+}
+
+int ___FileOutputStream______nativeOpen_____AR_B(struct ArrayObject * ao) {
+  int length=ao->___length___;
+  char* filename= (((char *)& ao->___length___)+sizeof(int));
+  int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
+  return fd;
+}
+
+int ___FileInputStream______nativeOpen_____AR_B(struct ArrayObject * ao) {
+  int length=ao->___length___;
+  char* filename= (((char *)& ao->___length___)+sizeof(int));
+  int fd=open(filename, O_RDONLY, 0);
+  return fd;
+}
+
+void ___FileInputStream______nativeClose____I(int fd) {
+  close(fd);
+}
+
+int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject * ao, int numBytes) {
+  int toread=ao->___length___;
+  char* string= (((char *)& ao->___length___)+sizeof(int));
+  int status;
+
+  if (numBytes<toread)
+    toread=numBytes;
+
+  status=read(fd, string, toread);
+  return status;
+}
diff --git a/Robust/src/Tests/ReadFile.java b/Robust/src/Tests/ReadFile.java
new file mode 100644 (file)
index 0000000..ff282ec
--- /dev/null
@@ -0,0 +1,12 @@
+public class ReadFile {
+    public static void main(String []str) {
+       String filename="testfile000";
+       FileInputStream fis=new FileInputStream(filename);
+       byte x[]=new byte[9];
+       fis.read(x);
+       fis.close();
+       String st=new String(x);
+       System.printString(st);
+    }
+
+}
index b7a0c04acb311e6f946ac033585c7251e016abe9..0ba7f5717851529df11fbfd35e629b793f26eaab 100755 (executable)
@@ -4,4 +4,4 @@ MAINFILE=$1
 shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -mainclass $MAINFILE $@
-gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c -o $MAINFILE.bin
\ No newline at end of file
+gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c  $ROBUSTROOT/Runtime/file.c -o $MAINFILE.bin
\ No newline at end of file
index 1f495db7088d180b113d245fab6abbb04570b911..7501938333723e9d84b244f3b9111d6deffed823 100755 (executable)
@@ -62,6 +62,7 @@ gcc -I$ROBUSTROOT/Runtime -I. -I$BUILDDIR/specdir \
 -IRuntime/include -I$BUILDDIR -O0 -DBOEHM_GC -DCONSCHECK \
 -LRuntime/lib/ -lgc -DTASK -g tmpbuilddirectory/methods.c \
 tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c \
+$ROBUSTROOT/Runtime/file.c \
 $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
 $ROBUSTROOT/Runtime/checkpoint.c \
 $ROBUSTROOT/Runtime/GenericHashtable.c $BUILDDIR/specdir/*.o -o \
index e485dd832945e448bfd8be2c2dd72b065104da1b..5b67f8f03e1ffc2f95810855f7f383ffd58a88c6 100755 (executable)
@@ -5,4 +5,4 @@ shift
 mkdir tmpbuilddirectory
 java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task $@
 #gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
-gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file
+gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file