GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hello.c
1 /*
2  * FILE:
3  * hello.c
4  *
5  * FUNCTION:
6  * The first in a sequence of demos for cgi-bin programming
7  * This demo shows how to intialize the gnc_engine, and how
8  * to dump the entire contents of a gnucash file to stdout.
9  *
10  */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #include "gnc-commodity.h"
17 #include "gnc-engine.h"
18 #include "io-gncxml-v2.h"
19 
20 
21 int
22 main (int argc, char *argv[])
23 {
24  int fake_argc = 1;
25  char * fake_argv[] = {"hello", 0};
26  QofBook *book;
27  int rc;
28 
29  /* intitialize the engine */
30  gnc_engine_init (fake_argc, fake_argv);
31 
32  /* dirty little hack to work around commodity borkeness */
33  {
34  gnc_commodity_table *t = gnc_engine_commodities ();
35  gnc_commodity *cm = gnc_commodity_new ("US Dollar", "ISO4217", "USD", "840", 100);
37  }
38 
39  /* contact the database, which is a flat file for this demo */
40  book = qof_book_new ();
41 
42  rc = gnc_book_begin (book, "file:/tmp/demo.gml", FALSE, FALSE);
43  if (!rc)
44  {
45  GNCBackendError err = gnc_book_get_error (book);
46  printf ("HTTP/1.1 500 Server Error\n");
47  printf ("\n");
48  printf ("err=%d \n", err);
49  goto bookerrexit;
50  }
51 
52  rc = gnc_book_load (book);
53  if (!rc)
54  {
55  GNCBackendError err = gnc_book_get_error (book);
56  printf ("HTTP/1.1 500 Server Error\n");
57  printf ("\n");
58  printf ("err=%d \n", err);
59  goto bookerrexit;
60  }
61 
62  /* print the HTTP header */
63  printf ("HTTP/1.1 200 OK\n");
64  printf ("Content-Type: text/gnc-xml\r\n");
65  // the current write interfaces don't give us a length :-(
66  // printf ("Content-Length: %d\r\n", sz);
67  printf ("\r\n");
68 
69  gnc_book_write_to_xml_filehandle_v2 (book, stdout);
70 
71 bookerrexit:
72  /* close the book */
73  qof_book_destroy (book);
74 
75  /* shut down the engine */
77 
78  return 0;
79 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
void gnc_engine_shutdown(void)
Definition: gnc-engine.c:160
QofBook * qof_book_new(void)
api for GnuCash version 2 XML-based file format
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
void gnc_engine_init(int argc, char **argv)
Definition: gnc-engine.c:139
All type declarations for the whole Gnucash engine.
Commodity handling public routines.
void qof_book_destroy(QofBook *book)