aboutsummaryrefslogtreecommitdiff
path: root/coreutils/ls.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-19 22:26:25 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-19 22:26:25 +0000
commitf5a3838e2ffb1e75b878f9ac48a6951d4d209f5a (patch)
treeb131d6e42bbbcce9eee2417f9ae52de6e5a4374e /coreutils/ls.c
parente674eb78e4cbd52d4b044d8e67d1620b32244e8f (diff)
downloadbusybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.tar.gz
busybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.tar.bz2
busybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.zip
More stuff
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r--coreutils/ls.c137
1 files changed, 1 insertions, 136 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index a8e7e048a..0cde1960f 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -1,138 +1,4 @@
1/* 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// I started writing a newer small one, but it isn't done yet....
23// -Erik
24#if fooBar
25
26#include <stdio.h>
27#include <unistd.h>
28#include <dirent.h>
29#include "internal.h"
30
31
32static const char ls_usage[] = "ls [OPTION]... [FILE]...\n"
33"List information about the FILEs (the current directory by default).\n";
34
35int oneFlag=FALSE;
36int allFlag=FALSE;
37int directoryFlag=FALSE;
38int longFlag=FALSE;
39int typeFlag=FALSE;
40int dereferenceFlag=FALSE;
41int recursiveFlag=FALSE;
42
43static int fileAction(const char *fileName)
44{
45 if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0)
46 || (strcmp(fileName, ".") == 0)) ) {
47 return( TRUE);
48 }
49 //struct stat statBuf;
50 //if (stat(fileName, &statBuf) > 0) {
51 fprintf(stdout, "%s\n", fileName);
52 return( TRUE);
53 //}
54 //else {
55// perror(fileName);
56// return( FALSE);
57// }
58}
59
60static int dirAction(const char *fileName)
61{
62 DIR *dir;
63 struct dirent *entry;
64
65 fprintf(stdout, "%s\n", fileName);
66
67 dir = opendir( fileName);
68 if (!dir) {
69 perror("Can't open directory");
70 exit(FALSE);
71 }
72 while ((entry = readdir(dir)) != NULL) {
73 recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
74 }
75 return( TRUE);
76}
77
78int ls_main(int argc, char **argv)
79{
80 if (argc <= 1) {
81 char buf[NAME_MAX];
82 getcwd( buf, NAME_MAX);
83 dirAction( buf);
84 }
85
86 /* peel of the "ls" */
87 argc--;
88 argv++;
89
90 /* Parse any options */
91 while (**argv == '-') {
92 while (*++(*argv)) switch (**argv) {
93 case '1':
94 oneFlag = TRUE;
95 break;
96 case 'a':
97 allFlag = TRUE;
98 break;
99 case 'd':
100 directoryFlag = TRUE;
101 break;
102 case 'l':
103 longFlag = TRUE;
104 break;
105 case 'F':
106 typeFlag = TRUE;
107 break;
108 case 'L':
109 dereferenceFlag = TRUE;
110 break;
111 case 'R':
112 recursiveFlag = TRUE;
113 break;
114 default:
115 usage (ls_usage);
116 }
117 argc--;
118 argv++;
119 }
120
121 /* Ok, ready to do the deed now */
122 fprintf(stderr, "B\n");
123 while (argc-- > 1) {
124 fprintf(stderr, "C\n");
125 recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction);
126 }
127 exit(TRUE);
128}
129
130
131
132#else
133
134
135/*
136 * tiny-ls.c version 0.1.0: A minimalist 'ls' 2 * tiny-ls.c version 0.1.0: A minimalist 'ls'
137 * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> 3 * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
138 * 4 *
@@ -571,7 +437,7 @@ listerr:
571 return 1; 437 return 1;
572} 438}
573 439
574const char ls_usage[] = "ls [-1a" 440static const char ls_usage[] = "ls [-1a"
575#ifdef FEATURE_TIMESTAMPS 441#ifdef FEATURE_TIMESTAMPS
576 "c" 442 "c"
577#endif 443#endif
@@ -672,4 +538,3 @@ print_usage_message:
672 exit( FALSE); 538 exit( FALSE);
673} 539}
674 540
675#endif