From 318a1dd55f25ab2aa7238e23c3fb02ad627cabf7 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Fri, 21 Dec 2001 07:41:54 +0000 Subject: [PATCH] * src/gnome-utils/gw-gnome-utils-spec.scm: g-wrap new funcs * src/gnome-utils/gncmod-gnome-utils.c: remove #include cruft * src/gnome-utils/gnc-html.c: remove #include cruft * src/gnome-utils/gnc-gnome-utils.h: new file * src/gnome-utils/gnc-gnome-utils.c: new file -- init and shutdown functions * src/gnome-utils/argv-list-converters.h: add * src/gnome-utils/argv-list-converters.c: add * src/gnome-utils/Makefile.am: add new files git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6407 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome-utils/Makefile.am | 5 +- src/gnome-utils/argv-list-converters.c | 130 ++++++++++++++++++++++++ src/gnome-utils/argv-list-converters.h | 58 +++++++++++ src/gnome-utils/gnc-gnome-utils.c | 124 ++++++++++++++++++++++ src/gnome-utils/gnc-gnome-utils.h | 34 +++++++ src/gnome-utils/gnc-html.c | 1 - src/gnome-utils/gncmod-gnome-utils.c | 2 - src/gnome-utils/gw-gnome-utils-spec.scm | 21 ++++ 8 files changed, 371 insertions(+), 4 deletions(-) create mode 100644 src/gnome-utils/argv-list-converters.c create mode 100644 src/gnome-utils/argv-list-converters.h create mode 100644 src/gnome-utils/gnc-gnome-utils.c create mode 100644 src/gnome-utils/gnc-gnome-utils.h diff --git a/src/gnome-utils/Makefile.am b/src/gnome-utils/Makefile.am index 8208eaba3b..39a6b0ac17 100644 --- a/src/gnome-utils/Makefile.am +++ b/src/gnome-utils/Makefile.am @@ -8,7 +8,6 @@ AM_CFLAGS = \ -I${top_srcdir}/src/network-utils \ -I${top_srcdir}/src/app-utils \ -I${top_srcdir}/src \ - -I${top_srcdir}/src/gnome \ ${GUILE_INCS} \ ${GUPPI_CFLAGS} \ ${GLIB_CFLAGS} \ @@ -21,6 +20,7 @@ AM_CFLAGS = \ libgncmod_gnome_utils_la_SOURCES = \ cursors.c \ + argv-list-converters.c \ dialog-commodity.c \ dialog-options.c \ dialog-utils.c \ @@ -33,6 +33,7 @@ libgncmod_gnome_utils_la_SOURCES = \ gnc-date-edit.c \ gnc-frequency.c \ gnc-general-select.c \ + gnc-gnome-utils.c \ gnc-gui-query.c \ gnc-html-history.c \ gnc-html-guppi.c \ @@ -58,6 +59,7 @@ gncinclude_HEADERS = \ gnc-date-edit.h \ gnc-frequency.h \ gnc-general-select.h \ + gnc-gnome-utils.h \ gnc-gui-query.h \ gnc-html-history.h \ gnc-html-guppi.h \ @@ -69,6 +71,7 @@ gncinclude_HEADERS = \ window-help.h noinst_HEADERS = \ + argv-list-converters.h \ gnc-dir.h libgncmod_gnome_utils_la_LDFLAGS = -module diff --git a/src/gnome-utils/argv-list-converters.c b/src/gnome-utils/argv-list-converters.c new file mode 100644 index 0000000000..42558d2bbe --- /dev/null +++ b/src/gnome-utils/argv-list-converters.c @@ -0,0 +1,130 @@ +/********************************************************************\ + * argv-list-converters.c * + * Copyright (C) 2000 Gnumatic, Inc * + * Copyright (C) 2000 James LewisMoss * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ + +#include "config.h" + +#include +#include + +#include "argv-list-converters.h" + + +char** +gnc_scheme_list_to_nulltermcharpp(int prelen, const char **prepend, SCM list) +{ + SCM next = list; + char **ret; + int len = 0; + int loc; + + if(gh_pair_p(list)) + { + int i; + len = gh_length(list) + prelen; + ret = g_new(char *, len + 1); + ret[len] = NULL; + for(i = 0; i < prelen; i++) + { + ret[i] = g_strdup(prepend[i]); + } + } + else + { + return NULL; + } + + loc = prelen; + while(gh_pair_p(next)) + { + SCM scm_string = gh_car(next); + next = gh_cdr(next); + if(gh_string_p(scm_string)) + { + char *onestr = gh_scm2newstr(scm_string, 0); + ret[loc] = g_strdup (onestr); + if (onestr) + free (onestr); + } + else + { + int i; + + for (i = 0; i < loc; i++) + g_free (ret[i]); + g_free(ret); + return NULL; + } + loc++; + } + + return ret; +} + +SCM +gnc_argvarr_to_scheme_list(int argc, const char** argv) +{ + int i; + SCM ret = SCM_EOL; + + for(i = 0; i < argc; i++) + { + /* FIXME: when we drop support older guiles, + * drop the (char *) coercion. */ + ret = gh_cons(gh_str02scm((char *) argv[i]), ret); + } + + return gh_reverse(ret); +} + +void +gnc_free_argv(char** argv) +{ + char **now = argv; + + if(!argv) + { + return; + } + + while(*now != 0) + { + g_free(*now); + now++; + } + g_free(argv); +} + +int +argv_length(char** nulltermlist) +{ + int ret = 0; + + if(!nulltermlist) + { + return 0; + } + + while(nulltermlist[ret] != 0) + ret++; + return ret; +} diff --git a/src/gnome-utils/argv-list-converters.h b/src/gnome-utils/argv-list-converters.h new file mode 100644 index 0000000000..e0ddcea45f --- /dev/null +++ b/src/gnome-utils/argv-list-converters.h @@ -0,0 +1,58 @@ +/********************************************************************\ + * argv-list-converters.h * + * Copyright (C) 2000 Gnumatic, Inc * + * Copyright (C) 2000 James LewisMoss * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ + +#ifndef ARGV_LIST_CONVERTERS_H +#define ARGV_LIST_CONVERTERS_H + + +/* + * This function takes a SCM value. Determines whether it is a list + * and whether that list contains only strings and returns a null + * terminated array of strings (char*'s) + */ +char** gnc_scheme_list_to_nulltermcharpp(int prelen, const char **prepend, + SCM list); + + +/* + * This function takes a length and char** and makes a scheme list + * with similar contents + */ +SCM gnc_argvarr_to_scheme_list(int argc, const char** argv); + +/* + * Frees the strings and the argv array + */ +void gnc_free_argv(char** argv); + +/* + * print out the argv array in a nice manner + */ +void print_argv(char **argv); + +/* + * get the length of null terminated char* array + */ +int argv_length(char** nulltermlist); + +#endif diff --git a/src/gnome-utils/gnc-gnome-utils.c b/src/gnome-utils/gnc-gnome-utils.c new file mode 100644 index 0000000000..6026d60004 --- /dev/null +++ b/src/gnome-utils/gnc-gnome-utils.c @@ -0,0 +1,124 @@ +/********************************************************************\ + * gnc-gnome-utils.c -- utility functions for gnome for GnuCash * + * Copyright (C) 2001 Linux Developers Group * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +#include "config.h" + +#include +#include + +#ifdef GTKHTML_HAVE_GCONF +#include +#endif + +#ifdef USE_GUPPI +#include "gnc-html-guppi.h" +#endif + +#include "argv-list-converters.h" +#include "gnc-gnome-utils.h" +#include "gnc-html.h" + + +static char** +gnc_scm2argv (SCM scm, int prelen, const char **prependargv) +{ + /* FIXME: when we drop support older guiles, drop the (char *) coercion. */ + return gnc_scheme_list_to_nulltermcharpp (prelen, prependargv, scm); +} + +static SCM +gnc_argv2scm (int len, const char **rest) +{ + return gnc_argvarr_to_scheme_list (len, rest); +} + +static const char *default_argv[] = {"", 0}; + +static const struct poptOption nullPoptTable[] = { + { NULL, 0, 0, NULL, 0 } +}; + +SCM +gnc_gnome_init (const char * arg0, + const char * progname, + const char * version, + SCM command_line) +{ + poptContext returnedPoptContext; + int restargc; + char **restargv; + char **restargv2; + SCM ret = command_line; + + if (arg0) + default_argv[0] = arg0; + + restargv = gnc_scm2argv (command_line, 1, default_argv); + if (!restargv) + { + restargv = g_new (char*, 2); + restargv[0] = g_strdup (default_argv[0]); + restargv[1] = NULL; + } + + restargc = argv_length (restargv); + + gnome_init_with_popt_table (progname, version, restargc, restargv, + nullPoptTable, 0, &returnedPoptContext); + + restargv2 = (char**) poptGetArgs (returnedPoptContext); + ret = gnc_argv2scm (argv_length (restargv2), (const char**)restargv2); + +#ifdef GTKHTML_HAVE_GCONF + { + GError * gerror; + + if (!gconf_init (restargc, restargv, &gerror)) + g_error_free (gerror); + } +#endif + + /* this must come after using the poptGetArgs return value */ + poptFreeContext (returnedPoptContext); + gnc_free_argv (restargv); + + /* initialization required for gtkhtml */ + gdk_rgb_init (); + gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); + gtk_widget_set_default_visual (gdk_rgb_get_visual ()); + +#ifdef USE_GUPPI + /* initialize guppi handling in gnc-html */ + gnc_html_guppi_init (); +#endif + + return ret; +} + +void +gnc_gnome_shutdown (void) +{ +#ifdef USE_GUPPI + gnc_html_guppi_shutdown(); +#endif +} diff --git a/src/gnome-utils/gnc-gnome-utils.h b/src/gnome-utils/gnc-gnome-utils.h new file mode 100644 index 0000000000..207b4a1102 --- /dev/null +++ b/src/gnome-utils/gnc-gnome-utils.h @@ -0,0 +1,34 @@ +/********************************************************************\ + * gnc-gnome-utils.h -- utility functions for gnome for GnuCash * + * Copyright (C) 2001 Linux Developers Group * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +#ifndef GNC_GNOME_UTILS_H +#define GNC_GNOME_UTILS_H + +SCM gnc_gnome_init (const char * arg0, + const char * progname, + const char * version, + SCM command_line); + +void gnc_gnome_shutdown (void); + +#endif diff --git a/src/gnome-utils/gnc-html.c b/src/gnome-utils/gnc-html.c index d4447db541..52b293a821 100644 --- a/src/gnome-utils/gnc-html.c +++ b/src/gnome-utils/gnc-html.c @@ -53,7 +53,6 @@ #include "gnc-html.h" #include "gnc-http.h" #include "gnc-html-history.h" -#include "gnc-network.h" #include "gnc-ui.h" #include "gnc-ui-util.h" #include "messages.h" diff --git a/src/gnome-utils/gncmod-gnome-utils.c b/src/gnome-utils/gncmod-gnome-utils.c index d255339659..76ce95d75b 100644 --- a/src/gnome-utils/gncmod-gnome-utils.c +++ b/src/gnome-utils/gncmod-gnome-utils.c @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include "gnc-module.h" #include "gnc-module-api.h" diff --git a/src/gnome-utils/gw-gnome-utils-spec.scm b/src/gnome-utils/gw-gnome-utils-spec.scm index 025fd3b2c0..f0c8ecfb5e 100644 --- a/src/gnome-utils/gw-gnome-utils-spec.scm +++ b/src/gnome-utils/gw-gnome-utils-spec.scm @@ -45,6 +45,7 @@ "#include \n" "#include \n" "#include \n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -53,6 +54,26 @@ "#include \n" ))) + + (gw:wrap-function + mod + 'gnc:gnome-init + ' + "gnc_gnome_init" + '((( gw:const) arg0) + (( gw:const) progname) + (( gw:const) version) + ( command-line)) + "Initialize the GnuCash gnome system.") + + (gw:wrap-function + mod + 'gnc:gnome-shutdown + ' + "gnc_gnome_shutdown" + '() + "Shutdown the GnuCash gnome system.") + (let ((nnt (gw:wrap-non-native-type mod '