#! /bin/sh # # Args: db-file-1 tag-in-file-2 db-file-2 tag-in-file-1 # (That is, each db file followed by its "owner".) # PATH=/home/mouse/acc/bin:"$PATH" case $# in 4) ;; *) echo Usage: $0 db-1 owner-1 db-2 owner-2 1>&2 exit 1 ;; esac # t=/tmp/shared.$$ trap 'touch '$t'.touch; rm -f '$t'.*; exit' 0 1 2 15 # scanfile="$1" appfile="$3" scantag="$4" apptag="$2" # umask 077 sslock "$scanfile" $$ || exit 1 sslock "$appfile" $$ || exit 1 echo scanning "$scanfile"\; appending to "$appfile" # flagpgm: if s [ if p or x [ write to .p-or-x and .leave ] else [ write to pipe ] ] else [ write to .leave ] < "$scanfile" flag 'Ns?NpNx+?3W4W#1W.#4W.' 3> $t.p-or-x 4> $t.leave | select -split 3 \( -not -from "" -and -not -to "" \) -or -cat transaction > $t.proc-trans 3> $t.process if [ -s $t.proc-trans ]; then ( echo "Can't share transactions, fix by hand:" < $t.proc-trans sed -e 's/^/ /' ) 1>&2 exit 1 fi if [ -s $t.p-or-x ]; then ( echo "$0: warning: can't share the following (p or x):" < $t.p-or-x sed -e 's/^/ /' ) 1>&2 fi if [ ! -s $t.process ]; then exit 0 fi touch $t.a $t.b $t.c < $t.process awk -F: 'BEGIN { odd = 0; today = "'`ndate`'" } { date = $1; edate = $2; flag = $3; cat = $4; from = $5; to = $6; amt = $7; if (NF > 7) curr = ":" $8; else curr = ""; printf("%s:%s:%s:%s:%s:%s:%d%s\n",date,edate,flag,cat,from,to,amt,curr) > "'$t'.a"; nfrom = ""; if (from != "") nfrom = "'"$scantag"'"; nto = ""; if (to != "") nto = "'"$scantag"'"; if (odd[curr]) amt ++; if (amt % 2) { amt --; odd[curr] = 1; } half = amt / 2; printf("%s:%s:AS:%s:%s:%s:%d%s\n",date,today,cat,nfrom,nto,-half,curr) > "'$t'.b"; nfrom = ""; if (from != "") nfrom = "'"$apptag"'"; nto = ""; if (to != "") nto = "'"$apptag"'"; printf("%s:%s:AS:%s:%s:%s:%d%s\n",date,today,cat,nfrom,nto,half,curr) > "'$t'.c"; }' trap "" 1 2 15 ( cat $t.leave $t.b ; flag '(F@sd@F!S)' < $t.a ) > "$scanfile" cat $t.c >> "$appfile" ssunlock "$scanfile" ssunlock "$appfile"