Diff for /Amaya/amaya/AHTURLTools.c between versions 1.83 and 1.84

version 1.83, 2000/02/08 16:29:35 version 1.84, 2000/02/16 17:03:45
Line 322  STRING              aSuffix; Line 322  STRING              aSuffix;
   returns TRUE if path points to an HTML resource.    returns TRUE if path points to an HTML resource.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 ThotBool             IsHTMLName (const CharUnit* path)  ThotBool             IsHTMLName (const CHAR_T* path)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 ThotBool             IsHTMLName (path)  ThotBool             IsHTMLName (path)
 const CharUnit*      path;  const CHAR_T*        path;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    CharUnit          temppath[MAX_LENGTH];     CHAR_T            temppath[MAX_LENGTH];
    CharUnit          suffix[MAX_LENGTH];     CHAR_T            suffix[MAX_LENGTH];
    CharUnit          nsuffix[MAX_LENGTH];     CHAR_T            nsuffix[MAX_LENGTH];
    int               i;     int               i; 
   
    if (!path)     if (!path)
       return (FALSE);        return (FALSE);
   
    StringCopy (temppath, path);     ustrcpy (temppath, path);
    ExtractSuffix (temppath, suffix);     ExtractSuffix (temppath, suffix);
   
    /* Normalize the suffix */     /* Normalize the suffix */
    i = 0;     i = 0;
    while (suffix[i] != CUS_EOS && i < MAX_LENGTH -1)     while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
      {       {
        nsuffix[i] = ToLower (suffix[i]);         nsuffix[i] = utolower (suffix[i]);
        i++;         i++;
      }       }
    nsuffix[i] = EOS;     nsuffix[i] = WC_EOS;
    if (!StringCompare (nsuffix, CUSTEXT("html")) ||     if (!ustrcmp (nsuffix, TEXT("html")) ||
        !StringCompare (nsuffix, CUSTEXT("htm")) ||         !ustrcmp (nsuffix, TEXT("htm")) ||
        !StringCompare (nsuffix, CUSTEXT("shtml")) ||         !ustrcmp (nsuffix, TEXT("shtml")) ||
        !StringCompare (nsuffix, CUSTEXT("jsp")) ||         !ustrcmp (nsuffix, TEXT("jsp")) ||
        !StringCompare (nsuffix, CUSTEXT("xht")) ||         !ustrcmp (nsuffix, TEXT("xht")) ||
        !StringCompare (nsuffix, CUSTEXT("xhtm")) ||         !ustrcmp (nsuffix, TEXT("xhtm")) ||
        !StringCompare (nsuffix, CUSTEXT("xhtml")))         !ustrcmp (nsuffix, TEXT("xhtml")))
      return (TRUE);       return (TRUE);
    else if (!StringCompare (nsuffix, CUSTEXT("gz")))     else if (!ustrcmp (nsuffix, TEXT("gz")))
      {       {
        /* take into account compressed files */         /* take into account compressed files */
        ExtractSuffix (temppath, suffix);                ExtractSuffix (temppath, suffix);       
        /* Normalize the suffix */         /* Normalize the suffix */
        i = 0;         i = 0;
        while (suffix[i] != CUS_EOS && i < MAX_LENGTH -1)         while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
          {           {
            nsuffix[i] = ToLower (suffix[i]);             nsuffix[i] = utolower (suffix[i]);
            i++;             i++;
          }           }
        nsuffix[i] = CUS_EOS;         nsuffix[i] = WC_EOS;
        if (!StringCompare (nsuffix, CUSTEXT("html")) ||         if (!ustrcmp (nsuffix, TEXT("html")) ||
            !StringCompare (nsuffix, CUSTEXT("htm")) ||             !ustrcmp (nsuffix, TEXT("htm")) ||
            !StringCompare (nsuffix, CUSTEXT("shtml")) ||             !ustrcmp (nsuffix, TEXT("shtml")) ||
            !StringCompare (nsuffix, CUSTEXT("jsp")) ||             !ustrcmp (nsuffix, TEXT("jsp")) ||
            !StringCompare (nsuffix, CUSTEXT("xht")) ||             !ustrcmp (nsuffix, TEXT("xht")) ||
            !StringCompare (nsuffix, CUSTEXT("xhtm")) ||             !ustrcmp (nsuffix, TEXT("xhtm")) ||
            !StringCompare (nsuffix, CUSTEXT("xhtml")))             !ustrcmp (nsuffix, TEXT("xhtml")))
     
          return (TRUE);           return (TRUE);
        else         else
Line 632  const char         *url; Line 632  const char         *url;
   returns TRUE if path is in fact a URL.    returns TRUE if path is in fact a URL.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 ThotBool             IsW3Path (const CharUnit* path)  ThotBool             IsW3Path (const CHAR_T* path)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 ThotBool             IsW3Path (path)  ThotBool             IsW3Path (path)
 const CharUnit*      path;  const CHAR_T*        path;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   if (StringNCompare (path, CUSTEXT("http:"), 5)   &&     if (ustrncmp (path, TEXT("http:"), 5)   && 
       StringNCompare (path, CUSTEXT("ftp:"), 4)    &&        ustrncmp (path, TEXT("ftp:"), 4)    &&
       StringNCompare (path, CUSTEXT("telnet:"), 7) &&         ustrncmp (path, TEXT("telnet:"), 7) && 
       StringNCompare (path, CUSTEXT("wais:"), 5)   &&        ustrncmp (path, TEXT("wais:"), 5)   &&
       StringNCompare (path, CUSTEXT("news:"), 5)   &&         ustrncmp (path, TEXT("news:"), 5)   && 
       StringNCompare (path, CUSTEXT("gopher:"), 7) &&        ustrncmp (path, TEXT("gopher:"), 7) &&
       StringNCompare (path, CUSTEXT("mailto:"), 7) &&         ustrncmp (path, TEXT("mailto:"), 7) && 
       StringNCompare (path, CUSTEXT("archie:"), 7))        ustrncmp (path, TEXT("archie:"), 7))
     return FALSE;      return FALSE;
   return TRUE;    return TRUE;
 }  }
Line 682  const STRING       url; Line 682  const STRING       url;
       - or the document path (without document name).        - or the document path (without document name).
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 CharUnit*           GetBaseURL (Document doc)  CHAR_T*             GetBaseURL (Document doc)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 CharUnit*           GetBaseURL (doc)  CHAR_T*             GetBaseURL (doc)
 Document            doc;  Document            doc;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
Line 692  Document            doc; Line 692  Document            doc;
   ElementType         elType;    ElementType         elType;
   AttributeType       attrType;    AttributeType       attrType;
   Attribute           attr;    Attribute           attr;
   STRING              ptr, basename;    CHAR_T              *ptr, *basename;
   int                 length;    int                 length;
   
   /* @@@ irene */    /* @@@ irene */
Line 700  Document            doc; Line 700  Document            doc;
           return NULL;            return NULL;
   basename = TtaAllocString (MAX_LENGTH);    basename = TtaAllocString (MAX_LENGTH);
   ustrncpy (basename, DocumentURLs[doc], MAX_LENGTH-1);    ustrncpy (basename, DocumentURLs[doc], MAX_LENGTH-1);
   basename[MAX_LENGTH-1] = EOS;    basename[MAX_LENGTH-1] = WC_EOS;
   length = MAX_LENGTH -1;    length = MAX_LENGTH -1;
   /* get the root element    */    /* get the root element    */
   el = TtaGetMainRoot (doc);    el = TtaGetMainRoot (doc);
Line 725  Document            doc; Line 725  Document            doc;
           TtaGiveTextAttributeValue (attr, basename, &length);            TtaGiveTextAttributeValue (attr, basename, &length);
           /* base and orgName have to be separated by a DIR_SEP */            /* base and orgName have to be separated by a DIR_SEP */
           length--;            length--;
           if (basename[0] != EOS && basename[length] != URL_SEP && basename[length] != DIR_SEP)             if (basename[0] != WC_EOS && basename[length] != WC_URL_SEP && basename[length] != WC_DIR_SEP) 
             /* verify if the base has the form "protocol://server:port" */              /* verify if the base has the form "protocol://server:port" */
             {              {
               ptr = AmayaParseUrl (basename, _EMPTYSTR_, AMAYA_PARSE_ACCESS |                ptr = AmayaParseUrl (basename, TEXT(""), AMAYA_PARSE_ACCESS |
                                                  AMAYA_PARSE_HOST |                                                   AMAYA_PARSE_HOST |
                                                  AMAYA_PARSE_PUNCTUATION);                                                   AMAYA_PARSE_PUNCTUATION);
               if (ptr && !ustrcmp (ptr, basename))                if (ptr && !ustrcmp (ptr, basename))
                 {                  {
                   /* it has this form, we complete it by adding a URL_STR  */                    /* it has this form, we complete it by adding a URL_STR  */
                   if (ustrchr (basename, DIR_SEP))                    if (ustrchr (basename, WC_DIR_SEP))
                     ustrcat (basename, DIR_STR);                      ustrcat (basename, WC_DIR_STR);
                   else                    else
                     ustrcat (basename, URL_STR);                      ustrcat (basename, WC_URL_STR);
                   length++;                    length++;
                 }                  }
               if (ptr)                if (ptr)
Line 753  Document            doc; Line 753  Document            doc;
    */     */
   length = ustrlen (basename) - 1;    length = ustrlen (basename) - 1;
   /* search for the last DIR_SEP char */    /* search for the last DIR_SEP char */
   while (length >= 0  && basename[length] != URL_SEP && basename[length] != DIR_SEP)    while (length >= 0  && basename[length] != WC_URL_SEP && basename[length] != WC_DIR_SEP)
     length--;      length--;
   if (length >= 0)    if (length >= 0)
     /* found the last DIR_SEP char, end the string there */      /* found the last DIR_SEP char, end the string there */
     basename[length + 1] = EOS;                  basename[length + 1] = WC_EOS;                 
   else    else
     /* search for the first PATH_STR char */      /* search for the first PATH_STR char */
     {      {
       for (length = 0; basename[length] != TEXT(':') &&         for (length = 0; basename[length] != TEXT(':') && 
              basename[length] != EOS; length ++);               basename[length] != WC_EOS; length ++);
       if (basename[length] == TEXT(':'))        if (basename[length] == TEXT(':'))
         /* found, so end the string there */          /* found, so end the string there */
         basename[length + 1] = EOS;          basename[length + 1] = WC_EOS;
       else        else
         /* not found, discard the base */          /* not found, discard the base */
         basename[0] = EOS;          basename[0] = WC_EOS;
     }      }
   return (basename);    return (basename);
 }  }
Line 779  Document            doc; Line 779  Document            doc;
    Allocate and return the local document path associated to the url     Allocate and return the local document path associated to the url
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 CharUnit*  GetLocalPath (Document doc, CharUnit* url)  CHAR_T*    GetLocalPath (Document doc, CHAR_T* url)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 CharUnit*  GetLocalPath (doc, url)  CHAR_T*    GetLocalPath (doc, url)
 Document   doc;  Document   doc;
 CharUnit*  url;  CHAR_T*    url;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   CharUnit* ptr;    CHAR_T*   ptr;
   CharUnit* n;    CHAR_T*   n;
   CharUnit* documentname;    CHAR_T*   documentname;
   CharUnit  url_sep;    CHAR_T    url_sep;
   int       len;    int       len;
   ThotBool  noFile;    ThotBool  noFile;
   
   if (url != NULL)    if (url != NULL)
     {      {
       /* check whether the file name exists */        /* check whether the file name exists */
       len = StringLength (url) - 1;        len = ustrlen (url) - 1;
       if (IsW3Path (url))        if (IsW3Path (url))
          url_sep = CUSTEXT('/');           url_sep = TEXT('/');
       else         else 
           url_sep = CUS_DIR_SEP;            url_sep = WC_DIR_SEP;
       noFile = (url[len] == url_sep);        noFile = (url[len] == url_sep);
       if (noFile)        if (noFile)
          url[len] = CUS_EOS;           url[len] = WC_EOS;
       ptr = TtaAllocCUString (MAX_LENGTH);        ptr = TtaAllocString (MAX_LENGTH);
       documentname = TtaAllocCUString (MAX_LENGTH);        documentname = TtaAllocString (MAX_LENGTH);
       TtaExtractName (url, ptr, documentname);        TtaExtractName (url, ptr, documentname);
       cus_sprintf (ptr, CUSTEXT("%s%s%d%s"), TempFileDirectory, CUS_DIR_STR, doc, CUS_DIR_STR);        usprintf (ptr, TEXT("%s%s%d%s"), TempFileDirectory, WC_DIR_STR, doc, WC_DIR_STR);
       if (!TtaCheckDirectory (ptr))        if (!TtaCheckDirectory (ptr))
         /* directory did not exist */          /* directory did not exist */
         TtaMakeDirectory (ptr);          TtaMakeDirectory (ptr);
   
       /* don't include the query string within document name */        /* don't include the query string within document name */
       n = StrRChr (documentname, CUSTEXT('?'));        n = ustrrchr (documentname, TEXT('?'));
       if (n != NULL)        if (n != NULL)
          *n = CUS_EOS;           *n = WC_EOS;
       /* don't include ':' within document name */        /* don't include ':' within document name */
       n = StrChr (documentname, CUSTEXT(':'));        n = ustrchr (documentname, TEXT(':'));
       if (n != NULL)        if (n != NULL)
          *n = CUS_EOS;           *n = WC_EOS;
       /* if after all this operations document name        /* if after all this operations document name
          is empty, let's use noname.html instead */           is empty, let's use noname.html instead */
       if (documentname[0] == CUS_EOS)        if (documentname[0] == WC_EOS)
          StringConcat (ptr, CUSTEXT("noname.html"));           ustrcat (ptr, TEXT("noname.html"));
       else        else
           StringConcat (ptr, documentname);            ustrcat (ptr, documentname);
       TtaFreeMemory (documentname);        TtaFreeMemory (documentname);
       /* restore the url */        /* restore the url */
       if (noFile)        if (noFile)
Line 840  CharUnit*  url; Line 840  CharUnit*  url;
    ExtractTarget extract the target name from document nane.             ExtractTarget extract the target name from document nane.        
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 void         ExtractTarget (CharUnit* aName, CharUnit* target)  void         ExtractTarget (CHAR_T* aName, CHAR_T* target)
 #else  #else
 void         ExtractTarget (aName, target)  void         ExtractTarget (aName, target)
 CharUnit*    aName;  CHAR_T*      aName;
 CharUnit*    target;  CHAR_T*      target;
 #endif  #endif
 {  {
    int       lg, i;     int       lg, i;
    CharUnit* ptr;     CHAR_T*   ptr;
    CharUnit* oldptr;     CHAR_T*   oldptr;
   
    if (!target || !aName)     if (!target || !aName)
      /* bad target */       /* bad target */
      return;       return;
   
    target[0] = CUS_EOS;     target[0] = WC_EOS;
    lg = StringLength (aName);     lg = ustrlen (aName);
    if (lg)     if (lg)
      {       {
         /* the name is not empty */          /* the name is not empty */
         oldptr = ptr = &aName[0];          oldptr = ptr = &aName[0];
         do          do
           {            {
              ptr = StrRChr (oldptr, CUSTEXT('#'));               ptr = ustrrchr (oldptr, TEXT('#'));
              if (ptr)               if (ptr)
                 oldptr = &ptr[1];                  oldptr = &ptr[1];
           }            }
Line 872  CharUnit*    target; Line 872  CharUnit*    target;
         i = (int) (oldptr) - (int) (aName);     /* name length */          i = (int) (oldptr) - (int) (aName);     /* name length */
         if (i > 1)          if (i > 1)
           {            {
              aName[i - 1] = CUS_EOS;               aName[i - 1] = WC_EOS;
              if (i != lg)               if (i != lg)
                 StringCopy (target, oldptr);                  ustrcpy (target, oldptr);
           }            }
      }       }
 }  }
Line 885  CharUnit*    target; Line 885  CharUnit*    target;
    can use it as a local filename     can use it as a local filename
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 void ConvertFileURL (CharUnit* url)  void ConvertFileURL (CHAR_T* url)
 #else  #else
 void ConvertFileURL (url)  void ConvertFileURL (url)
 CharUnit* url  CHAR_T* url
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   if (!StringNCaseCompare (url, CUSTEXT("file:"), 5))    if (!ustrncasecmp (url, TEXT("file:"), 5))
      StringCopy (url, url + 5);       ustrcpy (url, url + 5);
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 907  CharUnit* url Line 907  CharUnit* url
    the name "noname.html".     the name "noname.html".
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 void                NormalizeURL (CharUnit* orgName, Document doc, CharUnit* newName, CharUnit* docName, CharUnit* otherPath)  void                NormalizeURL (CHAR_T* orgName, Document doc, CHAR_T* newName, CHAR_T* docName, CHAR_T* otherPath)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 void                NormalizeURL (orgName, doc, newName, docName, otherPath)  void                NormalizeURL (orgName, doc, newName, docName, otherPath)
 CharUnit*           orgName;  CHAR_T*             orgName;
 Document            doc;  Document            doc;
 CharUnit*           newName;  CHAR_T*             newName;
 CharUnit*           docName;  CHAR_T*             docName;
 CharUnit*           otherPath;  CHAR_T*             otherPath;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    CharUnit*        basename;     CHAR_T*        basename;
    CharUnit         tempOrgName[MAX_LENGTH];     CHAR_T         tempOrgName[MAX_LENGTH];
    CharUnit*        ptr;     CHAR_T*        ptr;
    CharUnit         used_sep;     CHAR_T         used_sep;
    int              length;     int            length;
    ThotBool         check;     ThotBool       check;
   
 #  ifdef _WINDOWS  #  ifdef _WINDOWS
    int ndx;     int ndx;
Line 934  CharUnit*           otherPath; Line 934  CharUnit*           otherPath;
    if (doc != 0)     if (doc != 0)
      basename = GetBaseURL (doc);       basename = GetBaseURL (doc);
    else if (otherPath != NULL)     else if (otherPath != NULL)
      basename = StringDuplicate (otherPath);       basename = TtaWCSdup (otherPath);
    else     else
      basename = NULL;       basename = NULL;
   
Line 945  CharUnit*           otherPath; Line 945  CharUnit*           otherPath;
     */      */
    ptr = orgName;     ptr = orgName;
    /* skip leading white space and new line characters */     /* skip leading white space and new line characters */
    while ((*ptr == CUS_SPACE || *ptr == CUS_EOL) && *ptr++ != CUS_EOS);     while ((*ptr == WC_SPACE || *ptr == WC_EOL) && *ptr++ != WC_EOS);
    StringNCopy (tempOrgName, ptr, MAX_LENGTH -1);     ustrncpy (tempOrgName, ptr, MAX_LENGTH -1);
    tempOrgName[MAX_LENGTH -1] = CUS_EOS;     tempOrgName[MAX_LENGTH -1] = WC_EOS;
    /*     /*
     * Make orgName a complete URL      * Make orgName a complete URL
     * If the URL does not include a protocol, then try to calculate      * If the URL does not include a protocol, then try to calculate
     * one using the doc's base element (if it exists),      * one using the doc's base element (if it exists),
     */      */
    if (tempOrgName[0] == CUS_EOS)     if (tempOrgName[0] == WC_EOS)
      {       {
        newName[0] = CUS_EOS;         newName[0] = WC_EOS;
        TtaFreeMemory (basename);         TtaFreeMemory (basename);
        return;         return;
      }       }
   
    /* clean trailing white space */     /* clean trailing white space */
    length = StringLength (tempOrgName) - 1;     length = ustrlen (tempOrgName) - 1;
    while (tempOrgName[length] == CUS_SPACE && tempOrgName[length] == CUS_EOL)     while (tempOrgName[length] == WC_SPACE && tempOrgName[length] == WC_EOL)
      {       {
        tempOrgName[length] = CUS_EOS;         tempOrgName[length] = WC_EOS;
        length--;         length--;
      }       }
   
    /* remove extra dot (which dot???) */     /* remove extra dot (which dot???) */
    /* ugly, but faster than a strcmp */     /* ugly, but faster than a strcmp */
    if (tempOrgName[length] == CUSTEXT('.')     if (tempOrgName[length] == TEXT('.')
        && (length == 0 || tempOrgName[length-1] != CUSTEXT('.')))         && (length == 0 || tempOrgName[length-1] != TEXT('.')))
          tempOrgName[length] = CUS_EOS;           tempOrgName[length] = WC_EOS;
   
    if (IsW3Path (tempOrgName))     if (IsW3Path (tempOrgName))
      {       {
        /* the name is complete, go to the Sixth Step */         /* the name is complete, go to the Sixth Step */
        StringCopy (newName, tempOrgName);         ustrcpy (newName, tempOrgName);
        SimplifyUrl (&newName);         SimplifyUrl (&newName);
        /* verify if the URL has the form "protocol://server:port" */         /* verify if the URL has the form "protocol://server:port" */
        ptr = AmayaParseUrl (newName, _EMPTYSTR_, AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);         ptr = AmayaParseUrl (newName, TEXT(""), AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
        if (ptr && !StringCompare (ptr, newName)) /* it has this form, we complete it by adding a DIR_STR  */         if (ptr && !ustrcmp (ptr, newName)) /* it has this form, we complete it by adding a DIR_STR  */
          StringConcat (newName, CUS_URL_STR);           ustrcat (newName, WC_URL_STR);
   
        if (ptr)         if (ptr)
          TtaFreeMemory (ptr);           TtaFreeMemory (ptr);
      }       }
    else if ( basename == NULL)     else if ( basename == NULL)
      /* the name is complete, go to the Sixth Step */       /* the name is complete, go to the Sixth Step */
      StringCopy (newName, tempOrgName);       ustrcpy (newName, tempOrgName);
    else     else
      {       {
        /* Calculate the absolute URL, using the base or document URL */         /* Calculate the absolute URL, using the base or document URL */
Line 1006  CharUnit*           otherPath; Line 1006  CharUnit*           otherPath;
        if (ptr)         if (ptr)
          {           {
            SimplifyUrl (&ptr);             SimplifyUrl (&ptr);
            StringCopy (newName, ptr);             ustrcpy (newName, ptr);
            TtaFreeMemory (ptr);             TtaFreeMemory (ptr);
          }           }
        else         else
          newName[0] = CUS_EOS;           newName[0] = WC_EOS;
      }       }
   
    TtaFreeMemory (basename);     TtaFreeMemory (basename);
Line 1019  CharUnit*           otherPath; Line 1019  CharUnit*           otherPath;
     * .amaya directory. If the new URL finishes on DIR_SEP, then use      * .amaya directory. If the new URL finishes on DIR_SEP, then use
     * noname.html as a default ressource name      * noname.html as a default ressource name
    */     */
    if (newName[0] != CUS_EOS)     if (newName[0] != WC_EOS)
      {       {
        length = StringLength (newName) - 1;         length = ustrlen (newName) - 1;
        if (newName[length] == CUS_URL_SEP || newName[length] == CUS_DIR_SEP)         if (newName[length] == WC_URL_SEP || newName[length] == WC_DIR_SEP)
          {           {
            used_sep = newName[length];             used_sep = newName[length];
            check = TRUE;             check = TRUE;
Line 1031  CharUnit*           otherPath; Line 1031  CharUnit*           otherPath;
                length--;                 length--;
                while (length >= 0 && newName[length] != used_sep)                 while (length >= 0 && newName[length] != used_sep)
                  length--;                   length--;
                if (!StringNCompare (&newName[length+1], CUSTEXT(".."), 2))                 if (!ustrncmp (&newName[length+1], TEXT(".."), 2))
                  {                   {
                    newName[length+1] = CUS_EOS;                     newName[length+1] = WC_EOS;
                    /* remove also previous directory */                     /* remove also previous directory */
                    length--;                     length--;
                    while (length >= 0 && newName[length] != used_sep)                     while (length >= 0 && newName[length] != used_sep)
                      length--;                       length--;
                    if (StringNCompare (&newName[length+1], CUSTEXT("//"), 2))                     if (ustrncmp (&newName[length+1], TEXT("//"), 2))
                      /* don't remove server name */                       /* don't remove server name */
                      newName[length+1] = CUS_EOS;                       newName[length+1] = WC_EOS;
                  }                   }
                else if (!StringNCompare (&newName[length+1], CUSTEXT("."), 1))                 else if (!ustrncmp (&newName[length+1], TEXT("."), 1))
                  newName[length+1] = CUS_EOS;                   newName[length+1] = WC_EOS;
                else                 else
                  check = FALSE;                   check = FALSE;
              }               }
            StringCopy (docName, CUSTEXT("noname.html"));                            ustrcpy (docName, TEXT("noname.html"));             
            /* docname was not comprised inside the URL, so let's */             /* docname was not comprised inside the URL, so let's */
            /* assign the default ressource name */             /* assign the default ressource name */
            StringCopy (docName, CUSTEXT("noname.html"));             ustrcpy (docName, TEXT("noname.html"));
          }           }
        else         else
          { /* docname is comprised inside the URL */           { /* docname is comprised inside the URL */
            while (length >= 0 && newName[length] != CUS_URL_SEP && newName[length] != CUS_DIR_SEP)             while (length >= 0 && newName[length] != WC_URL_SEP && newName[length] != WC_DIR_SEP)
              length--;               length--;
            if (length < 0)             if (length < 0)
              StringCopy (docName, newName);               ustrcpy (docName, newName);
            else             else
              StringCopy (docName, &newName[length+1]);               ustrcpy (docName, &newName[length+1]);
          }           }
      }       }
    else     else
      docName[0] = CUS_EOS;       docName[0] = WC_EOS;
 }   } 
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 1080  const STRING       url2; Line 1080  const STRING       url2;
    STRING           basename_ptr1, basename_ptr2;     STRING           basename_ptr1, basename_ptr2;
    ThotBool          result;     ThotBool          result;
   
    basename_ptr1 = AmayaParseUrl (url1, _EMPTYSTR_, AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);     basename_ptr1 = AmayaParseUrl (url1, TEXT(""), AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
    basename_ptr2 = AmayaParseUrl (url2, _EMPTYSTR_, AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);     basename_ptr2 = AmayaParseUrl (url2, _EMPTYSTR_, AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
   
    if (ustrcmp (basename_ptr1, basename_ptr2))     if (ustrcmp (basename_ptr1, basename_ptr2))
Line 1112  const STRING    path; Line 1112  const STRING    path;
    if (!path || path[0] == EOS || path[ustrlen(path)] == DIR_SEP)     if (!path || path[0] == EOS || path[ustrlen(path)] == DIR_SEP)
      return (FALSE);       return (FALSE);
   
    root = AmayaParseUrl(path, _EMPTYSTR_, AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);     root = AmayaParseUrl(path, TEXT(""), AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
   
    if (root)      if (root) 
      {       {
Line 1303  HTURI       *parts; Line 1303  HTURI       *parts;
         returns         A pointer to a malloc'd string which MUST BE FREED          returns         A pointer to a malloc'd string which MUST BE FREED
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 STRING        AmayaParseUrl (const STRING aName, STRING relatedName, int wanted)  CHAR_T*        AmayaParseUrl (const CHAR_T* aName, CHAR_T* relatedName, int wanted)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 STRING        AmayaParseUrl (aName, relatedName, wanted)  CHAR_T*        AmayaParseUrl (aName, relatedName, wanted)
 const STRING  aName;  const CHAR_T*  aName;
 STRING        relatedName;  CHAR_T*        relatedName;
 int            wanted;  int            wanted;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   STRING     return_value;    CHAR_T*    return_value;
   CHAR_T     result[MAX_LENGTH];    CHAR_T     result[MAX_LENGTH];
   CHAR_T     name[MAX_LENGTH];    CHAR_T     name[MAX_LENGTH];
   CHAR_T     rel[MAX_LENGTH];    CHAR_T     rel[MAX_LENGTH];
   STRING     p, access;    CHAR_T     *p, *access;
   HTURI      given, related;    HTURI      given, related;
   int        len;    int        len;
   CHAR_T     used_sep;    CHAR_T     used_sep;
   STRING     used_str;    CHAR_T*    used_str;
   
   if (ustrchr (aName, DIR_SEP) || ustrchr (relatedName, DIR_SEP))    if (ustrchr (aName, WC_DIR_SEP) || ustrchr (relatedName, WC_DIR_SEP))
     {      {
       used_str = DIR_STR;        used_str = WC_DIR_STR;
       used_sep = DIR_SEP;        used_sep = WC_DIR_SEP;
     }      }
   else    else
     {      {
       used_str = URL_STR;        used_str = WC_URL_STR;
       used_sep = URL_SEP;        used_sep = WC_URL_SEP;
     }      }
   
   /* Make working copies of input strings to cut up: */    /* Make working copies of input strings to cut up: */
Line 1340  int            wanted; Line 1340  int            wanted;
   if (relatedName != NULL)      if (relatedName != NULL)  
     ustrcpy (rel, relatedName);      ustrcpy (rel, relatedName);
   else    else
     relatedName[0] = EOS;      relatedName[0] = WC_EOS;
       
   scan (name, &given);    scan (name, &given);
   scan (rel,  &related);     scan (rel,  &related); 
Line 1428  int            wanted; Line 1428  int            wanted;
             ustrcat (result, given.fragment);               ustrcat (result, given.fragment); 
           }            }
         else if (!(given.absolute) && !(given.fragment))          else if (!(given.absolute) && !(given.fragment))
           ustrcat (result, _EMPTYSTR_);            ustrcat (result, TEXT(""));
         else          else
           {            {
             if (wanted & AMAYA_PARSE_PUNCTUATION)              if (wanted & AMAYA_PARSE_PUNCTUATION)
Line 1455  int            wanted; Line 1455  int            wanted;
       
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 static CharUnit* HTCanon (CharUnit** filename, CharUnit* host)  static CHAR_T* HTCanon (CHAR_T** filename, CHAR_T* host)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 static STRING HTCanon (filename, host)  static STRING HTCanon (filename, host)
 CharUnit** filename;  CHAR_T** filename;
 CharUnit*  host;  CHAR_T*  host;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
     CharUnit* newname = NULL;      CHAR_T* newname = NULL;
     CharUnit  used_sep;      CHAR_T  used_sep;
     CharUnit* path;      CHAR_T* path;
     CharUnit* strptr;      CHAR_T* strptr;
     CharUnit* port;      CHAR_T* port;
     CharUnit* access = host-3;      CHAR_T* access = host-3;
   
       
      if (*filename && StrChr (*filename, CUS_URL_SEP))       if (*filename && ustrchr (*filename, WC_URL_SEP))
        {         {
          used_sep = CUS_URL_SEP;           used_sep = WC_URL_SEP;
        }         }
      else       else
        {         {
          used_sep = CUS_DIR_SEP;           used_sep = WC_DIR_SEP;
        }         }
       
     while (access > *filename && *(access - 1) != used_sep)       /* Find access method */      while (access > *filename && *(access - 1) != used_sep)       /* Find access method */
         access--;          access--;
     if ((path = StrChr (host, used_sep)) == NULL)                       /* Find path */      if ((path = ustrchr (host, used_sep)) == NULL)                      /* Find path */
        path = host + StringLength (host);         path = host + ustrlen (host);
     if ((strptr = StrChr (host, CUSTEXT('@'))) != NULL && strptr < path)           /* UserId */      if ((strptr = ustrchr (host, TEXT('@'))) != NULL && strptr < path)     /* UserId */
        host = strptr;         host = strptr;
     if ((port = StrChr (host, CUSTEXT(':'))) != NULL && port > path)      /* Port number */      if ((port = ustrchr (host, TEXT(':'))) != NULL && port > path)      /* Port number */
        port = NULL;         port = NULL;
   
     strptr = host;                                  /* Convert to lower-case */      strptr = host;                                  /* Convert to lower-case */
     while (strptr < path)      while (strptr < path)
       {        {
          *strptr = ToLower (*strptr);           *strptr = utolower (*strptr);
          strptr++;           strptr++;
       }        }
           
Line 1499  CharUnit*  host; Line 1499  CharUnit*  host;
        numerical host name. The domain name is already made lower-case         numerical host name. The domain name is already made lower-case
        and without a trailing dot. */         and without a trailing dot. */
     {      {
       CharUnit* dot = port ? port : path;        CHAR_T* dot = port ? port : path;
       if (dot > *filename && *--dot == CUSTEXT('.'))        if (dot > *filename && *--dot == TEXT('.'))
         {          {
           CharUnit* orig = dot;            CHAR_T* orig = dot;
       CharUnit* dest = dot + 1;        CHAR_T* dest = dot + 1;
           while ((*orig++ = *dest++));            while ((*orig++ = *dest++));
             if (port) port--;              if (port) port--;
           path--;            path--;
Line 1516  CharUnit*  host; Line 1516  CharUnit*  host;
           {            {
             if (!newname)              if (!newname)
               {                {
                 CharUnit* orig = port;                   CHAR_T* orig = port; 
         CharUnit* dest = port + 1;          CHAR_T* dest = port + 1;
                 while ((*orig++ = *dest++));                  while ((*orig++ = *dest++));
               }                }
           }            }
         else if ((!StringNCompare (access, CUSTEXT("http"), 4)   &&          else if ((!ustrncmp (access, TEXT("http"), 4)   &&
              (*(port + 1) == CUSTEXT('8')                    &&                (*(port + 1) == TEXT('8')                    && 
              *(port+2) == CUSTEXT('0')                       &&                *(port+2) == TEXT('0')                       && 
              (*(port+3) == used_sep || !*(port + 3))))       ||               (*(port+3) == used_sep || !*(port + 3))))       ||
              (!StringNCompare (access, CUSTEXT("gopher"), 6) &&               (!ustrncmp (access, TEXT("gopher"), 6) &&
              (*(port+1) == CUSTEXT('7')                      &&                (*(port+1) == TEXT('7')                      && 
              *(port+2) == CUSTEXT('0')                       &&                *(port+2) == TEXT('0')                       && 
              (*(port+3) == used_sep || !*(port+3))))         ||               (*(port+3) == used_sep || !*(port+3))))         ||
              (!StringNCompare (access, CUSTEXT("ftp"), 3)    &&               (!ustrncmp (access, TEXT("ftp"), 3)    &&
              (*(port+1) == CUSTEXT('2')                      &&                (*(port+1) == TEXT('2')                      && 
              *(port + 2) == CUSTEXT('1')                     &&                *(port + 2) == TEXT('1')                     && 
              (*(port+3) == used_sep || !*(port+3))))) {               (*(port+3) == used_sep || !*(port+3))))) {
           if (!newname)            if (!newname)
             {              {
               CharUnit* orig = port;                 CHAR_T* orig = port; 
           CharUnit* dest = port + 3;            CHAR_T* dest = port + 3;
               while((*orig++ = *dest++));                while((*orig++ = *dest++));
               /* Update path position, Henry Minsky */                /* Update path position, Henry Minsky */
               path -= 3;                path -= 3;
             }              }
         }          }
         else if (newname)          else if (newname)
           StringNConcat (newname, port, (int) (path - port));            ustrncat (newname, port, (int) (path - port));
       }        }
   
     if (newname)      if (newname)
       {        {
         CharUnit* newpath = newname + StringLength (newname);          CHAR_T* newpath = newname + ustrlen (newname);
         StringConcat (newname, path);          ustrcat (newname, path);
         path = newpath;          path = newpath;
         /* Free old copy */          /* Free old copy */
         TtaFreeMemory(*filename);          TtaFreeMemory(*filename);
Line 1585  CharUnit*  host; Line 1585  CharUnit*  host;
   Returns: A string which might be the old one or a new one.    Returns: A string which might be the old one or a new one.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 void         SimplifyUrl (CharUnit** url)  void         SimplifyUrl (CHAR_T** url)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 void         SimplifyUrl (url)  void         SimplifyUrl (url)
 CharUnit**   url;  CHAR_T**     url;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   CharUnit* path;    CHAR_T*   path;
   CharUnit* access;    CHAR_T*   access;
   CharUnit* newptr;     CHAR_T*   newptr; 
   STRING    p;    CHAR_T*   p;
   STRING    orig, dest, end;    CHAR_T   *orig, *dest, *end;
   
   CharUnit used_sep;    CharUnit used_sep;
   ThotBool ddot_simplify; /* used to desactivate the double dot simplifcation:    ThotBool ddot_simplify; /* used to desactivate the double dot simplifcation:
Line 1605  CharUnit**   url; Line 1605  CharUnit**   url;
   if (!url || !*url)    if (!url || !*url)
     return;      return;
   
   if (StrChr (*url, CUS_URL_SEP))    if (ustrchr (*url, WC_URL_SEP))
     {      {
       used_sep = CUS_URL_SEP;        used_sep = WC_URL_SEP;
     }      }
   else    else
     {      {
       used_sep = CUS_DIR_SEP;        used_sep = WC_DIR_SEP;
     }      }
   
   /* should we simplify double dot? */    /* should we simplify double dot? */
   path = *url;    path = *url;
   if (*path == CUSTEXT('.') && *(path + 1) == CUSTEXT('.'))    if (*path == TEXT('.') && *(path + 1) == TEXT('.'))
     ddot_simplify = FALSE;      ddot_simplify = FALSE;
   else    else
     ddot_simplify = TRUE;      ddot_simplify = TRUE;
   
   /* Find any scheme name */    /* Find any scheme name */
   if ((path = StringSubstring(*url, CUSTEXT("://"))) != NULL)    if ((path = ustrstr (*url, TEXT("://"))) != NULL)
     {      {
       /* Find host name */        /* Find host name */
       access = *url;        access = *url;
       while (access < path && (*access = ToLower (*access)))        while (access < path && (*access = utolower (*access)))
             access++;              access++;
       path += 3;        path += 3;
       while ((newptr = StringSubstring (path, CUSTEXT ("://"))) != NULL)        while ((newptr = ustrstr (path, TEXT ("://"))) != NULL)
             /* For proxies */              /* For proxies */
             path = newptr+3;              path = newptr+3;
      /* We have a host name */       /* We have a host name */
       path = HTCanon(url, path);        path = HTCanon (url, path);
     }      }
   else if ((path = ustrstr(*url, TEXT(":/"))) != NULL)    else if ((path = ustrstr (*url, TEXT(":/"))) != NULL)
     path += 2;      path += 2;
   else    else
     path = *url;      path = *url;
   
   if (*path == used_sep && *(path+1)==used_sep)    if (*path == used_sep && *(path+1) == used_sep)
     /* Some URLs start //<foo> */      /* Some URLs start //<foo> */
     path += 1;      path += 1;
   else if (!ustrncmp(path, TEXT("news:"), 5))    else if (!ustrncmp (path, TEXT("news:"), 5))
     {      {
       newptr = ustrchr(path+5, TEXT('@'));        newptr = ustrchr (path+5, TEXT('@'));
       if (!newptr)        if (!newptr)
         newptr = path + 5;          newptr = path + 5;
       while (*newptr)        while (*newptr)
         {          {
           /* Make group or host lower case */            /* Make group or host lower case */
           *newptr = tolower (*newptr);            *newptr = utolower (*newptr);
           newptr++;            newptr++;
         }          }
       /* Doesn't need to do any more */        /* Doesn't need to do any more */
Line 1677  CharUnit**   url; Line 1677  CharUnit**   url;
               if (p > *url && *(p+1) == TEXT('.') && (*(p+2) == used_sep || !*(p+2)))                if (p > *url && *(p+1) == TEXT('.') && (*(p+2) == used_sep || !*(p+2)))
                 {                  {
                   orig = p + 1;                    orig = p + 1;
                   dest = (*(p+2)!=used_sep) ? p+2 : p+3;                    dest = (*(p+2) != used_sep) ? p+2 : p+3;
                   while ((*orig++ = *dest++)); /* Remove a used_sep and a dot*/                    while ((*orig++ = *dest++)); /* Remove a used_sep and a dot*/
                   end = orig - 1;                    end = orig - 1;
                 }                  }
Line 1731  CharUnit**   url; Line 1731  CharUnit**   url;
    Return TRUE if target and src differ.                                Return TRUE if target and src differ.                           
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 ThotBool             NormalizeFile (CharUnit* src, CharUnit* target)  ThotBool             NormalizeFile (CHAR_T* src, CHAR_T* target)
 #else  #else
 ThotBool             NormalizeFile (src, target)  ThotBool             NormalizeFile (src, target)
 CharUnit*            src;  CHAR_T*              src;
 CharUnit*            target;  CHAR_T*              target;
   
 #endif  #endif
 {  {
    CharUnit*         s;     CHAR_T*           s;
    ThotBool          change;     ThotBool          change;
   
    change = FALSE;     change = FALSE;
    if (StringNCompare (src, CUSTEXT("file:"), 5) == 0)     if (ustrncmp (src, TEXT("file:"), 5) == 0)
      {       {
         /* remove the prefix file: */          /* remove the prefix file: */
         if (src[5] == CUS_EOS)          if (src[5] == WC_EOS)
            StringCopy (target, CUS_DIR_STR);             ustrcpy (target, WC_DIR_STR);
         else if (src[0] == CUSTEXT('~'))          else if (src[0] == TEXT('~'))
           {            {
             /* replace ~ */              /* replace ~ */
             s = TtaGetEnvString ("HOME");              s = TtaGetEnvString ("HOME");
             StringCopy (target, s);              ustrcpy (target, s);
             StringConcat (target, &src[5]);              ustrcat (target, &src[5]);
           }            }
         else          else
            StringCopy (target, &src[5]);             ustrcpy (target, &src[5]);
         change = TRUE;          change = TRUE;
      }       }
 #  ifndef _WINDOWS  #  ifndef _WINDOWS
    else if (src[0] == CUSTEXT('~'))     else if (src[0] == TEXT('~'))
      {       {
         /* replace ~ */          /* replace ~ */
         s = TtaGetEnvString ("HOME");          s = TtaGetEnvString ("HOME");
         StringCopy (target, s);          ustrcpy (target, s);
         if (src[1] != CUS_DIR_SEP)          if (src[1] != WC_DIR_SEP)
           strcat (target, CUS_DIR_STR);            ustrcat (target, WC_DIR_STR);
         StringConcat (target, &src[1]);          ustrcat (target, &src[1]);
         change = TRUE;          change = TRUE;
      }       }
 #   endif /* _WINDOWS */  #   endif /* _WINDOWS */
    else     else
       StringCopy (target, src);        ustrcpy (target, src);
   
    /* remove /../ and /./ */     /* remove /../ and /./ */
    SimplifyUrl (&target);     SimplifyUrl (&target);
    if (!change)     if (!change)
      change = StringCompare (src, target);       change = ustrcmp (src, target);
    return (change);     return (change);
 }  }
   

Removed from v.1.83  
changed lines
  Added in v.1.84


Webmaster