annotate toys/posix/basename.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 2986aa63a021
children b300eb824c70
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
1 /* basename.c - Return non-directory portion of a pathname
408
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
2 *
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
3 * Copyright 2012 Tryn Mirell <tryn@mirell.org>
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
4 *
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/basename.html
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
6
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
7
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 408
diff changeset
8 USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_USR|TOYFLAG_BIN))
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
9
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
10 config BASENAME
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
11 bool "basename"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
12 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
13 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
14 usage: basename string [suffix]
408
8506c538f26a Comment changes, and add a blank line to the help text.
Rob Landley <rob@landley.net>
parents: 405
diff changeset
15
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
16 Return non-directory portion of a pathname removing suffix
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
17 */
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
18
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
19 #include "toys.h"
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
20
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
21 void basename_main(void)
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
22 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
23 char *arg = toys.optargs[0], *suffix = toys.optargs[1], *base;
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
24
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
25 while ((base = strrchr(arg, '/'))) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
26 if (base == arg) break;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
27 if (!base[1]) *base = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
28 else {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
29 base++;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
30 break;
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
31 }
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
32 }
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
33
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
34 if (!base) base = arg;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
35
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
36 // chop off the suffix if provided
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
37 if (suffix) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
38 arg = base + strlen(base) - strlen(suffix);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
39 if (arg > base && !strcmp(arg, suffix)) *arg = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
40 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
41
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
42 puts(base);
404
ad5ffc45aa62 Initial 'basename' implementation
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
43 }