Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162879

Re: Freeing a dynamically allocated array of structs within a struct in C

Path csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Freeing a dynamically allocated array of structs within a struct in C
Date Thu, 30 Sep 2021 07:04:49 -0700
Organization A noiseless patient Spider
Lines 63
Message-ID <86lf3etb0e.fsf@linuxsc.com> (permalink)
References <1348a974-54cd-47cf-bf40-7034feaa1f78n@googlegroups.com> <cvinigd0u1jrb02ch20cequm2nh08copvh@4ax.com> <sgglni$1vg$5@dont-email.me> <sgj0bf$259$1@dont-email.me> <sgj75c$ovg$1@dont-email.me> <c%cXI.36951$Kv2.14372@fx47.iad>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info reader02.eternal-september.org; posting-host="d4788905ada0446dfc3ae6b02ecc1355"; logging-data="15857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RASKw5EUqKwnpipoPijttBiXnTpvCSSY="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:bfVlu0va7k/stHfMsNnSVIGc6R4= sha1:BUW3onaM5KjrFSyXL8qBx9R2Lps=
Xref csiph.com comp.lang.c:162879

Show key headers only | View raw


scott@slp53.sl.home (Scott Lurndal) writes:

>     if (cep->ce_splitargs) {
>         argcount = 0;
>         cp = line;
>         while (*cp != '\0') {
>             if (argcount == MAX_ARGCOUNT) {
>                 fprintf(stdout,
>                         "Error:  More than %d arguments unsupported\n",
>                         MAX_ARGCOUNT);
>                 return 1;
>             }
>             while (*cp != '\0' && isspace(*cp)) cp++;
>             if (*cp == '\0') continue;
>             if (*cp == '"') {
>                 in_quote = true;
>                 cp++;
>             }
>             arglist[argcount++] = cp;
>             if (in_quote) {
>                 while (*cp != '\0' && *cp != '"') cp++;
>                 in_quote = false;
>             } else {
>                 while (*cp != '\0' && !isspace(*cp)) cp++;
>             }
>             if (*cp == '\0') continue;
>             *cp++ = '\0';
>         }
>     } else {
>         arglist[0] = command;
>         arglist[1] = line;
>         argcount   = 2;
>     }

int
parse_arguments_failed( char *command, char *line ){
    char *p = line;
    const int most = MAX_ARGCOUNT;
    argcount = 0;

    if(  ! cep->ce_splitargs  ){
        arglist[ argcount++ ] = command;
        arglist[ argcount++ ] = line;
        return  0;
    }

    while(   p = skip_over_spaces( p ),   *p  &&  argcount < most   ){
        if(  *p == '"'  )  p = skip_to_quote(  arglist[ argcount++ ] = p+1  );
        else               p = skip_to_space(  arglist[ argcount++ ] = p    );

        p =   *p  ? *p=0, p+1  : p;
    }

    if(  *p == 0  )  return  0;

    fprintf( stderr, "Error:  More than %d arguments unsupported\n", most );
    return  1;
}


The three helper functions skip_over_spaces(), skip_to_quote(),
and skip_to_space() are all very simple and can be written in
one or two lines each.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Freeing a dynamically allocated array of structs within a struct in C Bithov Vinu Student <vinub@calday.co.uk> - 2021-08-29 08:34 -0700
  Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-29 15:43 +0000
    Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-29 16:12 +0000
      Re: Freeing a dynamically allocated array of structs within a struct in C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-06 05:46 -0700
  Re: Freeing a dynamically allocated array of structs within a struct in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-08-29 17:17 +0100
  Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-29 20:01 +0200
    Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-29 18:21 +0000
      Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-29 20:34 +0200
    Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-30 09:01 +0200
      Re: Freeing a dynamically allocated array of structs within a struct in C Robert Latest <boblatest@yahoo.com> - 2021-08-31 05:44 +0000
      Re: Freeing a dynamically allocated array of structs within a struct in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-08-31 07:50 +0000
        Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-31 10:59 +0200
    Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-30 09:45 +0200
      Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-30 10:15 +0200
  Re: Freeing a dynamically allocated array of structs within a struct in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-08-29 18:14 +0000
  Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-29 18:18 +0000
  Re: Freeing a dynamically allocated array of structs within a struct in C Barry Schwarz <schwarzb@delq.com> - 2021-08-29 11:44 -0700
    Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-29 19:04 +0000
      Re: Freeing a dynamically allocated array of structs within a struct in C Barry Schwarz <schwarzb@delq.com> - 2021-08-29 14:15 -0700
        Re: Freeing a dynamically allocated array of structs within a struct in C scott@slp53.sl.home (Scott Lurndal) - 2021-08-29 21:19 +0000
          Re: Freeing a dynamically allocated array of structs within a struct in C Barry Schwarz <schwarzb@delq.com> - 2021-08-29 18:14 -0700
        Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-30 18:27 +0200
      Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-30 16:17 +0000
        Re: Freeing a dynamically allocated array of structs within a struct in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-08-30 14:14 -0400
          Re: Freeing a dynamically allocated array of structs within a struct in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-08-30 11:39 -0700
            Re: Freeing a dynamically allocated array of structs within a struct in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-08-31 10:08 -0400
            Re: Freeing a dynamically allocated array of structs within a struct in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-09-01 04:40 +0000
              Re: Freeing a dynamically allocated array of structs within a struct in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-01 00:57 -0700
          Re: Freeing a dynamically allocated array of structs within a struct in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-08-30 19:16 +0000
            Re: Freeing a dynamically allocated array of structs within a struct in C Manfred <noname@add.invalid> - 2021-08-30 21:49 +0200
          Re: Freeing a dynamically allocated array of structs within a struct in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-08-30 12:49 -0700
          Re: Freeing a dynamically allocated array of structs within a struct in C scott@slp53.sl.home (Scott Lurndal) - 2021-08-30 22:31 +0000
            Re: Freeing a dynamically allocated array of structs within a struct in C Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-09-30 07:04 -0700
    Re: Freeing a dynamically allocated array of structs within a struct in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-08-29 15:38 -0700
      Re: Freeing a dynamically allocated array of structs within a struct in C Manfred <noname@add.invalid> - 2021-08-30 14:21 +0200
      Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-30 18:29 +0200
        Re: Freeing a dynamically allocated array of structs within a struct in C Bart <bc@freeuk.com> - 2021-08-30 18:30 +0100
          Re: Freeing a dynamically allocated array of structs within a struct in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-08-31 04:22 +0200

csiph-web