--- /dev/null
+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);
+ }
+}
--- /dev/null
+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);
+ }
+}
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;
}
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");
--- /dev/null
+#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;
+}
--- /dev/null
+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);
+ }
+
+}
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
-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 \
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