本文介绍了在Linux环境下使用C语言实现grep命令的过程和技术细节,包括正则表达式的匹配和文本搜索算法。
#if HAVE_NBTOOL_CONFIG_H
#include nbtool_config.h
#endif
#include
__RCSID($NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $);
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef WITHOUT_NLS
#else
nl_catd catalog;
#endif
/* Default messages to use when NLS is disabled or no catalogue is found. */
const char *errstr[] = {
, /* 1 */
(standard input), /* 2 */
cannot read bzip2 compressed file, /* 3 */
unknown %s option, /* 4 */
usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZz] [-A num] [-B num] [-C[num]]\n,
\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n,
\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n,
\t[pattern] [file ...]\n, /* 7 */
Binary file %s matches\n, /* 8 */
%s (BSD grep) %s\n /* 9 */
};