[hackers] [sbase][PATCH] Make 'w' command print byte count

From: Tait Hoyem <code_AT_tait.tech>
Date: Mon, 07 Sep 2020 16:07:21 +0000

diff --git a/ed.c b/ed.c
index cee9687..82b9c2c 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -623,14 +623,16 @@ static void
 dowrite(const char *fname, int trunc)
 {
         FILE *fp;
- int i, line;
+ int i, line, bytecount;

         if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
                 error("input/output error");

         line = curln;
- for (i = line1; i <= line2; ++i)
+ for (i = line1; i <= line2; ++i) {
+ bytecount += strlen(gettxt(i));
                 fputs(gettxt(i), fp);
+ }

         curln = line2;
         if (fclose(fp))
_AT_@ -638,6 +640,7 @@ dowrite(const char *fname, int trunc)
         strcpy(savfname, fname);
         modflag = 0;
         curln = line;
+ printf("%d\n", bytecount);
 }

 static void

diff --git a/TODO b/TODO
index 59c9440..92acfa3 100644
--- a/TODO
+++ b/TODO
_AT_@ -55,7 +55,6 @@ ed
     line
     .
     1g/^$/p
-* w command doesn't print byte count.
 * Editing huge files doesn't work well.

 printf
Received on Mon Sep 07 2020 - 18:07:21 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 07 2020 - 18:12:26 CEST