mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
Add a simple /bin/more.
This commit is contained in:
parent
4dd50b1f6d
commit
36bd53b36a
4 changed files with 56 additions and 2 deletions
|
@ -29,6 +29,7 @@ cp -v ../Userland/tty mnt/bin/tty
|
||||||
cp -v ../Userland/mkdir mnt/bin/mkdir
|
cp -v ../Userland/mkdir mnt/bin/mkdir
|
||||||
cp -v ../Userland/touch mnt/bin/touch
|
cp -v ../Userland/touch mnt/bin/touch
|
||||||
cp -v ../Userland/sync mnt/bin/sync
|
cp -v ../Userland/sync mnt/bin/sync
|
||||||
|
cp -v ../Userland/more mnt/bin/more
|
||||||
sh sync-local.sh
|
sh sync-local.sh
|
||||||
cp -v kernel.map mnt/
|
cp -v kernel.map mnt/
|
||||||
ln -s dir_a mnt/dir_cur
|
ln -s dir_a mnt/dir_cur
|
||||||
|
|
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -20,3 +20,4 @@ fgrep
|
||||||
mkdir
|
mkdir
|
||||||
touch
|
touch
|
||||||
sync
|
sync
|
||||||
|
more
|
||||||
|
|
|
@ -17,7 +17,8 @@ OBJS = \
|
||||||
fgrep.o \
|
fgrep.o \
|
||||||
tty.o \
|
tty.o \
|
||||||
mkdir.o \
|
mkdir.o \
|
||||||
touch.o
|
touch.o \
|
||||||
|
more.o
|
||||||
|
|
||||||
APPS = \
|
APPS = \
|
||||||
id \
|
id \
|
||||||
|
@ -39,7 +40,8 @@ APPS = \
|
||||||
tty \
|
tty \
|
||||||
mkdir \
|
mkdir \
|
||||||
touch \
|
touch \
|
||||||
sync
|
sync \
|
||||||
|
more
|
||||||
|
|
||||||
ARCH_FLAGS =
|
ARCH_FLAGS =
|
||||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
|
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc
|
||||||
|
@ -119,6 +121,9 @@ touch: touch.o
|
||||||
sync: sync.o
|
sync: sync.o
|
||||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
|
more: more.o
|
||||||
|
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
|
47
Userland/more.cpp
Normal file
47
Userland/more.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
static int key_fd;
|
||||||
|
|
||||||
|
void wait_for_key()
|
||||||
|
{
|
||||||
|
printf("\033[7m--[ more ]--\033[0m");
|
||||||
|
fflush(stdout);
|
||||||
|
char dummy;
|
||||||
|
read(key_fd, &dummy, 1);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
|
||||||
|
key_fd = open(ttyname(1), O_RDONLY);
|
||||||
|
if (key_fd < 0) {
|
||||||
|
perror("open");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct winsize ws;
|
||||||
|
ioctl(1, TIOCGWINSZ, &ws);
|
||||||
|
|
||||||
|
unsigned lines_printed = 0;
|
||||||
|
while (!feof(stdin)) {
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
auto* str = fgets(buffer, sizeof(buffer), stdin);
|
||||||
|
if (!str)
|
||||||
|
break;
|
||||||
|
printf(str);
|
||||||
|
++lines_printed;
|
||||||
|
if ((lines_printed % (ws.ws_row - 1)) == 0) {
|
||||||
|
wait_for_key();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
close(key_fd);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue