filename.h

00001 
00002 /*---------------------------------------------------------------------------
00003                                     E.S.O.
00004  ----------------------------------------------------------------------------
00005    File name    :   filename.h
00006    Author       :   Nicolas Devillard
00007    Created on   :   November 1999
00008    Language     :   ANSI C
00009                     Part of ECLIPSE library for Adonis
00010    Description  :   file name handling
00011  *--------------------------------------------------------------------------*/
00012 
00013 /*
00014 
00015     $Id: filename.h,v 1.1 2003/09/03 12:50:47 amodigli Exp $
00016     $Author: amodigli $
00017     $Date: 2003/09/03 12:50:47 $
00018     $Revision: 1.1 $
00019 
00020 */
00021 
00022 #ifndef _FILENAME_H_
00023 #define _FILENAME_H_
00024 
00025 /*---------------------------------------------------------------------------
00026                                 Includes
00027  ---------------------------------------------------------------------------*/
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <unistd.h>
00033 #include <ctype.h>
00034 
00035 
00036 /*---------------------------------------------------------------------------
00037                             Function prototypes
00038  ---------------------------------------------------------------------------*/
00039 
00040 /*
00041    The following functions are useful to cut out a filename into its
00042    components. All functions work with statically allocated memory,
00043    i.e. the pointers they return are not permanent but likely to be
00044    overwritten at each function call. If you need a returned value
00045    later on, you should store it into a local variable.
00046    Example:
00047 
00048    char * s ;
00049    s = get_dirname("/mnt/cdrom/data/image.fits")
00050 
00051    s contains now "/mnt/cdrom/data" but will loose these contents at
00052    the next function call. To retain its value, you can either do:
00053 
00054    char s[1024];
00055    strcpy(s, get_dirname("/mnt/cdrom/data/image.fits"));
00056 
00057    or:
00058    char * s;
00059    s = strdup(get_dirname("/mnt/cdrom/data/image.fits"));
00060    ...
00061    free(s);
00062 
00063  */
00064 
00065 
00066 
00067 /*---------------------------------------------------------------------------
00068    Function :   get_dirname()
00069    In       :   allocated character string containing a file name
00070    Out      :   pointer to statically allocated string
00071    Job      :   find the directory name associated to the file
00072    Notice   :   No trailing slash appended to directory name
00073    Example  :   get_dirname("/cdrom/data/image.fits") returns "/cdrom/data"
00074                 get_dirname("filename.fits") returns "."
00075  ---------------------------------------------------------------------------*/
00076 
00077 char * get_dirname(char * filename);
00078 
00079 
00080 /*---------------------------------------------------------------------------
00081    Function :   get_basename()
00082    In       :   allocated character string containing a file name
00083    Out      :   pointer to statically allocated string
00084    Job      :   find out the base name of a file (i.e. without path)
00085    Notice   :   returns the filename itself if no path is present
00086    Example  :   get_basename("/cdrom/data/image.fits") returns "image.fits"
00087                 get_basename("filename.fits") return "filename.fits"
00088  ---------------------------------------------------------------------------*/
00089 char * get_basename(const char *filename);
00090 
00091 
00092 /*---------------------------------------------------------------------------
00093    Function :   get_rootname()
00094    In       :   allocated character string containing a file name
00095                 WITHOUT path prefix, i.e. typically the output from
00096                 get_basename().
00097    Out      :   pointer to statically allocated string
00098    Job      :   find out the root part of a basename, i.e. the file
00099                 name without extension. Supported extensions are:
00100                 "fits"  "FITS"
00101                 "tfits" "TFITS"
00102                 "paf"   "PAF"
00103                 "ascii" "ASCII"
00104                 "dat"   "DAT"
00105                 (all sensitive)
00106    Notice   :   get_rootname("filename.fits") returns "filename"
00107                 get_rootname("filename") returns "filename"
00108                 get_rootname("filename.ext") returns "filename.ext"
00109  ---------------------------------------------------------------------------*/
00110 
00111 
00112 
00113 char * get_rootname(char * filename);
00114 
00115 
00116 
00117 /*---------------------------------------------------------------------------
00118    Function :   get_extname()
00119    In       :   allocated character string containing a file name
00120                 WITHOUT path prefix, i.e. typically the output from
00121                 get_basename().
00122    Out      :   pointer to statically allocated string
00123    Job      :   find out the extension of a file name.
00124    Notice   :   get_extname("filename.fits") returns "fits"
00125                 get_extname("hello.c") returns "c"
00126                 get_extname("readme") returns NULL
00127  ---------------------------------------------------------------------------*/
00128 
00129 
00130 char * get_extname(char * filename);
00131 
00132 
00133 /*---------------------------------------------------------------------------
00134    Function :   get_program_path()
00135    In       :   allocated char string
00136    Out      :   pointer to statically allocated char string
00137                 NULL in case of error, or if the program cannot be found.
00138    Job      :   find out in which directory a command lives
00139    Notice   :   the input character string must be the name of a
00140                 command without prefixing path of any kind, i.e. only
00141                 the command name. The returned character string is the
00142                 path in which a command matching the same name was
00143                 found. Examples:
00144                 (assuming there is a prog named 'hello' in the cwd)
00145                 get_program_path("hello") returns "."
00146                 get_program_path("ls")    returns "/bin"
00147                 get_program_path("csh")   returns "/usr/bin"
00148                 get_program_path("/bin/ls") returns NULL
00149  ---------------------------------------------------------------------------*/
00150 
00151 char * get_program_path(char * pname);
00152 
00153 #endif

Generated on Wed Oct 26 13:08:52 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001