<!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][16010] </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=16010">16010</a></dd>
<dt>Author</dt> <dd>jlenk</dd>
<dt>Date</dt> <dd>2009-12-21 11:39:05 -0600 (Mon, 21 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre><a href="http://jira.freeswitch.org/browse/ESL-24">ESL-24</a> Add tab complete to windows</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunklibseslfs_clic">freeswitch/trunk/libs/esl/fs_cli.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_consolec">freeswitch/trunk/src/switch_console.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunklibseslfs_clic"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/esl/fs_cli.c (16009 => 16010)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/esl/fs_cli.c        2009-12-21 16:15:49 UTC (rev 16009)
+++ freeswitch/trunk/libs/esl/fs_cli.c        2009-12-21 17:39:05 UTC (rev 16010)
</span><span class="lines">@@ -7,12 +7,39 @@
</span><span class="cx"> #include &lt;esl.h&gt;
</span><span class="cx"> #include &lt;signal.h&gt;
</span><span class="cx"> 
</span><ins>+#define CMD_BUFLEN 1024
+
</ins><span class="cx"> #ifdef WIN32
</span><span class="cx"> #define strdup(src) _strdup(src)
</span><span class="cx"> #define usleep(time) Sleep(time/1000)
</span><span class="cx"> #define fileno _fileno
</span><span class="cx"> #define read _read
</span><span class="cx"> #include &lt;io.h&gt;
</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
+
+#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);
+static unsigned char esl_console_complete(const char *buffer, const char *cursor);
</ins><span class="cx"> #else
</span><span class="cx"> #include &lt;sys/select.h&gt;
</span><span class="cx"> #include &lt;unistd.h&gt;
</span><span class="lines">@@ -50,18 +77,6 @@
</span><span class="cx"> static int thread_running = 0;
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-#ifdef HAVE_EDITLINE
-static char *prompt(EditLine * e)
-{
-    return prompt_str;
-}
-
-static EditLine *el;
-static History *myhistory;
-static HistEvent ev;
-
-
-
</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">@@ -89,6 +104,16 @@
</span><span class="cx">         return CC_REDISPLAY;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#ifdef HAVE_EDITLINE
+static char *prompt(EditLine * e)
+{
+    return prompt_str;
+}
+
+static EditLine *el;
+static History *myhistory;
+static HistEvent ev;
+
</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">@@ -155,8 +180,355 @@
</span><span class="cx">                 return CC_REDISPLAY;
</span><span class="cx">         }
</span><span class="cx"> }
</span><ins>+#else
+#ifdef _MSC_VER
+char history[HISTLEN][CMD_BUFLEN+1];
+int iHistory = 0;
+int iHistorySel = 0;
</ins><span class="cx"> 
</span><ins>+static int console_history (char *cmd, int direction)
+{
+        int i;
+        static int first;
+
+        if (direction == 0) {
+                first = 1;
+                if (iHistory &lt; HISTLEN) {
+                        if (iHistory &amp;&amp; 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 &lt; HISTLEN-1; i++)
+                        {
+                                strcpy(history[i], history[i+1]);
+                        }
+                        iHistorySel = iHistory;
+                        strcpy(history[iHistory++], cmd);
+                }
+        }
+        else {
+                if (!first) {
+                        iHistorySel += direction;
+                }
+                first = 0;
+                if (iHistorySel &lt; 0) {
+                        iHistorySel = 0;
+                }
+                if (iHistory &amp;&amp; iHistorySel &gt;= iHistory) {
+                        iHistorySel = iHistory-1;
+                }
+                strcpy(cmd, history[iHistorySel]);
+        }
+        return (0);
+}
+
+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, &amp;info);
+        position = info.dwCursorPosition;
+        if (iCmdCursor == 0) {
+                orgPosition = position;
+        }
+
+        if (key == PROMPT_OP) {
+                if (strlen(cmd) &lt; sizeof(prompt)) {
+                        strcpy(prompt, cmd);
+                }
+                return 0;
+        }
+
+        if (key == KEY_TAB) {
+                esl_console_complete(cmd, cmd+iCmdBuffer);
+                return 0;
+        }
+        if (key == KEY_UP || key == KEY_DOWN || key == CLEAR_OP) {
+                SetConsoleCursorPosition(hOut, orgPosition);
+                for (i = 0; i &lt; (int)strlen(cmd); i++) {
+                        printf(&quot; &quot;);
+                }
+                SetConsoleCursorPosition(hOut, orgPosition);
+                iCmdBuffer = 0;
+                iCmdCursor = 0;
+                memset(cmd, 0, CMD_BUFLEN);
+        }
+        if (key == DELETE_REFRESH_OP) {
+                int l = len &lt; (int)strlen(cmd) ? len : (int)strlen(cmd);
+                for (i = 0; i &lt; l; i++) {
+                        cmd[--iCmdBuffer] = 0;
+                }
+                iCmdCursor = (int)strlen(cmd);
+                printf(&quot;%s&quot;, prompt);
+                GetConsoleScreenBufferInfo(hOut, &amp;info);
+                orgPosition = info.dwCursorPosition;
+                printf(&quot;%s&quot;, 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 &lt; (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 &lt; len; iBuf++) {
+                switch (addchars[iBuf]) {
+                        case '\r':
+                        case '\n':
+                                if (ignoreNext) {
+                                        ignoreNext = 0;
+                                }
+                                else {
+                                        int ret = iCmdBuffer;
+                                        if (iCmdBuffer == 0) {
+                                                strcpy(cmd, &quot;Empty&quot;);
+                                                ret = (int)strlen(cmd);
+                                        }
+                                        else {
+                                                console_history(cmd, 0);
+                                                cmd[iCmdBuffer] = 0;
+                                        }
+                                        iCmdBuffer = 0;
+                                        iCmdCursor = 0;
+                                        printf(&quot;\n&quot;);
+                                        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(&quot; &quot;);
+                                        if (iCmdCursor &lt; iCmdBuffer) {
+                                                        int pos;
+                                                        iCmdCursor--;
+                                                        for (pos = iCmdCursor; pos &lt; iCmdBuffer; pos++) {
+                                                                cmd[pos] = cmd[pos+1];
+                                                        }
+                                                        cmd[pos] = 0;
+                                                        iCmdBuffer--;
+
+                                                        SetConsoleCursorPosition(hOut, position);
+                                                        for (pos = iCmdCursor; pos &lt; iCmdBuffer; pos++) {
+                                                                printf(&quot;%c&quot;, cmd[pos]);
+                                                        }
+                                                        printf(&quot; &quot;);
+                                                        SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        else {
+                                                SetConsoleCursorPosition(hOut, position);
+                                                iCmdBuffer--;
+                                                iCmdCursor--;
+                                                cmd[iCmdBuffer] = 0;
+                                        }
+                                }
+                                break;
+                        default:
+                                if (!ignoreNext) {
+                                        if (iCmdCursor &lt; 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 &gt;= iCmdCursor; pos--) {
+                                                                cmd[pos+1] = cmd[pos];
+                                                        }
+                                                }
+                                                iCmdBuffer++;
+                                                cmd[iCmdCursor++] = addchars[iBuf];
+                                                printf(&quot;%c&quot;, addchars[iBuf]);
+                                                for (pos = iCmdCursor; pos &lt; iCmdBuffer; pos++) {
+                                                        GetConsoleScreenBufferInfo(hOut, &amp;info);
+                                                        if (info.dwCursorPosition.X == info.dwSize.X-1 &amp;&amp; info.dwCursorPosition.Y == info.dwSize.Y-1) {
+                                                                orgPosition.Y -= 1;
+                                                                position.Y -= 1;
+                                                        }
+                                                        printf(&quot;%c&quot;, cmd[pos]);
+                                                }
+                                                SetConsoleCursorPosition(hOut, position);
+                                        }
+                                        else {
+                                                if (position.X == info.dwSize.X-1 &amp;&amp; position.Y == info.dwSize.Y-1) {
+                                                        orgPosition.Y -= 1;
+                                                }
+                                                cmd[iCmdBuffer++] = addchars[iBuf];
+                                                iCmdCursor++;
+                                                printf(&quot;%c&quot;, addchars[iBuf]);
+                                        }
+                                }
+                }
+                if (iCmdBuffer == CMD_BUFLEN) {
+                        printf(&quot;Read Console... BUFFER OVERRUN\n&quot;);
+                        iCmdBuffer = 0;
+                        ignoreNext = 1;
+                }
+    }
+    return (0);
+}
+
+
+static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int *key)
+{
+    DWORD recordIndex, bufferIndex, toRead, red;
+    PINPUT_RECORD pInput;
+
+    GetNumberOfConsoleInputEvents(conIn, &amp;toRead);
+        if (len &lt; (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, &amp;red);
+
+    for (recordIndex = bufferIndex = 0; recordIndex &lt; red; recordIndex++) {
+        KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
+            if (pInput[recordIndex].EventType == KEY_EVENT &amp;&amp; keyEvent.bKeyDown) {
+                        if (keyEvent.wVirtualKeyCode == 38 &amp;&amp; keyEvent.wVirtualScanCode == 72) {
+                                buf[0] = 0;
+                                console_history(buf, -1);
+                                *key = KEY_UP;
+                                bufferIndex += (DWORD)strlen(buf);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 40 &amp;&amp; keyEvent.wVirtualScanCode == 80) {
+                                buf[0] = 0;
+                                console_history(buf, 1);
+                                *key = KEY_DOWN;
+                                bufferIndex += (DWORD)strlen(buf);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 112 &amp;&amp; keyEvent.wVirtualScanCode == 59) {
+                                console_fnkey_pressed(1);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 113 &amp;&amp; keyEvent.wVirtualScanCode == 60) {
+                                console_fnkey_pressed(2);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 114 &amp;&amp; keyEvent.wVirtualScanCode == 61) {
+                                console_fnkey_pressed(3);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 115 &amp;&amp; keyEvent.wVirtualScanCode == 62) {
+                                console_fnkey_pressed(4);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 116 &amp;&amp; keyEvent.wVirtualScanCode == 63) {
+                                console_fnkey_pressed(5);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 117 &amp;&amp; keyEvent.wVirtualScanCode == 64) {
+                                console_fnkey_pressed(6);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 118 &amp;&amp; keyEvent.wVirtualScanCode == 65) {
+                                console_fnkey_pressed(7);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 119 &amp;&amp; keyEvent.wVirtualScanCode == 66) {
+                                console_fnkey_pressed(8);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 120 &amp;&amp; keyEvent.wVirtualScanCode == 67) {
+                                console_fnkey_pressed(9);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 121 &amp;&amp; keyEvent.wVirtualScanCode == 68) {
+                                console_fnkey_pressed(10);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 122 &amp;&amp; keyEvent.wVirtualScanCode == 87) {
+                                console_fnkey_pressed(11);
+                        }
+                        if (keyEvent.wVirtualKeyCode == 123 &amp;&amp; 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 &amp;&amp; keyEvent.wVirtualScanCode == 75) {
+                                *key = KEY_LEFT;
+                        }
+                        if (keyEvent.wVirtualKeyCode == 39 &amp;&amp; keyEvent.wVirtualScanCode == 77) {
+                                *key = KEY_RIGHT;
+                        }
+                        if (keyEvent.wVirtualKeyCode == 45 &amp;&amp; keyEvent.wVirtualScanCode == 82) {
+                                *key = KEY_INSERT;
+                        }
+                while (keyEvent.wRepeatCount &amp;&amp; keyEvent.uChar.AsciiChar) {
+                            buf[bufferIndex] = keyEvent.uChar.AsciiChar;
+                                if (buf[bufferIndex] == '\r') {
+                                    buf[bufferIndex] = '\n';
+                                }
+                            bufferIndex++;
+                            keyEvent.wRepeatCount--;
+                }
+            }
+    }
+
+    free(pInput);
+    *pRed = bufferIndex;
+    return (TRUE);
+}
</ins><span class="cx"> #endif
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx"> static void handle_SIGINT(int sig)
</span><span class="cx"> {
</span><span class="lines">@@ -356,10 +728,11 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #ifndef HAVE_EDITLINE
</span><del>-static char command_buf[2048] = &quot;&quot;;
</del><ins>+static char command_buf[CMD_BUFLEN+1] = &quot;&quot;;
</ins><span class="cx"> 
</span><span class="cx"> static const char *basic_gets(int *cnt)
</span><span class="cx"> {
</span><ins>+#ifndef _MSC_VER
</ins><span class="cx">         int x = 0;
</span><span class="cx"> 
</span><span class="cx">         printf(&quot;%s&quot;, prompt_str);
</span><span class="lines">@@ -382,9 +755,29 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         *cnt = x;
</span><ins>+#else
+        int read, key;
+        char keys[80];
+        HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
</ins><span class="cx"> 
</span><ins>+        console_bufferInput (0, 0, prompt_str, PROMPT_OP);
+        printf(&quot;%s&quot;, prompt_str);
+
+        *cnt = 0;
+        memset(&amp;command_buf, 0, sizeof(command_buf));
+
+        while (!*cnt) {
+                if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &amp;read, &amp;key)) {
+                        *cnt = console_bufferInput(keys, read, command_buf, key);
+                        if (!strcmp(command_buf, &quot;Empty&quot;)) {
+                                command_buf[0] = 0;
+                        }
+                }
+                Sleep(20);
+        }
+
</ins><span class="cx">         return command_buf;
</span><del>-
</del><ins>+#endif
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -427,22 +820,19 @@
</span><span class="cx">         profile-&gt;console_fnkeys[11] = &quot;version&quot;;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
-#ifdef HAVE_EDITLINE
</del><span class="cx"> #define end_of_p(_s) (*_s == '\0' ? _s : _s + strlen(_s) - 1)
</span><span class="cx"> 
</span><del>-static unsigned char complete(EditLine * el, int ch)
</del><ins>+static unsigned char esl_console_complete(const char *buffer, const char *cursor)
</ins><span class="cx"> {
</span><del>-        const LineInfo *lf = el_line(el);
</del><span class="cx">         char cmd_str[2048] = &quot;&quot;;
</span><span class="cx">         unsigned char ret = CC_REDISPLAY;
</span><del>-        char *dup = strdup(lf-&gt;buffer);
</del><ins>+        char *dup = strdup(buffer);
</ins><span class="cx">         char *buf = dup;
</span><span class="cx">         int pos = 0, sc = 0;
</span><span class="cx">         char *p;
</span><span class="cx"> 
</span><del>-        if (!esl_strlen_zero(lf-&gt;cursor) &amp;&amp; !esl_strlen_zero(lf-&gt;buffer)) {
-                pos = (lf-&gt;cursor - lf-&gt;buffer);
</del><ins>+        if (!esl_strlen_zero(cursor) &amp;&amp; !esl_strlen_zero(buffer)) {
+                pos = (int)(cursor - buffer);
</ins><span class="cx">         }
</span><span class="cx">         if (pos &gt; 0) {
</span><span class="cx">                 *(buf + pos) = '\0';
</span><span class="lines">@@ -456,10 +846,12 @@
</span><span class="cx">                 buf++;
</span><span class="cx">                 sc++;
</span><span class="cx">         }
</span><del>-        
</del><ins>+
+#ifdef HAVE_EDITLINE
</ins><span class="cx">         if (!*buf &amp;&amp; sc) {
</span><span class="cx">                 el_deletestr(el, sc);
</span><span class="cx">         }
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">         sc = 0;
</span><span class="cx"> 
</span><span class="lines">@@ -469,14 +861,15 @@
</span><span class="cx">                 p--;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+#ifdef HAVE_EDITLINE
</ins><span class="cx">         if (sc &gt; 1) {
</span><span class="cx">                 el_deletestr(el, sc - 1);
</span><span class="cx">                 *(p + 2) = '\0';
</span><span class="cx">         }
</span><del>-
</del><ins>+#endif
</ins><span class="cx">         
</span><span class="cx"> 
</span><del>-        if (*lf-&gt;cursor) {
</del><ins>+        if (*cursor) {
</ins><span class="cx">                 snprintf(cmd_str, sizeof(cmd_str), &quot;api console_complete c=%ld;%s\n\n&quot;, (long)pos, buf);
</span><span class="cx">         } else {
</span><span class="cx">                 snprintf(cmd_str, sizeof(cmd_str), &quot;api console_complete %s\n\n&quot;, buf);
</span><span class="lines">@@ -503,11 +896,21 @@
</span><span class="cx">                                 
</span><span class="cx">                                 printf(&quot;%s\n\n\n&quot;, r);
</span><span class="cx"> 
</span><ins>+#ifdef HAVE_EDITLINE
</ins><span class="cx">                                 el_deletestr(el, len);
</span><span class="cx">                                 el_insertstr(el, w);
</span><ins>+#else
+#ifdef _MSC_VER
+                                console_bufferInput(0, len, (char*)buffer, DELETE_REFRESH_OP);
+                                console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
+#endif
+#endif
</ins><span class="cx">                                 
</span><span class="cx">                         } else {
</span><span class="cx">                                 printf(&quot;%s\n&quot;, r);
</span><ins>+#ifdef _MSC_VER
+                                console_bufferInput(0, 0, (char*)buffer, DELETE_REFRESH_OP);
+#endif
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -518,6 +921,14 @@
</span><span class="cx"> 
</span><span class="cx">         return ret;
</span><span class="cx"> }
</span><ins>+
+#ifdef HAVE_EDITLINE
+static unsigned char complete(EditLine * el, int ch)
+{
+        const LineInfo *lf = el_line(el);
+
+        return esl_console_complete(lf-&gt;buffer, lf-&gt;cursor);
+}
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_consolec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_console.c (16009 => 16010)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_console.c        2009-12-21 16:15:49 UTC (rev 16009)
+++ freeswitch/trunk/src/switch_console.c        2009-12-21 17:39:05 UTC (rev 16010)
</span><span class="lines">@@ -1123,7 +1123,10 @@
</span><span class="cx">                         cmd[--iCmdBuffer] = 0;
</span><span class="cx">                 }
</span><span class="cx">                 iCmdCursor = (int)strlen(cmd);
</span><del>-                printf(&quot;%s%s&quot;, prompt, cmd);
</del><ins>+                printf(&quot;%s&quot;, prompt);
+                GetConsoleScreenBufferInfo(hOut, &amp;info);
+                orgPosition = info.dwCursorPosition;
+                printf(&quot;%s&quot;, cmd);
</ins><span class="cx">                 return 0;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>