mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
new history implementation, not complete yet...
svn path=/trunk/; revision=833
This commit is contained in:
parent
9530a7d656
commit
f30ade19b8
5 changed files with 245 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: cmd.c,v 1.14 1999/11/04 11:29:36 ekohl Exp $
|
||||
/* $Id: cmd.c,v 1.15 1999/12/06 19:26:49 paolopan Exp $
|
||||
*
|
||||
* CMD.C - command-line interface.
|
||||
*
|
||||
|
@ -142,9 +142,6 @@ WORD wDefColor = FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; /* default
|
|||
#endif
|
||||
|
||||
|
||||
extern COMMAND cmds[]; /* The internal command table */
|
||||
|
||||
|
||||
/*
|
||||
* is character a delimeter when used on first word?
|
||||
*
|
||||
|
@ -1026,6 +1023,11 @@ Initialize (int argc, char *argv[])
|
|||
InitDirectoryStack ();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FEATURE_HISTORY
|
||||
InitHistory();
|
||||
#endif
|
||||
|
||||
/* Set COMSPEC environment variable */
|
||||
#ifndef __REACTOS__
|
||||
if (argv)
|
||||
|
|
|
@ -129,6 +129,8 @@ typedef struct tagCOMMAND
|
|||
INT (*func) (LPTSTR, LPTSTR);
|
||||
} COMMAND, *LPCOMMAND;
|
||||
|
||||
extern COMMAND cmds[]; /* The internal command table */
|
||||
|
||||
|
||||
/* Prototypes for COLOR.C */
|
||||
VOID SetScreenColor(WORD wArgColor, BOOL bFill);
|
||||
|
@ -244,6 +246,8 @@ INT cmd_goto (LPTSTR, LPTSTR);
|
|||
/* Prototypes for HISTORY.C */
|
||||
#ifdef FEATURE_HISTORY
|
||||
VOID History (INT, LPTSTR);
|
||||
VOID History_move_to_bottom(VOID);
|
||||
VOID InitHistory(VOID);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -104,7 +104,6 @@
|
|||
#include "batch.h"
|
||||
|
||||
|
||||
|
||||
SHORT maxx;
|
||||
SHORT maxy;
|
||||
|
||||
|
@ -237,11 +236,11 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
|||
case VK_TAB:
|
||||
#ifdef FEATURE_UNIX_FILENAME_COMPLETION
|
||||
/* expand current file name */
|
||||
if (current == charcount) // only works at end of line
|
||||
if (current == charcount) /* only works at end of line*/
|
||||
{
|
||||
if (wLastKey != VK_TAB)
|
||||
{
|
||||
// if first TAB, complete filename
|
||||
/* if first TAB, complete filename*/
|
||||
CompleteFilename (str, charcount);
|
||||
charcount = _tcslen (str);
|
||||
current = charcount;
|
||||
|
@ -253,13 +252,14 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
|||
}
|
||||
else
|
||||
{
|
||||
//if second TAB, list matches
|
||||
/*if second TAB, list matches*/
|
||||
if (ShowCompletionMatches (str, charcount))
|
||||
{
|
||||
PrintPrompt ();
|
||||
GetCursorXY (&orgx, &orgy);
|
||||
ConOutPrintf (_T("%s"), str);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -302,9 +302,10 @@ VOID ReadCommand (LPTSTR str, INT maxlen)
|
|||
ClearCommandLine (str, maxlen, orgx, orgy);
|
||||
current = charcount = 0;
|
||||
break;
|
||||
case VK_F3:
|
||||
case VK_UP:
|
||||
#ifdef FEATURE_HISTORY
|
||||
case VK_F3:
|
||||
History_move_to_bottom();
|
||||
case VK_UP:
|
||||
/* get previous command from buffer */
|
||||
ClearCommandLine (str, maxlen, orgx, orgy);
|
||||
History (-1, str);
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
/* Define to enable history */
|
||||
#define FEATURE_HISTORY
|
||||
|
||||
/*Define to enable history wrap (4nt's style)*/
|
||||
#define WRAP_HISTORY
|
||||
|
||||
|
||||
/* Define one of these to enable filename completion */
|
||||
#define FEATURE_UNIX_FILENAME_COMPLETION
|
||||
|
|
|
@ -17,10 +17,30 @@
|
|||
* 25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
||||
* Cleanup!
|
||||
* Unicode and redirection safe!
|
||||
*
|
||||
* 25-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
||||
* Added lots of comments (beginning studying the source)
|
||||
* Added command.com's F3 support (see cmdinput.c)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* HISTORY.C - command line history. Second version
|
||||
*
|
||||
*
|
||||
* History:
|
||||
*
|
||||
* 06/12/99 (Paolo Pantaleo <paolopan@freemail.it>)
|
||||
* started.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#ifdef FEATURE_HISTORY
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -30,21 +50,210 @@
|
|||
|
||||
#include "cmd.h"
|
||||
|
||||
#define MAXLINES 128
|
||||
|
||||
static INT history_size = 2048; /* make this configurable later */
|
||||
typedef struct tagHISTORY
|
||||
{
|
||||
struct tagHISTORY *prev;
|
||||
struct tagHISTORY *next;
|
||||
LPTSTR string;
|
||||
} HIST_ENTRY, * LPHIST_ENTRY;
|
||||
|
||||
static INT size,
|
||||
max_size=10;
|
||||
/*for now not configurable*/
|
||||
|
||||
|
||||
static LPHIST_ENTRY Top;
|
||||
static LPHIST_ENTRY Bottom;
|
||||
|
||||
|
||||
static LPHIST_ENTRY curr_ptr=0;
|
||||
|
||||
|
||||
VOID InitHistory(VOID)
|
||||
{
|
||||
size=0;
|
||||
|
||||
|
||||
Top = malloc(sizeof(HIST_ENTRY));
|
||||
Bottom = malloc(sizeof(HIST_ENTRY));
|
||||
|
||||
|
||||
|
||||
Top->prev = Bottom;
|
||||
Top->next = NULL;
|
||||
Top->string = NULL;
|
||||
|
||||
|
||||
Bottom->prev = NULL;
|
||||
Bottom->next = Top;
|
||||
Bottom->string = NULL;
|
||||
|
||||
curr_ptr=Bottom;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static
|
||||
VOID del(LPHIST_ENTRY item)
|
||||
{
|
||||
|
||||
if(item==NULL)
|
||||
return;
|
||||
|
||||
|
||||
/*set links in prev and next item*/
|
||||
item->next->prev=item->prev;
|
||||
item->prev->next=item->next;
|
||||
|
||||
|
||||
/*free mem*/
|
||||
if (item->string)
|
||||
free(item->string);
|
||||
|
||||
free(item);
|
||||
|
||||
size--;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID add_at_bottom(LPTSTR string)
|
||||
{
|
||||
{
|
||||
|
||||
LPHIST_ENTRY tmp;
|
||||
|
||||
|
||||
/*delete first entry if maximum number of entries is reached*/
|
||||
if(size==max_size)
|
||||
del(Top->prev);
|
||||
|
||||
|
||||
|
||||
/*fill bottom with string*/
|
||||
Bottom->string=malloc(_tclen(string));
|
||||
_tcscpy(Bottom->string,string);
|
||||
|
||||
/*save Bottom value*/
|
||||
tmp=Bottom;
|
||||
|
||||
|
||||
/*create new void Bottom*/
|
||||
Bottom=malloc(sizeof(HIST_ENTRY));
|
||||
Bottom->next=tmp;
|
||||
Bottom->prev=NULL;
|
||||
Bottom->string=NULL;
|
||||
|
||||
tmp->prev=Bottom;
|
||||
|
||||
/*set new size*/
|
||||
size++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID History_move_to_bottom(VOID)
|
||||
{
|
||||
curr_ptr=Bottom;
|
||||
|
||||
}
|
||||
|
||||
|
||||
VOID History (INT dir, LPTSTR commandline)
|
||||
{
|
||||
static LPTSTR history = NULL;
|
||||
static LPTSTR lines[MAXLINES];
|
||||
static INT curline = 0;
|
||||
static INT numlines = 0;
|
||||
static INT maxpos = 0;
|
||||
INT count;
|
||||
INT length;
|
||||
|
||||
if(dir==0)
|
||||
{
|
||||
add_at_bottom(commandline);
|
||||
curr_ptr=Bottom;
|
||||
return;
|
||||
}
|
||||
|
||||
if (size==0)
|
||||
{
|
||||
commandline[0]=_T('\0');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(dir<0)/*key up*/
|
||||
{
|
||||
if (curr_ptr->next==Top || curr_ptr->next==0)
|
||||
{
|
||||
#ifdef WRAP_HISTORY
|
||||
curr_ptr=Bottom;
|
||||
#else
|
||||
curr_ptr=Top;
|
||||
commandline[0]=_T('\0');
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
curr_ptr = curr_ptr->next;
|
||||
if(curr_ptr->string)
|
||||
_tcscpy(commandline,curr_ptr->string);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(dir>0)
|
||||
{
|
||||
|
||||
if (curr_ptr->prev==Bottom || curr_ptr->prev==0)
|
||||
{
|
||||
#ifdef WRAP_HISTORY
|
||||
curr_ptr=Top;
|
||||
#else
|
||||
curr_ptr=Bottom;
|
||||
commandline[0]=_T('\0');
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
curr_ptr=curr_ptr->prev;
|
||||
if(curr_ptr->string)
|
||||
_tcscpy(commandline,curr_ptr->string);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
LPTSTR history = NULL; /*buffer to sotre all the lines*/
|
||||
LPTSTR lines[MAXLINES]; /*array of pointers to each line(entry)*/
|
||||
/*located in history buffer*/
|
||||
|
||||
INT curline = 0; /*the last line recalled by user*/
|
||||
INT numlines = 0; /*number of entries, included the last*/
|
||||
/*empty one*/
|
||||
|
||||
INT maxpos = 0; /*index of last byte of last entry*/
|
||||
|
||||
|
||||
|
||||
VOID History (INT dir, LPTSTR commandline)
|
||||
{
|
||||
|
||||
INT count; /*used in for loops*/
|
||||
INT length; /*used in the same loops of count*/
|
||||
/*both to make room when is full
|
||||
either history or lines*/
|
||||
|
||||
/*first time History is called allocate mem*/
|
||||
if (!history)
|
||||
{
|
||||
history = malloc (history_size * sizeof (TCHAR));
|
||||
|
@ -111,11 +320,16 @@ VOID History (INT dir, LPTSTR commandline)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*copy entry in the history bufer*/
|
||||
_tcscpy (lines[numlines], commandline);
|
||||
numlines++;
|
||||
|
||||
/*set last lines[numlines] pointer next the end of last, valid,
|
||||
just setted entry (the two lines above)*/
|
||||
lines[numlines] = lines[numlines - 1] + _tcslen (commandline) + 1;
|
||||
maxpos += _tcslen (commandline) + 1;
|
||||
/* last line, empty */
|
||||
|
||||
curline = numlines;
|
||||
}
|
||||
|
||||
|
@ -123,3 +337,5 @@ VOID History (INT dir, LPTSTR commandline)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif //#if 0
|
Loading…
Reference in a new issue