Что-то мне посказывает, что я тут наговнокодил. Слишком много раз проверяю imageXX [!=]= SML_NOTASSIGNED. Как сократить?
int SmlWindowIconSet(int index, int image16, int image32)
{
if ((warehouse.win.count <= index) ||
(warehouse.win.alive[index]) == SML_DEAD)
{
return SML_ERR_BADWINDOW;
}
if ((image16 == SML_NOTASSIGNED) &&
(image32 == SML_NOTASSIGNED))
return SML_ERR_BADIMAGE;
if ((image16 != SML_NOTASSIGNED) &&
((warehouse.img.count <= image16) ||
(warehouse.img.alive[image16] == SML_DEAD) ||
(warehouse.img.ptr[image16]->width != 16) ||
(warehouse.img.ptr[image16]->height != 16)))
{
return SML_ERR_BADIMAGE;
}
if ((image32 != SML_NOTASSIGNED) &&
((warehouse.img.count <= image32) ||
(warehouse.img.alive[image32] == SML_DEAD) ||
(warehouse.img.ptr[image32]->width != 32) ||
(warehouse.img.ptr[image32]->height != 32)))
{
return SML_ERR_BADIMAGE;
}
int memsize = 0;
if (image16 != SML_NOTASSIGNED) memsize += 2 + 16 * 16;
if (image32 != SML_NOTASSIGNED) memsize += 2 + 32 * 32;
int * data = malloc(memsize * 4);
if (data == NULL)
return SML_ERR_BADALLOC;
int count = 0;
if (image16 != SML_NOTASSIGNED)
{
data[count++] = 16;
data[count++] = 16;
memcpy(data + count, warehouse.img.ptr[image16]->data, 16 * 16 * 4);
count += 16 * 16;
}
if (image32 != SML_NOTASSIGNED)
{
data[count++] = 32;
data[count++] = 32;
memcpy(data + count, warehouse.img.ptr[image32]->data, 32 * 32 * 4);
count += 32 * 32;
}
int err = XChangeProperty(warehouse.display,
warehouse.win.ptr[index].window,
warehouse.atoms.wmicon,
warehouse.atoms.cardinal,
32, PropModeReplace,
(const unsigned char *) data, count);
SML_CHECKERROR(err);
return SML_ERR_SUCCESS;
}