From b5047fac9b36d7a552dfb8f385ac4ce77e218919 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 3 Nov 2020 10:37:39 +0800 Subject: [PATCH] Remove MINGW32 partial implementation. --- Makefile | 11 +- README.md | 3 +- estruct.h | 10 -- fridge/mingw32.c | 197 ++++++++++++++++++++++++++++++++++ wscreen.c => fridge/wscreen.c | 0 wscreen.h => fridge/wscreen.h | 0 tcap.c | 2 - termio.c | 2 +- wrapper.c | 6 -- 9 files changed, 204 insertions(+), 27 deletions(-) create mode 100644 fridge/mingw32.c rename wscreen.c => fridge/wscreen.c (100%) rename wscreen.h => fridge/wscreen.h (100%) diff --git a/Makefile b/Makefile index 928ae70..c67c585 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -# Makefile for uEMACS, updated 02 Nov 2020 09:40:01 +# Makefile for uEMACS, updated 03 Nov 2020 10:22:37 -SRC=basic.c bind.c bindable.c buffer.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c util.c window.c word.c wrapper.c wscreen.c -OBJ=basic.o bind.o bindable.o buffer.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o util.o window.o word.o wrapper.o wscreen.o -HDR=basic.h bind.h bindable.h buffer.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isa.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h util.h version.h window.h word.h wrapper.h wscreen.h +SRC=basic.c bind.c bindable.c buffer.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c util.c window.c word.c wrapper.c +OBJ=basic.o bind.o bindable.o buffer.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o util.o window.o word.o wrapper.o +HDR=basic.h bind.h bindable.h buffer.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isa.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h util.h version.h window.h word.h wrapper.h # DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them @@ -128,7 +128,7 @@ depend: ${SRC} $(Q) ${CC} ${CFLAGS} ${DEFINES} -c $*.c # DO NOT DELETE THIS LINE -- make depend uses it -# Updated 02 Nov 2020 11:25:55 +# Updated 03 Nov 2020 10:29:47 basic.o: basic.c basic.h retcode.h input.h bind.h mlout.h random.h \ terminal.h defines.h utf8.h window.h buffer.h line.h @@ -198,7 +198,6 @@ window.o: window.c window.h defines.h buffer.h line.h retcode.h utf8.h \ word.o: word.c word.h basic.h retcode.h buffer.h line.h utf8.h estruct.h \ isa.h mlout.h random.h region.h window.h defines.h wrapper.o: wrapper.c wrapper.h -wscreen.o: wscreen.c wscreen.h # DEPENDENCIES MUST END AT END OF FILE # IF YOU PUT STUFF HERE IT WILL GO AWAY diff --git a/README.md b/README.md index d8c3ae3..1cfc656 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,8 @@ * Some defaults changed due to 'finger habits': ue instead of em, ^S in commands mapping... ### How to build ### -* dependencies: gcc, gmake, ncurses. +* dependencies: gcc, gmake, ncurses-devel. * make depend ; make -* MINGW32 target is experimental and lacks screen/kbd support. ### Badges ### [![Coverity Status](https://scan.coverity.com/projects/4449/badge.svg)](https://scan.coverity.com/projects/4449) diff --git a/estruct.h b/estruct.h index 7bc9524..26abded 100644 --- a/estruct.h +++ b/estruct.h @@ -79,16 +79,6 @@ #define TERMCAP 0 /* Use TERMCAP */ #define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */ -#elif defined( MINGW32) - -#define VT220 UNIX -#define VT100 0 - -#define ANSI 0 -#define VT52 0 -#define TERMCAP 0 -#define IBMPC 0 - #else #define VT220 UNIX diff --git a/fridge/mingw32.c b/fridge/mingw32.c new file mode 100644 index 0000000..c827873 --- /dev/null +++ b/fridge/mingw32.c @@ -0,0 +1,197 @@ +/* mingw32.c -- */ + +#ifdef MINGW32 +#include "termio.h" +#include "terminal.h" + +#include +#include +#include +#include +#include + +#include "utf8.h" +#include "wscreen.h" + +static void vv( void) {} +static void vi( int i) {} +static int is( char *s) { return *s ; } + +static void ttmove( int l, int c) ; + +#define MARGIN 8 +#define SCRSIZ 64 +#define NPAUSE 10 /* # times thru update to pause. */ + +struct terminal term = { + 24, /* These four values are set dynamically at open time. */ + 24, + 80, + 80, + MARGIN, + SCRSIZ, + NPAUSE, + ttopen, +#if PKCODE + ttclose, +#else + ttclose, +#endif + vv, /* ttkopen, */ + vv, /* ttkclose, */ + ttgetc, + ttputc, + ttflush, + ttmove, + vv, /* tteeol, */ + vv, /* tteeop, */ + vv, /* ttbeep, */ + vi, /* ttrev, */ + is /* ttcres */ +#if COLOR + , iv, /* ttfcol, */ + iv /* ttbcol */ +#endif +#if SCROLLCODE + , NULL /* set dynamically at open time */ +#endif +} ; + + +int ttrow ; /* Row location of HW cursor */ +int ttcol ; /* Column location of HW cursor */ + +boolean eolexist = TRUE ; /* does clear to EOL exist? */ +boolean revexist = FALSE ; /* does reverse video exist? */ +boolean sgarbf = TRUE ; /* State of screen unknown */ + +char sres[ 16] ; /* Current screen resolution. */ + /* NORMAL, CGA, EGA, VGA */ + +void ttopen( void) { + winit() ; + wcls() ; + term.t_mrow = term.t_nrow = wbottom() - wtop() ; + term.t_mcol = term.t_ncol = wright() - wleft() + 1 ; + wtitle( "uEMACS") ; +} + +void ttclose( void) { +} + +int ttputc( unicode_t c) { + char utf8[ 6] ; + int bytes ; + + bytes = unicode_to_utf8( c, utf8) ; + fwrite( utf8, 1, bytes, stdout); + return 0 ; +} + +void ttflush( void) { + int status ; + + status = fflush( stdout); + while( status < 0 && errno == EAGAIN) { + _sleep( 1) ; + status = fflush( stdout) ; + } + + if( status < 0) + exit( 15) ; +} + +int ttgetc( void) { + static char buffer[ 32] ; + static int pending ; + unicode_t c ; + int count, bytes = 1, expected ; + + count = pending ; + if( !count) { + count = read( 0, buffer, sizeof( buffer)) ; + if( count <= 0) + return 0 ; + + pending = count ; + } + + c = (unsigned char) buffer[ 0] ; + if( c >= 32 && c < 128) + goto done ; + + /* + * Lazy. We don't bother calculating the exact + * expected length. We want at least two characters + * for the special character case (ESC+[) and for + * the normal short UTF8 sequence that starts with + * the 110xxxxx pattern. + * + * But if we have any of the other patterns, just + * try to get more characters. At worst, that will + * just result in a barely perceptible 0.1 second + * delay for some *very* unusual utf8 character + * input. + */ + expected = 2 ; + if( (c & 0xe0) == 0xe0) + expected = 6 ; + + /* Special character - try to fill buffer */ + if( count < expected) { + int n; +#if 0 + ntermios.c_cc[VMIN] = 0; + ntermios.c_cc[VTIME] = 1; /* A .1 second lag */ + tcsetattr(0, TCSANOW, &ntermios); +#endif + n = read(0, buffer + count, sizeof(buffer) - count); + + /* Undo timeout */ +#if 0 + ntermios.c_cc[VMIN] = 1; + ntermios.c_cc[VTIME] = 0; + tcsetattr(0, TCSANOW, &ntermios); +#endif + if (n > 0) + pending += n; + } + + if( pending > 1) { + unsigned char second = buffer[1]; + + /* Turn ESC+'[' into CSI */ + if (c == 27 && second == '[') { + bytes = 2; + c = 128+27; + goto done; + } + } + + bytes = utf8_to_unicode( buffer, 0, pending, &c) ; + +done: + pending -= bytes ; + memmove( buffer, buffer+bytes, pending) ; + return c ; +} + +int typahead( void) { + int x ; /* holds # of pending chars */ + +#ifdef FIONREAD + if( ioctl( 0, FIONREAD, &x) < 0) +#endif + x = 0 ; + return x ; +} + +static void ttmove( int l, int c) { + wgoxy( c, l) ; +} + +#else +typedef void _pedantic_empty_translation_unit ; +#endif + +/* end of mingw32.c */ diff --git a/wscreen.c b/fridge/wscreen.c similarity index 100% rename from wscreen.c rename to fridge/wscreen.c diff --git a/wscreen.h b/fridge/wscreen.h similarity index 100% rename from wscreen.h rename to fridge/wscreen.h diff --git a/tcap.c b/tcap.c index 73981b3..7fff1b2 100644 --- a/tcap.c +++ b/tcap.c @@ -19,10 +19,8 @@ #define USE_BROKEN_OPTIMIZATION 0 #define termdef 1 /* Don't define "term" external. */ -#ifndef MINGW32 #include #include -#endif #include "display.h" #include "estruct.h" diff --git a/termio.c b/termio.c index 420e871..f17265e 100644 --- a/termio.c +++ b/termio.c @@ -1,5 +1,5 @@ /* termio.c -- implements termio.h */ -#if !defined( POSIX) && !defined( MINGW32) +#if !defined( POSIX) #include "termio.h" diff --git a/wrapper.c b/wrapper.c index bdf565b..21dda69 100644 --- a/wrapper.c +++ b/wrapper.c @@ -7,12 +7,6 @@ #include #include -#ifdef MINGW32 -int mkstemp( char *template) { - return -1 ; -} -#endif - static void die( const char *err) { fprintf( stderr, "fatal: %s\n", err) ; exit( EXIT_FAILURE) ;