aboutsummaryrefslogtreecommitdiff
path: root/project/dclib
diff options
context:
space:
mode:
authorWiimm <wiimm@wiimm.de>2023-07-11 16:18:26 +0200
committerWiimm <wiimm@wiimm.de>2023-07-11 16:18:26 +0200
commitb5b1fe7fc0cf460d6204c18ba7bb4c40f7597efa (patch)
treea7b4bb1e79fde818dd7af17fee1207ae40178ab7 /project/dclib
parent74ac39c1af5c8e85bf10711aed2ffc9dfee2e277 (diff)
SZS v2.35a
Diffstat (limited to '')
-rw-r--r--project/dclib/dclib-basics.h14
-rw-r--r--project/dclib/dclib-debug.c44
-rw-r--r--project/dclib/dclib-debug.h7
-rw-r--r--project/dclib/dclib-numeric.c85
-rw-r--r--project/dclib/dclib-parser.c5
-rw-r--r--project/dclib/dclib-parser.h4
-rw-r--r--project/dclib/dclib-types.h3
-rw-r--r--project/dclib/lib-mkw.c138
-rw-r--r--project/dclib/lib-mkw.h11
9 files changed, 299 insertions, 12 deletions
diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h
index 3110e57..c03708a 100644
--- a/project/dclib/dclib-basics.h
+++ b/project/dclib/dclib-basics.h
@@ -4190,6 +4190,20 @@ char * PrintSize1024
sizeform_mode_t sform_mode // output format, bit field
);
+//-----------------------------------------------------------------------------
+
+char * PrintHMS
+(
+ char *buf, // result buffer
+ // NULL: use a local circulary static buffer
+ size_t buf_size, // size of 'buf', ignored if buf==NULL
+
+ int seconds, // seconds to print
+ int min_seconds, // print only if 'seconds >= min_seconds'
+ ccp pre_text, // not NULL: Print text before H:M:S
+ ccp post_text // not NULL: Print text behind H:M:S
+);
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// scan size ///////////////
diff --git a/project/dclib/dclib-debug.c b/project/dclib/dclib-debug.c
index a5d978f..a3af57f 100644
--- a/project/dclib/dclib-debug.c
+++ b/project/dclib/dclib-debug.c
@@ -597,6 +597,21 @@ bool mark_used ( ccp name, ... )
/////////////// hexdump ///////////////
///////////////////////////////////////////////////////////////////////////////
+uint HexDump ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
+ const void * p_data, size_t count )
+{
+ // return the number of printed lines
+ if ( !f || !p_data || !count )
+ return 0;
+
+ XDump_t xd;
+ InitializeXDumpEx(&xd,f,indent,addr,addr_fw,row_len);
+ const int stat = XDump(&xd,p_data,count,true);
+ return stat < 0 ? 0 : stat;
+}
+
+//-----------------------------------------------------------------------------
+
uint HexDump16 ( FILE * f, int indent, u64 addr,
const void * data, size_t count )
{
@@ -613,19 +628,32 @@ uint HexDump20 ( FILE * f, int indent, u64 addr,
return HexDump(f,indent,addr,4,20,data,count);
}
-//-----------------------------------------------------------------------------
+///////////////////////////////////////////////////////////////////////////////
-uint HexDump ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
+uint HexDumpCRLF ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
const void * p_data, size_t count )
{
+ const typeof(hexdump_eol)saved_eol = hexdump_eol;
+ hexdump_eol = "\r\n";
+ const uint stat = HexDump(f,indent,addr,addr_fw,row_len,p_data,count);
+ hexdump_eol = saved_eol;
+ return stat;
+}
+
+//-----------------------------------------------------------------------------
+
+uint HexDump16CRLF ( FILE * f, int indent, u64 addr, const void * data, size_t count )
+{
// return the number of printed lines
- if ( !f || !p_data || !count )
- return 0;
+ return HexDumpCRLF(f,indent,addr,4,16,data,count);
+}
- XDump_t xd;
- InitializeXDumpEx(&xd,f,indent,addr,addr_fw,row_len);
- const int stat = XDump(&xd,p_data,count,true);
- return stat < 0 ? 0 : stat;
+//-----------------------------------------------------------------------------
+
+uint HexDump20CRLF ( FILE * f, int indent, u64 addr, const void * data, size_t count )
+{
+ // return the number of printed lines
+ return HexDumpCRLF(f,indent,addr,4,20,data,count);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/project/dclib/dclib-debug.h b/project/dclib/dclib-debug.h
index 7328770..4285f61 100644
--- a/project/dclib/dclib-debug.h
+++ b/project/dclib/dclib-debug.h
@@ -171,6 +171,13 @@ uint HexDump16 ( FILE * f, int indent, u64 addr,
uint HexDump20 ( FILE * f, int indent, u64 addr,
const void * data, size_t count );
+uint HexDumpCRLF ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
+ const void * p_data, size_t count );
+uint HexDump16CRLF ( FILE * f, int indent, u64 addr,
+ const void * data, size_t count );
+uint HexDump20CRLF ( FILE * f, int indent, u64 addr,
+ const void * data, size_t count );
+
uint HexDumpBE2 ( FILE * f, int indent, u64 addr, int addr_fw, int row_len,
const void * data, size_t count );
uint HexDump16BE2 ( FILE * f, int indent, u64 addr,
diff --git a/project/dclib/dclib-numeric.c b/project/dclib/dclib-numeric.c
index 6896b53..aa0ecd6 100644
--- a/project/dclib/dclib-numeric.c
+++ b/project/dclib/dclib-numeric.c
@@ -968,6 +968,41 @@ int CheckIndexCEnd ( int max, int * p_begin, int count )
//
///////////////////////////////////////////////////////////////////////////////
+/////////////// struct IntMode_t ///////////////
+///////////////////////////////////////////////////////////////////////////////
+
+ccp GetIntModeName ( IntMode_t mode )
+{
+ switch(mode)
+ {
+ case IMD_UNSET: return "-";
+
+ case IMD_BE0: return "BE";
+ case IMD_BE1: return "BE1";
+ case IMD_BE2: return "BE2";
+ case IMD_BE3: return "BE3";
+ case IMD_BE4: return "BE4";
+ case IMD_BE5: return "BE5";
+ case IMD_BE6: return "BE6";
+ case IMD_BE7: return "BE7";
+ case IMD_BE8: return "BE8";
+
+ case IMD_LE0: return "LE";
+ case IMD_LE1: return "LE1";
+ case IMD_LE2: return "LE2";
+ case IMD_LE3: return "LE3";
+ case IMD_LE4: return "LE4";
+ case IMD_LE5: return "LE5";
+ case IMD_LE6: return "LE6";
+ case IMD_LE7: return "LE7";
+ case IMD_LE8: return "LE8";
+
+ default: return "?";
+ }
+}
+
+//
+///////////////////////////////////////////////////////////////////////////////
/////////////// lt/eq/gt ///////////////
///////////////////////////////////////////////////////////////////////////////
@@ -8336,6 +8371,56 @@ char * PrintSize1024
return buf;
};
+//-----------------------------------------------------------------------------
+
+char * PrintHMS
+(
+ char *buf, // result buffer
+ // NULL: use a local circulary static buffer
+ size_t buf_size, // size of 'buf', ignored if buf==NULL
+
+ int seconds, // seconds to print
+ int min_seconds, // print only if 'seconds >= min_seconds'
+ ccp pre_text, // not NULL: Print text before H:M:S
+ ccp post_text // not NULL: Print text behind H:M:S
+)
+{
+ if ( seconds < min_seconds )
+ {
+ if (!buf)
+ return "";
+
+ *buf = 0;
+ return buf;
+ }
+
+ if (!pre_text)
+ pre_text = "";
+ if (!post_text)
+ post_text = "";
+
+ const ccp sign = seconds < 0 ? "-" : "";
+ seconds = abs(seconds);
+ const int hours = seconds / 3600;
+ const int minutes = seconds % 3600 / 60;
+ seconds = seconds % 60;
+
+ if (!buf)
+ return hours
+ ? PrintCircBuf("%s%s%u:%02u:%02u%s",pre_text,sign,hours,minutes,seconds,post_text)
+ : minutes
+ ? PrintCircBuf("%s%s%u:%02u%s",pre_text,sign,minutes,seconds,post_text)
+ : PrintCircBuf("%s%s%02us%s",pre_text,sign,seconds,post_text);
+
+ if (hours)
+ snprintf(buf,buf_size,"%s%s%u:%02u:%02u%s",pre_text,sign,hours,minutes,seconds,post_text);
+ else if (minutes)
+ snprintf(buf,buf_size,"%s%s%u:%02u%s",pre_text,sign,minutes,seconds,post_text);
+ else
+ snprintf(buf,buf_size,"%s%s%02us%s",pre_text,sign,seconds,post_text);
+ return buf;
+}
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// scan size ///////////////
diff --git a/project/dclib/dclib-parser.c b/project/dclib/dclib-parser.c
index b64914f..a94b8c6 100644
--- a/project/dclib/dclib-parser.c
+++ b/project/dclib/dclib-parser.c
@@ -49,6 +49,7 @@ void SetupScanText ( ScanText_t *st, cvp data, uint data_size )
st->data = data;
st->data_size = data_size;
st->ignore_comments = true;
+ st->ignore_values = true;
RewindScanText(st);
}
@@ -97,6 +98,7 @@ bool NextLineScanText ( ScanText_t *st )
{
DASSERT(st);
st->is_section = false;
+ st->is_value = false;
ccp ptr = st->ptr;
ccp eot = st->eot;
@@ -120,7 +122,8 @@ bool NextLineScanText ( ScanText_t *st )
while ( eol > line && eol[-1] == ' ' || eol[-1] == '\t' )
eol--;
- if ( line == eol || *line == '#' && st->ignore_comments )
+ st->is_value = *line == '@';
+ if ( line == eol || *line == '#' && st->ignore_comments || st->is_value && st->ignore_values )
continue;
if ( st->detect_sections > 0
&& *line == '['
diff --git a/project/dclib/dclib-parser.h b/project/dclib/dclib-parser.h
index e9a4830..ff73a58 100644
--- a/project/dclib/dclib-parser.h
+++ b/project/dclib/dclib-parser.h
@@ -56,15 +56,17 @@ typedef struct ScanText_t
//-- options
bool ignore_comments; // true: ignore lines with leading '#'
+ bool ignore_values; // true: ignore lines with leading '@'
int detect_sections; // >0: detect lines of format '[...]'
- //-- current statee
+ //-- current state
ccp ptr; // current text position
ccp eot; // end of text
ccp line; // current line
ccp eol; // end of current line
+ bool is_value; // current line begins with '@'
bool is_eot; // end of text reached
bool is_section; // new section reached
bool is_term; // := is_eot || is_section
diff --git a/project/dclib/dclib-types.h b/project/dclib/dclib-types.h
index 3d17081..2ef0de7 100644
--- a/project/dclib/dclib-types.h
+++ b/project/dclib/dclib-types.h
@@ -160,6 +160,9 @@ __attribute__ ((packed)) dcEndian_t;
#define ALIGNOFF32(d,a) ((d)&~(u32)((a)-1))
#define ALIGNOFF64(d,a) ((d)&~(u64)((a)-1))
+#define MINMAX(v,min,max) ( v < min ? min : v > max ? max : v )
+#define MINMAX0(v,min,max) ( v == 0 ? 0 : v < min ? min : v > max ? max : v )
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// error codes ///////////////
diff --git a/project/dclib/lib-mkw.c b/project/dclib/lib-mkw.c
index 5213e72..da955a1 100644
--- a/project/dclib/lib-mkw.c
+++ b/project/dclib/lib-mkw.c
@@ -1322,6 +1322,63 @@ ccp GetVehicleName4 ( u8 vehicle )
/////////////// LE-CODE track flags ///////////////
///////////////////////////////////////////////////////////////////////////////
+typedef struct use_color_t
+{
+ char *buf; // valid destination buffer
+ char *ptr; // current pointer for appends, if NULL: set to 'buf' first
+ uint size; // size of 'buf'
+ ColorSet_t *col; // valid color definition, never NULL
+ int index; // current color index: 0:off, 1:on, 2:bold
+}
+use_color_t;
+
+//-----------------------------------------------------------------------------
+
+static char * UseColor
+(
+ // returns 'ucol.ptr'
+ use_color_t *ucol, // initialized data structure
+ int index, // next color
+ char ch // not NULL: Append character
+)
+{
+ DASSERT(ucol);
+ DASSERT(ucol->buf);
+ DASSERT(ucol->col);
+ if (!ucol->ptr)
+ ucol->ptr = ucol->buf;
+
+ ccp copy_src = 0;
+ int copy_len = 0;
+ if ( ucol->index != index )
+ {
+ ucol->index = index;
+ switch (index)
+ {
+ case 1: copy_src = ucol->col->info; break;
+ case 2: copy_src = ucol->col->hint; break;
+ default: copy_src = ucol->col->reset; break;
+ }
+ copy_len = strlen(copy_src);
+ }
+
+ if ( ucol->ptr + copy_len < ucol->buf + ucol->size - 1 )
+ {
+ if (copy_len)
+ {
+ memcpy(ucol->ptr,copy_src,copy_len);
+ ucol->ptr += copy_len;
+ }
+ if (ch)
+ *ucol->ptr++ = ch;
+ }
+
+ *ucol->ptr = 0;
+ return ucol->ptr;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
le_flags_t ScanLEFL ( ccp text )
{
// automatic flags are not scannend!
@@ -1378,6 +1435,21 @@ ccp PrintLEFL8 ( le_flags_t flags, bool aligned )
///////////////////////////////////////////////////////////////////////////////
+ccp PrintLEFL8col ( le_flags_t flags, bool aligned, ColorSet_t *col )
+{
+ #if 1
+ return PrintLEFL8(flags,aligned);
+ #else
+ if (!col)
+ return PrintLEFL8(flags,aligned);
+
+ // ??? [[2do]]
+ return PrintLEFL8(flags,aligned);
+ #endif
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
ccp PrintLEFL16 ( le_flags_t flags, bool aligned )
{
char *buf = GetCircBuf(7);
@@ -1445,6 +1517,72 @@ ccp PrintLEFL16 ( le_flags_t flags, bool aligned )
return buf;
}
+///////////////////////////////////////////////////////////////////////////////
+
+ccp PrintLEFL16col ( le_flags_t flags, bool aligned, ColorSet_t *col )
+{
+ if ( !col || (flags & ~G_LEFL__XALL) )
+ return PrintLEFL16(flags,aligned);
+
+ char buf[300];
+ use_color_t ucol = { .buf = buf, .size = sizeof(buf), .col = col };
+
+ switch ( flags & (G_LEFL_BATTLE|G_LEFL_VERSUS|G_LEFL_RANDOM) )
+ {
+ case G_LEFL_BATTLE: UseColor(&ucol,1,'B'); break;
+ case G_LEFL_VERSUS: UseColor(&ucol,0,'V'); break;
+ case G_LEFL_RANDOM: UseColor(&ucol,2,'r'); break;
+ default:
+ if ( aligned )
+ UseColor(&ucol,0,'-');
+ }
+
+ switch ( flags & (G_LEFL_ORIG_CUP|G_LEFL_CUSTOM_CUP) )
+ {
+ case G_LEFL_ORIG_CUP: UseColor(&ucol,0,'o'); break;
+ case G_LEFL_CUSTOM_CUP: UseColor(&ucol,1,'c'); break;
+ case G_LEFL_ORIG_CUP | G_LEFL_CUSTOM_CUP: UseColor(&ucol,2,'b'); break;
+ default:
+ if ( aligned )
+ UseColor(&ucol,0,'-');
+ }
+
+ switch ( flags & (G_LEFL_RND_HEAD|G_LEFL_RND_GROUP) )
+ {
+ case G_LEFL_RND_HEAD: UseColor(&ucol,1,'H'); break;
+ case G_LEFL_RND_GROUP: UseColor(&ucol,0,'G'); break;
+ case G_LEFL_RND_HEAD | G_LEFL_RND_GROUP: UseColor(&ucol,2,'X'); break;
+ default:
+ if ( aligned )
+ UseColor(&ucol,0,'-');
+ }
+
+ switch ( flags & (G_LEFL_NEW|G_LEFL_TEXTURE) )
+ {
+ case G_LEFL_NEW: UseColor(&ucol,0,'N'); break;
+ case G_LEFL_TEXTURE: UseColor(&ucol,1,'T'); break;
+ case G_LEFL_NEW | G_LEFL_TEXTURE: UseColor(&ucol,2,'2'); break;
+ default:
+ if ( aligned )
+ UseColor(&ucol,0,'-');
+ }
+
+ if (aligned)
+ {
+ UseColor(&ucol,0, flags & G_LEFL_ALIAS ? 'A' : '-' );
+ UseColor(&ucol,0, flags & G_LEFL_HIDDEN ? 'i' : '-' );
+ }
+ else
+ {
+ if ( flags & G_LEFL_ALIAS ) UseColor(&ucol,0,'A');
+ if ( flags & G_LEFL_HIDDEN ) UseColor(&ucol,0,'i');
+ if ( ucol.ptr == buf )
+ UseColor(&ucol,0,'-');
+ }
+
+ return CopyCircBuf0(buf,ucol.ptr-buf);
+}
+
//
///////////////////////////////////////////////////////////////////////////////
/////////////// distribution flags ///////////////
diff --git a/project/dclib/lib-mkw.h b/project/dclib/lib-mkw.h
index 71ef140..b0d7558 100644
--- a/project/dclib/lib-mkw.h
+++ b/project/dclib/lib-mkw.h
@@ -474,12 +474,19 @@ static inline bool IsRandomLEFL ( le_flags_t flags )
le_flags_t ScanLEFL ( ccp text );
-ccp PrintLEFL8 ( le_flags_t flags, bool aligned );
-ccp PrintLEFL16 ( le_flags_t flags, bool aligned );
+ccp PrintLEFL8 ( le_flags_t flags, bool aligned );
+ccp PrintLEFL16 ( le_flags_t flags, bool aligned );
+
+// use PrintLEFL8() or PrintLEFL16() if col==0
+ccp PrintLEFL8col ( le_flags_t flags, bool aligned, ColorSet_t *col );
+ccp PrintLEFL16col ( le_flags_t flags, bool aligned, ColorSet_t *col );
static inline ccp PrintLEFL ( le_flags_t flags_bits, le_flags_t flags, bool aligned )
{ return ( flags_bits == 16 ? PrintLEFL16 : PrintLEFL8 )(flags,aligned); }
+static inline ccp PrintLEFLcol ( le_flags_t flags_bits, le_flags_t flags, bool aligned, ColorSet_t *col )
+ { return ( flags_bits == 16 ? PrintLEFL16col : PrintLEFL8col )(flags,aligned,col); }
+
typedef ccp (*PrintLEFL_func) ( le_flags_t flags, bool aligned );
static inline PrintLEFL_func GetPrintLEFL ( uint flags_bits )
{ return flags_bits == 16 ? PrintLEFL16 : PrintLEFL8; }