Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.c++ / Restructuring program

SubjectAuthor
* Restructuring programPaul N
+* Re: Restructuring programMalcolm McLean
|+* Re: Restructuring programBonita Montero
||`* Re: Restructuring programPaul N
|| +- Re: Restructuring programChris M. Thomasson
|| `* Re: Restructuring programBonita Montero
||  `- Re: Restructuring programBonita Montero
|`- Re: Restructuring programPaul N
`- Re: Restructuring programPaul N

1
Restructuring program

<7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=456&group=comp.lang.c%2B%2B#456

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:ac8:5707:0:b0:3f6:bb7b:b93e with SMTP id 7-20020ac85707000000b003f6bb7bb93emr5376383qtw.4.1687259018713;
Tue, 20 Jun 2023 04:03:38 -0700 (PDT)
X-Received: by 2002:a05:622a:1893:b0:3fd:ec53:7a93 with SMTP id
v19-20020a05622a189300b003fdec537a93mr2487859qtc.9.1687259018575; Tue, 20 Jun
2023 04:03:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Tue, 20 Jun 2023 04:03:38 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=92.28.25.60; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 92.28.25.60
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
Subject: Restructuring program
From: gw7...@aol.com (Paul N)
Injection-Date: Tue, 20 Jun 2023 11:03:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3235
 by: Paul N - Tue, 20 Jun 2023 11:03 UTC

I recently got the urge (as you do) to convert a 1980s BASIC program to C++, first as a console program and then as a Windows one. Converting it to a console program was not too bad but the Windows version, though working, looks very messy and I was wondering if anyone had any ideas as to how to make it look neater. The problems are with display, keyboard input and delays, and I'll give an example of the latter here.

In the console version, part of it goes as follows:

switch (mm) {
case Bash:
if (u == Duck) {
printf("Your attempted dodge - ");
sleep(3);
if (random(20) < d) { printf("success!\n"); break; }
printf("No luck.\n"); }
printf("\nHits on you are ");
g = ((double)t / r) + 0.999; printf("%d\t", g); c -= g;
sound();
break;

The program is a "Gladiators" game. If your opponent decides to "bash" you will normally suffer damage, unless your move (chosen without seeing his) is a duck. In which case you may avoid the blow, it depends on chance and on your dexterity. There is an exciting delay while you find out.

But a Windows program is not supposed to sit around doing nothing. So this part now looks like:

switch (mm) {
case Bash:
if (u == Duck) {
m1 = _TEXT("Your attempted dodge - ");
sleep(3, wait1);
return;
Wait1:
if (random(20) < d) { m2 = _TEXT("success!"); break; }
m2 = _TEXT("No luck."); }
g1 = ((double)t / r) + 0.999; c -= g1;
break;

To make it work, I have a "sleep" function which actually sets a counter:

void sleep(int count, states act) {
counter = count;
state = act;
refresh();
}

I start a timer and handle it as follows:

case WM_TIMER:
if (state >= wait1 && state <= wait4 && counter > 0) {
counter--;
if (counter == 0) glad(state, 0); }
break;

and at the start of the main routine "glad" I have:

void glad(states act, TCHAR key) {
if (act == wait1) goto Wait1;

I'm sure that a goto jumping into an if in a switch is not anybody's idea of nice code. It also only works because most of the variables are globals rather than autos.

So is there a nicer way of doing it, while still making it fairly clear what is going on?

Re: Restructuring program

<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=458&group=comp.lang.c%2B%2B#458

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:ad4:4e0c:0:b0:62f:f0c9:1c87 with SMTP id dl12-20020ad44e0c000000b0062ff0c91c87mr2382502qvb.12.1687278345664;
Tue, 20 Jun 2023 09:25:45 -0700 (PDT)
X-Received: by 2002:a05:622a:10:b0:3fd:e0c6:4d1b with SMTP id
x16-20020a05622a001000b003fde0c64d1bmr4850626qtw.11.1687278345517; Tue, 20
Jun 2023 09:25:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Tue, 20 Jun 2023 09:25:45 -0700 (PDT)
In-Reply-To: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:9c39:63f1:bdf3:1135;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:9c39:63f1:bdf3:1135
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
Subject: Re: Restructuring program
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Tue, 20 Jun 2023 16:25:45 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3029
 by: Malcolm McLean - Tue, 20 Jun 2023 16:25 UTC

On Tuesday, 20 June 2023 at 12:03:47 UTC+1, Paul N wrote:
>
> To make it work, I have a "sleep" function which actually sets a counter:
>
> void sleep(int count, states act) {
> counter = count;
> state = act;
> refresh();
> }
>
> I start a timer and handle it as follows:
>
> case WM_TIMER:
> if (state >= wait1 && state <= wait4 && counter > 0) {
> counter--;
> if (counter == 0) glad(state, 0); }
> break;
>
> and at the start of the main routine "glad" I have:
>
> void glad(states act, TCHAR key) {
> if (act == wait1) goto Wait1;
>
> I'm sure that a goto jumping into an if in a switch is not anybody's idea of nice code. It also only works because most of the variables are globals rather than autos.
>
> So is there a nicer way of doing it, while still making it fairly clear what is going on?
>
You make the program event-driven. The events will include window open and close, but most importantly
a WM_TIMER call. You arrange for a periodic WM_TIMER call every tenth of. a second or so. The response is to
call a function called tick().

tick() calls daemons.

You need some way of getting the current time and comparing two times. The standard library
functions are not very suitable and Windows has a file time stamp function you can use for the
purpose.

typedef struct
{ TIMESTAMP triggertime;
void (*function)(void *ptr);
void *ptr;
} DAEMON;

DEAMON *g_daemons = 0;
int g_Ndaemons = 0;
int g_daemonbuffsize = 0;

/* add a daemon to the list */
void setdaemon(TIMESTAMP *t, void (*fptr)(void *), void *ptr)

/* tick calls the daemons and removes them from the list */
void tick(void)

Since as designed the program has no way of recovering if the daemon
list become empty, you probably want a special function that is always
called as well.

Re: Restructuring program

<u6st6c$2gts4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=459&group=comp.lang.c%2B%2B#459

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Restructuring program
Date: Tue, 20 Jun 2023 21:03:39 +0200
Organization: A noiseless patient Spider
Lines: 1
Message-ID: <u6st6c$2gts4$1@dont-email.me>
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 20 Jun 2023 19:03:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b86604d5b2917deac70ad2762bde737f";
logging-data="2652036"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199xlAeLMYYEMe6RTvhrNNyu0RBQKzoHMg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:ReUx/kfvYdPUIcZn3Q8hvmoAw9I=
Content-Language: de-DE
In-Reply-To: <a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
 by: Bonita Montero - Tue, 20 Jun 2023 19:03 UTC

Don't use C function pointers in C++, use function<>-objects.

Re: Restructuring program

<f81f07da-bace-43f3-9098-554b7c9c4d13n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=460&group=comp.lang.c%2B%2B#460

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:620a:15d:b0:763:6645:20e1 with SMTP id e29-20020a05620a015d00b00763664520e1mr933288qkn.11.1687297849758;
Tue, 20 Jun 2023 14:50:49 -0700 (PDT)
X-Received: by 2002:a05:622a:10:b0:3fd:e0c6:4d1b with SMTP id
x16-20020a05622a001000b003fde0c64d1bmr5116910qtw.11.1687297849565; Tue, 20
Jun 2023 14:50:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Tue, 20 Jun 2023 14:50:49 -0700 (PDT)
In-Reply-To: <a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=92.28.25.60; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 92.28.25.60
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com> <a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f81f07da-bace-43f3-9098-554b7c9c4d13n@googlegroups.com>
Subject: Re: Restructuring program
From: gw7...@aol.com (Paul N)
Injection-Date: Tue, 20 Jun 2023 21:50:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4834
 by: Paul N - Tue, 20 Jun 2023 21:50 UTC

On Tuesday, June 20, 2023 at 5:25:55 PM UTC+1, Malcolm McLean wrote:
> On Tuesday, 20 June 2023 at 12:03:47 UTC+1, Paul N wrote:
> >
> > To make it work, I have a "sleep" function which actually sets a counter:
> >
> > void sleep(int count, states act) {
> > counter = count;
> > state = act;
> > refresh();
> > }
> >
> > I start a timer and handle it as follows:
> >
> > case WM_TIMER:
> > if (state >= wait1 && state <= wait4 && counter > 0) {
> > counter--;
> > if (counter == 0) glad(state, 0); }
> > break;
> >
> > and at the start of the main routine "glad" I have:
> >
> > void glad(states act, TCHAR key) {
> > if (act == wait1) goto Wait1;
> >
> > I'm sure that a goto jumping into an if in a switch is not anybody's idea of nice code. It also only works because most of the variables are globals rather than autos.
> >
> > So is there a nicer way of doing it, while still making it fairly clear what is going on?
> >
> You make the program event-driven. The events will include window open and close, but most importantly
> a WM_TIMER call. You arrange for a periodic WM_TIMER call every tenth of. a second or so. The response is to
> call a function called tick().

When I was mentally drafting this post I was going to include the phase "event-driven", but it seems not to have made it to the final version. Yes, my problems stem from the fact that the program is not supposed to sit around doing nothing when it pauses; likewise it is not supposed to actually wait for a key to be pressed. In each case it is supposed to "stop", and then be prodded back to life by an incoming message.

> tick() calls daemons.
>
> You need some way of getting the current time and comparing two times. The standard library
> functions are not very suitable and Windows has a file time stamp function you can use for the
> purpose.
>
> typedef struct
> {
> TIMESTAMP triggertime;
> void (*function)(void *ptr);
> void *ptr;
> } DAEMON;
>
> DEAMON *g_daemons = 0;
> int g_Ndaemons = 0;
> int g_daemonbuffsize = 0;
>
> /* add a daemon to the list */
> void setdaemon(TIMESTAMP *t, void (*fptr)(void *), void *ptr)
>
> /* tick calls the daemons and removes them from the list */
> void tick(void)
>
> Since as designed the program has no way of recovering if the daemon
> list become empty, you probably want a special function that is always
> called as well.

Thanks Malcom, but I think you mis-understand what I'm getting at. I currently have a timer which "ticks" every second. Normally "counter" is zero. When I want something to happen in the future I set "counter" to be the number of seconds delay and "state" to indicate what should happen. At each tick, counter is decreased if it is positive, and something happens if this reduces counter to zero. The length of the delay may vary by up to a second or so depending on exactly when it starts relative to the tick, but I am happy with this and I don't think I need to worry about actual timestamps.

What I am asking about is the ugliness (in my view) of the code that gets executed when the event (ie the end of the delay) happens, it jumps into an "if" which is itself in a "switch". Perhaps the code could be tidied if I included a delay whether or not the player is attempting to avoid a blow so at least the code paths are a bit more consistent.

Re: Restructuring program

<5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=461&group=comp.lang.c%2B%2B#461

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:622a:1a95:b0:3fe:bde8:76ea with SMTP id s21-20020a05622a1a9500b003febde876eamr3076340qtc.0.1687297972233;
Tue, 20 Jun 2023 14:52:52 -0700 (PDT)
X-Received: by 2002:a05:622a:1312:b0:3f4:dde4:baf5 with SMTP id
v18-20020a05622a131200b003f4dde4baf5mr6040948qtk.13.1687297972063; Tue, 20
Jun 2023 14:52:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Tue, 20 Jun 2023 14:52:51 -0700 (PDT)
In-Reply-To: <u6st6c$2gts4$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=92.28.25.60; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 92.28.25.60
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com> <u6st6c$2gts4$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
Subject: Re: Restructuring program
From: gw7...@aol.com (Paul N)
Injection-Date: Tue, 20 Jun 2023 21:52:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1520
 by: Paul N - Tue, 20 Jun 2023 21:52 UTC

On Tuesday, June 20, 2023 at 8:03:56 PM UTC+1, Bonita Montero wrote:
> Don't use C function pointers in C++, use function<>-objects.

Can you give an example? There are no function pointers in the code as written, but there is an enum which indicates to which label a jump should be made.

Re: Restructuring program

<u6t7h4$2i2bp$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=462&group=comp.lang.c%2B%2B#462

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Restructuring program
Date: Tue, 20 Jun 2023 15:00:03 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <u6t7h4$2i2bp$1@dont-email.me>
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
<u6st6c$2gts4$1@dont-email.me>
<5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 20 Jun 2023 22:00:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7258a41a77ff0c7bd860b1dc777f9c31";
logging-data="2689401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ujpAcwSRIjINbSpnTsEZO0GBULAwBEYk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:4/4fyXYN7y+7mVY7B0rrL4167B8=
In-Reply-To: <5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
Content-Language: en-US
 by: Chris M. Thomasson - Tue, 20 Jun 2023 22:00 UTC

On 6/20/2023 2:52 PM, Paul N wrote:
> On Tuesday, June 20, 2023 at 8:03:56 PM UTC+1, Bonita Montero wrote:
>> Don't use C function pointers in C++, use function<>-objects.
>
> Can you give an example? There are no function pointers in the code as written, but there is an enum which indicates to which label a jump should be made.

Perhaps Bonita is referring to:

typedef struct
{ TIMESTAMP triggertime;
void (*function)(void *ptr);
void *ptr;
} DAEMON;

Written my Malcolm? Bonita omitted it in the response... ;^o

Re: Restructuring program

<u6uum8$2svq7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=464&group=comp.lang.c%2B%2B#464

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Restructuring program
Date: Wed, 21 Jun 2023 15:41:29 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <u6uum8$2svq7$1@dont-email.me>
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
<u6st6c$2gts4$1@dont-email.me>
<5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 21 Jun 2023 13:41:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1ba7c9f6cb98ec3afb40817e58ff946e";
logging-data="3047239"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5L323Yrqxr01Ck/V1l1qs9Y9vqIuAYnw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:33uZSaRfzBU+mqIXFOzorWWAjk8=
In-Reply-To: <5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Wed, 21 Jun 2023 13:41 UTC

Am 20.06.2023 um 23:52 schrieb Paul N:
> On Tuesday, June 20, 2023 at 8:03:56 PM UTC+1, Bonita Montero wrote:
>> Don't use C function pointers in C++, use function<>-objects.
>
> Can you give an example? There are no function pointers in the code as written, but there is an enum which indicates to which label a jump should be made.

That's an example:

void fileList( wchar_t const *path, function<bool ( WIN32_FIND_DATAW
const & )> const &callback )
{ WIN32_FIND_DATAW fd;
HANDLE hFind = FindFirstFileW( path, &fd );
int ec;
auto thr = [&]() { throw system_error( ec, system_category(), "error
with FindFirstFileW()" ); };
if( hFind == INVALID_HANDLE_VALUE )
if( (ec = GetLastError()) != ERROR_FILE_NOT_FOUND )
thr();
else
return;
for( ; ; )
{
if( !callback( fd ) )
goto bye;
if( !FindNextFileW( hFind, &fd ) )
if( (ec = GetLastError()) != ERROR_FILE_NOT_FOUND )
thr();
else
goto bye;
}
bye:
FindClose( hFind );
}

You can pass a lambda to fileList and it is automatically converted. If
you use a templated function object you'd have multiple instantiations
of fileList. With the above code you won't need to put the above code
into a header.

Re: Restructuring program

<u6v5nf$2ukq0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=465&group=comp.lang.c%2B%2B#465

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Restructuring program
Date: Wed, 21 Jun 2023 17:41:35 +0200
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <u6v5nf$2ukq0$1@dont-email.me>
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
<a3320e43-6518-418f-9603-f28e1dba8e3fn@googlegroups.com>
<u6st6c$2gts4$1@dont-email.me>
<5d3d07f6-bd46-4351-94fb-59d48be20842n@googlegroups.com>
<u6uum8$2svq7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 21 Jun 2023 15:41:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1ba7c9f6cb98ec3afb40817e58ff946e";
logging-data="3101504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18V+fYxwGV3z+i1CnRzVDQFNwWHM0+PjCU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Cancel-Lock: sha1:+liQFjlp1ruWn7UHWXK15ziyTlM=
Content-Language: de-DE
In-Reply-To: <u6uum8$2svq7$1@dont-email.me>
 by: Bonita Montero - Wed, 21 Jun 2023 15:41 UTC

More complete:

#include <Windows.h>
#include <iostream>
#include <functional>
#include <system_error>

using namespace std;

void fileList( wchar_t const *path, function<bool ( WIN32_FIND_DATAW
const & )> const &callback, char const *errWhat );

int main()
{ fileList( L"*", []( WIN32_FIND_DATAW const &fdw ) -> bool
{
wcout << fdw.cFileName << endl;
return true;
}, "error listing files" );
}

void fileList( wchar_t const *path, function<bool ( WIN32_FIND_DATAW
const & )> const &callback, char const *errWhat )
{ WIN32_FIND_DATAW fd;
HANDLE hFind = FindFirstFileW( path, &fd );
int ec;
auto thr = [&]() { throw system_error( ec, system_category(), errWhat ?
errWhat : "" ); };
if( hFind == INVALID_HANDLE_VALUE )
if( (ec = GetLastError()) != ERROR_FILE_NOT_FOUND )
thr();
else
return;
for( ; ; )
{
if( !callback( fd ) )
return (void)FindClose( hFind );
if( !FindNextFileW( hFind, &fd ) )
if( (ec = GetLastError()) != ERROR_NO_MORE_FILES )
thr();
else
return (void)FindClose( hFind );
}
}

Re: Restructuring program

<0f5568a3-2efa-41dd-8098-0c8719f41deen@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=470&group=comp.lang.c%2B%2B#470

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:622a:2ca:b0:3f6:a22f:a99c with SMTP id a10-20020a05622a02ca00b003f6a22fa99cmr8401443qtx.6.1687550323699;
Fri, 23 Jun 2023 12:58:43 -0700 (PDT)
X-Received: by 2002:a05:6870:a8a9:b0:1a9:950a:dca6 with SMTP id
eb41-20020a056870a8a900b001a9950adca6mr5881700oab.5.1687550323471; Fri, 23
Jun 2023 12:58:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Fri, 23 Jun 2023 12:58:43 -0700 (PDT)
In-Reply-To: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=92.28.30.231; posting-account=0B-afgoAAABP6274zLUJKa8ZpdIdhsYx
NNTP-Posting-Host: 92.28.30.231
References: <7a5bfab2-d5d7-44d6-b402-d69f74f36108n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0f5568a3-2efa-41dd-8098-0c8719f41deen@googlegroups.com>
Subject: Re: Restructuring program
From: gw7...@aol.com (Paul N)
Injection-Date: Fri, 23 Jun 2023 19:58:43 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2296
 by: Paul N - Fri, 23 Jun 2023 19:58 UTC

On Tuesday, June 20, 2023 at 12:03:47 PM UTC+1, Paul N wrote:
> But a Windows program is not supposed to sit around doing nothing. So this part now looks like:
>
> switch (mm) {
> case Bash:
> if (u == Duck) {
> m1 = _TEXT("Your attempted dodge - ");
> sleep(3, wait1);
> return;
> Wait1:
> if (random(20) < d) { m2 = _TEXT("success!"); break; }
> m2 = _TEXT("No luck."); }
> g1 = ((double)t / r) + 0.999; c -= g1;
> break;

I've managed to improve it a bit, as follows:

Wait1:
switch (mm) {
case Bash:
if (u == Duck) {
if (act != wait1) {
m1 = _TEXT("Your attempted dodge - ");
sleep(3, wait1);
return; }
if (random(20) < d) { m2 = _TEXT("success!"); break; }
m2 = _TEXT("No luck."); }
g1 = ((double)t / r) + 0.999; c -= g1;
break;

This version relies on mm and u not changing between the two invocations, so the Wait1: label is not now buried in an "if" or a "switch". Indeed, I may be able to use an outer "switch" to get rid of the "goto" altogether.

Any more improvements than anyone can see?


devel / comp.lang.c++ / Restructuring program

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor