qfits/qfits/html/group__qfits__filename.html

219 lines
10 KiB
HTML

<html>
<head>
<meta name="keywords" content="eso, FITS format, C library">
<link href="doxygen.css" rel="stylesheet" type="text/css">
<title>QFITS Reference Manual 6.2.0</title>
</head>
<body text="#000000" bgcolor="#ffffff">
<!-- Generated by Doxygen 1.4.1 -->
<h1>Get various names (filenames, dir names,...)</h1><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">char *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__qfits__filename.html#ga0">qfits_get_dir_name</a> (const char *filename)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Find the directory name in the given string. <a href="#ga0"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">char *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__qfits__filename.html#ga1">qfits_get_base_name</a> (const char *filename)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Find out the base name of a file (i.e. without prefix path). <a href="#ga1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">char *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__qfits__filename.html#ga2">qfits_get_root_name</a> (const char *filename)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Find out the root part of a basename (name without extension). <a href="#ga2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">char *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__qfits__filename.html#ga3">qfits_get_ext_name</a> (const char *filename)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Find out the extension of a file name. <a href="#ga3"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The following functions are useful to cut out a filename into its components. All functions work with statically allocated memory, i.e. the pointers they return are not permanent but likely to be overwritten at each function call. If you need a returned value later on, you should store it into a local variable.<p>
Example:<p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> * s ;
s = <a class="code" href="group__qfits__filename.html#ga0">qfits_get_dir_name</a>(<span class="stringliteral">"/mnt/cdrom/data/image.fits"</span>)
</pre></div><p>
s contains now "/mnt/cdrom/data" but will loose these contents at the next function call. To retain its value, you can either do:<p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> s[1024];
strcpy(s, <a class="code" href="group__qfits__filename.html#ga0">qfits_get_dir_name</a>(<span class="stringliteral">"/mnt/cdrom/data/image.fits"</span>));
</pre></div><p>
or:<p>
<div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> * s;
s = strdup(<a class="code" href="group__qfits__filename.html#ga0">qfits_get_dir_name</a>(<span class="stringliteral">"/mnt/cdrom/data/image.fits"</span>));
...
free(s);
</pre></div> <hr><h2>Function Documentation</h2>
<a class="anchor" name="ga1" doxytag="qfits_filename.c::qfits_get_base_name"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">char* qfits_get_base_name </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top">const char *&nbsp;</td>
<td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Find out the base name of a file (i.e. without prefix path).
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>filename</em>&nbsp;</td><td>Full path name to scan. </td></tr>
</table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd>Pointer to char within the input string.</dd></dl>
Provide a full path name and you get in return a pointer to a statically allocated string containing the name of the file only, without prefixing directory names. If the input string does not contain a slash (i.e. it is not a full path), the returned string is a copy of the input string.<p>
This function does not check for the existence of the path or the file.<p>
Examples: <div class="fragment"><pre class="fragment">
qfits_get_base_name("/cdrom/data/image.fits") returns "image.fits"
qfits_get_base_name("filename.fits") returns "filename.fits"
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="ga0" doxytag="qfits_filename.c::qfits_get_dir_name"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">char* qfits_get_dir_name </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top">const char *&nbsp;</td>
<td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Find the directory name in the given string.
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>filename</em>&nbsp;</td><td>Full path name to scan. </td></tr>
</table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd>Pointer to statically allocated string.</dd></dl>
Provide a full path name and you get in return a pointer to a statically allocated string containing the name of the directory only, without trailing slash. If the input string does not contain a slash (i.e. it is not a full path), the returned string is '.', corresponding to the current working directory. Since the returned string is statically allocated, do not try to free it or modify it.<p>
This function does not check for the existence of the path or the file.<p>
Examples: <div class="fragment"><pre class="fragment">
qfits_get_dir_name("/cdrom/data/image.fits") returns "/cdrom/data"
qfits_get_dir_name("filename.fits") returns "."
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="ga3" doxytag="qfits_filename.c::qfits_get_ext_name"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">char* qfits_get_ext_name </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top">const char *&nbsp;</td>
<td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Find out the extension of a file name.
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>filename</em>&nbsp;</td><td>File name without path prefix. </td></tr>
</table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd>Pointer to char within the input string.</dd></dl>
Find out the extension of a given file name. Notice that the input character string must not contain a path prefix (typically, you feed in the output of <code>qfits_get_base_name</code>).<p>
Works with all kinds of extensions: returns the part of the string after the last dot. If no dot is found in the input string, NULL is returned.<p>
Examples: <div class="fragment"><pre class="fragment">
qfits_get_ext_name("filename.fits") returns "fits"
qfits_get_ext_name("hello.c") returns "c"
qfits_get_ext_name("readme") returns NULL
</pre></div> </td>
</tr>
</table>
<a class="anchor" name="ga2" doxytag="qfits_filename.c::qfits_get_root_name"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">char* qfits_get_root_name </td>
<td class="md" valign="top">(&nbsp;</td>
<td class="md" nowrap valign="top">const char *&nbsp;</td>
<td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
<td class="md" valign="top">&nbsp;)&nbsp;</td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Find out the root part of a basename (name without extension).
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>filename</em>&nbsp;</td><td>File name to scan. </td></tr>
</table>
</dl>
<dl compact><dt><b>Returns:</b></dt><dd>Pointer to statically allocated string.</dd></dl>
Find out the root part of a file name, i.e. the file name without extension. Since in Unix a file name can have several dots, only a number of extensions are supported. This includes:<p>
<ul>
<li>.fits and .FITS</li><li>.tfits and .TFITS</li><li>.paf and .PAF</li><li>.ascii and .ASCII</li><li>.dat and .DAT</li><li>.txt and .TXT</li></ul>
<p>
This function does not check for the existence of the path or the file.<p>
Examples: <div class="fragment"><pre class="fragment">
qfits_get_root_name("/cdrom/filename.fits") returns "/cdrom/filename"
qfits_get_root_name("filename.paf") returns "filename"
qfits_get_root_name("filename") returns "filename"
qfits_get_root_name("filename.ext") returns "filename.ext"
</pre></div><p>
Since the returned string is statically allocated in this module, do not try to free it or modify its contents. </td>
</tr>
</table>
</body>
</html>