1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-20 00:21:35 +00:00

Update to 0.8.2

This commit is contained in:
Tilman Keskinoz 2008-03-18 12:37:02 +00:00
parent ae78fcb654
commit 16efa28788
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=209295
3 changed files with 4 additions and 310 deletions

View File

@ -5,8 +5,7 @@
# $FreeBSD$
PORTNAME= newsbeuter
PORTVERSION= 0.8.1
PORTREVISION= 1
PORTVERSION= 0.8.2
CATEGORIES= www
MASTER_SITES= http://synflood.at/newsbeuter/

View File

@ -1,3 +1,3 @@
MD5 (newsbeuter-0.8.1.tar.gz) = 410c62c88da65db7a45290b129305984
SHA256 (newsbeuter-0.8.1.tar.gz) = 10cc32687350621d1fce8013ffc8b20a49473e2fc6582f4caa5b61e9bd300573
SIZE (newsbeuter-0.8.1.tar.gz) = 235670
MD5 (newsbeuter-0.8.2.tar.gz) = 403891c24d999206d57b33ee630c42b3
SHA256 (newsbeuter-0.8.2.tar.gz) = 28ade0aeb2dcd5f855cd24dbf7d773616e425944b91e2485086d935f494fb364
SIZE (newsbeuter-0.8.2.tar.gz) = 235774

View File

@ -1,305 +0,0 @@
Index: include/utils.h
===================================================================
--- include/utils.h (revision 1224)
+++ include/utils.h (revision 1231)
@@ -15,6 +15,8 @@
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);
Index: src/formatstring.cpp
===================================================================
--- src/formatstring.cpp (revision 1224)
+++ src/formatstring.cpp (revision 1231)
@@ -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 @@
}
} 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 @@
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,22 +83,30 @@
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[0], width);
}
+ GetLogger().log(LOG_DEBUG, "YYY result = `%ls'", subresult.c_str());
+ result.append(subresult);
+
i = k;
} else {
i = k - 1;
@@ -112,6 +123,7 @@
result.append(1, wfmt[i]);
}
}
+ GetLogger().log(LOG_DEBUG, "end of do_wformat");
return result;
}
Index: src/utils.cpp
===================================================================
--- src/utils.cpp (revision 1224)
+++ src/utils.cpp (revision 1231)
@@ -17,6 +17,7 @@
#include <curl/curl.h>
+#include <langinfo.h>
#include <stfl.h>
namespace newsbeuter {
@@ -133,7 +133,7 @@
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 +150,22 @@
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 +297,9 @@
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 +308,8 @@
}
} 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);
@@ -500,48 +516,19 @@
}
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) {
Index: src/logger.cpp
===================================================================
--- src/logger.cpp (revision 1224)
+++ src/logger.cpp (revision 1231)
@@ -2,7 +2,6 @@
#include <stdarg.h>
#include <exception.h>
#include <cerrno>
-#include <alloca.h>
namespace newsbeuter {
@@ -65,11 +64,11 @@
va_start(ap, format);
unsigned int len = vsnprintf(NULL,0,format,ap);
- logmsgbuf = (char *)alloca(len + 1);
+ logmsgbuf = new char[len + 1];
vsnprintf(logmsgbuf, len + 1, format, ap);
len = snprintf(NULL, 0, "[%s] %s: %s",date, loglevel_str[level], logmsgbuf);
- buf = (char *)alloca(len + 1);
+ buf = new char[len + 1];
snprintf(buf,len + 1,"[%s] %s: %s",date, loglevel_str[level], logmsgbuf);
if (f.is_open()) {
@@ -82,6 +81,9 @@
ef.flush();
}
+ delete[] buf;
+ delete[] logmsgbuf;
+
}
}