annotate kpathsea/make-suffix.c @ 1268:76a0c05089d4

[project @ 1995-04-20 19:15:51 by jwe] Initial revision
author jwe
date Thu, 20 Apr 1995 19:15:51 +0000
parents
children 611d403c7f3d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1268
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
1 /* make_suffix.c: unconditionally add a filename suffix.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
2
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 1992, 93 Free Software Foundation, Inc.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
4
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
8 any later version.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
9
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
13 GNU General Public License for more details.
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
14
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
16 along with this program; if not, write to the Free Software
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
18
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
19 #include <kpathsea/config.h>
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
20
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
21
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
22 /* Return a new string: S suffixed with SUFFIX, regardless of what it
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
23 was before. This returns a newly allocated string. */
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
24
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
25 string
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
26 make_suffix P2C(const_string, s, const_string, suffix)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
27 {
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
28 string new_s;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
29 const_string dot_pos = strrchr (s, '.');
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
30 const_string slash_pos = strrchr (s, '/');
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
31
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
32 if (dot_pos == NULL || dot_pos < slash_pos)
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
33 new_s = concat3 (s, ".", suffix);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
34 else
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
35 {
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
36 unsigned past_dot_index = dot_pos + 1 - s;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
37
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
38 new_s = (string) xmalloc (past_dot_index + strlen (suffix) + 1);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
39 strncpy (new_s, s, dot_pos + 1 - s);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
40 strcpy (new_s + past_dot_index, suffix);
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
41 }
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
42
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
43 return new_s;
76a0c05089d4 [project @ 1995-04-20 19:15:51 by jwe]
jwe
parents:
diff changeset
44 }