resrc.c

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

C
2,671
字号
voidrcparse_warning (msg)     const char *msg;{  fprintf (stderr, _("%s:%d: %s\n"), rc_filename, rc_lineno, msg);}/* Die if we get an unexpected end of file.  */static voidunexpected_eof (msg)     const char *msg;{  fatal (_("%s: unexpected EOF"), msg);}/* Read a 16 bit word from a file.  The data is assumed to be little   endian.  */static intget_word (e, msg)     FILE *e;     const char *msg;{  int b1, b2;  b1 = getc (e);  b2 = getc (e);  if (feof (e))    unexpected_eof (msg);  return ((b2 & 0xff) << 8) | (b1 & 0xff);}/* Read a 32 bit word from a file.  The data is assumed to be little   endian.  */static unsigned longget_long (e, msg)     FILE *e;     const char *msg;{  int b1, b2, b3, b4;  b1 = getc (e);  b2 = getc (e);  b3 = getc (e);  b4 = getc (e);  if (feof (e))    unexpected_eof (msg);  return (((((((b4 & 0xff) << 8)	      | (b3 & 0xff)) << 8)	    | (b2 & 0xff)) << 8)	  | (b1 & 0xff));}/* Read data from a file.  This is a wrapper to do error checking.  */static voidget_data (e, p, c, msg)     FILE *e;     unsigned char *p;     unsigned long c;     const char *msg;{  unsigned long got;  got = fread (p, 1, c, e);  if (got == c)    return;  fatal (_("%s: read of %lu returned %lu"), msg, c, got);}/* Define an accelerator resource.  */voiddefine_accelerator (id, resinfo, data)     struct res_id id;     const struct res_res_info *resinfo;     struct accelerator *data;{  struct res_resource *r;  r = define_standard_resource (&resources, RT_ACCELERATOR, id,				resinfo->language, 0);  r->type = RES_TYPE_ACCELERATOR;  r->u.acc = data;  r->res_info = *resinfo;}/* Define a bitmap resource.  Bitmap data is stored in a file.  The   first 14 bytes of the file are a standard header, which is not   included in the resource data.  */#define BITMAP_SKIP (14)voiddefine_bitmap (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;  int i;  struct res_resource *r;  e = open_file_search (filename, FOPEN_RB, "bitmap 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 - BITMAP_SKIP);  for (i = 0; i < BITMAP_SKIP; i++)    getc (e);  get_data (e, data, s.st_size - BITMAP_SKIP, real_filename);  fclose (e);  free (real_filename);  r = define_standard_resource (&resources, RT_BITMAP, id,				resinfo->language, 0);  r->type = RES_TYPE_BITMAP;  r->u.data.length = s.st_size - BITMAP_SKIP;  r->u.data.data = data;  r->res_info = *resinfo;}/* Define a cursor resource.  A cursor file may contain a set of   bitmaps, each representing the same cursor at various different   resolutions.  They each get written out with a different ID.  The   real cursor resource is then a group resource which can be used to   select one of the actual cursors.  */voiddefine_cursor (id, resinfo, filename)     struct res_id id;     const struct res_res_info *resinfo;     const char *filename;{  FILE *e;  char *real_filename;  int type, count, i;  struct icondir *icondirs;  int first_cursor;  struct res_resource *r;  struct group_cursor *first, **pp;  e = open_file_search (filename, FOPEN_RB, "cursor file", &real_filename);  /* A cursor file is basically an icon file.  The start of the file     is a three word structure.  The first word is ignored.  The     second word is the type of data.  The third word is the number of     entries.  */  get_word (e, real_filename);  type = get_word (e, real_filename);  count = get_word (e, real_filename);  if (type != 2)    fatal (_("cursor file `%s' does not contain cursor data"), real_filename);  /* Read in the icon directory entries.  */  icondirs = (struct icondir *) xmalloc (count * sizeof *icondirs);  for (i = 0; i < count; i++)    {      icondirs[i].width = getc (e);      icondirs[i].height = getc (e);      icondirs[i].colorcount = getc (e);      getc (e);      icondirs[i].u.cursor.xhotspot = get_word (e, real_filename);      icondirs[i].u.cursor.yhotspot = get_word (e, real_filename);      icondirs[i].bytes = get_long (e, real_filename);      icondirs[i].offset = get_long (e, real_filename);      if (feof (e))	unexpected_eof (real_filename);    }  /* Define each cursor as a unique resource.  */  first_cursor = cursors;  for (i = 0; i < count; i++)    {      unsigned char *data;      struct res_id name;      struct cursor *c;      if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)	fatal (_("%s: fseek to %lu failed: %s"), real_filename,	       icondirs[i].offset, strerror (errno));      data = (unsigned char *) res_alloc (icondirs[i].bytes);      get_data (e, data, icondirs[i].bytes, real_filename);      c = (struct cursor *) res_alloc (sizeof *c);      c->xhotspot = icondirs[i].u.cursor.xhotspot;      c->yhotspot = icondirs[i].u.cursor.yhotspot;      c->length = icondirs[i].bytes;      c->data = data;      ++cursors;      name.named = 0;      name.u.id = cursors;      r = define_standard_resource (&resources, RT_CURSOR, name,				    resinfo->language, 0);      r->type = RES_TYPE_CURSOR;      r->u.cursor = c;      r->res_info = *resinfo;    }  fclose (e);  free (real_filename);  /* Define a cursor group resource.  */  first = NULL;  pp = &first;  for (i = 0; i < count; i++)    {      struct group_cursor *cg;      cg = (struct group_cursor *) res_alloc (sizeof *cg);      cg->next = NULL;      cg->width = icondirs[i].width;      cg->height = 2 * icondirs[i].height;      /* FIXME: What should these be set to?  */      cg->planes = 1;      cg->bits = 1;      cg->bytes = icondirs[i].bytes + 4;      cg->index = first_cursor + i + 1;      *pp = cg;      pp = &(*pp)->next;    }  free (icondirs);  r = define_standard_resource (&resources, RT_GROUP_CURSOR, id,				resinfo->language, 0);  r->type = RES_TYPE_GROUP_CURSOR;  r->u.group_cursor = first;  r->res_info = *resinfo;}/* Define a dialog resource.  */voiddefine_dialog (id, resinfo, dialog)     struct res_id id;     const struct res_res_info *resinfo;     const struct dialog *dialog;{  struct dialog *copy;  struct res_resource *r;  copy = (struct dialog *) res_alloc (sizeof *copy);  *copy = *dialog;  r = define_standard_resource (&resources, RT_DIALOG, id,				resinfo->language, 0);  r->type = RES_TYPE_DIALOG;  r->u.dialog = copy;  r->res_info = *resinfo;}/* Define a dialog control.  This does not define a resource, but   merely allocates and fills in a structure.  */struct dialog_control *define_control (text, id, x, y, width, height, class, style, exstyle)     const char *text;     unsigned long id;     unsigned long x;     unsigned long y;     unsigned long width;     unsigned long height;     unsigned long class;     unsigned long style;     unsigned long exstyle;{  struct dialog_control *n;  n = (struct dialog_control *) res_alloc (sizeof *n);  n->next = NULL;  n->id = id;  n->style = style;  n->exstyle = exstyle;  n->x = x;  n->y = y;  n->width = width;  n->height = height;  n->class.named = 0;  n->class.u.id = class;  if (text == NULL)    text = "";  res_string_to_id (&n->text, text);  n->data = NULL;  n->help = 0;  return n;}struct dialog_control *define_icon_control (iid, id, x, y, style, exstyle, help, data, ex)     struct res_id iid;     unsigned long id;     unsigned long x;     unsigned long y;     unsigned long style;     unsigned long exstyle;     unsigned long help;     struct rcdata_item *data;     struct dialog_ex *ex;{  struct dialog_control *n;  if (style == 0)    style = SS_ICON | WS_CHILD | WS_VISIBLE;  n = define_control (0, id, x, y, 0, 0, CTL_STATIC, style, exstyle);  n->text = iid;  if (help && !ex)    rcparse_warning (_("help ID requires DIALOGEX"));  if (data && !ex)    rcparse_warning (_("control data requires DIALOGEX"));  n->help = help;  n->data = data;  return n;}/* Define a font resource.  */voiddefine_font (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;  long offset;  long fontdatalength;  unsigned char *fontdata;  struct fontdir *fd;  const char *device, *face;  struct fontdir **pp;  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);  r = define_standard_resource (&resources, RT_FONT, id,				resinfo->language, 0);  r->type = RES_TYPE_FONT;  r->u.data.length = s.st_size;  r->u.data.data = data;  r->res_info = *resinfo;  /* For each font resource, we must add an entry in the FONTDIR     resource.  The FONTDIR resource includes some strings in the font     file.  To find them, we have to do some magic on the data we have     read.  */  offset = ((((((data[47] << 8)		| data[46]) << 8)	      | data[45]) << 8)	    | data[44]);  if (offset > 0 && offset < s.st_size)    device = (char *) data + offset;  else    device = "";  offset = ((((((data[51] << 8)		| data[50]) << 8)	      | data[49]) << 8)	    | data[48]);  if (offset > 0 && offset < s.st_size)    face = (char *) data + offset;  else    face = "";  ++fonts;  fontdatalength = 58 + strlen (device) + strlen (face);  fontdata = (unsigned char *) res_alloc (fontdatalength);  memcpy (fontdata, data, 56);  strcpy ((char *) fontdata + 56, device);  strcpy ((char *) fontdata + 57 + strlen (device), face);  fd = (struct fontdir *) res_alloc (sizeof *fd);  fd->next = NULL;  fd->index = fonts;  fd->length = fontdatalength;  fd->data = fontdata;  for (pp = &fontdirs; *pp != NULL; pp = &(*pp)->next)    ;  *pp = fd;  /* For the single fontdirs resource, we always use the resource     information of the last font.  I don't know what else to do.  */  fontdirs_resinfo = *resinfo;}/* Define the fontdirs resource.  This is called after the entire rc   file has been parsed, if any font resources were seen.  */static voiddefine_fontdirs (){  struct res_resource *r;  struct res_id id;  id.named = 0;  id.u.id = 1;  r = define_standard_resource (&resources, RT_FONTDIR, id, 0x409, 0);  r->type = RES_TYPE_FONTDIR;  r->u.fontdir = fontdirs;  r->res_info = fontdirs_resinfo;}/* Define an icon resource.  An icon file may contain a set of   bitmaps, each representing the same icon at various different   resolutions.  They each get written out with a different ID.  The   real icon resource is then a group resource which can be used to   select one of the actual icon bitmaps.  */voiddefine_icon (id, resinfo, filename)     struct res_id id;     const struct res_res_info *resinfo;     const char *filename;{  FILE *e;  char *real_filename;  int type, count, i;  struct icondir *icondirs;  int first_icon;  struct res_resource *r;  struct group_icon *first, **pp;  e = open_file_search (filename, FOPEN_RB, "icon file", &real_filename);  /* The start of an icon file is a three word structure.  The first     word is ignored.  The second word is the type of data.  The third     word is the number of entries.  */  get_word (e, real_filename);  type = get_word (e, real_filename);  count = get_word (e, real_filename);  if (type != 1)    fatal (_("icon file `%s' does not contain icon data"), real_filename);  /* Read in the icon directory entries.  */  icondirs = (struct icondir *) xmalloc (count * sizeof *icondirs);  for (i = 0; i < count; i++)    {      icondirs[i].width = getc (e);      icondirs[i].height = getc (e);      icondirs[i].colorcount = getc (e);      getc (e);      icondirs[i].u.icon.planes = get_word (e, real_filename);      icondirs[i].u.icon.bits = get_word (e, real_filename);      icondirs[i].bytes = get_long (e, real_filename);      icondirs[i].offset = get_long (e, real_filename);      if (feof (e))	unexpected_eof (real_filename);    }  /* Define each icon as a unique resource.  */  first_icon = icons;  for (i = 0; i < count; i++)    {      unsigned char *data;      struct res_id name;      if (fseek (e, icondirs[i].offset, SEEK_SET) != 0)	fatal (_("%s: fseek to %lu failed: %s"), real_filename,	       icondirs[i].offset, strerror (errno));      data = (unsigned char *) res_alloc (icondirs[i].bytes);      get_data (e, data, icondirs[i].bytes, real_filename);      ++icons;      name.named = 0;      name.u.id = icons;      r = define_standard_resource (&resources, RT_ICON, name,				    resinfo->language, 0);      r->type = RES_TYPE_ICON;      r->u.data.length = icondirs[i].bytes;      r->u.data.data = data;      r->res_info = *resinfo;    }  fclose (e);  free (real_filename);  /* Define an icon group resource.  */

⌨️ 快捷键说明

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