staticchar *lookahead_buf; /* malloc'd buffer, or NULL initially */ staticchar *lookahead_buf_end; /* end+1 of allocated space */ staticchar *lookahead_start; /* => next char for fill_buffer() to fetch */ staticchar *lookahead_ptr; /* => next char for lookahead() to fetch */ staticchar *lookahead_end; /* last+1 valid char in lookahead_buf */ staticchar *lookahead_bp_save; /* lookahead position in bp_save, if any */
staticint pad_output(int current, int target);
void
dump_line(void)
{ /* dump_line is the routine that actually *effectstheprintingofthenewsource.It *printsthelabelsection,followedbythe *codesectionwiththeappropriatenesting
* level, followed by any comments */ int cur_col,
target_col = 1; staticint not_first_line;
if (ps.procname[0]) {
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++;
}
} elseif (!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 *additionalstatementindentationifweare
* 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--;
*e_lab = '\0';
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
cur_col = 1; /* there is no label section */
ps.pcase = false;
if (s_code != e_code) { /* print code section, if any */ char *p;
if (comment_open) {
comment_open = 0;
fprintf(output, ".*/\n");
}
target_col = compute_code_target();
{ int 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) { /* print comment, if any */ int target = ps.com_col; char *com_st = s_com;
target += ps.comment_delta; while (*com_st == '\t') /* consider original indentation in
* case this is a box comment */
com_st++, target += tabsize; while (target <= 0) if (*com_st == ' ')
target++, com_st++; elseif (*com_st == '\t')
target = tabsize * (1 + (target - 1) / tabsize) + 1, com_st++; else
target = 1; if (cur_col > target) { /* if comment can't fit on this line,
* put it on next line */
putc('\n', output);
cur_col = 1;
++ps.out_lines;
} while (e_com > com_st && isspace((unsignedchar)e_com[-1]))
e_com--;
(void)pad_output(cur_col, target);
fwrite(com_st, e_com - com_st, 1, output);
ps.comment_delta = ps.n_comment_delta;
++ps.com_lines; /* count lines with comments */
} if (ps.use_ff)
putc('\014', output); else
putc('\n', output);
++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,rememberthatfactfor
* proper comment indentation */ /* next line should be indented if we have not completed this stmt, and *eitherwearenotinadeclarationorweareinaninitialization *assignment;butnotifwe'rewithinbracesinaninitialization,
* because that scenario is handled by other rules. */
ps.ind_stmt = ps.in_stmt &&
(!ps.in_decl || (ps.block_init && ps.block_init_level <= 0));
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 = combuf + 1) = '\0';
ps.ind_level = ps.i_l_follow;
ps.paren_level = ps.p_l_follow; if (ps.paren_level > 0)
paren_target = -ps.paren_indents[ps.paren_level - 1];
not_first_line = 1;
}
int
compute_code_target(void)
{ int target_col = ps.ind_size * ps.ind_level + 1;
if (ps.paren_level) if (!lineup_to_parens)
target_col += continuation_indent
* (2 * continuation_indent == ps.ind_size ? 1 : ps.paren_level); elseif (lineup_to_parens_always)
target_col = paren_target; else { int w; int t = paren_target;
/* *Readdataaheadofwhathasbeencollectedintoin_buffer. * *Successivecallsgetfurtherandfurtherahead,untilwehitEOF. *Calllookahead_reset()torescanfromjustbeyondin_buffer. * *Lookaheadisautomaticallyresetwheneverfill_buffer()readsbeyond *thelookaheadbuffer,i.e.,youcan'tusethisfor"lookbehind". * *Thestandardpatternforpotentiallymulti-linelookaheadistocall *lookahead_reset(),thenenteraloopthatscansforwardfrombuf_ptr *tobuf_end,then(ifnecessary)callslookahead()toreadadditional *charactersfrombeyondtheendofthecurrentline.
*/ int
lookahead(void)
{ /* First read whatever's in bp_save area */ if (lookahead_bp_save != NULL && lookahead_bp_save < be_save) return (unsignedchar) *lookahead_bp_save++; /* Else, we have to examine and probably fill the main lookahead buffer */ while (lookahead_ptr >= lookahead_end) { int i = getc(input);
if (i == EOF) return i; if (i == '\0') continue; /* fill_buffer drops nulls, and so do we */
if (lookahead_end >= lookahead_buf_end) { /* Need to allocate or enlarge lookahead_buf */ char *new_buf;
size_t req;
/* *Resetsothatlookahead()willagainscanfromjustbeyondwhat'sin *in_buffer.
*/ void
lookahead_reset(void)
{ /* Reset the main lookahead buffer */
lookahead_ptr = lookahead_start; /* If bp_save isn't NULL, we need to scan that first */
lookahead_bp_save = bp_save;
}
/* *Copyright(C)1976bytheBoardofTrusteesoftheUniversityofIllinois * *Allrightsreserved * * *NAME:fill_buffer * *FUNCTION:Readsonelineofinputintoin_buffer, *setsupbuf_ptrandbuf_endtopointtotheline'sstartandend+1. *(Notethatthebufferdoesnotgetnull-terminated.) * *HISTORY:initialcodingNovember1976DAWillcoxofCAC1/7/77A *WillcoxofCACAddedcheckforswitchbacktopartlyfullinput *bufferfromtemporarybuffer *
*/ void
fill_buffer(void)
{ /* this routine reads stuff from the input */ char *p; int i;
FILE *f = input;
if (bp_save != NULL) { /* there is a partly filled input buffer left */
buf_ptr = bp_save; /* do not read anything, just switch buffers */
buf_end = be_save;
bp_save = be_save = NULL;
lookahead_bp_save = NULL; if (buf_ptr < buf_end) return; /* only return if there is really something in
* this buffer */
} 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 = 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;
} if (lookahead_start < lookahead_end) {
i = (unsignedchar) *lookahead_start++;
} else {
lookahead_start = lookahead_ptr = lookahead_end = lookahead_buf; if ((i = getc(f)) == EOF) {
*p++ = ' ';
*p++ = '\n';
had_eof = true; break;
}
} if (i != '\0')
*p++ = i; if (i == '\n') break;
}
buf_ptr = in_buffer;
buf_end = p; if (p - in_buffer > 2 && p[-2] == '/' && p[-3] == '*') { if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
fill_buffer(); /* flush indent error message */ else { int com = 0;
p = in_buffer; while (*p == ' ' || *p == '\t')
p++; if (*p == '/' && p[1] == '*') {
p += 2; while (*p == ' ' || *p == '\t')
p++; if (p[0] == 'I' && p[1] == 'N' && p[2] == 'D' && p[3] == 'E'
&& p[4] == 'N' && p[5] == 'T') {
p += 6; while (*p == ' ' || *p == '\t')
p++; if (*p == '*')
com = 1; elseif (*p == 'O') { if (*++p == 'N')
p++, com = 1; elseif (*p == 'F' && *++p == 'F')
p++, com = 2;
} while (*p == ' ' || *p == '\t')
p++; if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && com) { if (s_com != e_com || s_lab != e_lab || s_code != e_code)
dump_line(); if (!(inhibit_formatting = com - 1)) {
n_real_blanklines = 0;
postfix_blankline_requested = 0;
prefix_blankline_requested = 0;
suppress_blanklines = 1;
}
}
}
}
}
} if (inhibit_formatting) {
p = in_buffer; do
putc(*p, output); while (*p++ != '\n');
}
}
/* *Copyright(C)1976bytheBoardofTrusteesoftheUniversityofIllinois * *Allrightsreserved * * *NAME:pad_output * *FUNCTION:Writestabsandspacestomovethecurrentcolumnuptothedesired *position. * *ALGORITHM:Puttabsand/orblanksintopobuf,thenwritepobuf. * *PARAMETERS:currentintegerThecurrentcolumn *targetintegerThedesiredcolumn * *RETURNS:Integervalueofthenewcolumn.(Ifcurrent>=target,noactionis *taken,andcurrentisreturned. * *GLOBALS:None * *CALLS:write(sys) * *CALLEDBY:dump_line * *HISTORY:initialcodingNovember1976DAWillcoxofCAC *
*/ staticint
pad_output(int current, int target) /* writes tabs and blanks (if necessary) to *getthecurrentoutputpositionuptothe
* target column */ /* current: the current column value */ /* target: position we want it at */
{ int curr; /* internal column pointer */
if (current >= target) return (current); /* line is already long enough */
curr = current; if (use_tabs) { int tcur;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.21Bemerkung:
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-06)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.