1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

fgrep: Port fgrep to LibMain

This commit is contained in:
Kenneth Myhra 2021-12-21 20:22:53 +01:00 committed by Andreas Kling
parent 8aafe6cd1f
commit 22c27e1ba9
2 changed files with 11 additions and 9 deletions

View file

@ -91,6 +91,7 @@ target_link_libraries(env LibMain)
target_link_libraries(errno LibMain)
target_link_libraries(expr LibRegex LibMain)
target_link_libraries(fdtdump LibDeviceTree LibMain)
target_link_libraries(fgrep LibMain)
target_link_libraries(file LibGfx LibIPC LibCompress LibMain)
target_link_libraries(find LibMain)
target_link_libraries(flock LibMain)

View file

@ -4,25 +4,26 @@
* 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>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
if (argc < 2) {
if (arguments.strings.size() < 2) {
warnln("usage: fgrep <str>");
return 1;
}
for (;;) {
char buf[4096];
auto* str = fgets(buf, sizeof(buf), stdin);
if (str && strstr(str, argv[1]))
write(1, buf, strlen(buf));
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);
VERIFY(str.to_string().characters());
}
}