mirror of git://git.suckless.org/sbase
ed: Add bytecount print to 'w' command
This commit is contained in:
parent
0df09d5ba0
commit
714601b29d
1
TODO
1
TODO
|
@ -55,7 +55,6 @@ ed
|
||||||
line
|
line
|
||||||
.
|
.
|
||||||
1g/^$/p
|
1g/^$/p
|
||||||
* w command doesn't print byte count.
|
|
||||||
* Editing huge files doesn't work well.
|
* Editing huge files doesn't work well.
|
||||||
|
|
||||||
printf
|
printf
|
||||||
|
|
9
ed.c
9
ed.c
|
@ -623,14 +623,18 @@ static void
|
||||||
dowrite(const char *fname, int trunc)
|
dowrite(const char *fname, int trunc)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
size_t bytecount = 0;
|
||||||
int i, line;
|
int i, line;
|
||||||
|
|
||||||
if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
|
if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
|
||||||
error("input/output error");
|
error("input/output error");
|
||||||
|
|
||||||
line = curln;
|
line = curln;
|
||||||
for (i = line1; i <= line2; ++i)
|
for (i = line1; i <= line2; ++i) {
|
||||||
fputs(gettxt(i), fp);
|
gettxt(i);
|
||||||
|
bytecount += text.siz - 1;
|
||||||
|
fputs(text.str, fp);
|
||||||
|
}
|
||||||
|
|
||||||
curln = line2;
|
curln = line2;
|
||||||
if (fclose(fp))
|
if (fclose(fp))
|
||||||
|
@ -638,6 +642,7 @@ dowrite(const char *fname, int trunc)
|
||||||
strcpy(savfname, fname);
|
strcpy(savfname, fname);
|
||||||
modflag = 0;
|
modflag = 0;
|
||||||
curln = line;
|
curln = line;
|
||||||
|
printf("%zu\n", bytecount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue