[PATCH 2/3] text-utils/column.c: error messaging & exit codes

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

 



Human understandable error messages along with symbolic exit
codes to comply with coding standard.
---
 text-utils/column.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/text-utils/column.c b/text-utils/column.c
index 6371a98..12a94f5 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -159,7 +159,7 @@ main(int argc, char **argv)
 			(void)fclose(fp);
 		} else {
 			warn("%s", *argv);
-			eval = 1;
+			eval = EXIT_FAILURE;
 		}
 
 	if (!entries)
@@ -174,7 +174,7 @@ main(int argc, char **argv)
 	else
 		r_columnate();
 	if (ferror(stdout) || fclose(stdout))
-		eval = 1;
+		eval = EXIT_FAILURE;
 	exit(eval);
 }
 
@@ -280,7 +280,7 @@ maketbl()
 					       * sizeof(wchar_t *))) ||
 			!(lens = realloc(lens, ((u_int)maxcols + DEFCOLS)
 					       * sizeof(int))))
-			err(1, NULL);
+			err(EXIT_FAILURE, _("out of memory?"));
 		    memset((char *)lens + maxcols * sizeof(int),
 			   0, DEFCOLS * sizeof(int));
 		    maxcols += DEFCOLS;
@@ -313,7 +313,7 @@ input(fp)
 	FILE *fp;
 {
 	static int maxentry;
-	int len;
+	int len, lineno = 1, reportedline = 0;
 	wchar_t *p, buf[MAXLINELEN];
 
 	if (!list)
@@ -323,10 +323,14 @@ input(fp)
 		if (!*p)
 			continue;
 		if (!(p = wcschr(p, '\n')) && !(feof(fp))) {
-			warnx(_("line too long"));
-			eval = 1;
+			if (reportedline < lineno) {
+				warnx(_("line %d is too long, output will be truncated"), lineno);
+				reportedline = lineno;
+			}
+			eval = EXIT_FAILURE;
 			continue;
 		}
+		lineno++;
 		if (!(feof(fp)))
 			*p = '\0';
 		len = wcs_width(buf);	/* len = p - buf; */
@@ -336,7 +340,7 @@ input(fp)
 			maxentry += DEFNUM;
 			if (!(list = realloc(list,
 			    (u_int)maxentry * sizeof(wchar_t *))))
-				err(1, NULL);
+				err(EXIT_FAILURE, _("out of memory?"));
 		}
 		list[entries++] = wcsdup(buf);
 	}
@@ -391,7 +395,7 @@ emalloc(size)
 	char *p;
 
 	if (!(p = malloc(size)))
-		err(1, NULL);
+		err(EXIT_FAILURE, _("out of memory?"));
 	memset(p, 0, size);
 	return (p);
 }
-- 
1.7.3.1

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