From 646b95d113309378591b75a290ee6c62a04f3772 Mon Sep 17 00:00:00 2001 From: Wiimm Date: Wed, 30 Sep 2020 13:20:16 +0200 Subject: SZS v2.20a.beta1: Test Mac build --- project/dclib/dclib-basics.h | 105 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 15 deletions(-) (limited to 'project/dclib/dclib-basics.h') diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h index 96053d6..a13c748 100644 --- a/project/dclib/dclib-basics.h +++ b/project/dclib/dclib-basics.h @@ -1156,12 +1156,18 @@ void PrintSettingsDCLIB ( FILE *f, int indent ); void SetupProgname ( int argc, char ** argv, ccp tool_name, ccp tool_vers, ccp tool_title ); -// return NULL or 'progpath', calc GetProgramPath() once if needed +// return NULL or 'ProgInfo.progpath', calc GetProgramPath() once if needed ccp ProgramPath(void); -// return NULL or 'progdir', calc ProgramPath() once if needed +// return NULL or 'ProgInfo.progdir', calc ProgramPath() once if needed ccp ProgramDirectory(void); +// path0 can be a directory or a filename (->dir extracted) +void DefineLogDirectory ( ccp path0, bool force ); + +// get 'ProgInfo.logdir' without tailing '/' ("." as fall back) +ccp GetLogDirectory(); + #ifdef __CYGWIN__ ccp ProgramPathNoExt(void); #else @@ -2251,8 +2257,10 @@ uint EncodeBase64 int source_len, // length of 'source'; if <0: use strlen(source) const char encode64[64+1], // encoding table; if NULL: use TableEncode64default bool use_filler, // use filler for aligned output + ccp next_line, // not NULL: use this string as new line sep - uint next_line_trigger // >0: use 'next_line' every # input bytes + uint bytes_per_line // >0: use 'next_line' every # input bytes + // will be rounded down to multiple of 3 ); //----------------------------------------------------------------------------- @@ -2268,15 +2276,35 @@ mem_t EncodeBase64Circ const char encode64[64+1] // encoding table; if NULL: use TableEncode64default ); +//----------------------------------------------------------------------------- + +uint EncodeBase64ml // ml: multi line +( + // returns the number of scanned bytes of 'source' + + char *buf, // valid destination buffer + uint buf_size, // size of 'buf', >= 4 + const void *source, // NULL or data to encode + int source_len, // length of 'source'; if <0: use strlen(source) + const char encode64[64+1], // encoding table; if NULL: use TableEncode64default + bool use_filler, // use filler for aligned output + + int indent, // indention of output + ccp prefix, // NULL or prefix before encoded data + ccp eol, // line terminator, if NULL then use NL + int bytes_per_line // create a new line every # input bytes + // will be rounded down to multiple of 3 +); + /////////////////////////////////////////////////////////////////////////////// -static inline uint EncodeBase64Len ( uint src_len ) +static inline uint GetEncodeBase64Len ( uint src_len ) { return 4 * (src_len+2) / 3; } -static inline uint EncodeBase64FillLen ( uint src_len ) +static inline uint GetEncodeBase64FillLen ( uint src_len ) { return (src_len+2) / 3 * 4; } -static inline uint DecodeBase64Len ( uint src_len ) +static inline uint GetDecodeBase64Len ( uint src_len ) { return 3 * src_len / 4; } /////////////////////////////////////////////////////////////////////////////// @@ -3396,7 +3424,7 @@ ccp PrintTimeByFormat // returns temporary buffer by GetCircBuf(); ccp format, // format string for strftime() - time_t time // seconds since epoch -> time() + time_t tim // seconds since epoch; 0 is replaced by time() ); ccp PrintTimeByFormatUTC @@ -3404,7 +3432,7 @@ ccp PrintTimeByFormatUTC // returns temporary buffer by GetCircBuf(); ccp format, // format string for strftime() - time_t time // seconds since epoch -> time() + time_t tim // seconds since epoch; 0 is replaced by time() ); //----------------------------------------------------------------------------- @@ -3414,7 +3442,8 @@ ccp PrintUsecByFormat // returns temporary buffer by GetCircBuf(); ccp format, // format string for strftime() - time_t time, // seconds since epoch -> time() + // 1-6 '@' in row replaced by digits of 'usec' + time_t tim, // seconds since epoch uint usec // micro second of second ); @@ -3423,13 +3452,13 @@ ccp PrintUsecByFormatUTC // returns temporary buffer by GetCircBuf(); ccp format, // format string for strftime() - time_t time, // seconds since epoch -> time() + // 1-6 '@' in row replaced by digits of 'usec' + time_t tim, // seconds since epoch uint usec // micro second of second ); //----------------------------------------------------------------------------- - ccp PrintTimevalByFormat ( // returns temporary buffer by GetCircBuf(); @@ -3438,7 +3467,6 @@ ccp PrintTimevalByFormat const struct timeval *tv // time to print, if NULL use gettimeofday() ); - ccp PrintTimevalByFormatUTC ( // returns temporary buffer by GetCircBuf(); @@ -4856,6 +4884,7 @@ typedef enum SaveRestoreType_t SRT_BOOL, // type bool SRT_UINT, // unsigned int of any size (%llu) SRT_HEX, // unsigned int of any size as hex (%#llx) + SRT_COUNT, // unsigned int of any size (%llu), used as array counter SRT_INT, // signed int of any size (%lld) SRT_FLOAT, // float (%.8g) or double (%.16g) or long double (%.20g) SRT_XFLOAT, // float or double or long double as hex-float (%a/%La) @@ -4864,10 +4893,15 @@ typedef enum SaveRestoreType_t SRT_STRING_ALLOC, // alloced string, var is ccp or char* SRT_MEM, // alloced string, var is mem_t + SRT_DEF_ARRAY, // define/end an array of structs + SRT__IS_LIST, //----- from here: print lists; also used as separator SRT_STRING_FIELD, // var is StringField_t SRT_PARAM_FIELD, // var is ParamField_t + + + SRT_F_SIZE = 0x100, // factor for implicit size-modes for numerical types } SaveRestoreType_t; @@ -4879,7 +4913,8 @@ typedef struct SaveRestoreTab_t uint offset; // offset of variable uint size; // sizeof( var or string ) ccp name; // name in configuration file - u16 n_elem; // >0: is array with N elements + s16 n_elem; // >0: is array with N elements + // <0: is array with -N elements, use last SRT_COUNT u8 type; // SaveRestoreType_t u8 emode; // EncodeMode_t } @@ -4896,6 +4931,7 @@ __attribute__ ((packed)) SaveRestoreTab_t; #define DEF_SRT_BOOL(v,n) DEF_SRT_VAR(v,1,n,SRT_BOOL,0) #define DEF_SRT_UINT(v,n) DEF_SRT_VAR(v,1,n,SRT_UINT,0) #define DEF_SRT_HEX(v,n) DEF_SRT_VAR(v,1,n,SRT_HEX,0) +#define DEF_SRT_COUNT(v,n) DEF_SRT_VAR(v,1,n,SRT_COUNT,0) #define DEF_SRT_INT(v,n) DEF_SRT_VAR(v,1,n,SRT_INT,0) #define DEF_SRT_FLOAT(v,n) DEF_SRT_VAR(v,1,n,SRT_FLOAT,0) #define DEF_SRT_XFLOAT(v,n) DEF_SRT_VAR(v,1,n,SRT_XFLOAT,0) @@ -4907,7 +4943,7 @@ __attribute__ ((packed)) SaveRestoreTab_t; #define DEF_SRT_STRING_FIELD(v,n,e) DEF_SRT_VAR(v,1,n,SRT_STRING_FIELD,e) #define DEF_SRT_PARAM_FIELD(v,n,e) DEF_SRT_VAR(v,1,n,SRT_PARAM_FIELD,e) -//--- n elements +//--- n elements : if n<0, then n_elem=-n && use last SRT_COUNT #define DEF_SRT_BOOL_N(v,ne,n) DEF_SRT_VAR(v,ne,n,SRT_BOOL,0) #define DEF_SRT_UINT_N(v,ne,n) DEF_SRT_VAR(v,ne,n,SRT_UINT,0) @@ -4937,6 +4973,40 @@ __attribute__ ((packed)) SaveRestoreTab_t; #define DEF_SRT_STR_ALLOC_A(v,n,e) DEF_SRT_ARRAY(v,n,SRT_STRING_ALLOC,e) #define DEF_SRT_MEM_A(v,n,e) DEF_SRT_ARRAY(v,n,SRT_MEM,e) +//--- auto array, use last SRT_COUNT for element-count + +#define DEF_SRT_ARRAY_C(v,n,t,e) \ + {offsetof(SRT_NAME,v), sizeof(((SRT_NAME*)0)->v[0]), n, \ + -(s16)(sizeof(((SRT_NAME*)0)->v)/sizeof(*((SRT_NAME*)0)->v)), t, e } + +#define DEF_SRT_BOOL_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_BOOL,0) +#define DEF_SRT_UINT_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_UINT,0) +#define DEF_SRT_HEX_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_HEX,0) +#define DEF_SRT_INT_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_INT,0) +#define DEF_SRT_FLOAT_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_FLOAT,0) +#define DEF_SRT_XFLOAT_AC(v,n) DEF_SRT_ARRAY_C(v,n,SRT_XFLOAT,0) + +#define DEF_SRT_STR_SIZE_AC(v,n,e) DEF_SRT_ARRAY_C(v,n,SRT_STRING_SIZE,e) +#define DEF_SRT_STR_ALLOC_AC(v,n,e) DEF_SRT_ARRAY_C(v,n,SRT_STRING_ALLOC,e) +#define DEF_SRT_MEM_AC(v,n,e) DEF_SRT_ARRAY_C(v,n,SRT_MEM,e) + +//--- array of structs + +#define DEF_SRT_ARRAY_FL(f,l) \ + {offsetof(SRT_NAME,f), sizeof(((SRT_NAME*)0)->f), 0, \ + (offsetof(SRT_NAME,l)-offsetof(SRT_NAME,f))/sizeof(((SRT_NAME*)0)->f)+1, \ + SRT_DEF_ARRAY, 0 } + +#define DEF_SRT_ARRAY_FLC(f,l) \ + {offsetof(SRT_NAME,f), sizeof(((SRT_NAME*)0)->f), 0, \ + -(s16)((offsetof(SRT_NAME,l)-offsetof(SRT_NAME,f)) \ + /sizeof(((SRT_NAME*)0)->f)+1), SRT_DEF_ARRAY, 0 } + +#define DEF_SRT_ARRAY_N(v,ne) DEF_SRT_VAR(v[0],ne,0,SRT_DEF_ARRAY,0) +#define DEF_SRT_ARRAY_A(v) DEF_SRT_ARRAY(v,0,SRT_DEF_ARRAY,0) +#define DEF_SRT_ARRAY_AC(v) DEF_SRT_ARRAY_C(v,0,SRT_DEF_ARRAY,0) +#define DEF_SRT_ARRAY_END() {0,0,0,0,SRT_DEF_ARRAY,0} + //--- special #define DEF_SRT_SEPARATOR() {0,0,0,0,SRT__IS_LIST,0} @@ -4945,6 +5015,9 @@ __attribute__ ((packed)) SaveRestoreTab_t; /////////////////////////////////////////////////////////////////////////////// +extern int srt_auto_dump; +extern FILE *srt_auto_dump_file; + void DumpStateTable ( FILE *f, // valid output file @@ -5234,7 +5307,9 @@ extern int opt_new; // default 0 float double2float ( double d ); // reduce precision -uint CreateUniqueId ( int range ); +uint CreateUniqueIdN ( int range ); +static inline uint CreateUniqueId() { return CreateUniqueIdN(1); } +static inline uint CreateUniqueIdNBO() { return htonl(CreateUniqueIdN(1)); } void Sha1Hex2Bin ( sha1_hash_t bin, ccp src, ccp end ); void Sha1Bin2Hex ( sha1_hex_t hex, cvp bin ); -- cgit v1.3.1