Re: Getting environment variables?

2013-05-02 Thread Mark Fischer

Better late than never...

On Sunday, 23 November 2008 at 02:28:30 UTC, Christopher Wright
wrote:
...
I thought (perhaps wrongly) C allowed you to declare main as 
taking a list of environment variables, which is why I asked


Indeed, on Unix { not POSIX } and Windows:

From Wiki:
==
Other platform-dependent formats are also allowed by the C and
C++ standards, except that in C++ the return type must always be
int;[3] for example, Unix (though not POSIX.1) and Microsoft
Windows have a third argument giving the program's environment,
otherwise accessible through getenv in stdlib.h:

int main(int argc, char **argv, char **envp);

Mac OS X and Darwin have a fourth parameter containing arbitrary
OS-supplied information, such as the path to the executing
binary:[4]
==

Mark



Re: Getting environment variables?

2008-11-24 Thread Denis Koroskin
On Mon, 24 Nov 2008 16:53:20 +0300, Christopher Wright  
[EMAIL PROTECTED] wrote:



John C wrote:

novice2 Wrote:


i am afraid that windows API named *W works with UCS2 string.
but D wchar[] is UTF-16.

 Wrong - Windows has used UTF-16 as native since Windows 2000.


Actually, you're both right. UCS2 is UTF-16.


No. A quote from Wikipedia:

Because of the technical similarities and upwards compatibility from  
UCS-2 to UTF-16, the two encodings are often erroneously conflated and  
used as if interchangeable, so that strings encoded in UTF-16 are  
sometimes misidentified as being encoded in UCS-2.


UTF-16 is the native internal representation of text in the Microsoft  
Windows 2000/XP/2003/Vista/CE; Qualcomm BREW operating systems; the Java  
and .NET bytecode environments; Mac OS X's Cocoa and Core Foundation  
frameworks; and the Qt cross-platform graphical widget toolkit.


Older Windows NT systems (prior to Windows 2000) only support UCS-2.


Re: Getting environment variables?

2008-11-23 Thread novice2
 homeDrive = toString(getenv(HOMEDRIVE)).dup;
 homePath = toString(getenv(HOMEPATH)).dup;

don't forget, that D char[] is utf8 and windows char* is 8-bit chars, not utf8.
so you should import std.windows.charset and use toMBSz() as D-WindowsAPI and 
fromMBSz as WindowsAPI-D string converter. for example:
homeDrive = fromMBSz(getenv(HOMEDRIVE)).dup;


Re: Getting environment variables?

2008-11-23 Thread torhu

Christopher Wright wrote:

Hey all,

How do I get environment variables in a D program? I specifically want 
the path to a user's home folder.


Ta muchly.


I think the 'correct' way on Windows is to use SHGetSpecialFolderPathA.

Something like this:

char[MAX_PATH] buf;
SHGetSpecialFolderPathA(null, buf.ptr, CSIDL_PERSONAL, false);
char[] dir = toString(buf.ptr);

or CSIDL_APPDATA, etc.


Re: Getting environment variables?

2008-11-23 Thread Lars Ivar Igesund
torhu wrote:

 Christopher Wright wrote:
 Hey all,
 
 How do I get environment variables in a D program? I specifically want
 the path to a user's home folder.
 
 Ta muchly.
 
 I think the 'correct' way on Windows is to use SHGetSpecialFolderPathA.
 
 Something like this:
 
 char[MAX_PATH] buf;
 SHGetSpecialFolderPathA(null, buf.ptr, CSIDL_PERSONAL, false);
 char[] dir = toString(buf.ptr);
 
 or CSIDL_APPDATA, etc.

In tango this is available in tango.sys.win32.SpecialPath

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango  #D: larsivi
Dancing the Tango


Getting environment variables?

2008-11-22 Thread Christopher Wright

Hey all,

How do I get environment variables in a D program? I specifically want 
the path to a user's home folder.


Ta muchly.


Re: Getting environment variables?

2008-11-22 Thread Jarrett Billingsley
On Sat, Nov 22, 2008 at 12:55 PM, Christopher Wright [EMAIL PROTECTED] wrote:
 Hey all,

 How do I get environment variables in a D program? I specifically want the
 path to a user's home folder.

 Ta muchly.


In Tango, there's tango.sys.Environment
(http://www.dsource.org/projects/tango/docs/current/tango.sys.Environment.html)
which provides a nice interface to environment variables.

In Phobos, I think you have to use the C functions to get at
environment variables, but std.path.expandTilde can be abused to get
the home folder ;)


Re: Getting environment variables?

2008-11-22 Thread BCS

Reply to Christopher,


I thought (perhaps wrongly) C allowed you to declare main as taking a
list of environment variables,


It does.