// fil InnBUtB.java
import inf101.*;

/**
* Utvider klassen Inn med metode for ? lese
* en kode p? opptil 21000 verdier p? fil i en eller to byter,
* og en metode for ? lese neste ord p? fila.
************************************************************/
class InnB extends Inn {

    /** Avoids cotrol characters. : 10, 13, 128-160
    @param i a byte value read from file with inChar()
    @return 'code' as used when calling corresponding utKonv(int code) **/
	int inKonv (int i) {
			int ret = i;
			if (i >= 10 ) ret -= 4;
			if (i >= 128 ) ret -= 32;
			return ret;
	}

	InnB (String s) { super(s);}
	InnB (){super();}

    /**
	*  Reads next code from file. : lower 100 values (2 digits in code)  in byte 1.
    *  if value of code on file  >= 100  then byte 1 > 100 and byte 2 = upper 3 digits (up to 210 values).
	*  @return  max value = 210*100 (can easily be extended to 3,4.. byte encoding)
    *************************************************************************/
	public int innKode( ) {
		    int c,k;
			c = inKonv((int) inChar());

			if (c >= 100) {
				k = c - 100;
				c = inKonv((int) inChar());
				return c*100 +k;
			} else {
				return c;
			}
	} // end innKode


	/** Reads next word from file. Skips whitespace as determined
	*   by parameter to inString()**/
	public String lesNesteOrd () {
			return inString(" "); // Pr?v her andre avgrnsninger i tillegg som :.,\n-
	}

} // end class InnB


/**
* Utvider klassen Ut med metode for ? skrive
* en kode p? opptil 21000 verdier p? fil i en eller to byter.
************************************************************/
class UtB extends Ut {

   /** Avoids cotrol characters. : 10, 13, 128-160
       @return 'code' to be output on file, read by corresponding innKonv(int code) **/
	int utKonv(int i) {
				int ret = i;
				if (i >= 10 ) ret += 4;
			    if (i >= 124 ) ret += 32;
			    return ret;
			}

	UtB (String s) { super(s);}
	UtB (){super();}

    /**
	*  Writes code 'k' to file: lower 100 values (2 digits in code)  in byte 1.
    *  if value of code >= 100  then byte 1 >=100 and byte 2 = upper 3 digits (up to 210 values).
	*  Max code value = 210*100 (can easily be extended to 3,4.. byte encoding)
    *************************************************************************/
	public void utKode(int k) {
        int c1,c2;

		if (k >= 100) {
			c1 = utKonv( (k %100) + 100 );
			outChar( (char) c1);
			c2 = utKonv(k/100);
			outChar( (char) c2 );

		} else {
			c1 =  utKonv(k);
			outChar((char)c1);
        }
	} // end outKode


} // end class UtB