da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1992-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * David Korn
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Bell Laboratories
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * dirname path [suffix]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * print the dirname of a pathname
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[-?\n@(#)$Id: dirname (AT&T Research) 2009-01-31 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?dirname - return directory portion of file name]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?\bdirname\b treats \astring\a as a file name and returns "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the name of the directory containing the file name by deleting "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the last component from \astring\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?If \astring\a consists solely of \b/\b characters the output will "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "be a single \b/\b unless \bPATH_LEADING_SLASHES\b returned by "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\bgetconf\b(1) is \b1\b and \astring\a consists of multiple "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\b/\b characters in which case \b//\b will be output. "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "Otherwise, trailing \b/\b characters are removed, and if "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "there are no remaining \b/\b characters in \astring\a, "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the string \b.\b will be written to standard output. "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "Otherwise, all characters following the last \b/\b are removed. "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "If the remaining string consists solely of \b/\b characters, "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the output will be as if the original string had consisted solely "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "as \b/\b characters as described above. Otherwise, all "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "trailing slashes are removed and the output will be this string "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "unless this string is empty. If empty the output will be \b.\b.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[f:file?Print the \b$PATH\b relative regular file path for \astring\a.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[r:relative?Print the \b$PATH\b relative readable file path for \astring\a.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[x:executable?Print the \b$PATH\b relative executable file path for \astring\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+EXIT STATUS?]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?Successful Completion.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+>0?An error occurred.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[+SEE ALSO?\bbasename\b(1), \bgetconf\b(1), \bdirname\b(3), \bpathname\b(3)]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void l_dirname(register Sfio_t *outfile, register const char *pathname)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* go to end of path */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* back over trailing '/' */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* back over non-slash chars */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* all '/' or "" */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* back over trailing '/' */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* preserve // */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(last!=pathname && pathname[0]=='/' && pathname[1]=='/')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(last!=pathname && pathname[0]=='/' && pathname[1]=='/' && *astconf("PATH_LEADING_SLASHES",NiL,NiL)!='1')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinb_dirname(int argc,register char *argv[], void* context)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz error(1|ERROR_WARNING, "%s: relative path not found", argv[0]);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);