basename.c revision 1
1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1992-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A***********************************************************************/ 1N/A * AT&T Bell Laboratories 1N/A * namebase pathname [suffix] 1N/A * print the namebase of a pathname 1N/A"[-?\n@(#)$Id: basename (AT&T Research) 2010-05-06 $\n]" 1N/A"[+NAME?basename - strip directory and suffix from filenames]" 1N/A"[+DESCRIPTION?\bbasename\b removes all leading directory components " 1N/A "from the file name defined by \astring\a. If the file name defined by " 1N/A "\astring\a has a suffix that ends in \asuffix\a, it is removed as " 1N/A"[+?If \astring\a consists solely of \b/\b characters the output will be " 1N/A "a single \b/\b unless \bPATH_LEADING_SLASHES\b returned by " 1N/A "\bgetconf\b(1) is \b1\b and \astring\a consists of multiple \b/\b " 1N/A "characters in which case \b//\b will be output. Otherwise, trailing " 1N/A "\b/\b characters are removed, and if there are any remaining \b/\b " 1N/A "characters in \astring\a, all characters up to and including the last " 1N/A "\b/\b are removed. Finally, if \asuffix\a is specified, and is " 1N/A "identical the end of \astring\a, these characters are removed. The " 1N/A "characters not removed from \astring\a will be written on a single line " 1N/A "to the standard output.]" 1N/A"[a:all?All operands are treated as \astring\a and each modified " 1N/A "pathname is printed on a separate line on the standard output.]" 1N/A"[s:suffix?All operands are treated as \astring\a and each modified " 1N/A "pathname, with \asuffix\a removed if it exists, is printed on a " 1N/A "separate line on the standard output.]:[suffix]" 1N/A"\n string [suffix]\n" 1N/A "[+0?Successful Completion.]" 1N/A "[+>0?An error occurred.]" 1N/A"[+SEE ALSO?\bdirname\b(1), \bgetconf\b(1), \bbasename\b(3)]" 1N/A /* back over trailing '/' */ 1N/A if(*++
last==
'/')
/* keep leading // */ 1N/A /* check for trailing suffix */