summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2006-10-09 00:23:58 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2006-10-09 00:23:58 +0000
commit3732eb3f0c0befa9bd4971d43fe9014683618dd7 (patch)
treeb50c3571243730bef77592440a5cccc7badbbd51
parentb29db7291c1ecef2e19f2582a2eebec69a25e687 (diff)
pretty. the comma operator should not be used to cram two statements into
an if without braces, or worse, into a return.
-rw-r--r--usr.bin/sed/compile.c58
-rw-r--r--usr.bin/sed/main.c9
-rw-r--r--usr.bin/sed/misc.c9
-rw-r--r--usr.bin/sed/process.c29
4 files changed, 55 insertions, 50 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index a47bc3ed09b..20f33f82a30 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: compile.c,v 1.21 2005/04/11 07:11:44 deraadt Exp $ */
+/* $OpenBSD: compile.c,v 1.22 2006/10/09 00:23:56 tedu Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -35,7 +35,7 @@
#ifndef lint
/* from: static char sccsid[] = "@(#)compile.c 8.2 (Berkeley) 4/28/95"; */
-static char *rcsid = "$OpenBSD: compile.c,v 1.21 2005/04/11 07:11:44 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: compile.c,v 1.22 2006/10/09 00:23:56 tedu Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -183,10 +183,12 @@ semicolon: EATSPACE();
cmd->a2 = xmalloc(sizeof(struct s_addr));
p = compile_addr(p, cmd->a2);
EATSPACE();
- } else
+ } else {
cmd->a2 = 0;
- } else
+ }
+ } else {
cmd->a1 = cmd->a2 = 0;
+ }
nonsel: /* Now parse the command */
if (!*p)
@@ -199,7 +201,8 @@ nonsel: /* Now parse the command */
err(COMPILE, "invalid command code %c", *p);
if (naddr > fp->naddr)
err(COMPILE,
-"command %c expects up to %d address(es), found %d", *p, fp->naddr, naddr);
+ "command %c expects up to %d address(es), found %d",
+ *p, fp->naddr, naddr);
switch (fp->args) {
case NONSEL: /* ! */
p++;
@@ -243,13 +246,13 @@ nonsel: /* Now parse the command */
p++;
EATSPACE();
if (*p != '\\')
- err(COMPILE,
-"command %c expects \\ followed by text", cmd->code);
+ err(COMPILE, "command %c expects \\ followed by"
+ " text", cmd->code);
p++;
EATSPACE();
if (*p)
- err(COMPILE,
-"extra characters after \\ at the end of %c command", cmd->code);
+ err(COMPILE, "extra characters after \\ at the"
+ " end of %c command", cmd->code);
cmd->t = compile_text();
break;
case COMMENT: /* \0 # */
@@ -299,8 +302,8 @@ nonsel: /* Now parse the command */
case SUBST: /* s */
p++;
if (*p == '\0' || *p == '\\')
- err(COMPILE,
-"substitute pattern can not be delimited by newline or backslash");
+ err(COMPILE, "substitute pattern can not be"
+ " delimited by newline or backslash");
cmd->u.s = xmalloc(sizeof(struct s_subst));
p = compile_re(p, &cmd->u.s->re);
if (p == NULL)
@@ -325,8 +328,8 @@ nonsel: /* Now parse the command */
goto semicolon;
}
if (*p)
- err(COMPILE,
-"extra text at the end of a transform command");
+ err(COMPILE, "extra text at the end of a"
+ " transform command");
break;
}
}
@@ -360,15 +363,15 @@ compile_delimited(char *p, char *d)
continue;
} else if (*p == '\\' && p[1] == '[') {
*d++ = *p++;
- } else if (*p == '\\' && p[1] == c)
+ } else if (*p == '\\' && p[1] == c) {
p++;
- else if (*p == '\\' && p[1] == 'n') {
+ } else if (*p == '\\' && p[1] == 'n') {
*d++ = '\n';
p += 2;
continue;
- } else if (*p == '\\' && p[1] == '\\')
+ } else if (*p == '\\' && p[1] == '\\') {
*d++ = *p++;
- else if (*p == c) {
+ } else if (*p == c) {
*d = '\0';
return (p + 1);
}
@@ -396,9 +399,16 @@ compile_ccl(char **sp, char *t)
for (c = *s; (*t = *s) != ']' || c != d; s++, t++)
if ((c = *s) == '\0')
return NULL;
- } else if (*s == '\\' && s[1] == 'n')
- *t = '\n', s++;
- return (*s == ']') ? *sp = ++s, ++t : NULL;
+ } else if (*s == '\\' && s[1] == 'n') {
+ *t = '\n';
+ s++;
+ }
+ if (*s == ']') {
+ *sp = ++s;
+ return (++t);
+ } else {
+ return (NULL);
+ }
}
/*
@@ -529,8 +539,8 @@ compile_flags(char *p, struct s_subst *s)
switch (*p) {
case 'g':
if (gn)
- err(COMPILE,
-"more than one number or 'g' in substitute flags");
+ err(COMPILE, "more than one number or 'g' in"
+ " substitute flags");
gn = 1;
s->n = 0;
break;
@@ -545,8 +555,8 @@ compile_flags(char *p, struct s_subst *s)
case '4': case '5': case '6':
case '7': case '8': case '9':
if (gn)
- err(COMPILE,
-"more than one number or 'g' in substitute flags");
+ err(COMPILE, "more than one number or 'g' in"
+ " substitute flags");
gn = 1;
l = strtol(p, &p, 10);
if (l <= 0 || l >= INT_MAX)
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 214d0a7acca..5479917fd71 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.9 2003/06/10 22:20:50 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.10 2006/10/09 00:23:57 tedu Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -34,14 +34,11 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
/* from: static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94"; */
-static char *rcsid = "$OpenBSD: main.c,v 1.9 2003/06/10 22:20:50 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: main.c,v 1.10 2006/10/09 00:23:57 tedu Exp $";
#endif /* not lint */
#include <sys/types.h>
diff --git a/usr.bin/sed/misc.c b/usr.bin/sed/misc.c
index 18fee03a552..ba6055d31a2 100644
--- a/usr.bin/sed/misc.c
+++ b/usr.bin/sed/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.6 2004/07/20 03:50:26 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.7 2006/10/09 00:23:57 tedu Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -35,7 +35,7 @@
#ifndef lint
/* from: static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; */
-static char *rcsid = "$OpenBSD: misc.c,v 1.6 2004/07/20 03:50:26 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: misc.c,v 1.7 2006/10/09 00:23:57 tedu Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -69,8 +69,6 @@ xmalloc(u_int size)
void *
xrealloc(void *p, u_int size)
{
- if (p == NULL) /* Compatibility hack. */
- return (xmalloc(size));
if ((p = realloc(p, size)) == NULL)
err(FATAL, "%s", strerror(errno));
@@ -88,8 +86,7 @@ strregerror(int errcode, regex_t *preg)
static char *oe;
size_t s;
- if (oe != NULL)
- free(oe);
+ free(oe);
s = regerror(errcode, preg, "", 0);
oe = xmalloc(s);
(void)regerror(errcode, preg, oe, s);
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 9aa2da86c80..9d83e6d0c56 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process.c,v 1.12 2003/11/07 02:58:23 tedu Exp $ */
+/* $OpenBSD: process.c,v 1.13 2006/10/09 00:23:57 tedu Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -35,7 +35,7 @@
#ifndef lint
/* from: static char sccsid[] = "@(#)process.c 8.1 (Berkeley) 6/6/93"; */
-static char *rcsid = "$OpenBSD: process.c,v 1.12 2003/11/07 02:58:23 tedu Exp $";
+static const char rcsid[] = "$OpenBSD: process.c,v 1.13 2006/10/09 00:23:57 tedu Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -81,7 +81,7 @@ static regex_t *defpreg;
size_t maxnsub;
regmatch_t *match;
-#define OUT(s) { fwrite(s, sizeof(u_char), psl, stdout); }
+#define OUT(s) do { fwrite(s, sizeof(u_char), psl, stdout); } while (0)
void
process(void)
@@ -163,7 +163,7 @@ redirect:
break;
case 'n':
if (!nflag && !pd)
- OUT(ps)
+ OUT(ps);
flush_appends();
if (!mf_fgets(&PS, REPLACE))
exit(0);
@@ -173,14 +173,14 @@ redirect:
flush_appends();
if (!mf_fgets(&PS, 0)) {
if (!nflag && !pd)
- OUT(ps)
+ OUT(ps);
exit(0);
}
break;
case 'p':
if (pd)
break;
- OUT(ps)
+ OUT(ps);
break;
case 'P':
if (pd)
@@ -190,13 +190,13 @@ redirect:
oldpsl = psl;
psl = (p + 1) - ps;
}
- OUT(ps)
+ OUT(ps);
if (p != NULL)
psl = oldpsl;
break;
case 'q':
if (!nflag && !pd)
- OUT(ps)
+ OUT(ps);
flush_appends();
exit(0);
case 'r':
@@ -254,7 +254,7 @@ redirect:
} /* for all cp */
new: if (!nflag && !pd)
- OUT(ps)
+ OUT(ps);
flush_appends();
} /* for all lines */
}
@@ -303,7 +303,7 @@ applies(struct s_command *cp)
r = 0;
else
r = MATCH(cp->a1);
- return (cp->nonsel ? ! r : r);
+ return (cp->nonsel ? !r : r);
}
/*
@@ -404,7 +404,7 @@ substitute(struct s_command *cp)
/* Handle the 'p' flag. */
if (cp->u.s->p)
- OUT(ps)
+ OUT(ps);
/* Handle the 'w' flag. */
if (cp->u.s->wfile && !pd) {
@@ -463,7 +463,7 @@ lputs(char *s)
struct winsize win;
static int termwidth = -1;
- if (termwidth == -1)
+ if (termwidth == -1) {
if ((p = getenv("COLUMNS")))
termwidth = atoi(p);
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
@@ -471,6 +471,7 @@ lputs(char *s)
termwidth = win.ws_col;
else
termwidth = 60;
+ }
for (count = 0; *s; ++s) {
if (count >= termwidth) {
@@ -518,7 +519,7 @@ regexec_e(regex_t *preg, const char *string, int eflags,
eval = regexec(defpreg, string,
nomatch ? 0 : maxnsub + 1, match, eflags | REG_STARTEND);
- switch(eval) {
+ switch (eval) {
case 0:
return (1);
case REG_NOMATCH:
@@ -606,7 +607,7 @@ cfclose(struct s_command *cp, struct s_command *end)
{
for (; cp != end; cp = cp->next)
- switch(cp->code) {
+ switch (cp->code) {
case 's':
if (cp->u.s->wfd != -1 && close(cp->u.s->wfd))
err(FATAL,