diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.cpp | 13 | ||||
-rw-r--r-- | src/configcontainer.cpp | 2 | ||||
-rw-r--r-- | src/controller.cpp | 6 | ||||
-rw-r--r-- | src/filebrowser_formaction.cpp | 2 | ||||
-rw-r--r-- | src/formatstring.cpp | 52 | ||||
-rw-r--r-- | src/htmlrenderer.cpp | 1 | ||||
-rw-r--r-- | src/select_formaction.cpp | 2 | ||||
-rw-r--r-- | src/urlview_formaction.cpp | 2 | ||||
-rw-r--r-- | src/utils.cpp | 78 |
9 files changed, 80 insertions, 78 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index d765fb94..8d4aabc6 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -557,11 +557,10 @@ void cache::update_rssitem(rss_item& item, const std::string& feedurl) { throw dbexception(db); } if (count_cbh.count() > 0) { - std::string update = prepare_query("UPDATE rss_item SET title = '%q', author = '%q', url = '%q', feedurl = '%q', content = '%q', enclosure_url = '%q', enclosure_type = '%q', flags = '%q' WHERE guid = '%q'", + std::string update = prepare_query("UPDATE rss_item SET title = '%q', author = '%q', url = '%q', feedurl = '%q', content = '%q', enclosure_url = '%q', enclosure_type = '%q' WHERE guid = '%q'", item.title_raw().c_str(), item.author_raw().c_str(), item.link().c_str(), feedurl.c_str(), item.description_raw().c_str(), item.enclosure_url().c_str(), item.enclosure_type().c_str(), - item.flags().c_str(), item.guid().c_str()); GetLogger().log(LOG_DEBUG,"running query: %s", update.c_str()); rc = sqlite3_exec(db,update.c_str(),NULL,NULL,NULL); @@ -570,11 +569,11 @@ void cache::update_rssitem(rss_item& item, const std::string& feedurl) { throw dbexception(db); } } else { - std::string insert = prepare_query("INSERT INTO rss_item (guid,title,author,url,feedurl,pubDate,content,unread,enclosure_url,enclosure_type,enqueued,flags) " - "VALUES ('%q','%q','%q','%q','%q','%u','%q',1,'%q','%q',%d, '%q')", + std::string insert = prepare_query("INSERT INTO rss_item (guid,title,author,url,feedurl,pubDate,content,unread,enclosure_url,enclosure_type,enqueued) " + "VALUES ('%q','%q','%q','%q','%q','%u','%q',1,'%q','%q',%d)", item.guid().c_str(), item.title_raw().c_str(), item.author_raw().c_str(), item.link().c_str(), feedurl.c_str(), item.pubDate_timestamp(), item.description_raw().c_str(), - item.enclosure_url().c_str(), item.enclosure_type().c_str(), item.enqueued() ? 1 : 0, item.flags().c_str()); + item.enclosure_url().c_str(), item.enclosure_type().c_str(), item.enqueued() ? 1 : 0); GetLogger().log(LOG_DEBUG,"running query: %s", insert.c_str()); rc = sqlite3_exec(db,insert.c_str(),NULL,NULL,NULL); if (rc != SQLITE_OK) { @@ -643,10 +642,10 @@ void cache::update_rssitem_unread_and_enqueued(rss_item& item, const std::string } } else { std::string insert = prepare_query("INSERT INTO rss_item (guid,title,author,url,feedurl,pubDate,content,unread,enclosure_url,enclosure_type,enqueued,flags) " - "VALUES ('%q','%q','%q','%q','%q','%u','%q',1,'%q','%q',%d, '%q')", + "VALUES ('%q','%q','%q','%q','%q','%u','%q',1,'%q','%q',%d)", item.guid().c_str(), item.title_raw().c_str(), item.author_raw().c_str(), item.link().c_str(), feedurl.c_str(), item.pubDate_timestamp(), item.description_raw().c_str(), - item.enclosure_url().c_str(), item.enclosure_type().c_str(), item.enqueued() ? 1 : 0, item.flags().c_str()); + item.enclosure_url().c_str(), item.enclosure_type().c_str(), item.enqueued() ? 1 : 0); GetLogger().log(LOG_DEBUG,"running query: %s", insert.c_str()); rc = sqlite3_exec(db,insert.c_str(),NULL,NULL,NULL); if (rc != SQLITE_OK) { diff --git a/src/configcontainer.cpp b/src/configcontainer.cpp index 319d49c1..d278b34a 100644 --- a/src/configcontainer.cpp +++ b/src/configcontainer.cpp @@ -47,7 +47,7 @@ configcontainer::configcontainer() config_data["opml-url"] = configdata("", configdata::STR); config_data["html-renderer"] = configdata("internal", configdata::PATH); config_data["feedlist-format"] = configdata("%4i %n %11u %t", configdata::STR); - config_data["articlelist-format"] = configdata("%4i %f %D %?T?|%-17T| ?%t", configdata::STR); + config_data["articlelist-format"] = configdata("%4i %f %D %?T?|%-17T| &?%t", configdata::STR); config_data["text-width"] = configdata("0", configdata::INT); config_data["always-display-description"] = configdata("false", configdata::BOOL); diff --git a/src/controller.cpp b/src/controller.cpp index 49543e40..06f415a7 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -52,7 +52,7 @@ void ignore_signal(int sig) { void omg_a_child_died(int /* sig */) { pid_t pid; int stat; - while ((pid = waitpid(-1,&stat,WNOHANG)) > 0); + while ((pid = waitpid(-1,&stat,WNOHANG)) > 0) { } } controller::controller() : v(0), rsscache(0), url_file("urls"), cache_file("cache.db"), config_file("config"), queue_file("queue"), refresh_on_start(false), cfg(0) { @@ -820,8 +820,8 @@ std::string controller::bookmark(const std::string& url, const std::string& titl std::string bookmark_cmd = cfg->get_configvalue("bookmark-cmd"); if (bookmark_cmd.length() > 0) { char * my_argv[4]; - my_argv[0] = "/bin/sh"; - my_argv[1] = "-c"; + my_argv[0] = const_cast<char *>("/bin/sh"); + my_argv[1] = const_cast<char *>("-c"); // wow. what an abuse. std::string cmdline = bookmark_cmd + " " + stfl::quote(url) + " " + stfl::quote(title) + " " + stfl::quote(description); diff --git a/src/filebrowser_formaction.cpp b/src/filebrowser_formaction.cpp index 63fe9d94..b57066cd 100644 --- a/src/filebrowser_formaction.cpp +++ b/src/filebrowser_formaction.cpp @@ -24,7 +24,7 @@ filebrowser_formaction::filebrowser_formaction(view * vv, std::string formstr) filebrowser_formaction::~filebrowser_formaction() { } -void filebrowser_formaction::process_operation(operation op, bool automatic, std::vector<std::string> * args) { +void filebrowser_formaction::process_operation(operation op, bool /* automatic */, std::vector<std::string> * /* args */) { switch (op) { case OP_OPEN: { diff --git a/src/formatstring.cpp b/src/formatstring.cpp index 579bcba0..0ff416b0 100644 --- a/src/formatstring.cpp +++ b/src/formatstring.cpp @@ -10,45 +10,48 @@ namespace newsbeuter { void fmtstr_formatter::register_fmt(char f, const std::string& value) { - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::register_fmt: char = %c value = %s", f, value.c_str()); + // GetLogger().log(LOG_DEBUG, "fmtstr_formatter::register_fmt: char = %c value = %s", f, value.c_str()); fmts[f] = utils::utf8str2wstr(value); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::register_fmt: char = %c done", f); + // GetLogger().log(LOG_DEBUG, "fmtstr_formatter::register_fmt: char = %c done", f); } std::string fmtstr_formatter::do_format(const std::string& fmt, unsigned int width) { - std::wstring wfmt(utils::str2wstr(fmt)); - std::string result = utils::wstr2str(do_wformat(wfmt, width)); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: after conversion: `%s'", result.c_str()); + std::string result; + if (fmt.length() > 0) { + std::wstring wfmt(utils::str2wstr(fmt)); + std::wstring w = do_wformat(wfmt, width); + result = utils::wstr2str(w); + } return result; } std::wstring fmtstr_formatter::do_wformat(const std::wstring& wfmt, unsigned int width) { - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: fmt = `%ls' width = %u", wfmt.c_str(), width); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: fmt = `%ls' width = %u", wfmt.c_str(), width); std::wstring result; unsigned int i; unsigned int fmtlen = wfmt.length(); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: fmtlen = %u", fmtlen); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: fmtlen = %u", fmtlen); for (i=0;i<fmtlen;++i) { if (wfmt[i] == L'%') { if (i<(fmtlen-1)) { if (wfmt[i+1] == L'-' || iswdigit(wfmt[i+1])) { - std::string number; + std::wstring number; wchar_t c; while ((wfmt[i+1] == L'-' || iswdigit(wfmt[i+1])) && i<(fmtlen-1)) { number.append(1,wfmt[i+1]); ++i; } - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: number = %s", number.c_str()); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: number = %ls", number.c_str()); if (i<(fmtlen-1)) { c = wfmt[i+1]; ++i; - std::istringstream is(number); + std::wistringstream is(number); int align; is >> align; - if (abs(align) > fmts[c].length()) { + if (static_cast<unsigned int>(abs(align)) > fmts[c].length()) { wchar_t buf[256]; swprintf(buf,sizeof(buf)/sizeof(*buf),L"%*ls", align, fmts[c].c_str()); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: swprintf result = %ls", buf); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: swprintf result = %ls", buf); result.append(buf); } else { result.append(fmts[c].substr(0,abs(align))); @@ -56,7 +59,7 @@ std::wstring fmtstr_formatter::do_wformat(const std::wstring& wfmt, unsigned int } } else if (wfmt[i+1] == L'%') { result.append(1, L'%'); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: appending %"); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: appending %"); ++i; } else if (wfmt[i+1] == L'>') { if (wfmt[i+2]) { @@ -65,9 +68,9 @@ std::wstring fmtstr_formatter::do_wformat(const std::wstring& wfmt, unsigned int i += 2; } else { std::wstring rightside = do_wformat(&wfmt[i+3], 0); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: aligning, right side = %ls", rightside.c_str()); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: aligning, right side = %ls", rightside.c_str()); int diff = width - wcswidth(result.c_str(),result.length()) - wcswidth(rightside.c_str(), rightside.length()); - GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_format: diff = %d char = %lc", diff, wfmt[i+2]); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: diff = %d char = %lc", diff, wfmt[i+2]); if (diff > 0) { result.append(diff, wfmt[i+2]); } @@ -80,21 +83,29 @@ std::wstring fmtstr_formatter::do_wformat(const std::wstring& wfmt, unsigned int while (wfmt[j] && wfmt[j] != L'?') j++; if (wfmt[j]) { - std::wstring cond = wfmt.substr(i+2, j - i - 1); + std::wstring cond = wfmt.substr(i+2, j - i - 2); unsigned int k = j + 1; while (wfmt[k] && wfmt[k] != L'?') k++; if (wfmt[k]) { std::wstring values = wfmt.substr(j+1, k - j - 1); - std::vector<std::string> pair = utils::tokenize(utils::wstr2str(values),"&"); + std::vector<std::wstring> pair = utils::wtokenize(values,L"&"); while (pair.size() < 2) - pair.push_back(""); + pair.push_back(L""); + GetLogger().log(LOG_DEBUG, "fmtstr_formatter::do_wformat: values = `%ls' cond = `%ls' cond[0] = `%lc' fmts[cond[0]] = `%ls'", values.c_str(), cond.c_str(), cond[0], fmts[cond[0]].c_str()); + GetLogger().log(LOG_DEBUG, "YYY pair0 = `%ls' pair1 = `%ls'", pair[0].c_str(), pair[1].c_str()); + std::wstring subresult; if (fmts[cond[0]].length() > 0) { - result.append(do_wformat(utils::str2wstr(pair[0]), width)); + if (pair[0].length() > 0) + subresult = do_wformat(pair[0], width); } else { - result.append(do_wformat(utils::str2wstr(pair[1]), width)); + if (pair[1].length() > 0) + subresult = do_wformat(pair[1], width); } + GetLogger().log(LOG_DEBUG, "YYY result = `%ls'", subresult.c_str()); + result.append(subresult); + i = k; } else { @@ -112,6 +123,7 @@ std::wstring fmtstr_formatter::do_wformat(const std::wstring& wfmt, unsigned int result.append(1, wfmt[i]); } } + GetLogger().log(LOG_DEBUG, "end of do_wformat"); return result; } diff --git a/src/htmlrenderer.cpp b/src/htmlrenderer.cpp index 927eafa0..19487fbe 100644 --- a/src/htmlrenderer.cpp +++ b/src/htmlrenderer.cpp @@ -6,6 +6,7 @@ #include <iostream> #include <cstring> #include <stdexcept> +#include <algorithm> #include <logger.h> #include <libgen.h> #include <config.h> diff --git a/src/select_formaction.cpp b/src/select_formaction.cpp index 144083fd..9806458a 100644 --- a/src/select_formaction.cpp +++ b/src/select_formaction.cpp @@ -33,7 +33,7 @@ void select_formaction::handle_cmdline(const std::string& cmd) { } } -void select_formaction::process_operation(operation op, bool automatic, std::vector<std::string> * args) { +void select_formaction::process_operation(operation op, bool /* automatic */, std::vector<std::string> * /* args */) { switch (op) { case OP_QUIT: value = ""; diff --git a/src/urlview_formaction.cpp b/src/urlview_formaction.cpp index 8ee4196e..5eea6141 100644 --- a/src/urlview_formaction.cpp +++ b/src/urlview_formaction.cpp @@ -19,7 +19,7 @@ urlview_formaction::urlview_formaction(view * vv, std::string formstr) urlview_formaction::~urlview_formaction() { } -void urlview_formaction::process_operation(operation op, bool automatic, std::vector<std::string> * args) { +void urlview_formaction::process_operation(operation op, bool /* automatic */, std::vector<std::string> * /* args */) { switch (op) { case OP_OPEN: { diff --git a/src/utils.cpp b/src/utils.cpp index 017ac48e..ad5e2a6f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -17,6 +17,7 @@ #include <curl/curl.h> +#include <langinfo.h> #include <stfl.h> namespace newsbeuter { @@ -133,7 +134,7 @@ std::vector<std::string> utils::tokenize_quoted(const std::string& str, std::str return tokens; } - + std::vector<std::string> utils::tokenize(const std::string& str, std::string delimiters) { /* * This function tokenizes a string by the delimiters. Plain and simple. @@ -150,6 +151,22 @@ std::vector<std::string> utils::tokenize(const std::string& str, std::string del return tokens; } +std::vector<std::wstring> utils::wtokenize(const std::wstring& str, std::wstring delimiters) { + /* + * This function tokenizes a string by the delimiters. Plain and simple. + */ + std::vector<std::wstring> tokens; + std::wstring::size_type last_pos = str.find_first_not_of(delimiters, 0); + std::wstring::size_type pos = str.find_first_of(delimiters, last_pos); + + while (std::string::npos != pos || std::string::npos != last_pos) { + tokens.push_back(str.substr(last_pos, pos - last_pos)); + last_pos = str.find_first_not_of(delimiters, pos); + pos = str.find_first_of(delimiters, last_pos); + } + return tokens; +} + std::vector<std::string> utils::tokenize_spaced(const std::string& str, std::string delimiters) { std::vector<std::string> tokens; std::string::size_type last_pos = str.find_first_not_of(delimiters, 0); @@ -281,9 +298,9 @@ std::string utils::convert_text(const std::string& text, const std::string& toco case EINVAL: result.append(old_outbufp, outbufp - old_outbufp); result.append("?"); - GetLogger().log(LOG_DEBUG, "utils::convert_text: hit EILSEQ/EINVAL: result = `%s'", result.c_str()); + // GetLogger().log(LOG_DEBUG, "utils::convert_text: hit EILSEQ/EINVAL: result = `%s'", result.c_str()); inbufp += strlen(inbufp) - inbytesleft + 1; - GetLogger().log(LOG_DEBUG, "utils::convert_text: new inbufp: `%s'", inbufp); + // GetLogger().log(LOG_DEBUG, "utils::convert_text: new inbufp: `%s'", inbufp); inbytesleft = strlen(inbufp); break; } @@ -292,8 +309,8 @@ std::string utils::convert_text(const std::string& text, const std::string& toco } } while (inbytesleft > 0); - GetLogger().log(LOG_DEBUG, "utils::convert_text: before: %s", text.c_str()); - GetLogger().log(LOG_DEBUG, "utils::convert_text: after: %s", result.c_str()); + // GetLogger().log(LOG_DEBUG, "utils::convert_text: before: %s", text.c_str()); + // GetLogger().log(LOG_DEBUG, "utils::convert_text: after: %s", result.c_str()); iconv_close(cd); @@ -346,6 +363,7 @@ std::string utils::retrieve_url(const std::string& url, const char * user_agent, } curl_easy_perform(easyhandle); + curl_easy_cleanup(easyhandle); GetLogger().log(LOG_DEBUG, "utils::retrieve_url(%s): %s", url.c_str(), buf.c_str()); @@ -387,6 +405,7 @@ std::string utils::run_filter(const std::string& cmd, const std::string& input) close(opipe[0]); dup2(ipipe[0], 0); dup2(opipe[1], 1); + GetLogger().log(LOG_DEBUG, "utils::run_filter: ipipe[0] = %d ipipe[1] = %d opipe[0] = %d opipe[1] = %d", ipipe[0], ipipe[1], opipe[0], opipe[1]); execl("/bin/sh", "/bin/sh", "-c", cmd.c_str(), NULL); exit(1); } @@ -500,48 +519,19 @@ std::wstring utils::utf8str2wstr(const std::string& utf8str) { } std::wstring utils::str2wstr(const std::string& str) { - const char* pszExt = str.c_str(); - wchar_t pwszInt [str.length()+1]; - - memset(&pwszInt[0], 0, sizeof(wchar_t)*(str.length() + 1)); - const char* pszNext; - wchar_t* pwszNext; - mbstate_t state = {0}; - GetLogger().log(LOG_DEBUG, "utils::str2wstr: current locale: %s", setlocale(LC_CTYPE, NULL)); -#ifdef __APPLE__ - std::locale loc; -#else - std::locale loc(setlocale(LC_CTYPE, NULL)); -#endif - int res = std::use_facet<std::codecvt<wchar_t, char, mbstate_t> > ( loc ).in( state, pszExt, &pszExt[strlen(pszExt)], pszNext, pwszInt, &pwszInt[strlen(pszExt)], pwszNext ); - if (res == std::codecvt_base::error) { - GetLogger().log(LOG_ERROR, "utils::str2wstr: conversion of `%s' failed (locale = %s).", str.c_str(), setlocale(LC_CTYPE, NULL)); - throw "utils::str2wstr: conversion failed"; - } - // pwszInt[strlen(pszExt)] = 0; - return std::wstring(pwszInt); + const char * codeset = nl_langinfo(CODESET); + struct stfl_ipool * ipool = stfl_ipool_create(codeset); + std::wstring result = stfl_ipool_towc(ipool, str.c_str()); + stfl_ipool_destroy(ipool); + return result; } std::string utils::wstr2str(const std::wstring& wstr) { - char pszExt[4*wstr.length()+1]; - const wchar_t *pwszInt = wstr.c_str(); - memset(pszExt, 0, 4*wstr.length()+1); - char* pszNext; - const wchar_t* pwszNext; - mbstate_t state = {0}; - GetLogger().log(LOG_DEBUG, "utils::wstr2str: locale = %s input = `%ls'", setlocale(LC_CTYPE, NULL), wstr.c_str()); -#ifdef __APPLE__ - std::locale loc; -#else - std::locale loc(setlocale(LC_CTYPE, NULL)); -#endif - int res = std::use_facet<std::codecvt<wchar_t, char, mbstate_t> > (loc).out(state, pwszInt, &pwszInt[wcslen(pwszInt)], pwszNext, pszExt, pszExt + sizeof(pszExt), pszNext); - if (res == std::codecvt_base::error) { - GetLogger().log(LOG_ERROR, "utils::wstr2str: conversion of `%ls' failed.", wstr.c_str()); - throw "utils::wstr2str: conversion failed"; - } - // pszExt[wcslen(pwszInt)] = 0; - return std::string(pszExt); + const char * codeset = nl_langinfo(CODESET); + struct stfl_ipool * ipool = stfl_ipool_create(codeset); + std::string result = stfl_ipool_fromwc(ipool, wstr.c_str()); + stfl_ipool_destroy(ipool); + return result; } std::string utils::to_s(unsigned int u) { |