📄 indent.c
字号:
{ fill_buffer (); } } break; case '/': if (((*buf_ptr == '*') || (*buf_ptr == '/')) && !in_comment && !in_cplus_comment && !quote) { save_com.column = current_column () - 1; if (*buf_ptr == '/') { in_cplus_comment = 1; } else { in_comment = 1; } *e_lab++ = *buf_ptr++; com_start = e_lab - s_lab - 2; /* Store the column that corresponds with the start * of the buffer */ if (save_com.ptr == save_com.end) { save_com.start_column = current_column () - 2; } } break; case '"': case '\'': if (!quote) { quote = e_lab[-1]; } else if (e_lab[-1] == quote) { quote = 0; } break; case '*': if (*buf_ptr == '/' && in_comment) { in_comment = 0; *e_lab++ = *buf_ptr++; com_end = e_lab - s_lab; } break; } } while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == TAB)) { e_lab--; } if (in_cplus_comment) /* Should we also check in_comment? -jla */ { in_cplus_comment = 0; *e_lab++ = *buf_ptr++; com_end = e_lab - s_lab; } if (e_lab - s_lab == com_end && bp_save == 0) { /* comment on preprocessor line */ if (save_com.end != save_com.ptr) { need_chars (&save_com, 2); *save_com.end++ = EOL; /* add newline between * comments */ *save_com.end++ = ' '; save_com.len += 2; --line_no; } need_chars (&save_com, com_end - com_start + 1); strncpy (save_com.end, s_lab + com_start, com_end - com_start); save_com.end[com_end - com_start] = '\0'; save_com.end += com_end - com_start; save_com.len += com_end - com_start; e_lab = s_lab + com_start; while ((e_lab > s_lab) && ((e_lab[-1] == ' ') || (e_lab[-1] == TAB))) { e_lab--; } /* Switch input buffers so that calls to lexi() will * read from our save buffer. */ bp_save = buf_ptr; be_save = buf_end; buf_ptr = save_com.ptr; need_chars (&save_com, 1); buf_end = save_com.end; save_com.end = save_com.ptr; /* make save_com empty */ } *e_lab = '\0'; /* null terminate line */ parser_state_tos->pcase = false; } p = s_lab + 1; p = skip_horiz_space(p); if (strncmp (p, "if", 2) == 0) { if (settings.blanklines_around_conditional_compilation) { prefix_blankline_requested++; prefix_blankline_requested_code = preesc; while (*in_prog_pos++ == EOL) { } in_prog_pos--; } { /* Push a copy of the parser_state onto the stack. All * manipulations will use the copy at the top of stack, and * then we can return to the previous state by popping the * stack. */ parser_state_ty *new; new = (parser_state_ty *) xmalloc (sizeof (parser_state_ty)); (void) memcpy (new, parser_state_tos, sizeof (parser_state_ty)); /* We need to copy the dynamically allocated arrays in the * struct parser_state too. */ new->p_stack = (codes_ty *) xmalloc (parser_state_tos->p_stack_size * sizeof (codes_ty)); (void) memcpy (new->p_stack, parser_state_tos->p_stack, (parser_state_tos->p_stack_size * sizeof (codes_ty))); new->il = (int *) xmalloc (parser_state_tos->p_stack_size * sizeof (int)); (void) memcpy (new->il, parser_state_tos->il, parser_state_tos->p_stack_size * sizeof (int)); new->cstk = (int *) xmalloc (parser_state_tos->p_stack_size * sizeof (int)); (void) memcpy (new->cstk, parser_state_tos->cstk, parser_state_tos->p_stack_size * sizeof (int)); new->paren_indents = (short *) xmalloc (parser_state_tos->paren_indents_size * sizeof (short)); (void) memcpy (new->paren_indents, parser_state_tos->paren_indents, (parser_state_tos->paren_indents_size * sizeof (short))); new->next = parser_state_tos; parser_state_tos = new; /* GDB_HOOK_parser_state_tos */ } } else if ((strncmp (p, "else", 4) == 0) || (strncmp (p, "elif", 4) == 0)) { /* When we get #else, we want to restore the parser state to * what it was before the matching #if, so that things get * lined up with the code before the #if. However, we do not * want to pop the stack; we just want to copy the second to * top elt of the stack because when we encounter the #endif, * it will pop the stack. */ else_or_endif = (strncmp (p, "else", 4) == 0); prefix_blankline_requested = 0; if (parser_state_tos->next) { /* First save the addresses of the arrays for the top of * stack. */ codes_ty * tos_p_stack = parser_state_tos->p_stack; int * tos_il = parser_state_tos->il; int * tos_cstk = parser_state_tos->cstk; short * tos_paren_indents = parser_state_tos->paren_indents; parser_state_ty * second = parser_state_tos->next; (void) memcpy (parser_state_tos, second, sizeof (parser_state_ty)); parser_state_tos->next = second; /* Now copy the arrays from the second to top of stack to * the top of stack. */ /* Since the p_stack, etc. arrays only grow, never shrink, * we know that they will be big enough to fit the array * from the second to top of stack. */ parser_state_tos->p_stack = tos_p_stack; (void) memcpy (parser_state_tos->p_stack, parser_state_tos->next->p_stack, parser_state_tos->p_stack_size * sizeof (codes_ty)); parser_state_tos->il = tos_il; (void) memcpy (parser_state_tos->il, parser_state_tos->next->il, (parser_state_tos->p_stack_size * sizeof (int))); parser_state_tos->cstk = tos_cstk; (void) memcpy (parser_state_tos->cstk, parser_state_tos->next->cstk, (parser_state_tos->p_stack_size * sizeof (int))); parser_state_tos->paren_indents = tos_paren_indents; (void) memcpy (parser_state_tos->paren_indents, parser_state_tos->next->paren_indents, (parser_state_tos->paren_indents_size * sizeof (short))); } else { ERROR (else_or_endif ? _("Unmatched #else") : _("Unmatched #elif"), 0, 0); *file_exit_value = indent_error; } } else if (strncmp (p, "endif", 5) == 0) { else_or_endif = true; prefix_blankline_requested = 0; /* We want to remove the second to top elt on the stack, which * was put there by #if and was used to restore the stack at * the #else (if there was one). We want to leave the top of * stack unmolested so that the state which we have been using * is unchanged. */ if (parser_state_tos->next) { parser_state_ty *second = parser_state_tos->next; parser_state_tos->next = second->next; free (second->p_stack); free (second->il); free (second->cstk); free (second->paren_indents); free (second); } else { ERROR (_("Unmatched #endif"), 0, 0); *file_exit_value = indent_error; } if (settings.blanklines_around_conditional_compilation) { postfix_blankline_requested++; postfix_blankline_requested_code = preesc; n_real_blanklines = 0; } } /* Don't put a blank line after declarations if they are directly * followed by an #else or #endif -Run */ if (else_or_endif && prefix_blankline_requested_code == decl) { prefix_blankline_requested = 0; } /* Normally, subsequent processing of the newline character * causes the line to be printed. The following clause handles * a special case (comma-separated declarations separated * by the preprocessor lines) where this doesn't happen. */ if ((parser_state_tos->last_token == comma) && (parser_state_tos->p_l_follow <= 0) && settings.leave_comma && !parser_state_tos->block_init && break_comma && (s_com == e_com)) { dump_line(true, &paren_target); parser_state_tos->want_blank = false; }}/******************************************************************************/static void handle_token_comment( BOOLEAN * force_nl, BOOLEAN * flushed_nl){ if (parser_state_tos->last_saw_nl && (s_code != e_code)) { *flushed_nl = false; dump_line(true, &paren_target); parser_state_tos->want_blank = false; *force_nl = false; } print_comment (&paren_target);}/******************************************************************************/static void handle_token_attribute( ){ char * t_ptr; if (s_code != e_code) { set_buf_break (bb_attribute, paren_target); *e_code++ = ' '; } for (t_ptr = token; t_ptr < token_end; ++t_ptr) { check_code_size(); *e_code++ = *t_ptr; } parser_state_tos->in_decl = false; parser_state_tos->want_blank = true;}/******************************************************************************/static void handle_the_token( const codes_ty type_code, BOOLEAN * scase, BOOLEAN * force_nl, BOOLEAN * sp_sw, BOOLEAN * flushed_nl, codes_ty * hd_type, int * dec_ind, BOOLEAN * last_token_ends_sp, exit_values_ty * file_exit_value, const bb_code_ty can_break, BOOLEAN * last_else, BOOLEAN is_procname_definition){ switch (type_code) { case form_feed: /* found a form feed in line */ handle_token_form_feed(); break; case newline: handle_token_newline(force_nl); break; case lparen: handle_token_lparen(force_nl, sp_sw, dec_ind); break; case rparen: handle_token_rparen(force_nl, sp_sw, hd_type, last_token_ends_sp, file_exit_value); break; case unary_op: /* this could be any unary operation */ handle_token_unary_op( dec_ind, can_break); break; case binary_op: /* any binary operation */ handle_token_binary_op(can_break); break; case postop: /* got a trailing ++ or -- */ handle_token_postop(); break; case question: /* got a ? */ handle_token_question(can_break); break; case casestmt: /* got word 'case' or 'default' */ handle_token_casestmt(scase, file_exit_value); copy_id(type_code, force_nl, file_exit_value,can_break); break; case colon: /* got a ':' */ handle_token_colon(scase, force_nl, dec_ind, can_break); break; case doublecolon: /* Deal with C++ Class::Method */ handle_token_doublecolon(); break; case semicolon: /* we are not in an initialization or structure declaration */ handle_token_semicolon(scase, force_nl, sp_sw, dec_ind,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -