blob: 76d55756d5e70bfe37013099f5a84767d0211488 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "AK/String.h"
#include <AK/Assertions.h>
#include <AK/Format.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <stdio.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (arguments.strings.size() < 2) {
warnln("usage: fgrep <str>");
return 1;
}
for (;;) {
char buffer[4096];
auto str = StringView(fgets(buffer, sizeof(buffer), stdin));
if (str.contains(arguments.strings[1]))
TRY(Core::System::write(1, str.bytes()));
if (feof(stdin))
return 0;
VERIFY(str.to_string().characters());
}
}
|