From 5ffcc53ed24b70648a8f42782667f8792a05088c Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 26 Dec 1998 22:23:55 +0000 Subject: [PATCH] clean up the demos git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1482 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/swig/examples/scan-acct.pl | 26 ++++++++++++++++++++++++++ src/swig/examples/scan-acct.scm | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 src/swig/examples/scan-acct.pl diff --git a/src/swig/examples/scan-acct.pl b/src/swig/examples/scan-acct.pl new file mode 100755 index 0000000000..45a3555893 --- /dev/null +++ b/src/swig/examples/scan-acct.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +# gnucash perl demo: +# +# This file demonstrates how to open an acount file and print +# the names and balances of the top-level accounts in the file. +# +# use lib '../swig/perl5/'; +use lib '../perl5/'; +use gnucash; +package gnucash; + +die "Usage: $0 " if $#ARGV < 0; +print "its $ARGV[0]\n"; + +$grp = gnucash::xaccReadAccountGroup ($ARGV[0]); +$numacc = gnucash::xaccGroupGetNumAccounts ($grp); +print "Loaded $numacc accounts\n\n"; + +for ($i=0; $i<$numacc; $i++) { + $acct = gnucash::xaccGroupGetAccount ($grp, $i); + $acctname = gnucash::xaccAccountGetName ($acct); + $baln = gnucash::xaccAccountGetBalance ($acct); + print "\tAccount: $acctname \tBalance: $baln\n"; +} + diff --git a/src/swig/examples/scan-acct.scm b/src/swig/examples/scan-acct.scm index bfedf0a8e1..d5b7c1e5b5 100644 --- a/src/swig/examples/scan-acct.scm +++ b/src/swig/examples/scan-acct.scm @@ -1,8 +1,8 @@ (define (list-accts filename) (let ((db (xaccReadAccountGroup filename))) - (do ((total (xaccGetNumAccounts db)) + (do ((total (xaccGroupGetNumAccounts db)) (i 0 (+ i 1))) ((= i total)) - (let ((acct (xaccGetAccountFromID db i))) + (let ((acct (xaccGroupGetAccount db i))) (write (xaccAccountGetName acct))))))