/**---------------------------------------------------------------------------
 ** 
 ** file.c -- File and file name handling utilities
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/07/15 11:12:18
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/07/16 21:18:52
 ** Update Count    : 3
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/libs/misc/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    These are miscellaneous file and file name handling functions.
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

#include "file.h"

/*
  This macro is already defined in ioserv/misc.c, but it does not allow file
  names with more than one dot. This is fixed in the new definition below.
*/
#define isname(c) (isalpha(c) || isdigit(c) || c=='_' || c=='.')

/* ------------------------------------------------------------------
	Own version of split path function, allowing '.'. This functions puts the
	path of all in path and the file name in name. 

  RETURNS: 0
	------------------------------------------------------------------ */
#if PROTOTYPE_ALLOWED
int split_file_path(/* Full file name to split */
                    char *all, 
                    /* Path part of file name */
                    char *path, 
                    /* Name part of file name */
                    char *name)
#else
     int split_file_path(all, path, name)
     char *all, *path, *name;
#endif
{
   int i;
   
   /* 2000/12/03 PJ Added test for empty input */
   if(!(strlen(all))){
     path[0] = name[0] = '\0';
     return(0);
   }

   for (i=((int) strlen(all))-1; i>0 && isname(all[i]); i--)
      ;                   /* i is 0 or index of last path character */
   if (i>0)
      i++;         /* first character that is part of name; number of
                        path characters  */
   strncpy(path, all, (size_t) i);
   path[i] = '\0';
   strcpy(name, all+i);

	 return(0);
}
