home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / INTERNET / WWW / LYNX / SOURCE / SRC0_8A.ZIP / DOSLYNX / SRC / URLTODOS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  3.2 KB  |  122 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        none
  4. //    Include File:    urltodos.h
  5. //    Purpose:    convert a url path to a dos path
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        01-18-94    created
  9. #include"urltodos.h"
  10. #include"trace.h"
  11. #include<string.h>
  12.  
  13. extern "C" void urltodos(char *cp_url)    {
  14. //    Purpose:    convert a url to a dos path
  15. //    Arguments:    cp_url    the url to convert
  16. //    Return Value:    void
  17. //    Remarks/Portability/Dependencies/Restrictions:
  18. //        Will overwrite the cp_url memory in order to provide the new
  19. //            path.
  20. //        Does not actually take a complete url, only the part passed
  21. //            in by a routine in htfile.c
  22. //    Revision History:
  23. //        01-18-94    created
  24.  
  25.     //    Allocate space for the new name.
  26.     //    Remember the address of the original url
  27.     char *cp_newurl = new char[strlen(cp_url) + 1];
  28.     char *cp_oldurl = cp_url;
  29.  
  30.     //    Skip the always leading '/'
  31.     cp_url++;
  32.  
  33.     //    Next comes the drive letter.
  34.     *cp_newurl = *cp_url;
  35.     cp_url++;
  36.  
  37.     //    If the last character was a drive letter, this will be
  38.     //    a '|', if not, the rest must be a file name.
  39.     if(*cp_url == '|')    {
  40.         *(cp_newurl + 1) = ':';
  41.     }
  42.     else    {
  43.         //    Just copy over another character.
  44.         *(cp_newurl + 1) = *cp_url;
  45.     }
  46.  
  47.     //    Move past the '|'
  48.     cp_url++;
  49.  
  50.     //    Copy the rest of the string over.
  51.     strcpy(cp_newurl + 2, cp_url);
  52.  
  53.     //    Loop through the string, converting all '/' to '\\'
  54.     for(cp_url = cp_newurl; *cp_url != '\0'; cp_url++)    {
  55.         if(*cp_url == '/')    {
  56.             *cp_url = '\\';
  57.         }
  58.     }
  59.  
  60.     //    Done, copy back over the new url, and release our memory.
  61. #ifndef RELEASE
  62.     trace("Converted " << cp_oldurl << " to " << cp_newurl);
  63. #endif // RELEASE
  64.     strcpy(cp_oldurl, cp_newurl);
  65.     delete[](cp_newurl);
  66.  
  67.     //    Convert to lower case.
  68.     strlwr(cp_oldurl);
  69. }
  70.  
  71. extern void dostourl(char *cp_dest, const char *cp_dospath)    {
  72. //    Purpose:    convert a dos path to a url
  73. //    Arguments:    cp_dest        the buffer to put the url in
  74. //            cp_dospath    the dos path to convert
  75. //    Return Value:    void
  76. //    Remarks/Portability/Dependencies/Restrictions:
  77. //        Will return a full url.  What is returned is generally
  78. //            not passable back to usltodos as the beginning
  79. //            'file://' should be stripped off before passing.
  80. //    Revision History:
  81. //        01-19-94    created
  82.  
  83.     //    Copy the leading 'file:///' into cp_dest
  84.     strcpy(cp_dest, "file:///");
  85.     //    Append the dos part.
  86.     strcat(cp_dest, cp_dospath);
  87.  
  88.     //    Go through cp_dest, changing '\\' to '/' and ':' to '|'
  89.     for(int i_traverse = 8; *(cp_dest + i_traverse) != '\0';
  90.         i_traverse++)    {
  91.         switch(*(cp_dest + i_traverse))    {
  92.         case '\\':
  93.             *(cp_dest + i_traverse) = '/';
  94.             break;
  95.         case ':':
  96.             *(cp_dest + i_traverse) = '|';
  97.             break;
  98.         }
  99.     }
  100.  
  101.     //    convert to lower case.
  102.     strlwr(cp_dest);
  103.  
  104. #ifndef RELEASE
  105.     trace("Converted " << cp_dospath << " to " << cp_dest);
  106. #endif // RELEASE
  107. }
  108.  
  109.  
  110. extern int URLisLocal(const char *cp_URL)    {
  111. //    Purpose:    Determine if a URL is local.
  112. //    Arguments:    cp_URL    the url in question
  113. //    Return Value:    int    0    is not local
  114. //                1    is local
  115. //    Remarks/Portability/Dependencies/Restrictions:
  116. //        Assuming a URL is local on dos only when "file:///" is the
  117. //            prefix of the URL.
  118. //    Revision History:
  119. //        01-19-94    created
  120.  
  121.     return((strncmp(cp_URL, "file:///", 8) == 0) ? 1 : 0);
  122. }