2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2021-05-19 16:35:55 -03:00
|
|
|
#include <AK/Assertions.h>
|
2021-05-31 11:43:25 -03:00
|
|
|
#include <AK/Format.h>
|
2018-11-11 17:42:41 -02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
if (argc < 2) {
|
2021-05-31 11:43:25 -03:00
|
|
|
warnln("usage: fgrep <str>");
|
2021-06-01 15:27:59 -03:00
|
|
|
return 1;
|
2018-11-11 17:42:41 -02:00
|
|
|
}
|
|
|
|
|
for (;;) {
|
|
|
|
|
char buf[4096];
|
2019-04-25 09:07:17 -03:00
|
|
|
auto* str = fgets(buf, sizeof(buf), stdin);
|
|
|
|
|
if (str && strstr(str, argv[1]))
|
2018-11-11 17:42:41 -02:00
|
|
|
write(1, buf, strlen(buf));
|
2018-11-11 22:28:46 -02:00
|
|
|
if (feof(stdin))
|
|
|
|
|
return 0;
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(str);
|
2018-11-11 17:42:41 -02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|