📄 indent.c
字号:
set_buf_break (bb_proc_call, paren_target); } if (parser_state_tos->in_decl && !parser_state_tos->block_init) { if ((*token != '[') && !buf_break_used) { while ((e_code - s_code) < *dec_ind) { check_code_size(); set_buf_break (bb_dec_ind, paren_target); *e_code++ = ' '; } *e_code++ = token[0]; parser_state_tos->ind_stmt = false; } else { *e_code++ = token[0]; } } else { *e_code++ = token[0]; } if (settings.parentheses_space && *token != '[') { *e_code++ = ' '; } parser_state_tos->paren_indents[parser_state_tos->p_l_follow - 1] = e_code - s_code; if (*sp_sw && (parser_state_tos->p_l_follow == 1) && settings.extra_expression_indent && (parser_state_tos->paren_indents[0] < 2 * settings.ind_size)) { parser_state_tos->paren_indents[0] = 2 * settings.ind_size; } parser_state_tos->want_blank = false; if ((parser_state_tos->in_or_st == 1) && *token == '(') { /* this is a kludge to make sure that declarations will be * correctly aligned if proc decl has an explicit type on it, i.e. * "int a(x) {..." */ parse_lparen_in_decl (); /* Turn off flag for structure decl or initialization. */ parser_state_tos->in_or_st = 0; } /* For declarations, if user wants all fn decls broken, force that * now. */ if ((*token == '(') && settings.break_function_decl_args && parser_state_tos->in_stmt && parser_state_tos->in_decl && (parser_state_tos->paren_depth == 1)) { dump_line(true, &paren_target); *force_nl = false; paren_target = parser_state_tos->paren_depth * settings.ind_size + 1; parser_state_tos->paren_indents[parser_state_tos->p_l_follow - 1] = -paren_target; } if (parser_state_tos->sizeof_keyword) { parser_state_tos->sizeof_mask |= 1 << parser_state_tos->p_l_follow; } /* The '(' that starts a cast can never be preceded by an * indentifier or decl. */ if ((parser_state_tos->last_token == decl) || ((parser_state_tos->last_token == ident) && (parser_state_tos->last_rw != rw_return))) { parser_state_tos->noncast_mask |= 1 << parser_state_tos->p_l_follow; } else { parser_state_tos->noncast_mask &= ~(1 << parser_state_tos->p_l_follow); }}/******************************************************************************/static void handle_token_rparen( BOOLEAN * force_nl, BOOLEAN * sp_sw, codes_ty * hd_type, BOOLEAN * last_token_ends_sp, exit_values_ty * file_exit_value){ parser_state_tos->paren_depth--; #if 1 /* For declarations, if user wants close of fn decls broken, force that * now. */ if ((*token == ')') && settings.break_function_decl_args_end && !parser_state_tos->in_or_st && parser_state_tos->in_stmt && parser_state_tos->in_decl && (parser_state_tos->paren_depth == 0)) { if ((s_code != e_code) || (s_lab != e_lab) || (s_com != e_com)) { dump_line(true, &paren_target); } paren_target = parser_state_tos->paren_depth * settings.ind_size; parser_state_tos->paren_indents[parser_state_tos->p_l_follow - 1] = paren_target; parser_state_tos->ind_stmt = 0; }#endif if (parser_state_tos-> cast_mask & (1 << parser_state_tos-> p_l_follow) & ~parser_state_tos->sizeof_mask) { parser_state_tos->last_u_d = true; parser_state_tos->cast_mask &= (1 << parser_state_tos->p_l_follow) - 1; if (!parser_state_tos->cast_mask && settings.cast_space) { parser_state_tos->want_blank = true; } else { parser_state_tos->want_blank = false; parser_state_tos->can_break = bb_cast; } } else if (parser_state_tos->in_decl && !parser_state_tos->block_init && (parser_state_tos->paren_depth == 0)) { parser_state_tos->want_blank = true; } parser_state_tos->sizeof_mask &= (1 << parser_state_tos->p_l_follow) - 1; if (--parser_state_tos->p_l_follow < 0) { parser_state_tos->p_l_follow = 0; WARNING (_("Extra %c"), (unsigned long) *((unsigned char *) token), 0); } /* if the paren starts the line, then indent it */ if (e_code == s_code) { int level = parser_state_tos->p_l_follow; parser_state_tos->paren_level = level; if (level > 0) { paren_target = -parser_state_tos->paren_indents[level - 1]; } else { paren_target = 0; } } if (settings.parentheses_space && *token != ']') { *e_code++ = ' '; } *e_code++ = token[0]; /* check for end of if (...), or some such */ if (*sp_sw && (parser_state_tos->p_l_follow == 0)) { /* Indicate that we have just left the parenthesized expression * of a while, if, or for, unless we are getting out of the * parenthesized expression of the while of a do-while loop. * (do-while is different because a semicolon immediately * following this will not indicate a null loop body). */ if (parser_state_tos->p_stack[parser_state_tos->tos] != dohead) { *last_token_ends_sp = 2; } *sp_sw = false; *force_nl = true; /* must force newline after if */ parser_state_tos->last_u_d = true; /* inform lexi that a * following operator is * unary */ parser_state_tos->in_stmt = false; /* dont use stmt * continuation * indentation */ if (parse (*hd_type) != total_success) { *file_exit_value = indent_error; } } /* this should ensure that constructs such as main(){...} and * int[]{...} have their braces put in the right place */ parser_state_tos->search_brace = settings.btype_2;}/******************************************************************************/static void handle_token_unary_op( int * dec_ind, const bb_code_ty can_break){ char * t_ptr; if (parser_state_tos->want_blank) { set_buf_break (bb_unary_op, paren_target); *e_code++ = ' '; *e_code = '\0'; /* null terminate code sect */ } else if (can_break) { set_buf_break (can_break, paren_target); } { char *res = token; char *res_end = token_end; /* if this is a unary op in a declaration, we should * indent this token */ if ((parser_state_tos->paren_depth == 0) && parser_state_tos->in_decl && !buf_break_used && !parser_state_tos->block_init) { while ((e_code - s_code) < (*dec_ind - (token_end - token))) { check_code_size(); set_buf_break (bb_dec_ind, paren_target); *e_code++ = ' '; } parser_state_tos->ind_stmt = false; } for (t_ptr = res; t_ptr < res_end; ++t_ptr) { check_code_size(); *e_code++ = *t_ptr; } *e_code = '\0'; /* null terminate code sect */ } parser_state_tos->want_blank = false;}/******************************************************************************/static void handle_token_binary_op( const bb_code_ty can_break){ char * t_ptr; if (parser_state_tos->want_blank || (e_code > s_code && *e_code != ' ')) { set_buf_break (bb_binary_op, paren_target); *e_code++ = ' '; *e_code = '\0'; /* null terminate code sect */ } else if (can_break) { set_buf_break (can_break, paren_target); } { char *res = token; char *res_end = token_end; for (t_ptr = res; t_ptr < res_end; ++t_ptr) { check_code_size(); *e_code++ = *t_ptr; /* move the operator */ } }#if 1 if (*token == '=') { parser_state_tos->in_decl = false; }#endif parser_state_tos->want_blank = true;}/******************************************************************************/static void handle_token_postop(void){ *e_code++ = token[0]; *e_code++ = token[1]; parser_state_tos->want_blank = true;}/******************************************************************************/static void handle_token_question( const bb_code_ty can_break){ squest++; /* this will be used when a later colon * appears so we can distinguish the * <c>?<n>:<n> construct */ if (parser_state_tos->want_blank) { set_buf_break (bb_question, paren_target); *e_code++ = ' '; } else if (can_break) { set_buf_break (can_break, paren_target); } *e_code++ = '?'; parser_state_tos->want_blank = true; *e_code = '\0'; /* null terminate code sect */}/******************************************************************************/static void handle_token_casestmt( BOOLEAN * scase, exit_values_ty * file_exit_value){ *scase = true; /* so we can process the later colon * properly */ do { if (parse (casestmt) != total_success) { *file_exit_value = indent_error; } } while(0); /* Let parser know about it */ }/******************************************************************************/static void handle_token_colon( BOOLEAN * scase, BOOLEAN * force_nl, int * dec_ind, const bb_code_ty can_break){ char * t_ptr; if (squest > 0) { /* it is part of the <c> ? <n> : <n> construct */ --squest; if (parser_state_tos->want_blank) { set_buf_break (bb_colon, paren_target); *e_code++ = ' '; } else if (can_break) { set_buf_break (can_break, paren_target); } *e_code++ = ':'; *e_code = '\0'; /* null terminate code sect */ parser_state_tos->want_blank = true; } else { /* __ e_code * | * " private:\n" C++, treat as label. * ^^^ ^ * | | * | `- buf_ptr (in different buffer though!) * `- s_code * * or * * " unsigned int private:4\n" C/C++, treat as bits. */ if (parser_state_tos->in_decl) { if (!(((e_code - s_code > 6) && !strncmp (&buf_ptr[-8], "private:", 8)) && !isdigit (*buf_ptr)) && !(((e_code - s_code > 8) && !strncmp (&buf_ptr[-10], "protected:", 10)) && !isdigit (*buf_ptr)) && !(((e_code - s_code > 5) && !strncmp (&buf_ptr[-7], "public:", 7)) && !isdigit (*buf_ptr))) { *e_code++ = ':'; parser_state_tos->want_blank = false; return; } else if (*s_code == ' ') { /* * It is possible that dec_ind spaces have been inserted before * the `public:' etc. label because indent thinks it's of the * type: */ /* * Only now we see the '4' isn't there. * Remove those spaces:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -