示例#1
0
static int tm_init( int install )
/*******************************/
{
    const char      *term;

    MouseInstalled = false;
    MouseType = M_NONE;

    if( install == 0 )
        return( false );

    term = GetTermType();
    if( strcmp( term, "xterm" ) == 0 ) {
        DoMouseInit( M_XT, XT_INIT, ANSI_HDR "M" );
        return( true );
    }
    if( strstr( term, "qnx" ) != 0 ) {
        uiwritec( QNX_HDR QW_TEST );
        TrieAdd( EV_MOUSE_PRESS, QNX_HDR QW_TEST_RESPONSE );
        return( true );
    }
    uiwritec( ANSI_HDR QW_TEST );
    TrieAdd( EV_MOUSE_PRESS, ANSI_HDR QW_TEST_RESPONSE );
    return( true );
}
示例#2
0
//-----------------------------------------------------------------
// Load the static blacklists into Trie (Prefix Tree)
//-----------------------------------------------------------------
BOOL populateStaticBlacklist(LPTSTR lpszFileName)
{
	wchar_t line[MAX_PATH];
	FILE *hFile;
	wchar_t * key;
	wchar_t * path;

	hFile = _wfopen(lpszFileName, L"rb, ccs=UTF-16LE");

	while (fgetws(line, MAX_PATH, hFile))
	{
		// Remove newline character
		if (line[_tcslen(line) - 1] == (TCHAR)'\n') {
			line[_tcslen(line) - 1] = (TCHAR)'\0';
		}

		// Remove carrige return character
		if (line[_tcslen(line) - 1] == (TCHAR)'\r') {
			line[_tcslen(line) - 1] = (TCHAR)'\0';
		}

		// If line does not start with a hash ('#'), add to blacklist
		if (line[0] != (TCHAR)'#')
		{
			if (line == NULL) {
				continue;
			}
			
			//wchar_t * key = _tcstok(line, L"=");
			//wchar_t * path = _tcstok(NULL, L"=");
			key = _tcstok(line, L"=");
			path = _tcstok(NULL, L"=");

			if (key == NULL || path == NULL) {
				continue;
			}

			if (_tcscmp(key, _T("DIR")) == 0) {
				TrieAdd(&blacklistDIRS, path);
			}
			if (_tcscmp(key, _T("FILE")) == 0) {
				TrieAdd(&blacklistFILES, path);
			}
			if (_tcscmp(key, _T("KEY")) == 0) {
				TrieAdd(&blacklistKEYS, path);
			}
			if (_tcscmp(key, _T("VALUE")) == 0) {
				TrieAdd(&blacklistVALUES, path);
			}
		}
	}

	//LPTSTR string = TEXT("HKLM\\SYSTEM\\ControlSet002");
	//BOOL found = TrieSearchPath(blacklistKEYS->children, string);
	//printf("FOUND: %d", found);

	// All done with loading blacklist, so close file handle and return
	fclose(hFile);
	return TRUE;
}
//complete.c
//Created by Sameer Mehta
int main() {
	trie * print; //for printing
	// load all the dictionary words into the tree
	trie * trie;							//creates a instance of trie from ADT
	TrieInitialize(&trie);						//initializes the creates instance

	FILE * infile = fopen("american-english-no-accents", "r");	//creates a file to read to 'infile'
	char line[256];							//size of lines
	while ((fscanf(infile, "%s", line)) != EOF) {			//scan function to scan the file
		TrieAdd(trie, line);					//adds the file to the trie usign the fucntion TrieAdd
	}
	fclose(infile);							//close the reading of the file

	//get user input
    char * prefix;
   // trie * print;							//instance is made
    while (1) {								//while true
    	printf("Enter the word: ");					//asks for user input
    	fscanf(stdin, "%s", prefix);
    	fflush(stdin);							//deallocated/frees memory

    	print = TrieSearch(trie, prefix);				//prints the trie fby calling the search function
    	TriePrinter(print);						//prints what was initialized above using the printer function
    }
}
示例#4
0
/* use above table if no .tix file is found */
static int do_default( void )
/***************************/
{
    unsigned char       c, cmap;
    int                 i;

    for( i = 0; i < sizeof( default_tix ) / sizeof( default_tix[0] ) ; i ++ ) {
        cmap = c = default_tix[i].vt100;
        if( (c & 0x80) == 0 ) {
            cmap = find_acs_map( c, acs_chars );
            if( cmap != '\0' ) {
                ti_alt_map_set( i );
            } else {
                cmap = find_acs_map( c, acs_default );
                if( cmap == '\0' ) {
                    cmap = c;
                    ti_alt_map_set( i );
                }
            }
        }
        ti_char_map[i][0] = cmap;
    }
    for( i = 0; i < sizeof( alt_keys ); i++ ) {
        if ( alt_keys[i] ) {
            esc_str[1] = alt_keys[i];
            TrieAdd( 0x110 + i, esc_str );
            if( alt_keys[i] >= 'A' && alt_keys[i] <= 'Z' ) {
                esc_str[1] += 0x20;
                TrieAdd( 0x110 + i, esc_str );
            }
        }
    }
    for( i = 0; i < sizeof( alt_num_keys ); i++ ) {
        if ( alt_num_keys[i] ) {
            esc_str[1] = alt_num_keys[i];
            TrieAdd( 0x178 + i, esc_str );
        }
    }
    /* sticky function key ^F */
    TrieAdd( 0xff0, "\6");
    /* sticky ALT ^A */
    TrieAdd( 0xff3, "\1");
    return( 1 );
}
示例#5
0
文件: trie-c.c 项目: dkurochkin/squid
int
main (int argc, char **argv)
{
    void *aTrie = TrieCreate();
    if (!TrieAdd (aTrie, "User-Agent", 10, (void *)1)) {
        fprintf(stderr,"Could not add User-Agent\n");
        return 1;
    }
    if (TrieAdd (aTrie, "User-Agent", 10, (void *)2)) {
        fprintf(stderr, "Could add duplicate User-Agent\n");
        return 1;
    }
    if (TrieFind (aTrie, "User-Agent", 10) != (void *)1) {
        fprintf(stderr, "Could not find User-Agent\n");
        return 1;
    }
    TrieDestroy (aTrie);
    return 0;
}
示例#6
0
int main()
{
    Trie *root;
    printf("Trie Example\n");
     
    /*Create a trie*/
    TrieCreate(&root);
     
    TrieAdd(&root, "andrew", 1);
    TrieAdd(&root, "tina", 2);
    TrieAdd(&root, "argo", 3);
    TrieAdd(&root, "timor", 5);
    TrieAdd(&root, "tim", 6);
    TrieAdd(&root, "ti", 6);
    TrieAdd(&root, "amy", 7);
    TrieAdd(&root, "aramis", 8);
 
    /*Destroy the trie*/
    TrieDestroy(root);
}
示例#7
0
static void TryOne( int type, char *test, char *init, char *input )
{
    MOUSEORD    row;
    MOUSEORD    col;

    MouseType = type;
    uimouseforceoff();
    write( UIConHandle, init, strlen( init ) );
    TrieAdd( EV_MOUSE_PRESS, input );

    MouseInstalled = TRUE;

    UIData->mouse_xscale = 1;
    UIData->mouse_yscale = 1;
    checkmouse( &MouseStatus, &row, &col, &MouseTime );
    MouseRow = row;
    MouseCol = col;
    stopmouse();
}
示例#8
0
static void DoMouseInit( int type, char *init, const char *input )
{
    struct _osinfo      osinfo;
    MOUSEORD            row;
    MOUSEORD            col;

    MouseType = type;
    uimouseforceoff();
    uiwrite( init );
    TrieAdd( EV_MOUSE_PRESS, input );

    MouseInstalled = true;

    UIData->mouse_xscale = 1;
    UIData->mouse_yscale = 1;

    qnx_osinfo( 0, &osinfo );
    SysTimeSel = osinfo.timesel;

    checkmouse( &MouseStatus, &row, &col, &MouseTime );
    MouseRow = row;
    MouseCol = col;
    stopmouse();
}
示例#9
0
// ----------------------------------------------------------------------
// Get file snap shot
// ----------------------------------------------------------------------
VOID GetFilesSnap(LPSNAPSHOT lpShot, LPTSTR lpszFullName, LPFILECONTENT lpFatherFC, LPFILECONTENT *lplpCaller) 
{
	LPFILECONTENT lpFC;
	HANDLE hFile;
	BOOL calculateHash = TRUE;
	BOOL found = FALSE;

	// Full dir/file name is already given
	// Extra local block to reduce stack usage due to recursive calls
	{
		LPTSTR lpszFindFileName;
		lpszFindFileName = NULL;
		// Get father file data if not already provided (=called from FileShot)
		// lpFatherFC only equals "C:\" and is called once at start
		if (NULL == lpFatherFC) 
		{
			// Check if file is to be GENERIC excluded
			if ((NULL == lpszFullName)
				|| (((TCHAR)'.' == lpszFullName[0])  // fast exclusion for 99% of the cases
				&& ((0 == _tcscmp(lpszFullName, TEXT(".")))
				|| (0 == _tcscmp(lpszFullName, TEXT("..")))))) {
				return;
			}
			// Create new file content
			lpFatherFC = MYALLOC0(sizeof(FILECONTENT));

			// Set file name length
			lpFatherFC->cchFileName = _tcslen(lpszFullName);
			// Copy file name to new buffer for directory search and more
			lpszFindFileName = MYALLOC((lpFatherFC->cchFileName + 4 + 1) * sizeof(TCHAR));  // +4 for "\*.*" search when directory (later in routine)
			_tcscpy(lpszFindFileName, lpszFullName);
			// Special case if root dir of a drive was specified, needs trailing backslash otherwise current dir of that drive is used
			if ((TCHAR)':' == lpszFindFileName[lpFatherFC->cchFileName - 1]) {
				lpszFindFileName[lpFatherFC->cchFileName] = (TCHAR)'\\';
				lpszFindFileName[lpFatherFC->cchFileName + 1] = (TCHAR)'\0';
			}
			//printf("lpszFullName: %ws\n", lpszFullName);
			//printf("lpszFindFileName: %ws\n", lpszFindFileName);

			hFile = FindFirstFile(lpszFullName, &FindData);
			if (INVALID_HANDLE_VALUE != hFile) {
				FindClose(hFile);
			}
			else {
				// Workaround for some cases in Windows Vista and later
				ZeroMemory(&FindData, sizeof(FindData));
				
				hFile = CreateFile(lpszFullName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
				if (INVALID_HANDLE_VALUE != hFile) {
					BY_HANDLE_FILE_INFORMATION FileInformation;
					BOOL bResult;

					bResult = GetFileInformationByHandle(hFile, &FileInformation);
					if (bResult) {
						FindData.dwFileAttributes = FileInformation.dwFileAttributes;
						FindData.ftCreationTime = FileInformation.ftCreationTime;
						FindData.ftLastAccessTime = FileInformation.ftLastAccessTime;
						FindData.ftLastWriteTime = FileInformation.ftLastWriteTime;
						FindData.nFileSizeHigh = FileInformation.nFileSizeHigh;
						FindData.nFileSizeLow = FileInformation.nFileSizeLow;
					}
					else {
						FindData.dwFileAttributes = GetFileAttributes(lpszFullName);
						if (INVALID_FILE_ATTRIBUTES == FindData.dwFileAttributes) {
							FindData.dwFileAttributes = 0;
						}
						bResult = GetFileTime(hFile, &FindData.ftCreationTime, &FindData.ftLastAccessTime, &FindData.ftLastWriteTime);
						if (!bResult) {
							FindData.ftCreationTime.dwLowDateTime = 0;
							FindData.ftCreationTime.dwHighDateTime = 0;
							FindData.ftLastAccessTime.dwLowDateTime = 0;
							FindData.ftLastAccessTime.dwHighDateTime = 0;
							FindData.ftLastWriteTime.dwLowDateTime = 0;
							FindData.ftLastWriteTime.dwHighDateTime = 0;
						}
						FindData.nFileSizeLow = GetFileSize(hFile, &FindData.nFileSizeHigh);
						if (INVALID_FILE_SIZE == FindData.nFileSizeLow) {
							FindData.nFileSizeHigh = 0;
							FindData.nFileSizeLow = 0;
						}
					}
					CloseHandle(hFile);
				}
			}

			// Remove previously added backslash (if any)
			lpszFindFileName[lpFatherFC->cchFileName] = (TCHAR)'\0';

			// Copy pointer to current file into caller's pointer
			if (NULL != lplpCaller) {
				*lplpCaller = lpFatherFC;
			}
			          
			// Increase dir/file count
			if (ISFILE(FindData.dwFileAttributes)) {
				lpShot->stCounts.cFiles++;
			}
			else {
				lpShot->stCounts.cDirs++;
			}

			// Copy file name
			lpFatherFC->lpszFileName = MYALLOC((lpFatherFC->cchFileName + 1) * sizeof(TCHAR));
			_tcscpy(lpFatherFC->lpszFileName, lpszFullName);

			// Copy file data
			lpFatherFC->nWriteDateTimeLow = FindData.ftLastWriteTime.dwLowDateTime;
			lpFatherFC->nWriteDateTimeHigh = FindData.ftLastWriteTime.dwHighDateTime;
			lpFatherFC->nAccessDateTimeLow = FindData.ftLastWriteTime.dwLowDateTime;
			lpFatherFC->nAccessDateTimeHigh = FindData.ftLastWriteTime.dwHighDateTime;
			lpFatherFC->nFileSizeLow = FindData.nFileSizeLow;
			lpFatherFC->nFileSizeHigh = FindData.nFileSizeHigh;
			lpFatherFC->nFileAttributes = FindData.dwFileAttributes;

			// Set "lpFirstSubFC" pointer for storing the first child's pointer
			lplpCaller = &lpFatherFC->lpFirstSubFC;
		}

		// If father is a file, then leave (=special case when called from FileShot)
		if (ISFILE(lpFatherFC->nFileAttributes)) {
			if (NULL != lpszFindFileName) {
				MYFREE(lpszFindFileName);
			}
			return;
		}

		// Process all entries of directory
		// a) Create search pattern and start search
		if (NULL == lpszFindFileName) {
			lpszFindFileName = lpszFullName;
		}
		_tcscat(lpszFindFileName, TEXT("\\*.*"));
		hFile = FindFirstFile(lpszFindFileName, &FindData);
		if (lpszFindFileName != lpszFullName) {
			MYFREE(lpszFindFileName);
		}
	}  // End of extra local block
	if (INVALID_HANDLE_VALUE == hFile) {  
		// error: nothing in dir, no access, etc.
		//printf(">>> ERROR: fileshot.c: getFileSnap: INVALID_HANDLE_VALUE: %ws\n", lpszFullName);
		return;
	}
	// b) process entry then find next
	do {
		lpszFullName = NULL;
		//BOOL calculateHash = TRUE;
		//BOOL found = FALSE;

		// Check if file is to be GENERIC excluded (dot dirs)
		if ((NULL == FindData.cFileName)
			|| (((TCHAR)'.' == FindData.cFileName[0])  // fast exclusion for 99% of the cases
			&& ((0 == _tcscmp(FindData.cFileName, TEXT(".")))
			|| (0 == _tcscmp(FindData.cFileName, TEXT("..")))))) {
			continue;  // ignore this entry and continue with next file
		}

		// Create new file content
		lpFC = MYALLOC0(sizeof(FILECONTENT));
		// Set father of current key
		lpFC->lpFatherFC = lpFatherFC;
		// Set file name length
		lpFC->cchFileName = _tcslen(FindData.cFileName);

		// Allocate memory copy file name to FILECONTENT
		lpFC->lpszFileName = MYALLOC0((lpFC->cchFileName + 1) * sizeof(TCHAR));
		_tcscpy(lpFC->lpszFileName, FindData.cFileName);

		// Static blacklist for directories
		if (ISDIR(FindData.dwFileAttributes))
		{
			if (performStaticBlacklisting)
			{
				LPTSTR lpszFullPath;
				lpszFullPath = GetWholeFileName(lpFC, 4);

				found = TrieSearchPath(blacklistDIRS->children, lpszFullPath);
				if (found)
				{
					lpShot->stCounts.cFilesBlacklist++;
					MYFREE(lpszFullPath);
					FreeAllFileContents(lpFC);

					// Increase value count for display purposes
					lpShot->stCounts.cDirsBlacklist++;
					
					// Ignore this entry and continue with next brother value
					continue;  
				}
				else
				{
					MYFREE(lpszFullPath);
				}
			}
		}

		// Check if the file system entry is a symbolic link
		// If so, skip as it actually resides somewhere else on the file system!
		if (ISSYM(FindData.dwFileAttributes)) {
			if (ISFILE(FindData.dwFileAttributes)) {
				lpShot->stCounts.cFilesBlacklist++;
			}
			else {
				lpShot->stCounts.cDirsBlacklist++;
			}
			continue;
		}

		// Blacklisting implementation for files		
		if (ISFILE(FindData.dwFileAttributes))
		{
			if (dwBlacklist == 1)
			{
				// First snapshot, therefore populate the Trie (Prefix Tree)
				// Get the full file path
				LPTSTR lpszFullPath;
				lpszFullPath = GetWholeFileName(lpFC, 4);

				// Add full path to file blacklist prefix tree, then free path
				TrieAdd(&blacklistFILES, lpszFullPath);
				MYFREE(lpszFullPath);

				// Increase value count for display purposes
				lpShot->stCounts.cFiles++;

				// Ignore this entry and continue with next brother value
				//continue;  
			}
			else if (dwBlacklist == 2)
			{
				// Not the first snapshot, so either:
				// 1) If blacklisting enabled: Ignore file if its in the blacklist
				// 2) If hashing enabled (and not blacklisting): Mark file as not to be hashed
				LPTSTR lpszFullPath;
				lpszFullPath = GetWholeFileName(lpFC, 4);
				found = TrieSearchPath(blacklistFILES->children, lpszFullPath);
				if (found)
				{
					if (performDynamicBlacklisting)
					{
						MYFREE(lpszFullPath);
						FreeAllFileContents(lpFC);

						// Increase value count for display purposes
						lpShot->stCounts.cFilesBlacklist++;

						// Ignore this entry and continue with next brother value
						continue;  
					}
					if (performSHA1Hashing || performMD5Hashing)
					{
						lpShot->stCounts.cFiles++;
						MYFREE(lpszFullPath);
						calculateHash = FALSE;
					}
				}
				else
				{
					MYFREE(lpszFullPath);
				}
			}
		}
					
		// Copy pointer to current file into caller's pointer
		if (NULL != lplpCaller) {
			*lplpCaller = lpFC;
		}

		// Increase dir/file count
		if (ISFILE(FindData.dwFileAttributes)) {
			lpShot->stCounts.cFiles++;
		}
		else {
			lpShot->stCounts.cDirs++;
		}

		// Copy file data
		lpFC->nWriteDateTimeLow = FindData.ftLastWriteTime.dwLowDateTime;
		lpFC->nWriteDateTimeHigh = FindData.ftLastWriteTime.dwHighDateTime;
		lpFC->nAccessDateTimeLow = FindData.ftLastWriteTime.dwLowDateTime;
		lpFC->nAccessDateTimeHigh = FindData.ftLastWriteTime.dwHighDateTime;
		lpFC->nFileSizeLow = FindData.nFileSizeLow;
		lpFC->nFileSizeHigh = FindData.nFileSizeHigh;
		lpFC->nFileAttributes = FindData.dwFileAttributes;

		// Calculate file hash (computationally intensive!)
		// This should only be executed in the following scenarios:
		// 1) If the file system entry is a data file 
		// 2) If the data file is not blacklisted (previously known)
		if (ISFILE(FindData.dwFileAttributes))
		{
			if (dwBlacklist == 2 && calculateHash) {
			    if (performSHA1Hashing)
			    {
				    lpFC->cchSHA1 = 40;
				    lpFC->lpszSHA1 = MYALLOC((lpFC->cchSHA1 + 1) * sizeof(TCHAR));
				    _tcscpy(lpFC->lpszSHA1, CalculateSHA1(GetWholeFileName(lpFC, 4)));
                }
                if (performMD5Hashing)
                {
				    lpFC->cchMD5 = 32;
				    lpFC->lpszMD5 = MYALLOC((lpFC->cchMD5 + 1) * sizeof(TCHAR));
				    _tcscpy(lpFC->lpszMD5, CalculateMD5(GetWholeFileName(lpFC, 4)));
				}
				if (performMD5BlockHashing)
				{
					LPMD5BLOCK theMD5Block = CalculateMD5Blocks(GetWholeFileName(lpFC, 4), dwHashBlockSize);
					lpFC->lpMD5Block = MYALLOC0(sizeof(MD5BLOCK));
					lpFC->lpMD5Block = theMD5Block;
				}
			}
		}

		// Print file system shot status
		if ((dwBlacklist == 2 && performDynamicBlacklisting) || (performStaticBlacklisting)) {
			printf("  > Dirs: %d  Files: %d  Blacklisted Dirs: %d  Blacklisted Files: %d\r", lpShot->stCounts.cDirs, 
				lpShot->stCounts.cFiles,
				lpShot->stCounts.cDirsBlacklist,
				lpShot->stCounts.cFilesBlacklist);
		}
		else {
			printf("  > Dirs: %d  Files: %d\r", lpShot->stCounts.cDirs, lpShot->stCounts.cFiles);
		}

		// ATTENTION!!! FindData will be INVALID from this point on, due to recursive calls
		// If the entry is a directory, then do a recursive call for it
		// Pass this entry as father and "lpFirstSubFC" pointer for storing the first child's pointer
		if (ISDIR(lpFC->nFileAttributes)) {
			if (NULL == lpszFullName) {
				lpszFullName = GetWholeFileName(lpFC, 4);  // +4 for "\*.*" search (in recursive call)
			}
			GetFilesSnap(lpShot, lpszFullName, lpFC, &lpFC->lpFirstSubFC);
		}

		if (NULL != lpszFullName) {
			MYFREE(lpszFullName);
		}

		// Set "lpBrotherFC" pointer for storing the next brother's pointer
		lplpCaller = &lpFC->lpBrotherFC;
	} while (FindNextFile(hFile, &FindData));
	FindClose(hFile);
}
示例#10
0
void TrieAdd(trieNode_t **root, char *key, int data)
{
 trieNode_t *pTrav = NULL;

 if(NULL == *root)
 {
  printf("NULL tree\n");
  return;
 }
#ifdef DEBUG
 printf("\nInserting key %s: \n",key);
#endif
 pTrav = (*root)->children;



 if(pTrav == NULL)
 {
  /*First Node*/
  for(pTrav = *root; *key; pTrav = pTrav->children)
  {
   pTrav->children = TrieCreateNode(*key, 0xffffffff);
   pTrav->children->parent = pTrav;
#ifdef DEBUG
   printf("Inserting: [%c]\n",pTrav->children->key);
#endif
   key++;
  }

  pTrav->children = TrieCreateNode('\0', data);
  pTrav->children->parent = pTrav;
#ifdef DEBUG
  printf("Inserting: [%c]\n",pTrav->children->key);
#endif
  return;
 }

 if(TrieSearch(pTrav, key))
 {
  printf("Duplicate!\n");
  return;
 }

 while(*key != '\0')
 {
  if(*key == pTrav->key)
  {
   key++;
#ifdef DEBUG
   printf("Traversing child: [%c]\n",pTrav->children->key);
#endif
   pTrav = pTrav->children;
  }
  else
   break;
 }

 while(pTrav->next)
 {
  if(*key == pTrav->next->key)
  {
   key++;
   TrieAdd(&(pTrav->next), key, data);
   return;
  }
  pTrav = pTrav->next;
 }

 if(*key)
 {
  pTrav->next = TrieCreateNode(*key, 0xffffffff);
 }
 else
 {
  pTrav->next = TrieCreateNode(*key, data);
 }

 pTrav->next->parent = pTrav->parent;
 pTrav->next->prev = pTrav;

#ifdef DEBUG
 printf("Inserting [%c] as neighbour of [%c] \n",pTrav->next->key, pTrav->key);
#endif

 if(!(*key))
  return;

 key++;

 for(pTrav = pTrav->next; *key; pTrav = pTrav->children)
 {
  pTrav->children = TrieCreateNode(*key, 0xffffffff);
  pTrav->children->parent = pTrav;
#ifdef DEBUG
  printf("Inserting: [%c]\n",pTrav->children->key);
#endif
  key++;
 }

 pTrav->children = TrieCreateNode('\0', data);
 pTrav->children->parent = pTrav;
#ifdef DEBUG
 printf("Inserting: [%c]\n",pTrav->children->key);
#endif
 return;
}
示例#11
0
//-----------------------------------------------------------------
// Add a Trie (Prefix Tree) Node
//-----------------------------------------------------------------
void TrieAdd(trieNode_t **root, wchar_t *key)
{
	trieNode_t *pTrav = NULL;

	if (NULL == *root) {
		//printf("NULL tree\n");
		return;
	}
	//printf("\nInserting key %ws: \n", key);
	pTrav = (*root)->children;

	if (pTrav == NULL)
	{
		// If the node is NULL, this must be the first Node
		for (pTrav = *root; *key; pTrav = pTrav->children) {
			pTrav->children = TrieCreateNode(*key);
			pTrav->children->parent = pTrav;
			//printf("Inserting: [%c]\n", pTrav->children->key);
			key++;
		}

		pTrav->children = TrieCreateNode('\0');
		pTrav->children->parent = pTrav;
		//printf("Inserting: [%c]\n", pTrav->children->key);
		return;
	}

	if (TrieSearch(pTrav, key))
	{
		//printf("Duplicate!\n");
		return;
	}

	while (*key != '\0')
	{
		if (*key == pTrav->key)
		{
			key++;
			//printf("Traversing child: [%c]\n", pTrav->children->key);
			pTrav = pTrav->children;
		}
		else
			break;
	}

	while (pTrav->next)
	{
		if (*key == pTrav->next->key)
		{
			key++;
			TrieAdd(&(pTrav->next), key);
			return;
		}
		pTrav = pTrav->next;
	}

	if (*key) {
		pTrav->next = TrieCreateNode(*key);
	}
	else {
		pTrav->next = TrieCreateNode(*key);
	}

	pTrav->next->parent = pTrav->parent;
	pTrav->next->prev = pTrav;

	//printf("Inserting [%c] as neighbour of [%c] \n", pTrav->next->key, pTrav->key);

	if (!(*key))
		return;

	key++;

	for (pTrav = pTrav->next; *key; pTrav = pTrav->children)
	{
		pTrav->children = TrieCreateNode(*key);
		pTrav->children->parent = pTrav;
		//printf("Inserting: [%c]\n", pTrav->children->key);
		key++;
	}

	pTrav->children = TrieCreateNode('\0');
	pTrav->children->parent = pTrav;
	//printf("Inserting: [%c]\n", pTrav->children->key);
	return;
}
示例#12
0
void TrieAdd(Trie **root, char *key, int data)
{
 Trie *node = NULL;
 
 if(NULL == *root)
 {
  return;
 }
 node = (*root)->children;
 if(node == NULL)
 {
  /*First Node*/
  for(node = *root; *key; node = node->children)
  {
   node->children = TrieCreateNode(*key, 0xffffffff);
   node->children->parent = node;

   key++;
  }
  node->children = TrieCreateNode('\0', data);
  node->children->parent = node;

  return;
 }
 
 if(TrieSearch(node, key))
 {
  return;
 }
 
 while(*key != '\0')
 {
  if(*key == node->key)
  {
   key++;
   node = node->children;
  }
  else
   break;
 }
 
 while(node->next)
 {
  if(*key == node->next->key)
  {
   key++;
   TrieAdd(&(node->next), key, data);
   return;
  }
  node = node->next;
 }
 
 if(*key)
 {
  node->next = TrieCreateNode(*key, 0xffffffff);
 }
 else
 {
  node->next = TrieCreateNode(*key, data);
 }
 
 node->next->parent = node->parent;
 node->next->prev = node;
 
 if(!(*key))
  return;
 
 key++;
 
 for(node = node->next; *key; node = node->children)
 {
  node->children = TrieCreateNode(*key, 0xffffffff);
  node->children->parent = node;
  key++;
 }
 
 node->children = TrieCreateNode('\0', data);
 node->children->parent = node;
 return;
}
示例#13
0
int ti_read_tix( const char *termname )
/*************************************/
{
    int         i;
    int         ret;
    char        *s;
    int         utf8_mode = 0;

    memset( _ti_alt_map, 0, sizeof( _ti_alt_map ) );

    for( i = 0; i < sizeof( ti_char_map ) / sizeof( ti_char_map[0] ); i++ )
        ti_char_map[i][0]=i;

    if( !init_tix_scanner( termname ) ) {
        ret = do_default();
    } else {
        ret = do_parse();
        close_tix_scanner();
    }

    if ( ( ( s = getenv( "LC_ALL" ) )   && *s ) ||
         ( ( s = getenv( "LC_CTYPE" ) ) && *s ) ||
         ( ( s = getenv( "LANG" ) )     && *s ) )
        if ( strstr( s, "UTF" ) || strstr( s, "utf" ) )
            utf8_mode = 1;

    if( utf8_mode ) {
        /* handle at least iso-8859-1 for now */
        for( i = 0xa0; i < 0x100; i++ ) {
            wctomb( ti_char_map[i], i );
        }
    }

    #if 0
    /* do not play woth utf8 mode setting: all VT are already configured
       as needed. With this code on there is a problem with line drawing
       on the linux console (framebuffer mode) */

    if( strncmp( termname, "linux", 5 ) == 0 ) {
        /* force UTF-8 mode if the locale is set that way; *
         * we may be on a new VT on the Linux console      */
        if ( utf8_mode ) {
            write( UIConHandle, "\033%G", 3 );
            /* use UTF-8 characters instead of ACS */
            for( i = 0; i < sizeof( default_tix ) / sizeof( default_tix[0] ) ;
                 i ++ )
                wctomb( ti_char_map[i], default_tix[i].unicode );
        }
        else
            write( UIConHandle, "\033%@", 3 );
    }
    #endif

    if( strncmp( termname, "xterm", 5 ) == 0 ) {
        /* special xterm keys available in recent xterms */
        TrieAdd( EV_CTRL_CURSOR_UP, "\033[1;5A" );
        TrieAdd( EV_CTRL_CURSOR_DOWN, "\033[1;5B" );
        TrieAdd( EV_CTRL_CURSOR_RIGHT, "\033[1;5C" );
        TrieAdd( EV_CTRL_CURSOR_LEFT, "\033[1;5D" );
        TrieAdd( EV_CTRL_HOME, "\033[1;5H" );
        TrieAdd( EV_CTRL_END, "\033[1;5F" );
        TrieAdd( EV_CTRL_PAGE_UP, "\033[5;5~" );
        TrieAdd( EV_CTRL_PAGE_DOWN, "\033[6;5~" );

        /* slightly older xterms report these sequences... */
        TrieAdd( EV_CTRL_CURSOR_UP, "\033[O5A" );
        TrieAdd( EV_CTRL_CURSOR_DOWN, "\033[O5B" );
        TrieAdd( EV_CTRL_CURSOR_RIGHT, "\033[O5C" );
        TrieAdd( EV_CTRL_CURSOR_LEFT, "\033[O5D" );
        TrieAdd( EV_CTRL_HOME, "\033[O5H" );
        TrieAdd( EV_CTRL_END, "\033[O5F" );

        /* Red Hat 8 xterm has yet different sequences. Does
         * not differentiate between Home/End and Ctrl + Home/End,
         * but does for PgUp/PgDn (same codes as newer xterms above)
         */
        TrieAdd( EV_CTRL_CURSOR_UP, "\033O5A" );
        TrieAdd( EV_CTRL_CURSOR_DOWN, "\033O5B" );
        TrieAdd( EV_CTRL_CURSOR_RIGHT, "\033O5C" );
        TrieAdd( EV_CTRL_CURSOR_LEFT, "\033O5D" );
    }
    return( ret );
}
示例#14
0
static int do_parse( void )
/*************************/
{
    char        buff[80];
    char        input[80];
    tix_token   tok;
    unsigned    code;
    char        c;

    tok = get_tix_token( buff );
    for( ;; ) {
        if( tok == TT_EOF ) break;
        if( tok != TT_STRING ) {
            tix_error( "expecting directive" );
            return( 0 );
        }
        if( strcasecmp( buff, "display" ) == 0 ) {
            code = get_tix_code( (unsigned char *)buff );
            if( code == ~0U ) return( 0 );
            tok = get_tix_token( buff );
            if( tok == TT_EOF ) break;
            if( tok == TT_STRING ) {
                if( strcasecmp( buff, "alt" ) != 0 ) {
                    tix_error( "expecting alt" );
                    return( 0 );
                }
                tok = get_tix_token( buff );
                if( tok == TT_EOF ) break;
                c = find_acs_map( buff[0], acs_chars );
                if( c != '\0' ) {
                    ti_alt_map_set( code );
                } else {
                    c = find_acs_map( buff[0], acs_default );
                    if( c == '\0' ) {
                        c = buff[0];
                        ti_alt_map_set( code );
                    }
                }
                buff[0] = c;
            }
            if( tok != TT_CODE ) {
                tix_error( "expecting display code" );
                return( 0 );
            }
            ti_char_map[code][0] = buff[0];
            tok = get_tix_token( buff );
        } else if( strcasecmp( buff, "key" ) == 0 ) {
            code = get_tix_code( (unsigned char *)buff );
            if( code == ~0U ) return( 0 );
            input[0] = '\0';
            for( ;; ) {
                tok = get_tix_token( buff );
                if( tok != TT_CODE ) break;
                strcat( input, buff );
            }
            TrieAdd( code, input );
        } else {
            tix_error( "unknown directive" );
        }
    }
    return( 1 );
}