diff --git a/src/sys/misc/kernel_string_pool.c b/src/sys/misc/kernel_string_pool.c index ee97900..fa55041 100755 --- a/src/sys/misc/kernel_string_pool.c +++ b/src/sys/misc/kernel_string_pool.c @@ -29,6 +29,7 @@ char * p_curdst; const char * p_cursubstr; + p_curdst = p_dst; p_retval = p_dst + (*p_substr) + 1; p_cursubstr = (const char *) (p_substr + 1); @@ -55,55 +56,120 @@ return p_retval; } +// scans through all substrings until we arrive at the one we want +// returns pointer to the substring +static const BYTEg * FindSubString( const BYTEg * p_substrs, + DWORDg substr_idx ) +{ + DWORDg toskip; + const BYTEg * p_substr; + + p_substr = p_substrs; + toskip = substr_idx; + while( toskip ) + { + p_substr += (*p_substr); + toskip--; + } + + return p_substr; +} + +// p_substr_idx_o <- sub-string index +// returns next BYTE after substring index BYTEs +static const BYTEg * GetSubStringIndex( DWORDg * p_substr_idx_o, + const BYTEg * p_subidxbytes ) +{ + const BYTEg * p_idxbyte; + p_idxbyte = p_subidxbytes; +/* + 'KRNWORD': + - [BYTE] 'key1' + + - if key1 == [0,63]: + - key1 is the index of the 'sub-string' in the pool + + - otherwise + - if key1 has bit 7 set + - [BYTE] 'key2' + - [BYTE] 'key3' + - the index of the 'sub-string' in the pool is: + (key1&0x7F) * 65536 + + key2 * 256 + + key3 + - (index is in [16384,(2^23-1)] + + - otherwise + - [BYTE] 'key2' + - the index of the 'sub-string' in the pool is: + (key1&0x3F) * 256 + + key2 + - (index is in [64,16383]) +*/ + if( (*p_idxbyte) < 64 ) + { + (*p_substr_idx_o) = (DWORDg) (*p_idxbyte); + return p_idxbyte + 1; + } + + if( !( (*p_idxbyte) & (1<<7) ) ) + { + (*p_substr_idx_o) = (DWORDg) (*p_idxbyte); + (*p_substr_idx_o) &= 0x7F; + p_idxbyte++; + (*p_substr_idx_o) <<= 8; + (*p_substr_idx_o) += (DWORDg) (*p_idxbyte); + return p_idxbyte + 1; + } + + (*p_substr_idx_o) = (DWORDg) (*p_idxbyte); + (*p_substr_idx_o) &= 0x3F; + p_idxbyte++; + (*p_substr_idx_o) <<= 8; + (*p_substr_idx_o) += (DWORDg) (*p_idxbyte); + p_idxbyte++; + (*p_substr_idx_o) <<= 8; + (*p_substr_idx_o) += (DWORDg) (*p_idxbyte); + return p_idxbyte + 1; +} + // gets the substring indicated by 'id' from the pool 'p_ksp' into 'p_dst' // - returns pointer to 'p_dst' char * KSTR_POOL_GetString( KSTR_POOL * p_ksp, char * p_dst, DWORDg id ) { - DWORDg numsubstrs; - DWORDg offset; + DWORDg i; + DWORDg substr_idx; char * p_curdst; const BYTEg * p_substr; const BYTEg * p_krnstr; + const BYTEg * p_over_krnstr; - numsubstrs = (id & 0xFF); - offset = (id >> 8); - p_krnstr = p_ksp->p_krnstrs + offset; + // scan through *every* kernel string until we find the one we want + p_krnstr = p_ksp->p_krnstrs; + for( i = 0; i < id; i++ ) + { + p_krnstr += (*p_krnstr); + } - while( numsubstrs ) + // get end of kernel string + p_over_krnstr = (++p_krnstr) + (*p_krnstr); + while( 1 ) { // find substring - offset = (DWORDg) *p_krnstr; - p_krnstr++; - if( offset == 255 ) + p_krnstr = GetSubStringIndex( &substr_idx, p_krnstr ); + p_substr = FindSubString( p_ksp->p_substrs, substr_idx ); + + if( p_krnstr < p_over_krnstr ) { - offset += (((DWORDg) *p_krnstr)<<8); - p_krnstr++; - offset += (DWORDg) *p_krnstr; - p_krnstr++; + // append to destination and also append a space + p_curdst = ReadSubStringAppendSpace( p_curdst, p_substr ); + continue; } - p_substr = p_ksp->p_substrs + p_ksp->p_substr_off[offset]; - // append to destination and also append a space - p_curdst = ReadSubStringAppendSpace( p_curdst, p_substr ); - - // one less sub string - numsubstrs--; + // append to destination + p_curdst = ReadSubString( p_curdst, p_substr ); + break; } - // find final substring - offset = (DWORDg) *p_krnstr; - p_krnstr++; - if( offset == 255 ) - { - offset += (((DWORDg) *p_krnstr)<<8); - p_krnstr++; - offset += (DWORDg) *p_krnstr; - p_krnstr++; - } - p_substr = p_ksp->p_substrs + p_ksp->p_substr_off[offset]; - - // append to destination - p_curdst = ReadSubString( p_curdst, p_substr ); - return p_dst; }