1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +00:00

Add a naive /bin/fgrep for testing pipes.

This commit is contained in:
Andreas Kling 2018-11-11 20:42:41 +01:00
parent d5d45d1088
commit 18e3ddf605
8 changed files with 56 additions and 8 deletions

1
Userland/.gitignore vendored
View file

@ -19,3 +19,4 @@ tty
ft
ft2
strsignal
fgrep

View file

@ -17,6 +17,7 @@ OBJS = \
ft.o \
ft2.o \
strsignal.o \
fgrep.o \
tty.o
APPS = \
@ -38,6 +39,7 @@ APPS = \
ft \
ft2 \
strsignal \
fgrep \
tty
ARCH_FLAGS =
@ -70,6 +72,9 @@ ps: ps.o
ls: ls.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
fgrep: fgrep.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
sleep: sleep.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a

20
Userland/fgrep.cpp Normal file
View file

@ -0,0 +1,20 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (argc < 2) {
printf("usage: fgrep <str>\n");
return 0;
}
for (;;) {
char buf[4096];
fgets(buf, sizeof(buf), stdin);
if (feof(stdin))
return 0;
if (strstr(buf, argv[1]))
write(1, buf, strlen(buf));
}
return 0;
}