ed has a lot of global variables, mark the ones not used outside
the source file static.  Also make stdin unbuffered since that is
the same as using a single-byte buffer.

 - todd

Index: bin/ed/buf.c
===================================================================
RCS file: /cvs/src/bin/ed/buf.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 buf.c
--- bin/ed/buf.c        28 Jul 2015 17:46:52 -0000      1.21
+++ bin/ed/buf.c        5 Oct 2015 16:39:52 -0000
@@ -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);
Index: bin/ed/ed.h
===================================================================
RCS file: /cvs/src/bin/ed/ed.h,v
retrieving revision 1.18
diff -u -p -u -r1.18 ed.h
--- bin/ed/ed.h 4 Oct 2015 15:23:24 -0000       1.18
+++ bin/ed/ed.h 5 Oct 2015 16:41:07 -0000
@@ -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;
Index: bin/ed/glbl.c
===================================================================
RCS file: /cvs/src/bin/ed/glbl.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 glbl.c
--- bin/ed/glbl.c       4 Oct 2015 15:23:24 -0000       1.15
+++ bin/ed/glbl.c       5 Oct 2015 16:32:47 -0000
@@ -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
Index: bin/ed/io.c
===================================================================
RCS file: /cvs/src/bin/ed/io.c,v
retrieving revision 1.16
diff -u -p -u -r1.16 io.c
--- bin/ed/io.c 14 Apr 2014 22:12:01 -0000      1.16
+++ bin/ed/io.c 5 Oct 2015 16:33:04 -0000
@@ -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 */
Index: bin/ed/main.c
===================================================================
RCS file: /cvs/src/bin/ed/main.c,v
retrieving revision 1.48
diff -u -p -u -r1.48 main.c
--- bin/ed/main.c       4 Oct 2015 15:23:24 -0000       1.48
+++ bin/ed/main.c       5 Oct 2015 16:44:17 -0000
@@ -55,10 +55,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 */
@@ -78,16 +80,15 @@ volatile sig_atomic_t sigint = 0; /* if 
 /* 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)
@@ -1255,8 +1256,8 @@ display_lines(int from, int to, int gfla
 
 #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
Index: bin/ed/sub.c
===================================================================
RCS file: /cvs/src/bin/ed/sub.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 sub.c
--- bin/ed/sub.c        4 Oct 2015 15:23:24 -0000       1.12
+++ bin/ed/sub.c        5 Oct 2015 16:33:53 -0000
@@ -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  */
Index: bin/ed/undo.c
===================================================================
RCS file: /cvs/src/bin/ed/undo.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 undo.c
--- bin/ed/undo.c       18 May 2014 16:36:42 -0000      1.12
+++ bin/ed/undo.c       5 Oct 2015 16:34:33 -0000
@@ -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 *

Reply via email to