/****************************************************************************
 *
 *	Copyright (C) 1984-2006 Micro Focus (IP) Limited.
 *	All rights reserved.
 *
 *	The software and information contained herein are
 *	proprietary to, and comprise valuable trade secrets of,
 *	Micro Focus (IP) Limited, which intends to preserve
 *	as trade secrets such software and information. This software
 *	is an unpublished copyright of Micro Focus and may not be
 *	used, copied, transmitted, or stored in any manner.  This
 *	software and information or any other copies thereof may not
 *	be provided or otherwise made available to any other person.
 *
 *	Genesis Run Time System (Studio/Server 5.0 Freeze)
 *
 *	@(#)cbltypes.h	11.4
 *
 *	Last Modified on 06/08/31 at 18:24:26
 *
 ****************************************************************************/

/** Start of source module cbltypes.h **/

#ifndef	_CBLTYPES_H
#define	_CBLTYPES_H

#include "cobtypes.h"

#ifdef	__cplusplus
extern "C" {
#endif

/***********************************************************************
 *
 * This include file, which is supplied as $COBDIR/include/cbltypes.h, 
 *  defines corresponding C types for all the COBOL types defined in 
 *  $COBDIR/cpylib/cbltypes.cpy.  This include file, in conjunction 
 *  with the cbltypes.cpy copy book, can be useful in a mixed language 
 *  (C/COBOL) programming environment.
 *
 * Also included are the C-style definition of the parameter blocks
 *  required by many of the CBL_ prefix routines.
 *
 * NOTE: Defines that you might have to set when using this include
 *       file are:
 *         CBL_ALPHA_32BIT     <= On the Compaq Alpha Unix 32-bit COBOL
 *                                product, COBOL pointers are only 32 bits
 *                                whilst system pointers are 64-bit. 
 *
 ***********************************************************************/

#include <sys/types.h>

#if defined(CBL_NO_INTTYPES_H) && defined(_MSC_VER) && !defined(_SSIZE_T_DEFINED)
/* Microsoft C compilers do not define ssize_t */
#include <stdlib.h>

#ifdef _WIN64
typedef	__int64		ssize_t;
#else
typedef __int32		ssize_t;
#endif
#define _SSIZE_T_DEFINED

#endif

/***********************************************************************
 *
 * Basic Cobol types, used when passed by reference.
 *
 * To obtain a value from these types, they must be unpicked using the
 * cobget/put API calls - these calls take care of possible byteswap
 * (for COMP-X items) and alignment issues (for all items).
 *
 * cbl_x1_t             A cobol character position - basis for all types
 *
 * cbl_pointer_t	A (possibly unaligned) Cobol pointer.
 * cbl_ppointer_t	A (possibly unaligned) Cobol procedure pointer.
 *
 * cbl_sx1_comp5_t	Equivalent to: PIC s9(n)  COMP-5 where n=1 or 2
 * cbl_sx2_comp5_t	Equivalent to: PIC s9(n)  COMP-5 where n=3 or 4
 * cbl_sx4_comp5_t	Equivalent to: PIC s9(n)  COMP-5 where n=7 through 9
 * cbl_sx8_comp5_t	Equivalent to: PIC s9(18) COMP-5
 *
 * cbl_x1_comp5_t	Equivalent to: PIC X(1) COMP-5
 * cbl_x2_comp5_t	Equivalent to: PIC X(2) COMP-5
 * cbl_x4_comp5_t	Equivalent to: PIC X(4) COMP-5
 * cbl_x8_comp5_t	Equivalent to: PIC X(8) COMP-5
 *
 * cbl_x1_compx_t	Equivalent to: PIC X(1) COMP-X
 * cbl_x2_compx_t	Equivalent to: PIC X(2) COMP-X
 * cbl_x4_compx_t	Equivalent to: PIC X(4) COMP-X
 * cbl_x8_compx_t	Equivalent to: PIC X(8) COMP-X
 *
 ***********************************************************************/

typedef	cobchar_t       cbl_x1_t;

#ifdef CBL_ALPHA_32BIT 
typedef	struct { 
    cbl_x1_t	byte[4];
} cbl_pointer_t;

typedef	struct { 
    cbl_x1_t	byte[4];
} cbl_ppointer_t;
#else
typedef	struct { 
    cbl_x1_t	byte[sizeof(void *)];
} cbl_pointer_t;

typedef	struct { 
    cbl_x1_t	byte[sizeof(void *)];
} cbl_ppointer_t;
#endif

typedef	struct
{
    cbl_x1_t	byte;
} cbl_x1_comp5_t;

typedef	struct
{
    cbl_x1_t	byte;
} cbl_sx1_comp5_t;

typedef struct
{
    cbl_x1_t	byte;
} cbl_x1_compx_t;

typedef	struct
{
    cbl_x1_t	byte[2];
} cbl_x2_comp5_t;

typedef	struct
{
    cbl_x1_t	byte[2];
} cbl_sx2_comp5_t;

typedef struct
{
    cbl_x1_t	byte[2];
} cbl_x2_compx_t;

typedef	struct
{
    cbl_x1_t	byte[4];
} cbl_x4_comp5_t;

typedef	struct
{
    cbl_x1_t	byte[4];
} cbl_sx4_comp5_t;

typedef struct
{
    cbl_x1_t	byte[4];
} cbl_x4_compx_t;

typedef	struct
{
    cbl_x1_t	byte[8];
} cbl_x8_comp5_t;

typedef	struct
{
    cbl_x1_t	byte[8];
} cbl_sx8_comp5_t;

typedef struct
{
    cbl_x1_t	byte[8];
} cbl_x8_compx_t;

typedef struct
{
    cbl_x1_t	byte[sizeof(size_t)];
} cbl_os_size_comp5_t;

/***********************************************************************
 *
 * General Cobol types, used when by passed value.
 *
 * cbl_os_pointer_t	A system pointer
 * cbl_os_offset_t	Large enough to hold any OS file offsets
 * cbl_os_size_t	Large enough to hold any OS unsigned integer size
 * cbl_os_ssize_t	Large enough to hold any OS signed integer size
 * cbl_os_flags_t	Flags.
 *
 ***********************************************************************/

typedef	PFR	       (*cbl_os_ppointer_t)();
typedef	void		*cbl_os_pointer_t;

typedef	off_t	 	cbl_os_offset_t;  /* or 'unsigned long' */
typedef	size_t 		cbl_os_size_t;    /* or 'unsigned long' */
typedef	ssize_t 	cbl_os_ssize_t;   /* or 'long' */
typedef	size_t		cbl_os_flags_t;   /* or 'unsigned long' */

/***********************************************************************
 *
 * Returning Cobol types.
 *
 * cbl_rtncode_t	Returning item for all other CBL_ calls.
 *
 ***********************************************************************/

typedef	cobrtncode_t	cbl_rtncode_t;

/***********************************************************************
 *
 * Types for specific CBL_ routines, used when passed by reference...
 *
 ***********************************************************************/
 
/* 
 * Types and structures used by the file and filename handling routines
 */
typedef	cbl_x2_comp5_t  cbl_vfile_handle_t;
typedef	cbl_x2_compx_t	cbl_vfile_status_t;

typedef	cbl_x4_comp5_t  cbl_bytestream_handle_t;

typedef	cbl_x2_compx_t	cbl_file_status_t;

typedef struct cbl_fileexist_buf_t {
    cbl_x8_compx_t  fe_filesize;
    struct {
	cbl_x1_compx_t   day;
	cbl_x1_compx_t   month;
	cbl_x2_compx_t  year;
    } fe_date;
    struct {
	cbl_x1_compx_t   hours;
	cbl_x1_compx_t   minutes;
	cbl_x1_compx_t   seconds;
	cbl_x1_compx_t   hundreths;
    } fe_time;
} cbl_fileexist_buf_t;

typedef struct cbl_splitjoin_buf_t {
	cbl_x2_compx_t  sj_param_length;
	cbl_x1_compx_t  sj_split_join_flag1;
	cbl_x1_compx_t  sj_split_join_flag2;
	cbl_x2_compx_t  sj_device_offset;
	cbl_x2_compx_t  sj_device_length;
	cbl_x2_compx_t  sj_basename_offset;
	cbl_x2_compx_t  sj_basename_length;
	cbl_x2_compx_t  sj_extension_offset;
	cbl_x2_compx_t  sj_extension_length;
	cbl_x2_compx_t  sj_total_length;
	cbl_x2_compx_t  sj_split_buf_len;
	cbl_x2_compx_t  sj_join_buf_len;
	cbl_x2_compx_t  sj_first_path_component_length;
} cbl_splitjoin_buf_t;

/*
 * Structure used by the memory management routines
 */
typedef struct
{
    cbl_x1_comp5_t      name_len;
    cbl_x1_t   		name_text[1];			/* First of n */
} cbl_node_name_t;


/*
 * Structures used by the mouse handling routines
 */
typedef struct
{
    cbl_x2_compx_t	row;
    cbl_x2_compx_t	col;
} cbl_mouse_pos_t;

typedef struct
{
    cbl_x2_compx_t	fs;
    cbl_x4_compx_t	time;
    cbl_x2_compx_t	row;
    cbl_x2_compx_t	col;
} cbl_mouse_event_t;

typedef struct
{
    cbl_x1_t	 	char_and_mask;
    cbl_x1_t	 	attr_and_mask;
    cbl_x1_t	 	char_xor_mask;
    cbl_x1_t	 	attr_xor_mask;
} cbl_mouse_shape_t;

typedef struct
{
    cbl_x2_compx_t	top;
    cbl_x2_compx_t	left;
    cbl_x2_compx_t	bottom;
    cbl_x2_compx_t	right;
} cbl_mouse_rect_t;

/*
 * Structures used by CBL_NLS_ messaging routines
 */
typedef struct
{
    cbl_x2_compx_t	msg_set_number;
    cbl_x2_compx_t	msg_number;
} cbl_nls_msg_number_pair_t;

typedef struct
{
    cbl_x2_compx_t	msg_ins_count;
    cbl_pointer_t	msg_ins_pointer[1];		/* First of n */
} cbl_nls_msg_ins_struct_t;

typedef struct
{
    cbl_x2_compx_t	msg_buff_len;
    cbl_x1_t		msg_buff_text[1];		/* First of n */
} cbl_nls_msg_buffer_t;

typedef struct
{
    cbl_x2_compx_t	msg_set_number;
    cbl_x2_compx_t	msg_number;
    cbl_x2_compx_t	msg_max_buffer_len;
    cbl_x2_compx_t	msg_actual_msg_len;
    cbl_x2_compx_t	msg_flags;
} cbl_nls_msg_params_t;

/*
 * Structure used by CBL_CANCEL_PROC
 */
typedef struct
{
    cbl_x4_comp5_t	cppb_version;
    cbl_x4_comp5_t	cppb_flags;
    cbl_ppointer_t	cppb_callback;
    cbl_pointer_t	cppb_handle;
    cbl_pointer_t	cppb_userdata;
    cbl_x4_comp5_t	cppb_priority;
} cbl_cancel_proc_params_t;

/*
 * Structure used by CBL_EXIT_PROC
 */
typedef struct
{
    cbl_ppointer_t	ep_install_addr;
    cbl_x1_compx_t	ep_install_priority;
} cbl_exit_params_t;

/*
 * Structure used by CBL_SUBSYSTEM
 */
typedef struct
{
    cbl_x2_compx_t	ss_handle;
    cbl_x2_compx_t	ss_name_len;
    cbl_x1_t		ss_name[1];			/* First of n */
} cbl_subsys_params_t;


/*
 * Structure used by CBL_GET_EXIT_INFO
 */
typedef struct
{
    cbl_x4_comp5_t	gei_size;
    cbl_x4_comp5_t	gei_return_code;
    cbl_x4_comp5_t	gei_rts_error;
    cbl_x4_comp5_t	gei_exit_flags;
} cbl_exit_info_params_t;

/*
 * Structure used by CBL_GET_OS_INFO
 */

typedef struct 
{
    cbl_x2_compx_t	osi_length;
    cbl_x1_compx_t      osi_os_type;
    cbl_x4_compx_t      osi_os_version;
    cbl_x1_compx_t      osi_dbcs_support;
    cbl_x1_compx_t      osi_char_coding;
    cbl_x2_compx_t      osi_country_id;
    cbl_x2_compx_t      osi_code_page;
    cbl_x1_compx_t      osi_process_type;
    cbl_x4_compx_t      osi_rts_capabilities;
    cbl_x2_compx_t      osi_product;
    cbl_x2_compx_t      osi_product_version;
    cbl_x2_compx_t      osi_product_revision;
    cbl_x2_compx_t      osi_product_sp;
    cbl_x2_compx_t      osi_fixpack;
} cbl_os_info_params_t;

/*
 * Structures used by CBL_GET_PROGRAM_INFO
 */

typedef struct 
{
    cbl_x4_comp5_t	gpi_size;
    cbl_x4_comp5_t	gpi_flags;
    cbl_pointer_t	gpi_handle;
    cbl_pointer_t	gpi_prog_id;
    cbl_x4_comp5_t	gpi_attrs;
} cbl_prog_info_params_t;

typedef struct
{
    cbl_x4_comp5_t	gpiai_size;
    cbl_x4_comp5_t	gpiai_argc;
    cbl_pointer_t	gpiai_reserved1;
    cbl_pointer_t	gpiai_reserved2;
} cbl_prog_info_arg_info_t;

/*
 * Structure used by CBL_MEM_VALIDATE
 */

typedef struct 
{
    cbl_x4_comp5_t	mv_version;
    cbl_x4_comp5_t	mv_flags;
    cbl_x4_comp5_t	mv_type;
    cbl_os_size_comp5_t	mv_size;
    cbl_pointer_t	mv_address;
} cbl_mem_validate_params_t;

/*
 * Structure used by CBL_GET_FILE_SYSTEM_INFO
 */

typedef struct 
{
    cbl_x4_comp5_t	fsi_version;
    cbl_x4_comp5_t	fsi_block_len;
    cbl_x8_comp5_t	fsi_free_space;
    cbl_x8_comp5_t	fsi_total_space;
    cbl_x8_comp5_t	fsi_available_free_space;
    cbl_x4_comp5_t	fsi_capabilities;
} cbl_fs_info_params_t;

/*
 * Structures used by CBL_DIR_SCAN_ directory scanning routines
 */

/** IMPORTANT ** The following struct is used to store a string. **/
/** IMPORTANT ** As such the sizeof() operator is not reliable   **/
/** IMPORTANT ** Use sizeof(cbl_ds_msg_t) + <msg_buff_len> - 1   **/
typedef struct
{
    cbl_x2_comp5_t	msg_buff_len;
    cbl_x1_t		msg_buff_text[1];
} cbl_ds_msg_t;

typedef struct
{
    cbl_x4_comp5_t	year;
    cbl_x2_comp5_t	month;
    cbl_x2_comp5_t	day;
    cbl_x2_comp5_t	hour;
    cbl_x2_comp5_t	minute;
    cbl_x2_comp5_t	second;
    cbl_x2_comp5_t	millisec;
    cbl_x1_t		dst;
} cbl_ds_datestamp_t;

typedef struct
{
    cbl_x4_comp5_t	attribute;
    cbl_ds_datestamp_t	datestamp;
    cbl_x8_comp5_t	size;
    cbl_ds_msg_t	name;
} cbl_ds_entry_t;

/*
 * Structures used by CBL_nnnn_SCR_ screen handling calls.
 */
typedef struct
{
    cbl_x1_compx_t	sp_row;
    cbl_x1_compx_t	sp_col;
} cbl_screen_position_t;

typedef struct
{
    cbl_x1_compx_t	gsgb_flag;
    cbl_x2_compx_t	gsgb_buf_size;
    struct
    {
	struct
	{
	    cbl_x1_compx_t	up_arrow_dbflag;
	    cbl_x1_compx_t	up_arrow;
	}		    dbcs_up_arrow;
	struct
	{
	    cbl_x1_compx_t	down_arrow_dbflag;
	    cbl_x1_compx_t	down_arrow;
	}		    dbcs_down_arrow;
	struct
	{
	    cbl_x1_compx_t	right_arrow_dbflag;
	    cbl_x1_compx_t	right_arrow;
	}		    dbcs_right_arrow;
	struct
	{
	    cbl_x1_compx_t	left_arrow_dbflag;
	    cbl_x1_compx_t	left_arrow;
	}		    dbcs_left_arrow;
	struct
	{
	    cbl_x1_compx_t	maximize_dbflag;
	    cbl_x1_compx_t	maximize_char;
	}		    dbcs_maximize;
	struct
	{
	    cbl_x1_compx_t	minimize_dbflag;
	    cbl_x1_compx_t	minimize_char;
	}		    dbcs_minimize;
	struct
	{
	    cbl_x1_compx_t	check_dbflag;
	    cbl_x1_compx_t	check_char;
	}		    dbcs_check;
	struct
	{
	    cbl_x1_compx_t	restore_dbflag;
	    cbl_x1_compx_t	restore_char;
	}		    dbcs_restore;
	struct
	{
	    cbl_x1_compx_t	radio_dbflag;
	    cbl_x1_compx_t	radio_char;
	}		    dbcs_radio;
	struct
	{
	    cbl_x1_compx_t	scroll_dbflag;
	    cbl_x1_compx_t	scroll_char;
	}		    dbcs_scroll;
	struct
	{
	    cbl_x1_compx_t	rubber_band_dbflag;
	    cbl_x1_compx_t	rubber_band;
	}		    dbcs_rubber_band;
	struct
	{
	    cbl_x1_compx_t	sysmenu_dbflag;
	    cbl_x1_compx_t	sysmenu_char;
	}		    dbcs_sysmenu;
	struct
	{
	    cbl_x1_compx_t	editor_char_dbflag;
	    cbl_x1_compx_t	editor_char_char;
	}		    dbcs_editor_char;
	struct
	{
	    cbl_x1_compx_t	hyhelp_tab_dbflag;
	    cbl_x1_compx_t	hyhelp_tab;
	}		    dbcs_hyhelp_tab;
	struct
	{
	    cbl_x1_compx_t	hyhelb_btab_dbflag;
	    cbl_x1_compx_t	hyhelb_btab;
	}		    dbcs_hyhelb_btab;
    }			gsgb_buf;
} cbl_get_scr_graphics_buffer_t;

typedef struct
{
    cbl_x1_compx_t	gsld_draw_code;
    union
    {
	cbl_x1_compx_t	gsld_sbcs_draw_charx[1]; /* Actually, more than 1 ... */
	cbl_x2_compx_t	gsld_dbcs_draw_charx[1]; /*     "      "    "    "    */
    }	gsld_draw_chars;
} cbl_get_scr_line_draw_buffer_t;

#define gsld_draw_char		gsld_draw_chars.gsld_sbcs_draw_charx
#define gsld_dbcs_draw_char	gsld_draw_chars.gsld_dbcs_draw_charx

/*
 * Structures used by CBL_SCR_ Generic Attribute calls.
 */
typedef struct
{
    cbl_x2_compx_t	garv_red_value;
    cbl_x2_compx_t	garv_green_value;
    cbl_x2_compx_t	garv_blue_value;
    cbl_x1_compx_t	garv_filler[2];
} cbl_generic_attr_rgb_values_t;

typedef struct
{
    cbl_x4_compx_t	gav_foreground_color_attribute;
    cbl_x4_compx_t	gav_background_color_attribute;
    cbl_x1_compx_t	gav_character_attribute;
    cbl_x1_compx_t	gav_filler[3];
} cbl_generic_attr_value_t;

typedef struct
{
    cbl_x1_compx_t	gai_display_class;
    cbl_x2_compx_t	gai_colormap_size;
    cbl_x1_compx_t	gai_colormap_flags;
    cbl_x1_compx_t	gai_bits_per_gun;
} cbl_generic_attr_information_t;

/*
 * Definitions used by PC_WIN_ calls.
 */
typedef cbl_os_size_t	pcw_HWND_t;
typedef cbl_os_size_t	pcw_HINSTANCE_t;

/*
 * Structures used by PC_PRINTER_ calls.
 */
typedef struct 
{
    cbl_x2_comp5_t	pn_name_length;
    cbl_x1_t		pn_name_text[1];	/* First of n */
} pc_printer_name_t;

typedef struct
{
    cbl_x2_comp5_t	pp_length;
    cbl_sx2_comp5_t	pp_papersize;
    cbl_sx2_comp5_t	pp_paperlength;
    cbl_sx2_comp5_t	pp_paperwidth;
    cbl_sx2_comp5_t	pp_scale;
    cbl_sx2_comp5_t	pp_copies;
    cbl_sx2_comp5_t	pp_papertray;
    cbl_sx2_comp5_t	pp_printquality;
    cbl_sx2_comp5_t	pp_color;
    cbl_sx2_comp5_t	pp_duplex;
    cbl_sx2_comp5_t	pp_orientation;
    cbl_sx2_comp5_t	pp_yresolution;
} pc_printer_properties_t;

typedef struct
{
    cbl_os_size_t	pi_struct_size;
    cbl_pointer_t	pi_printer_hdc;
    cbl_os_size_t	pi_printer_hps;
    cbl_x4_comp5_t	pi_printer_orientation;
    cbl_x4_comp5_t	pi_printer_rows;
    cbl_x4_comp5_t	pi_printer_cols;
    cbl_x4_comp5_t	pi_printer_rowsleft;
    cbl_x4_comp5_t	pi_printer_max_horiz;
    cbl_x4_comp5_t	pi_printer_max_vert;
    cbl_x4_comp5_t	pi_printer_min_horiz;
    cbl_x4_comp5_t	pi_printer_min_vert;
    cbl_x4_comp5_t	pi_printer_curr_horiz;
    cbl_x4_comp5_t	pi_printer_curr_vert;

    cbl_x2_comp5_t	pi_printer_copies;
    cbl_x2_comp5_t	pi_printer_quality;

    cbl_x1_comp5_t	pi_printer_color;
    cbl_x1_comp5_t	pi_reserved_item1;

    cbl_x2_comp5_t	pi_printer_device_ver;
    struct
    {
        cbl_os_size_t 	pi_printer_pname_size;
        cbl_pointer_t 	pi_printer_pname;
    } pi_printer_name;
    struct
    {
        cbl_os_size_t 	pi_printer_ptype_size;
        cbl_pointer_t 	pi_printer_ptype;
    } pi_printer_type;
    struct
    {
        cbl_os_size_t 	pi_printer_pdevice_size;
        cbl_pointer_t 	pi_printer_pdevice;
    } pi_printer_device;
    struct
    {
        cbl_os_size_t 	pi_printer_plocation_size;
        cbl_pointer_t 	pi_printer_plocation;
    } pi_printer_location;
    struct
    {
        cbl_os_size_t 	pi_printer_pcomment_size;
        cbl_pointer_t 	pi_printer_pcomment;
    } pi_printer_comment;
    struct
    {
        cbl_os_size_t	pi_printer_ppapersize_size;
        cbl_pointer_t	pi_printer_ppapersize;	
    } pi_printer_papersize;
} pc_printer_info_t;

typedef struct
{
    union 
    {
        struct 
	{
	    cbl_x2_comp5_t	pd_printer_name_length;
	    cbl_x1_t		pd_printer_name[1];
	} pd_printer_name;
	struct
	{
	    cbl_os_size_t	pd_printer_browse_hwnd;
	    cbl_x2_comp5_t	pd_printer_browse_namelen;
	    cbl_x2_comp5_t	pd_reserved;
	    cbl_x1_t		pd_printer_browse_name[1];
	} pd_printer_browse;
    } pd_names;
} pc_printer_default_t;

#ifdef	__cplusplus
}
#endif

#endif /* _CBLTYPES_H */

/** End of source module cbltypes.h **/
