GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gncmod-locale-reports-us.c
1 /*********************************************************************
2  * gncmod-locale-reports-us.c
3  * module definition/initialization for the US reports
4  *
5  * Copyright (c) 2001 Linux Developers Group, Inc.
6  *********************************************************************/
7 
8 #include "config.h"
9 #ifdef LOCALE_SPECIFIC_TAX
10 #include <string.h>
11 #include <locale.h>
12 #endif // LOCALE_SPECIFIC_TAX
13 #include <gmodule.h>
14 #include <libguile.h>
15 
16 #include "gnc-module.h"
17 #include "gnc-module-api.h"
18 
19 GNC_MODULE_API_DECL(libgncmod_locale_reports_us)
20 
21 /* version of the gnc module system interface we require */
22 int libgncmod_locale_reports_us_gnc_module_system_interface = 0;
23 
24 /* module versioning uses libtool semantics. */
25 int libgncmod_locale_reports_us_gnc_module_current = 0;
26 int libgncmod_locale_reports_us_gnc_module_revision = 0;
27 int libgncmod_locale_reports_us_gnc_module_age = 0;
28 
29 
30 char *
31 libgncmod_locale_reports_us_gnc_module_path(void)
32 {
33  /* const char *thislocale = setlocale(LC_ALL, NULL);
34  if (strncmp(thislocale, "de_DE", 5) == 0)
35  return g_strdup("gnucash/report/locale-specific/de_DE");
36  else */
37  return g_strdup("gnucash/report/locale-specific/us");
38 }
39 
40 char *
41 libgncmod_locale_reports_us_gnc_module_description(void)
42 {
43  return g_strdup("US income tax reports and related material");
44 }
45 
46 int
47 libgncmod_locale_reports_us_gnc_module_init(int refcount)
48 {
49  const gchar *tax_module, *report_taxtxf, *report_locale;
50  /* load the tax info */
51 #ifdef LOCALE_SPECIFIC_TAX
52  /* This is a very simple hack that loads the (new, special) German
53  tax definition file in a German locale, or (default) loads the
54  previous US tax file. */
55 # ifdef G_OS_WIN32
56  gchar *thislocale = g_win32_getlocale();
57  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
58  g_free(thislocale);
59 # else /* !G_OS_WIN32 */
60  const char *thislocale = setlocale(LC_ALL, NULL);
61  gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
62 # endif /* G_OS_WIN32 */
63 #else /* !LOCALE_SPECIFIC_TAX */
64  gboolean is_de_DE = FALSE;
65 #endif /* LOCALE_SPECIFIC_TAX */
66  if (is_de_DE)
67  {
68  tax_module = "gnucash/tax/de_DE";
69  report_taxtxf = "(use-modules (gnucash report taxtxf-de_DE))";
70  report_locale = "(use-modules (gnucash report locale-specific de_DE))";
71  }
72  else
73  {
74  tax_module = "gnucash/tax/us";
75  report_taxtxf = "(use-modules (gnucash report taxtxf))";
76  report_locale = "(use-modules (gnucash report locale-specific us))";
77  }
78 
79  /* The gchar* cast is only because the function declaration expects
80  a non-const string -- probably an api error. */
81  if (!gnc_module_load((gchar*)tax_module, 0))
82  {
83  return FALSE;
84  }
85 
86  /* load the report system */
87  if (!gnc_module_load("gnucash/report/report-system", 0))
88  {
89  return FALSE;
90  }
91 
92  /* load the report generation scheme code */
93  if (scm_c_eval_string(report_taxtxf)
94  == SCM_BOOL_F)
95  {
96  g_warning("failed to load %s\n", report_taxtxf);
97  return FALSE;
98  }
99 
100  /* Load the module scheme code */
101  if (scm_c_eval_string(report_locale)
102  == SCM_BOOL_F)
103  {
104  return FALSE;
105  }
106 
107  return TRUE;
108 }
109 
110 int
111 libgncmod_locale_reports_us_gnc_module_end(int refcount)
112 {
113  return TRUE;
114 }