1 /********************************************************************
2 ** @source JEEPS input functions
3 **
4 ** @author Copyright (C) 1999 Alan Bleasby
5 ** @version 1.0
6 ** @modified Dec 28 1999 Alan Bleasby. First version
7 ** @@
8 **
9 ** This library is free software; you can redistribute it and/or
10 ** modify it under the terms of the GNU Library General Public
11 ** License as published by the Free Software Foundation; either
12 ** version 2 of the License, or (at your option) any later version.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ** Library General Public License for more details.
18 **
19 ** You should have received a copy of the GNU Library General Public
20 ** License along with this library; if not, write to the
21 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ** Boston, MA  02111-1307, USA.
23 ********************************************************************/
24 #include "gps.h"
25 #include <stdio.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <stdlib.h>
29 
30 
31 static int32 GPS_Input_Load_String(char* t, int32 n, char* s);
32 static int32 GPS_Input_Load_Strnull(char* t, char* s);
33 static int32 GPS_Input_Read_Line(char* s, FILE* inf);
34 
35 static int32 GPS_Input_Get_D100(GPS_PWay* way, FILE* inf);
36 static int32 GPS_Input_Get_D101(GPS_PWay* way, FILE* inf);
37 static int32 GPS_Input_Get_D102(GPS_PWay* way, FILE* inf);
38 static int32 GPS_Input_Get_D103(GPS_PWay* way, FILE* inf);
39 static int32 GPS_Input_Get_D104(GPS_PWay* way, FILE* inf);
40 static int32 GPS_Input_Get_D105(GPS_PWay* way, FILE* inf);
41 static int32 GPS_Input_Get_D106(GPS_PWay* way, FILE* inf);
42 static int32 GPS_Input_Get_D107(GPS_PWay* way, FILE* inf);
43 static int32 GPS_Input_Get_D108(GPS_PWay* way, FILE* inf);
44 static int32 GPS_Input_Get_D109(GPS_PWay* way, FILE* inf, int protonum);
45 static int32 GPS_Input_Get_D150(GPS_PWay* way, FILE* inf);
46 static int32 GPS_Input_Get_D151(GPS_PWay* way, FILE* inf);
47 static int32 GPS_Input_Get_D152(GPS_PWay* way, FILE* inf);
48 static int32 GPS_Input_Get_D154(GPS_PWay* way, FILE* inf);
49 static int32 GPS_Input_Get_D155(GPS_PWay* way, FILE* inf);
50 
51 static int32 GPS_Input_Get_Track301(GPS_PTrack** trk, FILE* inf, int32 type,
52                                     int32 n);
53 static int32 GPS_Input_Get_D300(GPS_PTrack* trk, FILE* inf, char* s);
54 static int32 GPS_Input_Get_D301(GPS_PTrack* trk, FILE* inf, char* s);
55 
56 static int32 GPS_Input_Get_Route201(GPS_PWay** way, FILE* inf);
57 
58 
59 /* @funcstatic GPS_Input_Load_String ***********************************
60 **
61 ** Load a GPS char type from an input line
62 ** Remove trailing newline
63 **
64 ** @param [w] t [char *] string to load
65 ** @param [r] n [int32] maximum type length
66 ** @param [r] s [char *] source line
67 **
68 ** @return [int32] success
69 ************************************************************************/
GPS_Input_Load_String(char * t,int32 n,char * s)70 static int32 GPS_Input_Load_String(char* t, int32 n, char* s)
71 {
72   char* p;
73   char* q;
74 
75   int32 len;
76   int32 i;
77 
78   gps_errno = INPUT_ERROR;
79 
80   p=s;
81   if (!(p=strchr(p,':'))) {
82     return gps_errno;
83   }
84   ++p;
85   while (*p && (*p==' ' || *p=='\t')) {
86     ++p;
87   }
88   if (!*p) {
89     return 0;
90   }
91 
92   len = strlen(p);
93   q = p+len-1;
94   while (*q==' ' || *q=='\t') {
95     --q;
96   }
97   len = q-p+1;
98 
99   if (q-p+1 > n) {
100     len = n;
101     p[n]='\0';
102   }
103   for (i=0; i<len; ++i) {
104     t[i]=*p++;
105   }
106 
107   return 1;
108 }
109 
110 
111 
112 /* @funcstatic GPS_Input_Load_Strnull **********************************
113 **
114 ** Load a GPS variable length string type from an input line
115 ** Remove trailing newline
116 **
117 ** @param [w] t [char *] string to load
118 ** @param [r] s [char *] source line
119 **
120 ** @return [int32] success
121 ************************************************************************/
GPS_Input_Load_Strnull(char * t,char * s)122 static int32 GPS_Input_Load_Strnull(char* t, char* s)
123 {
124   char* p;
125   char* q;
126 
127   gps_errno = INPUT_ERROR;
128 
129   p=s;
130   if (!(p=strchr(p,':'))) {
131     return gps_errno;
132   }
133   ++p;
134   while (*p && (*p==' ' || *p=='\t')) {
135     ++p;
136   }
137 
138   q = t;
139   while ((*q++ = *p++));
140 
141   return 1;
142 }
143 
144 
145 
146 /* @funcstatic GPS_Input_Read_Line   ************************************
147 **
148 ** Read line from a file ignoring comments and newlines
149 ** Remove trailing newline
150 **
151 ** @param [w] s [char *] string
152 ** @param [r] inf [FILE *] stream
153 **
154 ** @return [int32] success
155 ************************************************************************/
156 
GPS_Input_Read_Line(char * s,FILE * inf)157 static int32 GPS_Input_Read_Line(char* s, FILE* inf)
158 {
159   int32 len;
160 
161   while (fgets(s,GPS_ARB_LEN,inf)) {
162     if (*s=='#' || *s=='\n') {
163       continue;
164     }
165     len = strlen(s);
166     if (s[len-1]=='\n') {
167       s[len-1]='\0';
168       return len-1;
169     }
170     return len;
171   }
172 
173   return 0;
174 }
175 
176 
177 
178 /* @func GPS_Input_Get_Almanac   ****************************************
179 **
180 ** Construct an almanac array from a file
181 **
182 ** @param [w] alm [GPS_PAlmanac **] pointer to almanac array
183 ** @param [r] inf [FILE *] stream
184 **
185 ** @return [int32] number of entries
186 ************************************************************************/
187 
GPS_Input_Get_Almanac(GPS_PAlmanac ** alm,FILE * inf)188 int32 GPS_Input_Get_Almanac(GPS_PAlmanac** alm, FILE* inf)
189 {
190   char s[GPS_ARB_LEN];
191   int32 n;
192   int32 type;
193   int32 i;
194   int32   d;
195   float f;
196   char* p;
197 
198   gps_errno = INPUT_ERROR;
199 
200 
201   if (!GPS_Input_Read_Line(s,inf)) {
202     return gps_errno;
203   }
204 
205   if (sscanf(s,"Almanac %d%d",(int*)&n,(int*)&type)!=2) {
206     return gps_errno;
207   }
208 
209   if (!type) {
210     if (!(*alm = (GPS_PAlmanac*) malloc(32*sizeof(GPS_PAlmanac*)))) {
211       return MEMORY_ERROR;
212     }
213     for (i=0; i<32; ++i) {
214       if (!((*alm)[i] = GPS_Almanac_New())) {
215         return MEMORY_ERROR;
216       }
217 
218       (*alm)[i]->svid = i;
219       (*alm)[i]->wn = -1;
220     }
221   } else {
222     if (!(*alm = (GPS_PAlmanac*) malloc(n*sizeof(GPS_PAlmanac*)))) {
223       return MEMORY_ERROR;
224     }
225     for (i=0; i<32; ++i)
226       if (!((*alm)[i] = GPS_Almanac_New())) {
227         return MEMORY_ERROR;
228       }
229   }
230 
231   for (i=0; i<n; ++i) {
232     if (!GPS_Input_Read_Line(s,inf)) {
233       if (!type) {
234         break;
235       } else {
236         return gps_error;
237       }
238     }
239 
240     p=strchr(s,':');
241     if (sscanf(p+1,"%d",(int*)&d)!=1) {
242       return gps_errno;
243     }
244     --d;
245 
246     if (!type)
247       while ((*alm)[i]->svid!=d) {
248         ++i;
249       }
250     (*alm)[i]->svid=d;
251 
252     if (!GPS_Input_Read_Line(s,inf)) {
253       return gps_errno;
254     }
255     p=strchr(s,':');
256     if (sscanf(p+1,"%d",(int*)&d)!=1) {
257       return gps_errno;
258     }
259     (*alm)[i]->wn = d;
260 
261     if (!GPS_Input_Read_Line(s,inf)) {
262       return gps_errno;
263     }
264     p=strchr(s,':');
265     if (sscanf(p+1,"%f",&f)!=1) {
266       return gps_errno;
267     }
268     (*alm)[i]->toa = f;
269 
270     if (!GPS_Input_Read_Line(s,inf)) {
271       return gps_errno;
272     }
273     p=strchr(s,':');
274     if (sscanf(p+1,"%f",&f)!=1) {
275       return gps_errno;
276     }
277     (*alm)[i]->af0 = f;
278 
279     if (!GPS_Input_Read_Line(s,inf)) {
280       return gps_errno;
281     }
282     p=strchr(s,':');
283     if (sscanf(p+1,"%f",&f)!=1) {
284       return gps_errno;
285     }
286     (*alm)[i]->af1 = f;
287 
288     if (!GPS_Input_Read_Line(s,inf)) {
289       return gps_errno;
290     }
291     p=strchr(s,':');
292     if (sscanf(p+1,"%f",&f)!=1) {
293       return gps_errno;
294     }
295     (*alm)[i]->e = f;
296 
297     if (!GPS_Input_Read_Line(s,inf)) {
298       return gps_errno;
299     }
300     p=strchr(s,':');
301     if (sscanf(p+1,"%f",&f)!=1) {
302       return gps_errno;
303     }
304     (*alm)[i]->sqrta = f;
305 
306     if (!GPS_Input_Read_Line(s,inf)) {
307       return gps_errno;
308     }
309     p=strchr(s,':');
310     if (sscanf(p+1,"%f",&f)!=1) {
311       return gps_errno;
312     }
313     (*alm)[i]->m0 = f;
314 
315     if (!GPS_Input_Read_Line(s,inf)) {
316       return gps_errno;
317     }
318     p=strchr(s,':');
319     if (sscanf(p+1,"%f",&f)!=1) {
320       return gps_errno;
321     }
322     (*alm)[i]->w = f;
323 
324     if (!GPS_Input_Read_Line(s,inf)) {
325       return gps_errno;
326     }
327     p=strchr(s,':');
328     if (sscanf(p+1,"%f",&f)!=1) {
329       return gps_errno;
330     }
331     (*alm)[i]->omg0 = f;
332 
333     if (!GPS_Input_Read_Line(s,inf)) {
334       return gps_errno;
335     }
336     p=strchr(s,':');
337     if (sscanf(p+1,"%f",&f)!=1) {
338       return gps_errno;
339     }
340     (*alm)[i]->odot = f;
341 
342     if (!GPS_Input_Read_Line(s,inf)) {
343       return gps_errno;
344     }
345     p=strchr(s,':');
346     if (sscanf(p+1,"%f",&f)!=1) {
347       return gps_errno;
348     }
349     (*alm)[i]->i = f;
350 
351     if (!GPS_Input_Read_Line(s,inf)) {
352       return gps_errno;
353     }
354     p=strchr(s,':');
355     if (sscanf(p+1,"%d",(int*)&d)!=1) {
356       return gps_errno;
357     }
358     (*alm)[i]->hlth=d;
359   }
360 
361   if (!type) {
362     n = 32;
363   }
364 
365   return n;
366 }
367 
368 
369 
370 /* @func GPS_Input_Get_Waypoint *****************************************
371 **
372 ** Construct a waypoint array from a file
373 **
374 ** @param [w] way [GPS_PWay **] pointer to waypoint array
375 ** @param [r] inf [FILE *] stream
376 **
377 ** @return [int32] number of entries
378 ************************************************************************/
379 
GPS_Input_Get_Waypoint(GPS_PWay ** way,FILE * inf)380 int32 GPS_Input_Get_Waypoint(GPS_PWay** way, FILE* inf)
381 {
382   char s[GPS_ARB_LEN];
383   int32 n;
384   int32 type;
385   int32 i;
386   long pos;
387   int32 ret;
388 
389   gps_errno = INPUT_ERROR;
390 
391   if (!GPS_Input_Read_Line(s,inf)) {
392     return gps_errno;
393   }
394   if (sscanf(s,"Waypoints Type: %d",(int*)&type)!=1) {
395     return gps_errno;
396   }
397 
398   if (!GPS_Input_Read_Line(s,inf)) {
399     return gps_errno;
400   }
401   if (strncmp(s,"Start",5)) {
402     return gps_errno;
403   }
404 
405   pos = ftell(inf);
406   n = 0;
407   while (strncmp(s,"End",3)) {
408     if (!GPS_Input_Read_Line(s,inf)) {
409       return gps_errno;
410     }
411     if (strstr(s,"Latitude")) {
412       ++n;
413     }
414   }
415   fseek(inf,pos,0);
416 
417   if (!(*way=(GPS_PWay*)malloc(n*sizeof(GPS_PWay*)))) {
418     return MEMORY_ERROR;
419   }
420   for (i=0; i<n; ++i) {
421     if (!((*way)[i]=GPS_Way_New())) {
422       return MEMORY_ERROR;
423     }
424     (*way)[i]->prot = type;
425   }
426 
427 
428   for (i=0; i<n; ++i) {
429     switch (type) {
430     case 100:
431       ret = GPS_Input_Get_D100(&((*way)[i]),inf);
432       if (ret<0) {
433         return gps_errno;
434       }
435       break;
436     case 101:
437       ret = GPS_Input_Get_D101(&((*way)[i]),inf);
438       if (ret<0) {
439         return gps_errno;
440       }
441       break;
442     case 102:
443       ret = GPS_Input_Get_D102(&((*way)[i]),inf);
444       if (ret<0) {
445         return gps_errno;
446       }
447       break;
448     case 103:
449       ret = GPS_Input_Get_D103(&((*way)[i]),inf);
450       if (ret<0) {
451         return gps_errno;
452       }
453       break;
454     case 104:
455       ret = GPS_Input_Get_D104(&((*way)[i]),inf);
456       if (ret<0) {
457         return gps_errno;
458       }
459       break;
460     case 105:
461       ret = GPS_Input_Get_D105(&((*way)[i]),inf);
462       if (ret<0) {
463         return gps_errno;
464       }
465       break;
466     case 106:
467       ret = GPS_Input_Get_D106(&((*way)[i]),inf);
468       if (ret<0) {
469         return gps_errno;
470       }
471       break;
472     case 107:
473       ret = GPS_Input_Get_D107(&((*way)[i]),inf);
474       if (ret<0) {
475         return gps_errno;
476       }
477       break;
478     case 108:
479       ret = GPS_Input_Get_D108(&((*way)[i]),inf);
480       if (ret<0) {
481         return gps_errno;
482       }
483       break;
484     case 109:
485       ret = GPS_Input_Get_D109(&((*way)[i]),inf, 109);
486       if (ret<0) {
487         return gps_errno;
488       }
489       break;
490     case 110:
491       ret = GPS_Input_Get_D109(&((*way)[i]),inf, 110);
492       if (ret<0) {
493         return gps_errno;
494       }
495       break;
496     case 150:
497       ret = GPS_Input_Get_D150(&((*way)[i]),inf);
498       if (ret<0) {
499         return gps_errno;
500       }
501       break;
502     case 151:
503       ret = GPS_Input_Get_D151(&((*way)[i]),inf);
504       if (ret<0) {
505         return gps_errno;
506       }
507       break;
508     case 152:
509       ret = GPS_Input_Get_D152(&((*way)[i]),inf);
510       if (ret<0) {
511         return gps_errno;
512       }
513       break;
514     case 154:
515       ret = GPS_Input_Get_D154(&((*way)[i]),inf);
516       if (ret<0) {
517         return gps_errno;
518       }
519       break;
520     case 155:
521       ret = GPS_Input_Get_D155(&((*way)[i]),inf);
522       if (ret<0) {
523         return gps_errno;
524       }
525       break;
526     default:
527       GPS_Error("Input_Get_Waypoints: Unknown protocol");
528       return PROTOCOL_ERROR;
529     }
530   }
531 
532   return n;
533 }
534 
535 
536 
537 /* @func GPS_Input_Get_Proximity   *************************************
538 **
539 ** Construct a proximity waypoint array from a file
540 **
541 ** @param [w] way [GPS_PWay **] pointer to proximity waypoint array
542 ** @param [r] inf [FILE *] stream
543 **
544 ** @return [int32] number of entries
545 ************************************************************************/
546 
GPS_Input_Get_Proximity(GPS_PWay ** way,FILE * inf)547 int32 GPS_Input_Get_Proximity(GPS_PWay** way, FILE* inf)
548 {
549   char s[GPS_ARB_LEN];
550   int32 n;
551   int32 type;
552   int32 i;
553   long pos;
554   int32 ret;
555   double f;
556   char* p;
557 
558   gps_errno = INPUT_ERROR;
559 
560   if (!GPS_Input_Read_Line(s,inf)) {
561     return gps_errno;
562   }
563   if (sscanf(s,"Waypoints Type: %d",(int*)&type)!=1) {
564     return gps_errno;
565   }
566 
567   if (!GPS_Input_Read_Line(s,inf)) {
568     return gps_errno;
569   }
570   if (strncmp(s,"Start",5)) {
571     return gps_errno;
572   }
573 
574   pos = ftell(inf);
575   n = 0;
576   while (strncmp(s,"End",3)) {
577     if (!GPS_Input_Read_Line(s,inf)) {
578       return gps_errno;
579     }
580     if (strstr(s,"Latitude")) {
581       ++n;
582     }
583   }
584   fseek(inf,pos,0);
585 
586   if (!(*way=(GPS_PWay*)malloc(n*sizeof(GPS_PWay*)))) {
587     return MEMORY_ERROR;
588   }
589   for (i=0; i<n; ++i) {
590     if (!((*way)[i]=GPS_Way_New())) {
591       return MEMORY_ERROR;
592     }
593     (*way)[i]->prot = type;
594   }
595 
596   for (i=0; i<n; ++i) {
597     switch (type) {
598     case 400:
599       ret = GPS_Input_Get_D100(&((*way)[i]),inf);
600       if (ret<0) {
601         return gps_errno;
602       }
603       break;
604     case 101:
605       ret = GPS_Input_Get_D101(&((*way)[i]),inf);
606       if (ret<0) {
607         return gps_errno;
608       }
609       break;
610     case 102:
611       ret = GPS_Input_Get_D102(&((*way)[i]),inf);
612       if (ret<0) {
613         return gps_errno;
614       }
615       break;
616     case 403:
617       ret = GPS_Input_Get_D103(&((*way)[i]),inf);
618       if (ret<0) {
619         return gps_errno;
620       }
621       break;
622     case 104:
623       ret = GPS_Input_Get_D104(&((*way)[i]),inf);
624       if (ret<0) {
625         return gps_errno;
626       }
627       break;
628     case 105:
629       ret = GPS_Input_Get_D105(&((*way)[i]),inf);
630       if (ret<0) {
631         return gps_errno;
632       }
633       break;
634     case 106:
635       ret = GPS_Input_Get_D106(&((*way)[i]),inf);
636       if (ret<0) {
637         return gps_errno;
638       }
639       break;
640     case 107:
641       ret = GPS_Input_Get_D107(&((*way)[i]),inf);
642       if (ret<0) {
643         return gps_errno;
644       }
645       break;
646     case 108:
647       ret = GPS_Input_Get_D108(&((*way)[i]),inf);
648       if (ret<0) {
649         return gps_errno;
650       }
651       break;
652     case 109:
653       ret = GPS_Input_Get_D109(&((*way)[i]),inf, 109);
654       if (ret<0) {
655         return gps_errno;
656       }
657       break;
658     case 110:
659       ret = GPS_Input_Get_D109(&((*way)[i]),inf, 110);
660       if (ret<0) {
661         return gps_errno;
662       }
663       break;
664     case 450:
665       ret = GPS_Input_Get_D150(&((*way)[i]),inf);
666       if (ret<0) {
667         return gps_errno;
668       }
669       break;
670     case 151:
671       ret = GPS_Input_Get_D151(&((*way)[i]),inf);
672       if (ret<0) {
673         return gps_errno;
674       }
675       break;
676     case 152:
677       ret = GPS_Input_Get_D152(&((*way)[i]),inf);
678       if (ret<0) {
679         return gps_errno;
680       }
681       break;
682     case 154:
683       ret = GPS_Input_Get_D154(&((*way)[i]),inf);
684       if (ret<0) {
685         return gps_errno;
686       }
687       break;
688     case 155:
689       ret = GPS_Input_Get_D155(&((*way)[i]),inf);
690       if (ret<0) {
691         return gps_errno;
692       }
693       break;
694     default:
695       GPS_Error("Input_Get_Waypoints: Unknown protocol");
696       return PROTOCOL_ERROR;
697     }
698 
699     if (!GPS_Input_Read_Line(s,inf)) {
700       return gps_errno;
701     }
702     p=strchr(s,':');
703     if (sscanf(p+1,"%lf",&f)!=1) {
704       return gps_errno;
705     }
706     (*way)[i]->dst = f;
707   }
708 
709   return n;
710 }
711 
712 
713 
714 /* @funcstatic GPS_Input_Get_D100   ************************************
715 **
716 ** Get a D100 Entry
717 **
718 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
719 ** @param [r] inf [FILE *] stream
720 **
721 ** @return [int32] number of entries
722 ************************************************************************/
GPS_Input_Get_D100(GPS_PWay * way,FILE * inf)723 static int32 GPS_Input_Get_D100(GPS_PWay* way, FILE* inf)
724 {
725   char s[GPS_ARB_LEN];
726   char* p;
727 
728   double f;
729 
730   if (!GPS_Input_Read_Line(s,inf)) {
731     return gps_errno;
732   }
733   GPS_Input_Load_String((*way)->ident,6,s);
734 
735   if (!GPS_Input_Read_Line(s,inf)) {
736     return gps_errno;
737   }
738   p=strchr(s,':');
739   if (sscanf(p+1,"%lf",&f)!=1) {
740     return gps_errno;
741   }
742   (*way)->lat = f;
743 
744   if (!GPS_Input_Read_Line(s,inf)) {
745     return gps_errno;
746   }
747   p=strchr(s,':');
748   if (sscanf(p+1,"%lf",&f)!=1) {
749     return gps_errno;
750   }
751   (*way)->lon = f;
752 
753   if (!GPS_Input_Read_Line(s,inf)) {
754     return gps_errno;
755   }
756   GPS_Input_Load_String((*way)->cmnt,40,s);
757 
758   return 1;
759 }
760 
761 
762 
763 /* @funcstatic GPS_Input_Get_D101   ************************************
764 **
765 ** Get a D101 Entry
766 **
767 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
768 ** @param [r] inf [FILE *] stream
769 **
770 ** @return [int32] number of entries
771 ************************************************************************/
GPS_Input_Get_D101(GPS_PWay * way,FILE * inf)772 static int32 GPS_Input_Get_D101(GPS_PWay* way, FILE* inf)
773 {
774   char s[GPS_ARB_LEN];
775   char* p;
776 
777   double f;
778   int32 d;
779 
780 
781   if (!GPS_Input_Read_Line(s,inf)) {
782     return gps_errno;
783   }
784   GPS_Input_Load_String((*way)->ident,6,s);
785 
786   if (!GPS_Input_Read_Line(s,inf)) {
787     return gps_errno;
788   }
789   p=strchr(s,':');
790   if (sscanf(p+1,"%lf",&f)!=1) {
791     return gps_errno;
792   }
793   (*way)->lat = f;
794 
795   if (!GPS_Input_Read_Line(s,inf)) {
796     return gps_errno;
797   }
798   p=strchr(s,':');
799   if (sscanf(p+1,"%lf",&f)!=1) {
800     return gps_errno;
801   }
802   (*way)->lon = f;
803 
804   if (!GPS_Input_Read_Line(s,inf)) {
805     return gps_errno;
806   }
807   GPS_Input_Load_String((*way)->cmnt,40,s);
808 
809   if (!GPS_Input_Read_Line(s,inf)) {
810     return gps_errno;
811   }
812   p=strchr(s,':');
813   if (sscanf(p+1,"%d",(int*)&d)!=1) {
814     return gps_errno;
815   }
816   (*way)->smbl = d;
817 
818   return 1;
819 }
820 
821 
822 
823 /* @funcstatic GPS_Input_Get_D102   ************************************
824 **
825 ** Get a D102 Entry
826 **
827 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
828 ** @param [r] inf [FILE *] stream
829 **
830 ** @return [int32] number of entries
831 ************************************************************************/
GPS_Input_Get_D102(GPS_PWay * way,FILE * inf)832 static int32 GPS_Input_Get_D102(GPS_PWay* way, FILE* inf)
833 {
834   return GPS_Input_Get_D101(way,inf);
835 }
836 
837 
838 
839 /* @funcstatic GPS_Input_Get_D103   ************************************
840 **
841 ** Get a D103 Entry
842 **
843 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
844 ** @param [r] inf [FILE *] stream
845 **
846 ** @return [int32] number of entries
847 ************************************************************************/
GPS_Input_Get_D103(GPS_PWay * way,FILE * inf)848 static int32 GPS_Input_Get_D103(GPS_PWay* way, FILE* inf)
849 {
850   char s[GPS_ARB_LEN];
851   char* p;
852 
853   double f;
854   int32 d;
855 
856 
857   if (!GPS_Input_Read_Line(s,inf)) {
858     return gps_errno;
859   }
860   GPS_Input_Load_String((*way)->ident,6,s);
861 
862   if (!GPS_Input_Read_Line(s,inf)) {
863     return gps_errno;
864   }
865   p=strchr(s,':');
866   if (sscanf(p+1,"%lf",&f)!=1) {
867     return gps_errno;
868   }
869   (*way)->lat = f;
870 
871   if (!GPS_Input_Read_Line(s,inf)) {
872     return gps_errno;
873   }
874   p=strchr(s,':');
875   if (sscanf(p+1,"%lf",&f)!=1) {
876     return gps_errno;
877   }
878   (*way)->lon = f;
879 
880   if (!GPS_Input_Read_Line(s,inf)) {
881     return gps_errno;
882   }
883   GPS_Input_Load_String((*way)->cmnt,40,s);
884 
885   if (!GPS_Input_Read_Line(s,inf)) {
886     return gps_errno;
887   }
888   p=strchr(s,':');
889   if (sscanf(p+1,"%d",(int*)&d)!=1) {
890     return gps_errno;
891   }
892   (*way)->smbl = d;
893 
894   if (!GPS_Input_Read_Line(s,inf)) {
895     return gps_errno;
896   }
897   p=strchr(s,':');
898   if (sscanf(p+1,"%d",(int*)&d)!=1) {
899     return gps_errno;
900   }
901   (*way)->dspl = d;
902 
903   return 1;
904 }
905 
906 
907 
908 /* @funcstatic GPS_Input_Get_D104   ************************************
909 **
910 ** Get a D104 Entry
911 **
912 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
913 ** @param [r] inf [FILE *] stream
914 **
915 ** @return [int32] number of entries
916 ************************************************************************/
GPS_Input_Get_D104(GPS_PWay * way,FILE * inf)917 static int32 GPS_Input_Get_D104(GPS_PWay* way, FILE* inf)
918 {
919   return GPS_Input_Get_D103(way,inf);
920 }
921 
922 
923 
924 /* @funcstatic GPS_Input_Get_D105   ************************************
925 **
926 ** Get a D105 Entry
927 **
928 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
929 ** @param [r] inf [FILE *] stream
930 **
931 ** @return [int32] number of entries
932 ************************************************************************/
GPS_Input_Get_D105(GPS_PWay * way,FILE * inf)933 static int32 GPS_Input_Get_D105(GPS_PWay* way, FILE* inf)
934 {
935   char s[GPS_ARB_LEN];
936   char* p;
937 
938   double f;
939   int32 d;
940 
941 
942   if (!GPS_Input_Read_Line(s,inf)) {
943     return gps_errno;
944   }
945   p=strchr(s,':');
946   if (sscanf(p+1,"%lf",&f)!=1) {
947     return gps_errno;
948   }
949   (*way)->lat = f;
950 
951   if (!GPS_Input_Read_Line(s,inf)) {
952     return gps_errno;
953   }
954   p=strchr(s,':');
955   if (sscanf(p+1,"%lf",&f)!=1) {
956     return gps_errno;
957   }
958   (*way)->lon = f;
959 
960   if (!GPS_Input_Read_Line(s,inf)) {
961     return gps_errno;
962   }
963   p=strchr(s,':');
964   if (sscanf(p+1,"%d",(int*)&d)!=1) {
965     return gps_errno;
966   }
967   (*way)->smbl = d;
968 
969   if (!GPS_Input_Read_Line(s,inf)) {
970     return gps_errno;
971   }
972   GPS_Input_Load_Strnull((*way)->wpt_ident,s);
973 
974   return 1;
975 }
976 
977 
978 
979 /* @funcstatic GPS_Input_Get_D106   ************************************
980 **
981 ** Get a D106 Entry
982 **
983 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
984 ** @param [r] inf [FILE *] stream
985 **
986 ** @return [int32] number of entries
987 ************************************************************************/
GPS_Input_Get_D106(GPS_PWay * way,FILE * inf)988 static int32 GPS_Input_Get_D106(GPS_PWay* way, FILE* inf)
989 {
990   char s[GPS_ARB_LEN];
991   char* p;
992 
993   double f;
994   int32 d;
995 
996   if (!GPS_Input_Read_Line(s,inf)) {
997     return gps_errno;
998   }
999   p=strchr(s,':');
1000   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1001     return gps_errno;
1002   }
1003   (*way)->wpt_class = d;
1004 
1005   if (!GPS_Input_Read_Line(s,inf)) {
1006     return gps_errno;
1007   }
1008   GPS_Input_Load_String((char*)(*way)->subclass,13,s);
1009 
1010 
1011   if (!GPS_Input_Read_Line(s,inf)) {
1012     return gps_errno;
1013   }
1014   GPS_Input_Load_String((*way)->ident,6,s);
1015 
1016   if (!GPS_Input_Read_Line(s,inf)) {
1017     return gps_errno;
1018   }
1019   p=strchr(s,':');
1020   if (sscanf(p+1,"%lf",&f)!=1) {
1021     return gps_errno;
1022   }
1023   (*way)->lat = f;
1024 
1025   if (!GPS_Input_Read_Line(s,inf)) {
1026     return gps_errno;
1027   }
1028   p=strchr(s,':');
1029   if (sscanf(p+1,"%lf",&f)!=1) {
1030     return gps_errno;
1031   }
1032   (*way)->lon = f;
1033 
1034   if (!GPS_Input_Read_Line(s,inf)) {
1035     return gps_errno;
1036   }
1037   p=strchr(s,':');
1038   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1039     return gps_errno;
1040   }
1041   (*way)->smbl = d;
1042 
1043   if (!GPS_Input_Read_Line(s,inf)) {
1044     return gps_errno;
1045   }
1046   GPS_Input_Load_Strnull((*way)->wpt_ident,s);
1047 
1048   if (!GPS_Input_Read_Line(s,inf)) {
1049     return gps_errno;
1050   }
1051   GPS_Input_Load_Strnull((*way)->lnk_ident,s);
1052 
1053   return 1;
1054 }
1055 
1056 
1057 
1058 /* @funcstatic GPS_Input_Get_D107   ************************************
1059 **
1060 ** Get a D107 Entry
1061 **
1062 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1063 ** @param [r] inf [FILE *] stream
1064 **
1065 ** @return [int32] number of entries
1066 ************************************************************************/
GPS_Input_Get_D107(GPS_PWay * way,FILE * inf)1067 static int32 GPS_Input_Get_D107(GPS_PWay* way, FILE* inf)
1068 {
1069   char s[GPS_ARB_LEN];
1070   char* p;
1071 
1072   int32 d;
1073   int32 ret;
1074 
1075   if ((ret=GPS_Input_Get_D103(way,inf))<0) {
1076     return ret;
1077   }
1078 
1079   if (!GPS_Input_Read_Line(s,inf)) {
1080     return gps_errno;
1081   }
1082   p=strchr(s,':');
1083   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1084     return gps_errno;
1085   }
1086   (*way)->colour = d;
1087 
1088   return 1;
1089 }
1090 
1091 
1092 
1093 /* @funcstatic GPS_Input_Get_D108   ************************************
1094 **
1095 ** Get a D108 Entry
1096 **
1097 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1098 ** @param [r] inf [FILE *] stream
1099 **
1100 ** @return [int32] number of entries
1101 ************************************************************************/
GPS_Input_Get_D108(GPS_PWay * way,FILE * inf)1102 static int32 GPS_Input_Get_D108(GPS_PWay* way, FILE* inf)
1103 {
1104   char s[GPS_ARB_LEN];
1105   char* p;
1106   double f;
1107   int32 d;
1108   int32 xc;
1109 
1110 
1111   if (!GPS_Input_Read_Line(s,inf)) {
1112     return gps_errno;
1113   }
1114   GPS_Input_Load_Strnull((*way)->ident,s);
1115 
1116   if (!GPS_Input_Read_Line(s,inf)) {
1117     return gps_errno;
1118   }
1119   p=strchr(s,':');
1120   if (sscanf(p+1,"%lf",&f)!=1) {
1121     return gps_errno;
1122   }
1123   (*way)->lat = f;
1124 
1125   if (!GPS_Input_Read_Line(s,inf)) {
1126     return gps_errno;
1127   }
1128   p=strchr(s,':');
1129   if (sscanf(p+1,"%lf",&f)!=1) {
1130     return gps_errno;
1131   }
1132   (*way)->lon = f;
1133 
1134   if (!GPS_Input_Read_Line(s,inf)) {
1135     return gps_errno;
1136   }
1137   p=strchr(s,':');
1138   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1139     return gps_errno;
1140   }
1141   (*way)->colour = d;
1142 
1143   if (!GPS_Input_Read_Line(s,inf)) {
1144     return gps_errno;
1145   }
1146   p=strchr(s,':');
1147   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1148     return gps_errno;
1149   }
1150   (*way)->dspl = d;
1151 
1152   if (!GPS_Input_Read_Line(s,inf)) {
1153     return gps_errno;
1154   }
1155   p=strchr(s,':');
1156   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1157     return gps_errno;
1158   }
1159   (*way)->smbl = d;
1160 
1161   if (!GPS_Input_Read_Line(s,inf)) {
1162     return gps_errno;
1163   }
1164   p=strchr(s,':');
1165   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1166     return gps_errno;
1167   }
1168   (*way)->alt = d;
1169 
1170   if (!GPS_Input_Read_Line(s,inf)) {
1171     return gps_errno;
1172   }
1173   p=strchr(s,':');
1174   if (sscanf(p+1,"%lf",&f)!=1) {
1175     return gps_errno;
1176   }
1177   (*way)->dpth = f;
1178 
1179   if (!GPS_Input_Read_Line(s,inf)) {
1180     return gps_errno;
1181   }
1182   GPS_Input_Load_String((*way)->state,2,s);
1183 
1184   if (!GPS_Input_Read_Line(s,inf)) {
1185     return gps_errno;
1186   }
1187   GPS_Input_Load_String((*way)->cc,2,s);
1188 
1189   if (!GPS_Input_Read_Line(s,inf)) {
1190     return gps_errno;
1191   }
1192   p=strchr(s,':');
1193   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1194     return gps_errno;
1195   }
1196   (*way)->wpt_class = d;
1197   xc = d;
1198 
1199   if (xc>=0x80 && xc<=0x85) {
1200     if (!GPS_Input_Read_Line(s,inf)) {
1201       return gps_errno;
1202     }
1203     GPS_Input_Load_String((char*)(*way)->subclass,18,s);
1204   } else {
1205     GPS_Util_Put_Short((*way)->subclass,0);
1206     GPS_Util_Put_Int((*way)->subclass+2,0);
1207     GPS_Util_Put_Uint((*way)->subclass+6,0xffffffff);
1208     GPS_Util_Put_Uint((*way)->subclass+10,0xffffffff);
1209     GPS_Util_Put_Uint((*way)->subclass+14,0xffffffff);
1210   }
1211 
1212   if (!xc) {
1213     if (!GPS_Input_Read_Line(s,inf)) {
1214       return gps_errno;
1215     }
1216     GPS_Input_Load_Strnull((*way)->cmnt,s);
1217   }
1218 
1219   if (xc>=0x40 && xc<=0x46) {
1220     if (!GPS_Input_Read_Line(s,inf)) {
1221       return gps_errno;
1222     }
1223     GPS_Input_Load_Strnull((*way)->facility,s);
1224     if (!GPS_Input_Read_Line(s,inf)) {
1225       return gps_errno;
1226     }
1227     GPS_Input_Load_Strnull((*way)->city,s);
1228   }
1229 
1230   if (xc==0x83) {
1231     if (!GPS_Input_Read_Line(s,inf)) {
1232       return gps_errno;
1233     }
1234     GPS_Input_Load_Strnull((*way)->addr,s);
1235   }
1236 
1237   if (xc==0x82) {
1238     if (!GPS_Input_Read_Line(s,inf)) {
1239       return gps_errno;
1240     }
1241     GPS_Input_Load_Strnull((*way)->cross_road,s);
1242   }
1243 
1244   return 1;
1245 }
1246 
1247 
1248 
1249 /* @funcstatic GPS_Input_Get_D109   ************************************
1250 **
1251 ** Get a D109 Entry
1252 **
1253 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1254 ** @param [r] inf [FILE *] stream
1255 **
1256 ** @return [int32] number of entries
1257 ** D109's and D110's are so similar, we handle both with the same function.
1258 ************************************************************************/
GPS_Input_Get_D109(GPS_PWay * way,FILE * inf,int protonum)1259 static int32 GPS_Input_Get_D109(GPS_PWay* way, FILE* inf, int protonum)
1260 {
1261   char s[GPS_ARB_LEN];
1262   char* p;
1263   double f;
1264   int32 d;
1265   int32 xc;
1266 
1267 
1268   if (!GPS_Input_Read_Line(s,inf)) {
1269     return gps_errno;
1270   }
1271   GPS_Input_Load_Strnull((*way)->ident,s);
1272 
1273   if (!GPS_Input_Read_Line(s,inf)) {
1274     return gps_errno;
1275   }
1276   p=strchr(s,':');
1277   if (sscanf(p+1,"%lf",&f)!=1) {
1278     return gps_errno;
1279   }
1280   (*way)->lat = f;
1281 
1282   if (!GPS_Input_Read_Line(s,inf)) {
1283     return gps_errno;
1284   }
1285   p=strchr(s,':');
1286   if (sscanf(p+1,"%lf",&f)!=1) {
1287     return gps_errno;
1288   }
1289   (*way)->lon = f;
1290 
1291   if (!GPS_Input_Read_Line(s,inf)) {
1292     return gps_errno;
1293   }
1294   p=strchr(s,':');
1295   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1296     return gps_errno;
1297   }
1298   (*way)->colour = d;
1299 
1300   if (!GPS_Input_Read_Line(s,inf)) {
1301     return gps_errno;
1302   }
1303   p=strchr(s,':');
1304   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1305     return gps_errno;
1306   }
1307   (*way)->dspl = d;
1308 
1309   if (!GPS_Input_Read_Line(s,inf)) {
1310     return gps_errno;
1311   }
1312   p=strchr(s,':');
1313   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1314     return gps_errno;
1315   }
1316   (*way)->smbl = d;
1317 
1318   if (!GPS_Input_Read_Line(s,inf)) {
1319     return gps_errno;
1320   }
1321   p=strchr(s,':');
1322   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1323     return gps_errno;
1324   }
1325   (*way)->alt = d;
1326 
1327   if (!GPS_Input_Read_Line(s,inf)) {
1328     return gps_errno;
1329   }
1330   p=strchr(s,':');
1331   if (sscanf(p+1,"%lf",&f)!=1) {
1332     return gps_errno;
1333   }
1334   (*way)->dpth = f;
1335 
1336   if (!GPS_Input_Read_Line(s,inf)) {
1337     return gps_errno;
1338   }
1339   GPS_Input_Load_String((*way)->state,2,s);
1340 
1341   if (!GPS_Input_Read_Line(s,inf)) {
1342     return gps_errno;
1343   }
1344   GPS_Input_Load_String((*way)->cc,2,s);
1345 
1346   if (!GPS_Input_Read_Line(s,inf)) {
1347     return gps_errno;
1348   }
1349   p=strchr(s,':');
1350   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1351     return gps_errno;
1352   }
1353   (*way)->wpt_class = d;
1354   xc = d;
1355 
1356   if (xc>=0x80 && xc<=0x85) {
1357     if (!GPS_Input_Read_Line(s,inf)) {
1358       return gps_errno;
1359     }
1360     GPS_Input_Load_String((char*)(*way)->subclass,18,s);
1361   } else {
1362     GPS_Util_Put_Short((*way)->subclass,0);
1363     GPS_Util_Put_Int((*way)->subclass+2,0);
1364     GPS_Util_Put_Uint((*way)->subclass+6,0xffffffff);
1365     GPS_Util_Put_Uint((*way)->subclass+10,0xffffffff);
1366     GPS_Util_Put_Uint((*way)->subclass+14,0xffffffff);
1367   }
1368 
1369   if (!xc) {
1370     if (!GPS_Input_Read_Line(s,inf)) {
1371       return gps_errno;
1372     }
1373     GPS_Input_Load_Strnull((*way)->cmnt,s);
1374   }
1375 
1376   if (xc>=0x40 && xc<=0x46) {
1377     if (!GPS_Input_Read_Line(s,inf)) {
1378       return gps_errno;
1379     }
1380     GPS_Input_Load_Strnull((*way)->facility,s);
1381     if (!GPS_Input_Read_Line(s,inf)) {
1382       return gps_errno;
1383     }
1384     GPS_Input_Load_Strnull((*way)->city,s);
1385   }
1386 
1387   if (xc==0x83) {
1388     if (!GPS_Input_Read_Line(s,inf)) {
1389       return gps_errno;
1390     }
1391     GPS_Input_Load_Strnull((*way)->addr,s);
1392   }
1393 
1394   if (xc==0x82) {
1395     if (!GPS_Input_Read_Line(s,inf)) {
1396       return gps_errno;
1397     }
1398     GPS_Input_Load_Strnull((*way)->cross_road,s);
1399   }
1400 
1401   return 1;
1402 }
1403 
1404 
1405 /* @funcstatic GPS_Input_Get_D150   ************************************
1406 **
1407 ** Get a D150 Entry
1408 **
1409 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1410 ** @param [r] inf [FILE *] stream
1411 **
1412 ** @return [int32] number of entries
1413 ************************************************************************/
GPS_Input_Get_D150(GPS_PWay * way,FILE * inf)1414 static int32 GPS_Input_Get_D150(GPS_PWay* way, FILE* inf)
1415 {
1416   char s[GPS_ARB_LEN];
1417   char* p;
1418 
1419   double f;
1420   int32 d;
1421   int32 cl=0;
1422 
1423 
1424   if (!GPS_Input_Read_Line(s,inf)) {
1425     return gps_errno;
1426   }
1427   GPS_Input_Load_String((*way)->ident,6,s);
1428 
1429   if (!GPS_Input_Read_Line(s,inf)) {
1430     return gps_errno;
1431   }
1432   p=strchr(s,':');
1433   if (sscanf(p+1,"%lf",&f)!=1) {
1434     return gps_errno;
1435   }
1436   (*way)->lat = f;
1437 
1438   if (!GPS_Input_Read_Line(s,inf)) {
1439     return gps_errno;
1440   }
1441   p=strchr(s,':');
1442   if (sscanf(p+1,"%lf",&f)!=1) {
1443     return gps_errno;
1444   }
1445   (*way)->lon = f;
1446 
1447   if (!GPS_Input_Read_Line(s,inf)) {
1448     return gps_errno;
1449   }
1450   GPS_Input_Load_String((*way)->cmnt,40,s);
1451 
1452   if (!GPS_Input_Read_Line(s,inf)) {
1453     return gps_errno;
1454   }
1455   p=strchr(s,':');
1456   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1457     return gps_errno;
1458   }
1459   (*way)->wpt_class = cl = d;
1460 
1461   if (cl != 4) {
1462     if (!GPS_Input_Read_Line(s,inf)) {
1463       return gps_errno;
1464     }
1465     GPS_Input_Load_String((*way)->cc,2,s);
1466 
1467     if (!GPS_Input_Read_Line(s,inf)) {
1468       return gps_errno;
1469     }
1470     GPS_Input_Load_String((*way)->city,24,s);
1471 
1472     if (!GPS_Input_Read_Line(s,inf)) {
1473       return gps_errno;
1474     }
1475     GPS_Input_Load_String((*way)->state,2,s);
1476 
1477     if (!GPS_Input_Read_Line(s,inf)) {
1478       return gps_errno;
1479     }
1480     GPS_Input_Load_String((*way)->name,30,s);
1481   }
1482 
1483   if (!cl) {
1484     if (!GPS_Input_Read_Line(s,inf)) {
1485       return gps_errno;
1486     }
1487     p=strchr(s,':');
1488     if (sscanf(p+1,"%d",(int*)&d)!=1) {
1489       return gps_errno;
1490     }
1491     (*way)->alt = d;
1492   }
1493 
1494   return 1;
1495 }
1496 
1497 
1498 
1499 /* @funcstatic GPS_Input_Get_D151   ************************************
1500 **
1501 ** Get a D151 Entry
1502 **
1503 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1504 ** @param [r] inf [FILE *] stream
1505 **
1506 ** @return [int32] number of entries
1507 ************************************************************************/
GPS_Input_Get_D151(GPS_PWay * way,FILE * inf)1508 static int32 GPS_Input_Get_D151(GPS_PWay* way, FILE* inf)
1509 {
1510   char s[GPS_ARB_LEN];
1511   char* p;
1512 
1513   double f;
1514   int32 d;
1515   int32 cl=0;
1516 
1517 
1518   if (!GPS_Input_Read_Line(s,inf)) {
1519     return gps_errno;
1520   }
1521   GPS_Input_Load_String((*way)->ident,6,s);
1522 
1523   if (!GPS_Input_Read_Line(s,inf)) {
1524     return gps_errno;
1525   }
1526   p=strchr(s,':');
1527   if (sscanf(p+1,"%lf",&f)!=1) {
1528     return gps_errno;
1529   }
1530   (*way)->lat = f;
1531 
1532   if (!GPS_Input_Read_Line(s,inf)) {
1533     return gps_errno;
1534   }
1535   p=strchr(s,':');
1536   if (sscanf(p+1,"%lf",&f)!=1) {
1537     return gps_errno;
1538   }
1539   (*way)->lon = f;
1540 
1541   if (!GPS_Input_Read_Line(s,inf)) {
1542     return gps_errno;
1543   }
1544   GPS_Input_Load_String((*way)->cmnt,40,s);
1545 
1546   if (!GPS_Input_Read_Line(s,inf)) {
1547     return gps_errno;
1548   }
1549   p=strchr(s,':');
1550   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1551     return gps_errno;
1552   }
1553   (*way)->wpt_class = cl = d;
1554 
1555   if (cl != 2) {
1556     if (!GPS_Input_Read_Line(s,inf)) {
1557       return gps_errno;
1558     }
1559     GPS_Input_Load_String((*way)->cc,2,s);
1560 
1561     if (!GPS_Input_Read_Line(s,inf)) {
1562       return gps_errno;
1563     }
1564     GPS_Input_Load_String((*way)->city,24,s);
1565 
1566     if (!GPS_Input_Read_Line(s,inf)) {
1567       return gps_errno;
1568     }
1569     GPS_Input_Load_String((*way)->state,2,s);
1570 
1571     if (!GPS_Input_Read_Line(s,inf)) {
1572       return gps_errno;
1573     }
1574     GPS_Input_Load_String((*way)->name,30,s);
1575   }
1576 
1577   if (!cl) {
1578     if (!GPS_Input_Read_Line(s,inf)) {
1579       return gps_errno;
1580     }
1581     p=strchr(s,':');
1582     if (sscanf(p+1,"%d",(int*)&d)!=1) {
1583       return gps_errno;
1584     }
1585     (*way)->alt = d;
1586   }
1587 
1588   return 1;
1589 }
1590 
1591 
1592 /* @funcstatic GPS_Input_Get_D152   ************************************
1593 **
1594 ** Get a D152 Entry
1595 **
1596 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1597 ** @param [r] inf [FILE *] stream
1598 **
1599 ** @return [int32] number of entries
1600 ************************************************************************/
GPS_Input_Get_D152(GPS_PWay * way,FILE * inf)1601 static int32 GPS_Input_Get_D152(GPS_PWay* way, FILE* inf)
1602 {
1603   return GPS_Input_Get_D150(way,inf);
1604 }
1605 
1606 
1607 
1608 /* @funcstatic GPS_Input_Get_D154   ************************************
1609 **
1610 ** Get a D154 Entry
1611 **
1612 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1613 ** @param [r] inf [FILE *] stream
1614 **
1615 ** @return [int32] number of entries
1616 ************************************************************************/
GPS_Input_Get_D154(GPS_PWay * way,FILE * inf)1617 static int32 GPS_Input_Get_D154(GPS_PWay* way, FILE* inf)
1618 {
1619   char s[GPS_ARB_LEN];
1620   char* p;
1621 
1622   double f;
1623   int32 d;
1624   int32 cl=0;
1625 
1626 
1627   if (!GPS_Input_Read_Line(s,inf)) {
1628     return gps_errno;
1629   }
1630   GPS_Input_Load_String((*way)->ident,6,s);
1631 
1632   if (!GPS_Input_Read_Line(s,inf)) {
1633     return gps_errno;
1634   }
1635   p=strchr(s,':');
1636   if (sscanf(p+1,"%lf",&f)!=1) {
1637     return gps_errno;
1638   }
1639   (*way)->lat = f;
1640 
1641   if (!GPS_Input_Read_Line(s,inf)) {
1642     return gps_errno;
1643   }
1644   p=strchr(s,':');
1645   if (sscanf(p+1,"%lf",&f)!=1) {
1646     return gps_errno;
1647   }
1648   (*way)->lon = f;
1649 
1650   if (!GPS_Input_Read_Line(s,inf)) {
1651     return gps_errno;
1652   }
1653   GPS_Input_Load_String((*way)->cmnt,40,s);
1654 
1655   if (!GPS_Input_Read_Line(s,inf)) {
1656     return gps_errno;
1657   }
1658   p=strchr(s,':');
1659   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1660     return gps_errno;
1661   }
1662   (*way)->smbl = d;
1663 
1664   if (!GPS_Input_Read_Line(s,inf)) {
1665     return gps_errno;
1666   }
1667   p=strchr(s,':');
1668   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1669     return gps_errno;
1670   }
1671   (*way)->wpt_class = cl = d;
1672 
1673   if (cl != 4 && cl != 8) {
1674     if (!GPS_Input_Read_Line(s,inf)) {
1675       return gps_errno;
1676     }
1677     GPS_Input_Load_String((*way)->cc,2,s);
1678 
1679     if (!GPS_Input_Read_Line(s,inf)) {
1680       return gps_errno;
1681     }
1682     GPS_Input_Load_String((*way)->city,24,s);
1683 
1684     if (!GPS_Input_Read_Line(s,inf)) {
1685       return gps_errno;
1686     }
1687     GPS_Input_Load_String((*way)->state,2,s);
1688 
1689     if (!GPS_Input_Read_Line(s,inf)) {
1690       return gps_errno;
1691     }
1692     GPS_Input_Load_String((*way)->name,30,s);
1693   }
1694 
1695   if (!cl) {
1696     if (!GPS_Input_Read_Line(s,inf)) {
1697       return gps_errno;
1698     }
1699     p=strchr(s,':');
1700     if (sscanf(p+1,"%d",(int*)&d)!=1) {
1701       return gps_errno;
1702     }
1703     (*way)->alt = d;
1704   }
1705 
1706   return 1;
1707 }
1708 
1709 
1710 
1711 /* @funcstatic GPS_Input_Get_D155   ************************************
1712 **
1713 ** Get a D155 Entry
1714 **
1715 ** @param [w] way [GPS_PWay *] pointer to waypoint entry
1716 ** @param [r] inf [FILE *] stream
1717 **
1718 ** @return [int32] number of entries
1719 ************************************************************************/
GPS_Input_Get_D155(GPS_PWay * way,FILE * inf)1720 static int32 GPS_Input_Get_D155(GPS_PWay* way, FILE* inf)
1721 {
1722   char s[GPS_ARB_LEN];
1723   char* p;
1724 
1725   double f;
1726   int32 d;
1727   int32 cl=0;
1728 
1729 
1730   if (!GPS_Input_Read_Line(s,inf)) {
1731     return gps_errno;
1732   }
1733   GPS_Input_Load_String((*way)->ident,6,s);
1734 
1735   if (!GPS_Input_Read_Line(s,inf)) {
1736     return gps_errno;
1737   }
1738   p=strchr(s,':');
1739   if (sscanf(p+1,"%lf",&f)!=1) {
1740     return gps_errno;
1741   }
1742   (*way)->lat = f;
1743 
1744   if (!GPS_Input_Read_Line(s,inf)) {
1745     return gps_errno;
1746   }
1747   p=strchr(s,':');
1748   if (sscanf(p+1,"%lf",&f)!=1) {
1749     return gps_errno;
1750   }
1751   (*way)->lon = f;
1752 
1753   if (!GPS_Input_Read_Line(s,inf)) {
1754     return gps_errno;
1755   }
1756   GPS_Input_Load_String((*way)->cmnt,40,s);
1757 
1758   if (!GPS_Input_Read_Line(s,inf)) {
1759     return gps_errno;
1760   }
1761   p=strchr(s,':');
1762   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1763     return gps_errno;
1764   }
1765   (*way)->smbl = d;
1766 
1767   if (!GPS_Input_Read_Line(s,inf)) {
1768     return gps_errno;
1769   }
1770   p=strchr(s,':');
1771   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1772     return gps_errno;
1773   }
1774   (*way)->dspl = d;
1775 
1776   if (!GPS_Input_Read_Line(s,inf)) {
1777     return gps_errno;
1778   }
1779   p=strchr(s,':');
1780   if (sscanf(p+1,"%d",(int*)&d)!=1) {
1781     return gps_errno;
1782   }
1783   (*way)->wpt_class = cl = d;
1784 
1785   if (cl != 4 && cl != 8) {
1786     if (!GPS_Input_Read_Line(s,inf)) {
1787       return gps_errno;
1788     }
1789     GPS_Input_Load_String((*way)->cc,2,s);
1790 
1791     if (!GPS_Input_Read_Line(s,inf)) {
1792       return gps_errno;
1793     }
1794     GPS_Input_Load_String((*way)->city,24,s);
1795 
1796     if (!GPS_Input_Read_Line(s,inf)) {
1797       return gps_errno;
1798     }
1799     GPS_Input_Load_String((*way)->state,2,s);
1800 
1801     if (!GPS_Input_Read_Line(s,inf)) {
1802       return gps_errno;
1803     }
1804     GPS_Input_Load_String((*way)->name,30,s);
1805   }
1806 
1807   if (!cl) {
1808     if (!GPS_Input_Read_Line(s,inf)) {
1809       return gps_errno;
1810     }
1811     p=strchr(s,':');
1812     if (sscanf(p+1,"%d",(int*)&d)!=1) {
1813       return gps_errno;
1814     }
1815     (*way)->alt = d;
1816   }
1817 
1818   return 1;
1819 }
1820 
1821 
1822 
1823 /* @func GPS_Input_Get_Track *******************************************
1824 **
1825 ** Construct a travk array from a file
1826 **
1827 ** @param [w] trk [GPS_PTrack **] pointer to track array
1828 ** @param [r] inf [FILE *] stream
1829 **
1830 ** @return [int32] number of entries
1831 ************************************************************************/
1832 
GPS_Input_Get_Track(GPS_PTrack ** trk,FILE * inf)1833 int32 GPS_Input_Get_Track(GPS_PTrack** trk, FILE* inf)
1834 {
1835   char s[GPS_ARB_LEN];
1836   int32 n;
1837   int32 i;
1838   long pos;
1839   int32 a;
1840   int32 d;
1841 
1842   gps_errno = INPUT_ERROR;
1843 
1844   if (!GPS_Input_Read_Line(s,inf)) {
1845     return gps_errno;
1846   }
1847   if (strncmp(s,"Track log",9)) {
1848     return gps_errno;
1849   }
1850 
1851   if (sscanf(s,"Track log %d%d",(int*)&a,(int*)&d)!=2) {
1852     return INPUT_ERROR;
1853   }
1854 
1855 
1856   if (!GPS_Input_Read_Line(s,inf)) {
1857     return gps_errno;
1858   }
1859   if (strncmp(s,"Start",5)) {
1860     return gps_errno;
1861   }
1862 
1863   pos = ftell(inf);
1864   n = 0;
1865   while (strncmp(s,"End",3)) {
1866     if (!GPS_Input_Read_Line(s,inf)) {
1867       return gps_errno;
1868     }
1869     if (strstr(s,"Latitude")) {
1870       ++n;
1871     }
1872     if (strstr(s,"Header")) {
1873       ++n;
1874     }
1875   }
1876   fseek(inf,pos,0);
1877 
1878 
1879   if (!(*trk=(GPS_PTrack*)malloc(n*sizeof(GPS_PTrack*)))) {
1880     return MEMORY_ERROR;
1881   }
1882   for (i=0; i<n; ++i)
1883     if (!((*trk)[i]=GPS_Track_New())) {
1884       return MEMORY_ERROR;
1885     }
1886 
1887 
1888   switch (a) {
1889   case pA300:
1890     break;
1891   case pA301:
1892     return GPS_Input_Get_Track301(trk, inf, d, n);
1893   default:
1894     return INPUT_ERROR;
1895   }
1896 
1897 
1898 
1899   for (i=0; i<n; ++i) {
1900     if (!GPS_Input_Read_Line(s,inf)) {
1901       return gps_errno;
1902     }
1903 
1904     if (!strcmp(s,"New track")) {
1905       (*trk)[i]->tnew=1;
1906       if (!GPS_Input_Read_Line(s,inf)) {
1907         return gps_errno;
1908       }
1909     } else {
1910       (*trk)[i]->tnew=0;
1911     }
1912 
1913     switch (d) {
1914     case pD300:
1915       GPS_Input_Get_D300(&((*trk)[i]),inf,s);
1916       break;
1917     case pD301:
1918       GPS_Input_Get_D301(&((*trk)[i]),inf,s);
1919       break;
1920     default:
1921       return PROTOCOL_ERROR;
1922     }
1923   }
1924 
1925   return n;
1926 }
1927 
1928 
1929 
1930 /* @funcstatic GPS_Input_Get_Track301 **********************************
1931 **
1932 ** Construct a travk array from a file
1933 **
1934 ** @param [w] trk [GPS_PTrack **] pointer to track array
1935 ** @param [r] inf [FILE *] stream
1936 ** @param [r] type [int32] data type
1937 ** @param [r] n [int32] number of tracks
1938 **
1939 ** @return [int32] number of entries
1940 ************************************************************************/
1941 
GPS_Input_Get_Track301(GPS_PTrack ** trk,FILE * inf,int32 type,int32 n)1942 static int32 GPS_Input_Get_Track301(GPS_PTrack** trk, FILE* inf, int32 type,
1943                                     int32 n)
1944 {
1945   char s[GPS_ARB_LEN];
1946   int32 i;
1947   char* p;
1948   int32 x;
1949 
1950   for (i=0; i<n; ++i) {
1951     if (!GPS_Input_Read_Line(s,inf)) {
1952       return gps_errno;
1953     }
1954     if (!strcmp(s,"Header")) {
1955       (*trk)[i]->ishdr = 1;
1956 
1957       if (!GPS_Input_Read_Line(s,inf)) {
1958         return gps_errno;
1959       }
1960       GPS_Input_Load_Strnull((*trk)[i]->trk_ident,s);
1961 
1962       if (!GPS_Input_Read_Line(s,inf)) {
1963         return gps_errno;
1964       }
1965       p=strchr(s,':');
1966       if (sscanf(p+1,"%d",(int*)&x)!=1) {
1967         return INPUT_ERROR;
1968       }
1969       (*trk)[i]->dspl = x;
1970 
1971       if (!GPS_Input_Read_Line(s,inf)) {
1972         return gps_errno;
1973       }
1974       p=strchr(s,':');
1975       if (sscanf(p+1,"%d",(int*)&x)!=1) {
1976         return INPUT_ERROR;
1977       }
1978       (*trk)[i]->colour = x;
1979 
1980       continue;
1981     }
1982 
1983     (*trk)[i]->ishdr = 0;
1984 
1985     if (!strcmp(s,"New track")) {
1986       (*trk)[i]->tnew=1;
1987       if (!GPS_Input_Read_Line(s,inf)) {
1988         return gps_errno;
1989       }
1990     } else {
1991       (*trk)[i]->tnew=0;
1992     }
1993 
1994     switch (type) {
1995     case pD300:
1996       GPS_Input_Get_D300(&((*trk)[i]),inf,s);
1997       break;
1998     case pD301:
1999       GPS_Input_Get_D301(&((*trk)[i]),inf,s);
2000       break;
2001     default:
2002       return PROTOCOL_ERROR;
2003     }
2004   }
2005 
2006   return n;
2007 }
2008 
2009 
2010 
2011 /* @funcstatic GPS_Input_Get_D300 **********************************
2012 **
2013 ** Construct a track from a file
2014 **
2015 ** @param [w] trk [GPS_PTrack *] pointer to track
2016 ** @param [r] inf [FILE *] stream
2017 ** @param [w] s [char *] input line
2018 **
2019 ** @return [int32] number of entries
2020 ************************************************************************/
2021 
GPS_Input_Get_D300(GPS_PTrack * trk,FILE * inf,char * s)2022 static int32 GPS_Input_Get_D300(GPS_PTrack* trk, FILE* inf, char* s)
2023 {
2024   char* p;
2025   double f;
2026 
2027   p=strchr(s,':');
2028   if (sscanf(p+1,"%lf",&f)!=1) {
2029     return gps_errno;
2030   }
2031   (*trk)->lat = f;
2032 
2033   if (!GPS_Input_Read_Line(s,inf)) {
2034     return gps_errno;
2035   }
2036   p=strchr(s,':');
2037   if (sscanf(p+1,"%lf",&f)!=1) {
2038     return gps_errno;
2039   }
2040   (*trk)->lon = f;
2041 
2042   if (!GPS_Input_Read_Line(s,inf)) {
2043     return gps_errno;
2044   }
2045   (*trk)->Time = 0;
2046 
2047   return 1;
2048 }
2049 
2050 
2051 
2052 /* @funcstatic GPS_Input_Get_D301 **********************************
2053 **
2054 ** Construct a track from a file
2055 **
2056 ** @param [w] trk [GPS_PTrack *] pointer to track
2057 ** @param [r] inf [FILE *] stream
2058 ** @param [w] s [char *] input line
2059 **
2060 ** @return [int32] number of entries
2061 ************************************************************************/
2062 
GPS_Input_Get_D301(GPS_PTrack * trk,FILE * inf,char * s)2063 static int32 GPS_Input_Get_D301(GPS_PTrack* trk, FILE* inf, char* s)
2064 {
2065   char* p;
2066   double f;
2067 
2068   p=strchr(s,':');
2069   if (sscanf(p+1,"%lf",&f)!=1) {
2070     return gps_errno;
2071   }
2072   (*trk)->lat = f;
2073 
2074   if (!GPS_Input_Read_Line(s,inf)) {
2075     return gps_errno;
2076   }
2077   p=strchr(s,':');
2078   if (sscanf(p+1,"%lf",&f)!=1) {
2079     return gps_errno;
2080   }
2081   (*trk)->lon = f;
2082 
2083   if (!GPS_Input_Read_Line(s,inf)) {
2084     return gps_errno;
2085   }
2086   (*trk)->Time = 0;
2087 
2088   if (!GPS_Input_Read_Line(s,inf)) {
2089     return gps_errno;
2090   }
2091   p=strchr(s,':');
2092   if (sscanf(p+1,"%lf",&f)!=1) {
2093     return gps_errno;
2094   }
2095   (*trk)->alt = f;
2096 
2097   if (!GPS_Input_Read_Line(s,inf)) {
2098     return gps_errno;
2099   }
2100   p=strchr(s,':');
2101   if (sscanf(p+1,"%lf",&f)!=1) {
2102     return gps_errno;
2103   }
2104   (*trk)->dpth = f;
2105 
2106   return 1;
2107 }
2108 
2109 
2110 
2111 /* @func GPS_Input_Get_Route *******************************************
2112 **
2113 ** Construct a route array from a file
2114 **
2115 ** @param [w] way [GPS_PWay **] pointer to waypoint array
2116 ** @param [r] inf [FILE *] stream
2117 **
2118 ** @return [int32] number of entries
2119 ************************************************************************/
2120 
GPS_Input_Get_Route(GPS_PWay ** way,FILE * inf)2121 int32 GPS_Input_Get_Route(GPS_PWay** way, FILE* inf)
2122 {
2123   char s[GPS_ARB_LEN];
2124   int32 n;
2125   int32 type;
2126   int32 rtype=0;
2127   int32 atype=0;
2128   int32 i;
2129   long pos;
2130   int32 ret;
2131   char* p;
2132   int32 d;
2133 
2134   gps_errno = INPUT_ERROR;
2135 
2136 
2137   if (!GPS_Input_Read_Line(s,inf)) {
2138     return gps_errno;
2139   }
2140   if (sscanf(s,"Route log %d",(int*)&atype)!=1) {
2141     return gps_errno;
2142   }
2143   if (!GPS_Input_Read_Line(s,inf)) {
2144     return gps_errno;
2145   }
2146 
2147   switch (atype) {
2148   case pA200:
2149     break;
2150   case pA201:
2151     return GPS_Input_Get_Route201(way,inf);
2152   default:
2153     GPS_Error("GPS_Input_Get_Route: Unknown protocol");
2154     return PROTOCOL_ERROR;
2155   }
2156 
2157 
2158   if (!GPS_Input_Read_Line(s,inf)) {
2159     return gps_errno;
2160   }
2161   if (sscanf(s,"Route Type: %d",(int*)&rtype)!=1) {
2162     return gps_errno;
2163   }
2164 
2165   if (!GPS_Input_Read_Line(s,inf)) {
2166     return gps_errno;
2167   }
2168   if (sscanf(s,"Waypoints Type: %d",(int*)&type)!=1) {
2169     return gps_errno;
2170   }
2171 
2172   if (!GPS_Input_Read_Line(s,inf)) {
2173     return gps_errno;
2174   }
2175   if (strncmp(s,"Start",5)) {
2176     return gps_errno;
2177   }
2178 
2179   pos = ftell(inf);
2180   n = 1;
2181   while (strncmp(s,"End",3)) {
2182     if (!GPS_Input_Read_Line(s,inf)) {
2183       return gps_errno;
2184     }
2185     if (strstr(s,"Latitude") || strstr(s,"Route")) {
2186       ++n;
2187     }
2188   }
2189   fseek(inf,0L,0);
2190 
2191 
2192   if (!(*way=(GPS_PWay*)malloc(n*sizeof(GPS_PWay*)))) {
2193     return MEMORY_ERROR;
2194   }
2195   for (i=0; i<n; ++i) {
2196     if (!((*way)[i]=GPS_Way_New())) {
2197       return MEMORY_ERROR;
2198     }
2199     (*way)[i]->prot = type;
2200   }
2201 
2202   if (!GPS_Input_Read_Line(s,inf)) {
2203     return gps_errno;
2204   }
2205   if (!GPS_Input_Read_Line(s,inf)) {
2206     return gps_errno;
2207   }
2208   if (!GPS_Input_Read_Line(s,inf)) {
2209     return gps_errno;
2210   }
2211 
2212   for (i=0; i<n; ++i) {
2213     (*way)[i]->rte_prot = rtype;
2214     (*way)[i]->islink = 0;
2215     if (strstr(s,"Route")) {
2216       (*way)[i]->isrte = 1;
2217       switch (rtype) {
2218       case 200:
2219         p = strchr(s,':');
2220         p = strchr(p+1,':');
2221         if (sscanf(p+1,"%d",(int*)&d)!=1) {
2222           return gps_error;
2223         }
2224         (*way)[i]->rte_num=d;
2225         break;
2226       case 201:
2227         p = strchr(s,':');
2228         p = strchr(p+1,':');
2229         if (sscanf(p+1,"%d",(int*)&d)!=1) {
2230           return gps_error;
2231         }
2232         (*way)[i]->rte_num=d;
2233         ++p;
2234         GPS_Input_Load_String((*way)[i]->rte_cmnt,20,p+2);
2235         break;
2236       case 202:
2237         p = strchr(s,':');
2238         p = strchr(p+1,':');
2239         GPS_Input_Load_Strnull((*way)[i]->rte_ident,p+1);
2240         break;
2241       }
2242       if (!GPS_Input_Read_Line(s,inf)) {
2243         return gps_errno;
2244       }
2245       if (!GPS_Input_Read_Line(s,inf)) {
2246         return gps_errno;
2247       }
2248       continue;
2249     } else {
2250       (*way)[i]->isrte=0;
2251     }
2252 
2253     if (strstr(s,"End")) {
2254       if (!GPS_Input_Read_Line(s,inf)) {
2255         return gps_errno;
2256       }
2257 
2258       continue;
2259     }
2260 
2261 
2262     switch (type) {
2263     case 100:
2264       ret = GPS_Input_Get_D100(&((*way)[i]),inf);
2265       if (ret<0) {
2266         return gps_errno;
2267       }
2268       break;
2269     case 101:
2270       ret = GPS_Input_Get_D101(&((*way)[i]),inf);
2271       if (ret<0) {
2272         return gps_errno;
2273       }
2274       break;
2275     case 102:
2276       ret = GPS_Input_Get_D102(&((*way)[i]),inf);
2277       if (ret<0) {
2278         return gps_errno;
2279       }
2280       break;
2281     case 103:
2282       ret = GPS_Input_Get_D103(&((*way)[i]),inf);
2283       if (ret<0) {
2284         return gps_errno;
2285       }
2286       break;
2287     case 104:
2288       ret = GPS_Input_Get_D104(&((*way)[i]),inf);
2289       if (ret<0) {
2290         return gps_errno;
2291       }
2292       break;
2293     case 105:
2294       ret = GPS_Input_Get_D105(&((*way)[i]),inf);
2295       if (ret<0) {
2296         return gps_errno;
2297       }
2298       break;
2299     case 106:
2300       ret = GPS_Input_Get_D106(&((*way)[i]),inf);
2301       if (ret<0) {
2302         return gps_errno;
2303       }
2304       break;
2305     case 107:
2306       ret = GPS_Input_Get_D107(&((*way)[i]),inf);
2307       if (ret<0) {
2308         return gps_errno;
2309       }
2310       break;
2311     case 108:
2312       ret = GPS_Input_Get_D108(&((*way)[i]),inf);
2313       if (ret<0) {
2314         return gps_errno;
2315       }
2316       break;
2317     case 150:
2318       ret = GPS_Input_Get_D150(&((*way)[i]),inf);
2319       if (ret<0) {
2320         return gps_errno;
2321       }
2322       break;
2323     case 151:
2324       ret = GPS_Input_Get_D151(&((*way)[i]),inf);
2325       if (ret<0) {
2326         return gps_errno;
2327       }
2328       break;
2329     case 152:
2330       ret = GPS_Input_Get_D152(&((*way)[i]),inf);
2331       if (ret<0) {
2332         return gps_errno;
2333       }
2334       break;
2335     case 154:
2336       ret = GPS_Input_Get_D154(&((*way)[i]),inf);
2337       if (ret<0) {
2338         return gps_errno;
2339       }
2340       break;
2341     case 155:
2342       ret = GPS_Input_Get_D155(&((*way)[i]),inf);
2343       if (ret<0) {
2344         return gps_errno;
2345       }
2346       break;
2347     default:
2348       GPS_Error("Input_Get_Waypoints: Unknown protocol");
2349       return PROTOCOL_ERROR;
2350     }
2351 
2352   }
2353 
2354   return n;
2355 }
2356 
2357 
2358 
2359 /* @funcstatic GPS_Input_Get_Route201 ***********************************
2360 **
2361 ** Construct a route array from a file
2362 **
2363 ** @param [w] way [GPS_PWay **] pointer to waypoint array
2364 ** @param [r] inf [FILE *] stream
2365 **
2366 ** @return [int32] number of entries
2367 ************************************************************************/
2368 
GPS_Input_Get_Route201(GPS_PWay ** way,FILE * inf)2369 static int32 GPS_Input_Get_Route201(GPS_PWay** way, FILE* inf)
2370 {
2371   char s[GPS_ARB_LEN];
2372   int32 n;
2373   int32 type;
2374   int32 rtype;
2375   int32 i;
2376   long pos;
2377   int32 ret;
2378   char* p;
2379   int32 d;
2380 
2381   gps_errno = INPUT_ERROR;
2382 
2383   if (!GPS_Input_Read_Line(s,inf)) {
2384     return gps_errno;
2385   }
2386   if (sscanf(s,"Route Type: %d",(int*)&rtype)!=1) {
2387     return gps_errno;
2388   }
2389 
2390   if (!GPS_Input_Read_Line(s,inf)) {
2391     return gps_errno;
2392   }
2393   if (sscanf(s,"Waypoints Type: %d",(int*)&type)!=1) {
2394     return gps_errno;
2395   }
2396 
2397 
2398   pos = ftell(inf);
2399   n = 1;
2400   while (strncmp(s,"End",3)) {
2401     if (!GPS_Input_Read_Line(s,inf)) {
2402       return gps_errno;
2403     }
2404     if (strstr(s,"Latitude") || strstr(s,"Route") || strstr(s,"Link Class")) {
2405       ++n;
2406     }
2407   }
2408   fseek(inf,0L,0);
2409 
2410   if (!(*way=(GPS_PWay*)malloc(n*sizeof(GPS_PWay*)))) {
2411     return MEMORY_ERROR;
2412   }
2413   for (i=0; i<n; ++i) {
2414     if (!((*way)[i]=GPS_Way_New())) {
2415       return MEMORY_ERROR;
2416     }
2417     (*way)[i]->prot = type;
2418   }
2419 
2420   if (!GPS_Input_Read_Line(s,inf)) {
2421     return gps_errno;
2422   }
2423   if (!GPS_Input_Read_Line(s,inf)) {
2424     return gps_errno;
2425   }
2426   if (!GPS_Input_Read_Line(s,inf)) {
2427     return gps_errno;
2428   }
2429 
2430   for (i=0; i<n; ++i) {
2431     (*way)[i]->rte_prot = rtype;
2432     (*way)[i]->islink = 0;
2433     if (strstr(s,"Route")) {
2434       (*way)[i]->isrte = 1;
2435       switch (rtype) {
2436       case 200:
2437         p = strchr(s,':');
2438         p = strchr(p+1,':');
2439         if (sscanf(p+1,"%d",(int*)&d)!=1) {
2440           return gps_error;
2441         }
2442         (*way)[i]->rte_num=d;
2443         break;
2444       case 201:
2445         p = strchr(s,':');
2446         p = strchr(p+1,':');
2447         if (sscanf(p+1,"%d",(int*)&d)!=1) {
2448           return gps_error;
2449         }
2450         (*way)[i]->rte_num=d;
2451         p = strchr(p+1,':');
2452         GPS_Input_Load_String((*way)[i]->rte_cmnt,20,p+1);
2453         break;
2454       case 202:
2455         p = strchr(s,':');
2456         p = strchr(p+1,':');
2457         GPS_Input_Load_Strnull((*way)[i]->rte_ident,p+1);
2458         break;
2459       }
2460       if (!GPS_Input_Read_Line(s,inf)) {
2461         return gps_errno;
2462       }
2463       continue;
2464     } else {
2465       (*way)[i]->isrte=0;
2466     }
2467 
2468 
2469 
2470     if (strstr(s,"Link Class")) {
2471       (*way)[i]->islink = 1;
2472 
2473       p = strchr(s,':');
2474       if (sscanf(p+1,"%d",(int*)&d)!=1) {
2475         return gps_error;
2476       }
2477       (*way)[i]->rte_link_class=d;
2478 
2479       if (!((*way)[i]->rte_link_class==3 || (*way)[i]->rte_link_class
2480             ==0xff)) {
2481         if (!GPS_Input_Read_Line(s,inf)) {
2482           return gps_errno;
2483         }
2484         GPS_Input_Load_String((*way)[i]->rte_link_subclass,18,s);
2485       } else {
2486         GPS_Util_Put_Short((UC*)(*way)[i]->rte_link_subclass,0);
2487         GPS_Util_Put_Int((UC*)(*way)[i]->rte_link_subclass+2,0);
2488         GPS_Util_Put_Uint((UC*)(*way)[i]->rte_link_subclass+6,
2489                           0xffffffff);
2490         GPS_Util_Put_Uint((UC*)(*way)[i]->rte_link_subclass+10,
2491                           0xffffffff);
2492         GPS_Util_Put_Uint((UC*)(*way)[i]->rte_link_subclass+14,
2493                           0xffffffff);
2494       }
2495 
2496       if (!GPS_Input_Read_Line(s,inf)) {
2497         return gps_errno;
2498       }
2499       GPS_Input_Load_Strnull((*way)[i]->rte_link_ident,s);
2500 
2501       continue;
2502     } else {
2503       (*way)[i]->islink=0;
2504     }
2505 
2506 
2507     if (strstr(s,"End")) {
2508       GPS_Error("Get_Route201: Unexpected End");
2509       return INPUT_ERROR;
2510     }
2511 
2512 
2513     switch (type) {
2514     case 100:
2515       ret = GPS_Input_Get_D100(&((*way)[i]),inf);
2516       if (ret<0) {
2517         return gps_errno;
2518       }
2519       break;
2520     case 101:
2521       ret = GPS_Input_Get_D101(&((*way)[i]),inf);
2522       if (ret<0) {
2523         return gps_errno;
2524       }
2525       break;
2526     case 102:
2527       ret = GPS_Input_Get_D102(&((*way)[i]),inf);
2528       if (ret<0) {
2529         return gps_errno;
2530       }
2531       break;
2532     case 103:
2533       ret = GPS_Input_Get_D103(&((*way)[i]),inf);
2534       if (ret<0) {
2535         return gps_errno;
2536       }
2537       break;
2538     case 104:
2539       ret = GPS_Input_Get_D104(&((*way)[i]),inf);
2540       if (ret<0) {
2541         return gps_errno;
2542       }
2543       break;
2544     case 105:
2545       ret = GPS_Input_Get_D105(&((*way)[i]),inf);
2546       if (ret<0) {
2547         return gps_errno;
2548       }
2549       break;
2550     case 106:
2551       ret = GPS_Input_Get_D106(&((*way)[i]),inf);
2552       if (ret<0) {
2553         return gps_errno;
2554       }
2555       break;
2556     case 107:
2557       ret = GPS_Input_Get_D107(&((*way)[i]),inf);
2558       if (ret<0) {
2559         return gps_errno;
2560       }
2561       break;
2562     case 108:
2563       ret = GPS_Input_Get_D108(&((*way)[i]),inf);
2564       if (ret<0) {
2565         return gps_errno;
2566       }
2567       break;
2568     case 150:
2569       ret = GPS_Input_Get_D150(&((*way)[i]),inf);
2570       if (ret<0) {
2571         return gps_errno;
2572       }
2573       break;
2574     case 151:
2575       ret = GPS_Input_Get_D151(&((*way)[i]),inf);
2576       if (ret<0) {
2577         return gps_errno;
2578       }
2579       break;
2580     case 152:
2581       ret = GPS_Input_Get_D152(&((*way)[i]),inf);
2582       if (ret<0) {
2583         return gps_errno;
2584       }
2585       break;
2586     case 154:
2587       ret = GPS_Input_Get_D154(&((*way)[i]),inf);
2588       if (ret<0) {
2589         return gps_errno;
2590       }
2591       break;
2592     case 155:
2593       ret = GPS_Input_Get_D155(&((*way)[i]),inf);
2594       if (ret<0) {
2595         return gps_errno;
2596       }
2597       break;
2598     default:
2599       GPS_Error("Input_Get_Waypoints: Unknown protocol");
2600       return PROTOCOL_ERROR;
2601     }
2602     if (!GPS_Input_Read_Line(s,inf)) {
2603       return gps_errno;
2604     }
2605   }
2606 
2607   return n;
2608 }
2609