[hackers] [sbase] Moving back to the stone age. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Mon, 23 Apr 2012 16:32:48 +0200 (CEST)

changeset: 110:9af7eeae21d5
tag: tip
user: Christoph Lohmann <20h_AT_r-36.net>
date: Mon Apr 23 16:32:41 2012 +0200
files: basename.1 basename.c
description:
Moving back to the stone age.


diff -r d6ea66d9cc59 -r 9af7eeae21d5 basename.1
--- a/basename.1 Mon Apr 23 16:27:40 2012 +0200
+++ b/basename.1 Mon Apr 23 16:32:41 2012 +0200
_AT_@ -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
_AT_@ -16,17 +12,6 @@
 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 -r d6ea66d9cc59 -r 9af7eeae21d5 basename.c
--- a/basename.c Mon Apr 23 16:27:40 2012 +0200
+++ b/basename.c Mon Apr 23 16:32:41 2012 +0200
_AT_@ -14,28 +14,16 @@
 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;
_AT_@ -43,23 +31,13 @@
         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;
 }
Received on Mon Apr 23 2012 - 16:32:48 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 23 2012 - 16:36:09 CEST