void-packages/srcpkgs/motif/patches/17-switch-to-system-iswspac...

385 lines
13 KiB
Diff
Raw Normal View History

2018-11-27 05:11:58 +01:00
Description: Switch to system iswspace() function
This patch replaces calls to _XmDataFieldIsWSpace() in lib/Xm/DataF.c
and _XmTextFieldIsWSpace() in lib/Xm/TextF.c with calls to the system
iswspace() function.
.
It fixes an array bounds error in lib/Xm/DataF.c where
_XmDataFieldIsWSpace() is called with num_entries = 3.
Author: Graham Inggs <graham@nerve.org.za>
Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1629
Last-Update: 2013-11-18
--- a/lib/Xm/DataF.c
+++ b/lib/Xm/DataF.c
@@ -208,7 +208,6 @@
static Boolean df_VerifyLeave() ;
static Boolean _XmDataFieldIsWordBoundary() ;
static int _XmGetImage(Screen *, char *, XImage **);
-static Boolean _XmDataFieldIsWSpace() ;
static void df_FindWord() ;
static void df_FindPrevWord() ;
static void df_FindNextWord() ;
@@ -549,10 +548,6 @@
XmDataFieldWidget tf,
XmTextPosition pos1,
XmTextPosition pos2) ;
-static Boolean _XmDataFieldIsWSpace(
- wchar_t wide_char,
- wchar_t *white_space,
- int num_entries) ;
static void df_FindWord(
XmDataFieldWidget tf,
XmTextPosition begin,
@@ -4549,40 +4544,6 @@
return False;
}
-/* This routine accepts an array of wchar_t's containing wchar encodings
- * of whitespace characters (and the number of array elements), comparing
- * the wide character passed to each element of the array. If a match
- * is found, we got a white space. This routine exists only because
- * iswspace(3c) is not yet standard. If a system has isw* available,
- * calls to this routine should be changed to iswspace(3c) (and callers
- * should delete initialization of the array), and this routine should
- * be deleted. Its a stop gap measure to avoid allocating an instance
- * variable for the white_space array and/or declaring a widget wide
- * global for the data and using a macro. Its ugly, but it works and
- * in the long run will be replaced by standard functionality. */
-
-/* ARGSUSED */
-static Boolean
-#ifdef _NO_PROTO
-_XmDataFieldIsWSpace( wide_char, white_space, num_entries )
- wchar_t wide_char ;
- wchar_t * white_space ;
- int num_entries ;
-#else
-_XmDataFieldIsWSpace(
- wchar_t wide_char,
- wchar_t * white_space ,
- int num_entries )
-#endif /* _NO_PROTO */
-{
- int i;
-
- for (i=num_entries; i > 0; i--){
- if (wide_char == white_space[i]) return True;
- }
- return False;
-}
-
static void
#ifdef _NO_PROTO
df_FindWord( tf, begin, left, right )
@@ -4599,7 +4560,6 @@
#endif /* _NO_PROTO */
{
XmTextPosition start, end;
- wchar_t white_space[3];
if (XmTextF_max_char_size(tf) == 1) {
for (start = begin; start > 0; start--) {
@@ -4617,11 +4577,8 @@
}
*right = end - 1;
} else { /* check for iswspace and iswordboundary in each direction */
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
for (start = begin; start > 0; start --) {
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start-1],white_space, 3)
+ if (iswspace(XmTextF_wc_value(tf)[start-1])
|| _XmDataFieldIsWordBoundary(tf, (XmTextPosition) start - 1,
start)) {
break;
@@ -4630,7 +4587,7 @@
*left = start;
for (end = begin; end <= XmTextF_string_length(tf); end++) {
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)){
+ if (iswspace(XmTextF_wc_value(tf)[end])){
end++;
break;
} else if (end < XmTextF_string_length(tf)) {
@@ -4659,14 +4616,6 @@
{
XmTextPosition start = XmTextF_cursor_position(tf);
- wchar_t white_space[3];
-
- if (XmTextF_max_char_size(tf) != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
-
if (XmTextF_max_char_size(tf) == 1) {
if ((start > 0) &&
@@ -4680,11 +4629,9 @@
}
df_FindWord(tf, start, left, right);
} else {
- if ((start > 0) && (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start - 1],
- white_space, 3))) {
+ if ((start > 0) && (iswspace(XmTextF_wc_value(tf)[start - 1]))) {
for (; start > 0; start--) {
- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start -1],
- white_space, 3)){
+ if (!iswspace(XmTextF_wc_value(tf)[start -1])){
start--;
break;
}
@@ -4713,14 +4660,6 @@
{
XmTextPosition end = XmTextF_cursor_position(tf);
- wchar_t white_space[3];
-
- if (XmTextF_max_char_size(tf) != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
-
if(XmTextF_max_char_size(tf) == 1) {
if (isspace((int)(unsigned char)XmTextF_value(tf)[end])) {
@@ -4742,9 +4681,9 @@
if (*right < XmTextF_string_length(tf))
*right = *right - 1;
} else {
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
+ if (iswspace(XmTextF_wc_value(tf)[end])) {
for ( ; end < XmTextF_string_length(tf); end ++) {
- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
+ if (!iswspace(XmTextF_wc_value(tf)[end])) {
break;
}
}
@@ -4758,10 +4697,9 @@
* If word boundary caused by whitespace, set right to the last
* whitespace following the end of the current word.
*/
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right], white_space, 3)) {
+ if (iswspace(XmTextF_wc_value(tf)[(int)*right])) {
while (*right < XmTextF_string_length(tf) &&
- _XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right],
- white_space, 3)) {
+ iswspace(XmTextF_wc_value(tf)[(int)*right])) {
*right = *right + 1;
}
if (*right < XmTextF_string_length(tf))
@@ -5872,13 +5810,6 @@
{
XmDataFieldWidget tf = (XmDataFieldWidget) w;
XmTextPosition cursorPos, position, dummy;
- wchar_t white_space[3];
-
- if (XmTextF_max_char_size(tf) != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
cursorPos = XmTextF_cursor_position(tf);
@@ -5896,16 +5827,13 @@
}
}
} else {
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[cursorPos],
- white_space, 3))
+ if (iswspace(XmTextF_wc_value(tf)[cursorPos]))
df_FindWord(tf, cursorPos, &dummy, &position);
else
df_FindNextWord(tf, &dummy, &position);
- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position],
- white_space, 3)){
+ if (iswspace(XmTextF_wc_value(tf)[position])){
for (; position < XmTextF_string_length(tf); position++) {
- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position],
- white_space, 3))
+ if (!iswspace(XmTextF_wc_value(tf)[position]))
break;
}
}
--- a/lib/Xm/TextF.c
+++ b/lib/Xm/TextF.c
@@ -360,10 +360,6 @@
XmTextPosition pos1,
XmTextPosition pos2);
-static Boolean _XmTextFieldIsWSpace(wchar_t wide_char,
- wchar_t *white_space,
- int num_entries);
-
static void FindWord(XmTextFieldWidget tf,
XmTextPosition begin,
XmTextPosition *left,
@@ -3514,32 +3510,6 @@
return False;
}
-/* This routine accepts an array of wchar_t's containing wchar encodings
- * of whitespace characters (and the number of array elements), comparing
- * the wide character passed to each element of the array. If a match
- * is found, we got a white space. This routine exists only because
- * iswspace(3c) is not yet standard. If a system has isw* available,
- * calls to this routine should be changed to iswspace(3c) (and callers
- * should delete initialization of the array), and this routine should
- * be deleted. Its a stop gap measure to avoid allocating an instance
- * variable for the white_space array and/or declaring a widget wide
- * global for the data and using a macro. Its ugly, but it works and
- * in the long run will be replaced by standard functionality. */
-
-/* ARGSUSED */
-static Boolean
-_XmTextFieldIsWSpace(wchar_t wide_char,
- wchar_t * white_space ,
- int num_entries)
-{
- int i;
-
- for (i=0; i < num_entries; i++) {
- if (wide_char == white_space[i]) return True;
- }
- return False;
-}
-
static void
FindWord(XmTextFieldWidget tf,
XmTextPosition begin,
@@ -3547,7 +3517,6 @@
XmTextPosition *right)
{
XmTextPosition start, end;
- wchar_t white_space[3];
if (tf->text.max_char_size == 1) {
for (start = begin; start > 0; start--) {
@@ -3565,11 +3534,8 @@
}
*right = end - 1;
} else { /* check for iswspace and iswordboundary in each direction */
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
for (start = begin; start > 0; start --) {
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[start-1],white_space, 3)
+ if (iswspace(TextF_WcValue(tf)[start-1])
|| _XmTextFieldIsWordBoundary(tf, (XmTextPosition) start - 1,
start)) {
break;
@@ -3578,7 +3544,7 @@
*left = start;
for (end = begin; end <= tf->text.string_length; end++) {
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
+ if (iswspace(TextF_WcValue(tf)[end])) {
end++;
break;
} else if (end < tf->text.string_length) {
@@ -3599,14 +3565,6 @@
{
XmTextPosition start = TextF_CursorPosition(tf);
- wchar_t white_space[3];
-
- if (tf->text.max_char_size != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
-
if (tf->text.max_char_size == 1) {
if ((start > 0) &&
@@ -3620,11 +3578,9 @@
}
FindWord(tf, start, left, right);
} else {
- if ((start > 0) && (_XmTextFieldIsWSpace(TextF_WcValue(tf)[start - 1],
- white_space, 3))) {
+ if ((start > 0) && (iswspace(TextF_WcValue(tf)[start - 1]))) {
for (; start > 0; start--) {
- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[start -1],
- white_space, 3)) {
+ if (!iswspace(TextF_WcValue(tf)[start -1])) {
start--;
break;
}
@@ -3645,14 +3601,6 @@
{
XmTextPosition end = TextF_CursorPosition(tf);
- wchar_t white_space[3];
-
- if (tf->text.max_char_size != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
-
if(tf->text.max_char_size == 1) {
if (isspace((unsigned char)TextF_Value(tf)[end])) {
@@ -3674,9 +3622,9 @@
if (*right < tf->text.string_length)
*right = *right - 1;
} else {
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
+ if (iswspace(TextF_WcValue(tf)[end])) {
for (; end < tf->text.string_length; end ++) {
- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
+ if (!iswspace(TextF_WcValue(tf)[end])) {
break;
}
}
@@ -3690,10 +3638,9 @@
* If word boundary caused by whitespace, set right to the last
* whitespace following the end of the current word.
*/
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[(int)*right], white_space, 3)) {
+ if (iswspace(TextF_WcValue(tf)[(int)*right])) {
while (*right < tf->text.string_length &&
- _XmTextFieldIsWSpace(TextF_WcValue(tf)[(int)*right],
- white_space, 3)) {
+ iswspace(TextF_WcValue(tf)[(int)*right])) {
*right = *right + 1;
}
if (*right < tf->text.string_length)
@@ -4546,13 +4493,6 @@
{
XmTextFieldWidget tf = (XmTextFieldWidget) w;
XmTextPosition cursorPos, position, dummy;
- wchar_t white_space[3];
-
- if (tf->text.max_char_size != 1) {
- (void)mbtowc(&white_space[0], " ", 1);
- (void)mbtowc(&white_space[1], "\n", 1);
- (void)mbtowc(&white_space[2], "\t", 1);
- }
cursorPos = TextF_CursorPosition(tf);
@@ -4570,16 +4510,13 @@
}
}
} else {
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[cursorPos],
- white_space, 3))
+ if (iswspace(TextF_WcValue(tf)[cursorPos]))
FindWord(tf, cursorPos, &dummy, &position);
else
FindNextWord(tf, &dummy, &position);
- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[position],
- white_space, 3)) {
+ if (iswspace(TextF_WcValue(tf)[position])) {
for (; position < tf->text.string_length; position++) {
- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[position],
- white_space, 3))
+ if (!iswspace(TextF_WcValue(tf)[position]))
break;
}
}