diff options
author | David Z. Chen <david.z.chen@outlook.com> | 2014-03-10 03:48:12 -0700 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-03-16 12:00:41 -0300 |
commit | baab23827194175e811cfaccd287e9438f1d1b6d (patch) | |
tree | 72d3d35fc2680149fdbcc32a9d068e6a7c821354 /src | |
parent | 8a6118ccaced623b9e6d854e3a41fbd9d6fc68df (diff) | |
download | rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.tar.gz rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.tar.bz2 rneovim-baab23827194175e811cfaccd287e9438f1d1b6d.zip |
Issue #311 - Clean up blowfish.c/h, charset.c/h, diff.c/h, digraph.c/h, garray.c/h, hashtab.c/h, popupmnu.c/h, sha256.c/h, version.c/h. Update uncrustify to move logical operators to the beginning of the line when splitting. Also, clean up arabic.c/h and farsi.c/h
Diffstat (limited to 'src')
-rw-r--r-- | src/arabic.c | 150 | ||||
-rw-r--r-- | src/arabic.h | 67 | ||||
-rw-r--r-- | src/blowfish.c | 206 | ||||
-rw-r--r-- | src/blowfish.h | 7 | ||||
-rw-r--r-- | src/charset.c | 1862 | ||||
-rw-r--r-- | src/charset.h | 7 | ||||
-rw-r--r-- | src/crypt.c | 107 | ||||
-rw-r--r-- | src/diff.c | 2455 | ||||
-rw-r--r-- | src/diff.h | 7 | ||||
-rw-r--r-- | src/digraph.c | 3566 | ||||
-rw-r--r-- | src/digraph.h | 7 | ||||
-rw-r--r-- | src/farsi.c | 349 | ||||
-rw-r--r-- | src/farsi.h | 136 | ||||
-rw-r--r-- | src/garray.c | 118 | ||||
-rw-r--r-- | src/garray.h | 22 | ||||
-rw-r--r-- | src/hashtab.c | 465 | ||||
-rw-r--r-- | src/popupmnu.c | 589 | ||||
-rw-r--r-- | src/popupmnu.h | 17 | ||||
-rw-r--r-- | src/sha256.c | 358 | ||||
-rw-r--r-- | src/sha256.h | 14 | ||||
-rw-r--r-- | src/version.c | 584 | ||||
-rw-r--r-- | src/version.h | 7 |
22 files changed, 5889 insertions, 5211 deletions
diff --git a/src/arabic.c b/src/arabic.c index 2bff0c2866..fab7cfafed 100644 --- a/src/arabic.c +++ b/src/arabic.c @@ -1,25 +1,11 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ +/// @file arabic.c +/// +/// Functions for Arabic language +/// +/// Included by main.c, when FEAT_ARABIC & FEAT_GUI is defined. #include "arabic.h" -/* - * arabic.c: functions for Arabic language - * - * Included by main.c, when FEAT_ARABIC & FEAT_GUI is defined. - * - * -- - * - * Author: Nadim Shaikli & Isam Bayazidi - * - */ - static int A_is_a(int cur_c); static int A_is_s(int cur_c); static int A_is_f(int cur_c); @@ -40,9 +26,7 @@ static int A_is_ok(int c); static int A_is_valid(int c); static int A_is_special(int c); -/* - * Returns True if c is an ISO-8859-6 shaped ARABIC letter (user entered) - */ +// Returns True if c is an ISO-8859-6 shaped ARABIC letter (user entered). static int A_is_a(int cur_c) { switch (cur_c) { @@ -89,9 +73,7 @@ static int A_is_a(int cur_c) return FALSE; } -/* - * Returns True if c is an Isolated Form-B ARABIC letter - */ +// Returns True if c is an Isolated Form-B ARABIC letter static int A_is_s(int cur_c) { switch (cur_c) { @@ -137,9 +119,7 @@ static int A_is_s(int cur_c) return FALSE; } -/* - * Returns True if c is a Final shape of an ARABIC letter - */ +// Returns True if c is a Final shape of an ARABIC letter static int A_is_f(int cur_c) { switch (cur_c) { @@ -187,9 +167,7 @@ static int A_is_f(int cur_c) return FALSE; } -/* - * Change shape - from ISO-8859-6/Isolated to Form-B Isolated - */ +// Change shape - from ISO-8859-6/Isolated to Form-B Isolated static int chg_c_a2s(int cur_c) { int tempc; @@ -243,7 +221,7 @@ static int chg_c_a2s(int cur_c) tempc = a_s_ZAIN; break; - case a_TATWEEL: /* exceptions */ + case a_TATWEEL: // exceptions tempc = cur_c; break; @@ -350,9 +328,7 @@ static int chg_c_a2s(int cur_c) return tempc; } -/* - * Change shape - from ISO-8859-6/Isolated to Initial - */ +// Change shape - from ISO-8859-6/Isolated to Initial static int chg_c_a2i(int cur_c) { int tempc; @@ -362,59 +338,59 @@ static int chg_c_a2i(int cur_c) tempc = a_i_YEH_HAMZA; break; - case a_HAMZA: /* exceptions */ + case a_HAMZA: // exceptions tempc = a_s_HAMZA; break; - case a_ALEF_MADDA: /* exceptions */ + case a_ALEF_MADDA: // exceptions tempc = a_s_ALEF_MADDA; break; - case a_ALEF_HAMZA_ABOVE: /* exceptions */ + case a_ALEF_HAMZA_ABOVE: // exceptions tempc = a_s_ALEF_HAMZA_ABOVE; break; - case a_WAW_HAMZA: /* exceptions */ + case a_WAW_HAMZA: // exceptions tempc = a_s_WAW_HAMZA; break; - case a_ALEF_HAMZA_BELOW: /* exceptions */ + case a_ALEF_HAMZA_BELOW: // exceptions tempc = a_s_ALEF_HAMZA_BELOW; break; - case a_ALEF: /* exceptions */ + case a_ALEF: // exceptions tempc = a_s_ALEF; break; - case a_TEH_MARBUTA: /* exceptions */ + case a_TEH_MARBUTA: // exceptions tempc = a_s_TEH_MARBUTA; break; - case a_DAL: /* exceptions */ + case a_DAL: // exceptions tempc = a_s_DAL; break; - case a_THAL: /* exceptions */ + case a_THAL: // exceptions tempc = a_s_THAL; break; - case a_REH: /* exceptions */ + case a_REH: // exceptions tempc = a_s_REH; break; - case a_ZAIN: /* exceptions */ + case a_ZAIN: // exceptions tempc = a_s_ZAIN; break; - case a_TATWEEL: /* exceptions */ + case a_TATWEEL: // exceptions tempc = cur_c; break; - case a_WAW: /* exceptions */ + case a_WAW: // exceptions tempc = a_s_WAW; break; - case a_ALEF_MAKSURA: /* exceptions */ + case a_ALEF_MAKSURA: // exceptions tempc = a_s_ALEF_MAKSURA; break; @@ -513,31 +489,29 @@ static int chg_c_a2i(int cur_c) return tempc; } -/* - * Change shape - from ISO-8859-6/Isolated to Medial - */ +// Change shape - from ISO-8859-6/Isolated to Medial static int chg_c_a2m(int cur_c) { int tempc; switch (cur_c) { - case a_HAMZA: /* exception */ + case a_HAMZA: // exception tempc = a_s_HAMZA; break; - case a_ALEF_MADDA: /* exception */ + case a_ALEF_MADDA: // exception tempc = a_f_ALEF_MADDA; break; - case a_ALEF_HAMZA_ABOVE: /* exception */ + case a_ALEF_HAMZA_ABOVE: // exception tempc = a_f_ALEF_HAMZA_ABOVE; break; - case a_WAW_HAMZA: /* exception */ + case a_WAW_HAMZA: // exception tempc = a_f_WAW_HAMZA; break; - case a_ALEF_HAMZA_BELOW: /* exception */ + case a_ALEF_HAMZA_BELOW: // exception tempc = a_f_ALEF_HAMZA_BELOW; break; @@ -545,7 +519,7 @@ static int chg_c_a2m(int cur_c) tempc = a_m_YEH_HAMZA; break; - case a_ALEF: /* exception */ + case a_ALEF: // exception tempc = a_f_ALEF; break; @@ -553,7 +527,7 @@ static int chg_c_a2m(int cur_c) tempc = a_m_BEH; break; - case a_TEH_MARBUTA: /* exception */ + case a_TEH_MARBUTA: // exception tempc = a_f_TEH_MARBUTA; break; @@ -577,19 +551,19 @@ static int chg_c_a2m(int cur_c) tempc = a_m_KHAH; break; - case a_DAL: /* exception */ + case a_DAL: // exception tempc = a_f_DAL; break; - case a_THAL: /* exception */ + case a_THAL: // exception tempc = a_f_THAL; break; - case a_REH: /* exception */ + case a_REH: // exception tempc = a_f_REH; break; - case a_ZAIN: /* exception */ + case a_ZAIN: // exception tempc = a_f_ZAIN; break; @@ -625,7 +599,7 @@ static int chg_c_a2m(int cur_c) tempc = a_m_GHAIN; break; - case a_TATWEEL: /* exception */ + case a_TATWEEL: // exception tempc = cur_c; break; @@ -657,11 +631,11 @@ static int chg_c_a2m(int cur_c) tempc = a_m_HEH; break; - case a_WAW: /* exception */ + case a_WAW: // exception tempc = a_f_WAW; break; - case a_ALEF_MAKSURA: /* exception */ + case a_ALEF_MAKSURA: // exception tempc = a_f_ALEF_MAKSURA; break; @@ -676,25 +650,22 @@ static int chg_c_a2m(int cur_c) return tempc; } -/* - * Change shape - from ISO-8859-6/Isolated to final - */ +// Change shape - from ISO-8859-6/Isolated to final static int chg_c_a2f(int cur_c) { int tempc; - /* NOTE: these encodings need to be accounted for - - a_f_ALEF_MADDA; - a_f_ALEF_HAMZA_ABOVE; - a_f_ALEF_HAMZA_BELOW; - a_f_LAM_ALEF_MADDA_ABOVE; - a_f_LAM_ALEF_HAMZA_ABOVE; - a_f_LAM_ALEF_HAMZA_BELOW; - */ + // NOTE: these encodings need to be accounted for + // + // a_f_ALEF_MADDA; + // a_f_ALEF_HAMZA_ABOVE; + // a_f_ALEF_HAMZA_BELOW; + // a_f_LAM_ALEF_MADDA_ABOVE; + // a_f_LAM_ALEF_HAMZA_ABOVE; + // a_f_LAM_ALEF_HAMZA_BELOW; switch (cur_c) { - case a_HAMZA: /* exception */ + case a_HAMZA: // exception tempc = a_s_HAMZA; break; @@ -798,7 +769,7 @@ static int chg_c_a2f(int cur_c) tempc = a_f_GHAIN; break; - case a_TATWEEL: /* exception */ + case a_TATWEEL: // exception tempc = cur_c; break; @@ -849,9 +820,7 @@ static int chg_c_a2f(int cur_c) return tempc; } -/* - * Change shape - from Initial to Medial - */ +// Change shape - from Initial to Medial static int chg_c_i2m(int cur_c) { int tempc; @@ -956,24 +925,21 @@ static int chg_c_i2m(int cur_c) return tempc; } -/* - * Change shape - from Final to Medial - */ +// Change shape - from Final to Medial static int chg_c_f2m(int cur_c) { int tempc; switch (cur_c) { - /* NOTE: these encodings are multi-positional, no ? - case a_f_ALEF_MADDA: - case a_f_ALEF_HAMZA_ABOVE: - case a_f_ALEF_HAMZA_BELOW: - */ + // NOTE: these encodings are multi-positional, no ? + // case a_f_ALEF_MADDA: + // case a_f_ALEF_HAMZA_ABOVE: + // case a_f_ALEF_HAMZA_BELOW: case a_f_YEH_HAMZA: tempc = a_m_YEH_HAMZA; break; - case a_f_WAW_HAMZA: /* exceptions */ + case a_f_WAW_HAMZA: // exceptions case a_f_ALEF: case a_f_TEH_MARBUTA: case a_f_DAL: diff --git a/src/arabic.h b/src/arabic.h index 80b9563275..9743e8a935 100644 --- a/src/arabic.h +++ b/src/arabic.h @@ -1,37 +1,20 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - */ +/// @file arabic.h +/// +/// Arabic characters are categorized into following types: +/// +/// Isolated - iso-8859-6 form char denoted with a_* +/// Initial - unicode form-B start char denoted with a_i_* +/// Medial - unicode form-B middle char denoted with a_m_* +/// Final - unicode form-B final char denoted with a_f_* +/// Stand-Alone - unicode form-B isolated char denoted with a_s_* (NOT USED) +/// -#ifndef SRC_ARABIC_H_ -#define SRC_ARABIC_H_ +#ifndef NEOVIM_ARABIC_H +#define NEOVIM_ARABIC_H -/* - * Arabic characters are categorized into following types: - * - * Isolated - iso-8859-6 form char denoted with a_* - * Initial - unicode form-B start char denoted with a_i_* - * Medial - unicode form-B middle char denoted with a_m_* - * Final - unicode form-B final char denoted with a_f_* - * Stand-Alone - unicode form-B isolated char denoted with a_s_* (NOT USED) - * - * -- - * - * Author: Nadim Shaikli & Isam Bayazidi - * - (based on Unicode) - * - */ +// Arabic ISO-10646-1 character set definition -/* - * Arabic ISO-10646-1 character set definition - */ - -/* - * Arabic ISO-8859-6 (subset of 10646; 0600 - 06FF) - */ +// Arabic ISO-8859-6 (subset of 10646; 0600 - 06FF) #define a_COMMA 0x060C #define a_SEMICOLON 0x061B #define a_QUESTION 0x061F @@ -101,17 +84,15 @@ #define a_THOUSANDS 0x066c #define a_STAR 0x066d #define a_MINI_ALEF 0x0670 -/* Rest of 8859-6 does not relate to Arabic */ +// Rest of 8859-6 does not relate to Arabic -/* - * Arabic Presentation Form-B (subset of 10646; FE70 - FEFF) - * - * s -> isolated - * i -> initial - * m -> medial - * f -> final - * - */ +// Arabic Presentation Form-B (subset of 10646; FE70 - FEFF) +// +// s -> isolated +// i -> initial +// m -> medial +// f -> final +// #define a_s_FATHATAN 0xfe70 #define a_m_TATWEEL_FATHATAN 0xfe71 #define a_s_DAMMATAN 0xfe72 @@ -257,7 +238,7 @@ #define a_BYTE_ORDER_MARK 0xfeff -/* Range of Arabic characters that might be shaped. */ +// Range of Arabic characters that might be shaped. #define ARABIC_CHAR(c) ((c) >= a_HAMZA && (c) <= a_MINI_ALEF) -#endif // SRC_ARABIC_H_ +#endif // NEOVIM_ARABIC_H diff --git a/src/blowfish.c b/src/blowfish.c index f032389ba4..77b2f43c95 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -16,11 +16,11 @@ #include "message.h" #include "sha256.h" -#define ARRAY_LENGTH(A) (sizeof(A)/sizeof(A[0])) +#define ARRAY_LENGTH(A) (sizeof(A) / sizeof(A[0])) #define BF_BLOCK 8 #define BF_BLOCK_MASK 7 -#define BF_OFB_LEN (8*(BF_BLOCK)) +#define BF_OFB_LEN (8 * (BF_BLOCK)) typedef union { uint32_t ul[2]; @@ -305,7 +305,6 @@ static uint32_t sbi[4][256] = { 0xb74e6132u, 0xce77e25bu, 0x578fdfe3u, 0x3ac372e6u} }; - #define F1(i) \ xl ^= pax[i]; \ xr ^= ((sbx[0][xl >> 24] + \ @@ -323,7 +322,9 @@ static uint32_t sbi[4][256] = { static void bf_e_block(uint32_t *p_xl, uint32_t *p_xr) { - uint32_t temp, xl = *p_xl, xr = *p_xr; + uint32_t temp; + uint32_t xl = *p_xl; + uint32_t xr = *p_xr; F1(0) F2(1) F1(2) F2(3) F1(4) F2(5) F1(6) F2(7) F1(8) F2(9) F1(10) F2(11) F1(12) F2(13) F1(14) F2(15) @@ -336,15 +337,13 @@ static void bf_e_block(uint32_t *p_xl, uint32_t *p_xr) *p_xr = xr; } - - #ifdef WORDS_BIGENDIAN # define htonl2(x) \ - x = ((((x) & 0xffL) << 24) | (((x) & 0xff00L) << 8) | \ + x = ((((x) & 0xffL) << 24) | (((x) & 0xff00L) << 8) | \ (((x) & 0xff0000L) >> 8) | (((x) & 0xff000000L) >> 24)) -#else +#else // ifdef WORDS_BIGENDIAN # define htonl2(x) -#endif +#endif // ifdef WORDS_BIGENDIAN static void bf_e_cblock(char_u *block) { @@ -359,31 +358,28 @@ static void bf_e_cblock(char_u *block) memcpy(block, bk.uc, 8); } - -/* - * Initialize the crypt method using "password" as the encryption key and - * "salt[salt_len]" as the salt. - */ +// Initialize the crypt method using "password" as the encryption key and +// "salt[salt_len]" as the salt. void bf_key_init(char_u *password, char_u *salt, int salt_len) { - int i, j, keypos = 0; - unsigned u; - uint32_t val, data_l, data_r; - char_u *key; - int keylen; - - /* Process the key 1000 times. - * See http://en.wikipedia.org/wiki/Key_strengthening. */ - key = sha256_key(password, salt, salt_len); - for (i = 0; i < 1000; i++) + // Process the key 1000 times. + // See http://en.wikipedia.org/wiki/Key_strengthening. + char_u *key = sha256_key(password, salt, salt_len); + + int i; + for (i = 0; i < 1000; i++) { key = sha256_key(key, salt, salt_len); + } + + // Convert the key from 64 hex chars to 32 binary chars. + int keylen = (int)STRLEN(key) / 2; - /* Convert the key from 64 hex chars to 32 binary chars. */ - keylen = (int)STRLEN(key) / 2; if (keylen == 0) { EMSG(_("E831: bf_key_init() called with empty password")); return; } + + unsigned u; for (i = 0; i < keylen; i++) { sscanf((char *)&key[i * 2], "%2x", &u); key[i] = u; @@ -391,21 +387,27 @@ void bf_key_init(char_u *password, char_u *salt, int salt_len) mch_memmove(sbx, sbi, 4 * 4 * 256); - for (i = 0; i < 18; ++i) { - val = 0; - for (j = 0; j < 4; ++j) + int keypos = 0; + for (i = 0; i < 18; i++) { + uint32_t val = 0; + + int j; + for (j = 0; j < 4; j++) { val = (val << 8) | key[keypos++ % keylen]; + } pax[i] = ipa[i] ^ val; } - data_l = data_r = 0; + uint32_t data_l = 0; + uint32_t data_r = 0; for (i = 0; i < 18; i += 2) { bf_e_block(&data_l, &data_r); pax[i + 0] = data_l; pax[i + 1] = data_r; } - for (i = 0; i < 4; ++i) { + for (i = 0; i < 4; i++) { + int j; for (j = 0; j < 256; j += 2) { bf_e_block(&data_l, &data_r); sbx[i][j + 0] = data_l; @@ -414,19 +416,22 @@ void bf_key_init(char_u *password, char_u *salt, int salt_len) } } -/* - * BF Self test for corrupted tables or instructions - */ -static int bf_check_tables(uint32_t a_ipa[18], uint32_t a_sbi[4][256], uint32_t val) +/// BF Self test for corrupted tables or instructions +static int bf_check_tables(uint32_t a_ipa[18], uint32_t a_sbi[4][256], + uint32_t val) { - int i, j; uint32_t c = 0; - - for (i = 0; i < 18; i++) + int i; + for (i = 0; i < 18; i++) { c ^= a_ipa[i]; - for (i = 0; i < 4; i++) - for (j = 0; j < 256; j++) + } + + for (i = 0; i < 4; i++) { + int j; + for (j = 0; j < 256; j++) { c ^= a_sbi[i][j]; + } + } return c == val; } @@ -435,50 +440,50 @@ typedef struct { char_u salt[9]; char_u plaintxt[9]; char_u cryptxt[9]; - char_u badcryptxt[9]; /* cryptxt when big/little endian is wrong */ + char_u badcryptxt[9]; // cryptxt when big/little endian is wrong. uint32_t keysum; } struct_bf_test_data; -/* - * Assert bf(password, plaintxt) is cryptxt. - * Assert csum(pax sbx(password)) is keysum. - */ +// Assert bf(password, plaintxt) is cryptxt. +// Assert csum(pax sbx(password)) is keysum. static struct_bf_test_data bf_test_data[] = { { "password", "salt", "plaintxt", - "\xad\x3d\xfa\x7f\xe8\xea\x40\xf6", /* cryptxt */ - "\x72\x50\x3b\x38\x10\x60\x22\xa7", /* badcryptxt */ - 0x56701b5du /* keysum */ + "\xad\x3d\xfa\x7f\xe8\xea\x40\xf6", // cryptxt + "\x72\x50\x3b\x38\x10\x60\x22\xa7", // badcryptxt + 0x56701b5du // keysum }, }; -/* - * Return FAIL when there is something wrong with blowfish encryption. - */ -static int bf_self_test(void) { - int i, bn; +// Return FAIL when there is something wrong with blowfish encryption. +static int bf_self_test(void) +{ int err = 0; - block8 bk; - - if (!bf_check_tables(ipa, sbi, 0x6ffa520a)) + if (!bf_check_tables(ipa, sbi, 0x6ffa520a)) { err++; + } - bn = ARRAY_LENGTH(bf_test_data); + int bn = ARRAY_LENGTH(bf_test_data); + int i; for (i = 0; i < bn; i++) { - bf_key_init((char_u *)(bf_test_data[i].password), - bf_test_data[i].salt, - (int)STRLEN(bf_test_data[i].salt)); - if (!bf_check_tables(pax, sbx, bf_test_data[i].keysum)) + bf_key_init((char_u *)(bf_test_data[i].password), bf_test_data[i].salt, + (int)STRLEN(bf_test_data[i].salt)); + + if (!bf_check_tables(pax, sbx, bf_test_data[i].keysum)) { err++; + } - /* Don't modify bf_test_data[i].plaintxt, self test is idempotent. */ + // Don't modify bf_test_data[i].plaintxt, self test is idempotent. + block8 bk; memcpy(bk.uc, bf_test_data[i].plaintxt, 8); bf_e_cblock(bk.uc); + if (memcmp(bk.uc, bf_test_data[i].cryptxt, 8) != 0) { - if (err == 0 && memcmp(bk.uc, bf_test_data[i].badcryptxt, 8) == 0) + if ((err == 0) && (memcmp(bk.uc, bf_test_data[i].badcryptxt, 8) == 0)) { EMSG(_("E817: Blowfish big/little endian use wrong")); + } err++; } } @@ -486,52 +491,51 @@ static int bf_self_test(void) { return err > 0 ? FAIL : OK; } -/* Output feedback mode. */ +// Output feedback mode. static int randbyte_offset = 0; static int update_offset = 0; -static char_u ofb_buffer[BF_OFB_LEN]; /* 64 bytes */ +static char_u ofb_buffer[BF_OFB_LEN]; // 64 bytes -/* - * Initialize with seed "iv[iv_len]". - */ +// Initialize with seed "iv[iv_len]". void bf_ofb_init(char_u *iv, int iv_len) { - int i, mi; - randbyte_offset = update_offset = 0; vim_memset(ofb_buffer, 0, BF_OFB_LEN); + if (iv_len > 0) { - mi = iv_len > BF_OFB_LEN ? iv_len : BF_OFB_LEN; - for (i = 0; i < mi; i++) + int mi = iv_len > BF_OFB_LEN ? iv_len : BF_OFB_LEN; + int i; + for (i = 0; i < mi; i++) { ofb_buffer[i % BF_OFB_LEN] ^= iv[i % iv_len]; + } } } #define BF_OFB_UPDATE(c) { \ - ofb_buffer[update_offset] ^= (char_u)c; \ - if (++update_offset == BF_OFB_LEN) \ - update_offset = 0; \ + ofb_buffer[update_offset] ^= (char_u)c; \ + if (++update_offset == BF_OFB_LEN) { \ + update_offset = 0; \ + } \ } #define BF_RANBYTE(t) { \ - if ((randbyte_offset & BF_BLOCK_MASK) == 0) \ - bf_e_cblock(&ofb_buffer[randbyte_offset]); \ - t = ofb_buffer[randbyte_offset]; \ - if (++randbyte_offset == BF_OFB_LEN) \ - randbyte_offset = 0; \ + if ((randbyte_offset & BF_BLOCK_MASK) == 0) { \ + bf_e_cblock(&ofb_buffer[randbyte_offset]); \ + } \ + t = ofb_buffer[randbyte_offset]; \ + if (++randbyte_offset == BF_OFB_LEN) { \ + randbyte_offset = 0; \ + } \ } -/* - * Encrypt "from[len]" into "to[len]". - * "from" and "to" can be equal to encrypt in place. - */ +// Encrypt "from[len]" into "to[len]". +// "from" and "to" can be equal to encrypt in place. void bf_crypt_encode(char_u *from, size_t len, char_u *to) { size_t i; - int ztemp, t; - - for (i = 0; i < len; ++i) { - ztemp = from[i]; + for (i = 0; i < len; i++) { + int ztemp = from[i]; + int t; BF_RANBYTE(t); BF_OFB_UPDATE(ztemp); to[i] = t ^ ztemp; @@ -543,10 +547,9 @@ void bf_crypt_encode(char_u *from, size_t len, char_u *to) */ void bf_crypt_decode(char_u *ptr, long len) { - char_u *p; - int t; - - for (p = ptr; p < ptr + len; ++p) { + char_u *p; + for (p = ptr; p < ptr + len; p++) { + int t; BF_RANBYTE(t); *p ^= t; BF_OFB_UPDATE(*p); @@ -556,15 +559,12 @@ void bf_crypt_decode(char_u *ptr, long len) /* * Initialize the encryption keys and the random header according to * the given password. + * in: "passwd" password string with which to modify keys */ -void -bf_crypt_init_keys ( - char_u *passwd /* password string with which to modify keys */ -) +void bf_crypt_init_keys(char_u *passwd) { char_u *p; - - for (p = passwd; *p != NUL; ++p) { + for (p = passwd; *p != NUL; p++) { BF_OFB_UPDATE(*p); } } @@ -579,7 +579,8 @@ static uint32_t save_sbx[4][256]; * Save the current crypt state. Can only be used once before * bf_crypt_restore(). */ -void bf_crypt_save(void) { +void bf_crypt_save(void) +{ save_randbyte_offset = randbyte_offset; save_update_offset = update_offset; mch_memmove(save_ofb_buffer, ofb_buffer, BF_OFB_LEN); @@ -591,7 +592,8 @@ void bf_crypt_save(void) { * Restore the current crypt state. Can only be used after * bf_crypt_save(). */ -void bf_crypt_restore(void) { +void bf_crypt_restore(void) +{ randbyte_offset = save_randbyte_offset; update_offset = save_update_offset; mch_memmove(ofb_buffer, save_ofb_buffer, BF_OFB_LEN); @@ -603,7 +605,8 @@ void bf_crypt_restore(void) { * Run a test to check if the encryption works as expected. * Give an error and return FAIL when not. */ -int blowfish_self_test(void) { +int blowfish_self_test(void) +{ if (sha256_self_test() == FAIL) { EMSG(_("E818: sha256 test failed")); return FAIL; @@ -614,4 +617,3 @@ int blowfish_self_test(void) { } return OK; } - diff --git a/src/blowfish.h b/src/blowfish.h index 747f469349..cb0363e186 100644 --- a/src/blowfish.h +++ b/src/blowfish.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_BLOWFISH_H #define NEOVIM_BLOWFISH_H -/* blowfish.c */ + void bf_key_init(char_u *password, char_u *salt, int salt_len); void bf_ofb_init(char_u *iv, int iv_len); void bf_crypt_encode(char_u *from, size_t len, char_u *to); @@ -9,5 +9,6 @@ void bf_crypt_init_keys(char_u *passwd); void bf_crypt_save(void); void bf_crypt_restore(void); int blowfish_self_test(void); -/* vim: set ft=c : */ -#endif /* NEOVIM_BLOWFISH_H */ + +// vim: set ft=c: +#endif // NEOVIM_BLOWFISH_H diff --git a/src/charset.c b/src/charset.c index 3f609801a2..28dacf1a15 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1,11 +1,6 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ +/// @file charset.c +/// +/// Code related to character sets. #include "vim.h" #include "charset.h" @@ -20,9 +15,9 @@ static int win_chartabsize(win_T *wp, char_u *p, colnr_T col); -# if defined(HAVE_WCHAR_H) -# include <wchar.h> /* for towupper() and towlower() */ -# endif +#if defined(HAVE_WCHAR_H) +# include <wchar.h> // for towupper() and towlower() +#endif // if defined(HAVE_WCHAR_H) static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); @@ -30,212 +25,241 @@ static unsigned nr2hex(unsigned c); static int chartab_initialized = FALSE; -/* b_chartab[] is an array of 32 bytes, each bit representing one of the - * characters 0-255. */ -#define SET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> \ - 3] |= (1 << ((c) & 0x7)) -#define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> \ - 3] &= ~(1 << ((c) & 0x7)) -#define GET_CHARTAB(buf, \ - c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) - -/* - * Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword - * characters for current buffer. - * - * Depends on the option settings 'iskeyword', 'isident', 'isfname', - * 'isprint' and 'encoding'. - * - * The index in chartab[] depends on 'encoding': - * - For non-multi-byte index with the byte (same as the character). - * - For DBCS index with the first byte. - * - For UTF-8 index with the character (when first byte is up to 0x80 it is - * the same as the character, if the first byte is 0x80 and above it depends - * on further bytes). - * - * The contents of chartab[]: - * - The lower two bits, masked by CT_CELL_MASK, give the number of display - * cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80. - * - CT_PRINT_CHAR bit is set when the character is printable (no need to - * translate the character before displaying it). Note that only DBCS - * characters can have 2 display cells and still be printable. - * - CT_FNAME_CHAR bit is set when the character can be in a file name. - * - CT_ID_CHAR bit is set when the character can be in an identifier. - * - * Return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has an - * error, OK otherwise. - */ -int init_chartab(void) { +// b_chartab[] is an array of 32 bytes, each bit representing one of the +// characters 0-255. +#define SET_CHARTAB(buf, c) \ + (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7)) +#define RESET_CHARTAB(buf, c) \ + (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7)) +#define GET_CHARTAB(buf, c) \ + ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) + +/// Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword +/// characters for current buffer. +/// +/// Depends on the option settings 'iskeyword', 'isident', 'isfname', +/// 'isprint' and 'encoding'. +/// +/// The index in chartab[] depends on 'encoding': +/// - For non-multi-byte index with the byte (same as the character). +/// - For DBCS index with the first byte. +/// - For UTF-8 index with the character (when first byte is up to 0x80 it is +/// the same as the character, if the first byte is 0x80 and above it depends +/// on further bytes). +/// +/// The contents of chartab[]: +/// - The lower two bits, masked by CT_CELL_MASK, give the number of display +/// cells the character occupies (1 or 2). Not valid for UTF-8 above 0x80. +/// - CT_PRINT_CHAR bit is set when the character is printable (no need to +/// translate the character before displaying it). Note that only DBCS +/// characters can have 2 display cells and still be printable. +/// - CT_FNAME_CHAR bit is set when the character can be in a file name. +/// - CT_ID_CHAR bit is set when the character can be in an identifier. +/// +/// @return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has +/// an error, OK otherwise. +int init_chartab(void) +{ return buf_init_chartab(curbuf, TRUE); } -int -buf_init_chartab ( - buf_T *buf, - int global /* FALSE: only set buf->b_chartab[] */ -) +/// Helper for init_chartab +/// +/// @param global FALSE: only set buf->b_chartab[] +/// +/// @return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has +/// an error, OK otherwise. +int buf_init_chartab(buf_T *buf, int global) { int c; int c2; - char_u *p; + char_u *p; int i; int tilde; int do_isalpha; if (global) { - /* - * Set the default size for printable characters: - * From <Space> to '~' is 1 (printable), others are 2 (not printable). - * This also inits all 'isident' and 'isfname' flags to FALSE. - * - * EBCDIC: all chars below ' ' are not printable, all others are - * printable. - */ + // Set the default size for printable characters: + // From <Space> to '~' is 1 (printable), others are 2 (not printable). + // This also inits all 'isident' and 'isfname' flags to FALSE. + // + // EBCDIC: all chars below ' ' are not printable, all others are + // printable. c = 0; - while (c < ' ') + + while (c < ' ') { chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; - while (c <= '~') + } + + while (c <= '~') { chartab[c++] = 1 + CT_PRINT_CHAR; + } + if (p_altkeymap) { - while (c < YE) + while (c < YE) { chartab[c++] = 1 + CT_PRINT_CHAR; + } } + while (c < 256) { - /* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */ - if (enc_utf8 && c >= 0xa0) + if (enc_utf8 && (c >= 0xa0)) { + // UTF-8: bytes 0xa0 - 0xff are printable (latin1) chartab[c++] = CT_PRINT_CHAR + 1; - /* euc-jp characters starting with 0x8e are single width */ - else if (enc_dbcs == DBCS_JPNU && c == 0x8e) + } else if ((enc_dbcs == DBCS_JPNU) && (c == 0x8e)) { + // euc-jp characters starting with 0x8e are single width chartab[c++] = CT_PRINT_CHAR + 1; - /* other double-byte chars can be printable AND double-width */ - else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2) + } else if ((enc_dbcs != 0) && (MB_BYTE2LEN(c) == 2)) { + // other double-byte chars can be printable AND double-width chartab[c++] = CT_PRINT_CHAR + 2; - else - /* the rest is unprintable by default */ + } else { + // the rest is unprintable by default chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; + } } - /* Assume that every multi-byte char is a filename character. */ - for (c = 1; c < 256; ++c) - if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1) - || (enc_dbcs == DBCS_JPNU && c == 0x8e) - || (enc_utf8 && c >= 0xa0)) + // Assume that every multi-byte char is a filename character. + for (c = 1; c < 256; ++c) { + if (((enc_dbcs != 0) && (MB_BYTE2LEN(c) > 1)) + || ((enc_dbcs == DBCS_JPNU) && (c == 0x8e)) + || (enc_utf8 && (c >= 0xa0))) { chartab[c] |= CT_FNAME_CHAR; + } + } } - /* - * Init word char flags all to FALSE - */ + // Init word char flags all to FALSE vim_memset(buf->b_chartab, 0, (size_t)32); - if (enc_dbcs != 0) + + if (enc_dbcs != 0) { for (c = 0; c < 256; ++c) { - /* double-byte characters are probably word characters */ - if (MB_BYTE2LEN(c) == 2) + // double-byte characters are probably word characters + if (MB_BYTE2LEN(c) == 2) { SET_CHARTAB(buf, c); + } } + } - /* - * In lisp mode the '-' character is included in keywords. - */ - if (buf->b_p_lisp) + // In lisp mode the '-' character is included in keywords. + if (buf->b_p_lisp) { SET_CHARTAB(buf, '-'); + } - /* Walk through the 'isident', 'iskeyword', 'isfname' and 'isprint' - * options Each option is a list of characters, character numbers or - * ranges, separated by commas, e.g.: "200-210,x,#-178,-" - */ + // Walk through the 'isident', 'iskeyword', 'isfname' and 'isprint' + // options Each option is a list of characters, character numbers or + // ranges, separated by commas, e.g.: "200-210,x,#-178,-" for (i = global ? 0 : 3; i <= 3; ++i) { - if (i == 0) - p = p_isi; /* first round: 'isident' */ - else if (i == 1) - p = p_isp; /* second round: 'isprint' */ - else if (i == 2) - p = p_isf; /* third round: 'isfname' */ - else /* i == 3 */ - p = buf->b_p_isk; /* fourth round: 'iskeyword' */ + if (i == 0) { + // first round: 'isident' + p = p_isi; + } else if (i == 1) { + // second round: 'isprint' + p = p_isp; + } else if (i == 2) { + // third round: 'isfname' + p = p_isf; + } else { // i == 3 + // fourth round: 'iskeyword' + p = buf->b_p_isk; + } while (*p) { tilde = FALSE; do_isalpha = FALSE; - if (*p == '^' && p[1] != NUL) { + + if ((*p == '^') && (p[1] != NUL)) { tilde = TRUE; ++p; } - if (VIM_ISDIGIT(*p)) + + if (VIM_ISDIGIT(*p)) { c = getdigits(&p); - else if (has_mbyte) + } else if (has_mbyte) { c = mb_ptr2char_adv(&p); - else + } else { c = *p++; + } c2 = -1; - if (*p == '-' && p[1] != NUL) { + + if ((*p == '-') && (p[1] != NUL)) { ++p; - if (VIM_ISDIGIT(*p)) + + if (VIM_ISDIGIT(*p)) { c2 = getdigits(&p); - else if (has_mbyte) + } else if (has_mbyte) { c2 = mb_ptr2char_adv(&p); - else + } else { c2 = *p++; + } } - if (c <= 0 || c >= 256 || (c2 < c && c2 != -1) || c2 >= 256 - || !(*p == NUL || *p == ',')) + + if ((c <= 0) + || (c >= 256) + || ((c2 < c) && (c2 != -1)) + || (c2 >= 256) + || !((*p == NUL) || (*p == ','))) { return FAIL; + } - if (c2 == -1) { /* not a range */ - /* - * A single '@' (not "@-@"): - * Decide on letters being ID/printable/keyword chars with - * standard function isalpha(). This takes care of locale for - * single-byte characters). - */ + if (c2 == -1) { // not a range + // A single '@' (not "@-@"): + // Decide on letters being ID/printable/keyword chars with + // standard function isalpha(). This takes care of locale for + // single-byte characters). if (c == '@') { do_isalpha = TRUE; c = 1; c2 = 255; - } else + } else { c2 = c; + } } + while (c <= c2) { - /* Use the MB_ functions here, because isalpha() doesn't - * work properly when 'encoding' is "latin1" and the locale is - * "C". */ - if (!do_isalpha || MB_ISLOWER(c) || MB_ISUPPER(c) - || (p_altkeymap && (F_isalpha(c) || F_isdigit(c))) - ) { - if (i == 0) { /* (re)set ID flag */ - if (tilde) + // Use the MB_ functions here, because isalpha() doesn't + // work properly when 'encoding' is "latin1" and the locale is + // "C". + if (!do_isalpha + || MB_ISLOWER(c) + || MB_ISUPPER(c) + || (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))) { + if (i == 0) { + // (re)set ID flag + if (tilde) { chartab[c] &= ~CT_ID_CHAR; - else + } else { chartab[c] |= CT_ID_CHAR; - } else if (i == 1) { /* (re)set printable */ - if ((c < ' ' - || c > '~' - || (p_altkeymap - && (F_isalpha(c) || F_isdigit(c))) - ) - /* For double-byte we keep the cell width, so - * that we can detect it from the first byte. */ - && !(enc_dbcs && MB_BYTE2LEN(c) == 2) - ) { + } + } else if (i == 1) { + // (re)set printable + // For double-byte we keep the cell width, so + // that we can detect it from the first byte. + if (((c < ' ') + || (c > '~') + || (p_altkeymap && (F_isalpha(c) || F_isdigit(c)))) + && !(enc_dbcs && (MB_BYTE2LEN(c) == 2))) { if (tilde) { chartab[c] = (chartab[c] & ~CT_CELL_MASK) + ((dy_flags & DY_UHEX) ? 4 : 2); chartab[c] &= ~CT_PRINT_CHAR; - } else { + } else { chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1; chartab[c] |= CT_PRINT_CHAR; } } - } else if (i == 2) { /* (re)set fname flag */ - if (tilde) + } else if (i == 2) { + // (re)set fname flag + if (tilde) { chartab[c] &= ~CT_FNAME_CHAR; - else + } else { chartab[c] |= CT_FNAME_CHAR; - } else { /* i == 3 */ /* (re)set keyword flag */ - if (tilde) + } + } else { // i == 3 + // (re)set keyword flag + if (tilde) { RESET_CHARTAB(buf, c); - else + } else { SET_CHARTAB(buf, c); + } } } ++c; @@ -243,40 +267,47 @@ buf_init_chartab ( c = *p; p = skip_to_option_part(p); - if (c == ',' && *p == NUL) - /* Trailing comma is not allowed. */ + + if ((c == ',') && (*p == NUL)) { + // Trailing comma is not allowed. return FAIL; + } } } chartab_initialized = TRUE; return OK; } -/* - * Translate any special characters in buf[bufsize] in-place. - * The result is a string with only printable characters, but if there is not - * enough room, not all characters will be translated. - */ +/// Translate any special characters in buf[bufsize] in-place. +/// +/// The result is a string with only printable characters, but if there is not +/// enough room, not all characters will be translated. +/// +/// @param buf +/// @param bufsize void trans_characters(char_u *buf, int bufsize) { - int len; /* length of string needing translation */ - int room; /* room in buffer after string */ - char_u *trs; /* translated character */ - int trs_len; /* length of trs[] */ + int len; // length of string needing translation + int room; // room in buffer after string + char_u *trs; // translated character + int trs_len; // length of trs[] len = (int)STRLEN(buf); room = bufsize - len; + while (*buf != 0) { - /* Assume a multi-byte character doesn't need translation. */ - if (has_mbyte && (trs_len = (*mb_ptr2len)(buf)) > 1) + // Assume a multi-byte character doesn't need translation. + if (has_mbyte && ((trs_len = (*mb_ptr2len)(buf)) > 1)) { len -= trs_len; - else { + } else { trs = transchar_byte(*buf); trs_len = (int)STRLEN(trs); + if (trs_len > 1) { room -= trs_len - 1; - if (room <= 0) + if (room <= 0) { return; + } mch_memmove(buf + trs_len, buf + 1, (size_t)len); } mch_memmove(buf, trs, (size_t)trs_len); @@ -286,130 +317,162 @@ void trans_characters(char_u *buf, int bufsize) } } -#if defined(FEAT_EVAL) || defined(FEAT_TITLE) || defined(FEAT_INS_EXPAND) \ +#if defined(FEAT_EVAL) \ + || defined(FEAT_TITLE) \ + || defined(FEAT_INS_EXPAND) \ || defined(PROTO) -/* - * Translate a string into allocated memory, replacing special chars with - * printable chars. Returns NULL when out of memory. - */ + +/// Translate a string into allocated memory, replacing special chars with +/// printable chars. Returns NULL when out of memory. +/// +/// @param s +/// +/// @return translated string or NULL if out of memory. char_u *transstr(char_u *s) { - char_u *res; - char_u *p; + char_u *res; + char_u *p; int l, len, c; char_u hexbuf[11]; if (has_mbyte) { - /* Compute the length of the result, taking account of unprintable - * multi-byte characters. */ + // Compute the length of the result, taking account of unprintable + // multi-byte characters. len = 0; p = s; + while (*p != NUL) { if ((l = (*mb_ptr2len)(p)) > 1) { c = (*mb_ptr2char)(p); p += l; - if (vim_isprintc(c)) + + if (vim_isprintc(c)) { len += l; - else { + } else { transchar_hex(hexbuf, c); len += (int)STRLEN(hexbuf); } } else { l = byte2cells(*p++); - if (l > 0) + + if (l > 0) { len += l; - else - len += 4; /* illegal byte sequence */ + } else { + // illegal byte sequence + len += 4; + } } } res = alloc((unsigned)(len + 1)); - } else + } else { res = alloc((unsigned)(vim_strsize(s) + 1)); + } + if (res != NULL) { *res = NUL; p = s; + while (*p != NUL) { - if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) { + if (has_mbyte && ((l = (*mb_ptr2len)(p)) > 1)) { c = (*mb_ptr2char)(p); - if (vim_isprintc(c)) - STRNCAT(res, p, l); /* append printable multi-byte char */ - else + + if (vim_isprintc(c)) { + // append printable multi-byte char + STRNCAT(res, p, l); + } else { transchar_hex(res + STRLEN(res), c); + } p += l; - } else + } else { STRCAT(res, transchar_byte(*p++)); + } } } return res; } -#endif - -/* - * Convert the string "str[orglen]" to do ignore-case comparing. Uses the - * current locale. - * When "buf" is NULL returns an allocated string (NULL for out-of-memory). - * Otherwise puts the result in "buf[buflen]". - */ -char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) + +#endif // if defined(FEAT_EVAL) || defined(FEAT_TITLE) + // || defined(FEAT_INS_EXPAND) || defined(PROTO) + +/// Convert the string "str[orglen]" to do ignore-case comparing. Uses the +/// current locale. +/// +/// When "buf" is NULL returns an allocated string (NULL for out-of-memory). +/// Otherwise puts the result in "buf[buflen]". +/// +/// @param str +/// @param orglen +/// @param buf +/// @param buflen +/// +/// @return converted string. +char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) { garray_T ga; int i; int len = orglen; -#define GA_CHAR(i) ((char_u *)ga.ga_data)[i] -#define GA_PTR(i) ((char_u *)ga.ga_data + i) -#define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) -#define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + i) +#define GA_CHAR(i) ((char_u *)ga.ga_data)[i] +#define GA_PTR(i) ((char_u *)ga.ga_data + i) +#define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) +#define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + i) - /* Copy "str" into "buf" or allocated memory, unmodified. */ + // Copy "str" into "buf" or allocated memory, unmodified. if (buf == NULL) { ga_init2(&ga, 1, 10); - if (ga_grow(&ga, len + 1) == FAIL) + + if (ga_grow(&ga, len + 1) == FAIL) { return NULL; + } mch_memmove(ga.ga_data, str, (size_t)len); ga.ga_len = len; - } else { - if (len >= buflen) /* Ugly! */ + } else { + if (len >= buflen) { + // Ugly! len = buflen - 1; + } mch_memmove(buf, str, (size_t)len); } - if (buf == NULL) + + if (buf == NULL) { GA_CHAR(len) = NUL; - else + } else { buf[len] = NUL; + } - /* Make each character lower case. */ + // Make each character lower case. i = 0; while (STR_CHAR(i) != NUL) { - if (enc_utf8 || (has_mbyte && MB_BYTE2LEN(STR_CHAR(i)) > 1)) { + if (enc_utf8 || (has_mbyte && (MB_BYTE2LEN(STR_CHAR(i)) > 1))) { if (enc_utf8) { int c = utf_ptr2char(STR_PTR(i)); int olen = utf_ptr2len(STR_PTR(i)); int lc = utf_tolower(c); - /* Only replace the character when it is not an invalid - * sequence (ASCII character or more than one byte) and - * utf_tolower() doesn't return the original character. */ - if ((c < 0x80 || olen > 1) && c != lc) { + // Only replace the character when it is not an invalid + // sequence (ASCII character or more than one byte) and + // utf_tolower() doesn't return the original character. + if (((c < 0x80) || (olen > 1)) && (c != lc)) { int nlen = utf_char2len(lc); - /* If the byte length changes need to shift the following - * characters forward or backward. */ + // If the byte length changes need to shift the following + // characters forward or backward. if (olen != nlen) { if (nlen > olen) { - if (buf == NULL - ? ga_grow(&ga, nlen - olen + 1) == FAIL - : len + nlen - olen >= buflen) { - /* out of memory, keep old char */ + if ((buf == NULL) + ? (ga_grow(&ga, nlen - olen + 1) == FAIL) + : (len + nlen - olen >= buflen)) { + // out of memory, keep old char lc = c; nlen = olen; } } + if (olen != nlen) { if (buf == NULL) { STRMOVE(GA_PTR(i) + nlen, GA_PTR(i) + olen); ga.ga_len += nlen - olen; - } else { + } else { STRMOVE(buf + i + nlen, buf + i + olen); len += nlen - olen; } @@ -418,106 +481,123 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen) (void)utf_char2bytes(lc, STR_PTR(i)); } } - /* skip to next multi-byte char */ + + // skip to next multi-byte char i += (*mb_ptr2len)(STR_PTR(i)); - } else { - if (buf == NULL) + } else { + if (buf == NULL) { GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i)); - else + } else { buf[i] = TOLOWER_LOC(buf[i]); + } ++i; } } - if (buf == NULL) + if (buf == NULL) { return (char_u *)ga.ga_data; + } return buf; } -/* - * Catch 22: chartab[] can't be initialized before the options are - * initialized, and initializing options may cause transchar() to be called! - * When chartab_initialized == FALSE don't use chartab[]. - * Does NOT work for multi-byte characters, c must be <= 255. - * Also doesn't work for the first byte of a multi-byte, "c" must be a - * character! - */ +// Catch 22: chartab[] can't be initialized before the options are +// initialized, and initializing options may cause transchar() to be called! +// When chartab_initialized == FALSE don't use chartab[]. +// Does NOT work for multi-byte characters, c must be <= 255. +// Also doesn't work for the first byte of a multi-byte, "c" must be a +// character! static char_u transchar_buf[7]; -char_u *transchar(int c) +/// Translates a character +/// +/// @param c +/// +/// @return translated character. +char_u* transchar(int c) { - int i; - - i = 0; - if (IS_SPECIAL(c)) { /* special key code, display as ~@ char */ + int i = 0; + if (IS_SPECIAL(c)) { + // special key code, display as ~@ char transchar_buf[0] = '~'; transchar_buf[1] = '@'; i = 2; c = K_SECOND(c); } - if ((!chartab_initialized && ( - (c >= ' ' && c <= '~') - || F_ischar(c) - )) || (c < 256 && vim_isprintc_strict(c))) { - /* printable character */ + if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || F_ischar(c))) + || ((c < 256) && vim_isprintc_strict(c))) { + // printable character transchar_buf[i] = c; transchar_buf[i + 1] = NUL; - } else + } else { transchar_nonprint(transchar_buf + i, c); + } return transchar_buf; } -/* - * Like transchar(), but called with a byte instead of a character. Checks - * for an illegal UTF-8 byte. - */ -char_u *transchar_byte(int c) +/// Like transchar(), but called with a byte instead of a character. Checks +/// for an illegal UTF-8 byte. +/// +/// @param c +/// +/// @return pointer to translated character in transchar_buf. +char_u* transchar_byte(int c) { - if (enc_utf8 && c >= 0x80) { + if (enc_utf8 && (c >= 0x80)) { transchar_nonprint(transchar_buf, c); return transchar_buf; } return transchar(c); } -/* - * Convert non-printable character to two or more printable characters in - * "buf[]". "buf" needs to be able to hold five bytes. - * Does NOT work for multi-byte characters, c must be <= 255. - */ +/// Convert non-printable character to two or more printable characters in +/// "buf[]". "buf" needs to be able to hold five bytes. +/// Does NOT work for multi-byte characters, c must be <= 255. +/// +/// @param buf +/// @param c void transchar_nonprint(char_u *buf, int c) { - if (c == NL) - c = NUL; /* we use newline in place of a NUL */ - else if (c == CAR && get_fileformat(curbuf) == EOL_MAC) - c = NL; /* we use CR in place of NL in this case */ + if (c == NL) { + // we use newline in place of a NUL + c = NUL; + } else if ((c == CAR) && (get_fileformat(curbuf) == EOL_MAC)) { + // we use CR in place of NL in this case + c = NL; + } - if (dy_flags & DY_UHEX) /* 'display' has "uhex" */ + if (dy_flags & DY_UHEX) { + // 'display' has "uhex" transchar_hex(buf, c); - - else if (c <= 0x7f) { /* 0x00 - 0x1f and 0x7f */ + } else if (c <= 0x7f) { + // 0x00 - 0x1f and 0x7f buf[0] = '^'; - buf[1] = c ^ 0x40; /* DEL displayed as ^? */ + // DEL displayed as ^? + buf[1] = c ^ 0x40; buf[2] = NUL; - } else if (enc_utf8 && c >= 0x80) { + } else if (enc_utf8 && (c >= 0x80)) { transchar_hex(buf, c); - } else if (c >= ' ' + 0x80 && c <= '~' + 0x80) { /* 0xa0 - 0xfe */ + } else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) { + // 0xa0 - 0xfe buf[0] = '|'; buf[1] = c - 0x80; buf[2] = NUL; - } else { /* 0x80 - 0x9f and 0xff */ - /* - * TODO: EBCDIC I don't know what to do with this chars, so I display - * them as '~?' for now - */ + } else { + // 0x80 - 0x9f and 0xff + // TODO: EBCDIC I don't know what to do with this chars, so I display + // them as '~?' for now buf[0] = '~'; - buf[1] = (c - 0x80) ^ 0x40; /* 0xff displayed as ~? */ + buf[1] = (c - 0x80) ^ 0x40; + // 0xff displayed as ~? buf[2] = NUL; } } +/// Convert a non-printable character to hex. +/// +/// @param buf +/// @param c void transchar_hex(char_u *buf, int c) { int i = 0; @@ -533,183 +613,229 @@ void transchar_hex(char_u *buf, int c) buf[++i] = NUL; } -/* - * Convert the lower 4 bits of byte "c" to its hex character. - * Lower case letters are used to avoid the confusion of <F1> being 0xf1 or - * function key 1. - */ +/// Convert the lower 4 bits of byte "c" to its hex character. +/// Lower case letters are used to avoid the confusion of <F1> being 0xf1 or +/// function key 1. +/// +/// @param c +/// +/// @return the hex character. static unsigned nr2hex(unsigned c) { - if ((c & 0xf) <= 9) + if ((c & 0xf) <= 9) { return (c & 0xf) + '0'; + } return (c & 0xf) - 10 + 'a'; } -/* - * Return number of display cells occupied by byte "b". - * Caller must make sure 0 <= b <= 255. - * For multi-byte mode "b" must be the first byte of a character. - * A TAB is counted as two cells: "^I". - * For UTF-8 mode this will return 0 for bytes >= 0x80, because the number of - * cells depends on further bytes. - */ +/// Return number of display cells occupied by byte "b". +/// +/// Caller must make sure 0 <= b <= 255. +/// For multi-byte mode "b" must be the first byte of a character. +/// A TAB is counted as two cells: "^I". +/// For UTF-8 mode this will return 0 for bytes >= 0x80, because the number of +/// cells depends on further bytes. +/// +/// @param b +/// +/// @reeturn Number of display cells. int byte2cells(int b) { - if (enc_utf8 && b >= 0x80) + if (enc_utf8 && (b >= 0x80)) { return 0; + } return chartab[b] & CT_CELL_MASK; } -/* - * Return number of display cells occupied by character "c". - * "c" can be a special key (negative number) in which case 3 or 4 is returned. - * A TAB is counted as two cells: "^I" or four: "<09>". - */ +/// Return number of display cells occupied by character "c". +/// +/// "c" can be a special key (negative number) in which case 3 or 4 is returned. +/// A TAB is counted as two cells: "^I" or four: "<09>". +/// +/// @param c +/// +/// @return Number of display cells. int char2cells(int c) { - if (IS_SPECIAL(c)) + if (IS_SPECIAL(c)) { return char2cells(K_SECOND(c)) + 2; + } + if (c >= 0x80) { - /* UTF-8: above 0x80 need to check the value */ - if (enc_utf8) + // UTF-8: above 0x80 need to check the value + if (enc_utf8) { return utf_char2cells(c); - /* DBCS: double-byte means double-width, except for euc-jp with first - * byte 0x8e */ - if (enc_dbcs != 0 && c >= 0x100) { - if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) + } + + // DBCS: double-byte means double-width, except for euc-jp with first + // byte 0x8e + if ((enc_dbcs != 0) && (c >= 0x100)) { + if ((enc_dbcs == DBCS_JPNU) && (((unsigned)c >> 8) == 0x8e)) { return 1; + } return 2; } } return chartab[c & 0xff] & CT_CELL_MASK; } -/* - * Return number of display cells occupied by character at "*p". - * A TAB is counted as two cells: "^I" or four: "<09>". - */ +/// Return number of display cells occupied by character at "*p". +/// A TAB is counted as two cells: "^I" or four: "<09>". +/// +/// @param p +/// +/// @return number of display cells. int ptr2cells(char_u *p) { - /* For UTF-8 we need to look at more bytes if the first byte is >= 0x80. */ - if (enc_utf8 && *p >= 0x80) + // For UTF-8 we need to look at more bytes if the first byte is >= 0x80. + if (enc_utf8 && (*p >= 0x80)) { return utf_ptr2cells(p); - /* For DBCS we can tell the cell count from the first byte. */ + } + + // For DBCS we can tell the cell count from the first byte. return chartab[*p] & CT_CELL_MASK; } -/* - * Return the number of character cells string "s" will take on the screen, - * counting TABs as two characters: "^I". - * - * 's' must be non-null. - */ +/// Return the number of character cells string "s" will take on the screen, +/// counting TABs as two characters: "^I". +/// +/// 's' must be non-null. +/// +/// @param s +/// +/// @return number of character cells. int vim_strsize(char_u *s) { return vim_strnsize(s, (int)MAXCOL); } -/* - * Return the number of character cells string "s[len]" will take on the - * screen, counting TABs as two characters: "^I". - * - * 's' must be non-null. - */ +/// Return the number of character cells string "s[len]" will take on the +/// screen, counting TABs as two characters: "^I". +/// +/// 's' must be non-null. +/// +/// @param s +/// @param len +/// +/// @return Number of character cells. int vim_strnsize(char_u *s, int len) { - assert(s); + assert(s != NULL); int size = 0; - while (*s != NUL && --len >= 0) { if (has_mbyte) { int l = (*mb_ptr2len)(s); - size += ptr2cells(s); s += l; len -= l - 1; - } else + } else { size += byte2cells(*s++); + } } return size; } -/* - * Return the number of characters 'c' will take on the screen, taking - * into account the size of a tab. - * Use a define to make it fast, this is used very often!!! - * Also see getvcol() below. - */ - +/// Return the number of characters 'c' will take on the screen, taking +/// into account the size of a tab. +/// Use a define to make it fast, this is used very often!!! +/// Also see getvcol() below. +/// +/// @param p +/// @param col +/// +/// @return Number of characters. #define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ - if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ - { \ + if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) { \ int ts; \ ts = (buf)->b_p_ts; \ return (int)(ts - (col % ts)); \ - } \ - else \ - return ptr2cells(p); + } else { \ + return ptr2cells(p); \ + } -#if defined(FEAT_VREPLACE) || defined(FEAT_EX_EXTRA) || defined(FEAT_GUI) \ - || defined(FEAT_VIRTUALEDIT) || defined(PROTO) +#if defined(FEAT_VREPLACE) \ + || defined(FEAT_EX_EXTRA) \ + || defined(FEAT_GUI) \ + || defined(FEAT_VIRTUALEDIT) \ + || defined(PROTO) int chartabsize(char_u *p, colnr_T col) { RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col) } -#endif + +#endif /* if defined(FEAT_VREPLACE) || defined(FEAT_EX_EXTRA) || + defined(FEAT_GUI) || defined(FEAT_VIRTUALEDIT) || defined(PROTO) */ static int win_chartabsize(win_T *wp, char_u *p, colnr_T col) { RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, p, col) } -/* - * Return the number of characters the string 's' will take on the screen, - * taking into account the size of a tab. - */ +/// Return the number of characters the string 's' will take on the screen, +/// taking into account the size of a tab. +/// +/// @param s +/// +/// @return Number of characters the string will take on the screen. int linetabsize(char_u *s) { return linetabsize_col(0, s); } -/* - * Like linetabsize(), but starting at column "startcol". - */ +/// Like linetabsize(), but starting at column "startcol". +/// +/// @param startcol +/// @param s +/// +/// @return Number of characters the string will take on the screen. int linetabsize_col(int startcol, char_u *s) { colnr_T col = startcol; - while (*s != NUL) + while (*s != NUL) { col += lbr_chartabsize_adv(&s, col); + } return (int)col; } -/* - * Like linetabsize(), but for a given window instead of the current one. - */ +/// Like linetabsize(), but for a given window instead of the current one. +/// +/// @param wp +/// @param p +/// @param len +/// +/// @return Number of characters the string will take on the screen. int win_linetabsize(win_T *wp, char_u *p, colnr_T len) { colnr_T col = 0; - char_u *s; + char_u *s; - for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s)) + for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s)) { col += win_lbr_chartabsize(wp, s, col, NULL); + } return (int)col; } -/* - * Return TRUE if 'c' is a normal identifier character: - * Letters and characters from the 'isident' option. - */ +/// Return TRUE if 'c' is a normal identifier character: +/// +/// Letters and characters from the 'isident' option. +/// +/// @param c +/// +/// @return TRUE if 'c' is a normal identifier character. int vim_isIDc(int c) { return c > 0 && c < 0x100 && (chartab[c] & CT_ID_CHAR); } -/* - * return TRUE if 'c' is a keyword character: Letters and characters from - * 'iskeyword' option for current buffer. - * For multi-byte characters mb_get_class() is used (builtin rules). - */ +/// return TRUE if 'c' is a keyword character: Letters and characters from +/// 'iskeyword' option for current buffer. +/// +/// For multi-byte characters mb_get_class() is used (builtin rules). +/// +/// @param c +/// +/// @return TRUE if 'c' is a keyword character. int vim_iswordc(int c) { return vim_iswordc_buf(c, curbuf); @@ -718,96 +844,121 @@ int vim_iswordc(int c) int vim_iswordc_buf(int c, buf_T *buf) { if (c >= 0x100) { - if (enc_dbcs != 0) + if (enc_dbcs != 0) { return dbcs_class((unsigned)c >> 8, (unsigned)(c & 0xff)) >= 2; - if (enc_utf8) + } + + if (enc_utf8) { return utf_class(c) >= 2; + } } return c > 0 && c < 0x100 && GET_CHARTAB(buf, c) != 0; } -/* - * Just like vim_iswordc() but uses a pointer to the (multi-byte) character. - */ +/// Just like vim_iswordc() but uses a pointer to the (multi-byte) character. +/// +/// @param p +/// +/// @return TRUE if 'p' points to a keyword character. int vim_iswordp(char_u *p) { - if (has_mbyte && MB_BYTE2LEN(*p) > 1) + if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) { return mb_get_class(p) >= 2; + } return GET_CHARTAB(curbuf, *p) != 0; } int vim_iswordp_buf(char_u *p, buf_T *buf) { - if (has_mbyte && MB_BYTE2LEN(*p) > 1) + if (has_mbyte && (MB_BYTE2LEN(*p) > 1)) { return mb_get_class(p) >= 2; + } return GET_CHARTAB(buf, *p) != 0; } -/* - * return TRUE if 'c' is a valid file-name character - * Assume characters above 0x100 are valid (multi-byte). - */ +/// return TRUE if 'c' is a valid file-name character +/// Assume characters above 0x100 are valid (multi-byte). +/// +/// @param c +/// +/// @return TRUE if 'c' is a valid file name character. int vim_isfilec(int c) { return c >= 0x100 || (c > 0 && (chartab[c] & CT_FNAME_CHAR)); } -/* - * return TRUE if 'c' is a valid file-name character or a wildcard character - * Assume characters above 0x100 are valid (multi-byte). - * Explicitly interpret ']' as a wildcard character as mch_has_wildcard("]") - * returns false. - */ +/// return TRUE if 'c' is a valid file-name character or a wildcard character +/// Assume characters above 0x100 are valid (multi-byte). +/// Explicitly interpret ']' as a wildcard character as mch_has_wildcard("]") +/// returns false. +/// +/// @param c +/// +/// @return TRUE if 'c' is a valid file-name character or wildcard character. int vim_isfilec_or_wc(int c) { char_u buf[2]; - buf[0] = (char_u)c; buf[1] = NUL; return vim_isfilec(c) || c == ']' || mch_has_wildcard(buf); } -/* - * return TRUE if 'c' is a printable character - * Assume characters above 0x100 are printable (multi-byte), except for - * Unicode. - */ +/// return TRUE if 'c' is a printable character +/// Assume characters above 0x100 are printable (multi-byte), except for +/// Unicode. +/// +/// @param c +/// +/// @return TRUE if 'c' a printable character. int vim_isprintc(int c) { - if (enc_utf8 && c >= 0x100) + if (enc_utf8 && (c >= 0x100)) { return utf_printable(c); + } return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)); } -/* - * Strict version of vim_isprintc(c), don't return TRUE if "c" is the head - * byte of a double-byte character. - */ +/// Strict version of vim_isprintc(c), don't return TRUE if "c" is the head +/// byte of a double-byte character. +/// +/// @param c +/// +/// @return TRUE if 'c' is a printable character. int vim_isprintc_strict(int c) { - if (enc_dbcs != 0 && c < 0x100 && MB_BYTE2LEN(c) > 1) + if ((enc_dbcs != 0) && (c < 0x100) && (MB_BYTE2LEN(c) > 1)) { return FALSE; - if (enc_utf8 && c >= 0x100) + } + + if (enc_utf8 && (c >= 0x100)) { return utf_printable(c); + } return c >= 0x100 || (c > 0 && (chartab[c] & CT_PRINT_CHAR)); } -/* - * like chartabsize(), but also check for line breaks on the screen - */ +/// like chartabsize(), but also check for line breaks on the screen +/// +/// @param s +/// @param col +/// +/// @return The number of characters taken up on the screen. int lbr_chartabsize(unsigned char *s, colnr_T col) { - if (!curwin->w_p_lbr && *p_sbr == NUL) { - if (curwin->w_p_wrap) + if (!curwin->w_p_lbr && (*p_sbr == NUL)) { + if (curwin->w_p_wrap) { return win_nolbr_chartabsize(curwin, s, col, NULL); + } RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col) } return win_lbr_chartabsize(curwin, s, col, NULL); } -/* - * Call lbr_chartabsize() and advance the pointer. - */ +/// Call lbr_chartabsize() and advance the pointer. +/// +/// @param s +/// @param col +/// +/// @return The number of characters take up on the screen. int lbr_chartabsize_adv(char_u **s, colnr_T col) { int retval; @@ -817,176 +968,211 @@ int lbr_chartabsize_adv(char_u **s, colnr_T col) return retval; } -/* - * This function is used very often, keep it fast!!!! - * - * If "headp" not NULL, set *headp to the size of what we for 'showbreak' - * string at start of line. Warning: *headp is only set if it's a non-zero - * value, init to 0 before calling. - */ +/// This function is used very often, keep it fast!!!! +/// +/// If "headp" not NULL, set *headp to the size of what we for 'showbreak' +/// string at start of line. Warning: *headp is only set if it's a non-zero +/// value, init to 0 before calling. +/// +/// @param wp +/// @param s +/// @param col +/// @param headp +/// +/// @return The number of characters taken up on the screen. int win_lbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) { - int c; - int size; colnr_T col2; colnr_T colmax; int added; int mb_added = 0; int numberextra; - char_u *ps; + char_u *ps; int tab_corr = (*s == TAB); int n; - /* - * No 'linebreak' and 'showbreak': return quickly. - */ - if (!wp->w_p_lbr && *p_sbr == NUL) { - if (wp->w_p_wrap) + // No 'linebreak' and 'showbreak': return quickly. + if (!wp->w_p_lbr && (*p_sbr == NUL)) { + if (wp->w_p_wrap) { return win_nolbr_chartabsize(wp, s, col, headp); + } RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, s, col) } - /* - * First get normal size, without 'linebreak' - */ - size = win_chartabsize(wp, s, col); - c = *s; + // First get normal size, without 'linebreak' + int size = win_chartabsize(wp, s, col); + int c = *s; - /* - * If 'linebreak' set check at a blank before a non-blank if the line - * needs a break here - */ + // If 'linebreak' set check at a blank before a non-blank if the line + // needs a break here if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(s[1]) && !wp->w_p_list && wp->w_p_wrap - && wp->w_width != 0 - ) { - /* - * Count all characters from first non-blank after a blank up to next - * non-blank after a blank. - */ + && (wp->w_width != 0)) { + // Count all characters from first non-blank after a blank up to next + // non-blank after a blank. numberextra = win_col_off(wp); col2 = col; colmax = (colnr_T)(W_WIDTH(wp) - numberextra); + if (col >= colmax) { n = colmax + win_col_off2(wp); - if (n > 0) + + if (n > 0) { colmax += (((col - colmax) / n) + 1) * n; + } } - for (;; ) { + for (;;) { ps = s; mb_ptr_adv(s); c = *s; - if (!(c != NUL + + if (!((c != NUL) && (vim_isbreak(c) || (!vim_isbreak(c) - && (col2 == col || !vim_isbreak(*ps)))))) + && ((col2 == col) || !vim_isbreak(*ps)))))) { break; + } col2 += win_chartabsize(wp, s, col2); - if (col2 >= colmax) { /* doesn't fit */ + + if (col2 >= colmax) { /* doesn't fit */ size = colmax - col; tab_corr = FALSE; break; } } - } else if (has_mbyte && size == 2 && MB_BYTE2LEN(*s) > 1 - && wp->w_p_wrap && in_win_border(wp, col)) { - ++size; /* Count the ">" in the last column. */ + } else if (has_mbyte + && (size == 2) + && (MB_BYTE2LEN(*s) > 1) + && wp->w_p_wrap + && in_win_border(wp, col)) { + // Count the ">" in the last column. + ++size; mb_added = 1; } - /* - * May have to add something for 'showbreak' string at start of line - * Set *headp to the size of what we add. - */ + // May have to add something for 'showbreak' string at start of line + // Set *headp to the size of what we add. added = 0; - if (*p_sbr != NUL && wp->w_p_wrap && col != 0) { + + if ((*p_sbr != NUL) && wp->w_p_wrap && (col != 0)) { numberextra = win_col_off(wp); col += numberextra + mb_added; + if (col >= (colnr_T)W_WIDTH(wp)) { col -= W_WIDTH(wp); numberextra = W_WIDTH(wp) - (numberextra - win_col_off2(wp)); - if (numberextra > 0) + if (numberextra > 0) { col = col % numberextra; + } } - if (col == 0 || col + size > (colnr_T)W_WIDTH(wp)) { + + if ((col == 0) || (col + size > (colnr_T)W_WIDTH(wp))) { added = vim_strsize(p_sbr); - if (tab_corr) + if (tab_corr) { size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts; - else + } else { size += added; - if (col != 0) + } + + if (col != 0) { added = 0; + } } } - if (headp != NULL) + + if (headp != NULL) { *headp = added + mb_added; + } return size; } -/* - * Like win_lbr_chartabsize(), except that we know 'linebreak' is off and - * 'wrap' is on. This means we need to check for a double-byte character that - * doesn't fit at the end of the screen line. - */ +/// Like win_lbr_chartabsize(), except that we know 'linebreak' is off and +/// 'wrap' is on. This means we need to check for a double-byte character that +/// doesn't fit at the end of the screen line. +/// +/// @param wp +/// @param s +/// @param col +/// @param headp +/// +/// @return The number of characters take up on the screen. static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp) { int n; - if (*s == TAB && (!wp->w_p_list || lcs_tab1)) { + if ((*s == TAB) && (!wp->w_p_list || lcs_tab1)) { n = wp->w_buffer->b_p_ts; return (int)(n - (col % n)); } n = ptr2cells(s); - /* Add one cell for a double-width character in the last column of the - * window, displayed with a ">". */ - if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col)) { - if (headp != NULL) + + // Add one cell for a double-width character in the last column of the + // window, displayed with a ">". + if ((n == 2) && (MB_BYTE2LEN(*s) > 1) && in_win_border(wp, col)) { + if (headp != NULL) { *headp = 1; + } return 3; } return n; } -/* - * Return TRUE if virtual column "vcol" is in the rightmost column of window - * "wp". - */ +/// Return TRUE if virtual column "vcol" is in the rightmost column of window +/// "wp". +/// +/// @param wp +/// @param vcol +/// +/// @return TRUE if the virtual column is in the rightmost column. int in_win_border(win_T *wp, colnr_T vcol) { - int width1; /* width of first line (after line number) */ - int width2; /* width of further lines */ + int width1; // width of first line (after line number) + int width2; // width of further lines - if (wp->w_width == 0) /* there is no border */ + if (wp->w_width == 0) { + // there is no border return FALSE; + } width1 = W_WIDTH(wp) - win_col_off(wp); - if ((int)vcol < width1 - 1) + + if ((int)vcol < width1 - 1) { return FALSE; - if ((int)vcol == width1 - 1) + } + + if ((int)vcol == width1 - 1) { return TRUE; + } width2 = width1 + win_col_off2(wp); - if (width2 <= 0) + + if (width2 <= 0) { return FALSE; + } return (vcol - width1) % width2 == width2 - 1; } -/* - * Get virtual column number of pos. - * start: on the first position of this character (TAB, ctrl) - * cursor: where the cursor is on this character (first char, except for TAB) - * end: on the last position of this character (TAB, ctrl) - * - * This is used very often, keep it fast! - */ -void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end) +/// Get virtual column number of pos. +/// start: on the first position of this character (TAB, ctrl) +/// cursor: where the cursor is on this character (first char, except for TAB) +/// end: on the last position of this character (TAB, ctrl) +/// +/// This is used very often, keep it fast! +/// +/// @param wp +/// @param pos +/// @param start +/// @param cursor +/// @param end +void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, + colnr_T *end) { colnr_T vcol; - char_u *ptr; /* points to current char */ - char_u *posptr; /* points to char at pos->col */ + char_u *ptr; // points to current char + char_u *posptr; // points to char at pos->col int incr; int head; int ts = wp->w_buffer->b_p_ts; @@ -994,96 +1180,118 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en vcol = 0; ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); - if (pos->col == MAXCOL) - posptr = NULL; /* continue until the NUL */ - else + + if (pos->col == MAXCOL) { + // continue until the NUL + posptr = NULL; + } else { posptr = ptr + pos->col; + } - /* - * This function is used very often, do some speed optimizations. - * When 'list', 'linebreak' and 'showbreak' are not set use a simple loop. - * Also use this when 'list' is set but tabs take their normal size. - */ - if ((!wp->w_p_list || lcs_tab1 != NUL) - && !wp->w_p_lbr && *p_sbr == NUL - ) { - for (;; ) { + // This function is used very often, do some speed optimizations. + // When 'list', 'linebreak' and 'showbreak' are not set use a simple loop. + // Also use this when 'list' is set but tabs take their normal size. + if ((!wp->w_p_list || (lcs_tab1 != NUL)) + && !wp->w_p_lbr + && (*p_sbr == NUL)) { + for (;;) { head = 0; c = *ptr; - /* make sure we don't go past the end of the line */ + + // make sure we don't go past the end of the line if (c == NUL) { - incr = 1; /* NUL at end of line only takes one column */ + // NUL at end of line only takes one column + incr = 1; break; } - /* A tab gets expanded, depending on the current column */ - if (c == TAB) + + // A tab gets expanded, depending on the current column + if (c == TAB) { incr = ts - (vcol % ts); - else { + } else { if (has_mbyte) { - /* For utf-8, if the byte is >= 0x80, need to look at - * further bytes to find the cell width. */ - if (enc_utf8 && c >= 0x80) + // For utf-8, if the byte is >= 0x80, need to look at + // further bytes to find the cell width. + if (enc_utf8 && (c >= 0x80)) { incr = utf_ptr2cells(ptr); - else + } else { incr = CHARSIZE(c); + } - /* If a double-cell char doesn't fit at the end of a line - * it wraps to the next line, it's like this char is three - * cells wide. */ - if (incr == 2 && wp->w_p_wrap && MB_BYTE2LEN(*ptr) > 1 + // If a double-cell char doesn't fit at the end of a line + // it wraps to the next line, it's like this char is three + // cells wide. + if ((incr == 2) + && wp->w_p_wrap + && (MB_BYTE2LEN(*ptr) > 1) && in_win_border(wp, vcol)) { ++incr; head = 1; } - } else + } else { incr = CHARSIZE(c); + } } - if (posptr != NULL && ptr >= posptr) /* character at pos->col */ + if ((posptr != NULL) && (ptr >= posptr)) { + // character at pos->col break; + } vcol += incr; mb_ptr_adv(ptr); } - } else { - for (;; ) { - /* A tab gets expanded, depending on the current column */ + } else { + for (;;) { + // A tab gets expanded, depending on the current column head = 0; incr = win_lbr_chartabsize(wp, ptr, vcol, &head); - /* make sure we don't go past the end of the line */ + + // make sure we don't go past the end of the line if (*ptr == NUL) { - incr = 1; /* NUL at end of line only takes one column */ + // NUL at end of line only takes one column + incr = 1; break; } - if (posptr != NULL && ptr >= posptr) /* character at pos->col */ + if ((posptr != NULL) && (ptr >= posptr)) { + // character at pos->col break; + } vcol += incr; mb_ptr_adv(ptr); } } - if (start != NULL) + + if (start != NULL) { *start = vcol + head; - if (end != NULL) + } + + if (end != NULL) { *end = vcol + incr - 1; + } + if (cursor != NULL) { - if (*ptr == TAB + if ((*ptr == TAB) && (State & NORMAL) && !wp->w_p_list && !virtual_active() - && !(VIsual_active - && (*p_sel == 'e' || ltoreq(*pos, VIsual))) - ) - *cursor = vcol + incr - 1; /* cursor at end */ - else - *cursor = vcol + head; /* cursor at start */ + && !(VIsual_active && ((*p_sel == 'e') || ltoreq(*pos, VIsual)))) { + // cursor at end + *cursor = vcol + incr - 1; + } else { + // cursor at start + *cursor = vcol + head; + } } } -/* - * Get virtual cursor column in the current window, pretending 'list' is off. - */ +/// Get virtual cursor column in the current window, pretending 'list' is off. +/// +/// @param posp +/// +/// @retujrn The virtual cursor column. colnr_T getvcol_nolist(pos_T *posp) { int list_save = curwin->w_p_list; @@ -1095,150 +1303,198 @@ colnr_T getvcol_nolist(pos_T *posp) return vcol; } -/* - * Get virtual column in virtual mode. - */ -void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end) +/// Get virtual column in virtual mode. +/// +/// @param wp +/// @param pos +/// @param start +/// @param cursor +/// @param end +void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, + colnr_T *end) { colnr_T col; colnr_T coladd; colnr_T endadd; - char_u *ptr; + char_u *ptr; if (virtual_active()) { - /* For virtual mode, only want one value */ + // For virtual mode, only want one value getvcol(wp, pos, &col, NULL, NULL); coladd = pos->coladd; endadd = 0; - /* Cannot put the cursor on part of a wide character. */ + + // Cannot put the cursor on part of a wide character. ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); + if (pos->col < (colnr_T)STRLEN(ptr)) { int c = (*mb_ptr2char)(ptr + pos->col); - - if (c != TAB && vim_isprintc(c)) { + if ((c != TAB) && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); - if (coladd > endadd) /* past end of line */ + if (coladd > endadd) { + // past end of line endadd = 0; - else + } else { coladd = 0; + } } } col += coladd; - if (start != NULL) + + if (start != NULL) { *start = col; - if (cursor != NULL) + } + + if (cursor != NULL) { *cursor = col; - if (end != NULL) + } + + if (end != NULL) { *end = col + endadd; - } else + } + } else { getvcol(wp, pos, start, cursor, end); + } } -/* - * Get the leftmost and rightmost virtual column of pos1 and pos2. - * Used for Visual block mode. - */ -void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right) +/// Get the leftmost and rightmost virtual column of pos1 and pos2. +/// Used for Visual block mode. +/// +/// @param wp +/// @param pos1 +/// @param pos2 +/// @param left +/// @param right +void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, + colnr_T *right) { - colnr_T from1, from2, to1, to2; + colnr_T from1; + colnr_T from2; + colnr_T to1; + colnr_T to2; if (ltp(pos1, pos2)) { getvvcol(wp, pos1, &from1, NULL, &to1); getvvcol(wp, pos2, &from2, NULL, &to2); - } else { + } else { getvvcol(wp, pos2, &from1, NULL, &to1); getvvcol(wp, pos1, &from2, NULL, &to2); } - if (from2 < from1) + + if (from2 < from1) { *left = from2; - else + } else { *left = from1; + } + if (to2 > to1) { - if (*p_sel == 'e' && from2 - 1 >= to1) + if ((*p_sel == 'e') && (from2 - 1 >= to1)) { *right = from2 - 1; - else + } else { *right = to2; - } else + } + } else { *right = to1; + } } -/* - * skipwhite: skip over ' ' and '\t'. - */ -char_u *skipwhite(char_u *q) +/// skipwhite: skip over ' ' and '\t'. +/// +/// @param q +/// +/// @return Pointer to character after the skipped whitespace. +char_u* skipwhite(char_u *q) { - char_u *p = q; - - while (vim_iswhite(*p)) /* skip to next non-white */ - ++p; + char_u *p = q; + while (vim_iswhite(*p)) { + // skip to next non-white + p++; + } return p; } -/* - * skip over digits - */ -char_u *skipdigits(char_u *q) +/// skip over digits +/// +/// @param q +/// +/// @return Pointer to the character after the skipped digits. +char_u* skipdigits(char_u *q) { - char_u *p = q; - - while (VIM_ISDIGIT(*p)) /* skip to next non-digit */ - ++p; + char_u *p = q; + while (VIM_ISDIGIT(*p)) { + // skip to next non-digit + p++; + } return p; } -/* - * skip over digits and hex characters - */ -char_u *skiphex(char_u *q) +/// skip over digits and hex characters +/// +/// @param q +/// +/// @return Pointer to the character after the skipped digits and hex +/// characters. +char_u* skiphex(char_u *q) { - char_u *p = q; - - while (vim_isxdigit(*p)) /* skip to next non-digit */ - ++p; + char_u *p = q; + while (vim_isxdigit(*p)) { + // skip to next non-digit + p++; + } return p; } -/* - * skip to digit (or NUL after the string) - */ -char_u *skiptodigit(char_u *q) +/// skip to digit (or NUL after the string) +/// +/// @param q +/// +/// @return Pointer to the digit or (NUL after the string). +char_u* skiptodigit(char_u *q) { - char_u *p = q; - - while (*p != NUL && !VIM_ISDIGIT(*p)) /* skip to next digit */ - ++p; + char_u *p = q; + while (*p != NUL && !VIM_ISDIGIT(*p)) { + // skip to next digit + p++; + } return p; } -/* - * skip to hex character (or NUL after the string) - */ -char_u *skiptohex(char_u *q) +/// skip to hex character (or NUL after the string) +/// +/// @param q +/// +/// @return Pointer to the hex character or (NUL after the string). +char_u* skiptohex(char_u *q) { - char_u *p = q; - - while (*p != NUL && !vim_isxdigit(*p)) /* skip to next digit */ - ++p; + char_u *p = q; + while (*p != NUL && !vim_isxdigit(*p)) { + // skip to next digit + p++; + } return p; } -/* - * Variant of isdigit() that can handle characters > 0x100. - * We don't use isdigit() here, because on some systems it also considers - * superscript 1 to be a digit. - * Use the VIM_ISDIGIT() macro for simple arguments. - */ +/// Variant of isdigit() that can handle characters > 0x100. +/// We don't use isdigit() here, because on some systems it also considers +/// superscript 1 to be a digit. +/// Use the VIM_ISDIGIT() macro for simple arguments. +/// +/// @param c +/// +/// @return TRUE if the character is a digit. int vim_isdigit(int c) { return c >= '0' && c <= '9'; } -/* - * Variant of isxdigit() that can handle characters > 0x100. - * We don't use isxdigit() here, because on some systems it also considers - * superscript 1 to be a digit. - */ +/// Variant of isxdigit() that can handle characters > 0x100. +/// We don't use isxdigit() here, because on some systems it also considers +/// superscript 1 to be a digit. +/// +/// @param c +/// +/// @return TRUE if the character is a digit. int vim_isxdigit(int c) { return (c >= '0' && c <= '9') @@ -1246,191 +1502,259 @@ int vim_isxdigit(int c) || (c >= 'A' && c <= 'F'); } -/* - * Vim's own character class functions. These exist because many library - * islower()/toupper() etc. do not work properly: they crash when used with - * invalid values or can't handle latin1 when the locale is C. - * Speed is most important here. - */ +// Vim's own character class functions. These exist because many library +// islower()/toupper() etc. do not work properly: they crash when used with +// invalid values or can't handle latin1 when the locale is C. +// Speed is most important here. #define LATIN1LOWER 'l' #define LATIN1UPPER 'U' static char_u latin1flags[257] = - " UUUUUUUUUUUUUUUUUUUUUUUUUU llllllllllllllllllllllllll UUUUUUUUUUUUUUUUUUUUUUU UUUUUUUllllllllllllllllllllllll llllllll"; + " " + " UUUUUUUUUUUUUUUUUUUUUUUUUU llllllllllllllllllllllllll " + " " + "UUUUUUUUUUUUUUUUUUUUUUU UUUUUUUllllllllllllllllllllllll llllllll"; static char_u latin1upper[257] = - " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xf7\xd8\xd9\xda\xdb\xdc\xdd\xde\xff"; + " !\"#$%&'()*+,-./0123456789:;<=>" + "?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~" + "\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e" + "\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e" + "\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae" + "\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe" + "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce" + "\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde" + "\xdf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce" + "\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xf7\xd8\xd9\xda\xdb\xdc\xdd\xde\xff"; static char_u latin1lower[257] = - " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xd7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; + " !\"#$%&'()*+,-./0123456789:;<=>" + "?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + "\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e" + "\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e" + "\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae" + "\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe" + "\xbf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee" + "\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xd7\xf8\xf9\xfa\xfb\xfc\xfd\xfe" + "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee" + "\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; int vim_islower(int c) { - if (c <= '@') + if (c <= '@') { return FALSE; + } + if (c >= 0x80) { - if (enc_utf8) + if (enc_utf8) { return utf_islower(c); + } + if (c >= 0x100) { #ifdef HAVE_ISWLOWER - if (has_mbyte) + + if (has_mbyte) { return iswlower(c); -#endif - /* islower() can't handle these chars and may crash */ + } +#endif // ifdef HAVE_ISWLOWER + + // islower() can't handle these chars and may crash return FALSE; } - if (enc_latin1like) + + if (enc_latin1like) { return (latin1flags[c] & LATIN1LOWER) == LATIN1LOWER; + } } return islower(c); } int vim_isupper(int c) { - if (c <= '@') + if (c <= '@') { return FALSE; + } + if (c >= 0x80) { - if (enc_utf8) + if (enc_utf8) { return utf_isupper(c); + } + if (c >= 0x100) { #ifdef HAVE_ISWUPPER - if (has_mbyte) + + if (has_mbyte) { return iswupper(c); -#endif - /* islower() can't handle these chars and may crash */ + } +#endif // ifdef HAVE_ISWUPPER + + // islower() can't handle these chars and may crash return FALSE; } - if (enc_latin1like) + + if (enc_latin1like) { return (latin1flags[c] & LATIN1UPPER) == LATIN1UPPER; + } } return isupper(c); } int vim_toupper(int c) { - if (c <= '@') + if (c <= '@') { return c; + } + if (c >= 0x80) { - if (enc_utf8) + if (enc_utf8) { return utf_toupper(c); + } + if (c >= 0x100) { #ifdef HAVE_TOWUPPER - if (has_mbyte) + + if (has_mbyte) { return towupper(c); -#endif - /* toupper() can't handle these chars and may crash */ + } +#endif // ifdef HAVE_TOWUPPER + + // toupper() can't handle these chars and may crash return c; } - if (enc_latin1like) + + if (enc_latin1like) { return latin1upper[c]; + } } return TOUPPER_LOC(c); } int vim_tolower(int c) { - if (c <= '@') + if (c <= '@') { return c; + } + if (c >= 0x80) { - if (enc_utf8) + if (enc_utf8) { return utf_tolower(c); + } + if (c >= 0x100) { #ifdef HAVE_TOWLOWER - if (has_mbyte) + + if (has_mbyte) { return towlower(c); -#endif - /* tolower() can't handle these chars and may crash */ + } +#endif // ifdef HAVE_TOWLOWER + + // tolower() can't handle these chars and may crash return c; } - if (enc_latin1like) + + if (enc_latin1like) { return latin1lower[c]; + } } return TOLOWER_LOC(c); } -/* - * skiptowhite: skip over text until ' ' or '\t' or NUL. - */ -char_u *skiptowhite(char_u *p) +/// skiptowhite: skip over text until ' ' or '\t' or NUL. +/// +/// @param p +/// +/// @return Pointer to the next whitespace or NUL character. +char_u* skiptowhite(char_u *p) { - while (*p != ' ' && *p != '\t' && *p != NUL) - ++p; + while (*p != ' ' && *p != '\t' && *p != NUL) { + p++; + } return p; } -#if defined(FEAT_LISTCMDS) || defined(FEAT_SIGNS) || defined(FEAT_SNIFF) \ +#if defined(FEAT_LISTCMDS) \ + || defined(FEAT_SIGNS) \ + || defined(FEAT_SNIFF) \ || defined(PROTO) -/* - * skiptowhite_esc: Like skiptowhite(), but also skip escaped chars - */ -char_u *skiptowhite_esc(char_u *p) + +/// skiptowhite_esc: Like skiptowhite(), but also skip escaped chars +/// +/// @param p +/// +/// @return Pointer to the next whitespace character. +char_u* skiptowhite_esc(char_u *p) { while (*p != ' ' && *p != '\t' && *p != NUL) { - if ((*p == '\\' || *p == Ctrl_V) && *(p + 1) != NUL) + if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) { ++p; + } ++p; } return p; } -#endif -/* - * Getdigits: Get a number from a string and skip over it. - * Note: the argument is a pointer to a char_u pointer! - */ +#endif // if defined(FEAT_LISTCMDS) || defined(FEAT_SIGNS) + // || defined(FEAT_SNIFF) || defined(PROTO) + +/// Getdigits: Get a number from a string and skip over it. +/// +/// Note: the argument is a pointer to a char_u pointer! +/// +/// @param pp +/// +/// @return Number from the string. long getdigits(char_u **pp) { - char_u *p; - long retval; + char_u *p = *pp; + long retval = atol((char *)p); - p = *pp; - retval = atol((char *)p); - if (*p == '-') /* skip negative sign */ + if (*p == '-') { + // skip negative sign ++p; - p = skipdigits(p); /* skip to next non-digit */ + } + // skip to next non-digit + p = skipdigits(p); *pp = p; return retval; } -/* - * Return TRUE if "lbuf" is empty or only contains blanks. - */ +/// Return TRUE if "lbuf" is empty or only contains blanks. +/// +/// @param lbuf +/// +/// @return TRUE if `lbuf` is empty or only contains blanks. int vim_isblankline(char_u *lbuf) { - char_u *p; - - p = skipwhite(lbuf); + char_u *p = skipwhite(lbuf); return *p == NUL || *p == '\r' || *p == '\n'; } -/* - * Convert a string into a long and/or unsigned long, taking care of - * hexadecimal and octal numbers. Accepts a '-' sign. - * If "hexp" is not NULL, returns a flag to indicate the type of the number: - * 0 decimal - * '0' octal - * 'X' hex - * 'x' hex - * If "len" is not NULL, the length of the number in characters is returned. - * If "nptr" is not NULL, the signed result is returned in it. - * If "unptr" is not NULL, the unsigned result is returned in it. - * If "dooct" is non-zero recognize octal numbers, when > 1 always assume - * octal number. - * If "dohex" is non-zero recognize hex numbers, when > 1 always assume - * hex number. - */ -void -vim_str2nr ( - char_u *start, - int *hexp, /* return: type of number 0 = decimal, 'x' - or 'X' is hex, '0' = octal */ - int *len, /* return: detected length of number */ - int dooct, /* recognize octal number */ - int dohex, /* recognize hex number */ - long *nptr, /* return: signed result */ - unsigned long *unptr /* return: unsigned result */ -) +/// Convert a string into a long and/or unsigned long, taking care of +/// hexadecimal and octal numbers. Accepts a '-' sign. +/// If "hexp" is not NULL, returns a flag to indicate the type of the number: +/// 0 decimal +/// '0' octal +/// 'X' hex +/// 'x' hex +/// If "len" is not NULL, the length of the number in characters is returned. +/// If "nptr" is not NULL, the signed result is returned in it. +/// If "unptr" is not NULL, the unsigned result is returned in it. +/// If "dooct" is non-zero recognize octal numbers, when > 1 always assume +/// octal number. +/// If "dohex" is non-zero recognize hex numbers, when > 1 always assume +/// hex number. +/// +/// @param start +/// @param hexp Returns type of number 0 = decimal, 'x' or 'X' is hex, +// '0' = octal +/// @param len Returns the detected length of number. +/// @param dooct recognize octal number +/// @param dohex recognize hex number +/// @param nptr Returns the signed result. +/// @param unptr Returns the unsigned result. +void vim_str2nr(char_u *start, int *hexp, int *len, int dooct, int dohex, + long *nptr, unsigned long *unptr) { - char_u *ptr = start; - int hex = 0; /* default is decimal */ + char_u *ptr = start; + int hex = 0; // default is decimal int negative = FALSE; unsigned long un = 0; int n; @@ -1440,104 +1764,135 @@ vim_str2nr ( ++ptr; } - /* Recognize hex and octal. */ - if (ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9') { + // Recognize hex and octal. + if ((ptr[0] == '0') && (ptr[1] != '8') && (ptr[1] != '9')) { hex = ptr[1]; - if (dohex && (hex == 'X' || hex == 'x') && vim_isxdigit(ptr[2])) - ptr += 2; /* hexadecimal */ - else { - hex = 0; /* default is decimal */ + + if (dohex + && ((hex == 'X') || (hex == 'x')) + && vim_isxdigit(ptr[2])) { + // hexadecimal + ptr += 2; + } else { + // default is decimal + hex = 0; + if (dooct) { - /* Don't interpret "0", "08" or "0129" as octal. */ + // Don't interpret "0", "08" or "0129" as octal. for (n = 1; VIM_ISDIGIT(ptr[n]); ++n) { if (ptr[n] > '7') { - hex = 0; /* can't be octal */ + // can't be octal + hex = 0; break; } - if (ptr[n] >= '0') - hex = '0'; /* assume octal */ + + if (ptr[n] >= '0') { + // assume octal + hex = '0'; + } } } } } - /* - * Do the string-to-numeric conversion "manually" to avoid sscanf quirks. - */ - if (hex == '0' || dooct > 1) { - /* octal */ + // Do the string-to-numeric conversion "manually" to avoid sscanf quirks. + if ((hex == '0') || (dooct > 1)) { + // octal while ('0' <= *ptr && *ptr <= '7') { un = 8 * un + (unsigned long)(*ptr - '0'); - ++ptr; + ptr++; } - } else if (hex != 0 || dohex > 1) { - /* hex */ + } else if ((hex != 0) || (dohex > 1)) { + // hex while (vim_isxdigit(*ptr)) { un = 16 * un + (unsigned long)hex2nr(*ptr); - ++ptr; + ptr++; } - } else { - /* decimal */ + } else { + // decimal while (VIM_ISDIGIT(*ptr)) { un = 10 * un + (unsigned long)(*ptr - '0'); - ++ptr; + ptr++; } } - if (hexp != NULL) + if (hexp != NULL) { *hexp = hex; - if (len != NULL) + } + + if (len != NULL) { *len = (int)(ptr - start); + } + if (nptr != NULL) { - if (negative) /* account for leading '-' for decimal numbers */ + if (negative) { + // account for leading '-' for decimal numbers *nptr = -(long)un; - else + } else { *nptr = (long)un; + } } - if (unptr != NULL) + + if (unptr != NULL) { *unptr = un; + } } -/* - * Return the value of a single hex character. - * Only valid when the argument is '0' - '9', 'A' - 'F' or 'a' - 'f'. - */ +/// Return the value of a single hex character. +/// Only valid when the argument is '0' - '9', 'A' - 'F' or 'a' - 'f'. +/// +/// @param c +/// +/// @return The value of the hex character. int hex2nr(int c) { - if (c >= 'a' && c <= 'f') + if ((c >= 'a') && (c <= 'f')) { return c - 'a' + 10; - if (c >= 'A' && c <= 'F') + } + + if ((c >= 'A') && (c <= 'F')) { return c - 'A' + 10; + } return c - '0'; } #if defined(FEAT_TERMRESPONSE) \ - || (defined(FEAT_GUI_GTK) && defined(FEAT_WINDOWS)) || defined(PROTO) -/* - * Convert two hex characters to a byte. - * Return -1 if one of the characters is not hex. - */ + || (defined(FEAT_GUI_GTK) && defined(FEAT_WINDOWS)) \ + || defined(PROTO) + +/// Convert two hex characters to a byte. +/// Return -1 if one of the characters is not hex. +/// +/// @param p +/// +/// @return The two hex characters converted to a byte or -1 if one of the +/// character is not hex. int hexhex2nr(char_u *p) { - if (!vim_isxdigit(p[0]) || !vim_isxdigit(p[1])) + if (!vim_isxdigit(p[0]) || !vim_isxdigit(p[1])) { return -1; + } return (hex2nr(p[0]) << 4) + hex2nr(p[1]); } -#endif - -/* - * Return TRUE if "str" starts with a backslash that should be removed. - * For MS-DOS, WIN32 and OS/2 this is only done when the character after the - * backslash is not a normal file name character. - * '$' is a valid file name character, we don't remove the backslash before - * it. This means it is not possible to use an environment variable after a - * backslash. "C:\$VIM\doc" is taken literally, only "$VIM\doc" works. - * Although "\ name" is valid, the backslash in "Program\ files" must be - * removed. Assume a file name doesn't start with a space. - * For multi-byte names, never remove a backslash before a non-ascii - * character, assume that all multi-byte characters are valid file name - * characters. - */ + +#endif // if defined(FEAT_TERMRESPONSE) || (defined(FEAT_GUI_GTK) + // && defined(FEAT_WINDOWS)) || defined(PROTO) + +/// Return TRUE if "str" starts with a backslash that should be removed. +/// For MS-DOS, WIN32 and OS/2 this is only done when the character after the +/// backslash is not a normal file name character. +/// '$' is a valid file name character, we don't remove the backslash before +/// it. This means it is not possible to use an environment variable after a +/// backslash. "C:\$VIM\doc" is taken literally, only "$VIM\doc" works. +/// Although "\ name" is valid, the backslash in "Program\ files" must be +/// removed. Assume a file name doesn't start with a space. +/// For multi-byte names, never remove a backslash before a non-ascii +/// character, assume that all multi-byte characters are valid file name +/// characters. +/// +/// @param str +/// +/// @return TRUE if `str` starts with a backslash that should be removed. int rem_backslash(char_u *str) { #ifdef BACKSLASH_IN_FILENAME @@ -1548,34 +1903,37 @@ int rem_backslash(char_u *str) && str[1] != '*' && str[1] != '?' && !vim_isfilec(str[1]))); -#else + +#else // ifdef BACKSLASH_IN_FILENAME return str[0] == '\\' && str[1] != NUL; -#endif +#endif // ifdef BACKSLASH_IN_FILENAME } -/* - * Halve the number of backslashes in a file name argument. - * For MS-DOS we only do this if the character after the backslash - * is not a normal file character. - */ +/// Halve the number of backslashes in a file name argument. +/// For MS-DOS we only do this if the character after the backslash +/// is not a normal file character. +/// +/// @param p void backslash_halve(char_u *p) { - for (; *p; ++p) - if (rem_backslash(p)) + for (; *p; ++p) { + if (rem_backslash(p)) { STRMOVE(p, p + 1); + } + } } -/* - * backslash_halve() plus save the result in allocated memory. - */ -char_u *backslash_halve_save(char_u *p) +/// backslash_halve() plus save the result in allocated memory. +/// +/// @param p +/// +/// @return String with the number of backslashes halved. +char_u* backslash_halve_save(char_u *p) { - char_u *res; - - res = vim_strsave(p); - if (res == NULL) + char_u *res = vim_strsave(p); + if (res == NULL) { return p; + } backslash_halve(res); return res; } - diff --git a/src/charset.h b/src/charset.h index 433c88ec9e..ddcd8ac41c 100644 --- a/src/charset.h +++ b/src/charset.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_CHARSET_H #define NEOVIM_CHARSET_H -/* charset.c */ + int init_chartab(void); int buf_init_chartab(buf_T *buf, int global); void trans_characters(char_u *buf, int bufsize); @@ -63,5 +63,6 @@ int rem_backslash(char_u *str); void backslash_halve(char_u *p); char_u *backslash_halve_save(char_u *p); void ebcdic2ascii(char_u *buffer, int len); -/* vim: set ft=c : */ -#endif /* NEOVIM_CHARSET_H */ + +// vim: set ft=c: +#endif // NEOVIM_CHARSET_H diff --git a/src/crypt.c b/src/crypt.c index 21fd03b44a..9a62f9174d 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -21,8 +21,8 @@ /* from zip.h */ -typedef unsigned short ush; /* unsigned 16-bit value */ -typedef unsigned long ulg; /* unsigned 32-bit value */ +typedef unsigned short ush; /* unsigned 16-bit value */ +typedef unsigned long ulg; /* unsigned 32-bit value */ static void make_crc_tab(void); @@ -31,16 +31,21 @@ static ulg crc_32_tab[256]; /* * Fill the CRC table. */ -static void make_crc_tab(void) { - ulg s,t,v; +static void make_crc_tab(void) +{ + ulg s, t, v; static int done = FALSE; - if (done) + if (done) { return; + } + for (t = 0; t < 256; t++) { v = t; - for (s = 0; s < 8; s++) + + for (s = 0; s < 8; s++) { v = (v >> 1) ^ ((v & 1) * (ulg)0xedb88320L); + } crc_32_tab[t] = v; } done = TRUE; @@ -54,20 +59,19 @@ static ulg keys[3]; /* keys defining the pseudo-random sequence */ * Return the next byte in the pseudo-random sequence. */ #define DECRYPT_BYTE_ZIP(t) { \ - ush temp; \ - \ - temp = (ush)keys[2] | 2; \ - t = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); \ + ush temp; \ + temp = (ush)keys[2] | 2; \ + t = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); \ } /* * Update the encryption keys with the next byte of plain text. */ #define UPDATE_KEYS_ZIP(c) { \ - keys[0] = CRC32(keys[0], (c)); \ - keys[1] += keys[0] & 0xff; \ - keys[1] = keys[1] * 134775813L + 1; \ - keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ + keys[0] = CRC32(keys[0], (c)); \ + keys[1] += keys[0] & 0xff; \ + keys[1] = keys[1] * 134775813L + 1; \ + keys[2] = CRC32(keys[2], (int)(keys[1] >> 24)); \ } static int crypt_busy = 0; @@ -107,18 +111,21 @@ void set_crypt_method(buf_T *buf, int method) * the state. * Must always be called symmetrically with crypt_pop_state(). */ -void crypt_push_state(void) { +void crypt_push_state(void) +{ if (crypt_busy == 1) { /* save the state */ if (use_crypt_method == 0) { saved_keys[0] = keys[0]; saved_keys[1] = keys[1]; saved_keys[2] = keys[2]; - } else + } else { bf_crypt_save(); + } saved_crypt_method = use_crypt_method; - } else if (crypt_busy > 1) + } else if (crypt_busy > 1) { EMSG2(_(e_intern2), "crypt_push_state()"); + } ++crypt_busy; } @@ -127,16 +134,20 @@ void crypt_push_state(void) { * the saved state. * Must always be called symmetrically with crypt_push_state(). */ -void crypt_pop_state(void) { +void crypt_pop_state(void) +{ --crypt_busy; + if (crypt_busy == 1) { use_crypt_method = saved_crypt_method; + if (use_crypt_method == 0) { keys[0] = saved_keys[0]; keys[1] = saved_keys[1]; keys[2] = saved_keys[2]; - } else + } else { bf_crypt_restore(); + } } } @@ -149,15 +160,16 @@ void crypt_encode(char_u *from, size_t len, char_u *to) size_t i; int ztemp, t; - if (use_crypt_method == 0) + if (use_crypt_method == 0) { for (i = 0; i < len; ++i) { ztemp = from[i]; DECRYPT_BYTE_ZIP(t); UPDATE_KEYS_ZIP(ztemp); to[i] = t ^ ztemp; } - else + } else { bf_crypt_encode(from, len, to); + } } /* @@ -167,7 +179,7 @@ void crypt_decode(char_u *ptr, long len) { char_u *p; - if (use_crypt_method == 0) + if (use_crypt_method == 0) { for (p = ptr; p < ptr + len; ++p) { ush temp; @@ -175,21 +187,20 @@ void crypt_decode(char_u *ptr, long len) temp = (int)(((unsigned)(temp * (temp ^ 1U)) >> 8) & 0xff); UPDATE_KEYS_ZIP(*p ^= temp); } - else + } else { bf_crypt_decode(ptr, len); + } } /* * Initialize the encryption keys and the random header according to * the given password. * If "passwd" is NULL or empty, don't do anything. + * in: "passwd" password string with which to modify keys */ -void -crypt_init_keys ( - char_u *passwd /* password string with which to modify keys */ -) +void crypt_init_keys(char_u *passwd) { - if (passwd != NULL && *passwd != NUL) { + if ((passwd != NULL) && (*passwd != NUL)) { if (use_crypt_method == 0) { char_u *p; @@ -197,11 +208,13 @@ crypt_init_keys ( keys[0] = 305419896L; keys[1] = 591751049L; keys[2] = 878082192L; - for (p = passwd; *p!= NUL; ++p) { + + for (p = passwd; *p != NUL; ++p) { UPDATE_KEYS_ZIP((int)*p); } - } else + } else { bf_crypt_init_keys(passwd); + } } } @@ -214,8 +227,9 @@ void free_crypt_key(char_u *key) char_u *p; if (key != NULL) { - for (p = key; *p != NUL; ++p) + for (p = key; *p != NUL; ++p) { *p = 0; + } vim_free(key); } } @@ -225,41 +239,38 @@ void free_crypt_key(char_u *key) * When "store" is TRUE, the new key is stored in the 'key' option, and the * 'key' option value is returned: Don't free it. * When "store" is FALSE, the typed key is returned in allocated memory. + * in: "twice" Ask for the key twice. * Returns NULL on failure. */ -char_u * -get_crypt_key ( - int store, - int twice /* Ask for the key twice. */ -) +char_u *get_crypt_key(int store, int twice) { - char_u *p1, *p2 = NULL; + char_u *p1, *p2 = NULL; int round; for (round = 0;; ++round) { cmdline_star = TRUE; cmdline_row = msg_row; - p1 = getcmdline_prompt(NUL, round == 0 - ? (char_u *)_("Enter encryption key: ") - : (char_u *)_("Enter same key again: "), 0, EXPAND_NOTHING, - NULL); + char_u *prompt = (round == 0) + ? (char_u *) _("Enter encryption key: ") + : (char_u *) _("Enter same key again: "); + p1 = getcmdline_prompt(NUL, prompt, 0, EXPAND_NOTHING, NULL); cmdline_star = FALSE; - - if (p1 == NULL) + if (p1 == NULL) { break; + } if (round == twice) { - if (p2 != NULL && STRCMP(p1, p2) != 0) { + if ((p2 != NULL) && (STRCMP(p1, p2) != 0)) { MSG(_("Keys don't match!")); free_crypt_key(p1); free_crypt_key(p2); p2 = NULL; - round = -1; /* do it again */ + round = -1; /* do it again */ continue; } if (store) { - set_option_value((char_u *)"key", 0L, p1, OPT_LOCAL); + set_option_value((char_u *) "key", 0L, p1, OPT_LOCAL); free_crypt_key(p1); p1 = curbuf->b_p_key; } @@ -269,12 +280,12 @@ get_crypt_key ( } /* since the user typed this, no need to wait for return */ - if (msg_didout) + if (msg_didout) { msg_putchar('\n'); + } need_wait_return = FALSE; msg_didout = FALSE; free_crypt_key(p2); return p1; } - diff --git a/src/diff.c b/src/diff.c index f59ba8015a..bdf78dd708 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1,15 +1,6 @@ -/* vim:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * diff.c: code for diff'ing two, three or four buffers. - */ +/// @file diff.c +/// +/// Code for diff'ing two, three or four buffers. #include "vim.h" #include "diff.h" @@ -34,20 +25,21 @@ #include "window.h" #include "os/os.h" -static int diff_busy = FALSE; /* ex_diffgetput() is busy */ +static int diff_busy = FALSE; // ex_diffgetput() is busy -/* flags obtained from the 'diffopt' option */ -#define DIFF_FILLER 1 /* display filler lines */ -#define DIFF_ICASE 2 /* ignore case */ -#define DIFF_IWHITE 4 /* ignore change in white space */ -#define DIFF_HORIZONTAL 8 /* horizontal splits */ -#define DIFF_VERTICAL 16 /* vertical splits */ +// Flags obtained from the 'diffopt' option +#define DIFF_FILLER 1 // display filler lines +#define DIFF_ICASE 2 // ignore case +#define DIFF_IWHITE 4 // ignore change in white space +#define DIFF_HORIZONTAL 8 // horizontal splits +#define DIFF_VERTICAL 16 // vertical splits static int diff_flags = DIFF_FILLER; -#define LBUFLEN 50 /* length of line in diff file */ +#define LBUFLEN 50 // length of line in diff file -static int diff_a_works = MAYBE; /* TRUE when "diff -a" works, FALSE when it - doesn't work, MAYBE when not checked yet */ +// TRUE when "diff -a" works, FALSE when it doesn't work, MAYBE when not +// checked yet +static int diff_a_works = MAYBE; static int diff_buf_idx(buf_T *buf); static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp); @@ -65,319 +57,359 @@ static void diff_fold_update(diff_T *dp, int skip_idx); static void diff_read(int idx_orig, int idx_new, char_u *fname); static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new); -static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); +static diff_T* diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); #ifndef USE_CR # define tag_fgets vim_fgets -#endif +#endif // ifndef USE_CR -/* - * Called when deleting or unloading a buffer: No longer make a diff with it. - */ +/// Called when deleting or unloading a buffer: No longer make a diff with it. +/// +/// @param buf void diff_buf_delete(buf_T *buf) { - int i; - tabpage_T *tp; - + tabpage_T *tp; for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - i = diff_buf_idx_tp(buf, tp); + int i = diff_buf_idx_tp(buf, tp); + if (i != DB_COUNT) { tp->tp_diffbuf[i] = NULL; tp->tp_diff_invalid = TRUE; - if (tp == curtab) + + if (tp == curtab) { diff_redraw(TRUE); + } } } } -/* - * Check if the current buffer should be added to or removed from the list of - * diff buffers. - */ +/// Check if the current buffer should be added to or removed from the list of +/// diff buffers. +/// +/// @param win void diff_buf_adjust(win_T *win) { - win_T *wp; - int i; if (!win->w_p_diff) { - /* When there is no window showing a diff for this buffer, remove - * it from the diffs. */ - for (wp = firstwin; wp != NULL; wp = wp->w_next) - if (wp->w_buffer == win->w_buffer && wp->w_p_diff) + // When there is no window showing a diff for this buffer, remove + // it from the diffs. + win_T *wp; + for (wp = firstwin; wp != NULL; wp = wp->w_next) { + if ((wp->w_buffer == win->w_buffer) && wp->w_p_diff) { break; + } + } + if (wp == NULL) { - i = diff_buf_idx(win->w_buffer); + int i = diff_buf_idx(win->w_buffer); if (i != DB_COUNT) { curtab->tp_diffbuf[i] = NULL; curtab->tp_diff_invalid = TRUE; diff_redraw(TRUE); } } - } else + } else { diff_buf_add(win->w_buffer); + } } -/* - * Add a buffer to make diffs for. - * Call this when a new buffer is being edited in the current window where - * 'diff' is set. - * Marks the current buffer as being part of the diff and requiring updating. - * This must be done before any autocmd, because a command may use info - * about the screen contents. - */ +/// Add a buffer to make diffs for. +/// +/// Call this when a new buffer is being edited in the current window where +/// 'diff' is set. +/// Marks the current buffer as being part of the diff and requiring updating. +/// This must be done before any autocmd, because a command may use info +/// about the screen contents. +/// +/// @param buf The buffer to add. void diff_buf_add(buf_T *buf) { - int i; - - if (diff_buf_idx(buf) != DB_COUNT) - return; /* It's already there. */ + if (diff_buf_idx(buf) != DB_COUNT) { + // It's already there. + return; + } - for (i = 0; i < DB_COUNT; ++i) + int i; + for (i = 0; i < DB_COUNT; ++i) { if (curtab->tp_diffbuf[i] == NULL) { curtab->tp_diffbuf[i] = buf; curtab->tp_diff_invalid = TRUE; diff_redraw(TRUE); return; } + } EMSGN(_("E96: Can not diff more than %ld buffers"), DB_COUNT); } -/* - * Find buffer "buf" in the list of diff buffers for the current tab page. - * Return its index or DB_COUNT if not found. - */ +/// Find buffer "buf" in the list of diff buffers for the current tab page. +/// +/// @param buf The buffer to find. +/// +/// @return Its index or DB_COUNT if not found. static int diff_buf_idx(buf_T *buf) { int idx; - - for (idx = 0; idx < DB_COUNT; ++idx) - if (curtab->tp_diffbuf[idx] == buf) + for (idx = 0; idx < DB_COUNT; ++idx) { + if (curtab->tp_diffbuf[idx] == buf) { break; + } + } return idx; } -/* - * Find buffer "buf" in the list of diff buffers for tab page "tp". - * Return its index or DB_COUNT if not found. - */ +/// Find buffer "buf" in the list of diff buffers for tab page "tp". +/// +/// @param buf +/// @param tp +/// +/// @return its index or DB_COUNT if not found. static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp) { int idx; - - for (idx = 0; idx < DB_COUNT; ++idx) - if (tp->tp_diffbuf[idx] == buf) + for (idx = 0; idx < DB_COUNT; ++idx) { + if (tp->tp_diffbuf[idx] == buf) { break; + } + } return idx; } -/* - * Mark the diff info involving buffer "buf" as invalid, it will be updated - * when info is requested. - */ +/// Mark the diff info involving buffer "buf" as invalid, it will be updated +/// when info is requested. +/// +/// @param buf void diff_invalidate(buf_T *buf) { - tabpage_T *tp; - int i; - + tabpage_T *tp; for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - i = diff_buf_idx_tp(buf, tp); + int i = diff_buf_idx_tp(buf, tp); if (i != DB_COUNT) { tp->tp_diff_invalid = TRUE; - if (tp == curtab) + if (tp == curtab) { diff_redraw(TRUE); + } } } } -/* - * Called by mark_adjust(): update line numbers in "curbuf". - */ -void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after) +/// Called by mark_adjust(): update line numbers in "curbuf". +/// +/// @param line1 +/// @param line2 +/// @param amount +/// @param amount_after +void diff_mark_adjust(linenr_T line1, linenr_T line2, long amount, + long amount_after) { - int idx; - tabpage_T *tp; - - /* Handle all tab pages that use the current buffer in a diff. */ + // Handle all tab pages that use the current buffer in a diff. + tabpage_T *tp; for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { - idx = diff_buf_idx_tp(curbuf, tp); - if (idx != DB_COUNT) + int idx = diff_buf_idx_tp(curbuf, tp); + if (idx != DB_COUNT) { diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); + } } } -/* - * Update line numbers in tab page "tp" for "curbuf" with index "idx". - * This attempts to update the changes as much as possible: - * When inserting/deleting lines outside of existing change blocks, create a - * new change block and update the line numbers in following blocks. - * When inserting/deleting lines in existing change blocks, update them. - */ -static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount, long amount_after) +/// Update line numbers in tab page "tp" for "curbuf" with index "idx". +/// +/// This attempts to update the changes as much as possible: +/// When inserting/deleting lines outside of existing change blocks, create a +/// new change block and update the line numbers in following blocks. +/// When inserting/deleting lines in existing change blocks, update them. +/// +/// @param tp +/// @param idx +/// @param line1 +/// @param line2 +/// @param amount +/// @amount_after +static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, + linenr_T line2, long amount, long amount_after) { - diff_T *dp; - diff_T *dprev; - diff_T *dnext; - int i; - int inserted, deleted; - int n, off; - linenr_T last; - linenr_T lnum_deleted = line1; /* lnum of remaining deletion */ - int check_unchanged; - + int inserted; + int deleted; if (line2 == MAXLNUM) { - /* mark_adjust(99, MAXLNUM, 9, 0): insert lines */ + // mark_adjust(99, MAXLNUM, 9, 0): insert lines inserted = amount; deleted = 0; - } else if (amount_after > 0) { - /* mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines*/ + } else if (amount_after > 0) { + // mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines inserted = amount_after; deleted = 0; - } else { - /* mark_adjust(98, 99, MAXLNUM, -2): delete lines */ + } else { + // mark_adjust(98, 99, MAXLNUM, -2): delete lines inserted = 0; deleted = -amount_after; } - dprev = NULL; - dp = tp->tp_first_diff; - for (;; ) { - /* If the change is after the previous diff block and before the next - * diff block, thus not touching an existing change, create a new diff - * block. Don't do this when ex_diffgetput() is busy. */ - if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 - || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) - && (dprev == NULL - || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) + diff_T *dprev = NULL; + diff_T *dp = tp->tp_first_diff; + + linenr_T last; + linenr_T lnum_deleted = line1; // lnum of remaining deletion + int n; + int off; + for (;;) { + // If the change is after the previous diff block and before the next + // diff block, thus not touching an existing change, create a new diff + // block. Don't do this when ex_diffgetput() is busy. + if (((dp == NULL) + || (dp->df_lnum[idx] - 1 > line2) + || ((line2 == MAXLNUM) && (dp->df_lnum[idx] > line1))) + && ((dprev == NULL) + || (dprev->df_lnum[idx] + dprev->df_count[idx] < line1)) && !diff_busy) { - dnext = diff_alloc_new(tp, dprev, dp); - if (dnext == NULL) + diff_T *dnext = diff_alloc_new(tp, dprev, dp); + + if (dnext == NULL) { return; + } dnext->df_lnum[idx] = line1; dnext->df_count[idx] = inserted; - for (i = 0; i < DB_COUNT; ++i) - if (tp->tp_diffbuf[i] != NULL && i != idx) { - if (dprev == NULL) + int i; + for (i = 0; i < DB_COUNT; ++i) { + if ((tp->tp_diffbuf[i] != NULL) && (i != idx)) { + if (dprev == NULL) { dnext->df_lnum[i] = line1; - else + } else { dnext->df_lnum[i] = line1 - + (dprev->df_lnum[i] + dprev->df_count[i]) - - (dprev->df_lnum[idx] + dprev->df_count[idx]); + + (dprev->df_lnum[i] + dprev->df_count[i]) + - (dprev->df_lnum[idx] + dprev->df_count[idx]); + } dnext->df_count[i] = deleted; } + } } - /* if at end of the list, quit */ - if (dp == NULL) + // if at end of the list, quit + if (dp == NULL) { break; + } - /* - * Check for these situations: - * 1 2 3 - * 1 2 3 - * line1 2 3 4 5 - * 2 3 4 5 - * 2 3 4 5 - * line2 2 3 4 5 - * 3 5 6 - * 3 5 6 - */ - /* compute last line of this change */ + // + // Check for these situations: + // 1 2 3 + // 1 2 3 + // line1 2 3 4 5 + // 2 3 4 5 + // 2 3 4 5 + // line2 2 3 4 5 + // 3 5 6 + // 3 5 6 + + // compute last line of this change last = dp->df_lnum[idx] + dp->df_count[idx] - 1; - /* 1. change completely above line1: nothing to do */ + // 1. change completely above line1: nothing to do if (last >= line1 - 1) { - /* 6. change below line2: only adjust for amount_after; also when - * "deleted" became zero when deleted all lines between two diffs */ + // 6. change below line2: only adjust for amount_after; also when + // "deleted" became zero when deleted all lines between two diffs. if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) { - if (amount_after == 0) - break; /* nothing left to change */ + if (amount_after == 0) { + // nothing left to change + break; + } dp->df_lnum[idx] += amount_after; - } else { - check_unchanged = FALSE; + } else { + int check_unchanged = FALSE; - /* 2. 3. 4. 5.: inserted/deleted lines touching this diff. */ + // 2. 3. 4. 5.: inserted/deleted lines touching this diff. if (deleted > 0) { if (dp->df_lnum[idx] >= line1) { off = dp->df_lnum[idx] - lnum_deleted; + if (last <= line2) { - /* 4. delete all lines of diff */ - if (dp->df_next != NULL - && dp->df_next->df_lnum[idx] - 1 <= line2) { - /* delete continues in next diff, only do - * lines until that one */ + // 4. delete all lines of diff + if ((dp->df_next != NULL) + && (dp->df_next->df_lnum[idx] - 1 <= line2)) { + // delete continues in next diff, only do + // lines until that one n = dp->df_next->df_lnum[idx] - lnum_deleted; deleted -= n; n -= dp->df_count[idx]; lnum_deleted = dp->df_next->df_lnum[idx]; - } else + } else { n = deleted - dp->df_count[idx]; + } dp->df_count[idx] = 0; - } else { - /* 5. delete lines at or just before top of diff */ + } else { + // 5. delete lines at or just before top of diff n = off; dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; check_unchanged = TRUE; } dp->df_lnum[idx] = line1; - } else { + } else { off = 0; + if (last < line2) { - /* 2. delete at end of of diff */ + // 2. delete at end of of diff dp->df_count[idx] -= last - lnum_deleted + 1; - if (dp->df_next != NULL - && dp->df_next->df_lnum[idx] - 1 <= line2) { - /* delete continues in next diff, only do - * lines until that one */ + + if ((dp->df_next != NULL) + && (dp->df_next->df_lnum[idx] - 1 <= line2)) { + // delete continues in next diff, only do + // lines until that one n = dp->df_next->df_lnum[idx] - 1 - last; - deleted -= dp->df_next->df_lnum[idx] - - lnum_deleted; + deleted -= dp->df_next->df_lnum[idx] - lnum_deleted; lnum_deleted = dp->df_next->df_lnum[idx]; - } else + } else { n = line2 - last; + } check_unchanged = TRUE; - } else { - /* 3. delete lines inside the diff */ + } else { + // 3. delete lines inside the diff n = 0; dp->df_count[idx] -= deleted; } } - for (i = 0; i < DB_COUNT; ++i) - if (tp->tp_diffbuf[i] != NULL && i != idx) { + int i; + for (i = 0; i < DB_COUNT; ++i) { + if ((tp->tp_diffbuf[i] != NULL) && (i != idx)) { dp->df_lnum[i] -= off; dp->df_count[i] += n; } - } else { + } + } else { if (dp->df_lnum[idx] <= line1) { - /* inserted lines somewhere in this diff */ + // inserted lines somewhere in this diff dp->df_count[idx] += inserted; check_unchanged = TRUE; - } else - /* inserted lines somewhere above this diff */ + } else { + // inserted lines somewhere above this diff dp->df_lnum[idx] += inserted; + } } - if (check_unchanged) - /* Check if inserted lines are equal, may reduce the - * size of the diff. TODO: also check for equal lines - * in the middle and perhaps split the block. */ + if (check_unchanged) { + // Check if inserted lines are equal, may reduce the size of the + // diff. + // + // TODO: also check for equal lines in the middle and perhaps split + // the block. diff_check_unchanged(tp, dp); + } } } - /* check if this block touches the previous one, may merge them. */ - if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] - == dp->df_lnum[idx]) { - for (i = 0; i < DB_COUNT; ++i) - if (tp->tp_diffbuf[i] != NULL) + // check if this block touches the previous one, may merge them. + if ((dprev != NULL) + && (dprev->df_lnum[idx] + dprev->df_count[idx] == dp->df_lnum[idx])) { + int i; + for (i = 0; i < DB_COUNT; ++i) { + if (tp->tp_diffbuf[i] != NULL) { dprev->df_count[i] += dp->df_count[i]; + } + } dprev->df_next = dp->df_next; vim_free(dp); dp = dprev->df_next; - } else { - /* Advance to next entry. */ + } else { + // Advance to next entry. dprev = dp; dp = dp->df_next; } @@ -385,270 +417,315 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T dprev = NULL; dp = tp->tp_first_diff; + while (dp != NULL) { - /* All counts are zero, remove this entry. */ - for (i = 0; i < DB_COUNT; ++i) - if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) + // All counts are zero, remove this entry. + int i; + for (i = 0; i < DB_COUNT; ++i) { + if ((tp->tp_diffbuf[i] != NULL) && (dp->df_count[i] != 0)) { break; + } + } + if (i == DB_COUNT) { - dnext = dp->df_next; + diff_T *dnext = dp->df_next; vim_free(dp); dp = dnext; - if (dprev == NULL) + + if (dprev == NULL) { tp->tp_first_diff = dnext; - else + } else { dprev->df_next = dnext; - } else { - /* Advance to next entry. */ + } + } else { + // Advance to next entry. dprev = dp; dp = dp->df_next; } - } if (tp == curtab) { diff_redraw(TRUE); - /* Need to recompute the scroll binding, may remove or add filler - * lines (e.g., when adding lines above w_topline). But it's slow when - * making many changes, postpone until redrawing. */ + // Need to recompute the scroll binding, may remove or add filler + // lines (e.g., when adding lines above w_topline). But it's slow when + // making many changes, postpone until redrawing. diff_need_scrollbind = TRUE; } } -/* - * Allocate a new diff block and link it between "dprev" and "dp". - */ -static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) +/// Allocate a new diff block and link it between "dprev" and "dp". +/// +/// @param tp +/// @param dprev +/// @param dp +/// +/// @return The new diff block. +static diff_T* diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) { - diff_T *dnew; - - dnew = (diff_T *)alloc((unsigned)sizeof(diff_T)); + diff_T *dnew = (diff_T *)alloc((unsigned)sizeof(diff_T)); if (dnew != NULL) { dnew->df_next = dp; - if (dprev == NULL) + if (dprev == NULL) { tp->tp_first_diff = dnew; - else + } else { dprev->df_next = dnew; + } } return dnew; } -/* - * Check if the diff block "dp" can be made smaller for lines at the start and - * end that are equal. Called after inserting lines. - * This may result in a change where all buffers have zero lines, the caller - * must take care of removing it. - */ +/// Check if the diff block "dp" can be made smaller for lines at the start and +/// end that are equal. Called after inserting lines. +/// +/// This may result in a change where all buffers have zero lines, the caller +/// must take care of removing it. +/// +/// @param tp +/// @param dp static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) { + // Find the first buffers, use it as the original, compare the other + // buffer lines against this one. int i_org; - int i_new; - int off_org, off_new; - char_u *line_org; - int dir = FORWARD; - - /* Find the first buffers, use it as the original, compare the other - * buffer lines against this one. */ - for (i_org = 0; i_org < DB_COUNT; ++i_org) - if (tp->tp_diffbuf[i_org] != NULL) + for (i_org = 0; i_org < DB_COUNT; ++i_org) { + if (tp->tp_diffbuf[i_org] != NULL) { break; - if (i_org == DB_COUNT) /* safety check */ + } + } + + // safety check + if (i_org == DB_COUNT) { return; + } - if (diff_check_sanity(tp, dp) == FAIL) + if (diff_check_sanity(tp, dp) == FAIL) { return; + } - /* First check lines at the top, then at the bottom. */ - off_org = 0; - off_new = 0; - for (;; ) { - /* Repeat until a line is found which is different or the number of - * lines has become zero. */ + // First check lines at the top, then at the bottom. + int off_org = 0; + int off_new = 0; + int dir = FORWARD; + for (;;) { + // Repeat until a line is found which is different or the number of + // lines has become zero. while (dp->df_count[i_org] > 0) { - /* Copy the line, the next ml_get() will invalidate it. */ - if (dir == BACKWARD) + // Copy the line, the next ml_get() will invalidate it. + if (dir == BACKWARD) { off_org = dp->df_count[i_org] - 1; - line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], - dp->df_lnum[i_org] + off_org, FALSE)); - if (line_org == NULL) + } + char_u *line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], + dp->df_lnum[i_org] + off_org, + FALSE)); + + if (line_org == NULL) { return; + } + + int i_new; for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) { - if (tp->tp_diffbuf[i_new] == NULL) + if (tp->tp_diffbuf[i_new] == NULL) { continue; - if (dir == BACKWARD) + } + + if (dir == BACKWARD) { off_new = dp->df_count[i_new] - 1; - /* if other buffer doesn't have this line, it was inserted */ - if (off_new < 0 || off_new >= dp->df_count[i_new]) + } + + // if other buffer doesn't have this line, it was inserted + if ((off_new < 0) || (off_new >= dp->df_count[i_new])) { break; + } + if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], - dp->df_lnum[i_new] + off_new, FALSE)) != 0) + dp->df_lnum[i_new] + off_new, + FALSE)) != 0) { break; + } } vim_free(line_org); - /* Stop when a line isn't equal in all diff buffers. */ - if (i_new != DB_COUNT) + // Stop when a line isn't equal in all diff buffers. + if (i_new != DB_COUNT) { break; + } - /* Line matched in all buffers, remove it from the diff. */ - for (i_new = i_org; i_new < DB_COUNT; ++i_new) + // Line matched in all buffers, remove it from the diff. + for (i_new = i_org; i_new < DB_COUNT; ++i_new) { if (tp->tp_diffbuf[i_new] != NULL) { - if (dir == FORWARD) - ++dp->df_lnum[i_new]; - --dp->df_count[i_new]; + if (dir == FORWARD) { + dp->df_lnum[i_new]++; + } + dp->df_count[i_new]--; } + } } - if (dir == BACKWARD) + + if (dir == BACKWARD) { break; + } dir = BACKWARD; } } -/* - * Check if a diff block doesn't contain invalid line numbers. - * This can happen when the diff program returns invalid results. - */ +/// Check if a diff block doesn't contain invalid line numbers. +/// This can happen when the diff program returns invalid results. +/// +/// @param tp +/// @param dp +/// +/// @return OK if the diff block doesn't contain invalid line numbers. static int diff_check_sanity(tabpage_T *tp, diff_T *dp) { int i; - - for (i = 0; i < DB_COUNT; ++i) - if (tp->tp_diffbuf[i] != NULL) + for (i = 0; i < DB_COUNT; ++i) { + if (tp->tp_diffbuf[i] != NULL) { if (dp->df_lnum[i] + dp->df_count[i] - 1 - > tp->tp_diffbuf[i]->b_ml.ml_line_count) + > tp->tp_diffbuf[i]->b_ml.ml_line_count) { return FAIL; + } + } + } return OK; } -/* - * Mark all diff buffers in the current tab page for redraw. - */ -static void -diff_redraw ( - int dofold /* also recompute the folds */ -) +/// Mark all diff buffers in the current tab page for redraw. +/// +/// @param dofold Also recompute the folds +static void diff_redraw(int dofold) { - win_T *wp; - int n; - - for (wp = firstwin; wp != NULL; wp = wp->w_next) + win_T *wp; + for (wp = firstwin; wp != NULL; wp = wp->w_next) { if (wp->w_p_diff) { redraw_win_later(wp, SOME_VALID); - if (dofold && foldmethodIsDiff(wp)) + if (dofold && foldmethodIsDiff(wp)) { foldUpdateAll(wp); + } + /* A change may have made filler lines invalid, need to take care * of that for other windows. */ - n = diff_check(wp, wp->w_topline); - if ((wp != curwin && wp->w_topfill > 0) || n > 0) { - if (wp->w_topfill > n) + int n = diff_check(wp, wp->w_topline); + + if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) { + if (wp->w_topfill > n) { wp->w_topfill = (n < 0 ? 0 : n); - else if (n > 0 && n > wp->w_topfill) + } else if ((n > 0) && (n > wp->w_topfill)) { wp->w_topfill = n; + } } } + } } -/* - * Write buffer "buf" to file "name". - * Always use 'fileformat' set to "unix". - * Return FAIL for failure - */ +/// Write buffer "buf" to file "name". +/// +/// Always use 'fileformat' set to "unix". +/// +/// @param buf +/// @param fname +/// +/// @return FAIL for failure static int diff_write(buf_T *buf, char_u *fname) { - int r; - char_u *save_ff; - - save_ff = buf->b_p_ff; + char_u *save_ff = buf->b_p_ff; buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); - r = buf_write(buf, fname, NULL, (linenr_T)1, buf->b_ml.ml_line_count, - NULL, FALSE, FALSE, FALSE, TRUE); + int r = buf_write(buf, fname, NULL, (linenr_T)1, buf->b_ml.ml_line_count, + NULL, FALSE, FALSE, FALSE, TRUE); free_string_option(buf->b_p_ff); buf->b_p_ff = save_ff; return r; } -/* - * Completely update the diffs for the buffers involved. - * This uses the ordinary "diff" command. - * The buffers are written to a file, also for unmodified buffers (the file - * could have been produced by autocommands, e.g. the netrw plugin). - */ -void -ex_diffupdate ( - exarg_T *eap /* can be NULL */ -) +/// Completely update the diffs for the buffers involved. +/// +/// This uses the ordinary "diff" command. +/// The buffers are written to a file, also for unmodified buffers (the file +/// could have been produced by autocommands, e.g. the netrw plugin). +/// +/// @param eap can be NULL +void ex_diffupdate(exarg_T *eap) { - buf_T *buf; - int idx_orig; - int idx_new; - char_u *tmp_orig; - char_u *tmp_new; - char_u *tmp_diff; - FILE *fd; - int ok; - int io_error = FALSE; - - /* Delete all diffblocks. */ + // Delete all diffblocks. diff_clear(curtab); curtab->tp_diff_invalid = FALSE; - /* Use the first buffer as the original text. */ - for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) - if (curtab->tp_diffbuf[idx_orig] != NULL) + // Use the first buffer as the original text. + int idx_orig; + for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) { + if (curtab->tp_diffbuf[idx_orig] != NULL) { break; - if (idx_orig == DB_COUNT) + } + } + + if (idx_orig == DB_COUNT) { return; + } - /* Only need to do something when there is another buffer. */ - for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) - if (curtab->tp_diffbuf[idx_new] != NULL) + // Only need to do something when there is another buffer. + int idx_new; + for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) { + if (curtab->tp_diffbuf[idx_new] != NULL) { break; - if (idx_new == DB_COUNT) + } + } + + if (idx_new == DB_COUNT) { return; + } + + // We need three temp file names. + char_u *tmp_orig = vim_tempname('o'); + char_u *tmp_new = vim_tempname('n'); + char_u *tmp_diff = vim_tempname('d'); - /* We need three temp file names. */ - tmp_orig = vim_tempname('o'); - tmp_new = vim_tempname('n'); - tmp_diff = vim_tempname('d'); - if (tmp_orig == NULL || tmp_new == NULL || tmp_diff == NULL) + if ((tmp_orig == NULL) || (tmp_new == NULL) || (tmp_diff == NULL)) { goto theend; + } - /* - * Do a quick test if "diff" really works. Otherwise it looks like there - * are no differences. Can't use the return value, it's non-zero when - * there are differences. - * May try twice, first with "-a" and then without. - */ - for (;; ) { + // Do a quick test if "diff" really works. Otherwise it looks like there + // are no differences. Can't use the return value, it's non-zero when + // there are differences. + // May try twice, first with "-a" and then without. + int io_error = FALSE; + int ok = FALSE; + for (;;) { ok = FALSE; - fd = mch_fopen((char *)tmp_orig, "w"); - if (fd == NULL) + FILE *fd = mch_fopen((char *)tmp_orig, "w"); + + if (fd == NULL) { io_error = TRUE; - else { - if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) + } else { + if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) { io_error = TRUE; + } fclose(fd); fd = mch_fopen((char *)tmp_new, "w"); - if (fd == NULL) + + if (fd == NULL) { io_error = TRUE; - else { - if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) + } else { + if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) { io_error = TRUE; + } fclose(fd); diff_file(tmp_orig, tmp_new, tmp_diff); fd = mch_fopen((char *)tmp_diff, "r"); - if (fd == NULL) + + if (fd == NULL) { io_error = TRUE; - else { + } else { char_u linebuf[LBUFLEN]; - for (;; ) { - /* There must be a line that contains "1c1". */ - if (tag_fgets(linebuf, LBUFLEN, fd)) + for (;;) { + // There must be a line that contains "1c1". + if (tag_fgets(linebuf, LBUFLEN, fd)) { break; - if (STRNCMP(linebuf, "1c1", 3) == 0) + } + + if (STRNCMP(linebuf, "1c1", 3) == 0) { ok = TRUE; + } } fclose(fd); } @@ -658,58 +735,68 @@ ex_diffupdate ( mch_remove(tmp_orig); } - /* When using 'diffexpr' break here. */ - if (*p_dex != NUL) + // When using 'diffexpr' break here. + if (*p_dex != NUL) { break; + } - - /* If we checked if "-a" works already, break here. */ - if (diff_a_works != MAYBE) + // If we checked if "-a" works already, break here. + if (diff_a_works != MAYBE) { break; + } diff_a_works = ok; - /* If "-a" works break here, otherwise retry without "-a". */ - if (ok) + // If "-a" works break here, otherwise retry without "-a". + if (ok) { break; + } } + if (!ok) { - if (io_error) + if (io_error) { EMSG(_("E810: Cannot read or write temp files")); + } EMSG(_("E97: Cannot create diffs")); diff_a_works = MAYBE; goto theend; } - /* :diffupdate! */ - if (eap != NULL && eap->forceit) + // :diffupdate! + if ((eap != NULL) && eap->forceit) { for (idx_new = idx_orig; idx_new < DB_COUNT; ++idx_new) { - buf = curtab->tp_diffbuf[idx_new]; - if (buf_valid(buf)) + buf_T *buf = curtab->tp_diffbuf[idx_new]; + if (buf_valid(buf)) { buf_check_timestamp(buf, FALSE); + } } + } - /* Write the first buffer to a tempfile. */ - buf = curtab->tp_diffbuf[idx_orig]; - if (diff_write(buf, tmp_orig) == FAIL) + // Write the first buffer to a tempfile. + buf_T *buf = curtab->tp_diffbuf[idx_orig]; + if (diff_write(buf, tmp_orig) == FAIL) { goto theend; + } - /* Make a difference between the first buffer and every other. */ + // Make a difference between the first buffer and every other. for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) { - buf = curtab->tp_diffbuf[idx_new]; - if (buf == NULL) + buf_T *buf = curtab->tp_diffbuf[idx_new]; + if (buf == NULL) { continue; - if (diff_write(buf, tmp_new) == FAIL) + } + + if (diff_write(buf, tmp_new) == FAIL) { continue; + } diff_file(tmp_orig, tmp_new, tmp_diff); - /* Read the diff output and add each entry to the diff list. */ + // Read the diff output and add each entry to the diff list. diff_read(idx_orig, idx_new, tmp_diff); mch_remove(tmp_diff); mch_remove(tmp_new); } mch_remove(tmp_orig); - /* force updating cursor position on screen */ + // force updating cursor position on screen curwin->w_valid_cursor.lnum = 0; diff_redraw(TRUE); @@ -720,141 +807,158 @@ theend: vim_free(tmp_diff); } -/* - * Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". - */ +/// Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". +/// +/// @param tmp_orig +/// @param tmp_new +/// @param tmp_diff static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) { - char_u *cmd; - size_t len; - - if (*p_dex != NUL) - /* Use 'diffexpr' to generate the diff file. */ + if (*p_dex != NUL) { + // Use 'diffexpr' to generate the diff file. eval_diff(tmp_orig, tmp_new, tmp_diff); - else { - len = STRLEN(tmp_orig) + STRLEN(tmp_new) - + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; - cmd = alloc((unsigned)len); + } else { + size_t len = STRLEN(tmp_orig) + STRLEN(tmp_new) + STRLEN(tmp_diff) + + STRLEN(p_srr) + 27; + char_u *cmd = alloc((unsigned)len); + if (cmd != NULL) { /* We don't want $DIFF_OPTIONS to get in the way. */ - if (mch_getenv("DIFF_OPTIONS")) + if (mch_getenv("DIFF_OPTIONS")) { vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); + } /* Build the diff command and execute it. Always use -a, binary * differences are of no use. Ignore errors, diff returns * non-zero when differences have been found. */ vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", - diff_a_works == FALSE ? "" : "-a ", - "", - (diff_flags & DIFF_IWHITE) ? "-b " : "", - (diff_flags & DIFF_ICASE) ? "-i " : "", - tmp_orig, tmp_new); + diff_a_works == FALSE ? "" : "-a ", + "", + (diff_flags & DIFF_IWHITE) ? "-b " : "", + (diff_flags & DIFF_ICASE) ? "-i " : "", + tmp_orig, tmp_new); append_redir(cmd, (int)len, p_srr, tmp_diff); - block_autocmds(); /* Avoid ShellCmdPost stuff */ - (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); + block_autocmds(); /* Avoid ShellCmdPost stuff */ + (void)call_shell(cmd, SHELL_FILTER | SHELL_SILENT | SHELL_DOOUT); unblock_autocmds(); vim_free(cmd); } } } -/* - * Create a new version of a file from the current buffer and a diff file. - * The buffer is written to a file, also for unmodified buffers (the file - * could have been produced by autocommands, e.g. the netrw plugin). - */ +/// Create a new version of a file from the current buffer and a diff file. +/// +/// The buffer is written to a file, also for unmodified buffers (the file +/// could have been produced by autocommands, e.g. the netrw plugin). +/// +/// @param eap void ex_diffpatch(exarg_T *eap) { - char_u *tmp_orig; /* name of original temp file */ - char_u *tmp_new; /* name of patched temp file */ - char_u *buf = NULL; - size_t buflen; - win_T *old_curwin = curwin; - char_u *newname = NULL; /* name of patched file buffer */ + char_u *buf = NULL; + win_T *old_curwin = curwin; + char_u *newname = NULL; // name of patched file buffer + #ifdef UNIX char_u dirbuf[MAXPATHL]; - char_u *fullname = NULL; -#endif + char_u *fullname = NULL; +#endif // ifdef UNIX struct stat st; + // We need two temp file names. + // Name of original temp file. + char_u *tmp_orig = vim_tempname('o'); + // Name of patched temp file. + char_u *tmp_new = vim_tempname('n'); - /* We need two temp file names. */ - tmp_orig = vim_tempname('o'); - tmp_new = vim_tempname('n'); - if (tmp_orig == NULL || tmp_new == NULL) + if ((tmp_orig == NULL) || (tmp_new == NULL)) { goto theend; + } - /* Write the current buffer to "tmp_orig". */ + // Write the current buffer to "tmp_orig". if (buf_write(curbuf, tmp_orig, NULL, - (linenr_T)1, curbuf->b_ml.ml_line_count, - NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) + (linenr_T)1, curbuf->b_ml.ml_line_count, + NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) { goto theend; + } #ifdef UNIX - /* Get the absolute path of the patchfile, changing directory below. */ + // Get the absolute path of the patchfile, changing directory below. fullname = FullName_save(eap->arg, FALSE); -#endif - buflen = STRLEN(tmp_orig) + ( -# ifdef UNIX - fullname != NULL ? STRLEN(fullname) : -# endif - STRLEN(eap->arg)) + STRLEN(tmp_new) + 16; +#endif // ifdef UNIX + +#ifdef UNIX + size_t buflen = STRLEN(tmp_orig) + + (fullname != NULL ? STRLEN(fullname) : STRLEN(eap->arg)) + + STRLEN(tmp_new) + 16; +#else + size_t buflen = STRLEN(tmp_orig) + (STRLEN(eap->arg)) + STRLEN(tmp_new) + 16; +#endif // ifdef UNIX + buf = alloc((unsigned)buflen); - if (buf == NULL) + if (buf == NULL) { goto theend; + } #ifdef UNIX - /* Temporarily chdir to /tmp, to avoid patching files in the current - * directory when the patch file contains more than one patch. When we - * have our own temp dir use that instead, it will be cleaned up when we - * exit (any .rej files created). Don't change directory if we can't - * return to the current. */ - if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) + + // Temporarily chdir to /tmp, to avoid patching files in the current + // directory when the patch file contains more than one patch. When we + // have our own temp dir use that instead, it will be cleaned up when we + // exit (any .rej files created). Don't change directory if we can't + // return to the current. + if ((mch_dirname(dirbuf, MAXPATHL) != OK) + || (mch_chdir((char *)dirbuf) != 0)) { dirbuf[0] = NUL; - else { + } else { # ifdef TEMPDIRNAMES - if (vim_tempdir != NULL) + if (vim_tempdir != NULL) { ignored = mch_chdir((char *)vim_tempdir); - else -# endif + } else { + ignored = mch_chdir("/tmp"); + } +# else ignored = mch_chdir("/tmp"); +# endif // ifdef TEMPDIRNAMES shorten_fnames(TRUE); } -#endif - - if (*p_pex != NUL) - /* Use 'patchexpr' to generate the new file. */ - eval_patch(tmp_orig, -# ifdef UNIX - fullname != NULL ? fullname : -# endif - eap->arg, tmp_new); - else { - /* Build the patch command and execute it. Ignore errors. Switch to - * cooked mode to allow the user to respond to prompts. */ +#endif // ifdef UNIX + + if (*p_pex != NUL) { + // Use 'patchexpr' to generate the new file. +#ifdef UNIX + eval_patch(tmp_orig, fullname != NULL ? fullname : eap->arg, tmp_new); +#else + eval_patch(tmp_orig, eap->arg, tmp_new); +#endif // ifdef UNIX + } else { + // Build the patch command and execute it. Ignore errors. Switch to + // cooked mode to allow the user to respond to prompts. +#ifdef UNIX vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", - tmp_new, tmp_orig, -# ifdef UNIX - fullname != NULL ? fullname : -# endif - eap->arg); - block_autocmds(); /* Avoid ShellCmdPost stuff */ + tmp_new, tmp_orig, fullname != NULL ? fullname : eap->arg); +#else + vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", + tmp_new, tmp_orig, eap->arg); +#endif // ifdef UNIX + // Avoid ShellCmdPost stuff + block_autocmds(); (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); unblock_autocmds(); } #ifdef UNIX if (dirbuf[0] != NUL) { - if (mch_chdir((char *)dirbuf) != 0) + if (mch_chdir((char *)dirbuf) != 0) { EMSG(_(e_prev_dir)); + } shorten_fnames(TRUE); } -#endif +#endif // ifdef UNIX - /* patch probably has written over the screen */ + // patch probably has written over the screen redraw_later(CLEAR); - /* Delete any .orig or .rej file created. */ + // Delete any .orig or .rej file created. STRCPY(buf, tmp_new); STRCAT(buf, ".orig"); mch_remove(buf); @@ -862,128 +966,137 @@ void ex_diffpatch(exarg_T *eap) STRCAT(buf, ".rej"); mch_remove(buf); - /* Only continue if the output file was created. */ - if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) + // Only continue if the output file was created. + if ((mch_stat((char *)tmp_new, &st) < 0) || (st.st_size == 0)) { EMSG(_("E816: Cannot read patch output")); - else { + } else { if (curbuf->b_fname != NULL) { newname = vim_strnsave(curbuf->b_fname, - (int)(STRLEN(curbuf->b_fname) + 4)); - if (newname != NULL) + (int)(STRLEN(curbuf->b_fname) + 4)); + + if (newname != NULL) { STRCAT(newname, ".new"); + } } - /* don't use a new tab page, each tab page has its own diffs */ + // don't use a new tab page, each tab page has its own diffs cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { - /* Pretend it was a ":split fname" command */ + // Pretend it was a ":split fname" command eap->cmdidx = CMD_split; eap->arg = tmp_new; do_exedit(eap, old_curwin); - /* check that split worked and editing tmp_new */ - if (curwin != old_curwin && win_valid(old_curwin)) { - /* Set 'diff', 'scrollbind' on and 'wrap' off. */ + // check that split worked and editing tmp_new + if ((curwin != old_curwin) && win_valid(old_curwin)) { + // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); diff_win_options(old_curwin, TRUE); if (newname != NULL) { - /* do a ":file filename.new" on the patched buffer */ + // do a ":file filename.new" on the patched buffer eap->arg = newname; ex_file(eap); - /* Do filetype detection with the new name. */ - if (au_has_group((char_u *)"filetypedetect")) + // Do filetype detection with the new name. + if (au_has_group((char_u *)"filetypedetect")) { do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); + } } } } } theend: - if (tmp_orig != NULL) + if (tmp_orig != NULL) { mch_remove(tmp_orig); + } vim_free(tmp_orig); - if (tmp_new != NULL) + + if (tmp_new != NULL) { mch_remove(tmp_new); + } vim_free(tmp_new); vim_free(newname); vim_free(buf); #ifdef UNIX vim_free(fullname); -#endif +#endif // ifdef UNIX } -/* - * Split the window and edit another file, setting options to show the diffs. - */ +/// Split the window and edit another file, setting options to show the diffs. +/// +/// @param eap void ex_diffsplit(exarg_T *eap) { - win_T *old_curwin = curwin; + win_T *old_curwin = curwin; - /* don't use a new tab page, each tab page has its own diffs */ + // don't use a new tab page, each tab page has its own diffs cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { - /* Pretend it was a ":split fname" command */ + // Pretend it was a ":split fname" command eap->cmdidx = CMD_split; curwin->w_p_diff = TRUE; do_exedit(eap, old_curwin); - if (curwin != old_curwin) { /* split must have worked */ - /* Set 'diff', 'scrollbind' on and 'wrap' off. */ + // split must have worked + if (curwin != old_curwin) { + // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); diff_win_options(old_curwin, TRUE); } } } -/* - * Set options to show diffs for the current window. - */ +// Set options to show diffs for the current window. void ex_diffthis(exarg_T *eap) { - /* Set 'diff', 'scrollbind' on and 'wrap' off. */ + // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); } -/* - * Set options in window "wp" for diff mode. - */ -void -diff_win_options ( - win_T *wp, - int addbuf /* Add buffer to diff. */ -) +/// Set options in window "wp" for diff mode. +/// +/// @param addbuf Add buffer to diff. +void diff_win_options(win_T *wp, int addbuf) { win_T *old_curwin = curwin; - /* close the manually opened folds */ + // close the manually opened folds curwin = wp; newFoldLevel(); curwin = old_curwin; wp->w_p_diff = TRUE; - /* Use 'scrollbind' and 'cursorbind' when available */ - if (!wp->w_p_diff_saved) + // Use 'scrollbind' and 'cursorbind' when available + if (!wp->w_p_diff_saved) { wp->w_p_scb_save = wp->w_p_scb; + } wp->w_p_scb = TRUE; - if (!wp->w_p_diff_saved) + + if (!wp->w_p_diff_saved) { wp->w_p_crb_save = wp->w_p_crb; + } wp->w_p_crb = TRUE; - if (!wp->w_p_diff_saved) + + if (!wp->w_p_diff_saved) { wp->w_p_wrap_save = wp->w_p_wrap; + } wp->w_p_wrap = FALSE; curwin = wp; curbuf = curwin->w_buffer; - if (!wp->w_p_diff_saved) + + if (!wp->w_p_diff_saved) { wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); + } set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff", - OPT_LOCAL|OPT_FREE, 0); + OPT_LOCAL | OPT_FREE, 0); curwin = old_curwin; curbuf = curwin->w_buffer; + if (!wp->w_p_diff_saved) { wp->w_p_fdc_save = wp->w_p_fdc; wp->w_p_fen_save = wp->w_p_fen; @@ -993,69 +1106,88 @@ diff_win_options ( wp->w_p_fen = TRUE; wp->w_p_fdl = 0; foldUpdateAll(wp); - /* make sure topline is not halfway a fold */ + + // make sure topline is not halfway a fold changed_window_setting_win(wp); - if (vim_strchr(p_sbo, 'h') == NULL) + if (vim_strchr(p_sbo, 'h') == NULL) { do_cmdline_cmd((char_u *)"set sbo+=hor"); - /* Saved the current values, to be restored in ex_diffoff(). */ + } + + // Saved the current values, to be restored in ex_diffoff(). wp->w_p_diff_saved = TRUE; - if (addbuf) + if (addbuf) { diff_buf_add(wp->w_buffer); + } redraw_win_later(wp, NOT_VALID); } -/* - * Set options not to show diffs. For the current window or all windows. - * Only in the current tab page. - */ +/// Set options not to show diffs. For the current window or all windows. +/// Only in the current tab page. +/// +/// @param eap void ex_diffoff(exarg_T *eap) { - win_T *wp; - win_T *old_curwin = curwin; + win_T *old_curwin = curwin; int diffwin = FALSE; + win_T *wp; for (wp = firstwin; wp != NULL; wp = wp->w_next) { - if (eap->forceit ? wp->w_p_diff : wp == curwin) { - /* Set 'diff', 'scrollbind' off and 'wrap' on. If option values - * were saved in diff_win_options() restore them. */ + if (eap->forceit ? wp->w_p_diff : (wp == curwin)) { + // Set 'diff', 'scrollbind' off and 'wrap' on. If option values + // were saved in diff_win_options() restore them. wp->w_p_diff = FALSE; - if (wp->w_p_scb) + if (wp->w_p_scb) { wp->w_p_scb = wp->w_p_diff_saved ? wp->w_p_scb_save : FALSE; - if (wp->w_p_crb) + } + + if (wp->w_p_crb) { wp->w_p_crb = wp->w_p_diff_saved ? wp->w_p_crb_save : FALSE; - if (!wp->w_p_wrap) + } + + if (!wp->w_p_wrap) { wp->w_p_wrap = wp->w_p_diff_saved ? wp->w_p_wrap_save : TRUE; + } curwin = wp; curbuf = curwin->w_buffer; + if (wp->w_p_diff_saved) { free_string_option(wp->w_p_fdm); wp->w_p_fdm = wp->w_p_fdm_save; wp->w_p_fdm_save = empty_option; - } else + } else { set_string_option_direct((char_u *)"fdm", -1, - (char_u *)"manual", OPT_LOCAL|OPT_FREE, 0); + (char_u *)"manual", OPT_LOCAL | OPT_FREE, 0); + } curwin = old_curwin; curbuf = curwin->w_buffer; - if (wp->w_p_fdc == diff_foldcolumn) + + if (wp->w_p_fdc == diff_foldcolumn) { wp->w_p_fdc = wp->w_p_diff_saved ? wp->w_p_fdc_save : 0; - if (wp->w_p_fdl == 0 && wp->w_p_diff_saved) + } + + if ((wp->w_p_fdl == 0) + && wp->w_p_diff_saved) { wp->w_p_fdl = wp->w_p_fdl_save; + } if (wp->w_p_fen) { - /* Only restore 'foldenable' when 'foldmethod' is not - * "manual", otherwise we continue to show the diff folds. */ - if (foldmethodIsManual(wp) || !wp->w_p_diff_saved) + // Only restore 'foldenable' when 'foldmethod' is not + // "manual", otherwise we continue to show the diff folds. + if (foldmethodIsManual(wp) || !wp->w_p_diff_saved) { wp->w_p_fen = FALSE; - else + } else { wp->w_p_fen = wp->w_p_fen_save; + } } foldUpdateAll(wp); - /* make sure topline is not halfway a fold */ + + // make sure topline is not halfway a fold changed_window_setting_win(wp); - /* Note: 'sbo' is not restored, it's a global option. */ + + // Note: 'sbo' is not restored, it's a global option. diff_buf_adjust(wp); wp->w_p_diff_saved = FALSE; @@ -1063,176 +1195,207 @@ void ex_diffoff(exarg_T *eap) diffwin |= wp->w_p_diff; } - /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ - if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) + // Remove "hor" from from 'scrollopt' if there are no diff windows left. + if (!diffwin && (vim_strchr(p_sbo, 'h') != NULL)) { do_cmdline_cmd((char_u *)"set sbo-=hor"); + } } -/* - * Read the diff output and add each entry to the diff list. - */ -static void -diff_read ( - int idx_orig, /* idx of original file */ - int idx_new, /* idx of new file */ - char_u *fname /* name of diff output file */ -) +/// Read the diff output and add each entry to the diff list. +/// +/// @param idx_orig idx of original file +/// @param idx_new idx of new file +/// @param fname name of diff output file +static void diff_read(int idx_orig, int idx_new, char_u *fname) { - FILE *fd; - diff_T *dprev = NULL; - diff_T *dp = curtab->tp_first_diff; - diff_T *dn, *dpl; + FILE *fd; + diff_T *dprev = NULL; + diff_T *dp = curtab->tp_first_diff; + diff_T *dn, *dpl; long f1, l1, f2, l2; - char_u linebuf[LBUFLEN]; /* only need to hold the diff line */ + char_u linebuf[LBUFLEN]; // only need to hold the diff line int difftype; - char_u *p; + char_u *p; long off; int i; linenr_T lnum_orig, lnum_new; long count_orig, count_new; - int notset = TRUE; /* block "*dp" not set yet */ + int notset = TRUE; // block "*dp" not set yet fd = mch_fopen((char *)fname, "r"); + if (fd == NULL) { EMSG(_("E98: Cannot read diff output")); return; } - for (;; ) { - if (tag_fgets(linebuf, LBUFLEN, fd)) - break; /* end of file */ - if (!isdigit(*linebuf)) - continue; /* not the start of a diff block */ + for (;;) { + if (tag_fgets(linebuf, LBUFLEN, fd)) { + // end of file + break; + } - /* This line must be one of three formats: - * {first}[,{last}]c{first}[,{last}] - * {first}a{first}[,{last}] - * {first}[,{last}]d{first} - */ + if (!isdigit(*linebuf)) { + // not the start of a diff block + continue; + } + + // This line must be one of three formats: + // {first}[,{last}]c{first}[,{last}] + // {first}a{first}[,{last}] + // {first}[,{last}]d{first} p = linebuf; f1 = getdigits(&p); + if (*p == ',') { ++p; l1 = getdigits(&p); - } else + } else { l1 = f1; - if (*p != 'a' && *p != 'c' && *p != 'd') - continue; /* invalid diff format */ + } + + if ((*p != 'a') && (*p != 'c') && (*p != 'd')) { + // invalid diff format + continue; + } difftype = *p++; f2 = getdigits(&p); + if (*p == ',') { ++p; l2 = getdigits(&p); - } else + } else { l2 = f2; - if (l1 < f1 || l2 < f2) - continue; /* invalid line range */ + } + + if ((l1 < f1) || (l2 < f2)) { + // invalid line range + continue; + } if (difftype == 'a') { lnum_orig = f1 + 1; count_orig = 0; - } else { + } else { lnum_orig = f1; count_orig = l1 - f1 + 1; } + if (difftype == 'd') { lnum_new = f2 + 1; count_new = 0; - } else { + } else { lnum_new = f2; count_new = l2 - f2 + 1; } - /* Go over blocks before the change, for which orig and new are equal. - * Copy blocks from orig to new. */ + // Go over blocks before the change, for which orig and new are equal. + // Copy blocks from orig to new. while (dp != NULL && lnum_orig > dp->df_lnum[idx_orig] + dp->df_count[idx_orig]) { - if (notset) + if (notset) { diff_copy_entry(dprev, dp, idx_orig, idx_new); + } dprev = dp; dp = dp->df_next; notset = TRUE; } - if (dp != NULL - && lnum_orig <= dp->df_lnum[idx_orig] + dp->df_count[idx_orig] - && lnum_orig + count_orig >= dp->df_lnum[idx_orig]) { - /* New block overlaps with existing block(s). - * First find last block that overlaps. */ - for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) - if (lnum_orig + count_orig < dpl->df_next->df_lnum[idx_orig]) + if ((dp != NULL) + && (lnum_orig <= dp->df_lnum[idx_orig] + dp->df_count[idx_orig]) + && (lnum_orig + count_orig >= dp->df_lnum[idx_orig])) { + // New block overlaps with existing block(s). + // First find last block that overlaps. + for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) { + if (lnum_orig + count_orig < dpl->df_next->df_lnum[idx_orig]) { break; + } + } - /* If the newly found block starts before the old one, set the - * start back a number of lines. */ + // If the newly found block starts before the old one, set the + // start back a number of lines. off = dp->df_lnum[idx_orig] - lnum_orig; + if (off > 0) { - for (i = idx_orig; i < idx_new; ++i) - if (curtab->tp_diffbuf[i] != NULL) + for (i = idx_orig; i < idx_new; ++i) { + if (curtab->tp_diffbuf[i] != NULL) { dp->df_lnum[i] -= off; + } + } dp->df_lnum[idx_new] = lnum_new; dp->df_count[idx_new] = count_new; - } else if (notset) { - /* new block inside existing one, adjust new block */ + } else if (notset) { + // new block inside existing one, adjust new block dp->df_lnum[idx_new] = lnum_new + off; dp->df_count[idx_new] = count_new - off; - } else - /* second overlap of new block with existing block */ + } else { + // second overlap of new block with existing block dp->df_count[idx_new] += count_new - count_orig + dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig] - (dp->df_lnum[idx_orig] + dp->df_count[idx_orig]); + } - /* Adjust the size of the block to include all the lines to the - * end of the existing block or the new diff, whatever ends last. */ + // Adjust the size of the block to include all the lines to the + // end of the existing block or the new diff, whatever ends last. off = (lnum_orig + count_orig) - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); + if (off < 0) { - /* new change ends in existing block, adjust the end if not - * done already */ - if (notset) + // new change ends in existing block, adjust the end if not + // done already + if (notset) { dp->df_count[idx_new] += -off; + } off = 0; } - for (i = idx_orig; i < idx_new; ++i) - if (curtab->tp_diffbuf[i] != NULL) + + for (i = idx_orig; i < idx_new; ++i) { + if (curtab->tp_diffbuf[i] != NULL) { dp->df_count[i] = dpl->df_lnum[i] + dpl->df_count[i] - dp->df_lnum[i] + off; + } + } - /* Delete the diff blocks that have been merged into one. */ + // Delete the diff blocks that have been merged into one. dn = dp->df_next; dp->df_next = dpl->df_next; + while (dn != dp->df_next) { dpl = dn->df_next; vim_free(dn); dn = dpl; } - } else { - /* Allocate a new diffblock. */ + } else { + // Allocate a new diffblock. dp = diff_alloc_new(curtab, dprev, dp); - if (dp == NULL) + if (dp == NULL) { goto done; + } dp->df_lnum[idx_orig] = lnum_orig; dp->df_count[idx_orig] = count_orig; dp->df_lnum[idx_new] = lnum_new; dp->df_count[idx_new] = count_new; - /* Set values for other buffers, these must be equal to the - * original buffer, otherwise there would have been a change - * already. */ - for (i = idx_orig + 1; i < idx_new; ++i) - if (curtab->tp_diffbuf[i] != NULL) + // Set values for other buffers, these must be equal to the + // original buffer, otherwise there would have been a change + // already. + for (i = idx_orig + 1; i < idx_new; ++i) { + if (curtab->tp_diffbuf[i] != NULL) { diff_copy_entry(dprev, dp, idx_orig, i); + } + } } - notset = FALSE; /* "*dp" has been set */ + notset = FALSE; // "*dp" has been set } - /* for remaining diff blocks orig and new are equal */ + // for remaining diff blocks orig and new are equal while (dp != NULL) { - if (notset) + if (notset) { diff_copy_entry(dprev, dp, idx_orig, idx_new); + } dprev = dp; dp = dp->df_next; notset = TRUE; @@ -1242,29 +1405,34 @@ done: fclose(fd); } -/* - * Copy an entry at "dp" from "idx_orig" to "idx_new". - */ -static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new) +/// Copy an entry at "dp" from "idx_orig" to "idx_new". +/// +/// @param dprev +/// @param dp +/// @param idx_orig +/// @param idx_new +static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, + int idx_new) { long off; - if (dprev == NULL) + if (dprev == NULL) { off = 0; - else + } else { off = (dprev->df_lnum[idx_orig] + dprev->df_count[idx_orig]) - (dprev->df_lnum[idx_new] + dprev->df_count[idx_new]); + } dp->df_lnum[idx_new] = dp->df_lnum[idx_orig] - off; dp->df_count[idx_new] = dp->df_count[idx_orig]; } -/* - * Clear the list of diffblocks for tab page "tp". - */ +/// Clear the list of diffblocks for tab page "tp". +/// +/// @param tp void diff_clear(tabpage_T *tp) { - diff_T *p, *next_p; - + diff_T *p; + diff_T *next_p; for (p = tp->tp_first_diff; p != NULL; p = next_p) { next_p = p->df_next; vim_free(p); @@ -1272,343 +1440,419 @@ void diff_clear(tabpage_T *tp) tp->tp_first_diff = NULL; } -/* - * Check diff status for line "lnum" in buffer "buf": - * Returns 0 for nothing special - * Returns -1 for a line that should be highlighted as changed. - * Returns -2 for a line that should be highlighted as added/deleted. - * Returns > 0 for inserting that many filler lines above it (never happens - * when 'diffopt' doesn't contain "filler"). - * This should only be used for windows where 'diff' is set. - */ +/// Check diff status for line "lnum" in buffer "buf": +/// +/// Returns 0 for nothing special +/// Returns -1 for a line that should be highlighted as changed. +/// Returns -2 for a line that should be highlighted as added/deleted. +/// Returns > 0 for inserting that many filler lines above it (never happens +/// when 'diffopt' doesn't contain "filler"). +/// This should only be used for windows where 'diff' is set. +/// +/// @param wp +/// @param lnum +/// +/// @return diff status. int diff_check(win_T *wp, linenr_T lnum) { - int idx; /* index in tp_diffbuf[] for this buffer */ - diff_T *dp; + int idx; // index in tp_diffbuf[] for this buffer + diff_T *dp; int maxcount; int i; - buf_T *buf = wp->w_buffer; + buf_T *buf = wp->w_buffer; int cmp; - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } - if (curtab->tp_first_diff == NULL || !wp->w_p_diff) /* no diffs at all */ + // no diffs at all + if ((curtab->tp_first_diff == NULL) || !wp->w_p_diff) { return 0; + } - /* safety check: "lnum" must be a buffer line */ - if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) + // safety check: "lnum" must be a buffer line + if ((lnum < 1) || (lnum > buf->b_ml.ml_line_count + 1)) { return 0; + } idx = diff_buf_idx(buf); - if (idx == DB_COUNT) - return 0; /* no diffs for buffer "buf" */ - /* A closed fold never has filler lines. */ - if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) + if (idx == DB_COUNT) { + // no diffs for buffer "buf" return 0; + } + + // A closed fold never has filler lines. + if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) { + return 0; + } - /* search for a change that includes "lnum" in the list of diffblocks. */ - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) - if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) + // search for a change that includes "lnum" in the list of diffblocks. + for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { + if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) { break; - if (dp == NULL || lnum < dp->df_lnum[idx]) + } + } + + if ((dp == NULL) || (lnum < dp->df_lnum[idx])) { return 0; + } if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) { int zero = FALSE; - /* Changed or inserted line. If the other buffers have a count of - * zero, the lines were inserted. If the other buffers have the same - * count, check if the lines are identical. */ + // Changed or inserted line. If the other buffers have a count of + // zero, the lines were inserted. If the other buffers have the same + // count, check if the lines are identical. cmp = FALSE; - for (i = 0; i < DB_COUNT; ++i) - if (i != idx && curtab->tp_diffbuf[i] != NULL) { - if (dp->df_count[i] == 0) + + for (i = 0; i < DB_COUNT; ++i) { + if ((i != idx) && (curtab->tp_diffbuf[i] != NULL)) { + if (dp->df_count[i] == 0) { zero = TRUE; - else { - if (dp->df_count[i] != dp->df_count[idx]) - return -1; /* nr of lines changed. */ + } else { + if (dp->df_count[i] != dp->df_count[idx]) { + // nr of lines changed. + return -1; + } cmp = TRUE; } } + } + if (cmp) { - /* Compare all lines. If they are equal the lines were inserted - * in some buffers, deleted in others, but not changed. */ - for (i = 0; i < DB_COUNT; ++i) - if (i != idx && curtab->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) - if (!diff_equal_entry(dp, idx, i)) + // Compare all lines. If they are equal the lines were inserted + // in some buffers, deleted in others, but not changed. + for (i = 0; i < DB_COUNT; ++i) { + if ((i != idx) + && (curtab->tp_diffbuf[i] != NULL) + && (dp->df_count[i] != 0)) { + if (!diff_equal_entry(dp, idx, i)) { return -1; + } + } + } } - /* If there is no buffer with zero lines then there is no difference - * any longer. Happens when making a change (or undo) that removes - * the difference. Can't remove the entry here, we might be halfway - * updating the window. Just report the text as unchanged. Other - * windows might still show the change though. */ - if (zero == FALSE) + + // If there is no buffer with zero lines then there is no difference + // any longer. Happens when making a change (or undo) that removes + // the difference. Can't remove the entry here, we might be halfway + // updating the window. Just report the text as unchanged. Other + // windows might still show the change though. + if (zero == FALSE) { return 0; + } return -2; } - /* If 'diffopt' doesn't contain "filler", return 0. */ - if (!(diff_flags & DIFF_FILLER)) + // If 'diffopt' doesn't contain "filler", return 0. + if (!(diff_flags & DIFF_FILLER)) { return 0; + } - /* Insert filler lines above the line just below the change. Will return - * 0 when this buf had the max count. */ + // Insert filler lines above the line just below the change. Will return + // 0 when this buf had the max count. maxcount = 0; - for (i = 0; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) + for (i = 0; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] != NULL) && (dp->df_count[i] > maxcount)) { maxcount = dp->df_count[i]; + } + } return maxcount - dp->df_count[idx]; } -/* - * Compare two entries in diff "*dp" and return TRUE if they are equal. - */ +/// Compare two entries in diff "*dp" and return TRUE if they are equal. +/// +/// @param dp +/// @param idx1 First entry in diff "*dp" +/// @param idx2 Second entry in diff "*dp" +/// +/// @return return TRUE if two entires are equal. static int diff_equal_entry(diff_T *dp, int idx1, int idx2) { - int i; - char_u *line; - int cmp; - - if (dp->df_count[idx1] != dp->df_count[idx2]) + if (dp->df_count[idx1] != dp->df_count[idx2]) { return FALSE; - if (diff_check_sanity(curtab, dp) == FAIL) + } + + if (diff_check_sanity(curtab, dp) == FAIL) { return FALSE; + } + + int i; for (i = 0; i < dp->df_count[idx1]; ++i) { - line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], - dp->df_lnum[idx1] + i, FALSE)); - if (line == NULL) + char_u *line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], + dp->df_lnum[idx1] + i, FALSE)); + + if (line == NULL) { return FALSE; - cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], - dp->df_lnum[idx2] + i, FALSE)); + } + int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], + dp->df_lnum[idx2] + i, FALSE)); vim_free(line); - if (cmp != 0) + + if (cmp != 0) { return FALSE; + } } return TRUE; } -/* - * Compare strings "s1" and "s2" according to 'diffopt'. - * Return non-zero when they are different. - */ +/// Compare strings "s1" and "s2" according to 'diffopt'. +/// Return non-zero when they are different. +/// +/// @param s1 The first string +/// @param s2 The second string +/// +/// @return on-zero if the two strings are different. static int diff_cmp(char_u *s1, char_u *s2) { - char_u *p1, *p2; - int l; - - if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) + if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) { return STRCMP(s1, s2); - if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) + } + + if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) { return MB_STRICMP(s1, s2); + } + + // Ignore white space changes and possibly ignore case. + char_u *p1 = s1; + char_u *p2 = s2; - /* Ignore white space changes and possibly ignore case. */ - p1 = s1; - p2 = s2; while (*p1 != NUL && *p2 != NUL) { if (vim_iswhite(*p1) && vim_iswhite(*p2)) { p1 = skipwhite(p1); p2 = skipwhite(p2); - } else { - l = (*mb_ptr2len)(p1); - if (l != (*mb_ptr2len)(p2)) + } else { + int l = (*mb_ptr2len)(p1); + if (l != (*mb_ptr2len)(p2)) { break; + } + if (l > 1) { - if (STRNCMP(p1, p2, l) != 0 + if ((STRNCMP(p1, p2, l) != 0) && (!enc_utf8 || !(diff_flags & DIFF_ICASE) - || utf_fold(utf_ptr2char(p1)) - != utf_fold(utf_ptr2char(p2)))) + || (utf_fold(utf_ptr2char(p1)) + != utf_fold(utf_ptr2char(p2))))) { break; + } p1 += l; p2 += l; - } else { - if (*p1 != *p2 && (!(diff_flags & DIFF_ICASE) - || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2))) + } else { + if ((*p1 != *p2) + && (!(diff_flags & DIFF_ICASE) + || (TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))) { break; + } ++p1; ++p2; } } } - /* Ignore trailing white space. */ + // Ignore trailing white space. p1 = skipwhite(p1); p2 = skipwhite(p2); - if (*p1 != NUL || *p2 != NUL) + + if ((*p1 != NUL) || (*p2 != NUL)) { return 1; + } return 0; } -/* - * Return the number of filler lines above "lnum". - */ +/// Return the number of filler lines above "lnum". +/// +/// @param wp +/// @param lnum +/// +/// @return Number of filler lines above lnum int diff_check_fill(win_T *wp, linenr_T lnum) { - int n; - - /* be quick when there are no filler lines */ - if (!(diff_flags & DIFF_FILLER)) + // be quick when there are no filler lines + if (!(diff_flags & DIFF_FILLER)) { return 0; - n = diff_check(wp, lnum); - if (n <= 0) + } + int n = diff_check(wp, lnum); + + if (n <= 0) { return 0; + } return n; } -/* - * Set the topline of "towin" to match the position in "fromwin", so that they - * show the same diff'ed lines. - */ +/// Set the topline of "towin" to match the position in "fromwin", so that they +/// show the same diff'ed lines. +/// +/// @param fromwin +/// @param towin void diff_set_topline(win_T *fromwin, win_T *towin) { - buf_T *frombuf = fromwin->w_buffer; + buf_T *frombuf = fromwin->w_buffer; linenr_T lnum = fromwin->w_topline; - int fromidx; - int toidx; - diff_T *dp; + diff_T *dp; int max_count; int i; - fromidx = diff_buf_idx(frombuf); - if (fromidx == DB_COUNT) - return; /* safety check */ - - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + int fromidx = diff_buf_idx(frombuf); + if (fromidx == DB_COUNT) { + // safety check + return; + } + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } towin->w_topfill = 0; - /* search for a change that includes "lnum" in the list of diffblocks. */ - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) - if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) + // search for a change that includes "lnum" in the list of diffblocks. + for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { + if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) { break; + } + } + if (dp == NULL) { - /* After last change, compute topline relative to end of file; no - * filler lines. */ + // After last change, compute topline relative to end of file; no + // filler lines. towin->w_topline = towin->w_buffer->b_ml.ml_line_count - (frombuf->b_ml.ml_line_count - lnum); - } else { - /* Find index for "towin". */ - toidx = diff_buf_idx(towin->w_buffer); - if (toidx == DB_COUNT) - return; /* safety check */ + } else { + // Find index for "towin". + int toidx = diff_buf_idx(towin->w_buffer); + if (toidx == DB_COUNT) { + // safety check + return; + } towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); + if (lnum >= dp->df_lnum[fromidx]) { - /* Inside a change: compute filler lines. With three or more - * buffers we need to know the largest count. */ + // Inside a change: compute filler lines. With three or more + // buffers we need to know the largest count. max_count = 0; - for (i = 0; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] != NULL - && max_count < dp->df_count[i]) + + for (i = 0; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] != NULL) && (max_count < dp->df_count[i])) { max_count = dp->df_count[i]; + } + } if (dp->df_count[toidx] == dp->df_count[fromidx]) { - /* same number of lines: use same filler count */ + // same number of lines: use same filler count towin->w_topfill = fromwin->w_topfill; } else if (dp->df_count[toidx] > dp->df_count[fromidx]) { if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) { - /* more lines in towin and fromwin doesn't show diff - * lines, only filler lines */ + // more lines in towin and fromwin doesn't show diff + // lines, only filler lines if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) { - /* towin also only shows filler lines */ - towin->w_topline = dp->df_lnum[toidx] - + dp->df_count[toidx]; + // towin also only shows filler lines + towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; towin->w_topfill = fromwin->w_topfill; - } else - /* towin still has some diff lines to show */ + } else { + // towin still has some diff lines to show towin->w_topline = dp->df_lnum[toidx] + max_count - fromwin->w_topfill; + } } } else if (towin->w_topline >= dp->df_lnum[toidx] + dp->df_count[toidx]) { - /* less lines in towin and no diff lines to show: compute - * filler lines */ + // less lines in towin and no diff lines to show: compute + // filler lines towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; + if (diff_flags & DIFF_FILLER) { - if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) - /* fromwin is also out of diff lines */ + if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) { + // fromwin is also out of diff lines towin->w_topfill = fromwin->w_topfill; - else - /* fromwin has some diff lines */ - towin->w_topfill = dp->df_lnum[fromidx] - + max_count - lnum; + } else { + // fromwin has some diff lines + towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum; + } } } } } - /* safety check (if diff info gets outdated strange things may happen) */ + // safety check (if diff info gets outdated strange things may happen) towin->w_botfill = FALSE; + if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) { towin->w_topline = towin->w_buffer->b_ml.ml_line_count; towin->w_botfill = TRUE; } + if (towin->w_topline < 1) { towin->w_topline = 1; towin->w_topfill = 0; } - /* When w_topline changes need to recompute w_botline and cursor position */ + // When w_topline changes need to recompute w_botline and cursor position invalidate_botline_win(towin); changed_line_abv_curs_win(towin); check_topfill(towin, FALSE); (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, - NULL, TRUE, NULL); + NULL, TRUE, NULL); } -/* - * This is called when 'diffopt' is changed. - */ -int diffopt_changed(void) { - char_u *p; +/// This is called when 'diffopt' is changed. +/// +/// @return +int diffopt_changed(void) +{ int diff_context_new = 6; int diff_flags_new = 0; int diff_foldcolumn_new = 2; - tabpage_T *tp; - p = p_dip; + char_u *p = p_dip; while (*p != NUL) { if (STRNCMP(p, "filler", 6) == 0) { p += 6; diff_flags_new |= DIFF_FILLER; - } else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) { + } else if ((STRNCMP(p, "context:", 8) == 0) && VIM_ISDIGIT(p[8])) { p += 8; diff_context_new = getdigits(&p); - } else if (STRNCMP(p, "icase", 5) == 0) { + } else if (STRNCMP(p, "icase", 5) == 0) { p += 5; diff_flags_new |= DIFF_ICASE; - } else if (STRNCMP(p, "iwhite", 6) == 0) { + } else if (STRNCMP(p, "iwhite", 6) == 0) { p += 6; diff_flags_new |= DIFF_IWHITE; - } else if (STRNCMP(p, "horizontal", 10) == 0) { + } else if (STRNCMP(p, "horizontal", 10) == 0) { p += 10; diff_flags_new |= DIFF_HORIZONTAL; - } else if (STRNCMP(p, "vertical", 8) == 0) { + } else if (STRNCMP(p, "vertical", 8) == 0) { p += 8; diff_flags_new |= DIFF_VERTICAL; - } else if (STRNCMP(p, "foldcolumn:", 11) == 0 && VIM_ISDIGIT(p[11])) { + } else if ((STRNCMP(p, "foldcolumn:", 11) == 0) && VIM_ISDIGIT(p[11])) { p += 11; diff_foldcolumn_new = getdigits(&p); } - if (*p != ',' && *p != NUL) + + if ((*p != ',') && (*p != NUL)) { return FAIL; - if (*p == ',') + } + + if (*p == ',') { ++p; + } } - /* Can't have both "horizontal" and "vertical". */ - if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) + // Can't have both "horizontal" and "vertical". + if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) { return FAIL; + } - /* If "icase" or "iwhite" was added or removed, need to update the diff. */ - if (diff_flags != diff_flags_new) - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) + // If "icase" or "iwhite" was added or removed, need to update the diff. + if (diff_flags != diff_flags_new) { + tabpage_T *tp; + for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { tp->tp_diff_invalid = TRUE; + } + } diff_flags = diff_flags_new; diff_context = diff_context_new; @@ -1616,273 +1860,311 @@ int diffopt_changed(void) { diff_redraw(TRUE); - /* recompute the scroll binding with the new option value, may - * remove or add filler lines */ + // recompute the scroll binding with the new option value, may + // remove or add filler lines check_scrollbind((linenr_T)0, 0L); - return OK; } -/* - * Return TRUE if 'diffopt' contains "horizontal". - */ -int diffopt_horizontal(void) { +/// Return TRUE if 'diffopt' contains "horizontal". +/// +/// @return TRUE if 'diffopt' contains "horizontal" +int diffopt_horizontal(void) { return (diff_flags & DIFF_HORIZONTAL) != 0; } -/* - * Find the difference within a changed line. - * Returns TRUE if the line was added, no other buffer has it. - */ -int -diff_find_change ( - win_T *wp, - linenr_T lnum, - int *startp, /* first char of the change */ - int *endp /* last char of the change */ -) +/// Find the difference within a changed line. +/// +/// @param startp first char of the change +/// @param endp last char of the change +/// +/// @returns TRUE if the line was added, no other buffer has it. +int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) { - char_u *line_org; - char_u *line_new; - int i; - int si_org, si_new; - int ei_org, ei_new; - diff_T *dp; - int idx; - int off; + char_u *line_new; + int si_org; + int si_new; + int ei_org; + int ei_new; int added = TRUE; - /* Make a copy of the line, the next ml_get() will invalidate it. */ - line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); - if (line_org == NULL) + // Make a copy of the line, the next ml_get() will invalidate it. + char_u *line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); + if (line_org == NULL) { return FALSE; + } - idx = diff_buf_idx(wp->w_buffer); - if (idx == DB_COUNT) { /* cannot happen */ + int idx = diff_buf_idx(wp->w_buffer); + if (idx == DB_COUNT) { + // cannot happen vim_free(line_org); return FALSE; } - /* search for a change that includes "lnum" in the list of diffblocks. */ - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) - if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) + // search for a change that includes "lnum" in the list of diffblocks. + diff_T *dp; + for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { + if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) { break; - if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) { + } + } + + if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) { vim_free(line_org); return FALSE; } - off = lnum - dp->df_lnum[idx]; - - for (i = 0; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] != NULL && i != idx) { - /* Skip lines that are not in the other change (filler lines). */ - if (off >= dp->df_count[i]) + int off = lnum - dp->df_lnum[idx]; + int i; + for (i = 0; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] != NULL) && (i != idx)) { + // Skip lines that are not in the other change (filler lines). + if (off >= dp->df_count[i]) { continue; + } added = FALSE; line_new = ml_get_buf(curtab->tp_diffbuf[i], - dp->df_lnum[i] + off, FALSE); + dp->df_lnum[i] + off, FALSE); - /* Search for start of difference */ + // Search for start of difference si_org = si_new = 0; + while (line_org[si_org] != NUL) { if ((diff_flags & DIFF_IWHITE) && vim_iswhite(line_org[si_org]) && vim_iswhite(line_new[si_new])) { si_org = (int)(skipwhite(line_org + si_org) - line_org); si_new = (int)(skipwhite(line_new + si_new) - line_new); - } else { - if (line_org[si_org] != line_new[si_new]) + } else { + if (line_org[si_org] != line_new[si_new]) { break; + } ++si_org; ++si_new; } } + if (has_mbyte) { - /* Move back to first byte of character in both lines (may - * have "nn^" in line_org and "n^ in line_new). */ + // Move back to first byte of character in both lines (may + // have "nn^" in line_org and "n^ in line_new). si_org -= (*mb_head_off)(line_org, line_org + si_org); si_new -= (*mb_head_off)(line_new, line_new + si_new); } - if (*startp > si_org) + + if (*startp > si_org) { *startp = si_org; + } - /* Search for end of difference, if any. */ - if (line_org[si_org] != NUL || line_new[si_new] != NUL) { + // Search for end of difference, if any. + if ((line_org[si_org] != NUL) || (line_new[si_new] != NUL)) { ei_org = (int)STRLEN(line_org); ei_new = (int)STRLEN(line_new); - while (ei_org >= *startp && ei_new >= si_new - && ei_org >= 0 && ei_new >= 0) { + + while (ei_org >= *startp + && ei_new >= si_new + && ei_org >= 0 + && ei_new >= 0) { if ((diff_flags & DIFF_IWHITE) && vim_iswhite(line_org[ei_org]) && vim_iswhite(line_new[ei_new])) { - while (ei_org >= *startp - && vim_iswhite(line_org[ei_org])) - --ei_org; - while (ei_new >= si_new - && vim_iswhite(line_new[ei_new])) - --ei_new; - } else { - if (line_org[ei_org] != line_new[ei_new]) + while (ei_org >= *startp && vim_iswhite(line_org[ei_org])) { + ei_org--; + } + + while (ei_new >= si_new && vim_iswhite(line_new[ei_new])) { + ei_new--; + } + } else { + if (line_org[ei_org] != line_new[ei_new]) { break; - --ei_org; - --ei_new; + } + ei_org--; + ei_new--; } } - if (*endp < ei_org) + + if (*endp < ei_org) { *endp = ei_org; + } } } + } vim_free(line_org); return added; } -/* - * Return TRUE if line "lnum" is not close to a diff block, this line should - * be in a fold. - * Return FALSE if there are no diff blocks at all in this window. - */ +/// Return TRUE if line "lnum" is not close to a diff block, this line should +/// be in a fold. +/// +/// @param wp +/// @param lnum +/// +/// @return FALSE if there are no diff blocks at all in this window. int diff_infold(win_T *wp, linenr_T lnum) { - int i; - int idx = -1; int other = FALSE; - diff_T *dp; + diff_T *dp; - /* Return if 'diff' isn't set. */ - if (!wp->w_p_diff) + // Return if 'diff' isn't set. + if (!wp->w_p_diff) { return FALSE; + } + int idx = -1; + int i; for (i = 0; i < DB_COUNT; ++i) { - if (curtab->tp_diffbuf[i] == wp->w_buffer) + if (curtab->tp_diffbuf[i] == wp->w_buffer) { idx = i; - else if (curtab->tp_diffbuf[i] != NULL) + } else if (curtab->tp_diffbuf[i] != NULL) { other = TRUE; + } } - /* return here if there are no diffs in the window */ - if (idx == -1 || !other) + // return here if there are no diffs in the window + if ((idx == -1) || !other) { return FALSE; + } - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } - /* Return if there are no diff blocks. All lines will be folded. */ - if (curtab->tp_first_diff == NULL) + // Return if there are no diff blocks. All lines will be folded. + if (curtab->tp_first_diff == NULL) { return TRUE; + } for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { - /* If this change is below the line there can't be any further match. */ - if (dp->df_lnum[idx] - diff_context > lnum) + // If this change is below the line there can't be any further match. + if (dp->df_lnum[idx] - diff_context > lnum) { break; - /* If this change ends before the line we have a match. */ - if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) + } + + // If this change ends before the line we have a match. + if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) { return FALSE; + } } return TRUE; } -/* - * "dp" and "do" commands. - */ +/// "dp" and "do" commands. +/// +/// @param put void nv_diffgetput(int put) { exarg_T ea; - ea.arg = (char_u *)""; - if (put) + if (put) { ea.cmdidx = CMD_diffput; - else + } else { ea.cmdidx = CMD_diffget; + } ea.addr_count = 0; ea.line1 = curwin->w_cursor.lnum; ea.line2 = curwin->w_cursor.lnum; ex_diffgetput(&ea); } -/* - * ":diffget" - * ":diffput" - */ +/// ":diffget" and ":diffput" +/// +/// @param eap void ex_diffgetput(exarg_T *eap) { linenr_T lnum; int count; linenr_T off = 0; - diff_T *dp; - diff_T *dprev; - diff_T *dfree; - int idx_cur; - int idx_other; - int idx_from; - int idx_to; + diff_T *dp; + diff_T *dprev; + diff_T *dfree; int i; int added; - char_u *p; + char_u *p; aco_save_T aco; - buf_T *buf; + buf_T *buf; int start_skip, end_skip; int new_count; int buf_empty; int found_not_ma = FALSE; + int idx_other; + int idx_from; + int idx_to; - /* Find the current buffer in the list of diff buffers. */ - idx_cur = diff_buf_idx(curbuf); + // Find the current buffer in the list of diff buffers. + int idx_cur = diff_buf_idx(curbuf); if (idx_cur == DB_COUNT) { EMSG(_("E99: Current buffer is not in diff mode")); return; } if (*eap->arg == NUL) { - /* No argument: Find the other buffer in the list of diff buffers. */ - for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) - if (curtab->tp_diffbuf[idx_other] != curbuf - && curtab->tp_diffbuf[idx_other] != NULL) { - if (eap->cmdidx != CMD_diffput - || curtab->tp_diffbuf[idx_other]->b_p_ma) + // No argument: Find the other buffer in the list of diff buffers. + for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) { + if ((curtab->tp_diffbuf[idx_other] != curbuf) + && (curtab->tp_diffbuf[idx_other] != NULL)) { + if ((eap->cmdidx != CMD_diffput) + || curtab->tp_diffbuf[idx_other]->b_p_ma) { break; + } found_not_ma = TRUE; } + } + if (idx_other == DB_COUNT) { - if (found_not_ma) + if (found_not_ma) { EMSG(_("E793: No other buffer in diff mode is modifiable")); - else + } else { EMSG(_("E100: No other buffer in diff mode")); + } return; } - /* Check that there isn't a third buffer in the list */ - for (i = idx_other + 1; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] != curbuf - && curtab->tp_diffbuf[i] != NULL - && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) { - EMSG(_( - "E101: More than two buffers in diff mode, don't know which one to use")); + // Check that there isn't a third buffer in the list + for (i = idx_other + 1; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] != curbuf) + && (curtab->tp_diffbuf[i] != NULL) + && ((eap->cmdidx != CMD_diffput) || curtab->tp_diffbuf[i]->b_p_ma)) { + EMSG(_("E101: More than two buffers in diff mode, don't know " + "which one to use")); return; } - } else { - /* Buffer number or pattern given. Ignore trailing white space. */ + } + } else { + // Buffer number or pattern given. Ignore trailing white space. p = eap->arg + STRLEN(eap->arg); - while (p > eap->arg && vim_iswhite(p[-1])) - --p; - for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) - ; - if (eap->arg + i == p) /* digits only */ + while (p > eap->arg && vim_iswhite(p[-1])) { + p--; + } + + for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) { + } + + if (eap->arg + i == p) { + // digits only i = atol((char *)eap->arg); - else { + } else { i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); - if (i < 0) - return; /* error message already given */ + + if (i < 0) { + // error message already given + return; + } } buf = buflist_findnr(i); + if (buf == NULL) { EMSG2(_("E102: Can't find buffer \"%s\""), eap->arg); return; } - if (buf == curbuf) - return; /* nothing to do */ + + if (buf == curbuf) { + // nothing to do + return; + } idx_other = diff_buf_idx(buf); + if (idx_other == DB_COUNT) { EMSG2(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); return; @@ -1891,34 +2173,37 @@ void ex_diffgetput(exarg_T *eap) diff_busy = TRUE; - /* When no range given include the line above or below the cursor. */ + // When no range given include the line above or below the cursor. if (eap->addr_count == 0) { - /* Make it possible that ":diffget" on the last line gets line below - * the cursor line when there is no difference above the cursor. */ - if (eap->cmdidx == CMD_diffget - && eap->line1 == curbuf->b_ml.ml_line_count - && diff_check(curwin, eap->line1) == 0 - && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) + // Make it possible that ":diffget" on the last line gets line below + // the cursor line when there is no difference above the cursor. + if ((eap->cmdidx == CMD_diffget) + && (eap->line1 == curbuf->b_ml.ml_line_count) + && (diff_check(curwin, eap->line1) == 0) + && ((eap->line1 == 1) || (diff_check(curwin, eap->line1 - 1) == 0))) { ++eap->line2; - else if (eap->line1 > 0) + } else if (eap->line1 > 0) { --eap->line1; + } } if (eap->cmdidx == CMD_diffget) { idx_from = idx_other; idx_to = idx_cur; - } else { + } else { idx_from = idx_cur; idx_to = idx_other; - /* Need to make the other buffer the current buffer to be able to make - * changes in it. */ - /* set curwin/curbuf to buf and save a few things */ + + // Need to make the other buffer the current buffer to be able to make + // changes in it. + + // set curwin/curbuf to buf and save a few things aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); } - /* May give the warning for a changed buffer here, which can trigger the - * FileChangedRO autocommand, which may do nasty things and mess - * everything up. */ + // May give the warning for a changed buffer here, which can trigger the + // FileChangedRO autocommand, which may do nasty things and mess + // everything up. if (!curbuf->b_changed) { change_warning(0); if (diff_buf_idx(curbuf) != idx_to) { @@ -1928,74 +2213,87 @@ void ex_diffgetput(exarg_T *eap) } dprev = NULL; - for (dp = curtab->tp_first_diff; dp != NULL; ) { - if (dp->df_lnum[idx_cur] > eap->line2 + off) - break; /* past the range that was specified */ + for (dp = curtab->tp_first_diff; dp != NULL;) { + if (dp->df_lnum[idx_cur] > eap->line2 + off) { + // past the range that was specified + break; + } dfree = NULL; lnum = dp->df_lnum[idx_to]; count = dp->df_count[idx_to]; - if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off - && u_save(lnum - 1, lnum + count) != FAIL) { - /* Inside the specified range and saving for undo worked. */ + + if ((dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off) + && (u_save(lnum - 1, lnum + count) != FAIL)) { + // Inside the specified range and saving for undo worked. start_skip = 0; end_skip = 0; + if (eap->addr_count > 0) { - /* A range was specified: check if lines need to be skipped. */ + // A range was specified: check if lines need to be skipped. start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; if (start_skip > 0) { - /* range starts below start of current diff block */ + // range starts below start of current diff block if (start_skip > count) { lnum += count; count = 0; - } else { + } else { count -= start_skip; lnum += start_skip; } - } else + } else { start_skip = 0; + } end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 - (eap->line2 + off); + if (end_skip > 0) { - /* range ends above end of current/from diff block */ - if (idx_cur == idx_from) { /* :diffput */ + // range ends above end of current/from diff block + if (idx_cur == idx_from) { + // :diffput i = dp->df_count[idx_cur] - start_skip - end_skip; - if (count > i) + + if (count > i) { count = i; - } else { /* :diffget */ + } + } else { + // :diffget count -= end_skip; end_skip = dp->df_count[idx_from] - start_skip - count; - if (end_skip < 0) + + if (end_skip < 0) { end_skip = 0; + } } - } else + } else { end_skip = 0; + } } buf_empty = FALSE; added = 0; + for (i = 0; i < count; ++i) { - /* remember deleting the last line of the buffer */ + // remember deleting the last line of the buffer buf_empty = curbuf->b_ml.ml_line_count == 1; ml_delete(lnum, FALSE); - --added; + added--; } - for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) { - linenr_T nr; - nr = dp->df_lnum[idx_from] + start_skip + i; - if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) + for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) { + linenr_T nr = dp->df_lnum[idx_from] + start_skip + i; + if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) { break; - p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], - nr, FALSE)); + } + p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE)); if (p != NULL) { ml_append(lnum + i - 1, p, 0, FALSE); vim_free(p); - ++added; - if (buf_empty && curbuf->b_ml.ml_line_count == 2) { - /* Added the first line into an empty buffer, need to - * delete the dummy empty line. */ + added++; + if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { + // Added the first line into an empty buffer, need to + // delete the dummy empty line. buf_empty = FALSE; ml_delete((linenr_T)2, FALSE); } @@ -2004,155 +2302,181 @@ void ex_diffgetput(exarg_T *eap) new_count = dp->df_count[idx_to] + added; dp->df_count[idx_to] = new_count; - if (start_skip == 0 && end_skip == 0) { - /* Check if there are any other buffers and if the diff is - * equal in them. */ - for (i = 0; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] != NULL && i != idx_from - && i != idx_to - && !diff_equal_entry(dp, idx_from, i)) + if ((start_skip == 0) && (end_skip == 0)) { + // Check if there are any other buffers and if the diff is + // equal in them. + for (i = 0; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] != NULL) + && (i != idx_from) + && (i != idx_to) + && !diff_equal_entry(dp, idx_from, i)) { break; + } + } + if (i == DB_COUNT) { - /* delete the diff entry, the buffers are now equal here */ + // delete the diff entry, the buffers are now equal here dfree = dp; dp = dp->df_next; - if (dprev == NULL) + + if (dprev == NULL) { curtab->tp_first_diff = dp; - else + } else { dprev->df_next = dp; + } } } - /* Adjust marks. This will change the following entries! */ + // Adjust marks. This will change the following entries! if (added != 0) { mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); if (curwin->w_cursor.lnum >= lnum) { - /* Adjust the cursor position if it's in/after the changed - * lines. */ - if (curwin->w_cursor.lnum >= lnum + count) + // Adjust the cursor position if it's in/after the changed + // lines. + if (curwin->w_cursor.lnum >= lnum + count) { curwin->w_cursor.lnum += added; - else if (added < 0) + } else if (added < 0) { curwin->w_cursor.lnum = lnum; + } } } changed_lines(lnum, 0, lnum + count, (long)added); if (dfree != NULL) { - /* Diff is deleted, update folds in other windows. */ + // Diff is deleted, update folds in other windows. diff_fold_update(dfree, idx_to); vim_free(dfree); - } else - /* mark_adjust() may have changed the count in a wrong way */ + } else { + // mark_adjust() may have changed the count in a wrong way dp->df_count[idx_to] = new_count; + } - /* When changing the current buffer, keep track of line numbers */ - if (idx_cur == idx_to) + // When changing the current buffer, keep track of line numbers + if (idx_cur == idx_to) { off += added; + } } - /* If before the range or not deleted, go to next diff. */ + // If before the range or not deleted, go to next diff. if (dfree == NULL) { dprev = dp; dp = dp->df_next; } } - /* restore curwin/curbuf and a few other things */ + // restore curwin/curbuf and a few other things if (eap->cmdidx != CMD_diffget) { - /* Syncing undo only works for the current buffer, but we change - * another buffer. Sync undo if the command was typed. This isn't - * 100% right when ":diffput" is used in a function or mapping. */ - if (KeyTyped) + // Syncing undo only works for the current buffer, but we change + // another buffer. Sync undo if the command was typed. This isn't + // 100% right when ":diffput" is used in a function or mapping. + if (KeyTyped) { u_sync(FALSE); + } aucmd_restbuf(&aco); } diff_busy = FALSE; - /* Check that the cursor is on a valid character and update it's position. - * When there were filler lines the topline has become invalid. */ + // Check that the cursor is on a valid character and update it's position. + // When there were filler lines the topline has become invalid. check_cursor(); changed_line_abv_curs(); - /* Also need to redraw the other buffers. */ + // Also need to redraw the other buffers. diff_redraw(FALSE); } -/* - * Update folds for all diff buffers for entry "dp". - * Skip buffer with index "skip_idx". - * When there are no diffs, all folds are removed. - */ +/// Update folds for all diff buffers for entry "dp". +/// +/// Skip buffer with index "skip_idx". +/// When there are no diffs, all folds are removed. +/// +/// @param dp +/// @param skip_idx static void diff_fold_update(diff_T *dp, int skip_idx) { - int i; - win_T *wp; - - for (wp = firstwin; wp != NULL; wp = wp->w_next) - for (i = 0; i < DB_COUNT; ++i) - if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx) - foldUpdate(wp, dp->df_lnum[i], - dp->df_lnum[i] + dp->df_count[i]); + win_T *wp; + for (wp = firstwin; wp != NULL; wp = wp->w_next) { + int i; + for (i = 0; i < DB_COUNT; ++i) { + if ((curtab->tp_diffbuf[i] == wp->w_buffer) && (i != skip_idx)) { + foldUpdate(wp, dp->df_lnum[i], dp->df_lnum[i] + dp->df_count[i]); + } + } + } } -/* - * Return TRUE if buffer "buf" is in diff-mode. - */ +/// Checks if the buffer is in diff-mode. +/// +/// @param buf The buffer to check. +/// +/// @return TRUE if buffer "buf" is in diff-mode. int diff_mode_buf(buf_T *buf) { - tabpage_T *tp; - - for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) - if (diff_buf_idx_tp(buf, tp) != DB_COUNT) + tabpage_T *tp; + for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) { + if (diff_buf_idx_tp(buf, tp) != DB_COUNT) { return TRUE; + } + } return FALSE; } -/* - * Move "count" times in direction "dir" to the next diff block. - * Return FAIL if there isn't such a diff block. - */ +/// Move "count" times in direction "dir" to the next diff block. +/// +/// @param dir +/// @param count +/// +/// @return FAIL if there isn't such a diff block. int diff_move_to(int dir, long count) { - int idx; linenr_T lnum = curwin->w_cursor.lnum; - diff_T *dp; - - idx = diff_buf_idx(curbuf); - if (idx == DB_COUNT || curtab->tp_first_diff == NULL) + int idx = diff_buf_idx(curbuf); + if ((idx == DB_COUNT) || (curtab->tp_first_diff == NULL)) { return FAIL; + } - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } - if (curtab->tp_first_diff == NULL) /* no diffs today */ + if (curtab->tp_first_diff == NULL) { + // no diffs today return FAIL; + } while (--count >= 0) { - /* Check if already before first diff. */ - if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) + // Check if already before first diff. + if ((dir == BACKWARD) && (lnum <= curtab->tp_first_diff->df_lnum[idx])) { break; + } + diff_T *dp; for (dp = curtab->tp_first_diff;; dp = dp->df_next) { - if (dp == NULL) + if (dp == NULL) { break; - if ((dir == FORWARD && lnum < dp->df_lnum[idx]) - || (dir == BACKWARD - && (dp->df_next == NULL - || lnum <= dp->df_next->df_lnum[idx]))) { + } + + if (((dir == FORWARD) && (lnum < dp->df_lnum[idx])) + || ((dir == BACKWARD) + && ((dp->df_next == NULL) + || (lnum <= dp->df_next->df_lnum[idx])))) { lnum = dp->df_lnum[idx]; break; } } } - /* don't end up past the end of the file */ - if (lnum > curbuf->b_ml.ml_line_count) + // don't end up past the end of the file + if (lnum > curbuf->b_ml.ml_line_count) { lnum = curbuf->b_ml.ml_line_count; + } - /* When the cursor didn't move at all we fail. */ - if (lnum == curwin->w_cursor.lnum) + // When the cursor didn't move at all we fail. + if (lnum == curwin->w_cursor.lnum) { return FAIL; + } setpcmark(); curwin->w_cursor.lnum = lnum; @@ -2161,101 +2485,132 @@ int diff_move_to(int dir, long count) return OK; } -linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1, buf_T *buf2, linenr_T lnum3) +/// Finds the corresponding line in a diff. +/// +/// @param buf1 +/// @param lnum1 +/// @param buf2 +/// @param lnum3 +/// +/// @return The corresponding line. +linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1, buf_T *buf2, + linenr_T lnum3) { int idx1; int idx2; - diff_T *dp; + diff_T *dp; int baseline = 0; linenr_T lnum2; idx1 = diff_buf_idx(buf1); idx2 = diff_buf_idx(buf2); - if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL) + + if ((idx1 == DB_COUNT) + || (idx2 == DB_COUNT) + || (curtab->tp_first_diff == NULL)) { return lnum1; + } - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } - if (curtab->tp_first_diff == NULL) /* no diffs today */ + if (curtab->tp_first_diff == NULL) { + // no diffs today return lnum1; + } for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { if (dp->df_lnum[idx1] > lnum1) { lnum2 = lnum1 - baseline; - /* don't end up past the end of the file */ - if (lnum2 > buf2->b_ml.ml_line_count) + + // don't end up past the end of the file + if (lnum2 > buf2->b_ml.ml_line_count) { lnum2 = buf2->b_ml.ml_line_count; + } return lnum2; - } else if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) { - /* Inside the diffblock */ + } else if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) { + // Inside the diffblock baseline = lnum1 - dp->df_lnum[idx1]; - if (baseline > dp->df_count[idx2]) + + if (baseline > dp->df_count[idx2]) { baseline = dp->df_count[idx2]; + } return dp->df_lnum[idx2] + baseline; - } else if ( (dp->df_lnum[idx1] == lnum1) - && (dp->df_count[idx1] == 0) - && (dp->df_lnum[idx2] <= lnum3) - && ((dp->df_lnum[idx2] + dp->df_count[idx2]) > lnum3)) - /* - * Special case: if the cursor is just after a zero-count - * block (i.e. all filler) and the target cursor is already - * inside the corresponding block, leave the target cursor - * unmoved. This makes repeated CTRL-W W operations work - * as expected. - */ + } else if ((dp->df_lnum[idx1] == lnum1) + && (dp->df_count[idx1] == 0) + && (dp->df_lnum[idx2] <= lnum3) + && ((dp->df_lnum[idx2] + dp->df_count[idx2]) > lnum3)) { + // Special case: if the cursor is just after a zero-count + // block (i.e. all filler) and the target cursor is already + // inside the corresponding block, leave the target cursor + // unmoved. This makes repeated CTRL-W W operations work + // as expected. return lnum3; + } baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) - (dp->df_lnum[idx2] + dp->df_count[idx2]); } - /* If we get here then the cursor is after the last diff */ + // If we get here then the cursor is after the last diff lnum2 = lnum1 - baseline; - /* don't end up past the end of the file */ - if (lnum2 > buf2->b_ml.ml_line_count) + + // don't end up past the end of the file + if (lnum2 > buf2->b_ml.ml_line_count) { lnum2 = buf2->b_ml.ml_line_count; + } return lnum2; } -/* - * For line "lnum" in the current window find the equivalent lnum in window - * "wp", compensating for inserted/deleted lines. - */ +/// For line "lnum" in the current window find the equivalent lnum in window +/// "wp", compensating for inserted/deleted lines. linenr_T diff_lnum_win(linenr_T lnum, win_T *wp) { - diff_T *dp; + diff_T *dp; int idx; int i; linenr_T n; idx = diff_buf_idx(curbuf); - if (idx == DB_COUNT) /* safety check */ + + if (idx == DB_COUNT) { + // safety check return (linenr_T)0; + } - if (curtab->tp_diff_invalid) - ex_diffupdate(NULL); /* update after a big change */ + if (curtab->tp_diff_invalid) { + // update after a big change + ex_diffupdate(NULL); + } - /* search for a change that includes "lnum" in the list of diffblocks. */ - for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) - if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) + // search for a change that includes "lnum" in the list of diffblocks. + for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { + if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) { break; + } + } - /* When after the last change, compute relative to the last line number. */ - if (dp == NULL) + // When after the last change, compute relative to the last line number. + if (dp == NULL) { return wp->w_buffer->b_ml.ml_line_count - (curbuf->b_ml.ml_line_count - lnum); + } - /* Find index for "wp". */ + // Find index for "wp". i = diff_buf_idx(wp->w_buffer); - if (i == DB_COUNT) /* safety check */ + + if (i == DB_COUNT) { + // safety check return (linenr_T)0; + } n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); - if (n > dp->df_lnum[i] + dp->df_count[i]) + if (n > dp->df_lnum[i] + dp->df_count[i]) { n = dp->df_lnum[i] + dp->df_count[i]; + } return n; } - diff --git a/src/diff.h b/src/diff.h index 2f51fafbb2..61da3c6190 100644 --- a/src/diff.h +++ b/src/diff.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_DIFF_H #define NEOVIM_DIFF_H -/* diff.c */ + void diff_buf_delete(buf_T *buf); void diff_buf_adjust(win_T *win); void diff_buf_add(buf_T *buf); @@ -29,5 +29,6 @@ linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1, buf_T *buf2, linenr_T lnum3); linenr_T diff_lnum_win(linenr_T lnum, win_T *wp); -/* vim: set ft=c : */ -#endif /* NEOVIM_DIFF_H */ + +// vim: set ft=c: +#endif // NEOVIM_DIFF_H diff --git a/src/digraph.c b/src/digraph.c index 3faac48089..37fe9ad5b1 100644 --- a/src/digraph.c +++ b/src/digraph.c @@ -1,15 +1,6 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * digraph.c: code for digraphs - */ +/// @file digraph.c +/// +/// code for digraphs #include "vim.h" #include "digraph.h" @@ -34,1716 +25,1720 @@ typedef struct digraph { result_T result; } digr_T; -static int getexactdigraph(int, int, int); -static void printdigraph(digr_T *); +static int getexactdigraph(int char1, int char2, int meta_char); +static void printdigraph(digr_T *dp); -/* digraphs added by the user */ +// digraphs added by the user 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). - */ +/// 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[] = -# ifdef HPUX_DIGRAPHS - -/* - * different HPUX digraphs - */ -{{'A', '`', 161}, /* ¡ */ - {'A', '^', 162}, /* ¢ */ - {'E', '`', 163}, /* £ */ - {'E', '^', 164}, /* ¤ */ - {'E', '"', 165}, /* ¥ */ - {'I', '^', 166}, /* ¦ */ - {'I', '"', 167}, /* § */ - {'\'', '\'', 168}, /* ¨ */ - {'`', '`', 169}, /* © */ - {'^', '^', 170}, /* ª */ - {'"', '"', 171}, /* « */ - {'~', '~', 172}, /* ¬ */ - {'U', '`', 173}, /* */ - {'U', '^', 174}, /* ® */ - {'L', '=', 175}, /* ¯ */ - {'~', '_', 176}, /* ° */ - {'Y', '\'', 177}, /* ± */ - {'y', '\'', 178}, /* ² */ - {'~', 'o', 179}, /* ³ */ - {'C', ',', 180}, /* ´ */ - {'c', ',', 181}, /* µ */ - {'N', '~', 182}, /* ¶ */ - {'n', '~', 183}, /* · */ - {'~', '!', 184}, /* ¸ */ - {'~', '?', 185}, /* ¹ */ - {'o', 'x', 186}, /* º */ - {'L', '-', 187}, /* » */ - {'Y', '=', 188}, /* ¼ */ - {'p', 'p', 189}, /* ½ */ - {'f', 'l', 190}, /* ¾ */ - {'c', '|', 191}, /* ¿ */ - {'a', '^', 192}, /* À */ - {'e', '^', 193}, /* Á */ - {'o', '^', 194}, /* Â */ - {'u', '^', 195}, /* Ã */ - {'a', '\'', 196}, /* Ä */ - {'e', '\'', 197}, /* Å */ - {'o', '\'', 198}, /* Æ */ - {'u', '\'', 199}, /* Ç */ - {'a', '`', 200}, /* È */ - {'e', '`', 201}, /* É */ - {'o', '`', 202}, /* Ê */ - {'u', '`', 203}, /* Ë */ - {'a', '"', 204}, /* Ì */ - {'e', '"', 205}, /* Í */ - {'o', '"', 206}, /* Î */ - {'u', '"', 207}, /* Ï */ - {'A', 'o', 208}, /* Ð */ - {'i', '^', 209}, /* Ñ */ - {'O', '/', 210}, /* Ò */ - {'A', 'E', 211}, /* Ó */ - {'a', 'o', 212}, /* Ô */ - {'i', '\'', 213}, /* Õ */ - {'o', '/', 214}, /* Ö */ - {'a', 'e', 215}, /* × */ - {'A', '"', 216}, /* Ø */ - {'i', '`', 217}, /* Ù */ - {'O', '"', 218}, /* Ú */ - {'U', '"', 219}, /* Û */ - {'E', '\'', 220}, /* Ü */ - {'i', '"', 221}, /* Ý */ - {'s', 's', 222}, /* Þ */ - {'O', '^', 223}, /* ß */ - {'A', '\'', 224}, /* à */ - {'A', '~', 225}, /* á */ - {'a', '~', 226}, /* â */ - {'D', '-', 227}, /* ã */ - {'d', '-', 228}, /* ä */ - {'I', '\'', 229}, /* å */ - {'I', '`', 230}, /* æ */ - {'O', '\'', 231}, /* ç */ - {'O', '`', 232}, /* è */ - {'O', '~', 233}, /* é */ - {'o', '~', 234}, /* ê */ - {'S', '~', 235}, /* ë */ - {'s', '~', 236}, /* ì */ - {'U', '\'', 237}, /* í */ - {'Y', '"', 238}, /* î */ - {'y', '"', 239}, /* ï */ - {'p', '-', 240}, /* ð */ - {'p', '~', 241}, /* ñ */ - {'~', '.', 242}, /* ò */ - {'j', 'u', 243}, /* ó */ - {'P', 'p', 244}, /* ô */ - {'3', '4', 245}, /* õ */ - {'-', '-', 246}, /* ö */ - {'1', '4', 247}, /* ÷ */ - {'1', '2', 248}, /* ø */ - {'a', '_', 249}, /* ù */ - {'o', '_', 250}, /* ú */ - {'<', '<', 251}, /* û */ - {'x', 'x', 252}, /* ü */ - {'>', '>', 253}, /* ý */ - {'+', '-', 254}, /* þ */ - {'n', 'u', 255}, /* x XX */ - {NUL, NUL, NUL}}; - -# else /* !HPUX_DIGRAPHS */ - - -# ifdef OLD_DIGRAPHS - -/* - * digraphs compatible with Vim 5.x - */ -{{'~', '!', 161}, /* ¡ */ - {'c', '|', 162}, /* ¢ */ - {'$', '$', 163}, /* £ */ - {'o', 'x', 164}, /* ¤ - currency symbol in ISO 8859-1 */ - {'e', '=', 164}, /* ¤ - euro symbol in ISO 8859-15 */ - {'Y', '-', 165}, /* ¥ */ - {'|', '|', 166}, /* ¦ */ - {'p', 'a', 167}, /* § */ - {'"', '"', 168}, /* ¨ */ - {'c', 'O', 169}, /* © */ - {'a', '-', 170}, /* ª */ - {'<', '<', 171}, /* « */ - {'-', ',', 172}, /* ¬ */ - {'-', '-', 173}, /* */ - {'r', 'O', 174}, /* ® */ - {'-', '=', 175}, /* ¯ */ - {'~', 'o', 176}, /* ° */ - {'+', '-', 177}, /* ± */ - {'2', '2', 178}, /* ² */ - {'3', '3', 179}, /* ³ */ - {'\'', '\'', 180}, /* ´ */ - {'j', 'u', 181}, /* µ */ - {'p', 'p', 182}, /* ¶ */ - {'~', '.', 183}, /* · */ - {',', ',', 184}, /* ¸ */ - {'1', '1', 185}, /* ¹ */ - {'o', '-', 186}, /* º */ - {'>', '>', 187}, /* » */ - {'1', '4', 188}, /* ¼ */ - {'1', '2', 189}, /* ½ */ - {'3', '4', 190}, /* ¾ */ - {'~', '?', 191}, /* ¿ */ - {'A', '`', 192}, /* À */ - {'A', '\'', 193}, /* Á */ - {'A', '^', 194}, /* Â */ - {'A', '~', 195}, /* Ã */ - {'A', '"', 196}, /* Ä */ - {'A', '@', 197}, /* Å */ - {'A', 'A', 197}, /* Å */ - {'A', 'E', 198}, /* Æ */ - {'C', ',', 199}, /* Ç */ - {'E', '`', 200}, /* È */ - {'E', '\'', 201}, /* É */ - {'E', '^', 202}, /* Ê */ - {'E', '"', 203}, /* Ë */ - {'I', '`', 204}, /* Ì */ - {'I', '\'', 205}, /* Í */ - {'I', '^', 206}, /* Î */ - {'I', '"', 207}, /* Ï */ - {'D', '-', 208}, /* Ð */ - {'N', '~', 209}, /* Ñ */ - {'O', '`', 210}, /* Ò */ - {'O', '\'', 211}, /* Ó */ - {'O', '^', 212}, /* Ô */ - {'O', '~', 213}, /* Õ */ - {'O', '"', 214}, /* Ö */ - {'/', '\\', 215}, /* × - multiplication symbol in ISO 8859-1 */ - {'O', 'E', 215}, /* × - OE in ISO 8859-15 */ - {'O', '/', 216}, /* Ø */ - {'U', '`', 217}, /* Ù */ - {'U', '\'', 218}, /* Ú */ - {'U', '^', 219}, /* Û */ - {'U', '"', 220}, /* Ü */ - {'Y', '\'', 221}, /* Ý */ - {'I', 'p', 222}, /* Þ */ - {'s', 's', 223}, /* ß */ - {'a', '`', 224}, /* à */ - {'a', '\'', 225}, /* á */ - {'a', '^', 226}, /* â */ - {'a', '~', 227}, /* ã */ - {'a', '"', 228}, /* ä */ - {'a', '@', 229}, /* å */ - {'a', 'a', 229}, /* å */ - {'a', 'e', 230}, /* æ */ - {'c', ',', 231}, /* ç */ - {'e', '`', 232}, /* è */ - {'e', '\'', 233}, /* é */ - {'e', '^', 234}, /* ê */ - {'e', '"', 235}, /* ë */ - {'i', '`', 236}, /* ì */ - {'i', '\'', 237}, /* í */ - {'i', '^', 238}, /* î */ - {'i', '"', 239}, /* ï */ - {'d', '-', 240}, /* ð */ - {'n', '~', 241}, /* ñ */ - {'o', '`', 242}, /* ò */ - {'o', '\'', 243}, /* ó */ - {'o', '^', 244}, /* ô */ - {'o', '~', 245}, /* õ */ - {'o', '"', 246}, /* ö */ - {':', '-', 247}, /* ÷ - division symbol in ISO 8859-1 */ - {'o', 'e', 247}, /* ÷ - oe in ISO 8859-15 */ - {'o', '/', 248}, /* ø */ - {'u', '`', 249}, /* ù */ - {'u', '\'', 250}, /* ú */ - {'u', '^', 251}, /* û */ - {'u', '"', 252}, /* ü */ - {'y', '\'', 253}, /* ý */ - {'i', 'p', 254}, /* þ */ - {'y', '"', 255}, /* x XX */ - {NUL, NUL, NUL}}; -# else /* OLD_DIGRAPHS */ - -/* - * digraphs for Unicode from RFC1345 - * (also work for ISO-8859-1 aka latin1) - */ +#ifdef HPUX_DIGRAPHS + +/// different HPUX digraphs +{ { 'A', '`', 161 }, // ¡ + { 'A', '^', 162 }, // ¢ + { 'E', '`', 163 }, // £ + { 'E', '^', 164 }, // ¤ + { 'E', '"', 165 }, // ¥ + { 'I', '^', 166 }, // ¦ + { 'I', '"', 167 }, // § + { '\'', '\'', 168 }, // ¨ + { '`', '`', 169 }, // © + { '^', '^', 170 }, // ª + { '"', '"', 171 }, // « + { '~', '~', 172 }, // ¬ + { 'U', '`', 173 }, // + { 'U', '^', 174 }, // ® + { 'L', '=', 175 }, // ¯ + { '~', '_', 176 }, // ° + { 'Y', '\'', 177 }, // ± + { 'y', '\'', 178 }, // ² + { '~', 'o', 179 }, // ³ + { 'C', ',', 180 }, // ´ + { 'c', ',', 181 }, // µ + { 'N', '~', 182 }, // ¶ + { 'n', '~', 183 }, // · + { '~', '!', 184 }, // ¸ + { '~', '?', 185 }, // ¹ + { 'o', 'x', 186 }, // º + { 'L', '-', 187 }, // » + { 'Y', '=', 188 }, // ¼ + { 'p', 'p', 189 }, // ½ + { 'f', 'l', 190 }, // ¾ + { 'c', '|', 191 }, // ¿ + { 'a', '^', 192 }, // À + { 'e', '^', 193 }, // Á + { 'o', '^', 194 }, // Â + { 'u', '^', 195 }, // Ã + { 'a', '\'', 196 }, // Ä + { 'e', '\'', 197 }, // Å + { 'o', '\'', 198 }, // Æ + { 'u', '\'', 199 }, // Ç + { 'a', '`', 200 }, // È + { 'e', '`', 201 }, // É + { 'o', '`', 202 }, // Ê + { 'u', '`', 203 }, // Ë + { 'a', '"', 204 }, // Ì + { 'e', '"', 205 }, // Í + { 'o', '"', 206 }, // Î + { 'u', '"', 207 }, // Ï + { 'A', 'o', 208 }, // Ð + { 'i', '^', 209 }, // Ñ + { 'O', '/', 210 }, // Ò + { 'A', 'E', 211 }, // Ó + { 'a', 'o', 212 }, // Ô + { 'i', '\'', 213 }, // Õ + { 'o', '/', 214 }, // Ö + { 'a', 'e', 215 }, // × + { 'A', '"', 216 }, // Ø + { 'i', '`', 217 }, // Ù + { 'O', '"', 218 }, // Ú + { 'U', '"', 219 }, // Û + { 'E', '\'', 220 }, // Ü + { 'i', '"', 221 }, // Ý + { 's', 's', 222 }, // Þ + { 'O', '^', 223 }, // ß + { 'A', '\'', 224 }, // à + { 'A', '~', 225 }, // á + { 'a', '~', 226 }, // â + { 'D', '-', 227 }, // ã + { 'd', '-', 228 }, // ä + { 'I', '\'', 229 }, // å + { 'I', '`', 230 }, // æ + { 'O', '\'', 231 }, // ç + { 'O', '`', 232 }, // è + { 'O', '~', 233 }, // é + { 'o', '~', 234 }, // ê + { 'S', '~', 235 }, // ë + { 's', '~', 236 }, // ì + { 'U', '\'', 237 }, // í + { 'Y', '"', 238 }, // î + { 'y', '"', 239 }, // ï + { 'p', '-', 240 }, // ð + { 'p', '~', 241 }, // ñ + { '~', '.', 242 }, // ò + { 'j', 'u', 243 }, // ó + { 'P', 'p', 244 }, // ô + { '3', '4', 245 }, // õ + { '-', '-', 246 }, // ö + { '1', '4', 247 }, // ÷ + { '1', '2', 248 }, // ø + { 'a', '_', 249 }, // ù + { 'o', '_', 250 }, // ú + { '<', '<', 251 }, // û + { 'x', 'x', 252 }, // ü + { '>', '>', 253 }, // ý + { '+', '-', 254 }, // þ + { 'n', 'u', 255 }, // x XX + { NUL, NUL, NUL } }; + +#else // !HPUX_DIGRAPHS + + +# ifdef OLD_DIGRAPHS + +// digraphs compatible with Vim 5.x +{ { '~', '!', 161 }, // ¡ + { 'c', '|', 162 }, // ¢ + { '$', '$', 163 }, // £ + { 'o', 'x', 164 }, // ¤ - currency symbol in ISO 8859-1 + { 'e', '=', 164 }, // ¤ - euro symbol in ISO 8859-15 + { 'Y', '-', 165 }, // ¥ + { '|', '|', 166 }, // ¦ + { 'p', 'a', 167 }, // § + { '"', '"', 168 }, // ¨ + { 'c', 'O', 169 }, // © + { 'a', '-', 170 }, // ª + { '<', '<', 171 }, // « + { '-', ',', 172 }, // ¬ + { '-', '-', 173 }, // + { 'r', 'O', 174 }, // ® + { '-', '=', 175 }, // ¯ + { '~', 'o', 176 }, // ° + { '+', '-', 177 }, // ± + { '2', '2', 178 }, // ² + { '3', '3', 179 }, // ³ + { '\'', '\'', 180 }, // ´ + { 'j', 'u', 181 }, // µ + { 'p', 'p', 182 }, // ¶ + { '~', '.', 183 }, // · + { ',', ',', 184 }, // ¸ + { '1', '1', 185 }, // ¹ + { 'o', '-', 186 }, // º + { '>', '>', 187 }, // » + { '1', '4', 188 }, // ¼ + { '1', '2', 189 }, // ½ + { '3', '4', 190 }, // ¾ + { '~', '?', 191 }, // ¿ + { 'A', '`', 192 }, // À + { 'A', '\'', 193 }, // Á + { 'A', '^', 194 }, // Â + { 'A', '~', 195 }, // Ã + { 'A', '"', 196 }, // Ä + { 'A', '@', 197 }, // Å + { 'A', 'A', 197 }, // Å + { 'A', 'E', 198 }, // Æ + { 'C', ',', 199 }, // Ç + { 'E', '`', 200 }, // È + { 'E', '\'', 201 }, // É + { 'E', '^', 202 }, // Ê + { 'E', '"', 203 }, // Ë + { 'I', '`', 204 }, // Ì + { 'I', '\'', 205 }, // Í + { 'I', '^', 206 }, // Î + { 'I', '"', 207 }, // Ï + { 'D', '-', 208 }, // Ð + { 'N', '~', 209 }, // Ñ + { 'O', '`', 210 }, // Ò + { 'O', '\'', 211 }, // Ó + { 'O', '^', 212 }, // Ô + { 'O', '~', 213 }, // Õ + { 'O', '"', 214 }, // Ö + { '/', '\\', 215 }, // × - multiplication symbol in ISO 8859-1 + { 'O', 'E', 215 }, // × - OE in ISO 8859-15 + { 'O', '/', 216 }, // Ø + { 'U', '`', 217 }, // Ù + { 'U', '\'', 218 }, // Ú + { 'U', '^', 219 }, // Û + { 'U', '"', 220 }, // Ü + { 'Y', '\'', 221 }, // Ý + { 'I', 'p', 222 }, // Þ + { 's', 's', 223 }, // ß + { 'a', '`', 224 }, // à + { 'a', '\'', 225 }, // á + { 'a', '^', 226 }, // â + { 'a', '~', 227 }, // ã + { 'a', '"', 228 }, // ä + { 'a', '@', 229 }, // å + { 'a', 'a', 229 }, // å + { 'a', 'e', 230 }, // æ + { 'c', ',', 231 }, // ç + { 'e', '`', 232 }, // è + { 'e', '\'', 233 }, // é + { 'e', '^', 234 }, // ê + { 'e', '"', 235 }, // ë + { 'i', '`', 236 }, // ì + { 'i', '\'', 237 }, // í + { 'i', '^', 238 }, // î + { 'i', '"', 239 }, // ï + { 'd', '-', 240 }, // ð + { 'n', '~', 241 }, // ñ + { 'o', '`', 242 }, // ò + { 'o', '\'', 243 }, // ó + { 'o', '^', 244 }, // ô + { 'o', '~', 245 }, // õ + { 'o', '"', 246 }, // ö + { ':', '-', 247 }, // ÷ - division symbol in ISO 8859-1 + { 'o', 'e', 247 }, // ÷ - oe in ISO 8859-15 + { 'o', '/', 248 }, // ø + { 'u', '`', 249 }, // ù + { 'u', '\'', 250 }, // ú + { 'u', '^', 251 }, // û + { 'u', '"', 252 }, // ü + { 'y', '\'', 253 }, // ý + { 'i', 'p', 254 }, // þ + { 'y', '"', 255 }, // x XX + { NUL, NUL, NUL } }; +# else // OLD_DIGRAPHS + +// digraphs for Unicode from RFC1345 +// (also work for ISO-8859-1 aka latin1) { - {'N', 'U', 0x0a}, /* LF for NUL */ - {'S', 'H', 0x01}, - {'S', 'X', 0x02}, - {'E', 'X', 0x03}, - {'E', 'T', 0x04}, - {'E', 'Q', 0x05}, - {'A', 'K', 0x06}, - {'B', 'L', 0x07}, - {'B', 'S', 0x08}, - {'H', 'T', 0x09}, - {'L', 'F', 0x0a}, - {'V', 'T', 0x0b}, - {'F', 'F', 0x0c}, - {'C', 'R', 0x0d}, - {'S', 'O', 0x0e}, - {'S', 'I', 0x0f}, - {'D', 'L', 0x10}, - {'D', '1', 0x11}, - {'D', '2', 0x12}, - {'D', '3', 0x13}, - {'D', '4', 0x14}, - {'N', 'K', 0x15}, - {'S', 'Y', 0x16}, - {'E', 'B', 0x17}, - {'C', 'N', 0x18}, - {'E', 'M', 0x19}, - {'S', 'B', 0x1a}, - {'E', 'C', 0x1b}, - {'F', 'S', 0x1c}, - {'G', 'S', 0x1d}, - {'R', 'S', 0x1e}, - {'U', 'S', 0x1f}, - {'S', 'P', 0x20}, - {'N', 'b', 0x23}, - {'D', 'O', 0x24}, - {'A', 't', 0x40}, - {'<', '(', 0x5b}, - {'/', '/', 0x5c}, - {')', '>', 0x5d}, - {'\'', '>', 0x5e}, - {'\'', '!', 0x60}, - {'(', '!', 0x7b}, - {'!', '!', 0x7c}, - {'!', ')', 0x7d}, - {'\'', '?', 0x7e}, - {'D', 'T', 0x7f}, - {'P', 'A', 0x80}, - {'H', 'O', 0x81}, - {'B', 'H', 0x82}, - {'N', 'H', 0x83}, - {'I', 'N', 0x84}, - {'N', 'L', 0x85}, - {'S', 'A', 0x86}, - {'E', 'S', 0x87}, - {'H', 'S', 0x88}, - {'H', 'J', 0x89}, - {'V', 'S', 0x8a}, - {'P', 'D', 0x8b}, - {'P', 'U', 0x8c}, - {'R', 'I', 0x8d}, - {'S', '2', 0x8e}, - {'S', '3', 0x8f}, - {'D', 'C', 0x90}, - {'P', '1', 0x91}, - {'P', '2', 0x92}, - {'T', 'S', 0x93}, - {'C', 'C', 0x94}, - {'M', 'W', 0x95}, - {'S', 'G', 0x96}, - {'E', 'G', 0x97}, - {'S', 'S', 0x98}, - {'G', 'C', 0x99}, - {'S', 'C', 0x9a}, - {'C', 'I', 0x9b}, - {'S', 'T', 0x9c}, - {'O', 'C', 0x9d}, - {'P', 'M', 0x9e}, - {'A', 'C', 0x9f}, - {'N', 'S', 0xa0}, - {'!', 'I', 0xa1}, - {'C', 't', 0xa2}, - {'P', 'd', 0xa3}, - {'C', 'u', 0xa4}, - {'Y', 'e', 0xa5}, - {'B', 'B', 0xa6}, - {'S', 'E', 0xa7}, - {'\'', ':', 0xa8}, - {'C', 'o', 0xa9}, - {'-', 'a', 0xaa}, - {'<', '<', 0xab}, - {'N', 'O', 0xac}, - {'-', '-', 0xad}, - {'R', 'g', 0xae}, - {'\'', 'm', 0xaf}, - {'D', 'G', 0xb0}, - {'+', '-', 0xb1}, - {'2', 'S', 0xb2}, - {'3', 'S', 0xb3}, - {'\'', '\'', 0xb4}, - {'M', 'y', 0xb5}, - {'P', 'I', 0xb6}, - {'.', 'M', 0xb7}, - {'\'', ',', 0xb8}, - {'1', 'S', 0xb9}, - {'-', 'o', 0xba}, - {'>', '>', 0xbb}, - {'1', '4', 0xbc}, - {'1', '2', 0xbd}, - {'3', '4', 0xbe}, - {'?', 'I', 0xbf}, - {'A', '!', 0xc0}, - {'A', '\'', 0xc1}, - {'A', '>', 0xc2}, - {'A', '?', 0xc3}, - {'A', ':', 0xc4}, - {'A', 'A', 0xc5}, - {'A', 'E', 0xc6}, - {'C', ',', 0xc7}, - {'E', '!', 0xc8}, - {'E', '\'', 0xc9}, - {'E', '>', 0xca}, - {'E', ':', 0xcb}, - {'I', '!', 0xcc}, - {'I', '\'', 0xcd}, - {'I', '>', 0xce}, - {'I', ':', 0xcf}, - {'D', '-', 0xd0}, - {'N', '?', 0xd1}, - {'O', '!', 0xd2}, - {'O', '\'', 0xd3}, - {'O', '>', 0xd4}, - {'O', '?', 0xd5}, - {'O', ':', 0xd6}, - {'*', 'X', 0xd7}, - {'O', '/', 0xd8}, - {'U', '!', 0xd9}, - {'U', '\'', 0xda}, - {'U', '>', 0xdb}, - {'U', ':', 0xdc}, - {'Y', '\'', 0xdd}, - {'T', 'H', 0xde}, - {'s', 's', 0xdf}, - {'a', '!', 0xe0}, - {'a', '\'', 0xe1}, - {'a', '>', 0xe2}, - {'a', '?', 0xe3}, - {'a', ':', 0xe4}, - {'a', 'a', 0xe5}, - {'a', 'e', 0xe6}, - {'c', ',', 0xe7}, - {'e', '!', 0xe8}, - {'e', '\'', 0xe9}, - {'e', '>', 0xea}, - {'e', ':', 0xeb}, - {'i', '!', 0xec}, - {'i', '\'', 0xed}, - {'i', '>', 0xee}, - {'i', ':', 0xef}, - {'d', '-', 0xf0}, - {'n', '?', 0xf1}, - {'o', '!', 0xf2}, - {'o', '\'', 0xf3}, - {'o', '>', 0xf4}, - {'o', '?', 0xf5}, - {'o', ':', 0xf6}, - {'-', ':', 0xf7}, - {'o', '/', 0xf8}, - {'u', '!', 0xf9}, - {'u', '\'', 0xfa}, - {'u', '>', 0xfb}, - {'u', ':', 0xfc}, - {'y', '\'', 0xfd}, - {'t', 'h', 0xfe}, - {'y', ':', 0xff}, - -# define USE_UNICODE_DIGRAPHS - - {'A', '-', 0x0100}, - {'a', '-', 0x0101}, - {'A', '(', 0x0102}, - {'a', '(', 0x0103}, - {'A', ';', 0x0104}, - {'a', ';', 0x0105}, - {'C', '\'', 0x0106}, - {'c', '\'', 0x0107}, - {'C', '>', 0x0108}, - {'c', '>', 0x0109}, - {'C', '.', 0x010a}, - {'c', '.', 0x010b}, - {'C', '<', 0x010c}, - {'c', '<', 0x010d}, - {'D', '<', 0x010e}, - {'d', '<', 0x010f}, - {'D', '/', 0x0110}, - {'d', '/', 0x0111}, - {'E', '-', 0x0112}, - {'e', '-', 0x0113}, - {'E', '(', 0x0114}, - {'e', '(', 0x0115}, - {'E', '.', 0x0116}, - {'e', '.', 0x0117}, - {'E', ';', 0x0118}, - {'e', ';', 0x0119}, - {'E', '<', 0x011a}, - {'e', '<', 0x011b}, - {'G', '>', 0x011c}, - {'g', '>', 0x011d}, - {'G', '(', 0x011e}, - {'g', '(', 0x011f}, - {'G', '.', 0x0120}, - {'g', '.', 0x0121}, - {'G', ',', 0x0122}, - {'g', ',', 0x0123}, - {'H', '>', 0x0124}, - {'h', '>', 0x0125}, - {'H', '/', 0x0126}, - {'h', '/', 0x0127}, - {'I', '?', 0x0128}, - {'i', '?', 0x0129}, - {'I', '-', 0x012a}, - {'i', '-', 0x012b}, - {'I', '(', 0x012c}, - {'i', '(', 0x012d}, - {'I', ';', 0x012e}, - {'i', ';', 0x012f}, - {'I', '.', 0x0130}, - {'i', '.', 0x0131}, - {'I', 'J', 0x0132}, - {'i', 'j', 0x0133}, - {'J', '>', 0x0134}, - {'j', '>', 0x0135}, - {'K', ',', 0x0136}, - {'k', ',', 0x0137}, - {'k', 'k', 0x0138}, - {'L', '\'', 0x0139}, - {'l', '\'', 0x013a}, - {'L', ',', 0x013b}, - {'l', ',', 0x013c}, - {'L', '<', 0x013d}, - {'l', '<', 0x013e}, - {'L', '.', 0x013f}, - {'l', '.', 0x0140}, - {'L', '/', 0x0141}, - {'l', '/', 0x0142}, - {'N', '\'', 0x0143}, - {'n', '\'', 0x0144}, - {'N', ',', 0x0145}, - {'n', ',', 0x0146}, - {'N', '<', 0x0147}, - {'n', '<', 0x0148}, - {'\'', 'n', 0x0149}, - {'N', 'G', 0x014a}, - {'n', 'g', 0x014b}, - {'O', '-', 0x014c}, - {'o', '-', 0x014d}, - {'O', '(', 0x014e}, - {'o', '(', 0x014f}, - {'O', '"', 0x0150}, - {'o', '"', 0x0151}, - {'O', 'E', 0x0152}, - {'o', 'e', 0x0153}, - {'R', '\'', 0x0154}, - {'r', '\'', 0x0155}, - {'R', ',', 0x0156}, - {'r', ',', 0x0157}, - {'R', '<', 0x0158}, - {'r', '<', 0x0159}, - {'S', '\'', 0x015a}, - {'s', '\'', 0x015b}, - {'S', '>', 0x015c}, - {'s', '>', 0x015d}, - {'S', ',', 0x015e}, - {'s', ',', 0x015f}, - {'S', '<', 0x0160}, - {'s', '<', 0x0161}, - {'T', ',', 0x0162}, - {'t', ',', 0x0163}, - {'T', '<', 0x0164}, - {'t', '<', 0x0165}, - {'T', '/', 0x0166}, - {'t', '/', 0x0167}, - {'U', '?', 0x0168}, - {'u', '?', 0x0169}, - {'U', '-', 0x016a}, - {'u', '-', 0x016b}, - {'U', '(', 0x016c}, - {'u', '(', 0x016d}, - {'U', '0', 0x016e}, - {'u', '0', 0x016f}, - {'U', '"', 0x0170}, - {'u', '"', 0x0171}, - {'U', ';', 0x0172}, - {'u', ';', 0x0173}, - {'W', '>', 0x0174}, - {'w', '>', 0x0175}, - {'Y', '>', 0x0176}, - {'y', '>', 0x0177}, - {'Y', ':', 0x0178}, - {'Z', '\'', 0x0179}, - {'z', '\'', 0x017a}, - {'Z', '.', 0x017b}, - {'z', '.', 0x017c}, - {'Z', '<', 0x017d}, - {'z', '<', 0x017e}, - {'O', '9', 0x01a0}, - {'o', '9', 0x01a1}, - {'O', 'I', 0x01a2}, - {'o', 'i', 0x01a3}, - {'y', 'r', 0x01a6}, - {'U', '9', 0x01af}, - {'u', '9', 0x01b0}, - {'Z', '/', 0x01b5}, - {'z', '/', 0x01b6}, - {'E', 'D', 0x01b7}, - {'A', '<', 0x01cd}, - {'a', '<', 0x01ce}, - {'I', '<', 0x01cf}, - {'i', '<', 0x01d0}, - {'O', '<', 0x01d1}, - {'o', '<', 0x01d2}, - {'U', '<', 0x01d3}, - {'u', '<', 0x01d4}, - {'A', '1', 0x01de}, - {'a', '1', 0x01df}, - {'A', '7', 0x01e0}, - {'a', '7', 0x01e1}, - {'A', '3', 0x01e2}, - {'a', '3', 0x01e3}, - {'G', '/', 0x01e4}, - {'g', '/', 0x01e5}, - {'G', '<', 0x01e6}, - {'g', '<', 0x01e7}, - {'K', '<', 0x01e8}, - {'k', '<', 0x01e9}, - {'O', ';', 0x01ea}, - {'o', ';', 0x01eb}, - {'O', '1', 0x01ec}, - {'o', '1', 0x01ed}, - {'E', 'Z', 0x01ee}, - {'e', 'z', 0x01ef}, - {'j', '<', 0x01f0}, - {'G', '\'', 0x01f4}, - {'g', '\'', 0x01f5}, - {';', 'S', 0x02bf}, - {'\'', '<', 0x02c7}, - {'\'', '(', 0x02d8}, - {'\'', '.', 0x02d9}, - {'\'', '0', 0x02da}, - {'\'', ';', 0x02db}, - {'\'', '"', 0x02dd}, - {'A', '%', 0x0386}, - {'E', '%', 0x0388}, - {'Y', '%', 0x0389}, - {'I', '%', 0x038a}, - {'O', '%', 0x038c}, - {'U', '%', 0x038e}, - {'W', '%', 0x038f}, - {'i', '3', 0x0390}, - {'A', '*', 0x0391}, - {'B', '*', 0x0392}, - {'G', '*', 0x0393}, - {'D', '*', 0x0394}, - {'E', '*', 0x0395}, - {'Z', '*', 0x0396}, - {'Y', '*', 0x0397}, - {'H', '*', 0x0398}, - {'I', '*', 0x0399}, - {'K', '*', 0x039a}, - {'L', '*', 0x039b}, - {'M', '*', 0x039c}, - {'N', '*', 0x039d}, - {'C', '*', 0x039e}, - {'O', '*', 0x039f}, - {'P', '*', 0x03a0}, - {'R', '*', 0x03a1}, - {'S', '*', 0x03a3}, - {'T', '*', 0x03a4}, - {'U', '*', 0x03a5}, - {'F', '*', 0x03a6}, - {'X', '*', 0x03a7}, - {'Q', '*', 0x03a8}, - {'W', '*', 0x03a9}, - {'J', '*', 0x03aa}, - {'V', '*', 0x03ab}, - {'a', '%', 0x03ac}, - {'e', '%', 0x03ad}, - {'y', '%', 0x03ae}, - {'i', '%', 0x03af}, - {'u', '3', 0x03b0}, - {'a', '*', 0x03b1}, - {'b', '*', 0x03b2}, - {'g', '*', 0x03b3}, - {'d', '*', 0x03b4}, - {'e', '*', 0x03b5}, - {'z', '*', 0x03b6}, - {'y', '*', 0x03b7}, - {'h', '*', 0x03b8}, - {'i', '*', 0x03b9}, - {'k', '*', 0x03ba}, - {'l', '*', 0x03bb}, - {'m', '*', 0x03bc}, - {'n', '*', 0x03bd}, - {'c', '*', 0x03be}, - {'o', '*', 0x03bf}, - {'p', '*', 0x03c0}, - {'r', '*', 0x03c1}, - {'*', 's', 0x03c2}, - {'s', '*', 0x03c3}, - {'t', '*', 0x03c4}, - {'u', '*', 0x03c5}, - {'f', '*', 0x03c6}, - {'x', '*', 0x03c7}, - {'q', '*', 0x03c8}, - {'w', '*', 0x03c9}, - {'j', '*', 0x03ca}, - {'v', '*', 0x03cb}, - {'o', '%', 0x03cc}, - {'u', '%', 0x03cd}, - {'w', '%', 0x03ce}, - {'\'', 'G', 0x03d8}, - {',', 'G', 0x03d9}, - {'T', '3', 0x03da}, - {'t', '3', 0x03db}, - {'M', '3', 0x03dc}, - {'m', '3', 0x03dd}, - {'K', '3', 0x03de}, - {'k', '3', 0x03df}, - {'P', '3', 0x03e0}, - {'p', '3', 0x03e1}, - {'\'', '%', 0x03f4}, - {'j', '3', 0x03f5}, - {'I', 'O', 0x0401}, - {'D', '%', 0x0402}, - {'G', '%', 0x0403}, - {'I', 'E', 0x0404}, - {'D', 'S', 0x0405}, - {'I', 'I', 0x0406}, - {'Y', 'I', 0x0407}, - {'J', '%', 0x0408}, - {'L', 'J', 0x0409}, - {'N', 'J', 0x040a}, - {'T', 's', 0x040b}, - {'K', 'J', 0x040c}, - {'V', '%', 0x040e}, - {'D', 'Z', 0x040f}, - {'A', '=', 0x0410}, - {'B', '=', 0x0411}, - {'V', '=', 0x0412}, - {'G', '=', 0x0413}, - {'D', '=', 0x0414}, - {'E', '=', 0x0415}, - {'Z', '%', 0x0416}, - {'Z', '=', 0x0417}, - {'I', '=', 0x0418}, - {'J', '=', 0x0419}, - {'K', '=', 0x041a}, - {'L', '=', 0x041b}, - {'M', '=', 0x041c}, - {'N', '=', 0x041d}, - {'O', '=', 0x041e}, - {'P', '=', 0x041f}, - {'R', '=', 0x0420}, - {'S', '=', 0x0421}, - {'T', '=', 0x0422}, - {'U', '=', 0x0423}, - {'F', '=', 0x0424}, - {'H', '=', 0x0425}, - {'C', '=', 0x0426}, - {'C', '%', 0x0427}, - {'S', '%', 0x0428}, - {'S', 'c', 0x0429}, - {'=', '"', 0x042a}, - {'Y', '=', 0x042b}, - {'%', '"', 0x042c}, - {'J', 'E', 0x042d}, - {'J', 'U', 0x042e}, - {'J', 'A', 0x042f}, - {'a', '=', 0x0430}, - {'b', '=', 0x0431}, - {'v', '=', 0x0432}, - {'g', '=', 0x0433}, - {'d', '=', 0x0434}, - {'e', '=', 0x0435}, - {'z', '%', 0x0436}, - {'z', '=', 0x0437}, - {'i', '=', 0x0438}, - {'j', '=', 0x0439}, - {'k', '=', 0x043a}, - {'l', '=', 0x043b}, - {'m', '=', 0x043c}, - {'n', '=', 0x043d}, - {'o', '=', 0x043e}, - {'p', '=', 0x043f}, - {'r', '=', 0x0440}, - {'s', '=', 0x0441}, - {'t', '=', 0x0442}, - {'u', '=', 0x0443}, - {'f', '=', 0x0444}, - {'h', '=', 0x0445}, - {'c', '=', 0x0446}, - {'c', '%', 0x0447}, - {'s', '%', 0x0448}, - {'s', 'c', 0x0449}, - {'=', '\'', 0x044a}, - {'y', '=', 0x044b}, - {'%', '\'', 0x044c}, - {'j', 'e', 0x044d}, - {'j', 'u', 0x044e}, - {'j', 'a', 0x044f}, - {'i', 'o', 0x0451}, - {'d', '%', 0x0452}, - {'g', '%', 0x0453}, - {'i', 'e', 0x0454}, - {'d', 's', 0x0455}, - {'i', 'i', 0x0456}, - {'y', 'i', 0x0457}, - {'j', '%', 0x0458}, - {'l', 'j', 0x0459}, - {'n', 'j', 0x045a}, - {'t', 's', 0x045b}, - {'k', 'j', 0x045c}, - {'v', '%', 0x045e}, - {'d', 'z', 0x045f}, - {'Y', '3', 0x0462}, - {'y', '3', 0x0463}, - {'O', '3', 0x046a}, - {'o', '3', 0x046b}, - {'F', '3', 0x0472}, - {'f', '3', 0x0473}, - {'V', '3', 0x0474}, - {'v', '3', 0x0475}, - {'C', '3', 0x0480}, - {'c', '3', 0x0481}, - {'G', '3', 0x0490}, - {'g', '3', 0x0491}, - {'A', '+', 0x05d0}, - {'B', '+', 0x05d1}, - {'G', '+', 0x05d2}, - {'D', '+', 0x05d3}, - {'H', '+', 0x05d4}, - {'W', '+', 0x05d5}, - {'Z', '+', 0x05d6}, - {'X', '+', 0x05d7}, - {'T', 'j', 0x05d8}, - {'J', '+', 0x05d9}, - {'K', '%', 0x05da}, - {'K', '+', 0x05db}, - {'L', '+', 0x05dc}, - {'M', '%', 0x05dd}, - {'M', '+', 0x05de}, - {'N', '%', 0x05df}, - {'N', '+', 0x05e0}, - {'S', '+', 0x05e1}, - {'E', '+', 0x05e2}, - {'P', '%', 0x05e3}, - {'P', '+', 0x05e4}, - {'Z', 'j', 0x05e5}, - {'Z', 'J', 0x05e6}, - {'Q', '+', 0x05e7}, - {'R', '+', 0x05e8}, - {'S', 'h', 0x05e9}, - {'T', '+', 0x05ea}, - {',', '+', 0x060c}, - {';', '+', 0x061b}, - {'?', '+', 0x061f}, - {'H', '\'', 0x0621}, - {'a', 'M', 0x0622}, - {'a', 'H', 0x0623}, - {'w', 'H', 0x0624}, - {'a', 'h', 0x0625}, - {'y', 'H', 0x0626}, - {'a', '+', 0x0627}, - {'b', '+', 0x0628}, - {'t', 'm', 0x0629}, - {'t', '+', 0x062a}, - {'t', 'k', 0x062b}, - {'g', '+', 0x062c}, - {'h', 'k', 0x062d}, - {'x', '+', 0x062e}, - {'d', '+', 0x062f}, - {'d', 'k', 0x0630}, - {'r', '+', 0x0631}, - {'z', '+', 0x0632}, - {'s', '+', 0x0633}, - {'s', 'n', 0x0634}, - {'c', '+', 0x0635}, - {'d', 'd', 0x0636}, - {'t', 'j', 0x0637}, - {'z', 'H', 0x0638}, - {'e', '+', 0x0639}, - {'i', '+', 0x063a}, - {'+', '+', 0x0640}, - {'f', '+', 0x0641}, - {'q', '+', 0x0642}, - {'k', '+', 0x0643}, - {'l', '+', 0x0644}, - {'m', '+', 0x0645}, - {'n', '+', 0x0646}, - {'h', '+', 0x0647}, - {'w', '+', 0x0648}, - {'j', '+', 0x0649}, - {'y', '+', 0x064a}, - {':', '+', 0x064b}, - {'"', '+', 0x064c}, - {'=', '+', 0x064d}, - {'/', '+', 0x064e}, - {'\'', '+', 0x064f}, - {'1', '+', 0x0650}, - {'3', '+', 0x0651}, - {'0', '+', 0x0652}, - {'a', 'S', 0x0670}, - {'p', '+', 0x067e}, - {'v', '+', 0x06a4}, - {'g', 'f', 0x06af}, - {'0', 'a', 0x06f0}, - {'1', 'a', 0x06f1}, - {'2', 'a', 0x06f2}, - {'3', 'a', 0x06f3}, - {'4', 'a', 0x06f4}, - {'5', 'a', 0x06f5}, - {'6', 'a', 0x06f6}, - {'7', 'a', 0x06f7}, - {'8', 'a', 0x06f8}, - {'9', 'a', 0x06f9}, - {'B', '.', 0x1e02}, - {'b', '.', 0x1e03}, - {'B', '_', 0x1e06}, - {'b', '_', 0x1e07}, - {'D', '.', 0x1e0a}, - {'d', '.', 0x1e0b}, - {'D', '_', 0x1e0e}, - {'d', '_', 0x1e0f}, - {'D', ',', 0x1e10}, - {'d', ',', 0x1e11}, - {'F', '.', 0x1e1e}, - {'f', '.', 0x1e1f}, - {'G', '-', 0x1e20}, - {'g', '-', 0x1e21}, - {'H', '.', 0x1e22}, - {'h', '.', 0x1e23}, - {'H', ':', 0x1e26}, - {'h', ':', 0x1e27}, - {'H', ',', 0x1e28}, - {'h', ',', 0x1e29}, - {'K', '\'', 0x1e30}, - {'k', '\'', 0x1e31}, - {'K', '_', 0x1e34}, - {'k', '_', 0x1e35}, - {'L', '_', 0x1e3a}, - {'l', '_', 0x1e3b}, - {'M', '\'', 0x1e3e}, - {'m', '\'', 0x1e3f}, - {'M', '.', 0x1e40}, - {'m', '.', 0x1e41}, - {'N', '.', 0x1e44}, - {'n', '.', 0x1e45}, - {'N', '_', 0x1e48}, - {'n', '_', 0x1e49}, - {'P', '\'', 0x1e54}, - {'p', '\'', 0x1e55}, - {'P', '.', 0x1e56}, - {'p', '.', 0x1e57}, - {'R', '.', 0x1e58}, - {'r', '.', 0x1e59}, - {'R', '_', 0x1e5e}, - {'r', '_', 0x1e5f}, - {'S', '.', 0x1e60}, - {'s', '.', 0x1e61}, - {'T', '.', 0x1e6a}, - {'t', '.', 0x1e6b}, - {'T', '_', 0x1e6e}, - {'t', '_', 0x1e6f}, - {'V', '?', 0x1e7c}, - {'v', '?', 0x1e7d}, - {'W', '!', 0x1e80}, - {'w', '!', 0x1e81}, - {'W', '\'', 0x1e82}, - {'w', '\'', 0x1e83}, - {'W', ':', 0x1e84}, - {'w', ':', 0x1e85}, - {'W', '.', 0x1e86}, - {'w', '.', 0x1e87}, - {'X', '.', 0x1e8a}, - {'x', '.', 0x1e8b}, - {'X', ':', 0x1e8c}, - {'x', ':', 0x1e8d}, - {'Y', '.', 0x1e8e}, - {'y', '.', 0x1e8f}, - {'Z', '>', 0x1e90}, - {'z', '>', 0x1e91}, - {'Z', '_', 0x1e94}, - {'z', '_', 0x1e95}, - {'h', '_', 0x1e96}, - {'t', ':', 0x1e97}, - {'w', '0', 0x1e98}, - {'y', '0', 0x1e99}, - {'A', '2', 0x1ea2}, - {'a', '2', 0x1ea3}, - {'E', '2', 0x1eba}, - {'e', '2', 0x1ebb}, - {'E', '?', 0x1ebc}, - {'e', '?', 0x1ebd}, - {'I', '2', 0x1ec8}, - {'i', '2', 0x1ec9}, - {'O', '2', 0x1ece}, - {'o', '2', 0x1ecf}, - {'U', '2', 0x1ee6}, - {'u', '2', 0x1ee7}, - {'Y', '!', 0x1ef2}, - {'y', '!', 0x1ef3}, - {'Y', '2', 0x1ef6}, - {'y', '2', 0x1ef7}, - {'Y', '?', 0x1ef8}, - {'y', '?', 0x1ef9}, - {';', '\'', 0x1f00}, - {',', '\'', 0x1f01}, - {';', '!', 0x1f02}, - {',', '!', 0x1f03}, - {'?', ';', 0x1f04}, - {'?', ',', 0x1f05}, - {'!', ':', 0x1f06}, - {'?', ':', 0x1f07}, - {'1', 'N', 0x2002}, - {'1', 'M', 0x2003}, - {'3', 'M', 0x2004}, - {'4', 'M', 0x2005}, - {'6', 'M', 0x2006}, - {'1', 'T', 0x2009}, - {'1', 'H', 0x200a}, - {'-', '1', 0x2010}, - {'-', 'N', 0x2013}, - {'-', 'M', 0x2014}, - {'-', '3', 0x2015}, - {'!', '2', 0x2016}, - {'=', '2', 0x2017}, - {'\'', '6', 0x2018}, - {'\'', '9', 0x2019}, - {'.', '9', 0x201a}, - {'9', '\'', 0x201b}, - {'"', '6', 0x201c}, - {'"', '9', 0x201d}, - {':', '9', 0x201e}, - {'9', '"', 0x201f}, - {'/', '-', 0x2020}, - {'/', '=', 0x2021}, - {'.', '.', 0x2025}, - {'%', '0', 0x2030}, - {'1', '\'', 0x2032}, - {'2', '\'', 0x2033}, - {'3', '\'', 0x2034}, - {'1', '"', 0x2035}, - {'2', '"', 0x2036}, - {'3', '"', 0x2037}, - {'C', 'a', 0x2038}, - {'<', '1', 0x2039}, - {'>', '1', 0x203a}, - {':', 'X', 0x203b}, - {'\'', '-', 0x203e}, - {'/', 'f', 0x2044}, - {'0', 'S', 0x2070}, - {'4', 'S', 0x2074}, - {'5', 'S', 0x2075}, - {'6', 'S', 0x2076}, - {'7', 'S', 0x2077}, - {'8', 'S', 0x2078}, - {'9', 'S', 0x2079}, - {'+', 'S', 0x207a}, - {'-', 'S', 0x207b}, - {'=', 'S', 0x207c}, - {'(', 'S', 0x207d}, - {')', 'S', 0x207e}, - {'n', 'S', 0x207f}, - {'0', 's', 0x2080}, - {'1', 's', 0x2081}, - {'2', 's', 0x2082}, - {'3', 's', 0x2083}, - {'4', 's', 0x2084}, - {'5', 's', 0x2085}, - {'6', 's', 0x2086}, - {'7', 's', 0x2087}, - {'8', 's', 0x2088}, - {'9', 's', 0x2089}, - {'+', 's', 0x208a}, - {'-', 's', 0x208b}, - {'=', 's', 0x208c}, - {'(', 's', 0x208d}, - {')', 's', 0x208e}, - {'L', 'i', 0x20a4}, - {'P', 't', 0x20a7}, - {'W', '=', 0x20a9}, - {'=', 'e', 0x20ac}, /* euro */ - {'E', 'u', 0x20ac}, /* euro */ - {'o', 'C', 0x2103}, - {'c', 'o', 0x2105}, - {'o', 'F', 0x2109}, - {'N', '0', 0x2116}, - {'P', 'O', 0x2117}, - {'R', 'x', 0x211e}, - {'S', 'M', 0x2120}, - {'T', 'M', 0x2122}, - {'O', 'm', 0x2126}, - {'A', 'O', 0x212b}, - {'1', '3', 0x2153}, - {'2', '3', 0x2154}, - {'1', '5', 0x2155}, - {'2', '5', 0x2156}, - {'3', '5', 0x2157}, - {'4', '5', 0x2158}, - {'1', '6', 0x2159}, - {'5', '6', 0x215a}, - {'1', '8', 0x215b}, - {'3', '8', 0x215c}, - {'5', '8', 0x215d}, - {'7', '8', 0x215e}, - {'1', 'R', 0x2160}, - {'2', 'R', 0x2161}, - {'3', 'R', 0x2162}, - {'4', 'R', 0x2163}, - {'5', 'R', 0x2164}, - {'6', 'R', 0x2165}, - {'7', 'R', 0x2166}, - {'8', 'R', 0x2167}, - {'9', 'R', 0x2168}, - {'a', 'R', 0x2169}, - {'b', 'R', 0x216a}, - {'c', 'R', 0x216b}, - {'1', 'r', 0x2170}, - {'2', 'r', 0x2171}, - {'3', 'r', 0x2172}, - {'4', 'r', 0x2173}, - {'5', 'r', 0x2174}, - {'6', 'r', 0x2175}, - {'7', 'r', 0x2176}, - {'8', 'r', 0x2177}, - {'9', 'r', 0x2178}, - {'a', 'r', 0x2179}, - {'b', 'r', 0x217a}, - {'c', 'r', 0x217b}, - {'<', '-', 0x2190}, - {'-', '!', 0x2191}, - {'-', '>', 0x2192}, - {'-', 'v', 0x2193}, - {'<', '>', 0x2194}, - {'U', 'D', 0x2195}, - {'<', '=', 0x21d0}, - {'=', '>', 0x21d2}, - {'=', '=', 0x21d4}, - {'F', 'A', 0x2200}, - {'d', 'P', 0x2202}, - {'T', 'E', 0x2203}, - {'/', '0', 0x2205}, - {'D', 'E', 0x2206}, - {'N', 'B', 0x2207}, - {'(', '-', 0x2208}, - {'-', ')', 0x220b}, - {'*', 'P', 0x220f}, - {'+', 'Z', 0x2211}, - {'-', '2', 0x2212}, - {'-', '+', 0x2213}, - {'*', '-', 0x2217}, - {'O', 'b', 0x2218}, - {'S', 'b', 0x2219}, - {'R', 'T', 0x221a}, - {'0', '(', 0x221d}, - {'0', '0', 0x221e}, - {'-', 'L', 0x221f}, - {'-', 'V', 0x2220}, - {'P', 'P', 0x2225}, - {'A', 'N', 0x2227}, - {'O', 'R', 0x2228}, - {'(', 'U', 0x2229}, - {')', 'U', 0x222a}, - {'I', 'n', 0x222b}, - {'D', 'I', 0x222c}, - {'I', 'o', 0x222e}, - {'.', ':', 0x2234}, - {':', '.', 0x2235}, - {':', 'R', 0x2236}, - {':', ':', 0x2237}, - {'?', '1', 0x223c}, - {'C', 'G', 0x223e}, - {'?', '-', 0x2243}, - {'?', '=', 0x2245}, - {'?', '2', 0x2248}, - {'=', '?', 0x224c}, - {'H', 'I', 0x2253}, - {'!', '=', 0x2260}, - {'=', '3', 0x2261}, - {'=', '<', 0x2264}, - {'>', '=', 0x2265}, - {'<', '*', 0x226a}, - {'*', '>', 0x226b}, - {'!', '<', 0x226e}, - {'!', '>', 0x226f}, - {'(', 'C', 0x2282}, - {')', 'C', 0x2283}, - {'(', '_', 0x2286}, - {')', '_', 0x2287}, - {'0', '.', 0x2299}, - {'0', '2', 0x229a}, - {'-', 'T', 0x22a5}, - {'.', 'P', 0x22c5}, - {':', '3', 0x22ee}, - {'.', '3', 0x22ef}, - {'E', 'h', 0x2302}, - {'<', '7', 0x2308}, - {'>', '7', 0x2309}, - {'7', '<', 0x230a}, - {'7', '>', 0x230b}, - {'N', 'I', 0x2310}, - {'(', 'A', 0x2312}, - {'T', 'R', 0x2315}, - {'I', 'u', 0x2320}, - {'I', 'l', 0x2321}, - {'<', '/', 0x2329}, - {'/', '>', 0x232a}, - {'V', 's', 0x2423}, - {'1', 'h', 0x2440}, - {'3', 'h', 0x2441}, - {'2', 'h', 0x2442}, - {'4', 'h', 0x2443}, - {'1', 'j', 0x2446}, - {'2', 'j', 0x2447}, - {'3', 'j', 0x2448}, - {'4', 'j', 0x2449}, - {'1', '.', 0x2488}, - {'2', '.', 0x2489}, - {'3', '.', 0x248a}, - {'4', '.', 0x248b}, - {'5', '.', 0x248c}, - {'6', '.', 0x248d}, - {'7', '.', 0x248e}, - {'8', '.', 0x248f}, - {'9', '.', 0x2490}, - {'h', 'h', 0x2500}, - {'H', 'H', 0x2501}, - {'v', 'v', 0x2502}, - {'V', 'V', 0x2503}, - {'3', '-', 0x2504}, - {'3', '_', 0x2505}, - {'3', '!', 0x2506}, - {'3', '/', 0x2507}, - {'4', '-', 0x2508}, - {'4', '_', 0x2509}, - {'4', '!', 0x250a}, - {'4', '/', 0x250b}, - {'d', 'r', 0x250c}, - {'d', 'R', 0x250d}, - {'D', 'r', 0x250e}, - {'D', 'R', 0x250f}, - {'d', 'l', 0x2510}, - {'d', 'L', 0x2511}, - {'D', 'l', 0x2512}, - {'L', 'D', 0x2513}, - {'u', 'r', 0x2514}, - {'u', 'R', 0x2515}, - {'U', 'r', 0x2516}, - {'U', 'R', 0x2517}, - {'u', 'l', 0x2518}, - {'u', 'L', 0x2519}, - {'U', 'l', 0x251a}, - {'U', 'L', 0x251b}, - {'v', 'r', 0x251c}, - {'v', 'R', 0x251d}, - {'V', 'r', 0x2520}, - {'V', 'R', 0x2523}, - {'v', 'l', 0x2524}, - {'v', 'L', 0x2525}, - {'V', 'l', 0x2528}, - {'V', 'L', 0x252b}, - {'d', 'h', 0x252c}, - {'d', 'H', 0x252f}, - {'D', 'h', 0x2530}, - {'D', 'H', 0x2533}, - {'u', 'h', 0x2534}, - {'u', 'H', 0x2537}, - {'U', 'h', 0x2538}, - {'U', 'H', 0x253b}, - {'v', 'h', 0x253c}, - {'v', 'H', 0x253f}, - {'V', 'h', 0x2542}, - {'V', 'H', 0x254b}, - {'F', 'D', 0x2571}, - {'B', 'D', 0x2572}, - {'T', 'B', 0x2580}, - {'L', 'B', 0x2584}, - {'F', 'B', 0x2588}, - {'l', 'B', 0x258c}, - {'R', 'B', 0x2590}, - {'.', 'S', 0x2591}, - {':', 'S', 0x2592}, - {'?', 'S', 0x2593}, - {'f', 'S', 0x25a0}, - {'O', 'S', 0x25a1}, - {'R', 'O', 0x25a2}, - {'R', 'r', 0x25a3}, - {'R', 'F', 0x25a4}, - {'R', 'Y', 0x25a5}, - {'R', 'H', 0x25a6}, - {'R', 'Z', 0x25a7}, - {'R', 'K', 0x25a8}, - {'R', 'X', 0x25a9}, - {'s', 'B', 0x25aa}, - {'S', 'R', 0x25ac}, - {'O', 'r', 0x25ad}, - {'U', 'T', 0x25b2}, - {'u', 'T', 0x25b3}, - {'P', 'R', 0x25b6}, - {'T', 'r', 0x25b7}, - {'D', 't', 0x25bc}, - {'d', 'T', 0x25bd}, - {'P', 'L', 0x25c0}, - {'T', 'l', 0x25c1}, - {'D', 'b', 0x25c6}, - {'D', 'w', 0x25c7}, - {'L', 'Z', 0x25ca}, - {'0', 'm', 0x25cb}, - {'0', 'o', 0x25ce}, - {'0', 'M', 0x25cf}, - {'0', 'L', 0x25d0}, - {'0', 'R', 0x25d1}, - {'S', 'n', 0x25d8}, - {'I', 'c', 0x25d9}, - {'F', 'd', 0x25e2}, - {'B', 'd', 0x25e3}, - {'*', '2', 0x2605}, - {'*', '1', 0x2606}, - {'<', 'H', 0x261c}, - {'>', 'H', 0x261e}, - {'0', 'u', 0x263a}, - {'0', 'U', 0x263b}, - {'S', 'U', 0x263c}, - {'F', 'm', 0x2640}, - {'M', 'l', 0x2642}, - {'c', 'S', 0x2660}, - {'c', 'H', 0x2661}, - {'c', 'D', 0x2662}, - {'c', 'C', 0x2663}, - {'M', 'd', 0x2669}, - {'M', '8', 0x266a}, - {'M', '2', 0x266b}, - {'M', 'b', 0x266d}, - {'M', 'x', 0x266e}, - {'M', 'X', 0x266f}, - {'O', 'K', 0x2713}, - {'X', 'X', 0x2717}, - {'-', 'X', 0x2720}, - {'I', 'S', 0x3000}, - {',', '_', 0x3001}, - {'.', '_', 0x3002}, - {'+', '"', 0x3003}, - {'+', '_', 0x3004}, - {'*', '_', 0x3005}, - {';', '_', 0x3006}, - {'0', '_', 0x3007}, - {'<', '+', 0x300a}, - {'>', '+', 0x300b}, - {'<', '\'', 0x300c}, - {'>', '\'', 0x300d}, - {'<', '"', 0x300e}, - {'>', '"', 0x300f}, - {'(', '"', 0x3010}, - {')', '"', 0x3011}, - {'=', 'T', 0x3012}, - {'=', '_', 0x3013}, - {'(', '\'', 0x3014}, - {')', '\'', 0x3015}, - {'(', 'I', 0x3016}, - {')', 'I', 0x3017}, - {'-', '?', 0x301c}, - {'A', '5', 0x3041}, - {'a', '5', 0x3042}, - {'I', '5', 0x3043}, - {'i', '5', 0x3044}, - {'U', '5', 0x3045}, - {'u', '5', 0x3046}, - {'E', '5', 0x3047}, - {'e', '5', 0x3048}, - {'O', '5', 0x3049}, - {'o', '5', 0x304a}, - {'k', 'a', 0x304b}, - {'g', 'a', 0x304c}, - {'k', 'i', 0x304d}, - {'g', 'i', 0x304e}, - {'k', 'u', 0x304f}, - {'g', 'u', 0x3050}, - {'k', 'e', 0x3051}, - {'g', 'e', 0x3052}, - {'k', 'o', 0x3053}, - {'g', 'o', 0x3054}, - {'s', 'a', 0x3055}, - {'z', 'a', 0x3056}, - {'s', 'i', 0x3057}, - {'z', 'i', 0x3058}, - {'s', 'u', 0x3059}, - {'z', 'u', 0x305a}, - {'s', 'e', 0x305b}, - {'z', 'e', 0x305c}, - {'s', 'o', 0x305d}, - {'z', 'o', 0x305e}, - {'t', 'a', 0x305f}, - {'d', 'a', 0x3060}, - {'t', 'i', 0x3061}, - {'d', 'i', 0x3062}, - {'t', 'U', 0x3063}, - {'t', 'u', 0x3064}, - {'d', 'u', 0x3065}, - {'t', 'e', 0x3066}, - {'d', 'e', 0x3067}, - {'t', 'o', 0x3068}, - {'d', 'o', 0x3069}, - {'n', 'a', 0x306a}, - {'n', 'i', 0x306b}, - {'n', 'u', 0x306c}, - {'n', 'e', 0x306d}, - {'n', 'o', 0x306e}, - {'h', 'a', 0x306f}, - {'b', 'a', 0x3070}, - {'p', 'a', 0x3071}, - {'h', 'i', 0x3072}, - {'b', 'i', 0x3073}, - {'p', 'i', 0x3074}, - {'h', 'u', 0x3075}, - {'b', 'u', 0x3076}, - {'p', 'u', 0x3077}, - {'h', 'e', 0x3078}, - {'b', 'e', 0x3079}, - {'p', 'e', 0x307a}, - {'h', 'o', 0x307b}, - {'b', 'o', 0x307c}, - {'p', 'o', 0x307d}, - {'m', 'a', 0x307e}, - {'m', 'i', 0x307f}, - {'m', 'u', 0x3080}, - {'m', 'e', 0x3081}, - {'m', 'o', 0x3082}, - {'y', 'A', 0x3083}, - {'y', 'a', 0x3084}, - {'y', 'U', 0x3085}, - {'y', 'u', 0x3086}, - {'y', 'O', 0x3087}, - {'y', 'o', 0x3088}, - {'r', 'a', 0x3089}, - {'r', 'i', 0x308a}, - {'r', 'u', 0x308b}, - {'r', 'e', 0x308c}, - {'r', 'o', 0x308d}, - {'w', 'A', 0x308e}, - {'w', 'a', 0x308f}, - {'w', 'i', 0x3090}, - {'w', 'e', 0x3091}, - {'w', 'o', 0x3092}, - {'n', '5', 0x3093}, - {'v', 'u', 0x3094}, - {'"', '5', 0x309b}, - {'0', '5', 0x309c}, - {'*', '5', 0x309d}, - {'+', '5', 0x309e}, - {'a', '6', 0x30a1}, - {'A', '6', 0x30a2}, - {'i', '6', 0x30a3}, - {'I', '6', 0x30a4}, - {'u', '6', 0x30a5}, - {'U', '6', 0x30a6}, - {'e', '6', 0x30a7}, - {'E', '6', 0x30a8}, - {'o', '6', 0x30a9}, - {'O', '6', 0x30aa}, - {'K', 'a', 0x30ab}, - {'G', 'a', 0x30ac}, - {'K', 'i', 0x30ad}, - {'G', 'i', 0x30ae}, - {'K', 'u', 0x30af}, - {'G', 'u', 0x30b0}, - {'K', 'e', 0x30b1}, - {'G', 'e', 0x30b2}, - {'K', 'o', 0x30b3}, - {'G', 'o', 0x30b4}, - {'S', 'a', 0x30b5}, - {'Z', 'a', 0x30b6}, - {'S', 'i', 0x30b7}, - {'Z', 'i', 0x30b8}, - {'S', 'u', 0x30b9}, - {'Z', 'u', 0x30ba}, - {'S', 'e', 0x30bb}, - {'Z', 'e', 0x30bc}, - {'S', 'o', 0x30bd}, - {'Z', 'o', 0x30be}, - {'T', 'a', 0x30bf}, - {'D', 'a', 0x30c0}, - {'T', 'i', 0x30c1}, - {'D', 'i', 0x30c2}, - {'T', 'U', 0x30c3}, - {'T', 'u', 0x30c4}, - {'D', 'u', 0x30c5}, - {'T', 'e', 0x30c6}, - {'D', 'e', 0x30c7}, - {'T', 'o', 0x30c8}, - {'D', 'o', 0x30c9}, - {'N', 'a', 0x30ca}, - {'N', 'i', 0x30cb}, - {'N', 'u', 0x30cc}, - {'N', 'e', 0x30cd}, - {'N', 'o', 0x30ce}, - {'H', 'a', 0x30cf}, - {'B', 'a', 0x30d0}, - {'P', 'a', 0x30d1}, - {'H', 'i', 0x30d2}, - {'B', 'i', 0x30d3}, - {'P', 'i', 0x30d4}, - {'H', 'u', 0x30d5}, - {'B', 'u', 0x30d6}, - {'P', 'u', 0x30d7}, - {'H', 'e', 0x30d8}, - {'B', 'e', 0x30d9}, - {'P', 'e', 0x30da}, - {'H', 'o', 0x30db}, - {'B', 'o', 0x30dc}, - {'P', 'o', 0x30dd}, - {'M', 'a', 0x30de}, - {'M', 'i', 0x30df}, - {'M', 'u', 0x30e0}, - {'M', 'e', 0x30e1}, - {'M', 'o', 0x30e2}, - {'Y', 'A', 0x30e3}, - {'Y', 'a', 0x30e4}, - {'Y', 'U', 0x30e5}, - {'Y', 'u', 0x30e6}, - {'Y', 'O', 0x30e7}, - {'Y', 'o', 0x30e8}, - {'R', 'a', 0x30e9}, - {'R', 'i', 0x30ea}, - {'R', 'u', 0x30eb}, - {'R', 'e', 0x30ec}, - {'R', 'o', 0x30ed}, - {'W', 'A', 0x30ee}, - {'W', 'a', 0x30ef}, - {'W', 'i', 0x30f0}, - {'W', 'e', 0x30f1}, - {'W', 'o', 0x30f2}, - {'N', '6', 0x30f3}, - {'V', 'u', 0x30f4}, - {'K', 'A', 0x30f5}, - {'K', 'E', 0x30f6}, - {'V', 'a', 0x30f7}, - {'V', 'i', 0x30f8}, - {'V', 'e', 0x30f9}, - {'V', 'o', 0x30fa}, - {'.', '6', 0x30fb}, - {'-', '6', 0x30fc}, - {'*', '6', 0x30fd}, - {'+', '6', 0x30fe}, - {'b', '4', 0x3105}, - {'p', '4', 0x3106}, - {'m', '4', 0x3107}, - {'f', '4', 0x3108}, - {'d', '4', 0x3109}, - {'t', '4', 0x310a}, - {'n', '4', 0x310b}, - {'l', '4', 0x310c}, - {'g', '4', 0x310d}, - {'k', '4', 0x310e}, - {'h', '4', 0x310f}, - {'j', '4', 0x3110}, - {'q', '4', 0x3111}, - {'x', '4', 0x3112}, - {'z', 'h', 0x3113}, - {'c', 'h', 0x3114}, - {'s', 'h', 0x3115}, - {'r', '4', 0x3116}, - {'z', '4', 0x3117}, - {'c', '4', 0x3118}, - {'s', '4', 0x3119}, - {'a', '4', 0x311a}, - {'o', '4', 0x311b}, - {'e', '4', 0x311c}, - {'a', 'i', 0x311e}, - {'e', 'i', 0x311f}, - {'a', 'u', 0x3120}, - {'o', 'u', 0x3121}, - {'a', 'n', 0x3122}, - {'e', 'n', 0x3123}, - {'a', 'N', 0x3124}, - {'e', 'N', 0x3125}, - {'e', 'r', 0x3126}, - {'i', '4', 0x3127}, - {'u', '4', 0x3128}, - {'i', 'u', 0x3129}, - {'v', '4', 0x312a}, - {'n', 'G', 0x312b}, - {'g', 'n', 0x312c}, - {'1', 'c', 0x3220}, - {'2', 'c', 0x3221}, - {'3', 'c', 0x3222}, - {'4', 'c', 0x3223}, - {'5', 'c', 0x3224}, - {'6', 'c', 0x3225}, - {'7', 'c', 0x3226}, - {'8', 'c', 0x3227}, - {'9', 'c', 0x3228}, - /* code points 0xe000 - 0xefff excluded, they have no assigned - * characters, only used in proposals. */ - {'f', 'f', 0xfb00}, - {'f', 'i', 0xfb01}, - {'f', 'l', 0xfb02}, - {'f', 't', 0xfb05}, - {'s', 't', 0xfb06}, - - /* Vim 5.x compatible digraphs that don't conflict with the above */ - {'~', '!', 161}, /* ¡ */ - {'c', '|', 162}, /* ¢ */ - {'$', '$', 163}, /* £ */ - {'o', 'x', 164}, /* ¤ - currency symbol in ISO 8859-1 */ - {'Y', '-', 165}, /* ¥ */ - {'|', '|', 166}, /* ¦ */ - {'c', 'O', 169}, /* © */ - {'-', ',', 172}, /* ¬ */ - {'-', '=', 175}, /* ¯ */ - {'~', 'o', 176}, /* ° */ - {'2', '2', 178}, /* ² */ - {'3', '3', 179}, /* ³ */ - {'p', 'p', 182}, /* ¶ */ - {'~', '.', 183}, /* · */ - {'1', '1', 185}, /* ¹ */ - {'~', '?', 191}, /* ¿ */ - {'A', '`', 192}, /* À */ - {'A', '^', 194}, /* Â */ - {'A', '~', 195}, /* Ã */ - {'A', '"', 196}, /* Ä */ - {'A', '@', 197}, /* Å */ - {'E', '`', 200}, /* È */ - {'E', '^', 202}, /* Ê */ - {'E', '"', 203}, /* Ë */ - {'I', '`', 204}, /* Ì */ - {'I', '^', 206}, /* Î */ - {'I', '"', 207}, /* Ï */ - {'N', '~', 209}, /* Ñ */ - {'O', '`', 210}, /* Ò */ - {'O', '^', 212}, /* Ô */ - {'O', '~', 213}, /* Õ */ - {'/', '\\', 215}, /* × - multiplication symbol in ISO 8859-1 */ - {'U', '`', 217}, /* Ù */ - {'U', '^', 219}, /* Û */ - {'I', 'p', 222}, /* Þ */ - {'a', '`', 224}, /* à */ - {'a', '^', 226}, /* â */ - {'a', '~', 227}, /* ã */ - {'a', '"', 228}, /* ä */ - {'a', '@', 229}, /* å */ - {'e', '`', 232}, /* è */ - {'e', '^', 234}, /* ê */ - {'e', '"', 235}, /* ë */ - {'i', '`', 236}, /* ì */ - {'i', '^', 238}, /* î */ - {'n', '~', 241}, /* ñ */ - {'o', '`', 242}, /* ò */ - {'o', '^', 244}, /* ô */ - {'o', '~', 245}, /* õ */ - {'u', '`', 249}, /* ù */ - {'u', '^', 251}, /* û */ - {'y', '"', 255}, /* x XX */ - - {NUL, NUL, NUL} + { 'N', 'U', 0x0a }, // LF for NUL + { 'S', 'H', 0x01 }, + { 'S', 'X', 0x02 }, + { 'E', 'X', 0x03 }, + { 'E', 'T', 0x04 }, + { 'E', 'Q', 0x05 }, + { 'A', 'K', 0x06 }, + { 'B', 'L', 0x07 }, + { 'B', 'S', 0x08 }, + { 'H', 'T', 0x09 }, + { 'L', 'F', 0x0a }, + { 'V', 'T', 0x0b }, + { 'F', 'F', 0x0c }, + { 'C', 'R', 0x0d }, + { 'S', 'O', 0x0e }, + { 'S', 'I', 0x0f }, + { 'D', 'L', 0x10 }, + { 'D', '1', 0x11 }, + { 'D', '2', 0x12 }, + { 'D', '3', 0x13 }, + { 'D', '4', 0x14 }, + { 'N', 'K', 0x15 }, + { 'S', 'Y', 0x16 }, + { 'E', 'B', 0x17 }, + { 'C', 'N', 0x18 }, + { 'E', 'M', 0x19 }, + { 'S', 'B', 0x1a }, + { 'E', 'C', 0x1b }, + { 'F', 'S', 0x1c }, + { 'G', 'S', 0x1d }, + { 'R', 'S', 0x1e }, + { 'U', 'S', 0x1f }, + { 'S', 'P', 0x20 }, + { 'N', 'b', 0x23 }, + { 'D', 'O', 0x24 }, + { 'A', 't', 0x40 }, + { '<', '(', 0x5b }, + { '/', '/', 0x5c }, + { ')', '>', 0x5d }, + { '\'', '>', 0x5e }, + { '\'', '!', 0x60 }, + { '(', '!', 0x7b }, + { '!', '!', 0x7c }, + { '!', ')', 0x7d }, + { '\'', '?', 0x7e }, + { 'D', 'T', 0x7f }, + { 'P', 'A', 0x80 }, + { 'H', 'O', 0x81 }, + { 'B', 'H', 0x82 }, + { 'N', 'H', 0x83 }, + { 'I', 'N', 0x84 }, + { 'N', 'L', 0x85 }, + { 'S', 'A', 0x86 }, + { 'E', 'S', 0x87 }, + { 'H', 'S', 0x88 }, + { 'H', 'J', 0x89 }, + { 'V', 'S', 0x8a }, + { 'P', 'D', 0x8b }, + { 'P', 'U', 0x8c }, + { 'R', 'I', 0x8d }, + { 'S', '2', 0x8e }, + { 'S', '3', 0x8f }, + { 'D', 'C', 0x90 }, + { 'P', '1', 0x91 }, + { 'P', '2', 0x92 }, + { 'T', 'S', 0x93 }, + { 'C', 'C', 0x94 }, + { 'M', 'W', 0x95 }, + { 'S', 'G', 0x96 }, + { 'E', 'G', 0x97 }, + { 'S', 'S', 0x98 }, + { 'G', 'C', 0x99 }, + { 'S', 'C', 0x9a }, + { 'C', 'I', 0x9b }, + { 'S', 'T', 0x9c }, + { 'O', 'C', 0x9d }, + { 'P', 'M', 0x9e }, + { 'A', 'C', 0x9f }, + { 'N', 'S', 0xa0 }, + { '!', 'I', 0xa1 }, + { 'C', 't', 0xa2 }, + { 'P', 'd', 0xa3 }, + { 'C', 'u', 0xa4 }, + { 'Y', 'e', 0xa5 }, + { 'B', 'B', 0xa6 }, + { 'S', 'E', 0xa7 }, + { '\'', ':', 0xa8 }, + { 'C', 'o', 0xa9 }, + { '-', 'a', 0xaa }, + { '<', '<', 0xab }, + { 'N', 'O', 0xac }, + { '-', '-', 0xad }, + { 'R', 'g', 0xae }, + { '\'', 'm', 0xaf }, + { 'D', 'G', 0xb0 }, + { '+', '-', 0xb1 }, + { '2', 'S', 0xb2 }, + { '3', 'S', 0xb3 }, + { '\'', '\'', 0xb4 }, + { 'M', 'y', 0xb5 }, + { 'P', 'I', 0xb6 }, + { '.', 'M', 0xb7 }, + { '\'', ',', 0xb8 }, + { '1', 'S', 0xb9 }, + { '-', 'o', 0xba }, + { '>', '>', 0xbb }, + { '1', '4', 0xbc }, + { '1', '2', 0xbd }, + { '3', '4', 0xbe }, + { '?', 'I', 0xbf }, + { 'A', '!', 0xc0 }, + { 'A', '\'', 0xc1 }, + { 'A', '>', 0xc2 }, + { 'A', '?', 0xc3 }, + { 'A', ':', 0xc4 }, + { 'A', 'A', 0xc5 }, + { 'A', 'E', 0xc6 }, + { 'C', ',', 0xc7 }, + { 'E', '!', 0xc8 }, + { 'E', '\'', 0xc9 }, + { 'E', '>', 0xca }, + { 'E', ':', 0xcb }, + { 'I', '!', 0xcc }, + { 'I', '\'', 0xcd }, + { 'I', '>', 0xce }, + { 'I', ':', 0xcf }, + { 'D', '-', 0xd0 }, + { 'N', '?', 0xd1 }, + { 'O', '!', 0xd2 }, + { 'O', '\'', 0xd3 }, + { 'O', '>', 0xd4 }, + { 'O', '?', 0xd5 }, + { 'O', ':', 0xd6 }, + { '*', 'X', 0xd7 }, + { 'O', '/', 0xd8 }, + { 'U', '!', 0xd9 }, + { 'U', '\'', 0xda }, + { 'U', '>', 0xdb }, + { 'U', ':', 0xdc }, + { 'Y', '\'', 0xdd }, + { 'T', 'H', 0xde }, + { 's', 's', 0xdf }, + { 'a', '!', 0xe0 }, + { 'a', '\'', 0xe1 }, + { 'a', '>', 0xe2 }, + { 'a', '?', 0xe3 }, + { 'a', ':', 0xe4 }, + { 'a', 'a', 0xe5 }, + { 'a', 'e', 0xe6 }, + { 'c', ',', 0xe7 }, + { 'e', '!', 0xe8 }, + { 'e', '\'', 0xe9 }, + { 'e', '>', 0xea }, + { 'e', ':', 0xeb }, + { 'i', '!', 0xec }, + { 'i', '\'', 0xed }, + { 'i', '>', 0xee }, + { 'i', ':', 0xef }, + { 'd', '-', 0xf0 }, + { 'n', '?', 0xf1 }, + { 'o', '!', 0xf2 }, + { 'o', '\'', 0xf3 }, + { 'o', '>', 0xf4 }, + { 'o', '?', 0xf5 }, + { 'o', ':', 0xf6 }, + { '-', ':', 0xf7 }, + { 'o', '/', 0xf8 }, + { 'u', '!', 0xf9 }, + { 'u', '\'', 0xfa }, + { 'u', '>', 0xfb }, + { 'u', ':', 0xfc }, + { 'y', '\'', 0xfd }, + { 't', 'h', 0xfe }, + { 'y', ':', 0xff }, + +# define USE_UNICODE_DIGRAPHS + + { 'A', '-', 0x0100 }, + { 'a', '-', 0x0101 }, + { 'A', '(', 0x0102 }, + { 'a', '(', 0x0103 }, + { 'A', ';', 0x0104 }, + { 'a', ';', 0x0105 }, + { 'C', '\'', 0x0106 }, + { 'c', '\'', 0x0107 }, + { 'C', '>', 0x0108 }, + { 'c', '>', 0x0109 }, + { 'C', '.', 0x010a }, + { 'c', '.', 0x010b }, + { 'C', '<', 0x010c }, + { 'c', '<', 0x010d }, + { 'D', '<', 0x010e }, + { 'd', '<', 0x010f }, + { 'D', '/', 0x0110 }, + { 'd', '/', 0x0111 }, + { 'E', '-', 0x0112 }, + { 'e', '-', 0x0113 }, + { 'E', '(', 0x0114 }, + { 'e', '(', 0x0115 }, + { 'E', '.', 0x0116 }, + { 'e', '.', 0x0117 }, + { 'E', ';', 0x0118 }, + { 'e', ';', 0x0119 }, + { 'E', '<', 0x011a }, + { 'e', '<', 0x011b }, + { 'G', '>', 0x011c }, + { 'g', '>', 0x011d }, + { 'G', '(', 0x011e }, + { 'g', '(', 0x011f }, + { 'G', '.', 0x0120 }, + { 'g', '.', 0x0121 }, + { 'G', ',', 0x0122 }, + { 'g', ',', 0x0123 }, + { 'H', '>', 0x0124 }, + { 'h', '>', 0x0125 }, + { 'H', '/', 0x0126 }, + { 'h', '/', 0x0127 }, + { 'I', '?', 0x0128 }, + { 'i', '?', 0x0129 }, + { 'I', '-', 0x012a }, + { 'i', '-', 0x012b }, + { 'I', '(', 0x012c }, + { 'i', '(', 0x012d }, + { 'I', ';', 0x012e }, + { 'i', ';', 0x012f }, + { 'I', '.', 0x0130 }, + { 'i', '.', 0x0131 }, + { 'I', 'J', 0x0132 }, + { 'i', 'j', 0x0133 }, + { 'J', '>', 0x0134 }, + { 'j', '>', 0x0135 }, + { 'K', ',', 0x0136 }, + { 'k', ',', 0x0137 }, + { 'k', 'k', 0x0138 }, + { 'L', '\'', 0x0139 }, + { 'l', '\'', 0x013a }, + { 'L', ',', 0x013b }, + { 'l', ',', 0x013c }, + { 'L', '<', 0x013d }, + { 'l', '<', 0x013e }, + { 'L', '.', 0x013f }, + { 'l', '.', 0x0140 }, + { 'L', '/', 0x0141 }, + { 'l', '/', 0x0142 }, + { 'N', '\'', 0x0143 }, + { 'n', '\'', 0x0144 }, + { 'N', ',', 0x0145 }, + { 'n', ',', 0x0146 }, + { 'N', '<', 0x0147 }, + { 'n', '<', 0x0148 }, + { '\'', 'n', 0x0149 }, + { 'N', 'G', 0x014a }, + { 'n', 'g', 0x014b }, + { 'O', '-', 0x014c }, + { 'o', '-', 0x014d }, + { 'O', '(', 0x014e }, + { 'o', '(', 0x014f }, + { 'O', '"', 0x0150 }, + { 'o', '"', 0x0151 }, + { 'O', 'E', 0x0152 }, + { 'o', 'e', 0x0153 }, + { 'R', '\'', 0x0154 }, + { 'r', '\'', 0x0155 }, + { 'R', ',', 0x0156 }, + { 'r', ',', 0x0157 }, + { 'R', '<', 0x0158 }, + { 'r', '<', 0x0159 }, + { 'S', '\'', 0x015a }, + { 's', '\'', 0x015b }, + { 'S', '>', 0x015c }, + { 's', '>', 0x015d }, + { 'S', ',', 0x015e }, + { 's', ',', 0x015f }, + { 'S', '<', 0x0160 }, + { 's', '<', 0x0161 }, + { 'T', ',', 0x0162 }, + { 't', ',', 0x0163 }, + { 'T', '<', 0x0164 }, + { 't', '<', 0x0165 }, + { 'T', '/', 0x0166 }, + { 't', '/', 0x0167 }, + { 'U', '?', 0x0168 }, + { 'u', '?', 0x0169 }, + { 'U', '-', 0x016a }, + { 'u', '-', 0x016b }, + { 'U', '(', 0x016c }, + { 'u', '(', 0x016d }, + { 'U', '0', 0x016e }, + { 'u', '0', 0x016f }, + { 'U', '"', 0x0170 }, + { 'u', '"', 0x0171 }, + { 'U', ';', 0x0172 }, + { 'u', ';', 0x0173 }, + { 'W', '>', 0x0174 }, + { 'w', '>', 0x0175 }, + { 'Y', '>', 0x0176 }, + { 'y', '>', 0x0177 }, + { 'Y', ':', 0x0178 }, + { 'Z', '\'', 0x0179 }, + { 'z', '\'', 0x017a }, + { 'Z', '.', 0x017b }, + { 'z', '.', 0x017c }, + { 'Z', '<', 0x017d }, + { 'z', '<', 0x017e }, + { 'O', '9', 0x01a0 }, + { 'o', '9', 0x01a1 }, + { 'O', 'I', 0x01a2 }, + { 'o', 'i', 0x01a3 }, + { 'y', 'r', 0x01a6 }, + { 'U', '9', 0x01af }, + { 'u', '9', 0x01b0 }, + { 'Z', '/', 0x01b5 }, + { 'z', '/', 0x01b6 }, + { 'E', 'D', 0x01b7 }, + { 'A', '<', 0x01cd }, + { 'a', '<', 0x01ce }, + { 'I', '<', 0x01cf }, + { 'i', '<', 0x01d0 }, + { 'O', '<', 0x01d1 }, + { 'o', '<', 0x01d2 }, + { 'U', '<', 0x01d3 }, + { 'u', '<', 0x01d4 }, + { 'A', '1', 0x01de }, + { 'a', '1', 0x01df }, + { 'A', '7', 0x01e0 }, + { 'a', '7', 0x01e1 }, + { 'A', '3', 0x01e2 }, + { 'a', '3', 0x01e3 }, + { 'G', '/', 0x01e4 }, + { 'g', '/', 0x01e5 }, + { 'G', '<', 0x01e6 }, + { 'g', '<', 0x01e7 }, + { 'K', '<', 0x01e8 }, + { 'k', '<', 0x01e9 }, + { 'O', ';', 0x01ea }, + { 'o', ';', 0x01eb }, + { 'O', '1', 0x01ec }, + { 'o', '1', 0x01ed }, + { 'E', 'Z', 0x01ee }, + { 'e', 'z', 0x01ef }, + { 'j', '<', 0x01f0 }, + { 'G', '\'', 0x01f4 }, + { 'g', '\'', 0x01f5 }, + { ';', 'S', 0x02bf }, + { '\'', '<', 0x02c7 }, + { '\'', '(', 0x02d8 }, + { '\'', '.', 0x02d9 }, + { '\'', '0', 0x02da }, + { '\'', ';', 0x02db }, + { '\'', '"', 0x02dd }, + { 'A', '%', 0x0386 }, + { 'E', '%', 0x0388 }, + { 'Y', '%', 0x0389 }, + { 'I', '%', 0x038a }, + { 'O', '%', 0x038c }, + { 'U', '%', 0x038e }, + { 'W', '%', 0x038f }, + { 'i', '3', 0x0390 }, + { 'A', '*', 0x0391 }, + { 'B', '*', 0x0392 }, + { 'G', '*', 0x0393 }, + { 'D', '*', 0x0394 }, + { 'E', '*', 0x0395 }, + { 'Z', '*', 0x0396 }, + { 'Y', '*', 0x0397 }, + { 'H', '*', 0x0398 }, + { 'I', '*', 0x0399 }, + { 'K', '*', 0x039a }, + { 'L', '*', 0x039b }, + { 'M', '*', 0x039c }, + { 'N', '*', 0x039d }, + { 'C', '*', 0x039e }, + { 'O', '*', 0x039f }, + { 'P', '*', 0x03a0 }, + { 'R', '*', 0x03a1 }, + { 'S', '*', 0x03a3 }, + { 'T', '*', 0x03a4 }, + { 'U', '*', 0x03a5 }, + { 'F', '*', 0x03a6 }, + { 'X', '*', 0x03a7 }, + { 'Q', '*', 0x03a8 }, + { 'W', '*', 0x03a9 }, + { 'J', '*', 0x03aa }, + { 'V', '*', 0x03ab }, + { 'a', '%', 0x03ac }, + { 'e', '%', 0x03ad }, + { 'y', '%', 0x03ae }, + { 'i', '%', 0x03af }, + { 'u', '3', 0x03b0 }, + { 'a', '*', 0x03b1 }, + { 'b', '*', 0x03b2 }, + { 'g', '*', 0x03b3 }, + { 'd', '*', 0x03b4 }, + { 'e', '*', 0x03b5 }, + { 'z', '*', 0x03b6 }, + { 'y', '*', 0x03b7 }, + { 'h', '*', 0x03b8 }, + { 'i', '*', 0x03b9 }, + { 'k', '*', 0x03ba }, + { 'l', '*', 0x03bb }, + { 'm', '*', 0x03bc }, + { 'n', '*', 0x03bd }, + { 'c', '*', 0x03be }, + { 'o', '*', 0x03bf }, + { 'p', '*', 0x03c0 }, + { 'r', '*', 0x03c1 }, + { '*', 's', 0x03c2 }, + { 's', '*', 0x03c3 }, + { 't', '*', 0x03c4 }, + { 'u', '*', 0x03c5 }, + { 'f', '*', 0x03c6 }, + { 'x', '*', 0x03c7 }, + { 'q', '*', 0x03c8 }, + { 'w', '*', 0x03c9 }, + { 'j', '*', 0x03ca }, + { 'v', '*', 0x03cb }, + { 'o', '%', 0x03cc }, + { 'u', '%', 0x03cd }, + { 'w', '%', 0x03ce }, + { '\'', 'G', 0x03d8 }, + { ',', 'G', 0x03d9 }, + { 'T', '3', 0x03da }, + { 't', '3', 0x03db }, + { 'M', '3', 0x03dc }, + { 'm', '3', 0x03dd }, + { 'K', '3', 0x03de }, + { 'k', '3', 0x03df }, + { 'P', '3', 0x03e0 }, + { 'p', '3', 0x03e1 }, + { '\'', '%', 0x03f4 }, + { 'j', '3', 0x03f5 }, + { 'I', 'O', 0x0401 }, + { 'D', '%', 0x0402 }, + { 'G', '%', 0x0403 }, + { 'I', 'E', 0x0404 }, + { 'D', 'S', 0x0405 }, + { 'I', 'I', 0x0406 }, + { 'Y', 'I', 0x0407 }, + { 'J', '%', 0x0408 }, + { 'L', 'J', 0x0409 }, + { 'N', 'J', 0x040a }, + { 'T', 's', 0x040b }, + { 'K', 'J', 0x040c }, + { 'V', '%', 0x040e }, + { 'D', 'Z', 0x040f }, + { 'A', '=', 0x0410 }, + { 'B', '=', 0x0411 }, + { 'V', '=', 0x0412 }, + { 'G', '=', 0x0413 }, + { 'D', '=', 0x0414 }, + { 'E', '=', 0x0415 }, + { 'Z', '%', 0x0416 }, + { 'Z', '=', 0x0417 }, + { 'I', '=', 0x0418 }, + { 'J', '=', 0x0419 }, + { 'K', '=', 0x041a }, + { 'L', '=', 0x041b }, + { 'M', '=', 0x041c }, + { 'N', '=', 0x041d }, + { 'O', '=', 0x041e }, + { 'P', '=', 0x041f }, + { 'R', '=', 0x0420 }, + { 'S', '=', 0x0421 }, + { 'T', '=', 0x0422 }, + { 'U', '=', 0x0423 }, + { 'F', '=', 0x0424 }, + { 'H', '=', 0x0425 }, + { 'C', '=', 0x0426 }, + { 'C', '%', 0x0427 }, + { 'S', '%', 0x0428 }, + { 'S', 'c', 0x0429 }, + { '=', '"', 0x042a }, + { 'Y', '=', 0x042b }, + { '%', '"', 0x042c }, + { 'J', 'E', 0x042d }, + { 'J', 'U', 0x042e }, + { 'J', 'A', 0x042f }, + { 'a', '=', 0x0430 }, + { 'b', '=', 0x0431 }, + { 'v', '=', 0x0432 }, + { 'g', '=', 0x0433 }, + { 'd', '=', 0x0434 }, + { 'e', '=', 0x0435 }, + { 'z', '%', 0x0436 }, + { 'z', '=', 0x0437 }, + { 'i', '=', 0x0438 }, + { 'j', '=', 0x0439 }, + { 'k', '=', 0x043a }, + { 'l', '=', 0x043b }, + { 'm', '=', 0x043c }, + { 'n', '=', 0x043d }, + { 'o', '=', 0x043e }, + { 'p', '=', 0x043f }, + { 'r', '=', 0x0440 }, + { 's', '=', 0x0441 }, + { 't', '=', 0x0442 }, + { 'u', '=', 0x0443 }, + { 'f', '=', 0x0444 }, + { 'h', '=', 0x0445 }, + { 'c', '=', 0x0446 }, + { 'c', '%', 0x0447 }, + { 's', '%', 0x0448 }, + { 's', 'c', 0x0449 }, + { '=', '\'', 0x044a }, + { 'y', '=', 0x044b }, + { '%', '\'', 0x044c }, + { 'j', 'e', 0x044d }, + { 'j', 'u', 0x044e }, + { 'j', 'a', 0x044f }, + { 'i', 'o', 0x0451 }, + { 'd', '%', 0x0452 }, + { 'g', '%', 0x0453 }, + { 'i', 'e', 0x0454 }, + { 'd', 's', 0x0455 }, + { 'i', 'i', 0x0456 }, + { 'y', 'i', 0x0457 }, + { 'j', '%', 0x0458 }, + { 'l', 'j', 0x0459 }, + { 'n', 'j', 0x045a }, + { 't', 's', 0x045b }, + { 'k', 'j', 0x045c }, + { 'v', '%', 0x045e }, + { 'd', 'z', 0x045f }, + { 'Y', '3', 0x0462 }, + { 'y', '3', 0x0463 }, + { 'O', '3', 0x046a }, + { 'o', '3', 0x046b }, + { 'F', '3', 0x0472 }, + { 'f', '3', 0x0473 }, + { 'V', '3', 0x0474 }, + { 'v', '3', 0x0475 }, + { 'C', '3', 0x0480 }, + { 'c', '3', 0x0481 }, + { 'G', '3', 0x0490 }, + { 'g', '3', 0x0491 }, + { 'A', '+', 0x05d0 }, + { 'B', '+', 0x05d1 }, + { 'G', '+', 0x05d2 }, + { 'D', '+', 0x05d3 }, + { 'H', '+', 0x05d4 }, + { 'W', '+', 0x05d5 }, + { 'Z', '+', 0x05d6 }, + { 'X', '+', 0x05d7 }, + { 'T', 'j', 0x05d8 }, + { 'J', '+', 0x05d9 }, + { 'K', '%', 0x05da }, + { 'K', '+', 0x05db }, + { 'L', '+', 0x05dc }, + { 'M', '%', 0x05dd }, + { 'M', '+', 0x05de }, + { 'N', '%', 0x05df }, + { 'N', '+', 0x05e0 }, + { 'S', '+', 0x05e1 }, + { 'E', '+', 0x05e2 }, + { 'P', '%', 0x05e3 }, + { 'P', '+', 0x05e4 }, + { 'Z', 'j', 0x05e5 }, + { 'Z', 'J', 0x05e6 }, + { 'Q', '+', 0x05e7 }, + { 'R', '+', 0x05e8 }, + { 'S', 'h', 0x05e9 }, + { 'T', '+', 0x05ea }, + { ',', '+', 0x060c }, + { ';', '+', 0x061b }, + { '?', '+', 0x061f }, + { 'H', '\'', 0x0621 }, + { 'a', 'M', 0x0622 }, + { 'a', 'H', 0x0623 }, + { 'w', 'H', 0x0624 }, + { 'a', 'h', 0x0625 }, + { 'y', 'H', 0x0626 }, + { 'a', '+', 0x0627 }, + { 'b', '+', 0x0628 }, + { 't', 'm', 0x0629 }, + { 't', '+', 0x062a }, + { 't', 'k', 0x062b }, + { 'g', '+', 0x062c }, + { 'h', 'k', 0x062d }, + { 'x', '+', 0x062e }, + { 'd', '+', 0x062f }, + { 'd', 'k', 0x0630 }, + { 'r', '+', 0x0631 }, + { 'z', '+', 0x0632 }, + { 's', '+', 0x0633 }, + { 's', 'n', 0x0634 }, + { 'c', '+', 0x0635 }, + { 'd', 'd', 0x0636 }, + { 't', 'j', 0x0637 }, + { 'z', 'H', 0x0638 }, + { 'e', '+', 0x0639 }, + { 'i', '+', 0x063a }, + { '+', '+', 0x0640 }, + { 'f', '+', 0x0641 }, + { 'q', '+', 0x0642 }, + { 'k', '+', 0x0643 }, + { 'l', '+', 0x0644 }, + { 'm', '+', 0x0645 }, + { 'n', '+', 0x0646 }, + { 'h', '+', 0x0647 }, + { 'w', '+', 0x0648 }, + { 'j', '+', 0x0649 }, + { 'y', '+', 0x064a }, + { ':', '+', 0x064b }, + { '"', '+', 0x064c }, + { '=', '+', 0x064d }, + { '/', '+', 0x064e }, + { '\'', '+', 0x064f }, + { '1', '+', 0x0650 }, + { '3', '+', 0x0651 }, + { '0', '+', 0x0652 }, + { 'a', 'S', 0x0670 }, + { 'p', '+', 0x067e }, + { 'v', '+', 0x06a4 }, + { 'g', 'f', 0x06af }, + { '0', 'a', 0x06f0 }, + { '1', 'a', 0x06f1 }, + { '2', 'a', 0x06f2 }, + { '3', 'a', 0x06f3 }, + { '4', 'a', 0x06f4 }, + { '5', 'a', 0x06f5 }, + { '6', 'a', 0x06f6 }, + { '7', 'a', 0x06f7 }, + { '8', 'a', 0x06f8 }, + { '9', 'a', 0x06f9 }, + { 'B', '.', 0x1e02 }, + { 'b', '.', 0x1e03 }, + { 'B', '_', 0x1e06 }, + { 'b', '_', 0x1e07 }, + { 'D', '.', 0x1e0a }, + { 'd', '.', 0x1e0b }, + { 'D', '_', 0x1e0e }, + { 'd', '_', 0x1e0f }, + { 'D', ',', 0x1e10 }, + { 'd', ',', 0x1e11 }, + { 'F', '.', 0x1e1e }, + { 'f', '.', 0x1e1f }, + { 'G', '-', 0x1e20 }, + { 'g', '-', 0x1e21 }, + { 'H', '.', 0x1e22 }, + { 'h', '.', 0x1e23 }, + { 'H', ':', 0x1e26 }, + { 'h', ':', 0x1e27 }, + { 'H', ',', 0x1e28 }, + { 'h', ',', 0x1e29 }, + { 'K', '\'', 0x1e30 }, + { 'k', '\'', 0x1e31 }, + { 'K', '_', 0x1e34 }, + { 'k', '_', 0x1e35 }, + { 'L', '_', 0x1e3a }, + { 'l', '_', 0x1e3b }, + { 'M', '\'', 0x1e3e }, + { 'm', '\'', 0x1e3f }, + { 'M', '.', 0x1e40 }, + { 'm', '.', 0x1e41 }, + { 'N', '.', 0x1e44 }, + { 'n', '.', 0x1e45 }, + { 'N', '_', 0x1e48 }, + { 'n', '_', 0x1e49 }, + { 'P', '\'', 0x1e54 }, + { 'p', '\'', 0x1e55 }, + { 'P', '.', 0x1e56 }, + { 'p', '.', 0x1e57 }, + { 'R', '.', 0x1e58 }, + { 'r', '.', 0x1e59 }, + { 'R', '_', 0x1e5e }, + { 'r', '_', 0x1e5f }, + { 'S', '.', 0x1e60 }, + { 's', '.', 0x1e61 }, + { 'T', '.', 0x1e6a }, + { 't', '.', 0x1e6b }, + { 'T', '_', 0x1e6e }, + { 't', '_', 0x1e6f }, + { 'V', '?', 0x1e7c }, + { 'v', '?', 0x1e7d }, + { 'W', '!', 0x1e80 }, + { 'w', '!', 0x1e81 }, + { 'W', '\'', 0x1e82 }, + { 'w', '\'', 0x1e83 }, + { 'W', ':', 0x1e84 }, + { 'w', ':', 0x1e85 }, + { 'W', '.', 0x1e86 }, + { 'w', '.', 0x1e87 }, + { 'X', '.', 0x1e8a }, + { 'x', '.', 0x1e8b }, + { 'X', ':', 0x1e8c }, + { 'x', ':', 0x1e8d }, + { 'Y', '.', 0x1e8e }, + { 'y', '.', 0x1e8f }, + { 'Z', '>', 0x1e90 }, + { 'z', '>', 0x1e91 }, + { 'Z', '_', 0x1e94 }, + { 'z', '_', 0x1e95 }, + { 'h', '_', 0x1e96 }, + { 't', ':', 0x1e97 }, + { 'w', '0', 0x1e98 }, + { 'y', '0', 0x1e99 }, + { 'A', '2', 0x1ea2 }, + { 'a', '2', 0x1ea3 }, + { 'E', '2', 0x1eba }, + { 'e', '2', 0x1ebb }, + { 'E', '?', 0x1ebc }, + { 'e', '?', 0x1ebd }, + { 'I', '2', 0x1ec8 }, + { 'i', '2', 0x1ec9 }, + { 'O', '2', 0x1ece }, + { 'o', '2', 0x1ecf }, + { 'U', '2', 0x1ee6 }, + { 'u', '2', 0x1ee7 }, + { 'Y', '!', 0x1ef2 }, + { 'y', '!', 0x1ef3 }, + { 'Y', '2', 0x1ef6 }, + { 'y', '2', 0x1ef7 }, + { 'Y', '?', 0x1ef8 }, + { 'y', '?', 0x1ef9 }, + { ';', '\'', 0x1f00 }, + { ',', '\'', 0x1f01 }, + { ';', '!', 0x1f02 }, + { ',', '!', 0x1f03 }, + { '?', ';', 0x1f04 }, + { '?', ',', 0x1f05 }, + { '!', ':', 0x1f06 }, + { '?', ':', 0x1f07 }, + { '1', 'N', 0x2002 }, + { '1', 'M', 0x2003 }, + { '3', 'M', 0x2004 }, + { '4', 'M', 0x2005 }, + { '6', 'M', 0x2006 }, + { '1', 'T', 0x2009 }, + { '1', 'H', 0x200a }, + { '-', '1', 0x2010 }, + { '-', 'N', 0x2013 }, + { '-', 'M', 0x2014 }, + { '-', '3', 0x2015 }, + { '!', '2', 0x2016 }, + { '=', '2', 0x2017 }, + { '\'', '6', 0x2018 }, + { '\'', '9', 0x2019 }, + { '.', '9', 0x201a }, + { '9', '\'', 0x201b }, + { '"', '6', 0x201c }, + { '"', '9', 0x201d }, + { ':', '9', 0x201e }, + { '9', '"', 0x201f }, + { '/', '-', 0x2020 }, + { '/', '=', 0x2021 }, + { '.', '.', 0x2025 }, + { '%', '0', 0x2030 }, + { '1', '\'', 0x2032 }, + { '2', '\'', 0x2033 }, + { '3', '\'', 0x2034 }, + { '1', '"', 0x2035 }, + { '2', '"', 0x2036 }, + { '3', '"', 0x2037 }, + { 'C', 'a', 0x2038 }, + { '<', '1', 0x2039 }, + { '>', '1', 0x203a }, + { ':', 'X', 0x203b }, + { '\'', '-', 0x203e }, + { '/', 'f', 0x2044 }, + { '0', 'S', 0x2070 }, + { '4', 'S', 0x2074 }, + { '5', 'S', 0x2075 }, + { '6', 'S', 0x2076 }, + { '7', 'S', 0x2077 }, + { '8', 'S', 0x2078 }, + { '9', 'S', 0x2079 }, + { '+', 'S', 0x207a }, + { '-', 'S', 0x207b }, + { '=', 'S', 0x207c }, + { '(', 'S', 0x207d }, + { ')', 'S', 0x207e }, + { 'n', 'S', 0x207f }, + { '0', 's', 0x2080 }, + { '1', 's', 0x2081 }, + { '2', 's', 0x2082 }, + { '3', 's', 0x2083 }, + { '4', 's', 0x2084 }, + { '5', 's', 0x2085 }, + { '6', 's', 0x2086 }, + { '7', 's', 0x2087 }, + { '8', 's', 0x2088 }, + { '9', 's', 0x2089 }, + { '+', 's', 0x208a }, + { '-', 's', 0x208b }, + { '=', 's', 0x208c }, + { '(', 's', 0x208d }, + { ')', 's', 0x208e }, + { 'L', 'i', 0x20a4 }, + { 'P', 't', 0x20a7 }, + { 'W', '=', 0x20a9 }, + { '=', 'e', 0x20ac }, // euro + { 'E', 'u', 0x20ac }, // euro + { 'o', 'C', 0x2103 }, + { 'c', 'o', 0x2105 }, + { 'o', 'F', 0x2109 }, + { 'N', '0', 0x2116 }, + { 'P', 'O', 0x2117 }, + { 'R', 'x', 0x211e }, + { 'S', 'M', 0x2120 }, + { 'T', 'M', 0x2122 }, + { 'O', 'm', 0x2126 }, + { 'A', 'O', 0x212b }, + { '1', '3', 0x2153 }, + { '2', '3', 0x2154 }, + { '1', '5', 0x2155 }, + { '2', '5', 0x2156 }, + { '3', '5', 0x2157 }, + { '4', '5', 0x2158 }, + { '1', '6', 0x2159 }, + { '5', '6', 0x215a }, + { '1', '8', 0x215b }, + { '3', '8', 0x215c }, + { '5', '8', 0x215d }, + { '7', '8', 0x215e }, + { '1', 'R', 0x2160 }, + { '2', 'R', 0x2161 }, + { '3', 'R', 0x2162 }, + { '4', 'R', 0x2163 }, + { '5', 'R', 0x2164 }, + { '6', 'R', 0x2165 }, + { '7', 'R', 0x2166 }, + { '8', 'R', 0x2167 }, + { '9', 'R', 0x2168 }, + { 'a', 'R', 0x2169 }, + { 'b', 'R', 0x216a }, + { 'c', 'R', 0x216b }, + { '1', 'r', 0x2170 }, + { '2', 'r', 0x2171 }, + { '3', 'r', 0x2172 }, + { '4', 'r', 0x2173 }, + { '5', 'r', 0x2174 }, + { '6', 'r', 0x2175 }, + { '7', 'r', 0x2176 }, + { '8', 'r', 0x2177 }, + { '9', 'r', 0x2178 }, + { 'a', 'r', 0x2179 }, + { 'b', 'r', 0x217a }, + { 'c', 'r', 0x217b }, + { '<', '-', 0x2190 }, + { '-', '!', 0x2191 }, + { '-', '>', 0x2192 }, + { '-', 'v', 0x2193 }, + { '<', '>', 0x2194 }, + { 'U', 'D', 0x2195 }, + { '<', '=', 0x21d0 }, + { '=', '>', 0x21d2 }, + { '=', '=', 0x21d4 }, + { 'F', 'A', 0x2200 }, + { 'd', 'P', 0x2202 }, + { 'T', 'E', 0x2203 }, + { '/', '0', 0x2205 }, + { 'D', 'E', 0x2206 }, + { 'N', 'B', 0x2207 }, + { '(', '-', 0x2208 }, + { '-', ')', 0x220b }, + { '*', 'P', 0x220f }, + { '+', 'Z', 0x2211 }, + { '-', '2', 0x2212 }, + { '-', '+', 0x2213 }, + { '*', '-', 0x2217 }, + { 'O', 'b', 0x2218 }, + { 'S', 'b', 0x2219 }, + { 'R', 'T', 0x221a }, + { '0', '(', 0x221d }, + { '0', '0', 0x221e }, + { '-', 'L', 0x221f }, + { '-', 'V', 0x2220 }, + { 'P', 'P', 0x2225 }, + { 'A', 'N', 0x2227 }, + { 'O', 'R', 0x2228 }, + { '(', 'U', 0x2229 }, + { ')', 'U', 0x222a }, + { 'I', 'n', 0x222b }, + { 'D', 'I', 0x222c }, + { 'I', 'o', 0x222e }, + { '.', ':', 0x2234 }, + { ':', '.', 0x2235 }, + { ':', 'R', 0x2236 }, + { ':', ':', 0x2237 }, + { '?', '1', 0x223c }, + { 'C', 'G', 0x223e }, + { '?', '-', 0x2243 }, + { '?', '=', 0x2245 }, + { '?', '2', 0x2248 }, + { '=', '?', 0x224c }, + { 'H', 'I', 0x2253 }, + { '!', '=', 0x2260 }, + { '=', '3', 0x2261 }, + { '=', '<', 0x2264 }, + { '>', '=', 0x2265 }, + { '<', '*', 0x226a }, + { '*', '>', 0x226b }, + { '!', '<', 0x226e }, + { '!', '>', 0x226f }, + { '(', 'C', 0x2282 }, + { ')', 'C', 0x2283 }, + { '(', '_', 0x2286 }, + { ')', '_', 0x2287 }, + { '0', '.', 0x2299 }, + { '0', '2', 0x229a }, + { '-', 'T', 0x22a5 }, + { '.', 'P', 0x22c5 }, + { ':', '3', 0x22ee }, + { '.', '3', 0x22ef }, + { 'E', 'h', 0x2302 }, + { '<', '7', 0x2308 }, + { '>', '7', 0x2309 }, + { '7', '<', 0x230a }, + { '7', '>', 0x230b }, + { 'N', 'I', 0x2310 }, + { '(', 'A', 0x2312 }, + { 'T', 'R', 0x2315 }, + { 'I', 'u', 0x2320 }, + { 'I', 'l', 0x2321 }, + { '<', '/', 0x2329 }, + { '/', '>', 0x232a }, + { 'V', 's', 0x2423 }, + { '1', 'h', 0x2440 }, + { '3', 'h', 0x2441 }, + { '2', 'h', 0x2442 }, + { '4', 'h', 0x2443 }, + { '1', 'j', 0x2446 }, + { '2', 'j', 0x2447 }, + { '3', 'j', 0x2448 }, + { '4', 'j', 0x2449 }, + { '1', '.', 0x2488 }, + { '2', '.', 0x2489 }, + { '3', '.', 0x248a }, + { '4', '.', 0x248b }, + { '5', '.', 0x248c }, + { '6', '.', 0x248d }, + { '7', '.', 0x248e }, + { '8', '.', 0x248f }, + { '9', '.', 0x2490 }, + { 'h', 'h', 0x2500 }, + { 'H', 'H', 0x2501 }, + { 'v', 'v', 0x2502 }, + { 'V', 'V', 0x2503 }, + { '3', '-', 0x2504 }, + { '3', '_', 0x2505 }, + { '3', '!', 0x2506 }, + { '3', '/', 0x2507 }, + { '4', '-', 0x2508 }, + { '4', '_', 0x2509 }, + { '4', '!', 0x250a }, + { '4', '/', 0x250b }, + { 'd', 'r', 0x250c }, + { 'd', 'R', 0x250d }, + { 'D', 'r', 0x250e }, + { 'D', 'R', 0x250f }, + { 'd', 'l', 0x2510 }, + { 'd', 'L', 0x2511 }, + { 'D', 'l', 0x2512 }, + { 'L', 'D', 0x2513 }, + { 'u', 'r', 0x2514 }, + { 'u', 'R', 0x2515 }, + { 'U', 'r', 0x2516 }, + { 'U', 'R', 0x2517 }, + { 'u', 'l', 0x2518 }, + { 'u', 'L', 0x2519 }, + { 'U', 'l', 0x251a }, + { 'U', 'L', 0x251b }, + { 'v', 'r', 0x251c }, + { 'v', 'R', 0x251d }, + { 'V', 'r', 0x2520 }, + { 'V', 'R', 0x2523 }, + { 'v', 'l', 0x2524 }, + { 'v', 'L', 0x2525 }, + { 'V', 'l', 0x2528 }, + { 'V', 'L', 0x252b }, + { 'd', 'h', 0x252c }, + { 'd', 'H', 0x252f }, + { 'D', 'h', 0x2530 }, + { 'D', 'H', 0x2533 }, + { 'u', 'h', 0x2534 }, + { 'u', 'H', 0x2537 }, + { 'U', 'h', 0x2538 }, + { 'U', 'H', 0x253b }, + { 'v', 'h', 0x253c }, + { 'v', 'H', 0x253f }, + { 'V', 'h', 0x2542 }, + { 'V', 'H', 0x254b }, + { 'F', 'D', 0x2571 }, + { 'B', 'D', 0x2572 }, + { 'T', 'B', 0x2580 }, + { 'L', 'B', 0x2584 }, + { 'F', 'B', 0x2588 }, + { 'l', 'B', 0x258c }, + { 'R', 'B', 0x2590 }, + { '.', 'S', 0x2591 }, + { ':', 'S', 0x2592 }, + { '?', 'S', 0x2593 }, + { 'f', 'S', 0x25a0 }, + { 'O', 'S', 0x25a1 }, + { 'R', 'O', 0x25a2 }, + { 'R', 'r', 0x25a3 }, + { 'R', 'F', 0x25a4 }, + { 'R', 'Y', 0x25a5 }, + { 'R', 'H', 0x25a6 }, + { 'R', 'Z', 0x25a7 }, + { 'R', 'K', 0x25a8 }, + { 'R', 'X', 0x25a9 }, + { 's', 'B', 0x25aa }, + { 'S', 'R', 0x25ac }, + { 'O', 'r', 0x25ad }, + { 'U', 'T', 0x25b2 }, + { 'u', 'T', 0x25b3 }, + { 'P', 'R', 0x25b6 }, + { 'T', 'r', 0x25b7 }, + { 'D', 't', 0x25bc }, + { 'd', 'T', 0x25bd }, + { 'P', 'L', 0x25c0 }, + { 'T', 'l', 0x25c1 }, + { 'D', 'b', 0x25c6 }, + { 'D', 'w', 0x25c7 }, + { 'L', 'Z', 0x25ca }, + { '0', 'm', 0x25cb }, + { '0', 'o', 0x25ce }, + { '0', 'M', 0x25cf }, + { '0', 'L', 0x25d0 }, + { '0', 'R', 0x25d1 }, + { 'S', 'n', 0x25d8 }, + { 'I', 'c', 0x25d9 }, + { 'F', 'd', 0x25e2 }, + { 'B', 'd', 0x25e3 }, + { '*', '2', 0x2605 }, + { '*', '1', 0x2606 }, + { '<', 'H', 0x261c }, + { '>', 'H', 0x261e }, + { '0', 'u', 0x263a }, + { '0', 'U', 0x263b }, + { 'S', 'U', 0x263c }, + { 'F', 'm', 0x2640 }, + { 'M', 'l', 0x2642 }, + { 'c', 'S', 0x2660 }, + { 'c', 'H', 0x2661 }, + { 'c', 'D', 0x2662 }, + { 'c', 'C', 0x2663 }, + { 'M', 'd', 0x2669 }, + { 'M', '8', 0x266a }, + { 'M', '2', 0x266b }, + { 'M', 'b', 0x266d }, + { 'M', 'x', 0x266e }, + { 'M', 'X', 0x266f }, + { 'O', 'K', 0x2713 }, + { 'X', 'X', 0x2717 }, + { '-', 'X', 0x2720 }, + { 'I', 'S', 0x3000 }, + { ',', '_', 0x3001 }, + { '.', '_', 0x3002 }, + { '+', '"', 0x3003 }, + { '+', '_', 0x3004 }, + { '*', '_', 0x3005 }, + { ';', '_', 0x3006 }, + { '0', '_', 0x3007 }, + { '<', '+', 0x300a }, + { '>', '+', 0x300b }, + { '<', '\'', 0x300c }, + { '>', '\'', 0x300d }, + { '<', '"', 0x300e }, + { '>', '"', 0x300f }, + { '(', '"', 0x3010 }, + { ')', '"', 0x3011 }, + { '=', 'T', 0x3012 }, + { '=', '_', 0x3013 }, + { '(', '\'', 0x3014 }, + { ')', '\'', 0x3015 }, + { '(', 'I', 0x3016 }, + { ')', 'I', 0x3017 }, + { '-', '?', 0x301c }, + { 'A', '5', 0x3041 }, + { 'a', '5', 0x3042 }, + { 'I', '5', 0x3043 }, + { 'i', '5', 0x3044 }, + { 'U', '5', 0x3045 }, + { 'u', '5', 0x3046 }, + { 'E', '5', 0x3047 }, + { 'e', '5', 0x3048 }, + { 'O', '5', 0x3049 }, + { 'o', '5', 0x304a }, + { 'k', 'a', 0x304b }, + { 'g', 'a', 0x304c }, + { 'k', 'i', 0x304d }, + { 'g', 'i', 0x304e }, + { 'k', 'u', 0x304f }, + { 'g', 'u', 0x3050 }, + { 'k', 'e', 0x3051 }, + { 'g', 'e', 0x3052 }, + { 'k', 'o', 0x3053 }, + { 'g', 'o', 0x3054 }, + { 's', 'a', 0x3055 }, + { 'z', 'a', 0x3056 }, + { 's', 'i', 0x3057 }, + { 'z', 'i', 0x3058 }, + { 's', 'u', 0x3059 }, + { 'z', 'u', 0x305a }, + { 's', 'e', 0x305b }, + { 'z', 'e', 0x305c }, + { 's', 'o', 0x305d }, + { 'z', 'o', 0x305e }, + { 't', 'a', 0x305f }, + { 'd', 'a', 0x3060 }, + { 't', 'i', 0x3061 }, + { 'd', 'i', 0x3062 }, + { 't', 'U', 0x3063 }, + { 't', 'u', 0x3064 }, + { 'd', 'u', 0x3065 }, + { 't', 'e', 0x3066 }, + { 'd', 'e', 0x3067 }, + { 't', 'o', 0x3068 }, + { 'd', 'o', 0x3069 }, + { 'n', 'a', 0x306a }, + { 'n', 'i', 0x306b }, + { 'n', 'u', 0x306c }, + { 'n', 'e', 0x306d }, + { 'n', 'o', 0x306e }, + { 'h', 'a', 0x306f }, + { 'b', 'a', 0x3070 }, + { 'p', 'a', 0x3071 }, + { 'h', 'i', 0x3072 }, + { 'b', 'i', 0x3073 }, + { 'p', 'i', 0x3074 }, + { 'h', 'u', 0x3075 }, + { 'b', 'u', 0x3076 }, + { 'p', 'u', 0x3077 }, + { 'h', 'e', 0x3078 }, + { 'b', 'e', 0x3079 }, + { 'p', 'e', 0x307a }, + { 'h', 'o', 0x307b }, + { 'b', 'o', 0x307c }, + { 'p', 'o', 0x307d }, + { 'm', 'a', 0x307e }, + { 'm', 'i', 0x307f }, + { 'm', 'u', 0x3080 }, + { 'm', 'e', 0x3081 }, + { 'm', 'o', 0x3082 }, + { 'y', 'A', 0x3083 }, + { 'y', 'a', 0x3084 }, + { 'y', 'U', 0x3085 }, + { 'y', 'u', 0x3086 }, + { 'y', 'O', 0x3087 }, + { 'y', 'o', 0x3088 }, + { 'r', 'a', 0x3089 }, + { 'r', 'i', 0x308a }, + { 'r', 'u', 0x308b }, + { 'r', 'e', 0x308c }, + { 'r', 'o', 0x308d }, + { 'w', 'A', 0x308e }, + { 'w', 'a', 0x308f }, + { 'w', 'i', 0x3090 }, + { 'w', 'e', 0x3091 }, + { 'w', 'o', 0x3092 }, + { 'n', '5', 0x3093 }, + { 'v', 'u', 0x3094 }, + { '"', '5', 0x309b }, + { '0', '5', 0x309c }, + { '*', '5', 0x309d }, + { '+', '5', 0x309e }, + { 'a', '6', 0x30a1 }, + { 'A', '6', 0x30a2 }, + { 'i', '6', 0x30a3 }, + { 'I', '6', 0x30a4 }, + { 'u', '6', 0x30a5 }, + { 'U', '6', 0x30a6 }, + { 'e', '6', 0x30a7 }, + { 'E', '6', 0x30a8 }, + { 'o', '6', 0x30a9 }, + { 'O', '6', 0x30aa }, + { 'K', 'a', 0x30ab }, + { 'G', 'a', 0x30ac }, + { 'K', 'i', 0x30ad }, + { 'G', 'i', 0x30ae }, + { 'K', 'u', 0x30af }, + { 'G', 'u', 0x30b0 }, + { 'K', 'e', 0x30b1 }, + { 'G', 'e', 0x30b2 }, + { 'K', 'o', 0x30b3 }, + { 'G', 'o', 0x30b4 }, + { 'S', 'a', 0x30b5 }, + { 'Z', 'a', 0x30b6 }, + { 'S', 'i', 0x30b7 }, + { 'Z', 'i', 0x30b8 }, + { 'S', 'u', 0x30b9 }, + { 'Z', 'u', 0x30ba }, + { 'S', 'e', 0x30bb }, + { 'Z', 'e', 0x30bc }, + { 'S', 'o', 0x30bd }, + { 'Z', 'o', 0x30be }, + { 'T', 'a', 0x30bf }, + { 'D', 'a', 0x30c0 }, + { 'T', 'i', 0x30c1 }, + { 'D', 'i', 0x30c2 }, + { 'T', 'U', 0x30c3 }, + { 'T', 'u', 0x30c4 }, + { 'D', 'u', 0x30c5 }, + { 'T', 'e', 0x30c6 }, + { 'D', 'e', 0x30c7 }, + { 'T', 'o', 0x30c8 }, + { 'D', 'o', 0x30c9 }, + { 'N', 'a', 0x30ca }, + { 'N', 'i', 0x30cb }, + { 'N', 'u', 0x30cc }, + { 'N', 'e', 0x30cd }, + { 'N', 'o', 0x30ce }, + { 'H', 'a', 0x30cf }, + { 'B', 'a', 0x30d0 }, + { 'P', 'a', 0x30d1 }, + { 'H', 'i', 0x30d2 }, + { 'B', 'i', 0x30d3 }, + { 'P', 'i', 0x30d4 }, + { 'H', 'u', 0x30d5 }, + { 'B', 'u', 0x30d6 }, + { 'P', 'u', 0x30d7 }, + { 'H', 'e', 0x30d8 }, + { 'B', 'e', 0x30d9 }, + { 'P', 'e', 0x30da }, + { 'H', 'o', 0x30db }, + { 'B', 'o', 0x30dc }, + { 'P', 'o', 0x30dd }, + { 'M', 'a', 0x30de }, + { 'M', 'i', 0x30df }, + { 'M', 'u', 0x30e0 }, + { 'M', 'e', 0x30e1 }, + { 'M', 'o', 0x30e2 }, + { 'Y', 'A', 0x30e3 }, + { 'Y', 'a', 0x30e4 }, + { 'Y', 'U', 0x30e5 }, + { 'Y', 'u', 0x30e6 }, + { 'Y', 'O', 0x30e7 }, + { 'Y', 'o', 0x30e8 }, + { 'R', 'a', 0x30e9 }, + { 'R', 'i', 0x30ea }, + { 'R', 'u', 0x30eb }, + { 'R', 'e', 0x30ec }, + { 'R', 'o', 0x30ed }, + { 'W', 'A', 0x30ee }, + { 'W', 'a', 0x30ef }, + { 'W', 'i', 0x30f0 }, + { 'W', 'e', 0x30f1 }, + { 'W', 'o', 0x30f2 }, + { 'N', '6', 0x30f3 }, + { 'V', 'u', 0x30f4 }, + { 'K', 'A', 0x30f5 }, + { 'K', 'E', 0x30f6 }, + { 'V', 'a', 0x30f7 }, + { 'V', 'i', 0x30f8 }, + { 'V', 'e', 0x30f9 }, + { 'V', 'o', 0x30fa }, + { '.', '6', 0x30fb }, + { '-', '6', 0x30fc }, + { '*', '6', 0x30fd }, + { '+', '6', 0x30fe }, + { 'b', '4', 0x3105 }, + { 'p', '4', 0x3106 }, + { 'm', '4', 0x3107 }, + { 'f', '4', 0x3108 }, + { 'd', '4', 0x3109 }, + { 't', '4', 0x310a }, + { 'n', '4', 0x310b }, + { 'l', '4', 0x310c }, + { 'g', '4', 0x310d }, + { 'k', '4', 0x310e }, + { 'h', '4', 0x310f }, + { 'j', '4', 0x3110 }, + { 'q', '4', 0x3111 }, + { 'x', '4', 0x3112 }, + { 'z', 'h', 0x3113 }, + { 'c', 'h', 0x3114 }, + { 's', 'h', 0x3115 }, + { 'r', '4', 0x3116 }, + { 'z', '4', 0x3117 }, + { 'c', '4', 0x3118 }, + { 's', '4', 0x3119 }, + { 'a', '4', 0x311a }, + { 'o', '4', 0x311b }, + { 'e', '4', 0x311c }, + { 'a', 'i', 0x311e }, + { 'e', 'i', 0x311f }, + { 'a', 'u', 0x3120 }, + { 'o', 'u', 0x3121 }, + { 'a', 'n', 0x3122 }, + { 'e', 'n', 0x3123 }, + { 'a', 'N', 0x3124 }, + { 'e', 'N', 0x3125 }, + { 'e', 'r', 0x3126 }, + { 'i', '4', 0x3127 }, + { 'u', '4', 0x3128 }, + { 'i', 'u', 0x3129 }, + { 'v', '4', 0x312a }, + { 'n', 'G', 0x312b }, + { 'g', 'n', 0x312c }, + { '1', 'c', 0x3220 }, + { '2', 'c', 0x3221 }, + { '3', 'c', 0x3222 }, + { '4', 'c', 0x3223 }, + { '5', 'c', 0x3224 }, + { '6', 'c', 0x3225 }, + { '7', 'c', 0x3226 }, + { '8', 'c', 0x3227 }, + { '9', 'c', 0x3228 }, + + // code points 0xe000 - 0xefff excluded, they have no assigned + // characters, only used in proposals. + { 'f', 'f', 0xfb00 }, + { 'f', 'i', 0xfb01 }, + { 'f', 'l', 0xfb02 }, + { 'f', 't', 0xfb05 }, + { 's', 't', 0xfb06 }, + + // Vim 5.x compatible digraphs that don't conflict with the above + { '~', '!', 161 }, // ¡ + { 'c', '|', 162 }, // ¢ + { '$', '$', 163 }, // £ + { 'o', 'x', 164 }, // ¤ - currency symbol in ISO 8859-1 + { 'Y', '-', 165 }, // ¥ + { '|', '|', 166 }, // ¦ + { 'c', 'O', 169 }, // © + { '-', ',', 172 }, // ¬ + { '-', '=', 175 }, // ¯ + { '~', 'o', 176 }, // ° + { '2', '2', 178 }, // ² + { '3', '3', 179 }, // ³ + { 'p', 'p', 182 }, // ¶ + { '~', '.', 183 }, // · + { '1', '1', 185 }, // ¹ + { '~', '?', 191 }, // ¿ + { 'A', '`', 192 }, // À + { 'A', '^', 194 }, // Â + { 'A', '~', 195 }, // Ã + { 'A', '"', 196 }, // Ä + { 'A', '@', 197 }, // Å + { 'E', '`', 200 }, // È + { 'E', '^', 202 }, // Ê + { 'E', '"', 203 }, // Ë + { 'I', '`', 204 }, // Ì + { 'I', '^', 206 }, // Î + { 'I', '"', 207 }, // Ï + { 'N', '~', 209 }, // Ñ + { 'O', '`', 210 }, // Ò + { 'O', '^', 212 }, // Ô + { 'O', '~', 213 }, // Õ + { '/', '\\', 215 }, // × - multiplication symbol in ISO 8859-1 + { 'U', '`', 217 }, // Ù + { 'U', '^', 219 }, // Û + { 'I', 'p', 222 }, // Þ + { 'a', '`', 224 }, // à + { 'a', '^', 226 }, // â + { 'a', '~', 227 }, // ã + { 'a', '"', 228 }, // ä + { 'a', '@', 229 }, // å + { 'e', '`', 232 }, // è + { 'e', '^', 234 }, // ê + { 'e', '"', 235 }, // ë + { 'i', '`', 236 }, // ì + { 'i', '^', 238 }, // î + { 'n', '~', 241 }, // ñ + { 'o', '`', 242 }, // ò + { 'o', '^', 244 }, // ô + { 'o', '~', 245 }, // õ + { 'u', '`', 249 }, // ù + { 'u', '^', 251 }, // û + { 'y', '"', 255 }, // x XX + + { NUL, NUL, NUL } }; -# endif /* OLD_DIGRAPHS */ +# endif // OLD_DIGRAPHS -# endif /* !HPUX_DIGRAPHS */ +#endif // !HPUX_DIGRAPHS -/* - * handle digraphs after typing a character - */ +/// handle digraphs after typing a character +/// +/// @param c +/// +/// @return The digraph. int do_digraph(int c) { - static int backspaced; /* character before K_BS */ - static int lastchar; /* last typed character */ + static int backspaced; // character before K_BS + static int lastchar; // last typed character - if (c == -1) { /* init values */ + if (c == -1) { // init values backspaced = -1; } else if (p_dg) { - if (backspaced >= 0) + if (backspaced >= 0) { c = getdigraph(backspaced, c, FALSE); + } backspaced = -1; - if ((c == K_BS || c == Ctrl_H) && lastchar >= 0) + + if (((c == K_BS) || (c == Ctrl_H)) && (lastchar >= 0)) { backspaced = lastchar; + } } lastchar = c; return c; } -/* - * Get a digraph. Used after typing CTRL-K on the command line or in normal - * mode. - * Returns composed character, or NUL when ESC was used. - */ -int -get_digraph ( - int cmdline /* TRUE when called from the cmdline */ -) +/// Get a digraph. Used after typing CTRL-K on the command line or in normal +/// mode. +/// +/// @param cmdline TRUE when called from the cmdline +/// +/// @returns composed character, or NUL when ESC was used. +int get_digraph(int cmdline) { - int c, cc; - - ++no_mapping; - ++allow_keys; - c = plain_vgetc(); - --no_mapping; - --allow_keys; - if (c != ESC) { /* ESC cancels CTRL-K */ - if (IS_SPECIAL(c)) /* insert special key code */ + int cc; + no_mapping++; + allow_keys++; + int c = plain_vgetc(); + no_mapping--; + allow_keys--; + + if (c != ESC) { + // ESC cancels CTRL-K + if (IS_SPECIAL(c)) { + // insert special key code return c; + } + if (cmdline) { - if (char2cells(c) == 1 - && cmdline_star == 0 - ) + if ((char2cells(c) == 1) && (cmdline_star == 0)) { putcmdline(c, TRUE); - } else + } + } else { add_to_showcmd(c); - ++no_mapping; - ++allow_keys; + } + no_mapping++; + allow_keys++; cc = plain_vgetc(); - --no_mapping; - --allow_keys; - if (cc != ESC) /* ESC cancels CTRL-K */ + no_mapping--; + allow_keys--; + + if (cc != ESC) { + // ESC cancels CTRL-K return getdigraph(c, cc, TRUE); + } } return NUL; } -/* - * Lookup the pair "char1", "char2" in the digraph tables. - * If no match, return "char2". - * If "meta_char" is TRUE and "char1" is a space, return "char2" | 0x80. - */ +/// Lookup the pair "char1", "char2" in the digraph tables. +/// +/// @param char1 +/// @param char2 +/// @param meta_char +/// +/// @return If no match, return "char2". If "meta_char" is TRUE and "char1" +// is a space, return "char2" | 0x80. static int getexactdigraph(int char1, int char2, int meta_char) { - int i; int retval = 0; - digr_T *dp; - if (IS_SPECIAL(char1) || IS_SPECIAL(char2)) + if (IS_SPECIAL(char1) || IS_SPECIAL(char2)) { return char2; + } - /* - * Search user digraphs first. - */ - dp = (digr_T *)user_digraphs.ga_data; + // Search user digraphs first. + digr_T *dp = (digr_T *)user_digraphs.ga_data; + int i; for (i = 0; i < user_digraphs.ga_len; ++i) { - if ((int)dp->char1 == char1 && (int)dp->char2 == char2) { + if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { retval = dp->result; break; } ++dp; } - /* - * Search default digraphs. - */ + // Search default digraphs. if (retval == 0) { dp = digraphdefault; + for (i = 0; dp->char1 != 0; ++i) { - if ((int)dp->char1 == char1 && (int)dp->char2 == char2) { + if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) { retval = dp->result; break; } ++dp; } } -# ifdef USE_UNICODE_DIGRAPHS - if (retval != 0 && !enc_utf8) { +#ifdef USE_UNICODE_DIGRAPHS + + if ((retval != 0) && !enc_utf8) { char_u buf[6], *to; vimconv_T vc; - /* - * Convert the Unicode digraph to 'encoding'. - */ + // Convert the Unicode digraph to 'encoding'. i = utf_char2bytes(retval, buf); retval = 0; vc.vc_type = CONV_NONE; + if (convert_setup(&vc, (char_u *)"utf-8", p_enc) == OK) { vc.vc_fail = TRUE; to = string_convert(&vc, buf, &i); + if (to != NULL) { retval = (*mb_ptr2char)(to); vim_free(to); @@ -1751,77 +1746,92 @@ static int getexactdigraph(int char1, int char2, int meta_char) (void)convert_setup(&vc, NULL, NULL); } } -# endif +#endif // ifdef USE_UNICODE_DIGRAPHS - /* Ignore multi-byte characters when not in multi-byte mode. */ - if (!has_mbyte && retval > 0xff) + // Ignore multi-byte characters when not in multi-byte mode. + if (!has_mbyte && (retval > 0xff)) { retval = 0; + } - if (retval == 0) { /* digraph deleted or not found */ - if (char1 == ' ' && meta_char) /* <space> <char> --> meta-char */ + if (retval == 0) { + // digraph deleted or not found + if ((char1 == ' ') && meta_char) { + // <space> <char> --> meta-char return char2 | 0x80; + } return char2; } return retval; } -/* - * Get digraph. - * Allow for both char1-char2 and char2-char1 - */ +/// Get digraph. +/// Allow for both char1-char2 and char2-char1 +/// +/// @param char1 +/// @param char2 +/// @param meta_char +/// +/// @return The digraph. int getdigraph(int char1, int char2, int meta_char) { int retval; if (((retval = getexactdigraph(char1, char2, meta_char)) == char2) && (char1 != char2) - && ((retval = getexactdigraph(char2, char1, meta_char)) == char1)) + && ((retval = getexactdigraph(char2, char1, meta_char)) == char1)) { return char2; + } return retval; } -/* - * Add the digraphs in the argument to the digraph table. - * format: {c1}{c2} char {c1}{c2} char ... - */ +/// Add the digraphs in the argument to the digraph table. +/// format: {c1}{c2} char {c1}{c2} char ... +/// +/// @param str void putdigraph(char_u *str) { int char1, char2, n; int i; - digr_T *dp; + digr_T *dp; while (*str != NUL) { str = skipwhite(str); - if (*str == NUL) + + if (*str == NUL) { return; + } char1 = *str++; char2 = *str++; + if (char2 == 0) { EMSG(_(e_invarg)); return; } - if (char1 == ESC || char2 == ESC) { + + if ((char1 == ESC) || (char2 == ESC)) { EMSG(_("E104: Escape not allowed in digraph")); return; } str = skipwhite(str); + if (!VIM_ISDIGIT(*str)) { EMSG(_(e_number_exp)); return; } n = getdigits(&str); - /* If the digraph already exists, replace the result. */ + // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; + for (i = 0; i < user_digraphs.ga_len; ++i) { - if ((int)dp->char1 == char1 && (int)dp->char2 == char2) { + if (((int)dp->char1 == char1) && ((int)dp->char2 == char2)) { dp->result = n; break; } ++dp; } - /* Add a new digraph to the table. */ + // Add a new digraph to the table. if (i == user_digraphs.ga_len) { if (ga_grow(&user_digraphs, 1) == OK) { dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len; @@ -1834,32 +1844,37 @@ void putdigraph(char_u *str) } } -void listdigraphs(void) { +void listdigraphs(void) +{ int i; - digr_T *dp; + digr_T *dp; msg_putchar('\n'); dp = digraphdefault; + for (i = 0; dp->char1 != NUL && !got_int; ++i) { #if defined(USE_UNICODE_DIGRAPHS) && defined(FEAT_MBYTE) digr_T tmp; - /* May need to convert the result to 'encoding'. */ + // May need to convert the result to 'encoding'. tmp.char1 = dp->char1; tmp.char2 = dp->char2; tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE); - if (tmp.result != 0 && tmp.result != tmp.char2 - && (has_mbyte || tmp.result <= 255)) + + if ((tmp.result != 0) + && (tmp.result != tmp.char2) + && (has_mbyte || (tmp.result <= 255))) { printdigraph(&tmp); -#else + } +#else // if defined(USE_UNICODE_DIGRAPHS) && defined(FEAT_MBYTE) - if (getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result - && (has_mbyte || dp->result <= 255) - ) + if ((getexactdigraph(dp->char1, dp->char2, FALSE) == dp->result) + && (has_mbyte || (dp->result <= 255))) { printdigraph(dp); -#endif - ++dp; + } +#endif // if defined(USE_UNICODE_DIGRAPHS) && defined(FEAT_MBYTE) + dp++; ui_breakcheck(); } @@ -1867,97 +1882,106 @@ void listdigraphs(void) { for (i = 0; i < user_digraphs.ga_len && !got_int; ++i) { printdigraph(dp); ui_breakcheck(); - ++dp; + dp++; } - must_redraw = CLEAR; /* clear screen, because some digraphs may be - wrong, in which case we messed up ScreenLines */ + // clear screen, because some digraphs may be wrong, in which case we messed + // up ScreenLines + must_redraw = CLEAR; } static void printdigraph(digr_T *dp) { char_u buf[30]; - char_u *p; + char_u *p; int list_width; - if ((dy_flags & DY_UHEX) - || has_mbyte - ) + if ((dy_flags & DY_UHEX) || has_mbyte) { list_width = 13; - else + } else { list_width = 11; + } if (dp->result != 0) { - if (msg_col > Columns - list_width) + if (msg_col > Columns - list_width) { msg_putchar('\n'); - if (msg_col) - while (msg_col % list_width != 0) + } + + if (msg_col) { + while (msg_col % list_width != 0) { msg_putchar(' '); + } + } p = buf; *p++ = dp->char1; *p++ = dp->char2; *p++ = ' '; + if (has_mbyte) { - /* add a space to draw a composing char on */ - if (enc_utf8 && utf_iscomposing(dp->result)) + // add a space to draw a composing char on + if (enc_utf8 && utf_iscomposing(dp->result)) { *p++ = ' '; + } p += (*mb_char2bytes)(dp->result, p); - } else + } else { *p++ = (char_u)dp->result; - if (char2cells(dp->result) == 1) + } + + if (char2cells(dp->result) == 1) { *p++ = ' '; + } vim_snprintf((char *)p, sizeof(buf) - (p - buf), " %3d", dp->result); msg_outtrans(buf); } } - - -/* structure used for b_kmap_ga.ga_data */ +/// structure used for b_kmap_ga.ga_data typedef struct { - char_u *from; - char_u *to; + char_u *from; + char_u *to; } kmap_T; -#define KMAP_MAXLEN 20 /* maximum length of "from" or "to" */ +#define KMAP_MAXLEN 20 // maximum length of "from" or "to" static void keymap_unload(void); -/* - * Set up key mapping tables for the 'keymap' option. - * Returns NULL if OK, an error message for failure. This only needs to be - * used when setting the option, not later when the value has already been - * checked. - */ -char_u *keymap_init(void) { +/// Set up key mapping tables for the 'keymap' option. +/// +/// @return NULL if OK, an error message for failure. This only needs to be +/// used when setting the option, not later when the value has already +/// been checked. +char_u* keymap_init(void) +{ curbuf->b_kmap_state &= ~KEYMAP_INIT; if (*curbuf->b_p_keymap == NUL) { - /* Stop any active keymap and clear the table. Also remove - * b:keymap_name, as no keymap is active now. */ + // Stop any active keymap and clear the table. Also remove + // b:keymap_name, as no keymap is active now. keymap_unload(); do_cmdline_cmd((char_u *)"unlet! b:keymap_name"); - } else { + } else { char_u *buf; size_t buflen; - /* 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; + // 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; buf = alloc((unsigned)buflen); - if (buf == NULL) + + if (buf == NULL) { return e_outofmem; + } - /* try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' */ + // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim", - curbuf->b_p_keymap, p_enc); + curbuf->b_p_keymap, p_enc); + if (source_runtime(buf, FALSE) == FAIL) { - /* try finding "keymap/'keymap'.vim" in 'runtimepath' */ + // try finding "keymap/'keymap'.vim" in 'runtimepath' vim_snprintf((char *)buf, buflen, "keymap/%s.vim", - curbuf->b_p_keymap); + curbuf->b_p_keymap); + if (source_runtime(buf, FALSE) == FAIL) { vim_free(buf); return (char_u *)N_("E544: Keymap file not found"); @@ -1969,46 +1993,48 @@ char_u *keymap_init(void) { return NULL; } -/* - * ":loadkeymap" command: load the following lines as the keymap. - */ +/// ":loadkeymap" command: load the following lines as the keymap. +/// +/// @param eap void ex_loadkeymap(exarg_T *eap) { - char_u *line; - char_u *p; - char_u *s; - kmap_T *kp; -#define KMAP_LLEN 200 /* max length of "to" and "from" together */ + char_u *line; + char_u *p; + char_u *s; + kmap_T *kp; + +#define KMAP_LLEN 200 // max length of "to" and "from" together char_u buf[KMAP_LLEN + 11]; int i; - char_u *save_cpo = p_cpo; + char_u *save_cpo = p_cpo; if (!getline_equal(eap->getline, eap->cookie, getsourceline)) { EMSG(_("E105: Using :loadkeymap not in a sourced file")); return; } - /* - * Stop any active keymap and clear the table. - */ + // Stop any active keymap and clear the table. keymap_unload(); curbuf->b_kmap_state = 0; ga_init2(&curbuf->b_kmap_ga, (int)sizeof(kmap_T), 20); - /* Set 'cpoptions' to "C" to avoid line continuation. */ + // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; - /* - * Get each line of the sourced file, break at the end. - */ - for (;; ) { + // Get each line of the sourced file, break at the end. + for (;;) { line = eap->getline(0, eap->cookie, 0); - if (line == NULL) + + if (line == NULL) { break; + } p = skipwhite(line); - if (*p != '"' && *p != NUL && ga_grow(&curbuf->b_kmap_ga, 1) == OK) { + + if ((*p != '"') + && (*p != NUL) + && (ga_grow(&curbuf->b_kmap_ga, 1) == OK)) { kp = (kmap_T *)curbuf->b_kmap_ga.ga_data + curbuf->b_kmap_ga.ga_len; s = skiptowhite(p); kp->from = vim_strnsave(p, (int)(s - p)); @@ -2016,26 +2042,28 @@ void ex_loadkeymap(exarg_T *eap) s = skiptowhite(p); kp->to = vim_strnsave(p, (int)(s - p)); - if (kp->from == NULL || kp->to == NULL - || STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN - || *kp->from == NUL || *kp->to == NUL) { - if (kp->to != NULL && *kp->to == NUL) + if ((kp->from == NULL) + || (kp->to == NULL) + || (STRLEN(kp->from) + STRLEN(kp->to) >= KMAP_LLEN) + || (*kp->from == NUL) + || (*kp->to == NUL)) { + if ((kp->to != NULL) && (*kp->to == NUL)) { EMSG(_("E791: Empty keymap entry")); + } vim_free(kp->from); vim_free(kp->to); - } else + } else { ++curbuf->b_kmap_ga.ga_len; + } } vim_free(line); } - /* - * setup ":lnoremap" to map the keys - */ + // setup ":lnoremap" to map the keys for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)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); + ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, + ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); (void)do_map(2, buf, LANGMAP, FALSE); } @@ -2045,23 +2073,24 @@ void ex_loadkeymap(exarg_T *eap) status_redraw_curbuf(); } -/* - * Stop using 'keymap'. - */ -static void keymap_unload(void) { +/// Stop using 'keymap'. +static void keymap_unload(void) +{ char_u buf[KMAP_MAXLEN + 10]; int i; - char_u *save_cpo = p_cpo; - kmap_T *kp; + char_u *save_cpo = p_cpo; + kmap_T *kp; - if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) + if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) { return; + } - /* Set 'cpoptions' to "C" to avoid line continuation. */ + // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; - /* clear the ":lmap"s */ + // clear the ":lmap"s kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; + for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); (void)do_map(1, buf, LANGMAP, FALSE); @@ -2075,4 +2104,3 @@ static void keymap_unload(void) { curbuf->b_kmap_state &= ~KEYMAP_LOADED; status_redraw_curbuf(); } - diff --git a/src/digraph.h b/src/digraph.h index f638e0bd90..e19d2e4106 100644 --- a/src/digraph.h +++ b/src/digraph.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_DIGRAPH_H #define NEOVIM_DIGRAPH_H -/* digraph.c */ + int do_digraph(int c); int get_digraph(int cmdline); int getdigraph(int char1, int char2, int meta_char); @@ -8,5 +8,6 @@ void putdigraph(char_u *str); void listdigraphs(void); char_u *keymap_init(void); void ex_loadkeymap(exarg_T *eap); -/* vim: set ft=c : */ -#endif /* NEOVIM_DIGRAPH_H */ + +// vim: set ft=c: +#endif // NEOVIM_DIGRAPH_H diff --git a/src/farsi.c b/src/farsi.c index 9a22b3f364..1e2ea7428b 100644 --- a/src/farsi.c +++ b/src/farsi.c @@ -1,21 +1,13 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ +/// @file farsi.c +/// +/// Functions for Farsi language +/// +/// Included by main.c, when FEAT_FKMAP is defined. #include "farsi.h" #include "edit.h" #include "ex_getln.h" -/* - * farsi.c: functions for Farsi language - * - * Included by main.c, when FEAT_FKMAP is defined. - */ static int toF_Xor_X_(int c); static int F_is_TyE(int c); @@ -38,9 +30,11 @@ static int F_isterm(int c); static int toF_ending(int c); static void lrswapbuf(char_u *buf, int len); -/* -** Convert the given Farsi character into a _X or _X_ type -*/ +/// Convert the given Farsi character into a _X or _X_ type +/// +/// @param c The character to convert. +/// +/// @return Farsi character converted to a _X or _X_ type. static int toF_Xor_X_(int c) { int tempc; @@ -152,9 +146,11 @@ static int toF_Xor_X_(int c) return 0; } -/* -** Convert the given Farsi character into Farsi capital character . -*/ +/// Convert the given Farsi character into Farsi capital character. +/// +/// @param c The character to convert. +/// +/// @return Character converted to the Farsi capital leter. int toF_TyA(int c) { switch (c) { @@ -216,7 +212,8 @@ int toF_TyA(int c) case _GHAF: return GHAF; - /* I am not sure what it is !!! case _KAF_H: */ + // I am not sure what it is !!! + // case _KAF_H: case _KAF: return KAF; @@ -254,11 +251,14 @@ int toF_TyA(int c) return c; } -/* -** Is the character under the cursor+offset in the given buffer a join type. -** That is a character that is combined with the others. -** Note: the offset is used only for command line buffer. -*/ +/// Is the character under the cursor+offset in the given buffer a join type. +/// That is a character that is combined with the others. +/// Note: the offset is used only for command line buffer. +/// +/// @param src +/// @param offset +/// +/// @return TRUE if the character under the cursor+offset is a join type. static int F_is_TyB_TyC_TyD(int src, int offset) { int c; @@ -306,9 +306,11 @@ static int F_is_TyB_TyC_TyD(int src, int offset) return FALSE; } -/* -** Is the Farsi character one of the terminating only type. -*/ +/// Is the Farsi character one of the terminating only type. +/// +/// @param c The character to check. +/// +/// @return TRUE if the Farsi character is one of the terminating only types. static int F_is_TyE(int c) { switch (c) { @@ -327,9 +329,11 @@ static int F_is_TyE(int c) return FALSE; } -/* -** Is the Farsi character one of the none leading type. -*/ +/// Is the Farsi character one of the none leading type. +/// +/// @param c The character to check. +/// +/// @return TRUE if the Farsi character is one of the none-leading types. static int F_is_TyC_TyD(int c) { switch (c) { @@ -349,9 +353,11 @@ static int F_is_TyC_TyD(int c) return FALSE; } -/* -** Convert a none leading Farsi char into a leading type. -*/ +/// Convert a none leading Farsi char into a leading type. +/// +/// @param c The character to convert. +/// +/// @return The character converted into a leading type. static int toF_TyB(int c) { switch (c) { @@ -365,13 +371,15 @@ static int toF_TyB(int c) return _AYN; case AYN_: - return AYN; /* exception - there are many of them */ + // exception - there are many of them + return AYN; case _GHAYN_: return _GHAYN; case GHAYN_: - return GHAYN; /* exception - there are many of them */ + // exception - there are many of them + return GHAYN; case _HE_: return _HE; @@ -391,9 +399,9 @@ static int toF_TyB(int c) return c; } -/* -** Overwrite the current redo and cursor characters + left adjust -*/ +/// Overwrite the current redo and cursor characters + left adjust +/// +/// @param c static void put_curr_and_l_to_X(int c) { int tempc; @@ -434,9 +442,7 @@ static void put_and_redo(int c) AppendCharToRedobuff(c); } -/* -** Change the char. under the cursor to a X_ or X type -*/ +/// Change the char. under the cursor to a X_ or X type static void chg_c_toX_orX(void) { int tempc, curc; @@ -582,9 +588,7 @@ static void chg_c_toX_orX(void) } } -/* -** Change the char. under the cursor to a _X_ or X_ type -*/ +/// Change the char. under the cursor to a _X_ or X_ type static void chg_c_to_X_orX_(void) { int tempc; @@ -643,9 +647,7 @@ static void chg_c_to_X_orX_(void) } } -/* -** Change the char. under the cursor to a _X_ or _X type -*/ +/// Change the char. under the cursor to a _X_ or _X type static void chg_c_to_X_or_X(void) { int tempc; @@ -669,15 +671,13 @@ static void chg_c_to_X_or_X(void) } } -/* -** Change the character left to the cursor to a _X_ or X_ type -*/ +/// Change the character left to the cursor to a _X_ or X_ type static void chg_l_to_X_orX_(void) { int tempc; - if ((curwin->w_cursor.col != 0) && - (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) { + if ((curwin->w_cursor.col != 0) + && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(ml_get_curline()))) { return; } @@ -751,9 +751,7 @@ static void chg_l_to_X_orX_(void) } } -/* -** Change the character left to the cursor to a X or _X type -*/ +/// Change the character left to the cursor to a X or _X type static void chg_l_toXor_X(void) { int tempc; @@ -833,9 +831,7 @@ static void chg_l_toXor_X(void) } } -/* -** Change the character right to the cursor to a _X or _X_ type -*/ +/// Change the character right to the cursor to a _X or _X_ type static void chg_r_to_Xor_X_(void) { int tempc, c; @@ -856,9 +852,7 @@ static void chg_r_to_Xor_X_(void) } } -/* -** Map Farsi keyboard when in fkmap mode. -*/ +/// Map Farsi keyboard when in fkmap mode. int fkmap(int c) { int tempc; @@ -868,14 +862,15 @@ int fkmap(int c) return c; } - if (VIM_ISDIGIT(c) || - (((c == '.') || - (c == '+') || - (c == '-') || - (c == '^') || - (c == '%') || - (c == '#') || - (c == '=')) && revins)) { + if (VIM_ISDIGIT(c) + || (((c == '.') + || (c == '+') + || (c == '-') + || (c == '^') + || (c == '%') + || (c == '#') + || (c == '=')) + && revins)) { if (!revins) { if (curwin->w_cursor.col) { if (!p_ri) { @@ -897,7 +892,7 @@ int fkmap(int c) inc_cursor(); } - ++revins; + revins++; p_ri = 1; } else { if (revins) { @@ -906,28 +901,28 @@ int fkmap(int c) revins = 0; if (curwin->w_p_rl) { - while ((F_isdigit(gchar_cursor()) || - (gchar_cursor() == F_PERIOD || - gchar_cursor() == F_PLUS || - gchar_cursor() == F_MINUS || - gchar_cursor() == F_MUL || - gchar_cursor() == F_DIVIDE || - gchar_cursor() == F_PERCENT || - gchar_cursor() == F_EQUALS)) && - gchar_cursor() != NUL) { - ++curwin->w_cursor.col; + while ((F_isdigit(gchar_cursor()) + || (gchar_cursor() == F_PERIOD + || gchar_cursor() == F_PLUS + || gchar_cursor() == F_MINUS + || gchar_cursor() == F_MUL + || gchar_cursor() == F_DIVIDE + || gchar_cursor() == F_PERCENT + || gchar_cursor() == F_EQUALS)) + && gchar_cursor() != NUL) { + curwin->w_cursor.col++; } } else { if (curwin->w_cursor.col) { - while ((F_isdigit(gchar_cursor()) || - (gchar_cursor() == F_PERIOD || - gchar_cursor() == F_PLUS || - gchar_cursor() == F_MINUS || - gchar_cursor() == F_MUL || - gchar_cursor() == F_DIVIDE || - gchar_cursor() == F_PERCENT || - gchar_cursor() == F_EQUALS)) && - --curwin->w_cursor.col) { + while ((F_isdigit(gchar_cursor()) + || (gchar_cursor() == F_PERIOD + || gchar_cursor() == F_PLUS + || gchar_cursor() == F_MINUS + || gchar_cursor() == F_MUL + || gchar_cursor() == F_DIVIDE + || gchar_cursor() == F_PERCENT + || gchar_cursor() == F_EQUALS)) + && --curwin->w_cursor.col) { } } @@ -963,7 +958,6 @@ int fkmap(int c) } tempc = 0; - switch (c) { case '`': case ' ': @@ -1022,10 +1016,8 @@ int fkmap(int c) case NL: case TAB: if (p_ri && (c == NL) && curwin->w_cursor.col) { - /* - ** If the char before the cursor is _X_ or X_ do not change - ** the one under the cursor with X type. - */ + // If the char before the cursor is _X_ or X_ do not change + // the one under the cursor with X type. dec_cursor(); if (F_isalpha(gchar_cursor())) { @@ -1853,9 +1845,11 @@ int fkmap(int c) return c; } -/* -** Convert a none leading Farsi char into a leading type. -*/ +/// Convert a none leading Farsi char into a leading type. +/// +/// @param c The character to convert. +/// +/// @return The non-leading Farsi character converted to a leading type. static int toF_leading(int c) { switch (c) { @@ -1951,9 +1945,11 @@ static int toF_leading(int c) return c; } -/* -** Convert a given Farsi char into right joining type. -*/ +/// Convert a given Farsi char into right joining type. +/// +/// @param c The character to convert. +/// +/// @return The Farsi character converted into a right joining type static int toF_Rjoin(int c) { switch (c) { @@ -2052,9 +2048,11 @@ static int toF_Rjoin(int c) return c; } -/* -** Can a given Farsi character join via its left edj. -*/ +/// Can a given Farsi character join via its left edj. +/// +/// @param c The character to check. +/// +/// @return TRUE if the character can join via its left edj. static int canF_Ljoin(int c) { switch (c) { @@ -2124,9 +2122,11 @@ static int canF_Ljoin(int c) return FALSE; } -/* -** Can a given Farsi character join via its right edj. -*/ +/// Can a given Farsi character join via its right edj. +/// +/// @param c +/// +/// @return TRUE if the character can join via its right edj. static int canF_Rjoin(int c) { switch (c) { @@ -2149,9 +2149,11 @@ static int canF_Rjoin(int c) return canF_Ljoin(c); } -/* -** is a given Farsi character a terminating type. -*/ +/// Is a given Farsi character a terminating type. +/// +/// @param c +/// +/// @return TRUE if the character is a terminating type. static int F_isterm(int c) { switch (c) { @@ -2174,9 +2176,11 @@ static int F_isterm(int c) return FALSE; } -/* -** Convert the given Farsi character into a ending type . -*/ +/// Convert the given Farsi character into a ending type. +/// +/// @param c The character to convert. +/// +/// @return The character converted into an ending type. static int toF_ending(int c) { switch (c) { @@ -2278,9 +2282,7 @@ static int toF_ending(int c) return c; } -/* -** Convert the Farsi 3342 standard into Farsi VIM. -*/ +/// Convert the Farsi 3342 standard into Farsi VIM. void conv_to_pvim(void) { char_u *ptr; @@ -2292,14 +2294,14 @@ void conv_to_pvim(void) for (i = 0; i < llen - 1; i++) { if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i + 1])) { ptr[i] = toF_leading(ptr[i]); - ++i; + i++; while (canF_Rjoin(ptr[i]) && i < llen) { ptr[i] = toF_Rjoin(ptr[i]); if (F_isterm(ptr[i]) || !F_isalpha(ptr[i])) { break; } - ++i; + i++; } if (!F_isalpha(ptr[i]) || !canF_Rjoin(ptr[i])) { @@ -2311,30 +2313,22 @@ void conv_to_pvim(void) } } - /* - * Following lines contains Farsi encoded character. - */ - + // Following lines contains Farsi encoded character. do_cmdline_cmd((char_u *)"%s/\202\231/\232/g"); do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/g"); - /* Assume the screen has been messed up: clear it and redraw. */ + // Assume the screen has been messed up: clear it and redraw. redraw_later(CLEAR); MSG_ATTR(farsi_text_1, hl_attr(HLF_S)); } -/* - * Convert the Farsi VIM into Farsi 3342 standard. - */ +/// Convert the Farsi VIM into Farsi 3342 standard. void conv_to_pstd(void) { char_u *ptr; int lnum, llen, i; - /* - * Following line contains Farsi encoded character. - */ - + // Following line contains Farsi encoded character. do_cmdline_cmd((char_u *)"%s/\232/\202\231/g"); for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { ptr = ml_get((linenr_T)lnum); @@ -2344,14 +2338,15 @@ void conv_to_pstd(void) } } - /* Assume the screen has been messed up: clear it and redraw. */ + // Assume the screen has been messed up: clear it and redraw. redraw_later(CLEAR); MSG_ATTR(farsi_text_2, hl_attr(HLF_S)); } -/* - * left-right swap the characters in buf[len]. - */ +/// left-right swap the characters in buf[len]. +/// +/// @param buf +/// @param len static void lrswapbuf(char_u *buf, int len) { char_u *s, *e; @@ -2368,9 +2363,11 @@ static void lrswapbuf(char_u *buf, int len) } } -/* - * swap all the characters in reverse direction - */ +/// swap all the characters in reverse direction +/// +/// @param ibuf +/// +/// @return The buffer with the characters swapped. char_u* lrswap(char_u *ibuf) { if ((ibuf != NULL) && (*ibuf != NUL)) { @@ -2379,9 +2376,12 @@ char_u* lrswap(char_u *ibuf) return ibuf; } -/* - * swap all the Farsi characters in reverse direction - */ +/// swap all the Farsi characters in reverse direction +/// +/// @param cmdbuf +/// @param . +/// +/// @return The buffer with all Farsi characters swapped. char_u* lrFswap(char_u *cmdbuf, int len) { int i, cnt; @@ -2394,10 +2394,10 @@ char_u* lrFswap(char_u *cmdbuf, int len) } for (i = 0; i < len; i++) { - for (cnt = 0; i + cnt < len && - (F_isalpha(cmdbuf[i + cnt]) || - F_isdigit(cmdbuf[i + cnt]) || - cmdbuf[i + cnt] == ' '); ++cnt) { + for (cnt = 0; i + cnt < len + && (F_isalpha(cmdbuf[i + cnt]) + || F_isdigit(cmdbuf[i + cnt]) + || cmdbuf[i + cnt] == ' '); ++cnt) { } lrswapbuf(cmdbuf + i, cnt); @@ -2406,11 +2406,14 @@ char_u* lrFswap(char_u *cmdbuf, int len) return cmdbuf; } -/* - * Reverse the characters in the search path and substitute section - * accordingly. - * TODO: handle different separator characters. Use skip_regexp(). - */ +/// Reverse the characters in the search path and substitute section +/// accordingly. +/// TODO: handle different separator characters. Use skip_regexp(). +/// +/// @param ibuf +/// +/// @return The buffer with the characters in the search path and substitute +/// section reversed. char_u* lrF_sub(char_u *ibuf) { char_u *p, *ep; @@ -2418,7 +2421,7 @@ char_u* lrF_sub(char_u *ibuf) p = ibuf; - /* Find the boundary of the search path */ + // Find the boundary of the search path while (((p = vim_strchr(p + 1, '/')) != NULL) && p[-1] == '\\') { } @@ -2426,17 +2429,17 @@ char_u* lrF_sub(char_u *ibuf) return ibuf; } - /* Reverse the Farsi characters in the search path. */ + // Reverse the Farsi characters in the search path. lrFswap(ibuf, (int)(p - ibuf)); - /* Now find the boundary of the substitute section */ + // Now find the boundary of the substitute section if ((ep = (char_u *)strrchr((char *)++p, '/')) != NULL) { cnt = (int)(ep - p); } else { cnt = (int)STRLEN(p); } - /* Reverse the characters in the substitute section and take care of '\' */ + // Reverse the characters in the substitute section and take care of '\' for (i = 0; i < cnt - 1; i++) { if (p[i] == '\\') { p[i] = p[i + 1]; @@ -2448,9 +2451,11 @@ char_u* lrF_sub(char_u *ibuf) return ibuf; } -/* - * Map Farsi keyboard when in cmd_fkmap mode. - */ +/// Map Farsi keyboard when in cmd_fkmap mode. +/// +/// @param c +/// +/// @return The mapped character. int cmdl_fkmap(int c) { int tempc; @@ -2567,7 +2572,7 @@ int cmdl_fkmap(int c) if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR + 1)) { cmd_pchar(YE_, AT_CURSOR); } else { - cmd_pchar(YE, AT_CURSOR); + cmd_pchar(YE, AT_CURSOR); } } @@ -2881,27 +2886,33 @@ int cmdl_fkmap(int c) return c; } -/* - * F_isalpha returns TRUE if 'c' is a Farsi alphabet - */ +/// F_isalpha returns TRUE if 'c' is a Farsi alphabet +/// +/// @param c The character to check. +/// +/// @return TRUE if 'c' is a Farsi alphabet character. int F_isalpha(int c) { - return (c >= TEE_ && c <= _YE) || - (c >= ALEF_A && c <= YE) || - (c >= _IE && c <= YE_); + return (c >= TEE_ && c <= _YE) + || (c >= ALEF_A && c <= YE) + || (c >= _IE && c <= YE_); } -/* - * F_isdigit returns TRUE if 'c' is a Farsi digit - */ +/// F_isdigit returns TRUE if 'c' is a Farsi digit +/// +/// @param c The character to check. +/// +/// @return TRUE if 'c' is a Farsi digit. int F_isdigit(int c) { return c >= FARSI_0 && c <= FARSI_9; } -/* - * F_ischar returns TRUE if 'c' is a Farsi character. - */ +/// F_ischar returns TRUE if 'c' is a Farsi character. +/// +/// @param c The character to check. +/// +/// @return TRUE if 'c' is a Farsi character. int F_ischar(int c) { return c >= TEE_ && c <= YE_; diff --git a/src/farsi.h b/src/farsi.h index 1a38e01cf3..6e35f8ef39 100644 --- a/src/farsi.h +++ b/src/farsi.h @@ -1,31 +1,19 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - */ - -#ifndef SRC_FARSI_H_ -#define SRC_FARSI_H_ - -/* - * Farsi characters are categorized into following types: - * - * TyA (for capital letter representation) - * TyB (for types that look like _X e.g. AYN) - * TyC (for types that look like X_ e.g. YE_) - * TyD (for types that look like _X_ e.g. _AYN_) - * TyE (for types that look like X e.g. RE) - */ - -/* - * Farsi character set definition - */ - -/* - * Begin of the non-standard part - */ +/// @file farsi.h +/// +/// Farsi characters are categorized into following types: +/// +/// TyA (for capital letter representation) +/// TyB (for types that look like _X e.g. AYN) +/// TyC (for types that look like X_ e.g. YE_) +/// TyD (for types that look like _X_ e.g. _AYN_) +/// TyE (for types that look like X e.g. RE) + +#ifndef NEOVIM_FARSI_H +#define NEOVIM_FARSI_H + +// Farsi character set definition + +// Begin of the non-standard part #define TEE_ 0x80 #define ALEF_U_H_ 0x81 @@ -66,30 +54,26 @@ #define YEE_ 0xef #define YE_ 0xff -/* - * End of the non-standard part - */ - -/* - * Standard part - */ - -#define F_BLANK 0xa0 /* Farsi ' ' (SP) character */ -#define F_PSP 0xa1 /* PSP for capitalizing of a character */ -#define F_PCN 0xa2 /* PCN for redefining of the hamye meaning */ -#define F_EXCL 0xa3 /* Farsi ! character */ -#define F_CURRENCY 0xa4 /* Farsi Rial character */ -#define F_PERCENT 0xa5 /* Farsi % character */ -#define F_PERIOD 0xa6 /* Farsi '.' character */ -#define F_COMMA 0xa7 /* Farsi ',' character */ -#define F_LPARENT 0xa8 /* Farsi '(' character */ -#define F_RPARENT 0xa9 /* Farsi ')' character */ -#define F_MUL 0xaa /* Farsi 'x' character */ -#define F_PLUS 0xab /* Farsi '+' character */ -#define F_BCOMMA 0xac /* Farsi comma character */ -#define F_MINUS 0xad /* Farsi '-' character */ -#define F_DIVIDE 0xae /* Farsi divide (/) character */ -#define F_SLASH 0xaf /* Farsi '/' character */ +// End of the non-standard part + +// Standard part + +#define F_BLANK 0xa0 // Farsi ' ' (SP) character +#define F_PSP 0xa1 // PSP for capitalizing of a character +#define F_PCN 0xa2 // PCN for redefining of the hamye meaning +#define F_EXCL 0xa3 // Farsi ! character +#define F_CURRENCY 0xa4 // Farsi Rial character +#define F_PERCENT 0xa5 // Farsi % character +#define F_PERIOD 0xa6 // Farsi '.' character +#define F_COMMA 0xa7 // Farsi ',' character +#define F_LPARENT 0xa8 // Farsi '(' character +#define F_RPARENT 0xa9 // Farsi ')' character +#define F_MUL 0xaa // Farsi 'x' character +#define F_PLUS 0xab // Farsi '+' character +#define F_BCOMMA 0xac // Farsi comma character +#define F_MINUS 0xad // Farsi '-' character +#define F_DIVIDE 0xae // Farsi divide (/) character +#define F_SLASH 0xaf // Farsi '/' character #define FARSI_0 0xb0 #define FARSI_1 0xb1 @@ -102,12 +86,12 @@ #define FARSI_8 0xb8 #define FARSI_9 0xb9 -#define F_DCOLON 0xba /* Farsi ':' character */ -#define F_SEMICOLON 0xbb /* Farsi ';' character */ -#define F_GREATER 0xbc /* Farsi '>' character */ -#define F_EQUALS 0xbd /* Farsi '=' character */ -#define F_LESS 0xbe /* Farsi '<' character */ -#define F_QUESTION 0xbf /* Farsi ? character */ +#define F_DCOLON 0xba // Farsi ':' character +#define F_SEMICOLON 0xbb // Farsi ';' character +#define F_GREATER 0xbc // Farsi '>' character +#define F_EQUALS 0xbd // Farsi '=' character +#define F_LESS 0xbe // Farsi '<' character +#define F_QUESTION 0xbf // Farsi ? character #define ALEF_A 0xc0 #define ALEF 0xc1 @@ -141,22 +125,22 @@ #define MIM 0xdd #define NOON 0xde #define WAW 0xdf -#define F_HE 0xe0 /* F_ added for name clash with Perl */ +#define F_HE 0xe0 // F_ added for name clash with Perl #define YE 0xe1 #define TEE 0xfc #define _KAF_H 0xfd #define YEE 0xfe -#define F_LBRACK 0xe2 /* Farsi '[' character */ -#define F_RBRACK 0xe3 /* Farsi ']' character */ -#define F_LBRACE 0xe4 /* Farsi '{' character */ -#define F_RBRACE 0xe5 /* Farsi '}' character */ -#define F_LQUOT 0xe6 /* Farsi left quotation character */ -#define F_RQUOT 0xe7 /* Farsi right quotation character */ -#define F_STAR 0xe8 /* Farsi '*' character */ -#define F_UNDERLINE 0xe9 /* Farsi '_' character */ -#define F_PIPE 0xea /* Farsi '|' character */ -#define F_BSLASH 0xeb /* Farsi '\' character */ +#define F_LBRACK 0xe2 // Farsi '[' character +#define F_RBRACK 0xe3 // Farsi ']' character +#define F_LBRACE 0xe4 // Farsi '{' character +#define F_RBRACE 0xe5 // Farsi '}' character +#define F_LQUOT 0xe6 // Farsi left quotation character +#define F_RQUOT 0xe7 // Farsi right quotation character +#define F_STAR 0xe8 // Farsi '*' character +#define F_UNDERLINE 0xe9 // Farsi '_' character +#define F_PIPE 0xea // Farsi '|' character +#define F_BSLASH 0xeb // Farsi '\' character #define MAD 0xf0 #define JAZR 0xf1 @@ -170,23 +154,19 @@ #define WAW_H 0xf9 #define ALEF_D_H 0xfa -/* - * global definitions - * ================== - */ +// global definitions +// ================== #define SRC_EDT 0 #define SRC_CMD 1 #define AT_CURSOR 0 -/* - * definitions for the window dependent functions (w_farsi). - */ +// definitions for the window dependent functions (w_farsi). #define W_CONV 0x1 #define W_R_L 0x2 -/* special Farsi text messages */ +// special Farsi text messages #ifdef DO_INIT EXTERN char_u farsi_text_1[] = { @@ -231,4 +211,4 @@ EXTERN char_u farsi_text_5[] = { EXTERN char_u farsi_text_5[]; #endif -#endif // SRC_FARSI_H_ +#endif // NEOVIM_FARSI_H diff --git a/src/garray.c b/src/garray.c index b941233ed1..f991498a2b 100644 --- a/src/garray.c +++ b/src/garray.c @@ -1,39 +1,38 @@ -/* - * Functions for handling growing arrays. - */ +/// @file garray.c +/// +/// Functions for handling growing arrays. #include "vim.h" #include "ascii.h" #include "misc2.h" #include "garray.h" -//#include "globals.h" + +// #include "globals.h" #include "memline.h" -/* - * Clear an allocated growing array. - */ +/// Clear an allocated growing array. void ga_clear(garray_T *gap) { vim_free(gap->ga_data); ga_init(gap); } -/* - * Clear a growing array that contains a list of strings. - */ +/// Clear a growing array that contains a list of strings. +/// +/// @param gap void ga_clear_strings(garray_T *gap) { int i; - - for (i = 0; i < gap->ga_len; ++i) + for (i = 0; i < gap->ga_len; ++i) { vim_free(((char_u **)(gap->ga_data))[i]); + } ga_clear(gap); } -/* - * Initialize a growing array. Don't forget to set ga_itemsize and - * ga_growsize! Or use ga_init2(). - */ +/// Initialize a growing array. Don't forget to set ga_itemsize and +/// ga_growsize! Or use ga_init2(). +/// +/// @param gap void ga_init(garray_T *gap) { gap->ga_data = NULL; @@ -41,6 +40,11 @@ void ga_init(garray_T *gap) gap->ga_len = 0; } +/// Initialize a growing array. +/// +/// @param gap +/// @param itemsize +/// @param growsize void ga_init2(garray_T *gap, int itemsize, int growsize) { ga_init(gap); @@ -48,24 +52,30 @@ void ga_init2(garray_T *gap, int itemsize, int growsize) gap->ga_growsize = growsize; } -/* - * Make room in growing array "gap" for at least "n" items. - * Return FAIL for failure, OK otherwise. - */ +/// Make room in growing array "gap" for at least "n" items. +/// +/// @param gap +/// @param n +/// +/// @return FAIL for failure, OK otherwise. int ga_grow(garray_T *gap, int n) { size_t old_len; size_t new_len; - char_u *pp; + char_u *pp; if (gap->ga_maxlen - gap->ga_len < n) { - if (n < gap->ga_growsize) + if (n < gap->ga_growsize) { n = gap->ga_growsize; + } new_len = gap->ga_itemsize * (gap->ga_len + n); pp = (gap->ga_data == NULL) - ? alloc((unsigned)new_len) : vim_realloc(gap->ga_data, new_len); - if (pp == NULL) + ? alloc((unsigned)new_len) + : vim_realloc(gap->ga_data, new_len); + + if (pp == NULL) { return FAIL; + } old_len = gap->ga_itemsize * gap->ga_maxlen; vim_memset(pp + old_len, 0, new_len - old_len); gap->ga_maxlen = gap->ga_len + n; @@ -74,71 +84,79 @@ int ga_grow(garray_T *gap, int n) return OK; } -/* - * For a growing array that contains a list of strings: concatenate all the - * strings with a separating comma. - * Returns NULL when out of memory. - */ -char_u *ga_concat_strings(garray_T *gap) +/// For a growing array that contains a list of strings: concatenate all the +/// strings with a separating comma. +/// +/// @param gap +/// +/// @returns NULL when out of memory. +char_u* ga_concat_strings(garray_T *gap) { int i; int len = 0; - char_u *s; + char_u *s; - for (i = 0; i < gap->ga_len; ++i) + for (i = 0; i < gap->ga_len; ++i) { len += (int)STRLEN(((char_u **)(gap->ga_data))[i]) + 1; + } s = alloc(len + 1); + if (s != NULL) { *s = NUL; + for (i = 0; i < gap->ga_len; ++i) { - if (*s != NUL) + if (*s != NUL) { STRCAT(s, ","); + } STRCAT(s, ((char_u **)(gap->ga_data))[i]); } } return s; } -/* - * Concatenate a string to a growarray which contains characters. - * Note: Does NOT copy the NUL at the end! - */ +/// Concatenate a string to a growarray which contains characters. +/// Note: Does NOT copy the NUL at the end! +/// +/// @param gap +/// @param s void ga_concat(garray_T *gap, char_u *s) { int len = (int)STRLEN(s); - if (ga_grow(gap, len) == OK) { mch_memmove((char *)gap->ga_data + gap->ga_len, s, (size_t)len); gap->ga_len += len; } } -/* - * Append one byte to a growarray which contains bytes. - */ +/// Append one byte to a growarray which contains bytes. +/// +/// @param gap +/// @param c void ga_append(garray_T *gap, int c) { if (ga_grow(gap, 1) == OK) { - *((char *)gap->ga_data + gap->ga_len) = c; + *((char *) gap->ga_data + gap->ga_len) = c; ++gap->ga_len; } } #if defined(UNIX) || defined(WIN3264) -/* - * Append the text in "gap" below the cursor line and clear "gap". - */ + +/// Append the text in "gap" below the cursor line and clear "gap". +/// +/// @param gap void append_ga_line(garray_T *gap) { - /* Remove trailing CR. */ - if (gap->ga_len > 0 + // Remove trailing CR. + if ((gap->ga_len > 0) && !curbuf->b_p_bin - && ((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR) - --gap->ga_len; + && (((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR)) { + gap->ga_len--; + } ga_append(gap, NUL); ml_append(curwin->w_cursor.lnum++, gap->ga_data, 0, FALSE); gap->ga_len = 0; } -#endif +#endif // if defined(UNIX) || defined(WIN3264) diff --git a/src/garray.h b/src/garray.h index 412a7f3ec3..c427842d93 100644 --- a/src/garray.h +++ b/src/garray.h @@ -1,20 +1,18 @@ #ifndef NEOVIM_GARRAY_H #define NEOVIM_GARRAY_H -/* - * Structure used for growing arrays. - * This is used to store information that only grows, is deleted all at - * once, and needs to be accessed by index. See ga_clear() and ga_grow(). - */ +/// Structure used for growing arrays. +/// This is used to store information that only grows, is deleted all at +/// once, and needs to be accessed by index. See ga_clear() and ga_grow(). typedef struct growarray { - int ga_len; /* current number of items used */ - int ga_maxlen; /* maximum number of items possible */ - int ga_itemsize; /* sizeof(item) */ - int ga_growsize; /* number of items to grow each time */ - void *ga_data; /* pointer to the first item */ + int ga_len; // current number of items used + int ga_maxlen; // maximum number of items possible + int ga_itemsize; // sizeof(item) + int ga_growsize; // number of items to grow each time + void *ga_data; // pointer to the first item } garray_T; -#define GA_EMPTY {0, 0, 0, 0, NULL} +#define GA_EMPTY { 0, 0, 0, 0, NULL } void ga_clear(garray_T *gap); void ga_clear_strings(garray_T *gap); @@ -26,4 +24,4 @@ void ga_concat(garray_T *gap, char_u *s); void ga_append(garray_T *gap, int c); void append_ga_line(garray_T *gap); -#endif /* NEOVIM_GARRAY_H */ +#endif // NEOVIM_GARRAY_H diff --git a/src/hashtab.c b/src/hashtab.c index fc639e3512..ed198ecc6a 100644 --- a/src/hashtab.c +++ b/src/hashtab.c @@ -1,180 +1,186 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * hashtab.c: Handling of a hashtable with Vim-specific properties. - * - * Each item in a hashtable has a NUL terminated string key. A key can appear - * only once in the table. - * - * A hash number is computed from the key for quick lookup. When the hashes - * of two different keys point to the same entry an algorithm is used to - * iterate over other entries in the table until the right one is found. - * To make the iteration work removed keys are different from entries where a - * key was never present. - * - * The mechanism has been partly based on how Python Dictionaries are - * implemented. The algorithm is from Knuth Vol. 3, Sec. 6.4. - * - * The hashtable grows to accommodate more entries when needed. At least 1/3 - * of the entries is empty to keep the lookup efficient (at the cost of extra - * memory). - */ +/// @file hashtab.c +/// +/// Handling of a hashtable with Vim-specific properties. +/// +/// Each item in a hashtable has a NUL terminated string key. A key can appear +/// only once in the table. +/// +/// A hash number is computed from the key for quick lookup. When the hashes +/// of two different keys point to the same entry an algorithm is used to +/// iterate over other entries in the table until the right one is found. +/// To make the iteration work removed keys are different from entries where a +/// key was never present. +/// +/// The mechanism has been partly based on how Python Dictionaries are +/// implemented. The algorithm is from Knuth Vol. 3, Sec. 6.4. +/// +/// The hashtable grows to accommodate more entries when needed. At least 1/3 +/// of the entries is empty to keep the lookup efficient (at the cost of extra +/// memory). #include "vim.h" #include "hashtab.h" #include "message.h" #include "misc2.h" -/* Magic value for algorithm that walks through the array. */ +// Magic value for algorithm that walks through the array. #define PERTURB_SHIFT 5 static int hash_may_resize(hashtab_T *ht, int minitems); -/* - * Initialize an empty hash table. - */ +/// Initialize an empty hash table. +/// +/// @param ht void hash_init(hashtab_T *ht) { - /* This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". */ + // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". vim_memset(ht, 0, sizeof(hashtab_T)); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; } -/* - * Free the array of a hash table. Does not free the items it contains! - * If "ht" is not freed then you should call hash_init() next! - */ +/// Free the array of a hash table. Does not free the items it contains! +/// If "ht" is not freed then you should call hash_init() next! +/// +/// @param ht void hash_clear(hashtab_T *ht) { - if (ht->ht_array != ht->ht_smallarray) + if (ht->ht_array != ht->ht_smallarray) { vim_free(ht->ht_array); + } } -/* - * Free the array of a hash table and all the keys it contains. The keys must - * have been allocated. "off" is the offset from the start of the allocate - * memory to the location of the key (it's always positive). - */ +/// Free the array of a hash table and all the keys it contains. The keys must +/// have been allocated. "off" is the offset from the start of the allocate +/// memory to the location of the key (it's always positive). +/// +/// @param ht +/// @param off void hash_clear_all(hashtab_T *ht, int off) { long todo; - hashitem_T *hi; + hashitem_T *hi; todo = (long)ht->ht_used; + for (hi = ht->ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { vim_free(hi->hi_key - off); - --todo; + todo--; } } hash_clear(ht); } -/* - * Find "key" in hashtable "ht". "key" must not be NULL. - * Always returns a pointer to a hashitem. If the item was not found then - * HASHITEM_EMPTY() is TRUE. The pointer is then the place where the key - * would be added. - * WARNING: The returned pointer becomes invalid when the hashtable is changed - * (adding, setting or removing an item)! - */ -hashitem_T *hash_find(hashtab_T *ht, char_u *key) +/// Find "key" in hashtable "ht". "key" must not be NULL. +/// Always returns a pointer to a hashitem. If the item was not found then +/// HASHITEM_EMPTY() is TRUE. The pointer is then the place where the key +/// would be added. +/// WARNING: The returned pointer becomes invalid when the hashtable is changed +/// (adding, setting or removing an item)! +/// +/// @param ht +/// @param key +/// +/// @return Pointer to the hashitem stored with the given key. +hashitem_T* hash_find(hashtab_T *ht, char_u *key) { return hash_lookup(ht, key, hash_hash(key)); } -/* - * Like hash_find(), but caller computes "hash". - */ -hashitem_T *hash_lookup(hashtab_T *ht, char_u *key, hash_T hash) +/// Like hash_find(), but caller computes "hash". +/// +/// @param ht +/// @param key +/// @param hash +/// +/// @return Pointer to the hashitem stored with the given key. +hashitem_T* hash_lookup(hashtab_T *ht, char_u *key, hash_T hash) { hash_T perturb; - hashitem_T *freeitem; - hashitem_T *hi; + hashitem_T *freeitem; + hashitem_T *hi; unsigned idx; #ifdef HT_DEBUG - ++hash_count_lookup; -#endif - - /* - * Quickly handle the most common situations: - * - return if there is no item at all - * - skip over a removed item - * - return if the item matches - */ + hash_count_lookup++; +#endif // ifdef HT_DEBUG + + // Quickly handle the most common situations: + // - return if there is no item at all + // - skip over a removed item + // - return if the item matches idx = (unsigned)(hash & ht->ht_mask); hi = &ht->ht_array[idx]; - if (hi->hi_key == NULL) + if (hi->hi_key == NULL) { return hi; - if (hi->hi_key == HI_KEY_REMOVED) + } + + if (hi->hi_key == HI_KEY_REMOVED) { freeitem = hi; - else if (hi->hi_hash == hash && STRCMP(hi->hi_key, key) == 0) + } else if ((hi->hi_hash == hash) && (STRCMP(hi->hi_key, key) == 0)) { return hi; - else + } else { freeitem = NULL; + } - /* - * Need to search through the table to find the key. The algorithm - * to step through the table starts with large steps, gradually becoming - * smaller down to (1/4 table size + 1). This means it goes through all - * table entries in the end. - * When we run into a NULL key it's clear that the key isn't there. - * Return the first available slot found (can be a slot of a removed - * item). - */ + // Need to search through the table to find the key. The algorithm + // to step through the table starts with large steps, gradually becoming + // smaller down to (1/4 table size + 1). This means it goes through all + // table entries in the end. + // When we run into a NULL key it's clear that the key isn't there. + // Return the first available slot found (can be a slot of a removed + // item). for (perturb = hash;; perturb >>= PERTURB_SHIFT) { #ifdef HT_DEBUG - ++hash_count_perturb; /* count a "miss" for hashtab lookup */ -#endif + // count a "miss" for hashtab lookup + hash_count_perturb++; +#endif // ifdef HT_DEBUG idx = (unsigned)((idx << 2U) + idx + perturb + 1U); hi = &ht->ht_array[idx & ht->ht_mask]; - if (hi->hi_key == NULL) + + if (hi->hi_key == NULL) { return freeitem == NULL ? hi : freeitem; - if (hi->hi_hash == hash - && hi->hi_key != HI_KEY_REMOVED - && STRCMP(hi->hi_key, key) == 0) + } + + if ((hi->hi_hash == hash) + && (hi->hi_key != HI_KEY_REMOVED) + && (STRCMP(hi->hi_key, key) == 0)) { return hi; - if (hi->hi_key == HI_KEY_REMOVED && freeitem == NULL) + } + + if ((hi->hi_key == HI_KEY_REMOVED) && (freeitem == NULL)) { freeitem = hi; + } } } -/* - * Print the efficiency of hashtable lookups. - * Useful when trying different hash algorithms. - * Called when exiting. - */ -void hash_debug_results(void) { +/// Print the efficiency of hashtable lookups. +/// Useful when trying different hash algorithms. +/// Called when exiting. +void hash_debug_results(void) +{ #ifdef HT_DEBUG fprintf(stderr, "\r\n\r\n\r\n\r\n"); fprintf(stderr, "Number of hashtable lookups: %ld\r\n", hash_count_lookup); fprintf(stderr, "Number of perturb loops: %ld\r\n", hash_count_perturb); fprintf(stderr, "Percentage of perturb loops: %ld%%\r\n", - hash_count_perturb * 100 / hash_count_lookup); -#endif + hash_count_perturb * 100 / hash_count_lookup); +#endif // ifdef HT_DEBUG } -/* - * Add item with key "key" to hashtable "ht". - * Returns FAIL when out of memory or the key is already present. - */ +/// Add item with key "key" to hashtable "ht". +/// +/// @param ht +/// @param key +/// +/// @returns FAIL when out of memory or the key is already present. int hash_add(hashtab_T *ht, char_u *key) { hash_T hash = hash_hash(key); - hashitem_T *hi; - - hi = hash_lookup(ht, key, hash); + hashitem_T *hi = hash_lookup(ht, key, hash); if (!HASHITEM_EMPTY(hi)) { EMSG2(_(e_intern2), "hash_add()"); return FAIL; @@ -182,77 +188,79 @@ int hash_add(hashtab_T *ht, char_u *key) return hash_add_item(ht, hi, key, hash); } -/* - * Add item "hi" with "key" to hashtable "ht". "key" must not be NULL and - * "hi" must have been obtained with hash_lookup() and point to an empty item. - * "hi" is invalid after this! - * Returns OK or FAIL (out of memory). - */ +/// Add item "hi" with "key" to hashtable "ht". "key" must not be NULL and +/// "hi" must have been obtained with hash_lookup() and point to an empty item. +/// "hi" is invalid after this! +/// +/// @param ht +/// @param hi +/// @param key +/// @param hash +/// +/// @returns OK or FAIL (out of memory). int hash_add_item(hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) { - /* If resizing failed before and it fails again we can't add an item. */ - if (ht->ht_error && hash_may_resize(ht, 0) == FAIL) + // If resizing failed before and it fails again we can't add an item. + if (ht->ht_error && (hash_may_resize(ht, 0) == FAIL)) { return FAIL; + } - ++ht->ht_used; - if (hi->hi_key == NULL) - ++ht->ht_filled; + ht->ht_used++; + if (hi->hi_key == NULL) { + ht->ht_filled++; + } hi->hi_key = key; hi->hi_hash = hash; - /* When the space gets low may resize the array. */ + // When the space gets low may resize the array. return hash_may_resize(ht, 0); } - -/* - * Remove item "hi" from hashtable "ht". "hi" must have been obtained with - * hash_lookup(). - * The caller must take care of freeing the item itself. - */ +/// Remove item "hi" from hashtable "ht". "hi" must have been obtained with +/// hash_lookup(). +/// +/// The caller must take care of freeing the item itself. +/// +/// @param ht +/// @param hi void hash_remove(hashtab_T *ht, hashitem_T *hi) { - --ht->ht_used; + ht->ht_used--; hi->hi_key = HI_KEY_REMOVED; hash_may_resize(ht, 0); } -/* - * Lock a hashtable: prevent that ht_array changes. - * Don't use this when items are to be added! - * Must call hash_unlock() later. - */ +/// Lock a hashtable: prevent that ht_array changes. +/// Don't use this when items are to be added! +/// Must call hash_unlock() later. +/// +/// @param ht void hash_lock(hashtab_T *ht) { - ++ht->ht_locked; + ht->ht_locked++; } - -/* - * Unlock a hashtable: allow ht_array changes again. - * Table will be resized (shrink) when necessary. - * This must balance a call to hash_lock(). - */ +/// Unlock a hashtable: allow ht_array changes again. +/// Table will be resized (shrink) when necessary. +/// This must balance a call to hash_lock(). void hash_unlock(hashtab_T *ht) { - --ht->ht_locked; + ht->ht_locked--; (void)hash_may_resize(ht, 0); } -/* - * Shrink a hashtable when there is too much empty space. - * Grow a hashtable when there is not enough empty space. - * Returns OK or FAIL (out of memory). - */ -static int -hash_may_resize ( - hashtab_T *ht, - int minitems /* minimal number of items */ -) +/// Shrink a hashtable when there is too much empty space. +/// Grow a hashtable when there is not enough empty space. +/// +/// @param ht +/// @param minitems minimal number of items +/// +/// @returns OK or FAIL (out of memory). +static int hash_may_resize(hashtab_T *ht, int minitems) { hashitem_T temparray[HT_INIT_SIZE]; - hashitem_T *oldarray, *newarray; - hashitem_T *olditem, *newitem; + hashitem_T *oldarray, *newarray; + hashitem_T *olditem, *newitem; unsigned newi; int todo; long_u oldsize, newsize; @@ -260,73 +268,89 @@ hash_may_resize ( long_u newmask; hash_T perturb; - /* Don't resize a locked table. */ - if (ht->ht_locked > 0) + // Don't resize a locked table. + if (ht->ht_locked > 0) { return OK; + } #ifdef HT_DEBUG - if (ht->ht_used > ht->ht_filled) + if (ht->ht_used > ht->ht_filled) { EMSG("hash_may_resize(): more used than filled"); - if (ht->ht_filled >= ht->ht_mask + 1) + } + + if (ht->ht_filled >= ht->ht_mask + 1) { EMSG("hash_may_resize(): table completely filled"); -#endif + } +#endif // ifdef HT_DEBUG if (minitems == 0) { - /* Return quickly for small tables with at least two NULL items. NULL - * items are required for the lookup to decide a key isn't there. */ - if (ht->ht_filled < HT_INIT_SIZE - 1 - && ht->ht_array == ht->ht_smallarray) + // Return quickly for small tables with at least two NULL items. NULL + // items are required for the lookup to decide a key isn't there. + if ((ht->ht_filled < HT_INIT_SIZE - 1) + && (ht->ht_array == ht->ht_smallarray)) { return OK; + } - /* - * Grow or refill the array when it's more than 2/3 full (including - * removed items, so that they get cleaned up). - * Shrink the array when it's less than 1/5 full. When growing it is - * at least 1/4 full (avoids repeated grow-shrink operations) - */ + // Grow or refill the array when it's more than 2/3 full (including + // removed items, so that they get cleaned up). + // Shrink the array when it's less than 1/5 full. When growing it is + // at least 1/4 full (avoids repeated grow-shrink operations) oldsize = ht->ht_mask + 1; - if (ht->ht_filled * 3 < oldsize * 2 && ht->ht_used > oldsize / 5) + if ((ht->ht_filled * 3 < oldsize * 2) && (ht->ht_used > oldsize / 5)) { return OK; + } - if (ht->ht_used > 1000) - minsize = ht->ht_used * 2; /* it's big, don't make too much room */ - else - minsize = ht->ht_used * 4; /* make plenty of room */ - } else { - /* Use specified size. */ - if ((long_u)minitems < ht->ht_used) /* just in case... */ + if (ht->ht_used > 1000) { + // it's big, don't make too much room + minsize = ht->ht_used * 2; + } else { + // make plenty of room + minsize = ht->ht_used * 4; + } + } else { + // Use specified size. + if ((long_u)minitems < ht->ht_used) { + // just in case... minitems = (int)ht->ht_used; - minsize = minitems * 3 / 2; /* array is up to 2/3 full */ + } + // array is up to 2/3 full + minsize = minitems * 3 / 2; } newsize = HT_INIT_SIZE; + while (newsize < minsize) { - newsize <<= 1; /* make sure it's always a power of 2 */ - if (newsize == 0) - return FAIL; /* overflow */ + // make sure it's always a power of 2 + newsize <<= 1; + if (newsize == 0) { + // overflow + return FAIL; + } } if (newsize == HT_INIT_SIZE) { - /* Use the small array inside the hashdict structure. */ + // Use the small array inside the hashdict structure. newarray = ht->ht_smallarray; if (ht->ht_array == newarray) { - /* Moving from ht_smallarray to ht_smallarray! Happens when there - * are many removed items. Copy the items to be able to clean up - * removed items. */ + // Moving from ht_smallarray to ht_smallarray! Happens when there + // are many removed items. Copy the items to be able to clean up + // removed items. mch_memmove(temparray, newarray, sizeof(temparray)); oldarray = temparray; - } else + } else { oldarray = ht->ht_array; - } else { - /* Allocate an array. */ - newarray = (hashitem_T *)alloc((unsigned) - (sizeof(hashitem_T) * newsize)); + } + } else { + // Allocate an array. + newarray = (hashitem_T *)alloc((unsigned)(sizeof(hashitem_T) * newsize)); + if (newarray == NULL) { - /* Out of memory. When there are NULL items still return OK. - * Otherwise set ht_error, because lookup may result in a hang if - * we add another item. */ - if (ht->ht_filled < ht->ht_mask) + // Out of memory. When there are NULL items still return OK. + // Otherwise set ht_error, because lookup may result in a hang if + // we add another item. + if (ht->ht_filled < ht->ht_mask) { return OK; + } ht->ht_error = TRUE; return FAIL; } @@ -334,36 +358,36 @@ hash_may_resize ( } vim_memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize)); - /* - * Move all the items from the old array to the new one, placing them in - * the right spot. The new array won't have any removed items, thus this - * is also a cleanup action. - */ + // Move all the items from the old array to the new one, placing them in + // the right spot. The new array won't have any removed items, thus this + // is also a cleanup action. newmask = newsize - 1; todo = (int)ht->ht_used; - for (olditem = oldarray; todo > 0; ++olditem) + + for (olditem = oldarray; todo > 0; ++olditem) { if (!HASHITEM_EMPTY(olditem)) { - /* - * The algorithm to find the spot to add the item is identical to - * the algorithm to find an item in hash_lookup(). But we only - * need to search for a NULL key, thus it's simpler. - */ + // The algorithm to find the spot to add the item is identical to + // the algorithm to find an item in hash_lookup(). But we only + // need to search for a NULL key, thus it's simpler. newi = (unsigned)(olditem->hi_hash & newmask); newitem = &newarray[newi]; - - if (newitem->hi_key != NULL) + if (newitem->hi_key != NULL) { for (perturb = olditem->hi_hash;; perturb >>= PERTURB_SHIFT) { newi = (unsigned)((newi << 2U) + newi + perturb + 1U); newitem = &newarray[newi & newmask]; - if (newitem->hi_key == NULL) + if (newitem->hi_key == NULL) { break; + } } + } *newitem = *olditem; - --todo; + todo--; } + } - if (ht->ht_array != ht->ht_smallarray) + if (ht->ht_array != ht->ht_smallarray) { vim_free(ht->ht_array); + } ht->ht_array = newarray; ht->ht_mask = newmask; ht->ht_filled = ht->ht_used; @@ -372,28 +396,31 @@ hash_may_resize ( return OK; } -/* - * Get the hash number for a key. - * If you think you know a better hash function: Compile with HT_DEBUG set and - * run a script that uses hashtables a lot. Vim will then print statistics - * when exiting. Try that with the current hash algorithm and yours. The - * lower the percentage the better. - */ +/// Get the hash number for a key. +/// If you think you know a better hash function: Compile with HT_DEBUG set and +/// run a script that uses hashtables a lot. Vim will then print statistics +/// when exiting. Try that with the current hash algorithm and yours. The +/// lower the percentage the better. +/// +/// @param key +/// +/// @return Hash number for the key. hash_T hash_hash(char_u *key) { hash_T hash; - char_u *p; + char_u *p; - if ((hash = *key) == 0) - return (hash_T)0; /* Empty keys are not allowed, but we don't - want to crash if we get one. */ + if ((hash = *key) == 0) { + // Empty keys are not allowed, but we don't want to crash if we get one. + return (hash_T) 0; + } p = key + 1; - /* A simplistic algorithm that appears to do very well. - * Suggested by George Reilly. */ - while (*p != NUL) + // A simplistic algorithm that appears to do very well. + // Suggested by George Reilly. + while (*p != NUL) { hash = hash * 101 + *p++; + } return hash; } - diff --git a/src/popupmnu.c b/src/popupmnu.c index 7ae9018e0c..a563095c95 100644 --- a/src/popupmnu.c +++ b/src/popupmnu.c @@ -1,15 +1,7 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * popupmnu.c: Popup menu (PUM) - */ +/// @file popupmnu.c +/// +/// Popup menu (PUM) +// #include "vim.h" #include "popupmnu.h" #include "charset.h" @@ -22,40 +14,36 @@ #include "search.h" #include "window.h" -static pumitem_T *pum_array = NULL; /* items of displayed pum */ -static int pum_size; /* nr of items in "pum_array" */ -static int pum_selected; /* index of selected item or -1 */ -static int pum_first = 0; /* index of top item */ +static pumitem_T *pum_array = NULL; // items of displayed pum +static int pum_size; // nr of items in "pum_array" +static int pum_selected; // index of selected item or -1 +static int pum_first = 0; // index of top item -static int pum_height; /* nr of displayed pum items */ -static int pum_width; /* width of displayed pum items */ -static int pum_base_width; /* width of pum items base */ -static int pum_kind_width; /* width of pum items kind column */ -static int pum_scrollbar; /* TRUE when scrollbar present */ +static int pum_height; // nr of displayed pum items +static int pum_width; // width of displayed pum items +static int pum_base_width; // width of pum items base +static int pum_kind_width; // width of pum items kind column +static int pum_scrollbar; // TRUE when scrollbar present -static int pum_row; /* top row of pum */ -static int pum_col; /* left column of pum */ +static int pum_row; // top row of pum +static int pum_col; // left column of pum -static int pum_do_redraw = FALSE; /* do redraw anyway */ +static int pum_do_redraw = FALSE; // do redraw anyway static int pum_set_selected(int n, int repeat); #define PUM_DEF_HEIGHT 10 #define PUM_DEF_WIDTH 15 -/* - * Show the popup menu with items "array[size]". - * "array" must remain valid until pum_undisplay() is called! - * When possible the leftmost character is aligned with screen column "col". - * The menu appears above the screen line "row" or at "row" + "height" - 1. - */ -void -pum_display ( - pumitem_T *array, - int size, - int selected /* index of initially selected item, none if - out of range */ -) +/// Show the popup menu with items "array[size]". +/// "array" must remain valid until pum_undisplay() is called! +/// When possible the leftmost character is aligned with screen column "col". +/// The menu appears above the screen line "row" or at "row" + "height" - 1. +/// +/// @param array +/// @param size +/// @param selected index of initially selected item, none if out of range +void pum_display(pumitem_T *array, int size, int selected) { int w; int def_width; @@ -76,46 +64,50 @@ redo: kind_width = 0; extra_width = 0; - /* Pretend the pum is already there to avoid that must_redraw is set when - * 'cuc' is on. */ + // Pretend the pum is already there to avoid that must_redraw is set when + // 'cuc' is on. pum_array = (pumitem_T *)1; validate_cursor_col(); pum_array = NULL; row = curwin->w_wrow + W_WINROW(curwin); - if (firstwin->w_p_pvw) + if (firstwin->w_p_pvw) { top_clear = firstwin->w_height; - else + } else { top_clear = 0; + } - /* When the preview window is at the bottom stop just above it. Also - * avoid drawing over the status line so that it's clear there is a window - * boundary. */ - if (lastwin->w_p_pvw) + // When the preview window is at the bottom stop just above it. Also + // avoid drawing over the status line so that it's clear there is a window + // boundary. + if (lastwin->w_p_pvw) { above_row -= lastwin->w_height + lastwin->w_status_height + 1; + } - /* - * Figure out the size and position of the pum. - */ - if (size < PUM_DEF_HEIGHT) + // Figure out the size and position of the pum. + if (size < PUM_DEF_HEIGHT) { pum_height = size; - else + } else { pum_height = PUM_DEF_HEIGHT; - if (p_ph > 0 && pum_height > p_ph) + } + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_height = p_ph; + } - /* Put the pum below "row" if possible. If there are few lines decide on - * where there is more room. */ - if (row + 2 >= above_row - pum_height - && row > (above_row - top_clear) / 2) { - /* pum above "row" */ + // Put the pum below "row" if possible. If there are few lines decide on + // where there is more room. + if ((row + 2 >= above_row - pum_height) + && (row > (above_row - top_clear) / 2)) { + // pum above "row" - /* Leave two lines of context if possible */ - if (curwin->w_wrow - curwin->w_cline_row >= 2) + // Leave two lines of context if possible + if (curwin->w_wrow - curwin->w_cline_row >= 2) { context_lines = 2; - else + } else { context_lines = curwin->w_wrow - curwin->w_cline_row; + } if (row >= size + context_lines) { pum_row = row - size - context_lines; @@ -124,125 +116,148 @@ redo: pum_row = 0; pum_height = row - context_lines; } - if (p_ph > 0 && pum_height > p_ph) { + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_row += pum_height - p_ph; pum_height = p_ph; } - } else { - /* pum below "row" */ + } else { + // pum below "row" - /* Leave two lines of context if possible */ - if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) + // Leave two lines of context if possible + if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3) { context_lines = 3; - else + } else { context_lines = curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow; + } pum_row = row + context_lines; - if (size > above_row - pum_row) + if (size > above_row - pum_row) { pum_height = above_row - pum_row; - else + } else { pum_height = size; - if (p_ph > 0 && pum_height > p_ph) + } + + if ((p_ph > 0) && (pum_height > p_ph)) { pum_height = p_ph; + } } - /* don't display when we only have room for one line */ - if (pum_height < 1 || (pum_height == 1 && size > 1)) + // don't display when we only have room for one line + if ((pum_height < 1) || ((pum_height == 1) && (size > 1))) { return; + } - /* If there is a preview window at the top avoid drawing over it. */ + // If there is a preview window at the top avoid drawing over it. if (firstwin->w_p_pvw - && pum_row < firstwin->w_height - && pum_height > firstwin->w_height + 4) { + && (pum_row < firstwin->w_height) + && (pum_height > firstwin->w_height + 4)) { pum_row += firstwin->w_height; pum_height -= firstwin->w_height; } - /* Compute the width of the widest match and the widest extra. */ + // Compute the width of the widest match and the widest extra. for (i = 0; i < size; ++i) { w = vim_strsize(array[i].pum_text); - if (max_width < w) + + if (max_width < w) { max_width = w; + } + if (array[i].pum_kind != NULL) { w = vim_strsize(array[i].pum_kind) + 1; - if (kind_width < w) + + if (kind_width < w) { kind_width = w; + } } + if (array[i].pum_extra != NULL) { w = vim_strsize(array[i].pum_extra) + 1; - if (extra_width < w) + + if (extra_width < w) { extra_width = w; + } } } pum_base_width = max_width; pum_kind_width = kind_width; - /* Calculate column */ - if (curwin->w_p_rl) + // Calculate column + if (curwin->w_p_rl) { col = W_WINCOL(curwin) + W_WIDTH(curwin) - curwin->w_wcol - 1; - else + } else { col = W_WINCOL(curwin) + curwin->w_wcol; + } - /* if there are more items than room we need a scrollbar */ + // if there are more items than room we need a scrollbar if (pum_height < size) { pum_scrollbar = 1; - ++max_width; - } else + max_width++; + } else { pum_scrollbar = 0; + } - if (def_width < max_width) + if (def_width < max_width) { def_width = max_width; + } - if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width) + if ((((col < Columns - PUM_DEF_WIDTH) || (col < Columns - max_width)) && !curwin->w_p_rl) - || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width) - )) { - /* align pum column with "col" */ + || (curwin->w_p_rl && ((col > PUM_DEF_WIDTH) || (col > max_width)))) { + // align pum column with "col" pum_col = col; - - if (curwin->w_p_rl) + if (curwin->w_p_rl) { pum_width = pum_col - pum_scrollbar + 1; - else + } else { pum_width = Columns - pum_col - pum_scrollbar; + } - if (pum_width > max_width + kind_width + extra_width + 1 - && pum_width > PUM_DEF_WIDTH) { + if ((pum_width > max_width + kind_width + extra_width + 1) + && (pum_width > PUM_DEF_WIDTH)) { pum_width = max_width + kind_width + extra_width + 1; - if (pum_width < PUM_DEF_WIDTH) + + if (pum_width < PUM_DEF_WIDTH) { pum_width = PUM_DEF_WIDTH; + } } - } else if (Columns < def_width) { - /* not enough room, will use what we have */ - if (curwin->w_p_rl) + } else if (Columns < def_width) { + // not enough room, will use what we have + if (curwin->w_p_rl) { pum_col = Columns - 1; - else + } else { pum_col = 0; + } pum_width = Columns - 1; - } else { - if (max_width > PUM_DEF_WIDTH) - max_width = PUM_DEF_WIDTH; /* truncate */ - if (curwin->w_p_rl) + } else { + if (max_width > PUM_DEF_WIDTH) { + // truncate + max_width = PUM_DEF_WIDTH; + } + + if (curwin->w_p_rl) { pum_col = max_width - 1; - else + } else { pum_col = Columns - max_width; + } pum_width = max_width - pum_scrollbar; } pum_array = array; pum_size = size; - /* Set selected item and redraw. If the window size changed need to redo - * the positioning. Limit this to two times, when there is not much - * room the window size will keep changing. */ - if (pum_set_selected(selected, redo_count) && ++redo_count <= 2) + // Set selected item and redraw. If the window size changed need to redo + // the positioning. Limit this to two times, when there is not much + // room the window size will keep changing. + if (pum_set_selected(selected, redo_count) && (++redo_count <= 2)) { goto redo; + } } -/* - * Redraw the popup menu, using "pum_first" and "pum_selected". - */ -void pum_redraw(void) { +/// Redraw the popup menu, using "pum_first" and "pum_selected". +void pum_redraw(void) +{ int row = pum_row; int col; int attr_norm = highlight_attr[HLF_PNI]; @@ -252,22 +267,24 @@ void pum_redraw(void) { int attr; int i; int idx; - char_u *s; - char_u *p = NULL; + char_u *s; + char_u *p = NULL; int totwidth, width, w; int thumb_pos = 0; int thumb_heigth = 1; int round; int n; - /* Never display more than we have */ - if (pum_first > pum_size - pum_height) + // Never display more than we have + if (pum_first > pum_size - pum_height) { pum_first = pum_size - pum_height; + } if (pum_scrollbar) { thumb_heigth = pum_height * pum_height / pum_size; - if (thumb_heigth == 0) + if (thumb_heigth == 0) { thumb_heigth = 1; + } thumb_pos = (pum_first * (pum_height - thumb_heigth) + (pum_size - pum_height) / 2) / (pum_size - pum_height); @@ -277,155 +294,179 @@ void pum_redraw(void) { idx = i + pum_first; attr = (idx == pum_selected) ? attr_select : attr_norm; - /* prepend a space if there is room */ + // prepend a space if there is room if (curwin->w_p_rl) { - if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) + if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1) { screen_putchar(' ', row, pum_col + 1, attr); - } else if (pum_col > 0) + } + } else if (pum_col > 0) { screen_putchar(' ', row, pum_col - 1, attr); + } - /* Display each entry, use two spaces for a Tab. - * Do this 3 times: For the main text, kind and extra info */ + // Display each entry, use two spaces for a Tab. + // Do this 3 times: For the main text, kind and extra info col = pum_col; totwidth = 0; + for (round = 1; round <= 3; ++round) { width = 0; s = NULL; + switch (round) { - case 1: p = pum_array[idx].pum_text; break; - case 2: p = pum_array[idx].pum_kind; break; - case 3: p = pum_array[idx].pum_extra; break; + case 1: + p = pum_array[idx].pum_text; + break; + + case 2: + p = pum_array[idx].pum_kind; + break; + + case 3: + p = pum_array[idx].pum_extra; + break; } - if (p != NULL) + + if (p != NULL) { for (;; mb_ptr_adv(p)) { - if (s == NULL) + if (s == NULL) { s = p; + } w = ptr2cells(p); - if (*p == NUL || *p == TAB || totwidth + w > pum_width) { - /* Display the text that fits or comes before a Tab. - * First convert it to printable characters. */ - char_u *st; + + if ((*p == NUL) || (*p == TAB) || (totwidth + w > pum_width)) { + // Display the text that fits or comes before a Tab. + // First convert it to printable characters. + char_u *st; int saved = *p; *p = NUL; st = transstr(s); *p = saved; + if (curwin->w_p_rl) { if (st != NULL) { char_u *rt = reverse_text(st); if (rt != NULL) { - char_u *rt_start = rt; + char_u *rt_start = rt; int size; size = vim_strsize(rt); + if (size > pum_width) { do { - size -= has_mbyte - ? (*mb_ptr2cells)(rt) : 1; + size -= has_mbyte ? (*mb_ptr2cells)(rt) : 1; mb_ptr_adv(rt); } while (size > pum_width); if (size < pum_width) { - /* Most left character requires - * 2-cells but only 1 cell is - * available on screen. Put a - * '<' on the left of the pum - * item */ + // Most left character requires 2-cells but only 1 cell + // is available on screen. Put a '<' on the left of the + // pum item *(--rt) = '<'; size++; } } - screen_puts_len(rt, (int)STRLEN(rt), - row, col - size + 1, attr); + screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, + attr); vim_free(rt_start); } vim_free(st); } col -= width; - } else { + } else { if (st != NULL) { - screen_puts_len(st, (int)STRLEN(st), row, col, - attr); + screen_puts_len(st, (int)STRLEN(st), row, col, attr); vim_free(st); } col += width; } - if (*p != TAB) + if (*p != TAB) { break; + } - /* Display two spaces for a Tab. */ + // Display two spaces for a Tab. if (curwin->w_p_rl) { - screen_puts_len((char_u *)" ", 2, row, col - 1, - attr); + screen_puts_len((char_u *)" ", 2, row, col - 1, attr); col -= 2; } else { screen_puts_len((char_u *)" ", 2, row, col, attr); col += 2; } totwidth += 2; - s = NULL; /* start text at next char */ + // start text at next char + s = NULL; width = 0; - } else + } else { width += w; + } } + } - if (round > 1) + if (round > 1) { n = pum_kind_width + 1; - else + } else { n = 1; + } - /* Stop when there is nothing more to display. */ - if (round == 3 - || (round == 2 && pum_array[idx].pum_extra == NULL) - || (round == 1 && pum_array[idx].pum_kind == NULL - && pum_array[idx].pum_extra == NULL) - || pum_base_width + n >= pum_width) + // Stop when there is nothing more to display. + if ((round == 3) + || ((round == 2) + && (pum_array[idx].pum_extra == NULL)) + || ((round == 1) + && (pum_array[idx].pum_kind == NULL) + && (pum_array[idx].pum_extra == NULL)) + || (pum_base_width + n >= pum_width)) { break; + } + if (curwin->w_p_rl) { screen_fill(row, row + 1, pum_col - pum_base_width - n + 1, - col + 1, ' ', ' ', attr); + col + 1, ' ', ' ', attr); col = pum_col - pum_base_width - n + 1; } else { screen_fill(row, row + 1, col, pum_col + pum_base_width + n, - ' ', ' ', attr); + ' ', ' ', attr); col = pum_col + pum_base_width + n; } totwidth = pum_base_width + n; } - if (curwin->w_p_rl) - screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', - ' ', attr); - else - screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', - attr); + if (curwin->w_p_rl) { + screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ', ' ', + attr); + } else { + screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr); + } + if (pum_scrollbar > 0) { - if (curwin->w_p_rl) + if (curwin->w_p_rl) { screen_putchar(' ', row, pum_col - pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth - ? attr_thumb : attr_scroll); - else + i >= thumb_pos && i < thumb_pos + thumb_heigth + ? attr_thumb : attr_scroll); + } else { screen_putchar(' ', row, pum_col + pum_width, - i >= thumb_pos && i < thumb_pos + thumb_heigth - ? attr_thumb : attr_scroll); + i >= thumb_pos && i < thumb_pos + thumb_heigth + ? attr_thumb : attr_scroll); + } } - - ++row; + row++; } } -/* - * Set the index of the currently selected item. The menu will scroll when - * necessary. When "n" is out of range don't scroll. - * This may be repeated when the preview window is used: - * "repeat" == 0: open preview window normally - * "repeat" == 1: open preview window but don't set the size - * "repeat" == 2: don't open preview window - * Returns TRUE when the window was resized and the location of the popup menu - * must be recomputed. - */ +/// Set the index of the currently selected item. The menu will scroll when +/// necessary. When "n" is out of range don't scroll. +/// This may be repeated when the preview window is used: +/// "repeat" == 0: open preview window normally +/// "repeat" == 1: open preview window but don't set the size +/// "repeat" == 2: don't open preview window +/// +/// @param n +/// @param repeat +/// +/// @returns TRUE when the window was resized and the location of the popup +/// menu must be recomputed. static int pum_set_selected(int n, int repeat) { int resized = FALSE; @@ -433,100 +474,112 @@ static int pum_set_selected(int n, int repeat) pum_selected = n; - if (pum_selected >= 0 && pum_selected < pum_size) { + if ((pum_selected >= 0) && (pum_selected < pum_size)) { if (pum_first > pum_selected - 4) { - /* scroll down; when we did a jump it's probably a PageUp then - * scroll a whole page */ + // scroll down; when we did a jump it's probably a PageUp then + // scroll a whole page if (pum_first > pum_selected - 2) { pum_first -= pum_height - 2; - if (pum_first < 0) + if (pum_first < 0) { pum_first = 0; - else if (pum_first > pum_selected) + } else if (pum_first > pum_selected) { pum_first = pum_selected; - } else + } + } else { pum_first = pum_selected; - } else if (pum_first < pum_selected - pum_height + 5) { - /* scroll up; when we did a jump it's probably a PageDown then - * scroll a whole page */ + } + } else if (pum_first < pum_selected - pum_height + 5) { + // scroll up; when we did a jump it's probably a PageDown then + // scroll a whole page if (pum_first < pum_selected - pum_height + 1 + 2) { pum_first += pum_height - 2; - if (pum_first < pum_selected - pum_height + 1) + if (pum_first < pum_selected - pum_height + 1) { pum_first = pum_selected - pum_height + 1; - } else + } + } else { pum_first = pum_selected - pum_height + 1; + } } - /* Give a few lines of context when possible. */ - if (context > 3) + // Give a few lines of context when possible. + if (context > 3) { context = 3; + } + if (pum_height > 2) { if (pum_first > pum_selected - context) { - /* scroll down */ + // scroll down pum_first = pum_selected - context; - if (pum_first < 0) + + if (pum_first < 0) { pum_first = 0; - } else if (pum_first < pum_selected + context - pum_height + 1) { - /* scroll up */ + } + } else if (pum_first < pum_selected + context - pum_height + 1) { + // scroll up pum_first = pum_selected + context - pum_height + 1; } } - /* - * Show extra info in the preview window if there is something and - * 'completeopt' contains "preview". - * Skip this when tried twice already. - * Skip this also when there is not much room. - * NOTE: Be very careful not to sync undo! - */ - if (pum_array[pum_selected].pum_info != NULL - && Rows > 10 - && repeat <= 1 - && vim_strchr(p_cot, 'p') != NULL) { - win_T *curwin_save = curwin; + // Show extra info in the preview window if there is something and + // 'completeopt' contains "preview". + // Skip this when tried twice already. + // Skip this also when there is not much room. + // NOTE: Be very careful not to sync undo! + if ((pum_array[pum_selected].pum_info != NULL) + && (Rows > 10) + && (repeat <= 1) + && (vim_strchr(p_cot, 'p') != NULL)) { + win_T *curwin_save = curwin; int res = OK; - /* Open a preview window. 3 lines by default. Prefer - * 'previewheight' if set and smaller. */ + // Open a preview window. 3 lines by default. Prefer + // 'previewheight' if set and smaller. g_do_tagpreview = 3; - if (p_pvh > 0 && p_pvh < g_do_tagpreview) + + if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) { g_do_tagpreview = p_pvh; + } resized = prepare_tagpreview(FALSE); g_do_tagpreview = 0; if (curwin->w_p_pvw) { - if (curbuf->b_fname == NULL - && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f' - && curbuf->b_p_bh[0] == 'w') { - /* Already a "wipeout" buffer, make it empty. */ - while (!bufempty()) + if ((curbuf->b_fname == NULL) + && (curbuf->b_p_bt[0] == 'n') + && (curbuf->b_p_bt[2] == 'f') + && (curbuf->b_p_bh[0] == 'w')) { + // Already a "wipeout" buffer, make it empty. + while (!bufempty()) { ml_delete((linenr_T)1, FALSE); - } else { - /* Don't want to sync undo in the current buffer. */ - ++no_u_sync; + } + } else { + // Don't want to sync undo in the current buffer. + no_u_sync++; res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); - --no_u_sync; + no_u_sync--; + if (res == OK) { - /* Edit a new, empty buffer. Set options for a "wipeout" - * buffer. */ + // Edit a new, empty buffer. Set options for a "wipeout" + // buffer. set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); set_option_value((char_u *)"bt", 0L, - (char_u *)"nofile", OPT_LOCAL); + (char_u *)"nofile", OPT_LOCAL); set_option_value((char_u *)"bh", 0L, - (char_u *)"wipe", OPT_LOCAL); + (char_u *)"wipe", OPT_LOCAL); set_option_value((char_u *)"diff", 0L, - NULL, OPT_LOCAL); + NULL, OPT_LOCAL); } } + if (res == OK) { - char_u *p, *e; + char_u *p, *e; linenr_T lnum = 0; - for (p = pum_array[pum_selected].pum_info; *p != NUL; ) { + for (p = pum_array[pum_selected].pum_info; *p != NUL;) { e = vim_strchr(p, '\n'); if (e == NULL) { ml_append(lnum++, p, 0, FALSE); break; - } else { + } else { *e = NUL; ml_append(lnum++, p, (int)(e - p + 1), FALSE); *e = '\n'; @@ -534,11 +587,13 @@ static int pum_set_selected(int n, int repeat) } } - /* Increase the height of the preview window to show the - * text, but no more than 'previewheight' lines. */ + // Increase the height of the preview window to show the + // text, but no more than 'previewheight' lines. if (repeat == 0) { - if (lnum > p_pvh) + if (lnum > p_pvh) { lnum = p_pvh; + } + if (curwin->w_height < lnum) { win_setheight((int)lnum); resized = TRUE; @@ -550,31 +605,32 @@ static int pum_set_selected(int n, int repeat) curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; - if (curwin != curwin_save && win_valid(curwin_save)) { - /* Return cursor to where we were */ + if ((curwin != curwin_save) && win_valid(curwin_save)) { + // Return cursor to where we were validate_cursor(); redraw_later(SOME_VALID); - /* When the preview window was resized we need to - * update the view on the buffer. Only go back to - * the window when needed, otherwise it will always be - * redraw. */ + // When the preview window was resized we need to + // update the view on the buffer. Only go back to + // the window when needed, otherwise it will always be + // redraw. if (resized) { win_enter(curwin_save, TRUE); update_topline(); } - /* Update the screen before drawing the popup menu. - * Enable updating the status lines. */ + // Update the screen before drawing the popup menu. + // Enable updating the status lines. pum_do_redraw = TRUE; update_screen(0); pum_do_redraw = FALSE; - if (!resized && win_valid(curwin_save)) + if (!resized && win_valid(curwin_save)) { win_enter(curwin_save, TRUE); + } - /* May need to update the screen again when there are - * autocommands involved. */ + // May need to update the screen again when there are + // autocommands involved. pum_do_redraw = TRUE; update_screen(0); pum_do_redraw = FALSE; @@ -584,43 +640,42 @@ static int pum_set_selected(int n, int repeat) } } - if (!resized) + if (!resized) { pum_redraw(); + } return resized; } -/* - * Undisplay the popup menu (later). - */ -void pum_undisplay(void) { +/// Undisplay the popup menu (later). +void pum_undisplay(void) +{ pum_array = NULL; redraw_all_later(SOME_VALID); redraw_tabline = TRUE; status_redraw_all(); } -/* - * Clear the popup menu. Currently only resets the offset to the first - * displayed item. - */ -void pum_clear(void) { +/// Clear the popup menu. Currently only resets the offset to the first +/// displayed item. +void pum_clear(void) +{ pum_first = 0; } -/* - * Return TRUE if the popup menu is displayed. - * Overruled when "pum_do_redraw" is set, used to redraw the status lines. - */ -int pum_visible(void) { +/// Overruled when "pum_do_redraw" is set, used to redraw the status lines. +/// +/// @return TRUE if the popup menu is displayed. +int pum_visible(void) +{ return !pum_do_redraw && pum_array != NULL; } -/* - * Return the height of the popup menu, the number of entries visible. - * Only valid when pum_visible() returns TRUE! - */ -int pum_get_height(void) { +/// Gets the height of the menu. +/// +/// @return the height of the popup menu, the number of entries visible. +/// Only valid when pum_visible() returns TRUE! +int pum_get_height(void) +{ return pum_height; } - diff --git a/src/popupmnu.h b/src/popupmnu.h index 26d0df439a..2010492845 100644 --- a/src/popupmnu.h +++ b/src/popupmnu.h @@ -1,14 +1,12 @@ #ifndef NEOVIM_POPUPMNU_H #define NEOVIM_POPUPMNU_H -/* - * Used for popup menu items. - */ +/// Used for popup menu items. typedef struct { - char_u *pum_text; /* main menu text */ - char_u *pum_kind; /* extra kind text (may be truncated) */ - char_u *pum_extra; /* extra menu text (may be truncated) */ - char_u *pum_info; /* extra info */ + char_u *pum_text; // main menu text + char_u *pum_kind; // extra kind text (may be truncated) + char_u *pum_extra; // extra menu text (may be truncated) + char_u *pum_info; // extra info } pumitem_T; void pum_display(pumitem_T *array, int size, int selected); @@ -17,5 +15,6 @@ void pum_undisplay(void); void pum_clear(void); int pum_visible(void); int pum_get_height(void); -/* vim: set ft=c : */ -#endif /* NEOVIM_POPUPMNU_H */ + +// vim: set ft=c: +#endif // NEOVIM_POPUPMNU_H diff --git a/src/sha256.c b/src/sha256.c index 1a3216fc17..1670221929 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -1,45 +1,36 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - * - * FIPS-180-2 compliant SHA-256 implementation - * GPL by Christophe Devine, applies to older version. - * Modified for md5deep, in public domain. - * Modified For Vim, Mohsin Ahmed, http://www.cs.albany.edu/~mosh - * Mohsin Ahmed states this work is distributed under the VIM License or GPL, - * at your choice. - * - * Vim specific notes: - * Functions exported by this file: - * 1. sha256_key() hashes the password to 64 bytes char string. - * 2. sha2_seed() generates a random header. - * sha256_self_test() is implicitly called once. - */ +/// @file sha256.c +/// +/// FIPS-180-2 compliant SHA-256 implementation +/// GPL by Christophe Devine, applies to older version. +/// Modified for md5deep, in public domain. +/// Modified For Vim, Mohsin Ahmed, http://www.cs.albany.edu/~mosh +/// Mohsin Ahmed states this work is distributed under the VIM License or GPL, +/// at your choice. +/// +/// Vim specific notes: +/// Functions exported by this file: +/// 1. sha256_key() hashes the password to 64 bytes char string. +/// 2. sha2_seed() generates a random header. +/// sha256_self_test() is implicitly called once. #include "vim.h" #include "sha256.h" static void sha256_process(context_sha256_T *ctx, char_u data[64]); -#define GET_UINT32(n, b, i) \ - { \ - (n) = ( (uint32_t)(b)[(i) ] << 24) \ - | ( (uint32_t)(b)[(i) + 1] << 16) \ - | ( (uint32_t)(b)[(i) + 2] << 8) \ - | ( (uint32_t)(b)[(i) + 3] ); \ - } +#define GET_UINT32(n, b, i) { \ + (n) = ((uint32_t)(b)[(i)] << 24) \ + | ((uint32_t)(b)[(i) + 1] << 16) \ + | ((uint32_t)(b)[(i) + 2] << 8) \ + | ((uint32_t)(b)[(i) + 3]); \ +} -#define PUT_UINT32(n,b,i) \ - { \ - (b)[(i) ] = (char_u)((n) >> 24); \ - (b)[(i) + 1] = (char_u)((n) >> 16); \ - (b)[(i) + 2] = (char_u)((n) >> 8); \ - (b)[(i) + 3] = (char_u)((n) ); \ - } +#define PUT_UINT32(n, b, i) { \ + (b)[(i)] = (char_u)((n) >> 24); \ + (b)[(i) + 1] = (char_u)((n) >> 16); \ + (b)[(i) + 2] = (char_u)((n) >> 8); \ + (b)[(i) + 3] = (char_u)((n)); \ +} void sha256_start(context_sha256_T *ctx) { @@ -90,18 +81,15 @@ static void sha256_process(context_sha256_T *ctx, char_u data[64]) #define F0(x, y, z) ((x & y) | (z & (x | y))) #define F1(x, y, z) (z ^ (x & (y ^ z))) -#define R(t) \ - ( \ - W[t] = S1(W[t - 2]) + W[t - 7] + \ - S0(W[t - 15]) + W[t - 16] \ - ) - -#define P(a,b,c,d,e,f,g,h,x,K) \ - { \ - temp1 = h + S3(e) + F1(e, f, g) + K + x; \ - temp2 = S2(a) + F0(a, b, c); \ - d += temp1; h = temp1 + temp2; \ - } +#define R(t) \ + (W[t] = S1(W[t - 2]) + W[t - 7] + \ + S0(W[t - 15]) + W[t - 16]) + +#define P(a, b, c, d, e, f, g, h, x, K) { \ + temp1 = h + S3(e) + F1(e, f, g) + K + x; \ + temp2 = S2(a) + F0(a, b, c); \ + d += temp1; h = temp1 + temp2; \ +} A = ctx->state[0]; B = ctx->state[1]; @@ -112,70 +100,70 @@ static void sha256_process(context_sha256_T *ctx, char_u data[64]) G = ctx->state[6]; H = ctx->state[7]; - P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98); - P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491); - P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF); - P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5); - P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B); - P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1); - P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4); - P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5); - P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98); - P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01); - P( G, H, A, B, C, D, E, F, W[10], 0x243185BE); - P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3); - P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74); - P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE); - P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7); - P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174); - P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1); - P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786); - P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6); - P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC); - P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F); - P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA); - P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC); - P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA); - P( A, B, C, D, E, F, G, H, R(24), 0x983E5152); - P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D); - P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8); - P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7); - P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3); - P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147); - P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351); - P( B, C, D, E, F, G, H, A, R(31), 0x14292967); - P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85); - P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138); - P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC); - P( F, G, H, A, B, C, D, E, R(35), 0x53380D13); - P( E, F, G, H, A, B, C, D, R(36), 0x650A7354); - P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB); - P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E); - P( B, C, D, E, F, G, H, A, R(39), 0x92722C85); - P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1); - P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B); - P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70); - P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3); - P( E, F, G, H, A, B, C, D, R(44), 0xD192E819); - P( D, E, F, G, H, A, B, C, R(45), 0xD6990624); - P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585); - P( B, C, D, E, F, G, H, A, R(47), 0x106AA070); - P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116); - P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08); - P( G, H, A, B, C, D, E, F, R(50), 0x2748774C); - P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5); - P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3); - P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A); - P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F); - P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3); - P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE); - P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F); - P( G, H, A, B, C, D, E, F, R(58), 0x84C87814); - P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208); - P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA); - P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB); - P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7); - P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2); + P(A, B, C, D, E, F, G, H, W[0], 0x428A2F98); + P(H, A, B, C, D, E, F, G, W[1], 0x71374491); + P(G, H, A, B, C, D, E, F, W[2], 0xB5C0FBCF); + P(F, G, H, A, B, C, D, E, W[3], 0xE9B5DBA5); + P(E, F, G, H, A, B, C, D, W[4], 0x3956C25B); + P(D, E, F, G, H, A, B, C, W[5], 0x59F111F1); + P(C, D, E, F, G, H, A, B, W[6], 0x923F82A4); + P(B, C, D, E, F, G, H, A, W[7], 0xAB1C5ED5); + P(A, B, C, D, E, F, G, H, W[8], 0xD807AA98); + P(H, A, B, C, D, E, F, G, W[9], 0x12835B01); + P(G, H, A, B, C, D, E, F, W[10], 0x243185BE); + P(F, G, H, A, B, C, D, E, W[11], 0x550C7DC3); + P(E, F, G, H, A, B, C, D, W[12], 0x72BE5D74); + P(D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE); + P(C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7); + P(B, C, D, E, F, G, H, A, W[15], 0xC19BF174); + P(A, B, C, D, E, F, G, H, R(16), 0xE49B69C1); + P(H, A, B, C, D, E, F, G, R(17), 0xEFBE4786); + P(G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6); + P(F, G, H, A, B, C, D, E, R(19), 0x240CA1CC); + P(E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F); + P(D, E, F, G, H, A, B, C, R(21), 0x4A7484AA); + P(C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC); + P(B, C, D, E, F, G, H, A, R(23), 0x76F988DA); + P(A, B, C, D, E, F, G, H, R(24), 0x983E5152); + P(H, A, B, C, D, E, F, G, R(25), 0xA831C66D); + P(G, H, A, B, C, D, E, F, R(26), 0xB00327C8); + P(F, G, H, A, B, C, D, E, R(27), 0xBF597FC7); + P(E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3); + P(D, E, F, G, H, A, B, C, R(29), 0xD5A79147); + P(C, D, E, F, G, H, A, B, R(30), 0x06CA6351); + P(B, C, D, E, F, G, H, A, R(31), 0x14292967); + P(A, B, C, D, E, F, G, H, R(32), 0x27B70A85); + P(H, A, B, C, D, E, F, G, R(33), 0x2E1B2138); + P(G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC); + P(F, G, H, A, B, C, D, E, R(35), 0x53380D13); + P(E, F, G, H, A, B, C, D, R(36), 0x650A7354); + P(D, E, F, G, H, A, B, C, R(37), 0x766A0ABB); + P(C, D, E, F, G, H, A, B, R(38), 0x81C2C92E); + P(B, C, D, E, F, G, H, A, R(39), 0x92722C85); + P(A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1); + P(H, A, B, C, D, E, F, G, R(41), 0xA81A664B); + P(G, H, A, B, C, D, E, F, R(42), 0xC24B8B70); + P(F, G, H, A, B, C, D, E, R(43), 0xC76C51A3); + P(E, F, G, H, A, B, C, D, R(44), 0xD192E819); + P(D, E, F, G, H, A, B, C, R(45), 0xD6990624); + P(C, D, E, F, G, H, A, B, R(46), 0xF40E3585); + P(B, C, D, E, F, G, H, A, R(47), 0x106AA070); + P(A, B, C, D, E, F, G, H, R(48), 0x19A4C116); + P(H, A, B, C, D, E, F, G, R(49), 0x1E376C08); + P(G, H, A, B, C, D, E, F, R(50), 0x2748774C); + P(F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5); + P(E, F, G, H, A, B, C, D, R(52), 0x391C0CB3); + P(D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A); + P(C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F); + P(B, C, D, E, F, G, H, A, R(55), 0x682E6FF3); + P(A, B, C, D, E, F, G, H, R(56), 0x748F82EE); + P(H, A, B, C, D, E, F, G, R(57), 0x78A5636F); + P(G, H, A, B, C, D, E, F, R(58), 0x84C87814); + P(F, G, H, A, B, C, D, E, R(59), 0x8CC70208); + P(E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA); + P(D, E, F, G, H, A, B, C, R(61), 0xA4506CEB); + P(C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7); + P(B, C, D, E, F, G, H, A, R(63), 0xC67178F2); ctx->state[0] += A; ctx->state[1] += B; @@ -191,8 +179,9 @@ void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length) { uint32_t left, fill; - if (length == 0) + if (length == 0) { return; + } left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -200,10 +189,11 @@ void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length) ctx->total[0] += length; ctx->total[0] &= 0xFFFFFFFF; - if (ctx->total[0] < length) + if (ctx->total[0] < length) { ctx->total[1]++; + } - if (left && length >= fill) { + if (left && (length >= fill)) { memcpy((void *)(ctx->buffer + left), (void *)input, fill); sha256_process(ctx, ctx->buffer); length -= fill; @@ -217,8 +207,9 @@ void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length) input += 64; } - if (length) + if (length) { memcpy((void *)(ctx->buffer + left), (void *)input, length); + } } static char_u sha256_padding[64] = { @@ -244,7 +235,7 @@ void sha256_finish(context_sha256_T *ctx, char_u digest[32]) padn = (last < 56) ? (56 - last) : (120 - last); sha256_update(ctx, sha256_padding, padn); - sha256_update(ctx, msglen, 8); + sha256_update(ctx, msglen, 8); PUT_UINT32(ctx->state[0], digest, 0); PUT_UINT32(ctx->state[1], digest, 4); @@ -258,10 +249,15 @@ void sha256_finish(context_sha256_T *ctx, char_u digest[32]) static unsigned int get_some_time(void); -/* - * Returns hex digest of "buf[buf_len]" in a static array. - * if "salt" is not NULL also do "salt[salt_len]". - */ +/// Gets the hex digest of the buffer. +/// +/// @param buf +/// @param buf_len +/// @param salt +/// @param salt_len +/// +/// @returns hex digest of "buf[buf_len]" in a static array. +/// if "salt" is not NULL also do "salt[salt_len]". char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len) { char_u sha256sum[32]; @@ -272,32 +268,38 @@ char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len) sha256_self_test(); sha256_start(&ctx); - sha256_update(&ctx, buf, buf_len); - if (salt != NULL) + sha256_update(&ctx, buf, buf_len); + + if (salt != NULL) { sha256_update(&ctx, salt, salt_len); + } sha256_finish(&ctx, sha256sum); - for (j = 0; j < 32; j++) - sprintf((char *)hexit + j * 2, "%02x", sha256sum[j]); + + for (j = 0; j < 32; j++) { + sprintf((char *) hexit + j * 2, "%02x", sha256sum[j]); + } hexit[sizeof(hexit) - 1] = '\0'; return hexit; } -/* - * Returns sha256(buf) as 64 hex chars in static array. - */ -char_u *sha256_key(char_u *buf, char_u *salt, int salt_len) +/// Gets sha256(buf) as 64 hex characters in a static array. +/// +/// @param buf +/// @param salt +/// @param salt_len +/// +/// @returns sha256(buf) as 64 hex chars in static array. +char_u* sha256_key(char_u *buf, char_u *salt, int salt_len) { - /* No passwd means don't encrypt */ - if (buf == NULL || *buf == NUL) + // No passwd means don't encrypt + if ((buf == NULL) || (*buf == NUL)) { return (char_u *)""; + } return sha256_bytes(buf, (int)STRLEN(buf), salt, salt_len); } -/* - * These are the standard FIPS-180-2 test vectors - */ - +// These are the standard FIPS-180-2 test vectors static char *sha_self_test_msg[] = { "abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", @@ -313,86 +315,102 @@ static char *sha_self_test_vector[] = { "f1809a48a497200e046d39ccc7112cd0" }; -/* - * Perform a test on the SHA256 algorithm. - * Return FAIL or OK. - */ -int sha256_self_test(void) { +/// Perform a test on the SHA256 algorithm. +/// +/// @return FAIL or OK. +int sha256_self_test(void) +{ int i, j; char output[65]; context_sha256_T ctx; char_u buf[1000]; char_u sha256sum[32]; static int failures = 0; - char_u *hexit; + char_u *hexit; static int sha256_self_tested = 0; - if (sha256_self_tested > 0) + if (sha256_self_tested > 0) { return failures > 0 ? FAIL : OK; + } sha256_self_tested = 1; for (i = 0; i < 3; i++) { if (i < 2) { - hexit = sha256_bytes((char_u *)sha_self_test_msg[i], - (int)STRLEN(sha_self_test_msg[i]), - NULL, 0); + hexit = sha256_bytes((char_u *) sha_self_test_msg[i], + (int) STRLEN(sha_self_test_msg[i]), + NULL, 0); STRCPY(output, hexit); - } else { + } else { sha256_start(&ctx); vim_memset(buf, 'a', 1000); - for (j = 0; j < 1000; j++) - sha256_update(&ctx, (char_u *)buf, 1000); + + for (j = 0; j < 1000; j++) { + sha256_update(&ctx, (char_u *) buf, 1000); + } sha256_finish(&ctx, sha256sum); - for (j = 0; j < 32; j++) + + for (j = 0; j < 32; j++) { sprintf(output + j * 2, "%02x", sha256sum[j]); + } } + if (memcmp(output, sha_self_test_vector[i], 64)) { failures++; output[sizeof(output) - 1] = '\0'; - /* printf("sha256_self_test %d failed %s\n", i, output); */ + + // printf("sha256_self_test %d failed %s\n", i, output); } } return failures > 0 ? FAIL : OK; } -static unsigned int get_some_time(void) { -# ifdef HAVE_GETTIMEOFDAY +static unsigned int get_some_time(void) +{ +#ifdef HAVE_GETTIMEOFDAY struct timeval tv; - /* Using usec makes it less predictable. */ + // Using usec makes it less predictable. gettimeofday(&tv, NULL); - return (unsigned int)(tv.tv_sec + tv.tv_usec); -# else - return (unsigned int)time(NULL); -# endif + return (unsigned int) (tv.tv_sec + tv.tv_usec); + +#else // ifdef HAVE_GETTIMEOFDAY + return (unsigned int) time(NULL); + +#endif // ifdef HAVE_GETTIMEOFDAY } -/* - * Fill "header[header_len]" with random_data. - * Also "salt[salt_len]" when "salt" is not NULL. - */ +/// Fill "header[header_len]" with random_data. +/// Also "salt[salt_len]" when "salt" is not NULL. +/// +/// @param header +/// @param header_len +/// @param salt +/// @param salt_len void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len) { - int i; static char_u random_data[1000]; char_u sha256sum[32]; context_sha256_T ctx; srand(get_some_time()); - for (i = 0; i < (int)sizeof(random_data) - 1; i++) - random_data[i] = (char_u)((get_some_time() ^ rand()) & 0xff); + int i; + for (i = 0; i < (int) sizeof(random_data) - 1; i++) { + random_data[i] = (char_u) ((get_some_time() ^ rand()) & 0xff); + } sha256_start(&ctx); - sha256_update(&ctx, (char_u *)random_data, sizeof(random_data)); + sha256_update(&ctx, (char_u *) random_data, sizeof(random_data)); sha256_finish(&ctx, sha256sum); - /* put first block into header. */ - for (i = 0; i < header_len; i++) + // put first block into header. + for (i = 0; i < header_len; i++) { header[i] = sha256sum[i % sizeof(sha256sum)]; + } - /* put remaining block into salt. */ - if (salt != NULL) - for (i = 0; i < salt_len; i++) + // put remaining block into salt. + if (salt != NULL) { + for (i = 0; i < salt_len; i++) { salt[i] = sha256sum[(i + header_len) % sizeof(sha256sum)]; + } + } } - diff --git a/src/sha256.h b/src/sha256.h index 5501e468d1..7f84ec16b3 100644 --- a/src/sha256.h +++ b/src/sha256.h @@ -8,14 +8,12 @@ typedef struct { } context_sha256_T; void sha256_start(context_sha256_T *ctx); -void sha256_update(context_sha256_T *ctx, char_u *input, - uint32_t length); +void sha256_update(context_sha256_T *ctx, char_u *input, uint32_t length); void sha256_finish(context_sha256_T *ctx, char_u digest[32]); -char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, - int salt_len); +char_u *sha256_bytes(char_u *buf, int buf_len, char_u *salt, int salt_len); char_u *sha256_key(char_u *buf, char_u *salt, int salt_len); int sha256_self_test(void); -void sha2_seed(char_u *header, int header_len, char_u *salt, - int salt_len); -/* vim: set ft=c : */ -#endif /* NEOVIM_SHA256_H */ +void sha2_seed(char_u *header, int header_len, char_u *salt, int salt_len); + +// vim: set ft=c: +#endif // NEOVIM_SHA256_H diff --git a/src/version.c b/src/version.c index 030033cff7..18f9fddc44 100644 --- a/src/version.c +++ b/src/version.c @@ -1,11 +1,14 @@ -/* vi:set ts=8 sts=4 sw=4: - * - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ +/// @file version.c +/// +/// Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred) +/// It has been changed beyond recognition since then. +/// +/// Differences between version 6.x and 7.x can be found with ":help version7". +/// Differences between version 5.x and 6.x can be found with ":help version6". +/// Differences between version 4.x and 5.x can be found with ":help version5". +/// Differences between version 3.0 and 4.x can be found with ":help version4". +/// All the remarks about older versions have been removed, they are not very +/// interesting. #include "vim.h" #include "version.h" @@ -15,52 +18,39 @@ #include "misc2.h" #include "screen.h" -/* - * Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred) - * It has been changed beyond recognition since then. - * - * Differences between version 6.x and 7.x can be found with ":help version7". - * Differences between version 5.x and 6.x can be found with ":help version6". - * Differences between version 4.x and 5.x can be found with ":help version5". - * Differences between version 3.0 and 4.x can be found with ":help version4". - * All the remarks about older versions have been removed, they are not very - * interesting. - */ - #include "version_defs.h" -char *Version = VIM_VERSION_SHORT; -static char *mediumVersion = VIM_VERSION_MEDIUM; +char *Version = VIM_VERSION_SHORT; +static char *mediumVersion = VIM_VERSION_MEDIUM; #if defined(HAVE_DATE_TIME) || defined(PROTO) -char *longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; -#else -char *longVersion = VIM_VERSION_LONG; -#endif +char *longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; +#else // if defined(HAVE_DATE_TIME) || defined(PROTO) +char *longVersion = VIM_VERSION_LONG; +#endif // if defined(HAVE_DATE_TIME) || defined(PROTO) static void list_features(void); static void version_msg(char *s); -static char *(features[]) = -{ +static char *(features[]) = { #ifdef HAVE_ACL "+acl", -#else +#else // ifdef HAVE_ACL "-acl", -#endif +#endif // ifdef HAVE_ACL "+arabic", "+autocmd", "-balloon_eval", "-browse", #ifdef NO_BUILTIN_TCAPS "-builtin_terms", -#endif +#endif // ifdef NO_BUILTIN_TCAPS #ifdef SOME_BUILTIN_TCAPS "+builtin_terms", -#endif +#endif // ifdef SOME_BUILTIN_TCAPS #ifdef ALL_BUILTIN_TCAPS "++builtin_terms", -#endif +#endif // ifdef ALL_BUILTIN_TCAPS "+byte_offset", "+cindent", "-clientserver", @@ -73,7 +63,11 @@ static char *(features[]) = "+cryptv", "+cscope", "+cursorbind", +#ifdef CURSOR_SHAPE "+cursorshape", +#else // ifdef CURSOR_SHAPE + "-cursorshape", +#endif // ifdef CURSOR_SHAPE "+dialog_con", "+diff", "+digraphs", @@ -89,29 +83,32 @@ static char *(features[]) = "+float", "+folding", "-footer", - /* only interesting on Unix systems */ + + // only interesting on Unix systems #if defined(UNIX) "+fork()", -#endif +#endif // if defined(UNIX) "+gettext", #if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) || defined(DYNAMIC_ICONV) # ifdef DYNAMIC_ICONV "+iconv/dyn", -# else +# else // ifdef DYNAMIC_ICONV "+iconv", -# endif -#else +# endif // ifdef DYNAMIC_ICONV +#else // if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) + // ||defined(DYNAMIC_ICONV) "-iconv", -#endif +#endif // if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) + // || defined(DYNAMIC_ICONV) "+insert_expand", "+jumplist", "+keymap", "+langmap", #ifdef FEAT_LIBCALL "+libcall", -#else +#else // ifdef FEAT_LIBCALL "-libcall", -#endif +#endif // ifdef FEAT_LIBCALL "+linebreak", "+lispindent", "+listcmds", @@ -128,11 +125,11 @@ static char *(features[]) = "-mouse_gpm", # ifdef FEAT_MOUSE_JSB "+mouse_jsbterm", -# else +# else // ifdef FEAT_MOUSE_JSB "-mouse_jsbterm", -# endif +# endif // ifdef FEAT_MOUSE_JSB "+mouse_netterm", -#endif +#endif // if defined(UNIX) || defined(VMS) #if defined(UNIX) || defined(VMS) @@ -140,7 +137,7 @@ static char *(features[]) = "-mouse_sysmouse", "+mouse_urxvt", "+mouse_xterm", -#endif +#endif // if defined(UNIX) || defined(VMS) "+multi_byte", "+multi_lang", @@ -164,9 +161,9 @@ static char *(features[]) = "-sniff", #ifdef STARTUPTIME "+startuptime", -#else +#else // ifdef STARTUPTIME "-startuptime", -#endif +#endif // ifdef STARTUPTIME "+statusline", "-sun_workshop", "+syntax", @@ -174,24 +171,25 @@ static char *(features[]) = "+tag_old_static", #ifdef FEAT_TAG_ANYWHITE "+tag_any_white", -#else +#else // ifdef FEAT_TAG_ANYWHITE "-tag_any_white", -#endif +#endif // ifdef FEAT_TAG_ANYWHITE "-tcl", #if defined(UNIX) || defined(__EMX__) - /* only Unix (or OS/2 with EMX!) can have terminfo instead of termcap */ + + // only Unix (or OS/2 with EMX!) can have terminfo instead of termcap # ifdef TERMINFO "+terminfo", -# else +# else // ifdef TERMINFO "-terminfo", -# endif -#else /* unix always includes termcap support */ +# endif // ifdef TERMINFO +#else // unix always includes termcap support # ifdef HAVE_TGETENT "+tgetent", -# else +# else // ifdef HAVE_TGETENT "-tgetent", -# endif -#endif +# endif // ifdef HAVE_TGETENT +#endif // if defined(UNIX) || defined(__EMX__) "+termresponse", "+textobjects", "+title", @@ -209,480 +207,322 @@ static char *(features[]) = "+writebackup", #if defined(UNIX) || defined(VMS) "-X11", -#endif +#endif // if defined(UNIX) || defined(VMS) "-xfontset", "-xim", #if defined(UNIX) || defined(VMS) "-xsmp", "-xterm_clipboard", -#endif +#endif // if defined(UNIX) || defined(VMS) #ifdef FEAT_XTERM_SAVE "+xterm_save", -#else +#else // ifdef FEAT_XTERM_SAVE "-xterm_save", -#endif +#endif // ifdef FEAT_XTERM_SAVE "-xpm", NULL }; -static int included_patches[] = -{ /* Add new patch number below this line */ - /**/ +static int included_patches[] = { + // Add new patch number below this line 160, - /**/ 159, - /**/ 158, - /**/ 157, - /**/ 156, - /**/ 155, - /**/ 154, - /**/ 153, - /**/ 152, - /**/ 151, - /**/ 150, - /**/ 149, - /**/ 148, - /**/ 147, - /**/ 146, - /**/ 145, - /**/ 144, - /**/ 143, - /**/ 142, - /**/ 141, - /**/ 140, - /**/ 139, - /**/ 138, - /**/ 137, - /**/ 136, - /**/ 135, - /**/ 134, - /**/ 133, - /**/ 132, - /**/ 131, - /**/ 130, - /**/ 129, - /**/ 128, - /**/ 127, - /**/ 126, - /**/ 125, - /**/ 124, - /**/ 123, - /**/ 122, - /**/ 121, - /**/ 120, - /**/ 119, - /**/ 118, - /**/ 117, - /**/ 116, - /**/ 115, - /**/ 114, - /**/ 113, - /**/ 112, - /**/ 111, - /**/ 110, - /**/ 109, - /**/ 108, - /**/ 107, - /**/ 106, - /**/ 105, - /**/ 104, - /**/ 103, - /**/ 102, - /**/ 101, - /**/ 100, - /**/ 99, - /**/ 98, - /**/ 97, - /**/ 96, - /**/ 95, - /**/ 94, - /**/ 93, - /**/ 92, - /**/ 91, - /**/ 90, - /**/ 89, - /**/ 88, - /**/ 87, - /**/ 86, - /**/ 85, - /**/ 84, - /**/ 83, - /**/ 82, - /**/ 81, - /**/ 80, - /**/ 79, - /**/ 78, - /**/ 77, - /**/ 76, - /**/ 75, - /**/ 74, - /**/ 73, - /**/ 72, - /**/ 71, - /**/ 70, - /**/ 69, - /**/ 68, - /**/ 67, - /**/ 66, - /**/ 65, - /**/ 64, - /**/ 63, - /**/ 62, - /**/ 61, - /**/ 60, - /**/ 59, - /**/ 58, - /**/ 57, - /**/ 56, - /**/ 55, - /**/ 54, - /**/ 53, - /**/ 52, - /**/ 51, - /**/ 50, - /**/ 49, - /**/ 48, - /**/ 47, - /**/ 46, - /**/ 45, - /**/ 44, - /**/ 43, - /**/ 42, - /**/ 41, - /**/ 40, - /**/ 39, - /**/ 38, - /**/ 37, - /**/ 36, - /**/ 35, - /**/ 34, - /**/ 33, - /**/ 32, - /**/ 31, - /**/ 30, - /**/ 29, - /**/ 28, - /**/ 27, - /**/ 26, - /**/ 25, - /**/ 24, - /**/ 23, - /**/ 22, - /**/ 21, - /**/ 20, - /**/ 19, - /**/ 18, - /**/ 17, - /**/ 16, - /**/ 15, - /**/ 14, - /**/ 13, - /**/ 12, - /**/ 11, - /**/ 10, - /**/ 9, - /**/ 8, - /**/ 7, - /**/ 6, - /**/ 5, - /**/ 4, - /**/ 3, - /**/ 2, - /**/ 1, - /**/ 0 }; -/* - * Place to put a short description when adding a feature with a patch. - * Keep it short, e.g.,: "relative numbers", "persistent undo". - * Also add a comment marker to separate the lines. - * See the official Vim patches for the diff format: It must use a context of - * one line only. Create it by hand or use "diff -C2" and edit the patch. - */ -static char *(extra_patches[]) = -{ /* Add your patch description below this line */ - /**/ +/// Place to put a short description when adding a feature with a patch. +/// Keep it short, e.g.,: "relative numbers", "persistent undo". +/// Also add a comment marker to separate the lines. +/// See the official Vim patches for the diff format: It must use a context of +/// one line only. Create it by hand or use "diff -C2" and edit the patch. +static char *(extra_patches[]) = { + // Add your patch description below this line NULL }; -int highest_patch(void) { +int highest_patch(void) +{ int i; int h = 0; - for (i = 0; included_patches[i] != 0; ++i) - if (included_patches[i] > h) + for (i = 0; included_patches[i] != 0; ++i) { + if (included_patches[i] > h) { h = included_patches[i]; + } + } return h; } -/* - * Return TRUE if patch "n" has been included. - */ +/// Checks whether patch `n` has been included. +/// +/// @param n The patch number. +/// +/// @return TRUE if patch "n" has been included. int has_patch(int n) { int i; - - for (i = 0; included_patches[i] != 0; ++i) - if (included_patches[i] == n) + for (i = 0; included_patches[i] != 0; ++i) { + if (included_patches[i] == n) { return TRUE; + } + } return FALSE; } void ex_version(exarg_T *eap) { - /* - * Ignore a ":version 9.99" command. - */ + // Ignore a ":version 9.99" command. if (*eap->arg == NUL) { msg_putchar('\n'); list_version(); } } -/* - * List all features aligned in columns, dictionary style. - */ -static void list_features(void) { - int i; - int ncol; - int nrow; +/// List all features aligned in columns, dictionary style. +static void list_features(void) +{ int nfeat = 0; int width = 0; - /* Find the length of the longest feature name, use that + 1 as the column - * width */ + // Find the length of the longest feature name, use that + 1 as the column + // width + int i; for (i = 0; features[i] != NULL; ++i) { int l = (int)STRLEN(features[i]); - if (l > width) + if (l > width) { width = l; - ++nfeat; + } + nfeat++; } width += 1; if (Columns < width) { - /* Not enough screen columns - show one per line */ + // Not enough screen columns - show one per line for (i = 0; features[i] != NULL; ++i) { version_msg(features[i]); - if (msg_col > 0) + if (msg_col > 0) { msg_putchar('\n'); + } } return; } - /* The rightmost column doesn't need a separator. - * Sacrifice it to fit in one more column if possible. */ - ncol = (int) (Columns + 1) / width; - nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0); + // The rightmost column doesn't need a separator. + // Sacrifice it to fit in one more column if possible. + int ncol = (int)(Columns + 1) / width; + int nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0); - /* i counts columns then rows. idx counts rows then columns. */ + // i counts columns then rows. idx counts rows then columns. for (i = 0; !got_int && i < nrow * ncol; ++i) { int idx = (i / ncol) + (i % ncol) * nrow; - if (idx < nfeat) { int last_col = (i + 1) % ncol == 0; - msg_puts((char_u *)features[idx]); if (last_col) { - if (msg_col > 0) + if (msg_col > 0) { msg_putchar('\n'); - } else { - while (msg_col % width) + } + } else { + while (msg_col % width) { msg_putchar(' '); + } } - } else { - if (msg_col > 0) + } else { + if (msg_col > 0) { msg_putchar('\n'); + } } } } -void list_version(void) { +void list_version(void) +{ int i; int first; - char *s = ""; + char *s = ""; - /* - * When adding features here, don't forget to update the list of - * internal variables in eval.c! - */ + // When adding features here, don't forget to update the list of + // internal variables in eval.c! MSG(longVersion); - - /* Print the list of patch numbers if there is at least one. */ - /* Print a range when patches are consecutive: "1-10, 12, 15-40, 42-45" */ + // Print the list of patch numbers if there is at least one. + // Print a range when patches are consecutive: "1-10, 12, 15-40, 42-45" if (included_patches[0] != 0) { MSG_PUTS(_("\nIncluded patches: ")); first = -1; - /* find last one */ - for (i = 0; included_patches[i] != 0; ++i) - ; + + // find last one + for (i = 0; included_patches[i] != 0; ++i) {} + while (--i >= 0) { - if (first < 0) + if (first < 0) { first = included_patches[i]; - if (i == 0 || included_patches[i - 1] != included_patches[i] + 1) { + } + + if ((i == 0) || (included_patches[i - 1] != included_patches[i] + 1)) { MSG_PUTS(s); s = ", "; msg_outnum((long)first); + if (first != included_patches[i]) { MSG_PUTS("-"); msg_outnum((long)included_patches[i]); @@ -692,10 +532,11 @@ void list_version(void) { } } - /* Print the list of extra patch descriptions if there is at least one. */ + // Print the list of extra patch descriptions if there is at least one. if (extra_patches[0] != NULL) { MSG_PUTS(_("\nExtra patches: ")); s = ""; + for (i = 0; extra_patches[i] != NULL; ++i) { MSG_PUTS(s); s = ", "; @@ -707,21 +548,24 @@ void list_version(void) { MSG_PUTS("\n"); MSG_PUTS(_("Modified by ")); MSG_PUTS(MODIFIED_BY); -#endif +#endif // ifdef MODIFIED_BY #ifdef HAVE_PATHDEF - if (*compiled_user != NUL || *compiled_sys != NUL) { + + if ((*compiled_user != NUL) || (*compiled_sys != NUL)) { MSG_PUTS(_("\nCompiled ")); + if (*compiled_user != NUL) { MSG_PUTS(_("by ")); MSG_PUTS(compiled_user); } + if (*compiled_sys != NUL) { MSG_PUTS("@"); MSG_PUTS(compiled_sys); } } -#endif +#endif // ifdef HAVE_PATHDEF MSG_PUTS(_("\nHuge version ")); MSG_PUTS(_("without GUI.")); @@ -733,38 +577,40 @@ void list_version(void) { version_msg(_(" system vimrc file: \"")); version_msg(SYS_VIMRC_FILE); version_msg("\"\n"); -#endif +#endif // ifdef SYS_VIMRC_FILE #ifdef USR_VIMRC_FILE version_msg(_(" user vimrc file: \"")); version_msg(USR_VIMRC_FILE); version_msg("\"\n"); -#endif +#endif // ifdef USR_VIMRC_FILE #ifdef USR_VIMRC_FILE2 version_msg(_(" 2nd user vimrc file: \"")); version_msg(USR_VIMRC_FILE2); version_msg("\"\n"); -#endif +#endif // ifdef USR_VIMRC_FILE2 #ifdef USR_VIMRC_FILE3 version_msg(_(" 3rd user vimrc file: \"")); version_msg(USR_VIMRC_FILE3); version_msg("\"\n"); -#endif +#endif // ifdef USR_VIMRC_FILE3 #ifdef USR_EXRC_FILE version_msg(_(" user exrc file: \"")); version_msg(USR_EXRC_FILE); version_msg("\"\n"); -#endif +#endif // ifdef USR_EXRC_FILE #ifdef USR_EXRC_FILE2 version_msg(_(" 2nd user exrc file: \"")); version_msg(USR_EXRC_FILE2); version_msg("\"\n"); -#endif +#endif // ifdef USR_EXRC_FILE2 #ifdef HAVE_PATHDEF + if (*default_vim_dir != NUL) { version_msg(_(" fall-back for $VIM: \"")); version_msg((char *)default_vim_dir); version_msg("\"\n"); } + if (*default_vimruntime_dir != NUL) { version_msg(_(" f-b for $VIMRUNTIME: \"")); version_msg((char *)default_vimruntime_dir); @@ -775,66 +621,66 @@ void list_version(void) { version_msg("\n"); version_msg(_("Linking: ")); version_msg((char *)all_lflags); -#endif +#endif // ifdef HAVE_PATHDEF #ifdef DEBUG version_msg("\n"); version_msg(_(" DEBUG BUILD")); -#endif +#endif // ifdef DEBUG } -/* - * Output a string for the version message. If it's going to wrap, output a - * newline, unless the message is too long to fit on the screen anyway. - */ +/// Output a string for the version message. If it's going to wrap, output a +/// newline, unless the message is too long to fit on the screen anyway. +/// +/// @param s static void version_msg(char *s) { int len = (int)STRLEN(s); - if (!got_int && len < (int)Columns && msg_col + len >= (int)Columns - && *s != '\n') + if (!got_int + && (len < (int)Columns) + && (msg_col + len >= (int)Columns) + && (*s != '\n')) { msg_putchar('\n'); - if (!got_int) + } + + if (!got_int) { MSG_PUTS(s); + } } -static void do_intro_line(int row, char_u *mesg, int add_version, - int attr); +static void do_intro_line(int row, char_u *mesg, int add_version, int attr); -/* - * Show the intro message when not editing a file. - */ -void maybe_intro_message(void) { +/// Show the intro message when not editing a file. +void maybe_intro_message(void) +{ if (bufempty() - && curbuf->b_fname == NULL - && firstwin->w_next == NULL - && vim_strchr(p_shm, SHM_INTRO) == NULL) + && (curbuf->b_fname == NULL) + && (firstwin->w_next == NULL) + && (vim_strchr(p_shm, SHM_INTRO) == NULL)) { intro_message(FALSE); + } } -/* - * Give an introductory message about Vim. - * Only used when starting Vim on an empty file, without a file name. - * Or with the ":intro" command (for Sven :-). - */ -void -intro_message ( - int colon /* TRUE for ":intro" */ -) +/// Give an introductory message about Vim. +/// Only used when starting Vim on an empty file, without a file name. +/// Or with the ":intro" command (for Sven :-). +/// +/// @param colon TRUE for ":intro" +void intro_message(int colon) { int i; int row; int blanklines; int sponsor; - char *p; - static char *(lines[]) = - { + char *p; + static char *(lines[]) = { N_("VIM - Vi IMproved"), "", N_("version "), N_("by Bram Moolenaar et al."), #ifdef MODIFIED_BY " ", -#endif +#endif // ifdef MODIFIED_BY N_("Vim is open source and freely distributable"), "", N_("Help poor children in Uganda!"), @@ -850,62 +696,76 @@ intro_message ( N_("type :help cp-default<Enter> for info on this"), }; - /* blanklines = screen height - # message lines */ + // blanklines = screen height - # message lines blanklines = (int)Rows - ((sizeof(lines) / sizeof(char *)) - 1); - if (!p_cp) - blanklines += 4; /* add 4 for not showing "Vi compatible" message */ - /* Don't overwrite a statusline. Depends on 'cmdheight'. */ - if (p_ls > 1) + if (!p_cp) { + // add 4 for not showing "Vi compatible" message + blanklines += 4; + } + + // Don't overwrite a statusline. Depends on 'cmdheight'. + if (p_ls > 1) { blanklines -= Rows - topframe->fr_height; - if (blanklines < 0) + } + + if (blanklines < 0) { blanklines = 0; + } - /* Show the sponsor and register message one out of four times, the Uganda - * message two out of four times. */ + // Show the sponsor and register message one out of four times, the Uganda + // message two out of four times. sponsor = (int)time(NULL); sponsor = ((sponsor & 2) == 0) - ((sponsor & 4) == 0); - /* start displaying the message lines after half of the blank lines */ + // start displaying the message lines after half of the blank lines row = blanklines / 2; - if ((row >= 2 && Columns >= 50) || colon) { + + if (((row >= 2) && (Columns >= 50)) || colon) { for (i = 0; i < (int)(sizeof(lines) / sizeof(char *)); ++i) { p = lines[i]; if (p == NULL) { - if (!p_cp) + if (!p_cp) { break; + } continue; } + if (sponsor != 0) { - if (strstr(p, "children") != NULL) + if (strstr(p, "children") != NULL) { p = sponsor < 0 ? N_("Sponsor Vim development!") : N_("Become a registered Vim user!"); - else if (strstr(p, "iccf") != NULL) + } else if (strstr(p, "iccf") != NULL) { p = sponsor < 0 ? N_("type :help sponsor<Enter> for information ") : N_("type :help register<Enter> for information "); - else if (strstr(p, "Orphans") != NULL) + } else if (strstr(p, "Orphans") != NULL) { p = N_("menu Help->Sponsor/Register for information "); + } } - if (*p != NUL) + + if (*p != NUL) { do_intro_line(row, (char_u *)_(p), i == 2, 0); - ++row; + } + row++; } } - /* Make the wait-return message appear just below the text. */ - if (colon) + // Make the wait-return message appear just below the text. + if (colon) { msg_row = row; + } } static void do_intro_line(int row, char_u *mesg, int add_version, int attr) { char_u vers[20]; int col; - char_u *p; + char_u *p; int l; int clen; + #ifdef MODIFIED_BY # define MODBY_LEN 150 char_u modby[MODBY_LEN]; @@ -916,50 +776,58 @@ static void do_intro_line(int row, char_u *mesg, int add_version, int attr) vim_strncpy(modby + l, (char_u *)MODIFIED_BY, MODBY_LEN - l - 1); mesg = modby; } -#endif +#endif // ifdef MODIFIED_BY - /* Center the message horizontally. */ + // Center the message horizontally. col = vim_strsize(mesg); + if (add_version) { STRCPY(vers, mediumVersion); + if (highest_patch()) { - /* Check for 9.9x or 9.9xx, alpha/beta version */ + // Check for 9.9x or 9.9xx, alpha/beta version if (isalpha((int)vers[3])) { int len = (isalpha((int)vers[4])) ? 5 : 4; sprintf((char *)vers + len, ".%d%s", highest_patch(), - mediumVersion + len); - } else - sprintf((char *)vers + 3, ".%d", highest_patch()); + mediumVersion + len); + } else { + sprintf((char *)vers + 3, ".%d", highest_patch()); + } } col += (int)STRLEN(vers); } col = (Columns - col) / 2; - if (col < 0) + + if (col < 0) { col = 0; + } - /* Split up in parts to highlight <> items differently. */ + // Split up in parts to highlight <> items differently. for (p = mesg; *p != NUL; p += l) { clen = 0; + for (l = 0; p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); ++l) { if (has_mbyte) { clen += ptr2cells(p + l); l += (*mb_ptr2len)(p + l) - 1; - } else + } else { clen += byte2cells(p[l]); + } } screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr); col += clen; } - /* Add the version number to the version line. */ - if (add_version) + // Add the version number to the version line. + if (add_version) { screen_puts(vers, row, col, 0); + } } -/* - * ":intro": clear screen, display intro screen and wait for return. - */ +/// ":intro": clear screen, display intro screen and wait for return. +/// +/// @param eap void ex_intro(exarg_T *eap) { screenclear(); diff --git a/src/version.h b/src/version.h index 2b950e5e60..a400cdbfc1 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ #ifndef NEOVIM_VERSION_H #define NEOVIM_VERSION_H -/* version.c */ + void make_version(void); int highest_patch(void); int has_patch(int n); @@ -9,5 +9,6 @@ void list_version(void); void maybe_intro_message(void); void intro_message(int colon); void ex_intro(exarg_T *eap); -/* vim: set ft=c : */ -#endif /* NEOVIM_VERSION_H */ + +// vim: set ft=c: +#endif // NEOVIM_VERSION_H |