Merge branch 'main' into network
This commit is contained in:
commit
3d15cb35af
3
Makefile
3
Makefile
@ -1,4 +1,6 @@
|
|||||||
###### Build cbuild/default_tasks #######
|
###### Build cbuild/default_tasks #######
|
||||||
|
all: build_exec
|
||||||
|
|
||||||
build_exec:
|
build_exec:
|
||||||
@cbuild/call_task.sh build_exec
|
@cbuild/call_task.sh build_exec
|
||||||
build_exec_dbg:
|
build_exec_dbg:
|
||||||
@ -21,4 +23,3 @@ exec: build_exec
|
|||||||
valgrind: build_exec_dbg
|
valgrind: build_exec_dbg
|
||||||
@cbuild/call_task.sh valgrind
|
@cbuild/call_task.sh valgrind
|
||||||
|
|
||||||
all: build_exec
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
CONFIG_VERSION=3
|
CBUILD_VERSION=3
|
||||||
CBUILD_VERSION=2
|
CONFIG_VERSION=4
|
||||||
|
|
||||||
PROJECT=kerep
|
PROJECT=kerep
|
||||||
CMP_C=gcc
|
CMP_C=gcc
|
||||||
CMP_CPP=g++
|
CMP_CPP=g++
|
||||||
STD_C=c11
|
STD_C=c11
|
||||||
STD_CPP=c++17
|
STD_CPP=c++17
|
||||||
WARN_C="-Wall -Wno-discarded-qualifiers -Wno-int-conversion"
|
WARN_C="-Wall -Wno-discarded-qualifiers"
|
||||||
WARN_CPP="-Wall"
|
WARN_CPP="-Wall"
|
||||||
SRC_C="$( find src -name '*.c')"
|
SRC_C="$( find src -name '*.c')"
|
||||||
SRC_CPP="$( find src -name '*.cpp')"
|
SRC_CPP="$( find src -name '*.cpp')"
|
||||||
|
|||||||
@ -13,7 +13,7 @@ Array_declare(FilePath);
|
|||||||
typedef FILE File;
|
typedef FILE File;
|
||||||
ktid_declare(File);
|
ktid_declare(File);
|
||||||
|
|
||||||
typedef enum FileOpenMode{
|
PACK_ENUM(FileOpenMode,
|
||||||
// open a file for reading
|
// open a file for reading
|
||||||
FileOpenMode_Read=1,
|
FileOpenMode_Read=1,
|
||||||
// (re)create a file for writing
|
// (re)create a file for writing
|
||||||
@ -24,7 +24,7 @@ typedef enum FileOpenMode{
|
|||||||
FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write,
|
FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write,
|
||||||
// opens file for readng/writing additional data to the end / creates new file
|
// opens file for readng/writing additional data to the end / creates new file
|
||||||
FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append
|
FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append
|
||||||
} FileOpenMode;
|
)
|
||||||
|
|
||||||
|
|
||||||
/// @brief opens file
|
/// @brief opens file
|
||||||
|
|||||||
@ -10,6 +10,7 @@ extern "C" {
|
|||||||
#include "optime.h"
|
#include "optime.h"
|
||||||
#include "type_system/type_system.h"
|
#include "type_system/type_system.h"
|
||||||
#include "../kprint/kprintf.h"
|
#include "../kprint/kprintf.h"
|
||||||
|
#include "endian.h"
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/base/endian.c
Normal file
13
src/base/endian.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "endian.h"
|
||||||
|
|
||||||
|
static const union
|
||||||
|
{
|
||||||
|
uint16 number;
|
||||||
|
Endian bytes[2];
|
||||||
|
} _endian_union={ .number=0x0102 };
|
||||||
|
|
||||||
|
Endian getEndian(){
|
||||||
|
// if 0x0102 == { 1, 2 } then BigEndian
|
||||||
|
// if 0x0102 == { 2, 1 } then LittleEndian
|
||||||
|
return _endian_union.bytes[1];
|
||||||
|
}
|
||||||
9
src/base/endian.h
Normal file
9
src/base/endian.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "std.h"
|
||||||
|
|
||||||
|
PACK_ENUM(Endian,
|
||||||
|
UnknownEndian=0,
|
||||||
|
LittleEndian=1,
|
||||||
|
BigEndian=2
|
||||||
|
);
|
||||||
|
|
||||||
|
Endian getEndian();
|
||||||
@ -7,13 +7,13 @@ extern "C" {
|
|||||||
#include "std.h"
|
#include "std.h"
|
||||||
#include "type_system/unitype.h"
|
#include "type_system/unitype.h"
|
||||||
|
|
||||||
typedef enum ErrorId {
|
PACK_ENUM(ErrorId,
|
||||||
SUCCESS, // not an error
|
SUCCESS, // not an error
|
||||||
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
|
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
|
||||||
ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
|
ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
|
||||||
ERR_KEYNOTFOUND, ERR_FORMAT, ERR_UNEXPECTEDVAL,
|
ERR_KEYNOTFOUND, ERR_FORMAT, ERR_UNEXPECTEDVAL,
|
||||||
ERR_IO, ERR_IO_EOF
|
ERR_IO, ERR_IO_EOF
|
||||||
} ErrorId;
|
)
|
||||||
|
|
||||||
char* errname(ErrorId err);
|
char* errname(ErrorId err);
|
||||||
|
|
||||||
|
|||||||
@ -2,24 +2,40 @@
|
|||||||
|
|
||||||
#include "std.h"
|
#include "std.h"
|
||||||
|
|
||||||
// executes codeblock and prints execution time
|
#define __optime_print(opname, t)\
|
||||||
#ifdef CLOCK_REALTIME // non-standard high-precision clock
|
char tnames[3][3]={"s\0","ms","us"};\
|
||||||
#define optime(opname,repeats,codeblock) ({\
|
int tni=0;\
|
||||||
struct timespec start, stop;\
|
if(t>1000000){\
|
||||||
clock_gettime(CLOCK_REALTIME, &start);\
|
t/=1000000;\
|
||||||
for(uint64 ___OPREP=0;___OPREP<(uint64)repeats;___OPREP++)\
|
tni=0;\
|
||||||
(codeblock);\
|
} else if(t>1000){\
|
||||||
clock_gettime(CLOCK_REALTIME, &stop);\
|
t/=1000;\
|
||||||
double t=(double)(stop.tv_sec-start.tv_sec+(double)(stop.tv_nsec-start.tv_nsec)/1000000000)/repeats;\
|
tni=1;\
|
||||||
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
} else tni=2;\
|
||||||
})
|
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n",\
|
||||||
#else // standard low precision clock
|
opname, t, tnames[tni]);
|
||||||
#define optime(opname,repeats,codeblock) ({\
|
|
||||||
clock_t start=clock();\
|
#ifdef CLOCK_REALTIME
|
||||||
for(uint64 ___OPREP=0;___OPREP<(uint64)repeats;___OPREP++)\
|
/// executes codeblock and prints execution time
|
||||||
(codeblock);\
|
/// uint64 op_i is counter of the internal loop
|
||||||
clock_t stop=clock();\
|
/// uses non-standard high-precision clock
|
||||||
double t=(double)(stop-start)/CLOCKS_PER_SEC/repeats;\
|
#define optime(opname,repeats,codeblock) ({\
|
||||||
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
struct timespec start, stop;\
|
||||||
})
|
clock_gettime(CLOCK_REALTIME, &start);\
|
||||||
|
for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\
|
||||||
|
(codeblock);\
|
||||||
|
clock_gettime(CLOCK_REALTIME, &stop);\
|
||||||
|
double t=(double)(stop.tv_sec-start.tv_sec)*1000000+(double)(stop.tv_nsec-start.tv_nsec)/1000;\
|
||||||
|
__optime_print(opname,t)\
|
||||||
|
})
|
||||||
|
#else
|
||||||
|
/// uses standard low precision clock
|
||||||
|
#define optime(opname,repeats,codeblock) ({\
|
||||||
|
clock_t start=clock();\
|
||||||
|
for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\
|
||||||
|
(codeblock);\
|
||||||
|
clock_t stop=clock();\
|
||||||
|
double t=(double)(stop-start)/CLOCKS_PER_SEC*1000000;\
|
||||||
|
__optime_print(opname,t)\
|
||||||
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -72,18 +72,56 @@ typedef uint8 bool;
|
|||||||
|
|
||||||
|
|
||||||
#define __count_args(\
|
#define __count_args(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7 ,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||||
a24,a25,a26,a27,a28,a29,a30,a31,\
|
a24,a25,a26,a27,a28,a29,a30,a31,\
|
||||||
a32,...) a32
|
a32,a33,a34,a35,a36,a37,a38,a39,\
|
||||||
|
a40,a41,a42,a43,a44,a45,a46,a47,\
|
||||||
|
a48,a49,a50,a51,a52,a53,a54,a55,\
|
||||||
|
a56,a57,a58,a59,a60,a61,a62,a63,\
|
||||||
|
a64,...) a64
|
||||||
|
// Macro for counting variadic arguments (max 64)
|
||||||
|
// (see usage in kprint.h)
|
||||||
#define count_args(ARGS...) __count_args(\
|
#define count_args(ARGS...) __count_args(\
|
||||||
ARGS,\
|
ARGS,\
|
||||||
|
64,63,62,61,60,59,58,57,\
|
||||||
|
56,55,54,53,52,51,50,49,\
|
||||||
|
48,47,46,45,44,43,42,41,\
|
||||||
|
40,39,38,37,36,35,34,33,\
|
||||||
32,31,30,29,28,27,26,25,\
|
32,31,30,29,28,27,26,25,\
|
||||||
24,23,22,21,20,19,18,17,\
|
24,23,22,21,20,19,18,17,\
|
||||||
16,15,14,13,12,11,10,9,\
|
16,15,14,13,12,11,10,9,\
|
||||||
8, 7, 6, 5, 4, 3, 2, 1, 0)
|
8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Cross-platform warning supression.
|
||||||
|
WARNING_DISABLE( W_EXAMPLE,
|
||||||
|
some code producing W_EXAMPLE;
|
||||||
|
);
|
||||||
|
You can even embed it into macro in header (see kprint.h)
|
||||||
|
*/
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define PRAGMA_WARNING_PUSH __pragma(warning( push ))
|
||||||
|
#define DISABLE_WARNING(wNumber) __pragma(warning( disable : wNumber ))
|
||||||
|
#define PRAGMA_WARNING_POP __pragma(warning( pop ))
|
||||||
|
#else
|
||||||
|
#define _PRAGMA(P) _Pragma(#P)
|
||||||
|
#define PRAGMA_WARNING_PUSH _PRAGMA(GCC diagnostic push)
|
||||||
|
#define PRAGMA_WARNING_DISABLE(wName) _PRAGMA(GCC diagnostic ignored wName)
|
||||||
|
#define PRAGMA_WARNING_POP _PRAGMA(GCC diagnostic pop)
|
||||||
|
#define W_INT_CONVERSION "-Wint-conversion"
|
||||||
|
#endif
|
||||||
|
#define WARNING_DISABLE(WARNING, CODE)\
|
||||||
|
PRAGMA_WARNING_PUSH\
|
||||||
|
PRAGMA_WARNING_DISABLE(WARNING)\
|
||||||
|
CODE;\
|
||||||
|
PRAGMA_WARNING_POP
|
||||||
|
|
||||||
|
#define PACK_ENUM(ENUM_NAME, ENUM_MEMBERS...) typedef enum ENUM_NAME {\
|
||||||
|
ENUM_MEMBERS\
|
||||||
|
} __attribute__((__packed__)) ENUM_NAME;
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -4,14 +4,14 @@
|
|||||||
|
|
||||||
char* __toString_char(void* c, uint32 fmt) {
|
char* __toString_char(void* c, uint32 fmt) {
|
||||||
//*c=char
|
//*c=char
|
||||||
if(kprint_format_dataFormat(fmt)==kprint_fmtChar){
|
if(kp_fmt_dataFormat(fmt)==kp_c){
|
||||||
char* cc=malloc(2);
|
char* cc=malloc(2);
|
||||||
cc[0]=*(char*)c;
|
cc[0]=*(char*)c;
|
||||||
cc[1]=0;
|
cc[1]=0;
|
||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
// *c=cstring
|
// *c=cstring
|
||||||
else if(kprint_format_dataFormat(fmt)==kprint_fmtString){
|
else if(kp_fmt_dataFormat(fmt)==kp_s){
|
||||||
return cptr_copy(*(char**)c);
|
return cptr_copy(*(char**)c);
|
||||||
}
|
}
|
||||||
else throw(ERR_FORMAT);
|
else throw(ERR_FORMAT);
|
||||||
@ -19,7 +19,7 @@ char* __toString_char(void* c, uint32 fmt) {
|
|||||||
|
|
||||||
char* __toString_bool(void* c, uint32 fmt) {
|
char* __toString_bool(void* c, uint32 fmt) {
|
||||||
static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" };
|
static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" };
|
||||||
uint8 strind=*(bool*)c==1 + kprint_format_uppercase(fmt)*2;
|
uint8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2;
|
||||||
char* rez=malloc(6);
|
char* rez=malloc(6);
|
||||||
rez[0]=_strbool[strind][0];
|
rez[0]=_strbool[strind][0];
|
||||||
rez[1]=_strbool[strind][1];
|
rez[1]=_strbool[strind][1];
|
||||||
@ -31,72 +31,90 @@ char* __toString_bool(void* c, uint32 fmt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* toString_int(int64 n){
|
char* toString_int(int64 n){
|
||||||
int64 d=n;
|
int64 d=n<0 ? -1*n : n;
|
||||||
char str[32];
|
char str[32];
|
||||||
uint8 i=sizeof(str);
|
uint8 i=sizeof(str);
|
||||||
str[--i]=0;
|
str[--i]=0;
|
||||||
while(d!=0){
|
if(d==0)
|
||||||
|
str[--i]='0';
|
||||||
|
else while(d!=0){
|
||||||
str[--i]='0' + d%10;
|
str[--i]='0' + d%10;
|
||||||
d/=10;
|
d/=10;
|
||||||
}
|
}
|
||||||
if(n>>63)
|
if(n<0)
|
||||||
str[--i]='-';
|
str[--i]='-';
|
||||||
return cptr_copy((char*)str+i);
|
return cptr_copy((char*)str+i);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_uint(uint64 n, bool withPostfix, bool uppercase){
|
char* toString_uint(uint64 n, bool withPostfix, bool uppercase){
|
||||||
uint64 d=n;
|
|
||||||
char str[32];
|
char str[32];
|
||||||
uint8 i=sizeof(str);
|
uint8 i=sizeof(str);
|
||||||
str[--i]=0;
|
str[--i]=0;
|
||||||
if(withPostfix)
|
if(withPostfix)
|
||||||
str[--i]= uppercase ? 'U' : 'u';
|
str[--i]= uppercase ? 'U' : 'u';
|
||||||
while(d!=0){
|
if(n==0)
|
||||||
str[--i]='0' + d%10;
|
str[--i]='0';
|
||||||
d/=10;
|
else while(n!=0){
|
||||||
|
str[--i]='0' + n%10;
|
||||||
|
n/=10;
|
||||||
}
|
}
|
||||||
return cptr_copy((char*)str+i);
|
return cptr_copy((char*)str+i);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_float(float64 n, bool withPostfix, bool uppercase){
|
#define _toString_float_impl(bufsize, maxPrecision) {\
|
||||||
// int64 d=n;
|
char str[bufsize];\
|
||||||
// float64 r=n-d;
|
if(precision>maxPrecision)\
|
||||||
// char* strint=toString_int(d);
|
throw("too big precision");\
|
||||||
// char strfract[32];
|
if(precision==0)\
|
||||||
// uint8 i=0;
|
precision=toString_float_default_precision;\
|
||||||
// strfract[i++]='.';
|
int cn=sprintf(str, "%.*f", precision, n);\
|
||||||
// while(r!=0){
|
/* remove trailing zeroes except .0*/\
|
||||||
// r*=10.0;
|
while(str[cn-1]=='0' && str[cn-2]!='.')\
|
||||||
// char fc=r;
|
cn--;\
|
||||||
// strfract[i++]=fc;
|
if(withPostfix)\
|
||||||
// r-=fc;
|
str[cn++]= uppercase ? 'F' : 'f';\
|
||||||
// }
|
str[cn]='\0';\
|
||||||
// if(withPostfix)
|
return cptr_copy(str);\
|
||||||
// strfract[i++]= uppercase ? 'F' : 'f';
|
|
||||||
// strfract[i]=0;
|
|
||||||
// char* str==cptr_concat(strint, strfract);
|
|
||||||
// free(strint);
|
|
||||||
// return str;
|
|
||||||
return cptr_copy("<float>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_bin(void* _bytes, uint32 size, bool withPrefix){
|
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase)
|
||||||
|
_toString_float_impl(48, toString_float32_max_precision)
|
||||||
|
|
||||||
|
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase)
|
||||||
|
_toString_float_impl(512, toString_float64_max_precision)
|
||||||
|
|
||||||
|
#define byte_to_bits(byte) {\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>7)&1); /* 8th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>6)&1); /* 7th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>5)&1); /* 6th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>4)&1); /* 5th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>3)&1); /* 4th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>2)&1); /* 3th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>1)&1); /* 2th bit */\
|
||||||
|
str[cn++]='0' + (uint8)((byte>>0)&1); /* 1th bit */\
|
||||||
|
}
|
||||||
|
|
||||||
|
char* toString_bin(void* _bytes, uint32 size, bool inverse, bool withPrefix){
|
||||||
char* bytes=_bytes;
|
char* bytes=_bytes;
|
||||||
char* str=malloc(size*8 + (withPrefix?2:0) +1);
|
char* str=malloc(size*8 + (withPrefix?2:0) +1);
|
||||||
uint32 cn=0;
|
uint32 cn=0; // char number
|
||||||
if(withPrefix){
|
if(withPrefix){
|
||||||
str[cn++]='0';
|
str[cn++]='0';
|
||||||
str[cn++]='b';
|
str[cn++]='b';
|
||||||
}
|
}
|
||||||
for(uint32 bn=0; bn<size; bn++){
|
if(inverse){
|
||||||
unsigned char byte=bytes[bn];
|
// byte number
|
||||||
for(uint8 i=0; i<8; i++)
|
for(int32 bn=size-1; bn>=0; bn--)
|
||||||
str[cn++]='0' + (byte & (char)128>>i);
|
byte_to_bits(bytes[bn])
|
||||||
|
} else {
|
||||||
|
for(int32 bn=0; bn<size; bn++)
|
||||||
|
byte_to_bits(bytes[bn])
|
||||||
}
|
}
|
||||||
str[cn]=0;
|
str[cn]=0;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// converts number from 0 to F to char
|
||||||
char _4bitsHex(uint8 u, bool uppercase){
|
char _4bitsHex(uint8 u, bool uppercase){
|
||||||
switch(u){
|
switch(u){
|
||||||
case 0: case 1: case 2: case 3: case 4:
|
case 0: case 1: case 2: case 3: case 4:
|
||||||
@ -112,18 +130,30 @@ char _4bitsHex(uint8 u, bool uppercase){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* toString_hex(void* _bytes, uint32 size, bool withPrefix, bool uppercase){
|
char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase){
|
||||||
char* bytes=_bytes;
|
char* bytes=_bytes;
|
||||||
char* str=malloc(size*2 + (withPrefix?2:0) + 1);
|
char* str=malloc(size*2 + (withPrefix?2:0) + 1);
|
||||||
uint32 cn=0;
|
uint32 cn=0; // char number
|
||||||
if(withPrefix){
|
if(withPrefix){
|
||||||
str[cn++]='0';
|
str[cn++]='0';
|
||||||
str[cn++]='x';
|
str[cn++]='x';
|
||||||
}
|
}
|
||||||
for(uint32 bn=0; bn<size; bn++){
|
// left to right
|
||||||
unsigned char byte=bytes[bn];
|
if(inverse){
|
||||||
str[cn++]=_4bitsHex(byte%16, uppercase);
|
// byte number
|
||||||
str[cn++]=_4bitsHex(byte/16, uppercase);
|
for(int32 bn=size-1; bn>=0; bn--){
|
||||||
|
unsigned char byte=bytes[bn];
|
||||||
|
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||||
|
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// right to left
|
||||||
|
else {
|
||||||
|
for(int32 bn=0; bn<size; bn++){ // byte number
|
||||||
|
unsigned char byte=bytes[bn];
|
||||||
|
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||||
|
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
str[cn]=0;
|
str[cn]=0;
|
||||||
return str;
|
return str;
|
||||||
@ -131,16 +161,16 @@ char* toString_hex(void* _bytes, uint32 size, bool withPrefix, bool uppercase){
|
|||||||
|
|
||||||
|
|
||||||
#define __toString_int_def(BITS) char* __toString_int##BITS(void* _n, uint32 f){\
|
#define __toString_int_def(BITS) char* __toString_int##BITS(void* _n, uint32 f){\
|
||||||
switch(kprint_format_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kprint_fmtInt: ;\
|
case kp_i: ;\
|
||||||
int##BITS n=*(int##BITS*)_n;\
|
int##BITS n=*(int##BITS*)_n;\
|
||||||
return toString_int(n);\
|
return toString_int(n);\
|
||||||
case kprint_fmtBin:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kprint_fmtHex:\
|
case kp_h:\
|
||||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||||
default:\
|
default:\
|
||||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||||
throw(ERR_FORMAT);\
|
throw(ERR_FORMAT);\
|
||||||
return NULL;\
|
return NULL;\
|
||||||
}\
|
}\
|
||||||
@ -151,16 +181,16 @@ __toString_int_def(32)
|
|||||||
__toString_int_def(64)
|
__toString_int_def(64)
|
||||||
|
|
||||||
#define __toString_uint_def(BITS) char* __toString_uint##BITS(void* _n, uint32 f){\
|
#define __toString_uint_def(BITS) char* __toString_uint##BITS(void* _n, uint32 f){\
|
||||||
switch(kprint_format_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kprint_fmtUInt: ;\
|
case kp_u: ;\
|
||||||
uint##BITS n=*(uint##BITS*)_n;\
|
uint##BITS n=*(uint##BITS*)_n;\
|
||||||
return toString_uint(n, kprint_format_withPostfix(f), kprint_format_uppercase(f));\
|
return toString_uint(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||||
case kprint_fmtBin:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kprint_fmtHex:\
|
case kp_h:\
|
||||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||||
default:\
|
default:\
|
||||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||||
throw(ERR_FORMAT);\
|
throw(ERR_FORMAT);\
|
||||||
return NULL;\
|
return NULL;\
|
||||||
}\
|
}\
|
||||||
@ -171,16 +201,16 @@ __toString_uint_def(32)
|
|||||||
__toString_uint_def(64)
|
__toString_uint_def(64)
|
||||||
|
|
||||||
#define __toString_float_def(BITS) char* __toString_float##BITS(void* _n, uint32 f){\
|
#define __toString_float_def(BITS) char* __toString_float##BITS(void* _n, uint32 f){\
|
||||||
switch(kprint_format_dataFormat(f)){\
|
switch(kp_fmt_dataFormat(f)){\
|
||||||
case kprint_fmtFloat: ;\
|
case kp_f: ;\
|
||||||
float##BITS n=*(float##BITS*)_n;\
|
float##BITS n=*(float##BITS*)_n;\
|
||||||
return toString_float(n, kprint_format_withPostfix(f), kprint_format_uppercase(f));\
|
return toString_float64(n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||||
case kprint_fmtBin:\
|
case kp_b:\
|
||||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||||
case kprint_fmtHex:\
|
case kp_h:\
|
||||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||||
default:\
|
default:\
|
||||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||||
throw(ERR_FORMAT);\
|
throw(ERR_FORMAT);\
|
||||||
return NULL;\
|
return NULL;\
|
||||||
}\
|
}\
|
||||||
|
|||||||
@ -6,30 +6,41 @@ extern "C" {
|
|||||||
|
|
||||||
#include "../errors.h"
|
#include "../errors.h"
|
||||||
|
|
||||||
// functions for base types
|
// char and cstring
|
||||||
// has different output for fmtChar and fmtString
|
// has different output for fmtChar and fmtString
|
||||||
char* __toString_char(void* c, uint32 fmt);
|
char* __toString_char(void* c, uint32 fmt);
|
||||||
|
|
||||||
|
// bool
|
||||||
char* __toString_bool(void* c, uint32 fmt);
|
char* __toString_bool(void* c, uint32 fmt);
|
||||||
|
|
||||||
|
// signed int
|
||||||
char* toString_int(int64 n);
|
char* toString_int(int64 n);
|
||||||
char* __toString_int8(void* n, uint32 fmt);
|
char* __toString_int8(void* n, uint32 fmt);
|
||||||
char* __toString_int16(void* n, uint32 fmt);
|
char* __toString_int16(void* n, uint32 fmt);
|
||||||
char* __toString_int32(void* n, uint32 fmt);
|
char* __toString_int32(void* n, uint32 fmt);
|
||||||
char* __toString_int64(void* n, uint32 fmt);
|
char* __toString_int64(void* n, uint32 fmt);
|
||||||
|
|
||||||
|
// unsigned int
|
||||||
char* toString_uint(uint64 n, bool withPostfix, bool uppercase);
|
char* toString_uint(uint64 n, bool withPostfix, bool uppercase);
|
||||||
char* __toString_uint8(void* n, uint32 fmt);
|
char* __toString_uint8(void* n, uint32 fmt);
|
||||||
char* __toString_uint16(void* n, uint32 fmt);
|
char* __toString_uint16(void* n, uint32 fmt);
|
||||||
char* __toString_uint32(void* n, uint32 fmt);
|
char* __toString_uint32(void* n, uint32 fmt);
|
||||||
char* __toString_uint64(void* n, uint32 fmt);
|
char* __toString_uint64(void* n, uint32 fmt);
|
||||||
|
|
||||||
char* toString_float(float64 n, bool withPostfix, bool uppercase); // very bad implimentation
|
// float
|
||||||
|
#define toString_float32_max_precision 6
|
||||||
|
#define toString_float64_max_precision 15
|
||||||
|
#define toString_float_default_precision 6
|
||||||
|
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||||
|
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||||
char* __toString_float32(void* n, uint32 fmt);
|
char* __toString_float32(void* n, uint32 fmt);
|
||||||
char* __toString_float64(void* n, uint32 fmt);
|
char* __toString_float64(void* n, uint32 fmt);
|
||||||
|
|
||||||
// universal functions
|
|
||||||
char* toString_bin(void* bytes, uint32 size, bool withPrefix);
|
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||||
char* toString_hex(void* bytes, uint32 size, bool withPrefix, bool uppercase);
|
char* toString_bin(void* bytes, uint32 size, bool inverse, bool withPrefix);
|
||||||
|
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||||
|
char* toString_hex(void* bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,7 +81,7 @@ void ktDescriptors_initKerepTypes(){
|
|||||||
|
|
||||||
// string
|
// string
|
||||||
kt_register(string, NULL, NULL);
|
kt_register(string, NULL, NULL);
|
||||||
kt_register(string, ____Autoarr_free_string, NULL);
|
kt_register(Autoarr_string, ____Autoarr_free_string, NULL);
|
||||||
// StringBuilder
|
// StringBuilder
|
||||||
kt_register(StringBuilder, __StringBuilder_free, NULL);
|
kt_register(StringBuilder, __StringBuilder_free, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +1,50 @@
|
|||||||
# kprintf
|
# kprintf
|
||||||
It is just my variant of printf.
|
It is just my cross-plaform variant of printf.
|
||||||
|
Unlike in standard printf, `%l...` and `%ll...` placeholders dont depend on size of `long int` and `long long int`. And you can change terminal colors by unix codes (`\e[92m`) even on Windows.
|
||||||
|
|
||||||
|
| type | placeholder |
|
||||||
|
|-------------------------|-------------------------|
|
||||||
|
| int8 / int16 / int32 | %i / %d |
|
||||||
|
| int64 | %li / %ld / %lld / %lli |
|
||||||
|
| uint8 / uint16 / uint32 | %u |
|
||||||
|
| uint64 | %lu / %llu |
|
||||||
|
| float32 / float64 | %f |
|
||||||
|
| char | %c |
|
||||||
|
| char[] | %s |
|
||||||
|
| void\* | %p / %x |
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
# kprint
|
# kprint
|
||||||
I don't really like printf function (and its variants), so i made safer and more convinient replacement.
|
I don't really like printf function (and its variants), so i made safer and more convinient replacement.
|
||||||
|
|
||||||
| function | returns | arguments |
|
| function | returns | arguments |
|
||||||
|----------|---------|-----------|
|
|----------|---------|-----------|
|
||||||
| kprint | void/throw | kprint_format, void*, kprint_format, void*... |
|
| kprint | void/throw | kp_fmt, void\*, kp_fmt, void\*... |
|
||||||
| ksprint | Maybe<char*> | kprint_format, void*, kprint_format, void*... |
|
| ksprint | Maybe<char\*>| kp_fmt, void\*, kp_fmt, void\*... |
|
||||||
| kfprint | Maybe<void> | FILE*, kprint_format, void*, kprint_format, void*... |
|
| kfprint | Maybe<void> | FILE\*, kp_fmt, void\*, kp_fmt, void\*... |
|
||||||
|
|
||||||
## how to use it:
|
## how to use it:
|
||||||
+ **format construction:**
|
+ **format construction:**
|
||||||
```
|
```
|
||||||
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktid;
|
kp_fmt fmt= kp_fgColor | kp_bgColor | kprint_fdataFmt | flags | ktid;
|
||||||
```
|
```
|
||||||
[more about `kprint_format`](kprint_format.md)
|
[more about `kp_fmt`](kp_fmt.md)
|
||||||
+ fgColor and bgColor can be set to change console output color
|
+ fgColor and bgColor can be set to change console output color
|
||||||
+ you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and ktid for other types
|
+ you should set dataFormat for `int`/`uint`/`float`/`char\*` arguments and ktid for other types
|
||||||
+ flags can be set to modify TypeDescriptor.toString() behavior
|
+ flags can be set to modify TypeDescriptor.toString() behavior
|
||||||
+ don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
|
+ don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
|
||||||
|
|
||||||
+ **using base type arguments:**
|
+ **using base type arguments:**
|
||||||
you can just put them into a function
|
you can just put them into a function
|
||||||
```
|
```
|
||||||
kprint(kprint_fmtHex | kprint_fmtUppercase | kprint_fmtWithPrefix, 255);
|
kprint(kp_h|kp_upper|kp_prefix, 255);
|
||||||
```
|
```
|
||||||
output: 0xFF
|
output: 0xFF
|
||||||
+ **using other registered types:**
|
+ **using other registered types:**
|
||||||
should be sent as pointers
|
should be sent as pointers
|
||||||
```
|
```
|
||||||
Maybe m=MaybeNull;
|
Maybe m=MaybeNull;
|
||||||
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktid_MaybePtr, &m);
|
kprint(kp_fgBlue|kp_s, "Maybe: ", kp_fgGreen|ktid_MaybePtr, &m);
|
||||||
```
|
```
|
||||||
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktid_Null}}</span>
|
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktid_Null}}</span>
|
||||||
@ -1,29 +1,29 @@
|
|||||||
#include "../String/StringBuilder.h"
|
#include "../String/StringBuilder.h"
|
||||||
#include "kprint.h"
|
#include "kprint.h"
|
||||||
|
|
||||||
ktid __typeFromFormat(kprint_format f){
|
ktid __typeFromFormat(kp_fmt f){
|
||||||
ktid typeId=kprint_format_ktid(f);
|
ktid typeId=kp_fmt_ktid(f);
|
||||||
if(typeId)
|
if(typeId)
|
||||||
return typeId;
|
return typeId;
|
||||||
switch(kprint_format_dataFormat(f)){
|
switch(kp_fmt_dataFormat(f)){
|
||||||
case kprint_fmtInt:
|
case kp_i:
|
||||||
case kprint_fmtHex:
|
case kp_h:
|
||||||
case kprint_fmtBin:
|
case kp_b:
|
||||||
return ktid_name(int64);
|
return ktid_name(int64);
|
||||||
case kprint_fmtUInt:
|
case kp_u:
|
||||||
return ktid_name(uint64);
|
return ktid_name(uint64);
|
||||||
case kprint_fmtFloat:
|
case kp_f:
|
||||||
return ktid_name(float64);
|
return ktid_name(float64);
|
||||||
case kprint_fmtChar:
|
case kp_c:
|
||||||
return ktid_char;
|
return ktid_char;
|
||||||
case kprint_fmtString:
|
case kp_s:
|
||||||
return ktid_ptrName(char);
|
return ktid_ptrName(char);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
Maybe __next_toString(kp_fmt f, __kp_value_union* object){
|
||||||
// detecting type
|
// detecting type
|
||||||
ktid typeId=__typeFromFormat(f);
|
ktid typeId=__typeFromFormat(f);
|
||||||
if(typeId==-1)
|
if(typeId==-1)
|
||||||
@ -34,7 +34,14 @@ Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
|||||||
return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f)));
|
return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
Maybe check_argsN(uint8 n){
|
||||||
|
if(n%2 != 0) safethrow("kprint recieved non-even number of arguments",;);
|
||||||
|
if(n > 32) safethrow("kprint recieved >32 number of arguments",;);
|
||||||
|
return MaybeNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||||
|
try(check_argsN(n), _,;);
|
||||||
n/=2;
|
n/=2;
|
||||||
StringBuilder* strb=StringBuilder_create();
|
StringBuilder* strb=StringBuilder_create();
|
||||||
for(uint8 i=0; i<n; i++){
|
for(uint8 i=0; i<n; i++){
|
||||||
@ -46,7 +53,8 @@ Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
|||||||
return SUCCESS(UniHeapPtr(char, rezult));
|
return SUCCESS(UniHeapPtr(char, rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
Maybe __kfprint(FILE* file, uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||||
|
try(check_argsN(n), _,;);
|
||||||
n/=2;
|
n/=2;
|
||||||
for(uint8 i=0; i<n; i++){
|
for(uint8 i=0; i<n; i++){
|
||||||
try(__next_toString(formats[i], &objects[i]),maybeStr,;);
|
try(__next_toString(formats[i], &objects[i]),maybeStr,;);
|
||||||
@ -58,10 +66,11 @@ Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_unio
|
|||||||
return MaybeNull;
|
return MaybeNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||||
|
tryLast(check_argsN(n), _);
|
||||||
n/=2;
|
n/=2;
|
||||||
for(uint8 i=0; i<n; i++){
|
for(uint8 i=0; i<n; i++){
|
||||||
kprint_format fmt=formats[i];
|
kp_fmt fmt=formats[i];
|
||||||
kprint_setColor(fmt);
|
kprint_setColor(fmt);
|
||||||
tryLast(__next_toString(fmt, &objects[i]),maybeStr);
|
tryLast(__next_toString(fmt, &objects[i]),maybeStr);
|
||||||
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF)\
|
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF)\
|
||||||
@ -76,72 +85,72 @@ void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED
|
#define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED
|
||||||
|
|
||||||
DWORD kprint_fgColor_toWin(kprint_fgColor f){
|
DWORD kp_fgColor_toWin(kp_fgColor f){
|
||||||
//kprintf("fg: %x\n", f);
|
//kprintf("fg: %x\n", f);
|
||||||
switch(f){
|
switch(f){
|
||||||
case kprint_fgBlack: return 0;
|
case kp_fgBlack: return 0;
|
||||||
case kprint_fgDarkRed: return FOREGROUND_RED;
|
case kp_fgRedD: return FOREGROUND_RED;
|
||||||
case kprint_fgDarkGreen: return FOREGROUND_GREEN;
|
case kp_fgGreenD: return FOREGROUND_GREEN;
|
||||||
case kprint_fgDarkYellow: return FOREGROUND_GREEN | FOREGROUND_RED;
|
case kp_fgYellowD: return FOREGROUND_GREEN | FOREGROUND_RED;
|
||||||
case kprint_fgDarkBlue: return FOREGROUND_BLUE;
|
case kp_fgBlueD: return FOREGROUND_BLUE;
|
||||||
case kprint_fgDarkMagenta: return FOREGROUND_RED | FOREGROUND_BLUE;
|
case kp_fgMagentaD: return FOREGROUND_RED | FOREGROUND_BLUE;
|
||||||
case kprint_fgDarkCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN;
|
case kp_fgCyanD: return FOREGROUND_BLUE | FOREGROUND_GREEN;
|
||||||
case kprint_fgGray: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
case kp_fgGray: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
||||||
case kprint_fgDarkGray: return FOREGROUND_INTENSITY;
|
case kp_fgGrayD: return FOREGROUND_INTENSITY;
|
||||||
case kprint_fgRed: return FOREGROUND_RED | FOREGROUND_INTENSITY;
|
case kp_fgRed: return FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgGreen: return FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
case kp_fgGreen: return FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgYellow: return FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
case kp_fgYellow: return FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgBlue: return FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
case kp_fgBlue: return FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgMagenta: return FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
case kp_fgMagenta: return FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
case kp_fgCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||||
case kprint_fgWhite: return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
case kp_fgWhite: return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||||
default: throw(ERR_FORMAT);
|
default: throw(ERR_FORMAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD kprint_bgColor_toWin(kprint_bgColor f){
|
DWORD kp_bgColor_toWin(kp_bgColor f){
|
||||||
//kprintf("bg: %x\n", f);
|
//kprintf("bg: %x\n", f);
|
||||||
switch(f){
|
switch(f){
|
||||||
case kprint_bgBlack: return 0;
|
case kp_bgBlack: return 0;
|
||||||
case kprint_bgDarkRed: return BACKGROUND_RED;
|
case kp_bgRedD: return BACKGROUND_RED;
|
||||||
case kprint_bgDarkGreen: return BACKGROUND_GREEN;
|
case kp_bgGreenD: return BACKGROUND_GREEN;
|
||||||
case kprint_bgDarkYellow: return BACKGROUND_GREEN | BACKGROUND_RED;
|
case kp_bgYellowD: return BACKGROUND_GREEN | BACKGROUND_RED;
|
||||||
case kprint_bgDarkBlue: return BACKGROUND_BLUE;
|
case kp_bgBlueD: return BACKGROUND_BLUE;
|
||||||
case kprint_bgDarkMagenta: return BACKGROUND_RED | BACKGROUND_BLUE;
|
case kp_bgMagentaD: return BACKGROUND_RED | BACKGROUND_BLUE;
|
||||||
case kprint_bgDarkCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN;
|
case kp_bgCyanD: return BACKGROUND_BLUE | BACKGROUND_GREEN;
|
||||||
case kprint_bgGray: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
|
case kp_bgGray: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
|
||||||
case kprint_bgDarkGray: return BACKGROUND_INTENSITY;
|
case kp_bgGrayD: return BACKGROUND_INTENSITY;
|
||||||
case kprint_bgRed: return BACKGROUND_RED | BACKGROUND_INTENSITY;
|
case kp_bgRed: return BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgGreen: return BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
case kp_bgGreen: return BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgYellow: return BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
case kp_bgYellow: return BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgBlue: return BACKGROUND_BLUE | BACKGROUND_INTENSITY;
|
case kp_bgBlue: return BACKGROUND_BLUE | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgMagenta: return BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
case kp_bgMagenta: return BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
case kp_bgCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||||
case kprint_bgWhite: return BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
case kp_bgWhite: return BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||||
default: throw(ERR_FORMAT);
|
default: throw(ERR_FORMAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kprint_setColor(kprint_format f){
|
void kprint_setColor(kp_fmt f){
|
||||||
DWORD color=0;
|
DWORD color=0;
|
||||||
if(!kprint_format_fgColorChanged(f) & !kprint_format_bgColorChanged(f))
|
if(!kp_fmt_fgColorSet(f) & !kp_fmt_bgColorSet(f))
|
||||||
return;
|
return;
|
||||||
if(kprint_format_fgColorChanged(f))
|
if(kp_fmt_fgColorSet(f))
|
||||||
color+=kprint_fgColor_toWin(kprint_format_fgColor(f));
|
color+=kp_fgColor_toWin(kp_fmt_fgColor(f));
|
||||||
if(kprint_format_bgColorChanged(f))
|
if(kp_fmt_bgColorSet(f))
|
||||||
color+=kprint_bgColor_toWin(kprint_format_bgColor(f));
|
color+=kp_bgColor_toWin(kp_fmt_bgColor(f));
|
||||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
SetConsoleTextAttribute(hConsole, color);
|
SetConsoleTextAttribute(hConsole, color);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void kprint_setColor(kprint_format f){
|
void kprint_setColor(kp_fmt f){
|
||||||
if(kprint_format_fgColorChanged(f)){
|
if(kp_fmt_fgColorSet(f)){
|
||||||
uint8 fg=(f&0x0f000000)>>24;
|
uint8 fg=(f&0x0f000000)>>24;
|
||||||
if(fg<8) fg+=30;
|
if(fg<8) fg+=30;
|
||||||
else fg+=90-8;
|
else fg+=90-8;
|
||||||
printf("\e[%um", fg);
|
printf("\e[%um", fg);
|
||||||
}
|
}
|
||||||
if(kprint_format_bgColorChanged(f)){
|
if(kp_fmt_bgColorSet(f)){
|
||||||
uint8 bg=(f&0x00f00000)>>20;
|
uint8 bg=(f&0x00f00000)>>20;
|
||||||
if(bg<8) bg+=40;
|
if(bg<8) bg+=40;
|
||||||
else bg+=100-8;
|
else bg+=100-8;
|
||||||
@ -150,7 +159,7 @@ void kprint_setColor(kprint_format f){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maybe ksprint_ar(uint32 count, kprint_format format, ktid typeId, void* array){
|
/* Maybe ksprint_ar(uint32 count, kp_fmt format, ktid typeId, void* array){
|
||||||
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
|
|||||||
@ -8,65 +8,98 @@ extern "C" {
|
|||||||
#include "kprint_colors.h"
|
#include "kprint_colors.h"
|
||||||
#include "kprint_format.h"
|
#include "kprint_format.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
This file looks like a mess, but all cotnent here just solves the problem of putting variadic arguments to array of formats and array of objects.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
int64 i64;
|
int64 i64;
|
||||||
uint64 u64;
|
uint64 u64;
|
||||||
float64 f64;
|
float64 f64;
|
||||||
void* ptr;
|
void* ptr;
|
||||||
} __kprint_value_union;
|
} __kp_value_union;
|
||||||
#define __kprintVU(value) (__kprint_value_union){ value }
|
|
||||||
|
|
||||||
#define __kprint_argsToFormats8(\
|
|
||||||
|
static inline __kp_value_union __kpVU_f(float64 f) { return (__kp_value_union){ .f64=f }; }
|
||||||
|
inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i64=f }; }
|
||||||
|
|
||||||
|
#define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, double: __kpVU_f, default: __kpVU_i)(V)
|
||||||
|
|
||||||
|
#define __kpVU(V) __kpVU_selectType(V)
|
||||||
|
|
||||||
|
#define __kp_argsToFmts8(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||||
((int32[]){ a0,a2,a4,a6 })
|
((int32[]){ a0,a2,a4,a6 })
|
||||||
#define __kprint_argsToObjects8(\
|
#define __kp_argsToObjs8(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7) })
|
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7) })
|
||||||
|
|
||||||
#define __kprint_argsToFormats16(\
|
#define __kp_argsToFmts16(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14 })
|
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14 })
|
||||||
#define __kprint_argsToObjects16(\
|
#define __kp_argsToObjs16(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7),__kprintVU(a9),__kprintVU(a11),__kprintVU(a13),__kprintVU(a15) })
|
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7),__kpVU(a9),__kpVU(a11),__kpVU(a13),__kpVU(a15) })
|
||||||
|
|
||||||
#define __kprint_argsToFormats32(\
|
#define __kp_argsToFmts32(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||||
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
||||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 })
|
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 })
|
||||||
#define __kprint_argsToObjects32(\
|
#define __kp_argsToObjs32(\
|
||||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||||
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
||||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7),__kprintVU(a9),__kprintVU(a11),__kprintVU(a13),__kprintVU(a15),__kprintVU(a17),__kprintVU(a19),__kprintVU(a21),__kprintVU(a23),__kprintVU(a25),__kprintVU(a27),__kprintVU(a29),__kprintVU(a31) })
|
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7),__kpVU(a9),__kpVU(a11),__kpVU(a13),__kpVU(a15),__kpVU(a17),__kpVU(a19),__kpVU(a21),__kpVU(a23),__kpVU(a25),__kpVU(a27),__kpVU(a29),__kpVU(a31) })
|
||||||
|
|
||||||
#define __32zeroes 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
#define __32zeroes 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||||
|
|
||||||
#define __kprint_argsToArrs(COUNT,ARGS...)\
|
#define __kp_argsToArrs(COUNT,ARGS...)\
|
||||||
(kprint_format*)(COUNT<=8 ? __kprint_argsToFormats8(ARGS) :\
|
(kp_fmt*)(\
|
||||||
COUNT<=16 ? __kprint_argsToFormats16(ARGS) :\
|
COUNT<=8 ? __kp_argsToFmts8(ARGS) :\
|
||||||
__kprint_argsToFormats32(ARGS)),\
|
COUNT<=16 ? __kp_argsToFmts16(ARGS) :\
|
||||||
(__kprint_value_union*)(COUNT<=8 ? __kprint_argsToObjects8(ARGS) :\
|
__kp_argsToFmts32(ARGS)),\
|
||||||
COUNT<=16 ? __kprint_argsToObjects16(ARGS) :\
|
(__kp_value_union*)(\
|
||||||
__kprint_argsToObjects32(ARGS))
|
COUNT<=8 ? __kp_argsToObjs8(ARGS) :\
|
||||||
|
COUNT<=16 ? __kp_argsToObjs16(ARGS) :\
|
||||||
|
__kp_argsToObjs32(ARGS))
|
||||||
|
|
||||||
|
|
||||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||||
#define ksprint(ARGS...) __ksprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
|
||||||
|
|
||||||
Maybe __kfprint(FILE* fd, uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
||||||
#define kfprint(FD, ARGS...) __kfprint(FD, count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
///@returns Maybe<char*>
|
||||||
|
#define ksprint(ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||||
|
__ksprint(count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||||
|
)
|
||||||
|
/*-Wint-conversion warning was produced during value to __kp_value_union conversion*/
|
||||||
|
|
||||||
void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
Maybe __kfprint(FILE* fd, uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||||
#define kprint(ARGS...) __kprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
|
||||||
|
|
||||||
// can take (bgColor | fgColor)
|
/// @param FD FILE*
|
||||||
void kprint_setColor(kprint_format f);
|
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
||||||
|
///@returns Maybe<void>
|
||||||
|
#define kfprint(FD, ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||||
|
__kfprint(FD, count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||||
|
)
|
||||||
|
|
||||||
|
void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||||
|
|
||||||
|
///can use non-catchable throw !!!
|
||||||
|
///@param ARGS kp_fmt, value, kp_fmt, value...
|
||||||
|
///@returns void
|
||||||
|
#define kprint(ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||||
|
__kprint(count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||||
|
)
|
||||||
|
|
||||||
|
///@param f bgColor | fgColor
|
||||||
|
void kprint_setColor(kp_fmt f);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,51 +4,82 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum kprint_fgColor{
|
// 10000000 00000000 00000000 00000000
|
||||||
// 10000000 00000000 00000000 00000000
|
// ^ ^^^^
|
||||||
// ^ ^^^^
|
// | color num
|
||||||
// | color num
|
// fgColorSet flag
|
||||||
// fgColorChanged flag
|
PACK_ENUM(kp_fgColor,
|
||||||
|
/// black foreground
|
||||||
|
kp_fgBlack = 0x80000000,
|
||||||
|
/// dark red foreground
|
||||||
|
kp_fgRedD = 0x81000000,
|
||||||
|
/// dark green foreground
|
||||||
|
kp_fgGreenD = 0x82000000,
|
||||||
|
/// dark yellow foreground
|
||||||
|
kp_fgYellowD = 0x83000000,
|
||||||
|
/// dark blue foreground
|
||||||
|
kp_fgBlueD = 0x84000000,
|
||||||
|
/// dark magenta foreground
|
||||||
|
kp_fgMagentaD= 0x85000000,
|
||||||
|
/// dark cyan foreground
|
||||||
|
kp_fgCyanD = 0x86000000,
|
||||||
|
/// gray foreground
|
||||||
|
kp_fgGray = 0x87000000,
|
||||||
|
/// dark gray foreground
|
||||||
|
kp_fgGrayD = 0x88000000,
|
||||||
|
/// red foreground
|
||||||
|
kp_fgRed = 0x89000000,
|
||||||
|
/// green foreground
|
||||||
|
kp_fgGreen = 0x8a000000,
|
||||||
|
/// yellow foreground
|
||||||
|
kp_fgYellow = 0x8b000000,
|
||||||
|
/// blue foreground
|
||||||
|
kp_fgBlue = 0x8c000000,
|
||||||
|
/// magenta foreground
|
||||||
|
kp_fgMagenta = 0x8d000000,
|
||||||
|
/// cyan foreground
|
||||||
|
kp_fgCyan = 0x8e000000,
|
||||||
|
/// white foreground
|
||||||
|
kp_fgWhite = 0x8f000000
|
||||||
|
)
|
||||||
|
|
||||||
kprint_fgBlack = 0x80000000,
|
// 01000000 00000000 00000000 00000000
|
||||||
kprint_fgDarkRed = 0x81000000,
|
// ^ ^^^^
|
||||||
kprint_fgDarkGreen = 0x82000000,
|
// bgColorSet flag color num
|
||||||
kprint_fgDarkYellow = 0x83000000,
|
PACK_ENUM(kp_bgColor,
|
||||||
kprint_fgDarkBlue = 0x84000000,
|
/// black background
|
||||||
kprint_fgDarkMagenta= 0x85000000,
|
kp_bgBlack = 0x40000000,
|
||||||
kprint_fgDarkCyan = 0x86000000,
|
/// dark red background
|
||||||
kprint_fgGray = 0x87000000,
|
kp_bgRedD = 0x40100000,
|
||||||
kprint_fgDarkGray = 0x88000000,
|
/// dark green background
|
||||||
kprint_fgRed = 0x89000000,
|
kp_bgGreenD = 0x40200000,
|
||||||
kprint_fgGreen = 0x8a000000,
|
/// dark yellow background
|
||||||
kprint_fgYellow = 0x8b000000,
|
kp_bgYellowD = 0x40300000,
|
||||||
kprint_fgBlue = 0x8c000000,
|
/// dark blue background
|
||||||
kprint_fgMagenta = 0x8d000000,
|
kp_bgBlueD = 0x40400000,
|
||||||
kprint_fgCyan = 0x8e000000,
|
/// dark magenta background
|
||||||
kprint_fgWhite = 0x8f000000
|
kp_bgMagentaD= 0x40500000,
|
||||||
} kprint_fgColor;
|
/// dark cyan background
|
||||||
|
kp_bgCyanD = 0x40600000,
|
||||||
typedef enum kprint_bgColor{
|
/// gray background
|
||||||
// 01000000 00000000 00000000 00000000
|
kp_bgGray = 0x40700000,
|
||||||
// ^ ^^^^
|
/// dark gray background
|
||||||
// bgColorChanged flag color num
|
kp_bgGrayD = 0x40800000,
|
||||||
kprint_bgBlack = 0x40000000,
|
/// red background
|
||||||
kprint_bgDarkRed = 0x40100000,
|
kp_bgRed = 0x40900000,
|
||||||
kprint_bgDarkGreen = 0x40200000,
|
/// green background
|
||||||
kprint_bgDarkYellow = 0x40300000,
|
kp_bgGreen = 0x40a00000,
|
||||||
kprint_bgDarkBlue = 0x40400000,
|
/// yellow background
|
||||||
kprint_bgDarkMagenta= 0x40500000,
|
kp_bgYellow = 0x40b00000,
|
||||||
kprint_bgDarkCyan = 0x40600000,
|
/// blue background
|
||||||
kprint_bgGray = 0x40700000,
|
kp_bgBlue = 0x40c00000,
|
||||||
kprint_bgDarkGray = 0x40800000,
|
/// magenta background
|
||||||
kprint_bgRed = 0x40900000,
|
kp_bgMagenta = 0x40d00000,
|
||||||
kprint_bgGreen = 0x40a00000,
|
/// cyan background
|
||||||
kprint_bgYellow = 0x40b00000,
|
kp_bgCyan = 0x40e00000,
|
||||||
kprint_bgBlue = 0x40c00000,
|
/// white background
|
||||||
kprint_bgMagenta = 0x40d00000,
|
kp_bgWhite = 0x40f00000
|
||||||
kprint_bgCyan = 0x40e00000,
|
)
|
||||||
kprint_bgWhite = 0x40f00000
|
|
||||||
} kprint_bgColor;
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,41 +7,42 @@ extern "C" {
|
|||||||
#include "../base/std.h"
|
#include "../base/std.h"
|
||||||
#include "../base/type_system/ktid.h"
|
#include "../base/type_system/ktid.h"
|
||||||
|
|
||||||
typedef enum kprint_dataFormat{
|
/// kprint_format
|
||||||
// 00000000 00000000 00000000 00000000
|
typedef uint32 kp_fmt;
|
||||||
// ^^^^
|
|
||||||
// type
|
|
||||||
kprint_fmtInt = 0x00000000,
|
|
||||||
kprint_fmtUInt = 0x00010000,
|
|
||||||
kprint_fmtHex = 0x00020000,
|
|
||||||
kprint_fmtBin = 0x00030000,
|
|
||||||
kprint_fmtFloat = 0x00040000,
|
|
||||||
kprint_fmtChar = 0x00050000,
|
|
||||||
kprint_fmtString = 0x00060000,
|
|
||||||
|
|
||||||
// 00100000 00000000 00000000 00000000
|
PACK_ENUM(kp_dataFmt,
|
||||||
// ^
|
// 00000000 00000000 00000000 00000000
|
||||||
// prefix/postfix flag
|
// ^^^^
|
||||||
kprint_fmtWithPrefix=0x20000000,
|
// type
|
||||||
kprint_fmtWithPostfix=kprint_fmtWithPrefix,
|
kp_i = 0x00000000,
|
||||||
|
kp_u = 0x00010000,
|
||||||
|
kp_h = 0x00020000,
|
||||||
|
kp_b = 0x00030000,
|
||||||
|
kp_f = 0x00040000,
|
||||||
|
kp_c = 0x00050000,
|
||||||
|
kp_s = 0x00060000,
|
||||||
|
|
||||||
// 00010000 00000000 00000000 00000000
|
// 00100000 00000000 00000000 00000000
|
||||||
// ^
|
// ^
|
||||||
// uppercase flag
|
// prefix/postfix flag
|
||||||
kprint_fmtUppercase=0x10000000
|
kp_pre=0x20000000,
|
||||||
} kprint_dataFormat;
|
kp_post=kp_pre,
|
||||||
|
|
||||||
typedef uint32 kprint_format;
|
// 00010000 00000000 00000000 00000000
|
||||||
|
// ^
|
||||||
|
// uppercase flag
|
||||||
|
kp_upper=0x10000000
|
||||||
|
)
|
||||||
|
|
||||||
#define kprint_format_fgColorChanged(FMT) (FMT&0x80000000)
|
#define kp_fmt_fgColorSet(FMT) (bool)((FMT&0x80000000)!=0)
|
||||||
#define kprint_format_bgColorChanged(FMT) (FMT&0x40000000)
|
#define kp_fmt_bgColorSet(FMT) (bool)((FMT&0x40000000)!=0)
|
||||||
#define kprint_format_withPrefix(FMT) (FMT&kprint_fmtWithPrefix)
|
#define kp_fmt_withPrefix(FMT) (bool)((FMT&kp_pre)!=0)
|
||||||
#define kprint_format_withPostfix(FMT) (FMT&kprint_fmtWithPostfix)
|
#define kp_fmt_withPostfix(FMT) (bool)((FMT&kp_post)!=0)
|
||||||
#define kprint_format_uppercase(FMT) (FMT&kprint_fmtUppercase)
|
#define kp_fmt_isUpper(FMT) (bool)((FMT&kp_upper)!=0)
|
||||||
#define kprint_format_fgColor(FMT) (kprint_fgColor)(FMT&0x8f000000)
|
#define kp_fmt_fgColor(FMT) (kp_fgColor)(FMT&0x8f000000)
|
||||||
#define kprint_format_bgColor(FMT) (kprint_bgColor)(FMT&0x40f00000)
|
#define kp_fmt_bgColor(FMT) (kp_bgColor)(FMT&0x40f00000)
|
||||||
#define kprint_format_dataFormat(FMT) (kprint_dataFormat)(FMT&0x000f0000)
|
#define kp_fmt_dataFormat(FMT) (kp_dataFmt)(FMT&0x000f0000)
|
||||||
#define kprint_format_ktid(FMT) (kprint_dataFormat)(FMT&0x0000ffff)
|
#define kp_fmt_ktid(FMT) (ktid)(FMT&0x0000ffff)
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
# kerep_format
|
# kerep_format
|
||||||
|
|
||||||
```
|
```
|
||||||
00000000 00000000 00000000 00000000
|
00000000 00000000 00000000 00000000
|
||||||
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktid
|
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktid
|
||||||
bgColorSet─┘││ │ bgColor └data format
|
bgColorSet─┘││ │ bgColor └data format
|
||||||
prefix┬────┘│ └fgColor
|
prefix┬────┘│ └fgColor
|
||||||
postfix └uppercase
|
postfix └uppercase
|
||||||
@ -12,61 +12,61 @@ bgColorSet─┘││ │ bgColor └data format
|
|||||||
## Console colors
|
## Console colors
|
||||||
### *Foreground*
|
### *Foreground*
|
||||||
|
|
||||||
| kprint_fg | hex | bin |
|
| kp_fg | hex | bin |
|
||||||
|-----------|-----|-----|
|
|-------|-----|-----|
|
||||||
| Black | 0x80000000 | 10000000 00000000... |
|
| Black | 0x80000000 | 10000000 00000000... |
|
||||||
| DarkRed | 0x81000000 | 10000001 00000000... |
|
| RedD | 0x81000000 | 10000001 00000000... |
|
||||||
| DarkGreen | 0x82000000 | 10000010 00000000... |
|
| GreenD | 0x82000000 | 10000010 00000000... |
|
||||||
| DarkYellow | 0x83000000 | 10000011 00000000... |
|
| YellowD | 0x83000000 | 10000011 00000000... |
|
||||||
| DarkBlue | 0x84000000 | 10000100 00000000... |
|
| BlueD | 0x84000000 | 10000100 00000000... |
|
||||||
| DarkMagenta | 0x85000000 | 10000101 00000000... |
|
| MagentaD | 0x85000000 | 10000101 00000000... |
|
||||||
| DarkCyan | 0x86000000 | 10000110 00000000... |
|
| CyanD | 0x86000000 | 10000110 00000000... |
|
||||||
| Gray | 0x87000000 | 10000111 00000000... |
|
| Gray | 0x87000000 | 10000111 00000000... |
|
||||||
| DarkGray | 0x88000000 | 10001000 00000000... |
|
| GrayD | 0x88000000 | 10001000 00000000... |
|
||||||
| Red | 0x89000000 | 10001001 00000000... |
|
| Red | 0x89000000 | 10001001 00000000... |
|
||||||
| Green | 0x8a000000 | 10001010 00000000... |
|
| Green | 0x8a000000 | 10001010 00000000... |
|
||||||
| Yellow | 0x8b000000 | 10001011 00000000... |
|
| Yellow | 0x8b000000 | 10001011 00000000... |
|
||||||
| Blue | 0x8c000000 | 10001100 00000000... |
|
| Blue | 0x8c000000 | 10001100 00000000... |
|
||||||
| Magenta | 0x8d000000 | 10001101 00000000... |
|
| Magenta | 0x8d000000 | 10001101 00000000... |
|
||||||
| Cyan | 0x8e000000 | 10001110 00000000... |
|
| Cyan | 0x8e000000 | 10001110 00000000... |
|
||||||
| White | 0x8f000000 | 10001111 00000000... |
|
| White | 0x8f000000 | 10001111 00000000... |
|
||||||
|
|
||||||
### *Background*
|
### *Background*
|
||||||
| kprint_bg | hex | bin |
|
| kp_bg | hex | bin |
|
||||||
|-----------|-----|-----|
|
|-------|-----|-----|
|
||||||
| Black | 0x40000000 | 01000000 00000000... |
|
| Black | 0x40000000 | 01000000 00000000... |
|
||||||
| DarkRed | 0x40100000 | 01000000 00010000... |
|
| RedD | 0x40100000 | 01000000 00010000... |
|
||||||
| DarkGreen | 0x40200000 | 01000000 00100000... |
|
| GreenD | 0x40200000 | 01000000 00100000... |
|
||||||
| DarkYellow | 0x40300000 | 01000000 00110000... |
|
| YellowD | 0x40300000 | 01000000 00110000... |
|
||||||
| DarkBlue | 0x40400000 | 01000000 01000000... |
|
| BlueD | 0x40400000 | 01000000 01000000... |
|
||||||
| DarkMagenta | 0x40500000 | 01000000 01010000... |
|
| MagentaD | 0x40500000 | 01000000 01010000... |
|
||||||
| DarkCyan | 0x40600000 | 01000000 01100000... |
|
| CyanD | 0x40600000 | 01000000 01100000... |
|
||||||
| Gray | 0x40700000 | 01000000 01110000... |
|
| Gray | 0x40700000 | 01000000 01110000... |
|
||||||
| DarkGray | 0x40800000 | 01000000 10000000... |
|
| GrayD | 0x40800000 | 01000000 10000000... |
|
||||||
| Red | 0x40900000 | 01000000 10010000... |
|
| Red | 0x40900000 | 01000000 10010000... |
|
||||||
| Green | 0x40a00000 | 01000000 10100000... |
|
| Green | 0x40a00000 | 01000000 10100000... |
|
||||||
| Yellow | 0x40b00000 | 01000000 10110000... |
|
| Yellow | 0x40b00000 | 01000000 10110000... |
|
||||||
| Blue | 0x40c00000 | 01000000 11000000... |
|
| Blue | 0x40c00000 | 01000000 11000000... |
|
||||||
| Magenta | 0x40d00000 | 01000000 11010000... |
|
| Magenta | 0x40d00000 | 01000000 11010000... |
|
||||||
| Cyan | 0x40e00000 | 01000000 11100000... |
|
| Cyan | 0x40e00000 | 01000000 11100000... |
|
||||||
| White | 0x40f00000 | 01000000 11110000... |
|
| White | 0x40f00000 | 01000000 11110000... |
|
||||||
|
|
||||||
|
|
||||||
## Data format
|
## Data format
|
||||||
|
|
||||||
| kprint_fmt | possible flags | data types | hex value | bin value |
|
| format | possible flags | data types | hex value | bin value |
|
||||||
|------------|----------------|------------|-----------|-----------|
|
|-----------|----------------|------------|-----------|-----------|
|
||||||
| Int | | int8... int64 | 0x00000000 | 00000000 00000000... |
|
| kp_i | | int8... int64 | 0x00000000 | 00000000 00000000... |
|
||||||
| UInt | WithPostfix, Uppercase | uint8... uint64 | 0x00010000 | 00000000 00000001... |
|
| kp_u | Postfix, Upper | uint8... uint64 | 0x00010000 | 00000000 00000001... |
|
||||||
| Hex | WithPrefix, Uppercase | any | 0x00020000 | 00000000 00000010... |
|
| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... |
|
||||||
| Bin | WithPrefix, | any | 0x00030000 | 00000000 00000011... |
|
| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... |
|
||||||
| Float | WithPostfix, Uppercase | float32, float64 | 0x00040000 | 00000000 00000100... |
|
| kp_f | Postfix, Upper | float32, float64 | 0x00040000 | 00000000 00000100... |
|
||||||
| Char | | char | 0x00050000 | 00000000 00000101... |
|
| kp_c | | char | 0x00050000 | 00000000 00000101... |
|
||||||
| String | | char* | 0x00060000 | 00000000 00000110... |
|
| kp_sing | | char* | 0x00060000 | 00000000 00000110... |
|
||||||
|
|
||||||
### *Flags*
|
### *Flags*
|
||||||
| kprint_fmt | hex value | bin value |
|
| flag | hex value | bin value |
|
||||||
|-------------|------------|-----------|
|
|------|------------|-----------|
|
||||||
| withPrefix | 0x20000000 | 00100000 00000000... |
|
| kp_pre | 0x20000000 | 00100000 00000000... |
|
||||||
| withPostfix | 0x20000000 | 00100000 00000000... |
|
| kp_post | 0x20000000 | 00100000 00000000... |
|
||||||
| upperase | 0x10000000 | 00010000 00000000... |
|
| kp_upper | 0x10000000 | 00010000 00000000... |
|
||||||
|
|||||||
@ -53,42 +53,35 @@ void kprintf(const char* format, ...){
|
|||||||
for(char c=format[i++]; c!=0; c=format[i++]){
|
for(char c=format[i++]; c!=0; c=format[i++]){
|
||||||
if(c=='%'){
|
if(c=='%'){
|
||||||
char* argstr=NULL;
|
char* argstr=NULL;
|
||||||
|
bool l=false;
|
||||||
c=format[i++];
|
c=format[i++];
|
||||||
format_escape_seq:
|
format_escape_seq:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'u':
|
case 'u':
|
||||||
argstr=toString_uint(va_arg(vl, uint64),0,0);
|
argstr=toString_uint(
|
||||||
|
l ? va_arg(vl, uint64) : va_arg(vl, uint32)
|
||||||
|
,0,0);
|
||||||
break;
|
break;
|
||||||
case 'i': case 'd':
|
case 'i': case 'd':
|
||||||
argstr=toString_int(va_arg(vl, uint64));
|
argstr=toString_int(
|
||||||
|
l ? va_arg(vl, int64) : va_arg(vl, int32)
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
argstr=toString_float(va_arg(vl, float64),0,0);
|
// float32 is promoted to float64 when passed through '...'
|
||||||
|
argstr=toString_float64(va_arg(vl, float64), toString_float_default_precision,0,0);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
|
l=true;
|
||||||
if((c=format[i++]))
|
if((c=format[i++]))
|
||||||
goto format_escape_seq;
|
goto format_escape_seq;
|
||||||
break;
|
break;
|
||||||
// switch (c) {
|
|
||||||
// case 'u':
|
|
||||||
// argstr=toString_uint(va_arg(vl, uint64),0,0);
|
|
||||||
// break;
|
|
||||||
// case 'i':
|
|
||||||
// argstr=toString_int(va_arg(vl, uint64));
|
|
||||||
// break;
|
|
||||||
// case 'f':
|
|
||||||
// argstr=toString_float(va_arg(vl, float64),0,0);
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// throw(ERR_FORMAT);
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'x':
|
case 'x': ;
|
||||||
uint64 px=va_arg(vl, uint64);
|
uint64 px=va_arg(vl, uint64);
|
||||||
argstr=toString_hex(&px,sizeof(px),1,0);
|
argstr=toString_hex(&px,getEndian()==LittleEndian,sizeof(px),1,0);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's': ;
|
||||||
char* cptr=va_arg(vl,char*);
|
char* cptr=va_arg(vl,char*);
|
||||||
if(!cptr)
|
if(!cptr)
|
||||||
cptr="<nullstr>";
|
cptr="<nullstr>";
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// cross-platform kprintf analog
|
// cross-platform printf analog
|
||||||
void kprintf(const char* format, ...);
|
void kprintf(const char* format, ...);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@ -1,26 +1,12 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
void test_all(){
|
|
||||||
test_string();
|
|
||||||
test_safethrow();
|
|
||||||
test_searchtree();
|
|
||||||
test_autoarr();
|
|
||||||
test_autoarrVsVector();
|
|
||||||
test_hash_functions();
|
|
||||||
test_hashtable();
|
|
||||||
test_dtsod();
|
|
||||||
test_rng_algorithms();
|
|
||||||
test_kprint_colors();
|
|
||||||
kprintf("\e[96m--------------------------------------\e[0m\n");
|
|
||||||
}
|
|
||||||
int main(){
|
int main(){
|
||||||
if(!setlocale(LC_ALL, "C.UTF8"))
|
if(!setlocale(LC_ALL, "C.UTF8"))
|
||||||
kprintf("\e[93msetlocale failed\n");
|
kprintf("\e[93msetlocale failed\n");
|
||||||
ktDescriptors_beginInit();
|
ktDescriptors_beginInit();
|
||||||
ktDescriptors_initKerepTypes();
|
ktDescriptors_initKerepTypes();
|
||||||
ktDescriptors_endInit();
|
ktDescriptors_endInit();
|
||||||
kprintf("\e[97mkerep tests are starting!\n");
|
test_all();
|
||||||
optime("test_all",1,test_all());
|
|
||||||
ktDescriptors_free();
|
ktDescriptors_free();
|
||||||
kprintf("\e[0m\n");
|
kprintf("\e[0m\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -7,34 +7,28 @@ int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
|
|||||||
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
|
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
|
||||||
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
|
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
|
||||||
std::vector<int64> vec=std::vector<int64>();
|
std::vector<int64> vec=std::vector<int64>();
|
||||||
optime("Autoarr_add", 1, ({
|
optime("Autoarr_add", count,
|
||||||
for(uint32 i=0; i< count; i++)
|
Autoarr_add(ar, op_i));
|
||||||
Autoarr_add(ar, i);
|
optime("vector_push_back", count,
|
||||||
}));
|
vec.push_back(op_i));
|
||||||
optime("vector_push_back", 1, ({
|
|
||||||
for(uint32 i=0; i< count; i++)
|
|
||||||
vec.push_back(i);
|
|
||||||
}));
|
|
||||||
int64 t=0;
|
int64 t=0;
|
||||||
optime("Autoarr_get", 1, ({
|
optime("Autoarr_get", count,
|
||||||
for(uint32 i=0; i< count; i++)
|
t=Autoarr_get(ar, op_i));
|
||||||
t=Autoarr_get(ar, i);
|
optime("vector_get", count,
|
||||||
}));
|
t=vec[op_i]);
|
||||||
optime("vector_get", 1, ({
|
|
||||||
for(uint32 i=0; i< count; i++)
|
|
||||||
t=vec[i];
|
|
||||||
}));
|
|
||||||
Autoarr_free(ar, true);
|
Autoarr_free(ar, true);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_autoarrVsVector(){
|
void test_autoarrVsVector(){
|
||||||
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
|
optime(__func__, 1, ({
|
||||||
_autoarrVsVector(4, 16);
|
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
|
||||||
_autoarrVsVector(16, 64);
|
_autoarrVsVector(4, 16);
|
||||||
_autoarrVsVector(32, 32);
|
_autoarrVsVector(16, 64);
|
||||||
_autoarrVsVector(64, 64);
|
_autoarrVsVector(32, 32);
|
||||||
_autoarrVsVector(32, 1024);
|
_autoarrVsVector(64, 64);
|
||||||
_autoarrVsVector(256, 256);
|
_autoarrVsVector(32, 1024);
|
||||||
_autoarrVsVector(1024, 1024);
|
_autoarrVsVector(256, 256);
|
||||||
|
_autoarrVsVector(1024, 1024);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
50
tests/test_kprint.c
Normal file
50
tests/test_kprint.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include "tests.h"
|
||||||
|
#include "../src/kprint/kprint.h"
|
||||||
|
|
||||||
|
void test_kprint(){
|
||||||
|
//int
|
||||||
|
kprint(kp_fgCyan|
|
||||||
|
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
||||||
|
//uint
|
||||||
|
kprint(kp_fgGreen|
|
||||||
|
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
||||||
|
kp_u,1234567890987654321LL, kp_c,'\n');
|
||||||
|
//float
|
||||||
|
kprint(kp_fgCyanD|
|
||||||
|
kp_f,-4000.0109f, kp_c,' ', kp_f,-0.000020004f, kp_c,'\n',
|
||||||
|
kp_f,-1.0f, kp_c,' ', kp_f,0.0f, kp_c,' ', kp_f,1.0f, kp_c,'\n',
|
||||||
|
kp_f|kp_post,0.000020004f, kp_c,' ',
|
||||||
|
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
||||||
|
//double
|
||||||
|
kprint(kp_fgYellowD|
|
||||||
|
kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n',
|
||||||
|
kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n',
|
||||||
|
kp_f|kp_post,0.000020004, kp_c,' ',
|
||||||
|
kp_f|kp_post|kp_upper,4000.0109, kp_c,'\n');
|
||||||
|
//hex
|
||||||
|
kprint(kp_fgYellow|
|
||||||
|
kp_h,0, kp_c,' ', kp_h,1, kp_c,' ', kp_h,-1, kp_c,' ', kp_h,15, kp_c,'\n',
|
||||||
|
kp_h,4095, kp_c,' ', kp_h,-4095, kp_c,'\n',
|
||||||
|
kp_h,1234567890987654321LL, kp_c,'\n', kp_h,-1234567890987654321LL, kp_c,'\n');
|
||||||
|
kprint(
|
||||||
|
kp_h,-1.0f, kp_c,' ', kp_h,0.0f, kp_c,' ', kp_h,1.0f, kp_c,'\n',
|
||||||
|
kp_h, 0.00016f, kp_c,' ', kp_h,-115515.009f, kp_c,'\n');
|
||||||
|
kprint(
|
||||||
|
kp_h|kp_pre, 0.00016, kp_c,'\n',
|
||||||
|
kp_h|kp_pre|kp_upper,-115515.009, kp_c,'\n');
|
||||||
|
//bin
|
||||||
|
kprint(kp_fgBlue|
|
||||||
|
kp_b,0, kp_c,'\n', kp_b,1, kp_c,'\n', kp_b,-1, kp_c,'\n', kp_b,15, kp_c,'\n',
|
||||||
|
kp_b,4095, kp_c,'\n', kp_b,-4095, kp_c,'\n',
|
||||||
|
kp_b,1234567890987654321LL, kp_c,'\n', kp_b,-1234567890987654321LL, kp_c,'\n');
|
||||||
|
kprint(
|
||||||
|
kp_b,-1.0f, kp_c,'\n', kp_b,0.0f, kp_c,'\n', kp_b,1.0f, kp_c,'\n',
|
||||||
|
kp_b, 0.00016f, kp_c,'\n', kp_b,-115515.009f, kp_c,'\n');
|
||||||
|
kprint(
|
||||||
|
kp_b|kp_pre, 0.00016, kp_c,'\n',
|
||||||
|
kp_b|kp_pre|kp_upper,-115515.009, kp_c,'\n');
|
||||||
|
//string
|
||||||
|
kprint(kp_s|kp_fgYellow, "\n ooo \n",
|
||||||
|
kp_s|kp_fgWhite, "gg",
|
||||||
|
kp_fgGray|kp_bgBlack|kp_s, "\n");
|
||||||
|
}
|
||||||
@ -5,11 +5,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define testColor(COLOR) \
|
#define testColor(COLOR) \
|
||||||
kprint_setColor(kprint_bgBlack | kprint_fg##COLOR);\
|
kprint_setColor(kp_bgBlack|kp_fg##COLOR);\
|
||||||
kprintf(#COLOR " ");\
|
kprintf(#COLOR " ");\
|
||||||
kprint_setColor(kprint_bg##COLOR | kprint_fgGray);\
|
kprint_setColor(kp_bg##COLOR|kp_fgGray);\
|
||||||
kprintf(#COLOR);\
|
kprintf(#COLOR);\
|
||||||
kprint_setColor(kprint_bgBlack | kprint_fgBlack);\
|
kprint_setColor(kp_bgBlack|kp_fgBlack);\
|
||||||
kprintf("\n");
|
kprintf("\n");
|
||||||
|
|
||||||
void test_kprint_colors(){
|
void test_kprint_colors(){
|
||||||
@ -29,14 +29,14 @@ void test_kprint_colors(){
|
|||||||
kprintf("\n"); */
|
kprintf("\n"); */
|
||||||
|
|
||||||
testColor(Black);
|
testColor(Black);
|
||||||
testColor(DarkRed);
|
testColor(RedD);
|
||||||
testColor(DarkGreen);
|
testColor(GreenD);
|
||||||
testColor(DarkYellow);
|
testColor(YellowD);
|
||||||
testColor(DarkBlue);
|
testColor(BlueD);
|
||||||
testColor(DarkMagenta);
|
testColor(MagentaD);
|
||||||
testColor(DarkCyan);
|
testColor(CyanD);
|
||||||
testColor(Gray);
|
testColor(Gray);
|
||||||
testColor(DarkGray);
|
testColor(GrayD);
|
||||||
testColor(Red);
|
testColor(Red);
|
||||||
testColor(Green);
|
testColor(Green);
|
||||||
testColor(Yellow);
|
testColor(Yellow);
|
||||||
@ -44,7 +44,5 @@ void test_kprint_colors(){
|
|||||||
testColor(Magenta);
|
testColor(Magenta);
|
||||||
testColor(Cyan);
|
testColor(Cyan);
|
||||||
testColor(White);
|
testColor(White);
|
||||||
kprint_setColor(kprint_bgBlack | kprint_fgGray);
|
kprint_setColor(kp_bgBlack|kp_fgGray);
|
||||||
|
|
||||||
kprint(kprint_fmtInt | kprint_fgCyan, 8888, kprint_fmtString | kprint_fgYellow, " ooo ", kprint_fmtFloat | kprint_bgDarkGreen | kprint_fgRed, 4.01, kprint_fmtString | kprint_fgWhite, "\ngg\n");
|
|
||||||
}
|
}
|
||||||
9
tests/test_type_system.c
Normal file
9
tests/test_type_system.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
void test_type_system(){
|
||||||
|
for(ktid id=0; id<ktid_last; id++){
|
||||||
|
ktDescriptor d=ktDescriptor_get(id);
|
||||||
|
kprintf("\e[37m{ id:%u name:%s size:%u freeMembers:%p toString:%p }\n",
|
||||||
|
d.id, d.name, d.size, d.freeMembers, d.toString);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,9 +13,30 @@ void test_autoarr();
|
|||||||
void test_hash_functions();
|
void test_hash_functions();
|
||||||
void test_hashtable();
|
void test_hashtable();
|
||||||
void test_dtsod();
|
void test_dtsod();
|
||||||
void test_kprint_colors();
|
|
||||||
void test_autoarrVsVector();
|
void test_autoarrVsVector();
|
||||||
void test_rng_algorithms();
|
void test_rng_algorithms();
|
||||||
|
void test_kprint_colors();
|
||||||
|
void test_kprint();
|
||||||
|
void test_type_system();
|
||||||
|
|
||||||
|
inline void test_all(){
|
||||||
|
kprintf("\e[97mkerep tests are starting!\n");
|
||||||
|
optime(__func__, 1, ({
|
||||||
|
test_type_system();
|
||||||
|
test_string();
|
||||||
|
test_safethrow();
|
||||||
|
test_searchtree();
|
||||||
|
test_autoarr();
|
||||||
|
test_autoarrVsVector();
|
||||||
|
test_hash_functions();
|
||||||
|
test_hashtable();
|
||||||
|
test_dtsod();
|
||||||
|
test_rng_algorithms();
|
||||||
|
test_kprint_colors();
|
||||||
|
test_kprint();
|
||||||
|
kprintf("\e[96m--------------------------------------\e[0m\n");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
|
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user