Annotation of early-roguelike/urogue/dict.h, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: dict.h
3:
4: UltraRogue: The Ultimate Adventure in the Dungeons of Doom
5: Copyright (C) 1995 Herb Chong
6: All rights reserved.
7:
8: See the file LICENSE.TXT for full copyright and licensing information.
9: */
10:
11: /*-----------------
12: Change history:
13: (AK:04/03/95) - Added hook for extensions to dictionary structure.
14: (AK:04/04/95) - Added dictionary signature, table of contents and parameter
15: structure defintions and fields in DICTIONARY structure
16: -------------------*/
17:
18: #ifndef dict_h_included
19: #define dict_h_included
20:
21: static char dict_sccsid[] = "%W% %G%";
22:
23: #ifndef TRUE
24: #define TRUE 1
25: #define FALSE 0
26: #endif
27:
28: #define DICT_NONE 0x00000000 /* no flags set */
29: #define DICT_VALIDATE 0xdeadbeef /* look for this in every dictionary structure */
30: #define DICT_ENTRY_NONE -1 /* index of invalid entry */
31:
32: typedef unsigned char BOOLEANC;
33:
34: /*------------------
35: string table entry
36: ------------------*/
37: typedef struct string_entry {
38: long string_offset; /* offset in string array */
39: long count; /* number of occurrences of string */
40: long next; /* offset of next in hash chain */
41: void *any_ptr; /* free pointer */
42: unsigned long flags; /* user definable flag value for string */
43: unsigned long hash_value; /* hash value of string using hash function */
44: } STRING_ENTRY;
45:
46: /*--------------------
47: Dictionary signature (AK:04/04/95)
48: --------------------*/
49: typedef struct dict_sig_ { /* Dictionary signature */
50: unsigned long check_value; /* 0xdeadbeef */
51: int toc_size; /* # of entries in Table of Contents */
52: long nparms; /* # of parameters */
53: unsigned long checksum; /* Checksum for TOC */
54: } DICT_SIG;
55:
56: /*----------------------------------
57: Dictionary table of contents entry (AK:04/04/95)
58: ----------------------------------*/
59: typedef struct TOC_entry_ { /* Dictionary table of contents entry */
60: char id[5]; /* Field identifier: */
61: long offset; /* Offset (bytes) of entry in file */
62: long size; /* Size (bytes) of entry */
63: void *ptr; /* Where entry is stored in memory */
64: unsigned long checksum; /* Checksum of entry */
65: int type; /* 0=ordinary ; 1=EVECTOR ; 2=NULL */
66: } DICT_TOC_ENTRY;
67:
68: /*--------------------------------
69: Dictionary parameter table entry (AK:04/04/95)
70: --------------------------------*/
71: typedef struct dict_parm_entry_ { /* Dictionary parameter table entry */
72: char id[13]; /* Parameter identifier */
73: unsigned long value; /* Parameter value */
74: } DICT_PARM_ENTRY;
75:
76:
77: /*---------------------------
78: Hash dictionary information
79: ---------------------------*/
80: typedef struct dictionary {
81: unsigned long check_value; /* check validation value */
82: unsigned long flags; /* flag values */
83: long entry_count; /* number of used entries in each table */
84:
85: char *string_array; /* storage for strings */
86: long array_size; /* number of bytes allocated */
87: long array_used; /* number of bytes occupied */
88: int array_growth_count; /* number of times grown */
89:
90: STRING_ENTRY *string_table; /* string table */
91: long string_max; /* max number of entries in string table */
92: long scan_string_index; /* current index into string table for scan */
93: int string_growth_count; /* number of times had to grow string table */
94:
95: long *chains; /* vector of array indices to hash entries */
96: int longest_chain_length; /* longest chain length in hash table */
97: int allowable_chain_length; /* chain lengths always < this */
98: long table_size; /* number of elements in hash entries vector */
99: unsigned long hash_mask; /* mask for doing mod() function */
100: int hash_growth_count; /* number of times had to grow hash table */
101:
102: void *ext; /* Hook for extensions to the dictionary (AK:04/03/95) */
103:
104: DICT_SIG *sig; /* Signature (AK:04/04/95) */
105: DICT_TOC_ENTRY *toc; /* Table of contents (AK:04/04/95) */
106: DICT_PARM_ENTRY *parm; /* Parameters (AK:04/04/95) */
107:
108: } DICTIONARY;
109:
110: /*--------------------------------------------------------------
111: dict_create: create a dictionary and initialize its structures
112: --------------------------------------------------------------*/
113: extern DICTIONARY *dict_create(
114: const long toc_size,
115: const long initial_string_count,
116: const long initial_hash_entries,
117: const long max_chain_length );
118:
119: /*-------------------------------------------------
120: dict_delete: deletes an entry from the dictionary
121: -------------------------------------------------*/
122: extern BOOLEANC dict_delete(
123: const DICTIONARY *dict,
124: const char *s,
125: const long count );
126:
127: /*---------------------------------------------------
128: dict_destroy: discard a dictionary and its contents
129: ---------------------------------------------------*/
130: extern BOOLEANC dict_destroy(
131: DICTIONARY *dict );
132:
133: /*------------------------------------------------
134: dict_export: write a dictionary to an ASCII file
135: ------------------------------------------------*/
136: extern BOOLEANC dict_export(
137: DICTIONARY *dict,
138: const char *fname );
139:
140: /*-------------------------------------------------
141: dict_import: read a dictionary from an ASCII file
142: -------------------------------------------------*/
143: extern DICTIONARY *dict_import(
144: const char *dict_fname,
145: const long initial_string_count,
146: const long initial_hash_entries,
147: const long max_chain_length );
148:
149: /*------------------------------------------------------------------
150: dict_insert: add entries into the dictionary, growing as necessary
151: ------------------------------------------------------------------*/
152: extern STRING_ENTRY *dict_insert(
153: DICTIONARY *dict,
154: char *s,
155: const long occurences,
156: const unsigned long flags,
157: void *any_ptr,
158: long *number );
159:
160: /*----------------------------------------------------
161: dict_load: read a dictionary from a file into memory
162: ----------------------------------------------------*/
163: extern DICTIONARY *dict_load(
164: const char *fname );
165:
166: /*-----------------------------------------------------------------
167: dict_merge: merges the contents of a dictionary into another one,
168: updating the contents of the destination
169: -----------------------------------------------------------------*/
170: extern BOOLEANC dict_merge(
171: const DICTIONARY *dst,
172: const DICTIONARY *src,
173: const BOOLEANC move );
174:
175: /*----------------------------------------------------
176: dict_save: save a dictionary from memory into a file
177: ----------------------------------------------------*/
178: extern BOOLEANC dict_save(
179: DICTIONARY *dict,
180: const char *fname );
181:
182: /*-----------------------------------------------
183: dict_scan_begin: begin a scan of the dictionary
184: -----------------------------------------------*/
185: extern BOOLEANC dict_scan_begin(
186: DICTIONARY *dict );
187:
188: /*--------------------------------------------
189: dict_scan_next: get the next entry in a scan
190: --------------------------------------------*/
191: extern STRING_ENTRY *dict_scan_next(
192: DICTIONARY *dict );
193:
194: /*-----------------------------------------------
195: dict_search: look for entries in the dictionary
196: -----------------------------------------------*/
197: extern STRING_ENTRY *dict_search(
198: const DICTIONARY *dict,
199: const char *s,
200: long *number );
201:
202: /*----------------------------------------------------------------------
203: dict_string_by_number: return string pointer for a given string number
204: ----------------------------------------------------------------------*/
205: extern STRING_ENTRY *dict_string_by_number(
206: const DICTIONARY *dict,
207: const long number );
208:
209: /*----------------------------------------------------------
210: dict_union: merges contents of 2 dictionaries into a third
211: ----------------------------------------------------------*/
212: extern DICTIONARY *dict_union(
213: const DICTIONARY *dict1,
214: const DICTIONARY *dict2 );
215:
216: #endif /* dict_h_included */
CVSweb