Add suffix stripping support to basename
-Erik
This commit is contained in:
parent
0a027e6880
commit
ac130e1dca
12
Changelog
12
Changelog
@ -15,15 +15,17 @@
|
||||
does force anyway
|
||||
* tail can now accept -<num> commands (e.g. -10) for better
|
||||
compatibility with the standard tail command
|
||||
* added a simple id implementation; doesn't support supp. groups yet
|
||||
* logname used getlogin(3) which uses utmp under the hood. Now it behaves.
|
||||
* added a simple id implementation; doesn't support sup. groups yet
|
||||
* logname used getlogin(3) which uses utmp. Now it doesn't.
|
||||
* whoami used getpwuid(3) which uses libc NSS. Now it behaves.
|
||||
* Due to the license change, I can now use minix code. Minux tr replaces
|
||||
the BSD derived tr, saving 4k and eliminating bsearch(3) from the
|
||||
list of used Libc symbols.
|
||||
* Due to the license change, I can now use minix code. Minux tr
|
||||
replaces the BSD derived tr, saving 4k and eliminating bsearch(3)
|
||||
from the list of used Libc symbols.
|
||||
* Add support for "noatime" and "nodiratime" mount flags to mount.
|
||||
* Changed 'umount -f' to mean force, and actually use umount2.
|
||||
* Changed 'umount -l' to mean "Do not free loop device".
|
||||
* Fixed basename to support stripping of suffixes. Patch thanks
|
||||
to xiong jianxin <jxiong@uiuc.edu>
|
||||
* More doc updates
|
||||
|
||||
-Erik
|
||||
|
20
basename.c
20
basename.c
@ -26,12 +26,14 @@
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [FILE ...]\n"
|
||||
usage("basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE(s).\n"
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
@ -40,10 +42,20 @@ extern int basename_main(int argc, char **argv)
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if (m>=n && strncmp(s+m-n, *argv, n)==0)
|
||||
s[m-n] = '\0';
|
||||
}
|
||||
printf("%s\n", s);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,14 @@
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [FILE ...]\n"
|
||||
usage("basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE(s).\n"
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
@ -40,10 +42,20 @@ extern int basename_main(int argc, char **argv)
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if (m>=n && strncmp(s+m-n, *argv, n)==0)
|
||||
s[m-n] = '\0';
|
||||
}
|
||||
printf("%s\n", s);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,10 @@ uname, uniq, update, uptime, usleep, wc, whoami, yes, zcat, [
|
||||
|
||||
=item basename
|
||||
|
||||
Usage: basename [file ...]
|
||||
Usage: basename FILE [SUFFIX]
|
||||
|
||||
Strips directory path and suffixes from FILE(s).
|
||||
Strips directory path and suffixes from FILE.
|
||||
If specified, also removes any trailing SUFFIX.
|
||||
|
||||
Example:
|
||||
|
||||
@ -81,6 +82,8 @@ Example:
|
||||
foo
|
||||
$ basename /usr/local/bin/
|
||||
bin
|
||||
$ basename /foo/bar.txt .txt
|
||||
bar
|
||||
|
||||
-------------------------------
|
||||
|
||||
@ -1878,4 +1881,4 @@ Enrique Zanardi <ezanardi@ull.es>
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: busybox.pod,v 1.28 2000/05/05 19:49:33 erik Exp $
|
||||
# $Id: busybox.pod,v 1.29 2000/05/10 05:00:31 erik Exp $
|
||||
|
Loading…
Reference in New Issue
Block a user