www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - bug in command line arguments parsing?

reply novice2 <novice2_member pathlink.com> writes:
hello!
i use dmd 0.127 under Windows XP.
i need analyse command lime parameters in my program.
i use main() parameters char[][] args for this.
but it seems it not works with non-english letters.
Test program:

///// test.d /////
void main(char[][] args)
{
int len1 = args[1].length;
int len2 = args[2].length;
int len3 = args[3].length;
printf("len1=%d, len2=%d, len3=%d", len1, len2, len3);
}
////////

When i run it as
test.exe param1 param2 param3

then it print to console
len1=6, len2=6, len3=6


When i replace word "param" by national letters (same length)
test.exe парам1 парам2 парам3

then it print to console
len1=1, len2=6, len3=6

First parameter length wrong :(
Is it bug?
Jul 10 2005
next sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
novice2 <novice2_member pathlink.com> wrote:

[...]
 First parameter length wrong :(
 Is it bug?
Seems to be a bug in the parameter handling by dmc: first non-ascii sequence of characters is suppressed. gcc does not have this problem. -manfred
Jul 10 2005
prev sibling parent reply Vathix <chris dprogramming.com> writes:
On Sun, 10 Jul 2005 07:09:21 -0400, novice2 <novice2_member pathlink.com>  
wrote:

 hello!
 i use dmd 0.127 under Windows XP.
 i need analyse command lime parameters in my program.
 i use main() parameters char[][] args for this.
 but it seems it not works with non-english letters.
Currently, D expects everyone to set their terminal to UTF-8. I've complained about this before because there appears to be an easy solution. If D would just use GetCommandLineW(), which IS supported on win9x/me and NT, and convert it to UTF-8, Windows would convert from the current charset. While this solution would make main(args[]) happy, you'd need to set your terminal to UTF-8 in order to writef() correctly, but that's not such a big deal because it won't result in an exception.
Jul 10 2005
next sibling parent novice2 <novice2_member pathlink.com> writes:
While this solution would make main(args[]) happy, you'd need to set your  
terminal to UTF-8 in order to writef() correctly, but that's not such a  
big deal because it won't result in an exception.
Again and again :( Every time i use user input or works with filenames in D i realize, that default UTF-8 strings - big pain (for me at least). In Delphi i have not any problems with non-english letters, excsept oem<->ansi conversion.
Jul 11 2005
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Vathix wrote:
 On Sun, 10 Jul 2005 07:09:21 -0400, novice2 
 <novice2_member pathlink.com>  wrote:
 
 hello!
 i use dmd 0.127 under Windows XP.
 i need analyse command lime parameters in my program.
 i use main() parameters char[][] args for this.
 but it seems it not works with non-english letters.
Currently, D expects everyone to set their terminal to UTF-8. I've complained about this before because there appears to be an easy solution. If D would just use GetCommandLineW(), which IS supported on win9x/me and NT, and convert it to UTF-8, Windows would convert from the current charset.
This would enable Win9x apps to use Unicode command lines, but since Win9x DOS windows can't use UTF-8, it would break the hello.d example. Nonetheless, I've started working on something to this effect....
 While this solution would make main(args[]) happy, you'd need to set 
 your terminal to UTF-8 in order to writef() correctly, but that's not 
 such a big deal because it won't result in an exception.
How does the Windows XP "terminal" work? Is it somehow different from an MS-DOS window under Win9x, such that it makes sense to use UTF-8 with it? Moreover, can console apps under XP auto-detect the terminal encoding? And can it be done in such a way that the app will work under 9x as well? We ought to have an I/O system that supports different encodings. See my little conversation with Uwe Salomon starting here: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.announce/906 Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 11 2005
parent reply "Uwe Salomon" <post uwesalomon.de> writes:
 We ought to have an I/O system that supports different encodings.  See  
 my little conversation with Uwe Salomon starting here:

 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.announce/906
By the way, did you already decide if you want to work on a TextStream? Just curious... :) Ciao uwe
Jul 11 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Uwe Salomon wrote:
 We ought to have an I/O system that supports different encodings.  
 See my little conversation with Uwe Salomon starting here:

 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.announce/906
By the way, did you already decide if you want to work on a TextStream? Just curious... :)
Sorry, I was away for the weekend, and so haven't had much time to look at the possibility. But I will soon. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 12 2005