64 lines (57 with data), 1.6 kB
/*
* arbitrary storage stuff in player.c - mainly used to cut back in
* file usage. ie. don't create more files for quicktypers etc.
* The "password" is for security on your values.
* (in particular the prevention of overwriting). -- Dredd.
* Shouldn't be used for anything secure - G.
*/
/*
* Dredd 1999
* Should be rewritten to use "hash_value"
* (auto-resizing hash_table)
*/
array storage = [ ];
add_store(name, value, password) {
int x;
if (!name) return 0;
if (!pointerp(storage)) {
storage = [ "%"+name+"%", value, password ];
return 1;
}
x = index(storage, "%"+name+"%");
if (x > -1) {
if ((storage[x+2]) && (password != (storage[x+2]))) return 0;
storage[x+1] = value;
return 1;
}
storage = storage + [ "%"+name+"%", value, password ];
return 1;
}
remove_store(name, password) {
int x;
array a, b;
if (!name) return 0;
if (!storage) return 0;
x = index(storage, "%"+name+"%");
if (x < 0) return 0;
if ((storage[x+2]) && (password != (storage[x+2]))) return 0;
if (x == 0) storage = storage[3..];
else {
a = storage[..x-1];
b = storage[x+3..];
storage = a + b;
}
return 1;
}
query_store(name, password) {
int x;
if (!name) return 0;
if (!storage) return 0;
x = index(storage, "%"+name+"%");
if (x == -1) return 0;
if ((storage[x+2]) && (password != (storage[x+2]))) return 0;
return (storage[x + 1]);
}
query_storage() {
return storage;
}