#include <assert.h>
#include <limits.h>
#include <stdarg.h>
+#include <stdlib.h>
#define DEFINE_INTORPTR_FNS
struct controlbox *ctrl_new_box(void)
{
- struct controlbox *ret = smalloc(sizeof(struct controlbox));
+ struct controlbox *ret = snew(struct controlbox);
ret->nctrlsets = ret->ctrlsetsize = 0;
ret->ctrlsets = NULL;
char *path, char *title)
{
- struct controlset *s = smalloc(sizeof(struct controlset));
+ struct controlset *s = snew(struct controlset);
int index = ctrl_find_set(b, path, 1);
s->pathname = dupstr(path);
s->boxname = NULL;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
- b->ctrlsets = srealloc(b->ctrlsets,
- b->ctrlsetsize*sizeof(*b->ctrlsets));
+ b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
return b->ctrlsets[index];
index++;
}
- s = smalloc(sizeof(struct controlset));
+ s = snew(struct controlset);
s->pathname = dupstr(path);
s->boxname = dupstr(name);
s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
s->ctrls = NULL;
if (b->nctrlsets >= b->ctrlsetsize) {
b->ctrlsetsize = b->nctrlsets + 32;
- b->ctrlsets = srealloc(b->ctrlsets,
- b->ctrlsetsize*sizeof(*b->ctrlsets));
+ b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
}
if (index < b->nctrlsets)
memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
void *ctrl_alloc(struct controlbox *b, size_t size)
{
void *p;
+ /*
+ * This is an internal allocation routine, so it's allowed to
+ * use smalloc directly.
+ */
p = smalloc(size);
if (b->nfrees >= b->freesize) {
b->freesize = b->nfrees + 32;
- b->frees = srealloc(b->frees, b->freesize*sizeof(*b->frees));
+ b->frees = sresize(b->frees, b->freesize, void *);
}
b->frees[b->nfrees++] = p;
return p;
intorptr helpctx, handler_fn handler,
intorptr context)
{
- union control *c = smalloc(sizeof(union control));
+ union control *c = snew(union control);
if (s->ncontrols >= s->ctrlsize) {
s->ctrlsize = s->ncontrols + 32;
- s->ctrls = srealloc(s->ctrls, s->ctrlsize * sizeof(*s->ctrls));
+ s->ctrls = sresize(s->ctrls, s->ctrlsize, union control *);
}
s->ctrls[s->ncontrols++] = c;
/*
} else {
va_list ap;
int i;
- c->columns.percentages = smalloc(ncolumns * sizeof(int));
+ c->columns.percentages = snewn(ncolumns, int);
va_start(ap, ncolumns);
for (i = 0; i < ncolumns; i++)
c->columns.percentages[i] = va_arg(ap, int);
while (va_arg(ap, char *) != NULL) {
i++;
if (c->radio.shortcut == NO_SHORTCUT)
- va_arg(ap, int); /* char promotes to int in arg lists */
- va_arg(ap, intorptr);
+ (void)va_arg(ap, int); /* char promotes to int in arg lists */
+ (void)va_arg(ap, intorptr);
}
va_end(ap);
c->radio.nbuttons = i;
if (c->radio.shortcut == NO_SHORTCUT)
- c->radio.shortcuts = smalloc(c->radio.nbuttons * sizeof(char));
+ c->radio.shortcuts = snewn(c->radio.nbuttons, char);
else
c->radio.shortcuts = NULL;
- c->radio.buttons = smalloc(c->radio.nbuttons * sizeof(char *));
- c->radio.buttondata = smalloc(c->radio.nbuttons * sizeof(intorptr));
+ c->radio.buttons = snewn(c->radio.nbuttons, char *);
+ c->radio.buttondata = snewn(c->radio.nbuttons, intorptr);
/*
* Second pass along variable argument list to actually fill in
* the structure.
c->button.label = label ? dupstr(label) : NULL;
c->button.shortcut = shortcut;
c->button.isdefault = 0;
+ c->button.iscancel = 0;
return c;
}
c->listbox.draglist = 0;
c->listbox.multisel = 0;
c->listbox.percentwidth = percentage;
+ c->listbox.ncols = 0;
+ c->listbox.percentages = NULL;
return c;
}
c->listbox.draglist = 1;
c->listbox.multisel = 0;
c->listbox.percentwidth = 100;
+ c->listbox.ncols = 0;
+ c->listbox.percentages = NULL;
return c;
}