
/**************************************************************************
 *                                                                        *
 * Copyright (c) 1989 Michael Richmond, Richard Treffers and              *
 *                    The Regents of the University of California         *
 *                                                                        *
 *                    This software may be copied and distributed for     *
 *                    educational, research and not for profit services   *
 *                    provided that this copyright and statement are      *
 *                    included in all such copies.                        *
 *                                                                        *
 **************************************************************************/



/* routine to modify file name extensions 		*/
/*  	fname - is the filename string input 	*/
/*	    ext - is file extension			   		*/
/* example: if fname="blah.obj"  and ext=".exe" */
/* 			fname becomes "blah.exe"			*/

/*	Fix from Steve Walton inserted 1/30/91 by MWR.  Fixes relative paths
	correctly now. */

#include <stdio.h>
#include <string.h>
#include "pcvista.h"


#define FITS_EXTENSION ".fts"

/*      insane procedure to add FTS_EXTENSION only if it needs it
    we try to do the following:
    Case            in                              out
    A.                      foo.fts   -->    foo.fts
    B.                      foo.xyz  -->     foo.xyz
    C.                      foo   -->        foo.fts
    Furthermore we shouldn't get confused by '.'s in
    the front of a path e.g.  ../foo.xyz
*/

		
void exten(in)
char *in;
{   
    int n,nfts;
    char *tail;
    
    /* first check for case A and do nothing */
    n=strlen(in);
    nfts=strlen(FITS_EXTENSION);
    
    if(n>nfts){
        if(strncmp(in-nfts,FITS_EXTENSION,nfts) == 0 )
            return;
    }
    tail=strrchr(in,'/');
    if (tail == NULL)
        tail=in;
        
    /*      this is case B */
    if(strchr(tail,'.') != NULL)
        return;
        
    /* finally case C */
    
    strcat(in,FITS_EXTENSION);
}   

