#include <stdio.h>
#include <string.h>
char whitespace[] = " \t\r\n\v";
/* Skip white space and check *ps lies in toks */
int peek(char **ps, char *es, char *toks)
{
char *s;
s = *ps;
while(s < es && strchr(whitespace, *s)) // skin white space
s++;
*ps = s; // change ps
return *s && strchr(toks, *s);
}
char* skip_whitespace(char *s)
{
char *es;
es = s + strlen(s);
while(s < es && strchr(whitespace, *s))
s++;
return s;
}
int main()
{
char* s = " < | hello, world.\n";
if(peek(&s, s + strlen(s), "|<>"))
printf("find %c\n", *s);
else
printf("find nothing\n");
}
Reference: http://pdos.csail.mit.edu/6.828/2014/homework/xv6-shell.html