示例#1
0
unichar *
unichar_dup (const unichar *unicode)
{
  unichar *r;
  int len;

  if (! unicode)
    return NULL;
  for (len = 0; unicode[len] != 0; ++len)
    ;
  ++len;
  r = ((unichar *) res_alloc (len * sizeof (unichar)));
  memcpy (r, unicode, len * sizeof (unichar));
  return r;
}
/* Read a resource entry, returns 0 when all resources are read */
static int
read_resource_entry (windres_bfd *wrbfd, rc_uint_type *off, rc_uint_type omax)
{
    rc_res_id type;
    rc_res_id name;
    rc_res_res_info resinfo;
    res_hdr reshdr;
    void *buff;

    rc_res_resource *r;
    struct bin_res_info l;

    off[0] = (off[0] + 3) & ~3;

    /* Read header */
    if ((off[0] + 8) > omax)
        return 0;
    read_res_data_hdr (wrbfd, off, omax, &reshdr);

    /* read resource type */
    read_res_id (wrbfd, off, omax, &type);
    /* read resource id */
    read_res_id (wrbfd, off, omax, &name);

    off[0] = (off[0] + 3) & ~3;

    /* Read additional resource header */
    read_res_data (wrbfd, off, omax, &l, BIN_RES_INFO_SIZE);
    resinfo.version = windres_get_32 (wrbfd, l.version, 4);
    resinfo.memflags = windres_get_16 (wrbfd, l.memflags, 2);
    resinfo.language = windres_get_16 (wrbfd, l.language, 2);
    /* resinfo.version2 = windres_get_32 (wrbfd, l.version2, 4); */
    resinfo.characteristics = windres_get_32 (wrbfd, l.characteristics, 4);

    off[0] = (off[0] + 3) & ~3;

    /* Allocate buffer for data */
    buff = res_alloc (reshdr.data_size);
    /* Read data */
    read_res_data (wrbfd, off, omax, buff, reshdr.data_size);
    /* Convert binary data to resource */
    r = bin_to_res (wrbfd, type, buff, reshdr.data_size);
    r->res_info = resinfo;
    /* Add resource to resource directory */
    res_add_resource (r, &type, &name, resinfo.language, 0);

    return 1;
}
示例#3
0
void
codepage_from_unicode (rc_uint_type *length, const unichar *unicode, char **ascii, rc_uint_type cp)
{
  rc_uint_type len;

  len = wind_WideCharToMultiByte (cp, unicode, NULL, 0);
  if (len)
    {
      *ascii = (char *) res_alloc (len * sizeof (char));
      wind_WideCharToMultiByte (cp, unicode, *ascii, len);
    }
  /* Discount the trailing '/0'.  If MultiByteToWideChar failed,
     this will set *length to -1.  */
  len--;

  if (length != NULL)
    *length = len;
}
示例#4
0
void
unicode_from_codepage (rc_uint_type *length, unichar **u, const char *src, rc_uint_type cp)
{
  rc_uint_type len;

  len = wind_MultiByteToWideChar (cp, src, NULL, 0);
  if (len)
    {
      *u = ((unichar *) res_alloc (len));
      wind_MultiByteToWideChar (cp, src, *u, len);
    }
  /* Discount the trailing '/0'.  If MultiByteToWideChar failed,
     this will set *length to -1.  */
  len -= sizeof (unichar);

  if (length != NULL)
    *length = len / sizeof (unichar);
}
示例#5
0
void
unicode_from_ascii (int *length, unichar **unicode, const char *ascii)
{
  int len;
  const char *s;
  unsigned short *w;

  len = strlen (ascii);

  if (length != NULL)
    *length = len;

  *unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar)));

#ifdef _WIN32
  /* FIXME: On Windows, we should be using MultiByteToWideChar to set
     the length.  */
  MultiByteToWideChar (CP_ACP, 0, ascii, len + 1, *unicode, len + 1);
#else
  for (s = ascii, w = *unicode; *s != '\0'; s++, w++)
    *w = *s & 0xff;
  *w = 0;
#endif
}
示例#6
0
void
unicode_from_ascii_len (rc_uint_type *length, unichar **unicode, const char *ascii, rc_uint_type a_length)
{
  char *tmp, *p;
  rc_uint_type tlen, elen, idx = 0;

  *unicode = NULL;

  if (!a_length)
    {
      if (length)
        *length = 0;
      return;
    }

  /* Make sure we have zero terminated string.  */
  p = tmp = (char *) xmalloc (a_length + 1);
  memcpy (tmp, ascii, a_length);
  tmp[a_length] = 0;

  while (a_length > 0)
    {
      unichar *utmp, *up;

      tlen = strlen (p);

      if (tlen > a_length)
        tlen = a_length;
      if (*p == 0)
        {
	  /* Make room for one more character.  */
	  utmp = (unichar *) res_alloc (sizeof (unichar) * (idx + 1));
	  if (idx > 0)
	    {
	      memcpy (utmp, *unicode, idx * sizeof (unichar));
	    }
	  *unicode = utmp;
	  utmp[idx++] = 0;
	  --a_length;
	  p++;
	  continue;
	}
      utmp = NULL;
      elen = 0;
      elen = wind_MultiByteToWideChar (wind_current_codepage, p, NULL, 0);
      if (elen)
	{
	  utmp = ((unichar *) res_alloc (elen + sizeof (unichar) * 2));
	  wind_MultiByteToWideChar (wind_current_codepage, p, utmp, elen);
	  elen /= sizeof (unichar);
	  elen --;
	}
      else
        {
	  /* Make room for one more character.  */
	  utmp = (unichar *) res_alloc (sizeof (unichar) * (idx + 1));
	  if (idx > 0)
	    {
	      memcpy (utmp, *unicode, idx * sizeof (unichar));
	    }
	  *unicode = utmp;
	  utmp[idx++] = ((unichar) *p) & 0xff;
	  --a_length;
	  p++;
	  continue;
	}
      p += tlen;
      a_length -= tlen;

      up = (unichar *) res_alloc (sizeof (unichar) * (idx + elen));
      if (idx > 0)
	memcpy (up, *unicode, idx * sizeof (unichar));

      *unicode = up;
      if (elen)
	memcpy (&up[idx], utmp, sizeof (unichar) * elen);

      idx += elen;
    }

  if (length)
    *length = idx;

  free (tmp);
}