Re: howto recompile dmd 2.053 for CentOS 5.x?

2011-05-25 Thread Lars Holowko
On Tue, May 24, 2011 at 5:30 PM, Nick Sabalausky a@a.a wrote:

 The DMD zips contain all the source code. You should be able to do this:

 - Unzip dmd.2.053.zip (or whatever other version you want)
 - Go into the 'src/dmd' directory
 - Compile dmd (For me, it's just make -f linux.mak, but I'm on a 32/32
 system. I don't know if you'd need another switch for 64-bit...But you say
 you've already compiled dmd from git, so you probably already know :) )
 - Copy the resulting executable to the bin directory: cp ./dmd
 ../../linu/bin(32|64)/

 That should be all you need. I don't *think* you'd need to to recompile
 druntime or phobos (but then, I'm not an expert on DMD's internals). If you
 do end up needing to recompile them, they're right there in th zip, too,
 'src/druntime' and 'src/phobos'. If you do, the just remember to copy the
 resulting libs from the src directory to 'linux/lib(32|64)/'.

 We do really need a better way to compile DMD/DRuntime/Phobos, though. I've
 been meaning to make unix and windows scripts for it, but haven't gotten to
 it yet.



Thanks a lot Nick,

Just recompiling dmd alone and use the rest from the zip archive worked.
(had to remove L--no-warn-search-mismatch from dmd.conf which is not
supported by CentOS' ancient ld). I thought I would need to recompile
everything to match compiler and libraries.

And it really doesn't help that the phobos src in the 2.053.zip does not
compile (vs phobos on git does).

When dmd goes in the next beta round this will be my first test:
  Can I compile everything in the zip file...

But it would be great if we could convince Walter to build dmd on an
older distro like CentOS 5 (or even 4?) instead.

Lars


Re: Get single keystroke?

2011-03-21 Thread Lars Holowko
On Mon, Mar 21, 2011 at 1:33 PM, Sean Eskapp eatingstap...@gmail.com wrote:
 Is there a way to get a single keystroke in D2? Any method I've tried requires
 pushing Enter before the stroke is registered.


Hi Sean,

what you want to do is OS dependent.

I needed something similar ('press key to continue')

e.g.: for Windows

import core.sys.windows.windows;

bool kbHit() {
// inspired by
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686id=1043284392
HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD saveMode;

GetConsoleMode(stdIn, saveMode);
SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT);

bool ret = false;

if (WaitForSingleObject(stdIn, INFINITE) == WAIT_OBJECT_0) {
uint num;
char ch;

ReadConsoleA(stdIn, ch, 1, num, cast(void *) 0L);
ret = true;
}

SetConsoleMode(stdIn, saveMode);
return ret;
}

void wait_for_key() {
writeln(\nPress any key to continue);
while (!kbHit())
{}
}


for Linux/Unix something like
http://www.linuxquestions.org/questions/programming-9/kbhit-34027/
should work.

Hope that helps,

Lars


How-to manipulate a C array with D2 vector operations?

2011-02-28 Thread Lars Holowko
Hi

I am trying to implement a D2 function that has this C signature (it
gets called from a C module and I cannot change the caller):

extern(C) read_into(char *buffer, size_t buf_len);

I would like to use D's vector (or array-wise according to TDPL)
operations on buffer but I cannot find a way, how I could initialize a
(static?) D array and tell it to use buffer as its memory. Obviously I
don't want to copy buffer in a regular D array to be able to do the
manipulations and than having to copy everything back into buffer.

Is there any way to get this accomplished?


Thanks,

Lars


Re: How-to manipulate a C array with D2 vector operations?

2011-02-28 Thread Lars Holowko

On 2/28/2011 10:15 AM, Denis Koroskin wrote:

On Mon, 28 Feb 2011 19:51:28 +0300, Lars Holowko
lars.holo...@gmail.com wrote:


gets called from a C module and I cannot change the caller):

extern(C) read_into(char *buffer, size_t buf_len);

I would like to use D's vector (or array-wise according to TDPL)
operations on buffer but I cannot find a way, how I could initialize a
(static?) D array and tell it to use buffer as its memory. Obviously I


Here you go:

auto arr = buffer[0..buf_len];

Now you can operate on this array however you like. E.g.

arr[] = 0; // initialize with zeros


Thanks Denis and Trass3r,

that was embarrasingly easy ;-)