rem: int    n; char    c; int    baseLen; char    *ptr; char    *newName;  ptr = curName;  while ((ptr = strrchr(ptr, '{')) && !(sscanf(ptr, "{%i}%c", &n, &c)==1)) { ptr++; } if (!ptr) return wstrappend(curName, " {1}");  baseLen = ptr - curName -1;  newName = wmalloc(baseLen + 16); strncpy(newName, curName, baseLen); newName[baseLen] = 0;  sprintf(&newName[baseLen], " {%i}", n+1);  return newName;
add: int	n; char	c; int	baseLen; char	*ptr; char	*newName;   assert(curName);  ptr = curName;  if ( ((ptr = strrchr(ptr, '{')) == 0) || sscanf(ptr, "{%i}%c", &n, &c) != 1 ) return wstrappend(curName, " {1}");  baseLen = ptr - curName -1;  newName = wmalloc(baseLen + 16); strncpy(newName, curName, baseLen); newName[baseLen] = 0;  sprintf(&newName[baseLen], " {%i}", n+1);  return newName;
context: generateNewFilename(char *curName){    int    n;    char    c;    int    baseLen;    char    *ptr;    char    *newName;        ptr = curName;            while ((ptr = strrchr(ptr, '{')) && !(sscanf(ptr, "{%i}%c", &n, &c)==1)) {        ptr++;    }    if (!ptr)         return wstrappend(curName, " {1}");        baseLen = ptr - curName -1;        newName = wmalloc(baseLen + 16);    strncpy(newName, curName, baseLen);    newName[baseLen] = 0;        sprintf(&newName[baseLen], " {%i}", n+1);        return newName;}