Previous 15994 Revisions Next

r7712 Monday 5th April, 2010 at 08:56:22 UTC by Wilbert Pol
Added some extra checks to info_listsoftware to prevent crashes.
[src/mess]climess.c

src/mess/climess.c
r7711r7712
115115    games
116116   TODO: Avoid outputting lists more than once.
117117   TODO: Add DTD.
118   TODO: Add all information read from the source files
118119-------------------------------------------------*/
119120
120121int info_listsoftware(core_options *options, const char *gamename)
r7711r7712
141142
142143               for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ )
143144               {
144                  if ( swlist->list_name[i] )
145                  if ( swlist->list_name[i] && *swlist->list_name[i] )
145146                  {
146147                     fprintf(out, "\t<softwarelist name=\"%s\">\n", swlist->list_name[i] );
147148
148149                     software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL );
149150
150                     for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) )
151                     if ( list )
151152                     {
152                        fprintf( out, "\t\t<software name=\"%s\"", swinfo->shortname );
153                        if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL )
154                           fprintf( out, " supported=\"partial\"" );
155                        if ( swinfo->supported == SOFTWARE_SUPPORTED_NO )
156                           fprintf( out, " supported=\"no\"" );
157                        fprintf( out, ">\n" );
158                        fprintf( out, "\t\t\t<description>%s</description>\n", xml_normalize_string(swinfo->longname) );
159                        fprintf( out, "\t\t\t<year>%s</year>\n", xml_normalize_string( swinfo->year ) );
160                        fprintf( out, "\t\t\t<publisher>%s</publisher>\n", xml_normalize_string( swinfo->publisher ) );
161
162                        for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) )
153                        for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) )
163154                        {
164                           fprintf( out, "\t\t\t<part name=\"%s\"", part->name );
165                           if ( part->interface_ )
166                              fprintf( out, " interface=\"%s\"", part->interface_ );
167                           if ( part->feature )
168                              fprintf( out, " features=\"%s\"", part->feature );
169                           fprintf( out, ">\n");
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 ) );
170164
171                           /* TODO: display rom region information */
172                           for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) )
165                           for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) )
173166                           {
174                              fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) );
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");
175173
176                              for ( const rom_entry *rom = rom_first_file( region ); rom; rom = rom_next_file( rom ) )
174                              /* TODO: display rom region information */
175                              for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) )
177176                              {
178                                 if ( ROMENTRY_ISFILE(rom) )
177                                 fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) );
178
179                                 for ( const rom_entry *rom = rom_first_file( region ); rom; rom = rom_next_file( rom ) )
179180                                 {
180                                    fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", ROM_GETNAME(rom), ROM_GETLENGTH(rom) );
181
182                                    /* dump checksum information only if there is a known dump */
183                                    if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
181                                    if ( ROMENTRY_ISFILE(rom) )
184182                                    {
185                                       char checksum[HASH_BUF_SIZE];
186                                       int hashtype;
183                                       fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", ROM_GETNAME(rom), ROM_GETLENGTH(rom) );
187184
188                                       /* iterate over hash function types and print out their values */
189                                       for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++)
190                                          if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum))
191                                             fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum);
185                                       /* dump checksum information only if there is a known dump */
186                                       if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
187                                       {
188                                          char checksum[HASH_BUF_SIZE];
189                                          int hashtype;
190
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                                       }
196
197                                       fprintf( out, " offset=\"%x\" />\n", ROM_GETOFFSET(rom) );
192198                                    }
199                                 }
193200
194                                    fprintf( out, " offset=\"%x\" />\n", ROM_GETOFFSET(rom) );
195                                 }
201                                 fprintf( out, "\t\t\t\t</datearea>\n" );
196202                              }
197203
198                              fprintf( out, "\t\t\t\t</datearea>\n" );
204                              fprintf( out, "\t\t\t</part>\n" );
199205                           }
200206
201                           fprintf( out, "\t\t\t</part>\n" );
207                           fprintf( out, "\t\t</software>\n" );
202208                        }
203209
204                        fprintf( out, "\t\t</software>\n" );
210                        software_list_close( list );
205211                     }
206212
207                     software_list_close( list );
208
209213                     fprintf(out, "\t</softwarelist>\n" );
210214                  }
211215               }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team