Previous 15994 Revisions Next

r7759 Wednesday 7th April, 2010 at 17:08:37 UTC by Wilbert Pol
Improvements to -listsoftware command:
- Added DTD.
- Software lists are now only displayed once.
[src/mess]climess.c

src/mess/climess.c
r7758r7759
113113    info_listsoftware - output the list of
114114    software supported by a given game or set of
115115    games
116   TODO: Avoid outputting lists more than once.
117   TODO: Add DTD.
118116   TODO: Add all information read from the source files
117    Possible improvement: use a sorted list for
118        identifying duplicate lists.
119119-------------------------------------------------*/
120120
121121int info_listsoftware(core_options *options, const char *gamename)
122122{
123123   FILE *out = stdout;
124   int nr_lists = 0;
125   char ** lists = NULL;
126   int list_idx = 0;
124127
128   /* First determine the maximum number of lists we might encounter */
129   for ( int drvindex = 0; drivers[drvindex] != NULL; drvindex++ )
130   {
131      if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 )
132      {
133         /* allocate the machine config */
134         machine_config *config = machine_config_alloc( drivers[drvindex]->machine_config );
135
136         for (const device_config *dev = config->devicelist.first(); dev != NULL; dev = dev->next)
137         {
138            if ( ! strcmp( dev->tag(), __SOFTWARE_LIST_TAG ) )
139            {
140               software_list_config *swlist = (software_list_config *)dev->inline_config;
141
142               for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ )
143               {
144                  if ( swlist->list_name[i] && *swlist->list_name[i] )
145                     nr_lists++;
146               }
147            }
148         }
149
150         /* free the machine config */
151         machine_config_free( config );
152      }
153   }
154
155   lists = global_alloc_array( char *, nr_lists );
156
125157   fprintf( out,
126158         "<?xml version=\"1.0\"?>\n"
159         "<!ELEMENT softwarelists (softwarelist*)\n"
160         "\t<!ELEMENT softwarelist (software+)>\n"
161         "\t\t<!ATTLIST softwarelist name CDATA #REQUIRED>\n"
162         "\t\t<!ATTLIST softwarelist description CDATA #IMPLIED>\n"
163         "\t\t<!ELEMENT software (description, year?, publisher, part*)>\n"
164         "\t\t\t<!ATTLIST software name CDATA #REQUIRED>\n"
165         "\t\t\t<!ATTLIST software cloneof CDATA #IMPLIED>\n"
166         "\t\t\t<!ATTLIST software supported (yes|partial|no) \"yes\">\n"
167         "\t\t\t<!ELEMENT description (#PCDATA)>\n"
168         "\t\t\t<!ELEMENT year (#PCDATA)>\n"
169         "\t\t\t<!ELEMENT publisher (#PCDATA)>\n"
170         "\t\t\t<!ELEMENT part (dataarea*)>\n"
171         "\t\t\t\t<!ATTLIST part name CDATA #REQUIRED>\n"
172         "\t\t\t\t<!ATTLIST part interface CDATA #REQUIRED>\n"
173         "\t\t\t\t<!ATTLIST part feature CDATA #IMPLIED>\n"
174         "\t\t\t\t<!ELEMENT dataarea (rom*)>\n"
175         "\t\t\t\t\t<!ATTLIST dataarea name CDATA #REQUIRED>\n"
176         "\t\t\t\t\t<!ATTLIST dataarea size CDATA #REQUIRED>\n"
177         "\t\t\t\t\t<!ATTLIST dataarea databits (8|16|32|64) \"8\">\n"
178         "\t\t\t\t\t<!ATTLIST dataarea endian (big|little) \"little\">\n"
179         "\t\t\t\t\t<!ELEMENT rom EMPTY>\n"
180         "\t\t\t\t\t\t<!ATTLIST rom name CDATA #IMPLIED>\n"
181         "\t\t\t\t\t\t<!ATTLIST rom size CDATA #REQUIRED>\n"
182         "\t\t\t\t\t\t<!ATTLIST rom crc CDATA #IMPLIED>\n"
183         "\t\t\t\t\t\t<!ATTLIST rom md5 CDATA #IMPLIED>\n"
184         "\t\t\t\t\t\t<!ATTLIST rom sha1 CDATA #IMPLIED>\n"
185         "\t\t\t\t\t\t<!ATTLIST rom offset CDATA #IMPLIED>\n"
186         "\t\t\t\t\t\t<!ATTLIST rom status (baddump|nodump|good) \"good\">\n"
187         "\t\t\t\t\t\t<!ATTLIST rom loadflag (load16_byte|load16_word|load16_word_swap|load32_byte|load32_word|load32_word_swap|load32_dword|load64_word|load64_word_swap|reload) #IMPLIED>\n"
127188         "<softwarelists>\n"
128189   );
129190
r7758r7759
144205               {
145206                  if ( swlist->list_name[i] && *swlist->list_name[i] )
146207                  {
147                     fprintf(out, "\t<softwarelist name=\"%s\">\n", swlist->list_name[i] );
148
149208                     software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL );
150209
151210                     if ( list )
152211                     {
153                        for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) )
212                        /* Verify if we have encountered this list before */
213                        bool seen_before = false;
214                        for ( int l = 0; l < list_idx && !seen_before; l++ )
154215                        {
155                           fprintf( out, "\t\t<software name=\"%s\"", swinfo->shortname );
156                           if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL )
157                              fprintf( out, " supported=\"partial\"" );
158                           if ( swinfo->supported == SOFTWARE_SUPPORTED_NO )
159                              fprintf( out, " supported=\"no\"" );
160                           fprintf( out, ">\n" );
161                           fprintf( out, "\t\t\t<description>%s</description>\n", xml_normalize_string(swinfo->longname) );
162                           fprintf( out, "\t\t\t<year>%s</year>\n", xml_normalize_string( swinfo->year ) );
163                           fprintf( out, "\t\t\t<publisher>%s</publisher>\n", xml_normalize_string( swinfo->publisher ) );
216                           if ( ! strcmp( swlist->list_name[i], lists[l] ) )
217                           {
218                              seen_before = true;
219                           }
220                        }
164221
165                           for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) )
222                        if ( ! seen_before )
223                        {
224                           lists[list_idx] = core_strdup( swlist->list_name[i] );
225                           list_idx++;
226
227                           fprintf(out, "\t<softwarelist name=\"%s\">\n", swlist->list_name[i] );
228
229                           for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) )
166230                           {
167                              fprintf( out, "\t\t\t<part name=\"%s\"", part->name );
168                              if ( part->interface_ )
169                                 fprintf( out, " interface=\"%s\"", part->interface_ );
170                              if ( part->feature )
171                                 fprintf( out, " features=\"%s\"", part->feature );
172                              fprintf( out, ">\n");
231                              fprintf( out, "\t\t<software name=\"%s\"", swinfo->shortname );
232                              if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL )
233                                 fprintf( out, " supported=\"partial\"" );
234                              if ( swinfo->supported == SOFTWARE_SUPPORTED_NO )
235                                 fprintf( out, " supported=\"no\"" );
236                              fprintf( out, ">\n" );
237                              fprintf( out, "\t\t\t<description>%s</description>\n", xml_normalize_string(swinfo->longname) );
238                              fprintf( out, "\t\t\t<year>%s</year>\n", xml_normalize_string( swinfo->year ) );
239                              fprintf( out, "\t\t\t<publisher>%s</publisher>\n", xml_normalize_string( swinfo->publisher ) );
173240
174                              /* TODO: display rom region information */
175                              for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) )
241                              for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) )
176242                              {
177                                 fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) );
243                                 fprintf( out, "\t\t\t<part name=\"%s\"", part->name );
244                                 if ( part->interface_ )
245                                    fprintf( out, " interface=\"%s\"", part->interface_ );
246                                 if ( part->feature )
247                                    fprintf( out, " features=\"%s\"", part->feature );
248                                 fprintf( out, ">\n");
178249
179                                 for ( const rom_entry *rom = rom_first_file( region ); rom; rom = rom_next_file( rom ) )
250                                 /* TODO: display rom region information */
251                                 for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) )
180252                                 {
181                                    if ( ROMENTRY_ISFILE(rom) )
253                                    fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) );
254
255                                    for ( const rom_entry *rom = rom_first_file( region ); rom; rom = rom_next_file( rom ) )
182256                                    {
183                                       fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", ROM_GETNAME(rom), ROM_GETLENGTH(rom) );
184
185                                       /* dump checksum information only if there is a known dump */
186                                       if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
257                                       if ( ROMENTRY_ISFILE(rom) )
187258                                       {
188                                          char checksum[HASH_BUF_SIZE];
189                                          int hashtype;
259                                          fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", ROM_GETNAME(rom), ROM_GETLENGTH(rom) );
190260
191                                          /* iterate over hash function types and print out their values */
192                                          for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++)
193                                             if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum))
194                                                fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum);
195                                       }
261                                          /* dump checksum information only if there is a known dump */
262                                          if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
263                                          {
264                                             char checksum[HASH_BUF_SIZE];
265                                             int hashtype;
196266
197                                       fprintf( out, " offset=\"%x\"", ROM_GETOFFSET(rom) );
267                                             /* iterate over hash function types and print out their values */
268                                             for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++)
269                                                if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum))
270                                                   fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum);
271                                          }
198272
199                                       if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP) )
200                                          fprintf( out, " status=\"baddump\"" );
201                                       if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP) )
202                                          fprintf( out, " status=\"nodump\"" );
273                                          fprintf( out, " offset=\"%x\"", ROM_GETOFFSET(rom) );
203274
204                                       fprintf( out, "/>\n" );
275                                          if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP) )
276                                             fprintf( out, " status=\"baddump\"" );
277                                          if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP) )
278                                             fprintf( out, " status=\"nodump\"" );
279
280                                          fprintf( out, "/>\n" );
281                                       }
205282                                    }
283
284                                    fprintf( out, "\t\t\t\t</datearea>\n" );
206285                                 }
207286
208                                 fprintf( out, "\t\t\t\t</datearea>\n" );
287                                 fprintf( out, "\t\t\t</part>\n" );
209288                              }
210289
211                              fprintf( out, "\t\t\t</part>\n" );
290                              fprintf( out, "\t\t</software>\n" );
212291                           }
213292
214                           fprintf( out, "\t\t</software>\n" );
293                           fprintf(out, "\t</softwarelist>\n" );
215294                        }
216295
217296                        software_list_close( list );
218297                     }
219
220                     fprintf(out, "\t</softwarelist>\n" );
221298                  }
222299               }
223300            }
r7758r7759
229306
230307   fprintf( out, "</softwarelists>\n" );
231308
309   global_free( lists );
310
232311   return MAMERR_NONE;
233312}
234313

Previous 15994 Revisions Next


© 1998-2018 The MESS Team