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

polserver / polserver / 21066490217

16 Jan 2026 12:22PM UTC coverage: 60.507%. Remained the same
21066490217

push

github

web-flow
misc clang-tidy (#853)

* trigger tidy

* Automated clang-tidy change: modernize-use-equals-delete,modernize-make-shared,modernize-make-unique,modernize-use-constraints,readability-container-size-empty,modernize-redundant-void-arg,modernize-use-emplace

* removed non needed macros

* missed to disable tidy build

---------

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

174 of 248 new or added lines in 74 files covered. (70.16%)

2 existing lines in 2 files now uncovered.

44459 of 73477 relevant lines covered (60.51%)

515895.79 hits per line

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

4.35
/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
namespace Pol
25
{
26
namespace Core
27
{
28
MenuItem::MenuItem() : objtype_( 0 ), graphic_( 0 ), color_( 0 ), submenu_id( 0 )
×
29
{
30
  title[0] = '\0';
×
31
  submenu_name[0] = '\0';
×
32
}
×
33

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

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

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

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

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

58
  weakptr.set( this );
×
59

60
  return *this;
×
61
}
×
62

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

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

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

89
  return &gamestate.menus[menu_id - 1];
×
90
}
91

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

101
  Clib::ConfigFile cf( "config/menus.cfg" );
×
102

103
  Clib::ConfigElem elem;
×
104

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

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

115
    menu_name = elem.remove_string( "NAME" );
×
116
    menu_title = elem.remove_string( "TITLE" );
×
117

NEW
118
    gamestate.menus.emplace_back();
×
119
    Menu* menu = &gamestate.menus.back();
×
120

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

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

134
        /*
135
        char *submenu_name = nullptr;
136
        char *objtype_str = nullptr;
137
        char *title = nullptr;
138
        */
139

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

145
          // skipws
146
          // is.eatwhite();
147

148
          std::getline( is, title );  // title.getline( is );
×
149

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

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

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

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

NEW
204
        menu->menuitems_.emplace_back();
×
205
        MenuItem* mi = &menu->menuitems_.back();
×
206

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

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

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

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

231

232
  for ( unsigned menuidx = 0; menuidx < gamestate.menus.size(); menuidx++ )
×
233
  {
234
    Menu* menu = &gamestate.menus[menuidx];
×
235
    for ( unsigned itemidx = 0; itemidx < menu->menuitems_.size(); itemidx++ )
×
236
    {
237
      MenuItem* mi = &menu->menuitems_[itemidx];
×
238

239
      if ( mi->submenu_name[0] )
×
240
      {
241
        Menu* found = find_menu( mi->submenu_name );
×
242
        if ( found )
×
243
        {
244
          mi->submenu_id = found->menu_id;
×
245
        }
246
        else
247
        {
248
          INFO_PRINTLN( "Unable to find SubMenu {}", mi->submenu_name );
×
249
        }
250
      }
251
    }
252
  }
253
}
×
254
}  // namespace Core
255
}  // namespace Pol
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