-LIBS = -lslang -lm #-lefence
-SHLIBS = -lslang -lm -lc
+LIBS = -lslang -lm -ldl #-lefence
+SHLIBS = -lslang -lm -dl -lc
GPM_SUPPORT=@gpm_support@
-CFLAGS = $(RPM_OPT_FLAGS) -Wall -I/usr/include/slang -D_GNU_SOURCE
-ifeq ($(RPM_OPT_FLAGS),)
-CFLAGS += -g
-endif
+CFLAGS = $(RPM_OPT_FLAGS) -Wall -I/usr/include/slang -D_GNU_SOURCE -g -O2 -DUTF8
VERSION = @VERSION@
CVSTAG = r$(subst .,-,$(VERSION))
all: $(TARGET) _snackmodule.so
test: $(TESTOBJS) $(LIBNEWT)
- gcc -g -o test $(TESTOBJS) $(LIBNEWT) $(LIBS) -static
+ $(CC) -g -o test $(TESTOBJS) $(LIBNEWT) $(LIBS) -static
testgrid: testgrid.o $(LIBNEWT)
- gcc -g -o testgrid testgrid.o $(LIBNEWT) $(LIBS)
+ $(CC) -g -o testgrid testgrid.o $(LIBNEWT) $(LIBS)
testtree: testtree.o $(LIBNEWT)
- gcc -g -o testtree testtree.o $(LIBNEWT) $(LIBS)
+ $(CC) -g -o testtree testtree.o $(LIBNEWT) $(LIBS)
showchars: showchars.o $(LIBNEWT)
- gcc -g -o showchars showchars.o $(LIBNEWT) $(LIBS)
+ $(CC) -g -o showchars showchars.o $(LIBNEWT) $(LIBS)
showkey: showkey.o $(LIBNEWT)
- gcc -g -o showkey showkey.o $(LIBNEWT) $(LIBS)
+ $(CC) -g -o showkey showkey.o $(LIBNEWT) $(LIBS)
_snackmodule.so: snackmodule.c $(LIBNEWTSH)
for ver in $(PYTHONVERS) ; do \
if [ ! -f "$$ver/_snackmodule.so" -o $(LIBNEWTSH) -nt "$$ver/_snackmodule.so" ]; then \
mkdir -p $$ver ;\
- gcc $(CFLAGS) -I/usr/include/$$ver -fPIC -c -o $$ver/snackmodule.o snackmodule.c ;\
- gcc --shared $(SHCFLAGS) -o $$ver/_snackmodule.so $$ver/snackmodule.o -L . $(LIBNEWTSH) ;\
+ $(CC) $(CFLAGS) -I/usr/include/$$ver -fPIC -c -o $$ver/snackmodule.o snackmodule.c ;\
+ $(CC) --shared $(SHCFLAGS) -o $$ver/_snackmodule.so $$ver/snackmodule.o -L . $(LIBNEWTSH) ;\
fi ; \
done
whiptail: $(NDIALOGOBJS) $(LIBNEWTSH)
- gcc -g -o whiptail $(NDIALOGOBJS) -L . $(LIBNEWTSH) $(LIBS) -lpopt
+ $(CC) -g -o whiptail $(NDIALOGOBJS) -L . $(LIBNEWTSH) $(LIBS) -lpopt
whiptcl.so: $(WHIPTCLOBJS) $(LIBNEWTSH)
gcc -shared $(SHCFLAGS) -o whiptcl.so $(WHIPTCLOBJS) -L . $(LIBNEWTSH) -ltcl -lslang -lpopt -lm
+# Ensure dialogboxes is compiled -fPIC
+dialogboxes.o: dialogboxes.c
+ $(CC) $(CFLAGS) $(SHCFLAGS) -c dialogboxes.c
+
+
$(LIBNEWT): $(LIBOBJS)
ar rv $@ $^
sharedlib: $(LIBNEWTSH)
$(LIBNEWTSH): $(SHAREDDIR) $(SHAREDOBJS)
- gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(SHLIBS)
+ $(CC) -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(SHLIBS)
$(SHAREDDIR)/%.o : %.c
$(CC) $(SHCFLAGS) -c $(CFLAGS) -o $@ $<
newtDefaultMappedHandler,
} ;
+/*
+ * return NULL on malloc error.
+ * FIXME: all createButton calls should check for error
+ */
static newtComponent createButton(int left, int row, const char * text, int compact) {
newtComponent co;
struct button * bu;
int width = wstrlen(text,-1);
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
bu = malloc(sizeof(struct button));
+ if (bu == NULL) {
+ free (co);
+ return NULL;
+ }
co->data = bu;
bu->text = strdup(text);
newtGotorc(co->top, co->left);
return co;
+
}
newtComponent newtCompactButton(int left, int row, const char * text) {
cbDraw(co);
}
+/*
+ * returns NULL on error.
+ * FIXME: Check all calls.
+ */
newtComponent newtCheckbox(int left, int top, const char * text, char defValue,
const char * seq, char * result) {
newtComponent co;
if (!seq) seq = " *";
co = malloc(sizeof(*co));
+ if (co == NULL)
+ return NULL;
cb = malloc(sizeof(struct checkbox));
+ if (cb == NULL) {
+ free(co);
+ return NULL;
+ }
co->data = cb;
cb->flags = 0;
if (result)
}
}
+/* FIXME: Check what happens on malloc failure.
+ */
static void buildFlatList(newtComponent co) {
struct CheckboxTree * ct = co->data;
int newtCheckboxTreeAddArray(newtComponent co,
const char * text, const void * data,
int flags, int * indexes) {
- struct items * curList, * newNode, * item;
+ struct items * curList, * newNode, * item = NULL;
struct items ** listPtr = NULL;
int i, index, numIndexes, width;
struct CheckboxTree * ct = co->data;
if (!ct->itemlist) {
if (numIndexes > 1) return -1;
- ct->itemlist = malloc(sizeof(*ct->itemlist));
+ ct->itemlist = malloc(sizeof(*ct->itemlist)); // FIXME: Error check?
item = ct->itemlist;
item->prev = NULL;
item->next = NULL;
} else if (!item) { /* append to end */
item = curList;
while (item->next) item = item->next;
- item->next = malloc(sizeof(*curList->prev));
+ item->next = malloc(sizeof(*curList->prev)); // FIXME Error check
item->next->prev = item;
item = item->next;
item->next = NULL;
} else {
- newNode = malloc(sizeof(*newNode));
+ newNode = malloc(sizeof(*newNode)); // FIXME Error check ?
newNode->prev = item->prev;
newNode->next = item;
struct items ** item;
int i, j;
char * spaces;
- int currRow;
+ int currRow = 0;
if (!co->isMapped) return ;
AC_INIT(newt_pr.h)
AC_CONFIG_HEADER(config.h)
+PACKAGE=newt
VERSION=$(awk '/^%define version/ {print $3}' $srcdir/newt.spec)
SONAME=0.51
+AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(SONAME)
AC_PROG_CC
#include "newt_pr.h"
#include "popt.h"
+#define MAXBUF 200
+#define MAXFORMAT 20
+
/* globals -- ick */
static int buttonHeight = 1;
static newtComponent (*makeButton)(int left, int right, const char * text) =
int allocedItems = 5;
int i, top;
int rc = DLG_OKAY;
- char buf[80], format[20];
+ char buf[MAXBUF], format[MAXFORMAT];
int maxTagWidth = 0;
int maxTextWidth = 0;
int scrollFlag;
const char * tag;
} * itemInfo = malloc(allocedItems * sizeof(*itemInfo));
+ if (itemInfo == NULL) return DLG_ERROR;
if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
listHeight = strtoul(arg, &end, 10);
if (*end) return DLG_ERROR;
if (allocedItems == numItems) {
allocedItems += 5;
itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems);
+ if (itemInfo == NULL) return DLG_ERROR;
}
itemInfo[numItems].tag = arg;
numItems++;
}
+ if (numItems == 0)
+ return DLG_ERROR;
form = newtForm(NULL, NULL, 0);
top + 1, listHeight,
NEWT_FLAG_RETURNEXIT | scrollFlag);
- sprintf(format, "%%-%ds %%s", maxTagWidth);
+ snprintf(format, MAXFORMAT, "%%-%ds %%s", maxTagWidth);
for (i = 0; i < numItems; i++) {
- sprintf(buf, format, itemInfo[i].tag, itemInfo[i].text);
+ snprintf(buf, MAXBUF, format, itemInfo[i].tag, itemInfo[i].text);
newtListboxAddEntry(listBox, buf, (void *) i);
}
} * cbInfo = malloc(allocedBoxes * sizeof(*cbInfo));
char * cbStates = malloc(allocedBoxes * sizeof(cbStates));
+ if ( (cbInfo == NULL) || (cbStates == NULL)) return DLG_ERROR;
if (!(arg = poptGetArg(optCon))) return DLG_ERROR;
listHeight = strtoul(arg, &end, 10);
if (*end) return DLG_ERROR;
allocedBoxes += 5;
cbInfo = realloc(cbInfo, sizeof(*cbInfo) * allocedBoxes);
cbStates = realloc(cbStates, sizeof(*cbStates) * allocedBoxes);
+ if ((cbInfo == NULL) || (cbStates == NULL)) return DLG_ERROR;
}
cbInfo[numBoxes].tag = arg;
subform = newtForm(sb, NULL, 0);
newtFormSetBackground(subform, NEWT_COLORSET_CHECKBOX);
- sprintf(format, "%%-%ds %%s", maxWidth);
+ snprintf(format, MAXFORMAT, "%%-%ds %%s", maxWidth);
for (i = 0; i < numBoxes; i++) {
- sprintf(buf, format, cbInfo[i].tag, cbInfo[i].text);
+ snprintf(buf, MAXBUF, format, cbInfo[i].tag, cbInfo[i].text);
if (useRadio)
cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf,
for (i = 0; i < numBoxes; i++)
if (cbInfo[i].comp == answer) {
*selections = malloc(sizeof(char *) * 2);
+ if (*selections == NULL) return DLG_ERROR;
(*selections)[0] = cbInfo[i].tag;
(*selections)[1] = NULL;
break;
}
*selections = malloc(sizeof(char *) * (numSelected + 1));
+ if (*selections == NULL) return DLG_ERROR;
numSelected = 0;
for (i = 0; i < numBoxes; i++) {
SLtt_set_cursor_visibility (cursorOn);
}
-void newtResume(void) {
+int newtResume(void) {
SLsmg_resume_smg ();
SLsmg_refresh();
- SLang_init_tty(0, 0, 0);
+ return SLang_init_tty(0, 0, 0);
}
void newtCls(void) {
int newtInit(void) {
char * MonoValue, * MonoEnv = "NEWT_MONO";
const char *lang;
+ int ret;
if ((lang = getenv("LC_ALL")) == NULL)
if ((lang = getenv("LC_CTYPE")) == NULL)
SLtt_Use_Ansi_Colors = 0;
}
- SLsmg_init_smg();
- SLang_init_tty(0, 0, 0);
+ if ((ret = SLsmg_init_smg()) < 0)
+ return ret;
+ if ((ret = SLang_init_tty(0, 0, 0)) < 0)
+ return ret;
newtSetColors(newtDefaultColorPalette);
newtCursorOff();
SLsignal_intr(SIGWINCH, handleSigwinch);
SLang_getkey_intr_hook = getkeyInterruptHook;
-
-
return 0;
}
}
}
-int newtOpenWindow(int left, int top, int width, int height,
+int newtOpenWindow(unsigned left, unsigned top, unsigned width, unsigned height,
const char * title) {
int j, row, col;
int n;
return 0;
}
-int newtCenteredWindow(int width, int height, const char * title) {
- int top, left;
+int newtCenteredWindow(unsigned width, unsigned height, const char * title) {
+ unsigned top, left;
top = (SLtt_Screen_Rows - height) / 2;
}
#endif
-void newtDelay(int usecs) {
+void newtDelay(unsigned usecs) {
fd_set set;
struct timeval tv;
void newtResizeScreen(int redraw);
void newtWaitForKey(void);
void newtClearKeyBuffer(void);
-void newtDelay(int usecs);
+void newtDelay(unsigned int usecs);
/* top, left are *not* counting the border */
-int newtOpenWindow(int left, int top, int width, int height,
- const char * title);
-int newtCenteredWindow(int width, int height, const char * title);
+int newtOpenWindow(unsigned int left,unsigned int top,
+ unsigned int width,unsigned int height,
+ const char * title);
+int newtCenteredWindow(unsigned int width,unsigned int height, const char * title);
void newtPopWindow(void);
void newtSetColors(struct newtColors colors);
void newtRefresh(void);
void newtSuspend(void);
void newtSetSuspendCallback(newtSuspendCallback cb, void * data);
void newtSetHelpCallback(newtCallback cb);
-void newtResume(void);
+int newtResume(void);
void newtPushHelpLine(const char * text);
void newtRedrawHelpLine(void);
void newtPopHelpLine(void);
#define OPT_INFOBOX 1008
static void usage(void) {
- fprintf(stderr, "whiptail: bad parameters (see man dialog(1) for details)\n");
- exit(1);
+ newtFinished();
+ fprintf(stderr, "whiptail: bad parameters (see man whiptail(1) for details)\n");
+ exit(DLG_ERROR);
}
int main(int argc, const char ** argv) {
}
static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc,
- char ** argv) {
+ const char ** argv) {
enum mode mode = MODE_NONE;
poptContext optCon;
int arg;
int rc = 0;
int flags = 0;
int defaultNo = 0;
- char * result;
- char ** selections, ** next;
+ const char * result;
+ const char ** selections, ** next;
char * title = NULL;
struct poptOption optionsTable[] = {
{ "checklist", '\0', 0, 0, OPT_CHECKLIST },
case MODE_NONE:
/* this can't happen */
+ break;
}
newtPopWindow();
int Whiptcl_Init(Tcl_Interp * interp) {
Tcl_CreateCommand(interp, "whiptcl_finish", wtFinish, NULL, NULL);
Tcl_CreateCommand(interp, "whiptcl_init", wtInit, NULL, NULL);
- Tcl_CreateCommand(interp, "whiptcl_cmd", wtCmd, NULL, NULL);
+ Tcl_CreateCommand(interp, "whiptcl_cmd", (Tcl_CmdProc *) wtCmd, NULL, NULL);
return TCL_OK;
}