<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Audacious: util.c Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Audacious <span id="projectnumber">$Id:Doxyfile42802007-03-2104:39:00Znenolod$</span></div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <h1>util.c</h1> </div> </div> <div class="contents"> <a href="util_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Audacious - Cross-platform multimedia player</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2005-2008 Audacious development team</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Based on BMP:</span> <a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2003-2004 BMP development team.</span> <a name="l00006"></a>00006 <span class="comment"> *</span> <a name="l00007"></a>00007 <span class="comment"> * Based on XMMS:</span> <a name="l00008"></a>00008 <span class="comment"> * Copyright (C) 1998-2003 XMMS development team.</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span> <a name="l00011"></a>00011 <span class="comment"> * it under the terms of the GNU General Public License as published by</span> <a name="l00012"></a>00012 <span class="comment"> * the Free Software Foundation; under version 3 of the License.</span> <a name="l00013"></a>00013 <span class="comment"> *</span> <a name="l00014"></a>00014 <span class="comment"> * This program is distributed in the hope that it will be useful,</span> <a name="l00015"></a>00015 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00016"></a>00016 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00017"></a>00017 <span class="comment"> * GNU General Public License for more details.</span> <a name="l00018"></a>00018 <span class="comment"> *</span> <a name="l00019"></a>00019 <span class="comment"> * You should have received a copy of the GNU General Public License</span> <a name="l00020"></a>00020 <span class="comment"> * along with this program. If not, see <http://www.gnu.org/licenses>.</span> <a name="l00021"></a>00021 <span class="comment"> *</span> <a name="l00022"></a>00022 <span class="comment"> * The Audacious team does not consider modular code linking to</span> <a name="l00023"></a>00023 <span class="comment"> * Audacious or using our public API to be a derived work.</span> <a name="l00024"></a>00024 <span class="comment"> */</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor"># include "config.h"</span> <a name="l00028"></a>00028 <span class="preprocessor">#endif</span> <a name="l00029"></a>00029 <span class="preprocessor"></span> <a name="l00030"></a>00030 <a name="l00031"></a>00031 <span class="preprocessor">#include <glib.h></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <stdlib.h></span> <a name="l00033"></a>00033 <span class="preprocessor">#include <string.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <ctype.h></span> <a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="preprocessor">#include <errno.h></span> <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="preprocessor">#ifdef HAVE_FTS_H</span> <a name="l00039"></a>00039 <span class="preprocessor"></span><span class="preprocessor"># include <sys/types.h></span> <a name="l00040"></a>00040 <span class="preprocessor"># include <sys/stat.h></span> <a name="l00041"></a>00041 <span class="preprocessor"># include <fts.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#endif</span> <a name="l00043"></a>00043 <span class="preprocessor"></span> <a name="l00044"></a>00044 <span class="preprocessor">#include <libaudcore/audstrings.h></span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#include "<a class="code" href="audconfig_8h.html">audconfig.h</a>"</span> <a name="l00047"></a>00047 <span class="preprocessor">#include "<a class="code" href="debug_8h.html">debug.h</a>"</span> <a name="l00048"></a>00048 <span class="preprocessor">#include "<a class="code" href="i18n_8h.html">i18n.h</a>"</span> <a name="l00049"></a>00049 <span class="preprocessor">#include "<a class="code" href="misc_8h.html">misc.h</a>"</span> <a name="l00050"></a>00050 <span class="preprocessor">#include "<a class="code" href="plugins_8h.html">plugins.h</a>"</span> <a name="l00051"></a>00051 <span class="preprocessor">#include "<a class="code" href="util_8h.html">util.h</a>"</span> <a name="l00052"></a>00052 <a name="l00053"></a>00053 <a class="code" href="configdb-api_8h.html#a3ac4dad7ee7fd2890139bff9a134ee9a">gboolean</a> <a name="l00054"></a><a class="code" href="util_8h.html#aefd282c1c561ff3fcd88d2ed3d43bd2c">00054</a> <a class="code" href="util_8c.html#aefd282c1c561ff3fcd88d2ed3d43bd2c">dir_foreach</a>(<span class="keyword">const</span> gchar * <a class="code" href="plugins-api_8h.html#aed23534511ec9dec0630ca4854c4552b">path</a>, <a class="code" href="util_8h.html#aa8c71e96f3fb21b81a9c7defb9f48753">DirForeachFunc</a> function, <a name="l00055"></a>00055 gpointer user_data, GError ** <a class="code" href="audctrl_8c.html#abc39a4bba3587c275762137dee2c3fc1">error</a>) <a name="l00056"></a>00056 { <a name="l00057"></a>00057 GError *error_out = NULL; <a name="l00058"></a>00058 GDir *dir; <a name="l00059"></a>00059 <span class="keyword">const</span> gchar *<a class="code" href="playlist-api_8h.html#abaa108414cc2c74407885fb19e375eb7">entry</a>; <a name="l00060"></a>00060 gchar *entry_fullpath; <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="keywordflow">if</span> (!(dir = g_dir_open(path, 0, &error_out))) { <a name="l00063"></a>00063 g_propagate_error(error, error_out); <a name="l00064"></a>00064 <span class="keywordflow">return</span> FALSE; <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordflow">while</span> ((entry = g_dir_read_name(dir))) { <a name="l00068"></a>00068 entry_fullpath = g_build_filename(path, entry, NULL); <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="keywordflow">if</span> ((*function) (entry_fullpath, entry, user_data)) { <a name="l00071"></a>00071 g_free(entry_fullpath); <a name="l00072"></a>00072 <span class="keywordflow">break</span>; <a name="l00073"></a>00073 } <a name="l00074"></a>00074 <a name="l00075"></a>00075 g_free(entry_fullpath); <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <a name="l00078"></a>00078 g_dir_close(dir); <a name="l00079"></a>00079 <a name="l00080"></a>00080 <span class="keywordflow">return</span> TRUE; <a name="l00081"></a>00081 } <a name="l00082"></a>00082 <a name="l00091"></a>00091 gchar* <a name="l00092"></a><a class="code" href="util_8c.html#a0c8bcaa04dab89b16587878c5033618a">00092</a> <a class="code" href="util_8c.html#a0c8bcaa04dab89b16587878c5033618a" title="util_get_localdir:">util_get_localdir</a>(<span class="keywordtype">void</span>) <a name="l00093"></a>00093 { <a name="l00094"></a>00094 gchar *datadir; <a name="l00095"></a>00095 gchar *tmp; <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="keywordflow">if</span> ( (tmp = getenv(<span class="stringliteral">"XDG_CONFIG_HOME"</span>)) == NULL ) <a name="l00098"></a>00098 datadir = g_build_filename( g_get_home_dir() , <span class="stringliteral">".config"</span> , <span class="stringliteral">"audacious"</span> , NULL ); <a name="l00099"></a>00099 <span class="keywordflow">else</span> <a name="l00100"></a>00100 datadir = g_build_filename( tmp , <span class="stringliteral">"audacious"</span> , NULL ); <a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="keywordflow">return</span> datadir; <a name="l00103"></a>00103 } <a name="l00104"></a>00104 <a name="l00105"></a>00105 <a name="l00106"></a><a class="code" href="util_8c.html#add00a573f6606985a8ae373b25168433">00106</a> gchar * <a class="code" href="util_8c.html#add00a573f6606985a8ae373b25168433">construct_uri</a> (<span class="keyword">const</span> gchar * <span class="keywordtype">string</span>, <span class="keyword">const</span> gchar * playlist_name) <a name="l00107"></a>00107 { <a name="l00108"></a>00108 gchar *<a class="code" href="misc-api_8h.html#a820d8643bcfa9e2641dd6377f804de20">filename</a> = g_strdup(<span class="keywordtype">string</span>); <a name="l00109"></a>00109 gchar *uri = NULL; <a name="l00110"></a>00110 <a name="l00111"></a>00111 <span class="comment">/* try to translate dos path */</span> <a name="l00112"></a>00112 <a class="code" href="audstrings_8c.html#a48c422999c8590222573865843798714">convert_dos_path</a>(filename); <span class="comment">/* in place replacement */</span> <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="comment">// make full path uri here</span> <a name="l00115"></a>00115 <span class="comment">// case 1: filename is raw full path or uri</span> <a name="l00116"></a>00116 <span class="keywordflow">if</span> (filename[0] == <span class="charliteral">'/'</span> || strstr(filename, <span class="stringliteral">"://"</span>)) { <a name="l00117"></a>00117 uri = g_filename_to_uri(filename, NULL, NULL); <a name="l00118"></a>00118 <span class="keywordflow">if</span>(!uri) <a name="l00119"></a>00119 uri = g_strdup(filename); <a name="l00120"></a>00120 } <a name="l00121"></a>00121 <span class="comment">// case 2: filename is not raw full path nor uri</span> <a name="l00122"></a>00122 <span class="comment">// make full path by replacing last part of playlist path with filename.</span> <a name="l00123"></a>00123 <span class="keywordflow">else</span> <a name="l00124"></a>00124 { <a name="l00125"></a>00125 <span class="keyword">const</span> gchar * fslash = strrchr (filename, <span class="charliteral">'/'</span>); <a name="l00126"></a>00126 <span class="keyword">const</span> gchar * pslash = strrchr (playlist_name, <span class="charliteral">'/'</span>); <a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="keywordflow">if</span> (pslash) <a name="l00129"></a>00129 uri = g_strdup_printf (<span class="stringliteral">"%.*s/%s"</span>, (<a class="code" href="misc-api_8h.html#acf599c059f43e0cca83145eb6b0c93cd">gint</a>) (pslash - playlist_name), <a name="l00130"></a>00130 playlist_name, fslash ? fslash + 1 : filename); <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <a name="l00133"></a>00133 g_free (filename); <a name="l00134"></a>00134 <span class="keywordflow">return</span> uri; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00137"></a>00137 <span class="comment">/* local files -- not URI's */</span> <a name="l00138"></a><a class="code" href="util_8h.html#ad97b5479f55862897b2842f9e358a4b4">00138</a> <a class="code" href="misc-api_8h.html#acf599c059f43e0cca83145eb6b0c93cd">gint</a> <a class="code" href="util_8c.html#ad97b5479f55862897b2842f9e358a4b4">file_get_mtime</a> (<span class="keyword">const</span> gchar * <a class="code" href="misc-api_8h.html#a820d8643bcfa9e2641dd6377f804de20">filename</a>) <a name="l00139"></a>00139 { <a name="l00140"></a>00140 <span class="keyword">struct </span>stat info; <a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="keywordflow">if</span> (stat (filename, & info)) <a name="l00143"></a>00143 <span class="keywordflow">return</span> -1; <a name="l00144"></a>00144 <a name="l00145"></a>00145 <span class="keywordflow">return</span> info.st_mtime; <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00148"></a>00148 <span class="keywordtype">void</span> <a name="l00149"></a><a class="code" href="util_8h.html#a80a528b743572fe978ca2bbe876d2feb">00149</a> <a class="code" href="util_8c.html#a80a528b743572fe978ca2bbe876d2feb">make_directory</a>(<span class="keyword">const</span> gchar * <a class="code" href="plugins-api_8h.html#aed23534511ec9dec0630ca4854c4552b">path</a>, mode_t mode) <a name="l00150"></a>00150 { <a name="l00151"></a>00151 <span class="keywordflow">if</span> (g_mkdir_with_parents(path, mode) == 0) <a name="l00152"></a>00152 <span class="keywordflow">return</span>; <a name="l00153"></a>00153 <a name="l00154"></a>00154 g_printerr(<a class="code" href="i18n_8h.html#a32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"Could not create directory (%s): %s\n"</span>), path, <a name="l00155"></a>00155 g_strerror(errno)); <a name="l00156"></a>00156 } <a name="l00157"></a>00157 <a name="l00158"></a><a class="code" href="util_8c.html#a49d8ae867f44d07b3de55d32cdc808ba">00158</a> <span class="preprocessor">#define URL_HISTORY_MAX_SIZE 30</span> <a name="l00159"></a>00159 <span class="preprocessor"></span> <a name="l00160"></a>00160 <span class="keywordtype">void</span> <a name="l00161"></a><a class="code" href="util_8c.html#a953e4438b65994f9b7de525af01be3e7">00161</a> <a class="code" href="util_8c.html#a953e4438b65994f9b7de525af01be3e7">util_add_url_history_entry</a>(<span class="keyword">const</span> gchar * url) <a name="l00162"></a>00162 { <a name="l00163"></a>00163 <span class="keywordflow">if</span> (g_list_find_custom(<a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history, url, (GCompareFunc) strcasecmp)) <a name="l00164"></a>00164 <span class="keywordflow">return</span>; <a name="l00165"></a>00165 <a name="l00166"></a>00166 <a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history = g_list_prepend(<a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history, g_strdup(url)); <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="keywordflow">while</span> (g_list_length(<a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history) > <a class="code" href="util_8c.html#a49d8ae867f44d07b3de55d32cdc808ba">URL_HISTORY_MAX_SIZE</a>) { <a name="l00169"></a>00169 GList *node = g_list_last(<a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history); <a name="l00170"></a>00170 g_free(node->data); <a name="l00171"></a>00171 <a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history = g_list_delete_link(<a class="code" href="audconfig_8c.html#a98bd56a064259046a6cc6b1a620badf8">cfg</a>.url_history, node); <a name="l00172"></a>00172 } <a name="l00173"></a>00173 } <a name="l00174"></a>00174 <a name="l00175"></a><a class="code" href="util_8c.html#a0a122d21b30fd51ae9a0ff8011db0601">00175</a> <span class="keyword">static</span> <a class="code" href="configdb-api_8h.html#a3ac4dad7ee7fd2890139bff9a134ee9a">gboolean</a> <a class="code" href="util_8c.html#a0a122d21b30fd51ae9a0ff8011db0601">plugin_list_func</a> (<a class="code" href="structPluginHandle.html">PluginHandle</a> * plugin, GList * * <a class="code" href="misc-api_8h.html#a5b3afcdfb4bae9b4dd1b1ba8f2e6e638">list</a>) <a name="l00176"></a>00176 { <a name="l00177"></a>00177 gpointer p_hdr = <a class="code" href="plugin-registry_8c.html#aa9f011539a9eab34d41d5e82b21fe81f">plugin_get_header</a>(plugin); <a name="l00178"></a>00178 g_return_val_if_fail(p_hdr != NULL, TRUE); <a name="l00179"></a>00179 *list = g_list_prepend (*list, p_hdr); <a name="l00180"></a>00180 <span class="keywordflow">return</span> TRUE; <a name="l00181"></a>00181 } <a name="l00182"></a>00182 <a name="l00183"></a>00183 <span class="comment">/* Deprecated: This loads all the plugins at once, causing a major slowdown. */</span> <a name="l00184"></a><a class="code" href="util_8h.html#ac80b918c3b70c80aaf5107a181731281">00184</a> GList * <a class="code" href="util_8c.html#ac80b918c3b70c80aaf5107a181731281">plugin_get_list</a> (<a class="code" href="misc-api_8h.html#acf599c059f43e0cca83145eb6b0c93cd">gint</a> <a class="code" href="plugins-api_8h.html#aadb7c01f728e0e29453ee3c1279b3746">type</a>) <a name="l00185"></a>00185 { <a name="l00186"></a>00186 <span class="keyword">static</span> GList *<a class="code" href="misc-api_8h.html#a5b3afcdfb4bae9b4dd1b1ba8f2e6e638">list</a>[<a class="code" href="plugins_8h.html#a16af7b253440dadd46a80a4b9fddba4da19772b5cbccf50bc78640ca70094c2d6">PLUGIN_TYPES</a>] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="keywordflow">if</span> (list[type] == NULL) <a name="l00189"></a>00189 { <a name="l00190"></a>00190 <a class="code" href="plugin-registry_8c.html#a0ac22e2fe7cdfdd4f6262835126dea3d">plugin_for_each</a> (type, (<a class="code" href="plugins_8h.html#aca40a3a62c5957dc9ac52e5cbd131016">PluginForEachFunc</a>) <a class="code" href="util_8c.html#a0a122d21b30fd51ae9a0ff8011db0601">plugin_list_func</a>, & list[type]); <a name="l00191"></a>00191 list[<a class="code" href="plugins-api_8h.html#aadb7c01f728e0e29453ee3c1279b3746">type</a>] = g_list_reverse (list[type]); <a name="l00192"></a>00192 } <a name="l00193"></a>00193 <a name="l00194"></a>00194 <span class="keywordflow">return</span> list[<a class="code" href="plugins-api_8h.html#aadb7c01f728e0e29453ee3c1279b3746">type</a>]; <a name="l00195"></a>00195 } </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Sun Apr 17 2011 for Audacious by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address> </body> </html>