aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/digraph.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/digraph.c')
-rw-r--r--src/nvim/digraph.c184
1 files changed, 98 insertions, 86 deletions
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index e4528f9038..33038dfb9f 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -8,24 +8,34 @@
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
+#include <string.h>
#include "nvim/ascii.h"
+#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/digraph.h"
#include "nvim/drawscreen.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
+#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
+#include "nvim/gettext.h"
+#include "nvim/globals.h"
+#include "nvim/highlight_defs.h"
+#include "nvim/keycodes.h"
#include "nvim/mapping.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/normal.h"
+#include "nvim/option_defs.h"
#include "nvim/os/input.h"
#include "nvim/runtime.h"
#include "nvim/strings.h"
+#include "nvim/types.h"
#include "nvim/vim.h"
typedef int result_T;
@@ -52,7 +62,6 @@ static garray_T user_digraphs = { 0, 0, (int)sizeof(digr_T), 10, NULL };
/// Note: Characters marked with XX are not included literally, because some
/// compilers cannot handle them (Amiga SAS/C is the most picky one).
static digr_T digraphdefault[] =
-
// digraphs for Unicode from RFC1345
// (also work for ISO-8859-1 aka latin1)
{
@@ -1519,30 +1528,31 @@ int get_digraph(bool cmdline)
no_mapping--;
allow_keys--;
- if (c != ESC) {
- // ESC cancels CTRL-K
- if (IS_SPECIAL(c)) {
- // insert special key code
- return c;
- }
+ if (c == ESC) { // ESC cancels CTRL-K
+ return NUL;
+ }
- if (cmdline) {
- if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) {
- putcmdline((char)c, true);
- }
- } else {
- add_to_showcmd(c);
- }
- no_mapping++;
- allow_keys++;
- int cc = plain_vgetc();
- no_mapping--;
- allow_keys--;
-
- if (cc != ESC) {
- // ESC cancels CTRL-K
- return digraph_get(c, cc, true);
+ if (IS_SPECIAL(c)) {
+ // insert special key code
+ return c;
+ }
+
+ if (cmdline) {
+ if ((char2cells(c) == 1) && c < 128 && (cmdline_star == 0)) {
+ putcmdline((char)c, true);
}
+ } else {
+ add_to_showcmd(c);
+ }
+ no_mapping++;
+ allow_keys++;
+ int cc = plain_vgetc();
+ no_mapping--;
+ allow_keys--;
+
+ if (cc != ESC) {
+ // ESC cancels CTRL-K
+ return digraph_get(c, cc, true);
}
return NUL;
}
@@ -1578,7 +1588,7 @@ static int getexactdigraph(int char1, int char2, bool meta_char)
if (retval == 0) {
dp = digraphdefault;
- for (int i = 0; dp->char1 != 0; i++) {
+ while (dp->char1 != 0) {
if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) {
retval = dp->result;
break;
@@ -1646,8 +1656,8 @@ static void registerdigraph(int char1, int char2, int n)
bool check_digraph_chars_valid(int char1, int char2)
{
if (char2 == 0) {
- char_u msg[MB_MAXBYTES + 1];
- msg[utf_char2bytes(char1, (char *)msg)] = NUL;
+ char msg[MB_MAXBYTES + 1];
+ msg[utf_char2bytes(char1, msg)] = NUL;
semsg(_(e_digraph_must_be_just_two_characters_str), msg);
return false;
}
@@ -1707,7 +1717,7 @@ void listdigraphs(bool use_headers)
const digr_T *dp = digraphdefault;
- for (int i = 0; dp->char1 != NUL && !got_int; i++) {
+ while (dp->char1 != NUL && !got_int) {
digr_T tmp;
// May need to convert the result to 'encoding'.
@@ -1759,7 +1769,7 @@ void digraph_getlist_common(bool list_all, typval_T *rettv)
if (list_all) {
dp = digraphdefault;
- for (int i = 0; dp->char1 != NUL && !got_int; i++) {
+ while (dp->char1 != NUL && !got_int) {
digr_T tmp;
tmp.char1 = dp->char1;
tmp.char2 = dp->char2;
@@ -1817,54 +1827,56 @@ static void printdigraph(const digr_T *dp, result_T *previous)
char_u buf[30];
int list_width = 13;
- if (dp->result != 0) {
- if (previous != NULL) {
- for (int i = 0; header_table[i].dg_header != NULL; i++) {
- if (*previous < header_table[i].dg_start
- && dp->result >= header_table[i].dg_start
- && dp->result < header_table[i + 1].dg_start) {
- digraph_header(_(header_table[i].dg_header));
- break;
- }
+ if (dp->result == 0) {
+ return;
+ }
+
+ if (previous != NULL) {
+ for (int i = 0; header_table[i].dg_header != NULL; i++) {
+ if (*previous < header_table[i].dg_start
+ && dp->result >= header_table[i].dg_start
+ && dp->result < header_table[i + 1].dg_start) {
+ digraph_header(_(header_table[i].dg_header));
+ break;
}
- *previous = dp->result;
- }
- if (msg_col > Columns - list_width) {
- msg_putchar('\n');
}
+ *previous = dp->result;
+ }
+ if (msg_col > Columns - list_width) {
+ msg_putchar('\n');
+ }
- // Make msg_col a multiple of list_width by using spaces.
- if (msg_col % list_width != 0) {
- int spaces = (msg_col / list_width + 1) * list_width - msg_col;
- while (spaces--) {
- msg_putchar(' ');
- }
+ // Make msg_col a multiple of list_width by using spaces.
+ if (msg_col % list_width != 0) {
+ int spaces = (msg_col / list_width + 1) * list_width - msg_col;
+ while (spaces--) {
+ msg_putchar(' ');
}
+ }
- char_u *p = &buf[0];
- *p++ = dp->char1;
- *p++ = dp->char2;
- *p++ = ' ';
- *p = NUL;
- msg_outtrans((char *)buf);
- p = buf;
+ char_u *p = &buf[0];
+ *p++ = dp->char1;
+ *p++ = dp->char2;
+ *p++ = ' ';
+ *p = NUL;
+ msg_outtrans((char *)buf);
+ p = buf;
- // add a space to draw a composing char on
- if (utf_iscomposing(dp->result)) {
- *p++ = ' ';
- }
- p += utf_char2bytes(dp->result, (char *)p);
+ // add a space to draw a composing char on
+ if (utf_iscomposing(dp->result)) {
+ *p++ = ' ';
+ }
+ p += utf_char2bytes(dp->result, (char *)p);
- *p = NUL;
- msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8));
- p = buf;
- if (char2cells(dp->result) == 1) {
- *p++ = ' ';
- }
- assert(p >= buf);
- vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result);
- msg_outtrans((char *)buf);
+ *p = NUL;
+ msg_outtrans_attr((char *)buf, HL_ATTR(HLF_8));
+ p = buf;
+ if (char2cells(dp->result) == 1) {
+ *p++ = ' ';
}
+ assert(p >= buf);
+ vim_snprintf((char *)p, sizeof(buf) - (size_t)(p - buf), " %3d", dp->result);
+ msg_outtrans((char *)buf);
}
/// Get the two digraph characters from a typval.
@@ -1926,15 +1938,15 @@ void f_digraph_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
if (digraphs == NULL) {
return;
}
- if (STRLEN(digraphs) != 2) {
+ if (strlen(digraphs) != 2) {
semsg(_(e_digraph_must_be_just_two_characters_str), digraphs);
return;
}
int code = digraph_get(digraphs[0], digraphs[1], false);
- char_u buf[NUMBUFLEN];
- buf[utf_char2bytes(code, (char *)buf)] = NUL;
- rettv->vval.v_string = (char *)vim_strsave(buf);
+ char buf[NUMBUFLEN];
+ buf[utf_char2bytes(code, buf)] = NUL;
+ rettv->vval.v_string = xstrdup(buf);
}
/// "digraph_getlist()" function
@@ -2010,8 +2022,8 @@ void f_digraph_setlist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// structure used for b_kmap_ga.ga_data
typedef struct {
- char_u *from;
- char_u *to;
+ char *from;
+ char *to;
} kmap_T;
#define KMAP_MAXLEN 20 // maximum length of "from" or "to"
@@ -2036,7 +2048,7 @@ char *keymap_init(void)
// Source the keymap file. It will contain a ":loadkeymap" command
// which will call ex_loadkeymap() below.
- buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14;
+ buflen = strlen(curbuf->b_p_keymap) + strlen(p_enc) + 14;
buf = xmalloc(buflen);
// try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath'
@@ -2064,10 +2076,10 @@ char *keymap_init(void)
/// @param eap
void ex_loadkeymap(exarg_T *eap)
{
- char_u *s;
+ char *s;
#define KMAP_LLEN 200 // max length of "to" and "from" together
- char_u buf[KMAP_LLEN + 11];
+ char buf[KMAP_LLEN + 11];
char *save_cpo = p_cpo;
if (!getline_equal(eap->getline, eap->cookie, getsourceline)) {
@@ -2092,17 +2104,17 @@ void ex_loadkeymap(exarg_T *eap)
break;
}
- char_u *p = (char_u *)skipwhite(line);
+ char *p = skipwhite(line);
if ((*p != '"') && (*p != NUL)) {
kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga);
- s = (char_u *)skiptowhite((char *)p);
- kp->from = vim_strnsave(p, (size_t)(s - p));
- p = (char_u *)skipwhite((char *)s);
- s = (char_u *)skiptowhite((char *)p);
- kp->to = vim_strnsave(p, (size_t)(s - p));
+ s = skiptowhite(p);
+ kp->from = xstrnsave(p, (size_t)(s - p));
+ p = skipwhite(s);
+ s = skiptowhite(p);
+ kp->to = xstrnsave(p, (size_t)(s - p));
- if ((STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN)
+ if ((strlen(kp->from) + strlen(kp->to) >= KMAP_LLEN)
|| (*kp->from == NUL)
|| (*kp->to == NUL)) {
if (*kp->to == NUL) {
@@ -2118,7 +2130,7 @@ void ex_loadkeymap(exarg_T *eap)
// setup ":lmap" to map the keys
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
- vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s %s",
+ vim_snprintf(buf, sizeof(buf), "<buffer> %s %s",
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from,
((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to);
(void)do_map(MAPTYPE_MAP, buf, MODE_LANGMAP, false);
@@ -2158,7 +2170,7 @@ static void keymap_unload(void)
for (int i = 0; i < curbuf->b_kmap_ga.ga_len; i++) {
vim_snprintf(buf, sizeof(buf), "<buffer> %s", kp[i].from);
- (void)do_map(MAPTYPE_UNMAP, (char_u *)buf, MODE_LANGMAP, false);
+ (void)do_map(MAPTYPE_UNMAP, buf, MODE_LANGMAP, false);
}
keymap_ga_clear(&curbuf->b_kmap_ga);