/*************************************************************** Utility routines */ #include "string.h" /* strcat() */ #include "dbext.h" /* PATHBUFSIZE */ #include "misc.h" /* split_path */ /* new_extension: replace an old extension, or add a new one. The extension must include the period, since the old name is copied up to but not including the period or ending null. Modified 5/2/91 - JR - changed algorithm (old version searched from start for a '.' and interpreted remainder as extension, thereby mishandling names that had '.' in a path context, e.g., '../cal/a901') Modified 93/09/22 - JR - erased 4-char limit on extension */ void new_extension(char *new_name, char *old_name, char *extension) { char path_name[PATHBUFSIZE]; int i; split_path(old_name, path_name, new_name); if ( (i = strlen(path_name)) > 0 ) /* special char. found */ { if (path_name[i-1] == '.') /* path_name has prefix part */ { path_name[i-1] = '\0'; /* drop the '.' */ strcpy(new_name, path_name); /* preserve path */ } else /* then path_name must be path part */ { /* & old_name had no extension to begin with */ strcpy(new_name, old_name); } } new_name[PATHBUFSIZE - strlen(extension) - 1] = '\0'; /* truncate if too long */ strcat(new_name, extension); }