-char *
-cl_cmdline::skip_delims(char *start)
-{
- while (*start &&
- strchr(" \t\v\r,", *start))
- start++;
- return(start);
-}
-
-int
-cl_cmdline::split(void)
-{
- 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 != '"')
- end++;
- if (*end == '"')
- end--;
- else
- simulator->cmd->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(simulator->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= simulator->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0));
- else
- sfr= simulator->mk_cmd_sym_arg(param_str);
- if (*dot == '\0')
- {
- bit= 0;
- simulator->cmd->printf("Uncomplete bit address\n");
- }
- else
- {
- if (strchr("0123456789", *dot) != NULL)
- bit= simulator->mk_cmd_int_arg((long long)
- strtol(dot, 0, 0));
- else
- bit= simulator->mk_cmd_sym_arg(dot);
- }
- params->add(simulator->mk_cmd_bit_arg(sfr, bit));
- }
- else if (strchr("0123456789", *param_str) != NULL)
- {
- // number
- params->add(simulator->mk_cmd_int_arg((long long)
- strtol(param_str, 0, 0)));
- }
- else
- {
- // symbol
- params->add(simulator->mk_cmd_sym_arg(param_str));
- }
- free(param_str);
- }
- start= end;
- start= skip_delims(start);
- }
- return(0);
-}
-
-int
-cl_cmdline::shift(void)
-{
- char *s= skip_delims(cmd);
-
- free(name);
- name= NULL;
- if (s && *s)
- {
- while (*s &&
- strchr(" \t\v\r,", *s) == NULL)
- s++;
- s= skip_delims(s);
- char *p= strdup(s);
- free(cmd);
- cmd= p;
- delete params;
- params= new cl_list(2, 2);
- split();
- }
- return(name && *name);
-}
-
-int
-cl_cmdline::repeat(void)
-{
- return(name &&
- *name == '\n');
-}
-
-class cl_cmd_arg *
-cl_cmdline::param(int num)
-{
- if (num >= params->count)
- return(0);
- return((class cl_cmd_arg *)(params->at(num)));
-}
-