aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/indent_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/indent_c.c')
-rw-r--r--src/nvim/indent_c.c150
1 files changed, 70 insertions, 80 deletions
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index c5e030ce25..166695ef5b 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -212,19 +212,17 @@ int is_pos_in_string(const char_u *line, colnr_T col)
* Below "XXX" means that this function may unlock the current line.
*/
-/*
- * Return true if the string "line" starts with a word from 'cinwords'.
- */
-bool cin_is_cinword(const char_u *line)
+/// @return true if the string "line" starts with a word from 'cinwords'.
+bool cin_is_cinword(const char *line)
{
bool retval = false;
size_t cinw_len = STRLEN(curbuf->b_p_cinw) + 1;
char_u *cinw_buf = xmalloc(cinw_len);
- line = (char_u *)skipwhite((char *)line);
+ line = skipwhite((char *)line);
- for (char_u *cinw = curbuf->b_p_cinw; *cinw;) {
- size_t len = copy_option_part((char **)&cinw, (char *)cinw_buf, cinw_len, ",");
+ for (char *cinw = curbuf->b_p_cinw; *cinw;) {
+ size_t len = copy_option_part(&cinw, (char *)cinw_buf, cinw_len, ",");
if (STRNCMP(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) {
retval = true;
@@ -275,10 +273,8 @@ static const char_u *cin_skipcomment(const char_u *s)
return s;
}
-/*
- * Return TRUE if there is no code at *s. White space and comments are
- * not considered code.
- */
+/// Return true if there is no code at *s. White space and comments are
+/// not considered code.
static int cin_nocode(const char_u *s)
{
return *cin_skipcomment(s) == NUL;
@@ -317,17 +313,17 @@ static bool cin_has_js_key(const char_u *text)
if (*s == '\'' || *s == '"') {
// can be 'key': or "key":
quote = *s;
- ++s;
+ s++;
}
if (!vim_isIDc(*s)) { // need at least one ID character
return false;
}
while (vim_isIDc(*s)) {
- ++s;
+ s++;
}
if (*s && *s == quote) {
- ++s;
+ s++;
}
s = cin_skipcomment(s);
@@ -383,7 +379,7 @@ bool cin_islabel(void) // XXX
cursor_save = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1) {
- --curwin->w_cursor.lnum;
+ curwin->w_cursor.lnum--;
/*
* If we're in a comment or raw string now, skip to the start of
@@ -403,7 +399,7 @@ bool cin_islabel(void) // XXX
}
curwin->w_cursor = cursor_save;
- if (cin_isterminated(line, TRUE, FALSE)
+ if (cin_isterminated(line, true, false)
|| cin_isscopedecl(line)
|| cin_iscase(line, true)
|| (cin_islabel_skip(&line) && cin_nocode(line))) {
@@ -434,7 +430,7 @@ static int cin_isinit(void)
for (;;) {
int i, l;
- for (i = 0; i < (int)ARRAY_SIZE(skip); ++i) {
+ for (i = 0; i < (int)ARRAY_SIZE(skip); i++) {
l = (int)strlen(skip[i]);
if (cin_starts_with(s, skip[i])) {
s = cin_skipcomment(s + l);
@@ -455,7 +451,7 @@ static int cin_isinit(void)
return true;
}
- return FALSE;
+ return false;
}
/// Recognize a switch label: "case .*:" or "default:".
@@ -465,7 +461,7 @@ bool cin_iscase(const char_u *s, bool strict)
{
s = cin_skipcomment(s);
if (cin_starts_with(s, "case")) {
- for (s += 4; *s; ++s) {
+ for (s += 4; *s; s++) {
s = cin_skipcomment(s);
if (*s == NUL) {
break;
@@ -519,8 +515,8 @@ bool cin_isscopedecl(const char_u *p)
bool found = false;
- for (char_u *cinsd = curbuf->b_p_cinsd; *cinsd;) {
- const size_t len = copy_option_part((char **)&cinsd, (char *)cinsd_buf, cinsd_len, ",");
+ for (char *cinsd = curbuf->b_p_cinsd; *cinsd;) {
+ const size_t len = copy_option_part(&cinsd, (char *)cinsd_buf, cinsd_len, ",");
if (STRNCMP(s, cinsd_buf, len) == 0) {
const char_u *skip = cin_skipcomment(s + len);
if (*skip == ':' && skip[1] != ':') {
@@ -588,7 +584,7 @@ static bool cin_is_cpp_namespace(const char_u *s)
*/
static const char_u *after_label(const char_u *l)
{
- for (; *l; ++l) {
+ for (; *l; l++) {
if (*l == ':') {
if (l[1] == ':') { // skip over "::" for C++
l++;
@@ -680,10 +676,10 @@ static int cin_first_id_amount(void)
line = get_cursor_line_ptr();
p = (char_u *)skipwhite((char *)line);
- len = (int)(skiptowhite(p) - p);
+ len = (int)((char_u *)skiptowhite((char *)p) - p);
if (len == 6 && STRNCMP(p, "static", 6) == 0) {
p = (char_u *)skipwhite((char *)p + 6);
- len = (int)(skiptowhite(p) - p);
+ len = (int)((char_u *)skiptowhite((char *)p) - p);
}
if (len == 6 && STRNCMP(p, "struct", 6) == 0) {
p = (char_u *)skipwhite((char *)p + 6);
@@ -769,10 +765,10 @@ static int cin_ispreproc(const char_u *s)
if (*skipwhite((char *)s) == '#') {
return true;
}
- return FALSE;
+ return false;
}
-/// Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
+/// Return true if line "*pp" at "*lnump" is a preprocessor statement or a
/// continuation line of a preprocessor statement. Decrease "*lnump" to the
/// start and return the line in "*pp".
/// Put the amount of indent in "*amount".
@@ -789,7 +785,7 @@ static int cin_ispreproc_cont(const char_u **pp, linenr_T *lnump, int *amount)
for (;;) {
if (cin_ispreproc(line)) {
- retval = TRUE;
+ retval = true;
*lnump = lnum;
break;
}
@@ -842,7 +838,7 @@ static char_u cin_isterminated(const char_u *s, int incl_open, int incl_comma)
{
char_u found_start = 0;
unsigned n_open = 0;
- int is_else = FALSE;
+ int is_else = false;
s = cin_skipcomment(s);
@@ -1095,14 +1091,12 @@ probablyFound:
return 0;
}
-/*
- * Return TRUE if we are at the end of a do-while.
- * do
- * nothing;
- * while (foo
- * && bar); <-- here
- * Adjust the cursor to the line with "while".
- */
+/// Return true if we are at the end of a do-while.
+/// do
+/// nothing;
+/// while (foo
+/// && bar); <-- here
+/// Adjust the cursor to the line with "while".
static int cin_iswhileofdo_end(int terminated)
{
const char_u *line;
@@ -1133,7 +1127,7 @@ static int cin_iswhileofdo_end(int terminated)
}
if (cin_starts_with(s, "while")) {
curwin->w_cursor.lnum = trypos->lnum;
- return TRUE;
+ return true;
}
}
@@ -1146,7 +1140,7 @@ static int cin_iswhileofdo_end(int terminated)
p++;
}
}
- return FALSE;
+ return false;
}
static int cin_isbreak(const char_u *p)
@@ -1190,7 +1184,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
return false;
}
- cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
+ cpp_base_class = lookfor_ctor_init = class_or_struct = false;
/* Search for a line starting with '#', empty, ending in ';' or containing
* '{' or '}' and start below it. This handles the following situations:
@@ -1256,7 +1250,7 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
if (s[1] == ':') {
/* skip double colon. It can't be a constructor
* initialization any more */
- lookfor_ctor_init = FALSE;
+ lookfor_ctor_init = false;
s = cin_skipcomment(s + 2);
} else if (lookfor_ctor_init || class_or_struct) {
/* we have something found, that looks like the start of
@@ -1270,8 +1264,8 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
}
} else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
|| (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6]))) {
- class_or_struct = TRUE;
- lookfor_ctor_init = FALSE;
+ class_or_struct = true;
+ lookfor_ctor_init = false;
if (*s == 'c') {
s = cin_skipcomment(s + 5);
@@ -1280,12 +1274,12 @@ static int cin_is_cpp_baseclass(cpp_baseclass_cache_T *cached)
}
} else {
if (s[0] == '{' || s[0] == '}' || s[0] == ';') {
- cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
+ cpp_base_class = lookfor_ctor_init = class_or_struct = false;
} else if (s[0] == ')') {
/* Constructor-initialization is assumed if we come across
* something like "):" */
- class_or_struct = FALSE;
- lookfor_ctor_init = TRUE;
+ class_or_struct = false;
+ lookfor_ctor_init = true;
} else if (s[0] == '?') {
// Avoid seeing '() :' after '?' as constructor init.
return false;
@@ -1345,11 +1339,9 @@ static int get_baseclass_amount(int col)
return amount;
}
-/*
- * Return TRUE if string "s" ends with the string "find", possibly followed by
- * white space and comments. Skip strings and comments.
- * Ignore "ignore" after "find" if it's not NULL.
- */
+/// Return true if string "s" ends with the string "find", possibly followed by
+/// white space and comments. Skip strings and comments.
+/// Ignore "ignore" after "find" if it's not NULL.
static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore)
{
const char_u *p = s;
@@ -1371,12 +1363,10 @@ static int cin_ends_in(const char_u *s, const char_u *find, const char_u *ignore
p++;
}
}
- return FALSE;
+ return false;
}
-/*
- * Return TRUE when "s" starts with "word" and then a non-ID character.
- */
+/// Return true when "s" starts with "word" and then a non-ID character.
static int cin_starts_with(const char_u *s, const char *word)
{
int l = (int)STRLEN(word);
@@ -1573,7 +1563,7 @@ static int corr_ind_maxparen(pos_T *startpos)
static int find_last_paren(const char_u *l, int start, int end)
{
int i;
- int retval = FALSE;
+ int retval = false;
int open_count = 0;
curwin->w_cursor.col = 0; // default is start of line
@@ -1588,7 +1578,7 @@ static int find_last_paren(const char_u *l, int start, int end)
open_count--;
} else {
curwin->w_cursor.col = i;
- retval = TRUE;
+ retval = true;
}
}
}
@@ -1601,8 +1591,8 @@ static int find_last_paren(const char_u *l, int start, int end)
*/
void parse_cino(buf_T *buf)
{
- char_u *p;
- char_u *l;
+ char *p;
+ char *l;
int divider;
int fraction = 0;
int sw = get_sw_value(buf);
@@ -1745,11 +1735,11 @@ void parse_cino(buf_T *buf)
if (*p == '-') {
p++;
}
- char_u *digits_start = p; // remember where the digits start
- int n = getdigits_int((char **)&p, true, 0);
+ char *digits_start = p; // remember where the digits start
+ int n = getdigits_int(&p, true, 0);
divider = 0;
if (*p == '.') { // ".5s" means a fraction.
- fraction = atoi((char *)++p);
+ fraction = atoi(++p);
while (ascii_isdigit(*p)) {
p++;
if (divider) {
@@ -1768,7 +1758,7 @@ void parse_cino(buf_T *buf)
n += (sw * fraction + divider / 2) / divider;
}
}
- ++p;
+ p++;
}
if (l[1] == '-') {
n = -n;
@@ -2029,7 +2019,7 @@ int get_c_indent(void)
if (trypos == NULL && curwin->w_cursor.lnum > 1) {
// There may be a statement before the comment, search from the end
// of the line for a comment start.
- linecomment_pos.col = check_linecomment(ml_get(curwin->w_cursor.lnum - 1));
+ linecomment_pos.col = check_linecomment((char *)ml_get(curwin->w_cursor.lnum - 1));
if (linecomment_pos.col != MAXCOL) {
trypos = &linecomment_pos;
trypos->lnum = curwin->w_cursor.lnum - 1;
@@ -2052,10 +2042,10 @@ int get_c_indent(void)
char lead_start[COM_MAX_LEN]; // start-comment string
char lead_middle[COM_MAX_LEN]; // middle-comment string
char lead_end[COM_MAX_LEN]; // end-comment string
- char_u *p;
+ char *p;
int start_align = 0;
int start_off = 0;
- int done = FALSE;
+ int done = false;
// find how indented the line beginning the comment is
getvcol(curwin, comment_pos, &col, NULL, NULL);
@@ -2071,11 +2061,11 @@ int get_c_indent(void)
while (*p != NUL && *p != ':') {
if (*p == COM_START || *p == COM_END || *p == COM_MIDDLE) {
- what = *p++;
+ what = (unsigned char)(*p++);
} else if (*p == COM_LEFT || *p == COM_RIGHT) {
- align = *p++;
+ align = (unsigned char)(*p++);
} else if (ascii_isdigit(*p) || *p == '-') {
- off = getdigits_int((char **)&p, true, 0);
+ off = getdigits_int(&p, true, 0);
} else {
p++;
}
@@ -2084,7 +2074,7 @@ int get_c_indent(void)
if (*p == ':') {
p++;
}
- (void)copy_option_part((char **)&p, lead_end, COM_MAX_LEN, ",");
+ (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
if (what == COM_START) {
STRCPY(lead_start, lead_end);
lead_start_len = (int)STRLEN(lead_start);
@@ -2098,7 +2088,7 @@ int get_c_indent(void)
* up with the comment opener per the 'comments' option. */
if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
&& STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0) {
- done = TRUE;
+ done = true;
if (curwin->w_cursor.lnum > 1) {
/* If the start comment string matches in the previous
* line, use the indent of that line plus offset. If
@@ -2330,7 +2320,7 @@ int get_c_indent(void)
/* look for opening unmatched paren, indent one level
* for each additional level */
n = 1;
- for (col = 0; col < our_paren_pos.col; ++col) {
+ for (col = 0; col < our_paren_pos.col; col++) {
switch (l[col]) {
case '(':
case '{':
@@ -2388,7 +2378,7 @@ int get_c_indent(void)
* but ignore (void) before the line (ignore_paren_col). */
col = our_paren_pos.col;
while ((int)our_paren_pos.col > ignore_paren_col) {
- --our_paren_pos.col;
+ our_paren_pos.col--;
switch (*ml_get_pos(&our_paren_pos)) {
case '(':
amount += curbuf->b_ind_unclosed2;
@@ -2562,7 +2552,7 @@ int get_c_indent(void)
}
}
- lookfor_break = FALSE;
+ lookfor_break = false;
if (cin_iscase(theline, false)) { // it's a switch() label
lookfor = LOOKFOR_CASE; // find a previous switch() label
@@ -2646,7 +2636,7 @@ int get_c_indent(void)
continue;
}
- terminated = cin_isterminated(l, FALSE, TRUE);
+ terminated = cin_isterminated(l, false, true);
/*
* If we are at top level and the line looks like a
@@ -2660,7 +2650,7 @@ int get_c_indent(void)
* don't add extra indent.
* TODO: does not work, if a function
* declaration is split over multiple lines:
- * cin_isfuncdecl returns FALSE then.
+ * cin_isfuncdecl returns false then.
*/
if (terminated == ',') {
break;
@@ -2862,7 +2852,7 @@ int get_c_indent(void)
if (n) {
amount = n;
l = after_label(get_cursor_line_ptr());
- if (l != NULL && cin_is_cinword(l)) {
+ if (l != NULL && cin_is_cinword((char *)l)) {
if (theline[0] == '{') {
amount += curbuf->b_ind_open_extra;
} else {
@@ -2971,7 +2961,7 @@ int get_c_indent(void)
* initialisation (not indented) or a variable declaration
* (indented).
*/
- terminated = cin_isterminated(l, FALSE, TRUE);
+ terminated = cin_isterminated(l, false, true);
if (js_cur_has_key) {
js_cur_has_key = false; // only check the first line
@@ -3116,7 +3106,7 @@ int get_c_indent(void)
* Check if we are after an "if", "while", etc.
* Also allow " } else".
*/
- if (cin_is_cinword(l) || cin_iselse((char_u *)skipwhite((char *)l))) {
+ if (cin_is_cinword((char *)l) || cin_iselse((char_u *)skipwhite((char *)l))) {
// Found an unterminated line after an if (), line up
// with the last one.
// if (cond)
@@ -3334,7 +3324,7 @@ int get_c_indent(void)
amount += curbuf->b_ind_open_extra;
}
}
- ++whilelevel;
+ whilelevel++;
}
/*
* We are after a "normal" statement.
@@ -3848,7 +3838,7 @@ static int find_match(int lookfor, linenr_T ourscope)
* another "do", so increment whilelevel. XXX
*/
if (cin_iswhileofdo(look, curwin->w_cursor.lnum)) {
- ++whilelevel;
+ whilelevel++;
continue;
}