1 package com.tapina.robe.swi.clib.stdio;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.swi.clib.Stub;
5
6 import java.io.IOException;
7
8 /***
9 * This function reads a string of characters from the stream in a3 into the character array pointed to by a1.
10 * A maximum of (a2-1) characters will be read and in any case reading will terminate at a newline character or
11 * end-of-file.
12 * If there is an error, a null pointer will be returned but the array contents may still have changed.
13 * Returns: Pointer to string read, or a null pointer if there is an error.
14 */
15 public class FGetS extends Stub {
16 public void executeStub(Environment environment) {
17 final int[] R = environment.getCpu().R;
18 FilePointer filePointer = FilePointer.find(environment.getMemoryMap().getWord(R[2]));
19 try {
20 final String string = filePointer.gets(R[1] - 1);
21 environment.getMemoryMap().storeString0(R[0], string);
22 } catch (IOException e) {
23 log.warning("Error during fgets(): " + e.getMessage());
24 R[0] = 0;
25 }
26 }
27 }