home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / normaliz.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  6.4 KB  |  165 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    n o r m a l i z . c                                             */
  3. /*                                                                    */
  4. /*    Normalize a path for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992 by Kendra Electronic Wonderworks; all        */
  7. /*    rights reserved except those explicitly granted by the          */
  8. /*    UUPC/extended license.                                          */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  13. /*       Wonderworks.                                                 */
  14. /*                                                                    */
  15. /*       All rights reserved except those explicitly granted by       */
  16. /*       the UUPC/extended license agreement.                         */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                          RCS Information                           */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. /*
  24.  *    $Id: normaliz.c 1.9 1993/10/12 00:46:16 ahd Exp $
  25.  *
  26.  *    Revision history:
  27.  *    $Log: normaliz.c $
  28.  *     Revision 1.9  1993/10/12  00:46:16  ahd
  29.  *     Normalize comments
  30.  *
  31.  *     Revision 1.8  1993/09/20  04:38:11  ahd
  32.  *     TCP/IP support from Dave Watt
  33.  *     't' protocol support
  34.  *     OS/2 2.x support
  35.  *
  36.  *     Revision 1.7  1993/08/08  17:39:09  ahd
  37.  *     Denormalize path for opening on selected networks
  38.  *
  39.  *     Revision 1.6  1993/07/06  10:55:20  ahd
  40.  *     Drop doubled path delimiters before calling _fullpath
  41.  *     Abort, not return NULL, if _fullpath fails
  42.  *
  43.  *     Revision 1.5  1993/06/16  04:19:31  ahd
  44.  *     Copy trailing null when copying slashes
  45.  *
  46.  *     Revision 1.4  1993/06/16  04:03:25  ahd
  47.  *     drop duplicated slashes (caused by root directory support *sigh*)
  48.  *
  49.  *     Revision 1.3  1993/06/15  12:18:06  ahd
  50.  *     Display last known directory name for debugging
  51.  *
  52.  *     Revision 1.2  1993/04/11  00:32:05  ahd
  53.  *     Global edits for year, TEXT, etc.
  54.  *
  55.  * Revision 1.1  1992/11/22  21:06:14  ahd
  56.  * Initial revision
  57.  *
  58.  */
  59.  
  60. /*--------------------------------------------------------------------*/
  61. /*                        System include files                        */
  62. /*--------------------------------------------------------------------*/
  63.  
  64. #include <stdio.h>
  65. #include <stdlib.h>
  66. #include <string.h>
  67. #include <time.h>
  68. #include <sys/types.h>
  69. #include <ctype.h>
  70.  
  71. /*--------------------------------------------------------------------*/
  72. /*                    UUPC/extended include files                     */
  73. /*--------------------------------------------------------------------*/
  74.  
  75. #include "lib.h"
  76.  
  77. currentfile();
  78.  
  79. /*--------------------------------------------------------------------*/
  80. /*    n o r m a l i z e                                               */
  81. /*                                                                    */
  82. /*    Normalize a DOS Path                                            */
  83. /*--------------------------------------------------------------------*/
  84.  
  85. char *normalize( const char *pathx )
  86. {
  87.    static char save[FILENAME_MAX];
  88.    char path[FILENAME_MAX];
  89.    int column;
  90.    char *p;
  91.  
  92. /*--------------------------------------------------------------------*/
  93. /*                      Normalize the seperators                      */
  94. /*--------------------------------------------------------------------*/
  95.  
  96.    strcpy( path, pathx );
  97.    denormalize( path );
  98.  
  99. /*--------------------------------------------------------------------*/
  100. /*                    Add leading path, if needed                     */
  101. /*--------------------------------------------------------------------*/
  102.  
  103.    if (  ( E_cwd != NULL ) &&
  104.          equaln( E_cwd, "//", 2 ) &&               /* Network CWD drive */
  105.        ! (isalpha( *path ) && (path[1] == ':')) && /* Not explicit drive */
  106.          (*path != '\\'))                          /* Not explicit path */
  107.    {
  108.       column = strlen( E_cwd );
  109.       memmove( path + column + 1, path, strlen(path) + 1 );
  110.                                           /* Make room for path       */
  111.       memcpy( path, E_cwd, column );      /* Insert path              */
  112.       path[column] = '\\';                /* Add directory sep        */
  113.    }
  114.  
  115.    p = path + 1;                 /* Allow leading double slash for    */
  116.                                  /* Network drives                    */
  117.  
  118.    while ((p = strstr(p,"\\\\")) != NULL)  /* Drop all double slashes */
  119.       memmove(p, p+1, strlen(p));          /* Includes trailing NULL  */
  120.  
  121. /*--------------------------------------------------------------------*/
  122. /*           Drop trailing slashes, OS/2 doesn't like them            */
  123. /*--------------------------------------------------------------------*/
  124.  
  125.    column = strlen( path ) - 1;
  126.    if ( (column > 2) && (path[column] == '\\') )
  127.       path[column] = '\0';
  128.  
  129. /*--------------------------------------------------------------------*/
  130. /*                    Now actually expand the path                    */
  131. /*--------------------------------------------------------------------*/
  132.  
  133.    p = _fullpath( save, path, sizeof save );
  134.  
  135.    if ( p == NULL )
  136.    {
  137.       printerr( path );
  138.       panic();
  139.    }
  140.  
  141.    while ((p = strchr(p,'\\')) != NULL)   /* Back slashes to slashes  */
  142.       *p++ = '/';
  143.  
  144.    if ( equaln( save + 1, "://", 3))
  145.       p = save + 2;                       /* Drop drive if really network */
  146.    else
  147.       p = save;                           /* Else use as-is           */
  148.  
  149.    column = strlen( p ) - 1;
  150.    if ((column > 2) && ( p[column] == '/' )) /* Zap all but root trailing */
  151.        p[column] = '\0';
  152.  
  153. /*--------------------------------------------------------------------*/
  154. /*               Print the results and return to caller               */
  155. /*--------------------------------------------------------------------*/
  156.  
  157.    printmsg(5,"Normalize: cwd = %s, input = %s, output = %s",
  158.                (E_cwd == NULL) ? "?" : E_cwd,
  159.                pathx,
  160.                p );
  161.  
  162.    return p;
  163.  
  164. } /* normalize */
  165.