From 991591bebcc7a4553790dc57a009a13d69f38eed Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Sep 2013 01:25:00 +0200 Subject: uriparse-test is now posix compliant --- util/t/uriparse/parse-retard-uri | 8 ++++---- util/t/uriparse/parse-url | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/util/t/uriparse/parse-retard-uri b/util/t/uriparse/parse-retard-uri index 0c149148..76feac41 100755 --- a/util/t/uriparse/parse-retard-uri +++ b/util/t/uriparse/parse-retard-uri @@ -5,9 +5,9 @@ trap "/bin/rm -f $tempfile" EXIT INT uriparse "http://'lolwut:\"khan@domain.tld/'''" > $tempfile . $tempfile -[ "$HOSTN" == "domain.tld" ] && \ - [ "$USERNAME" == "'lolwut" ] && \ - [ "$PASSWORD" == '"khan' ] && \ - [ "$URIPATH" == "/'''" ] +[ "$HOSTN" = "domain.tld" ] && \ + [ "$USERNAME" = "'lolwut" ] && \ + [ "$PASSWORD" = '"khan' ] && \ + [ "$URIPATH" = "/'''" ] diff --git a/util/t/uriparse/parse-url b/util/t/uriparse/parse-url index cf6f53fd..2ccf39c9 100755 --- a/util/t/uriparse/parse-url +++ b/util/t/uriparse/parse-url @@ -5,9 +5,9 @@ trap "/bin/rm -f $tempfile" EXIT INT uriparse "http://user:pass@domain.tld/path" > $tempfile . $tempfile -[ "$HOSTN" == "domain.tld" ] && \ - [ $USERNAME == "user" ] && \ - [ $PASSWORD == "pass" ] && \ - [ $URIPATH == "/path" ] +[ "$HOSTN" = "domain.tld" ] && \ + [ $USERNAME = "user" ] && \ + [ $PASSWORD = "pass" ] && \ + [ $URIPATH = "/path" ] -- cgit v1.2.3 From 935d71847f73bc1f5172a8662e775ebf6cd89946 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Sep 2013 01:26:14 +0200 Subject: fix travis script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 81eb2492..56b6c8c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: c notifications: irc: "chat.freenode.net#krebs_incoming" -script: "make -C util test | grep -q '^not ok' && exit 1" +script: "if make -C util test | grep -q '^not ok' ;then exit 1; else exit 0; fi" before_install: - sudo apt-get install bc -qq - sudo apt-get install python -qq -- cgit v1.2.3 From 25268899884510c7f336d86ab3e89048ac7fbabb Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Sep 2013 01:28:49 +0200 Subject: skip submodules --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 56b6c8c5..04059cc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,5 @@ before_install: branches: only: - master +git: + submodules: false -- cgit v1.2.3 From b0845d5b495fdbdf38c6959395dbd74e114cbccd Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 3 Sep 2013 01:30:37 +0200 Subject: update travis script (again) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 04059cc4..e62f843f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: c notifications: irc: "chat.freenode.net#krebs_incoming" -script: "if make -C util test | grep -q '^not ok' ;then exit 1; else exit 0; fi" +script: "! ( make -C util test | grep -q '^not ok' )" before_install: - sudo apt-get install bc -qq - sudo apt-get install python -qq -- cgit v1.2.3 From 6e4e2fa779b641711977ab921615ce3c803276c0 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:43:44 +0200 Subject: ledger balance: initial commit --- ledger/lib/balance | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 ledger/lib/balance diff --git a/ledger/lib/balance b/ledger/lib/balance new file mode 100755 index 00000000..8d84dd7b --- /dev/null +++ b/ledger/lib/balance @@ -0,0 +1,73 @@ +#! /bin/awk -f +# +# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE +# see also: //cholerab/ledger-spec.markdown +# + +BEGIN { + colorize = ENVIRON["colorize"] == "" || ENVIRON["colorize"] == "true" + # TODO use bc for arbitrary precision arithmetic + scale = ENVIRON["scale"] +} + +/^[[:space:]]*[0-9]+-[0-9][0-9]-[0-9][0-9]/{ + tx($2, $3, $4, $5) +} + +END { + display_accounts() +} + +function tx (dst, src, amt, u) { + withdraw(src, amt, u) + deposit(dst, amt, u) +} + +function deposit (name, amt, u) { + accounts[name][u] += amt +} + +function withdraw (name, amt, u) { + accounts[name][u] -= amt +} + +function display_accounts() { + max_name_len = 0 + for (name in accounts) { + if (length(name) > max_name_len) { + max_name_len = length(name) + } + } + + max_balance_len = 0 + for (name in accounts) { + for (u in accounts[name]) { + s = accounts[name][u] + sub(/\..*/, "", s) + if (length(s) > max_balance_len) { + max_balance_len = length(s) + } + } + } + if (scale > 0) { + max_balance_len += 1 + scale + } + + for (name in accounts) { + for (u in accounts[name]) { + + fmt = "NAME BALANCE UNIT\n" + balance = accounts[name][u] + + if (colorize) { + sub("BALANCE", "[" (balance < 0 ? 31 : 32) "m&", fmt) + } + + sub("NAME", "%-" max_name_len "s", fmt) + sub("BALANCE", "%" max_balance_len "." scale "f", fmt) + sub("UNIT", "%s", fmt) + + printf fmt, name, balance, u + } + } +} -- cgit v1.2.3 From a48c908949884f1e550abbd5bda5b30131fe71c4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:48:44 +0200 Subject: ledger balance: fix usage description --- ledger/lib/balance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index 8d84dd7b..1e9e2db2 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -1,6 +1,6 @@ #! /bin/awk -f # -# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE +# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... # see also: //cholerab/ledger-spec.markdown # -- cgit v1.2.3 From 87b90098679c9daccd558d6df0fef508cf7a4a24 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 19:59:53 +0200 Subject: ledger balance: clarify max_balance_len computation --- ledger/lib/balance | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index 1e9e2db2..f75410c3 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -42,15 +42,14 @@ function display_accounts() { max_balance_len = 0 for (name in accounts) { for (u in accounts[name]) { - s = accounts[name][u] - sub(/\..*/, "", s) - if (length(s) > max_balance_len) { - max_balance_len = length(s) + n = length(int(accounts[name][u])) + if (n > max_balance_len) { + max_balance_len = n } } } if (scale > 0) { - max_balance_len += 1 + scale + max_balance_len += length(".") + scale } for (name in accounts) { -- cgit v1.2.3 From 74961ef05afc5d06d0af192752912466021882c4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 20:14:06 +0200 Subject: ledger balance: add description and pipe-usage --- ledger/lib/balance | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ledger/lib/balance b/ledger/lib/balance index f75410c3..77cb7f6d 100755 --- a/ledger/lib/balance +++ b/ledger/lib/balance @@ -1,7 +1,20 @@ #! /bin/awk -f # -# usage: [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... -# see also: //cholerab/ledger-spec.markdown +# ledger balance calculator +# +# usage: +# [colorize=false] [scale=N] //ledger/lib/balance LEDGER_FILE... +# [colorize=false] [scale=N] //ledger/lib/balance < LEDGER_FILE +# +# description: +# The ledger balance calculator computes the balance of each account it +# encounters in the provided ledger files. +# +# example: +# //ledger/lib/balance < //cholerab/ledger-spec.markdown +# +# see also: +# //cholerab/ledger-spec.markdown (ledger file format) # BEGIN { -- cgit v1.2.3 From c39c60f74a8d6be286648e2bdb264c9f93eaddef Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Sep 2013 20:40:14 +0200 Subject: cholerab ledger-spec: talk about DATE and AMOUNT --- cholerab/ledger-spec.markdown | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cholerab/ledger-spec.markdown b/cholerab/ledger-spec.markdown index 15a290bf..812bce33 100644 --- a/cholerab/ledger-spec.markdown +++ b/cholerab/ledger-spec.markdown @@ -1,8 +1,16 @@ -# Format +# Ledger Specification + +## Transaction Record + +### External Representation DATE DESTINATION-ACCOUNT SOURCE-ACCOUNT AMOUNT UNIT [COMMENT...] -# Example + where + - `DATE` has the form `YYYY-MM-DD` + - `AMOUNT` is a non-negative, decimal number + +### Example 2013-01-01 krebs-ml amazon 30 EUR C0DE-AAAA-BBBB-CCCC 2013-02-02 momo krebs-ml 50 EUR C0DE-AAAA-BBBB-CCCC -- cgit v1.2.3