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

char *fn_root(filename,rootpart)
/*============================================================================*/
/* PURPOSE: EXTRACT THE ROOT PART OF THE FILE SPECIFICATION.  THUS,
/*	".../.../ROOT.EXT" WILL YIELD "ROOT" AS OUTPUT.  IF THERE IS NO
/*	LEADING "ROOT", THE RETURN STRING WILL BE NULL.  THE DIRECTORY PART
/*	IS DEFINED TO BE EVERYTHING UP TO BUT NOT INCLUDING THE LAST SLASH.
/* INPUTS:
/*	FILENAME	FILENAME WITH OPTIONAL DIRECTORY PREFIX.
/* OUTPUTS:
/*	ROOTPART	COPY OF FILE ROOT SPECIFICATION.
/*	RETURN VALUE	POINTER TO FILEPART.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 12 MAY 1992 MVG (FIX COMMENT)
*/
   char filename[];
   char rootpart[];
   {
   char *last_slash;	/* POINTER TO LAST SLASH IN FILENAME. */
   char *last_dot;	/* POINTER TO LAST DOT IN FILENAME. */

   /* TRIM OFF DIRECTORY PART (MAY BE NULL IF NOT SPECIFIED). */
   last_slash=strrchr(filename,'/');	/* FIND THE LAST SLASH. */
   strcpy(rootpart, (last_slash!=NULL ? last_slash+1 : filename));

   /* TRIM OFF EXTENSION PART (MAY BE NULL IF NOT SPECIFIED). */
   last_dot=strrchr(rootpart,'.');	/* FIND THE LAST DOT. */
   if (last_dot!=NULL) *last_dot='\0';

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