/*
# +----------------------------------------------------------------------+
# | Aubit 4gl Language Compiler Version $.0                              |
# +----------------------------------------------------------------------+
# | Copyright (c) 2000-2005 Aubit Development Team (See Credits file)    |
# +----------------------------------------------------------------------+
# | This program is free software; you can redistribute it and/or modify |
# | it under the terms of one of the following licenses:                 |
# |                                                                      |
# |  A) 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.                                               |
# |                                                                      |
# |  B) the Aubit License as published by the Aubit Development Team and |
# |     included in the distribution in the file: LICENSE                |
# |                                                                      |
# | 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 both licenses referred to here.   |
# | If you did not, or have any questions about Aubit licensing, please  |
# | contact licensing@aubit.com                                           |
# +----------------------------------------------------------------------+
#
# $Id: a4gl_4gl_callable.h,v 1.84 2017-07-03 15:57:00 mikeaubury Exp $
*/

/**
 * @file
 * Header file used to include in the generated c files with origin
 * in the 4gl source files.
 *
 * This file is NOT included from anywhere else - compile_c.c prints
 * include statemennt for this file when outputing C code that is result
 * of compiling 4gl code by 4glc
 *
 * Therefore, this file contains definitions and prototypes that are
 * needed ONLY when compiling/running compiled programs, and NOT anywhere else in
 * Aubit compiler or libraries code.
 *
 */

#ifndef FGLINCLDEF_INCL
#define FGLINCLDEF_INCL

#ifdef __cplusplus
extern "C"
{
#endif


#ifndef ALLOW_BOTH_LIB_AND_CALL
#ifdef _AUBIT_LIB_INCL_EXT_
#error a4gl_4gl_callable.h and a4gl_libaubit4gl.h should not be included together
#endif
#endif


/* #include "a4gl_API_esql.h" */
#include "a4gl_exdata.h"
#include "a4gl_API_exreport.h"
#include "a4gl_API_form.h"
#include "a4gl_API_help.h"
/* #include "a4gl_API_lex.h" */
#include "a4gl_API_menu.h"
//#include "a4gl_API_msg.h"
/* #include "a4gl_API_packer.h" */
#include "a4gl_API_rpc.h"
#include "a4gl_API_sql.h"
#include "a4gl_API_sqlparse.h"
#include "a4gl_API_ui.h"
#include "a4gl_builtin_funcs.h"
// Cant add a4gl_sql.h - its not always available - because its not copied by a make install
//#include "a4gl_sql.h"
#include "json.h"

#ifndef A4GL_aubit_strcasecmp
#if HAVE_STRCASECMP 
#define A4GL_aubit_strcasecmp strcasecmp
#else
#define A4GL_aubit_strcasecmp A4GL_aubit_strcasecmp_internal
int A4GL_aubit_strcasecmp_internal (char *a, char *b);
#endif
#endif

int A4GL_load_data (char *fname, char *delims, void *filterfunc, char *tabname, ...);
void A4GL_end_report_table (struct BINDING *b, int n, struct BINDING *reread);
void A4GL_skip_top_of_page (struct rep_structure *rep,int rep_end);
void A4GL_aclfgli_skip_lines (struct rep_structure *rep);
void A4GL_add_spaces (void);
void A4GL_add_row_report_table (struct BINDING *b, int n);
void A4GL_need_lines (struct rep_structure *rep);
int A4GL_chk_params (struct BINDING *b, int nb, struct BINDING *o, int no);
void A4GL_def_int (void);
void A4GL_def_quit (void);
void A4GL_make_report_table (struct BINDING *b, int n);
int A4GL_init_report_table (struct BINDING *b, int n, struct BINDING *o, int no, struct BINDING **reread,char *asc_desc);
void *A4GLSQL_prepare_glob_sql (char *s, int ni, void  *ibind);
struct s_sid * A4GL_prepare_select (struct BINDING *ibind, int ni, struct BINDING *obind, int no, char *s,char *modname, int lineno,int converted, int singleton);


void A4GL_rep_file_print (struct rep_structure *rep, char *fname, int opt_semi);
void A4GL_rep_print (struct rep_structure *rep, int a, int s, int right_margin,int entry);
void A4GL_rep_print_tag(struct rep_structure *rep,int entry,char *_tag);
void A4GL_close_report_file(struct rep_structure *rep);
int A4GL_report_table_fetch (struct BINDING *reread, int n, struct BINDING *b);
void A4GL_set_column (struct rep_structure *rep);
void A4GL_set_help_file (char *fname);


#define ALREADY_DONE_POP_PUSH_ETC


// Sept 15 2006
int A4GL_get_a4gl_status (void);
void A4GLSQL_set_sqlerrd(int a0,int a1,int a2,int a3,int a4,int a5);
void A4GL_copy_sqlca_sqlawarn_8chars( char c0, char c1, char c2, char c3, char c4, char c5, char c6, char c7);
//void A4GL_set_sqlerrm (char *m, char *p);

//**********
double A4GL_pop_double(void);
double A4GL_pop_double_null_as_zero(void);
void A4GL_pop_into_double (double *d);
void A4GL_pop_into_double_null_as_zero(double *d );
int A4GL_pop_bool (void);
short A4GL_pop_int (void);
long A4GL_pop_long (void);
long A4GL_pop_date (void);
float A4GL_pop_float (void);
void A4GL_debug_full (char *fmt, ...);
void A4GL_debug_full_extended (char *fmt, ...);
int A4GL_pop_var (void *p, int d);
int A4GL_pop_var2 (void *p, int d, int s);
void A4GL_pop_object(char *objtype,void *obj,int dtype,int size,int isFcall) ;
//void A4GL_pop_object_n(char *objtype,void *obj,int dtype,int size) ;
int A4GL_pop_char (char *z, int size);
int A4GL_pop_param (void *p, int d, int size);
void A4GL_pop_params (struct BINDING *b, int n);
void A4GL_pop_params_and_save_blobs(struct BINDING *b, int n,void **blobdata);
void A4GL_copy_back_blobs(void *_blobdata,int nrets);
void A4GL_push_param (void *p, int d);
void A4GL_push_user (void);
void A4GL_push_today (void);
void A4GL_push_params (struct BINDING *b, int n);
void A4GL_pop_args (int a);
int A4GL_set_line (char *s, long l);
int A4GL_set_line_extended (char *s, long l, const char *level, const char * func);
char *a4gl_substr (char *s, int dtype, int a, int b, ...);
void A4GL_push_dtime (struct A4GLSQL_dtime *p);
void A4GL_push_int (short p);
int A4GL_push_binding_onto_stack(struct BINDING *b, int n);
int A4GL_pop_binding_from_stack(struct BINDING **b, int *n,char dir) ;
void A4GL_push_long (long p);
void A4GL_push_date (long p);
void A4GL_push_date_in_char(char *s);
void A4GL_push_float (float p);
void A4GL_push_dec (char *p, int ismoney,int size);
void A4GL_push_double (double p);
void A4GL_push_chars (char *p, int dtype, int size);
void A4GL_push_sqlerrmessage(void);
void A4GL_push_empty_char(void);
void A4GL_push_char (char *p);
void A4GL_push_char_not_null (char *p);
void A4GL_push_variable (void *ptr, int dtype);
void A4GL_push_interval (struct ival *p);
char *acl_getenv (const char *);
void A4GL_pushop (int a);
void A4GL_push_null (int dtype,int size);
void A4GL_push_bind (struct BINDING *b, int n, int no, int elemsize);
void A4GL_push_bind_reverse (struct BINDING *b, int n, int no, int elemsize);
void A4GL_chk_err (int lineno, char *fname);

void A4GL_pushIntEq(int a,int b);
void A4GL_pushIntNE(int a,int b);
void A4GL_pushIntGt(int a,int b);
void A4GL_pushIntLt(int a,int b);
void A4GL_pushIntLE(int a,int b);
void A4GL_pushIntGE(int a,int b);

void A4GL_err_continue_log (int lineno, char *fname);

int A4GLSTK_isStackInfo (void);
char *A4GLSTK_getStackTrace (void);
#define  A4GLSTK_pushFunction #error You must recompile your 4gl to remove the A4GLSTK_pushFunction function 
void A4GLSTK_pushFunction_v2 (const char *functionName, char *params[], int n,char *this_module,int this_line, void *objData[]);
void A4GLSTK_pushFunction_v3 (const char *functionName, char *params[], int n,char *this_module,int this_line, void *objData[],char functionOrReport);

void A4GLSTK_popFunction (void);
void A4GLSTK_popFunction_nl (int nrets,int yylineno);
void A4GL_fgl_end_4gl_0 (void);
void A4GL_fgl_end_4gl_1 (void); /* Used on interrupt */
void A4GL_display_at (int n, int a);
int A4GL_add_compiled_form (char *s, char *packer, char *formtype, char *frm);
int A4GL_set_status (int a, int sql);
int A4GL_key_val(char *s);
int A4GL_internal_build (void);
char *A4GL_internal_version (void);
//int aclfgl_aclfgl_setenv(int n);
//int aclfgl_aclfgl_get_stack_trace(int n);
//int aclfgl_aclfgl_replace_start(int n);
//int aclfgl_aclfgl_replace_in_string(int n);
int A4GL_setenv(char *name, char *value, int overwrite);
int A4GL_isyes(char *s);
int A4GL_isno(char *s);
void A4GL_set_esql_connection(char *s);
int A4GL_execute_implicit_select(void* sid,int singleton) ;
char *A4GL_get_esql_connection(void);
void *A4GL_get_curr_report(void);
void A4GL_set_curr_report(void *);
void A4GL_debug_full_extended_ln (char *s, long l, const char *level, const char * func, char *fmt, ...);
long A4GL_bounds_check(long a,long maxbound);
int A4GL_rep_is_stdout ( struct rep_structure *rep);
void A4GL_free_associated_mem(void *orig);
void A4GL_exitwith (char *s);
void A4GL_free_directory(void);
long A4GL_get_length (char *s);
void A4GL_trim_nl (char *p);
char **A4GL_read_directory(char *dir,char *spec);
int A4GL_sqlid_from_aclfile(char *dbname,char *uname,char *passwd, char *dsn);
char *a4gl_let_substr (char *ca, int dtype, int a, int b, ...);
int A4GL_system_run_waiting (char *rstr, char *msg, int sleep_sec,int repeat_sec, int use_error);
void A4GL_assertion (int a, char *s);
int A4GL_menu_hide (ACL_Menu * menu, ...);
int A4GL_menu_show (ACL_Menu * menu, ...);
//int A4GL_free_blob(fglbyte b);

char * acl_getenv_not_set_as_0 (const char *s);
int A4GL_fgl_fieldtouched_current(void *sio, char itype);
int A4GL_fgl_fieldtouched (void *i,char itype, ...);

void A4GL_dec_refcount(void **obj);

char *A4GL_get_ident(char *module,char *identifier, char *original_clobbered_name);
void A4GL_set_ignore_error_list(int n, ...) ;
void A4GL_clr_ignore_error_list(void);
struct sObject *new_object(char *type);


long A4GL_get_option_value (char type);

//long A4GL_create_object(char *s,int nparam);
int ensureObject(char *type,long objectId, struct sObject **o);
void A4GL_push_objectID (long p);
void A4GL_add_object_type(char *s);
int
A4GL_add_datatype_function_i (int a, char *funcname, void *func);

int send_report_to_ui(char *filename, int lineInFile);
char *A4GL_get_tmp_rep(char *mod,char *f);

void* A4GL_declare_cursor(int upd_hold,void* sid,int scroll,char* cursname) ;
int A4GL_add_prepare (char *pname, void *vsid);
void A4GL_free_cursor(char* cursor_name,int partOfAnotherCommand) ;
void A4GL_push_json(JsonNode *node);
int A4GL_open_cursor(char* s,int no,void* vibind) ;
int A4GL_fetch_cursor(char* cursor_name,int fetch_mode,int fetch_when,int nibind,void* ibind) ;
int A4GL_close_cursor(char* currname,int explicit_) ;
void A4GL_push_double_str (char *p);
void A4GL_register_global_objects(char *modulename,  void **objData) ;
void A4GL_register_module_objects(char *modulename,  void **objData) ;
void A4GL_register_report_objects(char *reportname,  void **objData) ;
int A4GL_get_hash_index(char **s, int sz, int idx);
void A4GL_unload_data2 (char *fname, char *delims,void *filterFunc, char *sql1,int nbind,struct BINDING *ibind,int converted);
int A4GL_execute_implicit_sql(void* sid,int singleton,int no,void* ibind) ;
void A4GL_log_error (int lineno, char *fname, int mstatus);
void A4GL_set_logsqlstart(void );
void A4GL_set_sqlerrd(int a0,int a1,int a2,int a3,int a4,int a5);
void A4GL_logsql(int lineno,char *module, char *s,char *type,char *cursor);
void A4GL_free_duplicate_binding (struct BINDING *b, int n);
void A4GL_set_sqlerrm (char *m, char *p);
void A4GL_convert_to_pdf_x (void);
void A4GL_acli_scroll (int n, ...);
int A4GL_strattr_to_num (char *s);
int A4GL_swap_bind_stmt (char *stmt, char t, void **sb, int *sc, void *bind, int cnt);
int aclfgl_fgl_setcurrline(int n);
int A4GL_directory_exists (char *fname);
int isverbose_c(int n);
int A4GL_aubit_strcasecmp_internal (char *a, char *b);
void trim (char *s);
int aclfgl_fgl_getpid(int n);
int aclfgl_ord (int n);

void A4GL_convert_to_pdf_y (void);
//
//int aclfgl_aclfgl_unload_csv_no_headers(int n);
//int aclfgl_aclfgl_unload_csv(int n);


//void A4GL_copyback(void *varptr,int sz, struct BINDING *binding, int n);

//int A4GL_fgl_infield (void *inp,char itype,...);
#ifndef LOCATE_VAR_DEFINED
#define LOCATE_VAR_DEFINED
void A4GL_locate_var (struct fgl_int_loc *p, char where, char *filename);
#endif

//void A4GLSQL_map_tname(char *db, char *code);
//void A4GLSQL_unmap_tname(char *db);
//int A4GLSQL_is_tname_mapped(char *code);


#define A4GL_FUNCTION
#define A4GL_INTERNAL_FUNCTION
#define A4GL_MAIN
#define A4GL_REPORT


#ifdef __cplusplus
}
#endif
#endif				/* #ifndef FGLHDR_INCL */
