Main Page   Modules   Data Structures   File List   Data Fields   Globals  

path.cpp

Go to the documentation of this file.
00001 /*
00002  * path.cpp
00003  * Created on 25 Feb 2005
00004  * Authors:
00005  *    Wesley Leggette <wleggette@kaylix.net>
00006  * 
00007  * 
00008  * 
00009  * libdarc
00010  * 
00011  * 
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  * 
00026  * $Id: path_8cpp-source.html 708 2005-03-21 12:30:37Z leggwes $
00027  */
00028 
00035 #include "path.h"
00036 #if LIBDARC_HAVE_LIBDAR_HPP
00037 #include <dar/libdar.hpp>
00038 #endif
00039 
00040 NAMESPACE_LIBDAR_START
00041 
00042 extern "C" dar_path *dar_path_create( char* path )
00043 {
00044     libdar::path* ret;
00045     try {
00046         ret = new libdar::path( path );
00047     } catch (...) {
00048         return NULL;
00049     }
00050     return (dar_path*)ret;
00051 }
00052 
00053 extern "C" dar_path *dar_path_copy( dar_path* ref )
00054 {
00055     libdar::path* tmp = (libdar::path*)ref;
00056     libdar::path* ret = new libdar::path( *tmp );
00057     return (dar_path*)ret;
00058 }
00059 
00060 extern "C" void dar_path_destroy( dar_path* ref )
00061 {
00062     libdar::path* tmp = (libdar::path*)ref;
00063     delete tmp;
00064 }
00065 
00066 extern "C" bool dar_path_compare( dar_path* ref, dar_path* path )
00067 {
00068     libdar::path* r = (libdar::path*)ref;
00069     libdar::path* p = (libdar::path*)path;
00070     return *r == *p;
00071 }
00072 
00073 extern "C" bool dar_path_is_relative( dar_path* ref )
00074 {
00075     libdar::path* r = (libdar::path*)ref;
00076     return r->is_relative();
00077 }
00078 
00079 extern "C" bool dar_path_is_subdir_of( dar_path* ref, dar_path* path, bool case_sensit )
00080 {
00081     libdar::path* r = (libdar::path*)ref;
00082     libdar::path* p = (libdar::path*)path;
00083     return r->is_subdir_of( *p, case_sensit );
00084 }
00085 
00086 
00087 extern "C" char *dar_path_iterate_next( dar_path* ref )
00088 {
00089     libdar::path* r = (libdar::path*)ref;
00090     std::string tmp;
00091     if ( !(r->read_subdir(tmp)) )
00092         return NULL;
00093     char* ret = (char*)malloc(tmp.length() + 1);
00094     if (ret == NULL) { return NULL; }
00095     strcpy( ret, tmp.c_str() );
00096     return ret;
00097 }
00098 
00099 extern "C" void dar_path_iterate_reset( dar_path* ref )
00100 {
00101     libdar::path* r = (libdar::path*)ref;
00102     r->reset_read();
00103     return;
00104 }
00105 
00106 extern "C" bool dar_path_stack_push( dar_path* ref, dar_path* path )
00107 {
00108     libdar::path* r = (libdar::path*)ref;
00109     libdar::path* p = (libdar::path*)path;
00110     try {
00111         (*r) += (*p);
00112     } catch (...) {
00113         return false;
00114     }
00115     return true;
00116 }
00117 
00118 extern "C" bool dar_path_stack_peek( dar_path* ref, char** name )
00119 {
00120     libdar::path* r = (libdar::path*)ref;
00121     std::string tmp = r->basename();
00122     *name = (char*)malloc(tmp.length() + 1);
00123     strcpy( *name, tmp.c_str() );
00124     if ( r->degre() > 1 )
00125         return true;
00126     else
00127         return false;
00128 }
00129 
00130 extern "C" bool dar_path_stack_pop( dar_path* ref, char** name )
00131 {
00132     libdar::path* r = (libdar::path*)ref;
00133     std::string tmp;
00134     if ( !(r->pop(tmp)) )
00135     {
00136         *name = NULL;
00137         return false;
00138     }
00139     *name = (char*)malloc(tmp.length() + 1);
00140     if ( *name == NULL ) { return false; }
00141     strcpy( *name, tmp.c_str() );
00142     return true;
00143 }
00144 
00145 extern "C" bool dar_path_stack_pop_front( dar_path* ref, char** name )
00146 {
00147     libdar::path* r = (libdar::path*)ref;
00148     std::string tmp;
00149     if ( !(r->pop_front(tmp)) )
00150     {
00151         *name = NULL;
00152         return false;
00153     }
00154     *name = (char*)malloc(tmp.length() + 1);
00155     if ( *name == NULL ) { return false; }
00156     strcpy( *name, tmp.c_str() );
00157     return true;
00158 }
00159 
00160 
00161 extern "C" char *dar_path_get_string( dar_path* ref )
00162 {
00163     libdar::path* r = (libdar::path*)ref;
00164     std::string tmp = r->display();
00165     char* ret = (char*)malloc(tmp.length() + 1);
00166     if ( ret == NULL ) { return false; }
00167     strcpy( ret, tmp.c_str() );
00168     return ret;
00169 }
00170 
00171 extern "C" unsigned int dar_path_get_depth( dar_path* ref )
00172 {
00173     libdar::path* r = (libdar::path*)ref;
00174     return r->degre();
00175 }
00176 
00177 
00178 
00179 NAMESPACE_LIBDAR_END
00180