Small fix for the patch special char patch earlier.
[reactos.git] / reactos / subsys / system / cmd / cmdinput.c
index ca704ad..2bb36e3 100644 (file)
@@ -97,7 +97,8 @@
  *        Fixed problems when the screen was scrolled away.
  */
 
-#include "precomp.h"
+#include <precomp.h>
+#include "resource.h"
 
 
 SHORT maxx;
@@ -137,6 +138,9 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
        WORD   wLastKey = 0;
        TCHAR  ch;
        BOOL bContinue=FALSE;/*is TRUE the second case will not be executed*/
+    BOOL bReturn = FALSE;
+       TCHAR szPath[MAX_PATH];
+    BOOL bCharInput;
 
        /* get screen size */
        GetScreenSize (&maxx, &maxy);
@@ -154,6 +158,9 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
 
        do
        {
+    
+        bReturn = FALSE;
+        
                ConInKey (&ir);
 
                if (ir.Event.KeyEvent.dwControlKeyState &
@@ -165,13 +172,13 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                        {
 
 #ifdef FEATURE_HISTORY
-       
+
                                case 'K':
                                        /*add the current command line to the history*/
                                        if (ir.Event.KeyEvent.dwControlKeyState &
                                                (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
                                        {
-                               
+
                                                if (str[0])
                                                        History(0,str);
 
@@ -189,7 +196,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                                                (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
                                        {
                                                ClearCommandLine (str, maxlen, orgx, orgy);
-                                               History_del_current_entry(str);                                 
+                                               History_del_current_entry(str);
                                                current = charcount = _tcslen (str);
                                                ConOutPrintf (_T("%s"), str);
                                                GetCursorXY (&curx, &cury);
@@ -201,7 +208,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                        }
 
 
-                       
+
 
                }
 
@@ -209,6 +216,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                //      continue;
 
 
+        bCharInput = FALSE;
 
                switch (ir.Event.KeyEvent.wVirtualKeyCode)
                {
@@ -314,10 +322,6 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                                                charcount = _tcslen (str);
                                                current = charcount;
 
-                                               if (current > 0 &&
-                                                   str[current-1] == _T('"'))
-                                                       current--;
-
                                                SetCursorXY (orgx, orgy);
                                                ConOutPrintf (_T("%s"), str);
 
@@ -353,33 +357,71 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                                                                     orgy + (orgx + current) / maxx);
                                                        GetCursorXY (&curx, &cury);
                                                }
-                                               
+
                                        }
                                }
                                else
                                {
-#ifdef __REACTOS__
-                                       Beep (440, 50);
-#else
                                        MessageBeep (-1);
-#endif
                                }
 #endif
 #ifdef FEATURE_4NT_FILENAME_COMPLETION
-                               /* this is not implemented yet */
-                               if (ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED)
-                               {
-                                       /* get previous match */
+                               
+                               /* used to later see if we went down to the next line */
+                               tempscreen = charcount;
+                               szPath[0]=_T('\0');
+
+                               /* str is the whole things that is on the current line 
+                                  that is and and out.  arg 2 is weather it goes back
+                                       one file or forward one file */
+                               CompleteFilename(str, !(ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED), szPath, current);
+                               /* Attempt to clear the line */
+                               ClearCommandLine (str, maxlen, orgx, orgy);
+                               curx = orgx;
+                               cury = orgy;
+                               current = charcount = 0;                                
+        //str[0]=_T('\0');
+                               
+                               /* Everything is deleted, lets add it back in */
+                               _tcscpy(str,szPath);
+        
+                               /* Figure out where cusor is going to be after we print it */
+                               charcount = _tcslen (str);
+                               current = charcount;
+
+                               SetCursorXY (orgx, orgy);
+                               /* Print out what we have now */
+                               ConOutPrintf (_T("%s"), str);
 
+                               /* Move cursor accordingly */
+                               if(tempscreen > charcount)
+                               {
+                                       GetCursorXY (&curx, &cury);
+                                       for(count = tempscreen - charcount; count--; )
+                                               ConOutChar (_T(' '));
+                                       SetCursorXY (curx, cury);
                                }
                                else
                                {
-                                       /* get next match */
-
+                                       if(((charcount + orgx) / maxx) + orgy > maxy - 1)
+                                               orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
                                }
+                               SetCursorXY((short)(((int)orgx + current) % maxx), (short)((int)orgy + ((int)orgx + current) / maxx));
+                               GetCursorXY(&curx, &cury);
+
 #endif
                                break;
-
+            
+            case _T('M'):
+            case _T('C'):
+                /* ^M does the same as return */
+                bCharInput = TRUE;
+                if(!(ir.Event.KeyEvent.dwControlKeyState &
+                   (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)))
+                {
+                    break;
+                }
+                    
                        case VK_RETURN:
                                /* end input, return to main */
 #ifdef FEATURE_HISTORY
@@ -389,6 +431,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
 #endif
                                ConInDummy ();
                                ConOutChar (_T('\n'));
+                bReturn = TRUE;
                                break;
 
                        case VK_ESCAPE:
@@ -448,11 +491,7 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                                }
                                else
                                {
-#ifdef __REACTOS__
-                                       Beep (440, 50);
-#else
                                        MessageBeep (-1);
-#endif
                                }
                                break;
 
@@ -475,69 +514,61 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
                                }
                                break;
 
-                       default:
+            default:
+                /* This input is just a normal char */
+                bCharInput = TRUE;
+
+                       }
 #ifdef _UNICODE
-                               ch = ir.Event.KeyEvent.uChar.UnicodeChar;
-                               if ((ch >= 32 && ch <= 255) && (charcount != (maxlen - 2)))
+            ch = ir.Event.KeyEvent.uChar.UnicodeChar;
+            if ((ch >= 32 && (charcount != (maxlen - 2)) && bCharInput)
 #else
-                               ch = ir.Event.KeyEvent.uChar.AsciiChar;
-                               if ((UCHAR)ch >= 32 && (charcount != (maxlen - 2)))
+            ch = ir.Event.KeyEvent.uChar.AsciiChar;
+            if ((UCHAR)ch >= 32 && (charcount != (maxlen - 2)) && bCharInput)
 #endif /* _UNICODE */
-                               {
-                                       /* insert character into string... */
-                                       if (bInsert && current != charcount)
-                                       {
-                                               /* If this character insertion will cause screen scrolling,
-                                                * adjust the saved origin of the command prompt. */
-                                               tempscreen = _tcslen(str + current) + curx;
-                                               if ((tempscreen % maxx) == (maxx - 1) &&
-                                                   (tempscreen / maxx) + cury == (maxy - 1))
-                                               {
-                                                       orgy--;
-                                                       cury--;
-                                               }
-
-                                               for (count = charcount; count > current; count--)
-                                                       str[count] = str[count - 1];
-                                               str[current++] = ch;
-                                               if (curx == maxx - 1)
-                                                       curx = 0, cury++;
-                                               else
-                                                       curx++;
-                                               ConOutPrintf (_T("%s"), &str[current - 1]);
-                                               SetCursorXY (curx, cury);
-                                               charcount++;
-                                       }
-                                       else
-                                       {
-                                               if (current == charcount)
-                                                       charcount++;
-                                               str[current++] = ch;
-                                               if (GetCursorX () == maxx - 1 && GetCursorY () == maxy - 1)
-                                                       orgy--, cury--;
-                                               if (GetCursorX () == maxx - 1)
-                                                       curx = 0, cury++;
-                                               else
-                                                       curx++;
-                                               ConOutChar (ch);
-                                       }
-                               }
-#if 0
-                               else
-                               {
-#ifdef __REACTOS__
-                                       Beep (440, 100);
-#else
-                                       MessageBeep (-1);
-#endif
-                               }
-#endif
-                               break;
-
-               }
+            {
+                /* insert character into string... */
+                if (bInsert && current != charcount)
+                {
+                        /* If this character insertion will cause screen scrolling,
+                                                                 * adjust the saved origin of the command prompt. */
+                        tempscreen = _tcslen(str + current) + curx;
+                    if ((tempscreen % maxx) == (maxx - 1) &&
+                        (tempscreen / maxx) + cury == (maxy - 1))
+                    {
+                        orgy--;
+                        cury--;
+                    }
+
+                    for (count = charcount; count > current; count--)
+                        str[count] = str[count - 1];
+                    str[current++] = ch;
+                    if (curx == maxx - 1)
+                        curx = 0, cury++;
+                    else
+                        curx++;
+                    ConOutPrintf (_T("%s"), &str[current - 1]);
+                    SetCursorXY (curx, cury);
+                    charcount++;
+                }
+                else
+                {
+                    if (current == charcount)
+                        charcount++;
+                    str[current++] = ch;
+                    if (GetCursorX () == maxx - 1 && GetCursorY () == maxy - 1)
+                        orgy--, cury--;
+                    if (GetCursorX () == maxx - 1)
+                        curx = 0, cury++;
+                    else
+                        curx++;
+                    ConOutChar (ch);
+                }
+            }
+               
                wLastKey = ir.Event.KeyEvent.wVirtualKeyCode;
        }
-       while (ir.Event.KeyEvent.wVirtualKeyCode != VK_RETURN);
+       while (!bReturn);
 
        SetCursorType (bInsert, TRUE);
 }