From c91cc1bb721f71f9178525eba9b85483e77f61b9 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Thu, 8 May 2025 19:07:00 +0800 Subject: [PATCH] feat: remove FSearch integration and related files - Deleted FSearch related source and header files to streamline the project. - Updated CMake configuration to remove references to FSearch. - Adjusted searcher implementation to focus on the new file name searcher. Log: clean up project by removing obsolete FSearch integration --- .reuse/dep5 | 5 - 3rdparty/fsearch/array.c | 164 --- 3rdparty/fsearch/array.h | 59 - 3rdparty/fsearch/btree.c | 344 ----- 3rdparty/fsearch/btree.h | 97 -- 3rdparty/fsearch/database.c | 1030 ------------- 3rdparty/fsearch/database.h | 111 -- 3rdparty/fsearch/database_search.c | 847 ----------- 3rdparty/fsearch/database_search.h | 133 -- 3rdparty/fsearch/fsearch.c | 184 --- 3rdparty/fsearch/fsearch.h | 63 - 3rdparty/fsearch/fsearch_config.c | 590 -------- 3rdparty/fsearch/fsearch_config.h | 114 -- 3rdparty/fsearch/fsearch_limits.h | 26 - 3rdparty/fsearch/fsearch_thread_pool.c | 268 ---- 3rdparty/fsearch/fsearch_thread_pool.h | 65 - 3rdparty/fsearch/fsearch_utils.cpp | 31 - 3rdparty/fsearch/fsearch_utils.h | 18 - 3rdparty/fsearch/query.c | 60 - 3rdparty/fsearch/query.h | 46 - 3rdparty/fsearch/string_utils.c | 64 - 3rdparty/fsearch/string_utils.h | 32 - 3rdparty/fsearch/utf8.h | 1285 ----------------- LICENSES/GPL-2.0-or-later.txt | 117 -- debian/control | 1 - src/dde-grand-search-daemon/CMakeLists.txt | 46 +- .../configuration/configer.cpp | 56 +- .../maincontroller/maincontroller.cpp | 2 - .../searcher/file/filenameworker.cpp | 2 +- .../searcher/file/fssearcher.cpp | 163 --- .../searcher/file/fssearcher.h | 52 - .../searcher/file/fsworker.cpp | 310 ---- .../searcher/file/fsworker.h | 59 - .../searcher/searchergroup.cpp | 11 +- .../searcher/searchergroup_p.h | 9 +- src/global/builtinsearch.h | 2 - src/global/searchhelper.cpp | 12 +- src/grand-search/utils/utils.cpp | 9 +- 38 files changed, 25 insertions(+), 6462 deletions(-) delete mode 100644 3rdparty/fsearch/array.c delete mode 100644 3rdparty/fsearch/array.h delete mode 100644 3rdparty/fsearch/btree.c delete mode 100644 3rdparty/fsearch/btree.h delete mode 100644 3rdparty/fsearch/database.c delete mode 100644 3rdparty/fsearch/database.h delete mode 100644 3rdparty/fsearch/database_search.c delete mode 100644 3rdparty/fsearch/database_search.h delete mode 100644 3rdparty/fsearch/fsearch.c delete mode 100644 3rdparty/fsearch/fsearch.h delete mode 100644 3rdparty/fsearch/fsearch_config.c delete mode 100644 3rdparty/fsearch/fsearch_config.h delete mode 100644 3rdparty/fsearch/fsearch_limits.h delete mode 100644 3rdparty/fsearch/fsearch_thread_pool.c delete mode 100644 3rdparty/fsearch/fsearch_thread_pool.h delete mode 100644 3rdparty/fsearch/fsearch_utils.cpp delete mode 100644 3rdparty/fsearch/fsearch_utils.h delete mode 100644 3rdparty/fsearch/query.c delete mode 100644 3rdparty/fsearch/query.h delete mode 100644 3rdparty/fsearch/string_utils.c delete mode 100644 3rdparty/fsearch/string_utils.h delete mode 100644 3rdparty/fsearch/utf8.h delete mode 100644 LICENSES/GPL-2.0-or-later.txt delete mode 100644 src/dde-grand-search-daemon/searcher/file/fssearcher.cpp delete mode 100644 src/dde-grand-search-daemon/searcher/file/fssearcher.h delete mode 100644 src/dde-grand-search-daemon/searcher/file/fsworker.cpp delete mode 100644 src/dde-grand-search-daemon/searcher/file/fsworker.h diff --git a/.reuse/dep5 b/.reuse/dep5 index 860c5a31..30bbfbcc 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -63,11 +63,6 @@ Files: tests/cmake/modules/FindGMock.cmake Copyright: 2011 Matej Svec License: MIT -# fsearch -Files: 3rdparty/fsearch/* -Copyright: 2020 Christian Boxdörfer -License: GPL-2.0-or-later - # interfaces Files: 3rdparty/interfaces/* Copyright: 2017 The Qt Company Ltd. diff --git a/3rdparty/fsearch/array.c b/3rdparty/fsearch/array.c deleted file mode 100644 index 6197cd79..00000000 --- a/3rdparty/fsearch/array.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#include -#include -#include -#include -#include "array.h" -#include "btree.h" - -void -darray_clear (DynamicArray *array) -{ - assert (array != NULL); - if (array->num_items > 0) { - for (uint32_t i = 0; i < array->max_items; i++) { - if(*(array->data) != NULL) - array->data[i] = NULL; - else { - break; - } - } - } -} - -void -darray_free (DynamicArray *array) -{ - if (array == NULL) { - return; - } - - darray_clear (array); - if (array->data) { - free (array->data); - array->data = NULL; - } - free (array); - array = NULL; -} - -DynamicArray * -darray_new (size_t num_items) -{ - DynamicArray *new = calloc (1, sizeof (DynamicArray)); - assert (new != NULL); - - new->max_items = num_items; - new->num_items = 0; - - new->data = calloc (num_items, sizeof (void *)); - assert (new->data != NULL); - - return new; -} - -static void -darray_expand (DynamicArray *array, size_t min) -{ - assert (array != NULL); - assert (array->data != NULL); - - size_t old_max_items = array->max_items; - size_t expand_rate = MAX (array->max_items/2, min - old_max_items); - array->max_items += expand_rate; - - void *new_data = realloc (array->data, array->max_items * sizeof (void *)); - assert (new_data != NULL); - array->data = new_data; - memset (array->data + old_max_items, 0, expand_rate + 1); -} - -void -darray_set_item (DynamicArray *array, void *data, uint32_t idx) -{ - assert (array != NULL); - assert (array->data != NULL); - - if (idx >= array->max_items) { - darray_expand (array, idx + 1); - } - - array->data[idx] = data; - if (data != NULL) { - array->num_items++; - } -} - -void -darray_remove_item (DynamicArray *array, uint32_t idx) -{ - assert (array != NULL); - assert (array->data != NULL); - - if (idx >= array->max_items) { - return; - } - - array->data[idx] = NULL; - array->num_items--; -} - -void * -darray_get_item (DynamicArray *array, uint32_t idx) -{ -// assert (array != NULL); -// assert (array->data != NULL); - if(array==NULL) - { - return NULL; - } - if(array->data==NULL) - { - return NULL; - } - if (idx >= array->max_items) { - return NULL; - } - - return array->data[idx]; -} - -uint32_t -darray_get_num_items (DynamicArray *array) -{ - assert (array != NULL); - assert (array->data != NULL); - - return array->num_items; -} - -uint32_t -darray_get_size (DynamicArray *array) -{ - assert (array != NULL); - assert (array->data != NULL); - - return array->max_items; -} - -void -darray_sort (DynamicArray *array, int (*comp_func)(const void *, const void *)) -{ - assert (array != NULL); - assert (array->data != NULL); - assert (comp_func != NULL); - - qsort (array->data, array->num_items, sizeof (void *), comp_func); -} diff --git a/3rdparty/fsearch/array.h b/3rdparty/fsearch/array.h deleted file mode 100644 index 476e18fd..00000000 --- a/3rdparty/fsearch/array.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include - -struct _DynamicArray { - // number of items in array - uint32_t num_items; - // total size of array - uint32_t max_items; - // data - void **data; -}; -typedef struct _DynamicArray DynamicArray; - -void -darray_sort(DynamicArray *array, int (*comp_func)(const void *, const void *)); - -uint32_t -darray_get_size(DynamicArray *array); - -uint32_t -darray_get_num_items(DynamicArray *array); - -void * -darray_get_item(DynamicArray *array, uint32_t idx); - -void -darray_remove_item(DynamicArray *array, uint32_t idx); - -void -darray_set_item(DynamicArray *array, void *data, uint32_t idx); - -DynamicArray * -darray_new(size_t num_items); - -void -darray_free(DynamicArray *array); - -void -darray_clear(DynamicArray *array); diff --git a/3rdparty/fsearch/btree.c b/3rdparty/fsearch/btree.c deleted file mode 100644 index 763e4c19..00000000 --- a/3rdparty/fsearch/btree.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include "btree.h" -#include "string_utils.h" - -BTreeNode * -btree_node_new (const char *name, - const char *full_py_name, - const char *first_py_name, - time_t mtime, - off_t size, - uint32_t pos, - bool is_dir) -{ - BTreeNode *new = calloc (1, sizeof (BTreeNode)); - assert (new); - - new->parent = NULL; - new->children = NULL; - new->next = NULL; - - // data - new->name = strdup(name); - new->full_py_name = strdup(full_py_name); - new->first_py_name = strdup(first_py_name); - - new->mtime = mtime; - new->size = size; - new->pos = pos; - new->is_dir = is_dir; - - return new; -} - -static void -btree_node_data_free (BTreeNode *node) -{ - if (!node) { - return; - } - if (node->name) { - free (node->name); - node->name = NULL; - } - if (node->full_py_name) { - free (node->full_py_name); - node->full_py_name = NULL; - } - if (node->first_py_name) { - free (node->first_py_name); - node->first_py_name = NULL; - } - free (node); - node = NULL; -} - -static void -btree_nodes_free (BTreeNode *node) -{ - while (node) { - if (node->children) { - btree_nodes_free (node->children); - } - BTreeNode *next = node->next; - btree_node_data_free (node); - node = next; - } -} - -void -btree_node_unlink (BTreeNode *node) -{ - assert (node); - if (!node->parent) { - return; - } - BTreeNode *parent = node->parent; - if (parent->children == node) { - parent->children = node->next; - } - else { - BTreeNode *sibling = parent->children; - while (sibling->next != node) { - sibling = sibling->next; - } - sibling->next = node->next; - } - - node->parent = NULL; - node->next = NULL; -} - -void -btree_node_free (BTreeNode *node) -{ - if (!node) { - return; - } - if (node->parent) { - btree_node_unlink (node); - } - if (node->children) { - btree_nodes_free (node->children); - } - btree_node_data_free (node); -} - -BTreeNode * -btree_node_append (BTreeNode *parent, BTreeNode *node) -{ - assert (parent); - assert (node); - node->parent = parent; - node->next = NULL; - - if (!parent->children) { - parent->children = node; - return node; - } - BTreeNode *child = parent->children; - while (child->next) { - child = child->next; - } - child->next = node; - return node; -} - -BTreeNode * -btree_node_prepend (BTreeNode *parent, BTreeNode *node) -{ - assert (parent); - assert (node); - node->parent = parent; - node->next = parent->children; - parent->children = node; - return node; -} - -void -btree_node_remove (BTreeNode *node) -{ - btree_node_free (node); -} - -BTreeNode * -btree_node_get_root (BTreeNode *node) -{ - assert (node); - BTreeNode *root = node; - while (root->parent) { - root = root->parent; - } - return root; -} - -bool -btree_node_is_root (BTreeNode *node) -{ - return node->parent ? false : true; -} - -uint32_t -btree_node_depth (BTreeNode *node) -{ - uint32_t depth = 0; - BTreeNode *temp = node; - while (temp) { - depth++; - temp = temp->parent; - } - return depth; -} - -uint32_t -btree_node_n_children (BTreeNode *node) -{ - assert (node); - if (!node->children) { - return 0; - } - uint32_t num_children = 0; - BTreeNode *child = node->children; - while (child) { - child = child->next; - num_children++; - } - return num_children; -} - -bool -btree_node_has_children (BTreeNode *node) -{ - assert (node); - return node->children ? true : false; -} - -void -btree_node_children_foreach (BTreeNode *node, - void (*func)(BTreeNode *, void *), - void *data) -{ - if (!node) { - return; - } - BTreeNode *child = node->children; - while (child) { - func (child, data); - child = child->next; - } -} - -void -btree_node_count_nodes (BTreeNode *node, uint32_t *num_nodes) -{ - (*num_nodes)++; - if (node->children) { - BTreeNode *child = node->children; - while (child) { - btree_node_count_nodes (child, num_nodes); - child = child->next; - } - } -} - -uint32_t -btree_node_n_nodes (BTreeNode *node) -{ - if (!node) { - return 0; - } - uint32_t num_nodes = 0; - btree_node_count_nodes (node, &num_nodes); - return num_nodes; -} - -void -btree_node_traverse_cb (BTreeNode *node, - bool (*func)(BTreeNode *, void *), - void *data) -{ - func (node, data); - if (node->children) { - BTreeNode *child = node->children; - while (child) { - btree_node_traverse_cb (child, func, data); - child = child->next; - } - } -} - - -void -btree_node_traverse (BTreeNode *node, - bool (*func)(BTreeNode *, void *), - void *data) -{ - if (!node) { - return; - } - btree_node_traverse_cb (node, func, data); -} - -static bool -btree_node_build_path (BTreeNode *node, char *path, size_t path_len) -{ - if (!node) { - // empty node - return false; - } - if (btree_node_is_root (node)) { - if (strlen (node->name) == 0) { - strncpy (path, "/", path_len); - } - else { - strncpy (path, node->name, path_len); - } - return true; - } - - const int32_t depth = btree_node_depth (node); - char *parents[depth + 1]; - parents[depth] = NULL; - - BTreeNode *temp = node; - for (int32_t i = depth - 1; i >= 0 && temp; i--) { - parents[i] = temp->name; - temp = temp->parent; - } - - char *ptr = path; - char *end = &path[path_len - 1]; - - uint32_t counter = 0; - ptr = fs_str_copy (ptr, end, parents[counter++]); - - char *item = parents[counter++]; - while (item && ptr != end) { - ptr = fs_str_copy (ptr, end, "/"); - ptr = fs_str_copy (ptr, end, item); - item = parents[counter++]; - } - return true; -} - -bool -btree_node_get_path (BTreeNode *node, char *path, size_t path_len) -{ - if (!node) { - // empty node - return false; - } - return btree_node_build_path (node->parent, path, path_len); -} - -bool -btree_node_get_path_full (BTreeNode *node, char *path, size_t path_len) -{ - if (!node) { - // empty node - return false; - } - return btree_node_build_path (node, path, path_len); -} diff --git a/3rdparty/fsearch/btree.h b/3rdparty/fsearch/btree.h deleted file mode 100644 index 6c3a294f..00000000 --- a/3rdparty/fsearch/btree.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include -#include - -typedef struct _BTreeNode BTreeNode; - -struct _BTreeNode { - BTreeNode *next; - BTreeNode *parent; - BTreeNode *children; - - // data - char *name; - char *full_py_name; - char *first_py_name; - - time_t mtime; - off_t size; - uint32_t pos; - bool is_dir; -}; - -BTreeNode * -btree_node_new(const char *name, - const char *full_py_name, - const char *first_py_name, - time_t mtime, - off_t size, - uint32_t pos, - bool is_dir); - -void -btree_node_free(BTreeNode *node); - -void -btree_node_unlink(BTreeNode *node); - -BTreeNode * -btree_node_append(BTreeNode *parent, BTreeNode *node); - -BTreeNode * -btree_node_prepend(BTreeNode *parent, BTreeNode *node); - -void -btree_node_remove(BTreeNode *node); - -BTreeNode * -btree_node_get_root(BTreeNode *node); - -bool -btree_node_is_root(BTreeNode *node); - -uint32_t -btree_node_n_nodes(BTreeNode *node); - -uint32_t -btree_node_depth(BTreeNode *node); - -uint32_t -btree_node_n_children(BTreeNode *node); - -bool -btree_node_has_children(BTreeNode *node); - -void -btree_node_children_foreach(BTreeNode *node, - void (*func)(BTreeNode *, void *), - void *data); -void -btree_node_traverse(BTreeNode *node, - bool (*func)(BTreeNode *, void *), - void *data); -bool -btree_node_get_path(BTreeNode *node, char *path, size_t path_len); - -bool -btree_node_get_path_full(BTreeNode *node, char *path, size_t path_len); diff --git a/3rdparty/fsearch/database.c b/3rdparty/fsearch/database.c deleted file mode 100644 index 527e7f92..00000000 --- a/3rdparty/fsearch/database.c +++ /dev/null @@ -1,1030 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "database.h" -#include "fsearch_config.h" -#include "fsearch.h" -#include "fsearch_utils.h" - -//#define WS_FOLLOWLINK (1 << 1) /* follow symlinks */ -#define WS_DOTFILES (1 << 2) /* per unix convention, .file is hidden */ - -// add py index,update database version to 1.0 -#define DATABASE_MAJOR_VERSION 1 -#define DATABASE_MINOR_VERSION 0 - - -struct _DatabaseLocation -{ - // B+ tree of entry nodes - BTreeNode *entries; - uint32_t num_items; -}; - -enum { - WALK_OK = 0, - WALK_BADPATTERN, - WALK_NAMETOOLONG, - WALK_BADIO, -}; - -// Forward declarations -static void -db_entries_clear (Database *db); - -static DatabaseLocation * -db_location_get_for_path (Database *db, const char *path); - -static DatabaseLocation * -db_location_build_tree (const char *dname, void (*callback)(const char *)); - -static DatabaseLocation * -db_location_new (void); - -static void -db_list_add_location (Database *db, DatabaseLocation *location); - -// Implemenation - -static void -db_update_timestamp (Database *db) -{ - assert (db != NULL); - db->timestamp = time(NULL); -} - -DatabaseLocation * -db_location_load_from_file (const char *fname) -{ - assert (fname != NULL); - - FILE *fp = fopen (fname, "rb"); - if (!fp) { - return NULL; - } - - BTreeNode *root = NULL; - - char magic[4]; - if (fread (magic, 1, 4, fp) != 4) { - printf ("failed to read magic\n"); - goto load_fail; - } - if (strncmp (magic, "FSDB", 4)) { - printf ("bad signature\n"); - goto load_fail; - } - - uint8_t majorver = 0; - if (fread (&majorver, 1, 1, fp) != 1) { - goto load_fail; - } - - if (majorver != DATABASE_MAJOR_VERSION) { - printf ("bad majorver=%d\n", majorver); - goto load_fail; - } - - uint8_t minorver = 0; - if (fread (&minorver, 1, 1, fp) != 1) { - goto load_fail; - } - - if (minorver != DATABASE_MINOR_VERSION) { - printf ("bad minorver=%d\n", minorver); - goto load_fail; - } - printf ("database version=%d.%d\n", majorver, minorver); - - uint32_t num_items = 0; - if (fread (&num_items, 1, 4, fp) != 4) { - goto load_fail; - } - - uint32_t num_items_read = 0; - BTreeNode *prev = NULL; - while (true) { - uint16_t name_len = 0; - if (fread (&name_len, 1, 2, fp) != 2) { - printf("failed to read name length\n"); - goto load_fail; - } - - if (name_len == 0) { - // reached end of child marker - if (!prev) { - goto load_fail; - } - prev = prev->parent; - if (!prev) { - // prev was root node, we're done - printf("reached root node. done\n"); - break; - } - continue; - } - - // read name - char name[name_len + 1]; - if (fread (&name, 1, name_len, fp) != name_len) { - printf("failed to read name\n"); - goto load_fail; - } - name[name_len] = '\0'; - - // read full pinyin - uint16_t full_py_len = 0; - if (fread (&full_py_len, 1, 2, fp) != 2) { - printf("failed to read full pinyin name length\n"); - goto load_fail; - } - char full_py_name[full_py_len + 1]; - if (full_py_len && fread (&full_py_name, 1, full_py_len, fp) != full_py_len) { - printf("failed to read full pinyin name\n"); - goto load_fail; - } - full_py_name[full_py_len] = '\0'; - - // read first pinyin name - uint16_t first_py_len = 0; - if (fread (&first_py_len, 1, 2, fp) != 2) { - printf("failed to read first pinyin name length\n"); - goto load_fail; - } - char first_py_name[first_py_len + 1]; - if (first_py_len && fread (&first_py_name, 1, first_py_len, fp) != first_py_len) { - printf("failed to read first pinyin name\n"); - goto load_fail; - } - first_py_name[first_py_len] = '\0'; - - // read is_dir - uint8_t is_dir = 0; - if (fread (&is_dir, 1, 1, fp) != 1) { - printf("failed to read is_dir\n"); - goto load_fail; - } - - // read size - uint64_t size = 0; - if (fread (&size, 1, 8, fp) != 8) { - printf("failed to read size\n"); - goto load_fail; - } - - // read mtime - uint64_t mtime = 0; - if (fread (&mtime, 1, 8, fp) != 8) { - printf("failed to read mtime\n"); - goto load_fail; - } - - // read mtime - uint32_t pos = 0; - if (fread (&pos, 1, 4, fp) != 4) { - printf("failed to read sort position\n"); - goto load_fail; - } - - int is_root = !strcmp (name, "/"); - BTreeNode *new = btree_node_new (is_root ? "" : name, - is_root ? "" : full_py_name, - is_root ? "" : first_py_name, - mtime, - size, - pos, - is_dir); - if (!prev) { - prev = new; - root = new; - continue; - } - prev = btree_node_prepend (prev, new); - num_items_read++; - } -// trace ("read database: %d/%d\n", num_items_read, num_items); - - DatabaseLocation *location = db_location_new (); - location->num_items = num_items_read; - location->entries = root; - - fclose (fp); - - return location; - -load_fail: - fprintf (stderr, "database load fail (%s)!\n", fname); - if (fp) { - fclose (fp); - } - if (root) { - btree_node_free (root); - } - return NULL; -} - -bool -db_location_write_to_file (DatabaseLocation *location, const char *path) -{ - assert (path != NULL); - assert (location != NULL); - - if (!location->entries) { - return false; - } - g_mkdir_with_parents (path, 0700); - - gchar tempfile[PATH_MAX] = ""; - snprintf (tempfile, sizeof (tempfile), "%s/database.db", path); - - FILE *fp = fopen (tempfile, "w+b"); - if (!fp) { - return false; - } - - const char magic[] = "FSDB"; - if (fwrite (magic, 1, 4, fp) != 4 ) { - goto save_fail; - } - - const uint8_t majorver = DATABASE_MAJOR_VERSION; - if (fwrite (&majorver, 1, 1, fp) != 1) { - goto save_fail; - } - - const uint8_t minorver = DATABASE_MINOR_VERSION; - if (fwrite (&minorver, 1, 1, fp) != 1) { - goto save_fail; - } - - uint32_t num_items = btree_node_n_nodes (location->entries); - if (fwrite (&num_items, 1, 4, fp) != 4) { - goto save_fail; - } - - const uint16_t del = 0; - - BTreeNode *root = location->entries; - BTreeNode *node = root; - uint32_t is_root = !strcmp (root->name, ""); - - while (node) { - const char *name = is_root ? "/" : node->name; - is_root = 0; - uint16_t len = (uint16_t)strlen (name); - uint16_t full_py_len = (uint16_t)strlen (node->full_py_name); - uint16_t first_py_len = (uint16_t)strlen (node->first_py_name); - if (len) { - // write length of node name - if (fwrite (&len, 1, 2, fp) != 2) { - goto save_fail; - } - // write node name - if (fwrite (name, 1, len, fp) != len) { - goto save_fail; - } - // write length of node full pinyin name - if (fwrite (&full_py_len, 1, 2, fp) != 2) { - goto save_fail; - } - // write node full pinyin name - if (full_py_len && fwrite (node->full_py_name, 1, full_py_len, fp) != full_py_len) { - goto save_fail; - } - // write length of node first pinyin name - if (fwrite (&first_py_len, 1, 2, fp) != 2) { - goto save_fail; - } - // write node first pinyin name - if (first_py_len && fwrite (node->first_py_name, 1, first_py_len, fp) != first_py_len) { - goto save_fail; - } - - // write node name - uint8_t is_dir = node->is_dir; - if (fwrite (&is_dir, 1, 1, fp) != 1) { - goto save_fail; - } - - // write node name - uint64_t size = node->size; - if (fwrite (&size, 1, 8, fp) != 8) { - goto save_fail; - } - - // write node name - uint64_t mtime = node->mtime; - if (fwrite (&mtime, 1, 8, fp) != 8) { - goto save_fail; - } - - // write node name - uint32_t pos = node->pos; - if (fwrite (&pos, 1, 4, fp) != 4) { - goto save_fail; - } - - BTreeNode *temp = node->children; - if (!temp) { - // reached end of children, write delimiter - if (fwrite (&del, 1, 2, fp) != 2) { - goto save_fail; - } - BTreeNode *current = node; - while (true) { - temp = current->next; - if (temp) { - // found next, sibling add that - node = temp; - break; - } - - if (fwrite (&del, 1, 2, fp) != 2) { - goto save_fail; - } - temp = current->parent; - if (!temp) { - // reached last node, abort - node = NULL; - break; - } - else { - current = temp; - } - } - } - else { - node = temp; - } - } - else { - goto save_fail; - } - - } - - fclose (fp); - return true; - -save_fail: - - fclose (fp); - unlink (tempfile); - return false; -} - -static bool -file_is_excluded (const char *name, char **exclude_files) -{ - if (exclude_files) { - for (int i = 0; exclude_files[i]; ++i) { - if (!fnmatch (exclude_files[i], name, 0)) { - return true; - } - } - } - return false; -} - -static bool -directory_is_excluded (const char *name, GList *excludes) -{ - while (excludes) { - if (!strcmp (name, excludes->data)) { - return true; - } - excludes = excludes->next; - } - return false; -} - -static int -db_location_walk_tree_recursive (DatabaseLocation *location, - GList *excludes, - char **exclude_files, - const char *dname, - GTimer *timer, - void (*callback)(const char *), - BTreeNode *parent, - int spec) -{ - int len = strlen (dname); - if (len >= FILENAME_MAX - 1) { - //trace ("filename too long: %s\n", dname); - return WALK_NAMETOOLONG; - } - - char fn[FILENAME_MAX] = ""; - strcpy (fn, dname); - if (strcmp (dname, "/")) { - // TODO: use a more performant fix to handle root directory - fn[len++] = '/'; - } - - DIR *dir = NULL; - if (!(dir = opendir (dname))) { - //trace ("can't open: %s\n", dname); - return WALK_BADIO; - } - gulong duration = 0; - g_timer_elapsed (timer, &duration); - - if (duration > 100000) { - if (callback) { - callback (dname); - } - g_timer_reset (timer); - } - - struct dirent *dent = NULL; - while ((dent = readdir (dir))) { - if (!strcmp (dent->d_name, ".") || !strcmp (dent->d_name, "..") || dent->d_name[0] == '.') { - continue; - } - - if (file_is_excluded (dent->d_name, exclude_files)) { - //trace ("excluded file: %s\n", dent->d_name); - continue; - } - - struct stat st; - strncpy (fn + len, dent->d_name, FILENAME_MAX - len); - if (lstat (fn, &st) == -1) { - //warn("Can't stat %s", fn); - continue; - } - - if (directory_is_excluded (fn, excludes)) { -// trace ("excluded directory: %s\n", fn); - continue; - } - - const bool is_dir = S_ISDIR (st.st_mode); - char full_py_name[FILENAME_MAX] = ""; - char first_py_name[FILENAME_MAX] = ""; - convert_chinese_2_pinyin(dent->d_name, first_py_name, full_py_name); - BTreeNode *node = btree_node_new (dent->d_name, - full_py_name, - first_py_name, - st.st_mtime, - st.st_size, - 0, - is_dir); - btree_node_prepend (parent, node); - location->num_items++; - if (is_dir) { - db_location_walk_tree_recursive (location, - excludes, - exclude_files, - fn, - timer, - callback, - node, - spec); - - } - } - - if (dir) { - closedir (dir); - } - return WALK_OK; -} - -static DatabaseLocation * -db_location_build_tree (const char *dname, void (*callback)(const char *)) -{ - const char *root_name = NULL; - if (!strcmp (dname, "/")) { - root_name = ""; - } - else { - root_name = dname; - } - BTreeNode *root = btree_node_new (root_name, "", "", 0, 0, 0, true); - DatabaseLocation *location = db_location_new (); - location->entries = root; - FsearchConfig *config = (FsearchConfig *)(calloc(1, sizeof(FsearchConfig))); - config_load_default(config); - - int spec = 0; - if (!config->exclude_hidden_items) { - spec |= WS_DOTFILES; - } - GTimer *timer = g_timer_new (); - g_timer_start (timer); - uint32_t res = db_location_walk_tree_recursive (location, - config->exclude_locations, - config->exclude_files, - dname, - timer, - callback, - root, - spec); - config_free(config); - g_timer_destroy (timer); - if (res == WALK_OK) { - return location; - } - else { -// trace ("walk error: %d", res); - db_location_free (location); - } - return NULL; -} - -static DatabaseLocation * -db_location_new (void) -{ - DatabaseLocation *location = g_new0 (DatabaseLocation, 1); - return location; -} - -bool -db_list_insert_node (BTreeNode *node, void *data) -{ - Database *db = data; - darray_set_item (db->entries, node, node->pos); - db->num_entries++; - return true; -} - -static void -db_traverse_tree_insert (BTreeNode *node, void *data) -{ - btree_node_traverse (node, db_list_insert_node, data); -} - -static uint32_t temp_index = 0; - -bool -db_list_add_node (BTreeNode *node, void *data) -{ - Database *db = data; - darray_set_item (db->entries, node, temp_index++); - db->num_entries++; - return true; -} - -static void -db_traverse_tree_add (BTreeNode *node, void *data) -{ - btree_node_traverse (node, db_list_add_node, data); -} - -static void -db_list_insert_location (Database *db, DatabaseLocation *location) -{ - assert (db != NULL); - assert (location != NULL); - assert (location->entries != NULL); - - btree_node_children_foreach (location->entries, db_traverse_tree_insert, db); -} - - -static void -db_list_add_location (Database *db, DatabaseLocation *location) -{ - assert (db != NULL); - assert (location != NULL); - assert (location->entries != NULL); - - btree_node_children_foreach (location->entries, db_traverse_tree_add, db); -} - -static DatabaseLocation * -db_location_get_for_path (Database *db, const char *path) -{ - assert (db != NULL); - assert (path != NULL); - - GList *locations = db->locations; - for (GList *l = locations; l != NULL; l = l->next) { - DatabaseLocation *location = (DatabaseLocation *)l->data; - BTreeNode *root = btree_node_get_root (location->entries); - const char *location_path = root->name; - if (!strcmp (location_path, path)) { - return location; - } - } - return NULL; -} - -void -db_location_free (DatabaseLocation *location) -{ - assert (location != NULL); - - if (location->entries) { - btree_node_free (location->entries); - location->entries = NULL; - } - g_free (location); - location = NULL; -} - -bool -db_location_remove (Database *db, const char *path) -{ - assert (db != NULL); - assert (path != NULL); - - DatabaseLocation *location = db_location_get_for_path (db, path); - if (location) { - db->locations = g_list_remove (db->locations, location); - db_location_free (location); - db_sort (db); - } - - return true; -} - -static void -location_build_path (char *path, size_t path_len, const char *location_name) -{ - assert (path != NULL); - assert (location_name != NULL); - -// char const *location = !strcmp (location_name, "") ? "/" : location_name; - -// gchar *path_checksum = g_compute_checksum_for_string (G_CHECKSUM_SHA256, -// location, -// -1); -// assert (path_checksum != NULL); - - gchar config_dir[PATH_MAX] = ""; -// config_build_dir (config_dir, sizeof (config_dir)); - database_build_dir(config_dir, sizeof (config_dir)); - - assert (0 <= snprintf (path, path_len, "%s/database", config_dir)); -// g_free (path_checksum); - return; -} - -void -db_location_delete (DatabaseLocation *location, const char *location_name) -{ - assert (location != NULL); - assert (location_name != NULL); - - gchar database_path[PATH_MAX] = ""; - location_build_path (database_path, - sizeof (database_path), - location_name); - - gchar database_file_path[PATH_MAX] = ""; - assert (0 <= snprintf (database_file_path, sizeof (database_file_path), "%s/%s", database_path, "database.db")); - - g_remove (database_file_path); - g_remove (database_path); -} - -bool -db_save_location (Database *db, const char *location_name) -{ - assert (db != NULL); - - gchar database_path[PATH_MAX] = ""; - location_build_path (database_path, - sizeof (database_path), - location_name); -// trace ("%s\n", database_path); - - gchar database_fname[PATH_MAX] = ""; - assert (0 <= snprintf (database_fname, sizeof (database_fname), "%s/database.db", database_path)); - DatabaseLocation *location = db_location_get_for_path (db, location_name); - if (location) { - db_location_write_to_file (location, database_path); - } - - return true; -} - -bool -db_save_locations (Database *db) -{ - assert (db != NULL); - g_return_val_if_fail (db->locations != NULL, false); - - //db_update_sort_index (db); - GList *locations = db->locations; - for (GList *l = locations; l != NULL; l = l->next) { - DatabaseLocation *location = (DatabaseLocation *)l->data; - BTreeNode *root = btree_node_get_root (location->entries); - const char *location_path = root->name; - db_save_location (db, location_path); - } - return true; -} - -static gchar * -db_location_get_path (const char *location_name) -{ - gchar database_path[PATH_MAX] = ""; - location_build_path (database_path, - sizeof (database_path), - location_name); -// trace ("%s\n", database_path); - - gchar database_fname[PATH_MAX] = ""; - assert (0 <= snprintf (database_fname, sizeof (database_fname), "%s/database.db", database_path)); - - return g_strdup (database_fname); -} - -bool -db_location_load (Database *db, const char *location_name) -{ - db_lock (db); - gchar *load_path = db_location_get_path (location_name); - if (!load_path) { - db_unlock (db); - return false; - } - DatabaseLocation *location = db_location_load_from_file (load_path); - g_free (load_path); - load_path = NULL; - - if (location) { - location->num_items = btree_node_n_nodes (location->entries); -// trace ("number of nodes: %d\n", location->num_items); - db->locations = g_list_append (db->locations, location); - db->num_entries += location->num_items; - db_update_timestamp (db); - db_unlock (db); - return true; - } - db_update_timestamp (db); - db_unlock (db); - return false; -} - -bool -db_location_add (Database *db, - const char *location_name, - void (*callback)(const char *)) -{ - assert (db != NULL); - db_lock (db); -// printf ("load location: %s\n", location_name); - - DatabaseLocation *location = db_location_build_tree (location_name, callback); - - if (location) { -// printf ("location num entries: %d\n", location->num_items); - db->locations = g_list_append (db->locations, location); - db->num_entries += location->num_items; - db_update_timestamp (db); - db_unlock (db); - return true; - } - - db_update_timestamp (db); - db_unlock (db); - return false; -} - -void -db_update_sort_index (Database *db) -{ - assert (db != NULL); - assert (db->entries != NULL); - - for (uint32_t i = 0; i < db->num_entries; ++i) { - BTreeNode *node = darray_get_item (db->entries, i); - if (node) { - node->pos = i; - } - } -} - -static uint32_t -db_locations_get_num_entries (Database *db) -{ - assert (db != NULL); - assert (db->locations != NULL); - - uint32_t num_entries = 0; - GList *locations = db->locations; - for (GList *l = locations; l != NULL; l = l->next) { - DatabaseLocation *location = l->data; - num_entries += location->num_items; - } - return num_entries; -} - -void -db_build_initial_entries_list (Database *db) -{ - assert (db != NULL); - assert (db->num_entries >= 0); - - db_lock (db); - db_entries_clear (db); - uint32_t num_entries = db_locations_get_num_entries (db); - db->entries = darray_new (num_entries); - - GList *locations = db->locations; - temp_index = 0; - for (GList *l = locations; l != NULL; l = l->next) { - db_list_add_location (db, l->data); - } - db_sort (db); - db_update_sort_index (db); - db_unlock (db); -} - -void -db_update_entries_list (Database *db) -{ - assert (db != NULL); - assert (db->num_entries >= 0); - - db_lock (db); - db_entries_clear (db); - uint32_t num_entries = db_locations_get_num_entries (db); -// trace ("update list: %d\n", num_entries); - db->entries = darray_new (num_entries); - - GList *locations = db->locations; - for (GList *l = locations; l != NULL; l = l->next) { - db_list_insert_location (db, l->data); - } - db_unlock (db); -} - -BTreeNode * -db_location_get_entries (DatabaseLocation *location) -{ - assert (location != NULL); - return location->entries; -} - -Database * -db_new () -{ - Database *db = g_new0 (Database, 1); - g_mutex_init (&db->mutex); - return db; -} - -static void -db_entries_clear (Database *db) -{ - // free entries - assert (db != NULL); - - if (db->entries) { - darray_free (db->entries); - db->entries = NULL; - } - db->num_entries = 0; -} - -void -db_free (Database *db) -{ - assert (db != NULL); - - db_entries_clear (db); - g_mutex_clear (&db->mutex); - g_free (db); - db = NULL; - return; -} - -time_t -db_get_timestamp (Database *db) -{ - assert (db != NULL); - return db->timestamp; -} - -uint32_t -db_get_num_entries (Database *db) -{ - assert (db != NULL); - return db->num_entries; -} - -void -db_unlock (Database *db) -{ - assert (db != NULL); - g_mutex_unlock (&db->mutex); -} - -void -db_lock (Database *db) -{ - assert (db != NULL); - g_mutex_lock (&db->mutex); -} - -bool -db_try_lock (Database *db) -{ - assert (db != NULL); - return g_mutex_trylock (&db->mutex); -} - -DynamicArray * -db_get_entries (Database *db) -{ - assert (db != NULL); - return db->entries; -} - -static int -sort_by_name (const void *a, const void *b) -{ - BTreeNode *node_a = *(BTreeNode **)a; - BTreeNode *node_b = *(BTreeNode **)b; - - if(!node_a) { - return -1; - } - if (!node_b) { - return 1; - } - - const bool is_dir_a = node_a->is_dir; - const bool is_dir_b = node_b->is_dir; - if (is_dir_a != is_dir_b) { - return is_dir_a ? -1 : 1; - } - - return strverscmp (node_a->name, node_b->name); -} - -void -db_sort (Database *db) -{ - assert (db != NULL); - assert (db->entries != NULL); - -// trace ("start sorting\n"); - darray_sort (db->entries, sort_by_name); -// trace ("finished sorting\n"); -} - -static void -db_location_free_all (Database *db) -{ - assert (db != NULL); - g_return_if_fail (db->locations != NULL); - - GList *l = db->locations; - while (l) { -// trace ("free location\n"); - db_location_free (l->data); - l = l->next; - } - g_list_free (db->locations); - db->locations = NULL; -} - -bool -db_clear (Database *db) -{ - assert (db != NULL); - -// trace ("clear locations\n"); - db_entries_clear (db); - db_location_free_all (db); - return true; -} - diff --git a/3rdparty/fsearch/database.h b/3rdparty/fsearch/database.h deleted file mode 100644 index b11b4034..00000000 --- a/3rdparty/fsearch/database.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include -#include -#include "array.h" -#include "btree.h" - -struct _Database -{ - GList *locations; - GList *searches; - DynamicArray *entries; - uint32_t num_entries; - - time_t timestamp; - - GMutex mutex; -}; -typedef struct _Database Database; - -typedef struct _DatabaseLocation DatabaseLocation; - -typedef struct _FsearchConfig FsearchConfig; - -void -db_location_free(DatabaseLocation *location); - -bool -db_location_load(Database *db, const char *location_name); - -bool -db_location_add(Database *db, - const char *location_name, - void (*callback)(const char *)); - -bool -db_location_remove(Database *db, const char *path); - -bool -db_location_write_to_file(DatabaseLocation *location, const char *fname); - -BTreeNode * -db_location_get_entries(DatabaseLocation *location); - -void -db_free(Database *db); - -Database * -db_new(); - -Database * -db_copy(const Database *db); - -gboolean -db_list_append_node(BTreeNode *node, - gpointer data); - -void -db_update_sort_index(Database *db); - -bool -db_save_locations(Database *db); - -void -db_update_entries_list(Database *db); - -void -db_build_initial_entries_list(Database *db); - -time_t -db_get_timestamp(Database *db); - -uint32_t -db_get_num_entries(Database *db); - -void -db_unlock(Database *db); - -void -db_lock(Database *db); - -bool -db_try_lock(Database *db); - -DynamicArray * -db_get_entries(Database *db); - -void -db_sort(Database *db); - -bool -db_clear(Database *db); diff --git a/3rdparty/fsearch/database_search.c b/3rdparty/fsearch/database_search.c deleted file mode 100644 index 5ba70e98..00000000 --- a/3rdparty/fsearch/database_search.c +++ /dev/null @@ -1,847 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "database_search.h" -#include "string_utils.h" -#include "query.h" -//#include "debug.h" -#include "utf8.h" - -#define OVECCOUNT 3 - - - -typedef struct search_query_s { - char *query; - uint32_t (*search_func)(const char *, const char *); - size_t query_len; - uint32_t has_uppercase; - uint32_t has_separator; - uint32_t is_utf8; - //uint32_t found; -} search_query_t; - -typedef struct search_context_s { - DatabaseSearch *search; - BTreeNode **results; - search_query_t **queries; - uint32_t num_queries; - uint32_t num_results; - uint32_t start_pos; - uint32_t end_pos; -} search_thread_context_t; - -DatabaseSearchResult * -db_search (DatabaseSearch *search, FsearchQuery *q); - -static DatabaseSearchResult * -db_search_empty (DatabaseSearch *search); - -DatabaseSearchEntry * -db_search_entry_new (BTreeNode *node, uint32_t pos); - -static void -db_search_entry_free (DatabaseSearchEntry *entry); - -static gpointer -fsearch_search_thread (gpointer user_data) -{ - DatabaseSearch *search = user_data; - - g_mutex_lock (&search->query_mutex); - while (true) { - search->search_thread_started = true; - g_cond_wait (&search->search_thread_start_cond, &search->query_mutex); - printf("---------------------------g_cond_wait (&search->search_thread_start_cond)\n"); - if (search->search_thread_terminate) { - break; - } - while (true) { - FsearchQuery *query = search->query_ctx; - if (!query) { - break; - } - search->query_ctx = NULL; - g_mutex_unlock (&search->query_mutex); - // if query is empty string we are done here - DatabaseSearchResult *result = NULL; - if (fs_str_is_empty (query->query)) { - if (!search->hide_results) { - result = db_search_empty (search); - } - else { - result = calloc (1, sizeof (DatabaseSearchResult)); - } - } - else { - result = db_search (search, query); - } - result->cb_data = query->callback_data; - query->callback (result, query->sender); - printf("+++++++++++++++++++++++++++++++++++++++++++query->callback\n"); - - //free - if (result->results) - g_ptr_array_free(result->results, TRUE); - free(result); - result = NULL; - - fsearch_query_free (query); - g_mutex_lock (&search->query_mutex); - } - } - g_mutex_unlock (&search->query_mutex); - return NULL; -} - - -static search_thread_context_t * -search_thread_context_new (DatabaseSearch *search, - search_query_t **queries, - uint32_t num_queries, - uint32_t start_pos, - uint32_t end_pos) -{ - search_thread_context_t *ctx = calloc (1, sizeof(search_thread_context_t)); - assert (ctx != NULL); - assert (end_pos >= start_pos); - - ctx->search = search; - ctx->queries = queries; - ctx->num_queries = num_queries; - ctx->results = calloc (end_pos - start_pos + 1, sizeof (BTreeNode *)); - assert (ctx->results != NULL); - - ctx->num_results = 0; - ctx->start_pos = start_pos; - ctx->end_pos = end_pos; - return ctx; -} - -static inline bool -filter_node (BTreeNode *node, FsearchFilter filter) -{ - if (filter == FSEARCH_FILTER_NONE) { - return true; - } - bool is_dir = node->is_dir; - if (filter == FSEARCH_FILTER_FILES - && !is_dir) { - return true; - } - if (filter == FSEARCH_FILTER_FOLDERS - && is_dir) { - return true; - } - return false; -} - -static void * -search_thread (void * user_data) -{ - search_thread_context_t *ctx = (search_thread_context_t *)user_data; -// assert (ctx != NULL); -// assert (ctx->results != NULL); - if(ctx==NULL) - { - return NULL; - } - if(ctx->results==NULL) - { - return NULL; - } - const uint32_t start = ctx->start_pos; - const uint32_t end = ctx->end_pos; - const uint32_t max_results = ctx->search->max_results; - const uint32_t num_queries = ctx->num_queries; - const FsearchFilter filter = ctx->search->filter; - search_query_t **queries = ctx->queries; - const uint32_t search_in_path = ctx->search->search_in_path; - const uint32_t auto_search_in_path = ctx->search->auto_search_in_path; - DynamicArray *entries = ctx->search->entries; - BTreeNode **results = ctx->results; - - uint32_t num_results = 0; - char full_path[PATH_MAX] = ""; - for (uint32_t i = start; i <= end; i++) { - if (max_results && num_results == max_results) { - break; - } - BTreeNode *node = darray_get_item (entries, i); - if (!node) { - continue; - } - if (!filter_node (node, filter)) { - continue; - } - - const char *haystack_path = NULL; - const char *haystack_name = node->name; - if (search_in_path) { - btree_node_get_path_full (node, full_path, sizeof (full_path)); - haystack_path = full_path; - } - - uint32_t num_found = 0; - while (true) { - if (num_found == num_queries) { - results[num_results] = node; - num_results++; - break; - } - search_query_t *query = queries[num_found++]; - if (!query) { - break; - } - char *ptr = query->query; - uint32_t (*search_func)(const char *, const char *) = query->search_func; - - const char *haystack = NULL; - if (search_in_path || (auto_search_in_path && query->has_separator)) { - if (!haystack_path) { - btree_node_get_path_full (node, full_path, sizeof (full_path)); - haystack_path = full_path; - } - haystack = haystack_path; - } - else { - haystack = haystack_name; - } - if (!search_func (haystack, ptr)) { - if (strlen(node->full_py_name)) { - // search first pinyin - if (!search_func (node->first_py_name, ptr)) { - // search full pinyin - if (!search_func (node->full_py_name, ptr)) { - break; - } - } - } else { - break; - } - } - } - - } - ctx->num_results = num_results; - return NULL; -} - -#ifdef DEBUG -static struct timeval tm1; -#endif - -static inline void timer_start() -{ -#ifdef DEBUG - gettimeofday(&tm1, NULL); -#endif -} - -static inline void timer_stop() -{ -#ifdef DEBUG - struct timeval tm2; - gettimeofday(&tm2, NULL); - - unsigned long long t = 1000 * (tm2.tv_sec - tm1.tv_sec) + (tm2.tv_usec - tm1.tv_usec) / 1000; - trace ("%llu ms\n", t); -#endif -} - -static void * -search_regex_thread (void * user_data) -{ - search_thread_context_t *ctx = (search_thread_context_t *)user_data; - assert (ctx != NULL); - assert (ctx->results != NULL); - - search_query_t **queries = ctx->queries; - search_query_t *query = queries[0]; - const char *error; - int erroffset; - pcre *regex = pcre_compile (query->query, - ctx->search->match_case ? 0 : PCRE_CASELESS, - &error, - &erroffset, - NULL); - - int ovector[OVECCOUNT]; - - if (regex) { - const uint32_t start = ctx->start_pos; - const uint32_t end = ctx->end_pos; - const uint32_t max_results = ctx->search->max_results; - const bool search_in_path = ctx->search->search_in_path; - const bool auto_search_in_path = ctx->search->auto_search_in_path; - DynamicArray *entries = ctx->search->entries; - BTreeNode **results = ctx->results; - const FsearchFilter filter = ctx->search->filter; - - uint32_t num_results = 0; - char full_path[PATH_MAX] = ""; - for (uint32_t i = start; i <= end; ++i) { - if (max_results && num_results == max_results) { - break; - } - BTreeNode *node = darray_get_item (entries, i); - if (!node) { - continue; - } - - if (!filter_node (node, filter)) { - continue; - } - - const char *haystack = NULL; - if (search_in_path || (auto_search_in_path && query->has_separator)) { - btree_node_get_path_full (node, full_path, sizeof (full_path)); - haystack = full_path; - } - else { - haystack = node->name; - } - size_t haystack_len = strlen (haystack); - - if (pcre_exec (regex, NULL, haystack, haystack_len, - 0, 0, ovector, OVECCOUNT) >= 0) { - results[num_results] = node; - num_results++; - } else if (strlen(node->full_py_name)) { - if (pcre_exec(regex, NULL, node->first_py_name, strlen(node->first_py_name), - 0, 0, ovector, OVECCOUNT) >= 0) { - results[num_results] = node; - num_results++; - } else if (pcre_exec(regex, NULL, node->full_py_name, strlen(node->full_py_name), - 0, 0, ovector, OVECCOUNT) >= 0) { - results[num_results] = node; - num_results++; - } - } - } - ctx->num_results = num_results; - pcre_free (regex); - } - return NULL; -} - -static int -is_regex (const char *query) -{ - char regex_chars[] = { - '$', - '(', - ')', - '*', - '+', - '.', - '?', - '[', - '\\', - '^', - '{', - '|', - '\0' - }; - - return (strpbrk(query, regex_chars) != NULL); -} - -static uint32_t -search_wildcard_icase (const char *haystack, const char *needle) -{ - return !fnmatch (needle, haystack, FNM_CASEFOLD) ? 1 : 0; -} - -static uint32_t -search_wildcard (const char *haystack, const char *needle) -{ - return !fnmatch (needle, haystack, 0) ? 1 : 0; -} - -static uint32_t -search_normal_icase_u8 (const char *haystack, const char *needle) -{ - // TODO: make this faster - return utf8casestr (haystack, needle) ? 1 : 0; -} - -static uint32_t -search_normal_icase (const char *haystack, const char *needle) -{ - return strcasestr (haystack, needle) ? 1 : 0; -} - -static uint32_t -search_normal (const char *haystack, const char *needle) -{ - return strstr (haystack, needle) ? 1 : 0; -} - -static void -search_query_free (void * data) -{ - search_query_t *query = data; - assert (query != NULL); - - if (query->query != NULL) { - g_free (query->query); - query->query = NULL; - } - g_free (query); - query = NULL; -} - -static search_query_t * -search_query_new (const char *query, bool match_case) -{ - search_query_t *new = calloc (1, sizeof (search_query_t)); - assert (new != NULL); - - new->query = g_strdup (query); - new->query_len = strlen (query); - new->has_uppercase = fs_str_has_upper (query); - new->has_separator = strchr (query, '/') ? 1 : 0; - // TODO: this might not work at all times? - if (utf8len (query) != new->query_len) { - new->is_utf8 = 1; - } - else { - new->is_utf8 = 0; - } - - if (match_case) { - new->search_func = search_normal; - } - else { - if (new->is_utf8) { - new->search_func = search_normal_icase_u8; - } - else { - new->search_func = search_normal_icase; - } - } - - return new; -} - -static search_query_t ** -build_queries (DatabaseSearch *search, FsearchQuery *q) -{ - assert (search != NULL); - assert (q->query != NULL); - - char *tmp_query_copy = strdup (q->query); - assert (tmp_query_copy != NULL); - // remove leading/trailing whitespace - g_strstrip (tmp_query_copy); - - search_query_t **queries = calloc (2, sizeof (search_query_t *)); - queries[0] = search_query_new (tmp_query_copy, search->match_case); - queries[1] = NULL; - g_free (tmp_query_copy); - tmp_query_copy = NULL; - - return queries; -} - -static DatabaseSearchResult * -db_search_empty (DatabaseSearch *search) -{ - assert (search != NULL); - assert (search->entries != NULL); - - const uint32_t num_results = MIN (search->max_results, search->num_entries); - GPtrArray *results = g_ptr_array_sized_new (num_results); - g_ptr_array_set_free_func (results, (GDestroyNotify)db_search_entry_free); - - DynamicArray *entries = search->entries; - - uint32_t num_folders = 0; - uint32_t num_files = 0; - uint32_t pos = 0; - for (uint32_t i = 0; pos < num_results && i < search->num_entries; ++i) { - BTreeNode *node = darray_get_item (entries, i); - if (!node) { - continue; - } - - if (!filter_node (node, search->filter)) { - continue; - } - if (node->is_dir) { - num_folders++; - } - else { - num_files++; - } - DatabaseSearchEntry *entry = db_search_entry_new (node, pos); - g_ptr_array_add (results, entry); - pos++; - } - DatabaseSearchResult *result_ctx = calloc (1, sizeof (DatabaseSearchResult)); - assert (result_ctx != NULL); - result_ctx->results = results; - result_ctx->num_folders = num_folders; - result_ctx->num_files = num_files; - return result_ctx; -} - - DatabaseSearchResult * -db_search (DatabaseSearch *search, FsearchQuery *q) -{ - assert (search != NULL); - assert (search->entries != NULL); - - search_query_t **queries = build_queries (search, q); - - const uint32_t num_threads = MIN(fsearch_thread_pool_get_num_threads (search->pool), search->num_entries); - const uint32_t num_items_per_thread = MAX(search->num_entries / num_threads, 1); - - search_thread_context_t *thread_data[num_threads]; - memset (thread_data, 0, num_threads * sizeof (search_thread_context_t *)); - - const uint32_t max_results = search->max_results; - const bool limit_results = max_results ? true : false; - const bool is_reg = is_regex (search->query); - uint32_t num_queries = 0; - while (queries[num_queries]) { - num_queries++; - } - uint32_t start_pos = 0; - uint32_t end_pos = num_items_per_thread - 1; - timer_start (); - GList *temp = fsearch_thread_pool_get_threads (search->pool); - for (uint32_t i = 0; i < num_threads; i++) { - thread_data[i] = search_thread_context_new (search, - queries, - num_queries, - start_pos, - i == num_threads - 1 ? search->num_entries - 1 : end_pos); - - start_pos = end_pos + 1; - end_pos += num_items_per_thread; - - fsearch_thread_pool_push_data (search->pool, - temp, - is_reg && search->enable_regex ? - search_regex_thread : search_thread, - thread_data[i]); - temp = temp->next; - } - temp = fsearch_thread_pool_get_threads (search->pool); - while (temp) { - fsearch_thread_pool_wait_for_thread (search->pool, temp); - temp = temp->next; - } - -// trace ("search done: "); - timer_stop (); - - // get total number of entries found - uint32_t num_results = 0; - for (uint32_t i = 0; i < num_threads; ++i) { - num_results += thread_data[i]->num_results; - } - GPtrArray *results = g_ptr_array_sized_new (MIN (num_results, max_results)); - g_ptr_array_set_free_func (results, (GDestroyNotify)db_search_entry_free); - uint32_t num_folders = 0; - uint32_t num_files = 0; - - uint32_t pos = 0; - for (uint32_t i = 0; i < num_threads; i++) { - search_thread_context_t *ctx = thread_data[i]; - if (!ctx) { - break; - } - for (uint32_t j = 0; j < ctx->num_results; ++j) { - if (limit_results) { - if (pos >= max_results) { - break; - } - } - BTreeNode *node = ctx->results[j]; - if (node->is_dir) { - num_folders++; - } - else { - num_files++; - } - DatabaseSearchEntry *entry = db_search_entry_new (node, pos); - g_ptr_array_add (results, entry); - pos++; - } - if (ctx->results) { - g_free (ctx->results); - ctx->results = NULL; - } - if (ctx) { - g_free (ctx); - ctx = NULL; - } - } - for (uint32_t i = 0; i < num_queries; ++i) { - search_query_free (queries[i]); - queries[i] = NULL; - } - free (queries); - queries = NULL; - DatabaseSearchResult *result_ctx = calloc (1, sizeof (DatabaseSearchResult)); - assert (result_ctx != NULL); - result_ctx->results = results; - result_ctx->num_folders = num_folders; - result_ctx->num_files = num_files; - return result_ctx; -} - -void -db_search_results_clear (DatabaseSearch *search) -{ - assert (search != NULL); - - // free entries - if (search->results) { - g_ptr_array_free (search->results, TRUE); - search->results = NULL; - } - search->num_folders = 0; - search->num_files = 0; - return; -} - -void -db_search_free (DatabaseSearch *search) -{ - assert (search != NULL); - - db_search_results_clear (search); - if (search->query) { - g_free (search->query); - search->query = NULL; - } - g_mutex_lock (&search->query_mutex); - if (search->query_ctx) { - fsearch_query_free (search->query_ctx); - search->query_ctx = NULL; - } - g_mutex_unlock (&search->query_mutex); - - search->search_thread_terminate = true; - g_cond_signal (&search->search_thread_start_cond); - g_thread_join (search->search_thread); - g_mutex_clear (&search->query_mutex); - g_cond_clear (&search->search_thread_start_cond); - g_free (search); - search = NULL; - return; -} - -BTreeNode * -db_search_entry_get_node (DatabaseSearchEntry *entry) -{ - return entry->node; -} - -uint32_t -db_search_entry_get_pos (DatabaseSearchEntry *entry) -{ - return entry->pos; -} - -void -db_search_entry_set_pos (DatabaseSearchEntry *entry, uint32_t pos) -{ - entry->pos = pos; -} - -static void -db_search_entry_free (DatabaseSearchEntry *entry) -{ - if (entry) { - g_free (entry); - entry = NULL; - } -} - -DatabaseSearchEntry * -db_search_entry_new (BTreeNode *node, uint32_t pos) -{ - DatabaseSearchEntry *entry = calloc (1, sizeof (DatabaseSearchEntry)); - assert (entry != NULL); - - entry->node = node; - entry->pos = pos; - return entry; -} - -DatabaseSearch * -db_search_new (FsearchThreadPool *pool) -{ - DatabaseSearch *db_search = calloc (1, sizeof (DatabaseSearch)); - assert (db_search != NULL); - - db_search->pool = pool; - db_search->search_thread_started = false; - g_mutex_init (&db_search->query_mutex); - g_cond_init (&db_search->search_thread_start_cond); - db_search->search_thread = g_thread_new("fsearch_search_thread", fsearch_search_thread, db_search); - return db_search; -} - -void -db_search_set_search_in_path (DatabaseSearch *search, bool search_in_path) -{ - assert (search != NULL); - - search->search_in_path = search_in_path; -} - -void -db_search_set_query (DatabaseSearch *search, const char *query) -{ - assert (search != NULL); - - if (search->query) { - g_free (search->query); - } - search->query = g_strdup (query); -} - -void -db_search_update (DatabaseSearch *search, - DynamicArray *entries, - uint32_t num_entries, - uint32_t max_results, - FsearchFilter filter, - const char *query, - bool hide_results, - bool match_case, - bool enable_regex, - bool auto_search_in_path, - bool search_in_path) -{ - assert (search != NULL); - - search->entries = entries; - search->num_entries = num_entries; - db_search_set_query (search, query); - search->enable_regex = enable_regex; - search->search_in_path = search_in_path; - search->auto_search_in_path = auto_search_in_path; - search->hide_results = hide_results; - search->match_case = match_case; - search->max_results = max_results; - search->filter = filter; -} - -uint32_t -db_search_get_num_results (DatabaseSearch *search) -{ - assert (search != NULL); - return search->results->len; -} - -uint32_t -db_search_get_num_files (DatabaseSearch *search) -{ - assert (search != NULL); - return search->num_files; -} - -uint32_t -db_search_get_num_folders (DatabaseSearch *search) -{ - assert (search != NULL); - return search->num_folders; -} - -static void -update_index (DatabaseSearch *search) -{ - assert (search != NULL); - - for (uint32_t i = 0; i < search->results->len; ++i) { - DatabaseSearchEntry *entry = g_ptr_array_index (search->results, i); - entry->pos = i; - } -} - -void -db_search_remove_entry (DatabaseSearch *search, DatabaseSearchEntry *entry) -{ - if (search == NULL) { - return; - } - if (entry == NULL) { - return; - } - - g_ptr_array_remove (search->results, (void *) entry); - update_index (search); -} - -GPtrArray * -db_search_get_results (DatabaseSearch *search) -{ - assert (search != NULL); - return search->results; -} - -static void -db_search_queue (DatabaseSearch *search, FsearchQuery *query) -{ - g_mutex_lock (&search->query_mutex); - if (search->query_ctx) { - fsearch_query_free (search->query_ctx); - } - search->query_ctx = query; - - g_mutex_unlock (&search->query_mutex); - // 确保search线程处于wait状态,否则会照成流程阻塞 - while (!search->search_thread_started) { - usleep(100); - } - g_cond_signal (&search->search_thread_start_cond); - - printf("---------------------------g_cond_signal (&search->search_thread_start_cond)\n"); -} - -void -db_perform_search (DatabaseSearch *search, void (*callback)(void *, void *), void *callback_data, void *sender) -{ - assert (search != NULL); - if (search->entries == NULL) { - return; - } - - db_search_results_clear (search); - - FsearchQuery *q = fsearch_query_new (search->query, callback, callback_data, sender, false, false, false, false); - db_search_queue (search, q); -} diff --git a/3rdparty/fsearch/database_search.h b/3rdparty/fsearch/database_search.h deleted file mode 100644 index 047daf43..00000000 --- a/3rdparty/fsearch/database_search.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ -#pragma once - -#include -#include "array.h" -#include "btree.h" -#include "query.h" -#include "fsearch_thread_pool.h" - -typedef struct _DatabaseSearch DatabaseSearch; -typedef struct _DatabaseSearchEntry DatabaseSearchEntry; - -// search modes -enum { - DB_SEARCH_MODE_NORMAL = 0, - DB_SEARCH_MODE_REGEX = 1, -}; -struct _DatabaseSearchEntry { - BTreeNode *node; - uint32_t pos; -}; -typedef enum { - FSEARCH_FILTER_NONE, - FSEARCH_FILTER_FOLDERS, - FSEARCH_FILTER_FILES, -} FsearchFilter; - -typedef struct { - GPtrArray *results; - void *cb_data; - uint32_t num_folders; - uint32_t num_files; -} DatabaseSearchResult; - -struct _DatabaseSearch { - GPtrArray *results; - FsearchThreadPool *pool; - - DynamicArray *entries; - uint32_t num_entries; - - GThread *search_thread; - bool search_thread_terminate; - GMutex query_mutex; - GCond search_thread_start_cond; - - char *query; - FsearchQuery *query_ctx; - FsearchFilter filter; - uint32_t max_results; - uint32_t num_folders; - uint32_t num_files; - bool hide_results; - bool match_case; - bool enable_regex; - bool search_in_path; - bool auto_search_in_path; - bool search_thread_started; -}; - -void -db_search_free(DatabaseSearch *search); - -DatabaseSearch * -db_search_new(FsearchThreadPool *pool); - -BTreeNode * -db_search_entry_get_node(DatabaseSearchEntry *entry); - -uint32_t -db_search_entry_get_pos(DatabaseSearchEntry *entry); - -void -db_search_entry_set_pos(DatabaseSearchEntry *entry, uint32_t pos); - -void -db_search_set_query(DatabaseSearch *search, const char *query); - -void -db_search_update(DatabaseSearch *search, - DynamicArray *entries, - uint32_t num_entries, - uint32_t max_results, - FsearchFilter filter, - const char *query, - bool hide_results, - bool match_case, - bool enable_regex, - bool auto_search_in_path, - bool search_in_path); - -void -db_search_results_clear(DatabaseSearch *search); - -void -db_search_set_search_in_path(DatabaseSearch *search, bool search_in_path); - -uint32_t -db_search_get_num_results(DatabaseSearch *search); - -uint32_t -db_search_get_num_files(DatabaseSearch *search); - -uint32_t -db_search_get_num_folders(DatabaseSearch *search); - -GPtrArray * -db_search_get_results(DatabaseSearch *search); - -void -db_search_remove_entry(DatabaseSearch *search, DatabaseSearchEntry *entry); - -void -db_perform_search(DatabaseSearch *search, void (*callback)(void *, void *), void *callback_data, void *sender); - -DatabaseSearchResult * -db_search(DatabaseSearch *search, FsearchQuery *q); diff --git a/3rdparty/fsearch/fsearch.c b/3rdparty/fsearch/fsearch.c deleted file mode 100644 index e899da67..00000000 --- a/3rdparty/fsearch/fsearch.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -//#ifdef HAVE_CONFIG_H -//#include -//#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fsearch.h" -#include "fsearch_config.h" -#include "fsearch_limits.h" -//#include "utils.h" -#include "database.h" -#include "database_search.h" -//#include "debug.h" -enum { - DATABASE_UPDATE, - DATABASE_UPDATED, - LAST_SIGNAL -}; - -//static guint signals [LAST_SIGNAL]; - -Database * -fsearch_application_get_db (FsearchApplication *fsearch) -{ - return fsearch->db; -} - -FsearchThreadPool * -fsearch_application_get_thread_pool (FsearchApplication *fsearch) -{ - return fsearch->pool; -} - -FsearchConfig * -fsearch_application_get_config (FsearchApplication *fsearch) -{ - return fsearch->config; -} -static void -build_location_callback (const char *text) -{ - if (text) { - //g_idle_add (update_db_cb, g_strdup (text)); - } -} - -static bool -make_location_dir (void) -{ - gchar config_dir[PATH_MAX] = ""; - config_build_dir (config_dir, sizeof (config_dir)); - gchar location_dir[PATH_MAX] = ""; - g_assert (0 <= snprintf (location_dir, sizeof (location_dir), "%s/%s", config_dir, "database")); - return !g_mkdir_with_parents (location_dir, 0700); -} - -void -fsearch_application_init (FsearchApplication *app) -{ - config_make_dir (); - make_location_dir (); - app->config = calloc (1, sizeof (FsearchConfig)); - if (!config_load (app->config)) { - if (!config_load_default (app->config)) { - } - } - app->db = NULL; - app->search = NULL; - g_mutex_init (&app->mutex); -} - -static void -fsearch_application_shutdown (FsearchApplication *app) -{ - FsearchApplication *fsearch = app; - - if (fsearch->db) { - db_save_locations (fsearch->db); - db_clear (fsearch->db); - } - if (fsearch->pool) { - fsearch_thread_pool_free (fsearch->pool); - } - config_save (fsearch->config); - config_free (fsearch->config); - g_mutex_clear (&fsearch->mutex); -// G_APPLICATION_CLASS (fsearch_application_parent_class)->shutdown (app); -} -static void -prepare_windows_for_db_update (FsearchApplication *app) -{ - return; -} - -#ifdef DEBUG -static struct timeval tm1; -#endif - -static inline void timer_start() -{ -#ifdef DEBUG - gettimeofday(&tm1, NULL); -#endif -} - -static inline void timer_stop() -{ -#ifdef DEBUG - struct timeval tm2; - gettimeofday(&tm2, NULL); - - unsigned long long t = 1000 * (tm2.tv_sec - tm1.tv_sec) + (tm2.tv_usec - tm1.tv_usec) / 1000; - trace ("%llu ms\n", t); -#endif -} - -gpointer -load_database (Database **db, const char *search_path) -{ - if (!*db) { - // create new database - timer_start (); - *db = db_new (); - - bool loaded = false; - bool build_new = false; - - if (!db_location_load (*db, search_path)) { - if (db_location_add (*db, search_path, build_location_callback)) { - loaded = true; - build_new = true; - } - } else { - loaded = true; - } - - if (loaded) { - if (build_new) { - db_build_initial_entries_list (*db); - } else { - db_update_entries_list (*db); - } - } - timer_stop (); - } else { - timer_start (); - db_clear (*db); - db_location_add (*db, search_path, build_location_callback); - db_build_initial_entries_list (*db); - timer_stop (); - } - return NULL; -} - -void -fsearch_application_startup (FsearchApplication* app) -{ - (app)->pool = fsearch_thread_pool_init (); -} diff --git a/3rdparty/fsearch/fsearch.h b/3rdparty/fsearch/fsearch.h deleted file mode 100644 index e339403d..00000000 --- a/3rdparty/fsearch/fsearch.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include -//#include -//#include -#include "database.h" -#include "fsearch_config.h" -#include "fsearch_thread_pool.h" -//#include "glib_support.h" -#include "database_search.h" - -struct _FsearchApplication { - Database *db; - DatabaseSearch *search; - FsearchConfig *config; - FsearchThreadPool *pool; - DatabaseSearchResult *result; - GMutex mutex; -}; -typedef struct _FsearchApplication FsearchApplication; - -void -fsearch_update_database(FsearchApplication *fsearch); - -Database * -fsearch_application_get_db(FsearchApplication *fsearch); - -FsearchConfig * -fsearch_application_get_config(FsearchApplication *fsearch); - -FsearchThreadPool * -fsearch_application_get_thread_pool(FsearchApplication *fsearch); - -void -fsearch_application_activate(FsearchApplication *app); - -void -fsearch_application_startup(FsearchApplication *app); - -gpointer -load_database(Database **db, const char *search_path); - -void -fsearch_application_init(FsearchApplication *app); diff --git a/3rdparty/fsearch/fsearch_config.c b/3rdparty/fsearch/fsearch_config.c deleted file mode 100644 index 5a2b5bbb..00000000 --- a/3rdparty/fsearch/fsearch_config.c +++ /dev/null @@ -1,590 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#include -#include -#include -#include -#include - -#include "fsearch_config.h" -#include "fsearch_limits.h" -//#include "debug.h" - -const char *config_file_name = "fsearch.conf"; -const char *config_folder_name = "fsearch"; - -void -config_build_dir (char *path, size_t len) -{ - g_assert (path != NULL); - g_assert (len >= 0); - - const gchar *xdg_conf_dir = g_get_user_config_dir (); - snprintf (path, len, "%s/%s", xdg_conf_dir, config_folder_name); - return; -} - -void database_build_dir(char *path, size_t len) -{ - g_assert (path != NULL); - g_assert (len >= 0); - - const gchar *cache_dir = g_get_user_cache_dir(); - const gchar *app_name = g_get_application_name(); - snprintf (path, len, "%s/%s/%s", cache_dir, app_name, config_folder_name); - return; -} - -static void -config_build_path (char *path, size_t len) -{ - g_assert (path != NULL); - g_assert (len >= 0); - - const gchar *xdg_conf_dir = g_get_user_config_dir (); - snprintf (path, len, "%s/%s/%s", xdg_conf_dir, config_folder_name, config_file_name); - return; -} - -bool -config_make_dir (void) -{ - gchar config_dir[PATH_MAX] = ""; - config_build_dir (config_dir, sizeof (config_dir)); - return !g_mkdir_with_parents (config_dir, 0700); -} - -static void -config_load_handle_error (GError *error) -{ - if (!error) { - return; - } - switch (error->code) { - case G_KEY_FILE_ERROR_INVALID_VALUE: - fprintf(stderr, "load_config: invalid value: %s\n", error->message); - break; - case G_KEY_FILE_ERROR_KEY_NOT_FOUND: - case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: - // new config, use default value and don't report anything - break; - default: - fprintf(stderr, "load_config: unknown error: %s\n", error->message); - } - g_error_free (error); -} - -static uint32_t -config_load_integer (GKeyFile *key_file, - const char *group_name, - const char *key, - uint32_t default_value) -{ - GError *error = NULL; - uint32_t result = g_key_file_get_integer (key_file, group_name, key, &error); - if (error != NULL) { - result = default_value; - config_load_handle_error (error); - } - return result; -} - -static bool -config_load_boolean (GKeyFile *key_file, - const char *group_name, - const char *key, - bool default_value) -{ - GError *error = NULL; - bool result = g_key_file_get_boolean (key_file, group_name, key, &error); - if (error != NULL) { - result = default_value; - config_load_handle_error (error); - } - return result; -} - -static char * -config_load_string (GKeyFile *key_file, - const char *group_name, - const char *key, - char *default_value) -{ - GError *error = NULL; - char *result = g_key_file_get_string (key_file, group_name, key, &error); - if (error != NULL) { - result = default_value; - config_load_handle_error (error); - } - return result; -} - -bool -config_load (FsearchConfig *config) -{ - g_assert (config != NULL); - - bool result = false; - GKeyFile *key_file = g_key_file_new (); - g_assert (key_file != NULL); - - gchar config_path[PATH_MAX] = ""; - config_build_path (config_path, sizeof (config_path)); - - GError *error = NULL; - if (g_key_file_load_from_file (key_file, config_path, G_KEY_FILE_NONE, &error)) { -// trace ("loaded config file\n"); - // Interface - config->restore_column_config = config_load_boolean (key_file, - "Interface", - "restore_column_configuration", - false); - config->enable_list_tooltips = config_load_boolean (key_file, - "Interface", - "enable_list_tooltips", - true); - config->enable_dark_theme = config_load_boolean (key_file, - "Interface", - "enable_dark_theme", - false); - config->show_menubar = config_load_boolean (key_file, - "Interface", - "show_menubar", - true); - config->show_statusbar = config_load_boolean (key_file, - "Interface", - "show_statusbar", - true); - config->show_filter = config_load_boolean (key_file, - "Interface", - "show_filter", - true); - config->show_search_button = config_load_boolean (key_file, - "Interface", - "show_search_button", - true); - config->show_base_2_units = config_load_boolean (key_file, - "Interface", - "show_base_2_units", - false); - config->action_after_file_open = config_load_integer(key_file, - "Interface", - "action_after_file_open", - 0); - config->action_after_file_open_keyboard = config_load_boolean (key_file, - "Interface", - "action_after_file_open_keyboard", - false); - config->action_after_file_open_mouse = config_load_boolean (key_file, - "Interface", - "action_after_file_open_mouse", - false); - - // Warning Dialogs - config->show_dialog_failed_opening = config_load_boolean(key_file, - "Dialogs", - "show_dialog_failed_opening", - true); - - // Applications - config->folder_open_cmd = config_load_string (key_file, - "Applications", - "folder_open_cmd", - NULL); - - // Window - config->restore_window_size = config_load_boolean (key_file, - "Interface", - "restore_window_size", - false); - config->window_width = config_load_integer (key_file, - "Interface", - "window_width", - 800); - config->window_height = config_load_integer (key_file, - "Interface", - "window_height", - 600); - - // Columns - config->show_listview_icons = config_load_boolean (key_file, - "Interface", - "show_listview_icons", - true); - config->show_path_column = config_load_boolean (key_file, - "Interface", - "show_path_column", - true); - config->show_type_column = config_load_boolean (key_file, - "Interface", - "show_type_column", - true); - config->show_size_column = config_load_boolean (key_file, - "Interface", - "show_size_column", - true); - config->show_modified_column = config_load_boolean (key_file, - "Interface", - "show_modified_column", - true); - - // Column Size - config->name_column_width = config_load_integer (key_file, - "Interface", - "name_column_width", - 250); - config->path_column_width = config_load_integer (key_file, - "Interface", - "path_column_width", - 250); - config->type_column_width = config_load_integer (key_file, - "Interface", - "type_column_width", - 100); - config->size_column_width = config_load_integer (key_file, - "Interface", - "size_column_width", - 75); - config->modified_column_width = config_load_integer (key_file, - "Interface", - "modified_column_width", - 75); - - // Column position - config->name_column_pos = config_load_integer (key_file, - "Interface", - "name_column_pos", - 0); - config->path_column_pos = config_load_integer (key_file, - "Interface", - "path_column_pos", - 1); - config->type_column_pos = config_load_integer (key_file, - "Interface", - "type_column_pos", - 2); - config->size_column_pos = config_load_integer (key_file, - "Interface", - "size_column_pos", - 3); - config->modified_column_pos = config_load_integer (key_file, - "Interface", - "modified_column_pos", - 4); - - // Search - config->search_as_you_type = config_load_boolean (key_file, - "Search", - "search_as_you_type", - true); - config->auto_search_in_path = config_load_boolean (key_file, - "Search", - "auto_search_in_path", - true); - config->match_case = config_load_boolean (key_file, - "Search", - "match_case", - false); - config->enable_regex = config_load_boolean (key_file, - "Search", - "enable_regex", - false); - config->search_in_path = config_load_boolean (key_file, - "Search", - "search_in_path", - false); - config->hide_results_on_empty_search = config_load_boolean (key_file, - "Search", - "hide_results_on_empty_search", - true); - config->limit_results = config_load_boolean (key_file, - "Search", - "limit_results", - false); - config->num_results = config_load_integer (key_file, - "Search", - "num_results", - 1000); - - // Database - config->update_database_on_launch = config_load_boolean (key_file, - "Database", - "update_database_on_launch", - false); - config->exclude_hidden_items = config_load_boolean (key_file, - "Database", - "exclude_hidden_files_and_folders", - false); - config->follow_symlinks = config_load_boolean (key_file, - "Database", - "follow_symbolic_links", - false); - - char *exclude_files_str = config_load_string (key_file, "Database", "exclude_files", NULL); - if (exclude_files_str) { - config->exclude_files = g_strsplit (exclude_files_str, ";", -1); - free (exclude_files_str); - exclude_files_str = NULL; - } - - // Locations - uint32_t pos = 1; - while (true) { - char key[100] = ""; - snprintf (key, sizeof (key), "location_%d", pos++); - char *value = config_load_string (key_file, "Database", key, NULL); - if (value) { - config->locations = g_list_append (config->locations, value); - } - else { - break; - } - } - // Exclude - pos = 1; - while (true) { - char key[100] = ""; - snprintf (key, sizeof (key), "exclude_location_%d", pos++); - char *value = config_load_string (key_file, "Database", key, NULL); - if (value) { - config->exclude_locations = g_list_append (config->exclude_locations, value); - } - else { - break; - } - } - - result = true; - } - else { - fprintf(stderr, "load config failed: %s\n", error->message); - g_error_free (error); - } - - g_key_file_free (key_file); - return result; -} - -bool -config_load_default (FsearchConfig *config) -{ - g_assert (config != NULL); - - // Search - config->auto_search_in_path = false; - config->search_as_you_type = true; - config->match_case = false; - config->enable_regex = false; - config->search_in_path = false; - config->hide_results_on_empty_search = true; - config->limit_results = true; - config->num_results = 1000; - - // Interface - config->enable_dark_theme = false; - config->enable_list_tooltips = true; - config->restore_column_config = false; - config->show_menubar = true; - config->show_statusbar = true; - config->show_filter = true; - config->show_search_button = true; - config->show_base_2_units = false; - config->action_after_file_open = 0; - config->action_after_file_open_keyboard = false; - config->action_after_file_open_mouse = false; - - // Columns - config->show_listview_icons = true; - config->show_path_column = true; - config->show_type_column = true; - config->show_size_column = true; - config->show_modified_column = true; - - config->name_column_pos = 0; - config->path_column_pos = 1; - config->type_column_pos = 2; - config->size_column_pos = 3; - config->modified_column_pos = 4; - - config->name_column_width = 250; - config->path_column_width = 250; - config->type_column_width = 100; - config->size_column_width = 75; - config->modified_column_width = 125; - - // Warning Dialogs - config->show_dialog_failed_opening = true; - - // Window - config->restore_window_size = false; - config->window_width = 800; - config->window_height = 600; - - // Database - config->update_database_on_launch = false; - config->exclude_hidden_items = false; - config->follow_symlinks = false; - - // Locations - config->locations = NULL; - config->exclude_locations = NULL; - - return true; -} - -bool -config_save (FsearchConfig *config) -{ - g_assert (config != NULL); - - bool result = false; - GKeyFile *key_file = g_key_file_new (); - g_assert (key_file != NULL); - - // Interface - g_key_file_set_boolean (key_file, "Interface", "restore_column_configuration", config->restore_column_config); - g_key_file_set_boolean (key_file, "Interface", "enable_list_tooltips", config->enable_list_tooltips); - g_key_file_set_boolean (key_file, "Interface", "enable_dark_theme", config->enable_dark_theme); - g_key_file_set_boolean (key_file, "Interface", "show_menubar", config->show_menubar); - g_key_file_set_boolean (key_file, "Interface", "show_statusbar", config->show_statusbar); - g_key_file_set_boolean (key_file, "Interface", "show_filter", config->show_filter); - g_key_file_set_boolean (key_file, "Interface", "show_search_button", config->show_search_button); - g_key_file_set_boolean (key_file, "Interface", "show_base_2_units", config->show_base_2_units); - g_key_file_set_integer (key_file, "Interface", "action_after_file_open", config->action_after_file_open); - g_key_file_set_boolean (key_file, "Interface", "action_after_file_open_keyboard", config->action_after_file_open_keyboard); - g_key_file_set_boolean (key_file, "Interface", "action_after_file_open_mouse", config->action_after_file_open_mouse); - - // Warning Dialogs - g_key_file_set_boolean (key_file, "Dialogs", "show_dialog_failed_opening", config->show_dialog_failed_opening); - - // Window - g_key_file_set_boolean (key_file, "Interface", "restore_window_size", config->restore_window_size); - g_key_file_set_integer (key_file, "Interface", "window_width", config->window_width); - g_key_file_set_integer (key_file, "Interface", "window_height", config->window_height); - - // Columns visibility - g_key_file_set_boolean (key_file, "Interface", "show_listview_icons", config->show_listview_icons); - g_key_file_set_boolean (key_file, "Interface", "show_path_column", config->show_path_column); - g_key_file_set_boolean (key_file, "Interface", "show_type_column", config->show_type_column); - g_key_file_set_boolean (key_file, "Interface", "show_size_column", config->show_size_column); - g_key_file_set_boolean (key_file, "Interface", "show_modified_column", config->show_modified_column); - - // Column width - g_key_file_set_integer (key_file, "Interface", "name_column_width", config->name_column_width); - g_key_file_set_integer (key_file, "Interface", "path_column_width", config->path_column_width); - g_key_file_set_integer (key_file, "Interface", "type_column_width", config->type_column_width); - g_key_file_set_integer (key_file, "Interface", "size_column_width", config->size_column_width); - g_key_file_set_integer (key_file, "Interface", "modified_column_width", config->modified_column_width); - - // Column position - g_key_file_set_integer (key_file, "Interface", "name_column_pos", config->name_column_pos); - g_key_file_set_integer (key_file, "Interface", "path_column_pos", config->path_column_pos); - g_key_file_set_integer (key_file, "Interface", "type_column_pos", config->type_column_pos); - g_key_file_set_integer (key_file, "Interface", "size_column_pos", config->size_column_pos); - g_key_file_set_integer (key_file, "Interface", "modified_column_pos", config->modified_column_pos); - - // Applications - if (config->folder_open_cmd) { - g_key_file_set_string (key_file, "Applications", "folder_open_cmd", config->folder_open_cmd); - } - - // Search - g_key_file_set_boolean (key_file, "Search", "search_as_you_type", config->search_as_you_type); - g_key_file_set_boolean (key_file, "Search", "auto_search_in_path", config->auto_search_in_path); - g_key_file_set_boolean (key_file, "Search", "search_in_path", config->search_in_path); - g_key_file_set_boolean (key_file, "Search", "enable_regex", config->enable_regex); - g_key_file_set_boolean (key_file, "Search", "match_case", config->match_case); - g_key_file_set_boolean (key_file, "Search", "hide_results_on_empty_search", config->hide_results_on_empty_search); - g_key_file_set_boolean (key_file, "Search", "limit_results", config->limit_results); - g_key_file_set_integer (key_file, "Search", "num_results", config->num_results); - - // Database - g_key_file_set_boolean (key_file, "Database", "update_database_on_launch", config->update_database_on_launch); - g_key_file_set_boolean (key_file, "Database", "exclude_hidden_files_and_folders", config->exclude_hidden_items); - g_key_file_set_boolean (key_file, "Database", "follow_symbolic_links", config->follow_symlinks); - - if (config->locations) { - uint32_t pos = 1; - for (GList *l = config->locations; l != NULL; l = l->next) { - char location[100] = ""; - snprintf (location, sizeof (location), "location_%d", pos); - g_key_file_set_string (key_file, "Database", location, l->data); - pos++; - } - } - - if (config->exclude_locations) { - uint32_t pos = 1; - for (GList *l = config->exclude_locations; l != NULL; l = l->next) { - char location[100] = ""; - snprintf (location, sizeof (location), "exclude_location_%d", pos); - g_key_file_set_string (key_file, "Database", location, l->data); - pos++; - } - } - - if (config->exclude_files) { - char *exclude_files_str = g_strjoinv (";", config->exclude_files); - g_key_file_set_string (key_file, "Database", "exclude_files", exclude_files_str); - free (exclude_files_str); - } - - gchar config_path[PATH_MAX] = ""; - config_build_path (config_path, sizeof (config_path)); - - GError *error = NULL; - if (g_key_file_save_to_file (key_file, config_path, &error)) { -// trace ("saved config file\n"); - result = true; - } - else { - fprintf(stderr, "save config failed: %s\n", error->message); - } - - g_key_file_free (key_file); - return result; -} - -void -config_free (FsearchConfig *config) -{ - g_assert (config != NULL); - - if (config->folder_open_cmd) { - free (config->folder_open_cmd); - config->folder_open_cmd = NULL; - } - if (config->locations) { - g_list_free(config->locations); -// g_list_free_full (config->locations, (GDestroyNotify)free); - config->locations = NULL; - } - if (config->exclude_locations) { - g_list_free(config->exclude_locations); -// g_list_free_full (config->exclude_locations, (GDestroyNotify)free); - config->exclude_locations = NULL; - } - if (config->exclude_files) { - g_strfreev (config->exclude_files); - config->exclude_files = NULL; - } - free (config); - config = NULL; -} - diff --git a/3rdparty/fsearch/fsearch_config.h b/3rdparty/fsearch/fsearch_config.h deleted file mode 100644 index 2232de97..00000000 --- a/3rdparty/fsearch/fsearch_config.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include -#include - -typedef struct _FsearchConfig FsearchConfig; - -struct _FsearchConfig { - // Search - bool limit_results; - bool hide_results_on_empty_search; - bool search_in_path; - bool enable_regex; - bool match_case; - bool auto_search_in_path; - bool search_as_you_type; - bool show_base_2_units; - - // Applications - char *folder_open_cmd; - - // Window - bool restore_window_size; - int32_t window_width; - int32_t window_height; - - // Interface - bool enable_dark_theme; - bool enable_list_tooltips; - bool restore_column_config; - uint32_t action_after_file_open; - bool action_after_file_open_keyboard; - bool action_after_file_open_mouse; - - // Warning Dialogs - bool show_dialog_failed_opening; - - // View menu - bool show_menubar; - bool show_statusbar; - bool show_filter; - bool show_search_button; - - // Columns - bool show_listview_icons; - bool show_path_column; - bool show_type_column; - bool show_size_column; - bool show_modified_column; - - uint32_t name_column_width; - uint32_t path_column_width; - uint32_t type_column_width; - uint32_t size_column_width; - uint32_t modified_column_width; - - uint32_t name_column_pos; - uint32_t path_column_pos; - uint32_t type_column_pos; - uint32_t size_column_pos; - uint32_t modified_column_pos; - - // database - bool update_database_on_launch; - bool exclude_hidden_items; - bool follow_symlinks; - - uint32_t num_results; - - GList *locations; - GList *exclude_locations; - char **exclude_files; -}; - - -bool -config_make_dir(void); - -bool -config_load(FsearchConfig *config); - -bool -config_load_default(FsearchConfig *config); - -bool -config_save(FsearchConfig *config); - -void -config_build_dir(char *path, size_t len); - -void -database_build_dir(char *path, size_t len); - -void -config_free(FsearchConfig *config); diff --git a/3rdparty/fsearch/fsearch_limits.h b/3rdparty/fsearch/fsearch_limits.h deleted file mode 100644 index 309e9f99..00000000 --- a/3rdparty/fsearch/fsearch_limits.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include - -#ifndef PATH_MAX -#define PATH_MAX 4096 /* max # of characters in a path name */ -#endif - diff --git a/3rdparty/fsearch/fsearch_thread_pool.c b/3rdparty/fsearch/fsearch_thread_pool.c deleted file mode 100644 index 92be1c6d..00000000 --- a/3rdparty/fsearch/fsearch_thread_pool.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#include -#include -#include "fsearch_thread_pool.h" -#include -struct _FsearchThreadPool { - GList *threads; - uint32_t num_threads; -}; - -typedef struct thread_context_s { - GThread *thread; - gpointer (*thread_func)(gpointer thread_data); - - gpointer *thread_data; - - GMutex mutex; - GCond start_cond; - GCond finished_cond; - bool thread_waited; - FsearchThreadStatus status; - bool terminate; -} thread_context_t; - -static bool -thread_pool_has_thread (FsearchThreadPool *pool, GList *thread) -{ - GList *temp = pool->threads; - while (temp) { - if (temp == thread) { - return true; - } - temp = temp->next; - } - return false; -} - -static gpointer -fsearch_thread_pool_thread (gpointer user_data) -{ - thread_context_t *ctx = user_data; - - g_mutex_lock (&ctx->mutex); - while (!ctx->terminate) { - // 线程已开启 - ctx->thread_waited = true; - g_cond_wait (&ctx->start_cond, &ctx->mutex); - ctx->status = THREAD_BUSY; - if (ctx->thread_data) { - ctx->thread_func (ctx->thread_data); - ctx->status = THREAD_FINISHED; - ctx->thread_data = NULL; - g_cond_signal (&ctx->finished_cond); - } - ctx->status = THREAD_IDLE; - } - g_mutex_unlock (&ctx->mutex); - return NULL; -} - -static void -thread_context_free (thread_context_t *ctx) -{ - if (!ctx) { - return; - } - - g_mutex_lock (&ctx->mutex); - if (ctx->thread_data) { -// trace ("search data still there\n"); - } - - // terminate thread - ctx->terminate = true; - g_cond_signal (&ctx->start_cond); - g_mutex_unlock (&ctx->mutex); - g_thread_join (ctx->thread); - - g_mutex_clear (&ctx->mutex); - g_cond_clear (&ctx->start_cond); - g_cond_clear (&ctx->finished_cond); - g_free (ctx); - ctx = NULL; -} - -static thread_context_t * -thread_context_new (void) -{ - thread_context_t *ctx = g_new0 (thread_context_t, 1); - if (!ctx) { - return NULL; - } - ctx->thread_data = NULL; - ctx->thread_func = NULL; - ctx->terminate = false; - ctx->status = THREAD_IDLE; - g_mutex_init (&ctx->mutex); - g_cond_init (&ctx->start_cond); - g_cond_init (&ctx->finished_cond); - ctx->thread_waited = false; - - ctx->thread = g_thread_new("thread pool", fsearch_thread_pool_thread, ctx); - return ctx; -} - -FsearchThreadPool * -fsearch_thread_pool_init (void) -{ - FsearchThreadPool *pool = g_new0 (FsearchThreadPool, 1); - pool->threads = NULL; - pool->num_threads = 0; - - uint32_t num_cpus = g_get_num_processors (); - for (uint32_t i = 0; i < num_cpus; i++) { - thread_context_t *ctx = thread_context_new (); - if (ctx) { - pool->threads = g_list_prepend (pool->threads, ctx); - pool->num_threads++; - - // 等待线程开启 - while (!ctx->thread_waited) { - usleep(100); - } - } - } - - return pool; -} - -void -fsearch_thread_pool_free (FsearchThreadPool *pool) -{ - if (!pool) { - return; - } - GList *thread = pool->threads; - for (uint32_t i = 0; thread && i < pool->num_threads; i++) { - thread_context_t *ctx = thread->data; - thread_context_free (ctx); - thread = thread->next; - } - pool->num_threads = 0; - g_list_free(pool->threads); - pool->threads = NULL; - g_free (pool); - pool = NULL; -} - -GList * -fsearch_thread_pool_get_threads (FsearchThreadPool *pool) -{ - if (!pool) { - return NULL; - } - return pool->threads; -} - -gpointer -fsearch_thread_pool_get_data (FsearchThreadPool *pool, GList *thread) -{ - if (!pool || !thread) { - return NULL; - } - if (!thread_pool_has_thread (pool, thread)) { - return NULL; - } - thread_context_t *ctx = thread->data; - if (!ctx) { - return NULL; - } - return ctx->thread_data; -} - -bool -fsearch_thread_pool_task_is_idle (FsearchThreadPool *pool, GList *thread) -{ - bool res = false; - if (!thread_pool_has_thread (pool, thread)) { - return res; - } - thread_context_t *ctx = thread->data; - if (!ctx) { - return res; - } - - res = ctx->status == THREAD_IDLE ? true : false; - - return res; -} - -bool -fsearch_thread_pool_task_is_busy (FsearchThreadPool *pool, GList *thread) -{ - bool res = false; - if (!thread_pool_has_thread (pool, thread)) { - return res; - } - thread_context_t *ctx = thread->data; - if (!ctx) { - return res; - } - - res = ctx->status == THREAD_BUSY ? true : false; - - return res; -} - -bool -fsearch_thread_pool_wait_for_thread (FsearchThreadPool *pool, GList *thread) -{ - thread_context_t *ctx = thread->data; - g_mutex_lock (&ctx->mutex); - while (fsearch_thread_pool_task_is_busy (pool, thread)) { - g_cond_wait (&ctx->finished_cond, &ctx->mutex); - } - g_mutex_unlock (&ctx->mutex); - return true; -} - -uint32_t -fsearch_thread_pool_get_num_threads (FsearchThreadPool *pool) -{ - if (!pool) { - return 0; - } - return pool->num_threads; -} - -bool -fsearch_thread_pool_push_data (FsearchThreadPool *pool, - GList *thread, - ThreadFunc thread_func, - gpointer thread_data) -{ - if (!pool || !thread || !thread_func || !thread_data) { - return false; - } - if (!thread_pool_has_thread (pool, thread)) { - return false; - } - thread_context_t *ctx = thread->data; - g_mutex_lock (&ctx->mutex); - ctx->thread_func = thread_func; - ctx->thread_data = thread_data; - ctx->status = THREAD_BUSY; - - g_cond_signal (&ctx->start_cond); - g_mutex_unlock (&ctx->mutex); - return true; -} - diff --git a/3rdparty/fsearch/fsearch_thread_pool.h b/3rdparty/fsearch/fsearch_thread_pool.h deleted file mode 100644 index 12532a3e..00000000 --- a/3rdparty/fsearch/fsearch_thread_pool.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include -#include -#include - -typedef struct _FsearchThreadPool FsearchThreadPool; -typedef GThreadFunc ThreadFunc; - -typedef enum { - THREAD_IDLE, - THREAD_BUSY, - THREAD_FINISHED -} FsearchThreadStatus; - -FsearchThreadPool * -fsearch_thread_pool_init(void); - -void -fsearch_thread_pool_free(FsearchThreadPool *pool); - -GList * -fsearch_thread_pool_get_threads(FsearchThreadPool *pool); - -uint32_t -fsearch_thread_pool_get_num_threads(FsearchThreadPool *pool); - -bool -fsearch_thread_pool_push_data(FsearchThreadPool *pool, - GList *thread, - ThreadFunc thread_func, - gpointer thread_data); - -bool -fsearch_thread_pool_wait_for_thread(FsearchThreadPool *pool, GList *thread); - -bool -fsearch_thread_pool_task_is_busy(FsearchThreadPool *pool, GList *thread); - -bool -fsearch_thread_pool_task_is_idle(FsearchThreadPool *pool, GList *thread); - -gpointer -fsearch_thread_pool_get_data(FsearchThreadPool *pool, GList *thread); - -bool -fsearch_thread_pool_set_task_finished(FsearchThreadPool *pool, GList *thread); diff --git a/3rdparty/fsearch/fsearch_utils.cpp b/3rdparty/fsearch/fsearch_utils.cpp deleted file mode 100644 index cea78a03..00000000 --- a/3rdparty/fsearch/fsearch_utils.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "fsearch_utils.h" -#include "utils/chineseletterhelper.h" - -#include - -#include - -bool convert_chinese_2_pinyin(const char *in_str, char *out_first_py, char *out_full_py) -{ - QRegularExpression reg("[\u4e00-\u9fa5]"); - QString str(in_str); - if (!str.contains(reg)) - return false; - - QString first_py; - QString full_py; - bool ret = GrandSearch::ChineseLetterHelper::instance()->convertChinese2Pinyin(str, first_py, full_py); - if (ret) { - int full_py_len = full_py.toLocal8Bit().size(); - int first_py_len = first_py.toLocal8Bit().size(); - - memcpy(out_full_py, full_py.toLocal8Bit().data(), full_py_len > FILENAME_MAX ? FILENAME_MAX : static_cast(full_py_len)); - memcpy(out_first_py, first_py.toLocal8Bit().data(), first_py_len > FILENAME_MAX ? FILENAME_MAX : static_cast(first_py_len)); - } - - return ret; -} diff --git a/3rdparty/fsearch/fsearch_utils.h b/3rdparty/fsearch/fsearch_utils.h deleted file mode 100644 index e85d655a..00000000 --- a/3rdparty/fsearch/fsearch_utils.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef FSEARCH_UTILS_H -#define FSEARCH_UTILS_H - -#ifdef __cplusplus -extern "C" { -#endif - -extern bool convert_chinese_2_pinyin(const char *in_str, char *out_first_py, char *out_full_py); - -#ifdef __cplusplus -} -#endif - -#endif // FSEARCH_UTILS_H diff --git a/3rdparty/fsearch/query.c b/3rdparty/fsearch/query.c deleted file mode 100644 index 8a4c4a53..00000000 --- a/3rdparty/fsearch/query.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#define _GNU_SOURCE -#include -#include -#include -#include "query.h" - -FsearchQuery * -fsearch_query_new (const char *query, - void (*callback)(void *, void *), - void *callback_data, - void *sender, - bool match_case, - bool enable_regex, - bool auto_search_in_path, - bool search_in_path) -{ - FsearchQuery *q = calloc (1, sizeof (FsearchQuery)); - assert (q != NULL); - if (query) { - q->query = strdup (query); - } - q->callback = callback; - q->callback_data = callback_data; - q->sender = sender; - q->match_case = match_case; - q->enable_regex = enable_regex; - q->auto_search_in_path = auto_search_in_path; - q->search_in_path = search_in_path; - return q; -} - -void -fsearch_query_free (FsearchQuery *query) -{ - assert (query != NULL); - if (query->query) { - free (query->query); - query->query = NULL; - } - free (query); - query = NULL; -} diff --git a/3rdparty/fsearch/query.h b/3rdparty/fsearch/query.h deleted file mode 100644 index 8f175793..00000000 --- a/3rdparty/fsearch/query.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once - -#include - -typedef struct { - char *query; - bool match_case; - bool enable_regex; - bool auto_search_in_path; - bool search_in_path; - - void (*callback)(void *, void *); - void *callback_data; - void *sender; -} FsearchQuery; - -FsearchQuery * -fsearch_query_new(const char *query, - void (*callback)(void *, void *), - void *callback_data, - void *sender, - bool match_case, - bool enable_regex, - bool auto_search_in_path, - bool search_in_path); - -void -fsearch_query_free(FsearchQuery *query); diff --git a/3rdparty/fsearch/string_utils.c b/3rdparty/fsearch/string_utils.c deleted file mode 100644 index 05b452fe..00000000 --- a/3rdparty/fsearch/string_utils.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#include -#include -#include -#include -#include "string_utils.h" - -bool -fs_str_is_empty (const char *str) -{ - // query is considered empty if: - // - fist character is null terminator - // - or it has only space characters - while (*str != '\0') { - if (!isspace (*str)) { - return false; - } - str++; - } - return true; -} - -bool -fs_str_has_upper (const char *strc) -{ - assert (strc != NULL); - const char *ptr = strc; - while (*ptr != '\0') { - if (isupper (*ptr)) { - return true; - } - ptr++; - } - return false; -} - -char * -fs_str_copy (char *dest, char *end, const char *src) -{ - char *ptr = dest; - while (ptr != end && *src != '\0') { - *ptr++ = *src++; - } - *ptr = '\0'; - return ptr; -} - diff --git a/3rdparty/fsearch/string_utils.h b/3rdparty/fsearch/string_utils.h deleted file mode 100644 index 9b335922..00000000 --- a/3rdparty/fsearch/string_utils.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - FSearch - A fast file search utility - Copyright © 2020 Christian Boxdörfer - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . - */ - -#pragma once -#include -#include - -bool -fs_str_is_empty(const char *str); - -bool -fs_str_has_upper(const char *str); - -char * -fs_str_copy(char *dest, - char *end, - const char *src); diff --git a/3rdparty/fsearch/utf8.h b/3rdparty/fsearch/utf8.h deleted file mode 100644 index e47ef423..00000000 --- a/3rdparty/fsearch/utf8.h +++ /dev/null @@ -1,1285 +0,0 @@ -// The latest version of this library is available on GitHub; -// https://github.com/sheredom/utf8.h - -// This is free and unencumbered software released into the public domain. -// -// Anyone is free to copy, modify, publish, use, compile, sell, or -// distribute this software, either in source code form or as a compiled -// binary, for any purpose, commercial or non-commercial, and by any -// means. -// -// In jurisdictions that recognize copyright laws, the author or authors -// of this software dedicate any and all copyright interest in the -// software to the public domain. We make this dedication for the benefit -// of the public at large and to the detriment of our heirs and -// successors. We intend this dedication to be an overt act of -// relinquishment in perpetuity of all present and future rights to this -// software under copyright law. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// For more information, please refer to - -#ifndef SHEREDOM_UTF8_H_INCLUDED -#define SHEREDOM_UTF8_H_INCLUDED - -#if defined(_MSC_VER) -#pragma warning(push) - -// disable 'bytes padding added after construct' warning -#pragma warning(disable : 4820) -#endif - -#include -#include - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - -#if defined(_MSC_VER) -typedef __int32 utf8_int32_t; -#else -#include -typedef int32_t utf8_int32_t; -#endif - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wold-style-cast" -#pragma clang diagnostic ignored "-Wcast-qual" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(__clang__) || defined(__GNUC__) -#define utf8_nonnull __attribute__((nonnull)) -#define utf8_pure __attribute__((pure)) -#define utf8_restrict __restrict__ -#define utf8_weak __attribute__((weak)) -#elif defined(_MSC_VER) -#define utf8_nonnull -#define utf8_pure -#define utf8_restrict __restrict -#define utf8_weak __inline -#else -#error Non clang, non gcc, non MSVC compiler found! -#endif - -#ifdef __cplusplus -#define utf8_null NULL -#else -#define utf8_null 0 -#endif - -// Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > -// src2 respectively, case insensitive. -utf8_nonnull utf8_pure utf8_weak int utf8casecmp(const void *src1, - const void *src2); - -// Append the utf8 string src onto the utf8 string dst. -utf8_nonnull utf8_weak void *utf8cat(void *utf8_restrict dst, - const void *utf8_restrict src); - -// Find the first match of the utf8 codepoint chr in the utf8 string src. -utf8_nonnull utf8_pure utf8_weak void *utf8chr(const void *src, - utf8_int32_t chr); - -// Return less than 0, 0, greater than 0 if src1 < src2, -// src1 == src2, src1 > src2 respectively. -utf8_nonnull utf8_pure utf8_weak int utf8cmp(const void *src1, - const void *src2); - -// Copy the utf8 string src onto the memory allocated in dst. -utf8_nonnull utf8_weak void *utf8cpy(void *utf8_restrict dst, - const void *utf8_restrict src); - -// Number of utf8 codepoints in the utf8 string src that consists entirely -// of utf8 codepoints not from the utf8 string reject. -utf8_nonnull utf8_pure utf8_weak size_t utf8cspn(const void *src, - const void *reject); - -// Duplicate the utf8 string src by getting its size, malloc'ing a new buffer -// copying over the data, and returning that. Or 0 if malloc failed. -utf8_nonnull utf8_weak void *utf8dup(const void *src); - -// Number of utf8 codepoints in the utf8 string str, -// excluding the null terminating byte. -utf8_nonnull utf8_pure utf8_weak size_t utf8len(const void *str); - -// Return less than 0, 0, greater than 0 if src1 < src2, src1 == src2, src1 > -// src2 respectively, case insensitive. Checking at most n bytes of each utf8 -// string. -utf8_nonnull utf8_pure utf8_weak int utf8ncasecmp(const void *src1, - const void *src2, size_t n); - -// Append the utf8 string src onto the utf8 string dst, -// writing at most n+1 bytes. Can produce an invalid utf8 -// string if n falls partway through a utf8 codepoint. -utf8_nonnull utf8_weak void *utf8ncat(void *utf8_restrict dst, - const void *utf8_restrict src, size_t n); - -// Return less than 0, 0, greater than 0 if src1 < src2, -// src1 == src2, src1 > src2 respectively. Checking at most n -// bytes of each utf8 string. -utf8_nonnull utf8_pure utf8_weak int utf8ncmp(const void *src1, - const void *src2, size_t n); - -// Copy the utf8 string src onto the memory allocated in dst. -// Copies at most n bytes. If there is no terminating null byte in -// the first n bytes of src, the string placed into dst will not be -// null-terminated. If the size (in bytes) of src is less than n, -// extra null terminating bytes are appended to dst such that at -// total of n bytes are written. Can produce an invalid utf8 -// string if n falls partway through a utf8 codepoint. -utf8_nonnull utf8_weak void *utf8ncpy(void *utf8_restrict dst, - const void *utf8_restrict src, size_t n); - -// Similar to utf8dup, except that at most n bytes of src are copied. If src is -// longer than n, only n bytes are copied and a null byte is added. -// -// Returns a new string if successful, 0 otherwise -utf8_nonnull utf8_weak void *utf8ndup(const void *src, size_t n); - -// Locates the first occurence in the utf8 string str of any byte in the -// utf8 string accept, or 0 if no match was found. -utf8_nonnull utf8_pure utf8_weak void *utf8pbrk(const void *str, - const void *accept); - -// Find the last match of the utf8 codepoint chr in the utf8 string src. -utf8_nonnull utf8_pure utf8_weak void *utf8rchr(const void *src, int chr); - -// Number of bytes in the utf8 string str, -// including the null terminating byte. -utf8_nonnull utf8_pure utf8_weak size_t utf8size(const void *str); - -// Number of utf8 codepoints in the utf8 string src that consists entirely -// of utf8 codepoints from the utf8 string accept. -utf8_nonnull utf8_pure utf8_weak size_t utf8spn(const void *src, - const void *accept); - -// The position of the utf8 string needle in the utf8 string haystack. -utf8_nonnull utf8_pure utf8_weak void *utf8str(const void *haystack, - const void *needle); - -// The position of the utf8 string needle in the utf8 string haystack, case -// insensitive. -utf8_nonnull utf8_pure utf8_weak void *utf8casestr(const void *haystack, - const void *needle); - -// Return 0 on success, or the position of the invalid -// utf8 codepoint on failure. -utf8_nonnull utf8_pure utf8_weak void *utf8valid(const void *str); - -// Sets out_codepoint to the next utf8 codepoint in str, and returns the address -// of the utf8 codepoint after the current one in str. -utf8_nonnull utf8_weak void * -utf8codepoint(const void *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint); - -// Returns the size of the given codepoint in bytes. -utf8_weak size_t utf8codepointsize(utf8_int32_t chr); - -// Write a codepoint to the given string, and return the address to the next -// place after the written codepoint. Pass how many bytes left in the buffer to -// n. If there is not enough space for the codepoint, this function returns -// null. -utf8_nonnull utf8_weak void *utf8catcodepoint(void *utf8_restrict str, - utf8_int32_t chr, size_t n); - -// Returns 1 if the given character is lowercase, or 0 if it is not. -utf8_weak int utf8islower(utf8_int32_t chr); - -// Returns 1 if the given character is uppercase, or 0 if it is not. -utf8_weak int utf8isupper(utf8_int32_t chr); - -// Transform the given string into all lowercase codepoints. -utf8_nonnull utf8_weak void utf8lwr(void *utf8_restrict str); - -// Transform the given string into all uppercase codepoints. -utf8_nonnull utf8_weak void utf8upr(void *utf8_restrict str); - -// Make a codepoint lower case if possible. -utf8_weak utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp); - -// Make a codepoint upper case if possible. -utf8_weak utf8_int32_t utf8uprcodepoint(utf8_int32_t cp); - -#undef utf8_weak -#undef utf8_pure -#undef utf8_nonnull - -int utf8casecmp(const void *src1, const void *src2) -{ - utf8_int32_t src1_cp, src2_cp, src1_orig_cp, src2_orig_cp; - - for (;;) { - src1 = utf8codepoint(src1, &src1_cp); - src2 = utf8codepoint(src2, &src2_cp); - - // take a copy of src1 & src2 - src1_orig_cp = src1_cp; - src2_orig_cp = src2_cp; - - // lower the srcs if required - src1_cp = utf8lwrcodepoint(src1_cp); - src2_cp = utf8lwrcodepoint(src2_cp); - - // check if the lowered codepoints match - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if (src1_cp == src2_cp) { - continue; - } - - // if they don't match, then we return the difference between the characters - return src1_cp - src2_cp; - } -} - -void *utf8cat(void *utf8_restrict dst, const void *utf8_restrict src) -{ - char *d = (char *)dst; - const char *s = (const char *)src; - - // find the null terminating byte in dst - while ('\0' != *d) { - d++; - } - - // overwriting the null terminating byte in dst, append src byte-by-byte - while ('\0' != *s) { - *d++ = *s++; - } - - // write out a new null terminating byte into dst - *d = '\0'; - - return dst; -} - -void *utf8chr(const void *src, utf8_int32_t chr) -{ - char c[5] = {'\0', '\0', '\0', '\0', '\0'}; - - if (0 == chr) { - // being asked to return position of null terminating byte, so - // just run s to the end, and return! - const char *s = (const char *)src; - while ('\0' != *s) { - s++; - } - return (void *)s; - } else if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - c[0] = (char)chr; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - c[0] = 0xc0 | (char)(chr >> 6); - c[1] = 0x80 | (char)(chr & 0x3f); - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = 0xe0 | (char)(chr >> 12); - c[1] = 0x80 | (char)((chr >> 6) & 0x3f); - c[2] = 0x80 | (char)(chr & 0x3f); - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = 0xf0 | (char)(chr >> 18); - c[1] = 0x80 | (char)((chr >> 12) & 0x3f); - c[2] = 0x80 | (char)((chr >> 6) & 0x3f); - c[3] = 0x80 | (char)(chr & 0x3f); - } - - // we've made c into a 2 utf8 codepoint string, one for the chr we are - // seeking, another for the null terminating byte. Now use utf8str to - // search - return utf8str(src, c); -} - -int utf8cmp(const void *src1, const void *src2) -{ - const unsigned char *s1 = (const unsigned char *)src1; - const unsigned char *s2 = (const unsigned char *)src2; - - while (('\0' != *s1) || ('\0' != *s2)) { - if (*s1 < *s2) { - return -1; - } else if (*s1 > *s2) { - return 1; - } - - s1++; - s2++; - } - - // both utf8 strings matched - return 0; -} - -int utf8coll(const void *src1, const void *src2); - -void *utf8cpy(void *utf8_restrict dst, const void *utf8_restrict src) -{ - char *d = (char *)dst; - const char *s = (const char *)src; - - // overwriting anything previously in dst, write byte-by-byte - // from src - while ('\0' != *s) { - *d++ = *s++; - } - - // append null terminating byte - *d = '\0'; - - return dst; -} - -size_t utf8cspn(const void *src, const void *reject) -{ - const char *s = (const char *)src; - size_t chars = 0; - - while ('\0' != *s) { - const char *r = (const char *)reject; - size_t offset = 0; - - while ('\0' != *r) { - // checking that if *r is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *r)) && (0 < offset)) { - return chars; - } else { - if (*r == s[offset]) { - // part of a utf8 codepoint matched, so move our checking - // onwards to the next byte - offset++; - r++; - } else { - // r could be in the middle of an unmatching utf8 code point, - // so we need to march it on to the next character beginning, - - do { - r++; - } while (0x80 == (0xc0 & *r)); - - // reset offset too as we found a mismatch - offset = 0; - } - } - } - - // the current utf8 codepoint in src did not match reject, but src - // could have been partway through a utf8 codepoint, so we need to - // march it onto the next utf8 codepoint starting byte - do { - s++; - } while ((0x80 == (0xc0 & *s))); - chars++; - } - - return chars; -} - -size_t utf8size(const void *str); - -void *utf8dup(const void *src) -{ - const char *s = (const char *)src; - char *n = utf8_null; - - // figure out how many bytes (including the terminator) we need to copy first - size_t bytes = utf8size(src); - - n = (char *)malloc(bytes); - - if (utf8_null == n) { - // out of memory so we bail - return utf8_null; - } else { - bytes = 0; - - // copy src byte-by-byte into our new utf8 string - while ('\0' != s[bytes]) { - n[bytes] = s[bytes]; - bytes++; - } - - // append null terminating byte - n[bytes] = '\0'; - return n; - } -} - -void *utf8fry(const void *str); - -size_t utf8len(const void *str) -{ - const unsigned char *s = (const unsigned char *)str; - size_t length = 0; - - while ('\0' != *s) { - if (0xf0 == (0xf8 & *s)) { - // 4-byte utf8 code point (began with 0b11110xxx) - s += 4; - } else if (0xe0 == (0xf0 & *s)) { - // 3-byte utf8 code point (began with 0b1110xxxx) - s += 3; - } else if (0xc0 == (0xe0 & *s)) { - // 2-byte utf8 code point (began with 0b110xxxxx) - s += 2; - } else { // if (0x00 == (0x80 & *s)) { - // 1-byte ascii (began with 0b0xxxxxxx) - s += 1; - } - - // no matter the bytes we marched s forward by, it was - // only 1 utf8 codepoint - length++; - } - - return length; -} - -int utf8ncasecmp(const void *src1, const void *src2, size_t n) -{ - utf8_int32_t src1_cp, src2_cp, src1_orig_cp, src2_orig_cp; - - do { - const unsigned char *const s1 = (const unsigned char *)src1; - const unsigned char *const s2 = (const unsigned char *)src2; - - // first check that we have enough bytes left in n to contain an entire - // codepoint - if (0 == n) { - return 0; - } - - if ((1 == n) && ((0xc0 == (0xe0 & *s1)) || (0xc0 == (0xe0 & *s2)))) { - const utf8_int32_t c1 = (0xe0 & *s1); - const utf8_int32_t c2 = (0xe0 & *s2); - - if (c1 < c2) { - return -1; - } else if (c1 > c2) { - return 1; - } else { - return 0; - } - } - - if ((2 >= n) && ((0xe0 == (0xf0 & *s1)) || (0xe0 == (0xf0 & *s2)))) { - const utf8_int32_t c1 = (0xf0 & *s1); - const utf8_int32_t c2 = (0xf0 & *s2); - - if (c1 < c2) { - return -1; - } else if (c1 > c2) { - return 1; - } else { - return 0; - } - } - - if ((3 >= n) && ((0xf0 == (0xf8 & *s1)) || (0xf0 == (0xf8 & *s2)))) { - const utf8_int32_t c1 = (0xf8 & *s1); - const utf8_int32_t c2 = (0xf8 & *s2); - - if (c1 < c2) { - return -1; - } else if (c1 > c2) { - return 1; - } else { - return 0; - } - } - - src1 = utf8codepoint(src1, &src1_cp); - src2 = utf8codepoint(src2, &src2_cp); - n -= utf8codepointsize(src1_cp); - - // Take a copy of src1 & src2 - src1_orig_cp = src1_cp; - src2_orig_cp = src2_cp; - - // Lower srcs if required - src1_cp = utf8lwrcodepoint(src1_cp); - src2_cp = utf8lwrcodepoint(src2_cp); - - // Check if the lowered codepoints match - if ((0 == src1_orig_cp) && (0 == src2_orig_cp)) { - return 0; - } else if (src1_cp == src2_cp) { - continue; - } - - // If they don't match, then we return which of the original's are less - if (src1_orig_cp < src2_orig_cp) { - return -1; - } else if (src1_orig_cp > src2_orig_cp) { - return 1; - } - } while (0 < n); - - // both utf8 strings matched - return 0; -} - -void *utf8ncat(void *utf8_restrict dst, const void *utf8_restrict src, - size_t n) -{ - char *d = (char *)dst; - const char *s = (const char *)src; - - // find the null terminating byte in dst - while ('\0' != *d) { - d++; - } - - // overwriting the null terminating byte in dst, append src byte-by-byte - // stopping if we run out of space - do { - *d++ = *s++; - } while (('\0' != *s) && (0 != --n)); - - // write out a new null terminating byte into dst - *d = '\0'; - - return dst; -} - -int utf8ncmp(const void *src1, const void *src2, size_t n) -{ - const unsigned char *s1 = (const unsigned char *)src1; - const unsigned char *s2 = (const unsigned char *)src2; - - while ((0 != n--) && (('\0' != *s1) || ('\0' != *s2))) { - if (*s1 < *s2) { - return -1; - } else if (*s1 > *s2) { - return 1; - } - - s1++; - s2++; - } - - // both utf8 strings matched - return 0; -} - -void *utf8ncpy(void *utf8_restrict dst, const void *utf8_restrict src, - size_t n) -{ - char *d = (char *)dst; - const char *s = (const char *)src; - size_t index; - - // overwriting anything previously in dst, write byte-by-byte - // from src - for (index = 0; index < n; index++) { - d[index] = s[index]; - if ('\0' == s[index]) { - break; - } - } - - // append null terminating byte - for (; index < n; index++) { - d[index] = 0; - } - - return dst; -} - -void *utf8ndup(const void *src, size_t n) -{ - const char *s = (const char *)src; - char *c = utf8_null; - size_t bytes = 0; - - // Find the end of the string or stop when n is reached - while ('\0' != s[bytes] && bytes < n) { - bytes++; - } - - // In case bytes is actually less than n, we need to set it - // to be used later in the copy byte by byte. - n = bytes; - - c = (char *)malloc(bytes + 1); - if (utf8_null == c) { - // out of memory so we bail - return utf8_null; - } - - bytes = 0; - - // copy src byte-by-byte into our new utf8 string - while ('\0' != s[bytes] && bytes < n) { - c[bytes] = s[bytes]; - bytes++; - } - - // append null terminating byte - c[bytes] = '\0'; - return c; -} - -void *utf8rchr(const void *src, int chr) -{ - const char *s = (const char *)src; - const char *match = utf8_null; - char c[5] = {'\0', '\0', '\0', '\0', '\0'}; - - if (0 == chr) { - // being asked to return position of null terminating byte, so - // just run s to the end, and return! - while ('\0' != *s) { - s++; - } - return (void *)s; - } else if (0 == ((int)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - c[0] = (char)chr; - } else if (0 == ((int)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - c[0] = 0xc0 | (char)(chr >> 6); - c[1] = 0x80 | (char)(chr & 0x3f); - } else if (0 == ((int)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = 0xe0 | (char)(chr >> 12); - c[1] = 0x80 | (char)((chr >> 6) & 0x3f); - c[2] = 0x80 | (char)(chr & 0x3f); - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - c[0] = 0xf0 | (char)(chr >> 18); - c[1] = 0x80 | (char)((chr >> 12) & 0x3f); - c[2] = 0x80 | (char)((chr >> 6) & 0x3f); - c[3] = 0x80 | (char)(chr & 0x3f); - } - - // we've created a 2 utf8 codepoint string in c that is - // the utf8 character asked for by chr, and a null - // terminating byte - - while ('\0' != *s) { - size_t offset = 0; - - while (s[offset] == c[offset]) { - offset++; - } - - if ('\0' == c[offset]) { - // we found a matching utf8 code point - match = s; - s += offset; - } else { - s += offset; - - // need to march s along to next utf8 codepoint start - // (the next byte that doesn't match 0b10xxxxxx) - if ('\0' != *s) { - do { - s++; - } while (0x80 == (0xc0 & *s)); - } - } - } - - // return the last match we found (or 0 if no match was found) - return (void *)match; -} - -void *utf8pbrk(const void *str, const void *accept) -{ - const char *s = (const char *)str; - - while ('\0' != *s) { - const char *a = (const char *)accept; - size_t offset = 0; - - while ('\0' != *a) { - // checking that if *a is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - return (void *)s; - } else { - if (*a == s[offset]) { - // part of a utf8 codepoint matched, so move our checking - // onwards to the next byte - offset++; - a++; - } else { - // r could be in the middle of an unmatching utf8 code point, - // so we need to march it on to the next character beginning, - - do { - a++; - } while (0x80 == (0xc0 & *a)); - - // reset offset too as we found a mismatch - offset = 0; - } - } - } - - // we found a match on the last utf8 codepoint - if (0 < offset) { - return (void *)s; - } - - // the current utf8 codepoint in src did not match accept, but src - // could have been partway through a utf8 codepoint, so we need to - // march it onto the next utf8 codepoint starting byte - do { - s++; - } while ((0x80 == (0xc0 & *s))); - } - - return utf8_null; -} - -size_t utf8size(const void *str) -{ - const char *s = (const char *)str; - size_t size = 0; - while ('\0' != s[size]) { - size++; - } - - // we are including the null terminating byte in the size calculation - size++; - return size; -} - -size_t utf8spn(const void *src, const void *accept) -{ - const char *s = (const char *)src; - size_t chars = 0; - - while ('\0' != *s) { - const char *a = (const char *)accept; - size_t offset = 0; - - while ('\0' != *a) { - // checking that if *r is the start of a utf8 codepoint - // (it is not 0b10xxxxxx) and we have successfully matched - // a previous character (0 < offset) - we found a match - if ((0x80 != (0xc0 & *a)) && (0 < offset)) { - // found a match, so increment the number of utf8 codepoints - // that have matched and stop checking whether any other utf8 - // codepoints in a match - chars++; - s += offset; - break; - } else { - if (*a == s[offset]) { - offset++; - a++; - } else { - // a could be in the middle of an unmatching utf8 codepoint, - // so we need to march it on to the next character beginning, - do { - a++; - } while (0x80 == (0xc0 & *a)); - - // reset offset too as we found a mismatch - offset = 0; - } - } - } - - // if a got to its terminating null byte, then we didn't find a match. - // Return the current number of matched utf8 codepoints - if ('\0' == *a) { - return chars; - } - } - - return chars; -} - -void *utf8str(const void *haystack, const void *needle) -{ - const char *h = (const char *)haystack; - utf8_int32_t throwaway_codepoint; - - // if needle has no utf8 codepoints before the null terminating - // byte then return haystack - if ('\0' == *((const char *)needle)) { - return (void *)haystack; - } - - while ('\0' != *h) { - const char *maybeMatch = h; - const char *n = (const char *)needle; - - while (*h == *n && (*h != '\0' && *n != '\0')) { - n++; - h++; - } - - if ('\0' == *n) { - // we found the whole utf8 string for needle in haystack at - // maybeMatch, so return it - return (void *)maybeMatch; - } else { - // h could be in the middle of an unmatching utf8 codepoint, - // so we need to march it on to the next character beginning - // starting from the current character - h = (const char *)utf8codepoint(maybeMatch, &throwaway_codepoint); - } - } - - // no match - return utf8_null; -} - -void *utf8casestr(const void *haystack, const void *needle) -{ - const void *h = haystack; - - // if needle has no utf8 codepoints before the null terminating - // byte then return haystack - if ('\0' == *((const char *)needle)) { - return (void *)haystack; - } - - for (;;) { - const void *maybeMatch = h; - const void *n = needle; - utf8_int32_t h_cp, n_cp; - - // Get the next code point and track it - const void *nextH = h = utf8codepoint(h, &h_cp); - n = utf8codepoint(n, &n_cp); - - while ((0 != h_cp) && (0 != n_cp)) { - h_cp = utf8lwrcodepoint(h_cp); - n_cp = utf8lwrcodepoint(n_cp); - - // if we find a mismatch, bail out! - if (h_cp != n_cp) { - break; - } - - h = utf8codepoint(h, &h_cp); - n = utf8codepoint(n, &n_cp); - } - - if (0 == n_cp) { - // we found the whole utf8 string for needle in haystack at - // maybeMatch, so return it - return (void *)maybeMatch; - } - - if (0 == h_cp) { - // no match - return utf8_null; - } - - // Roll back to the next code point in the haystack to test - h = nextH; - } -} - -void *utf8valid(const void *str) -{ - const char *s = (const char *)str; - - while ('\0' != *s) { - if (0xf0 == (0xf8 & *s)) { - // ensure each of the 3 following bytes in this 4-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2])) || - (0x80 != (0xc0 & s[3]))) { - return (void *)s; - } - - // ensure that our utf8 codepoint ended after 4 bytes - if (0x80 == (0xc0 & s[4])) { - return (void *)s; - } - - // ensure that the top 5 bits of this 4-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if ((0 == (0x07 & s[0])) && (0 == (0x30 & s[1]))) { - return (void *)s; - } - - // 4-byte utf8 code point (began with 0b11110xxx) - s += 4; - } else if (0xe0 == (0xf0 & *s)) { - // ensure each of the 2 following bytes in this 3-byte - // utf8 codepoint began with 0b10xxxxxx - if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2]))) { - return (void *)s; - } - - // ensure that our utf8 codepoint ended after 3 bytes - if (0x80 == (0xc0 & s[3])) { - return (void *)s; - } - - // ensure that the top 5 bits of this 3-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if ((0 == (0x0f & s[0])) && (0 == (0x20 & s[1]))) { - return (void *)s; - } - - // 3-byte utf8 code point (began with 0b1110xxxx) - s += 3; - } else if (0xc0 == (0xe0 & *s)) { - // ensure the 1 following byte in this 2-byte - // utf8 codepoint began with 0b10xxxxxx - if (0x80 != (0xc0 & s[1])) { - return (void *)s; - } - - // ensure that our utf8 codepoint ended after 2 bytes - if (0x80 == (0xc0 & s[2])) { - return (void *)s; - } - - // ensure that the top 4 bits of this 2-byte utf8 - // codepoint were not 0, as then we could have used - // one of the smaller encodings - if (0 == (0x1e & s[0])) { - return (void *)s; - } - - // 2-byte utf8 code point (began with 0b110xxxxx) - s += 2; - } else if (0x00 == (0x80 & *s)) { - // 1-byte ascii (began with 0b0xxxxxxx) - s += 1; - } else { - // we have an invalid 0b1xxxxxxx utf8 code point entry - return (void *)s; - } - } - - return utf8_null; -} - -void *utf8codepoint(const void *utf8_restrict str, - utf8_int32_t *utf8_restrict out_codepoint) -{ - const char *s = (const char *)str; - - if (0xf0 == (0xf8 & s[0])) { - // 4 byte utf8 codepoint - *out_codepoint = ((0x07 & s[0]) << 18) | ((0x3f & s[1]) << 12) | - ((0x3f & s[2]) << 6) | (0x3f & s[3]); - s += 4; - } else if (0xe0 == (0xf0 & s[0])) { - // 3 byte utf8 codepoint - *out_codepoint = - ((0x0f & s[0]) << 12) | ((0x3f & s[1]) << 6) | (0x3f & s[2]); - s += 3; - } else if (0xc0 == (0xe0 & s[0])) { - // 2 byte utf8 codepoint - *out_codepoint = ((0x1f & s[0]) << 6) | (0x3f & s[1]); - s += 2; - } else { - // 1 byte utf8 codepoint otherwise - *out_codepoint = s[0]; - s += 1; - } - - return (void *)s; -} - -size_t utf8codepointsize(utf8_int32_t chr) -{ - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - return 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - return 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - return 3; - } else { // if (0 == ((int)0xffe00000 & chr)) { - return 4; - } -} - -void *utf8catcodepoint(void *utf8_restrict str, utf8_int32_t chr, size_t n) -{ - char *s = (char *)str; - - if (0 == ((utf8_int32_t)0xffffff80 & chr)) { - // 1-byte/7-bit ascii - // (0b0xxxxxxx) - if (n < 1) { - return utf8_null; - } - s[0] = (char)chr; - s += 1; - } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { - // 2-byte/11-bit utf8 code point - // (0b110xxxxx 0b10xxxxxx) - if (n < 2) { - return utf8_null; - } - s[0] = 0xc0 | (char)(chr >> 6); - s[1] = 0x80 | (char)(chr & 0x3f); - s += 2; - } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { - // 3-byte/16-bit utf8 code point - // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) - if (n < 3) { - return utf8_null; - } - s[0] = 0xe0 | (char)(chr >> 12); - s[1] = 0x80 | (char)((chr >> 6) & 0x3f); - s[2] = 0x80 | (char)(chr & 0x3f); - s += 3; - } else { // if (0 == ((int)0xffe00000 & chr)) { - // 4-byte/21-bit utf8 code point - // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) - if (n < 4) { - return utf8_null; - } - s[0] = 0xf0 | (char)(chr >> 18); - s[1] = 0x80 | (char)((chr >> 12) & 0x3f); - s[2] = 0x80 | (char)((chr >> 6) & 0x3f); - s[3] = 0x80 | (char)(chr & 0x3f); - s += 4; - } - - return s; -} - -int utf8islower(utf8_int32_t chr) { return chr != utf8uprcodepoint(chr); } - -int utf8isupper(utf8_int32_t chr) { return chr != utf8lwrcodepoint(chr); } - -void utf8lwr(void *utf8_restrict str) -{ - void *p, *pn; - utf8_int32_t cp; - - p = (char *)str; - pn = utf8codepoint(p, &cp); - - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8lwrcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); - - if (lwr_cp != cp) { - utf8catcodepoint(p, lwr_cp, size); - } - - p = pn; - pn = utf8codepoint(p, &cp); - } -} - -void utf8upr(void *utf8_restrict str) -{ - void *p, *pn; - utf8_int32_t cp; - - p = (char *)str; - pn = utf8codepoint(p, &cp); - - while (cp != 0) { - const utf8_int32_t lwr_cp = utf8uprcodepoint(cp); - const size_t size = utf8codepointsize(lwr_cp); - - if (lwr_cp != cp) { - utf8catcodepoint(p, lwr_cp, size); - } - - p = pn; - pn = utf8codepoint(p, &cp); - } -} - -utf8_int32_t utf8lwrcodepoint(utf8_int32_t cp) -{ - if (((0x0041 <= cp) && (0x005a >= cp)) || - ((0x00c0 <= cp) && (0x00d6 >= cp)) || - ((0x00d8 <= cp) && (0x00de >= cp)) || - ((0x0391 <= cp) && (0x03a1 >= cp)) || - ((0x03a3 <= cp) && (0x03ab >= cp))) { - cp += 32; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp))) { - cp |= 0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp += 1; - cp &= ~0x1; - } else { - switch (cp) { - default: break; - case 0x0178: cp = 0x00ff; break; - case 0x0243: cp = 0x0180; break; - case 0x018e: cp = 0x01dd; break; - case 0x023d: cp = 0x019a; break; - case 0x0220: cp = 0x019e; break; - case 0x01b7: cp = 0x0292; break; - case 0x01c4: cp = 0x01c6; break; - case 0x01c7: cp = 0x01c9; break; - case 0x01ca: cp = 0x01cc; break; - case 0x01f1: cp = 0x01f3; break; - case 0x01f7: cp = 0x01bf; break; - case 0x0187: cp = 0x0188; break; - case 0x018b: cp = 0x018c; break; - case 0x0191: cp = 0x0192; break; - case 0x0198: cp = 0x0199; break; - case 0x01a7: cp = 0x01a8; break; - case 0x01ac: cp = 0x01ad; break; - case 0x01af: cp = 0x01b0; break; - case 0x01b8: cp = 0x01b9; break; - case 0x01bc: cp = 0x01bd; break; - case 0x01f4: cp = 0x01f5; break; - case 0x023b: cp = 0x023c; break; - case 0x0241: cp = 0x0242; break; - case 0x03fd: cp = 0x037b; break; - case 0x03fe: cp = 0x037c; break; - case 0x03ff: cp = 0x037d; break; - case 0x037f: cp = 0x03f3; break; - case 0x0386: cp = 0x03ac; break; - case 0x0388: cp = 0x03ad; break; - case 0x0389: cp = 0x03ae; break; - case 0x038a: cp = 0x03af; break; - case 0x038c: cp = 0x03cc; break; - case 0x038e: cp = 0x03cd; break; - case 0x038f: cp = 0x03ce; break; - case 0x0370: cp = 0x0371; break; - case 0x0372: cp = 0x0373; break; - case 0x0376: cp = 0x0377; break; - case 0x03f4: cp = 0x03d1; break; - case 0x03cf: cp = 0x03d7; break; - case 0x03f9: cp = 0x03f2; break; - case 0x03f7: cp = 0x03f8; break; - case 0x03fa: cp = 0x03fb; break; - }; - } - - return cp; -} - -utf8_int32_t utf8uprcodepoint(utf8_int32_t cp) -{ - if (((0x0061 <= cp) && (0x007a >= cp)) || - ((0x00e0 <= cp) && (0x00f6 >= cp)) || - ((0x00f8 <= cp) && (0x00fe >= cp)) || - ((0x03b1 <= cp) && (0x03c1 >= cp)) || - ((0x03c3 <= cp) && (0x03cb >= cp))) { - cp -= 32; - } else if (((0x0100 <= cp) && (0x012f >= cp)) || - ((0x0132 <= cp) && (0x0137 >= cp)) || - ((0x014a <= cp) && (0x0177 >= cp)) || - ((0x0182 <= cp) && (0x0185 >= cp)) || - ((0x01a0 <= cp) && (0x01a5 >= cp)) || - ((0x01de <= cp) && (0x01ef >= cp)) || - ((0x01f8 <= cp) && (0x021f >= cp)) || - ((0x0222 <= cp) && (0x0233 >= cp)) || - ((0x0246 <= cp) && (0x024f >= cp)) || - ((0x03d8 <= cp) && (0x03ef >= cp))) { - cp &= ~0x1; - } else if (((0x0139 <= cp) && (0x0148 >= cp)) || - ((0x0179 <= cp) && (0x017e >= cp)) || - ((0x01af <= cp) && (0x01b0 >= cp)) || - ((0x01b3 <= cp) && (0x01b6 >= cp)) || - ((0x01cd <= cp) && (0x01dc >= cp))) { - cp -= 1; - cp |= 0x1; - } else { - switch (cp) { - default: break; - case 0x00ff: cp = 0x0178; break; - case 0x0180: cp = 0x0243; break; - case 0x01dd: cp = 0x018e; break; - case 0x019a: cp = 0x023d; break; - case 0x019e: cp = 0x0220; break; - case 0x0292: cp = 0x01b7; break; - case 0x01c6: cp = 0x01c4; break; - case 0x01c9: cp = 0x01c7; break; - case 0x01cc: cp = 0x01ca; break; - case 0x01f3: cp = 0x01f1; break; - case 0x01bf: cp = 0x01f7; break; - case 0x0188: cp = 0x0187; break; - case 0x018c: cp = 0x018b; break; - case 0x0192: cp = 0x0191; break; - case 0x0199: cp = 0x0198; break; - case 0x01a8: cp = 0x01a7; break; - case 0x01ad: cp = 0x01ac; break; - case 0x01b0: cp = 0x01af; break; - case 0x01b9: cp = 0x01b8; break; - case 0x01bd: cp = 0x01bc; break; - case 0x01f5: cp = 0x01f4; break; - case 0x023c: cp = 0x023b; break; - case 0x0242: cp = 0x0241; break; - case 0x037b: cp = 0x03fd; break; - case 0x037c: cp = 0x03fe; break; - case 0x037d: cp = 0x03ff; break; - case 0x03f3: cp = 0x037f; break; - case 0x03ac: cp = 0x0386; break; - case 0x03ad: cp = 0x0388; break; - case 0x03ae: cp = 0x0389; break; - case 0x03af: cp = 0x038a; break; - case 0x03cc: cp = 0x038c; break; - case 0x03cd: cp = 0x038e; break; - case 0x03ce: cp = 0x038f; break; - case 0x0371: cp = 0x0370; break; - case 0x0373: cp = 0x0372; break; - case 0x0377: cp = 0x0376; break; - case 0x03d1: cp = 0x03f4; break; - case 0x03d7: cp = 0x03cf; break; - case 0x03f2: cp = 0x03f9; break; - case 0x03f8: cp = 0x03f7; break; - case 0x03fb: cp = 0x03fa; break; - }; - } - - return cp; -} - -#undef utf8_restrict -#undef utf8_null - -#ifdef __cplusplus -} // extern "C" -#endif - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - -#endif // SHEREDOM_UTF8_H_INCLUDED diff --git a/LICENSES/GPL-2.0-or-later.txt b/LICENSES/GPL-2.0-or-later.txt deleted file mode 100644 index 17cb2864..00000000 --- a/LICENSES/GPL-2.0-or-later.txt +++ /dev/null @@ -1,117 +0,0 @@ -GNU GENERAL PUBLIC LICENSE -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - -Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. - - c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. - -3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. - -This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author - - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. - -signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice diff --git a/debian/control b/debian/control index e80e2fd9..7a13bbff 100644 --- a/debian/control +++ b/debian/control @@ -22,7 +22,6 @@ Build-Depends: debhelper (>= 9), libavcodec-dev, libtag1-dev, libicu-dev, - libpcre3-dev, libdeepin-pdfium-dev (>=1.5.1), libjpeg62-turbo-dev, liblucene++-dev, diff --git a/src/dde-grand-search-daemon/CMakeLists.txt b/src/dde-grand-search-daemon/CMakeLists.txt index 46d5c718..a3236b38 100644 --- a/src/dde-grand-search-daemon/CMakeLists.txt +++ b/src/dde-grand-search-daemon/CMakeLists.txt @@ -94,46 +94,19 @@ set(SEARCHER searcher/extend/extendsearcher.cpp searcher/extend/extendworker.h searcher/extend/extendworker.cpp + searcher/file/filenamesearcher.h + searcher/file/filenamesearcher.cpp + searcher/file/filenameworker.h + searcher/file/filenameworker.cpp + searcher/file/filenameworker_p.h + searcher/file/filesearchutils.h + searcher/file/filesearchutils.cpp ) -#文件搜索 -if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips" - OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64" - OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw" - OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64" - ) - message(${CMAKE_SYSTEM_PROCESSOR} ": using fsearch") - ADD_DEFINITIONS(-DENABLE_FSEARCH) - FILE(GLOB 3RD_FSEARCH_SRC ${PROJECT_3RDPARTY_PATH}/fsearch/*) - pkg_check_modules(GLIB REQUIRED glib-2.0) - pkg_check_modules(PCRE REQUIRED libpcre) +if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") + ADD_DEFINITIONS(-DENABLE_SEMANTIC) set(SEARCHER ${SEARCHER} - ${3RD_FSEARCH_SRC} - searcher/file/fssearcher.h - searcher/file/fssearcher.cpp - searcher/file/fsworker.h - searcher/file/fsworker.cpp - searcher/file/filesearchutils.h - searcher/file/filesearchutils.cpp - ) - set(LINK_LIBS - ${LINK_LIBS} - ${GLIB_LIBRARIES} - ${PCRE_LIBRARIES} - ) -else () - message(${CMAKE_SYSTEM_PROCESSOR} ": using deepin-anything.") - ADD_DEFINITIONS(-DENABLE_DEEPINANYTHING) - set(SEARCHER - ${SEARCHER} - searcher/file/filenamesearcher.h - searcher/file/filenamesearcher.cpp - searcher/file/filenameworker.h - searcher/file/filenameworker.cpp - searcher/file/filenameworker_p.h - searcher/file/filesearchutils.h - searcher/file/filesearchutils.cpp ${SEMANTIC_FILES} ) @@ -226,7 +199,6 @@ add_executable(${BIN_NAME} target_include_directories(${BIN_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include - ${PROJECT_3RDPARTY_PATH}/fsearch ${GLIB_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS} ${deepin-qdbus-service_INCLUDE_DIR} diff --git a/src/dde-grand-search-daemon/configuration/configer.cpp b/src/dde-grand-search-daemon/configuration/configer.cpp index f8ba67a1..4bf91a9f 100644 --- a/src/dde-grand-search-daemon/configuration/configer.cpp +++ b/src/dde-grand-search-daemon/configuration/configer.cpp @@ -30,16 +30,11 @@ ConfigerPrivate::ConfigerPrivate(Configer *parent) UserPreferencePointer ConfigerPrivate::defaultSearcher() { QVariantHash data = { - #ifdef ENABLE_DEEPINANYTHING {GRANDSEARCH_CLASS_FILE_DEEPIN, true}, - #endif - #ifdef ENABLE_FSEARCH - {GRANDSEARCH_CLASS_FILE_FSEARCH, true}, - #endif - {GRANDSEARCH_CLASS_APP_DESKTOP, true}, - {GRANDSEARCH_CLASS_SETTING_CONTROLCENTER, true}, - {GRANDSEARCH_CLASS_WEB_STATICTEXT, true}, - {GRANDSEARCH_CLASS_GENERALFILE_SEMANTIC, true} + {GRANDSEARCH_CLASS_APP_DESKTOP, true}, + {GRANDSEARCH_CLASS_SETTING_CONTROLCENTER, true}, + {GRANDSEARCH_CLASS_WEB_STATICTEXT, true}, + {GRANDSEARCH_CLASS_GENERALFILE_SEMANTIC, true} }; return UserPreferencePointer(new UserPreference(data)); @@ -103,7 +98,6 @@ bool ConfigerPrivate::updateConfig1(QSettings *set) //文件搜索相关配置 { //初始化文件搜索的子类目 - #ifdef ENABLE_DEEPINANYTHING if (UserPreferencePointer conf = m_root->group(GRANDSEARCH_CLASS_FILE_DEEPIN)) { //若所有的文件类搜索都关闭,则关闭文件搜索项 bool on = false; @@ -136,42 +130,6 @@ bool ConfigerPrivate::updateConfig1(QSettings *set) } else { qWarning() << "no shuch config:" << GRANDSEARCH_CLASS_FILE_DEEPIN; } - #endif - - #ifdef ENABLE_FSEARCH - if (UserPreferencePointer conf = m_root->group(GRANDSEARCH_CLASS_FILE_FSEARCH)) { - //若所有的文件类搜索都关闭,则关闭文件搜索项 - bool on = false; - bool ret = set->value(GRANDSEARCH_GROUP_FOLDER, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FOLDER, ret); - on |= ret; - - ret = set->value(GRANDSEARCH_GROUP_FILE, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FILE, ret); - on |= ret; - - ret = set->value(GRANDSEARCH_GROUP_FILE_VIDEO, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FILE_VIDEO, ret); - on |= ret; - - ret = set->value(GRANDSEARCH_GROUP_FILE_AUDIO, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FILE_AUDIO, ret); - on |= ret; - - ret = set->value(GRANDSEARCH_GROUP_FILE_PICTURE, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FILE_PICTURE, ret); - on |= ret; - - ret = set->value(GRANDSEARCH_GROUP_FILE_DOCUMNET, true).toBool(); - conf->setValue(GRANDSEARCH_GROUP_FILE_DOCUMNET, ret); - on |= ret; - - //设置是否启用文件搜索项 - searcherConfig->setValue(GRANDSEARCH_CLASS_FILE_FSEARCH, on); - } else { - qWarning() << "no shuch config:" << GRANDSEARCH_CLASS_FILE_FSEARCH; - } - #endif } //设置是否启用设置搜索项 @@ -367,13 +325,7 @@ void Configer::initDefault() rootData.insert(GRANDSEARCH_PREF_SEARCHERENABLED, QVariant::fromValue(d->defaultSearcher())); //初始化文件搜索的子类目 -#ifdef ENABLE_DEEPINANYTHING rootData.insert(GRANDSEARCH_CLASS_FILE_DEEPIN, QVariant::fromValue(d->fileSearcher())); -#endif - -#ifdef ENABLE_FSEARCH - rootData.insert(GRANDSEARCH_CLASS_FILE_FSEARCH, QVariant::fromValue(d->fileSearcher())); -#endif // 拖尾 rootData.insert(GRANDSEARCH_TAILER_GROUP, QVariant::fromValue(d->tailerData())); diff --git a/src/dde-grand-search-daemon/maincontroller/maincontroller.cpp b/src/dde-grand-search-daemon/maincontroller/maincontroller.cpp index 0392dcd2..5a85a071 100644 --- a/src/dde-grand-search-daemon/maincontroller/maincontroller.cpp +++ b/src/dde-grand-search-daemon/maincontroller/maincontroller.cpp @@ -115,13 +115,11 @@ QStringList MainControllerPrivate::checkSearcher(const QStringList &groupList, c // 后缀不为空,说明需要文件搜索项 if (!suffixList.isEmpty()) { data.append(GRANDSEARCH_CLASS_FILE_DEEPIN); - data.append(GRANDSEARCH_CLASS_FILE_FSEARCH); } else { // 后缀、类目为空,搜索关键字不为空 // 说明分隔符前后的字段既不是后缀也不是类目 if (groupList.isEmpty() && !keywordList.isEmpty()) { data.append(GRANDSEARCH_CLASS_FILE_DEEPIN); - data.append(GRANDSEARCH_CLASS_FILE_FSEARCH); data.append(GRANDSEARCH_CLASS_APP_DESKTOP); } } diff --git a/src/dde-grand-search-daemon/searcher/file/filenameworker.cpp b/src/dde-grand-search-daemon/searcher/file/filenameworker.cpp index e113cd63..d7670d8b 100644 --- a/src/dde-grand-search-daemon/searcher/file/filenameworker.cpp +++ b/src/dde-grand-search-daemon/searcher/file/filenameworker.cpp @@ -177,7 +177,7 @@ bool FileNameWorkerPrivate::processSearchResults(const SearchResultExpected &res int leave = itemCount(); - qInfo() << "anything search completed, found items:" << m_resultCountHash + qInfo() << "filename search completed, found items:" << m_resultCountHash << "total spend:" << m_time.elapsed() << "current items" << leave; diff --git a/src/dde-grand-search-daemon/searcher/file/fssearcher.cpp b/src/dde-grand-search-daemon/searcher/file/fssearcher.cpp deleted file mode 100644 index f87c5a86..00000000 --- a/src/dde-grand-search-daemon/searcher/file/fssearcher.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "global/grandsearch_global.h" -#include "fssearcher.h" -#include "fsworker.h" -#include "global/builtinsearch.h" -#include "global/searchconfigdefine.h" - -#include - -using namespace GrandSearch; - -#define UPDATE_TIME_THRESHOLD 10*1000 // 索引更新阈值 -#define DB_SAVE_INTERVAL 10*60*1000 // 索引存储时间 - -FsSearcher::FsSearcher(QObject *parent) : Searcher(parent) -{ - -} - -FsSearcher::~FsSearcher() -{ - if (m_isLoading) { - m_isLoading = false; - - m_loadFuture.waitForFinished(); - } - - if (m_isUpdating) - m_updateFuture.waitForFinished(); - - if (m_app) { - if (m_app->db) { - // 现目前重启/注销时,索引会保存失败将冲掉已有索引文件,因此暂时屏蔽 -// db_save_locations(m_app->db); - db_clear(m_app->db); - db_free(m_app->db); - } - - if (m_app->pool) - fsearch_thread_pool_free(m_app->pool); - config_free(m_app->config); - db_search_free(m_app->search); - g_mutex_clear(&m_app->mutex); - free(m_app); - m_app = nullptr; - } - - if (m_databaseForUpdate) { - db_clear(m_databaseForUpdate); - db_free(m_databaseForUpdate); - } -} - -QString FsSearcher::name() const -{ - return GRANDSEARCH_CLASS_FILE_FSEARCH; -} - -bool FsSearcher::isActive() const -{ - return m_isInited; -} - -bool FsSearcher::activate() -{ - return false; -} - -ProxyWorker *FsSearcher::createWorker() const -{ - if (!m_isInited) - return nullptr; - - // 通过数据库时间戳来确定当前是否需要替换数据库 - if ((m_databaseForUpdate->timestamp > m_app->db->timestamp) && !m_isUpdating) - qSwap(m_app->db, m_databaseForUpdate); - - // 索引更新 - if (m_updateTime.elapsed() > UPDATE_TIME_THRESHOLD && !m_isUpdating) { - m_isUpdating = true; - m_updateFuture = QtConcurrent::run(updateDataBase, const_cast(this)); - } - - auto worker = new FsWorker(name()); - worker->setFsearchApp(m_app); - - return worker; -} - -bool FsSearcher::action(const QString &action, const QString &item) -{ - Q_UNUSED(item) - qWarning() << "no such action:" << action << "."; - return false; -} - -void FsSearcher::asyncInitDataBase() -{ - if (m_isInited || m_isLoading) - return; - - m_isLoading = true; - m_loadFuture = QtConcurrent::run(loadDataBase, this); -} - -void FsSearcher::loadDataBase(FsSearcher *fs) -{ - // 计时 - fs->m_updateTime.start(); - - fs->m_app = static_cast(calloc(1, sizeof(FsearchApplication))); - fs->m_app->config = static_cast(calloc(1, sizeof(FsearchConfig))); - config_load_default(fs->m_app->config); - fs->m_app->search = nullptr; - fs->m_app->config->locations = nullptr; - g_mutex_init(&fs->m_app->mutex); - - // 设置应用名,用于设置索引保存路径 - const auto &appName = QCoreApplication::organizationName() + "/" + GRANDSEARCH_DAEMON_NAME; - g_set_application_name(appName.toLocal8Bit().data()); - - // 索引/home/user目录 - QString searPath = QDir::homePath(); - fs->m_app->config->locations = g_list_append(fs->m_app->config->locations, searPath.toLocal8Bit().data()); - load_database(&fs->m_app->db, searPath.toLocal8Bit().data()); - load_database(&fs->m_databaseForUpdate, searPath.toLocal8Bit().data()); - - fs->m_app->pool = fsearch_thread_pool_init(); - fs->m_app->search = db_search_new(fsearch_application_get_thread_pool(fs->m_app)); - - fs->m_isInited = true; - fs->m_isLoading = false; - fs->m_databaseSaveTime.start(); - qInfo() << "load database complete,total items" << db_get_num_entries(fs->m_app->db) << "total spend" << fs->m_updateTime.elapsed(); -} - -void FsSearcher::updateDataBase(FsSearcher *fs) -{ - QElapsedTimer time; - time.start(); - - fs->m_isUpdating = true; - QString searPath = QDir::homePath(); - load_database(&fs->m_databaseForUpdate, searPath.toLocal8Bit().data()); - - fs->saveDataBase(fs->m_databaseForUpdate); - qInfo() << "update database complete,total spend" << time.elapsed(); - fs->m_isUpdating = false; - fs->m_updateTime.restart(); -} - -void FsSearcher::saveDataBase(Database *db) -{ - int cur = m_databaseSaveTime.elapsed(); - if (cur - m_lastSaveTime > DB_SAVE_INTERVAL) { - bool ret = db_save_locations(db); - qDebug() << "database has saved: " << ret; - m_lastSaveTime = cur; - } -} diff --git a/src/dde-grand-search-daemon/searcher/file/fssearcher.h b/src/dde-grand-search-daemon/searcher/file/fssearcher.h deleted file mode 100644 index d1fd6cd4..00000000 --- a/src/dde-grand-search-daemon/searcher/file/fssearcher.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef FSSEARCHER_H -#define FSSEARCHER_H - -#include "searcher/searcher.h" - -extern "C" { -#include "fsearch.h" -} - -#include -#include - -namespace GrandSearch { - -class FsSearcher : public Searcher -{ - Q_OBJECT -public: - explicit FsSearcher(QObject *parent = nullptr); - ~FsSearcher() Q_DECL_OVERRIDE; - QString name() const Q_DECL_OVERRIDE; - bool isActive() const Q_DECL_OVERRIDE; - bool activate() Q_DECL_OVERRIDE; - ProxyWorker *createWorker() const Q_DECL_OVERRIDE; - bool action(const QString &action, const QString &item) Q_DECL_OVERRIDE; - void asyncInitDataBase(); -private: - static void loadDataBase(FsSearcher *fs); - static void updateDataBase(FsSearcher *fs); - void saveDataBase(Database *db); -private: - bool m_isInited = false; - bool m_isLoading = false; - QFuture m_loadFuture; - - FsearchApplication *m_app = nullptr; - mutable Database *m_databaseForUpdate = nullptr; - mutable QElapsedTimer m_updateTime; - mutable bool m_isUpdating = false; - mutable QFuture m_updateFuture; - - QElapsedTimer m_databaseSaveTime; // 索引保存计时 - int m_lastSaveTime = 0; -}; - -} - -#endif // FSSEARCHER_H diff --git a/src/dde-grand-search-daemon/searcher/file/fsworker.cpp b/src/dde-grand-search-daemon/searcher/file/fsworker.cpp deleted file mode 100644 index 2697518b..00000000 --- a/src/dde-grand-search-daemon/searcher/file/fsworker.cpp +++ /dev/null @@ -1,310 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#include "global/grandsearch_global.h" -#include "fsworker.h" -#include "utils/specialtools.h" -#include "global/searchhelper.h" -#include "global/builtinsearch.h" -#include "configuration/configer.h" - -#include - -using namespace GrandSearch; - -#define MAX_SEARCH_NUM 100 -#define EMIT_INTERVAL 50 - -FsWorker::FsWorker(const QString &name, QObject *parent) : ProxyWorker(name, parent) -{ - initConfig(); -} - -void FsWorker::setContext(const QString &context) -{ - if (context.isEmpty()) - qWarning() << "search key is empty."; - m_searchInfo = FileSearchUtils::parseContent(context); -} - -bool FsWorker::isAsync() const -{ - return false; -} - -bool FsWorker::working(void *context) -{ - //准备状态切运行中,否则直接返回 - if (!m_status.testAndSetRelease(Ready, Runing)) - return false; - - Q_UNUSED(context); - if (m_searchInfo.keyword.isEmpty() || !m_app) { - m_status.storeRelease(Completed); - return true; - } - - m_time.start(); - - if (!searchLocalFile()) - return false; - - //检查是否还有数据 - if (m_status.testAndSetRelease(Runing, Completed)) { - //发送数据 - if (hasItem()) - emit unearthed(this); - } - - return true; -} - -void FsWorker::terminate() -{ - m_status.storeRelease(Terminated); -} - -ProxyWorker::Status FsWorker::status() -{ - return static_cast(m_status.loadAcquire()); -} - -bool FsWorker::hasItem() const -{ - QMutexLocker lk(&m_mtx); - for (int i = FileSearchUtils::GroupBegin; i < FileSearchUtils::GroupCount; ++i) - if (!m_items[i].isEmpty()) - return true; - - return false; -} - -GrandSearch::MatchedItemMap FsWorker::takeAll() -{ - QMutexLocker lk(&m_mtx); - //添加分组 - GrandSearch::MatchedItemMap ret; - for (int i = FileSearchUtils::GroupBegin; i < FileSearchUtils::GroupCount; ++i) { - if (!m_items[i].isEmpty()) { - GrandSearch::MatchedItems items = std::move(m_items[i]); - Q_ASSERT(m_items[i].isEmpty()); - ret.insert(FileSearchUtils::groupKey(static_cast(i)), items); - } - } - lk.unlock(); - - return ret; -} - -void FsWorker::setFsearchApp(FsearchApplication *app) -{ - //搜索中不允许设置, 已有数据后不允许更新 - if (m_status.loadAcquire() == Runing || m_app) - return; - - m_app = app; -} - -void FsWorker::initConfig() -{ - // 获取支持的搜索类目 - auto config = Configer::instance()->group(GRANDSEARCH_CLASS_FILE_FSEARCH); - if (config->value(GRANDSEARCH_GROUP_FOLDER, false)) - m_resultCountHash.insert(FileSearchUtils::Folder, 0); - - if (config->value(GRANDSEARCH_GROUP_FILE, false)) - m_resultCountHash.insert(FileSearchUtils::File, 0); - - if (config->value(GRANDSEARCH_GROUP_FILE_VIDEO, false)) - m_resultCountHash.insert(FileSearchUtils::Video, 0); - - if (config->value(GRANDSEARCH_GROUP_FILE_AUDIO, false)) - m_resultCountHash.insert(FileSearchUtils::Audio, 0); - - if (config->value(GRANDSEARCH_GROUP_FILE_PICTURE, false)) - m_resultCountHash.insert(FileSearchUtils::Picture, 0); - - if (config->value(GRANDSEARCH_GROUP_FILE_DOCUMNET, false)) - m_resultCountHash.insert(FileSearchUtils::Document, 0); -} - -void FsWorker::tryNotify() -{ - //50ms推送一次 - int cur = m_time.elapsed(); - if (hasItem() && (cur - m_lastEmit) > EMIT_INTERVAL) { - m_lastEmit = cur; - qDebug() << "unearthed, current spend:" << cur; - emit unearthed(this); - } -} - -int FsWorker::itemCount() const -{ - QMutexLocker lk(&m_mtx); - int count = 0; - for (int i = FileSearchUtils::GroupBegin; i < FileSearchUtils::GroupCount; ++i) - count += m_items[i].size(); - - return count; -} - -bool FsWorker::isResultLimit() -{ - const auto &iter = std::find_if(m_resultCountHash.begin(), m_resultCountHash.end(), [](const int &num){ - return num <= MAX_SEARCH_NUM; - }); - - return iter == m_resultCountHash.end(); -} - -void FsWorker::callbackReceiveResults(void *data, void *sender) -{ - DatabaseSearchResult *result = static_cast(data); - FsWorker *self = static_cast(sender); - Q_ASSERT(result && self); - - if (self->m_app->search == nullptr) { - self->m_conditionMtx.lock(); - self->m_waitCondition.wakeAll(); - self->m_conditionMtx.unlock(); - return; - } - - uint32_t num_results = 0; - if (result->results && result->results->len > 0) { - num_results = result->results->len; - for (uint32_t i = 0; i < num_results; ++i) { - //中断 - if (self->m_status.loadAcquire() != Runing) { - self->m_conditionMtx.lock(); - self->m_waitCondition.wakeAll(); - self->m_conditionMtx.unlock(); - return; - } - - QString fileName; - DatabaseSearchEntry *entry = static_cast(g_ptr_array_index(result->results, i)); - if (entry && entry->node) { - auto *pNode = entry->node; - while (pNode != nullptr) { - //中断 - if (self->m_status.loadAcquire() != Runing) { - self->m_conditionMtx.lock(); - self->m_waitCondition.wakeAll(); - self->m_conditionMtx.unlock(); - return; - } - - if (pNode->name != nullptr) { - fileName.prepend(pNode->name); - if (pNode->parent && strcmp(pNode->name, "") != 0) - fileName.prepend("/"); - } - pNode = pNode->parent; - } - } - - // 过滤文管设置的隐藏文件 - if (GrandSearch::SpecialTools::isHiddenFile(fileName, self->m_hiddenFilters, QDir::homePath())) - continue; - - self->appendSearchResult(fileName); - - //推送 - self->tryNotify(); - - if (self->isResultLimit()) - break; - } - } - - int leave = self->itemCount(); - qInfo() << "search completed, found items:" << self->m_resultCountHash - << "total spend:" << self->m_time.elapsed() - << "current items" << leave; - - self->m_conditionMtx.lock(); - self->m_waitCondition.wakeAll(); - self->m_conditionMtx.unlock(); -} - -bool FsWorker::appendSearchResult(const QString &fileName) -{ - if (m_tmpSearchResults.contains(fileName)) - return false; - - auto group = FileSearchUtils::getGroupByName(fileName); - Q_ASSERT(group >= FileSearchUtils::GroupBegin && group< FileSearchUtils::GroupCount); - - // 根据搜索类目配置判断是否需要进行添加 - if (!m_resultCountHash.contains(group)) { - if (group == FileSearchUtils::Folder) { - return false; - } - - if (m_resultCountHash.contains(FileSearchUtils::File)) { - group = FileSearchUtils::File; - } else { - return false; - } - } - - if (!FileSearchUtils::fileShouldVisible(fileName, group, m_searchInfo)) - return false; - - if (m_resultCountHash[group] >= MAX_SEARCH_NUM || FileSearchUtils::filterByBlacklist(fileName)) - return false; - - m_tmpSearchResults << fileName; - const auto &item = FileSearchUtils::packItem(fileName, name()); - - QMutexLocker lk(&m_mtx); - m_items[group].append(item); - m_resultCountHash[group]++; - - // 非文件类目搜索,不需要向文件类目中添加搜索结果 - if (m_searchInfo.isCombinationSearch && !m_searchInfo.groupList.contains(FileSearchUtils::File)) - return true; - - // 文档、音频、视频、图片需添加到文件组中 - if (group != FileSearchUtils::File && m_resultCountHash.contains(FileSearchUtils::File)) { - if (group != FileSearchUtils::Folder && m_resultCountHash[FileSearchUtils::File] < MAX_SEARCH_NUM) { - m_items[FileSearchUtils::File].append(item); - m_resultCountHash[FileSearchUtils::File]++; - } - } - - return true; -} - -bool FsWorker::searchLocalFile() -{ - db_search_results_clear(m_app->search); - Database *db = m_app->db; - if (!db_try_lock(db)) { - return true; - } - - if (m_app->search) { - db_search_update(m_app->search, - db_get_entries(db), - db_get_num_entries(db), - UINT32_MAX, - FsearchFilter::FSEARCH_FILTER_NONE, - m_searchInfo.keyword.toStdString().c_str(), - m_app->config->hide_results_on_empty_search, - m_app->config->match_case, - true, - m_app->config->auto_search_in_path, - m_app->config->search_in_path); - - m_conditionMtx.lock(); - db_perform_search(m_app->search, callbackReceiveResults, m_app, this); - m_waitCondition.wait(&m_conditionMtx, ULONG_MAX); - m_conditionMtx.unlock(); - } - db_unlock(db); - return true; -} diff --git a/src/dde-grand-search-daemon/searcher/file/fsworker.h b/src/dde-grand-search-daemon/searcher/file/fsworker.h deleted file mode 100644 index 54c47ddf..00000000 --- a/src/dde-grand-search-daemon/searcher/file/fsworker.h +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef FSWORKER_H -#define FSWORKER_H - -#include "searcher/proxyworker.h" -#include "filesearchutils.h" - -extern "C" { -#include "fsearch.h" -} - -namespace GrandSearch { - -class FsWorker : public ProxyWorker -{ -public: - explicit FsWorker(const QString &name, QObject *parent = nullptr); - - void setContext(const QString &context) Q_DECL_OVERRIDE; - bool isAsync() const Q_DECL_OVERRIDE; - bool working(void *context) Q_DECL_OVERRIDE; - void terminate() Q_DECL_OVERRIDE; - Status status() Q_DECL_OVERRIDE; - bool hasItem() const Q_DECL_OVERRIDE; - MatchedItemMap takeAll() Q_DECL_OVERRIDE; - void setFsearchApp(FsearchApplication *app); -private: - void initConfig(); - static void callbackReceiveResults(void *data, void *sender); - bool appendSearchResult(const QString &fileName); - bool searchLocalFile(); - void tryNotify(); - int itemCount() const; - bool isResultLimit(); -private: - FsearchApplication *m_app = nullptr; - QAtomicInt m_status = Ready; - FileSearchUtils::SearchInfo m_searchInfo; // 搜索信息 - - //搜索结果 - mutable QMutex m_mtx; - MatchedItems m_items[FileSearchUtils::GroupCount]; // 文件搜索 - QHash m_resultCountHash; // 记录各类型文件搜索结果数量 - - QWaitCondition m_waitCondition; - QMutex m_conditionMtx; - QSet m_tmpSearchResults; // 存储所有的搜索结果,用于去重 - QHash> m_hiddenFilters; - - QElapsedTimer m_time; //搜索计时 - int m_lastEmit = 0; -}; - -} - -#endif // FSWORKER_H diff --git a/src/dde-grand-search-daemon/searcher/searchergroup.cpp b/src/dde-grand-search-daemon/searcher/searchergroup.cpp index 89778ebe..5469bb70 100644 --- a/src/dde-grand-search-daemon/searcher/searchergroup.cpp +++ b/src/dde-grand-search-daemon/searcher/searchergroup.cpp @@ -19,18 +19,9 @@ void SearcherGroupPrivate::initBuiltin() { Q_ASSERT(m_builtin.isEmpty()); -#ifdef ENABLE_DEEPINANYTHING qInfo() << "create FileNameSearcher"; auto fileSearcher = new FileNameSearcher(this); m_builtin << fileSearcher; -#endif - -#ifdef ENABLE_FSEARCH - qInfo() << "create FsSearcher."; - auto fSearcher = new FsSearcher(this); - fSearcher->asyncInitDataBase(); - m_builtin << fSearcher; -#endif qInfo() << "create DesktopAppSearcher."; auto appSearcher = new DesktopAppSearcher(this); @@ -41,7 +32,7 @@ void SearcherGroupPrivate::initBuiltin() auto stWebSearcher = new StaticTextEchoer(this); m_builtin << stWebSearcher; -#ifdef ENABLE_DEEPINANYTHING +#ifdef ENABLE_SEMANTIC qInfo() << "create SemanticSearcher."; auto semanticSearcher = new SemanticSearcher(this); m_builtin << semanticSearcher; diff --git a/src/dde-grand-search-daemon/searcher/searchergroup_p.h b/src/dde-grand-search-daemon/searcher/searchergroup_p.h index 63236785..3f9959d2 100644 --- a/src/dde-grand-search-daemon/searcher/searchergroup_p.h +++ b/src/dde-grand-search-daemon/searcher/searchergroup_p.h @@ -11,14 +11,7 @@ #include "extend/extendsearcher.h" #include "web/statictextechoer.h" #include "semantic/semanticsearcher.h" - -#ifdef ENABLE_DEEPINANYTHING - #include "file/filenamesearcher.h" -#endif - -#ifdef ENABLE_FSEARCH - #include "file/fssearcher.h" -#endif +#include "file/filenamesearcher.h" namespace GrandSearch { diff --git a/src/global/builtinsearch.h b/src/global/builtinsearch.h index f357178e..98f3f82c 100644 --- a/src/global/builtinsearch.h +++ b/src/global/builtinsearch.h @@ -7,7 +7,6 @@ // 定义内置搜索项的名称 #define GRANDSEARCH_CLASS_FILE_DEEPIN "com.deepin.dde-grand-search.file-deepin" -#define GRANDSEARCH_CLASS_FILE_FSEARCH "com.deepin.dde-grand-search.file-fsearch" #define GRANDSEARCH_CLASS_APP_DESKTOP "com.deepin.dde-grand-search.app-desktop" #define GRANDSEARCH_CLASS_SETTING_CONTROLCENTER "com.deepin.dde-grand-search.dde-control-center-setting" #define GRANDSEARCH_CLASS_WEB_STATICTEXT "com.deepin.dde-grand-search.web-statictext" @@ -61,7 +60,6 @@ #define DEF_BUILTISEARCH_NAMES \ static const QStringList predefBuiltinSearches { \ GRANDSEARCH_CLASS_FILE_DEEPIN, \ -GRANDSEARCH_CLASS_FILE_FSEARCH, \ GRANDSEARCH_CLASS_APP_DESKTOP, \ GRANDSEARCH_CLASS_WEB_STATICTEXT, \ GRANDSEARCH_CLASS_GENERALFILE_SEMANTIC \ diff --git a/src/global/searchhelper.cpp b/src/global/searchhelper.cpp index 1423c4a8..085cf689 100644 --- a/src/global/searchhelper.cpp +++ b/src/global/searchhelper.cpp @@ -38,12 +38,12 @@ void SearchHelper::initGroupSuffixTable() void SearchHelper::initGroupSearcherTable() { - m_groupSearcherHash.insert(DOCUMENT_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); - m_groupSearcherHash.insert(PICTURE_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); - m_groupSearcherHash.insert(AUDIO_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); - m_groupSearcherHash.insert(VIDEO_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); - m_groupSearcherHash.insert(FILE_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); - m_groupSearcherHash.insert(FOLDER_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN, GRANDSEARCH_CLASS_FILE_FSEARCH}); + m_groupSearcherHash.insert(DOCUMENT_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); + m_groupSearcherHash.insert(PICTURE_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); + m_groupSearcherHash.insert(AUDIO_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); + m_groupSearcherHash.insert(VIDEO_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); + m_groupSearcherHash.insert(FILE_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); + m_groupSearcherHash.insert(FOLDER_GROUP, {GRANDSEARCH_CLASS_FILE_DEEPIN}); m_groupSearcherHash.insert(APPLICATION_GROUP, {GRANDSEARCH_CLASS_APP_DESKTOP}); } diff --git a/src/grand-search/utils/utils.cpp b/src/grand-search/utils/utils.cpp index 06fff19a..46d27cea 100644 --- a/src/grand-search/utils/utils.cpp +++ b/src/grand-search/utils/utils.cpp @@ -317,9 +317,7 @@ bool Utils::setWeightMethod(MatchedItem &item) return true; const QString &search = item.searcher; - if (search == GRANDSEARCH_CLASS_FILE_DEEPIN || - search == GRANDSEARCH_CLASS_FILE_FSEARCH) { - + if (search == GRANDSEARCH_CLASS_FILE_DEEPIN) { ext.insert(GRANDSEARCH_PROPERTY_WEIGHT_METHOD, GRANDSEARCH_PROPERTY_WEIGHT_METHOD_LOCALFILE); } else if (search == GRANDSEARCH_CLASS_APP_DESKTOP) { @@ -490,7 +488,6 @@ void Utils::packageBestMatch(MatchedItemMap &map, int maxQuantity) static const QMap supprotedSeracher = { {GRANDSEARCH_CLASS_FILE_DEEPIN, true}, - {GRANDSEARCH_CLASS_FILE_FSEARCH, true}, {GRANDSEARCH_CLASS_APP_DESKTOP, true}, {GRANDSEARCH_CLASS_SETTING_CONTROLCENTER, true}, }; @@ -774,7 +771,7 @@ bool Utils::openMatchedItem(const MatchedItem &item) bool Utils::openMatchedItemWithCtrl(const MatchedItem &item) { - if (GRANDSEARCH_CLASS_FILE_DEEPIN == item.searcher || GRANDSEARCH_CLASS_FILE_FSEARCH == item.searcher) { + if (GRANDSEARCH_CLASS_FILE_DEEPIN == item.searcher) { QFileInfo fileInfo(item.item); if (!fileInfo.isDir()) return openInFileManager(item); @@ -955,7 +952,7 @@ QIcon Utils::defaultIcon(const MatchedItem &item) { if (item.searcher == GRANDSEARCH_CLASS_APP_DESKTOP) return QIcon::fromTheme("application-x-desktop"); - else if (item.searcher == GRANDSEARCH_CLASS_FILE_DEEPIN || item.searcher == GRANDSEARCH_CLASS_FILE_FSEARCH) { + else if (item.searcher == GRANDSEARCH_CLASS_FILE_DEEPIN) { return QIcon::fromTheme(m_mimeDb.mimeTypeForFile(item.item).genericIconName()); } else if (item.searcher == GRANDSEARCH_CLASS_WEB_STATICTEXT) { // 使用默认浏览器的图标