Skip to content

Commit

Permalink
- refactor to a single .c file
Browse files Browse the repository at this point in the history
- use longjmp() to handle errors
- add memory-optimization and disk-optimization modes
  • Loading branch information
dongyx committed Nov 19, 2022
1 parent 956e341 commit a653f4d
Show file tree
Hide file tree
Showing 33 changed files with 918 additions and 1,218 deletions.
23 changes: 5 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
.PHONY: targets clean install test tag

CC = cc
CFLAGS = -D_XOPEN_SOURCE=700
INSTALL = install
prefix = /usr/local
bindir = $(prefix)/bin
datarootdir = $(prefix)/share
mandir = $(datarootdir)/man
src = $(wildcard *.c)
deps = $(src:.c=.d)
objs = $(src:.c=.o)
targets = hardv hardv.1

targets: $(targets)

-include $(deps)

hardv: $(objs)
$(CC) $(LDFLAGS) -o $@ $^

main.o: main.c version LICENSE
hardv: hardv.c
$(CC) $(CFLAGS) \
-DVERSION="\"`cat version`\"" \
-DCOPYRT="\"`grep -i 'copyright (c)' LICENSE`\"" \
-o $@ -c $<

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

%.d: %.c
@$(CC) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' >$@
-o $@ $^

hardv.1: hardv.man1 version LICENSE
hardv.1: hardv.1.s version LICENSE
@echo building manpage...
@set -e; \
cp $< $@; \
Expand All @@ -54,7 +41,7 @@ test: $(targets)
echo all tests passed;

clean:
@rm -rf $(targets) $(deps) $(objs) *.tmp
@rm -rf $(targets) *.tmp
@for i in test/*; do \
cd $$i; \
./clean; \
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ hardv
=====
(/*:rd'vi:*/)

`hardv` is a CLI flashcard app for UNIX-compatible systems,
conforming to the UNIX philosophy.
`hardv` is a CLI flashcard app for Unix-compatible systems,
conforming to the Unix philosophy.

- Almost everything can be customized,
with any programming language you prefer.
Expand All @@ -23,16 +23,25 @@ E.g.:
and more.

- The format of input files are
easy to be parsed by both human and other UNIX utilities
easy to be parsed by both human and other Unix utilities
like `grep`/`cut`/`sed`/`awk`/...

- Metadata like scheduled time is written back to input files;
Thus all your data is in files created and managed by yourself;
Nothing would prevent you from migration or uninstall.

- It is a UNIX filter, although an interactive one.
- It is a Unix filter, although an interactive one.
That makes `hardv` easy to be called by other programs.

By default, `hardv` runs in the memory-optimization mode.
Only one card is loaded in the memory at the same time.
The process consumes about 512KB to 1MB memory
for cards with typical size in common systems.
However, `hardv` allows you to turn it into the disk-optimization mode.
The disk-optimization mode consumes less disk I/O,
at the cost of loading all cards of a file into the memory.
See the `-d` option in the man page `hardv(1)`.

Getting Started
---------------

Expand Down
44 changes: 0 additions & 44 deletions apperr.c

This file was deleted.

28 changes: 0 additions & 28 deletions apperr.h

This file was deleted.

12 changes: 0 additions & 12 deletions applim.h

This file was deleted.

Loading

0 comments on commit a653f4d

Please sign in to comment.