home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / WB_ARexx_v1.1 / pathname.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  81 lines

  1. /** pathname.c
  2. *
  3. *                     Copyright 1988, W.G.J. Langeveld
  4. *                           All Rights Reserved
  5. *                           Freely Distributable
  6. *
  7. *    Expand path name given a lock on a file name. Emulates ARP function
  8. *   of the same name, which is slightly unreliable.
  9. *
  10. **/
  11. #include <exec/exec.h>
  12. #include <libraries/dos.h>
  13. #include <libraries/dosextens.h>
  14. #include <functions.h>
  15. #include <stdio.h>
  16.  
  17. char *index();
  18.  
  19. #define FIBSIZ ((long) sizeof(struct FileInfoBlock))
  20.  
  21. int PathName(plock, buffer, n)
  22. struct FileLock *plock;
  23. char *buffer;
  24. int n;
  25. {
  26.    struct FileLock *lock, *curdir;
  27.    char *temp, *pos;
  28.    struct FileInfoBlock *filinf;
  29.  
  30.    lock = NULL;
  31.    filinf = NULL;
  32.    temp = NULL;
  33.    buffer[0] = '\0';
  34.  
  35.    filinf = (struct FileInfoBlock *) AllocMem(FIBSIZ, MEMF_PUBLIC|MEMF_CLEAR);
  36.    if (filinf == NULL) goto cleanuplk;
  37.  
  38.    temp = (char *) AllocMem(255L, MEMF_PUBLIC|MEMF_CLEAR);
  39.    if (temp == NULL) goto cleanuplk;
  40.  
  41.    if (Examine(plock, filinf) == NULL) goto cleanuplk;
  42.    strcpy(buffer, filinf->fib_FileName);
  43.    lock = ParentDir(plock);
  44. /*
  45. *  Now loop back through the parent directories until root is found.
  46. *  Meanwhile, keep track of the names.
  47. */
  48.    while (lock != NULL) {
  49.       if (Examine(lock, filinf) == NULL) goto cleanuplk;
  50.  
  51.       strcpy(temp, buffer);
  52.       strcpy(buffer, filinf->fib_FileName);
  53.       strcat(buffer, "/");
  54.       strcat(buffer, temp);
  55.  
  56.       curdir = ParentDir(lock);
  57.       UnLock(lock);
  58.       lock = curdir;
  59.    }
  60. /*
  61. *   Now fix up the name
  62. */
  63.    if (pos = index(buffer, '/')) {
  64.       *pos = ':';
  65.       if (pos == buffer) {
  66.          strcpy(temp, "ram");
  67.          strcat(temp, buffer);
  68.          strcpy(buffer, temp);
  69.       }
  70.    }
  71.  
  72. cleanuplk:
  73.    
  74.    if (filinf) FreeMem(filinf, FIBSIZ);
  75.    if (temp)   FreeMem(temp, 255L);
  76.    if (lock)   UnLock(lock);
  77.  
  78.    return(strlen(buffer));
  79. }
  80.  
  81.