aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
Diffstat (limited to 'project/dclib')
-rw-r--r--project/dclib/dclib-basics.c404
-rw-r--r--project/dclib/dclib-basics.h105
-rw-r--r--project/dclib/dclib-color.c303
-rw-r--r--project/dclib/dclib-color.h6
-rw-r--r--project/dclib/dclib-debug.c368
-rw-r--r--project/dclib/dclib-debug.h65
-rw-r--r--project/dclib/dclib-file.c642
-rw-r--r--project/dclib/dclib-file.h112
-rw-r--r--project/dclib/dclib-network.c4
-rw-r--r--project/dclib/dclib-network.h22
-rw-r--r--project/dclib/dclib-numeric.c89
-rw-r--r--project/dclib/dclib-ui.c4
-rw-r--r--project/dclib/dclib-xdump.c39
-rw-r--r--project/dclib/dclib-xdump.h18
14 files changed, 1208 insertions, 973 deletions
diff --git a/project/dclib/dclib-basics.c b/project/dclib/dclib-basics.c
index 4a166df..64ea883 100644
--- a/project/dclib/dclib-basics.c
+++ b/project/dclib/dclib-basics.c
@@ -148,12 +148,13 @@ void PrintSettingsDCLIB ( FILE *f, int indent )
#endif
}
+//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void SetupMultiProcessing()
{
- multi_processing = true;
+ ProgInfo.multi_processing = true;
}
///////////////////////////////////////////////////////////////////////////////
@@ -161,27 +162,28 @@ void SetupMultiProcessing()
void SetupProgname ( int argc, char ** argv, ccp tname, ccp tvers, ccp ttitle )
{
if (tname)
- toolname = tname;
+ ProgInfo.toolname = tname;
if (tvers)
- toolversion = tvers;
+ ProgInfo.toolversion = tvers;
if (ttitle)
- tooltitle = ttitle;
+ ProgInfo.tooltitle = ttitle;
- if (!progpath)
+ if (!ProgInfo.progpath)
{
char path[PATH_MAX];
int res = GetProgramPath( path, sizeof(path), true, argc > 0 ? argv[0] : 0 );
if ( res > 0 )
- progpath = STRDUP(path);
+ ProgInfo.progpath = STRDUP(path);
}
if ( argc > 0 && *argv && **argv )
{
ccp slash = strrchr(*argv,'/');
- progname = slash ? slash + 1 : *argv;
+ ProgInfo.progname = slash ? slash + 1 : *argv;
}
else
- progname = toolname && *toolname ? toolname : "?";
+ ProgInfo.progname = ProgInfo.toolname && *ProgInfo.toolname
+ ? ProgInfo.toolname : "?";
}
///////////////////////////////////////////////////////////////////////////////
@@ -189,33 +191,78 @@ void SetupProgname ( int argc, char ** argv, ccp tname, ccp tvers, ccp ttitle )
ccp ProgramPath()
{
static bool done = false;
- if ( !progpath && !done )
+ if ( !ProgInfo.progpath && !done )
{
done = true;
char path[PATH_MAX];
int res = GetProgramPath( path, sizeof(path), true, 0 );
if ( res > 0 )
- progpath = STRDUP(path);
+ ProgInfo.progpath = STRDUP(path);
}
- return progpath;
+ return ProgInfo.progpath;
}
///////////////////////////////////////////////////////////////////////////////
ccp ProgramDirectory()
{
- if (!progdir)
+ if (!ProgInfo.progdir)
{
ccp path = ProgramPath();
if (path)
{
ccp end = strrchr(path,'/');
const uint len = end ? end - path : strlen(path);
- progdir = MEMDUP(path,len);
+ ProgInfo.progdir = MEMDUP(path,len);
}
}
- return progdir;
+ return ProgInfo.progdir;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+void DefineLogDirectory ( ccp path0, bool force )
+{
+ PRINT("DefineLogDirectory(%s,%d)\n",path0,force);
+ if ( path0 && *path0 && ( force || !ProgInfo.logdir ))
+ {
+ char path[PATH_MAX];
+ StringCopyS(path,sizeof(path),path0);
+ if (!ExistDirectory(path,0))
+ {
+ char *slash = strrchr(path,'/');
+ if (slash)
+ *slash = 0;
+ else
+ {
+ path[0] = '.';
+ path[1] = 0;
+ }
+
+ if (!ExistDirectory(path,0))
+ return;
+ }
+
+ int len = strlen(path);
+ while ( len > 0 && path[len-1] == '/' )
+ path[--len] = 0;
+
+ if ( len > 0 )
+ {
+ FreeString(ProgInfo.logdir);
+ ProgInfo.logdir = MEMDUP(path,len);
+ PRINT("#LOG-DIR: %s\n",ProgInfo.logdir);
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+
+ccp GetLogDirectory()
+{
+ return ProgInfo.logdir ? ProgInfo.logdir : ".";
}
///////////////////////////////////////////////////////////////////////////////
@@ -401,8 +448,8 @@ char * StringCat2E ( char * buf, ccp buf_end, ccp src1, ccp src2 )
// RESULT: end of copied string pointing to NULL
// 'src*' may be a NULL pointer.
- ASSERT(buf);
- ASSERT(buf<buf_end);
+ DASSERT(buf);
+ DASSERT(buf<buf_end);
buf_end--;
if (src1)
@@ -431,8 +478,8 @@ char * StringCat3E ( char * buf, ccp buf_end, ccp src1, ccp src2, ccp src3 )
// RESULT: end of copied string pointing to NULL
// 'src*' may be a NULL pointer.
- ASSERT(buf);
- ASSERT(buf<buf_end);
+ DASSERT(buf);
+ DASSERT(buf<buf_end);
buf_end--;
if (src1)
@@ -2049,7 +2096,7 @@ int ScanSplitArg
**argv_buf = argv_predef,
**argv_dest = argv_predef,
**argv_end = argv_predef + N_PREDEF;
- *argv_dest++ = progname ? (char*)progname : "";
+ *argv_dest++ = ProgInfo.progname ? (char*)ProgInfo.progname : "";
uint argv_size = 0;
if (!work_buf)
@@ -5085,309 +5132,6 @@ enumError Command_COLORS
//
///////////////////////////////////////////////////////////////////////////////
-/////////////// global commands: TESTCOLORS ///////////////
-///////////////////////////////////////////////////////////////////////////////
-// [[color_info_t]]
-
-typedef struct color_info_t
-{
- bool valid; // >0: data below is valid
-
- u8 m_index; // index of 0..255 for "\e[*m"
-
- s8 m_red; // -1:invalid, 0..5: red value of 'm_index'
- s8 m_green; // -1:invalid, 0..5: green value of 'm_index'
- s8 m_blue; // -1:invalid, 0..5: blue value of 'm_index'
- s8 m_gray; // -1:invalid, 0..23: gray value of 'm_index'
-
- u32 ref_color; // reference colors, based on 'm_index';
- u32 src_color; // scanned color
-}
-color_info_t;
-
-///////////////////////////////////////////////////////////////////////////////
-
-static bool AssignColorInfo ( color_info_t *ci, u32 rgb )
-{
- DASSERT(ci);
- memset(ci,0,sizeof(*ci));
-
- ci->src_color = rgb & 0xffffff;
- ci->m_index = ConvertColorRGBToM256(ci->src_color);
- ci->ref_color = ConvertColorM256ToRGB(ci->m_index);
-
- const uint r = ci->ref_color >> 16 & 0xff;
- const uint g = ci->ref_color >> 8 & 0xff;
- const uint b = ci->ref_color & 0xff;
-
- ci->m_red = SingleColorToM6(r);
- ci->m_green = SingleColorToM6(g);
- ci->m_blue = SingleColorToM6(b);
-
- ci->m_gray = ( r + g + b + 21 ) / 30;
- if ( ci->m_gray > 23 )
- ci->m_gray = 23;
- else if ( ci->m_gray > 0 )
- ci->m_gray--;
-
- return ci->valid = 1;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static bool ScanColorInfo ( color_info_t *ci, ccp arg )
-{
- DASSERT(ci);
- memset(ci,0,sizeof(*ci));
- if ( arg && *arg )
- {
- arg = SkipControls(arg);
-
- ulong num, r, g, b;
- if ( *arg >= 'g' && *arg <= 'z' )
- {
- const char mode = *arg;
- arg = SkipControls(arg+1);
-
- num = str2ul(arg,0,10);
- switch (mode)
- {
- case 'm':
- return AssignColorInfo(ci,ConvertColorM256ToRGB(num));
-
- case 'g':
- return AssignColorInfo(ci,ConvertColorM256ToRGB(232 + num % 24));
-
- case 'c':
- r = num / 100 % 10;
- g = num / 10 % 10;
- b = num % 10;
- goto rgb5;
- }
- }
- else
- {
- char *end;
- num = str2ul(arg,&end,16);
-
- ci->valid = true;
- if ( end - arg <= 3 )
- {
- r = num >> 8 & 15;
- g = num >> 4 & 15;
- b = num & 15;
-
- rgb5:
- if ( r > 5 ) r = 5;
- if ( g > 5 ) g = 5;
- if ( b > 5 ) b = 5;
- return AssignColorInfo(ci,ConvertColorM256ToRGB(16 + 36*r + 6*g + b));
- }
- return AssignColorInfo(ci,num);
- }
- }
-
- return ci->valid;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static void PrintColorInfo ( FILE *f, color_info_t *ci )
-{
- DASSERT(f);
- DASSERT(ci);
-
- if (ci->valid)
- fprintf(f," %06x -> %06x : %3u : %u,%u,%u : %2u"
- " \e[48;5;16;38;5;%um test \e[0m"
- " \e[48;5;244;38;5;%um test \e[0m"
- " \e[48;5;231;38;5;%um test \e[0m "
- " \e[38;5;16;48;5;%um test \e[0m"
- " \e[38;5;244;48;5;%um test \e[0m"
- " \e[38;5;231;48;5;%um test \e[0m\n",
- ci->src_color, ci->ref_color,
- ci->m_index, ci->m_red, ci->m_green, ci->m_blue, ci->m_gray,
- ci->m_index, ci->m_index, ci->m_index,
- ci->m_index, ci->m_index, ci->m_index );
- else
- fputs(" --\n",f);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-enumError Command_TESTCOLORS ( int argc, char ** argv )
-{
- #if HAVE_PRINT
- GetColorByName(colout,"blue");
- #endif
-
- printf("TEST COLORS: %u arguments:\n",argc);
-
- bool sep = true;
- int idx;
- for ( idx = 0; idx < argc; idx++ )
- {
- ccp minus = strchr(argv[idx],'-');
- if ( minus || sep )
- {
- putchar('\n');
- sep = false;
- if ( strlen(argv[idx]) == 1 )
- continue;
- }
-
- color_info_t ci1;
- ScanColorInfo(&ci1,argv[idx]);
- PrintColorInfo(stdout,&ci1);
-
- if (!minus)
- continue;
-
- color_info_t ci2;
- ScanColorInfo(&ci2,minus+1);
- if ( ci2.ref_color == ci1.ref_color )
- continue;
-
- int r1 = ci1.ref_color >> 16 & 0xff;
- int g1 = ci1.ref_color >> 8 & 0xff;
- int b1 = ci1.ref_color & 0xff;
- int r2 = ci2.ref_color >> 16 & 0xff;
- int g2 = ci2.ref_color >> 8 & 0xff;
- int b2 = ci2.ref_color & 0xff;
-
- int n_steps = abs( r2 - r1 );
- int diff = abs( g2 - g1 );
- if ( n_steps < diff )
- n_steps = diff;
- diff = abs( b2 - b1 );
- if ( n_steps < diff )
- n_steps = diff;
-
- u8 prev_m = ci1.m_index;
- u32 prev_rgb = ci1.ref_color;
- int i;
- for ( i = 1; i <= n_steps; i++ )
- {
- uint r = ( r2 - r1 ) * i / n_steps + r1;
- uint g = ( g2 - g1 ) * i / n_steps + g1;
- uint b = ( b2 - b1 ) * i / n_steps + b1;
- u8 new_m = ConvertColorRGB3ToM256(r,g,b);
- if ( prev_m != new_m )
- {
- prev_m = new_m;
- color_info_t ci3;
- AssignColorInfo(&ci3,r<<16|g<<8|b);
- if ( prev_rgb != ci3.ref_color )
- {
- prev_rgb = ci3.src_color = ci3.ref_color;
- PrintColorInfo(stdout,&ci3);
- }
- }
- }
- sep = true;
- }
- putchar('\n');
- return ERR_OK;
-}
-
-//
-///////////////////////////////////////////////////////////////////////////////
-/////////////// color helpers ///////////////
-///////////////////////////////////////////////////////////////////////////////
-//
-// https://en.wikipedia.org/wiki/ANSI_escape_code
-// https://jonasjacek.github.io/colors/
-//
-// 0..15: 000000 800000 008000 808000 000080 800080 008080 c0c0c0
-// 808080 ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff
-// => real colors varies on implementation
-//
-// 6x6x6: 0 95 135 175 215 255 == 00 5f 87 af d7 ff
-//
-// gray: 8 18 28 ... 238 == 08 12 1c 26 30 3a ... e4 ee f8
-//
-///////////////////////////////////////////////////////////////////////////////
-//
-// mkw-ana testcol 000000-ffffff
-// mkw-ana testcol 500-550 550-050 050-055 055-005 005-505 505-500
-//
-///////////////////////////////////////////////////////////////////////////////
-
-u32 ColorTab_M0_M15[16] =
-{
- 0x000000, 0x800000, 0x008000, 0x808000,
- 0x000080, 0x800080, 0x008080, 0xc0c0c0,
- 0x808080, 0xff0000, 0x00ff00, 0xffff00,
- 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-u8 ConvertColorRGB3ToM256 ( u8 r, u8 g, u8 b )
-{
- // 0..5
- const int r6 = SingleColorToM6(r);
- const int g6 = SingleColorToM6(g);
- const int b6 = SingleColorToM6(b);
-
- u8 m256 = 36*r6 + 6*g6 + b6 + 16;
- uint delta = abs ( ( r6 ? 55 + 40 * r6 : 0 ) - r )
- + abs ( ( g6 ? 55 + 40 * g6 : 0 ) - g )
- + abs ( ( b6 ? 55 + 40 * b6 : 0 ) - b );
-
- //printf("%02x>%u %02x>%u %02x>%u : m=%u delta=%d\n",r,r6,g,g6,b,b6,m256,delta);
-
- int m, gray, prev = 0x1000000;
- for ( m = 232, gray = 8; m < 256; m++, gray += 10 )
- {
- const uint d = abs( gray - r ) + abs( gray - g ) + abs( gray - b );
- if ( d > prev )
- break;
- if ( d <= delta )
- {
- delta = d;
- m256 = m;
- }
- prev = d;
- }
-
- return m256;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-u8 ConvertColorRGBToM256 ( u32 rgb )
-{
- return ConvertColorRGB3ToM256( rgb >> 16, rgb >> 8, rgb );
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-u32 ConvertColorM256ToRGB ( u8 m256 )
-{
- if ( m256 < 16 )
- return ColorTab_M0_M15[m256];
-
- if ( m256 < 232 )
- {
- m256 -= 16;
- const uint r = m256 / 36;
- const uint g = m256 / 6 % 6;
- const uint b = m256 % 6;
-
- u32 col = 0;
- if (r) col |= 0x370000 + 0x280000 * r;
- if (g) col |= 0x003700 + 0x002800 * g;
- if (b) col |= 0x000037 + 0x000028 * b;
- return col;
- }
-
- m256 -= 232;
- return 0x080808 + m256 * 0x0a0a0a;
-}
-
-//
-///////////////////////////////////////////////////////////////////////////////
/////////////// dynamic data support ///////////////
///////////////////////////////////////////////////////////////////////////////
@@ -8042,12 +7786,20 @@ int opt_new = 0;
///////////////////////////////////////////////////////////////////////////////
-uint CreateUniqueId ( int range )
+uint CreateUniqueIdN ( int range )
{
static uint unique_id = 1;
- const uint ret = unique_id;
- if ( range > 0 )
- unique_id += range;
+
+ if ( range <= 0 )
+ return unique_id;
+
+ uint ret = unique_id;
+ unique_id += range;
+ if ( unique_id < ret ) // overflow
+ {
+ ret = 1;
+ unique_id = ret + range;
+ }
return ret;
}
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 );
diff --git a/project/dclib/dclib-color.c b/project/dclib/dclib-color.c
index 341c915..19c49fb 100644
--- a/project/dclib/dclib-color.c
+++ b/project/dclib/dclib-color.c
@@ -688,6 +688,309 @@ uint PrintColoredLines
//
///////////////////////////////////////////////////////////////////////////////
+/////////////// global commands: TESTCOLORS ///////////////
+///////////////////////////////////////////////////////////////////////////////
+// [[color_info_t]]
+
+typedef struct color_info_t
+{
+ bool valid; // >0: data below is valid
+
+ u8 m_index; // index of 0..255 for "\e[*m"
+
+ s8 m_red; // -1:invalid, 0..5: red value of 'm_index'
+ s8 m_green; // -1:invalid, 0..5: green value of 'm_index'
+ s8 m_blue; // -1:invalid, 0..5: blue value of 'm_index'
+ s8 m_gray; // -1:invalid, 0..23: gray value of 'm_index'
+
+ u32 ref_color; // reference colors, based on 'm_index';
+ u32 src_color; // scanned color
+}
+color_info_t;
+
+///////////////////////////////////////////////////////////////////////////////
+
+static bool AssignColorInfo ( color_info_t *ci, u32 rgb )
+{
+ DASSERT(ci);
+ memset(ci,0,sizeof(*ci));
+
+ ci->src_color = rgb & 0xffffff;
+ ci->m_index = ConvertColorRGBToM256(ci->src_color);
+ ci->ref_color = ConvertColorM256ToRGB(ci->m_index);
+
+ const uint r = ci->ref_color >> 16 & 0xff;
+ const uint g = ci->ref_color >> 8 & 0xff;
+ const uint b = ci->ref_color & 0xff;
+
+ ci->m_red = SingleColorToM6(r);
+ ci->m_green = SingleColorToM6(g);
+ ci->m_blue = SingleColorToM6(b);
+
+ ci->m_gray = ( r + g + b + 21 ) / 30;
+ if ( ci->m_gray > 23 )
+ ci->m_gray = 23;
+ else if ( ci->m_gray > 0 )
+ ci->m_gray--;
+
+ return ci->valid = 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+static bool ScanColorInfo ( color_info_t *ci, ccp arg )
+{
+ DASSERT(ci);
+ memset(ci,0,sizeof(*ci));
+ if ( arg && *arg )
+ {
+ arg = SkipControls(arg);
+
+ ulong num, r, g, b;
+ if ( *arg >= 'g' && *arg <= 'z' )
+ {
+ const char mode = *arg;
+ arg = SkipControls(arg+1);
+
+ num = str2ul(arg,0,10);
+ switch (mode)
+ {
+ case 'm':
+ return AssignColorInfo(ci,ConvertColorM256ToRGB(num));
+
+ case 'g':
+ return AssignColorInfo(ci,ConvertColorM256ToRGB(232 + num % 24));
+
+ case 'c':
+ r = num / 100 % 10;
+ g = num / 10 % 10;
+ b = num % 10;
+ goto rgb5;
+ }
+ }
+ else
+ {
+ char *end;
+ num = str2ul(arg,&end,16);
+
+ ci->valid = true;
+ if ( end - arg <= 3 )
+ {
+ r = num >> 8 & 15;
+ g = num >> 4 & 15;
+ b = num & 15;
+
+ rgb5:
+ if ( r > 5 ) r = 5;
+ if ( g > 5 ) g = 5;
+ if ( b > 5 ) b = 5;
+ return AssignColorInfo(ci,ConvertColorM256ToRGB(16 + 36*r + 6*g + b));
+ }
+ return AssignColorInfo(ci,num);
+ }
+ }
+
+ return ci->valid;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+static void PrintColorInfo ( FILE *f, color_info_t *ci )
+{
+ DASSERT(f);
+ DASSERT(ci);
+
+ if (ci->valid)
+ fprintf(f," %06x -> %06x : %3u : %u,%u,%u : %2u"
+ " \e[48;5;16;38;5;%um test \e[0m"
+ " \e[48;5;244;38;5;%um test \e[0m"
+ " \e[48;5;231;38;5;%um test \e[0m "
+ " \e[38;5;16;48;5;%um test \e[0m"
+ " \e[38;5;244;48;5;%um test \e[0m"
+ " \e[38;5;231;48;5;%um test \e[0m\n",
+ ci->src_color, ci->ref_color,
+ ci->m_index, ci->m_red, ci->m_green, ci->m_blue, ci->m_gray,
+ ci->m_index, ci->m_index, ci->m_index,
+ ci->m_index, ci->m_index, ci->m_index );
+ else
+ fputs(" --\n",f);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+enumError Command_TESTCOLORS ( int argc, char ** argv )
+{
+ #if HAVE_PRINT
+ GetColorByName(colout,"blue");
+ #endif
+
+ printf("TEST COLORS: %u arguments:\n",argc);
+
+ bool sep = true;
+ int idx;
+ for ( idx = 0; idx < argc; idx++ )
+ {
+ ccp minus = strchr(argv[idx],'-');
+ if ( minus || sep )
+ {
+ putchar('\n');
+ sep = false;
+ if ( strlen(argv[idx]) == 1 )
+ continue;
+ }
+
+ color_info_t ci1;
+ ScanColorInfo(&ci1,argv[idx]);
+ PrintColorInfo(stdout,&ci1);
+
+ if (!minus)
+ continue;
+
+ color_info_t ci2;
+ ScanColorInfo(&ci2,minus+1);
+ if ( ci2.ref_color == ci1.ref_color )
+ continue;
+
+ int r1 = ci1.ref_color >> 16 & 0xff;
+ int g1 = ci1.ref_color >> 8 & 0xff;
+ int b1 = ci1.ref_color & 0xff;
+ int r2 = ci2.ref_color >> 16 & 0xff;
+ int g2 = ci2.ref_color >> 8 & 0xff;
+ int b2 = ci2.ref_color & 0xff;
+
+ int n_steps = abs( r2 - r1 );
+ int diff = abs( g2 - g1 );
+ if ( n_steps < diff )
+ n_steps = diff;
+ diff = abs( b2 - b1 );
+ if ( n_steps < diff )
+ n_steps = diff;
+
+ u8 prev_m = ci1.m_index;
+ u32 prev_rgb = ci1.ref_color;
+ int i;
+ for ( i = 1; i <= n_steps; i++ )
+ {
+ uint r = ( r2 - r1 ) * i / n_steps + r1;
+ uint g = ( g2 - g1 ) * i / n_steps + g1;
+ uint b = ( b2 - b1 ) * i / n_steps + b1;
+ u8 new_m = ConvertColorRGB3ToM256(r,g,b);
+ if ( prev_m != new_m )
+ {
+ prev_m = new_m;
+ color_info_t ci3;
+ AssignColorInfo(&ci3,r<<16|g<<8|b);
+ if ( prev_rgb != ci3.ref_color )
+ {
+ prev_rgb = ci3.src_color = ci3.ref_color;
+ PrintColorInfo(stdout,&ci3);
+ }
+ }
+ }
+ sep = true;
+ }
+ putchar('\n');
+ return ERR_OK;
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// color helpers ///////////////
+///////////////////////////////////////////////////////////////////////////////
+//
+// https://en.wikipedia.org/wiki/ANSI_escape_code
+// https://jonasjacek.github.io/colors/
+//
+// 0..15: 000000 800000 008000 808000 000080 800080 008080 c0c0c0
+// 808080 ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff
+// => real colors varies on implementation
+//
+// 6x6x6: 0 95 135 175 215 255 == 00 5f 87 af d7 ff
+//
+// gray: 8 18 28 ... 238 == 08 12 1c 26 30 3a ... e4 ee f8
+//
+///////////////////////////////////////////////////////////////////////////////
+//
+// mkw-ana testcol 000000-ffffff
+// mkw-ana testcol 500-550 550-050 050-055 055-005 005-505 505-500
+//
+///////////////////////////////////////////////////////////////////////////////
+
+u32 ColorTab_M0_M15[16] =
+{
+ 0x000000, 0x800000, 0x008000, 0x808000,
+ 0x000080, 0x800080, 0x008080, 0xc0c0c0,
+ 0x808080, 0xff0000, 0x00ff00, 0xffff00,
+ 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+u8 ConvertColorRGB3ToM256 ( u8 r, u8 g, u8 b )
+{
+ // 0..5
+ const int r6 = SingleColorToM6(r);
+ const int g6 = SingleColorToM6(g);
+ const int b6 = SingleColorToM6(b);
+
+ u8 m256 = 36*r6 + 6*g6 + b6 + 16;
+ uint delta = abs ( ( r6 ? 55 + 40 * r6 : 0 ) - r )
+ + abs ( ( g6 ? 55 + 40 * g6 : 0 ) - g )
+ + abs ( ( b6 ? 55 + 40 * b6 : 0 ) - b );
+
+ //printf("%02x>%u %02x>%u %02x>%u : m=%u delta=%d\n",r,r6,g,g6,b,b6,m256,delta);
+
+ int m, gray, prev = 0x1000000;
+ for ( m = 232, gray = 8; m < 256; m++, gray += 10 )
+ {
+ const uint d = abs( gray - r ) + abs( gray - g ) + abs( gray - b );
+ if ( d > prev )
+ break;
+ if ( d <= delta )
+ {
+ delta = d;
+ m256 = m;
+ }
+ prev = d;
+ }
+
+ return m256;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+u8 ConvertColorRGBToM256 ( u32 rgb )
+{
+ return ConvertColorRGB3ToM256( rgb >> 16, rgb >> 8, rgb );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+u32 ConvertColorM256ToRGB ( u8 m256 )
+{
+ if ( m256 < 16 )
+ return ColorTab_M0_M15[m256];
+
+ if ( m256 < 232 )
+ {
+ m256 -= 16;
+ const uint r = m256 / 36;
+ const uint g = m256 / 6 % 6;
+ const uint b = m256 % 6;
+
+ u32 col = 0;
+ if (r) col |= 0x370000 + 0x280000 * r;
+ if (g) col |= 0x003700 + 0x002800 * g;
+ if (b) col |= 0x000037 + 0x000028 * b;
+ return col;
+ }
+
+ m256 -= 232;
+ return 0x080808 + m256 * 0x0a0a0a;
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
/////////////// terminal ///////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-color.h b/project/dclib/dclib-color.h
index 6591f2e..c18de42 100644
--- a/project/dclib/dclib-color.h
+++ b/project/dclib/dclib-color.h
@@ -625,7 +625,7 @@ void PrintColorSetHelper
/////////////// color helpers ///////////////
///////////////////////////////////////////////////////////////////////////////
-u32 ColorTab_M0_M15[16]; // first 16 colors of "\e[m"
+extern u32 ColorTab_M0_M15[16]; // first 16 colors of "\e[m"
// return a m256 index
u8 ConvertColorRGB3ToM256 ( u8 r, u8 g, u8 b );
@@ -719,12 +719,12 @@ void PrintColorModes
// RedirectStdFiles() don't cange it, if it is NULL.
//
// stdmsg, colmsg:
-// Special output for catcable messages. Initalized by SetupStdMsg()
+// Special output for catcable messages. Initialized by SetupStdMsg()
// and set to the first not NULL of stdout, stderr and stdlog.
//
// stdwrn, colwrn:
// Output file of PrintError() functions.
-// Initalized to a copy of stderr.
+// Initialized to a copy of stderr.
//
////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-debug.c b/project/dclib/dclib-debug.c
index fd51f17..f6a474f 100644
--- a/project/dclib/dclib-debug.c
+++ b/project/dclib/dclib-debug.c
@@ -45,10 +45,7 @@
#include "dclib-basics.h"
#include "dclib-file.h"
-
-#if ENABLE_HEXDUMP_WRAPPER > 0
- #include "dclib-xdump.h"
-#endif
+#include "dclib-xdump.h"
//
///////////////////////////////////////////////////////////////////////////////
@@ -381,18 +378,7 @@ void ListErrorCodes
/////////////// error handling ///////////////
///////////////////////////////////////////////////////////////////////////////
-ccp progpath = 0;
-ccp progdir = 0;
-ccp progname = 0;
-
-ccp toolname = 0;
-ccp toolversion = 0;
-ccp tooltitle = 0;
-
-bool multi_processing = false;
-enumError last_error = ERR_OK;
-enumError max_error = ERR_OK;
-u32 error_count = 0;
+ProgInfo_t ProgInfo = {0};
///////////////////////////////////////////////////////////////////////////////
@@ -436,9 +422,9 @@ enumError PrintErrorArg ( ccp func, ccp file, unsigned int line,
}
char msg[1000];
- if (!progname)
- progname = "?";
- const int plen = strlen(progname)+2;
+ if (!ProgInfo.progname)
+ ProgInfo.progname = "?";
+ const int plen = strlen(ProgInfo.progname)+2;
if ( !format && err_code > ERR_NOT_IMPLEMENTED )
format = "Program is aborted immediately!";
@@ -491,21 +477,21 @@ enumError PrintErrorArg ( ccp func, ccp file, unsigned int line,
{
if ( err_code > ERR_WARNING )
fprintf(stdwrn,"%s%s%s:%s ERROR #%d [%s] in %s() @ %s#%d%s\n",
- prefix, coln, progname, col1, err_code,
+ prefix, coln, ProgInfo.progname, col1, err_code,
GetErrorName(err_code,0), func, file, line, col0 );
else
fprintf(stdwrn,"%s%s%s:%s WARNING in %s() @ %s#%d%s\n",
- prefix, coln, progname, col1, func, file, line, col0 );
+ prefix, coln, ProgInfo.progname, col1, func, file, line, col0 );
}
else
{
if ( err_code > ERR_WARNING )
fprintf(stdwrn,"%s%s%s:%s ERROR #%d [%s]%s\n",
- prefix, coln, progname, col1, err_code,
+ prefix, coln, ProgInfo.progname, col1, err_code,
GetErrorName(err_code,0), col0 );
else
fprintf(stdwrn,"%s%s%s:%s WARNING%s\n",
- prefix, coln, progname, col1, col0 );
+ prefix, coln, ProgInfo.progname, col1, col0 );
}
#if defined(EXTENDED_ERRORS) && EXTENDED_ERRORS > 1
@@ -518,8 +504,8 @@ enumError PrintErrorArg ( ccp func, ccp file, unsigned int line,
}
else
{
- fprintf(stdwrn,"%s%s:",prefix,progname);
- PutLines(stdwrn,plen,fw,strlen(progname)+1,prefix,msg,0);
+ fprintf(stdwrn,"%s%s:",prefix,ProgInfo.progname);
+ PutLines(stdwrn,plen,fw,strlen(ProgInfo.progname)+1,prefix,msg,0);
}
if (syserr)
@@ -531,14 +517,16 @@ enumError PrintErrorArg ( ccp func, ccp file, unsigned int line,
fflush(stdwrn);
if ( err_code > ERR_OK )
- error_count++;
+ {
+ ProgInfo.error_count++;
- last_error = err_code;
- if ( max_error < err_code )
- max_error = err_code;
+ ProgInfo.last_error = err_code;
+ if ( ProgInfo.max_error < err_code )
+ ProgInfo.max_error = err_code;
- if ( err_code > ERR_NOT_IMPLEMENTED )
- exit(err_code);
+ if ( err_code > ERR_NOT_IMPLEMENTED )
+ exit(err_code);
+ }
return err_code;
}
@@ -563,7 +551,7 @@ enumError PrintErrorStat ( enumError err, int verbose, ccp cmdname )
}
fprintf(stdwrn,"%s: Command '%s' returns with status #%d [%s]\n",
- progname, cmdname, err, GetErrorName(err,0) );
+ ProgInfo.progname, cmdname, err, GetErrorName(err,0) );
}
return err;
}
@@ -601,55 +589,6 @@ bool mark_used ( ccp name, ... )
/////////////// hexdump ///////////////
///////////////////////////////////////////////////////////////////////////////
-#if ENABLE_HEXDUMP_WRAPPER > 1
- int enable_xdump_wrapper = 1;
-#elif ENABLE_HEXDUMP_WRAPPER
- int enable_xdump_wrapper = 0;
-#endif
-
-ccp hexdump_prefix = "";
-ccp hexdump_eol = "\n";
-bool hexdump_align = false;
-
-//-----------------------------------------------------------------------------
-
-#if ENABLE_HEXDUMP_WRAPPER > 0
-
-static void SetupXDumpWrapper
-(
- XDump_t *xd,
- FILE *f,
- int indent,
- u64 addr,
- int addr_fw,
- int row_len
-)
-{
- DASSERT(xd);
- InitializeXDump(xd);
-
- xd->f = f;
- xd->prefix = hexdump_prefix;
- xd->eol = hexdump_eol;
- xd->mode_align = hexdump_align;
- xd->indent = indent;
- xd->start_addr = addr;
- xd->min_addr_fw = addr_fw;
- xd->min_width = row_len;
- xd->format = XDUMPF_INT_1;
- xd->print_format = false;
- xd->print_summary = false;
- xd->print_diff_sep = false;
-
- hexdump_prefix = EmptyString;
- hexdump_eol = "\n";
- hexdump_align = false;
-}
-
-#endif
-
-//-----------------------------------------------------------------------------
-
uint HexDump16 ( FILE * f, int indent, u64 addr,
const void * data, size_t count )
{
@@ -675,101 +614,10 @@ uint HexDump ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
if ( !f || !p_data || !count )
return 0;
- #if ENABLE_HEXDUMP_WRAPPER == 1 || ENABLE_HEXDUMP_WRAPPER == 2
- if (enable_xdump_wrapper)
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER > 0
- {
XDump_t xd;
- SetupXDumpWrapper(&xd,f,indent,addr,addr_fw,row_len);
+ InitializeXDumpEx(&xd,f,indent,addr,addr_fw,row_len);
const int stat = XDump(&xd,p_data,count,true);
return stat < 0 ? 0 : stat;
- }
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER < 3
-
- const int MAX_LEN = 256;
- char buf[MAX_LEN+2];
-
- const u8 * data = (const u8 *)p_data;
-
- indent = NormalizeIndent(indent);
- addr_fw = NormalizeIndent(addr_fw);
-
- const bool show_ascii = row_len >= 0;
- if ( row_len < 0 )
- row_len = -row_len;
- else if ( row_len < 1 )
- row_len = 16;
- else if ( row_len > MAX_LEN )
- row_len = MAX_LEN;
-
- uint skip = 0;
- if ( (s64)addr != -1 )
- {
- const int fw = snprintf(buf,sizeof(buf),"%llx",addr+count-1);
- if ( addr_fw < fw )
- addr_fw = fw;
-
- if (hexdump_align)
- {
- skip = addr % row_len;
- addr -= skip;
- }
- }
-
- uint line_count = 0;
- while ( count > 0 )
- {
- if ( (s64)addr == -1 )
- fprintf(f,"%s%*s", hexdump_prefix, indent,"" );
- else
- {
- fprintf(f,"%s%*s%*llx:", hexdump_prefix, indent,"", addr_fw, addr );
- addr += row_len;
- }
- char * dest = buf;
- if (!skip)
- *dest++ = ':';
-
- int i;
- for ( i = 0; i < row_len; i++ )
- {
- if ( skip > 0 )
- {
- fprintf(f,"%s ", i&3 ? "" : " " );
- *dest++ = ' ';
- if (!--skip)
- *dest++ = ':';
- }
- else
- {
- u8 ch = *data++;
- if ( count > 0 )
- {
- count--;
- fprintf(f,"%s%02x ", i&3 ? "" : " ", ch );
- *dest++ = ch < ' ' || ch >= 0x7f ? '.' : ch;
- }
- else
- fprintf(f,"%s ", i&3 ? "" : " " );
- }
- }
- *dest = 0;
- if (show_ascii)
- fprintf(f,"%s:%s",buf,hexdump_eol);
- else
- fputs(hexdump_eol,f);
- line_count++;
- }
-
- hexdump_prefix = "";
- hexdump_eol = "\n";
- hexdump_align = false;
- return line_count;
- #endif
}
//-----------------------------------------------------------------------------
@@ -790,23 +638,11 @@ uint HexDump0 ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
if ( !f || !p_data || !count )
return 0;
- #if ENABLE_HEXDUMP_WRAPPER == 1 || ENABLE_HEXDUMP_WRAPPER == 2
- if (enable_xdump_wrapper)
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER > 0
- {
XDump_t xd;
- SetupXDumpWrapper(&xd,f,indent,addr,addr_fw,row_len);
+ InitializeXDumpEx(&xd,f,indent,addr,addr_fw,row_len);
xd.mode_ignore = true;
const int stat = XDump(&xd,p_data,count,true);
return stat < 0 ? 0 : stat;
- }
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER < 3
- return HexDump( f, indent, addr, addr_fw, row_len, p_data, count );
- #endif
}
//-----------------------------------------------------------------------------
@@ -827,158 +663,10 @@ void HexDiff ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
if (!f)
return;
- #if ENABLE_HEXDUMP_WRAPPER == 1 || ENABLE_HEXDUMP_WRAPPER == 2
- if (enable_xdump_wrapper)
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER > 0
- {
XDump_t xd;
- SetupXDumpWrapper(&xd,f,indent,addr,addr_fw,row_len);
+ InitializeXDumpEx(&xd,f,indent,addr,addr_fw,row_len);
XDiff(&xd, p_data1,count1,true, p_data2,count2,true, 0,false );
return;
- }
- #endif
-
- #if ENABLE_HEXDUMP_WRAPPER < 3
-
- const int MAX_LEN = 256;
- char buf[MAX_LEN+2];
-
- const u8 * data1 = p_data1 ? (const u8 *)p_data1 : (u8*)EmptyString;
- const u8 * data2 = p_data2 ? (const u8 *)p_data2 : (u8*)EmptyString;
-
- indent = NormalizeIndent(indent);
- addr_fw = NormalizeIndent(addr_fw);
-
- const bool show_ascii = row_len >= 0;
- if ( row_len < 0 )
- row_len = -row_len;
- else if ( row_len < 1 )
- row_len = 16;
- else if ( row_len > MAX_LEN )
- row_len = MAX_LEN;
-
- uint skip = 0;
-
- if ( (s64)addr != -1 )
- {
- const size_t count = count1 > count2 ? count1 : count2;
- const int fw = snprintf(buf,sizeof(buf),"%llx",addr+count-1);
- if ( addr_fw < fw )
- addr_fw = fw;
-
- if (hexdump_align)
- {
- skip = addr % row_len;
- addr -= skip;
- }
- }
-
- while ( count1 > 0 && count2 > 0 )
- {
- size_t count = count1 < count2 ? count1 : count2;
- if ( count > row_len )
- count = row_len;
- noPRINT(" cnt=%zd,%zd -> %zd; cmp=%d\n",
- count1, count2, count, memcmp(data1,data2,count) );
-
- if (memcmp(data1,data2,count))
- {
- //--- print first line
-
- if (IS_M1(addr))
- fprintf(f,"%s%*s<", hexdump_prefix, indent,"" );
- else
- fprintf(f,"%s%*s<%*llx:", hexdump_prefix, indent,"", addr_fw, addr );
-
- char * dest = buf;
- if (!skip)
- *dest++ = ':';
-
- int i;
- for ( i = 0; i < row_len; i++ )
- {
- if ( skip > 0 )
- {
- fprintf(f,"%s ", i&3 ? "" : " " );
- *dest++ = ' ';
- if (!--skip)
- *dest++ = ':';
- }
- else
- {
- u8 ch = data1[i];
- if ( i < count1 )
- {
- fprintf(f,"%s%02x ", i&3 ? "" : " ", ch );
- *dest++ = ch < ' ' || ch >= 0x7f ? '.' : ch;
- }
- else
- fprintf(f,"%s ", i&3 ? "" : " " );
- }
- }
- *dest = 0;
- if (show_ascii)
- fprintf(f,"%s:%s",buf,hexdump_eol);
- else
- fputs(hexdump_eol,f);
-
-
- //--- print second line
-
- if (IS_M1(addr))
- fprintf(f,"%s%*s>", hexdump_prefix, indent,"" );
- else
- fprintf(f,"%s%*s>%*llx:", hexdump_prefix, indent,"", addr_fw, addr );
-
- dest = buf;
- if (!skip)
- *dest++ = ':';
-
- for ( i = 0; i < row_len; i++ )
- {
- if ( skip > 0 )
- {
- fprintf(f,"%s ", i&3 ? "" : " " );
- *dest++ = ' ';
- if (!--skip)
- *dest++ = ':';
- }
- else
- {
- u8 ch = data2[i];
- if ( i < count2 )
- {
- if ( ch == data1[i] )
- fprintf(f,"%s . ", i&3 ? "" : " " );
- else
- fprintf(f,"%s%02x ", i&3 ? "" : " ", ch );
- *dest++ = ch < ' ' || ch >= 0x7f ? '.' : ch;
- }
- else
- fprintf(f,"%s ", i&3 ? "" : " " );
- }
- }
- *dest = 0;
- if (show_ascii)
- fprintf(f,"%s:%s",buf,hexdump_eol);
- else
- fputs(hexdump_eol,f);
- }
- data1 += count;
- data2 += count;
- count1 -= count;
- count2 -= count;
- if (!IS_M1(addr))
- addr += count;
-
- }
- hexdump_prefix = "";
- hexdump_eol = "\n";
- hexdump_align = false;
-
- #endif
}
//
@@ -998,14 +686,14 @@ static void trace_helper ( int print_stderr, ccp format, va_list arg )
if (!TRACE_FILE)
{
char extend[16];
- if (multi_processing)
+ if (ProgInfo.multi_processing)
snprintf(extend,sizeof(extend),"-%u",getpid());
else
*extend = 0;
char fname[1000];
- if ( progname && *progname && *progname != '?' )
- snprintf( fname, sizeof(fname), "_trace-%s%s.tmp", progname, extend );
+ if ( ProgInfo.progname && *ProgInfo.progname && *ProgInfo.progname != '?' )
+ snprintf( fname, sizeof(fname), "_trace-%s%s.tmp", ProgInfo.progname, extend );
else
snprintf( fname, sizeof(fname), "_trace-%s.tmp", extend );
@@ -1373,8 +1061,8 @@ static FILE * OpenMemLog()
{
done = true;
char fname[500];
- if ( progname && *progname && *progname != '?' )
- snprintf(fname,sizeof(fname),"_trace_alloc-%s-%u.tmp",progname,getpid());
+ if ( ProgInfo.progname && *ProgInfo.progname && *ProgInfo.progname != '?' )
+ snprintf(fname,sizeof(fname),"_trace_alloc-%s-%u.tmp",ProgInfo.progname,getpid());
else
snprintf(fname,sizeof(fname),"_trace_alloc-%u.tmp",getpid());
diff --git a/project/dclib/dclib-debug.h b/project/dclib/dclib-debug.h
index 34726f1..cec834f 100644
--- a/project/dclib/dclib-debug.h
+++ b/project/dclib/dclib-debug.h
@@ -41,23 +41,37 @@
//
///////////////////////////////////////////////////////////////////////////////
-/////////////// error handling ///////////////
+/////////////// program info ///////////////
///////////////////////////////////////////////////////////////////////////////
+// [[ProgInfo_t]]
-extern ccp progpath; // full path of program, use ProgramPath() to access
-extern ccp progdir; // directory part of progpath, use ProgramDirectory() to access
-extern ccp progname; // program name, based on path or directly set
+typedef struct ProgInfo_t
+{
+ ccp progpath; // full path of program, use ProgramPath() to access
+ ccp progdir; // directory part of progpath, use ProgramDirectory() to access
+ ccp progname; // program name, based on path or directly set
-extern ccp toolname; // name of the tool, set by SetupProgname()
-extern ccp toolversion; // version of the tool, set by SetupProgname()
-extern ccp tooltitle; // title of the tool, set by SetupProgname()
+ ccp logdir; // log directory, set by DefineLogDirectory()
+ // and GetLogDirectory()
-extern bool multi_processing;
-extern enumError last_error;
-extern enumError max_error;
-extern u32 error_count;
+ ccp toolname; // name of the tool, set by SetupProgname()
+ ccp toolversion; // version of the tool, set by SetupProgname()
+ ccp tooltitle; // title of the tool, set by SetupProgname()
-//-----------------------------------------------------------------------------
+ bool multi_processing; // TRUE: program uses multiple thread
+
+ enumError last_error; // last error, set by PrintErrorArg()
+ enumError max_error; // max error, set by PrintErrorArg()
+ u32 error_count; // number of errors, set by PrintErrorArg()
+}
+ProgInfo_t;
+
+extern ProgInfo_t ProgInfo;
+
+//
+///////////////////////////////////////////////////////////////////////////////
+/////////////// error handling ///////////////
+///////////////////////////////////////////////////////////////////////////////
extern ccp (*GetErrorNameHook)( int stat, ccp ret_not_found );
extern ccp (*GetErrorTextHook)( int stat, ccp ret_not_found );
@@ -126,29 +140,12 @@ bool mark_used ( ccp name, ... );
/////////////// hexdump ///////////////
///////////////////////////////////////////////////////////////////////////////
-// 0: don't use XDump
-// 1: use 'enable_xdump_wrapper' to decide and init it with FALSE
-// 2: use 'enable_xdump_wrapper' to decide and init it with TRUE
-// 3: force usage of XDump
-
-#ifndef ENABLE_HEXDUMP_WRAPPER
- #ifdef TEST
- #define ENABLE_HEXDUMP_WRAPPER 3
- #else
- #define ENABLE_HEXDUMP_WRAPPER 3
- #endif
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-
-#if ENABLE_HEXDUMP_WRAPPER
- extern int enable_xdump_wrapper;
-#endif
-
extern ccp hexdump_prefix;
extern ccp hexdump_eol;
extern bool hexdump_align;
+//-----------------------------------------------------------------------------
+
// HexDump*() return the number of printed lines
uint HexDump ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
@@ -186,7 +183,7 @@ void HexDiff16 ( FILE * f, int indent, u64 addr,
// If symbol 'DEBUG' or symbol _DEBUG' is defined, then and only then
// DEBUG, DASSERT and TRACING are enabled.
//
-// There are to function like macros defined:
+// Defined functions/macros:
//
// TRACE ( ccp format, ... );
// Print to console only if TRACING is enabled.
@@ -197,10 +194,10 @@ void HexDiff16 ( FILE * f, int indent, u64 addr,
// Like TRACE(), but print only if 'condition' is true.
//
// TRACELINE
-// Print out current line and source.
+// Print out current line and source if TRACING is defined.
//
// TRACE_SIZEOF ( object_or_type );
-// Print out `sizeof(object_or_type)´
+// Print out `sizeof(object_or_type)´ if TRACING is defined.
//
// ASSERT(cond);
// If condition is false: print info and exit program.
diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c
index 0cd2478..a4849e3 100644
--- a/project/dclib/dclib-file.c
+++ b/project/dclib/dclib-file.c
@@ -36,6 +36,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
+#include <sys/time.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
@@ -197,8 +198,19 @@ FileAttrib_t * ClearFileAttrib
FileAttrib_t * dest // NULL or destination attribute
)
{
+ #if USE_NEW_FILEATTRIB
if (dest)
+ {
memset(dest,0,sizeof(*dest));
+ dest->atime.tv_nsec =
+ dest->mtime.tv_nsec =
+ dest->ctime.tv_nsec =
+ dest->itime.tv_nsec = UTIME_OMIT;
+ }
+ #else
+ if (dest)
+ memset(dest,0,sizeof(*dest));
+ #endif
return dest;
}
@@ -210,7 +222,17 @@ FileAttrib_t * TouchFileAttrib
)
{
DASSERT(dest);
+ #if USE_NEW_FILEATTRIB
+ struct timeval tv;
+ if (!gettimeofday(&tv,0))
+ {
+ dest->atime.tv_sec = tv.tv_sec;
+ dest->atime.tv_nsec = tv.tv_usec * 1000;
+ dest->mtime = dest->ctime = dest->itime = dest->atime;
+ }
+ #else
dest->mtime = dest->ctime = dest->atime = dest->itime = time(0);
+ #endif
return dest;
}
@@ -226,21 +248,46 @@ FileAttrib_t * SetFileAttrib
{
DASSERT(dest);
+ #if USE_NEW_FILEATTRIB
+
if (src_fa)
memcpy(dest,src_fa,sizeof(*dest));
else if (src_stat)
{
memset(dest,0,sizeof(*dest));
- if ( S_ISREG(src_stat->st_mode) )
+ if (S_ISREG(src_stat->st_mode))
+ {
+ dest->atime = src_stat->st_atim;
+ dest->mtime = src_stat->st_mtim;
+ dest->ctime = src_stat->st_ctim;
+ dest->itime = CompareTimeSpec(&dest->mtime,&dest->ctime) > 0
+ ? dest->mtime : dest->ctime;
+ dest->size = src_stat->st_size;
+ }
+ else
+ ClearFileAttrib(dest);
+ dest->mode = src_stat->st_mode;
+ }
+
+ #else
+
+ if (src_fa)
+ memcpy(dest,src_fa,sizeof(*dest));
+ else if (src_stat)
+ {
+ memset(dest,0,sizeof(*dest));
+ if (S_ISREG(src_stat->st_mode))
{
+ dest->atime = src_stat->st_atime;
dest->mtime = src_stat->st_mtime;
dest->ctime = src_stat->st_ctime;
dest->itime = dest->mtime > dest->ctime ? dest->mtime : dest->ctime;
- dest->atime = src_stat->st_atime;
dest->size = src_stat->st_size;
}
dest->mode = src_stat->st_mode;
}
+
+ #endif
return dest;
}
@@ -255,11 +302,51 @@ FileAttrib_t * MaxFileAttrib
{
DASSERT(dest);
+ #if USE_NEW_FILEATTRIB
+
if (src_fa)
{
+ if (CompareTimeSpec(&dest->atime,&src_fa->atime)>0) dest->atime = src_fa->atime;
+ if (CompareTimeSpec(&dest->mtime,&src_fa->mtime)>0) dest->mtime = src_fa->mtime;
+ if (CompareTimeSpec(&dest->ctime,&src_fa->ctime)>0) dest->ctime = src_fa->ctime;
+ if (CompareTimeSpec(&dest->itime,&src_fa->itime)>0) dest->itime = src_fa->itime;
+
+ if ( dest->size < src_fa->size )
+ dest->size = src_fa->size;
+ dest->mode = src_fa->mode;
+ }
+
+ if (src_stat)
+ {
+ if ( S_ISREG(src_stat->st_mode) )
+ {
+ if ( CompareTimeSpec(&dest->atime,&src_stat->st_atim) > 0 )
+ dest->atime = src_stat->st_atim;
+
+ if ( CompareTimeSpec(&dest->mtime,&src_stat->st_mtim) > 0 )
+ dest->mtime = src_stat->st_mtim;
+
+ if ( CompareTimeSpec(&dest->ctime,&src_stat->st_ctim) > 0 )
+ dest->ctime = src_stat->st_ctim;
+
+ if ( CompareTimeSpec(&dest->itime,&src_stat->st_mtim) > 0 )
+ dest->itime = src_stat->st_mtim;
+ if ( CompareTimeSpec(&dest->itime,&src_stat->st_ctim) > 0 )
+ dest->itime = src_stat->st_ctim;
+
+ if ( dest->size < src_stat->st_size )
+ dest->size = src_stat->st_size;
+ }
+ dest->mode = src_stat->st_mode;
+ }
+
+ #else
+
+ if (src_fa)
+ {
+ if ( dest->atime < src_fa->atime ) dest->atime = src_fa->atime;
if ( dest->mtime < src_fa->mtime ) dest->mtime = src_fa->mtime;
if ( dest->ctime < src_fa->ctime ) dest->ctime = src_fa->ctime;
- if ( dest->atime < src_fa->atime ) dest->atime = src_fa->atime;
if ( dest->itime < src_fa->itime ) dest->itime = src_fa->itime;
if ( dest->size < src_fa->size ) dest->size = src_fa->size;
@@ -271,9 +358,9 @@ FileAttrib_t * MaxFileAttrib
{
if ( S_ISREG(src_stat->st_mode) )
{
+ if ( dest->atime < src_stat->st_atime ) dest->atime = src_stat->st_atime;
if ( dest->mtime < src_stat->st_mtime ) dest->mtime = src_stat->st_mtime;
if ( dest->ctime < src_stat->st_ctime ) dest->ctime = src_stat->st_ctime;
- if ( dest->atime < src_stat->st_atime ) dest->atime = src_stat->st_atime;
if ( dest->itime < dest->mtime ) dest->itime = dest->mtime;
if ( dest->itime < dest->ctime ) dest->itime = dest->ctime;
@@ -283,6 +370,8 @@ FileAttrib_t * MaxFileAttrib
dest->mode = src_stat->st_mode;
}
+ #endif
+
return dest;
}
@@ -298,6 +387,30 @@ FileAttrib_t * NormalizeFileAttrib
if ( fa->size < 0 )
fa->size = 0;
+ #if USE_NEW_FILEATTRIB
+
+ if (IsTimeSpecNull(&fa->mtime))
+ {
+ if (!IsTimeSpecNull(&fa->itime))
+ fa->mtime = fa->itime;
+ else if (!IsTimeSpecNull(&fa->ctime))
+ fa->mtime = fa->ctime;
+ }
+
+ if (IsTimeSpecNull(&fa->itime))
+ fa->itime = CompareTimeSpec(&fa->ctime,&fa->mtime) > 0
+ ? fa->ctime : fa->mtime;
+
+ if (IsTimeSpecNull(&fa->ctime))
+ fa->ctime = CompareTimeSpec(&fa->itime,&fa->mtime) > 0
+ ? fa->itime : fa->mtime;
+
+ if (IsTimeSpecNull(&fa->atime))
+ fa->atime = CompareTimeSpec(&fa->itime,&fa->ctime) > 0
+ ? fa->itime : fa->ctime;
+
+ #else
+
time_t mtime = fa->mtime;
if (!mtime)
{
@@ -320,9 +433,23 @@ FileAttrib_t * NormalizeFileAttrib
if (!fa->atime)
fa->atime = fa->itime > fa->ctime ? fa->itime : fa->ctime;
+ #endif
+
return fa;
}
+///////////////////////////////////////////////////////////////////////////////
+// struct timespec helpers
+
+const struct timespec null_timespec = {0,0};
+
+int CompareTimeSpec0 ( const struct timespec *a, const struct timespec *b )
+{
+ if (!a) a = &null_timespec;
+ if (!b) b = &null_timespec;
+ return CompareTimeSpec(a,b);
+}
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// simple UNIX+TCP socket connect ///////////////
@@ -723,14 +850,18 @@ enumError CloseFile
TRACE("UNLINK %s\n",f->fname);
unlink(f->fname);
}
+ #if USE_NEW_FILEATTRIB
+ else if ( set_time == 1 && !IsTimeSpecNull(&f->fatt.mtime) )
+ utimensat(AT_FDCWD,f->fname,f->fatt.times,0);
+ #else
else if ( set_time == 1 && f->fatt.mtime )
{
struct utimbuf ubuf;
ubuf.actime = f->fatt.atime
? f->fatt.atime : f->fatt.mtime;
ubuf.modtime = f->fatt.mtime;
- utime(f->fname,&ubuf);
}
+ #endif
else if ( set_time > 1 || f->fmode & FM_TOUCH )
{
utime(f->fname,0);
@@ -1300,7 +1431,7 @@ s64 GetFileSize
if ( stat(path,&st) || !S_ISREG(st.st_mode) )
{
if ( fatt && !fatt_max )
- memset(fatt,0,sizeof(*fatt));
+ ClearFileAttrib(fatt);
return not_found_val;
}
@@ -2081,7 +2212,7 @@ uint ReadMemFileAt
enumError LoadMemFile
(
MemFile_t *mf, // MemFile_t data
- bool init_mf, // true: initalize 'mf' first
+ bool init_mf, // true: initialize 'mf' first
ccp path1, // NULL or part #1 of path
ccp path2, // NULL or part #2 of path
@@ -2677,7 +2808,7 @@ ccp FindConfigFile
//--- empty strings like NULL
- if ( share_name && !*share_name ) share_name = progname;
+ if ( share_name && !*share_name ) share_name = ProgInfo.progname;
if ( file_name && !*file_name ) file_name = 0;
if ( prog_ext && !*prog_ext ) prog_ext = 0;
@@ -4178,7 +4309,7 @@ enumError RestoreState
//--- scan name
ccp name = ptr;
- while ( isalnum((int)*ptr) || *ptr == '-' || *ptr == '_' || *ptr == '@' )
+ while ( *ptr >= '!' && *ptr <= '~' && *ptr != '=' )
ptr++;
char *name_end = ptr;
@@ -4449,6 +4580,11 @@ mem_t GetParamFieldMEM
/////////////// save + restore config by table ///////////////
///////////////////////////////////////////////////////////////////////////////
+int srt_auto_dump = 0;
+FILE *srt_auto_dump_file = 0;
+
+///////////////////////////////////////////////////////////////////////////////
+
void DumpStateTable
(
FILE *f, // valid output file
@@ -4461,6 +4597,12 @@ void DumpStateTable
return;
indent = NormalizeIndent(indent);
+ printf(
+ "%*s off size *n(e) ty em name\n"
+ "%*s----------------------------------\n",
+ indent,"",
+ indent,"" );
+
for ( ; srt->type != SRT__TERM; srt++ )
{
if ( srt->type == SRT__IS_LIST )
@@ -4471,10 +4613,11 @@ void DumpStateTable
putc('\n',f);
}
else
- fprintf(f,"%*s%4u %4u *%-3u %2u %2u %s\n",
+ fprintf(f,"%*s%4u %4u *%-4d %2u %2u %s\n",
indent,"",
srt->offset, srt->size, srt->n_elem, srt->type, srt->emode,
- srt->name ? srt->name : "-" );
+ srt->name ? srt->name
+ : srt->type == SRT_DEF_ARRAY ? " >ARRAY" : "-" );
}
}
@@ -4502,32 +4645,28 @@ static void print_scs_name ( FILE *f, int fw, int use_tab, ccp format, ... )
//-----------------------------------------------------------------------------
-static u64 SCS_get_uint ( const u8* data, int idx, const SaveRestoreTab_t *srt )
+static u64 SCS_get_uint ( const u8* data, int size )
{
- DASSERT(srt);
-
- switch(srt->size)
+ switch(size)
{
- case 1: return ((u8*) (data+srt->offset))[idx];
- case 2: return ((u16*)(data+srt->offset))[idx];
- case 4: return ((u32*)(data+srt->offset))[idx];
- case 8: return ((u64*)(data+srt->offset))[idx];
+ case 1: return *(u8*) data;
+ case 2: return *(u16*)data;
+ case 4: return *(u32*)data;
+ case 8: return *(u64*)data;
}
return 0;
}
//-----------------------------------------------------------------------------
-static s64 SCS_get_int ( const u8* data, int idx, const SaveRestoreTab_t *srt )
+static u64 SCS_get_int ( const u8* data, int size )
{
- DASSERT(srt);
-
- switch(srt->size)
+ switch(size)
{
- case 1: return ((s8*) (data+srt->offset))[idx];
- case 2: return ((s16*)(data+srt->offset))[idx];
- case 4: return ((s32*)(data+srt->offset))[idx];
- case 8: return ((s64*)(data+srt->offset))[idx];
+ case 1: return *(s8*) data;
+ case 2: return *(s16*)data;
+ case 4: return *(s32*)data;
+ case 8: return *(s64*)data;
}
return 0;
}
@@ -4558,6 +4697,7 @@ static void SCS_save_string ( FILE *f, ccp src, int slen, EncodeMode_t emode )
}
}
+//
//-----------------------------------------------------------------------------
void SaveCurrentStateByTable
@@ -4576,6 +4716,13 @@ void SaveCurrentStateByTable
if ( !f || !data0 || !srt )
return;
+ if ( srt_auto_dump && srt_auto_dump_file )
+ {
+ if ( srt_auto_dump > 0 )
+ srt_auto_dump--;
+ DumpStateTable(srt_auto_dump_file,0,srt);
+ }
+
if (!prefix)
prefix = EmptyString;
const uint prelen = strlen(prefix);
@@ -4603,10 +4750,27 @@ void SaveCurrentStateByTable
}
const int use_tab = (fw_name&7) ? 0 : (fw_name/8)*8+7;
- const u8 *data = data0;
+ const u8 *data = data0;
+ uint last_count = 0;
+ uint aelem_count = 0;
+ uint aelem_offset = 0;
for ( ; srt->type != SRT__TERM; srt++ )
{
+ if ( srt->type == SRT_DEF_ARRAY )
+ {
+ aelem_offset = srt->size;
+ if ( srt->n_elem < 0 )
+ {
+ aelem_count = -srt->n_elem;
+ if ( aelem_count > last_count )
+ aelem_count = last_count;
+ }
+ else
+ aelem_count = srt->n_elem;
+ continue;
+ }
+
if ( srt->type == SRT__IS_LIST )
{
if ( srt->name )
@@ -4622,51 +4786,85 @@ void SaveCurrentStateByTable
if ( srt->type < SRT__IS_LIST )
print_scs_name(f,fw_name,use_tab,"%s%s",prefix,srt->name);
+ int n_elem, elem_off;
+ bool have_array = aelem_count && aelem_offset;
+ if (have_array)
+ {
+ elem_off = aelem_offset;
+ n_elem = aelem_count;
+ }
+ else
+ {
+ elem_off = srt->size;
+ n_elem = srt->n_elem;
+ if ( n_elem < 0 )
+ {
+ have_array = true;
+ n_elem = -n_elem;
+ if ( n_elem > last_count )
+ n_elem = last_count;
+ }
+ else if ( n_elem > 1 )
+ have_array = true;
+ }
+
uint i, offset;
switch(srt->type)
{
case SRT_BOOL:
- if ( srt->n_elem > 1 )
+ if (have_array)
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%u", i ? "," : "", SCS_get_uint(data,i,srt)!=0 );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f,"%s%u", i ? "," : "", SCS_get_uint(d,srt->size)!=0 );
fputc('\n',f);
}
else
- fprintf(f,"%u\n",SCS_get_uint(data,0,srt)!=0);
+ fprintf(f,"%u\n",SCS_get_uint(data+srt->offset,srt->size)!=0);
break;
+ case SRT_COUNT:
+ last_count = 0;
+ // fall through
case SRT_UINT:
- if ( srt->n_elem > 1 )
+ if (have_array)
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%llu", i ? "," : "", SCS_get_uint(data,i,srt) );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f,"%s%llu", i ? "," : "", SCS_get_uint(d,srt->size) );
fputc('\n',f);
}
else
- fprintf(f,"%llu\n",SCS_get_uint(data,0,srt));
+ {
+ const u64 num = SCS_get_uint(data+srt->offset,srt->size);
+ if ( srt->type == SRT_COUNT && num <= UINT_MAX )
+ last_count = num;
+ fprintf(f,"%llu\n",num);
+ }
break;
case SRT_HEX:
- if ( srt->n_elem > 1 )
+ if (have_array)
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%#llx", i ? "," : "", SCS_get_uint(data,i,srt) );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f,"%s%#llx", i ? "," : "", SCS_get_uint(d,srt->size) );
fputc('\n',f);
}
else
- fprintf(f,"%#llx\n",SCS_get_uint(data,0,srt));
+ fprintf(f,"%#llx\n",SCS_get_uint(data+srt->offset,srt->size));
break;
case SRT_INT:
- if ( srt->n_elem > 1 )
+ if (have_array)
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%lld", i ? "," : "", SCS_get_int(data,i,srt) );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f,"%s%lld", i ? "," : "", SCS_get_int(d,srt->size) );
fputc('\n',f);
}
else
- fprintf(f,"%lld\n",SCS_get_int(data,0,srt));
+ fprintf(f,"%lld\n",SCS_get_int(data+srt->offset,srt->size));
break;
case SRT_FLOAT:
@@ -4674,25 +4872,25 @@ void SaveCurrentStateByTable
{
case sizeof(float):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%.8g", i ? "," : "",
- ((float*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%.8g", i ? "," : "", *(float*)d );
}
break;
case sizeof(double):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%.16g", i ? "," : "",
- ((double*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%.16g", i ? "," : "", *(double*)d );
}
break;
case sizeof(long double):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%.20Lg", i ? "," : "",
- ((long double*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%.20Lg", i ? "," : "", *(long double*)d );
}
break;
@@ -4707,25 +4905,25 @@ void SaveCurrentStateByTable
{
case sizeof(float):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%a", i ? "," : "",
- ((float*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%a", i ? "," : "", *(float*)d );
}
break;
case sizeof(double):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%a", i ? "," : "",
- ((double*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%a", i ? "," : "", *(double*)d );
}
break;
case sizeof(long double):
{
- for ( i = 0; i < srt->n_elem; i++ )
- fprintf(f,"%s%La", i ? "," : "",
- ((long double*)(data+srt->offset))[i] );
+ const u8 *d = data + srt->offset;
+ for ( i = 0; i < n_elem; i++, d += elem_off )
+ fprintf(f, "%s%La", i ? "," : "", *(long double*)d );
}
break;
@@ -4738,37 +4936,40 @@ void SaveCurrentStateByTable
//-----
case SRT_STRING_SIZE:
- for ( i = 0, offset = srt->offset;; offset += srt->size )
- {
- SCS_save_string(f,(char*)(data+offset),-1,srt->emode);
- if ( ++i == srt->n_elem )
- break;
- fputc(',',f);
- }
+ if ( n_elem > 0 )
+ for ( i = 0, offset = srt->offset;; offset += elem_off )
+ {
+ SCS_save_string(f,(char*)(data+offset),-1,srt->emode);
+ if ( ++i == n_elem )
+ break;
+ fputc(',',f);
+ }
fputc('\n',f);
break;
case SRT_STRING_ALLOC:
- for ( i = 0, offset = srt->offset;; offset += srt->size )
- {
- SCS_save_string(f,*(ccp*)(data+offset),-1,srt->emode);
- if ( ++i == srt->n_elem )
- break;
- fputc(',',f);
- }
+ if ( n_elem > 0 )
+ for ( i = 0, offset = srt->offset;; offset += elem_off )
+ {
+ SCS_save_string(f,*(ccp*)(data+offset),-1,srt->emode);
+ if ( ++i == n_elem )
+ break;
+ fputc(',',f);
+ }
fputc('\n',f);
break;
case SRT_MEM:
{
- for ( i = 0, offset = srt->offset;; offset += srt->size )
- {
- mem_t *mem = (mem_t*)(data+offset);
- SCS_save_string(f,mem->ptr,mem->len,srt->emode);
- if ( ++i == srt->n_elem )
- break;
- fputc(',',f);
- }
+ if ( n_elem > 0 )
+ for ( i = 0, offset = srt->offset;; offset += elem_off )
+ {
+ mem_t *mem = (mem_t*)(data+offset);
+ SCS_save_string(f,mem->ptr,mem->len,srt->emode);
+ if ( ++i == n_elem )
+ break;
+ fputc(',',f);
+ }
fputc('\n',f);
break;
}
@@ -4813,6 +5014,7 @@ void SaveCurrentStateByTable
}
}
+//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -4826,13 +5028,41 @@ void RestoreStateByTable
{
DASSERT(rs);
DASSERT(srt);
+ DASSERT(data0);
+ if ( !rs || !data0 || !srt )
+ return;
+
+ if ( srt_auto_dump && srt_auto_dump_file )
+ {
+ if ( srt_auto_dump > 0 )
+ srt_auto_dump--;
+ DumpStateTable(srt_auto_dump_file,0,srt);
+ }
- char buf[4000]; // ???
+ char buf[4000];
if (!prefix)
prefix = EmptyString;
+ uint last_count = 0;
+ uint aelem_count = 0;
+ uint aelem_offset = 0;
+
for ( ; srt->type != SRT__TERM; srt++ )
{
+ if ( srt->type == SRT_DEF_ARRAY )
+ {
+ aelem_offset = srt->size;
+ if ( srt->n_elem < 0 )
+ {
+ aelem_count = -srt->n_elem;
+ if ( aelem_count > last_count )
+ aelem_count = last_count;
+ }
+ else
+ aelem_count = srt->n_elem;
+ continue;
+ }
+
if ( srt->type == SRT__IS_LIST || !srt->name )
continue;
@@ -4841,155 +5071,187 @@ void RestoreStateByTable
if ( srt->type < SRT__IS_LIST )
StringCat2S(buf,sizeof(buf),prefix,srt->name);
+ int n_elem, elem_off;
+ if ( aelem_count && aelem_offset )
+ {
+ elem_off = aelem_offset;
+ n_elem = aelem_count;
+ }
+ else
+ {
+ elem_off = srt->size;
+ n_elem = srt->n_elem;
+ if ( n_elem < 0 )
+ {
+ n_elem = -n_elem;
+ if ( n_elem > last_count )
+ n_elem = last_count;
+ }
+ }
+
switch(srt->type)
{
+ case SRT_COUNT:
+ last_count = 0;
+ // fall through
case SRT_BOOL:
case SRT_UINT:
case SRT_HEX:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- if (!it)
- break;
-
- char *src = (char*)it->data;
- u8 *val = (u8*)(data+srt->offset);
- uint i = 0;
- while (*src)
+ if (n_elem)
{
- u64 num = str2ull(src,&src,10);
- switch(srt->size)
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ if (!it)
+ break;
+
+ char *src = (char*)it->data;
+ u8 *val = (u8*)(data+srt->offset);
+ uint i = 0;
+ while (*src)
{
- case 1: *(u8*) val = num; break;
- case 2: *(u16*)val = num; break;
- case 4: *(u32*)val = num; break;
- case 8: *(u64*)val = num; break;
+ u64 num = str2ull(src,&src,10);
+ if ( !i && srt->type == SRT_COUNT && num <= UINT_MAX )
+ last_count = num;
+
+ switch(srt->size)
+ {
+ case 1: *(u8*) val = num; break;
+ case 2: *(u16*)val = num; break;
+ case 4: *(u32*)val = num; break;
+ case 8: *(u64*)val = num; break;
+ }
+ if ( ++i == n_elem )
+ break;
+ val += elem_off;
+ if ( *src == ',' )
+ src++;
}
- if ( ++i == srt->n_elem )
- break;
- val += srt->size;
- if ( *src == ',' )
- src++;
}
break;
- }
case SRT_INT:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- if (!it)
- break;
-
- char *src = (char*)it->data;
- u8 *val = (u8*)(data+srt->offset);
- uint i = 0;
- while (*src)
+ if (n_elem)
{
- s64 num = str2ll(src,&src,10);
- switch(srt->size)
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ if (!it)
+ break;
+
+ char *src = (char*)it->data;
+ u8 *val = (u8*)(data+srt->offset);
+ uint i = 0;
+ while (*src)
{
- case 1: *(s8*) val = num; break;
- case 2: *(s16*)val = num; break;
- case 4: *(s32*)val = num; break;
- case 8: *(s64*)val = num; break;
+ s64 num = str2ll(src,&src,10);
+ switch(srt->size)
+ {
+ case 1: *(s8*) val = num; break;
+ case 2: *(s16*)val = num; break;
+ case 4: *(s32*)val = num; break;
+ case 8: *(s64*)val = num; break;
+ }
+ if ( ++i == n_elem )
+ break;
+ val += elem_off;
+ if ( *src == ',' )
+ src++;
}
- if ( ++i == srt->n_elem )
- break;
- val += srt->size;
- if ( *src == ',' )
- src++;
}
break;
- }
case SRT_FLOAT:
case SRT_XFLOAT:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- if (!it)
- break;
-
- char *src = (char*)it->data;
- u8 *val = (u8*)(data+srt->offset);
- uint i = 0;
- while (*src)
+ if (n_elem)
{
- switch(srt->size)
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ if (!it)
+ break;
+
+ char *src = (char*)it->data;
+ u8 *val = (u8*)(data+srt->offset);
+ uint i = 0;
+ while (*src)
{
- case sizeof(float): *(float*)val = strtof(src,&src); break;
- case sizeof(double): *(double*)val = strtod(src,&src); break;
- case sizeof(long double): *(long double*)val = strtold(src,&src); break;
+ switch(srt->size)
+ {
+ case sizeof(float): *(float*)val = strtof(src,&src); break;
+ case sizeof(double): *(double*)val = strtod(src,&src); break;
+ case sizeof(long double): *(long double*)val = strtold(src,&src); break;
+ }
+ if ( ++i == n_elem )
+ break;
+ val += elem_off;
+ if ( *src == ',' )
+ src++;
}
- if ( ++i == srt->n_elem )
- break;
- val += srt->size;
- if ( *src == ',' )
- src++;
}
break;
- }
//-----
case SRT_STRING_SIZE:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- mem_list_t ml;
- DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
+ if (n_elem)
+ {
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ mem_list_t ml;
+ DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
- char *val = (char*)(data+srt->offset);
- uint i;
- for ( i = 0; i < srt->n_elem; i++, val += srt->size )
- StringCopyS( val, srt->size, i<ml.used ? ml.list[i].ptr : 0 );
- ResetMemList(&ml);
+ char *val = (char*)(data+srt->offset);
+ uint i;
+ for ( i = 0; i < n_elem; i++, val += elem_off )
+ StringCopyS( val, srt->size, i<ml.used ? ml.list[i].ptr : 0 );
+ ResetMemList(&ml);
+ }
break;
- }
case SRT_STRING_ALLOC:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- mem_list_t ml;
- DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
-
- ccp *val = (ccp*)(data+srt->offset);
- uint i;
- for ( i = 0; i < srt->n_elem; i++, val++ )
+ if (n_elem)
{
- FreeString(*val);
- *val = 0;
- if ( i < ml.used )
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ mem_list_t ml;
+ DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
+
+ ccp *val = (ccp*)(data+srt->offset);
+ uint i;
+ for ( i = 0; i < n_elem; i++ )
{
- mem_t *m = ml.list+i;
- if ( m->ptr )
- *val = m->ptr == EmptyString ? EmptyString : MEMDUP(m->ptr,m->len);
+ FreeString(*val);
+ *val = 0;
+ if ( i < ml.used )
+ {
+ mem_t *m = ml.list+i;
+ if ( m->ptr )
+ *val = m->ptr == EmptyString ? EmptyString : MEMDUP(m->ptr,m->len);
+ }
+ val = (ccp*)( (u8*)val + elem_off );
}
+ ResetMemList(&ml);
}
- ResetMemList(&ml);
break;
- }
case SRT_MEM:
- {
- ParamFieldItem_t *it = GetParamField(rs,buf);
- mem_list_t ml;
- DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
-
- mem_t *val = (mem_t*)(data+srt->offset);
- uint i;
- for ( i = 0; i < srt->n_elem; i++, val++ )
+ if (n_elem)
{
- FreeString(val->ptr);
- val->ptr = 0;
- val->len = 0;
- if ( i < ml.used )
+ ParamFieldItem_t *it = GetParamField(rs,buf);
+ mem_list_t ml;
+ DecodeByModeMemList(&ml,2,it?(ccp)it->data:0,-1,srt->emode,0);
+
+ mem_t *val = (mem_t*)(data+srt->offset);
+ uint i;
+ for ( i = 0; i < n_elem; i++ )
{
- mem_t *m = ml.list+i;
- if ( m->ptr )
- *val = m->ptr == EmptyString ? EmptyMem : DupMem(*m);
+ FreeString(val->ptr);
+ val->ptr = 0;
+ val->len = 0;
+ if ( i < ml.used )
+ {
+ mem_t *m = ml.list+i;
+ if ( m->ptr )
+ *val = m->ptr == EmptyString ? EmptyMem : DupMem(*m);
+ }
+ val = (mem_t*)( (u8*)val + elem_off );
}
+ ResetMemList(&ml);
}
- ResetMemList(&ml);
break;
- }
//-----
@@ -5038,7 +5300,7 @@ void RestoreStateByTable
break;
}
}
- }
+ }
}
//
diff --git a/project/dclib/dclib-file.h b/project/dclib/dclib-file.h
index 532ff5f..d2be55c 100644
--- a/project/dclib/dclib-file.h
+++ b/project/dclib/dclib-file.h
@@ -126,10 +126,42 @@ ccp GetFileOpenMode
///////////////////////////////////////////////////////////////////////////////
/////////////// struct FileAttrib_t ///////////////
///////////////////////////////////////////////////////////////////////////////
+
+#ifndef USE_NEW_FILEATTRIB
+ #define USE_NEW_FILEATTRIB 1
+#endif
+
+#undef FILEATTRIB_SEC
+#if USE_NEW_FILEATTRIB
+ #define FILEATTRIB_SEC(t) ((t).tv_sec)
+#else
+ #define FILEATTRIB_SEC(t) (t)
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
// [[FileAttrib_t]]
typedef struct FileAttrib_t
{
+ #if USE_NEW_FILEATTRIB
+
+ union
+ {
+ struct timespec times[4];
+ struct
+ {
+ // order compatible to utimensat() and futimens()
+ struct timespec atime; // last ascces time
+ struct timespec mtime; // time of last content modification
+ struct timespec ctime; // time of file creation or last status change
+ struct timespec itime; // insertion time (special time for archives)
+ };
+ };
+
+ size_t size; // file size
+ mode_t mode; // file mode
+
+ #else
time_t mtime; // time of last content modification
time_t ctime; // time of file creation or last status change
time_t atime; // last ascces time
@@ -137,6 +169,8 @@ typedef struct FileAttrib_t
size_t size; // file size
mode_t mode; // file mode
+ #endif
+
}
FileAttrib_t;
@@ -147,6 +181,9 @@ FileAttrib_t * ClearFileAttrib
FileAttrib_t * dest // NULL or destination attribute
);
+static inline FileAttrib_t * ZeroFileAttrib ( FileAttrib_t * dest )
+ { DASSERT(dest); memset(dest,0,sizeof(*dest)); return dest; }
+
FileAttrib_t * TouchFileAttrib
(
FileAttrib_t * dest // valid destination attribute
@@ -183,6 +220,45 @@ FileAttrib_t * NormalizeFileAttrib
FileAttrib_t * fa // valid attribute
);
+///////////////////////////////////////////////////////////////////////////////
+// struct timespec helpers
+
+extern const struct timespec null_timespec;
+
+// NULL pointers allowed
+int CompareTimeSpec0 ( const struct timespec *a, const struct timespec *b );
+
+// NULL pointers forbidden
+static inline int CompareTimeSpec
+ ( const struct timespec *a, const struct timespec *b )
+{
+ DASSERT(a);
+ DASSERT(b);
+ return a->tv_sec < b->tv_sec ? -1
+ : a->tv_sec > b->tv_sec ? 1
+ : a->tv_nsec < b->tv_nsec ? -1
+ : a->tv_nsec > b->tv_nsec;
+}
+
+// NULL pointers forbidden
+static inline int CompareTimeSpecVal
+ ( const struct timespec *a, const struct timeval *b )
+{
+ DASSERT(a);
+ DASSERT(b);
+ return a->tv_sec < b->tv_sec ? -1
+ : a->tv_sec > b->tv_sec ? 1
+ : a->tv_nsec < b->tv_usec*1000 ? -1
+ : a->tv_nsec > b->tv_usec*1000;
+}
+
+static inline bool IsTimeSpecNull ( const struct timespec *ts )
+{
+ return !ts
+ || ts->tv_nsec > 1000000000 // includes UTIME_NOW || UTIME_OMIT
+ || !ts->tv_nsec && !ts->tv_sec;
+}
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// struct File_t ///////////////
@@ -632,7 +708,7 @@ static inline uint ReadMemFile
enumError LoadMemFile
(
MemFile_t *mf, // MemFile_t data
- bool init_mf, // true: initalize 'mf' first
+ bool init_mf, // true: initialize 'mf' first
ccp path1, // NULL or part #1 of path
ccp path2, // NULL or part #2 of path
@@ -881,43 +957,17 @@ uint NumberedFilename
);
///////////////////////////////////////////////////////////////////////////////
+
#if 0
-///////////////////////////////////////////////////////////////////////////////
-char * SplitSubPath
-(
+ char * SplitSubPath
+ (
char * buf, // destination buffer
size_t buf_size, // size of 'buf'
ccp path // source path, if NULL: use 'buf'
-);
-
-enumError LoadFile
-(
- ccp path1, // NULL or part #1 of path
- ccp path2, // NULL or part #2 of path
- size_t skip, // skip num of bytes before reading
- void * data, // destination buffer, size = 'size'
- size_t size, // size to read
- int silent, // 0: print all error messages
- // 1: suppress file size warning
- // 2: suppress all error messages
- FileAttrib_t * fatt, // not NULL: store file attributes
- bool fatt_max // true: store *max* values to 'fatt'
-);
-
-enumError SaveFile
-(
- ccp path1, // NULL or part #1 of path
- ccp path2, // NULL or part #2 of path
- bool overwrite, // true: force overwriting
- const void * data, // data to write
- uint data_size, // size of 'data'
- FileAttrib_t * fatt // not NULL: set timestamps using this attribs
-);
+ );
-///////////////////////////////////////////////////////////////////////////////
#endif
-///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-network.c b/project/dclib/dclib-network.c
index c7b5914..15fdf0d 100644
--- a/project/dclib/dclib-network.c
+++ b/project/dclib/dclib-network.c
@@ -1703,7 +1703,7 @@ void InitializeTCPStream ( TCPStream_t *ts, int sock )
{
DASSERT(ts);
memset(ts,0,sizeof(*ts));
- ts->unique_id = CreateUniqueId(1);
+ ts->unique_id = CreateUniqueId();
ts->sock = sock;
ts->poll_index = M1(ts->poll_index);
LOG_TCP_STREAM(ts,0,"%s","INIT()");
@@ -2534,7 +2534,7 @@ void InitializeTCPHandler
{
DASSERT(th);
memset(th,0,sizeof(*th));
- th->unique_id = CreateUniqueId(1);
+ th->unique_id = CreateUniqueId();
th->data_size = data_size;
th->OnAllowStream = IsStreamAllowed;
diff --git a/project/dclib/dclib-network.h b/project/dclib/dclib-network.h
index b533761..4cf099f 100644
--- a/project/dclib/dclib-network.h
+++ b/project/dclib/dclib-network.h
@@ -444,17 +444,17 @@ typedef struct ip4_head_t
{
// http://de.wikipedia.org/wiki/IP-Paket
- u8 vers_ihl; // high nibble: version, low nibble: IHL (Ip Header Len)
- u8 tos;
- u16 total_len;
- u16 id;
- u16 frag_off; // low 12 bits: fragment offset, high 4 bits: flags
- u8 ttl;
- u8 protocol;
- u16 checksum;
- u32 ip_src;
- u32 ip_dest;
- // optional: options + padding
+ /*00*/ u8 vers_ihl; // high nibble: version, low nibble: IHL (Ip Header Len)
+ /*01*/ u8 tos;
+ /*02*/ u16 total_len;
+ /*04*/ u16 id;
+ /*06*/ u16 frag_off; // low 12 bits: fragment offset, high 4 bits: flags
+ /*08*/ u8 ttl;
+ /*09*/ u8 protocol;
+ /*0a*/ u16 checksum;
+ /*0c*/ u32 ip_src;
+ /*10*/ u32 ip_dest;
+ /*14*/ // optional: options + padding
}
__attribute__ ((packed)) ip4_head_t;
diff --git a/project/dclib/dclib-numeric.c b/project/dclib/dclib-numeric.c
index 379e021..8be5cf6 100644
--- a/project/dclib/dclib-numeric.c
+++ b/project/dclib/dclib-numeric.c
@@ -1267,8 +1267,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
)
{
DASSERT(buf);
@@ -1278,11 +1280,11 @@ uint EncodeBase64
noPRINT("EncodeBase64(sz=%u,len=%d,fil=%d)\n",buf_size,source_len,use_filler);
if (!next_line)
- next_line_trigger = ~0;
- else if (!next_line_trigger)
- next_line_trigger = 19;
+ bytes_per_line = ~0;
+ else if (!bytes_per_line)
+ bytes_per_line = 19;
else
- next_line_trigger /= 3;
+ bytes_per_line /= 3;
char *dest = buf;
char *dest_end = buf + buf_size - 4;
@@ -1299,7 +1301,7 @@ uint EncodeBase64
while ( src < src_end && dest < dest_end )
{
- if ( ++n_tupel > next_line_trigger && next_line )
+ if ( ++n_tupel > bytes_per_line && next_line )
{
char *next = StringCopyE(dest,(char*)buf+buf_size,next_line);
if ( next >= dest_end )
@@ -1382,6 +1384,49 @@ mem_t EncodeBase64Circ
}
///////////////////////////////////////////////////////////////////////////////
+
+
+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
+)
+{
+ indent = NormalizeIndent(indent);
+ if (!eol)
+ eol = "\n";
+
+ char linesep[200];
+ int pre_pos;
+ snprintf(linesep,sizeof(linesep),"%s%n%*s%s",
+ eol,
+ &pre_pos,
+ indent, "",
+ prefix ? prefix : ""
+ );
+
+ char *end = buf + buf_size;
+ char *dest = StringCopyE(buf,end,linesep+pre_pos);
+ const uint scanned = EncodeBase64( dest, end-dest, source, source_len,
+ encode64, use_filler, linesep, bytes_per_line );
+ dest = buf + strlen(buf);
+ StringCopyE(dest,end,eol);
+ return scanned;
+}
+
+///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
uint EncodeJSON
@@ -1793,22 +1838,22 @@ uint EncodeByMode
case ENCODE_BASE64:
len = EncodeBase64(buf,buf_size,source,slen,TableEncode64,true,0,0);
- len = EncodeBase64FillLen(len);
+ len = GetEncodeBase64FillLen(len);
break;
case ENCODE_BASE64URL:
len = EncodeBase64(buf,buf_size,source,slen,TableEncode64url,true,0,0);
- len = EncodeBase64FillLen(len);
+ len = GetEncodeBase64FillLen(len);
break;
case ENCODE_BASE64STAR:
len = EncodeBase64(buf,buf_size,source,slen,TableEncode64star,true,0,0);
- len = EncodeBase64FillLen(len);
+ len = GetEncodeBase64FillLen(len);
break;
case ENCODE_BASE64XML:
len = EncodeBase64(buf,buf_size,source,slen,TableEncode64xml,true,0,0);
- len = EncodeBase64FillLen(len);
+ len = GetEncodeBase64FillLen(len);
break;
case ENCODE_JSON:
@@ -2050,11 +2095,14 @@ 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()
)
{
+ if (!tim)
+ tim = time(0);
+
char buf[100];
- struct tm *tm = localtime(&time);
+ struct tm *tm = localtime(&tim);
const uint len = strftime(buf,sizeof(buf),format,tm);
return CopyCircBuf(buf,len+1);
}
@@ -2066,11 +2114,14 @@ 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()
)
{
+ if (!tim)
+ tim = time(0);
+
char buf[100];
- struct tm *tm = gmtime(&time);
+ struct tm *tm = gmtime(&tim);
const uint len = strftime(buf,sizeof(buf),format,tm);
return CopyCircBuf(buf,len+1);
}
@@ -2082,12 +2133,13 @@ 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
)
{
char buf[100];
- struct tm *tm = localtime(&time);
+ struct tm *tm = localtime(&tim);
const uint len = strftime(buf,sizeof(buf),format,tm);
char *at = strchr(buf,'@');
if (at)
@@ -2109,12 +2161,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
)
{
char buf[100];
- struct tm *tm = gmtime(&time);
+ struct tm *tm = gmtime(&tim);
const uint len = strftime(buf,sizeof(buf),format,tm);
char *at = strchr(buf,'@');
if (at)
diff --git a/project/dclib/dclib-ui.c b/project/dclib/dclib-ui.c
index a642431..02f56c9 100644
--- a/project/dclib/dclib-ui.c
+++ b/project/dclib/dclib-ui.c
@@ -260,7 +260,7 @@ enumError CheckEnvOptions ( ccp varname, check_opt_func func )
char * buf = MALLOC(envlen+1);
char * dest = buf;
- int argc = 1; // argv[0] = progname
+ int argc = 1; // argv[0] = ProgInfo.progname
ccp src = env;
while (*src)
{
@@ -279,7 +279,7 @@ enumError CheckEnvOptions ( ccp varname, check_opt_func func )
TRACE("argc = %d\n",argc);
char ** argv = MALLOC((argc+1)*sizeof(*argv));
- argv[0] = (char*)progname;
+ argv[0] = (char*)ProgInfo.progname;
argv[argc] = 0;
dest = buf;
int i;
diff --git a/project/dclib/dclib-xdump.c b/project/dclib/dclib-xdump.c
index ec0e49a..b860b62 100644
--- a/project/dclib/dclib-xdump.c
+++ b/project/dclib/dclib-xdump.c
@@ -680,6 +680,45 @@ void InitializeXDump ( XDump_t *xd )
///////////////////////////////////////////////////////////////////////////////
+ccp hexdump_prefix = "";
+ccp hexdump_eol = "\n";
+bool hexdump_align = false;
+
+//-----------------------------------------------------------------------------
+
+void InitializeXDumpEx
+(
+ XDump_t *xd,
+ FILE *f,
+ int indent,
+ u64 addr,
+ int addr_fw,
+ int row_len
+)
+{
+ DASSERT(xd);
+ InitializeXDump(xd);
+
+ xd->f = f;
+ xd->prefix = hexdump_prefix;
+ xd->eol = hexdump_eol;
+ xd->mode_align = hexdump_align;
+ xd->indent = indent;
+ xd->start_addr = addr;
+ xd->min_addr_fw = addr_fw;
+ xd->min_width = row_len;
+ xd->format = XDUMPF_INT_1;
+ xd->print_format = false;
+ xd->print_summary = false;
+ xd->print_diff_sep = false;
+
+ hexdump_prefix = EmptyString;
+ hexdump_eol = "\n";
+ hexdump_align = false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
void SetupXDump ( XDump_t *xd, XDumpCommand_t cmd )
{
DASSERT(xd);
diff --git a/project/dclib/dclib-xdump.h b/project/dclib/dclib-xdump.h
index 2943cb4..f58ee29 100644
--- a/project/dclib/dclib-xdump.h
+++ b/project/dclib/dclib-xdump.h
@@ -205,9 +205,25 @@ XDump_t;
//-----------------------------------------------------------------------------
+extern ccp hexdump_prefix;
+extern ccp hexdump_eol;
+extern bool hexdump_align;
+
+//-----------------------------------------------------------------------------
+
void InitializeXDump ( XDump_t *xd );
-void SetupXDump ( XDump_t *xd, XDumpCommand_t cmd );
+void InitializeXDumpEx
+(
+ XDump_t *xd,
+ FILE *f,
+ int indent,
+ u64 addr,
+ int addr_fw,
+ int row_len
+);
+
+void SetupXDump ( XDump_t *xd, XDumpCommand_t cmd );
static inline void ResetXDump ( XDump_t *xd ) {}
void PrintXDumpParam