diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/basename.c | 4 | ||||
-rw-r--r-- | coreutils/dirname.c | 163 | ||||
-rw-r--r-- | coreutils/echo.c | 11 | ||||
-rw-r--r-- | coreutils/ls.c | 35 | ||||
-rw-r--r-- | coreutils/mknod.c | 4 |
5 files changed, 73 insertions, 144 deletions
diff --git a/coreutils/basename.c b/coreutils/basename.c index 06e27663f..5fe5e0f03 100644 --- a/coreutils/basename.c +++ b/coreutils/basename.c | |||
@@ -34,8 +34,10 @@ extern int basename_main(int argc, char **argv) | |||
34 | argv++; | 34 | argv++; |
35 | 35 | ||
36 | s1=*argv+strlen(*argv)-1; | 36 | s1=*argv+strlen(*argv)-1; |
37 | if (*s1 == '/') | 37 | while (s1 && *s1 == '/') { |
38 | *s1 = '\0'; | 38 | *s1 = '\0'; |
39 | s1=*argv+strlen(*argv)-1; | ||
40 | } | ||
39 | s = strrchr(*argv, '/'); | 41 | s = strrchr(*argv, '/'); |
40 | printf("%s\n", (s)? s + 1 : *argv); | 42 | printf("%s\n", (s)? s + 1 : *argv); |
41 | exit(TRUE); | 43 | exit(TRUE); |
diff --git a/coreutils/dirname.c b/coreutils/dirname.c index 77cb664ac..528b89a56 100644 --- a/coreutils/dirname.c +++ b/coreutils/dirname.c | |||
@@ -1,146 +1,45 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * This is temporary -- needs to be rewritten to be tighter */ | 3 | * Mini dirname implementation for busybox |
4 | /* | 4 | * |
5 | * Copyright (c) 1991, 1993, 1994 | 5 | * Copyright (C) 2000 by Lineo, inc. |
6 | * The Regents of the University of California. All rights reserved. | 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
7 | * | 12 | * |
8 | * Redistribution and use in source and binary forms, with or without | 13 | * This program is distributed in the hope that it will be useful, |
9 | * modification, are permitted provided that the following conditions | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * are met: | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | * 1. Redistributions of source code must retain the above copyright | 16 | * General Public License for more details. |
12 | * notice, this list of conditions and the following disclaimer. | 17 | * |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 18 | * You should have received a copy of the GNU General Public License |
14 | * notice, this list of conditions and the following disclaimer in the | 19 | * along with this program; if not, write to the Free Software |
15 | * documentation and/or other materials provided with the distribution. | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by the University of | ||
19 | * California, Berkeley and its contributors. | ||
20 | * 4. Neither the name of the University nor the names of its contributors | ||
21 | * may be used to endorse or promote products derived from this software | ||
22 | * without specific prior written permission. | ||
23 | * | 21 | * |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
34 | * SUCH DAMAGE. | ||
35 | */ | 22 | */ |
36 | |||
37 | #if 0 | ||
38 | #ifndef lint | ||
39 | static char copyright[] = "@(#) Copyright (c) 1991, 1993, 1994\n\ | ||
40 | The Regents of the University of California. All rights reserved.\n"; | ||
41 | #endif /* not lint */ | ||
42 | |||
43 | #ifndef lint | ||
44 | static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; | ||
45 | #endif /* not lint */ | ||
46 | #endif /* #if 0 */ | ||
47 | |||
48 | #include "internal.h" | 23 | #include "internal.h" |
49 | #include <stdio.h> | 24 | #include <stdio.h> |
50 | #include <stdlib.h> | ||
51 | #include <unistd.h> | ||
52 | 25 | ||
53 | void dirname_usage() | 26 | extern int dirname_main(int argc, char **argv) |
54 | { | 27 | { |
28 | char* s; | ||
55 | 29 | ||
56 | (void) fprintf(stderr, "usage: dirname path\n"); | 30 | if ((argc < 2) || (**(argv + 1) == '-')) { |
57 | exit(1); | 31 | usage("dirname [file ...]\n"); |
58 | } | ||
59 | |||
60 | extern int dirname_main(argc, argv) | ||
61 | int argc; | ||
62 | char **argv; | ||
63 | { | ||
64 | char *p; | ||
65 | int ch; | ||
66 | |||
67 | while ((ch = getopt(argc, argv, "")) != -1) | ||
68 | switch (ch) { | ||
69 | case '?': | ||
70 | default: | ||
71 | dirname_usage(); | ||
72 | } | ||
73 | argc -= optind; | ||
74 | argv += optind; | ||
75 | |||
76 | if (argc != 1) | ||
77 | dirname_usage(); | ||
78 | |||
79 | /* | ||
80 | * (1) If string is //, skip steps (2) through (5). | ||
81 | * (2) If string consists entirely of slash characters, string | ||
82 | * shall be set to a single slash character. In this case, | ||
83 | * skip steps (3) through (8). | ||
84 | */ | ||
85 | for (p = *argv;; ++p) { | ||
86 | if (!*p) { | ||
87 | if (p > *argv) | ||
88 | (void) printf("/\n"); | ||
89 | else | ||
90 | (void) printf(".\n"); | ||
91 | exit(0); | ||
92 | } | ||
93 | if (*p != '/') | ||
94 | break; | ||
95 | } | 32 | } |
33 | argv++; | ||
96 | 34 | ||
97 | /* | 35 | s=*argv+strlen(*argv)-1; |
98 | * (3) If there are any trailing slash characters in string, they | 36 | while (s && *s == '/') { |
99 | * shall be removed. | 37 | *s = '\0'; |
100 | */ | 38 | s=*argv+strlen(*argv)-1; |
101 | for (; *p; ++p); | ||
102 | while (*--p == '/') | ||
103 | continue; | ||
104 | *++p = '\0'; | ||
105 | |||
106 | /* | ||
107 | * (4) If there are no slash characters remaining in string, | ||
108 | * string shall be set to a single period character. In this | ||
109 | * case skip steps (5) through (8). | ||
110 | * | ||
111 | * (5) If there are any trailing nonslash characters in string, | ||
112 | * they shall be removed. | ||
113 | */ | ||
114 | while (--p >= *argv) | ||
115 | if (*p == '/') | ||
116 | break; | ||
117 | ++p; | ||
118 | if (p == *argv) { | ||
119 | (void) printf(".\n"); | ||
120 | exit(0); | ||
121 | } | 39 | } |
122 | 40 | s = strrchr(*argv, '/'); | |
123 | /* | 41 | if (s && *s) |
124 | * (6) If the remaining string is //, it is implementation defined | 42 | *s = '\0'; |
125 | * whether steps (7) and (8) are skipped or processed. | 43 | printf("%s\n", (s)? *argv : "."); |
126 | * | 44 | exit(TRUE); |
127 | * This case has already been handled, as part of steps (1) and (2). | ||
128 | */ | ||
129 | |||
130 | /* | ||
131 | * (7) If there are any trailing slash characters in string, they | ||
132 | * shall be removed. | ||
133 | */ | ||
134 | while (--p >= *argv) | ||
135 | if (*p != '/') | ||
136 | break; | ||
137 | ++p; | ||
138 | |||
139 | /* | ||
140 | * (8) If the remaining string is empty, string shall be set to | ||
141 | * a single slash character. | ||
142 | */ | ||
143 | *p = '\0'; | ||
144 | (void) printf("%s\n", p == *argv ? "/" : *argv); | ||
145 | exit(0); | ||
146 | } | 45 | } |
diff --git a/coreutils/echo.c b/coreutils/echo.c index 91f17aa0f..2405d0ae1 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c | |||
@@ -25,6 +25,14 @@ | |||
25 | #include "internal.h" | 25 | #include "internal.h" |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | 27 | ||
28 | static const char uname_usage[] = | ||
29 | "echo [-neE] [ARG ...]\n\n" | ||
30 | "Prints the specified ARGs to stdout\n\n" | ||
31 | "Options:\n" | ||
32 | "\t-n\tsuppress trailing newline\n" | ||
33 | "\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n" | ||
34 | "\t-E\tdisable interpretation of backslash-escaped characters\n"; | ||
35 | |||
28 | extern int | 36 | extern int |
29 | echo_main(int argc, char** argv) | 37 | echo_main(int argc, char** argv) |
30 | { | 38 | { |
@@ -45,6 +53,9 @@ echo_main(int argc, char** argv) | |||
45 | } else if (strcmp(p, "-E")==0) { | 53 | } else if (strcmp(p, "-E")==0) { |
46 | eflag = 0; | 54 | eflag = 0; |
47 | } | 55 | } |
56 | else if (strncmp(p, "--", 2)==0) { | ||
57 | usage( uname_usage); | ||
58 | } | ||
48 | else break; | 59 | else break; |
49 | ap++; | 60 | ap++; |
50 | } | 61 | } |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 3e010503c..0c7f6522c 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -88,7 +88,6 @@ | |||
88 | #define DISP_FULLTIME 32 /* show extended time display */ | 88 | #define DISP_FULLTIME 32 /* show extended time display */ |
89 | #define DIR_NOLIST 64 /* show directory as itself, not contents */ | 89 | #define DIR_NOLIST 64 /* show directory as itself, not contents */ |
90 | #define DISP_DIRNAME 128 /* show directory name (for internal use) */ | 90 | #define DISP_DIRNAME 128 /* show directory name (for internal use) */ |
91 | #define DIR_RECURSE 256 /* -R (not yet implemented) */ | ||
92 | 91 | ||
93 | #ifndef MAJOR | 92 | #ifndef MAJOR |
94 | #define MAJOR(dev) (((dev)>>8)&0xff) | 93 | #define MAJOR(dev) (((dev)>>8)&0xff) |
@@ -450,10 +449,33 @@ static const char ls_usage[] = "ls [-1a" | |||
450 | #ifdef BB_FEATURE_LS_FILETYPES | 449 | #ifdef BB_FEATURE_LS_FILETYPES |
451 | "F" | 450 | "F" |
452 | #endif | 451 | #endif |
453 | #ifdef FEATURE_RECURSIVE | 452 | "] [filenames...]\n\n" |
454 | "R" | 453 | "Options:\n" |
454 | "\t-a\tdo not hide entries starting with .\n" | ||
455 | #ifdef BB_FEATURE_LS_TIMESTAMPS | ||
456 | "\t-c\twith -l: show ctime (the time of last\n" | ||
457 | "\t\tmodification of file status information)\n" | ||
458 | #endif | ||
459 | "\t-d\tlist directory entries instead of contents\n" | ||
460 | #ifdef BB_FEATURE_LS_TIMESTAMPS | ||
461 | "\t-e\tlist both full date and full time\n" | ||
455 | #endif | 462 | #endif |
456 | "] [filenames...]\n"; | 463 | "\t-l\tuse a long listing format\n" |
464 | "\t-n\tlist numeric UIDs and GIDs instead of names\n" | ||
465 | #ifdef BB_FEATURE_LS_FILETYPES | ||
466 | "\t-p\tappend indicator (one of /=@|) to entries\n" | ||
467 | #endif | ||
468 | #ifdef BB_FEATURE_LS_TIMESTAMPS | ||
469 | "\t-u\twith -l: show access time (the time of last\n" | ||
470 | "\t\taccess of the file)\n" | ||
471 | #endif | ||
472 | "\t-x\tlist entries by lines instead of by columns\n" | ||
473 | "\t-A\tdo not list implied . and ..\n" | ||
474 | "\t-C\tlist entries by columns\n" | ||
475 | #ifdef BB_FEATURE_LS_FILETYPES | ||
476 | "\t-F\tappend indicator (one of */=@|) to entries\n" | ||
477 | #endif | ||
478 | ; | ||
457 | 479 | ||
458 | extern int ls_main(int argc, char **argv) | 480 | extern int ls_main(int argc, char **argv) |
459 | { | 481 | { |
@@ -508,11 +530,6 @@ extern int ls_main(int argc, char **argv) | |||
508 | case 'd': | 530 | case 'd': |
509 | opts |= DIR_NOLIST; | 531 | opts |= DIR_NOLIST; |
510 | break; | 532 | break; |
511 | #ifdef FEATURE_RECURSIVE | ||
512 | case 'R': | ||
513 | opts |= DIR_RECURSE; | ||
514 | break; | ||
515 | #endif | ||
516 | #ifdef BB_FEATURE_LS_TIMESTAMPS | 533 | #ifdef BB_FEATURE_LS_TIMESTAMPS |
517 | case 'u': | 534 | case 'u': |
518 | time_fmt = TIME_ACCESS; | 535 | time_fmt = TIME_ACCESS; |
diff --git a/coreutils/mknod.c b/coreutils/mknod.c index b11a81f2a..40f508d33 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c | |||
@@ -70,7 +70,7 @@ int mknod_main(int argc, char **argv) | |||
70 | 70 | ||
71 | if (mknod(argv[1], mode, dev) != 0) { | 71 | if (mknod(argv[1], mode, dev) != 0) { |
72 | perror(argv[1]); | 72 | perror(argv[1]); |
73 | return (FALSE); | 73 | exit (FALSE); |
74 | } | 74 | } |
75 | return (TRUE); | 75 | exit (TRUE); |
76 | } | 76 | } |