Compare commits

...

3 Commits

3 changed files with 13 additions and 12 deletions

View File

@ -3,7 +3,8 @@ cmake_minimum_required (VERSION 3.1)
project (sdn VERSION 0.1 LANGUAGES CXX)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set (CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-misleading-indentation -pedantic")
endif ()
# Since we use a language with slow compilers, let's at least use a fast linker

View File

@ -1,19 +1,19 @@
.POSIX:
SHELL = /bin/sh
CXXFLAGS = -g -std=c++14 -Wall -Wextra -pedantic
CXXFLAGS = -g -std=c++14 -Wall -Wextra -Wno-misleading-indentation -pedantic
CPPFLAGS = `sed -ne '/^project (\([^ )]*\) VERSION \([^ )]*\).*/ \
s//-DPROJECT_NAME="\1" -DPROJECT_VERSION="\2"/p' CMakeLists.txt`
sdn: sdn.cpp CMakeLists.txt
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o sdn \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ \
-lacl `pkg-config --libs --cflags ncursesw`
static: sdn.cpp CMakeLists.txt
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o sdn \
sdn-static: sdn.cpp CMakeLists.txt
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ \
-static-libstdc++ \
-Wl,--start-group,-Bstatic \
-lacl `pkg-config --static --libs --cflags ncursesw` \
-Wl,--end-group,-Bdynamic
clean:
rm -f sdn
rm -f sdn sdn-static
.PHONY: static clean
.PHONY: clean

10
sdn.cpp
View File

@ -93,8 +93,8 @@ fun to_mb (const wstring &wide) -> string {
return mb;
}
fun prefix_length (const wstring &in, const wstring &of) -> int {
int score = 0;
fun prefix_length (const wstring &in, const wstring &of) -> size_t {
size_t score = 0;
for (size_t i = 0; i < of.size () && in.size () >= i && in[i] == of[i]; i++)
score++;
return score;
@ -1008,10 +1008,10 @@ fun show_help () {
fun search (const wstring &needle, int push) -> int {
int best = g.cursor, best_n = 0, matches = 0, step = push != 0 ? push : 1;
for (int i = 0, count = g.entries.size (); i < count; i++) {
auto o = (g.cursor + (count + i * step) + (count + push)) % count;
int n = prefix_length (to_wide (g.entries[o].filename), needle);
int o = (g.cursor + (count + i * step) + (count + push)) % count;
size_t n = prefix_length (to_wide (g.entries[o].filename), needle);
matches += n == needle.size ();
if (n > best_n) {
if (n > (size_t) best_n) {
best = o;
best_n = n;
}