sw

simple wallet
git clone git://git.bitsmanent.org/sw
Log | Files | Refs | README | LICENSE

commit 73dda2a533052e01f5999b9da3a0e2f29477d9a6
parent d7ba5dc18897982e7e030bf8da4d0c65b433edc5
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Fri,  9 Mar 2018 23:36:20 +0100

Add -l flag to limit movements in listing (default: 25)

Diffstat:
Msw.1 | 5++++-
Msw.c | 21+++++++++++----------
2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/sw.1 b/sw.1 @@ -3,7 +3,7 @@ sw \- simple wallet .SH SYNOPSIS .B sw -.RB [ \-v ]\ [ \-d\ <id> ]\ [ \-f\ <file>]\ [<date>\ <amount>\ <note>] +.RB [ \-v ]\ [ \-d\ <id> ]\ [ \-f\ <file>]\ [ \-l\ <limit>]\ [<date>\ <amount>\ <note>] .SH DESCRIPTION sw is a simple wallet management tool which features a simple yet powerful interface to keep track of your money movements. @@ -17,3 +17,6 @@ remove the specified movement, then exits. .TP .B \-f\ <file> use the given file as movements database. +.TP +.B \-l\ <limit> +limit the number of movements in the listing. diff --git a/sw.c b/sw.c @@ -33,7 +33,7 @@ void *ecalloc(size_t nmemb, size_t size); void freemovs(void); void loadmovs(void); void savemovs(void); -void showmovs(void); +void showmovs(int limit); void sortmovs(void); int strtots(char *s); void usage(void); @@ -165,7 +165,7 @@ savemovs(void) { } void -showmovs(void) { +showmovs(int limit) { Movement *m; time_t ts; float tot = 0; @@ -174,11 +174,13 @@ showmovs(void) { printf("%3s | %16s | %8s | %s\n", "id", "date", "amount", "note"); for(m = movs; m; m = m->next) { + tot += m->amount; + ++nmovs; + if(nmovs > limit) + continue; ts = m->ts; strftime(time, sizeof time, "%d/%m/%Y %H:%M", localtime(&ts)); printf("%3d | %16s | %8.2f | %s\n", m->id, time, m->amount, m->note); - tot += m->amount; - ++nmovs; } printf("%3s | %17s: %8.2f |\n", "", "Wallet balance", tot); printf("%3s | %17s: %8d |\n", "", "Total movements", nmovs); @@ -209,18 +211,17 @@ strtots(char *s) { void usage(void) { - die("Usage: %s [-v] [-d <id>] [-f <file>] [<date> <amount> <note>]\n", argv0); + die("Usage: %s [-v] [-d <id>] [-f <file>] [-l <limit>] [<date> <amount> <note>]\n", argv0); } int main(int argc, char *argv[]) { - int delid = 0; + int delid = 0, limit = 25; ARGBEGIN { case 'd': delid = atoi(EARGF(usage())); break; - case 'f': - snprintf(movsfilename, sizeof movsfilename, "%s", EARGF(usage())); - break; + case 'f': snprintf(movsfilename, sizeof movsfilename, "%s", EARGF(usage())); break; + case 'l': limit = atoi(EARGF(usage())); break; case 'v': die("sw-"VERSION"\n"); default: usage(); } ARGEND; @@ -248,7 +249,7 @@ main(int argc, char *argv[]) { return 0; } sortmovs(); - showmovs(); + showmovs(limit); freemovs(); return 0; }