more stuff
authorEric Andersen <andersen@codepoet.org>
Wed, 6 Oct 1999 09:04:55 +0000 (09:04 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 6 Oct 1999 09:04:55 +0000 (09:04 -0000)
12 files changed:
Makefile
busybox.def.h
chown.c
coreutils/chown.c
coreutils/dd.c
coreutils/ls.c
dd.c
internal.h
ls.c
more.c
util-linux/more.c
utility.c

index 62c4ac6..535c4d7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,4 +37,4 @@ distclean: clean
 
 force:
 
-$(OBJECTS):  busybox.def.h Makefile
+$(OBJECTS):  busybox.def.h internal.h Makefile
index 2fc50b4..0149cc3 100644 (file)
 #define BB_CLEAR
 //#define BB_CP
 #define BB_DATE
-//#define BB_DD
+#define BB_DD
 //#define BB_DESCEND
 //#define BB_DF
-//#define BB_DMESG
+#define BB_DMESG
 //#define BB_DUTMP
 //#define BB_DYADIC
 #define BB_FALSE
@@ -30,7 +30,7 @@
 //#define BB_LN
 //#define BB_LOADKMAP
 ////#define BB_LOSETUP
-//#define BB_LS
+#define BB_LS
 //#define BB_MAIN
 //#define BB_MAKEDEVS
 ////#define BB_MATH
diff --git a/chown.c b/chown.c
index 5c2ae0d..5ac48f7 100644 (file)
--- a/chown.c
+++ b/chown.c
@@ -116,10 +116,7 @@ int chown_main(int argc, char **argv)
     }
     while (argc-- > 1) {
        argv++;
-       if (recursiveFlag==TRUE) 
-           recursiveAction( *argv, TRUE, fileAction, fileAction);
-       else
-           fileAction( *argv);
+       recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
     }
     return(TRUE);
 }
index 5c2ae0d..5ac48f7 100644 (file)
@@ -116,10 +116,7 @@ int chown_main(int argc, char **argv)
     }
     while (argc-- > 1) {
        argv++;
-       if (recursiveFlag==TRUE) 
-           recursiveAction( *argv, TRUE, fileAction, fileAction);
-       else
-           fileAction( *argv);
+       recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
     }
     return(TRUE);
 }
index 8f1b9d4..07f092c 100644 (file)
@@ -59,7 +59,7 @@ static const PARAM    params[] =
 static long    getNum(const char * cp);
 
 extern int
-dd_main (struct FileInfo *unused, int argc, char **argv)
+dd_main (int argc, char **argv)
 {
        const char *    str;
        const PARAM *   par;
index 2566bee..99cedf5 100644 (file)
@@ -1,3 +1,136 @@
+/*
+ * Mini ls implementation for busybox
+ *
+ * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#if fooBar
+
+#include <stdio.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "internal.h"
+
+
+static const char ls_usage[] = "ls [OPTION]... [FILE]...\n"
+"List information about the FILEs (the current directory by default).\n";
+
+int oneFlag=FALSE;
+int allFlag=FALSE;
+int directoryFlag=FALSE;
+int longFlag=FALSE;
+int typeFlag=FALSE;
+int dereferenceFlag=FALSE;
+int recursiveFlag=FALSE;
+
+static int fileAction(const char *fileName)
+{
+    if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0) 
+               || (strcmp(fileName, ".") == 0)) ) {
+       return( TRUE);
+    }
+    //struct stat statBuf;
+    //if (stat(fileName, &statBuf) > 0) {
+       fprintf(stdout, "%s\n", fileName);
+       return( TRUE);
+    //}
+    //else {
+//     perror(fileName);
+//     return( FALSE);
+//    }
+}
+
+static int dirAction(const char *fileName)
+{
+    DIR *dir;
+    struct dirent *entry;
+    
+    fprintf(stdout, "%s\n", fileName);
+
+    dir = opendir( fileName);
+    if (!dir) {
+       perror("Can't open directory");
+       exit(FALSE);
+    }
+    while ((entry = readdir(dir)) != NULL) {
+       recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
+    }
+    return( TRUE);
+}
+
+int ls_main(int argc, char **argv)
+{
+    if (argc <= 1) {
+       char buf[NAME_MAX];
+       getcwd( buf, NAME_MAX);
+       dirAction( buf); 
+    }
+
+    /* peel of the "ls" */
+    argc--;
+    argv++;
+
+    /* Parse any options */
+    while (**argv == '-') {
+       while (*++(*argv)) switch (**argv) {
+           case '1':
+               oneFlag = TRUE;
+               break;
+           case 'a':
+               allFlag = TRUE;
+               break;
+           case 'd':
+               directoryFlag = TRUE;
+               break;
+           case 'l':
+               longFlag = TRUE;
+               break;
+           case 'F':
+               typeFlag = TRUE;
+               break;
+           case 'L':
+               dereferenceFlag = TRUE;
+               break;
+           case 'R':
+               recursiveFlag = TRUE;
+               break;
+           default:
+               fprintf(stderr, "Usage: %s\n", ls_usage);
+               exit( FALSE);
+       }
+       argc--;
+       argv++;
+    }
+    
+    /* Ok, ready to do the deed now */
+    fprintf(stderr, "B\n");
+    while (argc-- > 1) {
+       fprintf(stderr, "C\n");
+       recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction);
+    }
+    exit(TRUE);
+}
+
+
+
+#else
+
+
 #include "internal.h"
 /*
  * tiny-ls.c version 0.1.0: A minimalist 'ls'
@@ -436,7 +569,7 @@ direrr:
        closedir(dir);  
 listerr:
        newline();
-       name_and_error(name);
+       perror(name);
        return 1;
 }
 
@@ -465,7 +598,7 @@ const char  ls_usage[] = "Usage: ls [-1a"
        "] [filenames...]\n";
 
 extern int
-ls_main(struct FileInfo * not_used, int argc, char * * argv)
+ls_main(int argc, char * * argv)
 {
        int argi=1, i;
        
@@ -537,6 +670,8 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
        return i;
 
 print_usage_message:
-       usage(ls_usage);
+       fprintf(stderr, "Usage: %s\n", ls_usage);
        return 1;
 }
+
+#endif
diff --git a/dd.c b/dd.c
index 8f1b9d4..07f092c 100644 (file)
--- a/dd.c
+++ b/dd.c
@@ -59,7 +59,7 @@ static const PARAM    params[] =
 static long    getNum(const char * cp);
 
 extern int
-dd_main (struct FileInfo *unused, int argc, char **argv)
+dd_main (int argc, char **argv)
 {
        const char *    str;
        const PARAM *   par;
index 3558128..5a8b0c5 100644 (file)
@@ -180,7 +180,7 @@ char *chunkstrdup(const char *str);
 void freeChunks(void);
 int fullWrite(int fd, const char *buf, int len);
 int fullRead(int fd, char *buf, int len);
-int recursiveAction(const char *fileName, BOOL followLinks,
+int recursiveAction(const char *fileName, BOOL recurse, BOOL followLinks,
          int (*fileAction) (const char *fileName),
          int (*dirAction) (const char *fileName));
 
diff --git a/ls.c b/ls.c
index 2566bee..99cedf5 100644 (file)
--- a/ls.c
+++ b/ls.c
@@ -1,3 +1,136 @@
+/*
+ * Mini ls implementation for busybox
+ *
+ * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#if fooBar
+
+#include <stdio.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "internal.h"
+
+
+static const char ls_usage[] = "ls [OPTION]... [FILE]...\n"
+"List information about the FILEs (the current directory by default).\n";
+
+int oneFlag=FALSE;
+int allFlag=FALSE;
+int directoryFlag=FALSE;
+int longFlag=FALSE;
+int typeFlag=FALSE;
+int dereferenceFlag=FALSE;
+int recursiveFlag=FALSE;
+
+static int fileAction(const char *fileName)
+{
+    if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0) 
+               || (strcmp(fileName, ".") == 0)) ) {
+       return( TRUE);
+    }
+    //struct stat statBuf;
+    //if (stat(fileName, &statBuf) > 0) {
+       fprintf(stdout, "%s\n", fileName);
+       return( TRUE);
+    //}
+    //else {
+//     perror(fileName);
+//     return( FALSE);
+//    }
+}
+
+static int dirAction(const char *fileName)
+{
+    DIR *dir;
+    struct dirent *entry;
+    
+    fprintf(stdout, "%s\n", fileName);
+
+    dir = opendir( fileName);
+    if (!dir) {
+       perror("Can't open directory");
+       exit(FALSE);
+    }
+    while ((entry = readdir(dir)) != NULL) {
+       recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
+    }
+    return( TRUE);
+}
+
+int ls_main(int argc, char **argv)
+{
+    if (argc <= 1) {
+       char buf[NAME_MAX];
+       getcwd( buf, NAME_MAX);
+       dirAction( buf); 
+    }
+
+    /* peel of the "ls" */
+    argc--;
+    argv++;
+
+    /* Parse any options */
+    while (**argv == '-') {
+       while (*++(*argv)) switch (**argv) {
+           case '1':
+               oneFlag = TRUE;
+               break;
+           case 'a':
+               allFlag = TRUE;
+               break;
+           case 'd':
+               directoryFlag = TRUE;
+               break;
+           case 'l':
+               longFlag = TRUE;
+               break;
+           case 'F':
+               typeFlag = TRUE;
+               break;
+           case 'L':
+               dereferenceFlag = TRUE;
+               break;
+           case 'R':
+               recursiveFlag = TRUE;
+               break;
+           default:
+               fprintf(stderr, "Usage: %s\n", ls_usage);
+               exit( FALSE);
+       }
+       argc--;
+       argv++;
+    }
+    
+    /* Ok, ready to do the deed now */
+    fprintf(stderr, "B\n");
+    while (argc-- > 1) {
+       fprintf(stderr, "C\n");
+       recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction);
+    }
+    exit(TRUE);
+}
+
+
+
+#else
+
+
 #include "internal.h"
 /*
  * tiny-ls.c version 0.1.0: A minimalist 'ls'
@@ -436,7 +569,7 @@ direrr:
        closedir(dir);  
 listerr:
        newline();
-       name_and_error(name);
+       perror(name);
        return 1;
 }
 
@@ -465,7 +598,7 @@ const char  ls_usage[] = "Usage: ls [-1a"
        "] [filenames...]\n";
 
 extern int
-ls_main(struct FileInfo * not_used, int argc, char * * argv)
+ls_main(int argc, char * * argv)
 {
        int argi=1, i;
        
@@ -537,6 +670,8 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
        return i;
 
 print_usage_message:
-       usage(ls_usage);
+       fprintf(stderr, "Usage: %s\n", ls_usage);
        return 1;
 }
+
+#endif
diff --git a/more.c b/more.c
index 2ea7092..6ac553e 100644 (file)
--- a/more.c
+++ b/more.c
 
 const char more_usage[] = "[file ...]";
 
-
+//#define ERASE_STUFF
 
 extern int more_main(int argc, char **argv)
 {
     int c, lines=0;
-    int next_page=0, rows = 24, cols=79;
+    int next_page=0, rows = 24;
+#ifdef ERASE_STUFF
+    int cols=79;
+#endif
     struct stat st;    
     FILE *file = stdin;
 
@@ -42,28 +45,30 @@ extern int more_main(int argc, char **argv)
     argv++;
 
     while (argc-- > 0) {
-       file = fopen(*argv, "r");
+           file = fopen(*argv, "r");
        if (file == NULL) {
-           perror(*argv);
+           perror("Can't open file");
            return(FALSE);
        }
        fstat(fileno(file), &st);
+       fprintf(stderr, "hi\n");
 
        while ((c = getc(file)) != EOF) {
            if ( next_page ) {
                int len=0;
                next_page = 0;
                lines=0;
-               len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", 
+               len = fprintf(stdout, "--More-- (%d%% of %ld bytes)", 
                        (int) (100*( (double) ftell(file) / (double) st.st_size )),
                        st.st_size);
                fflush(stdout);
                getc( stdin);
-#if 0
+#ifdef ERASE_STUFF
+               /* Try to erase the "More" message */
                while(len-- > 0)
                    putc('\b', stdout);
                while(len++ < cols)
-                   putc('8', stdout);
+                   putc(' ', stdout);
                while(len-- > 0)
                    putc('\b', stdout);
                fflush(stdout);
index 2ea7092..6ac553e 100644 (file)
 
 const char more_usage[] = "[file ...]";
 
-
+//#define ERASE_STUFF
 
 extern int more_main(int argc, char **argv)
 {
     int c, lines=0;
-    int next_page=0, rows = 24, cols=79;
+    int next_page=0, rows = 24;
+#ifdef ERASE_STUFF
+    int cols=79;
+#endif
     struct stat st;    
     FILE *file = stdin;
 
@@ -42,28 +45,30 @@ extern int more_main(int argc, char **argv)
     argv++;
 
     while (argc-- > 0) {
-       file = fopen(*argv, "r");
+           file = fopen(*argv, "r");
        if (file == NULL) {
-           perror(*argv);
+           perror("Can't open file");
            return(FALSE);
        }
        fstat(fileno(file), &st);
+       fprintf(stderr, "hi\n");
 
        while ((c = getc(file)) != EOF) {
            if ( next_page ) {
                int len=0;
                next_page = 0;
                lines=0;
-               len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", 
+               len = fprintf(stdout, "--More-- (%d%% of %ld bytes)", 
                        (int) (100*( (double) ftell(file) / (double) st.st_size )),
                        st.st_size);
                fflush(stdout);
                getc( stdin);
-#if 0
+#ifdef ERASE_STUFF
+               /* Try to erase the "More" message */
                while(len-- > 0)
                    putc('\b', stdout);
                while(len++ < cols)
-                   putc('8', stdout);
+                   putc(' ', stdout);
                while(len-- > 0)
                    putc('\b', stdout);
                fflush(stdout);
index a516355..c8f58e8 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -473,7 +473,7 @@ fullRead(int fd, char * buf, int len)
  * by the fileAction and dirAction function pointers).
  */
 int
-recursiveAction( const char *fileName, BOOL followLinks,
+recursiveAction( const char *fileName, BOOL recurse, BOOL followLinks,
        int (*fileAction)(const char* fileName), 
        int (*dirAction)(const char* fileName))
 {
@@ -481,6 +481,18 @@ recursiveAction( const char *fileName, BOOL followLinks,
     struct stat     statbuf;
     struct dirent*  next;
 
+    if (!recurse && S_ISDIR(statbuf.st_mode)) {
+       if (dirAction==NULL)
+           return(TRUE);
+       else
+           return(dirAction(fileName));
+    } else {
+       if (fileAction==NULL)
+           return(TRUE);
+       else
+           return(fileAction(fileName));
+    }
+
     if (followLinks)
        status = stat(fileName, &statbuf);
     else
@@ -504,7 +516,7 @@ recursiveAction( const char *fileName, BOOL followLinks,
                    continue;
                }
                sprintf(nextFile, "%s/%s", fileName, next->d_name);
-               status = recursiveAction(nextFile, followLinks, fileAction, dirAction);
+               status = recursiveAction(nextFile, TRUE, followLinks, fileAction, dirAction);
                if (status < 0) {
                    closedir(dir);
                    return(FALSE);