for(; (*fwdPtr != '\0') && (*fwdPtr != '?') && (*fwdPtr != '#'); ++fwdPtr) { if (*fwdPtr == '%' && *(fwdPtr+1) == '2' && (*(fwdPtr+2) == 'E' || *(fwdPtr+2) == 'e')) { *urlPtr++ = '.'; ++fwdPtr; ++fwdPtr; } else { *urlPtr++ = *fwdPtr; } }  for (; *fwdPtr != '\0'; ++fwdPtr) { *urlPtr++ = *fwdPtr; } *urlPtr = '\0';   fwdPtr = path; urlPtr = path;
net_CoalesceDirs(netCoalesceFlags flags, char* path){    /* Stolen from the old netlib's mkparse.c.     *     * modifies a url of the form   /foo/../foo1  ->  /foo1     *                       and    /foo/./foo1   ->  /foo/foo1     *                       and    /foo/foo1/..  ->  /foo/     */    char *fwdPtr = path;    char *urlPtr = path;    PRUint32 traversal = 0;    PRUint32 special_ftp_len = 0;    /* Remember if this url is a special ftp one: */    if (flags & NET_COALESCE_DOUBLE_SLASH_IS_ROOT)     {       /* some schemes (for example ftp) have the speciality that           the path can begin // or /%2F to mark the root of the           servers filesystem, a simple / only marks the root relative           to the user loging in. We remember the length of the marker */        if (nsCRT::strncasecmp(path,"/%2F",4) == 0)            special_ftp_len = 4;        else if (nsCRT::strncmp(path,"//",2) == 0 )            special_ftp_len = 2;     }    for(; (*fwdPtr != '\0') &&             (*fwdPtr != '?') &&             (*fwdPtr != '#'); ++fwdPtr)    {#if defined(XP_WIN)        // At first, If this is DBCS character, it skips next character.        if (::IsDBCSLeadByte(*fwdPtr) && *(fwdPtr+1) != '\0')         {            *urlPtr++ = *fwdPtr++;            *urlPtr++ = *fwdPtr;            continue;        }#endif        if (*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '/' )        {            // remove . followed by slash            ++fwdPtr;        }        else if(*fwdPtr == '/' && *(fwdPtr+1) == '.' && *(fwdPtr+2) == '.' &&                 (*(fwdPtr+3) == '/' ||                     *(fwdPtr+3) == '\0' || // This will take care of                     *(fwdPtr+3) == '?' ||  // something like foo/bar/..#sometag                    *(fwdPtr+3) == '#'))        {            // remove foo/..             // reverse the urlPtr to the previous slash if possible            // if url does not allow relative root then drop .. above root             // otherwise retain them in the path             if(traversal > 0 || !(flags &                                   NET_COALESCE_ALLOW_RELATIVE_ROOT))            {                 if (urlPtr != path)                    urlPtr--; // we must be going back at least by one                 for(;*urlPtr != '/' && urlPtr != path; urlPtr--)                    ;  // null body                 --traversal; // count back                // forward the fwdPtr past the ../                fwdPtr += 2;                // if we have reached the beginning of the path                // while searching for the previous / and we remember                // that it is an url that begins with /%2F then                // advance urlPtr again by 3 chars because /%2F already                 // marks the root of the path                if (urlPtr == path && special_ftp_len > 3)                 {                    ++urlPtr;                    ++urlPtr;                    ++urlPtr;                }                // special case if we have reached the end                 // to preserve the last /                if (*fwdPtr == '.' && *(fwdPtr+1) == '\0')                    ++urlPtr;            }             else             {                // there are to much /.. in this path, just copy them instead.                // forward the urlPtr past the /.. and copying it                // However if we remember it is an url that starts with                // /%2F and urlPtr just points at the "F" of "/%2F" then do                 // not overwrite it with the /, just copy .. and move forward                // urlPtr.                 if (special_ftp_len > 3 && urlPtr == path+special_ftp_len-1)                    ++urlPtr;                else                     *urlPtr++ = *fwdPtr;                ++fwdPtr;                *urlPtr++ = *fwdPtr;                ++fwdPtr;                *urlPtr++ = *fwdPtr;            }        }        else        {            // count the hierachie, but only if we do not have reached            // the root of some special urls with a special root marker             if (*fwdPtr == '/' &&  *(fwdPtr+1) != '.' &&               (special_ftp_len != 2 || *(fwdPtr+1) != '/'))                traversal++;            // copy the url incrementaly             *urlPtr++ = *fwdPtr;        }    }    // Copy remaining stuff past the #?;    for (; *fwdPtr != '\0'; ++fwdPtr)    {        *urlPtr++ = *fwdPtr;    }    *urlPtr = '\0';  // terminate the url     /*      *  Now lets remove trailing . case     *     /foo/foo1/.   ->  /foo/foo1/     */    if ((urlPtr > (path+1)) && (*(urlPtr-1) == '.') && (*(urlPtr-2) == '/'))        *(urlPtr-1) = '\0';}