console editing f8 command retrieval (win32 mode)

Ann and Jason Edmeades us at the-edmeades.demon.co.uk
Mon Apr 29 16:49:47 CDT 2002


One of the features I use of the command shell, which is provided
by the consol functions (as other non-command shell programs exhibit
the same behaviour) is the use of F8 to retrieve commands with the
same prefix.

I have coded something which behaves like this to update the console
editing functions, but wanted to get verification I have done the
right thing.

Specifically I am concerned about having to add another table, as
the char code for f8 is 0x00, so I cannot add it to the existing
table. Assuming it is ok, heres the patch

Changelog:

- Add f8 (histroy retrieval from partial command) support to
      console editing modes

Note: This includes my previous (small) patch relating to del,
         ctrl+right, and ctrl+end (must work out how to do
         diff better!)

Regards,
Jason

jason  @  the-edmeades.demon.co.uk

Index: editline.c
===================================================================
RCS file: /home/wine/wine/win32/editline.c,v
retrieving revision 1.6
diff -u -u -r1.6 editline.c
--- editline.c	26 Apr 2002 19:05:18 -0000	1.6
+++ editline.c	29 Apr 2002 21:48:36 -0000
@@ -19,8 +19,6 @@
  */

 #include "config.h"
-#include "wine/port.h"
-
 #include <string.h>

 #include "windef.h"
@@ -239,8 +237,8 @@
 static int WCEL_GetRightWordTransition(WCEL_Context* ctx, int ofs)
 {
     ofs++;
-    while (ofs <= ctx->len && !WCEL_iswalnum(ctx->line[ofs])) ofs++;
     while (ofs <= ctx->len && WCEL_iswalnum(ctx->line[ofs])) ofs++;
+    while (ofs <= ctx->len && !WCEL_iswalnum(ctx->line[ofs])) ofs++;
     return min(ofs, ctx->len);
 }

@@ -296,6 +294,46 @@
     }
 }

+static void    WCEL_FindPrevInHist(WCEL_Context* ctx)
+{
+    int startPos = ctx->histPos;
+    WCHAR*	data;
+    int		len, oldofs;
+
+    if (ctx->histPos && ctx->histPos == ctx->histSize) {
+        startPos--;
+        ctx->histPos--;
+    }
+
+    do {
+       data = WCEL_GetHistory(ctx, ctx->histPos);
+
+       if (ctx->histPos) ctx->histPos--;
+       else ctx->histPos = (ctx->histSize-1);
+
+       len = lstrlenW(data) + 1;
+       if ((len >= ctx->ofs) &&
+           (memcmp(ctx->line, data, ctx->ofs * sizeof(WCHAR)) == 0)) {
+
+           /* need to clean also the screen if new string is shorter than
old one */
+           WCEL_DeleteString(ctx, 0, ctx->len);
+
+           if (WCEL_Grow(ctx, len))
+           {
+              oldofs = ctx->ofs;
+              ctx->ofs = 0;
+              WCEL_InsertString(ctx, data);
+              ctx->ofs = oldofs;
+              SetConsoleCursorPosition(ctx->hConOut, WCEL_GetCoord(ctx,
ctx->ofs));
+              HeapFree(GetProcessHeap(), 0, data);
+              return;
+           }
+       }
+    } while (ctx->histPos != startPos);
+
+    return;
+}
+
 /* ====================================================================
  *
  * basic edition functions
@@ -537,6 +575,13 @@
     {	0,		NULL			}
 };

+static KeyEntry Win32ExtraStdKeyMap[] =
+{
+    {/*VK_F8*/   0x77,	WCEL_FindPrevInHist	},
+    {	0,		NULL			}
+};
+
+
 static	KeyEntry EmacsKeyMapCtrl[] =
 {
     {	CTRL('@'),	WCEL_SetMark		},
@@ -617,6 +662,7 @@
     {/*VK_END*/  0x23,	WCEL_MoveToEnd 		},
     {/*VK_UP*/   0x26, 	WCEL_MoveToPrevHist 	},
     {/*VK_DOWN*/ 0x28,	WCEL_MoveToNextHist	},
+    {/*VK_DEL*/  0x2e,	WCEL_FindPrevInHist /*L_DeleteCurrChar*/	},
     {	0,		NULL 			}
 };

@@ -624,12 +670,14 @@
 {
     {/*VK_LEFT*/ 0x25, 	WCEL_MoveToLeftWord 	},
     {/*VK_RIGHT*/0x27,	WCEL_MoveToRightWord	},
+    {/*VK_END*/  0x23,	WCEL_KillToEndOfLine	},
     {	0,		NULL 			}
 };

 KeyMap	Win32KeyMap[] =
 {
     {0x00000000, 1, StdKeyMap},
+    {0x00000000, 0, Win32ExtraStdKeyMap},
     {0x00000100, 0, Win32KeyMapExtended},
     {0x00000104, 0, Win32KeyMapCtrlExtended},
     {0x00000108, 0, Win32KeyMapCtrlExtended},

-------------- next part --------------
A non-text attachment was scrubbed...
Name: console-edit2.patch.6
Type: application/octet-stream
Size: 2950 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20020429/bb39979e/console-edit2.patch.obj


More information about the wine-patches mailing list