
#include "V.h"
/*
* Given a separator (usually '/'), return a pointer to the last field.  When
* there  are no instances of the separator, we return a pointer to the first
* char of the str, which will make filename scans work as you  expect.   You
* might  expect  that  the  most  efficient  way to do this would be to scan
* backwards from the end of the string, but with null-terminated strings, we
* must first scan from the start to locate the end, so we might as well just
* look for the sep and produce the result as a side-effect of this scan.
*
* A common mistake is to omit the first arg.  We can catch this, but there's
* also the problem of getting a bogus str pointer. This is where it would be
* really helpful if there were some way that we could  test  a  pointer  for
* validity.  Unfortunately, this is totally impossible on most current cpus.
* All we can do is hope that the caller sends us a valid  pointer,  and  die
* ignominiously if str is garbage.
*/
char* lastfld(sep,str)
	char  sep;
	char *str;
{	char  c, *p;
	if (B8(sep) != sep) {	/* Kludge to try to spot pointer as 1st arg */
		V2 "### lastfld called with sep=%08X.",sep D;
		return((char*)((long)sep));
	}
	for (p = str; (c = *str); ++str)
		if (c == sep)
			p = str + 1;
	return(p);
}
