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

  1. /*--------------------------------------------------------------------*/
  2. /*    e x p o r t . c                                                 */
  3. /*                                                                    */
  4. /*    File name mapping routines for UUPC/extended                    */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: export.c 1.3 1993/10/12 00:41:51 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: export.c $
  24.  *     Revision 1.3  1993/10/12  00:41:51  ahd
  25.  *     Normalize comments
  26.  *
  27.  *     Revision 1.2  1993/10/09  15:46:15  rhg
  28.  *     ANSIify the source
  29.  *
  30.  */
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*                        System include files                        */
  34. /*--------------------------------------------------------------------*/
  35.  
  36. #include <stdio.h>
  37. #include <ctype.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <time.h>
  41.  
  42. /*--------------------------------------------------------------------*/
  43. /*                    UUPC/extended include files                     */
  44. /*--------------------------------------------------------------------*/
  45.  
  46. #include "lib.h"
  47. #include "arbmath.h"
  48. #include "export.h"
  49. #include "import.h"
  50. #include "usertabl.h"
  51. #include "hostable.h"
  52. #include "security.h"
  53.  
  54. currentfile();
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*       e x p o r t p a t h                                          */
  58. /*                                                                    */
  59. /*       Convert a local environment name to UNIX format name         */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. void exportpath(char *canon, const char *host, const char *remote)
  63. {
  64.    const char *xhost;
  65.    char *copy;
  66.    char tempname[FILENAME_MAX];
  67.    unsigned subscript;
  68.    unsigned char number[MAX_DIGITS];
  69.    char *token, *out;
  70.  
  71.    static size_t range =  UNIX_END_C - UNIX_START_C + 1;
  72.                               /* Determine unique number characters in
  73.                                  the UNIX file names we are mapping   */
  74.    size_t charsetsize;
  75.             /* Number of allowed characters in
  76.                               MS-DOS file names                   */
  77.  
  78. /*--------------------------------------------------------------------*/
  79. /*                      Define our character set                      */
  80. /*--------------------------------------------------------------------*/
  81.  
  82.    if ( E_charset == NULL )
  83.       E_charset = DOSCHARS;
  84.  
  85.    charsetsize = strlen( E_charset );
  86.  
  87. /*--------------------------------------------------------------------*/
  88. /*                Drop leading spool directory, if any                */
  89. /*--------------------------------------------------------------------*/
  90.  
  91.    if (equalni(host, E_spooldir, strlen( E_spooldir )))
  92.       xhost = host + strlen( E_spooldir ) + 1;
  93.    else
  94.       xhost = host;
  95.  
  96.    copy = strdup( xhost );
  97.    checkref( copy );
  98.  
  99. /*--------------------------------------------------------------------*/
  100. /*                        Drop the remote name                        */
  101. /*--------------------------------------------------------------------*/
  102.  
  103.    token = strtok( copy, "/");
  104.  
  105.    if ((token == NULL) || !equaln( token, remote, strlen( token )))
  106.    {
  107.       printmsg(0,"exportpath: Badly formed host name \"%s\"",xhost);
  108.       panic();
  109.    }
  110.  
  111. /*--------------------------------------------------------------------*/
  112. /*                 Get the character leading the name                 */
  113. /*--------------------------------------------------------------------*/
  114.  
  115.    token = strtok( NULL, "/");
  116.    if ( (token == NULL) || (strlen(token) != 1))
  117.    {
  118.       printmsg(0,"exportpath: Badly formed host name \"%s\"",xhost);
  119.       panic();
  120.    }
  121.  
  122.    strcpy(canon, token);
  123.    strcat(canon, ".");
  124.  
  125. /*--------------------------------------------------------------------*/
  126. /*       Create a binary number which represents our file name        */
  127. /*--------------------------------------------------------------------*/
  128.  
  129.    for (subscript = 0; subscript < MAX_DIGITS; subscript++ )
  130.       number[subscript] = 0;  /* Initialize number to zero        */
  131.  
  132.    token = strtok( NULL, "/");   /* Get variable part of name         */
  133.    while( (*token != '\0') && (*number == '\0'))
  134.    {
  135.       unsigned char digit;
  136.       mult(number, charsetsize, MAX_DIGITS); /* Shift the number over */
  137.       digit = (unsigned char) (strchr( E_charset , *token++) - E_charset);
  138.       add(number, digit , MAX_DIGITS); /* Add in new low order        */
  139.       if (*token == '.')               /* Next character a period?    */
  140.          token ++;                     /* Yes --> Ignore it           */
  141.    } /* while */
  142.  
  143.    out = &tempname[FILENAME_MAX];
  144.    *--out = '\0';          /* Terminate the string we will build  */
  145.  
  146. /*--------------------------------------------------------------------*/
  147. /*         Here's the loop to actually do the base conversion         */
  148. /*--------------------------------------------------------------------*/
  149.  
  150.       while(adiv( number, range, &subscript, MAX_DIGITS))
  151.        *--out = (char) (subscript + UNIX_START_C);
  152.  
  153. /*--------------------------------------------------------------------*/
  154. /*    We sort of lied above; the first character out of the           */
  155. /*    conversion is not a character at all, but bits which say how    */
  156. /*    many characters the remote and local file names get prefixed    */
  157. /*    to the converted name.  Retrieve that information now           */
  158. /*--------------------------------------------------------------------*/
  159.  
  160.       subscript = *out - UNIX_START_C;
  161.                               /* Convert back to pure number          */
  162.       token = canon + strlen( canon ); /* Remember end of string      */
  163.       if (subscript > HOSTLEN)
  164.       {
  165.          subscript /= HOSTLEN;
  166.          strcat( canon, remote );
  167.       }
  168.       else
  169.          strcat( canon, E_nodename );
  170.       token[ subscript ] = '\0';    /* Only use the length we were told */
  171.  
  172. /*--------------------------------------------------------------------*/
  173. /*               Add in the variable name and we're done              */
  174. /*--------------------------------------------------------------------*/
  175.  
  176.       strcat( canon, ++out );
  177.       free( copy );
  178.  
  179. /*--------------------------------------------------------------------*/
  180. /*                          Check the result                          */
  181. /*--------------------------------------------------------------------*/
  182.  
  183.       importpath( tempname, canon, remote );
  184.       if ( !equal( tempname, xhost ))
  185.       {
  186.          printmsg(0,
  187.             "exportpath: **mapping error** input \"%s\","
  188.             " result \"%s\", import \"%s\"",
  189.             xhost, canon, tempname );
  190.          panic();
  191.       } /* if */
  192.  
  193. } /* exportpath */
  194.