Some of you will remember that I said I would move onto producing FPNs from text some days ago, well in aid of that I needed to backtrack the position of the source data on ocassion with the method I had originally chosen, but on stdin I ended up with errors, they may have been a result of faulty code elsewhere but I decided that to ensure it wasn't from my library code it was high time I cleaned it up and make it more suitable for sharing, I got most of that done but then hit a glitch somewhere in the backend function I'm working on now, the glitch resulted in output like this:
Code:
make word.run
cc -fPIC -Wall -Wno-multichar -shared -o ./libmcc_mem.so -c mcc_mem.c
cc -fPIC -Wall -Wno-multichar -shared -o ./libmcc_get.so -c mcc_get.c
cc -fPIC -Wall -Wno-multichar -shared -o ./libmcc_tsc.so -c mcc_tsc.c
cc -fPIC -Wall -Wno-multichar -shared -o ./libmcc_base62.so -c mcc_base62.c
cc -fPIC -Wall -Wno-multichar -D OUT=word.elf -o ./word.elf word.c ./libmcc_mem.so ./libmcc_get.so ./libmcc_tsc.so ./libmcc_base62.so
./word.elf
'Text': 'Testing,' ' testing' ', 123'
'Text': 'Te' 'st' 'in' 'g,' ' t' 'es' 'ti' 'ng' ', ' '12' '3'
'Word/s': '������'
'Word/s': 'T'
rm libmcc_get.so word.elf libmcc_tsc.so libmcc_mem.so libmcc_base62.so
Compilation finished successfully.
Using this code:
Code:
int mcc___getword( void *src, MCC_CH8 *dst,
mcc_char_info_t mcc_char_info,
func_mcc__read _read, func_mcc__last _last )
{
int ret;
intmax_t c = 0;
char *cb, *more;
mcc_ch8_t ch8;
MCC_VEC *dstv;
MCC_MEM *dstm;
MCC_ICONV_TOK tok;
MCC_ICONV_MEM nil = {0};
size_t read, size;
long leng;
if ( !dst ) return EDESTADDRREQ;
dstv = &(dst->vec);
dstm = &(dstv->mem);
if ( !_read || !_last ) return EDESTADDRREQ;
if ( !src || _last(src) )
return ENODATA;
if ( (ret = mcc_char_info_test(mcc_char_info)) != EXIT_SUCCESS )
return ret;
ch8 = 0;
cb = (char*)&c;
more = &cb[mcc_char_info.size];
tok = mcc_iconv_new_tok( mcc_char_info.ch8dst );
/* Permits appending to existing text */
tok.dst.done = dstv->use * sizeof(mcc_ch8_t);
tok.dst = mcc_iconv_tok_mem( tok.dst, dstm->addr, dstm->size );
while ( ch8 != U' ' ) {
/* Avoid the need to reset position by allocating memory 1st */
if ( tok.dst.left <= sizeof(mcc_utf_t) ) {
ret = mcc_vecsize( dstv, dstm->size + MCC_BUFSIZ, sizeof(mcc_ch8_t) );
if ( ret != EXIT_SUCCESS ) break;
tok.dst = mcc_iconv_tok_mem( tok.dst, dstm->addr, dstm->size );
}
/* _read() is not expected to overwrite all bytes */
c = 0;
read = _read( cb, mcc_char_info.size, 1, src );
/* Check if any more characters are expected */
leng = mcc_char_info.cleng(&c);
if ( leng > 1 ) {
size = (mcc_char_info.size * leng);
if ( size )
read += _read( more, mcc_char_info.size, leng - 1, src );
}
else {
leng = 1;
size = mcc_char_info.size;
}
if ( mcc_char_info.enc == mcc_encoding_ch8 ) {
/* Quicken the pace */
(void)memcpy( tok.dst.addr, cb, size );
tok.dst.done += size;
tok.dst.left -= size;
tok.dst.addr += size;
}
else {
/* Reset positon info like this */
tok.src = mcc_iconv_tok_mem( nil, cb, sizeof(intmax_t) );
ret = mcc_iconv( &tok );
}
ch8 = read ? *((mcc_ch8_t*)(tok.dst.addr)) : U' ';
/* Faster than calling another function */
switch ( ch8 ) {
case U'\f': case U'\v':
case U'\n': case U'\r':
case U'\t': ch8 = U' ';
}
if ( read != size ) break;
if ( ret != EXIT_SUCCESS ) break;
}
dstv->use = tok.dst.done / sizeof(mcc_ch8_t);
return ret;
}
Both use the same functions and source string so I know the source of the corruption lies somewhere in this code, I figure fresh eyes might spot what I haven't so for now I'll take a break and come back to this after some light entertainment, any help will be welcome.
Edit: Noticed I was still using an enum value to check for space in the while condition, corrected that but text was still curropted which is no surprise as that was only an exit condition