resrc.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,671 行 · 第 1/5 页

C
2,671
字号
  first = NULL;  pp = &first;  for (i = 0; i < count; i++)    {      struct group_icon *cg;      /* For some reason, at least in some files the planes and bits         are zero.  We instead set them from the color.  This is         copied from rcl.  */      cg = (struct group_icon *) res_alloc (sizeof *cg);      cg->next = NULL;      cg->width = icondirs[i].width;      cg->height = icondirs[i].height;      cg->colors = icondirs[i].colorcount;      cg->planes = 1;      cg->bits = 0;      while ((1 << cg->bits) < cg->colors)	++cg->bits;      cg->bytes = icondirs[i].bytes;      cg->index = first_icon + i + 1;      *pp = cg;      pp = &(*pp)->next;    }  free (icondirs);  r = define_standard_resource (&resources, RT_GROUP_ICON, id,				resinfo->language, 0);  r->type = RES_TYPE_GROUP_ICON;  r->u.group_icon = first;  r->res_info = *resinfo;}/* Define a menu resource.  */voiddefine_menu (id, resinfo, menuitems)     struct res_id id;     const struct res_res_info *resinfo;     struct menuitem *menuitems;{  struct menu *m;  struct res_resource *r;  m = (struct menu *) res_alloc (sizeof *m);  m->items = menuitems;  m->help = 0;  r = define_standard_resource (&resources, RT_MENU, id, resinfo->language, 0);  r->type = RES_TYPE_MENU;  r->u.menu = m;  r->res_info = *resinfo;}/* Define a menu item.  This does not define a resource, but merely   allocates and fills in a structure.  */struct menuitem *define_menuitem (text, menuid, type, state, help, menuitems)     const char *text;     int menuid;     unsigned long type;     unsigned long state;     unsigned long help;     struct menuitem *menuitems;{  struct menuitem *mi;  mi = (struct menuitem *) res_alloc (sizeof *mi);  mi->next = NULL;  mi->type = type;  mi->state = state;  mi->id = menuid;  if (text == NULL)    mi->text = NULL;  else    unicode_from_ascii ((int *) NULL, &mi->text, text);  mi->help = help;  mi->popup = menuitems;  return mi;}/* Define a messagetable resource.  */voiddefine_messagetable (id, resinfo, filename)     struct res_id id;     const struct res_res_info *resinfo;     const char *filename;{  FILE *e;  char *real_filename;  struct stat s;  unsigned char *data;  struct res_resource *r;  e = open_file_search (filename, FOPEN_RB, "messagetable file",			&real_filename);  if (stat (real_filename, &s) < 0)    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,	   strerror (errno));  data = (unsigned char *) res_alloc (s.st_size);  get_data (e, data, s.st_size, real_filename);  fclose (e);  free (real_filename);  r = define_standard_resource (&resources, RT_MESSAGETABLE, id,				resinfo->language, 0);  r->type = RES_TYPE_MESSAGETABLE;  r->u.data.length = s.st_size;  r->u.data.data = data;  r->res_info = *resinfo;}/* Define an rcdata resource.  */voiddefine_rcdata (id, resinfo, data)     struct res_id id;     const struct res_res_info *resinfo;     struct rcdata_item *data;{  struct res_resource *r;  r = define_standard_resource (&resources, RT_RCDATA, id,				resinfo->language, 0);  r->type = RES_TYPE_RCDATA;  r->u.rcdata = data;  r->res_info = *resinfo;}/* Create an rcdata item holding a string.  */struct rcdata_item *define_rcdata_string (string, len)     const char *string;     unsigned long len;{  struct rcdata_item *ri;  char *s;  ri = (struct rcdata_item *) res_alloc (sizeof *ri);  ri->next = NULL;  ri->type = RCDATA_STRING;  ri->u.string.length = len;  s = (char *) res_alloc (len);  memcpy (s, string, len);  ri->u.string.s = s;  return ri;}/* Create an rcdata item holding a number.  */struct rcdata_item *define_rcdata_number (val, dword)     unsigned long val;     int dword;{  struct rcdata_item *ri;  ri = (struct rcdata_item *) res_alloc (sizeof *ri);  ri->next = NULL;  ri->type = dword ? RCDATA_DWORD : RCDATA_WORD;  ri->u.word = val;  return ri;}/* Define a stringtable resource.  This is called for each string   which appears in a STRINGTABLE statement.  */voiddefine_stringtable (resinfo, stringid, string)     const struct res_res_info *resinfo;     unsigned long stringid;     const char *string;{  struct res_id id;  struct res_resource *r;  id.named = 0;  id.u.id = (stringid >> 4) + 1;  r = define_standard_resource (&resources, RT_STRING, id,				resinfo->language, 1);  if (r->type == RES_TYPE_UNINITIALIZED)    {      int i;      r->type = RES_TYPE_STRINGTABLE;      r->u.stringtable = ((struct stringtable *)			  res_alloc (sizeof (struct stringtable)));      for (i = 0; i < 16; i++)	{	  r->u.stringtable->strings[i].length = 0;	  r->u.stringtable->strings[i].string = NULL;	}      r->res_info = *resinfo;    }  unicode_from_ascii (&r->u.stringtable->strings[stringid & 0xf].length,		      &r->u.stringtable->strings[stringid & 0xf].string,		      string);}/* Define a user data resource where the data is in the rc file.  */voiddefine_user_data (id, type, resinfo, data)     struct res_id id;     struct res_id type;     const struct res_res_info *resinfo;     struct rcdata_item *data;{  struct res_id ids[3];  struct res_resource *r;  ids[0] = type;  ids[1] = id;  ids[2].named = 0;  ids[2].u.id = resinfo->language;  r = define_resource (&resources, 3, ids, 0);  r->type = RES_TYPE_USERDATA;  r->u.userdata = data;  r->res_info = *resinfo;}/* Define a user data resource where the data is in a file.  */voiddefine_user_file (id, type, resinfo, filename)     struct res_id id;     struct res_id type;     const struct res_res_info *resinfo;     const char *filename;{  FILE *e;  char *real_filename;  struct stat s;  unsigned char *data;  struct res_id ids[3];  struct res_resource *r;  e = open_file_search (filename, FOPEN_RB, "font file", &real_filename);  if (stat (real_filename, &s) < 0)    fatal (_("stat failed on bitmap file `%s': %s"), real_filename,	   strerror (errno));  data = (unsigned char *) res_alloc (s.st_size);  get_data (e, data, s.st_size, real_filename);  fclose (e);  free (real_filename);  ids[0] = type;  ids[1] = id;  ids[2].named = 0;  ids[2].u.id = resinfo->language;  r = define_resource (&resources, 3, ids, 0);  r->type = RES_TYPE_USERDATA;  r->u.userdata = ((struct rcdata_item *)		   res_alloc (sizeof (struct rcdata_item)));  r->u.userdata->next = NULL;  r->u.userdata->type = RCDATA_BUFFER;  r->u.userdata->u.buffer.length = s.st_size;  r->u.userdata->u.buffer.data = data;  r->res_info = *resinfo;}/* Define a versioninfo resource.  */voiddefine_versioninfo (id, language, fixedverinfo, verinfo)     struct res_id id;     int language;     struct fixed_versioninfo *fixedverinfo;     struct ver_info *verinfo;{  struct res_resource *r;  r = define_standard_resource (&resources, RT_VERSION, id, language, 0);  r->type = RES_TYPE_VERSIONINFO;  r->u.versioninfo = ((struct versioninfo *)		      res_alloc (sizeof (struct versioninfo)));  r->u.versioninfo->fixed = fixedverinfo;  r->u.versioninfo->var = verinfo;  r->res_info.language = language;}/* Add string version info to a list of version information.  */struct ver_info *append_ver_stringfileinfo (verinfo, language, strings)     struct ver_info *verinfo;     const char *language;     struct ver_stringinfo *strings;{  struct ver_info *vi, **pp;  vi = (struct ver_info *) res_alloc (sizeof *vi);  vi->next = NULL;  vi->type = VERINFO_STRING;  unicode_from_ascii ((int *) NULL, &vi->u.string.language, language);  vi->u.string.strings = strings;  for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)    ;  *pp = vi;  return verinfo;}/* Add variable version info to a list of version information.  */struct ver_info *append_ver_varfileinfo (verinfo, key, var)     struct ver_info *verinfo;     const char *key;     struct ver_varinfo *var;{  struct ver_info *vi, **pp;  vi = (struct ver_info *) res_alloc (sizeof *vi);  vi->next = NULL;  vi->type = VERINFO_VAR;  unicode_from_ascii ((int *) NULL, &vi->u.var.key, key);  vi->u.var.var = var;  for (pp = &verinfo; *pp != NULL; pp = &(*pp)->next)    ;  *pp = vi;  return verinfo;}/* Append version string information to a list.  */struct ver_stringinfo *append_verval (strings, key, value)     struct ver_stringinfo *strings;     const char *key;     const char *value;{  struct ver_stringinfo *vs, **pp;  vs = (struct ver_stringinfo *) res_alloc (sizeof *vs);  vs->next = NULL;  unicode_from_ascii ((int *) NULL, &vs->key, key);  unicode_from_ascii ((int *) NULL, &vs->value, value);  for (pp = &strings; *pp != NULL; pp = &(*pp)->next)    ;  *pp = vs;  return strings;}/* Append version variable information to a list.  */struct ver_varinfo *append_vertrans (var, language, charset)     struct ver_varinfo *var;     unsigned long language;     unsigned long charset;{  struct ver_varinfo *vv, **pp;  vv = (struct ver_varinfo *) res_alloc (sizeof *vv);  vv->next = NULL;  vv->language = language;  vv->charset = charset;  for (pp = &var; *pp != NULL; pp = &(*pp)->next)    ;  *pp = vv;  return var;}/* Local functions used to write out an rc file.  */static void indent PARAMS ((FILE *, int));static void write_rc_directory  PARAMS ((FILE *, const struct res_directory *, const struct res_id *,	   const struct res_id *, int *, int));static void write_rc_subdir  PARAMS ((FILE *, const struct res_entry *, const struct res_id *,	   const struct res_id *, int *, int));static void write_rc_resource  PARAMS ((FILE *, const struct res_id *, const struct res_id *,	   const struct res_resource *, int *));static void write_rc_accelerators  PARAMS ((FILE *, const struct accelerator *));static void write_rc_cursor PARAMS ((FILE *, const struct cursor *));static void write_rc_group_cursor  PARAMS ((FILE *, const struct group_cursor *));static void write_rc_dialog PARAMS ((FILE *, const struct dialog *));static void write_rc_dialog_control  PARAMS ((FILE *, const struct dialog_control *));static void write_rc_fontdir PARAMS ((FILE *, const struct fontdir *));static void write_rc_group_icon PARAMS ((FILE *, const struct group_icon *));static void write_rc_menu PARAMS ((FILE *, const struct menu *, int));static void write_rc_menuitems  PARAMS ((FILE *, const struct menuitem *, int, int));static void write_rc_rcdata PARAMS ((FILE *, const struct rcdata_item *, int));static void write_rc_stringtable  PARAMS ((FILE *, const struct res_id *, const struct stringtable *));static void write_rc_versioninfo PARAMS ((FILE *, const struct versioninfo *));static void write_rc_filedata  PARAMS ((FILE *, unsigned long, const unsigned char *));/* Indent a given number of spaces.  */static voidindent (e, c)     FILE *e;     int c;{  int i;  for (i = 0; i < c; i++)    putc (' ', e);}/* Dump the resources we have read in the format of an rc file.   Actually, we don't use the format of an rc file, because it's way   too much of a pain--for example, we'd have to write icon resources   into a file and refer to that file.  We just generate a readable   format that kind of looks like an rc file, and is useful for   understanding the contents of a resource file.  Someday we may want   to generate an rc file which the rc compiler can read; if that day   comes, this code will have to be fixed up.  */voidwrite_rc_file (filename, resources)     const char *filename;     const struct res_directory *resources;{  FILE *e;  int language;  if (filename == NULL)    e = stdout;  else    {      e = fopen (filename, FOPEN_WT);      if (e == NULL)	fatal (_("can't open `%s' for output: %s"), filename, strerror (errno));    }  language = -1;  write_rc_directory (e, resources, (const struct res_id *) NULL,		      (const struct res_id *) NULL, &language, 1);}/* Write out a directory.  E is the file to write to.  RD is the   directory.  TYPE is a pointer to the level 1 ID which serves as the   resource type.  NAME is a pointer to the level 2 ID which serves as   an individual resource name.  LANGUAGE is a pointer to the current   language.  LEVEL is the level in the tree.  */static voidwrite_rc_directory (e, rd, type, name, language, level)     FILE *e;     const struct res_directory *rd;     const struct res_id *type;     const struct res_id *name;     int *language;     int level;{  const struct res_entry *re;  /* Print out some COFF information that rc files can't represent.  */  if (rd->time != 0)    fprintf (e, "// Time stamp: %lu\n", rd->time);  if (rd->characteristics != 0)    fprintf (e, "// Characteristics: %lu\n", rd->characteristics);  if (rd->major != 0 || rd->minor != 0)    fprintf (e, "// Version: %d %d\n", rd->major, rd->minor);  for (re = rd->entries;  re != NULL; re = re->next)    {      switch (level)	{	case 1:	  /* If we're at level 1, the key of this resource is the             type.  This normally duplicates the information we have             stored with the resource itself, but we need to remember             the type if this is a user define resource type.  */	  type = &re->id;	  break;	case 2:	  /* If we're at level 2, the key of this resource is the name	     we are going to use in the rc printout. */	  name = &re->id;	  break;	case 3:	  /* If we're at level 3, then this key represents a language.	     Use it to update the current language.  */	  if (! re->id.named	      && re->id.u.id != (unsigned long) (unsigned int) *language	      && (re->id.u.id & 0xffff) == re->id.u.id)	    {	      fprintf (e, "LANGUAGE %lu, %lu\n",		       re->id.u.id & 0xff, (re->id.u.id >> 8) & 0xff);	      *language = re->id.u.id;	    }	  break;	default:	  break;	}      if (re->subdir)	write_rc_subdir (e, re, type, name, language, level);

⌨️ 快捷键说明

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