]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
merged in and munged patches from #117464
authorhavill <havill>
Wed, 7 Apr 2004 19:44:43 +0000 (19:44 +0000)
committerhavill <havill>
Wed, 7 Apr 2004 19:44:43 +0000 (19:44 +0000)
Makefile.in
button.c
checkbox.c
checkboxtree.c
configure.in
dialogboxes.c
newt.c
newt.h
whiptail.c
whiptcl.c

index c81515189ef725f5d7ee5e90531459947b6685bf..4583d72b7d19c06045fe2d0decb40fe1a92f3918 100644 (file)
@@ -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 $@ $<
index c933aad507843fafe8aab82f175a6b979c36956e..467efdb3534e76565dd399f72f72ba94e0163fec 100644 (file)
--- 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) {
index 780abc14044093a3123202b09fe6149ccee794d4..c753374bb701a02fd4d5360913aff0a74b031f34 100644 (file)
@@ -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)
index 7d9731df0fe8c7b62151771c067a13fb7335b720..815cc52e66c75f094d155ad76b76631824a47463 100644 (file)
@@ -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 ;
 
index 468116c10ca00d9805995d7a719df9e8ef5e00c4..42861ca333b1c0e405daed8ff92fc929c760880e 100644 (file)
@@ -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
index 736097d4d6b6ed47447d4da90276c06d701038e7..5e58a1aab222af2a954f47d83cd0f5217318a6a2 100644 (file)
@@ -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 1fe3fc77f799a03817e92719566fb8e2c69ea67f..53b78721d028643770e6f311a89e5ea7dd2a7218 100644 (file)
--- 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 f3f8bb298e84da1d487d62c246eb1ee9fea7c4bd..b179da105f556307c03f0030c3f387f28e9a2937 100644 (file)
--- 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);
index 4aa41b02c026344872014795374bfe8d3f3b6e03..f658a7b45c031fe18f5cf55c5e4af320663501ee 100644 (file)
@@ -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) {
index f137d791c073dbb687b8adb19cad8facff4a037f..6e496f84c785803dadff8570c2834de3cef13b3d 100644 (file)
--- 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;
 }