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

📄 cp-dem.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
    {      int member;      switch (**type)	{	case 'Q':	  n = (*type)[1] - '0';	  if (n < 0 || n > 9)	    success = 0;	  *type += 2;	  while (n-- > 0)	    do_type (type, result);	  break;	case 'P':	  *type += 1;	  string_prepend (&decl, "*");	  break;	case 'R':	  *type += 1;	  string_prepend (&decl, "&");	  break;	case 'T':	  *type += 1;	  if (!get_count (type, &n) || n >= ntypes)	    success = 0;	  else	    {	      remembered_type = typevec[n];	      type = &remembered_type;	    }	  break;	case 'F':	  *type += 1;	  if (!string_empty (&decl) && decl.b[0] == '*')	    {	      string_prepend (&decl, "(");	      string_append (&decl, ")");	    }	  if (!do_args (type, &decl) || **type != '_')	    success = 0;	  else	    *type += 1;	  break;	case 'M':	case 'O':	  {	    int constp = 0;	    int volatilep = 0;	    member = **type == 'M';	    *type += 1;	    if (!isdigit (**type))	      {		success = 0;		break;	      }	    n = 0;	    do	      {		n *= 10;		n += **type - '0';		*type += 1;	      } 	    while (isdigit (**type));	    if (strlen (*type) < n)	      {		success = 0;		break;	      }	    string_append (&decl, ")");	    string_prepend (&decl, "::");	    string_prependn (&decl, *type, n);	    string_prepend (&decl, "(");	    *type += n;	    if (member)	      {		if (**type == 'C')		  {		    *type += 1;		    constp = 1;		  }		if (**type == 'V')		  {		    *type += 1;		    volatilep = 1;		  }		if (*(*type)++ != 'F')		  {		    success = 0;		    break;		  }	      }	    if ((member && !do_args (type, &decl)) || **type != '_')	      {		success = 0;		break;	      }	    *type += 1;	    if (constp)	      {		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, "volatile");	      }	    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;	}    }  non_empty = 0;  if (success)    success = do_cuv_prefix (type, result, &non_empty);  if (success)    success = do_builtin_type(type, result, &non_empty);    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;    }}intdo_cuv_prefix (type, result, non_empty)     char **type;     string* result;     int* non_empty;{  int success = 1;  int done = 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;	}    }  return success;}intdo_builtin_type (type, result, non_empty)     char **type;     string* result;     int *non_empty;{  int success = 1;  int n;    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 'w':      *type += 1;      if (*non_empty)	string_append (result, " ");      string_append (result, "wchar_t");      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;    }  return success;}/* `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))    return;  if (name->p - name->b >= 3       && name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == CPLUS_MARKER)    {      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 (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;	}    }  /* ANSI.  */  else if (name->b[2] == 'o' && name->b[3] == 'p')    {      /* type conversion operator.  */      string type;      const char *tem = name->b + 4;      if (do_type (&tem, &type))	{	  string_clear (name);	  string_append (name, "operator ");	  string_appends (name, &type);	  string_delete (&type);	  return;	}    }  else if (name->b[2] >= 'a' && name->b[2] <= 'z'	   && name->b[3] >= 'a' && name->b[3] <= 'z')    {      int i;      if (name->b[4] == '\0')	{	  /* Operator.  */	  for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)	    {	      if (strlen (optable[i].in) == 2		  && memcmp (optable[i].in, name->b + 2, 2) == 0)		{		  string_clear (name);		  string_append (name, "operator");		  string_append (name, optable[i].out);		  return;		}	    }	}      else	{	  if (name->b[2] != 'a' || name->b[5] != '\0')	    return;	  /* Assignment.  */	  for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++)	    {	      if (strlen (optable[i].in) == 3		  && memcmp (optable[i].in, name->b + 2, 3) == 0)		{		  string_clear (name);		  string_append (name, "operator");		  string_append (name, optable[i].out);		  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 + -