@@ -81,8 +81,9 @@ struct disk_control_interface_t
81
81
82
82
unsigned char path [10 ][MAX_PATH ]; /* disk image paths */
83
83
unsigned char label [10 ][MAX_PATH ]; /* disk image base name w/o extension */
84
+
85
+ unsigned g_initial_disc ; /* initial disk index */
84
86
unsigned char g_initial_disc_path [MAX_PATH ]; /* initial disk path */
85
- unsigned g_initial_disc ; /* initial disk index */
86
87
};
87
88
88
89
static struct disk_control_interface_t disk ;
@@ -359,14 +360,15 @@ static void parse_cmdline(const char *argv);
359
360
360
361
static bool read_m3u (const char * file )
361
362
{
363
+ unsigned index = 0 ;
362
364
char line [MAX_PATH ];
363
365
char name [MAX_PATH ];
364
366
FILE * f = fopen (file , "r" );
365
367
366
368
if (!f )
367
369
return false;
368
370
369
- while (fgets (line , sizeof (line ), f ) && disk . total_images < sizeof (disk .path ) / sizeof (disk .path [0 ]))
371
+ while (fgets (line , sizeof (line ), f ) && index < sizeof (disk .path ) / sizeof (disk .path [0 ]))
370
372
{
371
373
if (line [0 ] == '#' )
372
374
continue ;
@@ -389,20 +391,39 @@ static bool read_m3u(const char *file)
389
391
if (line [0 ] != '\0' )
390
392
{
391
393
char image_label [4096 ];
394
+ char * custom_label ;
395
+ size_t len = 0 ;
392
396
393
- /* write disk image path */
394
397
snprintf (name , sizeof (name ), "%s%c%s" , base_dir , slash , line );
395
- strcpy (disk .path [disk .total_images ], name );
396
398
397
- /* extract and write disk image base name */
398
- extract_basename (image_label , name , sizeof (image_label ));
399
- snprintf (disk .label [disk .total_images ], sizeof (disk .label [disk .total_images ]), "%s" , image_label );
399
+ custom_label = strchr (name , '|' );
400
+ if (custom_label )
401
+ {
402
+ /* get disk path */
403
+ len = custom_label + 1 - name ;
404
+ strncpy (disk .path [index ], name , len - 1 );
400
405
401
- disk .total_images ++ ;
406
+ /* get custom label */
407
+ custom_label ++ ;
408
+ strncpy (disk .label [index ], custom_label , sizeof (disk .label [index ]));
409
+ }
410
+ else
411
+ {
412
+ /* copy path */
413
+ strncpy (disk .path [index ], name , sizeof (disk .path [index ]));
414
+
415
+ /* extract base name from path for labels */
416
+ extract_basename (image_label , name , sizeof (image_label ));
417
+ strncpy (disk .label [index ], image_label , sizeof (disk .label [index ]));
418
+ }
419
+
420
+ index ++ ;
402
421
}
403
422
}
404
423
424
+ disk .total_images = index ;
405
425
fclose (f );
426
+
406
427
return (disk .total_images != 0 );
407
428
}
408
429
0 commit comments