|
GnuCash 2.4.99
|
00001 /* 00002 * FILE: 00003 * hello.c 00004 * 00005 * FUNCTION: 00006 * The first in a sequence of demos for cgi-bin programming 00007 * This demo shows how to intialize the gnc_engine, and how 00008 * to dump the entire contents of a gnucash file to stdout. 00009 * 00010 */ 00011 00012 #include <stdio.h> 00013 #include <stdlib.h> 00014 #include <string.h> 00015 00016 #include "gnc-commodity.h" 00017 #include "gnc-engine.h" 00018 #include "io-gncxml-v2.h" 00019 00020 00021 int 00022 main (int argc, char *argv[]) 00023 { 00024 int fake_argc = 1; 00025 char * fake_argv[] = {"hello", 0}; 00026 QofBook *book; 00027 int rc; 00028 00029 /* intitialize the engine */ 00030 gnc_engine_init (fake_argc, fake_argv); 00031 00032 /* dirty little hack to work around commodity borkeness */ 00033 { 00034 gnc_commodity_table *t = gnc_engine_commodities (); 00035 gnc_commodity *cm = gnc_commodity_new ("US Dollar", "ISO4217", "USD", "840", 100); 00036 gnc_commodity_table_insert (t, cm); 00037 } 00038 00039 /* contact the database, which is a flat file for this demo */ 00040 book = qof_book_new (); 00041 00042 rc = gnc_book_begin (book, "file:/tmp/demo.gml", FALSE, FALSE); 00043 if (!rc) 00044 { 00045 GNCBackendError err = gnc_book_get_error (book); 00046 printf ("HTTP/1.1 500 Server Error\n"); 00047 printf ("\n"); 00048 printf ("err=%d \n", err); 00049 goto bookerrexit; 00050 } 00051 00052 rc = gnc_book_load (book); 00053 if (!rc) 00054 { 00055 GNCBackendError err = gnc_book_get_error (book); 00056 printf ("HTTP/1.1 500 Server Error\n"); 00057 printf ("\n"); 00058 printf ("err=%d \n", err); 00059 goto bookerrexit; 00060 } 00061 00062 /* print the HTTP header */ 00063 printf ("HTTP/1.1 200 OK\n"); 00064 printf ("Content-Type: text/gnc-xml\r\n"); 00065 // the current write interfaces don't give us a length :-( 00066 // printf ("Content-Length: %d\r\n", sz); 00067 printf ("\r\n"); 00068 00069 gnc_book_write_to_xml_filehandle_v2 (book, stdout); 00070 00071 bookerrexit: 00072 /* close the book */ 00073 qof_book_destroy (book); 00074 00075 /* shut down the engine */ 00076 gnc_engine_shutdown (); 00077 00078 return 0; 00079 }
1.7.4