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

📄 indent.c

📁 代码格式化工具。 其实就是linux下indent的windows版本。
💻 C
📖 第 1 页 / 共 5 页
字号:
#if 0        else if (!settings.braces_on_struct_decl_line &&                 (parser_state_tos->block_init != 1))        {            *force_nl = true;        }#endif    }    if ( (parser_state_tos->p_stack[parser_state_tos->tos] == ifhead) ||         ( (parser_state_tos->p_stack[parser_state_tos->tos] == dohead) &&           !settings.cuddle_do_while && !settings.btype_2))    {        *force_nl = true;    }    if (!parser_state_tos->in_decl && (parser_state_tos->tos <= 0) &&        settings.blanklines_after_procs && (parser_state_tos->dec_nest <= 0))    {        postfix_blankline_requested = 1;        postfix_blankline_requested_code =                parser_state_tos->in_decl ? decl : rbrace;    }}/******************************************************************************/static void handle_token_swstmt(    BOOLEAN        * sp_sw,    codes_ty       * hd_type){                *sp_sw = true;    *hd_type = swstmt;       /* keep this for when we have seen the                              * expression */    parser_state_tos->in_decl = false;}/******************************************************************************/static void handle_token_sp_paren(    BOOLEAN        * sp_sw,    codes_ty       * hd_type){    /* the interesting stuff is done after the expression is scanned */    *sp_sw = true;    /* remember the type of header for later use by parser */    *hd_type =            (*token == 'i' ? ifstmt : (*token == 'w' ? whilestmt : forstmt));}/******************************************************************************/static void handle_token_nparen(    BOOLEAN        * force_nl,    exit_values_ty * file_exit_value,    BOOLEAN        * last_else){    parser_state_tos->in_stmt = false;    if (*token == 'e')    {        if (e_code != s_code && (!settings.cuddle_else || e_code[-1] != '}'))        {            if (settings.verbose)            {                WARNING (_("Line broken"), 0, 0);            }                        dump_line (true, &paren_target);       /* make sure this starts a line */            parser_state_tos->want_blank = false;        }                /* This will be over ridden when next we read an `if' */                *force_nl = true;    /* also, following stuff must go onto new                              * line */        *last_else = 1;        if (parse (elselit) != total_success)         {            *file_exit_value = indent_error;        }    }    else    {        if (e_code != s_code)        {            /* make sure this starts a line */                        if (settings.verbose)            {                WARNING (_("Line broken"), 0, 0);            }                        dump_line (true, &paren_target);            parser_state_tos->want_blank = false;        }                *force_nl = true;    /* also, following stuff must go onto new                              * line */        *last_else = 0;        if (parse (dolit) != total_success)         {            *file_exit_value = indent_error;        }    }}/******************************************************************************/static void handle_token_overloaded(    const bb_code_ty can_break){    char           * t_ptr;    if (parser_state_tos->want_blank)    {        set_buf_break (bb_overloaded, paren_target);        *e_code++ = ' ';    }    else if (can_break)    {        set_buf_break (can_break, paren_target);    }    parser_state_tos->want_blank = true;    for (t_ptr = token; t_ptr < token_end; ++t_ptr)    {        check_code_size();        *e_code++ = *t_ptr;    }    *e_code = '\0'; /* null terminate code sect */}/******************************************************************************/static void handle_token_decl(    int            * dec_ind,    exit_values_ty * file_exit_value){    /* handle C++ const function declarations like     * const MediaDomainList PVR::get_itsMediaDomainList() const     * {     * return itsMediaDomainList;     * }     * by ignoring "const" just after a parameter list */    if ((parser_state_tos->last_token == rparen) &&        parser_state_tos->in_parameter_declaration &&        parser_state_tos->saw_double_colon &&        !strncmp (token, "const", 5))    {        char           * t_ptr;        set_buf_break (bb_const_qualifier, paren_target);        *e_code++ = ' ';        for (t_ptr = token; t_ptr < token_end; ++t_ptr)        {            check_code_size();            *e_code++ = *t_ptr;        }        *e_code = '\0';     /* null terminate code sect */    }    else    {                if (!parser_state_tos->sizeof_mask)        {            if (parse (decl) != total_success)            {                *file_exit_value = indent_error;            }        }                if ((parser_state_tos->last_token == rparen) &&            (parser_state_tos->tos <= 1))        {            parser_state_tos->in_parameter_declaration = 1;                        if (s_code != e_code)            {                dump_line (true, &paren_target);                parser_state_tos->want_blank = false;            }        }        if (parser_state_tos->in_parameter_declaration &&            (parser_state_tos->dec_nest == 0) &&            (parser_state_tos->p_l_follow == 0))        {            parser_state_tos->ind_level = parser_state_tos->i_l_follow =                    settings.indent_parameters;            parser_state_tos->ind_stmt = false;        }                /* in_or_st set for struct or initialization decl. Don't set it if         * we're in ansi prototype */                if (!parser_state_tos->paren_depth)        {            parser_state_tos->in_or_st = 1;        }                if (!parser_state_tos->sizeof_mask)        {            parser_state_tos->in_decl      = true;            parser_state_tos->decl_on_line = true;                        if (parser_state_tos->dec_nest <= 0)            {                parser_state_tos->just_saw_decl = 2;            }        }                if (prefix_blankline_requested &&            ((parser_state_tos->block_init != 0) ||             (parser_state_tos->block_init_level != -1) ||             (parser_state_tos->last_token != rbrace) ||             (e_code != s_code) ||              (e_lab  != s_lab)  ||              (e_com  != s_com)))        {            prefix_blankline_requested = 0;        }                *dec_ind = settings.decl_indent > 0 ? settings.decl_indent :                                              token_end - token + 1; /* get length of token plus 1 */    }}/******************************************************************************/static void handle_token_ident(    BOOLEAN        * force_nl,    BOOLEAN        * sp_sw,    codes_ty       * hd_type,    int            * dec_ind,    exit_values_ty * file_exit_value,    const bb_code_ty can_break,    BOOLEAN          is_procname_definition){    /* If we are in a declaration, we must indent identifier. But not     * inside the parentheses of an ANSI function declaration.  */    if (parser_state_tos->in_decl &&        (parser_state_tos->p_l_follow == 0) &&        (parser_state_tos->last_token != rbrace))    {        if (parser_state_tos->want_blank)        {            set_buf_break (bb_ident, paren_target);            *e_code++ = ' ';            *e_code = '\0'; /* null terminate code sect */        }        else if (can_break)        {            set_buf_break (can_break, paren_target);        }        parser_state_tos->want_blank = false;        if ((is_procname_definition == false) ||            (!settings.procnames_start_line && (s_code != e_code)))        {            if (!parser_state_tos->block_init && !buf_break_used)            {                if (is_procname_definition)                {                    *dec_ind = 0;                }                while ((e_code - s_code) < *dec_ind)                {                    check_code_size();                    set_buf_break (bb_dec_ind, paren_target);                    *e_code++ = ' ';                }                *e_code = '\0';     /* null terminate code sect */                parser_state_tos->ind_stmt = false;            }        }        else        {            if ((s_code != e_code) &&                (parser_state_tos->last_token != doublecolon))            {                dump_line(true, &paren_target);            }            *dec_ind = 0;            parser_state_tos->want_blank = false;        }    }    else if (*sp_sw && parser_state_tos->p_l_follow == 0)    {        *sp_sw = false;        *force_nl = true;        parser_state_tos->last_u_d = true;        parser_state_tos->in_stmt = false;                        if (parse (*hd_type) != total_success)         {            *file_exit_value = indent_error;        }    }}/******************************************************************************/static void handle_token_struct_delim(void){    char           * t_ptr;    for (t_ptr = token; t_ptr < token_end; ++t_ptr)    {        check_code_size();        *e_code++ = *t_ptr;    }    parser_state_tos->want_blank = false;   /* dont put a blank after a                                             * period */    parser_state_tos->can_break = bb_struct_delim;}/******************************************************************************/static void handle_token_comma(    BOOLEAN        * force_nl,    int            * dec_ind,    BOOLEAN          is_procname_definition){    parser_state_tos->want_blank = true;    if ((parser_state_tos->paren_depth == 0) &&        parser_state_tos->in_decl &&        !buf_break_used && (is_procname_definition == false) &&        !parser_state_tos->block_init)    {        while ((e_code - s_code) < (*dec_ind - 1))        {            check_code_size();            set_buf_break (bb_dec_ind, paren_target);            *e_code++ = ' ';        }        parser_state_tos->ind_stmt = false;    }    *e_code++ = ',';    if (parser_state_tos->p_l_follow == 0)    {        if (parser_state_tos->block_init_level <= 0)        {            parser_state_tos->block_init = 0;        }        /* If we are in a declaration, and either the user wants all         * comma'd declarations broken, or the line is getting too         * long, break the line.  */        if (break_comma && !settings.leave_comma)        {            *force_nl = true;        }    }    if (parser_state_tos->block_init)    {        parser_state_tos->in_stmt = false;  /* Don't indent after comma */    }    /* For declarations, if user wants all fn decls broken, force that     * now. */    if (settings.break_function_decl_args &&        (!parser_state_tos->in_or_st &&         parser_state_tos->in_stmt && parser_state_tos->in_decl))    {        *force_nl = true;    }}/******************************************************************************/static void handle_token_preesc(    exit_values_ty * file_exit_value){    char * t_ptr;    char * p;    if ((s_com != e_com) || (s_lab != e_lab) || (s_code != e_code))    {        dump_line(true, &paren_target);    }    {        int in_comment = 0;        int in_cplus_comment = 0;        int com_start = 0;        char quote = 0;        int com_end = 0;        /* ANSI allows spaces between '#' and preprocessor directives.         * If the user specified "-lps" and there are such spaces,         * they will be part of `token', otherwise `token' is just         * '#'. */        for (t_ptr = token; t_ptr < token_end; ++t_ptr)        {            check_lab_size();            *e_lab++ = *t_ptr;        }        while (!had_eof && (*buf_ptr != EOL || in_comment))        {            check_lab_size();            *e_lab = *buf_ptr++;            if (buf_ptr >= buf_end)            {                fill_buffer ();            }            switch (*e_lab++)            {            case BACKSLASH:                if (!in_comment && !in_cplus_comment)                {                    *e_lab++ = *buf_ptr++;                    if (buf_ptr >= buf_end)

⌨️ 快捷键说明

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