Mercurial > hg > toybox
annotate toys/basename.c @ 232:cd4d5630c978
Move some generated files into the "generated" subdirectory.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 10 Jan 2008 14:40:13 -0600 |
parents | 25447caf1b4b |
children | d4176f3f3835 |
rev | line source |
---|---|
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
|
1 /* vi: set sw=4 ts=4: */ |
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
|
2 /* basename.c - print non-directory portion of path |
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
|
3 * |
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
|
4 * See http://www.opengroup.org/onlinepubs/009695399/utilities/basename.html |
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
|
5 */ |
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 |
176
07533cabeede
Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 #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
|
8 |
186
25447caf1b4b
Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents:
177
diff
changeset
|
9 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
|
10 { |
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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 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
|
16 } |
07533cabeede
Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 puts(name); |
07533cabeede
Patch from Charlie Shepherd to add basename and dirname. (Fixed up to apply.)
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 } |