Beispiel #1
0
sExpression *cloneList(sExpression *exp){
  if(isList(exp)){
    sList *temp = toList(exp);
    return cons(cloneList(car(temp)),
                cloneList(cdr(temp)));
  }
  if(isSymbol(exp)){
    return newSymbol(toSymb(exp)->name);
  }
  if(isNumber(exp)){
    return newNumber(toNum(exp)->value);
  }
  if(isString(exp)){
    return newString(toString(exp)->value);
  }
  return exp;
}
t_list * getLiveINVars(t_basic_block *bblock)
{
   t_cflow_Node *firstNode;
   
   if (bblock == NULL)
      return NULL;

   if (bblock->nodes == NULL)
      return NULL;

   firstNode = (t_cflow_Node *) LDATA(bblock->nodes);
   assert(firstNode != NULL);

   /* return a copy of the list of variables live in
    * input to the current basic block */
   return cloneList(firstNode->in);
}
Beispiel #3
0
sExpression *evalSyntaxRule(sSyntax *syntax, sExpression *parameters){
  sExpression *clonedRule = cloneList(newExp(syntax->rules, LIST_TAG));
  sExpression *temp = &sNull;
  sExpression *syntax_tmp = car(syntax->syntaxes);
  sExpression *rule = car(toList(clonedRule));
  sExpression *syntaxcdr = cdr(syntax->syntaxes);
  sExpression *rulecdr = cdr(toList(clonedRule));

  temp = evalSyntaxRuleIter(syntax_tmp, parameters, rule);
  while(isList(syntaxcdr) && isNull(temp)){
    syntax_tmp = car(toList(syntaxcdr));
    rule = car(toList(rulecdr));
    syntaxcdr = cdr(toList(syntaxcdr));
    rulecdr = cdr(toList(rulecdr));
    temp = evalSyntaxRuleIter(syntax_tmp, parameters, rule);
  }
  return rule;
}
t_list * getLiveOUTVars(t_basic_block *bblock)
{
   t_list *last_Element;
   t_cflow_Node *lastNode;
   
   if (bblock == NULL)
      return NULL;

   if (bblock->nodes == NULL)
      return NULL;

   
   last_Element = getLastElement(bblock->nodes);
   lastNode = (t_cflow_Node *) LDATA(last_Element);
   assert(lastNode != NULL);

   /* return a copy of the list of variables live in
    * input to the current basic block */
   return cloneList(lastNode->out);
}
int main(int argc, char* argv[])
{
	/* Declarations */
	List list;
	List list_1;
	List list_2;
	List list_3;
	List list_4;
	List list_5;
	List list_6;
	Position pos;
	Position pos_1;
	Position pos_2;
	Position pos_3;
	Position pos_4;
	Position pos_a, pos_b;
	int len;
	int idx;
	ElementType elem;

	/* Initialize list */
	list=createList();

	/* Test functions 'insertNode' and 'appendNode' */
	printf("Test functions 'insertNode' and 'appendNode'\n\n");
	printf("Before 'insertNode':\n");
	printList(list);
	pos_1=getHeaderNode(list);
	insertNode(11, list, pos_1);
	pos_2=advanceNode(pos_1);
	insertNode(2, list, pos_2);
	pos_3=advanceNode(pos_2);
	insertNode(3, list, pos_3);
	pos_4=advanceNode(pos_3);
	insertNode(10, list, pos_4);
	insertNode(9, list, pos_2);
	printf("After 'insertNode':\n");
	printList(list);
	printf("Before 'appendNode':\n");
	printList(list);
	appendNode(7, list);
	appendNode(2, list);
	printf("After 'appendNode'\n");
	printList(list);
	printf("\n");

	/* Test functions 'cloneList', 'deleteNode' and 'deleteList' */
	printf("Test functions 'cloneList', 'deleteNode' and 'deleteList'\n\n");
	list_1=cloneList(list);
	printf("Before 'deleteNode':\n");
	printList(list_1);
	deleteNode(2, list_1);
	printf("After 'deleteNode':\n");
	printList(list_1);
	printf("Before 'deleteList':\n");
	printList(list_1);
	deleteList(list_1);
	printf("After 'deleteList':\n");
	printList(list_1);
	printf("\n");

	/* Test function 'getListLength' */
	printf("Test function 'getListLength'\n\n");
	len=getListLength(list);
	printf("Length: %d\n", len);
	printf("\n");

	/* Test functions 'findNode', 'findNodePrevious' and 'getNodeIndex' */
	printf("Test functions 'findNode', 'findNodePrevious' and 'getNodeIndex'\n\n");
	elem=2;
	pos=findNode(elem, list);
	if(pos!=NULL)
	{
		idx=getNodeIndex(pos, list);
		printList(list);
		printf("finding %d, Element at index %d found\n", elem, idx);
	}
	else
	{
		printf("finding %d, not found\n", elem);
	}
	elem=3;
	pos=findNodePrevious(elem, list);
	/* Check whether elem is found in list */
	if(pos->m_next!=NULL)
	{
		idx=getNodeIndex(pos, list);
		printf("finding previous element of %d, Element at index %d found\n", elem, idx);
	}
	else
	{
		/* elem is not in list */
		printf("finding previous element of %d, not found\n", elem);
	}
	printf("\n");

	/* Test functions 'makeListEmpty' and 'isListEmpty' */
	printf("Test functions 'makeListEmpty' and 'isListEmpty'\n\n");
	list_2=cloneList(list);
	printf("Before 'makeListEmpty':\n");
	printList(list_2);
	list_2=makeListEmpty(list_2);
	if(isListEmpty(list_2))
	{
		printf("List emptied successfully\n");
		printf("After 'makeListEmpty'\n");
		printList(list_2);
	}
	printf("\n");

	/* Test functions 'getHeaderNode', 'getFirstNode', 'getLastNode', 'advanceNode' and 'getNodeElem' */
	printf("Test functions 'getHeaderNode', 'getFirstNode', 'getLastNode', 'advanceNode' and 'getNodeElem'\n\n");
	printList(list);
	pos=getHeaderNode(list);
	printf("Header at index %d\n", getNodeIndex(pos, list));
	pos=getFirstNode(list);
	printf("First element at index %d have value %d\n", getNodeIndex(pos, list), getNodeElem(pos));
	pos=getLastNode(list);
	printf("Last element at index %d have value %d\n", getNodeIndex(pos, list), getNodeElem(pos));
	pos=getFirstNode(list);
	pos=advanceNode(pos);
	printf("Second element at index %d have value %d\n", getNodeIndex(pos, list), getNodeElem(pos));
	printf("\n");

	/* Test function 'reverseList' */
	printf("Test function 'reverseList'\n\n");
	list_3=cloneList(list);
	printf("Before 'reverseList':\n");
	printList(list_3);
	list_3=reverseList(list_3);
	printf("After 'reverseList':\n");
	printList(list_3);
	printf("\n");

	/* Test function 'swapNode' */
	printf("Test function 'swapNode'\n\n");
	list_4=cloneList(list);
	printf("Before 'swapNode':\n");
	printList(list_4);
	pos_a=getHeaderNode(list_4);
	pos_a=advanceNode(pos_a);
	pos_a=advanceNode(pos_a);
	pos_b=advanceNode(pos_a);
	swapNode(pos_a, pos_b, list_4);
	printf("After 'swapNode':\n");
	printList(list_4);
	printf("\n");

	/* Test function 'bubbleSortList' */
	printf("Test function 'bubbleSortList'\n\n");
	list_5=cloneList(list);
	printf("Before 'bubbleSortList':\n");
	printList(list_5);
	bubbleSortList(list_5);
	printf("After 'bubbleSortList':\n");
	printList(list_5);
	printf("\n");

	/* Test function 'connectList' */
	printf("Test function 'connectList'\n\n");
	printf("List 1:\n");
	printList(list);
	printf("Length: %d\n", getListLength(list));
	printf("List 2:\n");
	printList(list_5);
	printf("Length: %d\n", getListLength(list_5));
	list_6=connectList(list, list_5);
	printf("Connected list:\n");
	printList(list_6);
	printf("Length: %d\n", getListLength(list_6));
	printf("\n");

	/* Cleanup memory */
	destroyList(list);
	destroyList(list_1);
	destroyList(list_2);
	destroyList(list_3);
	destroyList(list_4);
	destroyList(list_5);
	destroyList(list_6);

	return 0;
}
int performLivenessOnBlock(t_basic_block *bblock, t_list *out)
{
   t_list *current_element;
   t_list *cloned_list;
   t_cflow_Node *next_node;
   t_cflow_Node *current_node;
   int modified;

   /* initialize the local variables */
   modified = 0;

   if (bblock == NULL || bblock->nodes == NULL) {
      cflow_errorcode = CFLOW_INVALID_BBLOCK;
      return modified;
   }

   current_element = getLastElement(bblock->nodes);
   current_node = (t_cflow_Node *) LDATA(current_element);
   assert(current_node != NULL);

   /* update the out set */
   current_node->out = addListToSet
         (current_node->out, out, NULL, &modified);

   /* update the in list */
   cloned_list = cloneList(current_node->out);
   
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#else
   if ((current_node->uses)[0] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   
   if ((current_node->uses)[2] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#endif



#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
   if (current_node->def != NULL)
#endif
   {
      int found = 0;
      int current_use_idx = 0;
      
      do
      {
         if ((current_node->uses)[current_use_idx] != NULL)
         {
            if ((current_node->uses)[current_use_idx]->ID == current_node->def->ID)
               found = 1;
         }
         
         current_use_idx++;
         
      } while((found == 0) && (current_use_idx < 3));
      
      if (!found)
         cloned_list = removeElement(cloned_list, current_node->def);
   }
   
   current_node->in = addListToSet
         (current_node->in, cloned_list, NULL, &modified);

   /* remove the cloned list */
   freeList(cloned_list);
   
   /* set the new value of next_node */
   next_node = current_node;
   current_element = LPREV(current_element);
   while (current_element != NULL)
   {
      /* take a new node */
      current_node = (t_cflow_Node *) LDATA(current_element);
      assert(current_node != NULL);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(next_node->in);
      
      /* update the out list */
      current_node->out = addListToSet
            (current_node->out, cloned_list, NULL, &modified);
      
      /* remove the cloned list */
      freeList(cloned_list);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(current_node->out);
      
      /* update the in list */
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#else
      if ((current_node->uses)[0] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#endif
      
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
      if (current_node->def != NULL)
#endif
      {
         int found = 0;
         int current_use_idx = 0;
      
         do
         {
            if ((current_node->uses)[current_use_idx] != NULL)
            {
               if ((current_node->uses)[current_use_idx]->ID
                        == current_node->def->ID)
               {
                  found = 1;
               }
            }
            current_use_idx++;
         
         } while((found == 0) && (current_use_idx < 3));
      
         if (!found)
            cloned_list = removeElement(cloned_list, current_node->def);
      }

      current_node->in = addListToSet
            (current_node->in, cloned_list, NULL, &modified);

      /* remove the cloned list */
      freeList(cloned_list);
      
      /* update the loop control informations */
      current_element = LPREV(current_element);
      next_node = current_node;
   }

   /* return the `modified' value */
   return modified;
}
Beispiel #7
0
static unsigned int tagtransform_c_filter_rel_member_tags(
        struct keyval *rel_tags, int member_count,
        struct keyval *member_tags, const char **member_role,
        int * member_superseeded, int * make_boundary, int * make_polygon, int * roads) {
    char *type;
    struct keyval tags, *p, *q, *qq, poly_tags;
    int i, j;
    int first_outerway, contains_tag;

    /* Get the type, if there's no type we don't care */
    type = getItem(rel_tags, "type");
    if (!type)
        return 1;

    initList(&tags);
    initList(&poly_tags);

    /* Clone tags from relation */
    p = rel_tags->next;
    while (p != rel_tags) {
        /* For routes, we convert name to route_name */
        if ((strcmp(type, "route") == 0) && (strcmp(p->key, "name") == 0))
            addItem(&tags, "route_name", p->value, 1);
        else if (strcmp(p->key, "type")) /* drop type= */
            addItem(&tags, p->key, p->value, 1);
        p = p->next;
    }

    if (strcmp(type, "route") == 0) {
        const char *state = getItem(rel_tags, "state");
        const char *netw = getItem(rel_tags, "network");
        int networknr = -1;

        if (state == NULL ) {
            state = "";
        }

        if (netw != NULL ) {
            if (strcmp(netw, "lcn") == 0) {
                networknr = 10;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "lcn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "lcn", "connection", 1);
                } else {
                    addItem(&tags, "lcn", "yes", 1);
                }
            } else if (strcmp(netw, "rcn") == 0) {
                networknr = 11;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "rcn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "rcn", "connection", 1);
                } else {
                    addItem(&tags, "rcn", "yes", 1);
                }
            } else if (strcmp(netw, "ncn") == 0) {
                networknr = 12;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "ncn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "ncn", "connection", 1);
                } else {
                    addItem(&tags, "ncn", "yes", 1);
                }

            } else if (strcmp(netw, "lwn") == 0) {
                networknr = 20;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "lwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "lwn", "connection", 1);
                } else {
                    addItem(&tags, "lwn", "yes", 1);
                }
            } else if (strcmp(netw, "rwn") == 0) {
                networknr = 21;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "rwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "rwn", "connection", 1);
                } else {
                    addItem(&tags, "rwn", "yes", 1);
                }
            } else if (strcmp(netw, "nwn") == 0) {
                networknr = 22;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "nwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "nwn", "connection", 1);
                } else {
                    addItem(&tags, "nwn", "yes", 1);
                }
            }
        }

        if (getItem(rel_tags, "preferred_color") != NULL ) {
            const char *a = getItem(rel_tags, "preferred_color");
            if (strcmp(a, "0") == 0 || strcmp(a, "1") == 0
                    || strcmp(a, "2") == 0 || strcmp(a, "3") == 0
                    || strcmp(a, "4") == 0) {
                addItem(&tags, "route_pref_color", a, 1);
            } else {
                addItem(&tags, "route_pref_color", "0", 1);
            }
        } else {
            addItem(&tags, "route_pref_color", "0", 1);
        }

        if (getItem(rel_tags, "ref") != NULL ) {
            if (networknr == 10) {
                addItem(&tags, "lcn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 11) {
                addItem(&tags, "rcn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 12) {
                addItem(&tags, "ncn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 20) {
                addItem(&tags, "lwn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 21) {
                addItem(&tags, "rwn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 22) {
                addItem(&tags, "nwn_ref", getItem(rel_tags, "ref"), 1);
            }
        }
    } else if (strcmp(type, "boundary") == 0) {
        /* Boundaries will get converted into multiple geometries:
         - Linear features will end up in the line and roads tables (useful for admin boundaries)
         - Polygon features also go into the polygon table (useful for national_forests)
         The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */
        *make_boundary = 1;
    } else if (strcmp(type, "multipolygon") == 0
            && getItem(&tags, "boundary")) {
        /* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */
        *make_boundary = 1;
    } else if (strcmp(type, "multipolygon") == 0) {
        *make_polygon = 1;

        /* Collect a list of polygon-like tags, these are used later to
         identify if an inner rings looks like it should be rendered separately */
        p = tags.next;
        while (p != &tags) {
            if (!strcmp(p->key, "area")) {
                addItem(&poly_tags, p->key, p->value, 1);
            } else {
                for (i = 0; i < exportListCount[OSMTYPE_WAY]; i++) {
                    if (strcmp(exportList[OSMTYPE_WAY][i].name, p->key) == 0) {
                        if (exportList[OSMTYPE_WAY][i].flags & FLAG_POLYGON) {
                            addItem(&poly_tags, p->key, p->value, 1);
                        }
                        break;
                    }
                }
            }
            p = p->next;
        }

        /* Copy the tags from the outer way(s) if the relation is untagged (with
         * respect to tags that influence its polygon nature. Tags like name or fixme should be fine*/
        if (!listHasData(&poly_tags)) {
            first_outerway = 1;
            for (i = 0; i < member_count; i++) {
                if (member_role[i] && !strcmp(member_role[i], "inner"))
                    continue;

                /* insert all tags of the first outerway to the potential list of copied tags. */
                if (first_outerway) {
                    p = member_tags[i].next;
                    while (p != &(member_tags[i])) {
                        addItem(&poly_tags, p->key, p->value, 1);                        
                        p = p->next;
                    }
                } else {
                    /* Check if all of the tags in the list of potential tags are present on this way,
                       otherwise remove from the list of potential tags. Tags need to be present on
                       all outer ways to be copied over to the relation */
                    q = poly_tags.next; 
                    while (q != &poly_tags) {
                        p = getTag(&(member_tags[i]), q->key);
                        if ((p != NULL) && (strcmp(q->value, p->value) == 0)) {
                            q = q->next;
                        } else {
                            /* This tag is not present on all member outer ways, so don't copy it over to relation */
                            qq = q->next;
                            removeTag(q);
                            q = qq;
                        }
                    }
                }
                first_outerway = 0;
            }
            /* Copy the list identified outer way tags over to the relation */
            q = poly_tags.next; 
            while (q != &poly_tags) {
                addItem(&tags, q->key, q->value, 1);                        
                q = q->next;
            }

            /* We need to re-check and only keep polygon tags in the list of polytags */
            q = poly_tags.next; 
            while (q != &poly_tags) {
                contains_tag = 0;
                for (j = 0; j < exportListCount[OSMTYPE_WAY]; j++) {
                    if (strcmp(exportList[OSMTYPE_WAY][j].name, q->key) == 0) {
                        if (exportList[OSMTYPE_WAY][j].flags & FLAG_POLYGON) {
                            contains_tag = 1;
                            break;
                        }
                    }
                }
                if (contains_tag == 0) {
                    qq = q->next;
                    removeTag(q);
                    q = qq;
                } else {
                    q = q->next;
                }
            }
        }
        resetList(&poly_tags);
    } else {
        /* Unknown type, just exit */
        resetList(&tags);
        resetList(&poly_tags);
        return 1;
    }

    if (!listHasData(&tags)) {
        resetList(&tags);
        resetList(&poly_tags);
        return 1;
    }

    /* If we are creating a multipolygon then we
     mark each member so that we can skip them during iterate_ways
     but only if the polygon-tags look the same as the outer ring */
    if (make_polygon) {
        for (i = 0; i < member_count; i++) {
            int match = 1;
            struct keyval *p = member_tags[i].next;
            while (p != &(member_tags[i])) {
                const char *v = getItem(&tags, p->key);
                if (!v || strcmp(v, p->value)) {
                    /* z_order and osm_ are automatically generated tags, so ignore them */
                    if ((strcmp(p->key, "z_order") != 0) && (strcmp(p->key, "osm_user") != 0) && 
                        (strcmp(p->key, "osm_version") != 0) && (strcmp(p->key, "osm_uid") != 0) &&
                        (strcmp(p->key, "osm_changeset")) && (strcmp(p->key, "osm_timestamp") != 0)) {
                        match = 0;
                        break;
                    }
                }
                p = p->next;
            }
            if (match) {
                member_superseeded[i] = 1;
            } else {
                member_superseeded[i] = 0;
            }
        }
    }

    resetList(rel_tags);
    cloneList(rel_tags, &tags);
    resetList(&tags);

    add_z_order(rel_tags, roads);

    return 0;
}
Beispiel #8
0
static unsigned int tagtransform_c_filter_rel_member_tags(
        struct keyval *rel_tags, int member_count,
        struct keyval *member_tags, const char **member_role,
        int * member_superseeded, int * make_boundary, int * make_polygon, int * roads) {
    char *type;
    struct keyval tags, *p, poly_tags;
    int i;

    /* Get the type, if there's no type we don't care */
    type = getItem(rel_tags, "type");
    if (!type)
        return 1;

    initList(&tags);
    initList(&poly_tags);

    /* Clone tags from relation */
    p = rel_tags->next;
    while (p != rel_tags) {
        /* For routes, we convert name to route_name */
        if ((strcmp(type, "route") == 0) && (strcmp(p->key, "name") == 0))
            addItem(&tags, "route_name", p->value, 1);
        else if (strcmp(p->key, "type")) /* drop type= */
            addItem(&tags, p->key, p->value, 1);
        p = p->next;
    }

    if (strcmp(type, "route") == 0) {
        const char *state = getItem(rel_tags, "state");
        const char *netw = getItem(rel_tags, "network");
        int networknr = -1;

        if (state == NULL ) {
            state = "";
        }

        if (netw != NULL ) {
            if (strcmp(netw, "lcn") == 0) {
                networknr = 10;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "lcn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "lcn", "connection", 1);
                } else {
                    addItem(&tags, "lcn", "yes", 1);
                }
            } else if (strcmp(netw, "rcn") == 0) {
                networknr = 11;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "rcn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "rcn", "connection", 1);
                } else {
                    addItem(&tags, "rcn", "yes", 1);
                }
            } else if (strcmp(netw, "ncn") == 0) {
                networknr = 12;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "ncn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "ncn", "connection", 1);
                } else {
                    addItem(&tags, "ncn", "yes", 1);
                }

            } else if (strcmp(netw, "lwn") == 0) {
                networknr = 20;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "lwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "lwn", "connection", 1);
                } else {
                    addItem(&tags, "lwn", "yes", 1);
                }
            } else if (strcmp(netw, "rwn") == 0) {
                networknr = 21;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "rwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "rwn", "connection", 1);
                } else {
                    addItem(&tags, "rwn", "yes", 1);
                }
            } else if (strcmp(netw, "nwn") == 0) {
                networknr = 22;
                if (strcmp(state, "alternate") == 0) {
                    addItem(&tags, "nwn", "alternate", 1);
                } else if (strcmp(state, "connection") == 0) {
                    addItem(&tags, "nwn", "connection", 1);
                } else {
                    addItem(&tags, "nwn", "yes", 1);
                }
            }
        }

        if (getItem(rel_tags, "preferred_color") != NULL ) {
            const char *a = getItem(rel_tags, "preferred_color");
            if (strcmp(a, "0") == 0 || strcmp(a, "1") == 0
                    || strcmp(a, "2") == 0 || strcmp(a, "3") == 0
                    || strcmp(a, "4") == 0) {
                addItem(&tags, "route_pref_color", a, 1);
            } else {
                addItem(&tags, "route_pref_color", "0", 1);
            }
        } else {
            addItem(&tags, "route_pref_color", "0", 1);
        }

        if (getItem(rel_tags, "ref") != NULL ) {
            if (networknr == 10) {
                addItem(&tags, "lcn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 11) {
                addItem(&tags, "rcn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 12) {
                addItem(&tags, "ncn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 20) {
                addItem(&tags, "lwn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 21) {
                addItem(&tags, "rwn_ref", getItem(rel_tags, "ref"), 1);
            } else if (networknr == 22) {
                addItem(&tags, "nwn_ref", getItem(rel_tags, "ref"), 1);
            }
        }
    } else if (strcmp(type, "boundary") == 0) {
        /* Boundaries will get converted into multiple geometries:
         - Linear features will end up in the line and roads tables (useful for admin boundaries)
         - Polygon features also go into the polygon table (useful for national_forests)
         The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */
        *make_boundary = 1;
    } else if (strcmp(type, "multipolygon") == 0
            && getItem(&tags, "boundary")) {
        /* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */
        *make_boundary = 1;
    } else if (strcmp(type, "multipolygon") == 0) {
        *make_polygon = 1;

        /* Copy the tags from the outer way(s) if the relation is untagged */
        /* or if there is just a name tag, people seem to like naming relations */
        if (!listHasData(&tags)
                || ((countList(&tags) == 1) && getItem(&tags, "name"))) {
            for (i = 0; i < member_count; i++) {
                if (member_role[i] && !strcmp(member_role[i], "inner"))
                    continue;

                p = member_tags[i].next;
                while (p != &(member_tags[i])) {
                    addItem(&tags, p->key, p->value, 1);
                    p = p->next;
                }
            }
        }

        /* Collect a list of polygon-like tags, these are used later to
         identify if an inner rings looks like it should be rendered separately */
        p = tags.next;
        while (p != &tags) {
            if (!strcmp(p->key, "area")) {
                addItem(&poly_tags, p->key, p->value, 1);
            } else {
                for (i = 0; i < exportListCount[OSMTYPE_WAY]; i++) {
                    if (strcmp(exportList[OSMTYPE_WAY][i].name, p->key) == 0) {
                        if (exportList[OSMTYPE_WAY][i].flags & FLAG_POLYGON) {
                            addItem(&poly_tags, p->key, p->value, 1);
                        }
                        break;
                    }
                }
            }
            p = p->next;
        }
    } else {
        /* Unknown type, just exit */
        resetList(&tags);
        resetList(&poly_tags);
        return 1;
    }

    /* If we are creating a multipolygon then we
     mark each member so that we can skip them during iterate_ways
     but only if the polygon-tags look the same as the outer ring */
    if (make_polygon) {
        for (i = 0; i < member_count; i++) {
            int match = 0;
            struct keyval *p = poly_tags.next;
            while (p != &poly_tags) {
                const char *v = getItem(&(member_tags[i]), p->key);
                if (!v || strcmp(v, p->value)) {
                    match = 0;
                    break;
                }
                match = 1;
                p = p->next;
            }
            if (match) {
                member_superseeded[i] = 1;
            } else {
                member_superseeded[i] = 0;
            }
        }
    }

    resetList(rel_tags);
    cloneList(rel_tags, &tags);
    resetList(&tags);

    add_z_order(rel_tags, roads);

    return 0;
}