diff options
-rw-r--r-- | usr.bin/indent/args.c | 157 | ||||
-rw-r--r-- | usr.bin/indent/indent.c | 82 | ||||
-rw-r--r-- | usr.bin/indent/indent.h | 47 | ||||
-rw-r--r-- | usr.bin/indent/indent_globs.h | 4 | ||||
-rw-r--r-- | usr.bin/indent/io.c | 116 | ||||
-rw-r--r-- | usr.bin/indent/lexi.c | 89 | ||||
-rw-r--r-- | usr.bin/indent/parse.c | 20 | ||||
-rw-r--r-- | usr.bin/indent/pr_comment.c | 22 |
8 files changed, 310 insertions, 227 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index 2e6821f..3693e1e 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -52,6 +52,7 @@ static const char rcsid[] = #include <stdlib.h> #include <string.h> #include "indent_globs.h" +#include "indent.h" /* profile types */ #define PRO_SPECIAL 1 /* special case */ @@ -69,6 +70,8 @@ static const char rcsid[] = #define STDIN 3 /* use stdin */ #define KEY 4 /* type (keyword) */ +static void scan_profile(FILE *); + char *option_source = "?"; /* @@ -85,80 +88,81 @@ struct pro { int *p_obj; /* the associated variable */ } pro[] = { - "T", PRO_SPECIAL, 0, KEY, 0, - "bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation, - "badp", PRO_BOOL, false, ON, &blanklines_after_declarations_at_proctop, - "bad", PRO_BOOL, false, ON, &blanklines_after_declarations, - "bap", PRO_BOOL, false, ON, &blanklines_after_procs, - "bbb", PRO_BOOL, false, ON, &blanklines_before_blockcomments, - "bc", PRO_BOOL, true, OFF, &ps.leave_comma, - "bl", PRO_BOOL, true, OFF, &btype_2, - "br", PRO_BOOL, true, ON, &btype_2, - "bs", PRO_BOOL, false, ON, &Bill_Shannon, - "cdb", PRO_BOOL, true, ON, &comment_delimiter_on_blankline, - "cd", PRO_INT, 0, 0, &ps.decl_com_ind, - "ce", PRO_BOOL, true, ON, &cuddle_else, - "ci", PRO_INT, 0, 0, &continuation_indent, - "cli", PRO_SPECIAL, 0, CLI, 0, - "c", PRO_INT, 33, 0, &ps.com_ind, - "di", PRO_INT, 16, 0, &ps.decl_indent, - "dj", PRO_BOOL, false, ON, &ps.ljust_decl, - "d", PRO_INT, 0, 0, &ps.unindent_displace, - "eei", PRO_BOOL, false, ON, &extra_expression_indent, - "ei", PRO_BOOL, true, ON, &ps.else_if, - "fbc", PRO_FONT, 0, 0, (int *) &blkcomf, - "fbx", PRO_FONT, 0, 0, (int *) &boxcomf, - "fb", PRO_FONT, 0, 0, (int *) &bodyf, - "fc1", PRO_BOOL, true, ON, &format_col1_comments, - "fcb", PRO_BOOL, true, ON, &format_block_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, - "nfcb", PRO_BOOL, true, OFF, &format_block_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, - "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, - "v", PRO_BOOL, false, ON, &verbose, + {"T", PRO_SPECIAL, 0, KEY, 0}, + {"bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation}, + {"badp", PRO_BOOL, false, ON, &blanklines_after_declarations_at_proctop}, + {"bad", PRO_BOOL, false, ON, &blanklines_after_declarations}, + {"bap", PRO_BOOL, false, ON, &blanklines_after_procs}, + {"bbb", PRO_BOOL, false, ON, &blanklines_before_blockcomments}, + {"bc", PRO_BOOL, true, OFF, &ps.leave_comma}, + {"bl", PRO_BOOL, true, OFF, &btype_2}, + {"br", PRO_BOOL, true, ON, &btype_2}, + {"bs", PRO_BOOL, false, ON, &Bill_Shannon}, + {"cdb", PRO_BOOL, true, ON, &comment_delimiter_on_blankline}, + {"cd", PRO_INT, 0, 0, &ps.decl_com_ind}, + {"ce", PRO_BOOL, true, ON, &cuddle_else}, + {"ci", PRO_INT, 0, 0, &continuation_indent}, + {"cli", PRO_SPECIAL, 0, CLI, 0}, + {"c", PRO_INT, 33, 0, &ps.com_ind}, + {"di", PRO_INT, 16, 0, &ps.decl_indent}, + {"dj", PRO_BOOL, false, ON, &ps.ljust_decl}, + {"d", PRO_INT, 0, 0, &ps.unindent_displace}, + {"eei", PRO_BOOL, false, ON, &extra_expression_indent}, + {"ei", PRO_BOOL, true, ON, &ps.else_if}, + {"fbc", PRO_FONT, 0, 0, (int *) &blkcomf}, + {"fbx", PRO_FONT, 0, 0, (int *) &boxcomf}, + {"fb", PRO_FONT, 0, 0, (int *) &bodyf}, + {"fc1", PRO_BOOL, true, ON, &format_col1_comments}, + {"fcb", PRO_BOOL, true, ON, &format_block_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}, + {"nfcb", PRO_BOOL, true, OFF, &format_block_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}, + {"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}, + {"v", PRO_BOOL, false, ON, &verbose}, /* whew! */ - 0, 0, 0, 0, 0 + {0, 0, 0, 0, 0} }; /* * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments * given in these files. */ -set_profile() +void +set_profile(void) { register FILE *f; char fname[BUFSIZ]; @@ -176,8 +180,8 @@ set_profile() option_source = "Command line"; } -scan_profile(f) - register FILE *f; +static void +scan_profile(register FILE *f) { register int i; register char *p; @@ -196,11 +200,10 @@ scan_profile(f) } } -char *param_start; +char *param_start; -eqin(s1, s2) - register char *s1; - register char *s2; +static int +eqin(char *s1, char *s2) { while (*s1) { if (*s1++ != *s2++) @@ -213,7 +216,8 @@ eqin(s1, s2) /* * Set the defaults. */ -set_defaults() +void +set_defaults(void) { register struct pro *p; @@ -227,11 +231,10 @@ set_defaults() *p->p_obj = p->p_default; } -set_option(arg) - register char *arg; +void +set_option(char *arg) { register struct pro *p; - extern double atof(); arg++; /* ignore leading "-" */ for (p = pro; p->p_name; p++) diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 447c8e2..71259a8 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -56,9 +56,12 @@ static const char rcsid[] = #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> #include "indent_globs.h" #include "indent_codes.h" -#include <ctype.h> +#include "indent.h" + +static void bakcopy(void); char *in_name = "Standard Input"; /* will always point to name of input * file */ @@ -66,20 +69,17 @@ char *out_name = "Standard Output"; /* will always point to name * of output file */ char bakfile[MAXPATHLEN] = ""; -static void usage __P((void)); - -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { - extern int found_err; /* flag set in diag() on error */ + extern int found_err; /* flag set in diagN() on error */ int dec_ind; /* current indentation for declarations */ int di_stack[20]; /* a stack of structure indentation levels */ 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 hd_type; /* used to store type of stmt for if (...), + int hd_type = 0; /* used to store type of stmt for if (...), * for (...), etc */ register int i; /* local loop counter */ int scase; /* set to true when we see a case, so we will @@ -252,7 +252,7 @@ main(argc, argv) parse(semicolon); { register char *p = buf_ptr; - register col = 1; + register int col = 1; while (1) { if (*p == ' ') @@ -349,7 +349,7 @@ main(argc, argv) if (sc_end >= &(save_com[sc_size])) { /* check for temp buffer * overflow */ - diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever."); + diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever."); fflush(output); exit(1); } @@ -363,10 +363,10 @@ main(argc, argv) if (flushed_nl) /* if we flushed a newline, make sure it is * put back */ force_nl = true; - if (type_code == sp_paren && *token == 'i' - && last_else && ps.else_if - || type_code == sp_nparen && *token == 'e' - && e_code != s_code && e_code[-1] == '}') + if ((type_code == sp_paren && *token == 'i' + && last_else && ps.else_if) + || (type_code == sp_nparen && *token == 'e' + && e_code != s_code && e_code[-1] == '}')) force_nl = false; if (sc_end == 0) { /* ignore buffering if comment wasnt @@ -383,7 +383,7 @@ main(argc, argv) *sc_end++ = ' '; if (verbose && !flushed_nl) /* print error msg if the line * was not already broken */ - diag(0, "Line broken"); + diag2(0, "Line broken"); flushed_nl = false; } for (t_ptr = token; *t_ptr; ++t_ptr) @@ -419,7 +419,7 @@ check_type: || s_com != e_com) /* must dump end of line */ dump_line(); if (ps.tos > 1) /* check for balanced braces */ - diag(1, "Stuff missing from end of file."); + diag2(1, "Stuff missing from end of file."); if (verbose) { printf("There were %d output lines and %d comments\n", @@ -440,7 +440,7 @@ check_type: (type_code != lbrace || !btype_2)) { /* we should force a broken line here */ if (verbose && !flushed_nl) - diag(0, "Line broken"); + diag2(0, "Line broken"); flushed_nl = false; dump_line(); ps.want_blank = false; /* dont insert blank at line start */ @@ -540,7 +540,7 @@ check_type: ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { ps.p_l_follow = 0; - diag(0, "Extra %c", *token); + diag3(0, "Extra %c", *token); } if (e_code == s_code) /* if the paren starts the line */ ps.paren_level = ps.p_l_follow; /* then indent it */ @@ -713,7 +713,7 @@ check_type: * stmt. It is a bit complicated, because the semicolon might * be in a for stmt */ - diag(1, "Unbalanced parens"); + diag2(1, "Unbalanced parens"); ps.p_l_follow = 0; if (sp_sw) { /* this is a check for a if, while, etc. with * unbalanced parens */ @@ -758,7 +758,7 @@ check_type: if (ps.p_l_follow > 0) { /* check for preceding unbalanced * parens */ - diag(1, "Unbalanced parens"); + diag2(1, "Unbalanced parens"); ps.p_l_follow = 0; if (sp_sw) { /* check for unclosed if, for, etc. */ sp_sw = false; @@ -800,7 +800,7 @@ check_type: * declarations */ parse(semicolon); if (ps.p_l_follow) {/* check for unclosed if, for, else. */ - diag(1, "Unbalanced parens"); + diag2(1, "Unbalanced parens"); ps.p_l_follow = 0; sp_sw = false; } @@ -809,7 +809,7 @@ check_type: if (s_code != e_code && !ps.block_init) { /* '}' must be first on * line */ if (verbose) - diag(0, "Line broken"); + diag2(0, "Line broken"); dump_line(); } *e_code++ = '}'; @@ -852,7 +852,7 @@ check_type: if (*token == 'e') { if (e_code != s_code && (!cuddle_else || e_code[-1] != '}')) { if (verbose) - diag(0, "Line broken"); + diag2(0, "Line broken"); dump_line();/* make sure this starts a line */ ps.want_blank = false; } @@ -863,7 +863,7 @@ check_type: else { if (e_code != s_code) { /* make sure this starts a line */ if (verbose) - diag(0, "Line broken"); + diag2(0, "Line broken"); dump_line(); ps.want_blank = false; } @@ -909,19 +909,19 @@ check_type: *e_code++ = ' '; ps.want_blank = false; if (is_procname == 0 || !procnames_start_line) { - if (!ps.block_init) + if (!ps.block_init) { if (troff && !ps.dumped_decl_indent) { sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7); ps.dumped_decl_indent = 1; e_code += strlen(e_code); - } - else + } else { while ((e_code - s_code) < dec_ind) { CHECK_SIZE_CODE; *e_code++ = ' '; } - } - else { + } + } + } else { if (dec_ind && s_code != e_code) dump_line(); dec_ind = 0; @@ -1072,7 +1072,7 @@ check_type: if (strncmp(s_lab, "#if", 3) == 0) { if (blanklines_around_conditional_compilation) { - register c; + register int c; prefix_blankline_requested++; while ((c = getc(input)) == '\n'); ungetc(c, input); @@ -1082,18 +1082,18 @@ check_type: state_stack[ifdef_level++] = ps; } else - diag(1, "#if stack overflow"); + diag2(1, "#if stack overflow"); } else if (strncmp(s_lab, "#else", 5) == 0) if (ifdef_level <= 0) - diag(1, "Unmatched #else"); + diag2(1, "Unmatched #else"); else { match_state[ifdef_level - 1] = ps; ps = state_stack[ifdef_level - 1]; } else if (strncmp(s_lab, "#endif", 6) == 0) { if (ifdef_level <= 0) - diag(1, "Unmatched #endif"); + diag2(1, "Unmatched #endif"); else { ifdef_level--; @@ -1104,7 +1104,7 @@ check_type: */ if (match_state[ifdef_level].tos >= 0 && bcmp(&ps, &match_state[ifdef_level], sizeof ps)) - diag(0, "Syntactically inconsistant #ifdef alternatives."); + diag2(0, "Syntactically inconsistant #ifdef alternatives."); #endif } if (blanklines_around_conditional_compilation) { @@ -1115,7 +1115,7 @@ check_type: break; /* subsequent processing of the newline * character will cause the line to be printed */ - case comment: /* we have gotten a /* this is a biggie */ + case comment: /* we have gotten a / followed by * this is a biggie */ if (flushed_nl) { /* we should force a broken line here */ flushed_nl = false; dump_line(); @@ -1132,19 +1132,13 @@ check_type: } /* end of main while (1) loop */ } -static void -usage() -{ - fprintf(stderr, "usage: indent [ file [ outfile ] ] [ options ]\n"); - exit(1); -} - /* * copy input file to backup file if in_name is /blah/blah/blah/file, then * backup file will be ".Bfile" then make the backup file the input and * original input file the output */ -bakcopy() +static void +bakcopy(void) { int n, bakchn; @@ -1163,7 +1157,7 @@ bakcopy() bakchn = creat(bakfile, 0600); if (bakchn < 0) err(1, "%s", bakfile); - while (n = read(fileno(input), buff, sizeof buff)) + while ((n = read(fileno(input), buff, sizeof buff)) != 0) if (write(bakchn, buff, n) != n) err(1, "%s", bakfile); if (n < 0) diff --git a/usr.bin/indent/indent.h b/usr.bin/indent/indent.h new file mode 100644 index 0000000..cd64498 --- /dev/null +++ b/usr.bin/indent/indent.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2001 Jens Schweikhardt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if 0 +__FBSDID("$FreeBSD$"); +#endif + +void addkey(char *, int); +int compute_code_target(void); +int compute_label_target(void); +int count_spaces(int, char *); +int lexi(void); +void diag2(int, char *); +void diag3(int, char *, int); +void diag4(int, char *, int, int); +void dump_line(void); +void fill_buffer(void); +void parse(int); +void parsefont(struct fstate *, char *); +void pr_comment(void); +void set_defaults(void); +void set_option(char *); +void set_profile(void); +void writefdef(struct fstate *f, int); diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index 5f49f9c..f366560 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -157,7 +157,7 @@ int procnames_start_line; /* if true, the names of procedures int proc_calls_space; /* If true, procedure calls look like: * foo(bar) rather than foo (bar) */ int format_block_comments; /* true if comments beginning with - * `/*\n' are to be reformatted */ + * `/ * \n' are to be reformatted */ int format_col1_comments; /* If comments which start in column 1 * are to be magically reformatted * (just like comments that begin in @@ -220,7 +220,7 @@ struct parser_state { float cstk[STACKSIZE];/* used to store case stmt indentation levels */ int box_com; /* set to true when we are in a "boxed" * comment. In that case, the first non-blank - * char should be lined up with the / in /* */ + * char should be lined up with the / in / followed by * */ int comment_delta, n_comment_delta; int cast_mask; /* indicates which close parens close off diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c index 596c849..b8f7a56 100644 --- a/usr.bin/indent/io.c +++ b/usr.bin/indent/io.c @@ -47,20 +47,22 @@ static const char rcsid[] = #include <stdlib.h> #include <string.h> #include "indent_globs.h" - +#include "indent.h" int comment_open; -static paren_target; +static int paren_target; +static int pad_output(int current, int target); -dump_line() +void +dump_line(void) { /* dump_line is the routine that actually * effects the printing of the new source. It * prints the label section, followed by the * code section with the appropriate nesting * level, followed by any comments */ register int cur_col, - target_col; - static not_first_line; + target_col = 1; + static int not_first_line; if (ps.procname[0]) { if (troff) { @@ -143,7 +145,7 @@ dump_line() } target_col = compute_code_target(); { - register i; + register int i; for (i = 0; i < ps.p_l_follow; i++) if (ps.paren_indents[i] >= 0) @@ -157,7 +159,7 @@ dump_line() putc(*p, output); cur_col = count_spaces(cur_col, s_code); } - if (s_com != e_com) + if (s_com != e_com) { if (troff) { int all_here = 0; register char *p; @@ -216,7 +218,7 @@ dump_line() } } else { /* print comment, if any */ - register target = ps.com_col; + register int target = ps.com_col; register char *com_st = s_com; target += ps.comment_delta; @@ -251,6 +253,7 @@ dump_line() cur_col = count_spaces(cur_col, com_st); ++ps.com_lines; /* count lines with comments */ } + } if (ps.use_ff) putc('\014', output); else @@ -282,19 +285,19 @@ inhibit_newline: ps.paren_level = ps.p_l_follow; paren_target = -ps.paren_indents[ps.paren_level - 1]; not_first_line = 1; - return; } -compute_code_target() +int +compute_code_target(void) { - register target_col = ps.ind_size * ps.ind_level + 1; + register int 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; + register int w; + register int t = paren_target; if ((w = count_spaces(t, s_code) - max_col) > 0 && count_spaces(target_col, s_code) <= max_col) { @@ -310,7 +313,8 @@ compute_code_target() return target_col; } -compute_label_target() +int +compute_label_target(void) { return ps.pcase ? (int) (case_ind * ps.ind_size) + 1 @@ -334,8 +338,8 @@ compute_label_target() * buffer from temporary buffer * */ -int -fill_buffer() +void +fill_buffer(void) { /* this routine reads stuff from the input */ register char *p; register int i; @@ -351,9 +355,9 @@ fill_buffer() } 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); + register int size = (in_buffer_limit - in_buffer) * 2 + 10; + register int offset = p - in_buffer; + in_buffer = realloc(in_buffer, size); if (in_buffer == 0) err(1, "input line too long"); p = in_buffer + offset; @@ -391,11 +395,12 @@ fill_buffer() p++; if (*p == '*') com = 1; - else if (*p == 'O') + 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) { @@ -418,7 +423,6 @@ fill_buffer() putc(*p, output); while (*p++ != '\n'); } - return; } /* @@ -449,11 +453,13 @@ fill_buffer() * HISTORY: initial coding November 1976 D A Willcox of CAC * */ -pad_output(current, target) /* writes tabs and blanks (if necessary) to +static int +pad_output(int current, int target) + /* writes tabs and blanks (if necessary) to * get the current output position up to the * target column */ - int current; /* the current column value */ - int target; /* position we want it at */ + /* current: the current column value */ + /* target: position we want it at */ { register int curr; /* internal column pointer */ register int tcur; @@ -495,13 +501,11 @@ pad_output(current, target) /* writes tabs and blanks (if necessary) to * */ int -count_spaces(current, buffer) +count_spaces(int current, char *buffer) /* * this routine figures out where the character position will be after * printing the text in buffer starting at column "current" */ - int current; - char *buffer; { register char *buf; /* used to look thru buffer */ register int cur; /* current character counter */ @@ -533,9 +537,9 @@ count_spaces(current, buffer) } int found_err; -/* VARARGS2 */ -diag(level, msg, a, b) - char *msg; + +void +diag4(int level, char *msg, int a, int b) { if (level) found_err = 1; @@ -551,18 +555,49 @@ diag(level, msg, a, b) } } -writefdef(f, nm) - register struct fstate *f; +void +diag3(int level, char *msg, int a) +{ + if (level) + found_err = 1; + if (output == stdout) { + fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no); + fprintf(stdout, msg, a); + fprintf(stdout, " */\n"); + } + else { + fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no); + fprintf(stderr, msg, a); + fprintf(stderr, "\n"); + } +} + +void +diag2(int level, char *msg) +{ + if (level) + found_err = 1; + if (output == stdout) { + fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no); + fprintf(stdout, msg); + fprintf(stdout, " */\n"); + } + else { + fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no); + fprintf(stderr, msg); + fprintf(stderr, "\n"); + } +} + +void +writefdef(struct fstate *f, int nm) { fprintf(output, ".ds f%c %s\n.nr s%c %d\n", nm, f->font, nm, f->size); } -char * -chfont(of, nf, s) - register struct fstate *of, - *nf; - char *s; +char * +chfont(struct fstate *of, struct fstate *nf, char *s) { if (of->font[0] != nf->font[0] || of->font[1] != nf->font[1]) { @@ -591,13 +626,12 @@ chfont(of, nf, s) return s; } - -parsefont(f, s0) - register struct fstate *f; - char *s0; +void +parsefont(struct fstate *f, char *s0) { register char *s = s0; int sizedelta = 0; + bzero(f, sizeof *f); while (*s) { if (isdigit(*s)) diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index 12e51dc..8374710 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -33,11 +33,13 @@ * SUCH DAMAGE. */ +#if 0 #ifndef lint static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ +#endif /* * Here we have the token scanner for indent. It scans off one token and puts @@ -55,6 +57,8 @@ static const char rcsid[] = #define alphanum 1 #define opchar 3 +void fill_buffer(void); + struct templ { char *rwd; int rwcode; @@ -62,37 +66,37 @@ struct templ { struct templ specials[1000] = { - "switch", 1, - "case", 2, - "break", 0, - "struct", 3, - "union", 3, - "enum", 3, - "default", 2, - "int", 4, - "char", 4, - "float", 4, - "double", 4, - "long", 4, - "short", 4, - "typdef", 4, - "unsigned", 4, - "register", 4, - "static", 4, - "global", 4, - "extern", 4, - "void", 4, - "goto", 0, - "return", 0, - "if", 5, - "while", 5, - "for", 5, - "else", 6, - "do", 6, - "sizeof", 7, - "const", 9, - "volatile", 9, - 0, 0 + {"switch", 1}, + {"case", 2}, + {"break", 0}, + {"struct", 3}, + {"union", 3}, + {"enum", 3}, + {"default", 2}, + {"int", 4}, + {"char", 4}, + {"float", 4}, + {"double", 4}, + {"long", 4}, + {"short", 4}, + {"typdef", 4}, + {"unsigned", 4}, + {"register", 4}, + {"static", 4}, + {"global", 4}, + {"extern", 4}, + {"void", 4}, + {"goto", 0}, + {"return", 0}, + {"if", 5}, + {"while", 5}, + {"for", 5}, + {"else", 6}, + {"do", 6}, + {"sizeof", 7}, + {"const", 9}, + {"volatile", 9}, + {0, 0} }; char chartype[128] = @@ -117,14 +121,10 @@ char chartype[128] = 1, 1, 1, 0, 3, 0, 3, 0 }; - - - int -lexi() +lexi(void) { int unary_delim; /* this is set to 1 if the current token - * * forces a following operator to be unary */ static int last_code; /* the last token type returned */ static int l_struct; /* set to 1 if the last token was 'struct' */ @@ -145,7 +145,7 @@ lexi() } /* Scan an alphanumeric token */ - if (chartype[*buf_ptr] == alphanum || buf_ptr[0] == '.' && isdigit(buf_ptr[1])) { + if (chartype[(int)*buf_ptr] == alphanum || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { /* * we have a character or number */ @@ -154,7 +154,7 @@ lexi() * reserved words */ register struct templ *p; - if (isdigit(*buf_ptr) || buf_ptr[0] == '.' && isdigit(buf_ptr[1])) { + if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { int seendot = 0, seenexp = 0, seensfx = 0; @@ -169,14 +169,15 @@ lexi() } else while (1) { - if (*buf_ptr == '.') + if (*buf_ptr == '.') { if (seendot) break; else seendot++; + } CHECK_SIZE_TOKEN; *e_token++ = *buf_ptr++; - if (!isdigit(*buf_ptr) && *buf_ptr != '.') + if (!isdigit(*buf_ptr) && *buf_ptr != '.') { if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) break; else { @@ -187,6 +188,7 @@ lexi() if (*buf_ptr == '+' || *buf_ptr == '-') *e_token++ = *buf_ptr++; } + } } while (1) { if (!(seensfx & 1) && @@ -209,7 +211,7 @@ lexi() } } else - while (chartype[*buf_ptr] == alphanum || *buf_ptr == BACKSLASH) { + while (chartype[(int)*buf_ptr] == alphanum || *buf_ptr == BACKSLASH) { /* fill_buffer() terminates buffer with newline */ if (*buf_ptr == BACKSLASH) { if (*(buf_ptr + 1) == '\n') { @@ -582,8 +584,8 @@ stop_lit: /* * Add the given keyword to the keyword table, using val as the keyword type */ -addkey(key, val) - char *key; +void +addkey(char *key, int val) { register struct templ *p = specials; while (p->rwd) @@ -598,5 +600,4 @@ addkey(key, val) p->rwcode = val; p[1].rwd = 0; p[1].rwcode = 0; - return; } diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c index da8b4a6..c87d1d4 100644 --- a/usr.bin/indent/parse.c +++ b/usr.bin/indent/parse.c @@ -32,19 +32,23 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - +#if 0 #ifndef lint static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93"; static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ +#endif #include <stdio.h> #include "indent_globs.h" #include "indent_codes.h" +#include "indent.h" -parse(tk) - int tk; /* the code for the construct scanned */ +static void reduce(void); + +void +parse(int tk) /* tk: the code for the construct scanned */ { int i; @@ -145,7 +149,7 @@ parse(tk) case elselit: /* scanned an else */ if (ps.p_stack[ps.tos] != ifhead) - diag(1, "Unmatched 'else'"); + diag2(1, "Unmatched 'else'"); else { ps.ind_level = ps.il[ps.tos]; /* indentation for else should * be same as for if */ @@ -164,7 +168,7 @@ parse(tk) ps.p_stack[ps.tos] = stmt; } else - diag(1, "Stmt nesting error."); + diag2(1, "Stmt nesting error."); break; case swstmt: /* had switch (...) */ @@ -188,7 +192,7 @@ parse(tk) break; default: /* this is an error */ - diag(1, "Unknown code to parser"); + diag2(1, "Unknown code to parser"); return; @@ -244,9 +248,9 @@ parse(tk) /*----------------------------------------------*\ | REDUCTION PHASE | \*----------------------------------------------*/ -reduce() +static void +reduce(void) { - register int i; for (;;) { /* keep looping until there is nothing left to diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c index 4bf974d..70c31aa 100644 --- a/usr.bin/indent/pr_comment.c +++ b/usr.bin/indent/pr_comment.c @@ -32,17 +32,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - +#if 0 #ifndef lint static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ - +#endif #include <stdio.h> #include <stdlib.h> #include "indent_globs.h" - +#include "indent.h" /* * NAME: * pr_comment @@ -74,8 +74,8 @@ static const char rcsid[] = * beginning of the input line are removed */ - -pr_comment() +void +pr_comment(void) { int now_col; /* column we are in now */ int adj_max_col; /* Adjusted max_col for when we decide to @@ -85,12 +85,12 @@ pr_comment() char *t_ptr; /* used for moving string */ int unix_comment; /* tri-state variable used to decide if it is * a unix-style comment. 0 means only blanks - * since /*, 1 means regular style comment, 2 + * since /+*, 1 means regular style comment, 2 * means unix style comment */ int break_delim = comment_delimiter_on_blankline; int l_just_saw_decl = ps.just_saw_decl; /* - * int ps.last_nl = 0; /* true iff the last significant thing + * int ps.last_nl = 0; true iff the last significant thing * weve seen is a newline */ int one_liner = 1; /* true iff this comment is a one-liner */ @@ -116,9 +116,9 @@ pr_comment() if (*buf_ptr == '-' || *buf_ptr == '*' || (*buf_ptr == '\n' && !format_block_comments)) { ps.box_com = true; /* A comment with a '-' or '*' immediately - * after the /* is assumed to be a boxed + * after the /+* is assumed to be a boxed * comment. A comment with a newline - * immediately after the /* is assumed to + * immediately after the /+* is assumed to * be a block comment and is treated as a * box comment unless format_block_comments * is nonzero (the default). */ @@ -136,7 +136,7 @@ pr_comment() ps.com_col = 1 + !format_col1_comments; } else { - register target_col; + register int target_col; break_delim = 0; if (s_code != e_code) target_col = count_spaces(compute_code_target(), s_code); @@ -163,7 +163,7 @@ pr_comment() buf_ptr++; } ps.comment_delta = 0; - *e_com++ = '/'; /* put '/*' into buffer */ + *e_com++ = '/'; /* put '/' followed by '*' into buffer */ *e_com++ = '*'; if (*buf_ptr != ' ' && !ps.box_com) *e_com++ = ' '; |