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

📄 io.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1985 Sun Microsystems, Inc. * Copyright (c) 1980, 1993 *	The Regents of the University of California.  All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)io.c	8.1 (Berkeley) 6/6/93";#endif /* not lint */#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include "indent_globs.h"int         comment_open;static      paren_target;dump_line(){				/* dump_line is the 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 */    register int cur_col,                target_col;    static      not_first_line;    if (ps.procname[0]) {	if (troff) {	    if (comment_open) {		comment_open = 0;		fprintf(output, ".*/\n");	    }	    fprintf(output, ".Pr \"%s\"\n", ps.procname);	}	ps.ind_level = 0;	ps.procname[0] = 0;    }    if (s_code == e_code && s_lab == e_lab && s_com == e_com) {	if (suppress_blanklines > 0)	    suppress_blanklines--;	else {	    ps.bl_line = true;	    n_real_blanklines++;	}    }    else if (!inhibit_formatting) {	suppress_blanklines = 0;	ps.bl_line = false;	if (prefix_blankline_requested && not_first_line)	    if (swallow_optional_blanklines) {		if (n_real_blanklines == 1)		    n_real_blanklines = 0;	    }	    else {		if (n_real_blanklines == 0)		    n_real_blanklines = 1;	    }	while (--n_real_blanklines >= 0)	    putc('\n', output);	n_real_blanklines = 0;	if (ps.ind_level == 0)	    ps.ind_stmt = 0;	/* this is a class A kludge. dont do				 * additional statement indentation if we are				 * at bracket level 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 */	    if (comment_open) {		comment_open = 0;		fprintf(output, ".*/\n");	    }	    while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))		e_lab--;	    cur_col = pad_output(1, compute_label_target());	    if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0				    || strncmp(s_lab, "#endif", 6) == 0)) {		register char *s = s_lab;		if (e_lab[-1] == '\n') e_lab--;		do putc(*s++, output);		while (s < e_lab && 'a' <= *s && *s<='z');		while ((*s == ' ' || *s == '\t') && s < e_lab)		    s++;		if (s < e_lab)		    fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",			    e_lab - s, s);	    }	    else fprintf(output, "%.*s", e_lab - s_lab, s_lab);	    cur_col = count_spaces(cur_col, s_lab);	}	else	    cur_col = 1;	/* there is no label section */	ps.pcase = false;	if (s_code != e_code) {	/* print code section, if any */	    register char *p;	    if (comment_open) {		comment_open = 0;		fprintf(output, ".*/\n");	    }	    target_col = compute_code_target();	    {		register    i;		for (i = 0; i < ps.p_l_follow; i++)		    if (ps.paren_indents[i] >= 0)			ps.paren_indents[i] = -(ps.paren_indents[i] + target_col);	    }	    cur_col = pad_output(cur_col, target_col);	    for (p = s_code; p < e_code; p++)		if (*p == (char) 0200)		    fprintf(output, "%d", target_col * 7);		else		    putc(*p, output);	    cur_col = count_spaces(cur_col, s_code);	}	if (s_com != e_com)	    if (troff) {		int         all_here = 0;		register char *p;		if (e_com[-1] == '/' && e_com[-2] == '*')		    e_com -= 2, all_here++;		while (e_com > s_com && e_com[-1] == ' ')		    e_com--;		*e_com = 0;		p = s_com;		while (*p == ' ')		    p++;		if (p[0] == '/' && p[1] == '*')		    p += 2, all_here++;		else if (p[0] == '*')		    p += p[1] == '/' ? 2 : 1;		while (*p == ' ')		    p++;		if (*p == 0)		    goto inhibit_newline;		if (comment_open < 2 && ps.box_com) {		    comment_open = 0;		    fprintf(output, ".*/\n");		}		if (comment_open == 0) {		    if ('a' <= *p && *p <= 'z')			*p = *p + 'A' - 'a';		    if (e_com - p < 50 && all_here == 2) {			register char *follow = p;			fprintf(output, "\n.nr C! \\w\1");			while (follow < e_com) {			    switch (*follow) {			    case '\n':				putc(' ', output);			    case 1:				break;			    case '\\':				putc('\\', output);			    default:				putc(*follow, output);			    }			    follow++;			}			putc(1, output);		    }		    fprintf(output, "\n./* %dp %d %dp\n",			    ps.com_col * 7,			    (s_code != e_code || s_lab != e_lab) - ps.box_com,			    target_col * 7);		}		comment_open = 1 + ps.box_com;		while (*p) {		    if (*p == BACKSLASH)			putc(BACKSLASH, output);		    putc(*p++, output);		}	    }	    else {		/* print comment, if any */		register    target = ps.com_col;		register char *com_st = s_com;		target += ps.comment_delta;		while (*com_st == '\t')		    com_st++, target += 8;	/* ? */		while (target <= 0)		    if (*com_st == ' ')			target++, com_st++;		    else if (*com_st == '\t')			target = ((target - 1) & ~7) + 9, com_st++;		    else			target = 1;		if (cur_col > target) {	/* if comment cant fit on this line,					 * put it on next line */		    putc('\n', output);		    cur_col = 1;		    ++ps.out_lines;		}		while (e_com > com_st && isspace(e_com[-1]))		    e_com--;		cur_col = pad_output(cur_col, target);		if (!ps.box_com) {		    if (star_comment_cont && (com_st[1] != '*' || e_com <= com_st + 1))			if (com_st[1] == ' ' && com_st[0] == ' ' && e_com > com_st + 1)			    com_st[1] = '*';			else			    fwrite(" * ", com_st[0] == '\t' ? 2 : com_st[0] == '*' ? 1 : 3, 1, output);		}		fwrite(com_st, e_com - com_st, 1, output);		ps.comment_delta = ps.n_comment_delta;		cur_col = count_spaces(cur_col, com_st);		++ps.com_lines;	/* count lines with comments */	    }	if (ps.use_ff)	    putc('\014', output);	else	    putc('\n', output);inhibit_newline:	++ps.out_lines;	if (ps.just_saw_decl == 1 && blanklines_after_declarations) {	    prefix_blankline_requested = 1;	    ps.just_saw_decl = 0;	}	else	    prefix_blankline_requested = postfix_blankline_requested;	postfix_blankline_requested = 0;    }    ps.decl_on_line = ps.in_decl;	/* if we are in the middle of a					 * declaration, remember that fact for					 * proper comment indentation */    ps.ind_stmt = ps.in_stmt & ~ps.in_decl;	/* next line should be						 * indented if we have not						 * completed this stmt and if						 * we are not in the middle of						 * a declaration */    ps.use_ff = false;    ps.dumped_decl_indent = 0;    *(e_lab = s_lab) = '\0';	/* reset buffers */    *(e_code = s_code) = '\0';    *(e_com = s_com) = '\0';    ps.ind_level = ps.i_l_follow;    ps.paren_level = ps.p_l_follow;    paren_target = -ps.paren_indents[ps.paren_level - 1];    not_first_line = 1;    return;}compute_code_target(){    register    target_col = ps.ind_size * ps.ind_level + 1;    if (ps.paren_level)	if (!lineup_to_parens)	    target_col += continuation_indent * ps.paren_level;	else {	    register    w;	    register    t = paren_target;	    if ((w = count_spaces(t, s_code) - max_col) > 0		    && count_spaces(target_col, s_code) <= max_col) {		t -= w + 1;		if (t > target_col)		    target_col = t;	    }	    else		target_col = t;	}    else if (ps.ind_stmt)	target_col += continuation_indent;    return target_col;}compute_label_target(){    return	ps.pcase ? (int) (case_ind * ps.ind_size) + 1	: *s_lab == '#' ? 1	: ps.ind_size * (ps.ind_level - label_offset) + 1;}

⌨️ 快捷键说明

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