summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2023-04-14 11:00:26 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2023-04-14 11:00:26 +0200
commit6638fe908eedd0d3fd7531a9af2ed10dd18ed5c1 (patch)
tree639e1ff84f31a1359f2f8e7c6030dc56d342023c
parent9d3b555393735e08c27b04a8b616f2736afe26de (diff)
downloadabase-6638fe908eedd0d3fd7531a9af2ed10dd18ed5c1.tar.gz
abase-6638fe908eedd0d3fd7531a9af2ed10dd18ed5c1.tar.bz2
implemented simplest possible version of "more"
-rw-r--r--Makefile3
-rw-r--r--README5
-rw-r--r--more.19
-rw-r--r--more.c77
-rw-r--r--util.h2
5 files changed, 90 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 0a0fdc2..404ffd4 100644
--- a/Makefile
+++ b/Makefile
@@ -40,11 +40,9 @@ $(LIBUTIL): $(LIBUTILOBJ)
install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
- mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
for m in $(MAN); do sed "s/^\.Os abase/.Os abase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
- mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
uninstall:
cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN)
@@ -84,7 +82,6 @@ abase-box-install: abase-box
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
for m in $(MAN); do sed "s/^\.Os abase/.Os abase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
- mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
abase-box-uninstall: uninstall
cd $(DESTDIR)$(PREFIX)/bin && rm -f abase-box
diff --git a/README b/README
index f222ea1..1bba99e 100644
--- a/README
+++ b/README
@@ -4,7 +4,10 @@ abase - Aba's tools
abase is a collection of tools that didn't fit into ubase or sbase.
Currently it contains the following:
-- a very simple more
+- a very simple 'more' pager
+- a simple 'hexdump'
+- a 'fdisk' (but we have to decide for which kind of partition types
+ and what kind of operations, could be too big)
Note: abase is a shameless copy of sbase/ubase in certain areas like
the Makefile, libutil, etc. This might also make an integration into
diff --git a/more.1 b/more.1
index b48f2f8..f2c3450 100644
--- a/more.1
+++ b/more.1
@@ -11,3 +11,12 @@
pages text file
.Ar path
to stdout, provides navigation key shortcuts.
+.Nm
+.Sh COMMANDS
+.sp
+.RE
+\fBRETURN\fP
+.RS 4
+Display next page of text.
+.RE
+
diff --git a/more.c b/more.c
index 11a3c2d..7dbe5f6 100644
--- a/more.c
+++ b/more.c
@@ -1,7 +1,15 @@
/* See LICENSE file for copyright and license details. */
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
#include "util.h"
+#define COLUMNS 80
+#define ROWS 25
+#define BUFSIZE 10
+
static void
usage(void)
{
@@ -11,12 +19,77 @@ usage(void)
int
main(int argc, char *argv[])
{
- int ret = 0;
+ int fd;
+ char c;
+ int col;
+ int row;
+ int buf[BUFSIZE];
ARGBEGIN {
default:
usage();
} ARGEND
+
+ if (argc < 1 && isatty(STDIN_FILENO))
+ usage();
+
+ if (isatty(STDIN_FILENO)) {
+ if ((fd = open(*argv, O_RDONLY)) < 0) {
+ weprintf("open %s:", *argv);
+ return 0;
+
+ }
+ } else {
+ fd = STDIN_FILENO;
+ }
+
+ col = 0;
+ row = 0;
+ while (read(fd, &c, 1) != 0) {
+ switch (c) {
+ case '\r':
+ col = 0;
+ break;
+
+ case '\n':
+ col = 0;
+ row++;
+ break;
+
+ case '\t':
+ col = ((col+1) | 0x07)+1;
+ break;
+
+ case '\b':
+ if (col>0) {
+ col--;
+ }
+ break;
+
+ default:
+ col++;
+ break;
+ }
+ putchar(c);
+
+ if (row<ROWS) {
+ continue;
+ }
+
+ puts("--more--");
+
+ if (read(STDIN_FILENO, &buf, BUFSIZE) < 0) {
+ goto END;
+ }
- return ret;
+ col = 0;
+ row = 0;
+ }
+
+END:
+ if (fd > STDERR_FILENO) {
+ close(fd);
+ }
+
+ return 0;
}
diff --git a/util.h b/util.h
index e582e73..5d68952 100644
--- a/util.h
+++ b/util.h
@@ -2,4 +2,6 @@
#include "arg.h"
+void enprintf(int, const char *, ...);
void eprintf(const char *, ...);
+void weprintf(const char *, ...);