home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 August - Disc 3 / chip_20018103_hu.iso / amiga / chiputil / gg / convertamigapath.lha / convertpath.c
C/C++ Source or Header  |  2001-06-21  |  658b  |  40 lines

  1. #include <stdlib.h>
  2.  
  3. char *__amigapath(const char *path)
  4. {
  5.     static char *amipath=NULL;
  6.     char *temp=NULL;
  7.     int ucur=0,acur=0;
  8.  
  9.     if (amipath)
  10.     free(amipath);
  11.  
  12.     temp=(char *)(malloc(strlen(path)+1));
  13.     if (temp==NULL)
  14.     return(NULL);
  15.  
  16.     for (;path[ucur]!='\0';acur++,ucur++) {
  17.     if (path[ucur]=='.') {
  18.         if ((path[ucur+1]=='.')&&(path[ucur+2]=='/')) {
  19.         acur--;
  20.         ucur++;
  21.         continue;
  22.         }
  23.         if (path[ucur+1]=='/') {
  24.         acur--;
  25.         ucur++;
  26.         continue;
  27.         }
  28.     }
  29.     temp[acur]=path[ucur];
  30.     }
  31.     temp[acur]='\0';
  32.  
  33.     amipath=(char *)(malloc(strlen(temp)+1));
  34.     if (amipath)
  35.     strcpy(amipath,temp);
  36.     free(temp);
  37.  
  38.     return(amipath);
  39. }
  40.