Conditionalize printfs instead of using conditional empty format

strings.
This commit is contained in:
joerg 2011-05-23 23:13:10 +00:00
parent 108836d4ba
commit a86027b1a0
2 changed files with 31 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: io.c,v 1.8 2005/06/26 19:10:49 christos Exp $ */
/* $NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
/*-
@ -32,7 +32,7 @@
#if 0
static char *rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
#else
__RCSID("$NetBSD: io.c,v 1.8 2005/06/26 19:10:49 christos Exp $");
__RCSID("$NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $");
#endif
#endif /* not lint */
@ -59,7 +59,8 @@ read_file(char *fn, long n)
sprintf(errmsg, "cannot close input file");
return ERR;
}
fprintf(stderr, !scripted ? "%lu\n" : "", size);
if (!scripted)
fprintf(stderr, "%lu\n", size);
return current_addr - n;
}
@ -165,7 +166,8 @@ write_file(const char *fn, const char *mode, long n, long m)
sprintf(errmsg, "cannot close output file");
return ERR;
}
fprintf(stderr, !scripted ? "%lu\n" : "", size);
if (!scripted)
fprintf(stderr, "%lu\n", size);
return n ? m - n + 1 : 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.22 2009/06/10 04:16:53 ginsbach Exp $ */
/* $NetBSD: main.c,v 1.23 2011/05/23 23:13:10 joerg Exp $ */
/* main.c: This file contains the main control and user-interface routines
for the ed line editor. */
@ -39,7 +39,7 @@ __COPYRIGHT(
#if 0
static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
#else
__RCSID("$NetBSD: main.c,v 1.22 2009/06/10 04:16:53 ginsbach Exp $");
__RCSID("$NetBSD: main.c,v 1.23 2011/05/23 23:13:10 joerg Exp $");
#endif
#endif /* not lint */
@ -200,9 +200,11 @@ top:
fputs("?\n", stderr);
sprintf(errmsg, "warning: file modified");
if (!isatty(0)) {
fprintf(stderr, garrulous ?
"script, line %d: %s\n" :
"", lineno, errmsg);
if (garrulous) {
fprintf(stderr,
"script, line %d: %s\n",
lineno, errmsg);
}
quit(2);
}
clearerr(stdin);
@ -233,27 +235,32 @@ top:
fputs("?\n", stderr); /* give warning */
sprintf(errmsg, "warning: file modified");
if (!isatty(0)) {
fprintf(stderr, garrulous ?
"script, line %d: %s\n" :
"", lineno, errmsg);
if (garrulous) {
fprintf(stderr,
"script, line %d: %s\n",
lineno, errmsg);
}
quit(2);
}
break;
case FATAL:
if (!isatty(0))
fprintf(stderr, garrulous ?
"script, line %d: %s\n" : "",
lineno, errmsg);
else
fprintf(stderr, garrulous ? "%s\n" : "",
errmsg);
if (garrulous) {
if (!isatty(0)) {
fprintf(stderr,
"script, line %d: %s\n",
lineno, errmsg);
} else {
fprintf(stderr, "%s\n", errmsg);
}
}
quit(3);
default:
fputs("?\n", stderr);
if (!isatty(0)) {
fprintf(stderr, garrulous ?
"script, line %d: %s\n" : "",
lineno, errmsg);
if (garrulous) {
fprintf(stderr, "script, line %d: %s\n",
lineno, errmsg);
}
quit(2);
}
break;