private static native int nativeOpen(byte[] filename);
private static native int nativeRead(int fd, byte[] array, int numBytes);
+ private static native int nativePeek(int fd);
private static native void nativeClose(int fd);
public int read() {
byte b[]=new byte[1];
int retval=read(b);
- if (retval==-1)
+ if (retval==-1 || retval==0)
return -1;
+
+ // if carriage return comes back, dump it
+ if( b[0] == 13 ) {
+ return read();
+ }
+
+ // otherwise return result
return b[0];
}
+ public int peek() {
+ return nativePeek(fd);
+ }
+
public int read(byte[] b) {
return nativeRead(fd, b, b.length);
}
return null;
}
- while( c != '\n' && c > 0 ) {
+ // ASCII 13 is carriage return, check for that also
+ while( c != '\n' && c != 13 && c > 0 ) {
line += (char)c;
c = read();
- }
+ }
+
+ // peek and consume characters that are carriage
+ // returns or line feeds so the whole line is read
+ // and returned, and none of the line-ending chars
+ c = peek();
+ while( c == '\n' || c == 13 ) {
+ c = read();
+ c = peek();
+ }
return line;
}
return status;
}
+int CALL11(___FileInputStream______nativePeek____I, int fd, int fd) {
+ int status;
+ char string[1];
+ status=read(fd, string, 1);
+
+ if( status <= 0 ) {
+ return status;
+ }
+ lseek(fd, -1, SEEK_CUR);
+ return string[0];
+}
+
long long CALL01(___File______nativeLength_____AR_B, struct ArrayObject * ___pathname___) {
int length=VAR(___pathname___)->___length___;
char* filename= (((char *)&VAR(___pathname___)->___length___)+sizeof(int));
line = in.readLine();
}
System.out.println( "#####################" );
+ System.out.println( "["+in.read()+"]" );
+ System.out.println( "["+in.read()+"]" );
+ in.close();
+
+
+ in = new FileInputStream( "charmap.txt" );
+ System.out.println( "\n\n\n#####################" );
+ line = in.readLine();
+ while( line != null ) {
+ System.out.println( line );
+ for( int i = 0; i < line.length(); ++i ) {
+ System.out.print( line.charAt( i )+"." );
+ }
+ System.out.println( "" );
+ line = in.readLine();
+ }
+ System.out.println( "#####################" );
+ System.out.println( "["+in.read()+"]" );
+ System.out.println( "["+in.read()+"]" );
+ in.close();
+
+
+ in = new FileInputStream( "test.txt" );
+ System.out.println( "\n\n\n#####################" );
+ int c = in.read();
+ while( c != -1 ) {
+ System.out.print( c+"." );
+ c = in.read();
+ }
+ System.out.println( "#####################" );
+ System.out.println( "["+in.read()+"]" );
+ System.out.println( "["+in.read()+"]" );
in.close();
}
}
\ No newline at end of file
--- /dev/null
+# basic characters\r
+<char:linebreak><index:22>\r
+\r
+# dots\r
+<char:cdot><index:22>\r
+\r
+# quotes\r
+<char:quote><index:22>\r
+<char:quoteleft><index:22>\r
+<char:quoteright><index:22>\r
+<char:quotedblleft><index:22>\r
+<char:quotedblright><index:22>\r