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-12-21 16:22:53 -03:00
|
|
|
#include "AK/String.h"
|
2021-05-19 16:35:55 -03:00
|
|
|
#include <AK/Assertions.h>
|
2021-05-31 11:43:25 -03:00
|
|
|
#include <AK/Format.h>
|
2021-12-21 16:22:53 -03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibMain/Main.h>
|
2018-11-11 17:42:41 -02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2021-12-21 16:22:53 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2018-11-11 17:42:41 -02:00
|
|
|
{
|
2021-12-21 16:22:53 -03:00
|
|
|
if (arguments.strings.size() < 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 (;;) {
|
2021-12-21 16:22:53 -03:00
|
|
|
char buffer[4096];
|
2022-07-11 16:53:29 -03:00
|
|
|
fgets(buffer, sizeof(buffer), stdin);
|
|
|
|
|
auto str = StringView { buffer, strlen(buffer) };
|
2021-12-21 16:22:53 -03:00
|
|
|
if (str.contains(arguments.strings[1]))
|
|
|
|
|
TRY(Core::System::write(1, str.bytes()));
|
2018-11-11 22:28:46 -02:00
|
|
|
if (feof(stdin))
|
|
|
|
|
return 0;
|
2021-12-21 16:22:53 -03:00
|
|
|
VERIFY(str.to_string().characters());
|
2018-11-11 17:42:41 -02:00
|
|
|
}
|
|
|
|
|
}
|