diff --git a/Makefile b/Makefile index 90bc9cd..e2a8caa 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -# Makefile for emacs, updated Sat, Nov 15, 2014 11:09:11 AM +# Makefile for emacs, updated Mon, Nov 17, 2014 1:05:02 PM -SRC=ansi.c basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c ibmpc.c input.c isearch.c line.c lock.c log.c main.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c -OBJ=ansi.o basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o ibmpc.o input.o isearch.o line.o lock.o log.o main.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o -HDR=basic.h bind.h bindable.h buffer.h crypt.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h log.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h +SRC=ansi.c basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c ibmpc.c input.c isearch.c line.c lock.c log.c main.c mingw32.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c wscreen.c +OBJ=ansi.o basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o ibmpc.o input.o isearch.o line.o lock.o log.o main.o mingw32.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o wscreen.o +HDR=basic.h bind.h bindable.h buffer.h crypt.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h log.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h # DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them @@ -176,6 +176,7 @@ log.o: log.c log.h retcode.h main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h crypt.h \ line.h utf8.h display.h eval.h execute.h file.h retcode.h input.h lock.h \ log.h random.h search.h terminal.h defines.h termio.h version.h window.h +mingw32.o: mingw32.c names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \ line.h utf8.h display.h eval.h exec.h retcode.h file.h isearch.h \ region.h random.h search.h spawn.h window.h defines.h word.h @@ -203,6 +204,7 @@ window.o: window.c window.h defines.h buffer.h crypt.h line.h utf8.h \ word.o: word.c word.h basic.h buffer.h crypt.h line.h utf8.h estruct.h \ log.h retcode.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/mingw32.c b/mingw32.c new file mode 100644 index 0000000..029f67e --- /dev/null +++ b/mingw32.c @@ -0,0 +1,191 @@ +#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( int 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) ; +} + +#endif diff --git a/wscreen.c b/wscreen.c new file mode 100644 index 0000000..45460d1 --- /dev/null +++ b/wscreen.c @@ -0,0 +1,117 @@ +/* wscreen.c -- windows screen console */ +#include "wscreen.h" + +#ifdef MINGW32 + +#include +#include +#include + +/* Standard error macro for reporting API errors */ +#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ + on line %d\n", __FILE__, GetLastError(), api, __LINE__);} + +static void cls( HANDLE hConsole ) +{ + COORD coordScreen = { 0, 0 }; /* here's where we'll home the + cursor */ + BOOL bSuccess; + DWORD cCharsWritten; + CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ + DWORD dwConSize; /* number of character cells in + the current buffer */ + + /* get the number of character cells in the current buffer */ + + bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); + PERR( bSuccess, "GetConsoleScreenBufferInfo" ); + dwConSize = csbi.dwSize.X * csbi.dwSize.Y; + + /* fill the entire screen with blanks */ + + bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', + dwConSize, coordScreen, &cCharsWritten ); + PERR( bSuccess, "FillConsoleOutputCharacter" ); + + /* get the current text attribute */ + + bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); + PERR( bSuccess, "ConsoleScreenBufferInfo" ); + + /* now set the buffer's attributes accordingly */ + + bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, + dwConSize, coordScreen, &cCharsWritten ); + PERR( bSuccess, "FillConsoleOutputAttribute" ); + + /* put the cursor at (0, 0) */ + + bSuccess = SetConsoleCursorPosition( hConsole, coordScreen ); + PERR( bSuccess, "SetConsoleCursorPosition" ); + return; +} + +void wcls( void) { + cls( GetStdHandle( STD_OUTPUT_HANDLE)) ; +} + +static struct { + int width ; + int height ; + int curTop, curBot, curRight, curLeft ; +} Screen ; + +void winit( void) { + CONSOLE_SCREEN_BUFFER_INFO csbInfo ; + + wcls() ; + if( GetConsoleScreenBufferInfo( + GetStdHandle( STD_OUTPUT_HANDLE), &csbInfo)) { + Screen.width = csbInfo.dwSize.X ; + Screen.height = csbInfo.dwSize.Y ; + Screen.curLeft = csbInfo.srWindow.Left ; + Screen.curTop = csbInfo.srWindow.Top ; + Screen.curRight = csbInfo.srWindow.Right ; + Screen.curBot = csbInfo.srWindow.Bottom ; + } +} + +int wwidth( void) { + return Screen.width ; +} + +int wheight( void) { + return Screen.height ; +} + +int wleft( void) { + return Screen.curLeft ; +} + +int wtop( void) { + return Screen.curTop ; +} + +int wright( void) { + return Screen.curRight ; +} + +int wbottom( void) { + return Screen.curBot ; +} + +void wgoxy( int x, int y) { + COORD coord ; + + coord.X = x ; + coord.Y = y ; + SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE), coord ); +} + +void wtitle( const char *title) { + SetConsoleTitle( title) ; +} + +#endif + +/* end of wscreen.c */ diff --git a/wscreen.h b/wscreen.h new file mode 100644 index 0000000..65080f4 --- /dev/null +++ b/wscreen.h @@ -0,0 +1,14 @@ +/* wscreen.h -- character screen drawing */ + +void winit( void) ; +void wcls( void) ; +void wgoxy( int x, int y) ; +void wtitle( const char *title) ; +int wwidth( void) ; +int wheight( void) ; +int wleft( void) ; +int wright( void) ; +int wtop( void) ; +int wbottom( void) ; + +/* end of wscreen.h */