Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's fun. The function separates buffer to an array of strings, where it hits a white-space delimiter.</p> <pre><code>void parse_args(char *buffer, char** args, size_t args_size, size_t *nargs) { char *buf_args[args_size]; /* You need C99 */ char **cp; char *wbuf; size_t i, j; </code></pre> <p>Initialization code...</p> <pre><code> wbuf=buffer; buf_args[0]=buffer; args[0] =buffer; </code></pre> <p>Set all pointers to the beginning of the buffer</p> <pre><code> for(cp=buf_args; (*cp=strsep(&amp;wbuf, " \n\t")) != NULL ;){ </code></pre> <ol> <li>Set the write pointer <code>cp</code> to point to the first element in the buf_args array.</li> <li><p>Set *cp to the next instance of a non-whitespace token in the buffer, and advance <code>wbuf</code> to its ending position</p> <pre><code> if ((*cp != '\0') &amp;&amp; (++cp &gt;= &amp;buf_args[args_size])) break; </code></pre></li> </ol> <p>Stop when <code>strsep</code> returned NULL, or when it points to the end of the buffer, or when it points beyond the end of buf_args[]</p> <pre><code> } for (j=i=0; buf_args[i]!=NULL; i++){ if(strlen(buf_args[i])&gt;0) args[j++]=buf_args[i]; } </code></pre> <p>This loop creates a condensed copy of the buf_args[] array: it copies only the arguments which aren't empty strings. I guess that could happen if your source buffer had a series of consecutive white-space characters. </p> <pre><code> *nargs=j; args[j]=NULL; } </code></pre> <p>Put a NULL at the end of the output array and set the <code>nargs</code> output argument.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload