home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / os2 / strippath.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  61 lines

  1. /* strippath.c -- remove unnecessary components from a path specifier
  2.    Copyright (C) 1992 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <string.h>
  19.  
  20. static void remove_component(char *beginc, char *endc);
  21. void strip_trailing_slashes(char *path);
  22.  
  23. /* Remove unnecessary components from PATH. */
  24.  
  25. void
  26. strip_path (path)
  27.      char *path;
  28. {
  29.   int stripped = 0;
  30.   char *cp, *slash;
  31.  
  32.   for (cp = path; *(slash = cp + strcspn (cp, "/\\")) != '\0'; cp = slash)
  33.     {
  34.       *slash = '\0';
  35.       if ((!*cp && (cp != path || stripped)) ||
  36.       strcmp(cp, ".") == 0 || strcmp(cp, "/") == 0)
  37.     {
  38.       stripped = 1;
  39.       remove_component(cp, slash);
  40.       slash = cp;
  41.     }
  42.       else
  43.     {
  44.       *slash++ = '/';
  45.     }
  46.     }
  47.   strip_trailing_slashes(path);
  48. }
  49.  
  50. /* Remove the component delimited by BEGINC and ENDC from the path */
  51.  
  52. static void
  53. remove_component (beginc, endc)
  54.      char *beginc;
  55.      char *endc;
  56. {
  57.   for (endc++; *endc; endc++)
  58.     *beginc++ = *endc;
  59.   *beginc = '\0';
  60. }
  61.