[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: PCB Gtk port



I did not provide solution for this problem so it is not quite right
for me to suggest anything but I would like to share my point of
view. I think that file formats do not really need to be "locale
correct", and in my opinion it is risky to allow commas and dots as
decimal separator since now spaces in some places become mandatory.

12.34  (float)
12,34  (maybe float, maybe two ints)
12, 34 (two ints, space needed)

What do you think?

> On Tue, 8 Mar 2005 00:45:38 +0100 (CET)
> Tomasz Motylewski <T.Motylewski@xxxxxxx> wrote:
> 
> > > When editing and saving it takes into account locale.
> > > When reading files it doesn't.
> > > The effect: if you have decimal separator other than '.' (dot)
you can
> > > save but you cannot load what you saved.
> > >
> > > Am I right?
> > 
> > Most probably yes. I had once reverse problem in gerbv - '.' was
saved but in
> > many locales sscanf("%f"...) was insisting on having ','.
> > 
> > Fixed by setlocale(LC_NUMERIC, "C" ) in the affected function
(parse_pnp()).
> > Because of some GTK magic calling it at the beginning of main()
did not work.
> > 
> > If this is not the proper solution, I would be delighted to hear
what is.
> 
> If you call setlocale(LC_NUMERIC, "C") at the beginning of main,
you then
> also have to call gtk_disable_setlocale() before gtk_init() to
prevent Gtk
> from undoing your LC_NUMERIC setting.
> 
> For example:
> 
>     /* Do our own setlocale() stufff since we want to override
LC_NUMERIC
>     */
>     gtk_set_locale();
>     setlocale(LC_NUMERIC, "POSIX");  /* use decimal point instead
of comma, use "C" or "POSIX" */
> 
>     /* Prevent gtk_init() and gtk_init_check() from automatically
>     | calling setlocale (LC_ALL, "") which would undo our LC_NUMERIC.
>     */
>     gtk_disable_setlocale();
> 
>     gtk_init(argc, argv);
> 
> But in the case of pcb-gtk I think it's that the lex parser is not
set up
> to accept commas for decimal points and fixing that should get things
> working for both '.' and ',' locales.  I've just uploaded a new
tarball:
> 
>     http://members.dslextreme.com/users/billw/test/pcb-gtk.tar.gz
> 
> or you can try this patch on the source you've got:
> 
> --- parse_l.l.orig	2005-03-07 18:59:17.000000000 -0600
> +++ parse_l.l	2005-03-07 18:59:42.000000000 -0600
> @@ -89,7 +89,7 @@ static	int		Parse(char *, char *, char *
>  
>  HEX				0x[0-9a-fA-F]+
>  DECIMAL			-?[1-9][0-9]*|0
> -FLOATING                -?[0-9]*"."[0-9]*
> +FLOATING                -?[0-9]*["."","][0-9]*
>  CARDINAL		[1-9][0-9]*|0
>  STRINGCHAR		([^"\n\r\\]|\\\\|\\\")
>  
> 
> Bill
> 
>