refactor: format with uncrustify #15722

This commit is contained in:
dundargoc
2021-09-19 22:07:42 +02:00
committed by GitHub
parent 6565adcbff
commit 853346a94d
16 changed files with 1806 additions and 1754 deletions

View File

@@ -15,9 +15,9 @@
#include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/arabic.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
// Arabic ISO-10646-1 character set definition
@@ -394,43 +394,80 @@ static bool A_is_f(int cur_c)
static int chg_c_a2s(int cur_c)
{
switch (cur_c) {
case a_HAMZA: return a_s_HAMZA;
case a_ALEF_MADDA: return a_s_ALEF_MADDA;
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE;
case a_WAW_HAMZA: return a_s_WAW_HAMZA;
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW;
case a_YEH_HAMZA: return a_s_YEH_HAMZA;
case a_ALEF: return a_s_ALEF;
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA;
case a_DAL: return a_s_DAL;
case a_THAL: return a_s_THAL;
case a_REH: return a_s_REH;
case a_ZAIN: return a_s_ZAIN;
case a_TATWEEL: return cur_c; // exceptions
case a_WAW: return a_s_WAW;
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA;
case a_BEH: return a_s_BEH;
case a_TEH: return a_s_TEH;
case a_THEH: return a_s_THEH;
case a_JEEM: return a_s_JEEM;
case a_HAH: return a_s_HAH;
case a_KHAH: return a_s_KHAH;
case a_SEEN: return a_s_SEEN;
case a_SHEEN: return a_s_SHEEN;
case a_SAD: return a_s_SAD;
case a_DAD: return a_s_DAD;
case a_TAH: return a_s_TAH;
case a_ZAH: return a_s_ZAH;
case a_AIN: return a_s_AIN;
case a_GHAIN: return a_s_GHAIN;
case a_FEH: return a_s_FEH;
case a_QAF: return a_s_QAF;
case a_KAF: return a_s_KAF;
case a_LAM: return a_s_LAM;
case a_MEEM: return a_s_MEEM;
case a_NOON: return a_s_NOON;
case a_HEH: return a_s_HEH;
case a_YEH: return a_s_YEH;
case a_HAMZA:
return a_s_HAMZA;
case a_ALEF_MADDA:
return a_s_ALEF_MADDA;
case a_ALEF_HAMZA_ABOVE:
return a_s_ALEF_HAMZA_ABOVE;
case a_WAW_HAMZA:
return a_s_WAW_HAMZA;
case a_ALEF_HAMZA_BELOW:
return a_s_ALEF_HAMZA_BELOW;
case a_YEH_HAMZA:
return a_s_YEH_HAMZA;
case a_ALEF:
return a_s_ALEF;
case a_TEH_MARBUTA:
return a_s_TEH_MARBUTA;
case a_DAL:
return a_s_DAL;
case a_THAL:
return a_s_THAL;
case a_REH:
return a_s_REH;
case a_ZAIN:
return a_s_ZAIN;
case a_TATWEEL:
return cur_c; // exceptions
case a_WAW:
return a_s_WAW;
case a_ALEF_MAKSURA:
return a_s_ALEF_MAKSURA;
case a_BEH:
return a_s_BEH;
case a_TEH:
return a_s_TEH;
case a_THEH:
return a_s_THEH;
case a_JEEM:
return a_s_JEEM;
case a_HAH:
return a_s_HAH;
case a_KHAH:
return a_s_KHAH;
case a_SEEN:
return a_s_SEEN;
case a_SHEEN:
return a_s_SHEEN;
case a_SAD:
return a_s_SAD;
case a_DAD:
return a_s_DAD;
case a_TAH:
return a_s_TAH;
case a_ZAH:
return a_s_ZAH;
case a_AIN:
return a_s_AIN;
case a_GHAIN:
return a_s_GHAIN;
case a_FEH:
return a_s_FEH;
case a_QAF:
return a_s_QAF;
case a_KAF:
return a_s_KAF;
case a_LAM:
return a_s_LAM;
case a_MEEM:
return a_s_MEEM;
case a_NOON:
return a_s_NOON;
case a_HEH:
return a_s_HEH;
case a_YEH:
return a_s_YEH;
}
return 0;
}
@@ -439,43 +476,80 @@ static int chg_c_a2s(int cur_c)
static int chg_c_a2i(int cur_c)
{
switch (cur_c) {
case a_YEH_HAMZA: return a_i_YEH_HAMZA;
case a_HAMZA: return a_s_HAMZA; // exceptions
case a_ALEF_MADDA: return a_s_ALEF_MADDA; // exceptions
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE; // exceptions
case a_WAW_HAMZA: return a_s_WAW_HAMZA; // exceptions
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW; // exceptions
case a_ALEF: return a_s_ALEF; // exceptions
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA; // exceptions
case a_DAL: return a_s_DAL; // exceptions
case a_THAL: return a_s_THAL; // exceptions
case a_REH: return a_s_REH; // exceptions
case a_ZAIN: return a_s_ZAIN; // exceptions
case a_TATWEEL: return cur_c; // exceptions
case a_WAW: return a_s_WAW; // exceptions
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA; // exceptions
case a_BEH: return a_i_BEH;
case a_TEH: return a_i_TEH;
case a_THEH: return a_i_THEH;
case a_JEEM: return a_i_JEEM;
case a_HAH: return a_i_HAH;
case a_KHAH: return a_i_KHAH;
case a_SEEN: return a_i_SEEN;
case a_SHEEN: return a_i_SHEEN;
case a_SAD: return a_i_SAD;
case a_DAD: return a_i_DAD;
case a_TAH: return a_i_TAH;
case a_ZAH: return a_i_ZAH;
case a_AIN: return a_i_AIN;
case a_GHAIN: return a_i_GHAIN;
case a_FEH: return a_i_FEH;
case a_QAF: return a_i_QAF;
case a_KAF: return a_i_KAF;
case a_LAM: return a_i_LAM;
case a_MEEM: return a_i_MEEM;
case a_NOON: return a_i_NOON;
case a_HEH: return a_i_HEH;
case a_YEH: return a_i_YEH;
case a_YEH_HAMZA:
return a_i_YEH_HAMZA;
case a_HAMZA:
return a_s_HAMZA; // exceptions
case a_ALEF_MADDA:
return a_s_ALEF_MADDA; // exceptions
case a_ALEF_HAMZA_ABOVE:
return a_s_ALEF_HAMZA_ABOVE; // exceptions
case a_WAW_HAMZA:
return a_s_WAW_HAMZA; // exceptions
case a_ALEF_HAMZA_BELOW:
return a_s_ALEF_HAMZA_BELOW; // exceptions
case a_ALEF:
return a_s_ALEF; // exceptions
case a_TEH_MARBUTA:
return a_s_TEH_MARBUTA; // exceptions
case a_DAL:
return a_s_DAL; // exceptions
case a_THAL:
return a_s_THAL; // exceptions
case a_REH:
return a_s_REH; // exceptions
case a_ZAIN:
return a_s_ZAIN; // exceptions
case a_TATWEEL:
return cur_c; // exceptions
case a_WAW:
return a_s_WAW; // exceptions
case a_ALEF_MAKSURA:
return a_s_ALEF_MAKSURA; // exceptions
case a_BEH:
return a_i_BEH;
case a_TEH:
return a_i_TEH;
case a_THEH:
return a_i_THEH;
case a_JEEM:
return a_i_JEEM;
case a_HAH:
return a_i_HAH;
case a_KHAH:
return a_i_KHAH;
case a_SEEN:
return a_i_SEEN;
case a_SHEEN:
return a_i_SHEEN;
case a_SAD:
return a_i_SAD;
case a_DAD:
return a_i_DAD;
case a_TAH:
return a_i_TAH;
case a_ZAH:
return a_i_ZAH;
case a_AIN:
return a_i_AIN;
case a_GHAIN:
return a_i_GHAIN;
case a_FEH:
return a_i_FEH;
case a_QAF:
return a_i_QAF;
case a_KAF:
return a_i_KAF;
case a_LAM:
return a_i_LAM;
case a_MEEM:
return a_i_MEEM;
case a_NOON:
return a_i_NOON;
case a_HEH:
return a_i_HEH;
case a_YEH:
return a_i_YEH;
}
return 0;
}
@@ -484,43 +558,80 @@ static int chg_c_a2i(int cur_c)
static int chg_c_a2m(int cur_c)
{
switch (cur_c) {
case a_HAMZA: return a_s_HAMZA; // exception
case a_ALEF_MADDA: return a_f_ALEF_MADDA; // exception
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE; // exception
case a_WAW_HAMZA: return a_f_WAW_HAMZA; // exception
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW; // exception
case a_YEH_HAMZA: return a_m_YEH_HAMZA;
case a_ALEF: return a_f_ALEF; // exception
case a_BEH: return a_m_BEH;
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA; // exception
case a_TEH: return a_m_TEH;
case a_THEH: return a_m_THEH;
case a_JEEM: return a_m_JEEM;
case a_HAH: return a_m_HAH;
case a_KHAH: return a_m_KHAH;
case a_DAL: return a_f_DAL; // exception
case a_THAL: return a_f_THAL; // exception
case a_REH: return a_f_REH; // exception
case a_ZAIN: return a_f_ZAIN; // exception
case a_SEEN: return a_m_SEEN;
case a_SHEEN: return a_m_SHEEN;
case a_SAD: return a_m_SAD;
case a_DAD: return a_m_DAD;
case a_TAH: return a_m_TAH;
case a_ZAH: return a_m_ZAH;
case a_AIN: return a_m_AIN;
case a_GHAIN: return a_m_GHAIN;
case a_TATWEEL: return cur_c; // exception
case a_FEH: return a_m_FEH;
case a_QAF: return a_m_QAF;
case a_KAF: return a_m_KAF;
case a_LAM: return a_m_LAM;
case a_MEEM: return a_m_MEEM;
case a_NOON: return a_m_NOON;
case a_HEH: return a_m_HEH;
case a_WAW: return a_f_WAW; // exception
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA; // exception
case a_YEH: return a_m_YEH;
case a_HAMZA:
return a_s_HAMZA; // exception
case a_ALEF_MADDA:
return a_f_ALEF_MADDA; // exception
case a_ALEF_HAMZA_ABOVE:
return a_f_ALEF_HAMZA_ABOVE; // exception
case a_WAW_HAMZA:
return a_f_WAW_HAMZA; // exception
case a_ALEF_HAMZA_BELOW:
return a_f_ALEF_HAMZA_BELOW; // exception
case a_YEH_HAMZA:
return a_m_YEH_HAMZA;
case a_ALEF:
return a_f_ALEF; // exception
case a_BEH:
return a_m_BEH;
case a_TEH_MARBUTA:
return a_f_TEH_MARBUTA; // exception
case a_TEH:
return a_m_TEH;
case a_THEH:
return a_m_THEH;
case a_JEEM:
return a_m_JEEM;
case a_HAH:
return a_m_HAH;
case a_KHAH:
return a_m_KHAH;
case a_DAL:
return a_f_DAL; // exception
case a_THAL:
return a_f_THAL; // exception
case a_REH:
return a_f_REH; // exception
case a_ZAIN:
return a_f_ZAIN; // exception
case a_SEEN:
return a_m_SEEN;
case a_SHEEN:
return a_m_SHEEN;
case a_SAD:
return a_m_SAD;
case a_DAD:
return a_m_DAD;
case a_TAH:
return a_m_TAH;
case a_ZAH:
return a_m_ZAH;
case a_AIN:
return a_m_AIN;
case a_GHAIN:
return a_m_GHAIN;
case a_TATWEEL:
return cur_c; // exception
case a_FEH:
return a_m_FEH;
case a_QAF:
return a_m_QAF;
case a_KAF:
return a_m_KAF;
case a_LAM:
return a_m_LAM;
case a_MEEM:
return a_m_MEEM;
case a_NOON:
return a_m_NOON;
case a_HEH:
return a_m_HEH;
case a_WAW:
return a_f_WAW; // exception
case a_ALEF_MAKSURA:
return a_f_ALEF_MAKSURA; // exception
case a_YEH:
return a_m_YEH;
}
return 0;
}
@@ -538,43 +649,80 @@ static int chg_c_a2f(int cur_c)
// a_f_LAM_ALEF_HAMZA_BELOW;
switch (cur_c) {
case a_HAMZA: return a_s_HAMZA; // exception
case a_ALEF_MADDA: return a_f_ALEF_MADDA;
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE;
case a_WAW_HAMZA: return a_f_WAW_HAMZA;
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW;
case a_YEH_HAMZA: return a_f_YEH_HAMZA;
case a_ALEF: return a_f_ALEF;
case a_BEH: return a_f_BEH;
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA;
case a_TEH: return a_f_TEH;
case a_THEH: return a_f_THEH;
case a_JEEM: return a_f_JEEM;
case a_HAH: return a_f_HAH;
case a_KHAH: return a_f_KHAH;
case a_DAL: return a_f_DAL;
case a_THAL: return a_f_THAL;
case a_REH: return a_f_REH;
case a_ZAIN: return a_f_ZAIN;
case a_SEEN: return a_f_SEEN;
case a_SHEEN: return a_f_SHEEN;
case a_SAD: return a_f_SAD;
case a_DAD: return a_f_DAD;
case a_TAH: return a_f_TAH;
case a_ZAH: return a_f_ZAH;
case a_AIN: return a_f_AIN;
case a_GHAIN: return a_f_GHAIN;
case a_TATWEEL: return cur_c; // exception
case a_FEH: return a_f_FEH;
case a_QAF: return a_f_QAF;
case a_KAF: return a_f_KAF;
case a_LAM: return a_f_LAM;
case a_MEEM: return a_f_MEEM;
case a_NOON: return a_f_NOON;
case a_HEH: return a_f_HEH;
case a_WAW: return a_f_WAW;
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA;
case a_YEH: return a_f_YEH;
case a_HAMZA:
return a_s_HAMZA; // exception
case a_ALEF_MADDA:
return a_f_ALEF_MADDA;
case a_ALEF_HAMZA_ABOVE:
return a_f_ALEF_HAMZA_ABOVE;
case a_WAW_HAMZA:
return a_f_WAW_HAMZA;
case a_ALEF_HAMZA_BELOW:
return a_f_ALEF_HAMZA_BELOW;
case a_YEH_HAMZA:
return a_f_YEH_HAMZA;
case a_ALEF:
return a_f_ALEF;
case a_BEH:
return a_f_BEH;
case a_TEH_MARBUTA:
return a_f_TEH_MARBUTA;
case a_TEH:
return a_f_TEH;
case a_THEH:
return a_f_THEH;
case a_JEEM:
return a_f_JEEM;
case a_HAH:
return a_f_HAH;
case a_KHAH:
return a_f_KHAH;
case a_DAL:
return a_f_DAL;
case a_THAL:
return a_f_THAL;
case a_REH:
return a_f_REH;
case a_ZAIN:
return a_f_ZAIN;
case a_SEEN:
return a_f_SEEN;
case a_SHEEN:
return a_f_SHEEN;
case a_SAD:
return a_f_SAD;
case a_DAD:
return a_f_DAD;
case a_TAH:
return a_f_TAH;
case a_ZAH:
return a_f_ZAH;
case a_AIN:
return a_f_AIN;
case a_GHAIN:
return a_f_GHAIN;
case a_TATWEEL:
return cur_c; // exception
case a_FEH:
return a_f_FEH;
case a_QAF:
return a_f_QAF;
case a_KAF:
return a_f_KAF;
case a_LAM:
return a_f_LAM;
case a_MEEM:
return a_f_MEEM;
case a_NOON:
return a_f_NOON;
case a_HEH:
return a_f_HEH;
case a_WAW:
return a_f_WAW;
case a_ALEF_MAKSURA:
return a_f_ALEF_MAKSURA;
case a_YEH:
return a_f_YEH;
}
return 0;
}
@@ -586,29 +734,52 @@ static int chg_c_a2f(int cur_c)
static int chg_c_i2m(int cur_c)
{
switch (cur_c) {
case a_i_YEH_HAMZA: return a_m_YEH_HAMZA;
case a_i_BEH: return a_m_BEH;
case a_i_TEH: return a_m_TEH;
case a_i_THEH: return a_m_THEH;
case a_i_JEEM: return a_m_JEEM;
case a_i_HAH: return a_m_HAH;
case a_i_KHAH: return a_m_KHAH;
case a_i_SEEN: return a_m_SEEN;
case a_i_SHEEN: return a_m_SHEEN;
case a_i_SAD: return a_m_SAD;
case a_i_DAD: return a_m_DAD;
case a_i_TAH: return a_m_TAH;
case a_i_ZAH: return a_m_ZAH;
case a_i_AIN: return a_m_AIN;
case a_i_GHAIN: return a_m_GHAIN;
case a_i_FEH: return a_m_FEH;
case a_i_QAF: return a_m_QAF;
case a_i_KAF: return a_m_KAF;
case a_i_LAM: return a_m_LAM;
case a_i_MEEM: return a_m_MEEM;
case a_i_NOON: return a_m_NOON;
case a_i_HEH: return a_m_HEH;
case a_i_YEH: return a_m_YEH;
case a_i_YEH_HAMZA:
return a_m_YEH_HAMZA;
case a_i_BEH:
return a_m_BEH;
case a_i_TEH:
return a_m_TEH;
case a_i_THEH:
return a_m_THEH;
case a_i_JEEM:
return a_m_JEEM;
case a_i_HAH:
return a_m_HAH;
case a_i_KHAH:
return a_m_KHAH;
case a_i_SEEN:
return a_m_SEEN;
case a_i_SHEEN:
return a_m_SHEEN;
case a_i_SAD:
return a_m_SAD;
case a_i_DAD:
return a_m_DAD;
case a_i_TAH:
return a_m_TAH;
case a_i_ZAH:
return a_m_ZAH;
case a_i_AIN:
return a_m_AIN;
case a_i_GHAIN:
return a_m_GHAIN;
case a_i_FEH:
return a_m_FEH;
case a_i_QAF:
return a_m_QAF;
case a_i_KAF:
return a_m_KAF;
case a_i_LAM:
return a_m_LAM;
case a_i_MEEM:
return a_m_MEEM;
case a_i_NOON:
return a_m_NOON;
case a_i_HEH:
return a_m_HEH;
case a_i_YEH:
return a_m_YEH;
}
return 0;
}
@@ -622,7 +793,8 @@ static int chg_c_f2m(int cur_c)
// case a_f_ALEF_MADDA:
// case a_f_ALEF_HAMZA_ABOVE:
// case a_f_ALEF_HAMZA_BELOW:
case a_f_YEH_HAMZA: return a_m_YEH_HAMZA;
case a_f_YEH_HAMZA:
return a_m_YEH_HAMZA;
case a_f_WAW_HAMZA: // exceptions
case a_f_ALEF:
case a_f_TEH_MARBUTA:
@@ -633,28 +805,50 @@ static int chg_c_f2m(int cur_c)
case a_f_WAW:
case a_f_ALEF_MAKSURA:
return cur_c;
case a_f_BEH: return a_m_BEH;
case a_f_TEH: return a_m_TEH;
case a_f_THEH: return a_m_THEH;
case a_f_JEEM: return a_m_JEEM;
case a_f_HAH: return a_m_HAH;
case a_f_KHAH: return a_m_KHAH;
case a_f_SEEN: return a_m_SEEN;
case a_f_SHEEN: return a_m_SHEEN;
case a_f_SAD: return a_m_SAD;
case a_f_DAD: return a_m_DAD;
case a_f_TAH: return a_m_TAH;
case a_f_ZAH: return a_m_ZAH;
case a_f_AIN: return a_m_AIN;
case a_f_GHAIN: return a_m_GHAIN;
case a_f_FEH: return a_m_FEH;
case a_f_QAF: return a_m_QAF;
case a_f_KAF: return a_m_KAF;
case a_f_LAM: return a_m_LAM;
case a_f_MEEM: return a_m_MEEM;
case a_f_NOON: return a_m_NOON;
case a_f_HEH: return a_m_HEH;
case a_f_YEH: return a_m_YEH;
case a_f_BEH:
return a_m_BEH;
case a_f_TEH:
return a_m_TEH;
case a_f_THEH:
return a_m_THEH;
case a_f_JEEM:
return a_m_JEEM;
case a_f_HAH:
return a_m_HAH;
case a_f_KHAH:
return a_m_KHAH;
case a_f_SEEN:
return a_m_SEEN;
case a_f_SHEEN:
return a_m_SHEEN;
case a_f_SAD:
return a_m_SAD;
case a_f_DAD:
return a_m_DAD;
case a_f_TAH:
return a_m_TAH;
case a_f_ZAH:
return a_m_ZAH;
case a_f_AIN:
return a_m_AIN;
case a_f_GHAIN:
return a_m_GHAIN;
case a_f_FEH:
return a_m_FEH;
case a_f_QAF:
return a_m_QAF;
case a_f_KAF:
return a_m_KAF;
case a_f_LAM:
return a_m_LAM;
case a_f_MEEM:
return a_m_MEEM;
case a_f_NOON:
return a_m_NOON;
case a_f_HEH:
return a_m_HEH;
case a_f_YEH:
return a_m_YEH;
// NOTE: these encodings are multi-positional, no ?
// case a_f_LAM_ALEF_MADDA_ABOVE:
// case a_f_LAM_ALEF_HAMZA_ABOVE:
@@ -668,10 +862,14 @@ static int chg_c_f2m(int cur_c)
static int chg_c_laa2i(int hid_c)
{
switch (hid_c) {
case a_ALEF_MADDA: return a_s_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_ABOVE: return a_s_LAM_ALEF_HAMZA_ABOVE;
case a_ALEF_HAMZA_BELOW: return a_s_LAM_ALEF_HAMZA_BELOW;
case a_ALEF: return a_s_LAM_ALEF;
case a_ALEF_MADDA:
return a_s_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_ABOVE:
return a_s_LAM_ALEF_HAMZA_ABOVE;
case a_ALEF_HAMZA_BELOW:
return a_s_LAM_ALEF_HAMZA_BELOW;
case a_ALEF:
return a_s_LAM_ALEF;
}
return 0;
}
@@ -680,10 +878,14 @@ static int chg_c_laa2i(int hid_c)
static int chg_c_laa2f(int hid_c)
{
switch (hid_c) {
case a_ALEF_MADDA: return a_f_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_ABOVE: return a_f_LAM_ALEF_HAMZA_ABOVE;
case a_ALEF_HAMZA_BELOW: return a_f_LAM_ALEF_HAMZA_BELOW;
case a_ALEF: return a_f_LAM_ALEF;
case a_ALEF_MADDA:
return a_f_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_ABOVE:
return a_f_LAM_ALEF_HAMZA_ABOVE;
case a_ALEF_HAMZA_BELOW:
return a_f_LAM_ALEF_HAMZA_BELOW;
case a_ALEF:
return a_f_LAM_ALEF;
}
return 0;
}
@@ -708,8 +910,7 @@ static int half_shape(int c)
// in: "prev_c1" is the first composing char for the previous char
// (not shaped)
// in: "next_c" is the next character (not shaped).
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
int next_c)
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c)
{
// Deal only with Arabic character, pass back all others
if (!A_is_ok(c)) {

View File

@@ -1,16 +1,16 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/os/os.h"
#include "nvim/fileio.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/ui.h"
#include "nvim/aucmd.h"
#include "nvim/buffer.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/buffer.h"
#include "nvim/fileio.h"
#include "nvim/main.h"
#include "nvim/os/os.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "aucmd.c.generated.h"

View File

@@ -3,10 +3,9 @@
// autocmd.c: Autocommand related functions
#include "nvim/autocmd.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
@@ -326,8 +325,7 @@ static void au_del_group(char_u *name)
event = (event_T)((int)event + 1)) {
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->group == i && ap->pat != NULL) {
give_warning(
(char_u *)_("W19: Deleting augroup that is still in use"), true);
give_warning((char_u *)_("W19: Deleting augroup that is still in use"), true);
in_use = true;
event = NUM_EVENTS;
break;
@@ -761,13 +759,8 @@ static int au_get_grouparg(char_u **argp)
// If *cmd == NUL: show entries.
// If forceit == true: delete entries.
// If group is not AUGROUP_ALL: only use this group.
static int do_autocmd_event(event_T event,
char_u *pat,
bool once,
int nested,
char_u *cmd,
int forceit,
int group)
static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, char_u *cmd,
int forceit, int group)
{
AutoPat *ap;
AutoPat **prev_ap;
@@ -847,8 +840,7 @@ static int do_autocmd_event(event_T event,
if (is_buflocal) {
// normalize pat into standard "<buffer>#N" form
snprintf(
(char *)buflocal_pat,
snprintf((char *)buflocal_pat,
BUFLOCAL_PAT_LEN,
"<buffer=%d>",
buflocal_nr);
@@ -889,7 +881,6 @@ static int do_autocmd_event(event_T event,
} else if (*cmd == NUL) {
// Show autocmd's for this autopat, or buflocals <buffer=X>
show_autocmd(ap, event);
} else if (ap->next == NULL) {
// Add autocmd to this autopat, if it's the last one.
break;
@@ -967,8 +958,7 @@ static int do_autocmd_event(event_T event,
// Implementation of ":doautocmd [group] event [fname]".
// Return OK for success, FAIL for failure;
int do_doautocmd(char_u *arg,
bool do_msg, // give message for no matching autocmds?
int do_doautocmd(char_u *arg, bool do_msg, // give message for no matching autocmds?
bool *did_something)
{
char_u *fname;
@@ -1188,7 +1178,7 @@ void aucmd_restbuf(aco_save_T *aco)
}
}
}
win_found:
win_found:
win_remove(curwin, NULL);
pmap_del(handle_T)(&window_handles, curwin->handle);
@@ -1268,11 +1258,7 @@ void aucmd_restbuf(aco_save_T *aco)
/// @param buf Buffer for <abuf>
///
/// @return true if some commands were executed.
bool apply_autocmds(event_T event,
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf)
bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf)
{
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
NULL);
@@ -1289,11 +1275,7 @@ bool apply_autocmds(event_T event,
/// @param exarg Ex command arguments
///
/// @return true if some commands were executed.
bool apply_autocmds_exarg(event_T event,
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf,
bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
exarg_T *eap)
{
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
@@ -1313,11 +1295,7 @@ bool apply_autocmds_exarg(event_T event,
/// @param[in,out] retval caller's retval
///
/// @return true if some autocommands were executed
bool apply_autocmds_retval(event_T event,
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf,
bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
int *retval)
{
if (should_abort(*retval)) {
@@ -1344,8 +1322,7 @@ bool has_event(event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// the current mode.
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return has_event(
(get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
return has_event((get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
// return first_autopat[] != NULL;
}
@@ -1376,13 +1353,8 @@ bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// @param eap Ex command arguments
///
/// @return true if some commands were executed.
static bool apply_autocmds_group(event_T event,
char_u *fname,
char_u *fname_io,
bool force,
int group,
buf_T *buf,
exarg_T *eap)
static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, bool force,
int group, buf_T *buf, exarg_T *eap)
{
char_u *sfname = NULL; // short file name
char_u *tail;
@@ -1769,8 +1741,7 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last)
&& (apc->group == AUGROUP_ALL || apc->group == ap->group)) {
// execution-condition
if (ap->buflocal_nr == 0
? match_file_pat(
NULL,
? match_file_pat(NULL,
&ap->reg_prog,
apc->fname,
apc->sfname,
@@ -1885,9 +1856,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
/// @param event event that occurred.
/// @param sfname filename the event occurred in.
/// @param buf buffer the file is open in
bool has_autocmd(event_T event,
char_u *sfname,
buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
{
AutoPat *ap;
char_u *fname;
@@ -1910,8 +1879,7 @@ bool has_autocmd(event_T event,
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0
? match_file_pat(
NULL,
? match_file_pat(NULL,
&ap->reg_prog,
fname,
sfname,
@@ -1948,11 +1916,8 @@ char_u *get_augroup_name(expand_T *xp, int idx)
return (char_u *)AUGROUP_NAME(idx);
}
char_u *set_context_in_autocmd(
expand_T *xp,
char_u *arg,
int doautocmd // true for :doauto*, false for :autocmd
)
char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd // true for :doauto*, false for :autocmd
)
{
char_u *p;
int group;

View File

@@ -19,32 +19,34 @@
// The current implementation remembers all file names ever used.
//
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/channel.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/extmark.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/highlight.h"
@@ -52,19 +54,21 @@
#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/shada.h"
#include "nvim/sign.h"
#include "nvim/spell.h"
#include "nvim/strings.h"
@@ -72,12 +76,8 @@
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/vim.h"
#include "nvim/window.h"
#include "nvim/shada.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os/input.h"
#include "nvim/buffer_updates.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer.c.generated.h"
@@ -99,9 +99,7 @@ typedef enum {
} BufFreeFlags;
// Read data from buffer for retrying.
static int
read_buffer(
int read_stdin, // read file from stdin, otherwise fifo
static int read_buffer(int read_stdin, // read file from stdin, otherwise fifo
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
int flags) // extra flags for readfile()
{
@@ -114,8 +112,7 @@ read_buffer(
// 'fileencoding' was guessed wrong.
//
line_count = curbuf->b_ml.ml_line_count;
retval = readfile(
read_stdin ? NULL : curbuf->b_ffname,
retval = readfile(read_stdin ? NULL : curbuf->b_ffname,
read_stdin ? NULL : curbuf->b_fname,
(linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
flags | READ_BUFFER);
@@ -152,11 +149,10 @@ read_buffer(
// Open current buffer, that is: open the memfile and read the file into
// memory.
// Return FAIL for failure, OK otherwise.
int open_buffer(
int read_stdin, // read file from stdin
int open_buffer(int read_stdin, // read file from stdin
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
int flags // extra flags for readfile()
)
)
{
int retval = OK;
bufref_T old_curbuf;
@@ -169,8 +165,9 @@ int open_buffer(
* user may have reset the flag by hand.
*/
if (readonlymode && curbuf->b_ffname != NULL
&& (curbuf->b_flags & BF_NEVERLOADED))
&& (curbuf->b_flags & BF_NEVERLOADED)) {
curbuf->b_p_ro = true;
}
if (ml_open(curbuf) == FAIL) {
/*
@@ -227,8 +224,7 @@ int open_buffer(
|| (S_ISCHR(perm)
&& is_dev_fd_file(curbuf->b_ffname))
# endif
)
) {
)) {
read_fifo = true;
}
if (read_fifo) {
@@ -431,9 +427,10 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
del_buf = true;
unload_buf = true;
wipe_buf = true;
} else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload"
} else if (buf->b_p_bh[0] == 'u') { // 'bufhidden' == "unload"
unload_buf = true;
}
}
if (buf->terminal && (unload_buf || del_buf || wipe_buf)) {
// terminal buffers can only be wiped
@@ -806,8 +803,8 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
// Avoid losing b:changedtick when deleting buffer: clearing variables
// implies using clear_tv() on b:changedtick and that sets changedtick to
// zero.
hashitem_T *const changedtick_hi = hash_find(
&buf->b_vars->dv_hashtab, (const char_u *)"changedtick");
hashitem_T *const changedtick_hi = hash_find(&buf->b_vars->dv_hashtab,
(const char_u *)"changedtick");
assert(changedtick_hi != NULL);
hash_remove(&buf->b_vars->dv_hashtab, changedtick_hi);
}
@@ -955,15 +952,10 @@ void handle_swap_exists(bufref_T *old_curbuf)
*
* Returns error message or NULL
*/
char_u *
do_bufdel(
int command,
char_u *arg, // pointer to extra arguments
int addr_count,
int start_bnr, // first buffer number in a range
char_u *do_bufdel(int command, char_u *arg, // pointer to extra arguments
int addr_count, int start_bnr, // first buffer number in a range
int end_bnr, // buffer nr or last buffer nr in a range
int forceit
)
int forceit)
{
int do_current = 0; // delete current buffer?
int deleted = 0; // number of buffers deleted
@@ -1121,14 +1113,10 @@ static int empty_curbuf(int close_others, int forceit, int action)
*
* Return FAIL or OK.
*/
int
do_buffer(
int action,
int start,
int dir, // FORWARD or BACKWARD
int do_buffer(int action, int start, int dir, // FORWARD or BACKWARD
int count, // buffer number or number of buffers
int forceit // true for :...!
)
)
{
buf_T *buf;
buf_T *bp;
@@ -1136,9 +1124,12 @@ do_buffer(
|| action == DOBUF_WIPE);
switch (start) {
case DOBUF_FIRST: buf = firstbuf; break;
case DOBUF_LAST: buf = lastbuf; break;
default: buf = curbuf; break;
case DOBUF_FIRST:
buf = firstbuf; break;
case DOBUF_LAST:
buf = lastbuf; break;
default:
buf = curbuf; break;
}
if (start == DOBUF_MOD) { // find next modified buffer
while (count-- > 0) {
@@ -1522,8 +1513,7 @@ void set_curbuf(buf_T *buf, int action)
* If curwin->w_buffer is null, enter_buffer() will make it valid again */
if ((buf_valid(buf) && buf != curbuf
&& !aborting()
) || curwin->w_buffer == NULL
) {
) || curwin->w_buffer == NULL) {
enter_buffer(buf);
if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
@@ -1705,8 +1695,7 @@ static inline void buf_init_changedtick(buf_T *const buf)
/// @param bufnr
///
/// @return pointer to the buffer
buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
int flags)
buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags)
{
char_u *ffname = ffname_arg;
char_u *sfname = sfname_arg;
@@ -2038,8 +2027,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
fpos = buflist_findfpos(buf);
lnum = fpos->lnum;
col = fpos->col;
} else
} else {
col = 0;
}
if (options & GETF_SWITCH) {
// If 'switchbuf' contains "useopen": jump to first window containing
@@ -2149,8 +2139,7 @@ buf_T *buflist_findname(char_u *ffname)
* getting it twice for the same file.
* Returns NULL if not found.
*/
static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
bool file_id_valid)
static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid)
{
// Start at the last buffer, expect to find a match sooner.
FOR_ALL_BUFFERS_BACKWARDS(buf) {
@@ -2165,13 +2154,11 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
/// Find file in buffer list by a regexp pattern.
/// Return fnum of the found buffer.
/// Return < 0 for error.
int buflist_findpat(
const char_u *pattern,
const char_u *pattern_end, // pointer to first char after pattern
int buflist_findpat(const char_u *pattern, const char_u *pattern_end, // pointer to first char after pattern
bool unlisted, // find unlisted buffers
bool diffmode, // find diff-mode buffers only
bool curtab_only // find buffers in current tab only
)
)
FUNC_ATTR_NONNULL_ARG(1)
{
int match = -1;
@@ -2288,8 +2275,7 @@ typedef struct {
} bufmatch_T;
/// Compare functions for qsort() below, that compares b_last_used.
static int
buf_time_compare(const void *s1, const void *s2)
static int buf_time_compare(const void *s1, const void *s2)
{
buf_T *buf1 = *(buf_T **)s1;
buf_T *buf2 = *(buf_T **)s2;
@@ -2326,8 +2312,9 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
patc = xmalloc(STRLEN(pat) + 11);
STRCPY(patc, "\\(^\\|[\\/]\\)");
STRCPY(patc + 11, pat + 1);
} else
} else {
patc = pat;
}
/*
* attempt == 0: try match with '\<', match at start of word
@@ -2485,12 +2472,8 @@ buf_T *buflist_findnr(int nr)
* home_replace() is used to shorten the file name (used for marks).
* Returns a pointer to allocated memory, of NULL when failed.
*/
char_u *
buflist_nr2name(
int n,
int fullname,
int helptail // for help buffers return tail only
)
char_u *buflist_nr2name(int n, int fullname, int helptail // for help buffers return tail only
)
{
buf_T *buf;
@@ -2511,8 +2494,7 @@ buflist_nr2name(
/// options are touched.
/// @param[in] col Column number to be set.
/// @param[in] copy_options If true save the local window option values.
void buflist_setfpos(buf_T *const buf, win_T *const win,
linenr_T lnum, colnr_T col,
void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T col,
bool copy_options)
FUNC_ATTR_NONNULL_ARG(1)
{
@@ -2593,8 +2575,7 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
// another tab page.
// Returns NULL when there isn't any info.
static wininfo_T *find_wininfo(buf_T *buf, bool need_options,
bool skip_diff_buffer)
static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer)
FUNC_ATTR_NONNULL_ALL
{
wininfo_T *wip;
@@ -2654,8 +2635,9 @@ void get_winopts(buf_T *buf)
curwin->w_fold_manual = wip->wi_fold_manual;
curwin->w_foldinvalid = true;
cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
} else
} else {
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
}
if (curwin->w_float_config.style == kWinStyleMinimal) {
didset_window_options(curwin);
@@ -2761,8 +2743,7 @@ void buflist_list(exarg_T *eap)
}
msg_putchar('\n');
len = vim_snprintf(
(char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
buf->b_fnum,
buf->b_p_bl ? ' ' : 'u',
buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
@@ -2824,12 +2805,8 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
// The file name with the full path is also remembered, for when :cd is used.
// Returns FAIL for failure (file name already in use by other buffer)
// OK otherwise.
int setfname(
buf_T *buf,
char_u *ffname_arg,
char_u *sfname_arg,
bool message // give message when buffer already exists
)
int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message // give message when buffer already exists
)
{
char_u *ffname = ffname_arg;
char_u *sfname = sfname_arg;
@@ -2961,9 +2938,8 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
* Get alternate file name for current window.
* Return NULL if there isn't any, and give error message if requested.
*/
char_u * getaltfname(
bool errmsg // give error message
)
char_u * getaltfname(bool errmsg // give error message
)
{
char_u *fname;
linenr_T dummy;
@@ -3038,8 +3014,7 @@ bool otherfile(char_u *ffname)
/// @param ffname full path name to check
/// @param file_id_p information about the file at "ffname".
/// @param file_id_valid whether a valid "file_id_p" was passed in.
static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p,
bool file_id_valid)
static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool file_id_valid)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
// no name is different
@@ -3106,12 +3081,8 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
/*
* Print info about the current buffer.
*/
void
fileinfo(
int fullname, // when non-zero print full path
int shorthelp,
int dont_truncate
)
void fileinfo(int fullname, // when non-zero print full path
int shorthelp, int dont_truncate)
{
char_u *name;
int n;
@@ -3124,8 +3095,9 @@ fileinfo(
if (fullname > 1) { // 2 CTRL-G: include buffer number
vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
p = buffer + STRLEN(buffer);
} else
} else {
p = buffer;
}
*p++ = '"';
if (buf_spname(curbuf) != NULL) {
@@ -3291,15 +3263,22 @@ void maketitle(void)
switch (bufIsChanged(curbuf)
| (curbuf->b_p_ro << 1)
| (!MODIFIABLE(curbuf) << 2)) {
case 0: break;
case 1: buf_p = strappend(buf_p, " +"); break;
case 2: buf_p = strappend(buf_p, " ="); break;
case 3: buf_p = strappend(buf_p, " =+"); break;
case 0:
break;
case 1:
buf_p = strappend(buf_p, " +"); break;
case 2:
buf_p = strappend(buf_p, " ="); break;
case 3:
buf_p = strappend(buf_p, " =+"); break;
case 4:
case 6: buf_p = strappend(buf_p, " -"); break;
case 6:
buf_p = strappend(buf_p, " -"); break;
case 5:
case 7: buf_p = strappend(buf_p, " -+"); break;
default: abort();
case 7:
buf_p = strappend(buf_p, " -+"); break;
default:
abort();
}
if (curbuf->b_fname != NULL) {
@@ -3485,17 +3464,8 @@ typedef enum {
/// @param tabtab Tab clicks definition (can be NULL).
///
/// @return The final width of the statusline
int build_stl_str_hl(
win_T *wp,
char_u *out,
size_t outlen,
char_u *fmt,
int use_sandbox,
char_u fillchar,
int maxwidth,
stl_hlrec_t **hltab,
StlClickRecord **tabtab
)
int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox,
char_u fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab)
{
static size_t stl_items_len = 20; // Initial value, grows as needed.
static stl_item_t *stl_items = NULL;
@@ -3608,8 +3578,9 @@ int build_stl_str_hl(
// Copy the formatting verbatim until we reach the end of the string
// or find a formatting item (denoted by `%`)
// or run out of room in our output buffer.
while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p)
while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p) {
*out_p++ = *fmt_p++;
}
// If we have processed the entire format string or run out of
// room in our output buffer, exit the loop.
@@ -3759,8 +3730,9 @@ int build_stl_str_hl(
// If the group is left-aligned, add characters to the right.
if (min_group_width < 0) {
min_group_width = 0 - min_group_width;
while (group_len++ < min_group_width && out_p < out_end_p)
while (group_len++ < min_group_width && out_p < out_end_p) {
*out_p++ = fillchar;
}
// If the group is right-aligned, shift everything to the right and
// prepend with filler characters.
} else {
@@ -3867,7 +3839,7 @@ int build_stl_str_hl(
if (*fmt_p == STL_CLICK_FUNC) {
fmt_p++;
char *t = (char *) fmt_p;
char *t = (char *)fmt_p;
while (*fmt_p != STL_CLICK_FUNC && *fmt_p) {
fmt_p++;
}
@@ -3935,7 +3907,6 @@ int build_stl_str_hl(
case STL_FILEPATH:
case STL_FULLPATH:
case STL_FILENAME:
{
// Set fillable to false so that ' ' in the filename will not
// get replaced with the fillchar
fillable = false;
@@ -3953,7 +3924,6 @@ int build_stl_str_hl(
str = path_tail(NameBuff);
}
break;
}
case STL_VIM_EXPR: // '{'
{
char_u *block_start = fmt_p - 1;
@@ -4042,10 +4012,10 @@ int build_stl_str_hl(
new_fmt_p = (char_u *)memcpy(new_fmt_p, usefmt, parsed_usefmt)
+ parsed_usefmt;
new_fmt_p = (char_u *)memcpy(new_fmt_p , str, str_length)
new_fmt_p = (char_u *)memcpy(new_fmt_p, str, str_length)
+ str_length;
new_fmt_p = (char_u *)memcpy(new_fmt_p, "%}", 2) + 2;
new_fmt_p = (char_u *)memcpy(new_fmt_p , fmt_p, fmt_length)
new_fmt_p = (char_u *)memcpy(new_fmt_p, fmt_p, fmt_length)
+ fmt_length;
*new_fmt_p = 0;
new_fmt_p = NULL;
@@ -4077,8 +4047,7 @@ int build_stl_str_hl(
break;
case STL_VIRTCOL:
case STL_VIRTCOL_ALT:
{
case STL_VIRTCOL_ALT: {
// In list mode virtcol needs to be recomputed
colnr_T virtcol = wp->w_virtcol;
if (wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL) {
@@ -4090,8 +4059,9 @@ int build_stl_str_hl(
// Don't display %V if it's the same as %c.
if (opt == STL_VIRTCOL_ALT
&& (virtcol == (colnr_T)(!(State & INSERT) && empty_line
? 0 : (int)wp->w_cursor.col + 1)))
? 0 : (int)wp->w_cursor.col + 1))) {
break;
}
num = (long)virtcol;
break;
}
@@ -4142,8 +4112,7 @@ int build_stl_str_hl(
case STL_OFFSET_X:
base = kNumBaseHexadecimal;
FALLTHROUGH;
case STL_OFFSET:
{
case STL_OFFSET: {
long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL,
false);
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
@@ -4174,9 +4143,10 @@ int build_stl_str_hl(
case STL_HELPFLAG:
case STL_HELPFLAG_ALT:
itemisflag = true;
if (wp->w_buffer->b_help)
if (wp->w_buffer->b_help) {
str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP"
: _("[Help]"));
}
break;
case STL_FILETYPE:
@@ -4192,7 +4162,6 @@ int build_stl_str_hl(
break;
case STL_FILETYPE_ALT:
{
itemisflag = true;
// Copy the filetype if it is not null and the formatted string will fit
// in the temporary buffer
@@ -4208,20 +4177,21 @@ int build_stl_str_hl(
str = buf_tmp;
}
break;
}
case STL_PREVIEWFLAG:
case STL_PREVIEWFLAG_ALT:
itemisflag = true;
if (wp->w_p_pvw)
if (wp->w_p_pvw) {
str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV"
: _("[Preview]"));
}
break;
case STL_QUICKFIX:
if (bt_quickfix(wp->w_buffer))
if (bt_quickfix(wp->w_buffer)) {
str = (char_u *)(wp->w_llist_ref
? _(msg_loclist)
: _(msg_qflist));
}
break;
case STL_MODIFIED:
@@ -4230,17 +4200,22 @@ int build_stl_str_hl(
switch ((opt == STL_MODIFIED_ALT)
+ bufIsChanged(wp->w_buffer) * 2
+ (!MODIFIABLE(wp->w_buffer)) * 4) {
case 2: str = (char_u *)"[+]"; break;
case 3: str = (char_u *)",+"; break;
case 4: str = (char_u *)"[-]"; break;
case 5: str = (char_u *)",-"; break;
case 6: str = (char_u *)"[+-]"; break;
case 7: str = (char_u *)",+-"; break;
case 2:
str = (char_u *)"[+]"; break;
case 3:
str = (char_u *)",+"; break;
case 4:
str = (char_u *)"[-]"; break;
case 5:
str = (char_u *)",-"; break;
case 6:
str = (char_u *)"[+-]"; break;
case 7:
str = (char_u *)",+-"; break;
}
break;
case STL_HIGHLIGHT:
{
case STL_HIGHLIGHT: {
// { The name of the highlight is surrounded by `#`
char_u *t = fmt_p;
while (*fmt_p != '#' && *fmt_p != NUL) {
@@ -4274,8 +4249,9 @@ int build_stl_str_hl(
if (itemisflag) {
if ((t[0] && t[1])
&& ((!prevchar_isitem && *t == ',')
|| (prevchar_isflag && *t == ' ')))
|| (prevchar_isflag && *t == ' '))) {
t++;
}
prevchar_isflag = true;
}
// }
@@ -4328,9 +4304,10 @@ int build_stl_str_hl(
// Change a space by fillchar, unless fillchar is '-' and a
// digit follows.
if (fillable && out_p[-1] == ' '
&& (!ascii_isdigit(*t) || fillchar != '-'))
&& (!ascii_isdigit(*t) || fillchar != '-')) {
out_p[-1] = fillchar;
}
}
// }
// For left-aligned items, fill any remaining space with the fillchar
@@ -4367,7 +4344,7 @@ int build_stl_str_hl(
// Note: We have to cast the base because the compiler uses
// unsigned ints for the enum values.
long num_chars = 1;
for (long n = num; n >= (int) base; n /= (int) base) {
for (long n = num; n >= (int)base; n /= (int)base) {
num_chars++;
}
@@ -4776,12 +4753,9 @@ char_u *alist_name(aentry_T *aep)
/*
* do_arg_all(): Open up to 'count' windows, one for each argument.
*/
void
do_arg_all(
int count,
int forceit, // hide buffers in current windows
void do_arg_all(int count, int forceit, // hide buffers in current windows
int keep_tabs // keep current tabs, for ":tab drop file"
)
)
{
char_u *opened; // Array of weight for which args are open:
// 0: not opened
@@ -5097,8 +5071,8 @@ void ex_buffer_all(exarg_T *eap)
: wp->w_width != Columns)
|| (had_tab > 0 && wp != firstwin))
&& !ONE_WINDOW
&& !(wp->w_closing || wp->w_buffer->b_locked > 0)
) {
&& !(wp->w_closing ||
wp->w_buffer->b_locked > 0)) {
win_close(wp, false);
wpnext = firstwin; // just in case an autocommand does
// something strange with windows
@@ -5189,9 +5163,10 @@ void ex_buffer_all(exarg_T *eap)
* discarded by a new aborting error, interrupt, or uncaught
* exception. */
leave_cleanup(&cs);
} else
} else {
handle_swap_exists(NULL);
}
}
os_breakcheck();
if (got_int) {
@@ -5282,11 +5257,8 @@ void do_modelines(int flags)
* chk_modeline() - check a single line for a mode string
* Return FAIL if an error encountered.
*/
static int
chk_modeline(
linenr_T lnum,
int flags // Same as for do_modelines().
)
static int chk_modeline(linenr_T lnum, int flags // Same as for do_modelines().
)
{
char_u *s;
char_u *e;
@@ -5302,8 +5274,9 @@ chk_modeline(
for (s = ml_get(lnum); *s != NUL; s++) {
if (prev == -1 || ascii_isspace(prev)) {
if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0)
|| STRNCMP(s, "vi:", (size_t)3) == 0)
|| STRNCMP(s, "vi:", (size_t)3) == 0) {
break;
}
// Accept both "vim" and "Vim".
if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') {
if (s[3] == '<' || s[3] == '=' || s[3] == '>') {
@@ -5477,8 +5450,10 @@ bool buf_hide(const buf_T *const buf)
switch (buf->b_p_bh[0]) {
case 'u': // "unload"
case 'w': // "wipe"
case 'd': return false; // "delete"
case 'h': return true; // "hide"
case 'd':
return false; // "delete"
case 'h':
return true; // "hide"
}
return p_hid || cmdmod.hide;
}
@@ -5660,11 +5635,8 @@ bool buf_contents_changed(buf_T *buf)
* this buffer. Call this to wipe out a temp buffer that does not contain any
* marks.
*/
void
wipe_buffer(
buf_T *buf,
bool aucmd // When true trigger autocommands.
)
void wipe_buffer(buf_T *buf, bool aucmd // When true trigger autocommands.
)
{
if (!aucmd) {
// Don't trigger BufDelete autocommands here.

View File

@@ -1,14 +1,14 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/buffer_updates.h"
#include "nvim/extmark.h"
#include "nvim/memline.h"
#include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/lua/executor.h"
#include "nvim/assert.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/extmark.h"
#include "nvim/lua/executor.h"
#include "nvim/memline.h"
#include "nvim/msgpack_rpc/channel.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer_updates.c.generated.h"
@@ -17,8 +17,7 @@
// Register a channel. Return True if the channel was added, or already added.
// Return False if the channel couldn't be added because the buffer is
// unloaded.
bool buf_updates_register(buf_T *buf, uint64_t channel_id,
BufUpdateCallbacks cb, bool send_buffer)
bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb, bool send_buffer)
{
// must fail if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
@@ -187,11 +186,8 @@ void buf_updates_unload(buf_T *buf, bool can_reload)
}
void buf_updates_send_changes(buf_T *buf,
linenr_T firstline,
int64_t num_added,
int64_t num_removed,
bool send_tick)
void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
int64_t num_removed, bool send_tick)
{
size_t deleted_codepoints, deleted_codeunits;
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints,
@@ -248,7 +244,7 @@ void buf_updates_send_changes(buf_T *buf,
// change notifications are so frequent that many dead channels will be
// cleared up quickly.
if (badchannelid != 0) {
ELOG("Disabling buffer updates for dead channel %"PRIu64, badchannelid);
ELOG("Disabling buffer updates for dead channel %" PRIu64, badchannelid);
buf_updates_unregister(buf, badchannelid);
}
@@ -302,11 +298,9 @@ void buf_updates_send_changes(buf_T *buf,
kv_size(buf->update_callbacks) = j;
}
void buf_updates_send_splice(
buf_T *buf,
int start_row, colnr_T start_col, bcount_t start_byte,
int old_row, colnr_T old_col, bcount_t old_byte,
int new_row, colnr_T new_col, bcount_t new_byte)
void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
colnr_T new_col, bcount_t new_byte)
{
if (!buf_updates_active(buf)
|| (old_byte == 0 && new_byte == 0)) {

View File

@@ -12,12 +12,12 @@
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
@@ -97,8 +97,7 @@ void changed(void)
// Create a swap file if that is wanted.
// Don't do this for "nofile" and "nowrite" buffer types.
if (curbuf->b_may_swap
&& !bt_dontwrite(curbuf)
) {
&& !bt_dontwrite(curbuf)) {
bool save_need_wait_return = need_wait_return;
need_wait_return = false;
@@ -140,8 +139,7 @@ void changed_internal(void)
/// Common code for when a change was made.
/// See changed_lines() for the arguments.
/// Careful: may trigger autocommands that reload the buffer.
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
long xtra)
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
{
int i;
pos_T *p;
@@ -463,9 +461,7 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
/// When only inserting lines, "lnum" and "lnume" are equal.
/// Takes care of calling changed() and updating b_mod_*.
/// Careful: may trigger autocommands that reload the buffer.
void
changed_lines(
linenr_T lnum, // first line with change
void changed_lines(linenr_T lnum, // first line with change
colnr_T col, // column in first line with change
linenr_T lnume, // line below last changed line
long xtra, // number of extra lines (negative when deleting)
@@ -473,7 +469,7 @@ changed_lines(
// and then increment changedtick *again*. This flag
// allows these callers to send the nvim_buf_lines_event
// events after they're done modifying changedtick.
)
)
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
@@ -657,8 +653,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
// show the match for right parens and braces.
if (p_sm && (State & INSERT)
&& msg_silent == 0
&& !ins_compl_active()
) {
&& !ins_compl_active()) {
showmatch(utf_ptr2char(buf));
}
@@ -791,8 +786,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
// fixpos is true, we don't want to end up positioned at the NUL,
// unless "restart_edit" is set or 'virtualedit' contains "onemore".
if (col > 0 && fixpos && restart_edit == 0
&& (ve_flags & VE_ONEMORE) == 0
) {
&& (ve_flags & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
curwin->w_cursor.coladd = 0;
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);
@@ -957,11 +951,8 @@ int copy_indent(int size, char_u *src)
/// OPENLINE_COM_LIST
///
/// @return true on success, false on failure
int open_line(
int dir, // FORWARD or BACKWARD
int flags,
int second_line_indent
)
int open_line(int dir, // FORWARD or BACKWARD
int flags, int second_line_indent)
{
char_u *next_line = NULL; // copy of the next line
char_u *p_extra = NULL; // what goes to next line
@@ -1023,8 +1014,7 @@ int open_line(
}
if ((State & INSERT)
&& !(State & VREPLACE_FLAG)
) {
&& !(State & VREPLACE_FLAG)) {
p_extra = saved_line + curwin->w_cursor.col;
if (do_si) { // need first char after new line break
p = skipwhite(p_extra);
@@ -1049,8 +1039,7 @@ int open_line(
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
// indent to use for the new line.
if (curbuf->b_p_ai
|| do_si
) {
|| do_si) {
// count white space on current line
newindent = get_indent_str_vtab(saved_line,
curbuf->b_p_ts,
@@ -1476,8 +1465,7 @@ int open_line(
// Recompute the indent, it may have changed.
if (curbuf->b_p_ai
|| do_si
) {
|| do_si) {
newindent = get_indent_str_vtab(leader,
curbuf->b_p_ts,
curbuf->b_p_vts_array, false);
@@ -1521,8 +1509,7 @@ int open_line(
// if a new indent will be set below, remove the indent that
// is in the comment leader
if (newindent
|| did_si
) {
|| did_si) {
while (lead_len && ascii_iswhite(*leader)) {
lead_len--;
newcol--;
@@ -1641,8 +1628,7 @@ int open_line(
inhibit_delete_count++;
if (newindent
|| did_si
) {
|| did_si) {
curwin->w_cursor.lnum++;
if (did_si) {
int sw = get_sw_value(curbuf);
@@ -1706,8 +1692,7 @@ int open_line(
// TODO(vigoux): maybe there is issues there with expandtabs ?
int cols_spliced = 0;
if (new_len < curwin->w_cursor.col) {
extmark_splice_cols(
curbuf, (int)curwin->w_cursor.lnum - 1,
extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1,
new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
cols_spliced = curwin->w_cursor.col - new_len;
}

View File

@@ -12,11 +12,11 @@
#include "nvim/msgpack_rpc/server.h"
#include "nvim/os/shell.h"
#ifdef WIN32
# include "nvim/os/pty_conpty_win.h"
# include "nvim/os/os_win_console.h"
# include "nvim/os/pty_conpty_win.h"
#endif
#include "nvim/path.h"
#include "nvim/ascii.h"
#include "nvim/path.h"
static bool did_stdio = false;
@@ -301,12 +301,10 @@ static void close_cb(Stream *stream, void *data)
/// < 0 if the job can't start
///
/// @returns [allocated] channel
Channel *channel_job_start(char **argv, CallbackReader on_stdout,
CallbackReader on_stderr, Callback on_exit,
bool pty, bool rpc, bool overlapped, bool detach,
ChannelStdinMode stdin_mode, const char *cwd,
uint16_t pty_width, uint16_t pty_height,
dict_T *env, varnumber_T *status_out)
Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader on_stderr,
Callback on_exit, bool pty, bool rpc, bool overlapped, bool detach,
ChannelStdinMode stdin_mode, const char *cwd, uint16_t pty_width,
uint16_t pty_height, dict_T *env, varnumber_T *status_out)
{
assert(cwd == NULL || os_isdir_executable(cwd));
@@ -409,8 +407,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
}
uint64_t channel_connect(bool tcp, const char *address,
bool rpc, CallbackReader on_output,
uint64_t channel_connect(bool tcp, const char *address, bool rpc, CallbackReader on_output,
int timeout, const char **error)
{
Channel *channel;
@@ -470,8 +467,7 @@ void channel_from_connection(SocketWatcher *watcher)
/// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
const char **error)
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, const char **error)
FUNC_ATTR_NONNULL_ALL
{
if (!headless_mode && !embedded_mode) {
@@ -514,8 +510,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
}
/// @param data will be consumed
size_t channel_send(uint64_t id, char *data, size_t len,
bool data_owned, const char **error)
size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const char **error)
FUNC_ATTR_NONNULL_ALL
{
Channel *chan = find_channel(id);
@@ -584,22 +579,20 @@ static inline list_T *buffer_to_tv_list(const char *const buf, const size_t len)
return l;
}
void on_channel_data(Stream *stream, RBuffer *buf, size_t count,
void *data, bool eof)
void on_channel_data(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_data);
}
void on_job_stderr(Stream *stream, RBuffer *buf, size_t count,
void *data, bool eof)
void on_job_stderr(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr);
}
static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf,
size_t count, bool eof, CallbackReader *reader)
static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf, size_t count, bool eof,
CallbackReader *reader)
{
// stub variable, to keep reading consistent with the order of events, only
// consider the count parameter.

View File

@@ -6,14 +6,15 @@
/// Code related to character sets.
#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include <wctype.h>
#include <inttypes.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/indent.h"
#include "nvim/main.h"
#include "nvim/mark.h"
@@ -21,15 +22,14 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/plines.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/path.h"
#include "nvim/cursor.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "charset.c.generated.h"
@@ -212,7 +212,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (i == 0) {
// (re)set ID flag
if (tilde) {
g_chartab[c] &= (uint8_t)~CT_ID_CHAR;
g_chartab[c] &= (uint8_t) ~CT_ID_CHAR;
} else {
g_chartab[c] |= CT_ID_CHAR;
}
@@ -224,7 +224,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (tilde) {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2));
g_chartab[c] &= (uint8_t)~CT_PRINT_CHAR;
g_chartab[c] &= (uint8_t) ~CT_PRINT_CHAR;
} else {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + 1);
g_chartab[c] |= CT_PRINT_CHAR;
@@ -233,7 +233,7 @@ int buf_init_chartab(buf_T *buf, int global)
} else if (i == 2) {
// (re)set fname flag
if (tilde) {
g_chartab[c] &= (uint8_t)~CT_FNAME_CHAR;
g_chartab[c] &= (uint8_t) ~CT_FNAME_CHAR;
} else {
g_chartab[c] |= CT_FNAME_CHAR;
}
@@ -417,7 +417,7 @@ char *transstr(const char *const s)
///
/// When "buf" is NULL, return an allocated string.
/// Otherwise, put the result in buf, limited by buflen, and return buf.
char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
char_u * str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
FUNC_ATTR_NONNULL_RET
{
garray_T ga;
@@ -906,8 +906,7 @@ bool in_win_border(win_T *wp, colnr_T vcol)
/// @param start
/// @param cursor
/// @param end
void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
colnr_T *end)
void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
{
colnr_T vcol;
char_u *ptr; // points to current char
@@ -1059,8 +1058,7 @@ colnr_T getvcol_nolist(pos_T *posp)
/// @param start
/// @param cursor
/// @param end
void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
colnr_T *end)
void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
{
colnr_T col;
colnr_T coladd;
@@ -1115,8 +1113,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
/// @param pos2
/// @param left
/// @param right
void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left,
colnr_T *right)
void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right)
{
colnr_T from1;
colnr_T from2;
@@ -1212,7 +1209,7 @@ char_u *skipdigits(const char_u *q)
/// @param q pointer to string
///
/// @return Pointer to the character after the skipped digits.
const char* skipbin(const char *q)
const char * skipbin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
@@ -1231,7 +1228,7 @@ const char* skipbin(const char *q)
///
/// @return Pointer to the character after the skipped digits and hex
/// characters.
char_u* skiphex(char_u *q)
char_u * skiphex(char_u *q)
{
char_u *p = q;
while (ascii_isxdigit(*p)) {
@@ -1246,7 +1243,7 @@ char_u* skiphex(char_u *q)
/// @param q
///
/// @return Pointer to the digit or (NUL after the string).
char_u* skiptodigit(char_u *q)
char_u * skiptodigit(char_u *q)
{
char_u *p = q;
while (*p != NUL && !ascii_isdigit(*p)) {
@@ -1261,7 +1258,7 @@ char_u* skiptodigit(char_u *q)
/// @param q pointer to string
///
/// @return Pointer to the binary character or (NUL after the string).
const char* skiptobin(const char *q)
const char * skiptobin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
@@ -1279,7 +1276,7 @@ const char* skiptobin(const char *q)
/// @param q
///
/// @return Pointer to the hex character or (NUL after the string).
char_u* skiptohex(char_u *q)
char_u * skiptohex(char_u *q)
{
char_u *p = q;
while (*p != NUL && !ascii_isxdigit(*p)) {
@@ -1308,7 +1305,7 @@ char_u *skiptowhite(const char_u *p)
/// @param p
///
/// @return Pointer to the next whitespace character.
char_u* skiptowhite_esc(char_u *p) {
char_u * skiptowhite_esc(char_u *p) {
while (*p != ' ' && *p != '\t' && *p != NUL) {
if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) {
++p;
@@ -1440,9 +1437,9 @@ bool vim_isblankline(char_u *lbuf)
/// @param strict If true, fail if the number has unexpected trailing
/// alpha-numeric chars: *len is set to 0 and nothing else is
/// returned.
void vim_str2nr(const char_u *const start, int *const prep, int *const len,
const int what, varnumber_T *const nptr,
uvarnumber_T *const unptr, const int maxlen, const bool strict)
void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what,
varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen,
const bool strict)
FUNC_ATTR_NONNULL_ARG(1)
{
const char *ptr = (const char *)start;
@@ -1464,7 +1461,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
// When forcing main consideration is skipping the prefix. Decimal numbers
// have no prefixes to skip. pre is not set.
switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) {
case STR2NR_HEX: {
case STR2NR_HEX:
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'x' || ptr[1] == 'X')
@@ -1472,8 +1469,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
ptr += 2;
}
goto vim_str2nr_hex;
}
case STR2NR_BIN: {
case STR2NR_BIN:
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'b' || ptr[1] == 'B')
@@ -1481,11 +1477,10 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
ptr += 2;
}
goto vim_str2nr_bin;
}
// Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
case STR2NR_OCT:
case STR2NR_OOCT:
case STR2NR_OCT | STR2NR_OOCT: {
case STR2NR_OCT | STR2NR_OOCT:
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'o' || ptr[1] == 'O')
@@ -1493,14 +1488,11 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
ptr += 2;
}
goto vim_str2nr_oct;
}
case 0: {
case 0:
goto vim_str2nr_dec;
}
default: {
default:
abort();
}
}
} else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN))
&& !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8'
&& ptr[1] != '9') {

View File

@@ -3,13 +3,13 @@
// Context: snapshot of the entire editor state as one big object/map
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/context.h"
#include "nvim/eval/encode.h"
#include "nvim/ex_docmd.h"
#include "nvim/option.h"
#include "nvim/shada.h"
#include "nvim/api/vim.h"
#include "nvim/api/private/helpers.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "context.c.generated.h"

View File

@@ -1,25 +1,25 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdbool.h>
#include <inttypes.h>
#include <stdbool.h>
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/extmark.h"
#include "nvim/fold.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/plines.h"
#include "nvim/screen.h"
#include "nvim/extmark.h"
#include "nvim/state.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/mark.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor.c.generated.h"
@@ -63,7 +63,7 @@ int coladvance_force(colnr_T wcol)
if (wcol == MAXCOL) {
curwin->w_valid &= ~VALID_VIRTCOL;
} else {
/* Virtcol is valid */
// Virtcol is valid
curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol;
}
@@ -83,22 +83,20 @@ int coladvance(colnr_T wcol)
{
int rc = getvpos(&curwin->w_cursor, wcol);
if (wcol == MAXCOL || rc == FAIL)
if (wcol == MAXCOL || rc == FAIL) {
curwin->w_valid &= ~VALID_VIRTCOL;
else if (*get_cursor_pos_ptr() != TAB) {
/* Virtcol is valid when not on a TAB */
} else if (*get_cursor_pos_ptr() != TAB) {
// Virtcol is valid when not on a TAB
curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol;
}
return rc;
}
static int coladvance2(
pos_T *pos,
bool addspaces, // change the text to achieve our goal?
static int coladvance2(pos_T *pos, bool addspaces, // change the text to achieve our goal?
bool finetune, // change char offset for the exact column
colnr_T wcol_arg // column to move to (can be negative)
)
)
{
colnr_T wcol = wcol_arg;
int idx;
@@ -121,9 +119,10 @@ static int coladvance2(
if ((addspaces || finetune) && !VIsual_active) {
curwin->w_curswant = linetabsize(line) + one_more;
if (curwin->w_curswant > 0)
if (curwin->w_curswant > 0) {
--curwin->w_curswant;
}
}
} else {
int width = curwin->w_width_inner - win_col_off(curwin);
@@ -133,8 +132,9 @@ static int coladvance2(
&& wcol >= (colnr_T)width
&& width > 0) {
csize = linetabsize(line);
if (csize > 0)
if (csize > 0) {
csize--;
}
if (wcol / width > (colnr_T)csize / width
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
@@ -148,7 +148,7 @@ static int coladvance2(
ptr = line;
while (col <= wcol && *ptr != NUL) {
/* Count a tab for what it's worth (if list mode not on) */
// Count a tab for what it's worth (if list mode not on)
csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
MB_PTR_ADV(ptr);
col += csize;
@@ -162,7 +162,7 @@ static int coladvance2(
*/
if (col > wcol || (!virtual_active() && one_more == 0)) {
idx -= 1;
/* Don't count the chars from 'showbreak'. */
// Don't count the chars from 'showbreak'.
csize -= head;
col -= csize;
}
@@ -175,7 +175,7 @@ static int coladvance2(
* filled with spaces. */
if (line[idx] == NUL) {
/* Append spaces */
// Append spaces
int correct = wcol - col;
size_t newline_size;
STRICT_ADD(idx, correct, &newline_size, size_t);
@@ -188,13 +188,14 @@ static int coladvance2(
idx += correct;
col = wcol;
} else {
/* Break a tab */
// Break a tab
int linelen = (int)STRLEN(line);
int correct = wcol - col - csize + 1; /* negative!! */
int correct = wcol - col - csize + 1; // negative!!
char_u *newline;
if (-correct > csize)
if (-correct > csize) {
return FAIL;
}
size_t n;
STRICT_ADD(linelen - 1, csize, &n, size_t);
@@ -216,16 +217,17 @@ static int coladvance2(
}
}
if (idx < 0)
if (idx < 0) {
pos->col = 0;
else
} else {
pos->col = idx;
}
pos->coladd = 0;
if (finetune) {
if (wcol == MAXCOL) {
/* The width of the last character is used to set coladd. */
// The width of the last character is used to set coladd.
if (!one_more) {
colnr_T scol, ecol;
@@ -340,11 +342,13 @@ void check_cursor_lnum(void)
/* If there is a closed fold at the end of the file, put the cursor in
* its first line. Otherwise in the last line. */
if (!hasFolding(curbuf->b_ml.ml_line_count,
&curwin->w_cursor.lnum, NULL))
&curwin->w_cursor.lnum, NULL)) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
if (curwin->w_cursor.lnum <= 0)
}
if (curwin->w_cursor.lnum <= 0) {
curwin->w_cursor.lnum = 1;
}
}
/*
@@ -430,8 +434,9 @@ void adjust_cursor_col(void)
{
if (curwin->w_cursor.col > 0
&& (!VIsual_active || *p_sel == 'o')
&& gchar_cursor() == NUL)
&& gchar_cursor() == NUL) {
--curwin->w_cursor.col;
}
}
/*
@@ -473,14 +478,15 @@ bool leftcol_changed(void)
coladvance(s - 1);
} else if (s < curwin->w_leftcol) {
retval = true;
if (coladvance(e + 1) == FAIL) { /* there isn't another character */
curwin->w_leftcol = s; /* adjust w_leftcol instead */
if (coladvance(e + 1) == FAIL) { // there isn't another character
curwin->w_leftcol = s; // adjust w_leftcol instead
changed_cline_bef_curs();
}
}
if (retval)
if (retval) {
curwin->w_set_curswant = true;
}
redraw_later(curwin, NOT_VALID);
return retval;
}

View File

@@ -3,15 +3,16 @@
#include <assert.h>
#include <stdint.h>
#include "nvim/vim.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cursor_shape.h"
#include "nvim/ex_getln.h"
#include "nvim/charset.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor_shape.c.generated.h"
@@ -56,10 +57,14 @@ Array mode_style_array(void)
if (cur->used_for & SHAPE_CURSOR) {
String shape_str;
switch (cur->shape) {
case SHAPE_BLOCK: shape_str = cstr_to_string("block"); break;
case SHAPE_VER: shape_str = cstr_to_string("vertical"); break;
case SHAPE_HOR: shape_str = cstr_to_string("horizontal"); break;
default: shape_str = cstr_to_string("unknown");
case SHAPE_BLOCK:
shape_str = cstr_to_string("block"); break;
case SHAPE_VER:
shape_str = cstr_to_string("vertical"); break;
case SHAPE_HOR:
shape_str = cstr_to_string("horizontal"); break;
default:
shape_str = cstr_to_string("unknown");
}
PUT(dic, "cursor_shape", STRING_OBJ(shape_str));
PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage));
@@ -142,15 +147,19 @@ char_u *parse_shape_opt(int what)
if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') {
all_idx = SHAPE_IDX_COUNT - 1;
} else {
for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx)
if (STRNICMP(modep, shape_table[idx].name, len) == 0)
for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) {
if (STRNICMP(modep, shape_table[idx].name, len) == 0) {
break;
}
}
if (idx == SHAPE_IDX_COUNT
|| (shape_table[idx].used_for & what) == 0)
|| (shape_table[idx].used_for & what) == 0) {
return (char_u *)N_("E546: Illegal mode");
if (len == 2 && modep[0] == 'v' && modep[1] == 'e')
}
if (len == 2 && modep[0] == 'v' && modep[1] == 'e') {
found_ve = true;
}
}
modep += len + 1;
}
@@ -158,7 +167,7 @@ char_u *parse_shape_opt(int what)
idx = all_idx--;
}
/* Parse the part after the colon */
// Parse the part after the colon
for (p = colonp + 1; *p && *p != ','; ) {
{
/*
@@ -166,20 +175,22 @@ char_u *parse_shape_opt(int what)
*/
i = *p;
len = 0;
if (STRNICMP(p, "ver", 3) == 0)
if (STRNICMP(p, "ver", 3) == 0) {
len = 3;
else if (STRNICMP(p, "hor", 3) == 0)
} else if (STRNICMP(p, "hor", 3) == 0) {
len = 3;
else if (STRNICMP(p, "blinkwait", 9) == 0)
} else if (STRNICMP(p, "blinkwait", 9) == 0) {
len = 9;
else if (STRNICMP(p, "blinkon", 7) == 0)
} else if (STRNICMP(p, "blinkon", 7) == 0) {
len = 7;
else if (STRNICMP(p, "blinkoff", 8) == 0)
} else if (STRNICMP(p, "blinkoff", 8) == 0) {
len = 8;
}
if (len != 0) {
p += len;
if (!ascii_isdigit(*p))
if (!ascii_isdigit(*p)) {
return (char_u *)N_("E548: digit expected");
}
int n = getdigits_int(&p, false, 0);
if (len == 3) { // "ver" or "hor"
if (n == 0) {
@@ -194,28 +205,31 @@ char_u *parse_shape_opt(int what)
shape_table[idx].percentage = n;
}
} else if (round == 2) {
if (len == 9)
if (len == 9) {
shape_table[idx].blinkwait = n;
else if (len == 7)
} else if (len == 7) {
shape_table[idx].blinkon = n;
else
} else {
shape_table[idx].blinkoff = n;
}
}
} else if (STRNICMP(p, "block", 5) == 0) {
if (round == 2)
if (round == 2) {
shape_table[idx].shape = SHAPE_BLOCK;
}
p += 5;
} else { /* must be a highlight group name then */
} else { // must be a highlight group name then
endp = vim_strchr(p, '-');
if (commap == NULL) { /* last part */
if (endp == NULL)
endp = p + STRLEN(p); /* find end of part */
if (commap == NULL) { // last part
if (endp == NULL) {
endp = p + STRLEN(p); // find end of part
}
} else if (endp > commap || endp == NULL) {
endp = commap;
}
slashp = vim_strchr(p, '/');
if (slashp != NULL && slashp < endp) {
/* "group/langmap_group" */
// "group/langmap_group"
i = syn_check_group(p, (int)(slashp - p));
p = slashp + 1;
}
@@ -223,17 +237,19 @@ char_u *parse_shape_opt(int what)
shape_table[idx].id = syn_check_group(p,
(int)(endp - p));
shape_table[idx].id_lm = shape_table[idx].id;
if (slashp != NULL && slashp < endp)
if (slashp != NULL && slashp < endp) {
shape_table[idx].id = i;
}
}
p = endp;
}
} /* if (what != SHAPE_MOUSE) */
} // if (what != SHAPE_MOUSE)
if (*p == '-')
if (*p == '-') {
++p;
}
}
}
modep = p;
if (modep != NULL && *modep == ',') {
modep++;
@@ -241,7 +257,7 @@ char_u *parse_shape_opt(int what)
}
}
/* If the 's' flag is not given, use the 'v' cursor for 's' */
// If the 's' flag is not given, use the 'v' cursor for 's'
if (!found_ve) {
{
shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape;

View File

@@ -4251,8 +4251,8 @@ static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr)
options += WILD_ICASE;
}
if (rettv->v_type == VAR_STRING) {
rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(
&argvars[0]), NULL, options, WILD_ALL);
rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
WILD_ALL);
} else {
ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
WILD_ALL_KEEP);
@@ -6564,8 +6564,8 @@ static void msgpackparse_unpack_list(const list_T *const list, list_T *const ret
goto end;
}
size_t read_bytes;
const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(
unpacker), IOSIZE, &read_bytes);
const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(unpacker), IOSIZE,
&read_bytes);
if (rlret == FAIL) {
EMSG2(_(e_invarg2), "List item is not a string");
goto end;
@@ -9275,7 +9275,8 @@ static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const bool do_special = non_zero_arg(&argvars[1]);
rettv->vval.v_string = vim_strsave_shellescape((const char_u *)tv_get_string(
&argvars[0]), do_special, do_special);
&argvars[0]), do_special,
do_special);
rettv->v_type = VAR_STRING;
}

View File

@@ -1,33 +1,31 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <assert.h>
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/assert.h"
#include "nvim/func_attr.h"
#include "nvim/memory.h"
#include "nvim/assert.h"
// FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is
// redefined
#include "nvim/vim.h"
#include "nvim/globals.h"
#include "nvim/message.h"
#include "nvim/ascii.h"
#include "nvim/eval/decode.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/ascii.h"
#include "nvim/macros.h"
#include "nvim/globals.h"
#include "nvim/lib/kvec.h"
#include "nvim/eval/decode.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/macros.h"
#include "nvim/message.h"
#include "nvim/vim.h"
/// Determine, which keys lua table contains
typedef struct {
@@ -118,11 +116,10 @@ static LuaTableProps nlua_traverse_table(lua_State *const lstate)
}
break;
}
default: {
default:
other_keys_num++;
break;
}
}
tsize++;
lua_pop(lstate, 1);
}
@@ -283,18 +280,16 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
.vval = { .v_number = 0 },
};
switch (lua_type(lstate, -1)) {
case LUA_TNIL: {
case LUA_TNIL:
cur.tv->v_type = VAR_SPECIAL;
cur.tv->vval.v_special = kSpecialVarNull;
break;
}
case LUA_TBOOLEAN: {
case LUA_TBOOLEAN:
cur.tv->v_type = VAR_BOOL;
cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
? kBoolVarTrue
: kBoolVarFalse);
break;
}
case LUA_TSTRING: {
size_t len;
const char *s = lua_tolstring(lstate, -1, &len);
@@ -336,7 +331,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
}
switch (table_props.type) {
case kObjectTypeArray: {
case kObjectTypeArray:
cur.tv->v_type = VAR_LIST;
cur.tv->vval.v_list = tv_list_alloc((ptrdiff_t)table_props.maxidx);
cur.tv->vval.v_list->lua_table_ref = table_ref;
@@ -347,8 +342,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
kvi_push(stack, cur);
}
break;
}
case kObjectTypeDictionary: {
case kObjectTypeDictionary:
if (table_props.string_keys_num == 0) {
cur.tv->v_type = VAR_DICT;
cur.tv->vval.v_dict = tv_dict_alloc();
@@ -357,8 +351,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
} else {
cur.special = table_props.has_string_with_nul;
if (table_props.has_string_with_nul) {
decode_create_map_special_dict(
cur.tv, (ptrdiff_t)table_props.string_keys_num);
decode_create_map_special_dict(cur.tv, (ptrdiff_t)table_props.string_keys_num);
assert(cur.tv->v_type == VAR_DICT);
dictitem_T *const val_di = tv_dict_find(cur.tv->vval.v_dict,
S_LEN("_VAL"));
@@ -378,23 +371,19 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
lua_pushnil(lstate);
}
break;
}
case kObjectTypeFloat: {
case kObjectTypeFloat:
cur.tv->v_type = VAR_FLOAT;
cur.tv->vval.v_float = (float_T)table_props.val;
break;
}
case kObjectTypeNil: {
case kObjectTypeNil:
EMSG(_("E5100: Cannot convert given lua table: table "
"should either have a sequence of positive integer keys "
"or contain only string keys"));
ret = false;
break;
}
default: {
default:
abort();
}
}
nlua_pop_typval_table_processing_end:
break;
}
@@ -402,8 +391,7 @@ nlua_pop_typval_table_processing_end:
LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
state->lua_callable.func_ref = nlua_ref(lstate, -1);
char_u *name = register_cfunc(
&nlua_CFunction_func_call,
char_u *name = register_cfunc(&nlua_CFunction_func_call,
&nlua_CFunction_func_free,
state);
@@ -425,12 +413,11 @@ nlua_pop_typval_table_processing_end:
}
break;
}
default: {
default:
EMSG(_("E5101: Cannot convert given lua type"));
ret = false;
break;
}
}
if (!cur.container) {
lua_pop(lstate, 1);
}
@@ -674,9 +661,7 @@ static inline void nlua_push_type(lua_State *lstate, ObjectType type)
/// @param[in] narr Number of “array” entries to be populated later.
/// @param[in] nrec Number of “dictionary” entries to be populated later.
/// @param[in] type Type of the table.
static inline void nlua_create_typed_table(lua_State *lstate,
const size_t narr,
const size_t nrec,
static inline void nlua_create_typed_table(lua_State *lstate, const size_t narr, const size_t nrec,
const ObjectType type)
FUNC_ATTR_NONNULL_ALL
{
@@ -733,8 +718,7 @@ void nlua_push_Boolean(lua_State *lstate, const Boolean b, bool special)
/// Convert given Dictionary to lua table
///
/// Leaves converted table on top of the stack.
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict,
bool special)
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, bool special)
FUNC_ATTR_NONNULL_ALL
{
if (dict.size == 0 && special) {
@@ -767,9 +751,9 @@ void nlua_push_Array(lua_State *lstate, const Array array, bool special)
}
#define GENERATE_INDEX_FUNCTION(type) \
void nlua_push_##type(lua_State *lstate, const type item, bool special) \
void nlua_push_##type(lua_State *lstate, const type item, bool special) \
FUNC_ATTR_NONNULL_ALL \
{ \
{ \
lua_pushnumber(lstate, (lua_Number)(item)); \
}
@@ -786,23 +770,22 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
FUNC_ATTR_NONNULL_ALL
{
switch (obj.type) {
case kObjectTypeNil: {
case kObjectTypeNil:
if (special) {
lua_pushnil(lstate);
} else {
nlua_pushref(lstate, nlua_nil_ref);
}
break;
}
case kObjectTypeLuaRef: {
nlua_pushref(lstate, obj.data.luaref);
break;
}
#define ADD_TYPE(type, data_key) \
case kObjectType##type: { \
case kObjectType##type: { \
nlua_push_##type(lstate, obj.data.data_key, special); \
break; \
}
}
ADD_TYPE(Boolean, boolean)
ADD_TYPE(Integer, integer)
ADD_TYPE(Float, floating)
@@ -811,10 +794,10 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
ADD_TYPE(Dictionary, dictionary)
#undef ADD_TYPE
#define ADD_REMOTE_TYPE(type) \
case kObjectType##type: { \
case kObjectType##type: { \
nlua_push_##type(lstate, (type)obj.data.integer, special); \
break; \
}
}
ADD_REMOTE_TYPE(Buffer)
ADD_REMOTE_TYPE(Window)
ADD_REMOTE_TYPE(Tabpage)
@@ -883,8 +866,7 @@ Boolean nlua_pop_Boolean(lua_State *lstate, Error *err)
/// @param[in] type Type to check.
///
/// @return @see nlua_traverse_table().
static inline LuaTableProps nlua_check_type(lua_State *const lstate,
Error *const err,
static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *const err,
const ObjectType type)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -937,8 +919,7 @@ Float nlua_pop_Float(lua_State *lstate, Error *err)
/// @param lstate Lua state.
/// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved.
static Array nlua_pop_Array_unchecked(lua_State *const lstate,
const LuaTableProps table_props,
static Array nlua_pop_Array_unchecked(lua_State *const lstate, const LuaTableProps table_props,
Error *const err)
{
Array ret = { .size = table_props.maxidx, .items = NULL };
@@ -990,10 +971,8 @@ Array nlua_pop_Array(lua_State *lstate, Error *err)
/// @param lstate Lua interpreter state.
/// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved.
static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate,
const LuaTableProps table_props,
bool ref,
Error *err)
static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate, const LuaTableProps table_props,
bool ref, Error *err)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
Dictionary ret = { .size = table_props.string_keys_num, .items = NULL };
@@ -1138,13 +1117,11 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
assert(!cur.container);
*cur.obj = NIL;
switch (lua_type(lstate, -1)) {
case LUA_TNIL: {
case LUA_TNIL:
break;
}
case LUA_TBOOLEAN: {
case LUA_TBOOLEAN:
*cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1));
break;
}
case LUA_TSTRING: {
size_t len;
const char *s = lua_tolstring(lstate, -1, &len);
@@ -1168,7 +1145,7 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
const LuaTableProps table_props = nlua_traverse_table(lstate);
switch (table_props.type) {
case kObjectTypeArray: {
case kObjectTypeArray:
*cur.obj = ARRAY_OBJ(((Array) {
.items = NULL,
.size = 0,
@@ -1183,8 +1160,7 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
kvi_push(stack, cur);
}
break;
}
case kObjectTypeDictionary: {
case kObjectTypeDictionary:
*cur.obj = DICTIONARY_OBJ(((Dictionary) {
.items = NULL,
.size = 0,
@@ -1200,31 +1176,26 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
lua_pushnil(lstate);
}
break;
}
case kObjectTypeFloat: {
case kObjectTypeFloat:
*cur.obj = FLOAT_OBJ((Float)table_props.val);
break;
}
case kObjectTypeNil: {
case kObjectTypeNil:
api_set_error(err, kErrorTypeValidation,
"Cannot convert given lua table");
break;
}
default: {
default:
abort();
}
}
break;
}
case LUA_TFUNCTION: {
case LUA_TFUNCTION:
if (ref) {
*cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
} else {
goto type_error;
}
break;
}
case LUA_TUSERDATA: {
nlua_pushref(lstate, nlua_nil_ref);
@@ -1239,13 +1210,12 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
break;
}
default: {
default:
type_error:
api_set_error(err, kErrorTypeValidation,
"Cannot convert given lua type");
break;
}
}
if (!cur.container) {
lua_pop(lstate, 1);
}
@@ -1268,14 +1238,14 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
}
#define GENERATE_INDEX_FUNCTION(type) \
type nlua_pop_##type(lua_State *lstate, Error *err) \
type nlua_pop_##type(lua_State *lstate, Error *err) \
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
{ \
{ \
type ret; \
ret = (type)lua_tonumber(lstate, -1); \
lua_pop(lstate, 1); \
return ret; \
}
}
GENERATE_INDEX_FUNCTION(Buffer)
GENERATE_INDEX_FUNCTION(Window)

View File

@@ -1,48 +1,45 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "nvim/assert.h"
#include "nvim/version.h"
#include "nvim/misc1.h"
#include "nvim/getchar.h"
#include "nvim/garray.h"
#include "nvim/func_attr.h"
#include "luv/luv.h"
#include "mpack/lmpack.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/vim.h"
#include "nvim/extmark.h"
#include "nvim/ex_getln.h"
#include "nvim/ex_cmds2.h"
#include "nvim/map.h"
#include "nvim/message.h"
#include "nvim/memline.h"
#include "nvim/buffer_defs.h"
#include "nvim/regexp.h"
#include "nvim/macros.h"
#include "nvim/screen.h"
#include "nvim/cursor.h"
#include "nvim/undo.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/buffer_defs.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/eval/userfunc.h"
#include "nvim/event/time.h"
#include "nvim/event/loop.h"
#include "mpack/lmpack.h"
#include "nvim/os/os.h"
#include "nvim/event/time.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/lua/treesitter.h"
#include "nvim/lua/xdiff.h"
#include "luv/luv.h"
#include "nvim/macros.h"
#include "nvim/map.h"
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/os/os.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/undo.h"
#include "nvim/version.h"
#include "nvim/vim.h"
static int in_fast_callback = 0;
@@ -55,8 +52,8 @@ typedef struct {
} LuaError;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "lua/vim_module.generated.h"
# include "lua/executor.c.generated.h"
# include "lua/vim_module.generated.h"
#endif
#define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \
@@ -69,8 +66,8 @@ typedef struct {
}
#if __has_feature(address_sanitizer)
static PMap(handle_T) nlua_ref_markers = MAP_INIT;
static bool nlua_track_refs = false;
static PMap(handle_T) nlua_ref_markers = MAP_INIT;
static bool nlua_track_refs = false;
# define NLUA_TRACK_REFS
#endif
@@ -216,8 +213,7 @@ static void nlua_luv_error_event(void **argv)
xfree(error);
}
static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult,
int flags)
static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags)
FUNC_ATTR_NONNULL_ALL
{
int retval;
@@ -300,8 +296,7 @@ static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
xfree(tw);
}
static bool nlua_wait_condition(lua_State *lstate, int *status,
bool *callback_result)
static bool nlua_wait_condition(lua_State *lstate, int *status, bool *callback_result)
{
lua_pushvalue(lstate, 2);
*status = lua_pcall(lstate, 0, 1, 0);
@@ -336,8 +331,7 @@ static int nlua_wait(lua_State *lstate)
}
if (!is_function) {
lua_pushliteral(
lstate,
lua_pushliteral(lstate,
"vim.wait: if passed, condition must be a function");
return lua_error(lstate);
}
@@ -365,8 +359,7 @@ static int nlua_wait(lua_State *lstate)
time_watcher_init(&main_loop, tw, NULL);
tw->events = loop_events;
tw->blockable = true;
time_watcher_start(
tw,
time_watcher_start(tw,
dummy_timer_due_cb,
(uint64_t)interval,
(uint64_t)interval);
@@ -374,12 +367,10 @@ static int nlua_wait(lua_State *lstate)
int pcall_status = 0;
bool callback_result = false;
LOOP_PROCESS_EVENTS_UNTIL(
&main_loop,
LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
loop_events,
(int)timeout,
is_function ? nlua_wait_condition(
lstate,
is_function ? nlua_wait_condition(lstate,
&pcall_status,
&callback_result) : false || got_int);
@@ -663,23 +654,20 @@ static void nlua_print_event(void **argv)
const size_t start = i;
while (i < len) {
switch (str[i]) {
case NUL: {
case NUL:
str[i] = NL;
i++;
continue;
}
case NL: {
case NL:
// TODO(bfredl): use proper multiline msg? Probably should implement
// print() in lua in terms of nvim_message(), when it is available.
str[i] = NUL;
i++;
break;
}
default: {
default:
i++;
continue;
}
}
break;
}
msg((char_u *)str + start);
@@ -719,8 +707,7 @@ static int nlua_print(lua_State *const lstate)
size_t len;
const char *const s = lua_tolstring(lstate, -1, &len);
if (s == NULL) {
PRINT_ERROR(
"<Unknown error: lua_tolstring returned NULL for tostring result>");
PRINT_ERROR("<Unknown error: lua_tolstring returned NULL for tostring result>");
}
ga_concat_len(&msg_ga, s, len);
if (curargidx < nargs) {
@@ -893,7 +880,7 @@ static int nlua_rpc(lua_State *lstate, bool request)
} else {
if (!rpc_send_event(chan_id, name, args)) {
api_set_error(&err, kErrorTypeValidation,
"Invalid channel: %"PRIu64, chan_id);
"Invalid channel: %" PRIu64, chan_id);
}
}
@@ -1108,8 +1095,7 @@ LuaRef api_new_luaref(LuaRef original_ref)
/// @param[out] ret_tv Location where result will be saved.
///
/// @return Result of the execution.
void nlua_typval_eval(const String str, typval_T *const arg,
typval_T *const ret_tv)
void nlua_typval_eval(const String str, typval_T *const arg, typval_T *const ret_tv)
FUNC_ATTR_NONNULL_ALL
{
#define EVALHEADER "local _A=select(1,...) return ("
@@ -1131,8 +1117,8 @@ void nlua_typval_eval(const String str, typval_T *const arg,
}
}
void nlua_typval_call(const char *str, size_t len, typval_T *const args,
int argcount, typval_T *ret_tv)
void nlua_typval_call(const char *str, size_t len, typval_T *const args, int argcount,
typval_T *ret_tv)
FUNC_ATTR_NONNULL_ALL
{
#define CALLHEADER "return "
@@ -1158,9 +1144,8 @@ void nlua_typval_call(const char *str, size_t len, typval_T *const args,
}
}
static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
const char *name, typval_T *const args,
int argcount, bool special, typval_T *ret_tv)
static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name,
typval_T *const args, int argcount, bool special, typval_T *ret_tv)
{
if (check_secure()) {
if (ret_tv) {
@@ -1188,8 +1173,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
}
}
int nlua_source_using_linegetter(LineGetter fgetline,
void *cookie, char *name)
int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
{
const linenr_T save_sourcing_lnum = sourcing_lnum;
const sctx_T save_current_sctx = current_sctx;
@@ -1225,13 +1209,8 @@ int nlua_source_using_linegetter(LineGetter fgetline,
/// @param[in] argcount Count of typval arguments
/// @param[in] argvars Typval Arguments
/// @param[out] rettv The return value from the called function.
int typval_exec_lua_callable(
lua_State *lstate,
LuaCallable lua_cb,
int argcount,
typval_T *argvars,
typval_T *rettv
)
int typval_exec_lua_callable(lua_State *lstate, LuaCallable lua_cb, int argcount, typval_T *argvars,
typval_T *rettv)
{
LuaRef cb = lua_cb.func_ref;
@@ -1294,8 +1273,7 @@ Object nlua_exec(const String str, const Array args, Error *err)
/// if false, discard return value
/// @param err Error details, if any (if NULL, errors are echoed)
/// @return Return value of function, if retval was set. Otherwise NIL.
Object nlua_call_ref(LuaRef ref, const char *name, Array args,
bool retval, Error *err)
Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Error *err)
{
lua_State *const lstate = global_lstate;
nlua_pushref(lstate, ref);
@@ -1502,10 +1480,7 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_setfield(lstate, -2, "_ts_get_language_version");
}
int nlua_expand_pat(expand_T *xp,
char_u *pat,
int *num_results,
char_u ***results)
int nlua_expand_pat(expand_T *xp, char_u *pat, int *num_results, char_u ***results)
{
lua_State *const lstate = global_lstate;
int ret = OK;
@@ -1521,8 +1496,7 @@ int nlua_expand_pat(expand_T *xp,
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
if (lua_pcall(lstate, 1, 2, 0) != 0) {
nlua_error(
lstate,
nlua_error(lstate,
_("Error executing vim._expand_pat: %.*s"));
return FAIL;
}
@@ -1554,8 +1528,7 @@ int nlua_expand_pat(expand_T *xp,
goto cleanup_array;
}
GA_APPEND(
char_u *,
GA_APPEND(char_u *,
&result_array,
vim_strsave((char_u *)v.data.string.data));
}
@@ -1711,11 +1684,7 @@ static int regex_match_line(lua_State *lstate)
// Required functions for lua c functions as VimL callbacks
int nlua_CFunction_func_call(
int argcount,
typval_T *argvars,
typval_T *rettv,
void *state)
int nlua_CFunction_func_call(int argcount, typval_T *argvars, typval_T *rettv, void *state)
{
lua_State *const lstate = global_lstate;
LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
@@ -1813,8 +1782,7 @@ void nlua_execute_on_key(int c)
lua_pushlstring(lstate, (const char *)buf, buf_len);
if (lua_pcall(lstate, 1, 0, 0)) {
nlua_error(
lstate,
nlua_error(lstate,
_("Error executing vim.on_key Lua callback: %.*s"));
}

View File

@@ -5,22 +5,20 @@
// NB: this file mostly contains a generic lua interface for tree-sitter
// trees and nodes, and could be broken out as a reusable lua package
#include <assert.h>
#include <inttypes.h>
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "tree_sitter/api.h"
#include "nvim/lua/treesitter.h"
#include "nvim/api/private/helpers.h"
#include "nvim/memline.h"
#include "nvim/buffer.h"
#include "nvim/lua/treesitter.h"
#include "nvim/memline.h"
#include "tree_sitter/api.h"
#define TS_META_PARSER "treesitter_parser"
#define TS_META_TREE "treesitter_tree"
@@ -179,8 +177,7 @@ int tslua_add_language(lua_State *L)
uint32_t lang_version = ts_language_version(lang);
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) {
return luaL_error(
L,
return luaL_error(L,
"ABI version mismatch for %s: supported between %d and %d, found %d",
path,
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
@@ -285,8 +282,8 @@ static int parser_tostring(lua_State *L)
return 1;
}
static const char *input_cb(void *payload, uint32_t byte_index,
TSPoint position, uint32_t *bytes_read)
static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position,
uint32_t *bytes_read)
{
buf_T *bp = payload;
#define BUFSIZE 256
@@ -318,9 +315,7 @@ static const char *input_cb(void *payload, uint32_t byte_index,
#undef BUFSIZE
}
static void push_ranges(lua_State *L,
const TSRange *ranges,
const unsigned int length)
static void push_ranges(lua_State *L, const TSRange *ranges, const unsigned int length)
{
lua_createtable(L, length, 0);
for (size_t i = 0; i < length; i++) {
@@ -393,8 +388,7 @@ static int parser_parse(lua_State *L)
// the lua GC.
// Old tree is still owned by the lua GC.
uint32_t n_ranges = 0;
TSRange *changed = old_tree ? ts_tree_get_changed_ranges(
old_tree, new_tree, &n_ranges) : NULL;
TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) : NULL;
push_tree(L, new_tree, false); // [tree]
@@ -504,16 +498,14 @@ static void range_from_lua(lua_State *L, TSRange *range)
}
return;
error:
luaL_error(
L,
luaL_error(L,
"Ranges can only be made from 6 element long tables or nodes.");
}
static int parser_set_ranges(lua_State *L)
{
if (lua_gettop(L) < 2) {
return luaL_error(
L,
return luaL_error(L,
"not enough args to parser:set_included_ranges()");
}
@@ -523,8 +515,7 @@ static int parser_set_ranges(lua_State *L)
}
if (!lua_istable(L, 2)) {
return luaL_error(
L,
return luaL_error(L,
"argument for parser:set_included_ranges() should be a table.");
}
@@ -917,8 +908,7 @@ static int node_named_descendant_for_range(lua_State *L)
static int node_next_child(lua_State *L)
{
TSTreeCursor *ud = luaL_checkudata(
L, lua_upvalueindex(1), TS_META_TREECURSOR);
TSTreeCursor *ud = luaL_checkudata(L, lua_upvalueindex(1), TS_META_TREECURSOR);
if (!ud) {
return 0;
}
@@ -939,8 +929,7 @@ static int node_next_child(lua_State *L)
if (ts_tree_cursor_goto_next_sibling(ud)) {
push:
push_node(
L,
push_node(L,
ts_tree_cursor_current_node(ud),
lua_upvalueindex(2)); // [node]
@@ -1200,11 +1189,16 @@ int tslua_parse_query(lua_State *L)
static const char *query_err_string(TSQueryError err) {
switch (err) {
case TSQueryErrorSyntax: return "invalid syntax";
case TSQueryErrorNodeType: return "invalid node type";
case TSQueryErrorField: return "invalid field";
case TSQueryErrorCapture: return "invalid capture";
default: return "error";
case TSQueryErrorSyntax:
return "invalid syntax";
case TSQueryErrorNodeType:
return "invalid node type";
case TSQueryErrorField:
return "invalid field";
case TSQueryErrorCapture:
return "invalid capture";
default:
return "error";
}
}

View File

@@ -1,18 +1,17 @@
#include <errno.h>
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "nvim/vim.h"
#include "xdiff/xdiff.h"
#include "nvim/lua/xdiff.h"
#include "nvim/api/private/helpers.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/api/private/helpers.h"
#include "nvim/lua/xdiff.h"
#include "nvim/vim.h"
#include "xdiff/xdiff.h"
typedef enum {
kNluaXdiffModeUnified = 0,
@@ -48,8 +47,7 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf)
}
// hunk_func callback used when opts.hunk_lines = true
static int hunk_locations_cb(long start_a, long count_a,
long start_b, long count_b, void *cb_data)
static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
{
// Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284
@@ -79,8 +77,7 @@ static int hunk_locations_cb(long start_a, long count_a,
}
// hunk_func callback used when opts.on_hunk is given
static int call_on_hunk_cb(long start_a, long count_a,
long start_b, long count_b, void *cb_data)
static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
{
// Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284
@@ -130,8 +127,7 @@ static mmfile_t get_string_arg(lua_State *lstate, int idx)
}
// Helper function for validating option types
static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
const char *name, Error *err)
static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char *name, Error *err)
{
if (actType != expType) {
const char * type_str =
@@ -149,9 +145,8 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
return false;
}
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate,
xdemitconf_t *cfg,
xpparam_t *params, Error *err)
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
Error *err)
{
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
@@ -211,13 +206,13 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate,
const char *name;
unsigned long value;
} flags[] = {
{ "ignore_whitespace" , XDF_IGNORE_WHITESPACE },
{ "ignore_whitespace_change" , XDF_IGNORE_WHITESPACE_CHANGE },
{ "ignore_whitespace", XDF_IGNORE_WHITESPACE },
{ "ignore_whitespace_change", XDF_IGNORE_WHITESPACE_CHANGE },
{ "ignore_whitespace_change_at_eol", XDF_IGNORE_WHITESPACE_AT_EOL },
{ "ignore_cr_at_eol" , XDF_IGNORE_CR_AT_EOL },
{ "ignore_blank_lines" , XDF_IGNORE_BLANK_LINES },
{ "indent_heuristic" , XDF_INDENT_HEURISTIC },
{ NULL , 0 },
{ "ignore_cr_at_eol", XDF_IGNORE_CR_AT_EOL },
{ "ignore_blank_lines", XDF_IGNORE_BLANK_LINES },
{ "indent_heuristic", XDF_INDENT_HEURISTIC },
{ NULL, 0 },
};
bool key_used = false;
for (size_t j = 0; flags[j].name; j++) {
@@ -270,9 +265,9 @@ int nlua_xdl_diff(lua_State *lstate)
xpparam_t params;
xdemitcb_t ecb;
memset(&cfg , 0, sizeof(cfg));
memset(&cfg, 0, sizeof(cfg));
memset(&params, 0, sizeof(params));
memset(&ecb , 0, sizeof(ecb));
memset(&ecb, 0, sizeof(ecb));
NluaXdiffMode mode = kNluaXdiffModeUnified;