int fb_DevFileWriteEncodWstr( FB_FILE *handle, const FB_WCHAR* buffer, size_t chars ) { FILE *fp; char *encod_buffer; ssize_t bytes; FB_LOCK(); fp = (FILE*) handle->opaque; if( fp == NULL ) { FB_UNLOCK(); return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ); } /* convert (note: only wstrings will be written using this function, so there's no binary data to care) */ encod_buffer = fb_WCharToUTF( handle->encod, buffer, chars, NULL, &bytes ); if( encod_buffer != NULL ) { /* do write */ if( fwrite( encod_buffer, 1, bytes, fp ) != (size_t)bytes ) { FB_UNLOCK(); return fb_ErrorSetNum( FB_RTERROR_FILEIO ); } if( encod_buffer != (char *)buffer ) free( encod_buffer ); } FB_UNLOCK(); return fb_ErrorSetNum( FB_RTERROR_OK ); }
void fb_ConsolePrintBufferWstrEx( const FB_WCHAR *buffer, size_t chars, int mask ) { size_t avail, avail_len; char *temp; if( !__fb_con.inited ) { /* !!!FIXME!!! is this ok or should it be converted to UTF-8 too? */ fwrite( buffer, sizeof( FB_WCHAR ), chars, stdout ); fflush( stdout ); return; } temp = alloca( chars * 4 + 1 ); /* ToDo: handle scrolling for internal characters/attributes buffer? */ avail = (__fb_con.w * __fb_con.h) - (((__fb_con.cur_y - 1) * __fb_con.w) + __fb_con.cur_x - 1); avail_len = chars; if (avail < avail_len) avail_len = avail; /* !!!FIXME!!! to support unicode the char_buffer would have to be a wchar_t, slowing down non-unicode printing.. */ fb_wstr_ConvToA( temp, buffer, avail_len ); memcpy( __fb_con.char_buffer + ((__fb_con.cur_y - 1) * __fb_con.w) + __fb_con.cur_x - 1, temp, avail_len ); memset( __fb_con.attr_buffer + ((__fb_con.cur_y - 1) * __fb_con.w) + __fb_con.cur_x - 1, __fb_con.fg_color | (__fb_con.bg_color << 4), avail_len ); /* convert wchar_t to UTF-8 */ int bytes; fb_WCharToUTF( FB_FILE_ENCOD_UTF8, buffer, chars, temp, &bytes ); /* add null-term */ temp[bytes] = '\0'; fputs( ENTER_UTF8, stdout ); fputs( temp, stdout ); fputs( EXIT_UTF8, stdout ); /* update x and y coordinates.. */ for( ; chars; chars--, buffer++ ) { ++__fb_con.cur_x; if( (*buffer == _LC('\n')) || (__fb_con.cur_x >= __fb_con.w) ) { __fb_con.cur_x = 1; ++__fb_con.cur_y; if( __fb_con.cur_y > __fb_con.h ) __fb_con.cur_y = __fb_con.h; } } fflush( stdout ); }