commit 3817f78f8781c184441fb17066bd87bde145fd1f
parent 120d8179202f359b4cca399ed396a205e28b01c2
Author: Christoph Lohmann <20h@r-36.net>
Date: Mon, 23 Apr 2012 16:32:41 +0200
Moving back to the stone age.
Diffstat:
2 files changed, 9 insertions(+), 46 deletions(-)
diff --git a/basename.1 b/basename.1
@@ -3,10 +3,6 @@
basename \- strip leading path component
.SH SYNOPSIS
.B basename
-.RB [ \-a ]
-.RB [ \-z ]
-.RB [ \-s
-.IR suffix ]
.I string
.RI [ suffix ]
.SH DESCRIPTION
@@ -16,17 +12,6 @@ prints the
with any leading path components, and the
.IR suffix ,
removed.
-.SH OPTIONS
-.TP
-.BI \-a
-multiple arguments will each be treated as strings
-.TP
-.BI \-s " suffix"
-specifies the suffix that should be removed
-.TP
-.BI \-z
-output will be separated with NUL
-.TP
.SH SEE ALSO
.IR dirname (1),
.IR basename (3)
diff --git a/basename.c b/basename.c
@@ -14,28 +14,16 @@ char *argv0;
void
usage(void)
{
- eprintf("usage: %s [-ahz] [-s suffix] name [suffix]\n",
- basename(argv0));
+ eprintf("usage: %s name [suffix]\n", basename(argv0));
}
int
main(int argc, char *argv[])
{
- char *s, *suffix = NULL;
- size_t n, sn;
- bool aflag = false, zflag = false;
+ char *s;
+ size_t n;
ARGBEGIN {
- case 'a':
- aflag = true;
- break;
- case 's':
- suffix = EARGF(usage());
- break;
- case 'z':
- zflag = true;
- break;
- case 'h':
default:
usage();
} ARGEND;
@@ -43,23 +31,13 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
- if (!aflag && argc == 2)
- suffix = argv[1];
- if (suffix)
- sn = strlen(suffix);
-
- for (; argc > 0; argc--, argv++) {
- s = basename(argv[0]);
- if (suffix) {
- n = strlen(s) - sn;
- if (!strcmp(&s[n], suffix))
- s[n] = '\0';
- }
- printf("%s%c", s, (zflag)? '\0' : '\n');
-
- if (!aflag)
- break;
+ s = basename(argv[0]);
+ if (suffix) {
+ n = strlen(s) - strlen(suffix);
+ if (!strcmp(&s[n], suffix))
+ s[n] = '\0';
}
+ puts(s);
return EXIT_SUCCESS;
}