summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/indent/args.c62
-rw-r--r--usr.bin/indent/indent.135
-rw-r--r--usr.bin/indent/indent.c44
-rw-r--r--usr.bin/indent/indent_codes.h7
-rw-r--r--usr.bin/indent/indent_globs.h37
-rw-r--r--usr.bin/indent/io.c123
-rw-r--r--usr.bin/indent/lexi.c42
-rw-r--r--usr.bin/indent/parse.c33
-rw-r--r--usr.bin/indent/pr_comment.c27
9 files changed, 244 insertions, 166 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index 71a6e6b5733..8cab02c1cd7 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: args.c,v 1.5 2000/08/02 04:10:47 millert Exp $ */
+/* $OpenBSD: args.c,v 1.6 2001/01/08 07:14:42 pjanzen Exp $ */
/*
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
+ * Copyright (c) 1985 Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,8 +37,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)args.c 5.10 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: args.c,v 1.5 2000/08/02 04:10:47 millert Exp $";
+/*static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";*/
+static char rcsid[] = "$OpenBSD: args.c,v 1.6 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
/*
@@ -57,7 +58,7 @@ static char rcsid[] = "$OpenBSD: args.c,v 1.5 2000/08/02 04:10:47 millert Exp $"
#define PRO_SPECIAL 1 /* special case */
#define PRO_BOOL 2 /* boolean */
#define PRO_INT 3 /* integer */
-#define PRO_FONT 4 /* troff font */
+#define PRO_FONT 4 /* troff font */
/* profile specials for booleans */
#define ON 1 /* turn it on */
@@ -156,8 +157,8 @@ struct pro {
{ 0, 0, 0, 0, 0 }
};
-void scan_profile();
-void set_option();
+void scan_profile __P((FILE *));
+void set_option __P((char *));
/*
* set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments
@@ -166,14 +167,14 @@ void set_option();
void
set_profile()
{
- register FILE *f;
+ FILE *f;
char fname[BUFSIZ];
char *home;
static char prof[] = ".indent.pro";
home = getenv("HOME");
if (home != NULL && *home != '\0') {
- if (strlen(home) + sizeof(prof) > sizeof(fname)) {
+ if (strlen(home) + sizeof(prof) + 1 > sizeof(fname)) {
warnx("%s/%s: %s", home, prof, strerror(ENAMETOOLONG));
return;
}
@@ -192,16 +193,19 @@ set_profile()
void
scan_profile(f)
- register FILE *f;
+ FILE *f;
{
- register int i;
- register char *p;
+ int i;
+ char *p;
char buf[BUFSIZ];
while (1) {
- for (p = buf; (i = getc(f)) != EOF && (*p = i) > ' '; ++p);
+ for (p = buf;
+ (i = getc(f)) != EOF && (*p = i) > ' ' && p + 1 - buf < BUFSIZ;
+ ++p)
+ ;
if (p != buf) {
- *p++ = 0;
+ *p = 0;
if (verbose)
printf("profile: %s\n", buf);
set_option(buf);
@@ -215,8 +219,8 @@ char *param_start;
int
eqin(s1, s2)
- register char *s1;
- register char *s2;
+ char *s1;
+ char *s2;
{
while (*s1) {
if (*s1++ != *s2++)
@@ -232,7 +236,7 @@ eqin(s1, s2)
void
set_defaults()
{
- register struct pro *p;
+ struct pro *p;
/*
* Because ps.case_indent is a float, we can't initialize it from the
@@ -246,17 +250,15 @@ set_defaults()
void
set_option(arg)
- register char *arg;
+ char *arg;
{
register struct pro *p;
- extern double atof();
arg++; /* ignore leading "-" */
for (p = pro; p->p_name; p++)
if (*p->p_name == *arg && eqin(p->p_name, arg))
goto found;
- fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1);
- exit(1);
+ errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
found:
switch (p->p_type) {
@@ -283,16 +285,16 @@ found:
if (*param_start == 0)
goto need_param;
{
- register char *str = (char *) malloc(strlen(param_start) + 1);
- strcpy(str, param_start);
+ char *str;
+ if ((str = strdup(param_start)) == NULL)
+ errx(1, "out of memory");
addkey(str, 4);
}
break;
default:
- fprintf(stderr, "\
-indent: set_option: internal error: p_special %d\n", p->p_special);
- exit(1);
+ errx(1, "set_option: internal error: p_special %d",
+ p->p_special);
}
break;
@@ -306,9 +308,8 @@ indent: set_option: internal error: p_special %d\n", p->p_special);
case PRO_INT:
if (!isdigit(*param_start)) {
need_param:
- fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n",
+ errx(1, "%s: ``%s'' requires a parameter",
option_source, arg - 1);
- exit(1);
}
*p->p_obj = atoi(param_start);
break;
@@ -318,8 +319,7 @@ indent: set_option: internal error: p_special %d\n", p->p_special);
break;
default:
- fprintf(stderr, "indent: set_option: internal error: p_type %d\n",
+ errx(1, "set_option: internal error: p_type %d",
p->p_type);
- exit(1);
}
}
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index 5daf89b673b..053e2e80933 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -1,6 +1,7 @@
-.\" $OpenBSD: indent.1,v 1.9 2000/03/23 21:39:53 aaron Exp $
+.\" $OpenBSD: indent.1,v 1.10 2001/01/08 07:14:42 pjanzen Exp $
.\"
-.\" Copyright (c) 1980, 1990 The Regents of the University of California.
+.\" Copyright (c) 1980, 1990, 1993
+.\" The Regents of the University of California.
.\" Copyright (c) 1985 Sun Microsystems, Inc.
.\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
.\" All rights reserved.
@@ -33,9 +34,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" from: @(#)indent.1 6.11 (Berkeley) 7/24/91
+.\" from: @(#)indent.1 8.1 (Berkeley) 7/1/93
.\"
-.Dd July 24, 1991
+.Dd July 1, 1993
.Dt INDENT 1
.Os
.Sh NAME
@@ -110,6 +111,9 @@ is named
.Pa /blah/blah/file ,
the backup file is named
.Pa file.BAK .
+If
+.Pa file.BAK
+exists, it is overwritten.
.Pp
If
.Ar output-file
@@ -137,7 +141,8 @@ Default:
.It Fl bbb , nbbb
If
.Fl bbb
-is specified, a blank line is forced before every block comment.Default:
+is specified, a blank line is forced before every block comment.
+Default:
.Fl nbbb .
.It Fl \&bc , nbc
If
@@ -146,7 +151,7 @@ is specified, then a newline is forced after each comma in a declaration.
.Fl nbc
turns off this option.
The default is
-.Fl \&bc .
+.Fl \&nbc .
.It Fl \&br , \&bl
Specifying
.Fl \&bl
@@ -221,7 +226,7 @@ Causes case labels to be indented
tab stops to the right of the containing
.Ic switch
statement.
-.Fl cli0 .5
+.Fl cli0.5
causes case labels to be indented half a tab stop.
The default is
.Fl cli0 .
@@ -292,8 +297,8 @@ For example, here is how a piece of continued code looks with
in effect:
.ne 2
.Bd -literal -offset indent
-.Li p1 = first_procedure(second_procedure(p2, p3),
-.Li \ \ third_procedure(p4,p5));
+p1 = first_procedure(second_procedure(p2, p3),
+\ \ third_procedure(p4,p5));
.Ed
.Pp
.ne 5
@@ -301,17 +306,17 @@ With
.Fl lp
in effect (the default) the code looks somewhat clearer:
.Bd -literal -offset indent
-.Li p1\ =\ first_procedure(second_procedure(p2,\ p3),
-.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5));
+p1\ =\ first_procedure(second_procedure(p2,\ p3),
+\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5));
.Ed
.Pp
.ne 5
Inserting two more newlines we get:
.Bd -literal -offset indent
-.Li p1\ =\ first_procedure(second_procedure(p2,
-.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
-.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
-.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
+p1\ =\ first_procedure(second_procedure(p2,
+\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
+\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
+\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
.Ed
.It Fl npro
Causes the profile files,
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 293f8b17be5..fa7e5f9267d 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: indent.c,v 1.8 2000/07/25 17:08:12 espie Exp $ */
+/* $OpenBSD: indent.c,v 1.9 2001/01/08 07:14:42 pjanzen Exp $ */
/*
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
+ * Copyright (c) 1985 Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,14 +39,15 @@
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\
- @(#) Copyright (c) 1980 The Regents of the University of California.\n\
+ @(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California.\n\
@(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)indent.c 5.16 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: indent.c,v 1.8 2000/07/25 17:08:12 espie Exp $";
+/*static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";*/
+static char rcsid[] = "$OpenBSD: indent.c,v 1.9 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -101,6 +103,7 @@ main(argc, argv)
\*-----------------------------------------------*/
+ hd_type = 0;
ps.p_stack[0] = stmt; /* this is the parser's stack */
ps.last_nl = true; /* this is true if the last thing scanned was
* a newline */
@@ -109,6 +112,9 @@ main(argc, argv)
labbuf = (char *) malloc(bufsize);
codebuf = (char *) malloc(bufsize);
tokenbuf = (char *) malloc(bufsize);
+ if (combuf == NULL || labbuf == NULL || codebuf == NULL ||
+ tokenbuf == NULL)
+ errx(1, "out of memory");
l_com = combuf + bufsize - 5;
l_lab = labbuf + bufsize - 5;
l_code = codebuf + bufsize - 5;
@@ -123,6 +129,8 @@ main(argc, argv)
s_token = e_token = tokenbuf + 1;
in_buffer = (char *) malloc(10);
+ if (in_buffer == NULL)
+ errx(1, "out of memory");
in_buffer_limit = in_buffer + 8;
buf_ptr = buf_end = in_buffer;
line_no = 1;
@@ -212,13 +220,14 @@ main(argc, argv)
fprintf(stderr, "usage: indent file [ outfile ] [ options ]\n");
exit(1);
}
- if (output == NULL)
+ if (output == NULL) {
if (troff)
output = stdout;
else {
out_name = in_name;
bakcopy();
}
+ }
if (ps.com_ind <= 1)
ps.com_ind = 2; /* dont put normal comments before column 2 */
if (troff) {
@@ -251,8 +260,8 @@ main(argc, argv)
parse(semicolon);
{
- register char *p = buf_ptr;
- register col = 1;
+ char *p = buf_ptr;
+ int col = 1;
while (1) {
if (*p == ' ')
@@ -774,10 +783,9 @@ check_type:
/* ? dec_ind = 0; */
}
else {
- ps.decl_on_line = false; /* we cant be in the middle of
- * a declaration, so dont do
- * special indentation of
- * comments */
+ ps.decl_on_line = false;
+ /* we can't be in the middle of a declaration, so don't do
+ * special indentation of comments */
if (blanklines_after_declarations_at_proctop
&& ps.in_parameter_declaration)
postfix_blankline_requested = 1;
@@ -908,7 +916,7 @@ 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;
@@ -919,6 +927,7 @@ check_type:
CHECK_SIZE_CODE;
*e_code++ = ' ';
}
+ }
}
else {
if (dec_ind && s_code != e_code)
@@ -1071,7 +1080,7 @@ check_type:
if (strncmp(s_lab, "#if", 3) == 0) {
if (blanklines_around_conditional_compilation) {
- register c;
+ int c;
prefix_blankline_requested++;
while ((c = getc(input)) == '\n');
ungetc(c, input);
@@ -1142,7 +1151,7 @@ bakcopy()
int n,
bakchn;
char buff[8 * 1024];
- register char *p;
+ char *p;
/* construct file name .Bfile */
for (p = in_name; *p; p++); /* skip to end of string */
@@ -1150,7 +1159,8 @@ bakcopy()
p--;
if (*p == '/')
p++;
- sprintf(bakfile, "%s.BAK", p);
+ if (snprintf(bakfile, MAXPATHLEN, "%s.BAK", p) >= MAXPATHLEN)
+ errx(1, "%s.BAK: %s", p, strerror(ENAMETOOLONG));
/* copy in_name to backup file */
bakchn = creat(bakfile, 0600);
diff --git a/usr.bin/indent/indent_codes.h b/usr.bin/indent/indent_codes.h
index edc0c0f7363..c56ee308d7c 100644
--- a/usr.bin/indent/indent_codes.h
+++ b/usr.bin/indent/indent_codes.h
@@ -1,7 +1,8 @@
-/* * $OpenBSD: indent_codes.h,v 1.2 1996/06/26 05:34:29 deraadt Exp $*/
+/* * $OpenBSD: indent_codes.h,v 1.3 2001/01/08 07:14:42 pjanzen Exp $*/
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
@@ -33,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)indent_codes.h 5.7 (Berkeley) 6/1/90
+ * from: @(#)indent_codes.h 8.1 (Berkeley) 6/6/93
*/
#define newline 1
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index 43b4b7c16a4..636f6a5ff3e 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -1,7 +1,8 @@
-/* * $OpenBSD: indent_globs.h,v 1.4 1999/09/14 18:38:28 deraadt Exp $*/
+/* * $OpenBSD: indent_globs.h,v 1.5 2001/01/08 07:14:42 pjanzen Exp $*/
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
@@ -33,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)indent_globs.h 5.11 (Berkeley) 2/26/91
+ * from: @(#)indent_globs.h 8.1 (Berkeley) 6/6/93
*/
#define BACKSLASH '\\'
@@ -58,6 +59,8 @@ FILE *output; /* the output file */
if (e_code >= l_code) { \
register int nsize = l_code-s_code+400; \
codebuf = (char *) realloc(codebuf, nsize); \
+ if (codebuf == NULL) \
+ errx(1, "out of memory"); \
e_code = codebuf + (e_code-s_code) + 1; \
l_code = codebuf + nsize - 5; \
s_code = codebuf + 1; \
@@ -66,6 +69,8 @@ FILE *output; /* the output file */
if (e_com >= l_com) { \
register int nsize = l_com-s_com+400; \
combuf = (char *) realloc(combuf, nsize); \
+ if (combuf == NULL) \
+ errx(1, "out of memory"); \
e_com = combuf + (e_com-s_com) + 1; \
l_com = combuf + nsize - 5; \
s_com = combuf + 1; \
@@ -74,6 +79,8 @@ FILE *output; /* the output file */
if (e_lab >= l_lab) { \
register int nsize = l_lab-s_lab+400; \
labbuf = (char *) realloc(labbuf, nsize); \
+ if (labbuf == NULL) \
+ errx(1, "out of memory"); \
e_lab = labbuf + (e_lab-s_lab) + 1; \
l_lab = labbuf + nsize - 5; \
s_lab = labbuf + 1; \
@@ -82,6 +89,8 @@ FILE *output; /* the output file */
if (e_token >= l_token) { \
register int nsize = l_token-s_token+400; \
tokenbuf = (char *) realloc(tokenbuf, nsize); \
+ if (tokenbuf == NULL) \
+ errx(1, "out of memory"); \
e_token = tokenbuf + (e_token-s_token) + 1; \
l_token = tokenbuf + nsize - 5; \
s_token = tokenbuf + 1; \
@@ -309,3 +318,25 @@ int ifdef_level;
int rparen_count;
struct parser_state state_stack[5];
struct parser_state match_state[5];
+
+int compute_code_target __P((void));
+int compute_label_target __P((void));
+int count_spaces __P((int, char *));
+void diag __P((int, char *, ...));
+void dump_line __P((void));
+int eqin __P((char *, char *));
+void fill_buffer __P((void));
+int pad_output __P((int, int));
+void scan_profile __P((FILE *));
+void set_defaults __P((void));
+void set_option __P((char *));
+void addkey __P((char *, int));
+void set_profile __P((void));
+char *chfont __P((struct fstate *, struct fstate *, char *));
+void parsefont __P((struct fstate *, char *));
+void writefdef __P((struct fstate *, int));
+int lexi __P((void));
+void reduce __P((void));
+void parse __P((int));
+void pr_comment __P((void));
+void bakcopy __P((void));
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index cf436ae7f97..c1abb2c8be0 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: io.c,v 1.3 1997/07/25 22:00:46 mickey Exp $ */
+/* $OpenBSD: io.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $ */
/*
* Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993 The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
@@ -36,8 +36,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)io.c 5.15 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: io.c,v 1.3 1997/07/25 22:00:46 mickey Exp $";
+/*static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";*/
+static char rcsid[] = "$OpenBSD: io.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -49,7 +49,7 @@ static char rcsid[] = "$OpenBSD: io.c,v 1.3 1997/07/25 22:00:46 mickey Exp $";
int comment_open;
-static paren_target;
+static int paren_target;
void
dump_line()
@@ -58,9 +58,8 @@ dump_line()
* 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;
+ int cur_col, target_col;
+ static int not_first_line;
if (ps.procname[0]) {
if (troff) {
@@ -84,15 +83,15 @@ dump_line()
else if (!inhibit_formatting) {
suppress_blanklines = 0;
ps.bl_line = false;
- if (prefix_blankline_requested && not_first_line)
+ if (prefix_blankline_requested && not_first_line) {
if (swallow_optional_blanklines) {
if (n_real_blanklines == 1)
n_real_blanklines = 0;
- }
- else {
+ } else {
if (n_real_blanklines == 0)
n_real_blanklines = 1;
}
+ }
while (--n_real_blanklines >= 0)
putc('\n', output);
n_real_blanklines = 0;
@@ -115,17 +114,19 @@ dump_line()
cur_col = pad_output(1, compute_label_target());
if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
|| strncmp(s_lab, "#endif", 6) == 0)) {
- register char *s = s_lab;
- if (e_lab[-1] == '\n') e_lab--;
- do putc(*s++, output);
+ char *s = s_lab;
+ if (e_lab[-1] == '\n')
+ e_lab--;
+ do
+ putc(*s++, output);
while (s < e_lab && 'a' <= *s && *s<='z');
while ((*s == ' ' || *s == '\t') && s < e_lab)
s++;
if (s < e_lab)
fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",
- e_lab - s, s);
+ (int)(e_lab - s), s);
}
- else fprintf(output, "%.*s", e_lab - s_lab, s_lab);
+ else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab);
cur_col = count_spaces(cur_col, s_lab);
}
else
@@ -134,7 +135,7 @@ dump_line()
ps.pcase = false;
if (s_code != e_code) { /* print code section, if any */
- register char *p;
+ char *p;
if (comment_open) {
comment_open = 0;
@@ -142,7 +143,7 @@ dump_line()
}
target_col = compute_code_target();
{
- register i;
+ int i;
for (i = 0; i < ps.p_l_follow; i++)
if (ps.paren_indents[i] >= 0)
@@ -156,10 +157,10 @@ 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;
+ int all_here = 0;
+ char *p;
if (e_com[-1] == '/' && e_com[-2] == '*')
e_com -= 2, all_here++;
@@ -185,7 +186,7 @@ dump_line()
if ('a' <= *p && *p <= 'z')
*p = *p + 'A' - 'a';
if (e_com - p < 50 && all_here == 2) {
- register char *follow = p;
+ char *follow = p;
fprintf(output, "\n.nr C! \\w\1");
while (follow < e_com) {
switch (*follow) {
@@ -213,10 +214,9 @@ dump_line()
putc(BACKSLASH, output);
putc(*p++, output);
}
- }
- else { /* print comment, if any */
- register target = ps.com_col;
- register char *com_st = s_com;
+ } else { /* print comment, if any */
+ int target = ps.com_col;
+ char *com_st = s_com;
target += ps.comment_delta;
while (*com_st == '\t')
@@ -238,17 +238,19 @@ dump_line()
e_com--;
cur_col = pad_output(cur_col, target);
if (!ps.box_com) {
- if (star_comment_cont && (com_st[1] != '*' || e_com <= com_st + 1))
+ if (star_comment_cont && (com_st[1] != '*' || e_com <= com_st + 1)) {
if (com_st[1] == ' ' && com_st[0] == ' ' && e_com > com_st + 1)
com_st[1] = '*';
else
fwrite(" * ", com_st[0] == '\t' ? 2 : com_st[0] == '*' ? 1 : 3, 1, output);
+ }
}
fwrite(com_st, e_com - com_st, 1, output);
ps.comment_delta = ps.n_comment_delta;
cur_col = count_spaces(cur_col, com_st);
++ps.com_lines; /* count lines with comments */
}
+ }
if (ps.use_ff)
putc('\014', output);
else
@@ -286,14 +288,15 @@ inhibit_newline:
int
compute_code_target()
{
- register target_col = ps.ind_size * ps.ind_level + 1;
+ int target_col;
+ target_col = ps.ind_size * ps.ind_level + 1;
if (ps.paren_level)
if (!lineup_to_parens)
target_col += continuation_indent * ps.paren_level;
else {
- register w;
- register t = paren_target;
+ int w;
+ int t = paren_target;
if ((w = count_spaces(t, s_code) - max_col) > 0
&& count_spaces(target_col, s_code) <= max_col) {
@@ -337,9 +340,9 @@ compute_label_target()
void
fill_buffer()
{ /* this routine reads stuff from the input */
- register char *p;
- register int i;
- register FILE *f = input;
+ char *p;
+ int i;
+ FILE *f = input;
if (bp_save != 0) { /* there is a partly filled input buffer left */
buf_ptr = bp_save; /* dont read anything, just switch buffers */
@@ -351,10 +354,10 @@ 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;
+ int size = (in_buffer_limit - in_buffer) * 2 + 10;
+ int offset = p - in_buffer;
in_buffer = (char *) realloc(in_buffer, size);
- if (in_buffer == 0)
+ if (in_buffer == NULL)
errx(1, "input line too long");
p = in_buffer + offset;
in_buffer_limit = in_buffer + size - 2;
@@ -391,11 +394,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) {
@@ -456,8 +460,8 @@ pad_output(current, target) /* writes tabs and blanks (if necessary) to
int current; /* the current column value */
int target; /* position we want it at */
{
- register int curr; /* internal column pointer */
- register int tcur;
+ int curr; /* internal column pointer */
+ int tcur;
if (troff)
fprintf(output, "\\h'|%dp'", (target - 1) * 7);
@@ -504,8 +508,8 @@ count_spaces(current, buffer)
int current;
char *buffer;
{
- register char *buf; /* used to look thru buffer */
- register int cur; /* current character counter */
+ char *buf; /* used to look thru buffer */
+ int cur; /* current character counter */
cur = current;
@@ -533,29 +537,51 @@ count_spaces(current, buffer)
return (cur);
}
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
int found_err;
+
/* VARARGS2 */
void
-diag(level, msg, a, b)
+#if __STDC__
+diag(int level, char *msg, ...)
+#else
+diag(level, msg, va_alist)
+ int level;
char *msg;
+ va_dcl
+#endif
{
+ va_list ap;
+#if __STDC__
+ va_start(ap, msg);
+#else
+ va_start(ap);
+#endif
+
if (level)
found_err = 1;
if (output == stdout) {
fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stdout, msg, a, b);
+ vfprintf(stdout, msg, ap);
fprintf(stdout, " */\n");
}
else {
fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stderr, msg, a, b);
+ vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
}
+ va_end(ap);
}
void
writefdef(f, nm)
- register struct fstate *f;
+ struct fstate *f;
+ int nm;
{
fprintf(output, ".ds f%c %s\n.nr s%c %d\n",
nm, f->font, nm, f->size);
@@ -563,8 +589,7 @@ writefdef(f, nm)
char *
chfont(of, nf, s)
- register struct fstate *of,
- *nf;
+ struct fstate *of, *nf;
char *s;
{
if (of->font[0] != nf->font[0]
@@ -596,10 +621,10 @@ chfont(of, nf, s)
void
parsefont(f, s0)
- register struct fstate *f;
+ struct fstate *f;
char *s0;
{
- register char *s = s0;
+ char *s = s0;
int sizedelta = 0;
bzero(f, sizeof *f);
while (*s) {
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 160adcd6b3c..71a3bab58c3 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: lexi.c,v 1.6 1998/05/22 05:15:12 deraadt Exp $ */
+/* $OpenBSD: lexi.c,v 1.7 2001/01/08 07:14:42 pjanzen Exp $ */
/*
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
+ * Copyright (c) 1985 Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,8 +37,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)lexi.c 5.16 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: lexi.c,v 1.6 1998/05/22 05:15:12 deraadt Exp $";
+/*static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";*/
+static char rcsid[] = "$OpenBSD: lexi.c,v 1.7 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
/*
@@ -50,6 +51,7 @@ static char rcsid[] = "$OpenBSD: lexi.c,v 1.6 1998/05/22 05:15:12 deraadt Exp $"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
+#include <err.h>
#include "indent_globs.h"
#include "indent_codes.h"
@@ -125,7 +127,6 @@ int
lexi()
{
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' */
@@ -147,14 +148,13 @@ lexi()
}
/* Scan an alphanumeric token */
- if (chartype[*buf_ptr] == alphanum ||
+ if (chartype[(int)*buf_ptr] == alphanum ||
(buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) {
/*
* we have a character or number
*/
- register char *j; /* used for searching thru list of
- *
- * reserved words */
+ char *j; /* used for searching thru list of
+ * reserved words */
if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) {
int seendot = 0,
seenexp = 0,
@@ -170,14 +170,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 {
@@ -188,6 +189,7 @@ lexi()
if (*buf_ptr == '+' || *buf_ptr == '-')
*e_token++ = *buf_ptr++;
}
+ }
}
while (1) {
if (!(seensfx & 1) &&
@@ -210,7 +212,7 @@ lexi()
}
}
else
- while (chartype[*buf_ptr] == alphanum) { /* copy it over */
+ while (chartype[(int)*buf_ptr] == alphanum) { /* copy it over */
CHECK_SIZE_TOKEN;
*e_token++ = *buf_ptr++;
if (buf_ptr >= buf_end)
@@ -238,7 +240,7 @@ lexi()
* This loop will check if the token is a keyword.
*/
for (i = 0; i < nspecials; i++) {
- register char *p = s_token; /* point at scanned token */
+ char *p = s_token; /* point at scanned token */
j = specials[i].rwd;
if (*j++ != *p++ || *j++ != *p++)
continue; /* This test depends on the fact that
@@ -293,11 +295,11 @@ lexi()
} /* end of switch */
} /* end of if (found_it) */
if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
- register char *tp = buf_ptr;
+ char *tp = buf_ptr;
while (tp < buf_end)
if (*tp++ == ')' && (*tp == ';' || *tp == ','))
goto not_proc;
- strncpy(ps.procname, token, sizeof ps.procname - 1);
+ strlcpy(ps.procname, token, sizeof ps.procname);
ps.in_parameter_declaration = 1;
rparen_count = 1;
not_proc:;
@@ -568,7 +570,7 @@ addkey(key, val)
char *key;
int val;
{
- register struct templ *p;
+ struct templ *p;
int i = 0;
while (i < nspecials) {
@@ -588,15 +590,15 @@ addkey(key, val)
maxspecials += maxspecials >> 2;
specials = (struct templ *)malloc(maxspecials * sizeof specials[0]);
if (specials == NULL)
- errx(1, "indent: out of memory");
+ errx(1, "out of memory");
memmove(specials, specialsinit, sizeof specialsinit);
} else if (nspecials >= maxspecials) {
maxspecials += maxspecials >> 2;
specials = realloc(specials, maxspecials * sizeof specials[0]);
if (specials == NULL)
- errx(1, "indent: out of memory");
+ errx(1, "out of memory");
}
-
+
p = &specials[i];
p->rwd = key;
p->rwcode = val;
diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c
index cc9f46e9e2f..40f2e93d939 100644
--- a/usr.bin/indent/parse.c
+++ b/usr.bin/indent/parse.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: parse.c,v 1.3 1997/07/25 22:00:47 mickey Exp $ */
+/* $OpenBSD: parse.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $ */
/*
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
+ * Copyright (c) 1985 Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,8 +37,8 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)parse.c 5.12 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: parse.c,v 1.3 1997/07/25 22:00:47 mickey Exp $";
+/*static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";*/
+static char rcsid[] = "$OpenBSD: parse.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -211,12 +212,12 @@ parse(tk)
/*
* NAME: reduce
- *
+ *
* FUNCTION: Implements the reduce part of the parsing algorithm
- *
+ *
* ALGORITHM: The following reductions are done. Reductions are repeated
* until no more are possible.
- *
+ *
* Old TOS New TOS
* <stmt> <stmt> <stmtl>
* <stmtl> <stmt> <stmtl>
@@ -228,22 +229,22 @@ parse(tk)
* for <stmt> <stmt>
* while <stmt> <stmt>
* "dostmt" while <stmt>
- *
+ *
* On each reduction, ps.i_l_follow (the indentation for the following line)
* is set to the indentation level associated with the old TOS.
- *
+ *
* PARAMETERS: None
- *
+ *
* RETURNS: Nothing
- *
+ *
* GLOBALS: ps.cstk ps.i_l_follow = ps.il ps.p_stack = ps.tos =
- *
+ *
* CALLS: None
- *
+ *
* CALLED BY: parse
- *
+ *
* HISTORY: initial coding November 1976 D A Willcox of CAC
- *
+ *
*/
/*----------------------------------------------*\
| REDUCTION PHASE |
diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c
index e3c26ce2d39..9b43761c84e 100644
--- a/usr.bin/indent/pr_comment.c
+++ b/usr.bin/indent/pr_comment.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: pr_comment.c,v 1.3 1997/07/25 22:00:47 mickey Exp $ */
+/* $OpenBSD: pr_comment.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $ */
/*
- * Copyright (c) 1985 Sun Microsystems, Inc.
- * Copyright (c) 1980 The Regents of the University of California.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
+ * Copyright (c) 1985 Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,10 +37,11 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)pr_comment.c 5.12 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$OpenBSD: pr_comment.c,v 1.3 1997/07/25 22:00:47 mickey Exp $";
+/*static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93";*/
+static char rcsid[] = "$OpenBSD: pr_comment.c,v 1.4 2001/01/08 07:14:42 pjanzen Exp $";
#endif /* not lint */
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "indent_globs.h"
@@ -66,7 +68,7 @@ static char rcsid[] = "$OpenBSD: pr_comment.c,v 1.3 1997/07/25 22:00:47 mickey E
* 12/6/76 D A Willcox of CAC Modification to handle
* UNIX-style comments
*
- */
+ */
/*
* this routine processes comments. It makes an attempt to keep comments from
@@ -92,15 +94,15 @@ pr_comment()
int l_just_saw_decl = ps.just_saw_decl;
/*
* int ps.last_nl = 0; true iff the last significant thing
- * weve seen is a newline
+ * we've seen is a newline
*/
int one_liner = 1; /* true iff this comment is a one-liner */
adj_max_col = max_col;
ps.just_saw_decl = 0;
last_bl = 0; /* no blanks found so far */
ps.box_com = false; /* at first, assume that we are not in
- * a boxed comment or some other
- * comment that should not be touched */
+ * a boxed comment or some other
+ * comment that should not be touched */
++ps.out_coms; /* keep track of number of comments */
unix_comment = 1; /* set flag to let us figure out if there is a
* unix-style comment ** DISABLED: use 0 to
@@ -123,7 +125,7 @@ pr_comment()
if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) {
/* klg: check only if this line is blank */
/*
- * If this (*and previous lines are*) blank, dont put comment way
+ * If this (*and previous lines are*) blank, don't put comment way
* out at left
*/
ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
@@ -132,7 +134,7 @@ pr_comment()
ps.com_col = 1 + !format_col1_comments;
}
else {
- register target_col;
+ int target_col;
break_delim = 0;
if (s_code != e_code)
target_col = count_spaces(compute_code_target(), s_code);
@@ -210,7 +212,8 @@ pr_comment()
}
one_liner = 0;
if (ps.box_com || ps.last_nl) { /* if this is a boxed comment,
- * we dont ignore the newline */
+ * we don't ignore the newline
+ */
if (s_com == e_com) {
*e_com++ = ' ';
*e_com++ = ' ';