home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / kpathsea / make-suffix.c < prev    next >
C/C++ Source or Header  |  2000-01-15  |  2KB  |  51 lines

  1. /* make-suffix.c: unconditionally add a filename suffix.
  2.  
  3. Copyright (C) 1992, 93, 95 Free Software Foundation, Inc.
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  18.  
  19. #include <kpathsea/config.h>
  20. #include <kpathsea/c-pathch.h>
  21.  
  22. /* Return a new string: S suffixed with SUFFIX, regardless of what it
  23.    was before. This returns a newly allocated string.  */ 
  24.  
  25. string
  26. make_suffix P2C(const_string, s,  const_string, suffix)
  27. {
  28.   string new_s;
  29.   const_string dot_pos = strrchr (s, '.');
  30.   const_string slash_pos;
  31.   
  32.   for (slash_pos = s + strlen (s) - 1; slash_pos > dot_pos && slash_pos > s;
  33.        slash_pos--) {
  34.     if (IS_DIR_SEP (*slash_pos))
  35.       break;
  36.   }
  37.  
  38.   if (dot_pos == NULL || slash_pos > dot_pos )
  39.     new_s = concat3 (s, ".", suffix);
  40.   else
  41.     {
  42.       unsigned past_dot_index = dot_pos + 1 - s;
  43.       
  44.       new_s = xmalloc (past_dot_index + strlen (suffix) + 1);
  45.       strncpy (new_s, s, dot_pos + 1 - s);
  46.       strcpy (new_s + past_dot_index, suffix);
  47.     }
  48.  
  49.   return new_s;
  50. }
  51.