aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
authorWiimm <wiimm@wiimm.de>2023-05-28 05:52:52 +0200
committerWiimm <wiimm@wiimm.de>2023-05-28 05:52:52 +0200
commit74ac39c1af5c8e85bf10711aed2ffc9dfee2e277 (patch)
treee6cd603f01c3d360c701d6ad5418fe7e133d2c26 /project/dclib
parentf978a965248a5a082d6801ef394bdebb55c78e4f (diff)
SZS v2.34a
Diffstat (limited to 'project/dclib')
-rw-r--r--project/dclib/Makefile.inc43
-rw-r--r--project/dclib/dclib-basics.c44
-rw-r--r--project/dclib/dclib-basics.h42
-rw-r--r--project/dclib/dclib-color.c4
-rw-r--r--project/dclib/dclib-file.c54
-rw-r--r--project/dclib/dclib-file.h16
-rw-r--r--project/dclib/dclib-numeric.c6
-rw-r--r--project/dclib/dclib-types.h28
-rw-r--r--project/dclib/lib-dol.h2
9 files changed, 202 insertions, 37 deletions
diff --git a/project/dclib/Makefile.inc b/project/dclib/Makefile.inc
index b505f2e..feaf15d 100644
--- a/project/dclib/Makefile.inc
+++ b/project/dclib/Makefile.inc
@@ -13,6 +13,12 @@
# Wiimms source code library #
# #
###########################################################################
+ # #
+ # Copyright (c) 2012-2023 by Dirk Clemens <wiimm@wiimm.de> #
+ # #
+ ###########################################################################
+
+# make manual: https://www.gnu.org/software/make/manual/make.html
#------------------------------------------------------------------------------
# standard object files
@@ -69,32 +75,57 @@ ifeq ($(origin DCLIB_HAVE_USABLE_SIZE), undefined)
endif
#------------------------------------------------------------------------------
-# add libraries and guardian macros
+# gcc version dependent cflags
+
+DCLIB_GCC = $(GCC)
+ifeq ($(DCLIB_GCC),)
+ DCLIB_GCC := gcc
+endif
+
+DCLIB_GCC_VERSION = $(shell $(DCLIB_GCC) -dumpversion)
+
+ifeq ($(shell expr $(DCLIB_GCC_VERSION) '>=' 7 ),1)
+ DCLIB_CFLAGS += -Wno-format-truncation
+else
+ DCLIB_CFLAGS += -Wno-pragmas -Wno-unknown-pragmas
+endif
+
+ifeq ($(shell expr $(DCLIB_GCC_VERSION) '>=' 9 ),1)
+ DCLIB_CFLAGS += -Wno-address-of-packed-member
+endif
+
+#------------------------------------------------------------------------------
+# add object files and guardian macros
ifeq ($(DCLIB_THREAD),1)
DCLIB_O += dclib-thread.o
- DCLIB_FLAGS += -DDCLIB_THREAD=1
+ DCLIB_DEFINES += -DDCLIB_THREAD=1
endif
ifeq ($(DCLIB_NETWORK),1)
DCLIB_O += dclib-network.o dclib-punycode.o
- DCLIB_FLAGS += -DDCLIB_NETWORK=1
+ DCLIB_DEFINES += -DDCLIB_NETWORK=1
else
DCLIB_MYSQL := 0
endif
ifeq ($(DCLIB_MYSQL),1)
DCLIB_O += dclib-mysql.o
- DCLIB_FLAGS += -DDCLIB_MYSQL=1
+ DCLIB_DEFINES += -DDCLIB_MYSQL=1
endif
ifeq ($(DCLIB_TERMINAL),1)
DCLIB_O += dclib-terminal.o dclib-command.o
- DCLIB_FLAGS += -DDCLIB_TERMINAL=1
+ DCLIB_DEFINES += -DDCLIB_TERMINAL=1
endif
ifeq ($(DCLIB_HAVE_USABLE_SIZE),1)
- DCLIB_FLAGS += -DDCLIB_HAVE_USABLE_SIZE=1
+ DCLIB_DEFINES += -DDCLIB_HAVE_USABLE_SIZE=1
endif
#------------------------------------------------------------------------------
+
+# support for deprecated DCLIB_FLAGS (2023-04-14)
+DCLIB_FLAGS := $(DCLIB_DEFINES) $(DCLIB_CFLAGS)
+
+#------------------------------------------------------------------------------
diff --git a/project/dclib/dclib-basics.c b/project/dclib/dclib-basics.c
index 5aede90..8da7c5b 100644
--- a/project/dclib/dclib-basics.c
+++ b/project/dclib/dclib-basics.c
@@ -2187,6 +2187,21 @@ char * CopyCircBuf
}
///////////////////////////////////////////////////////////////////////////////
+// variant to supress warning "return-local-addr"
+
+char * CopyCircBufIf
+(
+ // Never returns NULL, but always ALIGN(4)
+
+ bool condition, // use CopyCircBuf() if true
+ cvp data, // source to copy
+ u32 data_size // see GetCircBuf()
+)
+{
+ return condition ? CopyCircBuf(data,strlen(data)) : (char*)data;
+}
+
+///////////////////////////////////////////////////////////////////////////////
char * CopyCircBuf0
(
@@ -2204,6 +2219,22 @@ char * CopyCircBuf0
}
///////////////////////////////////////////////////////////////////////////////
+// variant to supress warning "return-local-addr"
+
+char * CopyCircBuf0If
+(
+ // Like CopyCircBuf(), but an additional char is alloced and set to NULL
+ // Never returns NULL, but always ALIGN(4).
+
+ bool condition, // use CopyCircBuf0() if true
+ cvp data, // source to copy
+ u32 data_size // see GetCircBuf()
+)
+{
+ return condition ? CopyCircBuf0(data,strlen(data)) : (char*)data;
+}
+
+///////////////////////////////////////////////////////////////////////////////
char * PrintCircBuf
(
@@ -2381,7 +2412,7 @@ ccp GetLineByListHelper ( const int *list, ccp beg, ccp mid, ccp end, ccp line )
/////////////// struct FastBuf_t ///////////////
///////////////////////////////////////////////////////////////////////////////
-FastBuf_t * InitializeFastBuf ( cvp mem, uint size )
+FastBuf_t * InitializeFastBuf ( void * mem, uint size )
{
DASSERT(mem);
DASSERT( size >= sizeof(FastBuf_t) );
@@ -6334,7 +6365,7 @@ const KeywordTab_t * ScanKeywordEx
void InitializeKeyListParam ( KeyListParam_t *par )
{
- DASSERT(klist);
+ DASSERT(par);
memset(par,0,sizeof(*par));
par->force_case = LOUP_UPPER;
par->allow_prefix = true;
@@ -6423,7 +6454,7 @@ s64 ScanKeywordListP
continue;
}
}
- else if ( par->min_number < par->max_number )
+ else if ( par->min_number < par->max_number )
{
// scan signed number
char *end;
@@ -6919,7 +6950,12 @@ char * PrintKeywordList
if (ret_length)
*ret_length = len;
+ #pragma GCC diagnostic push
+ #if __GNUC__ >= 9
+ #pragma GCC diagnostic ignored "-Wreturn-local-addr"
+ #endif
return buf == temp ? CopyCircBuf(temp,len+1) : buf;
+ #pragma GCC diagnostic pop
}
///////////////////////////////////////////////////////////////////////////////
@@ -8798,7 +8834,7 @@ void DumpEML ( FILE *f, int indent, const exmem_list_t * eml, ccp info )
fw_key = 30;
uint idx = 0;
- for ( ptr = eml->list; ptr < end; ptr++, idx++ )
+ for ( ptr = eml->list; ptr < end; ptr++, idx++ )
fprintf(f,"%*d [%c%c%c%c] %-*s = [%x] %s\n",
fw_idx, idx,
ptr->data.is_key_alloced? 'a' : '-', // flags: same as in PrintExMem()
diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h
index 3993f48..3110e57 100644
--- a/project/dclib/dclib-basics.h
+++ b/project/dclib/dclib-basics.h
@@ -1751,6 +1751,16 @@ char * CopyCircBuf
u32 data_size // see GetCircBuf()
);
+// variant to supress warning "return-local-addr"
+char * CopyCircBufIf
+(
+ // Never returns NULL, but always ALIGN(4)
+
+ bool condition, // use CopyCircBuf() if true
+ cvp data, // source to copy
+ u32 data_size // see GetCircBuf()
+);
+
char * CopyCircBuf0
(
// Like CopyCircBuf(), but an additional char is alloced and set to NULL
@@ -1760,6 +1770,17 @@ char * CopyCircBuf0
u32 data_size // see GetCircBuf()
);
+// variant to supress warning "return-local-addr"
+char * CopyCircBuf0If
+(
+ // Like CopyCircBuf(), but an additional char is alloced and set to NULL
+ // Never returns NULL, but always ALIGN(4).
+
+ bool condition, // use CopyCircBuf0() if true
+ cvp data, // source to copy
+ u32 data_size // see GetCircBuf()
+);
+
char * PrintCircBuf
(
// returns CopyCircBuf0() or EmptyString.
@@ -1995,7 +2016,7 @@ FastBuf_t;
//
//------------------------------------------------------------------
-FastBuf_t * InitializeFastBuf ( cvp mem, uint size );
+FastBuf_t * InitializeFastBuf ( void * mem, uint size );
FastBuf_t * InitializeFastBufAlloc ( FastBuf_t *fb, uint size );
void ResetFastBuf ( FastBuf_t *fb );
@@ -4093,7 +4114,8 @@ typedef enum size_mode_t
DC_SIZE_T, // force output in TB or TiB (tera,tebi)
DC_SIZE_P, // force output in PB or PiB (peta,pebi)
DC_SIZE_E, // force output in EB or EiB (exa, exbi)
- // zetta/zebi & yotta/yobi not supported because >2^64
+ // zetta/zebi, yotta/yobi, ronna and quetta
+ // are not supported because >2^64
DC_SIZE_N_MODES, // number of modes
@@ -4673,7 +4695,7 @@ ccp PrintNTimeByFormat
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_nsec_t ntime
+ u_nsec_t ntime // time in nsec, e.g. get by GetTimeNSec(false)
);
ccp PrintNTimeByFormatUTC
@@ -4682,7 +4704,7 @@ ccp PrintNTimeByFormatUTC
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_nsec_t ntime
+ u_nsec_t ntime // time in nsec, e.g. get by GetTimeNSec(false)
);
//-----------------------------------------------------------------------------
@@ -4719,7 +4741,7 @@ ccp PrintUTimeByFormat
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_usec_t utime
+ u_usec_t utime // time in usec, e.g. get by GetTimeUSec(false)
);
ccp PrintUTimeByFormatUTC
@@ -4728,7 +4750,7 @@ ccp PrintUTimeByFormatUTC
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_usec_t utime
+ u_nsec_t utime // time in usec, e.g. get by GetTimeUSec(false)
);
//-----------------------------------------------------------------------------
@@ -4738,7 +4760,7 @@ static inline ccp PrintMSecByFormat
// returns temporary buffer by GetCircBuf();
ccp format, // format string for strftime()
- // 1-9 '@' in row replaced by digits of 'usec'
+ // 1-9 '@' in row replaced by digits of 'msec'
time_t tim, // seconds since epoch
uint msec // millisecond of second
)
@@ -4751,7 +4773,7 @@ static inline ccp PrintMSecByFormatUTC
// returns temporary buffer by GetCircBuf();
ccp format, // format string for strftime()
- // 1-9 '@' in row replaced by digits of 'usec'
+ // 1-9 '@' in row replaced by digits of 'msec'
time_t tim, // seconds since epoch
uint msec // millisecond of second
)
@@ -4765,7 +4787,7 @@ ccp PrintMTimeByFormat
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_msec_t mtime
+ u_msec_t mtime // time in msec, e.g. get by GetTimeMSec(false)
);
ccp PrintMTimeByFormatUTC
@@ -4774,7 +4796,7 @@ ccp PrintMTimeByFormatUTC
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_msec_t mtime
+ u_msec_t mtime // time in msec, e.g. get by GetTimeMSec(false)
);
//-----------------------------------------------------------------------------
diff --git a/project/dclib/dclib-color.c b/project/dclib/dclib-color.c
index 43e4020..4bedef4 100644
--- a/project/dclib/dclib-color.c
+++ b/project/dclib/dclib-color.c
@@ -4967,11 +4967,15 @@ void ViewColorsPredef ( ColorView_t *cv, ColorSelect_t colsel )
colsel = COLSEL_M_MODE;
cv->print_alt = ( colsel & COLSEL_F_ALT ) != 0;
+ // use #pragma to fix a gcc error
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wformat-overflow"
fprintf(cv->f,
"%s\n%*sPredefined%s color names for mode %s:\n\n",
cv->colset->reset, cv->indent, "",
colsel & COLSEL_NAME ? " semantic" : "",
GetColorModeName(cv->col_mode,0) );
+ #pragma GCC diagnostic pop
if ( (colsel & COLSEL_NAME) == COLSEL_NAME )
ViewColorsPredef_helper(cv,ch_tab_name);
diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c
index f075847..ed53eb7 100644
--- a/project/dclib/dclib-file.c
+++ b/project/dclib/dclib-file.c
@@ -7487,7 +7487,7 @@ CpuStatus_t GetCpuStatus ( CpuStatus_t * prev_cpuinfo )
static int n_cpu = -1;
static int clock_ticks = 100;
- char buf[1000];
+ char buf[5000];
if ( n_cpu < 0 )
{
@@ -7541,20 +7541,46 @@ CpuStatus_t GetCpuStatus ( CpuStatus_t * prev_cpuinfo )
if (f_stat)
{
while (fgets(buf,sizeof(buf),f_stat))
- if ( !memcmp(buf,"cpu ",4) )
+ if (!memcmp(buf,"cpu ",4)) // only cpu summary is relevant
{
- char *ptr = buf;
- current.user = strtol(ptr+4,&ptr,10) * 10000 / clock_ticks;
- current.nice = strtol(ptr,&ptr,10) * 10000 / clock_ticks;
- current.system = strtol(ptr,&ptr,10) * 10000 / clock_ticks;
- current.idle = strtol(ptr,&ptr,10) * 10000 / clock_ticks;
+ char *ptr = buf+4;
+ for ( int i = 1; i < 100; i++ )
+ {
+ char *begin = ptr;
+ u64 val = strtol(ptr,&ptr,10) * 10000 / clock_ticks;
+ if ( begin == ptr )
+ break;
+
+ switch (i)
+ {
+ case 1: current.user = val; break;
+ case 2: current.nice = val; break;
+ case 3: current.system = val; break;
+ case 4: current.idle = val; break;
+ case 5: current.iowait = val; break;
+
+ case 6:
+ case 7: current.irq += val; break;
+
+ case 8:
+ case 9:
+ case 10: current.virtual += val; break;
+
+ default: current.unknown += val; break;
+ }
+ }
break;
}
fclose(f_stat);
}
if (!prev_cpuinfo)
+ {
+ current.have_irq = current.irq > 0;
+ current.have_virtual = current.virtual > 0;
+ current.have_unknown = current.unknown > 0;
return current;
+ }
//--- get delta for result
@@ -7562,12 +7588,20 @@ CpuStatus_t GetCpuStatus ( CpuStatus_t * prev_cpuinfo )
if (!prev_cpuinfo->valid)
*prev_cpuinfo = current;
+ current.have_irq = prev_cpuinfo->have_irq || current.irq > 0;
+ current.have_virtual = prev_cpuinfo->have_virtual || current.virtual > 0;
+ current.have_unknown = prev_cpuinfo->have_unknown || current.unknown > 0;
+
CpuStatus_t res = current;
res.nsec -= prev_cpuinfo->nsec;
res.user -= prev_cpuinfo->user;
res.nice -= prev_cpuinfo->nice;
res.system -= prev_cpuinfo->system;
res.idle -= prev_cpuinfo->idle;
+ res.iowait -= prev_cpuinfo->iowait;
+ res.irq -= prev_cpuinfo->irq;
+ res.virtual -= prev_cpuinfo->virtual;
+ res.unknown -= prev_cpuinfo->unknown;
*prev_cpuinfo = current;
return res;
@@ -7581,11 +7615,13 @@ ccp PrintCpuStatus ( const CpuStatus_t * cpuinfo )
return "INVALID";
return PrintCircBuf(
- "ticks=%d, cpus=%d, times=%lld+%lld+%lld+%lld=%lld, avg=%4.2f,%4.2f,%4.2f %u/%u, nsec=%llu",
+ "ticks=%d, cpus=%d, times=%lld+%lld+%lld+%lld+%lld+%lld+%lld+%lld=%lld, avg=%4.2f,%4.2f,%4.2f %u/%u, nsec=%llu",
cpuinfo->clock_ticks,
cpuinfo->n_cpu,
cpuinfo->user, cpuinfo->nice, cpuinfo->system, cpuinfo->idle,
- cpuinfo->user + cpuinfo->nice + cpuinfo->system + cpuinfo->idle,
+ cpuinfo->iowait, cpuinfo->irq, cpuinfo->virtual, cpuinfo->unknown,
+ cpuinfo->user + cpuinfo->nice + cpuinfo->system + cpuinfo->idle
+ + cpuinfo->iowait + cpuinfo->irq + cpuinfo->virtual + cpuinfo->unknown,
cpuinfo->loadavg[0], cpuinfo->loadavg[1], cpuinfo->loadavg[2],
cpuinfo->running_proc, cpuinfo->total_proc,
cpuinfo->nsec );
diff --git a/project/dclib/dclib-file.h b/project/dclib/dclib-file.h
index 8215583..bfc85e6 100644
--- a/project/dclib/dclib-file.h
+++ b/project/dclib/dclib-file.h
@@ -1679,15 +1679,23 @@ __attribute__ ((__format__(__printf__,3,4)));
typedef struct CpuStatus_t
{
bool valid; // TRUE: data valid (setup done)
+ bool have_irq; // TRUE if 'irq' ever >0
+ bool have_virtual; // TRUE if 'virtual' ever >0
+ bool have_unknown; // TRUE if 'unknown' ever >0
+
u_nsec_t nsec; // GetTimerNSec()
int clock_ticks; // number of clock ticks per second
int n_cpu; // total number of cpus
// all times in 1e4 ticks per second (in 0.01%)
- u64 user; // time spent in user mode.
- u64 nice; // time spent in user mode with low priority.
- u64 system; // time spent in system mode.
- u64 idle; // time spent in the idle task.
+ u64 user; // 1: time spent in user mode.
+ u64 nice; // 2: time spent in user mode with low priority.
+ u64 system; // 3: time spent in system mode.
+ u64 idle; // 4: time spent in the idle task.
+ u64 iowait; // 5: time waiting for I/O to complete (not reliable).
+ u64 irq; // 6..7: Time servicing (soft-)interrupts.
+ u64 virtual; // 8..10: time for virtual os.
+ u64 unknown; // 11...: time for future extentions
int running_proc; // currently runnable processes
int total_proc; // currently total processes
diff --git a/project/dclib/dclib-numeric.c b/project/dclib/dclib-numeric.c
index 51a8bce..6896b53 100644
--- a/project/dclib/dclib-numeric.c
+++ b/project/dclib/dclib-numeric.c
@@ -3281,7 +3281,7 @@ ccp PrintNTimeByFormatUTC
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_nsec_t ntime
+ u_nsec_t ntime // time in nsec, e.g. get by GetTimeNSec(false)
)
{
return PrintNSecByFormatUTC(format,ntime/NSEC_PER_SEC,ntime%NSEC_PER_SEC);
@@ -3295,7 +3295,7 @@ ccp PrintUTimeByFormat
ccp format, // format string for strftime()
// 1-9 '@' in row replaced by digits of 'usec'
- u_usec_t utime
+ u_usec_t utime // time in nsec, e.g. get by GetTimeNSec(false)
)
{
return PrintNSecByFormat(format,utime/USEC_PER_SEC,utime%USEC_PER_SEC*NSEC_PER_USEC);
@@ -3936,7 +3936,7 @@ ccp PrintTimer6N
}
}
- return buf == temp ? CopyCircBuf0(buf,strlen(buf)) : buf;
+ return CopyCircBuf0If(buf==temp,buf,strlen(buf));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-types.h b/project/dclib/dclib-types.h
index d8fde33..3d17081 100644
--- a/project/dclib/dclib-types.h
+++ b/project/dclib/dclib-types.h
@@ -50,6 +50,34 @@
//
///////////////////////////////////////////////////////////////////////////////
+/////////////// versions ///////////////
+///////////////////////////////////////////////////////////////////////////////
+// Predefined Macros: https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
+
+#if defined(__GNUC__)
+ #if defined(__GNUC_MINOR__)
+ #define DCLIB_GNUC_VERSION ( 1000 * __GNUC__ + __GNUC_MINOR__ )
+ #else
+ #define DCLIB_GNUC_VERSION ( 1000 * __GNUC__ )
+ #endif
+#else
+ #define DCLIB_GNUC_VERSION 0
+#endif
+
+//-----------------------------------------------------------------------------
+
+#if defined(__GLIBC__)
+ #if defined(__GLIBC_MINOR__)
+ #define DCLIB_GLIBC_VERSION ( 1000 * __GLIBC__ + __GLIBC_MINOR__ )
+ #else
+ #define DCLIB_GLIBC_VERSION ( 1000 * __GLIBC__ )
+ #endif
+#else
+ #define DCLIB_GLIBC_VERSION 0
+#endif
+
+//
+///////////////////////////////////////////////////////////////////////////////
/////////////// endian ///////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/lib-dol.h b/project/dclib/lib-dol.h
index 6637a2e..9f41a5e 100644
--- a/project/dclib/lib-dol.h
+++ b/project/dclib/lib-dol.h
@@ -457,7 +457,7 @@ typedef struct wch_header_t
{
// big endian!
- u32 magic; // magic: 'W\x{05}CH' (Gecko Code Handler)
+ u32 magic; // magic: 'W\x{05}CH' (Wiimm's Code Handler)
u32 version; // 0: raw, 1: bzip2
u32 size; // total size of (uncompressed) segment data