www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Dynamic rectangular arrays

reply Kevin M <Kevin_member pathlink.com> writes:
Hello, can someone help me with the following issue regarding dynamic
"rectangular arrays"? Thanks.

-Porting some C code to D.
-The C code allocates, deletes, and resizes a multi-dimensional character array
using malloc/free.
-Don't want to use malloc/free.
-How do I create the array Buffer[][] as dynamic, and set its length?
(ie. Buffer.length = cxBuffer; //obviously won't work)
-If Buffer[][] needs to be deleted and resized, how is this done)? Will
new/delete work, if so how?
-cxBuffer, cyBuffer, and Buffer must be static. They must keep their values when
the function exits.

Kevin M

----------------------------
some_function()
{
int         x, y;
static int  cxBuffer, cyBuffer;

//Initialize cxBuffer and cyBuffer
..

//Create Buffer[][]
static char Buffer[cxBuffer][cyBuffer];

//Initialize Buffer
for (y = 0 ; y < cyBuffer ; y++)
for (x = 0 ; x < cxBuffer ; x++)
Buffer[x][y] = ' ';
}
----------------------------
Mar 03 2005
next sibling parent Derek Parnell <derek psych.ward> writes:
On Fri, 4 Mar 2005 00:07:51 +0000 (UTC), Kevin M wrote:

 Hello, can someone help me with the following issue regarding dynamic
 "rectangular arrays"? Thanks.
 
 -Porting some C code to D.
 -The C code allocates, deletes, and resizes a multi-dimensional character array
 using malloc/free.
 -Don't want to use malloc/free.
 -How do I create the array Buffer[][] as dynamic, and set its length?
 (ie. Buffer.length = cxBuffer; //obviously won't work)
 -If Buffer[][] needs to be deleted and resized, how is this done)? Will
 new/delete work, if so how?
 -cxBuffer, cyBuffer, and Buffer must be static. They must keep their values
when
 the function exits.
 
 Kevin M
 
 ----------------------------
 some_function()
 {
 int         x, y;
 static int  cxBuffer, cyBuffer;
 
 //Initialize cxBuffer and cyBuffer
 ..
 
 //Create Buffer[][]
 static char Buffer[cxBuffer][cyBuffer];
 
 //Initialize Buffer
 for (y = 0 ; y < cyBuffer ; y++)
 for (x = 0 ; x < cxBuffer ; x++)
 Buffer[x][y] = ' ';
 }
 ----------------------------
Here some code that seems to do the job ... <code> import std.stdio; void some_function(char pTest) { int x, y; static int cxBuffer, cyBuffer; static char[][] Buffer; if (pTest == '\0') { //Initialize cxBuffer and cyBuffer cxBuffer = 40; cyBuffer = 23; //Create Buffer[][] Buffer.length = cyBuffer; foreach( inout char[] B; Buffer) { B.length = cxBuffer; B[0..length] = ' '; } } else { foreach( inout char[] B; Buffer) { B[0..length] = pTest; } } // Show it's current contents foreach(int iLine, char[] Line; Buffer) { std.stdio.writef("[%2d] '", iLine); foreach(char c; Line) std.stdio.putchar(c); std.stdio.puts("'\n"); } } void main() { char x; some_function('\0'); x = getchar(); some_function(x); } </code> -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ 4/03/2005 11:27:10 AM
Mar 03 2005
prev sibling next sibling parent reply Kevin M <Kevin_member pathlink.com> writes:
Here is the actual code, which makes it clearer what I am trying to do with
Buffer[][]. Currently Buffer[200][200] is static, but I want it to be dynamic,
so I can use Buffer[cxBuffer][cyBuffer] instead.

Kevin M

<code>
/*--------------------------------------
TYPER.D -- Typing Program
(c) Charles Petzold, 1998
--------------------------------------*/

// Translated to D Language by Kevin M 3-Mar-2005
//
// ($Revision: 1.7 $)
//
// To compile: dmd typer.d gdi32.lib
//
// Compiler requires win32.def:
//   EXETYPE NT
//   SUBSYSTEM WINDOWS
//
// (user32.lib, winuser.h):
// ------------------------
//   BeginPaint(), CreateCaret(), CreateWindowA()?, DefWindowProcA(),
//   DestroyCaret(), DispatchMessageA(), EndPaint(), GetDC(), GetFocus(),
/
/   GetMessageA(), HideCaret(), InvalidateRect(), LoadCursorA(), LoadIconA(),
//   MessageBoxA(), PostQuitMessage(), RegisterClassA(), ReleaseDC(),
//   SendMessageA(), SetCaretPos(), ShowCaret(), ShowWindow(),
//   TranslateMessage(), UpdateWindow()
//
// (gdi32.lib, wingdi.h):
// ----------------------
//   CreateFontA(), DeleteObject(), GetStockObject(), GetTextMetricsA(),
//   SelectObject(), TextOutA()
//
// (kernel32.lib, winbase.h):
// --------------------------
//   None
//
// (windows.d, windef.h macro):
// ----------------------------
//   HIWORD(), LOWORD()
//

import std.c.windows.windows;
//import std.c.stdlib;          // free(), malloc()

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
int result;

gc_init();                  // initialize garbage collector
_minit();                   // initialize module constructor table

try
{
_moduleCtor();          // call module constructors
_moduleUnitTests();     // run unit tests (optional)

result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}

catch (Object o)            // catch any uncaught exceptions
{
MessageBoxA(cast(HWND) null, cast(char *)o.toString(), "Error",
MB_OK | MB_ICONEXCLAMATION);
result = 0;             // failed
}

gc_term();                  // run finalizers; terminate garbage collector
return result;
}

// ************************************************************

//Win32 API header entries missing in C:\dmd\src\phobos\std\c\windows\windows.d
alias char TCHAR;

int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }

int myWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR[] szAppName = "Typer" ;
HWND           hwnd ;
MSG            msg ;
WNDCLASS       wndclass ;

wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc   = &WndProc ;
wndclass.cbClsExtra    = 0 ;
wndclass.cbWndExtra    = 0 ;
wndclass.hInstance     = hInstance ;
wndclass.hIcon         = LoadIconA (cast(HINSTANCE) null, IDI_APPLICATION) ;
wndclass.hCursor       = LoadCursorA (cast(HINSTANCE) null, IDC_ARROW) ;
wndclass.hbrBackground = cast(HBRUSH) (GetStockObject (WHITE_BRUSH)) ;
wndclass.lpszMenuName  = cast(LPCSTR) null ;
wndclass.lpszClassName = szAppName ;

if (!RegisterClassA (&wndclass))
{
MessageBoxA (cast(HWND) null, "This program requires Windows NT!",
szAppName, MB_ICONERROR) ;
return 0 ;
}

hwnd = CreateWindowA (szAppName,                  // window class name
"Typing Program",           // window caption
WS_OVERLAPPEDWINDOW,        // window style
CW_USEDEFAULT,              // initial x position
CW_USEDEFAULT,              // initial y position
CW_USEDEFAULT,              // initial x size
CW_USEDEFAULT,              // initial y size
cast(HWND) null,            // parent window handle
cast(HMENU) null,           // window menu handle
hInstance,                  // prog. instance handle
null) ;                     // creation parameters

assert(hwnd);

ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;

while (GetMessageA (&msg, cast(HWND) null, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessageA (&msg) ;
}
return msg.wParam ;
}

// #define BUFFER(x,y) *(pBuffer + y * cxBuffer + x)

extern (Windows)
int WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static DWORD   dwCharSet = DEFAULT_CHARSET ;
static int     cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,
xCaret, yCaret ;
//static TCHAR*  pBuffer = null ;
static TCHAR   BUFFER[200][200] ;  // replaces macro BUFFER
HDC            hdc ;
int            x, y, i ;
PAINTSTRUCT    ps ;
TEXTMETRICA    tm ;

switch (message)
{
case WM_INPUTLANGCHANGE:
dwCharSet = wParam ;
// fall through
case WM_CREATE:
hdc = GetDC (hwnd) ;
SelectObject (hdc, CreateFontA (0, 0, 0, 0, 0, 0, 0, 0,
dwCharSet, 0, 0, 0, FIXED_PITCH, cast(LPCSTR) null)) ;

GetTextMetricsA (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight ;

DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
ReleaseDC (hwnd, hdc) ;
// fall through
case WM_SIZE:
// obtain window size in pixels

if (message == WM_SIZE)
{
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
}
// calculate window size in characters

cxBuffer = max (1, cxClient / cxChar) ;
cyBuffer = max (1, cyClient / cyChar) ;

// allocate memory for buffer and clear it

//if (pBuffer != null)
//     free (pBuffer) ;

//pBuffer = cast(TCHAR*) malloc (cxBuffer * cyBuffer * TCHAR.sizeof) ;

//for (y = 0 ; y < cyBuffer ; y++)
//     for (x = 0 ; x < cxBuffer ; x++)
//          BUFFER[x][y] = ' ' ;

for (y = 0 ; y < 200 ; y++)
for (x = 0 ; x < 200 ; x++)
BUFFER[x][y] = ' ' ;

// set caret to upper left corner

xCaret = 0 ;
yCaret = 0 ;

if (hwnd == GetFocus ())
SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;

InvalidateRect (hwnd, cast(RECT*) null, TRUE) ;
return 0 ;

case WM_SETFOCUS:
// create and show the caret

CreateCaret (hwnd, cast(HBITMAP) null, cxChar, cyChar) ;
SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
ShowCaret (hwnd) ;
return 0 ;

case WM_KILLFOCUS:
// hide and destroy the caret

HideCaret (hwnd) ;
DestroyCaret () ;
return 0 ;

case WM_KEYDOWN:
switch (wParam)
{
case VK_HOME:
xCaret = 0 ;
break ;

case VK_END:
xCaret = cxBuffer - 1 ;
break ;

case VK_PRIOR:
yCaret = 0 ;
break ;

case VK_NEXT:
yCaret = cyBuffer - 1 ;
break ;

case VK_LEFT:
xCaret = max (xCaret - 1, 0) ;
break ;

case VK_RIGHT:
xCaret = min (xCaret + 1, cxBuffer - 1) ;
break ;

case VK_UP:
yCaret = max (yCaret - 1, 0) ;
break ;

case VK_DOWN:
yCaret = min (yCaret + 1, cyBuffer - 1) ;
break ;

case VK_DELETE:
for (x = xCaret ; x < cxBuffer - 1 ; x++)
BUFFER[x][yCaret] = BUFFER[x + 1][yCaret] ;

BUFFER[cxBuffer - 1][yCaret] = ' ' ;

HideCaret (hwnd) ;
hdc = GetDC (hwnd) ;

SelectObject (hdc, CreateFontA (0, 0, 0, 0, 0, 0, 0, 0,
dwCharSet, 0, 0, 0, FIXED_PITCH, cast(LPCSTR) null)) ;

TextOutA (hdc, xCaret * cxChar, yCaret * cyChar,
& BUFFER[xCaret][yCaret],
cxBuffer - xCaret) ;

DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
ReleaseDC (hwnd, hdc) ;
ShowCaret (hwnd) ;
break ;

default:
break;
}
SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
return 0 ;

case WM_CHAR:
for (i = 0 ; i < cast(int) LOWORD (lParam) ; i++)
{
switch (wParam)
{
case '\b':                    // backspace
if (xCaret > 0)
{
xCaret-- ;
SendMessageA (hwnd, WM_KEYDOWN, VK_DELETE, 1) ;
}
break ;

case '\t':                    // tab
do
{
SendMessageA (hwnd, WM_CHAR, ' ', 1) ;
}
while (xCaret % 8 != 0) ;
break ;

case '\n':                    // line feed
if (++yCaret == cyBuffer)
yCaret = 0 ;
break ;

case '\r':                    // carriage return
xCaret = 0 ;

if (++yCaret == cyBuffer)
yCaret = 0 ;
break ;

case '\x1B':                  // escape
for (y = 0 ; y < cyBuffer ; y++)
for (x = 0 ; x < cxBuffer ; x++)
BUFFER[x][y] = ' ' ;

xCaret = 0 ;
yCaret = 0 ;

InvalidateRect (hwnd, cast(RECT*) null, FALSE) ;
break ;

default:                      // character codes
BUFFER[xCaret][yCaret] = cast(TCHAR) wParam ;

HideCaret (hwnd) ;
hdc = GetDC (hwnd) ;

SelectObject (hdc, CreateFontA (0, 0, 0, 0, 0, 0, 0, 0,
dwCharSet, 0, 0, 0, FIXED_PITCH, cast(LPCSTR) null)) ;

TextOutA (hdc, xCaret * cxChar, yCaret * cyChar,
& BUFFER[xCaret][yCaret], 1) ;

DeleteObject (
SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
ReleaseDC (hwnd, hdc) ;
ShowCaret (hwnd) ;

if (++xCaret == cxBuffer)
{
xCaret = 0 ;

if (++yCaret == cyBuffer)
yCaret = 0 ;
}
break ;
}
}

SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
return 0 ;

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;

SelectObject (hdc, CreateFontA (0, 0, 0, 0, 0, 0, 0, 0,
dwCharSet, 0, 0, 0, FIXED_PITCH, cast(LPCSTR) null)) ;

for (y = 0 ; y < cyBuffer ; y++)
TextOutA (hdc, 0, y * cyChar, & BUFFER[0][y], cxBuffer) ;

DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
EndPaint (hwnd, &ps) ;
return 0 ;

case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;

default:
break;
}
return DefWindowProcA (hwnd, message, wParam, lParam) ;
}
</code>

In article <d088sm$2mpk$1 digitaldaemon.com>, Kevin M says...
Hello, can someone help me with the following issue regarding dynamic
"rectangular arrays"? Thanks.

-Porting some C code to D.
-The C code allocates, deletes, and resizes a multi-dimensional character array
using malloc/free.
-Don't want to use malloc/free.
-How do I create the array Buffer[][] as dynamic, and set its length?
(ie. Buffer.length = cxBuffer; //obviously won't work)
-If Buffer[][] needs to be deleted and resized, how is this done)? Will
new/delete work, if so how?
-cxBuffer, cyBuffer, and Buffer must be static. They must keep their values when
the function exits.

Kevin M

----------------------------
some_function()
{
int         x, y;
static int  cxBuffer, cyBuffer;

//Initialize cxBuffer and cyBuffer
..

//Create Buffer[][]
static char Buffer[cxBuffer][cyBuffer];

//Initialize Buffer
for (y = 0 ; y < cyBuffer ; y++)
for (x = 0 ; x < cxBuffer ; x++)
Buffer[x][y] = ' ';
}
----------------------------
Mar 03 2005
parent reply Derek Parnell <derek psych.ward> writes:
Content-type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

On Fri, 4 Mar 2005 01:30:17 +0000 (UTC), Kevin M wrote:

 Here is the actual code, which makes it clearer what I am trying to do with
 Buffer[][]. Currently Buffer[200][200] is static, but I want it to be dynamic,
 so I can use Buffer[cxBuffer][cyBuffer] instead.
I've attached the revised code to make it work. The main issue is that D and C++ have the order of multi-level indexes reversed. Whereas you had basically BUFFER[charindex][lineindex] you will find that you needed BUFFER[lineindex][charindex] BTW, I took your code and saved it as 'typer.d', then typed in 'build typer' and it compiled and linked it first go! This is the first test I've actually had using my Build utility with a real Windows application so I was stoked to see it work so easily. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ 4/03/2005 1:06:18 PM
Mar 03 2005
parent reply Kevin M <Kevin_member pathlink.com> writes:
Derek, thanks for your help. I just tested the code and it works. The Base64
encoding delayed my response.

Kevin M


In article <1t87qzdhec31w$.1q5jqinrfdsuj.dlg 40tude.net>, Derek Parnell says...
----447B463D08905736_message_boundary--
Content-type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

On Fri, 4 Mar 2005 01:30:17 +0000 (UTC), Kevin M wrote:

 Here is the actual code, which makes it clearer what I am trying to do with
 Buffer[][]. Currently Buffer[200][200] is static, but I want it to be dynamic,
 so I can use Buffer[cxBuffer][cyBuffer] instead.
I've attached the revised code to make it work. The main issue is that D and C++ have the order of multi-level indexes reversed. Whereas you had basically BUFFER[charindex][lineindex] you will find that you needed BUFFER[lineindex][charindex] BTW, I took your code and saved it as 'typer.d', then typed in 'build typer' and it compiled and linked it first go! This is the first test I've actually had using my Build utility with a real Windows application so I was stoked to see it work so easily. -- Derek Parnell Melbourne, Australia http://www.dsource.org/projects/build/ 4/03/2005 1:06:18 PM ----447B463D08905736_message_boundary-- Content-type: application/octet-string; name=typer.d Content-Transfer-Encoding: Base64 Content-Disposition: attachment; FileName=typer.d Content-Description: Attached file: typer.d
Mar 04 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Fri, 4 Mar 2005 12:00:43 +0000 (UTC), Kevin M wrote:

 Derek, thanks for your help. I just tested the code and it works. The Base64
 encoding delayed my response.
[snip]
----447B463D08905736_message_boundary--
Content-type: application/octet-string; name=typer.d
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; FileName=typer.d
Content-Description: Attached file: typer.d
I didn't even realize the 40Tude was set up that way. I've changed it to UUencode now. It that any better? -- Derek Parnell Melbourne, Australia 4/03/2005 11:03:46 PM begin 644 sort.d M5%-H96QL4V]R="A4*0T*>PT*=F]I9"!S;W)T*%1;72!X+"!I;G0 9G5N8W1I M;VXH5"!A+"!4(&(I(&8];G5L;"D-"GL-"B\O("`M+2!3;W)T(&%N(&%R<F%Y M="P ;&%S=#L-"B` ("!B;V]L(&-M<#L-"B` ("!4('1E;7!I+"!T96UP:CL- M" T*("` (&QA<W0 /2!X+FQE;F=T:#L- M*2LQ.PT*("` ('=H:6QE("AT<G5E*0T*("` ('L-"B` ("!F:7)S="`](&=A M(#T :2`M(&=A<#L- M(#X M"B` ("` ("` :68 *&H /#T M("` ('A;:BTQ72`]('1E;7!I.PT*("` ('T-"B` ("!I9B`H9V%P(#T M;W)T(2AI;G0I+G-O<G0 <V]R=#L-"B!A;&EA<R!44VAE;&Q3;W)T(2AC:&%R M6UTI+G-O<G0 <V]R=#L-"B`-"G!R:79A=&4 :6UP;W)T('-T9"YS=&1I;SL- M.PT*("` :68 *&$ /B!B*2`-"B` ("!R971U<FX ,3L-"B` (&EF("AA(#P M+"`F;7EC;VUP*3L-"B` ("!F;W)E86-H*&-H87);72!X.R!!*0T*("` ("` M('=R:71E9FQN*' I.PT*("` (`T*("` ('=R:71E9FQN*")497-T('=I=& F:"AC:&%R6UT >#L 02D-"B` ("` ("!W<FET969L;BAX*3L-"GT` ` end
Mar 04 2005
parent reply Kevin M <Kevin_member pathlink.com> writes:
Derek, I used http://makcoder.sourceforge.net/demo/base64.php to decode the
Base64. I've just installed 40tude, but how do I configure it for this forum?

Kevin

In article <5aqwhkz1z0a5$.h3l070vr6s3i$.dlg 40tude.net>, Derek Parnell says...
On Fri, 4 Mar 2005 12:00:43 +0000 (UTC), Kevin M wrote:

 Derek, thanks for your help. I just tested the code and it works. The Base64
 encoding delayed my response.
[snip]
----447B463D08905736_message_boundary--
Content-type: application/octet-string; name=typer.d
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; FileName=typer.d
Content-Description: Attached file: typer.d
I didn't even realize the 40Tude was set up that way. I've changed it to UUencode now. It that any better? -- Derek Parnell Melbourne, Australia 4/03/2005 11:03:46 PM begin 644 sort.d M5%-H96QL4V]R="A4*0T*>PT*=F]I9"!S;W)T*%1;72!X+"!I;G0 9G5N8W1I M;VXH5"!A+"!4(&(I(&8];G5L;"D-"GL-"B\O("`M+2!3;W)T(&%N(&%R<F%Y M="P ;&%S=#L-"B` ("!B;V]L(&-M<#L-"B` ("!4('1E;7!I+"!T96UP:CL- M" T*("` (&QA<W0 /2!X+FQE;F=T:#L- M*2LQ.PT*("` ('=H:6QE("AT<G5E*0T*("` ('L-"B` ("!F:7)S="`](&=A M(#T :2`M(&=A<#L- M(#X M"B` ("` ("` :68 *&H /#T M("` ('A;:BTQ72`]('1E;7!I.PT*("` ('T-"B` ("!I9B`H9V%P(#T M;W)T(2AI;G0I+G-O<G0 <V]R=#L-"B!A;&EA<R!44VAE;&Q3;W)T(2AC:&%R M6UTI+G-O<G0 <V]R=#L-"B`-"G!R:79A=&4 :6UP;W)T('-T9"YS=&1I;SL- M.PT*("` :68 *&$ /B!B*2`-"B` ("!R971U<FX ,3L-"B` (&EF("AA(#P M+"`F;7EC;VUP*3L-"B` ("!F;W)E86-H*&-H87);72!X.R!!*0T*("` ("` M('=R:71E9FQN*' I.PT*("` (`T*("` ('=R:71E9FQN*")497-T('=I=& F:"AC:&%R6UT >#L 02D-"B` ("` ("!W<FET969L;BAX*3L-"GT` ` end
Mar 04 2005
next sibling parent J C Calvarese <jcc7 cox.net> writes:
In article <d0a380$1hui$1 digitaldaemon.com>, Kevin M says...
Derek, I used http://makcoder.sourceforge.net/demo/base64.php to decode the
Base64. I've just installed 40tude, but how do I configure it for this forum?

Kevin
Looks like a handy tool. I added a link to it at Wiki4D (http://www.prowiki.org/wiki4d/wiki.cgi?NewsDmD). Here are some tools (written in D) that I've used: Base64, http://www.dsource.org/tutorials/index.php?show_example=81 UUDECODE, http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/4744 jcc7
Mar 04 2005
prev sibling parent Derek Parnell <derek psych.ward> writes:
On Fri, 4 Mar 2005 16:43:45 +0000 (UTC), Kevin M wrote:

 Derek, I used http://makcoder.sourceforge.net/demo/base64.php to decode the
 Base64. I've just installed 40tude, but how do I configure it for this forum?
 
(1) Define the new server. ** Select the menu item "Settings"/"Servers, Identities, Signatures..." ** Select "NewsServers" from the list, click the "New" button. ** Give it a name. I've called mine "DigitalMars", click "Ok" ** Type in the host name "news.digitalmars.com" and click "Ok". (2) Define an Identity ** Select the menu item "Settings"/"Servers, Identities, Signatures..." ** Select "Identities" from the list, click the "New" button. ** Give it a name, click the "Ok" button. ** Enter your name. This is the name that is displayed as the "From" name in postings. ** Enter in an email address for postings. This is usually a false one to fool spammers. ddparnell_at_ _bigpond_dot_._com ** Optionally enter in an email address for the Return To address when you send emails. ** Click on the POP3 tab and enter in your POP3 server details. ** Click on the SMTP tab and enter in your SMTP server details. ** Click "Ok" (3) Get a list of groups from the new News Server ** Select the menu item "Online"/"Get complete grouplist(s)"/"DigitalMars" ** After a while, this process will finish. ** Select the tab "New" which is in the "Subscribed", "All", and "Folders" tabbed pane. You will see all the groups in DigitalMars. ** Double click on the ones you wish to subscribe to. ** Select the menu "Online"/"Get new headers in subscribed groups" ** This will ask you the maximum number of headers to download. ** Next you will see in the Headers pane, all the downloaded headers. ** Either double click on any header to download its body, or press the SpaceBar to download the next unread one. Hope this helps. -- Derek Parnell Melbourne, Australia 5/03/2005 8:16:40 AM
Mar 04 2005
prev sibling next sibling parent reply Kevin M <Kevin_member pathlink.com> writes:
Attached is the actual code, which makes it clearer what I am trying to do with
Buffer[][]. Currently Buffer[200][200] is static, but I want it to be dynamic,
so I can use Buffer[cxBuffer][cyBuffer] instead.

By the way, how do I keep the Forum from deleting the leading spaces/tabs in
messages? I tried <code> and </code> which didn't work.

Kevin M


begin 0644 Typer2.d
M+RHM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*("` 
M5%E015(N1"`M+2!4>7!I;F< 4')O9W)A;0T*"0D ("` *&,I($-H87)L97, 
M4&5T>F]L9"P ,3DY.`T*("`M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM





M<C,R+FQI8BP =VEN=7-E<BYH*3H-"B\O("TM+2TM+2TM+2TM+2TM+2TM+2TM
M+2TM+0T*+R\ ("!"96=I;E!A:6YT*"DL($-R96%T94-A<F5T*"DL($-R96%T



M=" I+"!);G9A;&ED871E4F5C=" I+"!,;V%D0W5R<V]R02 I+"!,;V%D26-O
M;D$H*2P-"B\O("` 365S<V%G94)O>$$H*2P 4&]S=%%U:71-97-S86=E*"DL
M(%)E9VES=&5R0VQA<W-!*"DL(%)E;&5A<V5$0R I+`T*+R\ ("!396YD365S
M<V%G94$H*2P 4V5T0V%R9710;W,H*2P 4VAO=T-A<F5T*"DL(%-H;W=7:6YD
M;W<H*2P-"B\O("` 5')A;G-L871E365S<V%G92 I+"!5<&1A=&57:6YD;W<H
M*0T*+R\-"B\O("AG9&DS,BYL:6(L('=I;F=D:2YH*3H-"B\O("TM+2TM+2TM
M+2TM+2TM+2TM+2TM+2T-"B\O("` 0W)E871E1F]N=$$H*2P 1&5L971E3V)J
M96-T*"DL($=E=%-T;V-K3V)J96-T*"DL($=E=%1E>'1-971R:6-S02 I+`T*
M+R\ ("!396QE8W1/8FIE8W0H*2P 5&5X=$]U=$$H*0T*+R\-"B\O("AK97)N


M+F  ;6%C<F\I. T*+R\ +2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*









M"B` ("!G8U]I;FET*"D[("` ("` ("` ("` ("` ("` +R\ :6YI=&EA;&EZ
M92!G87)B86=E(&-O;&QE8W1O< T*("` (%]M:6YI=" I.R` ("` ("` ("` 
M("` ("` ("`O+R!I;FET:6%L:7IE(&UO9'5L92!C;VYS=')U8W1O<B!T86)L

M("`O+R!C86QL(&UO9'5L92!C;VYS=')U8W1O<G,-" D)7VUO9'5L955N:714

M"7)E<W5L="`](&UY5VEN36%I;BAH26YS=&%N8V4L(&A0<F5V26YS=&%N8V4L
M(&QP0VUD3&EN92P ;D-M9%-H;W<I.PT*("` ('T-" T*("` (&-A=&-H("A/
M8FIE8W0 ;RD ("` ("` ("` ("`O+R!C871C:"!A;GD =6YC875G:'0 97AC
M97!T:6]N<PT*("` ('L-" D)365S<V%G94)O>$$H8V%S="A(5TY$*2!N=6QL


M("` ("` ("` ("\O(&9A:6QE9`T*("` ('T-" T*("` (&=C7W1E<FTH*3L 
M("` ("` ("` ("` ("` ("`O+R!R=6X 9FEN86QI>F5R<SL =&5R;6EN871E

M+R\ *BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ

M:65S(&UI<W-I;F< :6X 0SI<9&UD7'-R8UQP:&]B;W-<<W1D7&-<=VEN9&]W

M(&$L(&EN="!B*2![(')E='5R;B!A(#X
M*&EN="!A+"!I;G0 8BD >R!R971U<FX 82`\(&( /R!A(#H
M;G0 ;7E7:6Y-86EN("A(24Y35$%.0T4 :$EN<W1A;F-E+"!(24Y35$%.0T4 



M(#L-
M='EL92` ("` ("` (#T 0U-?2%)%1%)!5R!\($-37U92141205< .PT*"7=N


M/2`P(#L-" EW;F1C;&%S<RYH26YS=&%N8V4 ("` (#T :$EN<W1A;F-E(#L-
M" EW;F1C;&%S<RYH26-O;B` ("` ("` (#T 3&]A9$EC;VY!("AC87-T*$A)



M(&-A<W0H2$)255-(*2`H1V5T4W1O8VM/8FIE8W0 *%=(251%7T)255-(*2D 
M.PT*"7=N9&-L87-S+FQP<WI-96YU3F%M92` /2!C87-T*$Q00U-44BD ;G5L

M" EI9B`H(5)E9VES=&5R0VQA<W-!(" F=VYD8VQA<W,I*0T*"7L-" D)365S
M<V%G94)O>$$ *&-A<W0H2%=.1"D ;G5L;"P (E1H:7, <')O9W)A;2!R97%U

M15)23U(I(#L-
M:6YD;W=!("AS>D%P<$YA;64L("` ("` ("` ("` ("` ("` +R\ =VEN9&]W
M(&-L87-S(&YA;64-" D)"0D)("`B5'EP:6YG(%!R;V=R86TB+"` ("` ("` 
M("` +R\ =VEN9&]W(&-A<'1I;VX-" D)"0D)("!74U]/5D523$%04$5$5TE.

M055,5"P ("` ("` ("` ("` ("\O(&EN:71I86P >"!P;W-I=&EO; T*"0D)
M"0D ($-77U53141%1D%53%0L("` ("` ("` ("` ("`O+R!I;FET:6%L('D 


M("` ("` ("` +R\ :6YI=&EA;"!Y('-I>F4-" D)"0D)("!C87-T*$A73D0I
M(&YU;&PL("` ("` ("` ("` +R\ <&%R96YT('=I;F1O=R!H86YD;&4-" D)
M"0D)("!C87-T*$A-14Y5*2!N=6QL+"` ("` ("` ("` +R\ =VEN9&]W(&UE

M("\O('!R;V<N(&EN<W1A;F-E(&AA;F1L90T*"0D)"0D (&YU;&PI(#L ("` 




M;G-L871E365S<V%G92`H)FUS9RD .PT*"0E$:7-P871C:$UE<W-A9V5!(" F

M9FEN92!"549&15(H>"QY*2`J*'!"=69F97( *R!Y("H 8WA"=69F97( *R!X

M+"!524Y4(&UE<W-A9V4L(%=005)!32!W4&%R86TL($Q005)!32!L4&%R86TI

M4T54(#L-

M+"!Y0V%R970 .PT*("` +R]S=&%T:6, 5$-(05(J("!P0G5F9F5R(#T ;G5L

M97!L86-E<R!M86-R;R!"549&15(-" E(1$, ("` ("` ("` ("!H9&, .PT*
M"6EN="` ("` ("` ("` (' L('DL(&D .PT*"5!!24Y44U1254-4("` ('!S
M(#L-

M/2!W4&%R86T .PT*"0D)"0D)"0DO+R!F86QL('1H<F]U9V -" EC87-E(%=-
M7T-214%413H-" D):&1C(#T 1V5T1$, *&AW;F0I(#L-" D)4V5L96-T3V)J
M96-T("AH9&,L($-R96%T949O;G1!(" P+"`P+"`P+"`P+"`P+"`P+"`P+"`P



M"6-Y0VAA<B`]('1M+G1M2&5I9VAT(#L-" T*"0E$96QE=&5/8FIE8W0 *%-E
M;&5C=$]B:F5C="`H:&1C+"!'9713=&]C:T]B:F5C="`H4UE35$5-7T9/3E0I
M*2D .PT*"0E296QE87-E1$, *&AW;F0L(&AD8RD .PT*"0D)"0D)"0DO+R!F





M(#T ;6%X(" Q+"!C>$-L:65N="`O(&-X0VAA<BD .PT*"0EC>4)U9F9E<B`]


M<$)U9F9E<B`A/2!N=6QL*0T*"2` ("`O+R` ("` 9G)E92`H<$)U9F9E<BD 

M9F5R("H 8WE"=69F97( *B!40TA!4BYS:7IE;V8I(#L-" T*"0DO+V9O<B`H

M/2`P(#L >"`\(&-X0G5F9F5R(#L >"LK*0T*"0DO+R` ("` ("` ("!"549&

M>2LK*0T*"0D)9F]R("AX(#T
M1D526WA=6WE=(#T )R`G(#L-" T*"0D)+R\ <V5T(&-A<F5T('1O('5P<&5R




M(#L-

M:'=N9"P 8V%S="A(0DE434%0*2!N=6QL+"!C>$-H87(L(&-Y0VAA<BD .PT*

M87(I(#L-
M"6-A<V4 5TU?2TE,3$9/0U53. T*"0D)+R\ :&ED92!A;F0 9&5S=')O>2!T
M:&4 8V%R970-" T*"0E(:61E0V%R970 *&AW;F0I(#L-" D)1&5S=')O>4-A
M<F5T(" I(#L-

M0V%R970 /2`P(#L-" D)"6)R96%K(#L-" T*"0EC87-E(%9+7T5.1#H-" D)


M"6-A<V4 5DM?3D585#H-


M24=(5#H-





M*0T*"0D)"4)51D9%4EMX75MY0V%R971=(#T 0E5&1D526W  *R`Q75MY0V%R
M971=(#L-" T*"0D)0E5&1D526V-X0G5F9F5R("T ,5U;>4-A<F5T72`]("< 

M*&AW;F0I(#L-" T*"0D)4V5L96-T3V)J96-T("AH9&,L($-R96%T949O;G1!
M(" P+"`P+"`P+"`P+"`P+"`P+"`P+"`P+`T*"0D)"0D)("` (&1W0VAA<E-E


M="`J(&-Y0VAA<BP-" D)"0D))B!"549&15);>$-A<F5T75MY0V%R971=+`T*

M*%-E;&5C=$]B:F5C="`H:&1C+"!'9713=&]C:T]B:F5C="`H4UE35$5-7T9/



M0V%R970 *B!C>4-H87(I(#L-
M2$%2. T*"0EF;W( *&D /2`P(#L :2`\(&-A<W0H:6YT*2!,3U=/4D0 *&Q0

M"0D)8V%S92`G7&(G.B` ("` ("` ("` ("` ("` ("` +R\ 8F%C:W-P86-E








M>4-A<F5T(#T
M("` ("` ("` ("` ("` ("`O+R!C87)R:6%G92!R971U<FX-" D)"0EX0V%R
M970 /2`P(#L-
M"0D)>4-A<F5T(#T
M)SH ("` ("` ("` ("` ("` ("`O+R!E<V-A<&4-" D)"0EF;W( *'D /2`P
M(#L >2`\(&-Y0G5F9F5R(#L >2LK*0T*"0D)"0EF;W( *'  /2`P(#L >"`\
M(&-X0G5F9F5R(#L >"LK*0T*"0D)"0D)0E5&1D526WA=6WE=(#T )R`G(#L-



M("` ("` ("`O+R!C:&%R86-T97( 8V]D97,-" D)"0E"549&15);>$-A<F5T
M75MY0V%R971=(#T 8V%S="A40TA!4BD =U!A<F%M(#L-







M=&]C:T]B:F5C="`H4UE35$5-7T9/3E0I*2D .PT*"0D)"5)E;&5A<V5$0R`H


M/2`P(#L-
M"0D)"0EY0V%R970 /2`P(#L-

M970 *B!C>4-H87(I(#L-
M5#H-" D):&1C(#T
M96-T3V)J96-T("AH9&,L($-R96%T949O;G1!(" P+"`P+"`P+"`P+"`P+"`P




M;&5T94]B:F5C="`H4V5L96-T3V)J96-T("AH9&,L($=E=%-T;V-K3V)J96-T




<<V%G92P =U!A<F%M+"!L4&%R86TI(#L-"GT-"G=0
`
end
Mar 03 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Fri, 4 Mar 2005 01:42:48 +0000 (UTC), Kevin M  
<Kevin_member pathlink.com> wrote:
 Attached is the actual code, which makes it clearer what I am trying to  
 do with
 Buffer[][]. Currently Buffer[200][200] is static, but I want it to be  
 dynamic,
 so I can use Buffer[cxBuffer][cyBuffer] instead.

 By the way, how do I keep the Forum from deleting the leading  
 spaces/tabs in
 messages? I tried <code> and </code> which didn't work.
For me spaces stay, tabs vanish, at least thats what my posts look like to me, who knows what they look like to you. eg. 4 spaces 1 tab 1 tab 1 space Regan
Mar 03 2005
prev sibling next sibling parent Kevin M <Kevin_member pathlink.com> writes:
Here is the actual code again (with indentation), which makes it clearer what I
am trying to do with
Buffer[][]. Currently Buffer[100][200] is static, but I want it to be dynamic,
so I can use Buffer[cyBuffer][cxBuffer] instead.

Kevin M







































#import std.c.windows.windows;


#extern (C) void gc_init();
#extern (C) void gc_term();
#extern (C) void _minit();
#extern (C) void _moduleCtor();
#extern (C) void _moduleUnitTests();

#extern (Windows)
#int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,





























#alias char TCHAR;

#int max(int a, int b) { return a > b ? a : b; }
#int min(int a, int b) { return a < b ? a : b; }

#int myWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,













;







































#extern (Windows)
#int WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)




















null)) ;



























;

















































































null)) ;






;






























































cast(LPCSTR) null)) ;




























null)) ;

















Mar 03 2005
prev sibling parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
There is no such thing like "dynamic rectangular arrays" in D, yet. You 
can have static rectangular arrays:

	int[13][42] myarray;

but dynamic multidimensional arrays like

	int[][] anotherarray;

are always 'ragged' arrays. I.e. each subarray may have another size. 
The implementation works on arrays of pointers to other arrays, which 
means that reshaping is generally not possible.

Ideas for real dynamic rectangular arrays are developed but will not go 
into D 1.0 anymore. Lets hope for future versions.

Ciao,
Norbert



Kevin M schrieb:
 Hello, can someone help me with the following issue regarding dynamic
 "rectangular arrays"? Thanks.
 
 -Porting some C code to D.
 -The C code allocates, deletes, and resizes a multi-dimensional character array
 using malloc/free.
 -Don't want to use malloc/free.
 -How do I create the array Buffer[][] as dynamic, and set its length?
 (ie. Buffer.length = cxBuffer; //obviously won't work)
 -If Buffer[][] needs to be deleted and resized, how is this done)? Will
 new/delete work, if so how?
 -cxBuffer, cyBuffer, and Buffer must be static. They must keep their values
when
 the function exits.
 
 Kevin M
 
 ----------------------------
 some_function()
 {
 int         x, y;
 static int  cxBuffer, cyBuffer;
 
 //Initialize cxBuffer and cyBuffer
 ..
 
 //Create Buffer[][]
 static char Buffer[cxBuffer][cyBuffer];
 
 //Initialize Buffer
 for (y = 0 ; y < cyBuffer ; y++)
 for (x = 0 ; x < cxBuffer ; x++)
 Buffer[x][y] = ' ';
 }
 ----------------------------
 
 
Mar 05 2005
parent "Matthew" <admin.hat stlsoft.dot.org> writes:
There's no reason why the techniques I describe in Chapter 33, Multidimensional
Arrays, of Imperfect C++ cannot be
applied, either in library or built-in form, to D at some point. Given that
slices+GC help us in so many ways, D's 
arguably
a much better suited language that C++


-- 
Matthew Wilson

Author: "Imperfect C++", Addison-Wesley, 2004
    (http://www.imperfectcplusplus.com)
Contributing editor, C/C++ Users Journal
    (http://www.synesis.com.au/articles.html#columns)
Director, Synesis Software
    (www.synesis.com.au)
STLSoft moderator
    (http://www.stlsoft.org)

Synesis Software Pty Ltd
P.O.Box 125
Waverley
New South Wales, 2024
Australia

-----------------------------------------------------


"Norbert Nemec" <Norbert Nemec-online.de> wrote in message
news:d0d2gb$1b5t$1 digitaldaemon.com...
 There is no such thing like "dynamic rectangular arrays" in D, yet. You can
have static rectangular arrays:

 int[13][42] myarray;

 but dynamic multidimensional arrays like

 int[][] anotherarray;

 are always 'ragged' arrays. I.e. each subarray may have another size. The
implementation works on arrays of pointers
 to other arrays, which means that reshaping is generally not possible.

 Ideas for real dynamic rectangular arrays are developed but will not go into D
1.0 anymore. Lets hope for future
 versions.

 Ciao,
 Norbert



 Kevin M schrieb:
 Hello, can someone help me with the following issue regarding dynamic
 "rectangular arrays"? Thanks.

 -Porting some C code to D.
 -The C code allocates, deletes, and resizes a multi-dimensional character array
 using malloc/free.
 -Don't want to use malloc/free.
 -How do I create the array Buffer[][] as dynamic, and set its length?
 (ie. Buffer.length = cxBuffer; //obviously won't work)
 -If Buffer[][] needs to be deleted and resized, how is this done)? Will
 new/delete work, if so how?
 -cxBuffer, cyBuffer, and Buffer must be static. They must keep their values
when
 the function exits.

 Kevin M

 ----------------------------
 some_function()
 {
 int         x, y;
 static int  cxBuffer, cyBuffer;

 //Initialize cxBuffer and cyBuffer
 ..

 //Create Buffer[][]
 static char Buffer[cxBuffer][cyBuffer];

 //Initialize Buffer
 for (y = 0 ; y < cyBuffer ; y++)
 for (x = 0 ; x < cxBuffer ; x++)
 Buffer[x][y] = ' ';
 }
 ----------------------------
Mar 05 2005