diff options
author | 2008-03-16 14:42:08 +0000 | |
---|---|---|
committer | 2008-03-16 14:42:08 +0000 | |
commit | b4f39162ccfd0183f77d186938f793932c280e4a (patch) | |
tree | fe0e277e76148afecc6f65c5dc58e25f71eafeed | |
parent | ae462380dab3a8f1b916704f6e6572f35de9f389 (diff) | |
download | newsboat-b4f39162ccfd0183f77d186938f793932c280e4a.tar.gz newsboat-b4f39162ccfd0183f77d186938f793932c280e4a.tar.zst newsboat-b4f39162ccfd0183f77d186938f793932c280e4a.zip |
Andreas Krennmair:
merged changes from trunk.
updated ChangeLog and program version in config.h.
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | Makefile.prof | 1 | ||||
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | filter/Parser.frame | 30 | ||||
-rw-r--r-- | filter/Scanner.frame | 8 | ||||
-rw-r--r-- | include/pb_view.h | 2 | ||||
-rw-r--r-- | include/utils.h | 2 | ||||
-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 | ||||
-rw-r--r-- | test/test.cpp | 38 | ||||
-rw-r--r-- | xmlrss/mrss_parser.c | 10 |
18 files changed, 149 insertions, 105 deletions
@@ -1,5 +1,8 @@ Changes for newsbeuter: +0.8.2 (2008-03-16): + fixed broken string conversion (the fix from 0.8.1 didn't fully work). + 0.8.1 (2008-03-12): fixed crash (related to string conversion of format string support) diff --git a/Makefile.prof b/Makefile.prof index 5dc3c009..c923546a 100644 --- a/Makefile.prof +++ b/Makefile.prof @@ -1,4 +1,5 @@ CXXFLAGS+=-fprofile-arcs -ftest-coverage +CFLAGS+=-fprofile-arcs -ftest-coverage LCOV_FILE=newsbeuter.info @@ -2,7 +2,7 @@ #define NEWSBEUTER_CONFIG__H #define PROGRAM_NAME PACKAGE -#define PROGRAM_VERSION "0.8.1" +#define PROGRAM_VERSION "0.8.2" #define PROGRAM_URL "http://synflood.at/newsbeuter.html" #define USER_AGENT PROGRAM_NAME " rss feedreader " PROGRAM_VERSION " (" PROGRAM_URL ")" diff --git a/filter/Parser.frame b/filter/Parser.frame index b8e8de34..ba5ce864 100644 --- a/filter/Parser.frame +++ b/filter/Parser.frame @@ -42,11 +42,10 @@ public: int count; // number of errors detected Errors(); - void SynErr(int line, int col, int n); - void Error(int line, int col, wchar_t *s); - void Warning(int line, int col, wchar_t *s); - void Warning(wchar_t *s); - void Exception(wchar_t *s); + void SynErr(int n); + void Error(); + void Warning(); + void Exception(); }; // Errors @@ -124,12 +123,13 @@ Coco/R itself) does not fall under the GNU General Public License. -->namespace_open void Parser::SynErr(int n) { - if (errDist >= minErrDist) errors->SynErr(la->line, la->col, n); + if (errDist >= minErrDist) errors->SynErr(n); errDist = 0; } void Parser::SemErr(wchar_t* msg) { - if (errDist >= minErrDist) errors->Error(t->line, t->col, msg); + msg = msg; + if (errDist >= minErrDist) errors->Error(); errDist = 0; } @@ -214,7 +214,7 @@ Errors::Errors() { count = 0; } -void Errors::SynErr(int line, int col, int n) { +void Errors::SynErr(int n) { wchar_t* s; switch (n) { -->errors @@ -226,26 +226,18 @@ void Errors::SynErr(int line, int col, int n) { } break; } - /* wprintf(L"-- line %d col %d: %ls\n", line, col, s); */ coco_string_delete(s); count++; } -void Errors::Error(int line, int col, wchar_t *s) { - /* wprintf(L"-- line %d col %d: %ls\n", line, col, s); */ +void Errors::Error() { count++; } -void Errors::Warning(int line, int col, wchar_t *s) { - /* wprintf(L"-- line %d col %d: %ls\n", line, col, s); */ -} - -void Errors::Warning(wchar_t *s) { - /* wprintf(L"%ls\n", s); */ +void Errors::Warning() { } -void Errors::Exception(wchar_t* s) { - /* wprintf(L"%ls", s); */ +void Errors::Exception() { } -->namespace_close diff --git a/filter/Scanner.frame b/filter/Scanner.frame index 1edddc15..9a98439e 100644 --- a/filter/Scanner.frame +++ b/filter/Scanner.frame @@ -68,7 +68,7 @@ int coco_string_lastindexof(wchar_t* data, wchar_t value); void coco_string_merge(wchar_t* &data, wchar_t* value); bool coco_string_equal(wchar_t* data1, wchar_t* data2); int coco_string_compareto(wchar_t* data1, wchar_t* data2); -int coco_string_hash(wchar_t* data); +int coco_string_hash(const wchar_t* data); // string handling, ascii character wchar_t* coco_string_create(const char *value); @@ -175,7 +175,7 @@ private: wchar_t *key; int val; Elem *next; - Elem(wchar_t *key, int val) { this->key = coco_string_create(key); this->val = val; next = NULL; } + Elem(const wchar_t *key, int val) { this->key = coco_string_create(key); this->val = val; next = NULL; } virtual ~Elem() { coco_string_delete(key); } }; @@ -195,7 +195,7 @@ public: delete [] tab; } - void set(wchar_t *key, int val) { + void set(const wchar_t *key, int val) { Elem *e = new Elem(key, val); int k = coco_string_hash(key) % 128; e->next = tab[k]; tab[k] = e; @@ -431,7 +431,7 @@ int coco_string_compareto(wchar_t* data1, wchar_t* data2) { return wcscmp(data1, data2); } -int coco_string_hash(wchar_t *data) { +int coco_string_hash(const wchar_t *data) { int h = 0; if (!data) { return 0; } while (*data != 0) { diff --git a/include/pb_view.h b/include/pb_view.h index 9a1a0634..40034f20 100644 --- a/include/pb_view.h +++ b/include/pb_view.h @@ -11,8 +11,6 @@ namespace podbeuter { class pb_controller; -class newsbeuter::colormanager; - struct keymap_hint_entry; class pb_view { diff --git a/include/utils.h b/include/utils.h index 4a07aae1..fe0a3298 100644 --- a/include/utils.h +++ b/include/utils.h @@ -15,6 +15,8 @@ class utils { static std::vector<std::string> tokenize_nl(const std::string& str, std::string delimiters = "\r\n"); static std::vector<std::string> tokenize_quoted(const std::string& str, std::string delimiters = " \r\n\t"); + static std::vector<std::wstring> wtokenize(const std::wstring& str, std::wstring delimiters = L" \r\n\t"); + static bool try_fs_lock(const std::string& lock_file, pid_t & pid); static void remove_fs_lock(const std::string& lock_file); 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) { diff --git a/test/test.cpp b/test/test.cpp index 693cb05b..00c33e24 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -60,6 +60,22 @@ BOOST_AUTO_TEST_CASE(TestNewsbeuterReload) { BOOST_CHECK_EQUAL(feed2.items()[0].title(), "Another Title"); BOOST_CHECK_EQUAL(feed2.items()[7].title(), "Handy als IR-Detektor"); + rsscache->set_lastmodified("http://bereshit.synflood.at/~ak/rss.xml", 1000); + BOOST_CHECK_EQUAL(rsscache->get_lastmodified("http://bereshit.synflood.at/~ak/rss.xml"), 1000); + rsscache->set_lastmodified("http://bereshit.synflood.at/~ak/rss.xml", 0); + BOOST_CHECK_EQUAL(rsscache->get_lastmodified("http://bereshit.synflood.at/~ak/rss.xml"), 1000); + + std::vector<std::string> feedurls = rsscache->get_feed_urls(); + BOOST_CHECK_EQUAL(feedurls.size(), 1u); + BOOST_CHECK_EQUAL(feedurls[0], "http://bereshit.synflood.at/~ak/rss.xml"); + + std::vector<rss_feed> feedv; + feedv.push_back(feed); + + cfg->set_configvalue("cleanup-on-quit", "true"); + rsscache->cleanup_cache(feedv); + + delete rsscache; delete cfg; @@ -103,6 +119,7 @@ BOOST_AUTO_TEST_CASE(TestConfigParserContainerAndKeymap) { BOOST_CHECK_EQUAL(k.get_operation("ENTER"), OP_OPEN); BOOST_CHECK_EQUAL(k.get_operation("u"), OP_SHOWURLS); BOOST_CHECK_EQUAL(k.get_operation("X"), OP_NIL); + BOOST_CHECK_EQUAL(k.get_operation(""), OP_NIL); k.unset_key("ENTER"); BOOST_CHECK_EQUAL(k.get_operation("ENTER"), OP_NIL); @@ -121,7 +138,19 @@ BOOST_AUTO_TEST_CASE(TestConfigParserContainerAndKeymap) { BOOST_CHECK_EQUAL(k.get_key("~"), '~'); BOOST_CHECK_EQUAL(k.get_key("INVALID"), 0); BOOST_CHECK_EQUAL(k.get_key("ENTER"), '\n'); + BOOST_CHECK_EQUAL(k.get_key("ESC"), '\033'); BOOST_CHECK_EQUAL(k.get_key("^A"), '\001'); + + std::vector<std::string> params; + BOOST_CHECK_EQUAL(k.handle_action("bind-key", params), AHS_TOO_FEW_PARAMS); + BOOST_CHECK_EQUAL(k.handle_action("unbind-key", params), AHS_TOO_FEW_PARAMS); + BOOST_CHECK_EQUAL(k.handle_action("macro", params), AHS_TOO_FEW_PARAMS); + params.push_back("r"); + BOOST_CHECK_EQUAL(k.handle_action("bind-key", params), AHS_TOO_FEW_PARAMS); + BOOST_CHECK_EQUAL(k.handle_action("unbind-key", params), AHS_OK); + params.push_back("open"); + BOOST_CHECK_EQUAL(k.handle_action("bind-key", params), AHS_OK); + BOOST_CHECK_EQUAL(k.handle_action("an-invalid-action", params), AHS_INVALID_PARAMS); } BOOST_AUTO_TEST_CASE(TestXmlPullParser) { @@ -385,6 +414,13 @@ BOOST_AUTO_TEST_CASE(TestStringConversion) { std::wstring w1 = utils::str2wstr("And that's another simple string."); BOOST_CHECK_EQUAL(w1 == L"And that's another simple string.", true); + + std::wstring w2 = utils::str2wstr(""); + BOOST_CHECK_EQUAL(w2 == L"", true); + + std::string s2 = utils::wstr2str(L""); + BOOST_CHECK_EQUAL(s2, ""); + } BOOST_AUTO_TEST_CASE(TestFmtStrFormatter) { @@ -431,7 +467,7 @@ BOOST_AUTO_TEST_CASE(TestMiscUtilsFunctions) { BOOST_CHECK_EQUAL(utils::get_command_output("ls /dev/null"), "/dev/null\n"); BOOST_CHECK_EQUAL(utils::run_filter("cat", "this is a multine-line\ntest string"), "this is a multine-line\ntest string"); - BOOST_CHECK_EQUAL(utils::run_filter("wc -c", "0123456789"), "10\n"); + BOOST_CHECK_EQUAL(utils::run_filter("echo -n 'hello world'", ""), "hello world"); BOOST_CHECK_EQUAL(utils::replace_all("aaa", "a", "b"), "bbb"); BOOST_CHECK_EQUAL(utils::replace_all("aaa", "aa", "ba"), "baa"); diff --git a/xmlrss/mrss_parser.c b/xmlrss/mrss_parser.c index 878f2608..9c6108c3 100644 --- a/xmlrss/mrss_parser.c +++ b/xmlrss/mrss_parser.c @@ -245,6 +245,8 @@ __mrss_atom_prepare_date (mrss_t * data, const char *datestr) { struct tm stm; + data = data; + if (!datestr) return NULL; @@ -450,6 +452,8 @@ __mrss_parser_rss_image (nxml_t * doc, nxml_data_t * cur, mrss_t * data) { const char *c; + doc = doc; + for (cur = cur->children; cur; cur = cur->next) { if (cur->type == NXML_TYPE_ELEMENT) @@ -499,6 +503,8 @@ __mrss_parser_rss_textinput (nxml_t * doc, nxml_data_t * cur, mrss_t * data) { const char *c; + doc = doc; + for (cur = cur->children; cur; cur = cur->next) { if (cur->type == NXML_TYPE_ELEMENT) @@ -532,6 +538,8 @@ __mrss_parser_rss_skipHours (nxml_t * doc, nxml_data_t * cur, mrss_t * data) { const char *c; + doc = doc; + for (cur = cur->children; cur; cur = cur->next) { if (cur->type == NXML_TYPE_ELEMENT) @@ -572,6 +580,8 @@ static void __mrss_parser_rss_skipDays (nxml_t * doc, nxml_data_t * cur, mrss_t * data) { const char *c; + + doc = doc; for (cur = cur->children; cur; cur = cur->next) { |