mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-16 19:00:58 +01:00
fix compileerrors, add tests (#2)
This commit is contained in:
32
engine.cc
32
engine.cc
@@ -315,8 +315,7 @@ void Engine::regexp() {
|
||||
// record end
|
||||
mode = "key";
|
||||
if(config.token != "") {
|
||||
//char **subs = new char*[2];
|
||||
char *subs[2];
|
||||
string *subs = new string[2];
|
||||
|
||||
num = pcre2_match(p_pcre, (PCRE2_SPTR)line.c_str(), (PCRE2_SIZE)line.length(), 0, 0, match_data, NULL);
|
||||
|
||||
@@ -326,19 +325,20 @@ void Engine::regexp() {
|
||||
cerr << "Token " << config.token << " did not produce sub strings!\n";
|
||||
else {
|
||||
ovector = pcre2_get_ovector_pointer(match_data);
|
||||
const char *constline = const_cast<char*>(line.c_str());
|
||||
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
char * substring_start = const_cast<char*>(line.c_str()) + ovector[2*i];
|
||||
for (int i = 1; i < num; i++) {
|
||||
PCRE2_SPTR substring_start = (PCRE2_SPTR8)constline + ovector[2*i];
|
||||
PCRE2_SIZE substring_length = ovector[2*i+1] - ovector[2*i];
|
||||
|
||||
if (i == 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
subs[i] = substring_start;
|
||||
char *part = (char *)malloc(substring_length+1);
|
||||
part = strncpy(part, (char *)substring_start, substring_length);
|
||||
|
||||
subs[i-1] = part;
|
||||
free(part);
|
||||
}
|
||||
|
||||
free(ovector);
|
||||
|
||||
|
||||
if(config.reverse) {
|
||||
value = subs[0];
|
||||
key = subs[1];
|
||||
@@ -349,9 +349,8 @@ void Engine::regexp() {
|
||||
}
|
||||
}
|
||||
|
||||
//delete(subs);
|
||||
delete[] subs;
|
||||
|
||||
|
||||
line = "";
|
||||
}
|
||||
value = encode(value);
|
||||
@@ -563,8 +562,9 @@ void Engine::regexp() {
|
||||
*/
|
||||
void Engine::remove() {
|
||||
init();
|
||||
#ifdef HAVE_BERKELEY
|
||||
Dbt key((char *)config.key.c_str(), config.key.length() + 1);
|
||||
#ifdef HAVE_BERKELEY
|
||||
char *k = (char *)config.key.c_str();
|
||||
Dbt key(k, strlen(k));
|
||||
int ret;
|
||||
if((ret = db->del(NULL, &key, 0)) != 0) {
|
||||
cerr << "Database error" << "(" << strerror(ret) << ")" << endl;
|
||||
|
||||
Reference in New Issue
Block a user