Use range_for for player menu list

This commit is contained in:
Kp 2015-07-18 21:01:55 +00:00
parent 4c200342dd
commit 921276232f

View file

@ -339,8 +339,6 @@ static int player_menu_handler( listbox *lb,const d_event &event, char **list )
//Inputs the player's name, without putting up the background screen //Inputs the player's name, without putting up the background screen
int RegisterPlayer() int RegisterPlayer()
{ {
const char **m;
char **f;
static const array<file_extension_t, 1> types{{"plr"}}; static const array<file_extension_t, 1> types{{"plr"}};
int i = 0, NumItems; int i = 0, NumItems;
int citem = 0; int citem = 0;
@ -373,7 +371,8 @@ int RegisterPlayer()
for (NumItems = 0; list[NumItems] != NULL; NumItems++) {} for (NumItems = 0; list[NumItems] != NULL; NumItems++) {}
NumItems++; // for TXT_CREATE_NEW NumItems++; // for TXT_CREATE_NEW
MALLOC(m, const char *, NumItems); RAIIdmem<const char *[]> m;
MALLOC(m, const char *[], NumItems);
if (m == NULL) if (m == NULL)
{ {
return 0; return 0;
@ -381,18 +380,18 @@ int RegisterPlayer()
m[i++] = TXT_CREATE_NEW; m[i++] = TXT_CREATE_NEW;
for (f = list.get(); *f; f++) range_for (const auto f, list)
{ {
char *p; char *p;
size_t lenf = strlen(*f); size_t lenf = strlen(f);
if (lenf > FILENAME_LEN-1 || lenf < 5) // sorry guys, can only have up to eight chars for the player name if (lenf > FILENAME_LEN-1 || lenf < 5) // sorry guys, can only have up to eight chars for the player name
{ {
NumItems--; NumItems--;
continue; continue;
} }
m[i++] = *f; m[i++] = f;
p = strchr(*f, '.'); p = strchr(f, '.');
if (p) if (p)
*p = '\0'; // chop the .plr *p = '\0'; // chop the .plr
} }
@ -410,8 +409,7 @@ int RegisterPlayer()
if (!d_stricmp(static_cast<const char *>(Players[Player_num].callsign), m[i]) ) if (!d_stricmp(static_cast<const char *>(Players[Player_num].callsign), m[i]) )
citem = i; citem = i;
newmenu_listbox1(TXT_SELECT_PILOT, NumItems, m, allow_abort_flag, citem, player_menu_handler, list.release()); newmenu_listbox1(TXT_SELECT_PILOT, NumItems, m.release(), allow_abort_flag, citem, player_menu_handler, list.release());
return 1; return 1;
} }