Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/ways.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (show annotations) (download) (as text)
Tue Mar 24 17:30:49 2009 UTC (16 years ago) by amb
File MIME type: text/x-csrc
File size: 7622 byte(s)
Added highway=path; defaults to foot=yes but also is defaulted for bicycle and
horse transport.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/ways.c,v 1.27 2009-03-24 17:30:49 amb Exp $
3
4 Way data type functions.
5 ******************/ /******************
6 Written by Andrew M. Bishop
7
8 This file Copyright 2008,2009 Andrew M. Bishop
9 It may be distributed under the GNU Public License, version 2, or
10 any higher version. See section COPYING of the GNU Public license
11 for conditions under which this file may be redistributed.
12 ***************************************/
13
14
15 #include <assert.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include "functions.h"
20 #include "ways.h"
21
22
23 /*++++++++++++++++++++++++++++++++++++++
24 Load in a way list from a file.
25
26 Ways* LoadWayList Returns the way list.
27
28 const char *filename The name of the file to load.
29 ++++++++++++++++++++++++++++++++++++++*/
30
31 Ways *LoadWayList(const char *filename)
32 {
33 void *data;
34 Ways *ways;
35
36 ways=(Ways*)malloc(sizeof(Ways));
37
38 data=MapFile(filename);
39
40 if(!data)
41 return(NULL);
42
43 /* Copy the Ways structure from the loaded data */
44
45 *ways=*((Ways*)data);
46
47 /* Adjust the pointers in the Ways structure. */
48
49 ways->data =data;
50 ways->ways =(Way *)(data+(off_t)ways->ways);
51 ways->names=(char*)(data+(off_t)ways->names);
52
53 return(ways);
54 }
55
56
57 /*++++++++++++++++++++++++++++++++++++++
58 Decide on the type of a way given the "highway" parameter.
59
60 Highway HighwayType Returns the highway type of the way.
61
62 const char *highway The string containing the type of the way.
63 ++++++++++++++++++++++++++++++++++++++*/
64
65 Highway HighwayType(const char *highway)
66 {
67 switch(*highway)
68 {
69 case 'b':
70 if(!strcmp(highway,"byway")) return(Way_Track);
71 if(!strcmp(highway,"bridleway")) return(Way_Bridleway);
72 return(Way_Unknown);
73
74 case 'c':
75 if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
76 return(Way_Unknown);
77
78 case 'f':
79 if(!strcmp(highway,"footway")) return(Way_Footway);
80 return(Way_Unknown);
81
82 case 'l':
83 if(!strcmp(highway,"living_street")) return(Way_Residential);
84 return(Way_Unknown);
85
86 case 'm':
87 if(!strncmp(highway,"motorway",8)) return(Way_Motorway);
88 if(!strcmp(highway,"minor")) return(Way_Unclassified);
89 return(Way_Unknown);
90
91 case 'p':
92 if(!strncmp(highway,"primary",7)) return(Way_Primary);
93 if(!strcmp(highway,"path")) return(Way_Path);
94 if(!strcmp(highway,"pedestrian")) return(Way_Footway);
95 return(Way_Unknown);
96
97 case 'r':
98 if(!strcmp(highway,"road")) return(Way_Unclassified);
99 if(!strcmp(highway,"residential")) return(Way_Residential);
100 return(Way_Unknown);
101
102 case 's':
103 if(!strncmp(highway,"secondary",9)) return(Way_Secondary);
104 if(!strcmp(highway,"service")) return(Way_Service);
105 if(!strcmp(highway,"services")) return(Way_Service);
106 if(!strcmp(highway,"steps")) return(Way_Footway);
107 return(Way_Unknown);
108
109 case 't':
110 if(!strncmp(highway,"trunk",5)) return(Way_Trunk);
111 if(!strcmp(highway,"tertiary")) return(Way_Tertiary);
112 if(!strcmp(highway,"track")) return(Way_Track);
113 return(Way_Unknown);
114
115 case 'u':
116 if(!strcmp(highway,"unclassified")) return(Way_Unclassified);
117 if(!strcmp(highway,"unsurfaced")) return(Way_Track);
118 if(!strcmp(highway,"unpaved")) return(Way_Track);
119 return(Way_Unknown);
120
121 case 'w':
122 if(!strcmp(highway,"walkway")) return(Way_Footway);
123 return(Way_Unknown);
124
125 default:
126 ;
127 }
128
129 return(Way_Unknown);
130 }
131
132
133 /*++++++++++++++++++++++++++++++++++++++
134 Decide on the allowed type of transport given the name of it.
135
136 Transport TransportType Returns the type of the transport.
137
138 const char *transport The string containing the method of transport.
139 ++++++++++++++++++++++++++++++++++++++*/
140
141 Transport TransportType(const char *transport)
142 {
143 switch(*transport)
144 {
145 case 'b':
146 if(!strcmp(transport,"bicycle"))
147 return(Transport_Bicycle);
148 break;
149
150 case 'f':
151 if(!strcmp(transport,"foot"))
152 return(Transport_Foot);
153 break;
154
155 case 'g':
156 if(!strcmp(transport,"goods"))
157 return(Transport_Goods);
158 break;
159
160 case 'h':
161 if(!strcmp(transport,"horse"))
162 return(Transport_Horse);
163 if(!strcmp(transport,"hgv"))
164 return(Transport_HGV);
165 break;
166
167 case 'm':
168 if(!strcmp(transport,"motorbike"))
169 return(Transport_Motorbike);
170 if(!strcmp(transport,"motorcar"))
171 return(Transport_Motorcar);
172 break;
173
174 case 'p':
175 if(!strcmp(transport,"psv"))
176 return(Transport_PSV);
177 break;
178
179 default:
180 return(Transport_None);
181 }
182
183 return(Transport_None);
184 }
185
186
187 /*++++++++++++++++++++++++++++++++++++++
188 A string containing the name of a type of highway.
189
190 const char *HighwayName Returns the name.
191
192 Highway highway The highway type.
193 ++++++++++++++++++++++++++++++++++++++*/
194
195 const char *HighwayName(Highway highway)
196 {
197 switch(highway)
198 {
199 case Way_Motorway:
200 return("motorway");
201 case Way_Trunk:
202 return("trunk");
203 case Way_Primary:
204 return("primary");
205 case Way_Secondary:
206 return("secondary");
207 case Way_Tertiary:
208 return("tertiary");
209 case Way_Unclassified:
210 return("unclassified");
211 case Way_Residential:
212 return("residential");
213 case Way_Service:
214 return("service");
215 case Way_Track:
216 return("track");
217 case Way_Path:
218 return("path");
219 case Way_Bridleway:
220 return("bridleway");
221 case Way_Cycleway:
222 return("cycleway");
223 case Way_Footway:
224 return("footway");
225
226 case Way_Unknown:
227 case Way_OneWay:
228 case Way_Roundabout:
229 return(NULL);
230 }
231
232 return(NULL);
233 }
234
235
236 /*++++++++++++++++++++++++++++++++++++++
237 A string containing the name of a type of transport.
238
239 const char *TransportName Returns the name.
240
241 Transport transport The transport type.
242 ++++++++++++++++++++++++++++++++++++++*/
243
244 const char *TransportName(Transport transport)
245 {
246 switch(transport)
247 {
248 case Transport_None:
249 return("NONE");
250
251 case Transport_Foot:
252 return("foot");
253 case Transport_Bicycle:
254 return("bicycle");
255 case Transport_Horse:
256 return("horse");
257 case Transport_Motorbike:
258 return("motorbike");
259 case Transport_Motorcar:
260 return("motorcar");
261 case Transport_Goods:
262 return("goods");
263 case Transport_HGV:
264 return("hgv");
265 case Transport_PSV:
266 return("psv");
267 }
268 return(NULL);
269 }
270
271
272 /*++++++++++++++++++++++++++++++++++++++
273 Returns a list of all the highway types.
274
275 const char *HighwayList Return a list of all the highway types.
276 ++++++++++++++++++++++++++++++++++++++*/
277
278 const char *HighwayList(void)
279 {
280 return " motorway = Motorway\n"
281 " trunk = Trunk\n"
282 " primary = Primary\n"
283 " secondary = Secondary\n"
284 " tertiary = Tertiary\n"
285 " unclassified = Unclassified\n"
286 " residential = Residential\n"
287 " service = Service\n"
288 " track = Track\n"
289 " path = Path\n"
290 " bridleway = Bridleway\n"
291 " cycleway = Cycleway\n"
292 " footway = Footway\n";
293 }
294
295
296 /*++++++++++++++++++++++++++++++++++++++
297 Returns a list of all the transport types.
298
299 const char *TransportList Return a list of all the transport types.
300 ++++++++++++++++++++++++++++++++++++++*/
301
302 const char *TransportList(void)
303 {
304 return " foot = Foot\n"
305 " bicycle = Bicycle\n"
306 " horse = Horse\n"
307 " motorbike = Motorbike\n"
308 " motorcar = Motorcar\n"
309 " goods = Goods (Small lorry, van)\n"
310 " hgv = HGV (Heavy Goods Vehicle - large lorry)\n"
311 " psv = PSV (Public Service Vehicle - bus, coach)\n";
312 }

Properties

Name Value
cvs:description Functions for ways.