From 9b6c7c877e26610dde3d5a4a21ac27bb571bcadb Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Tue, 20 Feb 2018 18:31:19 +0000 Subject: [PATCH] pg: Add the late V7 "pg" command --- Applications/V7/cmd/Makefile.6502 | 2 +- Applications/V7/cmd/Makefile.68000 | 1 + Applications/V7/cmd/Makefile.6809 | 1 + Applications/V7/cmd/Makefile.z80 | 2 +- Applications/V7/cmd/fuzix-cmd.pkg | 1 + Applications/V7/cmd/pg.c | 165 +++++++++++++++++++++++++++++ 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 Applications/V7/cmd/pg.c diff --git a/Applications/V7/cmd/Makefile.6502 b/Applications/V7/cmd/Makefile.6502 index 90b8067b..576429ea 100644 --- a/Applications/V7/cmd/Makefile.6502 +++ b/Applications/V7/cmd/Makefile.6502 @@ -12,7 +12,7 @@ CRT0NS = ../../../Library/libs/crt0nostdio_6502.o SRCS = ac.c accton.c at.c atrun.c col.c comm.c cron.c crypt.c dc.c dd.c \ deroff.c diff3.c diff.c diffh.c join.c look.c makekey.c mesg.c \ - newgrp.c pr.c ptx.c rev.c split.c su.c sum.c test.c time.c tsort.c \ + newgrp.c pg.c pr.c ptx.c rev.c split.c su.c sum.c test.c time.c tsort.c \ wall.c SRCSNS = ed.c diff --git a/Applications/V7/cmd/Makefile.68000 b/Applications/V7/cmd/Makefile.68000 index 6665e5ae..6501bd0d 100644 --- a/Applications/V7/cmd/Makefile.68000 +++ b/Applications/V7/cmd/Makefile.68000 @@ -18,6 +18,7 @@ SRCS = ac.c col.c dc.c diff.c makekey.c ptx.c sum.c wall.c SRCS += accton.c comm.c dd.c diffh.c mesg.c rev.c test.c SRCS += at.c cron.c deroff.c join.c newgrp.c split.c time.c SRCS += atrun.c crypt.c diff3.c look.c pr.c su.c tsort.c +SRCS += pg.c OBJS = $(SRCS:.c=.o) diff --git a/Applications/V7/cmd/Makefile.6809 b/Applications/V7/cmd/Makefile.6809 index 96e5070e..04e10697 100644 --- a/Applications/V7/cmd/Makefile.6809 +++ b/Applications/V7/cmd/Makefile.6809 @@ -18,6 +18,7 @@ SRCS = ac.c col.c dc.c diff.c makekey.c ptx.c sum.c wall.c SRCS += accton.c comm.c dd.c diffh.c mesg.c rev.c test.c SRCS += at.c cron.c deroff.c join.c newgrp.c split.c time.c SRCS += atrun.c crypt.c diff3.c look.c pr.c su.c tsort.c +SRCS += pg.c OBJS = $(SRCS:.c=.o) diff --git a/Applications/V7/cmd/Makefile.z80 b/Applications/V7/cmd/Makefile.z80 index 55636fda..e19e33e7 100644 --- a/Applications/V7/cmd/Makefile.z80 +++ b/Applications/V7/cmd/Makefile.z80 @@ -12,7 +12,7 @@ PROGLOAD=`(cat ../../../Kernel/platform/config.h; echo PROGLOAD) | cpp -E | tail SRCS = ac.c accton.c at.c atrun.c col.c comm.c cpio.c cron.c crypt.c dc.c dd.c \ deroff.c diff3.c diff.c diffh.c join.c look.c makekey.c mesg.c \ - newgrp.c pr.c ptx.c rev.c split.c su.c sum.c test.c time.c tsort.c \ + newgrp.c pg.c pr.c ptx.c rev.c split.c su.c sum.c test.c time.c tsort.c \ wall.c SRCSNS = ed.c diff --git a/Applications/V7/cmd/fuzix-cmd.pkg b/Applications/V7/cmd/fuzix-cmd.pkg index d1e55615..c291b148 100644 --- a/Applications/V7/cmd/fuzix-cmd.pkg +++ b/Applications/V7/cmd/fuzix-cmd.pkg @@ -30,6 +30,7 @@ f 0755 /usr/bin/sum sum f 0755 /usr/bin/time time f 0755 /usr/bin/tsort tsort f 0755 /usr/bin/wall wall +f 0755 /usr/bin/pg pg # Man pages - in a separate package so that storage-limited targets can # disable it. diff --git a/Applications/V7/cmd/pg.c b/Applications/V7/cmd/pg.c new file mode 100644 index 00000000..a80926d5 --- /dev/null +++ b/Applications/V7/cmd/pg.c @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include + +#define EOR '\n' +#define NL '\n' +#define CLEAR 014 +#define HOME 031 +#define BACK 037 +#define BUFMAX 16384 +#define PAGMAX 64 + +int file; +int cp, hp; +int page[PAGMAX]; +int eof; + +char buf[BUFMAX]; +int bptr, bnxt, bend; + + +#define incr(a,b) (a++, a&=b-1) +#define decr(a,b) (a--, a&=b-1) + + +void losepage(void) +{ + if(hp=512) + return(512); + losepage(); + } +} + + +void fillbuf(void) +{ + register int r; + ensure(); + if(eof) + return; + r=read(file,&buf[bend],512); + if(r==-1) + return; + bend += r; bend &= BUFMAX-1; + if(r==0) + eof++; +} + +int readchar(void) +{ + register char c; + if(bnxt==bend) + fillbuf(); + if(eof) + return(-1); + c=buf[bnxt]; + incr(bnxt,BUFMAX); + return(c); +} + +void setpage(void) +{ + incr(cp,PAGMAX); + if(cp==hp) + incr(hp,PAGMAX); + page[cp]=bnxt; +} + +void getpage(int i) +{ + if(i==0) + cp=hp; + else if(cp!=hp) + decr(cp,PAGMAX); + bnxt=page[cp]; +} + + +int shell(void) +{ + int rc, status, unixpid; + if( (unixpid=fork())==0 ) { + close(0); dup(2); + execl("/bin/sh", "sh", "-t", 0); + exit(255); + } + else if(unixpid == -1) + return(0); + else{ + signal(SIGCHLD, SIG_DFL); + signal(SIGINT,SIG_IGN); signal(SIGQUIT,SIG_IGN); + while( (rc = wait(&status)) != unixpid && rc != -1 ) ; + signal(SIGINT,SIG_DFL); signal(SIGQUIT,SIG_DFL); + return(1); + } +} + +void print(void) +{ + register int nlc; + char buf[2]; + + hp=0; cp=0; + bptr=bnxt=bend=0; + putchar(CLEAR); + for(;;) { + setpage(); + nlc=0; + putchar(BACK); + while(nlc<20) { + char c; + c = readchar(); + if(eof) + return; + if(c==NL) nlc++; + putchar(c); + } + while(read(2,buf,1)==1 && buf[0]!=NL) { + switch(buf[0]) { + case '/': + case HOME: + putchar(CLEAR); + getpage(0); + break; + case '-': + case BACK: + getpage(-1); + putchar(CLEAR); + break; + case '!': + shell(); buf[0]=NL; break; + } + } + } +} + + +int main(int argc, char *argv[]) +{ + int n=1; + if(argc<2) + print(); + else { + while(argv[n] != NULL) { + if((file=open(argv[n],0))>=0) { + print(); + close(file); + } else printf("pg: `%s' cannot open\n",argv[n]); + n++; + } + } + return 0; +} -- 2.34.1