View Javadoc

1   package com.tapina.robe.swi.clib.stdlib;
2   
3   import com.tapina.robe.runtime.ByteArrayUtils;
4   import com.tapina.robe.runtime.Environment;
5   import com.tapina.robe.runtime.MemoryMap;
6   import com.tapina.robe.runtime.RawDataBlock;
7   import com.tapina.robe.swi.OS;
8   import com.tapina.robe.swi.clib.Stub;
9   
10  /***
11   * This reads the contents of an environment variable, whose name is given. In DOS it reads the DOS environment
12   * variables eg PATH, whereas in RISC OS it reads the system variable eg Obey$Dir. When reading the variables it
13   * converts numbers to strings and expands macros.
14   * You should not modify the returned string and it may be overwritten by subsequent calls to getenv.
15   * This function is equivalent to the SWI OS_ReadVarVal , with R4=3.
16   * Returns: A pointer to the variable contents.
17   */
18  public class GetEnv extends Stub {
19      RawDataBlock block = null;
20  
21      public void executeStub(Environment environment) {
22          final MemoryMap memoryMap = environment.getMemoryMap();
23          final int[] R = environment.getCpu().R;
24          final String value = OS.getInstance().readVarVal(memoryMap.getString0(R[0]));
25          if (this.block != null) {
26              memoryMap.removeSystemDataBlock(block);
27          }
28          this.block = memoryMap.createSystemDataBlock(value);
29          R[0] = block.getAddress();
30      }
31  }