Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #388325
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Command line globber/tokenizer library for C? |
| Date | 2024-09-12 18:16 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <20240912181625.00006e68@yahoo.com> (permalink) |
| References | (4 earlier) <vbsu1d$3p7pp$1@dont-email.me> <vbtj88$1kpm$1@raubtier-asyl.eternal-september.org> <vbujak$733i$3@dont-email.me> <vbum9i$8h2o$1@dont-email.me> <vbur72$99cr$1@dont-email.me> |
On Thu, 12 Sep 2024 14:44:03 +0100
Bart <bc@freeuk.com> wrote:
> On 12/09/2024 13:20, Janis Papanagnou wrote:
> > On 12.09.2024 13:29, Bart wrote:
> >> On 12/09/2024 03:22, Bonita Montero wrote:
> >>> Am 11.09.2024 um 22:19 schrieb Bart:
> >>>
> >>>> C++ is a simpler language? You're having a laugh!
> >>>
> >>> The solutions are simpler because you've a fifth of the code as
> >>> in C.
> >>>
> >>> In this case, it actually needed somewhat more code, even if the
> >>> line
> >> count was half.
> >>
> >> But your solutions are always incomprehensible because they strive
> >> for the most advanced features possible.
> >
> > I don't know of the other poster's solutions. But a quick browse
> > seems to show nothing incomprehensible or anything that should be
> > difficult to understand. (YMMV; especially if you're not familiar
> > with C++ then I'm sure the code may look like noise to you.)
> >
> > In the given context of C and C++ I've always perceived the features
> > of C++ to add to comprehensibility of source code where the
> > respective C code required writing clumsy code and needed
> > (unnecessary) syntactic ballast to implement similar functions and
> > program constructs.
> >
> > Your undifferentiated complaint sounds more like someone not willing
> > to understand the other concepts or have a reluctance or laziness to
> > make yourself familiar with them.
>
> I'm saying it's not necessary to use such advanced features to do
> some trivial parsing.
>
> I've given a C solution below. (To test outside of Windows, remove
> windows.h and set cmdline to any string containing a test input or
> use a local function to get the program's command line as one string.)
>
> It uses no special features. Anybody can understand such code.
> Anybody can port it to another language far more easily than the C++.
> (Actually I wrote it first in my language then ported it to C. I only
> needed to do 1- to 0-based conversion.)
>
> There are two things missing compared with the C++ (other than it
> uses UTF8 strings):
>
> * Individual parameters are capped in length (to 1023 chars here).
> This can be solved by determining only the span of the item then
> working from that.
>
> * Handling an unknown number of parameters is not automatic:
>
> For the latter, the example uses a fixed array size. For a dynamic
> array size, call 'strtoargs' with a count of 0 to first determine the
> number of args, then allocate an array and call again to populate it.
>
>
> -------------------------------------------
> #include <windows.h>
> #include <stdio.h>
> #include <string.h>
>
> int strtoargs(char* cmd, char** dest, int count) {
> enum {ilen=1024};
> char item[ilen];
> int n=0, length, c;
> char *p=cmd, *q, *end=&item[ilen-1];
>
> while (c=*p++) {
> if (c==' ' || c=='\t')
> continue;
> else if (c=='"') {
> length=0;
> q=item;
>
> while (c=*p++, c!='"') {
> if (c==0) {
> --p;
> break;
> } else {
> if (q<end) *q++ = c;
> }
> }
> goto store;
> } else {
> length=0;
> q=item;
> --p;
>
> while (c=*p++, c!=' ' && c!='\t') {
> if (c==0) {
> --p;
> break;
> } else {
> if (q<end) *q++ = c;
> }
> }
>
> store: *q=0;
> ++n;
> if (n<=count) dest[n-1]=strdup(item);
> }
> }
> return n;
> }
>
> int main(void) {
> char* cmdline;
> enum {cap=30};
> char* args[cap];
> int n;
>
> cmdline = GetCommandLineA();
>
> n=strtoargs(cmdline, args, cap);
>
> for (int i=0; i<n; ++i) {
> if (i<cap)
> printf("%d %s\n", i, args[i]);
> else
> printf("%d <overflow>\n", i);
> }
> }
> -------------------------------------------
>
Apart from unnecessary ilen limit, of unnecessary goto into block (I
have nothing against forward gotos out of blocks, but gotos into blocks
make me nervous) and of variable 'length' that serves no purpose, your
code simply does not fulfill requirements of OP.
I can immediately see two gotchas: no handling of escaped double
quotation marks \" and no handling of single quotation marks. Quite
possibly there are additional omissions.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 19:01 +0000
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-10 20:58 +0000
Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-10 14:12 -0700
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-10 23:05 +0200
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 22:11 +0000
Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-10 14:37 -0700
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-10 22:13 +0000
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 01:56 +0000
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 02:54 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 14:17 +0200
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 12:22 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 14:28 +0200
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 12:44 +0000
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-11 13:42 +0100
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 14:59 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-11 20:14 +0200
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-11 18:17 +0000
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-11 18:49 +0000
Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-11 14:43 -0700
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 03:06 +0000
Re: Command line globber/tokenizer library for C? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-09-11 20:37 -0700
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 03:56 +0000
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 13:22 +0000
Re: Command line globber/tokenizer library for C? ted@loft.tnolan.com (Ted Nolan <tednolan>) - 2024-09-12 13:50 +0000
Columbia (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 14:06 +0000
Re: Columbia (Was: Command line globber/tokenizer library for C?) Michael S <already5chosen@yahoo.com> - 2024-09-12 17:20 +0300
Re: Columbia (Was: Command line globber/tokenizer library for C?) David Brown <david.brown@hesbynett.no> - 2024-09-12 16:43 +0200
Re: Columbia (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:07 +0000
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 04:14 +0000
Re: Command line globber/tokenizer library for C? Ben Bacarisse <ben@bsb.me.uk> - 2024-09-12 10:43 +0100
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-11 21:19 +0100
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 04:22 +0200
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 12:29 +0100
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 12:13 +0000
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 14:24 +0200
Other programming languages (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 13:20 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:01 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 14:07 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:14 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:40 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:48 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:59 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:32 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-09-12 18:50 -0400
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 01:37 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Michael S <already5chosen@yahoo.com> - 2024-09-13 11:30 +0300
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-13 04:06 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 02:58 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-13 14:31 +0200
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-13 04:18 +0000
Re: Other programming languages (Was: Command line globber/tokenizer library for C?) Kaz Kylheku <643-408-1753@kylheku.com> - 2024-09-13 03:38 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:00 +0200
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 14:20 +0200
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 14:44 +0100
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 15:16 +0100
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:23 +0200
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:46 +0200
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 17:15 +0100
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 18:26 +0200
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 18:16 +0300
Re: Command line globber/tokenizer library for C? scott@slp53.sl.home (Scott Lurndal) - 2024-09-12 15:37 +0000
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 18:49 +0300
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-12 17:28 +0100
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 19:02 +0200
Re: Command line globber/tokenizer library for C? gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 17:39 +0000
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-12 22:38 +0300
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 07:28 +0200
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 11:38 +0300
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 14:12 +0200
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 15:25 +0300
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 15:20 +0200
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 22:24 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-14 01:42 +0200
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 01:41 +0000
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-13 09:05 -0700
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-15 12:22 +0300
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-16 00:52 -0700
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-16 12:23 +0300
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 03:12 -0700
Re: Command line globber/tokenizer library for C? antispam@fricas.org - 2024-09-17 22:34 +0000
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 16:33 -0700
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 02:46 +0300
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-18 01:07 +0100
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:43 +0300
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-18 10:49 +0100
Re: Command line globber/tokenizer library for C? David Brown <david.brown@hesbynett.no> - 2024-09-18 12:44 +0200
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-18 06:01 -0700
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-17 18:31 -0700
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:03 +0300
Re: Command line globber/tokenizer library for C? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-18 05:09 -0700
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-18 02:20 +0000
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-18 11:05 +0300
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 16:04 +0200
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:30 +0200
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:47 +0200
Re: Command line globber/tokenizer library for C? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-09-12 17:56 +0200
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 18:09 +0200
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 02:43 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-13 07:27 +0200
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 06:49 +0000
Re: Command line globber/tokenizer library for C? Michael S <already5chosen@yahoo.com> - 2024-09-13 11:49 +0300
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-13 22:04 +0000
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-13 23:48 +0100
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 01:41 +0000
Re: Command line globber/tokenizer library for C? Bart <bc@freeuk.com> - 2024-09-14 10:58 +0100
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-14 22:37 +0000
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 15:58 +0200
Re: Command line globber/tokenizer library for C? Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:08 +0200
More OT BS (Was: Command line globber/tokenizer library for C?) gazelle@shell.xmission.com (Kenny McCormack) - 2024-09-12 15:23 +0000
Re: More OT BS (Was: Command line globber/tokenizer library for C?) Bonita Montero <Bonita.Montero@gmail.com> - 2024-09-12 17:24 +0200
Re: Command line globber/tokenizer library for C? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-09-12 22:09 +0000
csiph-web