This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 #include "plookup.h"
2 extern int classsize[];
3
4 plistnode_t *pCreate(int objects) {
5         plistnode_t *pile;
6         
7         //Create main structure
8         if((pile = calloc(1, sizeof(plistnode_t))) == NULL) {
9                 printf("Calloc error %s %d\n", __FILE__, __LINE__);
10                 return NULL;
11         }       
12         pile->next = NULL;
13         if ((pile->oidmod = calloc(objects, sizeof(unsigned int))) == NULL) {
14                 printf("Calloc error %s %d\n", __FILE__, __LINE__);
15                 return NULL;
16         }
17         if ((pile->oidread = calloc(objects, sizeof(unsigned int))) == NULL) {
18                 printf("Calloc error %s %d\n", __FILE__, __LINE__);
19                 return NULL;
20         }
21         pile->nummod = pile->numread = pile->sum_bytes = 0;
22         if ((pile->objread = calloc(objects, sizeof(int) + sizeof(short))) == NULL) {
23                 printf("Calloc error %s %d\n", __FILE__, __LINE__);
24                 return NULL;
25         }
26         pile->objmodified = NULL;
27         pile->nummod = pile->numread = pile->sum_bytes = 0;
28
29         return pile;
30 }
31
32 plistnode_t *pInsert(plistnode_t *pile, objheader_t *headeraddr, unsigned int mid, int num_objs) {
33         plistnode_t *ptr, *tmp;
34         int found = 0, offset;
35
36         tmp = pile;
37         //Add oid into a machine that is a part of the pile linked list structure
38         while(tmp != NULL) {
39                 if (tmp->mid == mid) {
40                         if ((headeraddr->status & DIRTY) == 1) {
41                                 tmp->oidmod[tmp->nummod] = headeraddr->oid;
42                                 tmp->nummod = tmp->nummod + 1;
43                                 tmp->sum_bytes += sizeof(objheader_t) + classsize[headeraddr->type];
44                         } else {
45                                 tmp->oidread[tmp->numread] = headeraddr->oid;
46                                 offset = (sizeof(unsigned int) + sizeof(short)) * tmp->numread;
47                                 memcpy(tmp->objread + offset, &headeraddr->oid, sizeof(unsigned int));
48                                 offset += sizeof(unsigned int);
49                                 memcpy(tmp->objread + offset, &headeraddr->version, sizeof(short));
50                                 tmp->numread = tmp->numread + 1;
51                         //      printf("DEBUG->pInsert() No of obj read = %d\n", tmp->numread);
52                         }
53                         found = 1;
54                         break;
55                 }
56                 tmp = tmp->next;
57         }
58         //Add oid for any new machine 
59         if (!found) {
60                 if((ptr = pCreate(num_objs)) == NULL) {
61                         return NULL;
62                 }
63                 ptr->mid = mid;
64                 if ((headeraddr->status & DIRTY) == 1) {
65                         ptr->oidmod[ptr->nummod] = headeraddr->oid;
66                         ptr->nummod = ptr->nummod + 1;
67                         ptr->sum_bytes += sizeof(objheader_t) + classsize[headeraddr->type];
68                 } else {
69                         ptr->oidread[ptr->numread] = headeraddr->oid;
70                         memcpy(ptr->objread, &headeraddr->oid, sizeof(unsigned int));
71                         memcpy(ptr->objread + sizeof(unsigned int), &headeraddr->version, sizeof(short));
72                         ptr->numread = ptr->numread + 1;
73                 }
74                 ptr->next = pile;
75                 pile = ptr;
76         }
77
78         return pile;
79 }
80
81 //Count the number of machine groups
82 int pCount(plistnode_t *pile) {
83         plistnode_t *tmp;
84         int pcount = 0;
85         tmp = pile;
86         while(tmp != NULL) {
87                 pcount++;
88                 tmp = tmp->next;
89         }
90         return pcount;
91 }
92
93 //Make a list of mid's for each machine group
94 int pListMid(plistnode_t *pile, unsigned int *list) {
95         int i = 0;
96         plistnode_t *tmp;
97         tmp = pile;
98         while (tmp != NULL) {
99                 list[i] = tmp->mid;
100                 i++;
101                 tmp = tmp->next;
102         }
103         return 0;
104 }
105
106 //Delete the entire pile
107 void pDelete(plistnode_t *pile) {
108         plistnode_t *next, *tmp;
109         tmp = pile;
110         while(tmp != NULL) {
111                 next = tmp->next;
112                 free(tmp->oidmod);
113                 free(tmp->oidread);
114                 free(tmp->objread);
115                 free(tmp);
116                 tmp = next;
117         }
118         return;
119 }