Esempio n. 1
0
static struct Ebl_GStrent *
newstring (struct Ebl_GStrtab *st, const char *str, size_t len)
{
  /* Compute the amount of padding needed to make the structure aligned.  */
  size_t align = ((__alignof__ (struct Ebl_GStrent)
		   - (((uintptr_t) st->backp)
		      & (__alignof__ (struct Ebl_GStrent) - 1)))
		  & (__alignof__ (struct Ebl_GStrent) - 1));

  /* Make sure there is enough room in the memory block.  */
  if (st->left < align + sizeof (struct Ebl_GStrent) + len * st->width)
    {
      morememory (st, sizeof (struct Ebl_GStrent) + len * st->width);
      align = 0;
    }

  /* Create the reserved string.  */
  struct Ebl_GStrent *newstr = (struct Ebl_GStrent *) (st->backp + align);
  newstr->string = str;
  newstr->len = len;
  newstr->width = st->width;
  newstr->next = NULL;
  newstr->left = NULL;
  newstr->right = NULL;
  newstr->offset = 0;
  for (int i = len - 2; i >= 0; --i)
    for (int j = st->width - 1; j >= 0; --j)
      newstr->reverse[i * st->width + j] = str[(len - 2 - i) * st->width + j];
  for (size_t j = 0; j < st->width; ++j)
    newstr->reverse[(len - 1) * st->width + j] = '\0';
  st->backp += align + sizeof (struct Ebl_GStrent) + len * st->width;
  st->left -= align + sizeof (struct Ebl_GStrent) + len * st->width;

  return newstr;
}
Esempio n. 2
0
static struct Ebl_WStrent *
newstring (struct Ebl_WStrtab *st, const wchar_t *str, size_t len)
{
  struct Ebl_WStrent *newstr;
  size_t align;
  int i;

  /* Compute the amount of padding needed to make the structure aligned.  */
  align = ((__alignof__ (struct Ebl_WStrent)
	    - (((uintptr_t) st->backp)
	       & (__alignof__ (struct Ebl_WStrent) - 1)))
	   & (__alignof__ (struct Ebl_WStrent) - 1));

  /* Make sure there is enough room in the memory block.  */
  if (st->left < align + sizeof (struct Ebl_WStrent) + len * sizeof (wchar_t))
    {
      if (morememory (st,
		      sizeof (struct Ebl_WStrent) + len * sizeof (wchar_t)))
	return NULL;

      align = 0;
    }

  /* Create the reserved string.  */
  newstr = (struct Ebl_WStrent *) (st->backp + align);
  newstr->string = str;
  newstr->len = len;
  newstr->next = NULL;
  newstr->left = NULL;
  newstr->right = NULL;
  newstr->offset = 0;
  for (i = len - 2; i >= 0; --i)
    newstr->reverse[i] = str[len - 2 - i];
  newstr->reverse[len - 1] = L'\0';
  st->backp += align + sizeof (struct Ebl_WStrent) + len * sizeof (wchar_t);
  st->left -= align + sizeof (struct Ebl_WStrent) + len * sizeof (wchar_t);

  return newstr;
}