Hi,
I am working on a tokenizer for command line arguments, to eventually work in a mini shell program. I cannot use strtok, I must get the arguments by hand. I have to ignore tokens that are in quotation marks.
For example:
cd ls "test"
token 0 - cd
token 1 - is
token 2 - "test"
So I was thinking that if I had a pair of starting quotes, then I would advance the i counter until i hit the pair of ending quotes, then put that info into the token. Here is what I have that is definitely not working. Any ideas on what direction I am going, or not going in? Any guidance would be appreciated. Thanks.
Code:
struct token* tokenizer(char* __commandline,int* __argumentcounter)
{
/*the following data structure should hold all the tokens*/
struct token* tokenlist = malloc(sizeof(struct token));
int i = 0;
int j = 0;
/*struct token* head = tokenlist;*/
struct token tokstruct;
struct token *tok;
tok = &tokstruct;
while (__commandline[i] != '\n')
{
if(__commandline[i] == '\"')
{
i++;
if(__commandline[i] == '\"')
{
tok*[j] = __commandline[i];
j++;
}
else if(__commandline[i] == ' ')
{
i++;
}
}
}