* 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.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley, the University of Illinois,
* Urbana, and Sun Microsystems, Inc. The name of either University
* or Sun Microsystems may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)io.c 5.10 (Berkeley) %G%";
#include "indent_globs.h"
{ /* 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 */
fprintf(output
, ".*/\n");
fprintf(output
, ".Pr \"%s\"\n", ps
.procname
);
if (s_code
== e_code
&& s_lab
== e_lab
&& s_com
== e_com
) {
if (suppress_blanklines
> 0)
else if (!inhibit_formatting
) {
if (prefix_blankline_requested
&& not_first_line
)
if (swallow_optional_blanklines
) {
if (n_real_blanklines
== 1)
if (n_real_blanklines
== 0)
while (--n_real_blanklines
>= 0)
ps
.ind_stmt
= 0; /* this is a class A kludge. dont do
* additional statement indentation if we are
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 */
fprintf(output
, ".*/\n");
while (e_lab
> s_lab
&& (e_lab
[-1] == ' ' || e_lab
[-1] == '\t'))
cur_col
= pad_output(1, compute_label_target());
fprintf(output
, "%.*s", e_lab
- s_lab
, s_lab
);
cur_col
= count_spaces(cur_col
, s_lab
);
cur_col
= 1; /* there is no label section */
if (s_code
!= e_code
) { /* print code section, if any */
fprintf(output
, ".*/\n");
target_col
= compute_code_target();
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
++)
fprintf(output
, "%d", target_col
* 7);
cur_col
= count_spaces(cur_col
, s_code
);
if (e_com
[-1] == '/' && e_com
[-2] == '*')
while (e_com
> s_com
&& e_com
[-1] == ' ')
if (p
[0] == '/' && p
[1] == '*')
p
+= p
[1] == '/' ? 2 : 1;
if (comment_open
< 2 && ps
.box_com
) {
fprintf(output
, ".*/\n");
if ('a' <= *p
&& *p
<= 'z')
if (e_com
- p
< 50 && all_here
== 2) {
register char *follow
= p
;
fprintf(output
, "\n.nr C! \\w\1");
fprintf(output
, "\n./* %dp %d %dp\n",
(s_code
!= e_code
|| s_lab
!= e_lab
) - ps
.box_com
,
comment_open
= 1 + ps
.box_com
;
else { /* print comment, if any */
register target
= ps
.com_col
;
register char *com_st
= s_com
;
target
+= ps
.comment_delta
;
com_st
++, target
+= 8; /* ? */
else if (*com_st
== '\t')
target
= ((target
- 1) & ~7) + 9, com_st
++;
if (cur_col
> target
) { /* if comment cant fit on this line,
while (e_com
> com_st
&& isspace(e_com
[-1]))
cur_col
= pad_output(cur_col
, target
);
if (star_comment_cont
&& (com_st
[1] != '*' || e_com
<= com_st
+ 1))
if (com_st
[1] == ' ' && com_st
[0] == ' ' && e_com
> com_st
+ 1)
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
.just_saw_decl
== 1 && blanklines_after_declarations
) {
prefix_blankline_requested
= 1;
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
ps
.dumped_decl_indent
= 0;
*(e_lab
= s_lab
) = '\0'; /* reset buffers */
*(e_code
= s_code
) = '\0';
ps
.ind_level
= ps
.i_l_follow
;
ps
.paren_level
= ps
.p_l_follow
;
paren_target
= -ps
.paren_indents
[ps
.paren_level
- 1];
register target_col
= ps
.ind_size
* ps
.ind_level
+ 1;
target_col
+= continuation_indent
* ps
.paren_level
;
register t
= paren_target
;
if ((w
= count_spaces(t
, s_code
) - max_col
) > 0
&& count_spaces(target_col
, s_code
) <= max_col
) {
target_col
+= continuation_indent
;
ps
.pcase
? (int) (case_ind
* ps
.ind_size
) + 1
: ps
.ind_size
* (ps
.ind_level
- label_offset
) + 1;
* Copyright (C) 1976 by the Board of Trustees of the University of Illinois
* FUNCTION: Reads one block of input into input_buffer
* HISTORY: initial coding November 1976 D A Willcox of CAC 1/7/77 A
* Willcox of CAC Added check for switch back to partly full input
* buffer from temporary buffer
{ /* this routine reads stuff from the input */
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 */
return; /* only return if there is really something in
for (p
= buf_ptr
= in_buffer
;;) {
if ((i
= getc(f
)) == EOF
) {
if (p
[-2] == '/' && p
[-3] == '*') {
if (in_buffer
[3] == 'I' && strncmp(in_buffer
, "/**INDENT**", 11) == 0)
fill_buffer(); /* flush indent error message */
while (*p
== ' ' || *p
== '\t')
if (*p
== '/' && p
[1] == '*') {
while (*p
== ' ' || *p
== '\t')
if (p
[0] == 'I' && p
[1] == 'N' && p
[2] == 'D' && p
[3] == 'E'
&& p
[4] == 'N' && p
[5] == 'T') {
while (*p
== ' ' || *p
== '\t')
else if (*p
== 'F' && *++p
== 'F')
while (*p
== ' ' || *p
== '\t')
if (p
[0] == '*' && p
[1] == '/' && p
[2] == '\n' && com
) {
if (s_com
!= e_com
|| s_lab
!= e_lab
|| s_code
!= e_code
)
if (!(inhibit_formatting
= com
- 1)) {
postfix_blankline_requested
= 0;
prefix_blankline_requested
= 0;
if (inhibit_formatting
) {
* Copyright (C) 1976 by the Board of Trustees of the University of Illinois
* FUNCTION: Writes tabs and spaces to move the current column up to the desired
* ALGORITHM: Put tabs and/or blanks into pobuf, then write pobuf.
* PARAMETERS: current integer The current column target
* nteger The desired column
* RETURNS: Integer value of the new column. (If current >= target, no action is
* taken, and current is returned.
* HISTORY: initial coding November 1976 D A Willcox of CAC
pad_output(current
, target
) /* writes tabs and blanks (if necessary) to
* get the current output position up to the
int current
; /* the current column value */
int target
; /* position we want it at */
register int curr
; /* internal column pointer */
fprintf(output
, "\\h'|%dp'", (target
- 1) * 7);
return (current
); /* line is already long enough */
while ((tcur
= ((curr
- 1) & tabmask
) + tabsize
+ 1) <= target
) {
putc(' ', output
); /* pad with final blanks */
* Copyright (C) 1976 by the Board of Trustees of the University of Illinois
* FUNCTION: Find out where printing of a given string will leave the current
* character position on output.
* ALGORITHM: Run thru input string and add appropriate values to current
* RETURNS: Integer value of position after printing "buffer" starting in column
* HISTORY: initial coding November 1976 D A Willcox of CAC
count_spaces(current
, buffer
)
* this routine figures out where the character position will be after
* printing the text in buffer starting at column "current"
register char *buf
; /* used to look thru buffer */
register int cur
; /* current character counter */
for (buf
= buffer
; *buf
!= '\0'; ++buf
) {
case 014: /* form feed */
cur
= ((cur
- 1) & tabmask
) + tabsize
+ 1;
case '\b': /* this is a backspace */
fprintf(stdout
, "/**INDENT** %s@%d: ", level
== 0 ? "Warning" : "Error", line_no
);
fprintf(stdout
, msg
, a
, b
);
fprintf(stdout
, " */\n");
fprintf(stderr
, "%s@%d: ", level
== 0 ? "Warning" : "Error", line_no
);
fprintf(stderr
, msg
, a
, b
);
register struct fstate
*f
;
fprintf(output
, ".ds f%c %s\n.nr s%c %d\n",
nm
, f
->font
, nm
, f
->size
);
register struct fstate
*of
,
if (of
->font
[0] != nf
->font
[0]
|| of
->font
[1] != nf
->font
[1]) {
if (nf
->size
!= of
->size
) {
if (nf
->size
< of
->size
) {
*s
++ = '0' + of
->size
- nf
->size
;
*s
++ = '0' + nf
->size
- of
->size
;
register struct fstate
*f
;
f
->size
= f
->size
* 10 + *s
- '0';
fprintf(stderr
, "indent: bad font specification: %s\n", s0
);
f
->size
= bodyf
.size
+ sizedelta
;
f
->size
= bodyf
.size
- f
->size
;