home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / cdity / EasyTM_src.lha / EasyTM-src / Node.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  2.6 KB  |  138 lines

  1. //************************************
  2. //
  3. // Name : Node.c
  4. //
  5. //************************************
  6.  
  7.  
  8. //**** Header files
  9.  
  10. //** OS Include files
  11.  
  12. #include <exec/lists.h>
  13. #include <exec/nodes.h>
  14. #include <exec/memory.h>
  15.  
  16. //** OS function prototypes
  17.  
  18. #include <clib/alib_protos.h>
  19. #include <clib/exec_protos.h>
  20.  
  21. //** OS function inline calls
  22.  
  23. #include <pragmas/exec_pragmas.h>
  24.  
  25. //** ANSI C includes
  26.  
  27. #include <string.h>
  28. #include <stdio.h>
  29.  
  30. //** application include
  31.  
  32. #include "Node.h"
  33.  
  34.  
  35. //**** Local storage
  36.  
  37. struct List *List=NULL;
  38.  
  39.  
  40. //**** Aux List functions
  41.  
  42. int InitList(void) {
  43.   if (NULL==List) {
  44.     if (List=AllocMem(sizeof(struct List),MEMF_CLEAR)) {
  45.       NewList(List);
  46.       return 1;
  47.     }
  48.   }
  49.   return 0;
  50. } // InitList
  51.  
  52. int FreeList(int all) {
  53.   struct Node *mynode;
  54.  
  55.   if (NULL!=List) {
  56.     while (mynode=RemHead(List)) {
  57.       DisposeNode((struct ProgNode *)mynode);
  58.     } // while
  59.  
  60.     if (1==all) {
  61.       FreeMem(List,sizeof(struct List));
  62.       List=NULL;
  63.     }
  64.     return 1;
  65.   }
  66.   return 0;
  67. } // FreeList
  68.  
  69. long ListLength(void) {
  70.   struct Node *myn;
  71.   long count=0;
  72.   if (NULL==List->lh_Head->ln_Succ) return 0;
  73.   for ( myn=List->lh_Head; myn->ln_Succ ; myn=myn->ln_Succ,count++ );
  74.   return count;
  75. } // ListLength
  76.  
  77.  
  78. //**** Node Con/De-Structors
  79.  
  80. struct ProgNode *NewNode(void) {
  81.   struct ProgNode *mynode;
  82.   mynode = AllocMem(sizeof(struct ProgNode),MEMF_CLEAR);
  83.   return mynode;
  84. } // NewNode
  85.  
  86. int DisposeNode(struct ProgNode *pn) {
  87.   if (NULL!=pn) {
  88.     if (NULL!=pn->pn_Node.ln_Name) FreeVec(pn->pn_Node.ln_Name);
  89.     if (NULL!=pn->pn_Filename) FreeVec(pn->pn_Filename);
  90.     if (NULL!=pn->pn_Directory) FreeVec(pn->pn_Directory);
  91.  
  92.     FreeMem(pn,sizeof(struct ProgNode));
  93.     return 1;
  94.   }
  95.   return 0;
  96. } // DisposeNode
  97.  
  98.  
  99. //**** Node Search functions
  100.  
  101. struct Node *FindNthNode(long n) {
  102.   struct Node *myn;
  103.  
  104.   for ( myn=List->lh_Head; (n--) && (myn) ; myn=myn->ln_Succ );
  105.   return myn;
  106. } // FindNthNode
  107.  
  108. //**** Node setting
  109.  
  110. void pnSetItem(struct ProgNode *pn, char *item) {
  111. #define ITEM pn->pn_Node.ln_Name
  112.   if (pn) {
  113.     if (NULL!=ITEM) FreeVec(ITEM);
  114.     ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
  115.   }
  116. #undef ITEM
  117. } // pnSetItem
  118.  
  119. void pnSetFilename(struct ProgNode *pn, char *item) {
  120. #define ITEM pn->pn_Filename
  121.   if (pn) {
  122.     if (NULL!=ITEM) FreeVec(ITEM);
  123.     ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
  124.   }
  125. #undef ITEM
  126. } // pnSetItem
  127.  
  128. void pnSetDirectory(struct ProgNode *pn, char *item) {
  129. #define ITEM pn->pn_Directory
  130.   if (pn) {
  131.     if (NULL!=ITEM) FreeVec(ITEM);
  132.     ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
  133.   }
  134. #undef ITEM
  135. } // pnSetItem
  136.  
  137. //**** End of file
  138.