Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Never ascribe to malice that which is caused by greed and ignorance." -- Cal Keegan


devel / comp.lang.c / Commandline parsing

SubjectAuthor
* Commandline parsingMalcolm McLean
+- Re: Commandline parsingLew Pitcher
+- Re: Commandline parsingScott Lurndal
+- Re: Commandline parsingSpiros Bousbouras
+* Re: Commandline parsingKenny McCormack
|`- Re: Commandline parsingMalcolm McLean
+* Re: Commandline parsingLynn McGuire
|+* Re: Commandline parsingLynn McGuire
||`* Re: Commandline parsingMalcolm McLean
|| `* Re: Commandline parsingKeith Thompson
||  `- Re: Commandline parsingMalcolm McLean
|+- Re: Commandline parsingKaz Kylheku
|`- Re: Commandline parsingSpiros Bousbouras
+* Re: Commandline parsingBlue-Maned_Hawk
|+- Re: Commandline parsingMalcolm McLean
|`* Re: Commandline parsingKeith Thompson
| `- Re: Commandline parsingKaz Kylheku
+* Re: Commandline parsingfir
|+* Re: Commandline parsingScott Lurndal
||`- Re: Commandline parsingfir
|`* Re: Commandline parsingMalcolm McLean
| +* Re: Commandline parsingfir
| |`* Re: Commandline parsingfir
| | `* Re: Commandline parsingfir
| |  +* Re: Commandline parsingfir
| |  |`- Re: Commandline parsingfir
| |  +- Re: Commandline parsingfir
| |  `* Re: Commandline parsingfir
| |   `- Re: Commandline parsingfir
| `- Re: Commandline parsingfir
+- Re: Commandline parsingMichael S
`- Re: Commandline parsingJoe Pfeiffer

Pages:12
Commandline parsing

<a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a26:b0:405:47dc:d05d with SMTP id f38-20020a05622a1a2600b0040547dcd05dmr7309qtb.4.1690385698035;
Wed, 26 Jul 2023 08:34:58 -0700 (PDT)
X-Received: by 2002:a05:6870:3a10:b0:1ba:a5d1:a579 with SMTP id
du16-20020a0568703a1000b001baa5d1a579mr3903828oab.4.1690385697680; Wed, 26
Jul 2023 08:34:57 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 26 Jul 2023 08:34:57 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
Subject: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 26 Jul 2023 15:34:58 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Wed, 26 Jul 2023 15:34 UTC

Just realised that my options parser isn't publically available, which I have just remedied.

What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?

Re: Commandline parsing

<u9rem2$1h2ik$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Wed, 26 Jul 2023 15:38:43 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 20
Message-ID: <u9rem2$1h2ik$2@dont-email.me>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 26 Jul 2023 15:38:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4f4fdb937d31d90ca6ab18c4ae36868a";
logging-data="1608276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1xXVAgp69HUtCvc8fVh+VvQzFiMHLPFE="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:HwSCc1zcC2dMCZEMU1WPtFJoKuQ=
 by: Lew Pitcher - Wed, 26 Jul 2023 15:38 UTC

On Wed, 26 Jul 2023 08:34:57 -0700, Malcolm McLean wrote:

> Just realised that my options parser isn't publically available,
> which I have just remedied.
>
> What approaches do people use towards parsing commandline
> options? Do you use getopt() ? Or do you find that real world
> programs have a simple enough set of options that it's easier
> to write bespoke code?

For simple commandlines, I usually write my own argument
"parser" (typically a set of strcmp() calls). For more complex
commandlines, I stick with getopt().

I haven't found any commandlines yet that require lex&yacc, but
I still keep looking for them (yes, I like the challenge :-) )

--
Lew Pitcher
"In Skills We Trust"

Re: Commandline parsing

<%qbwM.203240$TPw2.19626@fx17.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Commandline parsing
Newsgroups: comp.lang.c
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
Lines: 7
Message-ID: <%qbwM.203240$TPw2.19626@fx17.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 26 Jul 2023 16:00:59 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 26 Jul 2023 16:00:59 GMT
X-Received-Bytes: 961
 by: Scott Lurndal - Wed, 26 Jul 2023 16:00 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>Just realised that my options parser isn't publically available, which I have just remedied.
>
>What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?

getopt. always.

Re: Commandline parsing

<5QkjyexhaGA39yej3@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Wed, 26 Jul 2023 16:17:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <5QkjyexhaGA39yej3@bongo-ra.co>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 26 Jul 2023 16:17:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b77f4ba695e3df609b663904ee91e3ba";
logging-data="1630008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LcEg9N7RwLc61hOcBmyDI"
Cancel-Lock: sha1:cu3OEC5+W7YC4gbYbneWNI1cns4=
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
In-Reply-To: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
 by: Spiros Bousbouras - Wed, 26 Jul 2023 16:17 UTC

On Wed, 26 Jul 2023 08:34:57 -0700 (PDT) Malcolm McLean
<malcolm.arthur.mclean@gmail.com> wrote:
> Just realised that my options parser isn't publically available, which I
> have just remedied.
>
> What approaches do people use towards parsing commandline options ? Do you
> use getopt() ? Or do you find that real world programs have a simple enough
> set of options that it's easier to write bespoke code?

Custom made. Nothing fancy , never needed it.

Re: Commandline parsing

<u9rh91$2os5a$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Wed, 26 Jul 2023 16:22:57 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <u9rh91$2os5a$1@news.xmission.com>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
Injection-Date: Wed, 26 Jul 2023 16:22:57 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2912426"; 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 - Wed, 26 Jul 2023 16:22 UTC

In article <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>,
Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>Just realised that my options parser isn't publically available, which
>I have just remedied.

URL?

--
I shot a man on Fifth Aveneue, just to see him die.

Re: Commandline parsing

<d780bbf2-cf86-480e-a166-5c3f4bbee51en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:388:b0:406:94da:5abd with SMTP id j8-20020a05622a038800b0040694da5abdmr8318qtx.12.1690388802772;
Wed, 26 Jul 2023 09:26:42 -0700 (PDT)
X-Received: by 2002:a05:6870:771a:b0:1bb:55f5:bca5 with SMTP id
dw26-20020a056870771a00b001bb55f5bca5mr3969207oab.8.1690388802333; Wed, 26
Jul 2023 09:26:42 -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: Wed, 26 Jul 2023 09:26:41 -0700 (PDT)
In-Reply-To: <u9rh91$2os5a$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com> <u9rh91$2os5a$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d780bbf2-cf86-480e-a166-5c3f4bbee51en@googlegroups.com>
Subject: Re: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 26 Jul 2023 16:26:42 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1701
 by: Malcolm McLean - Wed, 26 Jul 2023 16:26 UTC

On Wednesday, 26 July 2023 at 17:23:11 UTC+1, Kenny McCormack wrote:
> In article <a631f98c-5482-4e90...@googlegroups.com>,
> Malcolm McLean <malcolm.ar...@gmail.com> wrote:
> >Just realised that my options parser isn't publically available, which
> >I have just remedied.
> URL?
>
https://github.com/MalcolmMcLean/optionparser
>
But I's like a discussion about what people would like to see in an options parser
rather than focusing too much on the specifics of my code in the first instance.

Re: Commandline parsing

<u9s6me$1k44g$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lynnmcgu...@gmail.com (Lynn McGuire)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Wed, 26 Jul 2023 17:28:30 -0500
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <u9s6me$1k44g$1@dont-email.me>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 26 Jul 2023 22:28:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1ae12a0f3d88e57de942718fdec8e98c";
logging-data="1708176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ECCcLrXH1akRRL6AnizFpa7DlYF3busg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.1
Cancel-Lock: sha1:KKTvZvkJ0p/RnUsMsbIJpJQC8AM=
In-Reply-To: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
Content-Language: en-US
 by: Lynn McGuire - Wed, 26 Jul 2023 22:28 UTC

On 7/26/2023 10:34 AM, Malcolm McLean wrote:
> Just realised that my options parser isn't publically available, which I have just remedied.
>
> What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?

And what do you do about Unicode on your command line ?

Lynn

Re: Commandline parsing

<u9s7l3$1k437$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lynnmcgu...@gmail.com (Lynn McGuire)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Wed, 26 Jul 2023 17:44:51 -0500
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <u9s7l3$1k437$1@dont-email.me>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9s6me$1k44g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 26 Jul 2023 22:44:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1ae12a0f3d88e57de942718fdec8e98c";
logging-data="1708135"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19U8ukJpQ5CaOnNa+Zz/LZa0Q1e2a8QkEo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.1
Cancel-Lock: sha1:HgFUvoZ6tjBBrnOVQIumLwq0U8g=
In-Reply-To: <u9s6me$1k44g$1@dont-email.me>
Content-Language: en-US
 by: Lynn McGuire - Wed, 26 Jul 2023 22:44 UTC

On 7/26/2023 5:28 PM, Lynn McGuire wrote:
> On 7/26/2023 10:34 AM, Malcolm McLean wrote:
>> Just realised that my options parser isn't publically available, which
>> I have just remedied.
>>
>> What approaches do people use towards parsing commandline options ? Do
>> you use getopt() ? Or do you find that real world programs have a
>> simple enough set of options that it's easier to write bespoke code?
>
> And what do you do about Unicode on your command line ?
>
> Lynn

BTW, we rolled our own command line parser that handles Unicode.

Lynn

Re: Commandline parsing

<20230726173129.737@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 00:32:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <20230726173129.737@kylheku.com>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9s6me$1k44g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Jul 2023 00:32:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8b46a856f685959d89dbb9806175f5b3";
logging-data="1731609"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gvvRIEJR8T/kcETcnwC70yd/08Lx18Do="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:jsrsSBmXG+IaY5NhwpPXgx03ipg=
 by: Kaz Kylheku - Thu, 27 Jul 2023 00:32 UTC

On 2023-07-26, Lynn McGuire <lynnmcguire5@gmail.com> wrote:
> On 7/26/2023 10:34 AM, Malcolm McLean wrote:
>> Just realised that my options parser isn't publically available, which I have just remedied.
>>
>> What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
>
> And what do you do about Unicode on your command line ?

That's just another UTF-8 input; same as from a text stream.

$ txr -e '(put-line "日本語")'
日本語

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Commandline parsing

<u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@gmail.com (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 04:00:03 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: base64
Injection-Date: Thu, 27 Jul 2023 08:00:04 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="44e9411fe8ca997db91709922f94e7b2";
logging-data="1934186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YLajGYh090FnxOXx24p3oTIpUYkgCq9M="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:Ic0YEQtNgxAG0dm+QrnRbKvvl0k=
Content-Language: en-US
In-Reply-To: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
 by: Blue-Maned_Hawk - Thu, 27 Jul 2023 08:00 UTC

On 7/26/23 11:34, Malcolm McLean wrote:
> Just realised that my options parser isn't publically available, which I have just remedied.
>
> What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
​I've only written one program where i had to deal with command-line
options, and when that happened i just used getopt(). That being said,
were i to write any more programs like that i don't think i'd use it, in
part because i think that the paradigm of the option is wantonly applied
to every program without consideration for whether it's most optimal
because it's just what everyone is used to.
--
⚗︎ | /blu.mɛin.dʰak/ | shortens to "Hawk" | he/him/his/himself/Mr.
bluemanedhawk.github.io
Bitches stole my whole ass ␔🭖᷿᪳𝼗᷍⏧𒒫𐻾ࣛ↉�⃣ quoted-printable, can't
have shit in Thunderbird 😩

Re: Commandline parsing

<d2e0e64a-2660-459d-adc4-c0c95019eaa5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:1928:b0:63d:2de5:be1d with SMTP id es8-20020a056214192800b0063d2de5be1dmr11819qvb.11.1690447172813;
Thu, 27 Jul 2023 01:39:32 -0700 (PDT)
X-Received: by 2002:a05:6830:1616:b0:6b9:2381:af59 with SMTP id
g22-20020a056830161600b006b92381af59mr7160310otr.2.1690447172457; Thu, 27 Jul
2023 01:39:32 -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: Thu, 27 Jul 2023 01:39:32 -0700 (PDT)
In-Reply-To: <u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com> <u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d2e0e64a-2660-459d-adc4-c0c95019eaa5n@googlegroups.com>
Subject: Re: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Thu, 27 Jul 2023 08:39:32 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2386
 by: Malcolm McLean - Thu, 27 Jul 2023 08:39 UTC

On Thursday, 27 July 2023 at 09:00:26 UTC+1, Blue-Maned_Hawk wrote:
> On 7/26/23 11:34, Malcolm McLean wrote:
> > Just realised that my options parser isn't publically available, which I have just remedied.
> >
> > What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> ​I've only written one program where i had to deal with command-line
> options, and when that happened i just used getopt(). That being said,
> were i to write any more programs like that i don't think i'd use it, in
> part because i think that the paradigm of the option is wantonly applied
> to every program without consideration for whether it's most optimal
> because it's just what everyone is used to.
>
I don't write commandline programs at work. Whilst I can imagine circumstances
in which that changed, a utility would most likely be in Python. For hobby programs,
it's also rare to need many options.

Re: Commandline parsing

<c092bdea-d2d1-4434-8a92-31da87d99c6cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:144e:b0:405:3a8b:b7e0 with SMTP id v14-20020a05622a144e00b004053a8bb7e0mr14270qtx.13.1690447584121;
Thu, 27 Jul 2023 01:46:24 -0700 (PDT)
X-Received: by 2002:a05:6808:23d3:b0:3a2:943d:da3e with SMTP id
bq19-20020a05680823d300b003a2943dda3emr4770646oib.1.1690447583889; Thu, 27
Jul 2023 01:46:23 -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: Thu, 27 Jul 2023 01:46:23 -0700 (PDT)
In-Reply-To: <u9s7l3$1k437$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9s6me$1k44g$1@dont-email.me> <u9s7l3$1k437$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c092bdea-d2d1-4434-8a92-31da87d99c6cn@googlegroups.com>
Subject: Re: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Thu, 27 Jul 2023 08:46:24 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2225
 by: Malcolm McLean - Thu, 27 Jul 2023 08:46 UTC

On Wednesday, 26 July 2023 at 23:45:06 UTC+1, Lynn McGuire wrote:
> On 7/26/2023 5:28 PM, Lynn McGuire wrote:
> > On 7/26/2023 10:34 AM, Malcolm McLean wrote:
> >> Just realised that my options parser isn't publically available, which
> >> I have just remedied.
> >>
> >> What approaches do people use towards parsing commandline options ? Do
> >> you use getopt() ? Or do you find that real world programs have a
> >> simple enough set of options that it's easier to write bespoke code?
> >
> > And what do you do about Unicode on your command line ?
> >
> > Lynn
> BTW, we rolled our own command line parser that handles Unicode.
>
You'd need to tweak the options parser slightly because it has a concept of
single character flags (so the user types something like "tar -xvf file.tar" he's
not passing one option "xvf", but three flags). So it would have to be UTF-8
aware to accomodate Unicode flags. Long options should work tranparently.
It's maybe a worthwhile change.

Re: Commandline parsing

<878rb1ptyb.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 02:47:08 -0700
Organization: None to speak of
Lines: 36
Message-ID: <878rb1ptyb.fsf@nosuchdomain.example.com>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9s6me$1k44g$1@dont-email.me> <u9s7l3$1k437$1@dont-email.me>
<c092bdea-d2d1-4434-8a92-31da87d99c6cn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f8957b03f6dc45951cee385c25f0e511";
logging-data="1953989"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qpLFm9pvTcPBAcYNe0zSd"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:YSs+NZI2pDBf5G1wcEVkCs0b5qQ=
sha1:PnN86VCWJlrIKmQiW+JPoYmz47s=
 by: Keith Thompson - Thu, 27 Jul 2023 09:47 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> On Wednesday, 26 July 2023 at 23:45:06 UTC+1, Lynn McGuire wrote:
>> On 7/26/2023 5:28 PM, Lynn McGuire wrote:
>> > On 7/26/2023 10:34 AM, Malcolm McLean wrote:
>> >> Just realised that my options parser isn't publically available, which
>> >> I have just remedied.
>> >>
>> >> What approaches do people use towards parsing commandline options ? Do
>> >> you use getopt() ? Or do you find that real world programs have a
>> >> simple enough set of options that it's easier to write bespoke code?
>> >
>> > And what do you do about Unicode on your command line ?
>> >
>> > Lynn
>> BTW, we rolled our own command line parser that handles Unicode.
>>
> You'd need to tweak the options parser slightly because it has a
> concept of single character flags (so the user types something like
> "tar -xvf file.tar" he's not passing one option "xvf", but three
> flags). So it would have to be UTF-8 aware to accomodate Unicode
> flags. Long options should work tranparently. It's maybe a worthwhile
> change.

I've never seen an option name that uses non-ASCII characters. The vast
majority of option names use just letters, mostly lowercase --
sometimes digits, and hyphens or rarely underscores for long option
names.

Handling full UTF-8 for *arguments* to options is useful. Requiring
non-ASCII characters as option names is going to make commands difficult
to type for a lot of users.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Commandline parsing

<874jlpptx8.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 02:47:47 -0700
Organization: None to speak of
Lines: 21
Message-ID: <874jlpptx8.fsf@nosuchdomain.example.com>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="f8957b03f6dc45951cee385c25f0e511";
logging-data="1953989"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2fbnB5tnEwPRKJZj/RFkk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:/klsg7omyJVU+48FSQ3NjpiOekM=
sha1:+gruvveMgfHi2kub+nZAyjf4E7I=
 by: Keith Thompson - Thu, 27 Jul 2023 09:47 UTC

Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
> On 7/26/23 11:34, Malcolm McLean wrote:
>> Just realised that my options parser isn't publically available,
>> which I have just remedied. What approaches do people use towards
>> parsing commandline options ? Do you use getopt() ? Or do you find
>> that real world programs have a simple enough set of options that
>> it's easier to write bespoke code?
>
> ​I've only written one program where i had to deal with command-line
> options, and when that happened i just used getopt(). That being
> said, were i to write any more programs like that i don't think i'd
> use it, in part because i think that the paradigm of the option is
> wantonly applied to every program without consideration for whether
> it's most optimal because it's just what everyone is used to.

What is your alternative to "the paradigm of the option"?

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Commandline parsing

<b191678d-cd16-4a9f-90e9-5499ca6460d9n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:152:b0:765:a62b:c5b6 with SMTP id e18-20020a05620a015200b00765a62bc5b6mr11526qkn.1.1690452725723;
Thu, 27 Jul 2023 03:12:05 -0700 (PDT)
X-Received: by 2002:a05:6808:2190:b0:3a5:b027:cca3 with SMTP id
be16-20020a056808219000b003a5b027cca3mr4907650oib.4.1690452725368; Thu, 27
Jul 2023 03:12:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.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: Thu, 27 Jul 2023 03:12:04 -0700 (PDT)
In-Reply-To: <878rb1ptyb.fsf@nosuchdomain.example.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:dd30:b3b3:c3fe:88aa
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9s6me$1k44g$1@dont-email.me> <u9s7l3$1k437$1@dont-email.me>
<c092bdea-d2d1-4434-8a92-31da87d99c6cn@googlegroups.com> <878rb1ptyb.fsf@nosuchdomain.example.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b191678d-cd16-4a9f-90e9-5499ca6460d9n@googlegroups.com>
Subject: Re: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Thu, 27 Jul 2023 10:12:05 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3473
 by: Malcolm McLean - Thu, 27 Jul 2023 10:12 UTC

On Thursday, 27 July 2023 at 10:47:22 UTC+1, Keith Thompson wrote:
> Malcolm McLean <malcolm.ar...@gmail.com> writes:
> > On Wednesday, 26 July 2023 at 23:45:06 UTC+1, Lynn McGuire wrote:
> >> On 7/26/2023 5:28 PM, Lynn McGuire wrote:
> >> > On 7/26/2023 10:34 AM, Malcolm McLean wrote:
> >> >> Just realised that my options parser isn't publically available, which
> >> >> I have just remedied.
> >> >>
> >> >> What approaches do people use towards parsing commandline options ? Do
> >> >> you use getopt() ? Or do you find that real world programs have a
> >> >> simple enough set of options that it's easier to write bespoke code?
> >> >
> >> > And what do you do about Unicode on your command line ?
> >> >
> >> > Lynn
> >> BTW, we rolled our own command line parser that handles Unicode.
> >>
> > You'd need to tweak the options parser slightly because it has a
> > concept of single character flags (so the user types something like
> > "tar -xvf file.tar" he's not passing one option "xvf", but three
> > flags). So it would have to be UTF-8 aware to accomodate Unicode
> > flags. Long options should work tranparently. It's maybe a worthwhile
> > change.
> I've never seen an option name that uses non-ASCII characters. The vast
> majority of option names use just letters, mostly lowercase --
> sometimes digits, and hyphens or rarely underscores for long option
> names.
>
That's worth knowing.
> Handling full UTF-8 for *arguments* to options is useful. Requiring
> non-ASCII characters as option names is going to make commands difficult
> to type for a lot of users.
>
The options parser is UTF-8 naive. So a filename with high Unicode characters
would just pass through. Similarly if you provide a long option with UTF-8,
that would be parsed. However currently it also takes a list of flags. These
are teated as single characters, so if you pass UTF-8, values over 127 will
be incorrectly treated.
If you are passed UTF-16 on the comandline, you'd have to convert to UTF-8.

Re: Commandline parsing

<HILg6E9lwcSXBfGLg@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 16:17:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <HILg6E9lwcSXBfGLg@bongo-ra.co>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com> <u9s6me$1k44g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Jul 2023 16:17:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5be96a2ef177e71063c2ed25abddbe2";
logging-data="2026705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//wmI6IBTHdc23FnH44QOr"
Cancel-Lock: sha1:Al/Y3HfsERZwVtbdr18SjGyntS8=
In-Reply-To: <u9s6me$1k44g$1@dont-email.me>
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Thu, 27 Jul 2023 16:17 UTC

On Wed, 26 Jul 2023 17:28:30 -0500
Lynn McGuire <lynnmcguire5@gmail.com> wrote:
> On 7/26/2023 10:34 AM, Malcolm McLean wrote:
> > Just realised that my options parser isn't publically available, which I have just remedied.
> >
> > What approaches do people use towards parsing commandline options ? Do
> > you use getopt() ? Or do you find that real world programs have a simple
> > enough set of options that it's easier to write bespoke code?
>
> And what do you do about Unicode on your command line ?

Nothing. I don't have options whose name includes (non ASCII) unicode and for
arguments which are not of a specialised nature (like numbers) , handling them
as an array of octets works fine. For example , pathnames on a Unix system
are arrays of octets so you just take the command line argument and you pass
it to fopen() .

Re: Commandline parsing

<20230727100504.323@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Commandline parsing
Date: Thu, 27 Jul 2023 17:29:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <20230727100504.323@kylheku.com>
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<u9t864$1r0ra$1@bluemanedhawk.eternal-september.org>
<874jlpptx8.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 27 Jul 2023 17:29:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8b46a856f685959d89dbb9806175f5b3";
logging-data="2044112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/B3BhZ9gX7x7X1/oYl3AeELe/L9Z3jNI4="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:C+TpTgKE6d+5Hvu4W17in/QhNeU=
 by: Kaz Kylheku - Thu, 27 Jul 2023 17:29 UTC

On 2023-07-27, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Blue-Maned_Hawk <bluemanedhawk@gmail.com> writes:
>> On 7/26/23 11:34, Malcolm McLean wrote:
>>> Just realised that my options parser isn't publically available,
>>> which I have just remedied. What approaches do people use towards
>>> parsing commandline options ? Do you use getopt() ? Or do you find
>>> that real world programs have a simple enough set of options that
>>> it's easier to write bespoke code?
>>
>> ​I've only written one program where i had to deal with command-line
>> options, and when that happened i just used getopt(). That being
>> said, were i to write any more programs like that i don't think i'd
>> use it, in part because i think that the paradigm of the option is
>> wantonly applied to every program without consideration for whether
>> it's most optimal because it's just what everyone is used to.
>
> What is your alternative to "the paradigm of the option"?

One is environment variables.

Imagine the dd utility, with its keyword parameters:

dd if=this of=that count=42

If dd were converted to look up in the environment instead of the comand
line, then (in POSIX shell syntax), it could be invoked like this:

if=this of=that count=42 dd

It gets cumbersome to run such a program with fork and exec, because
there isn't any API for doing an exec with an environment array that
augments the current environment, rather than replacing it. Only if the
program (and its children, if any) never need any environment variables
other than the ones in its API, execv can be used.

Also, if a program needs other environment variables, then the problem
is that the argument ones are mixed up with the others; you don't have
nice "get me all my keyword arguments" access without naming all of
them. It's impossible to diagnose typos. If an argument is misspelled,
it disappears into the environment; the program has no way of knowing it
was one of the argument-like variables specified for that call.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Commandline parsing

<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1999:b0:403:e8cd:284c with SMTP id u25-20020a05622a199900b00403e8cd284cmr36528qtc.12.1690817338796;
Mon, 31 Jul 2023 08:28:58 -0700 (PDT)
X-Received: by 2002:a05:6830:348d:b0:6b8:a385:c971 with SMTP id
c13-20020a056830348d00b006b8a385c971mr25021417otu.3.1690817338582; Mon, 31
Jul 2023 08:28:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 31 Jul 2023 08:28:58 -0700 (PDT)
In-Reply-To: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.125; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.125
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 15:28:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Mon, 31 Jul 2023 15:28 UTC

środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> Just realised that my options parser isn't publically available, which I have just remedied.
>
> What approaches do people use towards parsing commandline options ? Do you use getopt() ? Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?

i may not understand about what this topic is but in org-asm for comandline i use something most trivial

void ConsumeCommandlineOption(char* option)
{ if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
if( strcmp ( option, "-console" )==0) show_console = 1; else
if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
printf("\n ++++ option %s not reckognized and ignored ", option);

}
char* input_file_name = "input.asm";
char* output_file_name = "asm-result.exe";

int ConsumeCommandlineOptions(int argc, char* argv[])
{ if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
if(argc>=2) { input_file_name = argv[1]; }
if(argc>=3) { output_file_name = argv[2]; }
if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }

return 'ok';
}

its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as afair its a bit raw function, also this %s im not sure if its safe

Re: Commandline parsing

<XmRxM.40034$VPEa.25465@fx33.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx33.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Commandline parsing
Newsgroups: comp.lang.c
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com> <00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com>
Lines: 16
Message-ID: <XmRxM.40034$VPEa.25465@fx33.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 31 Jul 2023 16:32:55 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 31 Jul 2023 16:32:55 GMT
X-Received-Bytes: 1330
 by: Scott Lurndal - Mon, 31 Jul 2023 16:32 UTC

fir <profesor.fir@gmail.com> writes:
>=C5=9Broda, 26 lipca 2023 o=C2=A017:35:05 UTC+2 Malcolm McLean napisa=C5=82=
>(a):
>> Just realised that my options parser isn't publically available, which I =
>have just remedied.=20
>>=20
>> What approaches do people use towards parsing commandline options ? Do yo=
>u use getopt() ? Or do you find that real world programs have a simple enou=
>gh set of options that it's easier to write bespoke code?
>
>i may not understand about what this topic is but in org-asm for comandline=
> i use something most trivial=20

You may wish to familiarize yourself with this:

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Re: Commandline parsing

<5cf8744f-223c-418c-8eb6-ee3810eeffe5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5e08:0:b0:403:a721:3e5f with SMTP id h8-20020ac85e08000000b00403a7213e5fmr41772qtx.7.1690821824787;
Mon, 31 Jul 2023 09:43:44 -0700 (PDT)
X-Received: by 2002:a05:6808:d47:b0:3a1:f295:3e with SMTP id
w7-20020a0568080d4700b003a1f295003emr19389438oik.1.1690821824522; Mon, 31 Jul
2023 09:43:44 -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: Mon, 31 Jul 2023 09:43:44 -0700 (PDT)
In-Reply-To: <XmRxM.40034$VPEa.25465@fx33.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.118; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.118
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com> <XmRxM.40034$VPEa.25465@fx33.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5cf8744f-223c-418c-8eb6-ee3810eeffe5n@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 16:43:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2181
 by: fir - Mon, 31 Jul 2023 16:43 UTC

poniedziałek, 31 lipca 2023 o 18:33:10 UTC+2 Scott Lurndal napisał(a):
> fir <profes...@gmail.com> writes:
> >=C5=9Broda, 26 lipca 2023 o=C2=A017:35:05 UTC+2 Malcolm McLean napisa=C5=82=
> >(a):
> >> Just realised that my options parser isn't publically available, which I =
> >have just remedied.=20
> >>=20
> >> What approaches do people use towards parsing commandline options ? Do yo=
> >u use getopt() ? Or do you find that real world programs have a simple enou> >gh set of options that it's easier to write bespoke code?
> >
> >i may not understand about what this topic is but in org-asm for comandline=
> > i use something most trivial=20
>
> You may wish to familiarize yourself with this:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

okay, though not now..right now the trivial syntax i use is okay to me

Re: Commandline parsing

<0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5906:0:b0:403:b6b0:bdb5 with SMTP id 6-20020ac85906000000b00403b6b0bdb5mr35776qty.7.1690821963227;
Mon, 31 Jul 2023 09:46:03 -0700 (PDT)
X-Received: by 2002:a05:6870:1a8f:b0:1b0:2eab:e7e2 with SMTP id
ef15-20020a0568701a8f00b001b02eabe7e2mr12652890oab.0.1690821962920; Mon, 31
Jul 2023 09:46:02 -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: Mon, 31 Jul 2023 09:46:02 -0700 (PDT)
In-Reply-To: <00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=81.143.231.9; posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 81.143.231.9
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com> <00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
Subject: Re: Commandline parsing
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Mon, 31 Jul 2023 16:46:03 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4012
 by: Malcolm McLean - Mon, 31 Jul 2023 16:46 UTC

On Monday, 31 July 2023 at 16:29:06 UTC+1, fir wrote:
> środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> > Just realised that my options parser isn't publically available, which I have just remedied.
> >
> > What approaches do people use towards parsing commandline options ? Do you use getopt() ?
> Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> i may not understand about what this topic is but in org-asm for comandline i use something most trivial
>
>
> void ConsumeCommandlineOption(char* option)
> {
> if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
> if( strcmp ( option, "-console" )==0) show_console = 1; else
> if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
> if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
> printf("\n ++++ option %s not reckognized and ignored ", option);
>
> }
> char* input_file_name = "input.asm";
> char* output_file_name = "asm-result.exe";
>
> int ConsumeCommandlineOptions(int argc, char* argv[])
> {
> if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
> if(argc>=2) { input_file_name = argv[1]; }
> if(argc>=3) { output_file_name = argv[2]; }
> if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }
>
> return 'ok';
> }
>
> its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention
> (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as
> afair its a bit raw function, also this %s im not sure if its safe
>
That bespoke code is simple enough to be a viable approach.
Wiht the options parser it would look something like this.

int main(int argc, char **argv)
{ OPTIONS *opt = options(argc, argv, NULL);
int show_console = 0;
int show_verbose_console_info = 0;

if (opt_get(opt, "-noconsole", NULL))
show_console = 0;
if (opt_get(opt, "-console", NULL))
show_console = 1;
if (opt_get(opt, "-nolog", NULL))
show_verbose_console_info = 0;
if (opt_get(opt, "log", NULL))
show_verbose_console_info = 1;

if (opt_Nargs(opt) != 2)
/* don't have two arguments */
if (opt_error(opt, stderr))
/* user passed an unrecognised or malformed option */
input_file_name = opt_arg(opt, 0);
output_file_name = opt_arg(opt, 1);

killoptions(opt)):

...

The big disadvantage is that you have an external dependency on options.c.

Re: Commandline parsing

<ae8bdb37-39bd-400c-aa28-8056b675d501n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:b483:0:b0:75b:3962:8db3 with SMTP id d125-20020a37b483000000b0075b39628db3mr32871qkf.3.1690823568840;
Mon, 31 Jul 2023 10:12:48 -0700 (PDT)
X-Received: by 2002:a05:622a:1807:b0:403:fe96:5779 with SMTP id
t7-20020a05622a180700b00403fe965779mr39813qtc.5.1690823568635; Mon, 31 Jul
2023 10:12:48 -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: Mon, 31 Jul 2023 10:12:48 -0700 (PDT)
In-Reply-To: <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.118; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.118
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com> <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ae8bdb37-39bd-400c-aa28-8056b675d501n@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 17:12:48 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5982
 by: fir - Mon, 31 Jul 2023 17:12 UTC

poniedziałek, 31 lipca 2023 o 18:46:10 UTC+2 Malcolm McLean napisał(a):
> On Monday, 31 July 2023 at 16:29:06 UTC+1, fir wrote:
> > środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> > > Just realised that my options parser isn't publically available, which I have just remedied.
> > >
> > > What approaches do people use towards parsing commandline options ? Do you use getopt() ?
> > Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> > i may not understand about what this topic is but in org-asm for comandline i use something most trivial
> >
> >
> > void ConsumeCommandlineOption(char* option)
> > {
> > if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
> > if( strcmp ( option, "-console" )==0) show_console = 1; else
> > if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
> > if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
> > printf("\n ++++ option %s not reckognized and ignored ", option);
> >
> > }
> > char* input_file_name = "input.asm";
> > char* output_file_name = "asm-result.exe";
> >
> > int ConsumeCommandlineOptions(int argc, char* argv[])
> > {
> > if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
> > if(argc>=2) { input_file_name = argv[1]; }
> > if(argc>=3) { output_file_name = argv[2]; }
> > if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }
> >
> > return 'ok';
> > }
> >
> > its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention
> > (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as
> > afair its a bit raw function, also this %s im not sure if its safe
> >
> That bespoke code is simple enough to be a viable approach.
> Wiht the options parser it would look something like this.
>
> int main(int argc, char **argv)
> {
> OPTIONS *opt = options(argc, argv, NULL);
> int show_console = 0;
> int show_verbose_console_info = 0;
>
> if (opt_get(opt, "-noconsole", NULL))
> show_console = 0;
> if (opt_get(opt, "-console", NULL))
> show_console = 1;
> if (opt_get(opt, "-nolog", NULL))
> show_verbose_console_info = 0;
> if (opt_get(opt, "log", NULL))
> show_verbose_console_info = 1;
>
> if (opt_Nargs(opt) != 2)
> /* don't have two arguments */
> if (opt_error(opt, stderr))
> /* user passed an unrecognised or malformed option */
> input_file_name = opt_arg(opt, 0);
> output_file_name = opt_arg(opt, 1);
>
> killoptions(opt)):
>
> ...
>
> The big disadvantage is that you have an external dependency on options.c..

yes thats why teh simmple approch is imo better at least in simple cases i now need
(though its not elastical, i would only use -something options and possibly arguments without of it without "-"
-setwindow 400 600 -noconsole

for extreme simplicity not using underscores and spaces i guess maybe pass strings by

-setwindow 400 600 -noconsole -settitle "green fire app"

but i dont know if argc/argv handles that " " strings (but if no and divides by space it is also not hard to code it by taking args to rightside in argv[])

BTW thsi pice i posted has better naming conventions imo, something i clarified for some years
imo they are good
1) not use abbreviations (with very few exceptions like sin cos min max and things like that)
2) write long function names, camel style, use long then you dont need to write commentary (typicaly 3 to 5 words but even 7 words function names are okay)
3) variabel names write lowcase with underscores (medium sized if they are sorta global/module scope)
4) you may use short variable names liek 1 letter if they are local, but also may write longer too
5) structure names as types write like Ship but entity like ship
6) dont use macroprocessor at all

there are yet soem additional less used conventions for function names like you may use underscored SomeFunction_postfix() in soem cases (generally also function are based on verb (with very few exceptions, like conversion functions, maybe isSomething functions and this like), variables on nouns,

teh code you posted breaks thoat rules (4-5 times: OPTIONS , opt, opt_get, opt_Nargs) so imo it looks worse stylistically (by convention style)

Re: Commandline parsing

<706cbf3a-4e6f-4466-a139-2511f00a7e8an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:961:b0:635:de09:2058 with SMTP id do1-20020a056214096100b00635de092058mr36719qvb.3.1690827687426;
Mon, 31 Jul 2023 11:21:27 -0700 (PDT)
X-Received: by 2002:a05:6870:5aad:b0:1bb:48fa:f5a9 with SMTP id
dt45-20020a0568705aad00b001bb48faf5a9mr12798963oab.9.1690827687217; Mon, 31
Jul 2023 11:21:27 -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: Mon, 31 Jul 2023 11:21:25 -0700 (PDT)
In-Reply-To: <ae8bdb37-39bd-400c-aa28-8056b675d501n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.121; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.121
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com> <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
<ae8bdb37-39bd-400c-aa28-8056b675d501n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <706cbf3a-4e6f-4466-a139-2511f00a7e8an@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 18:21:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 7597
 by: fir - Mon, 31 Jul 2023 18:21 UTC

poniedziałek, 31 lipca 2023 o 19:12:56 UTC+2 fir napisał(a):
> poniedziałek, 31 lipca 2023 o 18:46:10 UTC+2 Malcolm McLean napisał(a):
> > On Monday, 31 July 2023 at 16:29:06 UTC+1, fir wrote:
> > > środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> > > > Just realised that my options parser isn't publically available, which I have just remedied.
> > > >
> > > > What approaches do people use towards parsing commandline options ? Do you use getopt() ?
> > > Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> > > i may not understand about what this topic is but in org-asm for comandline i use something most trivial
> > >
> > >
> > > void ConsumeCommandlineOption(char* option)
> > > {
> > > if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
> > > if( strcmp ( option, "-console" )==0) show_console = 1; else
> > > if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
> > > if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
> > > printf("\n ++++ option %s not reckognized and ignored ", option);
> > >
> > > }
> > > char* input_file_name = "input.asm";
> > > char* output_file_name = "asm-result.exe";
> > >
> > > int ConsumeCommandlineOptions(int argc, char* argv[])
> > > {
> > > if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
> > > if(argc>=2) { input_file_name = argv[1]; }
> > > if(argc>=3) { output_file_name = argv[2]; }
> > > if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }
> > >
> > > return 'ok';
> > > }
> > >
> > > its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention
> > > (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as
> > > afair its a bit raw function, also this %s im not sure if its safe
> > >
> > That bespoke code is simple enough to be a viable approach.
> > Wiht the options parser it would look something like this.
> >
> > int main(int argc, char **argv)
> > {
> > OPTIONS *opt = options(argc, argv, NULL);
> > int show_console = 0;
> > int show_verbose_console_info = 0;
> >
> > if (opt_get(opt, "-noconsole", NULL))
> > show_console = 0;
> > if (opt_get(opt, "-console", NULL))
> > show_console = 1;
> > if (opt_get(opt, "-nolog", NULL))
> > show_verbose_console_info = 0;
> > if (opt_get(opt, "log", NULL))
> > show_verbose_console_info = 1;
> >
> > if (opt_Nargs(opt) != 2)
> > /* don't have two arguments */
> > if (opt_error(opt, stderr))
> > /* user passed an unrecognised or malformed option */
> > input_file_name = opt_arg(opt, 0);
> > output_file_name = opt_arg(opt, 1);
> >
> > killoptions(opt)):
> >
> > ...
> >
> > The big disadvantage is that you have an external dependency on options..c.
> yes thats why teh simmple approch is imo better at least in simple cases i now need
> (though its not elastical, i would only use -something options and possibly arguments without of it without "-"
> -setwindow 400 600 -noconsole
>
> for extreme simplicity not using underscores and spaces i guess maybe pass strings by
>
> -setwindow 400 600 -noconsole -settitle "green fire app"
>
> but i dont know if argc/argv handles that " " strings (but if no and divides by space it is also not hard to code it by taking args to rightside in argv[])
>
> BTW thsi pice i posted has better naming conventions imo, something i clarified for some years
> imo they are good
> 1) not use abbreviations (with very few exceptions like sin cos min max and things like that)
> 2) write long function names, camel style, use long then you dont need to write commentary (typicaly 3 to 5 words but even 7 words function names are okay)

i meant PascalStyle.. the style you posted form me is like more gothic or yet maybe 19th century style (imo), what i write is imo more modern (pneumatic?)

this is probably all that abbreviations are 'cut' to/for the eye (as abrevviation cut words)
and this is not good.. imo using pascal for variables in turn is not good (so the options
for variables are mainly 3: classicc, this_one, camelStyle )yet is maybe 4th all big)..
i chosed underscored... if so then function names would to be nice to get different than
variables and Pascal imo looks really good (for pascal functions im more sure than underscored variables i guess (there is and option for pascal+camel instead of pascal+underscores i guess..
but not tested it

overally this convention i use is enough good imo but real mistake make all programmer who use abbreviations... in recent times i hovver began to consider if not use maybe not necassarely abbreviations but soem shorts (1 word lowercase eventually cut) for some arrays..becouse there are some arrays who tend to be writen in code thousands times, and maybe the things that do appear thousand times (like int, float) could and mabe even should be shorts

> 3) variabel names write lowcase with underscores (medium sized if they are sorta global/module scope)
> 4) you may use short variable names liek 1 letter if they are local, but also may write longer too
> 5) structure names as types write like Ship but entity like ship
> 6) dont use macroprocessor at all
>
> there are yet soem additional less used conventions for function names like you may use underscored SomeFunction_postfix() in soem cases (generally also function are based on verb (with very few exceptions, like conversion functions, maybe isSomething functions and this like), variables on nouns,
>
> teh code you posted breaks thoat rules (4-5 times: OPTIONS , opt, opt_get, opt_Nargs) so imo it looks worse stylistically (by convention style)

Re: Commandline parsing

<149e783f-abd9-4933-95a8-f9284bf7d774n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:8685:0:b0:76a:db07:2a0e with SMTP id i127-20020a378685000000b0076adb072a0emr32868qkd.3.1690829605738;
Mon, 31 Jul 2023 11:53:25 -0700 (PDT)
X-Received: by 2002:a05:6808:d47:b0:3a1:f295:3e with SMTP id
w7-20020a0568080d4700b003a1f295003emr19824952oik.1.1690829605376; Mon, 31 Jul
2023 11:53:25 -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: Mon, 31 Jul 2023 11:53:24 -0700 (PDT)
In-Reply-To: <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.76; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.76
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com> <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <149e783f-abd9-4933-95a8-f9284bf7d774n@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 18:53:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5225
 by: fir - Mon, 31 Jul 2023 18:53 UTC

poniedziałek, 31 lipca 2023 o 18:46:10 UTC+2 Malcolm McLean napisał(a):
> On Monday, 31 July 2023 at 16:29:06 UTC+1, fir wrote:
> > środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> > > Just realised that my options parser isn't publically available, which I have just remedied.
> > >
> > > What approaches do people use towards parsing commandline options ? Do you use getopt() ?
> > Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> > i may not understand about what this topic is but in org-asm for comandline i use something most trivial
> >
> >
> > void ConsumeCommandlineOption(char* option)
> > {
> > if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
> > if( strcmp ( option, "-console" )==0) show_console = 1; else
> > if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
> > if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
> > printf("\n ++++ option %s not reckognized and ignored ", option);
> >
> > }
> > char* input_file_name = "input.asm";
> > char* output_file_name = "asm-result.exe";
> >
> > int ConsumeCommandlineOptions(int argc, char* argv[])
> > {
> > if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
> > if(argc>=2) { input_file_name = argv[1]; }
> > if(argc>=3) { output_file_name = argv[2]; }
> > if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }
> >
> > return 'ok';
> > }
> >
> > its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention
> > (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as
> > afair its a bit raw function, also this %s im not sure if its safe
> >
> That bespoke code is simple enough to be a viable approach.
> Wiht the options parser it would look something like this.
>
> int main(int argc, char **argv)
> {
> OPTIONS *opt = options(argc, argv, NULL);
> int show_console = 0;
> int show_verbose_console_info = 0;
>
> if (opt_get(opt, "-noconsole", NULL))
> show_console = 0;
> if (opt_get(opt, "-console", NULL))
> show_console = 1;
> if (opt_get(opt, "-nolog", NULL))
> show_verbose_console_info = 0;
> if (opt_get(opt, "log", NULL))
> show_verbose_console_info = 1;
>
> if (opt_Nargs(opt) != 2)
> /* don't have two arguments */
> if (opt_error(opt, stderr))
> /* user passed an unrecognised or malformed option */
> input_file_name = opt_arg(opt, 0);
> output_file_name = opt_arg(opt, 1);
>
> killoptions(opt)):
>
> ...
>
> The big disadvantage is that you have an external dependency on options.c..

depend what dependencies i guess - imo include "some.c" or -l"some.dll" ale sorta standable dependencies - but it also depends if thiose things you delegate to this side codes are of such kind you need update them or no update and mostly forget (if need to update the another branch od code-jumping may and probably will be weary) (this way the 'dead' code is much better than live branches that need to be jumped)

besides i dont know what killoptions(opt)) exactly do but such paradigm of new/free open/close
is bad and not should be used... malloc free for example should be used same way as goto
or recursion today it means nearly never except some so rare cases most people probably dont ever seen it - also this pattern.. there shopuld not be done what i call "temporal" states in programming..in programming you shoudl operate on ram state this is some "spacial" state not temporal ones..temporal are most evil

Re: Commandline parsing

<7e13f4c1-d070-422f-bee2-b6eae71ad98cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:4e23:0:b0:635:dddc:1779 with SMTP id dm3-20020ad44e23000000b00635dddc1779mr40025qvb.7.1690832273726;
Mon, 31 Jul 2023 12:37:53 -0700 (PDT)
X-Received: by 2002:a05:6808:17a4:b0:3a6:e045:412a with SMTP id
bg36-20020a05680817a400b003a6e045412amr20898699oib.8.1690832273462; Mon, 31
Jul 2023 12:37:53 -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: Mon, 31 Jul 2023 12:37:53 -0700 (PDT)
In-Reply-To: <706cbf3a-4e6f-4466-a139-2511f00a7e8an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.55; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.55
References: <a631f98c-5482-4e90-9a0d-8ce49e447153n@googlegroups.com>
<00a6ddfb-2660-41b0-94d7-48a1d764577an@googlegroups.com> <0f2dce28-ac19-4613-8796-21f721eb97a6n@googlegroups.com>
<ae8bdb37-39bd-400c-aa28-8056b675d501n@googlegroups.com> <706cbf3a-4e6f-4466-a139-2511f00a7e8an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7e13f4c1-d070-422f-bee2-b6eae71ad98cn@googlegroups.com>
Subject: Re: Commandline parsing
From: profesor...@gmail.com (fir)
Injection-Date: Mon, 31 Jul 2023 19:37:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 11957
 by: fir - Mon, 31 Jul 2023 19:37 UTC

poniedziałek, 31 lipca 2023 o 20:21:36 UTC+2 fir napisał(a):
> poniedziałek, 31 lipca 2023 o 19:12:56 UTC+2 fir napisał(a):
> > poniedziałek, 31 lipca 2023 o 18:46:10 UTC+2 Malcolm McLean napisał(a):
> > > On Monday, 31 July 2023 at 16:29:06 UTC+1, fir wrote:
> > > > środa, 26 lipca 2023 o 17:35:05 UTC+2 Malcolm McLean napisał(a):
> > > > > Just realised that my options parser isn't publically available, which I have just remedied.
> > > > >
> > > > > What approaches do people use towards parsing commandline options ? Do you use getopt() ?
> > > > Or do you find that real world programs have a simple enough set of options that it's easier to write bespoke code?
> > > > i may not understand about what this topic is but in org-asm for comandline i use something most trivial
> > > >
> > > >
> > > > void ConsumeCommandlineOption(char* option)
> > > > {
> > > > if( strcmp ( option, "-noconsole" )==0) show_console = 0; else
> > > > if( strcmp ( option, "-console" )==0) show_console = 1; else
> > > > if( strcmp ( option, "-nolog" )==0) show_verbose_console_info = 0; else
> > > > if( strcmp ( option, "-log" )==0) show_verbose_console_info = 1; else
> > > > printf("\n ++++ option %s not reckognized and ignored ", option);
> > > >
> > > > }
> > > > char* input_file_name = "input.asm";
> > > > char* output_file_name = "asm-result.exe";
> > > >
> > > > int ConsumeCommandlineOptions(int argc, char* argv[])
> > > > {
> > > > if(argc==1 ) { PrintNoArgumentsInfo(); return 'stop'; }
> > > > if(argc>=2) { input_file_name = argv[1]; }
> > > > if(argc>=3) { output_file_name = argv[2]; }
> > > > if(argc>=4) { for(int i=3; i<argc;i++) ConsumeCommandlineOption(argv[i]); }
> > > >
> > > > return 'ok';
> > > > }
> > > >
> > > > its hovever dirty written and maybe i will revrite it..puting elses on right side is todays tiem invention
> > > > (never seen this and today get idea to put it on right first time ;c ) using strcomp im not sure its okay as
> > > > afair its a bit raw function, also this %s im not sure if its safe
> > > >
> > > That bespoke code is simple enough to be a viable approach.
> > > Wiht the options parser it would look something like this.
> > >
> > > int main(int argc, char **argv)
> > > {
> > > OPTIONS *opt = options(argc, argv, NULL);
> > > int show_console = 0;
> > > int show_verbose_console_info = 0;
> > >
> > > if (opt_get(opt, "-noconsole", NULL))
> > > show_console = 0;
> > > if (opt_get(opt, "-console", NULL))
> > > show_console = 1;
> > > if (opt_get(opt, "-nolog", NULL))
> > > show_verbose_console_info = 0;
> > > if (opt_get(opt, "log", NULL))
> > > show_verbose_console_info = 1;
> > >
> > > if (opt_Nargs(opt) != 2)
> > > /* don't have two arguments */
> > > if (opt_error(opt, stderr))
> > > /* user passed an unrecognised or malformed option */
> > > input_file_name = opt_arg(opt, 0);
> > > output_file_name = opt_arg(opt, 1);
> > >
> > > killoptions(opt)):
> > >
> > > ...
> > >
> > > The big disadvantage is that you have an external dependency on options.c.
> > yes thats why teh simmple approch is imo better at least in simple cases i now need
> > (though its not elastical, i would only use -something options and possibly arguments without of it without "-"
> > -setwindow 400 600 -noconsole
> >
> > for extreme simplicity not using underscores and spaces i guess maybe pass strings by
> >
> > -setwindow 400 600 -noconsole -settitle "green fire app"
> >
> > but i dont know if argc/argv handles that " " strings (but if no and divides by space it is also not hard to code it by taking args to rightside in argv[])
> >
> > BTW thsi pice i posted has better naming conventions imo, something i clarified for some years
> > imo they are good
> > 1) not use abbreviations (with very few exceptions like sin cos min max and things like that)
> > 2) write long function names, camel style, use long then you dont need to write commentary (typicaly 3 to 5 words but even 7 words function names are okay)
> i meant PascalStyle.. the style you posted form me is like more gothic or yet maybe 19th century style (imo), what i write is imo more modern (pneumatic?)
>
> this is probably all that abbreviations are 'cut' to/for the eye (as abrevviation cut words)
> and this is not good.. imo using pascal for variables in turn is not good (so the options
> for variables are mainly 3: classicc, this_one, camelStyle )yet is maybe 4th all big)..
> i chosed underscored... if so then function names would to be nice to get different than
> variables and Pascal imo looks really good (for pascal functions im more sure than underscored variables i guess (there is and option for pascal+camel instead of pascal+underscores i guess..
> but not tested it
>
> overally this convention i use is enough good imo but real mistake make all programmer who use abbreviations... in recent times i hovver began to consider if not use maybe not necassarely abbreviations but soem shorts (1 word lowercase eventually cut) for some arrays..becouse there are some arrays who tend to be writen in code thousands times, and maybe the things that do appear thousand times (like int, float) could and mabe even should be shorts
> > 3) variabel names write lowcase with underscores (medium sized if they are sorta global/module scope)
> > 4) you may use short variable names liek 1 letter if they are local, but also may write longer too
> > 5) structure names as types write like Ship but entity like ship
> > 6) dont use macroprocessor at all
> >
> > there are yet soem additional less used conventions for function names like you may use underscored SomeFunction_postfix() in soem cases (generally also function are based on verb (with very few exceptions, like conversion functions, maybe isSomething functions and this like), variables on nouns,
> >
> > teh code you posted breaks thoat rules (4-5 times: OPTIONS , opt, opt_get, opt_Nargs) so imo it looks worse stylistically (by convention style)

as to style i probbaly should write back to furia compiler, but it needs partially deeper focus
when writing (though standable) so i dont know if i write now

some example that a;ready compiles https://fastupload.io/pakja4Guq471ngn/file

input is in input.c output is in furia-output.exe

it generally tends to be extremally simplified extended/modernized c 'variant' or how to call it

rhe funny pieces

void SetupLight
SetPointLight 0 1 -1100.0 0.0 0.0 7000.0 50000.0 0.30 1.9 1.3 1.3 0.01 0.01 0.01 0.18 1.1 1.1 1.1 0.01 0.01 0.01
SetPointLight 1 3 1100.0 500.0 500.0 7000.0 50000.0 0.30 1.3 1.9 1.3 0.01 0.01 0.01 0.18 1.1 1.1 1.1 0.01 0.01 0.01
SetPointLight 2 3 0.0 -1500.0 -500.0 7000.0 50000.0 0.30 1.3 1.3 1.9 0.01 0.01 0.01 0.18 1.1 1.1 1.1 0.01 0.01 0.01 ;

this is most simplified function definition - seems qyite okay (and it compiles so its proven to work)

void ProcessMouseMove mouse_x mouse_y { }
void ProcessKeyDown key { }
void OnResize { RunFrame }

alseo 3 function definitions

void RunFrame int advance
{
Initialise, ClearFrameData 0x666666
DrawLine3d 100.0 100.0 0.0 100.0 -100.0 0.0 0xffffff
DrawLine3d 100.0 -100.0 0.0 -100.0 -100.0 0.0 0xffffff
DrawLine3d -100.0 -100.0 0.0 -100.0 100.0 0.0 0xffffff
DrawLine3d -100.0 100.0 0.0 100.0 100.0 0.0 0xffffff
DrawDot3d 0.0 0.0 100.0 20.0 0x557788
DrawDot3d 0.0 0.0 150.0 30.0 0x557722
DrawDot3d 0.0 0.0 -100.0 10.0 0xaa7788
DrawCloud1, DrawCloud2, DrawCloud21,
DrawCloud3
DrawSomeText2F 0xa99999 0x666666 10 20 "hello, this is example program compiled by fir's furia compiler \x00"
}

same

ints array

new type - resizable array of ints
may be iaccesed by array[i] using array.size,
size just may be changed by array.size=29; array.size=100; etc
has alo method add: array.add(10)

i generate code in assembly for that, i got no head in that so i a bit forgot bout the code for eemiting resizes are sorta like

void EmitResize(chunk name, int size) //for seting new size
{ FlushOutAsm("\n push %d", size );
FlushOutAsmChunkPE("\n push (", name, ") ");
FlushOutAsm("\n call (\"msvcrt.dll\"->realloc)");
FlushOutAsmChunkPE("\n mov (", name, ") eax ");
FlushOutAsm("\n pop edx");
FlushOutAsm("\n pop edx");
FlushOutAsmChunkPE("\n mov (", name, ") eax ");
FlushOutAsm("\n mov eax %d", size);
FlushOutAsmChunkPE("\n mov (", name, "_size) eax ");
}


Click here to read the complete article
Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor