From: Peter Avalos Date: Fri, 6 Apr 2007 23:36:54 +0000 (+0000) Subject: Sync with FreeBSD. X-Git-Url: https://gitweb.dragonflybsd.org/~alexh/dragonfly.git/commitdiff_plain/dc8e4b6f39924cd54b380b2c807c1f80b6672a88 Sync with FreeBSD. File positions are off_t nowdays, not long, so: fseek -> fseeko Make errmsg a const, so we can just set error messages instead of using sprintf/strcpy. proper parens mean that fd is always set by open(2) [in any part of C], and so we can accurately check for it returning -1, without feeling like we need to initialize fd to -1 in its declaration. Remove some #ifdef sun. Sprinkle const. --- diff --git a/bin/ed/buf.c b/bin/ed/buf.c index 9b5af86c8a..53faf3f426 100644 --- a/bin/ed/buf.c +++ b/bin/ed/buf.c @@ -26,8 +26,8 @@ * SUCH DAMAGE. * * @(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp - * $FreeBSD: src/bin/ed/buf.c,v 1.17 1999/08/27 23:14:12 peter Exp $ - * $DragonFly: src/bin/ed/buf.c,v 1.3 2003/09/28 14:39:14 hmp Exp $ + * $FreeBSD: src/bin/ed/buf.c,v 1.22 2002/06/30 05:13:53 obrien Exp $ + * $DragonFly: src/bin/ed/buf.c,v 1.4 2007/04/06 23:36:54 pavalos Exp $ */ #include @@ -57,9 +57,9 @@ get_sbuf_line(line_t *lp) /* out of position */ if (sfseek != lp->seek) { sfseek = lp->seek; - if (fseek(sfp, sfseek, SEEK_SET) < 0) { + if (fseeko(sfp, sfseek, SEEK_SET) < 0) { fprintf(stderr, "%s\n", strerror(errno)); - sprintf(errmsg, "cannot seek temp file"); + errmsg = "cannot seek temp file"; return NULL; } } @@ -67,7 +67,7 @@ get_sbuf_line(line_t *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 */ @@ -78,41 +78,41 @@ get_sbuf_line(line_t *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 * -put_sbuf_line(char *cs) +const char * +put_sbuf_line(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; /* out of position */ if (seek_write) { - if (fseek(sfp, 0L, SEEK_END) < 0) { + if (fseeko(sfp, (off_t)0, 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); + sfseek = ftello(sfp); seek_write = 0; } /* assert: SPL1() */ 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; @@ -146,7 +146,7 @@ get_line_node_addr(line_t *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; @@ -192,7 +192,7 @@ char sfn[15] = ""; /* scratch file name */ int open_sbuf(void) { - int fd = -1; + int fd; int u; isbinary = newline_added = 0; @@ -203,7 +203,7 @@ open_sbuf(void) if (fd != -1) close(fd); perror(sfn); - strcpy(errmsg, "cannot open temp file"); + errmsg = "cannot open temp file"; umask(u); return ERR; } @@ -219,7 +219,7 @@ close_sbuf(void) 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 21562fa137..0c5a091b21 100644 --- a/bin/ed/cbc.c +++ b/bin/ed/cbc.c @@ -37,8 +37,8 @@ * from: @(#)bdes.c 5.5 (Berkeley) 6/27/91 * * @(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp - * $FreeBSD: src/bin/ed/cbc.c,v 1.12.2.1 2001/07/04 22:32:18 kris Exp $ - * $DragonFly: src/bin/ed/cbc.c,v 1.9 2007/04/06 21:33:28 pavalos Exp $ + * $FreeBSD: src/bin/ed/cbc.c,v 1.20 2004/04/06 20:06:47 markm Exp $ + * $DragonFly: src/bin/ed/cbc.c,v 1.10 2007/04/06 23:36:54 pavalos Exp $ */ #include @@ -198,7 +198,7 @@ get_keyword(void) void des_error(const char *s) { - sprintf(errmsg, "%s", s ? s : strerror(errno)); + errmsg = s ? s : strerror(errno); } /* @@ -233,6 +233,8 @@ hex_to_binary(int c, int radix) /* * convert the key to a bit pattern + * obuf bit pattern + * inbuf the key itself */ void expand_des_key(char *obuf, char *inbuf) @@ -365,6 +367,8 @@ cbc_encode(char *msgbuf, int n, FILE *fp) /* * This decrypts using the Cipher Block Chaining mode of DES + * msgbuf I/O buffer + * fp input file descriptor */ int cbc_decode(char *msgbuf, FILE *fp) diff --git a/bin/ed/ed.h b/bin/ed/ed.h index f4a12ddfed..78f26977ef 100644 --- a/bin/ed/ed.h +++ b/bin/ed/ed.h @@ -1,5 +1,5 @@ /* ed.h: type and constant definitions for the ed editor. */ -/* +/*- * Copyright (c) 1993 Andrew Moore * All rights reserved. * @@ -25,8 +25,8 @@ * SUCH DAMAGE. * * @(#)ed.h,v 1.5 1994/02/01 00:34:39 alm Exp - * $FreeBSD: src/bin/ed/ed.h,v 1.13.2.1 2001/08/01 02:36:03 obrien Exp $ - * $DragonFly: src/bin/ed/ed.h,v 1.8 2007/04/06 21:33:28 pavalos Exp $ + * $FreeBSD: src/bin/ed/ed.h,v 1.20 2005/01/10 08:39:22 imp Exp $ + * $DragonFly: src/bin/ed/ed.h,v 1.9 2007/04/06 23:36:54 pavalos Exp $ */ #include @@ -106,7 +106,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; \ } \ @@ -122,14 +122,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; \ } \ @@ -147,7 +147,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; \ } \ @@ -176,10 +176,6 @@ if ((i) > (n)) { \ /* NEWLINE_TO_NUL: overwrite newlines with ASCII NULs */ #define NEWLINE_TO_NUL(s, l) translit_text(s, l, '\n', '\0') -#ifdef sun -# define strerror(n) sys_errlist[n] -#endif - #ifdef ED_DES_INCLUDES void des_error(const char *); void expand_des_key(char *, char *); @@ -193,72 +189,72 @@ int get_des_char(FILE *); int put_des_char(int, FILE *); /* Local Function Declarations */ -void add_line_node (line_t *); -int append_lines (long); -int apply_subst_template (char *, regmatch_t *, int, int); -int build_active_list (int); -int cbc_decode (char *, FILE *); -int cbc_encode (char *, int, FILE *); -int check_addr_range (long, long); -void clear_active_list (void); -void clear_undo_stack (void); -int close_sbuf (void); -int copy_lines (long); -int delete_lines (long, long); -int display_lines (long, long, int); -line_t *dup_line_node (line_t *); -int exec_command (void); -long exec_global (int, int); -int extract_addr_range (void); -char *extract_pattern (int); -int extract_subst_tail (int *, long *); -char *extract_subst_template (void); -int filter_lines (long, long, char *); -line_t *get_addressed_line_node (long); -pattern_t *get_compiled_pattern (void); -char *get_extended_line (int *, int); -char *get_filename (void); -int get_keyword (void); -long get_line_node_addr (line_t *); -long get_matching_node_addr (pattern_t *, int); -long get_marked_node_addr (int); -char *get_sbuf_line (line_t *); -int get_shell_command (void); -int get_stream_line (FILE *); -int get_tty_line (void); -void handle_hup (int); -void handle_int (int); -void handle_winch (int); -int has_trailing_escape (char *, char *); -int hex_to_binary (int, int); -void init_buffers (void); -int is_legal_filename (char *); -int join_lines (long, long); -int mark_line_node (line_t *, int); -int move_lines (long); -line_t *next_active_node (void); -long next_addr (void); -int open_sbuf (void); -char *parse_char_class (char *); -int pop_undo_stack (void); -undo_t *push_undo_stack (int, long, long); -char *put_sbuf_line (char *); -int put_stream_line (FILE *, char *, int); -int put_tty_line (char *, int, long, int); -void quit (int); -long read_file (char *, long); -long read_stream (FILE *, long); -int search_and_replace (pattern_t *, int, int); -int set_active_node (line_t *); -void signal_hup (int); -void signal_int (int); -char *strip_escapes (const char *); -int substitute_matching_text (pattern_t *, line_t *, int, int); -char *translit_text (char *, int, int, int); -void unmark_line_node (line_t *); -void unset_active_nodes (line_t *, line_t *); -long write_file (const char *, const char *, long, long); -long write_stream (FILE *, long, long); +void add_line_node(line_t *); +int append_lines(long); +int apply_subst_template(const char *, regmatch_t *, int, int); +int build_active_list(int); +int cbc_decode(char *, FILE *); +int cbc_encode(char *, int, FILE *); +int check_addr_range(long, long); +void clear_active_list(void); +void clear_undo_stack(void); +int close_sbuf(void); +int copy_lines(long); +int delete_lines(long, long); +int display_lines(long, long, int); +line_t *dup_line_node(line_t *); +int exec_command(void); +long exec_global(int, int); +int extract_addr_range(void); +char *extract_pattern(int); +int extract_subst_tail(int *, long *); +char *extract_subst_template(void); +int filter_lines(long, long, char *); +line_t *get_addressed_line_node(long); +pattern_t *get_compiled_pattern(void); +char *get_extended_line(int *, int); +char *get_filename(void); +int get_keyword(void); +long get_line_node_addr(line_t *); +long get_matching_node_addr(pattern_t *, int); +long get_marked_node_addr(int); +char *get_sbuf_line(line_t *); +int get_shell_command(void); +int get_stream_line(FILE *); +int get_tty_line(void); +void handle_hup(int); +void handle_int(int); +void handle_winch(int); +int has_trailing_escape(char *, char *); +int hex_to_binary(int, int); +void init_buffers(void); +int is_legal_filename(char *); +int join_lines(long, long); +int mark_line_node(line_t *, int); +int move_lines(long); +line_t *next_active_node(void); +long next_addr(void); +int open_sbuf(void); +char *parse_char_class(char *); +int pop_undo_stack(void); +undo_t *push_undo_stack(int, long, long); +const char *put_sbuf_line(const char *); +int put_stream_line(FILE *, const char *, int); +int put_tty_line(const char *, int, long, int); +void quit(int); +long read_file(char *, long); +long read_stream(FILE *, long); +int search_and_replace(pattern_t *, int, int); +int set_active_node(line_t *); +void signal_hup(int); +void signal_int(int); +char *strip_escapes(const char *); +int substitute_matching_text(pattern_t *, line_t *, int, int); +char *translit_text(char *, int, int, int); +void unmark_line_node(line_t *); +void unset_active_nodes(line_t *, line_t *); +long write_file(const char *, const char *, long, long); +long write_stream(FILE *, long, long); /* global buffers */ extern char stdinbuf[]; @@ -275,13 +271,10 @@ extern int sigflags; /* global vars */ extern long addr_last; -extern long u_addr_last; extern long current_addr; -extern long u_current_addr; -extern char errmsg[]; +extern const char *errmsg; extern long first_addr; extern int lineno; extern long second_addr; -#ifdef sun -extern char *sys_errlist[]; -#endif +extern long u_addr_last; +extern long u_current_addr; diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c index fe14524d02..1219b09c1d 100644 --- a/bin/ed/glbl.c +++ b/bin/ed/glbl.c @@ -26,8 +26,8 @@ * SUCH DAMAGE. * * @(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp - * $FreeBSD: src/bin/ed/glbl.c,v 1.9.2.1 2001/01/23 14:38:31 asmodai Exp $ - * $DragonFly: src/bin/ed/glbl.c,v 1.3 2003/09/28 14:39:14 hmp Exp $ + * $FreeBSD: src/bin/ed/glbl.c,v 1.13 2002/06/30 05:13:53 obrien Exp $ + * $DragonFly: src/bin/ed/glbl.c,v 1.4 2007/04/06 23:36:54 pavalos Exp $ */ #include @@ -49,7 +49,7 @@ build_active_list(int 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; @@ -107,13 +107,13 @@ exec_global(int interact, int 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) @@ -157,7 +157,7 @@ set_active_node(line_t *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; } @@ -166,7 +166,7 @@ set_active_node(line_t *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 90435e758a..d638d4f988 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -25,8 +25,8 @@ * SUCH DAMAGE. * * @(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp - * $FreeBSD: src/bin/ed/io.c,v 1.10 1999/08/27 23:14:14 peter Exp $ - * $DragonFly: src/bin/ed/io.c,v 1.5 2004/10/30 13:34:49 liamfoy Exp $ + * $FreeBSD: src/bin/ed/io.c,v 1.14 2003/01/01 18:48:39 schweikh Exp $ + * $DragonFly: src/bin/ed/io.c,v 1.6 2007/04/06 23:36:54 pavalos Exp $ */ #include "ed.h" @@ -45,13 +45,13 @@ read_file(char *fn, long 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); @@ -132,7 +132,7 @@ get_stream_line(FILE *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'; @@ -153,13 +153,13 @@ write_file(const char *fn, const char *mode, long n, long 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); @@ -198,18 +198,18 @@ write_stream(FILE *fp, long n, long m) /* put_stream_line: write a line of text to a stream; return status */ int -put_stream_line(FILE *fp, char *s, int len) +put_stream_line(FILE *fp, 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; } -/* get_extended_line: get a an extended line from stdin */ +/* get_extended_line: get an extended line from stdin */ char * get_extended_line(int *sizep, int nonl) { @@ -234,7 +234,7 @@ get_extended_line(int *sizep, int 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); @@ -275,7 +275,7 @@ get_tty_line(void) 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; @@ -302,7 +302,7 @@ extern int cols; /* put_tty_line: print text to stdout */ int -put_tty_line(char *s, int l, long n, int gflag) +put_tty_line(const char *s, int l, long n, int gflag) { int col = 0; int lc = 0; diff --git a/bin/ed/main.c b/bin/ed/main.c index b99b749869..2c2f1ea5ee 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -27,8 +27,8 @@ * * @(#) Copyright (c) 1993 Andrew Moore, Talke Studio. All rights reserved. * @(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp - * $FreeBSD: src/bin/ed/main.c,v 1.14.2.4 2001/08/01 02:36:03 obrien Exp $ - * $DragonFly: src/bin/ed/main.c,v 1.8 2005/03/09 02:38:51 drhodus Exp $ + * $FreeBSD: src/bin/ed/main.c,v 1.29 2006/08/17 23:00:33 imp Exp $ + * $DragonFly: src/bin/ed/main.c,v 1.9 2007/04/06 23:36:54 pavalos Exp $ */ /* @@ -93,11 +93,11 @@ int lineno; /* script line number */ const char *prompt; /* command-line prompt */ const char *dps = "*"; /* default command-line prompt */ -const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n"; +const char usage[] = "usage: %s [-] [-sx] [-p string] [file]\n"; /* ed: line editor */ int -main(int argc, char **argv) +main(int argc, char *argv[]) { int c, n; long status = 0; @@ -122,14 +122,13 @@ top: case 'x': /* use crypt */ #ifdef DES des = get_keyword(); - break; #else fprintf(stderr, "crypt unavailable\n?\n"); #endif break; default: - fprintf(stderr, usage, argv[0]); + fprintf(stderr, usage, red ? "red" : "ed"); exit(1); } argv += optind; @@ -158,7 +157,7 @@ top: #endif { fputs("\n?\n", stderr); - sprintf(errmsg, "interrupt"); + errmsg = "interrupt"; } else { init_buffers(); sigactive = 1; /* enable signal handlers */ @@ -172,7 +171,7 @@ top: } else if (argc) { fputs("?\n", stderr); if (**argv == '\0') - sprintf(errmsg, "invalid filename"); + errmsg = "invalid filename"; if (!isatty(0)) quit(2); } @@ -190,7 +189,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" : @@ -205,7 +204,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; @@ -223,7 +222,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" : @@ -282,14 +281,18 @@ extract_addr_range(void) #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(void) { - char *hd; + const char *hd; long addr = current_addr; long n; int first = 1; @@ -348,12 +351,12 @@ next_addr(void) addr = addr_last; break; } - /* FALL THROUGH */ + /* FALLTHROUGH */ default: if (ibufp == hd) return EOF; else if (addr < 0 || addr_last < addr) { - sprintf(errmsg, "invalid address"); + errmsg = "invalid address"; return ERR; } else return addr; @@ -372,10 +375,10 @@ next_addr(void) 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; \ @@ -391,7 +394,7 @@ next_addr(void) 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; \ @@ -419,7 +422,7 @@ next_addr(void) } \ } while (!done); \ if (*ibufp++ != '\n') { \ - sprintf(errmsg, "invalid command suffix"); \ + errmsg = "invalid command suffix"; \ return ERR; \ } \ } @@ -482,13 +485,13 @@ exec_command(void) case 'e': if (modified && !scripted) return EMOD; - /* fall through */ + /* FALLTHROUGH */ 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; @@ -503,7 +506,7 @@ exec_command(void) 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 @@ -515,15 +518,15 @@ exec_command(void) 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(); @@ -535,7 +538,7 @@ exec_command(void) 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; @@ -549,7 +552,7 @@ exec_command(void) break; case 'h': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -557,7 +560,7 @@ exec_command(void) break; case 'H': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -566,7 +569,7 @@ exec_command(void) break; case 'i': if (second_addr == 0) { - sprintf(errmsg, "invalid address"); + errmsg = "invalid address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -586,7 +589,7 @@ exec_command(void) case 'k': c = *ibufp++; if (second_addr == 0) { - sprintf(errmsg, "invalid address"); + errmsg = "invalid address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -606,7 +609,7 @@ exec_command(void) 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(); @@ -632,7 +635,7 @@ exec_command(void) break; case 'P': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -641,7 +644,7 @@ exec_command(void) case 'q': case 'Q': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -649,7 +652,7 @@ exec_command(void) 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; @@ -661,7 +664,7 @@ exec_command(void) strcpy(old_filename, fnp); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { - sprintf(errmsg, "no current filename"); + errmsg = "no current filename"; return ERR; } #endif @@ -696,18 +699,18 @@ exec_command(void) 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; @@ -768,7 +771,7 @@ exec_command(void) break; case 'u': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); @@ -782,7 +785,7 @@ exec_command(void) 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; @@ -795,7 +798,7 @@ exec_command(void) strcpy(old_filename, fnp); #ifdef BACKWARDS if (*fnp == '\0' && *old_filename == '\0') { - sprintf(errmsg, "no current filename"); + errmsg = "no current filename"; return ERR; } #endif @@ -809,14 +812,15 @@ exec_command(void) break; case 'x': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } GET_COMMAND_SUFFIX(); #ifdef DES des = get_keyword(); + break; #else - sprintf(errmsg, "crypt unavailable"); + errmsg = "crypt unavailable"; return ERR; #endif case 'z': @@ -840,7 +844,7 @@ exec_command(void) break; case '!': if (addr_cnt > 0) { - sprintf(errmsg, "unexpected address"); + errmsg = "unexpected address"; return ERR; } else if ((sflags = get_shell_command()) < 0) return ERR; @@ -859,7 +863,7 @@ exec_command(void) return ERR; break; default: - sprintf(errmsg, "unknown command"); + errmsg = "unknown command"; return ERR; } return gflag; @@ -876,7 +880,7 @@ check_addr_range(long n, long m) } if (first_addr > second_addr || 1 > first_addr || second_addr > addr_last) { - sprintf(errmsg, "invalid address"); + errmsg = "invalid address"; return ERR; } return 0; @@ -905,7 +909,7 @@ get_matching_node_addr(pattern_t *pat, int dir) return n; } } while (n != current_addr); - sprintf(errmsg, "no match"); + errmsg = "no match"; return ERR; } @@ -922,7 +926,7 @@ get_filename(void) 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; @@ -934,13 +938,13 @@ get_filename(void) 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 @@ -965,7 +969,7 @@ get_shell_command(void) 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; @@ -990,7 +994,7 @@ get_shell_command(void) else if (shcmd == NULL) #endif { - sprintf(errmsg, "no previous command"); + errmsg = "no previous command"; return ERR; } else { REALLOC(buf, n, i + shcmdi, ERR); @@ -1001,7 +1005,7 @@ get_shell_command(void) break; case '%': if (*old_filename == '\0') { - sprintf(errmsg, "no current filename"); + errmsg = "no current filename"; return ERR; } j = strlen(s = strip_escapes(old_filename)); @@ -1024,8 +1028,8 @@ int append_lines(long n) { int l; - char *lp = ibuf; - char *eot; + const char *lp = ibuf; + const char *eot; undo_t *up = NULL; for (current_addr = n;;) { @@ -1219,7 +1223,7 @@ display_lines(long from, long to, int gflag) char *s; if (!from) { - sprintf(errmsg, "invalid address"); + errmsg = "invalid address"; return ERR; } ep = get_addressed_line_node(INC_MOD(to, addr_last)); @@ -1244,7 +1248,7 @@ int mark_line_node(line_t *lp, 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++; @@ -1258,7 +1262,7 @@ long get_marked_node_addr(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']); @@ -1287,7 +1291,7 @@ dup_line_node(line_t *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; @@ -1347,12 +1351,13 @@ handle_hup(int 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) { @@ -1403,7 +1408,7 @@ int is_legal_filename(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 b9c1c480a7..7205bacdc1 100644 --- a/bin/ed/re.c +++ b/bin/ed/re.c @@ -26,8 +26,8 @@ * SUCH DAMAGE. * * @(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp - * $FreeBSD: src/bin/ed/re.c,v 1.15.2.1 2001/08/01 02:36:03 obrien Exp $ - * $DragonFly: src/bin/ed/re.c,v 1.3 2003/09/28 14:39:14 hmp Exp $ + * $FreeBSD: src/bin/ed/re.c,v 1.20 2003/07/20 10:24:09 ru Exp $ + * $DragonFly: src/bin/ed/re.c,v 1.4 2007/04/06 23:36:54 pavalos Exp $ */ #include "ed.h" @@ -35,42 +35,45 @@ extern int patlock; -char errmsg[PATH_MAX + 40] = ""; +const char *errmsg = ""; /* get_compiled_pattern: return pointer to compiled pattern from command buffer */ pattern_t * get_compiled_pattern(void) { - static pattern_t *exp = NULL; + static pattern_t *expr = NULL; + static char error[1024]; - char *exps; + char *exprs; 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"); - return exp; - } else if ((exps = extract_pattern(delimiter)) == NULL) + if (!expr) + errmsg = "no previous pattern"; + return expr; + } else if ((exprs = extract_pattern(delimiter)) == NULL) return NULL; /* buffer alloc'd && not reserved */ - if (exp && !patlock) - regfree(exp); - else if ((exp = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) { + if (expr && !patlock) + regfree(expr); + else if ((expr = (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); - free(exp); - return exp = NULL; + if ((n = regcomp(expr, exprs, 0))) { + regerror(n, expr, error, sizeof error); + errmsg = error; + free(expr); + return expr = NULL; } - return exp; + return expr; } @@ -91,13 +94,13 @@ extract_pattern(int 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 eccb17a1ad..26a725ad28 100644 --- a/bin/ed/sub.c +++ b/bin/ed/sub.c @@ -26,8 +26,8 @@ * SUCH DAMAGE. * * @(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp - * $FreeBSD: src/bin/ed/sub.c,v 1.12 1999/08/27 23:14:15 peter Exp $ - * $DragonFly: src/bin/ed/sub.c,v 1.3 2003/09/28 14:39:14 hmp Exp $ + * $FreeBSD: src/bin/ed/sub.c,v 1.15 2002/06/30 05:13:53 obrien Exp $ + * $DragonFly: src/bin/ed/sub.c,v 1.4 2007/04/06 23:36:54 pavalos Exp $ */ #include "ed.h" @@ -79,7 +79,8 @@ extract_subst_template(void) if (*ibufp == '%' && *(ibufp + 1) == delimiter) { ibufp++; - if (!rhbuf) sprintf(errmsg, "no previous substitution"); + if (!rhbuf) + errmsg = "no previous substitution"; return rhbuf; } while (*ibufp != delimiter) { @@ -114,8 +115,8 @@ int search_and_replace(pattern_t *pat, int gflag, int kth) { undo_t *up; - char *txt; - char *eot; + const char *txt; + const char *eot; long lc; long xa = current_addr; int nsubs = 0; @@ -153,7 +154,7 @@ search_and_replace(pattern_t *pat, int gflag, int 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) @@ -208,7 +209,7 @@ substitute_matching_text(pattern_t *pat, line_t *lp, int gflag, int 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) @@ -223,7 +224,7 @@ substitute_matching_text(pattern_t *pat, line_t *lp, int gflag, int kth) /* apply_subst_template: modify text according to a substitution template; return offset to end of modified text */ int -apply_subst_template(char *boln, regmatch_t *rm, int off, int re_nsub) +apply_subst_template(const char *boln, regmatch_t *rm, int off, int re_nsub) { int j = 0; int k = 0; diff --git a/bin/ed/undo.c b/bin/ed/undo.c index f82193a350..08475b366e 100644 --- a/bin/ed/undo.c +++ b/bin/ed/undo.c @@ -25,8 +25,8 @@ * SUCH DAMAGE. * * @(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp - * $FreeBSD: src/bin/ed/undo.c,v 1.9 1999/08/27 23:14:15 peter Exp $ - * $DragonFly: src/bin/ed/undo.c,v 1.3 2003/09/28 14:39:14 hmp Exp $ + * $FreeBSD: src/bin/ed/undo.c,v 1.12 2002/06/30 05:13:53 obrien Exp $ + * $DragonFly: src/bin/ed/undo.c,v 1.4 2007/04/06 23:36:54 pavalos Exp $ */ #include "ed.h" @@ -47,7 +47,7 @@ push_undo_stack(int type, long from, long 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 @@ -62,7 +62,7 @@ push_undo_stack(int type, long from, long 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; @@ -90,7 +90,7 @@ pop_undo_stack(void) 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;