src/mess/hashfile.c
| r2467 | r2468 | |
| 22 | 22 | object_pool *pool; |
| 23 | 23 | unsigned int functions[IO_COUNT]; |
| 24 | 24 | |
| 25 | | struct hash_info **preloaded_hashes; |
| 25 | hash_info **preloaded_hashes; |
| 26 | 26 | int preloaded_hash_count; |
| 27 | 27 | |
| 28 | 28 | void (*error_proc)(const char *message); |
| r2467 | r2468 | |
| 46 | 46 | int done; |
| 47 | 47 | |
| 48 | 48 | int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const char *hash); |
| 49 | | void (*use_proc)(hash_file *hashfile, void *param, struct hash_info *hi); |
| 49 | void (*use_proc)(hash_file *hashfile, void *param, hash_info *hi); |
| 50 | 50 | void (*error_proc)(const char *message); |
| 51 | 51 | void *param; |
| 52 | 52 | |
| 53 | 53 | enum hash_parse_position pos; |
| 54 | 54 | char **text_dest; |
| 55 | | struct hash_info *hi; |
| 55 | hash_info *hi; |
| 56 | 56 | }; |
| 57 | 57 | |
| 58 | 58 | |
| r2467 | r2468 | |
| 122 | 122 | { |
| 123 | 123 | struct hash_parse_state *state = (struct hash_parse_state *) data; |
| 124 | 124 | const char *name; |
| 125 | | struct hash_info *hi; |
| 125 | hash_info *hi; |
| 126 | 126 | char **text_dest; |
| 127 | 127 | char hash_string[HASH_BUF_SIZE]; |
| 128 | 128 | unsigned int functions, all_functions; |
| r2467 | r2468 | |
| 207 | 207 | /* do we use this hash? */ |
| 208 | 208 | if (!state->selector_proc || state->selector_proc(state->hashfile, state->param, name, hash_string)) |
| 209 | 209 | { |
| 210 | | hi = pool_malloc(state->hashfile->pool, sizeof(struct hash_info)); |
| 210 | hi = pool_malloc(state->hashfile->pool, sizeof(hash_info)); |
| 211 | 211 | if (!hi) |
| 212 | 212 | return; |
| 213 | 213 | memset(hi, 0, sizeof(*hi)); |
| r2467 | r2468 | |
| 296 | 296 | |
| 297 | 297 | static void hashfile_parse(hash_file *hashfile, |
| 298 | 298 | int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const char *hash), |
| 299 | | void (*use_proc)(hash_file *hashfile, void *param, struct hash_info *hi), |
| 299 | void (*use_proc)(hash_file *hashfile, void *param, hash_info *hi), |
| 300 | 300 | void (*error_proc)(const char *message), |
| 301 | 301 | void *param) |
| 302 | 302 | { |
| r2467 | r2468 | |
| 349 | 349 | |
| 350 | 350 | /* ----------------------------------------------------------------------- */ |
| 351 | 351 | |
| 352 | | static void preload_use_proc(hash_file *hashfile, void *param, struct hash_info *hi) |
| 352 | static void preload_use_proc(hash_file *hashfile, void *param, hash_info *hi) |
| 353 | 353 | { |
| 354 | | struct hash_info **new_preloaded_hashes; |
| 354 | hash_info **new_preloaded_hashes; |
| 355 | 355 | |
| 356 | 356 | new_preloaded_hashes = pool_realloc(hashfile->pool, hashfile->preloaded_hashes, |
| 357 | 357 | (hashfile->preloaded_hash_count + 1) * sizeof(*new_preloaded_hashes)); |
| r2467 | r2468 | |
| 428 | 428 | struct hashlookup_params |
| 429 | 429 | { |
| 430 | 430 | const char *hash; |
| 431 | | struct hash_info *hi; |
| 431 | hash_info *hi; |
| 432 | 432 | }; |
| 433 | 433 | |
| 434 | 434 | |
| r2467 | r2468 | |
| 442 | 442 | |
| 443 | 443 | |
| 444 | 444 | |
| 445 | | static void singular_use_proc(hash_file *hashfile, void *param, struct hash_info *hi) |
| 445 | static void singular_use_proc(hash_file *hashfile, void *param, hash_info *hi) |
| 446 | 446 | { |
| 447 | 447 | struct hashlookup_params *hlparams = (struct hashlookup_params *) param; |
| 448 | 448 | hlparams->hi = hi; |
| r2467 | r2468 | |
| 450 | 450 | |
| 451 | 451 | |
| 452 | 452 | |
| 453 | | const struct hash_info *hashfile_lookup(hash_file *hashfile, const char *hash) |
| 453 | const hash_info *hashfile_lookup(hash_file *hashfile, const char *hash) |
| 454 | 454 | { |
| 455 | 455 | struct hashlookup_params param; |
| 456 | 456 | int i; |
src/mess/hashfile.h
| r2467 | r2468 | |
| 6 | 6 | |
| 7 | 7 | *********************************************************************/ |
| 8 | 8 | |
| 9 | | #ifndef HASHFILE_H |
| 10 | | #define HASHFILE_H |
| 9 | #ifndef __HASHFILE_H__ |
| 10 | #define __HASHFILE_H__ |
| 11 | 11 | |
| 12 | 12 | #include "driver.h" |
| 13 | 13 | #include "hash.h" |
| 14 | 14 | |
| 15 | 15 | |
| 16 | | struct hash_info |
| 16 | /*************************************************************************** |
| 17 | TYPE DEFINITIONS |
| 18 | ***************************************************************************/ |
| 19 | |
| 20 | typedef struct _hash_info hash_info; |
| 21 | struct _hash_info |
| 17 | 22 | { |
| 18 | 23 | char hash[HASH_BUF_SIZE]; |
| 19 | 24 | const char *longname; |
| r2467 | r2468 | |
| 26 | 31 | typedef struct _hash_file hash_file; |
| 27 | 32 | |
| 28 | 33 | |
| 34 | |
| 35 | /*************************************************************************** |
| 36 | FUNCTION PROTOTYPES |
| 37 | ***************************************************************************/ |
| 38 | |
| 29 | 39 | /* opens a hash file; if is_preload is non-zero, the entire file is preloaded */ |
| 30 | 40 | hash_file *hashfile_open(const char *sysname, int is_preload, |
| 31 | 41 | void (*error_proc)(const char *message)); |
| r2467 | r2468 | |
| 38 | 48 | void hashfile_close(hash_file *hashfile); |
| 39 | 49 | |
| 40 | 50 | /* looks up information in a hash file */ |
| 41 | | const struct hash_info *hashfile_lookup(hash_file *hashfile, const char *hash); |
| 51 | const hash_info *hashfile_lookup(hash_file *hashfile, const char *hash); |
| 42 | 52 | |
| 43 | 53 | /* performs a syntax check on a hash file */ |
| 44 | 54 | int hashfile_verify(const char *sysname, void (*error_proc)(const char *message)); |
| r2467 | r2468 | |
| 47 | 57 | unsigned int hashfile_functions_used(hash_file *hashfile, iodevice_t devtype); |
| 48 | 58 | |
| 49 | 59 | |
| 50 | | #endif /* HASHFILE_H */ |
| 60 | #endif /* __HASHFILE_H__ */ |