• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21541532363

31 Jan 2026 08:14AM UTC coverage: 60.532% (+0.03%) from 60.507%
21541532363

push

github

web-flow
Tidy modernize for loops (#862)

* trigger loop convert

* Automated clang-tidy change: modernize-loop-convert

* fixed refactor

* Automated clang-tidy change: modernize-loop-convert

* compile

* first look through

* fixes and start to use a few ranges

* revert autogenerated file

* compilation fix

* second pass

* renamed loop variable

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

164 of 447 new or added lines in 61 files covered. (36.69%)

6 existing lines in 5 files now uncovered.

44377 of 73312 relevant lines covered (60.53%)

499857.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.46
/pol-core/pol/menu.cpp
1
/** @file
2
 *
3
 * @par History
4
 */
5

6

7
#include "menu.h"
8

9
#include <cstddef>
10
#include <string>
11

12
#include "../clib/cfgelem.h"
13
#include "../clib/cfgfile.h"
14
#include "../clib/clib.h"
15
#include "../clib/fileutil.h"
16
#include "../clib/logfacility.h"
17
#include "../clib/passert.h"
18
#include "../clib/rawtypes.h"
19
#include "../clib/stlutil.h"
20
#include "../plib/systemstate.h"
21
#include "globals/uvars.h"
22
#include "item/itemdesc.h"
23

24

25
namespace Pol::Core
26
{
27
MenuItem::MenuItem() : objtype_( 0 ), graphic_( 0 ), color_( 0 ), submenu_id( 0 )
×
28
{
29
  title[0] = '\0';
×
30
  submenu_name[0] = '\0';
×
31
}
×
32

33
Menu::Menu() : menu_id( 0 )
×
34
{
35
  weakptr.set( this );
×
36

37
  name[0] = '\0';
×
38
  title[0] = '\0';
×
39
}
×
40

41
Menu::Menu( const Menu& other ) : menu_id( other.menu_id ), menuitems_( other.menuitems_ )
×
42
{
43
  Clib::stracpy( name, other.name, sizeof name );
×
44
  Clib::stracpy( title, other.title, sizeof title );
×
45

46
  weakptr.set( this );
×
47
}
×
48
Menu& Menu::operator=( const Menu& rhs )
×
49
{
50
  Menu tmpMenu( rhs );
×
51

52
  std::swap( menu_id, tmpMenu.menu_id );
×
53
  std::swap( name, tmpMenu.name );
×
54
  std::swap( title, tmpMenu.title );
×
55
  std::swap( menuitems_, tmpMenu.menuitems_ );
×
56

57
  weakptr.set( this );
×
58

59
  return *this;
×
60
}
×
61

62
size_t Menu::estimateSize() const
×
63
{
64
  return sizeof( Menu ) + Clib::memsize( menuitems_ );
×
65
}
66

67
// TODO:: rewrite using std::find() and stlutil.h case insensitive string cmp
68
//         -- leaving the warning here as a reminder --
69
Menu* Menu::find_menu( const char* name )
×
70
{
NEW
71
  for ( auto& menu : gamestate.menus )
×
72
  {
NEW
73
    if ( stricmp( menu.name, name ) == 0 )
×
NEW
74
      return &menu;
×
75
  }
76
  return nullptr;
×
77
}
78

79
// currently a menu ID is its location in the array.
80
// we assume the code somehow validates menu choices.  For example,
81
// this is currently done by remembering which menu we sent a client.
82
// and only allowing the client to use that particular menu.
83
Menu* Menu::find_menu( unsigned short menu_id )
×
84
{
85
  passert( menu_id > 0 && menu_id <= gamestate.menus.size() );
×
86

87
  return &gamestate.menus[menu_id - 1];
×
88
}
89

90
void Menu::read_menus()
3✔
91
{
92
  if ( !Clib::FileExists( "config/menus.cfg" ) )
3✔
93
  {
94
    if ( Plib::systemstate.config.loglevel > 1 )
3✔
95
      INFO_PRINTLN( "File config/menus.cfg not found, skipping." );
3✔
96
    return;
3✔
97
  }
98

99
  Clib::ConfigFile cf( "config/menus.cfg" );
×
100

101
  Clib::ConfigElem elem;
×
102

103
  while ( cf.read( elem ) )
×
104
  {
105
    std::string menu_name;
×
106
    std::string menu_title;
×
107
    std::string propname;
×
108
    std::string value;
×
109

110
    if ( stricmp( elem.type(), "ItemMenu" ) != 0 )
×
111
      continue;
×
112

113
    menu_name = elem.remove_string( "NAME" );
×
114
    menu_title = elem.remove_string( "TITLE" );
×
115

116
    gamestate.menus.emplace_back();
×
117
    Menu* menu = &gamestate.menus.back();
×
118

119
    menu->menu_id = static_cast<unsigned short>( gamestate.menus.size() );
×
120
    Clib::stracpy( menu->name, menu_name.c_str(), sizeof menu->name );
×
121
    Clib::stracpy( menu->title, menu_title.c_str(), sizeof menu->title );
×
122

123
    while ( elem.remove_first_prop( &propname, &value ) )
×
124
    {
125
      if ( stricmp( propname.c_str(), "SubMenu" ) == 0 ||
×
126
           stricmp( propname.c_str(), "Entry" ) == 0 )
×
127
      {
128
        std::string submenu_name;
×
129
        std::string objtype_str;
×
130
        std::string title;
×
131

132
        /*
133
        char *submenu_name = nullptr;
134
        char *objtype_str = nullptr;
135
        char *title = nullptr;
136
        */
137

138
        if ( stricmp( propname.c_str(), "SubMenu" ) == 0 )
×
139
        {
140
          ISTRINGSTREAM is( value );
×
141
          is >> submenu_name >> objtype_str;
×
142

143
          // skipws
144
          // is.eatwhite();
145

146
          std::getline( is, title );  // title.getline( is );
×
147

148
          // FIXME: remove leading spaces (better way? please? anyone?)
149
          while ( isspace( title[0] ) )
×
150
            title.erase( 0, 1 );
×
151

152
          // char s[100];
153
          // is.ignore( std::numeric_limits<int>::max(), ' ' );
154
          // is.ignore( std::numeric_limits<int>::max(), '\t' );
155
          // is.getline( s, sizeof s );
156
          // title = s;
157
          /*
158
          submenu_name = strtok( value, " \t," );
159
          objtype_str = strtok( nullptr, " \t," );
160
          title = strtok( nullptr, "" ); // title is the rest of the line
161
          while ((title != nullptr) && *title && isspace(*title)) // skip leading spaces
162
          title++;
163
          */
164
        }
×
165
        else  // Entry
166
        {
167
          submenu_name = "";
×
168
          ISTRINGSTREAM is( value );
×
169
          is >> objtype_str;  // FIXME objtype_str ends up having the "," on the end
×
170

171
          std::getline( is, title );
×
172
          // FIXME: remove leading spaces (better way? please? anyone?)
173
          while ( isspace( title[0] ) )
×
174
            title.erase( 0, 1 );
×
175
        }
×
176

177
        if ( objtype_str.empty() )
×
178
        {
179
          ERROR_PRINTLN( "Entry in menu {} must provide at least an object type", menu->name );
×
180
          throw std::runtime_error( "Data error in MENUS.CFG" );
×
181
        }
182
        u32 objtype = (u32)strtoul( objtype_str.c_str(), nullptr, 0 );
×
183
        if ( objtype == 0 )  // 0 specified, or text
×
184
        {
185
          ERROR_PRINTLN( "Entry in menu {} cannot specify [{}] as an Object Type.", menu->name,
×
186
                         objtype_str );
187
          throw std::runtime_error( "Data error in MENUS.CFG" );
×
188
        }
189
        if ( ( stricmp( propname.c_str(), "SubMenu" ) == 0 ) && ( submenu_name.empty() ) )
×
190
        {
191
          ERROR_PRINTLN( "SubMenu in menu {} needs format: Objtype, Title, SubMenuName [got '{}']",
×
192
                         menu->name, value );
×
193
          throw std::runtime_error( "Data error in MENUS.CFG" );
×
194
        }
195
        if ( ( stricmp( propname.c_str(), "Entry" ) == 0 ) && ( !submenu_name.empty() ) )
×
196
        {
197
          ERROR_PRINTLN( "Entry in menu {} must not specify SubMenuName [got '{}']", menu->name,
×
198
                         value );
199
          throw std::runtime_error( "Data error in MENUS.CFG" );
×
200
        }
201

202
        menu->menuitems_.emplace_back();
×
203
        MenuItem* mi = &menu->menuitems_.back();
×
204

205
        mi->objtype_ = objtype;
×
206
        mi->graphic_ = Items::getgraphic( objtype );
×
207
        mi->color_ = Items::getcolor( objtype );
×
208

209
        if ( !title.empty() )
×
210
          Clib::stracpy( mi->title, title.c_str(), sizeof mi->title );
×
211
        else
212
          mi->title[0] = '\0';
×
213

214
        if ( !submenu_name.empty() )
×
215
          Clib::stracpy( mi->submenu_name, submenu_name.c_str(), sizeof mi->submenu_name );
×
216
        else
217
          mi->submenu_name[0] = '\0';
×
218

219
        mi->submenu_id = 0;
×
220
      }
×
221
      else
222
      {
223
        ERROR_PRINTLN( "Unexpected property in menu {}: {}", menu->name, propname );
×
224
        throw std::runtime_error( "Data error in MENUS.CFG" );
×
225
      }
226
    }
227
  }
×
228

229

NEW
230
  for ( auto& menu : gamestate.menus )
×
231
  {
NEW
232
    for ( auto& mi : menu.menuitems_ )
×
233
    {
NEW
234
      if ( mi.submenu_name[0] )
×
235
      {
NEW
236
        Menu* found = find_menu( mi.submenu_name );
×
237
        if ( found )
×
238
        {
NEW
239
          mi.submenu_id = found->menu_id;
×
240
        }
241
        else
242
        {
NEW
243
          INFO_PRINTLN( "Unable to find SubMenu {}", mi.submenu_name );
×
244
        }
245
      }
246
    }
247
  }
248
}
×
249
}  // namespace Pol::Core
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc