I'm taking in an input string, parsing it, and separating the items into arrays. From what I can tell, everything is getting parsed correctly. But, If I iterate of the arrays, I don't get the correct output. Any ideas?
The code is in HolyC. But, it's just c, with a tad bit of cpp. So, anything you say about incorrect pointer use or anything should be 100% valid, towards this code:
Code:
// The green colored lines are printf, without the word printf.
I64 token_pull(U8 *cmd, U8 *out, U8 delim = ' ') {
I64 i;
"cmd : %s\n", cmd;
"cmd before %d\n", cmd;
for (i=0;*cmd != '\0' && *cmd != delim; cmd++) {
out[i] = cmd[0];
"%c", cmd[0];
i++;
};
"\n";
"cmd after %d\n\n", cmd;
return cmd;
}
"cc->token_count :%d\n", cc->token_count;
"cc->flag_count :%d\n", cc->flag_count;
"cc->size :%d\n", cc->size;
//Saying U8 is the same as:
//char tokens[5][128];
U8 tokens[cc->token_count][cc->size];
U8 flags[cc->flag_count][cc->size];
"All tokens :%d\n\n", at;
for (i=0; i < at; i++) {
token_trim(cmd,,TRUE);
if (cmd[0] == '-') {
"fi : %d\n", fi;
cmd = token_pull(cmd, &flags[fi]); fi++;
}
else {
"ti : %d\n", ti;
cmd = token_pull(cmd, &tokens[ti]); ti++;
}
}
// List all the tokens.
for (i=0; i < tc; i++) {
"tokens[%d] : %s\n", i, tokens[i];
}
"\n";
// List all the flags.
for (i=0; i < fc; i++) {
"flags[%d] : %s\n", i, flags[i];
}
Ouput I get, when ran:
cmd: ls -a b c
cc->token_count : 3
cc->flag_count : 1
cc->size : 2
All tokens : 4
ti : 0
cmd : ls -a b c
cmd before 819438096
ls
cmd after 819438098
fi : 0
cmd : -a b c
cmd before 819438098
-a
cmd after 819438100
ti : 1
cmd : b c
cmd before 819438100
b
cmd after 819438101
ti : 2
cmd : c
cmd before 819438101
c
cmd after 819438102
Arrays:
tokens[0] : -bc
tokens[1] : bc
tokens[2] : c
flags[0] : -bc
Should Be:
tokens[0] : ls
tokens[1] : b
tokens[2] : c
flags[0] : -a