After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 329548 - Add G_OPTION_ARG_DOUBLE
Add G_OPTION_ARG_DOUBLE
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 336083 (view as bug list)
Depends on:
Blocks: 336090
 
 
Reported: 2006-02-02 01:32 UTC by Behdad Esfahbod
Modified: 2011-02-18 15:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch against cvs head with cvs diff up (5.73 KB, patch)
2006-02-03 21:45 UTC, Antoine Dopffer
none Details | Review
Patch that does what Matthias requested (6.62 KB, patch)
2006-03-26 18:58 UTC, Dominic Lachowicz
none Details | Review

Description Behdad Esfahbod 2006-02-02 01:32:18 UTC
That would be useful I guess.
Comment 1 Behdad Esfahbod 2006-02-02 01:36:32 UTC
Marking for love.  Needs docs too.
Comment 2 Antoine Dopffer 2006-02-02 18:05:44 UTC
Hello,

I think I can do the hack, but I have a few questions.
1) Should this option expect  both locale formatted and C formatted numbers ?

2) Should we use strtod, g_strtod or g_ascii_strtod  to convert the string to double ?

3) Does the position of  G_OPTION_ARG_DOUBLE in GOptionArg enum matter ?

4) My english isn't very good, but I am willing to change the docs. Is docs/reference/glib/tmpl/option.sgml the only file to change ?

Cordially
Comment 3 Matthias Clasen 2006-02-03 18:53:53 UTC
1) no, imo
2) g_ascii_strtod()
3) yes, because the existing values get compiled into GOption-using apps.
  you need to append at the end
4) yes, since you are only adding an enum value to the api (function docs live in the c source next to the function)
Comment 4 Antoine Dopffer 2006-02-03 21:45:49 UTC
Created attachment 58675 [details] [review]
patch against cvs head with cvs diff up

Hello,

this patch should do the job.
The double argument must be a C formatted number.
I have add a test  in option-test.c for double argument parsing.
It has succeed, but I am ready to add other tests if necessary.

Have a nice day.
Comment 5 Matthias Clasen 2006-03-26 14:46:09 UTC
*** Bug 336083 has been marked as a duplicate of this bug. ***
Comment 6 Dominic Lachowicz 2006-03-26 14:53:27 UTC
Matthias - question for you. I was wondering if strtod() would be more appropriate here, since the command-line represents a UI of sorts. Since the shell/command line syntax is the UI, shouldn't the number be formatted according to the user's locale? Thanks.
Comment 7 Matthias Clasen 2006-03-26 16:06:02 UTC
Don't know, really. 

I have very little experience with entering localized floats on the commandline.
If we use strtod(), we introduce a locale-dependence in goption which wasn't 
there before, so we will have to add some documentation about calling or not
calling setlocale() before using the goption api. 

I could be convinced otherwise though. Maybe the right approach is to use
g_strtod() here, which first tries strtod() and then g_ascii_strtod()
Comment 8 Dominic Lachowicz 2006-03-26 16:40:55 UTC
I whole-heartedly endorse using g_strtod() then. Is it ok to commit this patch to HEAD once that's in place?
Comment 9 Matthias Clasen 2006-03-26 17:09:47 UTC
yes. it would be nice to add a test for parsing localized floats,
and maybe the docs should mention it too. if you want to do that,
feel free to commit it. otherwise, i'll look into it tomorrow.
Comment 10 Dominic Lachowicz 2006-03-26 18:58:07 UTC
Created attachment 62059 [details] [review]
Patch that does what Matthias requested

I'm a bit hesitant about test5(), since we can't be sure that the tester has a non-ASCII locale to switch to, or what locale that might be. For the moment, it's commented out. But everything else should be implemented as-requested. I'll let you decide what's best. Thanks.
Comment 11 Matthias Clasen 2006-03-27 04:44:13 UTC
Using the "de" locale in a test is fine with me. We already have some
tests which can fail if certain locales/encodings are not available. 
And the only time when the tests really have to pass is when I am doing
a release.
Comment 12 Matthias Clasen 2006-03-27 06:57:46 UTC
2006-03-27  Matthias Clasen  <mclasen@redhat.com>

        Add support for floating point numbers to goption.
        (#329548, Behdad Esfahbod, patch by Antoine Dopffer and
         Dom Lachowicz)

        * glib/goption.h:
        * glib/goption.c: Support double arguments.

        * tests/option-test.c: Test double arguments.`

Comment 13 Dominic Lachowicz 2006-03-27 13:34:06 UTC
2006-03-27  Dom Lachowicz  <cinamod@hotmail.com>

	* tests/option-test.c: Copy-and-paste error slipped into test5. Enable
	test5, as per Matthias' comments in bug 329548#c11.