From d4109c3732affcc824c63efdf581e6df88dd181c Mon Sep 17 00:00:00 2001 From: sopwith Date: Mon, 8 Sep 1997 20:00:11 +0000 Subject: [PATCH] Various 'const' casting mods from Bruce Guenter --- button.c | 6 +++--- checkbox.c | 18 +++++++++--------- dialogboxes.c | 2 +- entry.c | 4 ++-- form.c | 4 ++-- label.c | 4 ++-- listbox.c | 20 +++++++++++--------- newt.c | 14 +++++++------- newt.h | 40 ++++++++++++++++++++-------------------- 9 files changed, 57 insertions(+), 55 deletions(-) diff --git a/button.c b/button.c index 42f5c0f..ee3543d 100644 --- a/button.c +++ b/button.c @@ -25,7 +25,7 @@ static struct componentOps buttonOps = { buttonDestroy, } ; -static newtComponent createButton(int left, int row, char * text, int compact) { +static newtComponent createButton(int left, int row, const char * text, int compact) { newtComponent co; struct button * bu; @@ -55,11 +55,11 @@ static newtComponent createButton(int left, int row, char * text, int compact) { return co; } -newtComponent newtCompactButton(int left, int row, char * text) { +newtComponent newtCompactButton(int left, int row, const char * text) { return createButton(left, row, text, 1); } -newtComponent newtButton(int left, int row, char * text) { +newtComponent newtButton(int left, int row, const char * text) { return createButton(left, row, text, 0); } diff --git a/checkbox.c b/checkbox.c index 2f83298..c4f24b5 100644 --- a/checkbox.c +++ b/checkbox.c @@ -15,7 +15,7 @@ struct checkbox { enum type type; char value; int active, inactive; - void * data; + const void * data; int flags; }; @@ -32,8 +32,8 @@ static struct componentOps cbOps = { cbDestroy, } ; -newtComponent newtListitem(int left, int top, char * text, int isDefault, - newtComponent prevItem, void * data, int flags) { +newtComponent newtListitem(int left, int top, const char * text, int isDefault, + newtComponent prevItem, const void * data, int flags) { newtComponent co; struct checkbox * li; @@ -51,10 +51,10 @@ newtComponent newtListitem(int left, int top, char * text, int isDefault, void * newtListitemGetData(newtComponent co) { struct checkbox * rb = co->data; - return rb->data; + return (void *)rb->data; } -void newtListitemSet(newtComponent co, char * text) { +void newtListitemSet(newtComponent co, const char * text) { struct checkbox * li = co->data; free(li->text); @@ -64,7 +64,7 @@ void newtListitemSet(newtComponent co, char * text) { co->width = strlen(text) + 4; } -newtComponent newtRadiobutton(int left, int top, char * text, int isDefault, +newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault, newtComponent prevButton) { newtComponent co; newtComponent curr; @@ -104,8 +104,8 @@ newtComponent newtRadioGetCurrent(newtComponent setMember) { return setMember; } -newtComponent newtCheckbox(int left, int top, char * text, char defValue, - char * seq, char * result) { +newtComponent newtCheckbox(int left, int top, const char * text, char defValue, + const char * seq, char * result) { newtComponent co; struct checkbox * cb; @@ -191,7 +191,7 @@ static void cbDestroy(newtComponent co) { struct eventResult cbEvent(newtComponent co, struct event ev) { struct checkbox * cb = co->data; struct eventResult er; - char * cur; + const char * cur; if (ev.when == EV_NORMAL) { switch (ev.event) { diff --git a/dialogboxes.c b/dialogboxes.c index a240776..1fadb71 100644 --- a/dialogboxes.c +++ b/dialogboxes.c @@ -12,7 +12,7 @@ /* globals -- ick */ int buttonHeight = 1; -newtComponent (*makeButton)(int left, int right, char * text) = +newtComponent (*makeButton)(int left, int right, const char * text) = newtCompactButton; static void addButtons(int height, int width, newtComponent form, diff --git a/entry.c b/entry.c index 4549f59..005f9a5 100644 --- a/entry.c +++ b/entry.c @@ -29,7 +29,7 @@ static struct componentOps entryOps = { entryDestroy, } ; -void newtEntrySet(newtComponent co, char * value, int cursorAtEnd) { +void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd) { struct entry * en = co->data; if ((strlen(value) + 1) > (unsigned int)en->bufAlloced) { @@ -50,7 +50,7 @@ void newtEntrySet(newtComponent co, char * value, int cursorAtEnd) { entryDraw(co); } ; -newtComponent newtEntry(int left, int top, char * initialValue, int width, +newtComponent newtEntry(int left, int top, const char * initialValue, int width, char ** resultPtr, int flags) { newtComponent co; struct entry * en; diff --git a/form.c b/form.c index 06b1ca2..d661a00 100644 --- a/form.c +++ b/form.c @@ -28,7 +28,7 @@ struct form { int flags; int vertOffset; newtComponent vertBar, exitComp; - char * help; + const char * help; int numRows; int * hotKeys; int numHotKeys; @@ -56,7 +56,7 @@ static inline int componentFits(newtComponent co, int compNum) { return 1; } -newtComponent newtForm(newtComponent vertBar, char * help, int flags) { +newtComponent newtForm(newtComponent vertBar, const char * help, int flags) { newtComponent co; struct form * form; diff --git a/label.c b/label.c index d882b1d..2cc4348 100644 --- a/label.c +++ b/label.c @@ -19,7 +19,7 @@ static struct componentOps labelOps = { labelDestroy, } ; -newtComponent newtLabel(int left, int top, char * text) { +newtComponent newtLabel(int left, int top, const char * text) { newtComponent co; struct label * la; @@ -41,7 +41,7 @@ newtComponent newtLabel(int left, int top, char * text) { return co; } -void newtLabelSetText(newtComponent co, char * text) { +void newtLabelSetText(newtComponent co, const char * text) { int newLength; struct label * la = co->data; diff --git a/listbox.c b/listbox.c index 32d288f..1ba443f 100644 --- a/listbox.c +++ b/listbox.c @@ -14,7 +14,8 @@ /* Linked list of items in the listbox */ struct items { - void *key, *data; + void *key; + const void *data; unsigned char isSelected; struct items *next; }; @@ -141,7 +142,7 @@ void * newtListboxGetCurrent(newtComponent co) { i++, item = item->next); if (item) - return item->data; + return (void *)item->data; else return NULL; } @@ -202,12 +203,12 @@ void ** newtListboxGetSelection(newtComponent co, int *numitems) for(i = 0, item = li->boxItems; item != NULL; item = item->next) if(item->isSelected) - retval[i++] = item->data; + retval[i++] = (void *)item->data; *numitems = li->numSelected; return retval; } -void newtListboxSetText(newtComponent co, int num, char * text) { +void newtListboxSetText(newtComponent co, int num, const char * text) { struct listbox * li = co->data; int i; struct items *item; @@ -232,7 +233,7 @@ void newtListboxSetText(newtComponent co, int num, char * text) { listboxDraw(co); } -void newtListboxSetEntry(newtComponent co, int num, char * text) { +void newtListboxSetEntry(newtComponent co, int num, const char * text) { newtListboxSetText(co, num, text); } @@ -247,7 +248,8 @@ void newtListboxSetData(newtComponent co, int num, void * data) { item->data = data; } -int newtListboxAddEntry(newtComponent co, char * text, void * data) { +int newtListboxAddEntry(newtComponent co, const char * text, + const void * data) { struct listbox * li = co->data; struct items *item; @@ -279,8 +281,8 @@ int newtListboxAddEntry(newtComponent co, char * text, void * data) { } -int newtListboxInsertEntry(newtComponent co, char * text, void * data, - int num) { +int newtListboxInsertEntry(newtComponent co, const char * text, + const void * data, int num) { struct listbox * li = co->data; struct items *item, *t; int i; @@ -414,7 +416,7 @@ void newtListboxGetEntry(newtComponent co, int num, char **text, void **data) { if (text) *text = item->key; if (data) - *data = item->data; + *data = (void *)item->data; } } diff --git a/newt.c b/newt.c index de28b46..cb5a3b6 100644 --- a/newt.c +++ b/newt.c @@ -31,7 +31,7 @@ static char ** currentHelpline = NULL; static int cursorRow, cursorCol; -static char * defaultHelpLine = +static const char * defaultHelpLine = " / between elements | selects | next screen" ; @@ -105,7 +105,7 @@ static struct keymap keymap[] = { }; static char keyPrefix = '\033'; -static char * version = "Newt windowing library version " VERSION +static const char * version = "Newt windowing library version " VERSION " - (C) 1996 Red Hat Software. " "Redistributable under the term of the Library " "GNU Public License. " @@ -310,7 +310,7 @@ void newtClearKeyBuffer(void) { } int newtOpenWindow(int left, int top, int width, int height, - char * title) { + const char * title) { int j, row, col; int n; int i; @@ -353,7 +353,7 @@ int newtOpenWindow(int left, int top, int width, int height, SLsmg_set_char_set(0); SLsmg_write_char(' '); SLsmg_set_color(NEWT_COLORSET_TITLE); - SLsmg_write_string(currentWindow->title); + SLsmg_write_string((char *)currentWindow->title); SLsmg_set_color(NEWT_COLORSET_BORDER); SLsmg_write_char(' '); SLsmg_set_char_set(1); @@ -501,7 +501,7 @@ void newtRedrawHelpLine(void) { SLsmg_write_string(buf); } -void newtPushHelpLine(char * text) { +void newtPushHelpLine(const char * text) { if (!text) text = defaultHelpLine; @@ -527,7 +527,7 @@ void newtPopHelpLine(void) { newtRedrawHelpLine(); } -void newtDrawRootText(int row, int col, char * text) { +void newtDrawRootText(int row, int col, const char * text) { SLsmg_set_color(NEWT_COLORSET_ROOTTEXT); if (col < 0) { @@ -539,7 +539,7 @@ void newtDrawRootText(int row, int col, char * text) { } SLsmg_gotorc(row, col); - SLsmg_write_string(text); + SLsmg_write_string((char *)text); } int newtSetFlags(int oldFlags, int newFlags, enum newtFlagsSense sense) { diff --git a/newt.h b/newt.h index 7e56cc2..efc3cb9 100644 --- a/newt.h +++ b/newt.h @@ -93,35 +93,35 @@ void newtClearKeyBuffer(void); void newtDelay(int usecs); /* top, left are *not* counting the border */ int newtOpenWindow(int left, int top, int width, int height, - char * title); + const char * title); void newtPopWindow(void); void newtSetColors(struct newtColors colors); void newtRefresh(void); void newtSuspend(void); void newtSetSuspendCallback(newtSuspendCallback cb); void newtResume(void); -void newtPushHelpLine(char * text); +void newtPushHelpLine(const char * text); void newtRedrawHelpLine(void); void newtPopHelpLine(void); -void newtDrawRootText(int row, int col, char * text); +void newtDrawRootText(int row, int col, const char * text); void newtBell(void); /* Components */ -newtComponent newtCompactButton(int left, int top, char * text); -newtComponent newtButton(int left, int top, char * text); -newtComponent newtCheckbox(int left, int top, char * text, char defValue, - char * seq, char * result); -newtComponent newtRadiobutton(int left, int top, char * text, int isDefault, +newtComponent newtCompactButton(int left, int top, const char * text); +newtComponent newtButton(int left, int top, const char * text); +newtComponent newtCheckbox(int left, int top, const char * text, char defValue, + const char * seq, char * result); +newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault, newtComponent prevButton); newtComponent newtRadioGetCurrent(newtComponent setMember); -newtComponent newtListitem(int left, int top, char * text, int isDefault, - newtComponent prevItem, void * data, int flags); -void newtListitemSet(newtComponent co, char * text); +newtComponent newtListitem(int left, int top, const char * text, int isDefault, + newtComponent prevItem, const void * data, int flags); +void newtListitemSet(newtComponent co, const char * text); void * newtListitemGetData(newtComponent co); -newtComponent newtLabel(int left, int top, char * text); -void newtLabelSetText(newtComponent co, char * text); +newtComponent newtLabel(int left, int top, const char * text); +void newtLabelSetText(newtComponent co, const char * text); newtComponent newtVerticalScrollbar(int left, int top, int height, int normalColorset, int thumbColorset); void newtScrollbarSet(newtComponent co, int where, int total); @@ -129,13 +129,13 @@ void newtScrollbarSet(newtComponent co, int where, int total); newtComponent newtListbox(int left, int top, int height, int flags); void * newtListboxGetCurrent(newtComponent co); void newtListboxSetCurrent(newtComponent co, int num); -void newtListboxSetText(newtComponent co, int num, char * text); -void newtListboxSetEntry(newtComponent co, int num, char * text); +void newtListboxSetText(newtComponent co, int num, const char * text); +void newtListboxSetEntry(newtComponent co, int num, const char * text); void newtListboxSetWidth(newtComponent co, int width); /* return the data passed to AddEntry */ void newtListboxSetData(newtComponent co, int num, void * data); -int newtListboxAddEntry(newtComponent co, char * text, void * data); -int newtListboxInsertEntry(newtComponent co, char * text, void * data, int num); +int newtListboxAddEntry(newtComponent co, const char * text, const void * data); +int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, int num); int newtListboxDeleteEntry(newtComponent co, int num); void newtListboxClear(newtComponent co); /* removes all entries from listbox */ void newtListboxGetEntry(newtComponent co, int num, char **text, void **data); @@ -159,7 +159,7 @@ struct newtExitStruct { } u; } ; -newtComponent newtForm(newtComponent vertBar, char * help, int flags); +newtComponent newtForm(newtComponent vertBar, const char * help, int flags); newtComponent newtFormGetCurrent(newtComponent co); void newtFormSetBackground(newtComponent co, int color); void newtFormSetCurrent(newtComponent co, newtComponent subco); @@ -172,9 +172,9 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es); void newtDrawForm(newtComponent form); void newtFormAddHotKey(newtComponent co, int key); -newtComponent newtEntry(int left, int top, char * initialValue, int width, +newtComponent newtEntry(int left, int top, const char * initialValue, int width, char ** resultPtr, int flags); -void newtEntrySet(newtComponent co, char * value, int cursorAtEnd); +void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd); void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense); newtComponent newtScale(int left, int top, int width, long long fullValue); -- 2.47.2