C code questions to understand to convert to PB
Posted: Fri Jul 06, 2018 1:42 pm
Hi,
I have some questions regarding C2PB
1.char * parse_line(char *buf, char *nargv[], int * nargc);
returns String or Pointer to string?
2. char *nargv[] is the pointer to Array?
3. char **carg = nargv+1; char **carg pointer to the 1st element in Array?
4. (*nargc) = 1; if *nargc pointer argument accepts value then why not "int nargc"
5. "char *buf" as argument is used like buf.s or *buf or buf.i in PB
6. while ((c = *buf) >= ' ' || !begun_reading ); can be handled as "while asc(mid(buf,curpos,1))>=charcode ?
7. while (*buf++ != 10);
and
if (c==10 || c==13)
does this mean 10th byte of *buf (and c) or chr(10)
8. (*nargc)++; does this mean next byte of *nargc memory pointer or increment nargc variable by 1?
9. while ((c = *buf) && (c != '"')) buf++; does this mean until next quote char?
10. if (c) *buf++ = '\0'; what does '\0' mean?
11. return (buf); as procedure declared as CHAR in the beginnig does buf contain string, 1 char or pointer?
I have some questions regarding C2PB
1.char * parse_line(char *buf, char *nargv[], int * nargc);
returns String or Pointer to string?
2. char *nargv[] is the pointer to Array?
3. char **carg = nargv+1; char **carg pointer to the 1st element in Array?
4. (*nargc) = 1; if *nargc pointer argument accepts value then why not "int nargc"
5. "char *buf" as argument is used like buf.s or *buf or buf.i in PB
6. while ((c = *buf) >= ' ' || !begun_reading ); can be handled as "while asc(mid(buf,curpos,1))>=charcode ?
7. while (*buf++ != 10);
and
if (c==10 || c==13)
does this mean 10th byte of *buf (and c) or chr(10)
8. (*nargc)++; does this mean next byte of *nargc memory pointer or increment nargc variable by 1?
9. while ((c = *buf) && (c != '"')) buf++; does this mean until next quote char?
10. if (c) *buf++ = '\0'; what does '\0' mean?
11. return (buf); as procedure declared as CHAR in the beginnig does buf contain string, 1 char or pointer?
Code: Select all
char * parse_line(char *buf, char *nargv[], int * nargc)
{
char **carg = nargv+1;
char c;
int begun_reading=FALSE;
(*nargc) = 1;
while ((c = *buf) >= ' ' || !begun_reading ) { /* looking for null or non-ASCII*/
buf++;
if (c == ' ') continue; /* skip blanks */
if (c == '#'){ /* skip comments */
while (*buf++ != 10);
continue;
}
if (c==10 || c==13) /* skip empty lines */
continue;
begun_reading=TRUE;
(*nargc)++;
if (c == '"') { /* quote separator */
*carg++ = buf; /* point to first char after quote */
while ((c = *buf) && (c != '"')) buf++;
if (c) *buf++ = '\0';
}
else { /* blank separator */
*carg++ = buf-1;
while ((c = *buf) && c > ' ' ) buf++;
if (c) *buf++ = '\0';
if (c < ' ') break; /* end of line (or file) found */
}
}
*carg = 0;
/* skip end of line stuff */
while ((c = *buf) && (c < ' ')) buf++;
return (buf); /* this will point to NULL or the next line */