From: "Torsten Bögershausen" <tboegi@web.de>
To: kusmabite@gmail.com
Cc: "Torsten Bögershausen" <tboegi@web.de>, git@vger.kernel.org
Subject: Re: [PATH/RFC] parse-options: report invalid UTF-8 switches
Date: Mon, 11 Feb 2013 18:04:32 +0100 [thread overview]
Message-ID: <511924A0.8030704@web.de> (raw)
In-Reply-To: <CABPQNSYXk5_VdGP9QQttZKpcBnmohmNb+AOH=bMkOrXjbq1ZmQ@mail.gmail.com>
On 11.02.13 17:36, Erik Faye-Lund wrote:
> On Mon, Feb 11, 2013 at 5:28 PM, Torsten Bögershausen <tboegi@web.de> wrote:
>> On 11.02.13 14:34, Erik Faye-Lund wrote:
>>> Even though parse-options doesn't support UTF-8 switches (which
>>> makes sense; non-ascii switches would be difficult to enter on
>>> some keyboard layouts), it can be useful to report incorrectly
>>> entered UTF-8 switches to make the output somewhat less ugly
>>> for those of us with keyboard layouts with UTF-8 characters on
>>> it.
>>>
>>> Make the reporting code grok UTF-8 in the option sequence, and
>>> write a variable-width output sequence.
>>>
>>> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
>>> ---
>>> As being both clumsy and Norwegian, I some times to enter the
>>> Norwegian bizarro-letters ('æ', 'ø' and 'å') instead of the
>>> correct ones when entering command-line options.
>>>
>>> However, since git only looks at one byte at the time for
>>> short-options, it ends up reporting a partial UTF-8 sequence
>>> in such cases, leading to corruption of the output.
>>>
>>> The "real fix" would probably be to add proper multi-byte
>>> support to the short-option parser, but this serves little
>>> purpose in Git; we don't internationalize the command-line
>>> switches.
>>>
>>> So perhaps this is a suitable band-aid instead?
>>>
>>> parse-options.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/parse-options.c b/parse-options.c
>>> index 67e98a6..20dc742 100644
>>> --- a/parse-options.c
>>> +++ b/parse-options.c
>>> @@ -3,6 +3,7 @@
>>> #include "cache.h"
>>> #include "commit.h"
>>> #include "color.h"
>>> +#include "utf8.h"
>>>
>>> static int parse_options_usage(struct parse_opt_ctx_t *ctx,
>>> const char * const *usagestr,
>>> @@ -462,7 +463,9 @@ int parse_options(int argc, const char **argv, const char *prefix,
>>> if (ctx.argv[0][1] == '-') {
>>> error("unknown option `%s'", ctx.argv[0] + 2);
>>> } else {
>>> - error("unknown switch `%c'", *ctx.opt);
>>> + const char *next = ctx.opt;
>>> + utf8_width(&next, NULL);
>>> + error("unknown switch `%.*s'", (int)(next - ctx.opt), ctx.opt);
>>> }
>>> usage_with_options(usagestr, options);
>>> }
>>>
>> Would the following do the trick?
>>
>> diff --git a/parse-options.c b/parse-options.c
>> index c1c66bd..f800552 100644
>> --- a/parse-options.c
>> +++ b/parse-options.c
>> @@ -471,7 +471,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
>> if (ctx.argv[0][1] == '-') {
>> error("unknown option `%s'", ctx.argv[0] + 2);
>> } else {
>> - error("unknown switch `%c'", *ctx.opt);
>> + error("unknown switch `%s'", ctx.opt);
>> }
>>
>>
> Nope; that would print the rest of the option-string, in cases of "git
> <command> -abcd".
Ok, may be pick_one_utf8_char() is a better choice than simply assuming ASCII.
We can make a guess, if it is utf-8, we use it. If not, assume ASCII.
Just thinking loud (the "if" could be written shorter using the "?" operator)
} else {
const char *start = ctx.opt;
unsigned c = pick_one_utf8_char(&start, NULL);
if (!c)
c = *ctx.opt;
error("unknown switch `%c'", c);
}
next prev parent reply other threads:[~2013-02-11 17:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-11 13:34 [PATH/RFC] parse-options: report invalid UTF-8 switches Erik Faye-Lund
2013-02-11 13:43 ` Matthieu Moy
2013-02-11 13:57 ` Erik Faye-Lund
2013-02-11 14:05 ` Matthieu Moy
2013-02-11 14:27 ` Erik Faye-Lund
2013-02-11 16:28 ` Torsten Bögershausen
2013-02-11 16:36 ` Erik Faye-Lund
2013-02-11 17:04 ` Torsten Bögershausen [this message]
2013-02-11 17:07 ` Junio C Hamano
2013-02-11 17:15 ` Erik Faye-Lund
2013-02-11 17:19 ` Jeff King
2013-02-11 17:21 ` Erik Faye-Lund
2013-02-11 17:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=511924A0.8030704@web.de \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
--cc=kusmabite@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).