[PATCH 03/20] fwts_log_scan: move fwts_log_find_changes
Marcello Sylvester Bauer
info at marcellobauer.com
Wed Jun 20 12:14:29 UTC 2018
Signed-off-by: Marcello Sylvester Bauer <info at marcellobauer.com>
---
src/lib/include/fwts_log_scan.h | 1 +
src/lib/src/fwts_klog.c | 46 +----------------------------------
src/lib/src/fwts_log_scan.c | 54 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 45 deletions(-)
diff --git a/src/lib/include/fwts_log_scan.h b/src/lib/include/fwts_log_scan.h
index b410db9b..34ac07e7 100644
--- a/src/lib/include/fwts_log_scan.h
+++ b/src/lib/include/fwts_log_scan.h
@@ -39,5 +39,6 @@ typedef struct {
} fwts_log_pattern;
void fwts_log_free(fwts_list *list);
+fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new);
#endif
diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c
index 3083fb45..bf5ac20f 100644
--- a/src/lib/src/fwts_klog.c
+++ b/src/lib/src/fwts_klog.c
@@ -51,51 +51,7 @@ void fwts_klog_free(fwts_list *klog)
*/
fwts_list *fwts_klog_find_changes(fwts_list *klog_old, fwts_list *klog_new)
{
- fwts_list_link *l_old, *l_new = NULL;
- fwts_list *klog_diff;
-
- if (klog_new == NULL) {
- /* Nothing new to compare, return nothing */
- return NULL;
- }
- if ((klog_diff = fwts_list_new()) == NULL)
- return NULL;
-
- if (klog_old == NULL) {
- /* Nothing in old log, so clone all of new list */
- l_new = klog_new->head;
- } else {
- fwts_list_link *l_old_last = NULL;
-
- /* Clone just the new differences */
-
- /* Find last item in old log */
- fwts_list_foreach(l_old, klog_old)
- l_old_last = l_old;
-
- if (l_old_last) {
- /* And now look for that last line in the new log */
- char *old = fwts_list_data(char *, l_old_last);
- fwts_list_foreach(l_new, klog_new) {
- const char *new = fwts_list_data(char *, l_new);
-
- if (!strcmp(new, old)) {
- /* Found last line that matches, bump to next */
- l_new = l_new->next;
- break;
- }
- }
- }
- }
-
- /* Clone the new unique lines to the klog_diff list */
- for (; l_new; l_new = l_new->next) {
- if (fwts_list_append(klog_diff, l_new->data) == NULL) {
- fwts_list_free(klog_diff, NULL);
- return NULL;
- }
- }
- return klog_diff;
+ return fwts_log_find_changes(klog_old, klog_new);
}
/*
diff --git a/src/lib/src/fwts_log_scan.c b/src/lib/src/fwts_log_scan.c
index 7ec81f6b..c5d174cb 100644
--- a/src/lib/src/fwts_log_scan.c
+++ b/src/lib/src/fwts_log_scan.c
@@ -37,3 +37,57 @@ void fwts_log_free(fwts_list *log)
{
fwts_text_list_free(log);
}
+
+/*
+ * fwts_log_find_changes()
+ * find new lines added to log, clone them from new list
+ * must be freed with fwts_list_free(log_diff, NULL);
+ */
+fwts_list *fwts_log_find_changes(fwts_list *log_old, fwts_list *log_new)
+{
+ fwts_list_link *l_old, *l_new = NULL;
+ fwts_list *log_diff;
+
+ if (log_new == NULL) {
+ /* Nothing new to compare, return nothing */
+ return NULL;
+ }
+ if ((log_diff = fwts_list_new()) == NULL)
+ return NULL;
+
+ if (log_old == NULL) {
+ /* Nothing in old log, so clone all of new list */
+ l_new = log_new->head;
+ } else {
+ fwts_list_link *l_old_last = NULL;
+
+ /* Clone just the new differences */
+
+ /* Find last item in old log */
+ fwts_list_foreach(l_old, log_old)
+ l_old_last = l_old;
+
+ if (l_old_last) {
+ /* And now look for that last line in the new log */
+ char *old = fwts_list_data(char *, l_old_last);
+ fwts_list_foreach(l_new, log_new) {
+ const char *new = fwts_list_data(char *, l_new);
+
+ if (!strcmp(new, old)) {
+ /* Found last line that matches, bump to next */
+ l_new = l_new->next;
+ break;
+ }
+ }
+ }
+ }
+
+ /* Clone the new unique lines to the log_diff list */
+ for (; l_new; l_new = l_new->next) {
+ if (fwts_list_append(log_diff, l_new->data) == NULL) {
+ fwts_list_free(log_diff, NULL);
+ return NULL;
+ }
+ }
+ return log_diff;
+}
--
2.16.4
More information about the fwts-devel
mailing list