ue: add termcap verson using tchelp to keep it tiny
authorAlan Cox <alan@linux.intel.com>
Sun, 30 Oct 2016 12:28:51 +0000 (12:28 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 30 Oct 2016 12:28:51 +0000 (12:28 +0000)
Applications/ue/Makefile
Applications/ue/Makefile.6809
Applications/ue/term-ansi.c [new file with mode: 0644]
Applications/ue/term-fuzix.c [new file with mode: 0644]
Applications/ue/tty.h [deleted file]
Applications/ue/ue.c
Applications/ue/ue.h [new file with mode: 0644]

index 2d1cadb..af3def0 100644 (file)
@@ -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 *~
 
index e875165..79568bd 100644 (file)
@@ -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 (file)
index 0000000..4d72030
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#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 (file)
index 0000000..d1577f5
--- /dev/null
@@ -0,0 +1,26 @@
+#include <unistd.h>
+#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 (file)
index faf79d4..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/* temporary replacement for a working <sys/tty.h> */
-
-struct winsize {
-    unsigned short ws_row;
-    unsigned short ws_col;
-    unsigned short ws_xpixel;
-    unsigned short ws_ypixel;
-};
-#define TIOCGWINSZ     10
-#define VTSIZE         0x22
-
index 426ac49..73ef935 100644 (file)
@@ -37,27 +37,17 @@ terminal is (1,1) based. display() takes care of the conversion.
 #include <ctype.h>
 #include <string.h>
 #include <termios.h>
-#ifdef ANSIEMU
-# include <stdio.h>
-#endif
 #include <unistd.h>
+#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 (file)
index 0000000..bb4336d
--- /dev/null
@@ -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;