home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38A.ZIP / BASENAME.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  56 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/basename.c,v 1.1 1992/01/24 03:26:56 dvadura Exp $
  2. -- SYNOPSIS -- return pointer to last pathname component
  3. -- 
  4. -- DESCRIPTION
  5. --    take a file name like /fred/foo/hoe/mary.k, and return the 'mary.k'
  6. --    portion
  7. -- 
  8. -- AUTHOR
  9. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  10. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  11. --
  12. -- COPYRIGHT
  13. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  14. -- 
  15. --      This program is free software; you can redistribute it and/or
  16. --      modify it under the terms of the GNU General Public License
  17. --      (version 1), as published by the Free Software Foundation, and
  18. --      found in the file 'LICENSE' included with this distribution.
  19. -- 
  20. --      This program is distributed in the hope that it will be useful,
  21. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  22. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. --      GNU General Public License for more details.
  24. -- 
  25. --      You should have received a copy of the GNU General Public License
  26. --      along with this program;  if not, write to the Free Software
  27. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. --
  29. -- LOG
  30. --     $Log: basename.c,v $
  31.  * Revision 1.1  1992/01/24  03:26:56  dvadura
  32.  * dmake Version 3.8, Initial revision
  33.  *
  34. */
  35.  
  36. #include "extern.h"
  37.  
  38. PUBLIC char*
  39. basename( path )
  40. char *path;
  41. {
  42.    char *p;
  43.    char *q;
  44.  
  45.    if( *(q = path) ) {
  46.       for(; *(p=_strpbrk(q, DirBrkStr)) != '\0'; q = p+1 );
  47.       if( !*q ) {
  48.      for( p=q-1; p != path; --p )
  49.         if( strchr( DirBrkStr, *p ) == NIL(char) ) return( p+1 );
  50.      return( strchr(DirBrkStr, *p)?path:(p+1) );
  51.       }
  52.       path = q;
  53.    }
  54.    return( path );
  55. }
  56.