[PATCH text-utils/line] trivial rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



line: Rewrite of line(1), making the already simple program a bit more readable. It does not need
 a global variable and a function other than main() to do the work.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 text-utils/line.c |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/text-utils/line.c b/text-utils/line.c
index 08c53fa..7555c71 100644
--- a/text-utils/line.c
+++ b/text-utils/line.c
@@ -4,33 +4,31 @@
  * Gunnar Ritter, Freiburg i. Br., Germany, December 2000.
  *
  * Public Domain.
+ * 
+ * Rewritten by Davidlohr Bueso <dave@xxxxxxx> (July, 2010).
  */
 
-#include	<stdio.h>
-#include	<unistd.h>
+#include <stdio.h>
+#include <unistd.h>
 
-static int	status;		/* exit status */
-
-static void
-doline(int fd)
+int main(void)
 {
 	char c;
 
-	for (;;) {
-		if (read(fd, &c, 1) <= 0) {
-			status = 1;
-			break;
+	while(1) {
+		if(read(0, &c, 1) <= 0) {
+			perror("read");
+			return 1;
 		}
-		if (c == '\n')
+		
+		else if(c == '\n')
 			break;
-		putchar(c);
+
+		else
+			printf("%c", c);
 	}
-	putchar('\n');
-}
 
-int
-main(int argc, char **argv)
-{
-	doline(0);
-	return status;
+	printf("\n");
+
+	return 0;
 }
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux