ReactOS  0.4.14-dev-614-gbfd8a84
Completion.cpp File Reference
#include "ph.h"
#include "RegistryKey.h"
#include "RegistryTree.h"
Include dependency graph for Completion.cpp:

Go to the source code of this file.

Classes

class  CCompletionMatch
 
class  CCompletionList
 

Macros

#define COMPLETION_BUFFER_SIZE   4096
 

Functions

BOOL FillCompletion (const TCHAR *pszKey)
 
const TCHARCompletionCallback (unsigned __int64 &rnIndex, const BOOL *pblnForward, const TCHAR *pszContext, const TCHAR *pszBegin)
 
void InvalidateCompletion ()
 

Variables

CRegistryTree Tree
 
BOOL g_blnCompletionCycle = TRUE
 
class CCompletionList g_Completion
 

Macro Definition Documentation

◆ COMPLETION_BUFFER_SIZE

#define COMPLETION_BUFFER_SIZE   4096

Definition at line 27 of file Completion.cpp.

Function Documentation

◆ CompletionCallback()

const TCHAR* CompletionCallback ( unsigned __int64 rnIndex,
const BOOL pblnForward,
const TCHAR pszContext,
const TCHAR pszBegin 
)

Definition at line 439 of file Completion.cpp.

443 {
444  static TCHAR pszBuffer[COMPLETION_BUFFER_SIZE];
445 
446  // Find first non-white space in context
447  while(*pszContext && _istspace(*pszContext))
448  pszContext++;
449 
450  BOOL blnNewCompletion = TRUE;
451  if (!g_Completion.IsNewCompletion(pszContext,pszBegin,blnNewCompletion))
452  {
453  ASSERT(FALSE);
454  return NULL;
455  }
456 
457  if (blnNewCompletion)
458  {
459  _tcsncpy(pszBuffer,pszBegin,COMPLETION_BUFFER_SIZE-1);
460  pszBuffer[COMPLETION_BUFFER_SIZE-1] = 0;
461  TCHAR *pszSeparator = pszBuffer; // set it to aby non null value
462  if (_tcscmp(pszBuffer,_T("\\")))
463  {
464  pszSeparator = _tcsrchr(pszBuffer,_T('\\'));
465  if (pszSeparator)
466  *pszSeparator = 0;
467  }
468 
469  if (!FillCompletion(pszSeparator?pszBuffer:NULL))
470  return NULL;
471  }
472 
473  unsigned __int64 nTotalItems = g_Completion.GetCount();
474  if (nTotalItems == 0)
475  return NULL;
476 
477  if (rnIndex >= nTotalItems)
478  rnIndex = nTotalItems-1;
479 
480  if (pblnForward)
481  {
482  if (*pblnForward)
483  {
484  rnIndex++;
485  if (rnIndex >= nTotalItems)
486  {
488  rnIndex = 0;
489  else
490  rnIndex--;
491  }
492  }
493  else
494  {
495  if (rnIndex)
496  rnIndex--;
497  else if (g_blnCompletionCycle)
498  rnIndex = nTotalItems-1;
499  }
500  }
501  BOOL blnIsKey = FALSE;
502  const TCHAR *pszName = g_Completion.Get(rnIndex,blnIsKey);
503 
504  ASSERT(pszName);
505 
506  _sntprintf(pszBuffer,COMPLETION_BUFFER_SIZE-1,_T("%s%s"),pszName,(blnIsKey?_T("\\"):_T("")));
507  pszBuffer[COMPLETION_BUFFER_SIZE-1] = 0;
508  return pszBuffer;
509 }
#define TRUE
Definition: types.h:120
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
const TCHAR * Get(unsigned __int64 nIndex, BOOL &rblnIsKey)
Definition: Completion.cpp:249
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
BOOL IsNewCompletion(const TCHAR *pszContext, const TCHAR *pszBegin, BOOL &rblnNew)
Definition: Completion.cpp:149
BOOL g_blnCompletionCycle
Definition: Completion.cpp:31
#define COMPLETION_BUFFER_SIZE
Definition: Completion.cpp:27
BOOL FillCompletion(const TCHAR *pszKey)
Definition: Completion.cpp:332
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
class CCompletionList g_Completion
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned __int64 GetCount()
Definition: Completion.cpp:301
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define _sntprintf
Definition: xmlstorage.h:201
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4
#define _istspace
Definition: tchar.h:1504
#define __int64
Definition: basetyps.h:16

Referenced by co_IntCallSentMessageCallback(), co_IntSendMessageWithCallBack(), co_MsqSendMessageAsync(), and main().

◆ FillCompletion()

BOOL FillCompletion ( const TCHAR pszKey)

Definition at line 332 of file Completion.cpp.

333 {
335  LONG nError;
337  TCHAR *pszSubkeyName = NULL;
338  DWORD dwMaxSubkeyNameLength;
339  TCHAR *pszValueName = NULL;
340  DWORD dwMaxValueNameSize;
341 
342  if (!Tree.GetKey(pszKey?pszKey:_T("."),KEY_ENUMERATE_SUB_KEYS|KEY_QUERY_VALUE,Key))
343  return FALSE;
344 
345  BOOL blnCompletionOnKeys = TRUE;
346  BOOL blnCompletionOnValues = TRUE;
347 
348 /* if ((_tcsnicmp(pchContext,DIR_CMD,DIR_CMD_LENGTH) == 0)||
349  (_tcsnicmp(pchContext,CD_CMD,CD_CMD_LENGTH) == 0)||
350  (_tcsnicmp(pchContext,OWNER_CMD,OWNER_CMD_LENGTH) == 0)||
351  (_tcsnicmp(pchContext,DACL_CMD,DACL_CMD_LENGTH) == 0)||
352  (_tcsnicmp(pchContext,SACL_CMD,SACL_CMD_LENGTH) == 0))
353  {
354  blnCompletionOnValues = FALSE;
355  }*/
356 // else if (_tcsnicmp(pchContext,VALUE_CMD,VALUE_CMD_LENGTH) == 0)
357 // {
358 // blnCompletionOnKeys = FALSE;
359 // }
360 
361  size_t nKeyNameSize = 0;
362  if (pszKey)
363  {
364  nKeyNameSize = _tcslen(pszKey);
365  if (_tcscmp(pszKey,_T("\\")))
366  nKeyNameSize++;
367  }
368 
369  if (blnCompletionOnKeys)
370  {
371  nError = Key.GetSubkeyNameMaxLength(dwMaxSubkeyNameLength);
372  if (nError != ERROR_SUCCESS)
373  return FALSE;
374 
375  pszSubkeyName = new (std::nothrow) TCHAR[nKeyNameSize+dwMaxSubkeyNameLength+1];
376  if (!pszSubkeyName)
377  goto Abort;
378 
379  if (pszKey)
380  _stprintf(pszSubkeyName,_tcscmp(pszKey,_T("\\"))?_T("%s\\"):_T("%s"),pszKey);
381 
382  Key.InitSubkeyEnumeration(pszSubkeyName+nKeyNameSize,dwMaxSubkeyNameLength);
383  while ((nError = Key.GetNextSubkeyName()) == ERROR_SUCCESS)
384  if (!g_Completion.Add(pszSubkeyName,TRUE))
385  {
386  ASSERT(FALSE);
387  goto Abort;
388  }
389  if ((nError != ERROR_SUCCESS)&&(nError != ERROR_NO_MORE_ITEMS))
390  {
391  ASSERT(FALSE);
392  goto Abort;
393  }
394  }
395 
396  if (blnCompletionOnValues)
397  {
398  nError = Key.GetMaxValueNameLength(dwMaxValueNameSize);
399  if (nError != ERROR_SUCCESS)
400  {
401  ASSERT(FALSE);
402  goto Abort;
403  }
404 
405  pszValueName = new (std::nothrow) TCHAR[nKeyNameSize+dwMaxValueNameSize+1];
406  if (!pszValueName)
407  goto Abort;
408 
409  if (pszKey)
410  _stprintf(pszValueName,_tcscmp(pszKey,_T("\\"))?_T("%s\\"):_T("%s"),pszKey);
411 
412  Key.InitValueEnumeration(pszValueName+nKeyNameSize,dwMaxValueNameSize,NULL,0,NULL);
413  while((nError = Key.GetNextValue()) == ERROR_SUCCESS)
414  if (!g_Completion.Add(pszValueName,FALSE))
415  {
416  ASSERT(FALSE);
417  goto Abort;
418  }
419  if ((nError != ERROR_SUCCESS)&&(nError != ERROR_NO_MORE_ITEMS))
420  {
421  ASSERT(FALSE);
422  goto Abort;
423  }
424  }
425 
426  if (pszValueName)
427  delete[] pszValueName;
428  if (pszSubkeyName)
429  delete[] pszSubkeyName;
430  return TRUE;
431 Abort:
432  if (pszValueName)
433  delete[] pszValueName;
434  if (pszSubkeyName)
435  delete[] pszSubkeyName;
436  return FALSE;
437 }
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
long LONG
Definition: pedump.c:60
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
class CCompletionList g_Completion
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
CRegistryTree Tree
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL Add(const TCHAR *pszText, BOOL blnIsKey)
Definition: Completion.cpp:214
#define _stprintf
Definition: utility.h:124
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

Referenced by CompletionCallback().

◆ InvalidateCompletion()

void InvalidateCompletion ( )

Variable Documentation

◆ g_blnCompletionCycle

BOOL g_blnCompletionCycle = TRUE

Definition at line 31 of file Completion.cpp.

Referenced by CompletionCallback().

◆ g_Completion

◆ Tree