Subject: bin/13963: bin/ed with corrected style
To: None <gnats-bugs@gnats.netbsd.org>
From: Petri Koistinen <thoron@mb-u07ip065.mbnet.fi>
List: netbsd-bugs
Date: 09/16/2001 02:48:54
>Number:         13963
>Category:       bin
>Synopsis:       bin/ed with corrected style
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 15 16:49:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Petri Koistinen
>Release:        NetBSD-current Sun Sep 16 02:45:46 EEST 2001
>Organization:
>Environment:
System: NetBSD mb-u07ip065.mbnet.fi 1.5X NetBSD 1.5X (DING-DONG) #1: Sun Sep 16 03:33:42 EEST 2001 thoron@legoland:/usr/src/sys/arch/amiga/compile/DING-DONG amiga
Architecture: m68k
Machine: amiga
>Description:
	Please apply attached patches for bin/ed.
>How-To-Repeat:
>Fix:
Index: buf.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/buf.c,v
retrieving revision 1.21
diff -u -r1.21 buf.c
--- buf.c	2000/04/17 23:37:50	1.21
+++ buf.c	2001/09/15 23:39:32
@@ -1,4 +1,4 @@
-/*	$NetBSD: buf.c,v 1.21 2000/04/17 23:37:50 christos Exp $	*/
+/* $NetBSD: buf.c,v 1.21 2000/04/17 23:37:50 christos Exp $ */
 
 /* buf.c: This file contains the scratch-file buffer rountines for the
    ed line editor. */
@@ -55,13 +55,12 @@
 /* get_sbuf_line: get a line of text from the scratch file; return pointer
    to the text */
 char *
-get_sbuf_line(lp)
-	line_t *lp;
+get_sbuf_line(line_t *lp)
 {
 	static char *sfbuf = NULL;	/* buffer */
 	static int sfbufsz = 0;		/* buffer size */
 
-	int len, ct;
+	int ct, len;
 
 	if (lp == &buffer_head)
 		return NULL;
@@ -91,11 +90,10 @@
 /* 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(cs)
-	char *cs;
+put_sbuf_line(char *cs)
 {
 	line_t *lp;
-	int len, ct;
+	int ct, len;
 	char *s;
 
 	if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
@@ -138,12 +136,11 @@
 
 /* add_line_node: add a line node in the editor buffer after the current line */
 void
-add_line_node(lp)
-	line_t *lp;
+add_line_node(line_t *lp)
 {
 	line_t *cp;
 
-	cp = get_addressed_line_node(current_addr);				/* this get_addressed_line_node last! */
+	cp = get_addressed_line_node(current_addr);	/* this get_addressed_line_node last! */
 	INSQUE(lp, cp);
 	addr_last++;
 	current_addr++;
@@ -152,12 +149,14 @@
 
 /* get_line_node_addr: return line number of pointer */
 long
-get_line_node_addr(lp)
-	line_t *lp;
+get_line_node_addr(line_t *lp)
 {
-	line_t *cp = &buffer_head;
-	long n = 0;
+	line_t *cp;
+	long n;
 
+	cp = &buffer_head;
+	n = 0;
+
 	while (cp != lp && (cp = cp->q_forw) != &buffer_head)
 		n++;
 	if (n && cp == &buffer_head) {
@@ -170,8 +169,7 @@
 
 /* get_addressed_line_node: return pointer to a line node in the editor buffer */
 line_t *
-get_addressed_line_node(n)
-	long n;
+get_addressed_line_node(long n)
 {
 	static line_t *lp = &buffer_head;
 	static long on = 0;
@@ -205,7 +203,7 @@
 
 /* open_sbuf: open scratch file */
 int
-open_sbuf()
+open_sbuf(void)
 {
 	int u, fd;
 	char *tmp;
@@ -238,7 +236,7 @@
 
 /* close_sbuf: close scratch file */
 int
-close_sbuf()
+close_sbuf(void)
 {
 	if (sfp) {
 		if (fclose(sfp) < 0) {
@@ -260,8 +258,7 @@
 
 /* quit: remove_lines scratch file and exit */
 void
-quit(n)
-	int n;
+quit(int n)
 {
 	if (sfp) {
 		fclose(sfp);
@@ -280,10 +277,12 @@
 
 /* init_buffers: open scratch buffer; initialize line queue */
 void
-init_buffers()
+init_buffers(void)
 {
-	int i = 0;
+	int i;
 
+	i = 0;
+
 	/* Read stdin one character at a time to avoid i/o contention 
 	   with shell escapes invoked by nonterminal input, e.g.,
 	   ed - <<EOF
@@ -301,11 +300,7 @@
 
 /* translit_text: translate characters in a string */
 char *
-translit_text(s, len, from, to)
-	char *s;
-	int len;
-	int from;
-	int to;
+translit_text(char *s, int len, int from, int to)
 {
 	static int i = 0;
 
Index: cbc.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/cbc.c,v
retrieving revision 1.13
diff -u -r1.13 cbc.c
--- cbc.c	1998/07/28 05:46:20	1.13
+++ cbc.c	2001/09/15 23:39:34
@@ -1,4 +1,4 @@
-/*	$NetBSD: cbc.c,v 1.13 1998/07/28 05:46:20 mycroft Exp $	*/
+/* $NetBSD: cbc.c,v 1.13 1998/07/28 05:46:20 mycroft Exp $ */
 
 /* cbc.c: This file contains the encryption routines for the ed line editor */
 /*-
@@ -119,7 +119,7 @@
 
 /* init_des_cipher: initialize DES */
 void
-init_des_cipher()
+init_des_cipher(void)
 {
 #ifdef DES
 	int i;
@@ -139,8 +139,7 @@
 
 /* get_des_char: return next char in an encrypted file */
 int
-get_des_char(fp)
-	FILE *fp;
+get_des_char(FILE *fp)
 {
 #ifdef DES
 	if (des_n >= des_ct) {
@@ -156,9 +155,7 @@
 
 /* put_des_char: write a char to an encrypted file; return char written */
 int
-put_des_char(c, fp)
-	int c;
-	FILE *fp;
+put_des_char(int c, FILE *fp)
 {
 #ifdef DES
 	if (des_n == sizeof des_buf) {
@@ -174,8 +171,7 @@
 
 /* flush_des_file: flush an encrypted file's output; return status */
 int
-flush_des_file(fp)
-	FILE *fp;
+flush_des_file(FILE *fp)
 {
 #ifdef DES
 	if (des_n == sizeof des_buf) {
@@ -193,7 +189,7 @@
  * get keyword from tty or stdin
  */
 int
-get_keyword()
+get_keyword(void)
 {
 	char *p;		/* used to obtain the key */
 	Desbuf msgbuf;			/* I/O buffer */
@@ -220,8 +216,9 @@
  * print a warning message and, possibly, terminate
  */
 void
-des_error(s)
-	char *s;		/* the message */
+des_error(
+	char *s			/* the message */
+)
 {
 	(void)sprintf(errmsg, "%s", s ? s : strerror(errno));
 }
@@ -230,9 +227,10 @@
  * map a hex character to an integer
  */
 int
-hex_to_binary(c, radix)
-	int c;			/* char to be converted */
-	int radix;		/* base (2 to 16) */
+hex_to_binary(
+	int c,			/* char to be converted */
+	int radix		/* base (2 to 16) */
+)
 {
 	switch(c) {
 	case '0':		return(0x0);
@@ -262,9 +260,10 @@
  * convert the key to a bit pattern
  */
 void
-expand_des_key(obuf, ibuf)
-	char *obuf;			/* bit pattern */
-	char *ibuf;			/* the key itself */
+expand_des_key(
+	char *obuf,			/* bit pattern */
+	char *ibuf			/* the key itself */
+)
 {
 	int i, j;			/* counter in a for loop */
 	int nbuf[64];			/* used for hex/key translation */
@@ -330,8 +329,9 @@
  * DES ignores the low order bit of each character.
  */
 void
-set_des_key(buf)
-	Desbuf buf;				/* key block */
+set_des_key(
+	Desbuf buf				/* key block */
+)
 {
 	int i, j;				/* counter in a for loop */
 	int par;				/* parity counter */
@@ -360,13 +360,11 @@
  * This encrypts using the Cipher Block Chaining mode of DES
  */
 int
-cbc_encode(msgbuf, n, fp)
-	char *msgbuf;
-	int n;
-	FILE *fp;
+cbc_encode(char *msgbuf, int n, FILE *fp)
 {
-	int inverse = 0;	/* 0 to encrypt, 1 to decrypt */
+	int inverse;
 
+	inverse = 0;        /* 0 to encrypt, 1 to decrypt */
 	/*
 	 * do the transformation
 	 */
@@ -399,14 +397,17 @@
  * This decrypts using the Cipher Block Chaining mode of DES
  */
 int
-cbc_decode(msgbuf, fp)
-	char *msgbuf;		/* I/O buffer */
-	FILE *fp;			/* input file descriptor */
-{
-	Desbuf ibuf;	/* 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 */
+cbc_decode(
+	char *msgbuf,		/* I/O buffer */
+	FILE *fp		/* input file descriptor */
+)
+{
+	Desbuf ibuf;		/* temp buffer for initialization vector */
+	int n;			/* number of bytes actually read */
+	int c;			/* used to test for EOF */
+	int inverse;
+
+	inverse = 1;		/* 0 to encrypt, 1 to decrypt */
 
 	if ((n = READ(BUFFER(msgbuf), 8, fp)) == 8) {
 		/*
Index: ed.h
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/ed.h,v
retrieving revision 1.28
diff -u -r1.28 ed.h
--- ed.h	2001/01/07 05:41:20	1.28
+++ ed.h	2001/09/15 23:39:35
@@ -1,4 +1,4 @@
-/*	$NetBSD: ed.h,v 1.28 2001/01/07 05:41:20 christos Exp $	*/
+/* $NetBSD: ed.h,v 1.28 2001/01/07 05:41:20 christos Exp $ */
 
 /* ed.h: type and constant definitions for the ed editor. */
 /*
@@ -28,6 +28,10 @@
  *
  *	@(#)ed.h,v 1.5 1994/02/01 00:34:39 alm Exp
  */
+
+#ifndef _ED_H_
+#define _ED_H_
+
 #include <sys/types.h>
 #if defined(BSD) && BSD >= 199103 || defined(__386BSD__)
 # include <sys/param.h>		/* for MAXPATHLEN */
@@ -197,79 +201,79 @@
 #endif
 
 /* 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 build_active_list __P((int));
-int cbc_decode __P((char *, FILE *));
-int cbc_encode __P((char *, int, FILE *));
-int check_addr_range __P((long, long));
-void clear_active_list __P((void));
-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 *));
-int display_lines __P((long, long, int));
-line_t *dup_line_node __P((line_t *));
-int exec_command __P((void));
-long exec_global __P((int, int));
-void expand_des_key __P((char *, char *));
-int extract_addr_range __P((void));
-char *extract_pattern __P((int));
-int extract_subst_tail __P((int *, long *));
-char *extract_subst_template __P((void));
-int filter_lines __P((long, long, char *));
-int flush_des_file __P((FILE *));
-line_t *get_addressed_line_node __P((long));
-pattern_t *get_compiled_pattern __P((void));
-int get_des_char __P((FILE *));
-char *get_extended_line __P((int *, int));
-char *get_filename __P((void));
-int get_keyword __P((void));
-long get_line_node_addr __P((line_t *));
-long get_matching_node_addr __P((pattern_t *, int));
-long get_marked_node_addr __P((int));
-char *get_sbuf_line __P((line_t *));
-int get_shell_command __P((void));
-int get_stream_line __P((FILE *));
-int get_tty_line __P((void));
-void handle_hup __P((int));
-void handle_int __P((int));
-void handle_winch __P((int));
-int has_trailing_escape __P((char *, char *));
-int hex_to_binary __P((int, int));
-void init_buffers __P((void));
-void init_des_cipher __P((void));
-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((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));
-void quit __P((int));
-long read_file __P((char *, long));
-long read_stream __P((FILE *, long));
-int search_and_replace __P((pattern_t *, int, int));
-int set_active_node __P((line_t *));
-void set_des_key __P((char *));
-void signal_hup __P((int));
-void signal_int __P((int));
-char *strip_escapes __P((char *));
-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_stream __P((FILE *, long, long));
+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);
+void des_error(char *);
+int display_lines(long, long, int);
+line_t *dup_line_node(line_t *);
+int exec_command(void);
+long exec_global(int, int);
+void expand_des_key(char *, char *);
+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 *);
+int flush_des_file(FILE *);
+line_t *get_addressed_line_node(long);
+pattern_t *get_compiled_pattern(void);
+int get_des_char(FILE *);
+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);
+void init_des_cipher(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);
+int put_des_char(int, FILE *);
+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 set_des_key(char *);
+void signal_hup(int);
+void signal_int(int);
+char *strip_escapes(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(char *, char *, long, long);
+long write_stream(FILE *, long, long);
 
 /* global buffers */
 extern char stdinbuf[];
@@ -302,3 +306,5 @@
 #if defined(sun) && !defined(__SVR4)
 extern char *sys_errlist[];
 #endif
+
+#endif /* !_ED_H_ */
Index: glbl.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/glbl.c,v
retrieving revision 1.4
diff -u -r1.4 glbl.c
--- glbl.c	1998/08/19 01:33:31	1.4
+++ glbl.c	2001/09/15 23:39:35
@@ -1,4 +1,4 @@
-/*	$NetBSD: glbl.c,v 1.4 1998/08/19 01:33:31 thorpej Exp $	*/
+/* $NetBSD: glbl.c,v 1.4 1998/08/19 01:33:31 thorpej Exp $ */
 
 /* glob.c: This file contains the global command routines for the ed line
    editor */
@@ -45,8 +45,7 @@
 
 /* build_active_list:  add line matching a pattern to the global-active list */
 int
-build_active_list(isgcmd)
-	int isgcmd;
+build_active_list(int isgcmd)
 {
 	pattern_t *pat;
 	line_t *lp;
@@ -79,17 +78,17 @@
 /* exec_global: apply command list in the command buffer to the active
    lines in a range; return command status */
 long
-exec_global(interact, gflag)
-	int interact;
-	int gflag;
+exec_global(int interact, int gflag)
 {
 	static char *ocmd = NULL;
 	static int ocmdsz = 0;
 
-	line_t *lp = NULL;
-	int status;
-	int n;
-	char *cmd = NULL;
+	line_t *lp;
+	int n, status;
+	char *cmd;
+
+	lp = NULL;
+	cmd = NULL;
 
 #ifdef BACKWARDS
 	if (!interact) {
@@ -154,8 +153,7 @@
 
 /* set_active_node: add a line node to the global-active list */
 int
-set_active_node(lp)
-	line_t *lp;
+set_active_node(line_t *lp)
 {
 	if (active_last + 1 > active_size) {
 		int ti = active_size;
@@ -193,8 +191,7 @@
 
 /* unset_active_nodes: remove a range of lines from the global-active list */
 void
-unset_active_nodes(np, mp)
-	line_t *np, *mp;
+unset_active_nodes(line_t *np, line_t *mp)
 {
 	line_t *lp;
 	long i;
@@ -211,7 +208,7 @@
 
 /* next_active_node: return the next global-active line node */
 line_t *
-next_active_node()
+next_active_node(void)
 {
 	while (active_ptr < active_last && active_list[active_ptr] == NULL)
 		active_ptr++;
@@ -221,7 +218,7 @@
 
 /* clear_active_list: clear the global-active list */
 void
-clear_active_list()
+clear_active_list(void)
 {
 	SPL1();
 	active_size = active_last = active_ptr = active_ndx = 0;
Index: io.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/io.c,v
retrieving revision 1.6
diff -u -r1.6 io.c
--- io.c	2000/04/17 23:37:30	1.6
+++ io.c	2001/09/15 23:39:35
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.6 2000/04/17 23:37:30 christos Exp $	*/
+/* $NetBSD: io.c,v 1.6 2000/04/17 23:37:30 christos Exp $ */
 
 /* io.c: This file contains the i/o routines for the ed line editor */
 /*-
@@ -41,9 +41,7 @@
 
 /* read_file: read a named file/pipe into the buffer; return line count */
 long
-read_file(fn, n)
-	char *fn;
-	long n;
+read_file(char *fn, long n)
 {
 	FILE *fp;
 	long size;
@@ -72,19 +70,21 @@
 
 /* read_stream: read a stream into the editor buffer; return status */
 long
-read_stream(fp, n)
-	FILE *fp;
-	long n;
+read_stream(FILE *fp, long n)
 {
-	line_t *lp = get_addressed_line_node(n);
-	undo_t *up = NULL;
-	unsigned long size = 0;
-	int o_newline_added = newline_added;
-	int o_isbinary = isbinary;
-	int appended = (n == addr_last);
-	int len;
-
-	isbinary = newline_added = 0;
+	line_t *lp;
+	undo_t *up;
+	unsigned long size;
+	int appended, len, o_isbinary, o_newline_added;
+
+	appended = (n == addr_last);
+	isbinary = 0;
+	lp = get_addressed_line_node(n);
+	newline_added = 0;
+	o_isbinary = isbinary;
+	o_newline_added = newline_added;
+	size = 0;
+	up = NULL;
 	if (des)
 		init_des_cipher();
 	for (current_addr = n; (len = get_stream_line(fp)) > 0; size += len) {
@@ -123,11 +123,11 @@
 
 /* get_stream_line: read a line of text from a stream; return line length */
 int
-get_stream_line(fp)
-	FILE *fp;
+get_stream_line(FILE *fp)
 {
-	int c;
-	int i = 0;
+	int c, i;
+
+	i = 0;
 
 	while (((c = des ? get_des_char(fp) : getc(fp)) != EOF || (!feof(fp) &&
 	    !ferror(fp))) && c != '\n') {
@@ -153,11 +153,7 @@
 
 /* write_file: write a range of lines to a named file/pipe; return line count */
 long
-write_file(fn, mode, n, m)
-	char *fn;
-	char *mode;
-	long n;
-	long m;
+write_file(char *fn, char *mode, long n, long m)
 {
 	FILE *fp;
 	long size;
@@ -181,16 +177,15 @@
 
 /* write_stream: write a range of lines to a stream; return status */
 long
-write_stream(fp, n, m)
-	FILE *fp;
-	long n;
-	long m;
+write_stream(FILE *fp, long n, long m)
 {
-	line_t *lp = get_addressed_line_node(n);
-	unsigned long size = 0;
+	line_t *lp;
+	unsigned long size;
 	char *s;
 	int len;
 
+	lp = get_addressed_line_node(n);
+	size = 0;
 	if (des)
 		init_des_cipher();
 	for (; n && n <= m; n++, lp = lp->q_forw) {
@@ -213,10 +208,7 @@
 
 /* put_stream_line: write a line of text to a stream; return status */
 int
-put_stream_line(fp, s, len)
-	FILE *fp;
-	char *s;
-	int len;
+put_stream_line(FILE *fp, char *s, int len)
 {
 	while (len--)
 		if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
@@ -229,16 +221,15 @@
 
 /* get_extended_line: get a an extended line from stdin */
 char *
-get_extended_line(sizep, nonl)
-	int *sizep;
-	int nonl;
+get_extended_line(int *sizep, int nonl)
 {
 	static char *cvbuf = NULL;		/* buffer */
 	static int cvbufsz = 0;			/* buffer size */
 
 	int l, n;
-	char *t = ibufp;
+	char *t;
 
+	t = ibufp;
 	while (*t++ != '\n')
 		;
 	if ((l = t - ibufp) < 2 || !has_trailing_escape(ibufp, ibufp + l - 1)) {
@@ -274,12 +265,12 @@
 
 /* get_tty_line: read a line of text from stdin; return line length */
 int
-get_tty_line()
+get_tty_line(void)
 {
-	int oi = 0;
-	int i = 0;
-	int c;
+	int c, i, oi;
 
+	i = 0;
+	oi = 0;
 	for (;;)
 		switch (c = getchar()) {
 		default:
@@ -319,18 +310,16 @@
 
 /* put_tty_line: print text to stdout */
 int
-put_tty_line(s, l, n, gflag)
-	char *s;
-	int l;
-	long n;
-	int gflag;
+put_tty_line(char *s, int l, long n, int gflag)
 {
-	int col = 0;
+	int col;
 	char *cp;
 #ifndef BACKWARDS
-	int lc = 0;
+	int lc;
+	lc = 0;
 #endif
 
+	col = 0;
 	if (gflag & GNP) {
 		printf("%ld\t", n);
 		col = 8;
Index: main.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/main.c,v
retrieving revision 1.12
diff -u -r1.12 main.c
--- main.c	2000/04/04 17:07:29	1.12
+++ main.c	2001/09/15 23:39:38
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.12 2000/04/04 17:07:29 thorpej Exp $	*/
+/* $NetBSD: main.c,v 1.12 2000/04/04 17:07:29 thorpej Exp $ */
 
 /* main.c: This file contains the main control and user-interface routines
    for the ed line editor. */
@@ -61,10 +61,11 @@
 
 #include <sys/ioctl.h>
 #include <sys/wait.h>
-#include <termios.h>
+
 #include <ctype.h>
-#include <setjmp.h>
 #include <pwd.h>
+#include <setjmp.h>
+#include <termios.h>
 
 #include "ed.h"
 
@@ -105,16 +106,17 @@
 
 char *usage = "usage: %s [-] [-sx] [-p string] [name]\n";
 
-int main __P((int, char *[]));
+int main(int, char *[]);
 
 /* ed: line editor */
 int
-main(argc, argv)
-	int argc;
-	char *argv[];
+main(int argc, char *argv[])
 {
 	int c, n;
-	long status = 0;
+	long status;
+
+	setprogname(argv[0]);
+	status = 0;
 #ifdef __GNUC__
 	(void) &argc;
 	(void) &argv;
@@ -139,7 +141,7 @@
 			break;
 
 		default:
-			fprintf(stderr, usage, argv[0]);
+			fprintf(stderr, usage, getprogname());
 			exit(1);
 			/* NOTREACHED */
 		}
@@ -268,7 +270,7 @@
 /* extract_addr_range: get line addresses from the command buffer until an 
    illegal address is seen; return status */
 int
-extract_addr_range()
+extract_addr_range(void)
 {
 	long addr;
 
@@ -297,14 +299,14 @@
 
 /*  next_addr: return the next line address in the command buffer */
 long
-next_addr()
+next_addr(void)
 {
 	char *hd;
-	long addr = current_addr;
-	long n;
-	int first = 1;
-	int c;
+	long addr, n;
+	int c, first;
 
+	addr = current_addr;
+	first = 1;
 	SKIP_BLANKS();
 	for (hd = ibufp;; first = 0)
 		switch (c = *ibufp) {
@@ -412,7 +414,9 @@
 
 /* GET_COMMAND_SUFFIX: verify the command suffix in the command buffer */
 #define GET_COMMAND_SUFFIX() { \
-	int done = 0; \
+	int done; \
+\
+	done = 0; \
 	do { \
 		switch(*ibufp) { \
 		case 'p': \
@@ -448,7 +452,7 @@
 /* exec_command: execute the next command in command buffer; return print
    request, if any */
 int
-exec_command()
+exec_command(void)
 {
 	static pattern_t *pat = NULL;
 	static int sgflag = 0;
@@ -456,12 +460,13 @@
 
 	pattern_t *tpat;
 	char *fnp;
-	int gflag = 0;
-	int sflags = 0;
-	long addr = 0;
-	int n = 0;
-	int c;
+	long addr;
+	int c, gflag, n, sflags;
 
+	addr = 0;
+	gflag = 0;
+	n = 0;
+	sflags = 0;
 	SKIP_BLANKS();
 	switch(c = *ibufp++) {
 	case 'a':
@@ -879,8 +884,7 @@
 
 /* check_addr_range: return status of address range check */
 int
-check_addr_range(n, m)
-	long n, m;
+check_addr_range(long n, long m)
 {
 	if (addr_cnt == 0) {
 		first_addr = n;
@@ -899,14 +903,13 @@
    pattern in a given direction.  wrap around begin/end of editor buffer if
    necessary */
 long
-get_matching_node_addr(pat, dir)
-	pattern_t *pat;
-	int dir;
+get_matching_node_addr(pattern_t *pat, int dir)
 {
 	char *s;
-	long n = current_addr;
+	long n;
 	line_t *lp;
 
+	n = current_addr;
 	if (!pat) return ERR;
 	do {
 		if ((n = dir ? INC_MOD(n, addr_last) :
@@ -927,7 +930,7 @@
 
 /* get_filename: return pointer to copy of filename in the command buffer */
 char *
-get_filename()
+get_filename(void)
 {
 	static char *file = NULL;
 	static int filesz = 0;
@@ -969,15 +972,16 @@
 /* get_shell_command: read a shell command from stdin; return substitution
    status */
 int
-get_shell_command()
+get_shell_command(void)
 {
 	static char *buf = NULL;
 	static int n = 0;
 
 	char *s;			/* substitution char pointer */
-	int i = 0;
-	int j = 0;
+	int i, j;
 
+	i = 0;
+	j = 0;
 	if (red) {
 		sprintf(errmsg, "shell access restricted");
 		return ERR;
@@ -1035,14 +1039,14 @@
 /* append_lines: insert text from stdin to after line n; stop when either a
    single period is read or EOF; return status */
 int
-append_lines(n)
-	long n;
+append_lines(long n)
 {
 	int l;
-	char *lp = ibuf;
-	char *eot;
-	undo_t *up = NULL;
+	char *eot, *lp;
+	undo_t *up;
 
+	lp = ibuf;
+	up = NULL;
 	for (current_addr = n;;) {
 		if (!isglobal) {
 			if ((l = get_tty_line()) < 0)
@@ -1085,17 +1089,16 @@
 
 /* join_lines: replace a range of lines with the joined text of those lines */
 int
-join_lines(from, to)
-	long from;
-	long to;
+join_lines(long from, long to)
 {
 	static char *buf = NULL;
 	static int n;
 
 	char *s;
-	int size = 0;
+	int size;
 	line_t *bp, *ep;
 
+	size = 0;
 	ep = get_addressed_line_node(INC_MOD(to, addr_last));
 	bp = get_addressed_line_node(from);
 	for (; bp != ep; bp = bp->q_forw) {
@@ -1124,14 +1127,15 @@
 
 /* move_lines: move a range of lines */
 int
-move_lines(addr)
-	long addr;
+move_lines(long addr)
 {
-	line_t *b1, *a1, *b2, *a2;
-	long n = INC_MOD(second_addr, addr_last);
-	long p = first_addr - 1;
-	int done = (addr == first_addr - 1 || addr == second_addr);
-
+	line_t *a1, *a2, *b1, *b2;
+	long n, p;
+	int done;
+
+	n = INC_MOD(second_addr, addr_last);
+	p = first_addr - 1;
+	done = (addr == first_addr - 1 || addr == second_addr);
 	SPL1();
 	if (done) {
 		a2 = get_addressed_line_node(n);
@@ -1169,15 +1173,17 @@
 
 /* copy_lines: copy a range of lines; return status */
 int
-copy_lines(addr)
-	long addr;
+copy_lines(long addr)
 {
-	line_t *lp, *np = get_addressed_line_node(first_addr);
-	undo_t *up = NULL;
-	long n = second_addr - first_addr + 1;
-	long m = 0;
+	line_t *lp, *np;
+	undo_t *up;
+	long m, n;
 
 	current_addr = addr;
+	n = second_addr - first_addr + 1;
+	np = get_addressed_line_node(first_addr);
+	m = 0;
+	up = NULL;
 	if (first_addr <= addr && addr < second_addr) {
 		n =  addr - first_addr + 1;
 		m = second_addr - addr;
@@ -1206,8 +1212,7 @@
 
 /* delete_lines: delete a range of lines */
 int
-delete_lines(from, to)
-	long from, to;
+delete_lines(long from, long to)
 {
 	line_t *n, *p;
 
@@ -1232,13 +1237,9 @@
 
 /* display_lines: print a range of lines to stdout */
 int
-display_lines(from, to, gflag)
-	long from;
-	long to;
-	int gflag;
+display_lines(long from, long to, int gflag)
 {
-	line_t *bp;
-	line_t *ep;
+	line_t *bp, *ep;
 	char *s;
 
 	if (!from) {
@@ -1264,9 +1265,7 @@
 
 /* mark_line_node: set a line node mark */
 int
-mark_line_node(lp, n)
-	line_t *lp;
-	int n;
+mark_line_node(line_t *lp, int n)
 {
 	if (!islower(n)) {
 		sprintf(errmsg, "invalid mark character");
@@ -1280,8 +1279,7 @@
 
 /* get_marked_node_addr: return address of a marked line */
 long
-get_marked_node_addr(n)
-	int n;
+get_marked_node_addr(int n)
 {
 	if (!islower(n)) {
 		sprintf(errmsg, "invalid mark character");
@@ -1293,8 +1291,7 @@
 
 /* unmark_line_node: clear line node mark */
 void
-unmark_line_node(lp)
-	line_t *lp;
+unmark_line_node(line_t *lp)
 {
 	int i;
 
@@ -1308,8 +1305,7 @@
 
 /* dup_line_node: return a pointer to a copy of a line node */
 line_t *
-dup_line_node(lp)
-	line_t *lp;
+dup_line_node(line_t *lp)
 {
 	line_t *np;
 
@@ -1327,9 +1323,7 @@
 /* has_trailing_escape:  return the parity of escapes preceding a character
    in a string */
 int
-has_trailing_escape(s, t)
-	char *s;
-	char *t;
+has_trailing_escape(char *s, char *t)
 {
     return (s == t || *(t - 1) != '\\') ? 0 : !has_trailing_escape(s, t - 1);
 }
@@ -1337,14 +1331,14 @@
 
 /* strip_escapes: return copy of escaped string of at most length MAXPATHLEN */
 char *
-strip_escapes(s)
-	char *s;
+strip_escapes(char *s)
 {
 	static char *file = NULL;
 	static int filesz = 0;
 
-	int i = 0;
+	int i;
 
+	i = 0;
 	REALLOC(file, filesz, MAXPATHLEN + 1, NULL);
 	/* assert: no trailing escape */
 	while ((file[i++] = (*s == '\\') != '\0' ? *++s : *s))
@@ -1354,8 +1348,7 @@
 
 
 void
-signal_hup(signo)
-	int signo;
+signal_hup(int signo)
 {
 	if (mutex)
 		sigflags |= (1 << (signo - 1));
@@ -1364,8 +1357,7 @@
 
 
 void
-signal_int(signo)
-	int signo;
+signal_int(int signo)
 {
 	if (mutex)
 		sigflags |= (1 << (signo - 1));
@@ -1374,13 +1366,12 @@
 
 
 void
-handle_hup(signo)
-	int signo;
+handle_hup(int signo)
 {
-	char *hup = NULL;		/* hup filename */
-	char *s;
+	char *hup, *s;
 	int n;
 
+	hup = NULL;               /* hup filename */
 	if (!sigactive)
 		quit(1);
 	sigflags &= ~(1 << (signo - 1));
@@ -1399,8 +1390,7 @@
 
 
 void
-handle_int(signo)
-	int signo;
+handle_int(int signo)
 {
 	if (!sigactive)
 		quit(1);
@@ -1416,8 +1406,7 @@
 int cols = 72;				/* wrap column */
 
 void
-handle_winch(signo)
-	int signo;
+handle_winch(int signo)
 {
 	struct winsize ws;		/* window size structure */
 
@@ -1431,8 +1420,7 @@
 
 /* is_legal_filename: return a legal filename */
 int
-is_legal_filename(s)
-	char *s;
+is_legal_filename(char *s)
 {
 	if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
 		sprintf(errmsg, "shell access restricted");
Index: re.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/re.c,v
retrieving revision 1.16
diff -u -r1.16 re.c
--- re.c	2000/04/04 17:07:29	1.16
+++ re.c	2001/09/15 23:39:38
@@ -1,4 +1,4 @@
-/*	$NetBSD: re.c,v 1.16 2000/04/04 17:07:29 thorpej Exp $	*/
+/* $NetBSD: re.c,v 1.16 2000/04/04 17:07:29 thorpej Exp $ */
 
 /* re.c: This file contains the regular expression interface routines for
    the ed line editor. */
@@ -45,7 +45,7 @@
 /* get_compiled_pattern: return pointer to compiled pattern from command 
    buffer */
 pattern_t *
-get_compiled_pattern()
+get_compiled_pattern(void)
 {
 	static pattern_t *exp = NULL;
 
@@ -82,8 +82,7 @@
 /* extract_pattern: copy a pattern string from the command buffer; return
    pointer to the copy */
 char *
-extract_pattern(delimiter)
-	int delimiter;
+extract_pattern(int delimiter)
 {
 	static char *lhbuf = NULL;	/* buffer */
 	static int lhbufsz = 0;		/* buffer size */
@@ -119,8 +118,7 @@
 
 /* parse_char_class: expand a POSIX character class */
 char *
-parse_char_class(s)
-	char *s;
+parse_char_class(char *s)
 {
 	int c, d;
 
Index: sub.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/sub.c,v
retrieving revision 1.5
diff -u -r1.5 sub.c
--- sub.c	1997/07/20 06:35:41	1.5
+++ sub.c	2001/09/15 23:39:39
@@ -1,4 +1,4 @@
-/*	$NetBSD: sub.c,v 1.5 1997/07/20 06:35:41 thorpej Exp $	*/
+/* $NetBSD: sub.c,v 1.5 1997/07/20 06:35:41 thorpej Exp $ */
 
 /* sub.c: This file contains the substitution routines for the ed 
    line editor */
@@ -46,9 +46,7 @@
 
 /* extract_subst_tail: extract substitution tail from the command buffer */
 int
-extract_subst_tail(flagp, np)
-	int *flagp;
-	long *np;
+extract_subst_tail(int *flagp, long *np)
 {
 	char delimiter;
 
@@ -79,13 +77,15 @@
 /* extract_subst_template: return pointer to copy of substitution template
    in the command buffer */
 char *
-extract_subst_template()
+extract_subst_template(void)
 {
-	int n = 0;
-	int i = 0;
-	char c;
-	char delimiter = *ibufp++;
+	int i, n;
+	char c, delimiter;
 
+	delimiter = *ibufp++;
+	i = 0;
+	n = 0;
+
 	if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
 		ibufp++;
 		if (!rhbuf) sprintf(errmsg, "no previous substitution");
@@ -120,20 +120,16 @@
 /* search_and_replace: for each line in a range, change text matching a pattern
    according to a substitution template; return status  */
 int
-search_and_replace(pat, gflag, kth)
-	pattern_t *pat;
-	int gflag;
-	int kth;
+search_and_replace(pattern_t *pat, int gflag, int kth)
 {
 	undo_t *up;
-	char *txt;
-	char *eot;
-	long lc;
-	long xa = current_addr;
-	int nsubs = 0;
+	char *eot, *txt;
+	long lc, xa;
+	int len, nsubs;
 	line_t *lp;
-	int len;
 
+	nsubs = 0;
+	xa = current_addr;
 	current_addr = first_addr - 1;
 	for (lc = 0; lc <= second_addr - first_addr; lc++) {
 		lp = get_addressed_line_node(++current_addr);
@@ -177,19 +173,16 @@
 /* substitute_matching_text: replace text matched by a pattern according to
    a substitution template; return pointer to the modified text */
 int
-substitute_matching_text(pat, lp, gflag, kth)
-	pattern_t *pat;
-	line_t *lp;
-	int gflag;
-	int kth;
+substitute_matching_text(pattern_t *pat, line_t *lp, int gflag, int kth)
 {
-	int off = 0;
-	int changed = 0;
-	int matchno = 0;
-	int i = 0;
+	int changed, off, i, matchno;
 	regmatch_t rm[SE_MAX];
-	char *txt;
-	char *eot;
+	char *eot, *txt;
+
+	changed = 0;
+	off = 0;
+	i = 0;
+	matchno = 0;
 
 	if ((txt = get_sbuf_line(lp)) == NULL)
 		return ERR;
@@ -238,17 +231,14 @@
 /* apply_subst_template: modify text according to a substitution template;
    return offset to end of modified text */
 int
-apply_subst_template(boln, rm, off, re_nsub)
-	char *boln;
-	regmatch_t *rm;
-	int off;
-	int re_nsub;
+apply_subst_template(char *boln, regmatch_t *rm, int off, int re_nsub)
 {
-	int j = 0;
-	int k = 0;
-	int n;
-	char *sub = rhbuf;
+	int j, k, n;
+	char *sub;
 
+	j = 0;
+	k = 0;
+	sub = rhbuf;
 	for (; sub - rhbuf < rhbufi; sub++)
 		if (*sub == '&') {
 			j = rm[0].rm_so;
Index: undo.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ed/undo.c,v
retrieving revision 1.3
diff -u -r1.3 undo.c
--- undo.c	1997/07/20 06:35:42	1.3
+++ undo.c	2001/09/15 23:39:39
@@ -1,4 +1,4 @@
-/*	$NetBSD: undo.c,v 1.3 1997/07/20 06:35:42 thorpej Exp $	*/
+/* $NetBSD: undo.c,v 1.3 1997/07/20 06:35:42 thorpej Exp $ */
 
 /* undo.c: This file contains the undo routines for the ed line editor */
 /*-
@@ -46,10 +46,7 @@
 
 /* push_undo_stack: return pointer to intialized undo node */
 undo_t *
-push_undo_stack(type, from, to)
-	int type;
-	long from;
-	long to;
+push_undo_stack(int type, long from, long to)
 {
 	undo_t *t;
 
@@ -93,12 +90,12 @@
 
 /* pop_undo_stack: undo last change to the editor buffer */
 int
-pop_undo_stack()
+pop_undo_stack(void)
 {
-	long n;
-	long o_current_addr = current_addr;
-	long o_addr_last = addr_last;
+	long o_addr_last, o_current_addr, n;
 
+	o_addr_last = addr_last;
+	o_current_addr = current_addr;
 	if (u_current_addr == -1 || u_addr_last == -1) {
 		sprintf(errmsg, "nothing to undo");
 		return ERR;
@@ -142,9 +139,9 @@
 
 /* clear_undo_stack: clear the undo stack */
 void
-clear_undo_stack()
+clear_undo_stack(void)
 {
-	line_t *lp, *ep, *tl;
+	line_t *ep, *lp, *tl;
 
 	while (u_p--)
 		if (ustack[u_p].type == UDEL) {

>Release-Note:
>Audit-Trail:
>Unformatted: