|
vswprintf implementation (need floating point support) |
Posted on: 2019/8/27 9:10
#1 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@All
I have found 2 vswprintf() implementations which we can use for os4 : one done by Salas00 (in his new unrar port), there is:
#include <wchar.h>
And another one i use since some time done by AROS team, there is:
#include <stdarg.h>
Both of them working, but both of them didn't handle floating point. I.e. there in both realisations no case 'f': code, and because of that , when i want to do something like this: swprintf(tmp, 255, L"triangles:%0.3f mio/s", driver->getPrimitiveCountDrawn(1) * (1.f / 1000000.f)); Then instead of necessary value (which should be 0.xxxx), i have some random/garbage character. Is there anyone who can wrote missing case 'f': in any of those examples ? I assume it will be just copy of case 'd' with some (?) little changes. Checking google for different vsnwprintf() implementations didn't help much at moment. Thanks ! |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/8/28 6:31
#2 |
---|---|---|
Just popping in
![]() ![]() Joined:
2018/3/1 21:08 From italy
Posts: 34
|
Maybe you could convert floats into string and use same vswprintf function.
|
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/8/28 6:45
#3 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@flash
It should be done inside of swprintf()/vsnwprintf() for making porting in future easer, and without needs to touch code which use them. That swprintf() offten need it, and will be good to deal with floating point support in it once and for all. |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/9/2 15:44
#4 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
No one ? Can pay 20-30$
|
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/9/7 15:24
#5 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
I added some basic %F/f support (works with some simple test cases at least): https://www.dropbox.com/s/ppxhbgjg0a68k2e/swprintf.c?dl=0 |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/9/7 18:08
#6 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@salas00
Oh, thanks a bunch, it works as expected ! Donated as promised, thanks again :) |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/9/7 21:24
#7 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
You're welcome, and thanks for the donation. |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/12 22:21
#8 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@salas00
Is by some luck you have fwprintf() realisation for os4 too ? I just have some part like this:
if ( mPriorityStdout <= priority_ )
I currently just replace it on:
if ( mPriorityStdout <= priority_ )
I.e. remove "w" and "L" things. It works, but not sure how rigth is it. Edited by kas1e on 2019/10/12 22:41:15
|
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 16:15
#9 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
Quote:
No, but it shouldn't be too hard to piece it together from the existing code. It is why I kept the code that pushes characters separate from the rest of the function. |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 17:22
#10 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
https://www.dropbox.com/s/w0803hmcch2vnud/libwprintf.7z?dl=0 I made it into a simple static lib so that the common code, which is most of it, can be shared between the functions. If other wprintf functions are needed it should be pretty easy to add them as well. |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 19:32
#11 |
---|---|---|
Home away from home
![]() ![]() Joined:
2006/11/26 21:45 From a dying planet
Posts: 4047
|
@salass00
Sorry for highjacking, but do we have vsnprintf (newlib) yet? |
|
_________________
People are dying. Entire ecosystems are collapsing. We are in the beginning of a mass extinction. And all you can talk about is money and fairytales of eternal economic growth. How dare you! – Greta Thunberg |
||
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 20:23
#12 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@Frederik
Thanks a bunch! Checked library : with gcc it works, with g++ not, saing about undefs. I assume there need some C++ guards as usually inside of libwprinf.h ? Maybe forgotten extern "C" or something ? |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 20:24
#13 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
double post
|
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 20:28
#14 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@Raziel
Quote:
Yes, since ages. I use it in many of my programs. It is one of several functions that is disabled by the __STRICT_ANSI__ define though (I guess because it didn't use to be an ANSI function). |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 20:35
#15 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
Quote:
Change the libwprintf.h header to:
#ifndef LIBWPRINTF_H
and it will work with C++ too. As I code mainly in plain C I tend to forget such things. |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 21:09
#16 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@Salas00
Yeah , works , thanks ! Through what i note, in the log, it add after each string 0x00. I checked on win32, and there is no 0x00 in the output. I.e. not just 0x0a for cariage return , but 0x0a00 |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 21:44
#17 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1800
|
@kas1e
The NUL character is needed for the correct working of the swprintf/vswprintf functions but should not be output for any of the other wprintf functions (as you point out). I've moved the code for outputting the final NUL character to vswprintf where it doesn't interfere any more. This change also made the implementation of the PUTWC() macro simpler. https://www.dropbox.com/s/w0803hmcch2vnud/libwprintf.7z?dl=0 |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2019/10/13 22:19
#18 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@Salas00
Yes, everything fine now, thanks a bunch as usual :) |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 2020/1/6 17:15
#19 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@Salas00
Is vswscanf() fit somehow in the libwprintf.7z's code? I mean is it easy to implement with it, or separate coding required? |
|
|
Re: vswprintf implementation (need floating point support) |
Posted on: 1/8 20:21
#20 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6954
|
@all
While it surely not related to salas00 implementation of swprintf, find out today that I have bugs with some code I tried to port, which have such stuff:
wchar_t w[50], w2[50];
Where "i" is 0,1 or 2 (and it have it for sure, I checked by printf). But then, such a swprintf draw on the screen not "Slot 1" or "Slot 2", but instead "Slot %i". Like it didn't take into account. And I can't be sure, but probably that causes sometimes crashes as well. Is it just bad code of swprintf there? Code done on windows, so everything possible. EDIT: oh, replaced %i on %d and it works! @frederik Didn't we have %i and %I implemented there? And if not, can it be that cause of crashes, or it surely not related ? |
|