Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, so let's walk through some of the lines in parse args</p> <pre><code>wbuf=buffer; buf_args[0]=buffer; args[0] =buffer; </code></pre> <p>This sets <code>wbuf</code> to point to what is in the <code>buffer</code>. It also sets the first pointer in the array of <code>buf_args</code> to the <code>buffer</code>. And it does the same thing for the first element of <code>args</code> as well. </p> <pre><code>for(cp=buf_args; (*cp=strsep(&amp;wbuf, " \n\t")) != NULL ;){ if ((*cp != '\0') &amp;&amp; (++cp &gt;= &amp;buf_args[args_size])) break; } </code></pre> <p>The function <code>strsep</code> looks through <code>wbuf</code> for the delimiters space, newline or tab and returns a pointer to the begining of a token, with <code>wbuf</code> updated to the end of the token. If there are no more delimiters in the string, the function returns <code>NULL</code>. So, the middle part of the <code>for</code> statement continues until <code>*cp</code> equals <code>NULL</code>. </p> <p>So, the pointer <code>cp</code> initially points to the string (pointer) in <code>buf_args[0]</code>. The string separator function fills <code>*cp</code> with the address of the token. Then, the <code>if</code> statement check 1) if the <code>for</code> loop has exceeded the capacity of <code>buf_args</code>, by checking whether the pointer <code>cp</code> has exceeded the last element and 2) if the first character of the returned token is the end of string character.</p> <p>Note: I think that line should be <code>*(*cp) != '\0'</code>?</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>Then, it loops over all the <code>buf_args</code> until it finds a <code>NULL</code> one. If the string pointed to by <code>buf_args</code> is longer than 0, i.e. it has characters, the array <code>args</code> gets a copy of the pointer to the token.</p> <pre><code>*nargs=j; args[j]=NULL; </code></pre> <p>The last element of <code>args</code> after the filled entries is set to <code>NULL</code>. And the value of <code>nargs</code> is set to the length of the number of filled elements in the <code>args</code> array.</p>
 

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