home *** CD-ROM | disk | FTP | other *** search
- //************************************
- //
- // Name : Node.c
- //
- //************************************
-
-
- //**** Header files
-
- //** OS Include files
-
- #include <exec/lists.h>
- #include <exec/nodes.h>
- #include <exec/memory.h>
-
- //** OS function prototypes
-
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
-
- //** OS function inline calls
-
- #include <pragmas/exec_pragmas.h>
-
- //** ANSI C includes
-
- #include <string.h>
- #include <stdio.h>
-
- //** application include
-
- #include "Node.h"
-
-
- //**** Local storage
-
- struct List *List=NULL;
-
-
- //**** Aux List functions
-
- int InitList(void) {
- if (NULL==List) {
- if (List=AllocMem(sizeof(struct List),MEMF_CLEAR)) {
- NewList(List);
- return 1;
- }
- }
- return 0;
- } // InitList
-
- int FreeList(int all) {
- struct Node *mynode;
-
- if (NULL!=List) {
- while (mynode=RemHead(List)) {
- DisposeNode((struct ProgNode *)mynode);
- } // while
-
- if (1==all) {
- FreeMem(List,sizeof(struct List));
- List=NULL;
- }
- return 1;
- }
- return 0;
- } // FreeList
-
- long ListLength(void) {
- struct Node *myn;
- long count=0;
- if (NULL==List->lh_Head->ln_Succ) return 0;
- for ( myn=List->lh_Head; myn->ln_Succ ; myn=myn->ln_Succ,count++ );
- return count;
- } // ListLength
-
-
- //**** Node Con/De-Structors
-
- struct ProgNode *NewNode(void) {
- struct ProgNode *mynode;
- mynode = AllocMem(sizeof(struct ProgNode),MEMF_CLEAR);
- return mynode;
- } // NewNode
-
- int DisposeNode(struct ProgNode *pn) {
- if (NULL!=pn) {
- if (NULL!=pn->pn_Node.ln_Name) FreeVec(pn->pn_Node.ln_Name);
- if (NULL!=pn->pn_Filename) FreeVec(pn->pn_Filename);
- if (NULL!=pn->pn_Directory) FreeVec(pn->pn_Directory);
-
- FreeMem(pn,sizeof(struct ProgNode));
- return 1;
- }
- return 0;
- } // DisposeNode
-
-
- //**** Node Search functions
-
- struct Node *FindNthNode(long n) {
- struct Node *myn;
-
- for ( myn=List->lh_Head; (n--) && (myn) ; myn=myn->ln_Succ );
- return myn;
- } // FindNthNode
-
- //**** Node setting
-
- void pnSetItem(struct ProgNode *pn, char *item) {
- #define ITEM pn->pn_Node.ln_Name
- if (pn) {
- if (NULL!=ITEM) FreeVec(ITEM);
- ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
- }
- #undef ITEM
- } // pnSetItem
-
- void pnSetFilename(struct ProgNode *pn, char *item) {
- #define ITEM pn->pn_Filename
- if (pn) {
- if (NULL!=ITEM) FreeVec(ITEM);
- ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
- }
- #undef ITEM
- } // pnSetItem
-
- void pnSetDirectory(struct ProgNode *pn, char *item) {
- #define ITEM pn->pn_Directory
- if (pn) {
- if (NULL!=ITEM) FreeVec(ITEM);
- ITEM=strcpy( AllocVec(strlen(item)+1,NULL), item);
- }
- #undef ITEM
- } // pnSetItem
-
- //**** End of file
-