rem: char	*newName; char	*numStart, *numEnd; char	*pre, *num, *post; int	n, numLength; char	*tmp;
context: generateNewFilename(char *Path, char *curName){	char	*newName;	char	*numStart, *numEnd;	char	*pre, *num, *post;	int	n, numLength;	char	*tmp;	newName = wstrdup(curName);	if (newName == NULL)		return wstrdup("Unnamed");	/*	 *	Modify the name to contain a number to make it unique 	 */	/* Get number-string from filename. */	numStart = strrchr(newName, '(');	if (numStart) {		if (strlen(numStart) > 1)			numStart++;						/* Next character, please */		numEnd = strrchr(numStart, ')');	/* Already past "numbers" */		if (numEnd) {			/* Now it gets interesting */			pre = wmalloc((numStart - newName +1) * sizeof(char));	/* a trailing '\0' is useful here */			memset(pre, 0, (numStart - newName +1) * sizeof(char));			strncpy (pre, newName, numStart-newName);			num = wmalloc((numEnd - numStart +1) * sizeof(char));			memset (num, 0, (numEnd - numStart +1) * sizeof(char));			strncpy (num, numStart, numEnd-numStart);			post = wstrdup( numEnd);			free(newName);	/* We don't need it anymore */			if (strcspn(num, "0123456789") == 0) {					n = (int)strtol(num, NULL, 10);				/* Increase number between brackets (in filename); This is what it all is about */				n++;				free(num);				num = wmalloc(3 * sizeof(char));		/* Nobody uses more than 999 duplicate filenames, do you ? */				memset(num, 0, 3 * sizeof(char));				numLength = sprintf(num, "%d", n);				free(num);				num = wmalloc(numLength * sizeof(char));				memset(num, 0, numLength * sizeof(char));				sprintf(num, "%d", n);				tmp = wstrappend (num, post);				newName = wstrappend (pre, tmp);				free (pre);				free (num);				free (post);				free (tmp);			}		}	}	if (strcmp( curName, newName) == 0) {		/* The name is still unchanged, so there was no number (between brackets) in it.			Add a number 1 to the end. 		*/		tmp = wstrdup(newName);		if (newName)			free(newName);		newName = wstrappend(tmp, " (1)");		free(tmp);	}	return newName;}