Exemplo n.º 1
0
Arquivo: files.c Projeto: srfrog/epic5
/* RETURNS A MALLOCED STRING, EH! */
static char *	read_from_dbm (int refnum, char *key)
{
	Dbm *db;
	Datum k, d;

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

	k.dptr = key;
	k.dsize = strlen(key);
	d = sdbm_fetch(db->db, k);
	if (d.dptr == NULL)
		return NULL;

	return Datum_to_string(d);
}
Exemplo n.º 2
0
Arquivo: init.c Projeto: 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;
}
Exemplo n.º 3
0
Arquivo: init.c Projeto: Chatto/VGdesk
static VALUE
fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
{
    datum key, value;
    struct dbmdata *dbmp;
    DBM *dbm;

    ExportStringValue(keystr);
    key.dptr = RSTRING_PTR(keystr);
    key.dsize = RSTRING_LENINT(keystr);

    GetDBM2(obj, dbmp, dbm);
    value = sdbm_fetch(dbm, key);
    if (value.dptr == 0) {
	if (ifnone == Qnil && rb_block_given_p())
	    return rb_yield(rb_external_str_new(key.dptr, key.dsize));
	return ifnone;
    }
    return rb_external_str_new(value.dptr, value.dsize);
}
Exemplo n.º 4
0
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);
}