home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / stefanb_src / dospath / src / copy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-25  |  2.4 KB  |  87 lines

  1. /*
  2.  * copy.c  V1.0
  3.  *
  4.  * Copy a path list
  5.  *
  6.  * (c) 1996 Stefan Becker
  7.  */
  8.  
  9. #include "dospath.h"
  10.  
  11. __geta4 struct PathListEntry *CopyPathList(__A0 struct PathListEntry *orig,
  12.                                            __A1 struct PathListEntry **anchor,
  13.                                            __A6 struct DOSPathBase *dpb)
  14. {
  15.  struct PathListEntry *head    = NULL;                    /* Head new list */
  16.  struct PathListEntry *current = anchor ? *anchor : NULL; /* Current entry */
  17.  struct PathListEntry *next    = NULL;                    /* Next entry    */
  18.  struct Library       *DOSBase = dpb->dpb_DOSBase;
  19.  
  20.  DEBUGLOG(kprintf("Copy: Orig 0x%08lx Anchor 0x%08lx Base 0x%08lx\n",
  21.                   orig, anchor, dpb);)
  22.  
  23.  /* Scan original path list */
  24.  while (orig) {
  25.  
  26.   DEBUGLOG(kprintf("Copy: Next Orig 0x%08lx\n", orig);)
  27.  
  28.   /* Allocate memory for next path list entry (only if not yet allocated!) */
  29.   /* Note: Please use AllocVec otherwise DOS gets mightely confused :-)    */
  30.   if ((next != NULL) ||
  31.       (next = AllocVec(sizeof(struct PathListEntry), MEMF_PUBLIC))) {
  32.  
  33.    DEBUGLOG(kprintf("Copy: Entry 0x%08lx\n", next);)
  34.  
  35.    /* Duplicate directory lock */
  36.    if (next->ple_Lock = DupLock(orig->ple_Lock)) {
  37.  
  38.     DEBUGLOG(kprintf("Copy: Lock 0x%08lx\n", next->ple_Lock);)
  39.  
  40.     /* Lock duplicated, clear pointer to next node */
  41.     next->ple_Next = NULL;
  42.  
  43.     /* Set head pointer */
  44.     if (head == NULL) head = next;
  45.  
  46.     /* Append new entry after current entry */
  47.     if (current) current->ple_Next = MKBADDR(next);
  48.  
  49.     /* Move current pointer */
  50.     current = next;
  51.  
  52.     /* Clear next pointer. A new entry must be allocated in the next round. */
  53.     next = NULL;
  54.    }
  55.  
  56.    /* Couldn't allocate memory for next path list entry */
  57.   } else {
  58.  
  59.    /* Free path list */
  60.    FreePathList(head, dpb);
  61.  
  62.    /* Clear head pointer */
  63.    head = NULL;
  64.  
  65.    /* If anchor was supplied remove new list from chain */
  66.    if (anchor && *anchor) (*anchor)->ple_Next = NULL;
  67.  
  68.    /* Leave loop */
  69.    break;
  70.   }
  71.  
  72.   /* Get next entry in original path list */
  73.   orig = BADDR(orig->ple_Next);
  74.  }
  75.  
  76.  /* Next path list entry already allocated? Free it! */
  77.  if (next) FreeVec(next);
  78.  
  79.  /* If anchor is valid and copy was successful then return end of list */
  80.  if (anchor && head) *anchor = current;
  81.  
  82.  DEBUGLOG(kprintf("Copy: Head 0x%08lx Anchor 0x%08lx\n", head, anchor);)
  83.  
  84.  /* Return pointer to head of copied path list */
  85.  return(head);
  86. }
  87.