1 package com.tapina.robe.swi.clib.stdio;
2
3 import com.tapina.robe.runtime.Environment;
4 import com.tapina.robe.runtime.MemoryMap;
5 import com.tapina.robe.swi.clib.Stub;
6 import com.tapina.robe.swi.clib.VarArgs;
7
8 /***
9 * This function reads input from the string pointed to by a1 under control of the format string in a2.
10 * In operation it is similar to fscanf , but input is read from a string instead of a stream. The end of the string counts as the end of file.
11 * Returns: The number of successful inputs or EOF if there was an input error.
12 */
13 public class SScanF extends Stub {
14 public void executeStub(Environment environment) {
15 final int[] R = environment.getCpu().R;
16 final MemoryMap memoryMap = environment.getMemoryMap();
17 final String inputString = memoryMap.getString0(R[0]);
18 final String formatString = memoryMap.getString0(R[1]);
19 final VarArgs varArgs = new VarArgs(environment, 2);
20 if (inputString.equals("1M") && formatString.equals("%ld%c")) {
21 memoryMap.storeWord(R[2], 1);
22 memoryMap.storeWord(R[3], 'M');
23 R[0] = 2;
24 return;
25 } else if (inputString.equals("4,8,0") && formatString.equals("%d,%d,%d")) {
26 memoryMap.storeWord(varArgs.getVarArg(0).asInt(), 4);
27 memoryMap.storeWord(varArgs.getVarArg(1).asInt(), 8);
28 memoryMap.storeWord(varArgs.getVarArg(2).asInt(), 0);
29 R[0] = 3;
30 return;
31 }
32 log.severe("sscanf(\"" + inputString + "\", \"" + formatString + "\", ...) not supported");
33 R[0] = 0;
34 }
35 }