diff options
Diffstat (limited to '')
| -rw-r--r-- | project/dclib/dclib-basics.c | 191 | ||||
| -rw-r--r-- | project/dclib/dclib-basics.h | 73 | ||||
| -rw-r--r-- | project/dclib/dclib-file.c | 35 | ||||
| -rw-r--r-- | project/dclib/dclib-network.c | 36 | ||||
| -rw-r--r-- | project/dclib/dclib-network.h | 41 | ||||
| -rw-r--r-- | project/dclib/dclib-numeric.c | 86 | ||||
| -rw-r--r-- | project/dclib/dclib-system.h | 2 | ||||
| -rw-r--r-- | project/dclib/dclib-tables.c | 1 | ||||
| -rw-r--r-- | project/dclib/dclib-xdump.c | 2 | ||||
| -rw-r--r-- | project/dclib/lib-bmg.c | 3 | ||||
| -rw-r--r-- | project/dclib/lib-bmg.h | 3 | ||||
| -rw-r--r-- | project/dclib/lib-mkw-def.c | 261 | ||||
| -rw-r--r-- | project/dclib/lib-mkw-def.h | 48 | ||||
| -rw-r--r-- | project/dclib/lib-mkw.c | 33 | ||||
| -rw-r--r-- | project/dclib/lib-mkw.h | 26 |
15 files changed, 727 insertions, 114 deletions
diff --git a/project/dclib/dclib-basics.c b/project/dclib/dclib-basics.c index d2eca00..8f9ec1f 100644 --- a/project/dclib/dclib-basics.c +++ b/project/dclib/dclib-basics.c @@ -720,6 +720,16 @@ ccp StringCenterE /////////////////////////////////////////////////////////////////////////////// +char * StringLower ( ccp src ) +{ + if (src) + for ( char *ptr = (char*)src; *ptr; ptr++ ) + *ptr = tolower(*ptr); + return (char*)src; +} + +//----------------------------------------------------------------------------- + char * StringLowerE ( char * buf, ccp buf_end, ccp src ) { // RESULT: end of copied string pointing to NULL @@ -781,6 +791,16 @@ char * MemLowerS ( char * buf, ssize_t buf_size, mem_t src ) /////////////////////////////////////////////////////////////////////////////// +char * StringUpper ( ccp src ) +{ + if (src) + for ( char *ptr = (char*)src; *ptr; ptr++ ) + *ptr = toupper(*ptr); + return (char*)src; +} + +//----------------------------------------------------------------------------- + char * StringUpperE ( char * buf, ccp buf_end, ccp src ) { // RESULT: end of copied string pointing to NULL @@ -3477,8 +3497,7 @@ void DumpArgManager ( FILE *f, int indent, const ArgManager_t *am, ccp title ) char buf[10]; int fw = snprintf(buf,sizeof(buf),"%u",am->argc-1)+2; - uint i; - for ( i = 0; i < am->argc; i++ ) + for ( int i = 0; i < am->argc; i++ ) fprintf(f,"%*s%*u: |%s|\n", indent,"", fw,i, am->argv[i] ); } } @@ -6074,23 +6093,41 @@ const KeywordTab_t *GetKewordByIdAndOpt /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -const KeywordTab_t * ScanKeyword +const KeywordTab_t * ScanKeywordEx ( int * res_abbrev, // NULL or pointer to result 'abbrev_count' ccp arg, // argument to scan + int arg_len, // length of 'arg', if <0 then terminate at null, comma or semicolon + LowerUpper_t force_case, // change case of scanned arg if LOUP_LOWER|LOUP_UPPER const KeywordTab_t * key_tab // valid pointer to command table ) { - DASSERT(arg); - char key_buf[KEYWORD_NAME_MAX]; + if ( !arg || !key_tab ) + return 0; + char key_buf[KEYWORD_NAME_MAX]; char *dest = key_buf; char *end = key_buf + sizeof(key_buf) - 1; - while ( *arg && *arg != ',' && *arg != ';' && dest < end ) - *dest++ = toupper((int)*arg++); + + if ( arg_len < 0 ) + { + while ( *arg && *arg != ',' && *arg != ';' && dest < end ) + *dest++ = *arg++; + } + else + { + ccp arg_end = arg + arg_len; + while ( *arg && arg < arg_end && dest < end ) + *dest++ = *arg++; + } *dest = 0; const int key_len = dest - key_buf; + if ( force_case == LOUP_UPPER ) + StringUpper(key_buf); + else if ( force_case == LOUP_LOWER ) + StringLower(key_buf); + int favor_count = 0, abbrev_count = 0; const KeywordTab_t *ct, *key_ct = 0; const KeywordTab_t *favor_ct = 0, *favor_prev = 0, *abbrev_ct = 0, *abbrev_prev = 0; @@ -6642,6 +6679,146 @@ int ScanKeywordOffOn // /////////////////////////////////////////////////////////////////////////////// +/////////////// KeywordTabManager_t /////////////// +/////////////////////////////////////////////////////////////////////////////// + +void InitializeKTM ( KeywordTabManager_t *ktm, int grow, bool sort ) +{ + DASSERT(ktm); + memset(ktm,0,sizeof(*ktm)); + ktm->sort = sort; + ktm->grow = grow > 10 ? grow : 10; + ktm->size = ktm->grow; + ktm->list = CALLOC(ktm->size+1,sizeof(*ktm->list)); +} + +/////////////////////////////////////////////////////////////////////////////// + +void ResetKTM ( KeywordTabManager_t *ktm ) +{ + if (ktm) + { + for ( int idx = 0; idx < ktm->used; idx++ ) + { + KeywordTab_t *key = ktm->list + idx; + FreeString(key->name1); + FreeString(key->name2); + } + FREE(ktm->list); + memset(ktm,0,sizeof(*ktm)); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +void ClearKTM ( KeywordTabManager_t *ktm ) +{ + if (ktm) + { + if (!ktm->list) + InitializeKTM(ktm,10,true); + DASSERT(ktm->list); + ktm->used = 0; + memset(ktm->list,0,sizeof(*ktm->list)); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +static ccp ktm_dup_name ( const KeywordTabManager_t *ktm, ccp name, int namelen ) +{ + ccp res = namelen < 0 ? STRDUP(name) : MEMDUP(name,namelen); + if ( ktm->force_case == LOUP_UPPER ) + StringUpper(res); + else if ( ktm->force_case == LOUP_LOWER ) + StringLower(res); + return res; +} + +/////////////////////////////////////////////////////////////////////////////// + +static KeywordTab_t * insert_ktm_helper + ( KeywordTabManager_t *ktm, uint idx, ccp name, int namelen, s64 id, s64 opt ) +{ + DASSERT(ktm); + if ( ktm->used == ktm->size ) + { + if ( ktm->grow < 10 ) + ktm->grow = 10; + ktm->size += ktm->size/2 + ktm->grow; + ktm->list = REALLOC( ktm->list, (ktm->size+1) * sizeof(*ktm->list)) ; + } + + if ( idx >= ktm->used ) + idx = ktm->used; + KeywordTab_t *key = ktm->list + idx; + + if ( idx < ktm->used ) + memmove( key+1, key, (ktm->used-idx)*sizeof(*ktm->list) ); + memset(ktm->list + ++ktm->used, 0, sizeof(*key) ); + + key->id = id; + key->opt = opt; + key->name1 = ktm_dup_name(ktm,name,namelen); + key->name2 = 0; + return key; +} + +/////////////////////////////////////////////////////////////////////////////// + +KeywordTab_t * InsertKTM + ( KeywordTabManager_t *ktm, ccp name, int namelen, s64 id, s64 opt ) +{ + DASSERT(ktm); + if (!ktm->sort) + return AppendKTM(ktm,name, namelen,id,opt); + + int idx; + KeywordTab_t *key = ktm->list; + + // find first occurance + for ( idx = 0; idx < ktm->used; idx++, key++ ) + if ( key->id == id && key->opt == opt ) + { + // skip same entries + for ( ; idx < ktm->used; idx++, key++ ) + if ( key->id != id || key->opt != opt ) + break; + + key--; + if ( !key->name2 ) + { + key->name2 = ktm_dup_name(ktm,name,namelen); + return key; + } + break; + } + + return insert_ktm_helper(ktm,idx,name,namelen,id,opt); +} + +/////////////////////////////////////////////////////////////////////////////// + +KeywordTab_t * AppendKTM + ( KeywordTabManager_t *ktm, ccp name, int namelen, s64 id, s64 opt ) +{ + DASSERT(ktm); + + if ( ktm->used > 0 ) + { + KeywordTab_t *key = ktm->list + ktm->used - 1; + if ( !key->name2 && key->id == id && key->opt == opt ) + { + key->name2 = ktm_dup_name(ktm,name,namelen); + return key; + } + } + + return insert_ktm_helper(ktm,ktm->used,name,namelen,id,opt); +} + +// +/////////////////////////////////////////////////////////////////////////////// /////////////// OFF/AUTO/ON/FORCE /////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/project/dclib/dclib-basics.h b/project/dclib/dclib-basics.h index 9df963c..99eb0c3 100644 --- a/project/dclib/dclib-basics.h +++ b/project/dclib/dclib-basics.h @@ -1532,6 +1532,10 @@ static inline char * StringCopySMem ( char *buf, ssize_t bufsize, mem_t mem ) static inline char * StringCopyEMem ( char *buf, ccp buf_end, mem_t mem ) { return StringCopyEM(buf,buf_end,mem.ptr,mem.len); } +// change case of src. !src is allowed. return src +char * StringLower ( ccp src ); +char * StringUpper ( ccp src ); + char * StringLowerS ( char * buf, ssize_t bufsize, ccp src ); char * StringLowerE ( char * buf, ccp buf_end, ccp src ); char * StringUpperS ( char * buf, ssize_t bufsize, ccp src ); @@ -2178,11 +2182,11 @@ void ** DupPointerMgr ( PointerList_t *pl, bool reset ); typedef struct ArgManager_t { - LowerUpper_t force_case; // change case? - char **argv; // list of strings - int argc; // number of used elements in 'argv' - uint size; // >0: 'argv' is alloced to store # elements - // last NULL element is not counted here + LowerUpper_t force_case; // change case if LOUP_UPPER | LOUP_LOWER + char **argv; // list of strings + int argc; // number of used elements in 'argv' + uint size; // >0: 'argv' is alloced to store # elements + // last NULL element is not counted here } ArgManager_t; @@ -2757,6 +2761,15 @@ __attribute__ ((__format__(__printf__,7,8))); /////////////// encoding/decoding /////////////// /////////////////////////////////////////////////////////////////////////////// +// support of encoded version numbers: MMMMmmaabb +// MMMM: major, mm:minor, aa: empty|a-z|A-Z, bb: beta|beta## +// Text formats: 1.23a | 1.23a.beta | 1.23a.beta## (letter 'a' is optional) + +uint EncodeVersion ( ccp arg ); // arg can be 0 or empty +ccp DecodeVersion ( uint code ); // return circ-buf + +/////////////////////////////////////////////////////////////////////////////// + extern const u32 TableCRC32[0x100]; u32 CalcCRC32 ( u32 crc, cvp buf, uint size ); @@ -3431,12 +3444,24 @@ static inline ccp GetKewordNameByIdAndOpt /////////////////////////////////////////////////////////////////////////////// -const KeywordTab_t * ScanKeyword +const KeywordTab_t * ScanKeywordEx +( + int * res_abbrev, // NULL or pointer to result 'abbrev_count' + ccp arg, // argument to scan + int arg_len, // length of 'arg', if <0 then terminate at null, comma or semicolon + LowerUpper_t force_case, // change case of scanned arg if LOUP_LOWER|LOUP_UPPER + const KeywordTab_t * key_tab // valid pointer to command table +); + +static inline const KeywordTab_t * ScanKeyword ( int *res_abbrev, // NULL or pointer to result 'abbrev_count' ccp arg, // argument to scan const KeywordTab_t *key_tab // valid pointer to command table -); +) +{ + return ScanKeywordEx(res_abbrev,arg,-1,LOUP_UPPER,key_tab); +} //----------------------------------------------------------------------------- @@ -3573,6 +3598,34 @@ enumError Command_COLORS // /////////////////////////////////////////////////////////////////////////////// +/////////////// KeywordTabManager_t /////////////// +/////////////////////////////////////////////////////////////////////////////// +// [[KeywordTabManager_t]] + +typedef struct KeywordTabManager_t +{ + KeywordTab_t *list; // list of elements including terminator + uint used; // number of used elements without terminator + uint size; // number of alloced elements without terminator + int grow; // list grow value; max(10,grow) is used + LowerUpper_t force_case; // change case if LOUP_UPPER | LOUP_LOWER + bool sort; // true: sort equal id's together + +} KeywordTabManager_t; + +//----------------------------------------------------------------------------- + +void InitializeKTM ( KeywordTabManager_t *ktm, int grow, bool sort ); +void ResetKTM ( KeywordTabManager_t *ktm ); // Reset if 'ktm' not NULL +void ClearKTM ( KeywordTabManager_t *ktm ); // Init or Clear if 'ktm' not NULL + +// if 'namelen' < 0, then use STRDUP(name), else MEMDUP(name,namelen) +// AppendKTM() ignores 'sort' +KeywordTab_t * InsertKTM ( KeywordTabManager_t *ktm, ccp name, int namelen, s64 id, s64 opt ); +KeywordTab_t * AppendKTM ( KeywordTabManager_t *ktm, ccp name, int namelen, s64 id, s64 opt ); + +// +/////////////////////////////////////////////////////////////////////////////// /////////////// OFF/AUTO/ON/FORCE /////////////// /////////////////////////////////////////////////////////////////////////////// // [[OffOn_t]] @@ -5203,7 +5256,8 @@ char * ScanDateTime time_t *res_time, // not NULL: store seconds u32 *res_usec, // not NULL: store microseconds of second ccp source, // source text - bool allow_delta // true: allow +|- interval + bool allow_delta, // true: allow +|- interval + bool use_localtime // false: UTC, true: local time ); /////////////////////////////////////////////////////////////////////////////// @@ -5212,7 +5266,8 @@ char * ScanDateTime64 ( u64 *res_usec, // not NULL: store total microseconds ccp source, // source text - bool allow_delta // true: allow +|- interval + bool allow_delta, // true: allow +|- interval + bool use_localtime // false: UTC, true: local time ); // diff --git a/project/dclib/dclib-file.c b/project/dclib/dclib-file.c index 94745e7..08ba1cc 100644 --- a/project/dclib/dclib-file.c +++ b/project/dclib/dclib-file.c @@ -2859,9 +2859,6 @@ void RedirectLineBuffer fprintf(f,"%.*s\n",line->len-1,line->ptr); line++; } -//DEL fprintf(f,"==> %zd %d\n", -//DEL line[-1].ptr + line[-1].len - (ccp)lb->buf.ptr, -//DEL lb->buf.used ); } fflush(f); @@ -3791,7 +3788,8 @@ static void search_paths_hit ( search_paths_t *sp, mem_t path, uint d_type ) /////////////////////////////////////////////////////////////////////////////// -static void search_paths_dir ( search_paths_t *sp, ParamField_t *collect, int min, int max ) +static void search_paths_dir + ( search_paths_t *sp, ParamField_t *collect, int min, int max ) { DASSERT(sp); DASSERT(collect); @@ -3905,41 +3903,52 @@ static void search_paths_helper ( search_paths_t *sp ) if ( pattern.ptr[0] == '*' && pattern.ptr[1] == '*' ) { - u32 n1 = 0, n2 = 100; + u32 min = 0, max = 100; char *ptr = (char*)pattern.ptr+2; if (*ptr) { if (isdigit(*ptr)) - n1 = str2ul(ptr,&ptr,10); + min = str2ul(ptr,&ptr,10); if (*ptr) { if ( *ptr != '-' ) goto terminate; if ( *++ptr ) { - n2 = str2ul(ptr,&ptr,10); + max = str2ul(ptr,&ptr,10); if (*ptr) goto terminate; } } else - n2 = n1; - if ( n2 > 100 ) - n2 = 100; - if ( n1 > n2 ) + max = min; + if ( max > 100 ) + max = 100; + if ( min > max ) goto terminate; } + if (!min) + InsertParamField(&collect,"",false,S_IFDIR,0); + local.path_star = path_ptr; - search_paths_dir(&local,&collect,n1,n2); + search_paths_dir(&local,&collect,min-1,max-1); PRINT0("%sDIR: %d records for **%s\n",colerr->highlight,collect.used,colerr->reset); ParamFieldItem_t *end = collect.field + collect.used; for ( ParamFieldItem_t *ptr = collect.field; !local.status.abort && ptr < end; ptr++ ) { - local.path_ptr = StringCopyE(path_ptr,sp->path_end,ptr->key); + if (ptr->key[0]) + local.path_ptr = StringCopyE(path_ptr,sp->path_end,ptr->key); + else + { + local.path_ptr = path_ptr-1; + *local.path_ptr = 0; + } PRINT0("%sDIR: %s%s\n",colerr->highlight,local.path_buf,colerr->reset); search_paths_helper(&local); + if (!ptr->key[0]) + *local.path_ptr = '/'; if (local.status.abort) break; } diff --git a/project/dclib/dclib-network.c b/project/dclib/dclib-network.c index b069ba2..abc5f08 100644 --- a/project/dclib/dclib-network.c +++ b/project/dclib/dclib-network.c @@ -335,10 +335,12 @@ ccp GetIPClassColor ( const ColorSet_t *colset, IPClass_t ipc ) switch (ipc) { case IPCL_INVALID: return colset->b_red; - case IPCL_LOOPBACK: return colset->b_cyan; - case IPCL_LOCAL: return colset->b_green; - case IPCL_STANDARD: return colset->reset; + case IPCL_LOOPBACK: return colset->b_blue; + case IPCL_LINK_LOCAL: return colset->b_cyan; + case IPCL_LOCAL: return colset->b_green_cyan; + case IPCL_UNIQUE_LOCAL: return colset->b_green; case IPCL_SPECIAL: return colset->b_yellow; + case IPCL_STANDARD: return colset->reset; default: return colset->b_magenta; } } @@ -588,6 +590,7 @@ IPClass_t GetIPClassBIP ( const BinIP_t * bip ) { 0xc0a80000, 0xffff0000, IPCL_LOCAL }, // 192.168.0.0/16 { 0xa9fe0000, 0xffff0000, IPCL_LOCAL }, // 169.254.0.0/16 { 0xe0000000, 0xe0000000, IPCL_SPECIAL }, // 224.0.0.0/3 + // IPCL_STANDARD is fallback { 0,0,IPCL__N }, }; @@ -601,10 +604,13 @@ IPClass_t GetIPClassBIP ( const BinIP_t * bip ) static struct ip6_tab ip6_tab[] = { - { IPCL_INVALID, "::" }, - { IPCL_LOOPBACK, "::1" }, - { IPCL_LOCAL, "fe80::/10" }, - { IPCL_SPECIAL, "f00::/8" }, + { IPCL_INVALID, "::" }, + { IPCL_LOOPBACK, "::1" }, + { IPCL_LINK_LOCAL, "fe80::/64" }, + { IPCL_UNIQUE_LOCAL, "fc00::/7" }, + { IPCL_STANDARD, "2000::/3" }, + { IPCL_SPECIAL, "f00::/8" }, + // IPCL_UNUSED is fallback { 0,0 }, }; @@ -651,7 +657,7 @@ IPClass_t GetIPClassBIP ( const BinIP_t * bip ) return ptr->ipc; } } - return IPCL_STANDARD; + return IPCL_UNUSED; } } @@ -1249,6 +1255,20 @@ ccp GetNameInfoMIP ( ManageIP_t *mip ) /////////////////////////////////////////////////////////////////////////////// +ccp GetNameInfoExMIP ( ManageIP_t *mip, PrintModeIP_t pmode ) +{ + DASSERT(mip); + + if ( pmode & PMIP_F_RESOLVE ) + return GetNameInfoMIP(mip); + + if ( !mip->name && mip->bin.ipvers ) + mip->name = STRDUP(PrintAddrMIP(mip,pmode)); + return mip->name; +} + +/////////////////////////////////////////////////////////////////////////////// + void ApplyMaskMIP ( ManageIP_t *mip, int bits ) { DASSERT(mip); diff --git a/project/dclib/dclib-network.h b/project/dclib/dclib-network.h index 41f371f..b42cb5c 100644 --- a/project/dclib/dclib-network.h +++ b/project/dclib/dclib-network.h @@ -117,27 +117,30 @@ bool ResolveHostMem typedef enum PrintModeIP_t { // characters for ScanPrintModeIP(): nria - PMIP_NEVER = 0x000, ///< '/Bits' unterdrücken. - PMIP_RELEVANT = 0x001, ///< '/Bits' nur falls relevant. - PMIP_IF_SET = 0x002, ///< '/Bits' nur falls gesetzt. - PMIP_ALWAYS = 0x003, ///< '/Bits' immer ausgeben. - PMIP_M_BITS = 0x003, ///< Maske für Bit-Modi. + PMIP_NEVER = 0x0000, ///< '/Bits' unterdrücken. + PMIP_RELEVANT = 0x0001, ///< '/Bits' nur falls relevant. + PMIP_IF_SET = 0x0002, ///< '/Bits' nur falls gesetzt. + PMIP_ALWAYS = 0x0003, ///< '/Bits' immer ausgeben. + PMIP_M_BITS = 0x0003, ///< Maske für Bit-Modi. // characters for ScanPrintModeIP(): psmb - PMIP_PORT = 0x004, ///< Flag: Print port if >0. - PMIP_SERVICE = 0x008, ///< Flag: Print service instead of port number. - PMIP_MASK = 0x010, ///< Flag: Print netmask instead of bits for IPv4. - PMIP_BRACKETS = 0x020, ///< Flag: Print bracktes if [IPv6]. + PMIP_PORT = 0x0004, ///< Flag: Print port if >0. + PMIP_SERVICE = 0x0008, ///< Flag: Print service instead of port number. + PMIP_MASK = 0x0010, ///< Flag: Print netmask instead of bits for IPv4. + PMIP_BRACKETS = 0x0020, ///< Flag: Print bracktes if [IPv6]. // characters for ScanPrintModeIP(): f - PMIP_FULL_IPV6 = 0x100, ///< Print IPv6 without short numbers. + PMIP_FULL_IPV6 = 0x0100, ///< Print IPv6 without short numbers. // characters for ScanPrintModeIP(): 0123 - PMIP_0DOTS = 0x200, ///< Print IPv4 as single number (highest priority). - PMIP_1DOT = 0x400, ///< Print IPv4 as "1.2" (A-Class notation). - PMIP_2DOTS = 0x800, ///< Print IPv4 as "1.2.3" (B-Class notation). - PMIP_3DOTS = 0, ///< Print IPv4 as "1.2.3.4" (C-Class notation, default). - PMIP_M_DOTS = 0xc00 ///< Maske für Dot-Modi. + PMIP_0DOTS = 0x0200, ///< Print IPv4 as single number (highest priority). + PMIP_1DOT = 0x0400, ///< Print IPv4 as "1.2" (A-Class notation). + PMIP_2DOTS = 0x0800, ///< Print IPv4 as "1.2.3" (B-Class notation). + PMIP_3DOTS = 0, ///< Print IPv4 as "1.2.3.4" (C-Class notation, default). + PMIP_M_DOTS = 0x0c00, ///< Maske für Dot-Modi. + + // flags for advanced usage + PMIP_F_RESOLVE = 0x1000, ///< If set: resolve address or name if missed } PrintModeIP_t; @@ -154,9 +157,12 @@ typedef enum IPClass_t { IPCL_INVALID, // 0.0.0.0 :: IPCL_LOOPBACK, // 127.0/8 ::1 - IPCL_LOCAL, // 10.0/8 172.16/12 192.168/16 169.254/16 fe80::/10 - IPCL_STANDARD, // * * + IPCL_LOCAL, // 10.0/8 172.16/12 192.168/16 169.254/16 - + IPCL_LINK_LOCAL, // - fe80::/64 + IPCL_UNIQUE_LOCAL, // - fc00::/7 IPCL_SPECIAL, // 224.0.0.0/3 f00::/8 + IPCL_STANDARD, // * 2000::/3 + IPCL_UNUSED, // - * IPCL__N, } IPClass_t; @@ -403,6 +409,7 @@ ManageIP_t GetAddrInfoMIP ( ccp addr, int protocol, IpMode_t ipm ); sockaddr_in46_t GetSockaddrMIP ( const ManageIP_t *mip ); ccp GetNameInfoMIP ( ManageIP_t *mip ); +ccp GetNameInfoExMIP ( ManageIP_t *mip, PrintModeIP_t pmode ); // respect PMIP_F_RESOLVE void ApplyMaskMIP ( ManageIP_t *mip, int bits ); void MaskPrefixMIP ( ManageIP_t *mip ); // includes ApplyMaskMIP() diff --git a/project/dclib/dclib-numeric.c b/project/dclib/dclib-numeric.c index c339a29..7a420c3 100644 --- a/project/dclib/dclib-numeric.c +++ b/project/dclib/dclib-numeric.c @@ -1431,6 +1431,76 @@ uint ScanEscapedString /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// +uint EncodeVersion ( ccp arg ) +{ + if (!arg) + return 0; + + if ( *arg =='v' || *arg == 'V' ) + arg++; + + char *next; + uint major = str2ul(arg,&next,10); + if ( major > 4293 ) + major = major; + + uint minor = 0, letter = 0, beta = ~0; + if ( *next == '.' ) + { + if (isdigit(*++next)) + { + minor = str2ul(next,&next,10); + if ( minor > 99 ) + minor = 99; + } + + if (!strncasecmp(next,"beta",4)) + beta = str2ul(next+4,0,10); + else if (islower(*next)) + letter = *next++ -'a' + 1; + else if (isupper(*next)) + letter = *next++ -'A' + 27; + + } + + if ( *next == '.' ) + next++; + if ( beta == ~0 && !strncasecmp(next,"beta",4) ) + beta = str2ul(next+4,0,10); + + if (!beta) + beta = 1; + else if ( beta > 99 ) + beta = 99; + + return 1000000 * major + 10000 * minor + 100 * letter + beta; +} + +/////////////////////////////////////////////////////////////////////////////// + +ccp DecodeVersion ( uint code ) +{ + const uint major = code / 1000000; + const uint minor = code / 10000 % 100; + const uint letter = code / 100 % 100; + const uint beta = code % 100; + + char xletter[2] = { 0x60+letter, 0 }; + if (!letter) + *xletter = 0; + else if (letter>52) + *xletter = '?'; + else if (letter>26) + *xletter += 'A'-'z'-1; + + return beta > 0 && beta < 99 + ? PrintCircBuf("%u.%02u%s.beta%u",major,minor,xletter,beta) + : PrintCircBuf("%u.%02u%s%s",major,minor,xletter,beta?"":"*"); +} + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + u32 CalcCRC32 ( u32 crc, cvp buf, uint size ) { #if HAVE_PRINT0 @@ -4217,7 +4287,8 @@ char * ScanDateTime time_t *res_time, // not NULL: store seconds here u32 *res_usec, // not NULL: store useconds of second here ccp source, // source text - bool allow_delta // true: allow +|- interval + bool allow_delta, // true: allow +|- interval + bool use_localtime // false: UTC, true: local time ) { //--- scan date @@ -4232,12 +4303,12 @@ char * ScanDateTime memset(&tm,0,sizeof(tm)); src = strptime(src,"%Y-%m-%d",&tm); - noPRINT(" %4u-%02u-%02u %2u:%02u:%02u |%s|\n", + PRINT1(" %4u-%02u-%02u %2u:%02u:%02u |%s|\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, src ); if (src) - total_time = mktime(&tm); + total_time = use_localtime ? mktime(&tm) : timegm(&tm); else src = source ? source : ""; noPRINT_TIME(total_time,"DATE"); @@ -4277,9 +4348,9 @@ char * ScanDateTime total_time -= delta + timezone; src = src2 + 5; } - else + else if (use_localtime) { - PRINT("timezone=%ld\n",timezone); + PRINT0("timezone=%ld, total_time=%ld\n",timezone,(long)total_time); struct tm *tm = localtime(&total_time); if (tm->tm_isdst) total_time -= 3600; @@ -4337,12 +4408,13 @@ char * ScanDateTime64 ( u64 *res_usec, // not NULL: store total microseconds ccp source, // source text - bool allow_delta // true: allow +|- interval + bool allow_delta, // true: allow +|- interval + bool use_localtime // false: UTC, true: local time ) { time_t time; u32 usec; - char *src = ScanDateTime(&time,&usec,source,allow_delta); + char *src = ScanDateTime(&time,&usec,source,allow_delta,use_localtime); if (res_usec) *res_usec = time * 1000000ull + usec; return src; diff --git a/project/dclib/dclib-system.h b/project/dclib/dclib-system.h index 7da6e82..aa518c4 100644 --- a/project/dclib/dclib-system.h +++ b/project/dclib/dclib-system.h @@ -76,7 +76,7 @@ typedef enum enumSystemID #elif __APPLE__ #define SYSTEM_LINUX 0 #define SYSTEM "mac" - #ifdef __aarch64__ + #if defined(__arm64__) || defined(__aarch64__) #define SYSTEM2 "mac/arm" #define SYSTEMID SYSID_MAC_ARM #elif __x86_64__ diff --git a/project/dclib/dclib-tables.c b/project/dclib/dclib-tables.c index 310e9a2..32948fd 100644 --- a/project/dclib/dclib-tables.c +++ b/project/dclib/dclib-tables.c @@ -524,6 +524,7 @@ const sizeof_info_t sizeof_info_dclib[] = SIZEOF_INFO_ENTRY(sizeof_info_t) SIZEOF_INFO_ENTRY(PointerList_t) SIZEOF_INFO_ENTRY(KeywordTab_t) + SIZEOF_INFO_ENTRY(KeywordTabManager_t) SIZEOF_INFO_ENTRY(StringField_t) SIZEOF_INFO_ENTRY(ParamFieldItem_t) SIZEOF_INFO_ENTRY(ParamField_t) diff --git a/project/dclib/dclib-xdump.c b/project/dclib/dclib-xdump.c index f4175b0..485c689 100644 --- a/project/dclib/dclib-xdump.c +++ b/project/dclib/dclib-xdump.c @@ -1532,8 +1532,6 @@ static int XDiffHelper #endif uint donesize = dumpsize1 > dumpsize2 ? dumpsize1 : dumpsize2; -//DEL fprintf(stderr,">>> %d,%d done=%d, donesize=%d, diffsize=%d\n",size1,size2,done,donesize,diffsize); - #if !OPTIMIZED_SEARCH if ( diffsize > 0 && ( diffsize < xd->bytes_per_line || memcmp(p1,p2,diffsize) )) diff --git a/project/dclib/lib-bmg.c b/project/dclib/lib-bmg.c index 9b7f5fd..b7d0525 100644 --- a/project/dclib/lib-bmg.c +++ b/project/dclib/lib-bmg.c @@ -4286,6 +4286,9 @@ enumError SaveTextFileBMG { MID_X_MESSAGE_BEG, "new messages for CT/LE-CODE" }, { MID_X_MESSAGE_END, 0 }, + { MID_LE_ALT_ARENA_BEG, "LE-CODE: alternative arena names for random slots" }, + { MID_LE_ALT_ARENA_END, 0 }, + { MID_LE_CUP_BEG, "LE-CODE: cup names" }, { MID_LE_CUP_END, 0 }, { MID_LE_TRACK_BEG, "LE-CODE: track names" }, diff --git a/project/dclib/lib-bmg.h b/project/dclib/lib-bmg.h index 636f681..7606b09 100644 --- a/project/dclib/lib-bmg.h +++ b/project/dclib/lib-bmg.h @@ -148,6 +148,9 @@ enum BMG_N_LE_ARENA = BMG_N_ARENA, BMG_LE_FIRST_CTRACK = 0x44, + MID_LE_ALT_ARENA_BEG = 0x6400, // alternate BMG of MID_LE_TRACK_BEG for arenas + MID_LE_ALT_ARENA_END = 0x6480, + MID_LE_CUP_BEG = 0x6800, MID_LE_RCUP_BEG = MID_LE_CUP_BEG, MID_LE_RCUP_END = MID_LE_RCUP_BEG + BMG_N_LE_RCUP, diff --git a/project/dclib/lib-mkw-def.c b/project/dclib/lib-mkw-def.c index 911262e..24489ee 100644 --- a/project/dclib/lib-mkw-def.c +++ b/project/dclib/lib-mkw-def.c @@ -30,105 +30,294 @@ MkwTrackCategory_t * GetMkwTrackCategory ( int id ) static MkwTrackCategory_t id_MTCAT_NINTENDO = { "Original track of Nintendo", + "", + 0x000000, + 0x00eaea, 0, G_MTCAT_NINTENDO, - "", "n", + "n", + 0x10, + 0, + "Nin.", "Nintendo", + "b_cyan", }; static MkwTrackCategory_t id_MTCAT_TEXTURE = { "Accepted texture hack", + "texture,texture2do", + 0x000000, + 0x20ffa0, 0, G_MTCAT_TEXTURE, - "green", "t", + "t", + 0x20, + 0, + "Tex.", "Texture", + "green", }; - static MkwTrackCategory_t id_MTCAT_DENIED = + static MkwTrackCategory_t id_MTCAT_TEMP_ALLOW = + { + "Temporary allowed texture hack", + "temp-allow", + 0x000000, + 0x20ffa0, + 0, + G_MTCAT_TEMP_ALLOW, + "+", + "ta", + 0x20, + 0, + "temp+", + "Temp-Allow", + "green", + }; + + static MkwTrackCategory_t id_MTCAT_TEMP_DENY = + { + "Temporary denied texture hack", + "temp-deny", + 0x000000, + 0xffff00, + 0, + G_MTCAT_TEMP_DENY, + "−", + "td", + 0x20, + 1, + "temp−", + "Temp-Deny", + "b_yellow", + }; + + static MkwTrackCategory_t id_MTCAT_DENY = { "Denied texture hack", + "deny,deny2do", + 0x000000, + 0xffff00, 0, - G_MTCAT_DENIED, - "b_cyan", + G_MTCAT_DENY, "d", - "Denied", + "d", + 0x20, + 2, + "Deny", + "Deny", + "b_yellow", + }; + + static MkwTrackCategory_t id_MTCAT_CHEAT = + { + "Denied texture hack (created to cheat)", + "cheat,cheat2do", + 0xffffff, + 0x800000, + 0, + G_MTCAT_CHEAT, + "â–¼", + "â–¼", + 0x60, + 5, + "Cheat", + "Cheat", + "b_red", }; static MkwTrackCategory_t id_MTCAT_EDIT = { - "Announced as texture hack, but with more edits", + "Track edit", + "edit,edit2do", + 0x000000, + 0xffc830, 0, G_MTCAT_EDIT, - "b_yellow", "e", - "Texture+", + "e", + 0x20, + 3, + "Edit", + "Edit", + "b_orange_yellow", }; static MkwTrackCategory_t id_MTCAT_MODEL = { - "Definitely a model hack", + "Model hack", + "model,model2do,reverse,reverse2do,tiny,tiny2do,colossal,colossal2do,shrink,shrink2do,stretch,stretch2do", + 0x000000, + 0xff8000, 0, G_MTCAT_MODEL, - "b_orange", - "m", + "E", + "E", + 0x20, + 3, + "Model", "Model", + "b_orange", }; - static MkwTrackCategory_t id_MTCAT_UNKNOWN = + static MkwTrackCategory_t id_MTCAT_CHEAT_EDIT = { - "Unknown track", + "Track edit (created to cheat)", + "cheat.edit", + 0xffffff, + 0x800000, 0, - G_MTCAT_UNKNOWN, + G_MTCAT_CHEAT_EDIT, + "â–²", + "â–²", + 0x60, + 5, + "Cht+Ed", + "Cheat+Edit", "b_red", - "u", - "Unknown", }; - static MkwTrackCategory_t id_MTCAT_CHEAT = + static MkwTrackCategory_t id_MTCAT_UNKNOWN = { - "Hack clearly created for cheating", + "Unknown track", + "", + 0x000000, + 0xff80ff, 0, - G_MTCAT_CHEAT, + G_MTCAT_UNKNOWN, + "u", + "u", + 1, + 4, + "Unkn.", + "Unknown", "b_magenta", - "â–¼", - "Cheat", }; static MkwTrackCategory_t id_MTCAT_CUSTOM = { - "Custom track", + "Custom or ported track", + "", + 0x000000, + 0xa0a0ff, 0, G_MTCAT_CUSTOM, - "cyan_blue", - "c", + "C", + "C", + 6, + 4, "Custom", + "Custom", + "cyan_blue", + }; + + static MkwTrackCategory_t id_MTCAT_HNS = + { + "Hide'n'Seek edit", + "hns,hns2do", + 0xffffff, + 0x404040, + 0, + G_MTCAT_HNS, + "h", + "h", + 0x20, + 4, + "H+S", + "Hide+Seek", + "grey5", + }; + + static MkwTrackCategory_t id_MTCAT_HNS_CT = + { + "Custom or ported Hide'n'Seek track", + "hns.ct", + 0xffff00, + 0x000000, + 0, + G_MTCAT_HNS_CT, + "H", + "H", + 4, + 4, + "H+S.ct", + "Hide+Seek.ct", + "grey7", + }; + + static MkwTrackCategory_t id_MTCAT_MISSION = + { + "Mission edit", + "mission,mission2do", + 0xffffff, + 0x404040, + 0, + G_MTCAT_MISSION, + "m", + "m", + 0x20, + 4, + "Mis", + "Mission", + "grey5", + }; + + static MkwTrackCategory_t id_MTCAT_MISSION_CT = + { + "Custom or ported Mission track", + "mission.ct", + 0xffff00, + 0x000000, + 0, + G_MTCAT_MISSION_CT, + "M", + "M", + 4, + 4, + "Mis.ct", + "Mission.ct", + "grey7", }; static MkwTrackCategory_t id_MTCAT__N = { "(invalid)", + "", + 0xffffff, + 0x500050, 0, G_MTCAT__N, - "fail", "?", + "?", + 0, + 4, "-?-", + "(invalid)", + "fail", }; switch(id) { - case G_MTCAT_NINTENDO: return &id_MTCAT_NINTENDO; - case G_MTCAT_TEXTURE: return &id_MTCAT_TEXTURE; - case G_MTCAT_DENIED: return &id_MTCAT_DENIED; - case G_MTCAT_EDIT: return &id_MTCAT_EDIT; - case G_MTCAT_MODEL: return &id_MTCAT_MODEL; - case G_MTCAT_UNKNOWN: return &id_MTCAT_UNKNOWN; - case G_MTCAT_CHEAT: return &id_MTCAT_CHEAT; - case G_MTCAT_CUSTOM: return &id_MTCAT_CUSTOM; - case G_MTCAT__N: return &id_MTCAT__N; - default: return 0; + case G_MTCAT_NINTENDO: return &id_MTCAT_NINTENDO; + case G_MTCAT_TEXTURE: return &id_MTCAT_TEXTURE; + case G_MTCAT_TEMP_ALLOW: return &id_MTCAT_TEMP_ALLOW; + case G_MTCAT_TEMP_DENY: return &id_MTCAT_TEMP_DENY; + case G_MTCAT_DENY: return &id_MTCAT_DENY; + case G_MTCAT_CHEAT: return &id_MTCAT_CHEAT; + case G_MTCAT_EDIT: return &id_MTCAT_EDIT; + case G_MTCAT_MODEL: return &id_MTCAT_MODEL; + case G_MTCAT_CHEAT_EDIT: return &id_MTCAT_CHEAT_EDIT; + case G_MTCAT_UNKNOWN: return &id_MTCAT_UNKNOWN; + case G_MTCAT_CUSTOM: return &id_MTCAT_CUSTOM; + case G_MTCAT_HNS: return &id_MTCAT_HNS; + case G_MTCAT_HNS_CT: return &id_MTCAT_HNS_CT; + case G_MTCAT_MISSION: return &id_MTCAT_MISSION; + case G_MTCAT_MISSION_CT: return &id_MTCAT_MISSION_CT; + case G_MTCAT__N: return &id_MTCAT__N; + default: return 0; }; } diff --git a/project/dclib/lib-mkw-def.h b/project/dclib/lib-mkw-def.h index 1f44c4e..fbda197 100644 --- a/project/dclib/lib-mkw-def.h +++ b/project/dclib/lib-mkw-def.h @@ -36,27 +36,53 @@ typedef enum MkwTrackCategory { G_MTCAT_NINTENDO = 0, G_MTCAT_TEXTURE = 1, - G_MTCAT_DENIED = 2, - G_MTCAT_ORIG_KMP_KCL = 2, - G_MTCAT_EDIT = 3, - G_MTCAT_MODEL = 4, - G_MTCAT_UNKNOWN = 5, + G_MTCAT_TEMP_ALLOW = 2, + G_MTCAT_TEMP_DENY = 3, + G_MTCAT_DENY = 4, + G_MTCAT_DENIED = 5, // [[obsolete]] G_MTCAT_CHEAT = 6, - G_MTCAT_CUSTOM = 7, - G_MTCAT__N = 8, + G_MTCAT_EDIT = 7, + G_MTCAT_MODEL = 8, + G_MTCAT_CHEAT_EDIT = 9, + G_MTCAT_UNKNOWN = 10, + G_MTCAT_CUSTOM = 11, + G_MTCAT_HNS = 12, + G_MTCAT_HNS_CT = 13, + G_MTCAT_MISSION = 14, + G_MTCAT_MISSION_CT = 15, + G_MTCAT__N = 16, } MkwTrackCategory; +// [[MkwTrackCatMode]] +typedef enum MkwTrackCatMode +{ + G_MTCAT_MD_UNKNOWN = 0x01, + G_MTCAT_MD_DEFAULT = 0x02, + G_MTCAT_MD_CUSTOM = 0x04, + G_MTCAT_MD_NINTENDO = 0x10, + G_MTCAT_MD_HACK = 0x20, + G_MTCAT_MD_CHEAT = 0x40, + G_MTCAT_MD__MASK = 0x77, +} +MkwTrackCatMode; +// [[MkwTrackCategory_t]] typedef struct MkwTrackCategory_t { - ccp info; + ccp attribs; + int fg_color; + int bg_color; int color_offset; u8 id; - char color[9+1]; - char ch[3+1]; - char title[8+1]; + char ch1[3+1]; + char ch2[3+1]; + u8 mode; + u8 ban; + char abbrev[7+1]; + char title[12+1]; + char color[15+1]; } MkwTrackCategory_t; diff --git a/project/dclib/lib-mkw.c b/project/dclib/lib-mkw.c index 01bcf9a..a97b8e2 100644 --- a/project/dclib/lib-mkw.c +++ b/project/dclib/lib-mkw.c @@ -1319,6 +1319,39 @@ ccp GetVehicleName4 ( u8 vehicle ) // /////////////////////////////////////////////////////////////////////////////// +/////////////// random slots /////////////// +/////////////////////////////////////////////////////////////////////////////// + +ccp GetLecodeRandomName ( uint slot, ccp return_on_err ) +{ + _Static_assert( MKW_N_LE_RANDOM == 5,"GetLecodeRandomName()"); + static const char name[][6] = { "rTex", "rAll", "rOrig", "rCust", "rNew" }; + return IsLecodeRandom(slot) + ? name[ slot - MKW_LE_RANDOM_BEG ] + : return_on_err; +} + +/////////////////////////////////////////////////////////////////////////////// + +ccp GetLecodeRandomInfo ( uint slot, ccp return_on_err ) +{ + _Static_assert( MKW_N_LE_RANDOM == 5,"GetLecodeRandomInfo()"); + static ccp info[] = + { + "Random: Texture Hacks", + "Random: All Tracks", + "Random: Original Tracks", + "Random: Custom Tracks", + "Random: New Tracks", + }; + + return IsLecodeRandom(slot) + ? info[ slot - MKW_LE_RANDOM_BEG ] + : return_on_err; +} + +// +/////////////////////////////////////////////////////////////////////////////// /////////////// sizeof_info_t: mkw /////////////// /////////////////////////////////////////////////////////////////////////////// // [[sizeof_info_mkw]] diff --git a/project/dclib/lib-mkw.h b/project/dclib/lib-mkw.h index 8a19dbb..5233506 100644 --- a/project/dclib/lib-mkw.h +++ b/project/dclib/lib-mkw.h @@ -91,9 +91,14 @@ enum mkw_consts_t // some constants //--- LE-CODE random tracks - MKW_N_LE_RANDOM = 0x04, - MKW_LE_RANDOM_BEG = 0x3e, - MKW_LE_RANDOM_END = MKW_LE_RANDOM_BEG + MKW_N_LE_RANDOM, + MKW_LE_RANDOM_BEG = 0x3d, + MKW_LE_RANDOM_TEXTURE = MKW_LE_RANDOM_BEG, + MKW_LE_RANDOM_BY_CUP, + MKW_LE_RANDOM_ORIG, + MKW_LE_RANDOM_CUSTOM, + MKW_LE_RANDOM_NEW, + MKW_LE_RANDOM_END, + MKW_N_LE_RANDOM = MKW_LE_RANDOM_END - MKW_LE_RANDOM_BEG, //--- LE-CODE extended slots @@ -110,12 +115,24 @@ enum mkw_consts_t // some constants //----------------------------------------------------------------------------- +ccp GetLecodeRandomName ( uint slot, ccp return_on_err ); +ccp GetLecodeRandomInfo ( uint slot, ccp return_on_err ); + +//----------------------------------------------------------------------------- + static inline bool IsMkwTrack ( uint tid ) { return tid < MKW_TRACK_END; } +static inline bool IsLecodeTrack ( uint tid ) + { return tid < MKW_TRACK_END || tid >= MKW_LE_SLOT_BEG; } + static inline bool IsMkwArena ( uint tid ) { return tid >= MKW_ARENA_BEG && tid < MKW_ARENA_END; } +static inline bool IsMkwArenaOrRandom ( uint tid ) + { return tid >= MKW_ARENA_BEG && tid < MKW_ARENA_END + || tid >= MKW_LE_RANDOM_BEG && tid < MKW_LE_RANDOM_END; } + static inline bool IsMkwOriginal ( uint tid ) { return tid < MKW_ARENA_END; } @@ -130,6 +147,9 @@ static inline bool IsValidLecodeSlot ( uint tid ) || tid >= MKW_LE_SLOT_BEG && tid < MKW_LE_SLOT_END || tid >= MKW_LE_RANDOM_BEG && tid < MKW_LE_RANDOM_END; } +static inline bool IsMkwSpecial ( uint tid ) + { return tid >= MKW_ARENA_END && tid < MKW_LE_SLOT_BEG; } + // /////////////////////////////////////////////////////////////////////////////// /////////////// 24p support /////////////// |
