On Tuesday, June 4, 2002, at 01:22  am, Andy Ross wrote:
>
> Heh, that actually sounded kinda fun, so I tried it.  Here's the
> smallest parser for your syntax that I could come up with, in good old
> obfuscatorial C style.  It sits pleasingly close to the line between
> elegance and perversity.

Thanks very much, some comment below...
>
> 37�54.204' N

How  do you generate a degree symbol under Linux? I was trying to and 
failed miserably ...

> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> double parseLatLon(char* s)
> {
>     char buf[64];
>     int i, len, top=0;
>     double stk[32], sign=1;

32 seems a trifle excessive, I might go with 4 ... not a big deal though.

>     strncpy(buf, s, 64);
>     len = strlen(buf);
>
>     for(i=0; i<len; i++) {
>         char c = buf[i];
>         if((c>='0' && c<='9') || c=='-' || c=='.' || c=='+')
>             continue;  /* Digit characters are cool as is */
>         if((c|32) == 'w' || (c|32) == 's')
>             sign = -1; /* These mean "negate" (note case 
> insensitivity) */
>         buf[i] = 0;    /* Replace everything else with nuls */
>     }
>
>     /* Build a stack of doubles */
>     stk[0] = stk[1] = stk[2] = 0;
>     for(i=0; i<len; i++) {
>         while(i<len && buf[i] == 0) i++;
>         if(i != len) {
>             stk[top++] = atof(buf+i);

Would prefer to use strtod here, atof is deprecated. not sure about 
platform compatibility though.

>             i += strlen(buf+i);
>         }
>     }
>
>     return sign * (stk[0] + (stk[1] + stk[2] / 60) / 60);
> }
>
> int main(int argc, char** argv)
> {
>     printf("%f\n", parseLatLon(argv[1]));
>     return 1;
> }
>

Other than this, it looks great, I'll add it to my code (currently 
piling up in src/Navaids). If people decide it it's general enough to 
move to SimGear in the future, all the better.

BTW, the route stuff is coming along nicely, working on the XML / input 
side. I am currently coding up support for flight-plans / routes with 
navaids, fixes and 'direct' positions (hence the need for the above 
code). Each point can have altitude and/or speed restrictions. In 
addition to the basic types, flight plans can contain airway and 
procedure segments. The flight plan will automatically pick transitions 
on the airways / SIDs / STARs / APs based on the next / preceding points 
on the flight plan.

Once this is all coded up and tested (by next weekend, I hope), I need 
to start wiring it up to the current auto-pilot logic, and then I might 
actually be able to fly a plan, which would be pretty cool.

H&H
James

--
What I like about deadlines is the lovely whooshing sound they make as 
they rush past. -- Douglas Adams




_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to