Re: [Flightgear-devel] perl scripting
Andy Ross writes: > This is trivially fixable by clearing $ENV{LANG} in scripts where you > want to call pack/unpack, but it is very non-obvious if you aren't > prepared for it. Thanks for the warning. Problems aside, I'm very happy to hear that Perl is supporting UTF-8 better now. All the best, David -- David Megginson, [EMAIL PROTECTED], http://www.megginson.com/ ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] perl scripting
David Megginson wrote: > Last time I looked at swig, it was for creating bindings for native > libraries from include files. > > Try > > perldoc -f pack > perldoc -f unpack > > Perl has excellent support for this kind of thing, once you get your > head around it. BIG WARNING: The pack/unpack facilities have been pretty thoroughly cuisinarted by the recent UTF8 support. I got smacked hard by this a few months back. Attached is a little mind bender that I wrote while trying to figure this out. All it does is take a number (255), and try to pack that as a single-byte number into a one character string. It verifies that the length is one; writes that single byte out to a file, reads that single byte back in from the file, and then verifies that the strings are equal. When run under Red Hat 8.0, the strings are *not* equal. When run on the same machine via an "ssh -c" command, the strings *are* equal. What happened is that perl honors the LANG attribute when doing file I/O, and LANG is set to "en_US.UTF-8" by default for login shells in Red Hat. So it writes out the (UCS-2) "character" 255 as a two byte (!) UTF8 string. This is sane behavior for perl in text contexts (UTF8 files turn into character arrays magically when read, and re-stream themselves magically when written), but it completely breaks the pack function, which is based on the idea of packing numbers into strings and interpreting those strings as arrays of bytes, not characters. This is trivially fixable by clearing $ENV{LANG} in scripts where you want to call pack/unpack, but it is very non-obvious if you aren't prepared for it. Andy -- Andrew J. RossNextBus Information Systems Senior Software Engineer Emeryville, CA [EMAIL PROTECTED] http://www.nextbus.com "Men go crazy in conflagrations. They only get better one by one." - Sting (misquoted) #!/usr/bin/perl -w use strict; use bytes; my $s0 = pack "C", 255; print "Length: ", length($s0), "\n"; print "Bytes: ", join(", ", unpack("C*", $s0)), "\n"; open FOO, ">foo.out" or die; print FOO $s0; close FOO; my $s1; open FOO, "foo.out" or die; read(FOO, $s1, 1) == 1 or die; close FOO; print "Length: ", length($s1), "\n"; print "Bytes: ", join(", ", unpack("C*", $s1)), "\n"; if($s0 eq $s1) { print "Strings are equal\n"; } else { print "Strings are NOT equal\n"; }
Re: [Flightgear-devel] perl scripting
David Megginson > Norman Vine writes: > > > > Last time I looked at swig, it was for creating bindings for native > > > libraries from include files. > > > > Not really sure what you mean by that David but SWIG is designed > > to extend scripting languages with application specific knowledge > > It is true that it gleens this knowledge from your header files but > > then so does 'C' so this is not revolutionary > > Swig is designed to solve the binary API problem, not the binary data > format problem. AFAICT it excels at solving both in a scripting language *neutral* manner All the best from a 'happy' SWIG user Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] perl scripting
Norman Vine writes: > > Last time I looked at swig, it was for creating bindings for native > > libraries from include files. > > Not really sure what you mean by that David but SWIG is designed > to extend scripting languages with application specific knowledge > It is true that it gleens this knowledge from your header files but > then so does 'C' so this is not revolutionary Swig is designed to solve the binary API problem, not the binary data format problem. All the best, David -- David Megginson, [EMAIL PROTECTED], http://www.megginson.com/ ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] perl scripting
David Megginson > > Norman Vine writes: > > > > but what worries me is how to translate a chunk of binary data > > > into perl variables ... probably easy once you know the tricks. > > > > http://www.swig.org > > Last time I looked at swig, it was for creating bindings for native > libraries from include files. Not really sure what you mean by that David but SWIG is designed to extend scripting languages with application specific knowledge It is true that it gleens this knowledge from your header files but then so does 'C' so this is not revolutionary > > Try > > perldoc -f pack > perldoc -f unpack > > Perl has excellent support for this kind of thing, once you get your > head around it. Yup so do most other scripting lanuages for example the 'struct' module in Python however I mentioned SWIG because it is so *easy* to use and results in a module that is not language specific and usually runs faster too :-) Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] perl scripting
Norman Vine writes: > > but what worries me is how to translate a chunk of binary data > > into perl variables ... probably easy once you know the tricks. > > http://www.swig.org Last time I looked at swig, it was for creating bindings for native libraries from include files. Try perldoc -f pack perldoc -f unpack Perl has excellent support for this kind of thing, once you get your head around it. All the best, David -- David Megginson, [EMAIL PROTECTED], http://www.megginson.com/ ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] perl scripting
Norman Vine wrotes: > Curtis L. Olson writes: > > > but what worries me is how to translate a chunk of > > binary data into perl variables ... probably easy once you know the > > tricks. > > http://www.swig.org for example if you extract the included tarball somewhere and assuming you have swig installed cd into the /swig/perl directory and simply issuing % ./doit should build a perl module to parse the ogcFGData message which probably has most of what you would want :-) This is a simple wrap of 'src / Network / opengc_data.hxx' HTH Norman fgfs_net_swig.tgz Description: application/compressed
Re: [Flightgear-devel] perl scripting
Curtis L. Olson > but what worries me is how to translate a chunk of > binary data into perl variables ... probably easy once you know the > tricks. http://www.swig.org Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
[Flightgear-devel] perl scripting
I'm playing around with an external perl script[1] for flightgear. I've been using the http interface, but as I do more and more things, that is turning out to be a performance bottleneck. Has anyone interfaced to FlightGear's "telnet" service from a perl script. I'm sure I could figure it out, but if someone has already done this, it might save an hour of my life. Down the road I'm also seeing a need to have my script monitor some of FlightGear's FDM output. If FlightGear is already broadcasting this via UDP (for other visual channels for instance) it would be cool if my perl script could listen in and grab the data too. Has anyone done UDP socket communication via perl? I know perl has all the socket interface calls, but what worries me is how to translate a chunk of binary data into perl variables ... probably easy once you know the tricks. Has anyone done either of these? Thanks, Curt. -- Curtis Olson IVLab / HumanFIRST Program FlightGear Project Twin Cities[EMAIL PROTECTED] [EMAIL PROTECTED] Minnesota http://www.menet.umn.edu/~curt http://www.flightgear.org [1] I know there are plenty of other scripting options out there, but I'm familiar with and like perl, so that is what I've chosen, so I'm looking for specific perl solutions here. :-) ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel