mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
While help/errstr has been added, the errstr builtin function is not yet written. In anticipation of the new errstr builtin the rest of the calc error system has been updated to associated errsym E_STRING's with errnum error codes and errmsg error messages. Minor improvements to help/rand. The verify_error_table() function that does a verification the error_table[] array and setup private_error_alias[] array is now called by libcalc_call_me_first(). Fix comment about wrong include file in have_sys_mount.h. Removed unused booltostr() and strtobool() macros from bool.h. Moved define of math_error(char *, ...) from zmath.h to errtbl.h. The errtbl.h include file, unless ERRCODE_SRC is defined also includes attribute.h and errsym.h. Group calc error related builtin support functions together in func.c. Make switch indenting in func.c consistent. Passing an invalid argument to error(), errno() or strerror() will set errno AND throw a math error. Before errno would be set and an error value was returned. Before there was no way to tell if the error value was a result of the arg or if an error detected. Added E_STRING to error([errnum | "E_STRING"]) builtin function. Added E_STRING to errno([errnum | "E_STRING"]) builtin function. Added E_STRING to strerror([errnum | "E_STRING"]) builtin function. Calling these functions with an E_STRING errsym is the same as calling them with the matching errnum code. Standardized on calc computation error related E_STRING strings where there are a set of related codes. Changed "E_...digits" into "E_..._digits". For example, E_FPUTC1 became E_FPUTC_1, E_FPUTC2 became E_FPUTC_2, and E_FPUTC3 became E_FPUTC_3. In a few cases such as E_APPR became E_APPR_1, because there was a E_APPR2 (which became E_APPR_2) and E_APPR3 (which became E_APPR_3). To other special cases, E_ILOG10 became E_IBASE10_LOG and E_ILOG2 became E_IBASE2_LOG because E_ILOG10 and E_ILOG2 are both independent calc computation error related E_STRING strings. Now related sets of E_STRING strings end in _ (underscore) followed by digits. The following is the list of E_STRING strings changes: E_APPR ==> E_APPR_1 E_ROUND ==> E_ROUND_1 E_SQRT ==> E_SQRT_1 E_ROOT ==> E_ROOT_1 E_SHIFT ==> E_SHIFT_1 E_SCALE ==> E_SCALE_1 E_POWI ==> E_POWI_1 E_POWER ==> E_POWER_1 E_QUO ==> E_QUO_1 E_MOD ==> E_MOD_1 E_ABS ==> E_ABS_1 E_APPR2 ==> E_APPR_2 E_APPR3 ==> E_APPR_3 E_ROUND2 ==> E_ROUND_2 E_ROUND3 ==> E_ROUND_3 E_BROUND2 ==> E_BROUND_2 E_BROUND3 ==> E_BROUND_3 E_SQRT2 ==> E_SQRT_2 E_SQRT3 ==> E_SQRT_3 E_ROOT2 ==> E_ROOT_2 E_ROOT3 ==> E_ROOT_3 E_SHIFT2 ==> E_SHIFT_2 E_SCALE2 ==> E_SCALE_2 E_POWI2 ==> E_POWI_2 E_POWER2 ==> E_POWER_2 E_POWER3 ==> E_POWER_3 E_QUO2 ==> E_QUO_2 E_QUO3 ==> E_QUO_3 E_MOD2 ==> E_MOD_2 E_MOD3 ==> E_MOD_3 E_ABS2 ==> E_ABS_2 E_EXP1 ==> E_EXP_1 E_EXP2 ==> E_EXP_2 E_FPUTC1 ==> E_FPUTC_1 E_FPUTC2 ==> E_FPUTC_2 E_FPUTC3 ==> E_FPUTC_3 E_FGETC1 ==> E_FGETC_1 E_FGETC2 ==> E_FGETC_2 E_FOPEN1 ==> E_FOPEN_1 E_FOPEN2 ==> E_FOPEN_2 E_FREOPEN1 ==> E_FREOPEN_1 E_FREOPEN2 ==> E_FREOPEN_2 E_FREOPEN3 ==> E_FREOPEN_3 E_FCLOSE1 ==> E_FCLOSE_1 E_FPUTS1 ==> E_FPUTS_1 E_FPUTS2 ==> E_FPUTS_2 E_FPUTS3 ==> E_FPUTS_3 E_FGETS1 ==> E_FGETS_1 E_FGETS2 ==> E_FGETS_2 E_FPUTSTR1 ==> E_FPUTSTR_1 E_FPUTSTR2 ==> E_FPUTSTR_2 E_FPUTSTR3 ==> E_FPUTSTR_3 E_FGETSTR1 ==> E_FGETSTR_1 E_FGETSTR2 ==> E_FGETSTR_2 E_FGETLINE1 ==> E_FGETLINE_1 E_FGETLINE2 ==> E_FGETLINE_2 E_FGETFIELD1 ==> E_FGETFIELD_1 E_FGETFIELD2 ==> E_FGETFIELD_2 E_REWIND1 ==> E_REWIND_1 E_PRINTF1 ==> E_PRINTF_1 E_PRINTF2 ==> E_PRINTF_2 E_FPRINTF1 ==> E_FPRINTF_1 E_FPRINTF2 ==> E_FPRINTF_2 E_FPRINTF3 ==> E_FPRINTF_3 E_STRPRINTF1 ==> E_STRPRINTF_1 E_STRPRINTF2 ==> E_STRPRINTF_2 E_FSCAN1 ==> E_FSCAN_1 E_FSCAN2 ==> E_FSCAN_2 E_FSCANF1 ==> E_FSCANF_1 E_FSCANF2 ==> E_FSCANF_2 E_FSCANF3 ==> E_FSCANF_3 E_FSCANF4 ==> E_FSCANF_4 E_STRSCANF1 ==> E_STRSCANF_1 E_STRSCANF2 ==> E_STRSCANF_2 E_STRSCANF3 ==> E_STRSCANF_3 E_STRSCANF4 ==> E_STRSCANF_4 E_SCANF1 ==> E_SCANF_1 E_SCANF2 ==> E_SCANF_2 E_SCANF3 ==> E_SCANF_3 E_FTELL1 ==> E_FTELL_1 E_FTELL2 ==> E_FTELL_2 E_FSEEK1 ==> E_FSEEK_1 E_FSEEK2 ==> E_FSEEK_2 E_FSEEK3 ==> E_FSEEK_3 E_FSIZE1 ==> E_FSIZE_1 E_FSIZE2 ==> E_FSIZE_2 E_FEOF1 ==> E_FEOF_1 E_FEOF2 ==> E_FEOF_2 E_FERROR1 ==> E_FERROR_1 E_FERROR2 ==> E_FERROR_2 E_UNGETC1 ==> E_UNGETC_1 E_UNGETC2 ==> E_UNGETC_2 E_UNGETC3 ==> E_UNGETC_3 E_ISATTY1 ==> E_ISATTY_1 E_ISATTY2 ==> E_ISATTY_2 E_ACCESS1 ==> E_ACCESS_1 E_ACCESS2 ==> E_ACCESS_2 E_SEARCH1 ==> E_SEARCH_1 E_SEARCH2 ==> E_SEARCH_2 E_SEARCH3 ==> E_SEARCH_3 E_SEARCH4 ==> E_SEARCH_4 E_SEARCH5 ==> E_SEARCH_5 E_SEARCH6 ==> E_SEARCH_6 E_RSEARCH1 ==> E_RSEARCH_1 E_RSEARCH2 ==> E_RSEARCH_2 E_RSEARCH3 ==> E_RSEARCH_3 E_RSEARCH4 ==> E_RSEARCH_4 E_RSEARCH5 ==> E_RSEARCH_5 E_RSEARCH6 ==> E_RSEARCH_6 E_REWIND2 ==> E_REWIND_2 E_STRERROR1 ==> E_STRERROR_1 E_STRERROR2 ==> E_STRERROR_2 E_COS1 ==> E_COS_1 E_COS2 ==> E_COS_2 E_SIN1 ==> E_SIN_1 E_SIN2 ==> E_SIN_2 E_EVAL2 ==> E_EVAL_2 E_ARG1 ==> E_ARG_1 E_ARG2 ==> E_ARG_2 E_POLAR1 ==> E_POLAR_1 E_POLAR2 ==> E_POLAR_2 E_MATFILL1 ==> E_MATFILL_1 E_MATFILL2 ==> E_MATFILL_2 E_MATTRANS1 ==> E_MATTRANS_1 E_MATTRANS2 ==> E_MATTRANS_2 E_DET1 ==> E_DET_1 E_DET2 ==> E_DET_2 E_DET3 ==> E_DET_3 E_MATMIN1 ==> E_MATMIN_1 E_MATMIN2 ==> E_MATMIN_2 E_MATMIN3 ==> E_MATMIN_3 E_MATMAX1 ==> E_MATMAX_1 E_MATMAX2 ==> E_MATMAX_2 E_MATMAX3 ==> E_MATMAX_3 E_CP1 ==> E_CP_1 E_CP2 ==> E_CP_2 E_CP3 ==> E_CP_3 E_DP1 ==> E_DP_1 E_DP2 ==> E_DP_2 E_DP3 ==> E_DP_3 E_SUBSTR1 ==> E_SUBSTR_1 E_SUBSTR2 ==> E_SUBSTR_2 E_INSERT1 ==> E_INSERT_1 E_INSERT2 ==> E_INSERT_2 E_DELETE1 ==> E_DELETE_1 E_DELETE2 ==> E_DELETE_2 E_LN1 ==> E_LN_1 E_LN2 ==> E_LN_2 E_ERROR1 ==> E_ERROR_1 E_ERROR2 ==> E_ERROR_2 E_EVAL3 ==> E_EVAL_3 E_EVAL4 ==> E_EVAL_4 E_RM1 ==> E_RM_1 E_RM2 ==> E_RM_2 E_BLK1 ==> E_BLK_1 E_BLK2 ==> E_BLK_2 E_BLK3 ==> E_BLK_3 E_BLK4 ==> E_BLK_4 E_BLKFREE1 ==> E_BLKFREE_1 E_BLKFREE2 ==> E_BLKFREE_2 E_BLKFREE3 ==> E_BLKFREE_3 E_BLKFREE4 ==> E_BLKFREE_4 E_BLKFREE5 ==> E_BLKFREE_5 E_BLOCKS1 ==> E_BLOCKS_1 E_BLOCKS2 ==> E_BLOCKS_2 E_COPY1 ==> E_COPY_01 E_COPY2 ==> E_COPY_02 E_COPY3 ==> E_COPY_03 E_COPY4 ==> E_COPY_04 E_COPY5 ==> E_COPY_05 E_COPY6 ==> E_COPY_06 E_COPY7 ==> E_COPY_07 E_COPY8 ==> E_COPY_08 E_COPY9 ==> E_COPY_09 E_COPY10 ==> E_COPY_10 E_COPY11 ==> E_COPY_11 E_COPY12 ==> E_COPY_12 E_COPY13 ==> E_COPY_13 E_COPY14 ==> E_COPY_14 E_COPY15 ==> E_COPY_15 E_COPY16 ==> E_COPY_16 E_COPY17 ==> E_COPY_17 E_COPYF1 ==> E_COPYF_1 E_COPYF2 ==> E_COPYF_2 E_COPYF3 ==> E_COPYF_3 E_COPYF4 ==> E_COPYF_4 E_PROTECT1 ==> E_PROTECT_1 E_PROTECT2 ==> E_PROTECT_2 E_PROTECT3 ==> E_PROTECT_3 E_MATFILL3 ==> E_MATFILL_3 E_MATFILL4 ==> E_MATFILL_4 E_MATTRACE1 ==> E_MATTRACE_1 E_MATTRACE2 ==> E_MATTRACE_2 E_MATTRACE3 ==> E_MATTRACE_3 E_TAN1 ==> E_TAN_1 E_TAN2 ==> E_TAN_2 E_COT1 ==> E_COT_1 E_COT2 ==> E_COT_2 E_SEC1 ==> E_SEC_1 E_SEC2 ==> E_SEC_2 E_CSC1 ==> E_CSC_1 E_CSC2 ==> E_CSC_2 E_SINH1 ==> E_SINH_1 E_SINH2 ==> E_SINH_2 E_COSH1 ==> E_COSH_1 E_COSH2 ==> E_COSH_2 E_TANH1 ==> E_TANH_1 E_TANH2 ==> E_TANH_2 E_COTH1 ==> E_COTH_1 E_COTH2 ==> E_COTH_2 E_SECH1 ==> E_SECH_1 E_SECH2 ==> E_SECH_2 E_CSCH1 ==> E_CSCH_1 E_CSCH2 ==> E_CSCH_2 E_ASIN1 ==> E_ASIN_1 E_ASIN2 ==> E_ASIN_2 E_ACOS1 ==> E_ACOS_1 E_ACOS2 ==> E_ACOS_2 E_ATAN1 ==> E_ATAN_1 E_ATAN2 ==> E_ATAN_2 E_ACOT1 ==> E_ACOT_1 E_ACOT2 ==> E_ACOT_2 E_ASEC1 ==> E_ASEC_1 E_ASEC2 ==> E_ASEC_2 E_ACSC1 ==> E_ACSC_1 E_ACSC2 ==> E_ACSC_2 E_ASINH1 ==> E_ASINH_1 E_ASINH2 ==> E_ASINH_2 E_ACOSH1 ==> E_ACOSH_1 E_ACOSH2 ==> E_ACOSH_2 E_ATANH1 ==> E_ATANH_1 E_ATANH2 ==> E_ATANH_2 E_ACOTH1 ==> E_ACOTH_1 E_ACOTH2 ==> E_ACOTH_2 E_ASECH1 ==> E_ASECH_1 E_ASECH2 ==> E_ASECH_2 E_ACSCH1 ==> E_ACSCH_1 E_ACSCH2 ==> E_ACSCH_2 E_GD1 ==> E_GD_1 E_GD2 ==> E_GD_2 E_AGD1 ==> E_AGD_1 E_AGD2 ==> E_AGD_2 E_BIT1 ==> E_BIT_1 E_BIT2 ==> E_BIT_2 E_SETBIT1 ==> E_SETBIT_1 E_SETBIT2 ==> E_SETBIT_2 E_SETBIT3 ==> E_SETBIT_3 E_SEG1 ==> E_SEG_1 E_SEG2 ==> E_SEG_2 E_SEG3 ==> E_SEG_3 E_HIGHBIT1 ==> E_HIGHBIT_1 E_HIGHBIT2 ==> E_HIGHBIT_2 E_LOWBIT1 ==> E_LOWBIT_1 E_LOWBIT2 ==> E_LOWBIT_2 E_HEAD1 ==> E_HEAD_1 E_HEAD2 ==> E_HEAD_2 E_TAIL1 ==> E_TAIL_1 E_TAIL2 ==> E_TAIL_2 E_XOR1 ==> E_XOR_1 E_XOR2 ==> E_XOR_2 E_INDICES1 ==> E_INDICES_1 E_INDICES2 ==> E_INDICES_2 E_EXP3 ==> E_EXP_3 E_SINH3 ==> E_SINH_3 E_COSH3 ==> E_COSH_3 E_SIN3 ==> E_SIN_3 E_COS3 ==> E_COS_3 E_GD3 ==> E_GD_3 E_AGD3 ==> E_AGD_3 E_POWER4 ==> E_POWER_4 E_ROOT4 ==> E_ROOT_4 E_DGT1 ==> E_DGT_1 E_DGT2 ==> E_DGT_2 E_DGT3 ==> E_DGT_3 E_PLCS1 ==> E_PLCS_1 E_PLCS2 ==> E_PLCS_2 E_DGTS1 ==> E_DGTS_1 E_DGTS2 ==> E_DGTS_2 E_ILOG10 ==> E_IBASE10_LOG E_ILOG2 ==> E_IBASE2_LOG E_COMB1 ==> E_COMB_1 E_COMB2 ==> E_COMB_2 E_ASSIGN1 ==> E_ASSIGN_1 E_ASSIGN2 ==> E_ASSIGN_2 E_ASSIGN3 ==> E_ASSIGN_3 E_ASSIGN4 ==> E_ASSIGN_4 E_ASSIGN5 ==> E_ASSIGN_5 E_ASSIGN6 ==> E_ASSIGN_6 E_ASSIGN7 ==> E_ASSIGN_7 E_ASSIGN8 ==> E_ASSIGN_8 E_ASSIGN9 ==> E_ASSIGN_9 E_SWAP1 ==> E_SWAP_1 E_SWAP2 ==> E_SWAP_2 E_SWAP3 ==> E_SWAP_3 E_QUOMOD1 ==> E_QUOMOD_1 E_QUOMOD2 ==> E_QUOMOD_2 E_QUOMOD3 ==> E_QUOMOD_3 E_PREINC1 ==> E_PREINC_1 E_PREINC2 ==> E_PREINC_2 E_PREINC3 ==> E_PREINC_3 E_PREDEC1 ==> E_PREDEC_1 E_PREDEC2 ==> E_PREDEC_2 E_PREDEC3 ==> E_PREDEC_3 E_POSTINC1 ==> E_POSTINC_1 E_POSTINC2 ==> E_POSTINC_2 E_POSTINC3 ==> E_POSTINC_3 E_POSTDEC1 ==> E_POSTDEC_1 E_POSTDEC2 ==> E_POSTDEC_2 E_POSTDEC3 ==> E_POSTDEC_3 E_INIT1 ==> E_INIT_01 E_INIT2 ==> E_INIT_02 E_INIT3 ==> E_INIT_03 E_INIT4 ==> E_INIT_04 E_INIT5 ==> E_INIT_05 E_INIT6 ==> E_INIT_06 E_INIT7 ==> E_INIT_07 E_INIT8 ==> E_INIT_08 E_INIT9 ==> E_INIT_09 E_INIT10 ==> E_INIT_10 E_LIST1 ==> E_LIST_1 E_LIST2 ==> E_LIST_2 E_LIST3 ==> E_LIST_3 E_LIST4 ==> E_LIST_4 E_LIST5 ==> E_LIST_5 E_LIST6 ==> E_LIST_6 E_MODIFY1 ==> E_MODIFY_1 E_MODIFY2 ==> E_MODIFY_2 E_MODIFY3 ==> E_MODIFY_3 E_MODIFY4 ==> E_MODIFY_4 E_MODIFY5 ==> E_MODIFY_5 E_FPATHOPEN1 ==> E_FPATHOPEN_1 E_FPATHOPEN2 ==> E_FPATHOPEN_2 E_LOG1 ==> E_LOG_1 E_LOG2 ==> E_LOG_2 E_LOG3 ==> E_LOG_3 E_FGETFILE1 ==> E_FGETFILE_1 E_FGETFILE2 ==> E_FGETFILE_2 E_FGETFILE3 ==> E_FGETFILE_3 E_TAN3 ==> E_TAN_3 E_TAN4 ==> E_TAN_4 E_COT3 ==> E_COT_3 E_COT4 ==> E_COT_4 E_SEC3 ==> E_SEC_3 E_CSC3 ==> E_CSC_3 E_TANH3 ==> E_TANH_3 E_TANH4 ==> E_TANH_4 E_COTH3 ==> E_COTH_3 E_COTH4 ==> E_COTH_4 E_SECH3 ==> E_SECH_3 E_CSCH3 ==> E_CSCH_3 E_ASIN3 ==> E_ASIN_3 E_ACOS3 ==> E_ACOS_3 E_ASINH3 ==> E_ASINH_3 E_ACOSH3 ==> E_ACOSH_3 E_ATAN3 ==> E_ATAN_3 E_ACOT3 ==> E_ACOT_3 E_ASEC3 ==> E_ASEC_3 E_ACSC3 ==> E_ACSC_3 E_ATANH3 ==> E_ATANH_3 E_ACOTH3 ==> E_ACOTH_3 E_ASECH3 ==> E_ASECH_3 E_ACSCH3 ==> E_ACSCH_3 E_D2R1 ==> E_D2R_1 E_D2R2 ==> E_D2R_2 E_R2D1 ==> E_R2D_1 E_R2D2 ==> E_R2D_2 E_G2R1 ==> E_G2R_1 E_G2R2 ==> E_G2R_2 E_R2G1 ==> E_R2G_1 E_R2G2 ==> E_R2G_2 E_D2G1 ==> E_D2G_1 E_G2D1 ==> E_G2D_1 E_D2DMS1 ==> E_D2DMS_1 E_D2DMS2 ==> E_D2DMS_2 E_D2DMS3 ==> E_D2DMS_3 E_D2DMS4 ==> E_D2DMS_4 E_D2DM1 ==> E_D2DM_1 E_D2DM2 ==> E_D2DM_2 E_D2DM3 ==> E_D2DM_3 E_D2DM4 ==> E_D2DM_4 E_G2GMS1 ==> E_G2GMS_1 E_G2GMS2 ==> E_G2GMS_2 E_G2GMS3 ==> E_G2GMS_3 E_G2GMS4 ==> E_G2GMS_4 E_G2GM1 ==> E_G2GM_1 E_G2GM2 ==> E_G2GM_2 E_G2GM3 ==> E_G2GM_3 E_G2GM4 ==> E_G2GM_4 E_H2HMS1 ==> E_H2HMS_1 E_H2HMS2 ==> E_H2HMS_2 E_H2HMS3 ==> E_H2HMS_3 E_H2HMS4 ==> E_H2HMS_4 E_H2HM1 ==> E_H2HM_1 E_H2HM2 ==> E_H2HM_2 E_H2HM3 ==> E_H2HM_3 E_H2HM4 ==> E_H2HM_4 E_DMS2D1 ==> E_DMS2D_1 E_DMS2D2 ==> E_DMS2D_2 E_DM2D1 ==> E_DM2D_1 E_DM2D2 ==> E_DM2D_2 E_GMS2G1 ==> E_GMS2G_1 E_GMS2G2 ==> E_GMS2G_2 E_GM2G1 ==> E_GM2G_1 E_GM2G2 ==> E_GM2G_2 E_HMS2H1 ==> E_HMS2H_1 E_HMS2H2 ==> E_HMS2H_2 E_HM2H1 ==> E_HM2H_1 E_HM2H2 ==> E_HM2H_2 E_VERSIN1 ==> E_VERSIN_1 E_VERSIN2 ==> E_VERSIN_2 E_VERSIN3 ==> E_VERSIN_3 E_AVERSIN1 ==> E_AVERSIN_1 E_AVERSIN2 ==> E_AVERSIN_2 E_AVERSIN3 ==> E_AVERSIN_3 E_COVERSIN1 ==> E_COVERSIN_1 E_COVERSIN2 ==> E_COVERSIN_2 E_COVERSIN3 ==> E_COVERSIN_3 E_ACOVERSIN1 ==> E_ACOVERSIN_1 E_ACOVERSIN2 ==> E_ACOVERSIN_2 E_ACOVERSIN3 ==> E_ACOVERSIN_3 E_VERCOS1 ==> E_VERCOS_1 E_VERCOS2 ==> E_VERCOS_2 E_VERCOS3 ==> E_VERCOS_3 E_AVERCOS1 ==> E_AVERCOS_1 E_AVERCOS2 ==> E_AVERCOS_2 E_AVERCOS3 ==> E_AVERCOS_3 E_COVERCOS1 ==> E_COVERCOS_1 E_COVERCOS2 ==> E_COVERCOS_2 E_COVERCOS3 ==> E_COVERCOS_3 E_ACOVERCOS1 ==> E_ACOVERCOS_1 E_ACOVERCOS2 ==> E_ACOVERCOS_2 E_ACOVERCOS3 ==> E_ACOVERCOS_3 E_TAN5 ==> E_TAN_5 E_COT5 ==> E_COT_5 E_COT6 ==> E_COT_6 E_SEC5 ==> E_SEC_5 E_CSC5 ==> E_CSC_5 E_CSC6 ==> E_CSC_6
590 lines
21 KiB
C
590 lines
21 KiB
C
/*
|
|
* value - definitions of general values and related routines used by calc
|
|
*
|
|
* Copyright (C) 1999-2007,2014,2021,2023 David I. Bell
|
|
*
|
|
* Calc is open software; you can redistribute it and/or modify it under
|
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
* Public License for more details.
|
|
*
|
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* Under source code control: 1993/07/30 19:42:47
|
|
* File existed as early as: 1993
|
|
*
|
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
|
*/
|
|
|
|
|
|
#if !defined(INCLUDE_VALUE_H)
|
|
#define INCLUDE_VALUE_H
|
|
|
|
|
|
#if defined(CALC_SRC) /* if we are building from the calc source tree */
|
|
# include "decl.h"
|
|
# include "cmath.h"
|
|
# include "config.h"
|
|
# include "sha1.h"
|
|
# include "hash.h"
|
|
# include "block.h"
|
|
# include "nametype.h"
|
|
# include "str.h"
|
|
# include "errtbl.h"
|
|
#else
|
|
# include <calc/decl.h>
|
|
# include <calc/cmath.h>
|
|
# include <calc/config.h>
|
|
# include <calc/sha1.h>
|
|
# include <calc/hash.h>
|
|
# include <calc/block.h>
|
|
# include <calc/nametype.h>
|
|
# include <calc/str.h>
|
|
# include <calc/errtbl.h>
|
|
#endif
|
|
|
|
|
|
#define MAXDIM 4 /* maximum number of dimensions in matrices */
|
|
#define USUAL_ELEMENTS 4 /* usual number of elements for objects */
|
|
|
|
|
|
/*
|
|
* Flags to modify results from the printvalue routine.
|
|
* These flags are OR'd together.
|
|
*/
|
|
#define PRINT_NORMAL 0x00 /* print in normal manner */
|
|
#define PRINT_SHORT 0x01 /* print in short format (no elements) */
|
|
#define PRINT_UNAMBIG 0x02 /* print in non-ambiguous manner */
|
|
|
|
|
|
/*
|
|
* Definition of values of various types.
|
|
*/
|
|
typedef struct value VALUE;
|
|
typedef struct object OBJECT;
|
|
typedef struct matrix MATRIX;
|
|
typedef struct list LIST;
|
|
typedef struct assoc ASSOC;
|
|
typedef long FILEID;
|
|
typedef struct rand RAND;
|
|
typedef struct random RANDOM;
|
|
|
|
|
|
/*
|
|
* calc values
|
|
*
|
|
* See below for information on what needs to be added for a new type.
|
|
*
|
|
* NOTE: The v_type can be a negative value. This happens when
|
|
* an error is returned as a VALUE.
|
|
*
|
|
* XXX - calc v3 wish: make v_type and v_subtype an int32_t - XXX
|
|
*/
|
|
struct value {
|
|
short v_type; /* type of value - IMPORTANT: v_type < 0 is an error code */
|
|
unsigned short v_subtype; /* other data related to some types */
|
|
union { /* types of values (see V_XYZ below) */
|
|
long vv_int; /* 1: small integer value */
|
|
NUMBER *vv_num; /* 2, 21: real number */
|
|
COMPLEX *vv_com; /* 3: complex number */
|
|
VALUE *vv_addr; /* 4, 18: address of variable value */
|
|
STRING *vv_str; /* 5, 20: string value */
|
|
MATRIX *vv_mat; /* 6: address of matrix */
|
|
LIST *vv_list; /* 7: address of list */
|
|
ASSOC *vv_assoc; /* 8: address of association */
|
|
OBJECT *vv_obj; /* 9: address of object */
|
|
FILEID vv_file; /* 10: id of opened file */
|
|
RAND *vv_rand; /* 11: subtractive 100 random state */
|
|
RANDOM *vv_random; /* 12: Blum random state */
|
|
CONFIG *vv_config; /* 13: configuration state */
|
|
HASH *vv_hash; /* 14: hash state */
|
|
BLOCK *vv_block; /* 15: memory block */
|
|
OCTET *vv_octet; /* 16, 19: octet addr (unsigned char) */
|
|
NBLOCK *vv_nblock; /* 17: named memory block */
|
|
} v_union;
|
|
};
|
|
|
|
|
|
/*
|
|
* For ease in referencing
|
|
*/
|
|
#define v_int v_union.vv_int
|
|
#define v_file v_union.vv_file
|
|
#define v_num v_union.vv_num
|
|
#define v_com v_union.vv_com
|
|
#define v_addr v_union.vv_addr
|
|
#define v_str v_union.vv_str
|
|
#define v_mat v_union.vv_mat
|
|
#define v_list v_union.vv_list
|
|
#define v_assoc v_union.vv_assoc
|
|
#define v_obj v_union.vv_obj
|
|
#define v_valid v_union.vv_int
|
|
#define v_rand v_union.vv_rand
|
|
#define v_random v_union.vv_random
|
|
#define v_config v_union.vv_config
|
|
#define v_hash v_union.vv_hash
|
|
#define v_block v_union.vv_block
|
|
#define v_octet v_union.vv_octet
|
|
#define v_nblock v_union.vv_nblock
|
|
|
|
|
|
/*
|
|
* Value types.
|
|
*
|
|
* NOTE: The following files should be checked/adjusted for a new type:
|
|
*
|
|
* size.c - elm_count(), lsizeof()
|
|
* help/size - update what the size() builtin will report
|
|
* hash.c - hash_value()
|
|
* quickhash.c - hashvalue()
|
|
* value.c - freevalue(), copyvalue(), comparevalue(),
|
|
* printvalue(),
|
|
* and other as needed such as testvalue(), etc.
|
|
*
|
|
* There may be others, but at is at least a start.
|
|
*/
|
|
#define V_NULL 0 /* null value */
|
|
#define V_INT 1 /* normal integer */
|
|
#define V_NUM 2 /* number */
|
|
#define V_COM 3 /* complex number */
|
|
#define V_ADDR 4 /* address of variable value */
|
|
#define V_STR 5 /* address of string */
|
|
#define V_MAT 6 /* address of matrix structure */
|
|
#define V_LIST 7 /* address of list structure */
|
|
#define V_ASSOC 8 /* address of association structure */
|
|
#define V_OBJ 9 /* address of object structure */
|
|
#define V_FILE 10 /* opened file id */
|
|
#define V_RAND 11 /* address of subtractive 100 random state */
|
|
#define V_RANDOM 12 /* address of Blum random state */
|
|
#define V_CONFIG 13 /* configuration state */
|
|
#define V_HASH 14 /* hash state */
|
|
#define V_BLOCK 15 /* memory block */
|
|
#define V_OCTET 16 /* octet (unsigned char) */
|
|
#define V_NBLOCK 17 /* named memory block */
|
|
#define V_VPTR 18 /* value address as pointer */
|
|
#define V_OPTR 19 /* octet address as pointer */
|
|
#define V_SPTR 20 /* string address as pointer */
|
|
#define V_NPTR 21 /* number address as pointer */
|
|
|
|
#define V_MAX V_NPTR /* highest legal value - must be last and match highest V_something value */
|
|
|
|
/*
|
|
* v_subtype values
|
|
*/
|
|
#define V_NOSUBTYPE 0 /* subtype has no meaning */
|
|
#define V_NOASSIGNTO 0x001 /* protection status 1 */
|
|
#define V_NONEWVALUE 0x002 /* protection status 2 */
|
|
#define V_NONEWTYPE 0x004 /* protection status 4 */
|
|
#define V_NOERROR 0x008 /* protection status 8 */
|
|
#define V_NOCOPYTO 0x010 /* protection status 16 */
|
|
#define V_NOREALLOC 0x020 /* protection status 32 */
|
|
#define V_NOASSIGNFROM 0x040 /* protection status 64 */
|
|
#define V_NOCOPYFROM 0x080 /* protection status 128 */
|
|
#define V_PROTECTALL 0x100 /* protection status 256 */
|
|
|
|
#define MAXPROTECT 0x1ff /* OR of all of the above protection statuses */
|
|
|
|
/*
|
|
* At present protect(var, sts) determines bits in var->v_subtype
|
|
* corresponding to 4 * sts. MAXPROTECT is the sum of the simple
|
|
* (power of two) protection status values.
|
|
*
|
|
* XXX - consider isseu #52 with respect to protect - XXX
|
|
*/
|
|
|
|
|
|
/*
|
|
* NOTE: The shift of 8 in TWOVAL() macro below assumes V_MAX < 1<<8
|
|
*
|
|
* The macro TWOVAL_ARGS_OK(a,b) will return true if both a and b are in range,
|
|
* otherwise it will return false.
|
|
*
|
|
* The TWOVAL_INVALID is a value that TWOVAL_ARGS_OK(a,b) is true,
|
|
* will never match a TWOVAL(a,b) value (i.e., using V_something defined values).
|
|
*
|
|
* The TWOVAL_AS_UINT(a,b) may be assigned to a unsigned int value so that
|
|
* with one switches on that unsigned int, cases with a and/or b being
|
|
* out of range will fall into the default (non-matching) case.
|
|
*
|
|
* unsigned int twoval_as_uint;
|
|
*
|
|
* ...
|
|
*
|
|
* twoval_as_uint = TWOVAL_AS_UINT(a,b);
|
|
* switch (twoval_as_uint) {
|
|
* case TWOVAL(V_INT,V_INT):
|
|
* ...
|
|
* break;
|
|
* case TWOVAL(V_INT,V_NUM):
|
|
* ...
|
|
* break;
|
|
* default:
|
|
* ...
|
|
* break;
|
|
* }
|
|
*
|
|
* If a is NOT 0 <= a <= V_MAX or if b is NOT 0 <= b <= V_MAX,
|
|
* when () macro returns -1 (all bits set) in order to
|
|
* not match and true TWOVAL() macro combination that uses
|
|
* uses a V_something defined value above.
|
|
*/
|
|
|
|
#define TWOVAL(a,b) ((unsigned int)(((a) << 8) | (b))) /* logical OR for switch of two V_something values */
|
|
#define TWOVAL_ARGS_OK(a,b) (((a) >= 0) && ((a) <= V_MAX) && ((b) >= 0) && ((b) <= V_MAX))
|
|
#define TWOVAL_INVALID ((unsigned int)(-1)) /* never a valid TWOVAL(a,b) value when a and b are in range */
|
|
#define TWOVAL_AS_UINT(a,b) (TWOVAL_ARGS_OK(a,b) ? TWOVAL(a,b) : TWOVAL_INVALID)
|
|
|
|
#define NULL_VALUE ((VALUE *) 0)
|
|
|
|
|
|
/*
|
|
* value functions
|
|
*/
|
|
E_FUNC void freevalue(VALUE *vp);
|
|
E_FUNC void copyvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void negvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void addvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void subvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void orvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void andvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void compvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void squarevalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void invertvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void setminusvalue(VALUE *, VALUE *, VALUE *);
|
|
E_FUNC void backslashvalue(VALUE *, VALUE *);
|
|
E_FUNC void contentvalue(VALUE *, VALUE *);
|
|
E_FUNC void hashopvalue(VALUE *, VALUE *, VALUE *);
|
|
E_FUNC void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void intvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void fracvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void incvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void decvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void conjvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void absvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void normvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC void shiftvalue(VALUE *v1, VALUE *v2, bool rightshift, VALUE *vres);
|
|
E_FUNC void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void powvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void divvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);
|
|
E_FUNC bool testvalue(VALUE *vp);
|
|
E_FUNC bool comparevalue(VALUE *v1, VALUE *v2);
|
|
E_FUNC bool acceptvalue(VALUE *v1, VALUE *v2);
|
|
E_FUNC void relvalue(VALUE *v1, VALUE *v2, VALUE *vres);
|
|
E_FUNC void sgnvalue(VALUE *vp, VALUE *vres);
|
|
E_FUNC QCKHASH hashvalue(VALUE *vp, QCKHASH val);
|
|
E_FUNC void printvalue(VALUE *vp, int flags);
|
|
E_FUNC void printestr(VALUE *vp);
|
|
E_FUNC bool precvalue(VALUE *v1, VALUE *v2);
|
|
E_FUNC VALUE error_value(int e);
|
|
E_FUNC int set_errno(int e);
|
|
E_FUNC int set_errcount(int e);
|
|
E_FUNC long countlistitems(LIST *lp);
|
|
E_FUNC void addlistitems(LIST *lp, VALUE *vres);
|
|
E_FUNC void addlistinv(LIST *lp, VALUE *vres);
|
|
E_FUNC void copy2octet(VALUE *, OCTET *);
|
|
E_FUNC int copystod(VALUE *, long, long, VALUE *, long);
|
|
E_FUNC void protecttodepth(VALUE *, int, int);
|
|
E_FUNC void set_update(int);
|
|
|
|
|
|
/*
|
|
* Structure of a matrix.
|
|
*/
|
|
struct matrix {
|
|
long m_dim; /* dimension of matrix */
|
|
long m_size; /* total number of elements */
|
|
long m_min[MAXDIM]; /* minimum bound for indices */
|
|
long m_max[MAXDIM]; /* maximum bound for indices */
|
|
VALUE m_table[1]; /* actually varying length table */
|
|
};
|
|
|
|
#define matsize(n) (sizeof(MATRIX) - sizeof(VALUE) + ((n) * sizeof(VALUE)))
|
|
|
|
|
|
E_FUNC MATRIX *matadd(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC MATRIX *matsub(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC MATRIX *matmul(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC MATRIX *matneg(MATRIX *m);
|
|
E_FUNC MATRIX *matalloc(long size);
|
|
E_FUNC MATRIX *matcopy(MATRIX *m);
|
|
E_FUNC MATRIX *matinit(MATRIX *m, VALUE *v1, VALUE *v2);
|
|
E_FUNC MATRIX *matsquare(MATRIX *m);
|
|
E_FUNC MATRIX *matinv(MATRIX *m);
|
|
E_FUNC MATRIX *matscale(MATRIX *m, long n);
|
|
E_FUNC MATRIX *matshift(MATRIX *m, long n);
|
|
E_FUNC MATRIX *matmulval(MATRIX *m, VALUE *vp);
|
|
E_FUNC MATRIX *matpowi(MATRIX *m, NUMBER *q);
|
|
E_FUNC MATRIX *matconj(MATRIX *m);
|
|
E_FUNC MATRIX *matquoval(MATRIX *m, VALUE *vp, VALUE *v3);
|
|
E_FUNC MATRIX *matmodval(MATRIX *m, VALUE *vp, VALUE *v3);
|
|
E_FUNC MATRIX *matint(MATRIX *m);
|
|
E_FUNC MATRIX *matfrac(MATRIX *m);
|
|
E_FUNC MATRIX *matappr(MATRIX *m, VALUE *v2, VALUE *v3);
|
|
E_FUNC VALUE mattrace(MATRIX *m);
|
|
E_FUNC MATRIX *mattrans(MATRIX *m);
|
|
E_FUNC MATRIX *matcross(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC bool mattest(MATRIX *m);
|
|
E_FUNC void matsum(MATRIX *m, VALUE *vres);
|
|
E_FUNC bool matcmp(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC int matsearch(MATRIX *m, VALUE *vp, long start, long end, ZVALUE *index);
|
|
E_FUNC int matrsearch(MATRIX *m, VALUE *vp, long start, long end,
|
|
ZVALUE *index);
|
|
E_FUNC VALUE matdet(MATRIX *m);
|
|
E_FUNC VALUE matdot(MATRIX *m1, MATRIX *m2);
|
|
E_FUNC void matfill(MATRIX *m, VALUE *v1, VALUE *v2);
|
|
E_FUNC void matfree(MATRIX *m);
|
|
E_FUNC void matprint(MATRIX *m, long max_print);
|
|
E_FUNC VALUE *matindex(MATRIX *mp, bool create, long dim, VALUE *indices);
|
|
E_FUNC void matreverse(MATRIX *m);
|
|
E_FUNC void matsort(MATRIX *m);
|
|
E_FUNC bool matisident(MATRIX *m);
|
|
E_FUNC MATRIX *matround(MATRIX *m, VALUE *v2, VALUE *v3);
|
|
E_FUNC MATRIX *matbround(MATRIX *m, VALUE *v2, VALUE *v3);
|
|
|
|
|
|
/*
|
|
* List definitions.
|
|
* An individual list element.
|
|
*/
|
|
typedef struct listelem LISTELEM;
|
|
struct listelem {
|
|
LISTELEM *e_next; /* next element in list (or NULL) */
|
|
LISTELEM *e_prev; /* previous element in list (or NULL) */
|
|
VALUE e_value; /* value of this element */
|
|
};
|
|
|
|
|
|
/*
|
|
* Structure for a list of elements.
|
|
*/
|
|
struct list {
|
|
LISTELEM *l_first; /* first list element (or NULL) */
|
|
LISTELEM *l_last; /* last list element (or NULL) */
|
|
LISTELEM *l_cache; /* cached list element (or NULL) */
|
|
long l_cacheindex; /* index of cached element (or undefined) */
|
|
long l_count; /* total number of elements in the list */
|
|
};
|
|
|
|
|
|
E_FUNC void insertlistfirst(LIST *lp, VALUE *vp);
|
|
E_FUNC void insertlistlast(LIST *lp, VALUE *vp);
|
|
E_FUNC void insertlistmiddle(LIST *lp, long index, VALUE *vp);
|
|
E_FUNC void removelistfirst(LIST *lp, VALUE *vp);
|
|
E_FUNC void removelistlast(LIST *lp, VALUE *vp);
|
|
E_FUNC void removelistmiddle(LIST *lp, long index, VALUE *vp);
|
|
E_FUNC void listfree(LIST *lp);
|
|
E_FUNC void listprint(LIST *lp, long max_print);
|
|
E_FUNC int listsearch(LIST *lp, VALUE *vp, long start, long end, ZVALUE *index);
|
|
E_FUNC int listrsearch(LIST *lp, VALUE *vp, long start, long end,
|
|
ZVALUE *index);
|
|
E_FUNC bool listcmp(LIST *lp1, LIST *lp2);
|
|
E_FUNC VALUE *listfindex(LIST *lp, long index);
|
|
E_FUNC LIST *listalloc(void);
|
|
E_FUNC LIST *listcopy(LIST *lp);
|
|
E_FUNC void listreverse(LIST *lp);
|
|
E_FUNC void listsort(LIST *lp);
|
|
E_FUNC LIST *listappr(LIST *lp, VALUE *v2, VALUE *v3);
|
|
E_FUNC LIST *listround(LIST *m, VALUE *v2, VALUE *v3);
|
|
E_FUNC LIST *listbround(LIST *m, VALUE *v2, VALUE *v3);
|
|
E_FUNC LIST *listquo(LIST *lp, VALUE *v2, VALUE *v3);
|
|
E_FUNC LIST *listmod(LIST *lp, VALUE *v2, VALUE *v3);
|
|
E_FUNC bool evp(LISTELEM *cp, LISTELEM *x, VALUE *vres);
|
|
E_FUNC bool evalpoly(LIST *clist, LISTELEM *x, VALUE *vres);
|
|
E_FUNC void insertitems(LIST *lp1, LIST *lp2);
|
|
E_FUNC LISTELEM *listelement(LIST *, long);
|
|
E_FUNC LIST *listsegment(LIST *, long, long);
|
|
|
|
|
|
/*
|
|
* Structures for associations.
|
|
* Associations are "indexed" by one or more arbitrary values, and are
|
|
* stored in a hash table with their hash values for quick indexing.
|
|
*/
|
|
typedef struct assocelem ASSOCELEM;
|
|
struct assocelem {
|
|
ASSOCELEM *e_next; /* next element in list (or NULL) */
|
|
long e_dim; /* dimension of indexing for this element */
|
|
QCKHASH e_hash; /* hash value for this element */
|
|
VALUE e_value; /* value of association */
|
|
VALUE e_indices[1]; /* index values (variable length) */
|
|
};
|
|
|
|
|
|
struct assoc {
|
|
long a_count; /* number of elements in the association */
|
|
long a_size; /* current size of association hash table */
|
|
ASSOCELEM **a_table; /* current hash table for elements */
|
|
};
|
|
|
|
|
|
E_FUNC ASSOC *assocalloc(long initsize);
|
|
E_FUNC ASSOC *assoccopy(ASSOC *ap);
|
|
E_FUNC void assocfree(ASSOC *ap);
|
|
E_FUNC void assocprint(ASSOC *ap, long max_print);
|
|
E_FUNC int assocsearch(ASSOC *ap, VALUE *vp, long start, long end,
|
|
ZVALUE *index);
|
|
E_FUNC int assocrsearch(ASSOC *ap, VALUE *vp, long start, long end,
|
|
ZVALUE *index);
|
|
E_FUNC bool assoccmp(ASSOC *ap1, ASSOC *ap2);
|
|
E_FUNC VALUE *assocfindex(ASSOC *ap, long index);
|
|
E_FUNC VALUE *associndex(ASSOC *ap, bool create, long dim, VALUE *indices);
|
|
|
|
|
|
/*
|
|
* Object actions.
|
|
*/
|
|
#define OBJ_PRINT 0 /* print the value */
|
|
#define OBJ_ONE 1 /* create the multiplicative identity */
|
|
#define OBJ_TEST 2 /* test a value for "zero" */
|
|
#define OBJ_ADD 3 /* add two values */
|
|
#define OBJ_SUB 4 /* sub-trace one value from another */
|
|
#define OBJ_NEG 5 /* negate a value */
|
|
#define OBJ_MUL 6 /* multiply two values */
|
|
#define OBJ_DIV 7 /* divide one value by another */
|
|
#define OBJ_INV 8 /* invert a value */
|
|
#define OBJ_ABS 9 /* take absolute value of value */
|
|
#define OBJ_NORM 10 /* take the norm of a value */
|
|
#define OBJ_CONJ 11 /* take the conjugate of a value */
|
|
#define OBJ_POW 12 /* take the power function */
|
|
#define OBJ_SGN 13 /* return the sign of a value */
|
|
#define OBJ_CMP 14 /* compare two values for equality */
|
|
#define OBJ_REL 15 /* compare two values for inequality */
|
|
#define OBJ_QUO 16 /* integer quotient of values */
|
|
#define OBJ_MOD 17 /* remainder of division of values */
|
|
#define OBJ_INT 18 /* integer part of */
|
|
#define OBJ_FRAC 19 /* fractional part of */
|
|
#define OBJ_INC 20 /* increment by one */
|
|
#define OBJ_DEC 21 /* decrement by one */
|
|
#define OBJ_SQUARE 22 /* square value */
|
|
#define OBJ_SCALE 23 /* scale by power of two */
|
|
#define OBJ_SHIFT 24 /* shift left (or right) by number of bits */
|
|
#define OBJ_ROUND 25 /* round to specified decimal places */
|
|
#define OBJ_BROUND 26 /* round to specified binary places */
|
|
#define OBJ_ROOT 27 /* take nth root of value */
|
|
#define OBJ_SQRT 28 /* take square root of value */
|
|
#define OBJ_OR 29 /* take bitwise or of values */
|
|
#define OBJ_AND 30 /* take bitwise and of values */
|
|
#define OBJ_NOT 31 /* take logical not of value */
|
|
#define OBJ_FACT 32 /* factorial or postfix ! */
|
|
#define OBJ_MIN 33 /* minimum value */
|
|
#define OBJ_MAX 34 /* maximum value */
|
|
#define OBJ_SUM 35 /* sum value */
|
|
#define OBJ_ASSIGN 36 /* assign value */
|
|
#define OBJ_XOR 37 /* ~ difference of values */
|
|
#define OBJ_COMP 38 /* ~ complement of value */
|
|
#define OBJ_CONTENT 39 /* unary hash op */
|
|
#define OBJ_HASHOP 40 /* binary hash op */
|
|
#define OBJ_BACKSLASH 41 /* unary backslash op */
|
|
#define OBJ_SETMINUS 42 /* binary backslash op */
|
|
#define OBJ_PLUS 43 /* unary + op */
|
|
#define OBJ_MAXFUNC 43 /* highest function */
|
|
|
|
|
|
/*
|
|
* Definition of an object type.
|
|
* This is actually a varying sized structure.
|
|
*/
|
|
typedef struct {
|
|
int oa_index; /* index of object type */
|
|
int oa_count; /* number of elements defined */
|
|
long oa_indices[OBJ_MAXFUNC+1]; /* function indices for actions */
|
|
int oa_elements[1]; /* element indices (MUST BE LAST) */
|
|
} OBJECTACTIONS;
|
|
|
|
#define objectactionsize(elements) \
|
|
(sizeof(OBJECTACTIONS) + ((elements) - 1) * sizeof(int))
|
|
|
|
|
|
/*
|
|
* Structure of an object.
|
|
* This is actually a varying sized structure.
|
|
* However, there are always at least USUAL_ELEMENTS values in the object.
|
|
*/
|
|
struct object {
|
|
OBJECTACTIONS *o_actions; /* action table for this object */
|
|
VALUE o_table[USUAL_ELEMENTS]; /* object values (MUST BE LAST) */
|
|
};
|
|
|
|
#define objectsize(elements) \
|
|
(sizeof(OBJECT) + ((elements) - USUAL_ELEMENTS) * sizeof(VALUE))
|
|
|
|
|
|
E_FUNC OBJECT *objcopy(OBJECT *op);
|
|
E_FUNC OBJECT *objalloc(long index);
|
|
E_FUNC VALUE objcall(int action, VALUE *v1, VALUE *v2, VALUE *v3);
|
|
E_FUNC void objfree(OBJECT *op);
|
|
E_FUNC int addelement(char *name);
|
|
E_FUNC int defineobject(char *name, int indices[], int count);
|
|
E_FUNC int checkobject(char *name);
|
|
E_FUNC void showobjfuncs(void);
|
|
E_FUNC void showobjtypes(void);
|
|
E_FUNC int findelement(char *name);
|
|
E_FUNC char *objtypename(unsigned long index);
|
|
E_FUNC int objoffset(OBJECT *op, long index);
|
|
|
|
|
|
/*
|
|
* Configuration parameter name and type.
|
|
*/
|
|
EXTERN NAMETYPE configs[];
|
|
E_FUNC void config_value(CONFIG *cfg, int type, VALUE *ret);
|
|
E_FUNC void setconfig(int type, VALUE *vp);
|
|
E_FUNC void config_print(CONFIG *cfg); /* the CONFIG to print */
|
|
|
|
|
|
/*
|
|
* size, memsize and sizeof support
|
|
*/
|
|
E_FUNC long elm_count(VALUE *vp);
|
|
E_FUNC size_t lsizeof(VALUE *vp);
|
|
E_FUNC size_t memsize(VALUE *vp);
|
|
|
|
/*
|
|
* String functions
|
|
*/
|
|
E_FUNC STRING *stringadd(STRING *, STRING *);
|
|
E_FUNC STRING *stringcopy(STRING *);
|
|
E_FUNC STRING *stringsub(STRING *, STRING *);
|
|
E_FUNC STRING *stringmul(NUMBER *, STRING *);
|
|
E_FUNC STRING *stringand(STRING *, STRING *);
|
|
E_FUNC STRING *stringor(STRING *, STRING *);
|
|
E_FUNC STRING *stringxor(STRING *, STRING *);
|
|
E_FUNC STRING *stringdiff(STRING *, STRING *);
|
|
E_FUNC STRING *stringsegment(STRING *, long, long);
|
|
E_FUNC STRING *stringshift(STRING *, long);
|
|
E_FUNC STRING *stringcomp(STRING *);
|
|
E_FUNC STRING *stringneg(STRING *);
|
|
E_FUNC STRING *stringtolower(STRING *);
|
|
E_FUNC STRING *stringtoupper(STRING *);
|
|
E_FUNC STRING *stringcpy(STRING *, STRING *);
|
|
E_FUNC STRING *stringncpy(STRING *, STRING *, size_t);
|
|
E_FUNC long stringcontent(STRING *s);
|
|
E_FUNC long stringlowbit(STRING *s);
|
|
E_FUNC long stringhighbit(STRING *s);
|
|
E_FUNC bool stringcmp(STRING *, STRING *);
|
|
E_FUNC FLAG stringrel(STRING *, STRING *);
|
|
E_FUNC FLAG stringcaserel(STRING *, STRING *);
|
|
E_FUNC int stringbit(STRING *, long);
|
|
E_FUNC bool stringtest(STRING *);
|
|
E_FUNC int stringsetbit(STRING *, long, bool);
|
|
E_FUNC int stringsearch(STRING *, STRING *, long, long, ZVALUE *);
|
|
E_FUNC int stringrsearch(STRING *, STRING *, long, long, ZVALUE *);
|
|
|
|
#endif /* !INCLUDE_VALUE_H */
|