its all C now

This commit is contained in:
anon
2024-08-07 00:16:11 +02:00
parent cb89a9927b
commit 8f387e9c63
13 changed files with 60 additions and 60 deletions

View File

@ -1,43 +1,43 @@
.PHONY: clean run
ifeq (${DEBUG}, 1)
CXXFLAGS += -DDEBUG -O0 -ggdb -fno-inline
CFLAGS += -DDEBUG -O0 -ggdb -fno-inline
WRAP := valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all
else
CXXFLAGS += -O3 -fno-stack-protector -fno-exceptions -fno-rtti
CFLAGS += -O3
endif
LIBFLAGS := $$(pkgconf --cflags ncurses readline sqlite3)
CXXFLAGS += -std=gnu++20 -I./source/ -I./object/ -I./ ${LIBFLAGS}
CXXFLAGS += -Wall -Wextra -Wpedantic
LINKasd += $$(pkgconf --libs ncurses readline sqlite3)
CFLAGS += -std=c2x -I./source/ -I./object/ -I./ ${LIBFLAGS}
CFLAGS += -Wall -Wextra -Wpedantic
LDLIBS += $$(pkgconf --libs ncurses readline sqlite3)
OBJECT.d:=object/
SOURCE.d:=source/
SOURCE:=argument_yy.tab.cpp bash_history.yy.cpp main.cpp cli.cpp tui.cpp storage.cpp damerau_levenshtein.cpp
SOURCE:=argument_yy.tab.c bash_history.yy.c main.c cli.c tui.c storage.c damerau_levenshtein.c
OBJECT:=$(addprefix ${OBJECT.d},$(addsuffix .o,$(basename ${SOURCE})))
SOURCE:=$(addprefix ${SOURCE.d},${SOURCE})
OUTPUT:=histui
${OUTPUT}: ${OBJECT}
${LINK.cpp} ${OBJECT} ${LINKasd} -o ${OUTPUT}
${LINK.c} -o ${OUTPUT} ${OBJECT} ${LDLIBS}
object/%.yy.cpp: source/%.l
flex --prefix=$*_ --header-file=$(basename $@).hpp -o $@ $<
object/%.yy.c: source/%.l
flex --prefix=$*_ --header-file=$(basename $@).h -o $@ $<
object/%.tab.cpp: source/%.y
bison --name-prefix=$*_ --header=$(basename $@).hpp -o $@ $<
object/%.tab.c: source/%.y
bison --name-prefix=$*_ --header=$(basename $@).h -o $@ $<
object/%.o: object/%.l.cpp
${COMPILE.cpp} $< -o $@
object/%.o: object/%.l.c
${COMPILE.c} $< -o $@
object/%.o: source/%.cpp
${COMPILE.cpp} $< -o $@
object/%.o: source/%.c
${COMPILE.c} $< -o $@
clean:
-rm ${OBJECT.d}/*
-rm ./${OUTPUT}
-${RM} ${OBJECT.d}/*
-${RM} ./${OUTPUT}
test:
${WRAP} ./${OUTPUT}

View File

@ -1,4 +1,4 @@
+ make (potentially slow) queries cancel using multi threading
+ scroll lags
+ scroll flashes
+ technical dept in tui.cpp
+ migrate to C
+ man page
+ readme

View File

@ -2,8 +2,9 @@
%token TUI ENABLE
%token LEVENSTEIN CASELESS
%{
#include "cli.hpp"
#include "storage.hpp"
#include <stdlib.h>
#include "cli.h"
#include "storage.h"
extern bool do_execute;
%}
%%

View File

@ -1,6 +1,6 @@
%{
#include "entry.h"
#include "storage.hpp"
#include "storage.h"
long timestamp;
%}
%option nodefault

View File

@ -1,10 +1,10 @@
#include "cli.hpp"
#include "cli.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argument_yy.tab.hpp"
#include "argument_yy.tab.h"
int * arg_tokens;
@ -36,20 +36,18 @@ void enable(void) {
);
*/
puts(
R"delim(
function _histui_run() {
COMMANDFILE="${XDG_CACHE_HOME}/histui_command.txt"
if ! [ -v HISTUICMD ]; then
HISTUICMD="histui tui"
fi
HISTFILE=$HISTFILE ${HISTUICMD} 3> "${COMMANDFILE}"
READLINE_LINE=$(cat "${COMMANDFILE}")
READLINE_POINT=${#READLINE_LINE}
}
bind -x '"\e[A": _histui_run'
bind -x '"\C-r": _histui_run'
)delim"
"function _histui_run() {\n"
" COMMANDFILE=\"${XDG_CACHE_HOME}/histui_command.txt\"\n"
" if ! [ -v HISTUICMD ]; then\n"
" HISTUICMD=\"histui tui\"\n"
" fi\n"
" HISTFILE=$HISTFILE ${HISTUICMD} 3> \"${COMMANDFILE}\"\n"
" READLINE_LINE=$(cat \"${COMMANDFILE}\")\n"
" READLINE_POINT=${#READLINE_LINE}\n"
"}\n"
"\n"
"bind -x '\"\\e[A\": _histui_run'\n"
"bind -x '\"\\C-r\": _histui_run'\n"
);
}

View File

@ -2,10 +2,10 @@
#include <pthread.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "cli.hpp"
#include "bash_history.yy.hpp"
#include "storage.hpp"
#include "tui.hpp"
#include "cli.h"
#include "bash_history.yy.h"
#include "storage.h"
#include "tui.h"
bool do_run = true;
bool do_execute = false;
@ -60,14 +60,15 @@ void export_result(const char * const result) {
* XXX: if anyone knows a better method, please tell me
*/
int fd[2];
pipe(fd);
int rc = pipe(fd);
(void)rc;
dprintf(3, result);
close(fd[0]);
close(fd[1]);
}
}
void * async(void * arg) {
void * async([[maybe_unused]] void * arg) {
while (do_run) {
tui_take_input();
if (is_input_changed) {

View File

@ -1,8 +1,9 @@
#include "storage.hpp"
#include "storage.h"
#include <stddef.h>
#include <iso646.h>
#include <sqlite3.h>
#include "damerau_levenshtein.hpp"
#include "damerau_levenshtein.h"
/* I would heavily prefer to not have dynamically generated SQL.
* This might became a scaling issue in the future tho,

View File

@ -1,4 +1,4 @@
#include "tui.hpp"
#include "tui.h"
#include <time.h>
#include <ncurses.h>
@ -59,13 +59,10 @@ int init_tui(void) {
rl_deprep_term_function = NULL;
rl_change_environment = 0;
rl_getc_function = []([[maybe_unused]] FILE* ignore){
input_available = false;
return (int)input;
};
rl_input_available_hook = []{
return input_available;
};
int getc_function([[maybe_unused]] FILE* ignore) { return (int)(input_available = false); }
int return_input_available(void) { return input_available; }
rl_getc_function = getc_function;
rl_input_available_hook = return_input_available;
rl_redisplay_function = refresh_input;
/* We must specify an input handler or readline chimps out,
* but we dont want the line to be actually submittable,
@ -73,8 +70,10 @@ int init_tui(void) {
* has typedso far)
* so we also override enter to do nothing.
*/
rl_callback_handler_install("", []([[maybe_unused]] char *line){ ; });
rl_bind_key('\n', []([[maybe_unused]] int i, [[maybe_unused]] int h){ return 0; });
void no_op_handler([[maybe_unused]] char *line) { ; }
int no_op_bind([[maybe_unused]] int i, [[maybe_unused]] int h) { return 0; }
rl_callback_handler_install("", no_op_handler);
rl_bind_key('\n', no_op_bind);
return 0;
}

View File

@ -4,7 +4,7 @@
#include <stddef.h>
#include "entry.h"
extern "C" char * rl_line_buffer;
extern char * rl_line_buffer;
extern size_t entry_lines;
extern size_t selection_offset;