diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 8cf4488748aa63264bef443bac67f3c146804cc8..d65f97adb9535a04d6a7f19240e1838c6970bf09 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -2,11 +2,11 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: builtin_functions.c,v 1.522 2003/12/06 10:08:55 nilsson Exp $ +|| $Id: builtin_functions.c,v 1.523 2003/12/18 21:22:23 marcus Exp $ */ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.522 2003/12/06 10:08:55 nilsson Exp $"); +RCSID("$Id: builtin_functions.c,v 1.523 2003/12/18 21:22:23 marcus Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -1248,6 +1248,7 @@ PMOD_EXPORT void f_add_constant(INT32 args) /*! @decl string combine_path(string absolute, string ... relative) *! @decl string combine_path_unix(string absolute, string ... relative) *! @decl string combine_path_nt(string absolute, string ... relative) + *! @decl string combine_path_amigaos(string absolute, string ... relative) *! *! Concatenate a relative path to an absolute path and remove any *! @expr{"//"@}, @expr{"/.."@} or @expr{"/."@} to produce a @@ -1255,10 +1256,13 @@ PMOD_EXPORT void f_add_constant(INT32 args) *! *! @[combine_path_nt()] concatenates according to NT-filesystem conventions, *! while @[combine_path_unix()] concatenates according to UNIX-style. + *! @[combine_path_amigaos()] concatenates according to AmigaOS filesystem + *! conventions. *! *! @[combine_path()] is equvivalent to @[combine_path_unix()] on UNIX-like - *! operating systems, and equvivalent to @[combine_path_nt()] on NT-like - *! operating systems. + *! operating systems, and equivalent to @[combine_path_nt()] on NT-like + *! operating systems, and equivalent to @[combine_path_amigaos()] on + *! AmigaOS-like operating systems. *! *! @seealso *! @[getcwd()], @[Stdio.append_path()] @@ -1270,6 +1274,9 @@ PMOD_EXPORT void f_add_constant(INT32 args) #define UNIX_COMBINE_PATH #include "combine_path.h" +#define AMIGAOS_COMBINE_PATH +#include "combine_path.h" + /*! @decl int zero_type(mixed a) @@ -7997,10 +8004,15 @@ void init_builtin_efuns(void) /* function(string...:string) */ ADD_EFUN("combine_path_nt",f_combine_path_nt,tFuncV(tNone,tStr,tStr),0); ADD_EFUN("combine_path_unix",f_combine_path_unix,tFuncV(tNone,tStr,tStr),0); + ADD_EFUN("combine_path_amigaos",f_combine_path_amigaos,tFuncV(tNone,tStr,tStr),0); #ifdef __NT__ ADD_EFUN("combine_path",f_combine_path_nt,tFuncV(tNone,tStr,tStr),0); +#else +#ifdef __amigaos__ + ADD_EFUN("combine_path",f_combine_path_amigaos,tFuncV(tNone,tStr,tStr),0); #else ADD_EFUN("combine_path",f_combine_path_unix,tFuncV(tNone,tStr,tStr),0); +#endif #endif ADD_EFUN("compile", f_compile, diff --git a/src/combine_path.h b/src/combine_path.h index 6eda2561935a92fab04726dc2fb452dd80fabbfe..6ad720f0b38a9f5509f14c31b97a5026358cfd13 100644 --- a/src/combine_path.h +++ b/src/combine_path.h @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: combine_path.h,v 1.12 2003/06/11 23:02:07 nilsson Exp $ +|| $Id: combine_path.h,v 1.13 2003/12/18 21:22:24 marcus Exp $ */ /* @@ -11,10 +11,13 @@ */ #undef IS_SEP +#undef IS_ANY_SEP #undef IS_ABS #undef IS_ROOT #undef F_COMBINE_PATH #undef APPEND_PATH +#undef CHAR_CURRENT +#undef CHAR_ROOT #define COMBINE_PATH_DEBUG 0 @@ -23,6 +26,8 @@ #define IS_ABS(X) (IS_SEP( INDEX_PCHARP((X),0))?1:0) #define APPEND_PATH append_path_unix #define F_COMBINE_PATH f_combine_path_unix +#define CHAR_CURRENT '.' +#define CHAR_ROOT '/' #endif /* UNIX_COMBINE_PATH */ @@ -52,8 +57,40 @@ static int find_absolute(PCHARP s) #define APPEND_PATH append_path_nt #define F_COMBINE_PATH f_combine_path_nt +#define CHAR_CURRENT '.' +#define CHAR_ROOT '/' + #endif /* NT_COMBINE_PATH */ + +#ifdef AMIGAOS_COMBINE_PATH +#define IS_SEP(X) ( (X)=='/' ) +#define IS_ANY_SEP(X) ( (X) == '/' || (X) == ':' ) +#define IS_ABS(X) find_absolute2((X)) +#define IS_ROOT(X) ( ( INDEX_PCHARP((X),0) == CHAR_ROOT)?1:0) +#define APPEND_PATH append_path_amigaos +#define F_COMBINE_PATH f_combine_path_amigaos +#define CHAR_ROOT ':' + +static int find_absolute2(PCHARP s) +{ + int r=0, p=0; + int c; + while((c=INDEX_PCHARP(s,p))) { + ++p; + if(c == CHAR_ROOT) + r = p; + } + return r>1? r:0; +} + +#endif /* AMIGAOS_COMBINE_PATH */ + + +#ifndef IS_ANY_SEP +#define IS_ANY_SEP(X) IS_SEP(X) +#endif + static void APPEND_PATH(struct string_builder *s, PCHARP path, size_t len) @@ -94,21 +131,23 @@ static void APPEND_PATH(struct string_builder *s, #define PUSH(X) string_builder_putchar(s,(X)) /* Ensure s ends with a separator. */ - if(s->s->len && !IS_SEP(LAST_PUSHED())) + if(s->s->len && !IS_ANY_SEP(LAST_PUSHED())) PUSH('/'); if (!len) return; +#ifdef CHAR_CURRENT /* Remove initial "./" if any. */ if(s->s->len==2) { PCHARP to=MKPCHARP_STR(s->s); - if(INDEX_PCHARP(to, 0) == '.') + if(INDEX_PCHARP(to, 0) == CHAR_CURRENT) { s->s->len=0; s->known_shift=0; } } +#endif while(1) { @@ -120,6 +159,19 @@ static void APPEND_PATH(struct string_builder *s, #endif if(IS_SEP(LAST_PUSHED())) { +#ifdef AMIGAOS_COMBINE_PATH + if(from<len && INDEX_PCHARP(path, from) == '/' && + s->s->len>1 && !IS_ANY_SEP(index_shared_string(s->s,s->s->len-2))) { + /* Handle "//" */ + int tmp=s->s->len-2; + while(tmp>0 && !IS_ANY_SEP(index_shared_string(s->s,tmp-1))) + --tmp; + s->s->len=tmp; + s->known_shift=0; + from++; + continue; + } +#else /* !AMIGAOS_COMBINE_PATH */ while(s->s->len && IS_SEP(LAST_PUSHED())) s->s->len--; PUSH('/'); @@ -182,6 +234,7 @@ static void APPEND_PATH(struct string_builder *s, continue; } } +#endif /* !AMIGAOS_COMBINE_PATH */ } if(from>=len) break; @@ -196,9 +249,11 @@ static void APPEND_PATH(struct string_builder *s, { if(abs) { - PUSH('/'); + PUSH(CHAR_ROOT); +#ifdef CHAR_CURRENT }else{ - PUSH('.'); + PUSH(CHAR_CURRENT); +#endif } } } @@ -257,3 +312,4 @@ void F_COMBINE_PATH(INT32 args) #undef UNIX_COMBINE_PATH #undef NT_COMBINE_PATH +#undef AMIGAOS_COMBINE_PATH