Usermode/irc - Fix pointer mismatch printing new messages
authorJohn Hodge <[email protected]>
Wed, 21 May 2014 15:21:57 +0000 (23:21 +0800)
committerJohn Hodge <[email protected]>
Wed, 21 May 2014 15:21:57 +0000 (23:21 +0800)
Usermode/Applications/irc_src/pseudo_curses.c
Usermode/Applications/irc_src/window.c

index bdcb3cf..23ee137 100644 (file)
@@ -1,26 +1,71 @@
 /*
  */
 #include "pseudo_curses.h"
+#include <stdbool.h>
 #include <acess/sys.h>
 #include <acess/devices/pty.h>
 #include <stdio.h>
 
+// === PROTOTYPES ===
+bool   ACurses_GetDims_Acess(void);
+bool   ACurses_GetDims_SerialTermHack(void);
+
+// === GLOBALS ===
  int   giTerminal_Width = 80;
  int   giTerminal_Height = 25;
 
+// === CODE ===
 void ACurses_Init(void)
 {
-       if( _SysIOCtl(1, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) {
+       if( ACurses_GetDims_Acess() ) {
+       }
+       else if( ACurses_GetDims_SerialTermHack() ) {
+       }
+       else {
                _SysDebug("note: assuming 80x25, can't get terminal dimensions");
                giTerminal_Width = 80;
                giTerminal_Height = 25;
        }
-       else {
-               struct ptydims  dims;
-               _SysIOCtl(1, PTY_IOCTL_GETDIMS, &dims);
-               giTerminal_Width = dims.W;
-               giTerminal_Height = dims.H;
-       }
+}
+
+bool ACurses_GetDims_Acess(void)
+{
+       if( _SysIOCtl(1, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
+               return false;
+       
+       struct ptydims  dims;
+       if( _SysIOCtl(1, PTY_IOCTL_GETDIMS, &dims) == -1 )
+               return false;
+       giTerminal_Width = dims.W;
+       giTerminal_Height = dims.H;
+       return true;
+}
+
+bool ACurses_GetDims_SerialTermHack(void)
+{
+       _SysDebug("ACurses_GetDims_SerialTermHack: Trying");
+       // Set cursor to 1000,1000 , request cursor position, reset cursor to 0,0
+       static const char req[] = "\033[1000;1000H\033[6n\033[H";
+       fflush(stdin);
+       _SysWrite(1, req, sizeof(req));
+       int64_t timeout = 1000;
+       fd_set fds;
+       FD_ZERO(&fds);
+       FD_SET(0, &fds);
+       _SysSelect(1, &fds, NULL, NULL, &timeout, 0);
+       if( !FD_ISSET(0, &fds) )
+               return false;
+       
+       if( fgetc(stdin) != '\x1b' )
+               return false;
+       if( fgetc(stdin) != '[' )
+               return false;
+       if( fscanf(stdin, "%i;%i", &giTerminal_Width, &giTerminal_Height) != 2 )
+               return false;
+       if( fgetc(stdin) != 'R' )
+               return false;
+       
+       return true;
 }
 
 void SetCursorPos(int Row, int Col)
index db3e4da..48daeb5 100644 (file)
@@ -141,7 +141,9 @@ size_t Windows_int_PaintMessagePrefix(const tMessage *Message, bool EnablePrint)
 
 size_t Windows_int_PaintMessageLine(const tMessage *Message, size_t Offset, bool EnablePrint)
 {
-       if( Message->Data[Offset] == '\0' ) {
+       _SysDebug("Windows_int_PaintMessageLine: Message=%p,Offset=%zi, EnablePrint=%b",
+               Message, Offset, EnablePrint);
+       if( Offset > strlen(Message->Data) ) {
                return 0;
        }
        
@@ -308,7 +310,7 @@ void Window_AppendMessage(tWindow *Window, enum eMessageClass Class, const char
                do {
                        printf("\33[T");        // Scroll down 1 (free space below)
                        SetCursorPos(giTerminal_Height-2, 1);
-                       len = Windows_int_PaintMessageLine(Message, offset, true);
+                       len = Windows_int_PaintMessageLine(msg, offset, true);
                        offset += len;
                } while( len > 0 );
                printf("\33[u");        // Restore cursor

UCC git Repository :: git.ucc.asn.au