home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 206.lha / Flist_v1.2 / Sources / pathname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-28  |  2.0 KB  |  93 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. *   Mods to device name generation by Steve (Raz) Berry
  11. *   12/31/88 (New Years Eve!)
  12. *
  13. **/
  14.  
  15. #include <stdio.h>
  16.  
  17. char *index();
  18. extern void auto_req();
  19.  
  20. #define FIBSIZ ((long) sizeof(struct FileInfoBlock))
  21.  
  22. int PathName(plock, buffer)
  23. struct FileLock *plock;
  24. char *buffer;
  25. {
  26.    struct FileLock *llock, *curdir;
  27.    char *temp, *pos, buf[100];
  28.    struct FileInfoBlock *filinf;
  29.     long rc;
  30.  
  31.    llock = NULL;
  32.    filinf = NULL;
  33.    temp = NULL;
  34.    buffer[0] = '\0';
  35.  
  36.    filinf = (struct FileInfoBlock *) AllocMem(FIBSIZ, MEMF_PUBLIC|MEMF_CLEAR);
  37.    if (filinf == NULL) goto cleanuplk;
  38.  
  39.    temp = (char *) AllocMem(255L, MEMF_PUBLIC|MEMF_CLEAR);
  40.    if (temp == NULL) goto cleanuplk;
  41.  
  42. #ifdef DEBUG
  43.    if(plock == NULL)
  44.     auto_req("lock is null");
  45. #endif
  46.  
  47.    rc = Examine(plock, filinf);
  48.  
  49.    if (rc == NULL) goto cleanuplk;
  50.  
  51.    strcpy(buffer, filinf->fib_FileName);
  52.    llock = ParentDir(plock);
  53. /*
  54. *  Now loop back through the parent directories until root is found.
  55. *  Meanwhile, keep track of the names.
  56. */
  57.  
  58.    while (llock != NULL) {
  59.       if (Examine(llock, filinf) == NULL) goto cleanuplk;
  60.  
  61.       strcpy(temp, buffer);
  62.       strcpy(buffer, filinf->fib_FileName);
  63.       strcat(buffer, "/");
  64.       strcat(buffer, temp);
  65.  
  66.       curdir = ParentDir(llock);
  67.       UnLock(llock);
  68.       llock = curdir;
  69.    }
  70. /*
  71. *   Now fix up the name
  72. */
  73.  
  74.    if (pos = index(buffer, '/')) {
  75.       *pos = ':';
  76.       if (pos == buffer) {
  77.          strcpy(temp, "ram");
  78.          strcat(temp, buffer);
  79.          strcpy(buffer, temp);
  80.       } 
  81.    } else 
  82.         strcat(buffer, ":");    /* Append : to root names - swb */
  83.  
  84. cleanuplk:
  85.  
  86.    if (filinf != NULL) FreeMem(filinf, FIBSIZ);
  87.    if (temp != NULL)   FreeMem(temp, 255L);
  88.    if (llock != NULL)   UnLock(llock);
  89.  
  90.    return(strlen(buffer));
  91. }
  92.  
  93.