📄 output.c
字号:
if (parser_state_tos->paren_indents[i] < ptr - s_code) { parser_state_tos->paren_indents[i] = -(parser_state_tos->paren_indents[i] + target_col); } else { parser_state_tos->paren_indents[i] -= offset; } } } for (i = parser_state_tos->p_l_follow; i < parser_state_tos->paren_indents_size; ++i) { if (parser_state_tos->paren_indents[i] >= (ptr - s_code)) { parser_state_tos->paren_indents[i] -= offset; } } for (p = s_code; p < s_code + buf_break->offset; p++) { mf_putc (output,*p); } c = s_code[buf_break->offset]; s_code[buf_break->offset] = '\0'; cur_col = count_columns (cur_col, s_code, NULL_CHAR); s_code[buf_break->offset] = c; not_truncated = 0; len = (e_code - ptr - 1); memmove (s_code, ptr + 1, len); e_code = s_code + len;#if COLOR_DEBUG fputs (" \e[31m", output); for (p = s_code; p < e_code; p++) { mf_putc (output,*p); } fputs (" \e[0m", output);#endif *e_code = '\0'; s_code_corresponds_to = buf_break->corresponds_to; prev_target_col_break = buf_break->target_col; if (!buf_break->priority_newline) { parser_state_tos->broken_at_non_nl = true; } set_next_buf_break (target_col, buf_break->target_col, offset); buf_break_used = 1; break_line = (buf_break != NULL) && (output_line_length () > settings.max_col); } else { for (i = 0; i < parser_state_tos->p_l_follow; i++) { if (parser_state_tos->paren_indents[i] >= 0) { parser_state_tos->paren_indents[i] = -(parser_state_tos->paren_indents[i] + target_col); } } for (p = s_code; p < e_code; p++) { mf_putc (output,*p); } cur_col = count_columns (cur_col, s_code, NULL_CHAR); clear_buf_break_list (); } } if (s_com != e_com) { { /* Here for comment printing. */ int target = parser_state_tos->com_col; char *com_st = s_com; if (cur_col > target) { mf_putc(output,EOL); cur_col = 1; ++out_lines; } cur_col = pad_output (cur_col, target); mf_write (output,com_st, e_com - com_st); cur_col += e_com - com_st; com_lines++; } } else if (embedded_comment_on_line) { com_lines++; } embedded_comment_on_line = 0; if (parser_state_tos->use_ff) { mf_putc (output,'\014'); parser_state_tos->use_ff = false; } else { mf_putc(output,EOL); } ++out_lines; if ((parser_state_tos->just_saw_decl == 1) && settings.blanklines_after_declarations) { prefix_blankline_requested = 1; prefix_blankline_requested_code = decl; parser_state_tos->just_saw_decl = 0; } else { prefix_blankline_requested = postfix_blankline_requested; prefix_blankline_requested_code = postfix_blankline_requested_code; } postfix_blankline_requested = 0; } /* if we are in the middle of a declaration, remember that fact * for proper comment indentation */ parser_state_tos->decl_on_line = parser_state_tos->in_decl; /* next line should be indented if we have not completed this stmt */ parser_state_tos->ind_stmt = parser_state_tos->in_stmt; e_lab = s_lab; *s_lab = '\0'; /* reset buffers */ if (not_truncated) { e_code = s_code; *s_code = '\0'; s_code_corresponds_to = NULL; } e_com = s_com; *s_com = '\0'; parser_state_tos->ind_level = parser_state_tos->i_l_follow; parser_state_tos->paren_level = parser_state_tos->p_l_follow; if (parser_state_tos->paren_level > 0) { /* If we broke the line and the following line will * begin with a rparen, the indentation is set for * the column of the rparen *before* the break - reset * the column to the position after the break. */ if (!not_truncated && ((*s_code == '(') || (*s_code == '[')) && (parser_state_tos->paren_level >= 2)) { *paren_targ = -parser_state_tos->paren_indents[parser_state_tos->paren_level - 2]; } else { *paren_targ = -parser_state_tos->paren_indents[parser_state_tos->paren_level - 1]; } } else { *paren_targ = 0; } if (inhibited) { char *p = cur_line; while (--n_real_blanklines >= 0) { mf_putc(output,EOL); } n_real_blanklines = 0; do { while ((*p != '\0') && (*p != EOL)) { mf_putc (output,*p++); } if ((*p == '\0') && ((unsigned long) (p - current_input->data) == current_input->size)) { in_prog_pos = p; buf_end = p; buf_ptr = p; had_eof = true; return; } if (*p == EOL) { cur_line = p + 1; line_no++; } mf_putc (output,*p++); while ((*p == ' ') || (*p == TAB)) { mf_putc (output, *p); p++; } if ((*p == '/') && ((*(p + 1) == '*') || (*(p + 1) == '/'))) { /* We've hit a comment. See if turns formatting back on. */ mf_putc (output,*p++); mf_putc (output,*p++); while ((*p == ' ') || (*p == TAB)) { mf_putc (output,*p); p++; } if (!strncmp (p, "*INDENT-ON*", 11)) { do { while ((*p != '\0') && (*p != EOL)) { mf_putc (output,*p++); } if ((*p == '\0') && (((unsigned long) (p - current_input->data) == current_input->size))) { in_prog_pos = p; buf_end = p; buf_ptr = p; had_eof = true; return; } else { if (*p == EOL) { inhibited = false; cur_line = p + 1; line_no++; } mf_putc (output,*p++); } } while (inhibited); } } } while (inhibited); in_prog_pos = cur_line; buf_end = cur_line; buf_ptr = cur_line; fill_buffer (); } /* Output the rest already if we really wanted a new-line after this code. */ if (buf_break_used && (s_code != e_code) && force_nl) { prefix_blankline_requested = 0; dump_line (true, paren_targ); } return;}/* * Name: flush_output * Description: Flushes any buffered output to the output file. * * Returns: None * * History: */extern void flush_output(void){ mf_flush (output);}/* * Name: open_output * Description: Opens the output file in read/write mode. * * Returns: None * * History: */void open_output( const char * filename, const char * mode){ output=mf_alloc();#if 0 if (filename == NULL) { output = stdout; } else { output = fopen(filename, mode); /* open the file for read + write * (but see the trunc function) */ if (output == NULL) { fprintf (stderr, _("indent: can't create %s\n"), filename); exit (indent_fatal); } }#endif}/* * Name: reopen_output_trunc * Description: Reopens the output file truncated. * * Returns: None * * History: */extern void reopen_output_trunc( const char * filename){ if (output) { mf_seek(output,MEMFILE_START,0); } else { output=mf_alloc(); }#if 0 output = freopen(filename, "w", output);#endif}/* * Name: close_output * Description: Closes the output file. * * Returns: None * * History: */extern void close_output( struct stat * file_stats, const char * filename){ mf_free(output);#if 0 if (output != stdout) { if (fclose(output) != 0) { fatal(_("Can't close output file %s"), filename); } else {#ifdef PRESERVE_MTIME if (file_stats != NULL) { struct utimbuf buf; buf.actime = time (NULL); buf.modtime = file_stats->st_mtime; if (utime(filename, &buf) != 0) { WARNING(_("Can't preserve modification time on output file %s"), filename, 0); } }#endif } }#endif}extern inhibit_indenting( BOOLEAN flag){ inhibited = flag;}MEMFILE* get_output(){ mf_seek(output,MEMFILE_START,0); return output;}void clear_output(){ mf_clear(output);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -