⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 output.c

📁 代码格式化工具。 其实就是linux下indent的windows版本。
💻 C
📖 第 1 页 / 共 3 页
字号:
        buf_break->prev = NULL;}void clear_buf_break_list (void){    buf_break_st_ty *bb;    for (bb = buf_break_list; bb;)    {        buf_break_st_ty *obb = bb;        bb = bb->prev;        free (obb);    }        buf_break = buf_break_list = NULL;    break_line = 0;}/* *        prev_code_target *        |                prev_code_target + offset *        |                | * <----->if ((aaa == bbb) && xxx *            && xxx *            | *            new_code_target */static void set_next_buf_break (                    int prev_code_target,                    int new_code_target,                    int offset){    buf_break_st_ty *bb;    better_break (buf_break, NULL);     /* Reset first_level */    if (buf_break_list == buf_break)    {        clear_buf_break_list ();        return;    }    /* Correct all elements of the remaining buf breaks: */    for (bb = buf_break_list; bb; bb = bb->prev)    {        if (bb->target_col > buf_break->target_col && settings.lineup_to_parens)        {            bb->target_col -= ((prev_code_target + offset) - new_code_target);        }                bb->col -= ((prev_code_target + offset) - new_code_target);        bb->offset -= offset;        bb->priority_code_length -= offset;        bb->first_level = buf_break->first_level;                if (!buf_break->priority_newline)        {            bb->priority_newline = false;        }                set_priority (bb);                if (bb->prev == buf_break)        {            break;        }    }    free (buf_break);    /* Set buf_break to first break in the list */        buf_break = bb;        /* GDB_HOOK_buf_break */        buf_break->prev = NULL;    /* Find a better break of the existing breaks */        for (bb = buf_break; bb; bb = bb->next)    {        if (bb->col > settings.max_col)        {            continue;        }                if (better_break (bb, buf_break))        {            /* Found better buf_break.  Get rid of all previous possible breaks. */            buf_break = bb;                        for (bb = bb->prev; bb;)            {                buf_break_st_ty *obb = bb;                bb = bb->prev;                free (obb);            }            bb = buf_break;            buf_break->prev = NULL;        }    }}/* * Name:         pad_output * Description:  Fill the output line with whitespace up to TARGET_COLUMN, *               given that the line is currently in column CURRENT_COLUMN. * * Returns:      the ending column number. * * History: */static int pad_output (    int current_column,    int target_column){    if (current_column >= target_column)    {        return current_column;    }        if (settings.use_tabs && settings.tabsize > 1)    {        int offset = settings.tabsize - (current_column - 1) % settings.tabsize;              while (current_column + offset <= target_column)        {            mf_putc ( output,TAB);            current_column += offset;            offset = settings.tabsize;        }    }    while (current_column < target_column)    {        mf_putc (output,' ');        current_column++;    }    return current_column;}/* * Name:         dump_line * Description:  routine that actually effects the printing of the new source. *               It prints the label section, followed by the code section with *               the appropriate nesting level, followed by any comments. * * Returns:      None. * * History: */extern void dump_line (    int force_nl,    int *paren_targ){    int cur_col;    int target_col = 0;    int not_truncated = 1;    int target_col_break = -1;    if (buf_break_used)    {        buf_break_used = 0;        target_col_break = prev_target_col_break;    }    else if (force_nl)    {        parser_state_tos->broken_at_non_nl = false;    }        if (parser_state_tos->procname[0] && !parser_state_tos->classname[0] &&        (s_code_corresponds_to == parser_state_tos->procname))    {        parser_state_tos->procname = "\0";    }    else if (parser_state_tos->procname[0] && parser_state_tos->classname[0] &&             (s_code_corresponds_to == parser_state_tos->classname))    {        parser_state_tos->procname = "\0";        parser_state_tos->classname = "\0";    }    /* A blank line */        if ((s_code == e_code) && (s_lab == e_lab) && (s_com == e_com))    {        /* If we have a formfeed on a blank line, we should just output it,         * rather than treat it as a normal blank line.  */                if (parser_state_tos->use_ff)        {            mf_putc (output,'\014');            parser_state_tos->use_ff = false;        }        else        {            n_real_blanklines++;        }    }    else    {        if (prefix_blankline_requested && n_real_blanklines == 0)        {            n_real_blanklines = 1;        }        else if (settings.swallow_optional_blanklines && (n_real_blanklines > 1))        {            n_real_blanklines = 1;        }        while (--n_real_blanklines >= 0)        {            mf_putc(output,EOL);        }                n_real_blanklines = 0;        if (e_lab != s_lab || e_code != s_code)        {            ++code_lines;               /* keep count of lines with code */        }        if (e_lab != s_lab)        {            /* print lab, if any */            while ((e_lab > s_lab) && ((e_lab[-1] == ' ') ||                                        (e_lab[-1] == TAB)))            {                e_lab--;            }                        cur_col = pad_output (1, compute_label_target ());                        /* force indentation of preprocessor directives.             * this happens when force_preproc_width > 0 */                        if ((settings.force_preproc_width > 0) &&                (s_lab[0] == '#'))            {                int preproc_postcrement;                char *p = &s_lab[1];                while(*p == ' ')                {                    p++;                }                preproc_postcrement = settings.force_preproc_width;                if (strncmp(p, "else", 4) == 0)                {                    preproc_indent-=settings.force_preproc_width;                }                else if((strncmp(p, "if", 2) == 0) ||                        (strncmp(p, "ifdef", 5) == 0))                {                }                else if (strncmp(p, "elif", 4) == 0)                {                    preproc_indent -= settings.force_preproc_width;                }                else if(strncmp(p, "endif", 5) == 0)                {                    preproc_indent -= settings.force_preproc_width;                    preproc_postcrement = 0;                }                else                {                    preproc_postcrement = 0;                }                if (preproc_indent == 0)                {                    mf_printf (output, "#");                }                else                {                    mf_printf (output, "#%*s", preproc_indent, " ");                }                                mf_printf (output, "%.*s", (int) (e_lab - p), p);                cur_col = count_columns (cur_col + preproc_indent + 1, p, NULL_CHAR);                preproc_indent += preproc_postcrement;            }            else if ((s_lab[0] == '#') && ((strncmp (&s_lab[1], "else", 4) == 0) ||                                           (strncmp (&s_lab[1], "endif", 5) == 0)))            {                /* Treat #else and #endif as a special case because any text                 * after #else or #endif should be converted to a comment.  */                                char *s = s_lab;                if (e_lab[-1] == EOL)   /* Don't include EOL in the comment */                {                    e_lab--;                }                                do                {                    mf_putc (output,*s++);                    ++cur_col;                } while ((s < e_lab) && ('a' <= *s) && (*s <= 'z'));                                while (((*s == ' ') || (*s == TAB)) && (s < e_lab))                {                    s++;                }                                if (s < e_lab)                {                    if (settings.tabsize > 1)                    {                        cur_col = pad_output (cur_col, cur_col + settings.tabsize -                                              (cur_col - 1) % settings.tabsize);                    }                    else                    {                        cur_col = pad_output (cur_col, cur_col + 2);                    }                                        if (s[0] == '/' && (s[1] == '*' || s[1] == '/'))                    {                        mf_printf (output, "%.*s", e_lab - s, s);                    }                    else                    {                        mf_printf (output, "/* %.*s */", e_lab - s, s);                    }                                        /* no need to update cur_col: the very next thing will                       be a new-line (or end of file) */                }            }            else            {                mf_printf (output, "%.*s", (int) (e_lab - s_lab), s_lab);                cur_col = count_columns (cur_col, s_lab, NULL_CHAR);            }        }        else        {            cur_col = 1;                /* there is no label section */        }        parser_state_tos->pcase = false;        /* Remove trailing spaces */        while ((*(e_code - 1) == ' ') && (e_code > s_code))        {            *(--e_code) = NULL_CHAR;        }                if (s_code != e_code)        {                       /* print code section, if any */            char *p;            int i;            /* If a comment begins this line, then indent it to the right             * column for comments, otherwise the line starts with code,             * so indent it for code. */                        if (embedded_comment_on_line == 1)            {                target_col = parser_state_tos->com_col;            }            else if (target_col_break != -1)            {                target_col = target_col_break;            }            else            {                target_col = compute_code_target (*paren_targ);            }            /* If a line ends in an lparen character, the following line should             * not line up with the parenthesis, but should be indented by the             * usual amount.  */                        if (parser_state_tos->last_token == lparen)            {                parser_state_tos->paren_indents[parser_state_tos->p_l_follow - 1] += settings.ind_size - 1;            }            cur_col = pad_output (cur_col, target_col);            if (break_line && (s_com == e_com) &&                (buf_break->target_col <= buf_break->col))            {                int offset, len;                char c;                char *ptr = &s_code[buf_break->offset];                if (*ptr != ' ')                {                    --ptr;                }                /* Add target_col (and negate) the brackets that are                 * actually printed.  The remaining brackets must                 * be given an offset of . */                                offset = ptr - s_code + 1;                for (i = 0; i < parser_state_tos->p_l_follow; i++)                {                    if (parser_state_tos->paren_indents[i] >= 0)                    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -