12572Sdlw /* 2*17230Sdlw char id_rindex[] = "@(#)rindex_.c 1.3"; 32572Sdlw * 42572Sdlw * find last occurrence of substring in string 52572Sdlw * 62572Sdlw * calling sequence: 72572Sdlw * character*(*) substr, string 82572Sdlw * indx = rindex (string, substr) 92572Sdlw * where: 102572Sdlw * indx will be the index of the first character of the last occurence 112572Sdlw * of substr in string, or zero if not found. 122572Sdlw */ 132572Sdlw 142572Sdlw long rindex_(str, substr, slen, sublen) 152572Sdlw char *str, *substr; long slen, sublen; 162572Sdlw { 17*17230Sdlw register char *p = str + (slen - sublen); 18*17230Sdlw register char *p1, *p2; 19*17230Sdlw register int len; 202572Sdlw 21*17230Sdlw if (sublen == 0) 22*17230Sdlw return(0L); 23*17230Sdlw while (p >= str) { 24*17230Sdlw p1 = p; 25*17230Sdlw p2 = substr; 26*17230Sdlw len = sublen; 27*17230Sdlw while ( *p1++ == *p2++ && --len > 0) ; 28*17230Sdlw if ( len <= 0 ) 292572Sdlw return((long)(++p - str)); 30*17230Sdlw p--; 31*17230Sdlw } 322572Sdlw return(0L); 332572Sdlw } 34