Back to index

tetex-bin  3.0
make-suffix.c
Go to the documentation of this file.
00001 /* make-suffix.c: unconditionally add a filename suffix.
00002 
00003 Copyright (C) 1992, 93, 95 Free Software Foundation, Inc.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #include <kpathsea/config.h>
00020 #include <kpathsea/c-pathch.h>
00021 
00022 /* Return a new string: S suffixed with SUFFIX, regardless of what it
00023    was before. This returns a newly allocated string.  */ 
00024 
00025 string
00026 make_suffix P2C(const_string, s,  const_string, suffix)
00027 {
00028   string new_s;
00029   const_string dot_pos = strrchr (s, '.');
00030   const_string slash_pos;
00031   
00032   for (slash_pos = s + strlen (s) - 1; slash_pos > dot_pos && slash_pos > s;
00033        slash_pos--) {
00034     if (IS_DIR_SEP (*slash_pos))
00035       break;
00036   }
00037 
00038   if (dot_pos == NULL || slash_pos > dot_pos )
00039     new_s = concat3 (s, ".", suffix);
00040   else
00041     {
00042       unsigned past_dot_index = dot_pos + 1 - s;
00043       
00044       new_s = (string)xmalloc (past_dot_index + strlen (suffix) + 1);
00045       strncpy (new_s, s, dot_pos + 1 - s);
00046       strcpy (new_s + past_dot_index, suffix);
00047     }
00048 
00049   return new_s;
00050 }