Compare commits

..
Author SHA1 Message Date
curt dfff091b5f Updated ... 2002-02-15 17:13:12 +00:00
curt 47eb7efafa Added README's to distribution. 2002-02-14 21:35:32 +00:00
curt b2a7fff26e Explicitely reset the glBlendFunc() after drawing the moon for the Voodoo2
linux driver since it seems to have a bug in glPopAttrib().
2002-02-14 14:21:48 +00:00
curt 5f70123723 0.7.9pre2 changes. 2002-02-13 15:10:06 +00:00
david dd629da8d3 Replaced some cout's with SG_LOG (fixes namespace problem with
ANSI-conformant compilers).
2002-02-13 12:14:01 +00:00
curt 74f7d52d95 Fixed a problem that could lead to a 'near infinite' loop if bogus input
values are provided.
2002-02-12 15:21:14 +00:00
curt 7a65a990ba Decouple sg_time code from the current time(NULL), i.e. you can run the
time calculations for an alternate calendar time (i.e. if the application
is being driven from an external source of data.)

Fix a bug in sg_binobj.cxx which disrupted the 'broken down time' globally
for the entire application.
2002-02-11 22:27:27 +00:00
curt fe0076e291 Updated with 0.0.17 changes. 2002-02-10 04:10:00 +00:00
curt 1a8bc06cc6 FreeBSD fix: strnstr() is already defined. 2002-02-10 03:28:57 +00:00
curt 8c41081a5c This code had been written to assume current clock time. Added options
to allow specifying an alternate clock time.
2002-02-10 03:16:03 +00:00
curt 5b40eed554 Fixes a config problem that could lead to a bogus build for people with
voodoo cards.
2002-02-07 22:37:09 +00:00
curt b1c4d34eef Fix for FreeBSD. 2002-02-06 01:04:38 +00:00
curt 0152b607f8 Tweaks ... 2002-02-05 21:36:09 +00:00
curt ab6e72047b oops, minor tweaks. 2002-02-04 22:48:30 +00:00
curt 15399bfe95 Various mingwin patches contributed by Norman Vine. 2002-02-04 22:38:23 +00:00
curt 0ff748987b Pass strings by const reference instead of by value,
Made fix_path() a private member function, SGPath::fix(),
Added bool SGPath::exists(),
Added an assignment operator that acts like SGPath::append().
2002-02-04 20:23:41 +00:00
curt 58e0e7736b Removed some depricated irix support that is now handled elsewhere. 2002-02-01 20:18:47 +00:00
david 2d1b2ca938 Minor fixes from Cameron Moore. 2002-01-30 15:09:56 +00:00
curt 9a4152eb2d Fixes to make telnet interface work more than 1x. 2002-01-28 21:48:00 +00:00
curt 6ab443545f Further autogen.sh fixes to handle more cases. 2002-01-19 13:45:06 +00:00
curt 98a9b4a10c Minor clean ups. 2002-01-19 13:37:22 +00:00
david a6251606dd Added some new functionality to the property manager:
1. Nodes cache previous relative paths so that they do not have to
parse the paths each time.

2. There are new getNode() methods that include indices, so that users
do not have to sprintf to a buffer to iterate through indexed nodes.
2002-01-19 03:06:22 +00:00
curt c3b21e143c Fixed typos ... 2002-01-17 16:58:18 +00:00
curt b496593883 Updated to automatically handle newer versions of automake.
Does some IRIX specific fixups.
2002-01-17 15:21:49 +00:00
curt 4ef4b019ca Added conditional support for Norman's jpegfactory code (requires libjpeg
to be already installed.)
2002-01-16 21:13:27 +00:00
curt a8021531ab Initial revision of jpegfactory code for generating jpeg format screen dumps. 2002-01-16 21:11:00 +00:00
david 93fd948978 Added aclocal.m4 2002-01-16 00:04:16 +00:00
curt a1b3740dc6 A few changes from Norman Vine to support mingwin. 2002-01-15 22:28:21 +00:00
curt 40920457cb Initial revision. 2001-12-29 03:35:31 +00:00
curt 5039c84fd0 Removed metakit and zlib from the configure/build process. The
developer will need to build and install these separately if they
don't have packages already installed by their system.  See
README.metakit and README.zlib for more details.

As a convenience, pristine tarballs of the metakit and zlib source
code trees are included with the simgear distribution (and cvs.)
2001-12-29 00:38:04 +00:00
curt 220a43bf46 Removed metakit and zlib from the configure/build process. The
developer will need to build and install these separately if they don't
have packages already installed by their system.  See README.metakit and
README.zlib for more details.

As a convenience, pristine tarballs of the metakit and zlib source code
trees are included with the simgear distribution (and cvs.)
2001-12-29 00:35:34 +00:00
curt 45d3e19c38 Small tweaks to class initialization. 2001-12-28 23:37:34 +00:00
curt 5bab565cfe Updates to build system to better support automake-1.5
- automake-1.4 sets default values for INCLUDES which we can't
  overwrite.
- automake-1.5 renames this to DEFAULT_INCLUDES and leaves INCLUDES
  open for the developer to use.

Thus for automake-1.4 we are forced to 'append' to INCLUDES and in
automake-1.5 we can just set the value to whatever we like.
Unfortunately, the behaviors of the two versions are mutually
incompatible.

The solution I am committing now works for both versions but
automake-1.5 generates a lot of spurious warning messages that are
annoying, but not fatal.
2001-12-28 21:27:19 +00:00
curt 319a4282c8 Test commit. 2001-12-17 16:52:20 +00:00
david c6aa8bc8e9 Fixed Makefile.am to install easyxml.hxx in the simgear/xml rather
than simgear/.
2001-12-16 20:59:16 +00:00
david 6f1bfa202e -Added .cvsignore files to clean up CVS messages 2001-12-12 02:44:37 +00:00
david 6fa9f86d1c Added trace attributes to properties:
TRACE_READ - log a message whenever the property is read.

TRACE_WRITE - log a message whenever the property is written.

The second one works only when the property value is changed through
the property manager; tied variables and accessors are not polled for
value changes because of the performance hit.

These methods end up invoking private methods
SGPropertyNode::trace_read and SGPropertyNode::trace_write.  By
setting breakpoints on these methods inside a debugger, it is possible
to debug property access and find what parts of a program are reading
or writing specific property values by doing a backtrace.

In the XML property files, users can use the attributes 'trace-read'
and 'trace-write' to control tracing; the value should be 'y' to
enable tracing or 'n' to disable it (the default).
2001-12-12 02:28:28 +00:00
david 019a9527d2 Added Curt to empty Authors file as CVS test. 2001-12-11 22:23:25 +00:00
curt d100ca485f Doh! fixed a typo ... 2001-12-10 00:24:51 +00:00
curt 35ab6900ee [Hopefully] fix a line ending problem that surfaces in MSVC. 2001-12-09 03:54:46 +00:00
curt c8570302f5 Removed this autogenerated file from CVS. 2001-12-06 22:53:29 +00:00
curt 74f10486bc In certain degenerate situations on the FlightGear side when the flight
model math blows up, the lat/lon could be nan.  Thus updateLocal() could
potentially called with nan arguments if FlightGear is reiniting from a
blown up state.  This is a bug in FlightGear, but I've added a simple
check to catch this so updateLocal() is robust if called under these
circumstances.
2001-12-05 22:31:03 +00:00
curt 2b12425a62 Christian M. says it's bad to chain one constructor call from another.
I can't find anything that addresses this in Stroustrup, but I also don't
see them doing this in any of their examples.  So I have rewritten this
instance to use default arguments to accomplish the same thing.  I imagine
there are other instances of this same sort of thing in other classes to
be fixed at a later date.
2001-11-27 03:17:43 +00:00
curt c600aad7a7 Bernie Bright: support for Intel C++ under Linux. 2001-11-21 21:31:40 +00:00
curt 67b2f0a977 - changed getAttribute to avoid MSVC compiler warning 2001-11-20 20:57:07 +00:00
curt 70c6b48a07 - implemented set/get_log_classes and set/get_log_priority 2001-11-20 20:56:53 +00:00
curt 76084f8538 Oops, typo ... 2001-11-12 18:20:32 +00:00
curt 64c408d2b7 Updated RPM make rule as per Ross Golder. 2001-11-12 17:37:24 +00:00
curt 73b050ae34 Mixed a makefile typo. 2001-11-12 15:27:32 +00:00
curt 59991393ca plib/net based udp client/server sockets. 2001-11-12 04:47:58 +00:00
curt 69b2717b62 One more tiny Irix tweak. 2001-10-24 20:01:15 +00:00
curt f2a323e048 Misc Irix tweaks. 2001-10-24 19:59:05 +00:00
curt 7d07e6ea51 Misc MSVC tweaks. 2001-10-24 19:05:16 +00:00
curt 7c846972bf Macintosh OSX changes. 2001-10-23 20:22:12 +00:00
curt 4f76c258af MSVC tweaks. 2001-08-13 17:14:21 +00:00
curt eca2afb982 Various changes for MingWin32 support. 2001-08-02 22:56:33 +00:00
curt 9ff6934c83 Various MSVC fixes. 2001-07-30 20:34:20 +00:00
curt e04839765d Updates for irix to disable various warnings and define
__STL_FUNCTION_TMPL_PARTIAL_ORDER
2001-07-30 20:05:27 +00:00
curt d0c655109f Oops, missing a trainling backslash after exception.hxx 2001-07-28 04:00:10 +00:00
curt b28b55abb1 - removed declaration of sg_xml_exception (use sg_io_exception) 2001-07-24 21:41:33 +00:00
curt c3a0db1aba - make sure file is closed when an exception passes through 2001-07-24 21:41:19 +00:00
curt 5e929d7d01 - remove dependencies on sg_throwable::clone 2001-07-24 21:41:06 +00:00
curt 17f113f8cd - remove clone methods for exceptions (SGI/Irix compiler bugs)
- added declaration for sg_throwable::getFormattedMessage
- added declaration for sg_io_exception::getFormattedMessage
- added #ifdef wrapper
2001-07-24 21:40:57 +00:00
curt 445cd4ccda - remove clone method declarations (SGI/Irix compiler bugs)
- added default implementation for sg_throwable::getFormattedMessage
  (returns sg_throwable::getMessage by default)
- removed unneeded newline in sg_location::asString
2001-07-24 21:40:46 +00:00
curt 55845bbbb9 Added exceptions.[ch]xx 2001-07-19 02:34:43 +00:00
curt 1976481ba2 - added sg_xml_exception class
- changed return type of readXML from bool to void (uses an exception
  to report problems now)
- removed XMLVisitor::error callback
- declared new readXML function that uses a path rather than a stream
- modified existing readXML function to take an optional path parameter
2001-07-19 02:34:18 +00:00
curt 5f17edbc72 - implemented sg_xml_exception class
- implemented new readXML function with path instead of stream
- modified existing readXML function to use optional path parameter
- modified readXML to throw exceptions rather than returning a bool
  value on error
2001-07-19 02:33:58 +00:00
curt 6f7fe4b481 - modified both readProperties functions to return void, and modified
file-name variant to invoke new readXML function
- readProperties and writeProperties will now throw exceptions if there
  are file I/O problems
- replace error messages with exceptions
- tunnel sg_io_exception through from nested property read, since
  the C-based Expat code cannot handle exceptions
2001-07-19 02:33:38 +00:00
curt 66ebe6e690 - changed return type of both readProperties functions to void
- changed return type of both writeProperties functions to void
2001-07-19 02:33:18 +00:00
curt a9cd67e0ce - new file: implementation of SimGear general exception classes 2001-07-19 02:33:00 +00:00
curt 994a470fbf Prepairing for 0.0.17 2001-07-13 14:58:14 +00:00
curt 0ce0684dae Added a missing include for memcpy() 2001-07-13 03:36:50 +00:00
curt 377eb4782a Updated for 0.0.16 2001-07-13 03:36:29 +00:00
curt f1a79e6b9f - changed default value of "archive" attribute from "y" to "n"
- modified to write out non-archivable parents if they have an
  archivable descendant (i.e. archive="n" no longer kills a whole
  subbranch); this makes sense now that archive defaults to "n".
- don't save the flags -- let the program handle them itself
- produce slightly less verbose output; omit n="0" in elements
2001-07-12 21:09:12 +00:00
curt 007a1e4659 - changed the default value of the archive flag to false; it must now
be set explicitly for a value to be saved
2001-07-12 21:08:58 +00:00
curt fcb873b6dd - added virtual destructor to XMLVisitor to make sure derived classes
get a virtual destructor automatically.
2001-07-11 16:02:26 +00:00
curt a66d1ad855 Check for valid hostname lookup in sg_socket.cxx. 2001-07-10 14:13:51 +00:00
curt 76a5950f19 Add a separate function to just return modified julian date. 2001-07-03 14:39:05 +00:00
curt b7a91bdb03 Various tweaks for Irix. 2001-07-02 20:51:32 +00:00
curt e4bbc5c50b Fix a potential array under/over run bug. 2001-06-30 02:01:22 +00:00
curt b481ccd749 Tweaks to track changes in property manager. 2001-06-28 21:54:02 +00:00
curt e7b9e55599 - removed all reference to SGValue
- renamed UNKNOWN to UNSPECIED and setUnknownValue to
  setUnspecifiedValue
- modified routines to use 'read', 'write', and 'archive' attribute
  for access-mode attributes (only if non-default; they all default to
  'y')
- modified write routine to honour ARCHIVE attribute (won't write
  subtree if ARCHIVE is not set)
2001-06-28 21:53:46 +00:00
curt 05eaa7135f - made getValue methods protected, so that they won't be invoked outside
the class
- renamed UNKNOWN to UNSPECIED and setUnknownValue to
  setUnspecifiedValue
- added access-mode attributes
- added methods for setting and querying access-mode attributes
2001-06-28 21:53:34 +00:00
curt d063b319e8 - attempting to tie an aliased node now fails; the node must be
unaliased first
- renamed UNKNOWN to UNSPECIED and setUnknownValue to
  setUnspecifiedValue
- modified get*Value and set*Value methods to respect READ and WRITE
  attributes
2001-06-28 21:53:24 +00:00
curt be4fd56660 - added SGCommandState class so that commands can compile and save
copies of their arguments
- modified prototype for command functions -- they now take a pointer
  to a pointer of an SGCommandState object (which they will normally
  subclass) so that they can cache state between invocations
- commented out convenience execute methods until they're actually
  needed
2001-06-28 21:53:10 +00:00
curt a406a3c00b - added implementation of SGCommandState
- removed commented-out convenience execute methods
2001-06-28 21:53:01 +00:00
curt c7295da5eb Fixed a type conversion bug that could trip up some of the pickier compilers
out there.
2001-06-27 02:48:01 +00:00
curt 505f561e1c Added tr.cxx / tr.h, Brian Paul's LGPL'd tiled rendering support libs for
rendering ultra high res "tiled" screen shots.
2001-06-26 15:19:39 +00:00
curt 7bd8477fa1 Tweaks. 2001-06-20 18:35:42 +00:00
curt 36ef15940e Changes for 0.7.8 2001-06-20 18:12:18 +00:00
98 changed files with 4995 additions and 2029 deletions
+8
View File
@@ -0,0 +1,8 @@
Makefile
Makefile.in
SimGear.spec
aclocal.m4
config.cache
config.log
config.status
configure
+1
View File
@@ -0,0 +1 @@
Curtis Olsen and others.
+1 -1
View File
@@ -22,7 +22,7 @@ PROJECT_NAME = SimGear
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = 0.0.15
PROJECT_NUMBER = 0.0.17
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
+12 -98
View File
@@ -1,105 +1,19 @@
EXTRA_DIST = mksymlinks.sh acsite.m4 acconfig.h SimGear.dsp SimGear.dsw
EXTRA_DIST = \
acsite.m4 \
acconfig.h \
mksymlinks.sh \
README.metakit \
README.zlib \
SimGear.dsp \
SimGear.dsw \
metakit-2.4.2-32.tar.gz \
zlib-1.1.3.tar.gz
SUBDIRS = simgear
#
# Additional all, clean, and distclean rules for additional packages.
# We can't just include the additional package dirs in SUBDIRS (which
# would be nice because there are then problems with make dist
#
all:
@list='@subdirs@'; \
target=`echo $@`; \
for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done
install:
@list='@subdirs@'; \
target=`echo $@`; \
for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done
clean:
@list='@subdirs@'; \
target=`echo $@`; \
for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done
distclean:
@list='@subdirs@'; \
target=`echo $@`; \
for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done
#
# distclean the associated packages and include them in the dist
#
dist-hook:
(cd $(top_srcdir); \
$(HOME)/projects/FlightGear-0.7/admin/am2dsp.pl --lib)
pwd
echo "copying simgear/metar"
(cd $(top_srcdir); tar cf - simgear/metar) | (cd $(distdir); tar xvf -)
echo "other stuff"
@list='@subdirs@'; \
target=distclean; \
for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) echo "distclean error ignored...";; *k*) fail=yes;; *) echo "distclean error ignored...";; esac; \
done
(cd $(top_srcdir); tar cf - simgear/metakit) | \
(cd $(distdir); tar xvf -)
SUBDIRS = simgear
#
# Rule to build RPM distribution package
#
rpm: dist
cp $(PACKAGE)-$(VERSION).tar.gz /usr/src/packages/SOURCES
rpm -ba @PACKAGE@.spec
rpm -ta $(PACKAGE)-$(VERSION).tar.gz
+63 -1
View File
@@ -1,5 +1,67 @@
New in 0.0.17 (final)
* February 16, 2002
* Converted some cout's to SG_LOG's.
* xplicitely reset the glBlendFunc() after drawing the moon for the
Voodoo2 linux driver since it seems to have a bug in glPopAttrib().
New in 0.0.17pre2
* February 13, 2002
* Replaced some cout's with SG_LOG's
New in 0.0.17pre1
* February 12, 2002
* Removed metakit and zlib from build process. Tarballs are still included
for those who's systems don't provide these packages.
* MSVC fixes.
* IRIX fixes.
* Mingwin fixes.
* Mac OS X fixes.
* FreeBSD fixes.
* Added support for Intel's C++ compiler under Linux.
* Attempt to build in support for various non-compatible automake/autoconf
versions.
* Fix for a problem that could lead to a bogus build for people with voodoo
cards.
* Added Norman's jpegfactory code which can create jpeg format screen shots
of a live running application.
* implemented set/get_log_classes and set/get_log_priority.
* Socket library improvements.
* Added a C++ exception abstraction.
* Property manager fixes and improvements including node path caching
and debug tracing of property reads/writes.
* Updates/fixes to xml handling.
New in 0.0.16
* July 12, 2001
* Various changes to the property manager implimentation to better support
dumping out the desired portions of the property tree to file.
* Don't compile the metakit demos by default (causes problems for Irix)'
* Other various tweaks for Irix.
* Added a virtual destructor to XMLVisitor to fix a warning message.
* Check for valid hostname lookup in sg_socket.cxx
* Add a function to return modified julian date without creating an
entire SGTime class. This avoids an extraneous warning about not
being able to find a timezone.
* Created a mailing list for cvs commit messages.
* Fixed a potential array under/over run bug in interpolator.cxx
* Removed all references to SGValue from the property manager. Added
support for an "archive" bit in the property manager to control
which values get written out.
* Added SGCommandState class so that commands can compile and save
copies of their arguments for efficiency if they are called multiple
times.
* Added Brian Baul's "tr" tiled rendering low level support library.
This along with some higher level code in flightgear allows us to do
ultra-hires tiled screen dumps suitable for large format printers.
(Norman Vine)
New in 0.0.15
* June 22, 2001
* June 20, 2001
* Various bug fixes, tweaks, and optimizations.
* Added a command manager (analogous to the property manager)
* Better Irix Mips support.
+1 -3
View File
@@ -1,3 +1 @@
MSVC5 users:
Copy simgear/config.h.vc5 to simgear/config.h before building.
[ Nothing here at this time. ]
+19 -2
View File
@@ -1,6 +1,23 @@
With the author's permission, SimGear now bundles MetaKit.
For your convenience (and with the author's permission) a copy of the
MetaKit source is bundled with SimGear. You must have metakit
installed before you can build SimGear.
Important build note:
- Most linux distributions have a metakit package. For linux
developers, we recommend ysou install your distributions package
rather than building from source.
- For developers on most other platforms, you will have to build
metakit from source and install it yourself. For your convenience a
tar ball of the metakit source is included with the simgear source
distribution. Untar the metakit source, and follow the included
build and installation instructions.
Once metakit is installed you can return to configuring and building
Simgear.
=============================================================================
Potentially important build note:
Later on when you are linking programs with -lmk4 (i.e. FlightGear or one
of it's associated programs) if you come across an error similar to the
+173
View File
@@ -0,0 +1,173 @@
For your convenience and allowed by zlib's license terms:
http://www.gzip.org/zlib/zlib_license.html a copy of the zlib source
is bundled with SimGear. You must have zlib installed before you can
build SimGear.
- Most linux distributions have a zlib package. For linux
developers, we recommend ysou install your distributions package
rather than building from source.
- Cygwin installs zlib automatically.
- For developers on most other platforms, you will have to build
zlib from source and install it yourself. For your convenience a
tar ball of the zlib source is included with the simgear source
distribution. Untar the zlib source, and follow the included
build and installation instructions.
Once zlib is installed you can return to configuring and building
Simgear.
We now send you to the official zlib README ...
=============================================================================
zlib 1.1.3 is a general purpose data compression library. All the code
is thread safe. The data format used by the zlib library
is described by RFCs (Request for Comments) 1950 to 1952 in the files
ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate
format) and rfc1952.txt (gzip format). These documents are also available in
other formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
All functions of the compression library are documented in the file zlib.h
(volunteer to write man pages welcome, contact jloup@gzip.org). A usage
example of the library is given in the file example.c which also tests that
the library is working correctly. Another example is given in the file
minigzip.c. The compression library itself is composed of all source files
except example.c and minigzip.c.
To compile all files and run the test program, follow the instructions
given at the top of Makefile. In short "make test; make install"
should work for most machines. For Unix: "configure; make test; make install"
For MSDOS, use one of the special makefiles such as Makefile.msc.
For VMS, use Make_vms.com or descrip.mms.
Questions about zlib should be sent to <zlib@quest.jpl.nasa.gov>, or to
Gilles Vollant <info@winimage.com> for the Windows DLL version.
The zlib home page is http://www.cdrom.com/pub/infozip/zlib/
The official zlib ftp site is ftp://ftp.cdrom.com/pub/infozip/zlib/
Before reporting a problem, please check those sites to verify that
you have the latest version of zlib; otherwise get the latest version and
check whether the problem still exists or not.
Mark Nelson <markn@tiny.com> wrote an article about zlib for the Jan. 1997
issue of Dr. Dobb's Journal; a copy of the article is available in
http://web2.airmail.net/markn/articles/zlibtool/zlibtool.htm
The changes made in version 1.1.3 are documented in the file ChangeLog.
The main changes since 1.1.2 are:
- fix "an inflate input buffer bug that shows up on rare but persistent
occasions" (Mark)
- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
- fix gzseek(..., SEEK_SET) in write mode
- fix crc check after a gzeek (Frank Faubert)
- fix miniunzip when the last entry in a zip file is itself a zip file
(J Lillge)
- add contrib/asm586 and contrib/asm686 (Brian Raiter)
See http://www.muppetlabs.com/~breadbox/software/assembly.html
- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
- added a FAQ file
plus many changes for portability.
Unsupported third party contributions are provided in directory "contrib".
A Java implementation of zlib is available in the Java Development Kit 1.1
http://www.javasoft.com/products/JDK/1.1/docs/api/Package-java.util.zip.html
See the zlib home page http://www.cdrom.com/pub/infozip/zlib/ for details.
A Perl interface to zlib written by Paul Marquess <pmarquess@bfsec.bt.co.uk>
is in the CPAN (Comprehensive Perl Archive Network) sites, such as:
ftp://ftp.cis.ufl.edu/pub/perl/CPAN/modules/by-module/Compress/Compress-Zlib*
A Python interface to zlib written by A.M. Kuchling <amk@magnet.com>
is available in Python 1.5 and later versions, see
http://www.python.org/doc/lib/module-zlib.html
A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com>
is availlable at http://www.westend.com/~kupries/doc/trf/man/man.html
An experimental package to read and write files in .zip format,
written on top of zlib by Gilles Vollant <info@winimage.com>, is
available at http://www.winimage.com/zLibDll/unzip.html
and also in the contrib/minizip directory of zlib.
Notes for some targets:
- To build a Windows DLL version, include in a DLL project zlib.def, zlib.rc
and all .c files except example.c and minigzip.c; compile with -DZLIB_DLL
The zlib DLL support was initially done by Alessandro Iacopetti and is
now maintained by Gilles Vollant <info@winimage.com>. Check the zlib DLL
home page at http://www.winimage.com/zLibDll
From Visual Basic, you can call the DLL functions which do not take
a structure as argument: compress, uncompress and all gz* functions.
See contrib/visual-basic.txt for more information, or get
http://www.tcfb.com/dowseware/cmp-z-it.zip
- For 64-bit Irix, deflate.c must be compiled without any optimization.
With -O, one libpng test fails. The test works in 32 bit mode (with
the -n32 compiler flag). The compiler bug has been reported to SGI.
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1
it works when compiled with cc.
- on Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1
is necessary to get gzprintf working correctly. This is done by configure.
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works
with other compilers. Use "make test" to check your compiler.
- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
- For Turbo C the small model is supported only with reduced performance to
avoid any far allocation; it was tested with -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3
- For PalmOs, see http://www.cs.uit.no/~perm/PASTA/pilot/software.html
Per Harald Myrvang <perm@stud.cs.uit.no>
Acknowledgments:
The deflate format used by zlib was defined by Phil Katz. The deflate
and zlib specifications were written by L. Peter Deutsch. Thanks to all the
people who reported problems and suggested various improvements in zlib;
they are too numerous to cite here.
Copyright notice:
(C) 1995-1998 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
If you use the zlib library in a product, we would appreciate *not*
receiving lengthy legal documents to sign. The sources are provided
for free but without warranty of any kind. The library has been
entirely written by Jean-loup Gailly and Mark Adler; it does not
include third-party code.
If you redistribute modified sources, we would appreciate that you include
in the file ChangeLog history information documenting your changes.
+60 -33
View File
@@ -41,7 +41,7 @@ RSC=rc.exe
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "\usr\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "HAVE_CONFIG_H" /I "." /I ".." /I ".\SimGear" /D "HAVE_CONFIG_H" /D "NDEBUG" /D "WIN32" /D "_MBCS" /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
@@ -64,7 +64,7 @@ LINK32=link.exe -lib
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /GX /ZI /Od /I "\usr\include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FR /FD /GZ /c
# ADD CPP /nologo /W3 /GX /ZI /Od /D "HAVE_CONFIG_H" /I "." /I ".." /I ".\SimGear" /D "HAVE_CONFIG_H" /D "_DEBUG" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
@@ -80,18 +80,6 @@ LINK32=link.exe -lib
# Name "SimGear - Win32 Release"
# Name "SimGear - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Group "Lib_sgbucket"
# PROP Default_Filter ""
@@ -785,6 +773,21 @@ SOURCE=.\simgear\misc\commands.cxx
# End Source File
# Begin Source File
SOURCE=.\simgear\misc\exception.cxx
!IF "$(CFG)" == "SimGear - Win32 Release"
# PROP Intermediate_Dir "Release\Lib_sgmisc"
!ELSEIF "$(CFG)" == "SimGear - Win32 Debug"
# PROP Intermediate_Dir "Debug\Lib_sgmisc"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\simgear\misc\props.cxx
!IF "$(CFG)" == "SimGear - Win32 Release"
@@ -973,6 +976,21 @@ SOURCE=.\simgear\screen\screen-dump.cxx
# End Source File
# Begin Source File
SOURCE=.\simgear\screen\tr.cxx
!IF "$(CFG)" == "SimGear - Win32 Release"
# PROP Intermediate_Dir "Release\Lib_sgscreen"
!ELSEIF "$(CFG)" == "SimGear - Win32 Debug"
# PROP Intermediate_Dir "Debug\Lib_sgscreen"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\simgear\screen\win32-printer.h
!IF "$(CFG)" == "SimGear - Win32 Release"
@@ -1113,25 +1131,6 @@ SOURCE=.\simgear\sky\stars.cxx
!ENDIF
# End Source File
# End Group
# Begin Group "Lib_sgthreads"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\simgear\threads\SGThread.cxx
!IF "$(CFG)" == "SimGear - Win32 Release"
# PROP Intermediate_Dir "Release\Lib_sgthreads"
!ELSEIF "$(CFG)" == "SimGear - Win32 Debug"
# PROP Intermediate_Dir "Debug\Lib_sgthreads"
!ENDIF
# End Source File
# End Group
# Begin Group "Lib_sgtiming"
@@ -1840,5 +1839,33 @@ SOURCE=.\simgear\zlib\zutil.h
# End Source File
# End Group
# Begin Source File
SOURCE = .\simgear\simgear_config.h.vc5
!IF "$(CFG)" == "FlightGear - Win32 Release"
# Begin Custom Build - Creating config.h
InputPath=.\simgear\simgear_config.h.vc5
".\simgear\simgear_config.h": $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy .\simgear\simgear_config.h.vc5 .\simgear\simgear_config.h
# End Custom Build
!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug"
# Begin Custom Build - Creating config.h
InputPath=.\simgear\simgear_config.h.vc5
".\simgear\simgear_config.h": $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy .\simgear\simgear_config.h.vc5 .\simgear\simgear_config.h
# End Custom Build
!ENDIF
# End Source File
# End Target
# End Project
-6
View File
@@ -184,12 +184,6 @@
/* Define if you have the wait3 system call. */
#undef HAVE_WAIT3
/* Define if you have gdbm installed system wide. */
/* #undef HAVE_GDBM */
/* Define if you have zlib installed system wide. */
#undef HAVE_ZLIB
/* Define as __inline if that's what the C compiler calls it. */
#undef inline
Vendored
-140
View File
@@ -1,140 +0,0 @@
dnl aclocal.m4 generated automatically by aclocal 1.4
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
dnl PARTICULAR PURPOSE.
# Do all the work for Automake. This macro actually does too much --
# some checks are only needed if your package does certain things.
# But this isn't really a big deal.
# serial 1
dnl Usage:
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
AC_DEFUN(AM_INIT_AUTOMAKE,
[AC_REQUIRE([AC_PROG_INSTALL])
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
AC_SUBST(VERSION)
dnl test to see if srcdir already configured
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
ifelse([$3],,
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
AC_REQUIRE([AM_SANITY_CHECK])
AC_REQUIRE([AC_ARG_PROGRAM])
dnl FIXME This is truly gross.
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_REQUIRE([AC_PROG_MAKE_SET])])
#
# Check to make sure that the build environment is sane.
#
AC_DEFUN(AM_SANITY_CHECK,
[AC_MSG_CHECKING([whether build environment is sane])
# Just in case
sleep 1
echo timestamp > conftestfile
# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
if test "[$]*" = "X"; then
# -L didn't work.
set X `ls -t $srcdir/configure conftestfile`
fi
if test "[$]*" != "X $srcdir/configure conftestfile" \
&& test "[$]*" != "X conftestfile $srcdir/configure"; then
# If neither matched, then we have a broken ls. This can happen
# if, for instance, CONFIG_SHELL is bash and it inherits a
# broken ls alias from the environment. This has actually
# happened. Such a system could not be considered "sane".
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
alias in your environment])
fi
test "[$]2" = conftestfile
)
then
# Ok.
:
else
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
rm -f conftest*
AC_MSG_RESULT(yes)])
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
dnl The program must properly implement --version.
AC_DEFUN(AM_MISSING_PROG,
[AC_MSG_CHECKING(for working $2)
# Run test in a subshell; some versions of sh will print an error if
# an executable is not found, even if stderr is redirected.
# Redirect stdin to placate older versions of autoconf. Sigh.
if ($2 --version) < /dev/null > /dev/null 2>&1; then
$1=$2
AC_MSG_RESULT(found)
else
$1="$3/missing $2"
AC_MSG_RESULT(missing)
fi
AC_SUBST($1)])
# Define a conditional.
AC_DEFUN(AM_CONDITIONAL,
[AC_SUBST($1_TRUE)
AC_SUBST($1_FALSE)
if $2; then
$1_TRUE=
$1_FALSE='#'
else
$1_TRUE='#'
$1_FALSE=
fi])
# Like AC_CONFIG_HEADER, but automatically create stamp file.
AC_DEFUN(AM_CONFIG_HEADER,
[AC_PREREQ([2.12])
AC_CONFIG_HEADER([$1])
dnl When config.status generates a header, we must update the stamp-h file.
dnl This file resides in the same directory as the config header
dnl that is generated. We must strip everything past the first ":",
dnl and everything past the last "/".
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
<<am_indx=1
for am_file in <<$1>>; do
case " <<$>>CONFIG_HEADERS " in
*" <<$>>am_file "*<<)>>
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
;;
esac
am_indx=`expr "<<$>>am_indx" + 1`
done<<>>dnl>>)
changequote([,]))])
+40
View File
@@ -0,0 +1,40 @@
exclude_dir = threads
include_path = .
include_path = ..
include_path = .\SimGear
#include_path = \usr\include
define = HAVE_CONFIG_H
#add_project = .\SimGear\simgear\metakit\win\msvc60\mklib.dsp
# Rule to create simgear_config.h
add_source_file = \
# Begin Source File\
\
SOURCE = .\simgear\simgear_config.h.vc5\
\
!IF "$(CFG)" == "FlightGear - Win32 Release"\
\
# Begin Custom Build - Creating config.h\
InputPath=.\simgear\simgear_config.h.vc5\
\
".\simgear\simgear_config.h": $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\
copy .\simgear\simgear_config.h.vc5 .\simgear\simgear_config.h\
\
# End Custom Build\
\
!ELSEIF "$(CFG)" == "FlightGear - Win32 Debug"\
\
# Begin Custom Build - Creating config.h\
InputPath=.\simgear\simgear_config.h.vc5\
\
".\simgear\simgear_config.h": $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\
copy .\simgear\simgear_config.h.vc5 .\simgear\simgear_config.h\
\
# End Custom Build\
\
!ENDIF\
\
# End Source File
Executable
+57
View File
@@ -0,0 +1,57 @@
#!/bin/sh
OSTYPE=`uname -s`
MACHINE=`uname -m`
AUTO_MAKE_VERSION=`automake --version | head -1 | awk '{print $4}' | sed -e 's/\-p[0-9]$//' | sed -e 's/\.//'`
echo "Host info: $OSTYPE $MACHINE"
echo -n " automake: `automake --version | head -1 | awk '{print $4}'`"
echo " ($AUTO_MAKE_VERSION)"
echo ""
ACLOCAL_OPTS=""
if [ $AUTO_MAKE_VERSION -ge 14 ]; then
if [ $OSTYPE = "IRIX" -o $OSTYPE = "IRIX64" ]; then echo " -I ."
ACLOCAL_OPTS="-I ."
fi
fi
echo "Running aclocal $ACLOCAL_OPTS"
aclocal $ACLOCAL_OPTS
echo "Running autoheader"
autoheader
echo -n "Running automake"
if [ $OSTYPE = "IRIX" -o $OSTYPE = "IRIX64" ]; then
echo " --add-missing --include-deps"
automake --add-missing --include-deps
else
echo " --add-missing"
automake --add-missing
fi
echo "Running autoconf"
autoconf
# fixup Makefiles for Irix
if test "$OSTYPE" = "IRIX" -o "$OSTYPE" = "IRIX64"; then
echo "Fixing Makefiles for Irix"
for n in `find . -name Makefile.in`; do \
mv -f $n $n.ar-new; \
sed 's/$(AR) cru /$(AR) -o /g' $n.ar-new > $n; \
rm -f $n.ar-new; \
done;
fi
echo ""
echo "======================================"
if [ -f config.cache ]; then
echo "config.cache exists. Removing the config.cache file will force"
echo "the ./configure script to rerun all it's tests rather than using"
echo "the previously cached values."
echo ""
fi
echo "Now you are ready to run './configure'"
echo "======================================"
+99 -66
View File
@@ -5,8 +5,11 @@ dnl $Id$
AC_INIT(simgear/bucket/newbucket.cxx)
# Require at least automake 2.13
AC_PREREQ(2.13)
dnl Initialize the automake stuff
AM_INIT_AUTOMAKE(SimGear, 0.0.15)
AM_INIT_AUTOMAKE(SimGear, 0.0.17pre2)
dnl Specify KAI C++ compiler and flags.
dnl Borrowed with slight modification from blitz distribution.
@@ -49,7 +52,12 @@ else
includedir="${includedir}/simgear"
echo "includedir changed to" $includedir "libdir is" $libdir
fi
# Determine version of automake ... important because of
# incompatibilities between versions
AUTO_MAKE_VERSION=`automake --version | head -1 | awk '{print $4}' | sed -e 's/\-p[[0-9]]$//' | sed -e 's/\.//'`
AM_CONDITIONAL(ANCIENT_AUTOMAKE, test $AUTO_MAKE_VERSION -lt 14)
AM_CONDITIONAL(OLD_AUTOMAKE, test $AUTO_MAKE_VERSION -lt 15)
# set logging default value
# with_logging=yes
@@ -58,7 +66,7 @@ if test "x$with_logging" = "xno" ; then
AC_DEFINE(FG_NDEBUG)
fi
dnl specify if we are building with "checker"
dnl specify if we are building with "electric fence"
AC_ARG_WITH(efence, [ --with-efence Specify if we are building with "electric-fence"])
if test "x$with_efence" = "xyes" ; then
@@ -66,21 +74,59 @@ if test "x$with_efence" = "xyes" ; then
LIBS="$LIBS -lefence"
fi
# Specify if we want to build with Norman's jpeg image server support.
# This requires libjpeg to be installed and available.
# Default to with_jpeg_server=no
JPEGLIB=''
AC_ARG_WITH(jpeg_factory, [ --with-jpeg-factory Include Norman's jpeg image factory support code])
if test "x$with_jpeg_factory" = "xyes" ; then
echo "Building with Norman's jpeg image factory support"
AC_CHECK_LIB(jpeg, jpeg_start_compress)
if test "x$ac_cv_lib_jpeg_jpeg_start_compress" != "xyes" ; then
echo
echo "In order to build the jpeg factory code you need libjpeg installed."
echo "otherwise please configure with the --with-jpeg-sever=no option"
echo
echo "libjpeg is available at :"
echo " ftp://ftp.uu.net in the directory graphics/jpeg"
exit 1
fi
else
echo "Building without Norman's jpeg image server support"
fi
AM_CONDITIONAL(ENABLE_JPEG_SERVER, test "x$with_jpeg_factory" = "xyes")
dnl Check for MS Windows environment
AC_CHECK_HEADER(windows.h)
dnl extra library and include directories
EXTRA_DIRS="/usr/local /usr/local/plib /usr/X11R6"
AC_EGREP_CPP(yes,
[#ifdef __MINGW32__
yes
#endif
],is_mingw=yes, is_mingw=no)
if test -d /opt/X11R6 ; then
EXTRA_DIRS="$EXTRA_DIRS /opt/X11R6"
echo "IS_MINGW = $is_mingw"
AM_CONDITIONAL(IS_MINGW, test "x$is_mingw" = "xyes")
AC_EGREP_CPP(yes,
[#ifdef __CYGWIN__
yes
#endif
],is_cygwin=yes, is_cygwin=no)
echo "IS_CYGWIN = $is_cygwin"
AM_CONDITIONAL(IS_CYGWIN, test "x$is_cygwin" = "xyes")
if test "x$HOSTTYPE" != "xmacintosh" -a "x$is_mingw" != "xyes"; then
dnl extra library and include directories
EXTRA_DIRS="/usr/local /usr/local/plib /usr/X11R6"
if test -d /opt/X11R6 ; then
EXTRA_DIRS="$EXTRA_DIRS /opt/X11R6"
fi
fi
if test "x$ac_cv_header_windows_h" = "xyes" ; then
EXTRA_DIRS="${EXTRA_DIRS} `pwd`/Win32"
# elif test `uname -s` = "SunOS" ; then
# EXTRA_DIRS="${EXTRA_DIRS} `pwd`/SunOS"
fi
wi_EXTRA_DIRS(no, ${EXTRA_DIRS})
dnl Using AM_CONDITIONAL is a step out of the protected little
@@ -93,8 +139,11 @@ dnl includes, compile alternative source files, etc.
dnl Enable serial support on Unix type systems
AM_CONDITIONAL(ENABLE_UNIX_SERIAL, true)
dnl Check for X11 (fancy)
AC_PATH_XTRA
dnl X11 might be installed on Mac OS X, don't want to use it if it is.
if test "x$HOSTTYPE" != "xmacintosh" ; then
dnl Check for X11 (fancy)
AC_PATH_XTRA
fi
dnl Checks for libraries.
@@ -114,18 +163,25 @@ fi
AM_CONDITIONAL(HAVE_THREADS, test "x$ac_cv_lib_pthread_pthread_exit" = "xyes" -a "x$ac_cv_header_pthread_h" = "xyes")
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(X11, XCreateWindow)
AC_CHECK_LIB(Xext, XShmCreateImage)
AC_CHECK_LIB(Xi, XGetExtensionVersion)
AC_CHECK_LIB(ICE, IceOpenConnection)
AC_CHECK_LIB(SM, SmcOpenConnection)
AC_CHECK_LIB(Xt, XtMalloc)
AC_CHECK_LIB(Xmu, XmuLookupStandardColormap)
dnl X11 might be installed, but we don't want to use it for OSX -dw-
if test "x$HOSTTYPE" != "xmacintosh" ; then
AC_CHECK_LIB(X11, XCreateWindow)
AC_CHECK_LIB(Xext, XShmCreateImage)
AC_CHECK_LIB(Xi, XGetExtensionVersion)
AC_CHECK_LIB(ICE, IceOpenConnection)
AC_CHECK_LIB(SM, SmcOpenConnection)
AC_CHECK_LIB(Xt, XtMalloc)
AC_CHECK_LIB(Xmu, XmuLookupStandardColormap)
fi
dnl check for OpenGL related libraries
if test "x$ac_cv_header_windows_h" != "xyes" ; then
dnl Reasonable stuff for non-windoze variants ... :-)
if test "x$HOSTTYPE" = "xmacintosh" ; then
dnl Macintosh OSX
LIBS="$LIBS -framework OpenGL -framework GLUT"
elif test "x$ac_cv_header_windows_h" != "xyes" ; then
dnl Reasonable stuff for X-Windows based machines
AC_CHECK_LIB(GLcore, glNewList)
if test "x$ac_cv_lib_GLcore_glNewList" = "xno" ; then
@@ -142,8 +198,8 @@ if test "x$ac_cv_header_windows_h" != "xyes" ; then
dnl if using mesa, check for xmesa.h
if test "x$ac_cv_lib_MesaGL_glNewList" = "xyes" ; then
AC_CHECK_HEADER(GL/xmesa.h)
if test "x$ac_cv_header_GL_xmesa_h" = "xyes"; then
AC_CHECK_HEADER(GL/fxmesa.h)
if test "x$ac_cv_header_GL_fxmesa_h" = "xyes"; then
AC_DEFINE( XMESA )
AC_DEFINE( FX )
fi
@@ -164,8 +220,7 @@ if test "x$ac_cv_header_windows_h" != "xyes" ; then
AC_CHECK_LIB(glut, glutGameModeString)
LIBS="$save_LIBS"
else
dnl Win32 is a little wierd because it has to try to handle the various
dnl winbloze-isms. We'll just do this manually for now.
dnl Win32 libs
echo Win32 specific hacks...
AC_DEFINE(WIN32)
@@ -191,6 +246,9 @@ else
LIBS="$LIBS -l${WIN32_GLUT} -l${WIN32_GLU} -l${WIN32_OPENGL}"
LIBS="$LIBS -luser32 -lgdi32"
if test "x$is_mingw" = "xyes" ; then
EXTRA_DIRS="${EXTRA_DIRS}"
fi
echo "Will link apps with $LIBS"
fi
@@ -231,35 +289,24 @@ if test "x$ac_cv_header_plib_pu_h" != "xyes"; then
exit
fi
# dnl Check for system installed gdbm
# AC_CHECK_HEADER(gdbm.h)
# if test "x$ac_cv_header_gdbm_h" = "xyes"; then
# AC_DEFINE( HAVE_GDBM )
# else
# echo "no gdbm found, configuring and building."
# fi
# AM_CONDITIONAL(HAVE_GDBM, test "x$ac_cv_header_gdbm_h" = "xyes" )
dnl Check for system installed metakit
AC_CHECK_HEADER(mk4.h)
if test "x$ac_cv_header_mk4_h" != "xyes"; then
echo "no metakit found, configuring and building."
# Run configure in the metakit subdir
AC_CONFIG_SUBDIRS( simgear/metakit/unix )
echo "Metakit not found, you will need to install this first."
echo "Please read the README.metakit for more information."
exit
fi
AM_CONDITIONAL(HAVE_METAKIT, test "x$ac_cv_header_mk4_h" = "xyes" )
dnl Specify if we want logging (testing build) or not (release build)
dnl Check for system installed zlib
AC_CHECK_HEADER(zlib.h)
if test "x$ac_cv_header_zlib_h" = "xyes"; then
AC_DEFINE( HAVE_ZLIB )
else
echo "no zlib found, building."
if test "x$ac_cv_header_zlib_h" != "xyes"; then
echo "zlib not found, you will need to install this first."
echo "Please read the README.zlib for more information."
exit
fi
AM_CONDITIONAL(HAVE_ZLIB, test "x$ac_cv_header_zlib_h" = "xyes" )
dnl Checks for header files.
AC_HEADER_STDC
@@ -306,14 +353,9 @@ AC_OUTPUT( \
simgear/timing/Makefile \
simgear/xgl/Makefile \
simgear/xml/Makefile \
simgear/zlib/Makefile \
)
AC_OUTPUT_COMMANDS([
# if test "x$ac_cv_header_windows_h" = "xyes" ; then
# cp simgear/gdbm/autoconf.h.cygwin32 simgear/gdbm/autoconf.h
# fi
])
# AC_OUTPUT_COMMANDS([])
echo ""
echo "Configure Summary"
@@ -333,16 +375,13 @@ else
echo "Electric fence: no"
fi
# if test "x$ac_cv_header_gdbm_h" != "xyes"; then
# echo "Building gdbm"
# fi
echo -n "Automake version: ($AUTO_MAKE_VERSION) "
automake --version | head -1
if test "x$ac_cv_header_mk4_h" != "xyes"; then
echo "Building metakit"
fi
if test "x$ac_cv_header_zlib_h" != "xyes"; then
echo "Building zlib"
if test "x$with_jpeg_factory" = "xyes"; then
echo "With JPEG Factory support"
else
echo "Without JPEG Factory support"
fi
if test "x$ac_cv_lib_pthread_pthread_exit" = "xyes" -a "x$ac_cv_header_pthread_h" = "xyes"; then
@@ -350,9 +389,3 @@ if test "x$ac_cv_lib_pthread_pthread_exit" = "xyes" -a "x$ac_cv_header_pthread_h
else
echo "Threads: no threads (pthread lib not found.)"
fi
if test "$OS" = "IRIX" -o "$OS" = "IRIX64"; then
if test "$CXX" = "CC"; then
echo "\nRemember to run: sh ../FlightGear/irix-hack.sh!\07\n"
fi
fi
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
Makefile
Makefile.in
simgear_config.h
stamp-h
stamp-h.in
version.h
+1 -14
View File
@@ -4,18 +4,6 @@ else
SERIAL_DIRS =
endif
# if HAVE_GDBM
# GDBM_DIRS =
# else
# GDBM_DIRS = gdbm
# endif
if HAVE_ZLIB
ZLIB_DIRS =
else
ZLIB_DIRS = zlib
endif
if HAVE_THREADS
SGTHREAD_DIR = threads
else
@@ -25,13 +13,12 @@ endif
# METAR_DIRS =
METAR_DIRS = metar
EXTRA_DIST = version.h.in
EXTRA_DIST = simgear_config.h.vc5 version.h.in
include_HEADERS = \
compiler.h constants.h sg_inlines.h sg_traits.hxx sg_zlib.h version.h
SUBDIRS = \
$(ZLIB_DIRS) \
xml \
debug \
misc \
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -14,4 +14,8 @@ libsgbucket_a_SOURCES = newbucket.cxx
# $(top_builddir)/bucket/libsgbucket.a \
# $(top_builddir)/misc/libsgmisc.a
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+39
View File
@@ -139,6 +139,11 @@
# endif
#endif
#if defined( __MINGW32__ )
# define bcopy(from, to, n) memcpy(to, from, n)
# define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
#endif
/* KAI C++ */
#if defined(__KCC)
@@ -278,6 +283,19 @@
# define STL_STRING <string>
# define STL_STRSTREAM <strstream.h>
// # define __STL_FUNCTION_TMPL_PARTIAL_ORDER
// typedef void PFNGLPOINTPARAMETERFEXTPROC
#define glPointParameterfEXT glPointParameterfSGIS
#define glPointParameterfvEXT glPointParameterfvSGIS
#pragma set woff 1001,1012,1014,1116,1155,1172,1174
#pragma set woff 1401,1460,1551,1552,1681
#ifdef __cplusplus
#pragma set woff 1682,3303
#endif
#endif // Native SGI compilers
@@ -294,6 +312,27 @@
# endif // __cplusplus
#endif // sun
//
// Intel C++ Compiler
//
#if defined(__ICC)
# define SG_NAMESPACES
# define SG_HAVE_STD
# define SG_HAVE_STREAMBUF
# define SG_HAVE_TRAITS
# define SG_HAVE_STD_INCLUDES
# define STL_ALGORITHM <algorithm>
# define STL_FUNCTIONAL <functional>
# define STL_IOMANIP <iomanip>
# define STL_IOSTREAM <iostream>
# define STL_ITERATOR <iterator>
# define STL_FSTREAM <fstream>
# define STL_STDEXCEPT <stdexcept>
# define STL_STRING <string>
# define STL_STRSTREAM <strstream>
#endif // __ICC
//
// No user modifiable definitions beyond here.
//
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -8,4 +8,8 @@ include_HEADERS = debug_types.h logstream.hxx
libsgdebug_a_SOURCES = logstream.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+24
View File
@@ -56,6 +56,30 @@ logbuf::set_log_level( sgDebugClass c, sgDebugPriority p )
logPriority = p;
}
void
logbuf::set_log_classes (sgDebugClass c)
{
logClass = c;
}
sgDebugClass
logbuf::get_log_classes ()
{
return logClass;
}
void
logbuf::set_log_priority (sgDebugPriority p)
{
logPriority = p;
}
sgDebugPriority
logbuf::get_log_priority ()
{
return logPriority;
}
void
logstream::setLogLevels( sgDebugClass c, sgDebugPriority p )
{
+29
View File
@@ -105,6 +105,35 @@ public:
*/
static void set_log_level( sgDebugClass c, sgDebugPriority p );
/**
* Set the allowed logging classes.
* @param c All enabled logging classes anded together.
*/
static void set_log_classes (sgDebugClass c);
/**
* Get the logging classes currently enabled.
* @return All enabled debug logging anded together.
*/
static sgDebugClass get_log_classes ();
/**
* Set the logging priority.
* @param c The priority cutoff for logging messages.
*/
static void set_log_priority (sgDebugPriority p);
/**
* Get the current logging priority.
* @return The priority cutoff for logging messages.
*/
static sgDebugPriority get_log_priority ();
/**
* Set the stream buffer
* @param sb stream buffer
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -31,4 +31,8 @@ libsgephem_a_SOURCES = \
uranus.cxx \
venus.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+6 -2
View File
@@ -32,10 +32,14 @@
#endif
// Constructor
SGStarData::SGStarData() {
SGStarData::SGStarData() :
nstars(0)
{
}
SGStarData::SGStarData( SGPath path ) {
SGStarData::SGStarData( SGPath path ) :
nstars(0)
{
data_path = SGPath( path );
load();
}
+6
View File
@@ -0,0 +1,6 @@
.deps
Makefile
Makefile.in
decode_binobj
lowtest
socktest
+17 -3
View File
@@ -8,7 +8,8 @@ include_HEADERS = \
sg_binobj.hxx \
sg_file.hxx \
sg_serial.hxx \
sg_socket.hxx
sg_socket.hxx \
sg_socket_udp.hxx
libsgio_a_SOURCES = \
iochannel.cxx \
@@ -16,9 +17,20 @@ libsgio_a_SOURCES = \
sg_binobj.cxx \
sg_file.cxx \
sg_serial.cxx \
sg_socket.cxx
sg_socket.cxx \
sg_socket_udp.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
if IS_MINGW
NETWORK_LIB = -lwsock32
else
NETWORK_LIB =
endif
noinst_PROGRAMS = decode_binobj socktest lowtest
@@ -29,6 +41,7 @@ socktest_LDADD = \
$(top_builddir)/simgear/io/libsgio.a \
$(top_builddir)/simgear/debug/libsgdebug.a \
$(top_builddir)/simgear/misc/libsgmisc.a \
$(top_builddir)/simgear/xml/libsgxml.a \
-lz
lowtest_SOURCES = lowtest.cxx
@@ -43,4 +56,5 @@ decode_binobj_LDADD = \
$(top_builddir)/simgear/bucket/libsgbucket.a \
$(top_builddir)/simgear/misc/libsgmisc.a \
$(top_builddir)/simgear/debug/libsgdebug.a \
-lz
$(top_builddir)/simgear/xml/libsgxml.a \
$(NETWORK_LIB) -lz
+1
View File
@@ -158,6 +158,7 @@ public:
inline void set_dir( const SGProtocolDir d ) { dir = d; }
inline SGProtocolDir get_dir() const { return dir; }
inline bool isvalid() const { return valid; }
inline void set_valid( const bool v ) { valid = v; }
};
+2
View File
@@ -23,6 +23,8 @@
// $Id$
#include <string.h> // for memcpy()
#include "lowlevel.hxx"
+1 -6
View File
@@ -29,12 +29,7 @@
#include <stdio.h>
#ifdef HAVE_ZLIB
# include <zlib.h>
#else
# include <simgear/zlib/zlib.h>
#endif
#include <zlib.h>
#include <plib/sg.h>
+10 -3
View File
@@ -205,11 +205,18 @@ bool SGBinObject::read_bin( const string& file ) {
// read creation time
time_t calendar_time;
sgReadLong( fp, &calendar_time );
#if 0
// The following code has a global effect on the host application
// and can screws up the time elsewhere. It should be avoided
// unless you need this for debugging in which case you should
// disable it again once the debugging task is finished.
struct tm *local_tm;
local_tm = localtime( &calendar_time );
char time_str[256];
strftime( time_str, 256, "%a %b %d %H:%M:%S %Z %Y", local_tm);
// cout << "File created on " << time_str << endl;
cout << "File created on " << time_str << endl;
#endif
// read number of top level objects
short nobjects;
@@ -551,7 +558,7 @@ bool SGBinObject::write_bin( const string& base, const string& name,
string dir = base + "/" + b.gen_base_path();
string command = "mkdir -p " + dir;
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
system( (string("mkdir ") + dir).c_str() );
#else
system(command.c_str());
@@ -828,7 +835,7 @@ bool SGBinObject::write_ascii( const string& base, const string& name,
string dir = base + "/" + b.gen_base_path();
string command = "mkdir -p " + dir;
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
system( (string("mkdir ") + dir).c_str() );
#else
system(command.c_str());
+2 -2
View File
@@ -25,7 +25,7 @@
#include STL_STRING
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <io.h>
#endif
@@ -51,7 +51,7 @@ bool SGFile::open( const SGProtocolDir d ) {
set_dir( d );
if ( get_dir() == SG_IO_OUT ) {
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
int mode = 00666;
#else
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+19 -13
View File
@@ -23,7 +23,7 @@
#include <simgear/compiler.h>
#if !defined(_MSC_VER)
#if !defined(_MSC_VER) && !defined(__MINGW32__)
# include <sys/time.h> // select()
# include <sys/types.h> // socket(), bind(), select(), accept()
# include <sys/socket.h> // socket(), bind(), listen(), accept()
@@ -48,7 +48,7 @@ SGSocket::SGSocket( const string& host, const string& port,
port_str(port),
save_len(0)
{
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
if (!wsock_init && !wsastartup()) {
SG_LOG( SG_IO, SG_ALERT, "Winsock not available");
}
@@ -75,7 +75,7 @@ SGSocket::~SGSocket() {
SGSocket::SocketType SGSocket::make_server_socket () {
struct sockaddr_in name;
#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( sgi ) || defined( _MSC_VER )
#if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) || defined( sgi ) || defined( _MSC_VER ) || defined(__MINGW32__) || defined( __APPLE__ )
int length;
#else
socklen_t length;
@@ -132,6 +132,10 @@ SGSocket::SocketType SGSocket::make_client_socket () {
// get the hosts official name/info
hp = gethostbyname( hostname.c_str() );
if (hp == NULL) {
SG_LOG( SG_IO, SG_ALERT, "Error: hostname lookup failed" );
return INVALID_SOCKET;
}
// Connect this socket to the host and the port specified on the
// command line
@@ -157,7 +161,7 @@ SGSocket::SocketType SGSocket::make_client_socket () {
// Wrapper functions
size_t SGSocket::readsocket( int fd, void *buf, size_t count ) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
return ::recv( fd, (char *)buf, count, 0 );
#else
return ::read( fd, buf, count );
@@ -165,14 +169,14 @@ size_t SGSocket::readsocket( int fd, void *buf, size_t count ) {
}
size_t SGSocket::writesocket( int fd, const void *buf, size_t count ) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
return ::send( fd, (const char*)buf, count, 0 );
#else
return ::write( fd, buf, count );
#endif
}
#if !defined(_MSC_VER)
#if !defined(_MSC_VER) && !defined(__MINGW32__)
int SGSocket::closesocket( int fd ) {
return ::close( fd );
}
@@ -335,9 +339,8 @@ int SGSocket::readline( char *buf, int length ) {
// cout << "sock_stream\n";
if ( msgsock == INVALID_SOCKET ) {
// cout << "msgsock == invalid\n";
msgsock = accept(sock, 0, 0);
closesocket(sock);
sock = msgsock;
msgsock = sock;
sock = accept(msgsock, 0, 0);
} else {
// cout << "ready to read\n";
char *buf_ptr = save_buf + save_len;
@@ -357,8 +360,7 @@ int SGSocket::readline( char *buf, int length ) {
if ( result == 0 && save_len == 0 && first_read == true ) {
SG_LOG( SG_IO, SG_ALERT,
"Connection closed by foreign host." );
closesocket(sock);
open( get_dir() );
close();
}
}
} else {
@@ -490,6 +492,10 @@ bool SGSocket::close() {
}
closesocket( sock );
if ( sock_style == SOCK_STREAM && msgsock != INVALID_SOCKET ) {
sock = msgsock;
msgsock = INVALID_SOCKET;
}
return true;
}
@@ -500,7 +506,7 @@ bool SGSocket::nonblock() {
return 0;
}
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
u_long arg = 1;
if (ioctlsocket( sock, FIONBIO, &arg ) != 0) {
int error_code = WSAGetLastError();
@@ -515,7 +521,7 @@ bool SGSocket::nonblock() {
return true;
}
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
bool SGSocket::wsock_init = false;
+4 -4
View File
@@ -41,7 +41,7 @@
SG_USING_STD(string);
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <winsock.h>
#endif
@@ -53,7 +53,7 @@ SG_USING_STD(string);
*/
class SGSocket : public SGIOChannel {
public:
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
typedef SOCKET SocketType;
#else
typedef int SocketType;
@@ -83,11 +83,11 @@ private:
// wrapper functions
size_t readsocket( int fd, void *buf, size_t count );
size_t writesocket( int fd, const void *buf, size_t count );
#if !defined(_MSC_VER)
#if !defined(_MSC_VER) && !defined(__MINGW32__)
int closesocket(int fd);
#endif
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
// Ensure winsock has been initialised.
static bool wsock_init;
static bool wsastartup();
+202
View File
@@ -0,0 +1,202 @@
// sg_socket.cxx -- Socket I/O routines
//
// Written by Curtis Olson, started November 1999.
//
// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#include <simgear/compiler.h>
#if defined( sgi )
#include <strings.h>
#endif
#include <simgear/debug/logstream.hxx>
#include "sg_socket_udp.hxx"
SGSocketUDP::SGSocketUDP( const string& host, const string& port ) :
hostname(host),
port_str(port),
save_len(0)
{
set_valid( false );
}
SGSocketUDP::~SGSocketUDP() {
}
// If specified as a server (in direction for now) open the master
// listening socket. If specified as a client (out direction), open a
// connection to a server.
bool SGSocketUDP::open( const SGProtocolDir d ) {
set_dir( d );
if ( ! sock.open( false ) ) { // open a UDP socket
SG_LOG( SG_IO, SG_ALERT, "error opening socket" );
return false;
}
if ( port_str == "" || port_str == "any" ) {
port = 0;
} else {
port = atoi( port_str.c_str() );
}
// client_connections.clear();
if ( get_dir() == SG_IO_IN ) {
// this means server
// bind ...
if ( sock.bind( hostname.c_str(), port ) == -1 ) {
SG_LOG( SG_IO, SG_ALERT, "error binding to port" << port_str );
return false;
}
} else if ( get_dir() == SG_IO_OUT ) {
// this means client
// connect ...
if ( sock.connect( hostname.c_str(), port ) == -1 ) {
SG_LOG( SG_IO, SG_ALERT,
"error connecting to " << hostname << port_str );
return false;
}
} else {
SG_LOG( SG_IO, SG_ALERT,
"Error: bidirection mode not available for UDP sockets." );
return false;
}
set_valid( true );
return true;
}
// read data from socket (server)
// read a block of data of specified size
int SGSocketUDP::read( char *buf, int length ) {
if ( ! isvalid() ) {
return 0;
}
int result;
if ( (result = sock.recv(buf, SG_IO_MAX_MSG_SIZE, 0)) >= 0 ) {
buf[result] = '\0';
// printf("msg received = %s\n", buf);
}
return result;
}
// read a line of data, length is max size of input buffer
int SGSocketUDP::readline( char *buf, int length ) {
if ( ! isvalid() ) {
return 0;
}
// cout << "sock = " << sock << endl;
char *buf_ptr = save_buf + save_len;
int result = sock.recv(buf_ptr, SG_IO_MAX_MSG_SIZE, 0);
// printf("msg received = %s\n", buf);
save_len += result;
// look for the end of line in save_buf
int i;
for ( i = 0; i < save_len && save_buf[i] != '\n'; ++i );
if ( save_buf[i] == '\n' ) {
result = i + 1;
} else {
// no end of line yet
// cout << "no eol found" << endl;
return 0;
}
// cout << "line length = " << result << endl;
// we found an end of line
// copy to external buffer
strncpy( buf, save_buf, result );
buf[result] = '\0';
// cout << "sg_socket line = " << buf << endl;
// shift save buffer
for ( i = result; i < save_len; ++i ) {
save_buf[ i - result ] = save_buf[i];
}
save_len -= result;
return result;
}
// write data to socket (client)
int SGSocketUDP::write( const char *buf, const int length ) {
if ( ! isvalid() ) {
return 0;
}
bool error_condition = false;
if ( sock.send( buf, length, 0 ) < 0 ) {
SG_LOG( SG_IO, SG_ALERT, "Error writing to socket: " << port );
error_condition = true;
return 0;
}
return length;
}
// write null terminated string to socket (server)
int SGSocketUDP::writestring( const char *str ) {
if ( !isvalid() ) {
return 0;
}
int length = strlen( str );
return write( str, length );
}
// close the port
bool SGSocketUDP::close() {
if ( !isvalid() ) {
return 0;
}
sock.close();
return true;
}
// configure the socket as non-blocking
bool SGSocketUDP::setBlocking( bool value ) {
sock.setBlocking( value );
return true;
}
+138
View File
@@ -0,0 +1,138 @@
/**
* \file sg_socket_udp.hxx
* UDP Socket I/O routines.
*/
// Written by Curtis Olson, started November 2001.
//
// Copyright (C) 2001 Curtis L. Olson - curt@flightgear.org
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifndef _SG_SOCKET_UDP_HXX
#define _SG_SOCKET_UDP_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#include <plib/netSocket.h>
#include <simgear/compiler.h>
#include STL_STRING
#include <simgear/math/sg_types.hxx>
#include <simgear/io/iochannel.hxx>
SG_USING_STD(string);
/**
* A UDP socket I/O class based on SGIOChannel and plib/net.
*/
class SGSocketUDP : public SGIOChannel {
private:
netSocket sock;
string hostname;
string port_str;
char save_buf[ 2 * SG_IO_MAX_MSG_SIZE ];
int save_len;
short unsigned int port;
public:
/**
* Create an instance of SGSocketUDP.
*
* When calling the constructor you need to provide a host name, and a
* port number. The convention used by the
* SGSocketUDP class is that the server side listens and the client
* side sends. For a server socket, the host name should be
* empty. For a server, the port number is optional, if you do not
* specify a port, the system will assign one. For a client
* socket, you need to specify both a destination host and
* destination port.
*
* UDP sockets are a lower level protocol than TCP sockets and are
* "connectionless" in the sense that either client or server can
* exist, or not exist, startup, quit, etc. in any order and
* whenever both ends are alive, the communication succeeds. With
* UDP sockets, the server end just sits and listens for incoming
* packets from anywhere. The client end sends it's message and
* forgets about it. It doesn't care if there isn't even a server
* out there listening and all the packets are getting
* lost. Although systems/networks usually do a pretty good job
* (statistically) of getting your UDP packets to their
* destination, there is no guarantee that any particular packet
* will make it. But, because of this low level implementation and
* lack of error checking, UDP packets are much faster and
* efficient. UDP packets are good for sending positional
* information to synchronize two applications. In this case, you
* want the information to arrive as quickly as possible, and if
* you lose a packet, you'd rather get new updated information
* rather than have the system waste time resending a packet that
* is becoming older and older with every retry.
* @param host name of host if direction is SG_IO_OUT or SG_IO_BI
* @param port port number if we care to choose one.
* @param style specify "udp" or "tcp" */
SGSocketUDP( const string& host, const string& port );
/** Destructor */
~SGSocketUDP();
// If specified as a server (in direction for now) open the master
// listening socket. If specified as a client (out direction),
// open a connection to a server.
bool open( const SGProtocolDir d );
// read data from socket
int read( char *buf, int length );
// read data from socket
int readline( char *buf, int length );
// write data to a socket
int write( const char *buf, const int length );
// write null terminated string to a socket
int writestring( const char *str );
// close file
bool close();
/**
* Set blocking true or false
* @return success/failure
*/
bool setBlocking( bool value );
/** @return the remote host name */
inline string get_hostname() const { return hostname; }
/** @return the port number (in string form) */
inline string get_port_str() const { return port_str; }
};
#endif // _SG_SOCKET_UDP_HXX
+4
View File
@@ -41,6 +41,10 @@ int main() {
if ( s.readline( buf, 256 ) > 0 ) {
cout << "result = " << buf;
}
#ifdef __MINGW32__
Sleep(100);
#else
sleep(1);
#endif
}
}
+4
View File
@@ -0,0 +1,4 @@
.deps
Makefile
Makefile.in
testmagvar
+4
View File
@@ -14,4 +14,8 @@ testmagvar_SOURCES = testmagvar.cxx
testmagvar_LDADD = $(top_builddir)/simgear/magvar/libsgmagvar.a
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+3 -3
View File
@@ -45,9 +45,9 @@ if (argc == 8){
var = calc_magvar( SGD_DEGREES_TO_RADIANS * lat_deg, SGD_DEGREES_TO_RADIANS * lon_deg, h,
yymmdd_to_julian_days(yy,mm,dd), field );
fprintf(stdout,"%6.0lf %6.0lf %6.0lf\n", field[0], field[1], field[2] );
fprintf(stdout,"%6.0lf %6.0lf %6.0lf\n", field[3], field[4], field[5] );
fprintf(stdout,"%6.0lf %6.0lf %6.0lf %4.2lf %4.2lf \n",
fprintf(stdout,"%6.0f %6.0f %6.0f\n", field[0], field[1], field[2] );
fprintf(stdout,"%6.0f %6.0f %6.0f\n", field[3], field[4], field[5] );
fprintf(stdout,"%6.0f %6.0f %6.0f %4.2f %4.2f \n",
field[3],field[4],field[5],
SGD_RADIANS_TO_DEGREES * (atan(field[5]/pow(field[3]*field[3]+field[4]*field[4],0.5))),
SGD_RADIANS_TO_DEGREES * var);
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+5 -7
View File
@@ -1,11 +1,5 @@
includedir = @includedir@/math
if HAVE_ZLIB
ZLIB_INCL =
else
ZLIB_INCL = -I$(top_srcdir)/src/zlib
endif
lib_LIBRARIES = libsgmath.a
include_HEADERS = \
@@ -30,4 +24,8 @@ libsgmath_a_SOURCES = \
sg_random.c \
vector.cxx
INCLUDES += -I$(top_srcdir) $(ZLIB_INCL)
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+4 -3
View File
@@ -83,8 +83,9 @@ double SGInterpTable::interpolate(double x) const
int i;
double y;
if (size == 0.0)
if (size == 0.0) {
return 0.0;
}
i = 0;
@@ -96,14 +97,14 @@ double SGInterpTable::interpolate(double x) const
// printf ("i = %d ", i);
if ( (i == 0) && (x < table[0].ind) ) {
if ( i <= 0 ) {
SG_LOG( SG_MATH, SG_DEBUG,
"interpolate(): lookup error, x to small = " << x );
return table[0].dep;
}
// cout << " table[size-1].ind = " << table[size-1].ind << endl;
if ( x > table[size-1].ind ) {
if ( i >= size ) {
SG_LOG( SG_MATH, SG_DEBUG,
"interpolate(): lookup error, x to big = " << x );
return table[size-1].dep;
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+9 -12
View File
@@ -1358,8 +1358,8 @@ static bool vrblVsby( char *string1, char *string2,
Decoded_METAR *Mptr, int *NDEX )
{
char buf[ 6 ];
int numerator,
denominator;
/* int numerator,
denominator; */
char *slash,
*V_char,
*temp;
@@ -1800,7 +1800,7 @@ static bool isWxToken( char *token )
if( token == NULL )
return FALSE;
for( i = 0; i < strlen(token); i++ )
for( i = 0; i < (int)strlen(token); i++ )
{
if( !(isalpha(*(token+i)) || *(token+i) == '+' ||
*(token+i) == '-' ) )
@@ -2365,17 +2365,14 @@ int DcdMETAR( char *string , Decoded_METAR *Mptr )
CAVOK, visibility,
RVR, presentWX, PartialObscur,
skyCond, tempGroup,
altimStng, NotIDed = 99} StartGroup,
SaveStartGroup,
MetarGroup;
altimStng, NotIDed = 99 }
StartGroup, SaveStartGroup, MetarGroup;
WindStruct *WinDataPtr;
// WindStruct *WinDataPtr;
int ndex,
NDEX,
i,
jkj,
j;
int ndex;
int NDEX;
// int i, jkj, j;
char **token,
+18 -16
View File
@@ -1,3 +1,5 @@
#include <simgear/compiler.h>
#include "Local.h" /* standard header file */
#include "Metar.h"
@@ -1393,9 +1395,9 @@ static bool isVariableVsby( char **string, Decoded_METAR *Mptr,
/* DECLARE LOCAL VARIABLES */
/***************************/
char *slash,
*slash1,
*slash2,
char *slash = NULL,
*slash1 = NULL,
*slash2 = NULL,
buf[ 5 ],
*V_char;
float minimumVsby,
@@ -2788,8 +2790,8 @@ static bool isSLP( char **token, Decoded_METAR *Mptr, int *NDEX )
/* DECLARE LOCAL VARIABLES */
/***************************/
int pressure,
ndex;
int pressure;
// int ndex;
/*************************/
/* BEGIN BODY OF ROUTINE */
@@ -2861,7 +2863,7 @@ static bool isSectorVsby( char **string, Decoded_METAR *Mptr,
/* DECLARE LOCAL VARIABLES */
/***************************/
float vsby;
float vsby = 0.0f;
char dd[3],
*slash;
@@ -4791,18 +4793,18 @@ void DcdMTRmk( char **token, Decoded_METAR *Mptr )
FZRANO = 0, TSNO = 0, maintIndicator = 0, CHINO = 0, RVRNO = 0,
VISNO = 0, PNO = 0, DVR = 0;
int NDEX,
ndex,
i;
char *slash,
*tokenX,
*V_char,
*temp_token;
int NDEX;
// int ndex;
int i;
// char *slash;
// char *tokenX;
// char *V_char;
// char *temp_token;
bool extra_token,
IS_NOT_RMKS;
// bool extra_token;
bool IS_NOT_RMKS;
float T_vsby;
// float T_vsby;
/*************************/
/* START BODY OF ROUTINE */
+3 -1
View File
@@ -1106,8 +1106,10 @@ char *strlwr(char *);
char *rptstrip(char *);
char *rptfmt(char *);
char *rptfmti(char *, unsigned short int);
#ifndef __FreeBSD__ // strnstr is already defined on FreeBSD
char *strnstr(char *, char *, size_t);
#endif
int stregion(int);
int ccregion(char *);
+4
View File
@@ -11,4 +11,8 @@ libsgmetar_a_SOURCES = \
MetarStation.cpp \
Prtdmetr.cpp Stspack2.cpp Stspack3.cpp
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+4
View File
@@ -0,0 +1,4 @@
.deps
Makefile
Makefile.in
props_test
+7 -7
View File
@@ -1,15 +1,10 @@
includedir = @includedir@/misc
if HAVE_ZLIB
ZLIB_INCL =
else
ZLIB_INCL = -I$(top_srcdir)/src/zlib
endif
lib_LIBRARIES = libsgmisc.a
include_HEADERS = \
commands.hxx \
exception.hxx \
props.hxx \
sg_path.hxx \
sgstream.hxx \
@@ -20,6 +15,7 @@ include_HEADERS = \
libsgmisc_a_SOURCES = \
commands.cxx \
exception.cxx \
props.cxx \
props_io.cxx \
sg_path.cxx \
@@ -33,4 +29,8 @@ noinst_PROGRAMS = props_test
props_test_SOURCES = props_test.cxx
props_test_LDADD = libsgmisc.a ../xml/libsgxml.a ../debug/libsgdebug.a
INCLUDES += -I$(top_srcdir) $(ZLIB_INCL)
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+88 -57
View File
@@ -7,6 +7,36 @@
#include "commands.hxx"
////////////////////////////////////////////////////////////////////////
// Implementation of SGCommandState class.
////////////////////////////////////////////////////////////////////////
SGCommandState::SGCommandState ()
: _args(0)
{
}
SGCommandState::SGCommandState (const SGPropertyNode * args)
: _args(0)
{
setArgs(args);
}
SGCommandState::~SGCommandState ()
{
delete _args;
}
void
SGCommandState::setArgs (const SGPropertyNode * args)
{
delete _args;
_args = new SGPropertyNode();
copyProperties(args, _args);
}
////////////////////////////////////////////////////////////////////////
// Implementation of SGCommandMgr class.
@@ -50,83 +80,84 @@ SGCommandMgr::getCommandNames () const
}
bool
SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
SGCommandState ** state) const
{
command_t command = getCommand(name);
if (command == 0)
return false;
else
return (*command)(arg);
return (*command)(arg, state);
}
bool
SGCommandMgr::execute (const string &name) const
{
// FIXME
SGPropertyNode node;
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name) const
// {
// // FIXME
// SGPropertyNode node;
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, bool value) const
{
// FIXME
SGPropertyNode node;
node.setBoolValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, bool value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setBoolValue(value);
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, int value) const
{
// FIXME
SGPropertyNode node;
node.setIntValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, int value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setIntValue(value);
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, long value) const
{
// FIXME
SGPropertyNode node;
node.setLongValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, long value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setLongValue(value);
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, float value) const
{
// FIXME
SGPropertyNode node;
node.setFloatValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, float value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setFloatValue(value);
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, double value) const
{
// FIXME
SGPropertyNode node;
node.setDoubleValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, double value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setDoubleValue(value);
// return execute(name, &node);
// }
bool
SGCommandMgr::execute (const string &name, string value) const
{
// FIXME
SGPropertyNode node;
node.setStringValue(value);
return execute(name, &node);
}
// bool
// SGCommandMgr::execute (const string &name, string value) const
// {
// // FIXME
// SGPropertyNode node;
// node.setStringValue(value);
// return execute(name, &node);
// }
// end of commands.cxx
+133 -90
View File
@@ -24,15 +24,55 @@ SG_USING_STD(map);
SG_USING_STD(vector);
/**
* Stored state for a command.
*
* <p>This class allows a command to cache parts of its state between
* invocations with the same parameters. Nearly every command that
* actually uses this will subclass it in some way. The command
* allocates the structure, but it is up to the caller to delete it
* when it is no longer necessary, unless the command deletes it
* and replaces the value with 0 or another command-state object
* first.</p>
*
* <p>Note that this class is for caching only; all of the information
* in it must be recoverable by other means, since the state could
* arbitrarily disappear between invocations if the caller decides to
* delete it.</p>
*
* <p>By default, the command state includes a place to keep a copy of
* the parameters.</p>
*
* @author David Megginson, david@megginson.com
*/
class SGCommandState
{
public:
SGCommandState ();
SGCommandState (const SGPropertyNode * args);
virtual ~SGCommandState ();
virtual void setArgs (const SGPropertyNode * args);
virtual const SGPropertyNode * getArgs () const { return _args; }
private:
SGPropertyNode * _args;
};
/**
* Manage commands.
*
* <p>This class allows the application to register and unregister
* commands, and provides shortcuts for executing them. Commands
* are simple functions that take a const pointer to an SGPropertyNode
* as an argument and return a bool value indicating success or failure.
* The property node may be ignored, or it may contain values that
* the command uses as parameters.</p>
* commands, and provides shortcuts for executing them. Commands are
* simple functions that take a const pointer to an SGPropertyNode and
* a pointer to a pointer variable (which should be 0 initially) where
* the function can store compiled copies of its arguments, etc. to
* avoid expensive recalculations. If the command deletes the
* SGCommandState, it must replace it with a new pointer or 0;
* otherwise, the caller is free to delete and zero the pointer at any
* time and the command will start fresh with the next invocation.
* The command must return a bool value indicating success or failure.
* The property node may be ignored, or it may contain values that the
* command uses as parameters.</p>
*
* <p>There are convenience methods for invoking a command function
* with no arguments or with a single, primitive argument.</p>
@@ -46,7 +86,8 @@ public:
/**
* Type for a command function.
*/
typedef bool (*command_t) (const SGPropertyNode * arg);
typedef bool (*command_t) (const SGPropertyNode * arg,
SGCommandState ** state);
/**
@@ -105,104 +146,106 @@ public:
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, const SGPropertyNode * arg) const;
virtual bool execute (const string &name,
const SGPropertyNode * arg,
SGCommandState ** state) const;
/**
* Execute a command with no argument.
*
* The command function will receive a pointer to a property node
* with no value and no children.
*
* @param name The name of the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name) const;
// /**
// * Execute a command with no argument.
// *
// * The command function will receive a pointer to a property node
// * with no value and no children.
// *
// * @param name The name of the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name) const;
/**
* Execute a command with a single bool argument.
*
* The command function will receive a pointer to a property node
* with a bool value and no children.
*
* @param name The name of the command.
* @param arg The bool argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, bool arg) const;
// /**
// * Execute a command with a single bool argument.
// *
// * The command function will receive a pointer to a property node
// * with a bool value and no children.
// *
// * @param name The name of the command.
// * @param arg The bool argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, bool arg) const;
/**
* Execute a command with a single int argument.
*
* The command function will receive a pointer to a property node
* with a int value and no children.
*
* @param name The name of the command.
* @param arg The int argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, int arg) const;
// /**
// * Execute a command with a single int argument.
// *
// * The command function will receive a pointer to a property node
// * with a int value and no children.
// *
// * @param name The name of the command.
// * @param arg The int argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, int arg) const;
/**
* Execute a command with a single long argument.
*
* The command function will receive a pointer to a property node
* with a long value and no children.
*
* @param name The name of the command.
* @param arg The long argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, long arg) const;
// /**
// * Execute a command with a single long argument.
// *
// * The command function will receive a pointer to a property node
// * with a long value and no children.
// *
// * @param name The name of the command.
// * @param arg The long argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, long arg) const;
/**
* Execute a command with a single float argument.
*
* The command function will receive a pointer to a property node
* with a float value and no children.
*
* @param name The name of the command.
* @param arg The float argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, float arg) const;
// /**
// * Execute a command with a single float argument.
// *
// * The command function will receive a pointer to a property node
// * with a float value and no children.
// *
// * @param name The name of the command.
// * @param arg The float argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, float arg) const;
/**
* Execute a command with a single double argument.
*
* The command function will receive a pointer to a property node
* with a double value and no children.
*
* @param name The name of the command.
* @param arg The double argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, double arg) const;
// /**
// * Execute a command with a single double argument.
// *
// * The command function will receive a pointer to a property node
// * with a double value and no children.
// *
// * @param name The name of the command.
// * @param arg The double argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, double arg) const;
/**
* Execute a command with a single string argument.
*
* The command function will receive a pointer to a property node
* with a string value and no children.
*
* @param name The name of the command.
* @param arg The string argument to the command.
* @return true if the command is present and executes successfully,
* false otherwise.
*/
virtual bool execute (const string &name, string arg) const;
// /**
// * Execute a command with a single string argument.
// *
// * The command function will receive a pointer to a property node
// * with a string value and no children.
// *
// * @param name The name of the command.
// * @param arg The string argument to the command.
// * @return true if the command is present and executes successfully,
// * false otherwise.
// */
// virtual bool execute (const string &name, string arg) const;
private:
+307
View File
@@ -0,0 +1,307 @@
// exception.cxx - implementation of SimGear base exceptions.
// Started Summer 2001 by David Megginson, david@megginson.com
// This code is released into the Public Domain.
//
// $Id$
#include "exception.hxx"
#include <stdio.h>
////////////////////////////////////////////////////////////////////////
// Implementation of sg_location class.
////////////////////////////////////////////////////////////////////////
sg_location::sg_location ()
: _path(""),
_line(-1),
_column(-1),
_byte(-1)
{
}
sg_location::sg_location (const string &path, int line, int column)
: _path(path),
_line(line),
_column(column),
_byte(-1)
{
}
sg_location::~sg_location ()
{
}
const string &
sg_location::getPath () const
{
return _path;
}
void
sg_location::setPath (const string &path)
{
_path = path;
}
int
sg_location::getLine () const
{
return _line;
}
void
sg_location::setLine (int line)
{
_line = line;
}
int
sg_location::getColumn () const
{
return _column;
}
void
sg_location::setColumn (int column)
{
_column = column;
}
int
sg_location::getByte () const
{
return _byte;
}
void
sg_location::setByte (int byte)
{
_byte = byte;
}
string
sg_location::asString () const
{
char buf[128];
string out = "";
if (_path != (string)"") {
out += _path;
if (_line != -1 || _column != -1)
out += ",\n";
}
if (_line != -1) {
sprintf(buf, "line %d", _line);
out += buf;
if (_column != -1)
out += ", ";
}
if (_column != -1) {
sprintf(buf, "column %d", _column);
out += buf;
}
return out;
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_throwable class.
////////////////////////////////////////////////////////////////////////
sg_throwable::sg_throwable ()
: _message(""),
_origin("")
{
}
sg_throwable::sg_throwable (const string &message, const string &origin)
: _message(message),
_origin(origin)
{
}
sg_throwable::~sg_throwable ()
{
}
const string &
sg_throwable::getMessage () const
{
return _message;
}
const string
sg_throwable::getFormattedMessage () const
{
return getMessage();
}
void
sg_throwable::setMessage (const string &message)
{
_message = message;
}
const string &
sg_throwable::getOrigin () const
{
return _origin;
}
void
sg_throwable::setOrigin (const string &origin)
{
_origin = origin;
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_error class.
////////////////////////////////////////////////////////////////////////
sg_error::sg_error ()
: sg_throwable ()
{
}
sg_error::sg_error (const string &message, const string &origin)
: sg_throwable(message, origin)
{
}
sg_error::~sg_error ()
{
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_exception class.
////////////////////////////////////////////////////////////////////////
sg_exception::sg_exception ()
: sg_throwable ()
{
}
sg_exception::sg_exception (const string &message, const string &origin)
: sg_throwable(message, origin)
{
}
sg_exception::~sg_exception ()
{
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_io_exception.
////////////////////////////////////////////////////////////////////////
sg_io_exception::sg_io_exception ()
: sg_exception()
{
}
sg_io_exception::sg_io_exception (const string &message, const string &origin)
: sg_exception(message, origin)
{
}
sg_io_exception::sg_io_exception (const string &message,
const sg_location &location,
const string &origin)
: sg_exception(message, origin),
_location(location)
{
}
sg_io_exception::~sg_io_exception ()
{
}
const string
sg_io_exception::getFormattedMessage () const
{
string ret = getMessage();
ret += "\n at ";
ret += getLocation().asString();
return ret;
}
const sg_location &
sg_io_exception::getLocation () const
{
return _location;
}
void
sg_io_exception::setLocation (const sg_location &location)
{
_location = location;
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_format_exception.
////////////////////////////////////////////////////////////////////////
sg_format_exception::sg_format_exception ()
: sg_exception(),
_text("")
{
}
sg_format_exception::sg_format_exception (const string &message,
const string &text,
const string &origin)
: sg_exception(message, origin),
_text(text)
{
}
sg_format_exception::~sg_format_exception ()
{
}
const string &
sg_format_exception::getText () const
{
return _text;
}
void
sg_format_exception::setText (const string &text)
{
_text = text;
}
////////////////////////////////////////////////////////////////////////
// Implementation of sg_range_exception.
////////////////////////////////////////////////////////////////////////
sg_range_exception::sg_range_exception ()
: sg_exception()
{
}
sg_range_exception::sg_range_exception (const string &message,
const string &origin)
: sg_exception(message, origin)
{
}
sg_range_exception::~sg_range_exception ()
{
}
// end of exception.cxx
+182
View File
@@ -0,0 +1,182 @@
/**
* \file exception.hxx
* Interface definition for SimGear base exceptions.
* Started Spring 2001 by David Megginson, david@megginson.com
* This code is released into the Public Domain.
*
* $Id$
*/
#ifndef __SIMGEAR_MISC_EXCEPTION_HXX
#define __SIMGEAR_MISC_EXCEPTION_HXX 1
#include <simgear/compiler.h>
#include STL_STRING
SG_USING_STD(string);
/**
* Information encapsulating a single location in an external resource
*
* A position in the resource my optionally be provided, either by
* line number, line number and column number, or byte offset from the
* beginning of the resource.
*/
class sg_location
{
public:
sg_location ();
sg_location (const string &path, int line = -1, int column = -1);
virtual ~sg_location ();
virtual const string &getPath () const;
virtual void setPath (const string &path);
virtual int getLine () const;
virtual void setLine (int line);
virtual int getColumn () const;
virtual void setColumn (int column);
virtual int getByte () const;
virtual void setByte (int byte);
virtual string asString () const;
private:
string _path;
int _line;
int _column;
int _byte;
};
/**
* Abstract base class for all throwables.
*/
class sg_throwable
{
public:
sg_throwable ();
sg_throwable (const string &message, const string &origin = "");
virtual ~sg_throwable ();
virtual const string &getMessage () const;
virtual const string getFormattedMessage () const;
virtual void setMessage (const string &message);
virtual const string &getOrigin () const;
virtual void setOrigin (const string &origin);
private:
string _message;
string _origin;
};
/**
* An unexpected fatal error.
*
* Methods and functions show throw this exception when something
* very bad has happened (such as memory corruption or
* a totally unexpected internal value). Applications should catch
* this exception only at the top level if at all, and should
* normally terminate execution soon afterwards.
*/
class sg_error : public sg_throwable
{
public:
sg_error ();
sg_error (const string &message, const string &origin = "");
virtual ~sg_error ();
};
/**
* Base class for all SimGear exceptions.
*
* SimGear-based code should throw this exception only when no
* more specific exception applies. It may not be caught until
* higher up in the application, where it is not possible to
* resume normal operations if desired.
*
* A caller can catch sg_exception by default to ensure that
* all exceptions are caught. Every SimGear exception can contain
* a human-readable error message and a human-readable string
* indicating the part of the application causing the exception
* (as an aid to debugging, only).
*/
class sg_exception : public sg_throwable
{
public:
sg_exception ();
sg_exception (const string &message, const string &origin = "");
virtual ~sg_exception ();
};
/**
* An I/O-related SimGear exception.
*
* SimGear-based code should throw this exception when it fails
* to read from or write to an external resource, such as a file,
* socket, URL, or database.
*
* In addition to the functionality of sg_exception, an
* sg_io_exception may contain location information, such as the name
* of a file or URL, and possible also a location in that file or URL.
*/
class sg_io_exception : public sg_exception
{
public:
sg_io_exception ();
sg_io_exception (const string &message, const string &origin = "");
sg_io_exception (const string &message, const sg_location &location,
const string &origin = "");
virtual ~sg_io_exception ();
virtual const string getFormattedMessage () const;
virtual const sg_location &getLocation () const;
virtual void setLocation (const sg_location &location);
private:
sg_location _location;
};
/**
* A format-related SimGear exception.
*
* SimGear-based code should throw this exception when a string
* does not appear in the expected format (for example, a date
* string does not conform to ISO 8601).
*
* In addition to the functionality of sg_exception, an
* sg_format_exception can contain a copy of the original malformated
* text.
*/
class sg_format_exception : public sg_exception
{
public:
sg_format_exception ();
sg_format_exception (const string &message, const string &text,
const string &origin = "");
virtual ~sg_format_exception ();
virtual const string &getText () const;
virtual void setText (const string &text);
private:
string _text;
};
/**
* A range-related SimGear exception.
*
* SimGear-based code should throw this exception when a value falls
* outside the range where it can reasonably be handled; examples
* include longitude outside the range -180:180, unrealistically high
* forces or velocities, an illegal airport code, etc. A range
* exception usually means that something has gone wrong internally.
*/
class sg_range_exception : public sg_exception
{
public:
sg_range_exception ();
sg_range_exception (const string &message, const string &origin = "");
virtual ~sg_range_exception ();
};
#endif
// end of exception.hxx
+678 -890
View File
File diff suppressed because it is too large Load Diff
+612 -193
View File
@@ -18,23 +18,30 @@
#include STL_STRING
#include <vector>
#include <map>
#include STL_IOSTREAM
SG_USING_STD(string);
SG_USING_STD(vector);
SG_USING_STD(map);
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
SG_USING_STD(istream);
SG_USING_STD(ostream);
#endif
#ifdef NONE
#pragma warn A sloppy coder has defined NONE as a macro!
#undef NONE
#endif
#ifdef ALIAS
#pragma warn A sloppy coder has defined ALIAS as a macro!
#undef ALIAS
#endif
#ifdef UNKNOWN
#pragma warn A sloppy coder has defined UNKNOWN as a macro!
#undef UNKNOWN
#ifdef UNSPECIFIED
#pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
#undef UNSPECIFIED
#endif
#ifdef BOOL
@@ -473,78 +480,623 @@ private:
/**
* A cooked value.
*
* This is the value that property-list clients see. It is a
* persistent layer over the possibly-changing raw value; once a
* client gets an SGValue from the property manager, the pointer
* will be good for the life of the property manager itself, no
* matter how often the pointer is tied or untied.
* A node in a property tree.
*/
class SGValue
class SGPropertyNode
{
public:
/**
* Property value types.
*/
enum Type {
NONE,
ALIAS,
BOOL,
INT,
LONG,
FLOAT,
DOUBLE,
STRING,
UNKNOWN
UNSPECIFIED
};
SGValue ();
SGValue (const SGValue &value);
~SGValue ();
/**
* Access mode attributes.
*
* <p>The ARCHIVE attribute is strictly advisory, and controls
* whether the property should normally be saved and restored.</p>
*/
enum Attribute {
READ = 1,
WRITE = 2,
ARCHIVE = 4,
TRACE_READ = 8,
TRACE_WRITE = 16
};
/**
* Default constructor.
*/
SGPropertyNode ();
/**
* Copy constructor.
*/
SGPropertyNode (const SGPropertyNode &node);
/**
* Destructor.
*/
virtual ~SGPropertyNode ();
//
// Basic properties.
//
/**
* Test whether this node contains a primitive leaf value.
*/
bool hasValue () const { return (_type != NONE); }
/**
* Get the node's simple (XML) name.
*/
const string &getName () const { return _name; }
/**
* Get the node's integer index.
*/
const int getIndex () const { return _index; }
/**
* Get a non-const pointer to the node's parent.
*/
SGPropertyNode * getParent () { return _parent; }
/**
* Get a const pointer to the node's parent.
*/
const SGPropertyNode * getParent () const { return _parent; }
//
// Children.
//
/**
* Get the number of child nodes.
*/
const int nChildren () const { return _children.size(); }
/**
* Get a child node by position (*NOT* index).
*/
SGPropertyNode * getChild (int position);
/**
* Get a const child node by position (*NOT* index).
*/
const SGPropertyNode * getChild (int position) const;
/**
* Get a child node by name and index.
*/
SGPropertyNode * getChild (const string &name, int index = 0,
bool create = false);
/**
* Get a const child node by name and index.
*/
const SGPropertyNode * getChild (const string &name, int index = 0) const;
/**
* Get a vector of all children with the specified name.
*/
vector<SGPropertyNode *> getChildren (const string &name);
/**
* Get a vector all all children (const) with the specified name.
*/
vector<const SGPropertyNode *> getChildren (const string &name) const;
//
// Alias support.
//
/**
* Alias this node's leaf value to another's.
*/
bool alias (SGPropertyNode * target);
/**
* Alias this node's leaf value to another's by relative path.
*/
bool alias (const string &path);
/**
* Remove any alias for this node.
*/
bool unalias ();
/**
* Test whether the node's leaf value is aliased to another's.
*/
bool isAlias () const { return (_type == ALIAS); }
/**
* Get a non-const pointer to the current alias target, if any.
*/
SGPropertyNode * getAliasTarget ();
/**
* Get a const pointer to the current alias target, if any.
*/
const SGPropertyNode * getAliasTarget () const;
//
// Path information.
//
/**
* Get the path to this node from the root.
*/
string getPath (bool simplify = false) const;
/**
* Get a pointer to the root node.
*/
SGPropertyNode * getRootNode ();
/**
* Get a const pointer to the root node.
*/
const SGPropertyNode * getRootNode () const;
/**
* Get a pointer to another node by relative path.
*/
SGPropertyNode * getNode (const string &relative_path, bool create = false);
/**
* Get a pointer to another node by relative path.
*
* This method leaves the index off the last member of the path,
* so that the user can specify it separately (and save some
* string building). For example, getNode("/bar[1]/foo", 3) is
* exactly equivalent to getNode("bar[1]/foo[3]"). The index
* provided overrides any given in the path itself for the last
* component.
*/
SGPropertyNode * getNode (const string &relative_path, int index,
bool create = false);
/**
* Get a const pointer to another node by relative path.
*/
const SGPropertyNode * getNode (const string &relative_path) const;
/**
* Get a const pointer to another node by relative path.
*
* This method leaves the index off the last member of the path,
* so that the user can specify it separate.
*/
const SGPropertyNode * getNode (const string &relative_path,
int index) const;
//
// Access Mode.
//
/**
* Check a single mode attribute for the property node.
*/
bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
/**
* Set a single mode attribute for the property node.
*/
void setAttribute (Attribute attr, bool state) {
(state ? _attr |= attr : _attr &= ~attr);
}
/**
* Get all of the mode attributes for the property node.
*/
int getAttributes () const { return _attr; }
/**
* Set all of the mode attributes for the property node.
*/
void setAttributes (int attr) { _attr = attr; }
//
// Leaf Value (primitive).
//
/**
* Get the type of leaf value, if any, for this node.
*/
Type getType () const;
SGValue * getAlias ();
const SGValue * getAlias () const;
bool alias (SGValue * alias);
bool unalias ();
bool isAlias () const { return _type == ALIAS; }
/**
* Get a bool value for this node.
*/
bool getBoolValue () const;
/**
* Get an int value for this node.
*/
int getIntValue () const;
/**
* Get a long int value for this node.
*/
long getLongValue () const;
/**
* Get a float value for this node.
*/
float getFloatValue () const;
/**
* Get a double value for this node.
*/
double getDoubleValue () const;
/**
* Get a string value for this node.
*/
string getStringValue () const;
bool setBoolValue (bool value);
bool setIntValue (int value);
bool setLongValue (long value);
bool setFloatValue (float value);
bool setDoubleValue (double value);
bool setStringValue (string value);
bool setUnknownValue (string value);
/**
* Set a bool value for this node.
*/
bool setBoolValue (bool value);
/**
* Set an int value for this node.
*/
bool setIntValue (int value);
/**
* Set a long int value for this node.
*/
bool setLongValue (long value);
/**
* Set a float value for this node.
*/
bool setFloatValue (float value);
/**
* Set a double value for this node.
*/
bool setDoubleValue (double value);
/**
* Set a string value for this node.
*/
bool setStringValue (string value);
/**
* Set a value of unspecified type for this node.
*/
bool setUnspecifiedValue (string value);
//
// Data binding.
//
/**
* Test whether this node is bound to an external data source.
*/
bool isTied () const { return _tied; }
/**
* Bind this node to an external bool source.
*/
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
/**
* Bind this node to an external int source.
*/
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
/**
* Bind this node to an external long int source.
*/
bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
/**
* Bind this node to an external float source.
*/
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
/**
* Bind this node to an external double source.
*/
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
/**
* Bind this node to an external string source.
*/
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
/**
* Unbind this node from any external data source.
*/
bool untie ();
//
// Convenience methods using paths.
// TODO: add attribute methods
//
/**
* Get another node's type.
*/
Type getType (const string &relative_path) const;
/**
* Test whether another node has a leaf value.
*/
bool hasValue (const string &relative_path) const;
/**
* Get another node's value as a bool.
*/
bool getBoolValue (const string &relative_path,
bool defaultValue = false) const;
/**
* Get another node's value as an int.
*/
int getIntValue (const string &relative_path,
int defaultValue = 0) const;
/**
* Get another node's value as a long int.
*/
long getLongValue (const string &relative_path,
long defaultValue = 0L) const;
/**
* Get another node's value as a float.
*/
float getFloatValue (const string &relative_path,
float defaultValue = 0.0) const;
/**
* Get another node's value as a double.
*/
double getDoubleValue (const string &relative_path,
double defaultValue = 0.0L) const;
/**
* Get another node's value as a string.
*/
string getStringValue (const string &relative_path,
string defaultValue = "") const;
/**
* Set another node's value as a bool.
*/
bool setBoolValue (const string &relative_path, bool value);
/**
* Set another node's value as an int.
*/
bool setIntValue (const string &relative_path, int value);
/**
* Set another node's value as a long int.
*/
bool setLongValue (const string &relative_path, long value);
/**
* Set another node's value as a float.
*/
bool setFloatValue (const string &relative_path, float value);
/**
* Set another node's value as a double.
*/
bool setDoubleValue (const string &relative_path, double value);
/**
* Set another node's value as a string.
*/
bool setStringValue (const string &relative_path, string value);
/**
* Set another node's value with no specified type.
*/
bool setUnspecifiedValue (const string &relative_path, string value);
/**
* Test whether another node is bound to an external data source.
*/
bool isTied (const string &relative_path) const;
/**
* Bind another node to an external bool source.
*/
bool tie (const string &relative_path, const SGRawValue<bool> &rawValue,
bool useDefault = true);
/**
* Bind another node to an external int source.
*/
bool tie (const string &relative_path, const SGRawValue<int> &rawValue,
bool useDefault = true);
/**
* Bind another node to an external long int source.
*/
bool tie (const string &relative_path, const SGRawValue<long> &rawValue,
bool useDefault = true);
/**
* Bind another node to an external float source.
*/
bool tie (const string &relative_path, const SGRawValue<float> &rawValue,
bool useDefault = true);
/**
* Bind another node to an external double source.
*/
bool tie (const string &relative_path, const SGRawValue<double> &rawValue,
bool useDefault = true);
/**
* Bind another node to an external string source.
*/
bool tie (const string &relative_path, const SGRawValue<string> &rawValue,
bool useDefault = true);
/**
* Unbind another node from any external data source.
*/
bool untie (const string &relative_path);
protected:
/**
* Protected constructor for making new nodes on demand.
*/
SGPropertyNode (const string &name, int index, SGPropertyNode * parent);
private:
enum {
ALIAS = -1
};
/**
* Clear any existing value and set the type to NONE.
*/
void clear_value ();
int _type;
/**
* Get the value as a string.
*/
string get_string () const;
/**
* Trace a read access.
*/
void trace_read (Type accessType) const;
/**
* Trace a write access.
*/
void trace_write (Type accessType) const;
string _name;
int _index;
SGPropertyNode * _parent;
vector<SGPropertyNode *> _children;
typedef map<const string,SGPropertyNode *> cache_map;
cache_map * _path_cache;
Type _type;
bool _tied;
int _attr;
// The right kind of pointer...
union {
SGValue * alias;
SGPropertyNode * alias;
SGRawValue<bool> * bool_val;
SGRawValue<int> * int_val;
SGRawValue<long> * long_val;
@@ -553,163 +1105,6 @@ private:
SGRawValue<string> * string_val;
} _value;
};
/**
* A node in a property tree.
*/
class SGPropertyNode
{
public:
/**
* Property value types.
*
* Right now, this duplicates SGValue::Type, but SGValue will be
* disappearing soon.
*/
enum Type {
BOOL,
INT,
LONG,
FLOAT,
DOUBLE,
STRING,
UNKNOWN
};
SGPropertyNode ();
virtual ~SGPropertyNode ();
// Basic properties.
bool hasValue () const { return (_value != 0); }
SGValue * getValue () { return _value; }
SGValue * getValue (bool create);
const SGValue * getValue () const { return _value; }
const string &getName () const { return _name; }
const int getIndex () const { return _index; }
SGPropertyNode * getParent () { return _parent; }
const SGPropertyNode * getParent () const { return _parent; }
// Alias support.
bool alias (SGPropertyNode * target);
bool alias (const string &path);
bool unalias ();
bool isAlias () const;
SGPropertyNode * getAliasTarget ();
const SGPropertyNode * getAliasTarget () const;
// Children.
const int nChildren () const { return _children.size(); }
SGPropertyNode * getChild (int position);
const SGPropertyNode * getChild (int position) const;
SGPropertyNode * getChild (const string &name, int index = 0,
bool create = false);
const SGPropertyNode * getChild (const string &name, int index = 0) const;
vector<SGPropertyNode *> getChildren (const string &name);
vector<const SGPropertyNode *> getChildren (const string &name) const;
// Path information.
string getPath (bool simplify = false) const;
// Relative or absolute paths.
SGPropertyNode * getRootNode ();
const SGPropertyNode * getRootNode () const;
SGPropertyNode * getNode (const string &relative_path, bool create = false);
const SGPropertyNode * getNode (const string &relative_path) const;
// Value-related stuff.
Type getType () const;
bool getBoolValue () const;
int getIntValue () const;
long getLongValue () const;
float getFloatValue () const;
double getDoubleValue () const;
string getStringValue () const;
bool setBoolValue (bool value);
bool setIntValue (int value);
bool setLongValue (long value);
bool setFloatValue (float value);
bool setDoubleValue (double value);
bool setStringValue (string value);
bool setUnknownValue (string value);
bool isTied () const;
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
bool untie ();
// Values from paths.
Type getType (const string &relative_path) const;
bool getBoolValue (const string &relative_path,
bool defaultValue = false) const;
int getIntValue (const string &relative_path,
int defaultValue = 0) const;
long getLongValue (const string &relative_path,
long defaultValue = 0L) const;
float getFloatValue (const string &relative_path,
float defaultValue = 0.0) const;
double getDoubleValue (const string &relative_path,
double defaultValue = 0.0L) const;
string getStringValue (const string &relative_path,
string defaultValue = "") const;
bool setBoolValue (const string &relative_path, bool value);
bool setIntValue (const string &relative_path, int value);
bool setLongValue (const string &relative_path, long value);
bool setFloatValue (const string &relative_path, float value);
bool setDoubleValue (const string &relative_path, double value);
bool setStringValue (const string &relative_path, string value);
bool setUnknownValue (const string &relative_path, string value);
bool isTied (const string &relative_path) const;
bool tie (const string &relative_path, const SGRawValue<bool> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<int> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<long> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<float> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<double> &rawValue,
bool useDefault = true);
bool tie (const string &relative_path, const SGRawValue<string> &rawValue,
bool useDefault = true);
bool untie (const string &relative_path);
protected:
SGPropertyNode (const string &name, int index, SGPropertyNode * parent);
private:
bool hasValue (const string &relative_path) const;
SGValue * getValue (const string &relative_path, bool create = false);
const SGValue * getValue (const string &relative_path) const;
SGPropertyNode (const SGPropertyNode &node) {}
SGValue * _value;
string _name;
int _index;
SGPropertyNode * _parent;
vector<SGPropertyNode *> _children;
mutable SGPropertyNode * _target;
};
@@ -719,11 +1114,35 @@ private:
// I/O functions.
////////////////////////////////////////////////////////////////////////
bool readProperties (istream &input, SGPropertyNode * start_node,
/**
* Read properties from an XML input stream.
*/
void readProperties (istream &input, SGPropertyNode * start_node,
const string &base = "");
bool readProperties (const string &file, SGPropertyNode * start_node);
bool writeProperties (ostream &output, const SGPropertyNode * start_node);
bool writeProperties (const string &file, const SGPropertyNode * start_node);
/**
* Read properties from an XML file.
*/
void readProperties (const string &file, SGPropertyNode * start_node);
/**
* Write properties to an XML output stream.
*/
void writeProperties (ostream &output, const SGPropertyNode * start_node);
/**
* Write properties to an XML file.
*/
void writeProperties (const string &file, const SGPropertyNode * start_node);
/**
* Copy properties from one node to another.
*/
bool copyProperties (const SGPropertyNode *in, SGPropertyNode *out);
+190 -114
View File
@@ -30,6 +30,8 @@ SG_USING_STD(string);
SG_USING_STD(vector);
SG_USING_STD(map);
#define DEFAULT_MODE (SGPropertyNode::READ|SGPropertyNode::WRITE)
////////////////////////////////////////////////////////////////////////
@@ -41,7 +43,9 @@ class PropsVisitor : public XMLVisitor
public:
PropsVisitor (SGPropertyNode * root, const string &base)
: _ok(true), _root(root), _level(0), _base(base) {}
: _root(root), _level(0), _base(base), _hasException(false) {}
virtual ~PropsVisitor () {}
void startXML ();
void endXML ();
@@ -49,29 +53,34 @@ public:
void endElement (const char * name);
void data (const char * s, int length);
void warning (const char * message, int line, int column);
void error (const char * message, int line, int column);
bool isOK () const { return _ok; }
bool hasException () const { return _hasException; }
sg_io_exception &getException () { return _exception; }
void setException (const sg_io_exception &exception) {
_exception = exception;
_hasException = true;
}
private:
struct State
{
State () : node(0), type("") {}
State (SGPropertyNode * _node, const char * _type)
: node(_node), type(_type) {}
State () : node(0), type(""), mode(DEFAULT_MODE) {}
State (SGPropertyNode * _node, const char * _type, int _mode)
: node(_node), type(_type), mode(_mode) {}
SGPropertyNode * node;
string type;
int mode;
map<string,int> counters;
};
State &state () { return _state_stack[_state_stack.size() - 1]; }
void push_state (SGPropertyNode * node, const char * type) {
void push_state (SGPropertyNode * node, const char * type, int mode) {
if (type == 0)
_state_stack.push_back(State(node, "unknown"));
_state_stack.push_back(State(node, "unspecified", mode));
else
_state_stack.push_back(State(node, type));
_state_stack.push_back(State(node, type, mode));
_level++;
_data = "";
}
@@ -81,12 +90,13 @@ private:
_level--;
}
bool _ok;
string _data;
SGPropertyNode * _root;
int _level;
vector<State> _state_stack;
string _base;
sg_io_exception _exception;
bool _hasException;
};
void
@@ -103,6 +113,28 @@ PropsVisitor::endXML ()
_state_stack.resize(0);
}
/**
* Check a yes/no flag, with default.
*/
static bool
checkFlag (const char * flag, bool defaultState = true)
{
if (flag == 0)
return defaultState;
else if (string(flag) == "y")
return true;
else if (string(flag) == "n")
return false;
else {
string message = "Unrecognized flag value '";
message += flag;
message += '\'';
// FIXME: add location info
throw sg_io_exception(message, "SimGear Property Reader");
}
}
void
PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
{
@@ -110,48 +142,72 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
if (_level == 0) {
if (string(name) != (string)"PropertyList") {
SG_LOG(SG_INPUT, SG_ALERT, "Root element name is " <<
name << "; expected PropertyList");
_ok = false;
string message = "Root element name is ";
message += name;
message += "; expected PropertyList";
throw sg_io_exception(message, "SimGear Property Reader");
}
push_state(_root, "");
push_state(_root, "", DEFAULT_MODE);
}
else {
const char * attval;
// Get the index.
const char * att_n = atts.getValue("n");
attval = atts.getValue("n");
int index = 0;
if (att_n != 0) {
index = atoi(att_n);
if (attval != 0) {
index = atoi(attval);
st.counters[name] = SG_MAX2(st.counters[name], index+1);
} else {
index = st.counters[name];
st.counters[name]++;
}
// Check for an alias.
// Got the index, so grab the node.
SGPropertyNode * node = st.node->getChild(name, index, true);
const char * att_alias = atts.getValue("alias");
if (att_alias != 0) {
if (!node->alias(att_alias))
SG_LOG(SG_INPUT, SG_ALERT, "Failed to set alias to " << att_alias);
// Get the access-mode attributes,
// but don't set yet (in case they
// prevent us from recording the value).
int mode = 0;
attval = atts.getValue("read");
if (checkFlag(attval, true))
mode |= SGPropertyNode::READ;
attval = atts.getValue("write");
if (checkFlag(attval, true))
mode |= SGPropertyNode::WRITE;
attval = atts.getValue("archive");
if (checkFlag(attval, false))
mode |= SGPropertyNode::ARCHIVE;
attval = atts.getValue("trace-read");
if (checkFlag(attval, false))
mode |= SGPropertyNode::TRACE_READ;
attval = atts.getValue("trace-write");
if (checkFlag(attval, false))
mode |= SGPropertyNode::TRACE_WRITE;
// Check for an alias.
attval = atts.getValue("alias");
if (attval != 0) {
if (!node->alias(attval))
SG_LOG(SG_INPUT, SG_ALERT, "Failed to set alias to " << attval);
}
// Check for an include.
const char * att_include = atts.getValue("include");
if (att_include != 0) {
attval = atts.getValue("include");
if (attval != 0) {
SGPath path(SGPath(_base).dir());
cerr << "Base is " << _base << endl;
cerr << "Dir is " << SGPath(_base).dir() << endl;
path.append(att_include);
if (!readProperties(path.str(), node)) {
SG_LOG(SG_INPUT, SG_ALERT, "Failed to read include file "
<< att_include);
_ok = false;
path.append(attval);
try {
readProperties(path.str(), node);
} catch (sg_io_exception &e) {
setException(e);
}
}
push_state(node, atts.getValue("type"));
push_state(node, atts.getValue("type"), mode);
}
}
@@ -179,12 +235,14 @@ PropsVisitor::endElement (const char * name)
ret = st.node->setDoubleValue(strtod(_data.c_str(), 0));
} else if (st.type == "string") {
ret = st.node->setStringValue(_data);
} else if (st.type == "unknown") {
ret = st.node->setUnknownValue(_data);
} else if (st.type == "unspecified") {
ret = st.node->setUnspecifiedValue(_data);
} else {
SG_LOG(SG_INPUT, SG_ALERT, "Unknown data type " << st.type
<< " assuming 'unknown'");
ret = st.node->setUnknownValue(_data);
string message = "Unrecognized data type '";
message += st.type;
message += '\'';
// FIXME: add location information
throw sg_io_exception(message, "SimGear Property Reader");
}
if (!ret)
SG_LOG(SG_INPUT, SG_ALERT, "readProperties: Failed to set "
@@ -192,6 +250,11 @@ PropsVisitor::endElement (const char * name)
<< _data << "\" with type " << st.type);
}
// Set the access-mode attributes now,
// once the value has already been
// assigned.
st.node->setAttributes(st.mode);
pop_state();
}
@@ -209,14 +272,6 @@ PropsVisitor::warning (const char * message, int line, int column)
<< message << " at line " << line << ", column " << column);
}
void
PropsVisitor::error (const char * message, int line, int column)
{
SG_LOG(SG_INPUT, SG_ALERT, "readProperties: FATAL: " <<
message << " at line " << line << ", column " << column);
_ok = false;
}
////////////////////////////////////////////////////////////////////////
@@ -232,12 +287,14 @@ PropsVisitor::error (const char * message, int line, int column)
* @param base A base path for resolving external include references.
* @return true if the read succeeded, false otherwise.
*/
bool
void
readProperties (istream &input, SGPropertyNode * start_node,
const string &base)
{
PropsVisitor visitor(start_node, base);
return readXML(input, visitor) && visitor.isOK();
readXML(input, visitor, base);
if (visitor.hasException())
throw visitor.getException();
}
@@ -248,18 +305,13 @@ readProperties (istream &input, SGPropertyNode * start_node,
* @param start_node The root node for reading properties.
* @return true if the read succeeded, false otherwise.
*/
bool
void
readProperties (const string &file, SGPropertyNode * start_node)
{
cerr << "Reading properties from " << file << endl;
ifstream input(file.c_str());
if (input.good()) {
return readProperties(input, start_node, file);
} else {
SG_LOG(SG_INPUT, SG_ALERT, "Error reading property list from file "
<< file);
return false;
}
PropsVisitor visitor(start_node, file);
readXML(file, visitor);
if (visitor.hasException())
throw visitor.getException();
}
@@ -277,24 +329,24 @@ static const char *
getTypeName (SGPropertyNode::Type type)
{
switch (type) {
case SGValue::UNKNOWN:
return "unknown";
case SGValue::BOOL:
case SGPropertyNode::UNSPECIFIED:
return "unspecified";
case SGPropertyNode::BOOL:
return "bool";
case SGValue::INT:
case SGPropertyNode::INT:
return "int";
case SGValue::LONG:
case SGPropertyNode::LONG:
return "long";
case SGValue::FLOAT:
case SGPropertyNode::FLOAT:
return "float";
case SGValue::DOUBLE:
case SGPropertyNode::DOUBLE:
return "double";
case SGValue::STRING:
case SGPropertyNode::STRING:
return "string";
}
// keep the compiler from squawking
return "unknown";
return "unspecified";
}
@@ -331,22 +383,71 @@ doIndent (ostream &output, int indent)
}
static void
writeAtts (ostream &output, const SGPropertyNode * node)
{
int index = node->getIndex();
if (index != 0)
output << " n=\"" << index << '"';
#if 0
if (!node->getAttribute(SGPropertyNode::READ))
output << " read=\"n\"";
if (!node->getAttribute(SGPropertyNode::WRITE))
output << " write=\"n\"";
if (node->getAttribute(SGPropertyNode::ARCHIVE))
output << " archive=\"y\"";
#endif
}
/**
* Test whether a node is archivable or has archivable descendants.
*/
static bool
isArchivable (const SGPropertyNode * node)
{
// FIXME: it's inefficient to do this all the time
if (node->getAttribute(SGPropertyNode::ARCHIVE))
return true;
else {
int nChildren = node->nChildren();
for (int i = 0; i < nChildren; i++)
if (isArchivable(node->getChild(i)))
return true;
}
return false;
}
static bool
writeNode (ostream &output, const SGPropertyNode * node, int indent)
{
// Don't write the node or any of
// its descendants unless it is
// allowed to be archived.
if (!isArchivable(node))
return true; // Everything's OK, but we won't write.
const string &name = node->getName();
int index = node->getIndex();
int nChildren = node->nChildren();
// If there is a literal value,
// write it first.
if (node->hasValue()) {
if (node->hasValue() && node->getAttribute(SGPropertyNode::ARCHIVE)) {
doIndent(output, indent);
output << '<' << name << " n=\"" << index << '"';
if (node->isAlias() && node->getAliasTarget() != 0)
output << " alias=\"" << node->getAliasTarget()->getPath() << "\"/>";
else {
if (node->getType() != SGPropertyNode::UNKNOWN)
output << '<' << name;
writeAtts(output, node);
if (node->isAlias() && node->getAliasTarget() != 0) {
output << " alias=\"" << node->getAliasTarget()->getPath()
<< "\"/>" << endl;
} else {
if (node->getType() != SGPropertyNode::UNSPECIFIED)
output << " type=\"" << getTypeName(node->getType()) << '"';
output << '>';
writeData(output, node->getStringValue());
@@ -358,9 +459,8 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
// next.
if (nChildren > 0 || node->isAlias()) {
doIndent(output, indent);
output << '<' << name << " n=\"" << index << '"';
if (node->isAlias() && node->getAliasTarget() != 0)
output << " alias=\"" << node->getAliasTarget()->getPath() << '"';
output << '<' << name;
writeAtts(output, node);
output << '>' << endl;
for (int i = 0; i < nChildren; i++)
writeNode(output, node->getChild(i), indent + INDENT_STEP);
@@ -368,26 +468,11 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
output << "</" << name << '>' << endl;
}
// If there were no children and no
// value, at least note the presence
// of the node.
// if (nChildren == 0 && !node->isAlias() && !node->hasValue()) {
// doIndent(output, indent);
// output << '<' << name << " n=\"" << index << "\"/>" << endl;
// }
return true;
}
/**
* Write a property tree to an output stream in XML format.
*
* @param output The output stream.
* @param start_node The root node to write.
* @return true if the write succeeded, false otherwise.
*/
bool
void
writeProperties (ostream &output, const SGPropertyNode * start_node)
{
int nChildren = start_node->nChildren();
@@ -400,28 +485,17 @@ writeProperties (ostream &output, const SGPropertyNode * start_node)
}
output << "</PropertyList>" << endl;
return true;
}
/**
* Write a property tree to a file in XML format.
*
* @param file The destination file.
* @param start_node The root node to write.
* @return true if the write succeeded, false otherwise.
*/
bool
void
writeProperties (const string &file, const SGPropertyNode * start_node)
{
ofstream output(file.c_str());
if (output.good()) {
return writeProperties(output, start_node);
writeProperties(output, start_node);
} else {
SG_LOG(SG_INPUT, SG_ALERT, "Cannot write properties to file "
<< file);
return false;
throw sg_io_exception("Cannot open file", sg_location(file));
}
}
@@ -449,36 +523,38 @@ copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
// if any.
if (in->hasValue()) {
switch (in->getType()) {
case SGValue::BOOL:
case SGPropertyNode::BOOL:
if (!out->setBoolValue(in->getBoolValue()))
retval = false;
break;
case SGValue::INT:
case SGPropertyNode::INT:
if (!out->setIntValue(in->getIntValue()))
retval = false;
break;
case SGValue::LONG:
case SGPropertyNode::LONG:
if (!out->setLongValue(in->getLongValue()))
retval = false;
break;
case SGValue::FLOAT:
case SGPropertyNode::FLOAT:
if (!out->setFloatValue(in->getFloatValue()))
retval = false;
break;
case SGValue::DOUBLE:
case SGPropertyNode::DOUBLE:
if (!out->setDoubleValue(in->getDoubleValue()))
retval = false;
break;
case SGValue::STRING:
case SGPropertyNode::STRING:
if (!out->setStringValue(in->getStringValue()))
retval = false;
break;
case SGValue::UNKNOWN:
if (!out->setUnknownValue(in->getStringValue()))
case SGPropertyNode::UNSPECIFIED:
if (!out->setUnspecifiedValue(in->getStringValue()))
retval = false;
break;
default:
throw string("Unknown SGValue type");
string message = "Unknown internal SGPropertyNode type";
message += in->getType();
throw sg_error(message, "SimGear Property Reader");
}
}
+81 -83
View File
@@ -50,13 +50,13 @@ static double getNum (int index) { return 1.0 / index; }
////////////////////////////////////////////////////////////////////////
static void
show_values (const SGValue * value)
show_values (const SGPropertyNode * node)
{
cout << "Bool: " << value->getBoolValue() << endl;
cout << "Int: " << value->getIntValue() << endl;
cout << "Float: " << value->getFloatValue() << endl;
cout << "Double: " << value->getDoubleValue() << endl;
cout << "String: " << value->getStringValue() << endl;
cout << "Bool: " << node->getBoolValue() << endl;
cout << "Int: " << node->getIntValue() << endl;
cout << "Float: " << node->getFloatValue() << endl;
cout << "Double: " << node->getDoubleValue() << endl;
cout << "String: " << node->getStringValue() << endl;
}
@@ -68,7 +68,7 @@ show_values (const SGValue * value)
static void
test_value ()
{
SGValue * value;
SGPropertyNode * node;
cout << endl << "Value" << endl << endl;
@@ -77,81 +77,81 @@ test_value ()
//
cout << "Testing coercion from bool (expect true)" << endl;
value = new SGValue;
value->setBoolValue(true);
show_values(value);
delete value;
node = new SGPropertyNode;
node->setBoolValue(true);
show_values(node);
delete node;
cout << endl;
cout << "Testing coercion from int (expect 128)" << endl;
value = new SGValue;
value->setIntValue(128);
show_values(value);
delete value;
node = new SGPropertyNode;
node->setIntValue(128);
show_values(node);
delete node;
cout << endl;
cout << "Testing coercion from float (expect 1.0/3.0)" << endl;
value = new SGValue;
value->setFloatValue(1.0/3.0);
show_values(value);
delete value;
node = new SGPropertyNode;
node->setFloatValue(1.0/3.0);
show_values(node);
delete node;
cout << endl;
cout << "Testing coercion from double (expect 1.0/3.0)" << endl;
value = new SGValue;
value->setDoubleValue(1.0/3.0);
show_values(value);
delete value;
node = new SGPropertyNode;
node->setDoubleValue(1.0/3.0);
show_values(node);
delete node;
cout << endl;
cout << "Testing coercion from string (expect 10e4)" << endl;
value = new SGValue;
value->setStringValue("10e4");
show_values(value);
delete value;
node = new SGPropertyNode;
node->setStringValue("10e4");
show_values(node);
delete node;
cout << endl;
cout << "Testing coercion from unknown (expect -10e-4)" << endl;
value = new SGValue;
value->setUnknownValue("-10e-4");
show_values(value);
delete value;
cout << "Testing coercion from unspecified (expect -10e-4)" << endl;
node = new SGPropertyNode;
node->setUnspecifiedValue("-10e-4");
show_values(node);
delete node;
cout << endl;
//
// Test coercion for setters.
//
value = new SGValue;
node = new SGPropertyNode;
cout << "Testing coercion to bool from bool (expect false)" << endl;
value->setBoolValue(false);
show_values(value);
node->setBoolValue(false);
show_values(node);
cout << endl;
cout << "Testing coercion to bool from int (expect 1)" << endl;
value->setIntValue(1);
show_values(value);
node->setIntValue(1);
show_values(node);
cout << endl;
cout << "Testing coercion to bool from float (expect 1.1)" << endl;
value->setFloatValue(1.1);
show_values(value);
node->setFloatValue(1.1);
show_values(node);
cout << endl;
cout << "Testing coercion to bool from double (expect 1.1)" << endl;
value->setDoubleValue(1.1);
show_values(value);
node->setDoubleValue(1.1);
show_values(node);
cout << endl;
cout << "Testing coercion to bool from string (expect 1e10)" << endl;
value->setStringValue("1e10");
show_values(value);
node->setStringValue("1e10");
show_values(node);
cout << endl;
cout << "Testing coercion to bool from unknown (expect 1e10)" << endl;
value->setUnknownValue("1e10");
show_values(value);
cout << "Testing coercion to bool from unspecified (expect 1e10)" << endl;
node->setUnspecifiedValue("1e10");
show_values(node);
cout << endl;
// Test tying to a pointer.
@@ -159,67 +159,67 @@ test_value ()
static int myValue = 10;
cout << "Testing tying to a pointer (expect 10)" << endl;
if (!value->tie(SGRawValuePointer<int>(&myValue)))
if (!node->tie(SGRawValuePointer<int>(&myValue), false))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Changing base variable (expect -5)" << endl;
myValue = -5;
show_values(value);
if (!value->untie())
cout << "*** FAIELD TO UNTIE VALUE!!!" << endl;
show_values(node);
if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
cout << endl;
// Test tying to static functions.
cout << "Create a new int value (expect 10)" << endl;
value->setIntValue(10);
show_values(value);
node->setIntValue(10);
show_values(node);
cout << endl;
cout << "Testing tying to static getter (expect 100)" << endl;
if (!value->tie(SGRawValueFunctions<int>(get100)))
if (!node->tie(SGRawValueFunctions<int>(get100)))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Try changing value with no setter (expect 100)" << endl;
if (value->setIntValue(200))
if (node->setIntValue(200))
cout << "*** setIntValue did not return false!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Untie value (expect 100)" << endl;
if (!value->untie())
if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Try changing value (expect 200)" << endl;
if (!value->setIntValue(200))
if (!node->setIntValue(200))
cout << "*** setIntValue RETURNED FALSE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
// Test tying to indexed static functions.
cout << "Create a new int value (expect 10)" << endl;
value->setIntValue(10);
show_values(value);
node->setIntValue(10);
show_values(node);
cout << endl;
cout << "Testing tying to indexed static getter (0.3333...)" << endl;
if (!value->tie(SGRawValueFunctionsIndexed<double>(3, getNum)))
if (!node->tie(SGRawValueFunctionsIndexed<double>(3, getNum)))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Untie value (expect 0.3333...)" << endl;
if (!value->untie())
if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
@@ -230,39 +230,39 @@ test_value ()
SGRawValueMethods<class Stuff,float> tiedstuff(stuff,
&Stuff::getStuff,
&Stuff::setStuff);
if (!value->tie(tiedstuff, false))
if (!node->tie(tiedstuff, false))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Try untying from object (expect 199)" << endl;
if (!value->untie())
if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Try tying to an indexed method (expect 199)" << endl;
if (!value->tie(SGRawValueMethodsIndexed<class Stuff, float>
if (!node->tie(SGRawValueMethodsIndexed<class Stuff, float>
(stuff, 2, &Stuff::getStuff, &Stuff::setStuff)))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
value->untie();
node->untie();
cout << "Change value (expect 50)" << endl;
if (!value->setIntValue(50))
if (!node->setIntValue(50))
cout << "*** FAILED TO SET VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
cout << "Try tying to an object with defaults (expect 50)" << endl;
if (!value->tie(tiedstuff, true))
if (!node->tie(tiedstuff, true))
cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value);
show_values(node);
cout << endl;
delete value;
delete node;
}
@@ -334,10 +334,8 @@ int main (int ac, char ** av)
for (int i = 1; i < ac; i++) {
cout << "Reading " << av[i] << endl;
SGPropertyNode root;
if (!readProperties(av[i], &root))
cerr << "Failed to read properties from " << av[i] << endl;
else
writeProperties(cout, &root);
readProperties(av[i], &root);
writeProperties(cout, &root);
cout << endl;
}
+35 -25
View File
@@ -24,6 +24,7 @@
#include <simgear_config.h>
#include <stdio.h>
#include "sg_path.hxx"
@@ -33,34 +34,35 @@
// should be used in file or directory names. In windoze, allow the
// second character to be a ":" for things like c:\foo\bar
static string fix_path( const string path ) {
string result = path;
for ( int i = 0; i < (int)path.size(); ++i ) {
void
SGPath::fix()
{
for ( string::size_type i = 0; i < path.size(); ++i ) {
#if defined( WIN32 )
// for windoze, don't replace the ":" for the second character
if ( i == 1 ) {
continue;
}
#endif
if ( result[i] == SG_BAD_PATH_SEP ) {
result[i] = SG_PATH_SEP;
if ( path[i] == SG_BAD_PATH_SEP ) {
path[i] = SG_PATH_SEP;
}
}
return result;
}
// default constructor
SGPath::SGPath() {
path = "";
SGPath::SGPath()
: path("")
{
}
// create a path based on "path"
SGPath::SGPath( const string p ) {
set( p );
SGPath::SGPath( const std::string& p )
: path(p)
{
fix();
}
@@ -70,36 +72,35 @@ SGPath::~SGPath() {
// set path
void SGPath::set( const string p ) {
path = fix_path( p );
void SGPath::set( const string& p ) {
path = p;
fix();
}
// append another piece to the existing path
void SGPath::append( const string p ) {
string part = fix_path( p );
void SGPath::append( const string& p ) {
if ( path.size() == 0 ) {
path = part;
path = p;
} else {
if ( part[0] != SG_PATH_SEP ) {
if ( p[0] != SG_PATH_SEP ) {
path += SG_PATH_SEP;
}
path += part;
path += p;
}
fix();
}
// concatenate a string to the end of the path without inserting a
// path separator
void SGPath::concat( const string p ) {
string part = fix_path( p );
void SGPath::concat( const string& p ) {
if ( path.size() == 0 ) {
path = part;
path = p;
} else {
path += part;
path += p;
}
fix();
}
@@ -112,3 +113,12 @@ string SGPath::dir() {
return "";
}
}
bool SGPath::exists() const {
FILE* fp = fopen( path.c_str(), "r");
if (fp == 0) {
return false;
}
fclose(fp);
return true;
}
+18 -6
View File
@@ -69,7 +69,7 @@ public:
* Construct a path based on the starting path provided.
* @param p initial path
*/
SGPath( const string p );
SGPath( const string& p );
/** Destructor */
~SGPath();
@@ -78,20 +78,21 @@ public:
* Set path to a new value
* @param p new path
*/
void set( const string p );
void set( const string& p );
SGPath& operator= ( const char* p ) { this->set(p); return *this; }
/**
* Append another piece to the existing path. Inserts a path
* separator between the existing component and the new component.
* @param p additional path component */
void append( const string p );
void append( const string& p );
/**
* Concatenate a string to the end of the path without inserting a
* path separator.
* @param p addtional path suffix
*/
void concat( const string p );
void concat( const string& p );
/**
* Get the directory part of the path.
@@ -102,12 +103,23 @@ public:
/** Get the path string
* @return path string
*/
inline string str() const { return path; }
string str() const { return path; }
/** Get the path string
* @return path in "C" string (ptr to char array) form.
*/
inline const char *c_str() { return path.c_str(); }
const char* c_str() { return path.c_str(); }
/**
* Determine if file exists by attempting to fopen it.
* @return true if file exists, otherwise returns false.
*/
bool exists() const;
private:
void fix();
};
+1 -5
View File
@@ -30,11 +30,7 @@
#include <simgear/compiler.h>
#ifdef HAVE_ZLIB
# include <zlib.h>
#else
# include <simgear/zlib/zlib.h>
#endif
#include <zlib.h>
// At least Irix needs this
#ifdef SG_HAVE_NATIVE_SGI_COMPILERS
+5
View File
@@ -0,0 +1,5 @@
.deps
Makefile
Makefile.in
routetest
waytest
+6 -1
View File
@@ -8,7 +8,11 @@ libsgroute_a_SOURCES = \
route.cxx \
waypoint.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
noinst_PROGRAMS = waytest routetest
@@ -19,6 +23,7 @@ waytest_LDADD = \
$(top_builddir)/simgear/math/libsgmath.a \
$(top_builddir)/simgear/debug/libsgdebug.a \
$(top_builddir)/simgear/misc/libsgmisc.a \
$(top_builddir)/simgear/xml/libsgxml.a \
-lz
routetest_SOURCES = routetest.cxx
@@ -26,4 +31,4 @@ routetest_SOURCES = routetest.cxx
routetest_LDADD = \
$(top_builddir)/simgear/route/libsgroute.a \
$(top_builddir)/simgear/math/libsgmath.a \
$(top_builddir)/simgear/debug/libsgdebug.a
$(top_builddir)/simgear/debug/libsgdebug.a
-5
View File
@@ -38,11 +38,6 @@ SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt,
}
SGWayPoint::SGWayPoint() {
SGWayPoint( 0.0, 0.0, 0.0, WGS84, "" );
}
// Destructor
SGWayPoint::~SGWayPoint() {
}
+3 -5
View File
@@ -79,9 +79,6 @@ private:
public:
/** Default constructor */
SGWayPoint();
/**
* Construct a waypoint
* @param lon destination longitude
@@ -90,8 +87,9 @@ public:
* @param mode type of coordinates/math to use
* @param s waypoint identifier
*/
SGWayPoint( const double lon, const double lat, const double alt,
const modetype m = WGS84, const string s = "" );
SGWayPoint( const double lon = 0.0, const double lat = 0.0,
const double alt = 0.0, const modetype m = WGS84,
const string s = "" );
/** Destructor */
~SGWayPoint();
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+15 -1
View File
@@ -2,11 +2,25 @@ includedir = @includedir@/screen
lib_LIBRARIES = libsgscreen.a
include_HEADERS = screen-dump.hxx
if ENABLE_JPEG_SERVER
IMAGE_SERVER_INCL = jpgfactory.hxx
IMAGE_SERVER_SRCS = jpgfactory.cxx
else
IMAGE_SERVER_INCL =
IMAGE_SERVER_SRCS =
endif
include_HEADERS = $(IMAGE_SERVER_INCL) screen-dump.hxx tr.h
libsgscreen_a_SOURCES = \
GLBitmaps.cxx GLBitmaps.h \
$(IMAGE_SERVER_SRCS) \
screen-dump.cxx \
tr.cxx \
win32-printer.h
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+371
View File
@@ -0,0 +1,371 @@
// jpgfactory.cxx -- jpeg frontend for TR library
//
// Written by Norman Vine, started August 2001.
//
// Copyright (C) 2001 Norman Vine - nhv@yahoo.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id:
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <plib/ssg.h>
#include "jpgfactory.hxx"
#ifdef __cplusplus
extern "C" {
#endif
static void init_destination (j_compress_ptr cinfo);
static void term_destination (j_compress_ptr cinfo);
static boolean empty_output_buffer (j_compress_ptr cinfo);
#ifdef __cplusplus
}
#endif
typedef struct {
struct jpeg_destination_mgr pub; /* public fields */
unsigned char * outfile; /* target stream */
JOCTET * buffer; /* start of buffer */
int numbytes; /* num bytes used */
int maxsize; /* size of outfile */
int error; /* error flag */
} my_destination_mgr;
typedef my_destination_mgr * my_dest_ptr;
/* Where should this go <simgear/screen/tr.h> ?? */
extern void trRenderFrame( void );
trJpgFactory::trJpgFactory() {
imageWidth = imageHeight = 0;
tile = NULL;
buffer = NULL;
IMAGE = NULL;
tr = NULL;
cinfo.dest = NULL;
}
trJpgFactory::~trJpgFactory() {
destroy();
}
/*
* deallocate our dynamic parts
*/
void trJpgFactory::destroy( int error )
{
if( error )
printf( "!! Malloc Failure trJpgFactory ( %d )!!\n",
error );
if( cinfo.dest ) jpeg_destroy_compress(&cinfo);
if( tr ) trDelete(tr);
if( IMAGE ) delete [] IMAGE;
if( buffer ) delete [] buffer;
if( tile ) delete [] tile;
}
/*
* allocate and initialize the jpeg compress struct
* application needs to dealocate this
*/
int trJpgFactory::jpeg_init()
{
j_compress_ptr cinfoPtr = &cinfo;
cinfoPtr->err = jpeg_std_error(&jerr);
jpeg_create_compress(cinfoPtr);
/* following taken from jpeg library exaample code */
cinfoPtr->dest = (struct jpeg_destination_mgr *)
(*cinfoPtr->mem->alloc_small)
((j_common_ptr)cinfoPtr,
JPOOL_PERMANENT,
sizeof(my_destination_mgr));
my_dest_ptr dest = (my_dest_ptr)cinfoPtr->dest;
if( !dest ) {
destroy(5);
return 5;
}
dest->pub.init_destination = init_destination;
dest->pub.empty_output_buffer = empty_output_buffer;
dest->pub.term_destination = term_destination;
dest->outfile = NULL;
dest->numbytes = 0;
dest->maxsize = 0;
cinfoPtr->image_width = imageWidth;
cinfoPtr->image_height = imageHeight;
cinfoPtr->input_components = 3;
cinfoPtr->in_color_space = JCS_RGB;
jpeg_set_defaults(cinfoPtr);
jpeg_set_quality(cinfoPtr, (100 * 90) >> 8, TRUE);
return 0;
}
/*
* may also be used as reinit() to change image size
*/
int trJpgFactory::init(int width, int height )
{
destroy();
if( width <= 0 || height <= 0 ) {
imageWidth = DEFAULT_XS;
imageHeight = DEFAULT_YS;
} else {
imageWidth = width;
imageHeight = height;
}
int bufsize = imageWidth * imageHeight * 3 * sizeof(GLubyte);
/* allocate buffer large enough to store one tile */
tile = new GLubyte[bufsize];
if (!tile) {
destroy(1);
return 1;
}
/* allocate buffer to hold a row of tiles */
buffer = new GLubyte[ bufsize ];
if (!buffer) {
destroy(2);
return 2;
}
/* this should be big enough */
IMAGESIZE = bufsize + 1024;
IMAGE = new unsigned char[ IMAGESIZE ];
if( !IMAGE ) {
destroy(3);
return 3;
}
tr = trNew();
if( !tr ) {
destroy(4);
return 4;
}
trRowOrder(tr, TR_TOP_TO_BOTTOM);
trTileSize(tr, imageWidth, imageHeight, 0);
trImageSize(tr, imageWidth, imageHeight);
trTileBuffer(tr, GL_RGB, GL_UNSIGNED_BYTE, tile);
return jpeg_init();
}
/*
*compress the image
*/
int trJpgFactory::compress()
{
JSAMPROW row_pointer[1];
int row_stride;
/* to keep track of jpeg library routines */
my_dest_ptr dest = (my_dest_ptr) cinfo.dest;
//printf("\tjpeg_start_compress(&cinfo, TRUE)\n");
jpeg_start_compress(&cinfo, TRUE);
if( !dest->error ) {
dest->outfile = IMAGE;
dest->maxsize = IMAGESIZE;
row_stride = cinfo.image_width * 3;
while( cinfo.next_scanline < cinfo.image_height &&
!dest->error )
{
row_pointer[0] = buffer + (cinfo.next_scanline * row_stride);
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
}
if( !dest->error ) {
// printf("\n\tBEFORE: jpeg_finish_compress(&cinfo)\n");
jpeg_finish_compress(&cinfo);
// printf("\tAFTER: jpeg_finish_compress(&cinfo)\n");
} else {
printf("INTERNAL JPEG_FACTORY ERROR\n");
jpeg_abort_compress(&cinfo);
/* OK - I am paranoid */
dest->numbytes = 0;
}
return dest->numbytes;
}
/*
* Makes the image then calls compress()
*/
int trJpgFactory::render()
{
if( !tr ) {
printf("!! NO tr !!\n trJpgFactory::render()\n");
return 0;
}
// Make sure we have SSG projection primed for current view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
sgFrustum *frustum = ssgGetFrustum();
trFrustum(tr,
frustum->getLeft(), frustum->getRight(),
frustum->getBot(), frustum->getTop(),
frustum->getNear(), frustum->getFar());
/* just to be safe... */
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// printf("\ttrBeginTile(tr)\n");
trBeginTile(tr);
trRenderFrame();
trEndTile(tr);
/* just to be safe */
int curTileHeight = trGet(tr, TR_CURRENT_TILE_HEIGHT);
int curTileWidth = trGet(tr, TR_CURRENT_TILE_WIDTH);
/* reverse image top to bottom */
int bytesPerImageRow = imageWidth * 3*sizeof(GLubyte);
int bytesPerTileRow = imageWidth * 3*sizeof(GLubyte);
int bytesPerCurrentTileRow = (curTileWidth) * 3*sizeof(GLubyte);
int i;
for (i=0;i<imageHeight;i++) {
memcpy(buffer + (curTileHeight-1-i) * bytesPerImageRow, /* Dest */
tile + i*bytesPerTileRow, /* Src */
bytesPerCurrentTileRow); /* Byte count*/
}
// printf("exit trJpgFactory::render()\n");
return compress();
}
#define OUTPUT_BUF_SIZE 4096
#ifdef __cplusplus
extern "C" {
#endif
/*
* Initialize destination --- called by jpeg_start_compress
* before any data is actually written.
*/
static void init_destination (j_compress_ptr cinfo)
{
// printf("enter init_destination()\n");
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
/* following taken from jpeg library exaample code
* Allocate the output buffer ---
* it automaically will be released when done with image */
dest->buffer = (JOCTET *)(*cinfo->mem->alloc_small)
((j_common_ptr)cinfo, JPOOL_IMAGE,
OUTPUT_BUF_SIZE * sizeof(JOCTET) );
if( !dest->buffer ) {
printf("MALLOC FAILED jpegFactory init_destination()\n");
dest->error = TRUE;
} else {
dest->error = FALSE;
}
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
dest->numbytes = 0;
}
/*
* Empty the output buffer --- called whenever buffer fills up.
*/
static boolean empty_output_buffer (j_compress_ptr cinfo)
{
// printf("enter empty_output_buffer(%d)\n", OUTPUT_BUF_SIZE);
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
if( (!dest->error) &&
((dest->numbytes + OUTPUT_BUF_SIZE) < dest->maxsize) )
{
memcpy( dest->outfile+dest->numbytes, dest->buffer, (size_t)OUTPUT_BUF_SIZE);
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
dest->numbytes += OUTPUT_BUF_SIZE;
} else {
printf("BUFFER OVERFLOW jpegFactory empty_output_buffer()\n");
dest->numbytes = 0;
dest->error = TRUE;
}
return TRUE;
}
/*
* Terminate destination --- called by jpeg_finish_compress
* after all data has been written. Usually needs to flush buffer.
*
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
* application must deal with any cleanup that should happen even
* for error exit.
*/
static void term_destination (j_compress_ptr cinfo)
{
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
if( (!dest->error) &&
((dest->numbytes + datacount) < (unsigned int)dest->maxsize) )
{
memcpy( dest->outfile+dest->numbytes, dest->buffer, datacount);
dest->numbytes += datacount;
} else {
printf("BUFFER OVERFLOW jpegFactory term_destination()\n");
dest->numbytes = 0;
dest->error = TRUE;
}
// printf(" term_destination(%d) total %d\n", datacount, dest->numbytes );
}
#ifdef __cplusplus
}
#endif
+75
View File
@@ -0,0 +1,75 @@
// jpgfactory.hxx -- jpeg frontend for TR library
//
// Written by Norman Vine, started August 2001.
//
// Copyright (C) 2001 Norman Vine - nhv@yahoo.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id:
#ifndef _FG_JPGFACTORY_HXX
#define _FG_JPGFACTORY_HXX
#ifdef __cplusplus
extern "C" {
#endif
#include <jpeglib.h>
#include <jerror.h>
#ifdef __cplusplus
}
#endif
#include <simgear/screen/tr.h>
/* should look at how VNC does this */
class trJpgFactory {
private:
int imageWidth;
int imageHeight;
GLubyte *tile;
GLubyte *buffer;
TRcontext *tr;
unsigned char *IMAGE;
int IMAGESIZE;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
int jpeg_init();
int compress();
typedef enum {
DEFAULT_XS = 320,
DEFAULT_YS = 240
} JPG_FACTORY_ENUM;
public:
trJpgFactory();
~trJpgFactory();
int init(int width = 0, int height = 0 );
void destroy(int error = 0);
int render();
unsigned char *data() { return IMAGE ; }
struct jpeg_compress_struct *JPGinfo() { return &cinfo ; }
};
#endif // #ifndef _FG_JPGFACTORY_HXX
+514
View File
@@ -0,0 +1,514 @@
/* $Id$ */
/*
* $Log$
* Revision 1.3 2001/07/30 20:34:21 curt
* Various MSVC fixes.
*
* Revision 1.2 2001/06/27 02:48:01 curt
* Fixed a type conversion bug that could trip up some of the pickier compilers
* out there.
*
* Revision 1.1 2001/06/26 15:19:39 curt
* Added tr.cxx / tr.h, Brian Paul's LGPL'd tiled rendering support libs for
* rendering ultra high res "tiled" screen shots.
*
* Revision 1.9 1998/01/29 16:56:54 brianp
* allow trOrtho() and trFrustum() to be called at any time, minor clean-up
*
* Revision 1.8 1998/01/28 19:47:39 brianp
* minor clean-up for C++
*
* Revision 1.7 1997/07/21 17:34:38 brianp
* added tile borders
*
* Revision 1.6 1997/07/21 15:47:35 brianp
* renamed all "near" and "far" variables
*
* Revision 1.5 1997/04/26 21:23:25 brianp
* added trRasterPos3f function
*
* Revision 1.4 1997/04/26 19:59:36 brianp
* set CurrentTile to -1 before first tile and after last tile
*
* Revision 1.3 1997/04/22 23:51:15 brianp
* added WIN32 header stuff, removed tabs
*
* Revision 1.2 1997/04/19 23:26:10 brianp
* many API changes
*
* Revision 1.1 1997/04/18 21:53:05 brianp
* Initial revision
*
*/
/*
* Tiled Rendering library
* Version 1.1
* Copyright (C) Brian Paul
*/
#include <simgear/compiler.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <plib/ssg.h>
#include "tr.h"
#define DEFAULT_TILE_WIDTH 256
#define DEFAULT_TILE_HEIGHT 256
#define DEFAULT_TILE_BORDER 0
struct _TRctx {
/* Final image parameters */
GLint ImageWidth, ImageHeight;
GLenum ImageFormat, ImageType;
GLvoid *ImageBuffer;
/* Tile parameters */
GLint TileWidth, TileHeight;
GLint TileWidthNB, TileHeightNB;
GLint TileBorder;
GLenum TileFormat, TileType;
GLvoid *TileBuffer;
/* Projection parameters */
GLboolean Perspective;
GLdouble Left;
GLdouble Right;
GLdouble Bottom;
GLdouble Top;
GLdouble Near;
GLdouble Far;
/* Misc */
TRenum RowOrder;
GLint Rows, Columns;
GLint CurrentTile;
GLint CurrentTileWidth, CurrentTileHeight;
GLint CurrentRow, CurrentColumn;
GLint ViewportSave[4];
};
/*
* Misc setup including computing number of tiles (rows and columns).
*/
static void Setup(TRcontext *tr)
{
if (!tr)
return;
tr->Columns = (tr->ImageWidth + tr->TileWidthNB - 1) / tr->TileWidthNB;
tr->Rows = (tr->ImageHeight + tr->TileHeightNB - 1) / tr->TileHeightNB;
tr->CurrentTile = 0;
assert(tr->Columns >= 0);
assert(tr->Rows >= 0);
}
TRcontext *trNew(void)
{
TRcontext *tr = (TRcontext *) calloc(1, sizeof(TRcontext));
if (tr) {
tr->TileWidth = DEFAULT_TILE_WIDTH;
tr->TileHeight = DEFAULT_TILE_HEIGHT;
tr->TileBorder = DEFAULT_TILE_BORDER;
tr->RowOrder = TR_BOTTOM_TO_TOP;
tr->CurrentTile = -1;
}
return (TRcontext *) tr;
}
void trDelete(TRcontext *tr)
{
if (tr)
free(tr);
}
void trTileSize(TRcontext *tr, GLint width, GLint height, GLint border)
{
if (!tr)
return;
assert(border >= 0);
assert(width >= 1);
assert(height >= 1);
assert(width >= 2*border);
assert(height >= 2*border);
tr->TileBorder = border;
tr->TileWidth = width;
tr->TileHeight = height;
tr->TileWidthNB = width - 2 * border;
tr->TileHeightNB = height - 2 * border;
Setup(tr);
}
void trTileBuffer(TRcontext *tr, GLenum format, GLenum type, GLvoid *image)
{
if (!tr)
return;
tr->TileFormat = format;
tr->TileType = type;
tr->TileBuffer = image;
}
void trImageSize(TRcontext *tr, GLint width, GLint height)
{
if (!tr)
return;
tr->ImageWidth = width;
tr->ImageHeight = height;
Setup(tr);
}
void trImageBuffer(TRcontext *tr, GLenum format, GLenum type, GLvoid *image)
{
if (!tr)
return;
tr->ImageFormat = format;
tr->ImageType = type;
tr->ImageBuffer = image;
}
GLint trGet(TRcontext *tr, TRenum param)
{
if (!tr)
return 0;
switch (param) {
case TR_TILE_WIDTH:
return tr->TileWidth;
case TR_TILE_HEIGHT:
return tr->TileHeight;
case TR_TILE_BORDER:
return tr->TileBorder;
case TR_IMAGE_WIDTH:
return tr->ImageWidth;
case TR_IMAGE_HEIGHT:
return tr->ImageHeight;
case TR_ROWS:
return tr->Rows;
case TR_COLUMNS:
return tr->Columns;
case TR_CURRENT_ROW:
if (tr->CurrentTile<0)
return -1;
else
return tr->CurrentRow;
case TR_CURRENT_COLUMN:
if (tr->CurrentTile<0)
return -1;
else
return tr->CurrentColumn;
case TR_CURRENT_TILE_WIDTH:
return tr->CurrentTileWidth;
case TR_CURRENT_TILE_HEIGHT:
return tr->CurrentTileHeight;
case TR_ROW_ORDER:
return (GLint) tr->RowOrder;
default:
return 0;
}
}
GLdouble trGetD(TRcontext *tr, TRenum param)
{
if (!tr)
return 0.0;
switch (param) {
case TR_LEFT:
return tr->Left;
case TR_RIGHT:
return tr->Right;
case TR_BOTTOM:
return tr->Bottom;
case TR_TOP:
return tr->Top;
case TR_NEAR:
return tr->Near;
case TR_FAR:
return tr->Far;
default:
return 0.0;
}
}
void trRowOrder(TRcontext *tr, TRenum order)
{
if (!tr)
return;
if (order==TR_TOP_TO_BOTTOM || order==TR_BOTTOM_TO_TOP)
tr->RowOrder = order;
}
void trOrtho(TRcontext *tr,
GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar)
{
if (!tr)
return;
tr->Perspective = GL_FALSE;
tr->Left = left;
tr->Right = right;
tr->Bottom = bottom;
tr->Top = top;
tr->Near = zNear;
tr->Far = zFar;
}
void trFrustum(TRcontext *tr,
GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar)
{
if (!tr)
return;
tr->Perspective = GL_TRUE;
tr->Left = left;
tr->Right = right;
tr->Bottom = bottom;
tr->Top = top;
tr->Near = zNear;
tr->Far = zFar;
}
void trPerspective(TRcontext *tr,
GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar )
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * 3.14159265 / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
trFrustum(tr, xmin, xmax, ymin, ymax, zNear, zFar);
}
void trBeginTile(TRcontext *tr)
{
GLint matrixMode;
GLint tileWidth, tileHeight, border;
GLdouble left, right, bottom, top;
if (!tr)
return;
if (tr->CurrentTile <= 0) {
Setup(tr);
/* Save user's viewport, will be restored after last tile rendered */
glGetIntegerv(GL_VIEWPORT, tr->ViewportSave);
}
/* which tile (by row and column) we're about to render */
if (tr->RowOrder==TR_BOTTOM_TO_TOP) {
tr->CurrentRow = tr->CurrentTile / tr->Columns;
tr->CurrentColumn = tr->CurrentTile % tr->Columns;
}
else if (tr->RowOrder==TR_TOP_TO_BOTTOM) {
tr->CurrentRow = tr->Rows - (tr->CurrentTile / tr->Columns) - 1;
tr->CurrentColumn = tr->CurrentTile % tr->Columns;
}
else {
/* This should never happen */
abort();
}
assert(tr->CurrentRow < tr->Rows);
assert(tr->CurrentColumn < tr->Columns);
border = tr->TileBorder;
/* Compute actual size of this tile with border */
if (tr->CurrentRow < tr->Rows-1)
tileHeight = tr->TileHeight;
else
tileHeight = tr->ImageHeight - (tr->Rows-1) * (tr->TileHeightNB) + 2 * border;
if (tr->CurrentColumn < tr->Columns-1)
tileWidth = tr->TileWidth;
else
tileWidth = tr->ImageWidth - (tr->Columns-1) * (tr->TileWidthNB) + 2 * border;
/* Save tile size, with border */
tr->CurrentTileWidth = tileWidth;
tr->CurrentTileHeight = tileHeight;
glViewport(0, 0, tileWidth, tileHeight); /* tile size including border */
/* save current matrix mode */
glGetIntegerv(GL_MATRIX_MODE, &matrixMode);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* compute projection parameters */
left = tr->Left + (tr->Right - tr->Left)
* (tr->CurrentColumn * tr->TileWidthNB - border) / tr->ImageWidth;
right = left + (tr->Right - tr->Left) * tileWidth / tr->ImageWidth;
bottom = tr->Bottom + (tr->Top - tr->Bottom)
* (tr->CurrentRow * tr->TileHeightNB - border) / tr->ImageHeight;
top = bottom + (tr->Top - tr->Bottom) * tileHeight / tr->ImageHeight;
ssgSetFrustum ( left, right, bottom, top, tr->Near, tr->Far );
/* restore user's matrix mode */
glMatrixMode( (GLenum)matrixMode );
}
int trEndTile(TRcontext *tr)
{
GLint prevRowLength, prevSkipRows, prevSkipPixels /*, prevAlignment */;
if (!tr)
return 0;
assert(tr->CurrentTile>=0);
/* be sure OpenGL rendering is finished */
glFlush();
/* save current glPixelStore values */
glGetIntegerv(GL_PACK_ROW_LENGTH, &prevRowLength);
glGetIntegerv(GL_PACK_SKIP_ROWS, &prevSkipRows);
glGetIntegerv(GL_PACK_SKIP_PIXELS, &prevSkipPixels);
/*glGetIntegerv(GL_PACK_ALIGNMENT, &prevAlignment);*/
if (tr->TileBuffer) {
GLint srcX = tr->TileBorder;
GLint srcY = tr->TileBorder;
GLint srcWidth = tr->TileWidthNB;
GLint srcHeight = tr->TileHeightNB;
glReadPixels(srcX, srcY, srcWidth, srcHeight,
tr->TileFormat, tr->TileType, tr->TileBuffer);
}
if (tr->ImageBuffer) {
GLint srcX = tr->TileBorder;
GLint srcY = tr->TileBorder;
GLint srcWidth = tr->CurrentTileWidth - 2 * tr->TileBorder;
GLint srcHeight = tr->CurrentTileHeight - 2 * tr->TileBorder;
GLint destX = tr->TileWidthNB * tr->CurrentColumn;
GLint destY = tr->TileHeightNB * tr->CurrentRow;
/* setup pixel store for glReadPixels */
glPixelStorei(GL_PACK_ROW_LENGTH, tr->ImageWidth);
glPixelStorei(GL_PACK_SKIP_ROWS, destY);
glPixelStorei(GL_PACK_SKIP_PIXELS, destX);
/*glPixelStorei(GL_PACK_ALIGNMENT, 1);*/
/* read the tile into the final image */
glReadPixels(srcX, srcY, srcWidth, srcHeight,
tr->ImageFormat, tr->ImageType, tr->ImageBuffer);
}
/* restore previous glPixelStore values */
glPixelStorei(GL_PACK_ROW_LENGTH, prevRowLength);
glPixelStorei(GL_PACK_SKIP_ROWS, prevSkipRows);
glPixelStorei(GL_PACK_SKIP_PIXELS, prevSkipPixels);
/*glPixelStorei(GL_PACK_ALIGNMENT, prevAlignment);*/
/* increment tile counter, return 1 if more tiles left to render */
tr->CurrentTile++;
if (tr->CurrentTile >= tr->Rows * tr->Columns) {
/* restore user's viewport */
glViewport(tr->ViewportSave[0], tr->ViewportSave[1],
tr->ViewportSave[2], tr->ViewportSave[3]);
tr->CurrentTile = -1; /* all done */
return 0;
}
else
return 1;
}
/*
* Replacement for glRastePos3f() which avoids the problem with invalid
* raster pos.
*/
void trRasterPos3f(TRcontext *tr, GLfloat x, GLfloat y, GLfloat z)
{
if (tr->CurrentTile<0) {
/* not doing tile rendering right now. Let OpenGL do this. */
glRasterPos3f(x, y, z);
}
else {
GLdouble modelview[16], proj[16];
GLint viewport[4];
GLdouble winX, winY, winZ;
/* Get modelview, projection and viewport */
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
viewport[0] = 0;
viewport[1] = 0;
viewport[2] = tr->CurrentTileWidth;
viewport[3] = tr->CurrentTileHeight;
/* Project object coord to window coordinate */
if (gluProject(x, y, z, modelview, proj, viewport, &winX, &winY, &winZ)){
/* set raster pos to window coord (0,0) */
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, tr->CurrentTileWidth,
0.0, tr->CurrentTileHeight, 0.0, 1.0);
glRasterPos3f(0.0, 0.0, -winZ);
/* Now use empty bitmap to adjust raster position to (winX,winY) */
{
GLubyte bitmap[1] = {0};
glBitmap(1, 1, 0.0, 0.0, winX, winY, bitmap);
}
/* restore original matrices */
glPopMatrix(); /*proj*/
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
#ifdef DEBUG
if (glGetError())
printf("GL error!\n");
#endif
}
}
+170
View File
@@ -0,0 +1,170 @@
/* $Id$ */
/*
* $Log$
* Revision 1.1 2001/06/26 15:19:39 curt
* Added tr.cxx / tr.h, Brian Paul's LGPL'd tiled rendering support libs for
* rendering ultra high res "tiled" screen shots.
*
* Revision 1.5 1997/07/21 17:34:07 brianp
* added tile borders, incremented version to 1.1
*
* Revision 1.4 1997/07/21 15:47:35 brianp
* renamed all "near" and "far" variables
*
* Revision 1.3 1997/04/26 21:23:25 brianp
* added trRasterPos3f function
*
* Revision 1.2 1997/04/19 23:26:10 brianp
* many API changes
*
* Revision 1.1 1997/04/18 21:53:05 brianp
* Initial revision
*
*/
/*
* Tiled Rendering library
* Version 1.1
* Copyright (C) Brian Paul
*
*
* This library allows one to render arbitrarily large images with OpenGL.
* The basic idea is to break the image into tiles which are rendered one
* at a time. The tiles are assembled together to form the final, large
* image. Tiles and images can be of any size.
*
* Basic usage:
*
* 1. Allocate a tile rendering context:
* TRcontext t = trNew();
*
* 2. Specify the final image buffer and tile size:
* GLubyte image[W][H][4]
* trImageSize(t, W, H);
* trImageBuffer(t, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte *) image);
*
* 3. Setup your projection:
* trFrustum(t, left, right, bottom top, near, far);
* or
* trOrtho(t, left, right, bottom top, near, far);
* or
* trPerspective(t, fovy, aspect, near, far);
*
* 4. Render the tiles:
* do {
* trBeginTile(t);
* DrawMyScene();
* } while (trEndTile(t));
*
* You provide the DrawMyScene() function which calls glClear() and
* draws all your stuff.
*
* 5. The image array is now complete. Display it, write it to a file, etc.
*
* 6. Delete the tile rendering context when finished:
* trDelete(t);
*
*/
#ifndef TR_H
#define TR_H
#include <GL/gl.h>
//#ifdef __cplusplus
//extern "C" {
//#endif
#define TR_VERSION "1.1"
#define TR_MAJOR_VERSION 1
#define TR_MINOR_VERSION 1
typedef struct _TRctx TRcontext;
typedef enum {
TR_TILE_WIDTH = 100,
TR_TILE_HEIGHT,
TR_TILE_BORDER,
TR_IMAGE_WIDTH,
TR_IMAGE_HEIGHT,
TR_ROWS,
TR_COLUMNS,
TR_CURRENT_ROW,
TR_CURRENT_COLUMN,
TR_CURRENT_TILE_WIDTH,
TR_CURRENT_TILE_HEIGHT,
TR_ROW_ORDER,
TR_TOP_TO_BOTTOM,
TR_BOTTOM_TO_TOP,
TR_LEFT,
TR_RIGHT,
TR_BOTTOM,
TR_TOP,
TR_NEAR,
TR_FAR
} TRenum;
extern TRcontext *trNew(void);
extern void trDelete(TRcontext *tr);
extern void trTileSize(TRcontext *tr, GLint width, GLint height, GLint border);
extern void trTileBuffer(TRcontext *tr, GLenum format, GLenum type,
GLvoid *image);
extern void trImageSize(TRcontext *tr, GLint width, GLint height);
extern void trImageBuffer(TRcontext *tr, GLenum format, GLenum type,
GLvoid *image);
extern void trRowOrder(TRcontext *tr, TRenum order);
extern GLint trGet(TRcontext *tr, TRenum param);
extern GLdouble trGetD(TRcontext *tr, TRenum param);
extern void trOrtho(TRcontext *tr,
GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar);
extern void trFrustum(TRcontext *tr,
GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar);
extern void trPerspective(TRcontext *tr,
GLdouble fovy, GLdouble aspect,
GLdouble zNear, GLdouble zFar );
extern void trBeginTile(TRcontext *tr);
extern int trEndTile(TRcontext *tr);
extern void trRasterPos3f(TRcontext *tr, GLfloat x, GLfloat y, GLfloat z);
//#ifdef __cplusplus
//}
//#endif
#endif
+4
View File
@@ -0,0 +1,4 @@
.deps
Makefile
Makefile.in
testserial
+4
View File
@@ -14,4 +14,8 @@ testserial_LDADD = \
$(top_builddir)/simgear/serial/libsgserial.a \
$(top_builddir)/simgear/debug/libsgdebug.a
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+41 -1
View File
@@ -28,11 +28,13 @@
#ifndef _SG_INLINES_H
#define _SG_INLINES_H
// return the sign of a value
template <class T>
inline const int SG_SIGN(const T x) {
return x < T(0) ? -1 : 1;
}
// return the minimum of two values
template <class T>
inline const T SG_MIN2(const T a, const T b) {
return a < b ? a : b;
@@ -44,6 +46,7 @@ inline const T SG_MIN3( const T a, const T b, const T c) {
return (a < b ? SG_MIN2 (a, c) : SG_MIN2 (b, c));
}
// return the maximum of two values
template <class T>
inline const T SG_MAX2(const T a, const T b) {
return a > b ? a : b;
@@ -55,10 +58,47 @@ inline const T SG_MAX3 (const T a, const T b, const T c) {
return (a > b ? SG_MAX2 (a, c) : SG_MAX2 (b, c));
}
//
// return the minimum and maximum of three values
template <class T>
inline void SG_MIN_MAX3 ( T &min, T &max, const T a, const T b, const T c) {
if( a > b ) {
if( a > c ) {
max = a;
min = SG_MIN2 (b, c);
} else {
max = c;
min = SG_MIN2 (a, b);
}
} else {
if( b > c ) {
max = b;
min = SG_MIN2 (a, c);
} else {
max = c;
min = SG_MIN2 (a, b);
}
}
}
// swap two values
template <class T>
inline void SG_SWAP( T &a, T &b) {
T c = a; a = b; b = c;
}
// clamp a value to lie between min and max
template <class T>
inline void SG_CLAMP_RANGE(T &x, const T min, const T max ) {
if ( x < min ) { x = min; }
if ( x > max ) { x = max; }
}
// normalize a value to lie between min and max
template <class T>
inline void SG_NORMALIZE_RANGE( T &val, const T min, const T max ) {
T step = max - min;
while( val >= max ) val -= step;
while( val < min ) val += step;
};
#endif // _SG_INLINES_H
-4
View File
@@ -61,11 +61,7 @@
#define sgclose(F) (fclose((F)))
#else
#ifdef HAVE_ZLIB
#include <zlib.h>
#else
#include <simgear/zlib/zlib.h>
#endif
#define sgFile gzFile
+4 -4
View File
@@ -1,4 +1,4 @@
/* simgear/simgear_config.h.in. Generated automatically from configure.in by autoheader. */
/* simgear/simgear_config.h.in. Generated automatically from configure.in by autoheader 2.13. */
/* Define to empty if the keyword does not work. */
#undef const
@@ -50,9 +50,6 @@
/* Define if you have the vprintf function. */
#undef HAVE_VPRINTF
/* Define if you have zlib installed system wide. */
#undef HAVE_ZLIB
/* Define as the return type of signal handlers (int or void). */
#undef RETSIGTYPE
@@ -200,6 +197,9 @@
/* Define if you have the glut library (-lglut). */
#undef HAVE_LIBGLUT
/* Define if you have the jpeg library (-ljpeg). */
#undef HAVE_LIBJPEG
/* Define if you have the m library (-lm). */
#undef HAVE_LIBM
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -20,4 +20,8 @@ libsgsky_a_SOURCES = \
sphere.cxx \
stars.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+24 -4
View File
@@ -27,6 +27,7 @@
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/sg_random.h>
#include <simgear/debug/logstream.hxx>
#include "cloud.hxx"
@@ -204,12 +205,31 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
base = tl->get( 0 );
base[0] += xoff;
while ( base[0] > 1.0 ) { base[0] -= 1.0; }
while ( base[0] < 0.0 ) { base[0] += 1.0; }
// the while loops can lead to *long* pauses if base[0] comes
// with a bogus value.
// while ( base[0] > 1.0 ) { base[0] -= 1.0; }
// while ( base[0] < 0.0 ) { base[0] += 1.0; }
if ( base[0] > -10.0 && base[0] < 10.0 ) {
base[0] -= (int)base[0];
} else {
base[0] = 0.0;
SG_LOG(SG_ASTRO, SG_ALERT,
"Error: base = " << base[0] << "," << base[1]);
}
base[1] += yoff;
while ( base[1] > 1.0 ) { base[1] -= 1.0; }
while ( base[1] < 0.0 ) { base[1] += 1.0; }
// the while loops can lead to *long* pauses if base[0] comes
// with a bogus value.
// while ( base[1] > 1.0 ) { base[1] -= 1.0; }
// while ( base[1] < 0.0 ) { base[1] += 1.0; }
if ( base[1] > -10.0 && base[1] < 10.0 ) {
base[1] -= (int)base[1];
} else {
base[1] = 0.0;
SG_LOG(SG_ASTRO, SG_ALERT,
"Error: base = " << base[0] << "," << base[1]);
}
// cout << "base = " << base[0] << "," << base[1] << endl;
+8 -1
View File
@@ -57,12 +57,16 @@ static int sgMoonOrbPreDraw( ssgEntity *e ) {
return true;
}
static int sgMoonOrbPostDraw( ssgEntity *e ) {
/* cout << endl << "Moon orb post draw" << endl << "----------------"
<< endl << endl; */
// glEnable( GL_DEPTH_TEST );
// glEnable( GL_FOG );
// glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
// Some drivers don't properly reset glBendFunc with a
// glPopAttrib() so we reset it to the 'default' here.
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
glPopAttrib();
// cout << "pop error = " << glGetError() << endl;
@@ -78,6 +82,8 @@ static int sgMoonOrbPostDraw( ssgEntity *e ) {
return true;
}
#if 0
static int sgMoonHaloPreDraw( ssgEntity *e ) {
/* cout << endl << "Moon halo pre draw" << endl << "----------------"
<< endl << endl; */
@@ -107,6 +113,7 @@ static int sgMoonHaloPostDraw( ssgEntity *e ) {
return true;
}
#endif
// Constructor
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -10,4 +10,8 @@ include_HEADERS = \
libsgthreads_a_SOURCES = \
SGThread.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+1 -1
View File
@@ -1,6 +1,6 @@
#include <simgear/compiler.h>
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <time.h>
#else
# include <sys/time.h>
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -16,4 +16,8 @@ libsgtiming_a_SOURCES = \
timestamp.cxx \
timezone.cxx
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+128 -38
View File
@@ -31,7 +31,6 @@
#include <errno.h> // for errno
#ifdef SG_HAVE_STD_INCLUDES
# include <cmath>
# include <cstdio>
# include <cstdlib>
# include <ctime>
@@ -39,18 +38,19 @@
# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
#endif
#ifdef HAVE_SYS_TIMEB_H
# include <sys/timeb.h> // for ftime() and struct timeb
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h> // for gettimeofday()
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
#endif
#include <math.h> // for NAN
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
@@ -70,13 +70,19 @@ static const double J2000 = 2451545.0 - MJD0;
static const double SIDRATE = 0.9972695677;
SGTime::SGTime( double lon, double lat, const string& root )
void SGTime::init( double lon, double lat,
const string& root, time_t init_time )
{
SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );
gst_diff = -9999.0;
cur_time = time(NULL);
if ( init_time ) {
cur_time = init_time;
} else {
cur_time = time(NULL);
}
cout << "Current greenwich mean time = " << asctime(gmtime(&cur_time))
<< endl;
cout << "Current local time = "
@@ -103,25 +109,34 @@ SGTime::SGTime( double lon, double lat, const string& root )
}
}
SGTime::SGTime( double lon, double lat, const string& root, time_t init_time )
{
init( lon, lat, root, init_time );
}
SGTime::SGTime( const string& root ) {
SGTime( 0.0, 0.0, root );
init( 0.0, 0.0, root, 0 );
}
SGTime::SGTime() {
SGTime( 0.0, 0.0, "" );
init( 0.0, 0.0, "", 0 );
}
SGTime::~SGTime()
{
if ( tzContainer != NULL ) {
delete tzContainer;
TimezoneContainer *tmp = tzContainer;
tzContainer = NULL;
delete tmp;
}
if ( zonename != NULL ) {
delete zonename;
char *tmp = zonename;
zonename = NULL;
delete tmp;
}
}
@@ -149,7 +164,7 @@ static double sidereal_precise( double mjd, double lng )
// return a courser but cheaper estimate of sidereal time
static double sidereal_course( time_t cur_time, struct tm *gmt, double lng )
static double sidereal_course( time_t cur_time, const struct tm *gmt, double lng )
{
time_t start_gmt, now;
double diff, part, days, hours, lstTmp;
@@ -186,9 +201,10 @@ static double sidereal_course( time_t cur_time, struct tm *gmt, double lng )
// Update the time related variables
void SGTime::update( double lon, double lat, long int warp ) {
void SGTime::update( double lon, double lat, time_t ct, long int warp ) {
double gst_precise, gst_course;
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
tm * gmt = &m_gmt;
#endif
@@ -196,13 +212,17 @@ void SGTime::update( double lon, double lat, long int warp ) {
// get current Unix calendar time (in seconds)
// warp += warp_delta;
cur_time = time(NULL) + warp;
if ( ct ) {
cur_time = ct + warp;
} else {
cur_time = time(NULL) + warp;
}
SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
// get GMT break down for current time
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
#else
gmt = gmtime(&cur_time);
@@ -213,11 +233,8 @@ void SGTime::update( double lon, double lat, long int warp ) {
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
<< gmt->tm_sec );
// calculate modified Julian date
// t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday,
// (int)(t->gmt->tm_year + 1900));
mjd = sgTimeCalcMJD( (int)(gmt->tm_mon+1), (double)gmt->tm_mday,
(int)(gmt->tm_year + 1900) );
// calculate modified Julian date starting with current
mjd = sgTimeCurrentMJD( ct, warp );
// add in partial day
mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
@@ -256,23 +273,51 @@ void SGTime::update( double lon, double lat, long int warp ) {
// Given lon/lat, update timezone information and local_offset
void SGTime::updateLocal( double lon, double lat, const string& root )
{
time_t currGMT;
time_t aircraftLocalTime;
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
GeoCoord* nearestTz = tzContainer->getNearest(location);
SGPath zone( root );
zone.append ( nearestTz->getDescription() );
if ( zonename ) {
delete zonename;
}
zonename = strdup( zone.c_str() );
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zone.c_str())) );
local_offset = aircraftLocalTime - currGMT;
// cout << "Using " << local_offset << " as local time offset Timezone is "
// << zonename << endl;
void SGTime::updateLocal( double lon, double lat, const string& root ) {
// sanity checking
if ( lon < -SGD_PI || lon > SGD_PI ) {
// not within -180 ... 180
lon = 0.0;
}
if ( lat < -SGD_PI * 0.5 || lat > SGD_PI * 0.5 ) {
// not within -90 ... 90
lat = 0.0;
}
if ( lon != lon ) {
// only true if lon == nan
SG_LOG( SG_EVENT, SG_ALERT, " Detected lon == nan, resetting to 0.0" );
lon = 0.0;
}
if ( lat != lat ) {
// only true if lat == nan
SG_LOG( SG_EVENT, SG_ALERT, " Detected lat == nan, resetting to 0.0" );
lat = 0.0;
}
time_t currGMT;
time_t aircraftLocalTime;
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
GeoCoord* nearestTz = tzContainer->getNearest(location);
SGPath zone( root );
zone.append ( nearestTz->getDescription() );
if ( zonename ) {
char *ptr = zonename;
zonename = NULL;
delete ptr;
}
zonename = strdup( zone.c_str() );
//Avoid troubles when zone.tab hasn't got the right line endings
if (zonename[strlen(zonename)-1] == '\r')
{
zonename[strlen(zonename)-1]=0;
zone.set( zonename );
}
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zone.c_str())) );
local_offset = aircraftLocalTime - currGMT;
// cout << "Using " << local_offset << " as local time offset Timezone is "
// << zonename << endl;
}
@@ -327,6 +372,51 @@ double sgTimeCalcMJD(int mn, double dy, int yr) {
}
// return the current modified Julian date (number of days elapsed
// since 1900 jan 0.5), mjd.
double sgTimeCurrentMJD( time_t ct, long int warp ) {
#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
struct tm *gmt = &m_gmt;
#else
struct tm *gmt;
#endif
// get current Unix calendar time (in seconds)
// warp += warp_delta;
time_t cur_time;
if ( ct ) {
cur_time = ct + warp;
} else {
cur_time = time(NULL) + warp;
}
SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
// get GMT break down for current time
#if defined(_MSC_VER) || defined(__MINGW32__)
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
#else
gmt = gmtime(&cur_time);
#endif
SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
<< gmt->tm_sec );
// calculate modified Julian date
// t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday,
// (int)(t->gmt->tm_year + 1900));
double mjd = sgTimeCalcMJD( (int)(gmt->tm_mon+1), (double)gmt->tm_mday,
(int)(gmt->tm_year + 1900) );
return mjd;
}
// given an mjd, calculate greenwich mean sidereal time, gst
double sgTimeCalcGST( double mjd ) {
double gst;
+24 -7
View File
@@ -78,7 +78,7 @@ private:
time_t cur_time;
// Break down of equivalent GMT time
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
struct tm m_gmt; // copy of system gmtime(&time_t) structure
#else
struct tm *gmt;
@@ -122,8 +122,10 @@ public:
* 0).
* @param lon current longitude
* @param lat current latitude
* @param root root path point to data file location (timezone, etc.) */
SGTime( double lon, double lat, const string& root );
* @param root root path point to data file location (timezone, etc.)
* @param init_time provide an initialization time, 0 means use
current clock time */
SGTime( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
/**
* Create an instance given a data file path.
@@ -134,6 +136,9 @@ public:
/** Destructor */
~SGTime();
/** init common constructor code */
void init( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
/**
* Update the time related variables.
* The update() method requires you to pass in your position and
@@ -143,9 +148,11 @@ public:
* every frame.
* @param lon current longitude
* @param lat current latitude
* @param ct specify a unix time, otherwise specify 0 to use current
clock time
* @param warp an optional time offset specified in seconds. This
* allows us to advance or rewind "time" if we choose to. */
void update( double lon, double lat, long int warp = 0 );
void update( double lon, double lat, time_t ct /* = 0 */, long int warp /* = 0 */ );
/**
* Given lon/lat, update timezone information and local_offset
@@ -166,7 +173,7 @@ public:
inline char* get_zonename() const { return zonename; }
/** @return GMT in a "brokent down" tm structure */
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW32__)
inline struct tm* getGmt()const { return (struct tm *)&m_gmt; };
#else
inline struct tm* getGmt()const { return gmt; };
@@ -231,12 +238,22 @@ inline time_t sgTimeGetGMT(struct tm* the_time) {
* @return modified julian date */
double sgTimeCalcMJD(int mn, double dy, int yr);
/**
* \relates SGTime
* Given an optional offset from current time calculate the current
* modified julian date.
* @param ct specify a unix time, otherwise specify 0 to use current
clock time
* @param warp number of seconds to offset from current time (0 if no offset)
* @return current modified Julian date (number of days elapsed
* since 1900 jan 0.5), mjd. */
double sgTimeCurrentMJD( time_t ct /* = 0 */, long int warp /* = 0 */ );
/**
* \relates SGTime
* Given an mjd, calculate greenwich mean sidereal time, gst
* @param mjd modified julian date
* @return greenwich mean sidereal time (gst)
*/
* @return greenwich mean sidereal time (gst) */
double sgTimeCalcGST( double mjd );
/**
+4 -1
View File
@@ -102,7 +102,10 @@ public:
inline long get_usec() const { return usec; }
};
inline SGTimeStamp::SGTimeStamp() {
inline SGTimeStamp::SGTimeStamp() :
seconds(0),
usec(0)
{
}
inline SGTimeStamp::SGTimeStamp( const long s, const long u ) {
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+4
View File
@@ -6,4 +6,8 @@ include_HEADERS = xgl.h
libsgxgl_a_SOURCES = xgl.c xglUtils.c
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+1 -1
View File
@@ -4,7 +4,7 @@
#include <string.h>
#if !defined( WIN32 )
# if !defined( HAVE_STL_SGI_PORT ) && !defined( __MWERKS__ )
# if !defined( HAVE_STL_SGI_PORT ) && !defined( __MWERKS__ ) && !defined( __APPLE__ )
// Avoid malloc with STLport and MSL
# include <malloc.h>
# endif
+3
View File
@@ -0,0 +1,3 @@
.deps
Makefile
Makefile.in
+6 -6
View File
@@ -1,8 +1,4 @@
if HAVE_ZLIB
ZLIB_INCL =
else
XLIB_INCL = -I$(top_srcdir)/src/zlib
endif
includedir = @includedir@/xml
lib_LIBRARIES = libsgxml.a
@@ -22,4 +18,8 @@ libsgxml_a_SOURCES = \
xmltok.h xmltok.c \
xmltok_impl.h
INCLUDES += -I$(top_srcdir) $(ZLIB_INCL)
if OLD_AUTOMAKE
INCLUDES += -I$(top_srcdir)
else
INCLUDES = -I$(top_srcdir)
endif
+57 -18
View File
@@ -7,6 +7,13 @@
#include "easyxml.hxx"
#include "xmlparse.h"
#include STL_FSTREAM
#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
SG_USING_STD(ifstream);
#endif
////////////////////////////////////////////////////////////////////////
// Implementation of XMLAttributes.
@@ -162,7 +169,7 @@ ExpatAtts::getValue (int i) const
// Static callback functions for Expat.
////////////////////////////////////////////////////////////////////////
#define VISITOR (*((XMLVisitor*)userData))
#define VISITOR (*((XMLVisitor *)userData))
static void
start_element (void * userData, const char * name, const char ** atts)
@@ -198,11 +205,9 @@ processing_instruction (void * userData,
// Implementation of XMLReader.
////////////////////////////////////////////////////////////////////////
bool
readXML (istream &input, XMLVisitor &visitor)
void
readXML (istream &input, XMLVisitor &visitor, const string &path)
{
bool retval = true;
XML_Parser parser = XML_ParserCreate(0);
XML_SetUserData(parser, &visitor);
XML_SetElementHandler(parser, start_element, end_element);
@@ -214,26 +219,60 @@ readXML (istream &input, XMLVisitor &visitor)
char buf[16384];
while (!input.eof()) {
input.read(buf,16384);
// TODO: deal with bad stream.
if (!XML_Parse(parser, buf, input.gcount(), false)) {
visitor.error(XML_ErrorString(XML_GetErrorCode(parser)),
XML_GetCurrentColumnNumber(parser),
XML_GetCurrentLineNumber(parser));
retval = false;
// FIXME: get proper error string from system
if (!input.good()) {
XML_ParserFree(parser);
throw sg_io_exception("Problem reading file",
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
}
input.read(buf,16384);
if (!XML_Parse(parser, buf, input.gcount(), false)) {
XML_ParserFree(parser);
throw sg_io_exception(XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
}
}
// Verify end of document.
if (!XML_Parse(parser, buf, 0, true))
retval = false;
if (retval)
visitor.endXML();
if (!XML_Parse(parser, buf, 0, true)) {
XML_ParserFree(parser);
throw sg_io_exception(XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
}
XML_ParserFree(parser);
}
return retval;
void
readXML (const string &path, XMLVisitor &visitor)
{
ifstream input(path.c_str());
if (input.good()) {
try {
readXML(input, visitor, path);
} catch (sg_io_exception &e) {
input.close();
throw e;
} catch (sg_throwable &t) {
input.close();
throw t;
}
} else {
throw sg_io_exception("Failed to open file", sg_location(path),
"SimGear XML Parser");
}
input.close();
}
// end of easyxml.cxx
+34 -22
View File
@@ -10,6 +10,8 @@
#include <simgear/compiler.h>
#include <simgear/misc/exception.hxx>
#include STL_IOSTREAM
#include STL_STRING
#include <vector>
@@ -240,6 +242,12 @@ class XMLVisitor
{
public:
/**
* Virtual destructor.
*/
virtual ~XMLVisitor () {}
/**
* Callback for the start of an XML document.
*
@@ -349,25 +357,6 @@ public:
* the warning.
*/
virtual void warning (const char * message, int line, int column) {}
/**
* Callback for a fatal XML parsing error.
*
* The XML parser will use this method to report any fatal errors
* during parsing. Once the first error callback is received,
* normal processing will stop, though additional errors may be
* reported. The application should take any appropriate
* error-handling procedures when it receives this callback, and
* should not attempt to use any of the data found in the XML
* document.
*
* @param message The error message from the parser.
* @param line The number of the line that generated the error.
* @param column The character position in the line that generated
* the error.
*/
virtual void error (const char * message, int line, int column) = 0;
};
@@ -385,11 +374,34 @@ public:
* @param input The byte input stream containing the XML document.
* @param visitor An object that contains callbacks for XML parsing
* events.
* @return true if the parse succeeded, false if there was a fatal
* error.
* @param path A string describing the original path of the resource.
* @exception Throws sg_io_exception or sg_xml_exception if there
* is a problem reading the file.
* @see XMLVisitor
*/
extern bool readXML (istream &input, XMLVisitor &visitor);
extern void readXML (istream &input, XMLVisitor &visitor,
const string &path="");
/**
* @relates XMLVisitor
* Read an XML document.
*
* This function reads an XML document from the input stream provided,
* and invokes the callback methods in the visitor object to pass the
* parsing events back to the application. When this function
* returns, the parser will have reported all of the data in the XML
* document to the application through the visitor callback methods,
* and XML processing will be complete.
*
* @param path The file name of the XML resource.
* @param visitor An object that contains callbacks for XML parsing
* events.
* @exception Throws sg_io_exception or sg_xml_exception if there
* is a problem reading the file.
* @see XMLVisitor
*/
extern void readXML (const string &path, XMLVisitor &visitor);
#endif // __EASYXML_HXX
BIN
View File
Binary file not shown.