diff options
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/history.c b/src/history.c index 63fa1104..57e556f7 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -67,8 +67,10 @@ void init_History(iHistory *d) { | |||
67 | } | 67 | } |
68 | 68 | ||
69 | void deinit_History(iHistory *d) { | 69 | void deinit_History(iHistory *d) { |
70 | clear_History(d); | 70 | iGuardMutex(d->mtx, { |
71 | deinit_Array(&d->recent); | 71 | clear_History(d); |
72 | deinit_Array(&d->recent); | ||
73 | }); | ||
72 | delete_Mutex(d->mtx); | 74 | delete_Mutex(d->mtx); |
73 | } | 75 | } |
74 | 76 | ||
@@ -249,3 +251,39 @@ void setCachedResponse_History(iHistory *d, const iGmResponse *response) { | |||
249 | } | 251 | } |
250 | unlock_Mutex(d->mtx); | 252 | unlock_Mutex(d->mtx); |
251 | } | 253 | } |
254 | |||
255 | const iStringArray *searchContents_History(const iHistory *d, const iRegExp *pattern) { | ||
256 | iStringArray *urls = iClob(new_StringArray()); | ||
257 | lock_Mutex(d->mtx); | ||
258 | iConstForEach(Array, i, &d->recent) { | ||
259 | const iRecentUrl *url = i.value; | ||
260 | const iGmResponse *resp = url->cachedResponse; | ||
261 | if (resp && category_GmStatusCode(resp->statusCode) == categorySuccess_GmStatusCode) { | ||
262 | if (indexOfCStrSc_String(&resp->meta, "text/", &iCaseInsensitive) == iInvalidPos) { | ||
263 | continue; | ||
264 | } | ||
265 | iRegExpMatch m; | ||
266 | init_RegExpMatch(&m); | ||
267 | if (matchRange_RegExp(pattern, range_Block(&resp->body), &m)) { | ||
268 | iString entry; | ||
269 | init_String(&entry); | ||
270 | iRangei cap = m.range; | ||
271 | cap.start = iMax(cap.start - 4, 0); | ||
272 | cap.end = iMin(cap.end + 10, (int) size_Block(&resp->body)); | ||
273 | iString content; | ||
274 | initRange_String(&content, (iRangecc){ m.subject + cap.start, m.subject + cap.end }); | ||
275 | /* This needs cleaning up; highlight the matched word. */ { | ||
276 | |||
277 | } | ||
278 | format_String(&entry, "match len:%zu str:%s", size_String(&content), cstr_String(&content)); | ||
279 | deinit_String(&content); | ||
280 | //appendRange_String(&entry, ); | ||
281 | appendFormat_String(&entry, " url:%s", cstr_String(&url->url)); | ||
282 | pushBack_StringArray(urls, &entry); | ||
283 | deinit_String(&entry); | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | unlock_Mutex(d->mtx); | ||
288 | return urls; | ||
289 | } | ||