#include <stdarg.h>
+#include <stddef.h>
#include "newt.h"
}
grid = newtCreateGrid(num, 1);
+ if (grid == NULL)
+ return NULL;
for (i = 0; i < num; i++) {
*buttons[i].compPtr = newtButton(-1, -1, buttons[i].name);
initialValue = ' ';
co = newtCheckbox(left, top, text, initialValue, " *", NULL);
+ if (co == NULL)
+ return NULL;
rb = co->data;
rb->type = RADIO;
struct CheckboxTree * ct;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
ct = malloc(sizeof(struct CheckboxTree));
+ if (ct == NULL) {
+ free(co);
+ return NULL;
+ }
co->callback = NULL;
co->destroyCallback = NULL;
co->data = ct;
struct entry * en;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
en = malloc(sizeof(struct entry));
+ if (en == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = en;
co->top = top;
en->bufAlloced = strlen(initialValue) + 1;
}
en->buf = malloc(en->bufAlloced);
+ if (en->buf == NULL) {
+ free(en);
+ free(co);
+ return NULL;
+ }
en->resultPtr = resultPtr;
if (en->resultPtr) *en->resultPtr = en->buf;
struct form * form;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
+
form = malloc(sizeof(*form));
+ if (form == NULL) {
+ free(co);
+ return NULL;
+ }
+
co->data = form;
co->width = 0;
co->height = 0;
co->callback = NULL;
co->destroyCallback = NULL;
+ form->elements = NULL;
+ form->hotKeys = NULL;
+
form->help = help;
form->flags = flags;
form->numCompsAlloced = 5;
form->maxFd = 0;
form->fds = NULL;
form->elements = malloc(sizeof(*(form->elements)) * form->numCompsAlloced);
+ if (form->elements == NULL) goto error;
form->background = COLORSET_WINDOW;
form->hotKeys = malloc(sizeof(int));
+ if (form->hotKeys == NULL) goto error;
+
form->numHotKeys = 0;
form->timer = 0;
form->lastTimeout.tv_sec = form->lastTimeout.tv_usec = 0;
form->helpCb = helpCallback;
return co;
+
+error:
+ free(form->hotKeys);
+ free(form->elements);
+ free(form);
+ free(co);
+
+ return NULL;
}
newtComponent newtFormGetCurrent(newtComponent co) {
newtGrid grid;
grid = malloc(sizeof(*grid));
+ if (grid == NULL)
+ return NULL;
grid->rows = rows;
grid->cols = cols;
grid->fields = malloc(sizeof(*grid->fields) * cols);
+ if (grid->fields == NULL) {
+ free(grid);
+ return NULL;
+ }
+
while (cols--) {
grid->fields[cols] = malloc(sizeof(**(grid->fields)) * rows);
+ if (grid->fields[cols] == NULL) {
+ for (cols++; cols < grid->cols; cols++)
+ free(grid->fields[cols]);
+ free(grid->fields);
+ free(grid);
+ return NULL;
+ }
memset(grid->fields[cols], 0, sizeof(**(grid->fields)) * rows);
}
}
grid = newtCreateGrid(isVert ? 1 : num, isVert ? num : 1);
+ if (grid == NULL)
+ return NULL;
for (i = 0; i < num; i++) {
newtGridSetField(grid, isVert ? 0 : i, isVert ? i : 0,
newtGrid grid;
grid = newtCreateGrid(1, 3);
+ if (grid == NULL)
+ return NULL;
+
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, middle,
newtGrid grid;
grid = newtCreateGrid(1, 3);
+ if (grid == NULL)
+ return NULL;
+
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text,
0, 0, 0, 0, NEWT_ANCHOR_LEFT, 0);
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, middle,
struct label * la;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
la = malloc(sizeof(struct label));
+ if (la == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = la;
co->destroyCallback = NULL;
struct scale * sc;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
sc = malloc(sizeof(struct scale));
+ if (sc == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = sc;
co->destroyCallback = NULL;
struct scrollbar * sb;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
sb = malloc(sizeof(*sb));
+ if (sb == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = sb;
co->destroyCallback = NULL;
reflowedText = newtReflowText(text, width, flexDown, flexUp,
&actWidth, &actHeight);
+ if (reflowedText == NULL)
+ return NULL;
co = newtTextbox(left, top, actWidth, actHeight, NEWT_FLAG_WRAP);
+ if (co == NULL) {
+ free(reflowedText);
+ return NULL;
+ }
+
newtTextboxSetText(co, reflowedText);
free(reflowedText);
struct textbox * tb;
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
tb = malloc(sizeof(*tb));
+ if (tb == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = tb;
if (width < 1)
int i;
buf = malloc(bufAlloced + 1);
+ if (buf == NULL)
+ return NULL;
+
for (src = text, dest = buf; *src; src++) {
if ((bufUsed + 10) > bufAlloced) {
bufAlloced += strlen(text) / 2;
buf = realloc(buf, bufAlloced + 1);
+ if (buf == NULL)
+ return NULL;
dest = buf + bufUsed;
}
if (*src == '\t') {
result = malloc(strlen(text) + (strlen(text) / (width - 1)) + 2);
} else
result = malloc(strlen(text) * 2 + 2);
+
*resultPtr = result;
+ if (result == NULL)
+ return;
}
memset(&ps,0,sizeof(mbstate_t));
width = 1;
expandedText = expandTabs(text);
+ if (expandedText == NULL)
+ return NULL;
if (flexDown || flexUp) {
min = width - flexDown;