astyle --recursive --indent=spaces=2 --style=kr --indent-col1-comments --break-blocks --convert-tabs --max-code-length=200
This is done for better merging branch/LG_PRE_RELEASE_0.3 into trunk (same process is applied on this branch) git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7073 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
+145
-154
@@ -33,7 +33,7 @@
|
||||
* \date 2014
|
||||
* \version 0.1
|
||||
* \company EURECOM
|
||||
* \email:
|
||||
* \email:
|
||||
* \note
|
||||
* \warning
|
||||
*/
|
||||
@@ -59,131 +59,129 @@ parse_data (char *trace_file, int node_type)
|
||||
int fmt, id = 0, gid;
|
||||
node_container *value;
|
||||
|
||||
//if(table==NULL)
|
||||
//if(table==NULL)
|
||||
create_new_table (node_type);
|
||||
|
||||
if(list_head ==NULL)
|
||||
list_head = (node_info **) calloc (MAX_NUM_NODE_TYPES, sizeof (node_info*));
|
||||
list_head = (node_info **) calloc (MAX_NUM_NODE_TYPES, sizeof (node_info*));
|
||||
|
||||
if (list_head == NULL )
|
||||
{
|
||||
LOG_E (OMG, "-------node list table creation failed--------\n");
|
||||
exit (-1);
|
||||
if (list_head == NULL ) {
|
||||
LOG_E (OMG, "-------node list table creation failed--------\n");
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
|
||||
if ((fp = fopen (trace_file, "r")) == NULL) {
|
||||
LOG_E (OMG, "[OMG]:Cannot open file %s\n", trace_file);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
||||
while (!feof (fp)) {
|
||||
if (fgets (str, 126, fp)) {
|
||||
fmt = 0;
|
||||
p = str;
|
||||
|
||||
while (*p == ' ' || *p == '\t' || *p == '\r')
|
||||
p++; // skip whitespaces
|
||||
|
||||
if (*p != '\n') { //escape empty line
|
||||
pch = strtok (p, " "); // the separator between the items in the list is a space
|
||||
node_data *node = (node_data *) calloc (1, sizeof (node_data));
|
||||
node->type=-1;
|
||||
|
||||
while (pch != NULL) {
|
||||
|
||||
switch (fmt) {
|
||||
case 0:
|
||||
if (atof (pch) < 0)
|
||||
LOG_E (OMG, "error: negative time input \n");
|
||||
|
||||
node->time = fabs (atof (pch));
|
||||
LOG_D (OMG, "%.2f \n",node->time);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
node->vid = atoi (pch);
|
||||
LOG_D (OMG, "%d \n",node->vid);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
node->x_pos = atof (pch);
|
||||
LOG_D (OMG, "%.2f \n",node->x_pos);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
node->y_pos = atof (pch);
|
||||
LOG_D (OMG, "%.2f \n",node->y_pos);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (atof (pch) < 0)
|
||||
LOG_D (OMG, "error: negative speed input");
|
||||
|
||||
node->speed = fabs (atof (pch));
|
||||
LOG_D (OMG, "speed %.2f \n",node->speed);
|
||||
break;
|
||||
|
||||
/*case 5:
|
||||
node->type = atof (pch);
|
||||
break;*/
|
||||
default:
|
||||
LOG_E (OMG,
|
||||
"[Error in trance file]:incorrect data format \n");
|
||||
break;
|
||||
}
|
||||
|
||||
fmt += 1;
|
||||
pch = strtok (NULL, " ");
|
||||
}
|
||||
|
||||
node->next = NULL;
|
||||
node->visit = 0;
|
||||
|
||||
// look for node in node info
|
||||
gid = find_node_info (node->vid, node_type);
|
||||
|
||||
if (gid == -1) {
|
||||
node->gid = id;
|
||||
add_node_info (node->vid, node->gid, node_type);
|
||||
//store node data in the table
|
||||
hash_table_add (table[node_type], node, NULL);
|
||||
id++;
|
||||
} else {
|
||||
node->gid = gid;
|
||||
value = hash_table_lookup (table[node_type], node->gid);
|
||||
hash_table_add (table[node_type], node, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((fp = fopen (trace_file, "r")) == NULL)
|
||||
{
|
||||
LOG_E (OMG, "[OMG]:Cannot open file %s\n", trace_file);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
|
||||
while (!feof (fp))
|
||||
{
|
||||
if (fgets (str, 126, fp))
|
||||
{
|
||||
fmt = 0;
|
||||
p = str;
|
||||
|
||||
while (*p == ' ' || *p == '\t' || *p == '\r')
|
||||
p++; // skip whitespaces
|
||||
|
||||
if (*p != '\n') //escape empty line
|
||||
{
|
||||
pch = strtok (p, " "); // the separator between the items in the list is a space
|
||||
node_data *node = (node_data *) calloc (1, sizeof (node_data));
|
||||
node->type=-1;
|
||||
|
||||
while (pch != NULL)
|
||||
{
|
||||
|
||||
switch (fmt)
|
||||
{
|
||||
case 0:
|
||||
if (atof (pch) < 0)
|
||||
LOG_E (OMG, "error: negative time input \n");
|
||||
node->time = fabs (atof (pch));
|
||||
LOG_D (OMG, "%.2f \n",node->time);
|
||||
break;
|
||||
case 1:
|
||||
node->vid = atoi (pch);
|
||||
LOG_D (OMG, "%d \n",node->vid);
|
||||
break;
|
||||
case 2:
|
||||
node->x_pos = atof (pch);
|
||||
LOG_D (OMG, "%.2f \n",node->x_pos);
|
||||
break;
|
||||
case 3:
|
||||
node->y_pos = atof (pch);
|
||||
LOG_D (OMG, "%.2f \n",node->y_pos);
|
||||
break;
|
||||
case 4:
|
||||
if (atof (pch) < 0)
|
||||
LOG_D (OMG, "error: negative speed input");
|
||||
node->speed = fabs (atof (pch));
|
||||
LOG_D (OMG, "speed %.2f \n",node->speed);
|
||||
break;
|
||||
/*case 5:
|
||||
node->type = atof (pch);
|
||||
break;*/
|
||||
default:
|
||||
LOG_E (OMG,
|
||||
"[Error in trance file]:incorrect data format \n");
|
||||
break;
|
||||
}
|
||||
|
||||
fmt += 1;
|
||||
pch = strtok (NULL, " ");
|
||||
}
|
||||
|
||||
node->next = NULL;
|
||||
node->visit = 0;
|
||||
|
||||
// look for node in node info
|
||||
gid = find_node_info (node->vid, node_type);
|
||||
|
||||
if (gid == -1)
|
||||
{
|
||||
node->gid = id;
|
||||
add_node_info (node->vid, node->gid, node_type);
|
||||
//store node data in the table
|
||||
hash_table_add (table[node_type], node, NULL);
|
||||
id++;
|
||||
}
|
||||
else
|
||||
{
|
||||
node->gid = gid;
|
||||
value = hash_table_lookup (table[node_type], node->gid);
|
||||
hash_table_add (table[node_type], node, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
||||
}
|
||||
|
||||
//search for node given id if exist
|
||||
//search for node given id if exist
|
||||
|
||||
int
|
||||
find_node_info (int vid, int node_type)
|
||||
{
|
||||
node_info *search;
|
||||
if (list_head[node_type] != NULL)
|
||||
{
|
||||
search = list_head[node_type];
|
||||
while (search != NULL)
|
||||
{
|
||||
if (search->vid == vid)
|
||||
return search->g_id;
|
||||
search = search->next;
|
||||
}
|
||||
|
||||
if (list_head[node_type] != NULL) {
|
||||
search = list_head[node_type];
|
||||
|
||||
while (search != NULL) {
|
||||
if (search->vid == vid)
|
||||
return search->g_id;
|
||||
|
||||
search = search->next;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -193,32 +191,29 @@ void
|
||||
add_node_info (int nid, int n_gid, int node_type)
|
||||
{
|
||||
node_info *new = (node_info *) malloc (sizeof (node_info));
|
||||
if (new != NULL)
|
||||
{
|
||||
new->vid = nid;
|
||||
new->g_id = n_gid;
|
||||
new->next = NULL;
|
||||
|
||||
if (list_head[node_type] == NULL)
|
||||
list_head[node_type] = new;
|
||||
else
|
||||
{
|
||||
node_info *temp, *save;
|
||||
temp = list_head[node_type];
|
||||
while (temp != NULL)
|
||||
{
|
||||
save = temp;
|
||||
temp = temp->next;
|
||||
}
|
||||
if (new != NULL) {
|
||||
new->vid = nid;
|
||||
new->g_id = n_gid;
|
||||
new->next = NULL;
|
||||
|
||||
save->next = new;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E (OMG, "node info list creation failed\n");
|
||||
exit (-1);
|
||||
if (list_head[node_type] == NULL)
|
||||
list_head[node_type] = new;
|
||||
else {
|
||||
node_info *temp, *save;
|
||||
temp = list_head[node_type];
|
||||
|
||||
while (temp != NULL) {
|
||||
save = temp;
|
||||
temp = temp->next;
|
||||
}
|
||||
|
||||
save->next = new;
|
||||
}
|
||||
} else {
|
||||
LOG_E (OMG, "node info list creation failed\n");
|
||||
exit (-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,30 +235,26 @@ get_next_data (hash_table_t * table, int vid, int flag)
|
||||
|
||||
if (links == NULL)
|
||||
LOG_E (OMG, "ERROR in reading-: NO data for node %d in this block \n",
|
||||
vid);
|
||||
vid);
|
||||
|
||||
while (links != NULL)
|
||||
{
|
||||
if (links->visit == 0)
|
||||
break;
|
||||
save = links;
|
||||
links = links->next;
|
||||
}
|
||||
while (links != NULL) {
|
||||
if (links->visit == 0)
|
||||
break;
|
||||
|
||||
if (links != NULL)
|
||||
{
|
||||
if (flag == DATA_AND_STATUS_CHANGE)
|
||||
{
|
||||
if (block->next != block->end)
|
||||
links->visit = 1;
|
||||
return links;
|
||||
}
|
||||
else if (flag == DATA_ONLY)
|
||||
{
|
||||
return save;
|
||||
}
|
||||
save = links;
|
||||
links = links->next;
|
||||
}
|
||||
|
||||
if (links != NULL) {
|
||||
if (flag == DATA_AND_STATUS_CHANGE) {
|
||||
if (block->next != block->end)
|
||||
links->visit = 1;
|
||||
|
||||
return links;
|
||||
} else if (flag == DATA_ONLY) {
|
||||
return save;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return links;
|
||||
|
||||
DevAssert(false); // FIXME return 0?
|
||||
|
||||
Reference in New Issue
Block a user