GnuCOBOL  2.0
A free COBOL compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
scanner.l File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include "cobc.h"
#include "tree.h"
#include "parser.h"
Include dependency graph for scanner.l:

Data Structures

struct  cob_field_attr
 
struct  cob_field
 
struct  cob_fp_128
 
struct  cob_decimal
 
struct  cob_frame
 
union  cob_content
 
union  cob_call_union
 
struct  cob_call_struct
 
struct  __cob_screen
 
struct  __cob_module
 
struct  cob_func_loc
 
struct  cob_file_key
 
struct  cob_file
 
struct  cob_linage
 
struct  cob_report
 
struct  __cob_global
 
struct  cob_fileio_funcs
 
struct  cobjmp_buf
 
struct  longoption_def
 
struct  cb_text_list
 
struct  cb_replace_list
 
struct  cb_define_struct
 
struct  local_filename
 
struct  filename
 
struct  cb_exception
 
struct  noreserve
 
struct  cobc_mem_struct
 
struct  cobc_reserved
 
struct  cb_tree_common
 
struct  cb_const
 
struct  cb_direct
 
struct  cb_debug
 
struct  cb_debug_call
 
struct  cb_integer
 
struct  cb_string
 
struct  cb_alphabet_name
 
struct  cb_class_name
 
struct  cb_locale_name
 
struct  cb_system_name
 
struct  cb_literal
 
struct  cb_decimal
 
struct  cb_picture
 
struct  cb_key
 
struct  cb_field
 
struct  cb_para_label
 
struct  cb_alter_id
 
struct  cb_label
 
struct  handler_struct
 
struct  cb_alt_key
 
struct  cb_file
 
struct  cb_word
 
struct  cb_reference
 
struct  cb_binary_op
 
struct  cb_funcall
 
struct  cb_cast
 
struct  cb_assign
 
struct  cb_intrinsic_table
 
struct  cb_intrinsic
 
struct  cb_initialize
 
struct  cb_search
 
struct  cb_call
 
struct  cb_cancel
 
struct  cb_alter
 
struct  cb_goto
 
struct  cb_if
 
struct  cb_perform_varying
 
struct  cb_perform
 
struct  cb_attr_struct
 
struct  cb_statement
 
struct  cb_continue
 
struct  cb_set_attr
 
struct  cb_list
 
struct  cb_report
 
struct  nested_list
 
struct  cb_program
 
struct  cb_level_78
 
struct  cb_top_level_78
 

Macros

#define YY_READ_BUF_SIZE   32768
 
#define YY_BUF_SIZE   32768
 
#define YY_SKIP_YYWRAP
 
#define yywrap()   1
 
#define YY_INPUT(buf, result, max_size)
 
#define YY_USER_INIT
 
#define COB_IN_SCANNER   1
 
#define YYSTYPE   cb_tree
 
#define SET_LOCATION(x)
 

Typedefs

typedef struct __cob_screen cob_screen
 
typedef struct __cob_module cob_module
 
typedef struct __cob_global cob_global
 
typedef struct longoption_def longoption_def
 
typedef struct cb_tree_commoncb_tree
 

Enumerations

enum  cb_operation_type { CB_OPERATION_READ = 0, CB_OPERATION_WRITE, CB_OPERATION_ASSIGN }
 
enum  cb_support {
  CB_OK = 0, CB_WARNING, CB_ARCHAIC, CB_OBSOLETE,
  CB_SKIP, CB_IGNORE, CB_ERROR, CB_UNCONFORMABLE
}
 
enum  cb_std_def {
  CB_STD_OC = 0, CB_STD_MF, CB_STD_IBM, CB_STD_MVS,
  CB_STD_BS2000, CB_STD_85, CB_STD_2002
}
 
enum  cb_tag {
  CB_TAG_CONST = 0, CB_TAG_INTEGER, CB_TAG_STRING, CB_TAG_ALPHABET_NAME,
  CB_TAG_CLASS_NAME, CB_TAG_LOCALE_NAME, CB_TAG_SYSTEM_NAME, CB_TAG_LITERAL,
  CB_TAG_DECIMAL, CB_TAG_FIELD, CB_TAG_FILE, CB_TAG_REPORT,
  CB_TAG_REFERENCE, CB_TAG_BINARY_OP, CB_TAG_FUNCALL, CB_TAG_CAST,
  CB_TAG_INTRINSIC, CB_TAG_LABEL, CB_TAG_ASSIGN, CB_TAG_INITIALIZE,
  CB_TAG_SEARCH, CB_TAG_CALL, CB_TAG_GOTO, CB_TAG_IF,
  CB_TAG_PERFORM, CB_TAG_STATEMENT, CB_TAG_CONTINUE, CB_TAG_CANCEL,
  CB_TAG_ALTER, CB_TAG_SET_ATTR, CB_TAG_PERFORM_VARYING, CB_TAG_PICTURE,
  CB_TAG_LIST, CB_TAG_DIRECT, CB_TAG_DEBUG, CB_TAG_DEBUG_CALL,
  CB_TAG_CONST = 0, CB_TAG_INTEGER, CB_TAG_STRING, CB_TAG_ALPHABET_NAME,
  CB_TAG_CLASS_NAME, CB_TAG_LOCALE_NAME, CB_TAG_SYSTEM_NAME, CB_TAG_LITERAL,
  CB_TAG_DECIMAL, CB_TAG_FIELD, CB_TAG_FILE, CB_TAG_REPORT,
  CB_TAG_REFERENCE, CB_TAG_BINARY_OP, CB_TAG_FUNCALL, CB_TAG_CAST,
  CB_TAG_INTRINSIC, CB_TAG_LABEL, CB_TAG_ASSIGN, CB_TAG_INITIALIZE,
  CB_TAG_SEARCH, CB_TAG_CALL, CB_TAG_GOTO, CB_TAG_IF,
  CB_TAG_PERFORM, CB_TAG_STATEMENT, CB_TAG_CONTINUE, CB_TAG_CANCEL,
  CB_TAG_ALTER, CB_TAG_SET_ATTR, CB_TAG_PERFORM_VARYING, CB_TAG_PICTURE,
  CB_TAG_LIST, CB_TAG_DIRECT, CB_TAG_DEBUG, CB_TAG_DEBUG_CALL,
  CB_TAG_CONST = 0, CB_TAG_INTEGER, CB_TAG_STRING, CB_TAG_ALPHABET_NAME,
  CB_TAG_CLASS_NAME, CB_TAG_LOCALE_NAME, CB_TAG_SYSTEM_NAME, CB_TAG_LITERAL,
  CB_TAG_DECIMAL, CB_TAG_FIELD, CB_TAG_FILE, CB_TAG_REPORT,
  CB_TAG_REFERENCE, CB_TAG_BINARY_OP, CB_TAG_FUNCALL, CB_TAG_CAST,
  CB_TAG_INTRINSIC, CB_TAG_LABEL, CB_TAG_ASSIGN, CB_TAG_INITIALIZE,
  CB_TAG_SEARCH, CB_TAG_CALL, CB_TAG_GOTO, CB_TAG_IF,
  CB_TAG_PERFORM, CB_TAG_STATEMENT, CB_TAG_CONTINUE, CB_TAG_CANCEL,
  CB_TAG_ALTER, CB_TAG_SET_ATTR, CB_TAG_PERFORM_VARYING, CB_TAG_PICTURE,
  CB_TAG_LIST, CB_TAG_DIRECT, CB_TAG_DEBUG, CB_TAG_DEBUG_CALL
}
 
enum  cb_system_name_category {
  CB_DEVICE_NAME = 0, CB_SWITCH_NAME, CB_FEATURE_NAME, CB_CALL_CONVENTION_NAME,
  CB_CODE_NAME, CB_COMPUTER_NAME, CB_ENTRY_CONVENTION_NAME, CB_EXTERNAL_LOCALE_NAME,
  CB_LIBRARY_NAME, CB_TEXT_NAME, CB_DEVICE_NAME = 0, CB_SWITCH_NAME,
  CB_FEATURE_NAME, CB_CALL_CONVENTION_NAME, CB_CODE_NAME, CB_COMPUTER_NAME,
  CB_ENTRY_CONVENTION_NAME, CB_EXTERNAL_LOCALE_NAME, CB_LIBRARY_NAME, CB_TEXT_NAME,
  CB_DEVICE_NAME = 0, CB_SWITCH_NAME, CB_FEATURE_NAME, CB_CALL_CONVENTION_NAME,
  CB_CODE_NAME, CB_COMPUTER_NAME, CB_ENTRY_CONVENTION_NAME, CB_EXTERNAL_LOCALE_NAME,
  CB_LIBRARY_NAME, CB_TEXT_NAME
}
 
enum  cb_class {
  CB_CLASS_UNKNOWN = 0, CB_CLASS_ALPHABETIC, CB_CLASS_ALPHANUMERIC, CB_CLASS_BOOLEAN,
  CB_CLASS_INDEX, CB_CLASS_NATIONAL, CB_CLASS_NUMERIC, CB_CLASS_OBJECT,
  CB_CLASS_POINTER, CB_CLASS_UNKNOWN = 0, CB_CLASS_ALPHABETIC, CB_CLASS_ALPHANUMERIC,
  CB_CLASS_BOOLEAN, CB_CLASS_INDEX, CB_CLASS_NATIONAL, CB_CLASS_NUMERIC,
  CB_CLASS_OBJECT, CB_CLASS_POINTER, CB_CLASS_UNKNOWN = 0, CB_CLASS_ALPHABETIC,
  CB_CLASS_ALPHANUMERIC, CB_CLASS_BOOLEAN, CB_CLASS_INDEX, CB_CLASS_NATIONAL,
  CB_CLASS_NUMERIC, CB_CLASS_OBJECT, CB_CLASS_POINTER
}
 
enum  cb_category {
  CB_CATEGORY_UNKNOWN = 0, CB_CATEGORY_ALPHABETIC, CB_CATEGORY_ALPHANUMERIC, CB_CATEGORY_ALPHANUMERIC_EDITED,
  CB_CATEGORY_BOOLEAN, CB_CATEGORY_INDEX, CB_CATEGORY_NATIONAL, CB_CATEGORY_NATIONAL_EDITED,
  CB_CATEGORY_NUMERIC, CB_CATEGORY_NUMERIC_EDITED, CB_CATEGORY_OBJECT_REFERENCE, CB_CATEGORY_DATA_POINTER,
  CB_CATEGORY_PROGRAM_POINTER, CB_CATEGORY_UNKNOWN = 0, CB_CATEGORY_ALPHABETIC, CB_CATEGORY_ALPHANUMERIC,
  CB_CATEGORY_ALPHANUMERIC_EDITED, CB_CATEGORY_BOOLEAN, CB_CATEGORY_INDEX, CB_CATEGORY_NATIONAL,
  CB_CATEGORY_NATIONAL_EDITED, CB_CATEGORY_NUMERIC, CB_CATEGORY_NUMERIC_EDITED, CB_CATEGORY_OBJECT_REFERENCE,
  CB_CATEGORY_DATA_POINTER, CB_CATEGORY_PROGRAM_POINTER, CB_CATEGORY_UNKNOWN = 0, CB_CATEGORY_ALPHABETIC,
  CB_CATEGORY_ALPHANUMERIC, CB_CATEGORY_ALPHANUMERIC_EDITED, CB_CATEGORY_BOOLEAN, CB_CATEGORY_INDEX,
  CB_CATEGORY_NATIONAL, CB_CATEGORY_NATIONAL_EDITED, CB_CATEGORY_NUMERIC, CB_CATEGORY_NUMERIC_EDITED,
  CB_CATEGORY_OBJECT_REFERENCE, CB_CATEGORY_DATA_POINTER, CB_CATEGORY_PROGRAM_POINTER
}
 
enum  cb_storage {
  CB_STORAGE_CONSTANT = 0, CB_STORAGE_FILE, CB_STORAGE_WORKING, CB_STORAGE_LOCAL,
  CB_STORAGE_LINKAGE, CB_STORAGE_SCREEN, CB_STORAGE_REPORT, CB_STORAGE_COMMUNICATION,
  CB_STORAGE_CONSTANT = 0, CB_STORAGE_FILE, CB_STORAGE_WORKING, CB_STORAGE_LOCAL,
  CB_STORAGE_LINKAGE, CB_STORAGE_SCREEN, CB_STORAGE_REPORT, CB_STORAGE_COMMUNICATION,
  CB_STORAGE_CONSTANT = 0, CB_STORAGE_FILE, CB_STORAGE_WORKING, CB_STORAGE_LOCAL,
  CB_STORAGE_LINKAGE, CB_STORAGE_SCREEN, CB_STORAGE_REPORT, CB_STORAGE_COMMUNICATION
}
 
enum  cb_usage {
  CB_USAGE_BINARY = 0, CB_USAGE_BIT, CB_USAGE_COMP_5, CB_USAGE_COMP_X,
  CB_USAGE_DISPLAY, CB_USAGE_FLOAT, CB_USAGE_DOUBLE, CB_USAGE_INDEX,
  CB_USAGE_NATIONAL, CB_USAGE_OBJECT, CB_USAGE_PACKED, CB_USAGE_POINTER,
  CB_USAGE_PROGRAM, CB_USAGE_LENGTH, CB_USAGE_PROGRAM_POINTER, CB_USAGE_UNSIGNED_CHAR,
  CB_USAGE_SIGNED_CHAR, CB_USAGE_UNSIGNED_SHORT, CB_USAGE_SIGNED_SHORT, CB_USAGE_UNSIGNED_INT,
  CB_USAGE_SIGNED_INT, CB_USAGE_UNSIGNED_LONG, CB_USAGE_SIGNED_LONG, CB_USAGE_COMP_6,
  CB_USAGE_FP_DEC64, CB_USAGE_FP_DEC128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64,
  CB_USAGE_FP_BIN128, CB_USAGE_LONG_DOUBLE, CB_USAGE_BINARY = 0, CB_USAGE_BIT,
  CB_USAGE_COMP_5, CB_USAGE_COMP_X, CB_USAGE_DISPLAY, CB_USAGE_FLOAT,
  CB_USAGE_DOUBLE, CB_USAGE_INDEX, CB_USAGE_NATIONAL, CB_USAGE_OBJECT,
  CB_USAGE_PACKED, CB_USAGE_POINTER, CB_USAGE_PROGRAM, CB_USAGE_LENGTH,
  CB_USAGE_PROGRAM_POINTER, CB_USAGE_UNSIGNED_CHAR, CB_USAGE_SIGNED_CHAR, CB_USAGE_UNSIGNED_SHORT,
  CB_USAGE_SIGNED_SHORT, CB_USAGE_UNSIGNED_INT, CB_USAGE_SIGNED_INT, CB_USAGE_UNSIGNED_LONG,
  CB_USAGE_SIGNED_LONG, CB_USAGE_COMP_6, CB_USAGE_FP_DEC64, CB_USAGE_FP_DEC128,
  CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64, CB_USAGE_FP_BIN128, CB_USAGE_LONG_DOUBLE,
  CB_USAGE_BINARY = 0, CB_USAGE_BIT, CB_USAGE_COMP_5, CB_USAGE_COMP_X,
  CB_USAGE_DISPLAY, CB_USAGE_FLOAT, CB_USAGE_DOUBLE, CB_USAGE_INDEX,
  CB_USAGE_NATIONAL, CB_USAGE_OBJECT, CB_USAGE_PACKED, CB_USAGE_POINTER,
  CB_USAGE_PROGRAM, CB_USAGE_LENGTH, CB_USAGE_PROGRAM_POINTER, CB_USAGE_UNSIGNED_CHAR,
  CB_USAGE_SIGNED_CHAR, CB_USAGE_UNSIGNED_SHORT, CB_USAGE_SIGNED_SHORT, CB_USAGE_UNSIGNED_INT,
  CB_USAGE_SIGNED_INT, CB_USAGE_UNSIGNED_LONG, CB_USAGE_SIGNED_LONG, CB_USAGE_COMP_6,
  CB_USAGE_FP_DEC64, CB_USAGE_FP_DEC128, CB_USAGE_FP_BIN32, CB_USAGE_FP_BIN64,
  CB_USAGE_FP_BIN128, CB_USAGE_LONG_DOUBLE
}
 
enum  cb_cast_type {
  CB_CAST_INTEGER = 0, CB_CAST_LONG_INT, CB_CAST_ADDRESS, CB_CAST_ADDR_OF_ADDR,
  CB_CAST_LENGTH, CB_CAST_PROGRAM_POINTER, CB_CAST_INTEGER = 0, CB_CAST_LONG_INT,
  CB_CAST_ADDRESS, CB_CAST_ADDR_OF_ADDR, CB_CAST_LENGTH, CB_CAST_PROGRAM_POINTER,
  CB_CAST_INTEGER = 0, CB_CAST_LONG_INT, CB_CAST_ADDRESS, CB_CAST_ADDR_OF_ADDR,
  CB_CAST_LENGTH, CB_CAST_PROGRAM_POINTER
}
 
enum  cb_intr_enum {
  CB_INTR_ABS = 1, CB_INTR_ACOS, CB_INTR_ANNUITY, CB_INTR_ASIN,
  CB_INTR_ATAN, CB_INTR_BOOLEAN_OF_INTEGER, CB_INTR_BYTE_LENGTH, CB_INTR_CHAR,
  CB_INTR_CHAR_NATIONAL, CB_INTR_COMBINED_DATETIME, CB_INTR_CONCATENATE, CB_INTR_COS,
  CB_INTR_CURRENCY_SYMBOL, CB_INTR_CURRENT_DATE, CB_INTR_DATE_OF_INTEGER, CB_INTR_DATE_TO_YYYYMMDD,
  CB_INTR_DAY_OF_INTEGER, CB_INTR_DAY_TO_YYYYDDD, CB_INTR_DISPLAY_OF, CB_INTR_E,
  CB_INTR_EXCEPTION_FILE, CB_INTR_EXCEPTION_FILE_N, CB_INTR_EXCEPTION_LOCATION, CB_INTR_EXCEPTION_LOCATION_N,
  CB_INTR_EXCEPTION_STATEMENT, CB_INTR_EXCEPTION_STATUS, CB_INTR_EXP, CB_INTR_EXP10,
  CB_INTR_FACTORIAL, CB_INTR_FORMATTED_CURRENT_DATE, CB_INTR_FORMATTED_DATE, CB_INTR_FORMATTED_DATETIME,
  CB_INTR_FORMATTED_TIME, CB_INTR_FRACTION_PART, CB_INTR_HIGHEST_ALGEBRAIC, CB_INTR_INTEGER,
  CB_INTR_INTEGER_OF_BOOLEAN, CB_INTR_INTEGER_OF_DATE, CB_INTR_INTEGER_OF_DAY, CB_INTR_INTEGER_OF_FORMATTED_DATE,
  CB_INTR_INTEGER_PART, CB_INTR_LENGTH, CB_INTR_LOCALE_COMPARE, CB_INTR_LOCALE_DATE,
  CB_INTR_LOCALE_TIME, CB_INTR_LOCALE_TIME_FROM_SECS, CB_INTR_LOG, CB_INTR_LOG10,
  CB_INTR_LOWER_CASE, CB_INTR_LOWEST_ALGEBRAIC, CB_INTR_MAX, CB_INTR_MEAN,
  CB_INTR_MEDIAN, CB_INTR_MIDRANGE, CB_INTR_MIN, CB_INTR_MOD,
  CB_INTR_MODULE_CALLER_ID, CB_INTR_MODULE_DATE, CB_INTR_MODULE_FORMATTED_DATE, CB_INTR_MODULE_ID,
  CB_INTR_MODULE_PATH, CB_INTR_MODULE_SOURCE, CB_INTR_MODULE_TIME, CB_INTR_MON_DECIMAL_POINT,
  CB_INTR_MON_THOUSANDS_SEP, CB_INTR_NATIONAL_OF, CB_INTR_NUM_DECIMAL_POINT, CB_INTR_NUM_THOUSANDS_SEP,
  CB_INTR_NUMVAL, CB_INTR_NUMVAL_C, CB_INTR_NUMVAL_F, CB_INTR_ORD,
  CB_INTR_ORD_MAX, CB_INTR_ORD_MIN, CB_INTR_PI, CB_INTR_PRESENT_VALUE,
  CB_INTR_RANDOM, CB_INTR_RANGE, CB_INTR_REM, CB_INTR_REVERSE,
  CB_INTR_SECONDS_FROM_FORMATTED_TIME, CB_INTR_SECONDS_PAST_MIDNIGHT, CB_INTR_SIGN, CB_INTR_SIN,
  CB_INTR_SQRT, CB_INTR_STANDARD_COMPARE, CB_INTR_STANDARD_DEVIATION, CB_INTR_STORED_CHAR_LENGTH,
  CB_INTR_SUBSTITUTE, CB_INTR_SUBSTITUTE_CASE, CB_INTR_SUM, CB_INTR_TAN,
  CB_INTR_TEST_DATE_YYYYMMDD, CB_INTR_TEST_DAY_YYYYDDD, CB_INTR_TEST_FORMATTED_DATETIME, CB_INTR_TEST_NUMVAL,
  CB_INTR_TEST_NUMVAL_C, CB_INTR_TEST_NUMVAL_F, CB_INTR_TRIM, CB_INTR_UPPER_CASE,
  CB_INTR_USER_FUNCTION, CB_INTR_VARIANCE, CB_INTR_WHEN_COMPILED, CB_INTR_YEAR_TO_YYYY,
  CB_INTR_ABS = 1, CB_INTR_ACOS, CB_INTR_ANNUITY, CB_INTR_ASIN,
  CB_INTR_ATAN, CB_INTR_BOOLEAN_OF_INTEGER, CB_INTR_BYTE_LENGTH, CB_INTR_CHAR,
  CB_INTR_CHAR_NATIONAL, CB_INTR_COMBINED_DATETIME, CB_INTR_CONCATENATE, CB_INTR_COS,
  CB_INTR_CURRENCY_SYMBOL, CB_INTR_CURRENT_DATE, CB_INTR_DATE_OF_INTEGER, CB_INTR_DATE_TO_YYYYMMDD,
  CB_INTR_DAY_OF_INTEGER, CB_INTR_DAY_TO_YYYYDDD, CB_INTR_DISPLAY_OF, CB_INTR_E,
  CB_INTR_EXCEPTION_FILE, CB_INTR_EXCEPTION_FILE_N, CB_INTR_EXCEPTION_LOCATION, CB_INTR_EXCEPTION_LOCATION_N,
  CB_INTR_EXCEPTION_STATEMENT, CB_INTR_EXCEPTION_STATUS, CB_INTR_EXP, CB_INTR_EXP10,
  CB_INTR_FACTORIAL, CB_INTR_FORMATTED_CURRENT_DATE, CB_INTR_FORMATTED_DATE, CB_INTR_FORMATTED_DATETIME,
  CB_INTR_FORMATTED_TIME, CB_INTR_FRACTION_PART, CB_INTR_HIGHEST_ALGEBRAIC, CB_INTR_INTEGER,
  CB_INTR_INTEGER_OF_BOOLEAN, CB_INTR_INTEGER_OF_DATE, CB_INTR_INTEGER_OF_DAY, CB_INTR_INTEGER_OF_FORMATTED_DATE,
  CB_INTR_INTEGER_PART, CB_INTR_LENGTH, CB_INTR_LOCALE_COMPARE, CB_INTR_LOCALE_DATE,
  CB_INTR_LOCALE_TIME, CB_INTR_LOCALE_TIME_FROM_SECS, CB_INTR_LOG, CB_INTR_LOG10,
  CB_INTR_LOWER_CASE, CB_INTR_LOWEST_ALGEBRAIC, CB_INTR_MAX, CB_INTR_MEAN,
  CB_INTR_MEDIAN, CB_INTR_MIDRANGE, CB_INTR_MIN, CB_INTR_MOD,
  CB_INTR_MODULE_CALLER_ID, CB_INTR_MODULE_DATE, CB_INTR_MODULE_FORMATTED_DATE, CB_INTR_MODULE_ID,
  CB_INTR_MODULE_PATH, CB_INTR_MODULE_SOURCE, CB_INTR_MODULE_TIME, CB_INTR_MON_DECIMAL_POINT,
  CB_INTR_MON_THOUSANDS_SEP, CB_INTR_NATIONAL_OF, CB_INTR_NUM_DECIMAL_POINT, CB_INTR_NUM_THOUSANDS_SEP,
  CB_INTR_NUMVAL, CB_INTR_NUMVAL_C, CB_INTR_NUMVAL_F, CB_INTR_ORD,
  CB_INTR_ORD_MAX, CB_INTR_ORD_MIN, CB_INTR_PI, CB_INTR_PRESENT_VALUE,
  CB_INTR_RANDOM, CB_INTR_RANGE, CB_INTR_REM, CB_INTR_REVERSE,
  CB_INTR_SECONDS_FROM_FORMATTED_TIME, CB_INTR_SECONDS_PAST_MIDNIGHT, CB_INTR_SIGN, CB_INTR_SIN,
  CB_INTR_SQRT, CB_INTR_STANDARD_COMPARE, CB_INTR_STANDARD_DEVIATION, CB_INTR_STORED_CHAR_LENGTH,
  CB_INTR_SUBSTITUTE, CB_INTR_SUBSTITUTE_CASE, CB_INTR_SUM, CB_INTR_TAN,
  CB_INTR_TEST_DATE_YYYYMMDD, CB_INTR_TEST_DAY_YYYYDDD, CB_INTR_TEST_FORMATTED_DATETIME, CB_INTR_TEST_NUMVAL,
  CB_INTR_TEST_NUMVAL_C, CB_INTR_TEST_NUMVAL_F, CB_INTR_TRIM, CB_INTR_UPPER_CASE,
  CB_INTR_USER_FUNCTION, CB_INTR_VARIANCE, CB_INTR_WHEN_COMPILED, CB_INTR_YEAR_TO_YYYY,
  CB_INTR_ABS = 1, CB_INTR_ACOS, CB_INTR_ANNUITY, CB_INTR_ASIN,
  CB_INTR_ATAN, CB_INTR_BOOLEAN_OF_INTEGER, CB_INTR_BYTE_LENGTH, CB_INTR_CHAR,
  CB_INTR_CHAR_NATIONAL, CB_INTR_COMBINED_DATETIME, CB_INTR_CONCATENATE, CB_INTR_COS,
  CB_INTR_CURRENCY_SYMBOL, CB_INTR_CURRENT_DATE, CB_INTR_DATE_OF_INTEGER, CB_INTR_DATE_TO_YYYYMMDD,
  CB_INTR_DAY_OF_INTEGER, CB_INTR_DAY_TO_YYYYDDD, CB_INTR_DISPLAY_OF, CB_INTR_E,
  CB_INTR_EXCEPTION_FILE, CB_INTR_EXCEPTION_FILE_N, CB_INTR_EXCEPTION_LOCATION, CB_INTR_EXCEPTION_LOCATION_N,
  CB_INTR_EXCEPTION_STATEMENT, CB_INTR_EXCEPTION_STATUS, CB_INTR_EXP, CB_INTR_EXP10,
  CB_INTR_FACTORIAL, CB_INTR_FORMATTED_CURRENT_DATE, CB_INTR_FORMATTED_DATE, CB_INTR_FORMATTED_DATETIME,
  CB_INTR_FORMATTED_TIME, CB_INTR_FRACTION_PART, CB_INTR_HIGHEST_ALGEBRAIC, CB_INTR_INTEGER,
  CB_INTR_INTEGER_OF_BOOLEAN, CB_INTR_INTEGER_OF_DATE, CB_INTR_INTEGER_OF_DAY, CB_INTR_INTEGER_OF_FORMATTED_DATE,
  CB_INTR_INTEGER_PART, CB_INTR_LENGTH, CB_INTR_LOCALE_COMPARE, CB_INTR_LOCALE_DATE,
  CB_INTR_LOCALE_TIME, CB_INTR_LOCALE_TIME_FROM_SECS, CB_INTR_LOG, CB_INTR_LOG10,
  CB_INTR_LOWER_CASE, CB_INTR_LOWEST_ALGEBRAIC, CB_INTR_MAX, CB_INTR_MEAN,
  CB_INTR_MEDIAN, CB_INTR_MIDRANGE, CB_INTR_MIN, CB_INTR_MOD,
  CB_INTR_MODULE_CALLER_ID, CB_INTR_MODULE_DATE, CB_INTR_MODULE_FORMATTED_DATE, CB_INTR_MODULE_ID,
  CB_INTR_MODULE_PATH, CB_INTR_MODULE_SOURCE, CB_INTR_MODULE_TIME, CB_INTR_MON_DECIMAL_POINT,
  CB_INTR_MON_THOUSANDS_SEP, CB_INTR_NATIONAL_OF, CB_INTR_NUM_DECIMAL_POINT, CB_INTR_NUM_THOUSANDS_SEP,
  CB_INTR_NUMVAL, CB_INTR_NUMVAL_C, CB_INTR_NUMVAL_F, CB_INTR_ORD,
  CB_INTR_ORD_MAX, CB_INTR_ORD_MIN, CB_INTR_PI, CB_INTR_PRESENT_VALUE,
  CB_INTR_RANDOM, CB_INTR_RANGE, CB_INTR_REM, CB_INTR_REVERSE,
  CB_INTR_SECONDS_FROM_FORMATTED_TIME, CB_INTR_SECONDS_PAST_MIDNIGHT, CB_INTR_SIGN, CB_INTR_SIN,
  CB_INTR_SQRT, CB_INTR_STANDARD_COMPARE, CB_INTR_STANDARD_DEVIATION, CB_INTR_STORED_CHAR_LENGTH,
  CB_INTR_SUBSTITUTE, CB_INTR_SUBSTITUTE_CASE, CB_INTR_SUM, CB_INTR_TAN,
  CB_INTR_TEST_DATE_YYYYMMDD, CB_INTR_TEST_DAY_YYYYDDD, CB_INTR_TEST_FORMATTED_DATETIME, CB_INTR_TEST_NUMVAL,
  CB_INTR_TEST_NUMVAL_C, CB_INTR_TEST_NUMVAL_F, CB_INTR_TRIM, CB_INTR_UPPER_CASE,
  CB_INTR_USER_FUNCTION, CB_INTR_VARIANCE, CB_INTR_WHEN_COMPILED, CB_INTR_YEAR_TO_YYYY
}
 
enum  cb_perform_type {
  CB_PERFORM_EXIT = 0, CB_PERFORM_ONCE, CB_PERFORM_TIMES, CB_PERFORM_UNTIL,
  CB_PERFORM_FOREVER, CB_PERFORM_EXIT = 0, CB_PERFORM_ONCE, CB_PERFORM_TIMES,
  CB_PERFORM_UNTIL, CB_PERFORM_FOREVER, CB_PERFORM_EXIT = 0, CB_PERFORM_ONCE,
  CB_PERFORM_TIMES, CB_PERFORM_UNTIL, CB_PERFORM_FOREVER
}
 

Functions

COB_EXPIMP void print_runtime_env (void)
 
COB_EXPIMP void print_info (void)
 
COB_EXPIMP void print_version (void)
 
char * cob_int_to_string (int, char *)
 
char * cob_int_to_formatted_bytestring (int, char *)
 
char * cob_strcat (char *, char *)
 
char * cob_strjoin (char **, int, char *)
 
COB_EXPIMP cob_globalcob_get_global_ptr (void)
 
COB_EXPIMP void cob_init (const int, char **)
 
COB_EXPIMP void cob_module_enter (cob_module **, cob_global **, const int)
 
COB_EXPIMP void cob_module_leave (cob_module *)
 
DECLNORET COB_EXPIMP void cob_stop_run (const int) COB_A_NORETURN
 
DECLNORET COB_EXPIMP void cob_fatal_error (const int) COB_A_NORETURN
 
COB_EXPIMP void * cob_malloc (const size_t) COB_A_MALLOC
 
COB_EXPIMP void cob_free (void *)
 
COB_EXPIMP void * cob_fast_malloc (const size_t) COB_A_MALLOC
 
COB_EXPIMP void * cob_cache_malloc (const size_t) COB_A_MALLOC
 
COB_EXPIMP void * cob_cache_realloc (void *, const size_t)
 
COB_EXPIMP void cob_cache_free (void *)
 
COB_EXPIMP void cob_set_locale (cob_field *, const int)
 
COB_EXPIMP void cob_check_version (const char *, const char *, const int)
 
COB_EXPIMP void * cob_save_func (cob_field **, const int, const int,...)
 
COB_EXPIMP void cob_restore_func (struct cob_func_loc *)
 
COB_EXPIMP void cob_accept_arg_number (cob_field *)
 
COB_EXPIMP void cob_accept_arg_value (cob_field *)
 
COB_EXPIMP void cob_accept_command_line (cob_field *)
 
COB_EXPIMP void cob_accept_date (cob_field *)
 
COB_EXPIMP void cob_accept_date_yyyymmdd (cob_field *)
 
COB_EXPIMP void cob_accept_day (cob_field *)
 
COB_EXPIMP void cob_accept_day_yyyyddd (cob_field *)
 
COB_EXPIMP void cob_accept_day_of_week (cob_field *)
 
COB_EXPIMP void cob_accept_environment (cob_field *)
 
COB_EXPIMP void cob_accept_exception_status (cob_field *)
 
COB_EXPIMP void cob_accept_time (cob_field *)
 
COB_EXPIMP void cob_accept_user_name (cob_field *)
 
COB_EXPIMP void cob_display_command_line (cob_field *)
 
COB_EXPIMP void cob_display_environment (const cob_field *)
 
COB_EXPIMP void cob_display_env_value (const cob_field *)
 
COB_EXPIMP void cob_display_arg_number (cob_field *)
 
COB_EXPIMP void cob_get_environment (const cob_field *, cob_field *)
 
COB_EXPIMP void cob_set_environment (const cob_field *, const cob_field *)
 
COB_EXPIMP void cob_chain_setup (void *, const size_t, const size_t)
 
COB_EXPIMP void cob_allocate (unsigned char **, cob_field *, cob_field *, cob_field *)
 
COB_EXPIMP void cob_free_alloc (unsigned char **, unsigned char *)
 
COB_EXPIMP int cob_extern_init (void)
 
COB_EXPIMP int cob_tidy (void)
 
COB_EXPIMP void * cob_command_line (int, int *, char ***, char ***, char **)
 
COB_EXPIMP char * cob_getenv (const char *)
 
COB_EXPIMP int cob_putenv (char *)
 
COB_EXPIMP void cob_incr_temp_iteration (void)
 
COB_EXPIMP void cob_temp_name (char *, const char *)
 
COB_EXPIMP int cob_sys_exit_proc (const void *, const void *)
 
COB_EXPIMP int cob_sys_error_proc (const void *, const void *)
 
COB_EXPIMP int cob_sys_system (const void *)
 
COB_EXPIMP int cob_sys_and (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_or (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_nor (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_xor (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_imp (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_nimp (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_eq (const void *, void *, const int)
 
COB_EXPIMP int cob_sys_not (void *, const int)
 
COB_EXPIMP int cob_sys_xf4 (void *, const void *)
 
COB_EXPIMP int cob_sys_xf5 (const void *, void *)
 
COB_EXPIMP int cob_sys_x91 (void *, const void *, void *)
 
COB_EXPIMP int cob_sys_toupper (void *, const int)
 
COB_EXPIMP int cob_sys_tolower (void *, const int)
 
COB_EXPIMP int cob_sys_oc_nanosleep (const void *)
 
COB_EXPIMP int cob_sys_getpid (void)
 
COB_EXPIMP int cob_sys_return_args (void *)
 
COB_EXPIMP int cob_sys_parameter_size (void *)
 
COB_EXPIMP int cob_sys_getopt_long_long (void *, void *, void *, const int, void *, void *)
 
COB_EXPIMP int cob_sys_sleep (const void *)
 
COB_EXPIMP int cob_sys_calledby (void *)
 
COB_EXPIMP int cob_sys_justify (void *,...)
 
COB_EXPIMP int cob_sys_printable (void *,...)
 
COB_EXPIMP void cob_set_location (const char *, const unsigned int, const char *, const char *, const char *)
 
COB_EXPIMP void cob_trace_section (const char *, const char *, const int)
 
COB_EXPIMP void * cob_external_addr (const char *, const int)
 
COB_EXPIMP unsigned char * cob_get_pointer (const void *)
 
COB_EXPIMP void * cob_get_prog_pointer (const void *)
 
COB_EXPIMP void cob_ready_trace (void)
 
COB_EXPIMP void cob_reset_trace (void)
 
COB_EXPIMP void cob_reg_sighnd (void(*sighnd)(int))
 
COB_EXPIMP int cob_get_switch (const int)
 
COB_EXPIMP void cob_set_switch (const int, const int)
 
COB_EXPIMP int cob_cmp (cob_field *, cob_field *)
 
COB_EXPIMP int cob_is_omitted (const cob_field *)
 
COB_EXPIMP int cob_is_numeric (const cob_field *)
 
COB_EXPIMP int cob_is_alpha (const cob_field *)
 
COB_EXPIMP int cob_is_upper (const cob_field *)
 
COB_EXPIMP int cob_is_lower (const cob_field *)
 
COB_EXPIMP void cob_table_sort_init (const size_t, const unsigned char *)
 
COB_EXPIMP void cob_table_sort_init_key (cob_field *, const int, const unsigned int)
 
COB_EXPIMP void cob_table_sort (cob_field *, const int)
 
COB_EXPIMP void cob_check_numeric (const cob_field *, const char *)
 
COB_EXPIMP void cob_correct_numeric (cob_field *)
 
COB_EXPIMP void cob_check_based (const unsigned char *, const char *)
 
COB_EXPIMP void cob_check_odo (const int, const int, const int, const char *)
 
COB_EXPIMP void cob_check_subscript (const int, const int, const int, const char *)
 
COB_EXPIMP void cob_check_ref_mod (const int, const int, const int, const char *)
 
COB_EXPIMP int cob_numeric_cmp (cob_field *, cob_field *)
 
COB_EXPIMP void cob_inspect_init (cob_field *, const cob_u32_t)
 
COB_EXPIMP void cob_inspect_start (void)
 
COB_EXPIMP void cob_inspect_before (const cob_field *)
 
COB_EXPIMP void cob_inspect_after (const cob_field *)
 
COB_EXPIMP void cob_inspect_characters (cob_field *)
 
COB_EXPIMP void cob_inspect_all (cob_field *, cob_field *)
 
COB_EXPIMP void cob_inspect_leading (cob_field *, cob_field *)
 
COB_EXPIMP void cob_inspect_first (cob_field *, cob_field *)
 
COB_EXPIMP void cob_inspect_trailing (cob_field *, cob_field *)
 
COB_EXPIMP void cob_inspect_converting (const cob_field *, const cob_field *)
 
COB_EXPIMP void cob_inspect_finish (void)
 
COB_EXPIMP void cob_string_init (cob_field *, cob_field *)
 
COB_EXPIMP void cob_string_delimited (cob_field *)
 
COB_EXPIMP void cob_string_append (cob_field *)
 
COB_EXPIMP void cob_string_finish (void)
 
COB_EXPIMP void cob_unstring_init (cob_field *, cob_field *, const size_t)
 
COB_EXPIMP void cob_unstring_delimited (cob_field *, const cob_u32_t)
 
COB_EXPIMP void cob_unstring_into (cob_field *, cob_field *, cob_field *)
 
COB_EXPIMP void cob_unstring_tallying (cob_field *)
 
COB_EXPIMP void cob_unstring_finish (void)
 
COB_EXPIMP void cob_move (cob_field *, cob_field *)
 
COB_EXPIMP void cob_set_int (cob_field *, const int)
 
COB_EXPIMP int cob_get_int (cob_field *)
 
COB_EXPIMP cob_s64_t cob_get_llint (cob_field *)
 
COB_EXPIMP void cob_decimal_init (cob_decimal *)
 
COB_EXPIMP void cob_decimal_set_llint (cob_decimal *, const cob_s64_t)
 
COB_EXPIMP void cob_decimal_set_field (cob_decimal *, cob_field *)
 
COB_EXPIMP int cob_decimal_get_field (cob_decimal *, cob_field *, const int)
 
COB_EXPIMP void cob_decimal_add (cob_decimal *, cob_decimal *)
 
COB_EXPIMP void cob_decimal_sub (cob_decimal *, cob_decimal *)
 
COB_EXPIMP void cob_decimal_mul (cob_decimal *, cob_decimal *)
 
COB_EXPIMP void cob_decimal_div (cob_decimal *, cob_decimal *)
 
COB_EXPIMP void cob_decimal_pow (cob_decimal *, cob_decimal *)
 
COB_EXPIMP int cob_decimal_cmp (cob_decimal *, cob_decimal *)
 
COB_EXPIMP void cob_add (cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_sub (cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_mul (cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_div (cob_field *, cob_field *, const int)
 
COB_EXPIMP int cob_add_int (cob_field *, const int, const int)
 
COB_EXPIMP int cob_sub_int (cob_field *, const int, const int)
 
COB_EXPIMP void cob_div_quotient (cob_field *, cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_div_remainder (cob_field *, const int)
 
COB_EXPIMP int cob_cmp_int (cob_field *, const int)
 
COB_EXPIMP int cob_cmp_uint (cob_field *, const unsigned int)
 
COB_EXPIMP int cob_cmp_llint (cob_field *, const cob_s64_t)
 
COB_EXPIMP int cob_cmp_packed (cob_field *, const cob_s64_t)
 
COB_EXPIMP int cob_cmp_numdisp (const unsigned char *, const size_t, const cob_s64_t, const cob_u32_t)
 
COB_EXPIMP int cob_cmp_float (cob_field *, cob_field *)
 
COB_EXPIMP void cob_set_packed_zero (cob_field *)
 
COB_EXPIMP void cob_set_packed_int (cob_field *, const int)
 
COB_EXPIMP void cob_decimal_alloc (const cob_u32_t,...)
 
COB_EXPIMP void cob_decimal_push (const cob_u32_t,...)
 
COB_EXPIMP void cob_decimal_pop (const cob_u32_t,...)
 
COB_EXPIMP void cob_gmp_free (void *)
 
DECLNORET COB_EXPIMP void cob_call_error (void) COB_A_NORETURN
 
COB_EXPIMP void cob_set_cancel (cob_module *)
 
COB_EXPIMP void * cob_resolve (const char *)
 
COB_EXPIMP void * cob_resolve_cobol (const char *, const int, const int)
 
COB_EXPIMP void * cob_resolve_func (const char *)
 
COB_EXPIMP const char * cob_resolve_error (void)
 
COB_EXPIMP void * cob_call_field (const cob_field *, const struct cob_call_struct *, const unsigned int, const int)
 
COB_EXPIMP void cob_cancel_field (const cob_field *, const struct cob_call_struct *)
 
COB_EXPIMP void cob_cancel (const char *)
 
COB_EXPIMP int cob_call (const char *, const int, void **)
 
COB_EXPIMP int cob_func (const char *, const int, void **)
 
COB_EXPIMP void * cob_savenv (struct cobjmp_buf *)
 
COB_EXPIMP void * cob_savenv2 (struct cobjmp_buf *, const int)
 
COB_EXPIMP void cob_longjmp (struct cobjmp_buf *)
 
COB_EXPIMP void cob_screen_line_col (cob_field *, const int)
 
COB_EXPIMP void cob_screen_display (cob_screen *, cob_field *, cob_field *)
 
COB_EXPIMP void cob_screen_accept (cob_screen *, cob_field *, cob_field *, cob_field *)
 
COB_EXPIMP void cob_field_display (cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_field_accept (cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_accept_escape_key (cob_field *)
 
COB_EXPIMP int cob_sys_clear_screen (void)
 
COB_EXPIMP int cob_sys_sound_bell (void)
 
COB_EXPIMP int cob_sys_get_csr_pos (unsigned char *)
 
COB_EXPIMP int cob_sys_get_scr_size (unsigned char *, unsigned char *)
 
COB_EXPIMP void cob_display (const int, const int, const int,...)
 
COB_EXPIMP void cob_accept (cob_field *)
 
COB_EXPIMP void cob_open (cob_file *, const int, const int, cob_field *)
 
COB_EXPIMP void cob_close (cob_file *, cob_field *, const int, const int)
 
COB_EXPIMP void cob_read (cob_file *, cob_field *, cob_field *, const int)
 
COB_EXPIMP void cob_read_next (cob_file *, cob_field *, const int)
 
COB_EXPIMP void cob_rewrite (cob_file *, cob_field *, const int, cob_field *)
 
COB_EXPIMP void cob_delete (cob_file *, cob_field *)
 
COB_EXPIMP void cob_start (cob_file *, const int, cob_field *, cob_field *, cob_field *)
 
COB_EXPIMP void cob_write (cob_file *, cob_field *, const int, cob_field *, const unsigned int)
 
COB_EXPIMP void cob_delete_file (cob_file *, cob_field *)
 
COB_EXPIMP void cob_unlock_file (cob_file *, cob_field *)
 
COB_EXPIMP void cob_commit (void)
 
COB_EXPIMP void cob_rollback (void)
 
COB_EXPIMP int cob_sys_open_file (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_create_file (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_read_file (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_write_file (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_close_file (unsigned char *)
 
COB_EXPIMP int cob_sys_flush_file (unsigned char *)
 
COB_EXPIMP int cob_sys_delete_file (unsigned char *)
 
COB_EXPIMP int cob_sys_copy_file (unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_check_file_exist (unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_rename_file (unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_get_current_dir (const int, const int, unsigned char *)
 
COB_EXPIMP int cob_sys_change_dir (unsigned char *)
 
COB_EXPIMP int cob_sys_create_dir (unsigned char *)
 
COB_EXPIMP int cob_sys_delete_dir (unsigned char *)
 
COB_EXPIMP int cob_sys_chdir (unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_mkdir (unsigned char *)
 
COB_EXPIMP int cob_sys_copyfile (unsigned char *, unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_file_info (unsigned char *, unsigned char *)
 
COB_EXPIMP int cob_sys_file_delete (unsigned char *, unsigned char *)
 
COB_EXPIMP void cob_file_sort_init (cob_file *, const unsigned int, const unsigned char *, void *, cob_field *)
 
COB_EXPIMP void cob_file_sort_init_key (cob_file *, cob_field *, const int, const unsigned int)
 
COB_EXPIMP void cob_file_sort_close (cob_file *)
 
COB_EXPIMP void cob_file_sort_using (cob_file *, cob_file *)
 
COB_EXPIMP void cob_file_sort_giving (cob_file *, const size_t,...)
 
COB_EXPIMP void cob_file_release (cob_file *)
 
COB_EXPIMP void cob_file_return (cob_file *)
 
COB_EXPIMP void cob_put_indirect_field (cob_field *)
 
COB_EXPIMP void cob_get_indirect_field (cob_field *)
 
COB_EXPIMP cob_fieldcob_switch_value (const int)
 
COB_EXPIMP cob_fieldcob_intr_binop (cob_field *, const int, cob_field *)
 
COB_EXPIMP int cob_valid_date_format (const char *)
 
COB_EXPIMP int cob_valid_datetime_format (const char *)
 
COB_EXPIMP int cob_valid_time_format (const char *)
 
COB_EXPIMP cob_fieldcob_intr_current_date (const int, const int)
 
COB_EXPIMP cob_fieldcob_intr_when_compiled (const int, const int, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_module_date (void)
 
COB_EXPIMP cob_fieldcob_intr_module_time (void)
 
COB_EXPIMP cob_fieldcob_intr_module_id (void)
 
COB_EXPIMP cob_fieldcob_intr_module_caller_id (void)
 
COB_EXPIMP cob_fieldcob_intr_module_source (void)
 
COB_EXPIMP cob_fieldcob_intr_module_formatted_date (void)
 
COB_EXPIMP cob_fieldcob_intr_module_path (void)
 
COB_EXPIMP cob_fieldcob_intr_exception_file (void)
 
COB_EXPIMP cob_fieldcob_intr_exception_location (void)
 
COB_EXPIMP cob_fieldcob_intr_exception_status (void)
 
COB_EXPIMP cob_fieldcob_intr_exception_statement (void)
 
COB_EXPIMP cob_fieldcob_intr_mon_decimal_point (void)
 
COB_EXPIMP cob_fieldcob_intr_num_decimal_point (void)
 
COB_EXPIMP cob_fieldcob_intr_mon_thousands_sep (void)
 
COB_EXPIMP cob_fieldcob_intr_num_thousands_sep (void)
 
COB_EXPIMP cob_fieldcob_intr_currency_symbol (void)
 
COB_EXPIMP cob_fieldcob_intr_char (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_ord (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_stored_char_length (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_combined_datetime (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_date_of_integer (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_day_of_integer (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_integer_of_date (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_integer_of_day (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_test_date_yyyymmdd (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_test_day_yyyyddd (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_test_numval (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_test_numval_c (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_test_numval_f (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_factorial (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_pi (void)
 
COB_EXPIMP cob_fieldcob_intr_e (void)
 
COB_EXPIMP cob_fieldcob_intr_exp (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_exp10 (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_abs (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_acos (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_asin (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_atan (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_cos (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_log (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_log10 (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_sin (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_sqrt (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_tan (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_upper_case (const int, const int, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_lower_case (const int, const int, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_reverse (const int, const int, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_concatenate (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_substitute (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_substitute_case (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_trim (const int, const int, cob_field *, const int)
 
COB_EXPIMP cob_fieldcob_intr_length (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_byte_length (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_integer (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_integer_part (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_fraction_part (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_sign (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_lowest_algebraic (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_highest_algebraic (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_numval (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_numval_c (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_numval_f (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_annuity (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_mod (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_rem (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_sum (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_ord_min (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_ord_max (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_min (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_max (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_midrange (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_median (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_mean (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_range (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_random (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_variance (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_standard_deviation (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_present_value (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_year_to_yyyy (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_date_to_yyyymmdd (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_day_to_yyyyddd (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_locale_compare (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_locale_date (const int, const int, cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_locale_time (const int, const int, cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_seconds_past_midnight (void)
 
COB_EXPIMP cob_fieldcob_intr_lcl_time_from_secs (const int, const int, cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_seconds_from_formatted_time (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_boolean_of_integer (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_char_national (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_display_of (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_exception_file_n (void)
 
COB_EXPIMP cob_fieldcob_intr_exception_location_n (void)
 
COB_EXPIMP cob_fieldcob_intr_formatted_current_date (const int, const int, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_formatted_date (const int, const int, cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_formatted_datetime (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_formatted_time (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_integer_of_boolean (cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_national_of (const int, const int, const int,...)
 
COB_EXPIMP cob_fieldcob_intr_standard_compare (const int,...)
 
COB_EXPIMP cob_fieldcob_intr_test_formatted_datetime (cob_field *, cob_field *)
 
COB_EXPIMP cob_fieldcob_intr_integer_of_formatted_date (cob_field *, cob_field *)
 
static const char * pgettext_aux (const char *domain, const char *msg_ctxt_id, const char *msgid, int category)
 
static const char * npgettext_aux (const char *domain, const char *msg_ctxt_id, const char *msgid, const char *msgid_plural, unsigned long int n, int category)
 
static const char * dcpgettext_expr (const char *domain, const char *msgctxt, const char *msgid, int category)
 
static const char * dcnpgettext_expr (const char *domain, const char *msgctxt, const char *msgid, const char *msgid_plural, unsigned long int n, int category)
 
 CB_FLAG_RQ (cb_stack_size, 0,"stack-size", 255, 1, _("Define PERFORM stack size\n\t\t\t- Default : 255")) CB_FLAG_RQ(cb_if_cutoff
 
if _ ("Define cutoff depth for IF statements\n\t\t\t- Default : 3")) CB_FLAG_RQ(cb_ebcdic_sign
 
if _ ("Define display sign representation\n\t\t\t- ASCII or EBCDIC (Default : machine native)")) CB_FLAG_RQ(cb_fold_copy
 
if fold _ ("Fold COPY subject to value\n\t\t\t- UPPER or LOWER (Default : no transformation)")) CB_FLAG_RQ(cb_fold_call
 
if fold fold _ ("Fold PROGRAM-ID, CALL, CANCEL subject to value\n\t\t\t- UPPER or LOWER (Default : no transformation)")) CB_FLAG_RQ(cb_default_byte
 
if fold fold _ ("Initialize fields without VALUE to decimal value\n\t\t\t- 0 to 255 (Default : initialize to picture)")) CB_FLAG_NQ(1
 
if fold fold _ ("Intrinsics to be used without FUNCTION keyword\n\t\t\t- ALL or intrinsic function name (,name,...)")) CB_FLAG(cb_flag_static_call
 
if fold fold static _ ("Output static function calls for the CALL statement")) CB_FLAG(cb_flag_computed_goto
 
if fold fold static computed _ ("Generate computed goto C statements")) CB_FLAG(cb_flag_alt_ebcdic
 
if fold fold static computed
alternate 
_ ("Use restricted ASCII to EBCDIC translate")) CB_FLAG(cb_flag_extra_brace
 
if fold fold static computed
alternate extra 
_ ("Generate extra braces in generated C code")) CB_FLAG(cb_flag_correct_numeric
 
if fold fold static computed
alternate extra correct 
_ ("Attempt correction of invalid numeric display items")) CB_FLAG(cb_flag_stack_on_heap
 
if fold fold static computed
alternate extra correct stack
on 
_ ("PERFORM stack allocated on heap")) CB_FLAG(cb_flag_trace
 
if fold fold static computed
alternate extra correct stack
on 
_ ("Generate trace code\n\t\t\t- Executed SECTION/PARAGRAPH")) CB_FLAG(cb_flag_traceall
 
if fold fold static computed
alternate extra correct stack
on 
_ ("Generate trace code\n\t\t\t- Executed SECTION/PARAGRAPH/STATEMENTS\n\t\t\t- Turned on by -debug")) CB_FLAG(cb_flag_syntax_only
 
if fold fold static computed
alternate extra correct stack
on syntax 
_ ("Syntax error checking only; don't emit any output")) CB_FLAG(cb_flag_debugging_line
 
if fold fold static computed
alternate extra correct stack
on syntax debugging 
_ ("Enable debugging lines\n\t\t\t- 'D' in indicator column or floating >>D")) CB_FLAG(cb_flag_source_location
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source 
_ ("Generate source location code\n\t\t\t- Turned on by -debug/-g/-ftraceall")) CB_FLAG(cb_flag_implicit_init
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit 
_ ("Automatic initialization of the Cobol runtime system")) CB_FLAG(cb_flag_stack_check
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack 
_ ("PERFORM stack checking\n\t\t\t- Turned on by -debug or -g")) CB_FLAG(cb_flag_syntax_extension
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax 
_ ("Allow syntax extensions\n\t\t\t- eg. Switch name SW1, etc.")) CB_FLAG(cb_flag_write_after
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write 
_ ("Use AFTER 1 for WRITE of LINE SEQUENTIAL\n\t\t\t- Default : BEFORE 1")) CB_FLAG(cb_flag_mfcomment
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write 
_ ("'*' or '/' in column 1 treated as comment\n\t\t\t- FIXED format only")) CB_FLAG(cb_flag_acucomment
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write 
_ ("'$' in indicator area treated as '*',\n\t\t\t'|' treated as floating comment")) CB_FLAG(cb_flag_notrunc
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write 
_ ("Allow numeric field overflow\n\t\t\t- Non-ANSI behaviour")) CB_FLAG(cb_flag_odoslide
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write 
_ ("Adjust items following OCCURS DEPENDING\n\t\t\t- Requires implicit/explicit relaxed syntax")) CB_FLAG(cb_flag_apostrophe
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single 
_ ("Use a single quote (apostrophe) for QUOTE\n\t\t\t- Default : double quote")) CB_FLAG(cb_flag_recursive
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive 
_ ("Check recursive program call")) CB_FLAG(cb_flag_relaxed_syntax
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax 
_ ("Relax syntax checking\n\t\t\t- eg. REDEFINES position")) CB_FLAG(cb_flag_optional_file
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Treat all files as OPTIONAL\n\t\t\t- unless NOT OPTIONAL specified")) CB_WARNDEF(cb_warn_obsolete
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn if obsolete features are used")) CB_WARNDEF(cb_warn_archaic
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn if archaic features are used")) CB_WARNDEF(cb_warn_redefinition
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn incompatible redefinition of data items")) CB_WARNDEF(cb_warn_constant
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn inconsistent constant")) CB_WARNDEF(cb_warn_overlap
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn overlapping MOVE items")) CB_WARNDEF(cb_warn_parentheses
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
_ ("Warn lack of parentheses around AND within OR")) CB_WARNDEF(cb_warn_strict_typing
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict 
_ ("Warn type mismatch strictly")) CB_WARNDEF(cb_warn_implicit_define
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit 
_ ("Warn implicitly defined data items")) CB_WARNDEF(cb_warn_corresponding
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit 
_ ("Warn CORRESPONDING with no matching items")) CB_WARNDEF(cb_warn_external_val
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external 
_ ("Warn EXTERNAL item with VALUE clause")) CB_NOWARNDEF(cb_warn_call_params
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call 
_ ("Warn non 01/77 items for CALL params")) CB_NOWARNDEF(cb_warn_column_overflow
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
_ ("Warn text after column 72, FIXED format")) CB_NOWARNDEF(cb_warn_terminator
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
_ ("Warn lack of scope terminator END-XXX")) CB_NOWARNDEF(cb_warn_truncate
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
_ ("Warn possible field truncation")) CB_NOWARNDEF(cb_warn_linkage
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
_ ("Warn dangling LINKAGE items")) CB_NOWARNDEF(cb_warn_unreachable
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
_ ("Warn unreachable statements")) enum cb_optim
 
void * cobc_malloc (const size_t)
 memory allocation for use when compiling More...
 
void cobc_free (void *)
 deallocation of compile time memory More...
 
void * cobc_strdup (const char *)
 safely duplicate a character array More...
 
void * cobc_realloc (void *, const size_t)
 
void * cobc_main_malloc (const size_t)
 
void * cobc_main_strdup (const char *)
 
void * cobc_main_realloc (void *, const size_t)
 
void cobc_main_free (void *)
 
void * cobc_parse_malloc (const size_t)
 
void * cobc_parse_strdup (const char *)
 
void * cobc_parse_realloc (void *, const size_t)
 
void cobc_parse_free (void *)
 
void * cobc_plex_malloc (const size_t)
 
void * cobc_plex_strdup (const char *)
 
void * cobc_check_string (const char *)
 
void cobc_abort_pr (const char *,...) COB_A_FORMAT12
 
DECLNORET void cobc_abort (const char *, const int) COB_A_NORETURN
 
DECLNORET void cobc_too_many_errors (void) COB_A_NORETURN
 
DECLNORET void cobc_dumb_abort (const char *, const int)
 
size_t cobc_check_valid_name (const char *, const unsigned int)
 
int cb_load_std (const char *)
 
int cb_config_entry (char *, const char *, const int)
 
int cb_load_conf (const char *, const int, const int)
 
int ppparse (void)
 
int ppopen (const char *, struct cb_replace_list *)
 
int ppcopy (const char *, const char *, struct cb_replace_list *)
 
void pp_set_replace_list (struct cb_replace_list *, const cob_u32_t)
 
void ppparse_error (const char *)
 
void ppparse_clear_vars (const struct cb_define_struct *)
 
void plex_clear_vars (void)
 
void plex_clear_all (void)
 
void plex_call_destroy (void)
 
void plex_action_directive (const unsigned int, const unsigned int)
 
int yyparse (void)
 
void ylex_clear_all (void)
 
void ylex_call_destroy (void)
 
void cob_gen_optim (const enum cb_optim)
 
void cb_warning (const char *,...) COB_A_FORMAT12
 
void cb_error (const char *,...) COB_A_FORMAT12
 
void cb_plex_warning (const size_t, const char *,...) COB_A_FORMAT23
 
void cb_plex_error (const size_t, const char *,...) COB_A_FORMAT23
 
void configuration_error (const char *, const int, const char *,...) COB_A_FORMAT34
 
unsigned int cb_verify (const enum cb_support, const char *)
 
char * cb_name (cb_tree)
 
enum cb_class cb_tree_class (cb_tree)
 
enum cb_category cb_tree_category (cb_tree)
 
int cb_tree_type (const cb_tree, const struct cb_field *)
 
int cb_category_is_alpha (cb_tree)
 
int cb_fits_int (const cb_tree)
 
int cb_fits_long_long (const cb_tree)
 
int cb_get_int (const cb_tree)
 
cob_s64_t cb_get_long_long (const cb_tree)
 
cob_u64_t cb_get_u_long_long (const cb_tree)
 
void cb_init_constants (void)
 
cb_tree cb_int (const int)
 
cb_tree cb_int_hex (const int)
 
cb_tree cb_build_string (const void *, const size_t)
 
cb_tree cb_build_class_name (cb_tree, cb_tree)
 
cb_tree cb_build_locale_name (cb_tree, cb_tree)
 
cb_tree cb_build_numeric_literal (const int, const void *, const int)
 
cb_tree cb_build_alphanumeric_literal (const void *, const size_t)
 
cb_tree cb_build_numsize_literal (const void *, const size_t, const int)
 
cb_tree cb_concat_literals (const cb_tree, const cb_tree)
 
cb_tree cb_build_decimal (const int)
 
cb_tree cb_build_picture (const char *)
 
cb_tree cb_build_comment (const char *)
 
cb_tree cb_build_direct (const char *, const unsigned int)
 
cb_tree cb_build_debug (const cb_tree, const char *, const cb_tree)
 
cb_tree cb_build_debug_call (struct cb_label *)
 
struct cb_picturecb_build_binary_picture (const char *, const cob_u32_t, const cob_u32_t)
 
cb_tree cb_build_field (cb_tree)
 
cb_tree cb_build_implicit_field (cb_tree, const int)
 
cb_tree cb_build_constant (cb_tree, cb_tree)
 
void cb_build_symbolic_chars (const cb_tree, const cb_tree)
 
struct cb_fieldcb_field_add (struct cb_field *, struct cb_field *)
 
struct cb_fieldcb_field_founder (const struct cb_field *)
 
struct cb_fieldcb_field_variable_size (const struct cb_field *)
 
unsigned int cb_field_variable_address (const struct cb_field *)
 
int cb_field_subordinate (const struct cb_field *, const struct cb_field *)
 
cb_tree cb_build_label (cb_tree, struct cb_label *)
 
struct cb_filebuild_file (cb_tree)
 
void validate_file (struct cb_file *, cb_tree)
 
void finalize_file (struct cb_file *, struct cb_field *)
 
cb_tree cb_build_filler (void)
 
cb_tree cb_build_reference (const char *)
 
cb_tree cb_build_field_reference (struct cb_field *, cb_tree)
 
const char * cb_define (cb_tree, cb_tree)
 
char * cb_to_cname (const char *)
 
void cb_set_system_names (void)
 
cb_tree cb_ref (cb_tree)
 
cb_tree cb_build_binary_op (cb_tree, const int, cb_tree)
 
cb_tree cb_build_binary_list (cb_tree, const int)
 
cb_tree cb_build_funcall (const char *, const int, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree)
 
cb_tree cb_build_cast (const enum cb_cast_type, const cb_tree)
 
cb_tree cb_build_cast_int (const cb_tree)
 
cb_tree cb_build_cast_llint (const cb_tree)
 
cb_tree cb_build_assign (const cb_tree, const cb_tree)
 
cb_tree cb_build_intrinsic (cb_tree, cb_tree, cb_tree, const int)
 
cb_tree cb_build_any_intrinsic (cb_tree)
 
cb_tree cb_build_search (const int, const cb_tree, const cb_tree, const cb_tree, const cb_tree)
 
cb_tree cb_build_call (const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cb_tree, const cob_u32_t, const int)
 
cb_tree cb_build_alter (const cb_tree, const cb_tree)
 
cb_tree cb_build_cancel (const cb_tree)
 
cb_tree cb_build_goto (const cb_tree, const cb_tree)
 
cb_tree cb_build_if (const cb_tree, const cb_tree, const cb_tree, const unsigned int)
 
cb_tree cb_build_perform (const enum cb_perform_type)
 
cb_tree cb_build_perform_varying (cb_tree, cb_tree, cb_tree, cb_tree)
 
struct cb_statementcb_build_statement (const char *)
 
cb_tree cb_build_continue (void)
 
cb_tree cb_build_list (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_list_add (cb_tree, cb_tree)
 
cb_tree cb_pair_add (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_list_append (cb_tree, cb_tree)
 
cb_tree cb_list_reverse (cb_tree)
 
int cb_list_length (cb_tree)
 
struct cb_reportbuild_report (cb_tree)
 
void cb_add_common_prog (struct cb_program *)
 
void cb_insert_common_prog (struct cb_program *, struct cb_program *)
 
struct cb_intrinsic_tablelookup_intrinsic (const char *, const int, const int)
 
cb_tree cb_build_alphabet_name (cb_tree)
 
cb_tree cb_build_initialize (const cb_tree, const cb_tree, const cb_tree, const unsigned int, const unsigned int, const unsigned int)
 
struct cb_literalbuild_literal (enum cb_category, const void *, const size_t)
 
cb_tree cb_build_system_name (const enum cb_system_name_category, const int)
 
struct cobc_reservedlookup_reserved_word (const char *)
 
cb_tree lookup_system_name (const char *)
 
void cb_list_reserved (void)
 
void cb_list_intrinsics (void)
 
void cb_list_mnemonics (void)
 
void cb_list_system (void)
 
void cb_list_map (cb_tree(*)(cb_tree), cb_tree)
 
void cb_warning_x (cb_tree, const char *,...) COB_A_FORMAT23
 
void cb_error_x (cb_tree, const char *,...) COB_A_FORMAT23
 
void redefinition_error (cb_tree)
 
void redefinition_warning (cb_tree, cb_tree)
 
void undefined_error (cb_tree)
 
void ambiguous_error (cb_tree)
 
void group_error (cb_tree, const char *)
 
void level_redundant_error (cb_tree, const char *)
 
void level_require_error (cb_tree, const char *)
 
void level_except_error (cb_tree, const char *)
 
int cb_get_level (cb_tree)
 
cb_tree cb_build_field_tree (cb_tree, cb_tree, struct cb_field *, enum cb_storage, struct cb_file *, const int)
 
struct cb_fieldcb_resolve_redefines (struct cb_field *, cb_tree)
 
void cb_validate_field (struct cb_field *)
 
void cb_validate_88_item (struct cb_field *)
 
struct cb_fieldcb_validate_78_item (struct cb_field *, const cob_u32_t)
 
struct cb_fieldcb_get_real_field (void)
 
void cb_clear_real_field (void)
 
struct cb_programcb_build_program (struct cb_program *, const int)
 
cb_tree cb_check_numeric_value (cb_tree)
 
size_t cb_check_index_p (cb_tree x)
 
void cb_build_registers (void)
 
void cb_build_debug_item (void)
 
void cb_check_field_debug (cb_tree)
 
char * cb_encode_program_id (const char *)
 
char * cb_build_program_id (cb_tree, cb_tree, const cob_u32_t)
 
cb_tree cb_define_switch_name (cb_tree, cb_tree, const int)
 
cb_tree cb_build_section_name (cb_tree, const int)
 
cb_tree cb_build_assignment_name (struct cb_file *, cb_tree)
 
cb_tree cb_build_index (cb_tree, cb_tree, const unsigned int, struct cb_field *)
 
cb_tree cb_build_identifier (cb_tree, const int)
 
cb_tree cb_build_length (cb_tree)
 
cb_tree cb_build_const_length (cb_tree)
 
cb_tree cb_build_address (cb_tree)
 
cb_tree cb_build_ppointer (cb_tree)
 
void cb_validate_program_environment (struct cb_program *)
 
void cb_validate_program_data (struct cb_program *)
 
void cb_validate_program_body (struct cb_program *)
 
cb_tree cb_build_expr (cb_tree)
 
cb_tree cb_build_cond (cb_tree)
 
void cb_emit_arithmetic (cb_tree, const int, cb_tree)
 
cb_tree cb_build_add (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_sub (cb_tree, cb_tree, cb_tree)
 
void cb_emit_corresponding (cb_tree(*)(cb_tree, cb_tree, cb_tree), cb_tree, cb_tree, cb_tree)
 
void cb_emit_move_corresponding (cb_tree, cb_tree)
 
void cb_emit_accept (cb_tree, cb_tree, struct cb_attr_struct *)
 
void cb_emit_accept_line_or_col (cb_tree, const int)
 
void cb_emit_accept_escape_key (cb_tree)
 
void cb_emit_accept_exception_status (cb_tree)
 
void cb_emit_accept_user_name (cb_tree)
 
void cb_emit_accept_date (cb_tree)
 
void cb_emit_accept_date_yyyymmdd (cb_tree)
 
void cb_emit_accept_day (cb_tree)
 
void cb_emit_accept_day_yyyyddd (cb_tree)
 
void cb_emit_accept_day_of_week (cb_tree)
 
void cb_emit_accept_time (cb_tree)
 
void cb_emit_accept_command_line (cb_tree)
 
void cb_emit_accept_environment (cb_tree)
 
void cb_emit_accept_mnemonic (cb_tree, cb_tree)
 
void cb_emit_accept_name (cb_tree, cb_tree)
 
void cb_emit_accept_arg_number (cb_tree)
 
void cb_emit_accept_arg_value (cb_tree)
 
void cb_emit_get_environment (cb_tree, cb_tree)
 
void cb_emit_allocate (cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_alter (cb_tree, cb_tree)
 
void cb_emit_free (cb_tree)
 
void cb_emit_call (cb_tree, cb_tree, cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_cancel (cb_tree)
 
void cb_emit_close (cb_tree, cb_tree)
 
void cb_emit_commit (void)
 
void cb_emit_continue (void)
 
void cb_emit_delete (cb_tree)
 
void cb_emit_delete_file (cb_tree)
 
void cb_emit_display (cb_tree, cb_tree, cb_tree, cb_tree, struct cb_attr_struct *)
 
cb_tree cb_build_display_mnemonic (cb_tree)
 
cb_tree cb_build_display_name (cb_tree)
 
void cb_emit_env_name (cb_tree)
 
void cb_emit_env_value (cb_tree)
 
void cb_emit_arg_number (cb_tree)
 
void cb_emit_command_line (cb_tree)
 
void cb_emit_divide (cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_evaluate (cb_tree, cb_tree)
 
void cb_emit_goto (cb_tree, cb_tree)
 
void cb_emit_exit (const unsigned int)
 
void cb_emit_if (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_if_check_break (cb_tree, cb_tree)
 
void cb_emit_initialize (cb_tree, cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_inspect (cb_tree, cb_tree, cb_tree, const unsigned int)
 
void cb_init_tallying (void)
 
cb_tree cb_build_tallying_data (cb_tree)
 
cb_tree cb_build_tallying_characters (cb_tree)
 
cb_tree cb_build_tallying_all (void)
 
cb_tree cb_build_tallying_leading (void)
 
cb_tree cb_build_tallying_trailing (void)
 
cb_tree cb_build_tallying_value (cb_tree, cb_tree)
 
cb_tree cb_build_replacing_characters (cb_tree, cb_tree)
 
cb_tree cb_build_replacing_all (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_replacing_leading (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_replacing_first (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_replacing_trailing (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_converting (cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_inspect_region_start (void)
 
int validate_move (cb_tree, cb_tree, const unsigned int)
 
cb_tree cb_build_move (cb_tree, cb_tree)
 
void cb_emit_move (cb_tree, cb_tree)
 
void cb_emit_open (cb_tree, cb_tree, cb_tree)
 
void cb_emit_perform (cb_tree, cb_tree)
 
cb_tree cb_build_perform_once (cb_tree)
 
cb_tree cb_build_perform_times (cb_tree)
 
cb_tree cb_build_perform_until (cb_tree, cb_tree)
 
cb_tree cb_build_perform_forever (cb_tree)
 
cb_tree cb_build_perform_exit (struct cb_label *)
 
void cb_emit_read (cb_tree, cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_ready_trace (void)
 
void cb_emit_rewrite (cb_tree, cb_tree, cb_tree)
 
void cb_emit_release (cb_tree, cb_tree)
 
void cb_emit_reset_trace (void)
 
void cb_emit_return (cb_tree, cb_tree)
 
void cb_emit_rollback (void)
 
void cb_emit_search (cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_search_all (cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_setenv (cb_tree, cb_tree)
 
void cb_emit_set_to (cb_tree, cb_tree)
 
void cb_emit_set_up_down (cb_tree, cb_tree, cb_tree)
 
void cb_emit_set_on_off (cb_tree, cb_tree)
 
void cb_emit_set_true (cb_tree)
 
void cb_emit_set_false (cb_tree)
 
void cb_emit_set_attribute (cb_tree, const int, const int)
 
cb_tree cb_build_set_attribute (const struct cb_field *, const int, const int)
 
void cb_emit_sort_init (cb_tree, cb_tree, cb_tree)
 
void cb_emit_sort_using (cb_tree, cb_tree)
 
void cb_emit_sort_input (cb_tree)
 
void cb_emit_sort_giving (cb_tree, cb_tree)
 
void cb_emit_sort_output (cb_tree)
 
void cb_emit_sort_finish (cb_tree)
 
void cb_emit_start (cb_tree, cb_tree, cb_tree, cb_tree)
 
void cb_emit_stop_run (cb_tree)
 
void cb_emit_string (cb_tree, cb_tree, cb_tree)
 
void cb_emit_unlock (cb_tree)
 
void cb_emit_unstring (cb_tree, cb_tree, cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_unstring_delimited (cb_tree, cb_tree)
 
cb_tree cb_build_unstring_into (cb_tree, cb_tree, cb_tree)
 
void cb_emit_write (cb_tree, cb_tree, cb_tree, cb_tree)
 
cb_tree cb_build_write_advancing_lines (cb_tree, cb_tree)
 
cb_tree cb_build_write_advancing_mnemonic (cb_tree, cb_tree)
 
cb_tree cb_build_write_advancing_page (cb_tree)
 
DECLNORET void cobc_tree_cast_error (const cb_tree, const char *, const int, const enum cb_tag) COB_A_NORETURN
 
void codegen (struct cb_program *, const int)
 
void cb_unput_dot (void)
 
void cb_add_78 (struct cb_field *)
 
void cb_reset_78 (void)
 
void cb_reset_global_78 (void)
 
struct cb_fieldcheck_level_78 (const char *)
 
int yyparse ()
 
static void read_literal (const int)
 
static int scan_x (char *, const int)
 
static int scan_z (char *, const int, const cob_u32_t)
 
static int scan_h (char *, const int)
 
static int scan_numeric (char *)
 
static int scan_floating_numeric (const char *)
 
static void scan_picture (char *)
 
static void count_lines (const char *)
 
static void scan_define_options (const char *)
 
static void scan_options (const char *, const unsigned int)
 
 cobc_free (var)
 
void ylex_clear_all (void)
 
void ylex_call_destroy (void)
 

Variables

option option case insensitive
option never interactive
option noyy_scan_buffer option
noyy_scan_bytes option
noyy_scan_string option
noyyget_extra option
noyyset_extra option
noyyget_leng option
noyyget_text option
noyyget_lineno option
noyyset_lineno option
noyyget_in option noyyset_in
option noyyget_out option
noyyset_out option
noyyget_lval option
noyyset_lval option
noyyget_lloc option
noyyset_lloc option
noyyget_debug option 
noyyset_debug
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
obsolete
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
archaic
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
redefinition
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
constant
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
overlap
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional 
parentheses
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict 
typing
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit 
define
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit 
corresponding
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external 
value
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call 
params
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
overflow
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
terminator
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
truncate
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
linkage
 
if fold fold static computed
alternate extra correct stack
on syntax debugging source
implicit stack syntax write
single recursive relax
optional strict implicit
external call column 
unreachable
 
cb_tree cb_any
 
cb_tree cb_true
 
cb_tree cb_false
 
cb_tree cb_null
 
cb_tree cb_zero
 
cb_tree cb_one
 
cb_tree cb_space
 
cb_tree cb_low
 
cb_tree cb_high
 
cb_tree cb_norm_low
 
cb_tree cb_norm_high
 
cb_tree cb_quote
 
cb_tree cb_int0
 
cb_tree cb_int1
 
cb_tree cb_int2
 
cb_tree cb_int3
 
cb_tree cb_int4
 
cb_tree cb_int5
 
cb_tree cb_i [COB_MAX_SUBSCRIPTS]
 
cb_tree cb_error_node
 
cb_tree cb_intr_whencomp
 
cb_tree cb_standard_error_handler
 
cb_tree cb_depend_check
 
unsigned int gen_screen_ptr
 
cb_tree cobc_printer_node
 
int non_const_word
 
unsigned int cobc_in_procedure
 
unsigned int cobc_in_repository
 
unsigned int cobc_force_literal
 
unsigned int cobc_cs_check
 
size_t cb_needs_01
 
cb_tree cb_debug_item
 
cb_tree cb_debug_line
 
cb_tree cb_debug_name
 
cb_tree cb_debug_sub_1
 
cb_tree cb_debug_sub_2
 
cb_tree cb_debug_sub_3
 
cb_tree cb_debug_contents
 
static struct cb_level_78top78ptr = NULL
 
static struct cb_level_78const78ptr = NULL
 
static struct cb_level_78lev78ptr = NULL
 
static struct cb_level_78globlev78ptr = NULL
 
static unsigned char * plexbuff = NULL
 
static char * picbuff1 = NULL
 
static char * picbuff2 = NULL
 
static size_t plexsize
 
static size_t pic1size
 
static size_t pic2size
 
static unsigned int last_token_is_dot = 0
 
static unsigned int integer_is_label = 0
 
static unsigned int inside_bracket = 0
 
static const unsigned char valid_char [256]
 
s DECIMAL_IS_PERIOD
DECIMAL_IS_COMMA x
PICTURE_STATE 
FUNCTION_STATE
 
freevar __pad0__
 

Macro Definition Documentation

#define COB_IN_SCANNER   1
#define SET_LOCATION (   x)
Value:
do { \
(x)->source_file = cb_source_file; \
(x)->source_line = cb_source_line; \
} while (0)
#define YY_BUF_SIZE   32768
#define YY_INPUT (   buf,
  result,
  max_size 
)
Value:
{ \
if (fgets (buf, (int)max_size, yyin) == NULL) { \
result = YY_NULL; \
} else { \
result = strlen (buf); \
} \
}
#define YY_READ_BUF_SIZE   32768
#define YY_SKIP_YYWRAP
#define YY_USER_INIT
Value:
if (!plexbuff) { \
plexbuff = cobc_malloc ((size_t)COB_MINI_BUFF); \
plexsize = COB_MINI_BUFF; \
} \
if (!picbuff1) { \
picbuff1 = cobc_malloc ((size_t)COB_MINI_BUFF); \
pic1size = COB_MINI_BUFF; \
} \
if (!picbuff2) { \
picbuff2 = cobc_malloc ((size_t)COB_MINI_BUFF); \
pic2size = COB_MINI_BUFF; \
}
#define yywrap ( )    1

Typedef Documentation

typedef struct cb_tree_common* cb_tree
typedef struct __cob_global cob_global
typedef struct __cob_module cob_module
typedef struct __cob_screen cob_screen

Enumeration Type Documentation

Enumerator
CB_CAST_INTEGER 
CB_CAST_LONG_INT 
CB_CAST_ADDRESS 
CB_CAST_ADDR_OF_ADDR 
CB_CAST_LENGTH 
CB_CAST_PROGRAM_POINTER 
CB_CAST_INTEGER 
CB_CAST_LONG_INT 
CB_CAST_ADDRESS 
CB_CAST_ADDR_OF_ADDR 
CB_CAST_LENGTH 
CB_CAST_PROGRAM_POINTER 
CB_CAST_INTEGER 
CB_CAST_LONG_INT 
CB_CAST_ADDRESS 
CB_CAST_ADDR_OF_ADDR 
CB_CAST_LENGTH 
CB_CAST_PROGRAM_POINTER 
271  {
272  /* Line directive */
273  char *p1;
274  char *p2;
275 
Enumerator
CB_CATEGORY_UNKNOWN 
CB_CATEGORY_ALPHABETIC 
CB_CATEGORY_ALPHANUMERIC 
CB_CATEGORY_ALPHANUMERIC_EDITED 
CB_CATEGORY_BOOLEAN 
CB_CATEGORY_INDEX 
CB_CATEGORY_NATIONAL 
CB_CATEGORY_NATIONAL_EDITED 
CB_CATEGORY_NUMERIC 
CB_CATEGORY_NUMERIC_EDITED 
CB_CATEGORY_OBJECT_REFERENCE 
CB_CATEGORY_DATA_POINTER 
CB_CATEGORY_PROGRAM_POINTER 
CB_CATEGORY_UNKNOWN 
CB_CATEGORY_ALPHABETIC 
CB_CATEGORY_ALPHANUMERIC 
CB_CATEGORY_ALPHANUMERIC_EDITED 
CB_CATEGORY_BOOLEAN 
CB_CATEGORY_INDEX 
CB_CATEGORY_NATIONAL 
CB_CATEGORY_NATIONAL_EDITED 
CB_CATEGORY_NUMERIC 
CB_CATEGORY_NUMERIC_EDITED 
CB_CATEGORY_OBJECT_REFERENCE 
CB_CATEGORY_DATA_POINTER 
CB_CATEGORY_PROGRAM_POINTER 
CB_CATEGORY_UNKNOWN 
CB_CATEGORY_ALPHABETIC 
CB_CATEGORY_ALPHANUMERIC 
CB_CATEGORY_ALPHANUMERIC_EDITED 
CB_CATEGORY_BOOLEAN 
CB_CATEGORY_INDEX 
CB_CATEGORY_NATIONAL 
CB_CATEGORY_NATIONAL_EDITED 
CB_CATEGORY_NUMERIC 
CB_CATEGORY_NUMERIC_EDITED 
CB_CATEGORY_OBJECT_REFERENCE 
CB_CATEGORY_DATA_POINTER 
CB_CATEGORY_PROGRAM_POINTER 
231  {
enum cb_class
Enumerator
CB_CLASS_UNKNOWN 
CB_CLASS_ALPHABETIC 
CB_CLASS_ALPHANUMERIC 
CB_CLASS_BOOLEAN 
CB_CLASS_INDEX 
CB_CLASS_NATIONAL 
CB_CLASS_NUMERIC 
CB_CLASS_OBJECT 
CB_CLASS_POINTER 
CB_CLASS_UNKNOWN 
CB_CLASS_ALPHABETIC 
CB_CLASS_ALPHANUMERIC 
CB_CLASS_BOOLEAN 
CB_CLASS_INDEX 
CB_CLASS_NATIONAL 
CB_CLASS_NUMERIC 
CB_CLASS_OBJECT 
CB_CLASS_POINTER 
CB_CLASS_UNKNOWN 
CB_CLASS_ALPHABETIC 
CB_CLASS_ALPHANUMERIC 
CB_CLASS_BOOLEAN 
CB_CLASS_INDEX 
CB_CLASS_NATIONAL 
CB_CLASS_NUMERIC 
CB_CLASS_OBJECT 
CB_CLASS_POINTER 
231  {
Enumerator
CB_INTR_ABS 
CB_INTR_ACOS 
CB_INTR_ANNUITY 
CB_INTR_ASIN 
CB_INTR_ATAN 
CB_INTR_BOOLEAN_OF_INTEGER 
CB_INTR_BYTE_LENGTH 
CB_INTR_CHAR 
CB_INTR_CHAR_NATIONAL 
CB_INTR_COMBINED_DATETIME 
CB_INTR_CONCATENATE 
CB_INTR_COS 
CB_INTR_CURRENCY_SYMBOL 
CB_INTR_CURRENT_DATE 
CB_INTR_DATE_OF_INTEGER 
CB_INTR_DATE_TO_YYYYMMDD 
CB_INTR_DAY_OF_INTEGER 
CB_INTR_DAY_TO_YYYYDDD 
CB_INTR_DISPLAY_OF 
CB_INTR_E 
CB_INTR_EXCEPTION_FILE 
CB_INTR_EXCEPTION_FILE_N 
CB_INTR_EXCEPTION_LOCATION 
CB_INTR_EXCEPTION_LOCATION_N 
CB_INTR_EXCEPTION_STATEMENT 
CB_INTR_EXCEPTION_STATUS 
CB_INTR_EXP 
CB_INTR_EXP10 
CB_INTR_FACTORIAL 
CB_INTR_FORMATTED_CURRENT_DATE 
CB_INTR_FORMATTED_DATE 
CB_INTR_FORMATTED_DATETIME 
CB_INTR_FORMATTED_TIME 
CB_INTR_FRACTION_PART 
CB_INTR_HIGHEST_ALGEBRAIC 
CB_INTR_INTEGER 
CB_INTR_INTEGER_OF_BOOLEAN 
CB_INTR_INTEGER_OF_DATE 
CB_INTR_INTEGER_OF_DAY 
CB_INTR_INTEGER_OF_FORMATTED_DATE 
CB_INTR_INTEGER_PART 
CB_INTR_LENGTH 
CB_INTR_LOCALE_COMPARE 
CB_INTR_LOCALE_DATE 
CB_INTR_LOCALE_TIME 
CB_INTR_LOCALE_TIME_FROM_SECS 
CB_INTR_LOG 
CB_INTR_LOG10 
CB_INTR_LOWER_CASE 
CB_INTR_LOWEST_ALGEBRAIC 
CB_INTR_MAX 
CB_INTR_MEAN 
CB_INTR_MEDIAN 
CB_INTR_MIDRANGE 
CB_INTR_MIN 
CB_INTR_MOD 
CB_INTR_MODULE_CALLER_ID 
CB_INTR_MODULE_DATE 
CB_INTR_MODULE_FORMATTED_DATE 
CB_INTR_MODULE_ID 
CB_INTR_MODULE_PATH 
CB_INTR_MODULE_SOURCE 
CB_INTR_MODULE_TIME 
CB_INTR_MON_DECIMAL_POINT 
CB_INTR_MON_THOUSANDS_SEP 
CB_INTR_NATIONAL_OF 
CB_INTR_NUM_DECIMAL_POINT 
CB_INTR_NUM_THOUSANDS_SEP 
CB_INTR_NUMVAL 
CB_INTR_NUMVAL_C 
CB_INTR_NUMVAL_F 
CB_INTR_ORD 
CB_INTR_ORD_MAX 
CB_INTR_ORD_MIN 
CB_INTR_PI 
CB_INTR_PRESENT_VALUE 
CB_INTR_RANDOM 
CB_INTR_RANGE 
CB_INTR_REM 
CB_INTR_REVERSE 
CB_INTR_SECONDS_FROM_FORMATTED_TIME 
CB_INTR_SECONDS_PAST_MIDNIGHT 
CB_INTR_SIGN 
CB_INTR_SIN 
CB_INTR_SQRT 
CB_INTR_STANDARD_COMPARE 
CB_INTR_STANDARD_DEVIATION 
CB_INTR_STORED_CHAR_LENGTH 
CB_INTR_SUBSTITUTE 
CB_INTR_SUBSTITUTE_CASE 
CB_INTR_SUM 
CB_INTR_TAN 
CB_INTR_TEST_DATE_YYYYMMDD 
CB_INTR_TEST_DAY_YYYYDDD 
CB_INTR_TEST_FORMATTED_DATETIME 
CB_INTR_TEST_NUMVAL 
CB_INTR_TEST_NUMVAL_C 
CB_INTR_TEST_NUMVAL_F 
CB_INTR_TRIM 
CB_INTR_UPPER_CASE 
CB_INTR_USER_FUNCTION 
CB_INTR_VARIANCE 
CB_INTR_WHEN_COMPILED 
CB_INTR_YEAR_TO_YYYY 
CB_INTR_ABS 
CB_INTR_ACOS 
CB_INTR_ANNUITY 
CB_INTR_ASIN 
CB_INTR_ATAN 
CB_INTR_BOOLEAN_OF_INTEGER 
CB_INTR_BYTE_LENGTH 
CB_INTR_CHAR 
CB_INTR_CHAR_NATIONAL 
CB_INTR_COMBINED_DATETIME 
CB_INTR_CONCATENATE 
CB_INTR_COS 
CB_INTR_CURRENCY_SYMBOL 
CB_INTR_CURRENT_DATE 
CB_INTR_DATE_OF_INTEGER 
CB_INTR_DATE_TO_YYYYMMDD 
CB_INTR_DAY_OF_INTEGER 
CB_INTR_DAY_TO_YYYYDDD 
CB_INTR_DISPLAY_OF 
CB_INTR_E 
CB_INTR_EXCEPTION_FILE 
CB_INTR_EXCEPTION_FILE_N 
CB_INTR_EXCEPTION_LOCATION 
CB_INTR_EXCEPTION_LOCATION_N 
CB_INTR_EXCEPTION_STATEMENT 
CB_INTR_EXCEPTION_STATUS 
CB_INTR_EXP 
CB_INTR_EXP10 
CB_INTR_FACTORIAL 
CB_INTR_FORMATTED_CURRENT_DATE 
CB_INTR_FORMATTED_DATE 
CB_INTR_FORMATTED_DATETIME 
CB_INTR_FORMATTED_TIME 
CB_INTR_FRACTION_PART 
CB_INTR_HIGHEST_ALGEBRAIC 
CB_INTR_INTEGER 
CB_INTR_INTEGER_OF_BOOLEAN 
CB_INTR_INTEGER_OF_DATE 
CB_INTR_INTEGER_OF_DAY 
CB_INTR_INTEGER_OF_FORMATTED_DATE 
CB_INTR_INTEGER_PART 
CB_INTR_LENGTH 
CB_INTR_LOCALE_COMPARE 
CB_INTR_LOCALE_DATE 
CB_INTR_LOCALE_TIME 
CB_INTR_LOCALE_TIME_FROM_SECS 
CB_INTR_LOG 
CB_INTR_LOG10 
CB_INTR_LOWER_CASE 
CB_INTR_LOWEST_ALGEBRAIC 
CB_INTR_MAX 
CB_INTR_MEAN 
CB_INTR_MEDIAN 
CB_INTR_MIDRANGE 
CB_INTR_MIN 
CB_INTR_MOD 
CB_INTR_MODULE_CALLER_ID 
CB_INTR_MODULE_DATE 
CB_INTR_MODULE_FORMATTED_DATE 
CB_INTR_MODULE_ID 
CB_INTR_MODULE_PATH 
CB_INTR_MODULE_SOURCE 
CB_INTR_MODULE_TIME 
CB_INTR_MON_DECIMAL_POINT 
CB_INTR_MON_THOUSANDS_SEP 
CB_INTR_NATIONAL_OF 
CB_INTR_NUM_DECIMAL_POINT 
CB_INTR_NUM_THOUSANDS_SEP 
CB_INTR_NUMVAL 
CB_INTR_NUMVAL_C 
CB_INTR_NUMVAL_F 
CB_INTR_ORD 
CB_INTR_ORD_MAX 
CB_INTR_ORD_MIN 
CB_INTR_PI 
CB_INTR_PRESENT_VALUE 
CB_INTR_RANDOM 
CB_INTR_RANGE 
CB_INTR_REM 
CB_INTR_REVERSE 
CB_INTR_SECONDS_FROM_FORMATTED_TIME 
CB_INTR_SECONDS_PAST_MIDNIGHT 
CB_INTR_SIGN 
CB_INTR_SIN 
CB_INTR_SQRT 
CB_INTR_STANDARD_COMPARE 
CB_INTR_STANDARD_DEVIATION 
CB_INTR_STORED_CHAR_LENGTH 
CB_INTR_SUBSTITUTE 
CB_INTR_SUBSTITUTE_CASE 
CB_INTR_SUM 
CB_INTR_TAN 
CB_INTR_TEST_DATE_YYYYMMDD 
CB_INTR_TEST_DAY_YYYYDDD 
CB_INTR_TEST_FORMATTED_DATETIME 
CB_INTR_TEST_NUMVAL 
CB_INTR_TEST_NUMVAL_C 
CB_INTR_TEST_NUMVAL_F 
CB_INTR_TRIM 
CB_INTR_UPPER_CASE 
CB_INTR_USER_FUNCTION 
CB_INTR_VARIANCE 
CB_INTR_WHEN_COMPILED 
CB_INTR_YEAR_TO_YYYY 
CB_INTR_ABS 
CB_INTR_ACOS 
CB_INTR_ANNUITY 
CB_INTR_ASIN 
CB_INTR_ATAN 
CB_INTR_BOOLEAN_OF_INTEGER 
CB_INTR_BYTE_LENGTH 
CB_INTR_CHAR 
CB_INTR_CHAR_NATIONAL 
CB_INTR_COMBINED_DATETIME 
CB_INTR_CONCATENATE 
CB_INTR_COS 
CB_INTR_CURRENCY_SYMBOL 
CB_INTR_CURRENT_DATE 
CB_INTR_DATE_OF_INTEGER 
CB_INTR_DATE_TO_YYYYMMDD 
CB_INTR_DAY_OF_INTEGER 
CB_INTR_DAY_TO_YYYYDDD 
CB_INTR_DISPLAY_OF 
CB_INTR_E 
CB_INTR_EXCEPTION_FILE 
CB_INTR_EXCEPTION_FILE_N 
CB_INTR_EXCEPTION_LOCATION 
CB_INTR_EXCEPTION_LOCATION_N 
CB_INTR_EXCEPTION_STATEMENT 
CB_INTR_EXCEPTION_STATUS 
CB_INTR_EXP 
CB_INTR_EXP10 
CB_INTR_FACTORIAL 
CB_INTR_FORMATTED_CURRENT_DATE 
CB_INTR_FORMATTED_DATE 
CB_INTR_FORMATTED_DATETIME 
CB_INTR_FORMATTED_TIME 
CB_INTR_FRACTION_PART 
CB_INTR_HIGHEST_ALGEBRAIC 
CB_INTR_INTEGER 
CB_INTR_INTEGER_OF_BOOLEAN 
CB_INTR_INTEGER_OF_DATE 
CB_INTR_INTEGER_OF_DAY 
CB_INTR_INTEGER_OF_FORMATTED_DATE 
CB_INTR_INTEGER_PART 
CB_INTR_LENGTH 
CB_INTR_LOCALE_COMPARE 
CB_INTR_LOCALE_DATE 
CB_INTR_LOCALE_TIME 
CB_INTR_LOCALE_TIME_FROM_SECS 
CB_INTR_LOG 
CB_INTR_LOG10 
CB_INTR_LOWER_CASE 
CB_INTR_LOWEST_ALGEBRAIC 
CB_INTR_MAX 
CB_INTR_MEAN 
CB_INTR_MEDIAN 
CB_INTR_MIDRANGE 
CB_INTR_MIN 
CB_INTR_MOD 
CB_INTR_MODULE_CALLER_ID 
CB_INTR_MODULE_DATE 
CB_INTR_MODULE_FORMATTED_DATE 
CB_INTR_MODULE_ID 
CB_INTR_MODULE_PATH 
CB_INTR_MODULE_SOURCE 
CB_INTR_MODULE_TIME 
CB_INTR_MON_DECIMAL_POINT 
CB_INTR_MON_THOUSANDS_SEP 
CB_INTR_NATIONAL_OF 
CB_INTR_NUM_DECIMAL_POINT 
CB_INTR_NUM_THOUSANDS_SEP 
CB_INTR_NUMVAL 
CB_INTR_NUMVAL_C 
CB_INTR_NUMVAL_F 
CB_INTR_ORD 
CB_INTR_ORD_MAX 
CB_INTR_ORD_MIN 
CB_INTR_PI 
CB_INTR_PRESENT_VALUE 
CB_INTR_RANDOM 
CB_INTR_RANGE 
CB_INTR_REM 
CB_INTR_REVERSE 
CB_INTR_SECONDS_FROM_FORMATTED_TIME 
CB_INTR_SECONDS_PAST_MIDNIGHT 
CB_INTR_SIGN 
CB_INTR_SIN 
CB_INTR_SQRT 
CB_INTR_STANDARD_COMPARE 
CB_INTR_STANDARD_DEVIATION 
CB_INTR_STORED_CHAR_LENGTH 
CB_INTR_SUBSTITUTE 
CB_INTR_SUBSTITUTE_CASE 
CB_INTR_SUM 
CB_INTR_TAN 
CB_INTR_TEST_DATE_YYYYMMDD 
CB_INTR_TEST_DAY_YYYYDDD 
CB_INTR_TEST_FORMATTED_DATETIME 
CB_INTR_TEST_NUMVAL 
CB_INTR_TEST_NUMVAL_C 
CB_INTR_TEST_NUMVAL_F 
CB_INTR_TRIM 
CB_INTR_UPPER_CASE 
CB_INTR_USER_FUNCTION 
CB_INTR_VARIANCE 
CB_INTR_WHEN_COMPILED 
CB_INTR_YEAR_TO_YYYY 
280  {
281  *p1 = 0;
283  cb_source_line = (int)strtol (yytext + 5, NULL, 10) - 1;
284  }
285  cobc_free (p2);
286  }
287 }
288 
289 ^"#".* {
290  /* Ignore */
291 }
292 
293 "PIC" |
294 "PICTURE" {
296 }
297 
298 "FUNCTION" {
299  if (cobc_in_repository || cobc_cs_check == CB_CS_EXIT) {
300  yylval = NULL;
301  return FUNCTION;
302  }
304 }
305 
306 [\'\"] {
307  /* String literal */
308  cobc_force_literal = 0;
309  read_literal (yytext[0]);
310  return LITERAL;
311 }
312 
313 X\'[^\'\n]*\' |
314 X\"[^\"\n]*\" {
315  /* X string literal */
316  cobc_force_literal = 0;
317  return scan_x (yytext + 2, yytext[1]);
318 }
319 
320 Z\'[^\'\n]*\' |
321 Z\"[^\"\n]*\" {
322  /* Z string literal */
323  cobc_force_literal = 0;
324  return scan_z (yytext + 2, yytext[1], 0);
325 }
326 
327 L\'[^\'\n]*\' |
328 L\"[^\"\n]*\" {
329  /* L string literal */
330  cobc_force_literal = 0;
331  return scan_z (yytext + 2, yytext[1], 1);
332 }
333 
334 H\'[^\'\n]*\' |
335 H\"[^\"\n]*\" {
336  /* H numeric literal */
337  cobc_force_literal = 0;
338  return scan_h (yytext + 2, yytext[1]);
339 }
340 
341 \( {
342  inside_bracket++;
343  return TOK_OPEN_PAREN;
344 }
345 
346 \) {
347  if (inside_bracket > 0) {
348  inside_bracket--;
349  }
350  return TOK_CLOSE_PAREN;
351 }
352 
353 [0-9]+ {
354  cobc_force_literal = 0;
355  if (integer_is_label) {
356  /* Integer label or level number */
357  yylval = cb_build_reference (yytext);
358  SET_LOCATION (yylval);
359  return WORD;
360  }
361  /* Numeric literal */
362  return scan_numeric (yytext);
363 }
364 
365 <*>[ ]+ {
366  /* Ignore */
367 }
368 
369 <*>;+ {
370  if (inside_bracket) {
371  return SEMI_COLON;
372  }
373  /* Ignore */
374 }
375 
376 <DECIMAL_IS_PERIOD>[+-]?[0-9]+\.[0-9]*E[+-]?[0-9]+ {
377  /* Numeric floating point literal */
378  return scan_floating_numeric (yytext);
379 }
380 
381 <DECIMAL_IS_PERIOD>[+-]?[0-9\.]*[0-9]+ {
382  /* Numeric literal */
383  return scan_numeric (yytext);
Enumerator
CB_OPERATION_READ 
CB_OPERATION_WRITE 
CB_OPERATION_ASSIGN 
140  {
Enumerator
CB_PERFORM_EXIT 
CB_PERFORM_ONCE 
CB_PERFORM_TIMES 
CB_PERFORM_UNTIL 
CB_PERFORM_FOREVER 
CB_PERFORM_EXIT 
CB_PERFORM_ONCE 
CB_PERFORM_TIMES 
CB_PERFORM_UNTIL 
CB_PERFORM_FOREVER 
CB_PERFORM_EXIT 
CB_PERFORM_ONCE 
CB_PERFORM_TIMES 
CB_PERFORM_UNTIL 
CB_PERFORM_FOREVER 
386  {
387  if (inside_bracket) {
388  return COMMA_DELIM;
389  }
390  /* Ignore */
391 }
392 
enum cb_std_def
Enumerator
CB_STD_OC 
CB_STD_MF 
CB_STD_IBM 
CB_STD_MVS 
CB_STD_BS2000 
CB_STD_85 
CB_STD_2002 
231  {
enum cb_storage
Enumerator
CB_STORAGE_CONSTANT 
CB_STORAGE_FILE 
CB_STORAGE_WORKING 
CB_STORAGE_LOCAL 
CB_STORAGE_LINKAGE 
CB_STORAGE_SCREEN 
CB_STORAGE_REPORT 
CB_STORAGE_COMMUNICATION 
CB_STORAGE_CONSTANT 
CB_STORAGE_FILE 
CB_STORAGE_WORKING 
CB_STORAGE_LOCAL 
CB_STORAGE_LINKAGE 
CB_STORAGE_SCREEN 
CB_STORAGE_REPORT 
CB_STORAGE_COMMUNICATION 
CB_STORAGE_CONSTANT 
CB_STORAGE_FILE 
CB_STORAGE_WORKING 
CB_STORAGE_LOCAL 
CB_STORAGE_LINKAGE 
CB_STORAGE_SCREEN 
CB_STORAGE_REPORT 
CB_STORAGE_COMMUNICATION 
231  {
enum cb_support
Enumerator
CB_OK 
CB_WARNING 
CB_ARCHAIC 
CB_OBSOLETE 
CB_SKIP 
CB_IGNORE 
CB_ERROR 
CB_UNCONFORMABLE 
140  {
Enumerator
CB_DEVICE_NAME 
CB_SWITCH_NAME 
CB_FEATURE_NAME 
CB_CALL_CONVENTION_NAME 
CB_CODE_NAME 
CB_COMPUTER_NAME 
CB_ENTRY_CONVENTION_NAME 
CB_EXTERNAL_LOCALE_NAME 
CB_LIBRARY_NAME 
CB_TEXT_NAME 
CB_DEVICE_NAME 
CB_SWITCH_NAME 
CB_FEATURE_NAME 
CB_CALL_CONVENTION_NAME 
CB_CODE_NAME 
CB_COMPUTER_NAME 
CB_ENTRY_CONVENTION_NAME 
CB_EXTERNAL_LOCALE_NAME 
CB_LIBRARY_NAME 
CB_TEXT_NAME 
CB_DEVICE_NAME 
CB_SWITCH_NAME 
CB_FEATURE_NAME 
CB_CALL_CONVENTION_NAME 
CB_CODE_NAME 
CB_COMPUTER_NAME 
CB_ENTRY_CONVENTION_NAME 
CB_EXTERNAL_LOCALE_NAME 
CB_LIBRARY_NAME 
CB_TEXT_NAME 
140  {
141  ['-'] = 1,
142  ['0'] = 1,
143  ['1'] = 1,
144  ['2'] = 1,
145  ['3'] = 1,
146  ['4'] = 1,
147  ['5'] = 1,
148  ['6'] = 1,
enum cb_tag
Enumerator
CB_TAG_CONST 
CB_TAG_INTEGER 
CB_TAG_STRING 
CB_TAG_ALPHABET_NAME 
CB_TAG_CLASS_NAME 
CB_TAG_LOCALE_NAME 
CB_TAG_SYSTEM_NAME 
CB_TAG_LITERAL 
CB_TAG_DECIMAL 
CB_TAG_FIELD 
CB_TAG_FILE 
CB_TAG_REPORT 
CB_TAG_REFERENCE 
CB_TAG_BINARY_OP 
CB_TAG_FUNCALL 
CB_TAG_CAST 
CB_TAG_INTRINSIC 
CB_TAG_LABEL 
CB_TAG_ASSIGN 
CB_TAG_INITIALIZE 
CB_TAG_SEARCH 
CB_TAG_CALL 
CB_TAG_GOTO 
CB_TAG_IF 
CB_TAG_PERFORM 
CB_TAG_STATEMENT 
CB_TAG_CONTINUE 
CB_TAG_CANCEL 
CB_TAG_ALTER 
CB_TAG_SET_ATTR 
CB_TAG_PERFORM_VARYING 
CB_TAG_PICTURE 
CB_TAG_LIST 
CB_TAG_DIRECT 
CB_TAG_DEBUG 
CB_TAG_DEBUG_CALL 
CB_TAG_CONST 
CB_TAG_INTEGER 
CB_TAG_STRING 
CB_TAG_ALPHABET_NAME 
CB_TAG_CLASS_NAME 
CB_TAG_LOCALE_NAME 
CB_TAG_SYSTEM_NAME 
CB_TAG_LITERAL 
CB_TAG_DECIMAL 
CB_TAG_FIELD 
CB_TAG_FILE 
CB_TAG_REPORT 
CB_TAG_REFERENCE 
CB_TAG_BINARY_OP 
CB_TAG_FUNCALL 
CB_TAG_CAST 
CB_TAG_INTRINSIC 
CB_TAG_LABEL 
CB_TAG_ASSIGN 
CB_TAG_INITIALIZE 
CB_TAG_SEARCH 
CB_TAG_CALL 
CB_TAG_GOTO 
CB_TAG_IF 
CB_TAG_PERFORM 
CB_TAG_STATEMENT 
CB_TAG_CONTINUE 
CB_TAG_CANCEL 
CB_TAG_ALTER 
CB_TAG_SET_ATTR 
CB_TAG_PERFORM_VARYING 
CB_TAG_PICTURE 
CB_TAG_LIST 
CB_TAG_DIRECT 
CB_TAG_DEBUG 
CB_TAG_DEBUG_CALL 
CB_TAG_CONST 
CB_TAG_INTEGER 
CB_TAG_STRING 
CB_TAG_ALPHABET_NAME 
CB_TAG_CLASS_NAME 
CB_TAG_LOCALE_NAME 
CB_TAG_SYSTEM_NAME 
CB_TAG_LITERAL 
CB_TAG_DECIMAL 
CB_TAG_FIELD 
CB_TAG_FILE 
CB_TAG_REPORT 
CB_TAG_REFERENCE 
CB_TAG_BINARY_OP 
CB_TAG_FUNCALL 
CB_TAG_CAST 
CB_TAG_INTRINSIC 
CB_TAG_LABEL 
CB_TAG_ASSIGN 
CB_TAG_INITIALIZE 
CB_TAG_SEARCH 
CB_TAG_CALL 
CB_TAG_GOTO 
CB_TAG_IF 
CB_TAG_PERFORM 
CB_TAG_STATEMENT 
CB_TAG_CONTINUE 
CB_TAG_CANCEL 
CB_TAG_ALTER 
CB_TAG_SET_ATTR 
CB_TAG_PERFORM_VARYING 
CB_TAG_PICTURE 
CB_TAG_LIST 
CB_TAG_DIRECT 
CB_TAG_DEBUG 
CB_TAG_DEBUG_CALL 
66  { \
67  plexbuff = cobc_malloc ((size_t)COB_MINI_BUFF); \
68  plexsize = COB_MINI_BUFF; \
69  } \
70  if (!picbuff1) { \
71  picbuff1 = cobc_malloc ((size_t)COB_MINI_BUFF); \
72  pic1size = COB_MINI_BUFF; \
73  } \
74  if (!picbuff2) { \
75  picbuff2 = cobc_malloc ((size_t)COB_MINI_BUFF); \
76  pic2size = COB_MINI_BUFF; \
77  }
78 
79 #include "config.h"
80 
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <string.h>
84 #include <ctype.h>
85 
86 #ifdef HAVE_UNISTD_H
87 #include <unistd.h>
88 #else
89 #define YY_NO_UNISTD_H 1
90 #endif
91 
92 #define COB_IN_SCANNER 1
93 #include "cobc.h"
94 #include "tree.h"
95 
96 #define YYSTYPE cb_tree
97 #include "parser.h"
98 
99 #define SET_LOCATION(x) \
100  do { \
101  (x)->source_file = cb_source_file; \
102  (x)->source_line = cb_source_line; \
103  } while (0)
enum cb_usage
Enumerator
CB_USAGE_BINARY 
CB_USAGE_BIT 
CB_USAGE_COMP_5 
CB_USAGE_COMP_X 
CB_USAGE_DISPLAY 
CB_USAGE_FLOAT 
CB_USAGE_DOUBLE 
CB_USAGE_INDEX 
CB_USAGE_NATIONAL 
CB_USAGE_OBJECT 
CB_USAGE_PACKED 
CB_USAGE_POINTER 
CB_USAGE_PROGRAM 
CB_USAGE_LENGTH 
CB_USAGE_PROGRAM_POINTER 
CB_USAGE_UNSIGNED_CHAR 
CB_USAGE_SIGNED_CHAR 
CB_USAGE_UNSIGNED_SHORT 
CB_USAGE_SIGNED_SHORT 
CB_USAGE_UNSIGNED_INT 
CB_USAGE_SIGNED_INT 
CB_USAGE_UNSIGNED_LONG 
CB_USAGE_SIGNED_LONG 
CB_USAGE_COMP_6 
CB_USAGE_FP_DEC64 
CB_USAGE_FP_DEC128 
CB_USAGE_FP_BIN32 
CB_USAGE_FP_BIN64 
CB_USAGE_FP_BIN128 
CB_USAGE_LONG_DOUBLE 
CB_USAGE_BINARY 
CB_USAGE_BIT 
CB_USAGE_COMP_5 
CB_USAGE_COMP_X 
CB_USAGE_DISPLAY 
CB_USAGE_FLOAT 
CB_USAGE_DOUBLE 
CB_USAGE_INDEX 
CB_USAGE_NATIONAL 
CB_USAGE_OBJECT 
CB_USAGE_PACKED 
CB_USAGE_POINTER 
CB_USAGE_PROGRAM 
CB_USAGE_LENGTH 
CB_USAGE_PROGRAM_POINTER 
CB_USAGE_UNSIGNED_CHAR 
CB_USAGE_SIGNED_CHAR 
CB_USAGE_UNSIGNED_SHORT 
CB_USAGE_SIGNED_SHORT 
CB_USAGE_UNSIGNED_INT 
CB_USAGE_SIGNED_INT 
CB_USAGE_UNSIGNED_LONG 
CB_USAGE_SIGNED_LONG 
CB_USAGE_COMP_6 
CB_USAGE_FP_DEC64 
CB_USAGE_FP_DEC128 
CB_USAGE_FP_BIN32 
CB_USAGE_FP_BIN64 
CB_USAGE_FP_BIN128 
CB_USAGE_LONG_DOUBLE 
CB_USAGE_BINARY 
CB_USAGE_BIT 
CB_USAGE_COMP_5 
CB_USAGE_COMP_X 
CB_USAGE_DISPLAY 
CB_USAGE_FLOAT 
CB_USAGE_DOUBLE 
CB_USAGE_INDEX 
CB_USAGE_NATIONAL 
CB_USAGE_OBJECT 
CB_USAGE_PACKED 
CB_USAGE_POINTER 
CB_USAGE_PROGRAM 
CB_USAGE_LENGTH 
CB_USAGE_PROGRAM_POINTER 
CB_USAGE_UNSIGNED_CHAR 
CB_USAGE_SIGNED_CHAR 
CB_USAGE_UNSIGNED_SHORT 
CB_USAGE_SIGNED_SHORT 
CB_USAGE_UNSIGNED_INT 
CB_USAGE_SIGNED_INT 
CB_USAGE_UNSIGNED_LONG 
CB_USAGE_SIGNED_LONG 
CB_USAGE_COMP_6 
CB_USAGE_FP_DEC64 
CB_USAGE_FP_DEC128 
CB_USAGE_FP_BIN32 
CB_USAGE_FP_BIN64 
CB_USAGE_FP_BIN128 
CB_USAGE_LONG_DOUBLE 
233  {
235  } else {
237  }
238  }
239 
240  /* We treat integer literals immediately after '.' as labels;
241  that is, they must be level numbers or section names. */
242  if (last_token_is_dot) {
243  integer_is_label = 1;
244  last_token_is_dot = 0;
245  } else {
246  integer_is_label = 0;
247  }
248 %}
249 
250 
251 <*>^[ ]?"#DEFLIT".*\n {
253 }
254 
255 <*>^[ ]?"#OPTION".*\n {
256  scan_options (yytext, 1);
257 }
258 
259 <*>^[ ]?"#DEFOFF".*\n {
260  scan_options (yytext, 2);
261 }
262 
263 <*>^[ ]?"#DEFENV".*\n {
264  scan_options (yytext, 3);

Function Documentation

if _ ( "Define cutoff depth for IF statements\n\t\t\t- Default : 3"  )
if _ ( "Define display sign representation\n\t\t\t- ASCII or EBCDIC (Default : machine native)"  )
if fold _ ( "Fold COPY subject to value\n\t\t\t- UPPER or LOWER (Default : no transformation)"  )
if fold fold _ ( "Fold PROGRAM ID,
CALL  ,
CANCEL subject to value\n\t\t\t-UPPER or LOWER(Default:no transformation)"   
)
if fold fold _ ( "Initialize fields without VALUE to decimal value\n\t\t\t- 0 to 255 (Default : initialize to picture)"  )
if fold fold _ ( "Intrinsics to be used without FUNCTION keyword\n\t\t\t- ALL or intrinsic function name (,name,...)"  )
if fold fold static _ ( "Output static function calls for the CALL statement"  )
if fold fold static computed _ ( "Generate computed goto C statements"  )
if fold fold static computed alternate _ ( "Use restricted ASCII to EBCDIC translate"  )
if fold fold static computed alternate extra _ ( "Generate extra braces in generated C code"  )
if fold fold static computed alternate extra correct _ ( "Attempt correction of invalid numeric display items"  )
if fold fold static computed alternate extra correct stack on _ ( "PERFORM stack allocated on heap )
if fold fold static computed alternate extra correct stack on _ ( "Generate trace code\n\t\t\t- Executed SECTION/PARAGRAPH )
if fold fold static computed alternate extra correct stack on _ ( "Generate trace code\n\t\t\t- Executed SECTION/PARAGRAPH/STATEMENTS\n\t\t\t- Turned on by -debug"  )
if fold fold static computed alternate extra correct stack on syntax _ ( "Syntax error checking only; don't emit any output )
if fold fold static computed alternate extra correct stack on syntax debugging _ ( "Enable debugging lines\n\t\t\t- 'D' in indicator column or floating >>D"  )
if fold fold static computed alternate extra correct stack on syntax debugging source _ ( "Generate source location code\n\t\t\t- Turned on by -debug/-g/-ftraceall"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit _ ( "Automatic initialization of the Cobol runtime system"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack _ ( "PERFORM stack checking\n\t\t\t- Turned on by -debug or -g"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax _ ( "Allow syntax extensions\n\t\t\t- eg. Switch name  SW1,
etc."   
)
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write _ ( "Use AFTER 1 for WRITE of LINE SEQUENTIAL\n\t\t\t- Default : BEFORE 1"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write _ ( "'*' or '/' in column 1 treated as comment\n\t\t\t- FIXED format only )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write _ ( "'$' in indicator area treated as '*'  ,
\n\t\t\t'|'treated as floating comment"   
)
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write _ ( "Allow numeric field overflow\n\t\t\t- Non-ANSI behaviour"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write _ ( "Adjust items following OCCURS DEPENDING\n\t\t\t- Requires implicit/explicit relaxed syntax )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single _ ( "Use a single quote (apostrophe) for QUOTE\n\t\t\t- Default : double quote )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive _ ( "Check recursive program call )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax _ ( "Relax syntax checking\n\t\t\t- eg. REDEFINES position"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Treat all files as OPTIONAL\n\t\t\t- unless NOT OPTIONAL specified"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn if obsolete features are used"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn if archaic features are used"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn incompatible redefinition of data items"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn inconsistent constant )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn overlapping MOVE items"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional _ ( "Warn lack of parentheses around AND within OR )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict _ ( "Warn type mismatch strictly"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit _ ( "Warn implicitly defined data items"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit _ ( "Warn CORRESPONDING with no matching items"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external _ ( "Warn EXTERNAL item with VALUE clause"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call _ ( "Warn non 01/77 items for CALL params )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column _ ( "Warn text after column  72,
FIXED format"   
)
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column _ ( "Warn lack of scope terminator END-XXX"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column _ ( "Warn possible field truncation"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column _ ( "Warn dangling LINKAGE items"  )
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column _ ( "Warn unreachable statements"  )
231  {
232  if (likely(current_program)) {
233  if (current_program->decimal_point == '.') {
235  } else {
237  }
238  }
239 
240  /* We treat integer literals immediately after '.' as labels;
241  that is, they must be level numbers or section names. */
242  if (last_token_is_dot) {
243  integer_is_label = 1;
244  last_token_is_dot = 0;
245  } else {
246  integer_is_label = 0;
247  }
248 %}
249 
250 
251 <*>^[ ]?"#DEFLIT".*\n {
253 }
254 
255 <*>^[ ]?"#OPTION".*\n {
256  scan_options (yytext, 1);
257 }
258 
259 <*>^[ ]?"#DEFOFF".*\n {
260  scan_options (yytext, 2);
void ambiguous_error ( cb_tree  )
290 {
291  struct cb_word *w;
292  struct cb_field *p;
293  struct cb_label *l2;
294  cb_tree l;
295  cb_tree y;
296 
297  w = CB_REFERENCE (x)->word;
298  if (w->error == 0) {
299  if (!errnamebuff) {
300  errnamebuff = cobc_main_malloc ((size_t)COB_NORMAL_BUFF);
301  }
302  /* Display error the first time */
303  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX, "'%s'", CB_NAME (x));
304  for (l = CB_REFERENCE (x)->chain; l; l = CB_REFERENCE (l)->chain) {
305  strcat (errnamebuff, " in '");
306  strcat (errnamebuff, CB_NAME (l));
307  strcat (errnamebuff, "'");
308  }
309  cb_error_x (x, _("%s ambiguous; need qualification"), errnamebuff);
310  w->error = 1;
311 
312  /* Display all fields with the same name */
313  for (l = w->items; l; l = CB_CHAIN (l)) {
314  y = CB_VALUE (l);
315  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX,
316  "'%s' ", w->name);
317  switch (CB_TREE_TAG (y)) {
318  case CB_TAG_FIELD:
319  for (p = CB_FIELD (y)->parent; p; p = p->parent) {
320  strcat (errnamebuff, "in '");
321  strcat (errnamebuff, cb_name (CB_TREE(p)));
322  strcat (errnamebuff, "' ");
323  }
324  break;
325  case CB_TAG_LABEL:
326  l2 = CB_LABEL (y);
327  if (l2->section) {
328  strcat (errnamebuff, "in '");
329  strcat (errnamebuff,
330  (const char *)(l2->section->name));
331  strcat (errnamebuff, "' ");
332  }
333  break;
334  default:
335  break;
336  }
337  strcat (errnamebuff, _("defined here"));
338  cb_error_x (y, errnamebuff);
339  }
340  }
341 }
struct cb_file* build_file ( cb_tree  )
read
2203 {
2204  struct cb_file *p;
2205 
2206  p = make_tree (CB_TAG_FILE, CB_CATEGORY_UNKNOWN, sizeof (struct cb_file));
2207  p->name = cb_define (name, CB_TREE (p));
2208  p->cname = cb_to_cname (p->name);
2209 
2214  return p;
2215 }
struct cb_literal* build_literal ( enum  cb_category,
const void *  ,
const size_t   
)
read
631 {
632  struct cb_literal *p;
633 
634  p = make_tree (CB_TAG_LITERAL, category, sizeof (struct cb_literal));
635  p->data = cobc_parse_malloc (size + 1U);
636  p->size = size;
637  memcpy (p->data, data, size);
638  return p;
639 }
struct cb_report* build_report ( cb_tree  )
read
2183 {
2184  struct cb_report *p;
2185 
2186  p = make_tree (CB_TAG_REPORT, CB_CATEGORY_UNKNOWN, sizeof (struct cb_report));
2187  p->name = cb_define (name, CB_TREE (p));
2188  p->cname = cb_to_cname (p->name);
2189 
2190 #if 0 /* RXWRXW RP */
2191  p->organization = COB_ORG_SEQUENTIAL;
2192  p->access_mode = COB_ACCESS_SEQUENTIAL;
2193  p->handler = CB_LABEL (cb_standard_error_handler);
2194  p->handler_prog = current_program;
2195 #endif
2196  return p;
2197 }
void cb_add_78 ( struct cb_field f)

References CB_VALUE, check_78_replace(), cb_level_78::chk_const, cob_u32_t, cobc_malloc(), const78ptr, current_program, cb_field::flag_is_global, cb_level_78::fld78, globlev78ptr, cb_level_78::globnext, cb_level_78::last, lev78ptr, cb_field::name, cb_level_78::name_len, cb_level_78::next, cb_level_78::pic_len, cb_level_78::pic_replace, cb_level_78::prog, and cb_field::values.

Referenced by cb_validate_78_item().

1693 {
1694  struct cb_level_78 *p78;
1695 
1696  /* Add a constant (78 level) item */
1697  p78 = cobc_malloc (sizeof(struct cb_level_78));
1698  p78->fld78 = f;
1699  p78->prog = current_program;
1701  if (p78->pic_replace) {
1702  p78->pic_len = (cob_u32_t)strlen (p78->pic_replace);
1703  }
1704  p78->name_len = (cob_u32_t)strlen (f->name);
1705  if (f->flag_is_global) {
1706  if (!globlev78ptr) {
1707  p78->last = p78;
1708  } else {
1709  p78->last = globlev78ptr->last;
1710  }
1711  p78->last->globnext = const78ptr;
1712  p78->next = globlev78ptr;
1713  p78->globnext = globlev78ptr;
1714  p78->chk_const = 1;
1715  globlev78ptr = p78;
1716  if (lev78ptr) {
1718  } else {
1720  }
1721  } else {
1722  if (!lev78ptr) {
1723  p78->last = p78;
1724  } else {
1725  p78->last = lev78ptr->last;
1726  }
1727  if (globlev78ptr) {
1728  p78->last->globnext = globlev78ptr;
1729  } else {
1730  p78->last->globnext = const78ptr;
1731  }
1732  p78->next = lev78ptr;
1733  p78->globnext = lev78ptr;
1734  lev78ptr = p78;
1735  top78ptr = lev78ptr;
1736  }
1737 }
void cb_add_common_prog ( struct cb_program )
1312 {
1313  struct cb_program *q;
1314 
1315  /* Here we are sure that nested >= 1 */
1316  q = container_progs[prog->nested_level - 1];
1318 }
cb_tree cb_build_add ( cb_tree  ,
cb_tree  ,
cb_tree   
)
3940 {
3941  cb_tree opt;
3942  struct cb_field *f;
3943 
3944 #ifdef COB_NON_ALIGNED
3945  if (CB_INDEX_P (v)) {
3946  return cb_build_move (cb_build_binary_op (v, '+', n), v);
3947  }
3948  if (CB_TREE_CLASS (v) == CB_CLASS_POINTER) {
3949  optimize_defs[COB_POINTER_MANIP] = 1;
3950  return CB_BUILD_FUNCALL_3 ("cob_pointer_manip", v, n, cb_int0);
3951  }
3952 #else
3953  if (CB_INDEX_P (v) || CB_TREE_CLASS (v) == CB_CLASS_POINTER) {
3954  return cb_build_move (cb_build_binary_op (v, '+', n), v);
3955  }
3956 #endif
3957 
3958  if (CB_REF_OR_FIELD_P (v)) {
3959  f = CB_FIELD_PTR (v);
3960  f->count++;
3961  }
3962  if (CB_REF_OR_FIELD_P (n)) {
3963  f = CB_FIELD_PTR (n);
3964  f->count++;
3965  }
3966  if (round_opt == cb_high) {
3967  /* Short circuit from tree.c for perform */
3968  if (cb_fits_int (n)) {
3969  return cb_build_optim_add (v, n);
3970  } else {
3971  return CB_BUILD_FUNCALL_3 ("cob_add", v, n, cb_int0);
3972  }
3973  }
3974  opt = build_store_option (v, round_opt);
3975  if (opt == cb_int0 && cb_fits_int (n)) {
3976  return cb_build_optim_add (v, n);
3977  }
3978  return CB_BUILD_FUNCALL_3 ("cob_add", v, n, opt);
3979 }
cb_tree cb_build_address ( cb_tree  )
1329 {
1330  cb_tree v;
1331  struct cb_reference *r;
1332  const char *name;
1333  int numsubs;
1334  int refsubs;
1335 
1336  if (x == cb_error_node) {
1337  return cb_error_node;
1338  }
1339  if (!CB_REFERENCE_P (x)) {
1340  return CB_BUILD_CAST_ADDRESS (x);
1341  }
1342 
1343  r = CB_REFERENCE (x);
1344  name = r->word->name;
1345  v = cb_ref (x);
1346  if (v == cb_error_node) {
1347  return cb_error_node;
1348  }
1349 
1350  refsubs = cb_list_length (r->subs);
1351  if (CB_FIELD_P (v)) {
1352  numsubs = CB_FIELD (v)->indexes;
1353  if (refsubs > numsubs) {
1354  goto subserror;
1355  } else if (refsubs < numsubs) {
1356  if (!cb_relaxed_syntax_check) {
1357  goto subserror;
1358  } else {
1359  cb_warning_x (x,
1360  _("Subscripts missing for '%s' - Defaulting to 1"),
1361  name);
1362  for (; refsubs < numsubs; ++refsubs) {
1363  CB_ADD_TO_CHAIN (cb_one, r->subs);
1364  }
1365  }
1366  }
1367  } else {
1368  numsubs = 0;
1369  if (r->subs) {
1370  goto subserror;
1371  }
1372  if (r->offset) {
1373  cb_error_x (x, _("'%s' cannot be reference modified"), name);
1374  return cb_error_node;
1375  }
1376  }
1377 
1378  return CB_BUILD_CAST_ADDRESS (x);
1379 
1380 subserror:
1381  switch (numsubs) {
1382  case 0:
1383  cb_error_x (x, _("'%s' cannot be subscripted"), name);
1384  break;
1385  case 1:
1386  cb_error_x (x, _("'%s' requires 1 subscript"), name);
1387  break;
1388  default:
1389  cb_error_x (x, _("'%s' requires %d subscripts"),
1390  name, numsubs);
1391  break;
1392  }
1393  return cb_error_node;
1394 }
cb_tree cb_build_alphabet_name ( cb_tree  )
1448 {
1449  struct cb_alphabet_name *p;
1450 
1451  if (!name || name == cb_error_node) {
1452  return NULL;
1453  }
1455  sizeof (struct cb_alphabet_name));
1456  p->name = cb_define (name, CB_TREE (p));
1457  p->cname = cb_to_cname (p->name);
1458  return CB_TREE (p);
1459 }
cb_tree cb_build_alphanumeric_literal ( const void *  ,
const size_t   
)
1546 {
1547  return CB_TREE (build_literal (CB_CATEGORY_ALPHANUMERIC, data, size));
1548 }
cb_tree cb_build_alter ( const cb_tree  ,
const cb_tree   
)
2952 {
2953  struct cb_alter *p;
2954 
2956  sizeof (struct cb_alter));
2957  p->source = source;
2958  p->target = target;
2962  return CB_TREE (p);
2963 }
cb_tree cb_build_any_intrinsic ( cb_tree  )
3093 {
3094  struct cb_intrinsic_table *cbp;
3095 
3096  cbp = lookup_intrinsic ("LENGTH", 0, 0);
3097  return make_intrinsic (NULL, cbp, args, NULL, NULL, 0);
3098 }
cb_tree cb_build_assign ( const cb_tree  ,
const cb_tree   
)
2865 {
2866  struct cb_assign *p;
2867 
2869  sizeof (struct cb_assign));
2870  p->var = var;
2871  p->val = val;
2872  return CB_TREE (p);
2873 }
cb_tree cb_build_assignment_name ( struct cb_file ,
cb_tree   
)
1248 {
1249  const char *s;
1250  const char *p;
1251 
1252  if (name == cb_error_node) {
1253  return cb_error_node;
1254  }
1255  /* For special assignment */
1256  if (name == NULL) {
1257  return NULL;
1258  }
1259 
1260  switch (CB_TREE_TAG (name)) {
1261  case CB_TAG_LITERAL:
1262  return name;
1263 
1264  case CB_TAG_REFERENCE:
1265  s = CB_NAME (name);
1266  if (cb_assign_clause == CB_ASSIGN_MF) {
1267  if (cfile->flag_ext_assign) {
1268  p = strrchr (s, '-');
1269  if (p) {
1270  s = p + 1;
1271  }
1272  return cb_build_alphanumeric_literal (s, strlen (s));
1273  }
1276  return name;
1277  } else if (cb_assign_clause == CB_ASSIGN_IBM) {
1278  /* Check organization */
1279  if (strncmp (s, "S-", (size_t)2) == 0 ||
1280  strncmp (s, "AS-", (size_t)3) == 0) {
1281  goto org;
1282  }
1283  /* Skip the device label if exists */
1284  if ((p = strchr (s, '-')) != NULL) {
1285  s = p + 1;
1286  }
1287  /* Check organization again */
1288  if (strncmp (s, "S-", (size_t)2) == 0 ||
1289  strncmp (s, "AS-", (size_t)3) == 0) {
1290 org:
1291  /* Skip it for now */
1292  s = strchr (s, '-') + 1;
1293  }
1294  /* Convert the name into literal */
1295  if (warningopt) {
1296  cb_warning (_("ASSIGN interpreted as %s"), s);
1297  }
1298  return cb_build_alphanumeric_literal (s, strlen (s));
1299  }
1300  /* Fall through for CB_ASSIGN_COBOL2002 */
1301  /* To be looked at */
1302  default:
1303  return cb_error_node;
1304  }
1305 }
cb_tree cb_build_binary_list ( cb_tree  ,
const int   
)
2754 {
2755  cb_tree e;
2756 
2757  e = CB_VALUE (l);
2758  for (l = CB_CHAIN (l); l; l = CB_CHAIN (l)) {
2759  e = cb_build_binary_op (e, op, CB_VALUE (l));
2760  }
2761  return e;
2762 }
cb_tree cb_build_binary_op ( cb_tree  ,
const int  ,
cb_tree   
)
2679 {
2680  struct cb_binary_op *p;
2681  enum cb_category category = CB_CATEGORY_UNKNOWN;
2682 
2683  switch (op) {
2684  case '+':
2685  case '-':
2686  case '*':
2687  case '/':
2688  case '^':
2689  /* Arithmetic operators */
2690  if (CB_TREE_CLASS (x) == CB_CLASS_POINTER ||
2691  CB_TREE_CLASS (y) == CB_CLASS_POINTER) {
2692  category = CB_CATEGORY_DATA_POINTER;
2693  break;
2694  }
2697  if (x == cb_error_node || y == cb_error_node) {
2698  return cb_error_node;
2699  }
2700  category = CB_CATEGORY_NUMERIC;
2701  break;
2702 
2703  case '=':
2704  case '~':
2705  case '<':
2706  case '>':
2707  case '[':
2708  case ']':
2709  /* Relational operators */
2710  if ((CB_REF_OR_FIELD_P (x)) &&
2711  CB_FIELD (cb_ref (x))->level == 88) {
2712  cb_error_x (x, _("Invalid expression"));
2713  return cb_error_node;
2714  }
2715  if ((CB_REF_OR_FIELD_P (y)) &&
2716  CB_FIELD (cb_ref (y))->level == 88) {
2717  cb_error_x (y, _("Invalid expression"));
2718  return cb_error_node;
2719  }
2720  category = CB_CATEGORY_BOOLEAN;
2721  break;
2722 
2723  case '!':
2724  case '&':
2725  case '|':
2726  /* Logical operators */
2727  if (CB_TREE_CLASS (x) != CB_CLASS_BOOLEAN ||
2728  (y && CB_TREE_CLASS (y) != CB_CLASS_BOOLEAN)) {
2729  cb_error_x (x, _("Invalid expression"));
2730  return cb_error_node;
2731  }
2732  category = CB_CATEGORY_BOOLEAN;
2733  break;
2734 
2735  case '@':
2736  /* Parentheses */
2737  category = CB_TREE_CATEGORY (x);
2738  break;
2739 
2740  default:
2741  cobc_abort_pr (_("Unexpected operator -> %d"), op);
2742  COBC_ABORT ();
2743  }
2744 
2745  p = make_tree (CB_TAG_BINARY_OP, category, sizeof (struct cb_binary_op));
2746  p->op = op;
2747  p->x = x;
2748  p->y = y;
2749  return CB_TREE (p);
2750 }
struct cb_picture* cb_build_binary_picture ( const char *  ,
const cob_u32_t  ,
const cob_u32_t   
)
read
1643 {
1644  struct cb_picture *pic;
1645 
1647  sizeof (struct cb_picture));
1648  pic->orig = cobc_check_string (str);
1649  pic->size = size;
1650  pic->digits = size;
1651  pic->scale = 0;
1652  pic->have_sign = sign;
1654  return pic;
1655 }
cb_tree cb_build_call ( const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cob_u32_t  ,
const int   
)
2920 {
2921  struct cb_call *p;
2922 
2924  sizeof (struct cb_call));
2925  p->name = name;
2926  p->args = args;
2927  p->stmt1 = stmt1;
2928  p->stmt2 = stmt2;
2929  p->call_returning = returning;
2930  p->is_system = is_system_call;
2931  p->convention = convention;
2932  return CB_TREE (p);
2933 }
cb_tree cb_build_cancel ( const cb_tree  )
2939 {
2940  struct cb_cancel *p;
2941 
2943  sizeof (struct cb_cancel));
2944  p->target = target;
2945  return CB_TREE (p);
2946 }
cb_tree cb_build_cast ( const enum  cb_cast_type,
const cb_tree   
)
2798 {
2799  struct cb_cast *p;
2800  enum cb_category category;
2801 
2802  if (type == CB_CAST_INTEGER) {
2803  category = CB_CATEGORY_NUMERIC;
2804  } else {
2805  category = CB_CATEGORY_UNKNOWN;
2806  }
2807  p = make_tree (CB_TAG_CAST, category, sizeof (struct cb_cast));
2808  p->cast_type = type;
2809  p->val = val;
2810  return CB_TREE (p);
2811 }
cb_tree cb_build_cast_int ( const cb_tree  )
2815 {
2816  struct cb_cast *p;
2817 
2818  p = make_tree (CB_TAG_CAST, CB_CATEGORY_NUMERIC, sizeof (struct cb_cast));
2820  p->val = val;
2821  return CB_TREE (p);
2822 }
cb_tree cb_build_cast_llint ( const cb_tree  )
2826 {
2827  struct cb_cast *p;
2828 
2829  p = make_tree (CB_TAG_CAST, CB_CATEGORY_NUMERIC, sizeof (struct cb_cast));
2831  p->val = val;
2832  return CB_TREE (p);
2833 }
cb_tree cb_build_class_name ( cb_tree  ,
cb_tree   
)
1465 {
1466  struct cb_class_name *p;
1467 
1468  if (!name || name == cb_error_node) {
1469  return NULL;
1470  }
1472  sizeof (struct cb_class_name));
1473  p->name = cb_define (name, CB_TREE (p));
1474  if (!scratch_buff) {
1475  scratch_buff = cobc_main_malloc ((size_t)COB_MINI_BUFF);
1476  }
1477  snprintf (scratch_buff, (size_t)COB_MINI_MAX, "cob_is_%s_%d",
1478  cb_to_cname (p->name), class_id++);
1480  p->list = list;
1481  return CB_TREE (p);
1482 }
cb_tree cb_build_comment ( const char *  )
1383 {
1384  struct cb_direct *p;
1385 
1387  sizeof (struct cb_direct));
1388  p->line = str;
1389  CB_TREE (p)->source_file = cb_source_file;
1390  CB_TREE (p)->source_line = cb_source_line;
1391  return CB_TREE (p);
1392 }
cb_tree cb_build_cond ( cb_tree  )
3661 {
3662  struct cb_field *f;
3663  struct cb_binary_op *p;
3664  cb_tree d1;
3665  cb_tree d2;
3666  int size1;
3667  int size2;
3668 
3669  if (x == cb_error_node) {
3670  return cb_error_node;
3671  }
3672  switch (CB_TREE_TAG (x)) {
3673  case CB_TAG_CONST:
3674  if (x != cb_any && x != cb_true && x != cb_false) {
3676  _("Invalid expression"));
3677  return cb_error_node;
3678  }
3679  return x;
3680  case CB_TAG_FUNCALL:
3681  return x;
3682  case CB_TAG_REFERENCE:
3683  if (!CB_FIELD_P (cb_ref (x))) {
3684  return cb_build_cond (cb_ref (x));
3685  }
3686 
3687  f = CB_FIELD_PTR (x);
3688 
3689  /* Level 88 condition */
3690  if (f->level == 88) {
3691  /* Build an 88 condition at every occurrence */
3692  /* as it may be subscripted */
3693  return cb_build_cond (build_cond_88 (x));
3694  }
3695 
3696  cb_error_x (x, _("Invalid expression"));
3697  return cb_error_node;
3698  case CB_TAG_BINARY_OP:
3699  p = CB_BINARY_OP (x);
3700  if (!p->x || p->x == cb_error_node) {
3701  return cb_error_node;
3702  }
3703  switch (p->op) {
3704  case '!':
3705  return CB_BUILD_NEGATION (cb_build_cond (p->x));
3706  case '&':
3707  case '|':
3708  if (!p->y || p->y == cb_error_node) {
3709  return cb_error_node;
3710  }
3711  return cb_build_binary_op (cb_build_cond (p->x), p->op, cb_build_cond (p->y));
3712  default:
3713  if (!p->y || p->y == cb_error_node) {
3714  return cb_error_node;
3715  }
3716  if (CB_INDEX_P (p->x) || CB_INDEX_P (p->y) ||
3717  CB_TREE_CLASS (p->x) == CB_CLASS_POINTER ||
3718  CB_TREE_CLASS (p->y) == CB_CLASS_POINTER) {
3719  x = cb_build_binary_op (p->x, '-', p->y);
3720  } else if (CB_BINARY_OP_P (p->x) ||
3721  CB_BINARY_OP_P (p->y)) {
3722  /* Decimal comparison */
3723  d1 = decimal_alloc ();
3724  d2 = decimal_alloc ();
3725 
3726  decimal_expand (d1, p->x);
3727  decimal_expand (d2, p->y);
3728  dpush (CB_BUILD_FUNCALL_2 ("cob_decimal_cmp", d1, d2));
3729  decimal_free ();
3730  decimal_free ();
3732  decimal_stack = NULL;
3733  } else {
3734  /* DEBUG Bypass optimization for PERFORM */
3736  x = CB_BUILD_FUNCALL_2 ("cob_cmp", p->x, p->y);
3737  break;
3738  }
3739  if (cb_chk_num_cond (p->x, p->y)) {
3740  size1 = cb_field_size (p->x);
3741  x = CB_BUILD_FUNCALL_3 ("memcmp",
3742  CB_BUILD_CAST_ADDRESS (p->x),
3743  CB_BUILD_CAST_ADDRESS (p->y),
3744  cb_int (size1));
3745  break;
3746  }
3747  if (CB_TREE_CLASS (p->x) == CB_CLASS_NUMERIC &&
3748  CB_TREE_CLASS (p->y) == CB_CLASS_NUMERIC &&
3749  cb_fits_long_long (p->y)) {
3750  x = cb_build_optim_cond (p);
3751  break;
3752  }
3753 
3754  /* Field comparison */
3755  if ((CB_REF_OR_FIELD_P (p->x)) &&
3758  cb_field_size (p->x) == 1 &&
3760  (p->y == cb_space || p->y == cb_low ||
3761  p->y == cb_high || p->y == cb_zero)) {
3762  x = CB_BUILD_FUNCALL_2 ("$G", p->x, p->y);
3763  break;
3764  }
3765  if (cb_chk_alpha_cond (p->x) &&
3766  cb_chk_alpha_cond (p->y)) {
3767  size1 = cb_field_size (p->x);
3768  size2 = cb_field_size (p->y);
3769  } else {
3770  size1 = 0;
3771  size2 = 0;
3772  }
3773  if (size1 == 1 && size2 == 1) {
3774  x = CB_BUILD_FUNCALL_2 ("$G", p->x, p->y);
3775  } else if (size1 != 0 && size1 == size2) {
3776  x = CB_BUILD_FUNCALL_3 ("memcmp",
3777  CB_BUILD_CAST_ADDRESS (p->x),
3778  CB_BUILD_CAST_ADDRESS (p->y),
3779  cb_int (size1));
3780  } else {
3781  if (CB_TREE_CLASS (p->x) == CB_CLASS_NUMERIC && p->y == cb_zero) {
3782  x = cb_build_optim_cond (p);
3783  } else {
3784  x = CB_BUILD_FUNCALL_2 ("cob_cmp", p->x, p->y);
3785  }
3786  }
3787  }
3788  }
3789  return cb_build_binary_op (x, p->op, p->y);
3790  default:
3791  break;
3792  }
3793  cb_error_x (x, _("Invalid expression"));
3794  return cb_error_node;
3795 }
cb_tree cb_build_const_length ( cb_tree  )
1670 {
1671  struct cb_field *f;
1672  char buff[32];
1673 
1674  if (x == cb_error_node) {
1675  return cb_error_node;
1676  }
1677  if (CB_INTEGER_P (x)) {
1678  sprintf (buff, "%d", CB_INTEGER(x)->val);
1679  return cb_build_numeric_literal (0, buff, 0);
1680  }
1681  if (CB_REFERENCE_P (x)) {
1682  if (cb_ref (x) == cb_error_node) {
1683  return cb_error_node;
1684  }
1685  if (CB_REFERENCE (x)->offset) {
1686  cb_error (_("Reference modification not allowed here"));
1687  return cb_error_node;
1688  }
1689  }
1690 
1691  memset (buff, 0, sizeof (buff));
1692  f = CB_FIELD (cb_ref (x));
1693  if (f->flag_any_length) {
1694  cb_error (_("ANY LENGTH item not allowed here"));
1695  return cb_error_node;
1696  }
1697  if (f->level == 88) {
1698  cb_error (_("88 level item not allowed here"));
1699  return cb_error_node;
1700  }
1701  if (cb_field_variable_size (f)) {
1702  cb_error (_("Variable length item not allowed here"));
1703  return cb_error_node;
1704  }
1705  if (f->redefines) {
1707  if (f->rename_thru) {
1709  }
1710  cb_validate_field (f);
1711  sprintf (buff, "%d", f->size);
1712  } else {
1713  cb_validate_field (f);
1714  sprintf (buff, "%d", f->memory_size);
1715  }
1716  return cb_build_numeric_literal (0, buff, 0);
1717 }
cb_tree cb_build_constant ( cb_tree  ,
cb_tree   
)
2048 {
2049  cb_tree x;
2050 
2051  x = cb_build_field (name);
2053  CB_FIELD (x)->storage = CB_STORAGE_CONSTANT;
2054  CB_FIELD (x)->values = CB_LIST_INIT (value);
2055  return x;
2056 }
cb_tree cb_build_continue ( void  )
3065 {
3066  struct cb_continue *p;
3067 
3069  sizeof (struct cb_continue));
3070  return CB_TREE (p);
3071 }
cb_tree cb_build_converting ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5744 {
5745  validate_inspect (x, y, 2);
5746  return cb_list_add (l, CB_BUILD_FUNCALL_2 ("cob_inspect_converting", x, y));
5747 }
cb_tree cb_build_debug ( const cb_tree  ,
const char *  ,
const cb_tree   
)
1409 {
1410  struct cb_debug *p;
1411 
1413  sizeof (struct cb_debug));
1414  p->target = target;
1415  if (str) {
1416  p->value = cobc_parse_strdup (str);
1417  p->fld = NULL;
1418  p->size = strlen (str);
1419  } else {
1420  p->value = NULL;
1421  p->fld = fld;
1422  p->size = (size_t)CB_FIELD_PTR (fld)->size;
1423  }
1424  CB_TREE (p)->source_file = cb_source_file;
1425  CB_TREE (p)->source_line = cb_source_line;
1426  return CB_TREE (p);
1427 }
cb_tree cb_build_debug_call ( struct cb_label )
1433 {
1434  struct cb_debug_call *p;
1435 
1437  sizeof (struct cb_debug_call));
1438  p->target = target;
1439  CB_TREE (p)->source_file = cb_source_file;
1440  CB_TREE (p)->source_line = cb_source_line;
1441  return CB_TREE (p);
1442 }
void cb_build_debug_item ( void  )
2183 {
2184  cb_tree l;
2185  cb_tree x;
2186  cb_tree assign;
2187 
2188  /* Set up DEBUG-ITEM */
2189  l = cb_build_reference ("DEBUG-ITEM");
2191  NULL, 1);
2192  CB_FIELD (assign)->values = CB_LIST_INIT (cb_space);
2193  cb_debug_item = l;
2194 
2195  l = cb_build_reference ("DEBUG-LINE");
2196  x = cb_build_field_tree (NULL, l, CB_FIELD(assign),
2197  CB_STORAGE_WORKING, NULL, 3);
2198  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("9(6)"));
2199  cb_validate_field (CB_FIELD (x));
2200  cb_debug_line = l;
2201 
2202  l = cb_build_filler ();
2203  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2204  CB_STORAGE_WORKING, NULL, 3);
2205  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X"));
2206  CB_FIELD (x)->flag_filler = 1;
2207  cb_validate_field (CB_FIELD (x));
2208 
2209  l = cb_build_reference ("DEBUG-NAME");
2210  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2211  CB_STORAGE_WORKING, NULL, 3);
2212  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X(31)"));
2213  cb_validate_field (CB_FIELD (x));
2214  cb_debug_name = l;
2215 
2216  l = cb_build_filler ();
2217  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2218  CB_STORAGE_WORKING, NULL, 3);
2219  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X"));
2220  CB_FIELD (x)->flag_filler = 1;
2221  cb_validate_field (CB_FIELD (x));
2222 
2223  l = cb_build_reference ("DEBUG-SUB-1");
2224  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2225  CB_STORAGE_WORKING, NULL, 3);
2226  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("S9(4)"));
2227  CB_FIELD (x)->flag_sign_leading = 1;
2228  CB_FIELD (x)->flag_sign_separate = 1;
2229  cb_validate_field (CB_FIELD (x));
2230  cb_debug_sub_1 = l;
2231 
2232  l = cb_build_filler ();
2233  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2234  CB_STORAGE_WORKING, NULL, 3);
2235  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X"));
2236  CB_FIELD (x)->flag_filler = 1;
2237  cb_validate_field (CB_FIELD (x));
2238 
2239  l = cb_build_reference ("DEBUG-SUB-2");
2240  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2241  CB_STORAGE_WORKING, NULL, 3);
2242  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("S9(4)"));
2243  CB_FIELD (x)->flag_sign_leading = 1;
2244  CB_FIELD (x)->flag_sign_separate = 1;
2245  cb_validate_field (CB_FIELD (x));
2246  cb_debug_sub_2 = l;
2247 
2248  l = cb_build_filler ();
2249  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2250  CB_STORAGE_WORKING, NULL, 3);
2251  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X"));
2252  CB_FIELD (x)->flag_filler = 1;
2253  cb_validate_field (CB_FIELD (x));
2254 
2255  l = cb_build_reference ("DEBUG-SUB-3");
2256  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2257  CB_STORAGE_WORKING, NULL, 3);
2258  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("S9(4)"));
2259  CB_FIELD (x)->flag_sign_leading = 1;
2260  CB_FIELD (x)->flag_sign_separate = 1;
2261  cb_validate_field (CB_FIELD (x));
2262  cb_debug_sub_3 = l;
2263 
2264  l = cb_build_filler ();
2265  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2266  CB_STORAGE_WORKING, NULL, 3);
2267  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X"));
2268  CB_FIELD (x)->flag_filler = 1;
2269  cb_validate_field (CB_FIELD (x));
2270 
2271  l = cb_build_reference ("DEBUG-CONTENTS");
2272  x = cb_build_field_tree (NULL, l, CB_FIELD(x),
2273  CB_STORAGE_WORKING, NULL, 3);
2274  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture ("X(31)"));
2275  cb_validate_field (CB_FIELD (x));
2276  cb_debug_contents = l;
2277 
2278  cb_validate_field (CB_FIELD (assign));
2280 }
cb_tree cb_build_decimal ( const int  )
1629 {
1630  struct cb_decimal *p;
1631 
1633  sizeof (struct cb_decimal));
1634  p->id = id;
1635  return CB_TREE (p);
1636 }
cb_tree cb_build_direct ( const char *  ,
const unsigned  int 
)
1396 {
1397  cb_tree x;
1398 
1399  x = cb_build_comment (str);
1400  CB_DIRECT (x)->flag_is_direct = 1;
1401  CB_DIRECT (x)->flag_new_line = flagnl;
1402  return x;
1403 }
cb_tree cb_build_display_mnemonic ( cb_tree  )
5138 {
5139  if (x == cb_error_node) {
5140  return cb_int0;
5141  }
5142  if (cb_ref (x) == cb_error_node) {
5143  return cb_int0;
5144  }
5145 
5146  switch (CB_SYSTEM_NAME (cb_ref (x))->token) {
5147  case CB_DEVICE_CONSOLE:
5148  case CB_DEVICE_SYSOUT:
5149  return cb_int0;
5150  case CB_DEVICE_SYSERR:
5151  return cb_int1;
5152  default:
5153  cb_error_x (x, _("Invalid output device"));
5154  return cb_int0;
5155  }
5156 }
cb_tree cb_build_display_name ( cb_tree  )
5160 {
5161  const char *name;
5162  cb_tree sys;
5163 
5164  if (x == cb_error_node) {
5165  return cb_error_node;
5166  }
5167  name = CB_NAME (x);
5168  /* Allow direct reference to a device name */
5169  sys = lookup_system_name (name);
5170  if (sys) {
5171  switch (CB_SYSTEM_NAME (sys)->token) {
5172  case CB_DEVICE_CONSOLE:
5173  case CB_DEVICE_SYSOUT:
5174  if (!cb_relaxed_syntax_check) {
5175  cb_warning_x (x, _("'%s' is not defined in SPECIAL-NAMES"), name);
5176  }
5177  return cb_int0;
5178  case CB_DEVICE_SYSERR:
5179  if (!cb_relaxed_syntax_check) {
5180  cb_warning_x (x, _("'%s' is not defined in SPECIAL-NAMES"), name);
5181  }
5182  return cb_int1;
5183  default:
5184  cb_error_x (x, _("'%s' is not an output device"), name);
5185  return cb_error_node;
5186  }
5187  }
5188 
5189  cb_error_x (x, _("'%s' is not defined in SPECIAL-NAMES"), name);
5190  return cb_error_node;
5191 }
cb_tree cb_build_expr ( cb_tree  )
3060 {
3061  cb_tree l;
3062  int op;
3063 
3064  cb_expr_init ();
3065 
3066  for (l = list; l; l = CB_CHAIN (l)) {
3067  op = CB_PURPOSE_INT (l);
3068  switch (op) {
3069  case '9':
3070  /* NUMERIC */
3071  cb_expr_shift_class ("cob_is_numeric");
3072  break;
3073  case 'A':
3074  /* ALPHABETIC */
3075  cb_expr_shift_class ("cob_is_alpha");
3076  break;
3077  case 'L':
3078  /* ALPHABETIC_LOWER */
3079  cb_expr_shift_class ("cob_is_lower");
3080  break;
3081  case 'U':
3082  /* ALPHABETIC_UPPER */
3083  cb_expr_shift_class ("cob_is_upper");
3084  break;
3085  case 'P':
3086  /* POSITIVE */
3087  cb_expr_shift_sign ('>');
3088  break;
3089  case 'N':
3090  /* NEGATIVE */
3091  cb_expr_shift_sign ('<');
3092  break;
3093  case 'O':
3094  /* OMITTED */
3095  if (current_statement) {
3097  }
3098  cb_expr_shift_class ("cob_is_omitted");
3099  break;
3100  case 'C':
3101  /* CLASS */
3102  cb_expr_shift_class (CB_CLASS_NAME (cb_ref (CB_VALUE (l)))->cname);
3103  break;
3104  default:
3105  cb_expr_shift (op, CB_VALUE (l));
3106  break;
3107  }
3108  }
3109 
3110  return cb_expr_finish ();
3111 }
cb_tree cb_build_field ( cb_tree  )
2018 {
2019  struct cb_field *p;
2020 
2022  sizeof (struct cb_field));
2023  p->id = cb_field_id++;
2024  p->name = cb_define (name, CB_TREE (p));
2025  p->ename = NULL;
2026  p->usage = CB_USAGE_DISPLAY;
2028  p->occurs_max = 1;
2029  return CB_TREE (p);
2030 }
cb_tree cb_build_field_reference ( struct cb_field ,
cb_tree   
)
2456 {
2457  cb_tree x;
2458  struct cb_word *word;
2459 
2460  x = cb_build_reference (f->name);
2461  word = CB_REFERENCE (x)->word;
2462  if (ref) {
2463  memcpy (x, ref, sizeof (struct cb_reference));
2464  }
2466  CB_REFERENCE (x)->word = word;
2467  CB_REFERENCE (x)->value = CB_TREE (f);
2468  return x;
2469 }
cb_tree cb_build_field_tree ( cb_tree  ,
cb_tree  ,
struct cb_field ,
enum  cb_storage,
struct cb_file ,
const int   
)
93 {
94  struct cb_reference *r;
95  struct cb_field *f;
96  struct cb_field *p;
97  struct cb_field *field_fill;
98  cb_tree dummy_fill;
99  cb_tree l;
100  cb_tree x;
101  int lv;
102 
103  if (!expl_level) {
104  if (level == cb_error_node || name == cb_error_node) {
105  return cb_error_node;
106  }
107  /* Check the level number */
108  lv = cb_get_level (level);
109  if (!lv) {
110  return cb_error_node;
111  }
112  } else {
113  lv = expl_level;
114  }
115 
116  /* Build the field */
117  r = CB_REFERENCE (name);
118  f = CB_FIELD (cb_build_field (name));
119  f->storage = storage;
120  last_real_field = last_field;
121  if (lv == 78) {
122  f->level = 01;
123  f->flag_item_78 = 1;
124  return CB_TREE (f);
125  } else {
126  f->level = lv;
127  }
128  if (f->level == 01 && storage == CB_STORAGE_FILE && fn) {
129  if (fn->flag_external) {
130  f->flag_external = 1;
132  } else if (fn->flag_global) {
133  f->flag_is_global = 1;
134  }
135  }
136  if (last_field) {
137  if (last_field->level == 77 && f->level != 01 &&
138  f->level != 77 && f->level != 66 && f->level != 88) {
139  cb_error_x (name, _("Level number must begin with 01 or 77"));
140  return cb_error_node;
141  }
142  }
143 
144  /* Checks for redefinition */
145  if (cb_warn_redefinition && r->word->count > 1 && !r->flag_filler_ref) {
146  if (f->level == 01 || f->level == 77) {
148  } else {
149  for (l = r->word->items; l; l = CB_CHAIN (l)) {
150  x = CB_VALUE (l);
151  if (!CB_FIELD_P (x) ||
152  CB_FIELD (x)->level == 01 ||
153  CB_FIELD (x)->level == 77 ||
154  (last_field && f->level == last_field->level &&
155  CB_FIELD (x)->parent == last_field->parent)) {
157  break;
158  }
159  }
160  }
161  }
162 
163  if (last_field && last_field->level == 88) {
164  last_field = last_field->parent;
165  }
166 
167  /* Link the field into the tree */
168  if (f->level == 01 || f->level == 77) {
169  /* Top level */
170  cb_needs_01 = 0;
171  if (last_field) {
172  cb_field_founder (last_field)->sister = f;
173  }
174  } else if (!last_field || cb_needs_01) {
175  /* Invalid top level */
176  cb_error_x (name, _("Level number must begin with 01 or 77"));
177  return cb_error_node;
178  } else if (f->level == 66) {
179  /* Level 66 */
180  f->parent = cb_field_founder (last_field);
181  for (p = f->parent->children; p && p->sister; p = p->sister) ;
182  if (p) {
183  p->sister = f;
184  }
185  } else if (f->level == 88) {
186  /* Level 88 */
187  f->parent = last_field;
188  } else if (f->level > last_field->level) {
189  /* Lower level */
190  last_field->children = f;
191  f->parent = last_field;
192  } else if (f->level == last_field->level) {
193  /* Same level */
194 same_level:
195  last_field->sister = f;
196  f->parent = last_field->parent;
197  } else {
198  /* Upper level */
199  for (p = last_field->parent; p; p = p->parent) {
200  if (p->level == f->level) {
201  last_field = p;
202  goto same_level;
203  }
204  if (cb_relax_level_hierarchy && p->level < f->level) {
205  break;
206  }
207  }
208  if (cb_relax_level_hierarchy) {
209  dummy_fill = cb_build_filler ();
210  field_fill = CB_FIELD (cb_build_field (dummy_fill));
212  _("No previous data item of level %02d"),
213  f->level);
214  field_fill->level = f->level;
215  field_fill->flag_filler = 1;
216  field_fill->storage = storage;
217  field_fill->children = p->children;
218  field_fill->parent = p;
219  for (p = p->children; p; p = p->sister) {
220  p->parent = field_fill;
221  }
222  field_fill->parent->children = field_fill;
223  field_fill->sister = f;
224  f->parent = field_fill->parent;
225  /* last_field = field_fill; */
226  } else {
227  cb_error_x (name,
228  _("No previous data item of level %02d"),
229  f->level);
230  return cb_error_node;
231  }
232  }
233 
234  /* Inherit parents properties */
235  if (f->parent) {
236  f->usage = f->parent->usage;
237  f->indexes = f->parent->indexes;
241  }
242  return CB_TREE (f);
243 }
cb_tree cb_build_filler ( void  )
2443 {
2444  cb_tree x;
2445  char name[20];
2446 
2447  sprintf (name, "FILLER %d", filler_id++);
2448  x = cb_build_reference (name);
2450  CB_REFERENCE (x)->flag_filler_ref = 1;
2451  return x;
2452 }
cb_tree cb_build_funcall ( const char *  ,
const int  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree   
)
2772 {
2773  struct cb_funcall *p;
2774 
2776  sizeof (struct cb_funcall));
2777  p->name = name;
2778  p->argc = argc;
2779  p->varcnt = 0;
2781  p->argv[0] = a1;
2782  p->argv[1] = a2;
2783  p->argv[2] = a3;
2784  p->argv[3] = a4;
2785  p->argv[4] = a5;
2786  p->argv[5] = a6;
2787  p->argv[6] = a7;
2788  p->argv[7] = a8;
2789  p->argv[8] = a9;
2790  p->argv[9] = a10;
2791  return CB_TREE (p);
2792 }
cb_tree cb_build_goto ( const cb_tree  ,
const cb_tree   
)
2969 {
2970  struct cb_goto *p;
2971 
2973  sizeof (struct cb_goto));
2974  p->target = target;
2975  p->depending = depending;
2976  return CB_TREE (p);
2977 }
cb_tree cb_build_identifier ( cb_tree  ,
const int   
)
1398 {
1399  struct cb_reference *r;
1400  struct cb_field *f;
1401  struct cb_field *p;
1402  const char *name;
1403  cb_tree v;
1404  cb_tree e1;
1405  cb_tree e2;
1406  cb_tree l;
1407  cb_tree sub;
1408  int offset;
1409  int length;
1410  int n;
1411  int numsubs;
1412  int refsubs;
1413  int pseudosize;
1414 
1415  if (x == cb_error_node) {
1416  return cb_error_node;
1417  }
1418 
1419  r = CB_REFERENCE (x);
1420  name = r->word->name;
1421 
1422  /* Resolve reference */
1423  v = cb_ref (x);
1424  if (v == cb_error_node) {
1425  return cb_error_node;
1426  }
1427 
1428  /* Check if it is a data name */
1429  if (!CB_FIELD_P (v)) {
1430  if (r->subs) {
1431  cb_error_x (x, _("'%s' cannot be subscripted"), name);
1432  return cb_error_node;
1433  }
1434  if (r->offset) {
1435  cb_error_x (x, _("'%s' cannot be reference modified"), name);
1436  return cb_error_node;
1437  }
1438  return x;
1439  }
1440  f = CB_FIELD (v);
1441 
1442  /* BASED check */
1444  p = cb_field_founder (f);
1445  if (p->redefines) {
1446  p = p->redefines;
1447  }
1449  if (p->flag_item_based ||
1450  (f->storage == CB_STORAGE_LINKAGE &&
1451  !p->flag_is_pdiv_parm)) {
1453  "cob_check_based",
1455  CB_BUILD_STRING0 (name));
1456  }
1457  }
1458  }
1459 
1460  for (l = r->subs; l; l = CB_CHAIN (l)) {
1461  if (CB_BINARY_OP_P (CB_VALUE (l))) {
1462  /* Set special flag for codegen */
1463  CB_BINARY_OP(CB_VALUE(l))->flag = 1;
1464  }
1465  }
1466 
1467  /* Check the number of subscripts */
1468  numsubs = cb_list_length (r->subs);
1469  cb_check_lit_subs (r, numsubs, f->indexes);
1470  if (subchk) {
1471  if (!f->indexes) {
1472  cb_error_x (x, _("'%s' has no OCCURS clause"), name);
1473  return cb_error_node;
1474  }
1475  numsubs = f->indexes - 1;
1476  } else {
1477  numsubs = f->indexes;
1478  }
1479  refsubs = cb_list_length (r->subs);
1480  if (!r->flag_all && refsubs != numsubs) {
1481  if (refsubs > numsubs) {
1482  goto refsubserr;
1483  } else if (refsubs < numsubs) {
1484  if (!cb_relaxed_syntax_check) {
1485  goto refsubserr;
1486  } else {
1487  cb_warning_x (x,
1488  _("Subscripts missing for '%s' - Defaulting to 1"),
1489  name);
1490  for (; refsubs < numsubs; ++refsubs) {
1491  CB_ADD_TO_CHAIN (cb_one, r->subs);
1492  }
1493  }
1494  }
1495  }
1496 
1497  /* Subscript check */
1498  if (!r->flag_all && r->subs) {
1499  l = r->subs;
1500  for (p = f; p; p = p->parent) {
1501  if (!p->flag_occurs) {
1502  continue;
1503  }
1504 
1505 #if 1 /* RXWRXW - Sub check */
1506  if (!l) {
1507  break;
1508  }
1509 #endif
1510  sub = cb_check_integer_value (CB_VALUE (l));
1511  l = CB_CHAIN (l);
1512  if (sub == cb_error_node) {
1513  continue;
1514  }
1515 
1516  /* Compile-time check */
1517  if (CB_LITERAL_P (sub)) {
1518  n = cb_get_int (sub);
1519  if (n < 1 || n > p->occurs_max) {
1520  cb_error_x (x, _("Subscript of '%s' out of bounds: %d"),
1521  name, n);
1522  }
1523  }
1524 
1525  /* Run-time check */
1526  if (CB_EXCEPTION_ENABLE (COB_EC_BOUND_SUBSCRIPT)) {
1527  if (p->depending) {
1528  e1 = CB_BUILD_FUNCALL_4 ("cob_check_odo",
1530  cb_int (p->occurs_min),
1531  cb_int (p->occurs_max),
1533  ((CB_FIELD_PTR (p->depending)->name)));
1534  e2 = CB_BUILD_FUNCALL_4 ("cob_check_subscript",
1535  cb_build_cast_int (sub),
1536  cb_int1,
1538  CB_BUILD_STRING0 (name));
1539  r->check = cb_list_add (r->check, e1);
1540  r->check = cb_list_add (r->check, e2);
1541  } else {
1542  if (!CB_LITERAL_P (sub)) {
1543  e1 = CB_BUILD_FUNCALL_4 ("cob_check_subscript",
1544  cb_build_cast_int (sub),
1545  cb_int1,
1546  cb_int (p->occurs_max),
1547  CB_BUILD_STRING0 (name));
1548  r->check = cb_list_add (r->check, e1);
1549  }
1550  }
1551  }
1552  }
1553  }
1554 
1555  if (subchk) {
1556  r->subs = cb_list_reverse (r->subs);
1557  r->subs = cb_list_add (r->subs, cb_int1);
1558  r->subs = cb_list_reverse (r->subs);
1559  }
1560 
1561  /* Reference modification check */
1562  if ( f->usage == CB_USAGE_NATIONAL ) {
1563  pseudosize = f->size / 2;
1564  } else {
1565  pseudosize = f->size;
1566  }
1567  if (r->offset) {
1568  /* Compile-time check */
1569  if (CB_LITERAL_P (r->offset)) {
1570  offset = cb_get_int (r->offset);
1571  if (f->flag_any_length) {
1572  if (offset < 1) {
1573  cb_error_x (x, _("Offset of '%s' out of bounds: %d"), name, offset);
1574  } else if (r->length && CB_LITERAL_P (r->length)) {
1575  length = cb_get_int (r->length);
1576  if (length < 1) {
1577  cb_error_x (x, _("Length of '%s' out of bounds: %d"),
1578  name, length);
1579  }
1580  }
1581  } else {
1582  if (offset < 1 || offset > pseudosize) {
1583  cb_error_x (x, _("Offset of '%s' out of bounds: %d"), name, offset);
1584  } else if (r->length && CB_LITERAL_P (r->length)) {
1585  length = cb_get_int (r->length);
1586  if (length < 1 || length > pseudosize - offset + 1) {
1587  cb_error_x (x, _("Length of '%s' out of bounds: %d"),
1588  name, length);
1589  }
1590  }
1591  }
1592  }
1593 
1594  /* Run-time check */
1595  if (CB_EXCEPTION_ENABLE (COB_EC_BOUND_REF_MOD)) {
1596  if (f->flag_any_length || !CB_LITERAL_P (r->offset) ||
1597  (r->length && !CB_LITERAL_P (r->length))) {
1598  e1 = CB_BUILD_FUNCALL_4 ("cob_check_ref_mod",
1600  r->length ?
1601  cb_build_cast_int (r->length) :
1602  cb_int1,
1603  f->flag_any_length ?
1604  CB_BUILD_CAST_LENGTH (v) :
1605  cb_int (pseudosize),
1606  CB_BUILD_STRING0 (f->name));
1607  r->check = cb_list_add (r->check, e1);
1608  }
1609  }
1610  }
1611 
1612  if (f->storage == CB_STORAGE_CONSTANT) {
1613  return CB_VALUE (f->values);
1614  }
1615 
1616  return x;
1617 
1618 refsubserr:
1619  switch (numsubs) {
1620  case 0:
1621  cb_error_x (x, _("'%s' cannot be subscripted"), name);
1622  break;
1623  case 1:
1624  cb_error_x (x, _("'%s' requires 1 subscript"), name);
1625  break;
1626  default:
1627  cb_error_x (x, _("'%s' requires %d subscripts"),
1628  name, f->indexes);
1629  break;
1630  }
1631  return cb_error_node;
1632 }
cb_tree cb_build_if ( const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const unsigned  int 
)
2984 {
2985  struct cb_if *p;
2986 
2988  sizeof (struct cb_if));
2989  p->test = test;
2990  p->stmt1 = stmt1;
2991  p->stmt2 = stmt2;
2992  p->is_if = is_if;
2993  return CB_TREE (p);
2994 }
cb_tree cb_build_if_check_break ( cb_tree  ,
cb_tree   
)
5469 {
5470  cb_tree stmt_lis;
5471 
5472  stmt_lis = cb_check_needs_break (stmts);
5473  return cb_build_if (cond, stmt_lis, NULL, 0);
5474 }
cb_tree cb_build_implicit_field ( cb_tree  ,
const int   
)
2034 {
2035  cb_tree x;
2036  char pic[32];
2037 
2038  x = cb_build_field (name);
2039  memset (pic, 0, sizeof(pic));
2040  snprintf (pic, sizeof(pic), "X(%d)", len);
2041  CB_FIELD (x)->pic = CB_PICTURE (cb_build_picture (pic));
2042  cb_validate_field (CB_FIELD (x));
2043  return x;
2044 }
cb_tree cb_build_index ( cb_tree  ,
cb_tree  ,
const unsigned  int,
struct cb_field  
)
1310 {
1311  struct cb_field *f;
1312 
1313  f = CB_FIELD (cb_build_field (x));
1314  f->usage = CB_USAGE_INDEX;
1315  cb_validate_field (f);
1316  if (values) {
1317  f->values = CB_LIST_INIT (values);
1318  }
1319  if (qual) {
1320  f->index_qual = qual;
1321  }
1322  f->flag_indexed_by = !!indexed_by;
1324  return x;
1325 }
cb_tree cb_build_initialize ( const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const unsigned  int,
const unsigned  int,
const unsigned  int 
)
2882 {
2883  struct cb_initialize *p;
2884 
2886  sizeof (struct cb_initialize));
2887  p->var = var;
2888  p->val = val;
2889  p->rep = rep;
2890  p->flag_default = (cob_u8_t)def;
2891  p->flag_init_statement = (cob_u8_t)is_statement;
2892  p->flag_no_filler_init = (cob_u8_t)no_filler_init;
2893  return CB_TREE (p);
2894 }
cb_tree cb_build_inspect_region_start ( void  )
5751 {
5752  return CB_LIST_INIT (CB_BUILD_FUNCALL_0 ("cob_inspect_start"));
5753 }
cb_tree cb_build_intrinsic ( cb_tree  ,
cb_tree  ,
cb_tree  ,
const int   
)
3103 {
3104  struct cb_intrinsic_table *cbp;
3105  cb_tree x;
3106  int numargs;
3107  enum cb_category catg;
3108 
3109  numargs = cb_list_length (args);
3110 
3111  if (unlikely(isuser)) {
3112  if (refmod && CB_LITERAL_P(CB_PAIR_X(refmod)) &&
3113  cb_get_int (CB_PAIR_X(refmod)) < 1) {
3114  cb_error_x (name, _("FUNCTION '%s' has invalid reference modification"), CB_NAME(name));
3115  return cb_error_node;
3116  }
3117  if (refmod && CB_PAIR_Y(refmod) &&
3119  cb_get_int (CB_PAIR_Y(refmod)) < 1) {
3120  cb_error_x (name, _("FUNCTION '%s' has invalid reference modification"), CB_NAME(name));
3121  return cb_error_node;
3122  }
3123  if (numargs > current_program->max_call_param) {
3124  current_program->max_call_param = numargs;
3125  }
3126  return make_intrinsic (name, &userbp, args, cb_int1, refmod, 1);
3127  }
3128 
3129  cbp = lookup_intrinsic (CB_NAME (name), 0, 1);
3130  if (!cbp) {
3131  cb_error_x (name, _("FUNCTION '%s' unknown"), CB_NAME (name));
3132  return cb_error_node;
3133  }
3134  if (!cbp->implemented) {
3135  cb_error_x (name, _("FUNCTION '%s' not implemented"),
3136  cbp->name);
3137  return cb_error_node;
3138  }
3139  if ((cbp->args >= 0 && numargs != cbp->args) ||
3140  (cbp->args < 0 && numargs < cbp->min_args)) {
3141  cb_error_x (name,
3142  _("FUNCTION '%s' has wrong number of arguments"),
3143  cbp->name);
3144  return cb_error_node;
3145  }
3146  if (refmod) {
3147  if (!cbp->refmod) {
3148  cb_error_x (name, _("FUNCTION '%s' can not have reference modification"), cbp->name);
3149  return cb_error_node;
3150  }
3151  if (CB_LITERAL_P(CB_PAIR_X(refmod)) &&
3152  cb_get_int (CB_PAIR_X(refmod)) < 1) {
3153  cb_error_x (name, _("FUNCTION '%s' has invalid reference modification"), cbp->name);
3154  return cb_error_node;
3155  }
3157  cb_get_int (CB_PAIR_Y(refmod)) < 1) {
3158  cb_error_x (name, _("FUNCTION '%s' has invalid reference modification"), cbp->name);
3159  return cb_error_node;
3160  }
3161  }
3162 
3163  if (iso_8601_func (cbp->intr_enum)) {
3164  if (!valid_const_date_time_args (name, cbp, args)) {
3165  return cb_error_node;
3166  }
3167  }
3168 
3169  switch (cbp->intr_enum) {
3170  case CB_INTR_LENGTH:
3171  case CB_INTR_BYTE_LENGTH:
3172  x = CB_VALUE (args);
3173  if (CB_LITERAL_P (x)) {
3174  return cb_build_length (x);
3175  } else {
3176  return make_intrinsic (name, cbp, args, NULL, NULL, 0);
3177  }
3178 
3179  case CB_INTR_WHEN_COMPILED:
3180  if (refmod) {
3181  return make_intrinsic (name, cbp,
3182  CB_LIST_INIT (cb_intr_whencomp), NULL, refmod, 0);
3183  } else {
3184  return cb_intr_whencomp;
3185  }
3186 
3187  case CB_INTR_ABS:
3188  case CB_INTR_ACOS:
3189  case CB_INTR_ASIN:
3190  case CB_INTR_ATAN:
3191  case CB_INTR_COS:
3194  case CB_INTR_EXP:
3195  case CB_INTR_EXP10:
3196  case CB_INTR_FACTORIAL:
3197  case CB_INTR_FRACTION_PART:
3198  case CB_INTR_INTEGER:
3201  case CB_INTR_INTEGER_PART:
3202  case CB_INTR_LOG:
3203  case CB_INTR_LOG10:
3204  case CB_INTR_SIGN:
3205  case CB_INTR_SIN:
3206  case CB_INTR_SQRT:
3207  case CB_INTR_TAN:
3210  x = CB_VALUE (args);
3212  cb_error_x (name, _("FUNCTION '%s' has invalid parameter"), cbp->name);
3213  return cb_error_node;
3214  }
3215  return make_intrinsic (name, cbp, args, NULL, refmod, 0);
3216 
3217  case CB_INTR_ANNUITY:
3219  case CB_INTR_CHAR:
3220  case CB_INTR_CHAR_NATIONAL:
3223  case CB_INTR_CURRENT_DATE:
3224  case CB_INTR_E:
3235  case CB_INTR_LOCALE_DATE:
3236  case CB_INTR_LOCALE_TIME:
3238  case CB_INTR_LOWER_CASE:
3239  case CB_INTR_MOD:
3241  case CB_INTR_MODULE_DATE:
3243  case CB_INTR_MODULE_ID:
3244  case CB_INTR_MODULE_PATH:
3245  case CB_INTR_MODULE_SOURCE:
3246  case CB_INTR_MODULE_TIME:
3251  case CB_INTR_NUMVAL:
3252  case CB_INTR_NUMVAL_C:
3253  case CB_INTR_NUMVAL_F:
3254  case CB_INTR_ORD:
3255  case CB_INTR_PI:
3256  case CB_INTR_REM:
3257  case CB_INTR_REVERSE:
3262  case CB_INTR_TEST_NUMVAL:
3263  case CB_INTR_TEST_NUMVAL_C:
3264  case CB_INTR_TEST_NUMVAL_F:
3265  case CB_INTR_TRIM:
3266  case CB_INTR_UPPER_CASE:
3267  return make_intrinsic (name, cbp, args, NULL, refmod, 0);
3268 
3271  x = CB_VALUE (args);
3272  if (!CB_REF_OR_FIELD_P (x)) {
3273  cb_error_x (name, _("FUNCTION '%s' has invalid parameter"), cbp->name);
3274  return cb_error_node;
3275  }
3276  catg = cb_tree_category (x);
3277  if (catg != CB_CATEGORY_NUMERIC &&
3278  catg != CB_CATEGORY_NUMERIC_EDITED) {
3279  cb_error_x (name, _("FUNCTION '%s' has invalid parameter"), cbp->name);
3280  return cb_error_node;
3281  }
3282  return make_intrinsic (name, cbp, args, NULL, refmod, 0);
3283 
3284 
3285  case CB_INTR_CONCATENATE:
3286  case CB_INTR_DISPLAY_OF:
3289  case CB_INTR_NATIONAL_OF:
3290  return make_intrinsic (name, cbp, args, cb_int1, refmod, 0);
3291 
3295  case CB_INTR_MAX:
3296  case CB_INTR_MEAN:
3297  case CB_INTR_MEDIAN:
3298  case CB_INTR_MIDRANGE:
3299  case CB_INTR_MIN:
3300  case CB_INTR_ORD_MAX:
3301  case CB_INTR_ORD_MIN:
3302  case CB_INTR_PRESENT_VALUE:
3303  case CB_INTR_RANDOM:
3304  case CB_INTR_RANGE:
3307  case CB_INTR_SUM:
3308  case CB_INTR_VARIANCE:
3309  case CB_INTR_YEAR_TO_YYYY:
3310  return make_intrinsic (name, cbp, args, cb_int1, NULL, 0);
3311  case CB_INTR_SUBSTITUTE:
3313  if ((numargs % 2) == 0) {
3314  cb_error_x (name, _("FUNCTION '%s' has wrong number of arguments"), cbp->name);
3315  return cb_error_node;
3316  }
3317 #if 0 /* RXWRXW - Substitute param 1 */
3318  x = CB_VALUE (args);
3319  if (!CB_REF_OR_FIELD_P (x)) {
3320  cb_error_x (name, _("FUNCTION '%s' has invalid first parameter"), cbp->name);
3321  return cb_error_node;
3322  }
3323 #endif
3324  return make_intrinsic (name, cbp, args, cb_int1, refmod, 0);
3325 
3326  default:
3327  cb_error_x (name, _("FUNCTION '%s' unknown"), CB_NAME (name));
3328  return cb_error_node;
3329  }
3330 }
cb_tree cb_build_label ( cb_tree  ,
struct cb_label  
)
2839 {
2840  struct cb_label *p;
2841  struct cb_para_label *l;
2842 
2844  sizeof (struct cb_label));
2845  p->id = cb_id++;
2846  p->name = cb_define (name, CB_TREE (p));
2847  p->orig_name = p->name;
2848  p->section = section;
2849  if (section) {
2850  l = cobc_parse_malloc (sizeof(struct cb_para_label));
2851  l->next = section->para_label;
2852  l->para= p;
2853  section->para_label = l;
2854  p->section_id = p->section->id;
2855  } else {
2856  p->section_id = p->id;
2857  }
2858  return CB_TREE (p);
2859 }
cb_tree cb_build_length ( cb_tree  )
1721 {
1722  struct cb_field *f;
1723  struct cb_literal *l;
1724  cb_tree temp;
1725  char buff[32];
1726 
1727  if (x == cb_error_node) {
1728  return cb_error_node;
1729  }
1730  if (CB_REFERENCE_P (x) && cb_ref (x) == cb_error_node) {
1731  return cb_error_node;
1732  }
1733 
1734  if (CB_LITERAL_P (x)) {
1735  l = CB_LITERAL (x);
1736  sprintf (buff, "%d", (int)l->size);
1737  return cb_build_numeric_literal (0, buff, 0);
1738  }
1739  if (CB_INTRINSIC_P (x)) {
1740  return cb_build_any_intrinsic (CB_LIST_INIT (x));
1741  }
1742  if (CB_REF_OR_FIELD_P (x)) {
1743  if (CB_REFERENCE_P (x) && CB_REFERENCE (x)->offset) {
1744  return cb_build_any_intrinsic (CB_LIST_INIT (x));
1745  }
1746  f = CB_FIELD (cb_ref (x));
1747  if (f->flag_any_length) {
1748  return cb_build_any_intrinsic (CB_LIST_INIT (x));
1749  }
1750  if (cb_field_variable_size (f) == NULL) {
1751  sprintf (buff, "%d", cb_field_size (x));
1752  return cb_build_numeric_literal (0, buff, 0);
1753  }
1754  }
1755  temp = cb_build_index (cb_build_filler (), NULL, 0, NULL);
1756  CB_FIELD (cb_ref (temp))->usage = CB_USAGE_LENGTH;
1757  CB_FIELD (cb_ref (temp))->count++;
1759  return temp;
1760 }
cb_tree cb_build_list ( cb_tree  ,
cb_tree  ,
cb_tree   
)
1134 {
1135  struct cb_list *p;
1136 
1137  p = make_tree (CB_TAG_LIST, CB_CATEGORY_UNKNOWN, sizeof (struct cb_list));
1138  p->chain = chain;
1139  p->value = value;
1140  p->purpose = purpose;
1141  return CB_TREE (p);
1142 }
cb_tree cb_build_locale_name ( cb_tree  ,
cb_tree   
)
1488 {
1489  struct cb_class_name *p;
1490 
1491  if (!name || name == cb_error_node) {
1492  return NULL;
1493  }
1494  if (!CB_LITERAL_P (list) || CB_NUMERIC_LITERAL_P (list)) {
1495  cb_error (_("Invalid LOCALE literal"));
1496  return cb_error_node;
1497  }
1499  sizeof (struct cb_locale_name));
1500  p->name = cb_define (name, CB_TREE (p));
1501  p->cname = cb_to_cname (p->name);
1502  p->list = list;
1503  return CB_TREE (p);
1504 }
cb_tree cb_build_move ( cb_tree  ,
cb_tree   
)
7103 {
7104  struct cb_reference *x;
7105 
7106  if (src == cb_error_node || dst == cb_error_node) {
7107  return cb_error_node;
7108  }
7109 
7110  if (validate_move (src, dst, 0) < 0) {
7111  return cb_error_node;
7112  }
7113 
7114 #if 0 /* Flag receiving */
7115  if (CB_REFERENCE_P (src)) {
7116  CB_REFERENCE (src)->flag_receiving = 0;
7117  }
7118 #endif
7119 
7120  if (CB_REFERENCE_P (dst)) {
7121  /* Clone reference */
7122  x = cobc_parse_malloc (sizeof(struct cb_reference));
7123  *x = *CB_REFERENCE (dst);
7124  x->flag_receiving = 1;
7125  dst = CB_TREE (x);
7126  }
7127 
7128  if ((src == cb_space || src == cb_low ||
7129  src == cb_high || src == cb_quote) &&
7130  (CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC ||
7131  CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC_EDITED)) {
7132  src = cb_zero;
7133  }
7134 
7135  if (CB_TREE_CLASS (dst) == CB_CLASS_POINTER ||
7136  CB_TREE_CLASS (src) == CB_CLASS_POINTER) {
7137  return cb_build_assign (dst, src);
7138  }
7139 
7140  if (CB_REFERENCE_P (src) &&
7142  return CB_BUILD_FUNCALL_2 ("cob_move", src, dst);
7143  }
7144  if (CB_INDEX_P (dst)) {
7145  if (src == cb_null) {
7146  return cb_build_assign (dst, cb_zero);
7147  }
7148  return cb_build_assign (dst, src);
7149  }
7150 
7151  if (CB_INDEX_P (src)) {
7152  return CB_BUILD_FUNCALL_2 ("cob_set_int", dst,
7153  cb_build_cast_int (src));
7154  }
7155 
7156  if (CB_INTRINSIC_P (src) || CB_INTRINSIC_P (dst)) {
7157  return CB_BUILD_FUNCALL_2 ("cob_move", src, dst);
7158  }
7159 
7160  if (CB_REFERENCE_P (src) && CB_REFERENCE (src)->check) {
7161  return CB_BUILD_FUNCALL_2 ("cob_move", src, dst);
7162  }
7163  if (CB_REFERENCE_P (dst) && CB_REFERENCE (dst)->check) {
7164  return CB_BUILD_FUNCALL_2 ("cob_move", src, dst);
7165  }
7166 
7167  /* Output optimal code */
7168  if (src == cb_zero) {
7169  return cb_build_move_zero (dst);
7170  } else if (src == cb_space) {
7171  return cb_build_move_space (dst);
7172  } else if (src == cb_high) {
7173  return cb_build_move_high (dst);
7174  } else if (src == cb_low) {
7175  return cb_build_move_low (dst);
7176  } else if (src == cb_quote) {
7177  return cb_build_move_quote (dst);
7178  } else if (CB_LITERAL_P (src)) {
7179  return cb_build_move_literal (src, dst);
7180  }
7181  return cb_build_move_field (src, dst);
7182 }
cb_tree cb_build_numeric_literal ( const int  ,
const void *  ,
const int   
)
1525 {
1526  struct cb_literal *p;
1527 
1528  p = build_literal (CB_CATEGORY_NUMERIC, data, strlen (data));
1529  p->sign = (short)sign;
1530  p->scale = scale;
1531  return CB_TREE (p);
1532 }
cb_tree cb_build_numsize_literal ( const void *  ,
const size_t  ,
const int   
)
1536 {
1537  struct cb_literal *p;
1538 
1540  p->sign = (short)sign;
1541  return CB_TREE (p);
1542 }
cb_tree cb_build_perform ( const enum  cb_perform_type)
3000 {
3001  struct cb_perform *p;
3002 
3004  sizeof (struct cb_perform));
3005  p->perform_type = type;
3006  return CB_TREE (p);
3007 }
cb_tree cb_build_perform_exit ( struct cb_label )
7344 {
7345  cb_tree x;
7346 
7348  CB_PERFORM (x)->data = CB_TREE (label);
7349  return x;
7350 }
cb_tree cb_build_perform_forever ( cb_tree  )
7331 {
7332  cb_tree x;
7333 
7334  if (body == cb_error_node) {
7335  return cb_error_node;
7336  }
7338  CB_PERFORM (x)->body = body;
7339  return x;
7340 }
cb_tree cb_build_perform_once ( cb_tree  )
7293 {
7294  cb_tree x;
7295 
7296  if (body == cb_error_node) {
7297  return cb_error_node;
7298  }
7300  CB_PERFORM (x)->body = body;
7301  return x;
7302 }
cb_tree cb_build_perform_times ( cb_tree  )
7306 {
7307  cb_tree x;
7308 
7309  if (cb_check_integer_value (times) == cb_error_node) {
7310  return cb_error_node;
7311  }
7312 
7314  CB_PERFORM (x)->data = times;
7315  return x;
7316 }
cb_tree cb_build_perform_until ( cb_tree  ,
cb_tree   
)
7320 {
7321  cb_tree x;
7322 
7324  CB_PERFORM (x)->test = condition;
7325  CB_PERFORM (x)->varying = varying;
7326  return x;
7327 }
cb_tree cb_build_perform_varying ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
3011 {
3012  struct cb_perform_varying *p;
3013  cb_tree x;
3014  cb_tree l;
3015 
3017  sizeof (struct cb_perform_varying));
3018  p->name = name;
3019  p->from = from;
3020  p->until = until;
3021  if (name) {
3022  if (name == cb_error_node) {
3023  p->step = NULL;
3024  return CB_TREE (p);
3025  }
3026  l = cb_ref (name);
3027  x = cb_build_add (name, by, cb_high);
3030  CB_FIELD_P (l) && CB_FIELD (l)->flag_field_debug) {
3031  p->step = CB_LIST_INIT (x);
3032  x = cb_build_debug (cb_debug_name, CB_FIELD_PTR (name)->name,
3033  NULL);
3034  p->step = cb_list_add (p->step, x);
3036  p->step = cb_list_add (p->step, x);
3037  x = cb_build_debug_call (CB_FIELD_PTR (name)->debug_section);
3038  p->step = cb_list_add (p->step, x);
3039  } else {
3040  p->step = x;
3041  }
3042  } else {
3043  p->step = NULL;
3044  }
3045  return CB_TREE (p);
3046 }
cb_tree cb_build_picture ( const char *  )
1659 {
1660  struct cb_picture *pic;
1661  const unsigned char *p;
1662  size_t idx;
1663  size_t buffcnt;
1664  cob_u32_t at_beginning;
1665  cob_u32_t at_end;
1666  cob_u32_t p_char_seen;
1667  cob_u32_t s_char_seen;
1668  cob_u32_t dp_char_seen;
1670  cob_u32_t s_count;
1671  cob_u32_t v_count;
1672  cob_u32_t allocated;
1673  cob_u32_t x_digits;
1674  cob_u32_t digits;
1675  int category;
1676  int size;
1677  int scale;
1678  int i;
1679  int n;
1680  unsigned char c;
1681  unsigned char lastonechar;
1682  unsigned char lasttwochar;
1683 
1685  sizeof (struct cb_picture));
1686  if (strlen (str) > 50) {
1687  goto error;
1688  }
1689  if (!pic_buff) {
1690  pic_buff = cobc_main_malloc ((size_t)COB_SMALL_BUFF);
1691  }
1692 
1693  idx = 0;
1694  buffcnt = 0;
1695  p_char_seen = 0;
1696  s_char_seen = 0;
1697  dp_char_seen = 0;
1698  category = 0;
1699  size = 0;
1700  allocated = 0;
1701  digits = 0;
1702  x_digits = 0;
1703  real_digits = 0;
1704  scale = 0;
1705  s_count = 0;
1706  v_count = 0;
1707  lastonechar = 0;
1708  lasttwochar = 0;
1709 
1710  for (p = (const unsigned char *)str; *p; p++) {
1711  n = 1;
1712  c = *p;
1713 repeat:
1714  /* Count the number of repeated chars */
1715  while (p[1] == c) {
1716  p++, n++;
1717  }
1718 
1719  /* Add parenthesized numbers */
1720  if (p[1] == '(') {
1721  i = 0;
1722  p += 2;
1723  for (; *p == '0'; p++) {
1724  ;
1725  }
1726  for (; *p != ')'; p++) {
1727  if (!isdigit (*p)) {
1728  goto error;
1729  } else {
1730  allocated++;
1731  if (allocated > 9) {
1732  goto error;
1733  }
1734  i = i * 10 + (*p - '0');
1735  }
1736  }
1737  if (i == 0) {
1738  goto error;
1739  }
1740  n += i - 1;
1741  goto repeat;
1742  }
1743 
1744  /* Check grammar and category */
1745  /* FIXME: need more error checks */
1746  switch (c) {
1747  case 'A':
1748  if (s_char_seen || p_char_seen) {
1749  goto error;
1750  }
1751  category |= PIC_ALPHABETIC;
1752  x_digits += n;
1753  break;
1754 
1755  case 'X':
1756  if (s_char_seen || p_char_seen) {
1757  goto error;
1758  }
1759  category |= PIC_ALPHANUMERIC;
1760  x_digits += n;
1761  break;
1762 
1763  case '9':
1764  category |= PIC_NUMERIC;
1765  digits += n;
1766  real_digits += n;
1767  if (v_count) {
1768  scale += n;
1769  }
1770  break;
1771 
1772  case 'N':
1773  if (s_char_seen || p_char_seen) {
1774  goto error;
1775  }
1776  category |= PIC_NATIONAL;
1777  x_digits += n;
1778  break;
1779 
1780  case 'S':
1781  category |= PIC_NUMERIC;
1782  if (category & PIC_ALPHABETIC) {
1783  goto error;
1784  }
1785  s_count++;
1786  if (s_count > 1 || idx != 0) {
1787  goto error;
1788  }
1789  s_char_seen = 1;
1790  continue;
1791 
1792  case ',':
1793  case '.':
1794  category |= PIC_NUMERIC_EDITED;
1795  if (s_char_seen || p_char_seen) {
1796  goto error;
1797  }
1798  if (c != current_program->decimal_point) {
1799  break;
1800  }
1801  dp_char_seen = 1;
1802  /* fall through */
1803  case 'V':
1804  category |= PIC_NUMERIC;
1805  if (category & PIC_ALPHABETIC) {
1806  goto error;
1807  }
1808  v_count++;
1809  if (v_count > 1) {
1810  goto error;
1811  }
1812  break;
1813 
1814  case 'P':
1815  category |= PIC_NUMERIC;
1816  if (category & PIC_ALPHABETIC) {
1817  goto error;
1818  }
1819  if (p_char_seen || dp_char_seen) {
1820  goto error;
1821  }
1822  at_beginning = 0;
1823  at_end = 0;
1824  switch (buffcnt) {
1825  case 0:
1826  /* P..... */
1827  at_beginning = 1;
1828  break;
1829  case 1:
1830  /* VP.... */
1831  /* SP.... */
1832  if (lastonechar == 'V' || lastonechar == 'S') {
1833  at_beginning = 1;
1834  }
1835  break;
1836  case 2:
1837  /* SVP... */
1838  if (lasttwochar == 'S' && lastonechar == 'V') {
1839  at_beginning = 1;
1840  }
1841  break;
1842  default:
1843  break;
1844  }
1845  if (p[1] == 0 || (p[1] == 'V' && p[2] == 0)) {
1846  /* .....P */
1847  /* ....PV */
1848  at_end = 1;
1849  }
1850  if (!at_beginning && !at_end) {
1851  goto error;
1852  }
1853  p_char_seen = 1;
1854  if (at_beginning) {
1855  /* Implicit V */
1856  v_count++;
1857  }
1858  digits += n;
1859  if (v_count) {
1860  scale += n;
1861  } else {
1862  scale -= n;
1863  }
1864  break;
1865 
1866  case '0':
1867  case 'B':
1868  case '/':
1869  category |= PIC_EDITED;
1870  if (s_char_seen || p_char_seen) {
1871  goto error;
1872  }
1873  break;
1874 
1875  case '*':
1876  case 'Z':
1877  category |= PIC_NUMERIC_EDITED;
1878  if (category & PIC_ALPHABETIC) {
1879  goto error;
1880  }
1881  if (s_char_seen || p_char_seen) {
1882  goto error;
1883  }
1884  digits += n;
1885  if (v_count) {
1886  scale += n;
1887  }
1888  break;
1889 
1890  case '+':
1891  case '-':
1892  category |= PIC_NUMERIC_EDITED;
1893  if (category & PIC_ALPHABETIC) {
1894  goto error;
1895  }
1896  if (s_char_seen || p_char_seen) {
1897  goto error;
1898  }
1899  digits += n - 1;
1900  s_count++;
1901  /* FIXME: need more check */
1902  break;
1903 
1904  case 'C':
1905  category |= PIC_NUMERIC_EDITED;
1906  if (!(p[1] == 'R' && p[2] == 0)) {
1907  goto error;
1908  }
1909  if (s_char_seen || p_char_seen) {
1910  goto error;
1911  }
1912  p++;
1913  s_count++;
1914  break;
1915 
1916  case 'D':
1917  category |= PIC_NUMERIC_EDITED;
1918  if (!(p[1] == 'B' && p[2] == 0)) {
1919  goto error;
1920  }
1921  if (s_char_seen || p_char_seen) {
1922  goto error;
1923  }
1924  p++;
1925  s_count++;
1926  break;
1927 
1928  default:
1929  if (c == current_program->currency_symbol) {
1930  category |= PIC_NUMERIC_EDITED;
1931  digits += n - 1;
1932  /* FIXME: need more check */
1933  break;
1934  }
1935 
1936  goto error;
1937  }
1938 
1939  /* Calculate size */
1940  if (c != 'V' && c != 'P') {
1941  size += n;
1942  }
1943  if (c == 'C' || c == 'D') {
1944  size += n;
1945  }
1946  if (c == 'N') {
1947  size += n * (COB_NATIONAL_SIZE - 1);
1948  }
1949 
1950  /* Store in the buffer */
1951  pic_buff[idx++] = c;
1952  lasttwochar = lastonechar;
1953  lastonechar = c;
1954  memcpy (&pic_buff[idx], (void *)&n, sizeof(int));
1955  idx += sizeof(int);
1956  ++buffcnt;
1957  }
1958  pic_buff[idx] = 0;
1959 
1960  if (size == 0 && v_count) {
1961  goto error;
1962  }
1963  /* Set picture */
1964  pic->orig = cobc_check_string (str);
1965  pic->size = size;
1966  pic->digits = digits;
1967  pic->scale = scale;
1968  pic->have_sign = s_count;
1969  pic->real_digits = real_digits;
1970 
1971  /* Set picture category */
1972  switch (category) {
1973  case PIC_ALPHABETIC:
1975  break;
1976  case PIC_NUMERIC:
1978  if (digits > COB_MAX_DIGITS) {
1979  cb_error (_("Numeric field cannot be larger than %d digits"), COB_MAX_DIGITS);
1980  }
1981  break;
1982  case PIC_ALPHANUMERIC:
1983  case PIC_NATIONAL:
1985  break;
1986  case PIC_NUMERIC_EDITED:
1987  pic->str = cobc_parse_malloc (idx + 1);
1988  memcpy (pic->str, pic_buff, idx);
1990  pic->lenstr = idx;
1991  break;
1992  case PIC_EDITED:
1993  case PIC_ALPHABETIC_EDITED:
1995  case PIC_NATIONAL_EDITED:
1996  pic->str = cobc_parse_malloc (idx + 1);
1997  memcpy (pic->str, pic_buff, idx);
1999  pic->lenstr = idx;
2000  pic->digits = x_digits;
2001  break;
2002  default:
2003  goto error;
2004  }
2005  goto end;
2006 
2007 error:
2008  cb_error (_("Invalid picture string - '%s'"), str);
2009 
2010 end:
2011  return CB_TREE (pic);
2012 }
cb_tree cb_build_ppointer ( cb_tree  )
1764 {
1765  struct cb_field *f;
1766 
1767  if (x == cb_error_node ||
1768  (CB_REFERENCE_P (x) && cb_ref (x) == cb_error_node)) {
1769  return cb_error_node;
1770  }
1771 
1772  if (CB_REFERENCE_P (x)) {
1773  f = CB_FIELD_PTR (cb_ref(x));
1774  f->count++;
1775  }
1776  return CB_BUILD_CAST_PPOINTER (x);
1777 }
struct cb_program* cb_build_program ( struct cb_program ,
const int   
)
read
1247 {
1248  struct cb_program *p;
1249  struct cb_program *q;
1250 
1251  if (!last_program) {
1252  toplev_count = 0;
1253  }
1254  cb_reset_78 ();
1255  cobc_in_procedure = 0;
1256  cobc_in_repository = 0;
1257  cobc_cs_check = 0;
1259 
1260  p = cobc_parse_malloc (sizeof (struct cb_program));
1261  p->word_table = cobc_parse_malloc (CB_WORD_TABLE_SIZE);
1262 
1263  p->next_program = last_program;
1264  p->nested_level = nest_level;
1265  p->decimal_point = '.';
1266  p->currency_symbol = '$';
1267  p->numeric_separator = ',';
1268  /* Save current program as actual at it's level */
1269  container_progs[nest_level] = p;
1270  if (nest_level) {
1271  /* Contained program */
1272  /* Inherit from upper level */
1273  p->global_file_list = last_program->global_file_list;
1274  p->collating_sequence = last_program->collating_sequence;
1275  p->classification = last_program->classification;
1276  p->mnemonic_spec_list = last_program->mnemonic_spec_list;
1277  p->class_spec_list = last_program->class_spec_list;
1278  p->interface_spec_list = last_program->interface_spec_list;
1279  p->function_spec_list = last_program->function_spec_list;
1280  p->user_spec_list = last_program->user_spec_list;
1281  p->program_spec_list = last_program->program_spec_list;
1282  p->property_spec_list = last_program->property_spec_list;
1283  p->alphabet_name_list = last_program->alphabet_name_list;
1284  p->symbolic_char_list = last_program->symbolic_char_list;
1285  p->class_name_list = last_program->class_name_list;
1286  p->locale_list = last_program->locale_list;
1287  p->decimal_point = last_program->decimal_point;
1288  p->numeric_separator = last_program->numeric_separator;
1289  p->currency_symbol = last_program->currency_symbol;
1290  p->flag_trailing_separate = last_program->flag_trailing_separate;
1291  p->flag_console_is_crt = last_program->flag_console_is_crt;
1292  /* RETURN-CODE is global for contained programs */
1293  p->cb_return_code = last_program->cb_return_code;
1294  CB_FIELD_PTR (last_program->cb_return_code)->flag_is_global = 1;
1295  p->toplev_count = last_program->toplev_count;
1296  /* Add program to itself for possible recursion */
1298  /* Add contained program to it's parent */
1299  q = container_progs[nest_level - 1];
1301  } else {
1302  /* Top level program */
1303  p->toplev_count = toplev_count++;
1305  cb_reset_global_78 ();
1306  }
1307  return p;
1308 }
char* cb_build_program_id ( cb_tree  ,
cb_tree  ,
const cob_u32_t   
)
1170 {
1171  char *s;
1172  unsigned char *p;
1173 
1174  if (alt_name) {
1176  cobc_check_string ((char *)CB_LITERAL (alt_name)->data);
1177  s = cb_encode_program_id ((char *)CB_LITERAL (alt_name)->data);
1178  } else if (CB_LITERAL_P (name)) {
1180  cobc_check_string ((char *)CB_LITERAL (name)->data);
1181  s = cb_encode_program_id ((char *)CB_LITERAL (name)->data);
1182  } else {
1184  cobc_check_string (CB_NAME (name));
1185  s = cb_encode_program_id (CB_NAME (name));
1186  }
1188  if (is_func) {
1189  for (p = (unsigned char *)s; *p; ++p) {
1190  if (islower ((int)*p)) {
1191  *p = (cob_u8_t)toupper ((int)*p);
1192  }
1193  }
1194  }
1195  return s;
1196 }
cb_tree cb_build_reference ( const char *  )
2431 {
2432  struct cb_reference *p;
2433 
2435  sizeof (struct cb_reference));
2436  /* Look up / insert word into hash list */
2437  lookup_word (p, name);
2438  return CB_TREE (p);
2439 }
void cb_build_registers ( void  )
1045 {
1046 #if !defined(__linux__) && !defined(__CYGWIN__) && defined(HAVE_TIMEZONE)
1047  long contz;
1048 #endif
1049  cb_tree x;
1050  struct tm *tlt;
1051  time_t t;
1052  char buff[48];
1053 
1054  /* RETURN-CODE */
1055  if (!current_program->nested_level) {
1056  x = cb_build_index (cb_build_reference ("RETURN-CODE"),
1057  cb_zero, 0, NULL);
1058  CB_FIELD_PTR (x)->special_index = 1;
1060  }
1061 
1062  /* SORT-RETURN */
1063  x = cb_build_index (cb_build_reference ("SORT-RETURN"),
1064  cb_zero, 0, NULL);
1065  CB_FIELD_PTR (x)->flag_no_init = 1;
1067 
1068  /* NUMBER-OF-CALL-PARAMETERS */
1069  x = cb_build_index (cb_build_reference ("NUMBER-OF-CALL-PARAMETERS"),
1070  cb_zero, 0, NULL);
1071  CB_FIELD_PTR (x)->flag_no_init = 1;
1072  CB_FIELD_PTR (x)->flag_local = 1;
1073  CB_FIELD_PTR (x)->special_index = 2;
1075 
1076  t = time (NULL);
1077  tlt = localtime (&t);
1078  /* Leap seconds ? */
1079  if (tlt->tm_sec >= 60) {
1080  tlt->tm_sec = 59;
1081  }
1082 
1083  /* WHEN-COMPILED */
1084  memset (buff, 0, sizeof (buff));
1085  strftime (buff, (size_t)17, "%m/%d/%y%H.%M.%S", tlt);
1086  cb_build_constant (cb_build_reference ("WHEN-COMPILED"),
1087  cb_build_alphanumeric_literal (buff, (size_t)16));
1088 
1089  /* FUNCTION WHEN-COMPILED */
1090  memset (buff, 0, sizeof (buff));
1091 #if defined(__linux__) || defined(__CYGWIN__)
1092  strftime (buff, (size_t)22, "%Y%m%d%H%M%S00%z", tlt);
1093 #elif defined(HAVE_TIMEZONE)
1094  strftime (buff, (size_t)17, "%Y%m%d%H%M%S00", tlt);
1095  if (timezone <= 0) {
1096  contz = -timezone;
1097  buff[16] = '+';
1098  } else {
1099  contz = timezone;
1100  buff[16] = '-';
1101  }
1102  sprintf (&buff[17], "%2.2ld%2.2ld", contz / 3600, contz % 60);
1103 #else
1104  strftime (buff, (size_t)22, "%Y%m%d%H%M%S0000000", tlt);
1105 #endif
1106  cb_intr_whencomp = cb_build_alphanumeric_literal (buff, (size_t)21);
1107 
1108 }
cb_tree cb_build_replacing_all ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5716 {
5717  validate_inspect (x, y, 1);
5718  return cb_list_add (l, CB_BUILD_FUNCALL_2 ("cob_inspect_all", y, x));
5719 }
cb_tree cb_build_replacing_characters ( cb_tree  ,
cb_tree   
)
5706 {
5707  if (CB_LITERAL_P (x) && CB_LITERAL(x)->size != 1) {
5708  cb_error_x (CB_TREE (current_statement),
5709  _("Operand has wrong size"));
5710  }
5711  return cb_list_add (l, CB_BUILD_FUNCALL_1 ("cob_inspect_characters", x));
5712 }
cb_tree cb_build_replacing_first ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5730 {
5731  validate_inspect (x, y, 1);
5732  return cb_list_add (l, CB_BUILD_FUNCALL_2 ("cob_inspect_first", y, x));
5733 }
cb_tree cb_build_replacing_leading ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5723 {
5724  validate_inspect (x, y, 1);
5725  return cb_list_add (l, CB_BUILD_FUNCALL_2 ("cob_inspect_leading", y, x));
5726 }
cb_tree cb_build_replacing_trailing ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5737 {
5738  validate_inspect (x, y, 1);
5739  return cb_list_add (l, CB_BUILD_FUNCALL_2 ("cob_inspect_trailing", y, x));
5740 }
cb_tree cb_build_search ( const int  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree  ,
const cb_tree   
)
2901 {
2902  struct cb_search *p;
2903 
2905  sizeof (struct cb_search));
2906  p->flag_all = flag_all;
2907  p->table = table;
2908  p->var = var;
2909  p->end_stmt = end_stmt;
2910  p->whens = whens;
2911  return CB_TREE (p);
2912 }
cb_tree cb_build_section_name ( cb_tree  ,
const int   
)
1223 {
1224  cb_tree x;
1225 
1226  if (name == cb_error_node) {
1227  return cb_error_node;
1228  }
1229 
1230  if (CB_WORD_COUNT (name) > 0) {
1231  x = CB_VALUE (CB_WORD_ITEMS (name));
1232  /* Used as a non-label name or used as a section name.
1233  Duplicate paragraphs are allowed if not referenced;
1234  Checked in typeck.c */
1235  if (!CB_LABEL_P (x) || sect_or_para == 0 ||
1236  (sect_or_para && CB_LABEL_P (x) &&
1237  CB_LABEL (x)->flag_section)) {
1238  redefinition_error (name);
1239  return cb_error_node;
1240  }
1241  }
1242 
1243  return name;
1244 }
cb_tree cb_build_set_attribute ( const struct cb_field ,
const int  ,
const int   
)
3078 {
3079  struct cb_set_attr *p;
3080 
3082  sizeof (struct cb_set_attr));
3083  p->fld = (struct cb_field *)fld;
3084  p->val_on = val_on;
3085  p->val_off = val_off;
3086  return CB_TREE (p);
3087 }
struct cb_statement* cb_build_statement ( const char *  )
read
3052 {
3053  struct cb_statement *p;
3054 
3056  sizeof (struct cb_statement));
3057  p->name = name;
3058  return p;
3059 }
cb_tree cb_build_string ( const void *  ,
const size_t   
)
1369 {
1370  struct cb_string *p;
1371 
1373  sizeof (struct cb_string));
1374  p->size = size;
1375  p->data = data;
1376  return CB_TREE (p);
1377 }
cb_tree cb_build_sub ( cb_tree  ,
cb_tree  ,
cb_tree   
)
3983 {
3984  cb_tree opt;
3985  struct cb_field *f;
3986 
3987 #ifdef COB_NON_ALIGNED
3988  if (CB_INDEX_P (v)) {
3989  return cb_build_move (cb_build_binary_op (v, '-', n), v);
3990  }
3991  if (CB_TREE_CLASS (v) == CB_CLASS_POINTER) {
3992  optimize_defs[COB_POINTER_MANIP] = 1;
3993  return CB_BUILD_FUNCALL_3 ("cob_pointer_manip", v, n, cb_int1);
3994  }
3995 #else
3996  if (CB_INDEX_P (v) || CB_TREE_CLASS (v) == CB_CLASS_POINTER) {
3997  return cb_build_move (cb_build_binary_op (v, '-', n), v);
3998  }
3999 #endif
4000 
4001  if (CB_REF_OR_FIELD_P (v)) {
4002  f = CB_FIELD_PTR (v);
4003  f->count++;
4004  }
4005  if (CB_REF_OR_FIELD_P (n)) {
4006  f = CB_FIELD_PTR (n);
4007  f->count++;
4008  }
4009  opt = build_store_option (v, round_opt);
4010  if (opt == cb_int0 && cb_fits_int (n)) {
4011  return cb_build_optim_sub (v, n);
4012  }
4013  return CB_BUILD_FUNCALL_3 ("cob_sub", v, n, opt);
4014 }
void cb_build_symbolic_chars ( const cb_tree  ,
const cb_tree   
)
2148 {
2149  cb_tree l;
2150  cb_tree x;
2151  cb_tree x2;
2152  struct cb_alphabet_name *ap;
2153  int n;
2154  unsigned char buff[4];
2155 
2156  if (alphabet) {
2157  ap = CB_ALPHABET_NAME (alphabet);
2158  } else {
2159  ap = NULL;
2160  }
2161  for (l = sym_list; l; l = CB_CHAIN (l)) {
2162  n = cb_get_int (CB_PURPOSE (l)) - 1;
2163  if (ap) {
2164  buff[0] = (unsigned char)ap->alphachr[n];
2165  } else {
2166  buff[0] = (unsigned char)n;
2167  }
2168  buff[1] = 0;
2169  x2 = cb_build_alphanumeric_literal (buff, (size_t)1);
2170  CB_LITERAL (x2)->all = 1;
2171  x = cb_build_constant (CB_VALUE (l), x2);
2172  CB_FIELD (x)->flag_item_78 = 1;
2173  CB_FIELD (x)->flag_is_global = 1;
2174  CB_FIELD (x)->level = 1;
2175  (void)cb_validate_78_item (CB_FIELD (x), 0);
2176  }
2177 }
cb_tree cb_build_system_name ( const enum  cb_system_name_category,
const int   
)
1510 {
1511  struct cb_system_name *p;
1512 
1514  sizeof (struct cb_system_name));
1515  p->category = category;
1516  p->token = token;
1517  return CB_TREE (p);
1518 }
cb_tree cb_build_tallying_all ( void  )
5664 {
5665  if (inspect_data == NULL) {
5666  cb_error_x (CB_TREE (current_statement),
5667  _("Data name expected before ALL"));
5668  }
5669  inspect_func = "cob_inspect_all";
5670  return NULL;
5671 }
cb_tree cb_build_tallying_characters ( cb_tree  )
5653 {
5654  if (inspect_data == NULL) {
5655  cb_error_x (CB_TREE (current_statement),
5656  _("Data name expected before CHARACTERS"));
5657  }
5658  inspect_func = NULL;
5659  return cb_list_add (l, CB_BUILD_FUNCALL_1 ("cob_inspect_characters", inspect_data));
5660 }
cb_tree cb_build_tallying_data ( cb_tree  )
5646 {
5647  inspect_data = x;
5648  return NULL;
5649 }
cb_tree cb_build_tallying_leading ( void  )
5675 {
5676  if (inspect_data == NULL) {
5677  cb_error_x (CB_TREE (current_statement),
5678  _("Data name expected before LEADING"));
5679  }
5680  inspect_func = "cob_inspect_leading";
5681  return NULL;
5682 }
cb_tree cb_build_tallying_trailing ( void  )
5686 {
5687  if (inspect_data == NULL) {
5688  cb_error_x (CB_TREE (current_statement),
5689  _("Data name expected before TRAILING"));
5690  }
5691  inspect_func = "cob_inspect_trailing";
5692  return NULL;
5693 }
cb_tree cb_build_tallying_value ( cb_tree  ,
cb_tree   
)
5697 {
5698  if (inspect_func == NULL) {
5699  cb_error_x (x, _("ALL, LEADING or TRAILING expected before '%s'"), cb_name (x));
5700  }
5701  return cb_list_add (l, CB_BUILD_FUNCALL_2 (inspect_func, inspect_data, x));
5702 }
cb_tree cb_build_unstring_delimited ( cb_tree  ,
cb_tree   
)
8342 {
8343  if (cb_validate_one (value)) {
8344  return cb_error_node;
8345  }
8346  return CB_BUILD_FUNCALL_2 ("cob_unstring_delimited", value, all);
8347 }
cb_tree cb_build_unstring_into ( cb_tree  ,
cb_tree  ,
cb_tree   
)
8351 {
8352  if (cb_validate_one (name)) {
8353  return cb_error_node;
8354  }
8355  if (delimiter == NULL) {
8356  delimiter = cb_int0;
8357  }
8358  if (count == NULL) {
8359  count = cb_int0;
8360  }
8361  return CB_BUILD_FUNCALL_3 ("cob_unstring_into", name, delimiter, count);
8362 }
cb_tree cb_build_write_advancing_lines ( cb_tree  ,
cb_tree   
)
8449 {
8450  cb_tree e;
8451  int opt;
8452 
8453  opt = (pos == CB_BEFORE) ? COB_WRITE_BEFORE : COB_WRITE_AFTER;
8454  opt |= COB_WRITE_LINES;
8455  if (CB_LITERAL_P (lines)) {
8456  opt |= cb_get_int (lines);
8457  return cb_int_hex (opt);
8458  }
8459  e = cb_build_binary_op (cb_int (opt), '+', lines);
8460  return cb_build_cast_int (e);
8461 }
cb_tree cb_build_write_advancing_mnemonic ( cb_tree  ,
cb_tree   
)
8465 {
8466  int opt;
8467  int token;
8468 
8469  if (mnemonic == cb_error_node) {
8470  return cb_int0;
8471  }
8472  if (cb_ref (mnemonic) == cb_error_node) {
8473  return cb_int0;
8474  }
8475  token = CB_SYSTEM_NAME (cb_ref (mnemonic))->token;
8476  switch (token) {
8477  case CB_FEATURE_FORMFEED:
8478  opt = (pos == CB_BEFORE) ? COB_WRITE_BEFORE : COB_WRITE_AFTER;
8479  return cb_int_hex (opt | COB_WRITE_PAGE);
8480  case CB_FEATURE_C01:
8481  case CB_FEATURE_C02:
8482  case CB_FEATURE_C03:
8483  case CB_FEATURE_C04:
8484  case CB_FEATURE_C05:
8485  case CB_FEATURE_C06:
8486  case CB_FEATURE_C07:
8487  case CB_FEATURE_C08:
8488  case CB_FEATURE_C09:
8489  case CB_FEATURE_C10:
8490  case CB_FEATURE_C11:
8491  case CB_FEATURE_C12:
8492  opt = (pos == CB_BEFORE) ? COB_WRITE_BEFORE : COB_WRITE_AFTER;
8493  return cb_int_hex (opt | COB_WRITE_CHANNEL | COB_WRITE_PAGE | token);
8494  default:
8495  cb_error_x (mnemonic, _("Invalid mnemonic name"));
8496  return cb_int0;
8497  }
8498 }
cb_tree cb_build_write_advancing_page ( cb_tree  )
8502 {
8503  int opt = (pos == CB_BEFORE) ? COB_WRITE_BEFORE : COB_WRITE_AFTER;
8504 
8505  return cb_int_hex (opt | COB_WRITE_PAGE);
8506 }
int cb_category_is_alpha ( cb_tree  )
751 {
753 }
void cb_check_field_debug ( cb_tree  )
898 {
899  cb_tree l;
900  cb_tree x;
901  cb_tree z;
902  size_t size;
903  size_t found;
904  char buff[COB_MINI_BUFF];
905 
906  /* Basic reference check */
907  if (CB_WORD_COUNT (fld) > 0) {
908  if (!CB_WORD_ITEMS (fld)) {
909  return;
910  }
911  z = CB_VALUE(CB_WORD_ITEMS (fld));
912  if (!CB_FIELD_P (z)) {
913  return;
914  }
915  x = cb_ref (fld);
916  if (x == cb_error_node) {
917  return;
918  }
919  } else {
920  return;
921  }
922 
923  found = 0;
924  /* Check if reference is being debugged */
925  for (l = current_program->debug_list; l; l = CB_CHAIN (l)) {
926  if (!CB_PURPOSE (l)) {
927  continue;
928  }
929  if (x == CB_PURPOSE (l)) {
930  if (CB_REFERENCE (fld)->flag_target ||
931  CB_REFERENCE (CB_VALUE (l))->flag_all_debug) {
932  found = 1;
933  }
934  break;
935  }
936  }
937  if (!found) {
938  return;
939  }
940 
941  found = 0;
942  /* Found it - check if it is already in the statement list */
943  for (l = current_statement->debug_nodups; l; l = CB_CHAIN (l)) {
944  if (CB_VALUE (l) == x) {
945  found = 1;
946  break;
947  }
948  }
949  if (found) {
950  return;
951  }
952 
953  /* Set up debug info */
954  strcpy (buff, CB_FIELD(x)->name);
955  size = strlen (buff);
956  for (l = CB_REFERENCE (fld)->chain; l; l = CB_REFERENCE (l)->chain) {
957  z = cb_ref (l);
958  if (z != cb_error_node) {
959  size += strlen (CB_FIELD (z)->name);
960  size += 4;
961  if (size >= sizeof(buff)) {
962  break;
963  }
964  strcat (buff, " OF ");
965  strcat (buff, CB_FIELD (z)->name);
966  }
967  }
976  found = 0;
977  CB_REFERENCE (fld)->subs = cb_list_reverse (CB_REFERENCE (fld)->subs);
978  l = CB_REFERENCE (fld)->subs;
979  for (; l && found < 3; l = CB_CHAIN (l), ++found) {
980  switch (found) {
981  case 0:
984  cb_build_move (CB_VALUE (l),
985  cb_debug_sub_1));
986  break;
987  case 1:
990  cb_build_move (CB_VALUE (l),
991  cb_debug_sub_2));
992  break;
993  case 2:
996  cb_build_move (CB_VALUE (l),
997  cb_debug_sub_3));
998  break;
999  default:
1000  break;
1001  }
1002  }
1003  CB_REFERENCE (fld)->subs = cb_list_reverse (CB_REFERENCE (fld)->subs);
1004 
1005  for (; found < 3; ++found) {
1006  switch (found) {
1007  case 0:
1010  CB_BUILD_FUNCALL_3 ("memset",
1011  CB_BUILD_CAST_ADDRESS (cb_debug_sub_1),
1012  cb_int (' '),
1013  CB_BUILD_CAST_LENGTH (cb_debug_sub_1)));
1014  break;
1015  case 1:
1018  CB_BUILD_FUNCALL_3 ("memset",
1019  CB_BUILD_CAST_ADDRESS (cb_debug_sub_2),
1020  cb_int (' '),
1021  CB_BUILD_CAST_LENGTH (cb_debug_sub_2)));
1022  break;
1023  case 2:
1026  CB_BUILD_FUNCALL_3 ("memset",
1027  CB_BUILD_CAST_ADDRESS (cb_debug_sub_3),
1028  cb_int (' '),
1029  CB_BUILD_CAST_LENGTH (cb_debug_sub_3)));
1030  break;
1031  default:
1032  break;
1033  }
1034  }
1035 
1038  cb_build_debug_call (CB_FIELD(x)->debug_section));
1039 }
size_t cb_check_index_p ( cb_tree  x)
881 {
882  struct cb_field *f;
883 
884  if (!CB_REF_OR_FIELD_P (x)) {
885  return 0;
886  }
887  f = CB_FIELD_PTR (x);
888  if (f->usage == CB_USAGE_INDEX && !f->children) {
889  return 1;
890  }
891  return 0;
892 }
cb_tree cb_check_numeric_value ( cb_tree  )
645 {
646  if (x == cb_error_node) {
647  return cb_error_node;
648  }
649 
650  if (CB_TREE_CATEGORY (x) == CB_CATEGORY_NUMERIC) {
651  return x;
652  }
653 
654  cb_error_x (x, _("'%s' is not a numeric value"), cb_name (x));
655  return cb_error_node;
656 }
void cb_clear_real_field ( void  )
1437 {
1439 }
cb_tree cb_concat_literals ( const cb_tree  ,
const cb_tree   
)
1552 {
1553  unsigned char *data1;
1554  unsigned char *data2;
1555  struct cb_literal *p;
1556  size_t size1;
1557  size_t size2;
1558 
1559  if (x1 == cb_error_node || x2 == cb_error_node) {
1560  return cb_error_node;
1561  }
1562  if (CB_LITERAL_P (x1)) {
1563  data1 = CB_LITERAL (x1)->data;
1564  size1 = CB_LITERAL (x1)->size;
1565  } else if (CB_CONST_P (x1)) {
1566  size1 = 1;
1567  if (x1 == cb_space) {
1568  data1 = (unsigned char *)" ";
1569  } else if (x1 == cb_zero) {
1570  data1 = (unsigned char *)"0";
1571  } else if (x1 == cb_quote) {
1572  if (cb_flag_apostrophe) {
1573  data1 = (unsigned char *)"'";
1574  } else {
1575  data1 = (unsigned char *)"\"";
1576  }
1577  } else if (x1 == cb_norm_low) {
1578  data1 = (unsigned char *)"\0";
1579  } else if (x1 == cb_norm_high) {
1580  data1 = (unsigned char *)"\255";
1581  } else if (x1 == cb_null) {
1582  data1 = (unsigned char *)"\0";
1583  } else {
1584  return cb_error_node;
1585  }
1586  } else {
1587  return cb_error_node;
1588  }
1589  if (CB_LITERAL_P (x2)) {
1590  data2 = CB_LITERAL (x2)->data;
1591  size2 = CB_LITERAL (x2)->size;
1592  } else if (CB_CONST_P (x2)) {
1593  size2 = 1;
1594  if (x2 == cb_space) {
1595  data2 = (unsigned char *)" ";
1596  } else if (x2 == cb_zero) {
1597  data2 = (unsigned char *)"0";
1598  } else if (x2 == cb_quote) {
1599  if (cb_flag_apostrophe) {
1600  data2 = (unsigned char *)"'";
1601  } else {
1602  data2 = (unsigned char *)"\"";
1603  }
1604  } else if (x2 == cb_norm_low) {
1605  data2 = (unsigned char *)"\0";
1606  } else if (x2 == cb_norm_high) {
1607  data2 = (unsigned char *)"\255";
1608  } else if (x2 == cb_null) {
1609  data2 = (unsigned char *)"\0";
1610  } else {
1611  return cb_error_node;
1612  }
1613  } else {
1614  return cb_error_node;
1615  }
1617  sizeof (struct cb_literal));
1618  p->data = cobc_parse_malloc (size1 + size2 + 1U);
1619  p->size = size1 + size2;
1620  memcpy (p->data, data1, size1);
1621  memcpy (p->data + size1, data2, size2);
1622  return CB_TREE (p);
1623 }
int cb_config_entry ( char *  ,
const char *  ,
const int   
)

References _, CB_ANY, CB_ARCHAIC, CB_ASSIGN_IBM, CB_ASSIGN_MF, CB_BINARY_SIZE_1_2_4_8, CB_BINARY_SIZE_1__8, CB_BINARY_SIZE_2_4_8, CB_BOOLEAN, CB_BYTEORDER_BIG_ENDIAN, CB_BYTEORDER_NATIVE, CB_CONFIG_SIZE, CB_ERROR, CB_IGNORE, CB_INT, CB_OBSOLETE, CB_OK, CB_SKIP, CB_STRING, CB_SUPPORT, CB_UNCONFORMABLE, CB_WARNING, cobc_main_malloc(), cobc_nores_base, config_table, configuration_error(), invalid_value(), config_struct::name, noreserve::next, noreserve::noresword, NULL, read_string(), unsupported_value(), config_struct::val, and config_struct::var.

Referenced by cb_load_conf(), and process_command_line().

136 {
137  char *s;
138  const char *name;
139  char *e;
140  struct noreserve *noresptr;
141  size_t size;
142  const char *val;
143  void *var;
144  size_t i;
145  size_t j;
146 
147  /* Get tag */
148  s = strpbrk (buff, " \t:=");
149  if (!s) {
150  configuration_error (fname, line,
151  _("Invalid configuration '%s'"), buff);
152  return -1;
153  }
154  *s = 0;
155 
156  /* Find entry */
157  for (i = 0; i < CB_CONFIG_SIZE; i++) {
158  if (strcmp (buff, config_table[i].name) == 0) {
159  break;
160  }
161  }
162  if (i == CB_CONFIG_SIZE) {
163  configuration_error (fname, line, _("Unknown configuration tag '%s'"), buff);
164  return -1;
165  }
166 
167  /* Get value */
168  /* Move pointer to beginning of value */
169  for (s++; *s && strchr (" \t:=", *s); s++) {
170  ;
171  }
172  /* Set end pointer to first # (comment) or end of value */
173  for (e = s + 1; *e && !strchr ("#", *e); e++) {
174  ;
175  }
176  /* Remove trailing white-spaces */
177  for (--e; e >= s && strchr (" \t\r\n", *e); e--) {
178  ;
179  }
180  e[1] = 0;
181  config_table[i].val = s;
182 
183  /* Set value */
184  name = config_table[i].name;
185  var = config_table[i].var;
186  val = config_table[i].val;
187  switch (config_table[i].type) {
188  case CB_ANY:
189  if (strcmp (name, "assign-clause") == 0) {
190  if (strcmp (val, "cobol2002") == 0) {
191  unsupported_value (fname, line, name, val);
192  return -1;
193  } else if (strcmp (val, "mf") == 0) {
194  cb_assign_clause = CB_ASSIGN_MF;
195  } else if (strcmp (val, "ibm") == 0) {
196  cb_assign_clause = CB_ASSIGN_IBM;
197  } else {
198  invalid_value (fname, line, name, val);
199  return -1;
200  }
201  } else if (strcmp (name, "binary-size") == 0) {
202  if (strcmp (val, "2-4-8") == 0) {
203  cb_binary_size = CB_BINARY_SIZE_2_4_8;
204  } else if (strcmp (val, "1-2-4-8") == 0) {
205  cb_binary_size = CB_BINARY_SIZE_1_2_4_8;
206  } else if (strcmp (val, "1--8") == 0) {
207  cb_binary_size = CB_BINARY_SIZE_1__8;
208  } else {
209  invalid_value (fname, line, name, val);
210  return -1;
211  }
212  } else if (strcmp (name, "binary-byteorder") == 0) {
213  if (strcmp (val, "native") == 0) {
214  cb_binary_byteorder = CB_BYTEORDER_NATIVE;
215  } else if (strcmp (val, "big-endian") == 0) {
216  cb_binary_byteorder = CB_BYTEORDER_BIG_ENDIAN;
217  } else {
218  invalid_value (fname, line, name, val);
219  return -1;
220  }
221  }
222  break;
223  case CB_INT:
224  for (j = 0; val[j]; j++) {
225  if (val[j] < '0' || val[j] > '9') {
226  invalid_value (fname, line, name, val);
227  return -1;
228  break;
229  }
230  }
231  *((int *)var) = atoi (val);
232  break;
233  case CB_STRING:
234  val = read_string (val);
235 
236  if (strcmp (name, "include") == 0) {
237  if (fname) {
238  /* Include another conf file */
239  return 1;
240  } else {
242  _("'%s' not supported with -cb_conf"), name);
243  return -1;
244  }
245  } else if (strcmp (name, "not-reserved") == 0) {
246  size = strlen (val);
247  noresptr = cobc_main_malloc (sizeof (struct noreserve)
248  + size + 1U);
249  noresptr->noresword = (char *)noresptr
250  + sizeof (struct noreserve);
251  memcpy (noresptr->noresword, val, size);
252  noresptr->next = cobc_nores_base;
253  cobc_nores_base = noresptr;
254  } else {
255  *((const char **)var) = val;
256  }
257  break;
258  case CB_BOOLEAN:
259  if (strcmp (val, "yes") == 0) {
260  *((int *)var) = 1;
261  } else if (strcmp (val, "no") == 0) {
262  *((int *)var) = 0;
263  } else {
264  invalid_value (fname, line, name, val);
265  return -1;
266  }
267  break;
268  case CB_SUPPORT:
269  if (strcmp (val, "ok") == 0) {
270  *((enum cb_support *)var) = CB_OK;
271  } else if (strcmp (val, "warning") == 0) {
272  *((enum cb_support *)var) = CB_WARNING;
273  } else if (strcmp (val, "archaic") == 0) {
274  *((enum cb_support *)var) = CB_ARCHAIC;
275  } else if (strcmp (val, "obsolete") == 0) {
276  *((enum cb_support *)var) = CB_OBSOLETE;
277  } else if (strcmp (val, "skip") == 0) {
278  *((enum cb_support *)var) = CB_SKIP;
279  } else if (strcmp (val, "ignore") == 0) {
280  *((enum cb_support *)var) = CB_IGNORE;
281  } else if (strcmp (val, "error") == 0) {
282  *((enum cb_support *)var) = CB_ERROR;
283  } else if (strcmp (val, "unconformable") == 0) {
284  *((enum cb_support *)var) = CB_UNCONFORMABLE;
285  } else {
286  invalid_value (fname, line, name, val);
287  return -1;
288  }
289  break;
290  default:
291  configuration_error (fname, line, _("Invalid type for '%s'"), name);
292  return -1;
293  }
294  return 0;
295 }
const char* cb_define ( cb_tree  ,
cb_tree   
)
1214 {
1215  struct cb_word *w;
1216 
1217  w = CB_REFERENCE (name)->word;
1218  w->items = cb_list_add (w->items, val);
1219  w->count++;
1220  val->source_file = name->source_file;
1221  val->source_line = name->source_line;
1222  CB_REFERENCE (name)->value = val;
1223  return w->name;
1224 }
cb_tree cb_define_switch_name ( cb_tree  ,
cb_tree  ,
const int   
)
1200 {
1201  cb_tree switch_id;
1202  cb_tree value;
1203 
1204  if (!name || name == cb_error_node) {
1205  return NULL;
1206  }
1207  if (!sname || sname == cb_error_node ||
1208  CB_SYSTEM_NAME (sname)->category != CB_SWITCH_NAME) {
1209  cb_error_x (name, _("ON/OFF usage requires a SWITCH name"));
1210  return NULL;
1211  }
1212  switch_id = cb_int (CB_SYSTEM_NAME (sname)->token);
1213  value = CB_BUILD_FUNCALL_1 ("cob_get_switch", switch_id);
1214  if (flag == 0) {
1215  value = CB_BUILD_NEGATION (value);
1216  }
1217  cb_build_constant (name, value);
1218  return value;
1219 }
void cb_emit_accept ( cb_tree  ,
cb_tree  ,
struct cb_attr_struct  
)
4196 {
4197  cb_tree line;
4198  cb_tree column;
4199  cb_tree fgc;
4200  cb_tree bgc;
4201  cb_tree scroll;
4202  cb_tree timeout;
4203  cb_tree prompt;
4204  int dispattrs;
4205 
4206  if (attr_ptr) {
4207  fgc = attr_ptr->fgc;
4208  bgc = attr_ptr->bgc;
4209  scroll = attr_ptr->scroll;
4210  timeout = attr_ptr->timeout;
4211  prompt = attr_ptr->prompt;
4212  dispattrs = attr_ptr->dispattrs;
4213  } else {
4214  fgc = NULL;
4215  bgc = NULL;
4216  scroll = NULL;
4217  timeout = NULL;
4218  prompt = NULL;
4219  dispattrs = 0;
4220  }
4221 
4222  if (cb_validate_one (var)) {
4223  return;
4224  }
4225  if (cb_validate_one (pos)) {
4226  return;
4227  }
4228  if (cb_validate_one (fgc)) {
4229  return;
4230  }
4231  if (cb_validate_one (bgc)) {
4232  return;
4233  }
4234  if (cb_validate_one (scroll)) {
4235  return;
4236  }
4237  if (cb_validate_one (timeout)) {
4238  return;
4239  }
4240  if (cb_validate_one (prompt)) {
4241  return;
4242  }
4243 
4244  if (prompt) {
4245  /* PROMPT character - 1 character identifier or literal */
4246  if (CB_LITERAL_P (prompt)) {
4247  if (CB_LITERAL (prompt)->size != 1) {
4248  cb_error_x (prompt, _("Invalid PROMPT literal"));
4249  return;
4250  }
4251  } else {
4252  if (CB_FIELD_PTR (prompt)->size != 1) {
4253  cb_error_x (prompt, _("Invalid PROMPT identifier"));
4254  return;
4255  }
4256  }
4257  }
4258 
4259 #if 0 /* RXWRXW - Screen */
4260  if ((CB_REF_OR_FIELD_P (var)) &&
4261  CB_FIELD (cb_ref (var))->storage == CB_STORAGE_SCREEN) {
4263  }
4264 #endif
4265 
4267  /* Bump ref count to force CRT STATUS field generation */
4268  if (current_program->crt_status) {
4270  }
4271  if ((CB_REF_OR_FIELD_P (var)) &&
4272  CB_FIELD (cb_ref (var))->storage == CB_STORAGE_SCREEN) {
4273  output_screen_from (CB_FIELD (cb_ref (var)), 0);
4274  gen_screen_ptr = 1;
4275  if (pos) {
4276  if (CB_LIST_P (pos)) {
4277  line = CB_PAIR_X (pos);
4278  column = CB_PAIR_Y (pos);
4279  cb_emit (CB_BUILD_FUNCALL_4 ("cob_screen_accept",
4280  var, line, column, timeout));
4281  } else {
4282  cb_emit (CB_BUILD_FUNCALL_4 ("cob_screen_accept",
4283  var, pos, NULL, timeout));
4284  }
4285  } else {
4286  cb_emit (CB_BUILD_FUNCALL_4 ("cob_screen_accept",
4287  var, NULL, NULL, timeout));
4288  }
4289  gen_screen_ptr = 0;
4290  output_screen_to (CB_FIELD (cb_ref (var)), 0);
4291  } else {
4292  if (var == cb_null) {
4293  var = NULL;
4294  }
4295  if (pos || fgc || bgc || scroll || dispattrs) {
4296  cb_gen_field_accept (var, pos, fgc, bgc, scroll,
4297  timeout, prompt, dispattrs);
4298  } else {
4299  cb_emit (CB_BUILD_FUNCALL_9 ("cob_field_accept",
4300  var, NULL, NULL, fgc, bgc,
4301  scroll, timeout, prompt,
4302  cb_int (dispattrs)));
4303  }
4304  }
4305  } else if (pos || fgc || bgc || scroll || dispattrs) {
4306  /* Bump ref count to force CRT STATUS field generation */
4307  if (current_program->crt_status) {
4309  }
4310  if (var == cb_null) {
4311  var = NULL;
4312  }
4313  cb_gen_field_accept (var, pos, fgc, bgc, scroll,
4314  timeout, prompt, dispattrs);
4315  } else {
4316  if (var == cb_null) {
4317  var = NULL;
4318  }
4319  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept", var));
4320  }
4321 }
void cb_emit_accept_arg_number ( cb_tree  )
4445 {
4446  if (cb_validate_one (var)) {
4447  return;
4448  }
4449  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_arg_number", var));
4450 }
void cb_emit_accept_arg_value ( cb_tree  )
4454 {
4455  if (cb_validate_one (var)) {
4456  return;
4457  }
4458  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_arg_value", var));
4459 }
void cb_emit_accept_command_line ( cb_tree  )
4415 {
4416  if (cb_validate_one (var)) {
4417  return;
4418  }
4419  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_command_line", var));
4420 }
void cb_emit_accept_date ( cb_tree  )
4361 {
4362  if (cb_validate_one (var)) {
4363  return;
4364  }
4365  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_date", var));
4366 }
void cb_emit_accept_date_yyyymmdd ( cb_tree  )
4370 {
4371  if (cb_validate_one (var)) {
4372  return;
4373  }
4374  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_date_yyyymmdd", var));
4375 }
void cb_emit_accept_day ( cb_tree  )
4379 {
4380  if (cb_validate_one (var)) {
4381  return;
4382  }
4383  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_day", var));
4384 }
void cb_emit_accept_day_of_week ( cb_tree  )
4397 {
4398  if (cb_validate_one (var)) {
4399  return;
4400  }
4401  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_day_of_week", var));
4402 }
void cb_emit_accept_day_yyyyddd ( cb_tree  )
4388 {
4389  if (cb_validate_one (var)) {
4390  return;
4391  }
4392  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_day_yyyyddd", var));
4393 }
void cb_emit_accept_environment ( cb_tree  )
4436 {
4437  if (cb_validate_one (var)) {
4438  return;
4439  }
4440  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_environment", var));
4441 }
void cb_emit_accept_escape_key ( cb_tree  )
4334 {
4335  if (cb_validate_one (var)) {
4336  return;
4337  }
4338  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_escape_key", var));
4339 }
void cb_emit_accept_exception_status ( cb_tree  )
4343 {
4344  if (cb_validate_one (var)) {
4345  return;
4346  }
4347  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_exception_status", var));
4348 }
void cb_emit_accept_line_or_col ( cb_tree  ,
const int   
)
4325 {
4326  if (cb_validate_one (var)) {
4327  return;
4328  }
4329  cb_emit (CB_BUILD_FUNCALL_2 ("cob_screen_line_col", var, cb_int (l_or_c)));
4330 }
void cb_emit_accept_mnemonic ( cb_tree  ,
cb_tree   
)
4463 {
4464  if (cb_validate_one (var)) {
4465  return;
4466  }
4467  if (cb_ref (mnemonic) == cb_error_node) {
4468  return;
4469  }
4470  switch (CB_SYSTEM_NAME (cb_ref (mnemonic))->token) {
4471  case CB_DEVICE_CONSOLE:
4472  case CB_DEVICE_SYSIN:
4473  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept", var));
4474  break;
4475  default:
4476  cb_error_x (mnemonic, _("Invalid input device '%s'"),
4477  cb_name (mnemonic));
4478  break;
4479  }
4480 }
void cb_emit_accept_name ( cb_tree  ,
cb_tree   
)
4484 {
4485  cb_tree sys;
4486 
4487  if (cb_validate_one (var)) {
4488  return;
4489  }
4490 
4491  /* Allow direct reference to a device name */
4492  sys = lookup_system_name (CB_NAME (name));
4493  if (sys) {
4494  switch (CB_SYSTEM_NAME (sys)->token) {
4495  case CB_DEVICE_CONSOLE:
4496  case CB_DEVICE_SYSIN:
4497  if (!cb_relaxed_syntax_check) {
4498  cb_warning_x (name, _("'%s' is not defined in SPECIAL-NAMES"), CB_NAME (name));
4499  }
4500  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept", var));
4501  return;
4502  default:
4503  cb_error_x (name, _("Invalid input device '%s'"),
4504  cb_name (name));
4505  return;
4506  }
4507  }
4508 
4509  cb_error_x (name, _("'%s' is not defined in SPECIAL-NAMES"),
4510  CB_NAME (name));
4511 }
void cb_emit_accept_time ( cb_tree  )
4406 {
4407  if (cb_validate_one (var)) {
4408  return;
4409  }
4410  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_time", var));
4411 }
void cb_emit_accept_user_name ( cb_tree  )
4352 {
4353  if (cb_validate_one (var)) {
4354  return;
4355  }
4356  cb_emit (CB_BUILD_FUNCALL_1 ("cob_accept_user_name", var));
4357 }
void cb_emit_allocate ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
4518 {
4519  cb_tree x;
4520  char buff[32];
4521 
4522  if (cb_validate_one (target1)) {
4523  return;
4524  }
4525  if (cb_validate_one (target2)) {
4526  return;
4527  }
4528  if (cb_validate_one (size)) {
4529  return;
4530  }
4531  if (cb_validate_one (initialize)) {
4532  return;
4533  }
4534  if (target1) {
4535  if (!(CB_REFERENCE_P(target1) &&
4536  CB_FIELD_PTR (target1)->flag_item_based)) {
4538  _("Target of ALLOCATE is not a BASED item"));
4539  return;
4540  }
4541  }
4542  if (target2) {
4543  if (!(CB_REFERENCE_P(target2) &&
4544  CB_TREE_CLASS (target2) == CB_CLASS_POINTER)) {
4546  _("Target of RETURNING is not a data pointer"));
4547  return;
4548  }
4549  }
4550  if (size) {
4551  if (CB_TREE_CLASS (size) != CB_CLASS_NUMERIC) {
4553  _("The CHARACTERS field of ALLOCATE must be numeric"));
4554  return;
4555  }
4556  }
4557  if (target1) {
4558  sprintf (buff, "%d", CB_FIELD_PTR (target1)->memory_size);
4559  x = cb_build_numeric_literal (0, buff, 0);
4560  cb_emit (CB_BUILD_FUNCALL_4 ("cob_allocate",
4561  CB_BUILD_CAST_ADDR_OF_ADDR (target1),
4562  target2, x, NULL));
4563  } else {
4564  if (initialize && !cb_category_is_alpha (initialize)) {
4566  _("INITIALIZED TO item is not alphanumeric"));
4567  }
4568  cb_emit (CB_BUILD_FUNCALL_4 ("cob_allocate",
4569  NULL, target2, size, initialize));
4570  }
4571  if (initialize && target1) {
4573  cb_build_initialize (target1, cb_true, NULL, 1, 0, 0);
4574  }
4575 }
void cb_emit_alter ( cb_tree  ,
cb_tree   
)
4582 {
4583  if (source == cb_error_node) {
4584  return;
4585  }
4586  if (target == cb_error_node) {
4587  return;
4588  }
4589  CB_REFERENCE(source)->flag_alter_code = 1;
4590  cb_emit (cb_build_alter (source, target));
4591 }
void cb_emit_arg_number ( cb_tree  )
4973 {
4974  if (cb_validate_one (value)) {
4975  return;
4976  }
4977  cb_emit (CB_BUILD_FUNCALL_1 ("cob_display_arg_number", value));
4978 }
void cb_emit_arithmetic ( cb_tree  ,
const int  ,
cb_tree   
)
3389 {
3390  cb_tree l;
3391  cb_tree x;
3392 
3393  x = cb_check_numeric_value (val);
3394 
3395  if (op) {
3397  } else {
3399  }
3400 
3401  if (cb_validate_one (x)) {
3402  return;
3403  }
3404  if (cb_validate_list (vars)) {
3405  return;
3406  }
3407 
3408  if (!CB_BINARY_OP_P (x)) {
3409  if (op == '+' || op == '-' || op == '*' || op == '/') {
3411  for (l = vars; l; l = CB_CHAIN (l)) {
3412  cb_check_data_incompat (CB_VALUE (l));
3413  switch (op) {
3414  case '+':
3415  CB_VALUE (l) = cb_build_add (CB_VALUE (l), x, CB_PURPOSE (l));
3416  break;
3417  case '-':
3418  CB_VALUE (l) = cb_build_sub (CB_VALUE (l), x, CB_PURPOSE (l));
3419  break;
3420  case '*':
3421  CB_VALUE (l) = cb_build_mul (CB_VALUE (l), x, CB_PURPOSE (l));
3422  break;
3423  case '/':
3424  CB_VALUE (l) = cb_build_div (CB_VALUE (l), x, CB_PURPOSE (l));
3425  break;
3426  }
3427  }
3428  cb_emit_list (vars);
3429  return;
3430  }
3431  }
3432  if (x == cb_error_node) {
3433  return;
3434  }
3435 
3436  cb_emit_list (build_decimal_assign (vars, op, x));
3437 }
void cb_emit_call ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
4599 {
4600  cb_tree l;
4601  cb_tree x;
4602  struct cb_field *f;
4603  const struct system_table *psyst;
4604  const char *p;
4605  const char *entry;
4606  cob_s64_t val;
4607  cob_s64_t valmin;
4608  cob_s64_t valmax;
4609  cob_u32_t is_sys_call;
4610  cob_u32_t is_sys_idx;
4611  int error_ind;
4612  int call_conv;
4613  int numargs;
4614 
4615  if (CB_INTRINSIC_P (prog)) {
4616  if (CB_INTRINSIC(prog)->intr_tab->category != CB_CATEGORY_ALPHANUMERIC) {
4617  cb_error_x (CB_TREE (current_statement),
4618  _("Only alphanumeric FUNCTION types are allowed here"));
4619  return;
4620  }
4621  }
4622  if (returning && returning != cb_null) {
4623  if (CB_TREE_CLASS(returning) != CB_CLASS_NUMERIC &&
4624  CB_TREE_CLASS(returning) != CB_CLASS_POINTER) {
4625  cb_error_x (CB_TREE (current_statement),
4626  _("Invalid RETURNING field"));
4627  return;
4628  }
4629  }
4630 
4631  error_ind = 0;
4632  numargs = 0;
4633 
4634  if (convention) {
4635  if (CB_INTEGER_P (convention)) {
4636  call_conv = CB_INTEGER (convention)->val;
4637  } else {
4638  call_conv = cb_get_int (convention);
4639  }
4640  } else {
4641  call_conv = 0;
4642  }
4643 #ifndef _WIN32
4644  if (call_conv & CB_CONV_STDCALL) {
4645  call_conv &= ~CB_CONV_STDCALL;
4646  if (warningopt) {
4647  cb_warning (_("STDCALL not available on this platform"));
4648  }
4649  }
4650 #elif defined(_WIN64)
4651  if (call_conv & CB_CONV_STDCALL) {
4652  if (warningopt) {
4653  cb_warning (_("STDCALL used on 64-bit Windows platform"));
4654  }
4655  }
4656 #endif
4657  if ((call_conv & CB_CONV_STATIC_LINK) && !CB_LITERAL_P (prog)) {
4658  cb_error_x (CB_TREE (current_statement),
4659  _("STATIC CALL convention requires a literal program name"));
4660  error_ind = 1;
4661  }
4662 
4663  for (l = par_using; l; l = CB_CHAIN (l), numargs++) {
4664  x = CB_VALUE (l);
4665  if (x == cb_error_node) {
4666  error_ind = 1;
4667  continue;
4668  }
4669  if (CB_NUMERIC_LITERAL_P (x)) {
4670  if (CB_PURPOSE_INT (l) != CB_CALL_BY_VALUE) {
4671  continue;
4672  }
4673  if (CB_SIZES_INT_UNSIGNED(l) &&
4674  CB_LITERAL (x)->sign < 0) {
4675  cb_error_x (x, _("Numeric literal is negative"));
4676  error_ind = 1;
4677  continue;
4678  }
4679  val = 0;
4680  valmin = 0;
4681  valmax = 0;
4682  switch (CB_SIZES_INT (l)) {
4683  case CB_SIZE_1:
4684  val = cb_get_long_long (x);
4685  if (CB_SIZES_INT_UNSIGNED(l)) {
4686  valmin = 0;
4687  valmax = UCHAR_MAX;
4688  } else {
4689  valmin = CHAR_MIN;
4690  valmax = CHAR_MAX;
4691  }
4692  break;
4693  case CB_SIZE_2:
4694  val = cb_get_long_long (x);
4695  if (CB_SIZES_INT_UNSIGNED(l)) {
4696  valmin = 0;
4697  valmax = USHRT_MAX;
4698  } else {
4699  valmin = SHRT_MIN;
4700  valmax = SHRT_MAX;
4701  }
4702  break;
4703  case CB_SIZE_4:
4704  val = cb_get_long_long (x);
4705  if (CB_SIZES_INT_UNSIGNED(l)) {
4706  valmin = 0;
4707  valmax = UINT_MAX;
4708  } else {
4709  valmin = INT_MIN;
4710  valmax = INT_MAX;
4711  }
4712  break;
4713  case CB_SIZE_8:
4714  case CB_SIZE_AUTO:
4715  if (CB_SIZES_INT_UNSIGNED(l)) {
4716  if (CB_LITERAL (x)->size < 20) {
4717  break;
4718  }
4719  if (CB_LITERAL (x)->size > 20) {
4720  valmin = 1;
4721  break;
4722  }
4723  if (memcmp (CB_LITERAL (x)->data,
4724  "18446744073709551615",
4725  (size_t)20) > 0) {
4726  valmin = 1;
4727  break;
4728  }
4729  } else {
4730  if (CB_LITERAL (x)->size < 19) {
4731  break;
4732  }
4733  if (CB_LITERAL (x)->size > 19) {
4734  valmin = 1;
4735  break;
4736  }
4737  if (memcmp (CB_LITERAL (x)->data,
4738  "9223372036854775807",
4739  (size_t)19) > 0) {
4740  valmin = 1;
4741  break;
4742  }
4743  }
4744  break;
4745  default:
4746  break;
4747  }
4748  if (!valmin && !valmax) {
4749  continue;
4750  }
4751  if (val < valmin || val > valmax) {
4752  cb_error_x (x, _("Numeric literal exceeds size limits"));
4753  error_ind = 1;
4754  }
4755  continue;
4756  }
4757  if (CB_CONST_P (x) && x != cb_null) {
4758  cb_error_x (x, _("Figurative constant invalid here"));
4759  error_ind = 1;
4760  continue;
4761  }
4762  if ((CB_REFERENCE_P (x) && CB_FIELD_P(CB_REFERENCE(x)->value)) ||
4763  CB_FIELD_P (x)) {
4764  f = CB_FIELD_PTR (x);
4765  if (f->level == 88) {
4766  cb_error_x (x, _("'%s' is not a valid data name"), CB_NAME (x));
4767  error_ind = 1;
4768  continue;
4769  }
4770  if (f->flag_any_length &&
4771  CB_PURPOSE_INT (l) != CB_CALL_BY_REFERENCE) {
4772  cb_error_x (x, _("'%s' ANY LENGTH item not passed BY REFERENCE"), CB_NAME (x));
4773  error_ind = 1;
4774  continue;
4775  }
4776  if (cb_warn_call_params &&
4777  CB_PURPOSE_INT (l) == CB_CALL_BY_REFERENCE) {
4778  if (f->level != 01 && f->level != 77) {
4779  cb_warning_x (x, _("'%s' is not a 01 or 77 level item"), CB_NAME (x));
4780  }
4781  }
4782  }
4783  }
4784 
4785  is_sys_call = 0;
4786  if (CB_LITERAL_P(prog)) {
4787  entry = NULL;
4788  p = (const char *)CB_LITERAL(prog)->data;
4789  for (; *p; ++p) {
4790  if (*p == '/' || *p == '\\') {
4791  entry = p + 1;
4792  }
4793  }
4794  if (!entry) {
4795  entry = (const char *)CB_LITERAL(prog)->data;
4796  }
4797  is_sys_idx = 1;
4798  for (psyst = system_tab; psyst->syst_name; psyst++, is_sys_idx++) {
4799  if (!strcmp(entry, (const char *)psyst->syst_name)) {
4800  if (psyst->syst_params > cb_list_length (par_using)) {
4801  cb_error_x (CB_TREE (current_statement),
4802  _("Wrong number of CALL parameters for '%s'"),
4803  (char *)psyst->syst_name);
4804  return;
4805  }
4806  is_sys_call = is_sys_idx;
4807  break;
4808  }
4809  }
4810  }
4811 
4812  if (error_ind) {
4813  return;
4814  }
4815  if (numargs > current_program->max_call_param) {
4816  current_program->max_call_param = numargs;
4817  }
4818  cb_emit (cb_build_call (prog, par_using, on_exception, not_on_exception,
4819  returning, is_sys_call, call_conv));
4820 }
void cb_emit_cancel ( cb_tree  )
4826 {
4827  if (cb_validate_one (prog)) {
4828  return;
4829  }
4830  cb_emit (cb_build_cancel (prog));
4831 }
void cb_emit_close ( cb_tree  ,
cb_tree   
)
4837 {
4838  struct cb_file *f;
4839 
4840  if (file == cb_error_node) {
4841  return;
4842  }
4843  file = cb_ref (file);
4844  if (file == cb_error_node) {
4845  return;
4846  }
4848  f = CB_FILE (file);
4849 
4850  if (f->organization == COB_ORG_SORT) {
4851  cb_error_x (CB_TREE (current_statement),
4852  _("Operation not allowed on SORT files"));
4853  }
4854 
4855  cb_emit (CB_BUILD_FUNCALL_4 ("cob_close", file,
4856  f->file_status, opt, cb_int0));
4857 
4858  /* Check for file debugging */
4865  }
4866 }
void cb_emit_command_line ( cb_tree  )
4982 {
4983  if (cb_validate_one (value)) {
4984  return;
4985  }
4986  cb_emit (CB_BUILD_FUNCALL_1 ("cob_display_command_line", value));
4987 }
void cb_emit_commit ( void  )
4872 {
4873  cb_emit (CB_BUILD_FUNCALL_0 ("cob_commit"));
4874 }
void cb_emit_continue ( void  )
4880 {
4882 }
void cb_emit_corresponding ( cb_tree(*)(cb_tree, cb_tree, cb_tree ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
void cb_emit_delete ( cb_tree  )
4888 {
4889  struct cb_file *f;
4890 
4891  if (file == cb_error_node) {
4892  return;
4893  }
4894  file = cb_ref (file);
4895  if (file == cb_error_node) {
4896  return;
4897  }
4899  f = CB_FILE (file);
4900 
4901  if (f->organization == COB_ORG_SORT) {
4902  cb_error_x (CB_TREE (current_statement),
4903  _("Operation not allowed on SORT files"));
4904  return;
4905  } else if (f->organization == COB_ORG_LINE_SEQUENTIAL) {
4906  cb_error_x (CB_TREE (current_statement),
4907  _("Operation not allowed on LINE SEQUENTIAL files"));
4908  return;
4909  }
4910 
4911  /* Check for file debugging */
4914  f->flag_fl_debug) {
4915  /* Gen callback after delete but before exception test */
4917  }
4918 
4919  cb_emit (CB_BUILD_FUNCALL_2 ("cob_delete", file,
4920  f->file_status));
4921 }
void cb_emit_delete_file ( cb_tree  )
4925 {
4926  if (file == cb_error_node) {
4927  return;
4928  }
4929  file = cb_ref (file);
4930  if (file == cb_error_node) {
4931  return;
4932  }
4933  if (CB_FILE (file)->organization == COB_ORG_SORT) {
4934  cb_error_x (CB_TREE (current_statement),
4935  _("Operation not allowed on SORT files"));
4936  return;
4937  }
4938 
4939  /* Check for file debugging */
4943  /* Gen callback after delete but before exception test */
4945  }
4946 
4947  cb_emit (CB_BUILD_FUNCALL_2 ("cob_delete_file", file,
4948  CB_FILE(file)->file_status));
4949 }
void cb_emit_display ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
struct cb_attr_struct  
)
4992 {
4993  cb_tree l;
4994  cb_tree x;
4995  cb_tree line;
4996  cb_tree column;
4997  cb_tree p;
4998  cb_tree fgc;
4999  cb_tree bgc;
5000  cb_tree scroll;
5001  int dispattrs;
5002 
5003  if (attr_ptr) {
5004  fgc = attr_ptr->fgc;
5005  bgc = attr_ptr->bgc;
5006  scroll = attr_ptr->scroll;
5007  dispattrs = attr_ptr->dispattrs;
5008  } else {
5009  fgc = NULL;
5010  bgc = NULL;
5011  scroll = NULL;
5012  dispattrs = 0;
5013  }
5014 
5015  if (cb_validate_list (values)) {
5016  return;
5017  }
5018  if (cb_validate_one (pos)) {
5019  return;
5020  }
5021  if (cb_validate_one (fgc)) {
5022  return;
5023  }
5024  if (cb_validate_one (bgc)) {
5025  return;
5026  }
5027  if (cb_validate_one (scroll)) {
5028  return;
5029  }
5030  for (l = values; l; l = CB_CHAIN (l)) {
5031  x = CB_VALUE (l);
5032  if (x == cb_error_node) {
5033  return;
5034  }
5035 
5036  switch (CB_TREE_TAG (x)) {
5037  case CB_TAG_LITERAL:
5038  case CB_TAG_INTRINSIC:
5039  case CB_TAG_CONST:
5040  case CB_TAG_STRING:
5041  case CB_TAG_INTEGER:
5042  break;
5043  case CB_TAG_REFERENCE:
5044  if (!CB_FIELD_P(CB_REFERENCE(x)->value)) {
5045  cb_error_x (x, _("'%s' is an invalid type for DISPLAY operand"), cb_name (x));
5046  return;
5047  }
5048  break;
5049  default:
5050  cb_error_x (x, _("Invalid type for DISPLAY operand"));
5051  return;
5052  }
5053  }
5054  if (upon == cb_error_node) {
5055  return;
5056  }
5057 
5058  x = CB_VALUE (values);
5059  if ((CB_REF_OR_FIELD_P (x)) &&
5060  CB_FIELD (cb_ref (x))->storage == CB_STORAGE_SCREEN) {
5061  output_screen_from (CB_FIELD (cb_ref (x)), 0);
5062  gen_screen_ptr = 1;
5063  if (pos) {
5064  if (CB_PAIR_P (pos)) {
5065  line = CB_PAIR_X (pos);
5066  column = CB_PAIR_Y (pos);
5067  if (line == cb_int0) {
5068  line = NULL;
5069  }
5070  cb_emit (CB_BUILD_FUNCALL_3 ("cob_screen_display",
5071  x, line, column));
5072  } else {
5073  cb_emit (CB_BUILD_FUNCALL_3 ("cob_screen_display",
5074  x, pos, NULL));
5075  }
5076  } else {
5077  cb_emit (CB_BUILD_FUNCALL_3 ("cob_screen_display", x,
5078  NULL, NULL));
5079  }
5080  gen_screen_ptr = 0;
5081  } else if (pos || fgc || bgc || scroll || dispattrs || upon == cb_null) {
5082  for (l = values; l; l = CB_CHAIN (l)) {
5083  x = CB_VALUE (l);
5084  if (x == cb_space) {
5085  dispattrs |= COB_SCREEN_ERASE_EOS;
5086  dispattrs |= COB_SCREEN_NO_DISP;
5087  } else if (x == cb_low) {
5088  dispattrs |= COB_SCREEN_NO_DISP;
5089  } else if (CB_LITERAL_P (x) && CB_LITERAL (x)->all &&
5090  CB_LITERAL (x)->size == 1) {
5091  if (CB_LITERAL (x)->data[0] == 1) {
5092  dispattrs |= COB_SCREEN_ERASE_EOL;
5093  dispattrs |= COB_SCREEN_NO_DISP;
5094  } else if (CB_LITERAL (x)->data[0] == 2) {
5095  cb_emit (CB_BUILD_FUNCALL_0 ("cob_sys_clear_screen"));
5096  return;
5097  } else if (CB_LITERAL (x)->data[0] == 7) {
5098  dispattrs |= COB_SCREEN_BELL;
5099  dispattrs |= COB_SCREEN_NO_DISP;
5100  }
5101  }
5102  if (!pos) {
5103  cb_emit (CB_BUILD_FUNCALL_7 ("cob_field_display",
5104  x, NULL, NULL, fgc, bgc,
5105  scroll, cb_int (dispattrs)));
5106  } else if (CB_PAIR_P (pos)) {
5107  line = CB_PAIR_X (pos);
5108  column = CB_PAIR_Y (pos);
5109  if (line == cb_int0) {
5110  line = NULL;
5111  }
5112  cb_emit (CB_BUILD_FUNCALL_7 ("cob_field_display",
5113  x, line, column, fgc, bgc,
5114  scroll, cb_int (dispattrs)));
5115  } else {
5116  cb_emit (CB_BUILD_FUNCALL_7 ("cob_field_display",
5117  x, pos, NULL, fgc, bgc,
5118  scroll, cb_int (dispattrs)));
5119  }
5120  }
5121  } else {
5122  /* DISPLAY x ... [UPON device-name] */
5123  p = CB_BUILD_FUNCALL_3 ("cob_display", upon, no_adv, values);
5124  CB_FUNCALL(p)->varcnt = cb_list_length (values);
5125  CB_FUNCALL(p)->nolitcast = 1;
5126  cb_emit (p);
5127  for (l = values; l; l = CB_CHAIN (l)) {
5128  x = CB_VALUE (l);
5129  if (CB_FIELD_P (x)) {
5130  CB_FIELD (cb_ref (x))->count++;
5131  }
5132  }
5133  }
5134 }
void cb_emit_divide ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
5198 {
5199  if (cb_validate_one (dividend)) {
5200  return;
5201  }
5202  if (cb_validate_one (divisor)) {
5203  return;
5204  }
5205  CB_VALUE (quotient) = cb_check_numeric_edited_name (CB_VALUE (quotient));
5206  CB_VALUE (remainder) = cb_check_numeric_edited_name (CB_VALUE (remainder));
5207 
5208  if (cb_validate_one (CB_VALUE (quotient))) {
5209  return;
5210  }
5211  if (cb_validate_one (CB_VALUE (remainder))) {
5212  return;
5213  }
5214 
5215  cb_emit (CB_BUILD_FUNCALL_4 ("cob_div_quotient", dividend, divisor,
5216  CB_VALUE (quotient),
5217  build_store_option (CB_VALUE (quotient),
5218  CB_PURPOSE (quotient))));
5219  cb_emit (CB_BUILD_FUNCALL_2 ("cob_div_remainder", CB_VALUE (remainder),
5220  build_store_option (CB_VALUE (remainder),
5221  cb_int0)));
5222 }
void cb_emit_env_name ( cb_tree  )
4955 {
4956  if (cb_validate_one (value)) {
4957  return;
4958  }
4959  cb_emit (CB_BUILD_FUNCALL_1 ("cob_display_environment", value));
4960 }
void cb_emit_env_value ( cb_tree  )
4964 {
4965  if (cb_validate_one (value)) {
4966  return;
4967  }
4968  cb_emit (CB_BUILD_FUNCALL_1 ("cob_display_env_value", value));
4969 }
void cb_emit_evaluate ( cb_tree  ,
cb_tree   
)
5369 {
5370  cb_tree x;
5371  char sbuf[16];
5372 
5373  snprintf (sbuf, sizeof(sbuf), "goto %s%d;", CB_PREFIX_LABEL, cb_id);
5374  x = cb_build_direct (cobc_parse_strdup (sbuf), 0);
5375  build_evaluate (subject_list, case_list, x);
5376  snprintf (sbuf, sizeof(sbuf), "%s%d:;", CB_PREFIX_LABEL, cb_id);
5377  cb_emit (cb_build_comment ("End EVALUATE"));
5379  cb_id++;
5380 }
void cb_emit_exit ( const unsigned  int)
5451 {
5452  if (goback) {
5454  } else {
5456  }
5457 }
void cb_emit_free ( cb_tree  )
5386 {
5387  cb_tree l;
5388  struct cb_field *f;
5389  int i;
5390 
5391  if (cb_validate_list (vars)) {
5392  return;
5393  }
5394  for (l = vars, i = 1; l; l = CB_CHAIN (l), i++) {
5395  if (CB_TREE_CLASS (CB_VALUE (l)) == CB_CLASS_POINTER) {
5396  if (CB_CAST_P (CB_VALUE (l))) {
5397  f = CB_FIELD_PTR (CB_CAST (CB_VALUE(l))->val);
5398  if (!f->flag_item_based) {
5399  cb_error_x (CB_TREE (current_statement),
5400  _("Target %d of FREE is not a BASED data item"), i);
5401  }
5402  cb_emit (CB_BUILD_FUNCALL_2 ("cob_free_alloc",
5403  CB_BUILD_CAST_ADDRESS (CB_VALUE (l)), NULL));
5404  } else {
5405  cb_emit (CB_BUILD_FUNCALL_2 ("cob_free_alloc",
5406  NULL, CB_BUILD_CAST_ADDRESS (CB_VALUE (l))));
5407  }
5408  } else if (CB_REF_OR_FIELD_P (CB_VALUE (l))) {
5409  f = CB_FIELD_PTR (CB_VALUE (l));
5410  if (!f->flag_item_based) {
5411  cb_error_x (CB_TREE (current_statement),
5412  _("Target %d of FREE is not a BASED data item"), i);
5413  }
5414  cb_emit (CB_BUILD_FUNCALL_2 ("cob_free_alloc",
5415  CB_BUILD_CAST_ADDR_OF_ADDR (CB_VALUE (l)), NULL));
5416  } else {
5417  cb_error_x (CB_TREE (current_statement),
5418  _("Target %d of FREE must be a data pointer"), i);
5419  }
5420  }
5421 }
void cb_emit_get_environment ( cb_tree  ,
cb_tree   
)
4424 {
4425  if (cb_validate_one (envvar)) {
4426  return;
4427  }
4428  if (cb_validate_one (envval)) {
4429  return;
4430  }
4431  cb_emit (CB_BUILD_FUNCALL_2 ("cob_get_environment", envvar, envval));
4432 }
void cb_emit_goto ( cb_tree  ,
cb_tree   
)
5427 {
5428  if (target == cb_error_node) {
5429  return;
5430  }
5431  if (target == NULL) {
5432  cb_verify (cb_goto_statement_without_name, "GO TO without procedure-name");
5433  } else if (depending) {
5434  /* GO TO procedure-name ... DEPENDING ON identifier */
5436  return;
5437  }
5439  cb_emit (cb_build_goto (target, depending));
5440  } else if (CB_CHAIN (target)) {
5441  cb_error_x (CB_TREE (current_statement),
5442  _("GO TO with multiple procedure-names"));
5443  } else {
5444  /* GO TO procedure-name */
5445  cb_emit (cb_build_goto (CB_VALUE (target), NULL));
5446  }
5447 }
void cb_emit_if ( cb_tree  ,
cb_tree  ,
cb_tree   
)
5463 {
5464  cb_emit (cb_build_if (cond, stmt1, stmt2, 1));
5465 }
void cb_emit_initialize ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
5481 {
5482  cb_tree l;
5483  unsigned int no_fill_init;
5484  unsigned int def_init;
5485 
5486  if (cb_validate_list (vars)) {
5487  return;
5488  }
5489  if (value == NULL && replacing == NULL) {
5490  def = cb_true;
5491  }
5492  no_fill_init = (fillinit == NULL);
5493  def_init = (def != NULL);
5494  for (l = vars; l; l = CB_CHAIN (l)) {
5495  cb_emit (cb_build_initialize (CB_VALUE (l), value, replacing,
5496  def_init, 1, no_fill_init));
5497  }
5498 }
void cb_emit_inspect ( cb_tree  ,
cb_tree  ,
cb_tree  ,
const unsigned  int 
)
5596 {
5597  switch (CB_TREE_TAG(var)) {
5598  case CB_TAG_REFERENCE:
5599  break;
5600  case CB_TAG_INTRINSIC:
5601  if (replconv) {
5602  goto rep_error;
5603  }
5604  switch (CB_TREE_CATEGORY(var)) {
5607  case CB_CATEGORY_NATIONAL:
5608  break;
5609  default:
5610  cb_error_x (CB_TREE (current_statement),
5611  _("Invalid target for INSPECT"));
5612  return;
5613  }
5614  break;
5615  case CB_TAG_LITERAL:
5616  if (replconv) {
5617  goto rep_error;
5618  }
5619  break;
5620  default:
5621  goto rep_error;
5622  }
5623  cb_emit (CB_BUILD_FUNCALL_2 ("cob_inspect_init", var, replacing));
5624  cb_emit_list (body);
5625  cb_emit (CB_BUILD_FUNCALL_0 ("cob_inspect_finish"));
5626  return;
5627 rep_error:
5628  if (replconv == 1) {
5629  cb_error_x (CB_TREE (current_statement),
5630  _("Invalid target for %s"), "REPLACING");
5631  } else {
5632  cb_error_x (CB_TREE (current_statement),
5633  _("Invalid target for %s"), "CONVERTING");
5634  }
5635 }
void cb_emit_move ( cb_tree  ,
cb_tree   
)
7186 {
7187  cb_tree l;
7188  cb_tree x;
7189  cb_tree m;
7190  unsigned int tempval;
7191 
7192  if (cb_validate_one (src)) {
7193  return;
7194  }
7195  if (cb_validate_list (dsts)) {
7196  return;
7197  }
7198 
7199  cb_check_data_incompat (src);
7200 
7201  tempval = 0;
7202  if (cb_list_length (dsts) > 1) {
7203  if (CB_INTRINSIC_P (src) || (CB_REFERENCE_P (src) &&
7204  (CB_REFERENCE (src)->subs || CB_REFERENCE (src)->offset))) {
7205  tempval = 1;
7206  cb_emit (CB_BUILD_FUNCALL_1 ("cob_put_indirect_field",
7207  src));
7208  }
7209  }
7210 
7211  for (l = dsts; l; l = CB_CHAIN (l)) {
7212  x = CB_VALUE (l);
7213  if (CB_LITERAL_P (x) || CB_CONST_P (x)) {
7214  cb_error_x (CB_TREE (current_statement),
7215  _("Invalid MOVE target - %s"), cb_name (x));
7216  continue;
7217  }
7218  if (!tempval) {
7219  m = cb_build_move (src, x);
7220  } else {
7221  m = CB_BUILD_FUNCALL_1 ("cob_get_indirect_field", x);
7222  }
7223  cb_emit (m);
7224  }
7225 }
void cb_emit_move_corresponding ( cb_tree  ,
cb_tree   
)
4100 {
4101  cb_tree l;
4102  cb_tree v;
4103 
4104  x1 = cb_check_group_name (x1);
4105  if (cb_validate_one (x1)) {
4106  return;
4107  }
4108  for (l = x2; l; l = CB_CHAIN(l)) {
4109  v = CB_VALUE(l);
4110  v = cb_check_group_name (v);
4111  if (cb_validate_one (v)) {
4112  return;
4113  }
4114  if (!emit_move_corresponding (x1, v)) {
4115  if (cb_warn_corresponding) {
4116  cb_warning_x (v, _("No CORRESPONDING items found"));
4117  }
4118  }
4119  }
4120 }
void cb_emit_open ( cb_tree  ,
cb_tree  ,
cb_tree   
)
7231 {
7232  struct cb_file *f;
7233 
7234  if (file == cb_error_node) {
7235  return;
7236  }
7237  file = cb_ref (file);
7238  if (file == cb_error_node) {
7239  return;
7240  }
7242  f = CB_FILE (file);
7243 
7244  if (f->organization == COB_ORG_SORT) {
7245  cb_error_x (CB_TREE (current_statement),
7246  _("Operation not allowed on SORT files"));
7247  return;
7248  } else if (f->organization == COB_ORG_LINE_SEQUENTIAL &&
7249  mode == cb_int (COB_OPEN_I_O)) {
7250  cb_error_x (CB_TREE (current_statement),
7251  _("OPEN I-O not allowed on LINE SEQUENTIAL files"));
7252  return;
7253  }
7254  if (sharing == NULL) {
7255  if (f->sharing) {
7256  sharing = f->sharing;
7257  } else {
7258  sharing = cb_int0;
7259  }
7260  }
7261 
7262  cb_emit (CB_BUILD_FUNCALL_4 ("cob_open", file, mode,
7263  sharing, f->file_status));
7264 
7265  /* Check for file debugging */
7268  f->flag_fl_debug) {
7272  }
7273 }
void cb_emit_perform ( cb_tree  ,
cb_tree   
)
7279 {
7280  if (perform == cb_error_node) {
7281  return;
7282  }
7285  cb_emit (cb_build_debug (cb_debug_contents, "PERFORM LOOP", NULL));
7286  }
7287  CB_PERFORM (perform)->body = body;
7288  cb_emit (perform);
7289 }
void cb_emit_read ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
7357 {
7358  cb_tree file;
7359  cb_tree rec;
7360  cb_tree x;
7361  struct cb_file *f;
7362  int read_opts;
7363 
7364  read_opts = 0;
7365  if (lock_opts == cb_int1) {
7366  read_opts = COB_READ_LOCK;
7367  } else if (lock_opts == cb_int2) {
7368  read_opts = COB_READ_NO_LOCK;
7369  } else if (lock_opts == cb_int3) {
7370  read_opts = COB_READ_IGNORE_LOCK;
7371  } else if (lock_opts == cb_int4) {
7372  read_opts = COB_READ_WAIT_LOCK;
7373  }
7374  if (ref == cb_error_node) {
7375  return;
7376  }
7377  file = cb_ref (ref);
7378  if (file == cb_error_node) {
7379  return;
7380  }
7381  f = CB_FILE (file);
7382 
7383  rec = cb_build_field_reference (f->record, ref);
7384  if (f->organization == COB_ORG_SORT) {
7385  cb_error_x (CB_TREE (current_statement),
7386  _("Operation not allowed on SORT files"));
7387  return;
7388  }
7389  if (next == cb_int1 || next == cb_int2 ||
7391  /* READ NEXT/PREVIOUS */
7392  if (next == cb_int2) {
7393  switch (f->organization) {
7394  case COB_ORG_INDEXED:
7395  case COB_ORG_RELATIVE:
7396  break;
7397  default:
7398  cb_error_x (CB_TREE (current_statement),
7399  _("READ PREVIOUS not allowed for this file type"));
7400  return;
7401  }
7402  read_opts |= COB_READ_PREVIOUS;
7403  } else {
7404  read_opts |= COB_READ_NEXT;
7405  }
7406  if (key) {
7407  cb_warning (_("KEY ignored with sequential READ"));
7408  }
7409  cb_emit (CB_BUILD_FUNCALL_3 ("cob_read_next", file,
7410  f->file_status,
7411  cb_int (read_opts)));
7412  } else {
7413  /* READ */
7414  /* DYNAMIC with [NOT] AT END */
7415  if (f->access_mode == COB_ACCESS_DYNAMIC &&
7416  current_statement->handler_id == COB_EC_I_O_AT_END) {
7417  read_opts |= COB_READ_NEXT;
7418  cb_emit (CB_BUILD_FUNCALL_3 ("cob_read_next", file,
7419  f->file_status,
7420  cb_int (read_opts)));
7421  } else if (key || f->key) {
7422  cb_emit (CB_BUILD_FUNCALL_4 ("cob_read",
7423  file, key ? key : f->key,
7424  f->file_status, cb_int (read_opts)));
7425  } else {
7426  cb_emit (CB_BUILD_FUNCALL_3 ("cob_read_next", file,
7427  f->file_status,
7428  cb_int (read_opts)));
7429  }
7430  }
7431  if (into) {
7432  current_statement->handler3 = cb_build_move (rec, into);
7433  }
7434 
7435  /* Check for file debugging */
7438  f->flag_fl_debug) {
7439  if (into) {
7442  }
7446  x = cb_build_move (rec, cb_debug_contents);
7452  }
7454 }
void cb_emit_ready_trace ( void  )
7460 {
7461  cb_emit (CB_BUILD_FUNCALL_0 ("cob_ready_trace"));
7462 }
void cb_emit_release ( cb_tree  ,
cb_tree   
)
7550 {
7551  struct cb_field *f;
7552  cb_tree file;
7553 
7554  if (cb_validate_one (record)) {
7555  return;
7556  }
7557  if (cb_validate_one (from)) {
7558  return;
7559  }
7560  if (!CB_REF_OR_FIELD_P (cb_ref (record))) {
7561  cb_error_x (CB_TREE (current_statement),
7562  _("RELEASE requires a record name as subject"));
7563  return;
7564  }
7565  f = CB_FIELD_PTR (record);
7566  if (f->storage != CB_STORAGE_FILE) {
7567  cb_error_x (CB_TREE (current_statement),
7568  _("RELEASE subject does not refer to a record name"));
7569  return;
7570  }
7571  file = CB_TREE (f->file);
7572  if (CB_FILE (file)->organization != COB_ORG_SORT) {
7573  cb_error_x (CB_TREE (current_statement),
7574  _("RELEASE not allowed on this record item"));
7575  return;
7576  }
7578  if (from) {
7579  cb_emit (cb_build_move (from, record));
7580  }
7581  cb_emit (CB_BUILD_FUNCALL_1 ("cob_file_release", file));
7582 }
void cb_emit_reset_trace ( void  )
7469 {
7470  cb_emit (CB_BUILD_FUNCALL_0 ("cob_reset_trace"));
7471 }
void cb_emit_return ( cb_tree  ,
cb_tree   
)
7588 {
7589  cb_tree file;
7590  cb_tree rec;
7591 
7592  if (cb_validate_one (ref)) {
7593  return;
7594  }
7595  if (cb_validate_one (into)) {
7596  return;
7597  }
7598  file = cb_ref (ref);
7599  if (file == cb_error_node) {
7600  return;
7601  }
7602  rec = cb_build_field_reference (CB_FILE (file)->record, ref);
7603  cb_emit (CB_BUILD_FUNCALL_1 ("cob_file_return", file));
7604  if (into) {
7605  current_statement->handler3 = cb_build_move (rec, into);
7606  }
7608 }
void cb_emit_rewrite ( cb_tree  ,
cb_tree  ,
cb_tree   
)
7477 {
7478  cb_tree file;
7479  struct cb_file *f;
7480  int opts;
7481 
7482  if (cb_validate_one (record)) {
7483  return;
7484  }
7485  if (cb_validate_one (from)) {
7486  return;
7487  }
7488  if (!CB_REF_OR_FIELD_P (cb_ref (record))) {
7489  cb_error_x (CB_TREE (current_statement),
7490  _("REWRITE requires a record name as subject"));
7491  return;
7492  }
7493  if (CB_FIELD_PTR (record)->storage != CB_STORAGE_FILE) {
7494  cb_error_x (CB_TREE (current_statement),
7495  _("REWRITE subject does not refer to a record name"));
7496  return;
7497  }
7498 
7499  file = CB_TREE (CB_FIELD (cb_ref (record))->file);
7500  if (!file || file == cb_error_node) {
7501  return;
7502  }
7504  f = CB_FILE (file);
7505  opts = 0;
7506 
7507  if (f->organization == COB_ORG_SORT) {
7508  cb_error_x (CB_TREE (current_statement),
7509  _("Operation not allowed on SORT files"));
7510  return;
7511  } else if (f->organization == COB_ORG_LINE_SEQUENTIAL) {
7512  cb_error_x (CB_TREE (current_statement),
7513  _("Operation not allowed on LINE SEQUENTIAL files"));
7514  return;
7516  (f->organization != COB_ORG_RELATIVE &&
7517  f->organization != COB_ORG_INDEXED)) {
7519  _("INVALID KEY clause invalid with this file type"));
7520  return;
7521  } else if ((f->lock_mode & COB_LOCK_AUTOMATIC) && lockopt) {
7522  cb_error_x (CB_TREE (current_statement),
7523  _("LOCK clause invalid with file LOCK AUTOMATIC"));
7524  return;
7525  } else if (lockopt == cb_int1) {
7526  opts = COB_WRITE_LOCK;
7527  }
7528 
7529  if (from) {
7530  cb_emit (cb_build_move (from, record));
7531  }
7532 
7533  /* Check debugging on record name */
7536  CB_FIELD_PTR (record)->flag_field_debug) {
7538  CB_FIELD_PTR (record)->name, NULL));
7540  cb_emit (cb_build_debug_call (CB_FIELD_PTR (record)->debug_section));
7541  }
7542  cb_emit (CB_BUILD_FUNCALL_4 ("cob_rewrite", file, record,
7543  cb_int (opts), f->file_status));
7544 }
void cb_emit_rollback ( void  )
7614 {
7615  cb_emit (CB_BUILD_FUNCALL_0 ("cob_rollback"));
7616 }
void cb_emit_search ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
7735 {
7736  if (cb_validate_one (table)) {
7737  return;
7738  }
7739  if (cb_validate_one (varying)) {
7740  return;
7741  }
7742  if (table == cb_error_node) {
7743  return;
7744  }
7745  if (whens == cb_error_node) {
7746  return;
7747  }
7748  whens = cb_list_reverse (whens);
7749  cb_emit (cb_build_search (0, table, varying,
7750  cb_check_needs_break (at_end), whens));
7751 }
void cb_emit_search_all ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
7755 {
7756  cb_tree x;
7757  cb_tree stmt_lis;
7758 
7759  if (cb_validate_one (table)) {
7760  return;
7761  }
7762  if (table == cb_error_node) {
7763  return;
7764  }
7765  if (when == cb_error_node) {
7766  return;
7767  }
7768  x = cb_build_search_all (table, when);
7769  if (!x) {
7770  return;
7771  }
7772 
7773  stmt_lis = cb_check_needs_break (stmts);
7774  cb_emit (cb_build_search (1, table, NULL,
7775  cb_check_needs_break (at_end),
7776  cb_build_if (x, stmt_lis, NULL, 0)));
7777 }
void cb_emit_set_attribute ( cb_tree  ,
const int  ,
const int   
)
7977 {
7978  struct cb_field *f;
7979 
7980  if (cb_validate_one (x)) {
7981  return;
7982  }
7983  if (!CB_REF_OR_FIELD_P (cb_ref (x))) {
7984  cb_error_x (CB_TREE (current_statement),
7985  _("SET ATTRIBUTE requires a screen item as subject"));
7986  return;
7987  }
7988  f = CB_FIELD_PTR (x);
7989  if (f->storage != CB_STORAGE_SCREEN) {
7990  cb_error_x (CB_TREE (current_statement),
7991  _("SET ATTRIBUTE subject does not refer to a screen item"));
7992  return;
7993  }
7994  cb_emit (cb_build_set_attribute (f, val_on, val_off));
7995 }
void cb_emit_set_false ( cb_tree  )
7941 {
7942  cb_tree x;
7943  struct cb_field *f;
7944  cb_tree ref;
7945  cb_tree val;
7946 
7947  for (; l; l = CB_CHAIN (l)) {
7948  x = CB_VALUE (l);
7949  if (x == cb_error_node) {
7950  return;
7951  }
7952  if (!(CB_REFERENCE_P (x) && CB_FIELD_P(CB_REFERENCE(x)->value)) &&
7953  !CB_FIELD_P (x)) {
7954  cb_error_x (x, _("Invalid SET statement"));
7955  return;
7956  }
7957  f = CB_FIELD_PTR (x);
7958  if (f->level != 88) {
7959  cb_error_x (x, _("Invalid SET statement"));
7960  return;
7961  }
7962  if (!f->false_88) {
7963  cb_error_x (x, _("Field does not have FALSE clause"));
7964  return;
7965  }
7966  ref = cb_build_field_reference (f->parent, x);
7967  val = CB_VALUE (f->false_88);
7968  if (CB_PAIR_P (val)) {
7969  val = CB_PAIR_X (val);
7970  }
7971  cb_emit (cb_build_move (val, ref));
7972  }
7973 }
void cb_emit_set_on_off ( cb_tree  ,
cb_tree   
)
7894 {
7895  struct cb_system_name *s;
7896 
7897  if (cb_validate_list (l)) {
7898  return;
7899  }
7900  for (; l; l = CB_CHAIN (l)) {
7901  s = CB_SYSTEM_NAME (cb_ref (CB_VALUE (l)));
7902  cb_emit (CB_BUILD_FUNCALL_2 ("cob_set_switch",
7903  cb_int (s->token), flag));
7904  }
7905 }
void cb_emit_set_to ( cb_tree  ,
cb_tree   
)
7789 {
7790  cb_tree l;
7791  cb_tree v;
7792  struct cb_cast *p;
7793  enum cb_class class;
7794 
7795  if (cb_validate_one (x)) {
7796  return;
7797  }
7798  if (cb_validate_list (vars)) {
7799  return;
7800  }
7801 
7802 #if 0 /* RXWRXW - target check */
7803  /* Determine class of targets */
7804  for (l = vars; l; l = CB_CHAIN (l)) {
7805  if (CB_TREE_CLASS (CB_VALUE (l)) != CB_CLASS_UNKNOWN) {
7806  if (class == CB_CLASS_UNKNOWN) {
7807  class = CB_TREE_CLASS (CB_VALUE (l));
7808  } else if (class != CB_TREE_CLASS (CB_VALUE (l))) {
7809  break;
7810  }
7811  }
7812  }
7813  if (l || (class != CB_CLASS_INDEX && class != CB_CLASS_POINTER)) {
7814  cb_error_x (CB_TREE (current_statement),
7815  _("The targets of SET must be either indexes or pointers"));
7816  return;
7817  }
7818 #endif
7819 
7820  if (CB_CAST_P (x)) {
7821  p = CB_CAST (x);
7822  if (p->cast_type == CB_CAST_PROGRAM_POINTER) {
7823  for (l = vars; l; l = CB_CHAIN (l)) {
7824  v = CB_VALUE (l);
7825  if (!CB_REFERENCE_P (v)) {
7826  cb_error_x (CB_TREE (current_statement),
7827  _("SET targets must be PROGRAM-POINTER"));
7828  CB_VALUE (l) = cb_error_node;
7829  } else if (CB_FIELD(cb_ref(v))->usage != CB_USAGE_PROGRAM_POINTER) {
7830  cb_error_x (CB_TREE (current_statement),
7831  _("SET targets must be PROGRAM-POINTER"));
7832  CB_VALUE (l) = cb_error_node;
7833  }
7834  }
7835  }
7836  }
7837  /* Validate the targets */
7838  for (l = vars; l; l = CB_CHAIN (l)) {
7839  v = CB_VALUE (l);
7840  if (!CB_CAST_P (v)) {
7841  continue;
7842  }
7843  p = CB_CAST (v);
7844  if (p->cast_type == CB_CAST_ADDRESS &&
7845  !CB_FIELD (cb_ref (p->val))->flag_item_based &&
7846  CB_FIELD (cb_ref (p->val))->storage != CB_STORAGE_LINKAGE) {
7847  cb_error_x (p->val, _("The address of '%s' cannot be changed"),
7848  cb_name (p->val));
7849  CB_VALUE (l) = cb_error_node;
7850  }
7851  }
7852  if (cb_validate_list (vars)) {
7853  return;
7854  }
7855 
7856  for (l = vars; l; l = CB_CHAIN (l)) {
7857  class = cb_tree_class (CB_VALUE (l));
7858  switch (class) {
7859  case CB_CLASS_INDEX:
7860  case CB_CLASS_NUMERIC:
7861  case CB_CLASS_POINTER:
7863  cb_emit (cb_build_move (x, CB_VALUE (l)));
7864  break;
7865  default:
7866  cb_error_x (CB_TREE (current_statement),
7867  _("SET target is invalid - '%s'"),
7868  cb_name (CB_VALUE(l)));
7869  break;
7870  }
7871  }
7872 }
void cb_emit_set_true ( cb_tree  )
7909 {
7910  cb_tree x;
7911  struct cb_field *f;
7912  cb_tree ref;
7913  cb_tree val;
7914 
7915  for (; l; l = CB_CHAIN (l)) {
7916  x = CB_VALUE (l);
7917  if (x == cb_error_node) {
7918  return;
7919  }
7920  if (!(CB_REFERENCE_P (x) && CB_FIELD_P(CB_REFERENCE(x)->value)) &&
7921  !CB_FIELD_P (x)) {
7922  cb_error_x (x, _("Invalid SET statement"));
7923  return;
7924  }
7925  f = CB_FIELD_PTR (x);
7926  if (f->level != 88) {
7927  cb_error_x (x, _("Invalid SET statement"));
7928  return;
7929  }
7930  ref = cb_build_field_reference (f->parent, x);
7931  val = CB_VALUE (f->values);
7932  if (CB_PAIR_P (val)) {
7933  val = CB_PAIR_X (val);
7934  }
7935  cb_emit (cb_build_move (val, ref));
7936  }
7937 }
void cb_emit_set_up_down ( cb_tree  ,
cb_tree  ,
cb_tree   
)
7876 {
7877  if (cb_validate_one (x)) {
7878  return;
7879  }
7880  if (cb_validate_list (l)) {
7881  return;
7882  }
7883  for (; l; l = CB_CHAIN (l)) {
7884  if (flag == cb_int0) {
7885  cb_emit (cb_build_add (CB_VALUE (l), x, cb_int0));
7886  } else {
7887  cb_emit (cb_build_sub (CB_VALUE (l), x, cb_int0));
7888  }
7889  }
7890 }
void cb_emit_setenv ( cb_tree  ,
cb_tree   
)
7783 {
7784  cb_emit (CB_BUILD_FUNCALL_2 ("cob_set_environment", x, y));
7785 }
void cb_emit_sort_finish ( cb_tree  )
8120 {
8121  if (CB_FILE_P (cb_ref (file))) {
8122  cb_emit (CB_BUILD_FUNCALL_1 ("cob_file_sort_close", cb_ref (file)));
8123  }
8124 }
void cb_emit_sort_giving ( cb_tree  ,
cb_tree   
)
8083 {
8084  cb_tree p;
8085  int listlen;
8086 
8087  if (cb_validate_list (l)) {
8088  return;
8089  }
8090  for (p = l; p; p = CB_CHAIN (p)) {
8091  if (CB_FILE (cb_ref(CB_VALUE(p)))->organization == COB_ORG_SORT) {
8092  cb_error_x (CB_TREE (current_statement),
8093  _("Invalid SORT GIVING parameter"));
8094  }
8095  }
8096  listlen = cb_list_length (l);
8097  p = CB_BUILD_FUNCALL_2 ("cob_file_sort_giving", cb_ref (file), l);
8098  CB_FUNCALL(p)->varcnt = listlen;
8099  cb_emit (p);
8100 }
void cb_emit_sort_init ( cb_tree  ,
cb_tree  ,
cb_tree   
)
8001 {
8002  cb_tree l;
8003  struct cb_field *f;
8004 
8005  if (cb_validate_list (keys)) {
8006  return;
8007  }
8008  if (cb_ref (name) == cb_error_node) {
8009  return;
8010  }
8011  for (l = keys; l; l = CB_CHAIN (l)) {
8012  if (CB_VALUE (l) == NULL) {
8013  CB_VALUE (l) = name;
8014  }
8015  cb_ref (CB_VALUE (l));
8016  }
8017 
8018  if (CB_FILE_P (cb_ref (name))) {
8019  if (CB_FILE (cb_ref (name))->organization != COB_ORG_SORT) {
8020  cb_error_x (name, _("Invalid SORT filename"));
8021  }
8023  cb_emit (CB_BUILD_FUNCALL_5 ("cob_file_sort_init", cb_ref (name),
8024  cb_int (cb_list_length (keys)), col,
8025  CB_BUILD_CAST_ADDRESS (current_program->cb_sort_return),
8026  CB_FILE(cb_ref (name))->file_status));
8027  for (l = keys; l; l = CB_CHAIN (l)) {
8028  cb_emit (CB_BUILD_FUNCALL_4 ("cob_file_sort_init_key",
8029  cb_ref (name),
8030  CB_VALUE (l),
8031  CB_PURPOSE (l),
8032  cb_int (CB_FIELD_PTR (CB_VALUE(l))->offset)));
8033  }
8034  } else {
8035  if (keys == NULL) {
8036  cb_error_x (name, _("Table sort without keys not implemented yet"));
8037  }
8038  cb_emit (CB_BUILD_FUNCALL_2 ("cob_table_sort_init",
8039  cb_int (cb_list_length (keys)), col));
8040  for (l = keys; l; l = CB_CHAIN (l)) {
8041  cb_emit (CB_BUILD_FUNCALL_3 ("cob_table_sort_init_key",
8042  CB_VALUE (l),
8043  CB_PURPOSE (l),
8044  cb_int(CB_FIELD_PTR (CB_VALUE(l))->offset
8045  - CB_FIELD_PTR (CB_VALUE(l))->parent->offset)));
8046  }
8047  f = CB_FIELD (cb_ref (name));
8048  cb_emit (CB_BUILD_FUNCALL_2 ("cob_table_sort", name,
8049  (f->depending
8051  : cb_int (f->occurs_max))));
8052  }
8053 }
void cb_emit_sort_input ( cb_tree  )
8073 {
8076  cb_emit (cb_build_debug (cb_debug_contents, "SORT INPUT", NULL));
8077  }
8078  cb_emit (cb_build_perform_once (proc));
8079 }
void cb_emit_sort_output ( cb_tree  )
8104 {
8109  "MERGE OUTPUT", NULL));
8110  } else {
8112  "SORT OUTPUT", NULL));
8113  }
8114  }
8115  cb_emit (cb_build_perform_once (proc));
8116 }
void cb_emit_sort_using ( cb_tree  ,
cb_tree   
)
8057 {
8058  if (cb_validate_list (l)) {
8059  return;
8060  }
8061  for (; l; l = CB_CHAIN (l)) {
8062  if (CB_FILE (cb_ref(CB_VALUE(l)))->organization == COB_ORG_SORT) {
8063  cb_error_x (CB_TREE (current_statement),
8064  _("Invalid SORT USING parameter"));
8065  }
8066  cb_emit (CB_BUILD_FUNCALL_2 ("cob_file_sort_using",
8067  cb_ref (file), cb_ref (CB_VALUE (l))));
8068  }
8069 }
void cb_emit_start ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
8178 {
8179  cb_tree kfld;
8180  cb_tree fl;
8181  cb_tree cbtkey;
8182  struct cb_file *f;
8183 
8184  if (cb_validate_one (key)) {
8185  return;
8186  }
8187  if (cb_validate_one (keylen)) {
8188  return;
8189  }
8190  if (file == cb_error_node) {
8191  return;
8192  }
8193  fl = cb_ref (file);
8194  if (fl == cb_error_node) {
8195  return;
8196  }
8197  f = CB_FILE (fl);
8198 
8199  if (f->organization != COB_ORG_INDEXED &&
8201  cb_error_x (CB_TREE (current_statement),
8202  _("START not allowed on SEQUENTIAL files"));
8203  return;
8204  }
8205  if (keylen && f->organization != COB_ORG_INDEXED) {
8206  cb_error_x (CB_TREE (current_statement),
8207  _("LENGTH/SIZE clause only allowed on INDEXED files"));
8208  return;
8209  }
8210  if (f->access_mode == COB_ACCESS_RANDOM) {
8211  cb_error_x (CB_TREE (current_statement),
8212  _("START not allowed with ACCESS MODE RANDOM"));
8213  return;
8214  }
8215 
8216  current_statement->file = fl;
8217  if (key) {
8218  kfld = cb_ref (key);
8219  if (kfld == cb_error_node) {
8220  return;
8221  }
8222  if (check_valid_key (f, CB_FIELD_PTR (kfld))) {
8223  return;
8224  }
8225  cbtkey = key;
8226  } else {
8227  cbtkey = f->key;
8228  }
8229 
8230  /* Check for file debugging */
8233  f->flag_fl_debug) {
8234  /* Gen callback after start but before exception test */
8236  }
8237 
8238  cb_emit (CB_BUILD_FUNCALL_5 ("cob_start", fl, op, cbtkey, keylen,
8239  f->file_status));
8240 }
void cb_emit_stop_run ( cb_tree  )
8246 {
8247  cb_emit (CB_BUILD_FUNCALL_1 ("cob_stop_run", cb_build_cast_int (x)));
8248 }
void cb_emit_string ( cb_tree  ,
cb_tree  ,
cb_tree   
)
8254 {
8255  cb_tree start;
8256  cb_tree l;
8257  cb_tree end;
8258  cb_tree dlm;
8259 
8260  if (cb_validate_one (into)) {
8261  return;
8262  }
8263  if (cb_validate_one (pointer)) {
8264  return;
8265  }
8266  start = items;
8267  cb_emit (CB_BUILD_FUNCALL_2 ("cob_string_init", into, pointer));
8268  while (start) {
8269 
8270  /* Find DELIMITED item */
8271  for (end = start; end; end = CB_CHAIN (end)) {
8272  if (CB_PAIR_P (CB_VALUE (end))) {
8273  break;
8274  }
8275  }
8276 
8277  /* cob_string_delimited */
8278  dlm = end ? CB_PAIR_X (CB_VALUE (end)) : NULL;
8279  if (dlm == cb_int0) {
8280  dlm = NULL;
8281  }
8282  cb_emit (CB_BUILD_FUNCALL_1 ("cob_string_delimited", dlm));
8283 
8284  /* cob_string_append */
8285  for (l = start; l != end; l = CB_CHAIN (l)) {
8286  cb_emit (CB_BUILD_FUNCALL_1 ("cob_string_append",
8287  CB_VALUE (l)));
8288  }
8289 
8290  start = end ? CB_CHAIN (end) : NULL;
8291  }
8292  cb_emit (CB_BUILD_FUNCALL_0 ("cob_string_finish"));
8293 }
void cb_emit_unlock ( cb_tree  )
8299 {
8300  cb_tree file;
8301 
8302  if (ref != cb_error_node) {
8303  file = cb_ref (ref);
8304  if (file != cb_error_node) {
8305  cb_emit (CB_BUILD_FUNCALL_2 ("cob_unlock_file",
8306  file, CB_FILE(file)->file_status));
8308  }
8309  }
8310 }
void cb_emit_unstring ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
8317 {
8318  if (cb_validate_one (name)) {
8319  return;
8320  }
8321  if (cb_validate_one (tallying)) {
8322  return;
8323  }
8324  if (cb_validate_list (delimited)) {
8325  return;
8326  }
8327  if (cb_validate_list (into)) {
8328  return;
8329  }
8330  cb_emit (CB_BUILD_FUNCALL_3 ("cob_unstring_init", name, pointer,
8331  cb_int (cb_list_length (delimited))));
8332  cb_emit_list (delimited);
8333  cb_emit_list (into);
8334  if (tallying) {
8335  cb_emit (CB_BUILD_FUNCALL_1 ("cob_unstring_tallying", tallying));
8336  }
8337  cb_emit (CB_BUILD_FUNCALL_0 ("cob_unstring_finish"));
8338 }
void cb_emit_write ( cb_tree  ,
cb_tree  ,
cb_tree  ,
cb_tree   
)
8368 {
8369  cb_tree file;
8370  cb_tree check_eop;
8371  struct cb_file *f;
8372 
8373  if (cb_validate_one (record)) {
8374  return;
8375  }
8376  if (cb_validate_one (from)) {
8377  return;
8378  }
8379  if (!CB_REF_OR_FIELD_P (cb_ref (record))) {
8380  cb_error_x (CB_TREE (current_statement),
8381  _("WRITE requires a record name as subject"));
8382  return;
8383  }
8384  if (CB_FIELD_PTR (record)->storage != CB_STORAGE_FILE) {
8385  cb_error_x (CB_TREE (current_statement),
8386  _("WRITE subject does not refer to a record name"));
8387  return;
8388  }
8389  file = CB_TREE (CB_FIELD (cb_ref (record))->file);
8390  if (!file || file == cb_error_node) {
8391  return;
8392  }
8394  f = CB_FILE (file);
8395 
8396  if (f->organization == COB_ORG_SORT) {
8397  cb_error_x (CB_TREE (current_statement),
8398  _("Operation not allowed on SORT files"));
8400  (f->organization != COB_ORG_RELATIVE &&
8401  f->organization != COB_ORG_INDEXED)) {
8403  _("INVALID KEY clause invalid with this file type"));
8404  } else if (lockopt) {
8405  if (f->lock_mode & COB_LOCK_AUTOMATIC) {
8406  cb_error_x (CB_TREE (current_statement),
8407  _("LOCK clause invalid with file LOCK AUTOMATIC"));
8408  } else if (opt != cb_int0) {
8409  cb_error_x (CB_TREE (current_statement),
8410  _("LOCK clause invalid here"));
8411  } else if (lockopt == cb_int1) {
8412  opt = cb_int (COB_WRITE_LOCK);
8413  }
8414  }
8415 
8416  if (from) {
8417  cb_emit (cb_build_move (from, record));
8418  }
8419 
8420  /* Check debugging on record name */
8423  CB_FIELD_PTR (record)->flag_field_debug) {
8425  CB_FIELD_PTR (record)->name, NULL));
8427  cb_emit (cb_build_debug_call (CB_FIELD_PTR (record)->debug_section));
8428  }
8430  opt == cb_int0) {
8431  if (cb_flag_write_after || CB_FILE (file)->flag_line_adv) {
8433  } else {
8435  }
8436  }
8439  check_eop = cb_int1;
8440  } else {
8441  check_eop = cb_int0;
8442  }
8443  cb_emit (CB_BUILD_FUNCALL_5 ("cob_write", file, record, opt,
8444  f->file_status, check_eop));
8445 }
char* cb_encode_program_id ( const char *  )
1112 {
1113  unsigned char *p;
1114  const unsigned char *s;
1115  const unsigned char *t;
1116  unsigned char buff[COB_MINI_BUFF];
1117 
1118  s = NULL;
1119  for (t = (const unsigned char *)name; *t; t++) {
1120  if (*t == (unsigned char)'/' || *t == (unsigned char)'\\') {
1121  s = t + 1;
1122  }
1123  }
1124  if (!s) {
1125  s = (const unsigned char *)name;
1126  }
1127  p = buff;
1128  /* Encode the initial digit */
1129  if (*s <= (unsigned char)'9' && *s >= (unsigned char)'0') {
1130  *p++ = (unsigned char)'_';
1131  }
1132  /* Encode invalid letters */
1133  for (; *s; s++) {
1134  if (likely(valid_char[*s])) {
1135  *p++ = *s;
1136  } else {
1137  *p++ = (unsigned char)'_';
1138  if (*s == (unsigned char)'-') {
1139  *p++ = (unsigned char)'_';
1140  } else {
1141  *p++ = hexval[*s / 16U];
1142  *p++ = hexval[*s % 16U];
1143  }
1144  }
1145  }
1146  *p = 0;
1147 
1148  /* Check case folding */
1149  if (unlikely(cb_fold_call)) {
1150  if (cb_fold_call == COB_FOLD_UPPER) {
1151  for (p = buff; *p; p++) {
1152  if (islower (*p)) {
1153  *p = (cob_u8_t)toupper (*p);
1154  }
1155  }
1156  } else if (cb_fold_call == COB_FOLD_LOWER) {
1157  for (p = buff; *p; p++) {
1158  if (isupper (*p)) {
1159  *p = (cob_u8_t)tolower (*p);
1160  }
1161  }
1162  }
1163  }
1164 
1165  return cobc_check_string ((char *)buff);
1166 }
void cb_error_x ( cb_tree  ,
const char *  ,
  ... 
)
185 {
186  va_list ap;
187 
188  va_start (ap, fmt);
189  print_error (x->source_file, x->source_line, _("Error: "), fmt, ap);
190  va_end (ap);
191  if (++errorcount > 100) {
193  }
194 }
struct cb_field* cb_field_add ( struct cb_field ,
struct cb_field  
)
read
2071 {
2072  struct cb_field *t;
2073 
2074  if (f == NULL) {
2075  return p;
2076  }
2077  for (t = f; t->sister; t = t->sister) {
2078  ;
2079  }
2080  t->sister = p;
2081  return f;
2082 }
struct cb_field* cb_field_founder ( const struct cb_field )
read
2086 {
2087  const struct cb_field *ff;
2088 
2089  ff = f;
2090  while (ff->parent) {
2091  ff = ff->parent;
2092  }
2093  return (struct cb_field *)ff;
2094 }
int cb_field_subordinate ( const struct cb_field ,
const struct cb_field  
)
2133 {
2134  struct cb_field *p;
2135 
2136  for (p = pfld->parent; p; p = p->parent) {
2137  if (p == f) {
2138  return 1;
2139  }
2140  }
2141  return 0;
2142 }
unsigned int cb_field_variable_address ( const struct cb_field )
2114 {
2115  const struct cb_field *p;
2116  const struct cb_field *f;
2117 
2118  f = fld;
2119  for (p = f->parent; p; f = f->parent, p = f->parent) {
2120  for (p = p->children; p != f; p = p->sister) {
2121  if (p->depending || cb_field_variable_size (p)) {
2122  return 1;
2123  }
2124  }
2125  }
2126  return 0;
2127 }
struct cb_field* cb_field_variable_size ( const struct cb_field )
read
2098 {
2099  struct cb_field *p;
2100  struct cb_field *fc;
2101 
2102  for (fc = f->children; fc; fc = fc->sister) {
2103  if (fc->depending) {
2104  return fc;
2105  } else if ((p = cb_field_variable_size (fc)) != NULL) {
2106  return p;
2107  }
2108  }
2109  return NULL;
2110 }
int cb_fits_int ( const cb_tree  )
822 {
823  struct cb_literal *l;
824  struct cb_field *f;
825  const char *s;
826  const unsigned char *p;
827  size_t size;
828 
829  switch (CB_TREE_TAG (x)) {
830  case CB_TAG_LITERAL:
831  l = CB_LITERAL (x);
832  if (l->scale > 0) {
833  return 0;
834  }
835  for (size = 0, p = l->data; size < l->size; ++size, ++p) {
836  if (*p != (unsigned char)'0') {
837  break;
838  }
839  }
840  size = l->size - size;
841  if (size < 10) {
842  return 1;
843  }
844  if (size > 10) {
845  return 0;
846  }
847  if (l->sign < 0) {
848  s = "2147483648";
849  } else {
850  s = "2147483647";
851  }
852  if (memcmp (p, s, (size_t)10) > 0) {
853  return 0;
854  }
855  return 1;
856  case CB_TAG_FIELD:
857  f = CB_FIELD (x);
858  if (f->children) {
859  return 0;
860  }
861  switch (f->usage) {
862  case CB_USAGE_INDEX:
863  case CB_USAGE_LENGTH:
864  return 1;
865  case CB_USAGE_BINARY:
866  case CB_USAGE_COMP_5:
867  case CB_USAGE_COMP_X:
868  if (f->pic->scale <= 0 && f->size <= (int)sizeof (int)) {
869  return 1;
870  }
871  return 0;
872  case CB_USAGE_DISPLAY:
873  if (f->size < 10) {
874  if (!f->pic || f->pic->scale <= 0) {
875  return 1;
876  }
877  }
878  return 0;
879  case CB_USAGE_PACKED:
880  case CB_USAGE_COMP_6:
881  if (f->pic->scale <= 0 && f->pic->digits < 10) {
882  return 1;
883  }
884  return 0;
885  default:
886  return 0;
887  }
888  case CB_TAG_REFERENCE:
889  return cb_fits_int (CB_REFERENCE (x)->value);
890  case CB_TAG_INTEGER:
891  return 1;
892  default:
893  return 0;
894  }
895 }
int cb_fits_long_long ( const cb_tree  )
899 {
900  struct cb_literal *l;
901  struct cb_field *f;
902  const char *s;
903  const unsigned char *p;
904  size_t size;
905 
906  switch (CB_TREE_TAG (x)) {
907  case CB_TAG_LITERAL:
908  l = CB_LITERAL (x);
909  if (l->scale > 0) {
910  return 0;
911  }
912  for (size = 0, p = l->data; size < l->size; ++size, ++p) {
913  if (*p != (unsigned char)'0') {
914  break;
915  }
916  }
917  size = l->size - size;
918  if (size < 19) {
919  return 1;
920  }
921  if (size > 19) {
922  return 0;
923  }
924  if (l->sign < 0) {
925  s = "9223372036854775808";
926  } else {
927  s = "9223372036854775807";
928  }
929  if (memcmp (p, s, (size_t)19) > 0) {
930  return 0;
931  }
932  return 1;
933  case CB_TAG_FIELD:
934  f = CB_FIELD (x);
935  if (f->children) {
936  return 0;
937  }
938  switch (f->usage) {
939  case CB_USAGE_INDEX:
940  case CB_USAGE_LENGTH:
941  return 1;
942  case CB_USAGE_BINARY:
943  case CB_USAGE_COMP_5:
944  case CB_USAGE_COMP_X:
945  if (f->pic->scale <= 0 &&
946  f->size <= (int)sizeof (cob_s64_t)) {
947  return 1;
948  }
949  return 0;
950  case CB_USAGE_DISPLAY:
951  if (f->pic->scale <= 0 && f->size < 19) {
952  return 1;
953  }
954  return 0;
955  case CB_USAGE_PACKED:
956  case CB_USAGE_COMP_6:
957  if (f->pic->scale <= 0 && f->pic->digits < 19) {
958  return 1;
959  }
960  return 0;
961  default:
962  return 0;
963  }
964  case CB_TAG_REFERENCE:
965  return cb_fits_long_long (CB_REFERENCE (x)->value);
966  case CB_TAG_INTEGER:
967  return 1;
968  default:
969  return 0;
970  }
971 }
CB_FLAG_RQ ( cb_stack_size  ,
,
"stack-size"  ,
255  ,
,
_("Define PERFORM stack size\n\t\t\t- Default : 255")   
)
int cb_get_int ( const cb_tree  )
975 {
976  struct cb_literal *l;
977 #if 0 /* RXWRXW Fixme SZ */
978  const char *s;
979  size_t size;
980 #endif
981  size_t i;
982  int val;
983 
984  if (!CB_LITERAL_P (x)) {
985  cobc_abort_pr (_("Invalid literal cast - Aborting"));
986  COBC_ABORT ();
987  }
988  l = CB_LITERAL (x);
989  for (i = 0; i < l->size; i++) {
990  if (l->data[i] != '0') {
991  break;
992  }
993  }
994 
995 #if 0 /* RXWRXW Fixme SZ */
996  if (l->sign < 0) {
997  s = "2147483648";
998  } else {
999  s = "2147483647";
1000  }
1001  size = l->size - i;
1002  if (size > 10U || (size == 10U && memcmp (&l->data[i], s, 10) > 0)) {
1003  cobc_abort_pr (_("Numeric literal exceeds limit - Aborting"));
1004  COBC_ABORT ();
1005  }
1006 #endif
1007 
1008  val = 0;
1009  for (; i < l->size; i++) {
1010  val = val * 10 + l->data[i] - '0';
1011  }
1012  if (val && l->sign < 0) {
1013  val = -val;
1014  }
1015  return val;
1016 }
int cb_get_level ( cb_tree  )
47 {
48  const unsigned char *p;
49  const char *name;
50  int level;
51 
52  if (CB_INVALID_TREE (x)) {
53  return 0;
54  }
55  name = CB_NAME (x);
56  level = 0;
57  /* Get level */
58  for (p = (const unsigned char *)name; *p; p++) {
59  if (!isdigit ((int)(*p))) {
60  goto level_error;
61  }
62  level = level * 10 + (*p - '0');
63  if (level > 88) {
64  goto level_error;
65  }
66  }
67 
68  /* Check level */
69  switch (level) {
70  case 66:
71  case 77:
72  case 78:
73  case 88:
74  break;
75  default:
76  if (level < 1 || level > 49) {
77  goto level_error;
78  }
79  break;
80  }
81 
82  return level;
83 
84 level_error:
85  cb_error_x (x, _("Invalid level number '%s'"), name);
86  return 0;
87 }
cob_s64_t cb_get_long_long ( const cb_tree  )
1020 {
1021  struct cb_literal *l;
1022  const char *s;
1023  size_t i;
1024  size_t size;
1025  cob_s64_t val;
1026 
1027  if (!CB_LITERAL_P (x)) {
1028  cobc_abort_pr (_("Invalid literal cast - Aborting"));
1029  COBC_ABORT ();
1030  }
1031  l = CB_LITERAL (x);
1032  for (i = 0; i < l->size; i++) {
1033  if (l->data[i] != '0') {
1034  break;
1035  }
1036  }
1037 
1038  size = l->size - i;
1039  if (size > 19U) {
1040  cobc_abort_pr (_("Numeric literal exceeds limit - Aborting"));
1041  COBC_ABORT ();
1042  }
1043  if (size == 19U) {
1044  if (l->sign < 0) {
1045  s = "9223372036854775808";
1046  } else {
1047  s = "9223372036854775807";
1048  }
1049  if (memcmp (&(l->data[i]), s, (size_t)19) > 0) {
1050  cobc_abort_pr (_("Numeric literal exceeds limit - Aborting"));
1051  COBC_ABORT ();
1052  }
1053  }
1054 
1055  val = 0;
1056  for (; i < l->size; i++) {
1057  val = val * 10 + (l->data[i] & 0x0F);
1058  }
1059  if (val && l->sign < 0) {
1060  val = -val;
1061  }
1062  return val;
1063 }
struct cb_field* cb_get_real_field ( void  )
read
1443 {
1444  return last_real_field;
1445 }
cob_u64_t cb_get_u_long_long ( const cb_tree  )
1067 {
1068  struct cb_literal *l;
1069  size_t i;
1070  size_t size;
1071  cob_u64_t val;
1072 
1073  l = CB_LITERAL (x);
1074  for (i = 0; i < l->size; i++) {
1075  if (l->data[i] != '0') {
1076  break;
1077  }
1078  }
1079 
1080  size = l->size - i;
1081  if (size > 20U) {
1082  cobc_abort_pr (_("Numeric literal exceeds limit - Aborting"));
1083  COBC_ABORT ();
1084  }
1085  if (size == 20U) {
1086  if (memcmp (&(l->data[i]), "18446744073709551615", (size_t)20) > 0) {
1087  cobc_abort_pr (_("Numeric literal exceeds limit - Aborting"));
1088  COBC_ABORT ();
1089  }
1090  }
1091  val = 0;
1092  for (; i < l->size; i++) {
1093  val = val * 10 + (l->data[i] & 0x0F);
1094  }
1095  return val;
1096 }
void cb_init_constants ( void  )
1100 {
1101  int i;
1102 
1108  cb_zero = make_constant (CB_CATEGORY_NUMERIC, "&cob_all_zero");
1109  cb_space = make_constant (CB_CATEGORY_ALPHANUMERIC, "&cob_all_space");
1110  cb_low = make_constant (CB_CATEGORY_ALPHANUMERIC, "&cob_all_low");
1111  cb_norm_low = cb_low;
1112  cb_high = make_constant (CB_CATEGORY_ALPHANUMERIC, "&cob_all_high");
1114  cb_quote = make_constant (CB_CATEGORY_ALPHANUMERIC, "&cob_all_quote");
1115  cb_one = cb_build_numeric_literal (0, "1", 0);
1116  cb_int0 = cb_int (0);
1117  cb_int1 = cb_int (1);
1118  cb_int2 = cb_int (2);
1119  cb_int3 = cb_int (3);
1120  cb_int4 = cb_int (4);
1121  cb_int5 = cb_int (5);
1122  for (i = 0; i < COB_MAX_SUBSCRIPTS; i++) {
1124  }
1125  cb_standard_error_handler = make_constant_label ("Default Error Handler");
1126  CB_LABEL (cb_standard_error_handler)->flag_default_handler = 1;
1127  memset (container_progs, 0, sizeof(container_progs));
1128 }
void cb_init_tallying ( void  )
5639 {
5640  inspect_func = NULL;
5641  inspect_data = NULL;
5642 }
void cb_insert_common_prog ( struct cb_program ,
struct cb_program  
)
1322 {
1323  prog->nested_prog_list = add_contained_prog (prog->nested_prog_list,
1324  comprog);
1325 }
cb_tree cb_int ( const int  )
1331 {
1332  struct cb_integer *x;
1333  struct int_node *p;
1334 
1335  for (p = int_node_table; p; p = p->next) {
1336  if (p->n == n) {
1337  return p->node;
1338  }
1339  }
1340 
1341  /* Do not use make_tree here */
1342  x = cobc_main_malloc (sizeof (struct cb_integer));
1343  x->common.tag = CB_TAG_INTEGER;
1345  x->val = n;
1346 
1347  p = cobc_main_malloc (sizeof (struct int_node));
1348  p->n = n;
1349  p->node = CB_TREE (x);
1350  p->next = int_node_table;
1351  int_node_table = p;
1352  return CB_TREE (x);
1353 }
cb_tree cb_int_hex ( const int  )
1357 {
1358  cb_tree x;
1359 
1360  x = cb_int (n);
1361  CB_INTEGER (x)->hexval = 1;
1362  return x;
1363 }
cb_tree cb_list_add ( cb_tree  ,
cb_tree   
)
1162 {
1163  return cb_list_append (l, CB_LIST_INIT (x));
1164 }
cb_tree cb_list_append ( cb_tree  ,
cb_tree   
)
1146 {
1147  cb_tree l;
1148 
1149  if (l1 == NULL) {
1150  return l2;
1151  }
1152  l = l1;
1153  while (CB_CHAIN (l)) {
1154  l = CB_CHAIN (l);
1155  }
1156  CB_CHAIN (l) = l2;
1157  return l1;
1158 }
void cb_list_intrinsics ( void  )
2726 {
2727  const char *s;
2728  const char *t;
2729  size_t i;
2730  size_t n;
2731 
2732  putchar ('\n');
2733  puts (_("Intrinsic Function\t\tImplemented\tParameters"));
2734  for (i = 0; i < NUM_INTRINSICS; ++i) {
2735  n = strlen (function_list[i].name);
2736  switch (n / 8) {
2737  case 0:
2738  s = "\t\t\t\t";
2739  break;
2740  case 1:
2741  s = "\t\t\t";
2742  break;
2743  case 2:
2744  s = "\t\t";
2745  break;
2746  default:
2747  s = "\t";
2748  break;
2749  }
2750  if (function_list[i].implemented) {
2751  t = _("Y");
2752  } else {
2753  t = _("N");
2754  }
2755  if (function_list[i].args < 0) {
2756  printf ("%s%s%s\t\tVariable\n", function_list[i].name,
2757  s, t);
2758  } else {
2759  printf ("%s%s%s\t\t%d\n", function_list[i].name,
2760  s, t, function_list[i].args);
2761  }
2762  }
2763 }
int cb_list_length ( cb_tree  )
1189 {
1190  int n;
1191 
1192  if (l == cb_error_node) {
1193  return 0;
1194  }
1195  n = 0;
1196  for (; l; l = CB_CHAIN (l)) {
1197  n++;
1198  }
1199  return n;
1200 }
void cb_list_map ( cb_tree(*)(cb_tree ,
cb_tree   
)
void cb_list_mnemonics ( void  )
2767 {
2768  const char *tabs;
2769  const char *feature;
2770  size_t i;
2771 
2772  putchar ('\n');
2773  puts (_("Mnemonic names"));
2774  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
2775  if (strlen (system_table[i].name) < 8) {
2776  tabs = "\t\t";
2777  } else {
2778  tabs = "\t";
2779  }
2780  feature = res_get_feature (system_table[i].category);
2781  printf ("%s%s%s\n", system_table[i].name, tabs, feature);
2782  }
2783  putchar ('\n');
2784  puts (_("Extended mnemonic names (with -fsyntax-extension)"));
2785  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
2786  if (strlen (ext_system_table[i].name) < 8) {
2787  tabs = "\t\t";
2788  } else {
2789  tabs = "\t";
2790  }
2791  feature = res_get_feature (ext_system_table[i].category);
2792  printf ("%s%s%s\n", ext_system_table[i].name, tabs, feature);
2793  }
2794 }
void cb_list_reserved ( void  )
2664 {
2665  const char *s;
2666  const char *p;
2667  size_t i;
2668  size_t n;
2669 
2670  putchar ('\n');
2671  printf (_("Reserved Words\t\t\tImplemented (Y/N)"));
2672  puts ("\n");
2673  for (i = 0; i < NUM_RESERVED_WORDS; ++i) {
2674  n = strlen (reserved_words[i].name);
2675  switch (n / 8) {
2676  case 0:
2677  s = "\t\t\t\t";
2678  break;
2679  case 1:
2680  s = "\t\t\t";
2681  break;
2682  case 2:
2683  s = "\t\t";
2684  break;
2685  default:
2686  s = "\t";
2687  break;
2688  }
2689  if (reserved_words[i].token == 0) {
2690  p = _("N (85 obsolete)");
2691  } else if (reserved_words[i].token > 0) {
2692  if (reserved_words[i].context_sens) {
2693  p = _("Y (Context sensitive)");
2694  } else {
2695  p = _("Y");
2696  }
2697  } else {
2698  if (reserved_words[i].context_sens) {
2699  p = _("N (Context sensitive)");
2700  } else {
2701  p = _("N");
2702  }
2703  }
2704  printf ("%s%s%s\n", reserved_words[i].name, s, p);
2705  }
2706  putchar ('\n');
2707  puts (_("Extra (obsolete) context sensitive words"));
2708  puts ("AUTHOR");
2709  puts ("DATE-COMPILED");
2710  puts ("DATE-MODIFIED");
2711  puts ("DATE-WRITTEN");
2712  puts ("INSTALLATION");
2713  puts ("REMARKS");
2714  puts ("SECURITY");
2715  putchar ('\n');
2716  puts (_("Extra internal registers\tDefinition"));
2717  puts ("RETURN-CODE\t\t\tUSAGE BINARY-LONG");
2718  puts ("SORT-RETURN\t\t\tUSAGE BINARY-LONG");
2719  puts ("NUMBER-OF-CALL-PARAMETERS\tUSAGE BINARY-LONG");
2720  puts ("COB-CRT-STATUS\t\t\tPIC 9(4)");
2721  puts ("'LENGTH OF' phrase\t\tUSAGE BINARY-LONG");
2722 }
cb_tree cb_list_reverse ( cb_tree  )
1174 {
1175  cb_tree next;
1176  cb_tree last;
1177 
1178  last = NULL;
1179  for (; l; l = next) {
1180  next = CB_CHAIN (l);
1181  CB_CHAIN (l) = last;
1182  last = l;
1183  }
1184  return last;
1185 }
void cb_list_system ( void  )
827 {
828  const struct system_table *psyst;
829  const char *s;
830  size_t n;
831 
832  putchar ('\n');
833  printf (_("System routine\t\t\tParameters"));
834  puts ("\n");
835  for (psyst = system_tab; psyst->syst_name; psyst++) {
836  switch (*(unsigned char *)(psyst->syst_name)) {
837  case 'C':
838  case 'S':
839  printf ("%s", psyst->syst_name);
840  break;
841  case 0xF4:
842  printf ("X\"F4\"");
843  break;
844  case 0xF5:
845  printf ("X\"F5\"");
846  break;
847  case 0x91:
848  printf ("X\"91\"");
849  break;
850  case 0xE4:
851  printf ("X\"E4\"");
852  break;
853  case 0xE5:
854  printf ("X\"E5\"");
855  break;
856  default:
857  break;
858  }
859  n = strlen (psyst->syst_name);
860  switch (n / 8) {
861  case 0:
862  s = "\t\t\t\t";
863  break;
864  case 1:
865  s = "\t\t\t";
866  break;
867  case 2:
868  s = "\t\t";
869  break;
870  default:
871  s = "\t";
872  break;
873  }
874  printf ("%s%d\n", s, psyst->syst_params);
875  }
876 }
int cb_load_conf ( const char *  ,
const int  ,
const int   
)

References _, cb_config_entry(), CB_CONFIG_SIZE, cb_load_conf(), cob_config_dir, COB_SMALL_BUFF, COB_SMALL_MAX, config_table, configuration_error(), line, NULL, read_string(), SLASH_STR, and config_struct::val.

Referenced by cb_load_conf(), cb_load_std(), and process_command_line().

299 {
300  const unsigned char *x;
301  const char *name;
302  FILE *fp;
303  size_t i;
304  int sub_ret, ret;
305  int line;
306  char buff[COB_SMALL_BUFF];
307 
308  /* Initialize the configuration table */
309  if (check_nodef) {
310  for (i = 0; i < CB_CONFIG_SIZE; i++) {
311  config_table[i].val = NULL;
312  }
313  }
314 
315  if (prefix_dir) {
316  snprintf (buff, (size_t)COB_SMALL_MAX,
317  "%s%s%s", cob_config_dir, SLASH_STR, fname);
318  name = buff;
319  } else {
320  name = fname;
321  }
322  /* Open the configuration file */
323  fp = fopen (name, "r");
324  if (fp == NULL) {
325  fflush (stderr);
326  configuration_error (name, 0, _("No such file or directory"));
327  return -1;
328  }
329 
330  /* Read the configuration file */
331  ret = 0;
332  line = 0;
333  while (fgets (buff, COB_SMALL_BUFF, fp)) {
334  line++;
335 
336  /* Skip line comments, empty lines */
337  if (buff[0] == '#' || buff[0] == '\n') {
338  continue;
339  }
340 
341  /* Skip blank lines */
342  for (x = (const unsigned char *)buff; *x; x++) {
343  if (isgraph (*x)) {
344  break;
345  }
346  }
347  if (!*x) {
348  continue;
349  }
350 
351  sub_ret = cb_config_entry (buff, fname, line);
352  if (sub_ret == 1) {
353  /* Include another configuration file */
354  /* Find entry for getting include value */
355  for (i = 0; i < CB_CONFIG_SIZE; i++) {
356  if (strcmp (buff, config_table[i].name) == 0) {
357  break;
358  }
359  }
360  sub_ret = cb_load_conf (read_string(config_table[i].val), 0, 1);
361  if (sub_ret != 0) {
362  fclose (fp);
363  /* Only 1 include allowed */
364  if (sub_ret == 1) {
366  _("Only one include in configuration files allowed"));
367  sub_ret = -1;
368  }
369  }
370  }
371  if (sub_ret != 0) ret = sub_ret;
372  }
373  fclose (fp);
374 
375  /* Checks for missing definitions */
376  if (check_nodef) {
377  for (i = 2U; i < CB_CONFIG_SIZE; i++) {
378  if (config_table[i].val == NULL) {
379  configuration_error (fname, 0, _("No definition of '%s'"),
380  config_table[i].name);
381  ret = -1;
382  }
383  }
384  }
385 
386  return ret;
387 }
int cb_load_std ( const char *  )

References cb_load_conf().

Referenced by process_command_line().

130 {
131  return cb_load_conf (name, 1, 1);
132 }
char* cb_name ( cb_tree  )
643 {
644  char *s;
645 
646  s = cobc_parse_malloc ((size_t)COB_NORMAL_BUFF);
647  (void)cb_name_1 (s, x);
648  return s;
649 }
cb_tree cb_pair_add ( cb_tree  ,
cb_tree  ,
cb_tree   
)
1168 {
1169  return cb_list_append (l, CB_BUILD_PAIR (x, y));
1170 }
void cb_plex_error ( const size_t  ,
const char *  ,
  ... 
)

References _, cb_source_line, cobc_too_many_errors(), errorcount, NULL, and print_error().

Referenced by plex_action_directive(), ppinput(), and ppparse_error().

130 {
131  va_list ap;
132 
133  va_start (ap, fmt);
134  print_error (NULL, (int)(cb_source_line + sline), _("Error: "), fmt, ap);
135  va_end (ap);
136  if (++errorcount > 100) {
138  }
139 }
void cb_plex_warning ( const size_t  ,
const char *  ,
  ... 
)

References _, cb_source_line, NULL, print_error(), and warningcount.

Referenced by ppinput(), and while().

119 {
120  va_list ap;
121 
122  va_start (ap, fmt);
123  print_error (NULL, (int)(cb_source_line + sline), _("Warning: "), fmt, ap);
124  va_end (ap);
125  warningcount++;
126 }
cb_tree cb_ref ( cb_tree  )
2505 {
2506  struct cb_reference *r;
2507  struct cb_field *p;
2508  struct cb_label *s;
2509  cb_tree candidate;
2510  cb_tree items;
2511  cb_tree cb1;
2512  cb_tree cb2;
2513  cb_tree v;
2514  cb_tree c;
2515  struct cb_program *prog;
2516  struct cb_word *w;
2517  size_t val;
2518  size_t ambiguous;
2519 
2520  if (CB_INVALID_TREE (x)) {
2521  return cb_error_node;
2522  }
2523  r = CB_REFERENCE (x);
2524  /* If this reference has already been resolved (and the value
2525  has been cached), then just return the value */
2526  if (r->value) {
2527  return r->value;
2528  }
2529 
2530  /* Resolve the value */
2531 
2532  candidate = NULL;
2533  ambiguous = 0;
2534  items = r->word->items;
2535  for (; items; items = CB_CHAIN (items)) {
2536  /* Find a candidate value by resolving qualification */
2537  v = CB_VALUE (items);
2538  c = r->chain;
2539  switch (CB_TREE_TAG (v)) {
2540  case CB_TAG_FIELD:
2541  /* In case the value is a field, it might be qualified
2542  by its parent names and a file name */
2543  if (CB_FIELD (v)->flag_indexed_by) {
2544  p = CB_FIELD (v)->index_qual;
2545  } else {
2546  p = CB_FIELD (v)->parent;
2547  }
2548  /* Resolve by parents */
2549  for (; p; p = p->parent) {
2550  if (c && strcasecmp (CB_NAME (c), p->name) == 0) {
2551  c = CB_REFERENCE (c)->chain;
2552  }
2553  }
2554 
2555  /* Resolve by file */
2556  if (c && CB_REFERENCE (c)->chain == NULL) {
2557  if (CB_WORD_COUNT (c) == 1 &&
2558  CB_FILE_P (cb_ref (c)) &&
2559  (CB_FILE (cb_ref (c)) == cb_field_founder (CB_FIELD (v))->file)) {
2560  c = CB_REFERENCE (c)->chain;
2561  }
2562  }
2563 
2564  break;
2565  case CB_TAG_LABEL:
2566  /* In case the value is a label, it might be qualified
2567  by its section name */
2568  s = CB_LABEL (v)->section;
2569 
2570  /* Unqualified paragraph name referenced within the section
2571  is resolved without ambiguity check if not duplicated */
2572  if (c == NULL && r->offset && s == CB_LABEL (r->offset)) {
2573  for (cb1 = CB_CHAIN (items); cb1; cb1 = CB_CHAIN (cb1)) {
2574  cb2 = CB_VALUE (cb1);
2575  if (s == CB_LABEL (cb2)->section) {
2576  ambiguous_error (x);
2577  goto error;
2578  }
2579  }
2580  candidate = v;
2581  goto end;
2582  }
2583 
2584  /* Resolve by section name */
2585  if (c && s && strcasecmp (CB_NAME (c), (char *)s->name) == 0) {
2586  c = CB_REFERENCE (c)->chain;
2587  }
2588 
2589  break;
2590  default:
2591  /* Other values cannot be qualified */
2592  break;
2593  }
2594 
2595  /* A well qualified value is a good candidate */
2596  if (c == NULL) {
2597  if (candidate == NULL) {
2598  /* Keep the first candidate */
2599  candidate = v;
2600  } else {
2601  /* Multiple candidates and possibly ambiguous */
2602  ambiguous = 1;
2603  /* Continue search because the reference might not
2604  be ambiguous and exit loop by "goto end" later */
2605  }
2606  }
2607  }
2608 
2609  /* There is no candidate */
2610  if (candidate == NULL) {
2611  if (likely(current_program->nested_level <= 0)) {
2612  goto undef_error;
2613  }
2614  /* Nested program - check parents for GLOBAL candidate */
2615  ambiguous = 0;
2616 /* RXWRXW
2617  val = hash ((const unsigned char *)r->word->name);
2618 */
2619  val = r->hashval;
2620  prog = current_program->next_program;
2621  for (; prog; prog = prog->next_program) {
2622  if (prog->nested_level >= current_program->nested_level) {
2623  continue;
2624  }
2625  for (w = prog->word_table[val]; w; w = w->next) {
2626  if (strcasecmp (r->word->name, w->name) == 0) {
2627  candidate = global_check (r, w->items, &ambiguous);
2628  if (candidate) {
2629  if (ambiguous) {
2630  ambiguous_error (x);
2631  goto error;
2632  }
2633  if (CB_FILE_P(candidate)) {
2635  }
2636  goto end;
2637  }
2638  }
2639  }
2640  if (prog->nested_level == 0) {
2641  break;
2642  }
2643  }
2644  goto undef_error;
2645  }
2646 
2647  /* Reference is ambiguous */
2648  if (ambiguous) {
2649  ambiguous_error (x);
2650  goto error;
2651  }
2652 
2653 end:
2654  if (CB_FIELD_P (candidate)) {
2655  CB_FIELD (candidate)->count++;
2656  if (CB_FIELD (candidate)->flag_invalid) {
2657  goto error;
2658  }
2659  } else if (CB_LABEL_P (candidate) && r->flag_alter_code) {
2660  CB_LABEL (candidate)->flag_alter = 1;
2661  }
2662 
2663  r->value = candidate;
2664  return r->value;
2665 
2666 undef_error:
2667  undefined_error (x);
2668  /* Fall through */
2669 
2670 error:
2671  r->value = cb_error_node;
2672  return cb_error_node;
2673 }
void cb_reset_78 ( void  )

References cobc_free(), const78ptr, globlev78ptr, cb_level_78::next, cb_level_78::not_const, and NULL.

Referenced by cb_build_program().

1654 {
1655  struct cb_level_78 *p78;
1656  struct cb_level_78 *p782;
1657 
1658  /* Remove constant (78 level) items for current program */
1659  for (p78 = lev78ptr; p78; ) {
1660  p782 = p78->next;
1661  cobc_free (p78);
1662  p78 = p782;
1663  }
1664  lev78ptr = NULL;
1665  for (p78 = globlev78ptr; p78; p78 = p78->next) {
1666  p78->not_const = 0;
1667  }
1668  if (globlev78ptr) {
1670  } else {
1671  top78ptr = const78ptr;
1672  }
1673 }
void cb_reset_global_78 ( void  )

References cobc_free(), const78ptr, cb_level_78::next, and NULL.

Referenced by cb_build_program().

1677 {
1678  struct cb_level_78 *p78;
1679  struct cb_level_78 *p782;
1680 
1681  /* Remove constant (78 level) items for top program */
1682  for (p78 = globlev78ptr; p78; ) {
1683  p782 = p78->next;
1684  cobc_free (p78);
1685  p78 = p782;
1686  }
1687  globlev78ptr = NULL;
1688  top78ptr = const78ptr;
1689 }
struct cb_field* cb_resolve_redefines ( struct cb_field ,
cb_tree   
)
read
247 {
248  struct cb_field *f;
249  struct cb_reference *r;
250  const char *name;
251  cb_tree x;
252  cb_tree candidate;
253  cb_tree items;
254 
255  r = CB_REFERENCE (redefines);
256  name = CB_NAME (redefines);
257  x = CB_TREE (field);
258 
259  /* Check qualification */
260  if (r->chain) {
261  cb_error_x (x, _("'%s' cannot be qualified here"), name);
262  return NULL;
263  }
264 
265  /* Check subscripts */
266  if (r->subs) {
267  cb_error_x (x, _("'%s' cannot be subscripted here"), name);
268  return NULL;
269  }
270 
271  /* Resolve the name in the current group (if any) */
272  if (field->parent && field->parent->children) {
273  for (f = field->parent->children; f; f = f->sister) {
274  if (strcasecmp (f->name, name) == 0) {
275  break;
276  }
277  }
278  if (f == NULL) {
279  cb_error_x (x, _("'%s' is not defined in '%s'"), name, field->parent->name);
280  return NULL;
281  }
282  } else {
283  /* Get last defined name */
284  candidate = NULL;
285  items = r->word->items;
286  for (; items; items = CB_CHAIN (items)) {
287  if (CB_FIELD_P (CB_VALUE (items))) {
288  candidate = CB_VALUE (items);
289  }
290  }
291  if (!candidate) {
292  undefined_error (redefines);
293  return NULL;
294  }
295  f = CB_FIELD_PTR (candidate);
296  }
297 
298  /* Check level number */
299  if (f->level != field->level) {
300  cb_error_x (x, _("Level number of REDEFINES entries must be identical"));
301  return NULL;
302  }
303  if (f->level == 66 || f->level == 88) {
304  cb_error_x (x, _("Level number of REDEFINES entry cannot be 66 or 88"));
305  return NULL;
306  }
307 
308  if (!cb_indirect_redefines && f->redefines) {
309  cb_error_x (x, _("'%s' not the original definition"), f->name);
310  return NULL;
311  }
312 
313  /* Return the original definition */
314  while (f->redefines) {
315  f = f->redefines;
316  }
317  return f;
318 }
void cb_set_system_names ( void  )
2489 {
2490  cb_define_system_name ("CONSOLE");
2491  cb_define_system_name ("SYSIN");
2492  cb_define_system_name ("SYSIPT");
2493  cb_define_system_name ("STDIN");
2494  cb_define_system_name ("SYSOUT");
2495  cb_define_system_name ("STDOUT");
2496  cb_define_system_name ("SYSERR");
2497  cb_define_system_name ("STDERR");
2498  cb_define_system_name ("SYSLST");
2499  cb_define_system_name ("SYSLIST");
2500  cb_define_system_name ("FORMFEED");
2501 }
char* cb_to_cname ( const char *  )
613 {
614  char *copy;
615  unsigned char *p;
616 
617  copy = cobc_parse_strdup (s);
618  for (p = (unsigned char *)copy; *p; p++) {
619  if (*p == '-' || *p == ' ') {
620  *p = '_';
621  } else {
622  *p = (cob_u8_t)toupper (*p);
623  }
624  }
625  return copy;
626 }
enum cb_category cb_tree_category ( cb_tree  )
653 {
654  struct cb_cast *p;
655  struct cb_reference *r;
656  struct cb_field *f;
657 
658  if (x == cb_error_node) {
659  return (enum cb_category)0;
660  }
661  if (x->category != CB_CATEGORY_UNKNOWN) {
662  return x->category;
663  }
664 
665  switch (CB_TREE_TAG (x)) {
666  case CB_TAG_CAST:
667  p = CB_CAST (x);
668  switch (p->cast_type) {
669  case CB_CAST_ADDRESS:
671  x->category = CB_CATEGORY_DATA_POINTER;
672  break;
674  x->category = CB_CATEGORY_PROGRAM_POINTER;
675  break;
676  default:
677  cobc_abort_pr (_("Unexpected cast type -> %d"),
678  (int)(p->cast_type));
679  COBC_ABORT ();
680  }
681  break;
682  case CB_TAG_REFERENCE:
683  r = CB_REFERENCE (x);
684  if (r->offset) {
685  x->category = CB_CATEGORY_ALPHANUMERIC;
686  } else {
687  x->category = cb_tree_category (r->value);
688  }
689  break;
690  case CB_TAG_FIELD:
691  f = CB_FIELD (x);
692  if (f->children) {
693  x->category = CB_CATEGORY_ALPHANUMERIC;
694  } else if (f->usage == CB_USAGE_POINTER && f->level != 88) {
695  x->category = CB_CATEGORY_DATA_POINTER;
696  } else if (f->usage == CB_USAGE_PROGRAM_POINTER && f->level != 88) {
697  x->category = CB_CATEGORY_PROGRAM_POINTER;
698  } else {
699  switch (f->level) {
700  case 66:
701  if (f->rename_thru) {
702  x->category = CB_CATEGORY_ALPHANUMERIC;
703  } else {
704  x->category = cb_tree_category (CB_TREE (f->redefines));
705  }
706  break;
707  case 88:
708  x->category = CB_CATEGORY_BOOLEAN;
709  break;
710  default:
711  if (f->pic) {
712  x->category = f->pic->category;
713  } else {
714  x->category = (enum cb_category)0;
715  }
716  break;
717  }
718  }
719  break;
721  case CB_TAG_LOCALE_NAME:
722  x->category = CB_CATEGORY_ALPHANUMERIC;
723  break;
724  case CB_TAG_BINARY_OP:
725  x->category = CB_CATEGORY_BOOLEAN;
726  break;
727  case CB_TAG_INTRINSIC:
728  x->category = CB_INTRINSIC(x)->intr_tab->category;
729  break;
730  default:
731 #if 0 /* RXWRXW - Tree tag */
732  cobc_abort_pr (_("Unknown tree tag %d Category %d"),
733  (int)CB_TREE_TAG (x), (int)x->category);
734  COBC_ABORT ();
735 #endif
736  return CB_CATEGORY_UNKNOWN;
737  }
738 
739  return x->category;
740 }
enum cb_class cb_tree_class ( cb_tree  )
744 {
745 
747 }
int cb_tree_type ( const cb_tree  ,
const struct cb_field  
)
757 {
758  if (f->children) {
759  return COB_TYPE_GROUP;
760  }
761 
762  switch (CB_TREE_CATEGORY (x)) {
765  return COB_TYPE_ALPHANUMERIC;
768  case CB_CATEGORY_NUMERIC:
769  switch (f->usage) {
770  case CB_USAGE_DISPLAY:
772  case CB_USAGE_BINARY:
773  case CB_USAGE_COMP_5:
774  case CB_USAGE_COMP_X:
775  case CB_USAGE_INDEX:
776  case CB_USAGE_LENGTH:
778  case CB_USAGE_FLOAT:
779  return COB_TYPE_NUMERIC_FLOAT;
780  case CB_USAGE_DOUBLE:
782  case CB_USAGE_PACKED:
783  case CB_USAGE_COMP_6:
787  case CB_USAGE_FP_BIN32:
789  case CB_USAGE_FP_BIN64:
791  case CB_USAGE_FP_BIN128:
793  case CB_USAGE_FP_DEC64:
795  case CB_USAGE_FP_DEC128:
797  default:
798  cobc_abort_pr (_("Unexpected numeric usage -> %d"),
799  (int)f->usage);
800  COBC_ABORT ();
801  }
808  default:
809  cobc_abort_pr (_("Unexpected category -> %d"),
810  (int)CB_TREE_CATEGORY (x));
811  /* Use dumb variant */
812  COBC_DUMB_ABORT ();
813  }
814  /* NOT REACHED */
815 #ifndef _MSC_VER
816  return 0;
817 #endif
818 }
void cb_unput_dot ( void  )

References unput.

1648 {
1649  unput ('.');
1650 }
struct cb_field* cb_validate_78_item ( struct cb_field ,
const cob_u32_t   
)
read
1413 {
1414  cb_tree x;
1415  cob_u32_t noadd;
1416 
1417  x = CB_TREE (f);
1418  noadd = no78add;
1419  if (CB_INVALID_TREE(f->values) ||
1420  CB_INVALID_TREE(CB_VALUE(f->values))) {
1421  level_require_error (x, "VALUE");
1422  noadd = 1;
1423  }
1424 
1425  if (f->pic || f->flag_occurs) {
1426  level_except_error (x, "VALUE");
1427  noadd = 1;
1428  }
1429  if (!noadd) {
1430  cb_add_78 (f);
1431  }
1432  return last_real_field;
1433 }
void cb_validate_88_item ( struct cb_field )
1384 {
1385  cb_tree x;
1386  cb_tree l;
1387  cb_tree t;
1388 
1389  x = CB_TREE (f);
1390  if (!f->values) {
1391  level_require_error (x, "VALUE");
1392  return;
1393  }
1394 
1395  if (f->pic || f->flag_occurs) {
1396  level_except_error (x, "VALUE");
1397  return;
1398  }
1399  if (CB_VALID_TREE(f->parent) &&
1400  CB_TREE_CLASS (f->parent) == CB_CLASS_NUMERIC) {
1401  for (l = f->values; l; l = CB_CHAIN (l)) {
1402  t = CB_VALUE (l);
1403  if (t == cb_space || t == cb_low ||
1404  t == cb_high || t == cb_quote) {
1405  cb_error_x (x, _("Literal type does not match data type"));
1406  }
1407  }
1408  }
1409 }
void cb_validate_field ( struct cb_field )
1336 {
1337  struct cb_field *c;
1338 
1339  if (f->flag_is_verified) {
1340  return;
1341  }
1342  if (validate_field_1 (f) != 0) {
1343  f->flag_invalid = 1;
1344  return;
1345  }
1346  if (f->flag_item_78) {
1347  f->flag_is_verified = 1;
1348  return;
1349  }
1350 
1351  /* Set up parameters */
1352  if (f->storage == CB_STORAGE_LOCAL ||
1353  f->storage == CB_STORAGE_LINKAGE ||
1354  f->flag_item_based) {
1355  f->flag_local = 1;
1356  }
1357  if (f->storage == CB_STORAGE_LINKAGE || f->flag_item_based) {
1358  f->flag_base = 1;
1359  }
1360  setup_parameters (f);
1361 
1362  /* Compute size */
1363  occur_align_size = 1;
1364  compute_size (f);
1365  if (!f->redefines) {
1366  f->memory_size = f->size * f->occurs_max;
1367  } else if (f->redefines->memory_size < f->size * f->occurs_max) {
1368  f->redefines->memory_size = f->size * f->occurs_max;
1369  }
1370 
1372  if (f->flag_is_global) {
1373  f->count++;
1374  for (c = f->children; c; c = c->sister) {
1375  c->flag_is_global = 1;
1376  c->count++;
1377  }
1378  }
1379  f->flag_is_verified = 1;
1380 }
void cb_validate_program_body ( struct cb_program )
2483 {
2484  cb_tree l;
2485  cb_tree x;
2486  cb_tree v;
2487  struct cb_label *save_section;
2488  struct cb_label *save_paragraph;
2489  struct cb_alter_id *aid;
2490  struct cb_label *l1;
2491  struct cb_label *l2;
2492  struct cb_field *f;
2493  int size;
2494 
2495  /* Resolve all labels */
2496  save_section = current_section;
2497  save_paragraph = current_paragraph;
2498  for (l = cb_list_reverse (prog->label_list); l; l = CB_CHAIN (l)) {
2499  x = CB_VALUE (l);
2500  current_section = CB_REFERENCE (x)->section;
2501  current_paragraph = CB_REFERENCE (x)->paragraph;
2502  v = cb_ref (x);
2503  /* Check refs in to / out of DECLARATIVES */
2504  if (CB_LABEL_P (v)) {
2505  if (CB_REFERENCE (x)->flag_in_decl &&
2506  !CB_LABEL (v)->flag_declaratives) {
2507  if (!cb_relaxed_syntax_check) {
2508  cb_error_x (x, _("'%s' is not in DECLARATIVES"),
2509  CB_LABEL (v)->name);
2510  } else {
2511  cb_warning_x (x, _("'%s' is not in DECLARATIVES"),
2512  CB_LABEL (v)->name);
2513  }
2514  }
2515  if (CB_LABEL (v)->flag_declaratives &&
2516  !CB_REFERENCE (x)->flag_in_decl &&
2517  !CB_REFERENCE (x)->flag_decl_ok) {
2518  cb_error_x (x, _("Invalid reference to '%s' (In DECLARATIVES)"), CB_LABEL (v)->name);
2519  }
2520  CB_LABEL (v)->flag_begin = 1;
2521  if (CB_REFERENCE (x)->length) {
2522  CB_LABEL (v)->flag_return = 1;
2523  }
2524  } else if (v != cb_error_node) {
2525  cb_error_x (x, _("'%s' not a procedure name"), cb_name (x));
2526  }
2527  }
2528 
2529  /* Resolve DEBUG references */
2530  /* For data items, we may need to adjust the size of DEBUG-CONTENTS */
2531  /* Basic size of DEBUG-CONTENTS is 31 */
2532  size = 31;
2533  for (l = prog->debug_list; l; l = CB_CHAIN (l)) {
2534  x = CB_VALUE (l);
2535  current_section = CB_REFERENCE (x)->section;
2536  current_paragraph = CB_REFERENCE (x)->paragraph;
2537  v = cb_ref (x);
2538  if (v == cb_error_node) {
2539  continue;
2540  }
2541  switch (CB_TREE_TAG (v)) {
2542  case CB_TAG_LABEL:
2544  cb_error_x (x, _("'%s' - DEBUGGING target invalid with ALL PROCEDURES"),
2545  cb_name (x));
2546  }
2547  if (!CB_LABEL (v)->flag_real_label) {
2548  cb_error_x (x, _("'%s' - DEBUGGING target invalid"),
2549  cb_name (x));
2550  }
2551  CB_LABEL (v)->debug_section =
2552  CB_REFERENCE (x)->debug_section;
2553  CB_LABEL (v)->flag_debugging_mode = 1;
2554  break;
2555  case CB_TAG_FILE:
2556  break;
2557  case CB_TAG_FIELD:
2558  if (CB_FIELD (v)->size > size) {
2559  size = CB_FIELD (v)->size;
2560  }
2561  break;
2562  default:
2563  cb_error_x (x, _("'%s' is not a valid DEBUGGING target"),
2564  cb_name (x));
2565  break;
2566  }
2567  }
2568  /* If necessary, adjust size of DEBUG-CONTENTS (and DEBUG-ITEM) */
2570  if (size != 31) {
2572  f->size = size;
2573  f->memory_size = size;
2574  size -= 31;
2576  f->size += size;
2577  f->memory_size += size;
2578  }
2579  }
2580 
2581  /* Build ALTER ids - We need to remove duplicates */
2582  for (l = prog->alter_list; l; l = CB_CHAIN (l)) {
2583  if (CB_PURPOSE (l) == cb_error_node) {
2584  continue;
2585  }
2586  if (CB_VALUE (l) == cb_error_node) {
2587  continue;
2588  }
2589  x = CB_PURPOSE (l);
2590  v = CB_VALUE (l);
2591  if (CB_REFERENCE (x)->value == cb_error_node) {
2592  continue;
2593  }
2594  if (CB_REFERENCE (v)->value == cb_error_node) {
2595  continue;
2596  }
2597  l1 = CB_LABEL (CB_REFERENCE (x)->value);
2598  l2 = CB_LABEL (CB_REFERENCE (v)->value);
2599  current_section = CB_REFERENCE (x)->section;
2600  current_paragraph = CB_REFERENCE (x)->paragraph;
2601  /* First statement in paragraph must be a GO TO */
2602  if (!l1->flag_first_is_goto) {
2603  cb_error_x (x, _("'%s' is not an alterable paragraph"),
2604  l1->name);
2605  continue;
2606  }
2607  for (aid = l1->alter_gotos; aid; aid = aid->next) {
2608  if (aid->goto_id == l2->id) {
2609  break;
2610  }
2611  }
2612  if (!aid) {
2613  aid = cobc_parse_malloc (sizeof(struct cb_alter_id));
2614  aid->next = l1->alter_gotos;
2615  aid->goto_id = l2->id;
2616  l1->alter_gotos = aid;
2617  }
2618  for (aid = prog->alter_gotos; aid; aid = aid->next) {
2619  if (aid->goto_id == l1->id) {
2620  break;
2621  }
2622  }
2623  if (!aid) {
2624  aid = cobc_parse_malloc (sizeof(struct cb_alter_id));
2625  aid->next = prog->alter_gotos;
2626  aid->goto_id = l1->id;
2627  prog->alter_gotos = aid;
2628  }
2629  }
2630 
2631  current_section = save_section;
2632  current_paragraph = save_paragraph;
2633  cobc_cs_check = 0;
2634 
2635  prog->file_list = cb_list_reverse (prog->file_list);
2636  prog->exec_list = cb_list_reverse (prog->exec_list);
2637 }
void cb_validate_program_data ( struct cb_program )
2284 {
2285  cb_tree l;
2286  cb_tree x;
2287  cb_tree assign;
2288  struct cb_field *p;
2289  struct cb_field *q;
2290  struct cb_field *depfld;
2291  struct cb_file *f;
2292  struct cb_report *rep;
2293  unsigned char *c;
2294  char buff[COB_MINI_BUFF];
2295 
2296  for (l = current_program->report_list; l; l = CB_CHAIN (l)) {
2297  /* Set up LINE-COUNTER / PAGE-COUNTER */
2298  rep = CB_REPORT (CB_VALUE (l));
2299  snprintf (buff, (size_t)COB_MINI_MAX,
2300  "LINE-COUNTER %s", rep->cname);
2301  x = cb_build_field (cb_build_reference (buff));
2302  CB_FIELD (x)->usage = CB_USAGE_UNSIGNED_INT;
2303  CB_FIELD (x)->values = CB_LIST_INIT (cb_zero);
2304  CB_FIELD (x)->count++;
2305  cb_validate_field (CB_FIELD (x));
2306  rep->line_counter = cb_build_field_reference (CB_FIELD (x), NULL);
2308  snprintf (buff, (size_t)COB_MINI_MAX,
2309  "PAGE-COUNTER %s", rep->cname);
2310  x = cb_build_field (cb_build_reference (buff));
2311  CB_FIELD (x)->usage = CB_USAGE_UNSIGNED_INT;
2312  CB_FIELD (x)->values = CB_LIST_INIT (cb_zero);
2313  CB_FIELD (x)->count++;
2314  cb_validate_field (CB_FIELD (x));
2315  rep->page_counter = cb_build_field_reference (CB_FIELD (x), NULL);
2317  }
2318 
2319  for (l = current_program->file_list; l; l = CB_CHAIN (l)) {
2320  f = CB_FILE (CB_VALUE (l));
2321  if (!f->flag_finalized) {
2322  finalize_file (f, NULL);
2323  }
2324  }
2325 
2326  /* Build undeclared assignment name now */
2327  if (cb_assign_clause == CB_ASSIGN_MF) {
2328  for (l = current_program->file_list; l; l = CB_CHAIN (l)) {
2329  assign = CB_FILE (CB_VALUE (l))->assign;
2330  if (!assign) {
2331  continue;
2332  }
2333  if (CB_REFERENCE_P (assign)) {
2334  for (x = current_program->file_list; x; x = CB_CHAIN (x)) {
2335  if (!strcmp (CB_FILE (CB_VALUE (x))->name,
2336  CB_NAME (assign))) {
2337  redefinition_error (assign);
2338  }
2339  }
2340  p = check_level_78 (CB_NAME (assign));
2341  if (p) {
2342  c = (unsigned char *)CB_LITERAL(CB_VALUE(p->values))->data;
2343  assign = CB_TREE (build_literal (CB_CATEGORY_ALPHANUMERIC, c, strlen ((char *)c)));
2344  CB_FILE (CB_VALUE (l))->assign = assign;
2345  }
2346  }
2347  if (CB_REFERENCE_P (assign) &&
2348  CB_WORD_COUNT (assign) == 0) {
2349  if (cb_warn_implicit_define) {
2350  cb_warning (_("'%s' will be implicitly defined"), CB_NAME (assign));
2351  }
2352  x = cb_build_implicit_field (assign, COB_SMALL_BUFF);
2353  CB_FIELD (x)->count++;
2355  if (p) {
2356  while (p->sister) {
2357  p = p->sister;
2358  }
2359  p->sister = CB_FIELD (x);
2360  } else {
2362  }
2363  }
2364  if (CB_REFERENCE_P (assign)) {
2365  x = cb_ref (assign);
2366  if (CB_FIELD_P (x) && CB_FIELD (x)->level == 88) {
2367  cb_error_x (assign, _("ASSIGN data item '%s' invalid"), CB_NAME (assign));
2368  }
2369  }
2370  }
2371  }
2372 
2373  if (prog->cursor_pos) {
2374  x = cb_ref (prog->cursor_pos);
2375  if (x == cb_error_node) {
2376  prog->cursor_pos = NULL;
2377  } else if (CB_FIELD(x)->size != 6 && CB_FIELD(x)->size != 4) {
2378  cb_error_x (prog->cursor_pos, _("'%s' CURSOR is not 4 or 6 characters long"),
2379  cb_name (prog->cursor_pos));
2380  prog->cursor_pos = NULL;
2381  }
2382  }
2383  if (prog->crt_status) {
2384  x = cb_ref (prog->crt_status);
2385  if (x == cb_error_node) {
2386  prog->crt_status = NULL;
2387  } else if (CB_FIELD(x)->size != 4) {
2388  cb_error_x (prog->crt_status, _("'%s' CRT STATUS is not 4 characters long"),
2389  cb_name (prog->crt_status));
2390  prog->crt_status = NULL;
2391  }
2392  } else {
2393  l = cb_build_reference ("COB-CRT-STATUS");
2394  p = CB_FIELD (cb_build_field (l));
2395  p->usage = CB_USAGE_DISPLAY;
2396  p->pic = CB_PICTURE (cb_build_picture ("9(4)"));
2397  cb_validate_field (p);
2398  p->flag_no_init = 1;
2399  /* Do not initialize/bump ref count here
2400  p->values = CB_LIST_INIT (cb_zero);
2401  p->count++;
2402  */
2404  prog->crt_status = l;
2405  }
2406 
2407  /* Resolve all references so far */
2408  for (l = cb_list_reverse (prog->reference_list); l; l = CB_CHAIN (l)) {
2409  cb_ref (CB_VALUE (l));
2410  }
2411 
2412  /* Check ODO items */
2413  for (l = cb_depend_check; l; l = CB_CHAIN (l)) {
2414  x = CB_VALUE(l);
2415  if (x == cb_error_node) {
2416  continue;
2417  }
2418  q = CB_FIELD_PTR (x);
2419  if (cb_ref (q->depending) != cb_error_node) {
2420  depfld = CB_FIELD_PTR (q->depending);
2421  } else {
2422  depfld = NULL;
2423  }
2424  /* The data item that contains a OCCURS DEPENDING clause must be
2425  the last data item in the group */
2426  for (p = q; p->parent; p = p->parent) {
2427  for (; p->sister; p = p->sister) {
2428  if (p->sister == depfld) {
2429  cb_error_x (x,
2430  _("'%s' ODO field item invalid here"),
2431  p->sister->name);
2432  }
2433  if (!p->sister->redefines) {
2434  if (!cb_complex_odo) {
2435  cb_error_x (x,
2436  _("'%s' cannot have OCCURS DEPENDING"),
2437  cb_name (x));
2438  break;
2439  }
2440  p->flag_odo_item = 1;
2441  }
2442  }
2443  }
2444  /* If the field is GLOBAL, then the ODO must also be GLOBAL */
2445  if (q->flag_is_global && depfld) {
2446  if (!depfld->flag_is_global) {
2447  cb_error_x (x, _("'%s' ODO item must have GLOBAL attribute"),
2448  depfld->name);
2449  }
2450  }
2451  }
2453  cb_needs_01 = 0;
2454 
2455  for (l = current_program->file_list; l; l = CB_CHAIN (l)) {
2456  f = CB_FILE (CB_VALUE (l));
2457  if (CB_VALID_TREE(f->record_depending)) {
2458  x = f->record_depending;
2459  if (cb_ref (x) != cb_error_node) {
2460 #if 0 /* RXWRXW - This breaks old legacy programs */
2461  if (CB_REF_OR_FIELD_P(x)) {
2462  p = CB_FIELD_PTR (x);
2463  switch (p->storage) {
2464  case CB_STORAGE_WORKING:
2465  case CB_STORAGE_LOCAL:
2466  case CB_STORAGE_LINKAGE:
2467  break;
2468  default:
2469  cb_error (_("RECORD DEPENDING item must be in WORKING/LOCAL/LINKAGE section"));
2470  }
2471  } else {
2472 #endif
2473  if (!CB_REF_OR_FIELD_P(x)) {
2474  cb_error (_("Invalid RECORD DEPENDING item"));
2475  }
2476  }
2477  }
2478  }
2479 }
void cb_validate_program_environment ( struct cb_program )
1831 {
1832  cb_tree x;
1833  cb_tree y;
1834  cb_tree l;
1835  cb_tree ls;
1836  struct cb_alphabet_name *ap;
1837  struct cb_class_name *cp;
1838  unsigned char *data;
1839  size_t dupls;
1840  size_t unvals;
1841  size_t count;
1842  int lower;
1843  int upper;
1844  int size;
1845  int n;
1846  int i;
1847  int lastval;
1848  int tableval;
1849  int values[256];
1850  int charvals[256];
1851 
1852  /* Check ALPHABET clauses */
1853  /* Complicated by difference between code set and collating sequence */
1854  for (l = current_program->alphabet_name_list; l; l = CB_CHAIN (l)) {
1855  ap = CB_ALPHABET_NAME (CB_VALUE (l));
1856 
1857  /* Native */
1858  if (ap->alphabet_type == CB_ALPHABET_NATIVE) {
1859  for (n = 0; n < 256; n++) {
1860  ap->values[n] = n;
1861  ap->alphachr[n] = n;
1862  }
1863  continue;
1864  }
1865 
1866  /* ASCII */
1867  if (ap->alphabet_type == CB_ALPHABET_ASCII) {
1868  for (n = 0; n < 256; n++) {
1869 #ifdef COB_EBCDIC_MACHINE
1870  ap->values[n] = (int)cob_refer_ascii[n];
1871  ap->alphachr[n] = (int)cob_refer_ascii[n];
1872 #else
1873  ap->values[n] = n;
1874  ap->alphachr[n] = n;
1875 #endif
1876  }
1877  continue;
1878  }
1879 
1880  /* EBCDIC */
1881  if (ap->alphabet_type == CB_ALPHABET_EBCDIC) {
1882  for (n = 0; n < 256; n++) {
1883 #ifdef COB_EBCDIC_MACHINE
1884  ap->values[n] = n;
1885  ap->alphachr[n] = n;
1886 #else
1887  ap->values[n] = (int)cob_refer_ebcdic[n];
1888  ap->alphachr[n] = (int)cob_refer_ebcdic[n];
1889 #endif
1890  }
1891  continue;
1892  }
1893 
1894  /* Custom alphabet */
1895  dupls = 0;
1896  unvals = 0;
1897  count = 0;
1898  lastval = 0;
1899  tableval = 0;
1900  for (n = 0; n < 256; n++) {
1901  values[n] = -1;
1902  charvals[n] = -1;
1903  ap->values[n] = -1;
1904  ap->alphachr[n] = -1;
1905  }
1906  ap->low_val_char = 0;
1907  ap->high_val_char = 255;
1908  for (y = ap->custom_list; y; y = CB_CHAIN (y)) {
1909  if (count > 255) {
1910  unvals = 1;
1911  break;
1912  }
1913  x = CB_VALUE (y);
1914  if (CB_PAIR_P (x)) {
1915  /* X THRU Y */
1916  lower = get_value (CB_PAIR_X (x));
1917  upper = get_value (CB_PAIR_Y (x));
1918  lastval = upper;
1919  if (!count) {
1920  ap->low_val_char = lower;
1921  }
1922  if (lower < 0 || lower > 255) {
1923  unvals = 1;
1924  continue;
1925  }
1926  if (upper < 0 || upper > 255) {
1927  unvals = 1;
1928  continue;
1929  }
1930  if (lower <= upper) {
1931  for (i = lower; i <= upper; i++) {
1932  if (values[i] != -1) {
1933  dupls = 1;
1934  }
1935  values[i] = i;
1936  charvals[i] = i;
1937  ap->alphachr[tableval] = i;
1938  ap->values[i] = tableval++;
1939  count++;
1940  }
1941  } else {
1942  for (i = lower; i >= upper; i--) {
1943  if (values[i] != -1) {
1944  dupls = 1;
1945  }
1946  values[i] = i;
1947  charvals[i] = i;
1948  ap->alphachr[tableval] = i;
1949  ap->values[i] = tableval++;
1950  count++;
1951  }
1952  }
1953  } else if (CB_LIST_P (x)) {
1954  /* X ALSO Y ... */
1955  if (!count) {
1956  ap->low_val_char = get_value (CB_VALUE (x));
1957  }
1958  for (ls = x; ls; ls = CB_CHAIN (ls)) {
1959  n = get_value (CB_VALUE (ls));
1960  if (!CB_CHAIN (ls)) {
1961  lastval = n;
1962  }
1963  if (n < 0 || n > 255) {
1964  unvals = 1;
1965  continue;
1966  }
1967  if (values[n] != -1) {
1968  dupls = 1;
1969  }
1970  values[n] = n;
1971  ap->values[n] = tableval;
1972  if (ls == x) {
1973  ap->alphachr[tableval] = n;
1974  charvals[n] = n;
1975  }
1976  count++;
1977  }
1978  tableval++;
1979  } else {
1980  /* Literal */
1981  if (CB_NUMERIC_LITERAL_P (x)) {
1982  n = get_value (x);
1983  lastval = n;
1984  if (!count) {
1985  ap->low_val_char = n;
1986  }
1987  if (n < 0 || n > 255) {
1988  unvals = 1;
1989  continue;
1990  }
1991  if (values[n] != -1) {
1992  dupls = 1;
1993  }
1994  values[n] = n;
1995  charvals[n] = n;
1996  ap->alphachr[tableval] = n;
1997  ap->values[n] = tableval++;
1998  count++;
1999  } else if (CB_LITERAL_P (x)) {
2000  size = (int)CB_LITERAL (x)->size;
2001  data = CB_LITERAL (x)->data;
2002  if (!count) {
2003  ap->low_val_char = data[0];
2004  }
2005  lastval = data[size - 1];
2006  for (i = 0; i < size; i++) {
2007  n = data[i];
2008  if (values[n] != -1) {
2009  dupls = 1;
2010  }
2011  values[n] = n;
2012  charvals[n] = n;
2013  ap->alphachr[tableval] = n;
2014  ap->values[n] = tableval++;
2015  count++;
2016  }
2017  } else {
2018  n = get_value (x);
2019  lastval = n;
2020  if (!count) {
2021  ap->low_val_char = n;
2022  }
2023  if (n < 0 || n > 255) {
2024  unvals = 1;
2025  continue;
2026  }
2027  if (values[n] != -1) {
2028  dupls = 1;
2029  }
2030  values[n] = n;
2031  charvals[n] = n;
2032  ap->alphachr[tableval] = n;
2033  ap->values[n] = tableval++;
2034  count++;
2035  }
2036  }
2037  }
2038  if (dupls || unvals) {
2039  if (dupls) {
2040  cb_error_x (l, _("Duplicate character values in alphabet '%s'"),
2041  cb_name (CB_VALUE(l)));
2042  }
2043  if (unvals) {
2044  cb_error_x (l, _("Invalid character values in alphabet '%s'"),
2045  cb_name (CB_VALUE(l)));
2046  }
2047  ap->low_val_char = 0;
2048  ap->high_val_char = 255;
2049  continue;
2050  }
2051  /* Calculate HIGH-VALUE */
2052  /* If all 256 values have been specified, */
2053  /* HIGH-VALUE is the last one */
2054  /* Otherwise if HIGH-VALUE has been specified, find the highest */
2055  /* value that has not been used */
2056  if (count == 256) {
2057  ap->high_val_char = lastval;
2058  } else if (values[255] != -1) {
2059  for (n = 254; n >= 0; n--) {
2060  if (values[n] == -1) {
2061  ap->high_val_char = n;
2062  break;
2063  }
2064  }
2065  }
2066 
2067  /* Get rest of code set */
2068  for (n = tableval; n < 256; ++n) {
2069  for (i = 0; i < 256; ++i) {
2070  if (charvals[i] < 0) {
2071  charvals[i] = 0;
2072  ap->alphachr[n] = i;
2073  break;
2074  }
2075  }
2076  }
2077 
2078  /* Fill in missing characters */
2079  for (n = 0; n < 256; n++) {
2080  if (ap->values[n] < 0) {
2081  ap->values[n] = tableval++;
2082  }
2083  }
2084  }
2085 
2086  /* Reset HIGH/LOW-VALUES */
2087  cb_low = cb_norm_low;
2089 
2090  /* Check and generate SYMBOLIC clauses */
2091  for (l = current_program->symbolic_char_list; l; l = CB_CHAIN (l)) {
2092  if (CB_VALUE (l)) {
2093  y = cb_ref (CB_VALUE (l));
2094  if (y == cb_error_node) {
2095  continue;
2096  }
2097  if (!CB_ALPHABET_NAME_P (y)) {
2098  cb_error_x (y, _("Invalid ALPHABET name"));
2099  continue;
2100  }
2101  } else {
2102  y = NULL;
2103  }
2104  cb_build_symbolic_chars (CB_PURPOSE (l), y);
2105  }
2106 
2107  /* Check CLASS clauses */
2108  for (l = current_program->class_name_list; l; l = CB_CHAIN (l)) {
2109  dupls = 0;
2110  memset (values, 0, sizeof(values));
2111  cp = CB_CLASS_NAME (CB_VALUE (l));
2112  for (y = cp->list; y; y = CB_CHAIN (y)) {
2113  x = CB_VALUE (y);
2114  if (CB_PAIR_P (x)) {
2115  /* X THRU Y */
2116  lower = get_value (CB_PAIR_X (x));
2117  upper = get_value (CB_PAIR_Y (x));
2118  for (i = lower; i <= upper; i++) {
2119  if (values[i]) {
2120  dupls = 1;
2121  }
2122  values[i] = 1;
2123  }
2124  } else {
2125  if (CB_NUMERIC_LITERAL_P (x)) {
2126  n = get_value (x);
2127  if (values[n]) {
2128  dupls = 1;
2129  }
2130  values[n] = 1;
2131  } else if (CB_LITERAL_P (x)) {
2132  size = (int)CB_LITERAL (x)->size;
2133  data = CB_LITERAL (x)->data;
2134  for (i = 0; i < size; i++) {
2135  n = data[i];
2136  if (values[n]) {
2137  dupls = 1;
2138  }
2139  values[n] = 1;
2140  }
2141  } else {
2142  n = get_value (x);
2143  if (values[n]) {
2144  dupls = 1;
2145  }
2146  values[n] = 1;
2147  }
2148  }
2149  }
2150  if (dupls) {
2151  if (!cb_relaxed_syntax_check) {
2152  cb_error_x (CB_VALUE(l),
2153  _("Duplicate values in class '%s'"),
2154  cb_name (CB_VALUE(l)));
2155  } else {
2156  cb_warning_x (CB_VALUE(l),
2157  _("Duplicate values in class '%s'"),
2158  cb_name (CB_VALUE(l)));
2159  }
2160  }
2161  }
2162 
2163  /* Resolve the program collating sequence */
2164  if (prog->collating_sequence) {
2165  cb_validate_collating (prog);
2166  }
2167 
2168  /* Resolve the program classification */
2169  if (prog->classification && prog->classification != cb_int1) {
2170  x = cb_ref (prog->classification);
2171  if (!CB_LOCALE_NAME_P (x)) {
2172  cb_error_x (prog->classification,
2173  _("'%s' is not a locale name"),
2174  cb_name (prog->classification));
2175  prog->classification = NULL;
2176  return;
2177  }
2178  }
2179 }
unsigned int cb_verify ( const enum  cb_support,
const char *   
)

References _, CB_ARCHAIC, CB_ERROR, cb_error(), CB_IGNORE, CB_OBSOLETE, CB_OK, CB_SKIP, CB_UNCONFORMABLE, CB_WARNING, cb_warning(), and warningopt.

Referenced by cb_emit_goto(), check_comments(), compute_size(), validate_field_1(), and while().

198 {
199  switch (tag) {
200  case CB_OK:
201  return 1;
202  case CB_WARNING:
203  return 1;
204  case CB_ARCHAIC:
205  if (cb_warn_archaic) {
206  cb_warning (_("%s is archaic in %s"), feature, cb_config_name);
207  }
208  return 1;
209  case CB_OBSOLETE:
210  if (cb_warn_obsolete) {
211  cb_warning (_("%s is obsolete in %s"), feature, cb_config_name);
212  }
213  return 1;
214  case CB_SKIP:
215  return 0;
216  case CB_IGNORE:
217  if (warningopt) {
218  cb_warning (_("%s ignored"), feature);
219  }
220  return 0;
221  case CB_ERROR:
222  return 0;
223  case CB_UNCONFORMABLE:
224  cb_error (_("%s does not conform to %s"), feature, cb_config_name);
225  return 0;
226  default:
227  break;
228  }
229  return 0;
230 }
void cb_warning ( const char *  ,
  ... 
)
void cb_warning_x ( cb_tree  ,
const char *  ,
  ... 
)
174 {
175  va_list ap;
176 
177  va_start (ap, fmt);
178  print_error (x->source_file, x->source_line, _("Warning: "), fmt, ap);
179  va_end (ap);
180  warningcount++;
181 }
struct cb_field* check_level_78 ( const char *  name)
read

References cb_level_78::fld78, cb_field::name, cb_level_78::next, and NULL.

Referenced by cb_validate_program_data().

1741 {
1742  const struct cb_level_78 *p78;
1743 
1744  /* Check against a current constant (78 level) */
1745  for (p78 = lev78ptr; p78; p78 = p78->next) {
1746  if (strcasecmp (name, p78->fld78->name) == 0) {
1747  return p78->fld78;
1748  }
1749  }
1750  /* Check against a global constant (78 level) */
1751  for (p78 = globlev78ptr; p78; p78 = p78->next) {
1752  if (strcasecmp (name, p78->fld78->name) == 0) {
1753  return p78->fld78;
1754  }
1755  }
1756  return NULL;
1757 }
COB_EXPIMP void cob_accept ( cob_field )
283 {
284  unsigned char *p;
285  size_t size;
286  int ipchr;
287  cob_field temp;
288 
292  return;
293  }
294  if (COB_MODULE_PTR->crt_status) {
295  if (COB_FIELD_IS_NUMERIC (COB_MODULE_PTR->crt_status)) {
296  cob_set_int (COB_MODULE_PTR->crt_status, 0);
297  } else {
298  memset (COB_MODULE_PTR->crt_status->data, '0', (size_t)4);
299  }
300  }
301  /* extension: ACCEPT OMITTED */
302  if (unlikely(!f)) {
303  for (; ; ) {
304  ipchr = getchar ();
305  if (ipchr == '\n' || ipchr == EOF) {
306  break;
307  }
308  }
309  return;
310  }
311  p = COB_TERM_BUFF;
312  temp.data = p;
313  temp.attr = &const_alpha_attr;
314  size = 0;
315  /* Read a line */
316  for (; size < COB_MEDIUM_MAX; ) {
317  ipchr = getchar ();
318  if (unlikely(ipchr == EOF)) {
320  if (!size) {
321  size = 1;
322  p[0] = ' ';
323  p[1] = 0;
324  }
325  break;
326  } else if (ipchr == '\n') {
327  break;
328  }
329  p[size++] = (char) ipchr;
330  }
331  temp.size = size;
333  if (temp.size > f->size) {
334  temp.size = f->size;
335  }
336  }
337  cob_move (&temp, f);
338 }
COB_EXPIMP void cob_accept_arg_number ( cob_field )
2590 {
2591  int n;
2592  cob_field_attr attr;
2593  cob_field temp;
2594 
2595  n = cob_argc - 1;
2596  temp.size = 4;
2597  temp.data = (unsigned char *)&n;
2598  temp.attr = &attr;
2599  COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0, 0, NULL);
2600  cob_move (&temp, f);
2601 }
COB_EXPIMP void cob_accept_arg_value ( cob_field )
2605 {
2606  if (current_arg >= cob_argc) {
2608  return;
2609  }
2611  strlen (cob_argv[current_arg]));
2612  current_arg++;
2613 }
COB_EXPIMP void cob_accept_command_line ( cob_field )
2526 {
2527  char *buff;
2528  size_t i;
2529  size_t size;
2530  size_t len;
2531 
2532  if (commlncnt) {
2534  return;
2535  }
2536 
2537  if (cob_argc <= 1) {
2538  cob_memcpy (f, " ", (size_t)1);
2539  return;
2540  }
2541 
2542  size = 0;
2543  for (i = 1; i < (size_t)cob_argc; ++i) {
2544  size += (strlen (cob_argv[i]) + 1);
2545  if (size > f->size) {
2546  break;
2547  }
2548  }
2549  buff = cob_malloc (size);
2550  buff[0] = ' ';
2551  size = 0;
2552  for (i = 1; i < (size_t)cob_argc; ++i) {
2553  len = strlen (cob_argv[i]);
2554  memcpy (buff + size, cob_argv[i], len);
2555  size += len;
2556  if (i != (size_t)cob_argc - 1U) {
2557  buff[size++] = ' ';
2558  }
2559  if (size > f->size) {
2560  break;
2561  }
2562  }
2563  cob_memcpy (f, buff, size);
2564  cob_free (buff);
2565 }
COB_EXPIMP void cob_accept_date ( cob_field )
2414 {
2415  time_t t;
2416  char s[8];
2417 
2418  t = time (NULL);
2419  strftime (s, (size_t)7, "%y%m%d", localtime (&t));
2420  cob_memcpy (f, s, (size_t)6);
2421 }
COB_EXPIMP void cob_accept_date_yyyymmdd ( cob_field )
2425 {
2426  time_t t;
2427  char s[12];
2428 
2429  t = time (NULL);
2430  strftime (s, (size_t)9, "%Y%m%d", localtime (&t));
2431  cob_memcpy (f, s, (size_t)8);
2432 }
COB_EXPIMP void cob_accept_day ( cob_field )
2436 {
2437  time_t t;
2438  char s[8];
2439 
2440  t = time (NULL);
2441  strftime (s, (size_t)6, "%y%j", localtime (&t));
2442  cob_memcpy (f, s, (size_t)5);
2443 }
COB_EXPIMP void cob_accept_day_of_week ( cob_field )
2458 {
2459  struct tm *tm;
2460  time_t t;
2461  unsigned char s[4];
2462 
2463  t = time (NULL);
2464  tm = localtime (&t);
2465  if (tm->tm_wday == 0) {
2466  s[0] = (unsigned char)'7';
2467  } else {
2468  s[0] = (unsigned char)(tm->tm_wday + '0');
2469  }
2470  cob_memcpy (f, s, (size_t)1);
2471 }
COB_EXPIMP void cob_accept_day_yyyyddd ( cob_field )
2447 {
2448  time_t t;
2449  char s[12];
2450 
2451  t = time (NULL);
2452  strftime (s, (size_t)8, "%Y%j", localtime (&t));
2453  cob_memcpy (f, s, (size_t)7);
2454 }
COB_EXPIMP void cob_accept_environment ( cob_field )
2715 {
2716  const char *p = NULL;
2717 
2718  if (cob_local_env) {
2719  p = getenv (cob_local_env);
2720  }
2721  if (!p) {
2723  p = " ";
2724  }
2725  cob_memcpy (f, p, strlen (p));
2726 }
COB_EXPIMP void cob_accept_escape_key ( cob_field )
1777 {
1779 }
COB_EXPIMP void cob_accept_exception_status ( cob_field )
1106 {
1108 }
COB_EXPIMP void cob_accept_time ( cob_field )
2475 {
2476 #ifdef _WIN32
2477  SYSTEMTIME syst;
2478 #else
2479  struct tm *tlt;
2480  time_t t;
2481 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2482  struct timeval tmv;
2483  char buff2[8];
2484 #endif
2485 #endif
2486  char s[12];
2487 
2488 #ifdef _WIN32
2489  GetLocalTime (&syst);
2490  sprintf (s, "%2.2d%2.2d%2.2d%2.2d", syst.wHour, syst.wMinute,
2491  syst.wSecond, syst.wMilliseconds / 10);
2492 #else
2493 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2494  gettimeofday (&tmv, NULL);
2495  t = tmv.tv_sec;
2496 #else
2497  t = time (NULL);
2498 #endif
2499  tlt = localtime (&t);
2500  /* Leap seconds ? */
2501  if (tlt->tm_sec >= 60) {
2502  tlt->tm_sec = 59;
2503  }
2504  strftime (s, (size_t)9, "%H%M%S00", tlt);
2505 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2506  sprintf(buff2, "%2.2ld", (long int)(tmv.tv_usec / 10000));
2507  memcpy (&s[6], buff2, (size_t)2);
2508 #endif
2509 #endif
2510  cob_memcpy (f, s, (size_t)8);
2511 }
COB_EXPIMP void cob_accept_user_name ( cob_field )
1112 {
1113  if (cob_user_name) {
1115  strlen (cob_user_name));
1116  } else {
1117  cob_memcpy (f, " ", (size_t)1);
1118  }
1119 }
COB_EXPIMP void cob_add ( cob_field ,
cob_field ,
const int   
)
1932 {
1936  (void)cob_decimal_get_field (&cob_d1, f1, opt);
1937 }
COB_EXPIMP int cob_add_int ( cob_field ,
const int  ,
const int   
)
2196 {
2197  int scale;
2198  int val;
2199 
2200  if (unlikely(n == 0)) {
2201  return 0;
2202  }
2203 #if 0 /* RXWRXW - Buggy */
2204  if (COB_FIELD_TYPE (f) == COB_TYPE_NUMERIC_PACKED) {
2205  return cob_add_packed (f, n, opt);
2206  } else if (COB_FIELD_TYPE (f) == COB_TYPE_NUMERIC_DISPLAY) {
2207  return cob_display_add_int (f, n, opt);
2208  }
2209 #endif
2210 
2211  /* Not optimized */
2213 
2214  if (COB_FIELD_TYPE (f) >= COB_TYPE_NUMERIC_FLOAT
2215  && COB_FIELD_TYPE (f) <= COB_TYPE_NUMERIC_FP_BIN128) {
2216  mpz_set_si (cob_d2.value, (cob_sli_t) n);
2217  cob_d2.scale = 0;
2218  mpz_add (cob_d1.value, cob_d1.value, cob_d2.value);
2219  return cob_decimal_get_field (&cob_d1, f, opt);
2220  }
2221  else {
2222  scale = COB_FIELD_SCALE (f);
2223  val = n;
2224  if (unlikely(scale < 0)) {
2225  /* PIC 9(n)P(m) */
2226  if (-scale < 10) {
2227  while (scale++) {
2228  val /= 10;
2229  }
2230  } else {
2231  val = 0;
2232  }
2233  scale = 0;
2234  if (!val) {
2235  return 0;
2236  }
2237  }
2238  mpz_set_si (cob_d2.value, (cob_sli_t)val);
2239  cob_d2.scale = 0;
2240  if (scale > 0) {
2241  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)scale);
2242  mpz_mul (cob_d2.value, cob_d2.value, cob_mexp);
2244  }
2245  mpz_add (cob_d1.value, cob_d1.value, cob_d2.value);
2246  return cob_decimal_get_field (&cob_d1, f, opt);
2247  }
2248 }
COB_EXPIMP void cob_allocate ( unsigned char **  ,
cob_field ,
cob_field ,
cob_field  
)
2750 {
2751  void *mptr;
2752  struct cob_alloc_cache *cache_ptr;
2753  int fsize;
2754  cob_field temp;
2755 
2756  /* ALLOCATE */
2758  mptr = NULL;
2759  fsize = cob_get_int (sizefld);
2760  if (fsize > 0) {
2761  cache_ptr = cob_malloc (sizeof (struct cob_alloc_cache));
2762  mptr = malloc ((size_t)fsize);
2763  if (!mptr) {
2764  cob_set_exception (COB_EC_STORAGE_NOT_AVAIL);
2765  cob_free (cache_ptr);
2766  } else {
2767  if (initialize) {
2768  temp.size = (size_t)fsize;
2769  temp.data = mptr;
2770  temp.attr = &const_alpha_attr;
2771  cob_move (initialize, &temp);
2772  } else {
2773  memset (mptr, 0, (size_t)fsize);
2774  }
2775  cache_ptr->cob_pointer = mptr;
2776  cache_ptr->size = (size_t)fsize;
2777  cache_ptr->next = cob_alloc_base;
2778  cob_alloc_base = cache_ptr;
2779  }
2780  }
2781  if (dataptr) {
2782  *dataptr = mptr;
2783  }
2784  if (retptr) {
2785  *(void **)(retptr->data) = mptr;
2786  }
2787 }
COB_EXPIMP void cob_cache_free ( void *  )
1213 {
1214  struct cob_alloc_cache *cache_ptr;
1215  struct cob_alloc_cache *prev_ptr;
1216 
1217  if (!ptr) {
1218  return;
1219  }
1220  cache_ptr = cob_alloc_base;
1221  prev_ptr = cob_alloc_base;
1222  for (; cache_ptr; cache_ptr = cache_ptr->next) {
1223  if (ptr == cache_ptr->cob_pointer) {
1224  cob_free (cache_ptr->cob_pointer);
1225  if (cache_ptr == cob_alloc_base) {
1226  cob_alloc_base = cache_ptr->next;
1227  } else {
1228  prev_ptr->next = cache_ptr->next;
1229  }
1230  cob_free (cache_ptr);
1231  return;
1232  }
1233  prev_ptr = cache_ptr;
1234  }
1235 }
COB_EXPIMP void* cob_cache_malloc ( const size_t  )
1172 {
1173  struct cob_alloc_cache *cache_ptr;
1174  void *mptr;
1175 
1176  cache_ptr = cob_malloc (sizeof (struct cob_alloc_cache));
1177  mptr = cob_malloc (size);
1178  cache_ptr->cob_pointer = mptr;
1179  cache_ptr->size = size;
1180  cache_ptr->next = cob_alloc_base;
1181  cob_alloc_base = cache_ptr;
1182  return mptr;
1183 }
COB_EXPIMP void* cob_cache_realloc ( void *  ,
const size_t   
)
1187 {
1188  struct cob_alloc_cache *cache_ptr;
1189  void *mptr;
1190 
1191  if (!ptr) {
1192  return cob_cache_malloc (size);
1193  }
1194  cache_ptr = cob_alloc_base;
1195  for (; cache_ptr; cache_ptr = cache_ptr->next) {
1196  if (ptr == cache_ptr->cob_pointer) {
1197  if (size <= cache_ptr->size) {
1198  return ptr;
1199  }
1200  mptr = cob_malloc (size);
1201  memcpy (mptr, cache_ptr->cob_pointer, cache_ptr->size);
1202  cob_free (cache_ptr->cob_pointer);
1203  cache_ptr->cob_pointer = mptr;
1204  cache_ptr->size = size;
1205  return mptr;
1206  }
1207  }
1208  return ptr;
1209 }
COB_EXPIMP int cob_call ( const char *  ,
const int  ,
void **   
)
1088 {
1089  void **pargv;
1090  cob_call_union unifunc;
1091  int i;
1092 
1093  if (unlikely(!cobglobptr)) {
1094  cob_fatal_error (COB_FERROR_INITIALIZED);
1095  }
1096  if (argc < 0 || argc > COB_MAX_FIELD_PARAMS) {
1097  cob_runtime_error (_("Invalid number of arguments to 'cob_call'"));
1098  cob_stop_run (1);
1099  }
1100  if (unlikely(!name)) {
1101  cob_runtime_error (_("NULL name parameter passed to 'cob_call'"));
1102  cob_stop_run (1);
1103  }
1104  unifunc.funcvoid = cob_resolve_cobol (name, 0, 1);
1105  pargv = cob_malloc (COB_MAX_FIELD_PARAMS * sizeof(void *));
1106  /* Set number of parameters */
1107  cobglobptr->cob_call_params = argc;
1108  for (i = 0; i < argc; ++i) {
1109  pargv[i] = argv[i];
1110  }
1111  i = unifunc.funcint (pargv[0], pargv[1], pargv[2], pargv[3],
1112  pargv[4], pargv[5], pargv[6], pargv[7],
1113  pargv[8], pargv[9], pargv[10], pargv[11],
1114 #if COB_MAX_FIELD_PARAMS == 16
1115  pargv[12], pargv[13], pargv[14], pargv[15]);
1116 #elif COB_MAX_FIELD_PARAMS == 36
1117  pargv[12], pargv[13], pargv[14], pargv[15],
1118  pargv[16], pargv[17], pargv[18], pargv[19],
1119  pargv[20], pargv[21], pargv[22], pargv[23],
1120  pargv[24], pargv[25], pargv[26], pargv[27],
1121  pargv[28], pargv[29], pargv[30], pargv[31],
1122  pargv[32], pargv[33], pargv[34], pargv[35]);
1123 #else
1124 #error "Invalid COB_MAX_FIELD_PARAMS value"
1125 #endif
1126  cob_free (pargv);
1127  return i;
1128 }
DECLNORET COB_EXPIMP void cob_call_error ( void  )
886 {
888  cob_stop_run (1);
889 }
COB_EXPIMP void* cob_call_field ( const cob_field ,
const struct cob_call_struct ,
const unsigned  int,
const int   
)
966 {
967  void *p;
968  const struct cob_call_struct *s;
969  const struct system_table *psyst;
970  char *buff;
971  char *entry;
972  char *dirent;
973 
974  if (unlikely(!cobglobptr)) {
975  cob_fatal_error (COB_FERROR_INITIALIZED);
976  }
977 
978  buff = cob_get_buff (f->size + 1);
979  cob_field_to_string (f, buff, f->size);
980 
981  entry = cob_chk_call_path (buff, &dirent);
982 
983  /* Check if system routine */
984  for (psyst = system_tab; psyst->syst_name; ++psyst) {
985  if (!strcmp (entry, psyst->syst_name)) {
986  if (dirent) {
987  cob_free (dirent);
988  }
989  return psyst->syst_call.funcvoid;
990  }
991  }
992 
993 
994  /* Check if contained program */
995  for (s = cs; s && s->cob_cstr_name; s++) {
996  if (!strcmp (entry, s->cob_cstr_name)) {
997  if (dirent) {
998  cob_free (dirent);
999  }
1000  return s->cob_cstr_call.funcvoid;
1001  }
1002  }
1003 
1004  p = cob_resolve_internal (entry, dirent, fold_case);
1005  if (dirent) {
1006  cob_free (dirent);
1007  }
1008  if (unlikely(!p)) {
1009  if (errind) {
1010  cob_call_error ();
1011  } else {
1012  cob_set_exception (COB_EC_PROGRAM_NOT_FOUND);
1013  return NULL;
1014  }
1015  }
1016  return p;
1017 }
COB_EXPIMP void cob_cancel ( const char *  )
1021 {
1022  const char *entry;
1023  struct call_hash *p;
1024  struct call_hash **q;
1025  struct call_hash *r;
1026 
1027  if (unlikely(!cobglobptr)) {
1028  cob_fatal_error (COB_FERROR_INITIALIZED);
1029  }
1030  if (unlikely(!name)) {
1031  cob_runtime_error (_("NULL parameter passed to 'cob_cancel'"));
1032  cob_stop_run (1);
1033  }
1034  entry = cob_chk_dirp (name);
1035 
1036 #ifdef COB_ALT_HASH
1037  q = &call_table;
1038  p = *q;
1039 #else
1040  q = &call_table[hash ((const unsigned char *)entry)];
1041  p = *q;
1042 #endif
1043  r = NULL;
1044  for (; p; p = p->next) {
1045  if (strcmp (entry, p->name) == 0) {
1046  do_cancel_module (p, q, r);
1047  return;
1048  }
1049  r = p;
1050  }
1051 }
COB_EXPIMP void cob_cancel_field ( const cob_field ,
const struct cob_call_struct  
)
1055 {
1056  char *name;
1057  const char *entry;
1058  const struct cob_call_struct *s;
1059 
1060  int (*cancel_func)(const int, void *, void *, void *, void *);
1061 
1062  if (unlikely(!cobglobptr)) {
1063  cob_fatal_error (COB_FERROR_INITIALIZED);
1064  }
1065  if (!f || f->size == 0) {
1066  return;
1067  }
1068  name = cob_get_buff (f->size + 1);
1069  cob_field_to_string (f, name, f->size);
1070  entry = cob_chk_dirp (name);
1071 
1072  /* Check if contained program */
1073  for (s = cs; s && s->cob_cstr_name; s++) {
1074  if (!strcmp (entry, s->cob_cstr_name)) {
1075  if (s->cob_cstr_cancel.funcvoid) {
1076  cancel_func = s->cob_cstr_cancel.funcint;
1077  (void)cancel_func (-1, NULL, NULL, NULL,
1078  NULL);
1079  }
1080  return;
1081  }
1082  }
1083  cob_cancel (entry);
1084 }
COB_EXPIMP void cob_chain_setup ( void *  ,
const size_t  ,
const size_t   
)
2730 {
2731  size_t len;
2732 
2733  memset (data, ' ', size);
2734  if (parm <= (size_t)cob_argc - 1) {
2735  len = strlen (cob_argv[parm]);
2736  if (len <= size) {
2737  memcpy (data, cob_argv[parm], len);
2738  } else {
2739  memcpy (data, cob_argv[parm], size);
2740  }
2741  } else {
2742  memset (data, ' ', size);
2743  }
2745 }
COB_EXPIMP void cob_check_based ( const unsigned char *  ,
const char *   
)
2306 {
2307  if (!x) {
2308  cob_runtime_error (_("BASED/LINKAGE item '%s' has NULL address"), name);
2309  cob_stop_run (1);
2310  }
2311 }
COB_EXPIMP void cob_check_numeric ( const cob_field ,
const char *   
)
2315 {
2316  unsigned char *data;
2317  char *p;
2318  char *buff;
2319  size_t i;
2320 
2321  if (!cob_is_numeric (f)) {
2322  buff = cob_fast_malloc ((size_t)COB_SMALL_BUFF);
2323  p = buff;
2324  data = f->data;
2325  for (i = 0; i < f->size; ++i) {
2326  if (isprint (data[i])) {
2327  *p++ = data[i];
2328  } else {
2329  p += sprintf (p, "\\%03o", data[i]);
2330  }
2331  }
2332  *p = '\0';
2333  cob_runtime_error (_("'%s' not numeric: '%s'"), name, buff);
2334  cob_free (buff);
2335  cob_stop_run (1);
2336  }
2337 }
COB_EXPIMP void cob_check_odo ( const int  ,
const int  ,
const int  ,
const char *   
)
2342 {
2343  /* Check OCCURS DEPENDING ON item */
2344  if (i < min || max < i) {
2346  cob_runtime_error (_("OCCURS DEPENDING ON '%s' out of bounds: %d"), name, i);
2347  cob_stop_run (1);
2348  }
2349 }
COB_EXPIMP void cob_check_ref_mod ( const int  ,
const int  ,
const int  ,
const char *   
)
2366 {
2367  /* Check offset */
2368  if (offset < 1 || offset > size) {
2369  cob_set_exception (COB_EC_BOUND_REF_MOD);
2370  cob_runtime_error (_("Offset of '%s' out of bounds: %d"), name, offset);
2371  cob_stop_run (1);
2372  }
2373 
2374  /* Check length */
2375  if (length < 1 || offset + length - 1 > size) {
2376  cob_set_exception (COB_EC_BOUND_REF_MOD);
2377  cob_runtime_error (_("Length of '%s' out of bounds: %d"), name, length);
2378  cob_stop_run (1);
2379  }
2380 }
COB_EXPIMP void cob_check_subscript ( const int  ,
const int  ,
const int  ,
const char *   
)
2354 {
2355  /* Check subscript */
2356  if (i < min || max < i) {
2357  cob_set_exception (COB_EC_BOUND_SUBSCRIPT);
2358  cob_runtime_error (_("Subscript of '%s' out of bounds: %d"), name, i);
2359  cob_stop_run (1);
2360  }
2361 }
COB_EXPIMP void cob_check_version ( const char *  ,
const char *  ,
const int   
)
1675 {
1676  if (strcmp (packver, PACKAGE_VERSION) || patchlev != PATCH_LEVEL) {
1677  cob_runtime_error (_("Error - Version mismatch"));
1678  cob_runtime_error (_("%s has version/patch level %s/%d"), prog,
1679  packver, patchlev);
1680  cob_runtime_error (_("Library has version/patch level %s/%d"),
1682  cob_stop_run (1);
1683  }
1684 }
COB_EXPIMP void cob_close ( cob_file ,
cob_field ,
const int  ,
const int   
)
4518 {
4519  struct file_list *l;
4520  struct file_list *m;
4521  int ret;
4522 
4523  f->flag_read_done = 0;
4524  f->flag_operation = 0;
4525 
4526  f->lock_mode &= ~COB_LOCK_OPEN_EXCLUSIVE;
4527 
4528  if (COB_FILE_SPECIAL (f)) {
4529  f->open_mode = COB_OPEN_CLOSED;
4530  f->file = NULL;
4531  f->fd = -1;
4532  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
4533  return;
4534  }
4535 
4536  if (unlikely(remfil)) {
4537  /* Remove from cache - Needed for CANCEL */
4538  /* Setting m silences false compiler warning */
4539  m = file_cache;
4540  for (l = file_cache; l; l = l->next) {
4541  if (f == l->file) {
4542  if (l == file_cache) {
4543  file_cache = l->next;
4544  } else {
4545  m->next = l->next;
4546  }
4547  cob_free (l);
4548  break;
4549  }
4550  m = l;
4551  }
4552  }
4553 
4554  if (f->open_mode == COB_OPEN_CLOSED) {
4555  save_status (f, fnstatus, COB_STATUS_42_NOT_OPEN);
4556  return;
4557  }
4558 
4559  if (f->flag_nonexistent) {
4560  ret = COB_STATUS_00_SUCCESS;
4561  } else {
4562  ret = fileio_funcs[(int)f->organization]->close (f, opt);
4563  }
4564 
4565  if (ret == COB_STATUS_00_SUCCESS) {
4566  switch (opt) {
4567  case COB_CLOSE_LOCK:
4568  f->open_mode = COB_OPEN_LOCKED;
4569  break;
4570  default:
4571  f->open_mode = COB_OPEN_CLOSED;
4572  break;
4573  }
4574  }
4575 
4576  save_status (f, fnstatus, ret);
4577 }
COB_EXPIMP int cob_cmp ( cob_field ,
cob_field  
)
2099 {
2100  cob_field temp;
2101  cob_field_attr attr;
2102  unsigned char buff[256];
2103 
2104  if (COB_FIELD_IS_NUMERIC (f1) && COB_FIELD_IS_NUMERIC (f2)) {
2105  return cob_numeric_cmp (f1, f2);
2106  }
2107  if (COB_FIELD_TYPE (f2) == COB_TYPE_ALPHANUMERIC_ALL) {
2108  if (f2->size == 1 && f2->data[0] == '0' &&
2109  COB_FIELD_IS_NUMERIC (f1)) {
2110  return cob_cmp_int (f1, 0);
2111  }
2112  return cob_cmp_all (f1, f2);
2113  }
2114  if (COB_FIELD_TYPE (f1) == COB_TYPE_ALPHANUMERIC_ALL) {
2115  if (f1->size == 1 && f1->data[0] == '0' &&
2116  COB_FIELD_IS_NUMERIC (f2)) {
2117  return -cob_cmp_int (f2, 0);
2118  }
2119  return -cob_cmp_all (f2, f1);
2120  }
2121  if (COB_FIELD_IS_NUMERIC (f1) &&
2122  COB_FIELD_TYPE (f1) != COB_TYPE_NUMERIC_DISPLAY) {
2123  temp.size = COB_FIELD_DIGITS(f1);
2124  temp.data = buff;
2125  temp.attr = &attr;
2126  attr = *f1->attr;
2128  attr.flags &= ~COB_FLAG_HAVE_SIGN;
2129  cob_move (f1, &temp);
2130  f1 = &temp;
2131  }
2132  if (COB_FIELD_IS_NUMERIC (f2) &&
2133  COB_FIELD_TYPE (f2) != COB_TYPE_NUMERIC_DISPLAY) {
2134  temp.size = COB_FIELD_DIGITS(f2);
2135  temp.data = buff;
2136  temp.attr = &attr;
2137  attr = *f2->attr;
2139  attr.flags &= ~COB_FLAG_HAVE_SIGN;
2140  cob_move (f2, &temp);
2141  f2 = &temp;
2142  }
2143  return cob_cmp_alnum (f1, f2);
2144 }
COB_EXPIMP int cob_cmp_float ( cob_field ,
cob_field  
)
2312 {
2313  double d1,d2;
2314  float flt;
2315  if(COB_FIELD_TYPE (f1) == COB_TYPE_NUMERIC_FLOAT) {
2316  memcpy(&flt,f1->data,sizeof(float));
2317  d1 = flt;
2318  } else if(COB_FIELD_TYPE (f1) == COB_TYPE_NUMERIC_DOUBLE) {
2319  memcpy(&d1,f1->data,sizeof(double));
2320  } else {
2323  }
2324  if(COB_FIELD_TYPE (f2) == COB_TYPE_NUMERIC_FLOAT) {
2325  memcpy(&flt,f2->data,sizeof(float));
2326  d2 = flt;
2327  } else if(COB_FIELD_TYPE (f2) == COB_TYPE_NUMERIC_DOUBLE) {
2328  memcpy(&d2,f2->data,sizeof(double));
2329  } else {
2332  }
2333  if(d1 == d2)
2334  return 0;
2335  if(d1 != 0.0
2336  && FLOAT_EQ(d1,d2,TOLERANCE))
2337  return 0;
2338  if(d1 < d2)
2339  return -1;
2340  return 1;
2341 }
COB_EXPIMP int cob_cmp_int ( cob_field ,
const int   
)
2258 {
2260  mpz_set_si (cob_d2.value, (cob_sli_t)n);
2261  cob_d2.scale = 0;
2262  return cob_decimal_cmp (&cob_d1, &cob_d2);
2263 }
COB_EXPIMP int cob_cmp_llint ( cob_field ,
const cob_s64_t   
)
2276 {
2277 #ifdef COB_LI_IS_LL
2278  mpz_set_si (cob_d2.value, (cob_sli_t)n);
2279 #else
2280  cob_u64_t uval;
2281  cob_u32_t negative;
2282 
2283  negative = 0;
2284  if (n < 0) {
2285  negative = 1;
2286  uval = (cob_u64_t)-n;
2287  } else {
2288  uval = (cob_u64_t)n;
2289  }
2290  mpz_set_ui (cob_d2.value, (cob_uli_t)(uval >> 32));
2291  mpz_mul_2exp (cob_d2.value, cob_d2.value, 32);
2292  mpz_add_ui (cob_d2.value, cob_d2.value, (cob_uli_t)(uval & 0xFFFFFFFFU));
2293  if (negative) {
2294  mpz_neg (cob_d2.value, cob_d2.value);
2295  }
2296 #endif
2297 
2298  cob_d2.scale = 0;
2300  return cob_decimal_cmp (&cob_d1, &cob_d2);
2301 }
COB_EXPIMP int cob_cmp_numdisp ( const unsigned char *  ,
const size_t  ,
const cob_s64_t  ,
const cob_u32_t   
)
2541 {
2542  const unsigned char *p;
2543  cob_s64_t val = 0;
2544  size_t inc;
2545 
2546  p = data;
2547  if (!has_sign) {
2548  if (unlikely(n < 0)) {
2549  return 1;
2550  }
2551  for (inc = 0; inc < size; inc++, p++) {
2552  val = (val * 10) + COB_D2I (*p);
2553  }
2554  return (val < n) ? -1 : (val > n);
2555  }
2556  for (inc = 0; inc < size - 1; inc++, p++) {
2557  val = (val * 10) + COB_D2I (*p);
2558  }
2559  val *= 10;
2560  if (*p >= (unsigned char)'0' && *p <= (unsigned char)'9') {
2561  val += COB_D2I (*p);
2562  } else {
2563  if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
2564  if (cob_get_long_ebcdic_sign (p, &val)) {
2565  val = -val;
2566  }
2567  } else {
2568 #ifdef COB_EBCDIC_MACHINE
2569  if (cob_get_long_ascii_sign (p, &val)) {
2570  val = -val;
2571  }
2572 #else
2573  if (*p >= (unsigned char)'p' && *p <= (unsigned char)'y') {
2574  val += (*p - (unsigned char)'p');
2575  val = -val;
2576  }
2577 #endif
2578  }
2579  }
2580  return (val < n) ? -1 : (val > n);
2581 }
COB_EXPIMP int cob_cmp_packed ( cob_field ,
const cob_s64_t   
)
2359 {
2360  unsigned char *p;
2361  cob_u64_t n;
2362  size_t size;
2363  size_t inc;
2364  int sign;
2365  unsigned char val1[20];
2366 
2367  sign = cob_packed_get_sign (f);
2368  /* Field positive, value negative */
2369  if (sign >= 0 && val < 0) {
2370  return 1;
2371  }
2372  /* Field negative, value positive */
2373  if (sign < 0 && val >= 0) {
2374  return -1;
2375  }
2376  /* Both positive or both negative */
2377  if (val < 0) {
2378  n = (cob_u64_t)-val;
2379  } else {
2380  n = (cob_u64_t)val;
2381  }
2382  inc = 0;
2383  p = f->data;
2384  for (size = 0; size < 20; size++) {
2385  if (size < 20 - f->size) {
2386  val1[size] = 0;
2387  } else {
2388  val1[size] = p[inc++];
2389  }
2390  }
2391  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
2392  if ((COB_FIELD_DIGITS(f) % 2) == 1) {
2393  val1[20 - f->size] &= 0x0F;
2394  }
2395  } else {
2396  val1[19] &= 0xF0;
2397  if ((COB_FIELD_DIGITS(f) % 2) == 0) {
2398  val1[20 - f->size] &= 0x0F;
2399  }
2400  }
2401  if (n != last_packed_val) {
2402  last_packed_val = n;
2403  memset (packed_value, 0, sizeof(packed_value));
2404  if (n) {
2405  p = &packed_value[19];
2406  if (!COB_FIELD_NO_SIGN_NIBBLE (f)) {
2407  *p = (n % 10) << 4;
2408  p--;
2409  n /= 10;
2410  }
2411  for (; n;) {
2412  size = n % 100;
2413  *p = (unsigned char)((size % 10) | ((size / 10) << 4));
2414  n /= 100;
2415  p--;
2416  }
2417  }
2418  }
2419  for (size = 0; size < 20; size++) {
2420  if (val1[size] != packed_value[size]) {
2421  if (sign < 0) {
2422  return packed_value[size] - val1[size];
2423  } else {
2424  return val1[size] - packed_value[size];
2425  }
2426  }
2427  }
2428  return 0;
2429 }
COB_EXPIMP int cob_cmp_uint ( cob_field ,
const unsigned  int 
)
2267 {
2269  mpz_set_ui (cob_d2.value, (cob_uli_t)n);
2270  cob_d2.scale = 0;
2271  return cob_decimal_cmp (&cob_d1, &cob_d2);
2272 }
COB_EXPIMP void* cob_command_line ( int  ,
int *  ,
char ***  ,
char ***  ,
char **   
)
2940 {
2941 #if 0 /* RXWRXW cob_command_line */
2942  char **spenvp;
2943  char *spname;
2944 #else
2945  COB_UNUSED (penvp);
2946  COB_UNUSED (pname);
2947 #endif
2948 
2949  COB_UNUSED (flags);
2950 
2951  if (!cob_initialized) {
2952  cob_runtime_error (_("'cobcommandline' - Runtime has not been initialized"));
2953  cob_stop_run (1);
2954  }
2955  if (pargc && pargv) {
2956  cob_argc = *pargc;
2957  cob_argv = *pargv;
2958  }
2959 
2960 #if 0 /* RXWRXW cob_command_line */
2961  if (penvp) {
2962  spenvp = *penvp;
2963  }
2964  if (pname) {
2965  spname = *pname;
2966  }
2967 #endif
2968 
2969  /* What are we supposed to return here? */
2970  return NULL;
2971 }
COB_EXPIMP void cob_commit ( void  )
4871 {
4872  struct file_list *l;
4873 
4874  for (l = file_cache; l; l = l->next) {
4875  if (l->file) {
4876  cob_file_unlock (l->file);
4877  }
4878  }
4879 }
COB_EXPIMP void cob_correct_numeric ( cob_field )
1698 {
1699  unsigned char *p;
1700  unsigned char *data;
1701  size_t size;
1702  size_t i;
1703 
1704  if (!COB_FIELD_IS_NUMDISP(f)) {
1705  return;
1706  }
1707  size = f->size;
1708  data = f->data;
1709  if (COB_FIELD_HAVE_SIGN (f)) {
1710  /* Adjust for sign byte */
1711  size--;
1712  if (unlikely(COB_FIELD_SIGN_LEADING (f))) {
1713  p = f->data;
1714  data = p + 1;
1715  } else {
1716  p = f->data + f->size - 1;
1717  }
1718  if (unlikely(COB_FIELD_SIGN_SEPARATE (f))) {
1719  if (*p != '+' && *p != '-') {
1720  *p = '+';
1721  }
1722  } else if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
1723  switch (*p) {
1724  case '{':
1725  case 'A':
1726  case 'B':
1727  case 'C':
1728  case 'D':
1729  case 'E':
1730  case 'F':
1731  case 'G':
1732  case 'H':
1733  case 'I':
1734  case '}':
1735  case 'J':
1736  case 'K':
1737  case 'L':
1738  case 'M':
1739  case 'N':
1740  case 'O':
1741  case 'P':
1742  case 'Q':
1743  case 'R':
1744  break;
1745  case '0':
1746  *p = '{';
1747  break;
1748  case '1':
1749  *p = 'A';
1750  break;
1751  case '2':
1752  *p = 'B';
1753  break;
1754  case '3':
1755  *p = 'C';
1756  break;
1757  case '4':
1758  *p = 'D';
1759  break;
1760  case '5':
1761  *p = 'E';
1762  break;
1763  case '6':
1764  *p = 'F';
1765  break;
1766  case '7':
1767  *p = 'G';
1768  break;
1769  case '8':
1770  *p = 'H';
1771  break;
1772  case '9':
1773  *p = 'I';
1774  break;
1775  case 0:
1776  case ' ':
1777  *p = '{';
1778  break;
1779  default:
1780  break;
1781  }
1782  } else {
1783  if(!*p || *p == ' ') {
1784  *p = '0';
1785  }
1786  }
1787  } else {
1788  p = f->data + f->size - 1;
1789  if (unlikely(COB_MODULE_PTR->ebcdic_sign)) {
1790  switch (*p) {
1791  case 0:
1792  case ' ':
1793  case '{':
1794  case '}':
1795  *p = '0';
1796  break;
1797  case 'A':
1798  case 'B':
1799  case 'C':
1800  case 'D':
1801  case 'E':
1802  case 'F':
1803  case 'G':
1804  case 'H':
1805  case 'I':
1806  *p = '1' + (*p - 'A');
1807  break;
1808  case 'J':
1809  case 'K':
1810  case 'L':
1811  case 'M':
1812  case 'N':
1813  case 'O':
1814  case 'P':
1815  case 'Q':
1816  case 'R':
1817  *p = '1' + (*p - 'J');
1818  break;
1819  default:
1820  break;
1821  }
1822  } else {
1823  switch (*p) {
1824  case 0:
1825  case ' ':
1826  case 'p':
1827  *p = '0';
1828  break;
1829  case 'q':
1830  *p = '1';
1831  break;
1832  case 'r':
1833  *p = '2';
1834  break;
1835  case 's':
1836  *p = '3';
1837  break;
1838  case 't':
1839  *p = '4';
1840  break;
1841  case 'u':
1842  *p = '5';
1843  break;
1844  case 'v':
1845  *p = '6';
1846  break;
1847  case 'w':
1848  *p = '7';
1849  break;
1850  case 'x':
1851  *p = '8';
1852  break;
1853  case 'y':
1854  *p = '9';
1855  break;
1856  default:
1857  break;
1858  }
1859  }
1860  }
1861  for (i = 0, p = data; i < size; ++i, ++p) {
1862  switch (*p) {
1863  case '0':
1864  case '1':
1865  case '2':
1866  case '3':
1867  case '4':
1868  case '5':
1869  case '6':
1870  case '7':
1871  case '8':
1872  case '9':
1873  break;
1874  case 0:
1875  case ' ':
1876  *p = '0';
1877  break;
1878  default:
1879  if ((*p & 0x0F) <= 9) {
1880  *p = (*p & 0x0F) + '0';
1881  }
1882  break;
1883  }
1884  }
1885 }
COB_EXPIMP void cob_decimal_add ( cob_decimal ,
cob_decimal  
)
1876 {
1877  DECIMAL_CHECK (d1, d2);
1878  align_decimal (d1, d2);
1879  mpz_add (d1->value, d1->value, d2->value);
1880 }
COB_EXPIMP void cob_decimal_alloc ( const cob_u32_t  ,
  ... 
)
2585 {
2586  cob_decimal **dec;
2587  cob_u32_t i;
2588  va_list args;
2589 
2590  va_start (args, params);
2591  for (i = 0; i < params; ++i) {
2592  dec = va_arg (args, cob_decimal **);
2593  *dec = cob_decimal_base + i;
2594  }
2595  va_end (args);
2596 }
COB_EXPIMP int cob_decimal_cmp ( cob_decimal ,
cob_decimal  
)
1923 {
1924  align_decimal (d1, d2);
1925  return mpz_cmp (d1->value, d2->value);
1926 }
COB_EXPIMP void cob_decimal_div ( cob_decimal ,
cob_decimal  
)
1900 {
1901  DECIMAL_CHECK (d1, d2);
1902 
1903  /* Check for division by zero */
1904  if (unlikely(mpz_sgn (d2->value) == 0)) {
1907  return;
1908  }
1909  if (unlikely(mpz_sgn (d1->value) == 0)) {
1910  d1->scale = 0;
1911  return;
1912  }
1913  d1->scale -= d2->scale;
1914  shift_decimal (d1, COB_MAX_DIGITS + ((d1->scale < 0) ? -d1->scale : 0));
1915 #if 0 /* RXWRXW - cdiv */
1916  mpz_cdiv_q (d1->value, d1->value, d2->value);
1917 #endif
1918  mpz_tdiv_q (d1->value, d1->value, d2->value);
1919 }
COB_EXPIMP int cob_decimal_get_field ( cob_decimal ,
cob_field ,
const int   
)
1802 {
1803  cob_field temp;
1804  cob_field_attr attr;
1805  union {
1806  double val;
1807  float fval;
1808  } uval;
1809 
1810  if (unlikely(d->scale == COB_DECIMAL_NAN)) {
1811  cob_set_exception (COB_EC_SIZE_OVERFLOW);
1813  }
1814 
1815  /* work copy */
1816  if (d != &cob_d1) {
1817  mpz_set (cob_d1.value, d->value);
1818  cob_d1.scale = d->scale;
1819  d = &cob_d1;
1820  }
1821 
1822 #if 0 /* RXWRXW - Round FP */
1823  if (!COB_FIELD_IS_FP(f)) {
1824 #endif
1825  /* Rounding */
1826  if ((opt & COB_STORE_ROUND)) {
1827  cob_decimal_do_round (d, f, opt);
1828  }
1829  /* Append or truncate decimal digits */
1830  shift_decimal (d, COB_FIELD_SCALE(f) - d->scale);
1831 #if 0 /* RXWRXW - Round FP */
1832  }
1833 #endif
1834 
1835  /* Store number */
1836  switch (COB_FIELD_TYPE (f)) {
1838  return cob_decimal_get_binary (d, f, opt);
1840  return cob_decimal_get_display (d, f, opt);
1842  return cob_decimal_get_packed (d, f, opt);
1844  uval.fval = (float) cob_decimal_get_double (d);
1845  memcpy (f->data, &uval.fval, sizeof (float));
1846  return 0;
1848  uval.val = cob_decimal_get_double (d);
1849  memcpy (f->data, &uval.val, sizeof (double));
1850  return 0;
1852  return cob_decimal_get_ieee64dec (d, f, opt);
1854  return cob_decimal_get_ieee128dec (d, f, opt);
1855  default:
1856  break;
1857  }
1858  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, COB_FIELD_DIGITS(f),
1859  COB_FIELD_SCALE(f), COB_FLAG_HAVE_SIGN, NULL);
1860  temp.size = COB_FIELD_DIGITS(f);
1861  temp.data = cob_malloc (COB_FIELD_DIGITS(f));
1862  temp.attr = &attr;
1863  if (cob_decimal_get_display (d, &temp, opt) == 0) {
1864  cob_move (&temp, f);
1865  cob_free (temp.data);
1866  return 0;
1867  }
1868  cob_free (temp.data);
1870 }
COB_EXPIMP void cob_decimal_init ( cob_decimal )
322 {
323  mpz_init2 (d->value, COB_MPZ_DEF);
324  d->scale = 0;
325 }
COB_EXPIMP void cob_decimal_mul ( cob_decimal ,
cob_decimal  
)
1892 {
1893  DECIMAL_CHECK (d1, d2);
1894  d1->scale += d2->scale;
1895  mpz_mul (d1->value, d1->value, d2->value);
1896 }
COB_EXPIMP void cob_decimal_pop ( const cob_u32_t  ,
  ... 
)
2616 {
2617  cob_decimal *dec;
2618  cob_u32_t i;
2619  va_list args;
2620 
2621  va_start (args, params);
2622  for (i = 0; i < params; ++i) {
2623  dec = va_arg (args, cob_decimal *);
2624  mpz_clear (dec->value);
2625  cob_free (dec);
2626  }
2627  va_end (args);
2628 }
COB_EXPIMP void cob_decimal_pow ( cob_decimal ,
cob_decimal  
)
1962 {
1963  cob_uli_t n;
1964  int sign;
1965 
1966  if (unlikely(pd1->scale == COB_DECIMAL_NAN)) {
1967  return;
1968  }
1969  if (unlikely(pd2->scale == COB_DECIMAL_NAN)) {
1970  pd1->scale = COB_DECIMAL_NAN;
1971  return;
1972  }
1973 
1974  sign = mpz_sgn (pd1->value);
1975 
1976  if (!mpz_sgn (pd2->value)) {
1977  /* Exponent is zero */
1978  if (!sign) {
1979  /* 0 ^ 0 */
1980  cob_set_exception (COB_EC_SIZE_EXPONENTIATION);
1981  }
1982  mpz_set_ui (pd1->value, 1UL);
1983  pd1->scale = 0;
1984  return;
1985  }
1986  if (!sign) {
1987  /* Value is zero */
1988  pd1->scale = 0;
1989  return;
1990  }
1991 
1992  cob_trim_decimal (pd2);
1993 
1994  if (sign < 0 && pd2->scale) {
1995  /* Negative exponent and non-integer power */
1996  pd1->scale = COB_DECIMAL_NAN;
1997  cob_set_exception (COB_EC_SIZE_EXPONENTIATION);
1998  return;
1999  }
2000 
2001  cob_trim_decimal (pd1);
2002 
2003  if (!pd2->scale) {
2004  /* Integer power */
2005  if (!mpz_cmp_ui (pd2->value, 1UL)) {
2006  /* Power is 1 */
2007  return;
2008  }
2009  if (mpz_sgn (pd2->value) < 0 && mpz_fits_slong_p (pd2->value)) {
2010  /* Negative power */
2011  mpz_abs (pd2->value, pd2->value);
2012  n = mpz_get_ui (pd2->value);
2013  mpz_pow_ui (pd1->value, pd1->value, n);
2014  if (pd1->scale) {
2015  pd1->scale *= n;
2016  cob_trim_decimal (pd1);
2017  }
2018  cob_decimal_set (pd2, pd1);
2019  mpz_set_ui (pd1->value, 1UL),
2020  pd1->scale = 0;
2021  cob_decimal_div (pd1, pd2);
2022  cob_trim_decimal (pd1);
2023  return;
2024  }
2025  if (mpz_fits_ulong_p (pd2->value)) {
2026  /* Positive power */
2027  n = mpz_get_ui (pd2->value);
2028  mpz_pow_ui (pd1->value, pd1->value, n);
2029  if (pd1->scale) {
2030  pd1->scale *= n;
2031  cob_trim_decimal (pd1);
2032  }
2033  return;
2034  }
2035  }
2036 
2037  if (sign < 0) {
2038  mpz_abs (pd1->value, pd1->value);
2039  }
2041  if (pd2->scale == 1 && !mpz_cmp_ui (pd2->value, 5UL)) {
2042  /* Square root short cut */
2043  mpf_sqrt (cob_mpft2, cob_mpft);
2044  } else {
2047  mpf_mul (cob_mpft, cob_mpft, cob_mpft2);
2049  }
2051  if (sign < 0) {
2052  mpz_neg (pd1->value, pd1->value);
2053  }
2054 }
COB_EXPIMP void cob_decimal_push ( const cob_u32_t  ,
  ... 
)
2600 {
2601  cob_decimal **dec;
2602  cob_u32_t i;
2603  va_list args;
2604 
2605  va_start (args, params);
2606  for (i = 0; i < params; ++i) {
2607  dec = va_arg (args, cob_decimal **);
2608  *dec = cob_malloc (sizeof(cob_decimal));
2609  cob_decimal_init (*dec);
2610  }
2611  va_end (args);
2612 }
COB_EXPIMP void cob_decimal_set_field ( cob_decimal ,
cob_field  
)
1613 {
1614  union {
1615  double dval;
1616  float fval;
1617  } uval;
1618 
1619  switch (COB_FIELD_TYPE (f)) {
1621  cob_decimal_set_binary (d, f);
1622  break;
1624  cob_decimal_set_packed (d, f);
1625  break;
1627  memcpy ((void *)&uval.fval, f->data, sizeof(float));
1628  cob_decimal_set_double (d, (double)uval.fval);
1629  break;
1631  memcpy ((void *)&uval.dval, f->data, sizeof(double));
1632  cob_decimal_set_double (d, uval.dval);
1633  break;
1636  break;
1639  break;
1640  default:
1641  cob_decimal_set_display (d, f);
1642  break;
1643  }
1644 }
COB_EXPIMP void cob_decimal_set_llint ( cob_decimal ,
const cob_s64_t   
)
329 {
330 #ifdef COB_LI_IS_LL
331  mpz_set_si (d->value, (cob_sli_t)n);
332 #else
333  cob_u64_t uval;
334  cob_u32_t negative;
335 
336  negative = 0;
337  if (n < 0) {
338  negative = 1;
339  uval = (cob_u64_t)-n;
340  } else {
341  uval = (cob_u64_t)n;
342  }
343  mpz_set_ui (d->value, (cob_uli_t)(uval >> 32));
344  mpz_mul_2exp (d->value, d->value, 32);
345  mpz_add_ui (d->value, d->value, (cob_uli_t)(uval & 0xFFFFFFFFU));
346  if (negative) {
347  mpz_neg (d->value, d->value);
348  }
349 #endif
350  d->scale = 0;
351 }
COB_EXPIMP void cob_decimal_sub ( cob_decimal ,
cob_decimal  
)
1884 {
1885  DECIMAL_CHECK (d1, d2);
1886  align_decimal (d1, d2);
1887  mpz_sub (d1->value, d1->value, d2->value);
1888 }
COB_EXPIMP void cob_delete ( cob_file ,
cob_field  
)
4849 {
4850  int read_done;
4851 
4852  read_done = f->flag_read_done;
4853  f->flag_read_done = 0;
4854 
4855  if (unlikely(f->open_mode != COB_OPEN_I_O)) {
4856  save_status (f, fnstatus, COB_STATUS_49_I_O_DENIED);
4857  return;
4858  }
4859 
4860  if (f->access_mode == COB_ACCESS_SEQUENTIAL && !read_done) {
4862  return;
4863  }
4864 
4865  save_status (f, fnstatus,
4866  fileio_funcs[(int)f->organization]->fdelete (f));
4867 }
COB_EXPIMP void cob_delete_file ( cob_file ,
cob_field  
)
4895 {
4896  if (f->organization == COB_ORG_SORT) {
4898  return;
4899  }
4900 
4901  /* File was previously closed with lock */
4902  if (f->open_mode == COB_OPEN_LOCKED) {
4904  return;
4905  }
4906 
4907  /* File is open */
4908  if (f->open_mode != COB_OPEN_CLOSED) {
4909  save_status (f, fnstatus, COB_STATUS_41_ALREADY_OPEN);
4910  return;
4911  }
4912 
4913  if (unlikely(COB_FILE_STDIN (f))) {
4915  return;
4916  }
4917  if (unlikely(COB_FILE_STDOUT (f))) {
4919  return;
4920  }
4921 
4922  /* Obtain the file name */
4923  cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX);
4925 
4926  if (f->organization != COB_ORG_INDEXED) {
4927 #ifdef WITH_SEQRA_EXTFH
4929  return;
4930 #else
4931  unlink (file_open_name);
4932 #endif
4933  } else {
4934 #ifdef WITH_INDEX_EXTFH
4936  return;
4937 #else
4939 #endif
4940  }
4941  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
4942 }
COB_EXPIMP void cob_display ( const int  ,
const int  ,
const int  ,
  ... 
)
238 {
239  FILE *fp;
240  cob_field *f;
241  int i;
242  int nlattr;
243  cob_u32_t disp_redirect;
244  va_list args;
245 
246  disp_redirect = 0;
247  if (to_stderr) {
248  fp = stderr;
249  } else {
250  fp = stdout;
252  if (!COB_DISP_TO_STDERR) {
253  disp_redirect = 1;
254  } else {
255  fp = stderr;
256  }
257  }
258  }
259 
260  nlattr = newline ? COB_SCREEN_EMULATE_NL : 0;
261  va_start (args, varcnt);
262  for (i = 0; i < varcnt; ++i) {
263  f = va_arg (args, cob_field *);
264  if (unlikely(disp_redirect)) {
266  NULL, nlattr);
267  } else {
268  display_common (f, fp);
269  }
270  }
271  va_end (args);
272 
273  if (newline && !disp_redirect) {
274  putc ('\n', fp);
275  fflush (fp);
276  }
277 }
COB_EXPIMP void cob_display_arg_number ( cob_field )
2571 {
2572  int n;
2573  cob_field_attr attr;
2574  cob_field temp;
2575 
2576  temp.size = 4;
2577  temp.data = (unsigned char *)&n;
2578  temp.attr = &attr;
2579  COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0, 0, NULL);
2580  cob_move (f, &temp);
2581  if (n < 0 || n >= cob_argc) {
2582  cob_set_exception (COB_EC_IMP_DISPLAY);
2583  return;
2584  }
2585  current_arg = n;
2586 }
COB_EXPIMP void cob_display_command_line ( cob_field )
2515 {
2516  if (commlnptr) {
2517  cob_free (commlnptr);
2518  }
2519  commlnptr = cob_malloc (f->size + 1U);
2520  commlncnt = f->size;
2521  memcpy (commlnptr, f->data, commlncnt);
2522 }
COB_EXPIMP void cob_display_env_value ( const cob_field )
2641 {
2642  char *env2;
2643 #if !HAVE_SETENV
2644  char *p;
2645  size_t len;
2646 #endif
2647  int ret;
2648 
2649  if (!cob_local_env) {
2650  cob_set_exception (COB_EC_IMP_DISPLAY);
2651  return;
2652  }
2653  if (!*cob_local_env) {
2654  cob_set_exception (COB_EC_IMP_DISPLAY);
2655  return;
2656  }
2657  env2 = cob_malloc (f->size + 1U);
2658  cob_field_to_string (f, env2, f->size);
2659 #if HAVE_SETENV
2660  ret = setenv(cob_local_env, env2, 1);
2661 #else
2662  len = strlen (cob_local_env) + strlen (env2) + 3U;
2663  p = cob_fast_malloc (len);
2664  sprintf (p, "%s=%s", cob_local_env, env2);
2665  ret = putenv (p);
2666 #endif
2667  cob_free (env2);
2668  if (ret != 0) {
2669  cob_set_exception (COB_EC_IMP_DISPLAY);
2670  return;
2671  }
2672  /* Rescan term/screen variables */
2674 }
COB_EXPIMP void cob_display_environment ( const cob_field )
2619 {
2620  size_t i;
2621 
2622  if (cob_local_env_size < f->size) {
2623  cob_local_env_size = f->size;
2624  if (cob_local_env) {
2626  }
2628  }
2631  for (i = 0; i < strlen (cob_local_env); ++i) {
2632  if (!isalnum ((int)cob_local_env[i])) {
2633  cob_local_env[i] = '_';
2634  }
2635  }
2636  }
2637 }
COB_EXPIMP void cob_div ( cob_field ,
cob_field ,
const int   
)
1959 {
1963  (void)cob_decimal_get_field (&cob_d1, f1, opt);
1964 }
COB_EXPIMP void cob_div_quotient ( cob_field ,
cob_field ,
cob_field ,
const int   
)
1969 {
1970  /* Note that cob_div_quotient and cob_div_remainder must remain */
1971  /* separate because of COBOL rules. The quotient must be fully */
1972  /* evaluated before the remainder item is evaluated */
1973  /* eg. DIVIDE A BY B GIVING Z REMAINDER FLD (Z). */
1974 
1975  cob_decimal_set_field (&cob_d1, dividend);
1976  cob_decimal_set_field (&cob_d2, divisor);
1978 
1979  /* Compute quotient */
1981  /* Check divide by zero - Exception is set in cob_decimal_div */
1982  if (cob_d1.scale == COB_DECIMAL_NAN) {
1983  /* Forces an early return from cob_div_remainder */
1985  return;
1986  }
1987 
1988  /* Set quotient */
1990  (void)cob_decimal_get_field (&cob_d1, quotient, opt);
1991 
1992  /* Truncate digits from the quotient */
1994 
1995  /* Compute remainder */
1998 }
COB_EXPIMP void cob_div_remainder ( cob_field ,
const int   
)
2002 {
2003  (void)cob_decimal_get_field (&cob_d_remainder, fld_remainder, opt);
2004 }
COB_EXPIMP int cob_extern_init ( void  )
2932 {
2933  cob_init (0, NULL);
2934  return 0;
2935 }
COB_EXPIMP void* cob_external_addr ( const char *  ,
const int   
)
2384 {
2385  struct cob_external *eptr;
2386 
2387  /* Locate or allocate EXTERNAL item */
2388  for (eptr = basext; eptr; eptr = eptr->next) {
2389  if (!strcmp (exname, eptr->ename)) {
2390  if (exlength > eptr->esize) {
2391  cob_runtime_error (_("EXTERNAL item '%s' previously allocated with size %d, requested size is %d"),
2392  exname, eptr->esize, exlength);
2393  cob_stop_run (1);
2394  }
2396  return eptr->ext_alloc;
2397  }
2398  }
2399  eptr = cob_malloc (sizeof (struct cob_external));
2400  eptr->next = basext;
2401  eptr->esize = exlength;
2402  eptr->ename = cob_malloc (strlen (exname) + 1U);
2403  strcpy (eptr->ename, exname);
2404  eptr->ext_alloc = cob_malloc ((size_t)exlength);
2405  basext = eptr;
2407  return eptr->ext_alloc;
2408 }
COB_EXPIMP void* cob_fast_malloc ( const size_t  )
1147 {
1148  void *mptr;
1149 
1150  mptr = malloc (size);
1151  if (unlikely(!mptr)) {
1152  cob_fatal_error (COB_FERROR_MEMORY);
1153  }
1154  return mptr;
1155 }
DECLNORET COB_EXPIMP void cob_fatal_error ( const int  )
1441 {
1442  const char *msg;
1443  unsigned char *file_status;
1444  char *filename;
1445  int status;
1446 
1447  switch (fatal_error) {
1448  case COB_FERROR_NONE:
1449  cob_runtime_error (_("cob_init() has not been called"));
1450  break;
1451  case COB_FERROR_CANCEL:
1452  cob_runtime_error (_("Attempt to CANCEL active program"));
1453  break;
1455  cob_runtime_error (_("cob_init() has not been called"));
1456  break;
1457  case COB_FERROR_CODEGEN:
1458  cob_runtime_error (_("Codegen error - Please report this"));
1459  break;
1460  case COB_FERROR_CHAINING:
1461  cob_runtime_error (_("Recursive call of chained program"));
1462  break;
1463  case COB_FERROR_STACK:
1464  cob_runtime_error (_("Stack overflow, possible PERFORM depth exceeded"));
1465  break;
1466  case COB_FERROR_GLOBAL:
1467  cob_runtime_error (_("Invalid entry/exit in GLOBAL USE procedure"));
1468  break;
1469  case COB_FERROR_MEMORY:
1470  cob_runtime_error (_("Unable to allocate memory"));
1471  break;
1472  case COB_FERROR_MODULE:
1473  cob_runtime_error (_("Invalid entry into module"));
1474  break;
1475  case COB_FERROR_RECURSIVE:
1476  cob_runtime_error (_("Invalid recursive COBOL CALL"));
1477  break;
1478  case COB_FERROR_FREE:
1479  cob_runtime_error (_("Call to cob_free with NULL pointer"));
1480  break;
1481  case COB_FERROR_FILE:
1482  file_status = cobglobptr->cob_error_file->file_status;
1483  status = COB_D2I(file_status[0]) * 10 + COB_D2I(file_status[1]);
1484  switch (status) {
1486  msg = _("End of file");
1487  break;
1489  msg = _("Key out of range");
1490  break;
1492  msg = _("Key order not ascending");
1493  break;
1495  msg = _("Record key already exists");
1496  break;
1498  msg = _("Record key does not exist");
1499  break;
1501  msg = _("Permanent file error");
1502  break;
1504  msg = _("File does not exist");
1505  break;
1507  msg = _("Permission denied");
1508  break;
1510  msg = _("File already open");
1511  break;
1513  msg = _("File not open");
1514  break;
1516  msg = _("READ must be executed first");
1517  break;
1519  msg = _("Record overflow");
1520  break;
1522  msg = _("Failed to read");
1523  break;
1525  msg = _("READ/START not allowed");
1526  break;
1528  msg = _("WRITE not allowed");
1529  break;
1531  msg = _("DELETE/REWRITE not allowed");
1532  break;
1534  msg = _("Record locked by another file connector");
1535  break;
1537  msg = _("LINAGE values invalid");
1538  break;
1540  msg = _("File sharing conflict");
1541  break;
1543  msg = _("Runtime library is not configured for this operation");
1544  break;
1545  default:
1546  msg = _("Unknown file error");
1547  break;
1548  }
1549  filename = cob_malloc ((size_t)COB_FILE_BUFF);
1551  filename, (size_t)COB_FILE_MAX);
1552  cob_runtime_error (_("%s (Status = %02d) File : '%s'"),
1553  msg, status, filename);
1554  cob_free (filename);
1555  break;
1556  case COB_FERROR_FUNCTION:
1557  cob_runtime_error (_("Attempt to use non-implemented function"));
1558  break;
1559  default:
1560  cob_runtime_error (_("Unknown failure : %d"), fatal_error);
1561  break;
1562  }
1563  cob_stop_run (1);
1564 }
COB_EXPIMP void cob_field_accept ( cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
const int   
)
1703 {
1704  COB_UNUSED (f);
1705  COB_UNUSED (line);
1706  COB_UNUSED (column);
1707  COB_UNUSED (fgc);
1708  COB_UNUSED (bgc);
1709  COB_UNUSED (fscroll);
1710  COB_UNUSED (ftimeout);
1711  COB_UNUSED (prompt);
1712  COB_UNUSED (attr);
1713 }
COB_EXPIMP void cob_field_display ( cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
cob_field ,
const int   
)
1689 {
1690  COB_UNUSED (f);
1691  COB_UNUSED (line);
1692  COB_UNUSED (column);
1693  COB_UNUSED (fgc);
1694  COB_UNUSED (bgc);
1695  COB_UNUSED (fscroll);
1696  COB_UNUSED (attr);
1697 }
COB_EXPIMP void cob_file_release ( cob_file )
6247 {
6248  struct cobsort *hp;
6250  int ret;
6251 
6252  fnstatus = NULL;
6253  hp = f->file;
6254  if (likely(hp)) {
6255  fnstatus = hp->fnstatus;
6256  }
6257  ret = cob_file_sort_submit (f, f->record->data);
6258  if (!ret) {
6259  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
6260  return;
6261  }
6262  if (likely(hp)) {
6263  *(int *)(hp->sort_return) = 16;
6264  }
6266 }
COB_EXPIMP void cob_file_return ( cob_file )
6270 {
6271  struct cobsort *hp;
6273  int ret;
6274 
6275  fnstatus = NULL;
6276  hp = f->file;
6277  if (likely(hp)) {
6278  fnstatus = hp->fnstatus;
6279  }
6280  ret = cob_file_sort_retrieve (f, f->record->data);
6281  switch (ret) {
6282  case 0:
6283  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
6284  return;
6285  case COBSORTEND:
6286  save_status (f, fnstatus, COB_STATUS_10_END_OF_FILE);
6287  return;
6288  }
6289  if (likely(hp)) {
6290  *(int *)(hp->sort_return) = 16;
6291  }
6293 }
COB_EXPIMP void cob_file_sort_close ( cob_file )
6221 {
6222  struct cobsort *hp;
6224  size_t i;
6225 
6226  fnstatus = NULL;
6227  hp = f->file;
6228  if (likely(hp)) {
6229  fnstatus = hp->fnstatus;
6230  cob_free_list (hp);
6231  for (i = 0; i < 4; ++i) {
6232  if (hp->file[i].fp != NULL) {
6233  fclose (hp->file[i].fp);
6234  }
6235  }
6236  cob_free (hp);
6237  }
6238  if (f->keys) {
6239  cob_free (f->keys);
6240  }
6241  f->file = NULL;
6242  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
6243 }
COB_EXPIMP void cob_file_sort_giving ( cob_file ,
const size_t  ,
  ... 
)
6115 {
6116  cob_file **fbase;
6117  struct cobsort *hp;
6118  size_t i;
6119  int ret;
6120  int opt;
6121  va_list args;
6122 
6123  fbase = cob_malloc (varcnt * sizeof(cob_file *));
6124  va_start (args, varcnt);
6125  for (i = 0; i < varcnt; ++i) {
6126  fbase[i] = va_arg (args, cob_file *);
6127  }
6128  va_end (args);
6129  for (i = 0; i < varcnt; ++i) {
6130  cob_open (fbase[i], COB_OPEN_OUTPUT, 0, NULL);
6131  }
6132  for (;;) {
6133  ret = cob_file_sort_retrieve (sort_file, sort_file->record->data);
6134  if (ret) {
6135  if (ret == COBSORTEND) {
6136  sort_file->file_status[0] = '1';
6137  sort_file->file_status[1] = '0';
6138  } else {
6139  hp = sort_file->file;
6140  *(int *)(hp->sort_return) = 16;
6141  sort_file->file_status[0] = '3';
6142  sort_file->file_status[1] = '0';
6143  }
6144  break;
6145  }
6146  for (i = 0; i < varcnt; ++i) {
6147  if (COB_FILE_SPECIAL (fbase[i]) ||
6148  fbase[i]->organization == COB_ORG_LINE_SEQUENTIAL) {
6149  opt = COB_WRITE_BEFORE | COB_WRITE_LINES | 1;
6150  } else {
6151  opt = 0;
6152  }
6153  fbase[i]->record->size = fbase[i]->record_max;
6154  cob_copy_check (fbase[i], sort_file);
6155  cob_write (fbase[i], fbase[i]->record, opt, NULL, 0);
6156  }
6157  }
6158  for (i = 0; i < varcnt; ++i) {
6159  cob_close (fbase[i], NULL, COB_CLOSE_NORMAL, 0);
6160  }
6161  cob_free (fbase);
6162 }
COB_EXPIMP void cob_file_sort_init ( cob_file ,
const unsigned  int,
const unsigned char *  ,
void *  ,
cob_field  
)
6168 {
6169  struct cobsort *p;
6170  size_t n;
6171 
6172  p = cob_malloc (sizeof (struct cobsort));
6173  p->fnstatus = fnstatus;
6174  p->size = f->record_max;
6175  p->r_size = f->record_max + sizeof(size_t);
6176  p->w_size = f->record_max + sizeof(size_t) + 1;
6177  n = sizeof (struct cobitem) - offsetof (struct cobitem, item);
6178  if (f->record_max <= n) {
6179  p->alloc_size = sizeof (struct cobitem);
6180  } else {
6181  p->alloc_size = offsetof (struct cobitem, item) + f->record_max;
6182  }
6183  if (p->alloc_size % sizeof(void *)) {
6184  p->alloc_size += sizeof(void *) - (p->alloc_size % sizeof(void *));
6185  }
6187  if (p->chunk_size % p->alloc_size) {
6188  p->chunk_size += p->alloc_size - (p->chunk_size % p->alloc_size);
6189  }
6190  p->pointer = f;
6191  p->sort_return = sort_return;
6192  *(int *)sort_return = 0;
6193  p->mem_base = cob_fast_malloc (sizeof (struct sort_mem_struct));
6195  p->mem_base->next = NULL;
6196  p->mem_size = p->chunk_size;
6197  p->mem_total = p->chunk_size;
6198  f->file = p;
6199  f->keys = cob_malloc (sizeof (cob_file_key) * nkeys);
6200  f->nkeys = 0;
6201  if (collating_sequence) {
6202  f->sort_collating = collating_sequence;
6203  } else {
6204  f->sort_collating = COB_MODULE_PTR->collating_sequence;
6205  }
6206  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
6207 }
COB_EXPIMP void cob_file_sort_init_key ( cob_file ,
cob_field ,
const int  ,
const unsigned  int 
)
6212 {
6213  f->keys[f->nkeys].field = field;
6214  f->keys[f->nkeys].flag = flag;
6215  f->keys[f->nkeys].offset = offset;
6216  f->nkeys++;
6217 }
COB_EXPIMP void cob_file_sort_using ( cob_file ,
cob_file  
)
6095 {
6096  int ret;
6097 
6098  cob_open (data_file, COB_OPEN_INPUT, 0, NULL);
6099  for (;;) {
6100  cob_read_next (data_file, NULL, COB_READ_NEXT);
6101  if (data_file->file_status[0] != '0') {
6102  break;
6103  }
6104  cob_copy_check (sort_file, data_file);
6105  ret = cob_file_sort_submit (sort_file, sort_file->record->data);
6106  if (ret) {
6107  break;
6108  }
6109  }
6110  cob_close (data_file, NULL, COB_CLOSE_NORMAL, 0);
6111 }
COB_EXPIMP void cob_free ( void *  )
1135 {
1136 #ifdef _DEBUG
1137  if (unlikely(!mptr)) {
1138  cob_fatal_error (COB_FERROR_FREE);
1139  }
1140 #endif
1141  free (mptr);
1142 
1143 }
COB_EXPIMP void cob_free_alloc ( unsigned char **  ,
unsigned char *   
)
2791 {
2792  struct cob_alloc_cache *cache_ptr;
2793  struct cob_alloc_cache *prev_ptr;
2794  void *vptr1;
2795 
2796  /* FREE */
2798  cache_ptr = cob_alloc_base;
2799  prev_ptr = cob_alloc_base;
2800  if (ptr1 && *ptr1) {
2801  vptr1 = *ptr1;
2802  for (; cache_ptr; cache_ptr = cache_ptr->next) {
2803  if (vptr1 == cache_ptr->cob_pointer) {
2804  cob_free (cache_ptr->cob_pointer);
2805  if (cache_ptr == cob_alloc_base) {
2806  cob_alloc_base = cache_ptr->next;
2807  } else {
2808  prev_ptr->next = cache_ptr->next;
2809  }
2810  cob_free (cache_ptr);
2811  *ptr1 = NULL;
2812  return;
2813  }
2814  prev_ptr = cache_ptr;
2815  }
2817  return;
2818  }
2819  if (ptr2 && *(void **)ptr2) {
2820  for (; cache_ptr; cache_ptr = cache_ptr->next) {
2821  if (*(void **)ptr2 == cache_ptr->cob_pointer) {
2822  cob_free (cache_ptr->cob_pointer);
2823  if (cache_ptr == cob_alloc_base) {
2824  cob_alloc_base = cache_ptr->next;
2825  } else {
2826  prev_ptr->next = cache_ptr->next;
2827  }
2828  cob_free (cache_ptr);
2829  *(void **)ptr2 = NULL;
2830  return;
2831  }
2832  prev_ptr = cache_ptr;
2833  }
2835  return;
2836  }
2837 }
COB_EXPIMP int cob_func ( const char *  ,
const int  ,
void **   
)
1132 {
1133  int ret;
1134 
1135  ret = cob_call (name, argc, argv);
1136  cob_cancel (name);
1137  return ret;
1138 }
void cob_gen_optim ( const enum  cb_optim)

References _, COBC_ABORT, cobc_abort_pr(), and output_storage().

Referenced by codegen().

48 {
49  switch (val) {
50 
51  case COB_SET_SCREEN:
52  output_storage ("static void COB_NOINLINE");
53  output_storage ("cob_set_screen (cob_screen *s, cob_screen *next,");
54  output_storage (" cob_screen *child, cob_field *field, cob_field *value,");
55  output_storage (" cob_field *line, cob_field *column,");
56  output_storage (" cob_field *foreg, cob_field *backg, cob_field *prompt,");
57  output_storage (" const int type, const int occurs, const int attr)");
58  output_storage ("{");
59  output_storage (" s->next = next;");
60  output_storage (" s->child = child;");
61  output_storage (" s->field = field;");
62  output_storage (" s->value = value;");
63  output_storage (" s->line = line;");
64  output_storage (" s->column = column;");
65  output_storage (" s->foreg = foreg;");
66  output_storage (" s->backg = backg;");
67  output_storage (" s->prompt = prompt;");
68  output_storage (" s->type = type;");
69  output_storage (" s->occurs = occurs;");
70  output_storage (" s->attr = attr;");
71  output_storage ("}");
72  return;
73 
74  case COB_POINTER_MANIP:
75  output_storage ("static void COB_NOINLINE");
76  output_storage ("cob_pointer_manip (cob_field *f1, cob_field *f2, const unsigned int addsub)");
77  output_storage ("{");
78  output_storage (" unsigned char *tmptr;");
79  output_storage (" memcpy (&tmptr, f1->data, sizeof(void *));");
80  output_storage (" if (addsub) {");
81  output_storage (" tmptr -= cob_get_int (f2);");
82  output_storage (" } else {");
83  output_storage (" tmptr += cob_get_int (f2);");
84  output_storage (" }");
85  output_storage (" memcpy (f1->data, &tmptr, sizeof(void *));");
86  output_storage ("}");
87  return;
88 
89  case COB_GET_NUMDISP:
90  output_storage ("static int COB_NOINLINE");
91  output_storage ("cob_get_numdisp (const void *data, const size_t size)");
92  output_storage ("{");
93  output_storage (" const unsigned char *p;");
94  output_storage (" size_t n;");
95  output_storage (" int retval;");
96 
97  output_storage (" p = (const unsigned char *)data;");
98  output_storage (" retval = 0;");
99  output_storage (" for (n = 0; n < size; ++n, ++p) {");
100  output_storage (" retval *= 10;");
101  output_storage (" retval += (*p & 0x0F);");
102  output_storage (" }");
103  output_storage (" return retval;");
104  output_storage ("}");
105  return;
106 
107  case COB_CMP_PACKED_INT:
108  output_storage ("static int COB_NOINLINE");
109  output_storage ("cob_cmp_packed_int (const cob_field *f, const cob_s64_t n)");
110  output_storage ("{");
111  output_storage (" unsigned char *p;");
112  output_storage (" size_t size;");
113  output_storage (" cob_s64_t val;");
114 
115  output_storage (" val = 0;");
116  output_storage (" p = f->data;");
117  output_storage (" for (size = 0; size < f->size - 1; ++size, ++p) {");
118  output_storage (" val *= 10;");
119  output_storage (" val += *p >> 4;");
120  output_storage (" val *= 10;");
121  output_storage (" val += *p & 0x0f;");
122  output_storage (" }");
123  output_storage (" val *= 10;");
124  output_storage (" val += *p >> 4;");
125  output_storage (" if ((*p & 0x0f) == 0x0d) {");
126  output_storage (" val = -val;");
127  output_storage (" }");
128  output_storage (" return (val < n) ? -1 : (val > n);");
129  output_storage ("}");
130  return;
131 
132  case COB_GET_PACKED_INT:
133  output_storage ("static int COB_NOINLINE");
134  output_storage ("cob_get_packed_int (const cob_field *f)");
135  output_storage ("{");
136  output_storage (" unsigned char *p;");
137  output_storage (" size_t size;");
138  output_storage (" int val = 0;");
139 
140  output_storage (" p = f->data;");
141  output_storage (" for (size = 0; size < f->size - 1; ++size, ++p) {");
142  output_storage (" val *= 10;");
143  output_storage (" val += *p >> 4;");
144  output_storage (" val *= 10;");
145  output_storage (" val += *p & 0x0f;");
146  output_storage (" }");
147  output_storage (" val *= 10;");
148  output_storage (" val += *p >> 4;");
149  output_storage (" if ((*p & 0x0f) == 0x0d) {");
150  output_storage (" val = -val;");
151  output_storage (" }");
152  output_storage (" return val;");
153  output_storage ("}");
154  return;
155 
156  case COB_ADD_PACKED_INT:
157  output_storage ("static int COB_NOINLINE");
158  output_storage ("cob_add_packed_int (cob_field *f, const int val)");
159  output_storage ("{");
160  output_storage (" unsigned char *p;");
161  output_storage (" size_t size;");
162  output_storage (" int carry = 0;");
163  output_storage (" int n;");
164  output_storage (" int inc;");
165 
166  output_storage (" if (val == 0) {");
167  output_storage (" return 0;");
168  output_storage (" }");
169  output_storage (" p = f->data + f->size - 1;");
170  output_storage (" if ((*p & 0x0f) == 0x0d) {");
171  output_storage (" if (val > 0) {");
172  output_storage (" return cob_add_int (f, val, 0);");
173  output_storage (" }");
174  output_storage (" n = -val;");
175  output_storage (" } else {");
176  output_storage (" if (val < 0) {");
177  output_storage (" return cob_add_int (f, val, 0);");
178  output_storage (" }");
179  output_storage (" n = val;");
180  output_storage (" }");
181  output_storage (" inc = (*p >> 4) + (n %% 10);");
182  output_storage (" n /= 10;");
183  output_storage (" carry = inc / 10;");
184  output_storage (" *p = ((inc %% 10) << 4) | (*p & 0x0f);");
185  output_storage (" p--;");
186 
187  output_storage (" for (size = 0; size < f->size - 1; ++size, --p) {");
188  output_storage (" if (!carry && !n) {");
189  output_storage (" break;");
190  output_storage (" }");
191  output_storage (" inc = ((*p >> 4) * 10) + (*p & 0x0f) + carry + (n %% 100);");
192  output_storage (" carry = inc / 100;");
193  output_storage (" n /= 100;");
194  output_storage (" inc %%= 100;");
195  output_storage (" *p = ((inc / 10) << 4) | (inc %% 10);");
196  output_storage (" }");
197  output_storage (" return 0;");
198  output_storage ("}");
199  return;
200 
201  /* Aligned variants */
202 
203  /* Aligned compares */
204 
205  case COB_CMP_ALIGN_U16:
206  output_storage ("static COB_INLINE COB_A_INLINE int");
207  output_storage ("cob_cmp_align_u16 (const void *p, const cob_s64_t n)");
208  output_storage ("{");
209  output_storage (" unsigned short val;");
210 
211  output_storage (" if (unlikely(n < 0)) {");
212  output_storage (" return 1;");
213  output_storage (" }");
214  output_storage (" val = *(unsigned short __unaligned *)p;");
215  output_storage (" return (val < n) ? -1 : (val > n);");
216  output_storage ("}");
217  return;
218 
219  case COB_CMP_ALIGN_S16:
220  output_storage ("static COB_INLINE COB_A_INLINE int");
221  output_storage ("cob_cmp_align_s16 (const void *p, const cob_s64_t n)");
222  output_storage ("{");
223  output_storage (" short val;");
224 
225  output_storage (" val = *(short __unaligned *)p;");
226  output_storage (" return (val < n) ? -1 : (val > n);");
227  output_storage ("}");
228  return;
229 
230  case COB_CMP_ALIGN_U32:
231  output_storage ("static COB_INLINE COB_A_INLINE int");
232  output_storage ("cob_cmp_align_u32 (const void *p, const cob_s64_t n)");
233  output_storage ("{");
234  output_storage (" unsigned int val;");
235 
236  output_storage (" if (unlikely(n < 0)) {");
237  output_storage (" return 1;");
238  output_storage (" }");
239  output_storage (" val = *(unsigned int __unaligned *)p;");
240  output_storage (" return (val < n) ? -1 : (val > n);");
241  output_storage ("}");
242  return;
243 
244  case COB_CMP_ALIGN_S32:
245  output_storage ("static COB_INLINE COB_A_INLINE int");
246  output_storage ("cob_cmp_align_s32 (const void *p, const cob_s64_t n)");
247  output_storage ("{");
248  output_storage (" int val;");
249 
250  output_storage (" val = *(int __unaligned *)p;");
251  output_storage (" return (val < n) ? -1 : (val > n);");
252  output_storage ("}");
253  return;
254 
255  case COB_CMP_ALIGN_U64:
256  output_storage ("static COB_INLINE COB_A_INLINE int");
257  output_storage ("cob_cmp_align_u64 (const void *p, const cob_s64_t n)");
258  output_storage ("{");
259  output_storage (" cob_u64_t val;");
260 
261  output_storage (" if (unlikely(n < 0)) {");
262  output_storage (" return 1;");
263  output_storage (" }");
264  output_storage (" val = *(cob_u64_t __unaligned *)p;");
265  output_storage (" return (val < n) ? -1 : (val > n);");
266  output_storage ("}");
267  return;
268 
269  case COB_CMP_ALIGN_S64:
270  output_storage ("static COB_INLINE COB_A_INLINE int");
271  output_storage ("cob_cmp_align_s64 (const void *p, const cob_s64_t n)");
272  output_storage ("{");
273  output_storage (" cob_s64_t val;");
274 
275  output_storage (" val = *(cob_s64_t __unaligned *)p;");
276  output_storage (" return (val < n) ? -1 : (val > n);");
277  output_storage ("}");
278  return;
279 
280  /* Aligned adds */
281 
282  case COB_ADD_ALIGN_U16:
283  output_storage ("static COB_INLINE COB_A_INLINE void");
284  output_storage ("cob_add_align_u16 (void *p, const int val)");
285  output_storage ("{");
286  output_storage (" *(unsigned short __unaligned *)p += val;");
287  output_storage ("}");
288  return;
289 
290  case COB_ADD_ALIGN_S16:
291  output_storage ("static COB_INLINE COB_A_INLINE void");
292  output_storage ("cob_add_align_s16 (void *p, const int val)");
293  output_storage ("{");
294  output_storage (" *(short __unaligned *)p += val;");
295  output_storage ("}");
296  return;
297 
298  case COB_ADD_ALIGN_U32:
299  output_storage ("static COB_INLINE COB_A_INLINE void");
300  output_storage ("cob_add_align_u32 (void *p, const int val)");
301  output_storage ("{");
302  output_storage (" *(unsigned int __unaligned *)p += val;");
303  output_storage ("}");
304  return;
305 
306  case COB_ADD_ALIGN_S32:
307  output_storage ("static COB_INLINE COB_A_INLINE void");
308  output_storage ("cob_add_align_s32 (void *p, const int val)");
309  output_storage ("{");
310  output_storage (" *(int __unaligned *)p += val;");
311  output_storage ("}");
312  return;
313 
314  case COB_ADD_ALIGN_U64:
315  output_storage ("static COB_INLINE COB_A_INLINE void");
316  output_storage ("cob_add_align_u64 (void *p, const int val)");
317  output_storage ("{");
318  output_storage (" *(cob_u64_t __unaligned *)p += val;");
319  output_storage ("}");
320  return;
321 
322  case COB_ADD_ALIGN_S64:
323  output_storage ("static COB_INLINE COB_A_INLINE void");
324  output_storage ("cob_add_align_s64 (void *p, const int val)");
325  output_storage ("{");
326  output_storage (" *(cob_s64_t __unaligned *)p += val;");
327  output_storage ("}");
328  return;
329 
330  /* Aligned subtracts */
331 
332  case COB_SUB_ALIGN_U16:
333  output_storage ("static COB_INLINE COB_A_INLINE void");
334  output_storage ("cob_sub_align_u16 (void *p, const int val)");
335  output_storage ("{");
336  output_storage (" *(unsigned short __unaligned *)p -= val;");
337  output_storage ("}");
338  return;
339 
340  case COB_SUB_ALIGN_S16:
341  output_storage ("static COB_INLINE COB_A_INLINE void");
342  output_storage ("cob_sub_align_s16 (void *p, const int val)");
343  output_storage ("{");
344  output_storage (" *(short __unaligned *)p -= val;");
345  output_storage ("}");
346  return;
347 
348  case COB_SUB_ALIGN_U32:
349  output_storage ("static COB_INLINE COB_A_INLINE void");
350  output_storage ("cob_sub_align_u32 (void *p, const int val)");
351  output_storage ("{");
352  output_storage (" *(unsigned int __unaligned *)p -= val;");
353  output_storage ("}");
354  return;
355 
356  case COB_SUB_ALIGN_S32:
357  output_storage ("static COB_INLINE COB_A_INLINE void");
358  output_storage ("cob_sub_align_s32 (void *p, const int val)");
359  output_storage ("{");
360  output_storage (" *(int __unaligned *)p -= val;");
361  output_storage ("}");
362  return;
363 
364  case COB_SUB_ALIGN_U64:
365  output_storage ("static COB_INLINE COB_A_INLINE void");
366  output_storage ("cob_sub_align_u64 (void *p, const int val)");
367  output_storage ("{");
368  output_storage (" *(cob_u64_t __unaligned *)p -= val;");
369  output_storage ("}");
370  return;
371 
372  case COB_SUB_ALIGN_S64:
373  output_storage ("static COB_INLINE COB_A_INLINE void");
374  output_storage ("cob_sub_align_s64 (void *p, const int val)");
375  output_storage ("{");
376  output_storage (" *(cob_s64_t __unaligned *)p -= val;");
377  output_storage ("}");
378  return;
379 
380  case COB_CMPSWP_ALIGN_U16:
381  output_storage ("static COB_INLINE COB_A_INLINE int");
382  output_storage ("cob_cmpswp_align_u16 (const void *p, const cob_s64_t n)");
383  output_storage ("{");
384  output_storage (" unsigned short val;");
385 
386  output_storage (" if (unlikely(n < 0)) {");
387  output_storage (" return 1;");
388  output_storage (" }");
389  output_storage (" val = COB_BSWAP_16 (*(unsigned short __unaligned *)p);");
390  output_storage (" return (val < n) ? -1 : (val > n);");
391  output_storage ("}");
392  return;
393 
394  case COB_CMPSWP_ALIGN_S16:
395  output_storage ("static COB_INLINE COB_A_INLINE int");
396  output_storage ("cob_cmpswp_align_s16 (const void *p, const cob_s64_t n)");
397  output_storage ("{");
398  output_storage (" short val;");
399 
400  output_storage (" val = COB_BSWAP_16 (*(short __unaligned *)p);");
401  output_storage (" return (val < n) ? -1 : (val > n);");
402  output_storage ("}");
403  return;
404 
405  case COB_CMPSWP_ALIGN_U32:
406  output_storage ("static COB_INLINE COB_A_INLINE int");
407  output_storage ("cob_cmpswp_align_u32 (const void *p, const cob_s64_t n)");
408  output_storage ("{");
409  output_storage (" unsigned int val;");
410 
411  output_storage (" if (unlikely(n < 0)) {");
412  output_storage (" return 1;");
413  output_storage (" }");
414  output_storage (" val = COB_BSWAP_32 (*(unsigned int __unaligned *)p);");
415  output_storage (" return (val < n) ? -1 : (val > n);");
416  output_storage ("}");
417  return;
418 
419  case COB_CMPSWP_ALIGN_S32:
420  output_storage ("static COB_INLINE COB_A_INLINE int");
421  output_storage ("cob_cmpswp_align_s32 (const void *p, const cob_s64_t n)");
422  output_storage ("{");
423  output_storage (" int val;");
424 
425  output_storage (" val = COB_BSWAP_32 (*(int __unaligned *)p);");
426  output_storage (" return (val < n) ? -1 : (val > n);");
427  output_storage ("}");
428  return;
429 
430  case COB_CMPSWP_ALIGN_U64:
431  output_storage ("static COB_INLINE COB_A_INLINE int");
432  output_storage ("cob_cmpswp_align_u64 (const void *p, const cob_s64_t n)");
433  output_storage ("{");
434  output_storage (" cob_u64_t val;");
435 
436  output_storage (" if (unlikely(n < 0)) {");
437  output_storage (" return 1;");
438  output_storage (" }");
439  output_storage (" val = COB_BSWAP_64 (*(cob_u64_t __unaligned *)p);");
440  output_storage (" return (val < n) ? -1 : (val > n);");
441  output_storage ("}");
442  return;
443 
444  case COB_CMPSWP_ALIGN_S64:
445  output_storage ("static COB_INLINE COB_A_INLINE int");
446  output_storage ("cob_cmpswp_align_s64 (const void *p, const cob_s64_t n)");
447  output_storage ("{");
448  output_storage (" cob_s64_t val;");
449 
450  output_storage (" val = COB_BSWAP_64 (*(cob_s64_t __unaligned *)p);");
451  output_storage (" return (val < n) ? -1 : (val > n);");
452  output_storage ("}");
453  return;
454 
455  /* Binary compare */
456 
457  case COB_CMP_U8:
458  output_storage ("static COB_INLINE COB_A_INLINE int");
459  output_storage ("cob_cmp_u8 (const void *p, const cob_s64_t n)");
460  output_storage ("{");
461  output_storage (" if (unlikely(n < 0)) {");
462  output_storage (" return 1;");
463  output_storage (" }");
464  output_storage (" return (*(const unsigned char *)p < n) ? -1 : (*(const unsigned char *)p > n);");
465  output_storage ("}");
466  return;
467 
468  case COB_CMP_S8:
469  output_storage ("static COB_INLINE COB_A_INLINE int");
470  output_storage ("cob_cmp_s8 (const void *p, const cob_s64_t n)");
471  output_storage ("{");
472  output_storage (" return (*(const signed char *)p < n) ? -1 : (*(const signed char *)p > n);");
473  output_storage ("}");
474  return;
475 
476  case COB_CMP_U16:
477  output_storage ("static COB_INLINE COB_A_INLINE int");
478  output_storage ("cob_cmp_u16 (const void *p, const cob_s64_t n)");
479  output_storage ("{");
480 #ifndef COB_ALLOW_UNALIGNED
481  output_storage (" void *x;");
482 #endif
483  output_storage (" unsigned short val;");
484 
485  output_storage (" if (unlikely(n < 0)) {");
486  output_storage (" return 1;");
487  output_storage (" }");
488 #ifdef COB_ALLOW_UNALIGNED
489  output_storage (" val = *(const unsigned short __unaligned *)p;");
490 #else
491  output_storage (" x = &val;");
492  output_storage (" optim_memcpy (x, p, 2);");
493 #endif
494  output_storage (" return (val < n) ? -1 : (val > n);");
495  output_storage ("}");
496  return;
497 
498  case COB_CMP_S16:
499  output_storage ("static COB_INLINE COB_A_INLINE int");
500  output_storage ("cob_cmp_s16 (const void *p, const cob_s64_t n)");
501  output_storage ("{");
502  output_storage (" short val;");
503 
504 #ifdef COB_ALLOW_UNALIGNED
505  output_storage (" val = *(const short __unaligned *)p;");
506 #else
507  output_storage (" void *x;");
508 
509  output_storage (" x = &val;");
510  output_storage (" optim_memcpy (x, p, 2);");
511 #endif
512  output_storage (" return (val < n) ? -1 : (val > n);");
513  output_storage ("}");
514  return;
515 
516  case COB_CMP_U24:
517  output_storage ("static COB_INLINE COB_A_INLINE int");
518  output_storage ("cob_cmp_u24 (const void *p, const cob_s64_t n)");
519  output_storage ("{");
520  output_storage (" unsigned char *x;");
521  output_storage (" unsigned int val = 0;");
522 
523  output_storage (" if (unlikely(n < 0)) {");
524  output_storage (" return 1;");
525  output_storage (" }");
526 #ifdef WORDS_BIGENDIAN
527  output_storage (" x = ((unsigned char *)&val) + 1;");
528 #else
529  output_storage (" x = (unsigned char *)&val;");
530 #endif
531  output_storage (" optim_memcpy (x, p, 3);");
532  output_storage (" return (val < n) ? -1 : (val > n);");
533  output_storage ("}");
534  return;
535 
536  case COB_CMP_S24:
537  output_storage ("static COB_INLINE COB_A_INLINE int");
538  output_storage ("cob_cmp_s24 (const void *p, const cob_s64_t n)");
539  output_storage ("{");
540  output_storage (" unsigned char *x;");
541  output_storage (" int val = 0;");
542 
543 #ifdef WORDS_BIGENDIAN
544  output_storage (" x = (unsigned char *)&val;");
545 #else
546  output_storage (" x = ((unsigned char *)&val) + 1;");
547 #endif
548  output_storage (" optim_memcpy (x, p, 3);");
549  output_storage (" val >>= 8; /* Shift with sign */");
550  output_storage (" return (val < n) ? -1 : (val > n);");
551  output_storage ("}");
552  return;
553 
554  case COB_CMP_U32:
555  output_storage ("static COB_INLINE COB_A_INLINE int");
556  output_storage ("cob_cmp_u32 (const void *p, const cob_s64_t n)");
557  output_storage ("{");
558 #ifndef COB_ALLOW_UNALIGNED
559  output_storage (" void *x;");
560 #endif
561  output_storage (" unsigned int val;");
562 
563  output_storage (" if (unlikely(n < 0)) {");
564  output_storage (" return 1;");
565  output_storage (" }");
566 #ifdef COB_ALLOW_UNALIGNED
567  output_storage (" val = *(const unsigned int __unaligned *)p;");
568 #else
569  output_storage (" x = &val;");
570  output_storage (" optim_memcpy (x, p, 4);");
571 #endif
572  output_storage (" return (val < n) ? -1 : (val > n);");
573  output_storage ("}");
574  return;
575 
576  case COB_CMP_S32:
577  output_storage ("static COB_INLINE COB_A_INLINE int");
578  output_storage ("cob_cmp_s32 (const void *p, const cob_s64_t n)");
579  output_storage ("{");
580  output_storage (" int val;");
581 
582 #ifdef COB_ALLOW_UNALIGNED
583  output_storage (" val = *(const int __unaligned *)p;");
584 #else
585  output_storage (" void *x;");
586 
587  output_storage (" x = &val;");
588  output_storage (" optim_memcpy (x, p, 4);");
589 #endif
590  output_storage (" return (val < n) ? -1 : (val > n);");
591  output_storage ("}");
592  return;
593 
594  case COB_CMP_U40:
595  output_storage ("static COB_INLINE COB_A_INLINE int");
596  output_storage ("cob_cmp_u40 (const void *p, const cob_s64_t n)");
597  output_storage ("{");
598  output_storage (" cob_u64_t val = 0;");
599  output_storage (" unsigned char *x;");
600 
601  output_storage (" if (unlikely(n < 0)) {");
602  output_storage (" return 1;");
603  output_storage (" }");
604 #ifdef WORDS_BIGENDIAN
605  output_storage (" x = ((unsigned char *)&val) + 3;");
606 #else
607  output_storage (" x = (unsigned char *)&val;");
608 #endif
609  output_storage (" optim_memcpy (x, p, 5);");
610  output_storage (" return (val < n) ? -1 : (val > n);");
611  output_storage ("}");
612  return;
613 
614  case COB_CMP_S40:
615  output_storage ("static COB_INLINE COB_A_INLINE int");
616  output_storage ("cob_cmp_s40 (const void *p, const cob_s64_t n)");
617  output_storage ("{");
618  output_storage (" cob_s64_t val = 0;");
619  output_storage (" unsigned char *x;");
620 
621 #ifdef WORDS_BIGENDIAN
622  output_storage (" x = (unsigned char *)&val;");
623 #else
624  output_storage (" x = ((unsigned char *)&val) + 3;");
625 #endif
626  output_storage (" optim_memcpy (x, p, 5);");
627  output_storage (" val >>= 24; /* Shift with sign */");
628  output_storage (" return (val < n) ? -1 : (val > n);");
629  output_storage ("}");
630  return;
631 
632  case COB_CMP_U48:
633  output_storage ("static COB_INLINE COB_A_INLINE int");
634  output_storage ("cob_cmp_u48 (const void *p, const cob_s64_t n)");
635  output_storage ("{");
636  output_storage (" cob_u64_t val = 0;");
637  output_storage (" unsigned char *x;");
638 
639  output_storage (" if (unlikely(n < 0)) {");
640  output_storage (" return 1;");
641  output_storage (" }");
642 #ifdef WORDS_BIGENDIAN
643  output_storage (" x = ((unsigned char *)&val) + 2;");
644 #else
645  output_storage (" x = (unsigned char *)&val;");
646 #endif
647  output_storage (" optim_memcpy (x, p, 6);");
648  output_storage (" return (val < n) ? -1 : (val > n);");
649  output_storage ("}");
650  return;
651 
652  case COB_CMP_S48:
653  output_storage ("static COB_INLINE COB_A_INLINE int");
654  output_storage ("cob_cmp_s48 (const void *p, const cob_s64_t n)");
655  output_storage ("{");
656  output_storage (" cob_s64_t val = 0;");
657  output_storage (" unsigned char *x;");
658 
659 #ifdef WORDS_BIGENDIAN
660  output_storage (" x = (unsigned char *)&val;");
661 #else
662  output_storage (" x = ((unsigned char *)&val) + 2;");
663 #endif
664  output_storage (" optim_memcpy (x, p, 6);");
665  output_storage (" val >>= 16; /* Shift with sign */");
666  output_storage (" return (val < n) ? -1 : (val > n);");
667  output_storage ("}");
668  return;
669 
670  case COB_CMP_U56:
671  output_storage ("static COB_INLINE COB_A_INLINE int");
672  output_storage ("cob_cmp_u56 (const void *p, const cob_s64_t n)");
673  output_storage ("{");
674  output_storage (" cob_u64_t val = 0;");
675  output_storage (" unsigned char *x;");
676 
677  output_storage (" if (unlikely(n < 0)) {");
678  output_storage (" return 1;");
679  output_storage (" }");
680 #ifdef WORDS_BIGENDIAN
681  output_storage (" x = ((unsigned char *)&val) + 1;");
682 #else
683  output_storage (" x = (unsigned char *)&val;");
684 #endif
685  output_storage (" optim_memcpy (x, p, 7);");
686  output_storage (" return (val < n) ? -1 : (val > n);");
687  output_storage ("}");
688  return;
689 
690  case COB_CMP_S56:
691  output_storage ("static COB_INLINE COB_A_INLINE int");
692  output_storage ("cob_cmp_s56 (const void *p, const cob_s64_t n)");
693  output_storage ("{");
694  output_storage (" cob_s64_t val = 0;");
695  output_storage (" unsigned char *x;");
696 
697 #ifdef WORDS_BIGENDIAN
698  output_storage (" x = (unsigned char *)&val;");
699 #else
700  output_storage (" x = ((unsigned char *)&val) + 1;");
701 #endif
702  output_storage (" optim_memcpy (x, p, 7);");
703  output_storage (" val >>= 8; /* Shift with sign */");
704  output_storage (" return (val < n) ? -1 : (val > n);");
705  output_storage ("}");
706  return;
707 
708  case COB_CMP_U64:
709  output_storage ("static COB_INLINE COB_A_INLINE int");
710  output_storage ("cob_cmp_u64 (const void *p, const cob_s64_t n)");
711  output_storage ("{");
712 #ifndef COB_ALLOW_UNALIGNED
713  output_storage (" void *x;");
714 #endif
715  output_storage (" cob_u64_t val;");
716 
717  output_storage (" if (unlikely(n < 0)) {");
718  output_storage (" return 1;");
719  output_storage (" }");
720 #ifdef COB_ALLOW_UNALIGNED
721  output_storage (" val = *(const cob_u64_t __unaligned *)p;");
722 #else
723  output_storage (" x = &val;");
724  output_storage (" optim_memcpy (x, p, 8);");
725 #endif
726  output_storage (" return (val < n) ? -1 : (val > n);");
727  output_storage ("}");
728  return;
729 
730  case COB_CMP_S64:
731  output_storage ("static COB_INLINE COB_A_INLINE int");
732  output_storage ("cob_cmp_s64 (const void *p, const cob_s64_t n)");
733  output_storage ("{");
734  output_storage (" cob_s64_t val;");
735 
736 #ifdef COB_ALLOW_UNALIGNED
737  output_storage (" val = *(const cob_s64_t __unaligned *)p;");
738 #else
739  output_storage (" void *x;");
740 
741  output_storage (" x = &val;");
742  output_storage (" optim_memcpy (x, p, 8);");
743 #endif
744  output_storage (" return (val < n) ? -1 : (val > n);");
745  output_storage ("}");
746  return;
747 
748  /* Add/Subtract */
749 
750  case COB_ADD_U8:
751  output_storage ("static COB_INLINE COB_A_INLINE void");
752  output_storage ("cob_add_u8 (void *p, const int val)");
753  output_storage ("{");
754  output_storage (" *(unsigned char *)p += val;");
755  output_storage ("}");
756  return;
757 
758  case COB_ADD_S8:
759  output_storage ("static COB_INLINE COB_A_INLINE void");
760  output_storage ("cob_add_s8 (void *p, const int val)");
761  output_storage ("{");
762  output_storage (" *(signed char *)p += val;");
763  output_storage ("}");
764  return;
765 
766  case COB_ADD_U16:
767  output_storage ("static COB_INLINE COB_A_INLINE void");
768  output_storage ("cob_add_u16 (void *p, const int val)");
769  output_storage ("{");
770 #ifdef COB_ALLOW_UNALIGNED
771  output_storage (" *(unsigned short __unaligned *)p += val;");
772 #else
773  output_storage (" void *x;");
774  output_storage (" unsigned short n;");
775 
776  output_storage (" x = &n;");
777  output_storage (" optim_memcpy (x, p, 2);");
778  output_storage (" n += val;");
779  output_storage (" optim_memcpy (p, x, 2);");
780 #endif
781  output_storage ("}");
782  return;
783 
784  case COB_ADD_S16:
785  output_storage ("static COB_INLINE COB_A_INLINE void");
786  output_storage ("cob_add_s16 (void *p, const int val)");
787  output_storage ("{");
788 #ifdef COB_ALLOW_UNALIGNED
789  output_storage (" *(short __unaligned *)p += val;");
790 #else
791  output_storage (" void *x;");
792  output_storage (" short n;");
793 
794  output_storage (" x = &n;");
795  output_storage (" optim_memcpy (x, p, 2);");
796  output_storage (" n += val;");
797  output_storage (" optim_memcpy (p, x, 2);");
798 #endif
799  output_storage ("}");
800  return;
801 
802  case COB_ADD_U24:
803  output_storage ("static COB_INLINE COB_A_INLINE void");
804  output_storage ("cob_add_u24 (void *p, const int val)");
805  output_storage ("{");
806  output_storage (" unsigned char *x;");
807  output_storage (" unsigned int n = 0;");
808 
809 #ifdef WORDS_BIGENDIAN
810  output_storage (" x = ((unsigned char *)&n) + 1;");
811 #else
812  output_storage (" x = (unsigned char *)&n;");
813 #endif
814  output_storage (" optim_memcpy (x, p, 3);");
815  output_storage (" n += val;");
816  output_storage (" optim_memcpy (p, x, 3);");
817  output_storage ("}");
818  return;
819 
820  case COB_ADD_S24:
821  output_storage ("static COB_INLINE COB_A_INLINE void");
822  output_storage ("cob_add_s24 (void *p, const int val)");
823  output_storage ("{");
824  output_storage (" unsigned char *x;");
825  output_storage (" int n = 0;");
826 
827 #ifdef WORDS_BIGENDIAN
828  output_storage (" x = (unsigned char *)&n;");
829 #else
830  output_storage (" x = ((unsigned char *)&n) + 1;");
831 #endif
832  output_storage (" optim_memcpy (x, p, 3);");
833  output_storage (" n >>= 8; /* Shift with sign */");
834  output_storage (" n += val;");
835 #ifdef WORDS_BIGENDIAN
836  output_storage (" x = ((unsigned char *)&n) + 1;");
837 #else
838  output_storage (" x = (unsigned char *)&n;");
839 #endif
840  output_storage (" optim_memcpy (p, x, 3);");
841  output_storage ("}");
842  return;
843 
844  case COB_ADD_U32:
845  output_storage ("static COB_INLINE COB_A_INLINE void");
846  output_storage ("cob_add_u32 (void *p, const int val)");
847  output_storage ("{");
848 #ifdef COB_ALLOW_UNALIGNED
849  output_storage (" *(unsigned int __unaligned *)p += val;");
850 #else
851  output_storage (" void *x;");
852  output_storage (" unsigned int n;");
853 
854  output_storage (" x = &n;");
855  output_storage (" optim_memcpy (x, p, 4);");
856  output_storage (" n += val;");
857  output_storage (" optim_memcpy (p, x, 4);");
858 #endif
859  output_storage ("}");
860  return;
861 
862  case COB_ADD_S32:
863  output_storage ("static COB_INLINE COB_A_INLINE void");
864  output_storage ("cob_add_s32 (void *p, const int val)");
865  output_storage ("{");
866 #ifdef COB_ALLOW_UNALIGNED
867  output_storage (" *(int __unaligned *)p += val;");
868 #else
869  output_storage (" void *x;");
870  output_storage (" int n;");
871 
872  output_storage (" x = &n;");
873  output_storage (" optim_memcpy (x, p, 4);");
874  output_storage (" n += val;");
875  output_storage (" optim_memcpy (p, x, 4);");
876 #endif
877  output_storage ("}");
878  return;
879 
880  case COB_ADD_U40:
881  output_storage ("static COB_INLINE COB_A_INLINE void");
882  output_storage ("cob_add_u40 (void *p, const int val)");
883  output_storage ("{");
884  output_storage (" cob_u64_t n = 0;");
885  output_storage (" unsigned char *x;");
886 
887 #ifdef WORDS_BIGENDIAN
888  output_storage (" x = ((unsigned char *)&n) + 3;");
889 #else
890  output_storage (" x = (unsigned char *)&n;");
891 #endif
892  output_storage (" optim_memcpy (x, p, 5);");
893  output_storage (" n += val;");
894  output_storage (" optim_memcpy (p, x, 5);");
895  output_storage ("}");
896  return;
897 
898  case COB_ADD_S40:
899  output_storage ("static COB_INLINE COB_A_INLINE void");
900  output_storage ("cob_add_s40 (void *p, const int val)");
901  output_storage ("{");
902  output_storage (" cob_s64_t n = 0;");
903  output_storage (" unsigned char *x;");
904 
905 #ifdef WORDS_BIGENDIAN
906  output_storage (" x = (unsigned char *)&n;");
907 #else
908  output_storage (" x = ((unsigned char *)&n) + 3;");
909 #endif
910  output_storage (" optim_memcpy (x, p, 5);");
911  output_storage (" n >>= 24; /* Shift with sign */");
912  output_storage (" n += val;");
913 #ifdef WORDS_BIGENDIAN
914  output_storage (" x = ((unsigned char *)&n) + 3;");
915 #else
916  output_storage (" x = (unsigned char *)&n;");
917 #endif
918  output_storage (" optim_memcpy (p, x, 5);");
919  output_storage ("}");
920  return;
921 
922  case COB_ADD_U48:
923  output_storage ("static COB_INLINE COB_A_INLINE void");
924  output_storage ("cob_add_u48 (void *p, const int val)");
925  output_storage ("{");
926  output_storage (" cob_u64_t n = 0;");
927  output_storage (" unsigned char *x;");
928 
929 #ifdef WORDS_BIGENDIAN
930  output_storage (" x = ((unsigned char *)&n) + 2;");
931 #else
932  output_storage (" x = (unsigned char *)&n;");
933 #endif
934  output_storage (" optim_memcpy (x, p, 6);");
935  output_storage (" n += val;");
936  output_storage (" optim_memcpy (p, x, 6);");
937  output_storage ("}");
938  return;
939 
940  case COB_ADD_S48:
941  output_storage ("static COB_INLINE COB_A_INLINE void");
942  output_storage ("cob_add_s48 (void *p, const int val)");
943  output_storage ("{");
944  output_storage (" cob_s64_t n = 0;");
945  output_storage (" unsigned char *x;");
946 
947 #ifdef WORDS_BIGENDIAN
948  output_storage (" x = (unsigned char *)&n;");
949 #else
950  output_storage (" x = ((unsigned char *)&n) + 2;");
951 #endif
952  output_storage (" optim_memcpy (x, p, 6);");
953  output_storage (" n >>= 16; /* Shift with sign */");
954  output_storage (" n += val;");
955 #ifdef WORDS_BIGENDIAN
956  output_storage (" x = ((unsigned char *)&n) + 2;");
957 #else
958  output_storage (" x = (unsigned char *)&n;");
959 #endif
960  output_storage (" optim_memcpy (p, x, 6);");
961  output_storage ("}");
962  return;
963 
964  case COB_ADD_U56:
965  output_storage ("static COB_INLINE COB_A_INLINE void");
966  output_storage ("cob_add_u56 (void *p, const int val)");
967  output_storage ("{");
968  output_storage (" cob_u64_t n = 0;");
969  output_storage (" unsigned char *x;");
970 
971 #ifdef WORDS_BIGENDIAN
972  output_storage (" x = ((unsigned char *)&n) + 1;");
973 #else
974  output_storage (" x = (unsigned char *)&n;");
975 #endif
976  output_storage (" optim_memcpy (x, p, 7);");
977  output_storage (" n += val;");
978  output_storage (" optim_memcpy (p, x, 7);");
979  output_storage ("}");
980  return;
981 
982  case COB_ADD_S56:
983  output_storage ("static COB_INLINE COB_A_INLINE void");
984  output_storage ("cob_add_s56 (void *p, const int val)");
985  output_storage ("{");
986  output_storage (" cob_s64_t n = 0;");
987  output_storage (" unsigned char *x;");
988 
989 #ifdef WORDS_BIGENDIAN
990  output_storage (" x = (unsigned char *)&n;");
991 #else
992  output_storage (" x = ((unsigned char *)&n) + 1;");
993 #endif
994  output_storage (" optim_memcpy (x, p, 7);");
995  output_storage (" n >>= 8; /* Shift with sign */");
996  output_storage (" n += val;");
997 #ifdef WORDS_BIGENDIAN
998  output_storage (" x = ((unsigned char *)&n) + 1;");
999 #else
1000  output_storage (" x = (unsigned char *)&n;");
1001 #endif
1002  output_storage (" optim_memcpy (p, x, 7);");
1003  output_storage ("}");
1004  return;
1005 
1006  case COB_ADD_U64:
1007  output_storage ("static COB_INLINE COB_A_INLINE void");
1008  output_storage ("cob_add_u64 (void *p, const int val)");
1009  output_storage ("{");
1010 #ifdef COB_ALLOW_UNALIGNED
1011  output_storage (" *(cob_u64_t __unaligned *)p += val;");
1012 #else
1013  output_storage (" void *x;");
1014  output_storage (" cob_u64_t n;");
1015 
1016  output_storage (" x = &n;");
1017  output_storage (" optim_memcpy (x, p, 8);");
1018  output_storage (" n += val;");
1019  output_storage (" optim_memcpy (p, x, 8);");
1020 #endif
1021  output_storage ("}");
1022  return;
1023 
1024  case COB_ADD_S64:
1025  output_storage ("static COB_INLINE COB_A_INLINE void");
1026  output_storage ("cob_add_s64 (void *p, const int val)");
1027  output_storage ("{");
1028 #ifdef COB_ALLOW_UNALIGNED
1029  output_storage (" *(cob_s64_t __unaligned *)p += val;");
1030 #else
1031  output_storage (" void *x;");
1032  output_storage (" cob_s64_t n;");
1033 
1034  output_storage (" x = &n;");
1035  output_storage (" optim_memcpy (x, p, 8);");
1036  output_storage (" n += val;");
1037  output_storage (" optim_memcpy (p, x, 8);");
1038 #endif
1039  output_storage ("}");
1040  return;
1041 
1042  case COB_SUB_U8:
1043  output_storage ("static COB_INLINE COB_A_INLINE void");
1044  output_storage ("cob_sub_u8 (void *p, const int val)");
1045  output_storage ("{");
1046  output_storage (" *(unsigned char *)p -= val;");
1047  output_storage ("}");
1048  return;
1049 
1050  case COB_SUB_S8:
1051  output_storage ("static COB_INLINE COB_A_INLINE void");
1052  output_storage ("cob_sub_s8 (void *p, const int val)");
1053  output_storage ("{");
1054  output_storage (" *(signed char *)p -= val;");
1055  output_storage ("}");
1056  return;
1057 
1058  case COB_SUB_U16:
1059  output_storage ("static COB_INLINE COB_A_INLINE void");
1060  output_storage ("cob_sub_u16 (void *p, const int val)");
1061  output_storage ("{");
1062 #ifdef COB_ALLOW_UNALIGNED
1063  output_storage (" *(unsigned short __unaligned *)p -= val;");
1064 #else
1065  output_storage (" void *x;");
1066  output_storage (" unsigned short n;");
1067 
1068  output_storage (" x = &n;");
1069  output_storage (" optim_memcpy (x, p, 2);");
1070  output_storage (" n -= val;");
1071  output_storage (" optim_memcpy (p, x, 2);");
1072 #endif
1073  output_storage ("}");
1074  return;
1075 
1076  case COB_SUB_S16:
1077  output_storage ("static COB_INLINE COB_A_INLINE void");
1078  output_storage ("cob_sub_s16 (void *p, const int val)");
1079  output_storage ("{");
1080 #ifdef COB_ALLOW_UNALIGNED
1081  output_storage (" *(short __unaligned *)p -= val;");
1082 #else
1083  output_storage (" void *x;");
1084  output_storage (" short n;");
1085 
1086  output_storage (" x = &n;");
1087  output_storage (" optim_memcpy (x, p, 2);");
1088  output_storage (" n -= val;");
1089  output_storage (" optim_memcpy (p, x, 2);");
1090 #endif
1091  output_storage ("}");
1092  return;
1093 
1094  case COB_SUB_U24:
1095  output_storage ("static COB_INLINE COB_A_INLINE void");
1096  output_storage ("cob_sub_u24 (void *p, const int val)");
1097  output_storage ("{");
1098  output_storage (" unsigned char *x;");
1099  output_storage (" unsigned int n = 0;");
1100 
1101 #ifdef WORDS_BIGENDIAN
1102  output_storage (" x = ((unsigned char *)&n) + 1;");
1103 #else
1104  output_storage (" x = (unsigned char *)&n;");
1105 #endif
1106  output_storage (" optim_memcpy (x, p, 3);");
1107  output_storage (" n -= val;");
1108  output_storage (" optim_memcpy (p, x, 3);");
1109  output_storage ("}");
1110  return;
1111 
1112  case COB_SUB_S24:
1113  output_storage ("static COB_INLINE COB_A_INLINE void");
1114  output_storage ("cob_sub_s24 (void *p, const int val)");
1115  output_storage ("{");
1116  output_storage (" unsigned char *x;");
1117  output_storage (" int n = 0;");
1118 
1119 #ifdef WORDS_BIGENDIAN
1120  output_storage (" x = (unsigned char *)&n;");
1121 #else
1122  output_storage (" x = ((unsigned char *)&n) + 1;");
1123 #endif
1124  output_storage (" optim_memcpy (x, p, 3);");
1125  output_storage (" n >>= 8; /* Shift with sign */");
1126  output_storage (" n -= val;");
1127 #ifdef WORDS_BIGENDIAN
1128  output_storage (" x = ((unsigned char *)&n) + 1;");
1129 #else
1130  output_storage (" x = (unsigned char *)&n;");
1131 #endif
1132  output_storage (" optim_memcpy (p, x, 3);");
1133  output_storage ("}");
1134  return;
1135 
1136  case COB_SUB_U32:
1137  output_storage ("static COB_INLINE COB_A_INLINE void");
1138  output_storage ("cob_sub_u32 (void *p, const int val)");
1139  output_storage ("{");
1140 #ifdef COB_ALLOW_UNALIGNED
1141  output_storage (" *(unsigned int __unaligned *)p -= val;");
1142 #else
1143  output_storage (" void *x;");
1144  output_storage (" unsigned int n;");
1145 
1146  output_storage (" x = &n;");
1147  output_storage (" optim_memcpy (x, p, 4);");
1148  output_storage (" n -= val;");
1149  output_storage (" optim_memcpy (p, x, 4);");
1150 #endif
1151  output_storage ("}");
1152  return;
1153 
1154  case COB_SUB_S32:
1155  output_storage ("static COB_INLINE COB_A_INLINE void");
1156  output_storage ("cob_sub_s32 (void *p, const int val)");
1157  output_storage ("{");
1158 #ifdef COB_ALLOW_UNALIGNED
1159  output_storage (" *(int __unaligned *)p -= val;");
1160 #else
1161  output_storage (" void *x;");
1162  output_storage (" int n;");
1163 
1164  output_storage (" x = &n;");
1165  output_storage (" optim_memcpy (x, p, 4);");
1166  output_storage (" n -= val;");
1167  output_storage (" optim_memcpy (p, x, 4);");
1168 #endif
1169  output_storage ("}");
1170  return;
1171 
1172  case COB_SUB_U40:
1173  output_storage ("static COB_INLINE COB_A_INLINE void");
1174  output_storage ("cob_sub_u40 (void *p, const int val)");
1175  output_storage ("{");
1176  output_storage (" cob_u64_t n = 0;");
1177  output_storage (" unsigned char *x;");
1178 
1179 #ifdef WORDS_BIGENDIAN
1180  output_storage (" x = ((unsigned char *)&n) + 3;");
1181 #else
1182  output_storage (" x = (unsigned char *)&n;");
1183 #endif
1184  output_storage (" optim_memcpy (x, p, 5);");
1185  output_storage (" n -= val;");
1186  output_storage (" optim_memcpy (p, x, 5);");
1187  output_storage ("}");
1188  return;
1189 
1190  case COB_SUB_S40:
1191  output_storage ("static COB_INLINE COB_A_INLINE void");
1192  output_storage ("cob_sub_s40 (void *p, const int val)");
1193  output_storage ("{");
1194  output_storage (" cob_s64_t n = 0;");
1195  output_storage (" unsigned char *x;");
1196 
1197 #ifdef WORDS_BIGENDIAN
1198  output_storage (" x = (unsigned char *)&n;");
1199 #else
1200  output_storage (" x = ((unsigned char *)&n) + 3;");
1201 #endif
1202  output_storage (" optim_memcpy (x, p, 5);");
1203  output_storage (" n >>= 24; /* Shift with sign */");
1204  output_storage (" n -= val;");
1205 #ifdef WORDS_BIGENDIAN
1206  output_storage (" x = ((unsigned char *)&n) + 3;");
1207 #else
1208  output_storage (" x = (unsigned char *)&n;");
1209 #endif
1210  output_storage (" optim_memcpy (p, x, 5);");
1211  output_storage ("}");
1212  return;
1213 
1214  case COB_SUB_U48:
1215  output_storage ("static COB_INLINE COB_A_INLINE void");
1216  output_storage ("cob_sub_u48 (void *p, const int val)");
1217  output_storage ("{");
1218  output_storage (" cob_u64_t n = 0;");
1219  output_storage (" unsigned char *x;");
1220 
1221 #ifdef WORDS_BIGENDIAN
1222  output_storage (" x = ((unsigned char *)&n) + 2;");
1223 #else
1224  output_storage (" x = (unsigned char *)&n;");
1225 #endif
1226  output_storage (" optim_memcpy (x, p, 6);");
1227  output_storage (" n -= val;");
1228  output_storage (" optim_memcpy (p, x, 6);");
1229  output_storage ("}");
1230  return;
1231 
1232  case COB_SUB_S48:
1233  output_storage ("static COB_INLINE COB_A_INLINE void");
1234  output_storage ("cob_sub_s48 (void *p, const int val)");
1235  output_storage ("{");
1236  output_storage (" cob_s64_t n = 0;");
1237  output_storage (" unsigned char *x;");
1238 
1239 #ifdef WORDS_BIGENDIAN
1240  output_storage (" x = (unsigned char *)&n;");
1241 #else
1242  output_storage (" x = ((unsigned char *)&n) + 2;");
1243 #endif
1244  output_storage (" optim_memcpy (x, p, 6);");
1245  output_storage (" n >>= 16; /* Shift with sign */");
1246  output_storage (" n -= val;");
1247 #ifdef WORDS_BIGENDIAN
1248  output_storage (" x = ((unsigned char *)&n) + 2;");
1249 #else
1250  output_storage (" x = (unsigned char *)&n;");
1251 #endif
1252  output_storage (" optim_memcpy (p, x, 6);");
1253  output_storage ("}");
1254  return;
1255 
1256  case COB_SUB_U56:
1257  output_storage ("static COB_INLINE COB_A_INLINE void");
1258  output_storage ("cob_sub_u56 (void *p, const int val)");
1259  output_storage ("{");
1260  output_storage (" cob_u64_t n = 0;");
1261  output_storage (" unsigned char *x;");
1262 
1263 #ifdef WORDS_BIGENDIAN
1264  output_storage (" x = ((unsigned char *)&n) + 1;");
1265 #else
1266  output_storage (" x = (unsigned char *)&n;");
1267 #endif
1268  output_storage (" optim_memcpy (x, p, 7);");
1269  output_storage (" n -= val;");
1270  output_storage (" optim_memcpy (p, x, 7);");
1271  output_storage ("}");
1272  return;
1273 
1274  case COB_SUB_S56:
1275  output_storage ("static COB_INLINE COB_A_INLINE void");
1276  output_storage ("cob_sub_s56 (void *p, const int val)");
1277  output_storage ("{");
1278  output_storage (" cob_s64_t n = 0;");
1279  output_storage (" unsigned char *x;");
1280 
1281 #ifdef WORDS_BIGENDIAN
1282  output_storage (" x = (unsigned char *)&n;");
1283 #else
1284  output_storage (" x = ((unsigned char *)&n) + 1;");
1285 #endif
1286  output_storage (" optim_memcpy (x, p, 7);");
1287  output_storage (" n >>= 8; /* Shift with sign */");
1288  output_storage (" n -= val;");
1289 #ifdef WORDS_BIGENDIAN
1290  output_storage (" x = ((unsigned char *)&n) + 1;");
1291 #else
1292  output_storage (" x = (unsigned char *)&n;");
1293 #endif
1294  output_storage (" optim_memcpy (p, x, 7);");
1295  output_storage ("}");
1296  return;
1297 
1298  case COB_SUB_U64:
1299  output_storage ("static COB_INLINE COB_A_INLINE void");
1300  output_storage ("cob_sub_u64 (void *p, const int val)");
1301  output_storage ("{");
1302 #ifdef COB_ALLOW_UNALIGNED
1303  output_storage (" *(cob_u64_t __unaligned *)p -= val;");
1304 #else
1305  output_storage (" void *x;");
1306  output_storage (" cob_u64_t n;");
1307 
1308  output_storage (" x = &n;");
1309  output_storage (" optim_memcpy (x, p, 8);");
1310  output_storage (" n -= val;");
1311  output_storage (" optim_memcpy (p, x, 8);");
1312 #endif
1313  output_storage ("}");
1314  return;
1315 
1316  case COB_SUB_S64:
1317  output_storage ("static COB_INLINE COB_A_INLINE void");
1318  output_storage ("cob_sub_s64 (void *p, const int val)");
1319  output_storage ("{");
1320 #ifdef COB_ALLOW_UNALIGNED
1321  output_storage (" *(cob_s64_t __unaligned *)p -= val;");
1322 #else
1323  output_storage (" void *x;");
1324  output_storage (" cob_s64_t n;");
1325 
1326  output_storage (" x = &n;");
1327  output_storage (" optim_memcpy (x, p, 8);");
1328  output_storage (" n -= val;");
1329  output_storage (" optim_memcpy (p, x, 8);");
1330 #endif
1331  output_storage ("}");
1332  return;
1333 
1334  /* Binary swapped compare */
1335 
1336  case COB_CMPSWP_U16:
1337  output_storage ("static COB_INLINE COB_A_INLINE int");
1338  output_storage ("cob_cmpswp_u16 (const void *p, const cob_s64_t n)");
1339  output_storage ("{");
1340 #ifndef COB_ALLOW_UNALIGNED
1341  output_storage (" void *x;");
1342 #endif
1343  output_storage (" unsigned short val;");
1344 
1345  output_storage (" if (unlikely(n < 0)) {");
1346  output_storage (" return 1;");
1347  output_storage (" }");
1348 #ifdef COB_ALLOW_UNALIGNED
1349  output_storage (" val = COB_BSWAP_16 (*(unsigned short __unaligned *)p);");
1350 #else
1351  output_storage (" x = &val;");
1352  output_storage (" optim_memcpy (x, p, 2);");
1353  output_storage (" val = COB_BSWAP_16 (val);");
1354 #endif
1355  output_storage (" return (val < n) ? -1 : (val > n);");
1356  output_storage ("}");
1357  return;
1358 
1359  case COB_CMPSWP_S16:
1360  output_storage ("static COB_INLINE COB_A_INLINE int");
1361  output_storage ("cob_cmpswp_s16 (const void *p, const cob_s64_t n)");
1362  output_storage ("{");
1363  output_storage (" short val;");
1364 
1365 #ifdef COB_ALLOW_UNALIGNED
1366  output_storage (" val = COB_BSWAP_16 (*(short __unaligned *)p);");
1367 #else
1368  output_storage (" void *x;");
1369 
1370  output_storage (" x = &val;");
1371  output_storage (" optim_memcpy (x, p, 2);");
1372  output_storage (" val = COB_BSWAP_16 (val);");
1373 #endif
1374  output_storage (" return (val < n) ? -1 : (val > n);");
1375  output_storage ("}");
1376  return;
1377 
1378  case COB_CMPSWP_U24:
1379  output_storage ("static COB_INLINE COB_A_INLINE int");
1380  output_storage ("cob_cmpswp_u24 (const void *p, const cob_s64_t n)");
1381  output_storage ("{");
1382  output_storage (" unsigned char *x;");
1383  output_storage (" unsigned int val = 0;");
1384 
1385  output_storage (" if (unlikely(n < 0)) {");
1386  output_storage (" return 1;");
1387  output_storage (" }");
1388  output_storage (" x = ((unsigned char *)&val) + 1;");
1389  output_storage (" optim_memcpy (x, p, 3);");
1390  output_storage (" val = COB_BSWAP_32 (val);");
1391  output_storage (" return (val < n) ? -1 : (val > n);");
1392  output_storage ("}");
1393  return;
1394 
1395  case COB_CMPSWP_S24:
1396  output_storage ("static COB_INLINE COB_A_INLINE int");
1397  output_storage ("cob_cmpswp_s24 (const void *p, const cob_s64_t n)");
1398  output_storage ("{");
1399  output_storage (" unsigned char *x;");
1400  output_storage (" int val = 0;");
1401 
1402  output_storage (" x = (unsigned char *)&val;");
1403  output_storage (" optim_memcpy (x, p, 3);");
1404  output_storage (" val = COB_BSWAP_32 (val);");
1405  output_storage (" val >>= 8; /* Shift with sign */");
1406  output_storage (" return (val < n) ? -1 : (val > n);");
1407  output_storage ("}");
1408  return;
1409 
1410  case COB_CMPSWP_U32:
1411  output_storage ("static COB_INLINE COB_A_INLINE int");
1412  output_storage ("cob_cmpswp_u32 (const void *p, const cob_s64_t n)");
1413  output_storage ("{");
1414 #ifndef COB_ALLOW_UNALIGNED
1415  output_storage (" void *x;");
1416 #endif
1417  output_storage (" unsigned int val;");
1418 
1419  output_storage (" if (unlikely(n < 0)) {");
1420  output_storage (" return 1;");
1421  output_storage (" }");
1422 #ifdef COB_ALLOW_UNALIGNED
1423  output_storage (" val = COB_BSWAP_32 (*(const unsigned int __unaligned *)p);");
1424 #else
1425  output_storage (" x = &val;");
1426  output_storage (" optim_memcpy (x, p, 4);");
1427  output_storage (" val = COB_BSWAP_32 (val);");
1428 #endif
1429  output_storage (" return (val < n) ? -1 : (val > n);");
1430  output_storage ("}");
1431  return;
1432 
1433  case COB_CMPSWP_S32:
1434  output_storage ("static COB_INLINE COB_A_INLINE int");
1435  output_storage ("cob_cmpswp_s32 (const void *p, const cob_s64_t n)");
1436  output_storage ("{");
1437  output_storage (" int val;");
1438 
1439 #ifdef COB_ALLOW_UNALIGNED
1440  output_storage (" val = COB_BSWAP_32 (*(const int __unaligned *)p);");
1441 #else
1442  output_storage (" void *x;");
1443 
1444  output_storage (" x = &val;");
1445  output_storage (" optim_memcpy (x, p, 4);");
1446  output_storage (" val = COB_BSWAP_32 (val);");
1447 #endif
1448  output_storage (" return (val < n) ? -1 : (val > n);");
1449  output_storage ("}");
1450  return;
1451 
1452  case COB_CMPSWP_U40:
1453  output_storage ("static COB_INLINE COB_A_INLINE int");
1454  output_storage ("cob_cmpswp_u40 (const void *p, const cob_s64_t n)");
1455  output_storage ("{");
1456  output_storage (" cob_u64_t val = 0;");
1457  output_storage (" unsigned char *x;");
1458 
1459  output_storage (" if (unlikely(n < 0)) {");
1460  output_storage (" return 1;");
1461  output_storage (" }");
1462  output_storage (" x = ((unsigned char *)&val) + 3;");
1463  output_storage (" optim_memcpy (x, p, 5);");
1464  output_storage (" val = COB_BSWAP_64 (val);");
1465  output_storage (" return (val < n) ? -1 : (val > n);");
1466  output_storage ("}");
1467  return;
1468 
1469  case COB_CMPSWP_S40:
1470  output_storage ("static COB_INLINE COB_A_INLINE int");
1471  output_storage ("cob_cmpswp_s40 (const void *p, const cob_s64_t n)");
1472  output_storage ("{");
1473  output_storage (" cob_s64_t val = 0;");
1474  output_storage (" unsigned char *x;");
1475 
1476  output_storage (" x = (unsigned char *)&val;");
1477  output_storage (" optim_memcpy (x, p, 5);");
1478  output_storage (" val = COB_BSWAP_64 (val);");
1479  output_storage (" val >>= 24; /* Shift with sign */");
1480  output_storage (" return (val < n) ? -1 : (val > n);");
1481  output_storage ("}");
1482  return;
1483 
1484  case COB_CMPSWP_U48:
1485  output_storage ("static COB_INLINE COB_A_INLINE int");
1486  output_storage ("cob_cmpswp_u48 (const void *p, const cob_s64_t n)");
1487  output_storage ("{");
1488  output_storage (" cob_u64_t val = 0;");
1489  output_storage (" unsigned char *x;");
1490 
1491  output_storage (" if (unlikely(n < 0)) {");
1492  output_storage (" return 1;");
1493  output_storage (" }");
1494  output_storage (" x = ((unsigned char *)&val) + 2;");
1495  output_storage (" optim_memcpy (x, p, 6);");
1496  output_storage (" val = COB_BSWAP_64 (val);");
1497  output_storage (" return (val < n) ? -1 : (val > n);");
1498  output_storage ("}");
1499  return;
1500 
1501  case COB_CMPSWP_S48:
1502  output_storage ("static COB_INLINE COB_A_INLINE int");
1503  output_storage ("cob_cmpswp_s48 (const void *p, const cob_s64_t n)");
1504  output_storage ("{");
1505  output_storage (" cob_s64_t val = 0;");
1506  output_storage (" unsigned char *x;");
1507 
1508  output_storage (" x = (unsigned char *)&val;");
1509  output_storage (" optim_memcpy (x, p, 6);");
1510  output_storage (" val = COB_BSWAP_64 (val);");
1511  output_storage (" val >>= 16; /* Shift with sign */");
1512  output_storage (" return (val < n) ? -1 : (val > n);");
1513  output_storage ("}");
1514  return;
1515 
1516  case COB_CMPSWP_U56:
1517  output_storage ("static COB_INLINE COB_A_INLINE int");
1518  output_storage ("cob_cmpswp_u56 (const void *p, const cob_s64_t n)");
1519  output_storage ("{");
1520  output_storage (" cob_u64_t val = 0;");
1521  output_storage (" unsigned char *x;");
1522 
1523  output_storage (" if (unlikely(n < 0)) {");
1524  output_storage (" return 1;");
1525  output_storage (" }");
1526  output_storage (" x = ((unsigned char *)&val) + 1;");
1527  output_storage (" optim_memcpy (x, p, 7);");
1528  output_storage (" val = COB_BSWAP_64 (val);");
1529  output_storage (" return (val < n) ? -1 : (val > n);");
1530  output_storage ("}");
1531  return;
1532 
1533  case COB_CMPSWP_S56:
1534  output_storage ("static COB_INLINE COB_A_INLINE int");
1535  output_storage ("cob_cmpswp_s56 (const void *p, const cob_s64_t n)");
1536  output_storage ("{");
1537  output_storage (" cob_s64_t val = 0;");
1538  output_storage (" unsigned char *x;");
1539 
1540  output_storage (" x = (unsigned char *)&val;");
1541  output_storage (" optim_memcpy (x, p, 7);");
1542  output_storage (" val = COB_BSWAP_64 (val);");
1543  output_storage (" val >>= 8; /* Shift with sign */");
1544  output_storage (" return (val < n) ? -1 : (val > n);");
1545  output_storage ("}");
1546  return;
1547 
1548  case COB_CMPSWP_U64:
1549  output_storage ("static COB_INLINE COB_A_INLINE int");
1550  output_storage ("cob_cmpswp_u64 (const void *p, const cob_s64_t n)");
1551  output_storage ("{");
1552 #ifndef COB_ALLOW_UNALIGNED
1553  output_storage (" void *x;");
1554 #endif
1555  output_storage (" cob_u64_t val;");
1556 
1557  output_storage (" if (unlikely(n < 0)) {");
1558  output_storage (" return 1;");
1559  output_storage (" }");
1560 #ifdef COB_ALLOW_UNALIGNED
1561  output_storage (" val = COB_BSWAP_64 (*(const cob_u64_t __unaligned *)p);");
1562 #else
1563  output_storage (" x = &val;");
1564  output_storage (" optim_memcpy (x, p, 8);");
1565  output_storage (" val = COB_BSWAP_64 (val);");
1566 #endif
1567  output_storage (" return (val < n) ? -1 : (val > n);");
1568  output_storage ("}");
1569  return;
1570 
1571  case COB_CMPSWP_S64:
1572  output_storage ("static COB_INLINE COB_A_INLINE int");
1573  output_storage ("cob_cmpswp_s64 (const void *p, const cob_s64_t n)");
1574  output_storage ("{");
1575  output_storage (" cob_s64_t val;");
1576 
1577 #ifdef COB_ALLOW_UNALIGNED
1578  output_storage (" val = COB_BSWAP_64 (*(const cob_s64_t __unaligned *)p);");
1579 #else
1580  output_storage (" void *x;");
1581  output_storage (" x = &val;");
1582  output_storage (" optim_memcpy (x, p, 8);");
1583  output_storage (" val = COB_BSWAP_64 (val);");
1584 #endif
1585  output_storage (" return (val < n) ? -1 : (val > n);");
1586  output_storage ("}");
1587  return;
1588 
1589  /* Binary swapped add */
1590 
1591  case COB_ADDSWP_U16:
1592  output_storage ("static COB_INLINE COB_A_INLINE void");
1593  output_storage ("cob_addswp_u16 (void *p, const int val)");
1594  output_storage ("{");
1595  output_storage (" unsigned short n;");
1596 
1597 #ifdef COB_ALLOW_UNALIGNED
1598  output_storage (" n = COB_BSWAP_16 (*(unsigned short __unaligned *)p);");
1599  output_storage (" n += val;");
1600  output_storage (" *(unsigned short __unaligned *)p = COB_BSWAP_16(n);");
1601 #else
1602  output_storage (" unsigned char *x;");
1603  output_storage (" unsigned char *px = p;");
1604 
1605  output_storage (" x = (unsigned char *)&n;");
1606  output_storage (" x[0] = px[1];");
1607  output_storage (" x[1] = px[0];");
1608  output_storage (" n += val;");
1609  output_storage (" px[0] = x[1];");
1610  output_storage (" px[1] = x[0];");
1611 #endif
1612  output_storage ("}");
1613  return;
1614 
1615  case COB_ADDSWP_S16:
1616  output_storage ("static COB_INLINE COB_A_INLINE void");
1617  output_storage ("cob_addswp_s16 (void *p, const int val)");
1618  output_storage ("{");
1619  output_storage (" short n;");
1620 
1621 #ifdef COB_ALLOW_UNALIGNED
1622  output_storage (" n = COB_BSWAP_16 (*(short __unaligned *)p);");
1623  output_storage (" n += val;");
1624  output_storage (" *(short __unaligned *)p = COB_BSWAP_16(n);");
1625 #else
1626  output_storage (" unsigned char *x;");
1627  output_storage (" unsigned char *px = p;");
1628 
1629  output_storage (" x = (unsigned char *)&n;");
1630  output_storage (" x[0] = px[1];");
1631  output_storage (" x[1] = px[0];");
1632  output_storage (" n += val;");
1633  output_storage (" px[0] = x[1];");
1634  output_storage (" px[1] = x[0];");
1635 #endif
1636  output_storage ("}");
1637  return;
1638 
1639  case COB_ADDSWP_U24:
1640  output_storage ("static COB_INLINE COB_A_INLINE void");
1641  output_storage ("cob_addswp_u24 (void *p, const int val)");
1642  output_storage ("{");
1643  output_storage (" unsigned char *x;");
1644  output_storage (" unsigned char *px = p;");
1645  output_storage (" unsigned int n = 0;");
1646 
1647  output_storage (" x = (unsigned char *)&n;");
1648  output_storage (" x[0] = px[2];");
1649  output_storage (" x[1] = px[1];");
1650  output_storage (" x[2] = px[0];");
1651  output_storage (" n += val;");
1652  output_storage (" px[0] = x[2];");
1653  output_storage (" px[1] = x[1];");
1654  output_storage (" px[2] = x[0];");
1655  output_storage ("}");
1656  return;
1657 
1658  case COB_ADDSWP_S24:
1659  output_storage ("static COB_INLINE COB_A_INLINE void");
1660  output_storage ("cob_addswp_s24 (void *p, const int val)");
1661  output_storage ("{");
1662  output_storage (" unsigned char *x;");
1663  output_storage (" unsigned char *px = p;");
1664  output_storage (" int n = 0;");
1665 
1666  output_storage (" x = ((unsigned char *)&n) + 1;");
1667  output_storage (" x[0] = px[2];");
1668  output_storage (" x[1] = px[1];");
1669  output_storage (" x[2] = px[0];");
1670  output_storage (" n >>= 8; /* Shift with sign */");
1671  output_storage (" n += val;");
1672  output_storage (" x = (unsigned char *)&n;");
1673  output_storage (" px[0] = x[2];");
1674  output_storage (" px[1] = x[1];");
1675  output_storage (" px[2] = x[0];");
1676  output_storage ("}");
1677  return;
1678 
1679  case COB_ADDSWP_U32:
1680  output_storage ("static COB_INLINE COB_A_INLINE void");
1681  output_storage ("cob_addswp_u32 (void *p, const int val)");
1682  output_storage ("{");
1683  output_storage (" unsigned int n;");
1684 
1685 #ifdef COB_ALLOW_UNALIGNED
1686  output_storage (" n = COB_BSWAP_32 (*(unsigned int __unaligned *)p);");
1687  output_storage (" n += val;");
1688  output_storage (" *(unsigned int __unaligned *)p = COB_BSWAP_32(n);");
1689 #else
1690  output_storage (" unsigned char *x;");
1691  output_storage (" unsigned char *px = p;");
1692 
1693  output_storage (" x = (unsigned char *)&n;");
1694  output_storage (" x[0] = px[3];");
1695  output_storage (" x[1] = px[2];");
1696  output_storage (" x[2] = px[1];");
1697  output_storage (" x[3] = px[0];");
1698  output_storage (" n += val;");
1699  output_storage (" px[0] = x[3];");
1700  output_storage (" px[1] = x[2];");
1701  output_storage (" px[2] = x[1];");
1702  output_storage (" px[3] = x[0];");
1703 #endif
1704  output_storage ("}");
1705  return;
1706 
1707  case COB_ADDSWP_S32:
1708  output_storage ("static COB_INLINE COB_A_INLINE void");
1709  output_storage ("cob_addswp_s32 (void *p, const int val)");
1710  output_storage ("{");
1711  output_storage (" int n;");
1712 
1713 #ifdef COB_ALLOW_UNALIGNED
1714  output_storage (" n = COB_BSWAP_32 (*(int __unaligned *)p);");
1715  output_storage (" n += val;");
1716  output_storage (" *(int __unaligned *)p = COB_BSWAP_32(n);");
1717 #else
1718  output_storage (" unsigned char *x;");
1719  output_storage (" unsigned char *px = p;");
1720 
1721  output_storage (" x = (unsigned char *)&n;");
1722  output_storage (" x[0] = px[3];");
1723  output_storage (" x[1] = px[2];");
1724  output_storage (" x[2] = px[1];");
1725  output_storage (" x[3] = px[0];");
1726  output_storage (" n += val;");
1727  output_storage (" px[0] = x[3];");
1728  output_storage (" px[1] = x[2];");
1729  output_storage (" px[2] = x[1];");
1730  output_storage (" px[3] = x[0];");
1731 #endif
1732  output_storage ("}");
1733  return;
1734 
1735  case COB_ADDSWP_U40:
1736  output_storage ("static COB_INLINE COB_A_INLINE void");
1737  output_storage ("cob_addswp_u40 (void *p, const int val)");
1738  output_storage ("{");
1739  output_storage (" cob_u64_t n = 0;");
1740  output_storage (" unsigned char *x;");
1741  output_storage (" unsigned char *px = p;");
1742 
1743  output_storage (" x = (unsigned char *)&n;");
1744  output_storage (" x[0] = px[4];");
1745  output_storage (" x[1] = px[3];");
1746  output_storage (" x[2] = px[2];");
1747  output_storage (" x[3] = px[1];");
1748  output_storage (" x[4] = px[0];");
1749  output_storage (" n += val;");
1750  output_storage (" px[0] = x[4];");
1751  output_storage (" px[1] = x[3];");
1752  output_storage (" px[2] = x[2];");
1753  output_storage (" px[3] = x[1];");
1754  output_storage (" px[4] = x[0];");
1755  output_storage ("}");
1756  return;
1757 
1758  case COB_ADDSWP_S40:
1759  output_storage ("static COB_INLINE COB_A_INLINE void");
1760  output_storage ("cob_addswp_s40 (void *p, const int val)");
1761  output_storage ("{");
1762  output_storage (" cob_s64_t n = 0;");
1763  output_storage (" unsigned char *x;");
1764  output_storage (" unsigned char *px = p;");
1765 
1766  output_storage (" x = ((unsigned char *)&n) + 3;");
1767  output_storage (" x[0] = px[4];");
1768  output_storage (" x[1] = px[3];");
1769  output_storage (" x[2] = px[2];");
1770  output_storage (" x[3] = px[1];");
1771  output_storage (" x[4] = px[0];");
1772  output_storage (" n >>= 24; /* Shift with sign */");
1773  output_storage (" n += val;");
1774  output_storage (" x = (unsigned char *)&n;");
1775  output_storage (" px[0] = x[4];");
1776  output_storage (" px[1] = x[3];");
1777  output_storage (" px[2] = x[2];");
1778  output_storage (" px[3] = x[1];");
1779  output_storage (" px[4] = x[0];");
1780  output_storage ("}");
1781  return;
1782 
1783  case COB_ADDSWP_U48:
1784  output_storage ("static COB_INLINE COB_A_INLINE void");
1785  output_storage ("cob_addswp_u48 (void *p, const int val)");
1786  output_storage ("{");
1787  output_storage (" cob_u64_t n = 0;");
1788  output_storage (" unsigned char *x;");
1789  output_storage (" unsigned char *px = p;");
1790 
1791  output_storage (" x = (unsigned char *)&n;");
1792  output_storage (" x[0] = px[5];");
1793  output_storage (" x[1] = px[4];");
1794  output_storage (" x[2] = px[3];");
1795  output_storage (" x[3] = px[2];");
1796  output_storage (" x[4] = px[1];");
1797  output_storage (" x[5] = px[0];");
1798  output_storage (" n += val;");
1799  output_storage (" px[0] = x[5];");
1800  output_storage (" px[1] = x[4];");
1801  output_storage (" px[2] = x[3];");
1802  output_storage (" px[3] = x[2];");
1803  output_storage (" px[4] = x[1];");
1804  output_storage (" px[5] = x[0];");
1805  output_storage ("}");
1806  return;
1807 
1808  case COB_ADDSWP_S48:
1809  output_storage ("static COB_INLINE COB_A_INLINE void");
1810  output_storage ("cob_addswp_s48 (void *p, const int val)");
1811  output_storage ("{");
1812  output_storage (" cob_s64_t n = 0;");
1813  output_storage (" unsigned char *x;");
1814  output_storage (" unsigned char *px = p;");
1815 
1816  output_storage (" x = ((unsigned char *)&n) + 2;");
1817  output_storage (" x[0] = px[5];");
1818  output_storage (" x[1] = px[4];");
1819  output_storage (" x[2] = px[3];");
1820  output_storage (" x[3] = px[2];");
1821  output_storage (" x[4] = px[1];");
1822  output_storage (" x[5] = px[0];");
1823  output_storage (" n >>= 16; /* Shift with sign */");
1824  output_storage (" n += val;");
1825  output_storage (" x = (unsigned char *)&n;");
1826  output_storage (" px[0] = x[5];");
1827  output_storage (" px[1] = x[4];");
1828  output_storage (" px[2] = x[3];");
1829  output_storage (" px[3] = x[2];");
1830  output_storage (" px[4] = x[1];");
1831  output_storage (" px[5] = x[0];");
1832  output_storage ("}");
1833  return;
1834 
1835  case COB_ADDSWP_U56:
1836  output_storage ("static COB_INLINE COB_A_INLINE void");
1837  output_storage ("cob_addswp_u56 (void *p, const int val)");
1838  output_storage ("{");
1839  output_storage (" cob_u64_t n = 0;");
1840  output_storage (" unsigned char *x;");
1841  output_storage (" unsigned char *px = p;");
1842 
1843  output_storage (" x = (unsigned char *)&n;");
1844  output_storage (" x[0] = px[6];");
1845  output_storage (" x[1] = px[5];");
1846  output_storage (" x[2] = px[4];");
1847  output_storage (" x[3] = px[3];");
1848  output_storage (" x[4] = px[2];");
1849  output_storage (" x[5] = px[1];");
1850  output_storage (" x[6] = px[0];");
1851  output_storage (" n += val;");
1852  output_storage (" px[0] = x[6];");
1853  output_storage (" px[1] = x[5];");
1854  output_storage (" px[2] = x[4];");
1855  output_storage (" px[3] = x[3];");
1856  output_storage (" px[4] = x[2];");
1857  output_storage (" px[5] = x[1];");
1858  output_storage (" px[6] = x[0];");
1859  output_storage ("}");
1860  return;
1861 
1862  case COB_ADDSWP_S56:
1863  output_storage ("static COB_INLINE COB_A_INLINE void");
1864  output_storage ("cob_addswp_s56 (void *p, const int val)");
1865  output_storage ("{");
1866  output_storage (" cob_s64_t n = 0;");
1867  output_storage (" unsigned char *x;");
1868  output_storage (" unsigned char *px = p;");
1869 
1870  output_storage (" x = ((unsigned char *)&n) + 1;");
1871  output_storage (" x[0] = px[6];");
1872  output_storage (" x[1] = px[5];");
1873  output_storage (" x[2] = px[4];");
1874  output_storage (" x[3] = px[3];");
1875  output_storage (" x[4] = px[2];");
1876  output_storage (" x[5] = px[1];");
1877  output_storage (" x[6] = px[0];");
1878  output_storage (" n >>= 8; /* Shift with sign */");
1879  output_storage (" n += val;");
1880  output_storage (" x = (unsigned char *)&n;");
1881  output_storage (" px[0] = x[6];");
1882  output_storage (" px[1] = x[5];");
1883  output_storage (" px[2] = x[4];");
1884  output_storage (" px[3] = x[3];");
1885  output_storage (" px[4] = x[2];");
1886  output_storage (" px[5] = x[1];");
1887  output_storage (" px[6] = x[0];");
1888  output_storage ("}");
1889  return;
1890 
1891  case COB_ADDSWP_U64:
1892  output_storage ("static COB_INLINE COB_A_INLINE void");
1893  output_storage ("cob_addswp_u64 (void *p, const int val)");
1894  output_storage ("{");
1895  output_storage (" cob_u64_t n;");
1896 
1897 #ifdef COB_ALLOW_UNALIGNED
1898  output_storage (" n = COB_BSWAP_64 (*(cob_u64_t __unaligned *)p);");
1899  output_storage (" n += val;");
1900  output_storage (" *(cob_u64_t __unaligned *)p = COB_BSWAP_64(n);");
1901 #else
1902  output_storage (" unsigned char *x;");
1903  output_storage (" unsigned char *px = p;");
1904 
1905  output_storage (" x = (unsigned char *)&n;");
1906  output_storage (" x[0] = px[7];");
1907  output_storage (" x[1] = px[6];");
1908  output_storage (" x[2] = px[5];");
1909  output_storage (" x[3] = px[4];");
1910  output_storage (" x[4] = px[3];");
1911  output_storage (" x[5] = px[2];");
1912  output_storage (" x[6] = px[1];");
1913  output_storage (" x[7] = px[0];");
1914  output_storage (" n += val;");
1915  output_storage (" px[0] = x[7];");
1916  output_storage (" px[1] = x[6];");
1917  output_storage (" px[2] = x[5];");
1918  output_storage (" px[3] = x[4];");
1919  output_storage (" px[4] = x[3];");
1920  output_storage (" px[5] = x[2];");
1921  output_storage (" px[6] = x[1];");
1922  output_storage (" px[7] = x[0];");
1923 #endif
1924  output_storage ("}");
1925  return;
1926 
1927  case COB_ADDSWP_S64:
1928  output_storage ("static COB_INLINE COB_A_INLINE void");
1929  output_storage ("cob_addswp_s64 (void *p, const int val)");
1930  output_storage ("{");
1931  output_storage (" cob_s64_t n;");
1932 
1933 #ifdef COB_ALLOW_UNALIGNED
1934  output_storage (" n = COB_BSWAP_64 (*(cob_s64_t __unaligned *)p);");
1935  output_storage (" n += val;");
1936  output_storage (" *(cob_s64_t __unaligned *)p = COB_BSWAP_64(n);");
1937 #else
1938  output_storage (" unsigned char *x;");
1939  output_storage (" unsigned char *px = p;");
1940 
1941  output_storage (" x = (unsigned char *)&n;");
1942  output_storage (" x[0] = px[7];");
1943  output_storage (" x[1] = px[6];");
1944  output_storage (" x[2] = px[5];");
1945  output_storage (" x[3] = px[4];");
1946  output_storage (" x[4] = px[3];");
1947  output_storage (" x[5] = px[2];");
1948  output_storage (" x[6] = px[1];");
1949  output_storage (" x[7] = px[0];");
1950  output_storage (" n += val;");
1951  output_storage (" px[0] = x[7];");
1952  output_storage (" px[1] = x[6];");
1953  output_storage (" px[2] = x[5];");
1954  output_storage (" px[3] = x[4];");
1955  output_storage (" px[4] = x[3];");
1956  output_storage (" px[5] = x[2];");
1957  output_storage (" px[6] = x[1];");
1958  output_storage (" px[7] = x[0];");
1959 #endif
1960  output_storage ("}");
1961  return;
1962 
1963  /* Binary swapped subtract */
1964 
1965  case COB_SUBSWP_U16:
1966  output_storage ("static COB_INLINE COB_A_INLINE void");
1967  output_storage ("cob_subswp_u16 (void *p, const int val)");
1968  output_storage ("{");
1969  output_storage (" unsigned short n;");
1970 
1971 #ifdef COB_ALLOW_UNALIGNED
1972  output_storage (" n = COB_BSWAP_16 (*(unsigned short __unaligned *)p);");
1973  output_storage (" n -= val;");
1974  output_storage (" *(unsigned short __unaligned *)p = COB_BSWAP_16(n);");
1975 #else
1976  output_storage (" unsigned char *x;");
1977  output_storage (" unsigned char *px = p;");
1978 
1979  output_storage (" x = (unsigned char *)&n;");
1980  output_storage (" x[0] = px[1];");
1981  output_storage (" x[1] = px[0];");
1982  output_storage (" n -= val;");
1983  output_storage (" px[0] = x[1];");
1984  output_storage (" px[1] = x[0];");
1985 #endif
1986  output_storage ("}");
1987  return;
1988 
1989  case COB_SUBSWP_S16:
1990  output_storage ("static COB_INLINE COB_A_INLINE void");
1991  output_storage ("cob_subswp_s16 (void *p, const int val)");
1992  output_storage ("{");
1993  output_storage (" short n;");
1994 
1995 #ifdef COB_ALLOW_UNALIGNED
1996  output_storage (" n = COB_BSWAP_16 (*(short __unaligned *)p);");
1997  output_storage (" n -= val;");
1998  output_storage (" *(short __unaligned *)p = COB_BSWAP_16(n);");
1999 #else
2000  output_storage (" unsigned char *x;");
2001  output_storage (" unsigned char *px = p;");
2002 
2003  output_storage (" x = (unsigned char *)&n;");
2004  output_storage (" x[0] = px[1];");
2005  output_storage (" x[1] = px[0];");
2006  output_storage (" n -= val;");
2007  output_storage (" px[0] = x[1];");
2008  output_storage (" px[1] = x[0];");
2009 #endif
2010  output_storage ("}");
2011  return;
2012 
2013  case COB_SUBSWP_U24:
2014  output_storage ("static COB_INLINE COB_A_INLINE void");
2015  output_storage ("cob_subswp_u24 (void *p, const int val)");
2016  output_storage ("{");
2017  output_storage (" unsigned char *x;");
2018  output_storage (" unsigned char *px = p;");
2019  output_storage (" unsigned int n = 0;");
2020 
2021  output_storage (" x = (unsigned char *)&n;");
2022  output_storage (" x[0] = px[2];");
2023  output_storage (" x[1] = px[1];");
2024  output_storage (" x[2] = px[0];");
2025  output_storage (" n -= val;");
2026  output_storage (" px[0] = x[2];");
2027  output_storage (" px[1] = x[1];");
2028  output_storage (" px[2] = x[0];");
2029  output_storage ("}");
2030  return;
2031 
2032  case COB_SUBSWP_S24:
2033  output_storage ("static COB_INLINE COB_A_INLINE void");
2034  output_storage ("cob_subswp_s24 (void *p, const int val)");
2035  output_storage ("{");
2036  output_storage (" unsigned char *x;");
2037  output_storage (" unsigned char *px = p;");
2038  output_storage (" int n = 0;");
2039 
2040  output_storage (" x = ((unsigned char *)&n) + 1;");
2041  output_storage (" x[0] = px[2];");
2042  output_storage (" x[1] = px[1];");
2043  output_storage (" x[2] = px[0];");
2044  output_storage (" n >>= 8; /* Shift with sign */");
2045  output_storage (" n -= val;");
2046  output_storage (" x = (unsigned char *)&n;");
2047  output_storage (" px[0] = x[2];");
2048  output_storage (" px[1] = x[1];");
2049  output_storage (" px[2] = x[0];");
2050  output_storage ("}");
2051  return;
2052 
2053  case COB_SUBSWP_U32:
2054  output_storage ("static COB_INLINE COB_A_INLINE void");
2055  output_storage ("cob_subswp_u32 (void *p, const int val)");
2056  output_storage ("{");
2057  output_storage (" unsigned int n;");
2058 
2059 #ifdef COB_ALLOW_UNALIGNED
2060  output_storage (" n = COB_BSWAP_32 (*(unsigned int __unaligned *)p);");
2061  output_storage (" n -= val;");
2062  output_storage (" *(unsigned int __unaligned *)p = COB_BSWAP_32(n);");
2063 #else
2064  output_storage (" unsigned char *x;");
2065  output_storage (" unsigned char *px = p;");
2066 
2067  output_storage (" x = (unsigned char *)&n;");
2068  output_storage (" x[0] = px[3];");
2069  output_storage (" x[1] = px[2];");
2070  output_storage (" x[2] = px[1];");
2071  output_storage (" x[3] = px[0];");
2072  output_storage (" n -= val;");
2073  output_storage (" px[0] = x[3];");
2074  output_storage (" px[1] = x[2];");
2075  output_storage (" px[2] = x[1];");
2076  output_storage (" px[3] = x[0];");
2077 #endif
2078  output_storage ("}");
2079  return;
2080 
2081  case COB_SUBSWP_S32:
2082  output_storage ("static COB_INLINE COB_A_INLINE void");
2083  output_storage ("cob_subswp_s32 (void *p, const int val)");
2084  output_storage ("{");
2085  output_storage (" int n;");
2086 
2087 #ifdef COB_ALLOW_UNALIGNED
2088  output_storage (" n = COB_BSWAP_32 (*(int __unaligned *)p);");
2089  output_storage (" n -= val;");
2090  output_storage (" *(int __unaligned *)p = COB_BSWAP_32(n);");
2091 #else
2092  output_storage (" unsigned char *x;");
2093  output_storage (" unsigned char *px = p;");
2094 
2095  output_storage (" x = (unsigned char *)&n;");
2096  output_storage (" x[0] = px[3];");
2097  output_storage (" x[1] = px[2];");
2098  output_storage (" x[2] = px[1];");
2099  output_storage (" x[3] = px[0];");
2100  output_storage (" n -= val;");
2101  output_storage (" px[0] = x[3];");
2102  output_storage (" px[1] = x[2];");
2103  output_storage (" px[2] = x[1];");
2104  output_storage (" px[3] = x[0];");
2105 #endif
2106  output_storage ("}");
2107  return;
2108 
2109  case COB_SUBSWP_U40:
2110  output_storage ("static COB_INLINE COB_A_INLINE void");
2111  output_storage ("cob_subswp_u40 (void *p, const int val)");
2112  output_storage ("{");
2113  output_storage (" cob_u64_t n = 0;");
2114  output_storage (" unsigned char *x;");
2115  output_storage (" unsigned char *px = p;");
2116 
2117  output_storage (" x = (unsigned char *)&n;");
2118  output_storage (" x[0] = px[4];");
2119  output_storage (" x[1] = px[3];");
2120  output_storage (" x[2] = px[2];");
2121  output_storage (" x[3] = px[1];");
2122  output_storage (" x[4] = px[0];");
2123  output_storage (" n -= val;");
2124  output_storage (" px[0] = x[4];");
2125  output_storage (" px[1] = x[3];");
2126  output_storage (" px[2] = x[2];");
2127  output_storage (" px[3] = x[1];");
2128  output_storage (" px[4] = x[0];");
2129  output_storage ("}");
2130  return;
2131 
2132  case COB_SUBSWP_S40:
2133  output_storage ("static COB_INLINE COB_A_INLINE void");
2134  output_storage ("cob_subswp_s40 (void *p, const int val)");
2135  output_storage ("{");
2136  output_storage (" cob_s64_t n = 0;");
2137  output_storage (" unsigned char *x;");
2138  output_storage (" unsigned char *px = p;");
2139 
2140  output_storage (" x = ((unsigned char *)&n) + 3;");
2141  output_storage (" x[0] = px[4];");
2142  output_storage (" x[1] = px[3];");
2143  output_storage (" x[2] = px[2];");
2144  output_storage (" x[3] = px[1];");
2145  output_storage (" x[4] = px[0];");
2146  output_storage (" n >>= 24; /* Shift with sign */");
2147  output_storage (" n -= val;");
2148  output_storage (" x = (unsigned char *)&n;");
2149  output_storage (" px[0] = x[4];");
2150  output_storage (" px[1] = x[3];");
2151  output_storage (" px[2] = x[2];");
2152  output_storage (" px[3] = x[1];");
2153  output_storage (" px[4] = x[0];");
2154  output_storage ("}");
2155  return;
2156 
2157  case COB_SUBSWP_U48:
2158  output_storage ("static COB_INLINE COB_A_INLINE void");
2159  output_storage ("cob_subswp_u48 (void *p, const int val)");
2160  output_storage ("{");
2161  output_storage (" cob_u64_t n = 0;");
2162  output_storage (" unsigned char *x;");
2163  output_storage (" unsigned char *px = p;");
2164 
2165  output_storage (" x = (unsigned char *)&n;");
2166  output_storage (" x[0] = px[5];");
2167  output_storage (" x[1] = px[4];");
2168  output_storage (" x[2] = px[3];");
2169  output_storage (" x[3] = px[2];");
2170  output_storage (" x[4] = px[1];");
2171  output_storage (" x[5] = px[0];");
2172  output_storage (" n -= val;");
2173  output_storage (" px[0] = x[5];");
2174  output_storage (" px[1] = x[4];");
2175  output_storage (" px[2] = x[3];");
2176  output_storage (" px[3] = x[2];");
2177  output_storage (" px[4] = x[1];");
2178  output_storage (" px[5] = x[0];");
2179  output_storage ("}");
2180  return;
2181 
2182  case COB_SUBSWP_S48:
2183  output_storage ("static COB_INLINE COB_A_INLINE void");
2184  output_storage ("cob_subswp_s48 (void *p, const int val)");
2185  output_storage ("{");
2186  output_storage (" cob_s64_t n = 0;");
2187  output_storage (" unsigned char *x;");
2188  output_storage (" unsigned char *px = p;");
2189 
2190  output_storage (" x = ((unsigned char *)&n) + 2;");
2191  output_storage (" x[0] = px[5];");
2192  output_storage (" x[1] = px[4];");
2193  output_storage (" x[2] = px[3];");
2194  output_storage (" x[3] = px[2];");
2195  output_storage (" x[4] = px[1];");
2196  output_storage (" x[5] = px[0];");
2197  output_storage (" n >>= 16; /* Shift with sign */");
2198  output_storage (" n -= val;");
2199  output_storage (" x = (unsigned char *)&n;");
2200  output_storage (" px[0] = x[5];");
2201  output_storage (" px[1] = x[4];");
2202  output_storage (" px[2] = x[3];");
2203  output_storage (" px[3] = x[2];");
2204  output_storage (" px[4] = x[1];");
2205  output_storage (" px[5] = x[0];");
2206  output_storage ("}");
2207  return;
2208 
2209  case COB_SUBSWP_U56:
2210  output_storage ("static COB_INLINE COB_A_INLINE void");
2211  output_storage ("cob_subswp_u56 (void *p, const int val)");
2212  output_storage ("{");
2213  output_storage (" cob_u64_t n = 0;");
2214  output_storage (" unsigned char *x;");
2215  output_storage (" unsigned char *px = p;");
2216 
2217  output_storage (" x = (unsigned char *)&n;");
2218  output_storage (" x[0] = px[6];");
2219  output_storage (" x[1] = px[5];");
2220  output_storage (" x[2] = px[4];");
2221  output_storage (" x[3] = px[3];");
2222  output_storage (" x[4] = px[2];");
2223  output_storage (" x[5] = px[1];");
2224  output_storage (" x[6] = px[0];");
2225  output_storage (" n -= val;");
2226  output_storage (" px[0] = x[6];");
2227  output_storage (" px[1] = x[5];");
2228  output_storage (" px[2] = x[4];");
2229  output_storage (" px[3] = x[3];");
2230  output_storage (" px[4] = x[2];");
2231  output_storage (" px[5] = x[1];");
2232  output_storage (" px[6] = x[0];");
2233  output_storage ("}");
2234  return;
2235 
2236  case COB_SUBSWP_S56:
2237  output_storage ("static COB_INLINE COB_A_INLINE void");
2238  output_storage ("cob_subswp_s56 (void *p, const int val)");
2239  output_storage ("{");
2240  output_storage (" cob_s64_t n = 0;");
2241  output_storage (" unsigned char *x;");
2242  output_storage (" unsigned char *px = p;");
2243 
2244  output_storage (" x = ((unsigned char *)&n) + 1;");
2245  output_storage (" x[0] = px[6];");
2246  output_storage (" x[1] = px[5];");
2247  output_storage (" x[2] = px[4];");
2248  output_storage (" x[3] = px[3];");
2249  output_storage (" x[4] = px[2];");
2250  output_storage (" x[5] = px[1];");
2251  output_storage (" x[6] = px[0];");
2252  output_storage (" n >>= 8; /* Shift with sign */");
2253  output_storage (" n -= val;");
2254  output_storage (" x = (unsigned char *)&n;");
2255  output_storage (" px[0] = x[6];");
2256  output_storage (" px[1] = x[5];");
2257  output_storage (" px[2] = x[4];");
2258  output_storage (" px[3] = x[3];");
2259  output_storage (" px[4] = x[2];");
2260  output_storage (" px[5] = x[1];");
2261  output_storage (" px[6] = x[0];");
2262  output_storage ("}");
2263  return;
2264 
2265  case COB_SUBSWP_U64:
2266  output_storage ("static COB_INLINE COB_A_INLINE void");
2267  output_storage ("cob_subswp_u64 (void *p, const int val)");
2268  output_storage ("{");
2269  output_storage (" cob_u64_t n;");
2270 
2271 #ifdef COB_ALLOW_UNALIGNED
2272  output_storage (" n = COB_BSWAP_64 (*(cob_u64_t __unaligned *)p);");
2273  output_storage (" n -= val;");
2274  output_storage (" *(cob_u64_t __unaligned *)p = COB_BSWAP_64(n);");
2275 #else
2276  output_storage (" unsigned char *x;");
2277  output_storage (" unsigned char *px = p;");
2278 
2279  output_storage (" x = (unsigned char *)&n;");
2280  output_storage (" x[0] = px[7];");
2281  output_storage (" x[1] = px[6];");
2282  output_storage (" x[2] = px[5];");
2283  output_storage (" x[3] = px[4];");
2284  output_storage (" x[4] = px[3];");
2285  output_storage (" x[5] = px[2];");
2286  output_storage (" x[6] = px[1];");
2287  output_storage (" x[7] = px[0];");
2288  output_storage (" n -= val;");
2289  output_storage (" px[0] = x[7];");
2290  output_storage (" px[1] = x[6];");
2291  output_storage (" px[2] = x[5];");
2292  output_storage (" px[3] = x[4];");
2293  output_storage (" px[4] = x[3];");
2294  output_storage (" px[5] = x[2];");
2295  output_storage (" px[6] = x[1];");
2296  output_storage (" px[7] = x[0];");
2297 #endif
2298  output_storage ("}");
2299  return;
2300 
2301  case COB_SUBSWP_S64:
2302  output_storage ("static COB_INLINE COB_A_INLINE void");
2303  output_storage ("cob_subswp_s64 (void *p, const int val)");
2304  output_storage ("{");
2305  output_storage (" cob_s64_t n;");
2306 
2307 #ifdef COB_ALLOW_UNALIGNED
2308  output_storage (" n = COB_BSWAP_64 (*(cob_s64_t __unaligned *)p);");
2309  output_storage (" n -= val;");
2310  output_storage (" *(cob_s64_t __unaligned *)p = COB_BSWAP_64(n);");
2311 #else
2312  output_storage (" unsigned char *x;");
2313  output_storage (" unsigned char *px = p;");
2314 
2315  output_storage (" x = (unsigned char *)&n;");
2316  output_storage (" x[0] = px[7];");
2317  output_storage (" x[1] = px[6];");
2318  output_storage (" x[2] = px[5];");
2319  output_storage (" x[3] = px[4];");
2320  output_storage (" x[4] = px[3];");
2321  output_storage (" x[5] = px[2];");
2322  output_storage (" x[6] = px[1];");
2323  output_storage (" x[7] = px[0];");
2324  output_storage (" n -= val;");
2325  output_storage (" px[0] = x[7];");
2326  output_storage (" px[1] = x[6];");
2327  output_storage (" px[2] = x[5];");
2328  output_storage (" px[3] = x[4];");
2329  output_storage (" px[4] = x[3];");
2330  output_storage (" px[5] = x[2];");
2331  output_storage (" px[6] = x[1];");
2332  output_storage (" px[7] = x[0];");
2333 #endif
2334  output_storage ("}");
2335  return;
2336 
2337  /* Binary set swapped value */
2338  case COB_SETSWP_U16:
2339  output_storage ("static COB_INLINE COB_A_INLINE void");
2340  output_storage ("cob_setswp_u16 (void *p, const int val)");
2341  output_storage ("{");
2342  output_storage (" unsigned short n;");
2343 
2344 #ifdef COB_ALLOW_UNALIGNED
2345  output_storage (" n = val;");
2346  output_storage (" *(unsigned short __unaligned *)p = COB_BSWAP_16(n);");
2347 #else
2348  output_storage (" unsigned char *x;");
2349  output_storage (" unsigned char *px = p;");
2350 
2351  output_storage (" n = val;");
2352  output_storage (" x = (unsigned char *)&n;");
2353  output_storage (" px[0] = x[1];");
2354  output_storage (" px[1] = x[0];");
2355 #endif
2356  output_storage ("}");
2357  return;
2358 
2359  case COB_SETSWP_S16:
2360  output_storage ("static COB_INLINE COB_A_INLINE void");
2361  output_storage ("cob_setswp_s16 (void *p, const int val)");
2362  output_storage ("{");
2363  output_storage (" short n;");
2364 
2365 #ifdef COB_ALLOW_UNALIGNED
2366  output_storage (" n = val;");
2367  output_storage (" *(short __unaligned *)p = COB_BSWAP_16(n);");
2368 #else
2369  output_storage (" unsigned char *x;");
2370  output_storage (" unsigned char *px = p;");
2371 
2372  output_storage (" n = val;");
2373  output_storage (" x = (unsigned char *)&n;");
2374  output_storage (" px[0] = x[1];");
2375  output_storage (" px[1] = x[0];");
2376 #endif
2377  output_storage ("}");
2378  return;
2379 
2380  case COB_SETSWP_U24:
2381  output_storage ("static COB_INLINE COB_A_INLINE void");
2382  output_storage ("cob_setswp_u24 (void *p, const int val)");
2383  output_storage ("{");
2384  output_storage (" unsigned char *x;");
2385  output_storage (" unsigned char *px = p;");
2386  output_storage (" unsigned int n;");
2387 
2388  output_storage (" n = val;");
2389  output_storage (" x = (unsigned char *)&n;");
2390  output_storage (" px[0] = x[2];");
2391  output_storage (" px[1] = x[1];");
2392  output_storage (" px[2] = x[0];");
2393  output_storage ("}");
2394  return;
2395 
2396  case COB_SETSWP_S24:
2397  output_storage ("static COB_INLINE COB_A_INLINE void");
2398  output_storage ("cob_setswp_s24 (void *p, const int val)");
2399  output_storage ("{");
2400  output_storage (" unsigned char *x;");
2401  output_storage (" unsigned char *px = p;");
2402  output_storage (" int n;");
2403 
2404  output_storage (" n = val;");
2405  output_storage (" x = (unsigned char *)&n;");
2406  output_storage (" px[0] = x[2];");
2407  output_storage (" px[1] = x[1];");
2408  output_storage (" px[2] = x[0];");
2409  output_storage ("}");
2410  return;
2411 
2412  case COB_SETSWP_U32:
2413  output_storage ("static COB_INLINE COB_A_INLINE void");
2414  output_storage ("cob_setswp_u32 (void *p, const int val)");
2415  output_storage ("{");
2416  output_storage (" unsigned int n;");
2417 
2418 #ifdef COB_ALLOW_UNALIGNED
2419  output_storage (" n = val;");
2420  output_storage (" *(unsigned int __unaligned *)p = COB_BSWAP_32(n);");
2421 #else
2422  output_storage (" unsigned char *x;");
2423  output_storage (" unsigned char *px = p;");
2424 
2425  output_storage (" n = val;");
2426  output_storage (" x = (unsigned char *)&n;");
2427  output_storage (" px[0] = x[3];");
2428  output_storage (" px[1] = x[2];");
2429  output_storage (" px[2] = x[1];");
2430  output_storage (" px[3] = x[0];");
2431 #endif
2432  output_storage ("}");
2433  return;
2434 
2435  case COB_SETSWP_S32:
2436  output_storage ("static COB_INLINE COB_A_INLINE void");
2437  output_storage ("cob_setswp_s32 (void *p, const int val)");
2438  output_storage ("{");
2439  output_storage (" int n;");
2440 
2441 #ifdef COB_ALLOW_UNALIGNED
2442  output_storage (" n = val;");
2443  output_storage (" *(int __unaligned *)p = COB_BSWAP_32(n);");
2444 #else
2445  output_storage (" unsigned char *x;");
2446  output_storage (" unsigned char *px = p;");
2447 
2448  output_storage (" n = val;");
2449  output_storage (" x = (unsigned char *)&n;");
2450  output_storage (" px[0] = x[3];");
2451  output_storage (" px[1] = x[2];");
2452  output_storage (" px[2] = x[1];");
2453  output_storage (" px[3] = x[0];");
2454 #endif
2455  output_storage ("}");
2456  return;
2457 
2458  case COB_SETSWP_U40:
2459  output_storage ("static COB_INLINE COB_A_INLINE void");
2460  output_storage ("cob_setswp_u40 (void *p, const int val)");
2461  output_storage ("{");
2462  output_storage (" cob_u64_t n;");
2463  output_storage (" unsigned char *x;");
2464  output_storage (" unsigned char *px = p;");
2465 
2466  output_storage (" n = val;");
2467  output_storage (" x = (unsigned char *)&n;");
2468  output_storage (" px[0] = x[4];");
2469  output_storage (" px[1] = x[3];");
2470  output_storage (" px[2] = x[2];");
2471  output_storage (" px[3] = x[1];");
2472  output_storage (" px[4] = x[0];");
2473  output_storage ("}");
2474  return;
2475 
2476  case COB_SETSWP_S40:
2477  output_storage ("static COB_INLINE COB_A_INLINE void");
2478  output_storage ("cob_setswp_s40 (void *p, const int val)");
2479  output_storage ("{");
2480  output_storage (" cob_s64_t n;");
2481  output_storage (" unsigned char *x;");
2482  output_storage (" unsigned char *px = p;");
2483 
2484  output_storage (" n = val;");
2485  output_storage (" x = (unsigned char *)&n;");
2486  output_storage (" px[0] = x[4];");
2487  output_storage (" px[1] = x[3];");
2488  output_storage (" px[2] = x[2];");
2489  output_storage (" px[3] = x[1];");
2490  output_storage (" px[4] = x[0];");
2491  output_storage ("}");
2492  return;
2493 
2494  case COB_SETSWP_U48:
2495  output_storage ("static COB_INLINE COB_A_INLINE void");
2496  output_storage ("cob_setswp_u48 (void *p, const int val)");
2497  output_storage ("{");
2498  output_storage (" cob_u64_t n;");
2499  output_storage (" unsigned char *x;");
2500  output_storage (" unsigned char *px = p;");
2501 
2502  output_storage (" n = val;");
2503  output_storage (" x = (unsigned char *)&n;");
2504  output_storage (" px[0] = x[5];");
2505  output_storage (" px[1] = x[4];");
2506  output_storage (" px[2] = x[3];");
2507  output_storage (" px[3] = x[2];");
2508  output_storage (" px[4] = x[1];");
2509  output_storage (" px[5] = x[0];");
2510  output_storage ("}");
2511  return;
2512 
2513  case COB_SETSWP_S48:
2514  output_storage ("static COB_INLINE COB_A_INLINE void");
2515  output_storage ("cob_setswp_s48 (void *p, const int val)");
2516  output_storage ("{");
2517  output_storage (" cob_s64_t n;");
2518  output_storage (" unsigned char *x;");
2519  output_storage (" unsigned char *px = p;");
2520 
2521  output_storage (" n = val;");
2522  output_storage (" x = (unsigned char *)&n;");
2523  output_storage (" px[0] = x[5];");
2524  output_storage (" px[1] = x[4];");
2525  output_storage (" px[2] = x[3];");
2526  output_storage (" px[3] = x[2];");
2527  output_storage (" px[4] = x[1];");
2528  output_storage (" px[5] = x[0];");
2529  output_storage ("}");
2530  return;
2531 
2532  case COB_SETSWP_U56:
2533  output_storage ("static COB_INLINE COB_A_INLINE void");
2534  output_storage ("cob_setswp_u56 (void *p, const int val)");
2535  output_storage ("{");
2536  output_storage (" cob_u64_t n;");
2537  output_storage (" unsigned char *x;");
2538  output_storage (" unsigned char *px = p;");
2539 
2540  output_storage (" n = val;");
2541  output_storage (" x = (unsigned char *)&n;");
2542  output_storage (" px[0] = x[6];");
2543  output_storage (" px[1] = x[5];");
2544  output_storage (" px[2] = x[4];");
2545  output_storage (" px[3] = x[3];");
2546  output_storage (" px[4] = x[2];");
2547  output_storage (" px[5] = x[1];");
2548  output_storage (" px[6] = x[0];");
2549  output_storage ("}");
2550  return;
2551 
2552  case COB_SETSWP_S56:
2553  output_storage ("static COB_INLINE COB_A_INLINE void");
2554  output_storage ("cob_setswp_s56 (void *p, const int val)");
2555  output_storage ("{");
2556  output_storage (" cob_s64_t n;");
2557  output_storage (" unsigned char *x;");
2558  output_storage (" unsigned char *px = p;");
2559 
2560  output_storage (" n = val;");
2561  output_storage (" x = (unsigned char *)&n;");
2562  output_storage (" px[0] = x[6];");
2563  output_storage (" px[1] = x[5];");
2564  output_storage (" px[2] = x[4];");
2565  output_storage (" px[3] = x[3];");
2566  output_storage (" px[4] = x[2];");
2567  output_storage (" px[5] = x[1];");
2568  output_storage (" px[6] = x[0];");
2569  output_storage ("}");
2570  return;
2571 
2572  case COB_SETSWP_U64:
2573  output_storage ("static COB_INLINE COB_A_INLINE void");
2574  output_storage ("cob_setswp_u64 (void *p, const int val)");
2575  output_storage ("{");
2576  output_storage (" cob_u64_t n;");
2577 
2578 #ifdef COB_ALLOW_UNALIGNED
2579  output_storage (" n = val;");
2580  output_storage (" *(cob_u64_t __unaligned *)p = COB_BSWAP_64(n);");
2581 #else
2582  output_storage (" unsigned char *x;");
2583  output_storage (" unsigned char *px = p;");
2584 
2585  output_storage (" n = val;");
2586  output_storage (" x = (unsigned char *)&n;");
2587  output_storage (" px[0] = x[7];");
2588  output_storage (" px[1] = x[6];");
2589  output_storage (" px[2] = x[5];");
2590  output_storage (" px[3] = x[4];");
2591  output_storage (" px[4] = x[3];");
2592  output_storage (" px[5] = x[2];");
2593  output_storage (" px[6] = x[1];");
2594  output_storage (" px[7] = x[0];");
2595 #endif
2596  output_storage ("}");
2597  return;
2598 
2599  case COB_SETSWP_S64:
2600  output_storage ("static COB_INLINE COB_A_INLINE void");
2601  output_storage ("cob_setswp_s64 (void *p, const int val)");
2602  output_storage ("{");
2603  output_storage (" cob_s64_t n;");
2604 
2605 #ifdef COB_ALLOW_UNALIGNED
2606  output_storage (" n = val;");
2607  output_storage (" *(cob_s64_t __unaligned *)p = COB_BSWAP_64(n);");
2608 #else
2609  output_storage (" unsigned char *x;");
2610  output_storage (" unsigned char *px = p;");
2611 
2612  output_storage (" n = val;");
2613  output_storage (" x = (unsigned char *)&n;");
2614  output_storage (" px[0] = x[7];");
2615  output_storage (" px[1] = x[6];");
2616  output_storage (" px[2] = x[5];");
2617  output_storage (" px[3] = x[4];");
2618  output_storage (" px[4] = x[3];");
2619  output_storage (" px[5] = x[2];");
2620  output_storage (" px[6] = x[1];");
2621  output_storage (" px[7] = x[0];");
2622 #endif
2623  output_storage ("}");
2624  return;
2625  default:
2626  break;
2627  }
2628  cobc_abort_pr (_("Unexpected optimization value"));
2629  COBC_ABORT ();
2630 }
COB_EXPIMP void cob_get_environment ( const cob_field ,
cob_field  
)
2685 {
2686  const char *p;
2687  char *buff;
2688  size_t size;
2689 
2690  if (envname->size == 0 || envval->size == 0) {
2692  return;
2693  }
2694 
2695  buff = cob_malloc (envname->size + 1U);
2696  cob_field_to_string (envname, buff, envname->size);
2698  for (size = 0; size < strlen (buff); ++size) {
2699  if (!isalnum ((int)buff[size])) {
2700  buff[size] = '_';
2701  }
2702  }
2703  }
2704  p = getenv (buff);
2705  if (!p) {
2707  p = " ";
2708  }
2709  cob_memcpy (envval, p, strlen (p));
2710  cob_free (buff);
2711 }
COB_EXPIMP cob_global* cob_get_global_ptr ( void  )
1568 {
1569  if (unlikely(!cob_initialized)) {
1570  cob_fatal_error (COB_FERROR_INITIALIZED);
1571  }
1572  return cobglobptr;
1573 }
COB_EXPIMP void cob_get_indirect_field ( cob_field )
2068 {
2069  cob_move (move_field, f);
2070 }
COB_EXPIMP int cob_get_int ( cob_field )
1626 {
1627  int n;
1628  cob_s64_t val;
1629  cob_field temp;
1630  cob_field_attr attr;
1631 
1632  switch (COB_FIELD_TYPE (f)) {
1634  return cob_display_get_int (f);
1636  return cob_packed_get_int (f);
1638  val = cob_binary_mget_sint64 (f);
1639  for (n = COB_FIELD_SCALE (f); n > 0 && val; --n) {
1640  val /= 10;
1641  }
1642  return (int)val;
1643  default:
1644  COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0,
1645  COB_FLAG_HAVE_SIGN, NULL);
1646  temp.size = 4;
1647  temp.data = (unsigned char *)&n;
1648  temp.attr = &attr;
1649  cob_move (f, &temp);
1650  return n;
1651  }
1652 }
COB_EXPIMP cob_s64_t cob_get_llint ( cob_field )
1656 {
1657  cob_s64_t n;
1658  int inc;
1659  cob_field temp;
1660 
1661  switch (COB_FIELD_TYPE (f)) {
1663  return cob_display_get_long_long (f);
1665  return cob_packed_get_long_long (f);
1667  n = cob_binary_mget_sint64 (f);
1668  for (inc = COB_FIELD_SCALE (f); inc > 0 && n; --inc) {
1669  n /= 10;
1670  }
1671  return n;
1672  default:
1673  temp.size = 8;
1674  temp.data = (unsigned char *)&n;
1675  temp.attr = &const_binll_attr;
1676  cob_move (f, &temp);
1677  return n;
1678  }
1679 }
COB_EXPIMP unsigned char* cob_get_pointer ( const void *  )
1317 {
1318  void *tmptr;
1319 
1320  memcpy (&tmptr, srcptr, sizeof (void *));
1321  return (cob_u8_ptr)tmptr;
1322 }
COB_EXPIMP void* cob_get_prog_pointer ( const void *  )
1326 {
1327  void *tmptr;
1328 
1329  memcpy (&tmptr, srcptr, sizeof (void *));
1330  return tmptr;
1331 }
COB_EXPIMP int cob_get_switch ( const int  )
2077 {
2078  if (n < 0 || n > (COB_SWITCH_MAX - 1)) {
2079  return 0;
2080  }
2081  return cob_switch[n];
2082 }
COB_EXPIMP char* cob_getenv ( const char *  )
2841 {
2842  char *p;
2843 
2844  if (name) {
2845  p = getenv (name);
2846  if (p) {
2847  return cob_strdup (p);
2848  }
2849  }
2850  return NULL;
2851 }
COB_EXPIMP void cob_gmp_free ( void *  )
217  {
218 /* mpir/gmp free functions */
219 #ifdef HAVE_MP_GET_MEMORY_FUNCTIONS
220  void (*freefunc)(void *, size_t);
221  mp_get_memory_functions (NULL, NULL, &freefunc);
222  freefunc (ptr, strlen((char*) ptr) + 1);
223 #else
224  free (ptr);
225 #endif
226 }
COB_EXPIMP void cob_incr_temp_iteration ( void  )
2926 {
2928 }
COB_EXPIMP void cob_init ( const int  ,
char **   
)
4252 {
4253  char *s;
4254 #if defined(HAVE_READLINK) || defined(HAVE_GETEXECNAME)
4255  const char *path;
4256 #endif
4257  int i;
4258 
4259  if (cob_initialized) {
4260  return;
4261  }
4262 
4263  cobglobptr = NULL;
4264  runtimeptr = (struct runtime_env*) cob_malloc(sizeof(struct runtime_env));
4265 
4266  cob_set_signal ();
4267 
4268  cob_alloc_base = NULL;
4269  cob_local_env = NULL;
4270  cob_last_sfile = NULL;
4271  commlnptr = NULL;
4272  basext = NULL;
4273  sort_keys = NULL;
4274  sort_collate = NULL;
4280  cob_user_name = NULL;
4281  exit_hdlrs = NULL;
4282  hdlrs = NULL;
4283  commlncnt = 0;
4284  sort_nkeys = 0;
4285  cob_source_line = 0;
4286  cob_line_trace = 0;
4287  cob_local_env_size = 0;
4288 
4289  current_arg = 1;
4290 
4291  cob_argc = argc;
4292  cob_argv = argv;
4293 
4294  /* Get emergency buffer */
4296 
4297  /* Get global structure */
4298  cobglobptr = cob_malloc (sizeof(cob_global));
4299 
4300  cob_initialized = 1;
4301 
4302  if (argc) {
4304  }
4305 
4306 #ifdef HAVE_SETLOCALE
4307  /* Prime the locale from user settings */
4308  s = setlocale (LC_ALL, "");
4309  if (s) {
4310  /* Save initial values */
4312  s = setlocale (LC_CTYPE, NULL);
4313  if (s) {
4315  }
4316  s = setlocale (LC_COLLATE, NULL);
4317  if (s) {
4319  }
4320 #ifdef LC_MESSAGES
4321  s = setlocale (LC_MESSAGES, NULL);
4322  if (s) {
4324  }
4325 #endif
4326  s = setlocale (LC_MONETARY, NULL);
4327  if (s) {
4329  }
4330  s = setlocale (LC_NUMERIC, NULL);
4331  if (s) {
4333  }
4334  s = setlocale (LC_TIME, NULL);
4335  if (s) {
4337  }
4338  /* Set to standard "C" locale for COBOL */
4339  setlocale (LC_NUMERIC, "C");
4340  setlocale (LC_CTYPE, "C");
4341  /* Save changed locale */
4342  s = setlocale (LC_ALL, NULL);
4343  if (s) {
4345  }
4346  }
4347 #endif
4348 
4349 #ifdef _WIN32
4350  /* Allows running of tests under Win */
4351  s = getenv ("COB_UNIX_LF");
4352  if (s) {
4354 
4355  if (cob_check_env_true(s)) {
4356 
4357  cobglobptr->cob_unix_lf = 1;
4358  _setmode (_fileno (stdin), _O_BINARY);
4359  _setmode (_fileno (stdout), _O_BINARY);
4360  _setmode (_fileno (stderr), _O_BINARY);
4361  }
4362  }
4363 #endif
4364 
4365  /* Call inits with runtimeptr to get the adresses of all */
4367  cob_init_strings();
4370  /* Screen-IO might be needed for error outputs */
4375 
4376  /* Set up library routine stuff */
4377  cobglobptr->cob_term_buff = cob_malloc ((size_t)COB_MEDIUM_BUFF);
4379 
4380  /* Set switches */
4381  for (i = 0; i < COB_SWITCH_MAX; ++i) {
4382  sprintf (runtime_err_str, "COB_SWITCH_%d", i);
4383  s = getenv (runtime_err_str);
4384  if (s && (*s == '1' || strcasecmp (s, "ON") == 0)) {
4385  cob_switch[i] = 1;
4386  } else {
4387  cob_switch[i] = 0;
4388  }
4389  }
4390 
4391  /* Trace enable */
4392  s = getenv ("COB_SET_TRACE");
4393  if (s) {
4395 
4396  if (cob_check_env_true(s)) {
4397  cob_line_trace = 1;
4398  }
4399  }
4400 
4401  /* Trace file */
4402  s = getenv ("COB_TRACE_FILE");
4403  if (s) {
4404  cob_trace_env = (const char*) cob_save_env_value((char*) cob_trace_env, s);
4405  cob_trace_file = NULL;
4406  } else {
4407  cob_trace_env = NULL;
4408  cob_trace_file = stderr;
4409  }
4410 
4411  /* Disable runtime warnings */
4413  s = getenv ("COB_DISABLE_WARNINGS");
4414  if (s) {
4416 
4417  if (cob_check_env_true(s)) {
4419  }
4420  }
4421 
4422  /* Mangle environment names */
4423  s = getenv ("COB_ENV_MANGLE");
4424  if (s) {
4426 
4427  if (cob_check_env_true(s)) {
4429  }
4430  }
4431 
4432  /* Get user name */
4433  s = getenv ("USERNAME");
4434  if (s) {
4435  cob_user_name = cob_strdup (s);
4436  } else {
4437  s = getenv ("LOGNAME");
4438  if (s) {
4439  cob_user_name = cob_strdup (s);
4440  } else {
4441 #ifdef _WIN32
4442  unsigned long bsiz = COB_ERRBUF_SIZE;
4443  if (GetUserName (runtime_err_str, &bsiz)) {
4445  }
4446 #elif !defined(__OS400__)
4447  s = getlogin ();
4448  if (s) {
4449  cob_user_name = cob_strdup (s);
4450  }
4451 #endif
4452  }
4453  }
4454  if (!cob_user_name) {
4455  cob_user_name = cob_strdup (_("Unknown"));
4456  }
4457 
4458  /* This must be last in this function as we do early return */
4459  /* from certain ifdef's */
4460 
4461 #ifdef _WIN32
4462  s = cob_malloc ((size_t)COB_LARGE_BUFF);
4463  i = GetModuleFileNameA (NULL, s, COB_LARGE_MAX);
4464  if (i > 0 && i < COB_LARGE_BUFF) {
4466  cob_free (s);
4467  return;
4468  }
4469  cob_free (s);
4470 #elif defined(HAVE_READLINK)
4471  path = NULL;
4472  if (!access ("/proc/self/exe", R_OK)) {
4473  path = "/proc/self/exe";
4474  } else if (!access ("/proc/curproc/file", R_OK)) {
4475  path = "/proc/curproc/file";
4476  } else if (!access ("/proc/self/path/a.out", R_OK)) {
4477  path = "/proc/self/path/a.out";
4478  }
4479  if (path) {
4480  s = cob_malloc ((size_t)COB_LARGE_BUFF);
4481  i = (int)readlink (path, s, (size_t)COB_LARGE_MAX);
4482  if (i > 0 && i < COB_LARGE_BUFF) {
4484  cob_free (s);
4485  return;
4486  }
4487  cob_free (s);
4488  }
4489 #endif
4490 
4491 #ifdef HAVE_GETEXECNAME
4492  path = getexecname ();
4493  if (path) {
4494 #ifdef HAVE_REALPATH
4495  s = cob_malloc ((size_t)COB_LARGE_BUFF);
4496  if (realpath (path, s) != NULL) {
4498  } else {
4500  }
4501  cob_free (s);
4502 #else
4504 #endif
4505  return;
4506  }
4507 #endif
4508 
4509  if (argc && argv && argv[0]) {
4510 #ifdef _WIN32
4511  /* Returns malloced path or NULL */
4512  cobglobptr->cob_main_argv0 = _fullpath (NULL, argv[0], 1);
4513 #elif defined(HAVE_CANONICALIZE_FILE_NAME)
4514  /* Returns malloced path or NULL */
4515  cobglobptr->cob_main_argv0 = canonicalize_file_name (argv[0]);
4516 #elif defined(HAVE_REALPATH)
4517  s = cob_malloc ((size_t)COB_LARGE_BUFF);
4518  if (realpath (argv[0], s) != NULL) {
4520  }
4521  cob_free (s);
4522 #endif
4523  if (!cobglobptr->cob_main_argv0) {
4524  cobglobptr->cob_main_argv0 = cob_strdup (argv[0]);
4525  }
4526  } else {
4527  cobglobptr->cob_main_argv0 = cob_strdup (_("Unknown"));
4528  }
4529  /* The above must be last in this function as we do early return */
4530  /* from certain ifdef's */
4531 }
COB_EXPIMP void cob_inspect_after ( const cob_field )
284 {
285  unsigned char *p;
286 
287  for (p = inspect_start; p < inspect_end - str->size + 1; ++p) {
288  if (memcmp (p, str->data, str->size) == 0) {
289  inspect_start = p + str->size;
290  return;
291  }
292  }
294 }
COB_EXPIMP void cob_inspect_all ( cob_field ,
cob_field  
)
330 {
331  inspect_common (f1, f2, INSPECT_ALL);
332 }
COB_EXPIMP void cob_inspect_before ( const cob_field )
271 {
272  unsigned char *p;
273 
274  for (p = inspect_start; p < inspect_end - str->size + 1; ++p) {
275  if (memcmp (p, str->data, str->size) == 0) {
276  inspect_end = p;
277  return;
278  }
279  }
280 }
COB_EXPIMP void cob_inspect_characters ( cob_field )
298 {
299  int *mark;
300  int i;
301  int n;
302  int len;
303 
305  len = (int)(inspect_end - inspect_start);
306  if (inspect_replacing) {
307  /* INSPECT REPLACING CHARACTERS f1 */
308  for (i = 0; i < len; ++i) {
309  if (mark[i] == -1) {
310  mark[i] = f1->data[0];
311  }
312  }
313  } else {
314  /* INSPECT TALLYING f1 CHARACTERS */
315  n = 0;
316  for (i = 0; i < len; ++i) {
317  if (mark[i] == -1) {
318  mark[i] = 1;
319  n++;
320  }
321  }
322  if (n > 0) {
323  cob_add_int (f1, n, 0);
324  }
325  }
326 }
COB_EXPIMP void cob_inspect_converting ( const cob_field ,
const cob_field  
)
354 {
355  size_t i;
356  size_t j;
357  size_t len;
358 
359  if (unlikely(!f1)) {
360  f1 = &str_cob_low;
361  }
362  if (unlikely(!f2)) {
363  f2 = &str_cob_low;
364  }
365  if (f1->size != f2->size) {
366  if (COB_FIELD_TYPE (f2) == COB_TYPE_ALPHANUMERIC_ALL) {
367  alloc_figurative (f2, f1);
368  f2 = &alpha_fld;
369  } else {
370  cob_set_exception (COB_EC_RANGE_INSPECT_SIZE);
371  return;
372  }
373  }
374 
375  len = (size_t)(inspect_end - inspect_start);
376  for (j = 0; j < f1->size; ++j) {
377  for (i = 0; i < len; ++i) {
378  if (inspect_mark[i] == -1 &&
379  inspect_start[i] == f1->data[j]) {
380  inspect_start[i] = f2->data[j];
381  inspect_mark[i] = 1;
382  }
383  }
384  }
385 }
COB_EXPIMP void cob_inspect_finish ( void  )
389 {
390  size_t i;
391 
392  if (inspect_replacing) {
393  for (i = 0; i < inspect_size; ++i) {
394  if (inspect_mark[i] != -1) {
395  inspect_data[i] = inspect_mark[i];
396  }
397  }
398  }
399 
400  if (unlikely(inspect_var)) {
402  }
403 }
COB_EXPIMP void cob_inspect_first ( cob_field ,
cob_field  
)
342 {
343  inspect_common (f1, f2, INSPECT_FIRST);
344 }
COB_EXPIMP void cob_inspect_init ( cob_field ,
const cob_u32_t   
)
232 {
233  size_t i;
234  size_t digcount;
235 
236  if (unlikely(COB_FIELD_IS_NUMDISP (var))) {
237  inspect_var_copy = *var;
239  inspect_sign = COB_GET_SIGN (var);
240  } else {
241  inspect_var = NULL;
242  }
245  inspect_replacing = replacing;
247  inspect_end = NULL;
248  digcount = inspect_size * sizeof (int);
249  if (digcount > inspect_mark_size) {
250  if (inspect_mark) {
252  }
253  inspect_mark = cob_fast_malloc (digcount);
254  inspect_mark_size = digcount;
255  }
256  for (i = 0; i < inspect_size; ++i) {
257  inspect_mark[i] = -1;
258  }
259  cob_set_exception (0);
260 }
COB_EXPIMP void cob_inspect_leading ( cob_field ,
cob_field  
)
336 {
338 }
COB_EXPIMP void cob_inspect_start ( void  )
264 {
267 }
COB_EXPIMP void cob_inspect_trailing ( cob_field ,
cob_field  
)
348 {
350 }
char* cob_int_to_formatted_bytestring ( int  ,
char *   
)
3845  {
3846 
3847  double d;
3848  char* strB;
3849 
3850  if(!number) return NULL;
3851 
3852  strB = (char*) cob_fast_malloc(3);
3853 
3854  if (i > (1024 * 1024)) {
3855  d = i / 1024.0 / 1024.0;
3856  strB = (char*) "MB";
3857  } else if (i > 1024) {
3858  d = i / 1024.0;
3859  strB = (char*) "kB";
3860  } else {
3861  d = 0;
3862  strB = (char*) "B";
3863  }
3864  sprintf(number, "%3.2f %s", d, strB);
3865  return number;
3866 }
char* cob_int_to_string ( int  ,
char *   
)
3838  {
3839  if(!number) return NULL;
3840  sprintf(number, "%i", i);
3841  return number;
3842 }
COB_EXPIMP cob_field* cob_intr_abs ( cob_field )
3438 {
3439  cob_decimal_set_field (&d1, srcfield);
3440  mpz_abs (d1.value, d1.value);
3441 
3442  make_field_entry (srcfield);
3443  (void)cob_decimal_get_field (&d1, curr_field, 0);
3444  return curr_field;
3445 }
COB_EXPIMP cob_field* cob_intr_acos ( cob_field )
3449 {
3450  cob_decimal_set_field (&d1, srcfield);
3451 
3452  mpz_set (d4.value, d1.value);
3453  mpz_set (d5.value, d1.value);
3454  d4.scale = d1.scale;
3455  d5.scale = d1.scale;
3456  mpz_set_si (d2.value, -1L);
3457  d2.scale = 0;
3458  mpz_set_ui (d3.value, 1UL);
3459  d3.scale = 0;
3460 
3461  cob_set_exception (0);
3462  if (cob_decimal_cmp (&d4, &d2) < 0 || cob_decimal_cmp (&d5, &d3) > 0) {
3465  return curr_field;
3466  }
3467 
3471  cob_alloc_field (&d1);
3472  (void)cob_decimal_get_field (&d1, curr_field, 0);
3473 
3474  return curr_field;
3475 }
COB_EXPIMP cob_field* cob_intr_annuity ( cob_field ,
cob_field  
)
3892 {
3893  int sign;
3894 
3895  cob_decimal_set_field (&d1, srcfield1);
3896  cob_decimal_set_field (&d2, srcfield2);
3897 
3898  /* P1 >= 0, P2 > 0 and integer */
3899  sign = mpz_sgn (d1.value);
3900  if (sign < 0 || mpz_sgn (d2.value) <= 0 || d2.scale != 0) {
3903  return curr_field;
3904  }
3905 
3906  if (!sign) {
3907  mpz_set_ui (d1.value, 1UL);
3908  d1.scale = 0;
3909  cob_decimal_div (&d1, &d2);
3910  cob_alloc_field (&d1);
3911  (void)cob_decimal_get_field (&d1, curr_field, 0);
3912  return curr_field;
3913  }
3914 
3915  /* x = P1 / (1 - (1 + P1) ^ (-P2)) */
3916  mpz_neg (d2.value, d2.value);
3917 
3918  mpz_set (d3.value, d1.value);
3919  d3.scale = d1.scale;
3920  mpz_set_ui (d4.value, 1UL);
3921  d4.scale = 0;
3922  cob_decimal_add (&d3, &d4);
3923  cob_trim_decimal (&d3);
3924  cob_trim_decimal (&d2);
3925  cob_decimal_pow (&d3, &d2);
3926  mpz_set_ui (d4.value, 1UL);
3927  d4.scale = 0;
3928  cob_decimal_sub (&d4, &d3);
3929  cob_trim_decimal (&d4);
3930  cob_trim_decimal (&d1);
3931  cob_decimal_div (&d1, &d4);
3932  cob_alloc_field (&d1);
3933  (void)cob_decimal_get_field (&d1, curr_field, 0);
3934  return curr_field;
3935 }
COB_EXPIMP cob_field* cob_intr_asin ( cob_field )
3479 {
3480  cob_decimal_set_field (&d1, srcfield);
3481 
3482  mpz_set (d4.value, d1.value);
3483  mpz_set (d5.value, d1.value);
3484  d4.scale = d1.scale;
3485  d5.scale = d1.scale;
3486  mpz_set_si (d2.value, -1L);
3487  d2.scale = 0;
3488  mpz_set_ui (d3.value, 1UL);
3489  d3.scale = 0;
3490 
3491  cob_set_exception (0);
3492  if (cob_decimal_cmp (&d4, &d2) < 0 || cob_decimal_cmp (&d5, &d3) > 0) {
3495  return curr_field;
3496  }
3497 
3498  if (!mpz_sgn (d1.value)) {
3499  /* Asin (0) = 0 */
3501  return curr_field;
3502  }
3503 
3507  cob_alloc_field (&d1);
3508  (void)cob_decimal_get_field (&d1, curr_field, 0);
3509 
3510  return curr_field;
3511 }
COB_EXPIMP cob_field* cob_intr_atan ( cob_field )
3515 {
3516  cob_decimal_set_field (&d1, srcfield);
3517 
3518  cob_set_exception (0);
3519 
3520  if (!mpz_sgn (d1.value)) {
3521  /* Atan (0) = 0 */
3523  return curr_field;
3524  }
3525 
3529  cob_alloc_field (&d1);
3530  (void)cob_decimal_get_field (&d1, curr_field, 0);
3531 
3532  return curr_field;
3533 }
COB_EXPIMP cob_field* cob_intr_binop ( cob_field ,
const int  ,
cob_field  
)
2174 {
2175  cob_decimal_set_field (&d1, f1);
2176  cob_decimal_set_field (&d2, f2);
2177  switch (op) {
2178  case '+':
2179  cob_decimal_add (&d1, &d2);
2180  break;
2181  case '-':
2182  cob_decimal_sub (&d1, &d2);
2183  break;
2184  case '*':
2185  cob_decimal_mul (&d1, &d2);
2186  break;
2187  case '/':
2188  cob_set_exception (0);
2189  if (!mpz_sgn (d2.value)) {
2190  /* Divide by zero */
2192  mpz_set_ui (d1.value, 0UL);
2193  d1.scale = 0;
2194  } else {
2195  cob_decimal_div (&d1, &d2);
2196  }
2197  break;
2198  case '^':
2199  cob_decimal_pow (&d1, &d2);
2200  break;
2201  default:
2202  break;
2203  }
2204 
2205  cob_alloc_field (&d1);
2206  (void)cob_decimal_get_field (&d1, curr_field, 0);
2207  return curr_field;
2208 }
COB_EXPIMP cob_field* cob_intr_boolean_of_integer ( cob_field ,
cob_field  
)
5738 {
5739  COB_UNUSED (f1);
5740  COB_UNUSED (f2);
5741 
5742  cob_fatal_error (COB_FERROR_FUNCTION);
5743 }
COB_EXPIMP cob_field* cob_intr_byte_length ( cob_field )
2225 {
2226  cob_alloc_set_field_uint ((cob_u32_t)srcfield->size);
2227  return curr_field;
2228 }
COB_EXPIMP cob_field* cob_intr_char ( cob_field )
2964 {
2965  int i;
2966  cob_field field;
2967 
2969  make_field_entry (&field);
2970 
2971  i = cob_get_int (srcfield);
2972  if (i < 1 || i > 256) {
2973  *curr_field->data = 0;
2974  } else {
2975  *curr_field->data = i - 1;
2976  }
2977  return curr_field;
2978 }
COB_EXPIMP cob_field* cob_intr_char_national ( cob_field )
5747 {
5748  COB_UNUSED (srcfield);
5749 
5750  cob_fatal_error (COB_FERROR_FUNCTION);
5751 }
COB_EXPIMP cob_field* cob_intr_combined_datetime ( cob_field ,
cob_field  
)
3007 {
3008  int srdays;
3009  int srtime;
3010  cob_field_attr attr;
3011  cob_field field;
3012  char buff[16];
3013 
3014  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, 12, 5, 0, NULL);
3015  COB_FIELD_INIT (12, NULL, &attr);
3016  make_field_entry (&field);
3017 
3018  cob_set_exception (0);
3019  srdays = cob_get_int (srcdays);
3020  if (!valid_integer_date (srdays)) {
3022  memset (curr_field->data, '0', (size_t)12);
3023  return curr_field;
3024  }
3025  srtime = cob_get_int (srctime);
3026  if (!valid_time (srtime)) {
3028  memset (curr_field->data, '0', (size_t)12);
3029  return curr_field;
3030  }
3031  snprintf (buff, (size_t)15, "%7.7d%5.5d", srdays, srtime);
3032  memcpy (curr_field->data, buff, (size_t)12);
3033  return curr_field;
3034 }
COB_EXPIMP cob_field* cob_intr_concatenate ( const int  ,
const int  ,
const int  ,
  ... 
)
2469 {
2470  cob_field **f;
2471  unsigned char *p;
2472  size_t calcsize;
2473  int i;
2474  cob_field field;
2475  va_list args;
2476 
2477  f = cob_malloc ((size_t)params * sizeof (cob_field *));
2478 
2479  va_start (args, params);
2480 
2481  /* Extract args / calculate size */
2482  calcsize = 0;
2483  for (i = 0; i < params; ++i) {
2484  f[i] = va_arg (args, cob_field *);
2485  calcsize += f[i]->size;
2486  }
2487  va_end (args);
2488 
2489  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2490  make_field_entry (&field);
2491 
2492  p = curr_field->data;
2493  for (i = 0; i < params; ++i) {
2494  memcpy (p, f[i]->data, f[i]->size);
2495  p += f[i]->size;
2496  }
2497 
2498  if (unlikely(offset > 0)) {
2499  calc_ref_mod (curr_field, offset, length);
2500  }
2501  cob_free (f);
2502  return curr_field;
2503 }
COB_EXPIMP cob_field* cob_intr_cos ( cob_field )
3537 {
3538  cob_decimal_set_field (&d1, srcfield);
3539 
3540  cob_set_exception (0);
3541 
3545  cob_alloc_field (&d1);
3546  (void)cob_decimal_get_field (&d1, curr_field, 0);
3547 
3548  return curr_field;
3549 }
COB_EXPIMP cob_field* cob_intr_currency_symbol ( void  )
5211 {
5212 #ifdef HAVE_LOCALECONV
5213  struct lconv *p;
5214  size_t size;
5215 #endif
5216  cob_field field;
5217 
5219  cob_set_exception (0);
5220 
5221 #ifdef HAVE_LOCALECONV
5222  p = localeconv ();
5223  size = strlen (p->currency_symbol);
5224  if (size) {
5225  field.size = size;
5226  } else {
5227  field.size = 1;
5228  }
5229  make_field_entry (&field);
5230  if (size) {
5231  memcpy (curr_field->data, p->currency_symbol, size);
5232  } else {
5233  curr_field->size = 0;
5234  curr_field->data[0] = 0;
5235  }
5236 #else
5237  field.size = 1;
5238  make_field_entry (&field);
5239  curr_field->data[0] = COB_MODULE_PTR->currency_symbol;
5240 #endif
5241  return curr_field;
5242 }
COB_EXPIMP cob_field* cob_intr_current_date ( const int  ,
const int   
)
2869 {
2870 #if defined(_WIN32) && !defined(__CYGWIN__)
2871  struct tm *tmptr;
2872  long contz;
2873  struct _timeb tmb;
2874  cob_field field;
2875 #else
2876 
2877  struct tm *tmptr;
2878 #if !defined(__linux__) && !defined(__CYGWIN__) && !defined(COB_STRFTIME) && defined(HAVE_TIMEZONE)
2879  long contz;
2880 #endif
2881  time_t curtime;
2882  cob_field field;
2883 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2884  struct timeval tmv;
2885  char buff2[8];
2886 #endif
2887 #endif
2888  char buff[24];
2889 
2891  make_field_entry (&field);
2892  memset (buff, 0, sizeof(buff));
2893 
2894 #if defined(_WIN32) && !defined(__CYGWIN__)
2895  _ftime (&tmb);
2896  tmptr = localtime (&(tmb.time));
2897  /* Leap seconds ? */
2898  if (tmptr->tm_sec >= 60) {
2899  tmptr->tm_sec = 59;
2900  }
2901  if (tmb.timezone <= 0) {
2902  contz = -tmb.timezone;
2903  snprintf (buff, (size_t)23,
2904  "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d%2.2d+%2.2ld%2.2ld",
2905  tmptr->tm_year + 1900, tmptr->tm_mon + 1, tmptr->tm_mday,
2906  tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec,
2907  tmb.millitm / 100, contz / 60, contz % 60);
2908  } else {
2909  contz = tmb.timezone;
2910  snprintf (buff, (size_t)23,
2911  "%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d%2.2d-%2.2ld%2.2ld",
2912  tmptr->tm_year + 1900, tmptr->tm_mon + 1, tmptr->tm_mday,
2913  tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec,
2914  tmb.millitm / 100, contz / 60, contz % 60);
2915  }
2916 #else /* defined(_WIN32) && !defined(__CYGWIN__) */
2917 
2918 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2919  gettimeofday (&tmv, NULL);
2920  curtime = tmv.tv_sec;
2921 #else
2922  curtime = time (NULL);
2923 #endif
2924  tmptr = localtime (&curtime);
2925  /* Leap seconds ? */
2926  if (tmptr->tm_sec >= 60) {
2927  tmptr->tm_sec = 59;
2928  }
2929 
2930 #if defined(__linux__) || defined(__CYGWIN__) || defined(COB_STRFTIME)
2931  strftime (buff, (size_t)22, "%Y%m%d%H%M%S00%z", tmptr);
2932 #elif defined(HAVE_TIMEZONE)
2933  strftime (buff, (size_t)17, "%Y%m%d%H%M%S00", tmptr);
2934  contz = timezone;
2935  if (tmptr->tm_isdst > 0) {
2936  contz -= 3600;
2937  }
2938  if (contz <= 0) {
2939  contz = -contz;
2940  buff[16] = '+';
2941  } else {
2942  buff[16] = '-';
2943  }
2944  sprintf(&buff[17], "%2.2ld%2.2ld", contz / 3600, (contz % 3600) / 60);
2945 #else
2946  strftime (buff, (size_t)22, "%Y%m%d%H%M%S0000000", tmptr);
2947 #endif
2948 
2949 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
2950  snprintf(buff2, (size_t)7, "%2.2ld", tmv.tv_usec / 10000);
2951  memcpy (&buff[14], buff2, (size_t)2);
2952 #endif
2953 #endif
2954 
2955  memcpy (curr_field->data, buff, (size_t)21);
2956  if (unlikely(offset > 0)) {
2957  calc_ref_mod (curr_field, offset, length);
2958  }
2959  return curr_field;
2960 }
COB_EXPIMP cob_field* cob_intr_date_of_integer ( cob_field )
3038 {
3039  int days;
3040  int month;
3041  int year;
3042  cob_field_attr attr;
3043  cob_field field;
3044  char buff[16];
3045 
3046  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, NULL);
3047  COB_FIELD_INIT (8, NULL, &attr);
3048  make_field_entry (&field);
3049 
3050  cob_set_exception (0);
3051  /* Base 1601-01-01 */
3052  days = cob_get_int (srcdays);
3053  if (!valid_integer_date (days)) {
3055  memset (curr_field->data, '0', (size_t)8);
3056  return curr_field;
3057  }
3058 
3059  date_of_integer (days, &year, &month, &days);
3060 
3061  snprintf (buff, (size_t)15, "%4.4d%2.2d%2.2d", year, month, days);
3062  memcpy (curr_field->data, buff, (size_t)8);
3063  return curr_field;
3064 }
COB_EXPIMP cob_field* cob_intr_date_to_yyyymmdd ( const int  ,
  ... 
)
4485 {
4486  cob_field *f;
4487  struct tm *timeptr;
4488  va_list args;
4489  time_t t;
4490  int year;
4491  int mmdd;
4492  int interval;
4493  int xqtyear;
4494  int maxyear;
4495 
4496  cob_set_exception (0);
4497  va_start (args, params);
4498  f = va_arg (args, cob_field *);
4499  year = cob_get_int (f);
4500  mmdd = year % 10000;
4501  year /= 10000;
4502  if (params > 1) {
4503  f = va_arg (args, cob_field *);
4504  interval = cob_get_int (f);
4505  } else {
4506  interval = 50;
4507  }
4508  if (params > 2) {
4509  f = va_arg (args, cob_field *);
4510  xqtyear = cob_get_int (f);
4511  } else {
4512  t = time (NULL);
4513  timeptr = localtime (&t);
4514  xqtyear = 1900 + timeptr->tm_year;
4515  }
4516  va_end (args);
4517 
4518  if (year < 0 || year > 999999) {
4521  return curr_field;
4522  }
4523  if (!valid_year (xqtyear)) {
4526  return curr_field;
4527  }
4528  maxyear = xqtyear + interval;
4529  if (maxyear < 1700 || maxyear > 9999) {
4532  return curr_field;
4533  }
4534  if (maxyear % 100 >= year) {
4535  year += 100 * (maxyear / 100);
4536  } else {
4537  year += 100 * ((maxyear / 100) - 1);
4538  }
4539  year *= 10000;
4540  year += mmdd;
4541  cob_alloc_set_field_int (year);
4542  return curr_field;
4543 }
COB_EXPIMP cob_field* cob_intr_day_of_integer ( cob_field )
3068 {
3069  int days;
3070  int baseyear;
3071  cob_field_attr attr;
3072  cob_field field;
3073  char buff[16];
3074 
3075  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, 7, 0, 0, NULL);
3076  COB_FIELD_INIT (7, NULL, &attr);
3077  make_field_entry (&field);
3078 
3079  cob_set_exception (0);
3080  /* Base 1601-01-01 */
3081  days = cob_get_int (srcdays);
3082  if (!valid_integer_date (days)) {
3084  memset (curr_field->data, '0', (size_t)7);
3085  return curr_field;
3086  }
3087 
3088  day_of_integer (days, &baseyear, &days);
3089  snprintf (buff, (size_t)15, "%4.4d%3.3d", baseyear, days);
3090 
3091  memcpy (curr_field->data, buff, (size_t)7);
3092  return curr_field;
3093 }
COB_EXPIMP cob_field* cob_intr_day_to_yyyyddd ( const int  ,
  ... 
)
4547 {
4548  cob_field *f;
4549  struct tm *timeptr;
4550  va_list args;
4551  time_t t;
4552  int year;
4553  int days;
4554  int interval;
4555  int xqtyear;
4556  int maxyear;
4557 
4558  cob_set_exception (0);
4559  va_start (args, params);
4560  f = va_arg (args, cob_field *);
4561  year = cob_get_int (f);
4562  days = year % 1000;
4563  year /= 1000;
4564  if (params > 1) {
4565  f = va_arg (args, cob_field *);
4566  interval = cob_get_int (f);
4567  } else {
4568  interval = 50;
4569  }
4570  if (params > 2) {
4571  f = va_arg (args, cob_field *);
4572  xqtyear = cob_get_int (f);
4573  } else {
4574  t = time (NULL);
4575  timeptr = localtime (&t);
4576  xqtyear = 1900 + timeptr->tm_year;
4577  }
4578  va_end (args);
4579 
4580  if (year < 0 || year > 999999) {
4583  return curr_field;
4584  }
4585  if (!valid_year (xqtyear)) {
4588  return curr_field;
4589  }
4590  maxyear = xqtyear + interval;
4591  if (maxyear < 1700 || maxyear > 9999) {
4594  return curr_field;
4595  }
4596  if (maxyear % 100 >= year) {
4597  year += 100 * (maxyear / 100);
4598  } else {
4599  year += 100 * ((maxyear / 100) - 1);
4600  }
4601  year *= 1000;
4602  year += days;
4603  cob_alloc_set_field_int (year);
4604  return curr_field;
4605 }
COB_EXPIMP cob_field* cob_intr_display_of ( const int  ,
const int  ,
const int  ,
  ... 
)
5756 {
5757  COB_UNUSED (offset);
5758  COB_UNUSED (length);
5759  COB_UNUSED (params);
5760 
5761  cob_fatal_error (COB_FERROR_FUNCTION);
5762 }
COB_EXPIMP cob_field* cob_intr_e ( void  )
3286 {
3287  mpf_set_ui (cob_mpft, 1UL);
3290  cob_alloc_field (&d1);
3291  (void)cob_decimal_get_field (&d1, curr_field, 0);
3292 
3293  return curr_field;
3294 }
COB_EXPIMP cob_field* cob_intr_exception_file ( void  )
2748 {
2749  size_t flen;
2750  cob_field field;
2751 
2754  (cobglobptr->cob_exception_code & 0x0500) != 0x0500) {
2755  field.size = 2;
2756  make_field_entry (&field);
2757  memcpy (curr_field->data, "00", (size_t)2);
2758  } else {
2759  flen = strlen (cobglobptr->cob_error_file->select_name);
2760  field.size = flen + 2;
2761  make_field_entry (&field);
2762  memcpy (curr_field->data,
2763  cobglobptr->cob_error_file->file_status, (size_t)2);
2764  memcpy (&(curr_field->data[2]),
2766  }
2767  return curr_field;
2768 }
COB_EXPIMP cob_field* cob_intr_exception_file_n ( void  )
5766 {
5767  cob_fatal_error (COB_FERROR_FUNCTION);
5768 }
COB_EXPIMP cob_field* cob_intr_exception_location ( void  )
2772 {
2773  char *buff;
2774  cob_field field;
2775 
2778  field.size = 1;
2779  make_field_entry (&field);
2780  *(curr_field->data) = ' ';
2781  return curr_field;
2782  }
2783  buff = cob_malloc ((size_t)COB_SMALL_BUFF);
2785  snprintf (buff, (size_t)COB_SMALL_MAX, "%s; %s OF %s; %u",
2790  } else if (cobglobptr->cob_orig_section) {
2791  snprintf (buff, (size_t)COB_SMALL_MAX, "%s; %s; %u",
2795  } else if (cobglobptr->cob_orig_paragraph) {
2796  snprintf (buff, (size_t)COB_SMALL_MAX, "%s; %s; %u",
2800  } else {
2801  snprintf (buff, (size_t)COB_SMALL_MAX, "%s; ; %u",
2804  }
2805  field.size = strlen (buff);
2806  make_field_entry (&field);
2807  memcpy (curr_field->data, buff, field.size);
2808  cob_free (buff);
2809  return curr_field;
2810 }
COB_EXPIMP cob_field* cob_intr_exception_location_n ( void  )
5772 {
5773  cob_fatal_error (COB_FERROR_FUNCTION);
5774 }
COB_EXPIMP cob_field* cob_intr_exception_statement ( void  )
2834 {
2835  size_t flen;
2836  cob_field field;
2837 
2839  make_field_entry (&field);
2840 
2841  memset (curr_field->data, ' ', (size_t)31);
2843  flen = strlen (cobglobptr->cob_orig_statement);
2844  if (flen > 31) {
2845  memcpy (curr_field->data,
2846  cobglobptr->cob_orig_statement, (size_t)31);
2847  } else {
2848  memcpy (curr_field->data,
2850  }
2851  }
2852  return curr_field;
2853 }
COB_EXPIMP cob_field* cob_intr_exception_status ( void  )
2814 {
2815  const char *except_name;
2816  cob_field field;
2817 
2819  make_field_entry (&field);
2820 
2821  memset (curr_field->data, ' ', (size_t)31);
2823  except_name = cob_get_exception_name ();
2824  if (except_name == NULL) {
2825  except_name = "EXCEPTION-OBJECT";
2826  }
2827  memcpy (curr_field->data, except_name, strlen (except_name));
2828  }
2829  return curr_field;
2830 }
COB_EXPIMP cob_field* cob_intr_exp ( cob_field )
3309 {
3310  cob_decimal_set_field (&d1, srcfield);
3311 
3312  cob_set_exception (0);
3313 
3314  if (!mpz_sgn (d1.value)) {
3315  /* Power is zero */
3317  return curr_field;
3318  }
3319 
3323  cob_alloc_field (&d1);
3324  (void)cob_decimal_get_field (&d1, curr_field, 0);
3325 
3326  return curr_field;
3327 }
COB_EXPIMP cob_field* cob_intr_exp10 ( cob_field )
3331 {
3332  int sign;
3333 
3334  cob_decimal_set_field (&d1, srcfield);
3335 
3336  cob_set_exception (0);
3337 
3338  sign = mpz_sgn (d1.value);
3339  if (!sign) {
3340  /* Power is zero */
3342  return curr_field;
3343  }
3344 
3345  cob_trim_decimal (&d1);
3346 
3347  if (!d1.scale) {
3348  /* Integer positive/negative powers */
3349  if (sign < 0 && mpz_fits_sint_p (d1.value)) {
3350  mpz_abs (d1.value, d1.value);
3351  d1.scale = mpz_get_si (d1.value);
3352  mpz_set_ui (d1.value, 1UL);
3353  cob_alloc_field (&d1);
3354  (void)cob_decimal_get_field (&d1, curr_field, 0);
3355  return curr_field;
3356  }
3357  if (sign > 0 && mpz_fits_ulong_p (d1.value)) {
3358  mpz_ui_pow_ui (d1.value, 10UL, mpz_get_ui (d1.value));
3359  cob_alloc_field (&d1);
3360  (void)cob_decimal_get_field (&d1, curr_field, 0);
3361  return curr_field;
3362  }
3363  }
3364 
3365  mpz_set_ui (d2.value, 10UL);
3366  d2.scale = 0;
3367  cob_decimal_pow (&d2, &d1);
3368  cob_alloc_field (&d2);
3369  (void)cob_decimal_get_field (&d2, curr_field, 0);
3370 
3371  return curr_field;
3372 }
COB_EXPIMP cob_field* cob_intr_factorial ( cob_field )
3265 {
3266  int srcval;
3267 
3268  cob_set_exception (0);
3269  srcval = cob_get_int (srcfield);
3270  d1.scale = 0;
3271  if (srcval < 0) {
3274  return curr_field;
3275  } else {
3276  mpz_fac_ui (d1.value, (cob_uli_t)srcval);
3277  }
3278 
3279  cob_alloc_field (&d1);
3280  (void)cob_decimal_get_field (&d1, curr_field, 0);
3281  return curr_field;
3282 }
COB_EXPIMP cob_field* cob_intr_formatted_current_date ( const int  ,
const int  ,
cob_field  
)
5779 {
5780  COB_UNUSED (offset);
5781  COB_UNUSED (length);
5782  COB_UNUSED (srcfield);
5783 
5784  cob_fatal_error (COB_FERROR_FUNCTION);
5785 }
COB_EXPIMP cob_field* cob_intr_formatted_date ( const int  ,
const int  ,
cob_field ,
cob_field  
)
5509 {
5510  cob_field field;
5511  size_t field_length =
5512  num_leading_nonspace ((char *) format_field->data);
5513  char format_str[MAX_DATE_STR_LENGTH] = { '\0' };
5514  int days;
5515  struct date_format format;
5516  char buff[MAX_DATE_STR_LENGTH] = { '\0' };
5517 
5518  memcpy (format_str, format_field->data, field_length);
5519 
5520  COB_FIELD_INIT (field_length, NULL, &const_alpha_attr);
5521  make_field_entry (&field);
5522 
5523  cob_set_exception (0);
5524  days = cob_get_int (days_field);
5525 
5526  if (!valid_day_and_format (days, format_str)) {
5527  goto invalid_args;
5528  }
5529 
5530  format = parse_date_format_string (format_str);
5531  format_date (format, days, buff);
5532 
5533  memcpy (curr_field->data, buff, (size_t) field_length);
5534  goto end_of_func;
5535 
5536  invalid_args:
5538  memset (curr_field->data, ' ', strlen (format_str));
5539 
5540  end_of_func:
5541  if (unlikely(offset > 0)) {
5542  calc_ref_mod (curr_field, offset, length);
5543  }
5544  return curr_field;
5545 }
COB_EXPIMP cob_field* cob_intr_formatted_datetime ( const int  ,
const int  ,
const int  ,
  ... 
)
5630 {
5631  va_list args;
5632  cob_field *fmt_field;
5633  cob_field *days_field;
5634  cob_field *time_field;
5635  cob_field *offset_time_field;
5636  cob_field field;
5637  size_t field_length;
5638  char fmt_str[MAX_DATETIME_STR_LENGTH] = { '\0' };
5639  char date_fmt_str[MAX_DATE_STR_LENGTH] = { '\0' };
5640  char time_fmt_str[MAX_TIME_STR_LENGTH] = { '\0' };
5641  struct date_format date_fmt;
5642  struct time_format time_fmt;
5643  char formatted_date[MAX_DATE_STR_LENGTH] = { '\0' };
5644  char formatted_time[MAX_TIME_STR_LENGTH] = { '\0' };
5645  int days;
5646  int time;
5647  int offset_time;
5648  int *offset_time_ptr;
5649  char buff[MAX_DATETIME_STR_LENGTH] = { '\0' };
5650 
5651  if (!(params == 3 || params == 4)) {
5653  make_field_entry (&field);
5654  goto invalid_args;
5655  }
5656 
5657  /* Get arguments */
5658  va_start (args, params);
5659 
5660  fmt_field = va_arg (args, cob_field *);
5661  days_field = va_arg (args, cob_field *);
5662  time_field = va_arg (args, cob_field *);
5663  if (params == 4) {
5664  offset_time_field = va_arg (args, cob_field *);
5665  } else {
5666  offset_time_field = NULL;
5667  }
5668 
5669  va_end (args);
5670 
5671  field_length = num_leading_nonspace ((char *) fmt_field->data);
5672  memcpy (fmt_str, fmt_field->data, field_length);
5673 
5674  COB_FIELD_INIT (field_length, NULL, &const_alpha_attr);
5675  make_field_entry (&field);
5676 
5677  cob_set_exception (0);
5678 
5679  /* Validate the formats, dates and times */
5680  if (!cob_valid_datetime_format (fmt_str)) {
5681  goto invalid_args;
5682  }
5683 
5684  days = cob_get_int (days_field);
5685  time = cob_get_int (time_field);
5686 
5687  if (!valid_integer_date (days) || !valid_time (time)) {
5688  goto invalid_args;
5689  }
5690 
5691  split_around_t (fmt_str, date_fmt_str, time_fmt_str);
5692 
5693  time_fmt = parse_time_format_string (time_fmt_str);
5694  if (try_get_valid_offset_time (time_fmt, offset_time_field,
5695  &offset_time, &offset_time_ptr)) {
5696  goto invalid_args;
5697  }
5698 
5699  date_fmt = parse_date_format_string (date_fmt_str);
5700 
5701  /* Format */
5702 
5703  format_date (date_fmt, days, formatted_date);
5704  format_time (time_fmt, time, offset_time_ptr, formatted_time);
5705 
5706  sprintf (buff, "%sT%s", formatted_date, formatted_time);
5707 
5708  memcpy (curr_field->data, buff, (size_t) field_length);
5709  goto end_of_func;
5710 
5711  invalid_args:
5713  if (fmt_str != NULL) {
5714  memset (curr_field->data, ' ', strlen (fmt_str));
5715  }
5716 
5717  end_of_func:
5718  if (unlikely (offset > 0)) {
5719  calc_ref_mod (curr_field, offset, length);
5720  }
5721  return curr_field;
5722 }
COB_EXPIMP cob_field* cob_intr_formatted_time ( const int  ,
const int  ,
const int  ,
  ... 
)
5550 {
5551  va_list args;
5552  cob_field *format_field;
5553  cob_field *time_field;
5554  cob_field *offset_time_field;
5555  cob_field field;
5556  size_t field_length;
5557  char buff[MAX_TIME_STR_LENGTH] = { '\0' };
5558  char format_str[MAX_TIME_STR_LENGTH] = { '\0' };
5559  int time;
5560  int offset_time;
5561  int *offset_time_ptr;
5562  struct time_format format;
5563 
5564  if (!(params == 2 || params == 3)) {
5566  make_field_entry (&field);
5567  goto invalid_args;
5568  }
5569 
5570  /* Get args */
5571  va_start (args, params);
5572 
5573  format_field = va_arg (args, cob_field *);
5574  time_field = va_arg (args, cob_field *);
5575  if (params == 3) {
5576  offset_time_field = va_arg (args, cob_field *);
5577  } else {
5578  offset_time_field = NULL;
5579  }
5580 
5581  va_end (args);
5582 
5583  /* Initialise buffers */
5584  field_length = num_leading_nonspace ((char *) format_field->data);
5585  memcpy (format_str, format_field->data, field_length);
5586 
5587  COB_FIELD_INIT (field_length, NULL, &const_alpha_attr);
5588  make_field_entry (&field);
5589 
5590  cob_set_exception (0);
5591 
5592  /* Extract and validate the times and time format */
5593 
5594  time = cob_get_int (time_field);
5595  if (!valid_time (time)) {
5596  goto invalid_args;
5597  }
5598 
5599  if (!cob_valid_time_format (format_str)) {
5600  goto invalid_args;
5601  }
5602  format = parse_time_format_string (format_str);
5603 
5604  if (try_get_valid_offset_time (format, offset_time_field,
5605  &offset_time, &offset_time_ptr)) {
5606  goto invalid_args;
5607  }
5608 
5609  format_time (format, time, offset_time_ptr, buff);
5610 
5611  memcpy (curr_field->data, buff, (size_t) field_length);
5612  goto end_of_func;
5613 
5614 invalid_args:
5616  if (format_str != NULL) {
5617  memset (curr_field->data, ' ', strlen (format_str));
5618  }
5619 
5620  end_of_func:
5621  if (unlikely(offset > 0)) {
5622  calc_ref_mod (curr_field, offset, length);
5623  }
5624  return curr_field;
5625 }
COB_EXPIMP cob_field* cob_intr_fraction_part ( cob_field )
2277 {
2278  cob_decimal_set_field (&d1, srcfield);
2279  /* Check scale */
2280  if (d1.scale > 0) {
2281  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)d1.scale);
2282  mpz_tdiv_r (d1.value, d1.value, cob_mexp);
2283  } else {
2284  /* No decimals */
2285  mpz_set_ui (d1.value, 0UL);
2286  d1.scale = 0;
2287  }
2288 
2289  cob_alloc_field (&d1);
2290  (void)cob_decimal_get_field (&d1, curr_field, 0);
2291  return curr_field;
2292 }
COB_EXPIMP cob_field* cob_intr_highest_algebraic ( cob_field )
5339 {
5340  cob_uli_t expo;
5341  size_t size;
5342  cob_field field;
5343 
5344  switch (COB_FIELD_TYPE (srcfield)) {
5345  case COB_TYPE_ALPHANUMERIC:
5346  case COB_TYPE_NATIONAL:
5347  size = COB_FIELD_SIZE (srcfield);
5349  make_field_entry (&field);
5350  memset (curr_field->data, 255, size);
5351  break;
5352 
5355  size = COB_FIELD_DIGITS (srcfield);
5357  make_field_entry (&field);
5358  memset (curr_field->data, 255, size);
5359  break;
5360 
5362  if (COB_FIELD_REAL_BINARY (srcfield) ||
5363  !COB_FIELD_BINARY_TRUNC (srcfield)) {
5364  if (!COB_FIELD_HAVE_SIGN (srcfield)) {
5365  expo = COB_FIELD_SIZE (srcfield) * 8U;
5366  } else {
5367  expo = (COB_FIELD_SIZE (srcfield) * 8U) - 1U;
5368  }
5369  mpz_ui_pow_ui (d1.value, 2UL, expo);
5370  mpz_sub_ui (d1.value, d1.value, 1UL);
5371  d1.scale = COB_FIELD_SCALE (srcfield);
5372  cob_alloc_field (&d1);
5373  (void)cob_decimal_get_field (&d1, curr_field, 0);
5374  break;
5375  }
5376  expo = (cob_uli_t)COB_FIELD_DIGITS (srcfield);
5377  mpz_ui_pow_ui (d1.value, 10UL, expo);
5378  mpz_sub_ui (d1.value, d1.value, 1UL);
5379  d1.scale = COB_FIELD_SCALE (srcfield);
5380  cob_alloc_field (&d1);
5381  (void)cob_decimal_get_field (&d1, curr_field, 0);
5382  break;
5383 
5388  break;
5389 
5393  expo = (cob_uli_t)COB_FIELD_DIGITS (srcfield);
5394  mpz_ui_pow_ui (d1.value, 10UL, expo);
5395  mpz_sub_ui (d1.value, d1.value, 1UL);
5396  d1.scale = COB_FIELD_SCALE (srcfield);
5397  cob_alloc_field (&d1);
5398  (void)cob_decimal_get_field (&d1, curr_field, 0);
5399  break;
5400  default:
5403  break;
5404  }
5405  return curr_field;
5406 }
COB_EXPIMP cob_field* cob_intr_integer ( cob_field )
2232 {
2233  int sign;
2234 
2235  cob_decimal_set_field (&d1, srcfield);
2236  /* Check scale */
2237  if (d1.scale < 0) {
2238  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)-d1.scale);
2239  mpz_mul (d1.value, d1.value, cob_mexp);
2240  } else if (d1.scale > 0) {
2241  sign = mpz_sgn (d1.value);
2242  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)d1.scale);
2243  mpz_tdiv_qr (d1.value, cob_mpzt, d1.value, cob_mexp);
2244  /* Check negative and has decimal places */
2245  if (sign < 0 && mpz_sgn (cob_mpzt)) {
2246  mpz_sub_ui (d1.value, d1.value, 1UL);
2247  }
2248  }
2249  d1.scale = 0;
2250 
2251  cob_alloc_field (&d1);
2252  (void)cob_decimal_get_field (&d1, curr_field, 0);
2253  return curr_field;
2254 }
COB_EXPIMP cob_field* cob_intr_integer_of_boolean ( cob_field )
5789 {
5790  COB_UNUSED (srcfield);
5791 
5792  cob_fatal_error (COB_FERROR_FUNCTION);
5793 }
COB_EXPIMP cob_field* cob_intr_integer_of_date ( cob_field )
3097 {
3098  int indate;
3099  int days;
3100  int totaldays;
3101  int month;
3102  int year;
3103  int baseyear;
3104 
3105  cob_set_exception (0);
3106  /* Base 1601-01-01 */
3107  indate = cob_get_int (srcfield);
3108  year = indate / 10000;
3109  if (!valid_year (year)) {
3112  return curr_field;
3113  }
3114  indate %= 10000;
3115  month = indate / 100;
3116  if (month < 1 || month > 12) {
3119  return curr_field;
3120  }
3121  days = indate % 100;
3122  if (days < 1 || days > 31) {
3125  return curr_field;
3126  }
3127  if (leap_year (year)) {
3128  if (days > leap_month_days[month]) {
3131  return curr_field;
3132  }
3133  } else {
3134  if (days > normal_month_days[month]) {
3137  return curr_field;
3138  }
3139  }
3140  totaldays = 0;
3141  baseyear = 1601;
3142  while (baseyear != year) {
3143  if (leap_year (baseyear)) {
3144  totaldays += 366;
3145  } else {
3146  totaldays += 365;
3147  }
3148  ++baseyear;
3149  }
3150  if (leap_year (baseyear)) {
3151  totaldays += leap_days[month - 1];
3152  } else {
3153  totaldays += normal_days[month - 1];
3154  }
3155  totaldays += days;
3156  cob_alloc_set_field_int (totaldays);
3157  return curr_field;
3158 }
COB_EXPIMP cob_field* cob_intr_integer_of_day ( cob_field )
3162 {
3163  int indate;
3164  int days;
3165  cob_u32_t totaldays;
3166  int year;
3167  int baseyear;
3168 
3169  cob_set_exception (0);
3170  /* Base 1601-01-01 */
3171  indate = cob_get_int (srcfield);
3172  year = indate / 1000;
3173  if (!valid_year (year)) {
3176  return curr_field;
3177  }
3178  days = indate % 1000;
3179  if (days < 1 || days > 365 + leap_year (year)) {
3182  return curr_field;
3183  }
3184  totaldays = 0;
3185  baseyear = 1601;
3186  while (baseyear != year) {
3187  if (leap_year (baseyear)) {
3188  totaldays += 366;
3189  } else {
3190  totaldays += 365;
3191  }
3192  ++baseyear;
3193  }
3194  totaldays += days;
3195  cob_alloc_set_field_uint (totaldays);
3196  return curr_field;
3197 }
COB_EXPIMP cob_field* cob_intr_integer_of_formatted_date ( cob_field ,
cob_field  
)
5729 {
5730  COB_UNUSED (format_field);
5731  COB_UNUSED (date_field);
5732 
5733  cob_fatal_error (COB_FERROR_FUNCTION);
5734 }
COB_EXPIMP cob_field* cob_intr_integer_part ( cob_field )
2258 {
2259  cob_decimal_set_field (&d1, srcfield);
2260  /* Check scale */
2261  if (d1.scale < 0) {
2262  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)-d1.scale);
2263  mpz_mul (d1.value, d1.value, cob_mexp);
2264  } else if (d1.scale > 0) {
2265  mpz_ui_pow_ui (cob_mexp, 10UL, (cob_uli_t)d1.scale);
2266  mpz_tdiv_q (d1.value, d1.value, cob_mexp);
2267  }
2268  d1.scale = 0;
2269 
2270  cob_alloc_field (&d1);
2271  (void)cob_decimal_get_field (&d1, curr_field, 0);
2272  return curr_field;
2273 }
COB_EXPIMP cob_field* cob_intr_lcl_time_from_secs ( const int  ,
const int  ,
cob_field ,
cob_field  
)
4961 {
4962  cob_field field;
4963 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4964  size_t len;
4965  int indate;
4966  int hours;
4967  int minutes;
4968  int seconds;
4969 #ifdef HAVE_LANGINFO_CODESET
4970  char *deflocale = NULL;
4971  struct tm tstruct;
4972  char buff2[128];
4973 #else
4974  unsigned char *p;
4975  LCID localeid = LOCALE_USER_DEFAULT;
4976  SYSTEMTIME syst;
4977 #endif
4978  char buff[128];
4979  char locale_buff[COB_SMALL_BUFF];
4980 #endif
4981 
4983  cob_set_exception (0);
4984 
4985 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4986  if (COB_FIELD_IS_NUMERIC (srcfield)) {
4987  indate = cob_get_int (srcfield);
4988  } else {
4989  goto derror;
4990  }
4991  if (!valid_time (indate)) {
4992  goto derror;
4993  }
4994  hours = indate / 3600;
4995  indate %= 3600;
4996  minutes = indate / 60;
4997  seconds = indate % 60;
4998 
4999 #ifdef HAVE_LANGINFO_CODESET
5000  memset ((void *)&tstruct, 0, sizeof(struct tm));
5001  tstruct.tm_hour = hours;
5002  tstruct.tm_min = minutes;
5003  tstruct.tm_sec = seconds;
5004  if (locale_field) {
5005  if (locale_field->size >= COB_SMALL_BUFF) {
5006  goto derror;
5007  }
5008  cob_field_to_string (locale_field, locale_buff,
5009  (size_t)COB_SMALL_MAX);
5010  deflocale = locale_buff;
5011  (void) setlocale (LC_TIME, deflocale);
5012  }
5013  memset (buff2, 0, sizeof(buff2));
5014  snprintf(buff2, sizeof(buff2) - 1, "%s", nl_langinfo(T_FMT));
5015  if (deflocale) {
5016  (void) setlocale (LC_ALL, cobglobptr->cob_locale);
5017  }
5018  strftime (buff, sizeof(buff), buff2, &tstruct);
5019 #else
5020  memset ((void *)&syst, 0, sizeof(syst));
5021  syst.wHour = hours;
5022  syst.wMinute = minutes;
5023  syst.wSecond = seconds;
5024  if (locale_field) {
5025  if (locale_field->size >= COB_SMALL_BUFF) {
5026  goto derror;
5027  }
5028  cob_field_to_string (locale_field, locale_buff,
5029  COB_SMALL_MAX);
5030  for (p = (unsigned char *)locale_buff; *p; ++p) {
5031  if (isalnum(*p) || *p == '_') {
5032  continue;
5033  }
5034  break;
5035  }
5036  *p = 0;
5037  for (len = 0; len < WINLOCSIZE; ++len) {
5038  if (!strcmp(locale_buff, wintable[len].winlocalename)) {
5039  localeid = wintable[len].winlocaleid;
5040  break;
5041  }
5042  }
5043  if (len == WINLOCSIZE) {
5044  goto derror;
5045  }
5046  }
5047  if (!GetTimeFormat (localeid, LOCALE_NOUSEROVERRIDE, &syst, NULL, buff, sizeof(buff))) {
5048 
5049  goto derror;
5050  }
5051 #endif
5052  len = strlen (buff);
5053  field.size = len;
5054  make_field_entry (&field);
5055  memcpy (curr_field->data, buff, len);
5056  if (unlikely(offset > 0)) {
5057  calc_ref_mod (curr_field, offset, length);
5058  }
5059  return curr_field;
5060 derror:
5061 #endif
5062  field.size = 10;
5063  make_field_entry (&field);
5064  memset (curr_field->data, ' ', (size_t)10);
5066  return curr_field;
5067 }
COB_EXPIMP cob_field* cob_intr_length ( cob_field )
2214 {
2215  if (COB_FIELD_IS_NATIONAL (srcfield)) {
2216  cob_alloc_set_field_uint ((cob_u32_t)srcfield->size / COB_NATIONAL_SIZE);
2217  } else {
2218  cob_alloc_set_field_uint ((cob_u32_t)srcfield->size);
2219  }
2220  return curr_field;
2221 }
COB_EXPIMP cob_field* cob_intr_locale_compare ( const int  ,
  ... 
)
5410 {
5411  cob_field *f1;
5412  cob_field *f2;
5413  cob_field *locale_field;
5414 #ifdef HAVE_STRCOLL
5415  unsigned char *p;
5416  unsigned char *p1;
5417  unsigned char *p2;
5418  char *deflocale;
5419  size_t size;
5420  size_t size2;
5421  int ret;
5422 #endif
5423  cob_field field;
5424  va_list args;
5425 
5426  cob_set_exception (0);
5427  va_start (args, params);
5428  f1 = va_arg (args, cob_field *);
5429  f2 = va_arg (args, cob_field *);
5430  if (params > 2) {
5431  locale_field = va_arg (args, cob_field *);
5432  } else {
5433  locale_field = NULL;
5434  }
5435  va_end (args);
5436 
5438  make_field_entry (&field);
5439 
5440 #ifdef HAVE_STRCOLL
5441  deflocale = NULL;
5442 
5443  size = f1->size;
5444  size2 = size;
5445  for (p = f1->data + size - 1U; p != f1->data; --p) {
5446  if (*p != ' ') {
5447  break;
5448  }
5449  size2--;
5450  }
5451  p1 = cob_malloc (size2 + 1U);
5452  memcpy (p1, f1->data, size2);
5453 
5454  size = f2->size;
5455  size2 = size;
5456  for (p = f2->data + size - 1U; p != f2->data; --p) {
5457  if (*p != ' ') {
5458  break;
5459  }
5460  size2--;
5461  }
5462  p2 = cob_malloc (size2 + 1U);
5463  memcpy (p2, f2->data, size2);
5464 
5465  if (locale_field) {
5466  if (!locale_field->size) {
5467  goto derror;
5468  }
5469 #ifdef HAVE_SETLOCALE
5470  deflocale = cob_malloc (locale_field->size + 1U);
5471  cob_field_to_string (locale_field, deflocale,
5472  (size_t)(locale_field->size + 1U));
5473  (void) setlocale (LC_COLLATE, deflocale);
5474 #else
5475  goto derror;
5476 #endif
5477  }
5478 
5479  ret = strcoll ((char *)p1, (char *)p2);
5480  if (ret < 0) {
5481  curr_field->data[0] = '<';
5482  } else if (ret > 0) {
5483  curr_field->data[0] = '>';
5484  } else {
5485  curr_field->data[0] = '=';
5486  }
5487  cob_free (p1);
5488  cob_free (p2);
5489 
5490 #ifdef HAVE_SETLOCALE
5491  if (deflocale) {
5492  (void) setlocale (LC_ALL, cobglobptr->cob_locale);
5493  cob_free (deflocale);
5494  }
5495 #endif
5496 
5497  return curr_field;
5498 derror:
5499 #endif
5500  curr_field->data[0] = ' ';
5502 
5503  return curr_field;
5504 }
COB_EXPIMP cob_field* cob_intr_locale_date ( const int  ,
const int  ,
cob_field ,
cob_field  
)
4692 {
4693  cob_field field;
4694 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4695  size_t len;
4696  int indate;
4697  int days;
4698  int month;
4699  int year;
4700 #ifdef HAVE_LANGINFO_CODESET
4701  unsigned char *p;
4702  char *deflocale = NULL;
4703  struct tm tstruct;
4704  char buff2[128];
4705 #else
4706  unsigned char *p;
4707  LCID localeid = LOCALE_USER_DEFAULT;
4708  SYSTEMTIME syst;
4709 #endif
4710  char buff[128];
4711  char locale_buff[COB_SMALL_BUFF];
4712 #endif
4713 
4715  cob_set_exception (0);
4716 
4717 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4718  if (COB_FIELD_IS_NUMERIC (srcfield)) {
4719  indate = cob_get_int (srcfield);
4720  } else {
4721  if (srcfield->size < 8) {
4722  goto derror;
4723  }
4724  p = srcfield->data;
4725  indate = 0;
4726  for (len = 0; len < 8; ++len, ++p) {
4727  if (isdigit (*p)) {
4728  indate *= 10;
4729  indate += (*p - '0');
4730  } else {
4731  goto derror;
4732  }
4733  }
4734  }
4735  year = indate / 10000;
4736  if (!valid_year (year)) {
4737  goto derror;
4738  }
4739  indate %= 10000;
4740  month = indate / 100;
4741  if (month < 1 || month > 12) {
4742  goto derror;
4743  }
4744  days = indate % 100;
4745  if (days < 1 || days > 31) {
4746  goto derror;
4747  }
4748  if (leap_year (year)) {
4749  if (days > leap_month_days[month]) {
4750  goto derror;
4751  }
4752  } else {
4753  if (days > normal_month_days[month]) {
4754  goto derror;
4755  }
4756  }
4757 #ifdef HAVE_LANGINFO_CODESET
4758  month--;
4759 
4760  memset ((void *)&tstruct, 0, sizeof(struct tm));
4761  tstruct.tm_year = year - 1900;
4762  tstruct.tm_mon = month;
4763  tstruct.tm_mday = days;
4764  if (locale_field) {
4765  if (locale_field->size >= COB_SMALL_BUFF) {
4766  goto derror;
4767  }
4768  cob_field_to_string (locale_field, locale_buff,
4769  (size_t)COB_SMALL_MAX);
4770  deflocale = locale_buff;
4771  (void) setlocale (LC_TIME, deflocale);
4772  }
4773  memset (buff2, 0, sizeof(buff2));
4774  snprintf(buff2, sizeof(buff2) - 1, "%s", nl_langinfo(D_FMT));
4775  if (deflocale) {
4776  (void) setlocale (LC_ALL, cobglobptr->cob_locale);
4777  }
4778  strftime (buff, sizeof(buff), buff2, &tstruct);
4779 #else
4780  memset ((void *)&syst, 0, sizeof(syst));
4781  syst.wYear = year;
4782  syst.wMonth = month;
4783  syst.wDay = days;
4784  if (locale_field) {
4785  if (locale_field->size >= COB_SMALL_BUFF) {
4786  goto derror;
4787  }
4788  cob_field_to_string (locale_field, locale_buff,
4789  COB_SMALL_MAX);
4790  for (p = (unsigned char *)locale_buff; *p; ++p) {
4791  if (isalnum(*p) || *p == '_') {
4792  continue;
4793  }
4794  break;
4795  }
4796  *p = 0;
4797  for (len = 0; len < WINLOCSIZE; ++len) {
4798  if (!strcmp(locale_buff, wintable[len].winlocalename)) {
4799  localeid = wintable[len].winlocaleid;
4800  break;
4801  }
4802  }
4803  if (len == WINLOCSIZE) {
4804  goto derror;
4805  }
4806  }
4807  if (!GetDateFormat (localeid, DATE_SHORTDATE, &syst, NULL, buff, sizeof(buff))) {
4808  goto derror;
4809  }
4810 #endif
4811  len = strlen (buff);
4812  field.size = len;
4813  make_field_entry (&field);
4814  memcpy (curr_field->data, buff, len);
4815  if (unlikely(offset > 0)) {
4816  calc_ref_mod (curr_field, offset, length);
4817  }
4818  return curr_field;
4819 derror:
4820 #endif
4821  field.size = 10;
4822  make_field_entry (&field);
4823  memset (curr_field->data, ' ', (size_t)10);
4825  return curr_field;
4826 }
COB_EXPIMP cob_field* cob_intr_locale_time ( const int  ,
const int  ,
cob_field ,
cob_field  
)
4831 {
4832  cob_field field;
4833 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4834  size_t len;
4835  int indate;
4836  int hours;
4837  int minutes;
4838  int seconds;
4839 #ifdef HAVE_LANGINFO_CODESET
4840  unsigned char *p;
4841  char *deflocale = NULL;
4842  struct tm tstruct;
4843  char buff2[128];
4844 #else
4845  unsigned char *p;
4846  LCID localeid = LOCALE_USER_DEFAULT;
4847  SYSTEMTIME syst;
4848 #endif
4849  char buff[128];
4850  char locale_buff[COB_SMALL_BUFF];
4851 #endif
4852 
4854  cob_set_exception (0);
4855 
4856 #if defined(_WIN32) || defined(__CYGWIN__) || defined(HAVE_LANGINFO_CODESET)
4857  if (COB_FIELD_IS_NUMERIC (srcfield)) {
4858  indate = cob_get_int (srcfield);
4859  } else {
4860  if (srcfield->size < 6) {
4861  goto derror;
4862  }
4863  p = srcfield->data;
4864  indate = 0;
4865  for (len = 0; len < 6; ++len, ++p) {
4866  if (isdigit (*p)) {
4867  indate *= 10;
4868  indate += (*p - '0');
4869  } else {
4870  goto derror;
4871  }
4872  }
4873  }
4874  hours = indate / 10000;
4875  if (hours < 0 || hours > 24) {
4876  goto derror;
4877  }
4878  indate %= 10000;
4879  minutes = indate / 100;
4880  if (minutes < 0 || minutes > 59) {
4881  goto derror;
4882  }
4883  seconds = indate % 100;
4884  if (seconds < 0 || seconds > 59) {
4885  goto derror;
4886  }
4887 
4888 #ifdef HAVE_LANGINFO_CODESET
4889  memset ((void *)&tstruct, 0, sizeof(struct tm));
4890  tstruct.tm_hour = hours;
4891  tstruct.tm_min = minutes;
4892  tstruct.tm_sec = seconds;
4893  if (locale_field) {
4894  if (locale_field->size >= COB_SMALL_BUFF) {
4895  goto derror;
4896  }
4897  cob_field_to_string (locale_field, locale_buff,
4898  (size_t)COB_SMALL_MAX);
4899  deflocale = locale_buff;
4900  (void) setlocale (LC_TIME, deflocale);
4901  }
4902  memset (buff2, 0, sizeof(buff2));
4903  snprintf(buff2, sizeof(buff2) - 1, "%s", nl_langinfo(T_FMT));
4904  if (deflocale) {
4905  (void) setlocale (LC_ALL, cobglobptr->cob_locale);
4906  }
4907  strftime (buff, sizeof(buff), buff2, &tstruct);
4908 #else
4909  memset ((void *)&syst, 0, sizeof(syst));
4910  syst.wHour = hours;
4911  syst.wMinute = minutes;
4912  syst.wSecond = seconds;
4913  if (locale_field) {
4914  if (locale_field->size >= COB_SMALL_BUFF) {
4915  goto derror;
4916  }
4917  cob_field_to_string (locale_field, locale_buff,
4918  COB_SMALL_MAX);
4919  for (p = (unsigned char *)locale_buff; *p; ++p) {
4920  if (isalnum((int)*p) || *p == '_') {
4921  continue;
4922  }
4923  break;
4924  }
4925  *p = 0;
4926  for (len = 0; len < WINLOCSIZE; ++len) {
4927  if (!strcmp(locale_buff, wintable[len].winlocalename)) {
4928  localeid = wintable[len].winlocaleid;
4929  break;
4930  }
4931  }
4932  if (len == WINLOCSIZE) {
4933  goto derror;
4934  }
4935  }
4936  if (!GetTimeFormat (localeid, LOCALE_NOUSEROVERRIDE, &syst, NULL, buff, sizeof(buff))) {
4937 
4938  goto derror;
4939  }
4940 #endif
4941  len = strlen (buff);
4942  field.size = len;
4943  make_field_entry (&field);
4944  memcpy (curr_field->data, buff, len);
4945  if (unlikely(offset > 0)) {
4946  calc_ref_mod (curr_field, offset, length);
4947  }
4948  return curr_field;
4949 derror:
4950 #endif
4951  field.size = 10;
4952  make_field_entry (&field);
4953  memset (curr_field->data, ' ', (size_t)10);
4955  return curr_field;
4956 }
COB_EXPIMP cob_field* cob_intr_log ( cob_field )
3376 {
3377  cob_decimal_set_field (&d1, srcfield);
3378 
3379  cob_set_exception (0);
3380  if (mpz_sgn (d1.value) <= 0) {
3383  return curr_field;
3384  }
3385 
3386  if (d1.scale) {
3387  cob_trim_decimal (&d1);
3388  }
3389 
3390  if (!d1.scale && !mpz_cmp_ui (d1.value, 1UL)) {
3391  /* Log (1) = 0 */
3393  return curr_field;
3394  }
3395 
3399  cob_alloc_field (&d1);
3400  (void)cob_decimal_get_field (&d1, curr_field, 0);
3401 
3402  return curr_field;
3403 }
COB_EXPIMP cob_field* cob_intr_log10 ( cob_field )
3407 {
3408  cob_decimal_set_field (&d1, srcfield);
3409 
3410  cob_set_exception (0);
3411  if (mpz_sgn (d1.value) <= 0) {
3414  return curr_field;
3415  }
3416 
3417  if (d1.scale) {
3418  cob_trim_decimal (&d1);
3419  }
3420 
3421  if (!d1.scale && !mpz_cmp_ui (d1.value, 1UL)) {
3422  /* Log10 (1) = 0 */
3424  return curr_field;
3425  }
3426 
3430  cob_alloc_field (&d1);
3431  (void)cob_decimal_get_field (&d1, curr_field, 0);
3432 
3433  return curr_field;
3434 }
COB_EXPIMP cob_field* cob_intr_lower_case ( const int  ,
const int  ,
cob_field  
)
2321 {
2322  size_t i, size;
2323 
2324  make_field_entry (srcfield);
2325 
2326  size = srcfield->size;
2327  for (i = 0; i < size; ++i) {
2328  curr_field->data[i] = (cob_u8_t)tolower (srcfield->data[i]);
2329  }
2330  if (unlikely(offset > 0)) {
2331  calc_ref_mod (curr_field, offset, length);
2332  }
2333  return curr_field;
2334 }
COB_EXPIMP cob_field* cob_intr_lowest_algebraic ( cob_field )
5267 {
5268  cob_uli_t expo;
5269  cob_field field;
5270 
5271  switch (COB_FIELD_TYPE (srcfield)) {
5272  case COB_TYPE_ALPHANUMERIC:
5273  case COB_TYPE_NATIONAL:
5274  COB_FIELD_INIT (COB_FIELD_SIZE (srcfield), NULL, &const_alpha_attr);
5275  make_field_entry (&field);
5276  break;
5277 
5280  COB_FIELD_INIT (COB_FIELD_DIGITS (srcfield), NULL, &const_alpha_attr);
5281  make_field_entry (&field);
5282  break;
5283 
5285  if (!COB_FIELD_HAVE_SIGN (srcfield)) {
5287  break;
5288  }
5289  if (COB_FIELD_REAL_BINARY (srcfield) ||
5290  !COB_FIELD_BINARY_TRUNC (srcfield)) {
5291  expo = (cob_uli_t)((COB_FIELD_SIZE (srcfield) * 8U) - 1U);
5292  mpz_ui_pow_ui (d1.value, 2UL, expo);
5293  mpz_neg (d1.value, d1.value);
5294  d1.scale = COB_FIELD_SCALE (srcfield);
5295  cob_alloc_field (&d1);
5296  (void)cob_decimal_get_field (&d1, curr_field, 0);
5297  break;
5298  }
5299  expo = (cob_uli_t)COB_FIELD_DIGITS (srcfield);
5300  mpz_ui_pow_ui (d1.value, 10UL, expo);
5301  mpz_sub_ui (d1.value, d1.value, 1UL);
5302  mpz_neg (d1.value, d1.value);
5303  d1.scale = COB_FIELD_SCALE (srcfield);
5304  cob_alloc_field (&d1);
5305  (void)cob_decimal_get_field (&d1, curr_field, 0);
5306  break;
5307 
5312  break;
5313 
5317  if (!COB_FIELD_HAVE_SIGN (srcfield)) {
5319  break;
5320  }
5321  expo = (cob_uli_t)COB_FIELD_DIGITS (srcfield);
5322  mpz_ui_pow_ui (d1.value, 10UL, expo);
5323  mpz_sub_ui (d1.value, d1.value, 1UL);
5324  mpz_neg (d1.value, d1.value);
5325  d1.scale = COB_FIELD_SCALE (srcfield);
5326  cob_alloc_field (&d1);
5327  (void)cob_decimal_get_field (&d1, curr_field, 0);
5328  break;
5329  default:
5332  break;
5333  }
5334  return curr_field;
5335 }
COB_EXPIMP cob_field* cob_intr_max ( const int  ,
  ... 
)
4039 {
4040  cob_field *f;
4041  cob_field *basef;
4042  va_list args;
4043  int i;
4044 
4045  va_start (args, params);
4046 
4047  basef = va_arg (args, cob_field *);
4048  for (i = 1; i < params; ++i) {
4049  f = va_arg (args, cob_field *);
4050  if (cob_cmp (f, basef) > 0) {
4051  basef = f;
4052  }
4053  }
4054  va_end (args);
4055 
4056  make_field_entry (basef);
4057  memcpy (curr_field->data, basef->data, basef->size);
4058  return curr_field;
4059 }
COB_EXPIMP cob_field* cob_intr_mean ( const int  ,
  ... 
)
4147 {
4148  cob_field *f;
4149  va_list args;
4150  int i;
4151 
4152  va_start (args, params);
4153 
4154  if (params == 1) {
4155  f = va_arg (args, cob_field *);
4156  va_end (args);
4157  make_field_entry (f);
4158  memcpy (curr_field->data, f->data, f->size);
4159  return curr_field;
4160  }
4161 
4162  mpz_set_ui (d1.value, 0UL);
4163  d1.scale = 0;
4164 
4165  for (i = 0; i < params; ++i) {
4166  f = va_arg (args, cob_field *);
4167  cob_decimal_set_field (&d2, f);
4168  cob_decimal_add (&d1, &d2);
4169  }
4170  va_end (args);
4171 
4172  mpz_set_ui (d2.value, (cob_uli_t)params);
4173  d2.scale = 0;
4174  cob_decimal_div (&d1, &d2);
4175 
4176  cob_alloc_field (&d1);
4177  (void)cob_decimal_get_field (&d1, curr_field, 0);
4178 
4179  return curr_field;
4180 }
COB_EXPIMP cob_field* cob_intr_median ( const int  ,
  ... 
)
4099 {
4100  cob_field *f;
4101  cob_field **field_alloc;
4102  va_list args;
4103  int i;
4104 
4105  va_start (args, params);
4106 
4107  f = va_arg (args, cob_field *);
4108  if (params == 1) {
4109  va_end (args);
4110  make_field_entry (f);
4111  memcpy (curr_field->data, f->data, f->size);
4112  return curr_field;
4113  }
4114 
4115  field_alloc = cob_malloc ((size_t)params * sizeof (cob_field *));
4116  field_alloc[0] = f;
4117 
4118  for (i = 1; i < params; ++i) {
4119  field_alloc[i] = va_arg (args, cob_field *);
4120  }
4121  va_end (args);
4122 
4123  qsort (field_alloc, (size_t)params, (size_t)sizeof (cob_field *),
4124  comp_field);
4125 
4126  i = params / 2;
4127  if (params % 2) {
4128  f = field_alloc[i];
4129  make_field_entry (f);
4130  memcpy (curr_field->data, f->data, f->size);
4131  } else {
4132  cob_decimal_set_field (&d1, field_alloc[i-1]);
4133  cob_decimal_set_field (&d2, field_alloc[i]);
4134  cob_decimal_add (&d1, &d2);
4135  mpz_set_ui (d2.value, 2UL);
4136  d2.scale = 0;
4137  cob_decimal_div (&d1, &d2);
4138  cob_alloc_field (&d1);
4139  (void)cob_decimal_get_field (&d1, curr_field, 0);
4140  }
4141  cob_free (field_alloc);
4142  return curr_field;
4143 }
COB_EXPIMP cob_field* cob_intr_midrange ( const int  ,
  ... 
)
4063 {
4064  cob_field *f;
4065  cob_field *basemin;
4066  cob_field *basemax;
4067  va_list args;
4068  int i;
4069 
4070  va_start (args, params);
4071 
4072  basemin = va_arg (args, cob_field *);
4073  basemax = basemin;
4074  for (i = 1; i < params; ++i) {
4075  f = va_arg (args, cob_field *);
4076  if (cob_cmp (f, basemin) < 0) {
4077  basemin = f;
4078  }
4079  if (cob_cmp (f, basemax) > 0) {
4080  basemax = f;
4081  }
4082  }
4083  va_end (args);
4084 
4085  cob_decimal_set_field (&d1, basemin);
4086  cob_decimal_set_field (&d2, basemax);
4087  cob_decimal_add (&d1, &d2);
4088  mpz_set_ui (d2.value, 2UL);
4089  d2.scale = 0;
4090  cob_decimal_div (&d1, &d2);
4091 
4092  cob_alloc_field (&d1);
4093  (void)cob_decimal_get_field (&d1, curr_field, 0);
4094  return curr_field;
4095 }
COB_EXPIMP cob_field* cob_intr_min ( const int  ,
  ... 
)
4015 {
4016  cob_field *f;
4017  cob_field *basef;
4018  va_list args;
4019  int i;
4020 
4021  va_start (args, params);
4022 
4023  basef = va_arg (args, cob_field *);
4024  for (i = 1; i < params; ++i) {
4025  f = va_arg (args, cob_field *);
4026  if (cob_cmp (f, basef) < 0) {
4027  basef = f;
4028  }
4029  }
4030  va_end (args);
4031 
4032  make_field_entry (basef);
4033  memcpy (curr_field->data, basef->data, basef->size);
4034  return curr_field;
4035 }
COB_EXPIMP cob_field* cob_intr_mod ( cob_field ,
cob_field  
)
4184 {
4185  return cob_mod_or_rem (srcfield1, srcfield2, 0);
4186 }
COB_EXPIMP cob_field* cob_intr_module_caller_id ( void  )
2398 {
2399  size_t calcsize;
2400  cob_field field;
2401 
2402  if (!COB_MODULE_PTR->next) {
2404  make_field_entry (&field);
2405  curr_field->size = 0;
2406  curr_field->data[0] = ' ';
2407  return curr_field;
2408  }
2409  calcsize = strlen (COB_MODULE_PTR->next->module_name);
2410  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2411  make_field_entry (&field);
2412  memcpy (curr_field->data, COB_MODULE_PTR->next->module_name,
2413  calcsize);
2414  return curr_field;
2415 }
COB_EXPIMP cob_field* cob_intr_module_date ( void  )
2355 {
2356  cob_field_attr attr;
2357  cob_field field;
2358  char buff[16];
2359 
2360  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, 8, 0, 0, NULL);
2361  COB_FIELD_INIT (8, NULL, &attr);
2362  make_field_entry (&field);
2363  snprintf (buff, sizeof(buff), "%8.8u", COB_MODULE_PTR->module_date);
2364  memcpy (curr_field->data, buff, (size_t)8);
2365  return curr_field;
2366 }
COB_EXPIMP cob_field* cob_intr_module_formatted_date ( void  )
2419 {
2420  size_t calcsize;
2421  cob_field field;
2422 
2423  calcsize = strlen (COB_MODULE_PTR->module_formatted_date);
2424  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2425  make_field_entry (&field);
2426  memcpy (curr_field->data, COB_MODULE_PTR->module_formatted_date,
2427  calcsize);
2428  return curr_field;
2429 }
COB_EXPIMP cob_field* cob_intr_module_id ( void  )
2385 {
2386  size_t calcsize;
2387  cob_field field;
2388 
2389  calcsize = strlen (COB_MODULE_PTR->module_name);
2390  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2391  make_field_entry (&field);
2392  memcpy (curr_field->data, COB_MODULE_PTR->module_name, calcsize);
2393  return curr_field;
2394 }
COB_EXPIMP cob_field* cob_intr_module_path ( void  )
2446 {
2447  size_t calcsize;
2448  cob_field field;
2449 
2450  if (!COB_MODULE_PTR->module_path ||
2451  !*(COB_MODULE_PTR->module_path)) {
2453  make_field_entry (&field);
2454  curr_field->size = 0;
2455  curr_field->data[0] = ' ';
2456  return curr_field;
2457  }
2458  calcsize = strlen (*(COB_MODULE_PTR->module_path));
2459  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2460  make_field_entry (&field);
2461  memcpy (curr_field->data, *(COB_MODULE_PTR->module_path),
2462  calcsize);
2463  return curr_field;
2464 }
COB_EXPIMP cob_field* cob_intr_module_source ( void  )
2433 {
2434  size_t calcsize;
2435  cob_field field;
2436 
2437  calcsize = strlen (COB_MODULE_PTR->module_source);
2438  COB_FIELD_INIT (calcsize, NULL, &const_alpha_attr);
2439  make_field_entry (&field);
2440  memcpy (curr_field->data, COB_MODULE_PTR->module_source, calcsize);
2441  return curr_field;
2442 }
COB_EXPIMP cob_field* cob_intr_module_time ( void  )
2370 {
2371  cob_field_attr attr;
2372  cob_field field;
2373  char buff[8];
2374 
2375  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, 6, 0, 0, NULL);
2376  COB_FIELD_INIT (6, NULL, &attr);
2377  make_field_entry (&field);
2378  snprintf (buff, sizeof(buff), "%6.6u", COB_MODULE_PTR->module_time);
2379  memcpy (curr_field->data, buff, (size_t)6);
2380  return curr_field;
2381 }
COB_EXPIMP cob_field* cob_intr_mon_decimal_point ( void  )
5071 {
5072 #ifdef HAVE_LOCALECONV
5073  struct lconv *p;
5074  size_t size;
5075 #endif
5076  cob_field field;
5077 
5079  cob_set_exception (0);
5080 
5081 #ifdef HAVE_LOCALECONV
5082  p = localeconv ();
5083  size = strlen (p->mon_decimal_point);
5084  if (size) {
5085  field.size = size;
5086  } else {
5087  field.size = 1;
5088  }
5089  make_field_entry (&field);
5090  if (size) {
5091  memcpy (curr_field->data, p->mon_decimal_point, size);
5092  } else {
5093  curr_field->size = 0;
5094  curr_field->data[0] = 0;
5095  }
5096 #else
5097  field.size = 1;
5098  make_field_entry (&field);
5099  curr_field->data[0] = COB_MODULE_PTR->decimal_point;
5100 #endif
5101  return curr_field;
5102 }
COB_EXPIMP cob_field* cob_intr_mon_thousands_sep ( void  )
5141 {
5142 #ifdef HAVE_LOCALECONV
5143  struct lconv *p;
5144  size_t size;
5145 #endif
5146  cob_field field;
5147 
5149  cob_set_exception (0);
5150 
5151 #ifdef HAVE_LOCALECONV
5152  p = localeconv ();
5153  size = strlen (p->mon_thousands_sep);
5154  if (size) {
5155  field.size = size;
5156  } else {
5157  field.size = 1;
5158  }
5159  make_field_entry (&field);
5160  if (size) {
5161  memcpy (curr_field->data, p->mon_thousands_sep, size);
5162  } else {
5163  curr_field->size = 0;
5164  curr_field->data[0] = 0;
5165  }
5166 #else
5167  field.size = 1;
5168  make_field_entry (&field);
5169  curr_field->data[0] = COB_MODULE_PTR->decimal_point;
5170 #endif
5171  return curr_field;
5172 }
COB_EXPIMP cob_field* cob_intr_national_of ( const int  ,
const int  ,
const int  ,
  ... 
)
5797 {
5798  COB_UNUSED (offset);
5799  COB_UNUSED (length);
5800  COB_UNUSED (params);
5801 
5802  cob_fatal_error (COB_FERROR_FUNCTION);
5803 }
COB_EXPIMP cob_field* cob_intr_num_decimal_point ( void  )
5106 {
5107 #ifdef HAVE_LOCALECONV
5108  struct lconv *p;
5109  size_t size;
5110 #endif
5111  cob_field field;
5112 
5114  cob_set_exception (0);
5115 
5116 #ifdef HAVE_LOCALECONV
5117  p = localeconv ();
5118  size = strlen (p->decimal_point);
5119  if (size) {
5120  field.size = size;
5121  } else {
5122  field.size = 1;
5123  }
5124  make_field_entry (&field);
5125  if (size) {
5126  memcpy (curr_field->data, p->decimal_point, size);
5127  } else {
5128  curr_field->size = 0;
5129  curr_field->data[0] = 0;
5130  }
5131 #else
5132  field.size = 1;
5133  make_field_entry (&field);
5134  curr_field->data[0] = COB_MODULE_PTR->decimal_point;
5135 #endif
5136  return curr_field;
5137 }
COB_EXPIMP cob_field* cob_intr_num_thousands_sep ( void  )
5176 {
5177 #ifdef HAVE_LOCALECONV
5178  struct lconv *p;
5179  size_t size;
5180 #endif
5181  cob_field field;
5182 
5184  cob_set_exception (0);
5185 
5186 #ifdef HAVE_LOCALECONV
5187  p = localeconv ();
5188  size = strlen (p->thousands_sep);
5189  if (size) {
5190  field.size = size;
5191  } else {
5192  field.size = 1;
5193  }
5194  make_field_entry (&field);
5195  if (size) {
5196  memcpy (curr_field->data, p->thousands_sep, size);
5197  } else {
5198  curr_field->size = 0;
5199  curr_field->data[0] = 0;
5200  }
5201 #else
5202  field.size = 1;
5203  make_field_entry (&field);
5204  curr_field->data[0] = COB_MODULE_PTR->decimal_point;
5205 #endif
5206  return curr_field;
5207 }
COB_EXPIMP cob_field* cob_intr_numval ( cob_field )
3608 {
3609  unsigned char *final_buff;
3610  size_t i;
3611  int final_digits;
3612  int decimal_digits;
3613  int sign;
3614  int decimal_seen;
3615  unsigned char dec_pt;
3616 
3617  /* Validate source field */
3618  if (cob_check_numval (srcfield, NULL, 0, 0)) {
3621  return curr_field;
3622  }
3623 
3624  final_digits = 0;
3625  decimal_digits = 0;
3626  sign = 0;
3627  decimal_seen = 0;
3628  dec_pt = COB_MODULE_PTR->decimal_point;
3629  final_buff = cob_malloc (srcfield->size + 1U);
3630 
3631  for (i = 0; i < srcfield->size; ++i) {
3632  if (i < (srcfield->size - 1)) {
3633  if (memcmp (&srcfield->data[i], "CR", (size_t)2) == 0 ||
3634  memcmp (&srcfield->data[i], "DB", (size_t)2) == 0) {
3635  sign = 1;
3636  break;
3637  }
3638  }
3639  if (srcfield->data[i] == ' ') {
3640  continue;
3641  }
3642  if (srcfield->data[i] == '+') {
3643  continue;
3644  }
3645  if (srcfield->data[i] == '-') {
3646  sign = 1;
3647  continue;
3648  }
3649  if (srcfield->data[i] == dec_pt) {
3650  decimal_seen = 1;
3651  continue;
3652  }
3653  if (srcfield->data[i] >= (unsigned char)'0' &&
3654  srcfield->data[i] <= (unsigned char)'9') {
3655  if (decimal_seen) {
3656  decimal_digits++;
3657  }
3658  final_buff[final_digits++] = srcfield->data[i];
3659  }
3660  if (final_digits > COB_MAX_DIGITS) {
3661  break;
3662  }
3663  }
3664 
3665  if (!final_digits) {
3666  final_buff[0] = '0';
3667  }
3668  mpz_set_str (d1.value, (char *)final_buff, 10);
3669  cob_free (final_buff);
3670  if (sign && mpz_sgn (d1.value)) {
3671  mpz_neg (d1.value, d1.value);
3672  }
3673  d1.scale = decimal_digits;
3674  cob_alloc_field (&d1);
3675  (void)cob_decimal_get_field (&d1, curr_field, 0);
3676 
3677  return curr_field;
3678 }
COB_EXPIMP cob_field* cob_intr_numval_c ( cob_field ,
cob_field  
)
3682 {
3683  unsigned char *final_buff;
3684  unsigned char *currency_data;
3685  size_t i;
3686  int decimal_digits;
3687  int final_digits;
3688  int sign;
3689  int decimal_seen;
3690  unsigned char dec_pt;
3691  unsigned char cur_symb;
3692 
3693  /* Validate source field */
3694  if (cob_check_numval (srcfield, currency, 1, 0)) {
3697  return curr_field;
3698  }
3699 
3700  decimal_digits = 0;
3701  final_digits = 0;
3702  sign = 0;
3703  decimal_seen = 0;
3704  dec_pt = COB_MODULE_PTR->decimal_point;
3705  cur_symb = COB_MODULE_PTR->currency_symbol;
3706  final_buff = cob_malloc (srcfield->size + 1U);
3707 
3708  currency_data = NULL;
3709  if (currency) {
3710  if (currency->size < srcfield->size) {
3711  currency_data = currency->data;
3712  }
3713  }
3714  for (i = 0; i < srcfield->size; ++i) {
3715  if (i < (srcfield->size - 1)) {
3716  if (memcmp (&srcfield->data[i], "CR", (size_t)2) == 0 ||
3717  memcmp (&srcfield->data[i], "DB", (size_t)2) == 0) {
3718  sign = 1;
3719  break;
3720  }
3721  }
3722  if (currency_data) {
3723  if (i < (srcfield->size - currency->size)) {
3724  if (!memcmp (&srcfield->data[i],
3725  currency_data, currency->size)) {
3726  i += (currency->size - 1);
3727  continue;
3728  }
3729  }
3730  } else if (srcfield->data[i] == cur_symb) {
3731  continue;
3732  }
3733  if (srcfield->data[i] == ' ') {
3734  continue;
3735  }
3736  if (srcfield->data[i] == '+') {
3737  continue;
3738  }
3739  if (srcfield->data[i] == '-') {
3740  sign = 1;
3741  continue;
3742  }
3743  if (srcfield->data[i] == dec_pt) {
3744  decimal_seen = 1;
3745  continue;
3746  }
3747  if (srcfield->data[i] >= (unsigned char)'0' &&
3748  srcfield->data[i] <= (unsigned char)'9') {
3749  if (decimal_seen) {
3750  decimal_digits++;
3751  }
3752  final_buff[final_digits++] = srcfield->data[i];
3753  }
3754  if (final_digits > COB_MAX_DIGITS) {
3755  break;
3756  }
3757  }
3758 
3759  if (!final_digits) {
3760  final_buff[0] = '0';
3761  }
3762  mpz_set_str (d1.value, (char *)final_buff, 10);
3763  cob_free (final_buff);
3764  if (sign && mpz_sgn (d1.value)) {
3765  mpz_neg (d1.value, d1.value);
3766  }
3767  d1.scale = decimal_digits;
3768  cob_alloc_field (&d1);
3769  (void)cob_decimal_get_field (&d1, curr_field, 0);
3770 
3771  return curr_field;
3772 }
COB_EXPIMP cob_field* cob_intr_numval_f ( cob_field )
3776 {
3777  unsigned char *final_buff;
3778  unsigned char *p;
3779  size_t plus_minus;
3780  size_t digits;
3781  size_t decimal_digits;
3782  size_t dec_seen;
3783  size_t e_seen;
3784  size_t exponent;
3785  size_t e_plus_minus;
3786  size_t n;
3787  unsigned char dec_pt;
3788 
3789  /* Validate source field */
3790  if (cob_check_numval_f (srcfield)) {
3793  return curr_field;
3794  }
3795 
3796  plus_minus = 0;
3797  digits = 0;
3798  decimal_digits = 0;
3799  dec_seen = 0;
3800  e_seen = 0;
3801  exponent = 0;
3802  e_plus_minus = 0;
3803  dec_pt = COB_MODULE_PTR->decimal_point;
3804 
3805  final_buff = cob_malloc (srcfield->size + 1U);
3806  p = srcfield->data;
3807  for (n = 0; n < srcfield->size; ++n, ++p) {
3808  switch (*p) {
3809  case '0':
3810  case '1':
3811  case '2':
3812  case '3':
3813  case '4':
3814  case '5':
3815  case '6':
3816  case '7':
3817  case '8':
3818  case '9':
3819  if (e_seen) {
3820  exponent *= 10;
3821  exponent += (*p & 0x0F);
3822  } else {
3823  if (dec_seen) {
3824  decimal_digits++;
3825  }
3826  final_buff[digits++] = *p;
3827  }
3828  continue;
3829  case 'E':
3830  e_seen = 1;
3831  continue;
3832  case '-':
3833  if (e_seen) {
3834  e_plus_minus = 1;
3835  } else {
3836  plus_minus = 1;
3837  }
3838  continue;
3839  default:
3840  if (*p == dec_pt) {
3841  dec_seen = 1;
3842  }
3843  continue;
3844  }
3845  }
3846 
3847  if (!digits) {
3848  final_buff[0] = '0';
3849  }
3850 
3851  mpz_set_str (d1.value, (char *)final_buff, 10);
3852  cob_free (final_buff);
3853  if (!mpz_sgn (d1.value)) {
3854  /* Value is zero ; sign and exponent irrelevant */
3855  d1.scale = 0;
3856  cob_alloc_field (&d1);
3857  (void)cob_decimal_get_field (&d1, curr_field, 0);
3858  return curr_field;
3859  }
3860  if (plus_minus) {
3861  mpz_neg (d1.value, d1.value);
3862  }
3863  if (exponent) {
3864  if (e_plus_minus) {
3865  /* Negative exponent */
3866  d1.scale = decimal_digits + exponent;
3867  } else {
3868  /* Positive exponent */
3869  if (decimal_digits >= exponent) {
3870  d1.scale = decimal_digits - exponent;
3871  } else {
3872  exponent -= decimal_digits;
3873  mpz_ui_pow_ui (cob_mexp, 10UL,
3874  (cob_uli_t)exponent);
3875  mpz_mul (d1.value, d1.value, cob_mexp);
3876  d1.scale = 0;
3877  }
3878  }
3879  } else {
3880  /* No exponent */
3881  d1.scale = decimal_digits;
3882  }
3883 
3884  cob_alloc_field (&d1);
3885  (void)cob_decimal_get_field (&d1, curr_field, 0);
3886 
3887  return curr_field;
3888 }
COB_EXPIMP cob_field* cob_intr_ord ( cob_field )
2982 {
2983  cob_alloc_set_field_uint ((cob_u32_t)(*srcfield->data + 1U));
2984  return curr_field;
2985 }
COB_EXPIMP cob_field* cob_intr_ord_max ( const int  ,
  ... 
)
3989 {
3990  cob_field *f;
3991  cob_field *basef;
3992  cob_u32_t ordmax;
3993  int i;
3994  va_list args;
3995 
3996  va_start (args, params);
3997 
3998  ordmax = 1;
3999  basef = va_arg (args, cob_field *);
4000  for (i = 1; i < params; ++i) {
4001  f = va_arg (args, cob_field *);
4002  if (cob_cmp (f, basef) > 0) {
4003  basef = f;
4004  ordmax = i + 1;
4005  }
4006  }
4007  va_end (args);
4008 
4009  cob_alloc_set_field_uint (ordmax);
4010  return curr_field;
4011 }
COB_EXPIMP cob_field* cob_intr_ord_min ( const int  ,
  ... 
)
3963 {
3964  cob_field *f;
3965  cob_field *basef;
3966  int i;
3967  cob_u32_t ordmin;
3968  va_list args;
3969 
3970  va_start (args, params);
3971 
3972  ordmin = 1;
3973  basef = va_arg (args, cob_field *);
3974  for (i = 1; i < params; ++i) {
3975  f = va_arg (args, cob_field *);
3976  if (cob_cmp (f, basef) < 0) {
3977  basef = f;
3978  ordmin = i + 1;
3979  }
3980  }
3981  va_end (args);
3982 
3983  cob_alloc_set_field_uint (ordmin);
3984  return curr_field;
3985 }
COB_EXPIMP cob_field* cob_intr_pi ( void  )
3298 {
3299  mpf_set (cob_mpft, cob_pi);
3301  cob_alloc_field (&d1);
3302  (void)cob_decimal_get_field (&d1, curr_field, 0);
3303 
3304  return curr_field;
3305 }
COB_EXPIMP cob_field* cob_intr_present_value ( const int  ,
  ... 
)
4390 {
4391  cob_field *f;
4392  va_list args;
4393  int i;
4394 
4395  va_start (args, params);
4396 
4397  f = va_arg (args, cob_field *);
4398 
4399  cob_decimal_set_field (&d1, f);
4400  mpz_set_ui (d2.value, 1UL);
4401  d2.scale = 0;
4402  cob_decimal_add (&d1, &d2);
4403 
4404  mpz_set_ui (d4.value, 0UL);
4405  d4.scale = 0;
4406 
4407  for (i = 1; i < params; ++i) {
4408  f = va_arg (args, cob_field *);
4409  cob_decimal_set_field (&d2, f);
4410  mpz_set (d3.value, d1.value);
4411  d3.scale = d1.scale;
4412  if (i > 1) {
4413  mpz_pow_ui (d3.value, d3.value, (cob_uli_t)i);
4414  d3.scale *= i;
4415  }
4416  cob_decimal_div (&d2, &d3);
4417  cob_decimal_add (&d4, &d2);
4418  }
4419  va_end (args);
4420 
4421  cob_alloc_field (&d4);
4422  (void)cob_decimal_get_field (&d4, curr_field, 0);
4423  return curr_field;
4424 }
COB_EXPIMP cob_field* cob_intr_random ( const int  ,
  ... 
)
4227 {
4228  cob_field *f;
4229  va_list args;
4230  double val;
4231  int seed;
4232  int randnum;
4233  cob_field_attr attr;
4234  cob_field field;
4235 
4236  COB_ATTR_INIT (COB_TYPE_NUMERIC_DOUBLE, 20, 9, COB_FLAG_HAVE_SIGN, NULL);
4237  COB_FIELD_INIT (sizeof(double), NULL, &attr);
4238  va_start (args, params);
4239 
4240  if (params) {
4241  f = va_arg (args, cob_field *);
4242  seed = cob_get_int (f);
4243  if (seed < 0) {
4244  seed = 0;
4245  }
4246 #ifdef __CYGWIN__
4247  srandom ((unsigned int)seed);
4248 #else
4249  srand ((unsigned int)seed);
4250 #endif
4251  }
4252  va_end (args);
4253 
4254 #ifdef __CYGWIN__
4255  randnum = (int)random ();
4256 #else
4257  randnum = rand ();
4258 #endif
4259  make_field_entry (&field);
4260  val = (double)randnum / (double)RAND_MAX;
4261  memcpy (curr_field->data, &val, sizeof(val));
4262  return curr_field;
4263 }
COB_EXPIMP cob_field* cob_intr_range ( const int  ,
  ... 
)
4190 {
4191  cob_field *f, *basemin, *basemax;
4192  va_list args;
4193  int i;
4194 
4195  va_start (args, params);
4196 
4197  basemin = va_arg (args, cob_field *);
4198  basemax = basemin;
4199  for (i = 1; i < params; ++i) {
4200  f = va_arg (args, cob_field *);
4201  if (cob_cmp (f, basemin) < 0) {
4202  basemin = f;
4203  }
4204  if (cob_cmp (f, basemax) > 0) {
4205  basemax = f;
4206  }
4207  }
4208  va_end (args);
4209 
4210  cob_decimal_set_field (&d1, basemax);
4211  cob_decimal_set_field (&d2, basemin);
4212  cob_decimal_sub (&d1, &d2);
4213 
4214  cob_alloc_field (&d1);
4215  (void)cob_decimal_get_field (&d1, curr_field, 0);
4216  return curr_field;
4217 }
COB_EXPIMP cob_field* cob_intr_rem ( cob_field ,
cob_field  
)
4221 {
4222  return cob_mod_or_rem (srcfield1, srcfield2, 1);
4223 }
COB_EXPIMP cob_field* cob_intr_reverse ( const int  ,
const int  ,
cob_field  
)
2338 {
2339  size_t i, size;
2340 
2341  make_field_entry (srcfield);
2342 
2343  size = srcfield->size;
2344  for (i = 0; i < size; ++i) {
2345  curr_field->data[i] = srcfield->data[size - i - 1];
2346  }
2347  if (unlikely(offset > 0)) {
2348  calc_ref_mod (curr_field, offset, length);
2349  }
2350  return curr_field;
2351 }
COB_EXPIMP cob_field* cob_intr_seconds_from_formatted_time ( cob_field ,
cob_field  
)
4628 {
4629  unsigned char *p1;
4630  unsigned char *p2;
4631  size_t n;
4632  cob_u32_t seconds = 0;
4633  cob_u32_t minutes = 0;
4634  cob_u32_t hours = 0;
4635  cob_u32_t seconds_seen = 0;
4636  cob_u32_t minutes_seen = 0;
4637  cob_u32_t hours_seen = 0;
4638 
4639  cob_set_exception (0);
4640  if (value->size < format->size) {
4643  return curr_field;
4644  }
4645  p1 = format->data;
4646  p2 = value->data;
4647  for (n = 0; n < format->size - 1; ++n, ++p1, ++p2) {
4648  if (!memcmp (p1, "hh", (size_t)2) && !hours_seen) {
4649  if (*p2 >= (unsigned char)'0' &&
4650  *p2 <= (unsigned char)'9' &&
4651  *(p2 + 1) >= (unsigned char)'0' &&
4652  *(p2 + 1) <= (unsigned char)'9') {
4653  hours = ((*p2 - '0') * 10) + (*(p2 + 1) - '0');
4654  hours_seen = 1;
4655  continue;
4656  }
4657  }
4658  if (!memcmp (p1, "mm", (size_t)2) && !minutes_seen) {
4659  if (*p2 >= (unsigned char)'0' &&
4660  *p2 <= (unsigned char)'9' &&
4661  *(p2 + 1) >= (unsigned char)'0' &&
4662  *(p2 + 1) <= (unsigned char)'9') {
4663  minutes = ((*p2 - '0') * 10) + (*(p2 + 1) - '0');
4664  minutes_seen = 1;
4665  continue;
4666  }
4667  }
4668  if (!memcmp (p1, "ss", (size_t)2) && !seconds_seen) {
4669  if (*p2 >= (unsigned char)'0' &&
4670  *p2 <= (unsigned char)'9' &&
4671  *(p2 + 1) >= (unsigned char)'0' &&
4672  *(p2 + 1) <= (unsigned char)'9') {
4673  seconds = ((*p2 - '0') * 10) + (*(p2 + 1) - '0');
4674  seconds_seen = 1;
4675  continue;
4676  }
4677  }
4678  }
4679  if (hours_seen && minutes_seen && seconds_seen) {
4680  seconds += (hours * 3600) + (minutes * 60);
4681  } else {
4683  seconds = 0;
4684  }
4685  cob_alloc_set_field_uint (seconds);
4686  return curr_field;
4687 }
COB_EXPIMP cob_field* cob_intr_seconds_past_midnight ( void  )
4609 {
4610  struct tm *timeptr;
4611  time_t t;
4612  int seconds;
4613 
4614  t = time (NULL);
4615  timeptr = localtime (&t);
4616  /* Leap seconds ? */
4617  if (timeptr->tm_sec >= 60) {
4618  timeptr->tm_sec = 59;
4619  }
4620  seconds = (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) +
4621  timeptr->tm_sec;
4622  cob_alloc_set_field_int (seconds);
4623  return curr_field;
4624 }
COB_EXPIMP cob_field* cob_intr_sign ( cob_field )
2296 {
2297  cob_decimal_set_field (&d1, srcfield);
2298  cob_alloc_set_field_int (mpz_sgn (d1.value));
2299  return curr_field;
2300 }
COB_EXPIMP cob_field* cob_intr_sin ( cob_field )
3553 {
3554  cob_decimal_set_field (&d1, srcfield);
3555 
3556  cob_set_exception (0);
3557 
3561  cob_alloc_field (&d1);
3562  (void)cob_decimal_get_field (&d1, curr_field, 0);
3563 
3564  return curr_field;
3565 }
COB_EXPIMP cob_field* cob_intr_sqrt ( cob_field )
3585 {
3586  cob_decimal_set_field (&d1, srcfield);
3587 
3588  cob_set_exception (0);
3589  if (mpz_sgn (d1.value) < 0) {
3592  return curr_field;
3593  }
3594 
3595  mpz_set_ui (d2.value, 5UL);
3596  d2.scale = 1;
3597  cob_trim_decimal (&d1);
3598  cob_decimal_pow (&d1, &d2);
3599 
3600  cob_alloc_field (&d1);
3601  (void)cob_decimal_get_field (&d1, curr_field, 0);
3602 
3603  return curr_field;
3604 }
COB_EXPIMP cob_field* cob_intr_standard_compare ( const int  ,
  ... 
)
5807 {
5808  COB_UNUSED (params);
5809 
5810  cob_fatal_error (COB_FERROR_FUNCTION);
5811 }
COB_EXPIMP cob_field* cob_intr_standard_deviation ( const int  ,
  ... 
)
4322 {
4323  cob_field *f;
4324  va_list args;
4325  int i;
4326 
4327  va_start (args, params);
4328 
4329  if (params == 1) {
4330  va_end (args);
4332  return curr_field;
4333  }
4334 
4335  /* MEAN for all params */
4336  mpz_set_ui (d1.value, 0UL);
4337  d1.scale = 0;
4338 
4339  for (i = 0; i < params; ++i) {
4340  f = va_arg (args, cob_field *);
4341  cob_decimal_set_field (&d2, f);
4342  cob_decimal_add (&d1, &d2);
4343  }
4344  va_end (args);
4345 
4346  mpz_set_ui (d2.value, (cob_uli_t)params);
4347  d2.scale = 0;
4348  cob_decimal_div (&d1, &d2);
4349 
4350  /* Got the MEAN in d1, iterate again */
4351 
4352  mpz_set_ui (d4.value, 0UL);
4353  d4.scale = 0;
4354 
4355  va_start (args, params);
4356 
4357  for (i = 0; i < params; ++i) {
4358  f = va_arg (args, cob_field *);
4359  cob_decimal_set_field (&d2, f);
4360  cob_decimal_sub (&d2, &d1);
4361  cob_decimal_mul (&d2, &d2);
4362  cob_decimal_add (&d4, &d2);
4363  }
4364  va_end (args);
4365 
4366  mpz_set_ui (d3.value, (cob_uli_t)params);
4367  d3.scale = 0;
4368  cob_decimal_div (&d4, &d3);
4369 
4370  /* We have the VARIANCE in d4, sqrt = STANDARD-DEVIATION */
4371 
4372  cob_trim_decimal (&d4);
4373 
4374  cob_set_exception (0);
4375 
4376  mpz_set_ui (d3.value, 5UL);
4377  d3.scale = 1;
4378 
4379  cob_trim_decimal (&d4);
4380  cob_decimal_pow (&d4, &d3);
4381 
4382  cob_alloc_field (&d4);
4383  (void)cob_decimal_get_field (&d4, curr_field, 0);
4384 
4385  return curr_field;
4386 }
COB_EXPIMP cob_field* cob_intr_stored_char_length ( cob_field )
2989 {
2990  unsigned char *p;
2991  cob_u32_t count;
2992 
2993  count = srcfield->size;
2994  p = srcfield->data + srcfield->size - 1;
2995  for (; count > 0; count--, p--) {
2996  if (*p != ' ') {
2997  break;
2998  }
2999  }
3000 
3001  cob_alloc_set_field_uint (count);
3002  return curr_field;
3003 }
COB_EXPIMP cob_field* cob_intr_substitute ( const int  ,
const int  ,
const int  ,
  ... 
)
2508 {
2509  cob_field *var;
2510  cob_field **f1;
2511  cob_field **f2;
2512  unsigned char *p1;
2513  unsigned char *p2;
2514  size_t varsize;
2515  size_t calcsize;
2516  size_t n;
2517  size_t found;
2518  int numreps;
2519  int i;
2520  cob_field field;
2521  va_list args;
2522 
2523  numreps = params / 2;
2524  f1 = cob_malloc ((size_t)numreps * sizeof (cob_field *));
2525  f2 = cob_malloc ((size_t)numreps * sizeof (cob_field *));
2526 
2527  va_start (args, params);
2528 
2529  var = va_arg (args, cob_field *);
2530  varsize = var->size;
2531 
2532  /* Extract args */
2533  for (i = 0; i < params - 1; ++i) {
2534  if ((i % 2) == 0) {
2535  f1[i / 2] = va_arg (args, cob_field *);
2536  } else {
2537  f2[i / 2] = va_arg (args, cob_field *);
2538  }
2539  }
2540  va_end (args);
2541 
2542  /* Calculate required size */
2543  calcsize = 0;
2544  found = 0;
2545  p1 = var->data;
2546  for (n = 0; n < varsize; ) {
2547  for (i = 0; i < numreps; ++i) {
2548  if (n + f1[i]->size <= varsize) {
2549  if (!memcmp (p1, f1[i]->data, f1[i]->size)) {
2550  p1 += f1[i]->size;
2551  n += f1[i]->size;
2552  calcsize += f2[i]->size;
2553  found = 1;
2554  break;
2555  }
2556  }
2557  }
2558  if (found) {
2559  found = 0;
2560  continue;
2561  }
2562  ++n;
2563  ++p1;
2564  ++calcsize;
2565  }
2566 
2568  field.size = calcsize;
2569  make_field_entry (&field);
2570 
2571  found = 0;
2572  p1 = var->data;
2573  p2 = curr_field->data;
2574  for (n = 0; n < varsize; ) {
2575  for (i = 0; i < numreps; ++i) {
2576  if (n + f1[i]->size <= varsize) {
2577  if (!memcmp (p1, f1[i]->data, f1[i]->size)) {
2578  memcpy (p2, f2[i]->data, f2[i]->size);
2579  p1 += f1[i]->size;
2580  p2 += f2[i]->size;
2581  n += f1[i]->size;
2582  found = 1;
2583  break;
2584  }
2585  }
2586  }
2587  if (found) {
2588  found = 0;
2589  continue;
2590  }
2591  ++n;
2592  *p2++ = *p1++;
2593  }
2594  if (unlikely(offset > 0)) {
2595  calc_ref_mod (curr_field, offset, length);
2596  }
2597  cob_free (f1);
2598  cob_free (f2);
2599  return curr_field;
2600 }
COB_EXPIMP cob_field* cob_intr_substitute_case ( const int  ,
const int  ,
const int  ,
  ... 
)
2605 {
2606  cob_field *var;
2607  cob_field **f1;
2608  cob_field **f2;
2609  unsigned char *p1;
2610  unsigned char *p2;
2611  size_t varsize;
2612  size_t calcsize;
2613  size_t n;
2614  size_t found;
2615  int numreps;
2616  int i;
2617  cob_field field;
2618  va_list args;
2619 
2620  numreps = params / 2;
2621  f1 = cob_malloc ((size_t)numreps * sizeof (cob_field *));
2622  f2 = cob_malloc ((size_t)numreps * sizeof (cob_field *));
2623 
2624  va_start (args, params);
2625 
2626  var = va_arg (args, cob_field *);
2627  varsize = var->size;
2628 
2629  /* Extract args */
2630  for (i = 0; i < params - 1; ++i) {
2631  if ((i % 2) == 0) {
2632  f1[i / 2] = va_arg (args, cob_field *);
2633  } else {
2634  f2[i / 2] = va_arg (args, cob_field *);
2635  }
2636  }
2637  va_end (args);
2638 
2639  /* Calculate required size */
2640  calcsize = 0;
2641  found = 0;
2642  p1 = var->data;
2643  for (n = 0; n < varsize; ) {
2644  for (i = 0; i < numreps; ++i) {
2645  if (n + f1[i]->size <= varsize) {
2646  if (!strncasecmp ((const char *)p1,
2647  (const char *)(f1[i]->data),
2648  f1[i]->size)) {
2649  p1 += f1[i]->size;
2650  n += f1[i]->size;
2651  calcsize += f2[i]->size;
2652  found = 1;
2653  break;
2654  }
2655  }
2656  }
2657  if (found) {
2658  found = 0;
2659  continue;
2660  }
2661  ++n;
2662  ++p1;
2663  ++calcsize;
2664  }
2665 
2667  field.size = calcsize;
2668  make_field_entry (&field);
2669 
2670  found = 0;
2671  p1 = var->data;
2672  p2 = curr_field->data;
2673  for (n = 0; n < varsize; ) {
2674  for (i = 0; i < numreps; ++i) {
2675  if (n + f1[i]->size <= varsize) {
2676  if (!strncasecmp ((const char *)p1,
2677  (const char *)(f1[i]->data),
2678  f1[i]->size)) {
2679  memcpy (p2, f2[i]->data, f2[i]->size);
2680  p1 += f1[i]->size;
2681  p2 += f2[i]->size;
2682  n += f1[i]->size;
2683  found = 1;
2684  break;
2685  }
2686  }
2687  }
2688  if (found) {
2689  found = 0;
2690  continue;
2691  }
2692  ++n;
2693  *p2++ = *p1++;
2694  }
2695  if (unlikely(offset > 0)) {
2696  calc_ref_mod (curr_field, offset, length);
2697  }
2698  cob_free (f1);
2699  cob_free (f2);
2700  return curr_field;
2701 }
COB_EXPIMP cob_field* cob_intr_sum ( const int  ,
  ... 
)
3939 {
3940  cob_field *f;
3941  va_list args;
3942  int i;
3943 
3944  mpz_set_ui (d1.value, 0UL);
3945  d1.scale = 0;
3946 
3947  va_start (args, params);
3948 
3949  for (i = 0; i < params; ++i) {
3950  f = va_arg (args, cob_field *);
3951  cob_decimal_set_field (&d2, f);
3952  cob_decimal_add (&d1, &d2);
3953  }
3954  va_end (args);
3955 
3956  cob_alloc_field (&d1);
3957  (void)cob_decimal_get_field (&d1, curr_field, 0);
3958  return curr_field;
3959 }
COB_EXPIMP cob_field* cob_intr_tan ( cob_field )
3569 {
3570  cob_decimal_set_field (&d1, srcfield);
3571 
3572  cob_set_exception (0);
3573 
3577  cob_alloc_field (&d1);
3578  (void)cob_decimal_get_field (&d1, curr_field, 0);
3579 
3580  return curr_field;
3581 }
COB_EXPIMP cob_field* cob_intr_test_date_yyyymmdd ( cob_field )
3201 {
3202  int indate;
3203  int days;
3204  int month;
3205  int year;
3206 
3207  /* Base 1601-01-01 */
3208  indate = cob_get_int (srcfield);
3209  year = indate / 10000;
3210  if (!valid_year (year)) {
3212  return curr_field;
3213  }
3214  indate %= 10000;
3215  month = indate / 100;
3216  if (month < 1 || month > 12) {
3218  return curr_field;
3219  }
3220  days = indate % 100;
3221  if (days < 1 || days > 31) {
3223  return curr_field;
3224  }
3225  if (leap_year (year)) {
3226  if (days > leap_month_days[month]) {
3228  return curr_field;
3229  }
3230  } else {
3231  if (days > normal_month_days[month]) {
3233  return curr_field;
3234  }
3235  }
3237  return curr_field;
3238 }
COB_EXPIMP cob_field* cob_intr_test_day_yyyyddd ( cob_field )
3242 {
3243  int indate;
3244  int days;
3245  int year;
3246 
3247  /* Base 1601-01-01 */
3248  indate = cob_get_int (srcfield);
3249  year = indate / 1000;
3250  if (!valid_year (year)) {
3252  return curr_field;
3253  }
3254  days = indate % 1000;
3255  if (days < 1 || days > 365 + leap_year (year)) {
3257  return curr_field;
3258  }
3260  return curr_field;
3261 }
COB_EXPIMP cob_field* cob_intr_test_formatted_datetime ( cob_field ,
cob_field  
)
5815 {
5816  COB_UNUSED (f1);
5817  COB_UNUSED (f2);
5818 
5819  cob_fatal_error (COB_FERROR_FUNCTION);
5820 }
COB_EXPIMP cob_field* cob_intr_test_numval ( cob_field )
5246 {
5247  cob_alloc_set_field_int (cob_check_numval (srcfield, NULL, 0, 0));
5248  return curr_field;
5249 }
COB_EXPIMP cob_field* cob_intr_test_numval_c ( cob_field ,
cob_field  
)
5253 {
5254  cob_alloc_set_field_int (cob_check_numval (srcfield, currency, 1, 0));
5255  return curr_field;
5256 }
COB_EXPIMP cob_field* cob_intr_test_numval_f ( cob_field )
5260 {
5262  return curr_field;
5263 }
COB_EXPIMP cob_field* cob_intr_trim ( const int  ,
const int  ,
cob_field ,
const int   
)
2706 {
2707  unsigned char *begin;
2708  unsigned char *end;
2709  size_t i;
2710  size_t size;
2711 
2712  make_field_entry (srcfield);
2713 
2714  for (i = 0; i < srcfield->size; ++i) {
2715  if (srcfield->data[i] != ' ') {
2716  break;
2717  }
2718  }
2719  if (i == srcfield->size) {
2720  curr_field->size = 0;
2721  curr_field->data[0] = ' ';
2722  return curr_field;
2723  }
2724 
2725  begin = srcfield->data;
2726  if (direction != 2) {
2727  for (; *begin == ' '; ++begin) ;
2728  }
2729  end = srcfield->data + srcfield->size - 1;
2730  if (direction != 1) {
2731  for (; *end == ' '; end--) ;
2732  }
2733 
2734  size = 0;
2735  for (i = 0; begin <= end; ++begin, ++i) {
2736  curr_field->data[i] = *begin;
2737  ++size;
2738  }
2739  curr_field->size = size;
2740  if (unlikely(offset > 0)) {
2741  calc_ref_mod (curr_field, offset, length);
2742  }
2743  return curr_field;
2744 }
COB_EXPIMP cob_field* cob_intr_upper_case ( const int  ,
const int  ,
cob_field  
)
2304 {
2305  size_t i, size;
2306 
2307  make_field_entry (srcfield);
2308 
2309  size = srcfield->size;
2310  for (i = 0; i < size; ++i) {
2311  curr_field->data[i] = (cob_u8_t)toupper (srcfield->data[i]);
2312  }
2313  if (unlikely(offset > 0)) {
2314  calc_ref_mod (curr_field, offset, length);
2315  }
2316  return curr_field;
2317 }
COB_EXPIMP cob_field* cob_intr_variance ( const int  ,
  ... 
)
4267 {
4268  cob_field *f;
4269  va_list args;
4270  int i;
4271 
4272  va_start (args, params);
4273 
4274  if (params == 1) {
4275  va_end (args);
4277  return curr_field;
4278  }
4279 
4280  /* MEAN for all params */
4281  mpz_set_ui (d1.value, 0UL);
4282  d1.scale = 0;
4283 
4284  for (i = 0; i < params; ++i) {
4285  f = va_arg (args, cob_field *);
4286  cob_decimal_set_field (&d2, f);
4287  cob_decimal_add (&d1, &d2);
4288  }
4289  va_end (args);
4290 
4291  mpz_set_ui (d2.value, (cob_uli_t)params);
4292  d2.scale = 0;
4293  cob_decimal_div (&d1, &d2);
4294 
4295  /* Got the MEAN in d1, iterate again */
4296 
4297  mpz_set_ui (d4.value, 0UL);
4298  d4.scale = 0;
4299 
4300  va_start (args, params);
4301 
4302  for (i = 0; i < params; ++i) {
4303  f = va_arg (args, cob_field *);
4304  cob_decimal_set_field (&d2, f);
4305  cob_decimal_sub (&d2, &d1);
4306  cob_decimal_mul (&d2, &d2);
4307  cob_decimal_add (&d4, &d2);
4308  }
4309  va_end (args);
4310 
4311  mpz_set_ui (d3.value, (cob_uli_t)params);
4312  d3.scale = 0;
4313  cob_decimal_div (&d4, &d3);
4314 
4315  cob_alloc_field (&d4);
4316  (void)cob_decimal_get_field (&d4, curr_field, 0);
4317  return curr_field;
4318 }
COB_EXPIMP cob_field* cob_intr_when_compiled ( const int  ,
const int  ,
cob_field  
)
2857 {
2858  make_field_entry (f);
2859 
2860  memcpy (curr_field->data, f->data, f->size);
2861  if (unlikely(offset > 0)) {
2862  calc_ref_mod (curr_field, offset, length);
2863  }
2864  return curr_field;
2865 }
COB_EXPIMP cob_field* cob_intr_year_to_yyyy ( const int  ,
  ... 
)
4428 {
4429  cob_field *f;
4430  struct tm *timeptr;
4431  va_list args;
4432  time_t t;
4433  int year;
4434  int interval;
4435  int xqtyear;
4436  int maxyear;
4437 
4438  cob_set_exception (0);
4439  va_start (args, params);
4440  f = va_arg (args, cob_field *);
4441  year = cob_get_int (f);
4442  if (params > 1) {
4443  f = va_arg (args, cob_field *);
4444  interval = cob_get_int (f);
4445  } else {
4446  interval = 50;
4447  }
4448  if (params > 2) {
4449  f = va_arg (args, cob_field *);
4450  xqtyear = cob_get_int (f);
4451  } else {
4452  t = time (NULL);
4453  timeptr = localtime (&t);
4454  xqtyear = 1900 + timeptr->tm_year;
4455  }
4456  va_end (args);
4457 
4458  if (year < 0 || year > 99) {
4461  return curr_field;
4462  }
4463  if (!valid_year (xqtyear)) {
4466  return curr_field;
4467  }
4468  maxyear = xqtyear + interval;
4469  if (maxyear < 1700 || maxyear > 9999) {
4472  return curr_field;
4473  }
4474  if (maxyear % 100 >= year) {
4475  year += 100 * (maxyear / 100);
4476  } else {
4477  year += 100 * ((maxyear / 100) - 1);
4478  }
4479  cob_alloc_set_field_int (year);
4480  return curr_field;
4481 }
COB_EXPIMP int cob_is_alpha ( const cob_field )
2234 {
2235  size_t i;
2236 
2237  for (i = 0; i < f->size; ++i) {
2238  if (!isalpha (f->data[i]) && f->data[i] != (unsigned char)' ') {
2239  return 0;
2240  }
2241  }
2242  return 1;
2243 }
COB_EXPIMP int cob_is_lower ( const cob_field )
2260 {
2261  size_t i;
2262 
2263  for (i = 0; i < f->size; ++i) {
2264  if (!islower (f->data[i]) && f->data[i] != (unsigned char)' ') {
2265  return 0;
2266  }
2267  }
2268  return 1;
2269 }
COB_EXPIMP int cob_is_numeric ( const cob_field )
2156 {
2157  size_t i;
2158  union {
2159  float fpf;
2160  double fpd;
2161  } fval;
2162  int sign;
2163 
2164  switch (COB_FIELD_TYPE (f)) {
2166  return 1;
2168  memcpy (&fval.fpf, f->data, sizeof(float));
2169  return !finite ((double)fval.fpf);
2171  memcpy (&fval.fpd, f->data, sizeof(double));
2172  return !finite (fval.fpd);
2174  /* Check digits */
2175  for (i = 0; i < f->size - 1; ++i) {
2176  if ((f->data[i] & 0xF0) > 0x90 ||
2177  (f->data[i] & 0x0F) > 0x09) {
2178  return 0;
2179  }
2180  }
2181  /* Check high nibble of last byte */
2182  if ((f->data[i] & 0xF0) > 0x90) {
2183  return 0;
2184  }
2185 
2186  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
2187  /* COMP-6 - Check last nibble */
2188  if ((f->data[i] & 0x0F) > 0x09) {
2189  return 0;
2190  }
2191  return 1;
2192  }
2193 
2194  /* Check sign */
2195  sign = f->data[i] & 0x0F;
2196  if (COB_FIELD_HAVE_SIGN (f)) {
2197  if (sign == 0x0C || sign == 0x0D) {
2198  return 1;
2199  }
2200  if (COB_MODULE_PTR->flag_host_sign &&
2201  sign == 0x0F) {
2202  return 1;
2203  }
2204  } else if (sign == 0x0F) {
2205  return 1;
2206  }
2207  return 0;
2209  return cob_check_numdisp (f);
2211 #ifdef WORDS_BIGENDIAN
2212  return (f->data[0] & 0x78U) != 0x78U;
2213 #else
2214  return (f->data[7] & 0x78U) != 0x78U;
2215 #endif
2217 #ifdef WORDS_BIGENDIAN
2218  return (f->data[0] & 0x78U) != 0x78U;
2219 #else
2220  return (f->data[15] & 0x78U) != 0x78U;
2221 #endif
2222  default:
2223  for (i = 0; i < f->size; ++i) {
2224  if (!isdigit (f->data[i])) {
2225  return 0;
2226  }
2227  }
2228  return 1;
2229  }
2230 }
COB_EXPIMP int cob_is_omitted ( const cob_field )
2150 {
2151  return f->data == NULL;
2152 }
COB_EXPIMP int cob_is_upper ( const cob_field )
2247 {
2248  size_t i;
2249 
2250  for (i = 0; i < f->size; ++i) {
2251  if (!isupper (f->data[i]) && f->data[i] != (unsigned char)' ') {
2252  return 0;
2253  }
2254  }
2255  return 1;
2256 }
COB_EXPIMP void cob_longjmp ( struct cobjmp_buf )
1168 {
1169  if (unlikely(!cobglobptr)) {
1170  cob_fatal_error (COB_FERROR_INITIALIZED);
1171  }
1172  if (unlikely(!jbuf)) {
1173  cob_runtime_error (_("NULL parameter passed to 'cob_longjmp'"));
1174  cob_stop_run (1);
1175  }
1176  if (!cob_jmp_primed) {
1177  cob_runtime_error (_("Call to 'cob_longjmp' with no prior 'cob_setjmp'"));
1178  cob_stop_run (1);
1179  }
1180  cob_jmp_primed = 0;
1181  longjmp (jbuf->cbj_jmp_buf, 1);
1182 }
COB_EXPIMP void* cob_malloc ( const size_t  )
1123 {
1124  void *mptr;
1125 
1126  mptr = calloc ((size_t)1, size);
1127  if (unlikely(!mptr)) {
1128  cob_fatal_error (COB_FERROR_MEMORY);
1129  }
1130  return mptr;
1131 }
COB_EXPIMP void cob_module_enter ( cob_module **  ,
cob_global **  ,
const int   
)
1578 {
1579  /* Check initialized */
1580  if (unlikely(!cob_initialized)) {
1581  if (auto_init) {
1582  cob_init (0, NULL);
1583  } else {
1584  cob_fatal_error (COB_FERROR_INITIALIZED);
1585  }
1586  }
1587 
1588  /* Set global pointer */
1589  *mglobal = cobglobptr;
1590 
1591  /* Check module pointer */
1592  if (!*module) {
1593  *module = cob_cache_malloc (sizeof(cob_module));
1594  }
1595 
1596 #if 0 /* RXWRXW - Params */
1597  /* Save parameter count */
1598  (*module)->module_num_params = cobglobptr->cob_call_params;
1599 #endif
1600 
1601  /* Push module pointer */
1602  (*module)->next = COB_MODULE_PTR;
1603  COB_MODULE_PTR = *module;
1604 }
COB_EXPIMP void cob_module_leave ( cob_module )
1608 {
1609  COB_UNUSED (module);
1610  /* Pop module pointer */
1612 }
COB_EXPIMP void cob_move ( cob_field ,
cob_field  
)
1170 {
1171  int opt;
1172  cob_field temp;
1173  unsigned char data[4];
1174 
1175  if (src == dst) {
1176  return;
1177  }
1178  if (dst->size == 0) {
1179  return;
1180  }
1181  if (unlikely(src->size == 0)) {
1182  temp.size = 1;
1183  temp.data = data;
1184  temp.attr = &const_alpha_attr;
1185  data[0] = ' ';
1186  data[1] = 0;
1187  src = &temp;
1188  }
1189  if (COB_FIELD_TYPE (src) == COB_TYPE_ALPHANUMERIC_ALL) {
1190  cob_move_all (src, dst);
1191  return;
1192  }
1193 
1194  /* Non-elementary move */
1195  if (COB_FIELD_TYPE (src) == COB_TYPE_GROUP ||
1196  COB_FIELD_TYPE (dst) == COB_TYPE_GROUP) {
1197  cob_move_alphanum_to_alphanum (src, dst);
1198  return;
1199  }
1200 
1201  opt = 0;
1202  if (COB_FIELD_TYPE (dst) == COB_TYPE_NUMERIC_BINARY) {
1203  if (COB_FIELD_BINARY_TRUNC (dst) &&
1204  !COB_FIELD_REAL_BINARY(dst)) {
1206  }
1207  }
1208 
1209  /* Elementary move */
1210  switch (COB_FIELD_TYPE (src)) {
1212  switch (COB_FIELD_TYPE (dst)) {
1221  cob_decimal_setget_fld (src, dst, 0);
1222  return;
1224  cob_move_display_to_display (src, dst);
1225  return;
1227  cob_move_display_to_packed (src, dst);
1228  return;
1230  cob_move_display_to_binary (src, dst);
1231  return;
1233  cob_move_display_to_edited (src, dst);
1234  return;
1236  if (COB_FIELD_SCALE(src) < 0 ||
1237  COB_FIELD_SCALE(src) > COB_FIELD_DIGITS(src)) {
1238  /* Expand P's */
1240  (size_t)cob_max_int ((int)COB_FIELD_DIGITS(src), (int)COB_FIELD_SCALE(src)),
1241  cob_max_int (0, (int)COB_FIELD_SCALE(src)));
1242  return;
1243  } else {
1244  cob_move_alphanum_to_edited (src, dst);
1245  return;
1246  }
1247  default:
1248  cob_move_display_to_alphanum (src, dst);
1249  return;
1250  }
1251 
1253  switch (COB_FIELD_TYPE (dst)) {
1255  cob_move_packed_to_display (src, dst);
1256  return;
1258  cob_decimal_setget_fld (src, dst, opt);
1259  return;
1269  cob_decimal_setget_fld (src, dst, 0);
1270  return;
1271  default:
1273  (size_t)(COB_FIELD_DIGITS(src)),
1274  COB_FIELD_SCALE(src));
1275  return;
1276  }
1277 
1279  switch (COB_FIELD_TYPE (dst)) {
1281  if (COB_FIELD_SCALE(src) == COB_FIELD_SCALE(dst)) {
1282  cob_move_binary_to_binary (src, dst);
1283  return;
1284  }
1285  cob_decimal_setget_fld (src, dst, opt);
1286  return;
1288  cob_move_binary_to_display (src, dst);
1289  return;
1299  cob_decimal_setget_fld (src, dst, 0);
1300  return;
1303  (size_t)COB_MAX_DIGITS,
1304  COB_FIELD_SCALE(src));
1305  return;
1306  default:
1308  (size_t)(COB_FIELD_DIGITS(src)),
1309  COB_FIELD_SCALE(src));
1310  return;
1311  }
1312 
1314  switch (COB_FIELD_TYPE (dst)) {
1316  cob_move_edited_to_display (src, dst);
1317  return;
1330  (size_t)(2 * COB_MAX_DIGITS),
1331  COB_MAX_DIGITS);
1332  return;
1334  cob_move_alphanum_to_edited (src, dst);
1335  return;
1336  default:
1337  cob_move_alphanum_to_alphanum (src, dst);
1338  return;
1339  }
1340 
1342  switch (COB_FIELD_TYPE (dst)) {
1344  memmove (dst->data, src->data, sizeof(double));
1345  return;
1347  cob_move_fp_to_fp (src, dst);
1348  return;
1350  cob_decimal_setget_fld (src, dst, opt);
1351  return;
1360  cob_decimal_setget_fld (src, dst, 0);
1361  return;
1362  default:
1363  cob_decimal_move_temp (src, dst);
1364  return;
1365  }
1366 
1368  switch (COB_FIELD_TYPE (dst)) {
1370  memmove (dst->data, src->data, sizeof(float));
1371  return;
1373  cob_move_fp_to_fp (src, dst);
1374  return;
1376  cob_decimal_setget_fld (src, dst, opt);
1377  return;
1386  cob_decimal_setget_fld (src, dst, 0);
1387  return;
1388  default:
1389  cob_decimal_move_temp (src, dst);
1390  return;
1391  }
1392 
1394  switch (COB_FIELD_TYPE (dst)) {
1396  cob_decimal_setget_fld (src, dst, opt);
1397  return;
1399  memmove (dst->data, src->data, (size_t)8);
1400  return;
1409  cob_decimal_setget_fld (src, dst, 0);
1410  return;
1411  default:
1412  cob_decimal_move_temp (src, dst);
1413  return;
1414  }
1416  switch (COB_FIELD_TYPE (dst)) {
1418  cob_decimal_setget_fld (src, dst, opt);
1419  return;
1421  memmove (dst->data, src->data, (size_t)16);
1422  return;
1432  cob_decimal_setget_fld (src, dst, 0);
1433  return;
1434  default:
1435  cob_decimal_move_temp (src, dst);
1436  return;
1437  }
1438  default:
1439  switch (COB_FIELD_TYPE (dst)) {
1441  cob_move_alphanum_to_display (src, dst);
1442  return;
1455  (size_t)(2* COB_MAX_DIGITS),
1456  COB_MAX_DIGITS);
1457  return;
1459  cob_move_alphanum_to_edited (src, dst);
1460  return;
1461  default:
1462  cob_move_alphanum_to_alphanum (src, dst);
1463  return;
1464  }
1465  }
1466 }
COB_EXPIMP void cob_mul ( cob_field ,
cob_field ,
const int   
)
1950 {
1954  (void)cob_decimal_get_field (&cob_d1, f1, opt);
1955 }
COB_EXPIMP int cob_numeric_cmp ( cob_field ,
cob_field  
)
2345 {
2346  if(COB_FIELD_TYPE (f1) == COB_TYPE_NUMERIC_FLOAT
2347  || COB_FIELD_TYPE (f1) == COB_TYPE_NUMERIC_DOUBLE
2348  || COB_FIELD_TYPE (f2) == COB_TYPE_NUMERIC_FLOAT
2349  || COB_FIELD_TYPE (f2) == COB_TYPE_NUMERIC_DOUBLE) {
2350  return cob_cmp_float(f1,f2);
2351  }
2354  return cob_decimal_cmp (&cob_d1, &cob_d2);
2355 }
COB_EXPIMP void cob_open ( cob_file ,
const int  ,
const int  ,
cob_field  
)
4458 {
4459  f->flag_read_done = 0;
4460 
4461  /* File was previously closed with lock */
4462  if (f->open_mode == COB_OPEN_LOCKED) {
4464  return;
4465  }
4466 
4467  /* File is already open */
4468  if (f->open_mode != COB_OPEN_CLOSED) {
4469  save_status (f, fnstatus, COB_STATUS_41_ALREADY_OPEN);
4470  return;
4471  }
4472 
4473  f->last_open_mode = mode;
4474  f->flag_nonexistent = 0;
4475  f->flag_end_of_file = 0;
4476  f->flag_begin_of_file = 0;
4477  f->flag_first_read = 2;
4478  f->flag_operation = 0;
4479  f->lock_mode &= ~COB_LOCK_OPEN_EXCLUSIVE;
4480  f->lock_mode |= sharing;
4481 
4482  if (unlikely(COB_FILE_STDIN (f))) {
4483  if (mode != COB_OPEN_INPUT) {
4485  return;
4486  }
4487  f->file = stdin;
4488  f->fd = fileno (stdin);
4489  f->open_mode = mode;
4490  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
4491  return;
4492  }
4493  if (unlikely(COB_FILE_STDOUT (f))) {
4494  if (mode != COB_OPEN_OUTPUT) {
4496  return;
4497  }
4498  f->file = stdout;
4499  f->fd = fileno (stdout);
4500  f->open_mode = mode;
4501  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
4502  return;
4503  }
4504 
4505  /* Obtain the file name */
4506  cob_field_to_string (f->assign, file_open_name, (size_t)COB_FILE_MAX);
4507 
4508  cob_cache_file (f);
4509 
4510  /* Open the file */
4511  save_status (f, fnstatus,
4512  fileio_funcs[(int)f->organization]->open (f, file_open_name,
4513  mode, sharing));
4514 }
COB_EXPIMP void cob_put_indirect_field ( cob_field )
2060 {
2061  make_field_entry (f);
2062  memcpy (curr_field->data, f->data, f->size);
2064 }
COB_EXPIMP int cob_putenv ( char *  )
2855 {
2856  int ret;
2857 
2858  if (name && strchr (name, '=')) {
2859  ret = putenv (cob_strdup(name));
2860  if (!ret) {
2862  }
2863  return ret;
2864  }
2865  return -1;
2866 }
COB_EXPIMP void cob_read ( cob_file ,
cob_field ,
cob_field ,
const int   
)
4653 {
4654  int ret;
4655 
4656  f->flag_read_done = 0;
4657 
4658  if (unlikely(f->open_mode != COB_OPEN_INPUT &&
4659  f->open_mode != COB_OPEN_I_O)) {
4660  save_status (f, fnstatus, COB_STATUS_47_INPUT_DENIED);
4661  return;
4662  }
4663 
4664  if (unlikely(f->flag_nonexistent)) {
4665  if (f->flag_first_read == 0) {
4667  return;
4668  }
4669  f->flag_first_read = 0;
4670  save_status (f, fnstatus, COB_STATUS_10_END_OF_FILE);
4671  return;
4672  }
4673 
4674  /* Sequential read at the end of file is an error */
4675  if (key == NULL) {
4676  if (unlikely(f->flag_end_of_file &&
4677  !(read_opts & COB_READ_PREVIOUS))) {
4678  save_status (f, fnstatus, COB_STATUS_46_READ_ERROR);
4679  return;
4680  }
4681  if (unlikely(f->flag_begin_of_file &&
4682  (read_opts & COB_READ_PREVIOUS))) {
4683  save_status (f, fnstatus, COB_STATUS_46_READ_ERROR);
4684  return;
4685  }
4686  ret = fileio_funcs[(int)f->organization]->read_next (f, read_opts);
4687  } else {
4688  ret = fileio_funcs[(int)f->organization]->read (f, key, read_opts);
4689  }
4690 
4691  switch (ret) {
4692  case COB_STATUS_00_SUCCESS:
4694  f->flag_first_read = 0;
4695  f->flag_read_done = 1;
4696  f->flag_end_of_file = 0;
4697  f->flag_begin_of_file = 0;
4698  if (f->variable_record) {
4699  cob_set_int (f->variable_record, (int) f->record->size);
4700  }
4701  break;
4703  if (read_opts & COB_READ_PREVIOUS) {
4704  f->flag_begin_of_file = 1;
4705  } else {
4706  f->flag_end_of_file = 1;
4707  }
4708  break;
4709  }
4710 
4711  save_status (f, fnstatus, ret);
4712 }
COB_EXPIMP void cob_read_next ( cob_file ,
cob_field ,
const int   
)
4716 {
4717  int ret;
4718 
4719  f->flag_read_done = 0;
4720 
4721  if (unlikely(f->open_mode != COB_OPEN_INPUT &&
4722  f->open_mode != COB_OPEN_I_O)) {
4723  save_status (f, fnstatus, COB_STATUS_47_INPUT_DENIED);
4724  return;
4725  }
4726 
4727  if (unlikely(f->flag_nonexistent)) {
4728  if (f->flag_first_read == 0) {
4730  return;
4731  }
4732  f->flag_first_read = 0;
4733  save_status (f, fnstatus, COB_STATUS_10_END_OF_FILE);
4734  return;
4735  }
4736 
4737  /* Sequential read at the end of file is an error */
4738  if (unlikely(f->flag_end_of_file && !(read_opts & COB_READ_PREVIOUS))) {
4739  save_status (f, fnstatus, COB_STATUS_46_READ_ERROR);
4740  return;
4741  }
4742  if (unlikely(f->flag_begin_of_file && (read_opts & COB_READ_PREVIOUS))) {
4743  save_status (f, fnstatus, COB_STATUS_46_READ_ERROR);
4744  return;
4745  }
4746 
4747  ret = fileio_funcs[(int)f->organization]->read_next (f, read_opts);
4748 
4749  switch (ret) {
4750  case COB_STATUS_00_SUCCESS:
4752  f->flag_first_read = 0;
4753  f->flag_read_done = 1;
4754  f->flag_end_of_file = 0;
4755  f->flag_begin_of_file = 0;
4756  if (f->variable_record) {
4757  cob_set_int (f->variable_record, (int) f->record->size);
4758  }
4759  break;
4761  if (read_opts & COB_READ_PREVIOUS) {
4762  f->flag_begin_of_file = 1;
4763  } else {
4764  f->flag_end_of_file = 1;
4765  }
4766  break;
4767  }
4768 
4769  save_status (f, fnstatus, ret);
4770 }
COB_EXPIMP void cob_ready_trace ( void  )
1305 {
1306  cob_line_trace = 1;
1307 }
COB_EXPIMP void cob_reg_sighnd ( void(*)(int)  sighnd)
2069 {
2070  cob_ext_sighdl = sighnd;
2071 }
COB_EXPIMP void cob_reset_trace ( void  )
1311 {
1312  cob_line_trace = 0;
1313 }
COB_EXPIMP void* cob_resolve ( const char *  )
916 {
917  void *p;
918  char *entry;
919  char *dirent;
920 
921  entry = cob_chk_call_path (name, &dirent);
922  p = cob_resolve_internal (entry, dirent, 0);
923  if (dirent) {
924  cob_free (dirent);
925  }
926  return p;
927 }
COB_EXPIMP void* cob_resolve_cobol ( const char *  ,
const int  ,
const int   
)
931 {
932  void *p;
933  char *entry;
934  char *dirent;
935 
936  entry = cob_chk_call_path (name, &dirent);
937  p = cob_resolve_internal (entry, dirent, fold_case);
938  if (dirent) {
939  cob_free (dirent);
940  }
941  if (unlikely(!p)) {
942  if (errind) {
943  cob_call_error ();
944  }
945  cob_set_exception (COB_EC_PROGRAM_NOT_FOUND);
946  }
947  return p;
948 }
COB_EXPIMP const char* cob_resolve_error ( void  )
872 {
873  const char *p;
874 
875  if (!resolve_error) {
876  p = _("Indeterminable error");
877  } else {
878  p = resolve_error;
880  }
881  return p;
882 }
COB_EXPIMP void* cob_resolve_func ( const char *  )
952 {
953  void *p;
954 
955  p = cob_resolve_internal (name, NULL, 0);
956  if (unlikely(!p)) {
957  cob_runtime_error (_("User function '%s' not found"), name);
958  cob_stop_run (1);
959  }
960  return p;
961 }
COB_EXPIMP void cob_restore_func ( struct cob_func_loc )
1660 {
1661  /* Restore calling environment */
1662  cobglobptr->cob_call_params = fl->save_call_params;
1663 #if 0 /* RXWRXW - MODNEXT */
1664  COB_MODULE_PTR->next = fl->save_module;
1665 #endif
1666  COB_MODULE_PTR->cob_procedure_params = fl->save_proc_parms;
1667  COB_MODULE_PTR->module_num_params = fl->save_num_params;
1668  cob_free (fl->data);
1669  cob_free (fl->func_params);
1670  cob_free (fl);
1671 }
COB_EXPIMP void cob_rewrite ( cob_file ,
cob_field ,
const int  ,
cob_field  
)
4813 {
4814  int read_done;
4815 
4816  read_done = f->flag_read_done;
4817  f->flag_read_done = 0;
4818 
4819  if (unlikely(f->open_mode != COB_OPEN_I_O)) {
4820  save_status (f, fnstatus, COB_STATUS_49_I_O_DENIED);
4821  return;
4822  }
4823 
4824  if (f->access_mode == COB_ACCESS_SEQUENTIAL && !read_done) {
4826  return;
4827  }
4828 
4829  if (unlikely(f->organization == COB_ORG_SEQUENTIAL)) {
4830  if (f->record->size != rec->size) {
4832  return;
4833  }
4834 
4835  if (f->variable_record) {
4836  if (f->record->size != (size_t)cob_get_int (f->variable_record)) {
4838  return;
4839  }
4840  }
4841  }
4842 
4843  save_status (f, fnstatus,
4844  fileio_funcs[(int)f->organization]->rewrite (f, opt));
4845 }
COB_EXPIMP void cob_rollback ( void  )
4883 {
4884  struct file_list *l;
4885 
4886  for (l = file_cache; l; l = l->next) {
4887  if (l->file) {
4888  cob_file_unlock (l->file);
4889  }
4890  }
4891 }
COB_EXPIMP void* cob_save_func ( cob_field **  ,
const int  ,
const int  ,
  ... 
)
1617 {
1618  struct cob_func_loc *fl;
1619  va_list args;
1620  int numparams;
1621  int n;
1622 
1623  if (unlikely(params > eparams)) {
1624  numparams = eparams;
1625  } else {
1626  numparams = params;
1627  }
1628 
1629  /* Allocate return field */
1630  *savefld = cob_malloc (sizeof (cob_field));
1631  /* Allocate save area */
1632  fl = cob_malloc (sizeof(struct cob_func_loc));
1633  fl->func_params = cob_malloc (sizeof(void *) * ((size_t)numparams + 1U));
1634  fl->data = cob_malloc (sizeof(void *) * ((size_t)numparams + 1U));
1635 
1636  /* Save values */
1637  fl->save_module = COB_MODULE_PTR->next;
1639  fl->save_proc_parms = COB_MODULE_PTR->cob_procedure_params;
1640  fl->save_num_params = COB_MODULE_PTR->module_num_params;
1641 
1642  /* Set current values */
1643  COB_MODULE_PTR->cob_procedure_params = fl->func_params;
1644  cobglobptr->cob_call_params = numparams;
1645  if (numparams) {
1646  va_start (args, eparams);
1647  for (n = 0; n < numparams; ++n) {
1648  fl->func_params[n] = va_arg (args, cob_field *);
1649  if (fl->func_params[n]) {
1650  fl->data[n] = fl->func_params[n]->data;
1651  }
1652  }
1653  va_end (args);
1654  }
1655  return fl;
1656 }
COB_EXPIMP void* cob_savenv ( struct cobjmp_buf )
1142 {
1143  if (unlikely(!cobglobptr)) {
1144  cob_fatal_error (COB_FERROR_INITIALIZED);
1145  }
1146  if (unlikely(!jbuf)) {
1147  cob_runtime_error (_("NULL parameter passed to 'cob_savenv'"));
1148  cob_stop_run (1);
1149  }
1150  if (cob_jmp_primed) {
1151  cob_runtime_error (_("Multiple call to 'cob_setjmp'"));
1152  cob_stop_run (1);
1153  }
1154  cob_jmp_primed = 1;
1155  return jbuf->cbj_jmp_buf;
1156 }
COB_EXPIMP void* cob_savenv2 ( struct cobjmp_buf ,
const int   
)
1160 {
1161  COB_UNUSED (jsize);
1162 
1163  return cob_savenv (jbuf);
1164 }
COB_EXPIMP void cob_screen_accept ( cob_screen ,
cob_field ,
cob_field ,
cob_field  
)
1726 {
1727  COB_UNUSED (s);
1728  COB_UNUSED (line);
1729  COB_UNUSED (column);
1730  COB_UNUSED (ftimeout);
1731 }
COB_EXPIMP void cob_screen_display ( cob_screen ,
cob_field ,
cob_field  
)
1717 {
1718  COB_UNUSED (s);
1719  COB_UNUSED (line);
1720  COB_UNUSED (column);
1721 }
COB_EXPIMP void cob_screen_line_col ( cob_field ,
const int   
)
1735 {
1736  if (!l_or_c) {
1737  cob_set_int (f, 24);
1738  } else {
1739  cob_set_int (f, 80);
1740  }
1741 }
COB_EXPIMP void cob_set_cancel ( cob_module )
893 {
894  struct call_hash *p;
895 
896 #ifdef COB_ALT_HASH
897  p = call_table;
898 #else
899  p = call_table[hash ((const unsigned char *)(m->module_name))];
900 #endif
901  for (; p; p = p->next) {
902  if (strcmp (m->module_name, p->name) == 0) {
903  p->module = m;
904  /* Set path in program module structure */
905  if (p->path && m->module_path && !*(m->module_path)) {
906  *(m->module_path) = p->path;
907  }
908  return;
909  }
910  }
911  insert (m->module_name, m->module_entry.funcvoid, NULL, m, NULL, 1);
912 }
COB_EXPIMP void cob_set_environment ( const cob_field ,
const cob_field  
)
2678 {
2680  cob_display_env_value (f2);
2681 }
COB_EXPIMP void cob_set_int ( cob_field ,
const int   
)
1612 {
1613  cob_field temp;
1614  cob_field_attr attr;
1615 
1616  COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0,
1617  COB_FLAG_HAVE_SIGN | COB_FLAG_REAL_BINARY, NULL);
1618  temp.size = 4;
1619  temp.data = (unsigned char *)&n;
1620  temp.attr = &attr;
1621  cob_move (&temp, f);
1622 }
COB_EXPIMP void cob_set_locale ( cob_field ,
const int   
)
3766 {
3767 #ifdef HAVE_SETLOCALE
3768  char *p;
3769  char *buff;
3770 
3771  p = NULL;
3772  if (locale) {
3773  if (locale->size == 0) {
3774  return;
3775  }
3776  buff = cob_malloc (locale->size + 1U);
3777  cob_field_to_string (locale, buff, locale->size);
3778  } else {
3779  buff = NULL;
3780  }
3781 
3782  switch (category) {
3783  case COB_LC_COLLATE:
3784  p = setlocale (LC_COLLATE, buff);
3785  break;
3786  case COB_LC_CTYPE:
3787  p = setlocale (LC_CTYPE, buff);
3788  break;
3789 #ifdef LC_MESSAGES
3790  case COB_LC_MESSAGES:
3791  p = setlocale (LC_MESSAGES, buff);
3792  break;
3793 #endif
3794  case COB_LC_MONETARY:
3795  p = setlocale (LC_MONETARY, buff);
3796  break;
3797  case COB_LC_NUMERIC:
3798  p = setlocale (LC_NUMERIC, buff);
3799  break;
3800  case COB_LC_TIME:
3801  p = setlocale (LC_TIME, buff);
3802  break;
3803  case COB_LC_ALL:
3804  p = setlocale (LC_ALL, buff);
3805  break;
3806  case COB_LC_USER:
3807  if (cobglobptr->cob_locale_orig) {
3808  p = setlocale (LC_ALL, cobglobptr->cob_locale_orig);
3809  (void)setlocale (LC_NUMERIC, "C");
3810  }
3811  break;
3812  case COB_LC_CLASS:
3814  p = setlocale (LC_CTYPE, cobglobptr->cob_locale_ctype);
3815  }
3816  break;
3817  }
3818  if (buff) {
3819  cob_free (buff);
3820  }
3821  if (!p) {
3822  cob_set_exception (COB_EC_LOCALE_MISSING);
3823  return;
3824  }
3825  p = setlocale (LC_ALL, NULL);
3826  if (p) {
3827  if (cobglobptr->cob_locale) {
3829  }
3831  }
3832 #else
3833  cob_set_exception (COB_EC_LOCALE_MISSING);
3834 #endif
3835 }
COB_EXPIMP void cob_set_location ( const char *  ,
const unsigned  int,
const char *  ,
const char *  ,
const char *   
)
1241 {
1242  const char *s;
1243 
1244  cob_current_program_id = COB_MODULE_PTR->module_name;
1245  cob_source_file = sfile;
1246  cob_source_line = sline;
1247  cob_current_section = csect;
1248  cob_current_paragraph = cpara;
1249  if (cstatement) {
1250  cob_source_statement = cstatement;
1251  }
1252  if (cob_line_trace) {
1253  if (!cob_trace_file) {
1255  }
1256  if (!cob_last_sfile || strcmp (cob_last_sfile, sfile)) {
1257  cob_last_sfile = sfile;
1258  fprintf (cob_trace_file, "Source : '%s'\n", sfile);
1259  }
1260  if (COB_MODULE_PTR->module_name) {
1261  s = COB_MODULE_PTR->module_name;
1262  } else {
1263  s = "Unknown";
1264  }
1265  fprintf (cob_trace_file,
1266  "Program-Id: %-16s Statement: %-21.21s Line: %u\n",
1267  s, cstatement ? (char *)cstatement : "Unknown",
1268  sline);
1269  fflush (cob_trace_file);
1270  }
1271 }
COB_EXPIMP void cob_set_packed_int ( cob_field ,
const int   
)
1262 {
1263  unsigned char *p;
1264  size_t sign = 0;
1265  cob_u32_t n;
1266 
1267  if (!val) {
1268  cob_set_packed_zero (f);
1269  return;
1270  }
1271  if (val < 0) {
1272  n = (cob_u32_t)-val;
1273  sign = 1;
1274  } else {
1275  n = (cob_u32_t)val;
1276  }
1277  memset (f->data, 0, f->size);
1278  p = f->data + f->size - 1;
1279  if (!COB_FIELD_NO_SIGN_NIBBLE (f)) {
1280  *p = (n % 10) << 4;
1281  if (!COB_FIELD_HAVE_SIGN (f)) {
1282  *p |= 0x0FU;
1283  } else if (sign) {
1284  *p |= 0x0DU;
1285  } else {
1286  *p |= 0x0CU;
1287  }
1288  n /= 10;
1289  p--;
1290  }
1291  for (; n && p >= f->data; n /= 100, p--) {
1292  *p = packed_bytes[n % 100];
1293  }
1294  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
1295  if ((COB_FIELD_DIGITS(f) % 2) == 1) {
1296  *(f->data) &= 0x0FU;
1297  }
1298  return;
1299  }
1300  if ((COB_FIELD_DIGITS(f) % 2) == 0) {
1301  *(f->data) &= 0x0FU;
1302  }
1303 }
COB_EXPIMP void cob_set_packed_zero ( cob_field )
1074 {
1075  memset (f->data, 0, f->size);
1076  if (COB_FIELD_NO_SIGN_NIBBLE (f)) {
1077  return;
1078  }
1079  if (!COB_FIELD_HAVE_SIGN (f)) {
1080  *(f->data + f->size - 1) = 0x0F;
1081  } else {
1082  *(f->data + f->size - 1) = 0x0C;
1083  }
1084 }
COB_EXPIMP void cob_set_switch ( const int  ,
const int   
)
2086 {
2087  if (n < 0 || n > (COB_SWITCH_MAX - 1)) {
2088  return;
2089  }
2090  if (flag == 0) {
2091  cob_switch[n] = 0;
2092  } else if (flag == 1) {
2093  cob_switch[n] = 1;
2094  }
2095 }
COB_EXPIMP void cob_start ( cob_file ,
const int  ,
cob_field ,
cob_field ,
cob_field  
)
4605 {
4606  int ret;
4607  int size;
4608  cob_field tempkey;
4609 
4610  f->flag_read_done = 0;
4611  f->flag_first_read = 0;
4612 
4613  if (unlikely(f->open_mode != COB_OPEN_I_O &&
4614  f->open_mode != COB_OPEN_INPUT)) {
4615  save_status (f, fnstatus, COB_STATUS_47_INPUT_DENIED);
4616  return;
4617  }
4618 
4619  if (unlikely(f->access_mode == COB_ACCESS_RANDOM)) {
4620  save_status (f, fnstatus, COB_STATUS_47_INPUT_DENIED);
4621  return;
4622  }
4623 
4624  if (f->flag_nonexistent) {
4626  return;
4627  }
4628 
4629  size = 0;
4630  if (unlikely(keysize)) {
4631  size = cob_get_int (keysize);
4632  if (size < 1 || size > (int)key->size) {
4634  return;
4635  }
4636  tempkey = *key;
4637  tempkey.size = (size_t)size;
4638  ret = fileio_funcs[(int)f->organization]->start (f, cond, &tempkey);
4639  } else {
4640  ret = fileio_funcs[(int)f->organization]->start (f, cond, key);
4641  }
4642  if (ret == COB_STATUS_00_SUCCESS) {
4643  f->flag_end_of_file = 0;
4644  f->flag_begin_of_file = 0;
4645  f->flag_first_read = 1;
4646  }
4647 
4648  save_status (f, fnstatus, ret);
4649 }
DECLNORET COB_EXPIMP void cob_stop_run ( const int  )
1367 {
1368  struct exit_handlerlist *h;
1369 
1370  if (!cob_initialized) {
1371  exit (1);
1372  }
1373  if (exit_hdlrs != NULL) {
1374  h = exit_hdlrs;
1375  while (h != NULL) {
1376  h->proc ();
1377  h = h->next;
1378  }
1379  }
1381  exit (status);
1382 }
char* cob_strcat ( char *  ,
char *   
)
3869  {
3870  size_t l;
3871  char *temp1, *temp2;
3872 
3873  l = strlen(str1) + strlen(str2) + 1;
3874 
3875  /*
3876  * If one of the parameter is the buffer itself,
3877  * we copy the buffer before continuing.
3878  */
3879  if (str1 == strbuff) {
3880  temp1 = cob_strdup(str1);
3881  } else {
3882  temp1 = str1;
3883  }
3884  if (str2 == strbuff) {
3885  temp2 = cob_strdup(str2);
3886  } else {
3887  temp2 = str2;
3888  }
3889 
3890  cob_free(strbuff);
3891  strbuff = (char*) cob_fast_malloc(l);
3892 
3893  sprintf(strbuff, "%s%s", temp1, temp2);
3894  return strbuff;
3895 }
COB_EXPIMP void cob_string_append ( cob_field )
441 {
442  size_t src_size;
443  int i;
444  int size;
445 
446  if (cob_get_exception_code ()) {
447  return;
448  }
449 
450  src_size = src->size;
451  if (!src_size) {
452  return;
453  }
454  if (string_dlm) {
455  size = (int)(src_size - string_dlm->size + 1);
456  for (i = 0; i < size; ++i) {
457  if (memcmp (src->data + i, string_dlm->data,
458  string_dlm->size) == 0) {
459  src_size = i;
460  break;
461  }
462  }
463  }
464 
465  if (src_size <= string_dst->size - string_offset) {
466  memcpy (string_dst->data + string_offset, src->data, src_size);
467  string_offset += (int) src_size;
468  } else {
469  size = (int)(string_dst->size - string_offset);
470  memcpy (string_dst->data + string_offset, src->data, (size_t)size);
471  string_offset += size;
473  }
474 }
COB_EXPIMP void cob_string_delimited ( cob_field )
431 {
432  string_dlm = NULL;
433  if (dlm) {
434  string_dlm_copy = *dlm;
436  }
437 }
COB_EXPIMP void cob_string_finish ( void  )
478 {
479  if (string_ptr) {
481  }
482 }
COB_EXPIMP void cob_string_init ( cob_field ,
cob_field  
)
409 {
410  string_dst_copy = *dst;
412  string_ptr = NULL;
413  if (ptr) {
414  string_ptr_copy = *ptr;
416  }
417  string_offset = 0;
418  cob_set_exception (0);
419 
420  if (string_ptr) {
422  if (string_offset < 0 ||
423  string_offset >= (int)string_dst->size) {
425  }
426  }
427 }
char* cob_strjoin ( char **  ,
int  ,
char *   
)
3898  {
3899 
3900  char* result;
3901  int i;
3902 
3903  if(!strarray || size <= 0 || !separator) return NULL;
3904 
3905  result = strarray[0];
3906  for (i = 1; i < size; i++) {
3907  result = cob_strcat(result, separator);
3908  result = cob_strcat(result, strarray[i]);
3909  }
3910 
3911  return result;
3912 }
COB_EXPIMP void cob_sub ( cob_field ,
cob_field ,
const int   
)
1941 {
1945  (void)cob_decimal_get_field (&cob_d1, f1, opt);
1946 }
COB_EXPIMP int cob_sub_int ( cob_field ,
const int  ,
const int   
)
2252 {
2253  return cob_add_int (f, -n, opt);
2254 }
COB_EXPIMP cob_field* cob_switch_value ( const int  )
1952 {
1954  return curr_field;
1955 }
COB_EXPIMP int cob_sys_and ( const void *  ,
void *  ,
const int   
)
3125 {
3126  const cob_u8_ptr data_1 = p1;
3127  cob_u8_ptr data_2 = p2;
3128  size_t n;
3129 
3130  COB_CHK_PARMS (CBL_AND, 3);
3131 
3132  if (length <= 0) {
3133  return 0;
3134  }
3135  for (n = 0; n < (size_t)length; ++n) {
3136  data_2[n] &= data_1[n];
3137  }
3138  return 0;
3139 }
COB_EXPIMP int cob_sys_calledby ( void *  )
3444 {
3445  size_t size;
3446  size_t msize;
3447 
3448  COB_CHK_PARMS (C$CALLEDBY, 1);
3449 
3450  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
3451  return -1;
3452  }
3453  size = COB_MODULE_PTR->cob_procedure_params[0]->size;
3454  memset (data, ' ', size);
3455  if (!COB_MODULE_PTR->next) {
3456  return 0;
3457  }
3458  msize = strlen (COB_MODULE_PTR->next->module_name);
3459  if (msize > size) {
3460  msize = size;
3461  }
3462  memcpy (data, COB_MODULE_PTR->next->module_name, msize);
3463  return 1;
3464 }
COB_EXPIMP int cob_sys_change_dir ( unsigned char *  )
5415 {
5416  char *fn;
5417  int ret;
5418 
5419  COB_UNUSED (dir);
5420 
5421  COB_CHK_PARMS (CBL_CHANGE_DIR, 1);
5422 
5423  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5424  return -1;
5425  }
5426  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5427  ret = chdir (fn);
5428  cob_free (fn);
5429  if (ret) {
5430  return 128;
5431  }
5432  return 0;
5433 }
COB_EXPIMP int cob_sys_chdir ( unsigned char *  ,
unsigned char *   
)
5473 {
5474  int ret;
5475 
5476  COB_UNUSED (status);
5477 
5478  COB_CHK_PARMS (C$CHDIR, 2);
5479 
5480  ret = cob_sys_change_dir (dir);
5481  if (ret < 0) {
5482  ret = 128;
5483  }
5484  cob_set_int (COB_MODULE_PTR->cob_procedure_params[1], ret);
5485  return ret;
5486 }
COB_EXPIMP int cob_sys_check_file_exist ( unsigned char *  ,
unsigned char *   
)
5259 {
5260  char *fn;
5261  struct tm *tm;
5262  cob_s64_t sz;
5263  struct stat st;
5264  short y;
5265  short d, m, hh, mm, ss;
5266 
5267  COB_UNUSED (file_name);
5268 
5269  COB_CHK_PARMS (CBL_CHECK_FILE_EXIST, 2);
5270 
5271  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5272  return -1;
5273  }
5274  if (!COB_MODULE_PTR->cob_procedure_params[1]) {
5275  return -1;
5276  }
5277  if (COB_MODULE_PTR->cob_procedure_params[1]->size < 16U) {
5278  cob_runtime_error (_("'CBL_CHECK_FILE_EXIST' - File detail area is too short"));
5279  cob_stop_run (1);
5280  }
5281 
5282  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5283  if (stat (fn, &st) < 0) {
5284  cob_free (fn);
5285  return 35;
5286  }
5287  cob_free (fn);
5288  sz = (cob_s64_t)st.st_size;
5289  tm = localtime (&st.st_mtime);
5290  d = (short)tm->tm_mday;
5291  m = (short)(tm->tm_mon + 1);
5292  y = (short)(tm->tm_year + 1900);
5293  hh = (short)tm->tm_hour;
5294  mm = (short)tm->tm_min;
5295  /* Leap seconds ? */
5296  if (tm->tm_sec >= 60) {
5297  ss = 59;
5298  } else {
5299  ss = (short)tm->tm_sec;
5300  }
5301 
5302 #ifndef WORDS_BIGENDIAN
5303  sz = COB_BSWAP_64 (sz);
5304  y = COB_BSWAP_16 (y);
5305 #endif
5306  memcpy (file_info, &sz, (size_t)8);
5307  file_info[8] = (unsigned char)d;
5308  file_info[9] = (unsigned char)m;
5309  memcpy (file_info+10, &y, (size_t)2);
5310  file_info[12] = (unsigned char)hh;
5311  file_info[13] = (unsigned char)mm;
5312  file_info[14] = (unsigned char)ss;
5313  file_info[15] = 0;
5314  return 0;
5315 }
COB_EXPIMP int cob_sys_clear_screen ( void  )
1751 {
1752  return 0;
1753 }
COB_EXPIMP int cob_sys_close_file ( unsigned char *  )
5164 {
5165  int fd;
5166 
5167  COB_CHK_PARMS (CBL_CLOSE_FILE, 1);
5168 
5169  memcpy (&fd, file_handle, (size_t)4);
5170  return close (fd);
5171 }
COB_EXPIMP int cob_sys_copy_file ( unsigned char *  ,
unsigned char *   
)
5207 {
5208  char *fn1;
5209  char *fn2;
5210  int flag = O_BINARY;
5211  int ret;
5212  int i;
5213  int fd1, fd2;
5214 
5215  COB_UNUSED (fname1);
5216  COB_UNUSED (fname2);
5217 
5218  COB_CHK_PARMS (CBL_COPY_FILE, 2);
5219 
5220  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5221  return -1;
5222  }
5223  if (!COB_MODULE_PTR->cob_procedure_params[1]) {
5224  return -1;
5225  }
5226  fn1 = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5227  flag |= O_RDONLY;
5228  fd1 = open (fn1, flag, 0);
5229  if (fd1 < 0) {
5230  cob_free (fn1);
5231  return -1;
5232  }
5233  cob_free (fn1);
5234  fn2 = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[1]);
5235  flag &= ~O_RDONLY;
5236  flag |= O_CREAT | O_TRUNC | O_WRONLY;
5237  fd2 = open (fn2, flag, 0660);
5238  if (fd2 < 0) {
5239  close (fd1);
5240  cob_free (fn2);
5241  return -1;
5242  }
5243  cob_free (fn2);
5244 
5245  ret = 0;
5246  while ((i = read (fd1, file_open_buff, COB_FILE_BUFF)) > 0) {
5247  if (write (fd2, file_open_buff, (size_t)i) < 0) {
5248  ret = -1;
5249  break;
5250  }
5251  }
5252  close (fd1);
5253  close (fd2);
5254  return ret;
5255 }
COB_EXPIMP int cob_sys_copyfile ( unsigned char *  ,
unsigned char *  ,
unsigned char *   
)
5491 {
5492  int ret;
5493 
5494  /* RXW - Type is not yet evaluated */
5495  COB_UNUSED (file_type);
5496 
5497  COB_CHK_PARMS (C$COPY, 3);
5498 
5499  if (cobglobptr->cob_call_params < 3) {
5500  return 128;
5501  }
5502  ret = cob_sys_copy_file (fname1, fname2);
5503  if (ret < 0) {
5504  ret = 128;
5505  }
5506  return ret;
5507 }
COB_EXPIMP int cob_sys_create_dir ( unsigned char *  )
5389 {
5390  char *fn;
5391  int ret;
5392 
5393  COB_UNUSED (dir);
5394 
5395  COB_CHK_PARMS (CBL_CREATE_DIR, 1);
5396 
5397  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5398  return -1;
5399  }
5400  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5401 #ifdef _WIN32
5402  ret = mkdir (fn);
5403 #else
5404  ret = mkdir (fn, 0770);
5405 #endif
5406  cob_free (fn);
5407  if (ret) {
5408  return 128;
5409  }
5410  return 0;
5411 }
COB_EXPIMP int cob_sys_create_file ( unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *   
)
5061 {
5062  /*
5063  * @param: file_access : 1 (read-only), 2 (write-only), 3 (both)
5064  * @param: file_lock : not implemented, set 0
5065  * @param: file_dev : not implemented, set 0
5066  */
5067 
5068  if (*file_lock != 0 && cobglobptr->cob_display_warn) {
5069  fprintf (stderr, _("WARNING - Call to CBL_CREATE_FILE with wrong file_lock: %d"), *file_lock);
5070  putc ('\n', stderr);
5071  fflush (stderr);
5072  }
5073  if (*file_dev != 0 && cobglobptr->cob_display_warn) {
5074  fprintf (stderr, _("WARNING - Call to CBL_CREATE_FILE with wrong file_dev: %d"), *file_dev);
5075  putc ('\n', stderr);
5076  fflush (stderr);
5077  }
5078 
5079  COB_CHK_PARMS (CBL_CREATE_FILE, 5);
5080 
5081  return open_cbl_file (file_name, file_access, file_handle, O_CREAT | O_TRUNC);
5082 }
COB_EXPIMP int cob_sys_delete_dir ( unsigned char *  )
5437 {
5438  char *fn;
5439  int ret;
5440 
5441  COB_UNUSED (dir);
5442 
5443  COB_CHK_PARMS (CBL_DELETE_DIR, 1);
5444 
5445  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5446  return -1;
5447  }
5448  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5449  ret = rmdir (fn);
5450  cob_free (fn);
5451  if (ret) {
5452  return 128;
5453  }
5454  return 0;
5455 }
COB_EXPIMP int cob_sys_delete_file ( unsigned char *  )
5185 {
5186  char *fn;
5187  int ret;
5188 
5189  COB_UNUSED (file_name);
5190 
5191  COB_CHK_PARMS (CBL_DELETE_FILE, 1);
5192 
5193  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5194  return -1;
5195  }
5196  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5197  ret = unlink (fn);
5198  cob_free (fn);
5199  if (ret) {
5200  return 128;
5201  }
5202  return 0;
5203 }
COB_EXPIMP int cob_sys_eq ( const void *  ,
void *  ,
const int   
)
3233 {
3234  const cob_u8_ptr data_1 = p1;
3235  cob_u8_ptr data_2 = p2;
3236  size_t n;
3237 
3238  COB_CHK_PARMS (CBL_EQ, 3);
3239 
3240  if (length <= 0) {
3241  return 0;
3242  }
3243  for (n = 0; n < (size_t)length; ++n) {
3244  data_2[n] = ~(data_1[n] ^ data_2[n]);
3245  }
3246  return 0;
3247 }
COB_EXPIMP int cob_sys_error_proc ( const void *  ,
const void *   
)
3041 {
3042  struct handlerlist *hp = NULL;
3043  struct handlerlist *h = hdlrs;
3044  const unsigned char *x;
3045  int (**p)(char *s);
3046 
3047  COB_CHK_PARMS (CBL_ERROR_PROC, 2);
3048 
3049  memcpy (&p, &pptr, sizeof (void *));
3050  if (!p || !*p) {
3051  return -1;
3052  }
3053 
3054  hp = NULL;
3055  h = hdlrs;
3056  /* Remove handler anyway */
3057  while (h != NULL) {
3058  if (h->proc == *p) {
3059  if (hp != NULL) {
3060  hp->next = h->next;
3061  } else {
3062  hdlrs = h->next;
3063  }
3064  if (hp) {
3065  cob_free (hp);
3066  }
3067  break;
3068  }
3069  hp = h;
3070  h = h->next;
3071  }
3072  x = dispo;
3073  if (*x != 0) {
3074  /* Remove handler */
3075  return 0;
3076  }
3077  h = cob_malloc (sizeof(struct handlerlist));
3078  h->next = hdlrs;
3079  h->proc = *p;
3080  hdlrs = h;
3081  return 0;
3082 }
COB_EXPIMP int cob_sys_exit_proc ( const void *  ,
const void *   
)
2996 {
2997  struct exit_handlerlist *hp;
2998  struct exit_handlerlist *h;
2999  const unsigned char *x;
3000  int (**p)(void);
3001 
3002  COB_CHK_PARMS (CBL_EXIT_PROC, 2);
3003 
3004  memcpy (&p, &pptr, sizeof (void *));
3005  if (!p || !*p) {
3006  return -1;
3007  }
3008 
3009  hp = NULL;
3010  h = exit_hdlrs;
3011  /* Remove handler anyway */
3012  while (h != NULL) {
3013  if (h->proc == *p) {
3014  if (hp != NULL) {
3015  hp->next = h->next;
3016  } else {
3017  exit_hdlrs = h->next;
3018  }
3019  if (hp) {
3020  cob_free (hp);
3021  }
3022  break;
3023  }
3024  hp = h;
3025  h = h->next;
3026  }
3027  x = dispo;
3028  if (*x != 0 && *x != 2 && *x != 3) {
3029  /* Remove handler */
3030  return 0;
3031  }
3032  h = cob_malloc (sizeof(struct exit_handlerlist));
3033  h->next = exit_hdlrs;
3034  h->proc = *p;
3035  exit_hdlrs = h;
3036  return 0;
3037 }
COB_EXPIMP int cob_sys_file_delete ( unsigned char *  ,
unsigned char *   
)
5575 {
5576  int ret;
5577 
5578  /* RXW - Type is not yet evaluated */
5579  COB_UNUSED (file_type);
5580 
5581  COB_CHK_PARMS (C$DELETE, 2);
5582 
5583  if (cobglobptr->cob_call_params < 2 ||
5584  !COB_MODULE_PTR->cob_procedure_params[0]) {
5585  return 128;
5586  }
5587  ret = cob_sys_delete_file (file_name);
5588  if (ret < 0) {
5589  ret = 128;
5590  }
5591  return ret;
5592 }
COB_EXPIMP int cob_sys_file_info ( unsigned char *  ,
unsigned char *   
)
5511 {
5512  char *fn;
5513  struct tm *tm;
5514  cob_u64_t sz;
5515  unsigned int dt;
5516  short y;
5517  short d, m, hh, mm, ss;
5518  struct stat st;
5519 
5520  COB_UNUSED (file_name);
5521 
5522  COB_CHK_PARMS (C$FILEINFO, 2);
5523 
5524  if (cobglobptr->cob_call_params < 2 ||
5525  !COB_MODULE_PTR->cob_procedure_params[0]) {
5526  return 128;
5527  }
5528  if (!COB_MODULE_PTR->cob_procedure_params[1]) {
5529  return 128;
5530  }
5531  if (COB_MODULE_PTR->cob_procedure_params[1]->size < 16U) {
5532  cob_runtime_error (_("'C$FILEINFO' - File detail area is too short"));
5533  cob_stop_run (1);
5534  }
5535 
5536  fn = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5537  if (stat (fn, &st) < 0) {
5538  cob_free (fn);
5539  return 35;
5540  }
5541  cob_free (fn);
5542  sz = (cob_u64_t)st.st_size;
5543  tm = localtime (&st.st_mtime);
5544  d = (short)tm->tm_mday;
5545  m = (short)(tm->tm_mon + 1);
5546  y = (short)(tm->tm_year + 1900);
5547  hh = (short)tm->tm_hour;
5548  mm = (short)tm->tm_min;
5549  /* Leap seconds ? */
5550  if (tm->tm_sec >= 60) {
5551  ss = 59;
5552  } else {
5553  ss = (short)tm->tm_sec;
5554  }
5555 
5556 #ifndef WORDS_BIGENDIAN
5557  sz = COB_BSWAP_64 (sz);
5558 #endif
5559  memcpy (file_info, &sz, (size_t)8);
5560  dt = (y * 10000) + (m * 100) + d;
5561 #ifndef WORDS_BIGENDIAN
5562  dt = COB_BSWAP_32 (dt);
5563 #endif
5564  memcpy (file_info + 8, &dt, (size_t)4);
5565  dt = (hh * 1000000) + (mm * 10000) + (ss * 100);
5566 #ifndef WORDS_BIGENDIAN
5567  dt = COB_BSWAP_32 (dt);
5568 #endif
5569  memcpy (file_info + 12, &dt, (size_t)4);
5570  return 0;
5571 }
COB_EXPIMP int cob_sys_flush_file ( unsigned char *  )
5175 {
5176  COB_UNUSED (file_handle);
5177 
5178  COB_CHK_PARMS (CBL_FLUSH_FILE, 1);
5179 
5180  return 0;
5181 }
COB_EXPIMP int cob_sys_get_csr_pos ( unsigned char *  )
1783 {
1784 #ifdef COB_GEN_SCREENIO
1785  int cline;
1786  int ccol;
1787 #endif
1788 
1789  COB_CHK_PARMS (CBL_GET_CSR_POS, 1);
1790 
1791 #ifdef COB_GEN_SCREENIO
1792  getyx (stdscr, cline, ccol);
1793  fld[0] = (unsigned char)cline;
1794  fld[1] = (unsigned char)ccol;
1795 
1796 #else
1797  fld[0] = 1U;
1798  fld[1] = 1U;
1799 #endif
1800  return 0;
1801 }
COB_EXPIMP int cob_sys_get_current_dir ( const int  ,
const int  ,
unsigned char *   
)
5349 {
5350  char *dirname;
5351  int dir_size;
5352  int has_space;
5353 
5354  COB_CHK_PARMS (CBL_GET_CURRENT_DIR, 3);
5355 
5356  if (dir_length < 1) {
5357  return 128;
5358  }
5359  if (flags) {
5360  return 129;
5361  }
5362  memset (dir, ' ', (size_t)dir_length);
5363  dirname = getcwd (NULL, (size_t)0);
5364  if (dirname == NULL) {
5365  return 128;
5366  }
5367  dir_size = (int) strlen (dirname);
5368  has_space = 0;
5369  if (strchr (dirname, ' ')) {
5370  has_space = 2;
5371  }
5372  if (dir_size + has_space > dir_length) {
5373  cob_free (dirname);
5374  return 128;
5375  }
5376  if (has_space) {
5377  *dir = '"';
5378  memcpy (&dir[1], dirname, (size_t)dir_size);
5379  dir[dir_size + 1] = '"';
5380  } else {
5381  memcpy (dir, dirname, (size_t)dir_size);
5382  }
5383  cob_free (dirname);
5384  return 0;
5385 }
COB_EXPIMP int cob_sys_get_scr_size ( unsigned char *  ,
unsigned char *   
)
1805 {
1806  COB_CHK_PARMS (CBL_GET_SCR_SIZE, 2);
1807 
1808 #ifdef COB_GEN_SCREENIO
1809  *line = (unsigned char)LINES;
1810  *col = (unsigned char)COLS;
1811 #else
1812  *line = 24U;
1813  *col = 80U;
1814 #endif
1815  return 0;
1816 }
COB_EXPIMP int cob_sys_getopt_long_long ( void *  ,
void *  ,
void *  ,
const int  ,
void *  ,
void *   
)
3489  {
3490  /*
3491  * cob_argc is a static int containing argc from runtime
3492  * cob_argv is a static char** containing argv from runtime
3493  */
3494 
3495  size_t opt_val_size = 0;
3496  size_t so_size = 0;
3497  size_t lo_size = 0;
3498 
3499  unsigned int lo_amount;
3500 
3501  int exit_status;
3502 
3503  char* shortoptions;
3504  char* temp;
3505 
3506  struct option* longoptions;
3507  longoption_def* l = NULL;
3508 
3509  int longind = 0;
3510  unsigned int i;
3511  int j;
3512 
3513  unsigned int optlen;
3514  int return_value;
3515 
3516  COB_UNUSED (idx);
3517  COB_UNUSED (lo);
3518  COB_UNUSED (so);
3519 
3520  COB_CHK_PARMS (CBL_OC_GETOPT, 6);
3521 
3522  /*
3523  * Read in sizes of some parameters
3524  */
3525  if (COB_MODULE_PTR->cob_procedure_params[1]) {
3526  lo_size = COB_MODULE_PTR->cob_procedure_params[1]->size;
3527  }
3528  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3529  so_size = COB_MODULE_PTR->cob_procedure_params[0]->size;
3530  }
3531  if (COB_MODULE_PTR->cob_procedure_params[5]) {
3532  opt_val_size = COB_MODULE_PTR->cob_procedure_params[5]->size;
3533  }
3534 
3535  /*
3536  * Buffering longoptions (cobol), target format (struct option)
3537  */
3538  if (lo_size % sizeof(longoption_def) == 0) {
3539  lo_amount = (int)lo_size / sizeof(longoption_def);
3540  longoptions = (struct option*) cob_malloc(sizeof(struct option) * (lo_amount + 1U));
3541  }
3542  else {
3543  cob_runtime_error (_("Call to CBL_OC_GETOPT with wrong longoption size."));
3544  cob_stop_run (1);
3545  }
3546 
3547  if (!COB_MODULE_PTR->cob_procedure_params[2]) {
3548  cob_runtime_error (_("Call to CBL_OC_GETOPT with missing longind."));
3549  cob_stop_run (1);
3550  }
3551  longind = cob_get_int (COB_MODULE_PTR->cob_procedure_params[2]);
3552 
3553  /*
3554  * Add 0-termination to strings.
3555  */
3556  shortoptions = cob_malloc(so_size + 1U);
3557  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3558  cob_field_to_string (COB_MODULE_PTR->cob_procedure_params[0], shortoptions, so_size);
3559  }
3560 
3561  if (COB_MODULE_PTR->cob_procedure_params[1]) {
3562  l = (struct longoption_def*) (COB_MODULE_PTR->cob_procedure_params[1]->data);
3563  }
3564 
3565  for (i = 0; i < lo_amount; i++) {
3566  j = sizeof(l->name) - 1;
3567  while (j >= 0 && l->name[j] == 0x20) {
3568  l->name[j] = 0x00;
3569  j--;
3570  }
3571  longoptions->name = l->name;
3572  longoptions->has_arg = (int) l->has_option - '0';
3573  memcpy (&longoptions->flag, l->return_value_pointer, sizeof(l->return_value_pointer));
3574  memcpy(&longoptions->val, &l->return_value, 4);
3575 
3576  l = l + 1; /* +1 means pointer + 1*sizeof(longoption_def) */
3577  longoptions = longoptions + 1;
3578  }
3579 
3580  /*
3581  * Appending final record, so getopt can spot the end of longoptions
3582  */
3583  longoptions->name = NULL;
3584  longoptions->has_arg = 0;
3585  longoptions->flag = NULL;
3586  longoptions->val = 0;
3587 
3588 
3589  l -= lo_amount; /* Set pointer back to begin of longoptions */
3590  longoptions -= lo_amount;
3591 
3592  return_value = cob_getopt_long_long(cob_argc, cob_argv, shortoptions, longoptions, &longind, long_only);
3593  temp = (char*) &return_value;
3594 
3595  /*
3596  * Write data back to Cobol
3597  */
3598  if (temp[0] == '?' || temp[0] == ':' || temp[0] == 'W'
3599  || temp[0] == -1 || temp[0] == 0) exit_status = return_value;
3600  else exit_status = 3;
3601 
3602  for(i = 3; i > 0; i--) {
3603  if(temp[i] == 0x00) temp[i] = 0x20;
3604  else break;
3605  }
3606 
3607  cob_set_int (COB_MODULE_PTR->cob_procedure_params[2], longind);
3608  memcpy (return_char, &return_value, 4);
3609 
3610  if(cob_optarg != NULL) {
3611  memset (opt_val, 0x00, opt_val_size);
3612 
3613  optlen = strlen (cob_optarg);
3614  if (optlen > opt_val_size) {
3615  /* Returncode 2 for "Optionvalue too long => cut" */
3616  optlen = opt_val_size;
3617  exit_status = 2;
3618  }
3619  memcpy (opt_val, cob_optarg, optlen);
3620  }
3621 
3622 
3623  cob_free (shortoptions);
3624  cob_free (longoptions);
3625 
3626  return exit_status;
3627 
3628 }
COB_EXPIMP int cob_sys_getpid ( void  )
3421 {
3422  if (!cob_process_id) {
3423  cob_process_id = (int)getpid ();
3424  }
3425  return cob_process_id;
3426 }
COB_EXPIMP int cob_sys_imp ( const void *  ,
void *  ,
const int   
)
3197 {
3198  const cob_u8_ptr data_1 = p1;
3199  cob_u8_ptr data_2 = p2;
3200  size_t n;
3201 
3202  COB_CHK_PARMS (CBL_IMP, 3);
3203 
3204  if (length <= 0) {
3205  return 0;
3206  }
3207  for (n = 0; n < (size_t)length; ++n) {
3208  data_2[n] = (~data_1[n]) | data_2[n];
3209  }
3210  return 0;
3211 }
COB_EXPIMP int cob_sys_justify ( void *  ,
  ... 
)
3687 {
3688  cob_u8_ptr data;
3689  unsigned char *direction;
3690  size_t datalen;
3691  size_t left;
3692  size_t right;
3693  size_t movelen;
3694  size_t centrelen;
3695  size_t n;
3696  size_t shifting;
3697  va_list args;
3698 
3699  COB_CHK_PARMS (C$JUSTIFY, 1);
3700 
3701  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
3702  return 0;
3703  }
3704  data = p1;
3705  datalen = COB_MODULE_PTR->cob_procedure_params[0]->size;
3706  if (datalen < 2) {
3707  return 0;
3708  }
3709  if (data[0] != ' ' && data[datalen - 1] != ' ') {
3710  return 0;
3711  }
3712  for (left = 0; left < datalen; ++left) {
3713  if (data[left] != ' ') {
3714  break;
3715  }
3716  }
3717  if (left == datalen) {
3718  return 0;
3719  }
3720  right = 0;
3721  for (n = datalen - 1; ; --n, ++right) {
3722  if (data[n] != ' ') {
3723  break;
3724  }
3725  if (n == 0) {
3726  break;
3727  }
3728  }
3729  movelen = datalen - left - right;
3730  shifting = 0;
3731  if (cobglobptr->cob_call_params > 1) {
3732  va_start (args, p1);
3733  direction = va_arg (args, unsigned char *);
3734  va_end (args);
3735  if (*direction == 'L') {
3736  shifting = 1;
3737  } else if (*direction == 'C') {
3738  shifting = 2;
3739  }
3740  }
3741  switch (shifting) {
3742  case 1:
3743  memmove (data, &data[left], movelen);
3744  memset (&data[movelen], ' ', datalen - movelen);
3745  break;
3746  case 2:
3747  centrelen = (left + right) / 2;
3748  memmove (&data[centrelen], &data[left], movelen);
3749  memset (data, ' ', centrelen);
3750  if ((left + right) % 2) {
3751  memset (&data[centrelen + movelen], ' ', centrelen + 1);
3752  } else {
3753  memset (&data[centrelen + movelen], ' ', centrelen);
3754  }
3755  break;
3756  default:
3757  memmove (&data[left + right], &data[left], movelen);
3758  memset (data, ' ', datalen - movelen);
3759  break;
3760  }
3761  return 0;
3762 }
COB_EXPIMP int cob_sys_mkdir ( unsigned char *  )
5459 {
5460  int ret;
5461 
5462  COB_CHK_PARMS (C$MAKEDIR, 1);
5463 
5464  ret = cob_sys_create_dir (dir);
5465  if (ret < 0) {
5466  ret = 128;
5467  }
5468  return ret;
5469 }
COB_EXPIMP int cob_sys_nimp ( const void *  ,
void *  ,
const int   
)
3215 {
3216  const cob_u8_ptr data_1 = p1;
3217  cob_u8_ptr data_2 = p2;
3218  size_t n;
3219 
3220  COB_CHK_PARMS (CBL_NIMP, 3);
3221 
3222  if (length <= 0) {
3223  return 0;
3224  }
3225  for (n = 0; n < (size_t)length; ++n) {
3226  data_2[n] = data_1[n] & (~data_2[n]);
3227  }
3228  return 0;
3229 }
COB_EXPIMP int cob_sys_nor ( const void *  ,
void *  ,
const int   
)
3161 {
3162  const cob_u8_ptr data_1 = p1;
3163  cob_u8_ptr data_2 = p2;
3164  size_t n;
3165 
3166  COB_CHK_PARMS (CBL_NOR, 3);
3167 
3168  if (length <= 0) {
3169  return 0;
3170  }
3171  for (n = 0; n < (size_t)length; ++n) {
3172  data_2[n] = ~(data_1[n] | data_2[n]);
3173  }
3174  return 0;
3175 }
COB_EXPIMP int cob_sys_not ( void *  ,
const int   
)
3251 {
3252  cob_u8_ptr data_1 = p1;
3253  size_t n;
3254 
3255  COB_CHK_PARMS (CBL_NOT, 2);
3256 
3257  if (length <= 0) {
3258  return 0;
3259  }
3260  for (n = 0; n < (size_t)length; ++n) {
3261  data_1[n] = ~data_1[n];
3262  }
3263  return 0;
3264 }
COB_EXPIMP int cob_sys_oc_nanosleep ( const void *  )
3377 {
3378  cob_s64_t nsecs;
3379 #if defined(_WIN32) || defined(__370__) || defined(__OS400__)
3380  unsigned int msecs;
3381 #elif defined(HAVE_NANO_SLEEP)
3382  struct timespec tsec;
3383 #else
3384  unsigned int msecs;
3385 #endif
3386 
3387  COB_UNUSED (data);
3388 
3389  COB_CHK_PARMS (CBL_OC_NANOSLEEP, 1);
3390 
3391  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3392  nsecs = cob_get_llint (COB_MODULE_PTR->cob_procedure_params[0]);
3393  if (nsecs > 0) {
3394 #ifdef _WIN32
3395  msecs = (unsigned int)(nsecs / 1000000);
3396  if (msecs > 0) {
3397  Sleep (msecs);
3398  }
3399 #elif defined(__370__) || defined(__OS400__)
3400  msecs = (unsigned int)(nsecs / 1000000000);
3401  if (msecs > 0) {
3402  sleep (msecs);
3403  }
3404 #elif defined(HAVE_NANO_SLEEP)
3405  tsec.tv_sec = nsecs / 1000000000;
3406  tsec.tv_nsec = nsecs % 1000000000;
3407  nanosleep (&tsec, NULL);
3408 #else
3409  msecs = (unsigned int)(nsecs / 1000000000);
3410  if (msecs > 0) {
3411  sleep (msecs);
3412  }
3413 #endif
3414  }
3415  }
3416  return 0;
3417 }
COB_EXPIMP int cob_sys_open_file ( unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *   
)
5048 {
5049  COB_UNUSED (file_lock);
5050  COB_UNUSED (file_dev);
5051 
5052  COB_CHK_PARMS (CBL_OPEN_FILE, 5);
5053 
5054  return open_cbl_file (file_name, file_access, file_handle, 0);
5055 }
COB_EXPIMP int cob_sys_or ( const void *  ,
void *  ,
const int   
)
3143 {
3144  const cob_u8_ptr data_1 = p1;
3145  cob_u8_ptr data_2 = p2;
3146  size_t n;
3147 
3148  COB_CHK_PARMS (CBL_OR, 3);
3149 
3150  if (length <= 0) {
3151  return 0;
3152  }
3153  for (n = 0; n < (size_t)length; ++n) {
3154  data_2[n] |= data_1[n];
3155  }
3156  return 0;
3157 }
COB_EXPIMP int cob_sys_parameter_size ( void *  )
3468 {
3469  int n;
3470 
3471  COB_UNUSED (data);
3472 
3473  COB_CHK_PARMS (C$PARAMSIZE, 1);
3474 
3475  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3476  n = cob_get_int (COB_MODULE_PTR->cob_procedure_params[0]);
3477  if (n > 0 && n <= COB_MODULE_PTR->module_num_params) {
3478  n--;
3479  if (COB_MODULE_PTR->next &&
3480  COB_MODULE_PTR->next->cob_procedure_params[n]) {
3481  return (int)COB_MODULE_PTR->next->cob_procedure_params[n]->size;
3482  }
3483  }
3484  }
3485  return 0;
3486 }
COB_EXPIMP int cob_sys_printable ( void *  ,
  ... 
)
3654 {
3655  cob_u8_ptr data;
3656  unsigned char *dotptr;
3657  size_t datalen;
3658  size_t n;
3659  unsigned char dotrep;
3660  va_list args;
3661 
3662  COB_CHK_PARMS (C$PRINTABLE, 1);
3663 
3664  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
3665  return 0;
3666  }
3667  data = p1;
3668  datalen = COB_MODULE_PTR->cob_procedure_params[0]->size;
3669  if (cobglobptr->cob_call_params > 1) {
3670  va_start (args, p1);
3671  dotptr = va_arg (args, unsigned char *);
3672  va_end (args);
3673  dotrep = *dotptr;
3674  } else {
3675  dotrep = (unsigned char)'.';
3676  }
3677  for (n = 0; n < datalen; ++n) {
3678  if (!isprint (data[n])) {
3679  data[n] = dotrep;
3680  }
3681  }
3682  return 0;
3683 }
COB_EXPIMP int cob_sys_read_file ( unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *   
)
5088 {
5089  cob_s64_t off;
5090  int fd;
5091  int len;
5092  int rc;
5093  struct stat st;
5094 
5095  COB_CHK_PARMS (CBL_READ_FILE, 5);
5096 
5097  rc = 0;
5098  memcpy (&fd, file_handle, (size_t)4);
5099  memcpy (&off, file_offset, (size_t)8);
5100  memcpy (&len, file_len, (size_t)4);
5101 #ifndef WORDS_BIGENDIAN
5102  off = COB_BSWAP_64 (off);
5103  len = COB_BSWAP_32 (len);
5104 #endif
5105  if (lseek (fd, (off_t)off, SEEK_SET) == (off_t)-1) {
5106  return -1;
5107  }
5108  if (len > 0) {
5109  rc = read (fd, buf, (size_t)len);
5110  if (rc < 0) {
5111  rc = -1;
5112  } else if (rc == 0) {
5113  rc = 10;
5114  } else {
5115  rc = 0;
5116  }
5117  }
5118  if ((*flags & 0x80) != 0) {
5119  if (fstat (fd, &st) < 0) {
5120  return -1;
5121  }
5122  off = st.st_size;
5123 #ifndef WORDS_BIGENDIAN
5124  off = COB_BSWAP_64 (off);
5125 #endif
5126  memcpy (file_offset, &off, (size_t)8);
5127  }
5128  return rc;
5129 }
COB_EXPIMP int cob_sys_rename_file ( unsigned char *  ,
unsigned char *   
)
5319 {
5320  char *fn1;
5321  char *fn2;
5322  int ret;
5323 
5324  COB_UNUSED (fname1);
5325  COB_UNUSED (fname2);
5326 
5327  COB_CHK_PARMS (CBL_RENAME_FILE, 2);
5328 
5329  if (!COB_MODULE_PTR->cob_procedure_params[0]) {
5330  return -1;
5331  }
5332  if (!COB_MODULE_PTR->cob_procedure_params[1]) {
5333  return -1;
5334  }
5335  fn1 = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[0]);
5336  fn2 = cob_str_from_fld (COB_MODULE_PTR->cob_procedure_params[1]);
5337  ret = rename (fn1, fn2);
5338  cob_free (fn1);
5339  cob_free (fn2);
5340  if (ret) {
5341  return 128;
5342  }
5343  return 0;
5344 }
COB_EXPIMP int cob_sys_return_args ( void *  )
3430 {
3431  COB_UNUSED (data);
3432 
3433  COB_CHK_PARMS (C$NARG, 1);
3434 
3435  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3436  cob_set_int (COB_MODULE_PTR->cob_procedure_params[0],
3437  COB_MODULE_PTR->module_num_params);
3438  }
3439  return 0;
3440 }
COB_EXPIMP int cob_sys_sleep ( const void *  )
3632 {
3633  int n;
3634 
3635  COB_UNUSED (data);
3636 
3637  COB_CHK_PARMS (C$SLEEP, 1);
3638 
3639  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3640  n = cob_get_int (COB_MODULE_PTR->cob_procedure_params[0]);
3641  if (n > 0 && n < 3600*24*7) {
3642 #ifdef _WIN32
3643  Sleep (n*1000);
3644 #else
3645  sleep ((unsigned int)n);
3646 #endif
3647  }
3648  }
3649  return 0;
3650 }
COB_EXPIMP int cob_sys_sound_bell ( void  )
1759 {
1760  if (COB_BEEP_VALUE == 9) {
1761  return 0;
1762  }
1763 #ifdef COB_GEN_SCREENIO
1765  COB_BEEP_VALUE != 2) {
1766  cob_screen_init ();
1767  }
1768  cob_beep ();
1769 #else
1770  cob_speaker_beep ();
1771 #endif
1772  return 0;
1773 }
COB_EXPIMP int cob_sys_system ( const void *  )
3086 {
3087  const char *cmd;
3088  char *buff;
3089  int i;
3090 
3091  COB_CHK_PARMS (SYSTEM, 1);
3092 
3093  if (COB_MODULE_PTR->cob_procedure_params[0]) {
3094  cmd = cmdline;
3095  i = (int)COB_MODULE_PTR->cob_procedure_params[0]->size;
3096  if (unlikely(i > COB_MEDIUM_MAX)) {
3097  cob_runtime_error (_("Parameter to SYSTEM call is larger than 8192 characters"));
3098  cob_stop_run (1);
3099  }
3100  i--;
3101  for (; i >= 0; --i) {
3102  if (cmd[i] != ' ' && cmd[i] != 0) {
3103  break;
3104  }
3105  }
3106  if (i >= 0) {
3107  buff = cob_malloc ((size_t)(i + 2));
3108  memcpy (buff, cmd, (size_t)(i + 1));
3110  cob_screen_set_mode (0);
3111  }
3112  i = system (buff);
3113  cob_free (buff);
3115  cob_screen_set_mode (1U);
3116  }
3117  return i;
3118  }
3119  }
3120  return 1;
3121 }
COB_EXPIMP int cob_sys_tolower ( void *  ,
const int   
)
3359 {
3360  cob_u8_ptr data = p1;
3361  size_t n;
3362 
3363  COB_CHK_PARMS (CBL_TOLOWER, 2);
3364 
3365  if (length > 0) {
3366  for (n = 0; n < (size_t)length; ++n) {
3367  if (isupper (data[n])) {
3368  data[n] = (cob_u8_t)tolower (data[n]);
3369  }
3370  }
3371  }
3372  return 0;
3373 }
COB_EXPIMP int cob_sys_toupper ( void *  ,
const int   
)
3341 {
3342  cob_u8_ptr data = p1;
3343  size_t n;
3344 
3345  COB_CHK_PARMS (CBL_TOUPPER, 2);
3346 
3347  if (length > 0) {
3348  for (n = 0; n < (size_t)length; ++n) {
3349  if (islower (data[n])) {
3350  data[n] = (cob_u8_t)toupper (data[n]);
3351  }
3352  }
3353  }
3354  return 0;
3355 }
COB_EXPIMP int cob_sys_write_file ( unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *  ,
unsigned char *   
)
5135 {
5136  cob_s64_t off;
5137  int fd;
5138  int len;
5139  int rc;
5140 
5141  COB_UNUSED (flags);
5142 
5143  COB_CHK_PARMS (CBL_WRITE_FILE, 5);
5144 
5145  memcpy (&fd, file_handle, (size_t)4);
5146  memcpy (&off, file_offset, (size_t)8);
5147  memcpy (&len, file_len, (size_t)4);
5148 #ifndef WORDS_BIGENDIAN
5149  off = COB_BSWAP_64 (off);
5150  len = COB_BSWAP_32 (len);
5151 #endif
5152  if (lseek (fd, (off_t)off, SEEK_SET) == (off_t)-1) {
5153  return -1;
5154  }
5155  rc = write (fd, buf, (size_t)len);
5156  if (rc < 0) {
5157  return 30;
5158  }
5159  return 0;
5160 }
COB_EXPIMP int cob_sys_x91 ( void *  ,
const void *  ,
void *   
)
3299 {
3300  cob_u8_ptr result = p1;
3301  const cob_u8_ptr func = p2;
3302  cob_u8_ptr parm = p3;
3303  unsigned char *p;
3304  size_t i;
3305 
3306  switch (*func) {
3307  case 11:
3308  /* Set switches */
3309  p = parm;
3310  for (i = 0; i < 8; ++i, ++p) {
3311  if (*p == 0) {
3312  cob_switch[i] = 0;
3313  } else if (*p == 1) {
3314  cob_switch[i] = 1;
3315  }
3316  }
3317  *result = 0;
3318  break;
3319  case 12:
3320  /* Get switches */
3321  p = parm;
3322  for (i = 0; i < 8; ++i, ++p) {
3323  *p = (unsigned char)cob_switch[i];
3324  }
3325  *result = 0;
3326  break;
3327  case 16:
3328  /* Return number of call parameters */
3329  *parm = (unsigned char)COB_MODULE_PTR->module_num_params;
3330  *result = 0;
3331  break;
3332  default:
3333  *result = 1;
3334  break;
3335  }
3336  return 0;
3337 }
COB_EXPIMP int cob_sys_xf4 ( void *  ,
const void *   
)
3268 {
3269  cob_u8_ptr data_1 = p1;
3270  const cob_u8_ptr data_2 = p2;
3271  size_t n;
3272 
3273  COB_CHK_PARMS (CBL_XF4, 2);
3274 
3275  *data_1 = 0;
3276  for (n = 0; n < 8; ++n) {
3277  *data_1 |= (data_2[n] & 1) << (7 - n);
3278  }
3279  return 0;
3280 }
COB_EXPIMP int cob_sys_xf5 ( const void *  ,
void *   
)
3284 {
3285  const cob_u8_ptr data_1 = p1;
3286  cob_u8_ptr data_2 = p2;
3287  size_t n;
3288 
3289  COB_CHK_PARMS (CBL_XF5, 2);
3290 
3291  for (n = 0; n < 8; ++n) {
3292  data_2[n] = (*data_1 & (1 << (7 - n))) ? 1 : 0;
3293  }
3294  return 0;
3295 }
COB_EXPIMP int cob_sys_xor ( const void *  ,
void *  ,
const int   
)
3179 {
3180  const cob_u8_ptr data_1 = p1;
3181  cob_u8_ptr data_2 = p2;
3182  size_t n;
3183 
3184  COB_CHK_PARMS (CBL_XOR, 3);
3185 
3186  if (length <= 0) {
3187  return 0;
3188  }
3189  for (n = 0; n < (size_t)length; ++n) {
3190  data_2[n] ^= data_1[n];
3191  }
3192  return 0;
3193 }
COB_EXPIMP void cob_table_sort ( cob_field ,
const int   
)
2297 {
2298  qsort (f->data, (size_t) n, f->size, sort_compare);
2299  cob_free (sort_keys);
2300 }
COB_EXPIMP void cob_table_sort_init ( const size_t  ,
const unsigned char *   
)
2275 {
2276  sort_nkeys = 0;
2277  sort_keys = cob_malloc (nkeys * sizeof (cob_file_key));
2278  if (collating_sequence) {
2279  sort_collate = collating_sequence;
2280  } else {
2281  sort_collate = COB_MODULE_PTR->collating_sequence;
2282  }
2283 }
COB_EXPIMP void cob_table_sort_init_key ( cob_field ,
const int  ,
const unsigned  int 
)
2288 {
2289  sort_keys[sort_nkeys].field = field;
2290  sort_keys[sort_nkeys].flag = flag;
2291  sort_keys[sort_nkeys].offset = offset;
2292  sort_nkeys++;
2293 }
COB_EXPIMP void cob_temp_name ( char *  ,
const char *   
)
2913 {
2914  /* Set temporary file name */
2915  if (ext) {
2916  snprintf (filename, (size_t)COB_FILE_MAX, "%s%ccob%d_%d%s",
2917  cob_gettmpdir(), SLASH_INT, cob_sys_getpid(), cob_temp_iteration, ext);
2918  } else {
2919  snprintf (filename, (size_t)COB_FILE_MAX, "%s%ccobsort%d_%d",
2921  }
2922 }
COB_EXPIMP int cob_tidy ( void  )
2975 {
2976  struct exit_handlerlist *h;
2977 
2978  if (!cob_initialized) {
2979  exit (1);
2980  }
2981  if (exit_hdlrs != NULL) {
2982  h = exit_hdlrs;
2983  while (h != NULL) {
2984  h->proc ();
2985  h = h->next;
2986  }
2987  }
2989  return 0;
2990 }
COB_EXPIMP void cob_trace_section ( const char *  ,
const char *  ,
const int   
)
1276 {
1277  const char *s;
1278 
1279  if (cob_line_trace) {
1280  if (!cob_trace_file) {
1282  }
1283  if (source &&
1284  (!cob_last_sfile || strcmp (cob_last_sfile, source))) {
1285  cob_last_sfile = source;
1286  fprintf (cob_trace_file, "Source: '%s'\n", source);
1287  }
1288  if (COB_MODULE_PTR->module_name) {
1289  s = COB_MODULE_PTR->module_name;
1290  } else {
1291  s = "Unknown";
1292  }
1293  fprintf (cob_trace_file, "Program-Id: %-16s ", s);
1294  if (line) {
1295  fprintf (cob_trace_file, "%-34.34sLine: %d\n", para, line);
1296  } else {
1297  fprintf (cob_trace_file, "%s\n", para);
1298  }
1299  fflush (cob_trace_file);
1300  }
1301 }
COB_EXPIMP void cob_unlock_file ( cob_file ,
cob_field  
)
4451 {
4452  cob_file_unlock (f);
4453  save_status (f, fnstatus, COB_STATUS_00_SUCCESS);
4454 }
COB_EXPIMP void cob_unstring_delimited ( cob_field ,
const cob_u32_t   
)
517 {
520  unstring_ndlms++;
521 }
COB_EXPIMP void cob_unstring_finish ( void  )
621 {
622  if (unstring_offset < (int)unstring_src->size) {
623  cob_set_exception (COB_EC_OVERFLOW_UNSTRING);
624  }
625 
626  if (unstring_ptr) {
628  }
629 }
COB_EXPIMP void cob_unstring_init ( cob_field ,
cob_field ,
const size_t   
)
488 {
489  unstring_src_copy = *src;
491  unstring_ptr = NULL;
492  if (ptr) {
493  unstring_ptr_copy = *ptr;
495  }
496 
497  unstring_offset = 0;
498  unstring_count = 0;
499  unstring_ndlms = 0;
500  cob_set_exception (0);
501  if (num_dlm > dlm_list_size) {
502  cob_free (dlm_list);
503  dlm_list = cob_malloc (num_dlm * sizeof(struct dlm_struct));
504  dlm_list_size = num_dlm;
505  }
506 
507  if (unstring_ptr) {
509  if (unstring_offset < 0 || unstring_offset >= (int)unstring_src->size) {
510  cob_set_exception (COB_EC_OVERFLOW_UNSTRING);
511  }
512  }
513 }
COB_EXPIMP void cob_unstring_into ( cob_field ,
cob_field ,
cob_field  
)
525 {
526  unsigned char *p;
527  unsigned char *dp;
528  unsigned char *s;
529  unsigned char *dlm_data;
530  unsigned char *start;
531  size_t dlm_size = 0;
532  int i;
533  int srsize;
534  int dlsize;
535  int match_size = 0;
536  int brkpt = 0;
537 
538  if (cob_get_exception_code ()) {
539  return;
540  }
541 
542  if (unstring_offset >= (int)unstring_src->size) {
543  return;
544  }
545 
546  start = unstring_src->data + unstring_offset;
547  dlm_data = NULL;
548  if (unstring_ndlms == 0) {
549  match_size = cob_min_int ((int)COB_FIELD_SIZE (dst),
551  cob_str_memcpy (dst, start, match_size);
552  unstring_offset += match_size;
553  } else {
554  srsize = (int) unstring_src->size;
555  s = unstring_src->data + srsize;
556  for (p = start; p < s; ++p) {
557  for (i = 0; i < unstring_ndlms; ++i) {
558  dlsize = (int) dlm_list[i].uns_dlm.size;
559  dp = dlm_list[i].uns_dlm.data;
560  if (p + dlsize > s) {
561  continue;
562  }
563  if (!memcmp (p, dp, (size_t)dlsize)) { /* delimiter equal */
564  match_size = (int)(p - start); /* count in */
565  cob_str_memcpy (dst, start, match_size); /* into */
566  unstring_offset += match_size + dlsize; /* with pointer */
567  dlm_data = dp;
568  dlm_size = dlsize;
569  if (dlm_list[i].uns_all) { /* delimited by all */
570  for (p += dlsize ; p < s; p += dlsize) {
571  if (p + dlsize > s) {
572  break;
573  }
574  if (memcmp (p, dp, (size_t)dlsize)) {
575  break;
576  }
577  unstring_offset += dlsize;
578  }
579  }
580  brkpt = 1;
581  break;
582  }
583  }
584  if (brkpt) {
585  break;
586  }
587  }
588  if (!brkpt) {
589  /* No match */
590  match_size = (int)(unstring_src->size - unstring_offset);
591  cob_str_memcpy (dst, start, match_size);
593  dlm_data = NULL;
594  }
595  }
596  unstring_count++;
597 
598  if (dlm) {
599  if (dlm_data) {
600  cob_str_memcpy (dlm, dlm_data, (int) dlm_size);
601  } else if (COB_FIELD_IS_NUMERIC (dlm)) {
602  cob_set_int (dlm, 0);
603  } else {
604  memset (dlm->data, ' ', dlm->size);
605  }
606  }
607 
608  if (cnt) {
609  cob_set_int (cnt, match_size);
610  }
611 }
COB_EXPIMP void cob_unstring_tallying ( cob_field )
615 {
616  cob_add_int (f, unstring_count, 0);
617 }
COB_EXPIMP int cob_valid_date_format ( const char *  )
2102 {
2103  return !strcmp (format, "YYYYMMDD")
2104  || !strcmp (format, "YYYY-MM-DD")
2105  || !strcmp (format, "YYYYDDD")
2106  || !strcmp (format, "YYYY-DDD")
2107  || !strcmp (format, "YYYYWwwD")
2108  || !strcmp (format, "YYYY-Www-D");
2109 }
COB_EXPIMP int cob_valid_datetime_format ( const char *  )
2147 {
2148  char date_format_str[MAX_DATETIME_STR_LENGTH] = { '\0' };
2149  char time_format_str[MAX_DATETIME_STR_LENGTH] = { '\0' };
2150  struct date_format date_format;
2151  struct time_format time_format;
2152 
2153  split_around_t (format, date_format_str, time_format_str);
2154 
2155  if (!cob_valid_date_format (date_format_str)
2156  || !cob_valid_time_format (time_format_str)) {
2157  return 0;
2158  }
2159 
2160  /* Check time and date formats match */
2161  date_format = parse_date_format_string (date_format_str);
2162  time_format = parse_time_format_string (time_format_str);
2164  return 0;
2165  }
2166 
2167  return 1;
2168 }
COB_EXPIMP int cob_valid_time_format ( const char *  )
2113 {
2114  int with_colons;
2115  ptrdiff_t format_offset;
2116  int decimal_places = 0;
2117 
2118  if (!strncmp (format, "hhmmss", 6)) {
2119  with_colons = 0;
2120  format_offset = 6;
2121  } else if (!strncmp (format, "hh:mm:ss", 8)) {
2122  with_colons = 1;
2123  format_offset = 8;
2124  } else {
2125  return 0;
2126  }
2127 
2128  if (format[format_offset] == '.') {
2129  decimal_places = decimal_places_for_seconds (format, format_offset);
2130  format_offset += decimal_places + 1;
2131  if (!(1 <= decimal_places && decimal_places <= max_time_decimal_places)) {
2132  return 0;
2133  }
2134  }
2135 
2136  if (strlen (format) > format_offset
2137  && !rest_is_z (format + format_offset)
2138  && !rest_is_offset_format (format + format_offset, with_colons)) {
2139  return 0;
2140  }
2141 
2142  return 1;
2143 }
COB_EXPIMP void cob_write ( cob_file ,
cob_field ,
const int  ,
cob_field ,
const unsigned  int 
)
4775 {
4776  f->flag_read_done = 0;
4777 
4778  if (f->access_mode == COB_ACCESS_SEQUENTIAL) {
4779  if (unlikely(f->open_mode != COB_OPEN_OUTPUT &&
4780  f->open_mode != COB_OPEN_EXTEND)) {
4782  return;
4783  }
4784  } else {
4785  if (unlikely(f->open_mode != COB_OPEN_OUTPUT &&
4786  f->open_mode != COB_OPEN_I_O)) {
4788  return;
4789  }
4790  }
4791 
4792  if (f->variable_record) {
4793  f->record->size = (size_t)cob_get_int (f->variable_record);
4794  if (unlikely(f->record->size > rec->size)) {
4795  f->record->size = rec->size;
4796  }
4797  } else {
4798  f->record->size = rec->size;
4799  }
4800 
4801  if (f->record->size < f->record_min || f->record_max < f->record->size) {
4803  return;
4804  }
4805 
4806  check_eop_status = check_eop;
4807  save_status (f, fnstatus,
4808  fileio_funcs[(int)f->organization]->write (f, opt));
4809 }
DECLNORET void cobc_abort ( const char *  ,
const int   
)

References _, cobc_abort_pr(), and cobc_abort_terminate().

Referenced by cobc_dumb_abort().

607 {
608  cobc_abort_pr (_("%s:%d Internal compiler error"), filename, linenum);
610 }
void* cobc_check_string ( const char *  )

References _, base_string, cobc_abort_pr(), cobc_abort_terminate(), cobc_main_malloc(), cobc_main_strdup(), strcache::next, unlikely, and strcache::val.

Referenced by cb_build_binary_picture(), cb_build_picture(), cb_build_program_id(), cb_define_list_add(), and cb_encode_program_id().

942 {
943  struct strcache *s;
944 
945 #ifdef COB_TREE_DEBUG
946  if (unlikely(!dupstr)) {
947  cobc_abort_pr (_("Call to cobc_check_string with NULL pointer"));
949  }
950 #endif
951  for (s = base_string; s; s = s->next) {
952  if (!strcmp (dupstr, (const char *)s->val)) {
953  return s->val;
954  }
955  }
956  s = cobc_main_malloc (sizeof(struct strcache));
957  s->next = base_string;
958  s->val = cobc_main_strdup (dupstr);
959  base_string = s;
960  return s->val;
961 }
size_t cobc_check_valid_name ( const char *  ,
const unsigned  int 
)

References cob_csyns, COB_NUM_CSYNS, cobc_bcompare(), cobc_error_name(), and p.

Referenced by cb_build_program_id(), and process_filename().

1133 {
1134  const char *p;
1135  size_t len;
1136 
1137  for (p = name, len = 0; *p; p++, len++) {
1138  if (*p == '/' || *p == '\\') {
1139  cobc_error_name (name, prechk, 5U);
1140  return 1;
1141  }
1142  }
1143  if (len < 1) {
1144  cobc_error_name (name, prechk, 1U);
1145  return 1;
1146  }
1147  if (!cb_relaxed_syntax_check && len > 31) {
1148  cobc_error_name (name, prechk, 1U);
1149  return 1;
1150  }
1151  if (*name == '_' || *name == ' ') {
1152  cobc_error_name (name, prechk, 2U);
1153  return 1;
1154  }
1155  if (prechk && len > 3 &&
1156  (!memcmp (name, "cob_", (size_t)4) ||
1157  !memcmp (name, "COB_", (size_t)4))) {
1158  cobc_error_name (name, prechk, 3U);
1159  return 1;
1160  }
1161  if (bsearch (name, cob_csyns, COB_NUM_CSYNS,
1162  sizeof (char *), cobc_bcompare)) {
1163  cobc_error_name (name, prechk, 4U);
1164  return 1;
1165  }
1166  return 0;
1167 }
DECLNORET void cobc_dumb_abort ( const char *  ,
const int   
)

References cobc_abort().

614 {
615  cobc_abort (filename, linenum);
616 }
void cobc_free ( void *  )

deallocation of compile time memory

References _, cobc_abort_pr(), cobc_abort_terminate(), and unlikely.

Referenced by cb_define_list_add(), cb_reset_78(), cb_reset_global_78(), clear_initial_values(), cobc_cmd_print(), cobc_deciph_funcs(), cobc_free_mem(), cobc_main_free(), cobc_main_realloc(), cobc_parse_free(), cobc_parse_realloc(), cobc_var_print(), main(), plex_clear_all(), ppecho(), preprocess(), process(), process_env_copy_path(), scan_define_options(), while(), and ylex_clear_all().

658 {
659 #ifdef COB_TREE_DEBUG
660  if (unlikely(!mptr)) {
661  cobc_abort_pr (_("Call to cobc_free with NULL pointer"));
663  }
664 #endif
665  free(mptr);
666 }
cobc_free ( var  )
void cobc_main_free ( void *  )

References cobc_free(), cobc_mem_struct::memptr, cobc_mem_struct::next, and NULL.

779 {
780  struct cobc_mem_struct *curr;
781  struct cobc_mem_struct *prev;
782 
783  prev = NULL;
784  for (curr = cobc_mainmem_base; curr; curr = curr->next) {
785  if (curr->memptr == prevptr) {
786  break;
787  }
788  prev = curr;
789  }
790  if (!curr) {
791  return;
792  }
793  if (prev) {
794  prev->next = curr->next;
795  } else {
796  /* At mainmem_base */
797  cobc_mainmem_base = curr->next;
798  }
799  cobc_free (curr);
800 }
void* cobc_main_malloc ( const size_t  )
void* cobc_main_realloc ( void *  ,
const size_t   
)

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_free(), cobc_mem_struct::memlen, cobc_mem_struct::memptr, cobc_mem_struct::next, NULL, and unlikely.

Referenced by cb_expr_shift(), cobc_add_str(), cobc_chk_buff_size(), file_basename(), and output_initialize_one().

739 {
740  struct cobc_mem_struct *m;
741  struct cobc_mem_struct *curr;
742  struct cobc_mem_struct *prev;
743 
744  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
745  if (unlikely(!m)) {
746  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
747  (int)size);
749  }
750  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
751  m->memlen = size;
752 
753  prev = NULL;
754  for (curr = cobc_mainmem_base; curr; curr = curr->next) {
755  if (curr->memptr == prevptr) {
756  break;
757  }
758  prev = curr;
759  }
760  if (unlikely(!curr)) {
761  cobc_abort_pr (_("Attempt to reallocate non-allocated memory - Aborting"));
763  }
764  m->next = curr->next;
765  if (prev) {
766  prev->next = m;
767  } else {
768  /* At mainmem_base */
769  cobc_mainmem_base = m;
770  }
771  memcpy (m->memptr, curr->memptr, curr->memlen);
772  cobc_free (curr);
773 
774  return m->memptr;
775 }
void* cobc_main_strdup ( const char *  )

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_main_malloc(), p, and unlikely.

Referenced by cb_text_list_add(), cobc_check_string(), cobc_getenv(), cobc_set_value(), main(), process_command_line(), process_filename(), process_link(), and read_string().

721 {
722  void *p;
723  size_t n;
724 
725 #ifdef COB_TREE_DEBUG
726  if (unlikely(!dupstr)) {
727  cobc_abort_pr (_("Call to cobc_main_strdup with NULL pointer"));
729  }
730 #endif
731  n = strlen (dupstr);
732  p = cobc_main_malloc (n + 1);
733  memcpy (p, dupstr, n);
734  return p;
735 }
void* cobc_malloc ( const size_t  )

memory allocation for use when compiling

Allocate size bytes of memory, cleared to zeros. Aborts compile if memory unavailable.

References _, cobc_abort_pr(), cobc_abort_terminate(), and unlikely.

Referenced by cb_add_78(), cb_add_const_var(), cobc_strdup(), ppopen(), and process().

644 {
645  void *mptr;
646 
647  mptr = calloc ((size_t)1, size);
648  if (unlikely(!mptr)) {
649  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
650  (int)size);
652  }
653  return mptr;
654 }
void cobc_parse_free ( void *  )

References cobc_free(), cobc_mem_struct::memptr, cobc_mem_struct::next, and NULL.

Referenced by cb_build_move_literal(), terminator_clear(), terminator_error(), and terminator_warning().

881 {
882  struct cobc_mem_struct *curr;
883  struct cobc_mem_struct *prev;
884 
885  prev = NULL;
886  for (curr = cobc_parsemem_base; curr; curr = curr->next) {
887  if (curr->memptr == prevptr) {
888  break;
889  }
890  prev = curr;
891  }
892  if (!curr) {
893  return;
894  }
895  if (prev) {
896  prev->next = curr->next;
897  } else {
898  /* At parsemem_base */
899  cobc_parsemem_base = curr->next;
900  }
901  cobc_free (curr);
902 }
void* cobc_parse_realloc ( void *  ,
const size_t   
)

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_free(), cobc_mem_struct::memlen, cobc_mem_struct::memptr, cobc_mem_struct::next, NULL, and unlikely.

841 {
842  struct cobc_mem_struct *m;
843  struct cobc_mem_struct *curr;
844  struct cobc_mem_struct *prev;
845 
846  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
847  if (unlikely(!m)) {
848  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
849  (int)size);
851  }
852  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
853  m->memlen = size;
854 
855  prev = NULL;
856  for (curr = cobc_parsemem_base; curr; curr = curr->next) {
857  if (curr->memptr == prevptr) {
858  break;
859  }
860  prev = curr;
861  }
862  if (unlikely(!curr)) {
863  cobc_abort_pr (_("Attempt to reallocate non-allocated memory - Aborting"));
865  }
866  m->next = curr->next;
867  if (prev) {
868  prev->next = m;
869  } else {
870  /* At parsemem_base */
871  cobc_parsemem_base = m;
872  }
873  memcpy (m->memptr, curr->memptr, curr->memlen);
874  cobc_free (curr);
875 
876  return m->memptr;
877 }
void* cobc_parse_strdup ( const char *  )

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_parse_malloc(), p, and unlikely.

Referenced by cb_build_class_name(), cb_build_debug(), cb_emit_evaluate(), cb_to_cname(), lookup_string(), lookup_word(), and while().

823 {
824  void *p;
825  size_t n;
826 
827 #ifdef COB_TREE_DEBUG
828  if (unlikely(!dupstr)) {
829  cobc_abort_pr (_("Call to cobc_parse_strdup with NULL pointer"));
831  }
832 #endif
833  n = strlen (dupstr);
834  p = cobc_parse_malloc (n + 1);
835  memcpy (p, dupstr, n);
836  return p;
837 }
void* cobc_plex_malloc ( const size_t  )

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_plexmem_base, cobc_mem_struct::memptr, cobc_mem_struct::next, and unlikely.

Referenced by cobc_plex_strdup(), pp_text_list_add(), ppp_define_add(), ppp_list_add(), and ppp_replace_list_add().

907 {
908  struct cobc_mem_struct *m;
909 
910  m = calloc ((size_t)1, sizeof(struct cobc_mem_struct) + size);
911  if (unlikely(!m)) {
912  cobc_abort_pr (_("Cannot allocate %d bytes of memory - Aborting"),
913  (int)size);
915  }
916  m->memptr = (char *)m + sizeof(struct cobc_mem_struct);
917  m->next = cobc_plexmem_base;
918  cobc_plexmem_base = m;
919  return m->memptr;
920 }
void* cobc_plex_strdup ( const char *  )

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_plex_malloc(), p, and unlikely.

Referenced by ppp_define_add(), ppp_list_add(), ppp_set_value(), switch_to_buffer(), and while().

924 {
925  void *p;
926  size_t n;
927 
928 #ifdef COB_TREE_DEBUG
929  if (unlikely(!dupstr)) {
930  cobc_abort_pr (_("Call to cobc_plex_strdup with NULL pointer"));
932  }
933 #endif
934  n = strlen (dupstr);
935  p = cobc_plex_malloc (n + 1);
936  memcpy (p, dupstr, n);
937  return p;
938 }
void* cobc_realloc ( void *  ,
const size_t   
)

References _, cobc_abort_pr(), cobc_abort_terminate(), and unlikely.

Referenced by read_literal(), scan_x(), and scan_z().

688 {
689  void *mptr;
690 
691  mptr = realloc (prevptr, size);
692  if (unlikely(!mptr)) {
693  cobc_abort_pr (_("Cannot reallocate %d bytes of memory - Aborting"),
694  (int)size);
696  }
697  return mptr;
698 }
void* cobc_strdup ( const char *  )

safely duplicate a character array

References _, cobc_abort_pr(), cobc_abort_terminate(), cobc_malloc(), p, and unlikely.

Referenced by cb_define_list_add(), cobc_cmd_print(), cobc_deciph_funcs(), cobc_var_print(), ppecho(), ppopen(), process_command_line(), process_env_copy_path(), scan_define_options(), and while().

670 {
671  void *p;
672  size_t n;
673 
674 #ifdef COB_TREE_DEBUG
675  if (unlikely(!dupstr)) {
676  cobc_abort_pr (_("Call to cobc_strdup with NULL pointer"));
678  }
679 #endif
680  n = strlen (dupstr);
681  p = cobc_malloc (n + 1);
682  memcpy (p, dupstr, n);
683  return p;
684 }
DECLNORET void cobc_too_many_errors ( void  )

References _, cobc_abort_pr(), and cobc_abort_terminate().

Referenced by cb_error(), cb_error_x(), and cb_plex_error().

600 {
601  cobc_abort_pr (_("Too many errors - Aborting compilation"));
603 }
DECLNORET void cobc_tree_cast_error ( const cb_tree  ,
const char *  ,
const int  ,
const enum  cb_tag 
)
621 {
622  cobc_abort_pr (_("%s:%d Invalid cast from '%s' type %s to type %s"),
623  filename, linenum,
624  x ? cb_name (x) : "NULL",
625  x ? cobc_enum_explain (CB_TREE_TAG(x)) : "None",
626  cobc_enum_explain (tagnum));
628 }
void codegen ( struct cb_program ,
const int   
)
7340 {
7341  cb_tree l;
7342  struct attr_list *j;
7343  struct literal_list *m;
7344  struct field_list *k;
7345  struct string_list *stp;
7346  struct call_list *clp;
7347  struct base_list *blp;
7348  unsigned char *s;
7349  struct nested_list *nlp;
7350  struct cb_program *cp;
7351 #if 0 /* RXWRXW - Const */
7352  struct cb_literal *lp;
7353 #endif
7354  cb_tree l1;
7355  cb_tree l2;
7356  const char *prevprog;
7357  struct tm *loctime;
7358  cob_u32_t inc;
7359 #if 0 /* RXWRXW - Sticky */
7360  int save_sticky;
7361 #endif
7362  int i;
7363  int found;
7364  enum cb_optim optidx;
7365  time_t sectime;
7366 
7367  /* Clear local program stuff */
7368  current_prog = prog;
7369  param_id = 0;
7370  stack_id = 0;
7371  num_cob_fields = 0;
7372  progid = 0;
7373  loop_counter = 0;
7374  output_indent_level = 0;
7375  last_line = 0;
7376  needs_exit_prog = 0;
7377  gen_custom = 0;
7378  gen_nested_tab = 0;
7379  gen_dynamic = 0;
7380  gen_if_level = 0;
7381  local_mem = 0;
7382  local_working_mem = 0;
7383  need_save_exception = 0;
7384  last_segment = 0;
7385  last_section = NULL;
7386  call_cache = NULL;
7388  label_cache = NULL;
7391  inside_check = 0;
7392  for (i = 0; i < COB_INSIDE_SIZE; ++i) {
7393  inside_stack[i] = 0;
7394  }
7395  excp_current_program_id = prog->orig_program_id;
7398  memset ((void *)i_counters, 0, sizeof (i_counters));
7399 #if 0 /* RXWRXW - Sticky */
7400  save_sticky = cb_sticky_linkage;
7401 #endif
7402 
7403  output_target = yyout;
7405 
7406  if (!nested) {
7407  /* First iteration */
7408  gen_alt_ebcdic = 0;
7409  gen_ebcdic_ascii = 0;
7410  gen_full_ebcdic = 0;
7411  gen_native = 0;
7412  gen_figurative = 0;
7413  non_nested_count = 0;
7414  working_mem = 0;
7415  attr_cache = NULL;
7416  base_cache = NULL;
7417  globext_cache = NULL;
7418  literal_cache = NULL;
7419  field_cache = NULL;
7420  string_cache = NULL;
7421  string_id = 1;
7422  if (!string_buffer) {
7423  string_buffer = cobc_main_malloc ((size_t)COB_MINI_BUFF);
7424  }
7425 
7426  sectime = time (NULL);
7427  loctime = localtime (&sectime);
7428  /* Leap seconds ? */
7429  if (loctime->tm_sec >= 60) {
7430  loctime->tm_sec = 59;
7431  }
7432  if (loctime) {
7433  strftime (string_buffer, (size_t)COB_MINI_MAX,
7434  "%b %d %Y %H:%M:%S", loctime);
7435  } else {
7436  strcpy (string_buffer, _("Unknown"));
7437  }
7440  for (cp = prog; cp; cp = cp->next_program) {
7442  string_buffer, cp);
7443  }
7444 
7445 #ifndef _GNU_SOURCE
7446 #ifdef _XOPEN_SOURCE_EXTENDED
7447  output ("#ifndef\t_XOPEN_SOURCE_EXTENDED\n");
7448  output ("#define\t_XOPEN_SOURCE_EXTENDED 1\n");
7449  output ("#endif\n");
7450 #endif
7451 #endif
7452  output ("#include <stdio.h>\n");
7453  output ("#include <stdlib.h>\n");
7454  output ("#include <stddef.h>\n");
7455  output ("#include <string.h>\n");
7456  output ("#include <math.h>\n");
7457 #ifdef WORDS_BIGENDIAN
7458  output ("#define WORDS_BIGENDIAN 1\n");
7459 #endif
7460 #ifdef COB_KEYWORD_INLINE
7461  output ("#define COB_KEYWORD_INLINE %s\n",
7463 #endif
7464  output ("#include <libcob.h>\n\n");
7465 
7466  output ("#define COB_SOURCE_FILE\t\t\"%s\"\n",
7467  cb_source_file);
7468  output ("#define COB_PACKAGE_VERSION\t\t\"%s\"\n",
7469  PACKAGE_VERSION);
7470  output ("#define COB_PATCH_LEVEL\t\t%d\n",
7471  PATCH_LEVEL);
7472  /* string_buffer has formatted date from above */
7473  output ("#define COB_MODULE_FORMATTED_DATE\t\"%s\"\n",
7474  string_buffer);
7475  if (loctime) {
7476  i = ((loctime->tm_year + 1900) * 10000) +
7477  ((loctime->tm_mon + 1) * 100) +
7478  loctime->tm_mday;
7479  output ("#define COB_MODULE_DATE\t\t%d\n", i);
7480  i = (loctime->tm_hour * 10000) +
7481  (loctime->tm_min * 100) +
7482  loctime->tm_sec;
7483  output ("#define COB_MODULE_TIME\t\t%d\n", i);
7484  } else {
7485  output ("#define COB_MODULE_DATE\t\t0\n");
7486  output ("#define COB_MODULE_TIME\t\t0\n");
7487  }
7488 
7489  output_newline ();
7490  output ("/* Global variables */\n");
7491  output ("#include \"%s\"\n\n", cb_storage_file_name);
7492 
7493  output ("/* Function prototypes */\n\n");
7494  for (cp = prog; cp; cp = cp->next_program) {
7495  /* Build parameter list */
7496  for (l = cp->entry_list; l; l = CB_CHAIN (l)) {
7497  for (l1 = CB_VALUE (l); l1; l1 = CB_CHAIN (l1)) {
7498  for (l2 = cp->parameter_list; l2; l2 = CB_CHAIN (l2)) {
7499  if (strcasecmp (cb_code_field (CB_VALUE (l1))->name,
7500  cb_code_field (CB_VALUE (l2))->name) == 0) {
7501  break;
7502  }
7503  }
7504  if (l2 == NULL) {
7506  }
7507  }
7508  }
7509  if (cp->flag_main) {
7510  if (!cp->flag_recursive) {
7511  output ("static int\t\t%s ();\n",
7512  cp->program_id);
7513  } else {
7514  output ("int\t\t\t%s ();\n",
7515  cp->program_id);
7516  }
7517  } else {
7518  for (l = cp->entry_list; l; l = CB_CHAIN (l)) {
7519  output_entry_function (cp, l, cp->parameter_list, 0);
7520  }
7521  }
7522  if (cp->prog_type == CB_FUNCTION_TYPE) {
7523  non_nested_count++;
7524 #if 0 /* RXWRXW USERFUNC */
7525  output ("static cob_field\t*%s_ (const int, cob_field **",
7526 #else
7527  output ("static cob_field\t*%s_ (const int",
7528 #endif
7529  cp->program_id);
7530  } else if (!cp->nested_level) {
7531  non_nested_count++;
7532  output ("static int\t\t%s_ (const int",
7533  cp->program_id);
7534  } else {
7535  output ("static int\t\t%s_%d_ (const int",
7536  cp->program_id, cp->toplev_count);
7537  }
7538 #if 0 /* RXWRXW USERFUNC */
7539  if (!cp->flag_chained && cp->prog_type != CB_FUNCTION_TYPE) {
7540 #else
7541  if (!cp->flag_chained) {
7542 #endif
7543  for (l = cp->parameter_list; l; l = CB_CHAIN (l)) {
7544  output (", cob_u8_t *");
7545  if (cb_sticky_linkage) {
7546  output_storage ("static cob_u8_t\t\t\t*cob_parm_%d = NULL;\n",
7547  cb_code_field (CB_VALUE (l))->id);
7548  }
7549  }
7550  }
7551 #if 0 /* RXWRXW - NOINLINE */
7552  if (cb_flag_stack_check) {
7553  output (") COB_NOINLINE;\n");
7554  } else {
7555 #endif
7556  output (");\n");
7557 #if 0 /* RXWRXW - NOINLINE */
7558  }
7559 #endif
7560  }
7561  output ("\n");
7562  }
7563 
7564  /* Class-names */
7565  if (!prog->nested_level && prog->class_name_list) {
7566  output ("/* Class names */\n");
7567  for (l = prog->class_name_list; l; l = CB_CHAIN (l)) {
7568  output_class_name_definition (CB_CLASS_NAME (CB_VALUE (l)));
7569  }
7570  }
7571 
7572  /* Main function */
7573  if (prog->flag_main) {
7574  output_main_function (prog);
7575  }
7576 
7577  /* Functions */
7578  if (!nested) {
7579  output ("/* Functions */\n\n");
7580  }
7581 
7582  if (prog->prog_type == CB_FUNCTION_TYPE) {
7583  output ("/* FUNCTION-ID '%s' */\n\n", prog->orig_program_id);
7584  } else {
7585  output ("/* PROGRAM-ID '%s' */\n\n", prog->orig_program_id);
7586  }
7587 
7588  for (l = prog->entry_list; l; l = CB_CHAIN (l)) {
7589  output_entry_function (prog, l, prog->parameter_list, 1);
7590  }
7591 
7592  output_internal_function (prog, prog->parameter_list);
7593 
7594  if (!prog->next_program) {
7595  output ("/* End functions */\n\n");
7596  }
7597 
7598  if (gen_native || gen_full_ebcdic ||
7599  gen_ebcdic_ascii || prog->alphabet_name_list) {
7600  (void)lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
7601  }
7602 
7604 
7605  /* Program local stuff */
7606 
7607  /* CALL cache */
7609  output_local ("\n/* Call pointers */\n");
7610  }
7611  if (needs_unifunc) {
7612  output_local ("cob_call_union\t\tcob_unifunc;\n");
7613  }
7614  for (clp = call_cache; clp; clp = clp->next) {
7615  output_local ("static cob_call_union\tcall_%s;\n",
7616  clp->callname);
7617  }
7618  for (clp = func_call_cache; clp; clp = clp->next) {
7619  output_local ("static cob_call_union\tfunc_%s;\n",
7620  clp->callname);
7621  }
7622  needs_unifunc = 0;
7623 
7624  /* Nested / contained list */
7625  if (prog->nested_prog_list && gen_nested_tab) {
7626  /* Generate contained program list */
7627  output_local ("\n/* Nested call table */\n");
7628  output_local ("static struct cob_call_struct\tcob_nest_tab[] = {\n");
7629  nlp = prog->nested_prog_list;
7630  for (; nlp; nlp = nlp->next) {
7631  if (nlp->nested_prog == prog) {
7632 #if 0 /* RXWRXW Fix recursive */
7633  if (!prog->flag_recursive) {
7634  continue;
7635  }
7636 #endif
7637  output_local ("\t{ \"%s\", { (void *(*)())%s_%d__ }, { NULL } },\n",
7639  nlp->nested_prog->program_id,
7640  nlp->nested_prog->toplev_count);
7641  } else {
7642  output_local ("\t{ \"%s\", { (void *(*)())%s_%d__ }, { (void *(*)())%s_%d_ } },\n",
7644  nlp->nested_prog->program_id,
7645  nlp->nested_prog->toplev_count,
7646  nlp->nested_prog->program_id,
7647  nlp->nested_prog->toplev_count);
7648  }
7649  }
7650  output_local ("\t{ NULL, { NULL }, { NULL } }\n");
7651  output_local ("};\n");
7652  }
7653 
7654  /* Local indexes */
7655  found = 0;
7656  for (i = 0; i < COB_MAX_SUBSCRIPTS; i++) {
7657  if (i_counters[i]) {
7658  if (!found) {
7659  found = 1;
7660  output_local ("\n/* Subscripts */\n");
7661  }
7662  output_local ("int\t\ti%d;\n", i);
7663  }
7664  }
7665 
7666  /* PERFORM TIMES counters */
7667  if (loop_counter) {
7668  output_local ("\n/* Loop counters */\n");
7669  for (i = 0; i < loop_counter; i++) {
7670  output_local ("cob_s64_t\tn%d = 0;\n", i);
7671  }
7672  output_local ("\n");
7673  }
7674 
7675  /* Local implicit fields */
7676  if (num_cob_fields) {
7677  output_local ("\n/* Local cob_field items */\n");
7678  for (i = 0; i < num_cob_fields; i++) {
7679  output_local ("cob_field\t\tf%d;\n", i);
7680  }
7681  output_local ("\n");
7682  }
7683 
7684  /* Debugging fields */
7685  if (prog->flag_debugging) {
7686  output_local ("\n/* DEBUG runtime switch */\n");
7687  output_local ("static int\tcob_debugging_mode = 0;\n");
7688  }
7689  if (need_save_exception) {
7690  output_local ("\n/* DEBUG exception code save */\n");
7691  output_local ("int\t\tsave_exception_code = 0;\n");
7692  }
7693 
7694  /* LOCAL storage pointer */
7695  if (prog->local_storage && local_mem) {
7696  output_local ("\n/* LOCAL storage pointer */\n");
7697  output_local ("unsigned char\t\t*cob_local_ptr = NULL;\n");
7699  output_local ("static unsigned char\t*cob_local_save = NULL;\n");
7700  }
7701  }
7702 
7703  /* Call parameter stack */
7704  output_local ("\n/* Call parameters */\n");
7705  if (cb_flag_stack_on_heap || prog->flag_recursive) {
7706  output_local ("cob_field\t\t**cob_procedure_params;\n");
7707  } else {
7708  if (prog->max_call_param) {
7709  i = prog->max_call_param;
7710  } else {
7711  i = 1;
7712  }
7713  output_local ("cob_field\t\t*cob_procedure_params[%d];\n", i);
7714  }
7715 
7716  /* Frame stack */
7717  output_local ("\n/* Perform frame stack */\n");
7718  if (cb_perform_osvs && current_prog->prog_type == CB_PROGRAM_TYPE) {
7719  output_local ("struct cob_frame\t*temp_index;\n");
7720  }
7721  if (cb_flag_stack_check) {
7722  output_local ("struct cob_frame\t*frame_overflow;\n");
7723  }
7724  output_local ("struct cob_frame\t*frame_ptr;\n");
7725  if (cb_flag_stack_on_heap || prog->flag_recursive) {
7726  output_local ("struct cob_frame\t*frame_stack;\n\n");
7727  } else {
7728  output_local ("struct cob_frame\tframe_stack[%d];\n\n",
7729  cb_stack_size);
7730  }
7731 
7732  if (gen_dynamic) {
7733  output_local ("\n/* Dynamic field FUNCTION-ID pointers */\n");
7734  for (inc = 0; inc < gen_dynamic; inc++) {
7735  output_local ("cob_field\t*cob_dyn_%u = NULL;\n",
7736  inc);
7737  }
7738  }
7739 
7740  if (local_base_cache) {
7741  output_local ("\n/* Data storage */\n");
7743  &base_cache_cmp);
7744  for (blp = local_base_cache; blp; blp = blp->next) {
7745  if (blp->f->special_index > 1) {
7746  output_local ("int %s%d;",
7747  CB_PREFIX_BASE, blp->f->id);
7748  } else if (blp->f->special_index) {
7749  output_local ("static int %s%d;",
7750  CB_PREFIX_BASE, blp->f->id);
7751  } else {
7752  output_local ("static cob_u8_t %s%d[%d]%s;",
7753  CB_PREFIX_BASE, blp->f->id,
7754  blp->f->memory_size, COB_ALIGN);
7755  }
7756  output_local ("\t/* %s */\n", blp->f->name);
7757  }
7758  output_local ("\n/* End of data storage */\n\n");
7759  }
7760 
7761  if (local_field_cache) {
7762  /* Switch to local storage file */
7764  output_local ("\n/* Fields */\n");
7766  &field_cache_cmp);
7767  for (k = local_field_cache; k; k = k->next) {
7768  output ("static cob_field %s%d\t= ", CB_PREFIX_FIELD,
7769  k->f->id);
7770  if (!k->f->flag_local) {
7771  output_field (k->x);
7772  } else {
7773  output ("{");
7774  output_size (k->x);
7775  output (", NULL, ");
7776  output_attr (k->x);
7777  output ("}");
7778  }
7779  if (k->f->flag_filler) {
7780  output (";\t/* Implicit FILLER */\n");
7781  } else {
7782  output (";\t/* %s */\n", k->f->name);
7783  }
7784  }
7785  output_local ("\n/* End of fields */\n\n");
7786  /* Switch to main storage file */
7788  }
7789 
7790  /* Skip to next nested program */
7791 
7792  if (prog->next_program) {
7793  codegen (prog->next_program, 1);
7794  return;
7795  }
7796 
7797  /* Finalize the main include file */
7798 
7799 #if 0 /* RXWRXW - GLOBPTR */
7800  output_storage ("\n/* Global variable pointer */\n");
7801  output_storage ("static cob_global\t\t*cob_glob_ptr = NULL;\n");
7802 #endif
7803 
7804  if (!cobc_flag_main && non_nested_count > 1) {
7805  output_storage ("\n/* Module reference count */\n");
7806  output_storage ("static unsigned int\t\tcob_reference_count = 0;\n");
7807  }
7808 
7809  output_storage ("\n/* Module path */\n");
7810  output_storage ("static const char\t\t*cob_module_path = NULL;\n");
7811 
7812  if (globext_cache) {
7813  output_storage ("\n/* GLOBAL EXTERNAL pointers */\n");
7815  for (blp = globext_cache; blp; blp = blp->next) {
7816  output_storage ("static unsigned char\t\t*%s%d = NULL;",
7817  CB_PREFIX_BASE, blp->f->id);
7818  output_storage ("\t/* %s */\n", blp->f->name);
7819  }
7820  }
7821 
7822  if (base_cache) {
7823  output_storage ("\n/* Data storage */\n");
7825  prevprog = NULL;
7826  for (blp = base_cache; blp; blp = blp->next) {
7827  if (blp->curr_prog != prevprog) {
7828  prevprog = blp->curr_prog;
7829  output_storage ("\n/* PROGRAM-ID : %s */\n",
7830  prevprog);
7831  }
7832  if (blp->f->special_index) {
7833  output_storage ("static int %s%d;",
7834  CB_PREFIX_BASE, blp->f->id);
7835  } else {
7836  output_storage ("static cob_u8_t %s%d[%d]%s;",
7837  CB_PREFIX_BASE, blp->f->id,
7838  blp->f->memory_size, COB_ALIGN);
7839  }
7840  output_storage ("\t/* %s */\n", blp->f->name);
7841  }
7842  output_storage ("\n/* End of data storage */\n\n");
7843  }
7844 
7845  /* Attributes */
7846  if (attr_cache || gen_figurative) {
7847  output_storage ("\n/* Attributes */\n\n");
7849  for (j = attr_cache; j; j = j->next) {
7850  output_storage ("static const cob_field_attr %s%d =\t",
7851  CB_PREFIX_ATTR, j->id);
7852  output_storage ("{0x%02x, %3u, %3d, 0x%04x, ",
7853  j->type, j->digits,
7854  j->scale, j->flags);
7855  if (j->pic) {
7856  output_storage ("\"");
7857  for (s = j->pic; *s; s += 5) {
7858  output_storage ("%c\\%03o\\%03o\\%03o\\%03o",
7859  s[0], s[1], s[2], s[3], s[4]);
7860  }
7861  output_storage ("\"");
7862  } else {
7863  output_storage ("NULL");
7864  }
7865  output_storage ("};\n");
7866  }
7867  if (gen_figurative) {
7868  output_storage ("\nstatic const cob_field_attr cob_all_attr = ");
7869  output_storage ("{0x%02x, 0, 0, 0, NULL};\n",
7870  COB_TYPE_ALPHANUMERIC_ALL);
7871  }
7872  output_storage ("\n");
7873  }
7874 
7875  if (field_cache) {
7876  output_storage ("\n/* Fields */\n");
7878  prevprog = NULL;
7879  for (k = field_cache; k; k = k->next) {
7880  if (k->curr_prog != prevprog) {
7881  prevprog = k->curr_prog;
7882  output_storage ("\n/* PROGRAM-ID : %s */\n",
7883  prevprog);
7884  }
7885  output ("static cob_field %s%d\t= ", CB_PREFIX_FIELD,
7886  k->f->id);
7887  if (!k->f->flag_local) {
7888  output_field (k->x);
7889  } else {
7890  output ("{");
7891  output_size (k->x);
7892  output (", NULL, ");
7893  output_attr (k->x);
7894  output ("}");
7895  }
7896  if (k->f->flag_filler) {
7897  output (";\t/* Implicit FILLER */\n");
7898  } else {
7899  output (";\t/* %s */\n", k->f->name);
7900  }
7901  }
7902  output_storage ("\n/* End of fields */\n\n");
7903  }
7904 
7905  /* Literals, figuratives, constants */
7906  if (literal_cache || gen_figurative) {
7907  output_storage ("\n/* Constants */\n");
7909  for (m = literal_cache; m; m = m->next) {
7910 #if 0 /* RXWRXW - Const */
7911  output ("static const cob_fld_union %s%d\t= ",
7912  CB_PREFIX_CONST, m->id);
7913  output ("{");
7914  output_size (m->x);
7915  output (", ");
7916  lp = CB_LITERAL (m->x);
7917  if (CB_TREE_CLASS (m->x) == CB_CLASS_NUMERIC) {
7918  output ("\"%s%s\"", (char *)lp->data,
7919  (lp->sign < 0) ? "-" : (lp->sign > 0) ? "+" : "");
7920  } else {
7921  output_string (lp->data, (int) lp->size, lp->llit);
7922  }
7923  output (", ");
7924  output_attr (m->x);
7925  output ("}");
7926 #else
7927  output ("static const cob_field %s%d\t= ",
7928  CB_PREFIX_CONST, m->id);
7929  output_field (m->x);
7930 #endif
7931  output (";\n");
7932  }
7933  if (gen_figurative) {
7934  output ("\n");
7935  if (gen_figurative & CB_NEED_LOW) {
7936  output ("static cob_field cob_all_low\t= ");
7937  output ("{1, ");
7938  output ("(cob_u8_ptr)\"\\0\", ");
7939  output ("&cob_all_attr};\n");
7940  }
7941  if (gen_figurative & CB_NEED_HIGH) {
7942  output ("static cob_field cob_all_high\t= ");
7943  output ("{1, ");
7944  output ("(cob_u8_ptr)\"\\xff\", ");
7945  output ("&cob_all_attr};\n");
7946  }
7947  if (gen_figurative & CB_NEED_QUOTE) {
7948  output ("static cob_field cob_all_quote\t= ");
7949  output ("{1, ");
7950  if (cb_flag_apostrophe) {
7951  output ("(cob_u8_ptr)\"'\", ");
7952  } else {
7953  output ("(cob_u8_ptr)\"\\\"\", ");
7954  }
7955  output ("&cob_all_attr};\n");
7956  }
7957  if (gen_figurative & CB_NEED_SPACE) {
7958  output ("static cob_field cob_all_space\t= ");
7959  output ("{1, ");
7960  output ("(cob_u8_ptr)\" \", ");
7961  output ("&cob_all_attr};\n");
7962  }
7963  if (gen_figurative & CB_NEED_ZERO) {
7964  output ("static cob_field cob_all_zero\t= ");
7965  output ("{1, ");
7966  output ("(cob_u8_ptr)\"0\", ");
7967  output ("&cob_all_attr};\n");
7968  }
7969  }
7970  output ("\n");
7971  }
7972 
7973  /* Collating tables */
7974  if (gen_alt_ebcdic) {
7975  output_storage ("\n/* ASCII to EBCDIC translate table (restricted) */\n");
7976  output ("static const unsigned char\tcob_a2e[256] = {\n");
7977  /* Restricted table */
7978  output ("\t0x00, 0x01, 0x02, 0x03, 0x1D, 0x19, 0x1A, 0x1B,\n");
7979  output ("\t0x0F, 0x04, 0x16, 0x06, 0x07, 0x08, 0x09, 0x0A,\n");
7980  output ("\t0x0B, 0x0C, 0x0D, 0x0E, 0x1E, 0x1F, 0x1C, 0x17,\n");
7981  output ("\t0x10, 0x11, 0x20, 0x18, 0x12, 0x13, 0x14, 0x15,\n");
7982  output ("\t0x21, 0x27, 0x3A, 0x36, 0x28, 0x30, 0x26, 0x38,\n");
7983  output ("\t0x24, 0x2A, 0x29, 0x25, 0x2F, 0x2C, 0x22, 0x2D,\n");
7984  output ("\t0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A,\n");
7985  output ("\t0x7B, 0x7C, 0x35, 0x2B, 0x23, 0x39, 0x32, 0x33,\n");
7986  output ("\t0x37, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,\n");
7987  output ("\t0x5E, 0x5F, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,\n");
7988  output ("\t0x67, 0x68, 0x69, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,\n");
7989  output ("\t0x70, 0x71, 0x72, 0x7D, 0x6A, 0x7E, 0x7F, 0x31,\n");
7990  output ("\t0x34, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41,\n");
7991  output ("\t0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,\n");
7992  output ("\t0x4A, 0x4B, 0x4C, 0x4E, 0x4F, 0x50, 0x51, 0x52,\n");
7993  output ("\t0x53, 0x54, 0x55, 0x56, 0x2E, 0x60, 0x4D, 0x05,\n");
7994  output ("\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n");
7995  output ("\t0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,\n");
7996  output ("\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n");
7997  output ("\t0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,\n");
7998  output ("\t0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,\n");
7999  output ("\t0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,\n");
8000  output ("\t0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,\n");
8001  output ("\t0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,\n");
8002  output ("\t0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,\n");
8003  output ("\t0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,\n");
8004  output ("\t0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,\n");
8005  output ("\t0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,\n");
8006  output ("\t0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,\n");
8007  output ("\t0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,\n");
8008  output ("\t0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,\n");
8009  output ("\t0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF\n");
8010  output ("};\n");
8011  output_storage ("\n");
8012  }
8013  if (gen_full_ebcdic) {
8014  output_storage ("\n/* ASCII to EBCDIC table */\n");
8015  output ("static const unsigned char\tcob_ascii_ebcdic[256] = {\n");
8016  output ("\t0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,\n");
8017  output ("\t0x16, 0x05, 0x25, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\n");
8018  output ("\t0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,\n");
8019  output ("\t0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,\n");
8020  output ("\t0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,\n");
8021  output ("\t0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,\n");
8022  output ("\t0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,\n");
8023  output ("\t0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,\n");
8024  output ("\t0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,\n");
8025  output ("\t0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,\n");
8026  output ("\t0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,\n");
8027  output ("\t0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,\n");
8028  output ("\t0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n");
8029  output ("\t0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,\n");
8030  output ("\t0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,\n");
8031  output ("\t0xA7, 0xA8, 0xA9, 0xC0, 0x6A, 0xD0, 0xA1, 0x07,\n");
8032  output ("\t0x68, 0xDC, 0x51, 0x42, 0x43, 0x44, 0x47, 0x48,\n");
8033  output ("\t0x52, 0x53, 0x54, 0x57, 0x56, 0x58, 0x63, 0x67,\n");
8034  output ("\t0x71, 0x9C, 0x9E, 0xCB, 0xCC, 0xCD, 0xDB, 0xDD,\n");
8035  output ("\t0xDF, 0xEC, 0xFC, 0xB0, 0xB1, 0xB2, 0x3E, 0xB4,\n");
8036  output ("\t0x45, 0x55, 0xCE, 0xDE, 0x49, 0x69, 0x9A, 0x9B,\n");
8037  output ("\t0xAB, 0x9F, 0xBA, 0xB8, 0xB7, 0xAA, 0x8A, 0x8B,\n");
8038  output ("\t0xB6, 0xB5, 0x62, 0x4F, 0x64, 0x65, 0x66, 0x20,\n");
8039  output ("\t0x21, 0x22, 0x70, 0x23, 0x72, 0x73, 0x74, 0xBE,\n");
8040  output ("\t0x76, 0x77, 0x78, 0x80, 0x24, 0x15, 0x8C, 0x8D,\n");
8041  output ("\t0x8E, 0x41, 0x06, 0x17, 0x28, 0x29, 0x9D, 0x2A,\n");
8042  output ("\t0x2B, 0x2C, 0x09, 0x0A, 0xAC, 0x4A, 0xAE, 0xAF,\n");
8043  output ("\t0x1B, 0x30, 0x31, 0xFA, 0x1A, 0x33, 0x34, 0x35,\n");
8044  output ("\t0x36, 0x59, 0x08, 0x38, 0xBC, 0x39, 0xA0, 0xBF,\n");
8045  output ("\t0xCA, 0x3A, 0xFE, 0x3B, 0x04, 0xCF, 0xDA, 0x14,\n");
8046  output ("\t0xE1, 0x8F, 0x46, 0x75, 0xFD, 0xEB, 0xEE, 0xED,\n");
8047  output ("\t0x90, 0xEF, 0xB3, 0xFB, 0xB9, 0xEA, 0xBB, 0xFF\n");
8048  output ("};\n");
8049  if (gen_full_ebcdic > 1) {
8050  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8051  output
8052  ("static cob_field f_ascii_ebcdic = { 256, (cob_u8_ptr)cob_ascii_ebcdic, &%s%d };\n",
8053  CB_PREFIX_ATTR, i);
8054  }
8055  output_storage ("\n");
8056  }
8057  if (gen_ebcdic_ascii) {
8058  output_storage ("\n/* EBCDIC to ASCII table */\n");
8059  output ("static const unsigned char\tcob_ebcdic_ascii[256] = {\n");
8060  output ("\t0x00, 0x01, 0x02, 0x03, 0xEC, 0x09, 0xCA, 0x7F,\n");
8061  output ("\t0xE2, 0xD2, 0xD3, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\n");
8062  output ("\t0x10, 0x11, 0x12, 0x13, 0xEF, 0xC5, 0x08, 0xCB,\n");
8063  output ("\t0x18, 0x19, 0xDC, 0xD8, 0x1C, 0x1D, 0x1E, 0x1F,\n");
8064  output ("\t0xB7, 0xB8, 0xB9, 0xBB, 0xC4, 0x0A, 0x17, 0x1B,\n");
8065  output ("\t0xCC, 0xCD, 0xCF, 0xD0, 0xD1, 0x05, 0x06, 0x07,\n");
8066  output ("\t0xD9, 0xDA, 0x16, 0xDD, 0xDE, 0xDF, 0xE0, 0x04,\n");
8067  output ("\t0xE3, 0xE5, 0xE9, 0xEB, 0x14, 0x15, 0x9E, 0x1A,\n");
8068  output ("\t0x20, 0xC9, 0x83, 0x84, 0x85, 0xA0, 0xF2, 0x86,\n");
8069  output ("\t0x87, 0xA4, 0xD5, 0x2E, 0x3C, 0x28, 0x2B, 0xB3,\n");
8070  output ("\t0x26, 0x82, 0x88, 0x89, 0x8A, 0xA1, 0x8C, 0x8B,\n");
8071  output ("\t0x8D, 0xE1, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,\n");
8072  output ("\t0x2D, 0x2F, 0xB2, 0x8E, 0xB4, 0xB5, 0xB6, 0x8F,\n");
8073  output ("\t0x80, 0xA5, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,\n");
8074  output ("\t0xBA, 0x90, 0xBC, 0xBD, 0xBE, 0xF3, 0xC0, 0xC1,\n");
8075  output ("\t0xC2, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,\n");
8076  output ("\t0xC3, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,\n");
8077  output ("\t0x68, 0x69, 0xAE, 0xAF, 0xC6, 0xC7, 0xC8, 0xF1,\n");
8078  output ("\t0xF8, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,\n");
8079  output ("\t0x71, 0x72, 0xA6, 0xA7, 0x91, 0xCE, 0x92, 0xA9,\n");
8080  output ("\t0xE6, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,\n");
8081  output ("\t0x79, 0x7A, 0xAD, 0xA8, 0xD4, 0x5B, 0xD6, 0xD7,\n");
8082  output ("\t0x9B, 0x9C, 0x9D, 0xFA, 0x9F, 0xB1, 0xB0, 0xAC,\n");
8083  output ("\t0xAB, 0xFC, 0xAA, 0xFE, 0xE4, 0x5D, 0xBF, 0xE7,\n");
8084  output ("\t0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,\n");
8085  output ("\t0x48, 0x49, 0xE8, 0x93, 0x94, 0x95, 0xA2, 0xED,\n");
8086  output ("\t0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,\n");
8087  output ("\t0x51, 0x52, 0xEE, 0x96, 0x81, 0x97, 0xA3, 0x98,\n");
8088  output ("\t0x5C, 0xF0, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n");
8089  output ("\t0x59, 0x5A, 0xFD, 0xF5, 0x99, 0xF7, 0xF6, 0xF9,\n");
8090  output ("\t0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,\n");
8091  output ("\t0x38, 0x39, 0xDB, 0xFB, 0x9A, 0xF4, 0xEA, 0xFF\n");
8092  output ("};\n");
8093  if (gen_ebcdic_ascii > 1) {
8094  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8095  output
8096  ("static cob_field f_ebcdic_ascii = { 256, (cob_u8_ptr)cob_ebcdic_ascii, &%s%d };\n",
8097  CB_PREFIX_ATTR, i);
8098  }
8099  output_storage ("\n");
8100  }
8101  if (gen_native) {
8102  output_storage ("\n/* NATIVE table */\n");
8103  output ("static const unsigned char\tcob_native[256] = {\n");
8104  output ("\t0, 1, 2, 3, 4, 5, 6, 7,\n");
8105  output ("\t8, 9, 10, 11, 12, 13, 14, 15,\n");
8106  output ("\t16, 17, 18, 19, 20, 21, 22, 23,\n");
8107  output ("\t24, 25, 26, 27, 28, 29, 30, 31,\n");
8108  output ("\t32, 33, 34, 35, 36, 37, 38, 39,\n");
8109  output ("\t40, 41, 42, 43, 44, 45, 46, 47,\n");
8110  output ("\t48, 49, 50, 51, 52, 53, 54, 55,\n");
8111  output ("\t56, 57, 58, 59, 60, 61, 62, 63,\n");
8112  output ("\t64, 65, 66, 67, 68, 69, 70, 71,\n");
8113  output ("\t72, 73, 74, 75, 76, 77, 78, 79,\n");
8114  output ("\t80, 81, 82, 83, 84, 85, 86, 87,\n");
8115  output ("\t88, 89, 90, 91, 92, 93, 94, 95,\n");
8116  output ("\t96, 97, 98, 99, 100, 101, 102, 103,\n");
8117  output ("\t104, 105, 106, 107, 108, 109, 110, 111,\n");
8118  output ("\t112, 113, 114, 115, 116, 117, 118, 119,\n");
8119  output ("\t120, 121, 122, 123, 124, 125, 126, 127,\n");
8120  output ("\t128, 129, 130, 131, 132, 133, 134, 135,\n");
8121  output ("\t136, 137, 138, 139, 140, 141, 142, 143,\n");
8122  output ("\t144, 145, 146, 147, 148, 149, 150, 151,\n");
8123  output ("\t152, 153, 154, 155, 156, 157, 158, 159,\n");
8124  output ("\t160, 161, 162, 163, 164, 165, 166, 167,\n");
8125  output ("\t168, 169, 170, 171, 172, 173, 174, 175,\n");
8126  output ("\t176, 177, 178, 179, 180, 181, 182, 183,\n");
8127  output ("\t184, 185, 186, 187, 188, 189, 190, 191,\n");
8128  output ("\t192, 193, 194, 195, 196, 197, 198, 199,\n");
8129  output ("\t200, 201, 202, 203, 204, 205, 206, 207,\n");
8130  output ("\t208, 209, 210, 211, 212, 213, 214, 215,\n");
8131  output ("\t216, 217, 218, 219, 220, 221, 222, 223,\n");
8132  output ("\t224, 225, 226, 227, 228, 229, 230, 231,\n");
8133  output ("\t232, 233, 234, 235, 236, 237, 238, 239,\n");
8134  output ("\t240, 241, 242, 243, 244, 245, 246, 247,\n");
8135  output ("\t248, 249, 250, 251, 252, 253, 254, 255\n");
8136  output ("};\n");
8137  if (gen_native > 1) {
8138  i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
8139  output
8140  ("static cob_field f_native = { 256, (cob_u8_ptr)cob_native, &%s%d };\n",
8141  CB_PREFIX_ATTR, i);
8142  }
8143  output_storage ("\n");
8144  }
8145 
8146  /* Strings */
8147  if (string_cache) {
8148  output_storage ("\n/* Strings */\n");
8150  for (stp = string_cache; stp; stp = stp->next) {
8151  output ("static const char %s%d[]\t= \"%s\";\n",
8152  CB_PREFIX_STRING, stp->id, stp->text);
8153  }
8154  output_storage ("\n");
8155  }
8156 
8157  /* Optimizer output */
8158  for (optidx = COB_OPTIM_MIN; optidx < COB_OPTIM_MAX; ++optidx) {
8159  if (optimize_defs[optidx]) {
8160  cob_gen_optim (optidx);
8161  output_storage ("\n");
8162  }
8163  }
8164 }
void configuration_error ( const char *  ,
const int  ,
const char *  ,
  ... 
)

References _, and conf_error_displayed.

Referenced by cb_config_entry(), cb_load_conf(), invalid_value(), process_command_line(), and unsupported_value().

144 {
145  va_list args;
146 
147  if (!conf_error_displayed) {
149  fputs (_("Configuration Error"), stderr);
150  putc ('\n', stderr);
151  }
152 
153  if (fname) {
154  if (line) {
155  fprintf (stderr, "%s:%d: ", fname, line);
156  } else {
157  fprintf (stderr, "%s: ", fname);
158  }
159  } else {
160  fputs ("cb_conf: ", stderr);
161  }
162 
163  va_start(args, fmt);
164  vfprintf (stderr, fmt, args);
165  va_end(args);
166 
167  putc ('\n', stderr);
168  fflush (stderr);
169 }
static void count_lines ( const char *  )
static
static const char* dcnpgettext_expr ( const char *  domain,
const char *  msgctxt,
const char *  msgid,
const char *  msgid_plural,
unsigned long int  n,
int  category 
)
static
242  {
243  integer_is_label = 1;
244  last_token_is_dot = 0;
245  } else {
246  integer_is_label = 0;
247  }
248 %}
249 
250 
251 <*>^[ ]?"#DEFLIT".*\n {
253 }
254 
255 <*>^[ ]?"#OPTION".*\n {
256  scan_options (yytext, 1);
257 }
258 
259 <*>^[ ]?"#DEFOFF".*\n {
260  scan_options (yytext, 2);
261 }
262 
263 <*>^[ ]?"#DEFENV".*\n {
264  scan_options (yytext, 3);
265 }
266 
267 <*>\n {
268  cb_source_line++;
269 }
static const char* dcpgettext_expr ( const char *  domain,
const char *  msgctxt,
const char *  msgid,
int  category 
)
static
231  {
void finalize_file ( struct cb_file ,
struct cb_field  
)
2268 {
2269  struct cb_field *p;
2270  struct cb_field *v;
2271  struct cb_alt_key *cbak;
2272  cb_tree l;
2273  cb_tree x;
2274 
2275  /* stdin/stderr and LINE ADVANCING are L/S */
2276  if (f->special || f->flag_line_adv) {
2277  f->organization = COB_ORG_LINE_SEQUENTIAL;
2278  }
2279  if (f->flag_fileid && !f->assign) {
2280  f->assign = cb_build_alphanumeric_literal (f->name,
2281  strlen (f->name));
2282  }
2283 
2284  if (f->key && f->organization == COB_ORG_INDEXED &&
2285  (l = cb_ref (f->key)) != cb_error_node) {
2286  v = cb_field_founder (CB_FIELD_PTR (l));
2287  for (p = records; p; p = p->sister) {
2288  if (p == v) {
2289  break;
2290  }
2291  }
2292  if (!p) {
2293  cb_error (_("Invalid KEY item '%s'"),
2294  CB_FIELD_PTR (l)->name);
2295  }
2296  }
2297  if (f->alt_key_list) {
2298  for (cbak = f->alt_key_list; cbak; cbak = cbak->next) {
2299  l = cb_ref (cbak->key);
2300  if (l == cb_error_node) {
2301  continue;
2302  }
2303  v = cb_field_founder (CB_FIELD_PTR (l));
2304  for (p = records; p; p = p->sister) {
2305  if (p == v) {
2306  break;
2307  }
2308  }
2309  if (!p) {
2310  cb_error (_("Invalid KEY item '%s'"),
2311  CB_FIELD_PTR (l)->name);
2312  }
2313  }
2314  }
2315 
2316  /* Check the record size if it is limited */
2317  for (p = records; p; p = p->sister) {
2318  if (f->record_min > 0) {
2319  if (p->size < f->record_min) {
2320  cb_error (_("Record size too small '%s'"),
2321  p->name);
2322  }
2323  }
2324  if (f->record_max > 0) {
2325  if (p->size > f->record_max) {
2326  cb_error (_("Record size too large '%s' (%d)"),
2327  p->name, p->size);
2328  }
2329  }
2330  }
2331 
2332  /* Compute the record size */
2333  if (f->record_min == 0) {
2334  if (records) {
2335  f->record_min = records->size;
2336  } else {
2337  f->record_min = 0;
2338  }
2339  }
2340  for (p = records; p; p = p->sister) {
2341  v = cb_field_variable_size (p);
2342  if (v && v->offset + v->size * v->occurs_min < f->record_min) {
2343  f->record_min = v->offset + v->size * v->occurs_min;
2344  }
2345  if (p->size < f->record_min) {
2346  f->record_min = p->size;
2347  }
2348  if (p->size > f->record_max) {
2349  f->record_max = p->size;
2350  }
2351  }
2352 
2353  if (f->record_max > MAX_FD_RECORD) {
2354  cb_error (_("Record size exceeds maximum allowed (%d) - File '%s'"),
2355  MAX_FD_RECORD, f->name);
2356  }
2357 
2358  if (f->same_clause) {
2359  for (l = current_program->file_list; l; l = CB_CHAIN (l)) {
2360  if (CB_FILE (CB_VALUE (l))->same_clause == f->same_clause) {
2361  if (CB_FILE (CB_VALUE (l))->flag_finalized) {
2362  if (f->record_max > CB_FILE (CB_VALUE (l))->record->memory_size) {
2363  CB_FILE (CB_VALUE (l))->record->memory_size =
2364  f->record_max;
2365  }
2366  f->record = CB_FILE (CB_VALUE (l))->record;
2367  for (p = records; p; p = p->sister) {
2368  p->file = f;
2369  p->redefines = f->record;
2370  }
2371  for (p = f->record->sister; p; p = p->sister) {
2372  if (!p->sister) {
2373  p->sister = records;
2374  break;
2375  }
2376  }
2377  f->flag_finalized = 1;
2378  return;
2379  }
2380  }
2381  }
2382  }
2383  /* Create record */
2384  if (f->record_max == 0) {
2385  f->record_max = 32;
2386  f->record_min = 32;
2387  }
2388  if (f->organization == COB_ORG_LINE_SEQUENTIAL) {
2389  f->record_min = 0;
2390  }
2391  if (!scratch_buff) {
2392  scratch_buff = cobc_main_malloc ((size_t)COB_MINI_BUFF);
2393  }
2394  snprintf (scratch_buff, (size_t)COB_MINI_MAX, "%s Record", f->name);
2396  f->record_max));
2397  f->record->sister = records;
2398  f->record->count++;
2399  if (f->flag_external) {
2401  f->record->flag_external = 1;
2402  }
2403 
2404  for (p = records; p; p = p->sister) {
2405  p->file = f;
2406  p->redefines = f->record;
2407 #if 1 /* RXWRXW - Global/External */
2408  if (p->flag_is_global) {
2409  f->record->flag_is_global = 1;
2410  }
2411 #endif
2412  }
2413  f->flag_finalized = 1;
2414  if (f->linage) {
2415  snprintf (scratch_buff, (size_t)COB_MINI_MAX,
2416  "LINAGE-COUNTER %s", f->name);
2418  CB_FIELD (x)->usage = CB_USAGE_UNSIGNED_INT;
2419  CB_FIELD (x)->values = CB_LIST_INIT (cb_zero);
2420  CB_FIELD (x)->count++;
2421  cb_validate_field (CB_FIELD (x));
2422  f->linage_ctr = cb_build_field_reference (CB_FIELD (x), NULL);
2424  }
2425 }
void group_error ( cb_tree  ,
const char *   
)
345 {
346  cb_error_x (x, _("Group item '%s' cannot have %s clause"),
347  cb_name (x), clause);
348 }
void level_except_error ( cb_tree  ,
const char *   
)
388 {
389  const char *s;
390  const struct cb_field *f;
391 
392  s = cb_name (x);
393  f = CB_FIELD_PTR (x);
394  if (f->flag_item_78) {
395  cb_error_x (x, _("Constant item '%s' can only have a %s clause"),
396  s, clause);
397  } else {
398  cb_error_x (x, _("Level %02d item '%s' can only have a %s clause"),
399  f->level,
400  s, clause);
401  }
402 }
void level_redundant_error ( cb_tree  ,
const char *   
)
352 {
353  const char *s;
354  const struct cb_field *f;
355 
356  s = cb_name (x);
357  f = CB_FIELD_PTR (x);
358  if (f->flag_item_78) {
359  cb_error_x (x, _("Constant item '%s' cannot have a %s clause"),
360  s, clause);
361  } else {
362  cb_error_x (x, _("Level %02d item '%s' cannot have a %s clause"),
363  f->level,
364  s, clause);
365  }
366 }
void level_require_error ( cb_tree  ,
const char *   
)
370 {
371  const char *s;
372  const struct cb_field *f;
373 
374  s = cb_name (x);
375  f = CB_FIELD_PTR (x);
376  if (f->flag_item_78) {
377  cb_error_x (x, _("Constant item '%s' requires a %s clause"),
378  s, clause);
379  } else {
380  cb_error_x (x, _("Level %02d item '%s' requires a %s clause"),
381  f->level,
382  s, clause);
383  }
384 }
struct cb_intrinsic_table* lookup_intrinsic ( const char *  ,
const int  ,
const int   
)
read
2643 {
2644  struct cb_intrinsic_table *cbp;
2645  struct noreserve *nr;
2646 
2647  if (unlikely(cobc_nores_base && checkres)) {
2648  for (nr = cobc_nores_base; nr; nr = nr->next) {
2649  if (strcasecmp (name, nr->noresword) == 0) {
2650  return NULL;
2651  }
2652  }
2653  }
2654  cbp = bsearch (name, function_list, NUM_INTRINSICS,
2655  sizeof (struct cb_intrinsic_table), intrinsic_comp);
2656  if (cbp && (checkimpl || cbp->implemented)) {
2657  return cbp;
2658  }
2659  return NULL;
2660 }
struct cobc_reserved* lookup_reserved_word ( const char *  )
read
2568 {
2569  struct cobc_reserved *p;
2570  struct noreserve *nr;
2571 
2572  p = bsearch (name, reserved_words, NUM_RESERVED_WORDS,
2573  sizeof (struct cobc_reserved), reserve_comp);
2574  if (!p) {
2575  return NULL;
2576  }
2577 
2578  /* Allow obsolete/unimplemented 85 keywords as user names */
2579  if (!p->token && !cb_cobol85_reserved) {
2580  return NULL;
2581  }
2582 
2583  /* Check if the configuration has unreserved the word */
2584  for (nr = cobc_nores_base; nr; nr = nr->next) {
2585  if (strcasecmp (name, nr->noresword) == 0) {
2586  return NULL;
2587  }
2588  }
2589 
2590  /* Check word is implemented */
2591  if (unlikely(p->token <= 0)) {
2592  /* Not implemented - If context sensitive, no error */
2593  if (!p->context_sens) {
2594  cb_error (_("'%s' reserved word, but not supported"), name);
2595  }
2596  return NULL;
2597  }
2598 
2599  /* Special actions / Context sensitive */
2600  if (p->context_set) {
2601  if (unlikely(p->context_test)) {
2602  /* Dependent words */
2603  if (!(cobc_cs_check & p->context_test)) {
2604  return p;
2605  }
2606  }
2607  cobc_cs_check |= p->context_set;
2608  return p;
2609  }
2610 
2611  if (p->context_test) {
2612 #if 0 /* RXWRXW - CS check */
2613  if (!(cobc_cs_check & p->context_test)) {
2614 #endif
2615  if ((cobc_cs_check & p->context_test) != p->context_test) {
2616  return NULL;
2617  }
2618  if (!cobc_in_procedure) {
2619  cobc_cs_check = 0;
2620  }
2621  return p;
2622  }
2623 
2624  if (p->token == FUNCTION_ID) {
2625  cobc_cs_check = 0;
2626  cobc_force_literal = 1;
2627  } else if (p->token == INTRINSIC) {
2628  if (!cobc_in_repository) {
2629  return NULL;
2630  }
2631  } else if (p->token == PROGRAM_ID) {
2633  cobc_force_literal = 1;
2634  } else if (p->token == REPOSITORY) {
2635  cobc_in_repository = 1;
2636  }
2637 
2638  return p;
2639 }
cb_tree lookup_system_name ( const char *  )
2546 {
2547  size_t i;
2548 
2549  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
2550  if (cob_strcasecmp (name, system_table[i].name) == 0) {
2551  return cb_build_system_name (system_table[i].category,
2552  system_table[i].token);
2553  }
2554  }
2555  if (cb_flag_syntax_extension) {
2556  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
2557  if (cob_strcasecmp (name, ext_system_table[i].name) == 0) {
2558  return cb_build_system_name (ext_system_table[i].category,
2559  ext_system_table[i].token);
2560  }
2561  }
2562  }
2563  return NULL;
2564 }
static const char* npgettext_aux ( const char *  domain,
const char *  msg_ctxt_id,
const char *  msgid,
const char *  msgid_plural,
unsigned long int  n,
int  category 
)
static
231  {
static const char* pgettext_aux ( const char *  domain,
const char *  msg_ctxt_id,
const char *  msgid,
int  category 
)
static
140  {
141  ['-'] = 1,
142  ['0'] = 1,
143  ['1'] = 1,
144  ['2'] = 1,
void plex_action_directive ( const unsigned  int,
const unsigned  int 
)

References _, cb_plex_error(), cb_source_line, plex_stack::cmd, COBC_ABORT, cobc_abort_pr(), plex_stack::cond, plex_stack::line, PLEX_ACT_ELIF, PLEX_ACT_ELSE, PLEX_ACT_END, PLEX_ACT_IF, PLEX_COND_DEPTH, plex_cond_stack, plex_nest_depth, and plex_stack::skip.

4563 {
4564  unsigned int n;
4565 
4566  /* Action IF/ELSE/END-IF/ELIF */
4567  switch (cmdtype) {
4568  case PLEX_ACT_IF:
4569  /* Push stack - First occurrence is dummy */
4570  if (++plex_nest_depth >= PLEX_COND_DEPTH) {
4571  cobc_abort_pr (_("Directive nest depth exceeded - %d"),
4572  PLEX_COND_DEPTH);
4573  COBC_ABORT ();
4574  }
4576  /* Intersection with previous - first is always 0 */
4577  n = plex_cond_stack[plex_nest_depth - 1].skip | !is_true;
4581  plex_skip_input = n;
4582  return;
4583  case PLEX_ACT_ELSE:
4584  /* Must have an associated IF/ELIF */
4585  if (!plex_nest_depth ||
4586  plex_cond_stack[plex_nest_depth].cmd != 1) {
4588  _("ELSE directive without matching IF/ELIF"));
4589  return;
4590  }
4592  /* Reverse any IF/ELIF condition */
4596  /* Intersection with previous */
4598  return;
4599  case PLEX_ACT_END:
4600  /* Must have an associated IF/ELIF/ELSE */
4601  if (!plex_nest_depth ||
4604  _("END-IF directive without matching IF/ELIF/ELSE"));
4605  return;
4606  }
4611  /* Pop stack - set skip to previous */
4612  plex_nest_depth--;
4614  return;
4615  case PLEX_ACT_ELIF:
4616  /* Must have an associated IF/ELIF */
4617  if (!plex_nest_depth ||
4618  plex_cond_stack[plex_nest_depth].cmd != 1) {
4620  _("ELIF directive without matching IF/ELIF"));
4621  return;
4622  }
4624  if (plex_cond_stack[plex_nest_depth].cond) {
4625  /* Previous IF or one of previous ELIF was true */
4626  /* Set to skip */
4627  n = 1U;
4628  } else if (is_true) {
4629  /* Condition is true */
4631  n = 0;
4632  } else {
4633  /* Set to skip */
4634  n = 1U;
4635  }
4637  /* Intersection with previous */
4639  return;
4640  default:
4641  cobc_abort_pr (_("Invalid internal case - %u"),
4642  cmdtype);
4643  COBC_ABORT ();
4644  }
4645 }
void plex_call_destroy ( void  )

References pplex_destroy().

Referenced by preprocess().

4557 {
4558  (void)pplex_destroy ();
4559 }
void plex_clear_all ( void  )

References cobc_free(), and NULL.

Referenced by main().

4544 {
4545  if (plexbuff1) {
4546  cobc_free (plexbuff1);
4547  plexbuff1 = NULL;
4548  }
4549  if (plexbuff2) {
4550  cobc_free (plexbuff2);
4551  plexbuff2 = NULL;
4552  }
4553 }
void plex_clear_vars ( void  )

References plex_cond_stack.

Referenced by preprocess().

4533 {
4534  /* Reset variables */
4535  plex_skip_input = 0;
4536  plex_nest_depth = 0;
4537  memset (plex_cond_stack, 0, sizeof(plex_cond_stack));
4539  comment_allowed = 1;
4540 }
void pp_set_replace_list ( struct cb_replace_list ,
const cob_u32_t   
)

References base_replace_list, cb_replace_list::last, cb_replace_list::next, NULL, and cb_replace_list::prev.

4376 {
4377  /* Handle REPLACE verb */
4378  if (!list) {
4379  /* REPLACE [LAST] OFF */
4380  if (!is_pushpop) {
4382  return;
4383  }
4384  if (!base_replace_list) {
4385  return;
4386  }
4388  return;
4389  }
4390  /* REPLACE [ALSO] ... */
4391  if (base_replace_list && is_pushpop) {
4392  list->last->next = base_replace_list;
4393  list->prev = base_replace_list;
4394  } else {
4395  list->prev = NULL;
4396  }
4397  base_replace_list = list;
4398 }
int ppcopy ( const char *  ,
const char *  ,
struct cb_replace_list  
)

References _, cb_error(), cb_extension_list, cb_include_list, COB_SMALL_MAX, cb_text_list::next, plexbuff1, ppopen(), R_OK, and cb_text_list::text.

4485 {
4486  struct cb_text_list *il;
4487  struct cb_text_list *el;
4488  const char *s;
4489 
4490  /* Locate and open COPY file */
4491  if (lib) {
4492  snprintf (plexbuff1, (size_t)COB_SMALL_MAX, "%s/%s", lib, name);
4493  s = plexbuff1;
4494  } else {
4495  s = name;
4496  }
4497 
4498  /* Find the file */
4499  if (access (s, R_OK) == 0) {
4500  return ppopen (s, replace_list);
4501  }
4502 
4503  for (el = cb_extension_list; el; el = el->next) {
4504  snprintf (plexbuff2, (size_t)COB_SMALL_MAX, "%s%s", s, el->text);
4505  if (access (plexbuff2, R_OK) == 0) {
4506  return ppopen (plexbuff2, replace_list);
4507  }
4508  }
4509 
4510  if (*s != '/') {
4511  for (il = cb_include_list; il; il = il->next) {
4512  for (el = cb_extension_list; el; el = el->next) {
4513  snprintf (plexbuff2, (size_t)COB_SMALL_MAX,
4514  "%s/%s%s", il->text, name, el->text);
4515  if (access (plexbuff2, R_OK) == 0) {
4516  return ppopen (plexbuff2, replace_list);
4517  }
4518  }
4519  }
4520  }
4521  cb_error ("%s: %s", name, _("No such file or directory"));
4522  return -1;
4523 }
int ppopen ( const char *  ,
struct cb_replace_list  
)

References _, copy_info::buffer, cb_error(), cb_source_file, cb_source_format, cb_source_line, cobc_malloc(), cobc_strdup(), copy_stack, current_replace_list, copy_info::dname, errorcount, copy_info::file, cb_replace_list::last, copy_info::line, cb_replace_list::next, copy_info::next, p, pp_create_buffer(), ppin, copy_info::quotation_mark, quotation_mark, copy_info::replacing, replacing_list, copy_info::source_format, switch_to_buffer(), YY_BUF_SIZE, and YY_CURRENT_BUFFER.

Referenced by ppcopy(), and preprocess().

4402 {
4403  struct copy_info *p;
4404  char *s;
4405  char *dname;
4406 
4407 #ifdef _WIN32
4408  unsigned char bom[4];
4409 #endif
4410 
4411  if (ppin) {
4412  for (; newline_count > 0; newline_count--) {
4413  ungetc ('\n', ppin);
4414  }
4415  }
4416 
4417  /* Open copy/source file */
4418 #ifdef __OS400__
4419  ppin = fopen (name, "r");
4420 #else
4421  ppin = fopen (name, "rb");
4422 #endif
4423  if (!ppin) {
4424  if (cb_source_file) {
4425  cb_error ("%s: %s", name,
4426  _("No such file or directory"));
4427  } else {
4428  fflush (stderr);
4429  fprintf (stderr, "%s: %s", name,
4430  _("No such file or directory"));
4431  fflush (stderr);
4432  errorcount++;
4433  }
4434  return -1;
4435  }
4436 #ifdef _WIN32
4437  /* Check for BOM */
4438  if (fread (bom, 3, 1, ppin) == 1) {
4439  if (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF) {
4440  rewind (ppin);
4441  }
4442  } else {
4443  rewind (ppin);
4444  }
4445 #endif
4446 
4447  /* Preserve the current buffer */
4448  p = cobc_malloc (sizeof (struct copy_info));
4449  p->file = cb_source_file;
4451 
4452  /* Save variables */
4454  p->line = cb_source_line;
4457 
4458  p->next = copy_stack;
4459  copy_stack = p;
4460 
4461  /* Set replacing list */
4462  if (replacing_list) {
4463  if (current_replace_list) {
4464  replacing_list->last->next = current_replace_list;
4466  }
4468  }
4469 
4470  dname = cobc_strdup (name);
4471  p->dname = dname;
4472  for (s = dname; *s; ++s) {
4473  if (*s == '\\') {
4474  *s = '/';
4475  }
4476  }
4477 
4478  /* Switch to new buffer */
4480  return 0;
4481 }
int ppparse ( void  )

Referenced by preprocess().

void ppparse_clear_vars ( const struct cb_define_struct )

References cb_define_struct::name, cb_define_struct::next, NULL, ppp_define_add(), and cb_define_struct::value.

Referenced by preprocess().

495 {
496  const struct cb_define_struct *q;
497 
499  /* Set standard DEFINE's */
500  if (cb_perform_osvs) {
502  "PERFORM-TYPE",
503  "'OSVS'", 0);
504  } else {
506  "PERFORM-TYPE",
507  "'MF'", 0);
508  }
509  if (cb_ebcdic_sign) {
511  "SIGN",
512  "'EBCDIC'", 0);
513  } else {
515  "SIGN",
516  "'ASCII'", 0);
517  }
518 #ifdef WORDS_BIGENDIAN
520  "ENDIAN",
521  "'BIG'", 0);
522 #else
524  "ENDIAN",
525  "'LITTLE'", 0);
526 #endif
527 #if ' ' == 0x20
529  "CHARSET",
530  "'ASCII'", 0);
531 #elif ' ' == 0x40
533  "CHARSET",
534  "'EBCDIC'", 0);
535 #else
537  "CHARSET",
538  "'UNKNOWN'", 0);
539 #endif
540  /* Set DEFINE's from '-D' option(s) */
541  for (q = p; q; q = q->next) {
543  q->name,
544  q->value, 0);
545  }
546 }
void ppparse_error ( const char *  )

References cb_plex_error().

4527 {
4529 }
COB_EXPIMP void print_info ( void  )
4178  {
4179  char buff[16];
4180  char *s;
4181 
4182  print_version ();
4183  putchar ('\n');
4184  puts (_("Build information"));
4185  var_print (_("Build environment"), COB_BLD_BUILD, "", 0);
4186  var_print ("CC", COB_BLD_CC, "", 0);
4187  var_print ("CPPFLAGS", COB_BLD_CPPFLAGS, "", 0);
4188  var_print ("CFLAGS", COB_BLD_CFLAGS, "", 0);
4189  var_print ("LD", COB_BLD_LD, "", 0);
4190  var_print ("LDFLAGS", COB_BLD_LDFLAGS, "", 0);
4191  putchar ('\n');
4192  printf (_("C version %s%s"), OC_C_VERSION_PRF, OC_C_VERSION);
4193  putchar ('\n');
4194  puts (_("GNU Cobol information"));
4195 
4196 // if ((s = getenv ("COB_LIBRARY_PATH")) != NULL) {
4197 // var_print ("COB_LIBRARY_PATH", s, "", 1);
4198 // }
4199  var_print ("COB_MODULE_EXT", COB_MODULE_EXT, "", 0);
4200  var_print ("COB_OBJECT_EXT", COB_OBJECT_EXT, "", 0);
4201  var_print ("COB_EXEEXT", COB_EXEEXT, "", 0);
4202 
4203 #if defined(USE_LIBDL) || defined(_WIN32)
4204  var_print (_("Dynamic loading"), _("System"), "", 0);
4205 #else
4206  var_print (_("Dynamic loading"), _("Libtool"), "", 0);
4207 #endif
4208 
4209 #ifdef COB_PARAM_CHECK
4210  var_print ("\"CBL_\" param check", _("Enabled"), "", 0);
4211 #else
4212  var_print ("\"CBL_\" param check", _("Disabled"), "", 0);
4213 #endif
4214 
4215  snprintf (buff, sizeof(buff), "%d", WITH_VARSEQ);
4216  var_print (_("Variable format"), buff, "", 0);
4217  if ((s = getenv ("COB_VARSEQ_FORMAT")) != NULL) {
4218  var_print ("COB_VARSEQ_FORMAT", s, "", 1);
4219  }
4220 
4221 #ifdef COB_LI_IS_LL
4222  var_print ("BINARY-C-LONG", _("8 bytes"), "", 0);
4223 #else
4224  var_print ("BINARY-C-LONG", _("4 bytes"), "", 0);
4225 #endif
4226 
4227 #ifdef WITH_SEQRA_EXTFH
4228  var_print (_("Sequential handler"), _("External"), "", 0);
4229 #else
4230  var_print (_("Sequential handler"), _("Internal"), "", 0);
4231 #endif
4232 #ifdef WITH_INDEX_EXTFH
4233  var_print (_("ISAM handler"), _("External"), "", 0);
4234 #endif
4235 #ifdef WITH_DB
4236  var_print (_("ISAM handler"), _("BDB"), "", 0);
4237 #endif
4238 #ifdef WITH_CISAM
4239  var_print (_("ISAM handler"), _("C-ISAM (Experimental)"), "", 0);
4240 #endif
4241 #ifdef WITH_DISAM
4242  var_print (_("ISAM handler"), _("D-ISAM (Experimental)"), "", 0);
4243 #endif
4244 #ifdef WITH_VBISAM
4245  var_print (_("ISAM handler"), _("VBISAM (Experimental)"), "", 0);
4246 #endif
4247 }
COB_EXPIMP void print_runtime_env ( void  )
3999  {
4000  char* no_default;
4001  char* not_set;
4002  char* intstring;
4003  char* intstring2;
4004 
4005  printf("GNU Cobol runtime environment\n\n");
4006  printf("All values were resolved from current environment. \n\n");
4007  /* Alles aus common.c --> cob_init und cob_init_... - einigermaßen sinnvoll sortiert (ggf. Zwischenüberschriften ...*/
4008 
4009  if(!cob_initialized) {
4011  }
4012 
4013  no_default = (char*) _("No");
4014  not_set = (char*) _("not set");
4015  intstring = (char*) cob_fast_malloc(10);
4016  intstring2 = (char*) cob_fast_malloc(10);
4017 
4018  printf(_("Call environment\n"));
4019 
4020  var_print("COB_LIBRARY_PATH", runtimeptr->cob_library_path_env, not_set,
4021  2);
4022  var_print("resolve_path",
4024  (char*) PATHSEPS), not_set, 3);
4025  var_print("COB_PRE_LOAD", runtimeptr->cob_preload_env, not_set, 2);
4026  var_print("base_preload_ptr",
4027  runtimeptr->cob_preload_resolved, not_set, 3);
4028  var_print("COB_LOAD_CASE", runtimeptr->name_convert_env, not_set, 2);
4029  var_print("name_convert",
4030  cob_int_to_string(*(runtimeptr->name_convert), intstring),
4031  no_default, 3);
4032  var_print("COB_PHYSICAL_CANCEL", runtimeptr->physical_cancel_env,
4033  not_set, 2);
4034  var_print("physical_cancel",
4036  no_default, 3);
4037 
4038  printf(_("\n\nFile I/O\n"));
4039  var_print("COB_SYNC", runtimeptr->cob_do_sync_env, not_set, 2);
4040  var_print("cob_do_sync",
4041  cob_int_to_string(*(runtimeptr->cob_do_sync), intstring),
4042  no_default, 3);
4043  var_print("COB_LS_USES_CR", runtimeptr->cob_ls_uses_cr_env, not_set, 2);
4044  var_print("cob_ls_uses_cr",
4046  no_default, 3);
4047 
4048  var_print("COB_SORT_MEMORY", runtimeptr->cob_sort_memory_env, not_set,
4049  2);
4050  var_print("cob_sort_memory",
4052  intstring),
4053  cob_int_to_formatted_bytestring(COB_SORT_MEMORY, intstring2), 3);
4054  var_print("COB_SORT_CHUNK", runtimeptr->cob_sort_chunk_env, not_set, 2);
4055  var_print("cob_sort_chunk",
4057  intstring),
4058  cob_int_to_formatted_bytestring(COB_SORT_CHUNK, intstring2), 3);
4059  var_print("COB_FILE_PATH", runtimeptr->cob_file_path_env, not_set, 2);
4060  var_print("cob_file_path", runtimeptr->cob_file_path, not_set, 3);
4061  var_print("COB_LS_NULLS", runtimeptr->cob_ls_nulls_env, not_set, 2);
4062  var_print("cob_ls_nulls",
4063  cob_int_to_string(*(runtimeptr->cob_ls_nulls), intstring),
4064  no_default, 3);
4065  var_print("COB_LS_FIXED", runtimeptr->cob_ls_fixed_env, not_set, 2);
4066  var_print("cob_ls_fixed",
4067  cob_int_to_string(*(runtimeptr->cob_ls_fixed), intstring),
4068  no_default, 3);
4069  var_print("COB_VARSEQ_FORMAT", runtimeptr->cob_varseq_type_env,
4070  _("0 (default), [2-byte record-length] [0000] [record-data]"), 2);
4071  var_print("cob_varseq_type",
4073  _("0 (default), [2-byte record-length] [0000] [record-data]"), 3);
4074  var_print("COB_UNIX_LF", runtimeptr->cob_unix_lf_env, not_set,
4075  2);
4076  var_print("cob_unix_lf",
4078  no_default, 3);
4079 
4080  if (runtimeptr->cob_local_edit) {
4081  printf(_("\n\nLocale Properties\n"));
4082  var_print("COB_LOCALE_NUMERIC_EDITED", runtimeptr->cob_local_edit_env,
4083  not_set, 2);
4084  var_print("cob_local_edit",
4086  no_default, 3);
4087  }
4088 
4089  printf(_("\n\nScreen I/O\n"));
4090  var_print("COB_REDIRECT_DISPLAY",
4091  runtimeptr->cob_disp_to_stderr_env, not_set, 2);
4092  var_print("cob_disp_to_stderr",
4094  intstring), no_default, 3);
4095  var_print("COB_BELL", runtimeptr->cob_beep_str_env, not_set, 2);
4096  var_print("cob_beep_value", cob_int_to_string(cobglobptr->cob_beep_value, intstring), (char*) "0", 3);
4097  var_print("COB_TIMEOUT_SCALE", runtimeptr->cob_timeout_scale_env,
4098  not_set, 2);
4099  var_print("cob_timeout_scale",
4101  intstring), "1000", 3);
4102  var_print("COB_SCREEN_EXCEPTIONS",
4103  runtimeptr->cob_extended_status_env, not_set, 2);
4104  var_print("cob_extended_status",
4106  intstring), no_default, 3);
4107  var_print("COB_SCREEN_ESC", runtimeptr->cob_use_esc_env,
4108  not_set, 2);
4109  var_print("cob_screen_esc",
4111  no_default, 3);
4112  var_print("COB_LEGACY", runtimeptr->cob_legacy_env,
4113  not_set, 2);
4114  var_print("cob_legacy",
4115  cob_int_to_string(*(runtimeptr->cob_legacy), intstring),
4116  no_default, 3);
4117 
4118  printf(_("\n\nMiscellaneous\n"));
4119  var_print("COB_SET_TRACE", runtimeptr->cob_line_trace_env, not_set, 2);
4120  var_print("cob_line_trace", cob_int_to_string(cob_line_trace, intstring), no_default, 3);
4122  var_print("COB_TRACE_FILE", cob_trace_env, not_set, 2);
4123  if(cob_trace_file != stderr) {
4124  var_print("cob_trace_file", cob_trace_env, NULL, 3);
4125  }
4126  else {
4127  var_print("cob_trace_file", _("stderr (default)"), NULL, 3);
4128  }
4129  var_print("COB_DISABLE_WARNINGS",
4130  runtimeptr->cob_display_warn_env, not_set, 2);
4131  var_print("cob_display_warn",
4133  intstring), no_default, 3);
4134  var_print("COB_ENV_MANGLE", runtimeptr->cob_env_mangle_env,
4135  not_set, 2);
4136  var_print("cob_env_mangle",
4138  no_default, 3);
4139 }
COB_EXPIMP void print_version ( void  )
4142  {
4143  char* cobc_buffer;
4144  char month[32];
4145  int day, year;
4146 
4147  cobc_buffer = cob_fast_malloc((size_t) COB_MINI_MAX);
4148 
4149  /* Set up build time stamp */
4150  memset (month, 0, sizeof(month));
4151  day = 0;
4152  year = 0;
4153  sscanf (__DATE__, "%s %d %d", month, &day, &year);
4154 
4155  if (day && year) {
4156  snprintf (cobc_buffer, (size_t)COB_MINI_MAX,
4157  "%s %2.2d %4.4d %s", month, day, year, __TIME__);
4158  } else {
4159  snprintf (cobc_buffer, (size_t)COB_MINI_MAX,
4160  "%s %s", __DATE__, __TIME__);
4161  }
4162 
4163  printf ("libcob (%s) %s.%d\n",
4165  puts ("Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Keisuke Nishida");
4166  puts ("Copyright (C) 2006-2012 Roger While");
4167  puts ("Copyright (C) 2009,2010,2012,2014 Simon Sobisch");
4168  puts (_("This is free software; see the source for copying conditions. There is NO\n\
4169 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."));
4170  printf (_("Built %s"), cobc_buffer);
4171  putchar ('\n');
4172  printf (_("Packaged %s"), COB_TAR_DATE);
4173  putchar ('\n');
4174 
4175 }
static void read_literal ( const int  )
static
void redefinition_error ( cb_tree  )
234 {
235  struct cb_word *w;
236 
237  w = CB_REFERENCE (x)->word;
238  cb_error_x (x, _("Redefinition of '%s'"), w->name);
239  if (w->items) {
240  cb_error_x (CB_VALUE (w->items),
241  _("'%s' previously defined here"), w->name);
242  }
243 }
void redefinition_warning ( cb_tree  ,
cb_tree   
)
247 {
248  struct cb_word *w;
249  cb_tree z;
250 
251  w = CB_REFERENCE (x)->word;
252  cb_warning_x (x, _("Redefinition of '%s'"), w->name);
253  z = NULL;
254  if (y) {
255  z = y;
256  } else if (w->items) {
257  z = CB_VALUE (w->items);
258  }
259 
260  if (z) {
261  cb_warning_x (z, _("'%s' previously defined here"), w->name);
262  }
263 }
static void scan_define_options ( const char *  )
static
static int scan_floating_numeric ( const char *  )
static
static int scan_h ( char *  ,
const int   
)
static
static int scan_numeric ( char *  )
static
static void scan_options ( const char *  ,
const unsigned  int 
)
static
static void scan_picture ( char *  )
static
static int scan_x ( char *  ,
const int   
)
static
static int scan_z ( char *  ,
const int  ,
const cob_u32_t   
)
static
void undefined_error ( cb_tree  )
267 {
268  struct cb_reference *r;
269  cb_tree c;
270 
271  if (!errnamebuff) {
272  errnamebuff = cobc_main_malloc ((size_t)COB_NORMAL_BUFF);
273  }
274  r = CB_REFERENCE (x);
275  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX, "'%s'", CB_NAME (x));
276  for (c = r->chain; c; c = CB_REFERENCE (c)->chain) {
277  strcat (errnamebuff, " in '");
278  strcat (errnamebuff, CB_NAME (c));
279  strcat (errnamebuff, "'");
280  }
281  if (r->flag_optional) {
282  cb_warning_x (x, _("%s is not defined"), errnamebuff);
283  } else {
284  cb_error_x (x, _("%s is not defined"), errnamebuff);
285  }
286 }
void validate_file ( struct cb_file ,
cb_tree   
)
2219 {
2220  /* Check ASSIGN clause
2221  Currently break's GNU COBOL's extension for SORT FILEs having no need
2222  for an ASSIGN clause (tested in run_extensions "SORT ASSIGN ..."
2223  According to the Programmer's Guide for 1.1 the ASSIGN is totally
2224  ignored as the SORT is either done in memory (if there's enough space)
2225  or in a temporary disk file.
2226  For supporting this f->organization = COB_ORG_SORT is done when we
2227  see an SD in FILE SECTION for the file, while validate_file is called
2228  in INPUT-OUTPUT Section.
2229  */
2230  if (!f->assign && f->organization != COB_ORG_SORT && !f->flag_fileid) {
2231  file_error (name, "ASSIGN", CB_FILE_ERR_REQUIRED);
2232  }
2233  /* Check RECORD/RELATIVE KEY clause */
2234  switch (f->organization) {
2235  case COB_ORG_INDEXED:
2236  if (f->key == NULL) {
2237  file_error (name, "RECORD KEY", CB_FILE_ERR_REQUIRED);
2238  }
2239  break;
2240  case COB_ORG_RELATIVE:
2241  if (f->key == NULL && f->access_mode != COB_ACCESS_SEQUENTIAL) {
2242  file_error (name, "RELATIVE KEY", CB_FILE_ERR_REQUIRED);
2243  }
2244  if (f->alt_key_list) {
2245  file_error (name, "ALTERNATE", CB_FILE_ERR_INVALID_FT);
2246  f->alt_key_list = NULL;
2247  }
2248  break;
2249  default:
2250  if (f->key) {
2251  file_error (name, "RECORD", CB_FILE_ERR_INVALID_FT);
2252  f->key = NULL;
2253  }
2254  if (f->alt_key_list) {
2255  file_error (name, "ALTERNATE", CB_FILE_ERR_INVALID_FT);
2256  f->alt_key_list = NULL;
2257  }
2258  if (f->access_mode == COB_ACCESS_DYNAMIC ||
2259  f->access_mode == COB_ACCESS_RANDOM) {
2260  file_error (name, "ORGANIZATION", CB_FILE_ERR_INVALID);
2261  }
2262  break;
2263  }
2264 }
int validate_move ( cb_tree  ,
cb_tree  ,
const unsigned  int 
)
5939 {
5940  struct cb_field *fdst;
5941  struct cb_field *fsrc;
5942  struct cb_literal *l;
5943  unsigned char *p;
5944  cb_tree loc;
5945  cob_s64_t val;
5946  size_t i;
5947  size_t is_numeric_edited;
5948  int src_scale_mod;
5949  int dst_scale_mod;
5950  int dst_size_mod;
5951  int size;
5952  int most_significant;
5953  int least_significant;
5954 
5955  loc = src->source_line ? src : dst;
5956  is_numeric_edited = 0;
5957  overlapping = 0;
5958  if (CB_REFERENCE_P (dst)) {
5959  if (CB_ALPHABET_NAME_P(CB_REFERENCE(dst)->value)) {
5960  goto invalid;
5961  }
5962  if (CB_FILE_P(CB_REFERENCE(dst)->value)) {
5963  goto invalid;
5964  }
5965  }
5966  if (CB_TREE_CATEGORY (dst) == CB_CATEGORY_BOOLEAN) {
5967  cb_error_x (loc, _("Invalid destination for MOVE"));
5968  return -1;
5969  }
5970 
5971  if (CB_TREE_CLASS (dst) == CB_CLASS_POINTER) {
5972  if (CB_TREE_CLASS (src) == CB_CLASS_POINTER) {
5973  return 0;
5974  } else {
5975  goto invalid;
5976  }
5977  }
5978 
5979  fdst = CB_FIELD_PTR (dst);
5980  switch (CB_TREE_TAG (src)) {
5981  case CB_TAG_CONST:
5982  if (src == cb_space) {
5983  if (CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC ||
5984  (CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC_EDITED && !is_value)) {
5985  if (!cb_relaxed_syntax_check || is_value) {
5986  goto invalid;
5987  }
5988  cb_warning_x (loc, _("Source is non-numeric - substituting zero"));
5989  }
5990  } else if (src == cb_zero) {
5991  if (CB_TREE_CATEGORY (dst) == CB_CATEGORY_ALPHABETIC) {
5992  goto invalid;
5993  }
5994  } else if (src == cb_low || src == cb_high || src == cb_quote) {
5995  if (CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC ||
5996  CB_TREE_CATEGORY (dst) == CB_CATEGORY_NUMERIC_EDITED) {
5997  if (!cb_relaxed_syntax_check || is_value) {
5998  goto invalid;
5999  }
6000  cb_warning_x (loc, _("Source is non-numeric - substituting zero"));
6001  }
6002  }
6003  break;
6004  case CB_TAG_LITERAL:
6005  l = CB_LITERAL (src);
6006  if (CB_TREE_CLASS (src) == CB_CLASS_NUMERIC) {
6007  /* Numeric literal */
6008  if (l->all) {
6009  goto invalid;
6010  }
6011  if (fdst->usage == CB_USAGE_DOUBLE ||
6012  fdst->usage == CB_USAGE_FLOAT ||
6013  fdst->usage == CB_USAGE_LONG_DOUBLE ||
6014  fdst->usage == CB_USAGE_FP_BIN32 ||
6015  fdst->usage == CB_USAGE_FP_BIN64 ||
6016  fdst->usage == CB_USAGE_FP_BIN128 ||
6017  fdst->usage == CB_USAGE_FP_DEC64 ||
6018  fdst->usage == CB_USAGE_FP_DEC128) {
6019  break;
6020  }
6021  most_significant = -999;
6022  least_significant = 999;
6023 
6024  /* Compute the most significant figure place */
6025  for (i = 0; i < l->size; i++) {
6026  if (l->data[i] != '0') {
6027  break;
6028  }
6029  }
6030  if (i != l->size) {
6031  most_significant = (int) (l->size - l->scale - i - 1);
6032  }
6033 
6034  /* Compute the least significant figure place */
6035  for (i = 0; i < l->size; i++) {
6036  if (l->data[l->size - i - 1] != '0') {
6037  break;
6038  }
6039  }
6040  if (i != l->size) {
6041  least_significant = (int) (-l->scale + i);
6042  }
6043 
6044  /* Value check */
6045  switch (CB_TREE_CATEGORY (dst)) {
6048  if (is_value) {
6049  goto expect_alphanumeric;
6050  }
6051  if (l->scale == 0) {
6052  goto expect_alphanumeric;
6053  }
6054  goto non_integer_move;
6055  case CB_CATEGORY_NUMERIC:
6056  if (fdst->pic->scale < 0) {
6057  /* Check for PIC 9(n)P(m) */
6058  if (least_significant < -fdst->pic->scale) {
6059  goto value_mismatch;
6060  }
6061  } else if (fdst->pic->scale > fdst->pic->size) {
6062  /* Check for PIC P(n)9(m) */
6063  if (most_significant >= fdst->pic->size - fdst->pic->scale) {
6064  goto value_mismatch;
6065  }
6066  }
6067  break;
6069  if (is_value) {
6070  goto expect_alphanumeric;
6071  }
6072 
6073  /* TODO */
6074  break;
6076  if (is_value) {
6077  goto expect_alphanumeric;
6078  }
6079  /* Coming from codegen */
6080  if (!suppress_warn) {
6081  goto invalid;
6082  }
6083 #if 1 /* RXWRXW - Initialize warn */
6084  if (warningopt) {
6085  cb_warning_x (loc, _("Numeric move to ALPHABETIC"));
6086  }
6087 #endif
6088  break;
6089  default:
6090  if (is_value) {
6091  goto expect_alphanumeric;
6092  }
6093  goto invalid;
6094  }
6095 
6096  /* Sign check */
6097  if (l->sign != 0 && !fdst->pic->have_sign) {
6098  if (is_value) {
6099  cb_error_x (loc, _("Data item not signed"));
6100  return -1;
6101  }
6102  if (cb_warn_constant) {
6103  cb_warning_x (loc, _("Ignoring sign"));
6104  }
6105  }
6106 
6107  /* Size check */
6108  if (fdst->flag_real_binary ||
6109  ((fdst->usage == CB_USAGE_COMP_5 ||
6110  fdst->usage == CB_USAGE_COMP_X ||
6111  fdst->usage == CB_USAGE_BINARY) &&
6112  fdst->pic->scale == 0)) {
6113  p = l->data;
6114  for (i = 0; i < l->size; i++) {
6115  if (l->data[i] != '0') {
6116  p = &l->data[i];
6117  break;
6118  }
6119  }
6120  i = l->size - i;
6121  switch (fdst->size) {
6122  case 1:
6123  if (i > 18) {
6124  goto numlit_overflow;
6125  }
6126  val = cb_get_long_long (src);
6127  if (fdst->pic->have_sign) {
6128  if (val < COB_S64_C(-128) ||
6129  val > COB_S64_C(127)) {
6130  goto numlit_overflow;
6131  }
6132  } else {
6133  if (val > COB_S64_C(255)) {
6134  goto numlit_overflow;
6135  }
6136  }
6137  break;
6138  case 2:
6139  if (i > 18) {
6140  goto numlit_overflow;
6141  }
6142  val = cb_get_long_long (src);
6143  if (fdst->pic->have_sign) {
6144  if (val < COB_S64_C(-32768) ||
6145  val > COB_S64_C(32767)) {
6146  goto numlit_overflow;
6147  }
6148  } else {
6149  if (val > COB_S64_C(65535)) {
6150  goto numlit_overflow;
6151  }
6152  }
6153  break;
6154  case 3:
6155  if (i > 18) {
6156  goto numlit_overflow;
6157  }
6158  val = cb_get_long_long (src);
6159  if (fdst->pic->have_sign) {
6160  if (val < COB_S64_C(-8388608) ||
6161  val > COB_S64_C(8388607)) {
6162  goto numlit_overflow;
6163  }
6164  } else {
6165  if (val > COB_S64_C(16777215)) {
6166  goto numlit_overflow;
6167  }
6168  }
6169  break;
6170  case 4:
6171  if (i > 18) {
6172  goto numlit_overflow;
6173  }
6174  val = cb_get_long_long (src);
6175  if (fdst->pic->have_sign) {
6176  if (val < COB_S64_C(-2147483648) ||
6177  val > COB_S64_C(2147483647)) {
6178  goto numlit_overflow;
6179  }
6180  } else {
6181  if (val > COB_S64_C(4294967295)) {
6182  goto numlit_overflow;
6183  }
6184  }
6185  break;
6186  case 5:
6187  if (i > 18) {
6188  goto numlit_overflow;
6189  }
6190  val = cb_get_long_long (src);
6191  if (fdst->pic->have_sign) {
6192  if (val < COB_S64_C(-549755813888) ||
6193  val > COB_S64_C(549755813887)) {
6194  goto numlit_overflow;
6195  }
6196  } else {
6197  if (val > COB_S64_C(1099511627775)) {
6198  goto numlit_overflow;
6199  }
6200  }
6201  break;
6202  case 6:
6203  if (i > 18) {
6204  goto numlit_overflow;
6205  }
6206  val = cb_get_long_long (src);
6207  if (fdst->pic->have_sign) {
6208  if (val < COB_S64_C(-140737488355328) ||
6209  val > COB_S64_C(140737488355327)) {
6210  goto numlit_overflow;
6211  }
6212  } else {
6213  if (val > COB_S64_C(281474976710655)) {
6214  goto numlit_overflow;
6215  }
6216  }
6217  break;
6218  case 7:
6219  if (i > 18) {
6220  goto numlit_overflow;
6221  }
6222  val = cb_get_long_long (src);
6223  if (fdst->pic->have_sign) {
6224  if (val < COB_S64_C(-36028797018963968) ||
6225  val > COB_S64_C(36028797018963967)) {
6226  goto numlit_overflow;
6227  }
6228  } else {
6229  if (val > COB_S64_C(72057594037927935)) {
6230  goto numlit_overflow;
6231  }
6232  }
6233  break;
6234  default:
6235  if (fdst->pic->have_sign) {
6236  if (i < 19) {
6237  break;
6238  }
6239  if (i > 19) {
6240  goto numlit_overflow;
6241  }
6242  if (memcmp (p, "9223372036854775807", (size_t)19) > 0) {
6243  goto numlit_overflow;
6244  }
6245  } else {
6246  if (i < 20) {
6247  break;
6248  }
6249  if (i > 20) {
6250  goto numlit_overflow;
6251  }
6252  if (memcmp (p, "18446744073709551615", (size_t)20) > 0) {
6253  goto numlit_overflow;
6254  }
6255  }
6256  break;
6257  }
6258  return 0;
6259  }
6260  if (least_significant < -fdst->pic->scale) {
6261  goto size_overflow;
6262  }
6263  if (fdst->pic->scale > 0) {
6264  size = fdst->pic->digits - fdst->pic->scale;
6265  } else {
6266  size = fdst->pic->digits;
6267  }
6268  if (most_significant >= size) {
6269  goto size_overflow;
6270  }
6271  } else {
6272  /* Alphanumeric literal */
6273 
6274  /* Value check */
6275  switch (CB_TREE_CATEGORY (dst)) {
6277  for (i = 0; i < l->size; i++) {
6278  if (!isalpha (l->data[i]) &&
6279  l->data[i] != ' ') {
6280  goto value_mismatch;
6281  }
6282  }
6283  break;
6284  case CB_CATEGORY_NUMERIC:
6285  goto expect_numeric;
6287  if (!is_value) {
6288  goto expect_numeric;
6289  }
6290 
6291  /* TODO: validate the value */
6292  break;
6293  default:
6294  break;
6295  }
6296 
6297  /* Size check */
6298  size = cb_field_size (dst);
6299  if (size > 0 && (int)l->size > size) {
6300  goto size_overflow;
6301  }
6302  }
6303  break;
6304  case CB_TAG_FIELD:
6305  case CB_TAG_REFERENCE:
6306  if (CB_REFERENCE_P(src) &&
6308  break;
6309  }
6310  if (CB_REFERENCE_P(src) &&
6311  CB_FILE_P(CB_REFERENCE(src)->value)) {
6312  goto invalid;
6313  }
6314  fsrc = CB_FIELD_PTR (src);
6315  size = cb_field_size (src);
6316  if (size < 0) {
6317  size = fsrc->size;
6318  }
6319 
6320  /* Check basic overlapping */
6321  overlapping = cb_check_overlapping (src, dst, fsrc, fdst);
6322 
6323  /* Non-elementary move */
6324  if (fsrc->children || fdst->children) {
6325  if (size > fdst->size) {
6326  goto size_overflow_1;
6327  }
6328  break;
6329  }
6330 
6331  /* Elementary move */
6332  switch (CB_TREE_CATEGORY (src)) {
6334  switch (CB_TREE_CATEGORY (dst)) {
6335  case CB_CATEGORY_NUMERIC:
6337  if (size > (int)fdst->pic->digits) {
6338  goto size_overflow_2;
6339  }
6340  break;
6342  if (size > count_pic_alphanumeric_edited (fdst)) {
6343  goto size_overflow_1;
6344  }
6345  break;
6346  default:
6347  if (size > fdst->size) {
6348  goto size_overflow_1;
6349  }
6350  break;
6351  }
6352  break;
6355  switch (CB_TREE_CATEGORY (dst)) {
6356  case CB_CATEGORY_NUMERIC:
6358  goto invalid;
6360  if (size > count_pic_alphanumeric_edited(fdst)) {
6361  goto size_overflow_1;
6362  }
6363  break;
6364  default:
6365  if (size > fdst->size) {
6366  goto size_overflow_1;
6367  }
6368  break;
6369  }
6370  break;
6371  case CB_CATEGORY_NUMERIC:
6373  switch (CB_TREE_CATEGORY (dst)) {
6375  goto invalid;
6377  is_numeric_edited = 1;
6378  /* Drop through */
6380  if (!fsrc->pic) {
6381  return -1;
6382  }
6383  if (is_numeric_edited) {
6384  dst_size_mod = count_pic_alphanumeric_edited (fdst);
6385  } else {
6386  dst_size_mod = fdst->size;
6387  }
6388  if (CB_TREE_CATEGORY (src) == CB_CATEGORY_NUMERIC &&
6389  fsrc->pic->scale > 0) {
6390  goto non_integer_move;
6391  }
6392  if (CB_TREE_CATEGORY (src) == CB_CATEGORY_NUMERIC &&
6393  (int)fsrc->pic->digits > dst_size_mod) {
6394  goto size_overflow_2;
6395  }
6396  if (CB_TREE_CATEGORY (src) == CB_CATEGORY_NUMERIC_EDITED &&
6397  fsrc->size > dst_size_mod) {
6398  goto size_overflow_1;
6399  }
6400  break;
6401  default:
6402  if (!fsrc->pic) {
6403  return -1;
6404  }
6405  if (!fdst->pic) {
6406  return -1;
6407  }
6408  src_scale_mod = fsrc->pic->scale < 0 ?
6409  0 : fsrc->pic->scale;
6410  dst_scale_mod = fdst->pic->scale < 0 ?
6411  0 : fdst->pic->scale;
6412  if (fsrc->pic->digits - src_scale_mod >
6413  fdst->pic->digits - dst_scale_mod ||
6414  src_scale_mod > dst_scale_mod) {
6415  goto size_overflow_2;
6416  }
6417  break;
6418  }
6419  break;
6420  default:
6421  cb_error_x (loc, _("Invalid source for MOVE"));
6422  return -1;
6423  }
6424  break;
6425  case CB_TAG_INTEGER:
6426  case CB_TAG_BINARY_OP:
6427  case CB_TAG_INTRINSIC:
6428  case CB_TAG_FUNCALL:
6429  /* TODO: check this */
6430  break;
6431  default:
6432  cobc_abort_pr (_("Unexpected tree tag %d"),
6433  (int)CB_TREE_TAG (src));
6434  COBC_ABORT ();
6435  }
6436  return 0;
6437 
6438 invalid:
6439  if (is_value) {
6440  cb_error_x (loc, _("Invalid VALUE clause"));
6441  } else {
6442  cb_error_x (loc, _("Invalid MOVE statement"));
6443  }
6444  return -1;
6445 
6446 numlit_overflow:
6447  if (is_value) {
6448  cb_error_x (loc, _("Invalid VALUE clause - literal exceeds data size"));
6449  return -1;
6450  }
6451  if (cb_warn_constant && !suppress_warn) {
6452  cb_warning_x (loc, _("Numeric literal exceeds data size"));
6453  }
6454  return 0;
6455 
6456 non_integer_move:
6457  if (!suppress_warn) {
6458  if (cb_move_noninteger_to_alphanumeric == CB_ERROR) {
6459  goto invalid;
6460  }
6461  cb_warning_x (loc, _("Move non-integer to alphanumeric"));
6462  }
6463  return 0;
6464 
6465 expect_numeric:
6466  move_warning (src, dst, is_value, cb_warn_strict_typing, 0,
6467  _("Numeric value is expected"));
6468  return 0;
6469 
6470 expect_alphanumeric:
6471  move_warning (src, dst, is_value, cb_warn_strict_typing, 0,
6472  _("Alphanumeric value is expected"));
6473  return 0;
6474 
6475 value_mismatch:
6476  move_warning (src, dst, is_value, cb_warn_constant, 0,
6477  _("Value does not fit the picture string"));
6478  return 0;
6479 
6480 size_overflow:
6481  move_warning (src, dst, is_value, cb_warn_constant, 0,
6482  _("Value size exceeds data size"));
6483  return 0;
6484 
6485 size_overflow_1:
6486  move_warning (src, dst, is_value, cb_warn_truncate, 1,
6487  _("Sending field larger than receiving field"));
6488  return 0;
6489 
6490 size_overflow_2:
6491  move_warning (src, dst, is_value, cb_warn_truncate, 1,
6492  _("Some digits may be truncated"));
6493  return 0;
6494 }
void ylex_call_destroy ( void  )

References NULL, and yylex_destroy().

Referenced by process_translate().

4537 {
4538  /* Release flex buffers */
4539  (void)yylex_destroy ();
4540  const78ptr = NULL;
4541 }
void ylex_call_destroy ( void  )

Referenced by process_translate().

1640 {
1641  /* Release flex buffers */
1642  (void)yylex_destroy ();
1643  const78ptr = NULL;
1644 }
void ylex_clear_all ( void  )

References cobc_free(), and NULL.

Referenced by main().

4516 {
4517  /* Clear buffers after parsing all source elements */
4518  if (picbuff2) {
4519  cobc_free (picbuff2);
4520  picbuff2 = NULL;
4521  }
4522  if (picbuff1) {
4523  cobc_free (picbuff1);
4524  picbuff1 = NULL;
4525  }
4526  if (plexbuff) {
4527  cobc_free (plexbuff);
4528  plexbuff = NULL;
4529  }
4530  plexsize = 0;
4531  pic1size = 0;
4532  pic2size = 0;
4533 }
void ylex_clear_all ( void  )

Referenced by main().

1619 {
1620  /* Clear buffers after parsing all source elements */
1621  if (picbuff2) {
1622  cobc_free (picbuff2);
1623  picbuff2 = NULL;
1624  }
1625  if (picbuff1) {
1626  cobc_free (picbuff1);
1627  picbuff1 = NULL;
1628  }
1629  if (plexbuff) {
1630  cobc_free (plexbuff);
1631  plexbuff = NULL;
1632  }
1633  plexsize = 0;
1634  pic1size = 0;
1635  pic2size = 0;
1636 }
int yyparse ( void  )
int yyparse ( )

Variable Documentation

freevar __pad0__
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional archaic
cb_tree cb_any
cb_tree cb_debug_contents
cb_tree cb_debug_item
cb_tree cb_debug_line
cb_tree cb_debug_name
cb_tree cb_debug_sub_1
cb_tree cb_debug_sub_2
cb_tree cb_debug_sub_3
cb_tree cb_depend_check
cb_tree cb_error_node
cb_tree cb_false
cb_tree cb_high
cb_tree cb_int0
cb_tree cb_int1
cb_tree cb_int2
cb_tree cb_int3
cb_tree cb_int4
cb_tree cb_int5
cb_tree cb_intr_whencomp
cb_tree cb_low
size_t cb_needs_01
cb_tree cb_norm_high
cb_tree cb_norm_low
cb_tree cb_null
cb_tree cb_one
cb_tree cb_quote
cb_tree cb_space
cb_tree cb_standard_error_handler
cb_tree cb_true
cb_tree cb_zero
unsigned int cobc_cs_check
unsigned int cobc_force_literal
unsigned int cobc_in_procedure
unsigned int cobc_in_repository
cb_tree cobc_printer_node
struct cb_level_78* const78ptr = NULL
static
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional constant
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit corresponding
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit define
unsigned int gen_screen_ptr
struct cb_level_78* globlev78ptr = NULL
static
unsigned int inside_bracket = 0
static
unsigned int integer_is_label = 0
static
unsigned int last_token_is_dot = 0
static
struct cb_level_78* lev78ptr = NULL
static
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column linkage
int non_const_word
option option case insensitive option never interactive option noyy_scan_buffer option noyy_scan_bytes option noyy_scan_string option noyyget_extra option noyyset_extra option noyyget_leng option noyyget_text option noyyget_lineno option noyyset_lineno option noyyget_in option noyyset_in option noyyget_out option noyyset_out option noyyget_lval option noyyset_lval option noyyget_lloc option noyyset_lloc option noyyget_debug option noyyset_debug
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional obsolete
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column overflow
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional overlap
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call params
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional parentheses
size_t pic1size
static
size_t pic2size
static
char* picbuff1 = NULL
static
char* picbuff2 = NULL
static
unsigned char* plexbuff = NULL
static
size_t plexsize
static
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional redefinition
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column terminator
struct cb_level_78* top78ptr = NULL
static
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column truncate
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict typing
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external call column unreachable
const unsigned char valid_char[256]
static
if fold fold static computed alternate extra correct stack on syntax debugging source implicit stack syntax write single recursive relax optional strict implicit external value