summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-06 09:04:55 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-06 09:04:55 +0000
commit9d3aba7b37b275350a9fe0887871da9ba73dcbd7 (patch)
treeef6575073c089aaedbce47b63d13836552b4e556
parentb09c6b5d4a204dc89bbab702509b148602027ecd (diff)
downloadbusybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.tar.gz
busybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.tar.bz2
busybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.zip
more stuff
-rw-r--r--Makefile2
-rw-r--r--busybox.def.h6
-rw-r--r--chown.c5
-rw-r--r--coreutils/chown.c5
-rw-r--r--coreutils/dd.c2
-rw-r--r--coreutils/ls.c141
-rw-r--r--dd.c2
-rw-r--r--internal.h2
-rw-r--r--ls.c141
-rw-r--r--more.c19
-rw-r--r--util-linux/more.c19
-rw-r--r--utility.c16
12 files changed, 323 insertions, 37 deletions
diff --git a/Makefile b/Makefile
index 62c4ac6fe..535c4d7f8 100644
--- a/Makefile
+++ b/Makefile
@@ -37,4 +37,4 @@ distclean: clean
37 37
38force: 38force:
39 39
40$(OBJECTS): busybox.def.h Makefile 40$(OBJECTS): busybox.def.h internal.h Makefile
diff --git a/busybox.def.h b/busybox.def.h
index 2fc50b448..0149cc3bb 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -12,10 +12,10 @@
12#define BB_CLEAR 12#define BB_CLEAR
13//#define BB_CP 13//#define BB_CP
14#define BB_DATE 14#define BB_DATE
15//#define BB_DD 15#define BB_DD
16//#define BB_DESCEND 16//#define BB_DESCEND
17//#define BB_DF 17//#define BB_DF
18//#define BB_DMESG 18#define BB_DMESG
19//#define BB_DUTMP 19//#define BB_DUTMP
20//#define BB_DYADIC 20//#define BB_DYADIC
21#define BB_FALSE 21#define BB_FALSE
@@ -30,7 +30,7 @@
30//#define BB_LN 30//#define BB_LN
31//#define BB_LOADKMAP 31//#define BB_LOADKMAP
32////#define BB_LOSETUP 32////#define BB_LOSETUP
33//#define BB_LS 33#define BB_LS
34//#define BB_MAIN 34//#define BB_MAIN
35//#define BB_MAKEDEVS 35//#define BB_MAKEDEVS
36////#define BB_MATH 36////#define BB_MATH
diff --git a/chown.c b/chown.c
index 5c2ae0da6..5ac48f772 100644
--- a/chown.c
+++ b/chown.c
@@ -116,10 +116,7 @@ int chown_main(int argc, char **argv)
116 } 116 }
117 while (argc-- > 1) { 117 while (argc-- > 1) {
118 argv++; 118 argv++;
119 if (recursiveFlag==TRUE) 119 recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
120 recursiveAction( *argv, TRUE, fileAction, fileAction);
121 else
122 fileAction( *argv);
123 } 120 }
124 return(TRUE); 121 return(TRUE);
125} 122}
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 5c2ae0da6..5ac48f772 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -116,10 +116,7 @@ int chown_main(int argc, char **argv)
116 } 116 }
117 while (argc-- > 1) { 117 while (argc-- > 1) {
118 argv++; 118 argv++;
119 if (recursiveFlag==TRUE) 119 recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
120 recursiveAction( *argv, TRUE, fileAction, fileAction);
121 else
122 fileAction( *argv);
123 } 120 }
124 return(TRUE); 121 return(TRUE);
125} 122}
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 8f1b9d409..07f092cc2 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -59,7 +59,7 @@ static const PARAM params[] =
59static long getNum(const char * cp); 59static long getNum(const char * cp);
60 60
61extern int 61extern int
62dd_main (struct FileInfo *unused, int argc, char **argv) 62dd_main (int argc, char **argv)
63{ 63{
64 const char * str; 64 const char * str;
65 const PARAM * par; 65 const PARAM * par;
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 2566beea0..99cedf5f0 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -1,3 +1,136 @@
1/*
2 * Mini ls implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#if fooBar
23
24#include <stdio.h>
25#include <unistd.h>
26#include <dirent.h>
27#include "internal.h"
28
29
30static const char ls_usage[] = "ls [OPTION]... [FILE]...\n"
31"List information about the FILEs (the current directory by default).\n";
32
33int oneFlag=FALSE;
34int allFlag=FALSE;
35int directoryFlag=FALSE;
36int longFlag=FALSE;
37int typeFlag=FALSE;
38int dereferenceFlag=FALSE;
39int recursiveFlag=FALSE;
40
41static int fileAction(const char *fileName)
42{
43 if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0)
44 || (strcmp(fileName, ".") == 0)) ) {
45 return( TRUE);
46 }
47 //struct stat statBuf;
48 //if (stat(fileName, &statBuf) > 0) {
49 fprintf(stdout, "%s\n", fileName);
50 return( TRUE);
51 //}
52 //else {
53// perror(fileName);
54// return( FALSE);
55// }
56}
57
58static int dirAction(const char *fileName)
59{
60 DIR *dir;
61 struct dirent *entry;
62
63 fprintf(stdout, "%s\n", fileName);
64
65 dir = opendir( fileName);
66 if (!dir) {
67 perror("Can't open directory");
68 exit(FALSE);
69 }
70 while ((entry = readdir(dir)) != NULL) {
71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
72 }
73 return( TRUE);
74}
75
76int ls_main(int argc, char **argv)
77{
78 if (argc <= 1) {
79 char buf[NAME_MAX];
80 getcwd( buf, NAME_MAX);
81 dirAction( buf);
82 }
83
84 /* peel of the "ls" */
85 argc--;
86 argv++;
87
88 /* Parse any options */
89 while (**argv == '-') {
90 while (*++(*argv)) switch (**argv) {
91 case '1':
92 oneFlag = TRUE;
93 break;
94 case 'a':
95 allFlag = TRUE;
96 break;
97 case 'd':
98 directoryFlag = TRUE;
99 break;
100 case 'l':
101 longFlag = TRUE;
102 break;
103 case 'F':
104 typeFlag = TRUE;
105 break;
106 case 'L':
107 dereferenceFlag = TRUE;
108 break;
109 case 'R':
110 recursiveFlag = TRUE;
111 break;
112 default:
113 fprintf(stderr, "Usage: %s\n", ls_usage);
114 exit( FALSE);
115 }
116 argc--;
117 argv++;
118 }
119
120 /* Ok, ready to do the deed now */
121 fprintf(stderr, "B\n");
122 while (argc-- > 1) {
123 fprintf(stderr, "C\n");
124 recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction);
125 }
126 exit(TRUE);
127}
128
129
130
131#else
132
133
1#include "internal.h" 134#include "internal.h"
2/* 135/*
3 * tiny-ls.c version 0.1.0: A minimalist 'ls' 136 * tiny-ls.c version 0.1.0: A minimalist 'ls'
@@ -436,7 +569,7 @@ direrr:
436 closedir(dir); 569 closedir(dir);
437listerr: 570listerr:
438 newline(); 571 newline();
439 name_and_error(name); 572 perror(name);
440 return 1; 573 return 1;
441} 574}
442 575
@@ -465,7 +598,7 @@ const char ls_usage[] = "Usage: ls [-1a"
465 "] [filenames...]\n"; 598 "] [filenames...]\n";
466 599
467extern int 600extern int
468ls_main(struct FileInfo * not_used, int argc, char * * argv) 601ls_main(int argc, char * * argv)
469{ 602{
470 int argi=1, i; 603 int argi=1, i;
471 604
@@ -537,6 +670,8 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
537 return i; 670 return i;
538 671
539print_usage_message: 672print_usage_message:
540 usage(ls_usage); 673 fprintf(stderr, "Usage: %s\n", ls_usage);
541 return 1; 674 return 1;
542} 675}
676
677#endif
diff --git a/dd.c b/dd.c
index 8f1b9d409..07f092cc2 100644
--- a/dd.c
+++ b/dd.c
@@ -59,7 +59,7 @@ static const PARAM params[] =
59static long getNum(const char * cp); 59static long getNum(const char * cp);
60 60
61extern int 61extern int
62dd_main (struct FileInfo *unused, int argc, char **argv) 62dd_main (int argc, char **argv)
63{ 63{
64 const char * str; 64 const char * str;
65 const PARAM * par; 65 const PARAM * par;
diff --git a/internal.h b/internal.h
index 35581287c..5a8b0c57e 100644
--- a/internal.h
+++ b/internal.h
@@ -180,7 +180,7 @@ char *chunkstrdup(const char *str);
180void freeChunks(void); 180void freeChunks(void);
181int fullWrite(int fd, const char *buf, int len); 181int fullWrite(int fd, const char *buf, int len);
182int fullRead(int fd, char *buf, int len); 182int fullRead(int fd, char *buf, int len);
183int recursiveAction(const char *fileName, BOOL followLinks, 183int recursiveAction(const char *fileName, BOOL recurse, BOOL followLinks,
184 int (*fileAction) (const char *fileName), 184 int (*fileAction) (const char *fileName),
185 int (*dirAction) (const char *fileName)); 185 int (*dirAction) (const char *fileName));
186 186
diff --git a/ls.c b/ls.c
index 2566beea0..99cedf5f0 100644
--- a/ls.c
+++ b/ls.c
@@ -1,3 +1,136 @@
1/*
2 * Mini ls implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#if fooBar
23
24#include <stdio.h>
25#include <unistd.h>
26#include <dirent.h>
27#include "internal.h"
28
29
30static const char ls_usage[] = "ls [OPTION]... [FILE]...\n"
31"List information about the FILEs (the current directory by default).\n";
32
33int oneFlag=FALSE;
34int allFlag=FALSE;
35int directoryFlag=FALSE;
36int longFlag=FALSE;
37int typeFlag=FALSE;
38int dereferenceFlag=FALSE;
39int recursiveFlag=FALSE;
40
41static int fileAction(const char *fileName)
42{
43 if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0)
44 || (strcmp(fileName, ".") == 0)) ) {
45 return( TRUE);
46 }
47 //struct stat statBuf;
48 //if (stat(fileName, &statBuf) > 0) {
49 fprintf(stdout, "%s\n", fileName);
50 return( TRUE);
51 //}
52 //else {
53// perror(fileName);
54// return( FALSE);
55// }
56}
57
58static int dirAction(const char *fileName)
59{
60 DIR *dir;
61 struct dirent *entry;
62
63 fprintf(stdout, "%s\n", fileName);
64
65 dir = opendir( fileName);
66 if (!dir) {
67 perror("Can't open directory");
68 exit(FALSE);
69 }
70 while ((entry = readdir(dir)) != NULL) {
71 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
72 }
73 return( TRUE);
74}
75
76int ls_main(int argc, char **argv)
77{
78 if (argc <= 1) {
79 char buf[NAME_MAX];
80 getcwd( buf, NAME_MAX);
81 dirAction( buf);
82 }
83
84 /* peel of the "ls" */
85 argc--;
86 argv++;
87
88 /* Parse any options */
89 while (**argv == '-') {
90 while (*++(*argv)) switch (**argv) {
91 case '1':
92 oneFlag = TRUE;
93 break;
94 case 'a':
95 allFlag = TRUE;
96 break;
97 case 'd':
98 directoryFlag = TRUE;
99 break;
100 case 'l':
101 longFlag = TRUE;
102 break;
103 case 'F':
104 typeFlag = TRUE;
105 break;
106 case 'L':
107 dereferenceFlag = TRUE;
108 break;
109 case 'R':
110 recursiveFlag = TRUE;
111 break;
112 default:
113 fprintf(stderr, "Usage: %s\n", ls_usage);
114 exit( FALSE);
115 }
116 argc--;
117 argv++;
118 }
119
120 /* Ok, ready to do the deed now */
121 fprintf(stderr, "B\n");
122 while (argc-- > 1) {
123 fprintf(stderr, "C\n");
124 recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction);
125 }
126 exit(TRUE);
127}
128
129
130
131#else
132
133
1#include "internal.h" 134#include "internal.h"
2/* 135/*
3 * tiny-ls.c version 0.1.0: A minimalist 'ls' 136 * tiny-ls.c version 0.1.0: A minimalist 'ls'
@@ -436,7 +569,7 @@ direrr:
436 closedir(dir); 569 closedir(dir);
437listerr: 570listerr:
438 newline(); 571 newline();
439 name_and_error(name); 572 perror(name);
440 return 1; 573 return 1;
441} 574}
442 575
@@ -465,7 +598,7 @@ const char ls_usage[] = "Usage: ls [-1a"
465 "] [filenames...]\n"; 598 "] [filenames...]\n";
466 599
467extern int 600extern int
468ls_main(struct FileInfo * not_used, int argc, char * * argv) 601ls_main(int argc, char * * argv)
469{ 602{
470 int argi=1, i; 603 int argi=1, i;
471 604
@@ -537,6 +670,8 @@ ls_main(struct FileInfo * not_used, int argc, char * * argv)
537 return i; 670 return i;
538 671
539print_usage_message: 672print_usage_message:
540 usage(ls_usage); 673 fprintf(stderr, "Usage: %s\n", ls_usage);
541 return 1; 674 return 1;
542} 675}
676
677#endif
diff --git a/more.c b/more.c
index 2ea709278..6ac553e6b 100644
--- a/more.c
+++ b/more.c
@@ -25,12 +25,15 @@
25 25
26const char more_usage[] = "[file ...]"; 26const char more_usage[] = "[file ...]";
27 27
28 28//#define ERASE_STUFF
29 29
30extern int more_main(int argc, char **argv) 30extern int more_main(int argc, char **argv)
31{ 31{
32 int c, lines=0; 32 int c, lines=0;
33 int next_page=0, rows = 24, cols=79; 33 int next_page=0, rows = 24;
34#ifdef ERASE_STUFF
35 int cols=79;
36#endif
34 struct stat st; 37 struct stat st;
35 FILE *file = stdin; 38 FILE *file = stdin;
36 39
@@ -42,28 +45,30 @@ extern int more_main(int argc, char **argv)
42 argv++; 45 argv++;
43 46
44 while (argc-- > 0) { 47 while (argc-- > 0) {
45 file = fopen(*argv, "r"); 48 file = fopen(*argv, "r");
46 if (file == NULL) { 49 if (file == NULL) {
47 perror(*argv); 50 perror("Can't open file");
48 return(FALSE); 51 return(FALSE);
49 } 52 }
50 fstat(fileno(file), &st); 53 fstat(fileno(file), &st);
54 fprintf(stderr, "hi\n");
51 55
52 while ((c = getc(file)) != EOF) { 56 while ((c = getc(file)) != EOF) {
53 if ( next_page ) { 57 if ( next_page ) {
54 int len=0; 58 int len=0;
55 next_page = 0; 59 next_page = 0;
56 lines=0; 60 lines=0;
57 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", 61 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)",
58 (int) (100*( (double) ftell(file) / (double) st.st_size )), 62 (int) (100*( (double) ftell(file) / (double) st.st_size )),
59 st.st_size); 63 st.st_size);
60 fflush(stdout); 64 fflush(stdout);
61 getc( stdin); 65 getc( stdin);
62#if 0 66#ifdef ERASE_STUFF
67 /* Try to erase the "More" message */
63 while(len-- > 0) 68 while(len-- > 0)
64 putc('\b', stdout); 69 putc('\b', stdout);
65 while(len++ < cols) 70 while(len++ < cols)
66 putc('8', stdout); 71 putc(' ', stdout);
67 while(len-- > 0) 72 while(len-- > 0)
68 putc('\b', stdout); 73 putc('\b', stdout);
69 fflush(stdout); 74 fflush(stdout);
diff --git a/util-linux/more.c b/util-linux/more.c
index 2ea709278..6ac553e6b 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -25,12 +25,15 @@
25 25
26const char more_usage[] = "[file ...]"; 26const char more_usage[] = "[file ...]";
27 27
28 28//#define ERASE_STUFF
29 29
30extern int more_main(int argc, char **argv) 30extern int more_main(int argc, char **argv)
31{ 31{
32 int c, lines=0; 32 int c, lines=0;
33 int next_page=0, rows = 24, cols=79; 33 int next_page=0, rows = 24;
34#ifdef ERASE_STUFF
35 int cols=79;
36#endif
34 struct stat st; 37 struct stat st;
35 FILE *file = stdin; 38 FILE *file = stdin;
36 39
@@ -42,28 +45,30 @@ extern int more_main(int argc, char **argv)
42 argv++; 45 argv++;
43 46
44 while (argc-- > 0) { 47 while (argc-- > 0) {
45 file = fopen(*argv, "r"); 48 file = fopen(*argv, "r");
46 if (file == NULL) { 49 if (file == NULL) {
47 perror(*argv); 50 perror("Can't open file");
48 return(FALSE); 51 return(FALSE);
49 } 52 }
50 fstat(fileno(file), &st); 53 fstat(fileno(file), &st);
54 fprintf(stderr, "hi\n");
51 55
52 while ((c = getc(file)) != EOF) { 56 while ((c = getc(file)) != EOF) {
53 if ( next_page ) { 57 if ( next_page ) {
54 int len=0; 58 int len=0;
55 next_page = 0; 59 next_page = 0;
56 lines=0; 60 lines=0;
57 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", 61 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)",
58 (int) (100*( (double) ftell(file) / (double) st.st_size )), 62 (int) (100*( (double) ftell(file) / (double) st.st_size )),
59 st.st_size); 63 st.st_size);
60 fflush(stdout); 64 fflush(stdout);
61 getc( stdin); 65 getc( stdin);
62#if 0 66#ifdef ERASE_STUFF
67 /* Try to erase the "More" message */
63 while(len-- > 0) 68 while(len-- > 0)
64 putc('\b', stdout); 69 putc('\b', stdout);
65 while(len++ < cols) 70 while(len++ < cols)
66 putc('8', stdout); 71 putc(' ', stdout);
67 while(len-- > 0) 72 while(len-- > 0)
68 putc('\b', stdout); 73 putc('\b', stdout);
69 fflush(stdout); 74 fflush(stdout);
diff --git a/utility.c b/utility.c
index a516355b6..c8f58e8f2 100644
--- a/utility.c
+++ b/utility.c
@@ -473,7 +473,7 @@ fullRead(int fd, char * buf, int len)
473 * by the fileAction and dirAction function pointers). 473 * by the fileAction and dirAction function pointers).
474 */ 474 */
475int 475int
476recursiveAction( const char *fileName, BOOL followLinks, 476recursiveAction( const char *fileName, BOOL recurse, BOOL followLinks,
477 int (*fileAction)(const char* fileName), 477 int (*fileAction)(const char* fileName),
478 int (*dirAction)(const char* fileName)) 478 int (*dirAction)(const char* fileName))
479{ 479{
@@ -481,6 +481,18 @@ recursiveAction( const char *fileName, BOOL followLinks,
481 struct stat statbuf; 481 struct stat statbuf;
482 struct dirent* next; 482 struct dirent* next;
483 483
484 if (!recurse && S_ISDIR(statbuf.st_mode)) {
485 if (dirAction==NULL)
486 return(TRUE);
487 else
488 return(dirAction(fileName));
489 } else {
490 if (fileAction==NULL)
491 return(TRUE);
492 else
493 return(fileAction(fileName));
494 }
495
484 if (followLinks) 496 if (followLinks)
485 status = stat(fileName, &statbuf); 497 status = stat(fileName, &statbuf);
486 else 498 else
@@ -504,7 +516,7 @@ recursiveAction( const char *fileName, BOOL followLinks,
504 continue; 516 continue;
505 } 517 }
506 sprintf(nextFile, "%s/%s", fileName, next->d_name); 518 sprintf(nextFile, "%s/%s", fileName, next->d_name);
507 status = recursiveAction(nextFile, followLinks, fileAction, dirAction); 519 status = recursiveAction(nextFile, TRUE, followLinks, fileAction, dirAction);
508 if (status < 0) { 520 if (status < 0) {
509 closedir(dir); 521 closedir(dir);
510 return(FALSE); 522 return(FALSE);