summaryrefslogtreecommitdiffstats
path: root/bin/ed
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2001-08-06 22:01:31 +0000
committermike <mike@FreeBSD.org>2001-08-06 22:01:31 +0000
commiteced21209cdad6cf4ff64c6008b71b45a226d905 (patch)
tree0469fc49295a48c1140722bbff569214e2135f58 /bin/ed
parente7f429490d285f94132046b59db80b6d1fe253c4 (diff)
downloadFreeBSD-src-eced21209cdad6cf4ff64c6008b71b45a226d905.zip
FreeBSD-src-eced21209cdad6cf4ff64c6008b71b45a226d905.tar.gz
o Correctly define rcsid.
o Add consts where appropriate. o Rename some variables that were shadowing global declarations. o Remove register storage-classes. o Make errmsg a const, so we can just set error messages instead of using sprintf/strcpy. o Set WARNS=2 Reviewed by: bde, des
Diffstat (limited to 'bin/ed')
-rw-r--r--bin/ed/Makefile1
-rw-r--r--bin/ed/buf.c30
-rw-r--r--bin/ed/cbc.c52
-rw-r--r--bin/ed/ed.h24
-rw-r--r--bin/ed/glbl.c16
-rw-r--r--bin/ed/io.c36
-rw-r--r--bin/ed/main.c127
-rw-r--r--bin/ed/re.c23
-rw-r--r--bin/ed/sub.c19
-rw-r--r--bin/ed/undo.c12
10 files changed, 158 insertions, 182 deletions
diff --git a/bin/ed/Makefile b/bin/ed/Makefile
index 95901a6..93d5ee0 100644
--- a/bin/ed/Makefile
+++ b/bin/ed/Makefile
@@ -2,6 +2,7 @@
PROG= ed
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
+WARNS?= 2
LINKS= ${BINDIR}/ed ${BINDIR}/red
MLINKS= ed.1 red.1
diff --git a/bin/ed/buf.c b/bin/ed/buf.c
index 4e24796..fb23e5a 100644
--- a/bin/ed/buf.c
+++ b/bin/ed/buf.c
@@ -27,12 +27,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include <sys/file.h>
@@ -65,7 +61,7 @@ get_sbuf_line(lp)
sfseek = lp->seek;
if (fseek(sfp, sfseek, SEEK_SET) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot seek temp file");
+ errmsg = "cannot seek temp file";
return NULL;
}
}
@@ -73,7 +69,7 @@ get_sbuf_line(lp)
REALLOC(sfbuf, sfbufsz, len + 1, NULL);
if ((ct = fread(sfbuf, sizeof(char), len, sfp)) < 0 || ct != len) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot read temp file");
+ errmsg = "cannot read temp file";
return NULL;
}
sfseek += len; /* update file position */
@@ -84,24 +80,24 @@ get_sbuf_line(lp)
/* put_sbuf_line: write a line of text to the scratch file and add a line node
to the editor buffer; return a pointer to the end of the text */
-char *
+const char *
put_sbuf_line(cs)
- char *cs;
+ const char *cs;
{
line_t *lp;
int len, ct;
- char *s;
+ const char *s;
if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
return NULL;
}
/* assert: cs is '\n' terminated */
for (s = cs; *s != '\n'; s++)
;
if (s - cs >= LINECHARS) {
- sprintf(errmsg, "line too long");
+ errmsg = "line too long";
return NULL;
}
len = s - cs;
@@ -109,7 +105,7 @@ put_sbuf_line(cs)
if (seek_write) {
if (fseek(sfp, 0L, SEEK_END) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot seek temp file");
+ errmsg = "cannot seek temp file";
return NULL;
}
sfseek = ftell(sfp);
@@ -119,7 +115,7 @@ put_sbuf_line(cs)
if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
sfseek = -1;
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot write temp file");
+ errmsg = "cannot write temp file";
return NULL;
}
lp->len = len;
@@ -155,7 +151,7 @@ get_line_node_addr(lp)
while (cp != lp && (cp = cp->q_forw) != &buffer_head)
n++;
if (n && cp == &buffer_head) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
}
return n;
@@ -213,7 +209,7 @@ open_sbuf()
if (fd != -1)
close(fd);
perror(sfn);
- strcpy(errmsg, "cannot open temp file");
+ errmsg = "cannot open temp file";
umask(u);
return ERR;
}
@@ -229,7 +225,7 @@ close_sbuf()
if (sfp) {
if (fclose(sfp) < 0) {
fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
- sprintf(errmsg, "cannot close temp file");
+ errmsg = "cannot close temp file";
return ERR;
}
sfp = NULL;
diff --git a/bin/ed/cbc.c b/bin/ed/cbc.c
index 8ac0cd2..24b0385 100644
--- a/bin/ed/cbc.c
+++ b/bin/ed/cbc.c
@@ -33,17 +33,11 @@
* 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.
- *
- * from: @(#)bdes.c 5.5 (Berkeley) 6/27/91
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include <sys/types.h>
@@ -183,7 +177,7 @@ flush_des_file(fp)
int
get_keyword()
{
- register char *p; /* used to obtain the key */
+ char *p; /* used to obtain the key */
Desbuf msgbuf; /* I/O buffer */
/*
@@ -209,9 +203,9 @@ get_keyword()
*/
void
des_error(s)
- char *s; /* the message */
+ const char *s; /* the message */
{
- (void)sprintf(errmsg, "%s", s ? s : strerror(errno));
+ errmsg = s ? s : strerror(errno);
}
/*
@@ -250,23 +244,23 @@ hex_to_binary(c, radix)
* convert the key to a bit pattern
*/
void
-expand_des_key(obuf, ibuf)
+expand_des_key(obuf, kbuf)
char *obuf; /* bit pattern */
- char *ibuf; /* the key itself */
+ char *kbuf; /* the key itself */
{
- register int i, j; /* counter in a for loop */
+ int i, j; /* counter in a for loop */
int nbuf[64]; /* used for hex/key translation */
/*
* leading '0x' or '0X' == hex key
*/
- if (ibuf[0] == '0' && (ibuf[1] == 'x' || ibuf[1] == 'X')) {
- ibuf = &ibuf[2];
+ if (kbuf[0] == '0' && (kbuf[1] == 'x' || kbuf[1] == 'X')) {
+ kbuf = &kbuf[2];
/*
* now translate it, bombing on any illegal hex digit
*/
- for (i = 0; ibuf[i] && i < 16; i++)
- if ((nbuf[i] = hex_to_binary((int) ibuf[i], 16)) == -1)
+ for (i = 0; kbuf[i] && i < 16; i++)
+ if ((nbuf[i] = hex_to_binary((int) kbuf[i], 16)) == -1)
des_error("bad hex digit in key");
while (i < 16)
nbuf[i++] = 0;
@@ -280,13 +274,13 @@ expand_des_key(obuf, ibuf)
/*
* leading '0b' or '0B' == binary key
*/
- if (ibuf[0] == '0' && (ibuf[1] == 'b' || ibuf[1] == 'B')) {
- ibuf = &ibuf[2];
+ if (kbuf[0] == '0' && (kbuf[1] == 'b' || kbuf[1] == 'B')) {
+ kbuf = &kbuf[2];
/*
* now translate it, bombing on any illegal binary digit
*/
- for (i = 0; ibuf[i] && i < 16; i++)
- if ((nbuf[i] = hex_to_binary((int) ibuf[i], 2)) == -1)
+ for (i = 0; kbuf[i] && i < 16; i++)
+ if ((nbuf[i] = hex_to_binary((int) kbuf[i], 2)) == -1)
des_error("bad binary digit in key");
while (i < 64)
nbuf[i++] = 0;
@@ -300,7 +294,7 @@ expand_des_key(obuf, ibuf)
/*
* no special leader -- ASCII
*/
- (void)strncpy(obuf, ibuf, 8);
+ (void)strncpy(obuf, kbuf, 8);
}
/*****************
@@ -321,8 +315,8 @@ void
set_des_key(buf)
Desbuf buf; /* key block */
{
- register int i, j; /* counter in a for loop */
- register int par; /* parity counter */
+ int i, j; /* counter in a for loop */
+ int par; /* parity counter */
/*
* if the parity is not preserved, flip it
@@ -391,20 +385,20 @@ cbc_decode(msgbuf, fp)
char *msgbuf; /* I/O buffer */
FILE *fp; /* input file descriptor */
{
- Desbuf ibuf; /* temp buffer for initialization vector */
- register int n; /* number of bytes actually read */
- register int c; /* used to test for EOF */
+ Desbuf tbuf; /* temp buffer for initialization vector */
+ int n; /* number of bytes actually read */
+ int c; /* used to test for EOF */
int inverse = 1; /* 0 to encrypt, 1 to decrypt */
if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) {
/*
* do the transformation
*/
- MEMCPY(BUFFER(ibuf), BUFFER(msgbuf), 8);
+ MEMCPY(BUFFER(tbuf), BUFFER(msgbuf), 8);
DES_XFORM(UBUFFER(msgbuf));
for (c = 0; c < 8; c++)
UCHAR(msgbuf, c) ^= UCHAR(ivec, c);
- MEMCPY(BUFFER(ivec), BUFFER(ibuf), 8);
+ MEMCPY(BUFFER(ivec), BUFFER(tbuf), 8);
/*
* if the last one, handle it specially
*/
diff --git a/bin/ed/ed.h b/bin/ed/ed.h
index 34cd276..ad9c38f 100644
--- a/bin/ed/ed.h
+++ b/bin/ed/ed.h
@@ -105,7 +105,7 @@ if (--mutex == 0) { \
#define STRTOL(i, p) { \
if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
errno == ERANGE) { \
- sprintf(errmsg, "number out of range"); \
+ errmsg = "number out of range"; \
i = 0; \
return ERR; \
} \
@@ -121,14 +121,14 @@ if ((i) > (n)) { \
if ((b) != NULL) { \
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
- sprintf(errmsg, "out of memory"); \
+ errmsg = "out of memory"; \
SPL0(); \
return err; \
} \
} else { \
if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
- sprintf(errmsg, "out of memory"); \
+ errmsg = "out of memory"; \
SPL0(); \
return err; \
} \
@@ -146,7 +146,7 @@ if ((i) > (n)) { \
SPL1(); \
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
- sprintf(errmsg, "out of memory"); \
+ errmsg = "out of memory"; \
SPL0(); \
return err; \
} \
@@ -190,7 +190,7 @@ if ((i) > (n)) { \
/* Local Function Declarations */
void add_line_node __P((line_t *));
int append_lines __P((long));
-int apply_subst_template __P((char *, regmatch_t *, int, int));
+int apply_subst_template __P((const char *, regmatch_t *, int, int));
int build_active_list __P((int));
int cbc_decode __P((char *, FILE *));
int cbc_encode __P((char *, int, FILE *));
@@ -200,7 +200,7 @@ void clear_undo_stack __P((void));
int close_sbuf __P((void));
int copy_lines __P((long));
int delete_lines __P((long, long));
-void des_error __P((char *));
+void des_error __P((const char *));
int display_lines __P((long, long, int));
line_t *dup_line_node __P((line_t *));
int exec_command __P((void));
@@ -236,16 +236,16 @@ int is_legal_filename __P((char *));
int join_lines __P((long, long));
int mark_line_node __P((line_t *, int));
int move_lines __P((long));
-line_t *next_active_node __P(());
+line_t *next_active_node __P((void));
long next_addr __P((void));
int open_sbuf __P((void));
char *parse_char_class __P((char *));
int pop_undo_stack __P((void));
undo_t *push_undo_stack __P((int, long, long));
int put_des_char __P((int, FILE *));
-char *put_sbuf_line __P((char *));
-int put_stream_line __P((FILE *, char *, int));
-int put_tty_line __P((char *, int, long, int));
+const char *put_sbuf_line __P((const char *));
+int put_stream_line __P((FILE *, const char *, int));
+int put_tty_line __P((const char *, int, long, int));
void quit __P((int));
long read_file __P((char *, long));
long read_stream __P((FILE *, long));
@@ -259,7 +259,7 @@ int substitute_matching_text __P((pattern_t *, line_t *, int, int));
char *translit_text __P((char *, int, int, int));
void unmark_line_node __P((line_t *));
void unset_active_nodes __P((line_t *, line_t *));
-long write_file __P((char *, char *, long, long));
+long write_file __P((char *, const char *, long, long));
long write_stream __P((FILE *, long, long));
/* global buffers */
@@ -278,7 +278,7 @@ extern int sigflags;
/* global vars */
extern long addr_last;
extern long current_addr;
-extern char errmsg[];
+extern const char *errmsg;
extern long first_addr;
extern int lineno;
extern long second_addr;
diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c
index 081c5a9..163f170 100644
--- a/bin/ed/glbl.c
+++ b/bin/ed/glbl.c
@@ -27,12 +27,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include <sys/types.h>
@@ -55,7 +51,7 @@ build_active_list(isgcmd)
char delimiter;
if ((delimiter = *ibufp) == ' ' || delimiter == '\n') {
- sprintf(errmsg, "invalid pattern delimiter");
+ errmsg = "invalid pattern delimiter";
return ERR;
} else if ((pat = get_compiled_pattern()) == NULL)
return ERR;
@@ -115,13 +111,13 @@ exec_global(interact, gflag)
if (n < 0)
return ERR;
else if (n == 0) {
- sprintf(errmsg, "unexpected end-of-file");
+ errmsg = "unexpected end-of-file";
return ERR;
} else if (n == 1 && !strcmp(ibuf, "\n"))
continue;
else if (n == 2 && !strcmp(ibuf, "&\n")) {
if (cmd == NULL) {
- sprintf(errmsg, "no previous command");
+ errmsg = "no previous command";
return ERR;
} else cmd = ocmd;
} else if ((cmd = get_extended_line(&n, 0)) == NULL)
@@ -166,7 +162,7 @@ set_active_node(lp)
if ((ts = (line_t **) realloc(active_list,
(ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
SPL0();
return ERR;
}
@@ -175,7 +171,7 @@ set_active_node(lp)
if ((ts = (line_t **) malloc((ti += MINBUFSZ) *
sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
SPL0();
return ERR;
}
diff --git a/bin/ed/io.c b/bin/ed/io.c
index 2030798..47d0502 100644
--- a/bin/ed/io.c
+++ b/bin/ed/io.c
@@ -26,12 +26,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include "ed.h"
@@ -52,13 +48,13 @@ read_file(fn, n)
fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
- sprintf(errmsg, "cannot open input file");
+ errmsg = "cannot open input file";
return ERR;
} else if ((size = read_stream(fp, n)) < 0)
return ERR;
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
- sprintf(errmsg, "cannot close input file");
+ errmsg = "cannot close input file";
return ERR;
}
fprintf(stdout, !scripted ? "%lu\n" : "", size);
@@ -128,8 +124,8 @@ int
get_stream_line(fp)
FILE *fp;
{
- register int c;
- register int i = 0;
+ int c;
+ int i = 0;
while (((c = des ? get_des_char(fp) : getc(fp)) != EOF || (!feof(fp) &&
!ferror(fp))) && c != '\n') {
@@ -142,7 +138,7 @@ get_stream_line(fp)
sbuf[i++] = c;
else if (ferror(fp)) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot read input file");
+ errmsg = "cannot read input file";
return ERR;
} else if (i) {
sbuf[i++] = '\n';
@@ -157,7 +153,7 @@ get_stream_line(fp)
long
write_file(fn, mode, n, m)
char *fn;
- char *mode;
+ const char *mode;
long n;
long m;
{
@@ -167,13 +163,13 @@ write_file(fn, mode, n, m)
fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
- sprintf(errmsg, "cannot open output file");
+ errmsg = "cannot open output file";
return ERR;
} else if ((size = write_stream(fp, n, m)) < 0)
return ERR;
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
- sprintf(errmsg, "cannot close output file");
+ errmsg = "cannot close output file";
return ERR;
}
fprintf(stdout, !scripted ? "%lu\n" : "", size);
@@ -217,13 +213,13 @@ write_stream(fp, n, m)
int
put_stream_line(fp, s, len)
FILE *fp;
- char *s;
+ const char *s;
int len;
{
while (len--)
if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "cannot write file");
+ errmsg = "cannot write file";
return ERR;
}
return 0;
@@ -256,7 +252,7 @@ get_extended_line(sizep, nonl)
if ((n = get_tty_line()) < 0)
return NULL;
else if (n == 0 || ibuf[n - 1] != '\n') {
- sprintf(errmsg, "unexpected end-of-file");
+ errmsg = "unexpected end-of-file";
return NULL;
}
REALLOC(cvbuf, cvbufsz, l + n, NULL);
@@ -278,8 +274,8 @@ get_extended_line(sizep, nonl)
int
get_tty_line()
{
- register int oi = 0;
- register int i = 0;
+ int oi = 0;
+ int i = 0;
int c;
for (;;)
@@ -297,7 +293,7 @@ get_tty_line()
case EOF:
if (ferror(stdin)) {
fprintf(stderr, "stdin: %s\n", strerror(errno));
- sprintf(errmsg, "cannot read stdin");
+ errmsg = "cannot read stdin";
clearerr(stdin);
ibufp = NULL;
return ERR;
@@ -325,7 +321,7 @@ extern int cols;
/* put_tty_line: print text to stdout */
int
put_tty_line(s, l, n, gflag)
- char *s;
+ const char *s;
int l;
long n;
int gflag;
diff --git a/bin/ed/main.c b/bin/ed/main.c
index bb651e5..220dbc8 100644
--- a/bin/ed/main.c
+++ b/bin/ed/main.c
@@ -27,18 +27,14 @@
*/
#ifndef lint
-static char * const copyright =
+static const char copyright[] =
"@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
/*
@@ -100,8 +96,8 @@ char old_filename[PATH_MAX] = ""; /* default filename */
long current_addr; /* current address in editor buffer */
long addr_last; /* last address in editor buffer */
int lineno; /* script line number */
-char *prompt; /* command-line prompt */
-char *dps = "*"; /* default command-line prompt */
+const char *prompt; /* command-line prompt */
+const char *dps = "*"; /* default command-line prompt */
const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
@@ -169,7 +165,7 @@ top:
#endif
{
fputs("\n?\n", stderr);
- sprintf(errmsg, "interrupt");
+ errmsg = "interrupt";
} else {
init_buffers();
sigactive = 1; /* enable signal handlers */
@@ -183,7 +179,7 @@ top:
} else if (argc) {
fputs("?\n", stderr);
if (**argv == '\0')
- sprintf(errmsg, "invalid filename");
+ errmsg = "invalid filename";
if (!isatty(0))
quit(2);
}
@@ -201,7 +197,7 @@ top:
} else if (n == 0) {
if (modified && !scripted) {
fputs("?\n", stderr);
- sprintf(errmsg, "warning: file modified");
+ errmsg = "warning: file modified";
if (!isatty(0)) {
fprintf(stderr, garrulous ?
"script, line %d: %s\n" :
@@ -216,7 +212,7 @@ top:
quit(0);
} else if (ibuf[n - 1] != '\n') {
/* discard line */
- sprintf(errmsg, "unexpected end-of-file");
+ errmsg = "unexpected end-of-file";
clearerr(stdin);
status = ERR;
continue;
@@ -234,7 +230,7 @@ top:
case EMOD:
modified = 0;
fputs("?\n", stderr); /* give warning */
- sprintf(errmsg, "warning: file modified");
+ errmsg = "warning: file modified";
if (!isatty(0)) {
fprintf(stderr, garrulous ?
"script, line %d: %s\n" :
@@ -293,14 +289,18 @@ extract_addr_range()
#define SKIP_BLANKS() while (isspace((unsigned char)*ibufp) && *ibufp != '\n') ibufp++
-#define MUST_BE_FIRST() \
- if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
+#define MUST_BE_FIRST() do { \
+ if (!first) { \
+ errmsg = "invalid address"; \
+ return ERR; \
+ } \
+} while (0);
/* next_addr: return the next line address in the command buffer */
long
next_addr()
{
- char *hd;
+ const char *hd;
long addr = current_addr;
long n;
int first = 1;
@@ -364,7 +364,7 @@ next_addr()
if (ibufp == hd)
return EOF;
else if (addr < 0 || addr_last < addr) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
} else
return addr;
@@ -383,10 +383,10 @@ next_addr()
if (extract_addr_range() < 0) \
return ERR; \
else if (addr_cnt == 0) { \
- sprintf(errmsg, "destination expected"); \
+ errmsg = "destination expected"; \
return ERR; \
} else if (second_addr < 0 || addr_last < second_addr) { \
- sprintf(errmsg, "invalid address"); \
+ errmsg = "invalid address"; \
return ERR; \
} \
addr = second_addr; \
@@ -402,7 +402,7 @@ next_addr()
if (extract_addr_range() < 0) \
return ERR; \
if (second_addr < 0 || addr_last < second_addr) { \
- sprintf(errmsg, "invalid address"); \
+ errmsg = "invalid address"; \
return ERR; \
} \
addr = second_addr; \
@@ -430,7 +430,7 @@ next_addr()
} \
} while (!done); \
if (*ibufp++ != '\n') { \
- sprintf(errmsg, "invalid command suffix"); \
+ errmsg = "invalid command suffix"; \
return ERR; \
} \
}
@@ -499,10 +499,10 @@ exec_command()
/* fall through */
case 'E':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
} else if (!isspace((unsigned char)*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ errmsg = "unexpected command suffix";
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
@@ -517,7 +517,7 @@ exec_command()
if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
- sprintf(errmsg, "no current filename");
+ errmsg = "no current filename";
return ERR;
}
#endif
@@ -529,15 +529,15 @@ exec_command()
break;
case 'f':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
} else if (!isspace((unsigned char)*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ errmsg = "unexpected command suffix";
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
else if (*fnp == '!') {
- sprintf(errmsg, "invalid redirection");
+ errmsg = "invalid redirection";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -549,7 +549,7 @@ exec_command()
case 'G':
case 'V':
if (isglobal) {
- sprintf(errmsg, "cannot nest global commands");
+ errmsg = "cannot nest global commands";
return ERR;
} else if (check_addr_range(1, addr_last) < 0)
return ERR;
@@ -563,7 +563,7 @@ exec_command()
break;
case 'h':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -571,7 +571,7 @@ exec_command()
break;
case 'H':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -580,7 +580,7 @@ exec_command()
break;
case 'i':
if (second_addr == 0) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -600,7 +600,7 @@ exec_command()
case 'k':
c = *ibufp++;
if (second_addr == 0) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -620,7 +620,7 @@ exec_command()
return ERR;
GET_THIRD_ADDR(addr);
if (first_addr <= addr && addr < second_addr) {
- sprintf(errmsg, "invalid destination");
+ errmsg = "invalid destination";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -646,7 +646,7 @@ exec_command()
break;
case 'P':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -655,7 +655,7 @@ exec_command()
case 'q':
case 'Q':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -663,7 +663,7 @@ exec_command()
break;
case 'r':
if (!isspace((unsigned char)*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ errmsg = "unexpected command suffix";
return ERR;
} else if (addr_cnt == 0)
second_addr = addr_last;
@@ -675,7 +675,7 @@ exec_command()
strcpy(old_filename, fnp);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
- sprintf(errmsg, "no current filename");
+ errmsg = "no current filename";
return ERR;
}
#endif
@@ -710,18 +710,18 @@ exec_command()
break;
default:
if (sflags) {
- sprintf(errmsg, "invalid command suffix");
+ errmsg = "invalid command suffix";
return ERR;
}
}
} while (sflags && *ibufp != '\n');
if (sflags && !pat) {
- sprintf(errmsg, "no previous substitution");
+ errmsg = "no previous substitution";
return ERR;
} else if (sflags & SGG)
sgnum = 0; /* override numeric arg */
if (*ibufp != '\n' && *(ibufp + 1) == '\n') {
- sprintf(errmsg, "invalid pattern delimiter");
+ errmsg = "invalid pattern delimiter";
return ERR;
}
tpat = pat;
@@ -782,7 +782,7 @@ exec_command()
break;
case 'u':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
@@ -796,7 +796,7 @@ exec_command()
ibufp++;
}
if (!isspace((unsigned char)*ibufp)) {
- sprintf(errmsg, "unexpected command suffix");
+ errmsg = "unexpected command suffix";
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
@@ -809,7 +809,7 @@ exec_command()
strcpy(old_filename, fnp);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
- sprintf(errmsg, "no current filename");
+ errmsg = "no current filename";
return ERR;
}
#endif
@@ -823,14 +823,14 @@ exec_command()
break;
case 'x':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
}
GET_COMMAND_SUFFIX();
#ifdef DES
des = get_keyword();
#else
- sprintf(errmsg, "crypt unavailable");
+ errmsg = "crypt unavailable";
return ERR;
#endif
break;
@@ -855,7 +855,7 @@ exec_command()
break;
case '!':
if (addr_cnt > 0) {
- sprintf(errmsg, "unexpected address");
+ errmsg = "unexpected address";
return ERR;
} else if ((sflags = get_shell_command()) < 0)
return ERR;
@@ -874,7 +874,7 @@ exec_command()
return ERR;
break;
default:
- sprintf(errmsg, "unknown command");
+ errmsg = "unknown command";
return ERR;
}
return gflag;
@@ -892,7 +892,7 @@ check_addr_range(n, m)
}
if (first_addr > second_addr || 1 > first_addr ||
second_addr > addr_last) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
}
return 0;
@@ -923,7 +923,7 @@ get_matching_node_addr(pat, dir)
return n;
}
} while (n != current_addr);
- sprintf(errmsg, "no match");
+ errmsg = "no match";
return ERR;
}
@@ -940,7 +940,7 @@ get_filename()
if (*ibufp != '\n') {
SKIP_BLANKS();
if (*ibufp == '\n') {
- sprintf(errmsg, "invalid filename");
+ errmsg = "invalid filename";
return NULL;
} else if ((ibufp = get_extended_line(&n, 1)) == NULL)
return NULL;
@@ -952,13 +952,13 @@ get_filename()
printf("%s\n", shcmd + 1);
return shcmd;
} else if (n > PATH_MAX - 1) {
- sprintf(errmsg, "filename too long");
+ errmsg = "filename too long";
return NULL;
}
}
#ifndef BACKWARDS
else if (*old_filename == '\0') {
- sprintf(errmsg, "no current filename");
+ errmsg = "no current filename";
return NULL;
}
#endif
@@ -983,7 +983,7 @@ get_shell_command()
int j = 0;
if (red) {
- sprintf(errmsg, "shell access restricted");
+ errmsg = "shell access restricted";
return ERR;
} else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
return ERR;
@@ -1008,7 +1008,7 @@ get_shell_command()
else if (shcmd == NULL)
#endif
{
- sprintf(errmsg, "no previous command");
+ errmsg = "no previous command";
return ERR;
} else {
REALLOC(buf, n, i + shcmdi, ERR);
@@ -1019,7 +1019,7 @@ get_shell_command()
break;
case '%':
if (*old_filename == '\0') {
- sprintf(errmsg, "no current filename");
+ errmsg = "no current filename";
return ERR;
}
j = strlen(s = strip_escapes(old_filename));
@@ -1043,8 +1043,8 @@ append_lines(n)
long n;
{
int l;
- char *lp = ibuf;
- char *eot;
+ const char *lp = ibuf;
+ const char *eot;
undo_t *up = NULL;
for (current_addr = n;;) {
@@ -1246,7 +1246,7 @@ display_lines(from, to, gflag)
char *s;
if (!from) {
- sprintf(errmsg, "invalid address");
+ errmsg = "invalid address";
return ERR;
}
ep = get_addressed_line_node(INC_MOD(to, addr_last));
@@ -1273,7 +1273,7 @@ mark_line_node(lp, n)
int n;
{
if (!islower((unsigned char)n)) {
- sprintf(errmsg, "invalid mark character");
+ errmsg = "invalid mark character";
return ERR;
} else if (mark[n - 'a'] == NULL)
markno++;
@@ -1288,7 +1288,7 @@ get_marked_node_addr(n)
int n;
{
if (!islower((unsigned char)n)) {
- sprintf(errmsg, "invalid mark character");
+ errmsg = "invalid mark character";
return ERR;
}
return get_line_node_addr(mark[n - 'a']);
@@ -1319,7 +1319,7 @@ dup_line_node(lp)
if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
return NULL;
}
np->seek = lp->seek;
@@ -1385,12 +1385,13 @@ handle_hup(signo)
{
char *hup = NULL; /* hup filename */
char *s;
+ char ed_hup[] = "ed.hup";
int n;
if (!sigactive)
quit(1);
sigflags &= ~(1 << (signo - 1));
- if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
+ if (addr_last && write_file(ed_hup, "w", 1, addr_last) < 0 &&
(s = getenv("HOME")) != NULL &&
(n = strlen(s)) + 8 <= PATH_MAX && /* "ed.hup" + '/' */
(hup = (char *) malloc(n + 10)) != NULL) {
@@ -1444,7 +1445,7 @@ is_legal_filename(s)
char *s;
{
if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
- sprintf(errmsg, "shell access restricted");
+ errmsg = "shell access restricted";
return 0;
}
return 1;
diff --git a/bin/ed/re.c b/bin/ed/re.c
index 523e2a4..52dacdc 100644
--- a/bin/ed/re.c
+++ b/bin/ed/re.c
@@ -27,12 +27,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include "ed.h"
@@ -40,7 +36,7 @@ static char * const rcsid =
extern int patlock;
-char errmsg[PATH_MAX + 40] = "";
+const char *errmsg = "";
/* get_compiled_pattern: return pointer to compiled pattern from command
buffer */
@@ -48,16 +44,18 @@ pattern_t *
get_compiled_pattern()
{
static pattern_t *exp = NULL;
+ static char error[1024];
char *exps;
char delimiter;
int n;
if ((delimiter = *ibufp) == ' ') {
- sprintf(errmsg, "invalid pattern delimiter");
+ errmsg = "invalid pattern delimiter";
return NULL;
} else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) {
- if (!exp) sprintf(errmsg, "no previous pattern");
+ if (!exp)
+ errmsg = "no previous pattern";
return exp;
} else if ((exps = extract_pattern(delimiter)) == NULL)
return NULL;
@@ -66,12 +64,13 @@ get_compiled_pattern()
regfree(exp);
else if ((exp = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
return NULL;
}
patlock = 0;
if ((n = regcomp(exp, exps, 0))) {
- regerror(n, exp, errmsg, sizeof errmsg);
+ regerror(n, exp, error, sizeof error);
+ errmsg = error;
free(exp);
return exp = NULL;
}
@@ -97,13 +96,13 @@ extract_pattern(delimiter)
break;
case '[':
if ((nd = parse_char_class(++nd)) == NULL) {
- sprintf(errmsg, "unbalanced brackets ([])");
+ errmsg = "unbalanced brackets ([])";
return NULL;
}
break;
case '\\':
if (*++nd == '\n') {
- sprintf(errmsg, "trailing backslash (\\)");
+ errmsg = "trailing backslash (\\)";
return NULL;
}
break;
diff --git a/bin/ed/sub.c b/bin/ed/sub.c
index 3221373..1d53848 100644
--- a/bin/ed/sub.c
+++ b/bin/ed/sub.c
@@ -27,12 +27,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include "ed.h"
@@ -86,7 +82,8 @@ extract_subst_template()
if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
ibufp++;
- if (!rhbuf) sprintf(errmsg, "no previous substitution");
+ if (!rhbuf)
+ errmsg = "no previous substitution";
return rhbuf;
}
while (*ibufp != delimiter) {
@@ -124,8 +121,8 @@ search_and_replace(pat, gflag, kth)
int kth;
{
undo_t *up;
- char *txt;
- char *eot;
+ const char *txt;
+ const char *eot;
long lc;
long xa = current_addr;
int nsubs = 0;
@@ -163,7 +160,7 @@ search_and_replace(pat, gflag, kth)
}
current_addr = xa;
if (nsubs == 0 && !(gflag & GLB)) {
- sprintf(errmsg, "no match");
+ errmsg = "no match";
return ERR;
} else if ((gflag & (GPR | GLS | GNP)) &&
display_lines(current_addr, current_addr, gflag) < 0)
@@ -222,7 +219,7 @@ substitute_matching_text(pat, lp, gflag, kth)
i = eot - txt;
REALLOC(rbuf, rbufsz, off + i + 2, ERR);
if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) {
- sprintf(errmsg, "infinite substitution loop");
+ errmsg = "infinite substitution loop";
return ERR;
}
if (isbinary)
@@ -238,7 +235,7 @@ substitute_matching_text(pat, lp, gflag, kth)
return offset to end of modified text */
int
apply_subst_template(boln, rm, off, re_nsub)
- char *boln;
+ const char *boln;
regmatch_t *rm;
int off;
int re_nsub;
diff --git a/bin/ed/undo.c b/bin/ed/undo.c
index b2063c7..8feb381 100644
--- a/bin/ed/undo.c
+++ b/bin/ed/undo.c
@@ -26,12 +26,8 @@
*/
#ifndef lint
-#if 0
-static char * const rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp";
-#else
-static char * const rcsid =
+static const char rcsid[] =
"$FreeBSD$";
-#endif
#endif /* not lint */
#include "ed.h"
@@ -55,7 +51,7 @@ push_undo_stack(type, from, to)
if (ustack == NULL &&
(ustack = (undo_t *) malloc((usize = USIZE) * sizeof(undo_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
return NULL;
}
#endif
@@ -70,7 +66,7 @@ push_undo_stack(type, from, to)
}
/* out of memory - release undo stack */
fprintf(stderr, "%s\n", strerror(errno));
- sprintf(errmsg, "out of memory");
+ errmsg = "out of memory";
clear_undo_stack();
free(ustack);
ustack = NULL;
@@ -98,7 +94,7 @@ pop_undo_stack()
long o_addr_last = addr_last;
if (u_current_addr == -1 || u_addr_last == -1) {
- sprintf(errmsg, "nothing to undo");
+ errmsg = "nothing to undo";
return ERR;
} else if (u_p)
modified = 1;
OpenPOWER on IntegriCloud