clean up the demos

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1482 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-12-26 22:23:55 +00:00
parent d199bd73cf
commit 5ffcc53ed2
2 changed files with 28 additions and 2 deletions

26
src/swig/examples/scan-acct.pl Executable file
View File

@ -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 <filename>" 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";
}

View File

@ -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))))))