diff -N -r -u -b boost_1_34_0/tools/jam/src/pathamiga.c boost_1_34_0_amiga/tools/jam/src/pathamiga.c --- boost_1_34_0/tools/jam/src/pathamiga.c 2114-02-06 23:28:16 +++ boost_1_34_0_amiga/tools/jam/src/pathamiga.c 2007-06-02 08:10:21 @@ -0,0 +1,208 @@ +/* + * This file is part of Jam - see jam.c for Copyright information. + */ + +#include "jam.h" + +#if defined(OS_AMIGA) + +#include "pathsys.h" +#include "strings.h" +#include "newstr.h" +#include "filesys.h" + +#include +#include + + +/* + * pathamiga.c - manipulate file names on AmigaOS + * + * External routines: + * + * path_parse() - split a file name into dir/base/suffix/member + * path_build() - build a filename given dir/base/suffix/member + * path_parent() - make a PATHNAME point to its parent dir + * + * file_parse() and path_build() just manipuate a string and a structure; + * they do not make system calls. + */ + + +/* + * path_parse() - split a file name into dir/base/suffix/member + */ +void path_parse(char *file, PATHNAME *f) +{ + char *p, *q; + char *end; + + memset( (char *)f, 0, sizeof( *f ) ); + + /* Look for */ + if( file[0] == '<' && ( p = strchr( file, '>' ) ) ) + { + f->f_grist.ptr = file; + f->f_grist.len = p - file; + file = p + 1; + } + + /* Look for dir/ */ + p = strrchr( file, '/' ); + + if( p ) + { + f->f_dir.ptr = file; + f->f_dir.len = p - file; + + /* Special case for / - dirname is /, not "" */ + if( !f->f_dir.len ) + f->f_dir.len = 1; + + file = p + 1; + } + + end = file + strlen( file ); + + /* Look for (member) */ + if( ( p = strchr( file, '(' ) ) && end[-1] == ')' ) + { + f->f_member.ptr = p + 1; + f->f_member.len = end - p - 2; + end = p; + } + + /* Look for .suffix */ + /* This would be memrchr() */ + p = 0; + q = file; + + while( q = (char *)memchr( q, '.', end - q ) ) + p = q++; + + if( p ) + { + f->f_suffix.ptr = p; + f->f_suffix.len = end - p; + end = p; + } + + /* Leaves base */ + f->f_base.ptr = file; + f->f_base.len = end - file; +} + + +/* + * is_path_delim() - true iff c is a path delimiter + */ +static int is_path_delim(char c) +{ + return c == PATH_DELIM; +} + + +/* + * as_path_delim() - convert c to a path delimiter if it isn't one + * already + */ +static char as_path_delim( char c ) +{ + return is_path_delim(c) ? c : PATH_DELIM; +} + + +/* + * path_build() - build a filename given dir/base/suffix/member + */ +void path_build(PATHNAME *f, string *file, int binding) +{ + file_build1( f, file ); + + /* Don't prepend root if it's . or directory is rooted */ + if( f->f_root.len + && !( f->f_root.len == 1 && f->f_root.ptr[0] == '.' ) + && !( f->f_dir.len && f->f_dir.ptr[0] == '/' ) ) + { + string_append_range( file, f->f_root.ptr, f->f_root.ptr + f->f_root.len ); + /* If 'root' already ends with path delimeter, don't add yet another one. */ + if( ! is_path_delim( f->f_root.ptr[f->f_root.len-1] ) ) + string_push_back( file, as_path_delim( f->f_root.ptr[f->f_root.len] ) ); + } + + if( f->f_dir.len ) + { + string_append_range( file, f->f_dir.ptr, f->f_dir.ptr + f->f_dir.len ); + } + + /* Put / between dir and file */ + if( f->f_dir.len && ( f->f_base.len || f->f_suffix.len ) ) + { + /* Special case for dir / : don't add another / */ + if( !( f->f_dir.len == 1 && is_path_delim( f->f_dir.ptr[0] ) ) ) + string_push_back( file, as_path_delim( f->f_dir.ptr[f->f_dir.len] ) ); + } + + if( f->f_base.len ) + { + string_append_range( file, f->f_base.ptr, f->f_base.ptr + f->f_base.len ); + } + + if( f->f_suffix.len ) + { + string_append_range( file, f->f_suffix.ptr, f->f_suffix.ptr + f->f_suffix.len ); + } + + if( f->f_member.len ) + { + string_push_back( file, '(' ); + string_append_range( file, f->f_member.ptr, f->f_member.ptr + f->f_member.len ); + string_push_back( file, ')' ); + } +} + + +/* + * path_parent() - make a PATHNAME point to its parent dir + */ +void path_parent(PATHNAME *f) +{ + f->f_base.ptr = ""; + f->f_suffix.ptr = ""; + f->f_member.ptr = ""; + + f->f_base.len = 0; + f->f_suffix.len = 0; + f->f_member.len = 0; +} + + +const char * path_tmpdir() +{ + return "\t"; +} + + +const char * path_tmpnam(void) +{ + static char tmpbuf[64]; + uint32 pid = ((struct Process*)IExec->FindTask(0))->pr_ProcessID; + snprintf(tmpbuf, sizeof(tmpbuf), "jam.%u.XXXXXX", pid); + (void) mktemp(tmpbuf); + + return newstr(tmpbuf); +} + + +const char * path_tmpfile(void) +{ + const char * result = 0; + + static char pathbuf[4096]; + snprintf(pathbuf, sizeof(pathbuf), "%s%c%s", + path_tmpdir(), PATH_DELIM, path_tmpnam()); + + return newstr(pathbuf); +} + +#endif