- char *start= cmd;
- int i;
-
- name= 0;
- if (!cmd ||
- !*cmd)
- return(0);
- start+= strspn(start, " \t\v\r,");
- if (start &&
- *start == '\n')
- {
- name= (char*)malloc(2);
- strcpy(name, "\n");
- return(0);
- }
- if (!*start)
- return(0);
- i= strcspn(start, " \t\v\r,");
- if (i)
- {
- name= (char*)malloc(i+1);
- strncpy(name, start, i);
- name[i]= '\0';
- }
- start+= i;
- start= skip_delims(start);
- // skip delimiters
- while (*start)
- {
- char *end, *param_str;
- if (*start == '"')
- {
- // string
- start++;
- end= start;
- while (*end &&
- *end != '"')
- {
- if (*end == '\\')
- {
- end++;
- if (*end)
- end++;
- }
- else
- end++;
- }
- if (*end == '"')
- end--;
- else
- con->printf("Unterminated string\n");
- param_str= (char *)malloc(end-start+2);
- strncpy(param_str, start, 1+end-start);
- param_str[1+end-start]= '\0';
- tokens->add(strdup(param_str));
- params->add(con->sim->mk_cmd_str_arg(param_str));
- free(param_str);
- if (*end)
- end++;
- if (*end == '"')
- end++;
- }
- else
- {
- char *dot;
- i= strcspn(start, " \t\v\r,");
- end= start+i;
- param_str= (char *)malloc(i+1);
- strncpy(param_str, start, i);
- param_str[i]= '\0';
- tokens->add(strdup(param_str));
- if ((dot= strchr(param_str, '.')) != NULL)
- {
- // bit
- class cl_cmd_arg *sfr, *bit;
- *dot= '\0';
- dot++;
- if (strchr("0123456789", *param_str) != NULL)
- sfr= con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0));
- else
- sfr= con->sim->mk_cmd_sym_arg(param_str);
- if (*dot == '\0')
- {
- bit= 0;
- con->printf("Uncomplete bit address\n");
- delete sfr;
- }
- else
- {
- if (strchr("0123456789", *dot) != NULL)
- bit= con->sim->mk_cmd_int_arg((long long)
- strtol(dot, 0, 0));
- else
- bit= con->sim->mk_cmd_sym_arg(dot);
- params->add(con->sim->mk_cmd_bit_arg(sfr, bit));
- }
- }
- else if ((dot= strchr(param_str, '[')) != NULL)
- {
- // array
- class cl_cmd_arg *aname, *aindex;
- *dot= '\0';
- dot++;
- if (strchr("0123456789", *param_str) != NULL)
- aname= con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0));
- else
- aname= con->sim->mk_cmd_sym_arg(param_str);
- if (*dot == '\0')
- {
- aname= 0;
- con->printf("Uncomplete array\n");
- }
- else
- {
- char *p;
- p= dot + strlen(dot) - 1;
- while (p > dot &&
- *p != ']')
- {
- *p= '\0';
- p--;
- }
- if (*p == ']')
- *p= '\0';
- if (strlen(dot) == 0)
- {
- con->printf("Uncomplete array index\n");
- delete aname;
- }
- else
- {
- if (strchr("0123456789", *dot) != NULL)
- aindex= con->sim->mk_cmd_int_arg((long long)
- strtol(dot, 0, 0));
- else
- aindex= con->sim->mk_cmd_sym_arg(dot);
- params->add(con->sim->mk_cmd_array_arg(aname, aindex));
- }
- }
- }
- else if (strchr("0123456789", *param_str) != NULL)
- {
- // number
- params->add(con->sim->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0)));
- }
- else
- {
- // symbol
- params->add(con->sim->mk_cmd_sym_arg(param_str));
- }
- free(param_str);
- }
- start= end;
- start= skip_delims(start);
- }
- return(0);