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

📄 cplus-dem.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		if (non_empty)		  string_append (&decl, " ");		else		  non_empty = 1;		string_append (&decl, "const");	      }	    if (volatilep)	      {		if (non_empty)		  string_append (&decl, " ");		else		  non_empty = 1;		string_append (&decl, "volatilep");	      }	    break;	  }	case 'C':	  if ((*type)[1] == 'P')	    {	      *type += 1;	      if (!string_empty (&decl))		string_prepend (&decl, " ");	      string_prepend (&decl, "const");	      break;	    }	  /* fall through */	default:	  done = 1;	  break;	}    }  done = 0;  non_empty = 0;  while (success && !done)    {      switch (**type)	{	case 'C':	  *type += 1;	  if (non_empty)	    string_append (result, " ");	  else	    non_empty = 1;	  string_append (result, "const");	  break;	case 'U':	  *type += 1;	  if (non_empty)	    string_append (result, " ");	  else	    non_empty = 1;	  string_append (result, "unsigned");	  break;	case 'V':	  *type += 1;	  if (non_empty)	    string_append (result, " ");	  else	    non_empty = 1;	  string_append (result, "volatile");	  break;	default:	  done = 1;	  break;	}    }  if (success)    switch (**type)      {      case '\0':      case '_':	break;      case 'v':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "void");	break;      case 'x':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "long long");	break;      case 'l':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "long");	break;      case 'i':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "int");	break;      case 's':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "short");	break;      case 'c':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "char");	break;      case 'r':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "long double");	break;      case 'd':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "double");	break;      case 'f':	*type += 1;	if (non_empty)	  string_append (result, " ");	string_append (result, "float");	break;      case 'G':	*type += 1;	if (!isdigit (**type))	  {	    success = 0;	    break;	  }	/* fall through */      case '0':      case '1':      case '2':      case '3':      case '4':      case '5':      case '6':      case '7':      case '8':      case '9':	n = 0;	do	  {	    n *= 10;	    n += **type - '0';	    *type += 1;	  }	while (isdigit (**type));	if (strlen (*type) < n)	  {	    success = 0;	    break;	  }	if (non_empty)	  string_append (result, " ");	string_appendn (result, *type, n);	*type += n;	break;      default:	success = 0;	break;      }  if (success)    {      if (!string_empty (&decl))	{	  string_append (result, " ");	  string_appends (result, &decl);	}      string_delete (&decl);      return 1;    }  else    {      string_delete (&decl);      string_delete (result);      return 0;    }}/* `result' will be initialised in do_type; it will be freed on failure */static intdo_arg (type, result)     const char **type;     string *result;{  const char *start = *type;  if (!do_type (type, result))    return 0;  remember_type (start, *type - start);  return 1;}static voidremember_type (start, len)     const char *start;     int len;{  char *tem;  if (ntypes >= typevec_size)    {      if (typevec_size == 0)	{	  typevec_size = 3;	  typevec = (char **) xmalloc (sizeof (char*)*typevec_size);	}      else	{	  typevec_size *= 2;	  typevec = (char **) xrealloc ((char *)typevec, sizeof (char*)*typevec_size);	}    }  tem = (char *) xmalloc (len + 1);  memcpy (tem, start, len);  tem[len] = '\0';  typevec[ntypes++] = tem;}/* `decl' must be already initialised, usually non-empty;   it won't be freed on failure */static intdo_args (type, decl)     const char **type;     string *decl;{  string arg;  int need_comma = 0;  string_append (decl, "(");  while (**type != '_' && **type != '\0' && **type != 'e' && **type != 'v')    {      if (**type == 'N')	{	  int r;	  int t;	  *type += 1;	  if (!get_count (type, &r) || !get_count (type, &t) || t >= ntypes)	    return 0;	  while (--r >= 0)	    {	      const char *tem = typevec[t];	      if (need_comma)		string_append (decl, ", ");	      if (!do_arg (&tem, &arg))		return 0;	      string_appends (decl, &arg);	      string_delete (&arg);	      need_comma = 1;	    }	}      else	{	  if (need_comma)	    string_append (decl, ", ");	  if (!do_arg (type, &arg))	    return 0;	  string_appends (decl, &arg);	  string_delete (&arg);	  need_comma = 1;	}    }  if (**type == 'v')    *type += 1;  else if (**type == 'e')    {      *type += 1;      if (need_comma)	string_append (decl, ",");      string_append (decl, "...");    }  string_append (decl, ")");  return 1;}static voidmunge_function_name (name)     string *name;{  if (!string_empty (name) && name->p - name->b >= 3       && name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == '$')    {      int i;      /* see if it's an assignment expression */      if (name->p - name->b >= 10 /* op$assign_ */	  && memcmp (name->b + 3, "assign_", 7) == 0)	{	  for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)	    {	      int len = name->p - name->b - 10;	      if (strlen (optable[i].in) == len		  && memcmp (optable[i].in, name->b + 10, len) == 0)		{		  string_clear (name);		  string_append (name, "operator");		  string_append (name, optable[i].out);		  string_append (name, "=");		  return;		}	    }	}      else	{	  for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)	    {	      int len = name->p - name->b - 3;	      if (strlen (optable[i].in) == len 		  && memcmp (optable[i].in, name->b + 3, len) == 0)		{		  string_clear (name);		  string_append (name, "operator");		  string_append (name, optable[i].out);		  return;		}	    }	}      return;    }  else if (!string_empty (name) && name->p - name->b >= 5	   && memcmp (name->b, "type$", 5) == 0)    {      /* type conversion operator */      string type;      const char *tem = name->b + 5;      if (do_type (&tem, &type))	{	  string_clear (name);	  string_append (name, "operator ");	  string_appends (name, &type);	  string_delete (&type);	  return;	}    }}/* a mini string-handling package */static voidstring_need (s, n)     string *s;     int n;{  if (s->b == NULL)    {      if (n < 32)	n = 32;      s->p = s->b = (char *) xmalloc (n);      s->e = s->b + n;    }  else if (s->e - s->p < n)    {      int tem = s->p - s->b;      n += tem;      n *= 2;      s->b = (char *) xrealloc (s->b, n);      s->p = s->b + tem;      s->e = s->b + n;    }}static voidstring_delete (s)     string *s;{  if (s->b != NULL)    {      free (s->b);      s->b = s->e = s->p = NULL;    }}static voidstring_init (s)     string *s;{  s->b = s->p = s->e = NULL;}static void string_clear (s)     string *s;{  s->p = s->b;}static intstring_empty (s)     string *s;{  return s->b == s->p;}static voidstring_append (p, s)     string *p;     const char *s;{  int n;  if (s == NULL || *s == '\0')    return;  n = strlen (s);  string_need (p, n);  memcpy (p->p, s, n);  p->p += n;}static voidstring_appends (p, s)     string *p, *s;{  int n;  if (s->b == s->p)    return;  n = s->p - s->b;  string_need (p, n);  memcpy (p->p, s->b, n);  p->p += n;}static voidstring_appendn (p, s, n)     string *p;     const char *s;     int n;{  if (n == 0)    return;  string_need (p, n);  memcpy (p->p, s, n);  p->p += n;}static voidstring_prepend (p, s)     string *p;     const char *s;{  if (s == NULL || *s == '\0')    return;  string_prependn (p, s, strlen (s));}#if 0static voidstring_prepends (p, s)     string *p, *s;{  if (s->b == s->p)    return;  string_prependn (p, s->b, s->p - s->b);}#endifstatic voidstring_prependn (p, s, n)     string *p;     const char *s;     int n;{  char *q;  if (n == 0)    return;  string_need (p, n);  for (q = p->p - 1; q >= p->b; q--)    q[n] = q[0];  memcpy (p->b, s, n);  p->p += n;}

⌨️ 快捷键说明

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