Moving back to the stone age.
This commit is contained in:
parent
120d817920
commit
3817f78f87
15
basename.1
15
basename.1
@ -3,10 +3,6 @@
|
|||||||
basename \- strip leading path component
|
basename \- strip leading path component
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B basename
|
.B basename
|
||||||
.RB [ \-a ]
|
|
||||||
.RB [ \-z ]
|
|
||||||
.RB [ \-s
|
|
||||||
.IR suffix ]
|
|
||||||
.I string
|
.I string
|
||||||
.RI [ suffix ]
|
.RI [ suffix ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
@ -16,17 +12,6 @@ prints the
|
|||||||
with any leading path components, and the
|
with any leading path components, and the
|
||||||
.IR suffix ,
|
.IR suffix ,
|
||||||
removed.
|
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
|
.SH SEE ALSO
|
||||||
.IR dirname (1),
|
.IR dirname (1),
|
||||||
.IR basename (3)
|
.IR basename (3)
|
||||||
|
40
basename.c
40
basename.c
@ -14,28 +14,16 @@ char *argv0;
|
|||||||
void
|
void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-ahz] [-s suffix] name [suffix]\n",
|
eprintf("usage: %s name [suffix]\n", basename(argv0));
|
||||||
basename(argv0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *s, *suffix = NULL;
|
char *s;
|
||||||
size_t n, sn;
|
size_t n;
|
||||||
bool aflag = false, zflag = false;
|
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'a':
|
|
||||||
aflag = true;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
suffix = EARGF(usage());
|
|
||||||
break;
|
|
||||||
case 'z':
|
|
||||||
zflag = true;
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
@ -43,23 +31,13 @@ main(int argc, char *argv[])
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (!aflag && argc == 2)
|
s = basename(argv[0]);
|
||||||
suffix = argv[1];
|
if (suffix) {
|
||||||
if (suffix)
|
n = strlen(s) - strlen(suffix);
|
||||||
sn = strlen(suffix);
|
if (!strcmp(&s[n], suffix))
|
||||||
|
s[n] = '\0';
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
puts(s);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user