Back to index

tetex-bin  3.0
Functions
basechsuffix.c File Reference
#include "config.h"

Go to the source code of this file.

Functions

string basenamechangesuffix P3C (const_string, name, const_string, old_suffix, const_string, new_suffix)

Function Documentation

string basenamechangesuffix P3C ( const_string  ,
name  ,
const_string  ,
old_suffix  ,
const_string  ,
new_suffix   
)

Definition at line 15 of file basechsuffix.c.

{
  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;
}

Here is the call graph for this function: