summaryrefslogtreecommitdiff
path: root/src/search.h
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 14:29:17 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-03-03 14:29:17 +0100
commita3685d46c883c96e122b12bfebc6975705962e07 (patch)
treecddf8e88aee97ffe791ebaf5a5243d2346d8450d /src/search.h
v2 initial commit
Diffstat (limited to 'src/search.h')
-rw-r--r--src/search.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/search.h b/src/search.h
new file mode 100644
index 0000000..ebb98f3
--- /dev/null
+++ b/src/search.h
@@ -0,0 +1,64 @@
+#ifndef INCLUDE_SEARCH
+#define INCLUDE_SEARCH
+
+#define MAX_INPUT_LENGTH 4096
+#define MAX_ERROR_MESSAGE_LENGTH (MAX_INPUT_LENGTH)
+#define FILE_RESERVE_COUNT 100000
+#define ERROR_RESERVE_COUNT 100
+
+#include "array.h"
+#include "memory_bucket.h"
+#include "../utf8.h"
+
+typedef struct t_found_file
+{
+ utf8_int8_t *path;
+ int match_count;
+} found_file;
+
+typedef struct t_search_result
+{
+ // data
+ array files;
+ array matches;
+ int match_count;
+ int file_count;
+
+ // thread syncing
+ mutex mutex;
+ int completed_match_threads;
+ int done_finding_files;
+ int file_list_read_cursor;
+
+ // search query
+ utf8_int8_t *directory_to_search;
+ utf8_int8_t *search_text;
+ int max_thread_count;
+ int max_file_size;
+} search_result;
+
+typedef struct t_file_match
+{
+ found_file* file;
+ int line_nr;
+ int word_match_offset;
+ int word_match_length;
+ utf8_int8_t *line_info; // will be null when no match is found
+} file_match;
+
+typedef struct t_text_match
+{
+ int line_nr;
+ int word_offset;
+ int word_match_len;
+ char *line_start;
+ char *line_info;
+} text_match;
+
+array get_filters(char *pattern);
+int filter_matches(array *filters, char *string, char **matched_filter);
+int string_match(char *first, char *second);
+search_result *create_empty_search_result();
+bool string_contains_ex(char *text_to_search, char *text_to_find, array *text_matches);
+
+#endif \ No newline at end of file