View Javadoc

1   package com.tapina.robe.swi.clib.string;
2   
3   import com.tapina.robe.runtime.ByteArray;
4   import com.tapina.robe.runtime.Environment;
5   import com.tapina.robe.runtime.MemoryMap;
6   import com.tapina.robe.swi.clib.Stub;
7   
8   /***
9    * This function searches for a2 (converted to an unsigned char) in the first a3 characters of the object pointed to by a1.
10   * Returns: Pointer to the found character, or a null pointer if not found.
11   */
12  public class MemChr extends Stub {
13      public void executeStub(Environment environment) {
14          final int[] R = environment.getCpu().R;
15          final MemoryMap memoryMap = environment.getMemoryMap();
16          final ByteArray ptr = memoryMap.getByteArray(R[0], R[2], false);
17          for (int i = 0; i < R[2]; i++) {
18              if (ptr.getByte(i) == R[1]) {
19                  R[0] += i;
20                  return;
21              }
22          }
23          R[0] = 0;
24      }
25  }