コード例 #1
0
ファイル: files.c プロジェクト: srfrog/epic5
static char *	all_keys_for_dbm (int refnum)
{
	Dbm *	db;
	Datum 	k;
	char *	retval = NULL;
	size_t	clue = 0;
	char *	x;

	if (!(db = lookup_dbm(refnum)))
		return NULL;

	k = sdbm_firstkey(db->db);
	x = Datum_to_string(k);
	malloc_strcat_wordlist_c(&retval, space, x, &clue);
	new_free(&x);

	for (;;)
	{
		k = sdbm_nextkey(db->db);
		if (k.dptr == NULL)
			break;
		x = Datum_to_string(k);
		malloc_strcat_wordlist_c(&retval, space, x, &clue);
		new_free(&x);
	}

	return retval;
}
コード例 #2
0
ファイル: files.c プロジェクト: srfrog/epic5
static char *	iterate_on_dbm (int refnum, int restart)
{
	Dbm *	db;
	Datum 	k;

	if (!(db = lookup_dbm(refnum)))
		return NULL;

	if (restart)
		k = sdbm_firstkey(db->db);
	else
		k = sdbm_nextkey(db->db);

	return Datum_to_string(k);
}
コード例 #3
0
ファイル: init.c プロジェクト: Chatto/VGdesk
/*
 * call-seq:
 *   sdbm.key(value) -> key
 *
 * Returns the +key+ associated with the given +value+. If more than one
 * +key+ corresponds to the given +value+, then the first key to be found
 * will be returned. If no keys are found, +nil+ will be returned.
 */
static VALUE
fsdbm_key(VALUE obj, VALUE valstr)
{
    datum key, val;
    struct dbmdata *dbmp;
    DBM *dbm;

    ExportStringValue(valstr);
    val.dptr = RSTRING_PTR(valstr);
    val.dsize = RSTRING_LENINT(valstr);

    GetDBM2(obj, dbmp, dbm);
    for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
	val = sdbm_fetch(dbm, key);
	if (val.dsize == RSTRING_LEN(valstr) &&
	    memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
	    return rb_external_str_new(key.dptr, key.dsize);
    }
    return Qnil;
}
コード例 #4
0
ファイル: lockview.c プロジェクト: Freizeitsoldat/foswiki
int main(int argc, char *argv[]) {
	DBM *db;
	datum key, val;
	int count = 1;

	if (argc != 2) {
                printf("%s - dumps mod_dav lock database\n", argv[0]);
		printf("%s: no database specified (don't include extension)\n", argv[0]);
		return(-1);
	}

	if (CheckFile(argv, ".pag"))
		return(-1);
	if (CheckFile(argv, ".dir"))
		return(-1);
		
	db = sdbm_open((char *) argv[1],
		     O_RDONLY | O_BINARY, DAV_FS_MODE_FILE);

	key = sdbm_firstkey(db);
	if (key.dsize == 0) {
	    printf("%s: no outstanding locks.\n", argv[0]);
	}
	else {
	    while(key.dsize) {
		printf("[Lock record #%3d]\n", count++);
		val = sdbm_fetch(db, key);
		if (display_info(key, val) == -1)
		    return(-1);
		key = sdbm_nextkey(db);
	    }
	}

	sdbm_close(db);
	exit(0);
}