annotate toys/basename.c @ 233:d4176f3f3835

Zap toys/Config.in and instead create generated/Config.in from contents of toys/*.c. Move relevant info into comment at the top of each toys/*.c. Also convert more of Makefile into a thin wrapper around shell scripts that actually do the work. (Makefile is only still there for the user interface.)
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:08:39 -0600
parents 25447caf1b4b
children 163498bf547b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
2 *
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
3 * basename.c - print non-directory portion of path
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
4 *
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
5 * Copyright 2007 Charlie Shepherd <masterdriverz@gentoo.org>
177
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
6 *
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
8
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
9 config BASENAME
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
10 bool "basename"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
11 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
12 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
13 usage: basename path [suffix]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
14
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
15 Print the part of path after the last slash, optionally minus suffix.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
16 */
177
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
17
176
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
18 #include "toys.h"
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
19
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 177
diff changeset
20 void basename_main(void)
176
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
21 {
177
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
22 char *name = basename(*toys.optargs);
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
23 char *suffix = toys.optargs[1];
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
24 if (suffix) {
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
25 char *end = name+strlen(name)-strlen(suffix);
00bbb7f65b6f Remove a few bytes from basename and add 'em back (and more) in the help string.
Rob Landley <rob@landley.net>
parents: 176
diff changeset
26 if (end>name && !strcmp(end,suffix)) *end=0;
176
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
27 }
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
28 puts(name);
07533cabeede Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff changeset
29 }