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
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 * ----------------------------------------------- */
23 Lindex( const PLstr haystack
, const PLstr needle
, long p
)
27 p
--; /* for C string offset = 0, Rexx=1 */
34 if (!LLEN(*haystack
)) return LNOTFOUND
;
37 if (LLEN(*needle
) > LLEN(*haystack
)) return LNOTFOUND
;
41 if (p
>= LLEN(*haystack
)) return LNOTFOUND
;
42 while (LSTR(*haystack
)[p
] != LSTR(*needle
)[0]) {
44 if (p
>= LLEN(*haystack
)) return LNOTFOUND
;
47 while ( (LSTR(*haystack
)[p
]==LSTR(*needle
)[n
]) && (n
<LLEN(*needle
))) {
48 if ((++n
) >= LLEN(*needle
)) return lp
+1;
50 if (p
>= LLEN(*haystack
)) return LNOTFOUND
;
52 } while (n
<LLEN(*needle
));