Example #1
0
File: fp.c Project: fanf2/qp
static bool
next_rec(Trie *t, const char **pkey, size_t *plen, void **pval) {
	if(isbranch(t)) {
		// Recurse to find either this leaf (*pkey != NULL)
		// or the next one (*pkey == NULL).
		Tbitmap b = twigbit(t, *pkey, *plen);
		uint s, m; TWIGOFFMAX(s, m, t, b);
		for(; s < m; s++)
			if(next_rec(twig(t, s), pkey, plen, pval))
				return(true);
		return(false);
	}
	// We have found the next leaf.
	if(*pkey == NULL) {
		*pkey = t->leaf.key;
		*plen = strlen(*pkey);
		*pval = t->leaf.val;
		return(true);
	}
	// We have found this leaf, so start looking for the next one.
	if(strcmp(*pkey, t->leaf.key) == 0) {
		*pkey = NULL;
		*plen = 0;
		return(false);
	}
	// No match.
	return(false);
}
Example #2
0
File: fp.c Project: fanf2/qp
bool
Tnextl(Tbl *tbl, const char **pkey, size_t *plen, void **pval) {
	if(tbl == NULL) {
		*pkey = NULL;
		*plen = 0;
		return(NULL);
	}
	return(next_rec(&tbl->root, pkey, plen, pval));
}
Example #3
0
bool lemur::file::Keyfile::getNext( char* key, int maxKeySize, void* value, 
                                    int& actualSize, int maxValueSize ) const {
  int len; // for key length
  int result = next_rec( _handle, key, &len, maxKeySize,
                         value, &actualSize, maxValueSize );
  // null terminate
  key[len] = '\0';
  return !result;
}
Example #4
0
/* PUBLIC					HTAAFile_readPasswdRec()
**			READ A RECORD FROM THE PASSWORD FILE
** ON ENTRY:
**	fp		open password file
**	out_username	buffer to put the read username, must be at
**			least MAX_USERNAME_LEN+1 characters long.
**	out_passwd	buffer to put the read password, must be at
**			least MAX_PASSWORD_LEN+1 characters long.
** ON EXIT:
**	returns		EOF on end of file,
**			otherwise the number of read fields
**			(i.e. in a correct case returns 2).
**	out_username	contains the null-terminated read username.
**	out_password	contains the null-terminated read password.
**
** FORMAT OF PASSWORD FILE:
**	username:password:maybe real name or other stuff
**				(may include even colons)
**
**	There may be whitespace (blanks or tabs) in the beginning and
**	the end of each field. They are ignored.
*/
PUBLIC int HTAAFile_readPasswdRec ARGS3(FILE *, fp,
					char *, out_username,
					char *, out_password)
{
    char terminator;
    
    terminator = HTAAFile_readField(fp, out_username, MAX_USERNAME_LEN);

    if (terminator == EOF) {				/* End of file */
	return EOF;
    }
    else if (terminator == CR  ||  terminator == LF) {	/* End of line */
	next_rec(fp);
	return 1;
    }
    else {
	HTAAFile_readField(fp, out_password, MAX_PASSWORD_LEN);
	next_rec(fp);
	return 2;
    }
}
Example #5
0
bool lemur::file::Keyfile::next( char* key, int& keyLength, char* value, int& valueLength ) {
  assert( key && "key cannot be null" );
  assert( value && "value cannot be null" );

  int error = next_rec( _handle,
                        key,
                        &keyLength,
                        keyLength,
                        value,
                        &valueLength,
                        valueLength );

  if( error && error != ateof_err )
    LEMUR_THROW( LEMUR_KEYFILE_IO_ERROR, "Caught an internal error while trying to fetch next record." );

  return error != ateof_err;
}
Example #6
0
bool lemur::file::Keyfile::getNext( char* key, int &len, int maxKeySize, void* value, 
                                    int& actualSize, int maxValueSize ) const {
  int result = next_rec( _handle, key, &len, maxKeySize,
                         value, &actualSize, maxValueSize );
  return !result;
}