The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pathunix.c File Reference

#include "jam.h"
#include "pathsys.h"
#include "strings.h"
#include "newstr.h"
#include "filesys.h"

Include dependency graph for pathunix.c:

Include dependency graph

Go to the source code of this file.

Functions

char as_path_delim (char c)
int is_path_delim (char c)
void path_build (PATHNAME *f, string *file, int binding)
void path_parent (PATHNAME *f)
void path_parse (char *file, PATHNAME *f)

Variables

char path_delims []


Function Documentation

char as_path_delim char  c  )  [static]
 

Definition at line 163 of file pathunix.c.

References c, and is_path_delim().

Referenced by path_build().

00164 {
00165     return is_path_delim( c ) ? c : PATH_DELIM;
00166 }

Here is the call graph for this function:

int is_path_delim char  c  )  [static]
 

Definition at line 153 of file pathunix.c.

References c, p, and path_delims.

Referenced by as_path_delim(), and path_build().

00154 {
00155     char* p = strchr( path_delims, c );
00156     return p && *p;
00157 }

void path_build PATHNAME f,
string file,
int  binding
 

Definition at line 186 of file pathunix.c.

References as_path_delim(), f(), file, file_build1(), is_path_delim(), PATHNAME, string_append_range(), and string_push_back().

Referenced by builtin_glob_back(), file_dirscan(), search(), search_for_target(), timestamp(), var_edit_file(), and while().

00190 {
00191     file_build1( f, file );
00192     
00193     /* Don't prepend root if it's . or directory is rooted */
00194 # if PATH_DELIM == '/'
00195 
00196     if( f->f_root.len 
00197         && !( f->f_root.len == 1 && f->f_root.ptr[0] == '.' )
00198         && !( f->f_dir.len && f->f_dir.ptr[0] == '/' ) )
00199 
00200 # else /* unix */
00201 
00202     if( f->f_root.len 
00203         && !( f->f_root.len == 1 && f->f_root.ptr[0] == '.' )
00204         && !( f->f_dir.len && f->f_dir.ptr[0] == '/' )
00205         && !( f->f_dir.len && f->f_dir.ptr[0] == '\\' )
00206         && !( f->f_dir.len && f->f_dir.ptr[1] == ':' ) )
00207 
00208 # endif /* unix */
00209 
00210     {
00211         string_append_range( file, f->f_root.ptr, f->f_root.ptr + f->f_root.len  );
00212         string_push_back( file, as_path_delim( f->f_root.ptr[f->f_root.len] ) );
00213     }
00214 
00215     if( f->f_dir.len )
00216     {
00217         string_append_range( file, f->f_dir.ptr, f->f_dir.ptr + f->f_dir.len  );
00218     }
00219 
00220     /* UNIX: Put / between dir and file */
00221     /* NT:   Put \ between dir and file */
00222 
00223     if( f->f_dir.len && ( f->f_base.len || f->f_suffix.len ) )
00224     {
00225         /* UNIX: Special case for dir \ : don't add another \ */
00226         /* NT:   Special case for dir / : don't add another / */
00227 
00228 # if PATH_DELIM == '\\'
00229         if( !( f->f_dir.len == 3 && f->f_dir.ptr[1] == ':' ) )
00230 # endif
00231             if( !( f->f_dir.len == 1 && is_path_delim( f->f_dir.ptr[0] ) ) )
00232                 string_push_back( file, as_path_delim( f->f_dir.ptr[f->f_dir.len] ) );
00233     }
00234 
00235     if( f->f_base.len )
00236     {
00237         string_append_range( file, f->f_base.ptr, f->f_base.ptr + f->f_base.len  );
00238     }
00239 
00240     if( f->f_suffix.len )
00241     {
00242         string_append_range( file, f->f_suffix.ptr, f->f_suffix.ptr + f->f_suffix.len  );
00243     }
00244 
00245     if( f->f_member.len )
00246     {
00247         string_push_back( file, '(' );
00248         string_append_range( file, f->f_member.ptr, f->f_member.ptr + f->f_member.len  );
00249         string_push_back( file, ')' );
00250     }
00251 }

Here is the call graph for this function:

void path_parent PATHNAME f  ) 
 

Definition at line 258 of file pathunix.c.

References f(), and PATHNAME.

Referenced by timestamp(), and var_edit_file().

00259 {
00260         /* just set everything else to nothing */
00261 
00262         f->f_base.ptr =
00263         f->f_suffix.ptr =
00264         f->f_member.ptr = "";
00265 
00266         f->f_base.len = 
00267         f->f_suffix.len = 
00268         f->f_member.len = 0;
00269 }

Here is the call graph for this function:

void path_parse char *  file,
PATHNAME f
 

Definition at line 56 of file pathunix.c.

References end, f(), file, p, and PATHNAME.

Referenced by builtin_glob_back(), search(), search_for_target(), timestamp(), and var_edit_file().

00059 {
00060         char *p, *q;
00061         char *end;
00062         
00063         memset( (char *)f, 0, sizeof( *f ) );
00064 
00065         /* Look for <grist> */
00066 
00067         if( file[0] == '<' && ( p = strchr( file, '>' ) ) )
00068         {
00069             f->f_grist.ptr = file;
00070             f->f_grist.len = p - file;
00071             file = p + 1;
00072         }
00073 
00074         /* Look for dir/ */
00075 
00076         p = strrchr( file, '/' );
00077 
00078 # if PATH_DELIM == '\\'
00079         /* On NT, look for dir\ as well */
00080         {
00081             char *p1 = strrchr( file, '\\' );
00082             p = p1 > p ? p1 : p;
00083         }
00084 # endif
00085 
00086         if( p )
00087         {
00088             f->f_dir.ptr = file;
00089             f->f_dir.len = p - file;
00090         
00091             /* Special case for / - dirname is /, not "" */
00092 
00093             if( !f->f_dir.len )
00094                 f->f_dir.len = 1;
00095 
00096 # if PATH_DELIM == '\\'
00097             /* Special case for D:/ - dirname is D:/, not "D:" */
00098 
00099             if( f->f_dir.len == 2 && file[1] == ':' )
00100                 f->f_dir.len = 3;
00101 # endif
00102 
00103             file = p + 1;
00104         }
00105 
00106         end = file + strlen( file );
00107 
00108         /* Look for (member) */
00109 
00110         if( ( p = strchr( file, '(' ) ) && end[-1] == ')' )
00111         {
00112             f->f_member.ptr = p + 1;
00113             f->f_member.len = end - p - 2;
00114             end = p;
00115         } 
00116 
00117         /* Look for .suffix */
00118         /* This would be memrchr() */
00119 
00120         p = 0;
00121         q = file;
00122 
00123         while( q = (char *)memchr( q, '.', end - q ) )
00124             p = q++;
00125 
00126         if( p )
00127         {
00128             f->f_suffix.ptr = p;
00129             f->f_suffix.len = end - p;
00130             end = p;
00131         }
00132 
00133         /* Leaves base */
00134 
00135         f->f_base.ptr = file;
00136         f->f_base.len = end - file;
00137 }

Here is the call graph for this function:


Variable Documentation

char path_delims[] [static]
 

Initial value:

 {
    PATH_DELIM,



    0
}

Definition at line 142 of file pathunix.c.

Referenced by is_path_delim().


Generated on Mon Nov 8 17:08:16 2004 for MPT by  doxygen 1.3.9.1