[dev] [lsx] Assume cwd if no arguments are given.

From: Petr Sabata <psabata_AT_redhat.com>
Date: Mon, 23 May 2011 16:53:23 +0200

This makes lsx a bit more usable.

Signed-off-by: Petr Sabata <psabata_AT_redhat.com>

---
 lsx.c |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/lsx.c b/lsx.c
index 5060b9c..7fa5e35 100644
--- a/lsx.c
+++ b/lsx.c
@@ -8,28 +8,36 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-int
-main(int argc, char *argv[]) {
-	int i;
+void
+lsx(char *dirpath) {
 	struct dirent *dp;
 	struct stat s;
 	DIR *dir;
 
+	if((dir = opendir(dirpath))) {
+		fchdir(dirfd(dir));
+		do
+			if((dp = readdir(dir))
+				&& (stat(dp->d_name, &s) != -1)
+				&& S_ISREG (s.st_mode)
+				&& !access(dp->d_name, X_OK))
+				puts(dp->d_name);
+		while(dp);
+		closedir(dir);
+	}
+}
+
+int
+main(int argc, char *argv[]) {
+	int i;
+
 	if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
 		fputs("lsx-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
 		exit(EXIT_SUCCESS);
 	}
-	for(i = 0; i < argc; i++)
-		if((dir = opendir(argv[i]))) {
-			fchdir(dirfd(dir));
-			do
-				if((dp = readdir(dir))
-					&& (stat(dp->d_name, &s) != -1)
-					&& S_ISREG (s.st_mode)
-					&& !access(dp->d_name, X_OK))
-					puts(dp->d_name);
-			while(dp);
-			closedir(dir);
-		}
+	if (argc == 1)
+		lsx(".");
+	for(i = 1; i < argc; i++)
+		lsx(argv[i]);
 	return 0;
 }
-- 
1.7.4.4
Received on Mon May 23 2011 - 16:53:23 CEST

This archive was generated by hypermail 2.2.0 : Mon May 23 2011 - 17:00:06 CEST