Previous 15994 Revisions Next

r4161 Saturday 17th January, 2009 at 19:48:18 UTC by Nathan Woods
Cleanups
[src/mess]hashfile.c image.c image.h

src/mess/image.c
r4160r4161
16341634  pertaining to that image in the CRC database
16351635****************************************************************************/
16361636
1637const char *image_longname(const device_config *image)
1637/*-------------------------------------------------
1638    image_longname
1639-------------------------------------------------*/
1640
1641const char *image_longname(const device_config *device)
16381642{
1639   image_slot_data *slot = find_image_slot(image);
1643   image_slot_data *slot = find_image_slot(device);
16401644   image_checkhash(slot);
16411645   return slot->longname;
16421646}
16431647
16441648
16451649
1646const char *image_manufacturer(const device_config *image)
1650/*-------------------------------------------------
1651    image_manufacturer
1652-------------------------------------------------*/
1653
1654const char *image_manufacturer(const device_config *device)
16471655{
1648   image_slot_data *slot = find_image_slot(image);
1656   image_slot_data *slot = find_image_slot(device);
16491657   image_checkhash(slot);
16501658   return slot->manufacturer;
16511659}
16521660
16531661
16541662
1655const char *image_year(const device_config *image)
1663/*-------------------------------------------------
1664    image_year
1665-------------------------------------------------*/
1666
1667const char *image_year(const device_config *device)
16561668{
1657   image_slot_data *slot = find_image_slot(image);
1669   image_slot_data *slot = find_image_slot(device);
16581670   image_checkhash(slot);
16591671   return slot->year;
16601672}
16611673
16621674
16631675
1664const char *image_playable(const device_config *image)
1676/*-------------------------------------------------
1677    image_playable
1678-------------------------------------------------*/
1679
1680const char *image_playable(const device_config *device)
16651681{
1666   image_slot_data *slot = find_image_slot(image);
1682   image_slot_data *slot = find_image_slot(device);
16671683   image_checkhash(slot);
16681684   return slot->playable;
16691685}
16701686
16711687
16721688
1673const char *image_extrainfo(const device_config *image)
1689/*-------------------------------------------------
1690    image_extrainfo
1691-------------------------------------------------*/
1692
1693const char *image_extrainfo(const device_config *device)
16741694{
1675   image_slot_data *slot = find_image_slot(image);
1695   image_slot_data *slot = find_image_slot(device);
16761696   image_checkhash(slot);
16771697   return slot->extrainfo;
16781698}
src/mess/image.h
r4160r4161
280280  pertaining to that image in the CRC database
281281****************************************************************************/
282282
283const char *image_longname(const device_config *img);
284const char *image_manufacturer(const device_config *img);
285const char *image_year(const device_config *img);
286const char *image_playable(const device_config *img);
287const char *image_extrainfo(const device_config *img);
283const char *image_longname(const device_config *device);
284const char *image_manufacturer(const device_config *device);
285const char *image_year(const device_config *device);
286const char *image_playable(const device_config *device);
287const char *image_extrainfo(const device_config *device);
288288
289289
290290
src/mess/hashfile.c
r4160r4161
7171    CORE IMPLEMENTATION
7272***************************************************************************/
7373
74/*-------------------------------------------------
75    parse_error
76-------------------------------------------------*/
77
7478static void ATTR_PRINTF(2,3) parse_error(struct hash_parse_state *state, const char *fmt, ...)
7579{
7680   char buf[256];
r4160r4161
7983   if (state->error_proc)
8084   {
8185      va_start(va, fmt);
82      vsnprintf(buf, sizeof(buf) / sizeof(buf[0]), fmt, va);
86      vsnprintf(buf, ARRAY_LENGTH(buf), fmt, va);
8387      va_end(va);
84      state->error_proc(buf);
88      (*state->error_proc)(buf);
8589   }
8690}
8791
8892
8993
94/*-------------------------------------------------
95    unknown_tag
96-------------------------------------------------*/
97
9098static void unknown_tag(struct hash_parse_state *state, const char *tagname)
9199{
92100   parse_error(state, "[%lu:%lu]: Unknown tag: %s\n",
r4160r4161
97105
98106
99107
108/*-------------------------------------------------
109    unknown_attribute
110-------------------------------------------------*/
111
100112static void unknown_attribute(struct hash_parse_state *state, const char *attrname)
101113{
102114   parse_error(state, "[%lu:%lu]: Unknown attribute: %s\n",
r4160r4161
107119
108120
109121
122/*-------------------------------------------------
123    unknown_attribute_value
124-------------------------------------------------*/
125
110126static void unknown_attribute_value(struct hash_parse_state *state,
111127   const char *attrname, const char *attrvalue)
112128{
r4160r4161
118134
119135
120136
137/*-------------------------------------------------
138    start_handler
139-------------------------------------------------*/
140
121141static void start_handler(void *data, const char *tagname, const char **attributes)
122142{
123143   struct hash_parse_state *state = (struct hash_parse_state *) data;
r4160r4161
129149   iodevice_t device;
130150   int i;
131151
132   switch(state->pos++) {
133   case POS_ROOT:
134      if (!strcmp(tagname, "hashfile"))
135      {
136      }
137      else
138      {
139         unknown_tag(state, tagname);
140      }
141      break;
152   switch(state->pos++)
153   {
154      case POS_ROOT:
155         if (!strcmp(tagname, "hashfile"))
156         {
157         }
158         else
159         {
160            unknown_tag(state, tagname);
161         }
162         break;
142163
143   case POS_MAIN:
144      if (!strcmp(tagname, "hash"))
145      {
146         // we are now examining a hash tag
147         name = NULL;
148         memset(hash_string, 0, sizeof(hash_string));
149         all_functions = 0;
150         device = IO_COUNT;
164      case POS_MAIN:
165         if (!strcmp(tagname, "hash"))
166         {
167            // we are now examining a hash tag
168            name = NULL;
169            memset(hash_string, 0, sizeof(hash_string));
170            all_functions = 0;
171            device = IO_COUNT;
151172
152         while(attributes[0])
153         {
154            functions = 0;
155            if (!strcmp(attributes[0], "name"))
173            while(attributes[0])
156174            {
157               /* name attribute */
158               name = attributes[1];
175               functions = 0;
176               if (!strcmp(attributes[0], "name"))
177               {
178                  /* name attribute */
179                  name = attributes[1];
180               }
181               else if (!strcmp(attributes[0], "crc32"))
182               {
183                  /* crc32 attribute */
184                  functions = HASH_CRC;
185               }
186               else if (!strcmp(attributes[0], "md5"))
187               {
188                  /* md5 attribute */
189                  functions = HASH_MD5;
190               }
191               else if (!strcmp(attributes[0], "sha1"))
192               {
193                  /* sha1 attribute */
194                  functions = HASH_SHA1;
195               }
196               else if (!strcmp(attributes[0], "type"))
197               {
198                  /* type attribute */
199                  i = device_typeid(attributes[1]);
200                  if (i < 0)
201                     unknown_attribute_value(state, attributes[0], attributes[1]);
202                  else
203                     device = (iodevice_t) i;
204               }
205               else
206               {
207                  /* unknown attribute */
208                  unknown_attribute(state, attributes[0]);
209               }
210
211               if (functions)
212               {
213                  hash_data_insert_printable_checksum(hash_string, functions, attributes[1]);
214                  all_functions |= functions;
215               }
216
217               attributes += 2;
159218            }
160            else if (!strcmp(attributes[0], "crc32"))
219
220            if (device == IO_COUNT)
161221            {
162               /* crc32 attribute */
163               functions = HASH_CRC;
222               for (i = 0; i < IO_COUNT; i++)
223                  state->hashfile->functions[i] |= all_functions;
164224            }
165            else if (!strcmp(attributes[0], "md5"))
166            {
167               /* md5 attribute */
168               functions = HASH_MD5;
169            }
170            else if (!strcmp(attributes[0], "sha1"))
171            {
172               /* sha1 attribute */
173               functions = HASH_SHA1;
174            }
175            else if (!strcmp(attributes[0], "type"))
176            {
177               /* type attribute */
178               i = device_typeid(attributes[1]);
179               if (i < 0)
180                  unknown_attribute_value(state, attributes[0], attributes[1]);
181               else
182                  device = (iodevice_t) i;
183            }
184225            else
185            {
186               /* unknown attribute */
187               unknown_attribute(state, attributes[0]);
188            }
226               state->hashfile->functions[device] |= all_functions;
189227
190            if (functions)
228            /* do we use this hash? */
229            if (!state->selector_proc || state->selector_proc(state->hashfile, state->param, name, hash_string))
191230            {
192               hash_data_insert_printable_checksum(hash_string, functions, attributes[1]);
193               all_functions |= functions;
194            }
231               hi = pool_malloc(state->hashfile->pool, sizeof(hash_info));
232               if (!hi)
233                  return;
234               memset(hi, 0, sizeof(*hi));
195235
196            attributes += 2;
197         }
236               hi->longname = pool_strdup(state->hashfile->pool, name);
237               if (!hi->longname)
238                  return;
198239
199         if (device == IO_COUNT)
200         {
201            for (i = 0; i < IO_COUNT; i++)
202               state->hashfile->functions[i] |= all_functions;
240               strcpy(hi->hash, hash_string);
241               state->hi = hi;
242            }
203243         }
204244         else
205            state->hashfile->functions[device] |= all_functions;
206
207         /* do we use this hash? */
208         if (!state->selector_proc || state->selector_proc(state->hashfile, state->param, name, hash_string))
209245         {
210            hi = pool_malloc(state->hashfile->pool, sizeof(hash_info));
211            if (!hi)
212               return;
213            memset(hi, 0, sizeof(*hi));
214
215            hi->longname = pool_strdup(state->hashfile->pool, name);
216            if (!hi->longname)
217               return;
218
219            strcpy(hi->hash, hash_string);
220            state->hi = hi;
246            unknown_tag(state, tagname);
221247         }
222      }
223      else
224      {
225         unknown_tag(state, tagname);
226      }
227      break;
248         break;
228249
229   case POS_HASH:
230      text_dest = NULL;
250      case POS_HASH:
251         text_dest = NULL;
231252
232      if (!strcmp(tagname, "year"))
233         text_dest = (char **) &state->hi->year;
234      else if (!strcmp(tagname, "manufacturer"))
235         text_dest = (char **) &state->hi->manufacturer;
236      else if (!strcmp(tagname, "status"))
237         text_dest = (char **) &state->hi->playable;
238      else if (!strcmp(tagname, "extrainfo"))
239         text_dest = (char **) &state->hi->extrainfo;
240      else
241         unknown_tag(state, tagname);
253         if (!strcmp(tagname, "year"))
254            text_dest = (char **) &state->hi->year;
255         else if (!strcmp(tagname, "manufacturer"))
256            text_dest = (char **) &state->hi->manufacturer;
257         else if (!strcmp(tagname, "status"))
258            text_dest = (char **) &state->hi->playable;
259         else if (!strcmp(tagname, "extrainfo"))
260            text_dest = (char **) &state->hi->extrainfo;
261         else
262            unknown_tag(state, tagname);
242263
243      if (text_dest && state->hi)
244         state->text_dest = text_dest;
245      break;
264         if (text_dest && state->hi)
265            state->text_dest = text_dest;
266         break;
246267   }
247268}
248269
249270
250271
272/*-------------------------------------------------
273    end_handler
274-------------------------------------------------*/
275
251276static void end_handler(void *data, const char *name)
252277{
253278   struct hash_parse_state *state = (struct hash_parse_state *) data;
254279   state->text_dest = NULL;
255280
256   switch(--state->pos) {
257   case POS_ROOT:
258   case POS_HASH:
259      break;
281   switch(--state->pos)
282   {
283      case POS_ROOT:
284      case POS_HASH:
285         break;
260286
261   case POS_MAIN:
262      if (state->hi)
263      {
264         if (state->use_proc)
265            state->use_proc(state->hashfile, state->param, state->hi);
266         state->hi = NULL;
267      }
268      break;
287      case POS_MAIN:
288         if (state->hi)
289         {
290            if (state->use_proc)
291               (*state->use_proc)(state->hashfile, state->param, state->hi);
292            state->hi = NULL;
293         }
294         break;
269295   }
270296}
271297
272298
273299
300/*-------------------------------------------------
301    data_handler
302-------------------------------------------------*/
303
274304static void data_handler(void *data, const XML_Char *s, int len)
275305{
276306   struct hash_parse_state *state = (struct hash_parse_state *) data;
r4160r4161
294324
295325
296326
327/*-------------------------------------------------
328    hashfile_parse
329-------------------------------------------------*/
330
297331static void hashfile_parse(hash_file *hashfile,
298332   int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const char *hash),
299333   void (*use_proc)(hash_file *hashfile, void *param, hash_info *hi),
r4160r4161
347381
348382
349383
350/* ----------------------------------------------------------------------- */
384/*-------------------------------------------------
385    preload_use_proc
386-------------------------------------------------*/
351387
352388static void preload_use_proc(hash_file *hashfile, void *param, hash_info *hi)
353389{
r4160r4161
364400
365401
366402
403/*-------------------------------------------------
404    hashfile_open_options
405-------------------------------------------------*/
406
367407hash_file *hashfile_open_options(core_options *opts, const char *sysname, int is_preload,
368408   void (*error_proc)(const char *message))
369409{
r4160r4161
408448
409449
410450
451/*-------------------------------------------------
452    hashfile_open
453-------------------------------------------------*/
454
411455hash_file *hashfile_open(const char *sysname, int is_preload,
412456   void (*error_proc)(const char *message))
413457{
r4160r4161
416460
417461
418462
463/*-------------------------------------------------
464    hashfile_close
465-------------------------------------------------*/
466
419467void hashfile_close(hash_file *hashfile)
420468{
421469   if (hashfile->file)
r4160r4161
425473
426474
427475
476/*-------------------------------------------------
477    singular_selector_proc
478-------------------------------------------------*/
479
428480struct hashlookup_params
429481{
430482   const char *hash;
431483   hash_info *hi;
432484};
433485
434
435
436486static int singular_selector_proc(hash_file *hashfile, void *param, const char *name, const char *hash)
437487{
438488   struct hashlookup_params *hlparams = (struct hashlookup_params *) param;
r4160r4161
442492
443493
444494
495/*-------------------------------------------------
496    singular_use_proc
497-------------------------------------------------*/
498
445499static void singular_use_proc(hash_file *hashfile, void *param, hash_info *hi)
446500{
447501   struct hashlookup_params *hlparams = (struct hashlookup_params *) param;
r4160r4161
450504
451505
452506
507/*-------------------------------------------------
508    hashfile_lookup
509-------------------------------------------------*/
510
453511const hash_info *hashfile_lookup(hash_file *hashfile, const char *hash)
454512{
455513   struct hashlookup_params param;
r4160r4161
471529
472530
473531
532/*-------------------------------------------------
533    hashfile_functions_used
534-------------------------------------------------*/
535
474536unsigned int hashfile_functions_used(hash_file *hashfile, iodevice_t devtype)
475537{
476538   assert(devtype >= 0);
r4160r4161
480542
481543
482544
545/*-------------------------------------------------
546    hashfile_verify
547-------------------------------------------------*/
548
483549int hashfile_verify(const char *sysname, void (*my_error_proc)(const char *message))
484550{
485551   hash_file *hashfile;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team