void plog(struct lib_context *lc, int level, int lf, const char *file, int line, const char *format, ...) { int o = LC_VERBOSE, l = level; FILE *f = stdout; va_list ap; if (level == _PLOG_DEBUG) { o = LC_DEBUG; l -= _PLOG_WARN; } if (level == _PLOG_ERR || level == _PLOG_FATAL) f = stderr; /* Checking lc here to allow early calls without a context. */ else if (lc && lc_opt(lc, o) < l) return; if (_prefix(level)) fprintf(f, "%s: ", _prefix(level)); va_start(ap, format); vfprintf(f, format, ap); va_end(ap); if (lf) fputc('\n', f); }
std::string OcelotConfig::string() const { std::string result; if( version ) { result = _version(); } else if( flags ) { result = _flags(); } else if( prefix ) { result = _prefix(); } else if( libs ) { result = _libs(); } else if( includedir ) { result = _includedir(); } else if( libdir ) { result = _libdir(); } else if( bindir ) { result = _bindir(); } else { return ""; } if( trace ) { result += _tracelibs(); } return result + "\n"; }
// Write method template<typename T> inline void message(T msg, LogLevel level) { if (level <= logLevel) std::cout << _prefix(level) << msg << std::endl; }
bool zpt::RESTServer::route_http(zpt::socketstream_ptr _cs) { zpt::http::rep _reply; _reply->status((zpt::HTTPStatus) 200); zpt::http::req _request; try { (*_cs) >> _request; } catch(zpt::SyntaxErrorException& _e) { assertz(false, "error parsing HTTP data", 500, 0); } bool _return = false; bool _api_found = false; std::string _prefix(_request->url()); if (this->__options["directory"]->ok()) { for (auto _api : this->__options["directory"]->obj()) { bool _endpoint_found = false; for (auto _endpoint : _api.second["endpoints"]->arr()) { if (_prefix.find(_endpoint->str()) == 0) { _endpoint_found = true; _api_found = true; short _type = zpt::str2type(_api.second["type"]->str()); zpt::json _in = zpt::rest::http2zmq(_request); switch(_type) { case ZMQ_REP : case ZMQ_REQ : case ZMQ_ROUTER_DEALER : { zpt::socket _client = this->__poll->bind(ZMQ_ASSYNC_REQ, _api.second["connect"]->str()); _client->relay_for(_cs, [] (zpt::json _envelope) -> std::string { return std::string(zpt::rest::zmq2http(_envelope)); } ); _client->send(_in); _return = false; break; } case ZMQ_PUB_SUB : { std::string _connect = _api.second["connect"]->str(); zpt::socket _client = this->__poll->bind(ZMQ_PUB, _connect.substr(0, _connect.find(","))); _client->send(_in); zpt::http::rep _reply = zpt::rest::zmq2http(zpt::rest::accepted(_prefix)); (*_cs) << _reply << flush; _return = true; _client->unbind(); break; } case ZMQ_PUSH : { zpt::socket _client = this->__poll->bind(ZMQ_PUSH, _api.second["connect"]->str()); _client->send(_in); zpt::http::rep _reply = zpt::rest::zmq2http(zpt::rest::accepted(_prefix)); (*_cs) << _reply << flush; _return = true; _client->unbind(); break; } } break; } } if (_endpoint_found) { break; } } } if (!_api_found) { zlog(string("-> | \033[33;40m") + zpt::method_names[_request->method()] + string("\033[0m ") + _request->url(), zpt::info); zlog(string("<- | \033[31;40m404\033[0m"), zpt::info); zpt::http::rep _reply = zpt::rest::zmq2http(zpt::rest::not_found(_prefix)); (*_cs) << _reply << flush; _return = true; } return _return; }
static int _useidch(chtype *wcp, chtype *scp, int length, int maxi, int *id) { int x1, x2, blnk, idch, cost, cost_ich1, match; chtype wc; /* try deletion */ if (SP->dchok && _CHAR(*wcp) != ' ') { if ((match = _prefix(wcp, scp, length, length / 2, &idch)) > 0) cost = _COST(dcfixed) + (parm_dch ? _COST(Parm_dch) : _COST(Delete_character) * idch); else cost = _INFINITY; if (match >= cost) { /* SS: colors */ if (back_color_erase) _turn_off_background(); if (SP->dmode) { if (SP->sid_equal) { if (!(SP->phys_irm)) _ONINSERT(); } else { if (SP->phys_irm) _OFFINSERT(); _PUTS(enter_delete_mode, 1); } } if (parm_dch) _PUTS(tparm_p1(parm_dch, idch), 1); else for (x1 = 0; x1 < idch; ++x1) _PUTS(delete_character, 1); if (SP->dmode) { if (SP->eid_equal) SP->phys_irm = FALSE; _PUTS(exit_delete_mode, 1); } /* update screen image */ for (x1 = 0, x2 = idch; x2 < length; ++x1, ++x2) scp[x1] = scp[x2]; for (; x1 < length; ++x1) scp[x1] = ' '; *id = -idch; return (match); } } /* no insertion wanted or possible */ if (!(SP->ichok) || _CHAR(*scp) == ' ') return (0); /* see if insertion is worth it */ maxi = (idch = length / 2) < maxi ? idch : maxi; if ((match = _prefix(scp, wcp, length, maxi, &idch)) <= 0) return (0); /* see if inserting blanks only */ for (blnk = 0; blnk < idch; ++blnk) if (wcp[blnk] != ' ') { blnk = 0; break; } /* see if doing insertion is worth it */ cost_ich1 = idch * _COST(Insert_character); if (SP->imode) { cost = SP->phys_irm ? 0 : _COST(icfixed); if (blnk > _COST(Parm_ich) && _COST(Parm_ich) < cost_ich1) cost += _COST(Parm_ich); else if (insert_character) cost += cost_ich1; } else { if (parm_ich && _COST(Parm_ich) < cost_ich1) cost = _COST(Parm_ich); else cost = cost_ich1; } if ((cost - blnk) > match) return (0); /* perform the insertions */ /* SS: colors */ if (back_color_erase) _turn_off_background(); if (SP->imode) { if (!SP->phys_irm) _ONINSERT(); if (blnk > _COST(Parm_ich) && _COST(Parm_ich) < cost_ich1) _PUTS(tparm_p1(parm_ich, idch), 1); else if (insert_character) goto do_insert_char; else /* so that we'll do real char insertions */ blnk = 0; } else { if (parm_ich && _COST(Parm_ich) < cost_ich1) _PUTS(tparm_p1(parm_ich, idch), 1); else { do_insert_char: for (x1 = 0; x1 < idch; ++x1) _PUTS(insert_character, 1); } } /* inserting desired characters */ if (!blnk) for (x1 = 0; x1 < idch; ++x1) { wc = wcp[x1]; if (_ATTR(wc) != curscr->_attrs) _VIDS(_ATTR(wc), curscr->_attrs); (void) _outwch(_CHAR(wc) == '~' && tilde_glitch ? '`' : wc); ++cx; } /* update the screen image */ for (x1 = length - 1, x2 = length - idch - 1; x2 >= 0; --x1, --x2) scp[x1] = scp[x2]; (void) memcpy((char *) scp, (char *) wcp, idch * sizeof (chtype)); *id = idch; return (match + idch); }