From: Alan Cox Date: Sun, 30 Oct 2016 12:28:51 +0000 (+0000) Subject: ue: add termcap verson using tchelp to keep it tiny X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=826df36ce24d463f1fa5fe54b3fa2b80cffd95cb;p=FUZIX.git ue: add termcap verson using tchelp to keep it tiny --- diff --git a/Applications/ue/Makefile b/Applications/ue/Makefile index 2d1cadbe..af3def0b 100644 --- a/Applications/ue/Makefile +++ b/Applications/ue/Makefile @@ -5,15 +5,25 @@ CFLAGS = -c COPT = -O2 OBJS = ue.rel +LIBS = term-ansi.c term-fuzix.c term.c -all: ue +all: ue.fuzix ue.ansi ue -ue: $(OBJS) - $(CC) -o $@ --nostdio $(OBJS) +$(OBJS): ue.h +$(LIBS): ue.h .c.rel: $(CC) $(COPT) $(CFLAGS) $(DEFS) -c $< -o $@ +ue.fuzix: $(OBJS) term-fuzix.rel + $(CC) -o $@ --nostdio $(OBJS) term-fuzix.rel + +ue.ansi: $(OBJS) term-ansi.rel + $(CC) -o $@ $(OBJS) term-ansi.rel + +ue: $(OBJS) term.rel + $(CC) -o $@ --nostdio $(OBJS) term.rel -ltermcap + clean realclean clobber: rm -f *.rel ue *~ diff --git a/Applications/ue/Makefile.6809 b/Applications/ue/Makefile.6809 index e8751659..79568bde 100644 --- a/Applications/ue/Makefile.6809 +++ b/Applications/ue/Makefile.6809 @@ -15,19 +15,24 @@ CRT0NS = ../../Library/libs/crt0nostdio_6809.o .SUFFIXES: .c .o +APPS = ue.fuzix ue.ansi ue -SRCS = ue.c +SRCS = ue.c term-fuzix.c term-ansi.c term.c OBJS = $(SRCS:.c=.o) -APPS = $(OBJS:.o=) - all: $(APPS) size.report -$(APPS): $(CRT0NS) +$(APPS): ue.h + +ue.fuzix: ue.o term-fuzix.o + $(LINKER) -o $@ $(LINKER_OPT) $(CRT0NS) ue.o term-fuzix.o + +ue.ansi: ue.o term-ansi.o + $(LINKER) -o $@ $(LINKER_OPT) $(CRT0) ue.o term-ansi.o -$(APPS): %: %.o - $(LINKER) -o $@ $(LINKER_OPT) $^ +ue: ue.o term.o + $(LINKER) -o $@ $(LINKER_OPT) $(CRT0NS) ue.o term.o -ltermcap6809 size.report: $(APPS) ls -l $< > $@ diff --git a/Applications/ue/term-ansi.c b/Applications/ue/term-ansi.c new file mode 100644 index 00000000..4d72030f --- /dev/null +++ b/Applications/ue/term-ansi.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include "ue.h" + +char str[MAXCOLS]; /* used by gotoxy and clrtoeol */ + +void gotoxy(int x, int y) +{ + sprintf(str,"%c[%03d;%03dH",0x1b,y,x); + write(1, (void*)&str, 10); + outxy.Y=y;outxy.X=x; +} + +void clrtoeol(void) +{ + if (COLS-outxy.X > 0) { + memset(str, ' ', COLS-outxy.X); + write(1, str, COLS-outxy.X); + } + gotoxy(outxy.X,outxy.Y); +} + + +void clrtoeos(void) +{ + int i = outxy.Y; + while(i++ <= ROWS){ + clrtoeol(); + gotoxy(1,i); + } +} + +void tty_init(void) +{ +} diff --git a/Applications/ue/term-fuzix.c b/Applications/ue/term-fuzix.c new file mode 100644 index 00000000..d1577f5b --- /dev/null +++ b/Applications/ue/term-fuzix.c @@ -0,0 +1,26 @@ +#include +#include "ue.h" + +static char str[4] = "\x1bY"; + +void gotoxy(int x, int y){ + str[2] = y + 31; + str[3] = x + 31; + write(1, (void*)&str, 4); + outxy.Y=y;outxy.X=x; +} + +void clrtoeol(void) +{ + write(1, "\x1b" "K", 2); + gotoxy(outxy.X,outxy.Y); +} + +void clrtoeos(void) +{ + write(1, "\x1b" "J", 2); /* clear to end of screen */ +} + +void tty_init(void) +{ +} diff --git a/Applications/ue/tty.h b/Applications/ue/tty.h deleted file mode 100644 index faf79d4b..00000000 --- a/Applications/ue/tty.h +++ /dev/null @@ -1,11 +0,0 @@ -/* temporary replacement for a working */ - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; -#define TIOCGWINSZ 10 -#define VTSIZE 0x22 - diff --git a/Applications/ue/ue.c b/Applications/ue/ue.c index 426ac49c..73ef9358 100644 --- a/Applications/ue/ue.c +++ b/Applications/ue/ue.c @@ -37,27 +37,17 @@ terminal is (1,1) based. display() takes care of the conversion. #include #include #include -#ifdef ANSIEMU -# include -#endif #include +#include "ue.h" -#define BUF 4096*6 -#define UBUF 768 -#define MODE 0666 -#define TABSZ 4 -#define TABM TABSZ-1 - -#define MAXCOLS 96 - -int MAXLINES = 25; +COORD outxy; +int ROWS = MAXROWS; int COLS = MAXCOLS; int LINES = 1; int done; int row, col; -char str[MAXCOLS]; // used by gotoxy and clrtoeol char prompt[]="Look for: "; char sstring[MAXCOLS]; // search string, used by look() char ubuf[UBUF]; // undo buffer @@ -78,13 +68,6 @@ typedef struct { U_REC* undop = (U_REC*)&ubuf; -typedef struct { - int X; - int Y; -} COORD; - -COORD outxy; - struct termios termios, orig; // edit key function prototypes @@ -145,21 +128,6 @@ GetSetTerm(int set) tcsetattr(0, TCSANOW, termiop); } -void -gotoxy(int x, int y){ -#ifdef ANSIEMU - sprintf(str,"%c[%03d;%03dH",0x1b,y,x); - write(1, (void*)&str, 10); -#else - str[0] = '\x1b'; - str[1] = 'Y'; - str[2] = y + 31; - str[3] = x + 31; - write(1, (void*)&str, 4); -#endif - outxy.Y=y;outxy.X=x; -} - char getch() { @@ -186,19 +154,6 @@ emitch(int c) if(c == '\n'){outxy.X=0;outxy.Y++;}; } -void -clrtoeol(void) -{ -#ifdef ANSIEMU - int i=0; - while(i < COLS-outxy.X) - str[i++]=' '; - write(1, (void*)&str, COLS-outxy.X > 0 ? COLS-outxy.X : 0); -#else - write(1, "\x1b" "K", 2); -#endif - gotoxy(outxy.X,outxy.Y); -} // end of I/O char *prevline(char *p) @@ -269,7 +224,7 @@ pgdown(void) void pgup(void) { - int i = MAXLINES; + int i = ROWS; while (0 < --i) { page = prevline(page-1); up(); @@ -433,7 +388,7 @@ display(void) page = prevline(curp); if (epage <= curp) { page = curp; - i = MAXLINES; + i = ROWS; while (1 < i--) page = prevline(page-1); } @@ -444,7 +399,7 @@ display(void) row = i; col = j; } - if (i >= MAXLINES || LINES <= i || etxt <= epage) + if (i >= ROWS || LINES <= i || etxt <= epage) break; if (*epage == '\n' || COLS <= j) { ++i; @@ -457,15 +412,7 @@ display(void) } ++epage; } -#ifdef ANSIEMU - i = outxy.Y; - while(i++ <= MAXLINES){ - clrtoeol(); - gotoxy(1,i); - } -#else - write(1, "\x1b" "J", 2); /* clear to end of screen */ -#endif + clrtoeos(); gotoxy(col+1, row+1); } @@ -486,18 +433,20 @@ int main(int argc, char **argv) #ifdef VTSIZE vtsize = ioctl(0, VTSIZE, 0); if (vtsize != -1) { - MAXLINES = vtsize >> 8; + ROWS = vtsize >> 8; COLS = vtsize & 0xFF; } #endif #ifdef TIOCGWINSZ if (ioctl(0, TIOCGWINSZ, &w) != -1) { if (w.ws_row != 0) - MAXLINES = w.ws_row; + ROWS = w.ws_row; if (w.ws_col != 0) COLS = w.ws_col; } #endif + tty_init(); + if (0 < (i = open(filename = *++argv, 0))) { etxt += read(i, buf, BUF); if (etxt < buf) @@ -529,7 +478,7 @@ int main(int argc, char **argv) } } } - gotoxy(1,MAXLINES+1); + gotoxy(1,ROWS+1); GetSetTerm(1); return (0); } diff --git a/Applications/ue/ue.h b/Applications/ue/ue.h new file mode 100644 index 00000000..bb4336d8 --- /dev/null +++ b/Applications/ue/ue.h @@ -0,0 +1,23 @@ +typedef struct { + int X; + int Y; +} COORD; + +extern COORD outxy; + +extern void clrtoeol(void); +extern void clrtoeos(void); +extern void gotoxy(int, int); +extern void tty_init(void); + +#define BUF 4096*6 +#define UBUF 768 +#define MODE 0666 +#define TABSZ 4 +#define TABM TABSZ-1 + +#define MAXCOLS 132 +#define MAXROWS 32 + +extern int ROWS; +extern int COLS;