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
1058 lines
24 KiB
C
1058 lines
24 KiB
C
/*
|
|
* hash - one-way hash routines
|
|
*
|
|
* Copyright (C) 1999-2007,2021-2023 Landon Curt Noll
|
|
*
|
|
* 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: 1995/11/23 05:13:11
|
|
* File existed as early as: 1995
|
|
*
|
|
* chongo <was here> /\oo/\ http://www.isthe.com/chongo/
|
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include "have_string.h"
|
|
#ifdef HAVE_STRING_H
|
|
# include <string.h>
|
|
#endif
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include "calc.h"
|
|
#include "alloc.h"
|
|
#include "value.h"
|
|
#include "zrand.h"
|
|
#include "zrandom.h"
|
|
#include "hash.h"
|
|
|
|
|
|
#include "errtbl.h"
|
|
#include "banned.h" /* include after system header <> includes */
|
|
|
|
|
|
/*
|
|
* external hash_setup functions
|
|
*/
|
|
E_FUNC void shs_init_state(HASH*);
|
|
E_FUNC void sha1_init_state(HASH*);
|
|
E_FUNC void MD5_init_state(HASH*);
|
|
|
|
|
|
/*
|
|
* hash_long can deal with bool's, int's, FLAGS's and LEN's
|
|
*/
|
|
#define hash_bool(type, val, state) (hash_long((type), (long)(val), (state)))
|
|
#define hash_int(type, val, state) (hash_long((type), (long)(val), (state)))
|
|
#define hash_flag(type, val, state) (hash_long((type), (long)(val), (state)))
|
|
#define hash_len(type, val, state) (hash_long((type), (long)(val), (state)))
|
|
|
|
|
|
/*
|
|
* hash_setup - setup the hash state for a given hash
|
|
*/
|
|
STATIC struct hash_setup {
|
|
int type; /* hash type (see XYZ_HASH_TYPE below) */
|
|
void (*init_state)(HASH*); /* initialize a hash state */
|
|
} htbl[] = {
|
|
{ SHA1_HASH_TYPE, sha1_init_state }, /* SHA-1 / SHA-1 */
|
|
{ -1, NULL } /* must be last */
|
|
};
|
|
|
|
|
|
/*
|
|
* hash_init - initialize a hash state
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* state - the state to initialize, or NULL to malloc it
|
|
*
|
|
* returns:
|
|
* initialized state
|
|
*/
|
|
HASH *
|
|
hash_init(int type, HASH *state)
|
|
{
|
|
int i;
|
|
|
|
/*
|
|
* malloc if needed
|
|
*/
|
|
if (state == NULL) {
|
|
state = (HASH *)malloc(sizeof(HASH));
|
|
if (state == NULL) {
|
|
math_error("hash_init: cannot malloc HASH");
|
|
not_reached();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* clear hash value
|
|
*/
|
|
memset((void*)state, 0, sizeof(HASH));
|
|
state->bytes = true;
|
|
|
|
/*
|
|
* search for the hash_setup function
|
|
*/
|
|
for (i=0; htbl[i].init_state != NULL; ++i) {
|
|
|
|
/* if we found the state that we were looking for */
|
|
if (type == htbl[i].type) {
|
|
|
|
/* initialize state and return */
|
|
(htbl[i].init_state)(state);
|
|
|
|
/* firewall - MAX_CHUNKSIZE must be >= chunksize */
|
|
if (state->chunksize > MAX_CHUNKSIZE) {
|
|
math_error(
|
|
"internal error: MAX_CHUNKSIZE is too small");
|
|
not_reached();
|
|
}
|
|
return state;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* no such hash state
|
|
*/
|
|
math_error("internal error: hash type not found in htbl[]");
|
|
return NULL;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_free - free the hash state
|
|
*/
|
|
void
|
|
hash_free(HASH *state)
|
|
{
|
|
/*
|
|
* do nothing if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* free main state and return
|
|
*/
|
|
free(state);
|
|
return;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_copy - copy a hash state
|
|
*
|
|
* given:
|
|
* state - the state to copy
|
|
*
|
|
* returns:
|
|
* pointer to copy of state
|
|
*/
|
|
HASH *
|
|
hash_copy(HASH *state)
|
|
{
|
|
HASH *hnew; /* copy of state */
|
|
|
|
/*
|
|
* malloc new state
|
|
*/
|
|
hnew = (HASH *)malloc(sizeof(HASH));
|
|
if (hnew == NULL) {
|
|
math_error("hash_init: cannot malloc HASH");
|
|
not_reached();
|
|
}
|
|
|
|
/*
|
|
* duplicate state
|
|
*/
|
|
memcpy((void *)hnew, (void *)state, sizeof(HASH));
|
|
return hnew;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_cmp - compare hash values
|
|
*
|
|
* given:
|
|
* a first hash state
|
|
* b second hash state
|
|
*
|
|
* returns:
|
|
* true => hash states are different
|
|
* false => hash states are the same
|
|
*/
|
|
int
|
|
hash_cmp(HASH *a, HASH *b)
|
|
{
|
|
/*
|
|
* firewall and quick check
|
|
*/
|
|
if (a == b) {
|
|
/* pointers to the same object */
|
|
return false;
|
|
}
|
|
if (a == NULL || b == NULL) {
|
|
/* one pointer is NULL, so they differ */
|
|
return true;
|
|
}
|
|
if (a->cmp == NULL || b->cmp == NULL) {
|
|
/* one cmp function is NULL, so they differ */
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* compare hash types
|
|
*/
|
|
if (a->hashtype != b->hashtype) {
|
|
/* different hash types are different */
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* perform the hash specific comparison
|
|
*/
|
|
return ((a->cmp)(a,b));
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_print - print the name and value of a hash
|
|
*
|
|
* given:
|
|
* state the hash state to print name and value of
|
|
*/
|
|
void
|
|
hash_print(HASH *state)
|
|
{
|
|
/* print the hash */
|
|
(state->print)(state);
|
|
return;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_final - finalize the state of a hash and return a ZVALUE
|
|
*
|
|
* given:
|
|
* state the hash state to finalize
|
|
*
|
|
* returns:
|
|
* hash state as a ZVALUE
|
|
*/
|
|
ZVALUE
|
|
hash_final(HASH *state)
|
|
{
|
|
/* return the finalized the hash value */
|
|
return (state->final)(state);
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_long - note a long value
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* longval - a long value
|
|
* state - the state to hash
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*
|
|
* This function will hash a long value as if it were a 64 bit value.
|
|
* The input is a long. If a long is smaller than 64 bits, we will
|
|
* hash a final 32 bits of zeros.
|
|
*
|
|
* This function is OK to hash bool's, unsigned long's, unsigned int's
|
|
* signed int's as well as FLAG's and LEN's.
|
|
*/
|
|
HASH *
|
|
hash_long(int type, long longval, HASH *state)
|
|
{
|
|
long lval[64/LONG_BITS]; /* 64 bits of longs */
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the hash_long
|
|
*/
|
|
(state->chkpt)(state);
|
|
state->bytes = false; /* data to be read as words */
|
|
|
|
/*
|
|
* catch the zero numeric value special case
|
|
*/
|
|
if (longval == 0) {
|
|
/* note a zero numeric value and return */
|
|
(state->note)(HASH_ZERO(state->base), state);
|
|
return state;
|
|
}
|
|
|
|
/*
|
|
* prep for a long value hash
|
|
*/
|
|
(state->note)(state->base, state);
|
|
|
|
/*
|
|
* hash as if we have a 64 bit value
|
|
*/
|
|
memset((char *)lval, 0, sizeof(lval));
|
|
lval[0] = longval;
|
|
(state->update)(state, (USB8 *)lval, sizeof(lval));
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_zvalue - hash a ZVALUE
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* zval - the ZVALUE
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_zvalue(int type, ZVALUE zval, HASH *state)
|
|
{
|
|
|
|
#if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16
|
|
int full_lim; /* HALFs in whole chunks in zval */
|
|
int chunkhalf; /* size of half buffer in HALFs */
|
|
int i;
|
|
int j;
|
|
#endif
|
|
#if BASEB == 16
|
|
HALF half[MAX_CHUNKSIZE]; /* For endian reversal */
|
|
#endif
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the ZVALUE hash
|
|
*/
|
|
(state->chkpt)(state);
|
|
state->bytes = false; /* data to be read as words */
|
|
|
|
/*
|
|
* catch the zero numeric value special case
|
|
*/
|
|
if (ziszero(zval)) {
|
|
/* note a zero numeric value and return */
|
|
(state->note)(HASH_ZERO(state->base), state);
|
|
return state;
|
|
}
|
|
|
|
/*
|
|
* prep for a ZVALUE hash
|
|
*/
|
|
(state->note)(HASH_ZVALUE(state->base), state);
|
|
/* note if we have a negative value */
|
|
if (zisneg(zval)) {
|
|
(state->note)(HASH_NEG(state->base), state);
|
|
}
|
|
|
|
#if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16
|
|
|
|
/*
|
|
* hash full chunks
|
|
*
|
|
* We need to convert the array of HALFs into canonical architectural
|
|
* independent form -- 32 bit arrays. Because we have 16 bit values
|
|
* in Big Endian form, we need to swap 16 bit values so that they
|
|
* appear as 32 bit Big Endian values.
|
|
*/
|
|
chunkhalf = state->chunksize/sizeof(HALF);
|
|
full_lim = (zval.len / chunkhalf) * chunkhalf;
|
|
for (i=0; i < full_lim; i += chunkhalf) {
|
|
/* HALF swap copy a chunk into a data buffer */
|
|
for (j=0; j < chunkhalf; j += 2) {
|
|
half[j] = zval.v[i+j+1];
|
|
half[j+1] = zval.v[i+j];
|
|
}
|
|
(state->update)(state, (USB8*) half, state->chunksize);
|
|
}
|
|
|
|
/*
|
|
* hash the final partial chunk (if any)
|
|
*
|
|
* We need to convert the array of HALFs into canonical architectural
|
|
* independent form -- 32 bit arrays. Because we have 16 bit values
|
|
* in Big Endian form, we need to swap 16 bit values so that they
|
|
* appear as 32 bit Big Endian values.
|
|
*/
|
|
if (zval.len > full_lim) {
|
|
for (j=0; j < zval.len-full_lim-1; j += 2) {
|
|
half[j] = zval.v[full_lim+j+1];
|
|
half[j+1] = zval.v[full_lim+j];
|
|
}
|
|
if (j < zval.len-full_lim) {
|
|
half[j] = (HALF)0;
|
|
half[j+1] = zval.v[zval.len-1];
|
|
--full_lim;
|
|
}
|
|
(state->update)(state, (USB8 *) half,
|
|
(zval.len-full_lim)*sizeof(HALF));
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
|
* hash the array of HALFs
|
|
*
|
|
* The array of HALFs is equivalent to the canonical architectural
|
|
* independent form. We either have 32 bit HALFs (in which case
|
|
* we do not case the byte order) or we have 16 bit HALFs in Little
|
|
* Endian order (which happens to be laid out in the same order as
|
|
* 32 bit values).
|
|
*/
|
|
(state->update)(state, (USB8 *)zval.v, zval.len*sizeof(HALF));
|
|
|
|
#if BASEB == 16
|
|
if (zval.len & 1) { /* padding to complete word */
|
|
half[0] = 0;
|
|
(state->update)(state, (USB8 *) half, 2);
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_number - hash a NUMBER
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* n - the NUMBER
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_number(int type, void *n, HASH *state)
|
|
{
|
|
NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */
|
|
bool sign; /* sign of the denominator */
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the NUMBER hash
|
|
*/
|
|
(state->chkpt)(state);
|
|
state->bytes = false;
|
|
|
|
/*
|
|
* process the numerator
|
|
*/
|
|
state = hash_zvalue(type, number->num, state);
|
|
|
|
/*
|
|
* if the NUMBER is not an integer, process the denominator
|
|
*/
|
|
if (qisfrac(number)) {
|
|
|
|
/* note the division */
|
|
(state->note)(HASH_DIV(state->base), state);
|
|
|
|
/* hash denominator as positive -- just in case */
|
|
sign = number->den.sign;
|
|
number->den.sign = 0;
|
|
|
|
/* hash the denominator */
|
|
state = hash_zvalue(type, number->den, state);
|
|
|
|
/* restore the sign */
|
|
number->den.sign = sign;
|
|
}
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_complex - hash a COMPLEX
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* c - the COMPLEX
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_complex(int type, void *c, HASH *state)
|
|
{
|
|
COMPLEX *complex = (COMPLEX *)c; /* c as a COMPLEX pointer */
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the COMPLEX hash
|
|
*/
|
|
(state->chkpt)(state);
|
|
state->bytes = false;
|
|
|
|
/*
|
|
* catch the zero special case
|
|
*/
|
|
if (ciszero(complex)) {
|
|
/* note a zero numeric value and return */
|
|
(state->note)(HASH_ZERO(state->base), state);
|
|
return state;
|
|
}
|
|
|
|
/*
|
|
* process the real value if not pure imaginary
|
|
*
|
|
* We will ignore the real part if the value is of the form 0+xi.
|
|
*/
|
|
if (!qiszero(complex->real)) {
|
|
state = hash_number(type, complex->real, state);
|
|
}
|
|
|
|
/*
|
|
* if the NUMBER is not real, process the imaginary value
|
|
*
|
|
* We will ignore the imaginary part of the value is of the form x+0i.
|
|
*/
|
|
if (!cisreal(complex)) {
|
|
|
|
/* note the sqrt(-1) */
|
|
(state->note)(HASH_COMPLEX(state->base), state);
|
|
|
|
/* hash the imaginary value */
|
|
state = hash_number(type, complex->imag, state);
|
|
}
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_str - hash a null-terminated string
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* str - the string
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_str(int type, char *str, HASH *state)
|
|
{
|
|
size_t len; /* string length */
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the string hash
|
|
*/
|
|
if (!state->bytes) {
|
|
(state->chkpt)(state);
|
|
state->bytes = true;
|
|
}
|
|
|
|
len = strlen(str);
|
|
|
|
/*
|
|
* hash the string
|
|
*/
|
|
(state->update)(state, (USB8*)str, len);
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_STR - hash a STRING
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* str - the STRING
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_STR(int type, STRING *str, HASH *state)
|
|
{
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the string hash
|
|
*/
|
|
if (!state->bytes) {
|
|
(state->chkpt)(state);
|
|
state->bytes = true;
|
|
}
|
|
|
|
/*
|
|
* hash the string
|
|
*/
|
|
(state->update)(state, (USB8*) str->s_str, (USB32) str->s_len);
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_usb8 - hash an array of USB8s
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* byte - pointer to an array of USB8s
|
|
* len - number of USB8s to hash
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_usb8(int type, USB8 *byte, int len, HASH *state)
|
|
{
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* setup for the string hash
|
|
*/
|
|
if (!state->bytes) {
|
|
(state->chkpt)(state);
|
|
state->bytes = true;
|
|
}
|
|
|
|
/*
|
|
* hash the array of octets
|
|
*/
|
|
(state->update)(state, byte, (USB32)len);
|
|
|
|
/*
|
|
* all done
|
|
*/
|
|
return state;
|
|
}
|
|
|
|
|
|
/*
|
|
* hash_value - hash a value
|
|
*
|
|
* given:
|
|
* type - hash type (see hash.h)
|
|
* v - the value
|
|
* state - the state to hash or NULL
|
|
*
|
|
* returns:
|
|
* the new state
|
|
*/
|
|
HASH *
|
|
hash_value(int type, void *v, HASH *state)
|
|
{
|
|
LISTELEM *ep; /* list element pointer */
|
|
ASSOCELEM **assochead; /* association chain head */
|
|
ASSOCELEM *aep; /* current association value */
|
|
ASSOCELEM *nextaep; /* next association value */
|
|
VALUE *value = (VALUE *)v; /* v cast to a VALUE */
|
|
VALUE *vp; /* pointer to next OBJ table value */
|
|
ZVALUE fileval; /* size, position, dev, inode of a file */
|
|
int i;
|
|
|
|
/*
|
|
* initialize if state is NULL
|
|
*/
|
|
if (state == NULL) {
|
|
state = hash_init(type, NULL);
|
|
}
|
|
|
|
/*
|
|
* process the value type
|
|
*/
|
|
switch (value->v_type) {
|
|
case V_NULL:
|
|
(state->chkpt)(state);
|
|
state->bytes = true;
|
|
break;
|
|
|
|
case V_INT:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash as if we have a 64 bit value */
|
|
state = hash_int(type, value->v_int, state);
|
|
break;
|
|
|
|
case V_NUM:
|
|
/* hash this type */
|
|
state = hash_number(type, value->v_num, state);
|
|
break;
|
|
|
|
case V_COM:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash this type */
|
|
state = hash_complex(type, value->v_com, state);
|
|
break;
|
|
|
|
case V_ADDR:
|
|
/* there is nothing to setup, simply hash what we point at */
|
|
state = hash_value(type, value->v_addr, state);
|
|
break;
|
|
|
|
case V_STR:
|
|
/* strings have no setup */
|
|
|
|
/* hash this type */
|
|
state = hash_STR(type, value->v_str, state);
|
|
break;
|
|
|
|
case V_MAT:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
state->bytes = true;
|
|
|
|
/* hash all the elements of the matrix */
|
|
for (i=0; i < value->v_mat->m_size; ++i) {
|
|
|
|
/* hash the next matrix value */
|
|
state = hash_value(type,
|
|
value->v_mat->m_table+i, state);
|
|
state->bytes = false; /* as if reading words */
|
|
}
|
|
break;
|
|
|
|
case V_LIST:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash all the elements of the list */
|
|
for (i=0, ep = value->v_list->l_first;
|
|
ep != NULL && i < value->v_list->l_count;
|
|
++i, ep = ep->e_next) {
|
|
|
|
/* hash the next list value */
|
|
state = hash_value(type, &ep->e_value, state);
|
|
state->bytes = false; /* as if reading words */
|
|
}
|
|
break;
|
|
|
|
case V_ASSOC:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
state->bytes = true;
|
|
|
|
/* hash the association */
|
|
assochead = value->v_assoc->a_table;
|
|
for (i = 0; i < value->v_assoc->a_size; i++) {
|
|
nextaep = *assochead;
|
|
while (nextaep) {
|
|
aep = nextaep;
|
|
nextaep = aep->e_next;
|
|
|
|
/* hash the next association value */
|
|
state = hash_value(type, &aep->e_value, state);
|
|
state->bytes = false; /* as if reading words */
|
|
}
|
|
assochead++;
|
|
}
|
|
break;
|
|
|
|
case V_OBJ:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
state->bytes = true; /* reading bytes */
|
|
|
|
/* hash the object name and then the element values */
|
|
|
|
state = hash_str(type, objtypename(
|
|
value->v_obj->o_actions->oa_index), state);
|
|
(state->chkpt)(state);
|
|
|
|
for (i=value->v_obj->o_actions->oa_count,
|
|
vp=value->v_obj->o_table;
|
|
i-- > 0;
|
|
vp++) {
|
|
|
|
/* hash the next object value */
|
|
state = hash_value(type, vp, state);
|
|
state->bytes = false; /* as if reading words */
|
|
}
|
|
break;
|
|
|
|
case V_FILE:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash file length if possible */
|
|
if (getsize(value->v_file, &fileval) == 0) {
|
|
state = hash_zvalue(type, fileval, state);
|
|
zfree(fileval);
|
|
} else {
|
|
/* hash -1 for invalid length */
|
|
state = hash_long(type, (long)-1, state);
|
|
}
|
|
/* hash the file position if possible */
|
|
if (getloc(value->v_file, &fileval) == 0) {
|
|
state = hash_zvalue(type, fileval, state);
|
|
zfree(fileval);
|
|
} else {
|
|
/* hash -1 for invalid location */
|
|
state = hash_long(type, (long)-1, state);
|
|
}
|
|
/* hash the file device if possible */
|
|
if (get_device(value->v_file, &fileval) == 0) {
|
|
state = hash_zvalue(type, fileval, state);
|
|
zfree(fileval);
|
|
} else {
|
|
/* hash -1 for invalid device */
|
|
state = hash_long(type, (long)-1, state);
|
|
}
|
|
/* hash the file inode if possible */
|
|
if (get_inode(value->v_file, &fileval) == 0) {
|
|
state = hash_zvalue(type, fileval, state);
|
|
zfree(fileval);
|
|
} else {
|
|
/* hash -1 for invalid inode */
|
|
state = hash_long(type, (long)-1, state);
|
|
}
|
|
break;
|
|
|
|
case V_RAND:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash the RAND state */
|
|
state = hash_int(type, value->v_rand->seeded, state);
|
|
state = hash_int(type, value->v_rand->bits, state);
|
|
(state->update)(state,
|
|
(USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8);
|
|
state = hash_int(type, value->v_rand->j, state);
|
|
state = hash_int(type, value->v_rand->k, state);
|
|
state = hash_int(type, value->v_rand->need_to_skip, state);
|
|
(state->update)(state,
|
|
(USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8);
|
|
(state->update)(state,
|
|
(USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8);
|
|
state->bytes = false; /* as if reading words */
|
|
break;
|
|
|
|
case V_RANDOM:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash the RANDOM state */
|
|
state = hash_int(type, value->v_random->seeded, state);
|
|
state = hash_int(type, value->v_random->bits, state);
|
|
(state->update)(state,
|
|
(USB8 *)&(value->v_random->buffer), BASEB/8);
|
|
state = hash_zvalue(type, value->v_random->r, state);
|
|
state = hash_zvalue(type, value->v_random->n, state);
|
|
state->bytes = false; /* as if reading words */
|
|
break;
|
|
|
|
case V_CONFIG:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash the CONFIG state */
|
|
state = hash_int(type, value->v_config->outmode, state);
|
|
state = hash_int(type, value->v_config->outmode2, state);
|
|
state = hash_long(type,(long)value->v_config->outdigits, state);
|
|
state = hash_number(type, value->v_config->epsilon, state);
|
|
state = hash_long(type,
|
|
(long)value->v_config->epsilonprec, state);
|
|
state = hash_flag(type, value->v_config->traceflags, state);
|
|
state = hash_long(type, (long)value->v_config->maxprint, state);
|
|
state = hash_len(type, value->v_config->mul2, state);
|
|
state = hash_len(type, value->v_config->sq2, state);
|
|
state = hash_len(type, value->v_config->pow2, state);
|
|
state = hash_len(type, value->v_config->redc2, state);
|
|
state = hash_bool(type, value->v_config->tilde_ok, state);
|
|
state = hash_bool(type, value->v_config->tilde_space, state);
|
|
state = hash_bool(type, value->v_config->tab_ok, state);
|
|
state = hash_long(type, (long)value->v_config->quomod, state);
|
|
state = hash_long(type, (long)value->v_config->quo, state);
|
|
state = hash_long(type, (long)value->v_config->mod, state);
|
|
state = hash_long(type, (long)value->v_config->sqrt, state);
|
|
state = hash_long(type, (long)value->v_config->appr, state);
|
|
state = hash_long(type, (long)value->v_config->cfappr, state);
|
|
state = hash_long(type, (long)value->v_config->cfsim, state);
|
|
state = hash_long(type, (long)value->v_config->outround, state);
|
|
state = hash_long(type, (long)value->v_config->round, state);
|
|
state = hash_bool(type, value->v_config->leadzero, state);
|
|
state = hash_bool(type, value->v_config->fullzero, state);
|
|
state = hash_long(type,
|
|
(long)value->v_config->maxscancount, state);
|
|
state = hash_str(type, value->v_config->prompt1, state);
|
|
state->bytes = false; /* as if just read words */
|
|
state = hash_str(type, value->v_config->prompt2, state);
|
|
state->bytes = false; /* as if just read words */
|
|
state = hash_int(type, value->v_config->blkmaxprint, state);
|
|
state = hash_bool(type, value->v_config->blkverbose, state);
|
|
state = hash_int(type, value->v_config->blkbase, state);
|
|
state = hash_int(type, value->v_config->blkfmt, state);
|
|
state = hash_long(type,
|
|
(long)value->v_config->resource_debug, state);
|
|
state = hash_long(type,
|
|
(long)value->v_config->calc_debug, state);
|
|
state = hash_long(type,
|
|
(long)value->v_config->user_debug, state);
|
|
state = hash_bool(type, value->v_config->verbose_quit, state);
|
|
state = hash_int(type, value->v_config->ctrl_d, state);
|
|
state = hash_str(type, value->v_config->program, state);
|
|
state = hash_str(type, value->v_config->base_name, state);
|
|
state = hash_bool(type, value->v_config->windows, state);
|
|
state = hash_bool(type, value->v_config->cygwin, state);
|
|
state = hash_bool(type, value->v_config->compile_custom, state);
|
|
if (value->v_config->allow_custom != NULL &&
|
|
*(value->v_config->allow_custom)) {
|
|
state = hash_bool(type, true, state);
|
|
} else {
|
|
state = hash_bool(type, false, state);
|
|
}
|
|
state = hash_str(type, value->v_config->version, state);
|
|
state = hash_int(type, value->v_config->baseb, state);
|
|
state = hash_bool(type, value->v_config->redecl_warn, state);
|
|
state = hash_bool(type, value->v_config->dupvar_warn, state);
|
|
state = hash_bool(type, value->v_config->fraction_space, state);
|
|
break;
|
|
|
|
case V_HASH:
|
|
/* setup for the this value type */
|
|
(state->chkpt)(state);
|
|
(state->type)(value->v_type, state);
|
|
|
|
/* hash the HASH state */
|
|
state = hash_int(type, value->v_hash->type, state);
|
|
state = hash_bool(type, value->v_hash->bytes,state);
|
|
state = hash_int(type, value->v_hash->base, state);
|
|
state = hash_int(type, value->v_hash->chunksize, state);
|
|
state = hash_int(type, value->v_hash->unionsize, state);
|
|
(state->update)(state,
|
|
value->v_hash->h_union.data, state->unionsize);
|
|
state->bytes = false; /* as if reading words */
|
|
break;
|
|
|
|
case V_BLOCK:
|
|
/* there is no setup for a BLOCK */
|
|
|
|
/* hash the octets in the BLOCK */
|
|
if (value->v_block->datalen > 0) {
|
|
state = hash_usb8(type, value->v_block->data,
|
|
value->v_block->datalen, state);
|
|
}
|
|
break;
|
|
|
|
case V_OCTET:
|
|
/* there is no setup for an OCTET */
|
|
|
|
/* hash the OCTET */
|
|
state = hash_usb8(type, value->v_octet, 1, state);
|
|
break;
|
|
|
|
case V_NBLOCK:
|
|
/* there is no setup for a NBLOCK */
|
|
|
|
/* hash the octets in the NBLOCK */
|
|
if (value->v_nblock->blk->datalen > 0) {
|
|
state = hash_usb8(type, value->v_nblock->blk->data,
|
|
value->v_nblock->blk->datalen,
|
|
state);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
math_error("hashing an unknown value");
|
|
not_reached();
|
|
}
|
|
return state;
|
|
}
|