partially rewrite grep.c