/* Generated by G-Wrap: an experimental C->Guile wrapper engine */

#include <guile/gh.h>
#include <libguile.h>
#include <string.h>
#include <g-wrap-compatibility.h>

#include "gw-app-file.h"
#include <glib.h>
#include <guid.h>
#include <Query.h>
#include <Backend.h>
#include <Group.h>
#include <gnc-book.h>
#include <gnc-session.h>
#include <gnc-session-scm.h>
#include <gnc-engine-util.h>
#include <gnc-event.h>
#include <gnc-lot.h>
#include <date.h>
#include <engine-helpers.h>
#include <gnc-engine.h>
#include <gnc-commodity.h>
#include <gnc-numeric.h>
#include <g-wrap-wct.h>
#include <glib.h>
#include <g-wrap-glib.h>
#include <gnc-file.h>
#include <gnc-file-history.h>
#include <gnc-file-dialog.h>
enum GW__ErrorStatus
{
  GW__ERR_NONE,
  GW__ERR_MISC,
  GW__ERR_MEMORY,
  GW__ERR_RANGE,
  GW__ERR_TYPE,
  GW__ERR_ARGC,
  GW__ERR_ARG_RANGE,
  GW__ERR_ARG_TYPE
};
 
static void
gw__handle_wrapper_error(enum GW__ErrorStatus status,
                         const char *func_name,
                         unsigned int arg_pos,
                         const char *misc_msg,
                         SCM scm_data) __attribute__ ((noreturn));

static void
gw__handle_wrapper_error(enum GW__ErrorStatus status,
                         const char *func_name,
                         unsigned int arg_pos,
                         const char *misc_msg,
                         SCM scm_data)
{
  static SCM out_of_range_key = SCM_BOOL_F;
  static SCM wrong_type_key = SCM_BOOL_F;

  if(SCM_FALSEP(out_of_range_key))
    out_of_range_key = scm_permanent_object(scm_c_make_keyword("out-of-range"));
  if(SCM_FALSEP(wrong_type_key))
    wrong_type_key = scm_permanent_object(scm_c_make_keyword("wrong-type"));

  switch(status) {
  case GW__ERR_NONE:
    scm_misc_error(func_name,
                   "asked to handle error when there wasn't one",
                   SCM_EOL);
    break;
  case GW__ERR_MISC:
    /* scm_data is a list of format args for misc_msg */
    scm_misc_error(func_name, misc_msg, scm_data); break;
  case GW__ERR_MEMORY:
    scm_memory_error(func_name); break;
  case GW__ERR_RANGE:
    scm_error (out_of_range_key,
	       func_name,
	       "Out of range: ~S",
               scm_cons (scm_data, SCM_EOL),
	       SCM_BOOL_F);
    break;
  case GW__ERR_TYPE:
    scm_error(wrong_type_key,
              func_name,
              "Wrong type: ",
              scm_cons (scm_data, SCM_EOL),
              SCM_BOOL_F);
    break;
  case GW__ERR_ARGC:
    scm_wrong_num_args(scm_makfrom0str(func_name)); break;
  case GW__ERR_ARG_RANGE:
    /* scm_data is the bad arg */
    scm_out_of_range(func_name, scm_data); break;
  case GW__ERR_ARG_TYPE:
    /* scm_data is the bad arg */
    scm_wrong_type_arg(func_name, arg_pos, scm_data); break;
  default:
    scm_misc_error(func_name,
                   "asked to handle nonexistent gw:error type: ~S",
                   scm_cons(scm_long2num(status), SCM_EOL));    
    break;
  };
  exit(1);
}
static char * gw__tmp557_gnc_file_query_save_namestr = "gnc:file-query-save";
static SCM gw__tmp556_gnc_file_query_save_wrapper  () {
  SCM gw__scm_result = SCM_UNSPECIFIED;
  enum GW__ErrorStatus gw__error_status = GW__ERR_NONE;
  SCM gw__error_data = SCM_UNSPECIFIED;
  unsigned int gw__arg_pos = 0;
  const char *gw__error_misc_msg = NULL;
int gw__c_result;

if (gw__error_status == GW__ERR_NONE)
{
  /* no pre-call result code requested! */
if (gw__error_status != GW__ERR_NONE) goto gw__wrapper_exit;
SCM_DEFER_INTS;
gw__c_result = gnc_file_query_save ();
SCM_ALLOW_INTS;
{
gw__scm_result= (gw__c_result) ? SCM_BOOL_T : SCM_BOOL_F;
}
}
 gw__wrapper_exit:
  if(gw__error_status != GW__ERR_NONE)
    gw__handle_wrapper_error(gw__error_status,
                             gw__tmp557_gnc_file_query_save_namestr,
                             gw__arg_pos,
                             gw__error_misc_msg,
                             gw__error_data);
  return gw__scm_result;
}
static char * gw__tmp559_gnc_file_quit_namestr = "gnc:file-quit";
static SCM gw__tmp558_gnc_file_quit_wrapper  () {
  SCM gw__scm_result = SCM_UNSPECIFIED;
  enum GW__ErrorStatus gw__error_status = GW__ERR_NONE;
  SCM gw__error_data = SCM_UNSPECIFIED;
  unsigned int gw__arg_pos = 0;
  const char *gw__error_misc_msg = NULL;

if (gw__error_status == GW__ERR_NONE)
{
  /* no pre-call result code requested! */
if (gw__error_status != GW__ERR_NONE) goto gw__wrapper_exit;
SCM_DEFER_INTS;
gnc_file_quit ();
SCM_ALLOW_INTS;
{
gw__scm_result = SCM_UNSPECIFIED;
}
}
 gw__wrapper_exit:
  if(gw__error_status != GW__ERR_NONE)
    gw__handle_wrapper_error(gw__error_status,
                             gw__tmp559_gnc_file_quit_namestr,
                             gw__arg_pos,
                             gw__error_misc_msg,
                             gw__error_data);
  return gw__scm_result;
}
static char * gw__tmp561_gnc_file_open_file_namestr = "gnc:file-open-file";
static SCM gw__tmp560_gnc_file_open_file_wrapper  (SCM gw__scm_arg0 ) {
  SCM gw__scm_result = SCM_UNSPECIFIED;
  enum GW__ErrorStatus gw__error_status = GW__ERR_NONE;
  SCM gw__error_data = SCM_UNSPECIFIED;
  unsigned int gw__arg_pos = 0;
  const char *gw__error_misc_msg = NULL;
int gw__c_result;

const char * gw__c_arg0;
/* ARG 0 */
gw__arg_pos++;
if (gw__error_status != GW__ERR_NONE) goto gw__wrapper_exit;

{
gw__c_arg0 = NULL;

if(SCM_FALSEP(gw__scm_arg0))
  gw__c_arg0 = NULL;
else if(SCM_STRINGP(gw__scm_arg0))
  gw__c_arg0 = gh_scm2newstr(gw__scm_arg0, NULL);
else
{
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
if((gw__error_status == GW__ERR_TYPE)){
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
else if((gw__error_status == GW__ERR_RANGE)){
   gw__error_status = GW__ERR_ARG_RANGE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
if (gw__error_status == GW__ERR_NONE)
{
  /* no pre-call result code requested! */
if (gw__error_status != GW__ERR_NONE) goto gw__post_call_arg_0;
SCM_DEFER_INTS;
gw__c_result = gnc_file_open_file (gw__c_arg0);
SCM_ALLOW_INTS;
{
gw__scm_result= (gw__c_result) ? SCM_BOOL_T : SCM_BOOL_F;
}
}
  gw__post_call_arg_0:
{
if(gw__c_arg0) free((void *) gw__c_arg0);
}
  { /* shut up warnings if no code */ int x = x; }
}
 gw__wrapper_exit:
  if(gw__error_status != GW__ERR_NONE)
    gw__handle_wrapper_error(gw__error_status,
                             gw__tmp561_gnc_file_open_file_namestr,
                             gw__arg_pos,
                             gw__error_misc_msg,
                             gw__error_data);
  return gw__scm_result;
}
static char * gw__tmp563_gnc_history_get_last_namestr = "gnc:history-get-last";
static SCM gw__tmp562_gnc_history_get_last_wrapper  () {
  SCM gw__scm_result = SCM_UNSPECIFIED;
  enum GW__ErrorStatus gw__error_status = GW__ERR_NONE;
  SCM gw__error_data = SCM_UNSPECIFIED;
  unsigned int gw__arg_pos = 0;
  const char *gw__error_misc_msg = NULL;
const char * gw__c_result;

if (gw__error_status == GW__ERR_NONE)
{
  /* no pre-call result code requested! */
if (gw__error_status != GW__ERR_NONE) goto gw__wrapper_exit;
SCM_DEFER_INTS;
gw__c_result = gnc_history_get_last ();
SCM_ALLOW_INTS;
{
  /* we coerce to (char *) here b/c broken guile 1.3.4 prototype */
if(gw__c_result == NULL) gw__scm_result = SCM_BOOL_F;
else gw__scm_result = gh_str02scm((char *) gw__c_result);
}
}
 gw__wrapper_exit:
  if(gw__error_status != GW__ERR_NONE)
    gw__handle_wrapper_error(gw__error_status,
                             gw__tmp563_gnc_history_get_last_namestr,
                             gw__arg_pos,
                             gw__error_misc_msg,
                             gw__error_data);
  return gw__scm_result;
}
static char * gw__tmp565_gnc_file_dialog_namestr = "gnc:file-selection-dialog";
static SCM gw__tmp564_gnc_file_dialog_wrapper  (SCM gw__scm_arg0, SCM gw__scm_arg1, SCM gw__scm_arg2 ) {
  SCM gw__scm_result = SCM_UNSPECIFIED;
  enum GW__ErrorStatus gw__error_status = GW__ERR_NONE;
  SCM gw__error_data = SCM_UNSPECIFIED;
  unsigned int gw__arg_pos = 0;
  const char *gw__error_misc_msg = NULL;
const char * gw__c_result;

const char * gw__c_arg0;
const char * gw__c_arg1;
const char * gw__c_arg2;
/* ARG 0 */
gw__arg_pos++;
if (gw__error_status != GW__ERR_NONE) goto gw__wrapper_exit;

{
gw__c_arg0 = NULL;

if(SCM_FALSEP(gw__scm_arg0))
  gw__c_arg0 = NULL;
else if(SCM_STRINGP(gw__scm_arg0))
  gw__c_arg0 = gh_scm2newstr(gw__scm_arg0, NULL);
else
{
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
if((gw__error_status == GW__ERR_TYPE)){
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
else if((gw__error_status == GW__ERR_RANGE)){
   gw__error_status = GW__ERR_ARG_RANGE;
    gw__error_data = gw__scm_arg0;
   goto gw__post_call_arg_0;
}
/* ARG 1 */
gw__arg_pos++;
if (gw__error_status != GW__ERR_NONE) goto gw__post_call_arg_0;

{
gw__c_arg1 = NULL;

if(SCM_FALSEP(gw__scm_arg1))
  gw__c_arg1 = NULL;
else if(SCM_STRINGP(gw__scm_arg1))
  gw__c_arg1 = gh_scm2newstr(gw__scm_arg1, NULL);
else
{
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg1;
   goto gw__post_call_arg_1;
}
if((gw__error_status == GW__ERR_TYPE)){
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg1;
   goto gw__post_call_arg_1;
}
else if((gw__error_status == GW__ERR_RANGE)){
   gw__error_status = GW__ERR_ARG_RANGE;
    gw__error_data = gw__scm_arg1;
   goto gw__post_call_arg_1;
}
/* ARG 2 */
gw__arg_pos++;
if (gw__error_status != GW__ERR_NONE) goto gw__post_call_arg_1;

{
gw__c_arg2 = NULL;

if(SCM_FALSEP(gw__scm_arg2))
  gw__c_arg2 = NULL;
else if(SCM_STRINGP(gw__scm_arg2))
  gw__c_arg2 = gh_scm2newstr(gw__scm_arg2, NULL);
else
{
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg2;
   goto gw__post_call_arg_2;
}
if((gw__error_status == GW__ERR_TYPE)){
   gw__error_status = GW__ERR_ARG_TYPE;
    gw__error_data = gw__scm_arg2;
   goto gw__post_call_arg_2;
}
else if((gw__error_status == GW__ERR_RANGE)){
   gw__error_status = GW__ERR_ARG_RANGE;
    gw__error_data = gw__scm_arg2;
   goto gw__post_call_arg_2;
}
if (gw__error_status == GW__ERR_NONE)
{
  /* no pre-call result code requested! */
if (gw__error_status != GW__ERR_NONE) goto gw__post_call_arg_2;
SCM_DEFER_INTS;
gw__c_result = gnc_file_dialog (gw__c_arg0, gw__c_arg1, gw__c_arg2);
SCM_ALLOW_INTS;
{
  /* we coerce to (char *) here b/c broken guile 1.3.4 prototype */
if(gw__c_result == NULL) gw__scm_result = SCM_BOOL_F;
else gw__scm_result = gh_str02scm((char *) gw__c_result);
}
}
  gw__post_call_arg_2:
{
if(gw__c_arg2) free((void *) gw__c_arg2);
}
  { /* shut up warnings if no code */ int x = x; }
}
  gw__post_call_arg_1:
{
if(gw__c_arg1) free((void *) gw__c_arg1);
}
  { /* shut up warnings if no code */ int x = x; }
}
  gw__post_call_arg_0:
{
if(gw__c_arg0) free((void *) gw__c_arg0);
}
  { /* shut up warnings if no code */ int x = x; }
}
 gw__wrapper_exit:
  if(gw__error_status != GW__ERR_NONE)
    gw__handle_wrapper_error(gw__error_status,
                             gw__tmp565_gnc_file_dialog_namestr,
                             gw__arg_pos,
                             gw__error_misc_msg,
                             gw__error_data);
  return gw__scm_result;
}
void
gw_init_wrapset_gw_app_file() {
  static int gw_wrapset_initialized = 0;

  if(!gw_wrapset_initialized)
  {
    gh_eval_str("(use-modules (g-wrap runtime))");
    gh_eval_str("(gw:wrapset-register-runtime \"gw-app-file\")");

gh_eval_str("(use-modules (g-wrapped gw-engine))");
gh_eval_str("(use-modules (g-wrap gw-glib))");
gh_eval_str("(use-modules (g-wrap gw-standard))");
{
   enum GW__ErrorStatus gw__tmp566_status_var = GW__ERR_NONE;
   SCM gw__tmp568_err_data = SCM_UNSPECIFIED;
   char *gw__tmp567_err_misc_msg = NULL;
   (void) gw__tmp566_status_var;
   (void) gw__tmp568_err_data;
   (void) gw__tmp567_err_misc_msg;
}
{
   enum GW__ErrorStatus gw__tmp569_err_status = GW__ERR_NONE;
   SCM gw__tmp571_err_data = SCM_UNSPECIFIED;
   char *gw__tmp570_err_misc_msg = NULL;
   (void) gw__tmp569_err_status;
   (void) gw__tmp571_err_data;
   (void) gw__tmp570_err_misc_msg;
}
{
   enum GW__ErrorStatus gw__tmp572_status_var = GW__ERR_NONE;
   SCM gw__tmp574_err_data = SCM_UNSPECIFIED;
   char *gw__tmp573_err_misc_msg = NULL;
   (void) gw__tmp572_status_var;
   (void) gw__tmp574_err_data;
   (void) gw__tmp573_err_misc_msg;
    gh_new_procedure(gw__tmp557_gnc_file_query_save_namestr,
                     (SCM (*) ()) gw__tmp556_gnc_file_query_save_wrapper,
                     0,
                     0,
                     0);

if (gw__tmp572_status_var != GW__ERR_NONE)  gw__handle_wrapper_error (gw__tmp572_status_var,
                            "gw_init_wrapset_gw_app_file",
                            0,
                            gw__tmp573_err_misc_msg,
                            gw__tmp574_err_data);
    gh_new_procedure(gw__tmp559_gnc_file_quit_namestr,
                     (SCM (*) ()) gw__tmp558_gnc_file_quit_wrapper,
                     0,
                     0,
                     0);

if (gw__tmp572_status_var != GW__ERR_NONE)  gw__handle_wrapper_error (gw__tmp572_status_var,
                            "gw_init_wrapset_gw_app_file",
                            0,
                            gw__tmp573_err_misc_msg,
                            gw__tmp574_err_data);
    gh_new_procedure(gw__tmp561_gnc_file_open_file_namestr,
                     (SCM (*) ()) gw__tmp560_gnc_file_open_file_wrapper,
                     1,
                     0,
                     0);

if (gw__tmp572_status_var != GW__ERR_NONE)  gw__handle_wrapper_error (gw__tmp572_status_var,
                            "gw_init_wrapset_gw_app_file",
                            0,
                            gw__tmp573_err_misc_msg,
                            gw__tmp574_err_data);
    gh_new_procedure(gw__tmp563_gnc_history_get_last_namestr,
                     (SCM (*) ()) gw__tmp562_gnc_history_get_last_wrapper,
                     0,
                     0,
                     0);

if (gw__tmp572_status_var != GW__ERR_NONE)  gw__handle_wrapper_error (gw__tmp572_status_var,
                            "gw_init_wrapset_gw_app_file",
                            0,
                            gw__tmp573_err_misc_msg,
                            gw__tmp574_err_data);
    gh_new_procedure(gw__tmp565_gnc_file_dialog_namestr,
                     (SCM (*) ()) gw__tmp564_gnc_file_dialog_wrapper,
                     3,
                     0,
                     0);

if (gw__tmp572_status_var != GW__ERR_NONE)  gw__handle_wrapper_error (gw__tmp572_status_var,
                            "gw_init_wrapset_gw_app_file",
                            0,
                            gw__tmp573_err_misc_msg,
                            gw__tmp574_err_data);
}
    gw_wrapset_initialized = 1;
    (void) gw__handle_wrapper_error;
  }
}
