2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2021-12-21 22:22:53 +03:00
|
|
|
#include "AK/String.h"
|
2021-05-19 22:35:55 +03:00
|
|
|
#include <AK/Assertions.h>
|
2021-05-31 17:43:25 +03:00
|
|
|
#include <AK/Format.h>
|
2021-12-21 22:22:53 +03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
#include <LibMain/Main.h>
|
2018-11-11 22:42:41 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-12-21 22:22:53 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2018-11-11 22:42:41 +03:00
|
|
|
{
|
2021-12-21 22:22:53 +03:00
|
|
|
if (arguments.strings.size() < 2) {
|
2021-05-31 17:43:25 +03:00
|
|
|
warnln("usage: fgrep <str>");
|
2021-06-01 21:27:59 +03:00
|
|
|
return 1;
|
2018-11-11 22:42:41 +03:00
|
|
|
}
|
|
|
|
for (;;) {
|
2021-12-21 22:22:53 +03:00
|
|
|
char buffer[4096];
|
|
|
|
auto str = StringView(fgets(buffer, sizeof(buffer), stdin));
|
|
|
|
if (str.contains(arguments.strings[1]))
|
|
|
|
TRY(Core::System::write(1, str.bytes()));
|
2018-11-12 03:28:46 +03:00
|
|
|
if (feof(stdin))
|
|
|
|
return 0;
|
2021-12-21 22:22:53 +03:00
|
|
|
VERIFY(str.to_string().characters());
|
2018-11-11 22:42:41 +03:00
|
|
|
}
|
|
|
|
}
|