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

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

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

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

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

76.01
/pol-core/pol/module/cfgmod.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2005/07/04 Shinigami: mf_AppendConfigFileElem will reload file
5
 * - 2006/09/26 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
6
 */
7

8

9
#include "cfgmod.h"
10
#include <ctype.h>
11
#include <fstream>
12
#include <string>
13
#include <utility>
14

15
#include "../../bscript/berror.h"
16
#include "../../bscript/bobject.h"
17
#include "../../bscript/bstruct.h"
18
#include "../../bscript/contiter.h"
19
#include "../../bscript/dict.h"
20
#include "../../bscript/execmodl.h"
21
#include "../../bscript/executor.h"
22
#include "../../bscript/impstr.h"
23
#include "../../bscript/objmembers.h"
24
#include "../../clib/rawtypes.h"
25
#include "../../clib/refptr.h"
26
#include "../../clib/strutil.h"
27
#include "../../plib/pkg.h"
28
#include "../cfgrepos.h"
29

30
#include <module_defs/cfgfile.h>
31

32
namespace Pol
33
{
34
namespace Module
35
{
36
}
37
namespace Module
38
{
39
Bscript::BApplicObjType cfgfile_type;
40
Bscript::BApplicObjType cfgelem_type;
41

42

43
EConfigFileRefObjImp::EConfigFileRefObjImp( ref_ptr<Core::StoredConfigFile> rcfile )
36✔
44
    : EConfigFileRefObjImpBase( &cfgfile_type, rcfile )
36✔
45
{
46
}
36✔
47

48
class ConfigFileIterator final : public Bscript::ContIterator
49
{
50
public:
51
  ConfigFileIterator( EConfigFileRefObjImp* node, Bscript::BObject* pIter );
52
  Bscript::BObject* step() override;
53

54
private:
55
  Bscript::BObject m_ConfigObj;
56
  EConfigFileRefObjImp* node;
57
  Bscript::BObjectRef m_IterVal;
58
  Core::StoredConfigFile::ElementsByName::const_iterator name_itr;
59
};
60

61
ConfigFileIterator::ConfigFileIterator( EConfigFileRefObjImp* node, Bscript::BObject* pIter )
6✔
62
    : ContIterator(),
63
      m_ConfigObj( node ),
6✔
64
      node( node ),
6✔
65
      m_IterVal( pIter ),
6✔
66
      name_itr( node->obj_->elements_byname_.begin() )
12✔
67
{
68
}
6✔
69

70
Bscript::BObject* ConfigFileIterator::step()
36✔
71
{
72
  if ( name_itr == node->obj_->byname_end() )
36✔
73
    return nullptr;
6✔
74

75
  m_IterVal->setimp( new Bscript::String( name_itr->first ) );
30✔
76
  auto res = std::make_unique<Bscript::BObject>( new EConfigElemRefObjImp( name_itr->second ) );
30✔
77
  ++name_itr;
30✔
78
  return res.release();
30✔
79
}
30✔
80

81
Bscript::ContIterator* EConfigFileRefObjImp::createIterator( Bscript::BObject* pIterVal )
6✔
82
{
83
  return new ConfigFileIterator( this, pIterVal );
6✔
84
}
85

86
Bscript::BObjectRef EConfigFileRefObjImp::OperSubscript( const Bscript::BObject& obj )
63✔
87
{
88
  ref_ptr<Core::StoredConfigElem> celem;
63✔
89
  if ( const auto* str = obj.impptr_if<const Bscript::String>() )
63✔
90
  {
91
    celem = obj_->findelem( str->value() );
33✔
92
  }
93
  else if ( const auto* l = obj.impptr_if<const Bscript::BLong>() )
30✔
94
  {
95
    celem = obj_->findelem( l->value() );
27✔
96
  }
97

98
  if ( celem.get() != nullptr )
63✔
99
  {
100
    return Bscript::BObjectRef( new EConfigElemRefObjImp( celem ) );
120✔
101
  }
102
  return Bscript::BObjectRef( new Bscript::BError( "Element not found" ) );
3✔
103
}
63✔
104

105
const char* EConfigFileRefObjImp::typeOf() const
12✔
106
{
107
  return "ConfigFileRef";
12✔
108
}
109
u8 EConfigFileRefObjImp::typeOfInt() const
3✔
110
{
111
  return OTConfigFileRef;
3✔
112
}
113
Bscript::BObjectImp* EConfigFileRefObjImp::copy() const
9✔
114
{
115
  return new EConfigFileRefObjImp( obj_ );
9✔
116
}
117

118
EConfigElemRefObjImp::EConfigElemRefObjImp( ref_ptr<Core::StoredConfigElem> rcelem )
108✔
119
    : EConfigElemRefObjImpBase( &cfgelem_type, rcelem )
108✔
120
{
121
}
108✔
122

123
const char* EConfigElemRefObjImp::typeOf() const
21✔
124
{
125
  return "ConfigElemRef";
21✔
126
}
127
u8 EConfigElemRefObjImp::typeOfInt() const
3✔
128
{
129
  return OTConfigElemRef;
3✔
130
}
131
Bscript::BObjectImp* EConfigElemRefObjImp::copy() const
×
132
{
133
  return new EConfigElemRefObjImp( obj_ );
×
134
}
135

136
Bscript::BObjectRef EConfigElemRefObjImp::get_member_id( const int id )  // id test
3✔
137
{
138
  Bscript::ObjMember* memb = Bscript::getObjMember( id );
3✔
139

140
  return get_member( memb->code );
3✔
141
}
142
Bscript::BObjectRef EConfigElemRefObjImp::get_member( const char* membername )
51✔
143
{
144
  Bscript::BObjectImp* imp = obj_->getimp( membername );
51✔
145
  if ( imp != nullptr )
51✔
146
    return Bscript::BObjectRef( imp );
45✔
147

148
  return Bscript::BObjectRef( new Bscript::UninitObject );
6✔
149
}
150

151
Bscript::BObjectRef EConfigElemRefObjImp::OperSubscript( const Bscript::BObject& obj )
33✔
152
{
153
  if ( const auto* str = obj.impptr_if<const Bscript::String>() )
33✔
154
  {
155
    return get_member( str->data() );
33✔
156
  }
157
  if ( const auto* l = obj.impptr_if<const Bscript::BLong>() )
×
158
  {
159
    return get_member( std::to_string( l->value() ).c_str() );
×
160
  }
161
  return Bscript::BObjectRef( new Bscript::BError( "Element not found" ) );
×
162
}
163

164
ConfigFileExecutorModule::ConfigFileExecutorModule( Bscript::Executor& exec )
2,356✔
165
    : TmplExecutorModule<ConfigFileExecutorModule, Bscript::ExecutorModule>( exec )
2,356✔
166
{
167
}
2,356✔
168

169
bool ConfigFileExecutorModule::get_cfgfilename( const std::string& cfgdesc, std::string* cfgfile,
45✔
170
                                                std::string* errmsg, std::string* allpkgbase )
171
{
172
  if ( allpkgbase )
45✔
173
    *allpkgbase = "";
39✔
174
  const Plib::Package* pkg = exec.prog()->pkg;
45✔
175

176
  if ( cfgdesc[0] == ':' )
45✔
177
  {
178
    if ( cfgdesc[1] == ':' )
45✔
179
    {
180
      // Austin 2005-11-15
181
      // This is a bit of a kludge to make /regions/ config files readable.
182
      // Will go away when the paths here work like they do for file.em.
183
      // Looks for ::regions/filename
184
      if ( cfgdesc.substr( 2, 8 ) == "regions/" )
×
185
      {
186
        *cfgfile = cfgdesc.substr( 2, std::string::npos ) + ".cfg";
×
187
        return true;
×
188
      }
189
      // "::cfgfile" - core config file
190
      *cfgfile = "config/" + cfgdesc.substr( 2, std::string::npos ) + ".cfg";
×
191
      return true;
×
192
    }
193
    // ":pkgname:configfile" - config file in some package
194
    std::string::size_type second_colon = cfgdesc.find( ':', 2 );
45✔
195
    if ( second_colon != std::string::npos )
45✔
196
    {
197
      std::string pkgname = cfgdesc.substr( 1, second_colon - 1 );
45✔
198
      std::string cfgbase = cfgdesc.substr( second_colon + 1, std::string::npos );
45✔
199

200
      if ( pkgname == "*" )
45✔
201
      {
NEW
202
        if ( allpkgbase )
×
203
        {
NEW
204
          *cfgfile = cfgdesc;
×
NEW
205
          *allpkgbase = cfgbase;
×
UNCOV
206
          return true;
×
207
        }
208
        return false;
×
209
      }
210

211
      Plib::Package* dstpkg = Plib::find_package( pkgname );
45✔
212
      if ( dstpkg != nullptr )
45✔
213
      {
214
        *cfgfile = GetPackageCfgPath( dstpkg, cfgbase + ".cfg" );
45✔
215
        return true;
45✔
216
      }
NEW
217
      *errmsg = "Unable to find package " + pkgname;
×
UNCOV
218
      return false;
×
219
    }
45✔
NEW
220
    *errmsg = "Poorly formed config file descriptor: " + cfgdesc;
×
NEW
221
    return false;
×
222
  }
223
  if ( pkg != nullptr )
×
224
  {
225
    *cfgfile = GetPackageCfgPath( const_cast<Plib::Package*>( pkg ), cfgdesc + ".cfg" );
×
226
    return true;
×
227
  }
228
  *cfgfile = "config/" + cfgdesc + ".cfg";
×
229
  return true;
×
230
}
231

232

233
Bscript::BObjectImp* ConfigFileExecutorModule::mf_ReadConfigFile()
42✔
234
{
235
  const Bscript::String* cfgdesc_str;
236
  if ( exec.getStringParam( 0, cfgdesc_str ) )
42✔
237
  {
238
    const std::string& cfgdesc = cfgdesc_str->value();
39✔
239
    std::string cfgfile;
39✔
240
    std::string errmsg;
39✔
241
    std::string allpkgbase;
39✔
242
    if ( !get_cfgfilename( cfgdesc, &cfgfile, &errmsg, &allpkgbase ) )
39✔
243
    {
244
      return new Bscript::BError( errmsg );
×
245
    }
246

247
    ref_ptr<Core::StoredConfigFile> cfile = Core::FindConfigFile( cfgfile, allpkgbase );
39✔
248

249
    if ( cfile.get() != nullptr )
39✔
250
    {
251
      return new EConfigFileRefObjImp( cfile );
27✔
252
    }
253
    return new Bscript::BError( "Config file not found" );
12✔
254
  }
39✔
255
  return new Bscript::BError( "Invalid parameter type" );
3✔
256
}
257

258
bool legal_scp_filename( const char* filename )
×
259
{
260
  while ( filename && *filename )
×
261
  {
262
    if ( !isalnum( *filename ) )
×
263
      return false;
×
264
    ++filename;
×
265
  }
266
  return true;
×
267
}
268

269
Bscript::BObjectImp* ConfigFileExecutorModule::mf_LoadTusScpFile()
×
270
{
271
  const Bscript::String* filename_str;
272
  if ( !exec.getStringParam( 0, filename_str ) )
×
273
  {
274
    return new Bscript::BError( "Invalid parameter type" );
×
275
  }
276

277
  if ( !legal_scp_filename( filename_str->data() ) )
×
278
  {
279
    return new Bscript::BError( "Filename cannot include path information or special characters" );
×
280
  }
281

282
  ref_ptr<Core::StoredConfigFile> cfile =
283
      Core::LoadTusScpFile( "import/tus/" + filename_str->value() + ".scp" );
×
284

285
  if ( cfile.get() == nullptr )
×
286
  {
287
    return new Bscript::BError( "File not found" );
×
288
  }
289

290
  return new EConfigFileRefObjImp( cfile );
×
291
}
×
292

293
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigMaxIntKey()
3✔
294
{
295
  Core::StoredConfigFile* cfile;
296

297
  if ( getStoredConfigFileParam( *this, 0, cfile ) )
3✔
298
  {
299
    return new Bscript::BLong( cfile->maxintkey() );
3✔
300
  }
301
  return new Bscript::BError( "Parameter 0 must be a Config File" );
×
302
}
303

304
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigStringKeys()
9✔
305
{
306
  Core::StoredConfigFile* cfile;
307
  if ( getStoredConfigFileParam( *this, 0, cfile ) )
9✔
308
  {
309
    std::unique_ptr<Bscript::ObjArray> arr( new Bscript::ObjArray );
9✔
310
    Core::StoredConfigFile::ElementsByName::const_iterator itr = cfile->byname_begin(),
9✔
311
                                                           end = cfile->byname_end();
9✔
312
    for ( ; itr != end; ++itr )
24✔
313
    {
314
      arr->addElement( new Bscript::String( itr->first ) );
15✔
315
    }
316
    return arr.release();
9✔
317
  }
9✔
318
  return new Bscript::BError( "GetConfigStringKeys param 0 must be a Config File" );
×
319
}
320

321
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigIntKeys()
3✔
322
{
323
  Core::StoredConfigFile* cfile;
324
  if ( getStoredConfigFileParam( *this, 0, cfile ) )
3✔
325
  {
326
    std::unique_ptr<Bscript::ObjArray> arr( new Bscript::ObjArray );
3✔
327
    Core::StoredConfigFile::ElementsByNum::const_iterator itr = cfile->bynum_begin(),
3✔
328
                                                          end = cfile->bynum_end();
3✔
329
    for ( ; itr != end; ++itr )
9✔
330
    {
331
      arr->addElement( new Bscript::BLong( itr->first ) );
6✔
332
    }
333
    return arr.release();
3✔
334
  }
3✔
335
  return new Bscript::BError( "GetConfigIntKeys param 0 must be a Config File" );
×
336
}
337

338
Bscript::BObjectImp* ConfigFileExecutorModule::mf_FindConfigElem()
18✔
339
{
340
  Core::StoredConfigFile* cfile;
341

342
  if ( getStoredConfigFileParam( *this, 0, cfile ) )
18✔
343
  {
344
    Bscript::BObjectImp* keyimp = exec.getParamImp( 1 );
18✔
345

346
    ref_ptr<Core::StoredConfigElem> celem;
18✔
347

348
    if ( auto* l = impptrIf<Bscript::BLong>( keyimp ) )
18✔
349
    {
350
      celem = cfile->findelem( l->value() );
3✔
351
    }
352
    else if ( auto* str = impptrIf<Bscript::String>( keyimp ) )
15✔
353
    {
354
      celem = cfile->findelem( str->value() );
15✔
355
    }
356
    else
357
    {
358
      return new Bscript::BError( "Param 1 must be an Integer or a String" );
×
359
    }
360

361
    if ( celem.get() != nullptr )
18✔
362
    {
363
      return new EConfigElemRefObjImp( celem );
18✔
364
    }
365
    return new Bscript::BError( "Element not found" );
×
366
  }
18✔
367
  return new Bscript::BError( "Parameter 0 must be a Config File" );
×
368
}
369

370
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetElemProperty()
×
371
{
372
  return mf_GetConfigString();
×
373
}
374

375
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigString()
93✔
376
{
377
  Core::StoredConfigElem* celem;
378
  const Bscript::String* propname_str;
379

380
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
93✔
381
  {
382
    Bscript::BObjectImp* imp = celem->getimp( propname_str->value() );
93✔
383
    if ( imp != nullptr )
93✔
384
    {
385
      return new Bscript::String( imp->getStringRep() );
93✔
386
    }
387
    return new Bscript::BError( "Property not found" );
×
388
  }
389
  return new Bscript::BError( "Invalid parameter type" );
×
390
}
391

392
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigStringArray()
3✔
393
{
394
  Core::StoredConfigElem* celem;
395
  const Bscript::String* propname_str;
396

397
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
3✔
398
  {
399
    std::pair<Core::StoredConfigElem::const_iterator, Core::StoredConfigElem::const_iterator> pr =
400
        celem->equal_range( propname_str->data() );
3✔
401
    Core::StoredConfigElem::const_iterator itr = pr.first;
3✔
402
    Core::StoredConfigElem::const_iterator end = pr.second;
3✔
403

404
    std::unique_ptr<Bscript::ObjArray> ar( new Bscript::ObjArray );
3✔
405
    for ( ; itr != end; ++itr )
12✔
406
    {
407
      Bscript::BObjectImp* imp = ( *itr ).second.get();
9✔
408
      // Added 9-03-2005  Austin
409
      // Will no longer place the string right into the array.
410
      // Instead a check is done to make sure something is there.
411
      if ( !imp->getStringRep().empty() )
9✔
412
        ar->addElement( new Bscript::String( imp->getStringRep() ) );
6✔
413
    }
414
    return ar.release();
3✔
415
  }
3✔
416
  return new Bscript::BError( "Invalid parameter type" );
×
417
}
418

419
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigStringDictionary()
3✔
420
{
421
  Core::StoredConfigElem* celem;
422
  const Bscript::String* propname_str;
423

424
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
3✔
425
  {
426
    std::pair<Core::StoredConfigElem::const_iterator, Core::StoredConfigElem::const_iterator> pr =
427
        celem->equal_range( propname_str->data() );
3✔
428
    Core::StoredConfigElem::const_iterator itr = pr.first;
3✔
429
    Core::StoredConfigElem::const_iterator end = pr.second;
3✔
430

431
    std::unique_ptr<Bscript::BDictionary> dict( new Bscript::BDictionary );
3✔
432
    for ( ; itr != end; ++itr )
9✔
433
    {
434
      Bscript::BObjectImp* line = ( *itr ).second.get();
6✔
435

436
      std::string line_str = line->getStringRep();
6✔
437
      if ( line_str.empty() )
6✔
438
        continue;
×
439

440
      /* Example:
441
       * Elem
442
       * {
443
       *     PropName data moredata more data
444
       *     PropName stuff morestuff stuffity stuff
445
       * }
446
       * dict "data"->"moredata more data", "stuff"->"morestuff stuffity stuff!"
447
       */
448
      std::string prop_name, prop_value;
6✔
449
      Clib::splitnamevalue( line_str, prop_name, prop_value );
6✔
450

451
      dict->addMember( new Bscript::String( prop_name ), new Bscript::String( prop_value ) );
6✔
452
    }
6✔
453

454
    return dict.release();
3✔
455
  }
3✔
456
  return new Bscript::BError( "Invalid parameter type" );
×
457
}
458

459

460
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigInt()
9✔
461
{
462
  Core::StoredConfigElem* celem;
463
  const Bscript::String* propname_str;
464

465
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
9✔
466
  {
467
    Bscript::BObjectImp* imp = celem->getimp( propname_str->value() );
9✔
468
    if ( imp != nullptr )
9✔
469
    {
470
      if ( imp->isa( Bscript::BObjectImp::OTLong ) )
9✔
471
      {
472
        return imp;
3✔
473
      }
474
      if ( auto* dbl = impptrIf<Bscript::Double>( imp ) )
6✔
475
      {
476
        return new Bscript::BLong( static_cast<int>( dbl->value() ) );
3✔
477
      }
478
      if ( auto* str = impptrIf<Bscript::String>( imp ) )
3✔
479
      {
480
        try
481
        {
482
          return new Bscript::BLong( std::stoi( str->value(), nullptr, 0 ) );
3✔
483
        }
484
        catch ( const std::logic_error& )
3✔
485
        {
486
          return new Bscript::BError( "Integer overflow error" );
3✔
487
        }
3✔
488
      }
489
      return new Bscript::BError( "Invalid type in config file! (internal error)" );
×
490
    }
491
    return new Bscript::BError( "Property not found" );
×
492
  }
493
  return new Bscript::BError( "Invalid parameter type" );
×
494
}
495

496
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigIntArray()
9✔
497
{
498
  Core::StoredConfigElem* celem;
499
  const Bscript::String* propname_str;
500

501
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
9✔
502
  {
503
    auto pr = celem->equal_range( propname_str->data() );
9✔
504
    Core::StoredConfigElem::const_iterator itr = pr.first;
9✔
505
    Core::StoredConfigElem::const_iterator end = pr.second;
9✔
506

507
    std::unique_ptr<Bscript::ObjArray> ar( new Bscript::ObjArray );
9✔
508
    for ( ; itr != end; ++itr )
21✔
509
    {
510
      Bscript::BObjectImp* imp = itr->second.get();
12✔
511
      // Will no longer place the string right into the array.
512
      // Instead a check is done to make sure something is there.
513

514
      if ( auto* l = impptrIf<Bscript::BLong>( imp ) )
12✔
515
      {
516
        ar->addElement( l );
6✔
517
      }
518
      else if ( auto* d = impptrIf<Bscript::Double>( imp ) )
6✔
519
      {
520
        ar->addElement( new Bscript::BLong( static_cast<int>( d->value() ) ) );
3✔
521
      }
522
      else if ( auto* str = impptrIf<Bscript::String>( imp ) )
3✔
523
      {
524
        if ( str->length() >= 1 )
3✔
525
        {
526
          try
527
          {
528
            ar->addElement( new Bscript::BLong( std::stoi( str->value(), nullptr, 0 ) ) );
3✔
529
          }
530
          catch ( const std::logic_error& )
3✔
531
          {
532
            // overflow error: skip element
533
          }
3✔
534
        }
535
      }
536
    }
537
    return ar.release();
9✔
538
  }
9✔
539
  return new Bscript::BError( "Invalid parameter type" );
×
540
}
541

542
Bscript::BObjectImp* ConfigFileExecutorModule::mf_GetConfigReal()
9✔
543
{
544
  Core::StoredConfigElem* celem;
545
  const Bscript::String* propname_str;
546

547
  if ( getStoredConfigElemParam( *this, 0, celem ) && getStringParam( 1, propname_str ) )
9✔
548
  {
549
    Bscript::BObjectImp* imp = celem->getimp( propname_str->value() );
9✔
550
    if ( imp != nullptr )
9✔
551
    {
552
      if ( imp->isa( Bscript::BObjectImp::OTDouble ) )
9✔
553
      {
554
        return imp;
3✔
555
      }
556
      if ( auto* l = impptrIf<Bscript::BLong>( imp ) )
6✔
557
      {
558
        return new Bscript::Double( l->value() );
3✔
559
      }
560
      if ( auto* str = impptrIf<Bscript::String>( imp ) )
3✔
561
      {
562
        return new Bscript::Double( strtod( str->data(), nullptr ) );
3✔
563
      }
564
      return new Bscript::BError( "Invalid type in config file! (internal error)" );
×
565
    }
566
    return new Bscript::BError( "Property not found" );
×
567
  }
568
  return new Bscript::BError( "Invalid parameter type" );
×
569
}
570

571
Bscript::BObjectImp* ConfigFileExecutorModule::mf_ListConfigElemProps()
45✔
572
{
573
  Core::StoredConfigElem* celem;
574
  if ( getStoredConfigElemParam( *this, 0, celem ) )
45✔
575
  {
576
    // should return an array or prop-names
577
    return celem->listprops();
45✔
578
  }
579
  return new Bscript::BError( "Invalid parameter type" );
×
580
}
581

582
/* The elements in the array passed should each be a structure (name, value) */
583
Bscript::BObjectImp* ConfigFileExecutorModule::mf_AppendConfigFileElem()
6✔
584
{
585
  const Bscript::String* filename;
586
  const Bscript::String* elemtype;
587
  Bscript::ObjArray* objarr;
588
  if ( !exec.getStringParam( 0, filename ) || !exec.getStringParam( 1, elemtype ) ||
12✔
589
       !exec.getObjArrayParam( 3, objarr ) )
6✔
590
  {
591
    return new Bscript::BError( "Invalid parameter type" );
×
592
  }
593
  std::string elemkey = getParamImp( 2 )->getStringRep();
6✔
594

595
  std::string pathname, errmsg;
6✔
596
  const std::string& cfgdesc = filename->value();
6✔
597
  if ( !get_cfgfilename( cfgdesc, &pathname, &errmsg ) )
6✔
598
  {
599
    return new Bscript::BError( errmsg );
×
600
  }
601

602
  std::ofstream ofs( pathname.c_str(), std::ios::app );
6✔
603
  if ( !ofs.is_open() )
6✔
604
    return new Bscript::BError( "Failed to open file" );
3✔
605
  ofs << std::endl << elemtype->value() << " " << elemkey << std::endl << "{" << std::endl;
3✔
606
  for ( Bscript::ObjArray::const_iterator itr = objarr->ref_arr.begin(),
3✔
607
                                          end = objarr->ref_arr.end();
3✔
608
        itr != end; ++itr )
9✔
609
  {
610
    Bscript::BObject* bo = itr->get();
6✔
611
    if ( bo != nullptr )
6✔
612
    {
613
      if ( auto* inarr = bo->impptr_if<Bscript::ObjArray>() )
6✔
614
      {
615
        if ( inarr->ref_arr.size() == 2 )
3✔
616
        {
617
          Bscript::BObject* nobj = inarr->ref_arr[0].get();
3✔
618
          Bscript::BObject* vobj = inarr->ref_arr[1].get();
3✔
619
          if ( nobj != nullptr && nobj->isa( Bscript::BObjectImp::OTString ) && vobj != nullptr )
3✔
620
          {
621
            Bscript::String* namestr = nobj->impptr<Bscript::String>();
3✔
622
            std::string value = vobj->impptr()->getStringRep();
3✔
623

624
            ofs << "\t" << namestr->value() << "\t" << value << std::endl;
3✔
625
          }
3✔
626
        }
627
      }
628
      else if ( auto* instruct = bo->impptr_if<Bscript::BStruct>() )
3✔
629
      {
630
        const Bscript::BObjectImp* name_imp = instruct->FindMember( "name" );
3✔
631
        const Bscript::BObjectImp* value_imp = instruct->FindMember( "value" );
3✔
632
        if ( const auto* namestr = impptrIf<const Bscript::String>( name_imp );
3✔
633
             namestr && value_imp )
3✔
634
        {
635
          std::string value = value_imp->getStringRep();
3✔
636

637
          ofs << "\t" << namestr->value() << "\t" << value << std::endl;
3✔
638
        }
3✔
639
      }
640
    }
641
  }
642
  ofs << "}" << std::endl;
3✔
643

644
  Core::UnloadConfigFile( pathname );
3✔
645

646
  return new Bscript::BLong( 1 );
3✔
647
}
6✔
648

649
Bscript::BObjectImp* ConfigFileExecutorModule::mf_UnloadConfigFile()
×
650
{
651
  const Bscript::String* filename;
652
  if ( getStringParam( 0, filename ) )
×
653
  {
654
    const std::string& cfgdesc = filename->value();
×
655
    std::string cfgfile;
×
656
    std::string errmsg;
×
657
    std::string allpkgbase;
×
658
    if ( !get_cfgfilename( cfgdesc, &cfgfile, &errmsg, &allpkgbase ) )
×
659
    {
660
      return new Bscript::BError( errmsg );
×
661
    }
662

663
    return new Bscript::BLong( Core::UnloadConfigFile( cfgfile ) );
×
664
  }
×
665
  return new Bscript::BError( "Invalid parameter" );
×
666
}
667

668
bool getStoredConfigFileParam( Bscript::ExecutorModule& exmod, unsigned param,
33✔
669
                               Core::StoredConfigFile*& cfile )
670
{
671
  Bscript::BApplicObjBase* ao_cfile_base = exmod.exec.getApplicObjParam( param, &cfgfile_type );
33✔
672
  if ( ao_cfile_base != nullptr )
33✔
673
  {
674
    EConfigFileRefObjImp* ao_cfile = static_cast<EConfigFileRefObjImp*>( ao_cfile_base );
33✔
675

676
    cfile = ao_cfile->value().get();
33✔
677

678
    return true;
33✔
679
  }
680
  return false;
×
681
}
682

683
bool getStoredConfigElemParam( Bscript::ExecutorModule& exmod, unsigned param,
171✔
684
                               Core::StoredConfigElem*& celem )
685
{
686
  Bscript::BApplicObjBase* ao_celem_base = exmod.exec.getApplicObjParam( param, &cfgelem_type );
171✔
687
  if ( ao_celem_base != nullptr )
171✔
688
  {
689
    EConfigElemRefObjImp* ao_celem = static_cast<EConfigElemRefObjImp*>( ao_celem_base );
171✔
690

691
    celem = ao_celem->value().get();
171✔
692

693
    return true;
171✔
694
  }
695
  return false;
×
696
}
697
}  // namespace Module
698
}  // 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