mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
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
This commit is contained in:
parent
8a6118ccac
commit
baab238271
150
src/arabic.c
150
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:
|
||||
|
67
src/arabic.h
67
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
|
||||
|
206
src/blowfish.c
206
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.
|
||||
char_u *key = sha256_key(password, salt, salt_len);
|
||||
|
||||
/* 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++)
|
||||
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))
|
||||
err++;
|
||||
bf_key_init((char_u *)(bf_test_data[i].password), bf_test_data[i].salt,
|
||||
(int)STRLEN(bf_test_data[i].salt));
|
||||
|
||||
/* Don't modify bf_test_data[i].plaintxt, self test is idempotent. */
|
||||
if (!bf_check_tables(pax, sbx, bf_test_data[i].keysum)) {
|
||||
err++;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
1916
src/charset.c
1916
src/charset.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
107
src/crypt.c
107
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;
|
||||
}
|
||||
|
||||
|
2491
src/diff.c
2491
src/diff.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
3548
src/digraph.c
3548
src/digraph.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
349
src/farsi.c
349
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_;
|
||||
|
126
src/farsi.h
126
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.
|
||||
*/
|
||||
/// @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 SRC_FARSI_H_
|
||||
#define SRC_FARSI_H_
|
||||
#ifndef NEOVIM_FARSI_H
|
||||
#define NEOVIM_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
|
||||
|
||||
/*
|
||||
* Farsi character set definition
|
||||
*/
|
||||
|
||||
/*
|
||||
* Begin of the non-standard part
|
||||
*/
|
||||
// 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
|
||||
*/
|
||||
// End of the non-standard part
|
||||
|
||||
/*
|
||||
* 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 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
|
||||
|
118
src/garray.c
118
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)
|
||||
|
22
src/garray.h
22
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
|
||||
|
469
src/hashtab.c
469
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
|
||||
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
|
||||
*/
|
||||
// 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)
|
||||
freeitem = hi;
|
||||
else if (hi->hi_hash == hash && STRCMP(hi->hi_key, key) == 0)
|
||||
return hi;
|
||||
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).
|
||||
*/
|
||||
if (hi->hi_key == HI_KEY_REMOVED) {
|
||||
freeitem = hi;
|
||||
} else if ((hi->hi_hash == hash) && (STRCMP(hi->hi_key, key) == 0)) {
|
||||
return hi;
|
||||
} 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).
|
||||
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;
|
||||
}
|
||||
|
||||
|
599
src/popupmnu.c
599
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) {
|
||||
pum_width = max_width + kind_width + extra_width + 1;
|
||||
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)
|
||||
|
||||
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) {
|
||||
pum_width = PUM_DEF_WIDTH;
|
||||
}
|
||||
}
|
||||
} 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 (pum_scrollbar > 0) {
|
||||
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
|
||||
screen_putchar(' ', row, pum_col + pum_width,
|
||||
i >= thumb_pos && i < thumb_pos + thumb_heigth
|
||||
? attr_thumb : attr_scroll);
|
||||
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);
|
||||
}
|
||||
|
||||
++row;
|
||||
if (pum_scrollbar > 0) {
|
||||
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 {
|
||||
screen_putchar(' ', row, pum_col + pum_width,
|
||||
i >= thumb_pos && i < thumb_pos + thumb_heigth
|
||||
? attr_thumb : attr_scroll);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
356
src/sha256.c
356
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 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 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)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
14
src/sha256.h
14
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
|
||||
|
588
src/version.c
588
src/version.c
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
|
@ -1222,7 +1222,7 @@ pos_arith = ignore # ignore/join/lead/lead_brea
|
||||
pos_assign = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force
|
||||
|
||||
# The position of boolean operators in wrapped expressions
|
||||
pos_bool = trail_break # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force
|
||||
pos_bool = lead_break # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force
|
||||
|
||||
# The position of comparison operators in wrapped expressions
|
||||
pos_compare = ignore # ignore/join/lead/lead_break/lead_force/trail/trail_break/trail_force
|
||||
|
Loading…
Reference in New Issue
Block a user