515 lines
17 KiB
C
515 lines
17 KiB
C
/*
|
|
* Copyright (C) 1999 - 2003, Rildo Pragana,
|
|
* Andrew Cameron, David Essex, Jim Noeth.
|
|
* Copyright (C) 1993, 1991 Rildo Pragana.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
* as published by the Free Software Foundation; either version 2.1,
|
|
* or (at your option) any later version.
|
|
*
|
|
* This library 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; see the file COPYING.LIB. If
|
|
* not, write to the Free Software Foundation, Inc., 59 Temple Place,
|
|
* Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
/*
|
|
*
|
|
* Header file for COBOL Compiler Run Time Library
|
|
*
|
|
*/
|
|
|
|
|
|
#ifndef HTCOBLIB_H
|
|
#define HTCOBLIB_H
|
|
|
|
/*
|
|
// walter
|
|
//#define DEBUG_COMPILER 1
|
|
// fim walter
|
|
*/
|
|
|
|
#include "htconfig.h"
|
|
#include "mwindows.h"
|
|
|
|
#ifndef __MINGW32__
|
|
#include <sys/param.h>
|
|
#endif
|
|
|
|
//#include <sys/stat.h>
|
|
#include <ctype.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
//#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
//#include <fcntl.h>
|
|
#include <time.h>
|
|
#include <stdarg.h>
|
|
#include <sys/types.h>
|
|
|
|
|
|
#define tc_min(x,y) ((x)<(y) ? (x) : (y))
|
|
#define tc_abs(x) ((x)<0 ? -(x) : (x))
|
|
|
|
#define HTCOB_LD_PATH "TCOB_LD_LIBRARY_PATH"
|
|
|
|
/* Set library db headers and version 1.85 compatibility API for versions >= 2.xx */
|
|
#ifdef USE_DB
|
|
#include <db.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_1
|
|
#include <db1/db.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_23
|
|
#define DB_LIBRARY_COMPATIBILITY_API
|
|
#include <db_185.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_41
|
|
#define DB_LIBRARY_COMPATIBILITY_API
|
|
#include <db_185.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_2
|
|
#define DB_LIBRARY_COMPATIBILITY_API
|
|
#include <db2/db_185.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_3
|
|
#define DB_LIBRARY_COMPATIBILITY_API
|
|
#include <db3/db_185.h>
|
|
#endif
|
|
|
|
#ifdef USE_DB_4
|
|
#define DB_LIBRARY_COMPATIBILITY_API
|
|
#include <db4/db_185.h>
|
|
#endif
|
|
|
|
#ifdef WANT_READLINE
|
|
#include <readline/readline.h>
|
|
#endif
|
|
|
|
#ifdef WANT_DYNAMIC_LIBS
|
|
#include <dlfcn.h>
|
|
#endif
|
|
|
|
|
|
#define RTL_FILE_VERSION 4
|
|
|
|
#define KEY_RETURN 10
|
|
#define CHR_POSITIVE '+'
|
|
#define CHR_NEGATIVE '-'
|
|
#define CHR_BLANK ' '
|
|
#define CHR_ZERO '0'
|
|
|
|
#define DTYPE_DISPLAY '9'
|
|
#define DTYPE_ALPHA 'A'
|
|
#define DTYPE_BININT 'B'
|
|
#define DTYPE_PACKED 'C'
|
|
#define DTYPE_ACCEPT_DISPLAY 'D'
|
|
#define DTYPE_EDITED 'E'
|
|
#define DTYPE_GROUP 'G'
|
|
#define DTYPE_FLOAT 'U'
|
|
#define DTYPE_ALPHANUMERIC 'X'
|
|
#define DTYPE_ALPHANUMERICL 'x'
|
|
|
|
#define DTYPE_COUNT 7
|
|
#define MAX_DIGITS 18
|
|
#define MAX_INTEGERS 18
|
|
#define MAX_DECIMALS 18
|
|
|
|
#define RLBUF_SIZE 8192
|
|
|
|
#define ORG_INDEXED 1
|
|
#define ORG_SEQUENTIAL 2
|
|
#define ORG_RELATIVE 3
|
|
#define ORG_LINESEQUENTIAL 4
|
|
#ifdef SQL_GATEWAY
|
|
#define ORG_MYSQL 10
|
|
#define ORG_PGSQL 11
|
|
#endif
|
|
|
|
#define ACC_SEQUENTIAL 1
|
|
#define ACC_DYNAMIC 2
|
|
#define ACC_RANDOM 3
|
|
/*
|
|
The following are used by file open IO routine.
|
|
They indicate that the filename is EXTERNAL.
|
|
The stored filename string is then used as an environment
|
|
variable name. It is used to determined the actual filename.
|
|
If no environment variable is defined, then the filename
|
|
defaults to the stored name.
|
|
*/
|
|
#define ACCEV_ENVAR 5
|
|
#define ACCEV_SEQUENTIAL 6
|
|
#define ACCEV_DYNAMIC 7
|
|
#define ACCEV_RANDOM 8
|
|
|
|
#define FMOD_INPUT 1
|
|
#define FMOD_IO 2
|
|
#define FMOD_OUTPUT 3
|
|
#define FMOD_EXTEND 4
|
|
|
|
/* inspect options */
|
|
#define INSPECT_CHARACTERS 1
|
|
#define INSPECT_ALL 2
|
|
#define INSPECT_LEADING 3
|
|
#define INSPECT_FIRST 4
|
|
#define INSPECT_TRAILING 5
|
|
|
|
/* screen attributes */
|
|
#define SCR_BLANK_WHEN_ZERO 0x00000001
|
|
#define SCR_HIGHLIGHT 0x00000002
|
|
#define SCR_LOWLIGHT 0x00000004
|
|
#define SCR_UNDERLINE 0x00000008
|
|
#define SCR_REVERSE_VIDEO 0x00000010
|
|
#define SCR_BLINK 0x00000020
|
|
#define SCR_JUST_LEFT 0x00000040
|
|
#define SCR_JUST_RIGHT 0x00000080
|
|
#define SCR_AUTO 0x00000100
|
|
#define SCR_SECURE 0x00000200
|
|
#define SCR_REQUIRED 0x00000400
|
|
#define SCR_FULL 0x00000800
|
|
#define SCR_SIGN_LEADING 0x00001000
|
|
#define SCR_SIGN_SEPARATE 0x00002000
|
|
/* #define SCR_SIGN_PRESENT 0x00004000 */
|
|
#define SCR_BELL 0x00008000
|
|
#define SCR_BLANK_SCREEN 0x00010000
|
|
#define SCR_BLANK_LINE 0x00020000
|
|
#define SCR_DISPLAY 0x00040000 /* if set display, else accept */
|
|
#define SCR_NOECHO 0x00080000
|
|
#define SCR_UPDATE 0x00100000
|
|
#define SCR_ERASE_EOL 0x00200000
|
|
#define SCR_ERASE_EOS 0x00400000
|
|
#define SCR_NO_ADVANCING 0x00800000
|
|
#define SCR_UPPER 0x01000000
|
|
#define SCR_LOWER 0x02000000
|
|
#define SCR_IS_REFMOD 0x04000000 /* accept into a refmod field */
|
|
|
|
#define RTERR_INVALID_DATA 1
|
|
#define RTERR_INVALID_PIC 2
|
|
#define RTERR_NO_MEM 3
|
|
#define RTERR_DBG_TRACE 4
|
|
|
|
/* CONDITIONAL */
|
|
|
|
#define EQUAL 1
|
|
#define LESS 2
|
|
#define GREATER 4
|
|
#define GEQ 5
|
|
#define LEQ 3
|
|
#define NEQ 6
|
|
|
|
#define NO_OF_FILES 100
|
|
#define TCOB_MAX_PATHLN 255
|
|
|
|
/* walter 12-12-05 */
|
|
//struct who_call {
|
|
// char *name;
|
|
// struct who_call *next;
|
|
//};
|
|
|
|
struct element_order {
|
|
char *module_name;
|
|
// struct who_call *whocall;
|
|
char *who_call;
|
|
struct element_order *next;
|
|
};
|
|
/* fim walter */
|
|
|
|
/* 2 ways to enter a run element,
|
|
* entering a program directly or via a call (increasing the process stack
|
|
* or
|
|
* returning from a called program
|
|
*/
|
|
enum {
|
|
RUN_ELEMENT_ENTER,
|
|
RUN_ELEMENT_RETURN
|
|
};
|
|
|
|
#pragma pack(1)
|
|
struct fld_desc {
|
|
unsigned long int len;
|
|
char type;
|
|
unsigned char decimals;
|
|
char pscale;
|
|
unsigned int all:1;
|
|
unsigned int just_r:1;
|
|
unsigned int separate_sign:1;
|
|
unsigned int leading_sign:1;
|
|
unsigned int blank:1;
|
|
unsigned int reserved:3;
|
|
char *pic;
|
|
};
|
|
|
|
struct file_desc {
|
|
unsigned char vers_id;
|
|
struct fld_desc *fname_desc;
|
|
short signed reclen; /* length of record */
|
|
|
|
/* 1=INDEXED,2=SEQUENTIAL,3=RELATIVE, 4=LINESEQUENTIAL, 10=MYSQL, 11=PGSQL */
|
|
unsigned char organization;
|
|
|
|
/* 1=SEQUENTIAL,2=DYNAMIC,3=RANDOM */
|
|
unsigned char access_mode;
|
|
|
|
int open_mode;
|
|
char file_status[2]; /* internally saved file_status */
|
|
char file_status_ext[2]; /* reserve for a pointer to FS (libcob) */
|
|
DB *dbp; /* pointer for libdb operations */
|
|
char *start_record; /* record for start verb control (Andrew Cameron) */
|
|
unsigned int optional:1;
|
|
unsigned int file_missing:1;
|
|
unsigned int with_advancing:1;
|
|
unsigned int adv_before:1;
|
|
unsigned int init_done:1;
|
|
unsigned int eof_hit:1;
|
|
unsigned int read_done:1;
|
|
unsigned int reserved:1;
|
|
/******* from now on, only present for indexed files *********/
|
|
short unsigned rec_index; /* offset of index field in record */
|
|
struct fld_desc
|
|
*ixd_desc; /* offset (DGROUP) index field descriptor */
|
|
struct altkey_desc *key_in_use;
|
|
};
|
|
|
|
struct altkey_desc {
|
|
short int offset; /* offset of alternate key field in record */
|
|
struct fld_desc
|
|
*descriptor; /* descriptor for this field */
|
|
short int
|
|
duplicates; /* = 1 if duplicates allowed */
|
|
DB *alt_dbp; /* handle for the alternate key file */
|
|
};
|
|
|
|
struct scr_desc {
|
|
int attr;
|
|
int line;
|
|
int column;
|
|
short int foreground;
|
|
short int background;
|
|
void (*process_scr)();
|
|
};
|
|
|
|
/*
|
|
* Structure for keeping info for each run element
|
|
*/
|
|
struct runelement_info {
|
|
char *name; /* the name of the run element */
|
|
char *screen_status; /* pointer to the screen_status
|
|
field for this run element */
|
|
char *screen_cursor; /* pointer to the screen_cursor
|
|
field for this run element */
|
|
int decimal_comma; /* value of the decimal comma symbol
|
|
for this run element */
|
|
int currency_symbol; /* value of the currency symbol
|
|
for this run element */
|
|
void *handler; /* pointer for dynamic loaded routines
|
|
for calling cancel */
|
|
struct file_list *files; /* pointer to file open by run element. */
|
|
};
|
|
|
|
struct runelement_list {
|
|
struct runelement_info *element;
|
|
struct runelement_list *next;
|
|
struct runelement_list *prev;
|
|
};
|
|
|
|
struct file_list {
|
|
struct file_desc *file;
|
|
struct file_list *next;
|
|
};
|
|
#pragma pack()
|
|
|
|
/* cobmove.c */
|
|
void tcob_move(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2);
|
|
void _DUMP_(unsigned char *caData, char *szCount, char *caOut);
|
|
void _FLDDUMP_(struct fld_desc *f, char *c, char *szMsg);
|
|
void float2all(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2);
|
|
void initIntValues();
|
|
/* cobmove_9_.c */
|
|
void tcob_move_9_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_9_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_9_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_9_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_9_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_9_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
/* cobmove_b_.c */
|
|
void tcob_move_b_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_b_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_b_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_b_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_b_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_b_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
/* cobmove_c_.c */
|
|
void tcob_move_c_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_c_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_c_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_c_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_c_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_c_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
/* cobmove_f_.c */
|
|
void tcob_move_f_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_f_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_f_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_f_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_f_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_f_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
/* cobmove_x_.c */
|
|
void tcob_move_x_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_x_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_x_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_x_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_x_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_x_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
/* cobmove_e_.c */
|
|
void tcob_move_edited(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_9(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_b(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_c(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_e(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_f(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
void tcob_move_e_x(struct fld_desc *f1, char *s1,
|
|
struct fld_desc *f2, char *s2);
|
|
|
|
/* mcmath.c */
|
|
char tcob_sign_to_char(int digit );
|
|
int tcob_char_to_sign(char ch );
|
|
char tcob_extract_sign(struct fld_desc *f, char *s);
|
|
void tcob_put_sign(struct fld_desc *f, char *s, char sign);
|
|
int tcob_get_index(struct fld_desc *f, char *s);
|
|
void tcob_fldtod(struct fld_desc *f, char *s, double *fp);
|
|
void tcob_push_double(struct fld_desc *f, char *s, double d);
|
|
int tcob_assign_double(struct fld_desc *f, char *s1, int opts, double d1);
|
|
int tcob_dtofld(struct fld_desc *f, char *s1, int round, double d1);
|
|
void tcob_add_double(double *d2, double d1);
|
|
void tcob_subtract_double(double *d2, double d1);
|
|
void tcob_multiply_double(double *d2, double d1);
|
|
void tcob_divide_double(double *d2, double d1);
|
|
int tcob_add(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2, int round);
|
|
int tcob_subtract(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2, int round);
|
|
int tcob_multiply(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2, struct fld_desc *f3, char *s3, int round);
|
|
int tcob_divide(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2, struct fld_desc *f3, char *s3, int round);
|
|
int tcob_divide1(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2, struct fld_desc *f3, char *s3, struct fld_desc *f4, char *s4, int round);
|
|
int tcob_check_size_overflow(struct fld_desc *f, double d);
|
|
int tcob_check_condition(struct fld_desc *f1, char *s1, ...);
|
|
int tcob_compare(struct fld_desc *f1, char *s1, struct fld_desc *f2, char *s2);
|
|
|
|
/* general.c */
|
|
void tcob_stop_run(void);
|
|
unsigned int tcob_fldLength(struct fld_desc *f);
|
|
|
|
void tcob_add_file_list(struct file_desc *f);
|
|
void tcob_remove_file_list(struct file_desc *f);
|
|
|
|
void tcob_cancel_all();
|
|
struct runelement_info *tcob_get_current_runelement();
|
|
void tcob_unload_runelement(struct runelement_info *i);
|
|
|
|
/* pictures.c */
|
|
char* tcob_picExpand(struct fld_desc *f);
|
|
unsigned int tcob_picCompLength(struct fld_desc *f);
|
|
unsigned int tcob_picEditedCompLength(struct fld_desc *f);
|
|
unsigned int tcob_picEditedCompDecimals(struct fld_desc *f);
|
|
unsigned int tcob_picElemLen(char *p, unsigned int i);
|
|
char tcob_picElemVal(char *p, unsigned int i);
|
|
unsigned int tcob_picReqLen(unsigned int i);
|
|
char* tcob_picCreate(char *p, unsigned int len, ...);
|
|
char* tcob_picAppend(char *p, unsigned int len, ...);
|
|
int tcob_isFloatPic(char *p);
|
|
|
|
/* basicio.c */
|
|
void tcob_newline(int dupon);
|
|
void tcob_display(struct fld_desc *f,char *s, int dupon);
|
|
void tcob_display_erase(int dupon);
|
|
int tcob_accept_chron(struct fld_desc *f, char *buffer,
|
|
int date_fmt, int is_yyyy);
|
|
int tcob_accept_std(char *buffer, struct fld_desc *f, int echo);
|
|
int tcob_accept_cmd_line(struct fld_desc *f, char *buffer);
|
|
int tcob_accept_env_var(struct fld_desc *f, char *buffer, char *evname);
|
|
int tcob_init(int ac, char **av);
|
|
|
|
/* fileio.c */
|
|
int tcob_open(struct file_desc *f, char *record, char *fname, int mode);
|
|
int tcob_close(struct file_desc *f, char *record);
|
|
int tcob_close_real(struct file_desc *f, char *record);
|
|
int tcob_file_init(struct file_desc *f, char *record);
|
|
int tcob_read(struct file_desc *f, char *record, ...);
|
|
int tcob_read_into(struct file_desc *f, char *record, char *buf, ...);
|
|
int tcob_read_next(struct file_desc *f, char *record, ...);
|
|
int tcob_read_prev(struct file_desc *f, char *record, ...);
|
|
int tcob_read_next_into(struct file_desc *f, char *record, char *buf);
|
|
int tcob_read_prev_into(struct file_desc *f, char *record, char *buf);
|
|
int tcob_write(struct file_desc *f, char *record, ...);
|
|
int tcob_save_status(char *status, int rt);
|
|
|
|
/* screenio.c */
|
|
int tcob_accept_screen();
|
|
void tcob_display_screen();
|
|
void tcob_scr_process(int iAttr, int iLine, int line_sign,int iColumn,
|
|
int column_sign, int iFgColor, int iBgColor, int size,
|
|
struct fld_desc *fldScr, char *caScr, void *pInfo, ...);
|
|
void tcob_init_screen(void);
|
|
void tcob_do_scrio_finish();
|
|
|
|
/* dyncall.c */
|
|
/* void *tcob_resolve_subr(struct fld_desc*, char *); */
|
|
void *tcob_resolve_subr(struct fld_desc*, char *, int);
|
|
void tcob_resolve_subr_error(void);
|
|
void tcob_cancel_subr(char *, char *); // walter 12-12-2005 acrescentei um *
|
|
int tcob_call_loadlib(struct fld_desc*, char *);
|
|
void *tcob_resolve(char *);
|
|
|
|
/* Run Time Error Routines */
|
|
void runtime_error(int iErrorNbr, struct fld_desc *pFld, void *pData);
|
|
|
|
/* EOF htcoblib.h */
|
|
#endif /* HTCOBLIB_H */
|