From: havill Date: Wed, 7 Apr 2004 19:44:43 +0000 (+0000) Subject: merged in and munged patches from #117464 X-Git-Tag: r0-52-0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3ddfdd7f3da291db5babe48dde1e50a57de7df6;p=thirdparty%2Fnewt.git merged in and munged patches from #117464 --- diff --git a/Makefile.in b/Makefile.in index c815151..4583d72 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,12 +1,9 @@ -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)) @@ -52,35 +49,40 @@ endif 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 $@ $^ @@ -103,7 +105,7 @@ $(SHAREDDIR): 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 $@ $< diff --git a/button.c b/button.c index c933aad..467efdb 100644 --- a/button.c +++ b/button.c @@ -27,13 +27,23 @@ static struct componentOps buttonOps = { 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); @@ -56,6 +66,7 @@ static newtComponent createButton(int left, int row, const char * text, int comp newtGotorc(co->top, co->left); return co; + } newtComponent newtCompactButton(int left, int row, const char * text) { diff --git a/checkbox.c b/checkbox.c index 780abc1..c753374 100644 --- a/checkbox.c +++ b/checkbox.c @@ -89,6 +89,10 @@ void newtCheckboxSetValue(newtComponent co, char value) { 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; @@ -97,7 +101,13 @@ newtComponent newtCheckbox(int left, int top, const char * text, char defValue, 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) diff --git a/checkboxtree.c b/checkboxtree.c index 7d9731d..815cc52 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -81,6 +81,8 @@ static void doBuildFlatList(struct CheckboxTree * ct, struct items * item) { } } +/* FIXME: Check what happens on malloc failure. + */ static void buildFlatList(newtComponent co) { struct CheckboxTree * ct = co->data; @@ -167,7 +169,7 @@ int * newtCheckboxTreeFindItem(newtComponent co, void * 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; @@ -178,7 +180,7 @@ int newtCheckboxTreeAddArray(newtComponent co, 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; @@ -215,12 +217,12 @@ int newtCheckboxTreeAddArray(newtComponent co, } 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; @@ -441,7 +443,7 @@ static void ctDraw(newtComponent co) { struct items ** item; int i, j; char * spaces; - int currRow; + int currRow = 0; if (!co->isMapped) return ; diff --git a/configure.in b/configure.in index 468116c..42861ca 100644 --- a/configure.in +++ b/configure.in @@ -3,8 +3,10 @@ dnl Process this file with autoconf to produce a configure script. 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 diff --git a/dialogboxes.c b/dialogboxes.c index 736097d..5e58a1a 100644 --- a/dialogboxes.c +++ b/dialogboxes.c @@ -11,6 +11,9 @@ #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) = @@ -167,7 +170,7 @@ int listBox(const char * text, int height, int width, poptContext optCon, 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; @@ -176,6 +179,7 @@ int listBox(const char * text, int height, int width, poptContext optCon, 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; @@ -184,6 +188,7 @@ int listBox(const char * text, int height, int width, poptContext optCon, if (allocedItems == numItems) { allocedItems += 5; itemInfo = realloc(itemInfo, sizeof(*itemInfo) * allocedItems); + if (itemInfo == NULL) return DLG_ERROR; } itemInfo[numItems].tag = arg; @@ -201,6 +206,8 @@ int listBox(const char * text, int height, int width, poptContext optCon, numItems++; } + if (numItems == 0) + return DLG_ERROR; form = newtForm(NULL, NULL, 0); @@ -220,9 +227,9 @@ int listBox(const char * text, int height, int width, poptContext optCon, 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); } @@ -262,6 +269,7 @@ int checkList(const char * text, int height, int width, poptContext optCon, } * 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; @@ -271,6 +279,7 @@ int checkList(const char * text, int height, int width, poptContext optCon, 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; @@ -309,9 +318,9 @@ int checkList(const char * text, int height, int width, poptContext optCon, 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, @@ -340,6 +349,7 @@ int checkList(const char * text, int height, int width, poptContext optCon, 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; @@ -351,6 +361,7 @@ int checkList(const char * text, int height, int width, poptContext optCon, } *selections = malloc(sizeof(char *) * (numSelected + 1)); + if (*selections == NULL) return DLG_ERROR; numSelected = 0; for (i = 0; i < numBoxes; i++) { diff --git a/newt.c b/newt.c index 1fe3fc7..53b7872 100644 --- a/newt.c +++ b/newt.c @@ -197,10 +197,10 @@ void newtSuspend(void) { 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) { @@ -223,6 +223,7 @@ void newtResizeScreen(int redraw) { 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) @@ -243,8 +244,10 @@ int newtInit(void) { 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(); @@ -257,8 +260,6 @@ int newtInit(void) { SLsignal_intr(SIGWINCH, handleSigwinch); SLang_getkey_intr_hook = getkeyInterruptHook; - - return 0; } @@ -432,7 +433,7 @@ void newtClearKeyBuffer(void) { } } -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; @@ -510,8 +511,8 @@ int newtOpenWindow(int left, int top, int width, int height, 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; @@ -628,7 +629,7 @@ static void initKeymap(void) { } #endif -void newtDelay(int usecs) { +void newtDelay(unsigned usecs) { fd_set set; struct timeval tv; diff --git a/newt.h b/newt.h index f3f8bb2..b179da1 100644 --- a/newt.h +++ b/newt.h @@ -113,18 +113,19 @@ void newtCls(void); 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); diff --git a/whiptail.c b/whiptail.c index 4aa41b0..f658a7b 100644 --- a/whiptail.c +++ b/whiptail.c @@ -24,8 +24,9 @@ enum mode { MODE_NONE, MODE_INFOBOX, MODE_MSGBOX, MODE_YESNO, MODE_CHECKLIST, #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) { diff --git a/whiptcl.c b/whiptcl.c index f137d79..6e496f8 100644 --- a/whiptcl.c +++ b/whiptcl.c @@ -53,7 +53,7 @@ static int wtInit(ClientData clientData, Tcl_Interp * interp, int argc, } static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc, - char ** argv) { + const char ** argv) { enum mode mode = MODE_NONE; poptContext optCon; int arg; @@ -69,8 +69,8 @@ static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc, 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 }, @@ -229,6 +229,7 @@ static int wtCmd(ClientData clientData, Tcl_Interp * interp, int argc, case MODE_NONE: /* this can't happen */ + break; } newtPopWindow(); @@ -290,7 +291,7 @@ static char * setFullButtons(ClientData data, Tcl_Interp * interp, 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; }