diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-06 09:04:55 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-06 09:04:55 +0000 |
commit | 9d3aba7b37b275350a9fe0887871da9ba73dcbd7 (patch) | |
tree | ef6575073c089aaedbce47b63d13836552b4e556 /coreutils/ls.c | |
parent | b09c6b5d4a204dc89bbab702509b148602027ecd (diff) | |
download | busybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.tar.gz busybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.tar.bz2 busybox-w32-9d3aba7b37b275350a9fe0887871da9ba73dcbd7.zip |
more stuff
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r-- | coreutils/ls.c | 141 |
1 files changed, 138 insertions, 3 deletions
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 | |||
30 | static const char ls_usage[] = "ls [OPTION]... [FILE]...\n" | ||
31 | "List information about the FILEs (the current directory by default).\n"; | ||
32 | |||
33 | int oneFlag=FALSE; | ||
34 | int allFlag=FALSE; | ||
35 | int directoryFlag=FALSE; | ||
36 | int longFlag=FALSE; | ||
37 | int typeFlag=FALSE; | ||
38 | int dereferenceFlag=FALSE; | ||
39 | int recursiveFlag=FALSE; | ||
40 | |||
41 | static 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 | |||
58 | static 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 | |||
76 | int 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); |
437 | listerr: | 570 | listerr: |
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 | ||
467 | extern int | 600 | extern int |
468 | ls_main(struct FileInfo * not_used, int argc, char * * argv) | 601 | ls_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 | ||
539 | print_usage_message: | 672 | print_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 | ||