=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/indent/io.c,v retrieving revision 1.3 retrieving revision 1.4 diff -c -r1.3 -r1.4 *** src/usr.bin/indent/io.c 1997/07/25 22:00:46 1.3 --- src/usr.bin/indent/io.c 2001/01/08 07:14:42 1.4 *************** *** 1,8 **** ! /* $OpenBSD: io.c,v 1.3 1997/07/25 22:00:46 mickey Exp $ */ /* * Copyright (c) 1985 Sun Microsystems, Inc. ! * Copyright (c) 1980 The Regents of the University of California. * Copyright (c) 1976 Board of Trustees of the University of Illinois. * All rights reserved. * --- 1,8 ---- ! /* $OpenBSD: io.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $ */ /* * Copyright (c) 1985 Sun Microsystems, Inc. ! * Copyright (c) 1980, 1993 The Regents of the University of California. * Copyright (c) 1976 Board of Trustees of the University of Illinois. * All rights reserved. * *************** *** 36,43 **** */ #ifndef lint ! /*static char sccsid[] = "from: @(#)io.c 5.15 (Berkeley) 2/26/91";*/ ! static char rcsid[] = "$OpenBSD: io.c,v 1.3 1997/07/25 22:00:46 mickey Exp $"; #endif /* not lint */ #include --- 36,43 ---- */ #ifndef lint ! /*static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";*/ ! static char rcsid[] = "$OpenBSD: io.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $"; #endif /* not lint */ #include *************** *** 49,55 **** int comment_open; ! static paren_target; void dump_line() --- 49,55 ---- int comment_open; ! static int paren_target; void dump_line() *************** *** 58,66 **** * 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) { --- 58,65 ---- * prints the label section, followed by the * code section with the appropriate nesting * level, followed by any comments */ ! int cur_col, target_col; ! static int not_first_line; if (ps.procname[0]) { if (troff) { *************** *** 84,98 **** 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; --- 83,97 ---- 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; *************** *** 115,131 **** 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 --- 114,132 ---- cur_col = pad_output(1, compute_label_target()); if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0 || strncmp(s_lab, "#endif", 6) == 0)) { ! 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 */", ! (int)(e_lab - s), s); } ! else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab); cur_col = count_spaces(cur_col, s_lab); } else *************** *** 134,140 **** ps.pcase = false; if (s_code != e_code) { /* print code section, if any */ ! register char *p; if (comment_open) { comment_open = 0; --- 135,141 ---- ps.pcase = false; if (s_code != e_code) { /* print code section, if any */ ! char *p; if (comment_open) { comment_open = 0; *************** *** 142,148 **** } target_col = compute_code_target(); { ! register i; for (i = 0; i < ps.p_l_follow; i++) if (ps.paren_indents[i] >= 0) --- 143,149 ---- } target_col = compute_code_target(); { ! int i; for (i = 0; i < ps.p_l_follow; i++) if (ps.paren_indents[i] >= 0) *************** *** 156,165 **** 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++; --- 157,166 ---- putc(*p, output); cur_col = count_spaces(cur_col, s_code); } ! if (s_com != e_com) { if (troff) { ! int all_here = 0; ! char *p; if (e_com[-1] == '/' && e_com[-2] == '*') e_com -= 2, all_here++; *************** *** 185,191 **** 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) { --- 186,192 ---- if ('a' <= *p && *p <= 'z') *p = *p + 'A' - 'a'; if (e_com - p < 50 && all_here == 2) { ! char *follow = p; fprintf(output, "\n.nr C! \\w\1"); while (follow < e_com) { switch (*follow) { *************** *** 213,222 **** 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') --- 214,222 ---- putc(BACKSLASH, output); putc(*p++, output); } ! } else { /* print comment, if any */ ! int target = ps.com_col; ! char *com_st = s_com; target += ps.comment_delta; while (*com_st == '\t') *************** *** 238,254 **** 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 --- 238,256 ---- 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 *************** *** 286,299 **** int 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) { --- 288,302 ---- int compute_code_target() { ! int target_col; + 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 { ! int w; ! int t = paren_target; if ((w = count_spaces(t, s_code) - max_col) > 0 && count_spaces(target_col, s_code) <= max_col) { *************** *** 337,345 **** void fill_buffer() { /* this routine reads stuff from the input */ ! register char *p; ! register int i; ! register FILE *f = input; if (bp_save != 0) { /* there is a partly filled input buffer left */ buf_ptr = bp_save; /* dont read anything, just switch buffers */ --- 340,348 ---- void fill_buffer() { /* this routine reads stuff from the input */ ! char *p; ! int i; ! FILE *f = input; if (bp_save != 0) { /* there is a partly filled input buffer left */ buf_ptr = bp_save; /* dont read anything, just switch buffers */ *************** *** 351,360 **** } for (p = in_buffer;;) { if (p >= in_buffer_limit) { ! register size = (in_buffer_limit - in_buffer) * 2 + 10; ! register offset = p - in_buffer; in_buffer = (char *) realloc(in_buffer, size); ! if (in_buffer == 0) errx(1, "input line too long"); p = in_buffer + offset; in_buffer_limit = in_buffer + size - 2; --- 354,363 ---- } for (p = in_buffer;;) { if (p >= in_buffer_limit) { ! int size = (in_buffer_limit - in_buffer) * 2 + 10; ! int offset = p - in_buffer; in_buffer = (char *) realloc(in_buffer, size); ! if (in_buffer == NULL) errx(1, "input line too long"); p = in_buffer + offset; in_buffer_limit = in_buffer + size - 2; *************** *** 391,401 **** p++; if (*p == '*') com = 1; ! else if (*p == 'O') if (*++p == 'N') p++, com = 1; else if (*p == 'F' && *++p == 'F') p++, com = 2; while (*p == ' ' || *p == '\t') p++; if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) { --- 394,405 ---- p++; if (*p == '*') com = 1; ! else if (*p == 'O') { if (*++p == 'N') p++, com = 1; else if (*p == 'F' && *++p == 'F') p++, com = 2; + } while (*p == ' ' || *p == '\t') p++; if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) { *************** *** 456,463 **** int current; /* the current column value */ int target; /* position we want it at */ { ! register int curr; /* internal column pointer */ ! register int tcur; if (troff) fprintf(output, "\\h'|%dp'", (target - 1) * 7); --- 460,467 ---- int current; /* the current column value */ int target; /* position we want it at */ { ! int curr; /* internal column pointer */ ! int tcur; if (troff) fprintf(output, "\\h'|%dp'", (target - 1) * 7); *************** *** 504,511 **** int current; char *buffer; { ! register char *buf; /* used to look thru buffer */ ! register int cur; /* current character counter */ cur = current; --- 508,515 ---- int current; char *buffer; { ! char *buf; /* used to look thru buffer */ ! int cur; /* current character counter */ cur = current; *************** *** 533,561 **** return (cur); } int found_err; /* VARARGS2 */ void ! diag(level, msg, a, b) char *msg; { if (level) found_err = 1; if (output == stdout) { fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no); ! fprintf(stdout, msg, a, b); fprintf(stdout, " */\n"); } else { fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no); ! fprintf(stderr, msg, a, b); fprintf(stderr, "\n"); } } void writefdef(f, nm) ! register struct fstate *f; { fprintf(output, ".ds f%c %s\n.nr s%c %d\n", nm, f->font, nm, f->size); --- 537,587 ---- return (cur); } + #if __STDC__ + #include + #else + #include + #endif + int found_err; + /* VARARGS2 */ void ! #if __STDC__ ! diag(int level, char *msg, ...) ! #else ! diag(level, msg, va_alist) ! int level; char *msg; + va_dcl + #endif { + va_list ap; + #if __STDC__ + va_start(ap, msg); + #else + va_start(ap); + #endif + if (level) found_err = 1; if (output == stdout) { fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no); ! vfprintf(stdout, msg, ap); fprintf(stdout, " */\n"); } else { fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no); ! vfprintf(stderr, msg, ap); fprintf(stderr, "\n"); } + va_end(ap); } void writefdef(f, nm) ! struct fstate *f; ! int nm; { fprintf(output, ".ds f%c %s\n.nr s%c %d\n", nm, f->font, nm, f->size); *************** *** 563,570 **** char * chfont(of, nf, s) ! register struct fstate *of, ! *nf; char *s; { if (of->font[0] != nf->font[0] --- 589,595 ---- char * chfont(of, nf, s) ! struct fstate *of, *nf; char *s; { if (of->font[0] != nf->font[0] *************** *** 596,605 **** void parsefont(f, s0) ! register struct fstate *f; char *s0; { ! register char *s = s0; int sizedelta = 0; bzero(f, sizeof *f); while (*s) { --- 621,630 ---- void parsefont(f, s0) ! struct fstate *f; char *s0; { ! char *s = s0; int sizedelta = 0; bzero(f, sizeof *f); while (*s) {