diff options
author | chin <none@none> | 2007-08-17 12:01:52 -0700 |
---|---|---|
committer | chin <none@none> | 2007-08-17 12:01:52 -0700 |
commit | da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968 (patch) | |
tree | 5280d3b78e289fe9551371ab6e7f15ef9944ea14 /usr/src/lib/libcmd/common/dirname.c | |
parent | 073dbf9103ef2a2b05d8a16e2d26db04e0374b0e (diff) | |
download | illumos-joyent-da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968.tar.gz |
6437624 RFE: Add ksh93 (as /usr/bin/ksh93) and libshell.so to OS/Net
6505835 AST tools and library (libpp) required for creating l10n messages for ksh93
PSARC/2006/550 Korn Shell 93 Integration
PSARC/2006/587 /etc/ksh.kshrc for ksh93
PSARC/2007/035 ksh93 Amendments
Contributed by Roland Mainz <roland.mainz@nrubsig.org>
--HG--
rename : usr/src/lib/libcmd/common/mapfile-vers => deleted_files/usr/src/lib/libcmd/common/mapfile-vers
rename : usr/src/lib/libcmd/common/placeholder.c => deleted_files/usr/src/lib/libcmd/common/placeholder.c
Diffstat (limited to 'usr/src/lib/libcmd/common/dirname.c')
-rw-r--r-- | usr/src/lib/libcmd/common/dirname.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/usr/src/lib/libcmd/common/dirname.c b/usr/src/lib/libcmd/common/dirname.c new file mode 100644 index 0000000000..f4a3c820c3 --- /dev/null +++ b/usr/src/lib/libcmd/common/dirname.c @@ -0,0 +1,116 @@ +/*********************************************************************** +* * +* This software is part of the ast package * +* Copyright (c) 1992-2007 AT&T Knowledge Ventures * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Knowledge Ventures * +* * +* A copy of the License is available at * +* http://www.opensource.org/licenses/cpl1.0.txt * +* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * +* * +* Information and Software Systems Research * +* AT&T Research * +* Florham Park NJ * +* * +* Glenn Fowler <gsf@research.att.com> * +* David Korn <dgk@research.att.com> * +* * +***********************************************************************/ +#pragma prototyped +/* + * David Korn + * AT&T Bell Laboratories + * + * dirname path [suffix] + * + * print the dirname of a pathname + */ + +static const char usage[] = +"[-?\n@(#)$Id: dirname (AT&T Research) 2000-03-07 $\n]" +USAGE_LICENSE +"[+NAME?dirname - return directory portion of file name]" +"[+DESCRIPTION?\bdirname\b treats \astring\a as a file name and returns " + "the name of the directory containing the file name by deleting " + "the last component from \astring\a.]" +"[+?If \astring\a consists solely of \b/\b characters the output will " + "be a single \b/\b unless \bPATH_LEADING_SLASHES\b returned by " + "\bgetconf\b(1) is \b1\b and \astring\a consists of multiple " + "\b/\b characters in which case \b//\b will be output. " + "Otherwise, trailing \b/\b characters are removed, and if " + "there are no remaining \b/\b characters in \astring\a, " + "the string \b.\b will be written to standard output. " + "Otherwise, all characters following the last \b/\b are removed. " + "If the remaining string consists solely of \b/\b characters, " + "the output will be as if the original string had consisted solely " + "as \b/\b characters as described above. Otherwise, all " + "trailing slashes are removed and the output will be this string " + "unless this string is empty. If empty the output will be \b.\b.]" +"\n" +"\n string\n" +"\n" +"[+EXIT STATUS?]{" + "[+0?Successful Completion.]" + "[+>0?An error occurred.]" +"}" +"[+SEE ALSO?\bbasename\b(1), \bgetconf\b(1), \bdirname\b(3)]" +; + +#include <cmd.h> + +static void l_dirname(register Sfio_t *outfile, register const char *pathname) +{ + register const char *last; + /* go to end of path */ + for(last=pathname; *last; last++); + /* back over trailing '/' */ + while(last>pathname && *--last=='/'); + /* back over non-slash chars */ + for(;last>pathname && *last!='/';last--); + if(last==pathname) + { + /* all '/' or "" */ + if(*pathname!='/') + last = pathname = "."; + } + else + { + /* back over trailing '/' */ + for(;*last=='/' && last > pathname; last--); + } + /* preserve // */ + if(last!=pathname && pathname[0]=='/' && pathname[1]=='/') + { + while(pathname[2]=='/' && pathname<last) + pathname++; + if(last!=pathname && pathname[0]=='/' && pathname[1]=='/' && *astconf("PATH_LEADING_SLASHES",NiL,NiL)!='1') + pathname++; + } + sfwrite(outfile,pathname,last+1-pathname); + sfputc(outfile,'\n'); +} + +int +b_dirname(int argc,register char *argv[], void* context) +{ + register int n; + + cmdinit(argc, argv, context, ERROR_CATALOG, 0); + while (n = optget(argv, usage)) switch (n) + { + case ':': + error(2, "%s", opt_info.arg); + break; + case '?': + error(ERROR_usage(2), "%s", opt_info.arg); + break; + } + argv += opt_info.index; + argc -= opt_info.index; + if(error_info.errors || argc != 1) + error(ERROR_usage(2),"%s", optusage(NiL)); + l_dirname(sfstdout,argv[0]); + return(0); +} |