static void
ptypedef (definition * def)
{
  char *name = def->def_name;
  char *old = def->def.ty.old_type;
  char prefix[8];		/* enough to contain "struct ", including NUL */
  relation rel = def->def.ty.rel;


  if (!streq (name, old)) {
    if (streq (old, "string")) {
      old = "char";
      rel = REL_POINTER;
    }
    else if (streq (old, "opaque")) {
      old = "char";
    }
    else if (streq (old, "bool")) {
      old = "bool_t";
    }
    if (undefined2 (old, name) && def->def.ty.old_prefix) {
      s_print (prefix, "%s ", def->def.ty.old_prefix);
    }
    else {
      prefix[0] = 0;
    }
    f_print (fout, "typedef ");
    switch (rel) {
    case REL_ARRAY:
      f_print (fout, "struct {\n");
#if 0
      f_print (fout, "\tu_int %s_len;\n", name);
      f_print (fout, "\t%s%s *%s_val;\n", prefix, old, name);
#else
      f_print (fout, "\tu_int len;\n");
      if (compatflag)
	f_print (fout, "#ifndef %s_len\n#define %s_len len\n#endif\n",
		 name, name);
      f_print (fout, "\t%s%s *val;\n", prefix, old);
      if (compatflag)
	f_print (fout, "#ifndef %s_val\n#define %s_val val\n#endif\n",
		 name, name);
#endif
      f_print (fout, "} %s", name);
      break;
    case REL_POINTER:
      f_print (fout, "%s%s *%s", prefix, old, name);
      break;
    case REL_VECTOR:
      f_print (fout, "%s%s %s[%s]", prefix, old, name,
	       def->def.ty.array_max);
      break;
    case REL_ALIAS:
      f_print (fout, "%s%s %s", prefix, old, name);
      break;
    }
    f_print (fout, ";\n");
  }
}
Exemple #2
0
static void
ptypedef(definition * def)
{
    char *name = def->def_name;
    char *old = def->def.ty.old_type;
    char prefix[8];		/* enough to contain "struct ", including NUL */
    relation rel = def->def.ty.rel;


    if (!streq(name, old)) {
	if (streq(old, "string")) {
	    old = "char";
	    rel = REL_POINTER;
	} else if (!brief_flag && streq(old, "opaque")) {
	    old = "char";
	} else if (streq(old, "bool")) {
	    old = "bool_t";
	}
	if (undefined2(old, name) && def->def.ty.old_prefix) {
	    s_print(prefix, "%s ", def->def.ty.old_prefix);
	} else {
	    prefix[0] = 0;
	}
	f_print(fout, "typedef ");
	switch (rel) {
	case REL_ARRAY:
	    if (brief_flag) {
	        if (streq(old, "opaque")) {
		    f_print(fout, "struct rx_opaque %s", name);
		} else {
		    f_print(fout, "struct {\n");
		    f_print(fout, "\tu_int len;\n");
		    f_print(fout, "\t%s%s *val;\n", prefix, old);
		    f_print(fout, "} %s", name);
		}
	    } else {
	        f_print(fout, "struct %s {\n", name);
		f_print(fout, "\tu_int %s_len;\n", name);
		f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
	        f_print(fout, "} %s", name);
	    }
	    break;
	case REL_POINTER:
	    f_print(fout, "%s%s *%s", prefix, old, name);
	    break;
	case REL_VECTOR:
	    f_print(fout, "%s%s %s[%s]", prefix, old, name,
		    def->def.ty.array_max);
	    break;
	case REL_ALIAS:
	    f_print(fout, "%s%s %s", prefix, old, name);
	    break;
	}
	def->pc.rel = rel;
	STOREVAL(&typedef_defined, def);
	f_print(fout, ";\n");
    }
}