ex (not vi) can now edit files with lines of arbitrary length.

This commit is contained in:
Gunnar Ritter
2005-08-04 15:23:39 +00:00
parent 2b70d8e5eb
commit b0ff1d6b3e
26 changed files with 183 additions and 105 deletions

View File

@@ -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