//-------------------------------------------------------------------------------- CPipeConnector::CPipeConnector( nsBluefoot::CBFConnectionPool* pPool ) : nsBluefoot::CBFPlug( pPool ) { _WINQ_FCONTEXT( "CPipeConnector::CPipeConnector" ); m_pSecurity = 0; m_strServerName = CTString( _TXT( "." ) ); m_ulAccess = nsWin32::Generic_Read | nsWin32::Generic_Write; m_ulShareMode = 0; m_ulFlags = 0; m_ulConnectionTimeout = DefaultClientConnectionTimeout; }
static unsigned int parseNumber( const char* arg, const char* location) { unsigned int rt = 0; char const* ai = arg; for (; *ai >= '0' && *ai <= '9'; ++ai) { rt = rt * 10 + (*ai - '0'); } if (*ai) throw strus::runtime_error( _TXT("number expected as %s"), location); return rt; }
MetaDataRangePostingIterator( MetaDataReaderInterface* metareader_, Index nofDocuments_, const std::string& name_from, const std::string& name_to, ErrorBufferInterface* errorhnd_) :m_errorhnd(errorhnd_) ,m_metareader(metareader_) ,m_docno(0) ,m_handle_lo(name_from.empty()?-1:metareader_->elementHandle(name_from)) ,m_handle_hi(name_to.empty()?-1:metareader_->elementHandle(name_to)) ,m_pos_lo(0) ,m_pos_hi(0) ,m_posno(0) ,m_nofDocuments(nofDocuments_) { m_featureid.append( name_from); m_featureid.push_back( ':'); m_featureid.append( name_to); m_featureid.push_back( ':'); m_featureid.push_back( 'M'); if (m_handle_lo < 0 && !name_from.empty()) throw strus::runtime_error(_TXT("failed to define posting iterator from meta data (lower bound): undefined metadata element '%s'"), name_from.c_str()); if (m_handle_hi < 0 && !name_to.empty()) throw strus::runtime_error(_TXT("failed to define posting iterator from meta data (upper bound): undefined metadata element '%s'"), name_to.c_str()); }
const char* operator[]( const std::string& optname) const { if (m_opt.count( optname) > 1) { throw strus::runtime_error( _TXT("option '%s' specified more than once"), optname.c_str()); } std::map<std::string,std::string>::const_iterator oi = m_opt.find( optname); if (oi == m_opt.end()) return 0; return oi->second.c_str(); }
static inline const char* skipChar( const char* si) { unsigned char charsize = utf8charlen( *si); if (!charsize) { throw strus::runtime_error(_TXT( "illegal UTF-8 character in input: %u"), (unsigned int)(unsigned char)*si); } else { return si+charsize; } }
static void printStorageConfigOptions( std::ostream& out, const strus::ModuleLoaderInterface* moduleLoader, const std::string& config, strus::ErrorBufferInterface* errorhnd) { std::string configstr( config); std::string dbname; (void)strus::extractStringFromConfigString( dbname, configstr, "database", errorhnd); if (errorhnd->hasError()) throw strus::runtime_error(_TXT("cannot evaluate database: %s"), errorhnd->fetchError()); std::auto_ptr<strus::StorageObjectBuilderInterface> storageBuilder( moduleLoader->createStorageObjectBuilder()); if (!storageBuilder.get()) throw strus::runtime_error(_TXT("failed to create storage object builder")); const strus::DatabaseInterface* dbi = storageBuilder->getDatabase( dbname); if (!dbi) throw strus::runtime_error(_TXT("failed to get database interface")); const strus::StorageInterface* sti = storageBuilder->getStorage(); if (!sti) throw strus::runtime_error(_TXT("failed to get storage interface")); strus::printIndentMultilineString( out, 12, dbi->getConfigDescription( strus::DatabaseInterface::CmdCreateClient), errorhnd); strus::printIndentMultilineString( out, 12, sti->getConfigDescription( strus::StorageInterface::CmdCreateClient), errorhnd); }
virtual void skip( const char* value, std::size_t size) { try { Index val; m_hasValue = dbcursor.skip( std::string( value, size), m_value, val); if (m_hasValue) { m_hasInit = true; } } CATCH_ERROR_MAP( _TXT( "error in skip to key of storage value iterator: %s"), *m_errorhnd); }
static void printUsage() { std::cout << "strusResizeBlocks [options] <config> <blocktype> <newsize>" << std::endl; std::cout << "options:" << std::endl; std::cout << "-h|--help" << std::endl; std::cout << " " << _TXT("Print this usage and do nothing else") << std::endl; std::cout << "-v|--version" << std::endl; std::cout << " " << _TXT("Print the program version and do nothing else") << std::endl; std::cout << "-c|--commit <N>" << std::endl; std::cout << " " << _TXT("Set <N> as number of documents inserted per transaction (default 1000)") << std::endl; std::cout << "-D|--docno <START>:<END>" << std::endl; std::cout << " " << _TXT("Process document number range <START> to <END>") << std::endl; std::cout << "-T|--termtype <TYPE>" << std::endl; std::cout << " " << _TXT("Set <TYPE> as term type to select for resize") << std::endl; std::cout << "<config> : " << _TXT("configuration string of the key/value store database") << std::endl; std::cout << "<blocktype> : " << _TXT("storage block type. One of the following:") << std::endl; std::cout << " forwardindex:" << _TXT("forward index block type") << std::endl; std::cout << "<newsize> : " << _TXT("new size of the blocks, unit depends on block type.") << std::endl; }
static void init_global_context( const char* logfile) { g_glbctx.init_handlerdata = &init_handlerdata; g_glbctx.done_handlerdata = &done_handlerdata; g_glbctx.request_handler = &request_handler; if (logfile) { std::cerr << _TXT("strus RPC server writing logs to file '") << logfile << "'" << std::endl; g_glbctx.logf = ::fopen( logfile, "a+"); } else { g_glbctx.logf = stderr; } }
static std::string parseIdentifier( std::string::const_iterator& si, const std::string::const_iterator& se, const char* idname) { si = skipSpaces( si, se); if (!isIdentifier( *si)) { std::string str( si, se); throw strus::runtime_error( _TXT( "identifier (%s) expected at '%s'"), idname, str.c_str()); } std::string rt; for (; si != se && isIdentifier( *si); ++si) { rt.push_back( *si); } return rt; }
void TSVSegmenterContext::putInput( const char *chunk, std::size_t chunksize, bool eof ) { try { #ifdef STRUS_LOWLEVEL_DEBUG std::cout << "DEBUG: putInput '" << chunksize << " (eof: " << eof << ")" << std::endl; #endif if( m_eof ) { m_errbuf->report( "fed chunk after declared end of input" ); return; } m_buf.append( chunk, chunksize ); m_eof |= eof; m_is.str( m_buf ); } CATCH_ERROR_MAP_ARG1( _TXT("error in put input of '%s' segmenter: %s"), SEGMENTER_NAME, *m_errbuf); }
static int init_handlerdata( struct strus_handlerdata_t* handlerdata) { handler_context_t* ctx = reinterpret_cast<handler_context_t*>( handlerdata); try { ctx->obj = 0; new (&ctx->resultbuf) std::string(); } catch (const std::bad_alloc& err) { fprintf( g_glbctx.logf, _TXT("memory allocation error initializing request handler object: %s\n"), err.what()); return 1; } catch (...) { fprintf( g_glbctx.logf, "unknown exception initializing request handler object\n"); return 2; } return 0; }
static std::pair<unsigned int,unsigned int> parseNumberRange( const char* arg, const char* location) { unsigned int first = 0; unsigned int second = 0; char const* ai = arg; for (; *ai >= '0' && *ai <= '9'; ++ai) { first = first * 10 + (*ai - '0'); } if (*ai == ':') { for (++ai; *ai >= '0' && *ai <= '9'; ++ai) { second = second * 10 + (*ai - '0'); } } else { second = first; } if (*ai) throw strus::runtime_error( _TXT("number range expected as %s"), location); return std::pair<unsigned int,unsigned int>(first,second); }
virtual bool getNext( SegmenterPosition& segpos, const char*& segment, std::size_t& segmentsize) { try { if (m_segmentitr != m_segmentmap.end() && m_segmentitr->first == segpos) { ++m_segmentitr; } else if (segpos == 0) { m_segmentitr = m_segmentmap.begin(); } else { m_segmentitr = m_segmentmap.upper_bound( segpos); } if (m_segmentitr == m_segmentmap.end()) return false; segpos = m_segmentitr->first; segment = m_strings.c_str() + m_segmentitr->second.segidx; segmentsize = m_segmentitr->second.segsize; return true; } CATCH_ERROR_ARG1_MAP_RETURN( _TXT("error in get next for markup context of '%s' segmenter: %s"), "textwolf", *m_errorhnd, false); }
ProgramOptions( int argc_, const char** argv_, int nofopt, ...) :m_argc(argc_-1),m_argv(argv_+1) { //[1] Initialize options map: OptMapDef optmapdef; va_list ap; va_start( ap, nofopt); for (int ai=0; ai<nofopt; ai++) { const char* av = va_arg( ap, const char*); optmapdef.add( av); } va_end(ap); //[2] Parse options and fill m_opt: std::vector<std::string> optlist; std::string optarg; for (; m_argc && optmapdef.getOpt( *m_argv, optlist, optarg); ++m_argv,--m_argc) { std::vector<std::string>::const_iterator oi = optlist.begin(), oe = optlist.end(); for (; oi != oe; ++oi) { std::map<std::string,bool>::iterator li = optmapdef.longnamemap.find( *oi); if (li == optmapdef.longnamemap.end()) throw strus::runtime_error( _TXT("unknown option '--%s'"), oi->c_str()); if (li->second && oi+1 == oe) { if (optarg.empty() && m_argc > 1 && m_argv[1][0] != '-') { if (m_argv[1][0] == '=') { if (!m_argv[1][1] && m_argc > 2) { --m_argc; ++m_argv; m_opt.insert( OptMapElem( *oi, std::string( m_argv[1]))); } else { m_opt.insert( OptMapElem( *oi, std::string( m_argv[1]+1))); } } else { m_opt.insert( OptMapElem( *oi, std::string( m_argv[1]))); } --m_argc; ++m_argv; } else { m_opt.insert( OptMapElem( *oi, optarg)); } } else { m_opt.insert( OptMapElem( *oi, std::string())); } } } }
//-------------------------------------------------------------------------------- //default construct CWindowStyleModel::CWindowStyleModel( CModel* pContainer ) : nsMammut::CModel( pContainer ) , m_InstanceStyleProperties( this ) , m_Popup ( &m_InstanceStyleProperties, _TXT("Popup").str() , false ) , m_Child ( &m_InstanceStyleProperties, _TXT("Child").str() , false ) , m_Minimize ( &m_InstanceStyleProperties, _TXT("Minimize").str() , false ) , m_Visisble ( &m_InstanceStyleProperties, _TXT("Visible").str() , false ) , m_Disabled ( &m_InstanceStyleProperties, _TXT("Disabled").str() , false ) , m_ClipSiblings ( &m_InstanceStyleProperties, _TXT("ClipSiblings").str() , false ) , m_ClipChildren ( &m_InstanceStyleProperties, _TXT("ClipChildren").str() , false ) , m_Maximize ( &m_InstanceStyleProperties, _TXT("Maximize").str() , false ) , m_Caption ( &m_InstanceStyleProperties, _TXT("Caption").str() , false ) , m_Border ( &m_InstanceStyleProperties, _TXT("Border").str() , false ) , m_DlgFrame ( &m_InstanceStyleProperties, _TXT("DlgFrame").str() , false ) , m_VScroll ( &m_InstanceStyleProperties, _TXT("VScroll").str() , false ) , m_HScroll ( &m_InstanceStyleProperties, _TXT("HSCroll").str() , false ) , m_SysMenu ( &m_InstanceStyleProperties, _TXT("SysMenu").str() , false ) , m_ThickFrame ( &m_InstanceStyleProperties, _TXT("ThickFrame").str() , false ) , m_Group ( &m_InstanceStyleProperties, _TXT("Group").str() , false ) , m_TabStop ( &m_InstanceStyleProperties, _TXT("TabStop").str() , false ) , m_MinimizeBox ( &m_InstanceStyleProperties, _TXT("MinimizeBox").str() , false ) , m_MaximizeBox ( &m_InstanceStyleProperties, _TXT("MaximizeBox").str() , false ) , m_OverlappedWindow ( &m_InstanceStyleProperties, _TXT("Overlapped").str() , false ) , m_Left ( &m_InstanceStyleProperties, _TXT("Left").str() , false ) , m_DlgModalFrame ( &m_InstanceStyleProperties, _TXT("DlgModalFrame").str() , false ) , m_NoParentNotify ( &m_InstanceStyleProperties, _TXT("NoParentNotify").str() , false ) , m_Topmost ( &m_InstanceStyleProperties, _TXT("Topmost").str() , false ) , m_AcceptFiles ( &m_InstanceStyleProperties, _TXT("AcceptFiles").str() , false ) , m_Transparent ( &m_InstanceStyleProperties, _TXT("Transparent").str() , false ) , m_MDIChild ( &m_InstanceStyleProperties, _TXT("MDIChild").str() , false ) , m_ToolWindow ( &m_InstanceStyleProperties, _TXT("ToolWindow").str() , false ) , m_WindowEdge ( &m_InstanceStyleProperties, _TXT("WindowEdge").str() , false ) , m_ClientEdge ( &m_InstanceStyleProperties, _TXT("ClientEdge").str() , false ) , m_ContextHelp ( &m_InstanceStyleProperties, _TXT("ContextHelp").str() , false ) , m_Right ( &m_InstanceStyleProperties, _TXT("Right").str() , false ) , m_RTLReading ( &m_InstanceStyleProperties, _TXT("RTLReading").str() , false ) , m_LeftSrollBar ( &m_InstanceStyleProperties, _TXT("LeftScrollBar").str() , false ) , m_RightScrollBar ( &m_InstanceStyleProperties, _TXT("RightScrollBar").str() , false ) , m_ControlParent ( &m_InstanceStyleProperties, _TXT("ControlParent").str() , false ) , m_StaticEdge ( &m_InstanceStyleProperties, _TXT("StaticEdge").str() , false ) , m_AppWindow ( &m_InstanceStyleProperties, _TXT("AppWindow").str() , false ) , m_Layered ( &m_InstanceStyleProperties, _TXT("Layered").str() , false ) , m_NoInheritLayout ( &m_InstanceStyleProperties, _TXT("NoInheritLayout").str() , false ) , m_LayoutRTL ( &m_InstanceStyleProperties, _TXT("LayoutRTL").str() , false ) , m_Composited ( &m_InstanceStyleProperties, _TXT("Composited").str() , false ) , m_NoActivate ( &m_InstanceStyleProperties, _TXT("NoActivate").str() , false ) { }
//-------------------------------------------------------------------------------- //assign from a generic property set CWindowStyleModel& CWindowStyleModel::operator = ( const nsMammut::CPropertySet& src ) { if( (void*)&src != (void*)this ) { m_Popup = src[ _TXT("Popup").str() ]; m_Child = src[ _TXT("Child").str() ]; m_Minimize = src[ _TXT("Minimize").str() ]; m_Visisble = src[ _TXT("Visible").str() ]; m_Disabled = src[ _TXT("Disabled").str() ]; m_ClipSiblings = src[ _TXT("ClipSiblings").str() ]; m_ClipChildren = src[ _TXT("ClipChildren").str() ]; m_Maximize = src[ _TXT("Maximize").str() ]; m_Caption = src[ _TXT("Caption").str() ]; m_Border = src[ _TXT("Border").str() ]; m_DlgFrame = src[ _TXT("DlgFrame").str() ]; m_VScroll = src[ _TXT("VScroll").str() ]; m_HScroll = src[ _TXT("HSCroll").str() ]; m_SysMenu = src[ _TXT("SysMenu").str() ]; m_ThickFrame = src[ _TXT("ThickFrame").str() ]; m_Group = src[ _TXT("Group").str() ]; m_TabStop = src[ _TXT("TabStop").str() ]; m_MinimizeBox = src[ _TXT("MinimizeBox").str() ]; m_MaximizeBox = src[ _TXT("MaximizeBox").str() ]; m_OverlappedWindow = src[ _TXT("Overlapped").str() ]; m_Left = src[ _TXT("Left").str() ]; m_DlgModalFrame = src[ _TXT("DlgModalFrame").str() ]; m_NoParentNotify = src[ _TXT("NoParentNotify").str() ]; m_Topmost = src[ _TXT("Topmost").str() ]; m_AcceptFiles = src[ _TXT("AcceptFiles").str() ]; m_Transparent = src[ _TXT("Transparent").str() ]; m_MDIChild = src[ _TXT("MDIChild").str() ]; m_ToolWindow = src[ _TXT("ToolWindow").str() ]; m_WindowEdge = src[ _TXT("WindowEdge").str() ]; m_ClientEdge = src[ _TXT("ClientEdge").str() ]; m_ContextHelp = src[ _TXT("ContextHelp").str() ]; m_Right = src[ _TXT("Right").str() ]; m_RTLReading = src[ _TXT("RTLReading").str() ]; m_LeftSrollBar = src[ _TXT("LeftScrollBar").str() ]; m_RightScrollBar = src[ _TXT("RightScrollBar").str() ]; m_ControlParent = src[ _TXT("ControlParent").str() ]; m_StaticEdge = src[ _TXT("StaticEdge").str() ]; m_AppWindow = src[ _TXT("AppWindow").str() ]; m_Layered = src[ _TXT("Layered").str() ]; m_NoInheritLayout = src[ _TXT("NoInheritLayout").str()]; m_LayoutRTL = src[ _TXT("LayoutRTL").str() ]; m_Composited = src[ _TXT("Composited").str() ]; m_NoActivate = src[ _TXT("NoActivate").str() ]; } return *this; }
virtual const char* getDescription() const { return _TXT("Normalizer doing stemming based on snowball. The language is passed as parameter"); }
void analyze() { m_expr = m_analyzer->analyze(); if (m_errorhnd->hasError()) throw strus::runtime_error(_TXT("failed to analyze term expression: %s"), m_errorhnd->fetchError()); }
int main( int argc, const char* argv[]) { int rt = 0; std::auto_ptr<strus::ErrorBufferInterface> errorBuffer( strus::createErrorBuffer_standard( 0, 2)); if (!errorBuffer.get()) { std::cerr << _TXT("failed to create error buffer") << std::endl; return -1; } strus::ProgramOptions opt; bool printUsageAndExit = false; try { opt = strus::ProgramOptions( argc, argv, 11, "h,help", "v,version", "license", "t,tokenizer:", "n,normalizer:", "m,module:", "M,moduledir:", "q,quot:", "p,plain", "R,resourcedir:", "T,trace:"); if (opt( "help")) printUsageAndExit = true; std::auto_ptr<strus::ModuleLoaderInterface> moduleLoader( strus::createModuleLoader( errorBuffer.get())); if (!moduleLoader.get()) throw strus::runtime_error(_TXT("failed to create module loader")); if (opt("moduledir")) { std::vector<std::string> modirlist( opt.list("moduledir")); std::vector<std::string>::const_iterator mi = modirlist.begin(), me = modirlist.end(); for (; mi != me; ++mi) { moduleLoader->addModulePath( *mi); } moduleLoader->addSystemModulePath(); } if (opt("module")) { std::vector<std::string> modlist( opt.list("module")); std::vector<std::string>::const_iterator mi = modlist.begin(), me = modlist.end(); for (; mi != me; ++mi) { if (!moduleLoader->loadModule( *mi)) { throw strus::runtime_error(_TXT("error failed to load module %s"), mi->c_str()); } } } if (opt("license")) { std::vector<std::string> licenses_3rdParty = moduleLoader->get3rdPartyLicenseTexts(); std::vector<std::string>::const_iterator ti = licenses_3rdParty.begin(), te = licenses_3rdParty.end(); if (ti != te) std::cout << _TXT("3rd party licenses:") << std::endl; for (; ti != te; ++ti) { std::cout << *ti << std::endl; } std::cerr << std::endl; if (!printUsageAndExit) return 0; } if (opt( "version")) { std::cout << _TXT("Strus utilities version ") << STRUS_UTILITIES_VERSION_STRING << std::endl; std::cout << _TXT("Strus module version ") << STRUS_MODULE_VERSION_STRING << std::endl; std::cout << _TXT("Strus rpc version ") << STRUS_RPC_VERSION_STRING << std::endl; std::cout << _TXT("Strus trace version ") << STRUS_TRACE_VERSION_STRING << std::endl; std::cout << _TXT("Strus analyzer version ") << STRUS_ANALYZER_VERSION_STRING << std::endl; std::cout << _TXT("Strus base version ") << STRUS_BASE_VERSION_STRING << std::endl; std::vector<std::string> versions_3rdParty = moduleLoader->get3rdPartyVersionTexts(); std::vector<std::string>::const_iterator vi = versions_3rdParty.begin(), ve = versions_3rdParty.end(); if (vi != ve) std::cout << _TXT("3rd party versions:") << std::endl; for (; vi != ve; ++vi) { std::cout << *vi << std::endl; } if (!printUsageAndExit) return 0; } else if (!printUsageAndExit) { if (opt.nofargs() > 1) { std::cerr << _TXT("too many arguments") << std::endl; printUsageAndExit = true; rt = 1; } if (opt.nofargs() < 1) { std::cerr << _TXT("too few arguments") << std::endl; printUsageAndExit = true; rt = 2; } } if (printUsageAndExit) { std::cout << _TXT("usage:") << " strusAnalyze [options] <phrasepath>" << std::endl; std::cout << "<phrasepath> = " << _TXT("path to phrase to analyze ('-' for stdin)") << std::endl; std::cout << "description: " << _TXT("tokenizes and normalizes a text segment") << std::endl; std::cout << " " << _TXT("and prints the result to stdout.") << std::endl; std::cout << _TXT("options:") << std::endl; std::cout << "-h|--help" << std::endl; std::cout << " " << _TXT("Print this usage and do nothing else") << std::endl; std::cout << "-v|--version" << std::endl; std::cout << " " << _TXT("Print the program version and do nothing else") << std::endl; std::cout << "--license" << std::endl; std::cout << " " << _TXT("Print 3rd party licences requiring reference") << std::endl; std::cout << "-m|--module <MOD>" << std::endl; std::cout << " " << _TXT("Load components from module <MOD>") << std::endl; std::cout << "-M|--moduledir <DIR>" << std::endl; std::cout << " " << _TXT("Search modules to load first in <DIR>") << std::endl; std::cout << "-R|--resourcedir <DIR>" << std::endl; std::cout << " " << _TXT("Search resource files for analyzer first in <DIR>") << std::endl; std::cout << "-t|--tokenizer <CALL>" << std::endl; std::cout << " " << _TXT("Use the tokenizer <CALL> (default 'content')") << std::endl; std::cout << "-n|--normalizer <CALL>" << std::endl; std::cout << " " << _TXT("Use the normalizer <CALL> (default 'orig')") << std::endl; std::cout << "-q|--quot <STR>" << std::endl; std::cout << " " << _TXT("Use the string <STR> as quote for the result (default \"\'\")") << std::endl; std::cout << "-p|--plain" << std::endl; std::cout << " " << _TXT("Do not print position and define default quotes as empty") << std::endl; std::cout << "-T|--trace <CONFIG>" << std::endl; std::cout << " " << _TXT("Print method call traces configured with <CONFIG>") << std::endl; std::cout << " " << strus::string_format( _TXT("Example: %s"), "-T \"log=dump;file=stdout\"") << std::endl; return rt; } // Declare trace proxy objects: typedef strus::Reference<strus::TraceProxy> TraceReference; std::vector<TraceReference> trace; if (opt("trace")) { std::vector<std::string> tracecfglist( opt.list("trace")); std::vector<std::string>::const_iterator ti = tracecfglist.begin(), te = tracecfglist.end(); for (; ti != te; ++ti) { trace.push_back( new strus::TraceProxy( moduleLoader.get(), *ti, errorBuffer.get())); } } std::string resultQuot = "'"; bool resultPlain = false; if (opt( "plain")) { resultPlain = true; resultQuot.clear(); } if (opt( "quot")) { resultQuot = opt[ "quot"]; } std::string docpath = opt[0]; std::string tokenizer( "content"); if (opt( "tokenizer")) { tokenizer = opt[ "tokenizer"]; } std::string normalizer( "orig"); if (opt( "normalizer")) { normalizer = opt[ "normalizer"]; } // Set paths for locating resources: if (opt("resourcedir")) { std::vector<std::string> pathlist( opt.list("resourcedir")); std::vector<std::string>::const_iterator pi = pathlist.begin(), pe = pathlist.end(); for (; pi != pe; ++pi) { moduleLoader->addResourcePath( *pi); } } // Create root object for analyzer: std::auto_ptr<strus::AnalyzerObjectBuilderInterface> analyzerBuilder( moduleLoader->createAnalyzerObjectBuilder()); if (!analyzerBuilder.get()) throw strus::runtime_error(_TXT("failed to create analyzer object builder")); // Create proxy objects if tracing enabled: { std::vector<TraceReference>::const_iterator ti = trace.begin(), te = trace.end(); for (; ti != te; ++ti) { strus::AnalyzerObjectBuilderInterface* proxy = (*ti)->createProxy( analyzerBuilder.get()); analyzerBuilder.release(); analyzerBuilder.reset( proxy); } } // Create objects for analyzer: std::auto_ptr<strus::QueryAnalyzerInterface> analyzer( analyzerBuilder->createQueryAnalyzer()); if (!analyzer.get()) throw strus::runtime_error(_TXT("failed to create analyzer")); const strus::TextProcessorInterface* textproc = analyzerBuilder->getTextProcessor(); if (!textproc) throw strus::runtime_error(_TXT("failed to get text processor")); // Create phrase type (tokenizer and normalizer): std::string phraseType; if (!strus::loadQueryAnalyzerPhraseType( *analyzer, textproc, phraseType, "", normalizer, tokenizer, errorBuffer.get())) { throw strus::runtime_error(_TXT("failed to load analyze phrase type")); } // Load the phrase: std::string phrase; if (docpath == "-") { unsigned int ec = strus::readStdin( phrase); if (ec) throw strus::runtime_error( _TXT( "error reading input from stdin (errno %u)"), ec); } else { unsigned int ec = strus::readFile( docpath, phrase); if (ec) throw strus::runtime_error( _TXT( "error reading input file '%s' (errno %u)"), docpath.c_str(), ec); } // Analyze the phrase and print the result: std::vector<strus::analyzer::Term> terms = analyzer->analyzePhrase( phraseType, phrase); std::sort( terms.begin(), terms.end(), TermOrder()); std::vector<strus::analyzer::Term>::const_iterator ti = terms.begin(), te = terms.end(); for (; ti != te; ++ti) { if (!resultPlain) { std::cout << ti->pos() << " "; } std::cout << resultQuot << ti->value() << resultQuot << std::endl; } if (errorBuffer->hasError()) { throw strus::runtime_error(_TXT("error in analyze phrase")); } return 0; } catch (const std::bad_alloc&) { std::cerr << _TXT("ERROR ") << _TXT("out of memory") << std::endl; } catch (const std::runtime_error& e) { const char* errormsg = errorBuffer->fetchError(); if (errormsg) { std::cerr << _TXT("ERROR ") << e.what() << ": " << errormsg << std::endl; } else { std::cerr << _TXT("ERROR ") << e.what() << std::endl; } } catch (const std::exception& e) { std::cerr << _TXT("EXCEPTION ") << e.what() << std::endl; } return -1; }
virtual std::string getContent() const { try { std::vector<MarkupElement> markups = m_markups; std::sort( markups.begin(), markups.end()); std::string rt; typedef textwolf::XMLPrinter<CharsetEncoding,textwolf::charset::UTF8,std::string> MyXMLPrinter; MyXMLPrinter printer( true); typename std::vector<MarkupElement>::const_iterator mi = markups.begin(), me = markups.end(); std::size_t prevpos = 0; typename MarkupElement::Type prevtype = MarkupElement::CloseTag; for (; mi != me; ++mi) { if (mi->origpos > prevpos) { if (prevtype != MarkupElement::CloseTag) { printer.printValue( "", 0, rt); } rt.append( m_source.c_str() + prevpos, mi->origpos - prevpos); } switch (mi->type) { case MarkupElement::OpenTag: printer.printOpenTag( mi->value.c_str(), mi->value.size(), rt); break; case MarkupElement::AttributeName: printer.printToBuffer( ' ', rt); printer.printToBuffer( mi->value.c_str(), mi->value.size(), rt); printer.printToBuffer( '=', rt); ++mi; if (mi == me) { --mi; printer.printToBufferAttributeValue( "", 0, rt); } else { printer.printToBufferAttributeValue( mi->value.c_str(), mi->value.size(), rt); } break; case MarkupElement::AttributeValue: throw std::runtime_error( _TXT("logic error: unexpected attribute value")); case MarkupElement::CloseTag: { bool foundOpenTag = false; typename std::vector<MarkupElement>::const_iterator ma = mi; for (;ma != markups.begin() && (ma-1)->origpos == mi->origpos; --ma) { if ((ma-1)->type == MarkupElement::OpenTag && (ma-1)->value == mi->value) { printer.printCloseTag( rt); foundOpenTag = true; break; } } if (!foundOpenTag) { printer.printToBuffer( "</", 2, rt); printer.printToBuffer( mi->value.c_str(), mi->value.size(), rt); printer.printToBuffer( '>', rt); } break; } } prevtype = mi->type; prevpos = mi->origpos; if (printer.lasterror()) { throw strus::runtime_error(_TXT("error printing XML: %s"), printer.lasterror()); } } if (prevtype != MarkupElement::CloseTag) { printer.printValue( "", 0, rt); } rt.append( m_source.c_str() + prevpos, m_source.size() - prevpos); return rt; } CATCH_ERROR_ARG1_MAP_RETURN( _TXT("error in get next for markup context of '%s' segmenter: %s"), "textwolf", *m_errorhnd, std::string()); }
virtual const char* getDescription() const { return _TXT("Normalizer mapping the elements with a dictionary. For found elements the passed value is returned. The dictionary file name is passed as argument"); }
static int request_handler( struct strus_handlerdata_t* handlerdata, const unsigned char* readbuf, size_t readbufsize, size_t outputhdrsize, const unsigned char** output, size_t* outputsize) { handler_context_t* ctx = reinterpret_cast<handler_context_t*>( handlerdata); try { if (!ctx->obj) { ctx->obj = new strus::RpcRequestHandler( g_storageObjectBuilder, g_analyzerObjectBuilder, g_storageClient, g_errorBuffer); } ctx->resultbuf.clear(); ctx->resultbuf.append( "\0\0\0\0", sizeof( uint32_t)); if (readbufsize > 0 && readbuf[0] == 0xFF) { #ifdef STRUS_LOWLEVEL_DEBUG fprintf( g_glbctx.logf, _TXT("got multipart request [%u bytes]\n"), readbufsize); #endif unsigned char const* itr = readbuf+1; unsigned const char* end = itr + readbufsize -1; while (itr < end) { uint32_t msglen = unpackMessageLen( itr, end); #ifdef STRUS_LOWLEVEL_DEBUG fprintf( g_glbctx.logf, _TXT("call request handler [%u bytes]\n"), msglen); #endif ctx->resultbuf.append( ctx->obj->handleRequest( (const char*)itr, (std::size_t)msglen)); if (ctx->resultbuf.size() > sizeof(uint32_t)) { if (ctx->resultbuf[sizeof(uint32_t)] == (char)strus::MsgTypeAnswer && itr+msglen != end) { fprintf( g_glbctx.logf, _TXT("got unexpected answer (protocol error) ... closing connection\n")); return 6; } break; } itr += msglen; } } else { #ifdef STRUS_LOWLEVEL_DEBUG fprintf( g_glbctx.logf, _TXT("got singlepart request [%u bytes]\n"), readbufsize); fprintf( g_glbctx.logf, _TXT("call request handler [%u bytes]\n"), readbufsize); #endif ctx->resultbuf.append( ctx->obj->handleRequest( (const char*)readbuf, (std::size_t)readbufsize)); } *output = (const unsigned char*)ctx->resultbuf.c_str(); *outputsize = ctx->resultbuf.size(); } catch (const std::runtime_error& err) { fprintf( g_glbctx.logf, _TXT("runtime error in request handler: %s\n"), err.what()); return 1; } catch (const std::bad_alloc& err) { fprintf( g_glbctx.logf, _TXT("memory allocation error in request handler\n")); return 2; } catch (const std::exception& err) { fprintf( g_glbctx.logf, _TXT("exception in request handler: %s\n"), err.what()); return 3; } catch (...) { fprintf( g_glbctx.logf, _TXT("unknown exception in request handler\n")); return 4; } return 0; }
static void printUsage() { std::cout << "strusRpcServer [options]" << std::endl; std::cout << "options:" << std::endl; std::cout << "-h|--help" << std::endl; std::cout << " " << _TXT("Print this usage and do nothing else") << std::endl; std::cout << "-v|--version" << std::endl; std::cout << " " << _TXT("Print the program version and do nothing else") << std::endl; std::cout << "-m|--module <MOD>" << std::endl; std::cout << " " << _TXT("Load components from module <MOD>") << std::endl; std::cout << "-M|--moduledir <DIR>" << std::endl; std::cout << " " << _TXT("Search modules to load first in <DIR>") << std::endl; std::cout << "-R|--resourcedir <DIR>" << std::endl; std::cout << " " << _TXT("Define a resource path <DIR> for the analyzer") << std::endl; std::cout << "-p|--port <PORT>" << std::endl; std::cout << " " << _TXT("Define the port to listen for requests as <PORT> (default 7181)") << std::endl; std::cout << "-s|--storage <CONFIG>" << std::endl; std::cout << " " << _TXT("Define configuration <CONFIG> of storage hosted by this server") << std::endl; std::cout << "-S|--configfile <CFGFILE>" << std::endl; std::cout << " " << _TXT("Define storage configuration as content of file <CFGFILE>") << std::endl; std::cout << "-c|--create <CONFIG>" << std::endl; std::cout << " " << _TXT("Implicitely create storage with <CONFIG> if it does not exist yet") << std::endl; std::cout << "-l|--logfile <FILE>" << std::endl; std::cout << " " << _TXT("Write logs to file <FILE>") << std::endl; std::cout << "-T|--trace <CONFIG>" << std::endl; std::cout << " " << _TXT("Print method call traces configured with <CONFIG>") << std::endl; }
int main( int argc, const char* argv[]) { std::auto_ptr<strus::ErrorBufferInterface> errorBuffer( strus::createErrorBuffer_standard( 0, 2)); if (!errorBuffer.get()) { std::cerr << _TXT("failed to create error buffer") << std::endl; return -1; } g_errorBuffer = errorBuffer.get(); bool doExit = false; int argi = 1; std::string logfile; std::vector<std::string> moduledirs; std::vector<std::string> modules; std::vector<std::string> resourcedirs; std::vector<std::string> tracecfglist; std::string storageconfig; bool doCreateIfNotExist = false; unsigned int nofThreads = 0; unsigned int port = 7181; //... default port try { // Parsing arguments: for (; argi < argc; ++argi) { if (0==std::strcmp( argv[argi], "-h") || 0==std::strcmp( argv[argi], "--help")) { printUsage(); doExit = true; } else if (0==std::strcmp( argv[argi], "-v") || 0==std::strcmp( argv[argi], "--version")) { std::cerr << "strusRpc version " << STRUS_RPC_VERSION_STRING << std::endl; doExit = true; } else if (0==std::strcmp( argv[argi], "-m") || 0==std::strcmp( argv[argi], "--module")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--module"); modules.push_back( argv[argi]); } else if (0==std::strcmp( argv[argi], "-M") || 0==std::strcmp( argv[argi], "--moduledir")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--moduledir"); moduledirs.push_back( argv[argi]); } else if (0==std::strcmp( argv[argi], "-R") || 0==std::strcmp( argv[argi], "--resourcedir")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--resourcedir"); resourcedirs.push_back( argv[argi]); } else if (0==std::strcmp( argv[argi], "-p") || 0==std::strcmp( argv[argi], "--port")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--port"); try { port = strus::utils::touint( argv[argi]); if (port == 0 || port > 65535) { throw strus::runtime_error( _TXT("value out of range")); } } catch (const std::runtime_error& err) { throw strus::runtime_error( _TXT("illegal argument for option %s: %s"), "--port", err.what()); } } else if (0==std::strcmp( argv[argi], "-s") || 0==std::strcmp( argv[argi], "--storage")) { if (!storageconfig.empty()) throw strus::runtime_error( _TXT("option %s or %s specified twice"), "--storage","--configfile"); ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--storage"); storageconfig.append( argv[argi]); if (storageconfig.empty()) throw strus::runtime_error(_TXT("option %s with empty argument"), "--storage"); } else if (0==std::strcmp( argv[argi], "-S") || 0==std::strcmp( argv[argi], "--configfile")) { if (!storageconfig.empty()) throw strus::runtime_error( _TXT("option %s or %s specified twice"), "--storage","--configfile"); ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--configfile"); int ec = strus::readFile( argv[argi], storageconfig); if (ec) { throw strus::runtime_error(_TXT("failed to read configuration file %s (file system error %u)"), argv[argi], ec); } std::string::iterator di = storageconfig.begin(), de = storageconfig.end(); for (; di != de; ++di) { if ((unsigned char)*di < 32) *di = ' '; } if (storageconfig.empty()) throw strus::runtime_error(_TXT("option %s with empty file"), "--configfile"); } else if (0==std::strcmp( argv[argi], "-c") || 0==std::strcmp( argv[argi], "--create")) { doCreateIfNotExist = true; } else if (0==std::strcmp( argv[argi], "-T") || 0==std::strcmp( argv[argi], "--trace")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument (trace configuration)"), "--trace"); tracecfglist.push_back( argv[argi]); } else if (0==std::strcmp( argv[argi], "-t") || 0==std::strcmp( argv[argi], "--threads")) { ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects number as argument"), "--threads"); try { nofThreads = strus::utils::touint( argv[argi]); } catch (const std::runtime_error& err) { throw strus::runtime_error(_TXT("illegal argument for option %s: %s"),"--threads", err.what()); } } else if (0==std::strcmp( argv[argi], "-l") || 0==std::strcmp( argv[argi], "--logfile")) { if (logfile.size()) throw strus::runtime_error(_TXT("duplicate definition of option %s"), "--logfile"); ++argi; if (argi == argc) throw strus::runtime_error(_TXT("option %s expects argument"), "--logfile"); logfile = argv[argi]; if (logfile.empty()) throw strus::runtime_error(_TXT("empty definition of option %s"), "--logfile"); } else if (argv[argi][0] == '-') { throw strus::runtime_error(_TXT("unknown option %s"), argv[argi]); } else { throw strus::runtime_error( _TXT("no arguments expected (only options)")); } } if (doExit) return 0; init_global_context( logfile.empty()?0:logfile.c_str()); g_errorBuffer->setLogFile( g_glbctx.logf); g_errorBuffer->setMaxNofThreads( strus_threadpool_size()+2); // Create the global context: std::auto_ptr<strus::ModuleLoaderInterface> moduleLoader( strus::createModuleLoader( g_errorBuffer)); g_moduleLoader = moduleLoader.get(); if (!g_moduleLoader) throw strus::runtime_error( _TXT("failed to create module loader")); std::vector<std::string>::const_iterator di = moduledirs.begin(), de = moduledirs.end(); for (; di != de; ++di) { g_moduleLoader->addModulePath( *di); } moduleLoader->addSystemModulePath(); std::vector<std::string>::const_iterator mi = modules.begin(), me = modules.end(); for (; mi != me; ++mi) { g_moduleLoader->loadModule( *mi); } std::vector<std::string>::const_iterator pi = resourcedirs.begin(), pe = resourcedirs.end(); for (; pi != pe; ++pi) { g_moduleLoader->addResourcePath( *pi); } if (g_errorBuffer->hasError()) { throw strus::runtime_error(_TXT("error in initialization: %s"), g_errorBuffer->fetchError()); } // Declare trace proxy objects: typedef strus::Reference<strus::TraceProxy> TraceReference; std::vector<TraceReference> trace; if (!tracecfglist.empty()) { std::vector<std::string>::const_iterator ti = tracecfglist.begin(), te = tracecfglist.end(); for (; ti != te; ++ti) { trace.push_back( new strus::TraceProxy( g_moduleLoader, *ti, g_errorBuffer)); } } // Create objects: std::auto_ptr<strus::StorageObjectBuilderInterface> storageBuilder( g_moduleLoader->createStorageObjectBuilder()); if (!storageBuilder.get()) { throw strus::runtime_error( _TXT("failed to create storage builder")); } std::auto_ptr<strus::AnalyzerObjectBuilderInterface> analyzerBuilder( g_moduleLoader->createAnalyzerObjectBuilder()); if (!analyzerBuilder.get()) { throw strus::runtime_error( _TXT("failed to create analyzer builder")); } // Create proxy objects if tracing enabled: std::vector<TraceReference>::const_iterator ti = trace.begin(), te = trace.end(); for (; ti != te; ++ti) { strus::AnalyzerObjectBuilderInterface* aproxy = (*ti)->createProxy( analyzerBuilder.get()); analyzerBuilder.release(); analyzerBuilder.reset( aproxy); strus::StorageObjectBuilderInterface* sproxy = (*ti)->createProxy( storageBuilder.get()); storageBuilder.release(); storageBuilder.reset( sproxy); } std::auto_ptr<strus::StorageClientInterface> storageClient; g_storageObjectBuilder = storageBuilder.get(); g_analyzerObjectBuilder = analyzerBuilder.get(); if (!storageconfig.empty()) { if (doCreateIfNotExist) { createStorageIfNotExist( storageconfig); } storageClient.reset( strus::createStorageClient( g_storageObjectBuilder, g_errorBuffer, storageconfig)); if (!storageClient.get()) { throw strus::runtime_error( _TXT("failed to create storage client"), storageconfig.c_str()); } std::cerr << _TXT("strus RPC server is hosting storage ") << "'" << storageconfig << "'" << std::endl; g_storageClient = storageClient.get(); } // Start server: std::cerr << "strus RPC server listening on port " << port << std::endl; int err = strus_run_server( (unsigned short)(unsigned int)port, nofThreads, &g_glbctx); if (err) { throw strus::runtime_error( _TXT("server terminated with error (see logs)")); } std::cerr << _TXT("strus RPC server terminated") << std::endl; // Cleanup when done: done_global_context(); return 0; } catch (const std::exception& e) { const char* errormsg = g_errorBuffer?g_errorBuffer->fetchError():0; if (errormsg) { std::cerr << e.what() << ": " << errormsg << std::endl; } else { std::cerr << e.what() << std::endl; } } std::cerr << _TXT("strus RPC server terminated") << std::endl; done_global_context(); return -1; }
//-------------------------------------------------------------------------------- //assign from a generic property set CIconModel& CIconModel::operator = ( const nsMammut::CPropertySet& src ) { if( &src != this ) { m_Type = src[ _TXT( "Type" ).str() ]; m_presbits = src[ _TXT( "ResourceBits" ).str() ]; m_dwResSize = src[ _TXT( "ByteCount" ).str() ]; m_bIcon = src[ _TXT( "IsIcon" ).str() ]; m_dwVersion = src[ _TXT( "Version" ).str() ]; m_iHeight = src[ _TXT( "Height" ).str() ]; m_iWidth = src[ _TXT( "Width" ).str() ]; m_cBitsPerPixel = src[ _TXT( "BitsPerPixel" ).str() ]; m_pANDBits = src[ _TXT( "ANDBits" ).str() ]; m_pORBits = src[ _TXT( "ORBits" ).str() ]; m_cPlanes = src[ _TXT( "Planes" ).str() ]; m_uiFlags = src[ _TXT( "Flags" ).str() ]; m_szName = src[ _TXT( "Name" ).str() ]; m_pModule = src[ _TXT( "Module" ).str() ]; } return *this; }
//-------------------------------------------------------------------------------- //default construct CIconModel::CIconModel( CModel* pContainer ) : nsMammut::CPropertySet( pContainer ) , m_Type ( this, _TXT( "Type" ).str() , eByNameIcon ) , m_presbits ( this, _TXT( "ResourceBits" ).str() , 0 ) , m_dwResSize ( this, _TXT( "ByteCount" ).str() , 0 ) , m_bIcon ( this, _TXT( "IsIcon" ).str() , true ) , m_dwVersion ( this, _TXT( "Version" ).str() , 0 ) , m_iHeight ( this, _TXT( "Height" ).str() , 32 ) , m_iWidth ( this, _TXT( "Width" ).str() , 32 ) , m_cBitsPerPixel ( this, _TXT( "BitsPerPixel" ).str() , 1 ) , m_pANDBits ( this, _TXT( "ANDBits" ).str() , 0 ) , m_pORBits ( this, _TXT( "ORBits" ).str() , 0 ) , m_cPlanes ( this, _TXT( "Planes" ).str() , 1 ) , m_uiFlags ( this, _TXT( "Flags" ).str() , 0 ) , m_szName ( this, _TXT( "Name" ).str() , 0 ) , m_pModule ( this, _TXT( "Module" ).str() , 0 ) { }
//-------------------------------------------------------------------------------- CTabClass::CTabClass() : CCommonCtrlClass( CCommonCtrl::CCTAB_CLASSES, _TXT( "SysTabControl32" ) ) { _WINQ_FCONTEXT( "CTabClass::CTabClass" ); }
unsigned int asUint( const std::string& optname) const { int rt = asInt( optname); if (rt < 0) throw strus::runtime_error( _TXT("non negative value expected for option '%s'"), optname.c_str()); return (unsigned int)rt; }
//-------------------------------------------------------------------------------- //Construct from a generic PropertySet CIconModel::CIconModel( nsMammut::CPropertySet& src ) : CPropertySet( src ) , m_Type ( this, _TXT( "Type" ).str() , src[ _TXT( "Type" ).str() ] ) , m_presbits ( this, _TXT( "ResourceBits" ).str() , src[ _TXT( "ResourceBits" ).str() ] ) , m_dwResSize ( this, _TXT( "ByteCount" ).str() , src[ _TXT( "ByteCount" ).str() ] ) , m_bIcon ( this, _TXT( "IsIcon" ).str() , src[ _TXT( "IsIcon" ).str() ] ) , m_dwVersion ( this, _TXT( "Version" ).str() , src[ _TXT( "Version" ).str() ] ) , m_iHeight ( this, _TXT( "Height" ).str() , src[ _TXT( "Height" ).str() ] ) , m_iWidth ( this, _TXT( "Width" ).str() , src[ _TXT( "Width" ).str() ] ) , m_cBitsPerPixel ( this, _TXT( "BitsPerPixel" ).str() , src[ _TXT( "BitsPerPixel" ).str() ] ) , m_pANDBits ( this, _TXT( "ANDBits" ).str() , src[ _TXT( "ANDBits" ).str() ] ) , m_pORBits ( this, _TXT( "ORBits" ).str() , src[ _TXT( "ORBits" ).str() ] ) , m_cPlanes ( this, _TXT( "Planes" ).str() , src[ _TXT( "Planes" ).str() ] ) , m_uiFlags ( this, _TXT( "Flags" ).str() , src[ _TXT( "Flags" ).str() ] ) , m_szName ( this, _TXT( "Name" ).str() , src[ _TXT( "Name" ).str() ] ) , m_pModule ( this, _TXT( "Module" ).str() , src[ _TXT( "Module" ).str() ] ) { }