Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
871ea8a
feat: a brand new hhss!
logic-finder Jun 8, 2026
4ab730a
fix: prevent undersize
logic-finder Jun 8, 2026
2c6230f
fix: catch a leak
logic-finder Jun 8, 2026
9b60a00
fix: 4x size? no way!
logic-finder Jun 8, 2026
d784688
fix: parse logic error
logic-finder Jun 8, 2026
5424eb6
fix: catch a leak
logic-finder Jun 8, 2026
3837b48
fix: `vfatal` prototype argument order
logic-finder Jun 8, 2026
d57f8c7
fix: use a correct format specifier
logic-finder Jun 8, 2026
6d28134
fix: make it phony
logic-finder Jun 8, 2026
34e78d5
fix: add the missing `clean` rule
logic-finder Jun 9, 2026
a7495b6
fix: leave comments and organize
logic-finder Jun 9, 2026
c11782c
fix: canopen
logic-finder Jun 9, 2026
3d08f03
fix: prevent storing an empty line when parsing dtdb
logic-finder Jun 9, 2026
707136c
fix: handle a comment when parsing rtdb
logic-finder Jun 9, 2026
79ce6a9
fix: a typo: entires => entries
logic-finder Jun 9, 2026
94816ab
fix: rewind if not ${x}
logic-finder Jun 9, 2026
44459e0
fix: split misbehavior
logic-finder Jun 9, 2026
4444250
fix: update databases
logic-finder Jun 9, 2026
0ccccb1
fix: update dat.db
logic-finder Jun 9, 2026
0b4af55
fix: modify make help message
logic-finder Jun 10, 2026
b047986
fix: make $(TARGETS) phony
logic-finder Jun 10, 2026
9d27536
fix: enhance dat.db
logic-finder Jun 10, 2026
88b48fb
fix: use silent include
logic-finder Jun 10, 2026
56007c8
fix: -o $(notdir)
logic-finder Jun 10, 2026
b2c62d2
fix: rename common -> lib
logic-finder Jun 10, 2026
8d2c3cd
fix: use direct stdio calls
logic-finder Jun 10, 2026
aa0812a
fix: have a separate makefile for test and test-maker
logic-finder Jun 10, 2026
1521068
fix: put a \n
logic-finder Jun 10, 2026
956353c
fix: bypass postposition problems in strings having replate templates
logic-finder Jun 10, 2026
9c9276e
hotfix: modify cleanall recipe
logic-finder Jun 10, 2026
aeb3f97
fix: modify argv1parse()
logic-finder Jun 10, 2026
b268325
fix: makefiles
logic-finder Jun 10, 2026
60568d2
fix: take care of the first selection
logic-finder Jun 10, 2026
e729e44
fix: rename sighandler => sigprocessor
logic-finder Jun 10, 2026
ddff99c
fix: safe_realloc2x(), safe_realloc2x_arr()
logic-finder Jun 10, 2026
d430bed
fix: header dependency
logic-finder Jun 10, 2026
e995d4a
fix: dtdbparse()
logic-finder Jun 10, 2026
3e144a7
fix: parse_tokstr()
logic-finder Jun 10, 2026
6d87023
fix: apply camel case to symkind_t
logic-finder Jun 10, 2026
41ae661
fix: apply camel case to event_t
logic-finder Jun 10, 2026
66316d9
fix: apply camel case to tokkind_t
logic-finder Jun 10, 2026
f70e038
fix: define STREQL
logic-finder Jun 10, 2026
a4b31c4
fix: rthandle_user()
logic-finder Jun 10, 2026
32d2092
fix: skip_empty_lines()
logic-finder Jun 10, 2026
4b9940e
fix: readln()
logic-finder Jun 10, 2026
2edd41e
fix: split()
logic-finder Jun 10, 2026
7e763b0
fix: tokhandle_common()
logic-finder Jun 10, 2026
1b1841b
fix: tokenize()
logic-finder Jun 10, 2026
dde4af0
fix: split()
logic-finder Jun 10, 2026
077ee14
fix: include <string.h>
logic-finder Jun 10, 2026
38ed736
fix: tokenize()
logic-finder Jun 10, 2026
7c9c2e3
fix: makefile -include
logic-finder Jun 10, 2026
deb3128
fix: change token_t len field type: int => size_t
logic-finder Jun 11, 2026
448f7cb
fix: tokhandle_common()
logic-finder Jun 11, 2026
d32bfb7
fix: add comments
logic-finder Jun 11, 2026
7b8de14
fix: rewrite ${x} parsing logic
logic-finder Jun 11, 2026
67aa357
fix: address null-terminating issues + prefer memcpy
logic-finder Jun 11, 2026
c5ced17
fix: update dat.db
logic-finder Jun 11, 2026
523b952
fix: reflect changesets
logic-finder Jun 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**/.vs
.vscode/

bin/
__record__
lib/*.o
lib/*.d
178 changes: 44 additions & 134 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,159 +1,69 @@
## Includes
## Includes ##
include vars.mk
include defs.mk

## Settings
SHELL := /bin/sh
CC := gcc
# -g for debug
CFLAGS := -O -Wall -W -pedantic -g

# deletes the default value and registers only necessary ones.
# (Refer to the chapter 16.1 in GNU make manual.)
## Targets ##
.SUFFIXES:
.SUFFIXES: .c .o .h

# cstr = Color STRing
define cstr
"\033[$1m$2\033[0m"
endef
name_str = $(call cstr,38;5;49;1,$1)
build_completed_str = $(call cstr,48;5;222;30, [ BUILD COMPLETED ] )
inst_done_str = $(call cstr,48;5;150;30, [ INSTALL DONE ] )
warn_str = $(call cstr,48;5;88;37, [ WARNING ] )
notice_str = $(call cstr,48;5;152;30, [ NOTICE ] )

## Compilations
project := Utils
programs := btn hd hhss nsy nsy2 yandere
_programs := $(foreach program,$(programs),./$(program)/c/$(program))
default_goal := __record__
tempfile := __Utils_tempfile__

define is_recent
$(if $1,\
@echo $(notice_str) "The following programs have made a successful build:"$\
$(call name_str,$(foreach program,$1,\n\t$(program))),\
@echo $(notice_str) All programs are already up-to-date!!)
endef

### This is the default goal. ###
$(default_goal): $(tempfile) $(_programs)
$(call is_recent,$(file < $(tempfile)))
rm $(tempfile)
touch $(default_goal)

.PHONY: $(tempfile)
$(tempfile):
touch $(tempfile)

define program_template
$1_path := ./$1/c
$1_name := $$($1_path)/$1
$1_sources := $$(wildcard $$($1_path)/*.c)
$1_objects := $$($1_sources:.c=.o)
all_objects += $$($1_objects)

.PHONY: $1
# This rule is for the command `make program-names...`.
$1: $$($1_name)
if ! rm $(tempfile); then \
echo $(notice_str) $(call name_str,$1) is already up-to-date!; \
fi \

$$($1_name): $$($1_objects)
$(CC) $$^ $(CFLAGS) -o $$@
$$(file >> $$(tempfile),$1)
@echo $(build_completed_str) $(call name_str,$$@)"\n"
endef
all_objects =
.PHONY: all $(TARGETS)
.PHONY: $(TEST) install uninstall clean cleanall help

$(foreach program,$(programs),$(eval $(call program_template,$(program))))
## Default Goal ##
all: $(TARGETS)

# hhss.c requires a special care since it needs INSTPATH
inst_prefix := /usr/local
datadir := $(inst_prefix)/share/hhss
$(hhss_path)/hhss.o: $(hhss_path)/hhss.c
$(CC) $(CFLAGS) -DINSTPATH='"$(datadir)"' -o $@ -c $<
$(TARGETS):
$(MAKE) -C $@/c TARGET=$@ DIR_DATA=$(DIR_DATA)
@echo $(STR_BUILD_DONE) $(call STR_NAME,$@)

## Auxiliary Tasks
.PHONY: install
INSTALL := install
INSTALL_PROGRAM := $(INSTALL)
INSTALL_DATA := $(INSTALL) -m 644

bindir := $(inst_prefix)/bin
man1dir := $(inst_prefix)/share/man/man1
man7dir := $(inst_prefix)/share/man/man7

hhss_data := hsr usr

program_installation_cmd := $(INSTALL_PROGRAM) ./$$i/c/$$i $(bindir)
data_installation_cmd := $(INSTALL_DATA) ./hhss/$$i $(datadir)
## Test Program ##
$(TEST):
$(MAKE) --always-make --directory=$(TEST) \
PROG=$(PROG) \
TESTCASE=$(TESTCASE) \
DIR_BIN=$(DIR_BIN)

## Auxiliary Tasks ##
install:
test -d $(bindir) || (mkdir $(bindir))
test -d $(datadir) || (mkdir $(datadir))
test -d $(man1dir) || (mkdir $(man1dir))
test -d $(man7dir) || (mkdir $(man7dir))
$(call installation_template,$(programs),$(program_installation_cmd))
$(call installation_template,$(hhss_data:%=%.dat),$(data_installation_cmd))
$(call inst_man_t,$(programs),$(INSTALL) -m 644 $$i/$$i.1 $(man1dir),1)
$(call inst_man_t,$(project),$(INSTALL) -m 644 $$i.7 $(man7dir),7)

.PHONY: test
test_path := ./test
# It is necessary to assign values to these variables from the command line.
testcase =
prog =
test -d $(DIR_BIN) || mkdir -p $(DIR_BIN)
test -d $(DIR_DATA)/$(HHSS) || mkdir -p $(DIR_DATA)/$(HHSS)
test -d $(DIR_MAN1) || mkdir -p $(DIR_MAN1)
test -d $(DIR_MAN7) || mkdir -p $(DIR_MAN7)
$(call TPL_INST_PROG,$(TARGETS),$(CMD_INSTALL_PROG))
$(call TPL_INST_PROG,$(HHSS_DATA),$(CMD_INSTALL_DATA))
$(call TPL_INST_MAN,$(TARGETS),$(CMD_INSTALL_MAN1),1)
$(call TPL_INST_MAN,$(PROJECT),$(CMD_INSTALL_MAN7),7)

test: $(test_path)/test_maker
cd $(test_path) && ./test_maker ./.test/$(testcase)
$(test_path)/test $(bindir)/$(prog)

$(test_path)/test_maker: $(test_path)/test_maker.o
$(CC) $^ $(CFLAGS) -o $(test_path)/test_maker

.PHONY: uninstall
uninstall:
rm -f $(foreach program,$(programs),$(bindir)/$(program))
rm -rf $(datadir)
rm -f $(foreach program,$(programs),$(man1dir)/$(program).1)
rm -f $(man7dir)/$(project).7
rm -f $(foreach target,$(TARGETS),$(DIR_BIN)/$(target))
rm -rf $(DIR_DATA)/$(HHSS)
rm -f $(foreach target,$(TARGETS),$(DIR_MAN1)/$(target).1)
rm -f $(DIR_MAN7)/$(PROJECT).7

.PHONY: clean
clean:
rm -f $(all_objects)
rm -f $(_programs)
find . -name "*.o" -delete
find . -name "*.d" -delete
rm -f $(foreach target,$(TARGETS),$(target)/c/$(target))

.PHONY: cleanall
cleanall: uninstall clean
rm -f $(foreach file,test_maker.o test test_maker,$(test_path)/$(file))
$(MAKE) --directory=$(TEST) clean

.PHONY: help
cmd_group = $(call cstr,48;5;148;30, $1 )
cmd_color = $(call cstr,38;5;220,$1)
cmd_arg_color = $(call cstr,36,$1)
help:
@echo The below are the list of available commands from this Makefile.
@echo
@echo $(call cmd_group,1. MAKING ACTIONS)
@echo $(call STR_HELP_GROUP,1. MAKING ACTIONS)
@echo " make builds every program."
@echo " make "$(call cmd_color,program-names...)
@echo " make "$(call STR_HELP_CMDHL,program-names...)
@echo " builds mentioned program(s) only, e.g. make btn nsy"
@echo " make "$(call cmd_color,install)" copies the executables of each program into $(bindir) directory."
@echo " make "$(call STR_HELP_CMDHL,install)" copies the executables of each program into $(DIR_BIN) directory."
@echo
@echo $(call cmd_group,2. CLEANING ACTIONS)
@echo " make "$(call cmd_color,clean)" deletes all object files and all executables."
@echo " make "$(call cmd_color,uninstall)" deletes everything under $(bindir) directory."
@echo " make "$(call cmd_color,cleanall)" clean + uninstall + some files in ./test"
@echo $(call STR_HELP_GROUP,2. CLEANING ACTIONS)
@echo " make "$(call STR_HELP_CMDHL,clean)" deletes all of the build artifacts."
@echo " make "$(call STR_HELP_CMDHL,uninstall)" deletes everything under $(DIR_BIN) directory."
@echo " make "$(call STR_HELP_CMDHL,cleanall)" clean + uninstall + some files in ./test"
@echo
@echo $(call cmd_group,3. MISCELLANEOUS)
@echo " make "$(call cmd_color,test) \
$(call cmd_arg_color,prog)=\"the name of a program to be tested\" $(call cmd_arg_color,testcase)=\"the name of a testcase file\"
@echo $(call STR_HELP_GROUP,3. MISCELLANEOUS)
@echo " make "$(call STR_HELP_CMDHL,test) \
$(call STR_HELP_ARGHL,PROG)=\"the name of a program to be tested\" $(call STR_HELP_ARGHL,TESTCASE)=\"the name of a testcase file\"
@echo " performs a test on the executable with the test file."
@echo " make "$(call cmd_color,help)" prints this long manual on the screen that you are reading now."

# Frequently Used Commands
.PHONY: bullshit
bullshit:
export PATH=$(bindir) && hhss 5 | nsy e | btn 20
@echo " make "$(call STR_HELP_CMDHL,help)" prints this long manual on the screen that you are reading now."
30 changes: 22 additions & 8 deletions defs.mk
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
define installation_template
###############
# Definitions #
###############

# TPL_INST_PROG - program install template
# $1 = list of program names
# $2 = install command
define TPL_INST_PROG
for i in $1; do \
if $2; then \
echo $(inst_done_str) $(call name_str,$$i) has been installed successfully.; \
echo $(STR_INST_DONE) $(call STR_NAME,$$i) has been installed successfully.; \
else \
echo $(warn_str) There was a failure on installing $(call name_str,$$i).; \
echo $(STR_WARN) There was a failure on installing $(call STR_NAME,$$i).; \
fi \
done
endef

# inst_man_t - manual install template
# TPL_INST_MAN - manual install template
# $1 = list of program names
# $2 = install command
# $3 = manual section
define inst_man_t
define TPL_INST_MAN
for i in $1; do \
if $2; then \
echo $(inst_done_str) $(call name_str,$$i.$3) has been installed.; \
echo $(STR_INST_DONE) $(call STR_NAME,$$i.$3) has been installed.; \
else \
echo $(warn_str) Failed to install $(call name_str,$$i.$3).; \
echo $(STR_WARN) Failed to install $(call STR_NAME,$$i.$3).; \
fi \
done
endef
endef

# CSTR - color string
# $1 = color value
# $2 = message
define CSTR
"\033[$1m$2\033[0m"
endef
3 changes: 2 additions & 1 deletion hhss/c/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
hhss
hhss.exe
hhss.o
*.o
*.d
46 changes: 37 additions & 9 deletions hhss/c/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
CC = gcc
CCFLAGS = -O -Wall -W -pedantic
## Variables ##
TARGET := hhss

TARGET = hhss
CC := gcc
CFLAGS := -O -Wall -W -pedantic
CFLAGS += -g
CFLAGS += -MMD -MP
CPPFLAGS = \
-I $(DIR_LIB) \
-DINSTPATH='"$(DIR_DATA)/$(TARGET)"' \
-DPROGNAME='"$(TARGET)"'

SOURCES = $(wildcard ./*.c)
OBJECTS = $(patsubst %.c, %.o, $(SOURCES))
SOURCES = $(wildcard *.c)
LIB_SRCS = $(wildcard $(DIR_LIB)/*.c)
OBJECTS = $(SOURCES:.c=.o)
LIB_OBJS = $(notdir $(LIB_SRCS:.c=.o))

DIR_DATA := ../..
DIR_LIB := ../../lib

## Targets ##
.PHONY: all clean

## Default Goal ##
all: $(TARGET)

$(TARGET): $(OBJECTS)
$(CC) $(CCFLAGS) -o $@ $^
## Build ##
$(TARGET): $(OBJECTS) $(LIB_OBJS)
$(CC) $^ $(CFLAGS) -o $@

$(OBJECTS): %.o: %.c
$(CC) $< $(CPPFLAGS) $(CFLAGS) -c -o $@

$(LIB_OBJS): %.o: $(DIR_LIB)/%.c
$(CC) $< $(CPPFLAGS) $(CFLAGS) -c -o $@

## Dependency ##
-include $(OBJECTS:.o=.d)
-include $(LIB_OBJS:.o=.d)

%.o: %.c
$(CC) $(CCFLAGS) -c -o $@ $<
## Tasks ##
clean:
rm -f $(TARGET) *.o *.d
23 changes: 23 additions & 0 deletions hhss/c/argv1parse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "argv1parse.h"
#include "argv1parse.internals.h"

extern int argv1parse(const char *argv1, int threshold) {
char *i;
long ret;

errno = 0;
ret = strtol(argv1, &i, 10);

if (errno == ERANGE || ret > INT_MAX || ret < INT_MIN)
ERR("count out of range");
if (i == argv1)
ERR("conversion not performed");
if (*i != '\0')
ERR("invalid trailing characters in argv[1]");
if (ret < MIN_DATA_COUNT)
VERR("count must be %d at least", MIN_DATA_COUNT);
if (ret > (long) threshold)
VERR("count must be less than or equal to %d", threshold);

return (int) ret;
}
9 changes: 9 additions & 0 deletions hhss/c/argv1parse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef ARGV1PARSE_H
#define ARGV1PARSE_H

/**************
* PROTOTYPES *
**************/
int argv1parse(const char *argv1, int threshold);

#endif
14 changes: 14 additions & 0 deletions hhss/c/argv1parse.internals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef ARGV1PARSE_INTERNALS_H
#define ARGV1PARSE_INTERNALS_H

/************
* INCLUDES *
************/
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#
#include "fatal.h"
#include "global.h"

#endif
20 changes: 20 additions & 0 deletions hhss/c/dbload.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "dbload.h"
#include "dbload.internals.h"

extern array_t *dbload(const char *new, const char *old) {
if (canopen(new))
return loadfile(new, NULL, NULL);
return loadfile(old, NULL, NULL);
}

static int canopen(const char *filename) {
FILE *fp;

fp = fopen(filename, "r");
if (!fp)
return 0;

(void) fclose(fp);

return 1;
}
Comment thread
logic-finder marked this conversation as resolved.
Loading
Loading