pike.git / src / combine_path.h

version» Context lines:

pike.git/src/combine_path.h:173: Inside #if defined(AMIGAOS_COMBINE_PATH)
   /* 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 */ +  do { +  /* Remove sequences of ending slashes and single dots +  * from the result path. +  */    while(s->s->len && IS_SEP(LAST_PUSHED()))    s->s->len--; -  +  if (LAST_PUSHED() == '.') { +  if (s->s->len == 1) { +  /* Result path started with "./". */ +  s->s->len = 0; +  break; +  } else if (IS_SEP(index_shared_string(s->s, s->s->len-2))) { +  /* Result path ended with "/./". */ +  s->s->len -= 2; +  continue; +  } +  } +  /* Restore a single slash as directory separator. */    PUSH('/'); -  +  break; +  } while (1);    if(from<len && INDEX_PCHARP(path, from) == '.')    {    int c3;   #if COMBINE_PATH_DEBUG > 0    /* s->s->str[s->s->len]=0; */    fprintf(stderr, "combine_path(0), TO: \"%s\"[%d]\n",    s->s->str, s->s->len);    fprintf(stderr, "combine_path(0), FROM (%d): \"%s\"[%d]\n",    from, path.ptr+from, len - from);   #endif       switch(INDEX_PCHARP(path, from+1))    {    case '.':    c3=INDEX_PCHARP(path, from+2); -  if(IS_SEP(c3) || !c3) +  if(s->s->len && (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)))    break;    tmp++;    } else if (IS_SEP(index_shared_string(s->s, 0))) {    tmp++;    }       if (tmp < abs)    tmp = abs; -  else +  else { +  if (index_shared_string(s->s,tmp)=='.') {    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)))) +  IS_SEP(index_shared_string(s->s,tmp+2)))) {    break; -  +  } +  } +  }       from+=(c3? 3:2);    s->s->len=tmp;    s->known_shift=0;      #if COMBINE_PATH_DEBUG > 0    /* s->s->str[s->s->len]=0; */    fprintf(stderr,"combine_path(1), TO: %s[%d]\n",    s->s->str, s->s->len);    fprintf(stderr,"combine_path(1), FROM (%d): %s[%d]\n",
pike.git/src/combine_path.h:274:      #define F_FUNC(X) PIKE_CONCAT(f_,X)      void F_FUNC(COMBINE_PATH)(INT32 args)   {    int e;    int root=0;    struct string_builder ret;    ONERROR tmp;    -  check_all_args(DEFINETOSTR(COMBINE_PATH),args, +  check_all_args(NULL,args,    BIT_STRING, BIT_STRING | BIT_MANY | BIT_VOID, 0);       init_string_builder(&ret, 0);    SET_ONERROR(tmp, free_string_builder, &ret);      #if COMBINE_PATH_DEBUG > 0    for(e=0; e < args; e++) {    fprintf(stderr, "combine_path(), Arg #%d: \"%s\"[%d bytes]\n",    e, Pike_sp[e-args].u.string->str, Pike_sp[e-args].u.string->len);    }