From 4a93351da677b7bd0caef373d5a19a259c33e727 Mon Sep 17 00:00:00 2001 From: ewt Date: Mon, 2 Jun 1997 16:21:13 +0000 Subject: [PATCH] Various cleanups from Elliot --- Makefile | 3 ++- entry.c | 16 ++++++++-------- form.c | 2 +- listbox.c | 15 ++++++++------- newt.h | 11 ++++++----- newt.spec | 4 ++++ test.c | 10 +++++----- textbox.c | 4 ++-- whiptail.c | 8 ++++---- 9 files changed, 40 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index bb86303..2f2d697 100644 --- 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 d696967..a593be6 100644 --- 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 0b1fdde..06b1ca2 100644 --- 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); } diff --git a/listbox.c b/listbox.c index 7383b04..17276e0 100644 --- a/listbox.c +++ b/listbox.c @@ -4,6 +4,7 @@ Copyright Elliot Lee 1996 */ #include +#include #include #include @@ -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 f78a6c9..d8c414a 100644 --- 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 { diff --git a/newt.spec b/newt.spec index d418053..7517990 100644 --- a/newt.spec +++ b/newt.spec @@ -45,6 +45,10 @@ make install-sh %changelog +* Tue May 28 1997 Elliot Lee 0.8-2 +- Touchups on Makefile +- Cleaned up NEWT_FLAGS_* + * Tue Mar 18 1997 Erik Troan - Cleaned up listbox diff --git a/test.c b/test.c index da028d0..66b4ec7 100644 --- 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); diff --git a/textbox.c b/textbox.c index 1badddb..3238c25 100644 --- 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); diff --git a/whiptail.c b/whiptail.c index c69e20c..beff5ad 100644 --- a/whiptail.c +++ b/whiptail.c @@ -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); -- 2.47.2