]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
Various cleanups from Elliot
authorewt <ewt>
Mon, 2 Jun 1997 16:21:13 +0000 (16:21 +0000)
committerewt <ewt>
Mon, 2 Jun 1997 16:21:13 +0000 (16:21 +0000)
Makefile
entry.c
form.c
listbox.c
newt.h
newt.spec
test.c
textbox.c
whiptail.c

index bb86303e25548a3a3e31a0f4a2cfc2708c5c1dab..2f2d69754b9d0f9f350faf8542603fdb6740c991 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -66,7 +66,7 @@ shareddir:
 shared: $(LIBNEWTSH)
 
 $(LIBNEWTSH): shareddir $(SHAREDOBJS)
-       gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS)
+       gcc -shared -o $(LIBNEWTSH) -Wl,-soname,$(LIBNEWTSONAME) $(SHAREDOBJS) $(LIBS)
 
 $(SHAREDDIR)/%.o : %.c
        $(CC) $(SHCFLAGS) -c $(CFLAGS) -o $@ $<
@@ -76,6 +76,7 @@ $(SHAREDDIR)/newt.o: newt.c Makefile
 
 
 install: $(LIBNEWT)
+       [ -d $(bindir) ] || install -m 755 -d $(bindir)
        [ -d $(libdir) ] || install -m 755 -d $(libdir)
        [ -d $(includedir) ] || install -m 755 -d $(includedir)
        install -m 644 newt.h $(includedir)
diff --git a/entry.c b/entry.c
index d696967807906c863661303f52831ad75e7e46c5..a593be6a5ad52557918bf6c4a5f9e26a032e6bca 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -73,7 +73,7 @@ newtComponent newtEntry(int left, int top, char * initialValue, int width,
     en->bufUsed = 0;
     en->bufAlloced = width + 1;
 
-    if (!(en->flags & NEWT_ENTRY_DISABLED))
+    if (!(en->flags & NEWT_FLAG_DISABLED))
        co->takesFocus = 1;
     else
        co->takesFocus = 0;
@@ -103,12 +103,12 @@ static void entryDraw(newtComponent co) {
 
     if (co->top == -1) return;
 
-    if (en->flags & NEWT_ENTRY_DISABLED) 
+    if (en->flags & NEWT_FLAG_DISABLED) 
        SLsmg_set_color(NEWT_COLORSET_DISENTRY);
     else
        SLsmg_set_color(NEWT_COLORSET_ENTRY);
  
-    if (en->flags & NEWT_ENTRY_HIDDEN) {
+    if (en->flags & NEWT_FLAG_HIDDEN) {
        newtGotorc(co->top, co->left);
        for (i = 0; i < co->width; i++)
            SLsmg_write_char('_');
@@ -141,7 +141,7 @@ static void entryDraw(newtComponent co) {
        SLsmg_write_nstring(chptr, co->width);
     }
 
-    if (en->flags & NEWT_ENTRY_HIDDEN)
+    if (en->flags & NEWT_FLAG_HIDDEN)
        newtGotorc(co->top, co->left);
     else
        newtGotorc(co->top, co->left + (en->cursorPosition - en->firstChar));
@@ -153,7 +153,7 @@ void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense) {
 
     en->flags = newtSetFlags(en->flags, flags, sense);
 
-    if (!(en->flags & NEWT_ENTRY_DISABLED))
+    if (!(en->flags & NEWT_FLAG_DISABLED))
        co->takesFocus = 1;
     else
        co->takesFocus = 0;
@@ -180,7 +180,7 @@ static struct eventResult entryEvent(newtComponent co,
        switch (ev.event) {
          case EV_FOCUS:
            /*SLtt_set_cursor_visibility(0);*/
-           if (en->flags & NEWT_ENTRY_HIDDEN)
+           if (en->flags & NEWT_FLAG_HIDDEN)
                newtGotorc(co->top, co->left);
            else
                newtGotorc(co->top, co->left + 
@@ -213,7 +213,7 @@ static struct eventResult entryHandleKey(newtComponent co, int key) {
     er.result = ER_SWALLOWED;
     switch (key) {
       case '\r':                               /* Return */
-       if (en->flags & NEWT_ENTRY_RETURNEXIT) {
+       if (en->flags & NEWT_FLAG_RETURNEXIT) {
            er.result = ER_EXITFORM;
        } else {
            er.result = ER_NEXTCOMP;
@@ -277,7 +277,7 @@ static struct eventResult entryHandleKey(newtComponent co, int key) {
 
       default:
        if ((key >= 0x20 && key <= 0x7e) || (key >= 0xa0 && key <= 0xff)) {
-           if (!(en->flags & NEWT_ENTRY_SCROLL) && en->bufUsed == co->width) {
+           if (!(en->flags & NEWT_FLAG_SCROLL) && en->bufUsed == co->width) {
                SLtt_beep();
                break;
            } 
diff --git a/form.c b/form.c
index 0b1fddea005f2d346d889c77752413e7b906861b..06b1ca2da21cca61328ce6fb195b62fad2f57789 100644 (file)
--- a/form.c
+++ b/form.c
@@ -84,7 +84,7 @@ newtComponent newtForm(newtComponent vertBar, char * help, int flags) {
     form->background = COLORSET_WINDOW;
     form->hotKeys = malloc(sizeof(int));
     form->numHotKeys = 0;
-    if (!(form->flags & NEWT_FORM_NOF12)) {
+    if (!(form->flags & NEWT_FLAG_NOF12)) {
        newtFormAddHotKey(co, NEWT_KEY_F12);
     }
 
index 7383b046765127eee7d9b44a147db1f153a43a94..17276e0040ae63be59f71ea6d28aa465aa52993e 100644 (file)
--- a/listbox.c
+++ b/listbox.c
@@ -4,6 +4,7 @@
    Copyright Elliot Lee 1996 */
 
 #include <slang/slang.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -29,7 +30,7 @@ struct listbox {
     struct items *boxItems;
     int grow;
     int flags; /* flags for this listbox, right now just
-                 NEWT_LISTBOX_RETURNEXIT */
+                 NEWT_FLAG_RETURNEXIT */
 };
 
 static void listboxDraw(newtComponent co);
@@ -59,7 +60,7 @@ newtComponent newtListbox(int left, int top, int height, int flags) {
     li->currItem = 0;
     li->isActive = 0;
     li->startShowItem = 0;
-    li->flags = flags & (NEWT_LISTBOX_RETURNEXIT|NEWT_FLAG_DOBORDER);
+    li->flags = flags & (NEWT_FLAG_RETURNEXIT|NEWT_FLAG_DOBORDER);
 
     if (height) {
        li->grow = 0;
@@ -238,8 +239,8 @@ int newtListboxDeleteEntry(newtComponent co, int num) {
     if(num > li->numItems)
        num = li->numItems;
 
-    if (!li->boxItems)
-       return -1;
+    if (li->boxItems == NULL || li->numItems <= 0)
+       return 0;
 
     if (num <= 1) { 
        item = li->boxItems;
@@ -247,7 +248,7 @@ int newtListboxDeleteEntry(newtComponent co, int num) {
 
        /* Fix things up for the width-finding loop near the bottom */
        item2 = li->boxItems;
-       widest = strlen(item2->key);
+       widest = strlen(item2?item2->key:"");
     } else {
        for(i = 0, item = li->boxItems; item != NULL && i < num - 1;
            i++, item = item->next) {
@@ -265,7 +266,7 @@ int newtListboxDeleteEntry(newtComponent co, int num) {
     li->numItems--;
     if(li->currItem >= num)
        li->currItem--;
-    for (item = item2->next; item != NULL; item = item->next)
+    for (item = item2?item2->next:item2; item != NULL; item = item->next)
        if((t = strlen(item->key)) > widest) widest = t;
 
     /* Adjust the listbox width */
@@ -363,7 +364,7 @@ static struct eventResult listboxEvent(newtComponent co, struct event ev) {
 
        switch(ev.u.key) {
          case NEWT_KEY_ENTER:
-           if(li-> flags & NEWT_LISTBOX_RETURNEXIT)
+           if(li-> flags & NEWT_FLAG_RETURNEXIT)
                er.result = ER_EXITFORM;
            break;
 
diff --git a/newt.h b/newt.h
index f78a6c901c9170a86db2402a30b56d0cbde04b8f..d8c414a9c613eb05001f2b1905af672aa084440a 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -58,6 +58,8 @@ enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET };
 #define NEWT_FLAG_DISABLED     (1 << 3)
 #define NEWT_FLAG_NOSCROLL     (1 << 4)        /* for listboxes */
 #define NEWT_FLAG_DOBORDER     (1 << 5)
+#define NEWT_FLAG_WRAP         (1 << 6)
+#define NEWT_FLAG_NOF12                (1 << 7)
 
 /* Backwards compatibility */
 #define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
@@ -66,6 +68,10 @@ enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET };
 #define NEWT_ENTRY_RETURNEXIT  NEWT_FLAG_RETURNEXIT
 #define NEWT_ENTRY_DISABLED    NEWT_FLAG_DISABLED
 
+#define NEWT_TEXTBOX_WRAP      NEWT_FLAG_WRAP
+#define NEWT_TEXTBOX_SCROLL    NEWT_FLAG_SCROLL
+#define NEWT_FORM_NOF12                NEWT_FLAG_NOF12
+
 typedef struct newtComponent_struct * newtComponent;
 
 extern struct newtColors newtDefaultColorPalette;
@@ -125,16 +131,11 @@ int newtListboxInsertEntry(newtComponent co, char * text, void * data, int num);
 int newtListboxDeleteEntry(newtComponent co, int num);
 void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
 
-#define NEWT_TEXTBOX_WRAP      (1 << 0)
-#define NEWT_TEXTBOX_SCROLL    (1 << 1)
-
 newtComponent newtTextbox(int left, int top, int with, int height, int flags);
 void newtTextboxSetText(newtComponent co, const char * text);
 void newtTextboxSetHeight(newtComponent co, int height);
 int newtTextboxGetNumLines(newtComponent co);
 
-#define NEWT_FORM_NOF12                (1 << 0)
-
 struct newtExitStruct {
     enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT } reason;
     union {
index d4180532140382a18fd4e89ce57adb122b977fe5..75179900dd7cf0213433a9955af34d3dc7e617f7 100644 (file)
--- a/newt.spec
+++ b/newt.spec
@@ -45,6 +45,10 @@ make install-sh
 
 %changelog
 
+* Tue May 28 1997 Elliot Lee <sopwith@redhat.com> 0.8-2
+- Touchups on Makefile
+- Cleaned up NEWT_FLAGS_*
+
 * Tue Mar 18 1997 Erik Troan <ewt@redhat.com>
 
 - Cleaned up listbox
diff --git a/test.c b/test.c
index da028d011296d5080a08eb18f862f7f140c4babf..66b4ec7a3058b79690ef4b94fb72541f4150d57f 100644 (file)
--- a/test.c
+++ b/test.c
@@ -14,9 +14,9 @@ void disableCallback(newtComponent co, void * data) {
     struct callbackInfo * cbi = data;
 
     if (*cbi->state == ' ') {
-       newtEntrySetFlags(cbi->en, NEWT_ENTRY_DISABLED, NEWT_FLAGS_RESET);
+       newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
     } else {
-       newtEntrySetFlags(cbi->en, NEWT_ENTRY_DISABLED, NEWT_FLAGS_SET);
+       newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
     }
 
     newtRefresh();
@@ -72,8 +72,8 @@ void main(void) {
     l2 = newtLabel(3, 7, "Scrolls:");
     l3 = newtLabel(3, 8, "Hidden:");
     e1 = newtEntry(12, 6, "", 20, &scaleVal, 0);
-    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_ENTRY_SCROLL);
-    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_ENTRY_HIDDEN);
+    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);
+    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN);
 
     cbis[0].state = &results[0];
     cbis[0].en = e1;
@@ -98,7 +98,7 @@ void main(void) {
     newtListboxAddEntry(lb, "Ninth", NULL);
     newtListboxAddEntry(lb, "Tenth", NULL);
 
-    t = newtTextbox(45, 10, 17, 5, NEWT_TEXTBOX_WRAP);
+    t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
     newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");
 
     newtFormAddComponents(f, lb, t, NULL);
index 1badddb67246fbf7dbacfb262aaf192460aab05e..3238c25ce823d5922a3c86b27892a3b9d8c2c11a 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -53,13 +53,13 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags) {
     co->left = left;
     co->takesFocus = 0;
 
-    tb->doWrap = flags & NEWT_TEXTBOX_WRAP;
+    tb->doWrap = flags & NEWT_FLAG_WRAP;
     tb->numLines = 0;
     tb->linesAlloced = 0;
     tb->lines = NULL;
     tb->topLine = 0;
 
-    if (flags & NEWT_TEXTBOX_SCROLL) {
+    if (flags & NEWT_FLAG_SCROLL) {
        co->width = width - 2;
        tb->sb = newtVerticalScrollbar(co->left + co->width + 1, co->top, 
                           co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX);
index c69e20c77c95f227f4920e8e9687b539242f0307..beff5ad5b01db3d19fdfa75e92224eb37d473d50 100644 (file)
@@ -57,7 +57,7 @@ void addButtons(int height, int width, newtComponent form,
 newtComponent textbox(int maxHeight, int width, char * text, int flags, 
                        int * height) {
     newtComponent tb;
-    int sFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_TEXTBOX_SCROLL : 0;
+    int sFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0;
     int i;
     char * buf, * src, * dst;
 
@@ -72,7 +72,7 @@ newtComponent textbox(int maxHeight, int width, char * text, int flags,
     }
     *dst++ = '\0';
 
-    tb = newtTextbox(1, 0, width, maxHeight, NEWT_TEXTBOX_WRAP | sFlag);
+    tb = newtTextbox(1, 0, width, maxHeight, NEWT_FLAG_WRAP | sFlag);
     newtTextboxSetText(tb, buf);
 
     i = newtTextboxGetNumLines(tb);
@@ -383,12 +383,12 @@ int checkList(char * text, int height, int width, poptContext optCon,
 int messageBox(char * text, int height, int width, int type, int flags) {
     newtComponent form, yes, tb, answer;
     newtComponent no = NULL;
-    int tFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_TEXTBOX_SCROLL : 0;
+    int tFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0;
 
     form = newtForm(NULL, NULL, 0);
 
     tb = newtTextbox(1, 1, width - 2, height - 3 - buttonHeight, 
-                       NEWT_TEXTBOX_WRAP | tFlag);
+                       NEWT_FLAG_WRAP | tFlag);
     newtTextboxSetText(tb, text);
 
     newtFormAddComponent(form, tb);