<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16000] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16000">16000</a></dd>
<dt>Author</dt> <dd>mrene</dd>
<dt>Date</dt> <dd>2009-12-18 15:56:51 -0600 (Fri, 18 Dec 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre><a href="http://jira.freeswitch.org/browse/FSCORE-516">FSCORE-516</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcswitch_consolec">freeswitch/trunk/src/switch_console.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcswitch_consolec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_console.c (15999 => 16000)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_console.c        2009-12-18 20:46:39 UTC (rev 15999)
+++ freeswitch/trunk/src/switch_console.c        2009-12-18 21:56:51 UTC (rev 16000)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> #include <switch.h>
</span><span class="cx"> #include <switch_console.h>
</span><span class="cx"> #include <switch_version.h>
</span><del>-#define CMD_BUFLEN 1024;
</del><ins>+#define CMD_BUFLEN 1024
</ins><span class="cx">
</span><span class="cx"> #ifdef SWITCH_HAVE_LIBEDIT
</span><span class="cx"> #include <histedit.h>
</span><span class="lines">@@ -43,7 +43,35 @@
</span><span class="cx"> static HistEvent ev;
</span><span class="cx"> static char *hfile = NULL;
</span><span class="cx">
</span><ins>+#else
</ins><span class="cx">
</span><ins>+#define CC_NORM 0
+#define CC_NEWLINE 1
+#define CC_EOF 2
+#define CC_ARGHACK 3
+#define CC_REFRESH 4
+#define CC_CURSOR 5
+#define CC_ERROR 6
+#define CC_FATAL 7
+#define CC_REDISPLAY 8
+#define CC_REFRESH_BEEP 9
+
+#ifdef _MSC_VER
+#define HISTLEN 10
+#define KEY_UP 1
+#define KEY_DOWN 2
+#define KEY_TAB 3
+#define CLEAR_OP 4
+#define DELETE_REFRESH_OP 5
+#define KEY_LEFT 6
+#define KEY_RIGHT 7
+#define KEY_INSERT 8
+#define PROMPT_OP 9
+
+static int console_bufferInput (char* buf, int len, char *cmd, int key);
+#endif
+#endif
+
</ins><span class="cx"> /*
</span><span class="cx"> * store a strdup() of the string configured in XML
</span><span class="cx"> * bound to each of the 12 function key
</span><span class="lines">@@ -91,21 +119,7 @@
</span><span class="cx">
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><del>-#else
</del><span class="cx">
</span><del>-#define CC_NORM 0
-#define CC_NEWLINE 1
-#define CC_EOF 2
-#define CC_ARGHACK 3
-#define CC_REFRESH 4
-#define CC_CURSOR 5
-#define CC_ERROR 6
-#define CC_FATAL 7
-#define CC_REDISPLAY 8
-#define CC_REFRESH_BEEP 9
-
-#endif
-
</del><span class="cx"> SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_raw_write(switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen)
</span><span class="cx"> {
</span><span class="cx">         switch_size_t need = handle->data_len + datalen;
</span><span class="lines">@@ -467,7 +481,11 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (!zstr(target)) {
</span><ins>+#ifdef _MSC_VER
+                if ((h->hits % 3) == 0) {
+#else
</ins><span class="cx">                 if ((h->hits % 4) == 0) {
</span><ins>+#endif
</ins><span class="cx">                         if (h->out) {
</span><span class="cx">                                 fprintf(h->out, "\n");
</span><span class="cx">                         }
</span><span class="lines">@@ -543,10 +561,12 @@
</span><span class="cx">         int sc = 0;
</span><span class="cx">         
</span><span class="cx"> #ifndef SWITCH_HAVE_LIBEDIT
</span><ins>+#ifndef _MSC_VER
</ins><span class="cx">         if (!stream) {
</span><span class="cx">                 return CC_ERROR;
</span><span class="cx">         }
</span><span class="cx"> #endif
</span><ins>+#endif
</ins><span class="cx">
</span><span class="cx">         switch_core_db_handle(&db);
</span><span class="cx">         
</span><span class="lines">@@ -734,7 +754,22 @@
</span><span class="cx">                         el_insertstr(el, h.partial);
</span><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+#else
+#ifdef _MSC_VER
+        if (h.out) {
+                if (h.hits == 1 && !zstr(h.last)) {
+                        console_bufferInput(0, h.len, (char*)line, DELETE_REFRESH_OP);
+                        console_bufferInput(h.last, (int)strlen(h.last), (char*)line, 0);
+                        console_bufferInput(" ", 1, (char*)line, 0);
+                } else if (h.hits > 1 && !zstr(h.partial)) {
+                        console_bufferInput(0, h.len, (char*)line, DELETE_REFRESH_OP);
+                        console_bufferInput(h.partial, (int)strlen(h.partial), (char*)line, 0);
+                } else {
+                        console_bufferInput(0, 0, (char*)line, DELETE_REFRESH_OP);
+                }
+        }
</ins><span class="cx"> #endif
</span><ins>+#endif
</ins><span class="cx">
</span><span class="cx"> end:
</span><span class="cx">
</span><span class="lines">@@ -752,10 +787,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-
-#ifdef SWITCH_HAVE_LIBEDIT
-static char prompt_str[512] = "";
-
</del><span class="cx"> /*
</span><span class="cx"> * If a fnkey is configured then process the command
</span><span class="cx"> */
</span><span class="lines">@@ -782,6 +813,9 @@
</span><span class="cx">         return CC_REDISPLAY;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#ifdef SWITCH_HAVE_LIBEDIT
+static char prompt_str[512] = "";
+
</ins><span class="cx"> static unsigned char console_f1key(EditLine * el, int ch)
</span><span class="cx"> {
</span><span class="cx">         return console_fnkey_pressed(1);
</span><span class="lines">@@ -993,23 +1027,376 @@
</span><span class="cx">
</span><span class="cx"> #else
</span><span class="cx">
</span><ins>+#ifdef _MSC_VER
+char history[HISTLEN][CMD_BUFLEN+1];
+int iHistory = 0;
+int iHistorySel = 0;
+
+static int console_history (char *cmd, int direction)
+{
+        int i;
+        static int first;
+
+        if (direction == 0) {
+                first = 1;
+                if (iHistory < HISTLEN) {
+                        if (iHistory && strcmp(history[iHistory-1], cmd)) {
+                                iHistorySel = iHistory;
+                                strcpy(history[iHistory++], cmd);
+                        }
+                        else if (iHistory == 0) {
+                                iHistorySel = iHistory;
+                                strcpy(history[iHistory++], cmd);
+                        }
+                }
+                else {
+                        iHistory = HISTLEN-1;
+                        for (i = 0; i < HISTLEN-1; i++)
+                        {
+                                strcpy(history[i], history[i+1]);
+                        }
+                        iHistorySel = iHistory;
+                        strcpy(history[iHistory++], cmd);
+                }
+        }
+        else {
+                if (!first) {
+                        iHistorySel += direction;
+                }
+                first = 0;
+                if (iHistorySel < 0) {
+                        iHistorySel = 0;
+                }
+                if (iHistory && iHistorySel >= iHistory) {
+                        iHistorySel = iHistory-1;
+                }
+                strcpy(cmd, history[iHistorySel]);
+        }
+        return (SWITCH_STATUS_SUCCESS);
+}
+
+static int console_bufferInput (char* addchars, int len, char *cmd, int key)
+{
+ static int iCmdBuffer = 0;
+        static int iCmdCursor = 0;
+ static int ignoreNext = 0;
+        static int insertMode = 1;
+        static COORD orgPosition;
+        static char prompt [80];
+ int iBuf;
+        int i;
+
+        HANDLE hOut;
+        CONSOLE_SCREEN_BUFFER_INFO info;
+        COORD position;
+        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
+        GetConsoleScreenBufferInfo(hOut, &info);
+        position = info.dwCursorPosition;
+        if (iCmdCursor == 0) {
+                orgPosition = position;
+        }
+
+        if (key == PROMPT_OP) {
+                if (strlen(cmd) < sizeof(prompt)) {
+                        strcpy(prompt, cmd);
+                }
+                return 0;
+        }
+
+        if (key == KEY_TAB) {
+                switch_console_complete(cmd, cmd+iCmdBuffer, switch_core_get_console(), NULL, NULL);
+                return 0;
+        }
+        if (key == KEY_UP || key == KEY_DOWN || key == CLEAR_OP) {
+                SetConsoleCursorPosition(hOut, orgPosition);
+                for (i = 0; i < (int)strlen(cmd); i++) {
+                        printf(" ");
+                }
+                SetConsoleCursorPosition(hOut, orgPosition);
+                iCmdBuffer = 0;
+                iCmdCursor = 0;
+                memset(cmd, 0, CMD_BUFLEN);
+        }
+        if (key == DELETE_REFRESH_OP) {
+                int l = len < (int)strlen(cmd) ? len : (int)strlen(cmd);
+                for (i = 0; i < l; i++) {
+                        cmd[--iCmdBuffer] = 0;
+                }
+                iCmdCursor = (int)strlen(cmd);
+                printf("%s%s", prompt, cmd);
+                return 0;
+        }
+
+        if (key == KEY_LEFT) {
+                if (iCmdCursor) {
+                        if (position.X == 0) {
+                                position.Y -= 1;
+                                position.X = info.dwSize.X-1;
+                        }
+                        else {
+                                position.X -= 1;
+                        }
+
+                        SetConsoleCursorPosition(hOut, position);
+                        iCmdCursor--;
+                }
+        }
+        if (key == KEY_RIGHT) {
+                if (iCmdCursor < (int)strlen(cmd)) {
+                        if (position.X == info.dwSize.X-1) {
+                                position.Y += 1;
+                                position.X = 0;
+                        }
+                        else {
+                                position.X += 1;
+                        }
+
+                        SetConsoleCursorPosition(hOut, position);
+                        iCmdCursor++;
+                }
+        }
+        if (key == KEY_INSERT) {
+                insertMode = !insertMode;
+        }
+ for (iBuf = 0; iBuf < len; iBuf++) {
+                switch (addchars[iBuf]) {
+                        case '\r':
+                        case '\n':
+                                if (ignoreNext) {
+                                        ignoreNext = 0;
+                                }
+                                else {
+                                        int ret = iCmdBuffer;
+                                        if (iCmdBuffer == 0) {
+                                                strcpy(cmd, "Empty");
+                                                ret = (int)strlen(cmd);
+                                        }
+                                        else {
+                                                console_history(cmd, 0);
+                                                cmd[iCmdBuffer] = 0;
+                                        }
+                                        iCmdBuffer = 0;
+                                        iCmdCursor = 0;
+                                        printf("\n");
+                                        return (ret);
+                                }
+                                break;
+                        case '\b':
+                                if (iCmdCursor) {
+                                        if (position.X == 0) {
+                                                position.Y -= 1;
+                                                position.X = info.dwSize.X-1;
+                                                SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        else {
+                                                position.X -= 1;
+                                                SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        printf(" ");
+                                        if (iCmdCursor < iCmdBuffer) {
+                                                        int pos;
+                                                        iCmdCursor--;
+                                                        for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+                                                                cmd[pos] = cmd[pos+1];
+                                                        }
+                                                        cmd[pos] = 0;
+                                                        iCmdBuffer--;
+
+                                                        SetConsoleCursorPosition(hOut, position);
+                                                        for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+                                                                printf("%c", cmd[pos]);
+                                                        }
+                                                        printf(" ");
+                                                        SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        else {
+                                                SetConsoleCursorPosition(hOut, position);
+                                                iCmdBuffer--;
+                                                iCmdCursor--;
+                                                cmd[iCmdBuffer] = 0;
+                                        }
+                                }
+                                break;
+                        default:
+                                if (!ignoreNext) {
+                                        if (iCmdCursor < iCmdBuffer) {
+                                                int pos;
+
+                                                if (position.X == info.dwSize.X-1) {
+                                                        position.Y += 1;
+                                                        position.X = 0;
+                                                }
+                                                else {
+                                                        position.X += 1;
+                                                }
+
+                                                if (insertMode) {
+                                                        for (pos = iCmdBuffer-1; pos >= iCmdCursor; pos--) {
+                                                                cmd[pos+1] = cmd[pos];
+                                                        }
+                                                }
+                                                iCmdBuffer++;
+                                                cmd[iCmdCursor++] = addchars[iBuf];
+                                                printf("%c", addchars[iBuf]);
+                                                for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+                                                        GetConsoleScreenBufferInfo(hOut, &info);
+                                                        if (info.dwCursorPosition.X == info.dwSize.X-1 && info.dwCursorPosition.Y == info.dwSize.Y-1) {
+                                                                orgPosition.Y -= 1;
+                                                                position.Y -= 1;
+                                                        }
+                                                        printf("%c", cmd[pos]);
+                                                }
+                                                SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        else {
+                                                if (position.X == info.dwSize.X-1 && position.Y == info.dwSize.Y-1) {
+                                                        orgPosition.Y -= 1;
+                                                }
+                                                cmd[iCmdBuffer++] = addchars[iBuf];
+                                                iCmdCursor++;
+                                                printf("%c", addchars[iBuf]);
+                                        }
+                                }
+                }
+                if (iCmdBuffer == CMD_BUFLEN) {
+                        printf("Read Console... BUFFER OVERRUN\n");
+                        iCmdBuffer = 0;
+                        ignoreNext = 1;
+                }
+ }
+ return (SWITCH_STATUS_SUCCESS);
+}
+
+
+static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int *key)
+{
+ DWORD recordIndex, bufferIndex, toRead, red;
+ PINPUT_RECORD pInput;
+
+ GetNumberOfConsoleInputEvents(conIn, &toRead);
+        if (len < (int)toRead) {
+                toRead = len;
+        }
+        if (toRead == 0) {
+                return(FALSE);
+        }
+
+        if ((pInput = (PINPUT_RECORD) malloc(toRead * sizeof(INPUT_RECORD))) == NULL) {
+                return (FALSE);
+        }
+        *key = 0;
+ ReadConsoleInput(conIn, pInput, toRead, &red);
+
+ for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
+ KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
+         if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
+                        if (keyEvent.wVirtualKeyCode == 38 && keyEvent.wVirtualScanCode == 72) {
+                                buf[0] = 0;
+                                console_history(buf, -1);
+                                *key = KEY_UP;
+                                bufferIndex += (DWORD)strlen(buf);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 40 && keyEvent.wVirtualScanCode == 80) {
+                                buf[0] = 0;
+                                console_history(buf, 1);
+                                *key = KEY_DOWN;
+                                bufferIndex += (DWORD)strlen(buf);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 112 && keyEvent.wVirtualScanCode == 59) {
+                                console_fnkey_pressed(1);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 113 && keyEvent.wVirtualScanCode == 60) {
+                                console_fnkey_pressed(2);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 114 && keyEvent.wVirtualScanCode == 61) {
+                                console_fnkey_pressed(3);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 115 && keyEvent.wVirtualScanCode == 62) {
+                                console_fnkey_pressed(4);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 116 && keyEvent.wVirtualScanCode == 63) {
+                                console_fnkey_pressed(5);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 117 && keyEvent.wVirtualScanCode == 64) {
+                                console_fnkey_pressed(6);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 118 && keyEvent.wVirtualScanCode == 65) {
+                                console_fnkey_pressed(7);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 119 && keyEvent.wVirtualScanCode == 66) {
+                                console_fnkey_pressed(8);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 120 && keyEvent.wVirtualScanCode == 67) {
+                                console_fnkey_pressed(9);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 121 && keyEvent.wVirtualScanCode == 68) {
+                                console_fnkey_pressed(10);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 122 && keyEvent.wVirtualScanCode == 87) {
+                                console_fnkey_pressed(11);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 123 && keyEvent.wVirtualScanCode == 88) {
+                                console_fnkey_pressed(12);
+                        }
+                        if (keyEvent.uChar.AsciiChar == 9) {
+                                *key = KEY_TAB;
+                                break;
+                        }
+                        if (keyEvent.uChar.AsciiChar == 27) {
+                                *key = CLEAR_OP;
+                                break;
+                        }
+                        if (keyEvent.wVirtualKeyCode == 37 && keyEvent.wVirtualScanCode == 75) {
+                                *key = KEY_LEFT;
+                        }
+                        if (keyEvent.wVirtualKeyCode == 39 && keyEvent.wVirtualScanCode == 77) {
+                                *key = KEY_RIGHT;
+                        }
+                        if (keyEvent.wVirtualKeyCode == 45 && keyEvent.wVirtualScanCode == 82) {
+                                *key = KEY_INSERT;
+                        }
+          while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) {
+                         buf[bufferIndex] = keyEvent.uChar.AsciiChar;
+                                if (buf[bufferIndex] == '\r') {
+                                 buf[bufferIndex] = '\n';
+                                }
+                         bufferIndex++;
+                         keyEvent.wRepeatCount--;
+          }
+         }
+ }
+
+ free(pInput);
+ *pRed = bufferIndex;
+ return (TRUE);
+}
+#endif
+
+
</ins><span class="cx"> SWITCH_DECLARE(void) switch_console_loop(void)
</span><span class="cx"> {
</span><del>-
-        char cmd[2048] = "";
</del><ins>+        char cmd[CMD_BUFLEN+1] = "";
</ins><span class="cx">         int32_t activity = 1;        
</span><span class="cx"> #ifndef _MSC_VER
</span><span class="cx">         int x = 0;
</span><ins>+#else
+        char keys[80];
</ins><span class="cx"> #endif        
</span><span class="cx">
</span><ins>+        /* Load/Init the config first */
+        console_xml_config();
</ins><span class="cx">         gethostname(hostname, sizeof(hostname));
</span><ins>+#ifdef _MSC_VER
+        sprintf(cmd, "\nfreeswitch@%s> ", hostname);
+        console_bufferInput (0, 0, cmd, PROMPT_OP);
+        memset(cmd, 0, sizeof(cmd));
+#endif
</ins><span class="cx">
</span><span class="cx">         while (running) {
</span><span class="cx">                 int32_t arg;
</span><span class="cx"> #ifdef _MSC_VER
</span><del>-                DWORD read, i;
</del><ins>+                int read, key;
</ins><span class="cx">                 HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
</span><del>-                INPUT_RECORD in[128];
</del><span class="cx"> #else
</span><span class="cx">                 fd_set rfds, efds;
</span><span class="cx">                 struct timeval tv = { 0, 20000 };
</span><span class="lines">@@ -1025,29 +1412,17 @@
</span><span class="cx">                 }
</span><span class="cx"> #ifdef _MSC_VER
</span><span class="cx">                 activity = 0;
</span><del>-                PeekConsoleInput(stdinHandle, in, 128, &read);
-                for (i = 0; i < read; i++) {
-                        if (in[i].EventType == KEY_EVENT && !in[i].Event.KeyEvent.bKeyDown) {
</del><ins>+                if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
+                        if (console_bufferInput(keys, read, cmd, key)) {
+                                if (!strcmp(cmd, "Empty")) {
+                                        cmd[0] = '\n';
+                                        cmd[1] = 0;
+                                }
</ins><span class="cx">                                 activity = 1;
</span><del>-                                break;
</del><ins>+                                running = switch_console_process(cmd, 0);
+                                memset(cmd, 0, sizeof(cmd));
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-
-                if (activity) {
-                        DWORD bytes = 0;
-                        char *end;
-                        ReadConsole(stdinHandle, cmd, sizeof(cmd), &bytes, NULL);
-                        FlushConsoleInputBuffer(stdinHandle);
-                        end = end_of_p(cmd);
-                        while(*end == '\r' || *end == '\n') {
-                                *end-- = '\0';        
-                        }
-                }
-
-                if (cmd[0]) {
-                        running = switch_console_process(cmd, 0);
-                        memset(cmd, 0, sizeof(cmd));
-                }
</del><span class="cx">                 Sleep(20);
</span><span class="cx"> #else
</span><span class="cx">                 FD_ZERO(&rfds);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>