From 67d9079789883edb6cd4fe9b16e4c9632a5fe309 Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 9 Oct 2015 19:47:02 +0000 Subject: [PATCH] Mark static globals that are only used in their respective .c files. Also make stdin unbuffered since that is the same as using a single-byte buffer. OK tobias@ --- bin/ed/buf.c | 16 ++++++++-------- bin/ed/ed.h | 3 +-- bin/ed/glbl.c | 12 ++++++------ bin/ed/io.c | 6 +++--- bin/ed/main.c | 25 +++++++++++++------------ bin/ed/sub.c | 12 ++++++------ bin/ed/undo.c | 8 ++++---- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/bin/ed/buf.c b/bin/ed/buf.c index ad1aa4ed94e..0482430d014 100644 --- a/bin/ed/buf.c +++ b/bin/ed/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.21 2015/07/28 17:46:52 deraadt Exp $ */ +/* $OpenBSD: buf.c,v 1.22 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: buf.c,v 1.15 1995/04/23 10:07:28 cgd Exp $ */ /* buf.c: This file contains the scratch-file buffer routines for the @@ -34,10 +34,10 @@ #include "ed.h" -FILE *sfp; /* scratch file pointer */ -off_t sfseek; /* scratch file position */ -int seek_write; /* seek before writing */ -line_t buffer_head; /* incore buffer */ +static FILE *sfp; /* scratch file pointer */ +static off_t sfseek; /* scratch file position */ +static int seek_write; /* seek before writing */ +static line_t buffer_head; /* incore buffer */ /* get_sbuf_line: get a line of text from the scratch file; return pointer to the text */ @@ -190,7 +190,7 @@ get_addressed_line_node(int n) extern int newline_added; #define SCRATCH_TEMPLATE "/tmp/ed.XXXXXXXXXX" -char sfn[sizeof(SCRATCH_TEMPLATE)+1] = ""; /* scratch file name */ +static char sfn[sizeof(SCRATCH_TEMPLATE)+1] = ""; /* scratch file name */ /* open_sbuf: open scratch file */ int @@ -242,7 +242,7 @@ quit(int n) } -unsigned char ctab[256]; /* character translation table */ +static unsigned char ctab[256]; /* character translation table */ /* init_buffers: open scratch buffer; initialize line queue */ void @@ -256,7 +256,7 @@ init_buffers(void) !cat hello, world EOF */ - setbuffer(stdin, stdinbuf, 1); + setvbuf(stdin, NULL, _IONBF, 0); if (open_sbuf() < 0) quit(2); REQUE(&buffer_head, &buffer_head); diff --git a/bin/ed/ed.h b/bin/ed/ed.h index 2a5109dccad..aa1685e0a01 100644 --- a/bin/ed/ed.h +++ b/bin/ed/ed.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ed.h,v 1.18 2015/10/04 15:23:24 millert Exp $ */ +/* $OpenBSD: ed.h,v 1.19 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: ed.h,v 1.23 1995/03/21 09:04:40 cgd Exp $ */ /* ed.h: type and constant definitions for the ed editor. */ @@ -212,7 +212,6 @@ int write_file(char *, char *, int, int); int write_stream(FILE *, int, int); /* global buffers */ -extern char stdinbuf[]; extern char *ibuf; extern char *ibufp; extern int ibufsz; diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c index 5e4dca9252f..65ec7c9a686 100644 --- a/bin/ed/glbl.c +++ b/bin/ed/glbl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: glbl.c,v 1.15 2015/10/04 15:23:24 millert Exp $ */ +/* $OpenBSD: glbl.c,v 1.16 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: glbl.c,v 1.2 1995/03/21 09:04:41 cgd Exp $ */ /* glob.c: This file contains the global command routines for the ed line @@ -135,11 +135,11 @@ exec_global(int interact, int gflag) } -line_t **active_list; /* list of lines active in a global command */ -int active_last; /* index of last active line in active_list */ -int active_size; /* size of active_list */ -int active_ptr; /* active_list index (non-decreasing) */ -int active_ndx; /* active_list index (modulo active_last) */ +static line_t **active_list; /* list of lines active in a global command */ +static int active_last; /* index of last active line in active_list */ +static int active_size; /* size of active_list */ +static int active_ptr; /* active_list index (non-decreasing) */ +static int active_ndx; /* active_list index (modulo active_last) */ /* set_active_node: add a line node to the global-active list */ int diff --git a/bin/ed/io.c b/bin/ed/io.c index 3a2b37cf3e6..d83bd1af47e 100644 --- a/bin/ed/io.c +++ b/bin/ed/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.16 2014/04/14 22:12:01 tedu Exp $ */ +/* $OpenBSD: io.c,v 1.17 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */ /* io.c: This file contains the i/o routines for the ed line editor */ @@ -58,8 +58,8 @@ read_file(char *fn, int n) } -char *sbuf; /* file i/o buffer */ -int sbufsz; /* file i/o buffer size */ +static char *sbuf; /* file i/o buffer */ +static int sbufsz; /* file i/o buffer size */ int newline_added; /* if set, newline appended to input file */ /* read_stream: read a stream into the editor buffer; return status */ diff --git a/bin/ed/main.c b/bin/ed/main.c index eb216fa5cab..923f00a4c79 100644 --- a/bin/ed/main.c +++ b/bin/ed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.50 2015/10/09 01:37:06 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.51 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */ /* main.c: This file contains the main control and user-interface routines @@ -56,10 +56,12 @@ sigjmp_buf env; /* static buffers */ -char stdinbuf[1]; /* stdin buffer */ -char *shcmd; /* shell command buffer */ -int shcmdsz; /* shell command buffer size */ -int shcmdi; /* shell command buffer index */ +static char *shcmd; /* shell command buffer */ +static int shcmdsz; /* shell command buffer size */ +static int shcmdi; /* shell command buffer index */ +static char old_filename[PATH_MAX]; /* default filename */ + +/* global buffers */ char *ibuf; /* ed command-line buffer */ int ibufsz; /* ed command-line buffer size */ char *ibufp; /* pointer to ed command-line buffer */ @@ -79,16 +81,15 @@ volatile sig_atomic_t sigint = 0; /* if set, sigint received while mutex set */ /* if set, signal handlers are enabled */ volatile sig_atomic_t sigactive = 0; -char old_filename[PATH_MAX] = ""; /* default filename */ int current_addr; /* current address in editor buffer */ int addr_last; /* last address in editor buffer */ int lineno; /* script line number */ -char *prompt; /* command-line prompt */ -char *dps = "*"; /* default command-line prompt */ +static char *prompt; /* command-line prompt */ +static char *dps = "*"; /* default command-line prompt */ -const char usage[] = "usage: %s [-] [-s] [-p string] [file]\n"; +static const char usage[] = "usage: %s [-] [-s] [-p string] [file]\n"; -char *home; /* home directory */ +static char *home; /* home directory */ void seterrmsg(char *s) @@ -1259,8 +1260,8 @@ display_lines(int from, int to, int gflag) #define MAXMARK 26 /* max number of marks */ -line_t *mark[MAXMARK]; /* line markers */ -int markno; /* line marker count */ +static line_t *mark[MAXMARK]; /* line markers */ +static int markno; /* line marker count */ /* mark_line_node: set a line node mark */ int diff --git a/bin/ed/sub.c b/bin/ed/sub.c index 3e293d1cec9..18d5b701bb2 100644 --- a/bin/ed/sub.c +++ b/bin/ed/sub.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sub.c,v 1.12 2015/10/04 15:23:24 millert Exp $ */ +/* $OpenBSD: sub.c,v 1.13 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: sub.c,v 1.4 1995/03/21 09:04:50 cgd Exp $ */ /* sub.c: This file contains the substitution routines for the ed @@ -32,9 +32,9 @@ #include "ed.h" -char *rhbuf; /* rhs substitution buffer */ -int rhbufsz; /* rhs substitution buffer size */ -int rhbufi; /* rhs substitution buffer index */ +static char *rhbuf; /* rhs substitution buffer */ +static int rhbufsz; /* rhs substitution buffer size */ +static int rhbufi; /* rhs substitution buffer index */ /* extract_subst_tail: extract substitution tail from the command buffer */ int @@ -105,8 +105,8 @@ extract_subst_template(void) } -char *rbuf; /* substitute_matching_text buffer */ -int rbufsz; /* substitute_matching_text buffer size */ +static char *rbuf; /* substitute_matching_text buffer */ +static int rbufsz; /* substitute_matching_text buffer size */ /* search_and_replace: for each line in a range, change text matching a pattern according to a substitution template; return status */ diff --git a/bin/ed/undo.c b/bin/ed/undo.c index 5686aaa3462..43739beca4a 100644 --- a/bin/ed/undo.c +++ b/bin/ed/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.12 2014/05/18 16:36:42 espie Exp $ */ +/* $OpenBSD: undo.c,v 1.13 2015/10/09 19:47:02 millert Exp $ */ /* $NetBSD: undo.c,v 1.2 1995/03/21 09:04:52 cgd Exp $ */ /* undo.c: This file contains the undo routines for the ed line editor */ @@ -32,9 +32,9 @@ #define USIZE 100 /* undo stack size */ -undo_t *ustack = NULL; /* undo stack */ -int usize = 0; /* stack size variable */ -int u_p = 0; /* undo stack pointer */ +static undo_t *ustack = NULL; /* undo stack */ +static int usize = 0; /* stack size variable */ +static int u_p = 0; /* undo stack pointer */ /* push_undo_stack: return pointer to initialized undo node */ undo_t * -- 2.20.1