void SummaryDesc::build_fulldoc_desc() { LOG(debug, "Generating query highlights for complete document"); off_t pos = 0; for (key_occ_vector::const_iterator kit = _occ.begin(); kit != _occ.end(); ++kit) { int klen = (*kit)->tokenlen; int kpos = (*kit)->startpos(); add_desc(pos, kpos - pos, false); // Use valid() info to filter out non-phrase terms if this is // a phrase search: add_desc(kpos, klen, (!_matcher->UsesValid()) || (*kit)->valid()); pos = kpos + klen; } add_desc(pos, _matcher->DocumentSize() - pos, false); _est_len = _matcher->DocumentSize(); }
/** * Add hidden options for those supplied by the app modes that are not * the calling app. * * For example, add the opts for gtdownload and gtupload if the caller * was gtserver. * * It's possible for the app to be none of gtserver, gtupload or * gtdownload. * * This allows the options to appear in the config file * without generating an error about them being unknown. * * @param app The mode of the app calling this: 'S', 'D', or 'U' */ void gtBaseOpts::add_options_hidden (const char app) { boost::program_options::options_description hidden_desc; if (app != 'D') { hidden_desc.add_options () (OPT_MAX_CHILDREN, opt_string(), "hidden, ignored") ; } if (app != 'S') { hidden_desc.add_options () (OPT_SERVER, opt_string(), "hidden, ignored") (OPT_QUEUE, opt_string(), "hidden, ignored") ; } add_desc (hidden_desc, NOT_VISIBLE); }
void SummaryDesc::build_highlight_descs() { /* Set available print length per element (prefix or postfix) */ int len_per_elem; if (_est_len > (int)_length) { len_per_elem = (_length - _hit_len) / (_match_elems*2); // Adjust element length to sensible values len_per_elem = std::max(MIN_SURROUND_LEN, len_per_elem); /* Check that this does not yield a too long/too short teaser */ len_per_elem = recompute_estimate(len_per_elem); } else { len_per_elem = _surround_len; } // Max length to allow before a split is required: Note that we // allow an extra MIN_CONTINUATION extra bytes to the total those // times where matches are close int middle_len = len_per_elem * 2 + MIN_CONTINUATION; int len = len_per_elem; // Max running length to update pointer with LOG(spam, "length pr. elem %d", len_per_elem); /* build the ordered highlight description list (stored in _plist) * based on our collected info about the best matches available * and the estimated length (len_per_elem) of a triple * (pre-context, highlight keyword, post-context) (len_per_elem * assumes no overlap). Identify a line segment at a time.. */ off_t pos = 0; off_t startpos = 0; for (cand_list::iterator cit = _clist.begin(); cit != _clist.end(); ++cit) { /* look at each keyword within match */ keylist& klist = (*cit)->_klist; for (keylist::iterator kit = klist.begin(); kit != klist.end(); ++kit) { key_occ* k = *kit; int max_len = k->startpos() - pos; // the same occurrence may appear twice in a match, in // which case length will be < 0 if (max_len < 0) continue; if (pos == 0) { // Adding initial segment: if (len < max_len) { startpos = pos = max_len - len; } else { len = max_len; } add_desc(pos, len, false); } else if (max_len <= middle_len) { // Context in between fits completely len = max_len; add_desc(pos, len, false); } else { if (LOG_WOULD_LOG(spam)) { int dist = (k->startpos() - len_per_elem) - (pos + len_per_elem); LOG(spam, "Middle split case, distance: %d", dist); } len = max_len; add_desc(pos, len_per_elem, false); add_desc(k->startpos() - len_per_elem, len_per_elem, false); } // Finally add the keyword itself: add_desc(k->startpos(), k->tokenlen, true); pos += (k->tokenlen + len); } } if (pos > 0) { // Adding final segment, ensure that there is enough text available.. int max_len = std::min(len_per_elem, static_cast<int>(_matcher->DocumentSize() - pos)); add_desc(pos, max_len, false); } LOG(debug, "Summary: start %ld end: %ld", startpos, pos); }
char *opt_usage(const char *argv0, const char *extra) { unsigned int i; size_t max, len, width, indent; char *ret; width = get_columns(); if (width < MIN_TOTAL_WIDTH) width = MIN_TOTAL_WIDTH; /* Figure out longest option. */ indent = 0; for (i = 0; i < opt_count; i++) { size_t l; if (opt_table[i].desc == opt_hidden) continue; if (opt_table[i].type == OPT_SUBTABLE) continue; l = strlen(opt_table[i].names); if (opt_table[i].type == OPT_HASARG && !strchr(opt_table[i].names, ' ') && !strchr(opt_table[i].names, '=')) l += strlen(" <arg>"); if (l + 2 > indent) indent = l + 2; } /* Now we know how much to indent */ if (indent + MIN_DESC_WIDTH > width) indent = width - MIN_DESC_WIDTH; len = max = 0; ret = NULL; ret = add_str(ret, &len, &max, "Usage: "); ret = add_str(ret, &len, &max, argv0); /* Find usage message from among registered options if necessary. */ if (!extra) { extra = ""; for (i = 0; i < opt_count; i++) { if (opt_table[i].cb == (void *)opt_usage_and_exit && opt_table[i].u.carg) { extra = opt_table[i].u.carg; break; } } } ret = add_str(ret, &len, &max, " "); ret = add_str(ret, &len, &max, extra); ret = add_str(ret, &len, &max, "\n"); for (i = 0; i < opt_count; i++) { if (opt_table[i].desc == opt_hidden) continue; if (opt_table[i].type == OPT_SUBTABLE) { ret = add_str(ret, &len, &max, opt_table[i].desc); ret = add_str(ret, &len, &max, ":\n"); continue; } ret = add_desc(ret, &len, &max, indent, width, &opt_table[i]); } ret[len] = '\0'; return ret; }
void gtBaseOpts::add_options () { m_base_desc.add_options () (OPT_BIND_IP ",b", opt_string(), "Bind IP.") (OPT_CRED_FILE ",c", opt_string(), "Path/file to credentials file.") (OPT_CFG_DIR_DEPRECATED ",C", opt_string(), "Deprecated use " OPT_RESOURCE_DIR ".") (OPT_RESOURCE_DIR ",R", opt_string(), "Full path to a directory containing static resource files (dhparam.pem).") (OPT_ADVERT_IP ",e", opt_string(), "IP Address advertised.") (OPT_ADVERT_PORT ",f", opt_int(), "TCP Port advertised.") (OPT_INTERNAL_PORT ",i", opt_string(), "Local IP port to bind on.") (OPT_LOGGING ",l", opt_string(), "Path/file to log file, follow" " by the log level.") (OPT_RATE_LIMIT ",r", opt_float(), "Transfer rate limiter in MB/s.") (OPT_TIMESTAMP ",t", "Add timestamps to messages" " logged to the screen.") (OPT_VERBOSE, opt_int(), "Set on screen verbosity level.") (OPT_INACTIVE_TIMEOUT ",k", opt_int(), "Timeout transfers after" " inactivity in minutes.") (OPT_CURL_NO_VERIFY_SSL, "Do not verify SSL certificates" " of web services.") (OPT_PEER_TIMEOUT, opt_int(), "Set libtorrent peer timeout in seconds.") (OPT_NO_USER_CFG_FILE, "Do not allow users to specify a config file.") (OPT_ALLOWED_MODES, opt_string(), "Allowed modes in this GeneTorrent" " installation.") (OPT_ALLOWED_SERVERS, opt_string(), "Allowed IP address ranges for WSI, tracker," " and peer traffic.") ; if (m_use_path_opt) { m_base_desc.add_options () (OPT_PATH ",p", opt_string(), "File system path used for" " uploads and downloads.") ; } if (m_use_security_api_opt) { m_base_desc.add_options () (OPT_SECURITY_API, opt_string(), "SSL Key Signing URL") ; } add_desc (m_base_desc); m_cli_desc.add_options () (OPT_CFG_FILE, opt_string(), "Path/file to optional config file.") (OPT_HELP ",h", "Show help and exit.") (OPT_VERBOSE_INCR ",v", accumulator<int>(&global_verbosity), "Increase on screen verbosity level.") (OPT_VERSION, "Show version and exit.") ; if (m_use_alt_storage_opts) { m_cli_desc.add_options () (OPT_NULL_STORAGE, "Enable use of null storage.") (OPT_ZERO_STORAGE, "Enable use of zero storage.") ; } add_desc (m_cli_desc, VISIBLE, CLI_ONLY); }