⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.cc

📁 sdcc是为51等小型嵌入式cpu设计的c语言编译器支持数种不同类型的cpu
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* * Simulator of microcontrollers (cmd.src/command.cc) * * Copyright (C) 2002,02 Drotos Daniel, Talker Bt. *  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * *//* This file is part of microcontroller simulator: ucsim.UCSIM is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.UCSIM is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with UCSIM; see the file COPYING.  If not, write to the FreeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA02111-1307, USA. *//*@1@*/#include "ddconfig.h"#include <stdlib.h>#include "i_string.h"// prj// local, cmd#include "commandcl.h"/* * Command line *____________________________________________________________________________ */cl_cmdline::cl_cmdline(class cl_app *the_app,		       char *acmd, class cl_console *acon):  cl_base(){  app= the_app;  cmd= strdup(acmd);  params= new cl_list(2, 2, "command line params");  tokens= new cl_ustrings(2, 2, "command line tokens");  set_name(0);  matched_syntax= 0;  con= acon;}cl_cmdline::~cl_cmdline(void){  if (cmd)    free(cmd);  delete params;  delete tokens;}intcl_cmdline::init(void){  split();  return(0);}char *cl_cmdline::skip_delims(char *start){  while (*start &&	 strchr(" \t\v\r,", *start))    start++;  return(start);}intcl_cmdline::split(void){  //class cl_sim *sim;  char *start= cmd;  int i;  class cl_cmd_arg *arg;  //sim= app->get_sim();  set_name("\n");  if (!cmd ||      !*cmd)    return(0);  start+= strspn(start, " \t\v\r,");  if (start &&      *start == '\n')    {      char *n= (char*)malloc(2);      strcpy(n, "\n");      set_name(n);      return(0);    }  if (!*start)    return(0);  i= strcspn(start, " \t\v\r,");  if (i)    {      char *n= (char*)malloc(i+1);      strncpy(n, start, i);      n[i]= '\0';      set_name(n);    }  start+= i;  start= skip_delims(start);  // skip delimiters  while (*start)    {      char *end= start, *param_str;      if (*start == '"')	split_out_string(&start, &end);      else if (*start == '>')	split_out_output_redirection(&start, &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)	    split_out_bit(dot, param_str);	  else if ((dot= strchr(param_str, '[')) != NULL)	    split_out_array(dot, param_str);	  else if (strchr("0123456789-+", *param_str) != NULL)	    {	      // number	      params->add(arg= new cl_cmd_int_arg((long)						  strtol(param_str, 0, 0)));	      arg->init();	    }	  else	    {	      // symbol	      params->add(arg= new cl_cmd_sym_arg(param_str));	      arg->init();	    }	  free(param_str);	}      start= end;      start= skip_delims(start);    }  return(0);}voidcl_cmdline::split_out_string(char **_start, char **_end){  char *start= *_start, *end;  start++;  end= start;  while (*end &&        *end != '"')    {      if (*end == '\\')       {         end++;         if (*end)           end++;       }      else       end++;    }  if (*end == '"')    end--;  else    con->dd_printf("Unterminated string\n");  char *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));  class cl_cmd_arg *arg;  params->add(arg= new cl_cmd_str_arg(param_str));  arg->init();  free(param_str);  if (*end)    end++;  if (*end == '"')    end++;  *_start= start;  *_end= end;}voidcl_cmdline::split_out_output_redirection(char **_start, char **_end){  char *start= *_start, *end/*= *_end*/;  int i;  char mode[2];  mode[0]= 'w';  mode[1]= '\0';  start++;  i= strcspn(start, " \t\v\r,");  end= start+i;  char *param_str= (char *)malloc(i+1);  char *n= param_str;  strncpy(param_str, start, i);  param_str[i]= '\0';  if (param_str &&      param_str[0] == '>')    {      n++;      mode[0]= 'a';    }  tokens->add(strdup(n));  con->redirect(n, mode);  free(param_str);  *_start= start;  *_end= end;}voidcl_cmdline::split_out_bit(char *dot, char *param_str){  class cl_cmd_arg *sfr, *bit;  *dot= '\0';  dot++;  if (strchr("0123456789", *param_str) != NULL)    {      sfr= new cl_cmd_int_arg((long)strtol(param_str, 0, 0));      sfr->init();    }  else    {      sfr= new cl_cmd_sym_arg(param_str);      sfr->init();    }  if (*dot == '\0')    {      bit= 0;      con->dd_printf("Uncomplete bit address\n");      delete sfr;    }  else    {      if (strchr("0123456789", *dot) != NULL)       {         bit= new cl_cmd_int_arg((long)strtol(dot, 0, 0));         bit->init();       }      else       {         bit= new cl_cmd_sym_arg(dot);         bit->init();       }      class cl_cmd_arg *arg;      params->add(arg= new cl_cmd_bit_arg(sfr, bit));      arg->init();    }}voidcl_cmdline::split_out_array(char *dot, char *param_str){  class cl_cmd_arg *aname, *aindex;         *dot= '\0';  dot++;  if (strchr("0123456789", *param_str) != NULL)    {      aname= new cl_cmd_int_arg((long)strtol(param_str, 0, 0));      aname->init();    }  else    {      aname= new cl_cmd_sym_arg(param_str);      aname->init();    }  if (*dot == '\0')    {      aname= 0;      con->dd_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->dd_printf("Uncomplete array index\n");         delete aname;       }      else           {         if (strchr("0123456789", *dot) != NULL)           {             aindex= new cl_cmd_int_arg((long)strtol(dot, 0, 0));             aindex->init();           }         else           {             aindex= new cl_cmd_sym_arg(dot);             aindex->init();           }         class cl_cmd_arg *arg;         params->add(arg= new cl_cmd_array_arg(aname, aindex));         arg->init();       }    }}intcl_cmdline::shift(void){  char *s= skip_delims(cmd);  set_name(0);  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, "params");      split();      if (strcmp(get_name(), "\n") == 0)	set_name(0);    }  return(have_real_name());}intcl_cmdline::repeat(void){  char *n;  return((n= get_name()) &&	 *n == '\n');}class cl_cmd_arg *cl_cmdline::param(int num){  if (num >= params->count)    return(0);  return((class cl_cmd_arg *)(params->at(num)));}voidcl_cmdline::insert_param(int pos, class cl_cmd_arg *param){  if (pos >= params->count)    params->add(param);  else    params->add_at(pos, param);}boolcl_cmdline::syntax_match(class cl_uc *uc, char *syntax){  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);      if (uc)	switch (*p)	  {	  case SY_ADDR:	    if (!parm->as_address(uc))	      return(DD_FALSE);	    //printf("ADDRESS match %lx\n",parm->value.address);	    break;	  case SY_MEMORY:	    if (!parm->as_memory(uc))	      return(DD_FALSE);	    //printf("MEMORY match %s\n",parm->value.memory->class_name);	    break;	  case SY_BIT:	    if (!parm->as_bit(uc))	      return(DD_FALSE);	    break;	  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -