package niceIO; import java.lang.*; import java.io.* ; public class niceInputStream extends BufferedInputStream { /* allows moving the position-pointer back and re-reading symbols provided they are within the buffer. Does initialization with in.size make sense ? */ private int LinijkaNo=1; private boolean endsLine(int c) { return ((char)c=='\n' || (char)c=='\r' || c==-1); } private boolean endsLine(char c) { return (c=='\n' || c=='\r' || c== ((char)(-1))); } private void ifNewLine(int c) { if (endsLine(c)) LinijkaNo=LinijkaNo+1; } private void ifNewLine(char c) { if (endsLine(c)) LinijkaNo=LinijkaNo+1; } public niceInputStream(InputStream in) { super(in); } public niceInputStream(InputStream in, int size) { super(in,size); } public void unread(int x) { int k,c=0,z,r; if (x>pos) {z= pos; pos= 0;} else {z=x; pos= pos-x;} for (k=0; k< x; k++) try{ r= read(); if (endsLine(r)) c=c+1; } catch(IOException e){} LinijkaNo= LinijkaNo-c; if (x>pos) pos = 0; else pos= pos-x; } public void unread() { unread(1); } public final char tegn() { char c='0'; int ch=0; try{ ch= read(); c= (char)ch; ifNewLine(ch); } catch(IOException e){} return c; } public final char tegnNB() { // read first non-blank char c='0'; int ch=0; try{ ch= read(); c= (char)ch; ifNewLine(ch); while (c==' ') {ch= read(); c=(char)ch; ifNewLine(ch); } } catch(IOException e){} return c; } public final int htall() { int r=0, ch, s=0; try{ ch= read()-48; ifNewLine(ch+48); while (ch<0 || ch>9) {s=ch; ch= read()-48; ifNewLine(ch+48);} r= ch; ch= read()-48; ifNewLine(ch+48); while (ch >= 0 && ch <= 9) {r= (r*10)+ch; ch= read()-48; ifNewLine(ch+48); } } catch(IOException e){} s= s+48; if ((char)s == '-') {r= -r;} return r; } public final boolean bool() { char c= tegn(); if ( c=='n' || c=='N' || c=='0' || c=='-') return false; else return true; } /* read word - non-SPACE characters between SPACEs */ public final String ord() { char c= tegn(); String s= new String(""); while (Character.isSpace(c)) { c= tegn(); } while (!Character.isSpace(c)) {s= s+c; c= tegn();} return s; } /* read word starting with a letter and containing only letters or digits; this one has to re-position the pointer one step back after discovering a non-letterOrDigit terminating the word */ public final String ordBS() { int ch, i; char c; String s= new String(""); c= tegn(); i=1; while (!Character.isLetter(c)) { c= tegn(); i= i+1;} while (Character.isLetterOrDigit(c)) {s=s+c; c= tegn(); i=i+1;} unread(); return s; } public String token() {} public int LineNo() { return LinijkaNo; } }