1 /*
2    pspw_atom.c
3    author - Eric Bylaska
4 */
5 
6 #include	<stdlib.h>
7 #include	<stdio.h>
8 #include	"pspw_atom.h"
9 
10 
11 #define	NIL	((void *) 0)
12 
13 
14 
15 /********************************
16  *				*
17  *         pspw_atom_init	*
18  *				*
19  ********************************/
pspw_atom_init(Atom_List_Type * atom)20 void	pspw_atom_init(Atom_List_Type *atom)
21 {
22    *atom = NIL;
23 
24 } /* pspw_atom_init */
25 
26 /********************************
27  *				*
28  *         pspw_atom_add	*
29  *				*
30  ********************************/
pspw_atom_add(Atom_List_Type * atom,int a)31 void	pspw_atom_add(Atom_List_Type *atom, int a)
32 {
33    Atom_List_Type prev,cur,node;
34 
35    node       = (Atom_List_Type) malloc(sizeof(struct atom_struct));
36    node->a    = a;
37    node->next = NIL;
38 
39    /* first atom on list */
40    if (*atom == NIL)
41    {
42       *atom = node;
43    }
44    /* add to end of list */
45    else
46    {
47       cur  = *atom;
48       while (cur != NIL)
49       {
50          prev = cur;
51          cur  = cur->next;
52       }
53       prev->next = node;
54    }
55 
56 }
57 
58 /********************************
59  *				*
60  *         pspw_atom_size	*
61  *				*
62  ********************************/
pspw_atom_size(Atom_List_Type atom)63 int 	pspw_atom_size(Atom_List_Type atom)
64 {
65    Atom_List_Type cur;
66    int            count;
67 
68    cur   = atom;
69    count = 0;
70    while (cur != NIL)
71    {
72       cur = cur->next;
73       ++count;
74    }
75    return count;
76 }
77 
78 /********************************
79  *				*
80  *         pspw_atom		*
81  *				*
82  ********************************/
pspw_atom(Atom_List_Type atom,int indx)83 int 	pspw_atom(Atom_List_Type atom, int indx)
84 {
85     Atom_List_Type	cur;
86     int 		i;
87 
88     if (pspw_atom_size(atom) < indx)
89     {
90        printf("pspw_atom ERROR\n");
91        exit(99);
92     }
93 
94     cur = atom;
95     for (i=1; i<(indx); ++i)
96        cur = cur->next;
97 
98     return cur->a;
99 }
100 
101 /********************************
102  *				*
103  *         pspw_atom_end	*
104  *				*
105  ********************************/
pspw_atom_end(Atom_List_Type atom)106 void	pspw_atom_end(Atom_List_Type atom)
107 {
108     Atom_List_Type cur;
109 
110     while (atom != NIL)
111     {
112        cur = atom;
113        atom = atom->next;
114        free(cur);
115     }
116 }
117 
118 /* $Id$ */
119