From b0ff1d6b3e1eeb542d5e4577ecf2ae552ec19458 Mon Sep 17 00:00:00 2001 From: Gunnar Ritter Date: Thu, 4 Aug 2005 15:23:39 +0000 Subject: [PATCH] ex (not vi) can now edit files with lines of arbitrary length. --- Changes | 1 + ex.c | 13 ++++++++++--- ex.h | 12 ++++++------ ex_addr.c | 2 +- ex_cmdsub.c | 34 ++++++++++++++++++++++------------ ex_get.c | 2 +- ex_io.c | 10 ++++------ ex_proto.h | 4 +++- ex_re.c | 17 +++++++++++------ ex_re.h | 4 ++-- ex_subr.c | 38 +++++++++++++++++++++++++++++++++++++- ex_tagio.c | 5 +++-- ex_temp.c | 8 +++++--- ex_temp.h | 8 +++++--- ex_tune.h | 10 +++------- ex_unix.c | 2 +- ex_v.c | 2 +- ex_vadj.c | 26 +++++++++++++++++--------- ex_version.c | 50 +++++++++++++++++++++++++------------------------- ex_vis.h | 2 +- ex_vmain.c | 9 ++++++--- ex_vops.c | 9 ++++++--- ex_vops2.c | 2 +- ex_vops3.c | 10 ++++++---- ex_vput.c | 4 ++-- exrecover.c | 4 +++- 26 files changed, 183 insertions(+), 105 deletions(-) diff --git a/Changes b/Changes index 36d51e5..f1a56b6 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Release ... * The screen buffers for visual mode are now dynamically allocated, so vi usually does not return to ex mode with "screen too large" when the terminal is resized on a large monitor anymore. +* ex (not vi) can now edit files with lines of arbitrary length. Release 3/25/05 * vi no longer dies with a segmentation fault if a line does not fit on the diff --git a/ex.c b/ex.c index 7461788..a6b5121 100644 --- a/ex.c +++ b/ex.c @@ -77,7 +77,7 @@ char *copyright = "@(#) Copyright (c) 1980 Regents of the University of California.\n\ All rights reserved.\n"; -static char sccsid[] = "@(#)ex.c 1.36 (gritter) 2/13/05"; +static char sccsid[] = "@(#)ex.c 1.37 (gritter) 8/4/05"; #endif /* DOSCCS */ #endif /* !lint */ @@ -294,6 +294,13 @@ main(register int ac, register char *av[]) poolsbrk(0); #endif + /* + * Initialize the primary buffers which were originally static. + * NOTE: Most of this must be repeated in ex_recover.c. + */ + linebuf = calloc(LBSIZE = BUFSIZ<4096?4096:BUFSIZ, sizeof *linebuf); + genbuf = calloc(MAXBSIZE, sizeof *genbuf); + /* * Immediately grab the tty modes so that we wont * get messed up if an interrupt comes in quickly. @@ -588,9 +595,9 @@ argend: else { globp = 0; if ((cp = getenv("HOME")) != 0 && *cp) { - safecat(safecp(genbuf, cp, sizeof genbuf, + safecat(safecp(genbuf, cp, MAXBSIZE, "$HOME too long"), - "/.exrc", sizeof genbuf, + "/.exrc", MAXBSIZE, "$HOME too long"); if (iownit(genbuf)) source(genbuf, 1); diff --git a/ex.h b/ex.h index 3ec9795..0eff5b3 100644 --- a/ex.h +++ b/ex.h @@ -72,7 +72,7 @@ * * from ex.h 7.7.1.1 (Berkeley) 8/12/86 * - * Sccsid @(#)ex.h 1.54 (gritter) 8/4/05 + * Sccsid @(#)ex.h 1.55 (gritter) 8/4/05 */ /* @@ -276,9 +276,8 @@ typedef sigjmp_buf JMP_BUF; #define SETJMP(a) sigsetjmp(a, 1) #define LONGJMP(a, b) siglongjmp(a, b) -#ifndef MAXBSIZE -#define MAXBSIZE 8192 /* Same as in 4.2BSD */ -#endif +#undef MAXBSIZE +#define MAXBSIZE (2*LBSIZE) #include "ex_tune.h" #include "ex_vars.h" @@ -387,7 +386,7 @@ var short erfile; /* Error message file unit */ var line *fendcore; /* First address in line pointer space */ var char file[FNSIZE]; /* Working file name */ var bool fixedzero; /* zero file size was fixed (for visual) */ -var char genbuf[MAXBSIZE]; /* Working buffer when manipulating linebuf */ +var char *genbuf; /* Working buffer when manipulating linebuf */ var bool hush; /* Command line option - was given, hush up! */ var char *globp; /* (Untyped) input string to command mode */ var bool holdcm; /* Don't cursor address */ @@ -403,7 +402,8 @@ var bool laste; /* Last command was an "e" (or "rec") */ var char lastmac; /* Last macro called for ** */ var char lasttag[TAGSIZE]; /* Last argument to a tag command */ var char *linebp; /* Used in substituting in \n */ -var char linebuf[LBSIZE]; /* The primary line buffer */ +var char *linebuf; /* The primary line buffer */ +var int LBSIZE; /* Size of linebuf */ var bool listf; /* Command should run in list mode */ var line names['z'-'a'+2]; /* Mark registers a-z,' */ var int notecnt; /* Count for notify (to visual from cmd) */ diff --git a/ex_addr.c b/ex_addr.c index ffd8db8..8d92c64 100644 --- a/ex_addr.c +++ b/ex_addr.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_addr.c 1.10 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_addr.c 1.11 (gritter) 8/4/05"; #endif #endif /* not lint */ diff --git a/ex_cmdsub.c b/ex_cmdsub.c index 1f798d7..682f062 100644 --- a/ex_cmdsub.c +++ b/ex_cmdsub.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_cmdsub.c 1.29 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_cmdsub.c 1.31 (gritter) 8/4/05"; #endif #endif @@ -281,7 +281,7 @@ void join(int c) { register line *a1; - register char *cp, *cp1; + char *cp, *cp1; cp = genbuf; *cp = 0; @@ -301,8 +301,9 @@ join(int c) } while (*cp++ = *cp1++) if (cp > &genbuf[LBSIZE-2]) - error(catgets(catd, 1, 40, - "Line overflow|Result line of join would be too long")); + grow( + "Line overflow|Result line of join would be too long", + &cp1, NULL, &cp, NULL); cp--; } strcLIN(genbuf); @@ -477,7 +478,7 @@ pragged(int kill) getline(dol[1]); if (kill) strcLIN(pkill[0]); - safecp(gp, linebuf, sizeof genbuf - (gp - genbuf), "Line too long"); + safecp(gp, linebuf, MAXBSIZE - (gp - genbuf), "Line too long"); strcLIN(genbuf); putmark(dol+1); undkind = UNDCHANGE; @@ -495,7 +496,7 @@ void shift(int c, int cnt) { register line *addr; - register char *cp = NULL; + char *cp = NULL; char *dp; register int i; @@ -534,8 +535,9 @@ shift(int c, int cnt) #endif } if (cp + strlen(dp = vpastwh(linebuf)) >= &genbuf[LBSIZE - 2]) - error(catgets(catd, 1, 45, - "Line too long|Result line after shift would be too long")); + grow( + "Line too long|Result line after shift would be too long", + &dp, NULL, &cp, NULL); CP(cp, dp); strcLIN(genbuf); putmark(addr); @@ -562,9 +564,9 @@ tagfind(bool quick) struct stat sbuf; char *savefirstpat = NULL; int ofailed; + char *ft_iofbuf = NULL; #ifdef FASTTAG int ft_iof; - char ft_iofbuf[MAXBSIZE]; off_t mid; /* assumed byte offset */ off_t top, bot; /* length of tag file */ #endif @@ -600,6 +602,9 @@ badtag: */ safecp(tagfbuf, svalue(TAGS), sizeof tagfbuf, "Tag too long"); fne = tagfbuf - 1; +#ifdef FASTTAG + ft_iofbuf = smalloc(MAXBSIZE); +#endif while (fne) { fn = ++fne; while (*fne && *fne != ' ') @@ -646,10 +651,10 @@ badtag: tseek(ft_iof, mid); if (mid > 0) /* to get first tag in file to work */ /* scan to next \n */ - if(tgets(linebuf, sizeof linebuf, ft_iof)==0) + if(tgets(linebuf, LBSIZE, ft_iof)==0) goto goleft; /* get the line itself */ - if(tgets(linebuf, sizeof linebuf, ft_iof)==0) + if(tgets(linebuf, LBSIZE, ft_iof)==0) goto goleft; #ifdef TDEBUG printf("tag: %o %o %o %s\n", bot, mid, top, linebuf); @@ -687,6 +692,7 @@ goleft: cp++; if (!*cp) badtags: + free(ft_iofbuf); serror(catgets(catd, 1, 48, "%s: Bad tags file entry"), lasttag); lp = filebuf; @@ -720,9 +726,11 @@ badtags: /* Different file. Do autowrite & get it. */ if (!quick) { ckaw(); - if (chng && dol > zero) + if (chng && dol > zero) { + free(ft_iofbuf); error(catgets(catd, 1, 49, "No write@since last change (:tag! overrides)")); + } } oglobp = globp; strcpy(cmdbuf2, "e! "); @@ -767,6 +775,7 @@ badtags: } else tflag = 0; } + free(ft_iofbuf); return; } /* end of "for each tag in file" */ @@ -779,6 +788,7 @@ badtags: close(io); #endif } /* end of "for each file in path" */ + free(ft_iofbuf); if (tfcount <= 0) error(catgets(catd, 1, 50, "No tags file")); else diff --git a/ex_get.c b/ex_get.c index f2325b9..7bca559 100644 --- a/ex_get.c +++ b/ex_get.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_get.c 1.17 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_get.c 1.18 (gritter) 8/4/05"; #endif #endif diff --git a/ex_io.c b/ex_io.c index 8769a9d..fa0a871 100644 --- a/ex_io.c +++ b/ex_io.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_io.c 1.40 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_io.c 1.41 (gritter) 8/4/05"; #endif #endif @@ -839,7 +839,7 @@ int getfile(void) { register short c; - register char *lp, *fp; + char *lp, *fp; lp = linebuf; fp = nextip; @@ -858,10 +858,8 @@ getfile(void) fp = genbuf; cntch += ninbuf+1; } - if (lp >= &linebuf[LBSIZE]) { - synced(); - error(catgets(catd, 1, 118, " Line too long")); - } + if (lp >= &linebuf[LBSIZE]) + grow(" Line too long", &lp, NULL, &fp, &nextip); c = *fp++; if (c == 0) { cntnull++; diff --git a/ex_proto.h b/ex_proto.h index 96202c5..0712cf8 100644 --- a/ex_proto.h +++ b/ex_proto.h @@ -71,7 +71,7 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Sccsid @(#)ex_proto.h 1.29 (gritter) 8/4/05 + * Sccsid @(#)ex_proto.h 1.31 (gritter) 8/4/05 */ /* @@ -325,6 +325,8 @@ extern void onemt(int); extern char *movestr(char *, const char *); extern char *safecp(char *, const char *, size_t, char *, ...); extern char *safecat(char *, const char *, size_t, char *, ...); +extern void grow(char *, char **, char **, char **, char **); +extern void *smalloc(size_t); /* ex_tagio.c */ extern int topen(char *, char *); extern int tseek(int, off_t); diff --git a/ex_re.c b/ex_re.c index 7f903eb..989a470 100644 --- a/ex_re.c +++ b/ex_re.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_re.c 1.56 (gritter) 3/25/05"; +static char sccsid[] = "@(#)ex_re.c 1.58 (gritter) 8/4/05"; #endif #endif @@ -359,7 +359,7 @@ substitute(int c) * but we don't want to break other, reasonable cases. */ while (*loc2) { - if (++hopcount > sizeof linebuf) + if (++hopcount > LBSIZE) error(catgets(catd, 1, 124, "substitution loop")); if (dosubcon(1, addr) == 0) @@ -416,10 +416,10 @@ compsub(int ch) /* fall into ... */ case '&': redo: - if (re.Patbuf[0] == 0) + if (re.Patbuf == NULL || re.Patbuf[0] == 0) error(catgets(catd, 1, 127, "No previous re|No previous regular expression")); - if (subre.Patbuf[0] == 0) + if (subre.Patbuf == NULL || subre.Patbuf[0] == 0) error(catgets(catd, 1, 128, "No previous substitute re|No previous substitute to repeat")); break; @@ -867,7 +867,8 @@ snote(register int total, register int lines) void cerror(char *s) { - re.Patbuf[0] = '\0'; + if (re.Patbuf != NULL) + re.Patbuf[0] = '\0'; error(s); } @@ -1020,13 +1021,17 @@ compile(int eof, int oknl) { int c, d, i, n = 0; char mb[MB_LEN_MAX+1]; - char *p = re.Patbuf, *end = re.Patbuf + sizeof re.Patbuf; + char *p, *end; int nomagic = value(MAGIC) ? 0 : 1, esc, rcnt = 0; char *rhsp; #ifdef BIT8 char *rhsq; #endif + free(re.Patbuf); + re.Patbuf = smalloc(2*LBSIZE + 1); + p = re.Patbuf; + end = re.Patbuf + sizeof re.Patbuf; if (isalpha(eof) || isdigit(eof)) error(catgets(catd, 1, 133, "Regular expressions cannot be delimited by letters or digits")); diff --git a/ex_re.h b/ex_re.h index 885673b..7e4eb21 100644 --- a/ex_re.h +++ b/ex_re.h @@ -72,7 +72,7 @@ * * from ex_re.h 7.3 (Berkeley) 5/31/85 * - * Sccsid @(#)ex_re.h 1.23 (gritter) 8/4/05 + * Sccsid @(#)ex_re.h 1.24 (gritter) 8/4/05 */ /* @@ -85,7 +85,7 @@ * more and alternation.) */ struct regexp { - char Patbuf[2*LBSIZE + 1]; + char *Patbuf; long Re_ident; void *Expbuf; bool Circfl; diff --git a/ex_subr.c b/ex_subr.c index 6f884aa..5763c14 100644 --- a/ex_subr.c +++ b/ex_subr.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_subr.c 1.37 (gritter) 2/15/05"; +static char sccsid[] = "@(#)ex_subr.c 1.39 (gritter) 8/4/05"; #endif #endif @@ -1151,3 +1151,39 @@ safecat(char *s1, const char *s2, size_t max, char *msg, ...) /*NOTREACHED*/ return NULL; } + +/* + * Grow the line and generic buffers. + */ +void +grow(char *msg, char **tolb0, char **tolb1, char **togb0, char **togb1) +{ + char *nlb, *ngb = NULL; + + if ((nlb = realloc(linebuf, LBSIZE + 4096)) == NULL || + (ngb = realloc(genbuf, 2 * (LBSIZE + 4096))) == NULL) { + synced(); + error(msg); + } + if (tolb0) + *tolb0 += nlb - linebuf; + if (tolb1) + *tolb1 += nlb - linebuf; + if (togb0) + *togb0 += ngb - genbuf; + if (togb1) + *togb1 += ngb - genbuf; + linebuf = nlb; + genbuf = ngb; + LBSIZE += 4096; +} + +void * +smalloc(size_t size) +{ + void *vp; + + if ((vp = malloc(size)) == NULL) + error("no space"); + return vp; +} diff --git a/ex_tagio.c b/ex_tagio.c index f7570f5..73141a3 100644 --- a/ex_tagio.c +++ b/ex_tagio.c @@ -81,7 +81,7 @@ #ifdef FASTTAG #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_tagio.c 1.11 (gritter) 11/27/04"; +static char sccsid[] = "@(#)ex_tagio.c 1.12 (gritter) 8/4/05"; #endif #endif @@ -92,7 +92,7 @@ static char sccsid[] = "@(#)ex_tagio.c 1.11 (gritter) 11/27/04"; static long offset = -1; static long block = -1; static int bcnt = 0; -static int b_size = MAXBSIZE; +static int b_size; static char *ibuf; int @@ -101,6 +101,7 @@ topen(char *file, char *buf) int fd; struct stat statb; + b_size = MAXBSIZE; offset = -1; block = -1; if ((fd = open(file, O_RDONLY, 0)) < 0) diff --git a/ex_temp.c b/ex_temp.c index a1127f9..789a66d 100644 --- a/ex_temp.c +++ b/ex_temp.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_temp.c 1.24 (gritter) 11/24/04"; +static char sccsid[] = "@(#)ex_temp.c 1.26 (gritter) 8/4/05"; #endif #endif @@ -236,7 +236,7 @@ putline(void) } } tl = tline; - tline += (((lp - linebuf) + BNDRY - 1) >> SHFT) & 077776; + tline += (((lp - linebuf) + BNDRY - 1) >> SHFT) & TLNMSK; return (tl); } @@ -657,8 +657,9 @@ YANKreg(register int c) { register line *addr; register struct strreg *sp; - char savelb[LBSIZE]; + char *savelb; + savelb = smalloc(LBSIZE); if (isdigit(c)) kshift(); if (islower(c)) @@ -688,6 +689,7 @@ YANKreg(register int c) rbflush(); killed(); CP(linebuf,savelb); + free(savelb); } void diff --git a/ex_temp.h b/ex_temp.h index 66d68bc..0691cde 100644 --- a/ex_temp.h +++ b/ex_temp.h @@ -72,7 +72,7 @@ * * from ex_temp.h 7.4 (Berkeley) 5/31/85 * - * Sccsid @(#)ex_temp.h 1.9 (gritter) 8/4/05 + * Sccsid @(#)ex_temp.h 1.10 (gritter) 8/4/05 */ /* @@ -111,7 +111,8 @@ #define OFFBTS 7 /* 6 */ #define OFFMSK 0177 /* 077 */ #define SHFT 2 /* 3 */ -#else +#define TLNMSK 077776 +#else /* VMUNIX */ #ifdef LARGEF #define BLKMSK 017777777777 #else @@ -128,7 +129,8 @@ #define OFFBTS 10 #define OFFMSK 01777 #define SHFT 0 -#endif +#define TLNMSK 017777777776 +#endif /* VMUNIX */ /* * The editor uses three buffers into the temporary file (ed uses two diff --git a/ex_tune.h b/ex_tune.h index 92a728c..6ef8efb 100644 --- a/ex_tune.h +++ b/ex_tune.h @@ -72,7 +72,7 @@ * * from ex_tune.h 7.8.1 (2.11BSD) 1996/10/23 * - * Sccsid @(#)ex_tune.h 1.13 (gritter) 8/4/05 + * Sccsid @(#)ex_tune.h 1.14 (gritter) 8/4/05 */ /* @@ -111,8 +111,7 @@ /* * Maximums * - * The definition of LBSIZE should be the same as BUFSIZ (512 usually). - * Most other definitions are quite generous. + * Most definitions are quite generous. */ /* FNSIZE is also defined in expreserve.c */ #ifdef _POSIX_PATH_MAX @@ -121,20 +120,17 @@ #define FNSIZE 128 /* File name size */ #endif #ifdef VMUNIX -#define LBSIZE BUFSIZ /* Line buffer size */ #ifndef ESIZE /* see config.h */ #define ESIZE 512 /* Regular expression buffer size */ #endif #define CRSIZE BUFSIZ /* Crypt buffer size */ #else /* !VMUNIX */ #ifdef u370 -#define LBSIZE 4096 #ifndef ESIZE /* see config.h */ #define ESIZE 512 #endif #define CRSIZE 4096 #else -#define LBSIZE 512 /* Line length */ #ifndef ESIZE /* see config.h */ #define ESIZE 128 /* Size of compiled re */ #endif @@ -186,7 +182,7 @@ #undef NCARGS #ifndef VMUNIX #define NARGS 100 /* Maximum number of names in "next" */ -#define NCARGS LBSIZE /* Maximum arglist chars in "next" */ +#define NCARGS 512 /* Maximum arglist chars in "next" */ #else #define NCARGS 5120 #define NARGS (NCARGS/6) diff --git a/ex_unix.c b/ex_unix.c index 4be0e67..4ad17f9 100644 --- a/ex_unix.c +++ b/ex_unix.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_unix.c 1.16 (gritter) 11/23/04"; +static char sccsid[] = "@(#)ex_unix.c 1.17 (gritter) 8/4/05"; #endif #endif diff --git a/ex_v.c b/ex_v.c index cce1bba..969336c 100644 --- a/ex_v.c +++ b/ex_v.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_v.c 1.18 (gritter) 8/4/05"; +static char sccsid[] = "@(#)ex_v.c 1.19 (gritter) 8/4/05"; #endif #endif diff --git a/ex_vadj.c b/ex_vadj.c index 0bb62c7..d5ed06e 100644 --- a/ex_vadj.c +++ b/ex_vadj.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vadj.c 1.11 (gritter) 3/4/05"; +static char sccsid[] = "@(#)ex_vadj.c 1.14 (gritter) 8/4/05"; #endif #endif @@ -418,14 +418,14 @@ vopenup(int cnt, int could, int l) void vadjAL(int p, int cnt) { - cell *tlines[TUBELINES]; + cell **tlines = smalloc(TUBELINES * sizeof *tlines); register int from, to; #ifdef ADEBUG if (trace) tfixnl(), fprintf(trace, "vadjal(%d, %d)\n", p, cnt); #endif - copy(tlines, vtube, sizeof vtube); /*SASSIGN*/ + copy(tlines, vtube, TUBELINES * sizeof *tlines); /*SASSIGN*/ for (from = p, to = p + cnt; to <= WECHO; from++, to++) vtube[to] = tlines[from]; for (to = p; from <= WECHO; from++, to++) { @@ -437,6 +437,7 @@ vadjAL(int p, int cnt) * necessarily consistent with the rest of the display. */ vclrech(0); + free(tlines); } /* @@ -509,7 +510,7 @@ void vscroll(register int cnt) { register int from, to; - cell *tlines[TUBELINES]; + cell **tlines; #ifdef ADEBUG if (trace) @@ -519,7 +520,8 @@ vscroll(register int cnt) error(catgets(catd, 1, 219, "Internal error: vscroll")); if (cnt == 0) return; - copy(tlines, vtube, sizeof vtube); + tlines = smalloc(TUBELINES * sizeof *tlines); + copy(tlines, vtube, TUBELINES * sizeof *tlines); for (to = ZERO, from = ZERO + cnt; to <= WECHO - cnt; to++, from++) vtube[to] = tlines[from]; for (from = ZERO; to <= WECHO; to++, from++) { @@ -528,6 +530,7 @@ vscroll(register int cnt) } for (from = 0; from <= vcnt; from++) LINE(from) -= cnt; + free(tlines); } /* @@ -680,7 +683,7 @@ vredraw(register int p) { register int l; register line *tp; - char temp[LBSIZE]; + char *temp; bool anydl = 0; short oldhold = hold; @@ -697,6 +700,7 @@ vredraw(register int p) if (p < 0 /* || p > WECHO */) error(catgets(catd, 1, 221, "Internal error: vredraw")); + temp = smalloc(LBSIZE); /* * Trim the ragged edges (lines which are off the screen but * not yet logically discarded), save the current line, and @@ -790,6 +794,7 @@ vredraw(register int p) if (trace) tvliny(); #endif + free(temp); } /* @@ -845,7 +850,7 @@ vdellin(int p, int cnt, int l) void vadjDL(int p, int cnt) { - cell *tlines[TUBELINES]; + cell **tlines = smalloc(TUBELINES * sizeof *tlines); register int from, to; #ifdef ADEBUG @@ -857,13 +862,14 @@ vadjDL(int p, int cnt) * v7 compiler (released with phototypesetter for v6) * can't hack it. */ - copy(tlines, vtube, sizeof vtube); /*SASSIGN*/ + copy(tlines, vtube, TUBELINES * sizeof *tlines); /*SASSIGN*/ for (from = p + cnt, to = p; from <= WECHO; from++, to++) vtube[to] = tlines[from]; for (from = p; to <= WECHO; from++, to++) { vtube[to] = tlines[from]; vclrcell(vtube[to], WCOLS); } + free(tlines); } /* * Sync the screen, like redraw but more lazy and willing to leave @@ -896,7 +902,7 @@ void vsync1(register int p) { register int l; - char temp[LBSIZE]; + char *temp; register struct vlinfo *vp = &vlinfo[0]; short oldhold = hold; @@ -911,6 +917,7 @@ vsync1(register int p) } if (state == HARDOPEN || splitw) return; + temp = smalloc(LBSIZE); vscrap(); CP(temp, linebuf); if (vcnt == 0) @@ -960,6 +967,7 @@ vsync1(register int p) hold = oldhold; if (heldech) vclrech(0); + free(temp); } /* diff --git a/ex_version.c b/ex_version.c index a840840..c8e31a5 100644 --- a/ex_version.c +++ b/ex_version.c @@ -70,7 +70,7 @@ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Sccsid @(#)ex_version.c 1.136 (gritter) 8/4/05 + * Sccsid @(#)ex_version.c 1.139 (gritter) 8/4/05 */ #include "ex.h" @@ -90,43 +90,43 @@ printver(void) } /* SLIST */ /* -ex.c:static char sccsid[] = "@(#)ex.c 1.36 (gritter) 2/13/05"; -ex.h: * Sccsid @(#)ex.h 1.54 (gritter) 8/4/05 -ex_addr.c:static char sccsid[] = "@(#)ex_addr.c 1.10 (gritter) 2/17/05"; +ex.c:static char sccsid[] = "@(#)ex.c 1.37 (gritter) 8/4/05"; +ex.h: * Sccsid @(#)ex.h 1.55 (gritter) 8/4/05 +ex_addr.c:static char sccsid[] = "@(#)ex_addr.c 1.11 (gritter) 8/4/05"; ex_argv.h: * Sccsid @(#)ex_argv.h 1.9 (gritter) 8/4/05 ex_cmds.c:static char sccsid[] = "@(#)ex_cmds.c 1.22 (gritter) 2/18/05"; ex_cmds2.c:static char sccsid[] = "@(#)ex_cmds2.c 1.18 (gritter) 2/17/05"; -ex_cmdsub.c:static char sccsid[] = "@(#)ex_cmdsub.c 1.29 (gritter) 2/17/05"; +ex_cmdsub.c:static char sccsid[] = "@(#)ex_cmdsub.c 1.31 (gritter) 8/4/05"; ex_data.c:static char sccsid[] = "@(#)ex_data.c 1.14 (gritter) 11/23/04"; ex_extern.c:static char sccsid[] = "@(#)ex_extern.c 1.6 (gritter) 11/23/04"; -ex_get.c:static char sccsid[] = "@(#)ex_get.c 1.17 (gritter) 2/17/05"; -ex_io.c:static char sccsid[] = "@(#)ex_io.c 1.40 (gritter) 2/17/05"; -ex_proto.h: * Sccsid @(#)ex_proto.h 1.29 (gritter) 8/4/05 +ex_get.c:static char sccsid[] = "@(#)ex_get.c 1.18 (gritter) 8/4/05"; +ex_io.c:static char sccsid[] = "@(#)ex_io.c 1.41 (gritter) 8/4/05"; +ex_proto.h: * Sccsid @(#)ex_proto.h 1.31 (gritter) 8/4/05 ex_put.c:static char sccsid[] = "@(#)ex_put.c 1.32 (gritter) 2/17/05"; -ex_re.c:static char sccsid[] = "@(#)ex_re.c 1.56 (gritter) 3/25/05"; -ex_re.h: * Sccsid @(#)ex_re.h 1.23 (gritter) 8/4/05 +ex_re.c:static char sccsid[] = "@(#)ex_re.c 1.58 (gritter) 8/4/05"; +ex_re.h: * Sccsid @(#)ex_re.h 1.24 (gritter) 8/4/05 ex_set.c:static char sccsid[] = "@(#)ex_set.c 1.11 (gritter) 11/24/04"; -ex_subr.c:static char sccsid[] = "@(#)ex_subr.c 1.37 (gritter) 2/15/05"; -ex_tagio.c:static char sccsid[] = "@(#)ex_tagio.c 1.11 (gritter) 11/27/04"; -ex_temp.c:static char sccsid[] = "@(#)ex_temp.c 1.24 (gritter) 11/24/04"; -ex_temp.h: * Sccsid @(#)ex_temp.h 1.9 (gritter) 8/4/05 +ex_subr.c:static char sccsid[] = "@(#)ex_subr.c 1.39 (gritter) 8/4/05"; +ex_tagio.c:static char sccsid[] = "@(#)ex_tagio.c 1.12 (gritter) 8/4/05"; +ex_temp.c:static char sccsid[] = "@(#)ex_temp.c 1.26 (gritter) 8/4/05"; +ex_temp.h: * Sccsid @(#)ex_temp.h 1.10 (gritter) 8/4/05 ex_tty.c:static char sccsid[] = "@(#)ex_tty.c 1.30 (gritter) 8/4/05"; ex_tty.h: * Sccsid @(#)ex_tty.h 1.14 (gritter) 8/4/05 -ex_tune.h: * Sccsid @(#)ex_tune.h 1.13 (gritter) 8/4/05 -ex_unix.c:static char sccsid[] = "@(#)ex_unix.c 1.16 (gritter) 11/23/04"; -ex_v.c:static char sccsid[] = "@(#)ex_v.c 1.18 (gritter) 8/4/05"; -ex_vadj.c:static char sccsid[] = "@(#)ex_vadj.c 1.11 (gritter) 3/4/05"; +ex_tune.h: * Sccsid @(#)ex_tune.h 1.14 (gritter) 8/4/05 +ex_unix.c:static char sccsid[] = "@(#)ex_unix.c 1.17 (gritter) 8/4/05"; +ex_v.c:static char sccsid[] = "@(#)ex_v.c 1.19 (gritter) 8/4/05"; +ex_vadj.c:static char sccsid[] = "@(#)ex_vadj.c 1.14 (gritter) 8/4/05"; ex_vget.c:static char sccsid[] = "@(#)ex_vget.c 1.29 (gritter) 2/15/05"; -ex_vis.h: * Sccsid @(#)ex_vis.h 1.20 (gritter) 8/4/05 -ex_vmain.c:static char sccsid[] = "@(#)ex_vmain.c 1.29 (gritter) 2/17/05"; +ex_vis.h: * Sccsid @(#)ex_vis.h 1.21 (gritter) 8/4/05 +ex_vmain.c:static char sccsid[] = "@(#)ex_vmain.c 1.31 (gritter) 8/4/05"; ex_voper.c:static char sccsid[] = "@(#)ex_voper.c 1.27 (gritter) 2/15/05"; -ex_vops.c:static char sccsid[] = "@(#)ex_vops.c 1.26 (gritter) 1/13/05"; -ex_vops2.c:static char sccsid[] = "@(#)ex_vops2.c 1.34 (gritter) 1/12/05"; -ex_vops3.c:static char sccsid[] = "@(#)ex_vops3.c 1.19 (gritter) 1/2/05"; -ex_vput.c:static char sccsid[] = "@(#)ex_vput.c 1.49 (gritter) 2/15/05"; +ex_vops.c:static char sccsid[] = "@(#)ex_vops.c 1.28 (gritter) 8/4/05"; +ex_vops2.c:static char sccsid[] = "@(#)ex_vops2.c 1.35 (gritter) 8/4/05"; +ex_vops3.c:static char sccsid[] = "@(#)ex_vops3.c 1.21 (gritter) 8/4/05"; +ex_vput.c:static char sccsid[] = "@(#)ex_vput.c 1.50 (gritter) 8/4/05"; ex_vwind.c:static char sccsid[] = "@(#)ex_vwind.c 1.9 (gritter) 11/23/04"; expreserve.c:static char sccsid[] UNUSED = "@(#)expreserve.c 1.23 (gritter) 11/27/04"; -exrecover.c:static char sccsid[] UNUSED = "@(#)exrecover.c 1.21 (gritter) 11/27/04"; +exrecover.c:static char sccsid[] UNUSED = "@(#)exrecover.c 1.22 (gritter) 8/4/05"; mapmalloc.c: * Sccsid @(#)mapmalloc.c 1.6 (gritter) 6/19/05 printf.c:static char sccsid[] = "@(#)printf.c 1.15 (gritter) 12/1/04"; */ diff --git a/ex_vis.h b/ex_vis.h index df9a526..ebdb9cb 100644 --- a/ex_vis.h +++ b/ex_vis.h @@ -72,7 +72,7 @@ * * from ex_vis.h 7.4 (Berkeley) 5/31/85 * - * Sccsid @(#)ex_vis.h 1.20 (gritter) 8/4/05 + * Sccsid @(#)ex_vis.h 1.21 (gritter) 8/4/05 */ /* diff --git a/ex_vmain.c b/ex_vmain.c index ac07f92..08e1c63 100644 --- a/ex_vmain.c +++ b/ex_vmain.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vmain.c 1.29 (gritter) 2/17/05"; +static char sccsid[] = "@(#)ex_vmain.c 1.31 (gritter) 8/4/05"; #endif #endif @@ -1264,7 +1264,7 @@ vremote(int cnt, void (*f)(int), int arg) void vsave(void) { - char temp[LBSIZE]; + char *temp = smalloc(LBSIZE); CP(temp, linebuf); if (FIXUNDO && vundkind == VCHNG || vundkind == VCAPU) { @@ -1290,10 +1290,13 @@ vsave(void) * almost always be in a read buffer so this may well avoid disk i/o. */ getDOT(); - if (strcmp(linebuf, temp) == 0) + if (strcmp(linebuf, temp) == 0) { + free(temp); return; + } strcLIN(temp); putmark(dot); + free(temp); } #undef forbid diff --git a/ex_vops.c b/ex_vops.c index 4d28fac..f9a7aa5 100644 --- a/ex_vops.c +++ b/ex_vops.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vops.c 1.26 (gritter) 1/13/05"; +static char sccsid[] = "@(#)ex_vops.c 1.28 (gritter) 8/4/05"; #endif #endif @@ -143,7 +143,7 @@ vundo ( register int cnt; register line *addr; register char *cp; - char temp[LBSIZE]; + char *temp = smalloc(LBSIZE); bool savenote; int (*OO)(int); short oldhold = hold; @@ -246,6 +246,7 @@ vundo ( beep(); break; } + free(temp); } /* @@ -259,7 +260,7 @@ vmacchng(int fromvis) { line *savedot, *savedol; char *savecursor; - char savelb[LBSIZE]; + char *savelb; int nlines, more; /* register line *a1, *a2; */ /* char ch; */ /* DEBUG */ @@ -283,6 +284,7 @@ vmacchng(int fromvis) vch_mac = VC_ONECHANGE; break; case VC_ONECHANGE: + savelb = smalloc(LBSIZE); /* Save current state somewhere */ #ifdef TRACE vudump("before vmacchng hairy case"); @@ -330,6 +332,7 @@ vmacchng(int fromvis) #ifdef TRACE vudump("after vmacchng"); #endif + free(savelb); break; case VC_NOTINMAC: case VC_MANYCHANGE: diff --git a/ex_vops2.c b/ex_vops2.c index d7cd3fb..8039a0b 100644 --- a/ex_vops2.c +++ b/ex_vops2.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vops2.c 1.34 (gritter) 1/12/05"; +static char sccsid[] = "@(#)ex_vops2.c 1.35 (gritter) 8/4/05"; #endif #endif diff --git a/ex_vops3.c b/ex_vops3.c index 57cdebf..a855f16 100644 --- a/ex_vops3.c +++ b/ex_vops3.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vops3.c 1.19 (gritter) 1/2/05"; +static char sccsid[] = "@(#)ex_vops3.c 1.21 (gritter) 8/4/05"; #endif #endif @@ -118,7 +118,7 @@ llfind(bool pastatom, int cnt, void (*f)(int), line *limit) register int c; #endif register int rc = 0; - char save[LBSIZE]; + char *save = smalloc(LBSIZE); /* * Initialize, saving the current line buffer state @@ -284,6 +284,7 @@ begin: #endif ret: strcLIN(save); + free(save); return (rc); } @@ -424,7 +425,7 @@ lmatchp(line *addr) void lsmatch(char *cp) { - char save[LBSIZE]; + char *save = smalloc(LBSIZE); register char *sp = save; register char *scurs = cursor; @@ -457,6 +458,7 @@ lsmatch(char *cp) wdot = 0; wcursor = 0; cursor = scurs; + free(save); } int @@ -674,7 +676,7 @@ vswitch(int cnt) mbuf[1+n1] = '\0'; macpush(mbuf, 1); } else { /* cnt > 1 */ - char *mbuf = malloc(MAXDIGS + cnt*(mb_cur_max+1) + 5); + char *mbuf = smalloc(MAXDIGS + cnt*(mb_cur_max+1) + 5); register char *p = &mbuf[MAXDIGS + 1]; int num, n0, n1, m; diff --git a/ex_vput.c b/ex_vput.c index f2c9c3f..2f372ed 100644 --- a/ex_vput.c +++ b/ex_vput.c @@ -73,7 +73,7 @@ #ifndef lint #ifdef DOSCCS -static char sccsid[] = "@(#)ex_vput.c 1.49 (gritter) 2/15/05"; +static char sccsid[] = "@(#)ex_vput.c 1.50 (gritter) 8/4/05"; #endif #endif @@ -223,7 +223,7 @@ vclrech(bool didphys) splitw = 0; didphys = 1; } - if (didphys) + if (didphys && vtube) vclrcell(vtube[WECHO], WCOLS); heldech = 0; } diff --git a/exrecover.c b/exrecover.c index cca2250..0515ad0 100644 --- a/exrecover.c +++ b/exrecover.c @@ -83,7 +83,7 @@ char *copyright = "@(#) Copyright (c) 1980 Regents of the University of California.\n\ All rights reserved.\n"; #endif -static char sccsid[] UNUSED = "@(#)exrecover.c 1.21 (gritter) 11/27/04"; +static char sccsid[] UNUSED = "@(#)exrecover.c 1.22 (gritter) 8/4/05"; #endif /* from exrecover.c 7.9.2 (2.11BSD) 1996/10/26 */ @@ -210,6 +210,8 @@ main(int argc, char *argv[]) #ifdef VMUNIX poolsbrk(0); #endif + linebuf = calloc(LBSIZE = BUFSIZ<4096?4096:BUFSIZ, sizeof *linebuf); + genbuf = calloc(MAXBSIZE, sizeof *genbuf); #ifdef LANGMSG setlocale(LC_MESSAGES, ""); catd = catopen(CATNAME, NL_CAT_LOCALE);