From 75a0beffeb8bac041abb88360ccfb613bbb501a6 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Thu, 9 May 2013 17:34:06 +0200 Subject: [PATCH] WINGs: Added 'const' attribute to functions in dragdestination, wtext This makes both the API and local function const-correct on their input parameters. --- WINGs/WINGs/WINGs.h | 13 +++++++------ WINGs/dragdestination.c | 2 +- WINGs/wtext.c | 34 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 72e6ac80..ab5b274c 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -1607,9 +1607,9 @@ void WMSetTextBackgroundColor(WMText *tPtr, WMColor *color); void WMSetTextBackgroundPixmap(WMText *tPtr, WMPixmap *pixmap); -void WMPrependTextStream(WMText *tPtr, char *text); +void WMPrependTextStream(WMText *tPtr, const char *text); -void WMAppendTextStream(WMText *tPtr, char *text); +void WMAppendTextStream(WMText *tPtr, const char *text); #define WMClearText(tPtr) WMAppendTextStream \ ((tPtr), (NULL)) @@ -1640,23 +1640,24 @@ int WMGetTextSelectionUnderlined(WMText *tPtr); void WMSetTextAlignment(WMText *tPtr, WMAlignment alignment); -Bool WMFindInTextStream(WMText *tPtr, char *needle, Bool direction, +Bool WMFindInTextStream(WMText *tPtr, const char *needle, Bool direction, Bool caseSensitive); +/* Warning: replacement can be modified by the function */ Bool WMReplaceTextSelection(WMText *tPtr, char *replacement); /* parser related stuff... use only if implementing a new parser */ -void* WMCreateTextBlockWithObject(WMText *tPtr, WMWidget *w, char *description, +void* WMCreateTextBlockWithObject(WMText *tPtr, WMWidget *w, const char *description, WMColor *color, unsigned short first, unsigned short extraInfo); -void* WMCreateTextBlockWithPixmap(WMText *tPtr, WMPixmap *p, char *description, +void* WMCreateTextBlockWithPixmap(WMText *tPtr, WMPixmap *p, const char *description, WMColor *color, unsigned short first, unsigned short extraInfo); -void* WMCreateTextBlockWithText(WMText *tPtr, char *text, WMFont *font, +void* WMCreateTextBlockWithText(WMText *tPtr, const char *text, WMFont *font, WMColor *color, unsigned short first, unsigned short length); diff --git a/WINGs/dragdestination.c b/WINGs/dragdestination.c index 74f0d8e4..24c3ac48 100644 --- a/WINGs/dragdestination.c +++ b/WINGs/dragdestination.c @@ -417,7 +417,7 @@ storeDropData(WMView * destView, Atom selection, Atom target, Time timestamp, vo } } -Bool requestDropDataInSelection(WMView * destView, char *type) +Bool requestDropDataInSelection(WMView * destView, const char *type) { WMScreen *scr = W_VIEW_SCREEN(destView); diff --git a/WINGs/wtext.c b/WINGs/wtext.c index 827d19a8..620d57fa 100644 --- a/WINGs/wtext.c +++ b/WINGs/wtext.c @@ -616,7 +616,7 @@ static void paintText(Text * tPtr) { TextBlock *tb; WMFont *font; - char *text; + const char *text; int len, y, c, s, done = False, dir /* 1 = down */ ; WMScreen *scr = tPtr->view->screen; Display *dpy = tPtr->view->screen->display; @@ -960,7 +960,7 @@ static void cursorToTextPosition(Text * tPtr, int x, int y) { TextBlock *tb = NULL; int done = False, s, pos, len, _w, _y, dir = 1; /* 1 == "down" */ - char *text; + const char *text; if (tPtr->flags.needsLayOut) layOutDocument(tPtr); @@ -1372,7 +1372,7 @@ static int layOutLine(Text * tPtr, myLineItems * items, int nitems, int x, int y { int i, j = 0, lw = 0, line_height = 0, max_d = 0, len, n; WMFont *font; - char *text; + const char *text; TextBlock *tb, *tbsame = NULL; if (!items || nitems == 0) @@ -1472,7 +1472,7 @@ static void layOutDocument(Text * tPtr) unsigned int itemsSize = 0, nitems = 0, begin, end; WMFont *font; unsigned int x, y = 0, lw = 0, width = 0, bmargin; - char *start = NULL, *mark = NULL; + const char *start = NULL, *mark = NULL; if (tPtr->flags.frozen || (!(tb = tPtr->firstTextBlock))) return; @@ -2640,9 +2640,9 @@ static void handleEvents(XEvent * event, void *data) } } -static void insertPlainText(Text * tPtr, char *text) +static void insertPlainText(Text * tPtr, const char *text) { - char *start, *mark; + const char *start, *mark; void *tb = NULL; start = text; @@ -3060,7 +3060,7 @@ WMText *WMCreateTextForDocumentType(WMWidget * parent, WMAction * parser, WMActi return tPtr; } -void WMPrependTextStream(WMText * tPtr, char *text) +void WMPrependTextStream(WMText * tPtr, const char *text) { CHECK_CLASS(tPtr, WC_Text); @@ -3085,7 +3085,7 @@ void WMPrependTextStream(WMText * tPtr, char *text) } } -void WMAppendTextStream(WMText * tPtr, char *text) +void WMAppendTextStream(WMText * tPtr, const char *text) { CHECK_CLASS(tPtr, WC_Text); @@ -3152,7 +3152,7 @@ void WMSetTextDelegate(WMText * tPtr, WMTextDelegate * delegate) } void *WMCreateTextBlockWithObject(WMText * tPtr, WMWidget * w, - char *description, WMColor * color, + const char *description, WMColor * color, unsigned short first, unsigned short extraInfo) { TextBlock *tb; @@ -3185,7 +3185,7 @@ void *WMCreateTextBlockWithObject(WMText * tPtr, WMWidget * w, } void *WMCreateTextBlockWithPixmap(WMText * tPtr, WMPixmap * p, - char *description, WMColor * color, + const char *description, WMColor * color, unsigned short first, unsigned short extraInfo) { TextBlock *tb; @@ -3217,7 +3217,7 @@ void *WMCreateTextBlockWithPixmap(WMText * tPtr, WMPixmap * p, return tb; } -void *WMCreateTextBlockWithText(WMText * tPtr, char *text, WMFont * font, WMColor * color, +void *WMCreateTextBlockWithText(WMText * tPtr, const char *text, WMFont * font, WMColor * color, unsigned short first, unsigned short len) { TextBlock *tb; @@ -3814,9 +3814,9 @@ void WMThawText(WMText * tPtr) } /* find first occurence of a string */ -static char *mystrstr(char *haystack, char *needle, unsigned short len, char *end, Bool caseSensitive) +static const char *mystrstr(const char *haystack, const char *needle, unsigned short len, const char *end, Bool caseSensitive) { - char *ptr; + const char *ptr; if (!haystack || !needle || !end) return NULL; @@ -3836,9 +3836,9 @@ static char *mystrstr(char *haystack, char *needle, unsigned short len, char *en } /* find last occurence of a string */ -static char *mystrrstr(char *haystack, char *needle, unsigned short len, char *end, Bool caseSensitive) +static const char *mystrrstr(const char *haystack, const char *needle, unsigned short len, const char *end, Bool caseSensitive) { - char *ptr; + const char *ptr; if (!haystack || !needle || !end) return NULL; @@ -3856,10 +3856,10 @@ static char *mystrrstr(char *haystack, char *needle, unsigned short len, char *e return NULL; } -Bool WMFindInTextStream(WMText * tPtr, char *needle, Bool direction, Bool caseSensitive) +Bool WMFindInTextStream(WMText * tPtr, const char *needle, Bool direction, Bool caseSensitive) { TextBlock *tb; - char *mark = NULL; + const char *mark = NULL; unsigned short pos; #if 0