CCL Home Page
Up Directory CCL new_extension
#include "utility.h"

char *new_extension(filename,extension)
/*============================================================================*/
/* PURPOSE: REMOVE THE CURRENT EXTENSION (IF ANY) ON FILENAME, AND APPEND THE
/*	SPECIFIED EXTENSION.  AN "EXTENSION" IS DEFINED TO BE THE LAST PERIOD
/*	IN THE FILENAME AND ALL CHARACTERS FOLLOWING IT.  A LEADING PERIOD IS
/*	OPTIONAL IN THE NEW EXTENSION - IF NOT PRESENT, IT WILL BE ADDED.
/* INPUTS:
/*	FILENAME	ORIGINAL FILENAME WITH OPTIONAL EXTENSION.
/*	EXTENSION	NEW EXTENSION TO APPEND TO FILENAME AFTER PREVIOUS
/*			EXTENSION IS REMOVED.
/* OUTPUTS:
/*	FILENAME	THE ORIGINAL FILENAME WITH THE NEW EXTENSION.
/*	RETURN VALUE	POINTER TO MODIFIED FILENAME.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
   char filename[];
   char extension[];
   {
   char *last_period;	/* POINTER TO LAST PERIOD IN FILENAME. */

   last_period=strrchr(filename,'.');		/* FIND THE LAST PERIOD. */
   if (last_period!=NULL) *last_period=0;	/* TRIM OFF OLD EXTENSION. */

   if (extension[0]!='.') strcat(filename,".");	/* GUARANTEE A PERIOD. */
   strcat(filename,extension);			/* APPEND NEW EXTENSION. */

   return(filename);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4829 times since Sat Apr 17 21:58:58 1999 GMT