1 package com.tapina.robe.swi.clib.stdio; 2 3 import com.tapina.robe.runtime.Environment; 4 import com.tapina.robe.swi.clib.CLibrary; 5 import com.tapina.robe.swi.clib.Stub; 6 7 import java.io.EOFException; 8 import java.io.IOException; 9 10 /*** 11 * This function reads a single character from the stream pointed to by stream and returns it as an int. 12 * It is virtually identical to fgetc . The only difference is that the function might be a macro and the argument 13 * may be evaluated more than once so you can't use an expression with side effects. For example: getc(f[i++]) 14 * may cause i to be incremented twice. 15 * Returns: Character read, or EOF for an error. 16 */ 17 public class GetC extends Stub { 18 public void executeStub(Environment environment) { 19 final int[] R = environment.getCpu().R; 20 FilePointer filePointer = FilePointer.find(environment.getMemoryMap().getWord(R[0])); 21 try { 22 R[0] = filePointer.getc(); 23 } catch (EOFException e) { 24 log.info("EOF during getc()"); 25 R[0] = CLibrary.EOF; 26 } catch (IOException e) { 27 log.warning("Error during getc(): " + e.getMessage()); 28 R[0] = CLibrary.EOF; 29 } 30 } 31 }