This commit is contained in:
Alexander Popov 2022-09-30 01:01:29 +03:00
parent 58035f08a7
commit 006c3d1501
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
10 changed files with 2941 additions and 2816 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
indent indent
*.BAK

291
args.c
View File

@ -77,77 +77,209 @@ struct pro {
int *p_obj; /* the associated variable */ int *p_obj; /* the associated variable */
} pro[] = { } pro[] = {
{ "T", PRO_SPECIAL, 0, KEY, 0 }, {
{"bacc", PRO_BOOL, false, ON, "T", PRO_SPECIAL, 0, KEY, 0
&blanklines_around_conditional_compilation }, },
{"badp", PRO_BOOL, false, ON, {
&blanklines_after_declarations_at_proctop }, "bacc", PRO_BOOL, false, ON,
{"bad", PRO_BOOL, false, ON, &blanklines_after_declarations }, &blanklines_around_conditional_compilation
{"bap", PRO_BOOL, false, ON, &blanklines_after_procs }, },
{"bbb", PRO_BOOL, false, ON, &blanklines_before_blockcomments }, {
{"bc", PRO_BOOL, true, OFF, &ps.leave_comma }, "badp", PRO_BOOL, false, ON,
{"bl", PRO_BOOL, true, OFF, &btype_2 }, &blanklines_after_declarations_at_proctop
{"br", PRO_BOOL, true, ON, &btype_2 }, },
{"bs", PRO_BOOL, false, ON, &Bill_Shannon }, {
{"cdb", PRO_BOOL, true, ON, &comment_delimiter_on_blankline }, "bad", PRO_BOOL, false, ON, &blanklines_after_declarations
{"cd", PRO_INT, 0, 0, &ps.decl_com_ind }, },
{"ce", PRO_BOOL, true, ON, &cuddle_else }, {
{"ci", PRO_INT, 0, 0, &continuation_indent }, "bap", PRO_BOOL, false, ON, &blanklines_after_procs
{"cli", PRO_SPECIAL, 0, CLI, 0 }, },
{"c", PRO_INT, 33, 0, &ps.com_ind }, {
{"di", PRO_INT, 16, 0, &ps.decl_indent }, "bbb", PRO_BOOL, false, ON, &blanklines_before_blockcomments
{"dj", PRO_BOOL, false, ON, &ps.ljust_decl }, },
{"d", PRO_INT, 0, 0, &ps.unindent_displace }, {
{"eei", PRO_BOOL, false, ON, &extra_expression_indent }, "bc", PRO_BOOL, true, OFF, &ps.leave_comma
{"ei", PRO_BOOL, true, ON, &ps.else_if }, },
{"fbc", PRO_FONT, 0, 0, (int *) &blkcomf }, {
{"fbx", PRO_FONT, 0, 0, (int *) &boxcomf }, "bl", PRO_BOOL, true, OFF, &btype_2
{"fb", PRO_FONT, 0, 0, (int *) &bodyf }, },
{"fc1", PRO_BOOL, true, ON, &format_col1_comments }, {
{"fc", PRO_FONT, 0, 0, (int *) &scomf }, "br", PRO_BOOL, true, ON, &btype_2
{"fk", PRO_FONT, 0, 0, (int *) &keywordf }, },
{"fs", PRO_FONT, 0, 0, (int *) &stringf }, {
{"ip", PRO_BOOL, true, ON, &ps.indent_parameters }, "bs", PRO_BOOL, false, ON, &Bill_Shannon
{"i", PRO_INT, 8, 0, &ps.ind_size }, },
{"lc", PRO_INT, 0, 0, &block_comment_max_col }, {
{"lp", PRO_BOOL, true, ON, &lineup_to_parens }, "cdb", PRO_BOOL, true, ON, &comment_delimiter_on_blankline
{"l", PRO_INT, 78, 0, &max_col }, },
{"nbacc", PRO_BOOL, false, OFF, {
&blanklines_around_conditional_compilation }, "cd", PRO_INT, 0, 0, &ps.decl_com_ind
{"nbadp", PRO_BOOL, false, OFF, },
&blanklines_after_declarations_at_proctop }, {
{"nbad", PRO_BOOL, false, OFF, &blanklines_after_declarations }, "ce", PRO_BOOL, true, ON, &cuddle_else
{"nbap", PRO_BOOL, false, OFF, &blanklines_after_procs }, },
{"nbbb", PRO_BOOL, false, OFF, &blanklines_before_blockcomments }, {
{"nbc", PRO_BOOL, true, ON, &ps.leave_comma }, "ci", PRO_INT, 0, 0, &continuation_indent
{"nbs", PRO_BOOL, false, OFF, &Bill_Shannon }, },
{"ncdb", PRO_BOOL, true, OFF, &comment_delimiter_on_blankline }, {
{"nce", PRO_BOOL, true, OFF, &cuddle_else }, "cli", PRO_SPECIAL, 0, CLI, 0
{"ndj", PRO_BOOL, false, OFF, &ps.ljust_decl }, },
{"neei", PRO_BOOL, false, OFF, &extra_expression_indent }, {
{"nei", PRO_BOOL, true, OFF, &ps.else_if }, "c", PRO_INT, 33, 0, &ps.com_ind
{"nfc1", PRO_BOOL, true, OFF, &format_col1_comments }, },
{"nip", PRO_BOOL, true, OFF, &ps.indent_parameters }, {
{"nlp", PRO_BOOL, true, OFF, &lineup_to_parens }, "di", PRO_INT, 16, 0, &ps.decl_indent
{"npcs", PRO_BOOL, false, OFF, &proc_calls_space }, },
{"npro", PRO_SPECIAL, 0, IGN, 0 }, {
{"npsl", PRO_BOOL, true, OFF, &procnames_start_line }, "dj", PRO_BOOL, false, ON, &ps.ljust_decl
{"nps", PRO_BOOL, false, OFF, &pointer_as_binop }, },
{"nsc", PRO_BOOL, true, OFF, &star_comment_cont }, {
{"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines }, "d", PRO_INT, 0, 0, &ps.unindent_displace
{"nut", PRO_BOOL, true, OFF, &use_tabs}, },
{"nv", PRO_BOOL, false, OFF, &verbose }, {
{"pcs", PRO_BOOL, false, ON, &proc_calls_space }, "eei", PRO_BOOL, false, ON, &extra_expression_indent
{"psl", PRO_BOOL, true, ON, &procnames_start_line }, },
{"ps", PRO_BOOL, false, ON, &pointer_as_binop }, {
{"sc", PRO_BOOL, true, ON, &star_comment_cont }, "ei", PRO_BOOL, true, ON, &ps.else_if
{"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines }, },
{"st", PRO_SPECIAL, 0, STDIN, 0 }, {
{"troff", PRO_BOOL, false, ON, &troff }, "fbc", PRO_FONT, 0, 0, (int *) &blkcomf
{"ut", PRO_BOOL, true, ON, &use_tabs}, },
{"v", PRO_BOOL, false, ON, &verbose }, {
"fbx", PRO_FONT, 0, 0, (int *) &boxcomf
},
{
"fb", PRO_FONT, 0, 0, (int *) &bodyf
},
{
"fc1", PRO_BOOL, true, ON, &format_col1_comments
},
{
"fc", PRO_FONT, 0, 0, (int *) &scomf
},
{
"fk", PRO_FONT, 0, 0, (int *) &keywordf
},
{
"fs", PRO_FONT, 0, 0, (int *) &stringf
},
{
"ip", PRO_BOOL, true, ON, &ps.indent_parameters
},
{
"i", PRO_INT, 8, 0, &ps.ind_size
},
{
"lc", PRO_INT, 0, 0, &block_comment_max_col
},
{
"lp", PRO_BOOL, true, ON, &lineup_to_parens
},
{
"l", PRO_INT, 78, 0, &max_col
},
{
"nbacc", PRO_BOOL, false, OFF,
&blanklines_around_conditional_compilation
},
{
"nbadp", PRO_BOOL, false, OFF,
&blanklines_after_declarations_at_proctop
},
{
"nbad", PRO_BOOL, false, OFF, &blanklines_after_declarations
},
{
"nbap", PRO_BOOL, false, OFF, &blanklines_after_procs
},
{
"nbbb", PRO_BOOL, false, OFF, &blanklines_before_blockcomments
},
{
"nbc", PRO_BOOL, true, ON, &ps.leave_comma
},
{
"nbs", PRO_BOOL, false, OFF, &Bill_Shannon
},
{
"ncdb", PRO_BOOL, true, OFF, &comment_delimiter_on_blankline
},
{
"nce", PRO_BOOL, true, OFF, &cuddle_else
},
{
"ndj", PRO_BOOL, false, OFF, &ps.ljust_decl
},
{
"neei", PRO_BOOL, false, OFF, &extra_expression_indent
},
{
"nei", PRO_BOOL, true, OFF, &ps.else_if
},
{
"nfc1", PRO_BOOL, true, OFF, &format_col1_comments
},
{
"nip", PRO_BOOL, true, OFF, &ps.indent_parameters
},
{
"nlp", PRO_BOOL, true, OFF, &lineup_to_parens
},
{
"npcs", PRO_BOOL, false, OFF, &proc_calls_space
},
{
"npro", PRO_SPECIAL, 0, IGN, 0
},
{
"npsl", PRO_BOOL, true, OFF, &procnames_start_line
},
{
"nps", PRO_BOOL, false, OFF, &pointer_as_binop
},
{
"nsc", PRO_BOOL, true, OFF, &star_comment_cont
},
{
"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines
},
{
"nut", PRO_BOOL, true, OFF, &use_tabs
},
{
"nv", PRO_BOOL, false, OFF, &verbose
},
{
"pcs", PRO_BOOL, false, ON, &proc_calls_space
},
{
"psl", PRO_BOOL, true, ON, &procnames_start_line
},
{
"ps", PRO_BOOL, false, ON, &pointer_as_binop
},
{
"sc", PRO_BOOL, true, ON, &star_comment_cont
},
{
"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines
},
{
"st", PRO_SPECIAL, 0, STDIN, 0
},
{
"troff", PRO_BOOL, false, ON, &troff
},
{
"ut", PRO_BOOL, true, ON, &use_tabs
},
{
"v", PRO_BOOL, false, ON, &verbose
},
/* whew! */ /* whew! */
{ 0, 0, 0, 0, 0 } {
0, 0, 0, 0, 0
}
}; };
void scan_profile(FILE *); void scan_profile(FILE *);
@ -168,11 +300,12 @@ set_profile(void)
home = getenv("HOME"); home = getenv("HOME");
if (home != NULL && *home != '\0') { if (home != NULL && *home != '\0') {
if (snprintf(fname, sizeof fname, "%s/%s", home, prof) >= sizeof fname) { if (snprintf(fname, sizeof fname, "%s/%s", home, prof) >= sizeof fname) {
#if defined(__linux__) #if defined(__linux__)
printf("%s/%s", home, prof); // FIXIT printf("%s/%s", home, prof);
#else //FIXIT
#else
warnc(ENAMETOOLONG, "%s/%s", home, prof); warnc(ENAMETOOLONG, "%s/%s", home, prof);
#endif #endif
return; return;
} }
if ((f = fopen(option_source = fname, "r")) != NULL) { if ((f = fopen(option_source = fname, "r")) != NULL) {
@ -188,7 +321,7 @@ set_profile(void)
} }
void void
scan_profile(FILE *f) scan_profile(FILE * f)
{ {
int i; int i;
char *p; char *p;
@ -197,15 +330,13 @@ scan_profile(FILE *f)
while (1) { while (1) {
for (p = buf; for (p = buf;
(i = getc(f)) != EOF && (*p = i) > ' ' && p + 1 - buf < BUFSIZ; (i = getc(f)) != EOF && (*p = i) > ' ' && p + 1 - buf < BUFSIZ;
++p) ++p);
;
if (p != buf) { if (p != buf) {
*p = 0; *p = 0;
if (verbose) if (verbose)
printf("profile: %s\n", buf); printf("profile: %s\n", buf);
set_option(buf); set_option(buf);
} } else if (i == EOF)
else if (i == EOF)
return; return;
} }
} }
@ -297,7 +428,7 @@ found:
break; break;
case PRO_INT: case PRO_INT:
if (!isdigit((unsigned char)*param_start)) { if (!isdigit((unsigned char) *param_start)) {
need_param: need_param:
errx(1, "%s: ``%s'' requires a parameter", option_source, arg - 1); errx(1, "%s: ``%s'' requires a parameter", option_source, arg - 1);
} }

222
indent.c
View File

@ -44,8 +44,8 @@
#include <errno.h> #include <errno.h>
#include <err.h> #include <err.h>
char *in_name = "Standard Input"; /* will always point to name of input char *in_name = "Standard Input"; /* will always point to name
* file */ * of input file */
char *out_name = "Standard Output"; /* will always point to name char *out_name = "Standard Output"; /* will always point to name
* of output file */ * of output file */
char bakfile[PATH_MAX] = ""; char bakfile[PATH_MAX] = "";
@ -74,13 +74,14 @@ char *e_token;
char *l_token; char *l_token;
char *in_buffer; /* input buffer */ char *in_buffer; /* input buffer */
char *in_buffer_limit; /* the end of the input buffer */ char *in_buffer_limit;/* the end of the input buffer */
char *buf_ptr; /* ptr to next character to be taken from char *buf_ptr; /* ptr to next character to be taken from
* in_buffer */ * in_buffer */
char *buf_end; /* ptr to first after last char in in_buffer */ char *buf_end; /* ptr to first after last char in in_buffer */
char save_com[sc_size]; /* input text is saved here when looking for char save_com[sc_size]; /* input text is saved here when
* the brace after an if, while, etc */ * looking for the brace after an if,
* while, etc */
char *sc_end; /* pointer into save_com buffer */ char *sc_end; /* pointer into save_com buffer */
char *bp_save; /* saved value of buf_ptr when taking input char *bp_save; /* saved value of buf_ptr when taking input
@ -106,11 +107,12 @@ int code_lines; /* count of lines with code */
int had_eof; /* set to true when input is exhausted */ int had_eof; /* set to true when input is exhausted */
int line_no; /* the current line number. */ int line_no; /* the current line number. */
int max_col; /* the maximum allowable line length */ int max_col; /* the maximum allowable line length */
int verbose; /* when true, non-essential error messages are int verbose; /* when true, non-essential error messages
* printed */ * are printed */
int cuddle_else; /* true if else should cuddle up to '}' */ int cuddle_else; /* true if else should cuddle up to '}' */
int star_comment_cont; /* true iff comment continuation lines should int star_comment_cont; /* true iff comment continuation
* have stars at the beginning of each line. */ * lines should have stars at the
* beginning of each line. */
int comment_delimiter_on_blankline; int comment_delimiter_on_blankline;
int troff; /* true iff were generating troff input */ int troff; /* true iff were generating troff input */
int procnames_start_line; /* if true, the names of procedures int procnames_start_line; /* if true, the names of procedures
@ -118,19 +120,22 @@ int procnames_start_line; /* if true, the names of procedures
* 1 (ie. a newline is placed between * 1 (ie. a newline is placed between
* the type of the procedure and its * the type of the procedure and its
* name) */ * name) */
int proc_calls_space; /* If true, procedure calls look like: int proc_calls_space; /* If true, procedure calls look
* foo(bar) rather than foo (bar) */ * like: foo(bar) rather than foo
int format_col1_comments; /* If comments which start in column 1 * (bar) */
* are to be magically reformatted int format_col1_comments; /* If comments which start in column
* 1 are to be magically reformatted
* (just like comments that begin in * (just like comments that begin in
* later columns) */ * later columns) */
int inhibit_formatting; /* true if INDENT OFF is in effect */ int inhibit_formatting; /* true if INDENT OFF is in effect */
int suppress_blanklines;/* set iff following blanklines should be int suppress_blanklines; /* set iff following blanklines
* suppressed */ * should be suppressed */
int continuation_indent;/* set to the indentation between the edge of int continuation_indent; /* set to the indentation between the
* code and continuation lines */ * edge of code and continuation
int lineup_to_parens; /* if true, continued code within parens will * lines */
* be lined up to the open paren */ int lineup_to_parens; /* if true, continued code within
* parens will be lined up to the
* open paren */
int Bill_Shannon; /* true iff a blank should always be inserted int Bill_Shannon; /* true iff a blank should always be inserted
* after sizeof */ * after sizeof */
int blanklines_after_declarations_at_proctop; /* This is vaguely int blanklines_after_declarations_at_proctop; /* This is vaguely
@ -147,14 +152,16 @@ int blanklines_after_declarations_at_proctop; /* This is vaguely
* if there are no * if there are no
* declarations */ * declarations */
int block_comment_max_col; int block_comment_max_col;
int extra_expression_indent; /* True if continuation lines from the int extra_expression_indent; /* True if continuation lines
* expression part of "if(e)", * from the expression part
* "while(e)", "for(e;e;e)" should be * of "if(e)", "while(e)",
* indented an extra tab stop so that * "for(e;e;e)" should be
* they don't conflict with the code * indented an extra tab stop
* so that they don't
* conflict with the code
* that follows */ * that follows */
int use_tabs; /* set true to use tabs for spacing, int use_tabs; /* set true to use tabs for spacing, false
* false uses all spaces */ * uses all spaces */
/* -troff font state information */ /* -troff font state information */
@ -182,9 +189,10 @@ main(int argc, char **argv)
extern int found_err; /* flag set in diag() on error */ extern int found_err; /* flag set in diag() on error */
int dec_ind; /* current indentation for declarations */ int dec_ind; /* current indentation for declarations */
int di_stack[20]; /* a stack of structure indentation levels */ int di_stack[20]; /* a stack of structure indentation
int flushed_nl; /* used when buffering up comments to remember * levels */
* that a newline was passed over */ int flushed_nl; /* used when buffering up comments to
* remember that a newline was passed over */
int force_nl; /* when true, code must be broken */ int force_nl; /* when true, code must be broken */
int hd_type; /* used to store type of stmt for if (...), int hd_type; /* used to store type of stmt for if (...),
* for (...), etc */ * for (...), etc */
@ -197,17 +205,17 @@ main(int argc, char **argv)
* without the matching : in a <c>?<s>:<s> * without the matching : in a <c>?<s>:<s>
* construct */ * construct */
char *t_ptr; /* used for copying tokens */ char *t_ptr; /* used for copying tokens */
int tabs_to_var; /* true if using tabs to indent to var name */ int tabs_to_var;/* true if using tabs to indent to var name */
int type_code; /* the type of token, returned by lexi */ int type_code; /* the type of token, returned by lexi */
int last_else = 0; /* true iff last keyword was an else */ int last_else = 0; /* true iff last keyword was an else */
#if defined(__linux__) #if defined(__linux__)
// //
#else #else
if (pledge("stdio rpath wpath cpath", NULL) == -1) if (pledge("stdio rpath wpath cpath", NULL) == -1)
err(1, "pledge"); err(1, "pledge");
#endif #endif
/*-----------------------------------------------*\ /*-----------------------------------------------*\
| INITIALIZATION | | INITIALIZATION |
@ -311,8 +319,7 @@ main(int argc, char **argv)
if (input == NULL) /* check for open error */ if (input == NULL) /* check for open error */
err(1, "%s", in_name); err(1, "%s", in_name);
continue; continue;
} } else if (output == 0) { /* we have the output file */
else if (output == 0) { /* we have the output file */
out_name = argv[i]; /* remember name of output file */ out_name = argv[i]; /* remember name of output file */
if (strcmp(in_name, out_name) == 0) /* attempt to overwrite if (strcmp(in_name, out_name) == 0) /* attempt to overwrite
* the file */ * the file */
@ -323,8 +330,7 @@ main(int argc, char **argv)
continue; continue;
} }
errx(1, "unknown parameter: %s", argv[i]); errx(1, "unknown parameter: %s", argv[i]);
} } else
else
set_option(argv[i]); set_option(argv[i]);
} /* end of for */ } /* end of for */
if (input == NULL) { if (input == NULL) {
@ -386,8 +392,7 @@ main(int argc, char **argv)
ps.ind_level = ps.i_l_follow = col / ps.ind_size; ps.ind_level = ps.i_l_follow = col / ps.ind_size;
} }
if (troff) { if (troff) {
char *p = in_name, char *p = in_name, *beg = in_name;
*beg = in_name;
while (*p) while (*p)
if (*p++ == '/') if (*p++ == '/')
@ -398,13 +403,14 @@ main(int argc, char **argv)
* START OF MAIN LOOP * START OF MAIN LOOP
*/ */
while (1) { /* this is the main loop. it will go until we while (1) { /* this is the main loop. it will go until
* reach eof */ * we reach eof */
int is_procname; int is_procname;
type_code = lexi(); /* lexi reads one token. The actual type_code = lexi(); /* lexi reads one token. The actual
* characters read are stored in "token". lexi * characters read are stored in "token".
* returns a code indicating the type of token */ * lexi returns a code indicating the type of
* token */
is_procname = ps.procname[0]; is_procname = ps.procname[0];
/* /*
@ -416,10 +422,10 @@ main(int argc, char **argv)
flushed_nl = false; flushed_nl = false;
while (ps.search_brace) { /* if we scanned an if(), while(), while (ps.search_brace) { /* if we scanned an if(), while(),
* etc., we might need to copy stuff * etc., we might need to copy stuff
* into a buffer we must loop, copying * into a buffer we must loop,
* stuff into save_com, until we find * copying stuff into save_com, until
* the start of the stmt which follows * we find the start of the stmt
* the if, or whatever */ * which follows the if, or whatever */
switch (type_code) { switch (type_code) {
case newline: case newline:
++line_no; ++line_no;
@ -430,8 +436,8 @@ main(int argc, char **argv)
case lbrace: /* this is a brace that starts the compound case lbrace: /* this is a brace that starts the compound
* stmt */ * stmt */
if (sc_end == 0) { /* ignore buffering if a comment wasnt if (sc_end == 0) { /* ignore buffering if a comment
* stored up */ * wasnt stored up */
ps.search_brace = false; ps.search_brace = false;
goto check_type; goto check_type;
} }
@ -448,8 +454,7 @@ main(int argc, char **argv)
* must set up the buffer */ * must set up the buffer */
save_com[0] = save_com[1] = ' '; save_com[0] = save_com[1] = ' ';
sc_end = &(save_com[2]); sc_end = &(save_com[2]);
} } else {
else {
*sc_end++ = '\n'; /* add newline between *sc_end++ = '\n'; /* add newline between
* comments */ * comments */
*sc_end++ = ' '; *sc_end++ = ' ';
@ -458,7 +463,8 @@ main(int argc, char **argv)
*sc_end++ = '/'; /* copy in start of comment */ *sc_end++ = '/'; /* copy in start of comment */
*sc_end++ = '*'; *sc_end++ = '*';
for (;;) { /* loop until we get to the end of the comment */ for (;;) { /* loop until we get to the end of the
* comment */
*sc_end = *buf_ptr++; *sc_end = *buf_ptr++;
if (buf_ptr >= buf_end) if (buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
@ -500,8 +506,9 @@ main(int argc, char **argv)
* read from the buffer */ * read from the buffer */
*sc_end++ = '\n'; *sc_end++ = '\n';
*sc_end++ = ' '; *sc_end++ = ' ';
if (verbose && !flushed_nl) /* print error msg if the line if (verbose && !flushed_nl) /* print error msg if the
* was not already broken */ * line was not already
* broken */
diag(0, "Line broken"); diag(0, "Line broken");
flushed_nl = false; flushed_nl = false;
} }
@ -522,8 +529,8 @@ main(int argc, char **argv)
sc_end = 0; sc_end = 0;
break; break;
} /* end of switch */ } /* end of switch */
if (type_code != 0) /* we must make this check, just in case there if (type_code != 0) /* we must make this check, just in case
* was an unexpected EOF */ * there was an unexpected EOF */
type_code = lexi(); /* read another token */ type_code = lexi(); /* read another token */
/* if (ps.search_brace) ps.procname[0] = 0; */ /* if (ps.search_brace) ps.procname[0] = 0; */
if ((is_procname = ps.procname[0]) && flushed_nl if ((is_procname = ps.procname[0]) && flushed_nl
@ -565,9 +572,9 @@ check_type:
ps.want_blank = false; /* dont insert blank at line start */ ps.want_blank = false; /* dont insert blank at line start */
force_nl = false; force_nl = false;
} }
ps.in_stmt = true; /* turn on flag which causes an extra level of ps.in_stmt = true; /* turn on flag which causes an extra level
* indentation. this is turned off by a ; or * of indentation. this is turned off by a ;
* '}' */ * or '}' */
if (s_com != e_com) { /* the turkey has embedded a comment if (s_com != e_com) { /* the turkey has embedded a comment
* in a line. fix it */ * in a line. fix it */
*e_code++ = ' '; *e_code++ = ' ';
@ -580,8 +587,8 @@ check_type:
ps.want_blank = false; ps.want_blank = false;
e_com = s_com; e_com = s_com;
} }
} } else if (type_code != comment) /* preserve force_nl thru a
else if (type_code != comment) /* preserve force_nl thru a comment */ * comment */
force_nl = false; /* cancel forced newline after newline, form force_nl = false; /* cancel forced newline after newline, form
* feed, etc */ * feed, etc */
@ -621,8 +628,7 @@ check_type:
"\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token); "\n.Du %dp+\200p \"%s\"\n", dec_ind * 7, token);
e_code += strlen(e_code); e_code += strlen(e_code);
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
} } else {
else {
while ((e_code - s_code) < dec_ind) { while ((e_code - s_code) < dec_ind) {
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
*e_code++ = ' '; *e_code++ = ' ';
@ -643,8 +649,8 @@ check_type:
* "int a(x) {..." * "int a(x) {..."
*/ */
parse(semicolon); /* I said this was a kluge... */ parse(semicolon); /* I said this was a kluge... */
ps.in_or_st = false; /* turn off flag for structure decl or ps.in_or_st = false; /* turn off flag for structure decl
* initialization */ * or initialization */
} }
if (ps.sizeof_keyword) if (ps.sizeof_keyword)
ps.sizeof_mask |= 1 << ps.p_l_follow; ps.sizeof_mask |= 1 << ps.p_l_follow;
@ -694,8 +700,7 @@ check_type:
ps.dumped_decl_indent = 1; ps.dumped_decl_indent = 1;
e_code += strlen(e_code); e_code += strlen(e_code);
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
} } else {
else {
char *res = token; char *res = token;
if (ps.in_decl && !ps.block_init) { /* if this is a unary op if (ps.in_decl && !ps.block_init) { /* if this is a unary op
@ -790,7 +795,8 @@ check_type:
ps.in_stmt = false; /* seeing a label does not imply we are in a ps.in_stmt = false; /* seeing a label does not imply we are in a
* stmt */ * stmt */
for (t_ptr = s_code; *t_ptr; ++t_ptr) for (t_ptr = s_code; *t_ptr; ++t_ptr)
*e_lab++ = *t_ptr; /* turn everything so far into a label */ *e_lab++ = *t_ptr; /* turn everything so far into a
* label */
e_code = s_code; e_code = s_code;
*e_lab++ = ':'; *e_lab++ = ':';
*e_lab++ = ' '; *e_lab++ = ' ';
@ -824,9 +830,10 @@ check_type:
*e_code++ = ' '; *e_code++ = ' ';
} }
ps.in_decl = (ps.dec_nest > 0); /* if we were in a first level ps.in_decl = (ps.dec_nest > 0); /* if we were in a first
* structure declaration, we * level structure
* arent any more */ * declaration, we arent any
* more */
if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0) { if ((!sp_sw || hd_type != forstmt) && ps.p_l_follow > 0) {
@ -868,8 +875,7 @@ check_type:
if (!btype_2) { if (!btype_2) {
dump_line(); dump_line();
ps.want_blank = false; ps.want_blank = false;
} } else if (ps.in_parameter_declaration && !ps.in_or_st) {
else if (ps.in_parameter_declaration && !ps.in_or_st) {
ps.i_l_follow = 0; ps.i_l_follow = 0;
dump_line(); dump_line();
ps.want_blank = false; ps.want_blank = false;
@ -895,11 +901,12 @@ check_type:
* declaration or an init */ * declaration or an init */
di_stack[ps.dec_nest++] = dec_ind; di_stack[ps.dec_nest++] = dec_ind;
/* ? dec_ind = 0; */ /* ? dec_ind = 0; */
} } else {
else {
ps.decl_on_line = false; ps.decl_on_line = false;
/* we can't be in the middle of a declaration, so don't do /*
* special indentation of comments */ * we can't be in the middle of a declaration, so don't do
* special indentation of comments
*/
if (blanklines_after_declarations_at_proctop if (blanklines_after_declarations_at_proctop
&& ps.in_parameter_declaration) && ps.in_parameter_declaration)
postfix_blankline_requested = 1; postfix_blankline_requested = 1;
@ -977,18 +984,19 @@ check_type:
dump_line();/* make sure this starts a line */ dump_line();/* make sure this starts a line */
ps.want_blank = false; ps.want_blank = false;
} }
force_nl = true;/* also, following stuff must go onto new line */ force_nl = true;/* also, following stuff must go onto new
* line */
last_else = 1; last_else = 1;
parse(elselit); parse(elselit);
} } else {
else {
if (e_code != s_code) { /* make sure this starts a line */ if (e_code != s_code) { /* make sure this starts a line */
if (verbose) if (verbose)
diag(0, "Line broken"); diag(0, "Line broken");
dump_line(); dump_line();
ps.want_blank = false; ps.want_blank = false;
} }
force_nl = true;/* also, following stuff must go onto new line */ force_nl = true;/* also, following stuff must go onto new
* line */
last_else = 0; last_else = 0;
parse(dolit); parse(dolit);
} }
@ -1008,8 +1016,8 @@ check_type:
ps.ind_level = ps.i_l_follow = 1; ps.ind_level = ps.i_l_follow = 1;
ps.ind_stmt = 0; ps.ind_stmt = 0;
} }
ps.in_or_st = true; /* this might be a structure or initialization ps.in_or_st = true; /* this might be a structure or
* declaration */ * initialization declaration */
ps.in_decl = ps.decl_on_line = true; ps.in_decl = ps.decl_on_line = true;
if ( /* !ps.in_or_st && */ ps.dec_nest <= 0) if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
ps.just_saw_decl = 2; ps.just_saw_decl = 2;
@ -1058,7 +1066,6 @@ check_type:
pos += (ps.ind_level * ps.ind_size) % 8; pos += (ps.ind_level * ps.ind_size) % 8;
cur_dec_ind += (ps.ind_level * ps.ind_size) % 8; cur_dec_ind += (ps.ind_level * ps.ind_size) % 8;
} }
if (tabs_to_var) { if (tabs_to_var) {
while ((pos & ~7) + 8 <= cur_dec_ind) { while ((pos & ~7) + 8 <= cur_dec_ind) {
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
@ -1076,15 +1083,13 @@ check_type:
ps.want_blank = false; ps.want_blank = false;
} }
} }
} } else {
else {
if (dec_ind && s_code != e_code) if (dec_ind && s_code != e_code)
dump_line(); dump_line();
dec_ind = 0; dec_ind = 0;
ps.want_blank = false; ps.want_blank = false;
} }
} } else if (sp_sw && ps.p_l_follow == 0) {
else if (sp_sw && ps.p_l_follow == 0) {
sp_sw = false; sp_sw = false;
force_nl = true; force_nl = true;
ps.last_u_d = true; ps.last_u_d = true;
@ -1099,12 +1104,11 @@ check_type:
for (t_ptr = token; *t_ptr; ++t_ptr) { for (t_ptr = token; *t_ptr; ++t_ptr) {
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
*e_code++ = keywordf.allcaps && *e_code++ = keywordf.allcaps &&
islower((unsigned char)*t_ptr) ? islower((unsigned char) *t_ptr) ?
toupper((unsigned char)*t_ptr) : *t_ptr; toupper((unsigned char) *t_ptr) : *t_ptr;
} }
e_code = chfont(&keywordf, &bodyf, e_code); e_code = chfont(&keywordf, &bodyf, e_code);
} } else
else
for (t_ptr = token; *t_ptr; ++t_ptr) { for (t_ptr = token; *t_ptr; ++t_ptr) {
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
*e_code++ = *t_ptr; *e_code++ = *t_ptr;
@ -1120,8 +1124,8 @@ check_type:
case comma: case comma:
ps.want_blank = (s_code != e_code); /* only put blank after comma ps.want_blank = (s_code != e_code); /* only put blank after comma
* if comma does not start the * if comma does not start
* line */ * the line */
if (ps.in_decl && is_procname == 0 && !ps.block_init) if (ps.in_decl && is_procname == 0 && !ps.block_init)
while ((e_code - s_code) < (dec_ind - 1)) { while ((e_code - s_code) < (dec_ind - 1)) {
CHECK_SIZE_CODE; CHECK_SIZE_CODE;
@ -1237,11 +1241,9 @@ check_type:
if (ifdef_level < sizeof state_stack / sizeof state_stack[0]) { if (ifdef_level < sizeof state_stack / sizeof state_stack[0]) {
match_state[ifdef_level].tos = -1; match_state[ifdef_level].tos = -1;
state_stack[ifdef_level++] = ps; state_stack[ifdef_level++] = ps;
} } else
else
diag(1, "#if stack overflow"); diag(1, "#if stack overflow");
} } else if (strncmp(s_lab, "#else", 5) == 0)
else if (strncmp(s_lab, "#else", 5) == 0)
if (ifdef_level <= 0) if (ifdef_level <= 0)
diag(1, "Unmatched #else"); diag(1, "Unmatched #else");
else { else {
@ -1270,7 +1272,8 @@ check_type:
} }
} }
break; /* subsequent processing of the newline break; /* subsequent processing of the newline
* character will cause the line to be printed */ * character will cause the line to be
* printed */
case comment: /* we have gotten a comment this is a biggie */ case comment: /* we have gotten a comment this is a biggie */
if (flushed_nl) { /* we should force a broken line here */ if (flushed_nl) { /* we should force a broken line here */
@ -1297,8 +1300,7 @@ check_type:
void void
bakcopy(void) bakcopy(void)
{ {
int n, int n, bakchn;
bakchn;
char buff[8 * 1024]; char buff[8 * 1024];
char *p; char *p;
@ -1309,11 +1311,12 @@ bakcopy(void)
if (*p == '/') if (*p == '/')
p++; p++;
if (snprintf(bakfile, PATH_MAX, "%s.BAK", p) >= PATH_MAX) if (snprintf(bakfile, PATH_MAX, "%s.BAK", p) >= PATH_MAX)
#if defined(__linux__) #if defined(__linux__)
printf("%s.BAK", p); // FIXIT printf("%s.BAK", p);
#else //FIXIT
#else
errc(1, ENAMETOOLONG, "%s.BAK", p); errc(1, ENAMETOOLONG, "%s.BAK", p);
#endif #endif
/* copy in_name to backup file */ /* copy in_name to backup file */
bakchn = open(bakfile, O_CREAT | O_TRUNC | O_WRONLY, 0600); bakchn = open(bakfile, O_CREAT | O_TRUNC | O_WRONLY, 0600);
@ -1336,10 +1339,11 @@ bakcopy(void)
if (output == NULL) { if (output == NULL) {
int saved_errno = errno; int saved_errno = errno;
unlink(bakfile); unlink(bakfile);
#if defined(__linux__) #if defined(__linux__)
printf("%s", in_name); // FIXIT printf("%s", in_name);
#else //FIXIT
#else
errc(1, saved_errno, "%s", in_name); errc(1, saved_errno, "%s", in_name);
#endif #endif
} }
} }

1
indent.txt Normal file
View File

@ -0,0 +1 @@
:indent -nut -i4 -br

View File

@ -118,13 +118,14 @@ extern char *e_token;
extern char *l_token; extern char *l_token;
extern char *in_buffer; /* input buffer */ extern char *in_buffer; /* input buffer */
extern char *in_buffer_limit; /* the end of the input buffer */ extern char *in_buffer_limit;/* the end of the input buffer */
extern char *buf_ptr; /* ptr to next character to be taken from extern char *buf_ptr; /* ptr to next character to be taken from
* in_buffer */ * in_buffer */
extern char *buf_end; /* ptr to first after last char in in_buffer */ extern char *buf_end; /* ptr to first after last char in in_buffer */
extern char save_com[sc_size]; /* input text is saved here when looking for extern char save_com[sc_size]; /* input text is saved here when
* the brace after an if, while, etc */ * looking for the brace after an if,
* while, etc */
extern char *sc_end; /* pointer into save_com buffer */ extern char *sc_end; /* pointer into save_com buffer */
extern char *bp_save; /* saved value of buf_ptr when taking input extern char *bp_save; /* saved value of buf_ptr when taking input
@ -151,11 +152,12 @@ extern int code_lines; /* count of lines with code */
extern int had_eof; /* set to true when input is exhausted */ extern int had_eof; /* set to true when input is exhausted */
extern int line_no; /* the current line number. */ extern int line_no; /* the current line number. */
extern int max_col; /* the maximum allowable line length */ extern int max_col; /* the maximum allowable line length */
extern int verbose; /* when true, non-essential error messages are extern int verbose; /* when true, non-essential error messages
* printed */ * are printed */
extern int cuddle_else; /* true if else should cuddle up to '}' */ extern int cuddle_else; /* true if else should cuddle up to '}' */
extern int star_comment_cont; /* true iff comment continuation lines should extern int star_comment_cont; /* true iff comment continuation
* have stars at the beginning of each line. */ * lines should have stars at the
* beginning of each line. */
extern int comment_delimiter_on_blankline; extern int comment_delimiter_on_blankline;
extern int troff; /* true iff were generating troff input */ extern int troff; /* true iff were generating troff input */
extern int procnames_start_line; /* if true, the names of procedures extern int procnames_start_line; /* if true, the names of procedures
@ -163,19 +165,22 @@ extern int procnames_start_line; /* if true, the names of procedures
* 1 (ie. a newline is placed between * 1 (ie. a newline is placed between
* the type of the procedure and its * the type of the procedure and its
* name) */ * name) */
extern int proc_calls_space; /* If true, procedure calls look like: extern int proc_calls_space; /* If true, procedure calls look
* foo(bar) rather than foo (bar) */ * like: foo(bar) rather than foo
extern int format_col1_comments; /* If comments which start in column 1 * (bar) */
* are to be magically reformatted extern int format_col1_comments; /* If comments which start in column
* 1 are to be magically reformatted
* (just like comments that begin in * (just like comments that begin in
* later columns) */ * later columns) */
extern int inhibit_formatting; /* true if INDENT OFF is in effect */ extern int inhibit_formatting; /* true if INDENT OFF is in effect */
extern int suppress_blanklines;/* set iff following blanklines should be extern int suppress_blanklines; /* set iff following blanklines
* suppressed */ * should be suppressed */
extern int continuation_indent;/* set to the indentation between the edge of extern int continuation_indent; /* set to the indentation between the
* code and continuation lines */ * edge of code and continuation
extern int lineup_to_parens; /* if true, continued code within parens will * lines */
* be lined up to the open paren */ extern int lineup_to_parens; /* if true, continued code within
* parens will be lined up to the
* open paren */
extern int Bill_Shannon; /* true iff a blank should always be inserted extern int Bill_Shannon; /* true iff a blank should always be inserted
* after sizeof */ * after sizeof */
extern int blanklines_after_declarations_at_proctop; /* This is vaguely extern int blanklines_after_declarations_at_proctop; /* This is vaguely
@ -192,14 +197,16 @@ extern int blanklines_after_declarations_at_proctop; /* This is vaguely
* if there are no * if there are no
* declarations */ * declarations */
extern int block_comment_max_col; extern int block_comment_max_col;
extern int extra_expression_indent; /* True if continuation lines from the extern int extra_expression_indent; /* True if continuation lines
* expression part of "if(e)", * from the expression part
* "while(e)", "for(e;e;e)" should be * of "if(e)", "while(e)",
* indented an extra tab stop so that * "for(e;e;e)" should be
* they don't conflict with the code * indented an extra tab stop
* so that they don't
* conflict with the code
* that follows */ * that follows */
extern int use_tabs; /* set true to use tabs for spacing, extern int use_tabs; /* set true to use tabs for spacing, false
* false uses all spaces */ * uses all spaces */
/* -troff font state information */ /* -troff font state information */
@ -224,16 +231,17 @@ extern struct parser_state {
int last_token; int last_token;
struct fstate cfont; /* Current font */ struct fstate cfont; /* Current font */
int p_stack[STACKSIZE]; /* this is the parsers stack */ int p_stack[STACKSIZE]; /* this is the parsers stack */
int il[STACKSIZE]; /* this stack stores indentation levels */ int il[STACKSIZE]; /* this stack stores indentation
float cstk[STACKSIZE];/* used to store case stmt indentation levels */ * levels */
float cstk[STACKSIZE]; /* used to store case stmt
* indentation levels */
int box_com; /* set to true when we are in a "boxed" int box_com; /* set to true when we are in a "boxed"
* comment. In that case, the first non-blank * comment. In that case, the first non-blank
* char should be lined up with the / in rem */ * char should be lined up with the / in rem */
int comment_delta, int comment_delta, n_comment_delta;
n_comment_delta;
int cast_mask; /* indicates which close parens close off int cast_mask; /* indicates which close parens close off
* casts */ * casts */
int sizeof_mask; /* indicates which close parens close off int sizeof_mask;/* indicates which close parens close off
* sizeof''s */ * sizeof''s */
int block_init; /* true iff inside a block initialization */ int block_init; /* true iff inside a block initialization */
int block_init_level; /* The level of brace nesting in an int block_init_level; /* The level of brace nesting in an
@ -243,8 +251,8 @@ extern struct parser_state {
int in_or_st; /* Will be true iff there has been a int in_or_st; /* Will be true iff there has been a
* declarator (e.g. int or char) and no left * declarator (e.g. int or char) and no left
* paren since the last semicolon. When true, * paren since the last semicolon. When true,
* a '{' is starting a structure definition or * a '{' is starting a structure definition
* an initialization list */ * or an initialization list */
int bl_line; /* set to 1 by dump_line if the line is blank */ int bl_line; /* set to 1 by dump_line if the line is blank */
int col_1; /* set to true if the last token started in int col_1; /* set to true if the last token started in
* column 1 */ * column 1 */
@ -254,11 +262,12 @@ extern struct parser_state {
* of code should start */ * of code should start */
int com_lines; /* the number of lines with comments, set by int com_lines; /* the number of lines with comments, set by
* dump_line */ * dump_line */
int dec_nest; /* current nesting level for structure or init */ int dec_nest; /* current nesting level for structure or
* init */
int decl_com_ind; /* the column in which comments after int decl_com_ind; /* the column in which comments after
* declarations should be put */ * declarations should be put */
int decl_on_line; /* set to true if this line of code has part int decl_on_line; /* set to true if this line of code
* of a declaration on it */ * has part of a declaration on it */
int i_l_follow; /* the level to which ind_level should be set int i_l_follow; /* the level to which ind_level should be set
* after the current line is printed */ * after the current line is printed */
int in_decl; /* set to true when we are in a declaration int in_decl; /* set to true when we are in a declaration
@ -272,7 +281,7 @@ extern struct parser_state {
* middle of a stmt */ * middle of a stmt */
int last_u_d; /* set to true after scanning a token which int last_u_d; /* set to true after scanning a token which
* forces a following operator to be unary */ * forces a following operator to be unary */
int leave_comma; /* if true, never break declarations after int leave_comma;/* if true, never break declarations after
* commas */ * commas */
int ljust_decl; /* true if declarations should be left int ljust_decl; /* true if declarations should be left
* justified */ * justified */
@ -282,32 +291,33 @@ extern struct parser_state {
* dump_line */ * dump_line */
int p_l_follow; /* used to remember how to indent following int p_l_follow; /* used to remember how to indent following
* statement */ * statement */
int paren_level; /* parenthesization level. used to indent int paren_level;/* parenthesization level. used to indent
* within stmts */ * within stmts */
short paren_indents[20]; /* column positions of each paren */ short paren_indents[20]; /* column positions of each paren */
int pcase; /* set to 1 if the current line label is a int pcase; /* set to 1 if the current line label is a
* case. It is printed differently from a * case. It is printed differently from a
* regular label */ * regular label */
int search_brace; /* set to true by parse when it is necessary int search_brace; /* set to true by parse when it is
* to buffer up all info up to the start of a * necessary to buffer up all info up
* stmt after an if, while, etc */ * to the start of a stmt after an
* if, while, etc */
int unindent_displace; /* comments not to the right of code int unindent_displace; /* comments not to the right of code
* will be placed this many * will be placed this many
* indentation levels to the left of * indentation levels to the left of
* code */ * code */
int use_ff; /* set to one if the current line should be int use_ff; /* set to one if the current line should be
* terminated with a form feed */ * terminated with a form feed */
int want_blank; /* set to true when the following token should int want_blank; /* set to true when the following token
* be prefixed by a blank. (Said prefixing is * should be prefixed by a blank. (Said
* ignored in some cases.) */ * prefixing is ignored in some cases.) */
int else_if; /* True iff else if pairs should be handled int else_if; /* True iff else if pairs should be handled
* specially */ * specially */
int decl_indent; /* column to indent declared identifiers to */ int decl_indent;/* column to indent declared identifiers to */
int its_a_keyword; int its_a_keyword;
int sizeof_keyword; int sizeof_keyword;
int dumped_decl_indent; int dumped_decl_indent;
float case_indent; /* The distance to indent case labels from the float case_indent;/* The distance to indent case labels from
* switch statement */ * the switch statement */
int in_parameter_declaration; int in_parameter_declaration;
int indent_parameters; int indent_parameters;
int tos; /* pointer to top of stack */ int tos; /* pointer to top of stack */
@ -323,7 +333,7 @@ extern struct parser_state match_state[5];
int compute_code_target(void); int compute_code_target(void);
int compute_label_target(void); int compute_label_target(void);
int count_spaces(int, char *); int count_spaces(int, char *);
void diag(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void diag(int, const char *,...) __attribute__((__format__(printf, 2, 3)));
void dump_line(void); void dump_line(void);
int eqin(char *, char *); int eqin(char *, char *);
void fill_buffer(void); void fill_buffer(void);

57
io.c
View File

@ -71,8 +71,7 @@ dump_line(void)
ps.bl_line = true; ps.bl_line = true;
n_real_blanklines++; n_real_blanklines++;
} }
} } else if (!inhibit_formatting) {
else if (!inhibit_formatting) {
suppress_blanklines = 0; suppress_blanklines = 0;
ps.bl_line = false; ps.bl_line = false;
if (prefix_blankline_requested && not_first_line) { if (prefix_blankline_requested && not_first_line) {
@ -111,17 +110,16 @@ dump_line(void)
e_lab--; e_lab--;
do do
putc(*s++, output); putc(*s++, output);
while (s < e_lab && 'a' <= *s && *s<='z'); while (s < e_lab && 'a' <= *s && *s <= 'z');
while ((*s == ' ' || *s == '\t') && s < e_lab) while ((*s == ' ' || *s == '\t') && s < e_lab)
s++; s++;
if (s < e_lab) if (s < e_lab)
fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */", fprintf(output, s[0] == '/' && s[1] == '*' ? "\t%.*s" : "\t/* %.*s */",
(int)(e_lab - s), s); (int) (e_lab - s), s);
} } else
else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab); fprintf(output, "%.*s", (int) (e_lab - s_lab), s_lab);
cur_col = count_spaces(cur_col, s_lab); cur_col = count_spaces(cur_col, s_lab);
} } else
else
cur_col = 1; /* there is no label section */ cur_col = 1; /* there is no label section */
ps.pcase = false; ps.pcase = false;
@ -226,7 +224,7 @@ dump_line(void)
cur_col = 1; cur_col = 1;
++ps.out_lines; ++ps.out_lines;
} }
while (e_com > com_st && isspace((unsigned char)e_com[-1])) while (e_com > com_st && isspace((unsigned char) e_com[-1]))
e_com--; e_com--;
cur_col = pad_output(cur_col, target); cur_col = pad_output(cur_col, target);
if (!ps.box_com) { if (!ps.box_com) {
@ -252,19 +250,18 @@ inhibit_newline:
if (ps.just_saw_decl == 1 && blanklines_after_declarations) { if (ps.just_saw_decl == 1 && blanklines_after_declarations) {
prefix_blankline_requested = 1; prefix_blankline_requested = 1;
ps.just_saw_decl = 0; ps.just_saw_decl = 0;
} } else
else
prefix_blankline_requested = postfix_blankline_requested; prefix_blankline_requested = postfix_blankline_requested;
postfix_blankline_requested = 0; postfix_blankline_requested = 0;
} }
ps.decl_on_line = ps.in_decl; /* if we are in the middle of a ps.decl_on_line = ps.in_decl; /* if we are in the middle of a
* declaration, remember that fact for * declaration, remember that fact
* proper comment indentation */ * for proper comment indentation */
ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be
* indented if we have not * indented if we have not
* completed this stmt and if * completed this stmt and if
* we are not in the middle of * we are not in the middle
* a declaration */ * of a declaration */
ps.use_ff = false; ps.use_ff = false;
ps.dumped_decl_indent = 0; ps.dumped_decl_indent = 0;
*(e_lab = s_lab) = '\0'; /* reset buffers */ *(e_lab = s_lab) = '\0'; /* reset buffers */
@ -295,8 +292,7 @@ compute_code_target(void)
t -= w + 1; t -= w + 1;
if (t > target_col) if (t > target_col)
target_col = t; target_col = t;
} } else
else
target_col = t; target_col = t;
} }
else if (ps.ind_stmt) else if (ps.ind_stmt)
@ -341,8 +337,8 @@ fill_buffer(void)
buf_end = be_save; buf_end = be_save;
bp_save = be_save = 0; bp_save = be_save = 0;
if (buf_ptr < buf_end) if (buf_ptr < buf_end)
return; /* only return if there is really something in return; /* only return if there is really something
* this buffer */ * in this buffer */
} }
for (p = in_buffer;;) { for (p = in_buffer;;) {
if (p >= in_buffer_limit) { if (p >= in_buffer_limit) {
@ -525,7 +521,7 @@ count_spaces(int current, char *buffer)
int found_err; int found_err;
void void
diag(int level, const char *msg, ...) diag(int level, const char *msg,...)
{ {
va_list ap; va_list ap;
@ -536,8 +532,7 @@ diag(int level, const char *msg, ...)
fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no); fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
vfprintf(stdout, msg, ap); vfprintf(stdout, msg, ap);
fprintf(stdout, " */\n"); fprintf(stdout, " */\n");
} } else {
else {
fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no); fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
vfprintf(stderr, msg, ap); vfprintf(stderr, msg, ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -546,14 +541,14 @@ diag(int level, const char *msg, ...)
} }
void void
writefdef(struct fstate *f, int nm) writefdef(struct fstate * f, int nm)
{ {
fprintf(output, ".ds f%c %s\n.nr s%c %d\n", fprintf(output, ".ds f%c %s\n.nr s%c %d\n",
nm, f->font, nm, f->size); nm, f->font, nm, f->size);
} }
char * char *
chfont(struct fstate *of, struct fstate *nf, char *s) chfont(struct fstate * of, struct fstate * nf, char *s)
{ {
if (of->font[0] != nf->font[0] if (of->font[0] != nf->font[0]
|| of->font[1] != nf->font[1]) { || of->font[1] != nf->font[1]) {
@ -563,8 +558,7 @@ chfont(struct fstate *of, struct fstate *nf, char *s)
*s++ = '('; *s++ = '(';
*s++ = nf->font[0]; *s++ = nf->font[0];
*s++ = nf->font[1]; *s++ = nf->font[1];
} } else
else
*s++ = nf->font[0]; *s++ = nf->font[0];
} }
if (nf->size != of->size) { if (nf->size != of->size) {
@ -573,8 +567,7 @@ chfont(struct fstate *of, struct fstate *nf, char *s)
if (nf->size < of->size) { if (nf->size < of->size) {
*s++ = '-'; *s++ = '-';
*s++ = '0' + of->size - nf->size; *s++ = '0' + of->size - nf->size;
} } else {
else {
*s++ = '+'; *s++ = '+';
*s++ = '0' + nf->size - of->size; *s++ = '0' + nf->size - of->size;
} }
@ -583,15 +576,15 @@ chfont(struct fstate *of, struct fstate *nf, char *s)
} }
void void
parsefont(struct fstate *f, char *s0) parsefont(struct fstate * f, char *s0)
{ {
char *s = s0; char *s = s0;
int sizedelta = 0; int sizedelta = 0;
bzero(f, sizeof *f); bzero(f, sizeof *f);
while (*s) { while (*s) {
if (isdigit((unsigned char)*s)) if (isdigit((unsigned char) *s))
f->size = f->size * 10 + *s - '0'; f->size = f->size * 10 + *s - '0';
else if (isupper((unsigned char)*s)) else if (isupper((unsigned char) *s))
if (f->font[0]) if (f->font[0])
f->font[1] = *s; f->font[1] = *s;
else else

125
lexi.c
View File

@ -55,34 +55,34 @@ struct templ {
}; };
struct templ specialsinit[] = { struct templ specialsinit[] = {
{ "switch", 1 }, {"switch", 1},
{ "case", 2 }, {"case", 2},
{ "break", 0 }, {"break", 0},
{ "struct", 3 }, {"struct", 3},
{ "union", 3 }, {"union", 3},
{ "enum", 3 }, {"enum", 3},
{ "default", 2 }, {"default", 2},
{ "int", 4 }, {"int", 4},
{ "char", 4 }, {"char", 4},
{ "float", 4 }, {"float", 4},
{ "double", 4 }, {"double", 4},
{ "long", 4 }, {"long", 4},
{ "short", 4 }, {"short", 4},
{ "typedef", 4 }, {"typedef", 4},
{ "unsigned", 4 }, {"unsigned", 4},
{ "register", 4 }, {"register", 4},
{ "static", 4 }, {"static", 4},
{ "global", 4 }, {"global", 4},
{ "extern", 4 }, {"extern", 4},
{ "void", 4 }, {"void", 4},
{ "goto", 0 }, {"goto", 0},
{ "return", 0 }, {"return", 0},
{ "if", 5 }, {"if", 5},
{ "while", 5 }, {"while", 5},
{ "for", 5 }, {"for", 5},
{ "else", 6 }, {"else", 6},
{ "do", 6 }, {"do", 6},
{ "sizeof", 7 }, {"sizeof", 7},
}; };
struct templ *specials = specialsinit; struct templ *specials = specialsinit;
@ -117,7 +117,7 @@ char chartype[128] =
int int
lexi(void) lexi(void)
{ {
int unary_delim; /* this is set to 1 if the current token int unary_delim;/* this is set to 1 if the current token
* forces a following operator to be unary */ * forces a following operator to be unary */
static int last_code; /* the last token type returned */ static int last_code; /* the last token type returned */
static int l_struct; /* set to 1 if the last token was 'struct' */ static int l_struct; /* set to 1 if the last token was 'struct' */
@ -132,25 +132,23 @@ lexi(void)
ps.last_nl = false; ps.last_nl = false;
while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */
ps.col_1 = false; /* leading blanks imply token is not in column ps.col_1 = false; /* leading blanks imply token is not in
* 1 */ * column 1 */
if (++buf_ptr >= buf_end) if (++buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
} }
/* Scan an alphanumeric token */ /* Scan an alphanumeric token */
if (chartype[(int)*buf_ptr] == alphanum || if (chartype[(int) *buf_ptr] == alphanum ||
(buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { (buf_ptr[0] == '.' && isdigit((unsigned char) buf_ptr[1]))) {
/* /*
* we have a character or number * we have a character or number
*/ */
char *j; /* used for searching thru list of char *j; /* used for searching thru list of reserved
* reserved words */ * words */
if (isdigit((unsigned char)*buf_ptr) || if (isdigit((unsigned char) *buf_ptr) ||
(buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) { (buf_ptr[0] == '.' && isdigit((unsigned char) buf_ptr[1]))) {
int seendot = 0, int seendot = 0, seenexp = 0, seensfx = 0;
seenexp = 0,
seensfx = 0;
if (*buf_ptr == '0' && if (*buf_ptr == '0' &&
(buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) { (buf_ptr[1] == 'x' || buf_ptr[1] == 'X')) {
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
@ -159,8 +157,7 @@ lexi(void)
CHECK_SIZE_TOKEN; CHECK_SIZE_TOKEN;
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
} }
} } else
else
while (1) { while (1) {
if (*buf_ptr == '.') { if (*buf_ptr == '.') {
if (seendot) if (seendot)
@ -170,7 +167,7 @@ lexi(void)
} }
CHECK_SIZE_TOKEN; CHECK_SIZE_TOKEN;
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
if (!isdigit((unsigned char)*buf_ptr) && *buf_ptr != '.') { if (!isdigit((unsigned char) *buf_ptr) && *buf_ptr != '.') {
if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp)
break; break;
else { else {
@ -208,9 +205,8 @@ lexi(void)
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
seensfx |= 1; seensfx |= 1;
} }
} } else
else while (chartype[(int) *buf_ptr] == alphanum) { /* copy it over */
while (chartype[(int)*buf_ptr] == alphanum) { /* copy it over */
CHECK_SIZE_TOKEN; CHECK_SIZE_TOKEN;
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
if (buf_ptr >= buf_end) if (buf_ptr >= buf_end)
@ -223,8 +219,8 @@ lexi(void)
} }
ps.its_a_keyword = false; ps.its_a_keyword = false;
ps.sizeof_keyword = false; ps.sizeof_keyword = false;
if (l_struct) { /* if last token was 'struct', then this token if (l_struct) { /* if last token was 'struct', then this
* should be treated as a declaration */ * token should be treated as a declaration */
l_struct = false; l_struct = false;
last_code = ident; last_code = ident;
ps.last_u_d = true; ps.last_u_d = true;
@ -242,9 +238,9 @@ lexi(void)
j = specials[i].rwd; j = specials[i].rwd;
if (*j++ != *p++ || *j++ != *p++) if (*j++ != *p++ || *j++ != *p++)
continue; /* This test depends on the fact that continue; /* This test depends on the fact that
* identifiers are always at least 1 character * identifiers are always at least 1
* long (ie. the first two bytes of the * character long (ie. the first two bytes of
* identifier are always meaningful) */ * the identifier are always meaningful) */
if (p[-1] == 0) if (p[-1] == 0)
break; /* If its a one-character identifier */ break; /* If its a one-character identifier */
while (*p++ == *j) while (*p++ == *j)
@ -298,7 +294,7 @@ lexi(void)
if (*tp++ == ')' && (*tp == ';' || *tp == ',')) if (*tp++ == ')' && (*tp == ';' || *tp == ','))
goto not_proc; goto not_proc;
strncpy(ps.procname, token, sizeof ps.procname); strncpy(ps.procname, token, sizeof ps.procname);
// strlcpy(ps.procname, token, sizeof ps.procname); //strlcpy(ps.procname, token, sizeof ps.procname);
ps.in_parameter_declaration = 1; ps.in_parameter_declaration = 1;
rparen_count = 1; rparen_count = 1;
not_proc:; not_proc:;
@ -309,7 +305,7 @@ lexi(void)
* typedefd * typedefd
*/ */
if (((*buf_ptr == '*' && buf_ptr[1] != '=') || if (((*buf_ptr == '*' && buf_ptr[1] != '=') ||
isalpha((unsigned char)*buf_ptr) || *buf_ptr == '_') isalpha((unsigned char) *buf_ptr) || *buf_ptr == '_')
&& !ps.p_l_follow && !ps.p_l_follow
&& !ps.block_init && !ps.block_init
&& (ps.last_token == rparen || ps.last_token == semicolon || && (ps.last_token == rparen || ps.last_token == semicolon ||
@ -326,9 +322,7 @@ lexi(void)
last_code = ident; last_code = ident;
return (ident); /* the ident is not in the list */ return (ident); /* the ident is not in the list */
} /* end of procesing for alpanum character */ } /* end of procesing for alpanum character */
/* Scan a non-alphanumeric token */ /* Scan a non-alphanumeric token */
*e_token++ = *buf_ptr; /* if it is only a one-character token, it is *e_token++ = *buf_ptr; /* if it is only a one-character token, it is
* moved here */ * moved here */
*e_token = '\0'; *e_token = '\0';
@ -362,9 +356,10 @@ lexi(void)
printf("%d: Unterminated literal\n", line_no); printf("%d: Unterminated literal\n", line_no);
goto stop_lit; goto stop_lit;
} }
CHECK_SIZE_TOKEN; /* Only have to do this once in this loop, CHECK_SIZE_TOKEN; /* Only have to do this once in this
* since CHECK_SIZE guarantees that there * loop, since CHECK_SIZE guarantees
* are at least 5 entries left */ * that there are at least 5 entries
* left */
*e_token = *buf_ptr++; *e_token = *buf_ptr++;
if (buf_ptr >= buf_end) if (buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
@ -381,8 +376,7 @@ lexi(void)
* copied two chars */ * copied two chars */
if (buf_ptr >= buf_end) if (buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
} } else
else
break; /* we copied one character */ break; /* we copied one character */
} /* end of while (1) */ } /* end of while (1) */
} while (*e_token++ != qchar); } while (*e_token++ != qchar);
@ -473,8 +467,7 @@ stop_lit:
/* check for following ++ or -- */ /* check for following ++ or -- */
unary_delim = false; unary_delim = false;
} }
} } else if (*buf_ptr == '=')
else if (*buf_ptr == '=')
/* check for operator += */ /* check for operator += */
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
else if (*buf_ptr == '>') { else if (*buf_ptr == '>') {
@ -493,7 +486,8 @@ stop_lit:
if (ps.in_or_st) if (ps.in_or_st)
ps.block_init = 1; ps.block_init = 1;
#ifdef undef #ifdef undef
if (chartype[*buf_ptr] == opchar) { /* we have two char assignment */ if (chartype[*buf_ptr] == opchar) { /* we have two char
* assignment */
e_token[-1] = *buf_ptr++; e_token[-1] = *buf_ptr++;
if ((e_token[-1] == '<' || e_token[-1] == '>') && e_token[-1] == *buf_ptr) if ((e_token[-1] == '<' || e_token[-1] == '>') && e_token[-1] == *buf_ptr)
*e_token++ = *buf_ptr++; *e_token++ = *buf_ptr++;
@ -501,7 +495,7 @@ stop_lit:
*e_token = 0; *e_token = 0;
} }
#else #else
if (*buf_ptr == '=') {/* == */ if (*buf_ptr == '=') { /* == */
*e_token++ = '='; /* Flip =+ to += */ *e_token++ = '='; /* Flip =+ to += */
buf_ptr++; buf_ptr++;
*e_token = 0; *e_token = 0;
@ -581,7 +575,7 @@ addkey(char *key, int val)
/* /*
* Whoa. Must reallocate special table. * Whoa. Must reallocate special table.
*/ */
nspecials = sizeof (specialsinit) / sizeof (specialsinit[0]); nspecials = sizeof(specialsinit) / sizeof(specialsinit[0]);
maxspecials = nspecials + (nspecials >> 2); maxspecials = nspecials + (nspecials >> 2);
specials = calloc(maxspecials, sizeof specials[0]); specials = calloc(maxspecials, sizeof specials[0]);
if (specials == NULL) if (specials == NULL)
@ -597,7 +591,6 @@ addkey(char *key, int val)
specials = specials2; specials = specials2;
maxspecials = newspecials; maxspecials = newspecials;
} }
p = &specials[nspecials]; p = &specials[nspecials];
p->rwd = key; p->rwd = key;
p->rwcode = val; p->rwcode = val;

25
parse.c
View File

@ -39,8 +39,8 @@
void reduce(void); void reduce(void);
void void
parse(int tk) /* the code for the construct scanned */ parse(int tk)
{ { /* the code for the construct scanned */
int i; int i;
#ifdef debug #ifdef debug
@ -127,8 +127,7 @@ parse(int tk) /* the code for the construct scanned */
ps.ind_level = ps.i_l_follow = ps.il[ps.tos]; ps.ind_level = ps.i_l_follow = ps.il[ps.tos];
ps.p_stack[++ps.tos] = whilestmt; ps.p_stack[++ps.tos] = whilestmt;
ps.il[ps.tos] = ps.ind_level = ps.i_l_follow; ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
} } else { /* it is a while loop */
else { /* it is a while loop */
ps.p_stack[++ps.tos] = whilestmt; ps.p_stack[++ps.tos] = whilestmt;
ps.il[ps.tos] = ps.i_l_follow; ps.il[ps.tos] = ps.i_l_follow;
++ps.i_l_follow; ++ps.i_l_follow;
@ -142,10 +141,10 @@ parse(int tk) /* the code for the construct scanned */
if (ps.p_stack[ps.tos] != ifhead) if (ps.p_stack[ps.tos] != ifhead)
diag(1, "Unmatched 'else'"); diag(1, "Unmatched 'else'");
else { else {
ps.ind_level = ps.il[ps.tos]; /* indentation for else should ps.ind_level = ps.il[ps.tos]; /* indentation for else
* be same as for if */ * should be same as for if */
ps.i_l_follow = ps.ind_level + 1; /* everything following should ps.i_l_follow = ps.ind_level + 1; /* everything following
* be in 1 level */ * should be in 1 level */
ps.p_stack[ps.tos] = elsehead; ps.p_stack[ps.tos] = elsehead;
/* remember if with else */ /* remember if with else */
ps.search_brace = btype_2 | ps.else_if; ps.search_brace = btype_2 | ps.else_if;
@ -157,8 +156,7 @@ parse(int tk) /* the code for the construct scanned */
if (ps.p_stack[ps.tos - 1] == lbrace) { if (ps.p_stack[ps.tos - 1] == lbrace) {
ps.ind_level = ps.i_l_follow = ps.il[--ps.tos]; ps.ind_level = ps.i_l_follow = ps.il[--ps.tos];
ps.p_stack[ps.tos] = stmt; ps.p_stack[ps.tos] = stmt;
} } else
else
diag(1, "Stmt nesting error."); diag(1, "Stmt nesting error.");
break; break;
@ -245,8 +243,8 @@ reduce(void)
int i; int i;
for (;;) { /* keep looping until there is nothing left to for (;;) { /* keep looping until there is nothing left
* reduce */ * to reduce */
switch (ps.p_stack[ps.tos]) { switch (ps.p_stack[ps.tos]) {
@ -310,8 +308,7 @@ reduce(void)
/* it is termination of a do while */ /* it is termination of a do while */
ps.p_stack[--ps.tos] = stmt; ps.p_stack[--ps.tos] = stmt;
break; break;
} } else
else
return; return;
default: /* anything else on top */ default: /* anything else on top */

View File

@ -72,14 +72,15 @@ void
pr_comment(void) pr_comment(void)
{ {
int now_col; /* column we are in now */ int now_col; /* column we are in now */
int adj_max_col; /* Adjusted max_col for when we decide to int adj_max_col;/* Adjusted max_col for when we decide to
* spill comments over the right margin */ * spill comments over the right margin */
char *last_bl; /* points to the last blank in the output char *last_bl; /* points to the last blank in the output
* buffer */ * buffer */
char *t_ptr; /* used for moving string */ char *t_ptr; /* used for moving string */
int unix_comment; /* tri-state variable used to decide if it is int unix_comment; /* tri-state variable used to decide
* a unix-style comment. 0 means only blanks * if it is a unix-style comment. 0
* since / *, 1 means regular style comment, 2 * means only blanks since / *, 1
* means regular style comment, 2
* means unix style comment */ * means unix style comment */
int break_delim = comment_delimiter_on_blankline; int break_delim = comment_delimiter_on_blankline;
int l_just_saw_decl = ps.just_saw_decl; int l_just_saw_decl = ps.just_saw_decl;
@ -87,26 +88,27 @@ pr_comment(void)
* int ps.last_nl = 0; true iff the last significant thing * int ps.last_nl = 0; true iff the last significant thing
* we've seen is a newline * we've seen is a newline
*/ */
int one_liner = 1; /* true iff this comment is a one-liner */ int one_liner = 1; /* true iff this comment is a
* one-liner */
adj_max_col = max_col; adj_max_col = max_col;
ps.just_saw_decl = 0; ps.just_saw_decl = 0;
last_bl = 0; /* no blanks found so far */ last_bl = 0; /* no blanks found so far */
ps.box_com = false; /* at first, assume that we are not in ps.box_com = false; /* at first, assume that we are not in a
* a boxed comment or some other * boxed comment or some other comment that
* comment that should not be touched */ * should not be touched */
++ps.out_coms; /* keep track of number of comments */ ++ps.out_coms; /* keep track of number of comments */
unix_comment = 1; /* set flag to let us figure out if there is a unix_comment = 1; /* set flag to let us figure out if there is
* unix-style comment ** DISABLED: use 0 to * a unix-style comment ** DISABLED: use 0 to
* reenable this hack! */ * reenable this hack! */
/* Figure where to align and how to treat the comment */ /* Figure where to align and how to treat the comment */
if (ps.col_1 && !format_col1_comments) { /* if comment starts in column if (ps.col_1 && !format_col1_comments) { /* if comment starts in
* 1 it should not be touched */ * column 1 it should not be
* touched */
ps.box_com = true; ps.box_com = true;
ps.com_col = 1; ps.com_col = 1;
} } else {
else {
if (*buf_ptr == '-' || *buf_ptr == '*' || *buf_ptr == '\n') { if (*buf_ptr == '-' || *buf_ptr == '*' || *buf_ptr == '\n') {
ps.box_com = true; /* a comment with a '-', '*' or newline ps.box_com = true; /* a comment with a '-', '*' or newline
* immediately after the / * is assumed to be * immediately after the / * is assumed to be
@ -123,8 +125,7 @@ pr_comment(void)
adj_max_col = block_comment_max_col; adj_max_col = block_comment_max_col;
if (ps.com_col <= 1) if (ps.com_col <= 1)
ps.com_col = 1 + !format_col1_comments; ps.com_col = 1 + !format_col1_comments;
} } else {
else {
int target_col; int target_col;
break_delim = 0; break_delim = 0;
if (s_code != e_code) if (s_code != e_code)
@ -145,8 +146,7 @@ pr_comment(void)
buf_ptr[-2] = 0; buf_ptr[-2] = 0;
ps.n_comment_delta = 1 - count_spaces(1, in_buffer); ps.n_comment_delta = 1 - count_spaces(1, in_buffer);
buf_ptr[-2] = '/'; buf_ptr[-2] = '/';
} } else {
else {
ps.n_comment_delta = 0; ps.n_comment_delta = 0;
while (*buf_ptr == ' ' || *buf_ptr == '\t') while (*buf_ptr == ' ' || *buf_ptr == '\t')
buf_ptr++; buf_ptr++;
@ -161,8 +161,7 @@ pr_comment(void)
if (troff) { if (troff) {
now_col = 1; now_col = 1;
adj_max_col = 80; adj_max_col = 80;
} } else
else
now_col = count_spaces(ps.com_col, s_com); /* figure what column we now_col = count_spaces(ps.com_col, s_com); /* figure what column we
* would be in if we * would be in if we
* printed the comment * printed the comment
@ -186,8 +185,7 @@ pr_comment(void)
*e_com++ = '*'; *e_com++ = '*';
*e_com++ = ' '; *e_com++ = ' ';
while (*++buf_ptr == ' ' || *buf_ptr == '\t'); while (*++buf_ptr == ' ' || *buf_ptr == '\t');
} } else {
else {
if (++buf_ptr >= buf_end) if (++buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
*e_com++ = 014; *e_com++ = 014;
@ -202,9 +200,9 @@ pr_comment(void)
return; return;
} }
one_liner = 0; one_liner = 0;
if (ps.box_com || ps.last_nl) { /* if this is a boxed comment, if (ps.box_com || ps.last_nl) { /* if this is a boxed
* we don't ignore the newline * comment, we don't ignore
*/ * the newline */
if (s_com == e_com) { if (s_com == e_com) {
*e_com++ = ' '; *e_com++ = ' ';
*e_com++ = ' '; *e_com++ = ' ';
@ -230,8 +228,7 @@ pr_comment(void)
} }
dump_line(); dump_line();
now_col = ps.com_col; now_col = ps.com_col;
} } else {
else {
ps.last_nl = 1; ps.last_nl = 1;
if (unix_comment != 1) { /* we not are in unix_style if (unix_comment != 1) { /* we not are in unix_style
* comment */ * comment */
@ -245,8 +242,8 @@ pr_comment(void)
if (ps.com_col <= 1) if (ps.com_col <= 1)
ps.com_col = 2; ps.com_col = 2;
} }
unix_comment = 2; /* permanently remember that we are in unix_comment = 2; /* permanently remember that we are
* this type of comment */ * in this type of comment */
dump_line(); dump_line();
++line_no; ++line_no;
now_col = ps.com_col; now_col = ps.com_col;
@ -288,8 +285,7 @@ pr_comment(void)
goto end_of_comment; goto end_of_comment;
} }
} while (*buf_ptr == ' ' || *buf_ptr == '\t'); } while (*buf_ptr == ' ' || *buf_ptr == '\t');
} } else if (++buf_ptr >= buf_end)
else if (++buf_ptr >= buf_end)
fill_buffer(); fill_buffer();
break; /* end of case for newline */ break; /* end of case for newline */
@ -336,8 +332,7 @@ pr_comment(void)
*e_com = '\0'; *e_com = '\0';
ps.just_saw_decl = l_just_saw_decl; ps.just_saw_decl = l_just_saw_decl;
return; return;
} } else { /* handle isolated '*' */
else { /* handle isolated '*' */
*e_com++ = '*'; *e_com++ = '*';
++now_col; ++now_col;
} }