Branch: Tag:

2001-06-10

2001-06-10 22:56:34 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Backported various combine_path() fixes from Pike 7.3.

Rev: src/combine_path.h:1.2

1: + /* +  * $Id: combine_path.h,v 1.2 2001/06/10 22:56:34 grubba Exp $ +  * +  * Combine path template. +  * +  */ +    #undef IS_SEP   #undef IS_ABS   #undef IS_ROOT
82:   #define LAST_PUSHED() (s->s->len ? index_shared_string(s->s,s->s->len-1) : 0)   #define PUSH(X) string_builder_putchar(s,(X))    +  /* Ensure s ends with a separator. */    if(s->s->len && !IS_SEP(LAST_PUSHED()))    PUSH('/');    -  while(s->s->len==2) +  /* Remove initial "./" if any. */ +  if(s->s->len==2)    {    PCHARP to=MKPCHARP_STR(s->s);    if(INDEX_PCHARP(to, 0) == '.')
99: Inside #if COMBINE_PATH_DEBUG > 1
   {   #if COMBINE_PATH_DEBUG > 1    s->s->str[s->s->len]=0; -  fprintf(stderr,"combine_path(2), TO: %s\n",s->s->str); -  fprintf(stderr,"combine_path(2), FROM (%d): %s\n",from,path.ptr+from); +  fprintf(stderr, "combine_path(2), TO: \"%s\"\n", s->s->str); +  fprintf(stderr, "combine_path(2), FROM (%d): \"%s\"\n", +  from, path.ptr+from);   #endif    if(IS_SEP(LAST_PUSHED()))    {
112: Inside #if COMBINE_PATH_DEBUG > 0
   int c3;   #if COMBINE_PATH_DEBUG > 0    s->s->str[s->s->len]=0; -  fprintf(stderr,"combine_path(0), TO: %s\n",s->s->str); -  fprintf(stderr,"combine_path(0), FROM (%d): %s\n",from,path.ptr+from); +  fprintf(stderr, "combine_path(0), TO: \"%s\"\n", s->s->str); +  fprintf(stderr, "combine_path(0), FROM (%d): \"%s\"\n", +  from, path.ptr+from);   #endif       switch(INDEX_PCHARP(path, from+1))
122:    c3=INDEX_PCHARP(path, from+2);    if(IS_SEP(c3) || !c3)    { +  /* Handle "..". */    int tmp=s->s->len-1;    -  +  if (tmp) {    while(--tmp>=0) -  if(IS_SEP(index_shared_string(s->s,tmp))) +  if(IS_SEP(index_shared_string(s->s, tmp)))    break;    tmp++; -  +  } else if (IS_SEP(index_shared_string(s->s, 0))) { +  tmp++; +  }    -  if(index_shared_string(s->s,tmp)=='.' && -  index_shared_string(s->s,tmp+1)=='.' && -  ( IS_SEP(index_shared_string(s->s,tmp+2)) || -  !index_shared_string(s->s,tmp+2))) +  if ((tmp+1 < s->s->len) && +  (index_shared_string(s->s,tmp)=='.') && +  (index_shared_string(s->s,tmp+1)=='.') && +  ( (tmp+2 == s->s->len) || +  IS_SEP(index_shared_string(s->s,tmp+2))))    break;      
154: Inside #if defined(NT_COMBINE_PATH)
  #ifdef NT_COMBINE_PATH    case '\\':   #endif +  /* Handle ".". */    from++;    continue;    }
163:    if(from>=len) break;    PUSH(INDEX_PCHARP(path, from++));    } -  if(s->s->len && +  if((s->s->len > 1) &&    !IS_SEP(INDEX_PCHARP(path, from-1)) &&    IS_SEP(LAST_PUSHED()))    s->s->len--;