Repository: trafficserver Updated Branches: refs/heads/master 8c985ee41 -> f02b5a6da
Clang related clean up, formatting fixes. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/f02b5a6d Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/f02b5a6d Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/f02b5a6d Branch: refs/heads/master Commit: f02b5a6da6e5563b52b29ddad3fa4c25d02ff2dd Parents: 8c985ee Author: Alan M. Carroll <[email protected]> Authored: Mon Sep 29 17:12:04 2014 -0500 Committer: Alan M. Carroll <[email protected]> Committed: Mon Sep 29 17:12:04 2014 -0500 ---------------------------------------------------------------------- iocore/net/SSLCertLookup.cc | 1 - lib/tsconfig/TsConfigGrammar.c | 47 ++--- lib/tsconfig/TsConfigGrammar.y | 3 + lib/tsconfig/TsConfigSyntax.c | 56 +++--- lib/tsconfig/TsConfigSyntax.l | 4 + lib/tsconfig/TsErrataUtil.cc | 4 +- lib/tsconfig/TsValue.cc | 381 ++++++++++++++++++------------------ 7 files changed, 255 insertions(+), 241 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/iocore/net/SSLCertLookup.cc ---------------------------------------------------------------------- diff --git a/iocore/net/SSLCertLookup.cc b/iocore/net/SSLCertLookup.cc index 47c70df..814b75d 100644 --- a/iocore/net/SSLCertLookup.cc +++ b/iocore/net/SSLCertLookup.cc @@ -321,7 +321,6 @@ SSLContextStorage::insert(const char* name, int idx) Warning("previously indexed '%s' with SSL_CTX %p, cannot index it with SSL_CTX #%d now", name, value, idx); idx = -1; } else { - inserted = true; ink_hash_table_insert(this->hostnames, name, reinterpret_cast<void*>(static_cast<intptr_t>(idx))); Debug("ssl", "indexed '%s' with SSL_CTX %p [%d]", name, this->ctx_store[idx].ctx, idx); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsConfigGrammar.c ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsConfigGrammar.c b/lib/tsconfig/TsConfigGrammar.c index 784affe..6bcaaf8 100644 --- a/lib/tsconfig/TsConfigGrammar.c +++ b/lib/tsconfig/TsConfigGrammar.c @@ -62,6 +62,7 @@ /* Line 349 of yacc.c */ #line 26 "TsConfigGrammar.y" +# if ! defined(__clang_analyzer__) # include "TsConfigTypes.h" # include <stdlib.h> @@ -79,7 +80,7 @@ extern int tsconfiglex(YYSTYPE* yylval, yyscan_t lexer); /* Line 349 of yacc.c */ -#line 83 "TsConfigGrammar.c" +#line 84 "TsConfigGrammar.c" /* Substitute the variable and function names. */ #define yyparse tsconfigparse @@ -93,7 +94,7 @@ extern int tsconfiglex(YYSTYPE* yylval, yyscan_t lexer); /* Copy the first part of user declarations. */ /* Line 371 of yacc.c */ -#line 97 "TsConfigGrammar.c" +#line 98 "TsConfigGrammar.c" # ifndef YY_NULL # if defined __cplusplus && 201103L <= __cplusplus @@ -151,7 +152,7 @@ extern int tsconfigdebug; /* Line 387 of yacc.c */ -#line 155 "TsConfigGrammar.c" +#line 156 "TsConfigGrammar.c" /* Tokens. */ #ifndef YYTOKENTYPE @@ -216,10 +217,10 @@ int tsconfigparse (); /* Copy the second part of user declarations. */ /* Line 390 of yacc.c */ -#line 220 "TsConfigGrammar.c" +#line 221 "TsConfigGrammar.c" /* Unqualified %code blocks. */ /* Line 391 of yacc.c */ -#line 43 "TsConfigGrammar.y" +#line 44 "TsConfigGrammar.y" # define HANDLE_EVENT(x,y) \ @@ -242,7 +243,7 @@ int tsconfigerror( /* Line 391 of yacc.c */ -#line 246 "TsConfigGrammar.c" +#line 247 "TsConfigGrammar.c" #ifdef short # undef short @@ -539,10 +540,10 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 85, 85, 87, 89, 91, 93, 93, 93, 95, - 95, 97, 99, 101, 103, 103, 103, 105, 105, 105, - 105, 107, 107, 107, 109, 109, 111, 113, 115, 117, - 117, 119, 119 + 0, 86, 86, 88, 90, 92, 94, 94, 94, 96, + 96, 98, 100, 102, 104, 104, 104, 106, 106, 106, + 106, 108, 108, 108, 110, 110, 112, 114, 116, 118, + 118, 120, 120 }; #endif @@ -1489,67 +1490,67 @@ yyreduce: { case 4: /* Line 1792 of yacc.c */ -#line 89 "TsConfigGrammar.y" +#line 90 "TsConfigGrammar.y" { HANDLE_EVENT(GroupOpen, (yyvsp[(1) - (1)])); } break; case 5: /* Line 1792 of yacc.c */ -#line 91 "TsConfigGrammar.y" +#line 92 "TsConfigGrammar.y" { HANDLE_EVENT(GroupClose, (yyvsp[(1) - (1)])); } break; case 9: /* Line 1792 of yacc.c */ -#line 95 "TsConfigGrammar.y" +#line 96 "TsConfigGrammar.y" { HANDLE_EVENT(GroupName, (yyvsp[(1) - (2)])); } break; case 12: /* Line 1792 of yacc.c */ -#line 99 "TsConfigGrammar.y" +#line 100 "TsConfigGrammar.y" { HANDLE_EVENT(ListOpen, (yyvsp[(1) - (1)])); } break; case 13: /* Line 1792 of yacc.c */ -#line 101 "TsConfigGrammar.y" +#line 102 "TsConfigGrammar.y" { HANDLE_EVENT(ListClose, (yyvsp[(1) - (1)])); } break; case 17: /* Line 1792 of yacc.c */ -#line 105 "TsConfigGrammar.y" +#line 106 "TsConfigGrammar.y" { HANDLE_EVENT(LiteralValue, (yyvsp[(1) - (1)])); } break; case 27: /* Line 1792 of yacc.c */ -#line 113 "TsConfigGrammar.y" +#line 114 "TsConfigGrammar.y" { HANDLE_EVENT(PathOpen, (yyvsp[(1) - (1)])); } break; case 28: /* Line 1792 of yacc.c */ -#line 115 "TsConfigGrammar.y" +#line 116 "TsConfigGrammar.y" { HANDLE_EVENT(PathClose, (yyvsp[(1) - (1)])); } break; case 31: /* Line 1792 of yacc.c */ -#line 119 "TsConfigGrammar.y" +#line 120 "TsConfigGrammar.y" { HANDLE_EVENT(PathTag, (yyvsp[(1) - (1)])); } break; case 32: /* Line 1792 of yacc.c */ -#line 119 "TsConfigGrammar.y" +#line 120 "TsConfigGrammar.y" { HANDLE_EVENT(PathIndex, (yyvsp[(1) - (1)])); } break; /* Line 1792 of yacc.c */ -#line 1553 "TsConfigGrammar.c" +#line 1554 "TsConfigGrammar.c" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1781,5 +1782,7 @@ yyreturn: /* Line 2055 of yacc.c */ -#line 121 "TsConfigGrammar.y" +#line 122 "TsConfigGrammar.y" + +# endif // __clang_analyzer__ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsConfigGrammar.y ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsConfigGrammar.y b/lib/tsconfig/TsConfigGrammar.y index d33eb46..63a0425 100644 --- a/lib/tsconfig/TsConfigGrammar.y +++ b/lib/tsconfig/TsConfigGrammar.y @@ -24,6 +24,7 @@ } %code top { +# if ! defined(__clang_analyzer__) # include "TsConfigTypes.h" # include <stdlib.h> @@ -119,3 +120,5 @@ path_item: path_tag | path_item PATH_SEPARATOR path_tag ; path_tag: IDENT { HANDLE_EVENT(PathTag, $1); } | INTEGER { HANDLE_EVENT(PathIndex, $1); }; %% + +# endif // __clang_analyzer__ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsConfigSyntax.c ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsConfigSyntax.c b/lib/tsconfig/TsConfigSyntax.c index 33403df..ea363c3 100644 --- a/lib/tsconfig/TsConfigSyntax.c +++ b/lib/tsconfig/TsConfigSyntax.c @@ -484,6 +484,8 @@ static yyconst flex_int16_t yy_chk[89] = See the License for the specific language governing permissions and limitations under the License. */ + +# if ! defined(__clang_analyzer__) # include "TsConfigParseEvents.h" # include "TsConfigGrammar.h" @@ -510,7 +512,7 @@ struct Location TsConfig_Lex_Location = { 0, 1 }; #define YY_NO_INPUT 1 -#line 514 "TsConfigSyntax.c" +#line 516 "TsConfigSyntax.c" #define INITIAL 0 #define bad 1 @@ -747,10 +749,10 @@ YY_DECL register int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 64 "TsConfigSyntax.l" +#line 66 "TsConfigSyntax.l" -#line 754 "TsConfigSyntax.c" +#line 756 "TsConfigSyntax.c" yylval = yylval_param; @@ -835,7 +837,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 66 "TsConfigSyntax.l" +#line 68 "TsConfigSyntax.l" { ++(TsConfig_Lex_Location._line); TsConfig_Lex_Location._col = 0; @@ -844,12 +846,12 @@ YY_RULE_SETUP case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 71 "TsConfigSyntax.l" +#line 73 "TsConfigSyntax.l" ZRET(STRING); /* Quote string overrides comments */ YY_BREAK case 3: YY_RULE_SETUP -#line 73 "TsConfigSyntax.l" +#line 75 "TsConfigSyntax.l" /* Ignore all white space. */ YY_BREAK case 4: @@ -858,7 +860,7 @@ case 4: yyg->yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 74 "TsConfigSyntax.l" +#line 76 "TsConfigSyntax.l" /* Leading '#' is a comment. */ YY_BREAK case 5: @@ -866,73 +868,73 @@ case 5: yyg->yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 75 "TsConfigSyntax.l" +#line 77 "TsConfigSyntax.l" /* Trailing '//' is a comment. */ YY_BREAK case 6: YY_RULE_SETUP -#line 77 "TsConfigSyntax.l" +#line 79 "TsConfigSyntax.l" ZRET(IDENT); YY_BREAK case 7: YY_RULE_SETUP -#line 78 "TsConfigSyntax.l" +#line 80 "TsConfigSyntax.l" ZRET(INTEGER); YY_BREAK case 8: YY_RULE_SETUP -#line 79 "TsConfigSyntax.l" +#line 81 "TsConfigSyntax.l" ZRET(GROUP_OPEN); YY_BREAK case 9: YY_RULE_SETUP -#line 80 "TsConfigSyntax.l" +#line 82 "TsConfigSyntax.l" ZRET(GROUP_CLOSE); YY_BREAK case 10: YY_RULE_SETUP -#line 81 "TsConfigSyntax.l" +#line 83 "TsConfigSyntax.l" ZRET(LIST_OPEN); YY_BREAK case 11: YY_RULE_SETUP -#line 82 "TsConfigSyntax.l" +#line 84 "TsConfigSyntax.l" ZRET(LIST_CLOSE); YY_BREAK case 12: YY_RULE_SETUP -#line 83 "TsConfigSyntax.l" +#line 85 "TsConfigSyntax.l" ZRET(PATH_OPEN); YY_BREAK case 13: YY_RULE_SETUP -#line 84 "TsConfigSyntax.l" +#line 86 "TsConfigSyntax.l" ZRET(PATH_CLOSE); YY_BREAK case 14: YY_RULE_SETUP -#line 85 "TsConfigSyntax.l" +#line 87 "TsConfigSyntax.l" ZRET(PATH_SEPARATOR); YY_BREAK case 15: YY_RULE_SETUP -#line 86 "TsConfigSyntax.l" +#line 88 "TsConfigSyntax.l" ZRET(ASSIGN); YY_BREAK case 16: YY_RULE_SETUP -#line 87 "TsConfigSyntax.l" +#line 89 "TsConfigSyntax.l" ZRET(SEPARATOR); YY_BREAK case 17: YY_RULE_SETUP -#line 89 "TsConfigSyntax.l" +#line 91 "TsConfigSyntax.l" BEGIN(bad); FILL; YY_BREAK case 18: /* rule 18 can match eol */ YY_RULE_SETUP -#line 90 "TsConfigSyntax.l" +#line 92 "TsConfigSyntax.l" { BEGIN(0); // Terminate bad token mode. ++(TsConfig_Lex_Location._line); // Must bump line count. @@ -942,20 +944,20 @@ YY_RULE_SETUP case 19: /* rule 19 can match eol */ YY_RULE_SETUP -#line 95 "TsConfigSyntax.l" +#line 97 "TsConfigSyntax.l" BEGIN(0); HANDLE_EVENT(InvalidToken); YY_BREAK case 20: YY_RULE_SETUP -#line 96 "TsConfigSyntax.l" +#line 98 "TsConfigSyntax.l" ++(yylval->_n); YY_BREAK case 21: YY_RULE_SETUP -#line 97 "TsConfigSyntax.l" +#line 99 "TsConfigSyntax.l" ECHO; YY_BREAK -#line 959 "TsConfigSyntax.c" +#line 961 "TsConfigSyntax.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(bad): yyterminate(); @@ -2086,7 +2088,7 @@ void tsconfigfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 97 "TsConfigSyntax.l" +#line 99 "TsConfigSyntax.l" @@ -2117,3 +2119,5 @@ int tsconfig_parse_buffer( return zret; } +# endif // __clang_analyzer__ + http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsConfigSyntax.l ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsConfigSyntax.l b/lib/tsconfig/TsConfigSyntax.l index 6a07463..d7d6d7e 100644 --- a/lib/tsconfig/TsConfigSyntax.l +++ b/lib/tsconfig/TsConfigSyntax.l @@ -22,6 +22,8 @@ See the License for the specific language governing permissions and limitations under the License. */ + +# if ! defined(__clang_analyzer__) # include "TsConfigParseEvents.h" # include "TsConfigGrammar.h" @@ -122,3 +124,5 @@ int tsconfig_parse_buffer( return zret; } + +# endif // __clang_analyzer__ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsErrataUtil.cc ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsErrataUtil.cc b/lib/tsconfig/TsErrataUtil.cc index 7e8b77b..0cbec18 100644 --- a/lib/tsconfig/TsErrataUtil.cc +++ b/lib/tsconfig/TsErrataUtil.cc @@ -135,7 +135,7 @@ Errata vlogf_errno(Errata& errata, Errata::Id id, Errata::Code code, char const* format, va_list& rest) { int e = errno; // Preserve value before making system calls. int n; - static int const E_SIZE = 256; + static int const E_SIZE = 512; char e_buffer[E_SIZE]; static int const T_SIZE = 8192; char t_buffer[T_SIZE]; @@ -143,7 +143,7 @@ vlogf_errno(Errata& errata, Errata::Id id, Errata::Code code, char const* format n = vsnprintf(t_buffer, T_SIZE, format, rest); if (0 <= n && n < T_SIZE) { // still have room. ATS_UNUSED_RETURN(strerror_r(e, e_buffer, E_SIZE)); - n += snprintf(t_buffer + n, T_SIZE - n, "[%d] %s", e, e_buffer); + snprintf(t_buffer + n, T_SIZE - n, "[%d] %s", e, e_buffer); } errata.push(id, code, t_buffer); return errata; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f02b5a6d/lib/tsconfig/TsValue.cc ---------------------------------------------------------------------- diff --git a/lib/tsconfig/TsValue.cc b/lib/tsconfig/TsValue.cc index 06beaec..959db9e 100644 --- a/lib/tsconfig/TsValue.cc +++ b/lib/tsconfig/TsValue.cc @@ -46,31 +46,31 @@ detail::PseudoBool::Type const detail::PseudoBool::TRUE = &detail::PseudoBool::o bool detail::PseudoBool::operator ! () const { return false; } // --------------------------------------------------------------------------- unsigned int const detail::Type_Property[N_VALUE_TYPES] = { - 0, // Void - detail::IS_VALID | detail::IS_CONTAINER, // List - detail::IS_VALID | detail::IS_CONTAINER, // Group - detail::IS_VALID | detail::IS_LITERAL, // String - detail::IS_VALID | detail::IS_LITERAL, // Integer + 0, // Void + detail::IS_VALID | detail::IS_CONTAINER, // List + detail::IS_VALID | detail::IS_CONTAINER, // Group + detail::IS_VALID | detail::IS_LITERAL, // String + detail::IS_VALID | detail::IS_LITERAL, // Integer }; // --------------------------------------------------------------------------- detail::ValueTableImpl::ValueTableImpl() : _generation(0) { } detail::ValueTableImpl::~ValueTableImpl() { - for ( BufferGroup::iterator spot(_buffers.begin()), limit(_buffers.end()) ; spot != limit ; ++spot) - free(spot->_ptr); + for ( BufferGroup::iterator spot(_buffers.begin()), limit(_buffers.end()) ; spot != limit ; ++spot) + free(spot->_ptr); } // --------------------------------------------------------------------------- detail::ValueTable::ImplType* detail::ValueTable::instance() { - if (! _ptr) _ptr.reset(new ImplType); - return _ptr.get(); + if (! _ptr) _ptr.reset(new ImplType); + return _ptr.get(); } detail::ValueTable& detail::ValueTable::forceRootItem() { - ImplType* imp = this->instance(); - if (0 == imp->_values.size()) - imp->_values.push_back(ValueItem(GroupValue)); - return *this; + ImplType* imp = this->instance(); + if (0 == imp->_values.size()) + imp->_values.push_back(ValueItem(GroupValue)); + return *this; } Rv<detail::ValueIndex> @@ -107,220 +107,220 @@ detail::ValueTable::make(ValueIndex pidx, ValueType type, ConstBuffer const& nam detail::ValueItem& detail::ValueTable::operator [] ( ValueIndex idx ) { - assert(_ptr && idx < _ptr->_values.size()); - return _ptr->_values[idx]; + assert(_ptr && idx < _ptr->_values.size()); + return _ptr->_values[idx]; } Buffer detail::ValueTable::alloc(size_t n) { - ImplType* imp = this->instance(); - Buffer zret(static_cast<char*>(malloc(n)), n); - if (zret._ptr) imp->_buffers.push_back(zret); - return zret; + ImplType* imp = this->instance(); + Buffer zret(static_cast<char*>(malloc(n)), n); + if (zret._ptr) imp->_buffers.push_back(zret); + return zret; } // --------------------------------------------------------------------------- Value Value::operator [] (size_t idx) const { - Value zret; - detail::ValueItem const* item = this->item(); - if (item && idx < item->_children.size()) { - zret = Value(_config, item->_children[idx]); - if (PathValue == zret.getType()) zret = _config.getRoot().find(_config._table[zret._vidx]._path); - } - return zret; + Value zret; + detail::ValueItem const* item = this->item(); + if (item && idx < item->_children.size()) { + zret = Value(_config, item->_children[idx]); + if (PathValue == zret.getType()) zret = _config.getRoot().find(_config._table[zret._vidx]._path); + } + return zret; } Value Value::operator [] (ConstBuffer const& name) const { - Value zret; - detail::ValueItem const* item = this->item(); - if (item) { - for ( detail::ValueItem::ChildGroup::const_iterator spot = item->_children.begin(), limit = item->_children.end(); spot != limit; ++spot ) { - if (_config._table[*spot]._name == name) { - zret = Value(_config, *spot); - if (PathValue == zret.getType()) zret = _config.getRoot().find(_config._table[zret._vidx]._path); - break; - } - } + Value zret; + detail::ValueItem const* item = this->item(); + if (item) { + for ( detail::ValueItem::ChildGroup::const_iterator spot = item->_children.begin(), limit = item->_children.end(); spot != limit; ++spot ) { + if (_config._table[*spot]._name == name) { + zret = Value(_config, *spot); + if (PathValue == zret.getType()) zret = _config.getRoot().find(_config._table[zret._vidx]._path); + break; + } } - return zret; + } + return zret; } Value Value::find( ConstBuffer const& path ) { - Value zret = *this; - Path::Parser parser(path); - Rv<Path::Parser::Result> x; - ConstBuffer elt; - for ( x = parser.parse(&elt) ; zret && Path::Parser::EOP != x && Path::Parser::ERROR != x ; x = parser.parse(&elt) ) { - if (Path::Parser::TAG == x) zret = zret[elt]; - else if (Path::Parser::INDEX == x) zret = zret[elt._size]; - else zret.reset(); - } - if (Path::Parser::EOP != x) zret.reset(); - return zret; + Value zret = *this; + Path::Parser parser(path); + Rv<Path::Parser::Result> x; + ConstBuffer elt; + for ( x = parser.parse(&elt) ; zret && Path::Parser::EOP != x && Path::Parser::ERROR != x ; x = parser.parse(&elt) ) { + if (Path::Parser::TAG == x) zret = zret[elt]; + else if (Path::Parser::INDEX == x) zret = zret[elt._size]; + else zret.reset(); + } + if (Path::Parser::EOP != x) zret.reset(); + return zret; } Value Value::find(Path const& path ) { - Value zret = *this; - for ( size_t i = 0, n = path.count() ; i < n && zret ; ++i ) { - ConstBuffer const& elt = path[i]; - if (elt._ptr) zret = zret[elt]; - else zret = zret[elt._size]; - } - return zret; + Value zret = *this; + for ( size_t i = 0, n = path.count() ; i < n && zret ; ++i ) { + ConstBuffer const& elt = path[i]; + if (elt._ptr) zret = zret[elt]; + else zret = zret[elt._size]; + } + return zret; } Rv<Value> Value::makeChild(ValueType type, ConstBuffer const& name) { - Rv<Value> zret; - Rv<detail::ValueIndex> vr = _config._table.make(this->_vidx, type, name); - if (vr.isOK()) zret = Value(_config, vr.result()); - else zret.errata() = vr.errata(); - return zret; + Rv<Value> zret; + Rv<detail::ValueIndex> vr = _config._table.make(this->_vidx, type, name); + if (vr.isOK()) zret = Value(_config, vr.result()); + else zret.errata() = vr.errata(); + return zret; } Rv<Value> Value::makeGroup(ConstBuffer const& name) { - return this->makeChild(GroupValue, name); + return this->makeChild(GroupValue, name); } Rv<Value> Value::makeList(ConstBuffer const& name) { - return this->makeChild(ListValue, name); + return this->makeChild(ListValue, name); } Rv<Value> Value::makeString(ConstBuffer const& text, ConstBuffer const& name) { - Rv<Value> zret = this->makeChild(StringValue, name); - if (zret.isOK()) zret.result().setText(text); - return zret; + Rv<Value> zret = this->makeChild(StringValue, name); + if (zret.isOK()) zret.result().setText(text); + return zret; } Rv<Value> Value::makeInteger(ConstBuffer const& text, ConstBuffer const& name) { - Rv<Value> zret = this->makeChild(IntegerValue, name); - if (zret.isOK()) zret.result().setText(text); - return zret; + Rv<Value> zret = this->makeChild(IntegerValue, name); + if (zret.isOK()) zret.result().setText(text); + return zret; } Rv<Value> Value::makePath(Path const& path, ConstBuffer const& name) { - Rv<Value> zret = this->makeChild(PathValue, name); - if (zret.isOK()) _config._table[zret.result()._vidx]._path = path; - return zret; + Rv<Value> zret = this->makeChild(PathValue, name); + if (zret.isOK()) _config._table[zret.result()._vidx]._path = path; + return zret; } // --------------------------------------------------------------------------- Path& Path::reset() { - if (_ptr) { - // If we're sharing the instance, make a new one for us. - if (_ptr.isShared()) _ptr = new ImplType; - else { // clear out the existing instance. - _ptr->_elements.clear(); - } + if (_ptr) { + // If we're sharing the instance, make a new one for us. + if (_ptr.isShared()) _ptr = new ImplType; + else { // clear out the existing instance. + _ptr->_elements.clear(); } - return *this; + } + return *this; } // --------------------------------------------------------------------------- Rv<Path::Parser::Result> Path::Parser::parse(ConstBuffer *cbuff) { - Rv<Result> zret = EOP; - enum State { - S_INIT, // initial state - S_INDEX, // reading index. - S_TAG, // reading tag. - S_DASH, // reading dashes in tag. - } state = S_INIT; + Rv<Result> zret = EOP; + enum State { + S_INIT, // initial state + S_INDEX, // reading index. + S_TAG, // reading tag. + S_DASH, // reading dashes in tag. + } state = S_INIT; - // Character bucket - enum Bucket { - C_INVALID, // Invalid input. - C_DIGIT, // digit. - C_IDENT, // Identifier character. - C_DASH, // A dash - C_DOT, // A dot (period). - }; + // Character bucket + enum Bucket { + C_INVALID, // Invalid input. + C_DIGIT, // digit. + C_IDENT, // Identifier character. + C_DASH, // A dash + C_DOT, // A dot (period). + }; - if (cbuff) cbuff->reset(); - char const* start = _c; // save starting character location. - size_t idx = 0; // accumulator for index value. + if (cbuff) cbuff->reset(); + char const* start = _c; // save starting character location. + size_t idx = 0; // accumulator for index value. - bool final = false; - while (! final && this->hasInput()) { - Bucket cb; - if (isdigit(*_c)) cb = C_DIGIT; - else if ('_' == *_c || isalpha(*_c)) cb = C_IDENT; - else if ('-' == *_c) cb = C_DASH; - else if ('.' == *_c) cb = C_DOT; - else cb = C_INVALID; + bool final = false; + while (! final && this->hasInput()) { + Bucket cb; + if (isdigit(*_c)) cb = C_DIGIT; + else if ('_' == *_c || isalpha(*_c)) cb = C_IDENT; + else if ('-' == *_c) cb = C_DASH; + else if ('.' == *_c) cb = C_DOT; + else cb = C_INVALID; - if (C_INVALID == cb) { - msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in path.", *_c, *_c); - } else switch (state) { - case S_INIT: - switch (cb) { - case C_DIGIT: state = S_INDEX; idx = *_c - '0'; break; - case C_IDENT: state = S_TAG; break; - case C_DASH: msg::logf(zret, msg::WARN, "Dash not allowed as leading character for tag."); final = true; break; - case C_DOT: msg::logf(zret, msg::WARN, "Separator without preceding element."); final = true; break; - default: msg::logf(zret, msg::WARN, "Internal error: unexpected character %u in INIT state.", *_c); final = true; break; - } - break; - case S_INDEX: // reading an index. - if (C_DIGIT == cb) idx = 10 * idx + *_c - '0'; - else if (C_DOT == cb) { final = true; } - else { - msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); - final = true; - } - break; - case S_TAG: // reading a tag. - if (C_IDENT == cb || C_DIGIT == cb) ; // continue - else if (C_DASH == cb) state = S_DASH; - else if (C_DOT == cb) { final = true; } - else { // should never happen, but be safe. - msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); - final = true; - } - break; - case S_DASH: // dashes inside tag. - if (C_IDENT == cb || C_DIGIT == cb) state = S_TAG; - else if (C_DOT == cb) { - msg::log(zret, msg::WARN, "Trailing dash not allowed in tag element."); - final = true; - } else if (C_DASH != cb) { // should never happen, but be safe. - msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); - final = true; - } - break; + if (C_INVALID == cb) { + msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in path.", *_c, *_c); + } else switch (state) { + case S_INIT: + switch (cb) { + case C_DIGIT: state = S_INDEX; idx = *_c - '0'; break; + case C_IDENT: state = S_TAG; break; + case C_DASH: msg::logf(zret, msg::WARN, "Dash not allowed as leading character for tag."); final = true; break; + case C_DOT: msg::logf(zret, msg::WARN, "Separator without preceding element."); final = true; break; + default: msg::logf(zret, msg::WARN, "Internal error: unexpected character %u in INIT state.", *_c); final = true; break; } - ++_c; - } - if (!zret.isOK()) { - zret = ERROR; - if (cbuff) cbuff->set(_c - 1, 1); - _c = 0; - _input.reset(); - } else if (S_INIT == state) { - zret = EOP; - } else if (S_TAG == state) { - zret = TAG; - if (cbuff) { - cbuff->set(start, _c - start); - // if @a final is set, then we parsed a dot separator. - // don't include it in the returned tag. - if (final) cbuff->_size -= 1; + break; + case S_INDEX: // reading an index. + if (C_DIGIT == cb) idx = 10 * idx + *_c - '0'; + else if (C_DOT == cb) { final = true; } + else { + msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); + final = true; + } + break; + case S_TAG: // reading a tag. + if (C_IDENT == cb || C_DIGIT == cb) ; // continue + else if (C_DASH == cb) state = S_DASH; + else if (C_DOT == cb) { final = true; } + else { // should never happen, but be safe. + msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); + final = true; } - } else if (S_INDEX == state) { - zret = INDEX; - if (cbuff) cbuff->_size = idx; - } else if (S_DASH == state) { - zret = ERROR; - msg::log(zret, msg::WARN, "Trailing dash not allowed in tag element."); - if (cbuff) cbuff->set(start, _c - start); + break; + case S_DASH: // dashes inside tag. + if (C_IDENT == cb || C_DIGIT == cb) state = S_TAG; + else if (C_DOT == cb) { + msg::log(zret, msg::WARN, "Trailing dash not allowed in tag element."); + final = true; + } else if (C_DASH != cb) { // should never happen, but be safe. + msg::logf(zret, msg::WARN, "Invalid character '%c' [%u] in index element.", *_c, *_c); + final = true; + } + break; + } + ++_c; + } + if (!zret.isOK()) { + zret = ERROR; + if (cbuff) cbuff->set(_c - 1, 1); + _c = 0; + _input.reset(); + } else if (S_INIT == state) { + zret = EOP; + } else if (S_TAG == state) { + zret = TAG; + if (cbuff) { + cbuff->set(start, _c - start); + // if @a final is set, then we parsed a dot separator. + // don't include it in the returned tag. + if (final) cbuff->_size -= 1; } - return zret; + } else if (S_INDEX == state) { + zret = INDEX; + if (cbuff) cbuff->_size = idx; + } else if (S_DASH == state) { + zret = ERROR; + msg::log(zret, msg::WARN, "Trailing dash not allowed in tag element."); + if (cbuff) cbuff->set(start, _c - start); + } + return zret; } // --------------------------------------------------------------------------- Value @@ -331,34 +331,35 @@ Configuration::getRoot() const { Rv<Configuration> Configuration::loadFromPath(char const* path) { - Rv<Configuration> zret; - Buffer buffer; - FILE* in = fopen(path, "r"); + Rv<Configuration> zret; + Buffer buffer; + FILE* in = fopen(path, "r"); - if (in) { - struct stat info; - if (0 == fstat(_fileno(in), &info)) { - // Must reserve 2 bytes at the end for FLEX terminator. - buffer = zret.result().alloc(info.st_size + 2); - if (buffer._ptr) { - size_t n; - if (0 < (n = fread(buffer._ptr, sizeof(char), info.st_size, in))) { - buffer._size = n+2; - memset(buffer._ptr + n, 0, 2); // required by FLEX - zret = Builder(zret.result()).build(buffer); - } else { - msg::logf_errno(zret, msg::WARN, "failed to read %" PRIu64 " bytes from configuration file '%s'", info.st_size, path); - } - } else { - msg::logf_errno(zret, msg::WARN, "failed to allocate buffer for configuration file '%s' - needed %" PRIu64 " bytes.", path, info.st_size); - } + if (in) { + struct stat info; + if (0 == fstat(_fileno(in), &info)) { + // Must reserve 2 bytes at the end for FLEX terminator. + buffer = zret.result().alloc(info.st_size + 2); + if (buffer._ptr) { + size_t n; + if (0 < (n = fread(buffer._ptr, sizeof(char), info.st_size, in))) { + buffer._size = n+2; + memset(buffer._ptr + n, 0, 2); // required by FLEX + zret = Builder(zret.result()).build(buffer); } else { - msg::logf_errno(zret, msg::WARN, "failed to determine file information on '%s'", path); + msg::logf_errno(zret, msg::WARN, "failed to read %" PRIu64 " bytes from configuration file '%s'", info.st_size, path); } + } else { + msg::logf_errno(zret, msg::WARN, "failed to allocate buffer for configuration file '%s' - needed %" PRIu64 " bytes.", path, info.st_size); + } } else { - msg::logf_errno(zret, msg::WARN, "failed to open configuration file '%s'", path); + msg::logf_errno(zret, msg::WARN, "failed to determine file information on '%s'", path); } - return zret; + fclose(in); + } else { + msg::logf_errno(zret, msg::WARN, "failed to open configuration file '%s'", path); + } + return zret; } }} // namespace ts::config
