diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-17 21:41:51 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-17 21:41:51 +0000 |
commit | 487ca4806cc046076293cf6cc5fbba0db282bac7 (patch) | |
tree | 847b412ab5158dd7bdd7ed7e5a4cc3fbca94be32 /Build/source/texk/web2c/lib/basechsuffix.c | |
parent | a3d3111bfe26b8e5f5bc6049dfb2a4ca2edc7881 (diff) |
texk 1
git-svn-id: svn://tug.org/texlive/trunk@1485 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/lib/basechsuffix.c')
-rw-r--r-- | Build/source/texk/web2c/lib/basechsuffix.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/lib/basechsuffix.c b/Build/source/texk/web2c/lib/basechsuffix.c new file mode 100644 index 00000000000..f2c2d7bb06f --- /dev/null +++ b/Build/source/texk/web2c/lib/basechsuffix.c @@ -0,0 +1,42 @@ +/* basechsuffix.c: replace the last bit of a filename with something else. + + Written in 1995 by Karl Berry. Public domain. */ + +#include "config.h" + +/* Return the basename of NAME, with trailing characters OLD replaced by + NEW. (If last characters in NAME are not OLD, just append NEW.) + Since this is used to turn, e.g., foo/cmr10.300pk -> cmr10.300gf, + don't assume a `.' preceding OLD or NEW. + + In other words, we're implementing `basename NAME OLD`NEW. */ + +string +basenamechangesuffix P3C(const_string, name, const_string, old_suffix, + const_string, new_suffix) +{ + string answer; + unsigned c; + const_string base = xbasename (name); + unsigned base_len = strlen (base); + unsigned copy_limit = base_len; + unsigned old_suffix_len = strlen (old_suffix); + + if (old_suffix_len <= base_len) { + for (c = 0; c < old_suffix_len; c++) { + if (!FILECHARCASEEQ (old_suffix[old_suffix_len - c - 1], + base[base_len - c - 1])) + break; + } + if (c == old_suffix_len) { + copy_limit -= old_suffix_len; + } + } + + answer = (string)xmalloc (copy_limit + strlen (new_suffix) + 1); + strncpy (answer, base, copy_limit); + answer[copy_limit] = 0; + strcat (answer, new_suffix); + + return answer; +} |