-
-
Notifications
You must be signed in to change notification settings - Fork 85
FvwmForm: process UTF-8 input and paste request in input fields #1212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To make FvwmForm input fields UTF-8 aware, input.size field is duplicated as input.width, the first one containing size in bytes and the latter width in multibyte chars. To allow walking along a string with chars of different lengths (1 to 4 bytes), e.g., for pasting or moving a cursor by arrow keys or by a mouse click, a helper function find_nth_UTF8_char() is introduced.
…ke this into account on restart.
@ThomasAdam @somiaj No more places affected by "multibyteness" found. Testing shows no problems. Please review. |
modules/FvwmForm/FvwmForm.c
Outdated
@@ -2135,10 +2143,17 @@ char* find_nth_UTF8_char(char *str, char *before, | |||
} | |||
|
|||
while (1) { | |||
if (*str == '\0' || (before && str >= before) | |||
if (*str == '\0' || l == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 == 0
? We can do better than this, @ONykyf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple way to signal that no valid UTF-8 char can be found at the requested position, so no need for additional Boolean flags, and convenient to use in conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple way to signal that no valid UTF-8 char can be found at the requested position, so no need for additional Boolean flags, and convenient to use in conditions.
No... it's just unnecessary.
Please remove this instance, and subsequent ones.
modules/FvwmForm/FvwmForm.c
Outdated
pstr = str; | ||
l = 0; | ||
} | ||
else if (l == 0 || i == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ibid.
modules/FvwmForm/FvwmForm.c
Outdated
@@ -947,10 +947,11 @@ static void ct_Input(char *cp) | |||
item->input.blanks = fxmalloc(item->input.width); | |||
for (j = 0; j < item->input.width; j++) | |||
item->input.blanks[j] = ' '; | |||
item->input.buf = strlen(item->input.init_value) + 1; | |||
item->input.buf = strlen(item->input.init_value) + 1; /* room for init value */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
modules/FvwmForm/FvwmForm.c
Outdated
strcpy(item->input.init_value,cp); /* new initial value in field */ | ||
strncpy(item->input.init_value, cp, var_len); /* new initial value */ | ||
item->input.init_value[var_len] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see xasprintf
or similar used here, rather than a change to strncpy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to copy a part of a string up to a certain position (not necessarily to '\0'), so strndup() seems to be the best candidate. In case strndup() fails, the subsequent fxstrdup() will catch this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.
@ONykyf -- Thanks for this. It looks OK, although I'm not going to get time to properly look at it until later on the week. Other than my very small nits I've identified, I think we can probably improve on the logic in a few areas, but I'll wait until I've had change to go over those properly. |
…ocate mouse click faster, and translate labels with Gettext
This PR is getting there, still with comments from me which need addressing. I'm still not completely happy with the state of things overall though, but it's a convoluted mess and this is probably going to have to be good enough, but I suspect I'll merge this once you've finished addressing things, and then tidy it up afterward. |
Hope now the logic of the helper function is more straightforward and manageable enough by whoever will do this in the future. |
modules/FvwmForm/FvwmForm.c
Outdated
#if 0 /* no UTF-8, single-byte locale */ | ||
pstr = str; | ||
str++; | ||
i++; | ||
#else /* parse UTF-8 string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May as well just remove the #if 0/#else
stuff...
modules/FvwmForm/FvwmForm.c
Outdated
@@ -2135,10 +2143,17 @@ char* find_nth_UTF8_char(char *str, char *before, | |||
} | |||
|
|||
while (1) { | |||
if (*str == '\0' || (before && str >= before) | |||
if (*str == '\0' || l == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A simple way to signal that no valid UTF-8 char can be found at the requested position, so no need for additional Boolean flags, and convenient to use in conditions.
No... it's just unnecessary.
Please remove this instance, and subsequent ones.
modules/FvwmForm/FvwmForm.c
Outdated
strcpy(item->input.init_value,cp); /* new initial value in field */ | ||
strncpy(item->input.init_value, cp, var_len); /* new initial value */ | ||
item->input.init_value[var_len] = '\0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh.
modules/FvwmForm/FvwmForm.c
Outdated
if (num) *num = -1; | ||
if (len) *len = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: assignment after if() should be on its own line.
modules/FvwmForm/FvwmForm.c
Outdated
if (num) *num = i - 1; | ||
if (len) *len = l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ibid.
modules/FvwmForm/FvwmForm.c
Outdated
pstr = str; | ||
l = 0; | ||
} | ||
else if ((l == 0) || (*str == '\0')) { /* invalid UTF-8 char or '\0' */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We said we weren't going to do this 1 == 0
business....
modules/FvwmForm/FvwmForm.c
Outdated
if (num) *num = i - 1; | ||
if (len) *len = l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style, put the conditionals on their own line, after if()...
Removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be squashed into a previous commit as it's not introducing anything new.
@ThomasAdam Unsafe In fact getpwuid.c also contains |
No thanks. I don't think we need this.
getpwuid.c is a compat file found elsewhere, it's not changing to fit in with any wrapper functions. The point of the You may as well just remove this latest commit, and make the following adjustment:
I also think we need to look at |
Done
|
To make FvwmForm input fields UTF-8 aware, input.size field is duplicated as input.width, the first one containing size in bytes and the latter width in multibyte chars. To allow walking along a string with chars of different lengths (1 to 4 bytes), e.g., for pasting or moving a cursor by arrow keys or by a mouse click, a helper function find_nth_UTF8_char() is introduced.
Fixes #1211