ex_cmds: Simplify do_ascii

Specifically apply constants like enc_utf8 (which are constants *now*) and 
simplify conditions after that. Also some style changes.
This commit is contained in:
ZyX 2018-04-15 19:01:58 +03:00
parent db7f80302b
commit aa5008c1f0

View File

@ -109,79 +109,61 @@ typedef struct {
# include "ex_cmds.c.generated.h"
#endif
/*
* ":ascii" and "ga".
*/
void do_ascii(exarg_T *eap)
/// ":ascii" and "ga" implementation
void do_ascii(const exarg_T *const eap)
{
int c;
int cval;
char buf1[20];
char buf2[20];
char_u buf3[7];
int cc[MAX_MCO];
int ci = 0;
int len;
const bool l_enc_utf8 = enc_utf8;
if (l_enc_utf8)
c = utfc_ptr2char(get_cursor_pos_ptr(), cc);
else
c = gchar_cursor();
int c = utfc_ptr2char(get_cursor_pos_ptr(), cc);
if (c == NUL) {
MSG("NUL");
return;
}
IObuff[0] = NUL;
if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) {
if (c == NL) /* NUL is stored as NL */
int ci = 0;
if (c < 0x80) {
if (c == NL) { // NUL is stored as NL.
c = NUL;
if (c == CAR && get_fileformat(curbuf) == EOL_MAC)
cval = NL; /* NL is stored as CR */
else
cval = c;
if (vim_isprintc_strict(c) && (c < ' '
|| c > '~'
)) {
}
const int cval = (c == CAR && get_fileformat(curbuf) == EOL_MAC
? NL // NL is stored as CR.
: c);
char buf1[20];
if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) {
char_u buf3[7];
transchar_nonprint(buf3, c);
vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3);
} else
} else {
buf1[0] = NUL;
if (c >= 0x80)
vim_snprintf(buf2, sizeof(buf2), " <M-%s>",
(char *)transchar(c & 0x7f));
else
buf2[0] = NUL;
}
char buf2[20];
buf2[0] = NUL;
vim_snprintf((char *)IObuff, IOSIZE,
_("<%s>%s%s %d, Hex %02x, Octal %03o"),
transchar(c), buf1, buf2, cval, cval, cval);
if (l_enc_utf8)
c = cc[ci++];
else
c = 0;
_("<%s>%s%s %d, Hex %02x, Octal %03o"),
transchar(c), buf1, buf2, cval, cval, cval);
c = cc[ci++];
}
/* Repeat for combining characters. */
while (has_mbyte && (c >= 0x100 || (l_enc_utf8 && c >= 0x80))) {
len = (int)STRLEN(IObuff);
/* This assumes every multi-byte char is printable... */
if (len > 0)
// Repeat for combining characters.
while (c >= 0x80) {
int len = (int)STRLEN(IObuff);
// This assumes every multi-byte char is printable...
if (len > 0) {
IObuff[len++] = ' ';
}
IObuff[len++] = '<';
if (l_enc_utf8 && utf_iscomposing(c)) {
if (utf_iscomposing(c)) {
IObuff[len++] = ' '; // Draw composing char on top of a space.
}
len += (*mb_char2bytes)(c, IObuff + len);
len += utf_char2bytes(c, IObuff + len);
vim_snprintf((char *)IObuff + len, IOSIZE - len,
c < 0x10000 ? _("> %d, Hex %04x, Octal %o")
: _("> %d, Hex %08x, Octal %o"), c, c, c);
if (ci == MAX_MCO)
c < 0x10000 ? _("> %d, Hex %04x, Octal %o")
: _("> %d, Hex %08x, Octal %o"), c, c, c);
if (ci == MAX_MCO) {
break;
if (l_enc_utf8)
c = cc[ci++];
else
c = 0;
}
c = cc[ci++];
}
msg(IObuff);