ReactOS  0.4.14-dev-583-g2a1ba2c
history.c File Reference
#include "precomp.h"
Include dependency graph for history.c:

Go to the source code of this file.

Classes

struct  tagHISTORY
 

Typedefs

typedef struct tagHISTORY HIST_ENTRY
 
typedef struct tagHISTORYLPHIST_ENTRY
 

Functions

VOID InitHistory (VOID)
 
VOID History_move_to_bottom (VOID)
 
VOID History (INT dir, LPTSTR commandline)
 
VOID CleanHistory (VOID)
 
VOID History_del_current_entry (LPTSTR str)
 
static VOID del (LPHIST_ENTRY item)
 
static VOID add_at_bottom (LPTSTR string)
 
VOID set_size (INT new_size)
 
INT CommandHistory (LPTSTR param)
 
LPCTSTR PeekHistory (INT dir)
 

Variables

static INT size
 
static INT max_size = 100
 
static LPHIST_ENTRY Top = NULL
 
static LPHIST_ENTRY Bottom = NULL
 
static LPHIST_ENTRY curr_ptr = NULL
 

Typedef Documentation

◆ HIST_ENTRY

◆ LPHIST_ENTRY

Function Documentation

◆ add_at_bottom()

static VOID add_at_bottom ( LPTSTR  string)
static

Definition at line 225 of file history.c.

226 {
227  LPHIST_ENTRY tmp;
228 
229  ASSERT(Top && Bottom);
230 
231  /*delete first entry if maximum number of entries is reached*/
232  while (size>=max_size)
233  del(Top->prev);
234 
235  while (_istspace(*string))
236  string++;
237 
238  if (*string==_T('\0'))
239  return;
240 
241  /*if new entry is the same than the last do not add it*/
242  if (size)
243  {
244  if (_tcscmp(string,Bottom->next->string)==0)
245  return;
246  }
247 
248  /*create new empty Bottom*/
249  tmp = cmd_alloc(sizeof(HIST_ENTRY));
250  if (!tmp)
251  {
252  WARN("Cannot allocate memory for new Bottom!\n");
253  return;
254  }
255 
256  /*fill old bottom with string, it will become new Bottom->next*/
257  Bottom->string = cmd_alloc((_tcslen(string)+1)*sizeof(TCHAR));
258  if (!Bottom->string)
259  {
260  WARN("Cannot allocate memory for Bottom->string!\n");
261  cmd_free(tmp);
262  return;
263  }
264  _tcscpy(Bottom->string,string);
265 
266  tmp->next = Bottom;
267  tmp->prev = NULL;
268  tmp->string = NULL;
269 
270  Bottom->prev = tmp;
271 
272  /*save the new Bottom value*/
273  Bottom = tmp;
274 
275  /*set new size*/
276  size++;
277 }
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
struct tagHISTORY * next
Definition: history.c:47
#define WARN(fmt,...)
Definition: debug.h:111
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
static INT max_size
Definition: history.c:51
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLsizeiptr size
Definition: glext.h:5919
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define cmd_alloc(size)
Definition: cmddbg.h:29
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
#define cmd_free(ptr)
Definition: cmddbg.h:31
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
#define _istspace
Definition: tchar.h:1504
LPTSTR string
Definition: history.c:48
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by History().

◆ CleanHistory()

VOID CleanHistory ( VOID  )

Definition at line 163 of file history.c.

164 {
165  ASSERT(Top && Bottom);
166 
167  while (Bottom->next != Top)
168  del(Bottom->next);
169 
170  cmd_free(Top);
171  cmd_free(Bottom);
172 }
struct tagHISTORY * next
Definition: history.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
#define cmd_free(ptr)
Definition: cmddbg.h:31
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by Cleanup(), and CommandHistory().

◆ CommandHistory()

INT CommandHistory ( LPTSTR  param)

Definition at line 71 of file history.c.

72 {
73  LPTSTR tmp;
74  INT tmp_int;
75  LPHIST_ENTRY h_tmp;
76  TCHAR szBuffer[2048];
77 
78  tmp=_tcschr(param,_T('/'));
79 
80  if (tmp)
81  {
82  param=tmp;
83  switch (_totupper(param[1]))
84  {
85  case _T('F'):/*delete history*/
87  break;
88 
89  case _T('R'):/*read history from standard in*/
90  for(;;)
91  {
92  ConInString(szBuffer,sizeof(szBuffer)/sizeof(TCHAR));
93  if (*szBuffer!=_T('\0'))
94  History(0,szBuffer);
95  else
96  break;
97  }
98  break;
99 
100  case _T('A'):/*add an antry*/
101  History(0,param+2);
102  break;
103 
104  case _T('S'):/*set history size*/
105  if ((tmp_int=_ttoi(param+2)))
106  set_size(tmp_int);
107  break;
108 
109  default:
110  return 1;
111  }
112  }
113  else
114  {
115  for (h_tmp = Top->prev; h_tmp != Bottom; h_tmp = h_tmp->prev)
116  ConErrPuts(h_tmp->string);
117  }
118  return 0;
119 }
VOID set_size(INT new_size)
Definition: history.c:121
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
VOID InitHistory(VOID)
Definition: history.c:132
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
if(!(yy_init))
Definition: macro.lex.yy.c:714
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
GLfloat param
Definition: glext.h:5796
VOID ConErrPuts(LPTSTR szText)
Definition: tee.c:59
#define for
Definition: utility.h:88
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
int CDECL _ttoi(const _TCHAR *str)
Definition: atoi.c:10
VOID CleanHistory(VOID)
Definition: history.c:163
LPTSTR string
Definition: history.c:48
static LPHIST_ENTRY Top
Definition: history.c:53

◆ del()

static VOID del ( LPHIST_ENTRY  item)
static

Definition at line 199 of file history.c.

200 {
201  ASSERT(Top && Bottom);
202 
203  if (item==NULL || item==Top || item==Bottom)
204  {
205  TRACE ("del in " __FILE__ ": returning\n"
206  "item is 0x%08x (Bottom is0x%08x)\n",
207  item, Bottom);
208  return;
209  }
210 
211  /*free string's mem*/
212  if (item->string)
213  cmd_free(item->string);
214 
215  /*set links in prev and next item*/
216  item->next->prev=item->prev;
217  item->prev->next=item->next;
218 
219  cmd_free(item);
220 
221  size--;
222 }
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define cmd_free(ptr)
Definition: cmddbg.h:31
static ATOM item
Definition: dde.c:856
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by add_at_bottom(), CleanHistory(), find_prop_name_prot(), History_del_current_entry(), inf_value_parse(), ReceiveLine(), RtlSplayTreeTest(), set_size(), setValue(), and test_SetupDiInstallClassExA().

◆ History()

VOID History ( INT  dir,
LPTSTR  commandline 
)

Definition at line 326 of file history.c.

327 {
328  ASSERT(Top && Bottom);
329 
330  if (dir==0)
331  {
332  add_at_bottom(commandline);
333  curr_ptr = Bottom;
334  return;
335  }
336 
337  if (size==0)
338  {
339  commandline[0]=_T('\0');
340  return;
341  }
342 
343  if (dir<0)/*key up*/
344  {
345  if (curr_ptr->next==Top || curr_ptr==Top)
346  {
347 #ifdef WRAP_HISTORY
348  curr_ptr = Bottom;
349 #else
350  curr_ptr = Top;
351  commandline[0]=_T('\0');
352  return;
353 #endif
354  }
355 
357  if (curr_ptr->string)
358  _tcscpy(commandline,curr_ptr->string);
359  }
360 
361  if (dir>0)
362  {
363  if (curr_ptr->prev==Bottom || curr_ptr==Bottom)
364  {
365 #ifdef WRAP_HISTORY
366  curr_ptr = Top;
367 #else
368  curr_ptr = Bottom;
369  commandline[0]=_T('\0');
370  return;
371 #endif
372  }
373 
375  if (curr_ptr->string)
376  _tcscpy(commandline,curr_ptr->string);
377  }
378 }
struct tagHISTORY * next
Definition: history.c:47
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
static VOID add_at_bottom(LPTSTR string)
Definition: history.c:225
unsigned int dir
Definition: maze.c:112
#define _T(x)
Definition: vfdio.h:22
GLsizeiptr size
Definition: glext.h:5919
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
static LPHIST_ENTRY curr_ptr
Definition: history.c:56
LPTSTR string
Definition: history.c:48
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by CommandHistory(), History_del_current_entry(), and ReadCommand().

◆ History_del_current_entry()

VOID History_del_current_entry ( LPTSTR  str)

Definition at line 175 of file history.c.

176 {
177  LPHIST_ENTRY tmp;
178 
179  ASSERT(Top && Bottom);
180 
181  if (size == 0)
182  return;
183 
184  if (curr_ptr == Bottom)
185  curr_ptr = Bottom->next;
186 
187  if (curr_ptr == Top)
188  curr_ptr = Top->prev;
189 
190 
191  tmp = curr_ptr;
193  del(tmp);
194  History(-1, str);
195 }
struct tagHISTORY * next
Definition: history.c:47
const WCHAR * str
GLsizeiptr size
Definition: glext.h:5919
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
static LPHIST_ENTRY curr_ptr
Definition: history.c:56
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by ReadCommand().

◆ History_move_to_bottom()

VOID History_move_to_bottom ( VOID  )

Definition at line 280 of file history.c.

281 {
282  ASSERT(Top && Bottom);
283 
284  curr_ptr = Bottom;
285 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY curr_ptr
Definition: history.c:56
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by ReadCommand().

◆ InitHistory()

VOID InitHistory ( VOID  )

Definition at line 132 of file history.c.

133 {
134  size = 0;
135 
136  Top = cmd_alloc(sizeof(HIST_ENTRY));
137  if (!Top)
138  {
139  WARN("Cannot allocate memory for Top!\n");
140  return;
141  }
142  Bottom = cmd_alloc(sizeof(HIST_ENTRY));
143  if (!Bottom)
144  {
145  WARN("Cannot allocate memory for Bottom!\n");
146  cmd_free(Top);
147  Top = NULL;
148  return;
149  }
150 
151  Top->prev = Bottom;
152  Top->next = NULL;
153  Top->string = NULL;
154 
155  Bottom->prev = NULL;
156  Bottom->next = Top;
157  Bottom->string = NULL;
158 
159  curr_ptr = Bottom;
160 }
struct tagHISTORY * next
Definition: history.c:47
#define WARN(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
static LPHIST_ENTRY curr_ptr
Definition: history.c:56
LPTSTR string
Definition: history.c:48
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by CommandHistory(), and Initialize().

◆ PeekHistory()

LPCTSTR PeekHistory ( INT  dir)

Definition at line 287 of file history.c.

288 {
290 
291  ASSERT(Top && Bottom);
292 
293  if (dir == 0)
294  return NULL;
295 
296  if (dir < 0)
297  {
298  /* key up */
299  if (entry->next == Top || entry == Top)
300  {
301 #ifdef WRAP_HISTORY
302  entry = Bottom;
303 #else
304  return NULL;
305 #endif
306  }
307  entry = entry->next;
308  }
309  else
310  {
311  /* key down */
312  if (entry->prev == Bottom || entry == Bottom)
313  {
314 #ifdef WRAP_HISTORY
315  entry = Top;
316 #else
317  return NULL;
318 #endif
319  }
320  entry = entry->prev;
321  }
322 
323  return entry->string;
324 }
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
uint32_t entry
Definition: isohybrid.c:63
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY curr_ptr
Definition: history.c:56
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by ReadCommand().

◆ set_size()

VOID set_size ( INT  new_size)

Definition at line 121 of file history.c.

122 {
123  ASSERT(Top && Bottom);
124 
125  while (new_size<size)
126  del(Top->prev);
127 
128  max_size=new_size;
129 }
static INT max_size
Definition: history.c:51
GLsizeiptr size
Definition: glext.h:5919
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
static LPHIST_ENTRY Bottom
Definition: history.c:54
struct tagHISTORY * prev
Definition: history.c:46
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by CommandHistory(), set_end_of_file_information(), and set_valid_data_length_information().

Variable Documentation

◆ Bottom

◆ curr_ptr

LPHIST_ENTRY curr_ptr = NULL
static

◆ max_size

◆ size

INT size
static

Definition at line 51 of file history.c.

◆ Top

LPHIST_ENTRY Top = NULL
static

Definition at line 53 of file history.c.

Referenced by add_at_bottom(), BaseControlVideoImpl_SetDestinationPosition(), BaseControlVideoImpl_SetSourcePosition(), BaseControlWindowImpl_put_Top(), BaseControlWindowImpl_SetWindowPosition(), BasicVideo_SetDestinationPosition(), BasicVideo_SetSourcePosition(), BitBlt(), CleanHistory(), CommandHistory(), CreateFileSystemList(), CreateProgressBar(), CreateProgressBarEx(), del(), DisplayCharacter(), DisplayStringXY(), DrawGenericList(), DrawGenericListCurrentItem(), GuiWriteStream(), History(), History_del_current_entry(), History_move_to_bottom(), InbvSetProgressBarCoordinates(), InbvSetScrollRegion(), InbvSolidColorFill(), InitHistory(), InitPartitionListUi(), IntArc(), IntDrawRoundRect(), InternetExplorer_put_Top(), IntFillRoundRect(), IntRoundRect(), MiniQueueWorkItem(), MiniTuiDrawProgressBar(), MiniTuiDrawProgressBarCenter(), NtGdiCreateEllipticRgn(), NtGdiEllipse(), PeekHistory(), RleBitBlt(), set_size(), SetPixel(), ShellUIHelper2_AddDesktopComponent(), ShowPartitionSizeInputBox(), TuiDrawBox(), TuiDrawCenteredText(), TuiDrawProgressBar(), TuiDrawProgressBarCenter(), TuiDrawShadow(), TuiFillArea(), UiDrawBox(), UiDrawCenteredText(), UiDrawProgressBar(), UiDrawShadow(), UiFillArea(), UiInfoBox(), VgaScroll(), VidBitBlt(), VidBufferToScreenBlt(), VidDisplayStringXY(), VideoWindow_put_Top(), VideoWindow_SetWindowPosition(), VidpSetPixel(), VidScreenToBufferBlt(), VidSetScrollRegion(), VidSolidColorFill(), and WebBrowser_put_Top().