@@ -58,24 +58,11 @@ static const char *const gamemode_str[] = {
58
58
"Unknown mode"
59
59
};
60
60
61
- // "128 IWAD search directories should be enough for anybody".
62
-
63
- #define MAX_IWAD_DIRS 128
64
-
65
61
// Array of locations to search for IWAD files
62
+ #define M_ARRAY_INIT_CAPACITY 32
63
+ #include "m_array.h"
66
64
67
- static boolean iwad_dirs_built = false;
68
- char * iwad_dirs [MAX_IWAD_DIRS ];
69
- int num_iwad_dirs = 0 ;
70
-
71
- static void AddIWADDir (char * dir )
72
- {
73
- if (num_iwad_dirs < MAX_IWAD_DIRS )
74
- {
75
- iwad_dirs [num_iwad_dirs ] = dir ;
76
- ++ num_iwad_dirs ;
77
- }
78
- }
65
+ static char * * iwad_dirs ;
79
66
80
67
// Return the path where the executable lies -- Lee Killough
81
68
@@ -355,7 +342,7 @@ static void CheckUninstallStrings(void)
355
342
{
356
343
path = unstr + strlen (UNINSTALLER_STRING );
357
344
358
- AddIWADDir ( path );
345
+ array_push ( iwad_dirs , path );
359
346
}
360
347
}
361
348
}
@@ -383,7 +370,7 @@ static void CheckInstallRootPaths(void)
383
370
{
384
371
subpath = M_StringJoin (install_path , DIR_SEPARATOR_S ,
385
372
root_path_subdirs [j ]);
386
- AddIWADDir ( subpath );
373
+ array_push ( iwad_dirs , subpath );
387
374
}
388
375
389
376
free (install_path );
@@ -410,7 +397,7 @@ static void CheckSteamEdition(void)
410
397
subpath = M_StringJoin (install_path , DIR_SEPARATOR_S ,
411
398
steam_install_subdirs [i ]);
412
399
413
- AddIWADDir ( subpath );
400
+ array_push ( iwad_dirs , subpath );
414
401
}
415
402
416
403
free (install_path );
@@ -423,13 +410,13 @@ static void CheckDOSDefaults(void)
423
410
// These are the default install directories used by the deice
424
411
// installer program:
425
412
426
- AddIWADDir ( "\\doom2" ); // Doom II
427
- AddIWADDir ( "\\plutonia" ); // Final Doom
428
- AddIWADDir ( "\\tnt" );
429
- AddIWADDir ( "\\doom_se" ); // Ultimate Doom
430
- AddIWADDir ( "\\doom" ); // Shareware / Registered Doom
431
- AddIWADDir ( "\\dooms" ); // Shareware versions
432
- AddIWADDir ( "\\doomsw" );
413
+ array_push ( iwad_dirs , "\\doom2" ); // Doom II
414
+ array_push ( iwad_dirs , "\\plutonia" ); // Final Doom
415
+ array_push ( iwad_dirs , "\\tnt" );
416
+ array_push ( iwad_dirs , "\\doom_se" ); // Ultimate Doom
417
+ array_push ( iwad_dirs , "\\doom" ); // Shareware / Registered Doom
418
+ array_push ( iwad_dirs , "\\dooms" ); // Shareware versions
419
+ array_push ( iwad_dirs , "\\doomsw" );
433
420
}
434
421
435
422
#endif
@@ -464,7 +451,7 @@ static void AddIWADPath(const char *path, const char *suffix)
464
451
// as another iwad dir
465
452
* p = '\0' ;
466
453
467
- AddIWADDir ( M_StringJoin (left , suffix ));
454
+ array_push ( iwad_dirs , M_StringJoin (left , suffix ));
468
455
left = p + 1 ;
469
456
}
470
457
else
@@ -473,7 +460,7 @@ static void AddIWADPath(const char *path, const char *suffix)
473
460
}
474
461
}
475
462
476
- AddIWADDir ( M_StringJoin (left , suffix ));
463
+ array_push ( iwad_dirs , M_StringJoin (left , suffix ));
477
464
478
465
free (dup_path );
479
466
}
@@ -491,7 +478,7 @@ static void AddXdgDirs(void)
491
478
// We support $XDG_DATA_HOME/games/doom (which will usually be
492
479
// ~/.local/share/games/doom) as a user-writeable extension to
493
480
// the usual /usr/share/games/doom location.
494
- AddIWADDir ( M_StringJoin (env , "/games/doom" ));
481
+ array_push ( iwad_dirs , M_StringJoin (env , "/games/doom" ));
495
482
496
483
// Quote:
497
484
// > $XDG_DATA_DIRS defines the preference-ordered set of base
@@ -550,23 +537,23 @@ void BuildIWADDirList(void)
550
537
{
551
538
char * env ;
552
539
553
- if (iwad_dirs_built )
540
+ if (array_size ( iwad_dirs ) > 0 )
554
541
{
555
542
return ;
556
543
}
557
544
558
545
// Look in the current directory. Doom always does this.
559
- AddIWADDir ( "." );
546
+ array_push ( iwad_dirs , "." );
560
547
561
548
// Next check the directory where the executable is located. This might
562
549
// be different from the current directory.
563
- AddIWADDir ( D_DoomExeDir ());
550
+ array_push ( iwad_dirs , D_DoomExeDir ());
564
551
565
552
// Add DOOMWADDIR if it is in the environment
566
553
env = M_getenv ("DOOMWADDIR" );
567
554
if (env != NULL )
568
555
{
569
- AddIWADDir ( env );
556
+ array_push ( iwad_dirs , env );
570
557
}
571
558
572
559
// Add dirs from DOOMWADPATH:
@@ -578,7 +565,7 @@ void BuildIWADDirList(void)
578
565
579
566
// [FG] Add plain HOME directory
580
567
env = M_HomeDir ();
581
- AddIWADDir ( env );
568
+ array_push ( iwad_dirs , env );
582
569
583
570
#ifdef _WIN32
584
571
@@ -595,10 +582,6 @@ void BuildIWADDirList(void)
595
582
AddSteamDirs ();
596
583
# endif
597
584
#endif
598
-
599
- // Don't run this function again.
600
-
601
- iwad_dirs_built = true;
602
585
}
603
586
604
587
//
@@ -609,7 +592,6 @@ char *D_FindWADByName(const char *name)
609
592
{
610
593
char * path ;
611
594
char * probe ;
612
- int i ;
613
595
614
596
// Absolute path?
615
597
@@ -623,22 +605,23 @@ char *D_FindWADByName(const char *name)
623
605
624
606
// Search through all IWAD paths for a file with the given name.
625
607
626
- for (i = 0 ; i < num_iwad_dirs ; ++ i )
608
+ char * * dir ;
609
+ array_foreach (dir , iwad_dirs )
627
610
{
628
611
// As a special case, if this is in DOOMWADDIR or DOOMWADPATH,
629
612
// the "directory" may actually refer directly to an IWAD
630
613
// file.
631
614
632
- probe = M_FileCaseExists (iwad_dirs [ i ] );
633
- if (DirIsFile (iwad_dirs [ i ] , name ) && probe != NULL )
615
+ probe = M_FileCaseExists (* dir );
616
+ if (DirIsFile (* dir , name ) && probe != NULL )
634
617
{
635
618
return probe ;
636
619
}
637
620
free (probe );
638
621
639
622
// Construct a string for the full path
640
623
641
- path = M_StringJoin (iwad_dirs [ i ] , DIR_SEPARATOR_S , name );
624
+ path = M_StringJoin (* dir , DIR_SEPARATOR_S , name );
642
625
643
626
probe = M_FileCaseExists (path );
644
627
if (probe != NULL )
0 commit comments