diff options
author | pgen <p.gen.progs@gmail.com> | 2018-10-10 23:47:29 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2018-10-11 01:02:41 +0200 |
commit | 2aeefb23a183f4de00bc389c21c6c5669d4b9a69 (patch) | |
tree | 263154318e7bbfe82d06c574cabd83be1888d763 | |
parent | fdc9bbedae48ef73e040b2ad0bd4d637261346f9 (diff) |
Various small changes
-rw-r--r-- | fgetc.c | 6 | ||||
-rw-r--r-- | index.c | 2 | ||||
-rw-r--r-- | index.h | 4 | ||||
-rw-r--r-- | list.c | 24 | ||||
-rw-r--r-- | list.h | 13 | ||||
-rw-r--r-- | smenu.c | 35 | ||||
-rw-r--r-- | utf8.c | 4 | ||||
-rw-r--r-- | utils.c | 8 | ||||
-rw-r--r-- | xmalloc.c | 2 |
9 files changed, 51 insertions, 47 deletions
@@ -1,10 +1,10 @@ -#include <stdio.h> -#include "fgetc.h" - /* ************************************************************************ */ /* Custom fgetc/ungetc implementation able to unget more than one character */ /* ************************************************************************ */ +#include <stdio.h> +#include "fgetc.h" + enum { GETC_BUFF_SIZE = 16 @@ -1,5 +1,5 @@ /* *************************************************************** */ -/* Ternary Search Tree functions */ +/* Ternary Search Tree and sorted array creation functions */ /* Inspired by: https://www.cs.princeton.edu/~rs/strings/tstdemo.c */ /* *************************************************************** */ @@ -1,5 +1,5 @@ -#ifndef TST_H -#define TST_H +#ifndef INDEX_H +#define INDEX_H /* *************************************** */ /* Ternary Search Tree specific structures */ @@ -1,13 +1,3 @@ -#include "config.h" -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> -#include <errno.h> - -#include "xmalloc.h" -#include "list.h" - /* ********************************************************************* */ /* Tiny list immplementation. */ /* */ @@ -18,6 +8,16 @@ /* the structure members (head, tail, len, data, prev, next) */ /* ********************************************************************* */ +#include "config.h" +#include <stdio.h> +#include <stdlib.h> +#include <limits.h> +#include <string.h> +#include <errno.h> + +#include "xmalloc.h" +#include "list.h" + /* ======================== */ /* Create a new linked list */ /* ======================== */ @@ -186,7 +186,7 @@ ll_insert_after(ll_t * const list, ll_node_t * node, void * const data) /* Based on code found here: */ /* http://www.geeksforgeeks.org/quicksort-for-linked-list */ /* ====================================================== */ -ll_node_t * +static ll_node_t * ll_partition(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *), void (*swap)(void *, void *)) { @@ -221,7 +221,7 @@ ll_partition(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *), /* ======================================================= */ /* A recursive implementation of quicksort for linked list */ /* ======================================================= */ -void +static void ll_quicksort(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *), void (*swap)(void * a, void *)) { @@ -29,21 +29,20 @@ struct ll_s int ll_append(ll_t * const list, void * const data); -#if 0 /* here for coherency but not used. */ -int ll_prepend(ll_t * const list, void *const data); +int +ll_prepend(ll_t * const list, void * const data); void -ll_insert_before(ll_t * const list, ll_node_t * node, void *const data); +ll_insert_before(ll_t * const list, ll_node_t * node, void * const data); void -ll_insert_after(ll_t * const list, ll_node_t * node, void *const data); -#endif +ll_insert_after(ll_t * const list, ll_node_t * node, void * const data); -ll_node_t * +static ll_node_t * ll_partition(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *), void (*swap)(void *, void *)); -void +static void ll_quicksort(ll_node_t * l, ll_node_t * h, int (*comp)(void *, void *), void (*swap)(void * a, void *)); @@ -1055,7 +1055,7 @@ update_bitmaps(search_mode_t mode, search_data_t * data, char * str; /* copy of the current word put in lower case */ char * str_orig; /* oiginal version of the word */ - char * first_mb; + char * first_glyph; char * sb_orig = data->buf; /* sb: search buffer */ char * sb; @@ -1072,7 +1072,7 @@ update_bitmaps(search_mode_t mode, search_data_t * data, if (mode == FUZZY || mode == SUBSTRING) { - first_mb = xmalloc(5); + first_glyph = xmalloc(5); if (mode == FUZZY) { @@ -1196,7 +1196,8 @@ update_bitmaps(search_mode_t mode, search_data_t * data, long i = 1; long utf8_len; - first_mb = utf8_strprefix(first_mb, word_a[n].str, 1, &utf8_len); + first_glyph = utf8_strprefix(first_glyph, word_a[n].str, 1, + &utf8_len); if (!BIT_ISSET(word_a[n].bitmap, 0)) { @@ -1204,7 +1205,7 @@ update_bitmaps(search_mode_t mode, search_data_t * data, ptr1 = word_a[n].str; while ((ptr2 = utf8_next(ptr1)) != NULL) { - if (memcmp(ptr2, first_mb, utf8_len) == 0) + if (memcmp(ptr2, first_glyph, utf8_len) == 0) { if (BIT_ISSET(word_a[n].bitmap, i)) { @@ -1278,7 +1279,7 @@ update_bitmaps(search_mode_t mode, search_data_t * data, if (mode == FUZZY) free(sb); - free(first_mb); + free(first_glyph); } else if (mode == PREFIX) { @@ -3962,7 +3963,7 @@ select_ending_matches(win_t * win, term_t * term, search_data_t * search_data, long nb; long * tmp; char * ptr; - char * last_mb; + char * last_glyph; int utf8_len; /* Creation of an alternate array which will */ @@ -4004,12 +4005,12 @@ select_ending_matches(win_t * win, term_t * term, search_data_t * search_data, /* """""""""""""""""""""""""""""""""""""""""""""""""" */ if (search_mode == FUZZY) { - utf8_len = mblen(ptr, 4); - last_mb = search_data->buf + search_data->len - utf8_len; + utf8_len = mblen(ptr, 4); + last_glyph = search_data->buf + search_data->len - utf8_len; /* in fuzzy search mode we only look the last glyph */ /* """""""""""""""""""""""""""""""""""""""""""""""" */ - if (memcmp(ptr, last_mb, utf8_len) == 0) + if (memcmp(ptr, last_glyph, utf8_len) == 0) alt_matching_words_a[j++] = index; else memset(word_a[index].bitmap, '\0', @@ -4071,13 +4072,13 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data, long index; long * tmp; long pos; - char * first_mb; + char * first_glyph; int utf8_len; alt_matching_words_a = xrealloc(alt_matching_words_a, matches_count * (sizeof(long))); - first_mb = xmalloc(5); + first_glyph = xmalloc(5); for (i = 0; i < matches_count; i++) { @@ -4088,14 +4089,14 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data, { if (search_mode == FUZZY) { - first_mb = utf8_strprefix(first_mb, - word_a[index].str + daccess.flength, 1, - &pos); - utf8_len = pos; + first_glyph = utf8_strprefix(first_glyph, + word_a[index].str + daccess.flength, 1, + &pos); + utf8_len = pos; /* in fuzzy search mode we only look the first glyph */ /* """"""""""""""""""""""""""""""""""""""""""""""""" */ - if (memcmp(search_data->buf, first_mb, utf8_len) == 0) + if (memcmp(search_data->buf, first_glyph, utf8_len) == 0) alt_matching_words_a[j++] = index; else memset(word_a[index].bitmap, '\0', @@ -4115,7 +4116,7 @@ select_starting_matches(win_t * win, term_t * term, search_data_t * search_data, } } - free(first_mb); + free(first_glyph); matches_count = j; matching_words_a_size = j; @@ -1,3 +1,7 @@ +/* ************************************ */ +/* Various UTF-8 manipulation functions */ +/* ************************************ */ + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -1,3 +1,7 @@ +/* ******************************* */ +/* Various small utility functions */ +/* ******************************* */ + #include <stdlib.h> #include <limits.h> #include <string.h> @@ -180,10 +184,6 @@ strprefix(char * str1, char * str2) return *str2 == '\0'; } -/* ***************************** */ -/* Strings and utility functions */ -/* ***************************** */ - /* ======================= */ /* Trim leading characters */ /* ======================= */ @@ -1,5 +1,5 @@ /* *************************** */ -/* Memory allocation functions */ +/* Memory management functions */ /* *************************** */ /* Created by Kevin Locke (from numerous canonical examples) */ |