Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Oh, I've seen copies [of Linux Journal] around the terminal room at The Labs. -- Dennis Ritchie


devel / comp.lang.awk / They're just typos (Was: cppawk: portable case statement.)

SubjectAuthor
* cppawk: portable case statement.Kaz Kylheku
`* Re: cppawk: portable case statement.Ed Morton
 `* Re: cppawk: portable case statement.Kaz Kylheku
  `* Re: cppawk: portable case statement.Ed Morton
   `- They're just typos (Was: cppawk: portable case statement.)Kenny McCormack

1
cppawk: portable case statement.

<20220327155223.842@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1172&group=comp.lang.awk#1172

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: cppawk: portable case statement.
Date: Mon, 28 Mar 2022 07:09:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <20220327155223.842@kylheku.com>
Injection-Date: Mon, 28 Mar 2022 07:09:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9f3df9d3c5d46b28e70404db37378c66";
logging-data="6878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aH8PmXdumHBYyMjcfCYlLfocfPpIn3Is="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:UMMCl782yG1aAiYmq3ZQwf8sz8o=
 by: Kaz Kylheku - Mon, 28 Mar 2022 07:09 UTC

GNU Awk has a switch statement.

In cppawk I made a case statement which translates to GNU Awk switch,
but supports non-GNU Awk.

Check this out:

#include <case.h>

{
case ($0) {
of ("foo") {
print "** foo case: fallthrough!"
}
of ("bar", "xyzzy") {
print "** bar/xyzzy case"
cbreak;
}
matching (/x/) {
print "** /x/ case"
cbreak;
}
otherwise {
print "** default"
}
}
}

Translate for GNU Awk:

$ ./cppawk --prepro-only -f case.cwk
# 1 "<stdin>"
[ snip ]
# 33 "./cppawk-include/case.h" 2
# 2 "case.cwk" 2

{
switch ($0) {
case "foo": {
print "** foo case: fallthrough!"
}
case "bar": case "xyzzy": {
print "** bar/xyzzy case"
break;
}
case /x/: {
print "** /x/ case"
break;
}
default: {
print "** default"
}
}
}

Translate for Mawk:

$ ./cppawk --prepro-only --awk=mawk -f case.cwk
# 1 "<stdin>"
[snip]
# 33 "./cppawk-include/case.h" 2
# 2 "case.cwk" 2

{
for ((__once = 1) && (__pass = 0) || (__val = $0); __once; __once = 0) {
if (__pass || ((__val == ("foo"))) && (__pass = 1)) {
print "** foo case: fallthrough!"
}
if (__pass || ((__val == ("bar")) || (__val == ("xyzzy"))) && (__pass = 1)) {
print "** bar/xyzzy case"
break;
}
if (__pass || ((__val ~ (/x/))) && (__pass = 1)) {
print "** /x/ case"
break;
}
if (__pass = 1) {
print "** default"
}
}
}

The temporary variables are a bit ugly. In a function you can declare them like
this:

function fun(arg1, arg2,
local_var, case_temps)

case_temps expands to __val, __once, __pass for that implementation.

Some test cases and tweaking is needed to get the construct to work if nested
with itself.

I may switch it (pun intended) to have no fallthough by default between cases.
Perhaps a fallthrough statement can request it explicitly. A good way to
do that when targetting the Gawk switch is not obvious.

Re: cppawk: portable case statement.

<t1sakg$tlm$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1174&group=comp.lang.awk#1174

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: cppawk: portable case statement.
Date: Mon, 28 Mar 2022 07:45:04 -0500
Organization: A noiseless patient Spider
Lines: 125
Message-ID: <t1sakg$tlm$1@dont-email.me>
References: <20220327155223.842@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 28 Mar 2022 12:45:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b83f6ea49277a1dbb8daccf82b3277b8";
logging-data="30390"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bJlvIyBOG33j07ABWGa7/"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:Ybo5setqUzu/ypoI9qupOXbUlJM=
In-Reply-To: <20220327155223.842@kylheku.com>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 220327-4, 3/27/2022), Outbound message
 by: Ed Morton - Mon, 28 Mar 2022 12:45 UTC

On 3/28/2022 2:09 AM, Kaz Kylheku wrote:
> GNU Awk has a switch statement.
>
> In cppawk I made a case statement which translates to GNU Awk switch,
> but supports non-GNU Awk.
>
> Check this out:
>
> #include <case.h>
>
> {
> case ($0) {
> of ("foo") {
> print "** foo case: fallthrough!"
> }
> of ("bar", "xyzzy") {
> print "** bar/xyzzy case"
> cbreak;
> }
> matching (/x/) {
> print "** /x/ case"
> cbreak;
> }
> otherwise {
> print "** default"
> }
> }
> }
>
> Translate for GNU Awk:
>
> $ ./cppawk --prepro-only -f case.cwk
> # 1 "<stdin>"
> [ snip ]
> # 33 "./cppawk-include/case.h" 2
> # 2 "case.cwk" 2
>
> {
> switch ($0) {
> case "foo": {
> print "** foo case: fallthrough!"
> }
> case "bar": case "xyzzy": {
> print "** bar/xyzzy case"
> break;
> }
> case /x/: {
> print "** /x/ case"
> break;
> }
> default: {
> print "** default"
> }
> }
> }
>
> Translate for Mawk:
>
> $ ./cppawk --prepro-only --awk=mawk -f case.cwk
> # 1 "<stdin>"
> [snip]
> # 33 "./cppawk-include/case.h" 2
> # 2 "case.cwk" 2
>
> {
> for ((__once = 1) && (__pass = 0) || (__val = $0); __once; __once = 0) {
> if (__pass || ((__val == ("foo"))) && (__pass = 1)) {
> print "** foo case: fallthrough!"
> }
> if (__pass || ((__val == ("bar")) || (__val == ("xyzzy"))) && (__pass = 1)) {
> print "** bar/xyzzy case"
> break;
> }
> if (__pass || ((__val ~ (/x/))) && (__pass = 1)) {
> print "** /x/ case"
> break;
> }
> if (__pass = 1) {
> print "** default"
> }
> }
> }
>
> The temporary variables are a bit ugly. In a function you can declare them like
> this:
>
> function fun(arg1, arg2,
> local_var, case_temps)
>
> case_temps expands to __val, __once, __pass for that implementation.
>
> Some test cases and tweaking is needed to get the construct to work if nested
> with itself.
>
> I may switch it (pun intended) to have no fallthough by default between cases.
> Perhaps a fallthrough statement can request it explicitly. A good way to
> do that when targetting the Gawk switch is not obvious.

If I want portable code why wouldn't I simply write portable code?

{
s = $0
if (s == "foo") {
print "** foo case: fallthrough!"
}
if ( (s == "bar") || (s == "xyzzy") ) {
print "** bar/xyzzy case"
}
else if (s ~ /x/) {
print "** /x/ case"
}
else {
print "** default"
}
}

With "cppawk" you seem to be solving a problem that doesn't exist by
creating a real problem - introducing a private tool that'd be required
to parse the code and the necessity for people to have to look up ".h"
files to figure out what the language constructs in the code mean and
the potential for the tokens in the .h files to clash with variables or
other language constructs used in the script.

Ed.

Re: cppawk: portable case statement.

<20220328150619.531@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1178&group=comp.lang.awk#1178

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: cppawk: portable case statement.
Date: Mon, 28 Mar 2022 22:52:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <20220328150619.531@kylheku.com>
References: <20220327155223.842@kylheku.com> <t1sakg$tlm$1@dont-email.me>
Injection-Date: Mon, 28 Mar 2022 22:52:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4e6a162cfd562490aabeac8279871962";
logging-data="4327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19susFPSb/rAnC8BkravTu54rPtwCMFERg="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:9dWaTipacoYDn+C2vXHGKV7K8G0=
 by: Kaz Kylheku - Mon, 28 Mar 2022 22:52 UTC

On 2022-03-28, Ed Morton <mortonspam@gmail.com> wrote:
> On 3/28/2022 2:09 AM, Kaz Kylheku wrote:
>> GNU Awk has a switch statement.
>>
>> In cppawk I made a case statement which translates to GNU Awk switch,
>> but supports non-GNU Awk.
>
> If I want portable code why wouldn't I simply write portable code?

My use case is that what I *have* is nonportable code, and I want
GNU Awk to keep seeing more or less that same nonportable code while
I make it run on another implementation also.

Furthermore, I have reached a more or less final version of the macro
which is safer to use than switch: each clause must explicitly break,
fall-through or return from the surrounding function. This is now a
syntax error:

case (state) {
of (1, 2, 3)
state++
of (4)
return 0
}

it has to be:

case (state) {
of (1, 2, 3)
state++
cbreak # explicit cbreak, cfall or cret() required
of (4)
cret (0)
}

The syntax error isn't something nice (just unbalanced braces), but it's
better than silence.

> s = $0
> if (s == "foo") {
> print "** foo case: fallthrough!"
> }
> if ( (s == "bar") || (s == "xyzzy") ) {
> print "** bar/xyzzy case"
> }

This translation doesn't preserve the fallthrough; so while we have
portable code now, it has succumbed to human error.

I will make fewer conversion mistakes with a macro whose features
closely mimic switch, and which can be separately validated by its own
test cases.

> With "cppawk" you seem to be solving a problem that doesn't exist by
> creating a real problem - introducing a private tool that'd be required

I released this to the public, under a BSD license. It relies on other
commonly available and installed public tools.

> to parse the code and the necessity for people to have to look up ".h"
> files to figure out what the language constructs in the code mean and

That could be a problem in a project without documentation.
Oh, look; good thing I have that!

$ man -l cppawk-case.1
CPPAWK-CASE(1) Case Macro CPPAWK-CASE(1)

NAME
case - macro for portable switch statement

SYNOPSIS
#include <case.h>
[...]

> the potential for the tokens in the .h files to clash with variables or
> other language constructs used in the script.

While it's certainly possible to make a dog's breakfast of this, I'm
consciously following best practices for header file hygiene, because
that is super important in a tool like this. I'm hardly a beginner.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: cppawk: portable case statement.

<t1utgk$s11$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1182&group=comp.lang.awk#1182

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: cppawk: portable case statement.
Date: Tue, 29 Mar 2022 07:19:31 -0500
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <t1utgk$s11$1@dont-email.me>
References: <20220327155223.842@kylheku.com> <t1sakg$tlm$1@dont-email.me>
<20220328150619.531@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 29 Mar 2022 12:19:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="1c12b6d6b86ad08024fab560bebed460";
logging-data="28705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ffkCz5tqABtmjy3ncPNK0"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:ZdSaEoWXqvo/DLr0nSFNpYWKGjo=
In-Reply-To: <20220328150619.531@kylheku.com>
X-Antivirus-Status: Clean
Content-Language: en-US
X-Antivirus: Avast (VPS 220329-0, 3/28/2022), Outbound message
 by: Ed Morton - Tue, 29 Mar 2022 12:19 UTC

On 3/28/2022 5:52 PM, Kaz Kylheku wrote:
> On 2022-03-28, Ed Morton <mortonspam@gmail.com> wrote:
>> On 3/28/2022 2:09 AM, Kaz Kylheku wrote:
>>> GNU Awk has a switch statement.
>>>
>>> In cppawk I made a case statement which translates to GNU Awk switch,
>>> but supports non-GNU Awk.
>>
>> If I want portable code why wouldn't I simply write portable code?
>
> My use case is that what I *have* is nonportable code, and I want
> GNU Awk to keep seeing more or less that same nonportable code while
> I make it run on another implementation also.
>
> Furthermore, I have reached a more or less final version of the macro
> which is safer to use than switch: each clause must explicitly break,
> fall-through or return from the surrounding function. This is now a
> syntax error:
>
> case (state) {
> of (1, 2, 3)
> state++
> of (4)
> return 0
> }
>
> it has to be:
>
> case (state) {
> of (1, 2, 3)
> state++
> cbreak # explicit cbreak, cfall or cret() required
> of (4)
> cret (0)
> }
>
> The syntax error isn't something nice (just unbalanced braces), but it's
> better than silence.
>
>> s = $0
>> if (s == "foo") {
>> print "** foo case: fallthrough!"
>> }
>> if ( (s == "bar") || (s == "xyzzy") ) {
>> print "** bar/xyzzy case"
>> }
>
> This translation doesn't preserve the fallthrough;

Yeah, looks like I forgot how a "fallthrough" worked and thought the
next condition would be tested before the associated action was
executed. It's been a long time since I wrote such code.

so while we have
> portable code now, it has succumbed to human error.

The error was just in my understanding of what your code does, not in my
writing code to do what I intended it to do.

Ed.

>
> I will make fewer conversion mistakes with a macro whose features
> closely mimic switch, and which can be separately validated by its own
> test cases.
>
>> With "cppawk" you seem to be solving a problem that doesn't exist by
>> creating a real problem - introducing a private tool that'd be required
>
> I released this to the public, under a BSD license. It relies on other
> commonly available and installed public tools.
>
>> to parse the code and the necessity for people to have to look up ".h"
>> files to figure out what the language constructs in the code mean and
>
> That could be a problem in a project without documentation.
> Oh, look; good thing I have that!
>
> $ man -l cppawk-case.1
> CPPAWK-CASE(1) Case Macro CPPAWK-CASE(1)
>
> NAME
> case - macro for portable switch statement
>
> SYNOPSIS
> #include <case.h>
> [...]
>
>> the potential for the tokens in the .h files to clash with variables or
>> other language constructs used in the script.
>
> While it's certainly possible to make a dog's breakfast of this, I'm
> consciously following best practices for header file hygiene, because
> that is super important in a tool like this. I'm hardly a beginner.
>

They're just typos (Was: cppawk: portable case statement.)

<t1utun$28eg5$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1183&group=comp.lang.awk#1183

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: They're just typos (Was: cppawk: portable case statement.)
Date: Tue, 29 Mar 2022 12:27:04 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t1utun$28eg5$1@news.xmission.com>
References: <20220327155223.842@kylheku.com> <t1sakg$tlm$1@dont-email.me> <20220328150619.531@kylheku.com> <t1utgk$s11$1@dont-email.me>
Injection-Date: Tue, 29 Mar 2022 12:27:04 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2374149"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 29 Mar 2022 12:27 UTC

In article <t1utgk$s11$1@dont-email.me>,
A raving lunatic <mortonspam@gmail.com> wrote:
....
>The error was just in my understanding of what your code does, not in my
>writing code to do what I intended it to do.

Said every buggy programmer ever.

--
People who want to share their religious views with you
almost never want you to share yours with them. -- Dave Barry

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor