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:
parent
d5d45d1088
commit
18e3ddf605
8 changed files with 56 additions and 8 deletions
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -19,3 +19,4 @@ tty
|
|||
ft
|
||||
ft2
|
||||
strsignal
|
||||
fgrep
|
||||
|
|
|
@ -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
20
Userland/fgrep.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue