commit 714601b29d6ed52aaf111cde34c524bec997a555
Author: Tait Hoyem <[email protected]>
AuthorDate: Mon Sep 14 22:36:15 2020 +0000
Commit: Michael Forney <[email protected]>
CommitDate: Fri Sep 18 19:58:22 2020 -0700
ed: Add bytecount print to 'w' command
diff --git a/TODO b/TODO
index 59c9440..92acfa3 100644
--- a/TODO
+++ b/TODO
@@ -55,7 +55,6 @@ ed
line
.
1g/^$/p
-* w command doesn't print byte count.
* Editing huge files doesn't work well.
printf
diff --git a/ed.c b/ed.c
index cee9687..8e6fa9a 100644
--- a/ed.c
+++ b/ed.c
@@ -623,14 +623,18 @@ static void
dowrite(const char *fname, int trunc)
{
FILE *fp;
+ size_t bytecount = 0;
int i, line;
if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
error("input/output error");
line = curln;
- for (i = line1; i <= line2; ++i)
- fputs(gettxt(i), fp);
+ for (i = line1; i <= line2; ++i) {
+ gettxt(i);
+ bytecount += text.siz - 1;
+ fputs(text.str, fp);
+ }
curln = line2;
if (fclose(fp))
@@ -638,6 +642,7 @@ dowrite(const char *fname, int trunc)
strcpy(savfname, fname);
modflag = 0;
curln = line;
+ printf("%zu\n", bytecount);
}
static void