1 /***************************************
2 $Header: /home/amb/routino/src/RCS/ways.c,v 1.44 2010/04/28 17:27:02 amb Exp $
4 Way data type functions.
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
27 #include "functions.h"
31 /*++++++++++++++++++++++++++++++++++++++
32 Load in a way list from a file.
34 Ways* LoadWayList Returns the way list.
36 const char *filename The name of the file to load.
37 ++++++++++++++++++++++++++++++++++++++*/
39 Ways *LoadWayList(const char *filename)
44 ways=(Ways*)malloc(sizeof(Ways));
46 data=MapFile(filename);
48 /* Copy the Ways structure from the loaded data */
52 /* Adjust the pointers in the Ways structure. */
55 ways->ways =(Way *)(data+sizeof(Ways));
56 ways->names=(char*)(data+(sizeof(Ways)+ways->number*sizeof(Way)));
62 /*++++++++++++++++++++++++++++++++++++++
63 Return 0 if the two ways are the same (in respect of their types and limits),
64 otherwise return positive or negative to allow sorting.
66 int WaysCompare Returns a comparison.
68 Way *way1 The first way.
70 Way *way2 The second way.
71 ++++++++++++++++++++++++++++++++++++++*/
73 int WaysCompare(Way *way1,Way *way2)
78 if(way1->type!=way2->type)
79 return((int)way1->type - (int)way2->type);
81 if(way1->allow!=way2->allow)
82 return((int)way1->allow - (int)way2->allow);
84 if(way1->props!=way2->props)
85 return((int)way1->props - (int)way2->props);
87 if(way1->speed!=way2->speed)
88 return((int)way1->speed - (int)way2->speed);
90 if(way1->weight!=way2->weight)
91 return((int)way1->weight - (int)way2->weight);
93 if(way1->height!=way2->height)
94 return((int)way1->height - (int)way2->height);
96 if(way1->width!=way2->width)
97 return((int)way1->width - (int)way2->width);
99 if(way1->length!=way2->length)
100 return((int)way1->length - (int)way2->length);