This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 #include "machinepile.h"
2
3 prefetchpile_t *insertPile(int mid, unsigned int oid, short numoffset, short *offset, prefetchpile_t *head) {
4         prefetchpile_t *tmp = head;
5         prefetchpile_t *ptr;
6         objpile_t *objnode;
7         unsigned int *oidarray;
8         short *offvalues;
9         int i;
10         char found = 0;
11
12         while (tmp != NULL) {
13                 if (tmp->mid == mid) { // Found a match with exsisting machine id
14                         if ((objnode = (objpile_t *) calloc(1, sizeof(objpile_t))) == NULL) {
15                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
16                                 return NULL;
17                         }
18                         if ((offvalues = (short *) calloc(numoffset, sizeof(short))) == NULL) {
19                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
20                                 return NULL;
21                         }
22                         /* Fill objpiles DS */
23                         objnode->oid = oid;
24                         objnode->numoffset = numoffset;
25                         for(i = 0; i<numoffset; i++)
26                                 offvalues[i] = offset[i];
27                         objnode->offset = offvalues;
28                         objnode->next = tmp->objpiles;
29                         tmp->objpiles = objnode;
30                         found = 1;
31                         break;
32                 }
33                 tmp = tmp->next;
34         }
35
36         tmp = head;
37         if(found != 1) {
38                  if(tmp->mid == 0) {//First time
39                         tmp->mid = mid;
40                         if ((objnode = (objpile_t *) calloc(1, sizeof(objpile_t))) == NULL) {
41                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
42                                 return NULL;
43                         }
44                         if ((offvalues = (short *) calloc(numoffset, sizeof(short))) == NULL) {
45                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
46                                 return NULL;
47                         }
48                         // Fill objpiles DS
49                         objnode->oid = oid;
50                         objnode->numoffset = numoffset;
51                         for(i = 0; i<numoffset; i++)
52                                 offvalues[i] = *((short *)offset + i); 
53                         objnode->offset = offvalues;
54                         objnode->next = NULL;
55                         tmp->objpiles = objnode;
56                         tmp->next = NULL;
57                 } else {
58                         if ((tmp = (prefetchpile_t *) calloc(1, sizeof(prefetchpile_t))) == NULL) {
59                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
60                                 return NULL;
61                         }
62                         tmp->mid = mid;
63                         if ((objnode = (objpile_t *) calloc(1, sizeof(objpile_t))) == NULL) {
64                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
65                                 return NULL;
66                         }
67                         if ((offvalues = (short *) calloc(numoffset, sizeof(short))) == NULL) {
68                                 printf("Calloc error: %s %d\n", __FILE__, __LINE__);
69                                 return NULL;
70                         }
71                         // Fill objpiles DS
72                         objnode->oid = oid;
73                         objnode->numoffset = numoffset;
74                         for(i = 0; i<numoffset; i++)
75                                 offvalues[i] = *((short *)offset + i); 
76                         objnode->offset = offvalues;
77                         objnode->next = NULL;
78                         tmp->objpiles = objnode;
79                         tmp->next = head;
80                         head = tmp;
81                 }
82         }
83         
84         return head;
85 }