- if (!syntax)
- return(DD_FALSE);
- if (!*syntax &&
- !params->count)
- {
- matched_syntax= syntax;
- return(DD_TRUE);
- }
- if (!params->count)
- return(DD_FALSE);
- //printf("syntax %s?\n",syntax);
- char *p= syntax;
- int iparam= 0;
- class cl_cmd_arg *parm= (class cl_cmd_arg *)(params->at(iparam));
- while (*p &&
- parm)
- {
- //printf("Checking %s as %c\n",parm->get_svalue(),*p);
- switch (*p)
- {
- case SY_ADDR:
- if (!parm->as_address())
- return(DD_FALSE);
- //printf("ADDRESS match %lx\n",parm->value.address);
- break;
- case SY_NUMBER:
- if (!parm->as_number())
- return(DD_FALSE);
- break;
- case SY_DATA:
- if (!parm->as_data())
- return(DD_FALSE);
- break;
- case SY_MEMORY:
- if (!parm->as_memory())
- return(DD_FALSE);
- //printf("MEMORY match %s\n",parm->value.memory->class_name);
- break;
- case SY_HW:
- if (!parm->as_hw(sim->uc))
- return(DD_FALSE);
- break;
- case SY_STRING:
- if (!parm->as_string())
- return(DD_FALSE);
- break;
- case SY_DATALIST:
- if (!set_data_list(parm, &iparam))
- return(DD_FALSE);
- break;
- case SY_BIT:
- if (!parm->as_bit(sim->uc))
- return(DD_FALSE);
- break;
- default:
- return(DD_FALSE);
- }
- p++;
- iparam++;
- if (iparam < params->count)
- parm= (class cl_cmd_arg *)(params->at(iparam));
- else
- parm= 0;
- }
- if (!*p &&
- !parm)
- {
- matched_syntax= syntax;
- return(DD_TRUE);
- }
- return(DD_FALSE);
-}
-
-bool
-cl_cmdline::set_data_list(class cl_cmd_arg *parm, int *iparm)
-{
- class cl_cmd_arg *next_parm;
- int len, i, j;
- t_mem *array;
-
- len= 0;
- array= 0;
- for (i= *iparm, next_parm= param(i); next_parm; i++, next_parm= param(i))
- {
- if (next_parm->is_string())
- {
- int l;
- char *s;
- //s= proc_escape(next_parm->get_svalue(), &l);
- if (!next_parm->as_string())
- continue;
- s= next_parm->value.string.string;
- l= next_parm->value.string.len;
- if (!array)
- array= (t_mem*)malloc(sizeof(t_mem)*l);
- else
- array= (t_mem*)realloc(array, sizeof(t_mem)*(l+len));
- for (j= 0; j < l; j++)
- {
- array[len]= s[j];
- len++;
- }
- //if (s)
- //free(s);
- }
- else
- {
- if (!next_parm->as_data())
- {
- if (array)
- free(array);
- return(DD_FALSE);
- }
- if (!array)
- array= (t_mem*)malloc(sizeof(t_mem));
- else
- array= (t_mem*)realloc(array, sizeof(t_mem)*(1+len));
- array[len]= next_parm->value.data;
- len++;
- }
- }
- *iparm= i;
- parm->value.data_list.array= array;
- parm->value.data_list.len= len;
- return(DD_TRUE);
-}
-
-
-/*
- * Command
- *____________________________________________________________________________
- */
-
-cl_cmd::cl_cmd(//class cl_sim *asim,
- char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp):
- cl_base()
-{
- //sim= asim;
- names= new cl_strings(1, 1);
- names->add(aname?strdup(aname):strdup("unknown"));
- can_repeat= can_rep;
- short_help= short_hlp?strdup(short_hlp):NULL;
- long_help= long_hlp?strdup(long_hlp):NULL;
-}
-
-/*cl_cmd::cl_cmd(class cl_sim *asim):
- cl_base()
-{
- sim= asim;
- name= short_help= long_help= 0;
- can_repeat= 0;
-}*/
-
-cl_cmd::~cl_cmd(void)
-{
- delete names;
- if (short_help)
- free(short_help);
- if (long_help)
- free(long_help);
-}
-
-void
-cl_cmd::add_name(char *name)
-{
- if (name)
- names->add(strdup(name));
-}
-
-int
-cl_cmd::name_match(char *aname, int strict)
-{
- int i;
-
- if (names->count == 0 &&
- !aname)
- return(1);
- if (!aname)
- return(0);
- if (strict)
- {
- for (i= 0; i < names->count; i++)
- {
- char *n= (char*)(names->at(i));
- if (strcmp(aname, n) == 0)
- return(1);
- }
- }
- else
- {
- for (i= 0; i < names->count; i++)
- {
- char *n= (char*)(names->at(i));
- if (strstr(n, aname) == n)
- return(1);
- }
- }
- return(0);
-}
-
-int
-cl_cmd::name_match(class cl_cmdline *cmdline, int strict)
-{
- return(name_match(cmdline->name, strict));