add demo files

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3395 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2001-01-06 00:58:28 +00:00
parent 17d27e2a65
commit 8ef98f270f
4 changed files with 129 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
Makefile
Makefile.in
mbox.out

View File

@@ -0,0 +1,29 @@
# cgi-bin Makefile.am file.
bin_PROGRAMS = hello
CFLAGS = @CFLAGS@ ${GLIB_CFLAGS}
LDADD = \
../../engine/libgncengine.la \
-lxml -lglib
INCLUDES =
hello_SOURCES = \
hello.c
noinst_HEADERS =
EXTRA_DIST = \
.cvsignore \
README
CFLAGS = @CFLAGS@
# glib puts its header files in a bizarre place ...
INCLUDES = \
-I/usr/lib/glib/include \
-I../../engine

View File

@@ -0,0 +1 @@
this is some cgi-bin testing

View File

@@ -0,0 +1,96 @@
/*
* FILE:
* hello.c
*
* FUNCTION:
* A simple libgnc_engine hello-world demo
*/
#include <stdio.h>
#include <string.h>
#include "gnc-book.h"
#include "gnc-engine.h"
#include "Group.h"
#include "Query.h"
int
main (int argc, char *argv[])
{
int fake_argc =1;
char * fake_argv[] = {"hello", 0};
GNCBook *book;
AccountGroup *grp;
Query *q;
GList *split_list, *node;
Split *s;
int i, rc;
/* intitialize the engine */
gnc_engine_init (fake_argc, fake_argv);
/* contact the database, which is a flat file for this demo */
book = gnc_book_new ();
rc = gnc_book_begin (book, "file:/tmp/demo.xac");
if (!rc) {
int err = gnc_book_get_error (book);
printf ("HTTP/1.1 500 Server Error\n");
printf ("\n");
printf ("%d %s\n", err, strerror (err));
goto bookerrexit;
}
rc = gnc_book_load (book);
if (!rc) {
int err = gnc_book_get_error (book);
printf ("HTTP/1.1 500 Server Error\n");
printf ("\n");
printf ("%d %s\n", err, strerror (err));
goto bookerrexit;
}
/* the grp pointer points to our local cache of the data */
grp = gnc_book_get_group (book);
/* build a query */
q = xaccMallocQuery ();
xaccQuerySetGroup (q, grp);
xaccQuerySetMaxSplits (q, 30);
/* Get everything between some random dates */
/* In real life, we would use a query as specified by the user */
xaccQueryAddDateMatch (q, TRUE, 1982, 2, 28,
FALSE, 2010, 10, 16,
QUERY_OR);
split_list = xaccQueryGetSplits (q);
/* count number of splits */
i = 0;
for (node = split_list; node; node = node->next)
{
s = node->data;
i++;
}
/* print the HTTP header */
printf ("HTTP/1.1 200 OK\n");
printf ("Content-Type: text/xml\n");
printf ("\n");
printf ("found %d splits %d %d \n", i, xaccQueryHasTerms (q),
xaccGroupGetNumSubAccounts(grp));
xaccFreeQuery (q);
bookerrexit:
/* close the book */
gnc_book_destroy (book);
/* shut down the engine */
gnc_engine_shutdown ();
return 0;
}