home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / vmsisode / vmsisode80_tar.Z / vmsisode80_tar / sockit / source / unix2vms.c < prev   
Encoding:
C/C++ Source or Header  |  1991-12-05  |  2.4 KB  |  97 lines

  1. #include <stdio.h>
  2.  
  3. char *unix2vms(s)
  4. char *s;
  5. {
  6.     static char *buffer = NULL, *buf;
  7.     char *t, *p, *q, *x, *strchr(), *si_getenv();
  8.     static int debug = 0;
  9.  
  10.     if(buffer == NULL) {
  11.         buffer = (char *)malloc(257);
  12.         buf    = (char *)malloc(257);
  13.     }
  14.     t = buffer;
  15.     memset(t, 0, 257);
  16.     strcpy(buf,s);
  17.     p = strchr(buf,'=');  /*get rid of any '='s*/
  18.     if (p != NULL) {
  19.        *p = '_';
  20.        while ( (q = strchr(p+1,'=')) != NULL) {*q = '_';p = q;}
  21.     }
  22.  
  23. if (debug) fprintf(stderr,"unix2vms called :%s:",s);
  24.     if (strchr(buf,'[') != NULL) { /*crude test for already vms files*/
  25.        strcpy(buffer,buf);
  26. if (debug) fprintf(stderr,"translated0 to :%s:\n",buffer);
  27.        return(buffer);
  28.     }
  29.  
  30.     if (strcmp(buf,".") == 0 || strcmp(buf,"./") == 0) {
  31.         strcpy(buffer,"[]");
  32. /*        strcpy(buffer,si_getenv("PATH"));*/
  33. /* whats wrong here? commented version probably is needed somewhere
  34. or why would I have done it?*/
  35. if (debug) fprintf(stderr,"translated1 to :%s:\n",buffer);
  36.         return(buffer);
  37.     }
  38.  
  39.     if (strcmp(buf,"..") == 0 || strcmp(buf,"../") == 0) {
  40.         strcpy(buffer,"[-]");
  41. if (debug) fprintf(stderr,"translated2 to :%s:\n",buffer);
  42.         return(buffer);
  43.     }
  44.  
  45.     if (strchr(buf, '/') == NULL) {    /*is it a straight filename*/
  46.           if ((q = strchr(buf,']')) == NULL) q = buf;
  47.           p = strchr(q,'.');
  48.           if (p != NULL) {
  49.              while ( (q = strchr(p+1,'.')) != NULL) {*p = '_';p = q;}
  50.           }
  51.           strcpy(buffer,buf);
  52. if (debug) fprintf(stderr,"translated3 to :%s:\n",buffer);
  53.           return(buffer);
  54.     }
  55.  
  56.     x = buf;
  57.     if (*x == '/') {            /* does it start with a / */
  58.         p = strchr(x+1,'/');
  59.         *p = '\0';
  60.         strcpy(t, x+1);    /*yes - put first element:*/
  61.         t += strlen(t);
  62.         strcat(t,":[000000");
  63.         x = p+1;
  64.     }
  65.     else if ((*x == '.') && (*(x+1) == '/') && (strchr(x+2, '/') == NULL)) {
  66.             strcat(t,"[");
  67.         x = x+2;        /* ./fred ignore the ./ */
  68.     }
  69.     else strcat(t,"[");
  70.  
  71.     while (*x) {
  72.        p = strchr(x,'/');
  73.        if (p != NULL) {
  74.           *p = '\0';
  75.           if (*x == '.' && *(x+1) == '.' && *(x+2) == '\0') strcat(t,".-");
  76.           else if (*x == '.' && *(x+1) == '\0');
  77.           else {
  78.              strcat(t,".");
  79.              strcat(t,x);
  80.           }
  81.           x = p+1;
  82.           if (*x == '\0') strcat(t,"]");
  83.        }
  84.        else {
  85.           strcat(t,"]");
  86.           p = strchr(x,'.');
  87.           if (p != NULL) {
  88.              while ( (q = strchr(p+1,'.')) != NULL) {*p = '_';p = q;}
  89.           }
  90.           strcat(t,x);
  91.           x = x +strlen(x);
  92.        }
  93.     }
  94. if (debug) fprintf(stderr,"translated4 to :%s:\n",buffer);
  95.     return(buffer);
  96. }
  97.