fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / rexx / lstring / index.c
blobb4483b572328f7993ef06fb7efc5ecb0c4dec27f
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:37 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.1 1998/07/02 17:18:00 bnv
8 * Initial Version
12 #include <lstring.h>
14 /* ----------------- Lindex ---------------------- */
15 /* haystack - Lstr where to search *
16 * needle - Lstr to search *
17 * p - starting position [1,haystack len] *
18 * if p < 1 then p = 1 *
19 * returns 0 (NOTFOUND) is needle is not found *
20 * else returns position [1,haystack len] *
21 * ----------------------------------------------- */
22 long
23 Lindex( const PLstr haystack, const PLstr needle, long p)
25 long n,lp;
27 p--; /* for C string offset = 0, Rexx=1 */
28 if (p<0) p = 0;
30 L2STR(haystack);
31 L2STR(needle);
33 if (!LLEN(*needle)) {
34 if (!LLEN(*haystack)) return LNOTFOUND;
35 return p+1;
37 if (LLEN(*needle) > LLEN(*haystack)) return LNOTFOUND;
38 lp = p-1;
39 do {
40 n = 0; p = lp+1;
41 if (p >= LLEN(*haystack)) return LNOTFOUND;
42 while (LSTR(*haystack)[p] != LSTR(*needle)[0]) {
43 p++;
44 if (p >= LLEN(*haystack)) return LNOTFOUND;
46 lp = p;
47 while ( (LSTR(*haystack)[p]==LSTR(*needle)[n]) && (n<LLEN(*needle))) {
48 if ((++n) >= LLEN(*needle)) return lp+1;
49 p++;
50 if (p >= LLEN(*haystack)) return LNOTFOUND;
52 } while (n<LLEN(*needle));
53 return lp+1;
54 } /* Lindex */