1 /***************************************
2 $Header: /home/amb/routino/src/RCS/ways.c,v 1.46 2010/07/24 10:09:07 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 ***************************************/
32 /*++++++++++++++++++++++++++++++++++++++
33 Load in a way list from a file.
35 Ways* LoadWayList Returns the way list.
37 const char *filename The name of the file to load.
38 ++++++++++++++++++++++++++++++++++++++*/
40 Ways *LoadWayList(const char *filename)
44 ways=(Ways*)malloc(sizeof(Ways));
48 ways->data=MapFile(filename);
50 /* Copy the WaysFile structure from the loaded data */
52 ways->file=*((WaysFile*)ways->data);
54 /* Set the pointers in the Ways structure. */
56 ways->ways =(Way *)(ways->data+sizeof(WaysFile));
57 ways->names=(char*)(ways->data+sizeof(WaysFile)+ways->file.number*sizeof(Way));
61 ways->fd=ReOpenFile(filename);
63 /* Copy the WaysFile header structure from the loaded data */
65 ReadFile(ways->fd,&ways->file,sizeof(WaysFile));
67 ways->namesoffset=sizeof(WaysFile)+ways->file.number*sizeof(Way);
78 /*++++++++++++++++++++++++++++++++++++++
79 Return 0 if the two ways are the same (in respect of their types and limits),
80 otherwise return positive or negative to allow sorting.
82 int WaysCompare Returns a comparison.
84 Way *way1 The first way.
86 Way *way2 The second way.
87 ++++++++++++++++++++++++++++++++++++++*/
89 int WaysCompare(Way *way1,Way *way2)
94 if(way1->type!=way2->type)
95 return((int)way1->type - (int)way2->type);
97 if(way1->allow!=way2->allow)
98 return((int)way1->allow - (int)way2->allow);
100 if(way1->props!=way2->props)
101 return((int)way1->props - (int)way2->props);
103 if(way1->speed!=way2->speed)
104 return((int)way1->speed - (int)way2->speed);
106 if(way1->weight!=way2->weight)
107 return((int)way1->weight - (int)way2->weight);
109 if(way1->height!=way2->height)
110 return((int)way1->height - (int)way2->height);
112 if(way1->width!=way2->width)
113 return((int)way1->width - (int)way2->width);
115 if(way1->length!=way2->length)
116 return((int)way1->length - (int)way2->length);