BSD 4_3 release
[unix-history] / usr / src / usr.lib / libF77 / rindex_.c
CommitLineData
6d4cbc1e 1/*
be6e3ddf
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
6d4cbc1e 5 *
95f51977 6 * @(#)rindex_.c 5.2 6/7/85
bb3ec388 7 *
6d4cbc1e
DW
8 * find last occurrence of substring in string
9 *
10 * calling sequence:
11 * character*(*) substr, string
12 * indx = rindex (string, substr)
13 * where:
14 * indx will be the index of the first character of the last occurence
15 * of substr in string, or zero if not found.
16 */
17
18long rindex_(str, substr, slen, sublen)
19char *str, *substr; long slen, sublen;
20{
15499958
DW
21 register char *p = str + (slen - sublen);
22 register char *p1, *p2;
23 register int len;
6d4cbc1e 24
15499958
DW
25 if (sublen == 0)
26 return(0L);
27 while (p >= str) {
28 p1 = p;
29 p2 = substr;
30 len = sublen;
31 while ( *p1++ == *p2++ && --len > 0) ;
32 if ( len <= 0 )
6d4cbc1e 33 return((long)(++p - str));
15499958
DW
34 p--;
35 }
6d4cbc1e
DW
36 return(0L);
37}