GnuCOBOL  2.0
A free COBOL compiler
common.c File Reference
#include "config.h"
#include "defaults.h"
#include "tarstamp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <errno.h>
#include <math.h>
#include <time.h>
#include "lib/gettext.h"
#include "libcob.h"
#include "coblocal.h"
#include "libcob/cobgetopt.h"
#include "exception.def"
Include dependency graph for common.c:

Go to the source code of this file.

Data Structures

struct  cob_alloc_cache
 
struct  cob_external
 
struct  exit_handlerlist
 
struct  handlerlist
 

Macros

#define COB_LIB_EXPIMP
 
#define CB_IMSG_SIZE   24
 
#define CB_IVAL_SIZE   (80 - CB_IMSG_SIZE - 4)
 
#define CB_STRINGIFY(s)   #s
 
#define CB_XSTRINGIFY(s)   CB_STRINGIFY(s)
 
#define OC_C_VERSION_PRF   ""
 
#define OC_C_VERSION   "unknown"
 
#define COB_ERRBUF_SIZE   1024
 
#define COB_EXCEPTION(code, tag, name, critical)   name,
 
#define COB_EXCEPTION(code, tag, name, critical)   0x##code,
 
#define EXCEPTION_TAB_SIZE   sizeof(cob_exception_tab_code) / sizeof(int)
 
#define COB_SWITCH_MAX   36 /* (must match cobc/tree.h)*/
 
#define NUM_CONFIG   (sizeof(gc_conf)/sizeof(struct config_tbl)-1)
 
#define FUNC_NAME_IN_DEFAULT   NUM_CONFIG + 1
 

Functions

static int set_config_val (char *value, int pos)
 
static char * get_config_val (char *value, int pos, char *orgvalue)
 
void conf_runtime_error_value (char *value, const int conf_pos)
 
void conf_runtime_error (const int finish_error, const char *fmt,...)
 
static void cob_exit_common (void)
 
static void cob_terminate_routines (void)
 
static void cob_set_signal (void)
 
static int cob_get_sign_ascii (unsigned char *p)
 
static void cob_put_sign_ascii (unsigned char *p)
 
static int cob_get_sign_ebcdic (unsigned char *p)
 
static void cob_put_sign_ebcdic (unsigned char *p, const int sign)
 
static int common_cmpc (const unsigned char *s1, const unsigned int c, const size_t size, const unsigned char *col)
 
static int common_cmps (const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
 
static int cob_cmp_all (cob_field *f1, cob_field *f2)
 
static int cob_cmp_alnum (cob_field *f1, cob_field *f2)
 
static int sort_compare (const void *data1, const void *data2)
 
static void cob_memcpy (cob_field *dst, const void *src, const size_t size)
 
static void cob_check_trace_file (void)
 
int cob_check_env_true (char *s)
 
int cob_check_env_false (char *s)
 
static void cob_rescan_env_vals (void)
 
static int one_indexed_day_of_week_from_monday (int zero_indexed_from_sunday)
 
static void set_unknown_offset (struct cob_time *time)
 
int cob_get_exception_code (void)
 
const char * cob_get_exception_name (void)
 
void cob_set_exception (const int id)
 
void cob_accept_exception_status (cob_field *f)
 
void cob_accept_user_name (cob_field *f)
 
void * cob_malloc (const size_t size)
 
void * cob_realloc (void *optr, const size_t osize, const size_t nsize)
 
void cob_free (void *mptr)
 
void * cob_fast_malloc (const size_t size)
 
char * cob_strdup (const char *p)
 
void * cob_cache_malloc (const size_t size)
 
void * cob_cache_realloc (void *ptr, const size_t size)
 
void cob_cache_free (void *ptr)
 
void cob_set_location (const char *sfile, const unsigned int sline, const char *csect, const char *cpara, const char *cstatement)
 
void cob_trace_section (const char *para, const char *source, const int line)
 
void cob_ready_trace (void)
 
void cob_reset_trace (void)
 
unsigned char * cob_get_pointer (const void *srcptr)
 
void * cob_get_prog_pointer (const void *srcptr)
 
void cob_field_to_string (const cob_field *f, void *str, const size_t maxsize)
 
void cob_stop_run (const int status)
 
void cob_runtime_error (const char *fmt,...)
 
void cob_fatal_error (const int fatal_error)
 
cob_globalcob_get_global_ptr (void)
 
void cob_module_enter (cob_module **module, cob_global **mglobal, const int auto_init)
 
void cob_module_leave (cob_module *module)
 
void * cob_save_func (cob_field **savefld, const int params, const int eparams,...)
 
void cob_restore_func (struct cob_func_loc *fl)
 
void cob_check_version (const char *prog, const char *packver, const int patchlev)
 
void cob_parameter_check (const char *funcname, const int numparms)
 
void cob_correct_numeric (cob_field *f)
 
static int cob_check_numdisp (const cob_field *f)
 
int cob_real_get_sign (cob_field *f)
 
void cob_real_put_sign (cob_field *f, const int sign)
 
void cob_reg_sighnd (void(*sighnd)(int))
 
int cob_get_switch (const int n)
 
void cob_set_switch (const int n, const int flag)
 
int cob_cmp (cob_field *f1, cob_field *f2)
 
int cob_is_omitted (const cob_field *f)
 
int cob_is_numeric (const cob_field *f)
 
int cob_is_alpha (const cob_field *f)
 
int cob_is_upper (const cob_field *f)
 
int cob_is_lower (const cob_field *f)
 
void cob_table_sort_init (const size_t nkeys, const unsigned char *collating_sequence)
 
void cob_table_sort_init_key (cob_field *field, const int flag, const unsigned int offset)
 
void cob_table_sort (cob_field *f, const int n)
 
void cob_check_based (const unsigned char *x, const char *name)
 
void cob_check_linkage (const unsigned char *x, const char *name, const int check_type)
 
void cob_check_numeric (const cob_field *f, const char *name)
 
void cob_check_odo (const int i, const int min, const int max, const char *name)
 
void cob_check_subscript (const int i, const int min, const int max, const char *name)
 
void cob_check_ref_mod (const int offset, const int length, const int size, const char *name)
 
void * cob_external_addr (const char *exname, const int exlength)
 
int cob_ctoi (const char digit)
 
struct cob_time cob_get_current_date_and_time (void)
 
void cob_accept_date (cob_field *f)
 
void cob_accept_date_yyyymmdd (cob_field *f)
 
void cob_accept_day (cob_field *f)
 
void cob_accept_day_yyyyddd (cob_field *f)
 
void cob_accept_day_of_week (cob_field *f)
 
void cob_accept_time (cob_field *field)
 
void cob_display_command_line (cob_field *f)
 
void cob_accept_command_line (cob_field *f)
 
void cob_display_arg_number (cob_field *f)
 
void cob_accept_arg_number (cob_field *f)
 
void cob_accept_arg_value (cob_field *f)
 
void cob_display_environment (const cob_field *f)
 
void cob_display_env_value (const cob_field *f)
 
void cob_set_environment (const cob_field *f1, const cob_field *f2)
 
void cob_get_environment (const cob_field *envname, cob_field *envval)
 
void cob_accept_environment (cob_field *f)
 
void cob_chain_setup (void *data, const size_t parm, const size_t size)
 
void cob_allocate (unsigned char **dataptr, cob_field *retptr, cob_field *sizefld, cob_field *initialize)
 
void cob_free_alloc (unsigned char **ptr1, unsigned char *ptr2)
 
char * cob_getenv (const char *name)
 
int cob_putenv (char *name)
 
static const char * cob_gettmpdir (void)
 
void cob_temp_name (char *filename, const char *ext)
 
void cob_incr_temp_iteration (void)
 
int cob_extern_init (void)
 
void * cob_command_line (int flags, int *pargc, char ***pargv, char ***penvp, char **pname)
 
int cob_tidy (void)
 
int cob_sys_exit_proc (const void *dispo, const void *pptr)
 
int cob_sys_error_proc (const void *dispo, const void *pptr)
 
int cob_sys_system (const void *cmdline)
 
int cob_sys_hosted (void *p, const void *var)
 Return some hosted C variables, argc, argv, stdin, stdout, stderr. More...
 
int cob_sys_and (const void *p1, void *p2, const int length)
 
int cob_sys_or (const void *p1, void *p2, const int length)
 
int cob_sys_nor (const void *p1, void *p2, const int length)
 
int cob_sys_xor (const void *p1, void *p2, const int length)
 
int cob_sys_imp (const void *p1, void *p2, const int length)
 
int cob_sys_nimp (const void *p1, void *p2, const int length)
 
int cob_sys_eq (const void *p1, void *p2, const int length)
 
int cob_sys_not (void *p1, const int length)
 
int cob_sys_xf4 (void *p1, const void *p2)
 
int cob_sys_xf5 (const void *p1, void *p2)
 
int cob_sys_x91 (void *p1, const void *p2, void *p3)
 
int cob_sys_toupper (void *p1, const int length)
 
int cob_sys_tolower (void *p1, const int length)
 
int cob_sys_oc_nanosleep (const void *data)
 
int cob_sys_getpid (void)
 
int cob_sys_return_args (void *data)
 
int cob_sys_calledby (void *data)
 
int cob_sys_parameter_size (void *data)
 
int cob_sys_getopt_long_long (void *so, void *lo, void *idx, const int long_only, void *return_char, void *opt_val)
 
int cob_sys_sleep (const void *data)
 
int cob_sys_printable (void *p1,...)
 
int cob_sys_justify (void *p1,...)
 
void cob_set_locale (cob_field *locale, const int category)
 
char * cob_int_to_string (int i, char *number)
 
char * cob_int_to_formatted_bytestring (int i, char *number)
 
char * cob_strcat (char *str1, char *str2)
 
char * cob_strjoin (char **strarray, int size, char *separator)
 
char * cob_save_env_value (char *env_var, char *env_val)
 
static void var_print (const char *msg, const char *val, const char *default_val, const unsigned int format)
 
char * cob_expand_env_string (char *strval)
 
static void set_value (char *data, int len, long val)
 
static long get_value (char *data, int len)
 
static int set_config_val_by_name (char *value, const char *name, const char *func)
 
static int cb_lookup_config (char *keyword)
 
static int cb_config_entry (char *buf, int line)
 
static int cob_load_config_file (const char *config_file, int isoptional)
 
int cob_load_config (void)
 
void print_version (void)
 
void print_info (void)
 
void print_runtime_env ()
 
cob_settingscob_get_settings_ptr ()
 
void cob_init (const int argc, char **argv)
 

Variables

static int cob_initialized = 0
 
static int cob_argc
 
static char ** cob_argv
 
static struct cob_alloc_cachecob_alloc_base
 
static const char * cob_last_sfile
 
static cob_globalcobglobptr = ((void*)0)
 
static cob_settingscobsetptr = ((void*)0)
 
static char * runtime_err_str = ((void*)0)
 
static const cob_field_attr const_alpha_attr
 
static char * cob_local_env = ((void*)0)
 
static int current_arg
 
static unsigned char * commlnptr = ((void*)0)
 
static size_t commlncnt
 
static size_t cob_local_env_size = 0
 
static struct cob_externalbasext = ((void*)0)
 
static size_t sort_nkeys = 0
 
static cob_file_keysort_keys
 
static const unsigned char * sort_collate
 
static const char * cob_current_program_id = ((void*)0)
 
static const char * cob_current_section = ((void*)0)
 
static const char * cob_current_paragraph = ((void*)0)
 
static const char * cob_source_file = ((void*)0)
 
static const char * cob_source_statement = ((void*)0)
 
static FILE * cob_trace_file = ((void*)0)
 
static unsigned int cob_source_line = 0
 
static char * strbuff = ((void*)0)
 
static int cob_process_id = 0
 
static int cob_temp_iteration = 0
 
static unsigned int conf_runtime_error_displayed = 0
 
static unsigned int last_runtime_error_line = 0
 
static const char * last_runtime_error_file = "unknown"
 
static void(* cob_ext_sighdl )(int) = ((void*)0)
 
static const char *const cob_exception_tab_name []
 
static const int cob_exception_tab_code []
 
static int cob_switch [36+1]
 
static struct exit_handlerlistexit_hdlrs
 
static struct handlerlisthdlrs
 
static const char * setting_group []
 
static char not_set [] = "not set"
 
static struct config_enum lwrupr [] = {{"LOWER","1"},{"UPPER","2"},{not_set,"0"},{ ((void*)0) , ((void*)0) }}
 
static struct config_enum beepopts [] = {{"FLASH","1"},{"SPEAKER","2"},{"FALSE","9"},{"BEEP","0"},{ ((void*)0) , ((void*)0) }}
 
static struct config_enum timeopts [] = {{"0","1000"},{"1","100"},{"2","10"},{"3","1"},{ ((void*)0) , ((void*)0) }}
 
static struct config_enum syncopts [] = {{"P","1"},{ ((void*)0) , ((void*)0) }}
 
static struct config_enum varseqopts [] = {{"0","0"},{"1","1"},{"2","2"},{"3","3"},{ ((void*)0) , ((void*)0) }}
 
static char varseq_dflt [8] = "0"
 
static struct config_tbl gc_conf []
 

Macro Definition Documentation

#define CB_IMSG_SIZE   24

Definition at line 74 of file common.c.

Referenced by var_print().

#define CB_IVAL_SIZE   (80 - CB_IMSG_SIZE - 4)

Definition at line 75 of file common.c.

Referenced by var_print().

#define CB_STRINGIFY (   s)    #s

Definition at line 78 of file common.c.

#define CB_XSTRINGIFY (   s)    CB_STRINGIFY(s)

Definition at line 79 of file common.c.

#define COB_ERRBUF_SIZE   1024

Definition at line 120 of file common.c.

Referenced by cob_init().

#define COB_EXCEPTION (   code,
  tag,
  name,
  critical 
)    name,

Definition at line 187 of file common.c.

#define COB_EXCEPTION (   code,
  tag,
  name,
  critical 
)    0x##code,

Definition at line 187 of file common.c.

#define COB_LIB_EXPIMP

Definition at line 67 of file common.c.

#define COB_SWITCH_MAX   36 /* (must match cobc/tree.h)*/

Definition at line 199 of file common.c.

Referenced by cob_get_switch(), cob_init(), and cob_set_switch().

#define EXCEPTION_TAB_SIZE   sizeof(cob_exception_tab_code) / sizeof(int)

Definition at line 196 of file common.c.

Referenced by cob_get_exception_name().

#define FUNC_NAME_IN_DEFAULT   NUM_CONFIG + 1

Definition at line 284 of file common.c.

Referenced by print_runtime_env(), and set_config_val_by_name().

#define OC_C_VERSION   "unknown"

Definition at line 102 of file common.c.

Referenced by print_info().

#define OC_C_VERSION_PRF   ""

Definition at line 101 of file common.c.

Referenced by print_info().

Function Documentation

static int cb_config_entry ( char *  buf,
int  line 
)
static

Definition at line 4772 of file common.c.

References _, cb_lookup_config(), __cob_settings::cob_config_cur, cob_expand_env_string(), cob_free(), cob_malloc(), COB_MINI_BUFF, COB_SMALL_BUFF, cob_source_line, conf_runtime_error(), config_tbl::config_num, config_tbl::data_loc, config_tbl::data_type, ENV_PATH, ENV_STR, GRP_HIDE, line, NULL, NUM_CONFIG, config_tbl::set_by, set_config_val(), STS_CNFSET, STS_ENVCLR, STS_ENVSET, STS_RESET, and value.

Referenced by cob_load_config_file().

4773 {
4774  int i,j,k, old_type;
4775  void *data;
4776  char *env,*str,qt;
4777  char keyword[COB_MINI_BUFF],value[COB_SMALL_BUFF],value2[COB_SMALL_BUFF];
4778 
4780 
4781  for (j=(int)strlen(buf); buf[j-1] == '\r' || buf[j-1] == '\n'; ) /* Remove CR LF */
4782  buf[--j] = 0;
4783 
4784  for (i=0; isspace((unsigned char)buf[i]); i++);
4785 
4786  for (j=0; buf[i] != 0 && buf[i] != ':' && !isspace((unsigned char)buf[i]) && buf[i] != '=' && buf[i] != '#'; )
4787  keyword[j++] = buf[i++];
4788  keyword[j] = 0;
4789 
4790  while (buf[i] != 0 && ( isspace((unsigned char)buf[i]) || buf[i] == ':' || buf[i] == '=')) i++;
4791  if (buf[i] == '"'
4792  || buf[i] == '\'') {
4793  qt = buf[i++];
4794  for (j=0; buf[i] != qt && buf[i] != 0; )
4795  value[j++] = buf[i++];
4796  } else {
4797  for (j=0; !isspace((unsigned char)buf[i]) && buf[i] != '#' && buf[i] != 0; )
4798  value[j++] = buf[i++];
4799  }
4800 
4801  value[j] = 0;
4802 
4803  if (strcasecmp (keyword,"setenv") == 0 ) {
4804  /* collect additional value and push into environment */
4805  strcpy(value2,"");
4806  /*check for := in value 2 and split, if necessary*/
4807  k = 0; while (value[k] != '=' && value[k] != ':' && value[k] != '"' && value[k] != '\'' && value[k] != 0) k++;
4808  if (value[k] == '=' || value[k] == ':') {
4809  i = i - (int)strlen(value + k);
4810  value[k] = 0;
4811  }
4812  while(isspace((unsigned char)buf[i]) || buf[i] == ':' || buf[i] == '=') i++;
4813  if(buf[i] == '"'
4814  || buf[i] == '\'') {
4815  qt = buf[i++];
4816  for (j=0; buf[i] != qt && buf[i] != 0; )
4817  value2[j++] = buf[i++];
4818  } else {
4819  for (j=0; !isspace((unsigned char)buf[i]) && buf[i] != '#' && buf[i] != 0; )
4820  value2[j++] = buf[i++];
4821  }
4822  value2[j] = 0;
4823  if (strcmp(value2, "") == 0) {
4824  conf_runtime_error(1, _("WARNING - '%s %s' without a value - ignored!"), keyword, value);
4825  return 2;
4826  }
4827  /* check additional value for inline env vars ${varname:-default} */
4828  str = cob_expand_env_string(value2);
4829  env = cob_malloc(strlen(value)+strlen(str)+2);
4830  sprintf(env,"%s=%s",value,str);
4831  (void)putenv(env);
4832  cob_free(str);
4833  for (i=0; i < NUM_CONFIG; i++) { /* Set value from config file */
4834  if(gc_conf[i].env_name
4835  && strcasecmp(value,gc_conf[i].env_name) == 0) {/* no longer cleared by runtime.cfg */
4836  gc_conf[i].data_type &= ~STS_ENVCLR;
4837  break;
4838  }
4839  }
4840  return 0;
4841  }
4842 
4843  if (strcasecmp (keyword,"unsetenv") == 0) {
4844  if (strcmp(value, "") == 0) {
4845  conf_runtime_error(1, _("WARNING - '%s' without a value - ignored!"), keyword);
4846  return 2;
4847  }
4848  if ( (env = getenv(value)) != NULL ) {
4849  for (i=0; i < NUM_CONFIG; i++) { /* Set value from config file */
4850  if(gc_conf[i].env_name
4851  && strcasecmp(value,gc_conf[i].env_name) == 0) { /* Catch using env var name */
4853  break;
4854  }
4855  }
4856 #if HAVE_SETENV
4857  (void)unsetenv(value);
4858 #else
4859  env = cob_malloc(strlen(value)+2);
4860  sprintf(env,"%s=",value);
4861  (void)putenv(env);
4862 
4863 #endif
4864  }
4865  return 0;
4866  }
4867 
4868  if (strcasecmp (keyword, "include") == 0 ||
4869  strcasecmp (keyword, "includeif") == 0) {
4870  if (strcmp(value, "") == 0) {
4871  conf_runtime_error(1, _("'%s' without a value!"), keyword);
4872  return -1;
4873  }
4874  str = cob_expand_env_string(value);
4875  strcpy (buf, str);
4876  cob_free(str);
4877  if (strcasecmp (keyword, "include") == 0) {
4878  return 1;
4879  } else {
4880  return 3;
4881  }
4882  }
4883 
4884  if (strcasecmp (keyword, "reset") == 0) {
4885  i = cb_lookup_config(value);
4886  if(i >= NUM_CONFIG) {
4887  conf_runtime_error (1,_("Unknown configuration tag '%s'"), value);
4888  return -1;
4889  }
4890  gc_conf[i].data_type &= ~(STS_ENVSET|STS_CNFSET|STS_ENVCLR); /* Clear status */
4891  gc_conf[i].data_type |= STS_RESET;
4892  gc_conf[i].set_by = 0;
4894  if(gc_conf[i].default_val) {
4895  set_config_val((char*)gc_conf[i].default_val,i);
4896  } else if ((gc_conf[i].data_type & ENV_STR)
4897  || (gc_conf[i].data_type & ENV_PATH)) { /* String/Path stored as a string */
4898  data = (void*)((char *)cobsetptr + gc_conf[i].data_loc);
4899  memcpy(&str,data,sizeof(char *));
4900  if( str != NULL) {
4901  cob_free((void*)str);
4902  }
4903  } else {
4904  set_config_val((char*)"0",i);
4905  }
4906  return 0;
4907  }
4908 
4909  i = cb_lookup_config(keyword);
4910 
4911  if (i >= NUM_CONFIG) {
4912  conf_runtime_error (1,_("Unknown configuration tag '%s'"), keyword);
4913  return -1;
4914  }
4915  if (strcmp(value, "") == 0) {
4916  conf_runtime_error(1, _("WARNING - '%s' without a value - ignored!"), keyword);
4917  return 2;
4918  }
4919 
4920  old_type = gc_conf[i].data_type;
4922  if(!set_config_val(value,i)) {
4923  gc_conf[i].data_type &= ~STS_RESET;
4925 
4926  if(gc_conf[i].env_group == GRP_HIDE) {
4927  for (j=0; j < NUM_CONFIG; j++) { /* Any alias present? */
4928  if(j != i
4929  && gc_conf[i].data_loc == gc_conf[j].data_loc) {
4931  gc_conf[j].data_type &= ~STS_RESET;
4933  gc_conf[j].set_by = i;
4934  }
4935  }
4936  }
4937  } else {
4938  gc_conf[i].data_type = old_type;
4939  }
4940  return 0;
4941 }
#define ENV_PATH
Definition: coblocal.h:296
void cob_free(void *mptr)
Definition: common.c:1284
static int cb_lookup_config(char *keyword)
Definition: common.c:4755
int set_by
Definition: coblocal.h:285
#define COB_SMALL_BUFF
Definition: common.h:540
#define COB_MINI_BUFF
Definition: common.h:539
void conf_runtime_error(const int finish_error, const char *fmt,...)
Definition: common.c:1744
static unsigned int cob_source_line
Definition: common.c:156
static cob_settings * cobsetptr
Definition: common.c:131
int data_type
Definition: coblocal.h:281
int config_num
Definition: coblocal.h:284
static struct config_tbl gc_conf[]
Definition: common.c:235
strict implicit external value
Definition: warning.def:54
#define _(s)
Definition: cobcrun.c:59
#define STS_RESET
Definition: coblocal.h:303
#define GRP_HIDE
Definition: coblocal.h:306
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int data_loc
Definition: coblocal.h:282
#define STS_ENVCLR
Definition: coblocal.h:302
static int set_config_val(char *value, int pos)
Definition: common.c:4503
#define STS_ENVSET
Definition: coblocal.h:300
#define STS_CNFSET
Definition: coblocal.h:301
char * cob_expand_env_string(char *strval)
Definition: common.c:4406
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define NUM_CONFIG
Definition: common.c:283
#define ENV_STR
Definition: coblocal.h:295
unsigned int cob_config_cur
Definition: coblocal.h:207

Here is the call graph for this function:

Here is the caller graph for this function:

static int cb_lookup_config ( char *  keyword)
static

Definition at line 4755 of file common.c.

References NUM_CONFIG.

Referenced by cb_config_entry().

4756 {
4757  int i;
4758  for (i=0; i < NUM_CONFIG; i++) { /* Set value from config file */
4759  if(gc_conf[i].conf_name
4760  && strcasecmp(keyword,gc_conf[i].conf_name) == 0) { /* Look for config file name */
4761  break;
4762  }
4763  if(gc_conf[i].env_name
4764  && strcasecmp(keyword,gc_conf[i].env_name) == 0) { /* Catch using env var name */
4765  break;
4766  }
4767  }
4768  return i;
4769 }
static struct config_tbl gc_conf[]
Definition: common.c:235
#define NUM_CONFIG
Definition: common.c:283

Here is the caller graph for this function:

void cob_accept_arg_number ( cob_field f)

Definition at line 2930 of file common.c.

References cob_field::attr, cob_argc, COB_ATTR_INIT, cob_move(), COB_TYPE_NUMERIC_BINARY, cob_field::data, NULL, and cob_field::size.

Referenced by cobxref_().

2931 {
2932  int n;
2933  cob_field_attr attr;
2934  cob_field temp;
2935 
2936  n = cob_argc - 1;
2937  temp.size = 4;
2938  temp.data = (unsigned char *)&n;
2939  temp.attr = &attr;
2941  cob_move (&temp, f);
2942 }
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
static int cob_argc
Definition: common.c:125
#define COB_ATTR_INIT(u, v, x, y, z)
Definition: coblocal.h:150
unsigned char * data
Definition: common.h:952
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_arg_value ( cob_field f)

Definition at line 2945 of file common.c.

References cob_argc, cob_argv, COB_EC_IMP_ACCEPT, cob_memcpy(), cob_set_exception(), and current_arg.

Referenced by cobxref_().

2946 {
2947  if (current_arg >= cob_argc) {
2949  return;
2950  }
2952  strlen (cob_argv[current_arg]));
2953  current_arg++;
2954 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
static int current_arg
Definition: common.c:139
void cob_set_exception(const int id)
Definition: common.c:1212

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_command_line ( cob_field f)

Definition at line 2866 of file common.c.

References cob_argc, cob_argv, cob_free(), cob_malloc(), cob_memcpy(), commlncnt, commlnptr, and cob_field::size.

Referenced by GCic_().

2867 {
2868  char *buff;
2869  size_t i;
2870  size_t size;
2871  size_t len;
2872 
2873  if (commlncnt) {
2875  return;
2876  }
2877 
2878  if (cob_argc <= 1) {
2879  cob_memcpy (f, " ", (size_t)1);
2880  return;
2881  }
2882 
2883  size = 0;
2884  for (i = 1; i < (size_t)cob_argc; ++i) {
2885  size += (strlen (cob_argv[i]) + 1);
2886  if (size > f->size) {
2887  break;
2888  }
2889  }
2890  buff = cob_malloc (size);
2891  buff[0] = ' ';
2892  size = 0;
2893  for (i = 1; i < (size_t)cob_argc; ++i) {
2894  len = strlen (cob_argv[i]);
2895  memcpy (buff + size, cob_argv[i], len);
2896  size += len;
2897  if (i != (size_t)cob_argc - 1U) {
2898  buff[size++] = ' ';
2899  }
2900  if (size > f->size) {
2901  break;
2902  }
2903  }
2904  cob_memcpy (f, buff, size);
2905  cob_free (buff);
2906 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
void cob_free(void *mptr)
Definition: common.c:1284
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
static unsigned char * commlnptr
Definition: common.c:140
static size_t commlncnt
Definition: common.c:141
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_date ( cob_field f)

Definition at line 2781 of file common.c.

References cob_memcpy(), and NULL.

Referenced by cobxref_().

2782 {
2783  time_t t;
2784  char s[8];
2785 
2786  t = time (NULL);
2787  strftime (s, (size_t)7, "%y%m%d", localtime (&t));
2788  cob_memcpy (f, s, (size_t)6);
2789 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_date_yyyymmdd ( cob_field f)

Definition at line 2792 of file common.c.

References cob_memcpy(), and NULL.

Referenced by LISTING_().

2793 {
2794  time_t t;
2795  char s[12];
2796 
2797  t = time (NULL);
2798  strftime (s, (size_t)9, "%Y%m%d", localtime (&t));
2799  cob_memcpy (f, s, (size_t)8);
2800 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_day ( cob_field f)

Definition at line 2803 of file common.c.

References cob_memcpy(), and NULL.

2804 {
2805  time_t t;
2806  char s[8];
2807 
2808  t = time (NULL);
2809  strftime (s, (size_t)6, "%y%j", localtime (&t));
2810  cob_memcpy (f, s, (size_t)5);
2811 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

void cob_accept_day_of_week ( cob_field f)

Definition at line 2825 of file common.c.

References cob_memcpy(), and NULL.

2826 {
2827  struct tm *tm;
2828  time_t t;
2829  unsigned char s[4];
2830 
2831  t = time (NULL);
2832  tm = localtime (&t);
2833  if (tm->tm_wday == 0) {
2834  s[0] = (unsigned char)'7';
2835  } else {
2836  s[0] = (unsigned char)(tm->tm_wday + '0');
2837  }
2838  cob_memcpy (f, s, (size_t)1);
2839 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

void cob_accept_day_yyyyddd ( cob_field f)

Definition at line 2814 of file common.c.

References cob_memcpy(), and NULL.

2815 {
2816  time_t t;
2817  char s[12];
2818 
2819  t = time (NULL);
2820  strftime (s, (size_t)8, "%Y%j", localtime (&t));
2821  cob_memcpy (f, s, (size_t)7);
2822 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

void cob_accept_environment ( cob_field f)

Definition at line 3055 of file common.c.

References COB_EC_IMP_ACCEPT, cob_local_env, cob_memcpy(), cob_set_exception(), and NULL.

3056 {
3057  const char *p = NULL;
3058 
3059  if (cob_local_env) {
3060  p = getenv (cob_local_env);
3061  }
3062  if (!p) {
3064  p = " ";
3065  }
3066  cob_memcpy (f, p, strlen (p));
3067 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
static char * cob_local_env
Definition: common.c:138

Here is the call graph for this function:

void cob_accept_exception_status ( cob_field f)

Definition at line 1233 of file common.c.

References __cob_global::cob_exception_code, and cob_set_int().

1234 {
1236 }
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130

Here is the call graph for this function:

void cob_accept_time ( cob_field field)

Definition at line 2842 of file common.c.

References cob_get_current_date_and_time(), cob_memcpy(), cob_time::hour, cob_time::minute, cob_time::nanosecond, and cob_time::second.

Referenced by cobxref_().

2843 {
2844  struct cob_time time;
2845  char str[9] = { '\0' };
2846 
2848  snprintf (str, 9, "%2.2d%2.2d%2.2d%2.2d", time.hour, time.minute,
2849  time.second, time.nanosecond / 10000000);
2850 
2851  cob_memcpy (field, str, (size_t)8);
2852 }
struct cob_time cob_get_current_date_and_time(void)
Definition: common.c:2699
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_accept_user_name ( cob_field f)

Definition at line 1239 of file common.c.

References cob_memcpy(), and __cob_settings::cob_user_name.

1240 {
1241  if (cobsetptr->cob_user_name) {
1243  strlen (cobsetptr->cob_user_name));
1244  } else {
1245  cob_memcpy (f, " ", (size_t)1);
1246  }
1247 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
char * cob_user_name
Definition: coblocal.h:211
static cob_settings * cobsetptr
Definition: common.c:131

Here is the call graph for this function:

void cob_allocate ( unsigned char **  dataptr,
cob_field retptr,
cob_field sizefld,
cob_field initialize 
)

Definition at line 3089 of file common.c.

References cob_field::attr, cob_alloc_base, COB_EC_STORAGE_NOT_AVAIL, __cob_global::cob_exception_code, cob_free(), cob_get_int(), cob_malloc(), cob_move(), cob_alloc_cache::cob_pointer, cob_set_exception(), const_alpha_attr, cob_field::data, cob_alloc_cache::next, NULL, cob_alloc_cache::size, and cob_field::size.

3091 {
3092  void *mptr;
3093  struct cob_alloc_cache *cache_ptr;
3094  int fsize;
3095  cob_field temp;
3096 
3097  /* ALLOCATE */
3099  mptr = NULL;
3100  fsize = cob_get_int (sizefld);
3101  if (fsize > 0) {
3102  cache_ptr = cob_malloc (sizeof (struct cob_alloc_cache));
3103  mptr = malloc ((size_t)fsize);
3104  if (!mptr) {
3106  cob_free (cache_ptr);
3107  } else {
3108  if (initialize) {
3109  temp.size = (size_t)fsize;
3110  temp.data = mptr;
3111  temp.attr = &const_alpha_attr;
3112  cob_move (initialize, &temp);
3113  } else {
3114  memset (mptr, 0, (size_t)fsize);
3115  }
3116  cache_ptr->cob_pointer = mptr;
3117  cache_ptr->size = (size_t)fsize;
3118  cache_ptr->next = cob_alloc_base;
3119  cob_alloc_base = cache_ptr;
3120  }
3121  }
3122  if (dataptr) {
3123  *dataptr = mptr;
3124  }
3125  if (retptr) {
3126  *(void **)(retptr->data) = mptr;
3127  }
3128 }
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
size_t size
Definition: common.c:108
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
void * cob_pointer
Definition: common.c:107
unsigned char * data
Definition: common.h:952
int cob_get_int(cob_field *)
Definition: move.c:1626
struct cob_alloc_cache * next
Definition: common.c:106
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
void * cob_malloc(const size_t size)
Definition: common.c:1250
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130
static const cob_field_attr const_alpha_attr
Definition: common.c:135

Here is the call graph for this function:

void cob_cache_free ( void *  ptr)

Definition at line 1362 of file common.c.

References cob_alloc_base, cob_free(), cob_alloc_cache::cob_pointer, and cob_alloc_cache::next.

Referenced by CHECKSRC_(), get__reserved__lists_(), and LISTING_().

1363 {
1364  struct cob_alloc_cache *cache_ptr;
1365  struct cob_alloc_cache *prev_ptr;
1366 
1367  if (!ptr) {
1368  return;
1369  }
1370  cache_ptr = cob_alloc_base;
1371  prev_ptr = cob_alloc_base;
1372  for (; cache_ptr; cache_ptr = cache_ptr->next) {
1373  if (ptr == cache_ptr->cob_pointer) {
1374  cob_free (cache_ptr->cob_pointer);
1375  if (cache_ptr == cob_alloc_base) {
1376  cob_alloc_base = cache_ptr->next;
1377  } else {
1378  prev_ptr->next = cache_ptr->next;
1379  }
1380  cob_free (cache_ptr);
1381  return;
1382  }
1383  prev_ptr = cache_ptr;
1384  }
1385 }
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
void * cob_pointer
Definition: common.c:107
struct cob_alloc_cache * next
Definition: common.c:106

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_cache_malloc ( const size_t  size)

Definition at line 1321 of file common.c.

References cob_alloc_base, cob_malloc(), cob_alloc_cache::cob_pointer, cob_alloc_cache::next, and cob_alloc_cache::size.

Referenced by cob_cache_realloc(), cob_module_enter(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

1322 {
1323  struct cob_alloc_cache *cache_ptr;
1324  void *mptr;
1325 
1326  cache_ptr = cob_malloc (sizeof (struct cob_alloc_cache));
1327  mptr = cob_malloc (size);
1328  cache_ptr->cob_pointer = mptr;
1329  cache_ptr->size = size;
1330  cache_ptr->next = cob_alloc_base;
1331  cob_alloc_base = cache_ptr;
1332  return mptr;
1333 }
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
size_t size
Definition: common.c:108
void * cob_pointer
Definition: common.c:107
struct cob_alloc_cache * next
Definition: common.c:106
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_cache_realloc ( void *  ptr,
const size_t  size 
)

Definition at line 1336 of file common.c.

References cob_alloc_base, cob_cache_malloc(), cob_free(), cob_malloc(), cob_alloc_cache::cob_pointer, cob_alloc_cache::next, and cob_alloc_cache::size.

1337 {
1338  struct cob_alloc_cache *cache_ptr;
1339  void *mptr;
1340 
1341  if (!ptr) {
1342  return cob_cache_malloc (size);
1343  }
1344  cache_ptr = cob_alloc_base;
1345  for (; cache_ptr; cache_ptr = cache_ptr->next) {
1346  if (ptr == cache_ptr->cob_pointer) {
1347  if (size <= cache_ptr->size) {
1348  return ptr;
1349  }
1350  mptr = cob_malloc (size);
1351  memcpy (mptr, cache_ptr->cob_pointer, cache_ptr->size);
1352  cob_free (cache_ptr->cob_pointer);
1353  cache_ptr->cob_pointer = mptr;
1354  cache_ptr->size = size;
1355  return mptr;
1356  }
1357  }
1358  return ptr;
1359 }
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
size_t size
Definition: common.c:108
void * cob_pointer
Definition: common.c:107
struct cob_alloc_cache * next
Definition: common.c:106
void * cob_malloc(const size_t size)
Definition: common.c:1250
void * cob_cache_malloc(const size_t size)
Definition: common.c:1321

Here is the call graph for this function:

void cob_chain_setup ( void *  data,
const size_t  parm,
const size_t  size 
)

Definition at line 3070 of file common.c.

References cob_argc, cob_argv, and __cob_global::cob_call_params.

3071 {
3072  size_t len;
3073 
3074  memset (data, ' ', size);
3075  if (parm <= (size_t)cob_argc - 1) {
3076  len = strlen (cob_argv[parm]);
3077  if (len <= size) {
3078  memcpy (data, cob_argv[parm], len);
3079  } else {
3080  memcpy (data, cob_argv[parm], size);
3081  }
3082  } else {
3083  memset (data, ' ', size);
3084  }
3086 }
size_t size
Definition: common.c:108
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
int cob_call_params
Definition: common.h:1204
static cob_global * cobglobptr
Definition: common.c:130
void cob_check_based ( const unsigned char *  x,
const char *  name 
)

Definition at line 2525 of file common.c.

References _, cob_runtime_error(), and cob_stop_run().

2526 {
2527  if (!x) {
2528  /* name includes '' already and can be ... 'x' (addressed by 'y'= */
2529  cob_runtime_error (_("BASED/LINKAGE item %s has NULL address"), name);
2530  cob_stop_run (1);
2531  }
2532 }
#define _(s)
Definition: cobcrun.c:59
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

int cob_check_env_false ( char *  s)

Definition at line 1086 of file common.c.

1087 {
1088  if (s) {
1089  if (strlen(s) == 1 && (*s == 'N' || *s == 'n' || *s == '0')) return 1;
1090  if (strcasecmp(s, "NO") == 0 || strcasecmp(s, "NONE") == 0 ||
1091  strcasecmp(s, "OFF") == 0 || strcasecmp(s, "FALSE") == 0) {
1092  return 1;
1093  }
1094  }
1095  return 0;
1096 }
int cob_check_env_true ( char *  s)

Definition at line 1073 of file common.c.

1074 {
1075  if (s) {
1076  if (strlen(s) == 1 && (*s == 'Y' || *s == 'y' || *s == '1')) return 1;
1077  if (strcasecmp(s, "YES") == 0 || strcasecmp(s, "ON") == 0 ||
1078  strcasecmp(s, "TRUE") == 0) {
1079  return 1;
1080  }
1081  }
1082  return 0;
1083 }
void cob_check_linkage ( const unsigned char *  x,
const char *  name,
const int  check_type 
)

Definition at line 2535 of file common.c.

References _, cob_runtime_error(), and cob_stop_run().

2536 {
2537  if (!x) {
2538  /* name includes '' already and can be ... 'x' of 'y' */
2539  switch(check_type) {
2540  case 0: /* check for passed items and size on module entry */
2541  cob_runtime_error (_("LINKAGE item %s not passed by caller"), name);
2542  break;
2543  case 1: /* check for passed OPTIONAL items on item use */
2544  cob_runtime_error (_("LINKAGE item %s not passed by caller"), name);
2545  break;
2546  }
2547  cob_stop_run (1);
2548  }
2549 }
#define _(s)
Definition: cobcrun.c:59
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

static int cob_check_numdisp ( const cob_field f)
static

Definition at line 2108 of file common.c.

References COB_FIELD_HAVE_SIGN, COB_FIELD_SIGN_LEADING, COB_FIELD_SIGN_SEPARATE, COB_MODULE_PTR, cob_field::data, cob_func_loc::data, cob_field::size, and unlikely.

Referenced by cob_is_numeric().

2109 {
2110  unsigned char *p;
2111  unsigned char *data;
2112  size_t size;
2113  size_t i;
2114 
2115  size = f->size;
2116  data = f->data;
2117  if (COB_FIELD_HAVE_SIGN (f)) {
2118  /* Adjust for sign byte */
2119  size--;
2120  if (unlikely(COB_FIELD_SIGN_LEADING (f))) {
2121  p = f->data;
2122  data = p + 1;
2123  } else {
2124  p = f->data + f->size - 1;
2125  }
2126  if (unlikely(COB_FIELD_SIGN_SEPARATE (f))) {
2127  if (*p != '+' && *p != '-') {
2128  return 0;
2129  }
2130  } else if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
2131  switch (*p) {
2132  case '0':
2133  case '1':
2134  case '2':
2135  case '3':
2136  case '4':
2137  case '5':
2138  case '6':
2139  case '7':
2140  case '8':
2141  case '9':
2142  case '{':
2143  case 'A':
2144  case 'B':
2145  case 'C':
2146  case 'D':
2147  case 'E':
2148  case 'F':
2149  case 'G':
2150  case 'H':
2151  case 'I':
2152  case '}':
2153  case 'J':
2154  case 'K':
2155  case 'L':
2156  case 'M':
2157  case 'N':
2158  case 'O':
2159  case 'P':
2160  case 'Q':
2161  case 'R':
2162  break;
2163  default:
2164  return 0;
2165  }
2166  } else {
2167  switch (*p) {
2168  case '0':
2169  case '1':
2170  case '2':
2171  case '3':
2172  case '4':
2173  case '5':
2174  case '6':
2175  case '7':
2176  case '8':
2177  case '9':
2178  case 'p':
2179  case 'q':
2180  case 'r':
2181  case 's':
2182  case 't':
2183  case 'u':
2184  case 'v':
2185  case 'w':
2186  case 'x':
2187  case 'y':
2188  break;
2189  default:
2190  return 0;
2191  }
2192  }
2193  }
2194  for (i = 0; i < size; ++i) {
2195  if (!isdigit (data[i])) {
2196  return 0;
2197  }
2198  }
2199  return 1;
2200 }
size_t size
Definition: common.c:108
unsigned char * data
Definition: common.h:952
#define COB_FIELD_SIGN_SEPARATE(f)
Definition: common.h:644
#define unlikely(x)
Definition: common.h:437
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951
#define COB_FIELD_HAVE_SIGN(f)
Definition: common.h:643
#define COB_FIELD_SIGN_LEADING(f)
Definition: common.h:645

Here is the caller graph for this function:

void cob_check_numeric ( const cob_field f,
const char *  name 
)

Definition at line 2552 of file common.c.

References _, cob_fast_malloc(), cob_free(), cob_is_numeric(), cob_runtime_error(), COB_SMALL_BUFF, cob_stop_run(), cob_field::data, and cob_field::size.

2553 {
2554  unsigned char *data;
2555  char *p;
2556  char *buff;
2557  size_t i;
2558 
2559  if (!cob_is_numeric (f)) {
2560  buff = cob_fast_malloc ((size_t)COB_SMALL_BUFF);
2561  p = buff;
2562  data = f->data;
2563  for (i = 0; i < f->size; ++i) {
2564  if (isprint (data[i])) {
2565  *p++ = data[i];
2566  } else {
2567  p += sprintf (p, "\\%03o", data[i]);
2568  }
2569  }
2570  *p = '\0';
2571  cob_runtime_error (_("'%s' not numeric: '%s'"), name, buff);
2572  cob_free (buff);
2573  cob_stop_run (1);
2574  }
2575 }
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_SMALL_BUFF
Definition: common.h:540
unsigned char * data
Definition: common.h:952
#define _(s)
Definition: cobcrun.c:59
size_t size
Definition: common.h:951
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524
int cob_is_numeric(const cob_field *f)
Definition: common.c:2375

Here is the call graph for this function:

void cob_check_odo ( const int  i,
const int  min,
const int  max,
const char *  name 
)

Definition at line 2578 of file common.c.

References _, COB_EC_BOUND_ODO, cob_runtime_error(), cob_set_exception(), and cob_stop_run().

2580 {
2581  /* Check OCCURS DEPENDING ON item */
2582  if (i < min || max < i) {
2584  cob_runtime_error (_("OCCURS DEPENDING ON '%s' out of bounds: %d"), name, i);
2585  cob_stop_run (1);
2586  }
2587 }
#define _(s)
Definition: cobcrun.c:59
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

void cob_check_ref_mod ( const int  offset,
const int  length,
const int  size,
const char *  name 
)

Definition at line 2602 of file common.c.

References _, COB_EC_BOUND_REF_MOD, cob_runtime_error(), cob_set_exception(), and cob_stop_run().

2604 {
2605  /* Check offset */
2606  if (offset < 1 || offset > size) {
2608  cob_runtime_error (_("Offset of '%s' out of bounds: %d"), name, offset);
2609  cob_stop_run (1);
2610  }
2611 
2612  /* Check length */
2613  if (length < 1 || offset + length - 1 > size) {
2615  cob_runtime_error (_("Length of '%s' out of bounds: %d"), name, length);
2616  cob_stop_run (1);
2617  }
2618 }
size_t size
Definition: common.c:108
#define _(s)
Definition: cobcrun.c:59
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

void cob_check_subscript ( const int  i,
const int  min,
const int  max,
const char *  name 
)

Definition at line 2590 of file common.c.

References _, COB_EC_BOUND_SUBSCRIPT, cob_runtime_error(), cob_set_exception(), and cob_stop_run().

2592 {
2593  /* Check subscript */
2594  if (i < min || max < i) {
2596  cob_runtime_error (_("Subscript of '%s' out of bounds: %d"), name, i);
2597  cob_stop_run (1);
2598  }
2599 }
#define _(s)
Definition: cobcrun.c:59
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

static void cob_check_trace_file ( void  )
static

Definition at line 1056 of file common.c.

References cob_trace_file, __cob_settings::cob_trace_filename, and __cob_settings::cob_unix_lf.

Referenced by cob_set_location(), and cob_trace_section().

1057 {
1058  if (!cobsetptr->cob_trace_filename) {
1059  cob_trace_file = stderr;
1060  return;
1061  }
1062  if (!cobsetptr->cob_unix_lf) {
1064  } else {
1065  cob_trace_file = fopen (cobsetptr->cob_trace_filename, "wb");
1066  }
1067  if (!cob_trace_file) {
1068  cob_trace_file = stderr;
1069  }
1070 }
static FILE * cob_trace_file
Definition: common.c:155
unsigned int cob_unix_lf
Definition: coblocal.h:228
static cob_settings * cobsetptr
Definition: common.c:131
char * cob_trace_filename
Definition: coblocal.h:210

Here is the caller graph for this function:

void cob_check_version ( const char *  prog,
const char *  packver,
const int  patchlev 
)

Definition at line 1894 of file common.c.

References _, cob_runtime_error(), cob_stop_run(), PACKAGE_VERSION, and PATCH_LEVEL.

Referenced by CHECKSRC_(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

1895 {
1896  if (strcmp (packver, PACKAGE_VERSION) || patchlev != PATCH_LEVEL) {
1897  cob_runtime_error (_("Error - Version mismatch"));
1898  cob_runtime_error (_("%s has version/patch level %s/%d"), prog,
1899  packver, patchlev);
1900  cob_runtime_error (_("Library has version/patch level %s/%d"),
1902  cob_stop_run (1);
1903  }
1904 }
#define _(s)
Definition: cobcrun.c:59
#define PACKAGE_VERSION
Definition: config.h:312
#define PATCH_LEVEL
Definition: config.h:315
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_cmp ( cob_field f1,
cob_field f2 
)

Definition at line 2318 of file common.c.

References cob_field::attr, cob_cmp_all(), cob_cmp_alnum(), cob_cmp_int(), COB_FIELD_DIGITS, COB_FIELD_IS_NUMERIC, COB_FIELD_TYPE, COB_FLAG_HAVE_SIGN, cob_move(), cob_numeric_cmp(), COB_TYPE_ALPHANUMERIC_ALL, COB_TYPE_NUMERIC_DISPLAY, cob_field::data, cob_field_attr::flags, cob_field::size, and cob_field_attr::type.

Referenced by cob_intr_max(), cob_intr_min(), cob_intr_ord_max(), cob_intr_ord_min(), cobxref_(), comp_field(), GCic_(), get__reserved__lists_(), get_min_and_max_of_args(), and LISTING_().

2319 {
2320  cob_field temp;
2321  cob_field_attr attr;
2322  unsigned char buff[256];
2323 
2324  if (COB_FIELD_IS_NUMERIC (f1) && COB_FIELD_IS_NUMERIC (f2)) {
2325  return cob_numeric_cmp (f1, f2);
2326  }
2328  if (f2->size == 1 && f2->data[0] == '0' &&
2329  COB_FIELD_IS_NUMERIC (f1)) {
2330  return cob_cmp_int (f1, 0);
2331  }
2332  return cob_cmp_all (f1, f2);
2333  }
2335  if (f1->size == 1 && f1->data[0] == '0' &&
2336  COB_FIELD_IS_NUMERIC (f2)) {
2337  return -cob_cmp_int (f2, 0);
2338  }
2339  return -cob_cmp_all (f2, f1);
2340  }
2341  if (COB_FIELD_IS_NUMERIC (f1) &&
2343  temp.size = COB_FIELD_DIGITS(f1);
2344  temp.data = buff;
2345  temp.attr = &attr;
2346  attr = *f1->attr;
2348  attr.flags &= ~COB_FLAG_HAVE_SIGN;
2349  cob_move (f1, &temp);
2350  f1 = &temp;
2351  }
2352  if (COB_FIELD_IS_NUMERIC (f2) &&
2354  temp.size = COB_FIELD_DIGITS(f2);
2355  temp.data = buff;
2356  temp.attr = &attr;
2357  attr = *f2->attr;
2359  attr.flags &= ~COB_FLAG_HAVE_SIGN;
2360  cob_move (f2, &temp);
2361  f2 = &temp;
2362  }
2363  return cob_cmp_alnum (f1, f2);
2364 }
#define COB_FIELD_IS_NUMERIC(f)
Definition: common.h:674
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
#define COB_FIELD_TYPE(f)
Definition: common.h:662
unsigned short flags
Definition: common.h:944
unsigned char * data
Definition: common.h:952
#define COB_FLAG_HAVE_SIGN
Definition: common.h:630
int cob_cmp_int(cob_field *, const int)
Definition: numeric.c:2257
int cob_numeric_cmp(cob_field *, cob_field *)
Definition: numeric.c:2348
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
#define COB_TYPE_ALPHANUMERIC_ALL
Definition: common.h:622
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
static int cob_cmp_alnum(cob_field *f1, cob_field *f2)
Definition: common.c:982
unsigned short type
Definition: common.h:941
static int cob_cmp_all(cob_field *f1, cob_field *f2)
Definition: common.c:946
#define COB_FIELD_DIGITS(f)
Definition: common.h:663

Here is the call graph for this function:

Here is the caller graph for this function:

static int cob_cmp_all ( cob_field f1,
cob_field f2 
)
static

Definition at line 946 of file common.c.

References COB_FIELD_TYPE, COB_GET_SIGN, COB_MODULE_PTR, COB_PUT_SIGN, COB_TYPE_NUMERIC_PACKED, common_cmpc(), common_cmps(), cob_field::data, sign, and cob_field::size.

Referenced by cob_cmp().

947 {
948  unsigned char *data;
949  const unsigned char *s;
950  size_t size;
951  int ret;
952  int sign;
953 
954  size = f1->size;
955  data = f1->data;
956  sign = COB_GET_SIGN (f1);
957  s = COB_MODULE_PTR->collating_sequence;
958  if (f2->size == 1) {
959  ret = common_cmpc (data, f2->data[0], size, s);
960  goto end;
961  }
962  ret = 0;
963  while (size >= f2->size) {
964  if ((ret = common_cmps (data, f2->data, f2->size, s)) != 0) {
965  goto end;
966  }
967  size -= f2->size;
968  data += f2->size;
969  }
970  if (size > 0) {
971  ret = common_cmps (data, f2->data, size, s);
972  }
973 
974 end:
976  COB_PUT_SIGN (f1, sign);
977  }
978  return ret;
979 }
static int common_cmps(const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
Definition: common.c:923
static int common_cmpc(const unsigned char *s1, const unsigned int c, const size_t size, const unsigned char *col)
Definition: common.c:900
size_t size
Definition: common.c:108
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
#define COB_FIELD_TYPE(f)
Definition: common.h:662
unsigned char * data
Definition: common.h:952
#define COB_GET_SIGN(f)
Definition: coblocal.h:158
if sign
Definition: flag.def:42
#define COB_PUT_SIGN(f, s)
Definition: coblocal.h:160
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951

Here is the call graph for this function:

Here is the caller graph for this function:

static int cob_cmp_alnum ( cob_field f1,
cob_field f2 
)
static

Definition at line 982 of file common.c.

References COB_FIELD_TYPE, COB_GET_SIGN, COB_MODULE_PTR, COB_PUT_SIGN, COB_TYPE_NUMERIC_PACKED, common_cmpc(), common_cmps(), cob_field::data, and cob_field::size.

Referenced by cob_cmp().

983 {
984  const unsigned char *s;
985  size_t min;
986  int ret;
987  int sign1;
988  int sign2;
989 
990  sign1 = COB_GET_SIGN (f1);
991  sign2 = COB_GET_SIGN (f2);
992  min = (f1->size < f2->size) ? f1->size : f2->size;
993  s = COB_MODULE_PTR->collating_sequence;
994 
995  /* Compare common substring */
996  if ((ret = common_cmps (f1->data, f2->data, min, s)) != 0) {
997  goto end;
998  }
999 
1000  /* Compare the rest (if any) with spaces */
1001  if (f1->size > f2->size) {
1002  ret = common_cmpc (f1->data + min, ' ', f1->size - min, s);
1003  } else if (f1->size < f2->size) {
1004  ret = -common_cmpc (f2->data + min, ' ', f2->size - min, s);
1005  }
1006 
1007 end:
1009  COB_PUT_SIGN (f1, sign1);
1010  }
1012  COB_PUT_SIGN (f2, sign2);
1013  }
1014  return ret;
1015 }
static int common_cmps(const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
Definition: common.c:923
static int common_cmpc(const unsigned char *s1, const unsigned int c, const size_t size, const unsigned char *col)
Definition: common.c:900
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
#define COB_FIELD_TYPE(f)
Definition: common.h:662
unsigned char * data
Definition: common.h:952
#define COB_GET_SIGN(f)
Definition: coblocal.h:158
#define COB_PUT_SIGN(f, s)
Definition: coblocal.h:160
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_command_line ( int  flags,
int *  pargc,
char ***  pargv,
char ***  penvp,
char **  pname 
)

Definition at line 3279 of file common.c.

References _, cob_argc, cob_argv, cob_initialized, cob_runtime_error(), cob_stop_run(), COB_UNUSED, and NULL.

3281 {
3282 #if 0 /* RXWRXW cob_command_line */
3283  char **spenvp;
3284  char *spname;
3285 #else
3286  COB_UNUSED (penvp);
3287  COB_UNUSED (pname);
3288 #endif
3289 
3290  COB_UNUSED (flags);
3291 
3292  if (!cob_initialized) {
3293  cob_runtime_error (_("'cobcommandline' - Runtime has not been initialized"));
3294  cob_stop_run (1);
3295  }
3296  if (pargc && pargv) {
3297  cob_argc = *pargc;
3298  cob_argv = *pargv;
3299  }
3300 
3301 #if 0 /* RXWRXW cob_command_line */
3302  if (penvp) {
3303  spenvp = *penvp;
3304  }
3305  if (pname) {
3306  spname = *pname;
3307  }
3308 #endif
3309 
3310  /* What are we supposed to return here? */
3311  return NULL;
3312 }
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int cob_initialized
Definition: common.c:124
#define COB_UNUSED(z)
Definition: common.h:535
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

void cob_correct_numeric ( cob_field f)

Definition at line 1917 of file common.c.

References COB_FIELD_HAVE_SIGN, COB_FIELD_IS_NUMDISP, COB_FIELD_SIGN_LEADING, COB_FIELD_SIGN_SEPARATE, COB_MODULE_PTR, cob_field::data, cob_func_loc::data, cob_field::size, and unlikely.

1918 {
1919  unsigned char *p;
1920  unsigned char *data;
1921  size_t size;
1922  size_t i;
1923 
1924  if (!COB_FIELD_IS_NUMDISP(f)) {
1925  return;
1926  }
1927  size = f->size;
1928  data = f->data;
1929  if (COB_FIELD_HAVE_SIGN (f)) {
1930  /* Adjust for sign byte */
1931  size--;
1932  if (unlikely(COB_FIELD_SIGN_LEADING (f))) {
1933  p = f->data;
1934  data = p + 1;
1935  } else {
1936  p = f->data + f->size - 1;
1937  }
1938  if (unlikely(COB_FIELD_SIGN_SEPARATE (f))) {
1939  if (*p != '+' && *p != '-') {
1940  *p = '+';
1941  }
1942  } else if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
1943  switch (*p) {
1944  case '{':
1945  case 'A':
1946  case 'B':
1947  case 'C':
1948  case 'D':
1949  case 'E':
1950  case 'F':
1951  case 'G':
1952  case 'H':
1953  case 'I':
1954  case '}':
1955  case 'J':
1956  case 'K':
1957  case 'L':
1958  case 'M':
1959  case 'N':
1960  case 'O':
1961  case 'P':
1962  case 'Q':
1963  case 'R':
1964  break;
1965  case '0':
1966  *p = '{';
1967  break;
1968  case '1':
1969  *p = 'A';
1970  break;
1971  case '2':
1972  *p = 'B';
1973  break;
1974  case '3':
1975  *p = 'C';
1976  break;
1977  case '4':
1978  *p = 'D';
1979  break;
1980  case '5':
1981  *p = 'E';
1982  break;
1983  case '6':
1984  *p = 'F';
1985  break;
1986  case '7':
1987  *p = 'G';
1988  break;
1989  case '8':
1990  *p = 'H';
1991  break;
1992  case '9':
1993  *p = 'I';
1994  break;
1995  case 0:
1996  case ' ':
1997  *p = '{';
1998  break;
1999  default:
2000  break;
2001  }
2002  } else {
2003  if(!*p || *p == ' ') {
2004  *p = '0';
2005  }
2006  }
2007  } else {
2008  p = f->data + f->size - 1;
2009  if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
2010  switch (*p) {
2011  case 0:
2012  case ' ':
2013  case '{':
2014  case '}':
2015  *p = '0';
2016  break;
2017  case 'A':
2018  case 'B':
2019  case 'C':
2020  case 'D':
2021  case 'E':
2022  case 'F':
2023  case 'G':
2024  case 'H':
2025  case 'I':
2026  *p = '1' + (*p - 'A');
2027  break;
2028  case 'J':
2029  case 'K':
2030  case 'L':
2031  case 'M':
2032  case 'N':
2033  case 'O':
2034  case 'P':
2035  case 'Q':
2036  case 'R':
2037  *p = '1' + (*p - 'J');
2038  break;
2039  default:
2040  break;
2041  }
2042  } else {
2043  switch (*p) {
2044  case 0:
2045  case ' ':
2046  case 'p':
2047  *p = '0';
2048  break;
2049  case 'q':
2050  *p = '1';
2051  break;
2052  case 'r':
2053  *p = '2';
2054  break;
2055  case 's':
2056  *p = '3';
2057  break;
2058  case 't':
2059  *p = '4';
2060  break;
2061  case 'u':
2062  *p = '5';
2063  break;
2064  case 'v':
2065  *p = '6';
2066  break;
2067  case 'w':
2068  *p = '7';
2069  break;
2070  case 'x':
2071  *p = '8';
2072  break;
2073  case 'y':
2074  *p = '9';
2075  break;
2076  default:
2077  break;
2078  }
2079  }
2080  }
2081  for (i = 0, p = data; i < size; ++i, ++p) {
2082  switch (*p) {
2083  case '0':
2084  case '1':
2085  case '2':
2086  case '3':
2087  case '4':
2088  case '5':
2089  case '6':
2090  case '7':
2091  case '8':
2092  case '9':
2093  break;
2094  case 0:
2095  case ' ':
2096  *p = '0';
2097  break;
2098  default:
2099  if ((*p & 0x0F) <= 9) {
2100  *p = (*p & 0x0F) + '0';
2101  }
2102  break;
2103  }
2104  }
2105 }
#define COB_FIELD_IS_NUMDISP(f)
Definition: common.h:675
size_t size
Definition: common.c:108
unsigned char * data
Definition: common.h:952
#define COB_FIELD_SIGN_SEPARATE(f)
Definition: common.h:644
#define unlikely(x)
Definition: common.h:437
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951
#define COB_FIELD_HAVE_SIGN(f)
Definition: common.h:643
#define COB_FIELD_SIGN_LEADING(f)
Definition: common.h:645
int cob_ctoi ( const char  digit)

Definition at line 2651 of file common.c.

Referenced by cob_get_current_date_and_time(), seconds_from_formatted_time(), test_century(), test_day_of_year(), test_decade(), test_hour(), test_millenium(), test_month(), test_unit_year(), and test_week().

2652 {
2653  return (int) (digit - '0');
2654 }

Here is the caller graph for this function:

void cob_display_arg_number ( cob_field f)

Definition at line 2911 of file common.c.

References cob_field::attr, cob_argc, COB_ATTR_INIT, COB_EC_IMP_DISPLAY, cob_move(), cob_set_exception(), COB_TYPE_NUMERIC_BINARY, current_arg, cob_field::data, NULL, and cob_field::size.

2912 {
2913  int n;
2914  cob_field_attr attr;
2915  cob_field temp;
2916 
2917  temp.size = 4;
2918  temp.data = (unsigned char *)&n;
2919  temp.attr = &attr;
2921  cob_move (f, &temp);
2922  if (n < 0 || n >= cob_argc) {
2924  return;
2925  }
2926  current_arg = n;
2927 }
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
static int cob_argc
Definition: common.c:125
#define COB_ATTR_INIT(u, v, x, y, z)
Definition: coblocal.h:150
unsigned char * data
Definition: common.h:952
static int current_arg
Definition: common.c:139
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
void cob_set_exception(const int id)
Definition: common.c:1212
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953

Here is the call graph for this function:

void cob_display_command_line ( cob_field f)

Definition at line 2855 of file common.c.

References cob_free(), cob_malloc(), commlncnt, commlnptr, cob_field::data, and cob_field::size.

2856 {
2857  if (commlnptr) {
2858  cob_free (commlnptr);
2859  }
2860  commlnptr = cob_malloc (f->size + 1U);
2861  commlncnt = f->size;
2862  memcpy (commlnptr, f->data, commlncnt);
2863 }
void cob_free(void *mptr)
Definition: common.c:1284
unsigned char * data
Definition: common.h:952
static unsigned char * commlnptr
Definition: common.c:140
static size_t commlncnt
Definition: common.c:141
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

void cob_display_env_value ( const cob_field f)

Definition at line 2981 of file common.c.

References COB_EC_IMP_DISPLAY, cob_fast_malloc(), cob_field_to_string(), cob_free(), cob_local_env, cob_malloc(), cob_rescan_env_vals(), cob_set_exception(), and cob_field::size.

Referenced by cob_set_environment().

2982 {
2983  char *env2;
2984 #if !HAVE_SETENV
2985  char *p;
2986  size_t len;
2987 #endif
2988  int ret;
2989 
2990  if (!cob_local_env) {
2992  return;
2993  }
2994  if (!*cob_local_env) {
2996  return;
2997  }
2998  env2 = cob_malloc (f->size + 1U);
2999  cob_field_to_string (f, env2, f->size);
3000 #if HAVE_SETENV
3001  ret = setenv(cob_local_env, env2, 1);
3002 #else
3003  len = strlen (cob_local_env) + strlen (env2) + 3U;
3004  p = cob_fast_malloc (len);
3005  sprintf (p, "%s=%s", cob_local_env, env2);
3006  ret = putenv (p);
3007 #endif
3008  cob_free (env2);
3009  if (ret != 0) {
3011  return;
3012  }
3013  /* Rescan term/screen variables */
3015 }
void cob_free(void *mptr)
Definition: common.c:1284
static void cob_rescan_env_vals(void)
Definition: common.c:1099
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
static char * cob_local_env
Definition: common.c:138

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_display_environment ( const cob_field f)

Definition at line 2959 of file common.c.

References __cob_settings::cob_env_mangle, cob_field_to_string(), cob_free(), cob_local_env, cob_local_env_size, cob_malloc(), cob_field::size, and unlikely.

Referenced by cob_set_environment().

2960 {
2961  size_t i;
2962 
2963  if (cob_local_env_size < f->size) {
2964  cob_local_env_size = f->size;
2965  if (cob_local_env) {
2967  }
2969  }
2972  for (i = 0; i < strlen (cob_local_env); ++i) {
2973  if (!isalnum ((int)cob_local_env[i])) {
2974  cob_local_env[i] = '_';
2975  }
2976  }
2977  }
2978 }
void cob_free(void *mptr)
Definition: common.c:1284
size_t size
Definition: common.c:108
static cob_settings * cobsetptr
Definition: common.c:131
#define unlikely(x)
Definition: common.h:437
static size_t cob_local_env_size
Definition: common.c:142
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
unsigned int cob_env_mangle
Definition: coblocal.h:205
static char * cob_local_env
Definition: common.c:138

Here is the call graph for this function:

Here is the caller graph for this function:

static void cob_exit_common ( void  )
static

Definition at line 293 of file common.c.

References __cob_settings::cob_config_file, __cob_settings::cob_config_num, cob_free(), cob_initialized, cob_last_sfile, cob_local_env, __cob_global::cob_locale, __cob_global::cob_locale_collate, __cob_global::cob_locale_ctype, __cob_global::cob_locale_messages, __cob_global::cob_locale_monetary, __cob_global::cob_locale_numeric, __cob_global::cob_locale_orig, __cob_global::cob_locale_time, __cob_global::cob_main_argv0, cob_alloc_cache::cob_pointer, __cob_global::cob_term_buff, commlnptr, config_tbl::data_loc, cob_external::ename, ENV_PATH, ENV_STR, cob_external::ext_alloc, cob_alloc_cache::next, cob_external::next, NULL, NUM_CONFIG, and runtime_err_str.

Referenced by cob_terminate_routines().

294 {
295  struct cob_external *p;
296  struct cob_external *q;
297  struct cob_alloc_cache *x;
298  struct cob_alloc_cache *y;
299  void *data;
300  char *str;
301  unsigned int i;
302 
303 #ifdef HAVE_SETLOCALE
305  (void) setlocale (LC_ALL, cobglobptr->cob_locale_orig);
307  }
308  if (cobglobptr->cob_locale) {
310  }
313  }
316  }
319  }
322  }
325  }
328  }
329 #endif
330 
331  if (commlnptr) {
333  }
334  if (cob_local_env) {
336  }
337 
338  /* Free library routine stuff */
339 
340  if (cobglobptr->cob_term_buff) {
342  }
343 
344  /* Free cached externals */
345  for (p = basext; p;) {
346  q = p;
347  p = p->next;
348  if (q->ename) {
349  cob_free (q->ename);
350  }
351  if (q->ext_alloc) {
352  cob_free (q->ext_alloc);
353  }
354  cob_free (q);
355  }
356 
357  /* Free cached mallocs */
358  for (x = cob_alloc_base; x;) {
359  y = x;
360  x = x->next;
361  cob_free (y->cob_pointer);
362  cob_free (y);
363  }
364 
365  /* Free last stuff */
366  if (cob_last_sfile) {
367  cob_free ((void *)cob_last_sfile);
368  }
369  if (runtime_err_str) {
371  }
372  if (cobglobptr) {
373  if (cobglobptr->cob_main_argv0) {
374  cob_free ((void *)(cobglobptr->cob_main_argv0));
375  }
377  cobglobptr = NULL;
378  }
379  if (cobsetptr) {
380  if (cobsetptr->cob_config_file) {
381  for (i=0; i < cobsetptr->cob_config_num; i++)
382  if (cobsetptr->cob_config_file[i])
383  cob_free((void*)cobsetptr->cob_config_file[i]);
385  }
386  /* Free all strings pointed to by cobsetptr */
387  for (i=0; i < NUM_CONFIG; i++) {
388  if ((gc_conf[i].data_type & ENV_STR)
389  || (gc_conf[i].data_type & ENV_PATH)) { /* String/Path to be stored as a string */
390  data = (void*)((char *)cobsetptr + gc_conf[i].data_loc);
391  memcpy(&str,data,sizeof(char *));
392  if( str != NULL) {
393  cob_free((void*)str);
394  str = NULL;
395  memcpy(data,&str,sizeof(char *)); /* Reset pointer to NULL */
396  }
397  }
398  }
400  cobsetptr = NULL;
401  }
402  cob_initialized = 0;
403 }
#define ENV_PATH
Definition: coblocal.h:296
char * cob_locale_monetary
Definition: common.h:1199
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
static struct cob_external * basext
Definition: common.c:144
char * cob_locale_time
Definition: common.h:1201
char * cob_locale_numeric
Definition: common.h:1200
struct cob_external * next
Definition: common.c:114
char * ename
Definition: common.c:116
void * cob_pointer
Definition: common.c:107
static cob_settings * cobsetptr
Definition: common.c:131
static unsigned char * commlnptr
Definition: common.c:140
static struct config_tbl gc_conf[]
Definition: common.c:235
static const char * cob_last_sfile
Definition: common.c:128
unsigned char * cob_term_buff
Definition: common.h:1214
struct cob_alloc_cache * next
Definition: common.c:106
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
char * cob_locale_collate
Definition: common.h:1197
void * ext_alloc
Definition: common.c:115
int data_loc
Definition: coblocal.h:282
char * cob_locale_orig
Definition: common.h:1195
const char * cob_main_argv0
Definition: common.h:1193
static int cob_initialized
Definition: common.c:124
char * cob_locale_messages
Definition: common.h:1198
static cob_global * cobglobptr
Definition: common.c:130
static char * cob_local_env
Definition: common.c:138
char * cob_locale
Definition: common.h:1194
unsigned int cob_config_num
Definition: coblocal.h:208
#define NUM_CONFIG
Definition: common.c:283
#define ENV_STR
Definition: coblocal.h:295
char ** cob_config_file
Definition: coblocal.h:209
static char * runtime_err_str
Definition: common.c:133
char * cob_locale_ctype
Definition: common.h:1196

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_expand_env_string ( char *  strval)

Definition at line 4406 of file common.c.

References COB_CONFIG_DIR, COB_COPY_DIR, cob_free(), cob_malloc(), cob_realloc(), cob_strdup(), and NULL.

Referenced by cb_config_entry(), and set_config_val().

4407 {
4408  unsigned int i,j,k,envlen = 1280;
4409  char *env,*str = strval;
4410  char ename[128],*penv;
4411  env = cob_malloc(envlen);
4412  if (env) {
4413  for (j=k=0; strval[k] != 0; k++) {
4414  if(j >= (envlen-128)) { /* String almost full?; Expand it */
4415  env = cob_realloc(env,envlen,envlen+256);
4416  envlen += 256;
4417  }
4418  if (strval[k] == '$'
4419  && strval[k+1] == '{') { /* ${envname:default} */
4420  k += 2;
4421  for (i=0; strval[k] != '}'
4422  && strval[k] != 0
4423  && strval[k] != ':'; k++) {
4424  ename[i++] = strval[k];
4425  }
4426  ename[i++] = 0;
4427  penv = getenv(ename);
4428  if (penv == NULL) {
4429  if(strval[k] == ':') { /* Copy 'default' value */
4430  k++;
4431  if (strval[k] == '-') k++; /* ${name:-default} */
4432  while (strval[k] != '}' && strval[k] != 0) {
4433  if(j >= (envlen-50)) {
4434  env = cob_realloc(env,envlen,envlen+128);
4435  envlen += 128;
4436  }
4437  env[j++] = strval[k++];
4438  }
4439  } else if(strcmp(ename,"COB_CONFIG_DIR") == 0) {
4440  penv = (char*)COB_CONFIG_DIR;
4441  } else if(strcmp(ename,"COB_COPY_DIR") == 0) {
4442  penv = (char*)COB_COPY_DIR;
4443  }
4444  }
4445  if(penv != NULL) {
4446  if((j + strlen(penv)) > (unsigned int)(envlen - 128)) {
4447  env = cob_realloc(env,envlen, strlen(penv) + 256);
4448  envlen = (unsigned int)strlen(penv) + 256;
4449  }
4450  j += sprintf(&env[j],"%s",penv);
4451  penv = NULL;
4452  }
4453  while(strval[k] != '}' && strval[k] != 0)
4454  k++;
4455  if(strval[k] == '}')
4456  k++;
4457  k--;
4458  } else if (!isspace ((unsigned char)strval[k])) {
4459  env[j++] = strval[k];
4460  } else {
4461  env[j++] = ' ';
4462  }
4463  }
4464  env[j] = 0;
4465  str = cob_strdup(env);
4466  cob_free(env);
4467  }
4468  return str;
4469 }
void cob_free(void *mptr)
Definition: common.c:1284
void * cob_realloc(void *optr, const size_t osize, const size_t nsize)
Definition: common.c:1262
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_CONFIG_DIR
Definition: defaults.h:6
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define COB_COPY_DIR
Definition: defaults.h:7
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_extern_init ( void  )

Definition at line 3272 of file common.c.

References cob_init(), and NULL.

3273 {
3274  cob_init (0, NULL);
3275  return 0;
3276 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_init(const int argc, char **argv)
Definition: common.c:5390

Here is the call graph for this function:

void* cob_external_addr ( const char *  exname,
const int  exlength 
)

Definition at line 2621 of file common.c.

References _, basext, __cob_global::cob_initial_external, cob_malloc(), cob_runtime_error(), cob_stop_run(), cob_external::ename, cob_external::esize, cob_external::ext_alloc, and cob_external::next.

2622 {
2623  struct cob_external *eptr;
2624 
2625  /* Locate or allocate EXTERNAL item */
2626  for (eptr = basext; eptr; eptr = eptr->next) {
2627  if (!strcmp (exname, eptr->ename)) {
2628  if (exlength > eptr->esize) {
2629  cob_runtime_error (_("EXTERNAL item '%s' previously allocated with size %d, requested size is %d"),
2630  exname, eptr->esize, exlength);
2631  cob_stop_run (1);
2632  }
2634  return eptr->ext_alloc;
2635  }
2636  }
2637  eptr = cob_malloc (sizeof (struct cob_external));
2638  eptr->next = basext;
2639  eptr->esize = exlength;
2640  eptr->ename = cob_malloc (strlen (exname) + 1U);
2641  strcpy (eptr->ename, exname);
2642  eptr->ext_alloc = cob_malloc ((size_t)exlength);
2643  basext = eptr;
2645  return eptr->ext_alloc;
2646 }
static struct cob_external * basext
Definition: common.c:144
struct cob_external * next
Definition: common.c:114
char * ename
Definition: common.c:116
#define _(s)
Definition: cobcrun.c:59
int cob_initial_external
Definition: common.h:1205
void * ext_alloc
Definition: common.c:115
int esize
Definition: common.c:117
void * cob_malloc(const size_t size)
Definition: common.c:1250
static cob_global * cobglobptr
Definition: common.c:130
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

void* cob_fast_malloc ( const size_t  size)

Definition at line 1296 of file common.c.

References cob_fatal_error(), COB_FERROR_MEMORY, and unlikely.

Referenced by cob_check_numeric(), cob_decimal_set_display(), cob_display_env_value(), cob_file_sort_init(), cob_get_buff(), cob_getopt_long_long(), cob_gettmpdir(), cob_init(), cob_init_call(), cob_init_fileio(), cob_inspect_init(), cob_int_to_formatted_bytestring(), cob_new_item(), cob_save_env_value(), cob_strcat(), and cobcrun_setenv().

1297 {
1298  void *mptr;
1299 
1300  mptr = malloc (size);
1301  if (unlikely(!mptr)) {
1303  }
1304  return mptr;
1305 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
#define COB_FERROR_MEMORY
Definition: common.h:697

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_fatal_error ( const int  fatal_error)

Definition at line 1601 of file common.c.

References _, cob_file::assign, COB_D2I, __cob_global::cob_error_file, COB_FERROR_CANCEL, COB_FERROR_CHAINING, COB_FERROR_CODEGEN, COB_FERROR_FILE, COB_FERROR_FREE, COB_FERROR_FUNCTION, COB_FERROR_GLOBAL, COB_FERROR_INITIALIZED, COB_FERROR_MEMORY, COB_FERROR_MODULE, COB_FERROR_NONE, COB_FERROR_RECURSIVE, COB_FERROR_STACK, cob_field_to_string(), COB_FILE_BUFF, COB_FILE_MAX, cob_free(), cob_malloc(), COB_MODULE_PTR, cob_runtime_error(), COB_STATUS_10_END_OF_FILE, COB_STATUS_14_OUT_OF_KEY_RANGE, COB_STATUS_21_KEY_INVALID, COB_STATUS_22_KEY_EXISTS, COB_STATUS_23_KEY_NOT_EXISTS, COB_STATUS_30_PERMANENT_ERROR, COB_STATUS_35_NOT_EXISTS, COB_STATUS_37_PERMISSION_DENIED, COB_STATUS_41_ALREADY_OPEN, COB_STATUS_42_NOT_OPEN, COB_STATUS_43_READ_NOT_DONE, COB_STATUS_44_RECORD_OVERFLOW, COB_STATUS_46_READ_ERROR, COB_STATUS_47_INPUT_DENIED, COB_STATUS_48_OUTPUT_DENIED, COB_STATUS_49_I_O_DENIED, COB_STATUS_51_RECORD_LOCKED, COB_STATUS_57_I_O_LINAGE, COB_STATUS_61_FILE_SHARING, COB_STATUS_91_NOT_AVAILABLE, cob_stop_run(), and cob_file::file_status.

Referenced by CHECKSRC_(), cob_call(), cob_call_field(), cob_cancel(), cob_cancel_field(), cob_fast_malloc(), cob_file_open(), cob_free(), cob_get_global_ptr(), cob_intr_boolean_of_integer(), cob_intr_char_national(), cob_intr_display_of(), cob_intr_exception_file_n(), cob_intr_exception_location_n(), cob_intr_integer_of_boolean(), cob_intr_national_of(), cob_intr_standard_compare(), cob_longjmp(), cob_malloc(), cob_module_enter(), cob_realloc(), cob_resolve_internal(), cob_savenv(), cobxref_(), field_display(), GCic_(), get__reserved__lists_(), integer_of_ddd(), integer_of_formatted_date(), integer_of_mmdd(), integer_of_wwwd(), LISTING_(), and seconds_from_formatted_time().

1602 {
1603  const char *msg;
1604  unsigned char *file_status;
1605  char *err_cause;
1606  int status;
1607 
1608  switch (fatal_error) {
1609 #if 0 /* Currently not in use, should enter unknown error */
1610  case COB_FERROR_NONE:
1611  cob_runtime_error (_("cob_init() has not been called"));
1612  break;
1613 #endif
1614  case COB_FERROR_CANCEL:
1615  cob_runtime_error (_("Attempt to CANCEL active program"));
1616  break;
1618  cob_runtime_error (_("cob_init() has not been called"));
1619  break;
1620  case COB_FERROR_CODEGEN:
1621  cob_runtime_error (_("Codegen error - Please report this"));
1622  break;
1623  case COB_FERROR_CHAINING:
1624  cob_runtime_error (_("Recursive call of chained program"));
1625  break;
1626  case COB_FERROR_STACK:
1627  cob_runtime_error (_("Stack overflow, possible PERFORM depth exceeded"));
1628  break;
1629  case COB_FERROR_GLOBAL:
1630  cob_runtime_error (_("Invalid entry/exit in GLOBAL USE procedure"));
1631  break;
1632  case COB_FERROR_MEMORY:
1633  cob_runtime_error (_("Unable to allocate memory"));
1634  break;
1635  case COB_FERROR_MODULE:
1636  cob_runtime_error (_("Invalid entry into module"));
1637  break;
1638  case COB_FERROR_RECURSIVE:
1639  cob_runtime_error (_("Invalid recursive COBOL CALL to '%s'"),
1640  COB_MODULE_PTR->module_name);
1641  break;
1642  case COB_FERROR_FREE:
1643  cob_runtime_error (_("Call to %s with NULL pointer"), "cob_free");
1644  break;
1645  case COB_FERROR_FILE:
1646  file_status = cobglobptr->cob_error_file->file_status;
1647  status = COB_D2I(file_status[0]) * 10 + COB_D2I(file_status[1]);
1648  switch (status) {
1650  msg = _("End of file");
1651  break;
1653  msg = _("Key out of range");
1654  break;
1656  msg = _("Key order not ascending");
1657  break;
1659  msg = _("Record key already exists");
1660  break;
1662  msg = _("Record key does not exist");
1663  break;
1665  msg = _("Permanent file error");
1666  break;
1668  msg = _("File does not exist");
1669  break;
1671  msg = _("Permission denied");
1672  break;
1674  msg = _("File already open");
1675  break;
1677  msg = _("File not open");
1678  break;
1680  msg = _("READ must be executed first");
1681  break;
1683  msg = _("Record overflow");
1684  break;
1686  msg = _("Failed to READ");
1687  break;
1689  msg = _("READ/START not allowed");
1690  break;
1692  msg = _("WRITE not allowed");
1693  break;
1695  msg = _("DELETE/REWRITE not allowed");
1696  break;
1698  msg = _("Record locked by another file connector");
1699  break;
1701  msg = _("LINAGE values invalid");
1702  break;
1704  msg = _("File sharing conflict");
1705  break;
1707  msg = _("Runtime library is not configured for this operation");
1708  break;
1709  default:
1710  msg = _("Unknown file error");
1711  break;
1712  }
1713  err_cause = cob_malloc ((size_t)COB_FILE_BUFF);
1715  err_cause, (size_t)COB_FILE_MAX);
1716  cob_runtime_error (_("%s (Status = %02d) File : '%s'"),
1717  msg, status, err_cause);
1718  cob_free (err_cause);
1719  break;
1720  case COB_FERROR_FUNCTION:
1721  cob_runtime_error (_("Attempt to use non-implemented function"));
1722  break;
1723  default:
1724  cob_runtime_error (_("Unknown failure : %d"), fatal_error);
1725  break;
1726  }
1727  cob_stop_run (1);
1728 }
#define COB_STATUS_42_NOT_OPEN
Definition: common.h:847
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_STATUS_10_END_OF_FILE
Definition: common.h:833
#define COB_STATUS_41_ALREADY_OPEN
Definition: common.h:846
#define COB_FERROR_CODEGEN
Definition: common.h:693
cob_file * cob_error_file
Definition: common.h:1187
#define COB_STATUS_14_OUT_OF_KEY_RANGE
Definition: common.h:834
#define COB_STATUS_23_KEY_NOT_EXISTS
Definition: common.h:837
cob_field * assign
Definition: common.h:1114
#define COB_STATUS_61_FILE_SHARING
Definition: common.h:856
#define COB_FERROR_CANCEL
Definition: common.h:691
#define COB_STATUS_35_NOT_EXISTS
Definition: common.h:842
#define COB_FERROR_FUNCTION
Definition: common.h:702
#define COB_FERROR_RECURSIVE
Definition: common.h:699
#define COB_STATUS_44_RECORD_OVERFLOW
Definition: common.h:849
unsigned char * file_status
Definition: common.h:1113
#define COB_FERROR_GLOBAL
Definition: common.h:696
#define COB_STATUS_22_KEY_EXISTS
Definition: common.h:836
#define COB_FERROR_MODULE
Definition: common.h:698
#define COB_STATUS_46_READ_ERROR
Definition: common.h:850
#define _(s)
Definition: cobcrun.c:59
#define COB_FILE_BUFF
Definition: common.h:542
#define COB_STATUS_48_OUTPUT_DENIED
Definition: common.h:852
#define COB_STATUS_30_PERMANENT_ERROR
Definition: common.h:839
#define COB_FERROR_CHAINING
Definition: common.h:694
#define COB_FERROR_FILE
Definition: common.h:701
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_STATUS_21_KEY_INVALID
Definition: common.h:835
#define COB_FERROR_STACK
Definition: common.h:695
#define COB_STATUS_43_READ_NOT_DONE
Definition: common.h:848
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
#define COB_STATUS_49_I_O_DENIED
Definition: common.h:853
#define COB_FERROR_FREE
Definition: common.h:703
#define COB_FERROR_INITIALIZED
Definition: common.h:692
#define COB_STATUS_57_I_O_LINAGE
Definition: common.h:855
#define COB_STATUS_51_RECORD_LOCKED
Definition: common.h:854
#define COB_STATUS_47_INPUT_DENIED
Definition: common.h:851
void * cob_malloc(const size_t size)
Definition: common.c:1250
static cob_global * cobglobptr
Definition: common.c:130
#define COB_D2I(x)
Definition: coblocal.h:177
#define COB_FILE_MAX
Definition: common.h:548
#define COB_STATUS_91_NOT_AVAILABLE
Definition: common.h:857
#define COB_STATUS_37_PERMISSION_DENIED
Definition: common.h:843
#define COB_FERROR_MEMORY
Definition: common.h:697
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
#define COB_FERROR_NONE
Definition: common.h:690
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_field_to_string ( const cob_field f,
void *  str,
const size_t  maxsize 
)

Definition at line 1492 of file common.c.

References cob_field::data, cob_field::size, and unlikely.

Referenced by cob_call_field(), cob_cancel_field(), cob_delete_file(), cob_display_env_value(), cob_display_environment(), cob_exit_fileio(), cob_fatal_error(), cob_get_environment(), cob_intr_locale_compare(), cob_intr_locale_date(), cob_open(), cob_set_locale(), and cob_sys_getopt_long_long().

1493 {
1494  unsigned char *s;
1495  size_t count;
1496  size_t i;
1497 
1498  count = 0;
1499  if (unlikely(f->size == 0)) {
1500  return;
1501  }
1502  i = f->size - 1;
1503  for (; ;) {
1504  if (f->data[i] && f->data[i] != (unsigned char)' ') {
1505  count = i + 1;
1506  break;
1507  }
1508  if (!i) {
1509  break;
1510  }
1511  --i;
1512  }
1513  if (count > maxsize) {
1514  count = maxsize;
1515  }
1516  s = (unsigned char *)str;
1517  for (i = 0; i < count; ++i) {
1518  s[i] = f->data[i];
1519  }
1520  s[i] = 0;
1521 }
unsigned char * data
Definition: common.h:952
#define unlikely(x)
Definition: common.h:437
size_t size
Definition: common.h:951

Here is the caller graph for this function:

void cob_free ( void *  mptr)

Definition at line 1284 of file common.c.

References cob_fatal_error(), COB_FERROR_FREE, and unlikely.

Referenced by alloc_figurative(), cb_config_entry(), cb_list_intrinsics(), cb_load_conf_file(), cob_accept_command_line(), cob_allocate(), cob_cache_free(), cob_cache_realloc(), cob_call(), cob_call_field(), cob_check_numeric(), cob_chk_file_env(), cob_chk_file_mapping(), cob_close(), cob_decimal_get_field(), cob_decimal_pop(), cob_decimal_set_display(), cob_display_command_line(), cob_display_env_value(), cob_display_environment(), cob_exit_call(), cob_exit_common(), cob_exit_fileio(), cob_exit_intrinsic(), cob_exit_numeric(), cob_exit_screen(), cob_exit_strings(), cob_expand_env_string(), cob_fatal_error(), cob_file_sort_close(), cob_file_sort_giving(), cob_free_alloc(), cob_free_list(), cob_get_buff(), cob_get_environment(), cob_getopt_long_long(), cob_gettmpdir(), cob_init(), cob_init_call(), cob_inspect_init(), cob_intr_concatenate(), cob_intr_exception_location(), cob_intr_locale_compare(), cob_intr_median(), cob_intr_numval_f(), cob_move_all(), cob_move_edited_to_display(), cob_realloc(), cob_resolve(), cob_resolve_cobol(), cob_restore_func(), cob_runtime_error(), cob_save_env_value(), cob_set_library_path(), cob_set_locale(), cob_set_location(), cob_srttmpfile(), cob_strcat(), cob_sys_change_dir(), cob_sys_check_file_exist(), cob_sys_copy_file(), cob_sys_create_dir(), cob_sys_delete_dir(), cob_sys_delete_file(), cob_sys_error_proc(), cob_sys_exit_proc(), cob_sys_file_info(), cob_sys_get_current_dir(), cob_sys_getopt_long_long(), cob_sys_rename_file(), cob_sys_system(), cob_table_sort(), cob_trace_section(), cob_unstring_init(), do_cancel_module(), format_field(), indexed_close(), indexed_open(), indirect_move(), insert(), make_field_entry(), numval(), open_cbl_file(), set_config_val(), substitute(), and var_print().

1285 {
1286 #ifdef _DEBUG
1287  if (unlikely(!mptr)) {
1289  }
1290 #endif
1291  free (mptr);
1292 
1293 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
#define COB_FERROR_FREE
Definition: common.h:703

Here is the call graph for this function:

void cob_free_alloc ( unsigned char **  ptr1,
unsigned char *  ptr2 
)

Definition at line 3131 of file common.c.

References cob_alloc_base, COB_EC_STORAGE_NOT_ALLOC, __cob_global::cob_exception_code, cob_free(), cob_alloc_cache::cob_pointer, cob_set_exception(), cob_alloc_cache::next, and NULL.

3132 {
3133  struct cob_alloc_cache *cache_ptr;
3134  struct cob_alloc_cache *prev_ptr;
3135  void *vptr1;
3136 
3137  /* FREE */
3139  cache_ptr = cob_alloc_base;
3140  prev_ptr = cob_alloc_base;
3141  if (ptr1 && *ptr1) {
3142  vptr1 = *ptr1;
3143  for (; cache_ptr; cache_ptr = cache_ptr->next) {
3144  if (vptr1 == cache_ptr->cob_pointer) {
3145  cob_free (cache_ptr->cob_pointer);
3146  if (cache_ptr == cob_alloc_base) {
3147  cob_alloc_base = cache_ptr->next;
3148  } else {
3149  prev_ptr->next = cache_ptr->next;
3150  }
3151  cob_free (cache_ptr);
3152  *ptr1 = NULL;
3153  return;
3154  }
3155  prev_ptr = cache_ptr;
3156  }
3158  return;
3159  }
3160  if (ptr2 && *(void **)ptr2) {
3161  for (; cache_ptr; cache_ptr = cache_ptr->next) {
3162  if (*(void **)ptr2 == cache_ptr->cob_pointer) {
3163  cob_free (cache_ptr->cob_pointer);
3164  if (cache_ptr == cob_alloc_base) {
3165  cob_alloc_base = cache_ptr->next;
3166  } else {
3167  prev_ptr->next = cache_ptr->next;
3168  }
3169  cob_free (cache_ptr);
3170  *(void **)ptr2 = NULL;
3171  return;
3172  }
3173  prev_ptr = cache_ptr;
3174  }
3176  return;
3177  }
3178 }
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
void * cob_pointer
Definition: common.c:107
struct cob_alloc_cache * next
Definition: common.c:106
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130

Here is the call graph for this function:

struct cob_time cob_get_current_date_and_time ( void  )

Definition at line 2699 of file common.c.

References cob_ctoi(), cob_time::day_of_month, cob_time::day_of_week, cob_time::hour, cob_time::minute, cob_time::month, cob_time::nanosecond, NULL, cob_time::offset_known, one_indexed_day_of_week_from_monday(), cob_time::second, set_unknown_offset(), cob_time::utc_offset, and cob_time::year.

Referenced by cob_accept_time(), cob_intr_current_date(), format_current_date(), and get_system_offset_time_ptr().

2700 {
2701 #if defined (HAVE_CLOCK_GETTIME)
2702  struct timespec time_spec;
2703 #elif defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2704  struct timeval tmv;
2705 #endif
2706  time_t curtime;
2707  struct tm *tmptr;
2708  struct cob_time cb_time;
2709 #if defined(COB_STRFTIME)
2710  char iso_timezone[6] = { '\0' };
2711 #endif
2712 
2713  /* Get the current time */
2714 #if defined (HAVE_CLOCK_GETTIME)
2715  clock_gettime (CLOCK_REALTIME, &time_spec);
2716  curtime = time_spec.tv_sec;
2717 #elif defined (HAVE_SYS_TIME_H) && defined (HAVE_GETTIMEOFDAY)
2718  gettimeofday(&tmv, NULL);
2719  curtime = tmv.tv_sec;
2720 #else
2721  curtime = time (NULL);
2722 #endif
2723  tmptr = localtime (&curtime);
2724  /* Leap seconds ? */
2725  if (tmptr->tm_sec >= 60) {
2726  tmptr->tm_sec = 59;
2727  }
2728 
2729  cb_time.year = tmptr->tm_year + 1900;
2730  cb_time.month = tmptr->tm_mon + 1;
2731  cb_time.day_of_month = tmptr->tm_mday;
2732  cb_time.day_of_week = one_indexed_day_of_week_from_monday (tmptr->tm_wday);
2733  cb_time.hour = tmptr->tm_hour;
2734  cb_time.minute = tmptr->tm_min;
2735  cb_time.second = tmptr->tm_sec;
2736  cb_time.nanosecond = 0;
2737  cb_time.offset_known = 0;
2738  cb_time.utc_offset = 0;
2739 
2740  /* Get nanoseconds or microseconds, if possible */
2741 #if defined (HAVE_CLOCK_GETTIME)
2742  cb_time.nanosecond = time_spec.tv_nsec;
2743 #elif defined (HAVE_SYS_TIME_H) && defined (HAVE_GETTIMEOFDAY)
2744  cb_time.nanosecond = tmv.tv_usec * 1000;
2745 #else
2746  cb_time.nanosecond = 0;
2747 #endif
2748 
2749  /* Get the offset from UTC */
2750 #if defined (COB_STRFTIME)
2751  strftime (iso_timezone, (size_t) 6, "%z", tmptr);
2752 
2753  if (iso_timezone[0] == '0') {
2754  set_unknown_offset (&cb_time);
2755  } else {
2756  /* Convert the timezone string into minutes from UTC */
2757  cb_time.offset_known = 1;
2758  cb_time.utc_offset =
2759  cob_ctoi (iso_timezone[1]) * 60 * 10
2760  + cob_ctoi (iso_timezone[2]) * 60
2761  + cob_ctoi (iso_timezone[3]) * 10
2762  + cob_ctoi (iso_timezone[4]);
2763  if (iso_timezone[0] == '-') {
2764  cb_time.utc_offset *= -1;
2765  }
2766  }
2767 #elif defined (HAVE_TIMEZONE)
2768  cb_time.offset_known = 1;
2769  cb_time.utc_offset = timezone / 60;
2770 #else
2771  set_unknown_offset(&cb_time);
2772 #endif
2773 
2774  return cb_time;
2775 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int one_indexed_day_of_week_from_monday(int zero_indexed_from_sunday)
Definition: common.c:1147
int cob_ctoi(const char digit)
Definition: common.c:2651
static void set_unknown_offset(struct cob_time *time)
Definition: common.c:1153

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_get_environment ( const cob_field envname,
cob_field envval 
)

Definition at line 3025 of file common.c.

References COB_EC_IMP_ACCEPT, __cob_settings::cob_env_mangle, cob_field_to_string(), cob_free(), cob_malloc(), cob_memcpy(), cob_set_exception(), cob_field::size, and unlikely.

Referenced by cobxref_(), GCic_(), and LISTING_().

3026 {
3027  const char *p;
3028  char *buff;
3029  size_t size;
3030 
3031  if (envname->size == 0 || envval->size == 0) {
3033  return;
3034  }
3035 
3036  buff = cob_malloc (envname->size + 1U);
3037  cob_field_to_string (envname, buff, envname->size);
3039  for (size = 0; size < strlen (buff); ++size) {
3040  if (!isalnum ((int)buff[size])) {
3041  buff[size] = '_';
3042  }
3043  }
3044  }
3045  p = getenv (buff);
3046  if (!p) {
3048  p = " ";
3049  }
3050  cob_memcpy (envval, p, strlen (p));
3051  cob_free (buff);
3052 }
static void cob_memcpy(cob_field *dst, const void *src, const size_t size)
Definition: common.c:1042
void cob_free(void *mptr)
Definition: common.c:1284
static cob_settings * cobsetptr
Definition: common.c:131
#define unlikely(x)
Definition: common.h:437
void cob_set_exception(const int id)
Definition: common.c:1212
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
unsigned int cob_env_mangle
Definition: coblocal.h:205

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_get_exception_code ( void  )

Definition at line 1193 of file common.c.

References __cob_global::cob_exception_code.

Referenced by cob_string_append(), and cob_unstring_into().

1194 {
1196 }
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130

Here is the caller graph for this function:

const char* cob_get_exception_name ( void  )

Definition at line 1199 of file common.c.

References __cob_global::cob_exception_code, cob_exception_tab_code, cob_exception_tab_name, EXCEPTION_TAB_SIZE, and NULL.

Referenced by cob_intr_exception_status().

1200 {
1201  size_t n;
1202 
1203  for (n = 0; n < EXCEPTION_TAB_SIZE; ++n) {
1205  return cob_exception_tab_name[n];
1206  }
1207  }
1208  return NULL;
1209 }
static const char *const cob_exception_tab_name[]
Definition: common.c:180
#define EXCEPTION_TAB_SIZE
Definition: common.c:196
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130
static const int cob_exception_tab_code[]
Definition: common.c:188

Here is the caller graph for this function:

cob_global* cob_get_global_ptr ( void  )

Definition at line 1787 of file common.c.

References cob_fatal_error(), COB_FERROR_INITIALIZED, cob_initialized, cobglobptr, and unlikely.

1788 {
1789  if (unlikely(!cob_initialized)) {
1791  }
1792  return cobglobptr;
1793 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
#define COB_FERROR_INITIALIZED
Definition: common.h:692
static int cob_initialized
Definition: common.c:124
static cob_global * cobglobptr
Definition: common.c:130

Here is the call graph for this function:

unsigned char* cob_get_pointer ( const void *  srcptr)

Definition at line 1474 of file common.c.

References cob_u8_ptr.

1475 {
1476  void *tmptr;
1477 
1478  memcpy (&tmptr, srcptr, sizeof (void *));
1479  return (cob_u8_ptr)tmptr;
1480 }
#define cob_u8_ptr
Definition: common.h:66
void* cob_get_prog_pointer ( const void *  srcptr)

Definition at line 1483 of file common.c.

1484 {
1485  void *tmptr;
1486 
1487  memcpy (&tmptr, srcptr, sizeof (void *));
1488  return tmptr;
1489 }
cob_settings* cob_get_settings_ptr ( void  )

Definition at line 5384 of file common.c.

References cobsetptr.

5385 {
5386  return cobsetptr;
5387 }
static cob_settings * cobsetptr
Definition: common.c:131
static int cob_get_sign_ascii ( unsigned char *  p)
static

Definition at line 651 of file common.c.

Referenced by cob_real_get_sign().

652 {
653 #ifdef COB_EBCDIC_MACHINE
654  switch (*p) {
655  case 'p':
656  *p = (unsigned char)'0';
657  return -1;
658  case 'q':
659  *p = (unsigned char)'1';
660  return -1;
661  case 'r':
662  *p = (unsigned char)'2';
663  return -1;
664  case 's':
665  *p = (unsigned char)'3';
666  return -1;
667  case 't':
668  *p = (unsigned char)'4';
669  return -1;
670  case 'u':
671  *p = (unsigned char)'5';
672  return -1;
673  case 'v':
674  *p = (unsigned char)'6';
675  return -1;
676  case 'w':
677  *p = (unsigned char)'7';
678  return -1;
679  case 'x':
680  *p = (unsigned char)'8';
681  return -1;
682  case 'y':
683  *p = (unsigned char)'9';
684  return -1;
685  }
686  *p = (unsigned char)'0';
687  return 1;
688 #else
689  if (*p >= (unsigned char)'p' && *p <= (unsigned char)'y') {
690  *p &= ~64U;
691  return -1;
692  }
693  *p = (unsigned char)'0';
694  return 1;
695 #endif
696 }

Here is the caller graph for this function:

static int cob_get_sign_ebcdic ( unsigned char *  p)
static

Definition at line 747 of file common.c.

Referenced by cob_real_get_sign().

748 {
749  switch (*p) {
750  case '{':
751  *p = (unsigned char)'0';
752  return 1;
753  case 'A':
754  *p = (unsigned char)'1';
755  return 1;
756  case 'B':
757  *p = (unsigned char)'2';
758  return 1;
759  case 'C':
760  *p = (unsigned char)'3';
761  return 1;
762  case 'D':
763  *p = (unsigned char)'4';
764  return 1;
765  case 'E':
766  *p = (unsigned char)'5';
767  return 1;
768  case 'F':
769  *p = (unsigned char)'6';
770  return 1;
771  case 'G':
772  *p = (unsigned char)'7';
773  return 1;
774  case 'H':
775  *p = (unsigned char)'8';
776  return 1;
777  case 'I':
778  *p = (unsigned char)'9';
779  return 1;
780  case '}':
781  *p = (unsigned char)'0';
782  return -1;
783  case 'J':
784  *p = (unsigned char)'1';
785  return -1;
786  case 'K':
787  *p = (unsigned char)'2';
788  return -1;
789  case 'L':
790  *p = (unsigned char)'3';
791  return -1;
792  case 'M':
793  *p = (unsigned char)'4';
794  return -1;
795  case 'N':
796  *p = (unsigned char)'5';
797  return -1;
798  case 'O':
799  *p = (unsigned char)'6';
800  return -1;
801  case 'P':
802  *p = (unsigned char)'7';
803  return -1;
804  case 'Q':
805  *p = (unsigned char)'8';
806  return -1;
807  case 'R':
808  *p = (unsigned char)'9';
809  return -1;
810  default:
811  /* What to do here */
812  *p = (unsigned char)('0' + (*p & 0x0F));
813  if (*p > (unsigned char)'9') {
814  *p = (unsigned char)'0';
815  }
816  return 1;
817  }
818 }

Here is the caller graph for this function:

int cob_get_switch ( const int  n)

Definition at line 2296 of file common.c.

References cob_switch, and COB_SWITCH_MAX.

Referenced by cob_switch_value().

2297 {
2298  if (n < 0 || n > COB_SWITCH_MAX) {
2299  return 0;
2300  }
2301  return cob_switch[n];
2302 }
static int cob_switch[36+1]
Definition: common.c:201
#define COB_SWITCH_MAX
Definition: common.c:199

Here is the caller graph for this function:

char* cob_getenv ( const char *  name)

Definition at line 3181 of file common.c.

References cob_strdup(), and NULL.

3182 {
3183  char *p;
3184 
3185  if (name) {
3186  p = getenv (name);
3187  if (p) {
3188  return cob_strdup (p);
3189  }
3190  }
3191  return NULL;
3192 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

static const char* cob_gettmpdir ( void  )
static

Definition at line 3210 of file common.c.

References cob_fast_malloc(), cob_free(), cob_strdup(), and NULL.

Referenced by cob_temp_name().

3211 {
3212  char *tmpdir;
3213  char *tmp;
3214 #if !HAVE_SETENV
3215  char *put;
3216 #endif
3217 
3218  if ((tmpdir = getenv ("TMPDIR")) == NULL) {
3219  tmp = NULL;
3220 #ifdef _WIN32
3221  if ((tmpdir = getenv ("TEMP")) == NULL &&
3222  (tmpdir = getenv ("TMP")) == NULL &&
3223  (tmpdir = getenv ("USERPROFILE")) == NULL) {
3224  tmp = cob_fast_malloc (2U);
3225  strcpy (tmp, ".");
3226  tmpdir = tmp;
3227  }
3228 #else
3229  if ((tmpdir = getenv ("TMP")) == NULL &&
3230  (tmpdir = getenv ("TEMP")) == NULL) {
3231  tmp = cob_fast_malloc (5U);
3232  strcpy (tmp, "/tmp");
3233  tmpdir = tmp;
3234  }
3235 #endif
3236 #if HAVE_SETENV
3237  (void)setenv("TMPDIR", tmpdir, 1);
3238 #else
3239  put = cob_fast_malloc (strlen (tmpdir) + 10);
3240  sprintf (put, "TMPDIR=%s", tmpdir);
3241  (void)putenv (cob_strdup(put));
3242  cob_free ((void *)put);
3243 #endif
3244  if (tmp) {
3245  cob_free ((void *)tmp);
3246  tmpdir = getenv ("TMPDIR");
3247  }
3248  }
3249  return tmpdir;
3250 }
void cob_free(void *mptr)
Definition: common.c:1284
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_incr_temp_iteration ( void  )

Definition at line 3266 of file common.c.

References cob_temp_iteration.

Referenced by cob_srttmpfile(), and process_filename().

3267 {
3269 }
static int cob_temp_iteration
Definition: common.c:161

Here is the caller graph for this function:

void cob_init ( const int  argc,
char **  argv 
)

Definition at line 5390 of file common.c.

References _, bindtextdomain, cob_argc, cob_argv, cob_current_paragraph, cob_current_program_id, cob_current_section, COB_ERRBUF_SIZE, cob_fast_malloc(), cob_free(), cob_init_call(), cob_init_fileio(), cob_init_intrinsic(), cob_init_move(), cob_init_numeric(), cob_init_screenio(), cob_init_strings(), cob_init_termio(), cob_initialized, COB_LARGE_BUFF, COB_LARGE_MAX, cob_last_sfile, cob_load_config(), cob_local_env, cob_local_env_size, __cob_global::cob_locale, __cob_global::cob_locale_collate, __cob_global::cob_locale_ctype, __cob_global::cob_locale_messages, __cob_global::cob_locale_monetary, __cob_global::cob_locale_numeric, __cob_global::cob_locale_orig, __cob_global::cob_locale_time, __cob_global::cob_main_argv0, cob_malloc(), COB_MEDIUM_BUFF, __cob_settings::cob_physical_cancel, __cob_global::cob_physical_cancel, cob_set_signal(), cob_source_file, cob_source_line, cob_source_statement, cob_stop_run(), cob_strdup(), cob_switch, COB_SWITCH_MAX, __cob_global::cob_term_buff, __cob_settings::cob_unix_lf, __cob_settings::cob_user_name, commlncnt, commlnptr, current_arg, exit_hdlrs, hdlrs, LOCALEDIR, NULL, PACKAGE, R_OK, runtime_err_str, set_config_val_by_name(), sort_collate, sort_nkeys, textdomain, and unlikely.

Referenced by cob_extern_init(), cob_module_enter(), main(), and process_command_line().

5391 {
5392  char *s;
5393 #if defined(HAVE_READLINK) || defined(HAVE_GETEXECNAME)
5394  const char *path;
5395 #endif
5396 #ifdef ENABLE_NLS
5397  const char* localedir;
5398 #endif
5399 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
5400  HMODULE kernel32_handle;
5401 #endif
5402  int i;
5403 
5404 #if 0 /* Simon: Should not happen - is it neccessary any where?
5405  We may change this to a runtime warning/error */
5406  if (cob_initialized) {
5407  return;
5408  }
5409 #endif
5410 
5411  cob_set_signal ();
5412 
5413  cob_alloc_base = NULL;
5414  cob_local_env = NULL;
5415  cob_last_sfile = NULL;
5416  commlnptr = NULL;
5417  basext = NULL;
5418  sort_keys = NULL;
5419  sort_collate = NULL;
5425  exit_hdlrs = NULL;
5426  hdlrs = NULL;
5427  commlncnt = 0;
5428  sort_nkeys = 0;
5429  cob_source_line = 0;
5430  cob_local_env_size = 0;
5431 
5432  current_arg = 1;
5433 
5434  cob_argc = argc;
5435  cob_argv = argv;
5436 
5437  /* Get emergency buffer */
5439 
5440  /* Get global structure */
5441  cobglobptr = cob_malloc (sizeof(cob_global));
5442 
5443  /* Get settings structure */
5444  cobsetptr = cob_malloc (sizeof(cob_settings));
5445 
5446  cob_initialized = 1;
5447 
5448 #ifdef HAVE_SETLOCALE
5449  /* Prime the locale from user settings */
5450  s = setlocale (LC_ALL, "");
5451  if (s) {
5452  /* Save initial values */
5454  s = setlocale (LC_CTYPE, NULL);
5455  if (s) {
5457  }
5458  s = setlocale (LC_COLLATE, NULL);
5459  if (s) {
5461  }
5462 #ifdef LC_MESSAGES
5463  s = setlocale (LC_MESSAGES, NULL);
5464  if (s) {
5466  }
5467 #endif
5468  s = setlocale (LC_MONETARY, NULL);
5469  if (s) {
5471  }
5472  s = setlocale (LC_NUMERIC, NULL);
5473  if (s) {
5475  }
5476  s = setlocale (LC_TIME, NULL);
5477  if (s) {
5479  }
5480  /* Set to standard "C" locale for COBOL */
5481  setlocale (LC_NUMERIC, "C");
5482  setlocale (LC_CTYPE, "C");
5483  /* Save changed locale */
5484  s = setlocale (LC_ALL, NULL);
5485  if (s) {
5487  }
5488  }
5489 #endif
5490 
5491 #ifdef ENABLE_NLS
5492  localedir = getenv("LOCALEDIR");
5493  if (localedir != NULL) {
5494  bindtextdomain (PACKAGE, localedir);
5495  } else {
5497  }
5498  textdomain (PACKAGE);
5499 #endif
5500 
5501 #ifdef _WIN32
5502  /* cob_unix_lf needs to be set before configuration load,
5503  possible error messages would have wrong line endings otherwise */
5504  if ((s = getenv("COB_UNIX_LF")) != NULL) {
5505  set_config_val_by_name (s, "unix_lf", NULL);
5506  }
5507  if (cobsetptr->cob_unix_lf) {
5508  (void)_setmode (_fileno (stdin), _O_BINARY);
5509  (void)_setmode (_fileno (stdout), _O_BINARY);
5510  (void)_setmode (_fileno (stderr), _O_BINARY);
5511  }
5512 #endif
5513 
5514  /* Load runtime configuration file */
5515  if (unlikely(cob_load_config() < 0)) {
5516  cob_stop_run (1);
5517  }
5518 
5519  /* Copy COB_PHYSICAL_CANCEL from settings (internal) to global structure */
5521 
5522  /* Call inits with cobsetptr to get the adresses of all */
5523  /* Screen-IO might be needed for error outputs */
5526  cob_init_strings();
5532 
5533  /* Set up library routine stuff */
5535 
5536  /* Set switches */
5537  for (i = 0; i <= COB_SWITCH_MAX; ++i) {
5538  sprintf (runtime_err_str, "COB_SWITCH_%d", i);
5539  s = getenv (runtime_err_str);
5540  if (s && (*s == '1' || strcasecmp (s, "ON") == 0)) {
5541  cob_switch[i] = 1;
5542  } else {
5543  cob_switch[i] = 0;
5544  }
5545  }
5546 
5547  /* Get user name if not set via environment already */
5548  if (cobsetptr->cob_user_name == NULL || !strcmp(cobsetptr->cob_user_name, "Unknown")) {
5549 #if defined (_WIN32) && (!defined(_MSC_VER) || COB_USE_VC2008_OR_GREATER) /* Needs SDK for earlier versions */
5550  unsigned long bsiz = COB_ERRBUF_SIZE;
5551  if (GetUserName (runtime_err_str, &bsiz)) {
5552  set_config_val_by_name(runtime_err_str, "username", "GetUserName()");
5553  }
5554 #elif !defined(__OS400__)
5555  s = getlogin ();
5556  if (s) {
5557  set_config_val_by_name(s, "username", "getlogin()");
5558  }
5559 #endif
5560  }
5561 
5562 #if defined(_MSC_VER) && COB_USE_VC2008_OR_GREATER
5563  /* Get function pointer for most precisise time function */
5564  kernel32_handle = GetModuleHandle (TEXT ("kernel32.dll"));
5565  if (kernel32_handle != NULL) {
5566  time_as_filetime_func = (VOID (WINAPI *) (LPFILETIME))
5567  GetProcAddress (kernel32_handle, "GetSystemTimePreciseAsFileTime");
5568  }
5569  if (time_as_filetime_func == NULL) {
5570  time_as_filetime_func = GetSystemTimeAsFileTime;
5571  }
5572 #endif
5573 
5574  /* This must be last in this function as we do early return */
5575  /* from certain ifdef's */
5576 
5577 #ifdef _WIN32
5578  s = cob_malloc ((size_t)COB_LARGE_BUFF);
5579  i = GetModuleFileNameA (NULL, s, COB_LARGE_MAX);
5580  if (i > 0 && i < COB_LARGE_BUFF) {
5582  cob_free (s);
5583  return;
5584  }
5585  cob_free (s);
5586 #elif defined(HAVE_READLINK)
5587  path = NULL;
5588  if (!access ("/proc/self/exe", R_OK)) {
5589  path = "/proc/self/exe";
5590  } else if (!access ("/proc/curproc/file", R_OK)) {
5591  path = "/proc/curproc/file";
5592  } else if (!access ("/proc/self/path/a.out", R_OK)) {
5593  path = "/proc/self/path/a.out";
5594  }
5595  if (path) {
5596  s = cob_malloc ((size_t)COB_LARGE_BUFF);
5597  i = (int)readlink (path, s, (size_t)COB_LARGE_MAX);
5598  if (i > 0 && i < COB_LARGE_BUFF) {
5600  cob_free (s);
5601  return;
5602  }
5603  cob_free (s);
5604  }
5605 #endif
5606 
5607 #ifdef HAVE_GETEXECNAME
5608  path = getexecname ();
5609  if (path) {
5610 #ifdef HAVE_REALPATH
5611  s = cob_malloc ((size_t)COB_LARGE_BUFF);
5612  if (realpath (path, s) != NULL) {
5614  } else {
5616  }
5617  cob_free (s);
5618 #else
5620 #endif
5621  return;
5622  }
5623 #endif
5624 
5625  if (argc && argv && argv[0]) {
5626 #ifdef _WIN32
5627  /* Returns malloced path or NULL */
5628  cobglobptr->cob_main_argv0 = _fullpath (NULL, argv[0], 1);
5629 #elif defined(HAVE_CANONICALIZE_FILE_NAME)
5630  /* Returns malloced path or NULL */
5631  cobglobptr->cob_main_argv0 = canonicalize_file_name (argv[0]);
5632 #elif defined(HAVE_REALPATH)
5633  s = cob_malloc ((size_t)COB_LARGE_BUFF);
5634  if (realpath (argv[0], s) != NULL) {
5636  }
5637  cob_free (s);
5638 #endif
5639  if (!cobglobptr->cob_main_argv0) {
5640  cobglobptr->cob_main_argv0 = cob_strdup (argv[0]);
5641  }
5642  } else {
5643  cobglobptr->cob_main_argv0 = cob_strdup (_("Unknown"));
5644  }
5645  /* The above must be last in this function as we do early return */
5646  /* from certain ifdef's */
5647 }
char * cob_locale_monetary
Definition: common.h:1199
void cob_free(void *mptr)
Definition: common.c:1284
static struct cob_alloc_cache * cob_alloc_base
Definition: common.c:127
static struct cob_external * basext
Definition: common.c:144
void cob_init_numeric(cob_global *)
Definition: numeric.c:2671
char * cob_locale_time
Definition: common.h:1201
unsigned int cob_unix_lf
Definition: coblocal.h:228
char * cob_locale_numeric
Definition: common.h:1200
static cob_file_key * sort_keys
Definition: common.c:147
char * cob_user_name
Definition: coblocal.h:211
void cob_init_intrinsic(cob_global *)
Definition: intrinsic.c:6555
static struct exit_handlerlist * exit_hdlrs
#define COB_ERRBUF_SIZE
Definition: common.c:120
static int cob_argc
Definition: common.c:125
#define COB_MEDIUM_BUFF
Definition: common.h:543
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:86
static unsigned int cob_source_line
Definition: common.c:156
static cob_settings * cobsetptr
Definition: common.c:131
#define COB_LARGE_BUFF
Definition: common.h:544
static char ** cob_argv
Definition: common.c:126
static unsigned char * commlnptr
Definition: common.c:140
void cob_init_fileio(cob_global *, cob_settings *)
Definition: fileio.c:6345
#define textdomain(Domainname)
Definition: gettext.h:84
static const char * cob_last_sfile
Definition: common.c:128
static int current_arg
Definition: common.c:139
unsigned int cob_physical_cancel
Definition: common.h:1209
static struct handlerlist * hdlrs
unsigned char * cob_term_buff
Definition: common.h:1214
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
char * cob_locale_collate
Definition: common.h:1197
static size_t cob_local_env_size
Definition: common.c:142
static int set_config_val_by_name(char *value, const char *name, const char *func)
Definition: common.c:4644
int cob_load_config(void)
Definition: common.c:5063
void cob_init_strings(void)
Definition: strings.c:652
static const char * cob_current_paragraph
Definition: common.c:152
static size_t commlncnt
Definition: common.c:141
void cob_init_move(cob_global *, cob_settings *)
Definition: move.c:1683
void cob_init_screenio(cob_global *, cob_settings *)
Definition: screenio.c:2567
char * cob_locale_orig
Definition: common.h:1195
static const char * cob_current_program_id
Definition: common.c:150
const char * cob_main_argv0
Definition: common.h:1193
#define COB_LARGE_MAX
Definition: common.h:550
static const char * cob_source_file
Definition: common.c:153
static int cob_initialized
Definition: common.c:124
void cob_init_termio(cob_global *, cob_settings *)
Definition: termio.c:343
static const char * cob_source_statement
Definition: common.c:154
void * cob_malloc(const size_t size)
Definition: common.c:1250
char * cob_locale_messages
Definition: common.h:1198
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
static cob_global * cobglobptr
Definition: common.c:130
static char * cob_local_env
Definition: common.c:138
#define R_OK
Definition: cobc.h:58
static void cob_set_signal(void)
Definition: common.c:549
char * cob_locale
Definition: common.h:1194
static const char * cob_current_section
Definition: common.c:151
#define PACKAGE
Definition: config.h:294
#define LOCALEDIR
Definition: defaults.h:17
static int cob_switch[36+1]
Definition: common.c:201
void cob_init_call(cob_global *lptr, cob_settings *sptr)
Definition: call.c:1307
static const unsigned char * sort_collate
Definition: common.c:148
#define COB_SWITCH_MAX
Definition: common.c:199
static char * runtime_err_str
Definition: common.c:133
unsigned int cob_physical_cancel
Definition: coblocal.h:218
static size_t sort_nkeys
Definition: common.c:146
char * cob_locale_ctype
Definition: common.h:1196
void cob_stop_run(const int status)
Definition: common.c:1524
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_int_to_formatted_bytestring ( int  i,
char *  number 
)

Definition at line 4246 of file common.c.

References cob_fast_malloc(), and NULL.

4247 {
4248  double d;
4249  char *strB;
4250 
4251  if (!number) return NULL;
4252 
4253  strB = (char*) cob_fast_malloc(3);
4254 
4255  if (i > (1024 * 1024)) {
4256  d = i / 1024.0 / 1024.0;
4257  strB = (char*) "MB";
4258  } else if (i > 1024) {
4259  d = i / 1024.0;
4260  strB = (char*) "kB";
4261  } else {
4262  d = 0;
4263  strB = (char*) "B";
4264  }
4265  sprintf (number, "%3.2f %s", d, strB);
4266  return number;
4267 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296

Here is the call graph for this function:

char* cob_int_to_string ( int  i,
char *  number 
)

Definition at line 4238 of file common.c.

References NULL.

4239 {
4240  if (!number) return NULL;
4241  sprintf (number, "%i", i);
4242  return number;
4243 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int cob_is_alpha ( const cob_field f)

Definition at line 2453 of file common.c.

References cob_field::data, and cob_field::size.

Referenced by cobxref_().

2454 {
2455  size_t i;
2456 
2457  for (i = 0; i < f->size; ++i) {
2458  if (!isalpha (f->data[i]) && f->data[i] != (unsigned char)' ') {
2459  return 0;
2460  }
2461  }
2462  return 1;
2463 }
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951

Here is the caller graph for this function:

int cob_is_lower ( const cob_field f)

Definition at line 2479 of file common.c.

References cob_field::data, and cob_field::size.

2480 {
2481  size_t i;
2482 
2483  for (i = 0; i < f->size; ++i) {
2484  if (!islower (f->data[i]) && f->data[i] != (unsigned char)' ') {
2485  return 0;
2486  }
2487  }
2488  return 1;
2489 }
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951
int cob_is_numeric ( const cob_field f)

Definition at line 2375 of file common.c.

References cob_check_numdisp(), COB_FIELD_HAVE_SIGN, COB_FIELD_NO_SIGN_NIBBLE, COB_FIELD_TYPE, COB_MODULE_PTR, COB_TYPE_NUMERIC_BINARY, COB_TYPE_NUMERIC_DISPLAY, COB_TYPE_NUMERIC_DOUBLE, COB_TYPE_NUMERIC_FLOAT, COB_TYPE_NUMERIC_FP_DEC128, COB_TYPE_NUMERIC_FP_DEC64, COB_TYPE_NUMERIC_PACKED, cob_field::data, sign, and cob_field::size.

Referenced by cob_check_numeric(), and cobxref_().

2376 {
2377  size_t i;
2378  union {
2379  float fpf;
2380  double fpd;
2381  } fval;
2382  int sign;
2383 
2384  switch (COB_FIELD_TYPE (f)) {
2386  return 1;
2388  memcpy (&fval.fpf, f->data, sizeof(float));
2389  return !finite ((double)fval.fpf);
2391  memcpy (&fval.fpd, f->data, sizeof(double));
2392  return !finite (fval.fpd);
2394  /* Check digits */
2395  for (i = 0; i < f->size - 1; ++i) {
2396  if ((f->data[i] & 0xF0) > 0x90 ||
2397  (f->data[i] & 0x0F) > 0x09) {
2398  return 0;
2399  }
2400  }
2401  /* Check high nibble of last byte */
2402  if ((f->data[i] & 0xF0) > 0x90) {
2403  return 0;
2404  }
2405 
2406  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
2407  /* COMP-6 - Check last nibble */
2408  if ((f->data[i] & 0x0F) > 0x09) {
2409  return 0;
2410  }
2411  return 1;
2412  }
2413 
2414  /* Check sign */
2415  sign = f->data[i] & 0x0F;
2416  if (COB_FIELD_HAVE_SIGN (f)) {
2417  if (sign == 0x0C || sign == 0x0D) {
2418  return 1;
2419  }
2420  if (COB_MODULE_PTR->flag_host_sign &&
2421  sign == 0x0F) {
2422  return 1;
2423  }
2424  } else if (sign == 0x0F) {
2425  return 1;
2426  }
2427  return 0;
2429  return cob_check_numdisp (f);
2431 #ifdef WORDS_BIGENDIAN
2432  return (f->data[0] & 0x78U) != 0x78U;
2433 #else
2434  return (f->data[7] & 0x78U) != 0x78U;
2435 #endif
2437 #ifdef WORDS_BIGENDIAN
2438  return (f->data[0] & 0x78U) != 0x78U;
2439 #else
2440  return (f->data[15] & 0x78U) != 0x78U;
2441 #endif
2442  default:
2443  for (i = 0; i < f->size; ++i) {
2444  if (!isdigit (f->data[i])) {
2445  return 0;
2446  }
2447  }
2448  return 1;
2449  }
2450 }
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
#define COB_FIELD_TYPE(f)
Definition: common.h:662
static int cob_check_numdisp(const cob_field *f)
Definition: common.c:2108
unsigned char * data
Definition: common.h:952
#define COB_TYPE_NUMERIC_FP_DEC64
Definition: common.h:613
#define COB_FIELD_NO_SIGN_NIBBLE(f)
Definition: common.h:651
#define COB_TYPE_NUMERIC_FLOAT
Definition: common.h:610
if sign
Definition: flag.def:42
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951
#define COB_TYPE_NUMERIC_DOUBLE
Definition: common.h:611
#define COB_FIELD_HAVE_SIGN(f)
Definition: common.h:643
#define COB_TYPE_NUMERIC_FP_DEC128
Definition: common.h:614

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_is_omitted ( const cob_field f)

Definition at line 2369 of file common.c.

References cob_field::data, and NULL.

2370 {
2371  return f->data == NULL;
2372 }
unsigned char * data
Definition: common.h:952
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int cob_is_upper ( const cob_field f)

Definition at line 2466 of file common.c.

References cob_field::data, and cob_field::size.

2467 {
2468  size_t i;
2469 
2470  for (i = 0; i < f->size; ++i) {
2471  if (!isupper (f->data[i]) && f->data[i] != (unsigned char)' ') {
2472  return 0;
2473  }
2474  }
2475  return 1;
2476 }
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951
int cob_load_config ( void  )

Definition at line 5063 of file common.c.

References COB_CONFIG_DIR, cob_load_config_file(), COB_MEDIUM_BUFF, COB_MEDIUM_MAX, cob_rescan_env_vals(), config_tbl::data_type, NULL, NUM_CONFIG, set_config_val(), SLASH_STR, STS_CNFSET, STS_ENVCLR, STS_ENVSET, varseq_dflt, and WITH_VARSEQ.

Referenced by cob_init().

5064 {
5065  char *env;
5066  char conf_file[COB_MEDIUM_BUFF];
5067  int isoptional = 1, sts, i, j;
5068 
5069 
5070  /* Get the name for the configuration file */
5071  if ((env = getenv ("COB_RUNTIME_CONFIG")) != NULL && env[0]) {
5072  strcpy (conf_file, env);
5073  isoptional = 0; /* If declared then it is NOT optional */
5074  } else {
5075  /* check for COB_CONFIG_DIR (use default if not in environment) */
5076  if ((env = getenv("COB_CONFIG_DIR")) != NULL && env[0]) {
5077  snprintf (conf_file, (size_t)COB_MEDIUM_MAX, "%s%s%s", env, SLASH_STR, "runtime.cfg");
5078  } else {
5079  snprintf (conf_file, (size_t)COB_MEDIUM_MAX, "%s%s%s", COB_CONFIG_DIR, SLASH_STR, "runtime.cfg");
5080  }
5081  isoptional = 1; /* If not present, then just use env vars */
5082  }
5083 
5084  sprintf (varseq_dflt, "%d", WITH_VARSEQ); /* Default comes from config.h */
5085  for (i=0; i < NUM_CONFIG; i++) {
5086  gc_conf[i].data_type &= ~(STS_ENVSET|STS_CNFSET|STS_ENVCLR); /* Clear status */
5087  }
5088 
5089  sts = cob_load_config_file (conf_file, isoptional);
5090 
5091  cob_rescan_env_vals(); /* Check for possible environment variables */
5092 
5093  /* Set with default value if present and not set otherwise */
5094  for (i=0; i < NUM_CONFIG; i++) {
5095  if (gc_conf[i].default_val
5096  && !(gc_conf[i].data_type & STS_CNFSET)
5097  && !(gc_conf[i].data_type & STS_ENVSET)) {
5098  for (j=0; j < NUM_CONFIG; j++) { /* Any alias present? */
5099  if(j != i
5100  && gc_conf[i].data_loc == gc_conf[j].data_loc)
5101  break;
5102  }
5103  if(j < NUM_CONFIG) {
5104  if(!(gc_conf[j].data_type & STS_CNFSET)
5105  && !(gc_conf[j].data_type & STS_ENVSET)) { /* alias not defined? */
5106  set_config_val((char*)gc_conf[i].default_val,i);
5107  }
5108  } else {
5109  set_config_val((char*)gc_conf[i].default_val,i); /* Set default value */
5110  }
5111  }
5112  }
5113 
5114  return sts;
5115 }
#define SLASH_STR
Definition: common.h:506
#define WITH_VARSEQ
Definition: config.h:370
#define COB_MEDIUM_BUFF
Definition: common.h:543
int data_type
Definition: coblocal.h:281
static struct config_tbl gc_conf[]
Definition: common.c:235
static void cob_rescan_env_vals(void)
Definition: common.c:1099
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static char varseq_dflt[8]
Definition: common.c:225
#define STS_ENVCLR
Definition: coblocal.h:302
static int set_config_val(char *value, int pos)
Definition: common.c:4503
#define STS_ENVSET
Definition: coblocal.h:300
#define STS_CNFSET
Definition: coblocal.h:301
static int cob_load_config_file(const char *config_file, int isoptional)
Definition: common.c:4944
#define COB_CONFIG_DIR
Definition: defaults.h:6
#define NUM_CONFIG
Definition: common.c:283
#define COB_MEDIUM_MAX
Definition: common.h:549

Here is the call graph for this function:

Here is the caller graph for this function:

static int cob_load_config_file ( const char *  config_file,
int  isoptional 
)
static

Definition at line 4944 of file common.c.

References _, cb_config_entry(), __cob_settings::cob_config_cur, COB_CONFIG_DIR, __cob_settings::cob_config_file, __cob_settings::cob_config_num, COB_FILE_BUFF, COB_FILE_MAX, cob_malloc(), cob_realloc(), COB_SMALL_BUFF, cob_source_file, cob_source_line, conf_runtime_error(), F_OK, line, NULL, SLASH_CHAR, and SLASH_STR.

Referenced by cob_load_config().

4945 {
4946  char buff[COB_FILE_BUFF], filename[COB_FILE_BUFF];
4947  char *penv;
4948  int sub_ret, ret;
4949  unsigned int i;
4950  int line;
4951  FILE *conf_fd;
4952 
4953  for (i=0; config_file[i] != 0 && config_file[i] != SLASH_CHAR; i++);
4954  if (config_file[i] == 0) { /* Just a name, No directory */
4955  if (access(config_file, F_OK) != 0) { /* and file does not exist */
4956  /* check for path of previous configuration file (for includes) */
4957  filename[0] = 0;
4958  if (cobsetptr->cob_config_cur != 0) {
4959  strcpy(buff, cobsetptr->cob_config_file[cobsetptr->cob_config_cur - 1]);
4960  for (i = (int)strlen(buff); i != 0 && buff[i] != SLASH_CHAR; i--);
4961  if (i != 0) {
4962  buff[i] = 0;
4963  snprintf(filename, (size_t)COB_FILE_MAX, "%s%s%s", buff, SLASH_STR, config_file);
4964  if (access(filename, F_OK) == 0) { /* and prefixed file exist */
4965  config_file = filename; /* Prefix last directory */
4966  } else {
4967  filename[0] = 0;
4968  }
4969  }
4970  }
4971  if (filename[0] == 0) {
4972  /* check for COB_CONFIG_DIR (use default if not in environment) */
4973  penv = getenv("COB_CONFIG_DIR");
4974  if (penv != NULL) {
4975  snprintf(filename, (size_t)COB_FILE_MAX, "%s%s%s", penv, SLASH_STR, config_file);
4976  } else {
4977  snprintf(filename, (size_t)COB_FILE_MAX, "%s%s%s", COB_CONFIG_DIR, SLASH_STR, config_file);
4978  }
4979  if (access(filename, F_OK) == 0) { /* and prefixed file exist */
4980  config_file = filename; /* Prefix COB_CONFIG_DIR */
4981  }
4982  }
4983  }
4984  }
4985 
4986  cob_source_file = config_file;
4987 
4988  /* check for recursion */
4989  for (i=0; i < cobsetptr->cob_config_num; i++) {
4990  if (strcmp(cobsetptr->cob_config_file[i], config_file) == 0) {
4991  cob_source_line = 0;
4992  conf_runtime_error (1,_("Recursive inclusion"));
4993  return -2;
4994  }
4995  }
4996 
4997  /* Open the configuration file */
4998  conf_fd = fopen (config_file, "r");
4999  if (conf_fd == NULL && !isoptional) {
5000  cob_source_line = 0;
5001  conf_runtime_error (1,_("No such file or directory"));
5002  if (cobsetptr->cob_config_file) {
5004  }
5005  return -1;
5006  }
5007  if (conf_fd != NULL) {
5008  if (cobsetptr->cob_config_file == NULL) {
5009  cobsetptr->cob_config_file = cob_malloc(sizeof(char *));
5010  } else {
5012  sizeof(char *)*(cobsetptr->cob_config_num), sizeof(char *)*(cobsetptr->cob_config_num+1));
5013  }
5014  cobsetptr->cob_config_file[cobsetptr->cob_config_num++] = strdup (config_file); /* Save config file name */
5016  }
5017 
5018 
5019  /* Read the configuration file */
5020  ret = 0;
5021  line = 0;
5022  while ( (conf_fd != NULL)
5023  && (fgets (buff, COB_SMALL_BUFF, conf_fd) != NULL) ) {
5024  line++;
5025  for (i=0; isspace((unsigned char)buff[i]); i++);
5026  if (buff[i] == 0
5027  || buff[i] == '#'
5028  || buff[i] == '\r'
5029  || buff[i] == '\n')
5030  continue; /* Skip comments and blank lines */
5031 
5032  /* Evaluate config line */
5033  sub_ret = cb_config_entry (buff, line);
5034 
5035  /* Include another configuration file */
5036  if (sub_ret == 1 || sub_ret == 3) {
5038  sub_ret = cob_load_config_file (buff, sub_ret == 3);
5039  cob_source_file = config_file;
5040  if (sub_ret < 0) {
5041  ret = -1;
5043  conf_runtime_error (1, _("Configuration file was included here"));
5044  break;
5045  }
5046  }
5047  if (sub_ret < ret) ret = sub_ret;
5048  }
5049  if (conf_fd) {
5050  fclose (conf_fd);
5052  }
5054  conf_fd = NULL;
5055 
5056  return ret;
5057 }
#define SLASH_STR
Definition: common.h:506
#define COB_SMALL_BUFF
Definition: common.h:540
void conf_runtime_error(const int finish_error, const char *fmt,...)
Definition: common.c:1744
static unsigned int cob_source_line
Definition: common.c:156
static cob_settings * cobsetptr
Definition: common.c:131
void * cob_realloc(void *optr, const size_t osize, const size_t nsize)
Definition: common.c:1262
#define _(s)
Definition: cobcrun.c:59
#define COB_FILE_BUFF
Definition: common.h:542
#define F_OK
Definition: cobc.h:46
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define SLASH_CHAR
Definition: common.h:505
static int cb_config_entry(char *buf, int line)
Definition: common.c:4772
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
static int cob_load_config_file(const char *config_file, int isoptional)
Definition: common.c:4944
static const char * cob_source_file
Definition: common.c:153
#define COB_CONFIG_DIR
Definition: defaults.h:6
void * cob_malloc(const size_t size)
Definition: common.c:1250
Definition: cobc.h:195
unsigned int cob_config_num
Definition: coblocal.h:208
#define COB_FILE_MAX
Definition: common.h:548
char ** cob_config_file
Definition: coblocal.h:209
unsigned int cob_config_cur
Definition: coblocal.h:207

Here is the call graph for this function:

Here is the caller graph for this function:

void* cob_malloc ( const size_t  size)

Definition at line 1250 of file common.c.

References cob_fatal_error(), COB_FERROR_MEMORY, and unlikely.

Referenced by alloc_figurative(), cache_dynload(), cache_preload(), cb_config_entry(), cb_list_intrinsics(), cb_load_conf_file(), cob_accept_command_line(), cob_allocate(), cob_cache_file(), cob_cache_malloc(), cob_cache_realloc(), cob_call(), cob_decimal_get_field(), cob_decimal_push(), cob_display_command_line(), cob_display_env_value(), cob_display_environment(), cob_expand_env_string(), cob_external_addr(), cob_fatal_error(), cob_file_sort_giving(), cob_file_sort_init(), cob_get_environment(), cob_init(), cob_init_call(), cob_init_fileio(), cob_init_intrinsic(), cob_init_numeric(), cob_init_strings(), cob_intr_concatenate(), cob_intr_exception_location(), cob_intr_locale_compare(), cob_intr_median(), cob_intr_numval_f(), cob_load_config_file(), cob_move_all(), cob_move_edited_to_display(), cob_rescan_env_vals(), cob_resolve_internal(), cob_save_func(), cob_set_library_path(), cob_set_locale(), cob_srttmpfile(), cob_str_from_fld(), cob_strdup(), cob_sys_error_proc(), cob_sys_exit_proc(), cob_sys_getopt_long_long(), cob_sys_system(), cob_table_sort_init(), cob_unstring_init(), format_field(), indexed_open(), indexed_write(), indirect_move(), insert(), make_field_entry(), numval(), screen_accept(), and substitute().

1251 {
1252  void *mptr;
1253 
1254  mptr = calloc ((size_t)1, size);
1255  if (unlikely(!mptr)) {
1257  }
1258  return mptr;
1259 }
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
#define COB_FERROR_MEMORY
Definition: common.h:697

Here is the call graph for this function:

static void cob_memcpy ( cob_field dst,
const void *  src,
const size_t  size 
)
static

Definition at line 1042 of file common.c.

References cob_field::attr, cob_move(), cob_u8_ptr, const_alpha_attr, cob_field::data, and cob_field::size.

Referenced by cob_accept_arg_value(), cob_accept_command_line(), cob_accept_date(), cob_accept_date_yyyymmdd(), cob_accept_day(), cob_accept_day_of_week(), cob_accept_day_yyyyddd(), cob_accept_environment(), cob_accept_time(), cob_accept_user_name(), and cob_get_environment().

1043 {
1044  cob_field temp;
1045 
1046  if (!dst->size) {
1047  return;
1048  }
1049  temp.size = size;
1050  temp.data = (cob_u8_ptr)src;
1051  temp.attr = &const_alpha_attr;
1052  cob_move (&temp, dst);
1053 }
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
unsigned char * data
Definition: common.h:952
#define cob_u8_ptr
Definition: common.h:66
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
static const cob_field_attr const_alpha_attr
Definition: common.c:135

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_module_enter ( cob_module **  module,
cob_global **  mglobal,
const int  auto_init 
)

Definition at line 1796 of file common.c.

References cob_cache_malloc(), __cob_global::cob_call_params, cob_fatal_error(), COB_FERROR_INITIALIZED, cob_init(), cob_initialized, COB_MODULE_PTR, cobglobptr, module, NULL, and unlikely.

Referenced by CHECKSRC_(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

1798 {
1799  /* Check initialized */
1800  if (unlikely(!cob_initialized)) {
1801  if (auto_init) {
1802  cob_init (0, NULL);
1803  } else {
1805  }
1806  }
1807 
1808  /* Set global pointer */
1809  *mglobal = cobglobptr;
1810 
1811  /* Check module pointer */
1812  if (!*module) {
1813  *module = cob_cache_malloc (sizeof(cob_module));
1814  }
1815 
1816 #if 0 /* RXWRXW - Params */
1817  /* Save parameter count */
1818  (*module)->module_num_params = cobglobptr->cob_call_params;
1819 #endif
1820 
1821  /* Push module pointer */
1822  (*module)->next = COB_MODULE_PTR;
1824 }
static cob_module * module
Definition: cobxref.c.l.h:14
int cob_call_params
Definition: common.h:1204
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_init(const int argc, char **argv)
Definition: common.c:5390
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_FERROR_INITIALIZED
Definition: common.h:692
static int cob_initialized
Definition: common.c:124
static cob_global * cobglobptr
Definition: common.c:130
void * cob_cache_malloc(const size_t size)
Definition: common.c:1321

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_module_leave ( cob_module module)

Definition at line 1827 of file common.c.

References COB_MODULE_PTR, and COB_UNUSED.

Referenced by CHECKSRC_(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

1828 {
1829  COB_UNUSED (module);
1830  /* Pop module pointer */
1832 }
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_UNUSED(z)
Definition: common.h:535

Here is the caller graph for this function:

void cob_parameter_check ( const char *  funcname,
const int  numparms 
)

Definition at line 1907 of file common.c.

References _, __cob_global::cob_call_params, cob_runtime_error(), and cob_stop_run().

1908 {
1909  if (cobglobptr->cob_call_params < numparms) {
1910  cob_runtime_error (_("CALL to %s requires %d parameters"),
1911  funcname, numparms);
1912  cob_stop_run (1);
1913  }
1914 }
int cob_call_params
Definition: common.h:1204
#define _(s)
Definition: cobcrun.c:59
static cob_global * cobglobptr
Definition: common.c:130
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

static void cob_put_sign_ascii ( unsigned char *  p)
static

Definition at line 699 of file common.c.

Referenced by cb_build_move_literal(), and cob_real_put_sign().

700 {
701 #ifdef COB_EBCDIC_MACHINE
702  switch (*p) {
703  case '0':
704  *p = (unsigned char)'p';
705  return;
706  case '1':
707  *p = (unsigned char)'q';
708  return;
709  case '2':
710  *p = (unsigned char)'r';
711  return;
712  case '3':
713  *p = (unsigned char)'s';
714  return;
715  case '4':
716  *p = (unsigned char)'t';
717  return;
718  case '5':
719  *p = (unsigned char)'u';
720  return;
721  case '6':
722  *p = (unsigned char)'v';
723  return;
724  case '7':
725  *p = (unsigned char)'w';
726  return;
727  case '8':
728  *p = (unsigned char)'x';
729  return;
730  case '9':
731  *p = (unsigned char)'y';
732  return;
733  default:
734  *p = (unsigned char)'0';
735  }
736 #else
737  *p |= 64U;
738 #endif
739 }

Here is the caller graph for this function:

static void cob_put_sign_ebcdic ( unsigned char *  p,
const int  sign 
)
static

Definition at line 821 of file common.c.

Referenced by cob_real_put_sign().

822 {
823  if (sign < 0) {
824  switch (*p) {
825  case '0':
826  *p = (unsigned char)'}';
827  return;
828  case '1':
829  *p = (unsigned char)'J';
830  return;
831  case '2':
832  *p = (unsigned char)'K';
833  return;
834  case '3':
835  *p = (unsigned char)'L';
836  return;
837  case '4':
838  *p = (unsigned char)'M';
839  return;
840  case '5':
841  *p = (unsigned char)'N';
842  return;
843  case '6':
844  *p = (unsigned char)'O';
845  return;
846  case '7':
847  *p = (unsigned char)'P';
848  return;
849  case '8':
850  *p = (unsigned char)'Q';
851  return;
852  case '9':
853  *p = (unsigned char)'R';
854  return;
855  default:
856  /* What to do here */
857  *p = (unsigned char)'{';
858  return;
859  }
860  }
861  switch (*p) {
862  case '0':
863  *p = (unsigned char)'{';
864  return;
865  case '1':
866  *p = (unsigned char)'A';
867  return;
868  case '2':
869  *p = (unsigned char)'B';
870  return;
871  case '3':
872  *p = (unsigned char)'C';
873  return;
874  case '4':
875  *p = (unsigned char)'D';
876  return;
877  case '5':
878  *p = (unsigned char)'E';
879  return;
880  case '6':
881  *p = (unsigned char)'F';
882  return;
883  case '7':
884  *p = (unsigned char)'G';
885  return;
886  case '8':
887  *p = (unsigned char)'H';
888  return;
889  case '9':
890  *p = (unsigned char)'I';
891  return;
892  default:
893  /* What to do here */
894  *p = (unsigned char)'{';
895  return;
896  }
897 }
if sign
Definition: flag.def:42

Here is the caller graph for this function:

int cob_putenv ( char *  name)

Definition at line 3195 of file common.c.

References cob_rescan_env_vals(), and cob_strdup().

3196 {
3197  int ret;
3198 
3199  if (name && strchr (name, '=')) {
3200  ret = putenv (cob_strdup(name));
3201  if (!ret) {
3203  }
3204  return ret;
3205  }
3206  return -1;
3207 }
static void cob_rescan_env_vals(void)
Definition: common.c:1099
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

void cob_ready_trace ( void  )

Definition at line 1462 of file common.c.

References __cob_settings::cob_line_trace.

1463 {
1465 }
static cob_settings * cobsetptr
Definition: common.c:131
unsigned int cob_line_trace
Definition: coblocal.h:206
int cob_real_get_sign ( cob_field f)

Definition at line 2205 of file common.c.

References COB_FIELD_NO_SIGN_NIBBLE, COB_FIELD_SIGN_LEADING, COB_FIELD_SIGN_SEPARATE, COB_FIELD_TYPE, cob_get_sign_ascii(), cob_get_sign_ebcdic(), COB_MODULE_PTR, COB_TYPE_NUMERIC_DISPLAY, COB_TYPE_NUMERIC_PACKED, cob_field::data, cob_field::size, and unlikely.

2206 {
2207  unsigned char *p;
2208 
2209  switch (COB_FIELD_TYPE (f)) {
2211  /* Locate sign */
2212  if (unlikely(COB_FIELD_SIGN_LEADING (f))) {
2213  p = f->data;
2214  } else {
2215  p = f->data + f->size - 1;
2216  }
2217 
2218  /* Get sign */
2219  if (unlikely(COB_FIELD_SIGN_SEPARATE (f))) {
2220  return (*p == '-') ? -1 : 1;
2221  }
2222  if (*p >= (unsigned char)'0' && *p <= (unsigned char)'9') {
2223  return 1;
2224  }
2225  if (*p == ' ') {
2226 #if 0 /* RXWRXW - Space sign */
2227  *p = (unsigned char)'0';
2228 #endif
2229  return 1;
2230  }
2231  if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
2232  return cob_get_sign_ebcdic (p);
2233  }
2234  return cob_get_sign_ascii (p);
2236  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
2237  return 1;
2238  }
2239  p = f->data + f->size - 1;
2240  return ((*p & 0x0F) == 0x0D) ? -1 : 1;
2241  }
2242  return 0;
2243 }
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
#define COB_FIELD_TYPE(f)
Definition: common.h:662
static int cob_get_sign_ascii(unsigned char *p)
Definition: common.c:651
unsigned char * data
Definition: common.h:952
#define COB_FIELD_SIGN_SEPARATE(f)
Definition: common.h:644
#define COB_FIELD_NO_SIGN_NIBBLE(f)
Definition: common.h:651
#define unlikely(x)
Definition: common.h:437
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
#define COB_MODULE_PTR
Definition: coblocal.h:185
static int cob_get_sign_ebcdic(unsigned char *p)
Definition: common.c:747
size_t size
Definition: common.h:951
#define COB_FIELD_SIGN_LEADING(f)
Definition: common.h:645

Here is the call graph for this function:

void cob_real_put_sign ( cob_field f,
const int  sign 
)

Definition at line 2246 of file common.c.

References COB_FIELD_NO_SIGN_NIBBLE, COB_FIELD_SIGN_LEADING, COB_FIELD_SIGN_SEPARATE, COB_FIELD_TYPE, COB_MODULE_PTR, cob_put_sign_ascii(), cob_put_sign_ebcdic(), COB_TYPE_NUMERIC_DISPLAY, COB_TYPE_NUMERIC_PACKED, cob_u8_t, cob_field::data, cob_field::size, and unlikely.

2247 {
2248  unsigned char *p;
2249  unsigned char c;
2250 
2251  switch (COB_FIELD_TYPE (f)) {
2253  /* Locate sign */
2254  if (unlikely(COB_FIELD_SIGN_LEADING (f))) {
2255  p = f->data;
2256  } else {
2257  p = f->data + f->size - 1;
2258  }
2259 
2260  /* Put sign */
2261  if (unlikely(COB_FIELD_SIGN_SEPARATE (f))) {
2262  c = (sign < 0) ? (cob_u8_t)'-' : (cob_u8_t)'+';
2263  if (*p != c) {
2264  *p = c;
2265  }
2266  } else if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
2268  } else if (sign < 0) {
2269  cob_put_sign_ascii (p);
2270  }
2271  return;
2273  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
2274  return;
2275  }
2276  p = f->data + f->size - 1;
2277  if (sign < 0) {
2278  *p = (*p & 0xF0) | 0x0D;
2279  } else {
2280  *p = (*p & 0xF0) | 0x0C;
2281  }
2282  return;
2283  }
2284 }
static void cob_put_sign_ebcdic(unsigned char *p, const int sign)
Definition: common.c:821
#define COB_TYPE_NUMERIC_PACKED
Definition: common.h:609
#define COB_FIELD_TYPE(f)
Definition: common.h:662
unsigned char * data
Definition: common.h:952
#define cob_u8_t
Definition: common.h:27
#define COB_FIELD_SIGN_SEPARATE(f)
Definition: common.h:644
#define COB_FIELD_NO_SIGN_NIBBLE(f)
Definition: common.h:651
#define unlikely(x)
Definition: common.h:437
if sign
Definition: flag.def:42
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951
static void cob_put_sign_ascii(unsigned char *p)
Definition: common.c:699
#define COB_FIELD_SIGN_LEADING(f)
Definition: common.h:645

Here is the call graph for this function:

void* cob_realloc ( void *  optr,
const size_t  osize,
const size_t  nsize 
)

Definition at line 1262 of file common.c.

References cob_fatal_error(), COB_FERROR_FREE, COB_FERROR_MEMORY, cob_free(), and unlikely.

Referenced by cob_expand_env_string(), and cob_load_config_file().

1263 {
1264  void *mptr;
1265 
1266  if (unlikely(!optr)) {
1268  }
1269 
1270  if (unlikely(osize <= nsize)) {
1271  return realloc (optr, nsize);
1272  }
1273 
1274  mptr = calloc ((size_t)1, nsize);
1275  if (unlikely(!mptr)) {
1277  }
1278  memcpy (mptr, optr, osize);
1279  cob_free (optr);
1280  return mptr;
1281 }
void cob_free(void *mptr)
Definition: common.c:1284
void cob_fatal_error(const int fatal_error)
Definition: common.c:1601
#define unlikely(x)
Definition: common.h:437
#define COB_FERROR_FREE
Definition: common.h:703
#define COB_FERROR_MEMORY
Definition: common.h:697

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_reg_sighnd ( void(*)(int)  sighnd)

Definition at line 2288 of file common.c.

References cob_ext_sighdl.

2289 {
2290  cob_ext_sighdl = sighnd;
2291 }
static void(* cob_ext_sighdl)(int)
Definition: common.c:172
static void cob_rescan_env_vals ( void  )
static

Definition at line 1099 of file common.c.

References __cob_settings::cob_extended_status, cob_malloc(), cob_source_file, cob_source_line, __cob_settings::cob_use_esc, config_tbl::data_type, GRP_HIDE, NULL, NUM_CONFIG, config_tbl::set_by, set_config_val(), and STS_ENVSET.

Referenced by cob_display_env_value(), cob_load_config(), and cob_putenv().

1100 {
1101  int i, j, old_type;
1102  char *env, *sv_src_file;
1103 
1104  sv_src_file = (char*)cob_source_file;
1106  cob_source_line = 0;
1107  /* Check for possible environment variables */
1108  for (i=0; i < NUM_CONFIG; i++) {
1109  if(gc_conf[i].env_name
1110  && (env = getenv(gc_conf[i].env_name)) != NULL) {
1111  old_type = gc_conf[i].data_type;
1113  if(*env != 0 /* If *env -> Nul then ignore this */
1114  && set_config_val(env,i)) {
1115  gc_conf[i].data_type = old_type;
1116 
1117  /* Remove invalid setting */
1118 #if HAVE_SETENV
1119  (void)unsetenv(gc_conf[i].env_name);
1120 #else
1121  env = cob_malloc(strlen(gc_conf[i].env_name)+2);
1122  sprintf(env,"%s=",gc_conf[i].env_name);
1123  (void)putenv(env);
1124 #endif
1125  } else {
1126  if(gc_conf[i].env_group == GRP_HIDE) {
1127  for (j=0; j < NUM_CONFIG; j++) {/* Any alias present? */
1128  if(j != i
1129  && gc_conf[i].data_loc == gc_conf[j].data_loc) {
1131  gc_conf[j].set_by = i;
1132  }
1133  }
1134  }
1135  }
1136  }
1137  }
1138  cob_source_file = sv_src_file;
1139 
1140  /* Extended ACCEPT status returns */
1141  if (cobsetptr->cob_extended_status == 0) {
1142  cobsetptr->cob_use_esc = 0;
1143  }
1144 }
int set_by
Definition: coblocal.h:285
unsigned int cob_use_esc
Definition: coblocal.h:247
static unsigned int cob_source_line
Definition: common.c:156
static cob_settings * cobsetptr
Definition: common.c:131
int data_type
Definition: coblocal.h:281
static struct config_tbl gc_conf[]
Definition: common.c:235
#define GRP_HIDE
Definition: coblocal.h:306
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int set_config_val(char *value, int pos)
Definition: common.c:4503
#define STS_ENVSET
Definition: coblocal.h:300
static const char * cob_source_file
Definition: common.c:153
unsigned int cob_extended_status
Definition: coblocal.h:246
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define NUM_CONFIG
Definition: common.c:283

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_reset_trace ( void  )

Definition at line 1468 of file common.c.

References __cob_settings::cob_line_trace.

1469 {
1471 }
static cob_settings * cobsetptr
Definition: common.c:131
unsigned int cob_line_trace
Definition: coblocal.h:206
void cob_restore_func ( struct cob_func_loc fl)

Definition at line 1879 of file common.c.

References __cob_global::cob_call_params, cob_free(), COB_MODULE_PTR, cob_func_loc::data, cob_func_loc::func_params, cob_func_loc::save_call_params, cob_func_loc::save_module, cob_func_loc::save_num_params, and cob_func_loc::save_proc_parms.

1880 {
1881  /* Restore calling environment */
1883 #if 0 /* RXWRXW - MODNEXT */
1884  COB_MODULE_PTR->next = fl->save_module;
1885 #endif
1886  COB_MODULE_PTR->cob_procedure_params = fl->save_proc_parms;
1887  COB_MODULE_PTR->module_num_params = fl->save_num_params;
1888  cob_free (fl->data);
1889  cob_free (fl->func_params);
1890  cob_free (fl);
1891 }
void cob_free(void *mptr)
Definition: common.c:1284
cob_module * save_module
Definition: common.h:1092
int cob_call_params
Definition: common.h:1204
int save_call_params
Definition: common.h:1093
#define COB_MODULE_PTR
Definition: coblocal.h:185
int save_num_params
Definition: common.h:1094
cob_field ** save_proc_parms
Definition: common.h:1089
static cob_global * cobglobptr
Definition: common.c:130
cob_field ** func_params
Definition: common.h:1090
unsigned char ** data
Definition: common.h:1091

Here is the call graph for this function:

void cob_runtime_error ( const char *  fmt,
  ... 
)

Definition at line 1543 of file common.c.

References _, cob_exit_screen(), cob_free(), cob_source_file, cob_source_line, hdlrs, handlerlist::next, NULL, handlerlist::proc, and runtime_err_str.

Referenced by cob_call(), cob_call_error(), cob_cancel(), cob_check_based(), cob_check_linkage(), cob_check_numeric(), cob_check_odo(), cob_check_ref_mod(), cob_check_subscript(), cob_check_version(), cob_command_line(), cob_external_addr(), cob_fatal_error(), cob_get_sort_tempfile(), cob_longjmp(), cob_parameter_check(), cob_resolve_func(), cob_savenv(), cob_screen_init(), cob_sys_check_file_exist(), cob_sys_file_info(), cob_sys_getopt_long_long(), and cob_sys_system().

1544 {
1545  struct handlerlist *h;
1546  struct handlerlist *hp;
1547  char *p;
1548  va_list ap;
1549 
1550 #if 1 /* RXWRXW - Exit screen */
1551  /* Exit screen mode early */
1552  cob_exit_screen ();
1553 #endif
1554 
1555  if (hdlrs != NULL) {
1556  if (runtime_err_str) {
1557  p = runtime_err_str;
1558  if (cob_source_file) {
1559  sprintf (runtime_err_str, "%s: %u: ",
1561  p = runtime_err_str + strlen (runtime_err_str);
1562  }
1563  va_start (ap, fmt);
1564  vsprintf (p, fmt, ap);
1565  va_end (ap);
1566  }
1567  h = hdlrs;
1568  while (h != NULL) {
1569  if (runtime_err_str) {
1570  h->proc (runtime_err_str);
1571  } else {
1572  h->proc ((char *)_("Malloc error"));
1573  }
1574  hp = h;
1575  h = h->next;
1576  cob_free (hp);
1577  }
1578  hdlrs = NULL;
1579  }
1580 
1581  /* Prefix */
1582  if (cob_source_file) {
1583  fprintf (stderr, "%s: ", cob_source_file);
1584  if (cob_source_line) {
1585  fprintf (stderr, "%u: ", cob_source_line);
1586  }
1587  }
1588  fputs ("libcob: ", stderr);
1589 
1590  /* Body */
1591  va_start (ap, fmt);
1592  vfprintf (stderr, fmt, ap);
1593  va_end (ap);
1594 
1595  /* Postfix */
1596  putc ('\n', stderr);
1597  fflush (stderr);
1598 }
void cob_free(void *mptr)
Definition: common.c:1284
int(* proc)(char *s)
Definition: common.c:212
static unsigned int cob_source_line
Definition: common.c:156
static struct handlerlist * hdlrs
#define _(s)
Definition: cobcrun.c:59
struct handlerlist * next
Definition: common.c:211
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_exit_screen(void)
Definition: screenio.c:2401
static const char * cob_source_file
Definition: common.c:153
static char * runtime_err_str
Definition: common.c:133

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_save_env_value ( char *  env_var,
char *  env_val 
)

Definition at line 4319 of file common.c.

References cob_fast_malloc(), cob_free(), and NULL.

4320 {
4321  if (!env_val) return NULL;
4322 
4323  if (env_var) cob_free(env_var);
4324  env_var = (char*) cob_fast_malloc(strlen(env_val) + 1);
4325  strcpy(env_var, env_val);
4326 
4327  return env_var;
4328 }
void cob_free(void *mptr)
Definition: common.c:1284
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296

Here is the call graph for this function:

void* cob_save_func ( cob_field **  savefld,
const int  params,
const int  eparams,
  ... 
)

Definition at line 1835 of file common.c.

References __cob_global::cob_call_params, cob_malloc(), COB_MODULE_PTR, cob_field::data, cob_func_loc::data, cob_func_loc::func_params, params, cob_func_loc::save_call_params, cob_func_loc::save_module, cob_func_loc::save_num_params, cob_func_loc::save_proc_parms, and unlikely.

1837 {
1838  struct cob_func_loc *fl;
1839  va_list args;
1840  int numparams;
1841  int n;
1842 
1843  if (unlikely(params > eparams)) {
1844  numparams = eparams;
1845  } else {
1846  numparams = params;
1847  }
1848 
1849  /* Allocate return field */
1850  *savefld = cob_malloc (sizeof (cob_field));
1851  /* Allocate save area */
1852  fl = cob_malloc (sizeof(struct cob_func_loc));
1853  fl->func_params = cob_malloc (sizeof(void *) * ((size_t)numparams + 1U));
1854  fl->data = cob_malloc (sizeof(void *) * ((size_t)numparams + 1U));
1855 
1856  /* Save values */
1857  fl->save_module = COB_MODULE_PTR->next;
1859  fl->save_proc_parms = COB_MODULE_PTR->cob_procedure_params;
1860  fl->save_num_params = COB_MODULE_PTR->module_num_params;
1861 
1862  /* Set current values */
1863  COB_MODULE_PTR->cob_procedure_params = fl->func_params;
1864  cobglobptr->cob_call_params = numparams;
1865  if (numparams) {
1866  va_start (args, eparams);
1867  for (n = 0; n < numparams; ++n) {
1868  fl->func_params[n] = va_arg (args, cob_field *);
1869  if (fl->func_params[n]) {
1870  fl->data[n] = fl->func_params[n]->data;
1871  }
1872  }
1873  va_end (args);
1874  }
1875  return fl;
1876 }
cob_module * save_module
Definition: common.h:1092
unsigned char * data
Definition: common.h:952
int cob_call_params
Definition: common.h:1204
int save_call_params
Definition: common.h:1093
#define unlikely(x)
Definition: common.h:437
#define COB_MODULE_PTR
Definition: coblocal.h:185
int save_num_params
Definition: common.h:1094
cob_field ** save_proc_parms
Definition: common.h:1089
void * cob_malloc(const size_t size)
Definition: common.c:1250
static cob_global * cobglobptr
Definition: common.c:130
cob_field ** func_params
Definition: common.h:1090
strict implicit external call params
Definition: warning.def:60
unsigned char ** data
Definition: common.h:1091

Here is the call graph for this function:

void cob_set_environment ( const cob_field f1,
const cob_field f2 
)

Definition at line 3018 of file common.c.

References cob_display_env_value(), and cob_display_environment().

Referenced by GCic_().

3019 {
3021  cob_display_env_value (f2);
3022 }
void cob_display_environment(const cob_field *f)
Definition: common.c:2959
void cob_display_env_value(const cob_field *f)
Definition: common.c:2981

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_set_exception ( const int  id)

Definition at line 1212 of file common.c.

References cob_current_paragraph, cob_current_program_id, cob_current_section, __cob_global::cob_exception_code, cob_exception_tab_code, __cob_global::cob_got_exception, __cob_global::cob_orig_line, __cob_global::cob_orig_paragraph, __cob_global::cob_orig_program_id, __cob_global::cob_orig_section, __cob_global::cob_orig_statement, cob_source_line, cob_source_statement, and NULL.

Referenced by cob_accept(), cob_accept_arg_value(), cob_accept_environment(), cob_alloc_field(), cob_allocate(), cob_call_field(), cob_check_odo(), cob_check_pos_status(), cob_check_ref_mod(), cob_check_subscript(), cob_decimal_div(), cob_decimal_do_round(), cob_decimal_get_binary(), cob_decimal_get_display(), cob_decimal_get_field(), cob_decimal_get_ieee128dec(), cob_decimal_get_ieee64dec(), cob_decimal_get_packed(), cob_decimal_pow(), cob_display_arg_number(), cob_display_env_value(), cob_free_alloc(), cob_get_environment(), cob_inspect_converting(), cob_inspect_init(), cob_intr_acos(), cob_intr_annuity(), cob_intr_asin(), cob_intr_atan(), cob_intr_binop(), cob_intr_combined_datetime(), cob_intr_cos(), cob_intr_currency_symbol(), cob_intr_date_of_integer(), cob_intr_date_to_yyyymmdd(), cob_intr_day_of_integer(), cob_intr_day_to_yyyyddd(), cob_intr_exp(), cob_intr_exp10(), cob_intr_factorial(), cob_intr_formatted_current_date(), cob_intr_formatted_date(), cob_intr_formatted_datetime(), cob_intr_formatted_time(), cob_intr_highest_algebraic(), cob_intr_integer_of_date(), cob_intr_integer_of_day(), cob_intr_lcl_time_from_secs(), cob_intr_locale_compare(), cob_intr_locale_date(), cob_intr_locale_time(), cob_intr_log(), cob_intr_log10(), cob_intr_lowest_algebraic(), cob_intr_mon_decimal_point(), cob_intr_mon_thousands_sep(), cob_intr_num_decimal_point(), cob_intr_num_thousands_sep(), cob_intr_numval_f(), cob_intr_seconds_from_formatted_time(), cob_intr_sin(), cob_intr_sqrt(), cob_intr_standard_deviation(), cob_intr_tan(), cob_intr_year_to_yyyy(), cob_mod_or_rem(), cob_resolve_cobol(), cob_resolve_internal(), cob_set_locale(), cob_string_append(), cob_string_init(), cob_unstring_finish(), cob_unstring_init(), format_time(), inspect_common(), numval(), raise_ec_on_invalid_line_or_col(), raise_ec_on_truncation(), save_status(), and set_resolve_error().

1213 {
1222  } else {
1229  }
1230 }
unsigned int cob_orig_line
Definition: common.h:1206
const char * cob_orig_paragraph
Definition: common.h:1192
static unsigned int cob_source_line
Definition: common.c:156
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static const char * cob_current_paragraph
Definition: common.c:152
const char * cob_orig_section
Definition: common.h:1191
const char * cob_orig_statement
Definition: common.h:1189
unsigned int cob_got_exception
Definition: common.h:1207
static const char * cob_current_program_id
Definition: common.c:150
static const char * cob_source_statement
Definition: common.c:154
const char * cob_orig_program_id
Definition: common.h:1190
int cob_exception_code
Definition: common.h:1203
static cob_global * cobglobptr
Definition: common.c:130
static const char * cob_current_section
Definition: common.c:151
static const int cob_exception_tab_code[]
Definition: common.c:188
void cob_set_locale ( cob_field locale,
const int  category 
)

Definition at line 4165 of file common.c.

References COB_EC_LOCALE_MISSING, cob_field_to_string(), cob_free(), COB_LC_ALL, COB_LC_CLASS, COB_LC_COLLATE, COB_LC_CTYPE, COB_LC_MESSAGES, COB_LC_MONETARY, COB_LC_NUMERIC, COB_LC_TIME, COB_LC_USER, __cob_global::cob_locale, __cob_global::cob_locale_ctype, __cob_global::cob_locale_orig, cob_malloc(), cob_set_exception(), cob_strdup(), NULL, and cob_field::size.

4166 {
4167 #ifdef HAVE_SETLOCALE
4168  char *p;
4169  char *buff;
4170 
4171  p = NULL;
4172  if (locale) {
4173  if (locale->size == 0) {
4174  return;
4175  }
4176  buff = cob_malloc (locale->size + 1U);
4177  cob_field_to_string (locale, buff, locale->size);
4178  } else {
4179  buff = NULL;
4180  }
4181 
4182  switch (category) {
4183  case COB_LC_COLLATE:
4184  p = setlocale (LC_COLLATE, buff);
4185  break;
4186  case COB_LC_CTYPE:
4187  p = setlocale (LC_CTYPE, buff);
4188  break;
4189 #ifdef LC_MESSAGES
4190  case COB_LC_MESSAGES:
4191  p = setlocale (LC_MESSAGES, buff);
4192  break;
4193 #endif
4194  case COB_LC_MONETARY:
4195  p = setlocale (LC_MONETARY, buff);
4196  break;
4197  case COB_LC_NUMERIC:
4198  p = setlocale (LC_NUMERIC, buff);
4199  break;
4200  case COB_LC_TIME:
4201  p = setlocale (LC_TIME, buff);
4202  break;
4203  case COB_LC_ALL:
4204  p = setlocale (LC_ALL, buff);
4205  break;
4206  case COB_LC_USER:
4207  if (cobglobptr->cob_locale_orig) {
4208  p = setlocale (LC_ALL, cobglobptr->cob_locale_orig);
4209  (void)setlocale (LC_NUMERIC, "C");
4210  }
4211  break;
4212  case COB_LC_CLASS:
4214  p = setlocale (LC_CTYPE, cobglobptr->cob_locale_ctype);
4215  }
4216  break;
4217  }
4218  if (buff) {
4219  cob_free (buff);
4220  }
4221  if (!p) {
4223  return;
4224  }
4225  p = setlocale (LC_ALL, NULL);
4226  if (p) {
4227  if (cobglobptr->cob_locale) {
4229  }
4231  }
4232 #else
4234 #endif
4235 }
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_LC_MESSAGES
Definition: common.h:592
#define COB_LC_ALL
Definition: common.h:596
#define COB_LC_NUMERIC
Definition: common.h:594
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_LC_CLASS
Definition: common.h:598
void cob_set_exception(const int id)
Definition: common.c:1212
#define COB_LC_TIME
Definition: common.h:595
#define COB_LC_COLLATE
Definition: common.h:590
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
char * cob_locale_orig
Definition: common.h:1195
size_t size
Definition: common.h:951
void * cob_malloc(const size_t size)
Definition: common.c:1250
#define COB_LC_USER
Definition: common.h:597
static cob_global * cobglobptr
Definition: common.c:130
char * cob_locale
Definition: common.h:1194
#define COB_LC_CTYPE
Definition: common.h:591
#define COB_LC_MONETARY
Definition: common.h:593
char * cob_locale_ctype
Definition: common.h:1196
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

void cob_set_location ( const char *  sfile,
const unsigned int  sline,
const char *  csect,
const char *  cpara,
const char *  cstatement 
)

Definition at line 1388 of file common.c.

References cob_check_trace_file(), cob_current_paragraph, cob_current_program_id, cob_current_section, cob_free(), cob_last_sfile, __cob_settings::cob_line_trace, COB_MODULE_PTR, cob_source_file, cob_source_line, cob_source_statement, cob_strdup(), and cob_trace_file.

Referenced by CHECKSRC_(), cobxref_(), GCic_(), get__reserved__lists_(), and LISTING_().

1391 {
1392  const char *s;
1393 
1394  cob_current_program_id = COB_MODULE_PTR->module_name;
1395  cob_source_file = sfile;
1396  cob_source_line = sline;
1397  cob_current_section = csect;
1398  cob_current_paragraph = cpara;
1399  if (cstatement) {
1400  cob_source_statement = cstatement;
1401  }
1402  if (cobsetptr->cob_line_trace) {
1403  if (!cob_trace_file) {
1405  if (!cob_trace_file) return; /* silence warnings */
1406  }
1407  if (!cob_last_sfile || strcmp (cob_last_sfile, sfile)) {
1408  if (cob_last_sfile) {
1409  cob_free((void *)cob_last_sfile);
1410  }
1411  cob_last_sfile = cob_strdup (sfile);
1412  fprintf (cob_trace_file, "Source : '%s'\n", sfile);
1413  }
1414  if (COB_MODULE_PTR->module_name) {
1415  s = COB_MODULE_PTR->module_name;
1416  } else {
1417  s = "Unknown";
1418  }
1419  fprintf (cob_trace_file,
1420  "Program-Id: %-16s Statement: %-21.21s Line: %u\n",
1421  s, cstatement ? (char *)cstatement : "Unknown",
1422  sline);
1423  fflush (cob_trace_file);
1424  }
1425 }
void cob_free(void *mptr)
Definition: common.c:1284
static FILE * cob_trace_file
Definition: common.c:155
static unsigned int cob_source_line
Definition: common.c:156
static cob_settings * cobsetptr
Definition: common.c:131
static const char * cob_last_sfile
Definition: common.c:128
unsigned int cob_line_trace
Definition: coblocal.h:206
static const char * cob_current_paragraph
Definition: common.c:152
#define COB_MODULE_PTR
Definition: coblocal.h:185
static const char * cob_current_program_id
Definition: common.c:150
static const char * cob_source_file
Definition: common.c:153
static const char * cob_source_statement
Definition: common.c:154
static const char * cob_current_section
Definition: common.c:151
static void cob_check_trace_file(void)
Definition: common.c:1056
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

static void cob_set_signal ( void  )
static

Definition at line 549 of file common.c.

References NULL.

Referenced by cob_init().

550 {
551 #ifdef HAVE_SIGNAL_H
552 
553 #ifdef HAVE_SIGACTION
554  struct sigaction sa;
555  struct sigaction osa;
556 
557  memset (&sa, 0, sizeof(sa));
558  sa.sa_handler = cob_sig_handler;
559 #ifdef SA_RESETHAND
560  sa.sa_flags = SA_RESETHAND;
561 #else
562  sa.sa_flags = 0;
563 #endif
564 #ifdef SA_NOCLDSTOP
565  sa.sa_flags |= SA_NOCLDSTOP;
566 #endif
567 
568 #ifdef SIGINT
569  (void)sigaction (SIGINT, NULL, &osa);
570  if (osa.sa_handler != SIG_IGN) {
571  (void)sigemptyset (&sa.sa_mask);
572  (void)sigaction (SIGINT, &sa, NULL);
573  }
574 #endif
575 #ifdef SIGHUP
576  (void)sigaction (SIGHUP, NULL, &osa);
577  if (osa.sa_handler != SIG_IGN) {
578  (void)sigemptyset (&sa.sa_mask);
579  (void)sigaction (SIGHUP, &sa, NULL);
580  }
581 #endif
582 #ifdef SIGQUIT
583  (void)sigaction (SIGQUIT, NULL, &osa);
584  if (osa.sa_handler != SIG_IGN) {
585  (void)sigemptyset (&sa.sa_mask);
586  (void)sigaction (SIGQUIT, &sa, NULL);
587  }
588 #endif
589 #ifdef SIGTERM
590  (void)sigaction (SIGTERM, NULL, &osa);
591  if (osa.sa_handler != SIG_IGN) {
592  (void)sigemptyset (&sa.sa_mask);
593  (void)sigaction (SIGTERM, &sa, NULL);
594  }
595 #endif
596 #ifdef SIGPIPE
597  (void)sigaction (SIGPIPE, NULL, &osa);
598  if (osa.sa_handler != SIG_IGN) {
599  (void)sigemptyset (&sa.sa_mask);
600  (void)sigaction (SIGPIPE, &sa, NULL);
601  }
602 #endif
603 #ifdef SIGSEGV
604  /* Take direct control of segmentation violation */
605  (void)sigemptyset (&sa.sa_mask);
606  (void)sigaction (SIGSEGV, &sa, NULL);
607 #endif
608 
609 #else
610 
611 #ifdef SIGINT
612  if (signal (SIGINT, SIG_IGN) != SIG_IGN) {
613  (void)signal (SIGINT, cob_sig_handler);
614  }
615 #endif
616 #ifdef SIGHUP
617  if (signal (SIGHUP, SIG_IGN) != SIG_IGN) {
618  (void)signal (SIGHUP, cob_sig_handler);
619  }
620 #endif
621 #ifdef SIGQUIT
622  if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) {
623  (void)signal (SIGQUIT, cob_sig_handler);
624  }
625 #endif
626 #ifdef SIGTERM
627  if (signal (SIGTERM, SIG_IGN) != SIG_IGN) {
628  (void)signal (SIGTERM, cob_sig_handler);
629  }
630 #endif
631 #ifdef SIGPIPE
632  if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) {
633  (void)signal (SIGPIPE, cob_sig_handler);
634  }
635 #endif
636 #ifdef SIGSEGV
637  /* Take direct control of segmentation violation */
638  (void)signal (SIGSEGV, cob_sig_handler);
639 #endif
640 
641 #endif
642 #endif
643 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the caller graph for this function:

void cob_set_switch ( const int  n,
const int  flag 
)

Definition at line 2305 of file common.c.

References cob_switch, and COB_SWITCH_MAX.

2306 {
2307  if (n < 0 || n > COB_SWITCH_MAX) {
2308  return;
2309  }
2310  if (flag == 0) {
2311  cob_switch[n] = 0;
2312  } else if (flag == 1) {
2313  cob_switch[n] = 1;
2314  }
2315 }
static int cob_switch[36+1]
Definition: common.c:201
#define COB_SWITCH_MAX
Definition: common.c:199
void cob_stop_run ( const int  status)

Definition at line 1524 of file common.c.

References cob_initialized, cob_terminate_routines(), exit_hdlrs, exit_handlerlist::next, NULL, and exit_handlerlist::proc.

Referenced by cob_call(), cob_call_error(), cob_cancel(), cob_check_based(), cob_check_linkage(), cob_check_numeric(), cob_check_odo(), cob_check_ref_mod(), cob_check_subscript(), cob_check_version(), cob_command_line(), cob_external_addr(), cob_fatal_error(), cob_get_sort_tempfile(), cob_init(), cob_longjmp(), cob_parameter_check(), cob_resolve_func(), cob_savenv(), cob_screen_init(), cob_sys_check_file_exist(), cob_sys_file_info(), cob_sys_getopt_long_long(), cob_sys_system(), GCic_(), and main().

1525 {
1526  struct exit_handlerlist *h;
1527 
1528  if (!cob_initialized) {
1529  exit (1);
1530  }
1531  if (exit_hdlrs != NULL) {
1532  h = exit_hdlrs;
1533  while (h != NULL) {
1534  h->proc ();
1535  h = h->next;
1536  }
1537  }
1539  exit (status);
1540 }
struct exit_handlerlist * next
Definition: common.c:205
static struct exit_handlerlist * exit_hdlrs
int(* proc)(void)
Definition: common.c:206
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int cob_initialized
Definition: common.c:124
static void cob_terminate_routines(void)
Definition: common.c:406

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_strcat ( char *  str1,
char *  str2 
)

Definition at line 4270 of file common.c.

References cob_fast_malloc(), cob_free(), cob_strdup(), and strbuff.

Referenced by cache_preload(), cob_strjoin(), and var_print().

4271 {
4272  size_t l;
4273  char *temp1, *temp2;
4274 
4275  l = strlen (str1) + strlen (str2) + 1;
4276 
4277  /*
4278  * If one of the parameter is the buffer itself,
4279  * we copy the buffer before continuing.
4280  */
4281  if (str1 == strbuff) {
4282  temp1 = cob_strdup (str1);
4283  } else {
4284  temp1 = str1;
4285  }
4286  if (str2 == strbuff) {
4287  temp2 = cob_strdup (str2);
4288  } else {
4289  temp2 = str2;
4290  }
4291 
4292  if (strbuff) {
4293  cob_free (strbuff);
4294  }
4295  strbuff = (char*) cob_fast_malloc(l);
4296 
4297  sprintf (strbuff, "%s%s", temp1, temp2);
4298  return strbuff;
4299 }
void cob_free(void *mptr)
Definition: common.c:1284
static char * strbuff
Definition: common.c:158
void * cob_fast_malloc(const size_t size)
Definition: common.c:1296
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_strdup ( const char *  p)

Definition at line 1308 of file common.c.

References cob_malloc().

Referenced by cache_dynload(), cache_preload(), cob_chk_call_path(), cob_chk_file_env(), cob_chk_file_mapping(), cob_expand_env_string(), cob_getenv(), cob_gettmpdir(), cob_init(), cob_init_call(), cob_putenv(), cob_set_locale(), cob_set_location(), cob_strcat(), cob_trace_section(), indexed_open(), insert(), and var_print().

1309 {
1310  char *mptr;
1311  size_t len;
1312 
1313  len = strlen (p);
1314  mptr = (char *) cob_malloc (len + 1U);
1315  memcpy (mptr, p, len);
1316  return mptr;
1317 }
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

Here is the caller graph for this function:

char* cob_strjoin ( char **  strarray,
int  size,
char *  separator 
)

Definition at line 4302 of file common.c.

References cob_strcat(), and NULL.

4303 {
4304  char *result;
4305  int i;
4306 
4307  if(!strarray || size <= 0 || !separator) return NULL;
4308 
4309  result = strarray[0];
4310  for (i = 1; i < size; i++) {
4311  result = cob_strcat(result, separator);
4312  result = cob_strcat(result, strarray[i]);
4313  }
4314 
4315  return result;
4316 }
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
char * cob_strcat(char *str1, char *str2)
Definition: common.c:4270

Here is the call graph for this function:

int cob_sys_and ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3522 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3523 {
3524  const cob_u8_ptr data_1 = p1;
3525  cob_u8_ptr data_2 = p2;
3526  size_t n;
3527 
3528  COB_CHK_PARMS (CBL_AND, 3);
3529 
3530  if (length <= 0) {
3531  return 0;
3532  }
3533  for (n = 0; n < (size_t)length; ++n) {
3534  data_2[n] &= data_1[n];
3535  }
3536  return 0;
3537 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_calledby ( void *  data)

Definition at line 3841 of file common.c.

References COB_CHK_PARMS, and COB_MODULE_PTR.

3842 {
3843  size_t size;
3844  size_t msize;
3845 
3846  COB_CHK_PARMS (C$CALLEDBY, 1);
3847 
3848  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
3849  /* check what ACU ccbl/runcbl returns,
3850  the documentation doesn't say anything about this */
3851  return -1;
3852  }
3853  size = COB_MODULE_PTR->cob_procedure_params[0]->size;
3854  memset (data, ' ', size);
3855  if (!COB_MODULE_PTR->next) {
3856  return 0;
3857  }
3858  msize = strlen (COB_MODULE_PTR->next->module_name);
3859  if (msize > size) {
3860  msize = size;
3861  }
3862  memcpy (data, COB_MODULE_PTR->next->module_name, msize);
3863  return 1;
3864 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define COB_MODULE_PTR
Definition: coblocal.h:185
int cob_sys_eq ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3630 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3631 {
3632  const cob_u8_ptr data_1 = p1;
3633  cob_u8_ptr data_2 = p2;
3634  size_t n;
3635 
3636  COB_CHK_PARMS (CBL_EQ, 3);
3637 
3638  if (length <= 0) {
3639  return 0;
3640  }
3641  for (n = 0; n < (size_t)length; ++n) {
3642  data_2[n] = ~(data_1[n] ^ data_2[n]);
3643  }
3644  return 0;
3645 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_error_proc ( const void *  dispo,
const void *  pptr 
)

Definition at line 3381 of file common.c.

References COB_CHK_PARMS, cob_free(), cob_malloc(), hdlrs, handlerlist::next, NULL, and handlerlist::proc.

3382 {
3383  struct handlerlist *hp = NULL;
3384  struct handlerlist *h = hdlrs;
3385  const unsigned char *x;
3386  int (**p)(char *s);
3387 
3388  COB_CHK_PARMS (CBL_ERROR_PROC, 2);
3389 
3390  memcpy (&p, &pptr, sizeof (void *));
3391  if (!p || !*p) {
3392  return -1;
3393  }
3394 
3395  hp = NULL;
3396  h = hdlrs;
3397  /* Remove handler anyway */
3398  while (h != NULL) {
3399  if (h->proc == *p) {
3400  if (hp != NULL) {
3401  hp->next = h->next;
3402  } else {
3403  hdlrs = h->next;
3404  }
3405  if (hp) {
3406  cob_free (hp);
3407  }
3408  break;
3409  }
3410  hp = h;
3411  h = h->next;
3412  }
3413  x = dispo;
3414  if (*x != 0) {
3415  /* Remove handler */
3416  return 0;
3417  }
3418  h = cob_malloc (sizeof(struct handlerlist));
3419  h->next = hdlrs;
3420  h->proc = *p;
3421  hdlrs = h;
3422  return 0;
3423 }
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
int(* proc)(char *s)
Definition: common.c:212
static struct handlerlist * hdlrs
struct handlerlist * next
Definition: common.c:211
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

int cob_sys_exit_proc ( const void *  dispo,
const void *  pptr 
)

Definition at line 3336 of file common.c.

References COB_CHK_PARMS, cob_free(), cob_malloc(), exit_hdlrs, exit_handlerlist::next, NULL, and exit_handlerlist::proc.

3337 {
3338  struct exit_handlerlist *hp;
3339  struct exit_handlerlist *h;
3340  const unsigned char *x;
3341  int (**p)(void);
3342 
3343  COB_CHK_PARMS (CBL_EXIT_PROC, 2);
3344 
3345  memcpy (&p, &pptr, sizeof (void *));
3346  if (!p || !*p) {
3347  return -1;
3348  }
3349 
3350  hp = NULL;
3351  h = exit_hdlrs;
3352  /* Remove handler anyway */
3353  while (h != NULL) {
3354  if (h->proc == *p) {
3355  if (hp != NULL) {
3356  hp->next = h->next;
3357  } else {
3358  exit_hdlrs = h->next;
3359  }
3360  if (hp) {
3361  cob_free (hp);
3362  }
3363  break;
3364  }
3365  hp = h;
3366  h = h->next;
3367  }
3368  x = dispo;
3369  if (*x != 0 && *x != 2 && *x != 3) {
3370  /* Remove handler */
3371  return 0;
3372  }
3373  h = cob_malloc (sizeof(struct exit_handlerlist));
3374  h->next = exit_hdlrs;
3375  h->proc = *p;
3376  exit_hdlrs = h;
3377  return 0;
3378 }
void cob_free(void *mptr)
Definition: common.c:1284
struct exit_handlerlist * next
Definition: common.c:205
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
static struct exit_handlerlist * exit_hdlrs
int(* proc)(void)
Definition: common.c:206
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

int cob_sys_getopt_long_long ( void *  so,
void *  lo,
void *  idx,
const int  long_only,
void *  return_char,
void *  opt_val 
)

Definition at line 3889 of file common.c.

References _, cob_argc, cob_argv, COB_CHK_PARMS, cob_field_to_string(), cob_free(), cob_get_int(), cob_getopt_long_long(), cob_malloc(), COB_MODULE_PTR, cob_optarg, cob_runtime_error(), cob_set_int(), cob_stop_run(), COB_UNUSED, option::flag, option::has_arg, longoption_def::has_option, option::name, longoption_def::name, NULL, longoption_def::return_value, longoption_def::return_value_pointer, and option::val.

3889  {
3890  /*
3891  * cob_argc is a static int containing argc from runtime
3892  * cob_argv is a static char** containing argv from runtime
3893  */
3894 
3895  size_t opt_val_size = 0;
3896  size_t so_size = 0;
3897  size_t lo_size = 0;
3898  size_t optlen;
3899 
3900  unsigned int lo_amount;
3901 
3902  int exit_status;
3903 
3904  char* shortoptions;
3905  char* temp;
3906 
3907  struct option* longoptions;
3908  longoption_def* l = NULL;
3909 
3910  int longind = 0;
3911  unsigned int i;
3912  int j;
3913 
3914  int return_value;
3915 
3916  COB_UNUSED (idx);
3917  COB_UNUSED (lo);
3918  COB_UNUSED (so);
3919 
3920  COB_CHK_PARMS (CBL_OC_GETOPT, 6);
3921 
3922  /*
3923  * Read in sizes of some parameters
3924  */
3925  if (COB_MODULE_PTR->cob_procedure_params[1]) {
3926  lo_size = COB_MODULE_PTR->cob_procedure_params[1]->size;
3927  }
3928  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3929  so_size = COB_MODULE_PTR->cob_procedure_params[0]->size;
3930  }
3931  if (COB_MODULE_PTR->cob_procedure_params[5]) {
3932  opt_val_size = COB_MODULE_PTR->cob_procedure_params[5]->size;
3933  }
3934 
3935  /*
3936  * Buffering longoptions (cobol), target format (struct option)
3937  */
3938  if (lo_size % sizeof(longoption_def) == 0) {
3939  lo_amount = (int)lo_size / sizeof(longoption_def);
3940  longoptions = (struct option*) cob_malloc(sizeof(struct option) * (lo_amount + 1U));
3941  }
3942  else {
3943  cob_runtime_error (_("Call to CBL_OC_GETOPT with wrong longoption size."));
3944  cob_stop_run (1);
3945  }
3946 
3947  if (!COB_MODULE_PTR->cob_procedure_params[2]) {
3948  cob_runtime_error (_("Call to CBL_OC_GETOPT with missing longind."));
3949  cob_stop_run (1);
3950  }
3951  longind = cob_get_int (COB_MODULE_PTR->cob_procedure_params[2]);
3952 
3953  /*
3954  * Add 0-termination to strings.
3955  */
3956  shortoptions = cob_malloc(so_size + 1U);
3957  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3958  cob_field_to_string (COB_MODULE_PTR->cob_procedure_params[0], shortoptions, so_size);
3959  }
3960 
3961  if (COB_MODULE_PTR->cob_procedure_params[1]) {
3962  l = (struct longoption_def*) (COB_MODULE_PTR->cob_procedure_params[1]->data);
3963  }
3964 
3965  for (i = 0; i < lo_amount; i++) {
3966  j = sizeof(l->name) - 1;
3967  while (j >= 0 && l->name[j] == 0x20) {
3968  l->name[j] = 0x00;
3969  j--;
3970  }
3971  longoptions->name = l->name;
3972  longoptions->has_arg = (int) l->has_option - '0';
3973  memcpy (&longoptions->flag, l->return_value_pointer, sizeof(l->return_value_pointer));
3974  memcpy(&longoptions->val, &l->return_value, 4);
3975 
3976  l = l + 1; /* +1 means pointer + 1*sizeof(longoption_def) */
3977  longoptions = longoptions + 1;
3978  }
3979 
3980  /*
3981  * Appending final record, so getopt can spot the end of longoptions
3982  */
3983  longoptions->name = NULL;
3984  longoptions->has_arg = 0;
3985  longoptions->flag = NULL;
3986  longoptions->val = 0;
3987 
3988 
3989  l -= lo_amount; /* Set pointer back to begin of longoptions */
3990  longoptions -= lo_amount;
3991 
3992  return_value = cob_getopt_long_long(cob_argc, cob_argv, shortoptions, longoptions, &longind, long_only);
3993  temp = (char*) &return_value;
3994 
3995  /*
3996  * Write data back to COBOL
3997  */
3998  if (temp[0] == '?' || temp[0] == ':' || temp[0] == 'W'
3999  || temp[0] == -1 || temp[0] == 0) exit_status = return_value;
4000  else exit_status = 3;
4001 
4002  for(i = 3; i > 0; i--) {
4003  if(temp[i] == 0x00) temp[i] = 0x20;
4004  else break;
4005  }
4006 
4007  cob_set_int (COB_MODULE_PTR->cob_procedure_params[2], longind);
4008  memcpy (return_char, &return_value, 4);
4009 
4010  if(cob_optarg != NULL) {
4011  memset (opt_val, 0x00, opt_val_size);
4012 
4013  optlen = strlen (cob_optarg);
4014  if (optlen > opt_val_size) {
4015  /* Returncode 2 for "Optionvalue too long => cut" */
4016  optlen = opt_val_size;
4017  exit_status = 2;
4018  }
4019  memcpy (opt_val, cob_optarg, optlen);
4020  }
4021 
4022 
4023  cob_free (shortoptions);
4024  cob_free (longoptions);
4025 
4026  return exit_status;
4027 
4028 }
void cob_free(void *mptr)
Definition: common.c:1284
char return_value_pointer[sizeof(char *)]
Definition: common.h:1364
char has_option
Definition: common.h:1363
int cob_getopt_long_long(const int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, const int long_only)
Definition: cobgetopt.c:321
int val
Definition: cobgetopt.h:87
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
int cob_get_int(cob_field *)
Definition: move.c:1626
char name[25]
Definition: common.h:1362
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
const char * name
Definition: cobgetopt.h:82
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
#define COB_MODULE_PTR
Definition: coblocal.h:185
void cob_field_to_string(const cob_field *f, void *str, const size_t maxsize)
Definition: common.c:1492
int * flag
Definition: cobgetopt.h:86
void * cob_malloc(const size_t size)
Definition: common.c:1250
char return_value[4]
Definition: common.h:1365
#define COB_UNUSED(z)
Definition: common.h:535
int has_arg
Definition: cobgetopt.h:85
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
char * cob_optarg
Definition: cobgetopt.c:77
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

int cob_sys_getpid ( void  )

Definition at line 3818 of file common.c.

References cob_process_id.

Referenced by cob_temp_name().

3819 {
3820  if (!cob_process_id) {
3821  cob_process_id = (int)getpid ();
3822  }
3823  return cob_process_id;
3824 }
static int cob_process_id
Definition: common.c:160

Here is the caller graph for this function:

int cob_sys_hosted ( void *  p,
const void *  var 
)

Return some hosted C variables, argc, argv, stdin, stdout, stderr.

Definition at line 3465 of file common.c.

References cob_argc, cob_argv, COB_CHK_PARMS, COB_MODULE_PTR, and cob_u8_ptr.

3466 {
3467  const char *name = var;
3468  cob_u8_ptr data = p;
3469  size_t i;
3470 
3471  COB_CHK_PARMS (CBL_OC_HOSTED, 2);
3472 
3473  if (!data) {
3474  return 1;
3475  }
3476 
3477  if (COB_MODULE_PTR->cob_procedure_params[1]) {
3478  i = (int)COB_MODULE_PTR->cob_procedure_params[1]->size;
3479  if ((i == 4) && !strncmp (name, "argc", 4)) {
3480  *((int *)data) = cob_argc;
3481  return 0;
3482  }
3483  if ((i == 4) && !strncmp (name, "argv", 4)) {
3484  *((char ***)data) = cob_argv;
3485  return 0;
3486  }
3487  if ((i == 5) && !strncmp (name, "stdin", 5)) {
3488  *((FILE **)data) = stdin;
3489  return 0;
3490  }
3491  if ((i == 6) && !strncmp (name, "stdout", 6)) {
3492  *((FILE **)data) = stdout;
3493  return 0;
3494  }
3495  if ((i == 6) && !strncmp (name, "stderr", 6)) {
3496  *((FILE **)data) = stderr;
3497  return 0;
3498  }
3499  if ((i == 5) && !strncmp (name, "errno", 5)) {
3500  *((int **)data) = &errno;
3501  return 0;
3502  }
3503 #if defined(HAVE_TIMEZONE)
3504  if ((i == 6) && !strncmp (name, "tzname", 6)) {
3505  *((char ***)data) = tzname;
3506  return 0;
3507  }
3508  if ((i == 8) && !strncmp (name, "timezone", 8)) {
3509  *((long *)data) = timezone;
3510  return 0;
3511  }
3512  if ((i == 8) && !strncmp (name, "daylight", 8)) {
3513  *((int *)data) = daylight;
3514  return 0;
3515  }
3516 #endif
3517  }
3518  return 1;
3519 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
static int cob_argc
Definition: common.c:125
static char ** cob_argv
Definition: common.c:126
char name[25]
Definition: common.h:1362
#define cob_u8_ptr
Definition: common.h:66
#define COB_MODULE_PTR
Definition: coblocal.h:185
int cob_sys_imp ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3594 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3595 {
3596  const cob_u8_ptr data_1 = p1;
3597  cob_u8_ptr data_2 = p2;
3598  size_t n;
3599 
3600  COB_CHK_PARMS (CBL_IMP, 3);
3601 
3602  if (length <= 0) {
3603  return 0;
3604  }
3605  for (n = 0; n < (size_t)length; ++n) {
3606  data_2[n] = (~data_1[n]) | data_2[n];
3607  }
3608  return 0;
3609 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_justify ( void *  p1,
  ... 
)

Definition at line 4086 of file common.c.

References __cob_global::cob_call_params, COB_CHK_PARMS, COB_MODULE_PTR, and cob_u8_ptr.

Referenced by LISTING_().

4087 {
4088  cob_u8_ptr data;
4089  unsigned char *direction;
4090  size_t datalen;
4091  size_t left;
4092  size_t right;
4093  size_t movelen;
4094  size_t centrelen;
4095  size_t n;
4096  size_t shifting;
4097  va_list args;
4098 
4099  COB_CHK_PARMS (C$JUSTIFY, 1);
4100 
4101  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
4102  return 0;
4103  }
4104  data = p1;
4105  datalen = COB_MODULE_PTR->cob_procedure_params[0]->size;
4106  if (datalen < 2) {
4107  return 0;
4108  }
4109  if (data[0] != ' ' && data[datalen - 1] != ' ') {
4110  return 0;
4111  }
4112  for (left = 0; left < datalen; ++left) {
4113  if (data[left] != ' ') {
4114  break;
4115  }
4116  }
4117  if (left == datalen) {
4118  return 0;
4119  }
4120  right = 0;
4121  for (n = datalen - 1; ; --n, ++right) {
4122  if (data[n] != ' ') {
4123  break;
4124  }
4125  if (n == 0) {
4126  break;
4127  }
4128  }
4129  movelen = datalen - left - right;
4130  shifting = 0;
4131  if (cobglobptr->cob_call_params > 1) {
4132  va_start (args, p1);
4133  direction = va_arg (args, unsigned char *);
4134  va_end (args);
4135  if (*direction == 'L') {
4136  shifting = 1;
4137  } else if (*direction == 'C') {
4138  shifting = 2;
4139  }
4140  }
4141  switch (shifting) {
4142  case 1:
4143  memmove (data, &data[left], movelen);
4144  memset (&data[movelen], ' ', datalen - movelen);
4145  break;
4146  case 2:
4147  centrelen = (left + right) / 2;
4148  memmove (&data[centrelen], &data[left], movelen);
4149  memset (data, ' ', centrelen);
4150  if ((left + right) % 2) {
4151  memset (&data[centrelen + movelen], ' ', centrelen + 1);
4152  } else {
4153  memset (&data[centrelen + movelen], ' ', centrelen);
4154  }
4155  break;
4156  default:
4157  memmove (&data[left + right], &data[left], movelen);
4158  memset (data, ' ', datalen - movelen);
4159  break;
4160  }
4161  return 0;
4162 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
int cob_call_params
Definition: common.h:1204
#define cob_u8_ptr
Definition: common.h:66
#define COB_MODULE_PTR
Definition: coblocal.h:185
static cob_global * cobglobptr
Definition: common.c:130

Here is the caller graph for this function:

int cob_sys_nimp ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3612 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3613 {
3614  const cob_u8_ptr data_1 = p1;
3615  cob_u8_ptr data_2 = p2;
3616  size_t n;
3617 
3618  COB_CHK_PARMS (CBL_NIMP, 3);
3619 
3620  if (length <= 0) {
3621  return 0;
3622  }
3623  for (n = 0; n < (size_t)length; ++n) {
3624  data_2[n] = data_1[n] & (~data_2[n]);
3625  }
3626  return 0;
3627 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_nor ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3558 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3559 {
3560  const cob_u8_ptr data_1 = p1;
3561  cob_u8_ptr data_2 = p2;
3562  size_t n;
3563 
3564  COB_CHK_PARMS (CBL_NOR, 3);
3565 
3566  if (length <= 0) {
3567  return 0;
3568  }
3569  for (n = 0; n < (size_t)length; ++n) {
3570  data_2[n] = ~(data_1[n] | data_2[n]);
3571  }
3572  return 0;
3573 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_not ( void *  p1,
const int  length 
)

Definition at line 3648 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3649 {
3650  cob_u8_ptr data_1 = p1;
3651  size_t n;
3652 
3653  COB_CHK_PARMS (CBL_NOT, 2);
3654 
3655  if (length <= 0) {
3656  return 0;
3657  }
3658  for (n = 0; n < (size_t)length; ++n) {
3659  data_1[n] = ~data_1[n];
3660  }
3661  return 0;
3662 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_oc_nanosleep ( const void *  data)

Definition at line 3774 of file common.c.

References COB_CHK_PARMS, cob_get_llint(), COB_MODULE_PTR, cob_s64_t, COB_UNUSED, and NULL.

3775 {
3776  cob_s64_t nsecs;
3777 #if defined(_WIN32) || defined(__370__) || defined(__OS400__)
3778  unsigned int msecs;
3779 #elif defined(HAVE_NANO_SLEEP)
3780  struct timespec tsec;
3781 #else
3782  unsigned int msecs;
3783 #endif
3784 
3785  COB_UNUSED (data);
3786 
3787  COB_CHK_PARMS (CBL_OC_NANOSLEEP, 1);
3788 
3789  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3790  nsecs = cob_get_llint (COB_MODULE_PTR->cob_procedure_params[0]);
3791  if (nsecs > 0) {
3792 #ifdef _WIN32
3793  msecs = (unsigned int)(nsecs / 1000000);
3794  if (msecs > 0) {
3795  Sleep (msecs);
3796  }
3797 #elif defined(__370__) || defined(__OS400__)
3798  msecs = (unsigned int)(nsecs / 1000000000);
3799  if (msecs > 0) {
3800  sleep (msecs);
3801  }
3802 #elif defined(HAVE_NANO_SLEEP)
3803  tsec.tv_sec = nsecs / 1000000000;
3804  tsec.tv_nsec = nsecs % 1000000000;
3805  nanosleep (&tsec, NULL);
3806 #else
3807  msecs = (unsigned int)(nsecs / 1000000000);
3808  if (msecs > 0) {
3809  sleep (msecs);
3810  }
3811 #endif
3812  }
3813  }
3814  return 0;
3815 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_s64_t
Definition: common.h:51
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_UNUSED(z)
Definition: common.h:535
long long cob_get_llint(cob_field *)
Definition: move.c:1656

Here is the call graph for this function:

int cob_sys_or ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3540 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3541 {
3542  const cob_u8_ptr data_1 = p1;
3543  cob_u8_ptr data_2 = p2;
3544  size_t n;
3545 
3546  COB_CHK_PARMS (CBL_OR, 3);
3547 
3548  if (length <= 0) {
3549  return 0;
3550  }
3551  for (n = 0; n < (size_t)length; ++n) {
3552  data_2[n] |= data_1[n];
3553  }
3554  return 0;
3555 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_parameter_size ( void *  data)

Definition at line 3867 of file common.c.

References COB_CHK_PARMS, cob_get_int(), COB_MODULE_PTR, and COB_UNUSED.

3868 {
3869  int n;
3870 
3871  COB_UNUSED (data);
3872 
3873  COB_CHK_PARMS (C$PARAMSIZE, 1);
3874 
3875  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3876  n = cob_get_int (COB_MODULE_PTR->cob_procedure_params[0]);
3877  if (n > 0 && n <= COB_MODULE_PTR->module_num_params) {
3878  n--;
3879  if (COB_MODULE_PTR->next &&
3880  COB_MODULE_PTR->next->cob_procedure_params[n]) {
3881  return (int)COB_MODULE_PTR->next->cob_procedure_params[n]->size;
3882  }
3883  }
3884  }
3885  return 0;
3886 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
int cob_get_int(cob_field *)
Definition: move.c:1626
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_UNUSED(z)
Definition: common.h:535

Here is the call graph for this function:

int cob_sys_printable ( void *  p1,
  ... 
)

Definition at line 4053 of file common.c.

References __cob_global::cob_call_params, COB_CHK_PARMS, COB_MODULE_PTR, and cob_u8_ptr.

4054 {
4055  cob_u8_ptr data;
4056  unsigned char *dotptr;
4057  size_t datalen;
4058  size_t n;
4059  unsigned char dotrep;
4060  va_list args;
4061 
4062  COB_CHK_PARMS (C$PRINTABLE, 1);
4063 
4064  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
4065  return 0;
4066  }
4067  data = p1;
4068  datalen = COB_MODULE_PTR->cob_procedure_params[0]->size;
4069  if (cobglobptr->cob_call_params > 1) {
4070  va_start (args, p1);
4071  dotptr = va_arg (args, unsigned char *);
4072  va_end (args);
4073  dotrep = *dotptr;
4074  } else {
4075  dotrep = (unsigned char)'.';
4076  }
4077  for (n = 0; n < datalen; ++n) {
4078  if (!isprint (data[n])) {
4079  data[n] = dotrep;
4080  }
4081  }
4082  return 0;
4083 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
int cob_call_params
Definition: common.h:1204
#define cob_u8_ptr
Definition: common.h:66
#define COB_MODULE_PTR
Definition: coblocal.h:185
static cob_global * cobglobptr
Definition: common.c:130
int cob_sys_return_args ( void *  data)

Definition at line 3827 of file common.c.

References COB_CHK_PARMS, COB_MODULE_PTR, cob_set_int(), and COB_UNUSED.

3828 {
3829  COB_UNUSED (data);
3830 
3831  COB_CHK_PARMS (C$NARG, 1);
3832 
3833  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3834  cob_set_int (COB_MODULE_PTR->cob_procedure_params[0],
3835  COB_MODULE_PTR->module_num_params);
3836  }
3837  return 0;
3838 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_UNUSED(z)
Definition: common.h:535

Here is the call graph for this function:

int cob_sys_sleep ( const void *  data)

Definition at line 4031 of file common.c.

References COB_CHK_PARMS, cob_get_int(), COB_MODULE_PTR, and COB_UNUSED.

Referenced by GCic_().

4032 {
4033  int n;
4034 
4035  COB_UNUSED (data);
4036 
4037  COB_CHK_PARMS (C$SLEEP, 1);
4038 
4039  if (COB_MODULE_PTR->cob_procedure_params[0]) {
4040  n = cob_get_int (COB_MODULE_PTR->cob_procedure_params[0]);
4041  if (n > 0 && n < 3600*24*7) {
4042 #ifdef _WIN32
4043  Sleep (n*1000);
4044 #else
4045  sleep ((unsigned int)n);
4046 #endif
4047  }
4048  }
4049  return 0;
4050 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
int cob_get_int(cob_field *)
Definition: move.c:1626
#define COB_MODULE_PTR
Definition: coblocal.h:185
#define COB_UNUSED(z)
Definition: common.h:535

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_sys_system ( const void *  cmdline)

Definition at line 3426 of file common.c.

References _, COB_CHK_PARMS, cob_free(), cob_malloc(), COB_MEDIUM_MAX, COB_MODULE_PTR, cob_runtime_error(), __cob_global::cob_screen_initialized, cob_screen_set_mode(), cob_stop_run(), and unlikely.

Referenced by GCic_(), and get__reserved__lists_().

3427 {
3428  const char *cmd;
3429  char *buff;
3430  int i;
3431 
3432  COB_CHK_PARMS (SYSTEM, 1);
3433 
3434  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3435  cmd = cmdline;
3436  i = (int)COB_MODULE_PTR->cob_procedure_params[0]->size;
3437  if (unlikely(i > COB_MEDIUM_MAX)) {
3438  cob_runtime_error (_("Parameter to SYSTEM call is larger than %d characters"), COB_MEDIUM_MAX);
3439  cob_stop_run (1);
3440  }
3441  i--;
3442  for (; i >= 0; --i) {
3443  if (cmd[i] != ' ' && cmd[i] != 0) {
3444  break;
3445  }
3446  }
3447  if (i >= 0) {
3448  buff = cob_malloc ((size_t)(i + 2));
3449  memcpy (buff, cmd, (size_t)(i + 1));
3451  cob_screen_set_mode (0);
3452  }
3453  i = system (buff);
3454  cob_free (buff);
3456  cob_screen_set_mode (1U);
3457  }
3458  return i;
3459  }
3460  }
3461  return 1;
3462 }
void cob_free(void *mptr)
Definition: common.c:1284
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
#define COB_MODULE_PTR
Definition: coblocal.h:185
unsigned int cob_screen_initialized
Definition: common.h:1208
void cob_screen_set_mode(const cob_u32_t)
Definition: screenio.c:2388
void * cob_malloc(const size_t size)
Definition: common.c:1250
static cob_global * cobglobptr
Definition: common.c:130
#define COB_MEDIUM_MAX
Definition: common.h:549
void cob_runtime_error(const char *fmt,...)
Definition: common.c:1543
void cob_stop_run(const int status)
Definition: common.c:1524

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_sys_tolower ( void *  p1,
const int  length 
)

Definition at line 3756 of file common.c.

References COB_CHK_PARMS, cob_u8_ptr, and cob_u8_t.

3757 {
3758  cob_u8_ptr data = p1;
3759  size_t n;
3760 
3761  COB_CHK_PARMS (CBL_TOLOWER, 2);
3762 
3763  if (length > 0) {
3764  for (n = 0; n < (size_t)length; ++n) {
3765  if (isupper (data[n])) {
3766  data[n] = (cob_u8_t)tolower (data[n]);
3767  }
3768  }
3769  }
3770  return 0;
3771 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_t
Definition: common.h:27
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_toupper ( void *  p1,
const int  length 
)

Definition at line 3738 of file common.c.

References COB_CHK_PARMS, cob_u8_ptr, and cob_u8_t.

3739 {
3740  cob_u8_ptr data = p1;
3741  size_t n;
3742 
3743  COB_CHK_PARMS (CBL_TOUPPER, 2);
3744 
3745  if (length > 0) {
3746  for (n = 0; n < (size_t)length; ++n) {
3747  if (islower (data[n])) {
3748  data[n] = (cob_u8_t)toupper (data[n]);
3749  }
3750  }
3751  }
3752  return 0;
3753 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_t
Definition: common.h:27
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_x91 ( void *  p1,
const void *  p2,
void *  p3 
)

Definition at line 3696 of file common.c.

References COB_MODULE_PTR, cob_switch, and cob_u8_ptr.

3697 {
3698  cob_u8_ptr result = p1;
3699  const cob_u8_ptr func = p2;
3700  cob_u8_ptr parm = p3;
3701  unsigned char *p;
3702  size_t i;
3703 
3704  switch (*func) {
3705  case 11:
3706  /* Set switches */
3707  p = parm;
3708  for (i = 0; i < 8; ++i, ++p) {
3709  if (*p == 0) {
3710  cob_switch[i] = 0;
3711  } else if (*p == 1) {
3712  cob_switch[i] = 1;
3713  }
3714  }
3715  *result = 0;
3716  break;
3717  case 12:
3718  /* Get switches */
3719  p = parm;
3720  for (i = 0; i < 8; ++i, ++p) {
3721  *p = (unsigned char)cob_switch[i];
3722  }
3723  *result = 0;
3724  break;
3725  case 16:
3726  /* Return number of call parameters */
3727  *parm = (unsigned char)COB_MODULE_PTR->module_num_params;
3728  *result = 0;
3729  break;
3730  default:
3731  *result = 1;
3732  break;
3733  }
3734  return 0;
3735 }
#define cob_u8_ptr
Definition: common.h:66
#define COB_MODULE_PTR
Definition: coblocal.h:185
static int cob_switch[36+1]
Definition: common.c:201
int cob_sys_xf4 ( void *  p1,
const void *  p2 
)

Definition at line 3665 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3666 {
3667  cob_u8_ptr data_1 = p1;
3668  const cob_u8_ptr data_2 = p2;
3669  size_t n;
3670 
3671  COB_CHK_PARMS (CBL_XF4, 2);
3672 
3673  *data_1 = 0;
3674  for (n = 0; n < 8; ++n) {
3675  *data_1 |= (data_2[n] & 1) << (7 - n);
3676  }
3677  return 0;
3678 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_xf5 ( const void *  p1,
void *  p2 
)

Definition at line 3681 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3682 {
3683  const cob_u8_ptr data_1 = p1;
3684  cob_u8_ptr data_2 = p2;
3685  size_t n;
3686 
3687  COB_CHK_PARMS (CBL_XF5, 2);
3688 
3689  for (n = 0; n < 8; ++n) {
3690  data_2[n] = (*data_1 & (1 << (7 - n))) ? 1 : 0;
3691  }
3692  return 0;
3693 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
int cob_sys_xor ( const void *  p1,
void *  p2,
const int  length 
)

Definition at line 3576 of file common.c.

References COB_CHK_PARMS, and cob_u8_ptr.

3577 {
3578  const cob_u8_ptr data_1 = p1;
3579  cob_u8_ptr data_2 = p2;
3580  size_t n;
3581 
3582  COB_CHK_PARMS (CBL_XOR, 3);
3583 
3584  if (length <= 0) {
3585  return 0;
3586  }
3587  for (n = 0; n < (size_t)length; ++n) {
3588  data_2[n] ^= data_1[n];
3589  }
3590  return 0;
3591 }
#define COB_CHK_PARMS(x, z)
Definition: coblocal.h:167
#define cob_u8_ptr
Definition: common.h:66
void cob_table_sort ( cob_field f,
const int  n 
)

Definition at line 2516 of file common.c.

References cob_free(), cob_field::data, cob_field::size, and sort_compare().

Referenced by cobxref_().

2517 {
2518  qsort (f->data, (size_t) n, f->size, sort_compare);
2519  cob_free (sort_keys);
2520 }
void cob_free(void *mptr)
Definition: common.c:1284
static cob_file_key * sort_keys
Definition: common.c:147
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951
static int sort_compare(const void *data1, const void *data2)
Definition: common.c:1018

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_table_sort_init ( const size_t  nkeys,
const unsigned char *  collating_sequence 
)

Definition at line 2494 of file common.c.

References cob_malloc(), COB_MODULE_PTR, sort_collate, and sort_nkeys.

Referenced by cobxref_().

2495 {
2496  sort_nkeys = 0;
2497  sort_keys = cob_malloc (nkeys * sizeof (cob_file_key));
2498  if (collating_sequence) {
2499  sort_collate = collating_sequence;
2500  } else {
2501  sort_collate = COB_MODULE_PTR->collating_sequence;
2502  }
2503 }
static cob_file_key * sort_keys
Definition: common.c:147
#define COB_MODULE_PTR
Definition: coblocal.h:185
void * cob_malloc(const size_t size)
Definition: common.c:1250
static const unsigned char * sort_collate
Definition: common.c:148
static size_t sort_nkeys
Definition: common.c:146

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_table_sort_init_key ( cob_field field,
const int  flag,
const unsigned int  offset 
)

Definition at line 2506 of file common.c.

References cob_file_key::field, cob_file_key::flag, cob_file_key::offset, and sort_nkeys.

Referenced by cobxref_().

2508 {
2509  sort_keys[sort_nkeys].field = field;
2510  sort_keys[sort_nkeys].flag = flag;
2511  sort_keys[sort_nkeys].offset = offset;
2512  sort_nkeys++;
2513 }
static cob_file_key * sort_keys
Definition: common.c:147
unsigned int offset
Definition: common.h:1105
cob_field * field
Definition: common.h:1102
static size_t sort_nkeys
Definition: common.c:146

Here is the caller graph for this function:

void cob_temp_name ( char *  filename,
const char *  ext 
)

Definition at line 3253 of file common.c.

References COB_FILE_MAX, cob_gettmpdir(), cob_sys_getpid(), cob_temp_iteration, and SLASH_CHAR.

Referenced by cob_srttmpfile(), and process_filename().

3254 {
3255  /* Set temporary file name */
3256  if (ext) {
3257  snprintf (filename, (size_t)COB_FILE_MAX, "%s%ccob%d_%d%s",
3259  } else {
3260  snprintf (filename, (size_t)COB_FILE_MAX, "%s%ccobsort%d_%d",
3262  }
3263 }
static const char * cob_gettmpdir(void)
Definition: common.c:3210
#define SLASH_CHAR
Definition: common.h:505
static int cob_temp_iteration
Definition: common.c:161
Definition: cobc.h:195
#define COB_FILE_MAX
Definition: common.h:548
int cob_sys_getpid(void)
Definition: common.c:3818

Here is the call graph for this function:

Here is the caller graph for this function:

static void cob_terminate_routines ( void  )
static

Definition at line 406 of file common.c.

References cob_exit_call(), cob_exit_common(), cob_exit_fileio(), cob_exit_intrinsic(), cob_exit_numeric(), cob_exit_screen(), cob_exit_strings(), cob_initialized, cob_trace_file, and NULL.

Referenced by cob_stop_run(), and cob_tidy().

407 {
408  if (!cob_initialized) {
409  return;
410  }
411  if (!cobglobptr) {
412  return;
413  }
414 
415  if (cob_trace_file && cob_trace_file != stderr) {
416  fclose (cob_trace_file);
418  }
419 
420  cob_exit_screen ();
421  cob_exit_fileio ();
423  cob_exit_strings ();
424  cob_exit_numeric ();
425  cob_exit_call ();
426  cob_exit_common ();
427 }
static FILE * cob_trace_file
Definition: common.c:155
void cob_exit_call(void)
Definition: call.c:1204
void cob_exit_fileio(void)
Definition: fileio.c:6282
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static void cob_exit_common(void)
Definition: common.c:293
void cob_exit_screen(void)
Definition: screenio.c:2401
void cob_exit_numeric(void)
Definition: numeric.c:2637
static int cob_initialized
Definition: common.c:124
void cob_exit_intrinsic(void)
Definition: intrinsic.c:6521
void cob_exit_strings(void)
Definition: strings.c:634
static cob_global * cobglobptr
Definition: common.c:130

Here is the call graph for this function:

Here is the caller graph for this function:

int cob_tidy ( void  )

Definition at line 3315 of file common.c.

References cob_initialized, cob_terminate_routines(), exit_hdlrs, exit_handlerlist::next, NULL, and exit_handlerlist::proc.

3316 {
3317  struct exit_handlerlist *h;
3318 
3319  if (!cob_initialized) {
3320  exit (1);
3321  }
3322  if (exit_hdlrs != NULL) {
3323  h = exit_hdlrs;
3324  while (h != NULL) {
3325  h->proc ();
3326  h = h->next;
3327  }
3328  }
3330  return 0;
3331 }
struct exit_handlerlist * next
Definition: common.c:205
static struct exit_handlerlist * exit_hdlrs
int(* proc)(void)
Definition: common.c:206
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int cob_initialized
Definition: common.c:124
static void cob_terminate_routines(void)
Definition: common.c:406

Here is the call graph for this function:

void cob_trace_section ( const char *  para,
const char *  source,
const int  line 
)

Definition at line 1429 of file common.c.

References cob_check_trace_file(), cob_free(), cob_last_sfile, __cob_settings::cob_line_trace, COB_MODULE_PTR, cob_strdup(), and cob_trace_file.

1430 {
1431  const char *s;
1432 
1433  if (cobsetptr->cob_line_trace) {
1434  if (!cob_trace_file) {
1436  if (!cob_trace_file) return; /* silence warnings */
1437  }
1438  if (source &&
1439  (!cob_last_sfile || strcmp (cob_last_sfile, source))) {
1440  if (cob_last_sfile) {
1441  cob_free ((void *)cob_last_sfile);
1442  }
1443  cob_last_sfile = cob_strdup (source);
1444  fprintf (cob_trace_file, "Source: '%s'\n", source);
1445  }
1446  if (COB_MODULE_PTR->module_name) {
1447  s = COB_MODULE_PTR->module_name;
1448  } else {
1449  s = "Unknown";
1450  }
1451  fprintf (cob_trace_file, "Program-Id: %-16s ", s);
1452  if (line) {
1453  fprintf (cob_trace_file, "%-34.34sLine: %d\n", para, line);
1454  } else {
1455  fprintf (cob_trace_file, "%s\n", para);
1456  }
1457  fflush (cob_trace_file);
1458  }
1459 }
void cob_free(void *mptr)
Definition: common.c:1284
static FILE * cob_trace_file
Definition: common.c:155
static cob_settings * cobsetptr
Definition: common.c:131
static const char * cob_last_sfile
Definition: common.c:128
unsigned int cob_line_trace
Definition: coblocal.h:206
#define COB_MODULE_PTR
Definition: coblocal.h:185
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
static void cob_check_trace_file(void)
Definition: common.c:1056
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

static int common_cmpc ( const unsigned char *  s1,
const unsigned int  c,
const size_t  size,
const unsigned char *  col 
)
static

Definition at line 900 of file common.c.

References unlikely.

Referenced by cob_cmp_all(), and cob_cmp_alnum().

902 {
903  size_t i;
904  int ret;
905 
906  if (unlikely(col)) {
907  for (i = 0; i < size; ++i) {
908  if ((ret = col[s1[i]] - col[c]) != 0) {
909  return ret;
910  }
911  }
912  } else {
913  for (i = 0; i < size; ++i) {
914  if ((ret = s1[i] - c) != 0) {
915  return ret;
916  }
917  }
918  }
919  return 0;
920 }
#define unlikely(x)
Definition: common.h:437

Here is the caller graph for this function:

static int common_cmps ( const unsigned char *  s1,
const unsigned char *  s2,
const size_t  size,
const unsigned char *  col 
)
static

Definition at line 923 of file common.c.

References unlikely.

Referenced by cob_cmp_all(), cob_cmp_alnum(), and sort_compare().

925 {
926  size_t i;
927  int ret;
928 
929  if (unlikely(col)) {
930  for (i = 0; i < size; ++i) {
931  if ((ret = col[s1[i]] - col[s2[i]]) != 0) {
932  return ret;
933  }
934  }
935  } else {
936  for (i = 0; i < size; ++i) {
937  if ((ret = s1[i] - s2[i]) != 0) {
938  return ret;
939  }
940  }
941  }
942  return 0;
943 }
#define unlikely(x)
Definition: common.h:437

Here is the caller graph for this function:

void conf_runtime_error ( const int  finish_error,
const char *  fmt,
  ... 
)

Definition at line 1744 of file common.c.

References _, cob_source_file, cob_source_line, conf_runtime_error_displayed, last_runtime_error_file, and last_runtime_error_line.

Referenced by cb_config_entry(), cob_load_config_file(), conf_runtime_error_value(), and set_config_val().

1745 {
1746  va_list args;
1747 
1750  fputs(_("Configuration Error"), stderr);
1751  putc('\n', stderr);
1752  }
1753 
1754  /* Prefix */
1759  if (cob_source_file) {
1760  fprintf(stderr, "%s: ", cob_source_file);
1761  } else {
1762  fprintf(stderr, "%s", _("environment variables"));
1763  fprintf(stderr, ": ");
1764  }
1765  if (cob_source_line) {
1766  fprintf(stderr, "%u: ", cob_source_line);
1767  }
1768  }
1769 
1770  /* Body */
1771  va_start(args, fmt);
1772  vfprintf(stderr, fmt, args);
1773  va_end(args);
1774 
1775  /* Postfix */
1776  if (!finish_error) {
1777  putc(';', stderr);
1778  putc('\n', stderr);
1779  putc('\t', stderr);
1780  } else {
1781  putc('\n', stderr);
1782  fflush(stderr);
1783  }
1784 }
static unsigned int cob_source_line
Definition: common.c:156
static const char * last_runtime_error_file
Definition: common.c:165
#define _(s)
Definition: cobcrun.c:59
static const char * cob_source_file
Definition: common.c:153
static unsigned int conf_runtime_error_displayed
Definition: common.c:163
static unsigned int last_runtime_error_line
Definition: common.c:164

Here is the caller graph for this function:

void conf_runtime_error_value ( char *  value,
const int  conf_pos 
)

Definition at line 1731 of file common.c.

References _, config_tbl::conf_name, conf_runtime_error(), config_tbl::env_name, NULL, and STS_CNFSET.

Referenced by set_config_val().

1732 {
1733  const char *name = NULL;
1734 
1735  if (gc_conf[pos].data_type & STS_CNFSET) {
1736  name = gc_conf[pos].conf_name;
1737  } else {
1738  name = gc_conf[pos].env_name;
1739  }
1740  conf_runtime_error(0, _("Invalid value '%s' for configuration tag '%s'"), value, name);
1741 }
const char * conf_name
Definition: coblocal.h:277
void conf_runtime_error(const int finish_error, const char *fmt,...)
Definition: common.c:1744
const char * env_name
Definition: coblocal.h:276
static struct config_tbl gc_conf[]
Definition: common.c:235
strict implicit external value
Definition: warning.def:54
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define STS_CNFSET
Definition: coblocal.h:301

Here is the call graph for this function:

Here is the caller graph for this function:

static char * get_config_val ( char *  value,
int  pos,
char *  orgvalue 
)
static

Definition at line 4665 of file common.c.

References config_tbl::data_len, config_tbl::data_loc, config_tbl::data_type, config_tbl::enums, ENV_BOOL, ENV_CHAR, ENV_INT, ENV_NOT, ENV_PATH, ENV_SIZE, ENV_STR, get_value(), config_enum::match, NULL, numval(), and value.

Referenced by print_runtime_env().

4666 {
4667  void *data;
4668  char *str;
4669  double dval;
4670  long numval = 0;
4671  int i,data_type,data_loc,data_len;
4672 
4673  data_type = gc_conf[pos].data_type;
4674  data_loc = gc_conf[pos].data_loc;
4675  data_len = gc_conf[pos].data_len;
4676 
4677  data = (void*)((char *)cobsetptr + data_loc);
4678 
4679  strcpy(value,"Unknown");
4680  strcpy(orgvalue,"");
4681  if((data_type & ENV_INT)) { /* Integer data */
4682  numval = get_value((char *)data,data_len);
4683  sprintf(value,"%ld",numval);
4684 
4685  } else if((data_type & ENV_SIZE)) { /* Size: integer with K, M, G */
4686  numval = get_value((char *)data,data_len);
4687  dval = numval;
4688  if(numval > (1024 * 1024 * 1024)) {
4689  if((numval % (1024 * 1024 * 1024)) == 0)
4690  sprintf(value,"%ld GB",numval/(1024 * 1024 * 1024));
4691  else
4692  sprintf(value,"%.2f GB",dval/(1024.0 * 1024.0 * 1024.0));
4693  } else if(numval > (1024 * 1024)) {
4694  if((numval % (1024 * 1024)) == 0)
4695  sprintf(value,"%ld MB",numval/(1024 * 1024));
4696  else
4697  sprintf(value,"%.2f MB",dval/(1024.0 * 1024.0));
4698  } else if(numval > 1024) {
4699  if((numval % 1024) == 0)
4700  sprintf(value,"%ld KB",numval/1024);
4701  else
4702  sprintf(value,"%.2f KB",dval/1024.0);
4703  } else {
4704  sprintf(value,"%ld",numval);
4705  }
4706 
4707  } else if((data_type & ENV_BOOL)) { /* Boolean: Yes/No,True/False,... */
4708  numval = get_value((char *)data,data_len);
4709  if((data_type & ENV_NOT))
4710  numval = !numval;
4711  if(numval)
4712  strcpy(value,"true");
4713  else
4714  strcpy(value,"false");
4715 
4716  } else if((data_type & ENV_STR)) { /* String stored as a string */
4717  memcpy(&str,data,sizeof(char *));
4718  if(str == NULL)
4719  sprintf(value,"%s","not set");
4720  else
4721  sprintf(value,"'%s'",str);
4722 
4723  } else if((data_type & ENV_PATH)) { /* Path stored as a string */
4724  memcpy(&str,data,sizeof(char *));
4725  if(str == NULL)
4726  sprintf(value,"%s","not set");
4727  else
4728  sprintf(value,"%s",str);
4729 
4730  } else if((data_type & ENV_CHAR)) { /* 'char' field inline */
4731  if(*(char*)data == 0) {
4732  strcpy(value,"Nul");
4733  } else if(isprint(*(unsigned char*)data)) {
4734  sprintf(value,"'%s'",(char*)data);
4735  } else {
4736  sprintf(value,"0x%02X",*(char*)data);
4737  }
4738  }
4739 
4740  if(gc_conf[pos].enums) { /* Translate 'word' into alternate 'value' */
4741  for (i=0; gc_conf[pos].enums[i].match != NULL; i++) {
4742  if(strcasecmp(value,gc_conf[pos].enums[i].value) == 0) {
4743  if(strcmp(value,"0") != 0
4744  && strcmp(value,gc_conf[pos].default_val) != 0)
4745  strcpy(orgvalue,value);
4746  strcpy(value,gc_conf[pos].enums[i].match);
4747  break;
4748  }
4749  }
4750  }
4751  return value;
4752 }
#define ENV_PATH
Definition: coblocal.h:296
const char * match
Definition: coblocal.h:254
#define ENV_CHAR
Definition: coblocal.h:294
#define ENV_NOT
Definition: coblocal.h:290
static cob_field * numval(cob_field *srcfield, cob_field *currency, const enum numval_type type)
Definition: intrinsic.c:1456
static cob_settings * cobsetptr
Definition: common.c:131
int data_type
Definition: coblocal.h:281
static struct config_tbl gc_conf[]
Definition: common.c:235
#define ENV_SIZE
Definition: coblocal.h:292
strict implicit external value
Definition: warning.def:54
#define ENV_BOOL
Definition: coblocal.h:293
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int data_loc
Definition: coblocal.h:282
static long get_value(char *data, int len)
Definition: common.c:4488
#define ENV_INT
Definition: coblocal.h:291
struct config_enum * enums
Definition: coblocal.h:279
#define ENV_STR
Definition: coblocal.h:295
int data_len
Definition: coblocal.h:283

Here is the call graph for this function:

Here is the caller graph for this function:

static long get_value ( char *  data,
int  len 
)
static

Definition at line 4488 of file common.c.

Referenced by get_config_val().

4489 {
4490  if(len == sizeof(int)) {
4491  return (long)*(int*)data;
4492  } else if(len == sizeof(short)) {
4493  return (long)*(short*)data;
4494  } else if(len == sizeof(long)) {
4495  return (long)*(long*)data;
4496  } else {
4497  return (long)*(char*)data;
4498  }
4499 }

Here is the caller graph for this function:

static int one_indexed_day_of_week_from_monday ( int  zero_indexed_from_sunday)
static

Definition at line 1147 of file common.c.

Referenced by cob_get_current_date_and_time().

1148 {
1149  return ((zero_indexed_from_sunday + 6) % 7) + 1;
1150 }

Here is the caller graph for this function:

void print_info ( void  )

Definition at line 5153 of file common.c.

References _, COB_BLD_BUILD, COB_BLD_CC, COB_BLD_CFLAGS, COB_BLD_CPPFLAGS, COB_BLD_LD, COB_BLD_LDFLAGS, COB_EXEEXT, COB_MODULE_EXT, COB_OBJECT_EXT, NULL, OC_C_VERSION, OC_C_VERSION_PRF, print_version(), var_print(), WITH_CURSES, and WITH_VARSEQ.

Referenced by process_command_line().

5154 {
5155  char buff[16];
5156  char *s;
5157 
5158  print_version ();
5159  putchar ('\n');
5160  puts (_("Build information"));
5161  var_print (_("Build environment"), COB_BLD_BUILD, "", 0);
5162  var_print ("CC", COB_BLD_CC, "", 0);
5163  var_print ("CPPFLAGS", COB_BLD_CPPFLAGS, "", 0);
5164  var_print ("CFLAGS", COB_BLD_CFLAGS, "", 0);
5165  var_print ("LD", COB_BLD_LD, "", 0);
5166  var_print ("LDFLAGS", COB_BLD_LDFLAGS, "", 0);
5167  putchar ('\n');
5168  printf (_("C version %s%s"), OC_C_VERSION_PRF, OC_C_VERSION);
5169  putchar ('\n');
5170 
5171  puts (_("GnuCOBOL information"));
5172 
5173  var_print ("COB_MODULE_EXT", COB_MODULE_EXT, "", 0);
5174 #if 0 /* only relevant for cobc */
5175  var_print ("COB_OBJECT_EXT", COB_OBJECT_EXT, "", 0);
5176  var_print ("COB_EXEEXT", COB_EXEEXT, "", 0);
5177 #endif
5178 
5179 #if defined(USE_LIBDL) || defined(_WIN32)
5180  var_print (_("Dynamic loading"), _("System"), "", 0);
5181 #else
5182  var_print (_("Dynamic loading"), _("Libtool"), "", 0);
5183 #endif
5184 
5185 #ifdef COB_PARAM_CHECK
5186  var_print ("\"CBL_\" param check", _("Enabled"), "", 0);
5187 #else
5188  var_print ("\"CBL_\" param check", _("Disabled"), "", 0);
5189 #endif
5190 
5191  if (sizeof (void *) > 4U) {
5192  var_print ("64bit-mode", _("yes"), "", 0);
5193  } else {
5194  var_print ("64bit-mode", _("no"), "", 0);
5195  }
5196 
5197 #ifdef COB_LI_IS_LL
5198  var_print ("BINARY-C-LONG", _("8 bytes"), "", 0);
5199 #else
5200  var_print ("BINARY-C-LONG", _("4 bytes"), "", 0);
5201 #endif
5202 
5203  var_print (_("Extended screen I/O"), WITH_CURSES, "", 0);
5204 
5205  snprintf (buff, sizeof(buff), "%d", WITH_VARSEQ);
5206  var_print (_("Variable format"), buff, "", 0);
5207  if ((s = getenv ("COB_VARSEQ_FORMAT")) != NULL) {
5208  var_print ("COB_VARSEQ_FORMAT", s, "", 1);
5209  }
5210 
5211 #ifdef WITH_SEQRA_EXTFH
5212  var_print (_("Sequential handler"), _("External"), "", 0);
5213 #else
5214  var_print (_("Sequential handler"), _("Internal"), "", 0);
5215 #endif
5216 
5217 #if defined (WITH_INDEX_EXTFH)
5218  var_print (_("ISAM handler"), _("External"), "", 0);
5219 #elif defined (WITH_DB)
5220  var_print (_("ISAM handler"), "BDB", "", 0);
5221 #elif defined (WITH_CISAM)
5222  var_print (_("ISAM handler"), "C-ISAM" "", 0);
5223 #elif defined (WITH_DISAM)
5224  var_print (_("ISAM handler"), "D-ISAM", "", 0);
5225 #elif defined (WITH_VBISAM)
5226  var_print (_("ISAM handler"), "VBISAM", "", 0);
5227 #else
5228  var_print (_("ISAM handler"), _("Not available"), "", 0);
5229 #endif
5230 }
void print_version(void)
Definition: common.c:5119
#define WITH_VARSEQ
Definition: config.h:370
static void var_print(const char *msg, const char *val, const char *default_val, const unsigned int format)
Definition: common.c:4331
#define COB_BLD_CPPFLAGS
Definition: defaults.h:12
#define COB_MODULE_EXT
Definition: defaults.h:9
#define COB_BLD_LDFLAGS
Definition: defaults.h:15
#define COB_BLD_CC
Definition: defaults.h:11
#define OC_C_VERSION
Definition: common.c:102
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define WITH_CURSES
Definition: config.h:355
#define COB_BLD_LD
Definition: defaults.h:14
#define COB_BLD_CFLAGS
Definition: defaults.h:13
#define OC_C_VERSION_PRF
Definition: common.c:101
#define COB_BLD_BUILD
Definition: defaults.h:16
#define COB_EXEEXT
Definition: config.h:8
#define COB_OBJECT_EXT
Definition: defaults.h:10

Here is the call graph for this function:

Here is the caller graph for this function:

void print_runtime_env ( void  )

Definition at line 5234 of file common.c.

References _, __cob_settings::cob_config_file, __cob_settings::cob_config_num, COB_MEDIUM_BUFF, COB_MINI_BUFF, FUNC_NAME_IN_DEFAULT, get_config_val(), GRP_MAX, not_set, NULL, NUM_CONFIG, PACKAGE_NAME, PACKAGE_VERSION, PATCH_LEVEL, setting_group, STS_CNFSET, STS_ENVCLR, STS_ENVSET, STS_FNCSET, STS_RESET, and value.

Referenced by process_command_line().

5235 {
5236  unsigned int i,j,k,vl,dohdg,hdlen,plen;
5237  char value[COB_MEDIUM_BUFF],orgvalue[COB_MINI_BUFF];
5238 
5239  printf ("%s %s.%d ", PACKAGE_NAME, PACKAGE_VERSION, PATCH_LEVEL);
5240  puts (_("runtime environment"));
5241  if (cobsetptr->cob_config_file) {
5242  strcpy(value, _("via"));
5243  hdlen = (unsigned int)strlen(value) + 3;
5244 
5245  /* output path of main configuration file */
5246  printf(" %s ", value);
5247  plen = 80 - hdlen;
5248  strcpy(value, cobsetptr->cob_config_file[0]);
5249  vl = (unsigned int)strlen(value);
5250  for (k = 0; vl > plen; vl -= plen, k += plen) {
5251  printf("%.*s\n%-*s", plen, &value[k], hdlen, "");
5252  }
5253  printf("%s\n", &value[k]);
5254 
5255  /* output path of additional configuration files */
5256  for (i = 1; i < cobsetptr->cob_config_num; i++) {
5257  printf("%*d ", hdlen - 2, i);
5258  strcpy(value, cobsetptr->cob_config_file[i]);
5259  vl = (unsigned int)strlen(value);
5260  for (k = 0; vl > plen; vl -= plen, k += plen) {
5261  printf("%.*s\n%-*s", plen, &value[k], hdlen, "");
5262  }
5263  printf("%s\n", &value[k]);
5264  }
5265 
5266  }
5267  putchar('\n');
5268  strcpy(value,"todo");
5269  hdlen = 15;
5270  for (i=0; i < NUM_CONFIG; i++) {
5271  j = (unsigned int)strlen(gc_conf[i].env_name);
5272  if(j > hdlen)
5273  hdlen = j;
5274  j = (unsigned int)strlen(gc_conf[i].conf_name);
5275  if(j > hdlen)
5276  hdlen = j;
5277  }
5278 
5279  for (j=1; j < GRP_MAX; j++) {
5280  dohdg = 1;
5281  for (i=0; i < NUM_CONFIG; i++) {
5282  if(gc_conf[i].env_group == j) {
5283  if(dohdg) {
5284  dohdg = 0;
5285  if (j > 1) {
5286  putchar('\n');
5287  }
5288  printf(" %s\n",setting_group[j]);
5289  }
5290  /* Convert value back into string and display it */
5291  get_config_val(value,i,orgvalue);
5292  if((gc_conf[i].data_type & STS_ENVSET)
5293  || (gc_conf[i].data_type & STS_FNCSET)) {
5294  putchar(' ');
5295  if (gc_conf[i].data_type & STS_FNCSET) {
5296  printf(" ");
5297  } else if ((gc_conf[i].data_type & STS_CNFSET)) {
5298  printf("Ovr");
5299  } else {
5300  printf("env");
5301  }
5302  printf(": %-*s : ",hdlen,gc_conf[i].env_name);
5303  } else if((gc_conf[i].data_type & STS_CNFSET)) {
5304  if (gc_conf[i].config_num > 0) {
5305  printf(" %d ", gc_conf[i].config_num);
5306  } else {
5307  printf(" ");
5308  }
5309  if (gc_conf[i].set_by > 0) {
5310  printf(": %-*s : ", hdlen, gc_conf[i].env_name);
5311  } else {
5312  printf(": %-*s : ", hdlen, gc_conf[i].conf_name);
5313  }
5314  } else if(gc_conf[i].env_name) {
5315  if(gc_conf[i].config_num > 0){
5316  printf(" %d ",gc_conf[i].config_num);
5317  } else {
5318  printf(" ");
5319  }
5320  printf(": %-*s : ",hdlen,gc_conf[i].env_name);
5321  } else {
5322  printf(" : %-*s : ",hdlen,gc_conf[i].conf_name);
5323  }
5324  vl = (unsigned int)strlen(value);
5325  plen = 71 - hdlen;
5326  for (k = 0; vl > plen; vl -= plen, k += plen) {
5327  printf("%.*s\n %-*s : ", plen, &value[k], hdlen, "");
5328  }
5329  printf("%s",&value[k]);
5330  if (orgvalue[0] > ' ') {
5331  printf(" (%s)", orgvalue);
5332  }
5333  if (gc_conf[i].set_by > 0) {
5334  putchar(' ');
5335  if (gc_conf[i].set_by != FUNC_NAME_IN_DEFAULT) {
5336  printf(_("(set by %s)"), gc_conf[gc_conf[i].set_by].env_name);
5337  } else {
5338  printf(_("(set by %s)"), gc_conf[i].default_val);
5339  }
5340  }
5341  if(!(gc_conf[i].data_type & STS_ENVSET)
5342  && !(gc_conf[i].data_type & STS_CNFSET)
5343  && !(gc_conf[i].data_type & STS_FNCSET)) {
5344  putchar(' ');
5345  if ((gc_conf[i].data_type & STS_RESET)) {
5346  printf(_("(reset)"));
5347  } else if (strcmp(value, not_set) != 0) {
5348  printf(_("(default)"));
5349  }
5350  }
5351  putchar('\n');
5352  if ((gc_conf[i].data_type & STS_ENVCLR)) {
5353  puts(" : ");
5354  puts(_("... removed from environment"));
5355  }
5356  }
5357  }
5358  }
5359 
5360 
5361  /* checkme
5362 
5363  var_print ("resolve_path",
5364  cob_strjoin(&cobsetptr->cob_library_path, *(cobsetptr->resolve_size),
5365  (char*) PATHSEPS), not_set, 3);
5366  */
5367  //var_print ("base_preload_ptr",
5368  // cobsetptr->cob_preload_str, not_set, 3);
5369 
5370 
5371 #ifdef HAVE_SETLOCALE
5372  printf(" : %-*s : %s\n",hdlen,"LC_CTYPE", (char*) setlocale (LC_CTYPE, NULL));
5373  printf(" : %-*s : %s\n",hdlen,"LC_NUMERIC", (char*) setlocale (LC_NUMERIC, NULL));
5374  printf(" : %-*s : %s\n",hdlen,"LC_COLLATE", (char*) setlocale (LC_COLLATE, NULL));
5375 #ifdef LC_MESSAGES
5376  printf(" : %-*s : %s\n",hdlen,"LC_MESSAGES", (char*) setlocale (LC_MESSAGES, NULL));
5377 #endif
5378  printf(" : %-*s : %s\n",hdlen,"LC_MONETARY", (char*) setlocale (LC_MONETARY, NULL));
5379  printf(" : %-*s : %s\n",hdlen,"LC_TIME", (char*) setlocale (LC_TIME, NULL));
5380 #endif
5381 }
static char * get_config_val(char *value, int pos, char *orgvalue)
Definition: common.c:4665
#define COB_MINI_BUFF
Definition: common.h:539
#define COB_MEDIUM_BUFF
Definition: common.h:543
static cob_settings * cobsetptr
Definition: common.c:131
static struct config_tbl gc_conf[]
Definition: common.c:235
strict implicit external value
Definition: warning.def:54
#define PACKAGE_NAME
Definition: config.h:300
#define _(s)
Definition: cobcrun.c:59
#define STS_RESET
Definition: coblocal.h:303
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define STS_FNCSET
Definition: coblocal.h:304
#define STS_ENVCLR
Definition: coblocal.h:302
#define STS_ENVSET
Definition: coblocal.h:300
#define STS_CNFSET
Definition: coblocal.h:301
#define FUNC_NAME_IN_DEFAULT
Definition: common.c:284
#define GRP_MAX
Definition: coblocal.h:312
static char not_set[]
Definition: common.c:219
#define PACKAGE_VERSION
Definition: config.h:312
unsigned int cob_config_num
Definition: coblocal.h:208
#define NUM_CONFIG
Definition: common.c:283
#define PATCH_LEVEL
Definition: config.h:315
static const char * setting_group[]
Definition: common.c:215
char ** cob_config_file
Definition: coblocal.h:209

Here is the call graph for this function:

Here is the caller graph for this function:

void print_version ( void  )

Definition at line 5119 of file common.c.

References _, COB_MINI_BUFF, COB_MINI_MAX, COB_TAR_DATE, PACKAGE_NAME, PACKAGE_VERSION, and PATCH_LEVEL.

Referenced by print_info(), and process_command_line().

5120 {
5121  char cob_build_stamp[COB_MINI_BUFF];
5122  char month[64];
5123  int status, day, year;
5124 
5125  /* Set up build time stamp */
5126  memset (cob_build_stamp, 0, (size_t)COB_MINI_BUFF);
5127  memset (month, 0, sizeof(month));
5128  day = 0;
5129  year = 0;
5130  status = sscanf (__DATE__, "%s %d %d", month, &day, &year);
5131  if (status == 3) {
5132  snprintf (cob_build_stamp, (size_t)COB_MINI_MAX,
5133  "%s %2.2d %4.4d %s", month, day, year, __TIME__);
5134  } else {
5135  snprintf (cob_build_stamp, (size_t)COB_MINI_MAX,
5136  "%s %s", __DATE__, __TIME__);
5137  }
5138 
5139  printf ("libcob (%s) %s.%d\n",
5141  puts ("Copyright (C) 2001-2012, 2014-2016 Free Software Foundation, Inc.");
5142  printf (_("Written by %s\n"), "Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch");
5143  puts (_("This is free software; see the source for copying conditions. There is NO\n\
5144 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
5145  printf (_("Built %s"), cob_build_stamp);
5146  putchar ('\n');
5147  printf (_("Packaged %s"), COB_TAR_DATE);
5148  putchar ('\n');
5149 
5150 }
#define COB_MINI_BUFF
Definition: common.h:539
#define PACKAGE_NAME
Definition: config.h:300
#define _(s)
Definition: cobcrun.c:59
#define COB_TAR_DATE
Definition: tarstamp.h:1
#define PACKAGE_VERSION
Definition: config.h:312
#define PATCH_LEVEL
Definition: config.h:315
#define COB_MINI_MAX
Definition: common.h:545

Here is the caller graph for this function:

static int set_config_val ( char *  value,
int  pos 
)
static

Definition at line 4503 of file common.c.

References _, cob_expand_env_string(), cob_free(), conf_runtime_error(), conf_runtime_error_value(), config_tbl::data_len, config_tbl::data_loc, config_tbl::data_type, config_tbl::enums, ENV_BOOL, ENV_CHAR, ENV_ENUM, ENV_ENUMVAL, ENV_INT, ENV_NOT, ENV_PATH, ENV_SIZE, ENV_STR, config_enum::match, NULL, numval(), set_value(), and value.

Referenced by cb_config_entry(), cob_load_config(), cob_rescan_env_vals(), and set_config_val_by_name().

4504 {
4505  void *data;
4506  char *ptr = value,*str;
4507  unsigned long numval = 0;
4508  int i,data_type,data_loc,data_len,slen;
4509 
4510  data_type = gc_conf[pos].data_type;
4511  data_loc = gc_conf[pos].data_loc;
4512  data_len = gc_conf[pos].data_len;
4513 
4514  data = (void*)((char *)cobsetptr + data_loc);
4515 
4516  if(gc_conf[pos].enums) { /* Translate 'word' into alternate 'value' */
4517 
4518  for (i=0; gc_conf[pos].enums[i].match != NULL; i++) {
4519  if (strcasecmp(value,gc_conf[pos].enums[i].match) == 0) {
4520  ptr = value = (char*)gc_conf[pos].enums[i].value;
4521  break;
4522  }
4523  if ((data_type & ENV_ENUMVAL) && strcasecmp(value,gc_conf[pos].enums[i].value) == 0) {
4524  break;
4525  }
4526  }
4527  if((data_type & ENV_ENUM || data_type & ENV_ENUMVAL) /* Must be one of the 'enum' values */
4528  && gc_conf[pos].enums[i].match == NULL) {
4529  conf_runtime_error_value(ptr, pos);
4530  fprintf(stderr, _("should be one of the following values: %s"), "");
4531  for (i = 0; gc_conf[pos].enums[i].match != NULL; i++) {
4532  if (i != 0) {
4533  putc (',', stderr);
4534  putc (' ', stderr);
4535  }
4536  fprintf (stderr, "%s", (char*)gc_conf[pos].enums[i].match);
4537  if (data_type & ENV_ENUMVAL) {
4538  fprintf (stderr, "(%s)", (char*)gc_conf[pos].enums[i].value);
4539  }
4540  }
4541  putc ('\n', stderr);
4542  fflush (stderr);
4543  return 1;
4544  }
4545  }
4546 
4547  if((data_type & ENV_INT) /* Integer data */
4548  || (data_type & ENV_SIZE) ) { /* Size: integer with K, M, G */
4549  for (; *ptr != 0 && (isdigit((unsigned char)*ptr) || *ptr == ' '); ptr++) {
4550  if (*ptr != ' ') {
4551  numval = (numval * 10) + (*ptr - '0');
4552  }
4553  }
4554  if((data_type & ENV_SIZE) /* Size: any K, M, G */
4555  && *ptr != 0) {
4556  switch(toupper((unsigned char)*ptr)) {
4557  case 'K':
4558  numval = numval * 1024;
4559  break;
4560  case 'M':
4561  if (numval < 4001) {
4562  numval = numval * 1024 * 1024;
4563  } else {
4564  numval = 4294967295; /* max. guaranteed value for unsigned long */
4565  }
4566  break;
4567  case 'G':
4568  if (numval < 4) {
4569  numval = numval * 1024 * 1024 * 1024;
4570  } else {
4571  numval = 4294967295; /* max. guaranteed value for unsigned long */
4572  }
4573  break;
4574  }
4575  }
4576  if(gc_conf[pos].min_value > 0
4577  && numval < gc_conf[pos].min_value) {
4579  conf_runtime_error(1, _("minimum value: %lu"),gc_conf[pos].min_value);
4580  return 1;
4581  }
4582  if(gc_conf[pos].max_value > 0
4583  && numval > gc_conf[pos].max_value) {
4585  conf_runtime_error(1, _("maximum value: %lu"),gc_conf[pos].max_value);
4586  return 1;
4587  }
4588  set_value((char *)data,data_len,numval);
4589 
4590  } else if((data_type & ENV_BOOL)) { /* Boolean: Yes/No,True/False,... */
4591  numval = 2;
4592  if(isdigit((unsigned char)*ptr)) {
4593  numval = atoi(ptr); /* 0 or 1 */
4594  } else
4595  if(strcasecmp(ptr,"true") == 0
4596  || strcasecmp(ptr,"t") == 0
4597  || strcasecmp(ptr,"on") == 0
4598  || strcasecmp(ptr,"yes") == 0
4599  || strcasecmp(ptr,"y") == 0) {
4600  numval = 1; /* True value */
4601  } else
4602  if(strcasecmp(ptr,"false") == 0
4603  || strcasecmp(ptr,"f") == 0
4604  || strcasecmp(ptr,"off") == 0
4605  || strcasecmp(ptr,"no") == 0
4606  || strcasecmp(ptr,"n") == 0) {
4607  numval = 0; /* False value */
4608  }
4609 
4610  if(numval != 1
4611  && numval != 0) {
4612  conf_runtime_error_value(ptr, pos);
4613  conf_runtime_error(1, _("should be one of the following values: %s"), "true, false");
4614  return 1;
4615  } else {
4616  if ((data_type & ENV_NOT)) { /* Negate logic for actual setting */
4617  numval = !numval;
4618  }
4619  set_value((char *)data,data_len,numval);
4620  }
4621 
4622  } else if((data_type & ENV_STR)
4623  ||(data_type & ENV_PATH)) { /* String/Path to be stored as a string */
4624  memcpy(&str,data,sizeof(char *));
4625  if (str != NULL) {
4626  cob_free((void*)str);
4627  }
4629  memcpy(data,&str,sizeof(char *));
4630 
4631  } else if((data_type & ENV_CHAR)) { /* 'char' field inline */
4632  memset(data,0,data_len);
4633  slen = (int)strlen(value);
4634  if (slen > data_len) {
4635  slen = data_len;
4636  }
4637  memcpy(data,value,slen);
4638  }
4639  return 0;
4640 }
#define ENV_PATH
Definition: coblocal.h:296
void cob_free(void *mptr)
Definition: common.c:1284
const char * match
Definition: coblocal.h:254
static void set_value(char *data, int len, long val)
Definition: common.c:4473
#define ENV_CHAR
Definition: coblocal.h:294
#define ENV_NOT
Definition: coblocal.h:290
void conf_runtime_error(const int finish_error, const char *fmt,...)
Definition: common.c:1744
static cob_field * numval(cob_field *srcfield, cob_field *currency, const enum numval_type type)
Definition: intrinsic.c:1456
static cob_settings * cobsetptr
Definition: common.c:131
int data_type
Definition: coblocal.h:281
static struct config_tbl gc_conf[]
Definition: common.c:235
#define ENV_SIZE
Definition: coblocal.h:292
strict implicit external value
Definition: warning.def:54
#define ENV_BOOL
Definition: coblocal.h:293
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
int data_loc
Definition: coblocal.h:282
char * cob_expand_env_string(char *strval)
Definition: common.c:4406
#define ENV_INT
Definition: coblocal.h:291
#define ENV_ENUM
Definition: coblocal.h:297
void conf_runtime_error_value(char *value, const int conf_pos)
Definition: common.c:1731
struct config_enum * enums
Definition: coblocal.h:279
#define ENV_STR
Definition: coblocal.h:295
int data_len
Definition: coblocal.h:283
#define ENV_ENUMVAL
Definition: coblocal.h:298

Here is the call graph for this function:

Here is the caller graph for this function:

static int set_config_val_by_name ( char *  value,
const char *  name,
const char *  func 
)
static

Definition at line 4644 of file common.c.

References config_tbl::data_type, config_tbl::default_val, FUNC_NAME_IN_DEFAULT, NUM_CONFIG, config_tbl::set_by, set_config_val(), and STS_FNCSET.

Referenced by cob_init().

4645 {
4646  int i;
4647  int ret = 1;
4648 
4649  for (i = 0; i < NUM_CONFIG; i++) {
4650  if (!strcmp(gc_conf[i].conf_name,name)) {
4651  ret = set_config_val(value, i);
4652  if (func) {
4655  gc_conf[i].default_val = func;
4656  }
4657  break;
4658  }
4659  }
4660  return ret;
4661 }
const char * default_val
Definition: coblocal.h:278
int set_by
Definition: coblocal.h:285
int data_type
Definition: coblocal.h:281
static struct config_tbl gc_conf[]
Definition: common.c:235
strict implicit external value
Definition: warning.def:54
#define STS_FNCSET
Definition: coblocal.h:304
static int set_config_val(char *value, int pos)
Definition: common.c:4503
#define FUNC_NAME_IN_DEFAULT
Definition: common.c:284
#define NUM_CONFIG
Definition: common.c:283

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_unknown_offset ( struct cob_time time)
static

Definition at line 1153 of file common.c.

References cob_time::offset_known, and cob_time::utc_offset.

Referenced by cob_get_current_date_and_time().

1154 {
1155  time->offset_known = 0;
1156  time->utc_offset = 0;
1157 }
int utc_offset
Definition: coblocal.h:272
int offset_known
Definition: coblocal.h:271

Here is the caller graph for this function:

static void set_value ( char *  data,
int  len,
long  val 
)
static

Definition at line 4473 of file common.c.

Referenced by set_config_val().

4474 {
4475  if(len == sizeof(int)) {
4476  *(int*)data = (int)val;
4477  } else if(len == sizeof(short)) {
4478  *(short*)data = (short)val;
4479  } else if(len == sizeof(long)) {
4480  *(long*)data = val;
4481  } else {
4482  *(char*)data = (char)val;
4483  }
4484 }

Here is the caller graph for this function:

static int sort_compare ( const void *  data1,
const void *  data2 
)
static

Definition at line 1018 of file common.c.

References COB_ASCENDING, COB_FIELD_IS_NUMERIC, cob_numeric_cmp(), common_cmps(), cob_field::data, f1, f2, cob_file_key::field, cob_field::size, sort_collate, and sort_nkeys.

Referenced by cob_table_sort().

1019 {
1020  size_t i;
1021  int cmp;
1022  cob_field f1;
1023  cob_field f2;
1024 
1025  for (i = 0; i < sort_nkeys; ++i) {
1026  f1 = f2 = *sort_keys[i].field;
1027  f1.data = (unsigned char *)data1 + sort_keys[i].offset;
1028  f2.data = (unsigned char *)data2 + sort_keys[i].offset;
1029  if (COB_FIELD_IS_NUMERIC(&f1)) {
1030  cmp = cob_numeric_cmp (&f1, &f2);
1031  } else {
1032  cmp = common_cmps (f1.data, f2.data, f1.size, sort_collate);
1033  }
1034  if (cmp != 0) {
1035  return (sort_keys[i].flag == COB_ASCENDING) ? cmp : -cmp;
1036  }
1037  }
1038  return 0;
1039 }
static int common_cmps(const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
Definition: common.c:923
static cob_file_key * sort_keys
Definition: common.c:147
#define COB_FIELD_IS_NUMERIC(f)
Definition: common.h:674
cob_field * field
Definition: common.h:1102
cob_field f2
Definition: cobxref.c.l.h:55
unsigned char * data
Definition: common.h:952
int cob_numeric_cmp(cob_field *, cob_field *)
Definition: numeric.c:2348
cob_field f1
Definition: cobxref.c.l.h:54
size_t size
Definition: common.h:951
#define COB_ASCENDING
Definition: common.h:735
static const unsigned char * sort_collate
Definition: common.c:148
static size_t sort_nkeys
Definition: common.c:146

Here is the call graph for this function:

Here is the caller graph for this function:

static void var_print ( const char *  msg,
const char *  val,
const char *  default_val,
const unsigned int  format 
)
static

Definition at line 4331 of file common.c.

References _, CB_IMSG_SIZE, CB_IVAL_SIZE, cob_free(), cob_strcat(), cob_strdup(), and NULL.

Referenced by print_info().

4333 {
4334  char *p;
4335  char *token;
4336  size_t n;
4337  int lablen;
4338  int toklen;
4339 
4340  switch (format) {
4341  case 0:
4342  printf("%-*.*s : ", CB_IMSG_SIZE, CB_IMSG_SIZE, msg);
4343  break;
4344  case 1: {
4345  printf(" %s: ", _("env"));
4346  lablen = CB_IMSG_SIZE - 2 - (int)strlen(_("env")) - 2;
4347  printf("%-*.*s : ", lablen, lablen, msg);
4348  break;
4349  }
4350  case 2:
4351  printf(" %-*.*s : ", CB_IMSG_SIZE, CB_IMSG_SIZE, msg);
4352  break;
4353  case 3:
4354  printf(" %-*.*s : ", CB_IMSG_SIZE, CB_IMSG_SIZE, msg);
4355  break;
4356  default:
4357  printf("%-*.*s : ", CB_IMSG_SIZE, CB_IMSG_SIZE, msg);
4358  break;
4359  }
4360 
4361  if (!val && !default_val) {
4362  putchar('\n');
4363  return;
4364  } else if (val && default_val && ((format != 2 && val[0] == 0x30) || strcmp(val, default_val) == 0)) {
4365  val = cob_strcat((char*) default_val, (char*) _(" (default)"));
4366  } else if (!val && default_val) {
4367  val = default_val;
4368  }
4369 
4370  if (val && strlen(val) <= CB_IVAL_SIZE) {
4371  printf("%s", val);
4372  putchar ('\n');
4373 
4374  return;
4375  }
4376 
4377  p = cob_strdup (val);
4378 
4379  n = 0;
4380  token = strtok (p, " ");
4381  for (; token; token = strtok (NULL, " ")) {
4382  toklen = (int)strlen (token) + 1;
4383  if ((n + toklen) > CB_IVAL_SIZE) {
4384  if (n) {
4385  if (format == 2 || format == 3)
4386  printf("\n %*.*s", CB_IMSG_SIZE + 3,
4387  CB_IMSG_SIZE + 3, " ");
4388  else
4389  printf("\n%*.*s", CB_IMSG_SIZE + 3, CB_IMSG_SIZE + 3, " ");
4390  }
4391  n = 0;
4392  }
4393  printf ("%s%s", (n ? " " : ""), token);
4394  n += toklen;
4395  }
4396  putchar ('\n');
4397  cob_free (p);
4398 
4399 }
void cob_free(void *mptr)
Definition: common.c:1284
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define CB_IVAL_SIZE
Definition: common.c:75
char * cob_strcat(char *str1, char *str2)
Definition: common.c:4270
#define CB_IMSG_SIZE
Definition: common.c:74
char * cob_strdup(const char *p)
Definition: common.c:1308

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

struct cob_external* basext = ((void*)0)
static

Definition at line 144 of file common.c.

Referenced by cob_external_addr().

struct config_enum beepopts[] = {{"FLASH","1"},{"SPEAKER","2"},{"FALSE","9"},{"BEEP","0"},{ ((void*)0) , ((void*)0) }}
static

Definition at line 221 of file common.c.

struct cob_alloc_cache* cob_alloc_base
static
const char* cob_current_paragraph = ((void*)0)
static

Definition at line 152 of file common.c.

Referenced by cob_init(), cob_set_exception(), and cob_set_location().

const char* cob_current_program_id = ((void*)0)
static

Definition at line 150 of file common.c.

Referenced by cob_init(), cob_set_exception(), and cob_set_location().

const char* cob_current_section = ((void*)0)
static

Definition at line 151 of file common.c.

Referenced by cob_init(), cob_set_exception(), and cob_set_location().

const int cob_exception_tab_code[]
static

Definition at line 188 of file common.c.

Referenced by cob_get_exception_name(), and cob_set_exception().

const char* const cob_exception_tab_name[]
static

Definition at line 180 of file common.c.

Referenced by cob_get_exception_name().

void(* cob_ext_sighdl) (int) = ((void*)0)
static

Definition at line 172 of file common.c.

Referenced by cob_reg_sighnd().

int cob_initialized = 0
static
const char* cob_last_sfile
static

Definition at line 128 of file common.c.

Referenced by cob_exit_common(), cob_init(), cob_set_location(), and cob_trace_section().

char* cob_local_env = ((void*)0)
static
size_t cob_local_env_size = 0
static

Definition at line 142 of file common.c.

Referenced by cob_display_environment(), and cob_init().

int cob_process_id = 0
static

Definition at line 160 of file common.c.

Referenced by cob_sys_getpid().

const char* cob_source_file = ((void*)0)
static
unsigned int cob_source_line = 0
static
const char* cob_source_statement = ((void*)0)
static

Definition at line 154 of file common.c.

Referenced by cob_init(), cob_set_exception(), and cob_set_location().

int cob_switch[36+1]
static

Definition at line 201 of file common.c.

Referenced by cob_get_switch(), cob_init(), cob_set_switch(), and cob_sys_x91().

int cob_temp_iteration = 0
static

Definition at line 161 of file common.c.

Referenced by cob_incr_temp_iteration(), and cob_temp_name().

FILE* cob_trace_file = ((void*)0)
static
cob_global* cobglobptr = ((void*)0)
static

Definition at line 130 of file common.c.

Referenced by cob_get_global_ptr(), and cob_module_enter().

cob_settings* cobsetptr = ((void*)0)
static

Definition at line 131 of file common.c.

Referenced by cob_get_settings_ptr().

size_t commlncnt
static

Definition at line 141 of file common.c.

Referenced by cob_accept_command_line(), cob_display_command_line(), and cob_init().

unsigned char* commlnptr = ((void*)0)
static
unsigned int conf_runtime_error_displayed = 0
static

Definition at line 163 of file common.c.

Referenced by conf_runtime_error().

const cob_field_attr const_alpha_attr
static
Initial value:
=
{COB_TYPE_ALPHANUMERIC, 0, 0, 0, ((void*)0) }
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621

Definition at line 135 of file common.c.

Referenced by cob_allocate(), and cob_memcpy().

int current_arg
static

Definition at line 139 of file common.c.

Referenced by cob_accept_arg_value(), cob_display_arg_number(), and cob_init().

struct exit_handlerlist * exit_hdlrs
static
struct config_tbl gc_conf[]
static

Definition at line 235 of file common.c.

struct handlerlist * hdlrs
static
const char* last_runtime_error_file = "unknown"
static

Definition at line 165 of file common.c.

Referenced by conf_runtime_error().

unsigned int last_runtime_error_line = 0
static

Definition at line 164 of file common.c.

Referenced by conf_runtime_error().

struct config_enum lwrupr[] = {{"LOWER","1"},{"UPPER","2"},{not_set,"0"},{ ((void*)0) , ((void*)0) }}
static

Definition at line 220 of file common.c.

char not_set[] = "not set"
static

Definition at line 219 of file common.c.

Referenced by print_runtime_env().

char* runtime_err_str = ((void*)0)
static

Definition at line 133 of file common.c.

Referenced by cob_exit_common(), cob_init(), and cob_runtime_error().

const char* setting_group[]
static
Initial value:
= {" hidden setting ","Call environment",
"File I/O","Screen I/O","Miscellaneous",
"System environment"}

Definition at line 215 of file common.c.

Referenced by print_runtime_env().

const unsigned char* sort_collate
static

Definition at line 148 of file common.c.

Referenced by cob_init(), cob_table_sort_init(), and sort_compare().

cob_file_key* sort_keys
static

Definition at line 147 of file common.c.

size_t sort_nkeys = 0
static

Definition at line 146 of file common.c.

Referenced by cob_init(), cob_table_sort_init(), cob_table_sort_init_key(), and sort_compare().

char* strbuff = ((void*)0)
static

Definition at line 158 of file common.c.

Referenced by cob_strcat().

struct config_enum syncopts[] = {{"P","1"},{ ((void*)0) , ((void*)0) }}
static

Definition at line 223 of file common.c.

struct config_enum timeopts[] = {{"0","1000"},{"1","100"},{"2","10"},{"3","1"},{ ((void*)0) , ((void*)0) }}
static

Definition at line 222 of file common.c.

char varseq_dflt[8] = "0"
static

Definition at line 225 of file common.c.

Referenced by cob_load_config().

struct config_enum varseqopts[] = {{"0","0"},{"1","1"},{"2","2"},{"3","3"},{ ((void*)0) , ((void*)0) }}
static

Definition at line 224 of file common.c.