Imported Upstream version 1.4.1
[routino] / src / ways.c
1 /***************************************
2  $Header: /home/amb/routino/src/RCS/ways.c,v 1.44 2010/04/28 17:27:02 amb Exp $
3
4  Way data type functions.
5
6  Part of the Routino routing software.
7  ******************/ /******************
8  This file Copyright 2008-2010 Andrew M. Bishop
9
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.
14
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.
19
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  ***************************************/
23
24
25 #include <stdlib.h>
26
27 #include "functions.h"
28 #include "ways.h"
29
30
31 /*++++++++++++++++++++++++++++++++++++++
32   Load in a way list from a file.
33
34   Ways* LoadWayList Returns the way list.
35
36   const char *filename The name of the file to load.
37   ++++++++++++++++++++++++++++++++++++++*/
38
39 Ways *LoadWayList(const char *filename)
40 {
41  void *data;
42  Ways *ways;
43
44  ways=(Ways*)malloc(sizeof(Ways));
45
46  data=MapFile(filename);
47
48  /* Copy the Ways structure from the loaded data */
49
50  *ways=*((Ways*)data);
51
52  /* Adjust the pointers in the Ways structure. */
53
54  ways->data =data;
55  ways->ways =(Way *)(data+sizeof(Ways));
56  ways->names=(char*)(data+(sizeof(Ways)+ways->number*sizeof(Way)));
57
58  return(ways);
59 }
60
61
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.
65
66   int WaysCompare Returns a comparison.
67
68   Way *way1 The first way.
69
70   Way *way2 The second way.
71   ++++++++++++++++++++++++++++++++++++++*/
72
73 int WaysCompare(Way *way1,Way *way2)
74 {
75  if(way1==way2)
76     return(0);
77
78  if(way1->type!=way2->type)
79     return((int)way1->type - (int)way2->type);
80
81  if(way1->allow!=way2->allow)
82     return((int)way1->allow - (int)way2->allow);
83
84  if(way1->props!=way2->props)
85     return((int)way1->props - (int)way2->props);
86
87  if(way1->speed!=way2->speed)
88     return((int)way1->speed - (int)way2->speed);
89
90  if(way1->weight!=way2->weight)
91     return((int)way1->weight - (int)way2->weight);
92
93  if(way1->height!=way2->height)
94     return((int)way1->height - (int)way2->height);
95
96  if(way1->width!=way2->width)
97     return((int)way1->width - (int)way2->width);
98
99  if(way1->length!=way2->length)
100     return((int)way1->length - (int)way2->length);
101
102  return(0);
103 }