pax_global_header00006660000000000000000000000064133406477520014525gustar00rootroot0000000000000052 comment=189b212dce1e5e723a19f8dd8c16c1c4df5b485d lightspeed-1.2a.debian.1/000077500000000000000000000000001334064775200152405ustar00rootroot00000000000000lightspeed-1.2a.debian.1/AUTHORS000066400000000000000000000000471334064775200163110ustar00rootroot00000000000000Daniel Richard G. lightspeed-1.2a.debian.1/COPYING000066400000000000000000000634741334064775200163110ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! lightspeed-1.2a.debian.1/ChangeLog000066400000000000000000000050471334064775200170200ustar00rootroot000000000000002006-05-07 gettextize * configure.in (AC_OUTPUT): Add po/Makefile.in. 2006-05-07 gettextize * configure.in (AC_OUTPUT): Add intl/Makefile. 2006-05-07 gettextize * Makefile.am (SUBDIRS): Remove intl. (EXTRA_DIST): Add config/config.rpath, config/mkinstalldirs. 2006-05-07 gettextize * Makefile.am (SUBDIRS): Remove intl. (ACLOCAL_AMFLAGS): New variable. (EXTRA_DIST): Add config/config.rpath, m4/ChangeLog. * configure.in (AC_OUTPUT): Remove intl/Makefile. 1.3 (?? July 2001) ------------------ * Project moved to SourceForge. * Updated documentation (e-mail addresses, links, writing style, etc.) 1.2 (24 April 1999) ------------------- * Added keybindings for most operations. Those GtkAccelerator functions really need better documentation. * Upgraded profiler to calculate framerate using a variable-length frametime buffer. The fps readout shouldn't fluctuate so wildly anymore on super-fast hardware. * Small fix to velocity_entry( ) so that commas are also added when velocity units are changed. * Small changes to set_entry_width( ) and some GtkEntry handling. * Updated gtkgl interface to use the newer API. (Note: compat.h maintains older GtkGLArea compatibility) * More configure script fixes. 1.1 (14 April 1999) ------------------- * Added a vertical slider for velocity control. Thanks go to Stijn Buys for [being the first to send in] this excellent suggestion! * Added kilometers/hour velocity units, and removed kilometers/second (km/s was kind of redundant anyway) * Moved all language-specific program strings into lstrings.c. Light Speed! is ready to go international! (Please contact me if you wish to do translations, I will greatly appreciate it) * TIFF exporter fixed. (no segfaults! yay!) * Added heuristic for calculating camera distance when specifying its position with xyz/angles. This needs field testing; any opinions? * Remade title.xpm (for the About dialog), toning down the glow a bit. (you see, I have a *really dark* monitor :-) * Modified break_transition( ) and related code in transition_engine( ) to work more efficiently (was causing problems with the velocity slider) * Exported time-string generation code from infodisp.c to misc.c. This whole bit is all in time_string( ) now. * configure script fixes. Test for libpng now leaves off the -lgtkgl; a few other rough edges filed down too. Should I add a prefix option for libpng, libtiff, et. al.? 1.0 (4 April 1999) ------------------ * Initial release. lightspeed-1.2a.debian.1/MATH000066400000000000000000000236251334064775200157240ustar00rootroot00000000000000The Mathematics behind Light Speed! =================================== This file describes the mathematical framework of the relativistic transforms exhibited in the Light Speed! simulator. In particular, the formulae and some details of their implementation are given below. ==== THE LORENTZ CONTRACTION ==== A moving object will appear shorter than it does at rest, due to an oblique alignment in four-dimensional space-time imparted to it by its motion. Specifically, the object will appear compressed along its axis of travel, scaled down by a factor which is exactly the Lorentz factor, also known as gamma: 1 gamma = --------------------- sqrt( 1 - (v/c)^2 ) where v is the velocity of the object, and c is the speed of light. For most everyday values of v, gamma is practically 1. As v approaches the speed of light, however, gamma grows without bound. Assuming that a vehicle's length L is parallel with its axis of travel, its observed length L' at any velocity (below that of light!) is: L' = L / gamma This predicts that an object travelling at the speed of light will appear to have no length (and hence no volume), while retaining its frontal cross-sectional area. If the object were a rocket, for example, it would appear to have become a flying disc. ==== THE DOPPLER RED/BLUE SHIFT and THE HEADLIGHT EFFECT ==== These are transformations upon the color hue and intensity attributes of an object, respectively. Either is based upon the motion of a light source (whether by emission or reflection) with respect to a receiver or observer of its light. If the source is approaching the observer, it will appear blue-shifted (its light higher in frequency) and brighter. If it is moving away, it will appear red-shifted (lower in frequency) and darker. In Light Speed!, there are two instances where these effects are applied: 1. Ambient light striking (illuminating) the object 2. The object reflecting light toward the observer The first takes into account how the object is illuminated. If the object were a space vessel, travelling at relativistic speed, an onboard observer will notice that (for example) stars and planetary bodies ahead of the ship appear brighter and blue-shifted. Because of this, the nose of the ship will be bathed in a relatively bright, bluish light. The light it reflects, then, will also have this character. The second instance handles the color effects as naturally expected from the motion of the object, with respect to the camera. Both effects depend on the relative motion between a source point and a receiving point, one in motion and the other at rest. As such, the formula for either transform contains the term: v --- * cos a c in which: v = forward velocity of the moving point c = speed of light a = (alpha) angle subtended between the motion vector of the moving point and the vector connecting the two points (moving-to-stationary) This value is nothing more than the rate (as a factor of c, between 1.0 and -1.0) at which the two points are approaching or moving away from one another. With that pointed out, the formula describing the Doppler effect is as follows: n' 1 + (v/c)*cos a --- = --------------------- n sqrt( 1 - (v/c)^2 ) The n'/n (nu-prime over nu) is a frequency ratio. Multiplying the frequency of the source lighting by this value will give the frequency as observed by the receiver. (Also, note that the denominator is the reciprocal of the gamma factor. This accounts for the effect of time dilation upon the frequency, which to some extent always increases it). The Doppler shift routines used in Light Speed! were written by Antony Searle, and actually work with the reciprocal of this value, n/n', which is the _wavelength_ ratio between the two states of light. These routines are not trivial, as they accept an RGB-triplet color as input, and produce an RGB-triplet as output. The RGB representation must be converted to a rough spectrum to make the wavelength ratio meaningful, and then sampled into RGB again as this format is required by the graphics system. The resulting colors are only an approximation, with some assumptions made as to the character of light involved, but Mr. Searle's implementation has the important advantage of computational simplicity-- and thereby speed. The formula describing the headlight effect is similar: I' (1 + (v/c)*cos a)^2 --- = --------------------- I sqrt( 1 - (v/c)^2 ) (The only difference to the previous formula is in the squaring of the numerator) I'/I is an intensity ratio, again multiplying that of the source light to produce what is observed by the receiver. RGB colors can be directly manipulated by this value (i.e. multiplying each color component with it), although better intensity transforms may exist. (Some of the intensity-adjustment routines of quality paint programs come to mind). ==== OPTICAL ABERRATION ==== This results from the phenomena of delayed observation; i.e. we do not see things, but the light reflected from things. As light has a finite, albeit very high speed, there is a corresponding delay associated with our observation of events/things. In Light Speed!, the camera observes a moving object, which is comprised of various vertex points (interconnected in some arbitrary geometrical manner, be it triangles, quads, etc.) The position of each of these is known within a fiducial time frame, at the moment that the shutter is snapped. However, the camera perceives by way of light, whose propagation is not instantaneous. Thus it is necessary to translate each vertex of the object backward (w.r.t. the direction of travel) to an earlier position, specifically the position at which the camera is expected to observe the vertex-- at a slightly earlier point in time. There is one condition that this earlier position must satisfy: The time necessary for the vertex to travel from the earlier position to its position in the fiducial frame _must_exactly_equal_ the time necessary for light to travel from the earlier position of the vertex to the observer. (My apologies; this is very difficult to explain in a straightforward manner. Let me try a different approach...) If the object of concern consists of a single vertex, the problem may be illustrated geometrically as follows: A * |\ | \ | \ | \ | \ | \ B * \ | \ | \ | \ | \ |__ \ | | \ C *-------------* O Fig. 1 The object is traveling along the vector AC. At time T=-t (i.e. a short moment before T=0) it is at position A. At this moment, a photon strikes the object and reflects off its surface, beginning travel along the vector AO toward the observer O. The object continues along path AC. At time T=0, the object is at B, and the photon reaches O. The observer, seeing the photon, observes an image of the object at position A. (and, incidentally, has yet to see anything at position B) Whereas the image of the object is at A, the object itself is really at B; with the above thought experiment we have derived where the object will be (B) from the position of its image (A). Implementing a simulator, however, entails finding the image position A from the actual position B, taking into account the velocity v of the object and position O of the observer. The unknown length AB-- the image-to-object delta-- is what has to be calculated. This means calculating t, as AB is simply v*t. (Similarly, AO is c*t). In the geometrical sense, it is finding lengths AB and AO in the ratio v/c, scaled by some factor t which will make ACO a right triangle. For the sake of argument, let us say AC is the x-axis, with B being the origin. (This is close to how it is implemented in Light Speed!) Let: x = x-position of the observer = distance BC; y = y-position of the observer = distance CO; v = velocity of the moving object; c = speed of light. We start off with the right-triangle relationship (a.k.a. the Pythagorean Theorem), stating the square of the hypotenuse is equal to...: (c*t)^2 = (v*t + x)^2 + y^2 and then rearrange it into a quadratic equation of t: (v^2 - c^2)*t^2 + (2*x*v)*t + (x^2 + y^2) = 0 which yields the solution: -2*x*v - sqrt( (2*x*v)^2 - 4*(v^2 - c^2)*(x^2 + y^2) ) t = -------------------------------------------------------- 2*(v^2 - c^2) (The sign on the radical must be negative to give a positive value for t. Note that the denominator is always negative, as v lightspeed-1.2a.debian.1/Makefile.am000066400000000000000000000003711334064775200172750ustar00rootroot00000000000000# Makefile.am SUBDIRS= po src CONFIG_FILES=\ config/install-sh \ config/missing \ config/mkinstalldirs EXTRA_DIST=config/config.rpath config/mkinstalldirs m4/ChangeLog \ MATH gettext.h lightspeed.spec $(CONFIG_FILES) ACLOCAL_AMFLAGS=-I m4 lightspeed-1.2a.debian.1/NEWS000066400000000000000000000000251334064775200157340ustar00rootroot00000000000000http://slashdot.org/ lightspeed-1.2a.debian.1/README000066400000000000000000000067731334064775200161350ustar00rootroot00000000000000==== Light Speed! ==== DESCRIPTION This is a simulator designed to illustrate relativistic effects on the appearance of objects moving at ultra-high velocities. It simulates a geometrical lattice object traveling at a given speed in a straight line through space. Specifically, the object moves along the x-axis of this space, in the positive-x direction; at time t=0, the object is precisely centered on the origin. The simulator displays, in essence, a still image of the vicinity of the origin snapped at the exact moment that the object is *seen* to be at the origin; i.e. the moment that light reflected off the object, when the object was exactly at the origin (at t=0), eventually reaches the camera. This moment will usually be a few billionths of a second after t=0, accounting for the time needed for the light to traverse this distance. (The camera's info display will explicitly indicate the time of the snapshot, to 0.001 microsecond accuracy). Light Speed! will allow you to move around and see interactively how the object appears to change with observer position. At low velocities, this isn't much the case, but up in the several-million-meters-per-second range, the object as viewed from one angle to another can vary significantly. To get started, drag the slider at the right of the window upward. Relativistic effects will immediately become noticeable. Click and drag in the graphics window to move around. CONTROLS Most interactive control is performed with the mouse. By holding down a particular button, and dragging the pointer around, various camera motions can be obtained: Left button: Revolve camera around view target Shift key + Left button: Revolve view target around camera Middle button: Translate camera left, right, up or down Right button: Dolly in or out The first and last motions are generally the most useful. Should the camera become difficult to control at any point, it may be re-initialized by selecting Camera -> Reset View. THEORY Light Speed! takes into account the following consequences of special relativity: 1. Lorentz contraction (fast objects appear shorter) 2. Doppler red/blue shift (the Doppler effect on light/color) 3. Headlight effect (redistribution of reflected light) 4. Optical aberration (warping due to the finite speed of light) A lengthier treatment of the above phenomena, complete with the formulae used (really, they're not that bad!) may be found in the file MATH. LIMITATIONS The only major weakness of this simulator is color. The Doppler shifts produced are only approximations, and in certain cases may be wildly inaccurate. If color fidelity is a must, Antony Searle's BACKLIGHT raytracer program may be a better choice. (See the Acknowledgements section below for details). REQUIREMENTS Light Speed! requires the X Window System with OpenGL or Mesa3D support, as well as the GTK+ libraries to function. Compilation will additionally need Janne Lof's GtkGLArea widget. See the file INSTALL for details. ACKNOWLEDGEMENTS I would like to thank Antony Searle, of the Australian National University, for allowing me to make use of the Doppler-shift code from his well-received relativistic raytracer, BACKLIGHT. This program illustrates relativistic effects via a four-dimensional raytracing engine, and I highly recommend it in case greater scientific rigor or creative flexibility is desired. You may find it at: http://www.anu.edu.au/Physics/Searle/ ========================================= Daniel Richard G. // lightspeed-1.2a.debian.1/TODO000066400000000000000000000015441334064775200157340ustar00rootroot00000000000000BUG:importobjs.c: triangulate_polygon( ) does not work properly. Some LightWave models may get a wee bit mangled... BUG:menu_cbs.c: highlight_entry( ) does not work after a set_entry_text( ) (appears to be a bug in GTK+, I've sent in a report) BUG:menu_cbs.c: Dialogs do not hide properly before viewport is blanked (e.g. when generating a lattice, or loading a file. The dialog either leaves a lovely grey rectangle on the viewport, or doesn't hide at all until too late :P ) Not sure how to fix this. BUG:menu_cbs.c: Velocity input entry should have automagically inserted commas. gtk_entry_set_position( ) isn't cooperating, however :( TODO: Anyone want to translate lstrings.c? E-mail me if so, I will appreciate it greatly! TODO: Note in docs that Lorentz contraction / optical aberration toggles have no effect on exported SRS file lightspeed-1.2a.debian.1/configure.ac000066400000000000000000000123761334064775200175370ustar00rootroot00000000000000# configure.ac # # Process this file with autoconf to produce a configure script. # AC_PREREQ([2.67]) AC_INIT([lightspeed], [1.2b.debian.1], [Daniel Richard G. ]) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_MACRO_DIR([m4]) AC_USE_SYSTEM_EXTENSIONS AM_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE # Check for programs # AM_SANITY_CHECK AC_PROG_INSTALL AC_PROG_CC AC_PROG_CPP AC_PROG_CXX # Check for header files # AC_HEADER_STDC AC_CHECK_HEADERS([getopt.h malloc.h sys/time.h]) # Check for typedefs, structures, and compiler characteristics. # AC_C_CONST AC_TYPE_SIZE_T AC_HEADER_TIME # Check for library functions # AC_CHECK_FUNCS([getopt_long gettimeofday strcspn strdup strtod]) # Checks for GTK+ libraries. # AC_ARG_WITH(gtk, [ --with-gtk=1,2 use GTK 1 or 2 (auto)]) if test "x$with_gtk" != "x1" -a "$gtkmorph_gtk" = "" ; then pkg_modules="gtk+-2.0 >= 2.0.0" PKG_CHECK_MODULES(GTK, [$pkg_modules], version_of_gtk=gtk2, [if test "x$with_gtk" = "x2" ; then AC_MSG_ERROR([ libgtk 2 is not available ]) exit 1 fi;]) else AC_MSG_NOTICE([ Testing for GTK 2 skipped]) fi if test "x$with_gtk" != "x2" -a "$version_of_gtk" = "" ; then AC_MSG_ERROR([Cannot find proper GTK+ version]) dnl dnl Note: We are not using GTK1 anymore dnl dnl AM_PATH_GTK(1.0.1, , [AC_MSG_ERROR([Cannot find proper GTK+ version])]) dnl version_of_gtk=gtk1 dnl AC_DEFINE(HAVE_GTK1,1,"Define if compiled with GTK 1 and GtkGLArea ") dnl fi AM_CONDITIONAL(COND_GTK1, test "$version_of_gtk" = "gtk1" ) # # Check for OpenGL libraries # AC_ARG_WITH(GL-prefix, [ --with-GL-prefix=PFX Prefix where OpenGL is installed (optional)]) GL_CFLAGS="" GL_LDOPTS="" if test -n "$with_GL_prefix" ; then GL_CFLAGS="-I$with_GL_prefix/include" GL_LDOPTS="-L$with_GL_prefix/lib" fi AC_CHECK_LIB(GL, glBegin, , AC_MSG_ERROR([OpenGL library not found.]), $GL_LDOPTS) GL_LIBS="$GL_LDOPTS -lGL" # # Check for GtkGLArea widget # or for gtkglext-1.0 # AC_ARG_WITH(ftgl, [ --with-ftgl support for TrueType fonts]) if test "x$with_ftgl" = x -o "x$with_ftgl" = xyes ; then if test "$CXX" ; then PKG_CHECK_MODULES( FTGL, ["ftgl"], [AC_DEFINE([HAVE_LIBFTGL], [1], ["Define if FTGL support for TrueType font is available"]) with_ftgl=yes ] , [AC_MSG_WARN([ftgl is not available : support for TrueType fonts is unavailable]) with_ftgl=no ]) else AC_MSG_WARN([ ftgl needs a C++ compiler ]) with_ftgl=no fi if test "x$with_ftgl" = xyes ; then dnl Mennucc: TrueType fallback font font=${datadir}/fonts/truetype/freefont/FreeSans.ttf PKG_CHECK_MODULES(FC, fontconfig >= 2.2.3, [ AC_DEFINE(HAVE_FC,1,"Define if fontconfig library is available") ] , [if test ! -r $font ; then AC_MSG_WARN( TrueType font $font is not available , please install it from http://savannah.nongnu.org/download/freefont/) fi] ) fi else with_ftgl=no fi AM_CONDITIONAL(COND_FTGL, test "x$with_ftgl" != xno ) if test "$version_of_gtk" = "gtk2" ; then pkg_modules="gtkglext-1.0 >= 0.7.0" PKG_CHECK_MODULES(GTKGL, [$pkg_modules],[ : ] ,[ AC_MSG_ERROR([ gtkglext is not available ]) exit 1 ] ) else AC_ARG_WITH(gtkgl-prefix, [ --with-gtkgl-prefix=PFX Prefix where GtkGLArea is installed (optional)]) GTKGL_CFLAGS="" GTKGL_LDOPTS="" if test -n "$with_gtkgl_prefix" ; then GTKGL_CFLAGS="-I$with_gtkgl_prefix/include" GTKGL_LDOPTS="-L$with_gtkgl_prefix/lib" fi AC_CHECK_LIB(gtkgl, gtk_gl_area_new, , AC_MSG_ERROR([Cannot find GtkGLArea library.]), $GTKGL_LDOPTS $GTK_LIBS $GL_LIBS) GTKGL_LIBS="$GTKGL_LDOPTS -lgtkgl" fi # # Test for libpng # if test -z "$LIBPNG_LIB"; then AC_CHECK_LIB(png, png_read_info, [AC_CHECK_HEADER(png.h, png_ok=yes, png_ok=no) ],[ AC_MSG_WARN([*** PNG exporter cannot be built (PNG library not found) ***]) ],[ -lz -lm ]) if test "$png_ok" = yes; then AC_MSG_CHECKING([for png_structp in png.h]) AC_TRY_COMPILE([#include ], [png_structp pp; png_infop info; png_colorp cmap; png_create_read_struct;], png_ok=yes, png_ok=no) AC_MSG_RESULT($png_ok) if test "$png_ok" = yes; then PNG='png'; LIBPNG_LIB='-lpng -lz' else AC_MSG_WARN(*** PNG exporter cannot be built (PNG library is too old) ***) fi else AC_MSG_WARN(*** PNG exporter cannot be built (PNG header file not found) ***) fi fi # # Test for libtiff # if test -z "$LIBTIFF_LIB"; then AC_CHECK_LIB(tiff, TIFFReadScanline, [AC_CHECK_HEADER(tiffio.h, [TIFF='tiff'; LIBTIFF_LIB='-ltiff'], )], [AC_MSG_WARN([*** TIFF exporter cannot be built (TIFF header files not found) ***])] , -ltiff) fi if test "$PNG" = png ; then AC_DEFINE(HAVE_LIBPNG,1,"Define if libpng is available") fi if test "$TIFF" = tiff ; then AC_DEFINE(HAVE_LIBTIFF,1,"Define if libtiff is available") fi IMG_LIBS="$LIBPNG_LIB $LIBTIFF_LIB" # # That's a wrap! # AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) AC_SUBST(GTKGL_CFLAGS) AC_SUBST(GTKGL_LIBS) AC_SUBST(IMG_LIBS) #this is evil #CFLAGS="$CFLAGS $GTK_CFLAGS $GL_CFLAGS $GTKGL_CFLAGS" #LIBS="$LIBS $GTKGL_LIBS $GTK_LIBS $GL_LIBS $IMG_LIBS" AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.18]) AC_OUTPUT(Makefile src/Makefile intl/Makefile po/Makefile.in) # end configure.in lightspeed-1.2a.debian.1/gettext.h000066400000000000000000000065701334064775200171050ustar00rootroot00000000000000/* Convenience header for conditional use of GNU . Copyright (C) 1995-1998, 2000-2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LIBGETTEXT_H #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ #if ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include #else /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which chokes if dcgettext is defined as a macro. So include it now, to make later inclusions of a NOP. We don't include as well because people using "gettext.h" will not include , and also including would fail on SunOS 4, whereas is OK. */ #if defined(__sun) # include #endif /* Many header files from the libstdc++ coming with g++ 3.3 or newer include , which chokes if dcgettext is defined as a macro. So include it now, to make later inclusions of a NOP. */ #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) # include # if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H # include # endif #endif /* Disabled NLS. The casts to 'const char *' serve the purpose of producing warnings for invalid uses of the value returned from these functions. On pre-ANSI systems without 'const', the config.h file is supposed to contain "#define const". */ # define gettext(Msgid) ((const char *) (Msgid)) # define dgettext(Domainname, Msgid) ((const char *) (Msgid)) # define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) # define ngettext(Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dngettext(Domainname, Msgid1, Msgid2, N) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) # define textdomain(Domainname) ((const char *) (Domainname)) # define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) # define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) #endif /* A pseudo function call that serves as a marker for the automated extraction of messages, but does not call gettext(). The run-time translation is done at a different place in the code. The argument, String, should be a literal string. Concatenated strings and other string expressions won't work. The macro's expansion is not parenthesized, so that it is suitable as initializer for static 'char[]' or 'const char[]' variables. */ #define gettext_noop(String) String #endif /* _LIBGETTEXT_H */ lightspeed-1.2a.debian.1/intl/000077500000000000000000000000001334064775200162065ustar00rootroot00000000000000lightspeed-1.2a.debian.1/intl/ChangeLog000066400000000000000000000001111334064775200177510ustar00rootroot000000000000002005-05-23 GNU * Version 0.14.5 released. lightspeed-1.2a.debian.1/intl/Makefile.in000066400000000000000000000402551334064775200202610ustar00rootroot00000000000000# Makefile for directory with message catalog handling library of GNU gettext # Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. PACKAGE = @PACKAGE@ VERSION = @VERSION@ SHELL = /bin/sh srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = .. VPATH = $(srcdir) prefix = @prefix@ exec_prefix = @exec_prefix@ transform = @program_transform_name@ libdir = @libdir@ includedir = @includedir@ datadir = @datadir@ localedir = $(datadir)/locale gettextsrcdir = $(datadir)/gettext/intl aliaspath = $(localedir) subdir = intl INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ MKINSTALLDIRS = @MKINSTALLDIRS@ mkinstalldirs = $(SHELL) $(MKINSTALLDIRS) l = @INTL_LIBTOOL_SUFFIX_PREFIX@ AR = ar CC = @CC@ LIBTOOL = @LIBTOOL@ RANLIB = @RANLIB@ YACC = @INTLBISON@ -y -d YFLAGS = --name-prefix=__gettext DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \ -DLIBDIR=\"$(libdir)\" -DIN_LIBINTL \ -DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \ -Dset_relocation_prefix=libintl_set_relocation_prefix \ -Drelocate=libintl_relocate \ -DDEPENDS_ON_LIBICONV=1 @DEFS@ CPPFLAGS = @CPPFLAGS@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) HEADERS = \ gmo.h \ gettextP.h \ hash-string.h \ loadinfo.h \ plural-exp.h \ eval-plural.h \ localcharset.h \ relocatable.h \ xsize.h \ printf-args.h printf-args.c \ printf-parse.h wprintf-parse.h printf-parse.c \ vasnprintf.h vasnwprintf.h vasnprintf.c \ os2compat.h \ libgnuintl.h.in SOURCES = \ bindtextdom.c \ dcgettext.c \ dgettext.c \ gettext.c \ finddomain.c \ loadmsgcat.c \ localealias.c \ textdomain.c \ l10nflist.c \ explodename.c \ dcigettext.c \ dcngettext.c \ dngettext.c \ ngettext.c \ plural.y \ plural-exp.c \ localcharset.c \ relocatable.c \ langprefs.c \ localename.c \ log.c \ printf.c \ osdep.c \ os2compat.c \ intl-compat.c OBJECTS = \ bindtextdom.$lo \ dcgettext.$lo \ dgettext.$lo \ gettext.$lo \ finddomain.$lo \ loadmsgcat.$lo \ localealias.$lo \ textdomain.$lo \ l10nflist.$lo \ explodename.$lo \ dcigettext.$lo \ dcngettext.$lo \ dngettext.$lo \ ngettext.$lo \ plural.$lo \ plural-exp.$lo \ localcharset.$lo \ relocatable.$lo \ langprefs.$lo \ localename.$lo \ log.$lo \ printf.$lo \ osdep.$lo \ intl-compat.$lo DISTFILES.common = Makefile.in \ config.charset locale.alias ref-add.sin ref-del.sin $(HEADERS) $(SOURCES) DISTFILES.generated = plural.c DISTFILES.normal = VERSION DISTFILES.gettext = COPYING.LIB-2.0 COPYING.LIB-2.1 libintl.glibc \ libgnuintl.h_vms Makefile.vms \ libgnuintl.h.msvc-static libgnuintl.h.msvc-shared README.woe32 Makefile.msvc DISTFILES.obsolete = xopen-msg.sed linux-msg.sed po2tbl.sed.in cat-compat.c \ COPYING.LIB-2 gettext.h libgettext.h plural-eval.c libgnuintl.h all: all-@USE_INCLUDED_LIBINTL@ all-yes: libintl.$la libintl.h charset.alias ref-add.sed ref-del.sed all-no: all-no-@BUILD_INCLUDED_LIBINTL@ all-no-yes: libgnuintl.$la all-no-no: libintl.a libgnuintl.a: $(OBJECTS) rm -f $@ $(AR) cru $@ $(OBJECTS) $(RANLIB) $@ libintl.la libgnuintl.la: $(OBJECTS) $(LIBTOOL) --mode=link \ $(CC) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS) $(LDFLAGS) -o $@ \ $(OBJECTS) @LTLIBICONV@ @INTL_MACOSX_LIBS@ $(LIBS) -lc \ -version-info $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) \ -rpath $(libdir) \ -no-undefined # Libtool's library version information for libintl. # Before making a gettext release, the gettext maintainer must change this # according to the libtool documentation, section "Library interface versions". # Maintainers of other packages that include the intl directory must *not* # change these values. LTV_CURRENT=7 LTV_REVISION=3 LTV_AGE=4 .SUFFIXES: .SUFFIXES: .c .y .o .lo .sin .sed .c.o: $(COMPILE) $< .y.c: $(YACC) $(YFLAGS) --output $@ $< rm -f $*.h bindtextdom.lo: $(srcdir)/bindtextdom.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/bindtextdom.c dcgettext.lo: $(srcdir)/dcgettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcgettext.c dgettext.lo: $(srcdir)/dgettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dgettext.c gettext.lo: $(srcdir)/gettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/gettext.c finddomain.lo: $(srcdir)/finddomain.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/finddomain.c loadmsgcat.lo: $(srcdir)/loadmsgcat.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/loadmsgcat.c localealias.lo: $(srcdir)/localealias.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localealias.c textdomain.lo: $(srcdir)/textdomain.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/textdomain.c l10nflist.lo: $(srcdir)/l10nflist.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/l10nflist.c explodename.lo: $(srcdir)/explodename.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/explodename.c dcigettext.lo: $(srcdir)/dcigettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcigettext.c dcngettext.lo: $(srcdir)/dcngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dcngettext.c dngettext.lo: $(srcdir)/dngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/dngettext.c ngettext.lo: $(srcdir)/ngettext.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/ngettext.c plural.lo: $(srcdir)/plural.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural.c plural-exp.lo: $(srcdir)/plural-exp.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural-exp.c localcharset.lo: $(srcdir)/localcharset.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localcharset.c relocatable.lo: $(srcdir)/relocatable.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/relocatable.c langprefs.lo: $(srcdir)/langprefs.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/langprefs.c localename.lo: $(srcdir)/localename.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localename.c log.lo: $(srcdir)/log.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/log.c printf.lo: $(srcdir)/printf.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/printf.c osdep.lo: $(srcdir)/osdep.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/osdep.c intl-compat.lo: $(srcdir)/intl-compat.c $(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/intl-compat.c ref-add.sed: $(srcdir)/ref-add.sin sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-add.sin > t-ref-add.sed mv t-ref-add.sed ref-add.sed ref-del.sed: $(srcdir)/ref-del.sin sed -e '/^#/d' -e 's/@''PACKAGE''@/@PACKAGE@/g' $(srcdir)/ref-del.sin > t-ref-del.sed mv t-ref-del.sed ref-del.sed INCLUDES = -I. -I$(srcdir) -I.. libgnuintl.h: $(srcdir)/libgnuintl.h.in sed -e 's,@''HAVE_POSIX_PRINTF''@,@HAVE_POSIX_PRINTF@,g' \ -e 's,@''HAVE_ASPRINTF''@,@HAVE_ASPRINTF@,g' \ -e 's,@''HAVE_SNPRINTF''@,@HAVE_SNPRINTF@,g' \ -e 's,@''HAVE_WPRINTF''@,@HAVE_WPRINTF@,g' \ < $(srcdir)/libgnuintl.h.in > libgnuintl.h libintl.h: libgnuintl.h cp libgnuintl.h libintl.h charset.alias: $(srcdir)/config.charset $(SHELL) $(srcdir)/config.charset '@host@' > t-$@ mv t-$@ $@ check: all # We must not install the libintl.h/libintl.a files if we are on a # system which has the GNU gettext() function in its C library or in a # separate library. # If you want to use the one which comes with this version of the # package, you have to use `configure --with-included-gettext'. install: install-exec install-data install-exec: all if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \ $(INSTALL_DATA) libintl.h $(DESTDIR)$(includedir)/libintl.h; \ $(LIBTOOL) --mode=install \ $(INSTALL_DATA) libintl.$la $(DESTDIR)$(libdir)/libintl.$la; \ if test "@RELOCATABLE@" = yes; then \ dependencies=`sed -n -e 's,^dependency_libs=\(.*\),\1,p' < $(DESTDIR)$(libdir)/libintl.la | sed -e "s,^',," -e "s,'\$$,,"`; \ if test -n "$$dependencies"; then \ rm -f $(DESTDIR)$(libdir)/libintl.la; \ fi; \ fi; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ $(mkinstalldirs) $(DESTDIR)$(libdir); \ $(LIBTOOL) --mode=install \ $(INSTALL_DATA) libgnuintl.$la $(DESTDIR)$(libdir)/libgnuintl.$la; \ rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \ $(INSTALL_DATA) $(DESTDIR)$(libdir)/libgnuintl.so $(DESTDIR)$(libdir)/preloadable_libintl.so; \ $(LIBTOOL) --mode=uninstall \ rm -f $(DESTDIR)$(libdir)/libgnuintl.$la; \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ test @GLIBC21@ != no || $(mkinstalldirs) $(DESTDIR)$(libdir); \ temp=$(DESTDIR)$(libdir)/t-charset.alias; \ dest=$(DESTDIR)$(libdir)/charset.alias; \ if test -f $(DESTDIR)$(libdir)/charset.alias; then \ orig=$(DESTDIR)$(libdir)/charset.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ else \ if test @GLIBC21@ = no; then \ orig=charset.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ fi; \ fi; \ $(mkinstalldirs) $(DESTDIR)$(localedir); \ test -f $(DESTDIR)$(localedir)/locale.alias \ && orig=$(DESTDIR)$(localedir)/locale.alias \ || orig=$(srcdir)/locale.alias; \ temp=$(DESTDIR)$(localedir)/t-locale.alias; \ dest=$(DESTDIR)$(localedir)/locale.alias; \ sed -f ref-add.sed $$orig > $$temp; \ $(INSTALL_DATA) $$temp $$dest; \ rm -f $$temp; \ else \ : ; \ fi install-data: all if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \ $(INSTALL_DATA) VERSION $(DESTDIR)$(gettextsrcdir)/VERSION; \ $(INSTALL_DATA) ChangeLog.inst $(DESTDIR)$(gettextsrcdir)/ChangeLog; \ dists="COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common)"; \ for file in $$dists; do \ $(INSTALL_DATA) $(srcdir)/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ chmod a+x $(DESTDIR)$(gettextsrcdir)/config.charset; \ dists="$(DISTFILES.generated)"; \ for file in $$dists; do \ if test -f $$file; then dir=.; else dir=$(srcdir); fi; \ $(INSTALL_DATA) $$dir/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ dists="$(DISTFILES.obsolete)"; \ for file in $$dists; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi install-strip: install installdirs: if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir); \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ $(mkinstalldirs) $(DESTDIR)$(libdir); \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ test @GLIBC21@ != no || $(mkinstalldirs) $(DESTDIR)$(libdir); \ $(mkinstalldirs) $(DESTDIR)$(localedir); \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \ else \ : ; \ fi # Define this as empty until I found a useful application. installcheck: uninstall: if { test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; } \ && test '@USE_INCLUDED_LIBINTL@' = yes; then \ rm -f $(DESTDIR)$(includedir)/libintl.h; \ $(LIBTOOL) --mode=uninstall \ rm -f $(DESTDIR)$(libdir)/libintl.$la; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools" \ && test '@USE_INCLUDED_LIBINTL@' = no \ && test @GLIBC2@ != no; then \ rm -f $(DESTDIR)$(libdir)/preloadable_libintl.so; \ else \ : ; \ fi if test '@USE_INCLUDED_LIBINTL@' = yes; then \ if test -f $(DESTDIR)$(libdir)/charset.alias; then \ temp=$(DESTDIR)$(libdir)/t-charset.alias; \ dest=$(DESTDIR)$(libdir)/charset.alias; \ sed -f ref-del.sed $$dest > $$temp; \ if grep '^# Packages using this file: $$' $$temp > /dev/null; then \ rm -f $$dest; \ else \ $(INSTALL_DATA) $$temp $$dest; \ fi; \ rm -f $$temp; \ fi; \ if test -f $(DESTDIR)$(localedir)/locale.alias; then \ temp=$(DESTDIR)$(localedir)/t-locale.alias; \ dest=$(DESTDIR)$(localedir)/locale.alias; \ sed -f ref-del.sed $$dest > $$temp; \ if grep '^# Packages using this file: $$' $$temp > /dev/null; then \ rm -f $$dest; \ else \ $(INSTALL_DATA) $$temp $$dest; \ fi; \ rm -f $$temp; \ fi; \ else \ : ; \ fi if test "$(PACKAGE)" = "gettext-tools"; then \ for file in VERSION ChangeLog COPYING.LIB-2.0 COPYING.LIB-2.1 $(DISTFILES.common) $(DISTFILES.generated); do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi info dvi ps pdf html: $(OBJECTS): ../config.h libgnuintl.h bindtextdom.$lo dcgettext.$lo dcigettext.$lo dcngettext.$lo dgettext.$lo dngettext.$lo finddomain.$lo gettext.$lo intl-compat.$lo loadmsgcat.$lo localealias.$lo ngettext.$lo textdomain.$lo: $(srcdir)/gettextP.h $(srcdir)/gmo.h $(srcdir)/loadinfo.h dcigettext.$lo loadmsgcat.$lo: $(srcdir)/hash-string.h explodename.$lo l10nflist.$lo: $(srcdir)/loadinfo.h dcigettext.$lo loadmsgcat.$lo plural.$lo plural-exp.$lo: $(srcdir)/plural-exp.h dcigettext.$lo: $(srcdir)/eval-plural.h localcharset.$lo: $(srcdir)/localcharset.h localealias.$lo localcharset.$lo relocatable.$lo: $(srcdir)/relocatable.h printf.$lo: $(srcdir)/printf-args.h $(srcdir)/printf-args.c $(srcdir)/printf-parse.h $(srcdir)/wprintf-parse.h $(srcdir)/xsize.h $(srcdir)/printf-parse.c $(srcdir)/vasnprintf.h $(srcdir)/vasnwprintf.h $(srcdir)/vasnprintf.c tags: TAGS TAGS: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && etags -o $$here/TAGS $(HEADERS) $(SOURCES) ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && ctags -o $$here/CTAGS $(HEADERS) $(SOURCES) id: ID ID: $(HEADERS) $(SOURCES) here=`pwd`; cd $(srcdir) && mkid -f$$here/ID $(HEADERS) $(SOURCES) mostlyclean: rm -f *.a *.la *.o *.obj *.lo core core.* rm -f libgnuintl.h libintl.h charset.alias ref-add.sed ref-del.sed rm -f -r .libs _libs clean: mostlyclean distclean: clean rm -f Makefile ID TAGS if test "$(PACKAGE)" = "gettext-runtime" || test "$(PACKAGE)" = "gettext-tools"; then \ rm -f ChangeLog.inst $(DISTFILES.normal); \ else \ : ; \ fi maintainer-clean: distclean @echo "This command is intended for maintainers to use;" @echo "it deletes files that may require special tools to rebuild." # GNU gettext needs not contain the file `VERSION' but contains some # other files which should not be distributed in other packages. distdir = ../$(PACKAGE)-$(VERSION)/$(subdir) dist distdir: Makefile if test "$(PACKAGE)" = "gettext-tools"; then \ : ; \ else \ if test "$(PACKAGE)" = "gettext-runtime"; then \ additional="$(DISTFILES.gettext)"; \ else \ additional="$(DISTFILES.normal)"; \ fi; \ $(MAKE) $(DISTFILES.common) $(DISTFILES.generated) $$additional; \ for file in ChangeLog $(DISTFILES.common) $(DISTFILES.generated) $$additional; do \ if test -f $$file; then dir=.; else dir=$(srcdir); fi; \ cp -p $$dir/$$file $(distdir) || test $$file = Makefile.in || exit 1; \ done; \ fi Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status cd $(top_builddir) && $(SHELL) ./config.status # This would be more efficient, but doesn't work any more with autoconf-2.57, # when AC_CONFIG_FILES([intl/Makefile:somedir/Makefile.in]) is used. # cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status # Tell versions [3.59,3.63) of GNU make not to export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: lightspeed-1.2a.debian.1/intl/VERSION000066400000000000000000000000501334064775200172510ustar00rootroot00000000000000GNU gettext library from gettext-0.14.5 lightspeed-1.2a.debian.1/intl/bindtextdom.c000066400000000000000000000231241334064775200206750ustar00rootroot00000000000000/* Implementation of the bindtextdomain(3) function Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif #include "gettextP.h" #ifdef _LIBC /* We have to handle multi-threaded applications. */ # include #else /* Provide dummy implementation if this is outside glibc. */ # define __libc_rwlock_define(CLASS, NAME) # define __libc_rwlock_wrlock(NAME) # define __libc_rwlock_unlock(NAME) #endif /* The internal variables in the standalone libintl.a must have different names than the internal variables in GNU libc, otherwise programs using libintl.a cannot be linked statically. */ #if !defined _LIBC # define _nl_default_dirname libintl_nl_default_dirname # define _nl_domain_bindings libintl_nl_domain_bindings #endif /* Some compilers, like SunOS4 cc, don't have offsetof in . */ #ifndef offsetof # define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) #endif /* @@ end of prolog @@ */ /* Contains the default location of the message catalogs. */ extern const char _nl_default_dirname[]; #ifdef _LIBC extern const char _nl_default_dirname_internal[] attribute_hidden; #else # define INTUSE(name) name #endif /* List with bindings of specific domains. */ extern struct binding *_nl_domain_bindings; /* Lock variable to protect the global data in the gettext implementation. */ __libc_rwlock_define (extern, _nl_state_lock attribute_hidden) /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define BINDTEXTDOMAIN __bindtextdomain # define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset # ifndef strdup # define strdup(str) __strdup (str) # endif #else # define BINDTEXTDOMAIN libintl_bindtextdomain # define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset #endif /* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP to be used for the DOMAINNAME message catalog. If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not modified, only the current value is returned. If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither modified nor returned. */ static void set_binding_values (const char *domainname, const char **dirnamep, const char **codesetp) { struct binding *binding; int modified; /* Some sanity checks. */ if (domainname == NULL || domainname[0] == '\0') { if (dirnamep) *dirnamep = NULL; if (codesetp) *codesetp = NULL; return; } __libc_rwlock_wrlock (_nl_state_lock); modified = 0; for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) { int compare = strcmp (domainname, binding->domainname); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It is not in the list. */ binding = NULL; break; } } if (binding != NULL) { if (dirnamep) { const char *dirname = *dirnamep; if (dirname == NULL) /* The current binding has be to returned. */ *dirnamep = binding->dirname; else { /* The domain is already bound. If the new value and the old one are equal we simply do nothing. Otherwise replace the old binding. */ char *result = binding->dirname; if (strcmp (dirname, result) != 0) { if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) result = (char *) INTUSE(_nl_default_dirname); else { #if defined _LIBC || defined HAVE_STRDUP result = strdup (dirname); #else size_t len = strlen (dirname) + 1; result = (char *) malloc (len); if (__builtin_expect (result != NULL, 1)) memcpy (result, dirname, len); #endif } if (__builtin_expect (result != NULL, 1)) { if (binding->dirname != INTUSE(_nl_default_dirname)) free (binding->dirname); binding->dirname = result; modified = 1; } } *dirnamep = result; } } if (codesetp) { const char *codeset = *codesetp; if (codeset == NULL) /* The current binding has be to returned. */ *codesetp = binding->codeset; else { /* The domain is already bound. If the new value and the old one are equal we simply do nothing. Otherwise replace the old binding. */ char *result = binding->codeset; if (result == NULL || strcmp (codeset, result) != 0) { #if defined _LIBC || defined HAVE_STRDUP result = strdup (codeset); #else size_t len = strlen (codeset) + 1; result = (char *) malloc (len); if (__builtin_expect (result != NULL, 1)) memcpy (result, codeset, len); #endif if (__builtin_expect (result != NULL, 1)) { if (binding->codeset != NULL) free (binding->codeset); binding->codeset = result; binding->codeset_cntr++; modified = 1; } } *codesetp = result; } } } else if ((dirnamep == NULL || *dirnamep == NULL) && (codesetp == NULL || *codesetp == NULL)) { /* Simply return the default values. */ if (dirnamep) *dirnamep = INTUSE(_nl_default_dirname); if (codesetp) *codesetp = NULL; } else { /* We have to create a new binding. */ size_t len = strlen (domainname) + 1; struct binding *new_binding = (struct binding *) malloc (offsetof (struct binding, domainname) + len); if (__builtin_expect (new_binding == NULL, 0)) goto failed; memcpy (new_binding->domainname, domainname, len); if (dirnamep) { const char *dirname = *dirnamep; if (dirname == NULL) /* The default value. */ dirname = INTUSE(_nl_default_dirname); else { if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) dirname = INTUSE(_nl_default_dirname); else { char *result; #if defined _LIBC || defined HAVE_STRDUP result = strdup (dirname); if (__builtin_expect (result == NULL, 0)) goto failed_dirname; #else size_t len = strlen (dirname) + 1; result = (char *) malloc (len); if (__builtin_expect (result == NULL, 0)) goto failed_dirname; memcpy (result, dirname, len); #endif dirname = result; } } *dirnamep = dirname; new_binding->dirname = (char *) dirname; } else /* The default value. */ new_binding->dirname = (char *) INTUSE(_nl_default_dirname); new_binding->codeset_cntr = 0; if (codesetp) { const char *codeset = *codesetp; if (codeset != NULL) { char *result; #if defined _LIBC || defined HAVE_STRDUP result = strdup (codeset); if (__builtin_expect (result == NULL, 0)) goto failed_codeset; #else size_t len = strlen (codeset) + 1; result = (char *) malloc (len); if (__builtin_expect (result == NULL, 0)) goto failed_codeset; memcpy (result, codeset, len); #endif codeset = result; new_binding->codeset_cntr++; } *codesetp = codeset; new_binding->codeset = (char *) codeset; } else new_binding->codeset = NULL; /* Now enqueue it. */ if (_nl_domain_bindings == NULL || strcmp (domainname, _nl_domain_bindings->domainname) < 0) { new_binding->next = _nl_domain_bindings; _nl_domain_bindings = new_binding; } else { binding = _nl_domain_bindings; while (binding->next != NULL && strcmp (domainname, binding->next->domainname) > 0) binding = binding->next; new_binding->next = binding->next; binding->next = new_binding; } modified = 1; /* Here we deal with memory allocation failures. */ if (0) { failed_codeset: if (new_binding->dirname != INTUSE(_nl_default_dirname)) free (new_binding->dirname); failed_dirname: free (new_binding); failed: if (dirnamep) *dirnamep = NULL; if (codesetp) *codesetp = NULL; } } /* If we modified any binding, we flush the caches. */ if (modified) ++_nl_msg_cat_cntr; __libc_rwlock_unlock (_nl_state_lock); } /* Specify that the DOMAINNAME message catalog will be found in DIRNAME rather than in the system locale data base. */ char * BINDTEXTDOMAIN (const char *domainname, const char *dirname) { set_binding_values (domainname, &dirname, NULL); return (char *) dirname; } /* Specify the character encoding in which the messages from the DOMAINNAME message catalog will be returned. */ char * BIND_TEXTDOMAIN_CODESET (const char *domainname, const char *codeset) { set_binding_values (domainname, NULL, &codeset); return (char *) codeset; } #ifdef _LIBC /* Aliases for function names in GNU C Library. */ weak_alias (__bindtextdomain, bindtextdomain); weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset); #endif lightspeed-1.2a.debian.1/intl/config.charset000066400000000000000000000465341334064775200210420ustar00rootroot00000000000000#! /bin/sh # Output a system dependent table of character encoding aliases. # # Copyright (C) 2000-2004 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # The table consists of lines of the form # ALIAS CANONICAL # # ALIAS is the (system dependent) result of "nl_langinfo (CODESET)". # ALIAS is compared in a case sensitive way. # # CANONICAL is the GNU canonical name for this character encoding. # It must be an encoding supported by libiconv. Support by GNU libc is # also desirable. CANONICAL is case insensitive. Usually an upper case # MIME charset name is preferred. # The current list of GNU canonical charset names is as follows. # # name MIME? used by which systems # ASCII, ANSI_X3.4-1968 glibc solaris freebsd darwin # ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd darwin # ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd darwin # ISO-8859-3 Y glibc solaris # ISO-8859-4 Y osf solaris freebsd darwin # ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd darwin # ISO-8859-6 Y glibc aix hpux solaris # ISO-8859-7 Y glibc aix hpux irix osf solaris darwin # ISO-8859-8 Y glibc aix hpux osf solaris # ISO-8859-9 Y glibc aix hpux irix osf solaris darwin # ISO-8859-13 glibc darwin # ISO-8859-14 glibc # ISO-8859-15 glibc aix osf solaris freebsd darwin # KOI8-R Y glibc solaris freebsd darwin # KOI8-U Y glibc freebsd darwin # KOI8-T glibc # CP437 dos # CP775 dos # CP850 aix osf dos # CP852 dos # CP855 dos # CP856 aix # CP857 dos # CP861 dos # CP862 dos # CP864 dos # CP865 dos # CP866 freebsd darwin dos # CP869 dos # CP874 woe32 dos # CP922 aix # CP932 aix woe32 dos # CP943 aix # CP949 osf woe32 dos # CP950 woe32 dos # CP1046 aix # CP1124 aix # CP1125 dos # CP1129 aix # CP1250 woe32 # CP1251 glibc solaris darwin woe32 # CP1252 aix woe32 # CP1253 woe32 # CP1254 woe32 # CP1255 glibc woe32 # CP1256 woe32 # CP1257 woe32 # GB2312 Y glibc aix hpux irix solaris freebsd darwin # EUC-JP Y glibc aix hpux irix osf solaris freebsd darwin # EUC-KR Y glibc aix hpux irix osf solaris freebsd darwin # EUC-TW glibc aix hpux irix osf solaris # BIG5 Y glibc aix hpux osf solaris freebsd darwin # BIG5-HKSCS glibc solaris # GBK glibc aix osf solaris woe32 dos # GB18030 glibc solaris # SHIFT_JIS Y hpux osf solaris freebsd darwin # JOHAB glibc solaris woe32 # TIS-620 glibc aix hpux osf solaris # VISCII Y glibc # TCVN5712-1 glibc # GEORGIAN-PS glibc # HP-ROMAN8 hpux # HP-ARABIC8 hpux # HP-GREEK8 hpux # HP-HEBREW8 hpux # HP-TURKISH8 hpux # HP-KANA8 hpux # DEC-KANJI osf # DEC-HANYU osf # UTF-8 Y glibc aix hpux osf solaris darwin # # Note: Names which are not marked as being a MIME name should not be used in # Internet protocols for information interchange (mail, news, etc.). # # Note: ASCII and ANSI_X3.4-1968 are synonymous canonical names. Applications # must understand both names and treat them as equivalent. # # The first argument passed to this file is the canonical host specification, # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM host="$1" os=`echo "$host" | sed -e 's/^[^-]*-[^-]*-\(.*\)$/\1/'` echo "# This file contains a table of character encoding aliases," echo "# suitable for operating system '${os}'." echo "# It was automatically generated from config.charset." # List of references, updated during installation: echo "# Packages using this file: " case "$os" in linux-gnulibc1*) # Linux libc5 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "C ASCII" echo "POSIX ASCII" for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ sv_FI sv_SE; do echo "$l ISO-8859-1" echo "$l.iso-8859-1 ISO-8859-1" echo "$l.iso-8859-15 ISO-8859-15" echo "$l.iso-8859-15@euro ISO-8859-15" echo "$l@euro ISO-8859-15" echo "$l.cp-437 CP437" echo "$l.cp-850 CP850" echo "$l.cp-1252 CP1252" echo "$l.cp-1252@euro CP1252" #echo "$l.atari-st ATARI-ST" # not a commonly used encoding echo "$l.utf-8 UTF-8" echo "$l.utf-8@euro UTF-8" done for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ sl_SI sr sr_CS sr_YU; do echo "$l ISO-8859-2" echo "$l.iso-8859-2 ISO-8859-2" echo "$l.cp-852 CP852" echo "$l.cp-1250 CP1250" echo "$l.utf-8 UTF-8" done for l in mk mk_MK ru ru_RU; do echo "$l ISO-8859-5" echo "$l.iso-8859-5 ISO-8859-5" echo "$l.koi8-r KOI8-R" echo "$l.cp-866 CP866" echo "$l.cp-1251 CP1251" echo "$l.utf-8 UTF-8" done for l in ar ar_SA; do echo "$l ISO-8859-6" echo "$l.iso-8859-6 ISO-8859-6" echo "$l.cp-864 CP864" #echo "$l.cp-868 CP868" # not a commonly used encoding echo "$l.cp-1256 CP1256" echo "$l.utf-8 UTF-8" done for l in el el_GR gr gr_GR; do echo "$l ISO-8859-7" echo "$l.iso-8859-7 ISO-8859-7" echo "$l.cp-869 CP869" echo "$l.cp-1253 CP1253" echo "$l.cp-1253@euro CP1253" echo "$l.utf-8 UTF-8" echo "$l.utf-8@euro UTF-8" done for l in he he_IL iw iw_IL; do echo "$l ISO-8859-8" echo "$l.iso-8859-8 ISO-8859-8" echo "$l.cp-862 CP862" echo "$l.cp-1255 CP1255" echo "$l.utf-8 UTF-8" done for l in tr tr_TR; do echo "$l ISO-8859-9" echo "$l.iso-8859-9 ISO-8859-9" echo "$l.cp-857 CP857" echo "$l.cp-1254 CP1254" echo "$l.utf-8 UTF-8" done for l in lt lt_LT lv lv_LV; do #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name echo "$l ISO-8859-13" done for l in ru_UA uk uk_UA; do echo "$l KOI8-U" done for l in zh zh_CN; do #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name echo "$l GB2312" done for l in ja ja_JP ja_JP.EUC; do echo "$l EUC-JP" done for l in ko ko_KR; do echo "$l EUC-KR" done for l in th th_TH; do echo "$l TIS-620" done for l in fa fa_IR; do #echo "$l ISIRI-3342" # a broken encoding echo "$l.utf-8 UTF-8" done ;; linux* | *-gnu*) # With glibc-2.1 or newer, we don't need any canonicalization, # because glibc has iconv and both glibc and libiconv support all # GNU canonical names directly. Therefore, the Makefile does not # need to install the alias file at all. # The following applies only to glibc-2.0.x and older libcs. echo "ISO_646.IRV:1983 ASCII" ;; aix*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-6 ISO-8859-6" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "IBM-850 CP850" echo "IBM-856 CP856" echo "IBM-921 ISO-8859-13" echo "IBM-922 CP922" echo "IBM-932 CP932" echo "IBM-943 CP943" echo "IBM-1046 CP1046" echo "IBM-1124 CP1124" echo "IBM-1129 CP1129" echo "IBM-1252 CP1252" echo "IBM-eucCN GB2312" echo "IBM-eucJP EUC-JP" echo "IBM-eucKR EUC-KR" echo "IBM-eucTW EUC-TW" echo "big5 BIG5" echo "GBK GBK" echo "TIS-620 TIS-620" echo "UTF-8 UTF-8" ;; hpux*) echo "iso88591 ISO-8859-1" echo "iso88592 ISO-8859-2" echo "iso88595 ISO-8859-5" echo "iso88596 ISO-8859-6" echo "iso88597 ISO-8859-7" echo "iso88598 ISO-8859-8" echo "iso88599 ISO-8859-9" echo "iso885915 ISO-8859-15" echo "roman8 HP-ROMAN8" echo "arabic8 HP-ARABIC8" echo "greek8 HP-GREEK8" echo "hebrew8 HP-HEBREW8" echo "turkish8 HP-TURKISH8" echo "kana8 HP-KANA8" echo "tis620 TIS-620" echo "big5 BIG5" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "hp15CN GB2312" #echo "ccdc ?" # what is this? echo "SJIS SHIFT_JIS" echo "utf8 UTF-8" ;; irix*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-9 ISO-8859-9" echo "eucCN GB2312" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" ;; osf*) echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "cp850 CP850" echo "big5 BIG5" echo "dechanyu DEC-HANYU" echo "dechanzi GB2312" echo "deckanji DEC-KANJI" echo "deckorean EUC-KR" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "GBK GBK" echo "KSC5601 CP949" echo "sdeckanji EUC-JP" echo "SJIS SHIFT_JIS" echo "TACTIS TIS-620" echo "UTF-8 UTF-8" ;; solaris*) echo "646 ASCII" echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-3 ISO-8859-3" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-6 ISO-8859-6" echo "ISO8859-7 ISO-8859-7" echo "ISO8859-8 ISO-8859-8" echo "ISO8859-9 ISO-8859-9" echo "ISO8859-15 ISO-8859-15" echo "koi8-r KOI8-R" echo "ansi-1251 CP1251" echo "BIG5 BIG5" echo "Big5-HKSCS BIG5-HKSCS" echo "gb2312 GB2312" echo "GBK GBK" echo "GB18030 GB18030" echo "cns11643 EUC-TW" echo "5601 EUC-KR" echo "ko_KR.johap92 JOHAB" echo "eucJP EUC-JP" echo "PCK SHIFT_JIS" echo "TIS620.2533 TIS-620" #echo "sun_eu_greek ?" # what is this? echo "UTF-8 UTF-8" ;; freebsd* | os2*) # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just # reuse FreeBSD's locale data for OS/2. echo "C ASCII" echo "US-ASCII ASCII" for l in la_LN lt_LN; do echo "$l.ASCII ASCII" done for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do echo "$l.ISO_8859-1 ISO-8859-1" echo "$l.DIS_8859-15 ISO-8859-15" done for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do echo "$l.ISO_8859-2 ISO-8859-2" done for l in la_LN lt_LT; do echo "$l.ISO_8859-4 ISO-8859-4" done for l in ru_RU ru_SU; do echo "$l.KOI8-R KOI8-R" echo "$l.ISO_8859-5 ISO-8859-5" echo "$l.CP866 CP866" done echo "uk_UA.KOI8-U KOI8-U" echo "zh_TW.BIG5 BIG5" echo "zh_TW.Big5 BIG5" echo "zh_CN.EUC GB2312" echo "ja_JP.EUC EUC-JP" echo "ja_JP.SJIS SHIFT_JIS" echo "ja_JP.Shift_JIS SHIFT_JIS" echo "ko_KR.EUC EUC-KR" ;; netbsd*) echo "646 ASCII" echo "ISO8859-1 ISO-8859-1" echo "ISO8859-2 ISO-8859-2" echo "ISO8859-4 ISO-8859-4" echo "ISO8859-5 ISO-8859-5" echo "ISO8859-15 ISO-8859-15" echo "eucCN GB2312" echo "eucJP EUC-JP" echo "eucKR EUC-KR" echo "eucTW EUC-TW" echo "BIG5 BIG5" echo "SJIS SHIFT_JIS" ;; darwin[56]*) # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "C ASCII" for l in en_AU en_CA en_GB en_US la_LN; do echo "$l.US-ASCII ASCII" done for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ nl_NL no_NO pt_PT sv_SE; do echo "$l ISO-8859-1" echo "$l.ISO8859-1 ISO-8859-1" echo "$l.ISO8859-15 ISO-8859-15" done for l in la_LN; do echo "$l.ISO8859-1 ISO-8859-1" echo "$l.ISO8859-15 ISO-8859-15" done for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do echo "$l.ISO8859-2 ISO-8859-2" done for l in la_LN lt_LT; do echo "$l.ISO8859-4 ISO-8859-4" done for l in ru_RU; do echo "$l.KOI8-R KOI8-R" echo "$l.ISO8859-5 ISO-8859-5" echo "$l.CP866 CP866" done for l in bg_BG; do echo "$l.CP1251 CP1251" done echo "uk_UA.KOI8-U KOI8-U" echo "zh_TW.BIG5 BIG5" echo "zh_TW.Big5 BIG5" echo "zh_CN.EUC GB2312" echo "ja_JP.EUC EUC-JP" echo "ja_JP.SJIS SHIFT_JIS" echo "ko_KR.EUC EUC-KR" ;; darwin*) # Darwin 7.5 has nl_langinfo(CODESET), but it is useless: # - It returns the empty string when LANG is set to a locale of the # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 # LC_CTYPE file. # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. # - The documentation says: # "... all code that calls BSD system routines should ensure # that the const *char parameters of these routines are in UTF-8 # encoding. All BSD system functions expect their string # parameters to be in UTF-8 encoding and nothing else." # It also says # "An additional caveat is that string parameters for files, # paths, and other file-system entities must be in canonical # UTF-8. In a canonical UTF-8 Unicode string, all decomposable # characters are decomposed ..." # but this is not true: You can pass non-decomposed UTF-8 strings # to file system functions, and it is the OS which will convert # them to decomposed UTF-8 before accessing the file system. # - The Apple Terminal application displays UTF-8 by default. # - However, other applications are free to use different encodings: # - xterm uses ISO-8859-1 by default. # - TextEdit uses MacRoman by default. # We prefer UTF-8 over decomposed UTF-8-MAC because one should # minimize the use of decomposed Unicode. Unfortunately, through the # Darwin file system, decomposed UTF-8 strings are leaked into user # space nevertheless. echo "* UTF-8" ;; beos*) # BeOS has a single locale, and it has UTF-8 encoding. echo "* UTF-8" ;; msdosdjgpp*) # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore # localcharset.c falls back to using the full locale name # from the environment variables. echo "#" echo "# The encodings given here may not all be correct." echo "# If you find that the encoding given for your language and" echo "# country is not the one your DOS machine actually uses, just" echo "# correct it in this file, and send a mail to" echo "# Juan Manuel Guerrero " echo "# and Bruno Haible ." echo "#" echo "C ASCII" # ISO-8859-1 languages echo "ca CP850" echo "ca_ES CP850" echo "da CP865" # not CP850 ?? echo "da_DK CP865" # not CP850 ?? echo "de CP850" echo "de_AT CP850" echo "de_CH CP850" echo "de_DE CP850" echo "en CP850" echo "en_AU CP850" # not CP437 ?? echo "en_CA CP850" echo "en_GB CP850" echo "en_NZ CP437" echo "en_US CP437" echo "en_ZA CP850" # not CP437 ?? echo "es CP850" echo "es_AR CP850" echo "es_BO CP850" echo "es_CL CP850" echo "es_CO CP850" echo "es_CR CP850" echo "es_CU CP850" echo "es_DO CP850" echo "es_EC CP850" echo "es_ES CP850" echo "es_GT CP850" echo "es_HN CP850" echo "es_MX CP850" echo "es_NI CP850" echo "es_PA CP850" echo "es_PY CP850" echo "es_PE CP850" echo "es_SV CP850" echo "es_UY CP850" echo "es_VE CP850" echo "et CP850" echo "et_EE CP850" echo "eu CP850" echo "eu_ES CP850" echo "fi CP850" echo "fi_FI CP850" echo "fr CP850" echo "fr_BE CP850" echo "fr_CA CP850" echo "fr_CH CP850" echo "fr_FR CP850" echo "ga CP850" echo "ga_IE CP850" echo "gd CP850" echo "gd_GB CP850" echo "gl CP850" echo "gl_ES CP850" echo "id CP850" # not CP437 ?? echo "id_ID CP850" # not CP437 ?? echo "is CP861" # not CP850 ?? echo "is_IS CP861" # not CP850 ?? echo "it CP850" echo "it_CH CP850" echo "it_IT CP850" echo "lt CP775" echo "lt_LT CP775" echo "lv CP775" echo "lv_LV CP775" echo "nb CP865" # not CP850 ?? echo "nb_NO CP865" # not CP850 ?? echo "nl CP850" echo "nl_BE CP850" echo "nl_NL CP850" echo "nn CP865" # not CP850 ?? echo "nn_NO CP865" # not CP850 ?? echo "no CP865" # not CP850 ?? echo "no_NO CP865" # not CP850 ?? echo "pt CP850" echo "pt_BR CP850" echo "pt_PT CP850" echo "sv CP850" echo "sv_SE CP850" # ISO-8859-2 languages echo "cs CP852" echo "cs_CZ CP852" echo "hr CP852" echo "hr_HR CP852" echo "hu CP852" echo "hu_HU CP852" echo "pl CP852" echo "pl_PL CP852" echo "ro CP852" echo "ro_RO CP852" echo "sk CP852" echo "sk_SK CP852" echo "sl CP852" echo "sl_SI CP852" echo "sq CP852" echo "sq_AL CP852" echo "sr CP852" # CP852 or CP866 or CP855 ?? echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? # ISO-8859-3 languages echo "mt CP850" echo "mt_MT CP850" # ISO-8859-5 languages echo "be CP866" echo "be_BE CP866" echo "bg CP866" # not CP855 ?? echo "bg_BG CP866" # not CP855 ?? echo "mk CP866" # not CP855 ?? echo "mk_MK CP866" # not CP855 ?? echo "ru CP866" echo "ru_RU CP866" echo "uk CP1125" echo "uk_UA CP1125" # ISO-8859-6 languages echo "ar CP864" echo "ar_AE CP864" echo "ar_DZ CP864" echo "ar_EG CP864" echo "ar_IQ CP864" echo "ar_IR CP864" echo "ar_JO CP864" echo "ar_KW CP864" echo "ar_MA CP864" echo "ar_OM CP864" echo "ar_QA CP864" echo "ar_SA CP864" echo "ar_SY CP864" # ISO-8859-7 languages echo "el CP869" echo "el_GR CP869" # ISO-8859-8 languages echo "he CP862" echo "he_IL CP862" # ISO-8859-9 languages echo "tr CP857" echo "tr_TR CP857" # Japanese echo "ja CP932" echo "ja_JP CP932" # Chinese echo "zh_CN GBK" echo "zh_TW CP950" # not CP938 ?? # Korean echo "kr CP949" # not CP934 ?? echo "kr_KR CP949" # not CP934 ?? # Thai echo "th CP874" echo "th_TH CP874" # Other echo "eo CP850" echo "eo_EO CP850" ;; esac lightspeed-1.2a.debian.1/intl/dcgettext.c000066400000000000000000000034211334064775200203450ustar00rootroot00000000000000/* Implementation of the dcgettext(3) function. Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCGETTEXT __dcgettext # define DCIGETTEXT __dcigettext #else # define DCGETTEXT libintl_dcgettext # define DCIGETTEXT libintl_dcigettext #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ char * DCGETTEXT (const char *domainname, const char *msgid, int category) { return DCIGETTEXT (domainname, msgid, NULL, 0, 0, category); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ INTDEF(__dcgettext) weak_alias (__dcgettext, dcgettext); #endif lightspeed-1.2a.debian.1/intl/dcigettext.c000066400000000000000000001041561334064775200205250ustar00rootroot00000000000000/* Implementation of the internal dcigettext function. Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #ifdef __GNUC__ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #ifndef errno extern int errno; #endif #ifndef __set_errno # define __set_errno(val) errno = (val) #endif #include #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #include #ifdef _LIBC /* Guess whether integer division by zero raises signal SIGFPE. Set to 1 only if you know for sure. In case of doubt, set to 0. */ # if defined __alpha__ || defined __arm__ || defined __i386__ \ || defined __m68k__ || defined __s390__ # define INTDIV0_RAISES_SIGFPE 1 # else # define INTDIV0_RAISES_SIGFPE 0 # endif #endif #if !INTDIV0_RAISES_SIGFPE # include #endif #if defined HAVE_SYS_PARAM_H || defined _LIBC # include #endif #include "gettextP.h" #include "plural-exp.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif #include "hash-string.h" /* Thread safetyness. */ #ifdef _LIBC # include #else /* Provide dummy implementation if this is outside glibc. */ # define __libc_lock_define_initialized(CLASS, NAME) # define __libc_lock_lock(NAME) # define __libc_lock_unlock(NAME) # define __libc_rwlock_define_initialized(CLASS, NAME) # define __libc_rwlock_rdlock(NAME) # define __libc_rwlock_unlock(NAME) #endif /* Alignment of types. */ #if defined __GNUC__ && __GNUC__ >= 2 # define alignof(TYPE) __alignof__ (TYPE) #else # define alignof(TYPE) \ ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2) #endif /* The internal variables in the standalone libintl.a must have different names than the internal variables in GNU libc, otherwise programs using libintl.a cannot be linked statically. */ #if !defined _LIBC # define _nl_default_default_domain libintl_nl_default_default_domain # define _nl_current_default_domain libintl_nl_current_default_domain # define _nl_default_dirname libintl_nl_default_dirname # define _nl_domain_bindings libintl_nl_domain_bindings #endif /* Some compilers, like SunOS4 cc, don't have offsetof in . */ #ifndef offsetof # define offsetof(type,ident) ((size_t)&(((type*)0)->ident)) #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # define getcwd __getcwd # ifndef stpcpy # define stpcpy __stpcpy # endif # define tfind __tfind #else # if !defined HAVE_GETCWD char *getwd (); # define getcwd(buf, max) getwd (buf) # else # if VMS # define getcwd(buf, max) (getcwd) (buf, max, 0) # else char *getcwd (); # endif # endif # ifndef HAVE_STPCPY static char *stpcpy (char *dest, const char *src); # endif # ifndef HAVE_MEMPCPY static void *mempcpy (void *dest, const void *src, size_t n); # endif #endif /* Amount to increase buffer size by in each try. */ #define PATH_INCR 32 /* The following is from pathmax.h. */ /* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define PATH_MAX but might cause redefinition warnings when sys/param.h is later included (as on MORE/BSD 4.3). */ #if defined _POSIX_VERSION || (defined HAVE_LIMITS_H && !defined __GNUC__) # include #endif #ifndef _POSIX_PATH_MAX # define _POSIX_PATH_MAX 255 #endif #if !defined PATH_MAX && defined _PC_PATH_MAX # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX)) #endif /* Don't include sys/param.h if it already has been. */ #if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN # include #endif #if !defined PATH_MAX && defined MAXPATHLEN # define PATH_MAX MAXPATHLEN #endif #ifndef PATH_MAX # define PATH_MAX _POSIX_PATH_MAX #endif /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not, it may be concatenated to a directory pathname. IS_PATH_WITH_DIR(P) tests whether P contains a directory specification. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P)) # define IS_PATH_WITH_DIR(P) \ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P)) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0]) # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL) #endif /* This is the type used for the search tree where known translations are stored. */ struct known_translation_t { /* Domain in which to search. */ char *domainname; /* The category. */ int category; /* State of the catalog counter at the point the string was found. */ int counter; /* Catalog where the string was found. */ struct loaded_l10nfile *domain; /* And finally the translation. */ const char *translation; size_t translation_length; /* Pointer to the string in question. */ char msgid[ZERO]; }; /* Root of the search tree with known translations. We can use this only if the system provides the `tsearch' function family. */ #if defined HAVE_TSEARCH || defined _LIBC # include static void *root; # ifdef _LIBC # define tsearch __tsearch # endif /* Function to compare two entries in the table of known translations. */ static int transcmp (const void *p1, const void *p2) { const struct known_translation_t *s1; const struct known_translation_t *s2; int result; s1 = (const struct known_translation_t *) p1; s2 = (const struct known_translation_t *) p2; result = strcmp (s1->msgid, s2->msgid); if (result == 0) { result = strcmp (s1->domainname, s2->domainname); if (result == 0) /* We compare the category last (though this is the cheapest operation) since it is hopefully always the same (namely LC_MESSAGES). */ result = s1->category - s2->category; } return result; } #endif #ifndef INTVARDEF # define INTVARDEF(name) #endif #ifndef INTUSE # define INTUSE(name) name #endif /* Name of the default domain used for gettext(3) prior any call to textdomain(3). The default value for this is "messages". */ const char _nl_default_default_domain[] attribute_hidden = "messages"; /* Value used as the default domain for gettext(3). */ const char *_nl_current_default_domain attribute_hidden = _nl_default_default_domain; /* Contains the default location of the message catalogs. */ #if defined __EMX__ extern const char _nl_default_dirname[]; #else const char _nl_default_dirname[] = LOCALEDIR; INTVARDEF (_nl_default_dirname) #endif /* List with bindings of specific domains created by bindtextdomain() calls. */ struct binding *_nl_domain_bindings; /* Prototypes for local functions. */ static char *plural_lookup (struct loaded_l10nfile *domain, unsigned long int n, const char *translation, size_t translation_len) internal_function; static const char *guess_category_value (int category, const char *categoryname) internal_function; #ifdef _LIBC # include "../locale/localeinfo.h" # define category_to_name(category) _nl_category_names[category] #else static const char *category_to_name (int category) internal_function; #endif /* For those loosing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA /* Nothing has to be done. */ # define freea(p) /* nothing */ # define ADD_BLOCK(list, address) /* nothing */ # define FREE_BLOCKS(list) /* nothing */ #else struct block_list { void *address; struct block_list *next; }; # define ADD_BLOCK(list, addr) \ do { \ struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ /* If we cannot get a free block we cannot add the new element to \ the list. */ \ if (newp != NULL) { \ newp->address = (addr); \ newp->next = (list); \ (list) = newp; \ } \ } while (0) # define FREE_BLOCKS(list) \ do { \ while (list != NULL) { \ struct block_list *old = list; \ list = list->next; \ free (old->address); \ free (old); \ } \ } while (0) # undef alloca # define alloca(size) (malloc (size)) # define freea(p) free (p) #endif /* have alloca */ #ifdef _LIBC /* List of blocks allocated for translations. */ typedef struct transmem_list { struct transmem_list *next; char data[ZERO]; } transmem_block_t; static struct transmem_list *transmem_list; #else typedef unsigned char transmem_block_t; #endif /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCIGETTEXT __dcigettext #else # define DCIGETTEXT libintl_dcigettext #endif /* Lock variable to protect the global data in the gettext implementation. */ #ifdef _LIBC __libc_rwlock_define_initialized (, _nl_state_lock attribute_hidden) #endif /* Checking whether the binaries runs SUID must be done and glibc provides easier methods therefore we make a difference here. */ #ifdef _LIBC # define ENABLE_SECURE __libc_enable_secure # define DETERMINE_SECURE #else # ifndef HAVE_GETUID # define getuid() 0 # endif # ifndef HAVE_GETGID # define getgid() 0 # endif # ifndef HAVE_GETEUID # define geteuid() getuid() # endif # ifndef HAVE_GETEGID # define getegid() getgid() # endif static int enable_secure; # define ENABLE_SECURE (enable_secure == 1) # define DETERMINE_SECURE \ if (enable_secure == 0) \ { \ if (getuid () != geteuid () || getgid () != getegid ()) \ enable_secure = 1; \ else \ enable_secure = -1; \ } #endif /* Get the function to evaluate the plural expression. */ #include "eval-plural.h" /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale and, if PLURAL is nonzero, search over string depending on the plural form determined by N. */ char * DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, int plural, unsigned long int n, int category) { #ifndef HAVE_ALLOCA struct block_list *block_list = NULL; #endif struct loaded_l10nfile *domain; struct binding *binding; const char *categoryname; const char *categoryvalue; char *dirname, *xdomainname; char *single_locale; char *retval; size_t retlen; int saved_errno; #if defined HAVE_TSEARCH || defined _LIBC struct known_translation_t *search; struct known_translation_t **foundp = NULL; size_t msgid_len; #endif size_t domainname_len; /* If no real MSGID is given return NULL. */ if (msgid1 == NULL) return NULL; #ifdef _LIBC if (category < 0 || category >= __LC_LAST || category == LC_ALL) /* Bogus. */ return (plural == 0 ? (char *) msgid1 /* Use the Germanic plural rule. */ : n == 1 ? (char *) msgid1 : (char *) msgid2); #endif __libc_rwlock_rdlock (_nl_state_lock); /* If DOMAINNAME is NULL, we are interested in the default domain. If CATEGORY is not LC_MESSAGES this might not make much sense but the definition left this undefined. */ if (domainname == NULL) domainname = _nl_current_default_domain; /* OS/2 specific: backward compatibility with older libintl versions */ #ifdef LC_MESSAGES_COMPAT if (category == LC_MESSAGES_COMPAT) category = LC_MESSAGES; #endif #if defined HAVE_TSEARCH || defined _LIBC msgid_len = strlen (msgid1) + 1; /* Try to find the translation among those which we found at some time. */ search = (struct known_translation_t *) alloca (offsetof (struct known_translation_t, msgid) + msgid_len); memcpy (search->msgid, msgid1, msgid_len); search->domainname = (char *) domainname; search->category = category; foundp = (struct known_translation_t **) tfind (search, &root, transcmp); freea (search); if (foundp != NULL && (*foundp)->counter == _nl_msg_cat_cntr) { /* Now deal with plural. */ if (plural) retval = plural_lookup ((*foundp)->domain, n, (*foundp)->translation, (*foundp)->translation_length); else retval = (char *) (*foundp)->translation; __libc_rwlock_unlock (_nl_state_lock); return retval; } #endif /* Preserve the `errno' value. */ saved_errno = errno; /* See whether this is a SUID binary or not. */ DETERMINE_SECURE; /* First find matching binding. */ for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) { int compare = strcmp (domainname, binding->domainname); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It is not in the list. */ binding = NULL; break; } } if (binding == NULL) dirname = (char *) INTUSE(_nl_default_dirname); else if (IS_ABSOLUTE_PATH (binding->dirname)) dirname = binding->dirname; else { /* We have a relative path. Make it absolute now. */ size_t dirname_len = strlen (binding->dirname) + 1; size_t path_max; char *ret; path_max = (unsigned int) PATH_MAX; path_max += 2; /* The getcwd docs say to do this. */ for (;;) { dirname = (char *) alloca (path_max + dirname_len); ADD_BLOCK (block_list, dirname); __set_errno (0); ret = getcwd (dirname, path_max); if (ret != NULL || errno != ERANGE) break; path_max += path_max / 2; path_max += PATH_INCR; } if (ret == NULL) /* We cannot get the current working directory. Don't signal an error but simply return the default string. */ goto return_untranslated; stpcpy (stpcpy (strchr (dirname, '\0'), "/"), binding->dirname); } /* Now determine the symbolic name of CATEGORY and its value. */ categoryname = category_to_name (category); categoryvalue = guess_category_value (category, categoryname); domainname_len = strlen (domainname); xdomainname = (char *) alloca (strlen (categoryname) + domainname_len + 5); ADD_BLOCK (block_list, xdomainname); stpcpy (mempcpy (stpcpy (stpcpy (xdomainname, categoryname), "/"), domainname, domainname_len), ".mo"); /* Creating working area. */ single_locale = (char *) alloca (strlen (categoryvalue) + 1); ADD_BLOCK (block_list, single_locale); /* Search for the given string. This is a loop because we perhaps got an ordered list of languages to consider for the translation. */ while (1) { /* Make CATEGORYVALUE point to the next element of the list. */ while (categoryvalue[0] != '\0' && categoryvalue[0] == ':') ++categoryvalue; if (categoryvalue[0] == '\0') { /* The whole contents of CATEGORYVALUE has been searched but no valid entry has been found. We solve this situation by implicitly appending a "C" entry, i.e. no translation will take place. */ single_locale[0] = 'C'; single_locale[1] = '\0'; } else { char *cp = single_locale; while (categoryvalue[0] != '\0' && categoryvalue[0] != ':') *cp++ = *categoryvalue++; *cp = '\0'; /* When this is a SUID binary we must not allow accessing files outside the dedicated directories. */ if (ENABLE_SECURE && IS_PATH_WITH_DIR (single_locale)) /* Ingore this entry. */ continue; } /* If the current locale value is C (or POSIX) we don't load a domain. Return the MSGID. */ if (strcmp (single_locale, "C") == 0 || strcmp (single_locale, "POSIX") == 0) break; /* Find structure describing the message catalog matching the DOMAINNAME and CATEGORY. */ domain = _nl_find_domain (dirname, single_locale, xdomainname, binding); if (domain != NULL) { retval = _nl_find_msg (domain, binding, msgid1, &retlen); if (retval == NULL) { int cnt; for (cnt = 0; domain->successor[cnt] != NULL; ++cnt) { retval = _nl_find_msg (domain->successor[cnt], binding, msgid1, &retlen); if (retval != NULL) { domain = domain->successor[cnt]; break; } } } if (retval != NULL) { /* Found the translation of MSGID1 in domain DOMAIN: starting at RETVAL, RETLEN bytes. */ FREE_BLOCKS (block_list); #if defined HAVE_TSEARCH || defined _LIBC if (foundp == NULL) { /* Create a new entry and add it to the search tree. */ struct known_translation_t *newp; newp = (struct known_translation_t *) malloc (offsetof (struct known_translation_t, msgid) + msgid_len + domainname_len + 1); if (newp != NULL) { newp->domainname = mempcpy (newp->msgid, msgid1, msgid_len); memcpy (newp->domainname, domainname, domainname_len + 1); newp->category = category; newp->counter = _nl_msg_cat_cntr; newp->domain = domain; newp->translation = retval; newp->translation_length = retlen; /* Insert the entry in the search tree. */ foundp = (struct known_translation_t **) tsearch (newp, &root, transcmp); if (foundp == NULL || __builtin_expect (*foundp != newp, 0)) /* The insert failed. */ free (newp); } } else { /* We can update the existing entry. */ (*foundp)->counter = _nl_msg_cat_cntr; (*foundp)->domain = domain; (*foundp)->translation = retval; (*foundp)->translation_length = retlen; } #endif __set_errno (saved_errno); /* Now deal with plural. */ if (plural) retval = plural_lookup (domain, n, retval, retlen); __libc_rwlock_unlock (_nl_state_lock); return retval; } } } return_untranslated: /* Return the untranslated MSGID. */ FREE_BLOCKS (block_list); __libc_rwlock_unlock (_nl_state_lock); #ifndef _LIBC if (!ENABLE_SECURE) { extern void _nl_log_untranslated (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural); const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED"); if (logfilename != NULL && logfilename[0] != '\0') _nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural); } #endif __set_errno (saved_errno); return (plural == 0 ? (char *) msgid1 /* Use the Germanic plural rule. */ : n == 1 ? (char *) msgid1 : (char *) msgid2); } char * internal_function _nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *msgid, size_t *lengthp) { struct loaded_domain *domain; nls_uint32 nstrings; size_t act; char *result; size_t resultlen; if (domain_file->decided == 0) _nl_load_domain (domain_file, domainbinding); if (domain_file->data == NULL) return NULL; domain = (struct loaded_domain *) domain_file->data; nstrings = domain->nstrings; /* Locate the MSGID and its translation. */ if (domain->hash_tab != NULL) { /* Use the hashing table. */ nls_uint32 len = strlen (msgid); nls_uint32 hash_val = hash_string (msgid); nls_uint32 idx = hash_val % domain->hash_size; nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); while (1) { nls_uint32 nstr = W (domain->must_swap_hash_tab, domain->hash_tab[idx]); if (nstr == 0) /* Hash table entry is empty. */ return NULL; nstr--; /* Compare msgid with the original string at index nstr. We compare the lengths with >=, not ==, because plural entries are represented by strings with an embedded NUL. */ if (nstr < nstrings ? W (domain->must_swap, domain->orig_tab[nstr].length) >= len && (strcmp (msgid, domain->data + W (domain->must_swap, domain->orig_tab[nstr].offset)) == 0) : domain->orig_sysdep_tab[nstr - nstrings].length > len && (strcmp (msgid, domain->orig_sysdep_tab[nstr - nstrings].pointer) == 0)) { act = nstr; goto found; } if (idx >= domain->hash_size - incr) idx -= domain->hash_size - incr; else idx += incr; } /* NOTREACHED */ } else { /* Try the default method: binary search in the sorted array of messages. */ size_t top, bottom; bottom = 0; top = nstrings; while (bottom < top) { int cmp_val; act = (bottom + top) / 2; cmp_val = strcmp (msgid, (domain->data + W (domain->must_swap, domain->orig_tab[act].offset))); if (cmp_val < 0) top = act; else if (cmp_val > 0) bottom = act + 1; else goto found; } /* No translation was found. */ return NULL; } found: /* The translation was found at index ACT. If we have to convert the string to use a different character set, this is the time. */ if (act < nstrings) { result = (char *) (domain->data + W (domain->must_swap, domain->trans_tab[act].offset)); resultlen = W (domain->must_swap, domain->trans_tab[act].length) + 1; } else { result = (char *) domain->trans_sysdep_tab[act - nstrings].pointer; resultlen = domain->trans_sysdep_tab[act - nstrings].length; } #if defined _LIBC || HAVE_ICONV if (domain->codeset_cntr != (domainbinding != NULL ? domainbinding->codeset_cntr : 0)) { /* The domain's codeset has changed through bind_textdomain_codeset() since the message catalog was initialized or last accessed. We have to reinitialize the converter. */ _nl_free_domain_conv (domain); _nl_init_domain_conv (domain_file, domain, domainbinding); } if ( # ifdef _LIBC domain->conv != (__gconv_t) -1 # else # if HAVE_ICONV domain->conv != (iconv_t) -1 # endif # endif ) { /* We are supposed to do a conversion. First allocate an appropriate table with the same structure as the table of translations in the file, where we can put the pointers to the converted strings in. There is a slight complication with plural entries. They are represented by consecutive NUL terminated strings. We handle this case by converting RESULTLEN bytes, including NULs. */ if (domain->conv_tab == NULL && ((domain->conv_tab = (char **) calloc (nstrings + domain->n_sysdep_strings, sizeof (char *))) == NULL)) /* Mark that we didn't succeed allocating a table. */ domain->conv_tab = (char **) -1; if (__builtin_expect (domain->conv_tab == (char **) -1, 0)) /* Nothing we can do, no more memory. */ goto converted; if (domain->conv_tab[act] == NULL) { /* We haven't used this string so far, so it is not translated yet. Do this now. */ /* We use a bit more efficient memory handling. We allocate always larger blocks which get used over time. This is faster than many small allocations. */ __libc_lock_define_initialized (static, lock) # define INITIAL_BLOCK_SIZE 4080 static unsigned char *freemem; static size_t freemem_size; const unsigned char *inbuf; unsigned char *outbuf; int malloc_count; # ifndef _LIBC transmem_block_t *transmem_list = NULL; # endif __libc_lock_lock (lock); inbuf = (const unsigned char *) result; outbuf = freemem + sizeof (size_t); malloc_count = 0; while (1) { transmem_block_t *newmem; # ifdef _LIBC size_t non_reversible; int res; if (freemem_size < sizeof (size_t)) goto resize_freemem; res = __gconv (domain->conv, &inbuf, inbuf + resultlen, &outbuf, outbuf + freemem_size - sizeof (size_t), &non_reversible); if (res == __GCONV_OK || res == __GCONV_EMPTY_INPUT) break; if (res != __GCONV_FULL_OUTPUT) { __libc_lock_unlock (lock); goto converted; } inbuf = result; # else # if HAVE_ICONV const char *inptr = (const char *) inbuf; size_t inleft = resultlen; char *outptr = (char *) outbuf; size_t outleft; if (freemem_size < sizeof (size_t)) goto resize_freemem; outleft = freemem_size - sizeof (size_t); if (iconv (domain->conv, (ICONV_CONST char **) &inptr, &inleft, &outptr, &outleft) != (size_t) (-1)) { outbuf = (unsigned char *) outptr; break; } if (errno != E2BIG) { __libc_lock_unlock (lock); goto converted; } # endif # endif resize_freemem: /* We must allocate a new buffer or resize the old one. */ if (malloc_count > 0) { ++malloc_count; freemem_size = malloc_count * INITIAL_BLOCK_SIZE; newmem = (transmem_block_t *) realloc (transmem_list, freemem_size); # ifdef _LIBC if (newmem != NULL) transmem_list = transmem_list->next; else { struct transmem_list *old = transmem_list; transmem_list = transmem_list->next; free (old); } # endif } else { malloc_count = 1; freemem_size = INITIAL_BLOCK_SIZE; newmem = (transmem_block_t *) malloc (freemem_size); } if (__builtin_expect (newmem == NULL, 0)) { freemem = NULL; freemem_size = 0; __libc_lock_unlock (lock); goto converted; } # ifdef _LIBC /* Add the block to the list of blocks we have to free at some point. */ newmem->next = transmem_list; transmem_list = newmem; freemem = newmem->data; freemem_size -= offsetof (struct transmem_list, data); # else transmem_list = newmem; freemem = newmem; # endif outbuf = freemem + sizeof (size_t); } /* We have now in our buffer a converted string. Put this into the table of conversions. */ *(size_t *) freemem = outbuf - freemem - sizeof (size_t); domain->conv_tab[act] = (char *) freemem; /* Shrink freemem, but keep it aligned. */ freemem_size -= outbuf - freemem; freemem = outbuf; freemem += freemem_size & (alignof (size_t) - 1); freemem_size = freemem_size & ~ (alignof (size_t) - 1); __libc_lock_unlock (lock); } /* Now domain->conv_tab[act] contains the translation of all the plural variants. */ result = domain->conv_tab[act] + sizeof (size_t); resultlen = *(size_t *) domain->conv_tab[act]; } converted: /* The result string is converted. */ #endif /* _LIBC || HAVE_ICONV */ *lengthp = resultlen; return result; } /* Look up a plural variant. */ static char * internal_function plural_lookup (struct loaded_l10nfile *domain, unsigned long int n, const char *translation, size_t translation_len) { struct loaded_domain *domaindata = (struct loaded_domain *) domain->data; unsigned long int index; const char *p; index = plural_eval (domaindata->plural, n); if (index >= domaindata->nplurals) /* This should never happen. It means the plural expression and the given maximum value do not match. */ index = 0; /* Skip INDEX strings at TRANSLATION. */ p = translation; while (index-- > 0) { #ifdef _LIBC p = __rawmemchr (p, '\0'); #else p = strchr (p, '\0'); #endif /* And skip over the NUL byte. */ p++; if (p >= translation + translation_len) /* This should never happen. It means the plural expression evaluated to a value larger than the number of variants available for MSGID1. */ return (char *) translation; } return (char *) p; } #ifndef _LIBC /* Return string representation of locale CATEGORY. */ static const char * internal_function category_to_name (int category) { const char *retval; switch (category) { #ifdef LC_COLLATE case LC_COLLATE: retval = "LC_COLLATE"; break; #endif #ifdef LC_CTYPE case LC_CTYPE: retval = "LC_CTYPE"; break; #endif #ifdef LC_MONETARY case LC_MONETARY: retval = "LC_MONETARY"; break; #endif #ifdef LC_NUMERIC case LC_NUMERIC: retval = "LC_NUMERIC"; break; #endif #ifdef LC_TIME case LC_TIME: retval = "LC_TIME"; break; #endif #ifdef LC_MESSAGES case LC_MESSAGES: retval = "LC_MESSAGES"; break; #endif #ifdef LC_RESPONSE case LC_RESPONSE: retval = "LC_RESPONSE"; break; #endif #ifdef LC_ALL case LC_ALL: /* This might not make sense but is perhaps better than any other value. */ retval = "LC_ALL"; break; #endif default: /* If you have a better idea for a default value let me know. */ retval = "LC_XXX"; } return retval; } #endif /* Guess value of current locale from value of the environment variables or system-dependent defaults. */ static const char * internal_function guess_category_value (int category, const char *categoryname) { const char *language; const char *locale; #ifndef _LIBC const char *language_default; int locale_defaulted; #endif /* We use the settings in the following order: 1. The value of the environment variable 'LANGUAGE'. This is a GNU extension. Its value can be a colon-separated list of locale names. 2. The value of the environment variable 'LC_ALL', 'LC_xxx', or 'LANG'. More precisely, the first among these that is set to a non-empty value. This is how POSIX specifies it. The value is a single locale name. 3. A system-dependent preference list of languages. Its value can be a colon-separated list of locale names. 4. A system-dependent default locale name. This way: - System-dependent settings can be overridden by environment variables. - If the system provides both a list of languages and a default locale, the former is used. */ /* Fetch the locale name, through the POSIX method of looking to `LC_ALL', `LC_xxx', and `LANG'. On some systems this can be done by the `setlocale' function itself. */ #ifdef _LIBC locale = __current_locale_name (category); #else locale = _nl_locale_name_posix (category, categoryname); locale_defaulted = 0; if (locale == NULL) { locale = _nl_locale_name_default (); locale_defaulted = 1; } #endif /* Ignore LANGUAGE and its system-dependent analogon if the locale is set to "C" because 1. "C" locale usually uses the ASCII encoding, and most international messages use non-ASCII characters. These characters get displayed as question marks (if using glibc's iconv()) or as invalid 8-bit characters (because other iconv()s refuse to convert most non-ASCII characters to ASCII). In any case, the output is ugly. 2. The precise output of some programs in the "C" locale is specified by POSIX and should not depend on environment variables like "LANGUAGE" or system-dependent information. We allow such programs to use gettext(). */ if (strcmp (locale, "C") == 0) return locale; /* The highest priority value is the value of the 'LANGUAGE' environment variable. */ language = getenv ("LANGUAGE"); if (language != NULL && language[0] != '\0') return language; #ifndef _LIBC /* The next priority value is the locale name, if not defaulted. */ if (locale_defaulted) { /* The next priority value is the default language preferences list. */ language_default = _nl_language_preferences_default (); if (language_default != NULL) return language_default; } /* The least priority value is the locale name, if defaulted. */ #endif return locale; } /* @@ begin of epilog @@ */ /* We don't want libintl.a to depend on any other library. So we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ #if !_LIBC && !HAVE_STPCPY static char * stpcpy (char *dest, const char *src) { while ((*dest++ = *src++) != '\0') /* Do nothing. */ ; return dest - 1; } #endif #if !_LIBC && !HAVE_MEMPCPY static void * mempcpy (void *dest, const void *src, size_t n) { return (void *) ((char *) memcpy (dest, src, n) + n); } #endif #ifdef _LIBC /* If we want to free all resources we have to do some work at program's end. */ libc_freeres_fn (free_mem) { void *old; while (_nl_domain_bindings != NULL) { struct binding *oldp = _nl_domain_bindings; _nl_domain_bindings = _nl_domain_bindings->next; if (oldp->dirname != INTUSE(_nl_default_dirname)) /* Yes, this is a pointer comparison. */ free (oldp->dirname); free (oldp->codeset); free (oldp); } if (_nl_current_default_domain != _nl_default_default_domain) /* Yes, again a pointer comparison. */ free ((char *) _nl_current_default_domain); /* Remove the search tree with the known translations. */ __tdestroy (root, free); root = NULL; while (transmem_list != NULL) { old = transmem_list; transmem_list = transmem_list->next; free (old); } } #endif lightspeed-1.2a.debian.1/intl/dcngettext.c000066400000000000000000000034741334064775200205330ustar00rootroot00000000000000/* Implementation of the dcngettext(3) function. Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DCNGETTEXT __dcngettext # define DCIGETTEXT __dcigettext #else # define DCNGETTEXT libintl_dcngettext # define DCIGETTEXT libintl_dcigettext #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ char * DCNGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { return DCIGETTEXT (domainname, msgid1, msgid2, 1, n, category); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dcngettext, dcngettext); #endif lightspeed-1.2a.debian.1/intl/dgettext.c000066400000000000000000000033711334064775200202060ustar00rootroot00000000000000/* Implementation of the dgettext(3) function. Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DGETTEXT __dgettext # define DCGETTEXT INTUSE(__dcgettext) #else # define DGETTEXT libintl_dgettext # define DCGETTEXT libintl_dcgettext #endif /* Look up MSGID in the DOMAINNAME message catalog of the current LC_MESSAGES locale. */ char * DGETTEXT (const char *domainname, const char *msgid) { return DCGETTEXT (domainname, msgid, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dgettext, dgettext); #endif lightspeed-1.2a.debian.1/intl/dngettext.c000066400000000000000000000035461334064775200203700ustar00rootroot00000000000000/* Implementation of the dngettext(3) function. Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define DNGETTEXT __dngettext # define DCNGETTEXT __dcngettext #else # define DNGETTEXT libintl_dngettext # define DCNGETTEXT libintl_dcngettext #endif /* Look up MSGID in the DOMAINNAME message catalog of the current LC_MESSAGES locale and skip message according to the plural form. */ char * DNGETTEXT (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { return DCNGETTEXT (domainname, msgid1, msgid2, n, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__dngettext, dngettext); #endif lightspeed-1.2a.debian.1/intl/eval-plural.h000066400000000000000000000053261334064775200206110ustar00rootroot00000000000000/* Plural expression evaluation. Copyright (C) 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef STATIC #define STATIC static #endif /* Evaluate the plural expression and return an index value. */ STATIC unsigned long int internal_function plural_eval (struct expression *pexp, unsigned long int n) { switch (pexp->nargs) { case 0: switch (pexp->operation) { case var: return n; case num: return pexp->val.num; default: break; } /* NOTREACHED */ break; case 1: { /* pexp->operation must be lnot. */ unsigned long int arg = plural_eval (pexp->val.args[0], n); return ! arg; } case 2: { unsigned long int leftarg = plural_eval (pexp->val.args[0], n); if (pexp->operation == lor) return leftarg || plural_eval (pexp->val.args[1], n); else if (pexp->operation == land) return leftarg && plural_eval (pexp->val.args[1], n); else { unsigned long int rightarg = plural_eval (pexp->val.args[1], n); switch (pexp->operation) { case mult: return leftarg * rightarg; case divide: #if !INTDIV0_RAISES_SIGFPE if (rightarg == 0) raise (SIGFPE); #endif return leftarg / rightarg; case module: #if !INTDIV0_RAISES_SIGFPE if (rightarg == 0) raise (SIGFPE); #endif return leftarg % rightarg; case plus: return leftarg + rightarg; case minus: return leftarg - rightarg; case less_than: return leftarg < rightarg; case greater_than: return leftarg > rightarg; case less_or_equal: return leftarg <= rightarg; case greater_or_equal: return leftarg >= rightarg; case equal: return leftarg == rightarg; case not_equal: return leftarg != rightarg; default: break; } } /* NOTREACHED */ break; } case 3: { /* pexp->operation must be qmop. */ unsigned long int boolarg = plural_eval (pexp->val.args[0], n); return plural_eval (pexp->val.args[boolarg ? 1 : 2], n); } } /* NOTREACHED */ return 0; } lightspeed-1.2a.debian.1/intl/explodename.c000066400000000000000000000106471334064775200206630ustar00rootroot00000000000000/* Copyright (C) 1995-1998, 2000-2001, 2003 Free Software Foundation, Inc. Contributed by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "loadinfo.h" /* On some strange systems still no definition of NULL is found. Sigh! */ #ifndef NULL # if defined __STDC__ && __STDC__ # define NULL ((void *) 0) # else # define NULL 0 # endif #endif /* @@ end of prolog @@ */ char * _nl_find_language (const char *name) { while (name[0] != '\0' && name[0] != '_' && name[0] != '@' && name[0] != '+' && name[0] != ',') ++name; return (char *) name; } int _nl_explode_name (char *name, const char **language, const char **modifier, const char **territory, const char **codeset, const char **normalized_codeset, const char **special, const char **sponsor, const char **revision) { enum { undecided, xpg, cen } syntax; char *cp; int mask; *modifier = NULL; *territory = NULL; *codeset = NULL; *normalized_codeset = NULL; *special = NULL; *sponsor = NULL; *revision = NULL; /* Now we determine the single parts of the locale name. First look for the language. Termination symbols are `_' and `@' if we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */ mask = 0; syntax = undecided; *language = cp = name; cp = _nl_find_language (*language); if (*language == cp) /* This does not make sense: language has to be specified. Use this entry as it is without exploding. Perhaps it is an alias. */ cp = strchr (*language, '\0'); else if (cp[0] == '_') { /* Next is the territory. */ cp[0] = '\0'; *territory = ++cp; while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@' && cp[0] != '+' && cp[0] != ',' && cp[0] != '_') ++cp; mask |= TERRITORY; if (cp[0] == '.') { /* Next is the codeset. */ syntax = xpg; cp[0] = '\0'; *codeset = ++cp; while (cp[0] != '\0' && cp[0] != '@') ++cp; mask |= XPG_CODESET; if (*codeset != cp && (*codeset)[0] != '\0') { *normalized_codeset = _nl_normalize_codeset (*codeset, cp - *codeset); if (strcmp (*codeset, *normalized_codeset) == 0) free ((char *) *normalized_codeset); else mask |= XPG_NORM_CODESET; } } } if (cp[0] == '@' || (syntax != xpg && cp[0] == '+')) { /* Next is the modifier. */ syntax = cp[0] == '@' ? xpg : cen; cp[0] = '\0'; *modifier = ++cp; while (syntax == cen && cp[0] != '\0' && cp[0] != '+' && cp[0] != ',' && cp[0] != '_') ++cp; mask |= XPG_MODIFIER | CEN_AUDIENCE; } if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_')) { syntax = cen; if (cp[0] == '+') { /* Next is special application (CEN syntax). */ cp[0] = '\0'; *special = ++cp; while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_') ++cp; mask |= CEN_SPECIAL; } if (cp[0] == ',') { /* Next is sponsor (CEN syntax). */ cp[0] = '\0'; *sponsor = ++cp; while (cp[0] != '\0' && cp[0] != '_') ++cp; mask |= CEN_SPONSOR; } if (cp[0] == '_') { /* Next is revision (CEN syntax). */ cp[0] = '\0'; *revision = ++cp; mask |= CEN_REVISION; } } /* For CEN syntax values it might be important to have the separator character in the file name, not for XPG syntax. */ if (syntax == xpg) { if (*territory != NULL && (*territory)[0] == '\0') mask &= ~TERRITORY; if (*codeset != NULL && (*codeset)[0] == '\0') mask &= ~XPG_CODESET; if (*modifier != NULL && (*modifier)[0] == '\0') mask &= ~XPG_MODIFIER; } return mask; } lightspeed-1.2a.debian.1/intl/finddomain.c000066400000000000000000000127471334064775200204750ustar00rootroot00000000000000/* Handle list of needed message catalogs Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc. Written by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* List of already loaded domains. */ static struct loaded_l10nfile *_nl_loaded_domains; /* Return a data structure describing the message catalog described by the DOMAINNAME and CATEGORY parameters with respect to the currently established bindings. */ struct loaded_l10nfile * internal_function _nl_find_domain (const char *dirname, char *locale, const char *domainname, struct binding *domainbinding) { struct loaded_l10nfile *retval; const char *language; const char *modifier; const char *territory; const char *codeset; const char *normalized_codeset; const char *special; const char *sponsor; const char *revision; const char *alias_value; int mask; /* LOCALE can consist of up to four recognized parts for the XPG syntax: language[_territory[.codeset]][@modifier] and six parts for the CEN syntax: language[_territory][+audience][+special][,[sponsor][_revision]] Beside the first part all of them are allowed to be missing. If the full specified locale is not found, the less specific one are looked for. The various parts will be stripped off according to the following order: (1) revision (2) sponsor (3) special (4) codeset (5) normalized codeset (6) territory (7) audience/modifier */ /* If we have already tested for this locale entry there has to be one data set in the list of loaded domains. */ retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, strlen (dirname) + 1, 0, locale, NULL, NULL, NULL, NULL, NULL, NULL, NULL, domainname, 0); if (retval != NULL) { /* We know something about this locale. */ int cnt; if (retval->decided == 0) _nl_load_domain (retval, domainbinding); if (retval->data != NULL) return retval; for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) { if (retval->successor[cnt]->decided == 0) _nl_load_domain (retval->successor[cnt], domainbinding); if (retval->successor[cnt]->data != NULL) break; } return cnt >= 0 ? retval : NULL; /* NOTREACHED */ } /* See whether the locale value is an alias. If yes its value *overwrites* the alias name. No test for the original value is done. */ alias_value = _nl_expand_alias (locale); if (alias_value != NULL) { #if defined _LIBC || defined HAVE_STRDUP locale = strdup (alias_value); if (locale == NULL) return NULL; #else size_t len = strlen (alias_value) + 1; locale = (char *) malloc (len); if (locale == NULL) return NULL; memcpy (locale, alias_value, len); #endif } /* Now we determine the single parts of the locale name. First look for the language. Termination symbols are `_' and `@' if we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */ mask = _nl_explode_name (locale, &language, &modifier, &territory, &codeset, &normalized_codeset, &special, &sponsor, &revision); /* Create all possible locale entries which might be interested in generalization. */ retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname, strlen (dirname) + 1, mask, language, territory, codeset, normalized_codeset, modifier, special, sponsor, revision, domainname, 1); if (retval == NULL) /* This means we are out of core. */ return NULL; if (retval->decided == 0) _nl_load_domain (retval, domainbinding); if (retval->data == NULL) { int cnt; for (cnt = 0; retval->successor[cnt] != NULL; ++cnt) { if (retval->successor[cnt]->decided == 0) _nl_load_domain (retval->successor[cnt], domainbinding); if (retval->successor[cnt]->data != NULL) break; } } /* The room for an alias was dynamically allocated. Free it now. */ if (alias_value != NULL) free (locale); /* The space for normalized_codeset is dynamically allocated. Free it. */ if (mask & XPG_NORM_CODESET) free ((void *) normalized_codeset); return retval; } #ifdef _LIBC libc_freeres_fn (free_mem) { struct loaded_l10nfile *runp = _nl_loaded_domains; while (runp != NULL) { struct loaded_l10nfile *here = runp; if (runp->data != NULL) _nl_unload_domain ((struct loaded_domain *) runp->data); runp = runp->next; free ((char *) here->filename); free (here); } } #endif lightspeed-1.2a.debian.1/intl/gettext.c000066400000000000000000000035541334064775200200450ustar00rootroot00000000000000/* Implementation of gettext(3) function. Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef _LIBC # define __need_NULL # include #else # include /* Just for NULL. */ #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define GETTEXT __gettext # define DCGETTEXT INTUSE(__dcgettext) #else # define GETTEXT libintl_gettext # define DCGETTEXT libintl_dcgettext #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ char * GETTEXT (const char *msgid) { return DCGETTEXT (NULL, msgid, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__gettext, gettext); #endif lightspeed-1.2a.debian.1/intl/gettextP.h000066400000000000000000000150111334064775200201610ustar00rootroot00000000000000/* Header describing internals of libintl library. Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc. Written by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GETTEXTP_H #define _GETTEXTP_H #include /* Get size_t. */ #ifdef _LIBC # include "../iconv/gconv_int.h" #else # if HAVE_ICONV # include # endif #endif #include "loadinfo.h" #include "gmo.h" /* Get nls_uint32. */ /* @@ end of prolog @@ */ #ifndef internal_function # define internal_function #endif #ifndef attribute_hidden # define attribute_hidden #endif /* Tell the compiler when a conditional or integer expression is almost always true or almost always false. */ #ifndef HAVE_BUILTIN_EXPECT # define __builtin_expect(expr, val) (expr) #endif #ifndef W # define W(flag, data) ((flag) ? SWAP (data) : (data)) #endif #ifdef _LIBC # include # define SWAP(i) bswap_32 (i) #else static inline nls_uint32 SWAP (i) nls_uint32 i; { return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24); } #endif /* In-memory representation of system dependent string. */ struct sysdep_string_desc { /* Length of addressed string, including the trailing NUL. */ size_t length; /* Pointer to addressed string. */ const char *pointer; }; /* The representation of an opened message catalog. */ struct loaded_domain { /* Pointer to memory containing the .mo file. */ const char *data; /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed. */ int use_mmap; /* Size of mmap()ed memory. */ size_t mmap_size; /* 1 if the .mo file uses a different endianness than this machine. */ int must_swap; /* Pointer to additional malloc()ed memory. */ void *malloced; /* Number of static strings pairs. */ nls_uint32 nstrings; /* Pointer to descriptors of original strings in the file. */ const struct string_desc *orig_tab; /* Pointer to descriptors of translated strings in the file. */ const struct string_desc *trans_tab; /* Number of system dependent strings pairs. */ nls_uint32 n_sysdep_strings; /* Pointer to descriptors of original sysdep strings. */ const struct sysdep_string_desc *orig_sysdep_tab; /* Pointer to descriptors of translated sysdep strings. */ const struct sysdep_string_desc *trans_sysdep_tab; /* Size of hash table. */ nls_uint32 hash_size; /* Pointer to hash table. */ const nls_uint32 *hash_tab; /* 1 if the hash table uses a different endianness than this machine. */ int must_swap_hash_tab; int codeset_cntr; #ifdef _LIBC __gconv_t conv; #else # if HAVE_ICONV iconv_t conv; # endif #endif char **conv_tab; struct expression *plural; unsigned long int nplurals; }; /* We want to allocate a string at the end of the struct. But ISO C doesn't allow zero sized arrays. */ #ifdef __GNUC__ # define ZERO 0 #else # define ZERO 1 #endif /* A set of settings bound to a message domain. Used to store settings from bindtextdomain() and bind_textdomain_codeset(). */ struct binding { struct binding *next; char *dirname; int codeset_cntr; /* Incremented each time codeset changes. */ char *codeset; char domainname[ZERO]; }; /* A counter which is incremented each time some previous translations become invalid. This variable is part of the external ABI of the GNU libintl. */ extern int _nl_msg_cat_cntr; #ifndef _LIBC const char *_nl_language_preferences_default (void); const char *_nl_locale_name_posix (int category, const char *categoryname); const char *_nl_locale_name_default (void); const char *_nl_locale_name (int category, const char *categoryname); #endif struct loaded_l10nfile *_nl_find_domain (const char *__dirname, char *__locale, const char *__domainname, struct binding *__domainbinding) internal_function; void _nl_load_domain (struct loaded_l10nfile *__domain, struct binding *__domainbinding) internal_function; void _nl_unload_domain (struct loaded_domain *__domain) internal_function; const char *_nl_init_domain_conv (struct loaded_l10nfile *__domain_file, struct loaded_domain *__domain, struct binding *__domainbinding) internal_function; void _nl_free_domain_conv (struct loaded_domain *__domain) internal_function; char *_nl_find_msg (struct loaded_l10nfile *domain_file, struct binding *domainbinding, const char *msgid, size_t *lengthp) internal_function; #ifdef _LIBC extern char *__gettext (const char *__msgid); extern char *__dgettext (const char *__domainname, const char *__msgid); extern char *__dcgettext (const char *__domainname, const char *__msgid, int __category); extern char *__ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n); extern char *__dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int n); extern char *__dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category); extern char *__dcigettext (const char *__domainname, const char *__msgid1, const char *__msgid2, int __plural, unsigned long int __n, int __category); extern char *__textdomain (const char *__domainname); extern char *__bindtextdomain (const char *__domainname, const char *__dirname); extern char *__bind_textdomain_codeset (const char *__domainname, const char *__codeset); #else /* Declare the exported libintl_* functions, in a way that allows us to call them under their real name. */ # undef _INTL_REDIRECT_INLINE # undef _INTL_REDIRECT_MACROS # define _INTL_REDIRECT_MACROS # include "libgnuintl.h" extern char *libintl_dcigettext (const char *__domainname, const char *__msgid1, const char *__msgid2, int __plural, unsigned long int __n, int __category); #endif /* @@ begin of epilog @@ */ #endif /* gettextP.h */ lightspeed-1.2a.debian.1/intl/gmo.h000066400000000000000000000113511334064775200171420ustar00rootroot00000000000000/* Description of GNU message catalog format: general file layout. Copyright (C) 1995, 1997, 2000-2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _GETTEXT_H #define _GETTEXT_H 1 #include /* @@ end of prolog @@ */ /* The magic number of the GNU message catalog format. */ #define _MAGIC 0x950412de #define _MAGIC_SWAPPED 0xde120495 /* Revision number of the currently used .mo (binary) file format. */ #define MO_REVISION_NUMBER 0 #define MO_REVISION_NUMBER_WITH_SYSDEP_I 1 /* The following contortions are an attempt to use the C preprocessor to determine an unsigned integral type that is 32 bits wide. An alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but as of version autoconf-2.13, the AC_CHECK_SIZEOF macro doesn't work when cross-compiling. */ #if __STDC__ # define UINT_MAX_32_BITS 4294967295U #else # define UINT_MAX_32_BITS 0xFFFFFFFF #endif /* If UINT_MAX isn't defined, assume it's a 32-bit type. This should be valid for all systems GNU cares about because that doesn't include 16-bit systems, and only modern systems (that certainly have ) have 64+-bit integral types. */ #ifndef UINT_MAX # define UINT_MAX UINT_MAX_32_BITS #endif #if UINT_MAX == UINT_MAX_32_BITS typedef unsigned nls_uint32; #else # if USHRT_MAX == UINT_MAX_32_BITS typedef unsigned short nls_uint32; # else # if ULONG_MAX == UINT_MAX_32_BITS typedef unsigned long nls_uint32; # else /* The following line is intended to throw an error. Using #error is not portable enough. */ "Cannot determine unsigned 32-bit data type." # endif # endif #endif /* Header for binary .mo file format. */ struct mo_file_header { /* The magic number. */ nls_uint32 magic; /* The revision number of the file format. */ nls_uint32 revision; /* The following are only used in .mo files with major revision 0 or 1. */ /* The number of strings pairs. */ nls_uint32 nstrings; /* Offset of table with start offsets of original strings. */ nls_uint32 orig_tab_offset; /* Offset of table with start offsets of translated strings. */ nls_uint32 trans_tab_offset; /* Size of hash table. */ nls_uint32 hash_tab_size; /* Offset of first hash table entry. */ nls_uint32 hash_tab_offset; /* The following are only used in .mo files with minor revision >= 1. */ /* The number of system dependent segments. */ nls_uint32 n_sysdep_segments; /* Offset of table describing system dependent segments. */ nls_uint32 sysdep_segments_offset; /* The number of system dependent strings pairs. */ nls_uint32 n_sysdep_strings; /* Offset of table with start offsets of original sysdep strings. */ nls_uint32 orig_sysdep_tab_offset; /* Offset of table with start offsets of translated sysdep strings. */ nls_uint32 trans_sysdep_tab_offset; }; /* Descriptor for static string contained in the binary .mo file. */ struct string_desc { /* Length of addressed string, not including the trailing NUL. */ nls_uint32 length; /* Offset of string in file. */ nls_uint32 offset; }; /* The following are only used in .mo files with minor revision >= 1. */ /* Descriptor for system dependent string segment. */ struct sysdep_segment { /* Length of addressed string, including the trailing NUL. */ nls_uint32 length; /* Offset of string in file. */ nls_uint32 offset; }; /* Descriptor for system dependent string. */ struct sysdep_string { /* Offset of static string segments in file. */ nls_uint32 offset; /* Alternating sequence of static and system dependent segments. The last segment is a static segment, including the trailing NUL. */ struct segment_pair { /* Size of static segment. */ nls_uint32 segsize; /* Reference to system dependent string segment, or ~0 at the end. */ nls_uint32 sysdepref; } segments[1]; }; /* Marker for the end of the segments[] array. This has the value 0xFFFFFFFF, regardless whether 'int' is 16 bit, 32 bit, or 64 bit. */ #define SEGMENTS_END ((nls_uint32) ~0) /* @@ begin of epilog @@ */ #endif /* gettext.h */ lightspeed-1.2a.debian.1/intl/hash-string.h000066400000000000000000000031451334064775200206110ustar00rootroot00000000000000/* Description of GNU message catalog format: string hashing function. Copyright (C) 1995, 1997-1998, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* @@ end of prolog @@ */ /* We assume to have `unsigned long int' value with at least 32 bits. */ #define HASHWORDBITS 32 /* Defines the so called `hashpjw' function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.] */ static inline unsigned long int hash_string (const char *str_param) { unsigned long int hval, g; const char *str = str_param; /* Compute the hash value for the given string. */ hval = 0; while (*str != '\0') { hval <<= 4; hval += (unsigned char) *str++; g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4)); if (g != 0) { hval ^= g >> (HASHWORDBITS - 8); hval ^= g; } } return hval; } lightspeed-1.2a.debian.1/intl/intl-compat.c000066400000000000000000000064471334064775200206140ustar00rootroot00000000000000/* intl-compat.c - Stub functions to call gettext functions from GNU gettext Library. Copyright (C) 1995, 2000-2003 Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include "gettextP.h" /* @@ end of prolog @@ */ /* This file redirects the gettext functions (without prefix) to those defined in the included GNU libintl library (with "libintl_" prefix). It is compiled into libintl in order to make the AM_GNU_GETTEXT test of gettext <= 0.11.2 work with the libintl library >= 0.11.3 which has the redirections primarily in the include file. It is also compiled into libgnuintl so that libgnuintl.so can be used as LD_PRELOADable library on glibc systems, to provide the extra features that the functions in the libc don't have (namely, logging). */ #undef gettext #undef dgettext #undef dcgettext #undef ngettext #undef dngettext #undef dcngettext #undef textdomain #undef bindtextdomain #undef bind_textdomain_codeset /* When building a DLL, we must export some functions. Note that because the functions are only defined for binary backward compatibility, we don't need to use __declspec(dllimport) in any case. */ #if defined _MSC_VER && BUILDING_DLL # define DLL_EXPORTED __declspec(dllexport) #else # define DLL_EXPORTED #endif DLL_EXPORTED char * gettext (const char *msgid) { return libintl_gettext (msgid); } DLL_EXPORTED char * dgettext (const char *domainname, const char *msgid) { return libintl_dgettext (domainname, msgid); } DLL_EXPORTED char * dcgettext (const char *domainname, const char *msgid, int category) { return libintl_dcgettext (domainname, msgid, category); } DLL_EXPORTED char * ngettext (const char *msgid1, const char *msgid2, unsigned long int n) { return libintl_ngettext (msgid1, msgid2, n); } DLL_EXPORTED char * dngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) { return libintl_dngettext (domainname, msgid1, msgid2, n); } DLL_EXPORTED char * dcngettext (const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) { return libintl_dcngettext (domainname, msgid1, msgid2, n, category); } DLL_EXPORTED char * textdomain (const char *domainname) { return libintl_textdomain (domainname); } DLL_EXPORTED char * bindtextdomain (const char *domainname, const char *dirname) { return libintl_bindtextdomain (domainname, dirname); } DLL_EXPORTED char * bind_textdomain_codeset (const char *domainname, const char *codeset) { return libintl_bind_textdomain_codeset (domainname, codeset); } lightspeed-1.2a.debian.1/intl/l10nflist.c000066400000000000000000000273721334064775200202010ustar00rootroot00000000000000/* Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc. Contributed by Ulrich Drepper , 1995. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for stpcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #if defined _LIBC || defined HAVE_ARGZ_H # include #endif #include #include #include #include "loadinfo.h" /* On some strange systems still no definition of NULL is found. Sigh! */ #ifndef NULL # if defined __STDC__ && __STDC__ # define NULL ((void *) 0) # else # define NULL 0 # endif #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # ifndef stpcpy # define stpcpy(dest, src) __stpcpy(dest, src) # endif #else # ifndef HAVE_STPCPY static char *stpcpy (char *dest, const char *src); # endif #endif /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not, it may be concatenated to a directory pathname. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P)) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0]) #endif /* Define function which are usually not available. */ #if !defined _LIBC && !defined HAVE___ARGZ_COUNT /* Returns the number of strings in ARGZ. */ static size_t argz_count__ (const char *argz, size_t len) { size_t count = 0; while (len > 0) { size_t part_len = strlen (argz); argz += part_len + 1; len -= part_len + 1; count++; } return count; } # undef __argz_count # define __argz_count(argz, len) argz_count__ (argz, len) #else # ifdef _LIBC # define __argz_count(argz, len) INTUSE(__argz_count) (argz, len) # endif #endif /* !_LIBC && !HAVE___ARGZ_COUNT */ #if !defined _LIBC && !defined HAVE___ARGZ_STRINGIFY /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's except the last into the character SEP. */ static void argz_stringify__ (char *argz, size_t len, int sep) { while (len > 0) { size_t part_len = strlen (argz); argz += part_len; len -= part_len + 1; if (len > 0) *argz++ = sep; } } # undef __argz_stringify # define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep) #else # ifdef _LIBC # define __argz_stringify(argz, len, sep) \ INTUSE(__argz_stringify) (argz, len, sep) # endif #endif /* !_LIBC && !HAVE___ARGZ_STRINGIFY */ #if !defined _LIBC && !defined HAVE___ARGZ_NEXT static char * argz_next__ (char *argz, size_t argz_len, const char *entry) { if (entry) { if (entry < argz + argz_len) entry = strchr (entry, '\0') + 1; return entry >= argz + argz_len ? NULL : (char *) entry; } else if (argz_len > 0) return argz; else return 0; } # undef __argz_next # define __argz_next(argz, len, entry) argz_next__ (argz, len, entry) #endif /* !_LIBC && !HAVE___ARGZ_NEXT */ /* Return number of bits set in X. */ static inline int pop (int x) { /* We assume that no more than 16 bits are used. */ x = ((x & ~0x5555) >> 1) + (x & 0x5555); x = ((x & ~0x3333) >> 2) + (x & 0x3333); x = ((x >> 4) + x) & 0x0f0f; x = ((x >> 8) + x) & 0xff; return x; } struct loaded_l10nfile * _nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list, const char *dirlist, size_t dirlist_len, int mask, const char *language, const char *territory, const char *codeset, const char *normalized_codeset, const char *modifier, const char *special, const char *sponsor, const char *revision, const char *filename, int do_allocate) { char *abs_filename; struct loaded_l10nfile **lastp; struct loaded_l10nfile *retval; char *cp; size_t dirlist_count; size_t entries; int cnt; /* If LANGUAGE contains an absolute directory specification, we ignore DIRLIST. */ if (IS_ABSOLUTE_PATH (language)) dirlist_len = 0; /* Allocate room for the full file name. */ abs_filename = (char *) malloc (dirlist_len + strlen (language) + ((mask & TERRITORY) != 0 ? strlen (territory) + 1 : 0) + ((mask & XPG_CODESET) != 0 ? strlen (codeset) + 1 : 0) + ((mask & XPG_NORM_CODESET) != 0 ? strlen (normalized_codeset) + 1 : 0) + (((mask & XPG_MODIFIER) != 0 || (mask & CEN_AUDIENCE) != 0) ? strlen (modifier) + 1 : 0) + ((mask & CEN_SPECIAL) != 0 ? strlen (special) + 1 : 0) + (((mask & CEN_SPONSOR) != 0 || (mask & CEN_REVISION) != 0) ? (1 + ((mask & CEN_SPONSOR) != 0 ? strlen (sponsor) : 0) + ((mask & CEN_REVISION) != 0 ? strlen (revision) + 1 : 0)) : 0) + 1 + strlen (filename) + 1); if (abs_filename == NULL) return NULL; /* Construct file name. */ cp = abs_filename; if (dirlist_len > 0) { memcpy (cp, dirlist, dirlist_len); __argz_stringify (cp, dirlist_len, PATH_SEPARATOR); cp += dirlist_len; cp[-1] = '/'; } cp = stpcpy (cp, language); if ((mask & TERRITORY) != 0) { *cp++ = '_'; cp = stpcpy (cp, territory); } if ((mask & XPG_CODESET) != 0) { *cp++ = '.'; cp = stpcpy (cp, codeset); } if ((mask & XPG_NORM_CODESET) != 0) { *cp++ = '.'; cp = stpcpy (cp, normalized_codeset); } if ((mask & (XPG_MODIFIER | CEN_AUDIENCE)) != 0) { /* This component can be part of both syntaces but has different leading characters. For CEN we use `+', else `@'. */ *cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@'; cp = stpcpy (cp, modifier); } if ((mask & CEN_SPECIAL) != 0) { *cp++ = '+'; cp = stpcpy (cp, special); } if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0) { *cp++ = ','; if ((mask & CEN_SPONSOR) != 0) cp = stpcpy (cp, sponsor); if ((mask & CEN_REVISION) != 0) { *cp++ = '_'; cp = stpcpy (cp, revision); } } *cp++ = '/'; stpcpy (cp, filename); /* Look in list of already loaded domains whether it is already available. */ lastp = l10nfile_list; for (retval = *l10nfile_list; retval != NULL; retval = retval->next) if (retval->filename != NULL) { int compare = strcmp (retval->filename, abs_filename); if (compare == 0) /* We found it! */ break; if (compare < 0) { /* It's not in the list. */ retval = NULL; break; } lastp = &retval->next; } if (retval != NULL || do_allocate == 0) { free (abs_filename); return retval; } dirlist_count = (dirlist_len > 0 ? __argz_count (dirlist, dirlist_len) : 1); /* Allocate a new loaded_l10nfile. */ retval = (struct loaded_l10nfile *) malloc (sizeof (*retval) + (((dirlist_count << pop (mask)) + (dirlist_count > 1 ? 1 : 0)) * sizeof (struct loaded_l10nfile *))); if (retval == NULL) return NULL; retval->filename = abs_filename; /* We set retval->data to NULL here; it is filled in later. Setting retval->decided to 1 here means that retval does not correspond to a real file (dirlist_count > 1) or is not worth looking up (if an unnormalized codeset was specified). */ retval->decided = (dirlist_count > 1 || ((mask & XPG_CODESET) != 0 && (mask & XPG_NORM_CODESET) != 0)); retval->data = NULL; retval->next = *lastp; *lastp = retval; entries = 0; /* Recurse to fill the inheritance list of RETVAL. If the DIRLIST is a real list (i.e. DIRLIST_COUNT > 1), the RETVAL entry does not correspond to a real file; retval->filename contains colons. In this case we loop across all elements of DIRLIST and across all bit patterns dominated by MASK. If the DIRLIST is a single directory or entirely redundant (i.e. DIRLIST_COUNT == 1), we loop across all bit patterns dominated by MASK, excluding MASK itself. In either case, we loop down from MASK to 0. This has the effect that the extra bits in the locale name are dropped in this order: first the modifier, then the territory, then the codeset, then the normalized_codeset. */ for (cnt = dirlist_count > 1 ? mask : mask - 1; cnt >= 0; --cnt) if ((cnt & ~mask) == 0 && ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0) && ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 0)) { if (dirlist_count > 1) { /* Iterate over all elements of the DIRLIST. */ char *dir = NULL; while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir)) != NULL) retval->successor[entries++] = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt, language, territory, codeset, normalized_codeset, modifier, special, sponsor, revision, filename, 1); } else retval->successor[entries++] = _nl_make_l10nflist (l10nfile_list, dirlist, dirlist_len, cnt, language, territory, codeset, normalized_codeset, modifier, special, sponsor, revision, filename, 1); } retval->successor[entries] = NULL; return retval; } /* Normalize codeset name. There is no standard for the codeset names. Normalization allows the user to use any of the common names. The return value is dynamically allocated and has to be freed by the caller. */ const char * _nl_normalize_codeset (const char *codeset, size_t name_len) { int len = 0; int only_digit = 1; char *retval; char *wp; size_t cnt; for (cnt = 0; cnt < name_len; ++cnt) if (isalnum ((unsigned char) codeset[cnt])) { ++len; if (isalpha ((unsigned char) codeset[cnt])) only_digit = 0; } retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1); if (retval != NULL) { if (only_digit) wp = stpcpy (retval, "iso"); else wp = retval; for (cnt = 0; cnt < name_len; ++cnt) if (isalpha ((unsigned char) codeset[cnt])) *wp++ = tolower ((unsigned char) codeset[cnt]); else if (isdigit ((unsigned char) codeset[cnt])) *wp++ = codeset[cnt]; *wp = '\0'; } return (const char *) retval; } /* @@ begin of epilog @@ */ /* We don't want libintl.a to depend on any other library. So we avoid the non-standard function stpcpy. In GNU C Library this function is available, though. Also allow the symbol HAVE_STPCPY to be defined. */ #if !_LIBC && !HAVE_STPCPY static char * stpcpy (char *dest, const char *src) { while ((*dest++ = *src++) != '\0') /* Do nothing. */ ; return dest - 1; } #endif lightspeed-1.2a.debian.1/intl/langprefs.c000066400000000000000000000073011334064775200203340ustar00rootroot00000000000000/* Determine the user's language preferences. Copyright (C) 2004-2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif #include #if HAVE_CFPREFERENCESCOPYAPPVALUE # include # include # include # include # include extern void _nl_locale_name_canonicalize (char *name); #endif /* Determine the user's language preferences, as a colon separated list of locale names in XPG syntax language[_territory[.codeset]][@modifier] The result must not be freed; it is statically allocated. The LANGUAGE environment variable does not need to be considered; it is already taken into account by the caller. */ const char * _nl_language_preferences_default (void) { #if HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ { /* Cache the preferences list, since CoreFoundation calls are expensive. */ static const char *cached_languages; static int cache_initialized; if (!cache_initialized) { CFTypeRef preferences = CFPreferencesCopyAppValue (CFSTR ("AppleLanguages"), kCFPreferencesCurrentApplication); if (preferences != NULL && CFGetTypeID (preferences) == CFArrayGetTypeID ()) { CFArrayRef prefArray = (CFArrayRef)preferences; int n = CFArrayGetCount (prefArray); char buf[256]; size_t size = 0; int i; for (i = 0; i < n; i++) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); if (element != NULL && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (buf); size += strlen (buf) + 1; /* Most GNU programs use msgids in English and don't ship an en.mo message catalog. Therefore when we see "en" in the preferences list, arrange for gettext() to return the msgid, and ignore all further elements of the preferences list. */ if (strcmp (buf, "en") == 0) break; } else break; } if (size > 0) { char *languages = (char *) malloc (size); if (languages != NULL) { char *p = languages; for (i = 0; i < n; i++) { CFTypeRef element = CFArrayGetValueAtIndex (prefArray, i); if (element != NULL && CFGetTypeID (element) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)element, buf, sizeof (buf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (buf); strcpy (p, buf); p += strlen (buf); *p++ = ':'; if (strcmp (buf, "en") == 0) break; } else break; } *--p = '\0'; cached_languages = languages; } } } cache_initialized = 1; } if (cached_languages != NULL) return cached_languages; } #endif return NULL; } lightspeed-1.2a.debian.1/intl/libgnuintl.h.in000066400000000000000000000311721334064775200211370ustar00rootroot00000000000000/* Message catalogs for internationalization. Copyright (C) 1995-1997, 2000-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LIBINTL_H #define _LIBINTL_H 1 #include /* The LC_MESSAGES locale category is the category used by the functions gettext() and dgettext(). It is specified in POSIX, but not in ANSI C. On systems that don't define it, use an arbitrary value instead. On Solaris, defines __LOCALE_H (or _LOCALE_H in Solaris 2.5) then includes (i.e. this file!) and then only defines LC_MESSAGES. To avoid a redefinition warning, don't define LC_MESSAGES in this case. */ #if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun)) # define LC_MESSAGES 1729 #endif /* We define an additional symbol to signal that we use the GNU implementation of gettext. */ #define __USE_GNU_GETTEXT 1 /* Provide information about the supported file formats. Returns the maximum minor revision number supported for a given major revision. */ #define __GNU_GETTEXT_SUPPORTED_REVISION(major) \ ((major) == 0 || (major) == 1 ? 1 : -1) /* Resolve a platform specific conflict on DJGPP. GNU gettext takes precedence over _conio_gettext. */ #ifdef __DJGPP__ # undef gettext #endif #ifdef __cplusplus extern "C" { #endif /* We redirect the functions to those prefixed with "libintl_". This is necessary, because some systems define gettext/textdomain/... in the C library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer). If we used the unprefixed names, there would be cases where the definition in the C library would override the one in the libintl.so shared library. Recall that on ELF systems, the symbols are looked up in the following order: 1. in the executable, 2. in the shared libraries specified on the link command line, in order, 3. in the dependencies of the shared libraries specified on the link command line, 4. in the dlopen()ed shared libraries, in the order in which they were dlopen()ed. The definition in the C library would override the one in libintl.so if either * -lc is given on the link command line and -lintl isn't, or * -lc is given on the link command line before -lintl, or * libintl.so is a dependency of a dlopen()ed shared library but not linked to the executable at link time. Since Solaris gettext() behaves differently than GNU gettext(), this would be unacceptable. The redirection happens by default through macros in C, so that &gettext is independent of the compilation unit, but through inline functions in C++, in order not to interfere with the name mangling of class fields or class methods called 'gettext'. */ /* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS. If he doesn't, we choose the method. A third possible method is _INTL_REDIRECT_ASM, supported only by GCC. */ #if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS) # if __GNUC__ >= 2 && !defined __APPLE_CC__ && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus) # define _INTL_REDIRECT_ASM # else # ifdef __cplusplus # define _INTL_REDIRECT_INLINE # else # define _INTL_REDIRECT_MACROS # endif # endif #endif /* Auxiliary macros. */ #ifdef _INTL_REDIRECT_ASM # define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname)) # define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring # define _INTL_STRINGIFY(prefix) #prefix #else # define _INTL_ASM(cname) #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_gettext (const char *__msgid); static inline char *gettext (const char *__msgid) { return libintl_gettext (__msgid); } #else #ifdef _INTL_REDIRECT_MACROS # define gettext libintl_gettext #endif extern char *gettext (const char *__msgid) _INTL_ASM (libintl_gettext); #endif /* Look up MSGID in the DOMAINNAME message catalog for the current LC_MESSAGES locale. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dgettext (const char *__domainname, const char *__msgid); static inline char *dgettext (const char *__domainname, const char *__msgid) { return libintl_dgettext (__domainname, __msgid); } #else #ifdef _INTL_REDIRECT_MACROS # define dgettext libintl_dgettext #endif extern char *dgettext (const char *__domainname, const char *__msgid) _INTL_ASM (libintl_dgettext); #endif /* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY locale. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcgettext (const char *__domainname, const char *__msgid, int __category); static inline char *dcgettext (const char *__domainname, const char *__msgid, int __category) { return libintl_dcgettext (__domainname, __msgid, __category); } #else #ifdef _INTL_REDIRECT_MACROS # define dcgettext libintl_dcgettext #endif extern char *dcgettext (const char *__domainname, const char *__msgid, int __category) _INTL_ASM (libintl_dcgettext); #endif /* Similar to `gettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n); static inline char *ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n) { return libintl_ngettext (__msgid1, __msgid2, __n); } #else #ifdef _INTL_REDIRECT_MACROS # define ngettext libintl_ngettext #endif extern char *ngettext (const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_ASM (libintl_ngettext); #endif /* Similar to `dgettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n); static inline char *dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n) { return libintl_dngettext (__domainname, __msgid1, __msgid2, __n); } #else #ifdef _INTL_REDIRECT_MACROS # define dngettext libintl_dngettext #endif extern char *dngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n) _INTL_ASM (libintl_dngettext); #endif /* Similar to `dcgettext' but select the plural form corresponding to the number N. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category); static inline char *dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category) { return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category); } #else #ifdef _INTL_REDIRECT_MACROS # define dcngettext libintl_dcngettext #endif extern char *dcngettext (const char *__domainname, const char *__msgid1, const char *__msgid2, unsigned long int __n, int __category) _INTL_ASM (libintl_dcngettext); #endif /* Set the current default message catalog to DOMAINNAME. If DOMAINNAME is null, return the current default. If DOMAINNAME is "", reset to the default of "messages". */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_textdomain (const char *__domainname); static inline char *textdomain (const char *__domainname) { return libintl_textdomain (__domainname); } #else #ifdef _INTL_REDIRECT_MACROS # define textdomain libintl_textdomain #endif extern char *textdomain (const char *__domainname) _INTL_ASM (libintl_textdomain); #endif /* Specify that the DOMAINNAME message catalog will be found in DIRNAME rather than in the system locale data base. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bindtextdomain (const char *__domainname, const char *__dirname); static inline char *bindtextdomain (const char *__domainname, const char *__dirname) { return libintl_bindtextdomain (__domainname, __dirname); } #else #ifdef _INTL_REDIRECT_MACROS # define bindtextdomain libintl_bindtextdomain #endif extern char *bindtextdomain (const char *__domainname, const char *__dirname) _INTL_ASM (libintl_bindtextdomain); #endif /* Specify the character encoding in which the messages from the DOMAINNAME message catalog will be returned. */ #ifdef _INTL_REDIRECT_INLINE extern char *libintl_bind_textdomain_codeset (const char *__domainname, const char *__codeset); static inline char *bind_textdomain_codeset (const char *__domainname, const char *__codeset) { return libintl_bind_textdomain_codeset (__domainname, __codeset); } #else #ifdef _INTL_REDIRECT_MACROS # define bind_textdomain_codeset libintl_bind_textdomain_codeset #endif extern char *bind_textdomain_codeset (const char *__domainname, const char *__codeset) _INTL_ASM (libintl_bind_textdomain_codeset); #endif /* Support for format strings with positions in *printf(), following the POSIX/XSI specification. Note: These replacements for the *printf() functions are visible only in source files that #include or #include "gettext.h". Packages that use *printf() in source files that don't refer to _() or gettext() but for which the format string could be the return value of _() or gettext() need to add this #include. Oh well. */ #if !@HAVE_POSIX_PRINTF@ #include #include /* Get va_list. */ #if __STDC__ || defined __cplusplus || defined _MSC_VER # include #else # include #endif #undef fprintf #define fprintf libintl_fprintf extern int fprintf (FILE *, const char *, ...); #undef vfprintf #define vfprintf libintl_vfprintf extern int vfprintf (FILE *, const char *, va_list); #undef printf #define printf libintl_printf extern int printf (const char *, ...); #undef vprintf #define vprintf libintl_vprintf extern int vprintf (const char *, va_list); #undef sprintf #define sprintf libintl_sprintf extern int sprintf (char *, const char *, ...); #undef vsprintf #define vsprintf libintl_vsprintf extern int vsprintf (char *, const char *, va_list); #if @HAVE_SNPRINTF@ #undef snprintf #define snprintf libintl_snprintf extern int snprintf (char *, size_t, const char *, ...); #undef vsnprintf #define vsnprintf libintl_vsnprintf extern int vsnprintf (char *, size_t, const char *, va_list); #endif #if @HAVE_ASPRINTF@ #undef asprintf #define asprintf libintl_asprintf extern int asprintf (char **, const char *, ...); #undef vasprintf #define vasprintf libintl_vasprintf extern int vasprintf (char **, const char *, va_list); #endif #if @HAVE_WPRINTF@ #undef fwprintf #define fwprintf libintl_fwprintf extern int fwprintf (FILE *, const wchar_t *, ...); #undef vfwprintf #define vfwprintf libintl_vfwprintf extern int vfwprintf (FILE *, const wchar_t *, va_list); #undef wprintf #define wprintf libintl_wprintf extern int wprintf (const wchar_t *, ...); #undef vwprintf #define vwprintf libintl_vwprintf extern int vwprintf (const wchar_t *, va_list); #undef swprintf #define swprintf libintl_swprintf extern int swprintf (wchar_t *, size_t, const wchar_t *, ...); #undef vswprintf #define vswprintf libintl_vswprintf extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list); #endif #endif /* Support for relocatable packages. */ /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ #define libintl_set_relocation_prefix libintl_set_relocation_prefix extern void libintl_set_relocation_prefix (const char *orig_prefix, const char *curr_prefix); #ifdef __cplusplus } #endif #endif /* libintl.h */ lightspeed-1.2a.debian.1/intl/loadinfo.h000066400000000000000000000133261334064775200201570ustar00rootroot00000000000000/* Copyright (C) 1996-1999, 2000-2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LOADINFO_H #define _LOADINFO_H 1 /* Declarations of locale dependent catalog lookup functions. Implemented in localealias.c Possibly replace a locale name by another. explodename.c Split a locale name into its various fields. l10nflist.c Generate a list of filenames of possible message catalogs. finddomain.c Find and open the relevant message catalogs. The main function _nl_find_domain() in finddomain.c is declared in gettextP.h. */ #ifndef internal_function # define internal_function #endif /* Tell the compiler when a conditional or integer expression is almost always true or almost always false. */ #ifndef HAVE_BUILTIN_EXPECT # define __builtin_expect(expr, val) (expr) #endif /* Separator in PATH like lists of pathnames. */ #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__ /* Win32, OS/2, DOS */ # define PATH_SEPARATOR ';' #else /* Unix */ # define PATH_SEPARATOR ':' #endif /* Encoding of locale name parts. */ #define CEN_REVISION 1 #define CEN_SPONSOR 2 #define CEN_SPECIAL 4 #define XPG_NORM_CODESET 8 #define XPG_CODESET 16 #define TERRITORY 32 #define CEN_AUDIENCE 64 #define XPG_MODIFIER 128 #define CEN_SPECIFIC (CEN_REVISION|CEN_SPONSOR|CEN_SPECIAL|CEN_AUDIENCE) #define XPG_SPECIFIC (XPG_CODESET|XPG_NORM_CODESET|XPG_MODIFIER) struct loaded_l10nfile { const char *filename; int decided; const void *data; struct loaded_l10nfile *next; struct loaded_l10nfile *successor[1]; }; /* Normalize codeset name. There is no standard for the codeset names. Normalization allows the user to use any of the common names. The return value is dynamically allocated and has to be freed by the caller. */ extern const char *_nl_normalize_codeset (const char *codeset, size_t name_len); /* Lookup a locale dependent file. *L10NFILE_LIST denotes a pool of lookup results of locale dependent files of the same kind, sorted in decreasing order of ->filename. DIRLIST and DIRLIST_LEN are an argz list of directories in which to look, containing at least one directory (i.e. DIRLIST_LEN > 0). MASK, LANGUAGE, TERRITORY, CODESET, NORMALIZED_CODESET, MODIFIER, SPECIAL, SPONSOR, REVISION are the pieces of the locale name, as produced by _nl_explode_name(). FILENAME is the filename suffix. The return value is the lookup result, either found in *L10NFILE_LIST, or - if DO_ALLOCATE is nonzero - freshly allocated, or possibly NULL. If the return value is non-NULL, it is added to *L10NFILE_LIST, and its ->next field denotes the chaining inside *L10NFILE_LIST, and furthermore its ->successor[] field contains a list of other lookup results from which this lookup result inherits. */ extern struct loaded_l10nfile * _nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list, const char *dirlist, size_t dirlist_len, int mask, const char *language, const char *territory, const char *codeset, const char *normalized_codeset, const char *modifier, const char *special, const char *sponsor, const char *revision, const char *filename, int do_allocate); /* Lookup the real locale name for a locale alias NAME, or NULL if NAME is not a locale alias (but possibly a real locale name). The return value is statically allocated and must not be freed. */ extern const char *_nl_expand_alias (const char *name); /* Split a locale name NAME into its pieces: language, modifier, territory, codeset, special, sponsor, revision. NAME gets destructively modified: NUL bytes are inserted here and there. *LANGUAGE gets assigned NAME. Each of *MODIFIER, *TERRITORY, *CODESET, *SPECIAL, *SPONSOR, *REVISION gets assigned either a pointer into the old NAME string, or NULL. *NORMALIZED_CODESET gets assigned the expanded *CODESET, if it is different from *CODESET; this one is dynamically allocated and has to be freed by the caller. The return value is a bitmask, where each bit corresponds to one filled-in value: XPG_MODIFIER, CEN_AUDIENCE for *MODIFIER, TERRITORY for *TERRITORY, XPG_CODESET for *CODESET, XPG_NORM_CODESET for *NORMALIZED_CODESET, CEN_SPECIAL for *SPECIAL, CEN_SPONSOR for *SPONSOR, CEN_REVISION for *REVISION. */ extern int _nl_explode_name (char *name, const char **language, const char **modifier, const char **territory, const char **codeset, const char **normalized_codeset, const char **special, const char **sponsor, const char **revision); /* Split a locale name NAME into a leading language part and all the rest. Return a pointer to the first character after the language, i.e. to the first byte of the rest. */ extern char *_nl_find_language (const char *name); #endif /* loadinfo.h */ lightspeed-1.2a.debian.1/intl/loadmsgcat.c000066400000000000000000001072431334064775200204770ustar00rootroot00000000000000/* Load needed message catalogs. Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include #include #ifdef __GNUC__ # undef alloca # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #include #if defined HAVE_UNISTD_H || defined _LIBC # include #endif #ifdef _LIBC # include # include #endif #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \ || (defined _LIBC && defined _POSIX_MAPPED_FILES) # include # undef HAVE_MMAP # define HAVE_MMAP 1 #else # undef HAVE_MMAP #endif #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC # include #endif #if defined HAVE_INTTYPES_H || defined _LIBC # include #endif #include "gmo.h" #include "gettextP.h" #include "hash-string.h" #include "plural-exp.h" #ifdef _LIBC # include "../locale/localeinfo.h" #endif /* Provide fallback values for macros that ought to be defined in . Note that our fallback values need not be literal strings, because we don't use them with preprocessor string concatenation. */ #if !defined PRId8 || PRI_MACROS_BROKEN # undef PRId8 # define PRId8 "d" #endif #if !defined PRIi8 || PRI_MACROS_BROKEN # undef PRIi8 # define PRIi8 "i" #endif #if !defined PRIo8 || PRI_MACROS_BROKEN # undef PRIo8 # define PRIo8 "o" #endif #if !defined PRIu8 || PRI_MACROS_BROKEN # undef PRIu8 # define PRIu8 "u" #endif #if !defined PRIx8 || PRI_MACROS_BROKEN # undef PRIx8 # define PRIx8 "x" #endif #if !defined PRIX8 || PRI_MACROS_BROKEN # undef PRIX8 # define PRIX8 "X" #endif #if !defined PRId16 || PRI_MACROS_BROKEN # undef PRId16 # define PRId16 "d" #endif #if !defined PRIi16 || PRI_MACROS_BROKEN # undef PRIi16 # define PRIi16 "i" #endif #if !defined PRIo16 || PRI_MACROS_BROKEN # undef PRIo16 # define PRIo16 "o" #endif #if !defined PRIu16 || PRI_MACROS_BROKEN # undef PRIu16 # define PRIu16 "u" #endif #if !defined PRIx16 || PRI_MACROS_BROKEN # undef PRIx16 # define PRIx16 "x" #endif #if !defined PRIX16 || PRI_MACROS_BROKEN # undef PRIX16 # define PRIX16 "X" #endif #if !defined PRId32 || PRI_MACROS_BROKEN # undef PRId32 # define PRId32 "d" #endif #if !defined PRIi32 || PRI_MACROS_BROKEN # undef PRIi32 # define PRIi32 "i" #endif #if !defined PRIo32 || PRI_MACROS_BROKEN # undef PRIo32 # define PRIo32 "o" #endif #if !defined PRIu32 || PRI_MACROS_BROKEN # undef PRIu32 # define PRIu32 "u" #endif #if !defined PRIx32 || PRI_MACROS_BROKEN # undef PRIx32 # define PRIx32 "x" #endif #if !defined PRIX32 || PRI_MACROS_BROKEN # undef PRIX32 # define PRIX32 "X" #endif #if !defined PRId64 || PRI_MACROS_BROKEN # undef PRId64 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld") #endif #if !defined PRIi64 || PRI_MACROS_BROKEN # undef PRIi64 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli") #endif #if !defined PRIo64 || PRI_MACROS_BROKEN # undef PRIo64 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo") #endif #if !defined PRIu64 || PRI_MACROS_BROKEN # undef PRIu64 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu") #endif #if !defined PRIx64 || PRI_MACROS_BROKEN # undef PRIx64 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx") #endif #if !defined PRIX64 || PRI_MACROS_BROKEN # undef PRIX64 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX") #endif #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN # undef PRIdLEAST8 # define PRIdLEAST8 "d" #endif #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN # undef PRIiLEAST8 # define PRIiLEAST8 "i" #endif #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN # undef PRIoLEAST8 # define PRIoLEAST8 "o" #endif #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN # undef PRIuLEAST8 # define PRIuLEAST8 "u" #endif #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN # undef PRIxLEAST8 # define PRIxLEAST8 "x" #endif #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN # undef PRIXLEAST8 # define PRIXLEAST8 "X" #endif #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN # undef PRIdLEAST16 # define PRIdLEAST16 "d" #endif #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN # undef PRIiLEAST16 # define PRIiLEAST16 "i" #endif #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN # undef PRIoLEAST16 # define PRIoLEAST16 "o" #endif #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN # undef PRIuLEAST16 # define PRIuLEAST16 "u" #endif #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN # undef PRIxLEAST16 # define PRIxLEAST16 "x" #endif #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN # undef PRIXLEAST16 # define PRIXLEAST16 "X" #endif #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN # undef PRIdLEAST32 # define PRIdLEAST32 "d" #endif #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN # undef PRIiLEAST32 # define PRIiLEAST32 "i" #endif #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN # undef PRIoLEAST32 # define PRIoLEAST32 "o" #endif #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN # undef PRIuLEAST32 # define PRIuLEAST32 "u" #endif #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN # undef PRIxLEAST32 # define PRIxLEAST32 "x" #endif #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN # undef PRIXLEAST32 # define PRIXLEAST32 "X" #endif #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN # undef PRIdLEAST64 # define PRIdLEAST64 PRId64 #endif #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN # undef PRIiLEAST64 # define PRIiLEAST64 PRIi64 #endif #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN # undef PRIoLEAST64 # define PRIoLEAST64 PRIo64 #endif #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN # undef PRIuLEAST64 # define PRIuLEAST64 PRIu64 #endif #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN # undef PRIxLEAST64 # define PRIxLEAST64 PRIx64 #endif #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN # undef PRIXLEAST64 # define PRIXLEAST64 PRIX64 #endif #if !defined PRIdFAST8 || PRI_MACROS_BROKEN # undef PRIdFAST8 # define PRIdFAST8 "d" #endif #if !defined PRIiFAST8 || PRI_MACROS_BROKEN # undef PRIiFAST8 # define PRIiFAST8 "i" #endif #if !defined PRIoFAST8 || PRI_MACROS_BROKEN # undef PRIoFAST8 # define PRIoFAST8 "o" #endif #if !defined PRIuFAST8 || PRI_MACROS_BROKEN # undef PRIuFAST8 # define PRIuFAST8 "u" #endif #if !defined PRIxFAST8 || PRI_MACROS_BROKEN # undef PRIxFAST8 # define PRIxFAST8 "x" #endif #if !defined PRIXFAST8 || PRI_MACROS_BROKEN # undef PRIXFAST8 # define PRIXFAST8 "X" #endif #if !defined PRIdFAST16 || PRI_MACROS_BROKEN # undef PRIdFAST16 # define PRIdFAST16 "d" #endif #if !defined PRIiFAST16 || PRI_MACROS_BROKEN # undef PRIiFAST16 # define PRIiFAST16 "i" #endif #if !defined PRIoFAST16 || PRI_MACROS_BROKEN # undef PRIoFAST16 # define PRIoFAST16 "o" #endif #if !defined PRIuFAST16 || PRI_MACROS_BROKEN # undef PRIuFAST16 # define PRIuFAST16 "u" #endif #if !defined PRIxFAST16 || PRI_MACROS_BROKEN # undef PRIxFAST16 # define PRIxFAST16 "x" #endif #if !defined PRIXFAST16 || PRI_MACROS_BROKEN # undef PRIXFAST16 # define PRIXFAST16 "X" #endif #if !defined PRIdFAST32 || PRI_MACROS_BROKEN # undef PRIdFAST32 # define PRIdFAST32 "d" #endif #if !defined PRIiFAST32 || PRI_MACROS_BROKEN # undef PRIiFAST32 # define PRIiFAST32 "i" #endif #if !defined PRIoFAST32 || PRI_MACROS_BROKEN # undef PRIoFAST32 # define PRIoFAST32 "o" #endif #if !defined PRIuFAST32 || PRI_MACROS_BROKEN # undef PRIuFAST32 # define PRIuFAST32 "u" #endif #if !defined PRIxFAST32 || PRI_MACROS_BROKEN # undef PRIxFAST32 # define PRIxFAST32 "x" #endif #if !defined PRIXFAST32 || PRI_MACROS_BROKEN # undef PRIXFAST32 # define PRIXFAST32 "X" #endif #if !defined PRIdFAST64 || PRI_MACROS_BROKEN # undef PRIdFAST64 # define PRIdFAST64 PRId64 #endif #if !defined PRIiFAST64 || PRI_MACROS_BROKEN # undef PRIiFAST64 # define PRIiFAST64 PRIi64 #endif #if !defined PRIoFAST64 || PRI_MACROS_BROKEN # undef PRIoFAST64 # define PRIoFAST64 PRIo64 #endif #if !defined PRIuFAST64 || PRI_MACROS_BROKEN # undef PRIuFAST64 # define PRIuFAST64 PRIu64 #endif #if !defined PRIxFAST64 || PRI_MACROS_BROKEN # undef PRIxFAST64 # define PRIxFAST64 PRIx64 #endif #if !defined PRIXFAST64 || PRI_MACROS_BROKEN # undef PRIXFAST64 # define PRIXFAST64 PRIX64 #endif #if !defined PRIdMAX || PRI_MACROS_BROKEN # undef PRIdMAX # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld") #endif #if !defined PRIiMAX || PRI_MACROS_BROKEN # undef PRIiMAX # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli") #endif #if !defined PRIoMAX || PRI_MACROS_BROKEN # undef PRIoMAX # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo") #endif #if !defined PRIuMAX || PRI_MACROS_BROKEN # undef PRIuMAX # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu") #endif #if !defined PRIxMAX || PRI_MACROS_BROKEN # undef PRIxMAX # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx") #endif #if !defined PRIXMAX || PRI_MACROS_BROKEN # undef PRIXMAX # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX") #endif #if !defined PRIdPTR || PRI_MACROS_BROKEN # undef PRIdPTR # define PRIdPTR \ (sizeof (void *) == sizeof (long) ? "ld" : \ sizeof (void *) == sizeof (int) ? "d" : \ "lld") #endif #if !defined PRIiPTR || PRI_MACROS_BROKEN # undef PRIiPTR # define PRIiPTR \ (sizeof (void *) == sizeof (long) ? "li" : \ sizeof (void *) == sizeof (int) ? "i" : \ "lli") #endif #if !defined PRIoPTR || PRI_MACROS_BROKEN # undef PRIoPTR # define PRIoPTR \ (sizeof (void *) == sizeof (long) ? "lo" : \ sizeof (void *) == sizeof (int) ? "o" : \ "llo") #endif #if !defined PRIuPTR || PRI_MACROS_BROKEN # undef PRIuPTR # define PRIuPTR \ (sizeof (void *) == sizeof (long) ? "lu" : \ sizeof (void *) == sizeof (int) ? "u" : \ "llu") #endif #if !defined PRIxPTR || PRI_MACROS_BROKEN # undef PRIxPTR # define PRIxPTR \ (sizeof (void *) == sizeof (long) ? "lx" : \ sizeof (void *) == sizeof (int) ? "x" : \ "llx") #endif #if !defined PRIXPTR || PRI_MACROS_BROKEN # undef PRIXPTR # define PRIXPTR \ (sizeof (void *) == sizeof (long) ? "lX" : \ sizeof (void *) == sizeof (int) ? "X" : \ "llX") #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ISO C functions. This is required by the standard because some ISO C functions will require linking with this object file and the name space must not be polluted. */ # define open __open # define close __close # define read __read # define mmap __mmap # define munmap __munmap #endif /* For those losing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA # define freea(p) /* nothing */ #else # define alloca(n) malloc (n) # define freea(p) free (p) #endif /* For systems that distinguish between text and binary I/O. O_BINARY is usually declared in . */ #if !defined O_BINARY && defined _O_BINARY /* For MSC-compatible compilers. */ # define O_BINARY _O_BINARY # define O_TEXT _O_TEXT #endif #ifdef __BEOS__ /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ # undef O_BINARY # undef O_TEXT #endif /* On reasonable systems, binary I/O is the default. */ #ifndef O_BINARY # define O_BINARY 0 #endif /* We need a sign, whether a new catalog was loaded, which can be associated with all translations. This is important if the translations are cached by one of GCC's features. */ int _nl_msg_cat_cntr; /* Expand a system dependent string segment. Return NULL if unsupported. */ static const char * get_sysdep_segment_value (const char *name) { /* Test for an ISO C 99 section 7.8.1 format string directive. Syntax: P R I { d | i | o | u | x | X } { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */ /* We don't use a table of 14 times 6 'const char *' strings here, because data relocations cost startup time. */ if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I') { if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u' || name[3] == 'x' || name[3] == 'X') { if (name[4] == '8' && name[5] == '\0') { if (name[3] == 'd') return PRId8; if (name[3] == 'i') return PRIi8; if (name[3] == 'o') return PRIo8; if (name[3] == 'u') return PRIu8; if (name[3] == 'x') return PRIx8; if (name[3] == 'X') return PRIX8; abort (); } if (name[4] == '1' && name[5] == '6' && name[6] == '\0') { if (name[3] == 'd') return PRId16; if (name[3] == 'i') return PRIi16; if (name[3] == 'o') return PRIo16; if (name[3] == 'u') return PRIu16; if (name[3] == 'x') return PRIx16; if (name[3] == 'X') return PRIX16; abort (); } if (name[4] == '3' && name[5] == '2' && name[6] == '\0') { if (name[3] == 'd') return PRId32; if (name[3] == 'i') return PRIi32; if (name[3] == 'o') return PRIo32; if (name[3] == 'u') return PRIu32; if (name[3] == 'x') return PRIx32; if (name[3] == 'X') return PRIX32; abort (); } if (name[4] == '6' && name[5] == '4' && name[6] == '\0') { if (name[3] == 'd') return PRId64; if (name[3] == 'i') return PRIi64; if (name[3] == 'o') return PRIo64; if (name[3] == 'u') return PRIu64; if (name[3] == 'x') return PRIx64; if (name[3] == 'X') return PRIX64; abort (); } if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A' && name[7] == 'S' && name[8] == 'T') { if (name[9] == '8' && name[10] == '\0') { if (name[3] == 'd') return PRIdLEAST8; if (name[3] == 'i') return PRIiLEAST8; if (name[3] == 'o') return PRIoLEAST8; if (name[3] == 'u') return PRIuLEAST8; if (name[3] == 'x') return PRIxLEAST8; if (name[3] == 'X') return PRIXLEAST8; abort (); } if (name[9] == '1' && name[10] == '6' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST16; if (name[3] == 'i') return PRIiLEAST16; if (name[3] == 'o') return PRIoLEAST16; if (name[3] == 'u') return PRIuLEAST16; if (name[3] == 'x') return PRIxLEAST16; if (name[3] == 'X') return PRIXLEAST16; abort (); } if (name[9] == '3' && name[10] == '2' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST32; if (name[3] == 'i') return PRIiLEAST32; if (name[3] == 'o') return PRIoLEAST32; if (name[3] == 'u') return PRIuLEAST32; if (name[3] == 'x') return PRIxLEAST32; if (name[3] == 'X') return PRIXLEAST32; abort (); } if (name[9] == '6' && name[10] == '4' && name[11] == '\0') { if (name[3] == 'd') return PRIdLEAST64; if (name[3] == 'i') return PRIiLEAST64; if (name[3] == 'o') return PRIoLEAST64; if (name[3] == 'u') return PRIuLEAST64; if (name[3] == 'x') return PRIxLEAST64; if (name[3] == 'X') return PRIXLEAST64; abort (); } } if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S' && name[7] == 'T') { if (name[8] == '8' && name[9] == '\0') { if (name[3] == 'd') return PRIdFAST8; if (name[3] == 'i') return PRIiFAST8; if (name[3] == 'o') return PRIoFAST8; if (name[3] == 'u') return PRIuFAST8; if (name[3] == 'x') return PRIxFAST8; if (name[3] == 'X') return PRIXFAST8; abort (); } if (name[8] == '1' && name[9] == '6' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST16; if (name[3] == 'i') return PRIiFAST16; if (name[3] == 'o') return PRIoFAST16; if (name[3] == 'u') return PRIuFAST16; if (name[3] == 'x') return PRIxFAST16; if (name[3] == 'X') return PRIXFAST16; abort (); } if (name[8] == '3' && name[9] == '2' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST32; if (name[3] == 'i') return PRIiFAST32; if (name[3] == 'o') return PRIoFAST32; if (name[3] == 'u') return PRIuFAST32; if (name[3] == 'x') return PRIxFAST32; if (name[3] == 'X') return PRIXFAST32; abort (); } if (name[8] == '6' && name[9] == '4' && name[10] == '\0') { if (name[3] == 'd') return PRIdFAST64; if (name[3] == 'i') return PRIiFAST64; if (name[3] == 'o') return PRIoFAST64; if (name[3] == 'u') return PRIuFAST64; if (name[3] == 'x') return PRIxFAST64; if (name[3] == 'X') return PRIXFAST64; abort (); } } if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X' && name[7] == '\0') { if (name[3] == 'd') return PRIdMAX; if (name[3] == 'i') return PRIiMAX; if (name[3] == 'o') return PRIoMAX; if (name[3] == 'u') return PRIuMAX; if (name[3] == 'x') return PRIxMAX; if (name[3] == 'X') return PRIXMAX; abort (); } if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R' && name[7] == '\0') { if (name[3] == 'd') return PRIdPTR; if (name[3] == 'i') return PRIiPTR; if (name[3] == 'o') return PRIoPTR; if (name[3] == 'u') return PRIuPTR; if (name[3] == 'x') return PRIxPTR; if (name[3] == 'X') return PRIXPTR; abort (); } } } /* Test for a glibc specific printf() format directive flag. */ if (name[0] == 'I' && name[1] == '\0') { #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) /* The 'I' flag, in numeric format directives, replaces ASCII digits with the 'outdigits' defined in the LC_CTYPE locale facet. This is used for Farsi (Persian) and maybe Arabic. */ return "I"; #else return ""; #endif } /* Other system dependent strings are not valid. */ return NULL; } /* Initialize the codeset dependent parts of an opened message catalog. Return the header entry. */ const char * internal_function _nl_init_domain_conv (struct loaded_l10nfile *domain_file, struct loaded_domain *domain, struct binding *domainbinding) { /* Find out about the character set the file is encoded with. This can be found (in textual form) in the entry "". If this entry does not exist or if this does not contain the `charset=' information, we will assume the charset matches the one the current locale and we don't have to perform any conversion. */ char *nullentry; size_t nullentrylen; /* Preinitialize fields, to avoid recursion during _nl_find_msg. */ domain->codeset_cntr = (domainbinding != NULL ? domainbinding->codeset_cntr : 0); #ifdef _LIBC domain->conv = (__gconv_t) -1; #else # if HAVE_ICONV domain->conv = (iconv_t) -1; # endif #endif domain->conv_tab = NULL; /* Get the header entry. */ nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen); if (nullentry != NULL) { #if defined _LIBC || HAVE_ICONV const char *charsetstr; charsetstr = strstr (nullentry, "charset="); if (charsetstr != NULL) { size_t len; char *charset; const char *outcharset; charsetstr += strlen ("charset="); len = strcspn (charsetstr, " \t\n"); charset = (char *) alloca (len + 1); # if defined _LIBC || HAVE_MEMPCPY *((char *) mempcpy (charset, charsetstr, len)) = '\0'; # else memcpy (charset, charsetstr, len); charset[len] = '\0'; # endif /* The output charset should normally be determined by the locale. But sometimes the locale is not used or not correctly set up, so we provide a possibility for the user to override this. Moreover, the value specified through bind_textdomain_codeset overrides both. */ if (domainbinding != NULL && domainbinding->codeset != NULL) outcharset = domainbinding->codeset; else { outcharset = getenv ("OUTPUT_CHARSET"); if (outcharset == NULL || outcharset[0] == '\0') { # ifdef _LIBC outcharset = _NL_CURRENT (LC_CTYPE, CODESET); # else # if HAVE_ICONV extern const char *locale_charset (void); outcharset = locale_charset (); # endif # endif } } # ifdef _LIBC /* We always want to use transliteration. */ outcharset = norm_add_slashes (outcharset, "TRANSLIT"); charset = norm_add_slashes (charset, NULL); if (__gconv_open (outcharset, charset, &domain->conv, GCONV_AVOID_NOCONV) != __GCONV_OK) domain->conv = (__gconv_t) -1; # else # if HAVE_ICONV /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5, we want to use transliteration. */ # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ || _LIBICONV_VERSION >= 0x0105 if (strchr (outcharset, '/') == NULL) { char *tmp; len = strlen (outcharset); tmp = (char *) alloca (len + 10 + 1); memcpy (tmp, outcharset, len); memcpy (tmp + len, "//TRANSLIT", 10 + 1); outcharset = tmp; domain->conv = iconv_open (outcharset, charset); freea (outcharset); } else # endif domain->conv = iconv_open (outcharset, charset); # endif # endif freea (charset); } #endif /* _LIBC || HAVE_ICONV */ } return nullentry; } /* Frees the codeset dependent parts of an opened message catalog. */ void internal_function _nl_free_domain_conv (struct loaded_domain *domain) { if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1) free (domain->conv_tab); #ifdef _LIBC if (domain->conv != (__gconv_t) -1) __gconv_close (domain->conv); #else # if HAVE_ICONV if (domain->conv != (iconv_t) -1) iconv_close (domain->conv); # endif #endif } /* Load the message catalogs specified by FILENAME. If it is no valid message catalog do nothing. */ void internal_function _nl_load_domain (struct loaded_l10nfile *domain_file, struct binding *domainbinding) { int fd; size_t size; #ifdef _LIBC struct stat64 st; #else struct stat st; #endif struct mo_file_header *data = (struct mo_file_header *) -1; int use_mmap = 0; struct loaded_domain *domain; int revision; const char *nullentry; domain_file->decided = 1; domain_file->data = NULL; /* Note that it would be useless to store domainbinding in domain_file because domainbinding might be == NULL now but != NULL later (after a call to bind_textdomain_codeset). */ /* If the record does not represent a valid locale the FILENAME might be NULL. This can happen when according to the given specification the locale file name is different for XPG and CEN syntax. */ if (domain_file->filename == NULL) return; /* Try to open the addressed file. */ fd = open (domain_file->filename, O_RDONLY | O_BINARY); if (fd == -1) return; /* We must know about the size of the file. */ if ( #ifdef _LIBC __builtin_expect (fstat64 (fd, &st) != 0, 0) #else __builtin_expect (fstat (fd, &st) != 0, 0) #endif || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0) || __builtin_expect (size < sizeof (struct mo_file_header), 0)) { /* Something went wrong. */ close (fd); return; } #ifdef HAVE_MMAP /* Now we are ready to load the file. If mmap() is available we try this first. If not available or it failed we try to load it. */ data = (struct mo_file_header *) mmap (NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); if (__builtin_expect (data != (struct mo_file_header *) -1, 1)) { /* mmap() call was successful. */ close (fd); use_mmap = 1; } #endif /* If the data is not yet available (i.e. mmap'ed) we try to load it manually. */ if (data == (struct mo_file_header *) -1) { size_t to_read; char *read_ptr; data = (struct mo_file_header *) malloc (size); if (data == NULL) return; to_read = size; read_ptr = (char *) data; do { long int nb = (long int) read (fd, read_ptr, to_read); if (nb <= 0) { #ifdef EINTR if (nb == -1 && errno == EINTR) continue; #endif close (fd); return; } read_ptr += nb; to_read -= nb; } while (to_read > 0); close (fd); } /* Using the magic number we can test whether it really is a message catalog file. */ if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED, 0)) { /* The magic number is wrong: not a message catalog file. */ #ifdef HAVE_MMAP if (use_mmap) munmap ((caddr_t) data, size); else #endif free (data); return; } domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain)); if (domain == NULL) return; domain_file->data = domain; domain->data = (char *) data; domain->use_mmap = use_mmap; domain->mmap_size = size; domain->must_swap = data->magic != _MAGIC; domain->malloced = NULL; /* Fill in the information about the available tables. */ revision = W (domain->must_swap, data->revision); /* We support only the major revisions 0 and 1. */ switch (revision >> 16) { case 0: case 1: domain->nstrings = W (domain->must_swap, data->nstrings); domain->orig_tab = (const struct string_desc *) ((char *) data + W (domain->must_swap, data->orig_tab_offset)); domain->trans_tab = (const struct string_desc *) ((char *) data + W (domain->must_swap, data->trans_tab_offset)); domain->hash_size = W (domain->must_swap, data->hash_tab_size); domain->hash_tab = (domain->hash_size > 2 ? (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->hash_tab_offset)) : NULL); domain->must_swap_hash_tab = domain->must_swap; /* Now dispatch on the minor revision. */ switch (revision & 0xffff) { case 0: domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; break; case 1: default: { nls_uint32 n_sysdep_strings; if (domain->hash_tab == NULL) /* This is invalid. These minor revisions need a hash table. */ goto invalid; n_sysdep_strings = W (domain->must_swap, data->n_sysdep_strings); if (n_sysdep_strings > 0) { nls_uint32 n_sysdep_segments; const struct sysdep_segment *sysdep_segments; const char **sysdep_segment_values; const nls_uint32 *orig_sysdep_tab; const nls_uint32 *trans_sysdep_tab; nls_uint32 n_inmem_sysdep_strings; size_t memneed; char *mem; struct sysdep_string_desc *inmem_orig_sysdep_tab; struct sysdep_string_desc *inmem_trans_sysdep_tab; nls_uint32 *inmem_hash_tab; unsigned int i, j; /* Get the values of the system dependent segments. */ n_sysdep_segments = W (domain->must_swap, data->n_sysdep_segments); sysdep_segments = (const struct sysdep_segment *) ((char *) data + W (domain->must_swap, data->sysdep_segments_offset)); sysdep_segment_values = alloca (n_sysdep_segments * sizeof (const char *)); for (i = 0; i < n_sysdep_segments; i++) { const char *name = (char *) data + W (domain->must_swap, sysdep_segments[i].offset); nls_uint32 namelen = W (domain->must_swap, sysdep_segments[i].length); if (!(namelen > 0 && name[namelen - 1] == '\0')) { freea (sysdep_segment_values); goto invalid; } sysdep_segment_values[i] = get_sysdep_segment_value (name); } orig_sysdep_tab = (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->orig_sysdep_tab_offset)); trans_sysdep_tab = (const nls_uint32 *) ((char *) data + W (domain->must_swap, data->trans_sysdep_tab_offset)); /* Compute the amount of additional memory needed for the system dependent strings and the augmented hash table. At the same time, also drop string pairs which refer to an undefined system dependent segment. */ n_inmem_sysdep_strings = 0; memneed = domain->hash_size * sizeof (nls_uint32); for (i = 0; i < n_sysdep_strings; i++) { int valid = 1; size_t needs[2]; for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); size_t need = 0; const struct segment_pair *p = sysdep_string->segments; if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END) for (p = sysdep_string->segments;; p++) { nls_uint32 sysdepref; need += W (domain->must_swap, p->segsize); sysdepref = W (domain->must_swap, p->sysdepref); if (sysdepref == SEGMENTS_END) break; if (sysdepref >= n_sysdep_segments) { /* Invalid. */ freea (sysdep_segment_values); goto invalid; } if (sysdep_segment_values[sysdepref] == NULL) { /* This particular string pair is invalid. */ valid = 0; break; } need += strlen (sysdep_segment_values[sysdepref]); } needs[j] = need; if (!valid) break; } if (valid) { n_inmem_sysdep_strings++; memneed += needs[0] + needs[1]; } } memneed += 2 * n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); if (n_inmem_sysdep_strings > 0) { unsigned int k; /* Allocate additional memory. */ mem = (char *) malloc (memneed); if (mem == NULL) goto invalid; domain->malloced = mem; inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem; mem += n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem; mem += n_inmem_sysdep_strings * sizeof (struct sysdep_string_desc); inmem_hash_tab = (nls_uint32 *) mem; mem += domain->hash_size * sizeof (nls_uint32); /* Compute the system dependent strings. */ k = 0; for (i = 0; i < n_sysdep_strings; i++) { int valid = 1; for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); const struct segment_pair *p = sysdep_string->segments; if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END) for (p = sysdep_string->segments;; p++) { nls_uint32 sysdepref; sysdepref = W (domain->must_swap, p->sysdepref); if (sysdepref == SEGMENTS_END) break; if (sysdep_segment_values[sysdepref] == NULL) { /* This particular string pair is invalid. */ valid = 0; break; } } if (!valid) break; } if (valid) { for (j = 0; j < 2; j++) { const struct sysdep_string *sysdep_string = (const struct sysdep_string *) ((char *) data + W (domain->must_swap, j == 0 ? orig_sysdep_tab[i] : trans_sysdep_tab[i])); const char *static_segments = (char *) data + W (domain->must_swap, sysdep_string->offset); const struct segment_pair *p = sysdep_string->segments; /* Concatenate the segments, and fill inmem_orig_sysdep_tab[k] (for j == 0) and inmem_trans_sysdep_tab[k] (for j == 1). */ struct sysdep_string_desc *inmem_tab_entry = (j == 0 ? inmem_orig_sysdep_tab : inmem_trans_sysdep_tab) + k; if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END) { /* Only one static segment. */ inmem_tab_entry->length = W (domain->must_swap, p->segsize); inmem_tab_entry->pointer = static_segments; } else { inmem_tab_entry->pointer = mem; for (p = sysdep_string->segments;; p++) { nls_uint32 segsize = W (domain->must_swap, p->segsize); nls_uint32 sysdepref = W (domain->must_swap, p->sysdepref); size_t n; if (segsize > 0) { memcpy (mem, static_segments, segsize); mem += segsize; static_segments += segsize; } if (sysdepref == SEGMENTS_END) break; n = strlen (sysdep_segment_values[sysdepref]); memcpy (mem, sysdep_segment_values[sysdepref], n); mem += n; } inmem_tab_entry->length = mem - inmem_tab_entry->pointer; } } k++; } } if (k != n_inmem_sysdep_strings) abort (); /* Compute the augmented hash table. */ for (i = 0; i < domain->hash_size; i++) inmem_hash_tab[i] = W (domain->must_swap_hash_tab, domain->hash_tab[i]); for (i = 0; i < n_inmem_sysdep_strings; i++) { const char *msgid = inmem_orig_sysdep_tab[i].pointer; nls_uint32 hash_val = hash_string (msgid); nls_uint32 idx = hash_val % domain->hash_size; nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2)); for (;;) { if (inmem_hash_tab[idx] == 0) { /* Hash table entry is empty. Use it. */ inmem_hash_tab[idx] = 1 + domain->nstrings + i; break; } if (idx >= domain->hash_size - incr) idx -= domain->hash_size - incr; else idx += incr; } } domain->n_sysdep_strings = n_inmem_sysdep_strings; domain->orig_sysdep_tab = inmem_orig_sysdep_tab; domain->trans_sysdep_tab = inmem_trans_sysdep_tab; domain->hash_tab = inmem_hash_tab; domain->must_swap_hash_tab = 0; } else { domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; } freea (sysdep_segment_values); } else { domain->n_sysdep_strings = 0; domain->orig_sysdep_tab = NULL; domain->trans_sysdep_tab = NULL; } } break; } break; default: /* This is an invalid revision. */ invalid: /* This is an invalid .mo file. */ if (domain->malloced) free (domain->malloced); #ifdef HAVE_MMAP if (use_mmap) munmap ((caddr_t) data, size); else #endif free (data); free (domain); domain_file->data = NULL; return; } /* Now initialize the character set converter from the character set the file is encoded with (found in the header entry) to the domain's specified character set or the locale's character set. */ nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding); /* Also look for a plural specification. */ EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals); } #ifdef _LIBC void internal_function _nl_unload_domain (struct loaded_domain *domain) { if (domain->plural != &__gettext_germanic_plural) __gettext_free_exp (domain->plural); _nl_free_domain_conv (domain); if (domain->malloced) free (domain->malloced); # ifdef _POSIX_MAPPED_FILES if (domain->use_mmap) munmap ((caddr_t) domain->data, domain->mmap_size); else # endif /* _POSIX_MAPPED_FILES */ free ((void *) domain->data); free (domain); } #endif lightspeed-1.2a.debian.1/intl/localcharset.c000066400000000000000000000251651334064775200210270ustar00rootroot00000000000000/* Determine a canonical name for the current locale's character encoding. Copyright (C) 2000-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif /* Specification. */ #include "localcharset.h" #if HAVE_STDDEF_H # include #endif #include #if HAVE_STRING_H # include #else # include #endif #if HAVE_STDLIB_H # include #endif #if defined _WIN32 || defined __WIN32__ # undef WIN32 /* avoid warning on mingw32 */ # define WIN32 #endif #if defined __EMX__ /* Assume EMX program runs on OS/2, even if compiled under DOS. */ # define OS2 #endif #if !defined WIN32 # if HAVE_LANGINFO_CODESET # include # else # if HAVE_SETLOCALE # include # endif # endif #elif defined WIN32 # define WIN32_LEAN_AND_MEAN # include #endif #if defined OS2 # define INCL_DOS # include #endif #if ENABLE_RELOCATABLE # include "relocatable.h" #else # define relocate(pathname) (pathname) #endif #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') #endif #ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' #endif #ifndef ISSLASH # define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) #endif #if HAVE_DECL_GETC_UNLOCKED # undef getc # define getc getc_unlocked #endif /* The following static variable is declared 'volatile' to avoid a possible multithread problem in the function get_charset_aliases. If we are running in a threaded environment, and if two threads initialize 'charset_aliases' simultaneously, both will produce the same value, and everything will be ok if the two assignments to 'charset_aliases' are atomic. But I don't know what will happen if the two assignments mix. */ #if __STDC__ != 1 # define volatile /* empty */ #endif /* Pointer to the contents of the charset.alias file, if it has already been read, else NULL. Its format is: ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */ static const char * volatile charset_aliases; /* Return a pointer to the contents of the charset.alias file. */ static const char * get_charset_aliases () { const char *cp; cp = charset_aliases; if (cp == NULL) { #if !(defined VMS || defined WIN32) FILE *fp; const char *dir; const char *base = "charset.alias"; char *file_name; /* Make it possible to override the charset.alias location. This is necessary for running the testsuite before "make install". */ dir = getenv ("CHARSETALIASDIR"); if (dir == NULL || dir[0] == '\0') dir = relocate (LIBDIR); /* Concatenate dir and base into freshly allocated file_name. */ { size_t dir_len = strlen (dir); size_t base_len = strlen (base); int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); file_name = (char *) malloc (dir_len + add_slash + base_len + 1); if (file_name != NULL) { memcpy (file_name, dir, dir_len); if (add_slash) file_name[dir_len] = DIRECTORY_SEPARATOR; memcpy (file_name + dir_len + add_slash, base, base_len + 1); } } if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) /* Out of memory or file not found, treat it as empty. */ cp = ""; else { /* Parse the file's contents. */ char *res_ptr = NULL; size_t res_size = 0; for (;;) { int c; char buf1[50+1]; char buf2[50+1]; size_t l1, l2; char *old_res_ptr; c = getc (fp); if (c == EOF) break; if (c == '\n' || c == ' ' || c == '\t') continue; if (c == '#') { /* Skip comment, to end of line. */ do c = getc (fp); while (!(c == EOF || c == '\n')); if (c == EOF) break; continue; } ungetc (c, fp); if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) break; l1 = strlen (buf1); l2 = strlen (buf2); old_res_ptr = res_ptr; if (res_size == 0) { res_size = l1 + 1 + l2 + 1; res_ptr = (char *) malloc (res_size + 1); } else { res_size += l1 + 1 + l2 + 1; res_ptr = (char *) realloc (res_ptr, res_size + 1); } if (res_ptr == NULL) { /* Out of memory. */ res_size = 0; if (old_res_ptr != NULL) free (old_res_ptr); break; } strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); strcpy (res_ptr + res_size - (l2 + 1), buf2); } fclose (fp); if (res_size == 0) cp = ""; else { *(res_ptr + res_size) = '\0'; cp = res_ptr; } } if (file_name != NULL) free (file_name); #else # if defined VMS /* To avoid the troubles of an extra file charset.alias_vms in the sources of many GNU packages, simply inline the aliases here. */ /* The list of encodings is taken from the OpenVMS 7.3-1 documentation "Compaq C Run-Time Library Reference Manual for OpenVMS systems" section 10.7 "Handling Different Character Sets". */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" "ISO8859-2" "\0" "ISO-8859-2" "\0" "ISO8859-5" "\0" "ISO-8859-5" "\0" "ISO8859-7" "\0" "ISO-8859-7" "\0" "ISO8859-8" "\0" "ISO-8859-8" "\0" "ISO8859-9" "\0" "ISO-8859-9" "\0" /* Japanese */ "eucJP" "\0" "EUC-JP" "\0" "SJIS" "\0" "SHIFT_JIS" "\0" "DECKANJI" "\0" "DEC-KANJI" "\0" "SDECKANJI" "\0" "EUC-JP" "\0" /* Chinese */ "eucTW" "\0" "EUC-TW" "\0" "DECHANYU" "\0" "DEC-HANYU" "\0" "DECHANZI" "\0" "GB2312" "\0" /* Korean */ "DECKOREAN" "\0" "EUC-KR" "\0"; # endif # if defined WIN32 /* To avoid the troubles of installing a separate file in the same directory as the DLL and of retrieving the DLL's directory at runtime, simply inline the aliases here. */ cp = "CP936" "\0" "GBK" "\0" "CP1361" "\0" "JOHAB" "\0" "CP20127" "\0" "ASCII" "\0" "CP20866" "\0" "KOI8-R" "\0" "CP21866" "\0" "KOI8-RU" "\0" "CP28591" "\0" "ISO-8859-1" "\0" "CP28592" "\0" "ISO-8859-2" "\0" "CP28593" "\0" "ISO-8859-3" "\0" "CP28594" "\0" "ISO-8859-4" "\0" "CP28595" "\0" "ISO-8859-5" "\0" "CP28596" "\0" "ISO-8859-6" "\0" "CP28597" "\0" "ISO-8859-7" "\0" "CP28598" "\0" "ISO-8859-8" "\0" "CP28599" "\0" "ISO-8859-9" "\0" "CP28605" "\0" "ISO-8859-15" "\0"; # endif #endif charset_aliases = cp; } return cp; } /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed in config.charset. The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ #ifdef STATIC STATIC #endif const char * locale_charset () { const char *codeset; const char *aliases; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo (CODESET) nowadays. */ codeset = nl_langinfo (CODESET); # else /* On old systems which lack it, use setlocale or getenv. */ const char *locale = NULL; /* But most old systems don't have a complete set of locales. Some (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't use setlocale here; it would return "C" when it doesn't support the locale name the user has set. */ # if HAVE_SETLOCALE && 0 locale = setlocale (LC_CTYPE, NULL); # endif if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } } /* On some old systems, one used to set locale = "iso8859_1". On others, you set it to "language_COUNTRY.charset". In any case, we resolve it through the charset.alias file. */ codeset = locale; # endif #elif defined WIN32 static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; #elif defined OS2 const char *locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, with standard language environment variables. */ locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { /* If the locale name contains an encoding after the dot, return it. */ const char *dot = strchr (locale, '.'); if (dot != NULL) { const char *modifier; dot++; /* Look for the possible @... trailer and remove it, if any. */ modifier = strchr (dot, '@'); if (modifier == NULL) return dot; if (modifier - dot < sizeof (buf)) { memcpy (buf, dot, modifier - dot); buf [modifier - dot] = '\0'; return buf; } } /* Resolve through the charset.alias file. */ codeset = locale; } else { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) codeset = ""; else { sprintf (buf, "CP%u", cp[0]); codeset = buf; } } #endif if (codeset == NULL) /* The canonical name cannot be determined. */ codeset = ""; /* Resolve alias. */ for (aliases = get_charset_aliases (); *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 || (aliases[0] == '*' && aliases[1] == '\0')) { codeset = aliases + strlen (aliases) + 1; break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') codeset = "ASCII"; return codeset; } lightspeed-1.2a.debian.1/intl/localcharset.h000066400000000000000000000025631334064775200210310ustar00rootroot00000000000000/* Determine a canonical name for the current locale's character encoding. Copyright (C) 2000-2003 Free Software Foundation, Inc. This file is part of the GNU CHARSET Library. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _LOCALCHARSET_H #define _LOCALCHARSET_H #ifdef __cplusplus extern "C" { #endif /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed in config.charset. The result must not be freed; it is statically allocated. If the canonical name cannot be determined, the result is a non-canonical name. */ extern const char * locale_charset (void); #ifdef __cplusplus } #endif #endif /* _LOCALCHARSET_H */ lightspeed-1.2a.debian.1/intl/locale.alias000066400000000000000000000051261334064775200204640ustar00rootroot00000000000000# Locale name alias data base. # Copyright (C) 1996-2001,2003 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # The format of this file is the same as for the corresponding file of # the X Window System, which normally can be found in # /usr/lib/X11/locale/locale.alias # A single line contains two fields: an alias and a substitution value. # All entries are case independent. # Note: This file is far from being complete. If you have a value for # your own site which you think might be useful for others too, share # it with the rest of us. Send it using the `glibcbug' script to # bugs@gnu.org. # Packages using this file: bokmal nb_NO.ISO-8859-1 bokmål nb_NO.ISO-8859-1 catalan ca_ES.ISO-8859-1 croatian hr_HR.ISO-8859-2 czech cs_CZ.ISO-8859-2 danish da_DK.ISO-8859-1 dansk da_DK.ISO-8859-1 deutsch de_DE.ISO-8859-1 dutch nl_NL.ISO-8859-1 eesti et_EE.ISO-8859-1 estonian et_EE.ISO-8859-1 finnish fi_FI.ISO-8859-1 français fr_FR.ISO-8859-1 french fr_FR.ISO-8859-1 galego gl_ES.ISO-8859-1 galician gl_ES.ISO-8859-1 german de_DE.ISO-8859-1 greek el_GR.ISO-8859-7 hebrew he_IL.ISO-8859-8 hrvatski hr_HR.ISO-8859-2 hungarian hu_HU.ISO-8859-2 icelandic is_IS.ISO-8859-1 italian it_IT.ISO-8859-1 japanese ja_JP.eucJP japanese.euc ja_JP.eucJP ja_JP ja_JP.eucJP ja_JP.ujis ja_JP.eucJP japanese.sjis ja_JP.SJIS korean ko_KR.eucKR korean.euc ko_KR.eucKR ko_KR ko_KR.eucKR lithuanian lt_LT.ISO-8859-13 no_NO nb_NO.ISO-8859-1 no_NO.ISO-8859-1 nb_NO.ISO-8859-1 norwegian nb_NO.ISO-8859-1 nynorsk nn_NO.ISO-8859-1 polish pl_PL.ISO-8859-2 portuguese pt_PT.ISO-8859-1 romanian ro_RO.ISO-8859-2 russian ru_RU.ISO-8859-5 slovak sk_SK.ISO-8859-2 slovene sl_SI.ISO-8859-2 slovenian sl_SI.ISO-8859-2 spanish es_ES.ISO-8859-1 swedish sv_SE.ISO-8859-1 thai th_TH.TIS-620 turkish tr_TR.ISO-8859-9 lightspeed-1.2a.debian.1/intl/localealias.c000066400000000000000000000233441334064775200206310ustar00rootroot00000000000000/* Handle aliases for locale names. Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for mempcpy(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #if defined _LIBC || defined HAVE___FSETLOCKING # include #endif #include #ifdef __GNUC__ # undef alloca # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #include #include "gettextP.h" #if ENABLE_RELOCATABLE # include "relocatable.h" #else # define relocate(pathname) (pathname) #endif /* @@ end of prolog @@ */ #ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object file and the name space must not be polluted. */ # define strcasecmp __strcasecmp # ifndef mempcpy # define mempcpy __mempcpy # endif # define HAVE_MEMPCPY 1 # define HAVE___FSETLOCKING 1 /* We need locking here since we can be called from different places. */ # include __libc_lock_define_initialized (static, lock); #endif #ifndef internal_function # define internal_function #endif /* Some optimizations for glibc. */ #ifdef _LIBC # define FEOF(fp) feof_unlocked (fp) # define FGETS(buf, n, fp) fgets_unlocked (buf, n, fp) #else # define FEOF(fp) feof (fp) # define FGETS(buf, n, fp) fgets (buf, n, fp) #endif /* For those losing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA # define freea(p) /* nothing */ #else # define alloca(n) malloc (n) # define freea(p) free (p) #endif #if defined _LIBC_REENTRANT || HAVE_DECL_FGETS_UNLOCKED # undef fgets # define fgets(buf, len, s) fgets_unlocked (buf, len, s) #endif #if defined _LIBC_REENTRANT || HAVE_DECL_FEOF_UNLOCKED # undef feof # define feof(s) feof_unlocked (s) #endif struct alias_map { const char *alias; const char *value; }; #ifndef _LIBC # define libc_freeres_ptr(decl) decl #endif libc_freeres_ptr (static char *string_space); static size_t string_space_act; static size_t string_space_max; libc_freeres_ptr (static struct alias_map *map); static size_t nmap; static size_t maxmap; /* Prototypes for local functions. */ static size_t read_alias_file (const char *fname, int fname_len) internal_function; static int extend_alias_table (void); static int alias_compare (const struct alias_map *map1, const struct alias_map *map2); const char * _nl_expand_alias (const char *name) { static const char *locale_alias_path; struct alias_map *retval; const char *result = NULL; size_t added; #ifdef _LIBC __libc_lock_lock (lock); #endif if (locale_alias_path == NULL) locale_alias_path = LOCALE_ALIAS_PATH; do { struct alias_map item; item.alias = name; if (nmap > 0) retval = (struct alias_map *) bsearch (&item, map, nmap, sizeof (struct alias_map), (int (*) (const void *, const void *) ) alias_compare); else retval = NULL; /* We really found an alias. Return the value. */ if (retval != NULL) { result = retval->value; break; } /* Perhaps we can find another alias file. */ added = 0; while (added == 0 && locale_alias_path[0] != '\0') { const char *start; while (locale_alias_path[0] == PATH_SEPARATOR) ++locale_alias_path; start = locale_alias_path; while (locale_alias_path[0] != '\0' && locale_alias_path[0] != PATH_SEPARATOR) ++locale_alias_path; if (start < locale_alias_path) added = read_alias_file (start, locale_alias_path - start); } } while (added != 0); #ifdef _LIBC __libc_lock_unlock (lock); #endif return result; } static size_t internal_function read_alias_file (const char *fname, int fname_len) { FILE *fp; char *full_fname; size_t added; static const char aliasfile[] = "/locale.alias"; full_fname = (char *) alloca (fname_len + sizeof aliasfile); #ifdef HAVE_MEMPCPY mempcpy (mempcpy (full_fname, fname, fname_len), aliasfile, sizeof aliasfile); #else memcpy (full_fname, fname, fname_len); memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); #endif fp = fopen (relocate (full_fname), "r"); freea (full_fname); if (fp == NULL) return 0; #ifdef HAVE___FSETLOCKING /* No threads present. */ __fsetlocking (fp, FSETLOCKING_BYCALLER); #endif added = 0; while (!FEOF (fp)) { /* It is a reasonable approach to use a fix buffer here because a) we are only interested in the first two fields b) these fields must be usable as file names and so must not be that long We avoid a multi-kilobyte buffer here since this would use up stack space which we might not have if the program ran out of memory. */ char buf[400]; char *alias; char *value; char *cp; if (FGETS (buf, sizeof buf, fp) == NULL) /* EOF reached. */ break; cp = buf; /* Ignore leading white space. */ while (isspace ((unsigned char) cp[0])) ++cp; /* A leading '#' signals a comment line. */ if (cp[0] != '\0' && cp[0] != '#') { alias = cp++; while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) ++cp; /* Terminate alias name. */ if (cp[0] != '\0') *cp++ = '\0'; /* Now look for the beginning of the value. */ while (isspace ((unsigned char) cp[0])) ++cp; if (cp[0] != '\0') { size_t alias_len; size_t value_len; value = cp++; while (cp[0] != '\0' && !isspace ((unsigned char) cp[0])) ++cp; /* Terminate value. */ if (cp[0] == '\n') { /* This has to be done to make the following test for the end of line possible. We are looking for the terminating '\n' which do not overwrite here. */ *cp++ = '\0'; *cp = '\n'; } else if (cp[0] != '\0') *cp++ = '\0'; if (nmap >= maxmap) if (__builtin_expect (extend_alias_table (), 0)) return added; alias_len = strlen (alias) + 1; value_len = strlen (value) + 1; if (string_space_act + alias_len + value_len > string_space_max) { /* Increase size of memory pool. */ size_t new_size = (string_space_max + (alias_len + value_len > 1024 ? alias_len + value_len : 1024)); char *new_pool = (char *) realloc (string_space, new_size); if (new_pool == NULL) return added; if (__builtin_expect (string_space != new_pool, 0)) { size_t i; for (i = 0; i < nmap; i++) { map[i].alias += new_pool - string_space; map[i].value += new_pool - string_space; } } string_space = new_pool; string_space_max = new_size; } map[nmap].alias = memcpy (&string_space[string_space_act], alias, alias_len); string_space_act += alias_len; map[nmap].value = memcpy (&string_space[string_space_act], value, value_len); string_space_act += value_len; ++nmap; ++added; } } /* Possibly not the whole line fits into the buffer. Ignore the rest of the line. */ while (strchr (buf, '\n') == NULL) if (FGETS (buf, sizeof buf, fp) == NULL) /* Make sure the inner loop will be left. The outer loop will exit at the `feof' test. */ break; } /* Should we test for ferror()? I think we have to silently ignore errors. --drepper */ fclose (fp); if (added > 0) qsort (map, nmap, sizeof (struct alias_map), (int (*) (const void *, const void *)) alias_compare); return added; } static int extend_alias_table () { size_t new_size; struct alias_map *new_map; new_size = maxmap == 0 ? 100 : 2 * maxmap; new_map = (struct alias_map *) realloc (map, (new_size * sizeof (struct alias_map))); if (new_map == NULL) /* Simply don't extend: we don't have any more core. */ return -1; map = new_map; maxmap = new_size; return 0; } static int alias_compare (const struct alias_map *map1, const struct alias_map *map2) { #if defined _LIBC || defined HAVE_STRCASECMP return strcasecmp (map1->alias, map2->alias); #else const unsigned char *p1 = (const unsigned char *) map1->alias; const unsigned char *p2 = (const unsigned char *) map2->alias; unsigned char c1, c2; if (p1 == p2) return 0; do { /* I know this seems to be odd but the tolower() function in some systems libc cannot handle nonalpha characters. */ c1 = isupper (*p1) ? tolower (*p1) : *p1; c2 = isupper (*p2) ? tolower (*p2) : *p2; if (c1 == '\0') break; ++p1; ++p2; } while (c1 == c2); return c1 - c2; #endif } lightspeed-1.2a.debian.1/intl/localename.c000066400000000000000000001243001334064775200204520ustar00rootroot00000000000000/* Determine the current selected locale. Copyright (C) 1995-1999, 2000-2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Ulrich Drepper , 1995. */ /* Win32 code written by Tor Lillqvist . */ /* MacOS X code written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE # include # include # if HAVE_CFLOCALECOPYCURRENT # include # elif HAVE_CFPREFERENCESCOPYAPPVALUE # include # endif #endif #if defined _WIN32 || defined __WIN32__ # undef WIN32 /* avoid warning on mingw32 */ # define WIN32 #endif #ifdef WIN32 # define WIN32_LEAN_AND_MEAN # include /* List of language codes, sorted by value: 0x01 LANG_ARABIC 0x02 LANG_BULGARIAN 0x03 LANG_CATALAN 0x04 LANG_CHINESE 0x05 LANG_CZECH 0x06 LANG_DANISH 0x07 LANG_GERMAN 0x08 LANG_GREEK 0x09 LANG_ENGLISH 0x0a LANG_SPANISH 0x0b LANG_FINNISH 0x0c LANG_FRENCH 0x0d LANG_HEBREW 0x0e LANG_HUNGARIAN 0x0f LANG_ICELANDIC 0x10 LANG_ITALIAN 0x11 LANG_JAPANESE 0x12 LANG_KOREAN 0x13 LANG_DUTCH 0x14 LANG_NORWEGIAN 0x15 LANG_POLISH 0x16 LANG_PORTUGUESE 0x17 LANG_RHAETO_ROMANCE 0x18 LANG_ROMANIAN 0x19 LANG_RUSSIAN 0x1a LANG_CROATIAN == LANG_SERBIAN 0x1b LANG_SLOVAK 0x1c LANG_ALBANIAN 0x1d LANG_SWEDISH 0x1e LANG_THAI 0x1f LANG_TURKISH 0x20 LANG_URDU 0x21 LANG_INDONESIAN 0x22 LANG_UKRAINIAN 0x23 LANG_BELARUSIAN 0x24 LANG_SLOVENIAN 0x25 LANG_ESTONIAN 0x26 LANG_LATVIAN 0x27 LANG_LITHUANIAN 0x28 LANG_TAJIK 0x29 LANG_FARSI 0x2a LANG_VIETNAMESE 0x2b LANG_ARMENIAN 0x2c LANG_AZERI 0x2d LANG_BASQUE 0x2e LANG_SORBIAN 0x2f LANG_MACEDONIAN 0x30 LANG_SUTU 0x31 LANG_TSONGA 0x32 LANG_TSWANA 0x33 LANG_VENDA 0x34 LANG_XHOSA 0x35 LANG_ZULU 0x36 LANG_AFRIKAANS 0x37 LANG_GEORGIAN 0x38 LANG_FAEROESE 0x39 LANG_HINDI 0x3a LANG_MALTESE 0x3b LANG_SAAMI 0x3c LANG_GAELIC 0x3d LANG_YIDDISH 0x3e LANG_MALAY 0x3f LANG_KAZAK 0x40 LANG_KYRGYZ 0x41 LANG_SWAHILI 0x42 LANG_TURKMEN 0x43 LANG_UZBEK 0x44 LANG_TATAR 0x45 LANG_BENGALI 0x46 LANG_PUNJABI 0x47 LANG_GUJARATI 0x48 LANG_ORIYA 0x49 LANG_TAMIL 0x4a LANG_TELUGU 0x4b LANG_KANNADA 0x4c LANG_MALAYALAM 0x4d LANG_ASSAMESE 0x4e LANG_MARATHI 0x4f LANG_SANSKRIT 0x50 LANG_MONGOLIAN 0x51 LANG_TIBETAN 0x52 LANG_WELSH 0x53 LANG_CAMBODIAN 0x54 LANG_LAO 0x55 LANG_BURMESE 0x56 LANG_GALICIAN 0x57 LANG_KONKANI 0x58 LANG_MANIPURI 0x59 LANG_SINDHI 0x5a LANG_SYRIAC 0x5b LANG_SINHALESE 0x5c LANG_CHEROKEE 0x5d LANG_INUKTITUT 0x5e LANG_AMHARIC 0x5f LANG_TAMAZIGHT 0x60 LANG_KASHMIRI 0x61 LANG_NEPALI 0x62 LANG_FRISIAN 0x63 LANG_PASHTO 0x64 LANG_TAGALOG 0x65 LANG_DIVEHI 0x66 LANG_EDO 0x67 LANG_FULFULDE 0x68 LANG_HAUSA 0x69 LANG_IBIBIO 0x6a LANG_YORUBA 0x70 LANG_IGBO 0x71 LANG_KANURI 0x72 LANG_OROMO 0x73 LANG_TIGRINYA 0x74 LANG_GUARANI 0x75 LANG_HAWAIIAN 0x76 LANG_LATIN 0x77 LANG_SOMALI 0x78 LANG_YI 0x79 LANG_PAPIAMENTU */ /* Mingw headers don't have latest language and sublanguage codes. */ # ifndef LANG_AFRIKAANS # define LANG_AFRIKAANS 0x36 # endif # ifndef LANG_ALBANIAN # define LANG_ALBANIAN 0x1c # endif # ifndef LANG_AMHARIC # define LANG_AMHARIC 0x5e # endif # ifndef LANG_ARABIC # define LANG_ARABIC 0x01 # endif # ifndef LANG_ARMENIAN # define LANG_ARMENIAN 0x2b # endif # ifndef LANG_ASSAMESE # define LANG_ASSAMESE 0x4d # endif # ifndef LANG_AZERI # define LANG_AZERI 0x2c # endif # ifndef LANG_BASQUE # define LANG_BASQUE 0x2d # endif # ifndef LANG_BELARUSIAN # define LANG_BELARUSIAN 0x23 # endif # ifndef LANG_BENGALI # define LANG_BENGALI 0x45 # endif # ifndef LANG_BURMESE # define LANG_BURMESE 0x55 # endif # ifndef LANG_CAMBODIAN # define LANG_CAMBODIAN 0x53 # endif # ifndef LANG_CATALAN # define LANG_CATALAN 0x03 # endif # ifndef LANG_CHEROKEE # define LANG_CHEROKEE 0x5c # endif # ifndef LANG_DIVEHI # define LANG_DIVEHI 0x65 # endif # ifndef LANG_EDO # define LANG_EDO 0x66 # endif # ifndef LANG_ESTONIAN # define LANG_ESTONIAN 0x25 # endif # ifndef LANG_FAEROESE # define LANG_FAEROESE 0x38 # endif # ifndef LANG_FARSI # define LANG_FARSI 0x29 # endif # ifndef LANG_FRISIAN # define LANG_FRISIAN 0x62 # endif # ifndef LANG_FULFULDE # define LANG_FULFULDE 0x67 # endif # ifndef LANG_GAELIC # define LANG_GAELIC 0x3c # endif # ifndef LANG_GALICIAN # define LANG_GALICIAN 0x56 # endif # ifndef LANG_GEORGIAN # define LANG_GEORGIAN 0x37 # endif # ifndef LANG_GUARANI # define LANG_GUARANI 0x74 # endif # ifndef LANG_GUJARATI # define LANG_GUJARATI 0x47 # endif # ifndef LANG_HAUSA # define LANG_HAUSA 0x68 # endif # ifndef LANG_HAWAIIAN # define LANG_HAWAIIAN 0x75 # endif # ifndef LANG_HEBREW # define LANG_HEBREW 0x0d # endif # ifndef LANG_HINDI # define LANG_HINDI 0x39 # endif # ifndef LANG_IBIBIO # define LANG_IBIBIO 0x69 # endif # ifndef LANG_IGBO # define LANG_IGBO 0x70 # endif # ifndef LANG_INDONESIAN # define LANG_INDONESIAN 0x21 # endif # ifndef LANG_INUKTITUT # define LANG_INUKTITUT 0x5d # endif # ifndef LANG_KANNADA # define LANG_KANNADA 0x4b # endif # ifndef LANG_KANURI # define LANG_KANURI 0x71 # endif # ifndef LANG_KASHMIRI # define LANG_KASHMIRI 0x60 # endif # ifndef LANG_KAZAK # define LANG_KAZAK 0x3f # endif # ifndef LANG_KONKANI # define LANG_KONKANI 0x57 # endif # ifndef LANG_KYRGYZ # define LANG_KYRGYZ 0x40 # endif # ifndef LANG_LAO # define LANG_LAO 0x54 # endif # ifndef LANG_LATIN # define LANG_LATIN 0x76 # endif # ifndef LANG_LATVIAN # define LANG_LATVIAN 0x26 # endif # ifndef LANG_LITHUANIAN # define LANG_LITHUANIAN 0x27 # endif # ifndef LANG_MACEDONIAN # define LANG_MACEDONIAN 0x2f # endif # ifndef LANG_MALAY # define LANG_MALAY 0x3e # endif # ifndef LANG_MALAYALAM # define LANG_MALAYALAM 0x4c # endif # ifndef LANG_MALTESE # define LANG_MALTESE 0x3a # endif # ifndef LANG_MANIPURI # define LANG_MANIPURI 0x58 # endif # ifndef LANG_MARATHI # define LANG_MARATHI 0x4e # endif # ifndef LANG_MONGOLIAN # define LANG_MONGOLIAN 0x50 # endif # ifndef LANG_NEPALI # define LANG_NEPALI 0x61 # endif # ifndef LANG_ORIYA # define LANG_ORIYA 0x48 # endif # ifndef LANG_OROMO # define LANG_OROMO 0x72 # endif # ifndef LANG_PAPIAMENTU # define LANG_PAPIAMENTU 0x79 # endif # ifndef LANG_PASHTO # define LANG_PASHTO 0x63 # endif # ifndef LANG_PUNJABI # define LANG_PUNJABI 0x46 # endif # ifndef LANG_RHAETO_ROMANCE # define LANG_RHAETO_ROMANCE 0x17 # endif # ifndef LANG_SAAMI # define LANG_SAAMI 0x3b # endif # ifndef LANG_SANSKRIT # define LANG_SANSKRIT 0x4f # endif # ifndef LANG_SERBIAN # define LANG_SERBIAN 0x1a # endif # ifndef LANG_SINDHI # define LANG_SINDHI 0x59 # endif # ifndef LANG_SINHALESE # define LANG_SINHALESE 0x5b # endif # ifndef LANG_SLOVAK # define LANG_SLOVAK 0x1b # endif # ifndef LANG_SOMALI # define LANG_SOMALI 0x77 # endif # ifndef LANG_SORBIAN # define LANG_SORBIAN 0x2e # endif # ifndef LANG_SUTU # define LANG_SUTU 0x30 # endif # ifndef LANG_SWAHILI # define LANG_SWAHILI 0x41 # endif # ifndef LANG_SYRIAC # define LANG_SYRIAC 0x5a # endif # ifndef LANG_TAGALOG # define LANG_TAGALOG 0x64 # endif # ifndef LANG_TAJIK # define LANG_TAJIK 0x28 # endif # ifndef LANG_TAMAZIGHT # define LANG_TAMAZIGHT 0x5f # endif # ifndef LANG_TAMIL # define LANG_TAMIL 0x49 # endif # ifndef LANG_TATAR # define LANG_TATAR 0x44 # endif # ifndef LANG_TELUGU # define LANG_TELUGU 0x4a # endif # ifndef LANG_THAI # define LANG_THAI 0x1e # endif # ifndef LANG_TIBETAN # define LANG_TIBETAN 0x51 # endif # ifndef LANG_TIGRINYA # define LANG_TIGRINYA 0x73 # endif # ifndef LANG_TSONGA # define LANG_TSONGA 0x31 # endif # ifndef LANG_TSWANA # define LANG_TSWANA 0x32 # endif # ifndef LANG_TURKMEN # define LANG_TURKMEN 0x42 # endif # ifndef LANG_UKRAINIAN # define LANG_UKRAINIAN 0x22 # endif # ifndef LANG_URDU # define LANG_URDU 0x20 # endif # ifndef LANG_UZBEK # define LANG_UZBEK 0x43 # endif # ifndef LANG_VENDA # define LANG_VENDA 0x33 # endif # ifndef LANG_VIETNAMESE # define LANG_VIETNAMESE 0x2a # endif # ifndef LANG_WELSH # define LANG_WELSH 0x52 # endif # ifndef LANG_XHOSA # define LANG_XHOSA 0x34 # endif # ifndef LANG_YI # define LANG_YI 0x78 # endif # ifndef LANG_YIDDISH # define LANG_YIDDISH 0x3d # endif # ifndef LANG_YORUBA # define LANG_YORUBA 0x6a # endif # ifndef LANG_ZULU # define LANG_ZULU 0x35 # endif # ifndef SUBLANG_ARABIC_SAUDI_ARABIA # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 # endif # ifndef SUBLANG_ARABIC_IRAQ # define SUBLANG_ARABIC_IRAQ 0x02 # endif # ifndef SUBLANG_ARABIC_EGYPT # define SUBLANG_ARABIC_EGYPT 0x03 # endif # ifndef SUBLANG_ARABIC_LIBYA # define SUBLANG_ARABIC_LIBYA 0x04 # endif # ifndef SUBLANG_ARABIC_ALGERIA # define SUBLANG_ARABIC_ALGERIA 0x05 # endif # ifndef SUBLANG_ARABIC_MOROCCO # define SUBLANG_ARABIC_MOROCCO 0x06 # endif # ifndef SUBLANG_ARABIC_TUNISIA # define SUBLANG_ARABIC_TUNISIA 0x07 # endif # ifndef SUBLANG_ARABIC_OMAN # define SUBLANG_ARABIC_OMAN 0x08 # endif # ifndef SUBLANG_ARABIC_YEMEN # define SUBLANG_ARABIC_YEMEN 0x09 # endif # ifndef SUBLANG_ARABIC_SYRIA # define SUBLANG_ARABIC_SYRIA 0x0a # endif # ifndef SUBLANG_ARABIC_JORDAN # define SUBLANG_ARABIC_JORDAN 0x0b # endif # ifndef SUBLANG_ARABIC_LEBANON # define SUBLANG_ARABIC_LEBANON 0x0c # endif # ifndef SUBLANG_ARABIC_KUWAIT # define SUBLANG_ARABIC_KUWAIT 0x0d # endif # ifndef SUBLANG_ARABIC_UAE # define SUBLANG_ARABIC_UAE 0x0e # endif # ifndef SUBLANG_ARABIC_BAHRAIN # define SUBLANG_ARABIC_BAHRAIN 0x0f # endif # ifndef SUBLANG_ARABIC_QATAR # define SUBLANG_ARABIC_QATAR 0x10 # endif # ifndef SUBLANG_AZERI_LATIN # define SUBLANG_AZERI_LATIN 0x01 # endif # ifndef SUBLANG_AZERI_CYRILLIC # define SUBLANG_AZERI_CYRILLIC 0x02 # endif # ifndef SUBLANG_BENGALI_INDIA # define SUBLANG_BENGALI_INDIA 0x00 # endif # ifndef SUBLANG_BENGALI_BANGLADESH # define SUBLANG_BENGALI_BANGLADESH 0x01 # endif # ifndef SUBLANG_CHINESE_MACAU # define SUBLANG_CHINESE_MACAU 0x05 # endif # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 # endif # ifndef SUBLANG_ENGLISH_JAMAICA # define SUBLANG_ENGLISH_JAMAICA 0x08 # endif # ifndef SUBLANG_ENGLISH_CARIBBEAN # define SUBLANG_ENGLISH_CARIBBEAN 0x09 # endif # ifndef SUBLANG_ENGLISH_BELIZE # define SUBLANG_ENGLISH_BELIZE 0x0a # endif # ifndef SUBLANG_ENGLISH_TRINIDAD # define SUBLANG_ENGLISH_TRINIDAD 0x0b # endif # ifndef SUBLANG_ENGLISH_ZIMBABWE # define SUBLANG_ENGLISH_ZIMBABWE 0x0c # endif # ifndef SUBLANG_ENGLISH_PHILIPPINES # define SUBLANG_ENGLISH_PHILIPPINES 0x0d # endif # ifndef SUBLANG_ENGLISH_INDONESIA # define SUBLANG_ENGLISH_INDONESIA 0x0e # endif # ifndef SUBLANG_ENGLISH_HONGKONG # define SUBLANG_ENGLISH_HONGKONG 0x0f # endif # ifndef SUBLANG_ENGLISH_INDIA # define SUBLANG_ENGLISH_INDIA 0x10 # endif # ifndef SUBLANG_ENGLISH_MALAYSIA # define SUBLANG_ENGLISH_MALAYSIA 0x11 # endif # ifndef SUBLANG_ENGLISH_SINGAPORE # define SUBLANG_ENGLISH_SINGAPORE 0x12 # endif # ifndef SUBLANG_FRENCH_LUXEMBOURG # define SUBLANG_FRENCH_LUXEMBOURG 0x05 # endif # ifndef SUBLANG_FRENCH_MONACO # define SUBLANG_FRENCH_MONACO 0x06 # endif # ifndef SUBLANG_FRENCH_WESTINDIES # define SUBLANG_FRENCH_WESTINDIES 0x07 # endif # ifndef SUBLANG_FRENCH_REUNION # define SUBLANG_FRENCH_REUNION 0x08 # endif # ifndef SUBLANG_FRENCH_CONGO # define SUBLANG_FRENCH_CONGO 0x09 # endif # ifndef SUBLANG_FRENCH_SENEGAL # define SUBLANG_FRENCH_SENEGAL 0x0a # endif # ifndef SUBLANG_FRENCH_CAMEROON # define SUBLANG_FRENCH_CAMEROON 0x0b # endif # ifndef SUBLANG_FRENCH_COTEDIVOIRE # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c # endif # ifndef SUBLANG_FRENCH_MALI # define SUBLANG_FRENCH_MALI 0x0d # endif # ifndef SUBLANG_FRENCH_MOROCCO # define SUBLANG_FRENCH_MOROCCO 0x0e # endif # ifndef SUBLANG_FRENCH_HAITI # define SUBLANG_FRENCH_HAITI 0x0f # endif # ifndef SUBLANG_GERMAN_LUXEMBOURG # define SUBLANG_GERMAN_LUXEMBOURG 0x04 # endif # ifndef SUBLANG_GERMAN_LIECHTENSTEIN # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 # endif # ifndef SUBLANG_KASHMIRI_INDIA # define SUBLANG_KASHMIRI_INDIA 0x02 # endif # ifndef SUBLANG_MALAY_MALAYSIA # define SUBLANG_MALAY_MALAYSIA 0x01 # endif # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 # endif # ifndef SUBLANG_NEPALI_INDIA # define SUBLANG_NEPALI_INDIA 0x02 # endif # ifndef SUBLANG_PUNJABI_INDIA # define SUBLANG_PUNJABI_INDIA 0x00 # endif # ifndef SUBLANG_PUNJABI_PAKISTAN # define SUBLANG_PUNJABI_PAKISTAN 0x01 # endif # ifndef SUBLANG_ROMANIAN_ROMANIA # define SUBLANG_ROMANIAN_ROMANIA 0x00 # endif # ifndef SUBLANG_ROMANIAN_MOLDOVA # define SUBLANG_ROMANIAN_MOLDOVA 0x01 # endif # ifndef SUBLANG_SERBIAN_LATIN # define SUBLANG_SERBIAN_LATIN 0x02 # endif # ifndef SUBLANG_SERBIAN_CYRILLIC # define SUBLANG_SERBIAN_CYRILLIC 0x03 # endif # ifndef SUBLANG_SINDHI_INDIA # define SUBLANG_SINDHI_INDIA 0x00 # endif # ifndef SUBLANG_SINDHI_PAKISTAN # define SUBLANG_SINDHI_PAKISTAN 0x01 # endif # ifndef SUBLANG_SPANISH_GUATEMALA # define SUBLANG_SPANISH_GUATEMALA 0x04 # endif # ifndef SUBLANG_SPANISH_COSTA_RICA # define SUBLANG_SPANISH_COSTA_RICA 0x05 # endif # ifndef SUBLANG_SPANISH_PANAMA # define SUBLANG_SPANISH_PANAMA 0x06 # endif # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07 # endif # ifndef SUBLANG_SPANISH_VENEZUELA # define SUBLANG_SPANISH_VENEZUELA 0x08 # endif # ifndef SUBLANG_SPANISH_COLOMBIA # define SUBLANG_SPANISH_COLOMBIA 0x09 # endif # ifndef SUBLANG_SPANISH_PERU # define SUBLANG_SPANISH_PERU 0x0a # endif # ifndef SUBLANG_SPANISH_ARGENTINA # define SUBLANG_SPANISH_ARGENTINA 0x0b # endif # ifndef SUBLANG_SPANISH_ECUADOR # define SUBLANG_SPANISH_ECUADOR 0x0c # endif # ifndef SUBLANG_SPANISH_CHILE # define SUBLANG_SPANISH_CHILE 0x0d # endif # ifndef SUBLANG_SPANISH_URUGUAY # define SUBLANG_SPANISH_URUGUAY 0x0e # endif # ifndef SUBLANG_SPANISH_PARAGUAY # define SUBLANG_SPANISH_PARAGUAY 0x0f # endif # ifndef SUBLANG_SPANISH_BOLIVIA # define SUBLANG_SPANISH_BOLIVIA 0x10 # endif # ifndef SUBLANG_SPANISH_EL_SALVADOR # define SUBLANG_SPANISH_EL_SALVADOR 0x11 # endif # ifndef SUBLANG_SPANISH_HONDURAS # define SUBLANG_SPANISH_HONDURAS 0x12 # endif # ifndef SUBLANG_SPANISH_NICARAGUA # define SUBLANG_SPANISH_NICARAGUA 0x13 # endif # ifndef SUBLANG_SPANISH_PUERTO_RICO # define SUBLANG_SPANISH_PUERTO_RICO 0x14 # endif # ifndef SUBLANG_SWEDISH_FINLAND # define SUBLANG_SWEDISH_FINLAND 0x02 # endif # ifndef SUBLANG_TAMAZIGHT_ARABIC # define SUBLANG_TAMAZIGHT_ARABIC 0x01 # endif # ifndef SUBLANG_TAMAZIGHT_LATIN # define SUBLANG_TAMAZIGHT_LATIN 0x02 # endif # ifndef SUBLANG_TIGRINYA_ETHIOPIA # define SUBLANG_TIGRINYA_ETHIOPIA 0x00 # endif # ifndef SUBLANG_TIGRINYA_ERITREA # define SUBLANG_TIGRINYA_ERITREA 0x01 # endif # ifndef SUBLANG_URDU_PAKISTAN # define SUBLANG_URDU_PAKISTAN 0x01 # endif # ifndef SUBLANG_URDU_INDIA # define SUBLANG_URDU_INDIA 0x02 # endif # ifndef SUBLANG_UZBEK_LATIN # define SUBLANG_UZBEK_LATIN 0x01 # endif # ifndef SUBLANG_UZBEK_CYRILLIC # define SUBLANG_UZBEK_CYRILLIC 0x02 # endif #endif # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ /* Canonicalize a MacOS X locale name to a Unix locale name. NAME is a sufficiently large buffer. On input, it contains the MacOS X locale name. On output, it contains the Unix locale name. */ void _nl_locale_name_canonicalize (char *name) { /* This conversion is based on a posting by Deborah GoldSmith on 2005-03-08, http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */ /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this. Therefore we do it ourselves, using a table based on the results of the MacOS X 10.3.8 function CFLocaleCreateCanonicalLocaleIdentifierFromString(). */ typedef struct { const char legacy[21+1]; const char unixy[5+1]; } legacy_entry; static const legacy_entry legacy_table[] = { { "Afrikaans", "af" }, { "Albanian", "sq" }, { "Amharic", "am" }, { "Arabic", "ar" }, { "Armenian", "hy" }, { "Assamese", "as" }, { "Aymara", "ay" }, { "Azerbaijani", "az" }, { "Basque", "eu" }, { "Belarusian", "be" }, { "Belorussian", "be" }, { "Bengali", "bn" }, { "Brazilian Portugese", "pt_BR" }, { "Brazilian Portuguese", "pt_BR" }, { "Breton", "br" }, { "Bulgarian", "bg" }, { "Burmese", "my" }, { "Byelorussian", "be" }, { "Catalan", "ca" }, { "Chewa", "ny" }, { "Chichewa", "ny" }, { "Chinese", "zh" }, { "Chinese, Simplified", "zh_CN" }, { "Chinese, Traditional", "zh_TW" }, { "Chinese, Tradtional", "zh_TW" }, { "Croatian", "hr" }, { "Czech", "cs" }, { "Danish", "da" }, { "Dutch", "nl" }, { "Dzongkha", "dz" }, { "English", "en" }, { "Esperanto", "eo" }, { "Estonian", "et" }, { "Faroese", "fo" }, { "Farsi", "fa" }, { "Finnish", "fi" }, { "Flemish", "nl_BE" }, { "French", "fr" }, { "Galician", "gl" }, { "Gallegan", "gl" }, { "Georgian", "ka" }, { "German", "de" }, { "Greek", "el" }, { "Greenlandic", "kl" }, { "Guarani", "gn" }, { "Gujarati", "gu" }, { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */ { "Hebrew", "he" }, { "Hindi", "hi" }, { "Hungarian", "hu" }, { "Icelandic", "is" }, { "Indonesian", "id" }, { "Inuktitut", "iu" }, { "Irish", "ga" }, { "Italian", "it" }, { "Japanese", "ja" }, { "Javanese", "jv" }, { "Kalaallisut", "kl" }, { "Kannada", "kn" }, { "Kashmiri", "ks" }, { "Kazakh", "kk" }, { "Khmer", "km" }, { "Kinyarwanda", "rw" }, { "Kirghiz", "ky" }, { "Korean", "ko" }, { "Kurdish", "ku" }, { "Latin", "la" }, { "Latvian", "lv" }, { "Lithuanian", "lt" }, { "Macedonian", "mk" }, { "Malagasy", "mg" }, { "Malay", "ms" }, { "Malayalam", "ml" }, { "Maltese", "mt" }, { "Manx", "gv" }, { "Marathi", "mr" }, { "Moldavian", "mo" }, { "Mongolian", "mn" }, { "Nepali", "ne" }, { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */ { "Nyanja", "ny" }, { "Nynorsk", "nn" }, { "Oriya", "or" }, { "Oromo", "om" }, { "Panjabi", "pa" }, { "Pashto", "ps" }, { "Persian", "fa" }, { "Polish", "pl" }, { "Portuguese", "pt" }, { "Portuguese, Brazilian", "pt_BR" }, { "Punjabi", "pa" }, { "Pushto", "ps" }, { "Quechua", "qu" }, { "Romanian", "ro" }, { "Ruanda", "rw" }, { "Rundi", "rn" }, { "Russian", "ru" }, { "Sami", "se_NO" }, /* Not just "se". */ { "Sanskrit", "sa" }, { "Scottish", "gd" }, { "Serbian", "sr" }, { "Simplified Chinese", "zh_CN" }, { "Sindhi", "sd" }, { "Sinhalese", "si" }, { "Slovak", "sk" }, { "Slovenian", "sl" }, { "Somali", "so" }, { "Spanish", "es" }, { "Sundanese", "su" }, { "Swahili", "sw" }, { "Swedish", "sv" }, { "Tagalog", "tl" }, { "Tajik", "tg" }, { "Tajiki", "tg" }, { "Tamil", "ta" }, { "Tatar", "tt" }, { "Telugu", "te" }, { "Thai", "th" }, { "Tibetan", "bo" }, { "Tigrinya", "ti" }, { "Tongan", "to" }, { "Traditional Chinese", "zh_TW" }, { "Turkish", "tr" }, { "Turkmen", "tk" }, { "Uighur", "ug" }, { "Ukrainian", "uk" }, { "Urdu", "ur" }, { "Uzbek", "uz" }, { "Vietnamese", "vi" }, { "Welsh", "cy" }, { "Yiddish", "yi" } }; /* Convert new-style locale names with language tags (ISO 639 and ISO 15924) to Unix (ISO 639 and ISO 3166) names. */ typedef struct { const char langtag[7+1]; const char unixy[12+1]; } langtag_entry; static const langtag_entry langtag_table[] = { /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn". The default script for az on Unix is Latin. */ { "az-Latn", "az" }, /* MacOS X has "ga-dots". Does not yet exist on Unix. */ { "ga-dots", "ga" }, /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */ /* MacOS X has "mn-Cyrl", "mn-Mong". The default script for mn on Unix is Cyrillic. */ { "mn-Cyrl", "mn" }, /* MacOS X has "ms-Arab", "ms-Latn". The default script for ms on Unix is Latin. */ { "ms-Latn", "ms" }, /* MacOS X has "tg-Cyrl". The default script for tg on Unix is Cyrillic. */ { "tg-Cyrl", "tg" }, /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */ /* MacOS X has "tt-Cyrl". The default script for tt on Unix is Cyrillic. */ { "tt-Cyrl", "tt" }, /* MacOS X has "zh-Hans", "zh-Hant". Country codes are used to distinguish these on Unix. */ { "zh-Hans", "zh_CN" }, { "zh-Hant", "zh_TW" } }; /* Convert script names (ISO 15924) to Unix conventions. See http://www.unicode.org/iso15924/iso15924-codes.html */ typedef struct { const char script[4+1]; const char unixy[9+1]; } script_entry; static const script_entry script_table[] = { { "Arab", "arabic" }, { "Cyrl", "cyrillic" }, { "Mong", "mongolian" } }; /* Step 1: Convert using legacy_table. */ if (name[0] >= 'A' && name[0] <= 'Z') { unsigned int i1, i2; i1 = 0; i2 = sizeof (legacy_table) / sizeof (legacy_entry); while (i2 - i1 > 1) { /* At this point we know that if name occurs in legacy_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const legacy_entry *p = &legacy_table[i]; if (strcmp (name, p->legacy) < 0) i2 = i; else i1 = i; } if (strcmp (name, legacy_table[i1].legacy) == 0) { strcpy (name, legacy_table[i1].unixy); return; } } /* Step 2: Convert using langtag_table and script_table. */ if (strlen (name) == 7 && name[2] == '-') { unsigned int i1, i2; i1 = 0; i2 = sizeof (langtag_table) / sizeof (langtag_entry); while (i2 - i1 > 1) { /* At this point we know that if name occurs in langtag_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const langtag_entry *p = &langtag_table[i]; if (strcmp (name, p->langtag) < 0) i2 = i; else i1 = i; } if (strcmp (name, langtag_table[i1].langtag) == 0) { strcpy (name, langtag_table[i1].unixy); return; } i1 = 0; i2 = sizeof (script_table) / sizeof (script_entry); while (i2 - i1 > 1) { /* At this point we know that if (name + 3) occurs in script_table, its index must be >= i1 and < i2. */ unsigned int i = (i1 + i2) >> 1; const script_entry *p = &script_table[i]; if (strcmp (name + 3, p->script) < 0) i2 = i; else i1 = i; } if (strcmp (name + 3, script_table[i1].script) == 0) { name[2] = '@'; strcpy (name + 3, script_table[i1].unixy); return; } } /* Step 3: Convert new-style dash to Unix underscore. */ { char *p; for (p = name; *p != '\0'; p++) if (*p == '-') *p = '_'; } } #endif /* XPG3 defines the result of 'setlocale (category, NULL)' as: "Directs 'setlocale()' to query 'category' and return the current setting of 'local'." However it does not specify the exact format. Neither do SUSV2 and ISO C 99. So we can use this feature only on selected systems (e.g. those using GNU C Library). */ #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2) # define HAVE_LOCALE_NULL #endif /* Determine the current locale's name, and canonicalize it into XPG syntax language[_territory[.codeset]][@modifier] The codeset part in the result is not reliable; the locale_charset() should be used for codeset information instead. The result must not be freed; it is statically allocated. */ const char * _nl_locale_name_posix (int category, const char *categoryname) { /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'. On some systems this can be done by the 'setlocale' function itself. */ #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL return setlocale (category, NULL); #else const char *retval; /* Setting of LC_ALL overrides all other. */ retval = getenv ("LC_ALL"); if (retval != NULL && retval[0] != '\0') return retval; /* Next comes the name of the desired category. */ retval = getenv (categoryname); if (retval != NULL && retval[0] != '\0') return retval; /* Last possibility is the LANG environment variable. */ retval = getenv ("LANG"); if (retval != NULL && retval[0] != '\0') return retval; return NULL; #endif } const char * _nl_locale_name_default (void) { /* POSIX:2001 says: "All implementations shall define a locale as the default locale, to be invoked when no environment variables are set, or set to the empty string. This default locale can be the POSIX locale or any other implementation-defined locale. Some implementations may provide facilities for local installation administrators to set the default locale, customizing it for each location. POSIX:2001 does not require such a facility. */ #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32)) /* The system does not have a way of setting the locale, other than the POSIX specified environment variables. We use C as default locale. */ return "C"; #else /* Return an XPG style locale name language[_territory][@modifier]. Don't even bother determining the codeset; it's not useful in this context, because message catalogs are not specific to a single codeset. */ # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ { /* Cache the locale name, since CoreFoundation calls are expensive. */ static const char *cached_localename; if (cached_localename == NULL) { char namebuf[256]; # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ CFLocaleRef locale = CFLocaleCopyCurrent (); CFStringRef name = CFLocaleGetIdentifier (locale); if (CFStringGetCString (name, namebuf, sizeof(namebuf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (namebuf); cached_localename = strdup (namebuf); } CFRelease (locale); # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ CFTypeRef value = CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), kCFPreferencesCurrentApplication); if (value != NULL && CFGetTypeID (value) == CFStringGetTypeID () && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), kCFStringEncodingASCII)) { _nl_locale_name_canonicalize (namebuf); cached_localename = strdup (namebuf); } # endif if (cached_localename == NULL) cached_localename = "C"; } return cached_localename; } # endif # if defined(WIN32) /* WIN32 */ { LCID lcid; LANGID langid; int primary, sub; /* Use native Win32 API locale ID. */ lcid = GetThreadLocale (); /* Strip off the sorting rules, keep only the language part. */ langid = LANGIDFROMLCID (lcid); /* Split into language and territory part. */ primary = PRIMARYLANGID (langid); sub = SUBLANGID (langid); /* Dispatch on language. See also http://www.unicode.org/unicode/onlinedat/languages.html . For details about languages, see http://www.ethnologue.com/ . */ switch (primary) { case LANG_AFRIKAANS: return "af_ZA"; case LANG_ALBANIAN: return "sq_AL"; case LANG_AMHARIC: return "am_ET"; case LANG_ARABIC: switch (sub) { case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; case SUBLANG_ARABIC_EGYPT: return "ar_EG"; case SUBLANG_ARABIC_LIBYA: return "ar_LY"; case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; case SUBLANG_ARABIC_OMAN: return "ar_OM"; case SUBLANG_ARABIC_YEMEN: return "ar_YE"; case SUBLANG_ARABIC_SYRIA: return "ar_SY"; case SUBLANG_ARABIC_JORDAN: return "ar_JO"; case SUBLANG_ARABIC_LEBANON: return "ar_LB"; case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; case SUBLANG_ARABIC_UAE: return "ar_AE"; case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; case SUBLANG_ARABIC_QATAR: return "ar_QA"; } return "ar"; case LANG_ARMENIAN: return "hy_AM"; case LANG_ASSAMESE: return "as_IN"; case LANG_AZERI: switch (sub) { /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; } return "az"; case LANG_BASQUE: switch (sub) { case SUBLANG_DEFAULT: return "eu_ES"; } return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ case LANG_BELARUSIAN: return "be_BY"; case LANG_BENGALI: switch (sub) { case SUBLANG_BENGALI_INDIA: return "bn_IN"; case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; } return "bn"; case LANG_BULGARIAN: return "bg_BG"; case LANG_BURMESE: return "my_MM"; case LANG_CAMBODIAN: return "km_KH"; case LANG_CATALAN: return "ca_ES"; case LANG_CHEROKEE: return "chr_US"; case LANG_CHINESE: switch (sub) { case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; case SUBLANG_CHINESE_MACAU: return "zh_MO"; } return "zh"; case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN * What used to be called Serbo-Croatian * should really now be two separate * languages because of political reasons. * (Says tml, who knows nothing about Serbian * or Croatian.) * (I can feel those flames coming already.) */ switch (sub) { case SUBLANG_DEFAULT: return "hr_HR"; case SUBLANG_SERBIAN_LATIN: return "sr_CS"; case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; } return "hr"; case LANG_CZECH: return "cs_CZ"; case LANG_DANISH: return "da_DK"; case LANG_DIVEHI: return "dv_MV"; case LANG_DUTCH: switch (sub) { case SUBLANG_DUTCH: return "nl_NL"; case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; } return "nl"; case LANG_EDO: return "bin_NG"; case LANG_ENGLISH: switch (sub) { /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought * English was the language spoken in England. * Oh well. */ case SUBLANG_ENGLISH_US: return "en_US"; case SUBLANG_ENGLISH_UK: return "en_GB"; case SUBLANG_ENGLISH_AUS: return "en_AU"; case SUBLANG_ENGLISH_CAN: return "en_CA"; case SUBLANG_ENGLISH_NZ: return "en_NZ"; case SUBLANG_ENGLISH_EIRE: return "en_IE"; case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; case SUBLANG_ENGLISH_INDIA: return "en_IN"; case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; } return "en"; case LANG_ESTONIAN: return "et_EE"; case LANG_FAEROESE: return "fo_FO"; case LANG_FARSI: return "fa_IR"; case LANG_FINNISH: return "fi_FI"; case LANG_FRENCH: switch (sub) { case SUBLANG_FRENCH: return "fr_FR"; case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; case SUBLANG_FRENCH_SWISS: return "fr_CH"; case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; case SUBLANG_FRENCH_MONACO: return "fr_MC"; case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ case SUBLANG_FRENCH_REUNION: return "fr_RE"; case SUBLANG_FRENCH_CONGO: return "fr_CG"; case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; case SUBLANG_FRENCH_MALI: return "fr_ML"; case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; case SUBLANG_FRENCH_HAITI: return "fr_HT"; } return "fr"; case LANG_FRISIAN: return "fy_NL"; case LANG_FULFULDE: /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ return "ff_NG"; case LANG_GAELIC: switch (sub) { case 0x01: /* SCOTTISH */ return "gd_GB"; case 0x02: /* IRISH */ return "ga_IE"; } return "C"; case LANG_GALICIAN: return "gl_ES"; case LANG_GEORGIAN: return "ka_GE"; case LANG_GERMAN: switch (sub) { case SUBLANG_GERMAN: return "de_DE"; case SUBLANG_GERMAN_SWISS: return "de_CH"; case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; } return "de"; case LANG_GREEK: return "el_GR"; case LANG_GUARANI: return "gn_PY"; case LANG_GUJARATI: return "gu_IN"; case LANG_HAUSA: return "ha_NG"; case LANG_HAWAIIAN: /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) or Hawaii Creole English ("cpe_US", 600000 speakers)? */ return "cpe_US"; case LANG_HEBREW: return "he_IL"; case LANG_HINDI: return "hi_IN"; case LANG_HUNGARIAN: return "hu_HU"; case LANG_IBIBIO: return "nic_NG"; case LANG_ICELANDIC: return "is_IS"; case LANG_IGBO: return "ig_NG"; case LANG_INDONESIAN: return "id_ID"; case LANG_INUKTITUT: return "iu_CA"; case LANG_ITALIAN: switch (sub) { case SUBLANG_ITALIAN: return "it_IT"; case SUBLANG_ITALIAN_SWISS: return "it_CH"; } return "it"; case LANG_JAPANESE: return "ja_JP"; case LANG_KANNADA: return "kn_IN"; case LANG_KANURI: return "kr_NG"; case LANG_KASHMIRI: switch (sub) { case SUBLANG_DEFAULT: return "ks_PK"; case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; } return "ks"; case LANG_KAZAK: return "kk_KZ"; case LANG_KONKANI: /* FIXME: Adjust this when such locales appear on Unix. */ return "kok_IN"; case LANG_KOREAN: return "ko_KR"; case LANG_KYRGYZ: return "ky_KG"; case LANG_LAO: return "lo_LA"; case LANG_LATIN: return "la_VA"; case LANG_LATVIAN: return "lv_LV"; case LANG_LITHUANIAN: return "lt_LT"; case LANG_MACEDONIAN: return "mk_MK"; case LANG_MALAY: switch (sub) { case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; } return "ms"; case LANG_MALAYALAM: return "ml_IN"; case LANG_MALTESE: return "mt_MT"; case LANG_MANIPURI: /* FIXME: Adjust this when such locales appear on Unix. */ return "mni_IN"; case LANG_MARATHI: return "mr_IN"; case LANG_MONGOLIAN: switch (sub) { case SUBLANG_DEFAULT: return "mn_MN"; } return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ case LANG_NEPALI: switch (sub) { case SUBLANG_DEFAULT: return "ne_NP"; case SUBLANG_NEPALI_INDIA: return "ne_IN"; } return "ne"; case LANG_NORWEGIAN: switch (sub) { case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; } return "no"; case LANG_ORIYA: return "or_IN"; case LANG_OROMO: return "om_ET"; case LANG_PAPIAMENTU: return "pap_AN"; case LANG_PASHTO: return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ case LANG_POLISH: return "pl_PL"; case LANG_PORTUGUESE: switch (sub) { case SUBLANG_PORTUGUESE: return "pt_PT"; /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; } return "pt"; case LANG_PUNJABI: switch (sub) { case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ } return "pa"; case LANG_RHAETO_ROMANCE: return "rm_CH"; case LANG_ROMANIAN: switch (sub) { case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; } return "ro"; case LANG_RUSSIAN: switch (sub) { case SUBLANG_DEFAULT: return "ru_RU"; } return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ case LANG_SAAMI: /* actually Northern Sami */ return "se_NO"; case LANG_SANSKRIT: return "sa_IN"; case LANG_SINDHI: switch (sub) { case SUBLANG_SINDHI_INDIA: return "sd_IN"; case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; } return "sd"; case LANG_SINHALESE: return "si_LK"; case LANG_SLOVAK: return "sk_SK"; case LANG_SLOVENIAN: return "sl_SI"; case LANG_SOMALI: return "so_SO"; case LANG_SORBIAN: /* FIXME: Adjust this when such locales appear on Unix. */ return "wen_DE"; case LANG_SPANISH: switch (sub) { case SUBLANG_SPANISH: return "es_ES"; case SUBLANG_SPANISH_MEXICAN: return "es_MX"; case SUBLANG_SPANISH_MODERN: return "es_ES@modern"; /* not seen on Unix */ case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; case SUBLANG_SPANISH_PANAMA: return "es_PA"; case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; case SUBLANG_SPANISH_PERU: return "es_PE"; case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; case SUBLANG_SPANISH_ECUADOR: return "es_EC"; case SUBLANG_SPANISH_CHILE: return "es_CL"; case SUBLANG_SPANISH_URUGUAY: return "es_UY"; case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; case SUBLANG_SPANISH_HONDURAS: return "es_HN"; case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; } return "es"; case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ case LANG_SWAHILI: return "sw_KE"; case LANG_SWEDISH: switch (sub) { case SUBLANG_DEFAULT: return "sv_SE"; case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; } return "sv"; case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */ case LANG_TAGALOG: return "tl_PH"; case LANG_TAJIK: return "tg_TJ"; case LANG_TAMAZIGHT: switch (sub) { /* FIXME: Adjust this when Tamazight locales appear on Unix. */ case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; case SUBLANG_TAMAZIGHT_LATIN: return "ber_MA@latin"; } return "ber_MA"; case LANG_TAMIL: switch (sub) { case SUBLANG_DEFAULT: return "ta_IN"; } return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ case LANG_TATAR: return "tt_RU"; case LANG_TELUGU: return "te_IN"; case LANG_THAI: return "th_TH"; case LANG_TIBETAN: return "bo_CN"; case LANG_TIGRINYA: switch (sub) { case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; } return "ti"; case LANG_TSONGA: return "ts_ZA"; case LANG_TSWANA: return "tn_BW"; case LANG_TURKISH: return "tr_TR"; case LANG_TURKMEN: return "tk_TM"; case LANG_UKRAINIAN: return "uk_UA"; case LANG_URDU: switch (sub) { case SUBLANG_URDU_PAKISTAN: return "ur_PK"; case SUBLANG_URDU_INDIA: return "ur_IN"; } return "ur"; case LANG_UZBEK: switch (sub) { case SUBLANG_UZBEK_LATIN: return "uz_UZ"; case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; } return "uz"; case LANG_VENDA: return "ve_ZA"; case LANG_VIETNAMESE: return "vi_VN"; case LANG_WELSH: return "cy_GB"; case LANG_XHOSA: return "xh_ZA"; case LANG_YI: return "sit_CN"; case LANG_YIDDISH: return "yi_IL"; case LANG_YORUBA: return "yo_NG"; case LANG_ZULU: return "zu_ZA"; default: return "C"; } } # endif #endif } const char * _nl_locale_name (int category, const char *categoryname) { const char *retval; retval = _nl_locale_name_posix (category, categoryname); if (retval != NULL) return retval; return _nl_locale_name_default (); } lightspeed-1.2a.debian.1/intl/log.c000066400000000000000000000053071334064775200171400ustar00rootroot00000000000000/* Log file output. Copyright (C) 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Bruno Haible . */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include /* Print an ASCII string with quotes and escape sequences where needed. */ static void print_escaped (FILE *stream, const char *str) { putc ('"', stream); for (; *str != '\0'; str++) if (*str == '\n') { fputs ("\\n\"", stream); if (str[1] == '\0') return; fputs ("\n\"", stream); } else { if (*str == '"' || *str == '\\') putc ('\\', stream); putc (*str, stream); } putc ('"', stream); } /* Add to the log file an entry denoting a failed translation. */ void _nl_log_untranslated (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural) { static char *last_logfilename = NULL; static FILE *last_logfile = NULL; FILE *logfile; /* Can we reuse the last opened logfile? */ if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0) { /* Close the last used logfile. */ if (last_logfilename != NULL) { if (last_logfile != NULL) { fclose (last_logfile); last_logfile = NULL; } free (last_logfilename); last_logfilename = NULL; } /* Open the logfile. */ last_logfilename = (char *) malloc (strlen (logfilename) + 1); if (last_logfilename == NULL) return; strcpy (last_logfilename, logfilename); last_logfile = fopen (logfilename, "a"); if (last_logfile == NULL) return; } logfile = last_logfile; fprintf (logfile, "domain "); print_escaped (logfile, domainname); fprintf (logfile, "\nmsgid "); print_escaped (logfile, msgid1); if (plural) { fprintf (logfile, "\nmsgid_plural "); print_escaped (logfile, msgid2); fprintf (logfile, "\nmsgstr[0] \"\"\n"); } else fprintf (logfile, "\nmsgstr \"\"\n"); putc ('\n', logfile); } lightspeed-1.2a.debian.1/intl/ngettext.c000066400000000000000000000036741334064775200202260ustar00rootroot00000000000000/* Implementation of ngettext(3) function. Copyright (C) 1995, 1997, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef _LIBC # define __need_NULL # include #else # include /* Just for NULL. */ #endif #include "gettextP.h" #ifdef _LIBC # include #else # include "libgnuintl.h" #endif #include /* @@ end of prolog @@ */ /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define NGETTEXT __ngettext # define DCNGETTEXT __dcngettext #else # define NGETTEXT libintl_ngettext # define DCNGETTEXT libintl_dcngettext #endif /* Look up MSGID in the current default message catalog for the current LC_MESSAGES locale. If not found, returns MSGID itself (the default text). */ char * NGETTEXT (const char *msgid1, const char *msgid2, unsigned long int n) { return DCNGETTEXT (NULL, msgid1, msgid2, n, LC_MESSAGES); } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__ngettext, ngettext); #endif lightspeed-1.2a.debian.1/intl/os2compat.c000066400000000000000000000055071334064775200202700ustar00rootroot00000000000000/* OS/2 compatibility functions. Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #define OS2_AWARE #ifdef HAVE_CONFIG_H #include #endif #include #include #include /* A version of getenv() that works from DLLs */ extern unsigned long DosScanEnv (const unsigned char *pszName, unsigned char **ppszValue); char * _nl_getenv (const char *name) { unsigned char *value; if (DosScanEnv (name, &value)) return NULL; else return value; } /* A fixed size buffer. */ char libintl_nl_default_dirname[MAXPATHLEN+1]; char *_nlos2_libdir = NULL; char *_nlos2_localealiaspath = NULL; char *_nlos2_localedir = NULL; static __attribute__((constructor)) void nlos2_initialize () { char *root = getenv ("UNIXROOT"); char *gnulocaledir = getenv ("GNULOCALEDIR"); _nlos2_libdir = gnulocaledir; if (!_nlos2_libdir) { if (root) { size_t sl = strlen (root); _nlos2_libdir = (char *) malloc (sl + strlen (LIBDIR) + 1); memcpy (_nlos2_libdir, root, sl); memcpy (_nlos2_libdir + sl, LIBDIR, strlen (LIBDIR) + 1); } else _nlos2_libdir = LIBDIR; } _nlos2_localealiaspath = gnulocaledir; if (!_nlos2_localealiaspath) { if (root) { size_t sl = strlen (root); _nlos2_localealiaspath = (char *) malloc (sl + strlen (LOCALE_ALIAS_PATH) + 1); memcpy (_nlos2_localealiaspath, root, sl); memcpy (_nlos2_localealiaspath + sl, LOCALE_ALIAS_PATH, strlen (LOCALE_ALIAS_PATH) + 1); } else _nlos2_localealiaspath = LOCALE_ALIAS_PATH; } _nlos2_localedir = gnulocaledir; if (!_nlos2_localedir) { if (root) { size_t sl = strlen (root); _nlos2_localedir = (char *) malloc (sl + strlen (LOCALEDIR) + 1); memcpy (_nlos2_localedir, root, sl); memcpy (_nlos2_localedir + sl, LOCALEDIR, strlen (LOCALEDIR) + 1); } else _nlos2_localedir = LOCALEDIR; } if (strlen (_nlos2_localedir) <= MAXPATHLEN) strcpy (libintl_nl_default_dirname, _nlos2_localedir); } lightspeed-1.2a.debian.1/intl/os2compat.h000066400000000000000000000030261334064775200202670ustar00rootroot00000000000000/* OS/2 compatibility defines. This file is intended to be included from config.h Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* When included from os2compat.h we need all the original definitions */ #ifndef OS2_AWARE #undef LIBDIR #define LIBDIR _nlos2_libdir extern char *_nlos2_libdir; #undef LOCALEDIR #define LOCALEDIR _nlos2_localedir extern char *_nlos2_localedir; #undef LOCALE_ALIAS_PATH #define LOCALE_ALIAS_PATH _nlos2_localealiaspath extern char *_nlos2_localealiaspath; #endif #undef HAVE_STRCASECMP #define HAVE_STRCASECMP 1 #define strcasecmp stricmp #define strncasecmp strnicmp /* We have our own getenv() which works even if library is compiled as DLL */ #define getenv _nl_getenv /* Older versions of gettext used -1 as the value of LC_MESSAGES */ #define LC_MESSAGES_COMPAT (-1) lightspeed-1.2a.debian.1/intl/osdep.c000066400000000000000000000016471334064775200174740ustar00rootroot00000000000000/* OS dependent parts of libintl. Copyright (C) 2001-2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #if defined __EMX__ # include "os2compat.c" #else /* Avoid AIX compiler warning. */ typedef int dummy; #endif lightspeed-1.2a.debian.1/intl/plural-exp.c000066400000000000000000000076551334064775200204600ustar00rootroot00000000000000/* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "plural-exp.h" #if (defined __GNUC__ && !defined __APPLE_CC__) \ || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) /* These structs are the constant expression for the germanic plural form determination. It represents the expression "n != 1". */ static const struct expression plvar = { .nargs = 0, .operation = var, }; static const struct expression plone = { .nargs = 0, .operation = num, .val = { .num = 1 } }; struct expression GERMANIC_PLURAL = { .nargs = 2, .operation = not_equal, .val = { .args = { [0] = (struct expression *) &plvar, [1] = (struct expression *) &plone } } }; # define INIT_GERMANIC_PLURAL() #else /* For compilers without support for ISO C 99 struct/union initializers: Initialization at run-time. */ static struct expression plvar; static struct expression plone; struct expression GERMANIC_PLURAL; static void init_germanic_plural () { if (plone.val.num == 0) { plvar.nargs = 0; plvar.operation = var; plone.nargs = 0; plone.operation = num; plone.val.num = 1; GERMANIC_PLURAL.nargs = 2; GERMANIC_PLURAL.operation = not_equal; GERMANIC_PLURAL.val.args[0] = &plvar; GERMANIC_PLURAL.val.args[1] = &plone; } } # define INIT_GERMANIC_PLURAL() init_germanic_plural () #endif void internal_function EXTRACT_PLURAL_EXPRESSION (const char *nullentry, struct expression **pluralp, unsigned long int *npluralsp) { if (nullentry != NULL) { const char *plural; const char *nplurals; plural = strstr (nullentry, "plural="); nplurals = strstr (nullentry, "nplurals="); if (plural == NULL || nplurals == NULL) goto no_plural; else { char *endp; unsigned long int n; struct parse_args args; /* First get the number. */ nplurals += 9; while (*nplurals != '\0' && isspace ((unsigned char) *nplurals)) ++nplurals; if (!(*nplurals >= '0' && *nplurals <= '9')) goto no_plural; #if defined HAVE_STRTOUL || defined _LIBC n = strtoul (nplurals, &endp, 10); #else for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++) n = n * 10 + (*endp - '0'); #endif if (nplurals == endp) goto no_plural; *npluralsp = n; /* Due to the restrictions bison imposes onto the interface of the scanner function we have to put the input string and the result passed up from the parser into the same structure which address is passed down to the parser. */ plural += 7; args.cp = plural; if (PLURAL_PARSE (&args) != 0) goto no_plural; *pluralp = args.res; } } else { /* By default we are using the Germanic form: singular form only for `one', the plural form otherwise. Yes, this is also what English is using since English is a Germanic language. */ no_plural: INIT_GERMANIC_PLURAL (); *pluralp = &GERMANIC_PLURAL; *npluralsp = 2; } } lightspeed-1.2a.debian.1/intl/plural-exp.h000066400000000000000000000077371334064775200204660ustar00rootroot00000000000000/* Expression parsing and evaluation for plural form selection. Copyright (C) 2000-2003 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PLURAL_EXP_H #define _PLURAL_EXP_H #ifndef internal_function # define internal_function #endif #ifndef attribute_hidden # define attribute_hidden #endif /* This is the representation of the expressions to determine the plural form. */ struct expression { int nargs; /* Number of arguments. */ enum operator { /* Without arguments: */ var, /* The variable "n". */ num, /* Decimal number. */ /* Unary operators: */ lnot, /* Logical NOT. */ /* Binary operators: */ mult, /* Multiplication. */ divide, /* Division. */ module, /* Modulo operation. */ plus, /* Addition. */ minus, /* Subtraction. */ less_than, /* Comparison. */ greater_than, /* Comparison. */ less_or_equal, /* Comparison. */ greater_or_equal, /* Comparison. */ equal, /* Comparison for equality. */ not_equal, /* Comparison for inequality. */ land, /* Logical AND. */ lor, /* Logical OR. */ /* Ternary operators: */ qmop /* Question mark operator. */ } operation; union { unsigned long int num; /* Number value for `num'. */ struct expression *args[3]; /* Up to three arguments. */ } val; }; /* This is the data structure to pass information to the parser and get the result in a thread-safe way. */ struct parse_args { const char *cp; struct expression *res; }; /* Names for the libintl functions are a problem. This source code is used 1. in the GNU C Library library, 2. in the GNU libintl library, 3. in the GNU gettext tools. The function names in each situation must be different, to allow for binary incompatible changes in 'struct expression'. Furthermore, 1. in the GNU C Library library, the names have a __ prefix, 2.+3. in the GNU libintl library and in the GNU gettext tools, the names must follow ANSI C and not start with __. So we have to distinguish the three cases. */ #ifdef _LIBC # define FREE_EXPRESSION __gettext_free_exp # define PLURAL_PARSE __gettextparse # define GERMANIC_PLURAL __gettext_germanic_plural # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural #elif defined (IN_LIBINTL) # define FREE_EXPRESSION libintl_gettext_free_exp # define PLURAL_PARSE libintl_gettextparse # define GERMANIC_PLURAL libintl_gettext_germanic_plural # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural #else # define FREE_EXPRESSION free_plural_expression # define PLURAL_PARSE parse_plural_expression # define GERMANIC_PLURAL germanic_plural # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression #endif extern void FREE_EXPRESSION (struct expression *exp) internal_function; extern int PLURAL_PARSE (void *arg); extern struct expression GERMANIC_PLURAL attribute_hidden; extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry, struct expression **pluralp, unsigned long int *npluralsp) internal_function; #if !defined (_LIBC) && !defined (IN_LIBINTL) extern unsigned long int plural_eval (struct expression *pexp, unsigned long int n); #endif #endif /* _PLURAL_EXP_H */ lightspeed-1.2a.debian.1/intl/plural.c000066400000000000000000001107571334064775200176640ustar00rootroot00000000000000/* A Bison parser, made from plural.y by GNU bison 1.35. */ #define YYBISON 1 /* Identify Bison output. */ #define yyparse __gettextparse #define yylex __gettextlex #define yyerror __gettexterror #define yylval __gettextlval #define yychar __gettextchar #define yydebug __gettextdebug #define yynerrs __gettextnerrs # define EQUOP2 257 # define CMPOP2 258 # define ADDOP2 259 # define MULOP2 260 # define NUMBER 261 #line 1 "plural.y" /* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* The bison generated parser uses alloca. AIX 3 forces us to put this declaration at the beginning of the file. The declaration in bison's skeleton file comes too late. This must come before because may include arbitrary system headers. */ #if defined _AIX && !defined __GNUC__ #pragma alloca #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include "plural-exp.h" /* The main function generated by the parser is called __gettextparse, but we want it to be called PLURAL_PARSE. */ #ifndef _LIBC # define __gettextparse PLURAL_PARSE #endif #define YYLEX_PARAM &((struct parse_args *) arg)->cp #define YYPARSE_PARAM arg #line 49 "plural.y" #ifndef YYSTYPE typedef union { unsigned long int num; enum operator op; struct expression *exp; } yystype; # define YYSTYPE yystype # define YYSTYPE_IS_TRIVIAL 1 #endif #line 55 "plural.y" /* Prototypes for local functions. */ static int yylex (YYSTYPE *lval, const char **pexp); static void yyerror (const char *str); /* Allocation of expressions. */ static struct expression * new_exp (int nargs, enum operator op, struct expression * const *args) { int i; struct expression *newp; /* If any of the argument could not be malloc'ed, just return NULL. */ for (i = nargs - 1; i >= 0; i--) if (args[i] == NULL) goto fail; /* Allocate a new expression. */ newp = (struct expression *) malloc (sizeof (*newp)); if (newp != NULL) { newp->nargs = nargs; newp->operation = op; for (i = nargs - 1; i >= 0; i--) newp->val.args[i] = args[i]; return newp; } fail: for (i = nargs - 1; i >= 0; i--) FREE_EXPRESSION (args[i]); return NULL; } static inline struct expression * new_exp_0 (enum operator op) { return new_exp (0, op, NULL); } static inline struct expression * new_exp_1 (enum operator op, struct expression *right) { struct expression *args[1]; args[0] = right; return new_exp (1, op, args); } static struct expression * new_exp_2 (enum operator op, struct expression *left, struct expression *right) { struct expression *args[2]; args[0] = left; args[1] = right; return new_exp (2, op, args); } static inline struct expression * new_exp_3 (enum operator op, struct expression *bexp, struct expression *tbranch, struct expression *fbranch) { struct expression *args[3]; args[0] = bexp; args[1] = tbranch; args[2] = fbranch; return new_exp (3, op, args); } #ifndef YYDEBUG # define YYDEBUG 0 #endif #define YYFINAL 27 #define YYFLAG -32768 #define YYNTBASE 16 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */ #define YYTRANSLATE(x) ((unsigned)(x) <= 261 ? yytranslate[x] : 18) /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */ static const char yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 10, 2, 2, 2, 2, 5, 2, 14, 15, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 12, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 6, 7, 8, 9, 11 }; #if YYDEBUG static const short yyprhs[] = { 0, 0, 2, 8, 12, 16, 20, 24, 28, 32, 35, 37, 39 }; static const short yyrhs[] = { 17, 0, 17, 3, 17, 12, 17, 0, 17, 4, 17, 0, 17, 5, 17, 0, 17, 6, 17, 0, 17, 7, 17, 0, 17, 8, 17, 0, 17, 9, 17, 0, 10, 17, 0, 13, 0, 11, 0, 14, 17, 15, 0 }; #endif #if YYDEBUG /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const short yyrline[] = { 0, 150, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 199 }; #endif #if (YYDEBUG) || defined YYERROR_VERBOSE /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */ static const char *const yytname[] = { "$", "error", "$undefined.", "'?'", "'|'", "'&'", "EQUOP2", "CMPOP2", "ADDOP2", "MULOP2", "'!'", "NUMBER", "':'", "'n'", "'('", "')'", "start", "exp", 0 }; #endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const short yyr1[] = { 0, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const short yyr2[] = { 0, 1, 5, 3, 3, 3, 3, 3, 3, 2, 1, 1, 3 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const short yydefact[] = { 0, 0, 11, 10, 0, 1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 3, 4, 5, 6, 7, 8, 0, 2, 0, 0, 0 }; static const short yydefgoto[] = { 25, 5 }; static const short yypact[] = { -9, -9,-32768,-32768, -9, 34,-32768, 11, -9, -9, -9, -9, -9, -9, -9,-32768, 24, 39, 43, 16, 26, -3,-32768, -9, 34, 21, 53,-32768 }; static const short yypgoto[] = { -32768, -1 }; #define YYLAST 53 static const short yytable[] = { 6, 1, 2, 7, 3, 4, 14, 16, 17, 18, 19, 20, 21, 22, 8, 9, 10, 11, 12, 13, 14, 26, 24, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 13, 14, 23, 8, 9, 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 11, 12, 13, 14, 27 }; static const short yycheck[] = { 1, 10, 11, 4, 13, 14, 9, 8, 9, 10, 11, 12, 13, 14, 3, 4, 5, 6, 7, 8, 9, 0, 23, 7, 8, 9, 15, 3, 4, 5, 6, 7, 8, 9, 8, 9, 12, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 6, 7, 8, 9, 0 }; #define YYPURE 1 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ #line 3 "/home/haible/gnu/arch/linuxlibc6/share/bison/bison.simple" /* Skeleton output parser for bison, Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation in version 1.24 of Bison. */ /* This is the parser code that is written into each bison parser when the %semantic_parser declaration is not specified in the grammar. It was written by Richard Stallman by simplifying the hairy parser used when %semantic_parser is specified. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE) /* The parser invokes alloca or malloc; define the necessary symbols. */ # if YYSTACK_USE_ALLOCA # define YYSTACK_ALLOC alloca # else # ifndef YYSTACK_USE_ALLOCA # if defined (alloca) || defined (_ALLOCA_H) # define YYSTACK_ALLOC alloca # else # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # else # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif # define YYSTACK_ALLOC malloc # define YYSTACK_FREE free # endif #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */ #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { short yyss; YYSTYPE yyvs; # if YYLSP_NEEDED YYLTYPE yyls; # endif }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # if YYLSP_NEEDED # define YYSTACK_BYTES(N) \ ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAX) # else # define YYSTACK_BYTES(N) \ ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAX) # endif /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (0) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack, Stack, yysize); \ Stack = &yyptr->Stack; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) #endif #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ #endif #if ! defined (YYSIZE_T) && defined (size_t) # define YYSIZE_T size_t #endif #if ! defined (YYSIZE_T) # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif #endif #if ! defined (YYSIZE_T) # define YYSIZE_T unsigned int #endif #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY -2 #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrlab1 /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yychar1 = YYTRANSLATE (yychar); \ YYPOPSTACK; \ goto yybackup; \ } \ else \ { \ yyerror ("syntax error: cannot back up"); \ YYERROR; \ } \ while (0) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Compute the default location (before the actions are run). When YYLLOC_DEFAULT is run, CURRENT is set the location of the first token. By default, to implement support for ranges, extend its range to the last symbol. */ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ Current.last_line = Rhs[N].last_line; \ Current.last_column = Rhs[N].last_column; #endif /* YYLEX -- calling `yylex' with the right arguments. */ #if YYPURE # if YYLSP_NEEDED # ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) # else # define YYLEX yylex (&yylval, &yylloc) # endif # else /* !YYLSP_NEEDED */ # ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, YYLEX_PARAM) # else # define YYLEX yylex (&yylval) # endif # endif /* !YYLSP_NEEDED */ #else /* !YYPURE */ # define YYLEX yylex () #endif /* !YYPURE */ /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #if YYMAXDEPTH == 0 # undef YYMAXDEPTH #endif #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #ifdef YYERROR_VERBOSE # ifndef yystrlen # if defined (__GLIBC__) && defined (_STRING_H) # define yystrlen strlen # else /* Return the length of YYSTR. */ static YYSIZE_T # if defined (__STDC__) || defined (__cplusplus) yystrlen (const char *yystr) # else yystrlen (yystr) const char *yystr; # endif { register const char *yys = yystr; while (*yys++ != '\0') continue; return yys - yystr - 1; } # endif # endif # ifndef yystpcpy # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * # if defined (__STDC__) || defined (__cplusplus) yystpcpy (char *yydest, const char *yysrc) # else yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; # endif { register char *yyd = yydest; register const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif #endif #line 315 "/home/haible/gnu/arch/linuxlibc6/share/bison/bison.simple" /* The user can define YYPARSE_PARAM as the name of an argument to be passed into yyparse. The argument should have type void *. It should actually point to an object. Grammar actions can access the variable by casting it to the proper pointer type. */ #ifdef YYPARSE_PARAM # if defined (__STDC__) || defined (__cplusplus) # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM # define YYPARSE_PARAM_DECL # else # define YYPARSE_PARAM_ARG YYPARSE_PARAM # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; # endif #else /* !YYPARSE_PARAM */ # define YYPARSE_PARAM_ARG # define YYPARSE_PARAM_DECL #endif /* !YYPARSE_PARAM */ /* Prevent warning if -Wstrict-prototypes. */ #ifdef __GNUC__ # ifdef YYPARSE_PARAM int yyparse (void *); # else int yyparse (void); # endif #endif /* YY_DECL_VARIABLES -- depending whether we use a pure parser, variables are global, or local to YYPARSE. */ #define YY_DECL_NON_LSP_VARIABLES \ /* The lookahead symbol. */ \ int yychar; \ \ /* The semantic value of the lookahead symbol. */ \ YYSTYPE yylval; \ \ /* Number of parse errors so far. */ \ int yynerrs; #if YYLSP_NEEDED # define YY_DECL_VARIABLES \ YY_DECL_NON_LSP_VARIABLES \ \ /* Location data for the lookahead symbol. */ \ YYLTYPE yylloc; #else # define YY_DECL_VARIABLES \ YY_DECL_NON_LSP_VARIABLES #endif /* If nonreentrant, generate the variables here. */ #if !YYPURE YY_DECL_VARIABLES #endif /* !YYPURE */ int yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL { /* If reentrant, generate the variables here. */ #if YYPURE YY_DECL_VARIABLES #endif /* !YYPURE */ register int yystate; register int yyn; int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* Lookahead token as an internal (translated) token number. */ int yychar1 = 0; /* Three stacks and their tools: `yyss': related to states, `yyvs': related to semantic values, `yyls': related to locations. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ short yyssa[YYINITDEPTH]; short *yyss = yyssa; register short *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; register YYSTYPE *yyvsp; #if YYLSP_NEEDED /* The location stack. */ YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls = yylsa; YYLTYPE *yylsp; #endif #if YYLSP_NEEDED # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) #else # define YYPOPSTACK (yyvsp--, yyssp--) #endif YYSIZE_T yystacksize = YYINITDEPTH; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYLSP_NEEDED YYLTYPE yyloc; #endif /* When reducing, the number of symbols on the RHS of the reduced rule. */ int yylen; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; #if YYLSP_NEEDED yylsp = yyls; #endif goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. so pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyssp >= yyss + yystacksize - 1) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; short *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. */ # if YYLSP_NEEDED YYLTYPE *yyls1 = yyls; /* This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yyls1, yysize * sizeof (*yylsp), &yystacksize); yyls = yyls1; # else yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); # endif yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyoverflowlab; # else /* Extend the stack our own way. */ if (yystacksize >= YYMAXDEPTH) goto yyoverflowlab; yystacksize *= 2; if (yystacksize > YYMAXDEPTH) yystacksize = YYMAXDEPTH; { short *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyoverflowlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); # if YYLSP_NEEDED YYSTACK_RELOCATE (yyls); # endif # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; #if YYLSP_NEEDED yylsp = yyls + yysize - 1; #endif YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyssp >= yyss + yystacksize - 1) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. */ /* Read a lookahead token if we need one and don't already have one. */ /* yyresume: */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYFLAG) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* yychar is either YYEMPTY or YYEOF or a valid token in external form. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } /* Convert token to internal form (in yychar1) for indexing tables with */ if (yychar <= 0) /* This means end of input. */ { yychar1 = 0; yychar = YYEOF; /* Don't call YYLEX any more */ YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yychar1 = YYTRANSLATE (yychar); #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { YYFPRINTF (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); /* Give the individual parser a way to print the precise meaning of a token, for further debugging info. */ # ifdef YYPRINT YYPRINT (stderr, yychar, yylval); # endif YYFPRINTF (stderr, ")\n"); } #endif } yyn += yychar1; if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) goto yydefault; yyn = yytable[yyn]; /* yyn is what to do for this token type in this state. Negative => reduce, -yyn is rule number. Positive => shift, yyn is new state. New state is final state => don't bother to shift, just return success. 0, or most negative number => error. */ if (yyn < 0) { if (yyn == YYFLAG) goto yyerrlab; yyn = -yyn; goto yyreduce; } else if (yyn == 0) goto yyerrlab; if (yyn == YYFINAL) YYACCEPT; /* Shift the lookahead token. */ YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1])); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; yystate = yyn; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to the semantic value of the lookahead token. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; #if YYLSP_NEEDED /* Similarly for the default location. Let the user run additional commands if for instance locations are ranges. */ yyloc = yylsp[1-yylen]; YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); #endif #if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { int yyi; YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", yyn, yyrline[yyn]); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++) YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); } #endif switch (yyn) { case 1: #line 151 "plural.y" { if (yyvsp[0].exp == NULL) YYABORT; ((struct parse_args *) arg)->res = yyvsp[0].exp; } break; case 2: #line 159 "plural.y" { yyval.exp = new_exp_3 (qmop, yyvsp[-4].exp, yyvsp[-2].exp, yyvsp[0].exp); } break; case 3: #line 163 "plural.y" { yyval.exp = new_exp_2 (lor, yyvsp[-2].exp, yyvsp[0].exp); } break; case 4: #line 167 "plural.y" { yyval.exp = new_exp_2 (land, yyvsp[-2].exp, yyvsp[0].exp); } break; case 5: #line 171 "plural.y" { yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); } break; case 6: #line 175 "plural.y" { yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); } break; case 7: #line 179 "plural.y" { yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); } break; case 8: #line 183 "plural.y" { yyval.exp = new_exp_2 (yyvsp[-1].op, yyvsp[-2].exp, yyvsp[0].exp); } break; case 9: #line 187 "plural.y" { yyval.exp = new_exp_1 (lnot, yyvsp[0].exp); } break; case 10: #line 191 "plural.y" { yyval.exp = new_exp_0 (var); } break; case 11: #line 195 "plural.y" { if ((yyval.exp = new_exp_0 (num)) != NULL) yyval.exp->val.num = yyvsp[0].num; } break; case 12: #line 200 "plural.y" { yyval.exp = yyvsp[-1].exp; } break; } #line 705 "/home/haible/gnu/arch/linuxlibc6/share/bison/bison.simple" yyvsp -= yylen; yyssp -= yylen; #if YYLSP_NEEDED yylsp -= yylen; #endif #if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); } #endif *++yyvsp = yyval; #if YYLSP_NEEDED *++yylsp = yyloc; #endif /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTBASE] + *yyssp; if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTBASE]; goto yynewstate; /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #ifdef YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) { YYSIZE_T yysize = 0; char *yymsg; int yyx, yycount; yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) yysize += yystrlen (yytname[yyx]) + 15, yycount++; yysize += yystrlen ("parse error, unexpected ") + 1; yysize += yystrlen (yytname[YYTRANSLATE (yychar)]); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { char *yyp = yystpcpy (yymsg, "parse error, unexpected "); yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]); if (yycount < 5) { yycount = 0; for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) { const char *yyq = ! yycount ? ", expecting " : " or "; yyp = yystpcpy (yyp, yyq); yyp = yystpcpy (yyp, yytname[yyx]); yycount++; } } yyerror (yymsg); YYSTACK_FREE (yymsg); } else yyerror ("parse error; also virtual memory exhausted"); } else #endif /* defined (YYERROR_VERBOSE) */ yyerror ("parse error"); } goto yyerrlab1; /*--------------------------------------------------. | yyerrlab1 -- error raised explicitly by an action | `--------------------------------------------------*/ yyerrlab1: if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ /* return failure if at end of input */ if (yychar == YYEOF) YYABORT; YYDPRINTF ((stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1])); yychar = YYEMPTY; } /* Else will try to reuse lookahead token after shifting the error token. */ yyerrstatus = 3; /* Each real token shifted decrements this */ goto yyerrhandle; /*-------------------------------------------------------------------. | yyerrdefault -- current state does not do anything special for the | | error token. | `-------------------------------------------------------------------*/ yyerrdefault: #if 0 /* This is wrong; only states that explicitly want error tokens should shift them. */ /* If its default is to accept any token, ok. Otherwise pop it. */ yyn = yydefact[yystate]; if (yyn) goto yydefault; #endif /*---------------------------------------------------------------. | yyerrpop -- pop the current state because it cannot handle the | | error token | `---------------------------------------------------------------*/ yyerrpop: if (yyssp == yyss) YYABORT; yyvsp--; yystate = *--yyssp; #if YYLSP_NEEDED yylsp--; #endif #if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "Error: state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); } #endif /*--------------. | yyerrhandle. | `--------------*/ yyerrhandle: yyn = yypact[yystate]; if (yyn == YYFLAG) goto yyerrdefault; yyn += YYTERROR; if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) goto yyerrdefault; yyn = yytable[yyn]; if (yyn < 0) { if (yyn == YYFLAG) goto yyerrpop; yyn = -yyn; goto yyreduce; } else if (yyn == 0) goto yyerrpop; if (yyn == YYFINAL) YYACCEPT; YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; #if YYLSP_NEEDED *++yylsp = yylloc; #endif yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; /*---------------------------------------------. | yyoverflowab -- parser overflow comes here. | `---------------------------------------------*/ yyoverflowlab: yyerror ("parser stack overflow"); yyresult = 2; /* Fall through. */ yyreturn: #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif return yyresult; } #line 205 "plural.y" void internal_function FREE_EXPRESSION (struct expression *exp) { if (exp == NULL) return; /* Handle the recursive case. */ switch (exp->nargs) { case 3: FREE_EXPRESSION (exp->val.args[2]); /* FALLTHROUGH */ case 2: FREE_EXPRESSION (exp->val.args[1]); /* FALLTHROUGH */ case 1: FREE_EXPRESSION (exp->val.args[0]); /* FALLTHROUGH */ default: break; } free (exp); } static int yylex (YYSTYPE *lval, const char **pexp) { const char *exp = *pexp; int result; while (1) { if (exp[0] == '\0') { *pexp = exp; return YYEOF; } if (exp[0] != ' ' && exp[0] != '\t') break; ++exp; } result = *exp++; switch (result) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { unsigned long int n = result - '0'; while (exp[0] >= '0' && exp[0] <= '9') { n *= 10; n += exp[0] - '0'; ++exp; } lval->num = n; result = NUMBER; } break; case '=': if (exp[0] == '=') { ++exp; lval->op = equal; result = EQUOP2; } else result = YYERRCODE; break; case '!': if (exp[0] == '=') { ++exp; lval->op = not_equal; result = EQUOP2; } break; case '&': case '|': if (exp[0] == result) ++exp; else result = YYERRCODE; break; case '<': if (exp[0] == '=') { ++exp; lval->op = less_or_equal; } else lval->op = less_than; result = CMPOP2; break; case '>': if (exp[0] == '=') { ++exp; lval->op = greater_or_equal; } else lval->op = greater_than; result = CMPOP2; break; case '*': lval->op = mult; result = MULOP2; break; case '/': lval->op = divide; result = MULOP2; break; case '%': lval->op = module; result = MULOP2; break; case '+': lval->op = plus; result = ADDOP2; break; case '-': lval->op = minus; result = ADDOP2; break; case 'n': case '?': case ':': case '(': case ')': /* Nothing, just return the character. */ break; case ';': case '\n': case '\0': /* Be safe and let the user call this function again. */ --exp; result = YYEOF; break; default: result = YYERRCODE; #if YYDEBUG != 0 --exp; #endif break; } *pexp = exp; return result; } static void yyerror (const char *str) { /* Do nothing. We don't print error messages here. */ } lightspeed-1.2a.debian.1/intl/plural.y000066400000000000000000000162751334064775200177120ustar00rootroot00000000000000%{ /* Expression parsing for plural form selection. Copyright (C) 2000-2001, 2003 Free Software Foundation, Inc. Written by Ulrich Drepper , 2000. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* The bison generated parser uses alloca. AIX 3 forces us to put this declaration at the beginning of the file. The declaration in bison's skeleton file comes too late. This must come before because may include arbitrary system headers. */ #if defined _AIX && !defined __GNUC__ #pragma alloca #endif #ifdef HAVE_CONFIG_H # include #endif #include #include #include "plural-exp.h" /* The main function generated by the parser is called __gettextparse, but we want it to be called PLURAL_PARSE. */ #ifndef _LIBC # define __gettextparse PLURAL_PARSE #endif #define YYLEX_PARAM &((struct parse_args *) arg)->cp #define YYPARSE_PARAM arg %} %pure_parser %expect 7 %union { unsigned long int num; enum operator op; struct expression *exp; } %{ /* Prototypes for local functions. */ static int yylex (YYSTYPE *lval, const char **pexp); static void yyerror (const char *str); /* Allocation of expressions. */ static struct expression * new_exp (int nargs, enum operator op, struct expression * const *args) { int i; struct expression *newp; /* If any of the argument could not be malloc'ed, just return NULL. */ for (i = nargs - 1; i >= 0; i--) if (args[i] == NULL) goto fail; /* Allocate a new expression. */ newp = (struct expression *) malloc (sizeof (*newp)); if (newp != NULL) { newp->nargs = nargs; newp->operation = op; for (i = nargs - 1; i >= 0; i--) newp->val.args[i] = args[i]; return newp; } fail: for (i = nargs - 1; i >= 0; i--) FREE_EXPRESSION (args[i]); return NULL; } static inline struct expression * new_exp_0 (enum operator op) { return new_exp (0, op, NULL); } static inline struct expression * new_exp_1 (enum operator op, struct expression *right) { struct expression *args[1]; args[0] = right; return new_exp (1, op, args); } static struct expression * new_exp_2 (enum operator op, struct expression *left, struct expression *right) { struct expression *args[2]; args[0] = left; args[1] = right; return new_exp (2, op, args); } static inline struct expression * new_exp_3 (enum operator op, struct expression *bexp, struct expression *tbranch, struct expression *fbranch) { struct expression *args[3]; args[0] = bexp; args[1] = tbranch; args[2] = fbranch; return new_exp (3, op, args); } %} /* This declares that all operators have the same associativity and the precedence order as in C. See [Harbison, Steele: C, A Reference Manual]. There is no unary minus and no bitwise operators. Operators with the same syntactic behaviour have been merged into a single token, to save space in the array generated by bison. */ %right '?' /* ? */ %left '|' /* || */ %left '&' /* && */ %left EQUOP2 /* == != */ %left CMPOP2 /* < > <= >= */ %left ADDOP2 /* + - */ %left MULOP2 /* * / % */ %right '!' /* ! */ %token EQUOP2 CMPOP2 ADDOP2 MULOP2 %token NUMBER %type exp %% start: exp { if ($1 == NULL) YYABORT; ((struct parse_args *) arg)->res = $1; } ; exp: exp '?' exp ':' exp { $$ = new_exp_3 (qmop, $1, $3, $5); } | exp '|' exp { $$ = new_exp_2 (lor, $1, $3); } | exp '&' exp { $$ = new_exp_2 (land, $1, $3); } | exp EQUOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp CMPOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp ADDOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | exp MULOP2 exp { $$ = new_exp_2 ($2, $1, $3); } | '!' exp { $$ = new_exp_1 (lnot, $2); } | 'n' { $$ = new_exp_0 (var); } | NUMBER { if (($$ = new_exp_0 (num)) != NULL) $$->val.num = $1; } | '(' exp ')' { $$ = $2; } ; %% void internal_function FREE_EXPRESSION (struct expression *exp) { if (exp == NULL) return; /* Handle the recursive case. */ switch (exp->nargs) { case 3: FREE_EXPRESSION (exp->val.args[2]); /* FALLTHROUGH */ case 2: FREE_EXPRESSION (exp->val.args[1]); /* FALLTHROUGH */ case 1: FREE_EXPRESSION (exp->val.args[0]); /* FALLTHROUGH */ default: break; } free (exp); } static int yylex (YYSTYPE *lval, const char **pexp) { const char *exp = *pexp; int result; while (1) { if (exp[0] == '\0') { *pexp = exp; return YYEOF; } if (exp[0] != ' ' && exp[0] != '\t') break; ++exp; } result = *exp++; switch (result) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { unsigned long int n = result - '0'; while (exp[0] >= '0' && exp[0] <= '9') { n *= 10; n += exp[0] - '0'; ++exp; } lval->num = n; result = NUMBER; } break; case '=': if (exp[0] == '=') { ++exp; lval->op = equal; result = EQUOP2; } else result = YYERRCODE; break; case '!': if (exp[0] == '=') { ++exp; lval->op = not_equal; result = EQUOP2; } break; case '&': case '|': if (exp[0] == result) ++exp; else result = YYERRCODE; break; case '<': if (exp[0] == '=') { ++exp; lval->op = less_or_equal; } else lval->op = less_than; result = CMPOP2; break; case '>': if (exp[0] == '=') { ++exp; lval->op = greater_or_equal; } else lval->op = greater_than; result = CMPOP2; break; case '*': lval->op = mult; result = MULOP2; break; case '/': lval->op = divide; result = MULOP2; break; case '%': lval->op = module; result = MULOP2; break; case '+': lval->op = plus; result = ADDOP2; break; case '-': lval->op = minus; result = ADDOP2; break; case 'n': case '?': case ':': case '(': case ')': /* Nothing, just return the character. */ break; case ';': case '\n': case '\0': /* Be safe and let the user call this function again. */ --exp; result = YYEOF; break; default: result = YYERRCODE; #if YYDEBUG != 0 --exp; #endif break; } *pexp = exp; return result; } static void yyerror (const char *str) { /* Do nothing. We don't print error messages here. */ } lightspeed-1.2a.debian.1/intl/printf-args.c000066400000000000000000000062571334064775200206200ustar00rootroot00000000000000/* Decomposed printf argument list. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif /* Specification. */ #include "printf-args.h" #ifdef STATIC STATIC #endif int printf_fetchargs (va_list args, arguments *a) { size_t i; argument *ap; for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++) switch (ap->type) { case TYPE_SCHAR: ap->a.a_schar = va_arg (args, /*signed char*/ int); break; case TYPE_UCHAR: ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); break; case TYPE_SHORT: ap->a.a_short = va_arg (args, /*short*/ int); break; case TYPE_USHORT: ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); break; case TYPE_INT: ap->a.a_int = va_arg (args, int); break; case TYPE_UINT: ap->a.a_uint = va_arg (args, unsigned int); break; case TYPE_LONGINT: ap->a.a_longint = va_arg (args, long int); break; case TYPE_ULONGINT: ap->a.a_ulongint = va_arg (args, unsigned long int); break; #ifdef HAVE_LONG_LONG case TYPE_LONGLONGINT: ap->a.a_longlongint = va_arg (args, long long int); break; case TYPE_ULONGLONGINT: ap->a.a_ulonglongint = va_arg (args, unsigned long long int); break; #endif case TYPE_DOUBLE: ap->a.a_double = va_arg (args, double); break; #ifdef HAVE_LONG_DOUBLE case TYPE_LONGDOUBLE: ap->a.a_longdouble = va_arg (args, long double); break; #endif case TYPE_CHAR: ap->a.a_char = va_arg (args, int); break; #ifdef HAVE_WINT_T case TYPE_WIDE_CHAR: ap->a.a_wide_char = va_arg (args, wint_t); break; #endif case TYPE_STRING: ap->a.a_string = va_arg (args, const char *); break; #ifdef HAVE_WCHAR_T case TYPE_WIDE_STRING: ap->a.a_wide_string = va_arg (args, const wchar_t *); break; #endif case TYPE_POINTER: ap->a.a_pointer = va_arg (args, void *); break; case TYPE_COUNT_SCHAR_POINTER: ap->a.a_count_schar_pointer = va_arg (args, signed char *); break; case TYPE_COUNT_SHORT_POINTER: ap->a.a_count_short_pointer = va_arg (args, short *); break; case TYPE_COUNT_INT_POINTER: ap->a.a_count_int_pointer = va_arg (args, int *); break; case TYPE_COUNT_LONGINT_POINTER: ap->a.a_count_longint_pointer = va_arg (args, long int *); break; #ifdef HAVE_LONG_LONG case TYPE_COUNT_LONGLONGINT_POINTER: ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); break; #endif default: /* Unknown type. */ return -1; } return 0; } lightspeed-1.2a.debian.1/intl/printf-args.h000066400000000000000000000055061334064775200206210ustar00rootroot00000000000000/* Decomposed printf argument list. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PRINTF_ARGS_H #define _PRINTF_ARGS_H /* Get size_t. */ #include /* Get wchar_t. */ #ifdef HAVE_WCHAR_T # include #endif /* Get wint_t. */ #ifdef HAVE_WINT_T # include #endif /* Get va_list. */ #include /* Argument types */ typedef enum { TYPE_NONE, TYPE_SCHAR, TYPE_UCHAR, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_UINT, TYPE_LONGINT, TYPE_ULONGINT, #ifdef HAVE_LONG_LONG TYPE_LONGLONGINT, TYPE_ULONGLONGINT, #endif TYPE_DOUBLE, #ifdef HAVE_LONG_DOUBLE TYPE_LONGDOUBLE, #endif TYPE_CHAR, #ifdef HAVE_WINT_T TYPE_WIDE_CHAR, #endif TYPE_STRING, #ifdef HAVE_WCHAR_T TYPE_WIDE_STRING, #endif TYPE_POINTER, TYPE_COUNT_SCHAR_POINTER, TYPE_COUNT_SHORT_POINTER, TYPE_COUNT_INT_POINTER, TYPE_COUNT_LONGINT_POINTER #ifdef HAVE_LONG_LONG , TYPE_COUNT_LONGLONGINT_POINTER #endif } arg_type; /* Polymorphic argument */ typedef struct { arg_type type; union { signed char a_schar; unsigned char a_uchar; short a_short; unsigned short a_ushort; int a_int; unsigned int a_uint; long int a_longint; unsigned long int a_ulongint; #ifdef HAVE_LONG_LONG long long int a_longlongint; unsigned long long int a_ulonglongint; #endif float a_float; double a_double; #ifdef HAVE_LONG_DOUBLE long double a_longdouble; #endif int a_char; #ifdef HAVE_WINT_T wint_t a_wide_char; #endif const char* a_string; #ifdef HAVE_WCHAR_T const wchar_t* a_wide_string; #endif void* a_pointer; signed char * a_count_schar_pointer; short * a_count_short_pointer; int * a_count_int_pointer; long int * a_count_longint_pointer; #ifdef HAVE_LONG_LONG long long int * a_count_longlongint_pointer; #endif } a; } argument; typedef struct { size_t count; argument *arg; } arguments; /* Fetch the arguments, putting them into a. */ #ifdef STATIC STATIC #else extern #endif int printf_fetchargs (va_list args, arguments *a); #endif /* _PRINTF_ARGS_H */ lightspeed-1.2a.debian.1/intl/printf-parse.c000066400000000000000000000273371334064775200210000ustar00rootroot00000000000000/* Formatted output to strings. Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif /* Specification. */ #if WIDE_CHAR_VERSION # include "wprintf-parse.h" #else # include "printf-parse.h" #endif /* Get size_t, NULL. */ #include /* Get intmax_t. */ #if HAVE_STDINT_H_WITH_UINTMAX # include #endif #if HAVE_INTTYPES_H_WITH_UINTMAX # include #endif /* malloc(), realloc(), free(). */ #include /* Checked size_t computations. */ #include "xsize.h" #if WIDE_CHAR_VERSION # define PRINTF_PARSE wprintf_parse # define CHAR_T wchar_t # define DIRECTIVE wchar_t_directive # define DIRECTIVES wchar_t_directives #else # define PRINTF_PARSE printf_parse # define CHAR_T char # define DIRECTIVE char_directive # define DIRECTIVES char_directives #endif #ifdef STATIC STATIC #endif int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { const CHAR_T *cp = format; /* pointer into format */ size_t arg_posn = 0; /* number of regular arguments consumed */ size_t d_allocated; /* allocated elements of d->dir */ size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; d->count = 0; d_allocated = 1; d->dir = malloc (d_allocated * sizeof (DIRECTIVE)); if (d->dir == NULL) /* Out of memory. */ return -1; a->count = 0; a_allocated = 0; a->arg = NULL; #define REGISTER_ARG(_index_,_type_) \ { \ size_t n = (_index_); \ if (n >= a_allocated) \ { \ size_t memory_size; \ argument *memory; \ \ a_allocated = xtimes (a_allocated, 2); \ if (a_allocated <= n) \ a_allocated = xsum (n, 1); \ memory_size = xtimes (a_allocated, sizeof (argument)); \ if (size_overflow_p (memory_size)) \ /* Overflow, would lead to out of memory. */ \ goto error; \ memory = (a->arg \ ? realloc (a->arg, memory_size) \ : malloc (memory_size)); \ if (memory == NULL) \ /* Out of memory. */ \ goto error; \ a->arg = memory; \ } \ while (a->count <= n) \ a->arg[a->count++].type = TYPE_NONE; \ if (a->arg[n].type == TYPE_NONE) \ a->arg[n].type = (_type_); \ else if (a->arg[n].type != (_type_)) \ /* Ambiguous type for positional argument. */ \ goto error; \ } while (*cp != '\0') { CHAR_T c = *cp++; if (c == '%') { size_t arg_index = ARG_NONE; DIRECTIVE *dp = &d->dir[d->count];/* pointer to next directive */ /* Initialize the next directive. */ dp->dir_start = cp - 1; dp->flags = 0; dp->width_start = NULL; dp->width_end = NULL; dp->width_arg_index = ARG_NONE; dp->precision_start = NULL; dp->precision_end = NULL; dp->precision_arg_index = ARG_NONE; dp->arg_index = ARG_NONE; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; arg_index = n - 1; cp = np + 1; } } /* Read the flags. */ for (;;) { if (*cp == '\'') { dp->flags |= FLAG_GROUP; cp++; } else if (*cp == '-') { dp->flags |= FLAG_LEFT; cp++; } else if (*cp == '+') { dp->flags |= FLAG_SHOWSIGN; cp++; } else if (*cp == ' ') { dp->flags |= FLAG_SPACE; cp++; } else if (*cp == '#') { dp->flags |= FLAG_ALT; cp++; } else if (*cp == '0') { dp->flags |= FLAG_ZERO; cp++; } else break; } /* Parse the field width. */ if (*cp == '*') { dp->width_start = cp; cp++; dp->width_end = cp; if (max_width_length < 1) max_width_length = 1; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; dp->width_arg_index = n - 1; cp = np + 1; } } if (dp->width_arg_index == ARG_NONE) { dp->width_arg_index = arg_posn++; if (dp->width_arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->width_arg_index, TYPE_INT); } else if (*cp >= '0' && *cp <= '9') { size_t width_length; dp->width_start = cp; for (; *cp >= '0' && *cp <= '9'; cp++) ; dp->width_end = cp; width_length = dp->width_end - dp->width_start; if (max_width_length < width_length) max_width_length = width_length; } /* Parse the precision. */ if (*cp == '.') { cp++; if (*cp == '*') { dp->precision_start = cp - 1; cp++; dp->precision_end = cp; if (max_precision_length < 2) max_precision_length = 2; /* Test for positional argument. */ if (*cp >= '0' && *cp <= '9') { const CHAR_T *np; for (np = cp; *np >= '0' && *np <= '9'; np++) ; if (*np == '$') { size_t n = 0; for (np = cp; *np >= '0' && *np <= '9'; np++) n = xsum (xtimes (n, 10), *np - '0'); if (n == 0) /* Positional argument 0. */ goto error; if (size_overflow_p (n)) /* n too large, would lead to out of memory later. */ goto error; dp->precision_arg_index = n - 1; cp = np + 1; } } if (dp->precision_arg_index == ARG_NONE) { dp->precision_arg_index = arg_posn++; if (dp->precision_arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->precision_arg_index, TYPE_INT); } else { size_t precision_length; dp->precision_start = cp - 1; for (; *cp >= '0' && *cp <= '9'; cp++) ; dp->precision_end = cp; precision_length = dp->precision_end - dp->precision_start; if (max_precision_length < precision_length) max_precision_length = precision_length; } } { arg_type type; /* Parse argument type/size specifiers. */ { int flags = 0; for (;;) { if (*cp == 'h') { flags |= (1 << (flags & 1)); cp++; } else if (*cp == 'L') { flags |= 4; cp++; } else if (*cp == 'l') { flags += 8; cp++; } #ifdef HAVE_INTMAX_T else if (*cp == 'j') { if (sizeof (intmax_t) > sizeof (long)) { /* intmax_t = long long */ flags += 16; } else if (sizeof (intmax_t) > sizeof (int)) { /* intmax_t = long */ flags += 8; } cp++; } #endif else if (*cp == 'z' || *cp == 'Z') { /* 'z' is standardized in ISO C 99, but glibc uses 'Z' because the warning facility in gcc-2.95.2 understands only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ if (sizeof (size_t) > sizeof (long)) { /* size_t = long long */ flags += 16; } else if (sizeof (size_t) > sizeof (int)) { /* size_t = long */ flags += 8; } cp++; } else if (*cp == 't') { if (sizeof (ptrdiff_t) > sizeof (long)) { /* ptrdiff_t = long long */ flags += 16; } else if (sizeof (ptrdiff_t) > sizeof (int)) { /* ptrdiff_t = long */ flags += 8; } cp++; } else break; } /* Read the conversion character. */ c = *cp++; switch (c) { case 'd': case 'i': #ifdef HAVE_LONG_LONG if (flags >= 16 || (flags & 4)) type = TYPE_LONGLONGINT; else #endif if (flags >= 8) type = TYPE_LONGINT; else if (flags & 2) type = TYPE_SCHAR; else if (flags & 1) type = TYPE_SHORT; else type = TYPE_INT; break; case 'o': case 'u': case 'x': case 'X': #ifdef HAVE_LONG_LONG if (flags >= 16 || (flags & 4)) type = TYPE_ULONGLONGINT; else #endif if (flags >= 8) type = TYPE_ULONGINT; else if (flags & 2) type = TYPE_UCHAR; else if (flags & 1) type = TYPE_USHORT; else type = TYPE_UINT; break; case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': #ifdef HAVE_LONG_DOUBLE if (flags >= 16 || (flags & 4)) type = TYPE_LONGDOUBLE; else #endif type = TYPE_DOUBLE; break; case 'c': if (flags >= 8) #ifdef HAVE_WINT_T type = TYPE_WIDE_CHAR; #else goto error; #endif else type = TYPE_CHAR; break; #ifdef HAVE_WINT_T case 'C': type = TYPE_WIDE_CHAR; c = 'c'; break; #endif case 's': if (flags >= 8) #ifdef HAVE_WCHAR_T type = TYPE_WIDE_STRING; #else goto error; #endif else type = TYPE_STRING; break; #ifdef HAVE_WCHAR_T case 'S': type = TYPE_WIDE_STRING; c = 's'; break; #endif case 'p': type = TYPE_POINTER; break; case 'n': #ifdef HAVE_LONG_LONG if (flags >= 16 || (flags & 4)) type = TYPE_COUNT_LONGLONGINT_POINTER; else #endif if (flags >= 8) type = TYPE_COUNT_LONGINT_POINTER; else if (flags & 2) type = TYPE_COUNT_SCHAR_POINTER; else if (flags & 1) type = TYPE_COUNT_SHORT_POINTER; else type = TYPE_COUNT_INT_POINTER; break; case '%': type = TYPE_NONE; break; default: /* Unknown conversion character. */ goto error; } } if (type != TYPE_NONE) { dp->arg_index = arg_index; if (dp->arg_index == ARG_NONE) { dp->arg_index = arg_posn++; if (dp->arg_index == ARG_NONE) /* arg_posn wrapped around. */ goto error; } REGISTER_ARG (dp->arg_index, type); } dp->conversion = c; dp->dir_end = cp; } d->count++; if (d->count >= d_allocated) { size_t memory_size; DIRECTIVE *memory; d_allocated = xtimes (d_allocated, 2); memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); if (size_overflow_p (memory_size)) /* Overflow, would lead to out of memory. */ goto error; memory = realloc (d->dir, memory_size); if (memory == NULL) /* Out of memory. */ goto error; d->dir = memory; } } } d->dir[d->count].dir_start = cp; d->max_width_length = max_width_length; d->max_precision_length = max_precision_length; return 0; error: if (a->arg) free (a->arg); if (d->dir) free (d->dir); return -1; } #undef DIRECTIVES #undef DIRECTIVE #undef CHAR_T #undef PRINTF_PARSE lightspeed-1.2a.debian.1/intl/printf-parse.h000066400000000000000000000042131334064775200207710ustar00rootroot00000000000000/* Parse printf format string. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _PRINTF_PARSE_H #define _PRINTF_PARSE_H #include "printf-args.h" /* Flags */ #define FLAG_GROUP 1 /* ' flag */ #define FLAG_LEFT 2 /* - flag */ #define FLAG_SHOWSIGN 4 /* + flag */ #define FLAG_SPACE 8 /* space flag */ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ #define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct { const char* dir_start; const char* dir_end; int flags; const char* width_start; const char* width_end; size_t width_arg_index; const char* precision_start; const char* precision_end; size_t precision_arg_index; char conversion; /* d i o u x X f e E g G c s p n U % but not C S */ size_t arg_index; } char_directive; /* A parsed format string. */ typedef struct { size_t count; char_directive *dir; size_t max_width_length; size_t max_precision_length; } char_directives; /* Parses the format string. Fills in the number N of directives, and fills in directives[0], ..., directives[N-1], and sets directives[N].dir_start to the end of the format string. Also fills in the arg_type fields of the arguments and the needed count of arguments. */ #ifdef STATIC STATIC #else extern #endif int printf_parse (const char *format, char_directives *d, arguments *a); #endif /* _PRINTF_PARSE_H */ lightspeed-1.2a.debian.1/intl/printf.c000066400000000000000000000172031334064775200176570ustar00rootroot00000000000000/* Formatted output to strings, using POSIX/XSI format strings with positions. Copyright (C) 2003 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #ifdef __GNUC__ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else # ifdef _MSC_VER # include # define alloca _alloca # else # if defined HAVE_ALLOCA_H || defined _LIBC # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca char *alloca (); # endif # endif # endif # endif #endif #include #if !HAVE_POSIX_PRINTF #include #include /* When building a DLL, we must export some functions. Note that because the functions are only defined for binary backward compatibility, we don't need to use __declspec(dllimport) in any case. */ #if defined _MSC_VER && BUILDING_DLL # define DLL_EXPORTED __declspec(dllexport) #else # define DLL_EXPORTED #endif #define STATIC static /* Define auxiliary functions declared in "printf-args.h". */ #include "printf-args.c" /* Define auxiliary functions declared in "printf-parse.h". */ #include "printf-parse.c" /* Define functions declared in "vasnprintf.h". */ #define vasnprintf libintl_vasnprintf #include "vasnprintf.c" #if 0 /* not needed */ #define asnprintf libintl_asnprintf #include "asnprintf.c" #endif DLL_EXPORTED int libintl_vfprintf (FILE *stream, const char *format, va_list args) { if (strchr (format, '$') == NULL) return vfprintf (stream, format, args); else { size_t length; char *result = libintl_vasnprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) { if (fwrite (result, 1, length, stream) == length) retval = length; free (result); } return retval; } } DLL_EXPORTED int libintl_fprintf (FILE *stream, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vfprintf (stream, format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vprintf (const char *format, va_list args) { return libintl_vfprintf (stdout, format, args); } DLL_EXPORTED int libintl_printf (const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vprintf (format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vsprintf (char *resultbuf, const char *format, va_list args) { if (strchr (format, '$') == NULL) return vsprintf (resultbuf, format, args); else { size_t length = (size_t) ~0 / (4 * sizeof (char)); char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) { free (result); return -1; } else return length; } } DLL_EXPORTED int libintl_sprintf (char *resultbuf, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vsprintf (resultbuf, format, args); va_end (args); return retval; } #if HAVE_SNPRINTF # if HAVE_DECL__SNPRINTF /* Windows. */ # define system_vsnprintf _vsnprintf # else /* Unix. */ # define system_vsnprintf vsnprintf # endif DLL_EXPORTED int libintl_vsnprintf (char *resultbuf, size_t length, const char *format, va_list args) { if (strchr (format, '$') == NULL) return system_vsnprintf (resultbuf, length, format, args); else { size_t maxlength = length; char *result = libintl_vasnprintf (resultbuf, &length, format, args); if (result != resultbuf) { if (maxlength > 0) { if (length < maxlength) abort (); memcpy (resultbuf, result, maxlength - 1); resultbuf[maxlength - 1] = '\0'; } free (result); return -1; } else return length; } } DLL_EXPORTED int libintl_snprintf (char *resultbuf, size_t length, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vsnprintf (resultbuf, length, format, args); va_end (args); return retval; } #endif #if HAVE_ASPRINTF DLL_EXPORTED int libintl_vasprintf (char **resultp, const char *format, va_list args) { size_t length; char *result = libintl_vasnprintf (NULL, &length, format, args); if (result == NULL) return -1; *resultp = result; return length; } DLL_EXPORTED int libintl_asprintf (char **resultp, const char *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vasprintf (resultp, format, args); va_end (args); return retval; } #endif #if HAVE_FWPRINTF #include #define WIDE_CHAR_VERSION 1 /* Define auxiliary functions declared in "wprintf-parse.h". */ #include "printf-parse.c" /* Define functions declared in "vasnprintf.h". */ #define vasnwprintf libintl_vasnwprintf #include "vasnprintf.c" #if 0 /* not needed */ #define asnwprintf libintl_asnwprintf #include "asnprintf.c" #endif # if HAVE_DECL__SNWPRINTF /* Windows. */ # define system_vswprintf _vsnwprintf # else /* Unix. */ # define system_vswprintf vswprintf # endif DLL_EXPORTED int libintl_vfwprintf (FILE *stream, const wchar_t *format, va_list args) { if (wcschr (format, '$') == NULL) return vfwprintf (stream, format, args); else { size_t length; wchar_t *result = libintl_vasnwprintf (NULL, &length, format, args); int retval = -1; if (result != NULL) { size_t i; for (i = 0; i < length; i++) if (fputwc (result[i], stream) == WEOF) break; if (i == length) retval = length; free (result); } return retval; } } DLL_EXPORTED int libintl_fwprintf (FILE *stream, const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vfwprintf (stream, format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vwprintf (const wchar_t *format, va_list args) { return libintl_vfwprintf (stdout, format, args); } DLL_EXPORTED int libintl_wprintf (const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vwprintf (format, args); va_end (args); return retval; } DLL_EXPORTED int libintl_vswprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, va_list args) { if (wcschr (format, '$') == NULL) return system_vswprintf (resultbuf, length, format, args); else { size_t maxlength = length; wchar_t *result = libintl_vasnwprintf (resultbuf, &length, format, args); if (result != resultbuf) { if (maxlength > 0) { if (length < maxlength) abort (); memcpy (resultbuf, result, (maxlength - 1) * sizeof (wchar_t)); resultbuf[maxlength - 1] = 0; } free (result); return -1; } else return length; } } DLL_EXPORTED int libintl_swprintf (wchar_t *resultbuf, size_t length, const wchar_t *format, ...) { va_list args; int retval; va_start (args, format); retval = libintl_vswprintf (resultbuf, length, format, args); va_end (args); return retval; } #endif #endif lightspeed-1.2a.debian.1/intl/ref-add.sin000066400000000000000000000021051334064775200202210ustar00rootroot00000000000000# Add this package to a list of references stored in a text file. # # Copyright (C) 2000 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # Written by Bruno Haible . # /^# Packages using this file: / { s/# Packages using this file:// ta :a s/ @PACKAGE@ / @PACKAGE@ / tb s/ $/ @PACKAGE@ / :b s/^/# Packages using this file:/ } lightspeed-1.2a.debian.1/intl/ref-del.sin000066400000000000000000000020301334064775200202320ustar00rootroot00000000000000# Remove this package from a list of references stored in a text file. # # Copyright (C) 2000 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2, 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 # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. # # Written by Bruno Haible . # /^# Packages using this file: / { s/# Packages using this file:// s/ @PACKAGE@ / / s/^/# Packages using this file:/ } lightspeed-1.2a.debian.1/intl/relocatable.c000066400000000000000000000314711334064775200206350ustar00rootroot00000000000000/* Provide relocatable packages. Copyright (C) 2003-2004 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for getline(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include "config.h" #endif /* Specification. */ #include "relocatable.h" #if ENABLE_RELOCATABLE #include #include #include #include #ifdef NO_XMALLOC # define xmalloc malloc #else # include "xalloc.h" #endif #if defined _WIN32 || defined __WIN32__ # define WIN32_LEAN_AND_MEAN # include #endif #if DEPENDS_ON_LIBCHARSET # include #endif #if DEPENDS_ON_LIBICONV && HAVE_ICONV # include #endif #if DEPENDS_ON_LIBINTL && ENABLE_NLS # include #endif /* Faked cheap 'bool'. */ #undef bool #undef false #undef true #define bool int #define false 0 #define true 1 /* Pathname support. ISSLASH(C) tests whether C is a directory separator character. IS_PATH_WITH_DIR(P) tests whether P contains a directory specification. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') # define HAS_DEVICE(P) \ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ && (P)[1] == ':') # define IS_PATH_WITH_DIR(P) \ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P)) # define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0) #else /* Unix */ # define ISSLASH(C) ((C) == '/') # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL) # define FILE_SYSTEM_PREFIX_LEN(P) 0 #endif /* Original installation prefix. */ static char *orig_prefix; static size_t orig_prefix_len; /* Current installation prefix. */ static char *curr_prefix; static size_t curr_prefix_len; /* These prefixes do not end in a slash. Anything that will be concatenated to them must start with a slash. */ /* Sets the original and the current installation prefix of this module. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ static void set_this_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg) { if (orig_prefix_arg != NULL && curr_prefix_arg != NULL /* Optimization: if orig_prefix and curr_prefix are equal, the relocation is a nop. */ && strcmp (orig_prefix_arg, curr_prefix_arg) != 0) { /* Duplicate the argument strings. */ char *memory; orig_prefix_len = strlen (orig_prefix_arg); curr_prefix_len = strlen (curr_prefix_arg); memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1); #ifdef NO_XMALLOC if (memory != NULL) #endif { memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); orig_prefix = memory; memory += orig_prefix_len + 1; memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); curr_prefix = memory; return; } } orig_prefix = NULL; curr_prefix = NULL; /* Don't worry about wasted memory here - this function is usually only called once. */ } /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ void set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg) { set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg); /* Now notify all dependent libraries. */ #if DEPENDS_ON_LIBCHARSET libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif #if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109 libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif #if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg); #endif } #if !defined IN_LIBRARY || (defined PIC && defined INSTALLDIR) /* Convenience function: Computes the current installation prefix, based on the original installation prefix, the original installation directory of a particular file, and the current pathname of this file. Returns NULL upon failure. */ #ifdef IN_LIBRARY #define compute_curr_prefix local_compute_curr_prefix static #endif const char * compute_curr_prefix (const char *orig_installprefix, const char *orig_installdir, const char *curr_pathname) { const char *curr_installdir; const char *rel_installdir; if (curr_pathname == NULL) return NULL; /* Determine the relative installation directory, relative to the prefix. This is simply the difference between orig_installprefix and orig_installdir. */ if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix)) != 0) /* Shouldn't happen - nothing should be installed outside $(prefix). */ return NULL; rel_installdir = orig_installdir + strlen (orig_installprefix); /* Determine the current installation directory. */ { const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname); const char *p = curr_pathname + strlen (curr_pathname); char *q; while (p > p_base) { p--; if (ISSLASH (*p)) break; } q = (char *) xmalloc (p - curr_pathname + 1); #ifdef NO_XMALLOC if (q == NULL) return NULL; #endif memcpy (q, curr_pathname, p - curr_pathname); q[p - curr_pathname] = '\0'; curr_installdir = q; } /* Compute the current installation prefix by removing the trailing rel_installdir from it. */ { const char *rp = rel_installdir + strlen (rel_installdir); const char *cp = curr_installdir + strlen (curr_installdir); const char *cp_base = curr_installdir + FILE_SYSTEM_PREFIX_LEN (curr_installdir); while (rp > rel_installdir && cp > cp_base) { bool same = false; const char *rpi = rp; const char *cpi = cp; while (rpi > rel_installdir && cpi > cp_base) { rpi--; cpi--; if (ISSLASH (*rpi) || ISSLASH (*cpi)) { if (ISSLASH (*rpi) && ISSLASH (*cpi)) same = true; break; } #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS - case insignificant filesystem */ if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) break; #else if (*rpi != *cpi) break; #endif } if (!same) break; /* The last pathname component was the same. opi and cpi now point to the slash before it. */ rp = rpi; cp = cpi; } if (rp > rel_installdir) /* Unexpected: The curr_installdir does not end with rel_installdir. */ return NULL; { size_t curr_prefix_len = cp - curr_installdir; char *curr_prefix; curr_prefix = (char *) xmalloc (curr_prefix_len + 1); #ifdef NO_XMALLOC if (curr_prefix == NULL) return NULL; #endif memcpy (curr_prefix, curr_installdir, curr_prefix_len); curr_prefix[curr_prefix_len] = '\0'; return curr_prefix; } } } #endif /* !IN_LIBRARY || PIC */ #if defined PIC && defined INSTALLDIR /* Full pathname of shared library, or NULL. */ static char *shared_library_fullname; #if defined _WIN32 || defined __WIN32__ /* Determine the full pathname of the shared library when it is loaded. */ BOOL WINAPI DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved) { (void) reserved; if (event == DLL_PROCESS_ATTACH) { /* The DLL is being loaded into an application's address range. */ static char location[MAX_PATH]; if (!GetModuleFileName (module_handle, location, sizeof (location))) /* Shouldn't happen. */ return FALSE; if (!IS_PATH_WITH_DIR (location)) /* Shouldn't happen. */ return FALSE; shared_library_fullname = strdup (location); } return TRUE; } #else /* Unix */ static void find_shared_library_fullname () { #if defined __linux__ && __GLIBC__ >= 2 /* Linux has /proc/self/maps. glibc 2 has the getline() function. */ FILE *fp; /* Open the current process' maps file. It describes one VMA per line. */ fp = fopen ("/proc/self/maps", "r"); if (fp) { unsigned long address = (unsigned long) &find_shared_library_fullname; for (;;) { unsigned long start, end; int c; if (fscanf (fp, "%lx-%lx", &start, &end) != 2) break; if (address >= start && address <= end - 1) { /* Found it. Now see if this line contains a filename. */ while (c = getc (fp), c != EOF && c != '\n' && c != '/') continue; if (c == '/') { size_t size; int len; ungetc (c, fp); shared_library_fullname = NULL; size = 0; len = getline (&shared_library_fullname, &size, fp); if (len >= 0) { /* Success: filled shared_library_fullname. */ if (len > 0 && shared_library_fullname[len - 1] == '\n') shared_library_fullname[len - 1] = '\0'; } } break; } while (c = getc (fp), c != EOF && c != '\n') continue; } fclose (fp); } #endif } #endif /* WIN32 / Unix */ /* Return the full pathname of the current shared library. Return NULL if unknown. Guaranteed to work only on Linux and Woe32. */ static char * get_shared_library_fullname () { #if !(defined _WIN32 || defined __WIN32__) static bool tried_find_shared_library_fullname; if (!tried_find_shared_library_fullname) { find_shared_library_fullname (); tried_find_shared_library_fullname = true; } #endif return shared_library_fullname; } #endif /* PIC */ /* Returns the pathname, relocated according to the current installation directory. */ const char * relocate (const char *pathname) { #if defined PIC && defined INSTALLDIR static int initialized; /* Initialization code for a shared library. */ if (!initialized) { /* At this point, orig_prefix and curr_prefix likely have already been set through the main program's set_program_name_and_installdir function. This is sufficient in the case that the library has initially been installed in the same orig_prefix. But we can do better, to also cover the cases that 1. it has been installed in a different prefix before being moved to orig_prefix and (later) to curr_prefix, 2. unlike the program, it has not moved away from orig_prefix. */ const char *orig_installprefix = INSTALLPREFIX; const char *orig_installdir = INSTALLDIR; const char *curr_prefix_better; curr_prefix_better = compute_curr_prefix (orig_installprefix, orig_installdir, get_shared_library_fullname ()); if (curr_prefix_better == NULL) curr_prefix_better = curr_prefix; set_relocation_prefix (orig_installprefix, curr_prefix_better); initialized = 1; } #endif /* Note: It is not necessary to perform case insensitive comparison here, even for DOS-like filesystems, because the pathname argument was typically created from the same Makefile variable as orig_prefix came from. */ if (orig_prefix != NULL && curr_prefix != NULL && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { if (pathname[orig_prefix_len] == '\0') /* pathname equals orig_prefix. */ return curr_prefix; if (ISSLASH (pathname[orig_prefix_len])) { /* pathname starts with orig_prefix. */ const char *pathname_tail = &pathname[orig_prefix_len]; char *result = (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); #ifdef NO_XMALLOC if (result != NULL) #endif { memcpy (result, curr_prefix, curr_prefix_len); strcpy (result + curr_prefix_len, pathname_tail); return result; } } } /* Nothing to relocate. */ return pathname; } #endif lightspeed-1.2a.debian.1/intl/relocatable.h000066400000000000000000000052411334064775200206360ustar00rootroot00000000000000/* Provide relocatable packages. Copyright (C) 2003 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _RELOCATABLE_H #define _RELOCATABLE_H #ifdef __cplusplus extern "C" { #endif /* This can be enabled through the configure --enable-relocatable option. */ #if ENABLE_RELOCATABLE /* When building a DLL, we must export some functions. Note that because this is a private .h file, we don't need to use __declspec(dllimport) in any case. */ #if defined _MSC_VER && BUILDING_DLL # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport) #else # define RELOCATABLE_DLL_EXPORTED #endif /* Sets the original and the current installation prefix of the package. Relocation simply replaces a pathname starting with the original prefix by the corresponding pathname with the current prefix instead. Both prefixes should be directory names without trailing slash (i.e. use "" instead of "/"). */ extern RELOCATABLE_DLL_EXPORTED void set_relocation_prefix (const char *orig_prefix, const char *curr_prefix); /* Returns the pathname, relocated according to the current installation directory. */ extern const char * relocate (const char *pathname); /* Memory management: relocate() leaks memory, because it has to construct a fresh pathname. If this is a problem because your program calls relocate() frequently, think about caching the result. */ /* Convenience function: Computes the current installation prefix, based on the original installation prefix, the original installation directory of a particular file, and the current pathname of this file. Returns NULL upon failure. */ extern const char * compute_curr_prefix (const char *orig_installprefix, const char *orig_installdir, const char *curr_pathname); #else /* By default, we use the hardwired pathnames. */ #define relocate(pathname) (pathname) #endif #ifdef __cplusplus } #endif #endif /* _RELOCATABLE_H */ lightspeed-1.2a.debian.1/intl/textdomain.c000066400000000000000000000106641334064775200205350ustar00rootroot00000000000000/* Implementation of the textdomain(3) function. Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #ifdef _LIBC # include #else # include "libgnuintl.h" #endif #include "gettextP.h" #ifdef _LIBC /* We have to handle multi-threaded applications. */ # include #else /* Provide dummy implementation if this is outside glibc. */ # define __libc_rwlock_define(CLASS, NAME) # define __libc_rwlock_wrlock(NAME) # define __libc_rwlock_unlock(NAME) #endif /* The internal variables in the standalone libintl.a must have different names than the internal variables in GNU libc, otherwise programs using libintl.a cannot be linked statically. */ #if !defined _LIBC # define _nl_default_default_domain libintl_nl_default_default_domain # define _nl_current_default_domain libintl_nl_current_default_domain #endif /* @@ end of prolog @@ */ /* Name of the default text domain. */ extern const char _nl_default_default_domain[] attribute_hidden; /* Default text domain in which entries for gettext(3) are to be found. */ extern const char *_nl_current_default_domain attribute_hidden; /* Names for the libintl functions are a problem. They must not clash with existing names and they should follow ANSI C. But this source code is also used in GNU C Library where the names have a __ prefix. So we have to make a difference here. */ #ifdef _LIBC # define TEXTDOMAIN __textdomain # ifndef strdup # define strdup(str) __strdup (str) # endif #else # define TEXTDOMAIN libintl_textdomain #endif /* Lock variable to protect the global data in the gettext implementation. */ __libc_rwlock_define (extern, _nl_state_lock attribute_hidden) /* Set the current default message catalog to DOMAINNAME. If DOMAINNAME is null, return the current default. If DOMAINNAME is "", reset to the default of "messages". */ char * TEXTDOMAIN (const char *domainname) { char *new_domain; char *old_domain; /* A NULL pointer requests the current setting. */ if (domainname == NULL) return (char *) _nl_current_default_domain; __libc_rwlock_wrlock (_nl_state_lock); old_domain = (char *) _nl_current_default_domain; /* If domain name is the null string set to default domain "messages". */ if (domainname[0] == '\0' || strcmp (domainname, _nl_default_default_domain) == 0) { _nl_current_default_domain = _nl_default_default_domain; new_domain = (char *) _nl_current_default_domain; } else if (strcmp (domainname, old_domain) == 0) /* This can happen and people will use it to signal that some environment variable changed. */ new_domain = old_domain; else { /* If the following malloc fails `_nl_current_default_domain' will be NULL. This value will be returned and so signals we are out of core. */ #if defined _LIBC || defined HAVE_STRDUP new_domain = strdup (domainname); #else size_t len = strlen (domainname) + 1; new_domain = (char *) malloc (len); if (new_domain != NULL) memcpy (new_domain, domainname, len); #endif if (new_domain != NULL) _nl_current_default_domain = new_domain; } /* We use this possibility to signal a change of the loaded catalogs since this is most likely the case and there is no other easy we to do it. Do it only when the call was successful. */ if (new_domain != NULL) { ++_nl_msg_cat_cntr; if (old_domain != new_domain && old_domain != _nl_default_default_domain) free (old_domain); } __libc_rwlock_unlock (_nl_state_lock); return new_domain; } #ifdef _LIBC /* Alias for function name in GNU C Library. */ weak_alias (__textdomain, textdomain); #endif lightspeed-1.2a.debian.1/intl/vasnprintf.c000066400000000000000000000537621334064775200205610ustar00rootroot00000000000000/* vsprintf with automatic memory allocation. Copyright (C) 1999, 2002-2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Tell glibc's to provide a prototype for snprintf(). This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE # define _GNU_SOURCE 1 #endif #ifdef HAVE_CONFIG_H # include #endif #ifndef IN_LIBINTL # include #endif /* Specification. */ #if WIDE_CHAR_VERSION # include "vasnwprintf.h" #else # include "vasnprintf.h" #endif #include /* snprintf(), sprintf() */ #include /* abort(), malloc(), realloc(), free() */ #include /* memcpy(), strlen() */ #include /* errno */ #include /* CHAR_BIT, INT_MAX */ #include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if WIDE_CHAR_VERSION # include "wprintf-parse.h" #else # include "printf-parse.h" #endif /* Checked size_t computations. */ #include "xsize.h" /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */ #ifndef EOVERFLOW # define EOVERFLOW E2BIG #endif #ifdef HAVE_WCHAR_T # ifdef HAVE_WCSLEN # define local_wcslen wcslen # else /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid a dependency towards this library, here is a local substitute. Define this substitute only once, even if this file is included twice in the same compilation unit. */ # ifndef local_wcslen_defined # define local_wcslen_defined 1 static size_t local_wcslen (const wchar_t *s) { const wchar_t *ptr; for (ptr = s; *ptr != (wchar_t) 0; ptr++) ; return ptr - s; } # endif # endif #endif #if WIDE_CHAR_VERSION # define VASNPRINTF vasnwprintf # define CHAR_T wchar_t # define DIRECTIVE wchar_t_directive # define DIRECTIVES wchar_t_directives # define PRINTF_PARSE wprintf_parse # define USE_SNPRINTF 1 # if HAVE_DECL__SNWPRINTF /* On Windows, the function swprintf() has a different signature than on Unix; we use the _snwprintf() function instead. */ # define SNPRINTF _snwprintf # else /* Unix. */ # define SNPRINTF swprintf # endif #else # define VASNPRINTF vasnprintf # define CHAR_T char # define DIRECTIVE char_directive # define DIRECTIVES char_directives # define PRINTF_PARSE printf_parse # define USE_SNPRINTF (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) # if HAVE_DECL__SNPRINTF /* Windows. */ # define SNPRINTF _snprintf # else /* Unix. */ # define SNPRINTF snprintf # endif #endif CHAR_T * VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list args) { DIRECTIVES d; arguments a; if (PRINTF_PARSE (format, &d, &a) < 0) { errno = EINVAL; return NULL; } #define CLEANUP() \ free (d.dir); \ if (a.arg) \ free (a.arg); if (printf_fetchargs (args, &a) < 0) { CLEANUP (); errno = EINVAL; return NULL; } { size_t buf_neededlength; CHAR_T *buf; CHAR_T *buf_malloced; const CHAR_T *cp; size_t i; DIRECTIVE *dp; /* Output string accumulator. */ CHAR_T *result; size_t allocated; size_t length; /* Allocate a small buffer that will hold a directive passed to sprintf or snprintf. */ buf_neededlength = xsum4 (7, d.max_width_length, d.max_precision_length, 6); #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (CHAR_T)) { buf = (CHAR_T *) alloca (buf_neededlength * sizeof (CHAR_T)); buf_malloced = NULL; } else #endif { size_t buf_memsize = xtimes (buf_neededlength, sizeof (CHAR_T)); if (size_overflow_p (buf_memsize)) goto out_of_memory_1; buf = (CHAR_T *) malloc (buf_memsize); if (buf == NULL) goto out_of_memory_1; buf_malloced = buf; } if (resultbuf != NULL) { result = resultbuf; allocated = *lengthp; } else { result = NULL; allocated = 0; } length = 0; /* Invariants: result is either == resultbuf or == NULL or malloc-allocated. If length > 0, then result != NULL. */ /* Ensures that allocated >= needed. Aborts through a jump to out_of_memory if needed is SIZE_MAX or otherwise too big. */ #define ENSURE_ALLOCATION(needed) \ if ((needed) > allocated) \ { \ size_t memory_size; \ CHAR_T *memory; \ \ allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ if ((needed) > allocated) \ allocated = (needed); \ memory_size = xtimes (allocated, sizeof (CHAR_T)); \ if (size_overflow_p (memory_size)) \ goto out_of_memory; \ if (result == resultbuf || result == NULL) \ memory = (CHAR_T *) malloc (memory_size); \ else \ memory = (CHAR_T *) realloc (result, memory_size); \ if (memory == NULL) \ goto out_of_memory; \ if (result == resultbuf && length > 0) \ memcpy (memory, result, length * sizeof (CHAR_T)); \ result = memory; \ } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { if (cp != dp->dir_start) { size_t n = dp->dir_start - cp; size_t augmented_length = xsum (length, n); ENSURE_ALLOCATION (augmented_length); memcpy (result + length, cp, n * sizeof (CHAR_T)); length = augmented_length; } if (i == d.count) break; /* Execute a single directive. */ if (dp->conversion == '%') { size_t augmented_length; if (!(dp->arg_index == ARG_NONE)) abort (); augmented_length = xsum (length, 1); ENSURE_ALLOCATION (augmented_length); result[length] = '%'; length = augmented_length; } else { if (!(dp->arg_index != ARG_NONE)) abort (); if (dp->conversion == 'n') { switch (a.arg[dp->arg_index].type) { case TYPE_COUNT_SCHAR_POINTER: *a.arg[dp->arg_index].a.a_count_schar_pointer = length; break; case TYPE_COUNT_SHORT_POINTER: *a.arg[dp->arg_index].a.a_count_short_pointer = length; break; case TYPE_COUNT_INT_POINTER: *a.arg[dp->arg_index].a.a_count_int_pointer = length; break; case TYPE_COUNT_LONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longint_pointer = length; break; #ifdef HAVE_LONG_LONG case TYPE_COUNT_LONGLONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; break; #endif default: abort (); } } else { arg_type type = a.arg[dp->arg_index].type; CHAR_T *p; unsigned int prefix_count; int prefixes[2]; #if !USE_SNPRINTF size_t tmp_length; CHAR_T tmpbuf[700]; CHAR_T *tmp; /* Allocate a temporary buffer of sufficient size for calling sprintf. */ { size_t width; size_t precision; width = 0; if (dp->width_start != dp->width_end) { if (dp->width_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->width_arg_index].a.a_int; width = (arg < 0 ? (unsigned int) (-arg) : arg); } else { const CHAR_T *digitp = dp->width_start; do width = xsum (xtimes (width, 10), *digitp++ - '0'); while (digitp != dp->width_end); } } precision = 6; if (dp->precision_start != dp->precision_end) { if (dp->precision_arg_index != ARG_NONE) { int arg; if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); arg = a.arg[dp->precision_arg_index].a.a_int; precision = (arg < 0 ? 0 : arg); } else { const CHAR_T *digitp = dp->precision_start + 1; precision = 0; while (digitp != dp->precision_end) precision = xsum (xtimes (precision, 10), *digitp++ - '0'); } } switch (dp->conversion) { case 'd': case 'i': case 'u': # ifdef HAVE_LONG_LONG if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ break; case 'o': # ifdef HAVE_LONG_LONG if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1 /* turn floor into ceil */ + 1; /* account for leading sign */ break; case 'x': case 'X': # ifdef HAVE_LONG_LONG if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1 /* turn floor into ceil */ + 2; /* account for leading sign or alternate form */ else # endif if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1 /* turn floor into ceil */ + 2; /* account for leading sign or alternate form */ else tmp_length = (unsigned int) (sizeof (unsigned int) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1 /* turn floor into ceil */ + 2; /* account for leading sign or alternate form */ break; case 'f': case 'F': # ifdef HAVE_LONG_DOUBLE if (type == TYPE_LONGDOUBLE) tmp_length = (unsigned int) (LDBL_MAX_EXP * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 10; /* sign, decimal point etc. */ else # endif tmp_length = (unsigned int) (DBL_MAX_EXP * 0.30103 /* binary -> decimal */ * 2 /* estimate for FLAG_GROUP */ ) + 1 /* turn floor into ceil */ + 10; /* sign, decimal point etc. */ tmp_length = xsum (tmp_length, precision); break; case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': tmp_length = 12; /* sign, decimal point, exponent etc. */ tmp_length = xsum (tmp_length, precision); break; case 'c': # if defined HAVE_WINT_T && !WIDE_CHAR_VERSION if (type == TYPE_WIDE_CHAR) tmp_length = MB_CUR_MAX; else # endif tmp_length = 1; break; case 's': # ifdef HAVE_WCHAR_T if (type == TYPE_WIDE_STRING) { tmp_length = local_wcslen (a.arg[dp->arg_index].a.a_wide_string); # if !WIDE_CHAR_VERSION tmp_length = xtimes (tmp_length, MB_CUR_MAX); # endif } else # endif tmp_length = strlen (a.arg[dp->arg_index].a.a_string); break; case 'p': tmp_length = (unsigned int) (sizeof (void *) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1 /* turn floor into ceil */ + 2; /* account for leading 0x */ break; default: abort (); } if (tmp_length < width) tmp_length = width; tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ } if (tmp_length <= sizeof (tmpbuf) / sizeof (CHAR_T)) tmp = tmpbuf; else { size_t tmp_memsize = xtimes (tmp_length, sizeof (CHAR_T)); if (size_overflow_p (tmp_memsize)) /* Overflow, would lead to out of memory. */ goto out_of_memory; tmp = (CHAR_T *) malloc (tmp_memsize); if (tmp == NULL) /* Out of memory. */ goto out_of_memory; } #endif /* Construct the format string for calling snprintf or sprintf. */ p = buf; *p++ = '%'; if (dp->flags & FLAG_GROUP) *p++ = '\''; if (dp->flags & FLAG_LEFT) *p++ = '-'; if (dp->flags & FLAG_SHOWSIGN) *p++ = '+'; if (dp->flags & FLAG_SPACE) *p++ = ' '; if (dp->flags & FLAG_ALT) *p++ = '#'; if (dp->flags & FLAG_ZERO) *p++ = '0'; if (dp->width_start != dp->width_end) { size_t n = dp->width_end - dp->width_start; memcpy (p, dp->width_start, n * sizeof (CHAR_T)); p += n; } if (dp->precision_start != dp->precision_end) { size_t n = dp->precision_end - dp->precision_start; memcpy (p, dp->precision_start, n * sizeof (CHAR_T)); p += n; } switch (type) { #ifdef HAVE_LONG_LONG case TYPE_LONGLONGINT: case TYPE_ULONGLONGINT: *p++ = 'l'; /*FALLTHROUGH*/ #endif case TYPE_LONGINT: case TYPE_ULONGINT: #ifdef HAVE_WINT_T case TYPE_WIDE_CHAR: #endif #ifdef HAVE_WCHAR_T case TYPE_WIDE_STRING: #endif *p++ = 'l'; break; #ifdef HAVE_LONG_DOUBLE case TYPE_LONGDOUBLE: *p++ = 'L'; break; #endif default: break; } *p = dp->conversion; #if USE_SNPRINTF p[1] = '%'; p[2] = 'n'; p[3] = '\0'; #else p[1] = '\0'; #endif /* Construct the arguments for calling snprintf or sprintf. */ prefix_count = 0; if (dp->width_arg_index != ARG_NONE) { if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; } if (dp->precision_arg_index != ARG_NONE) { if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort (); prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; } #if USE_SNPRINTF /* Prepare checking whether snprintf returns the count via %n. */ ENSURE_ALLOCATION (xsum (length, 1)); result[length] = '\0'; #endif for (;;) { size_t maxlen; int count; int retcount; maxlen = allocated - length; count = -1; retcount = 0; #if USE_SNPRINTF # define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ retcount = SNPRINTF (result + length, maxlen, buf, \ arg, &count); \ break; \ case 1: \ retcount = SNPRINTF (result + length, maxlen, buf, \ prefixes[0], arg, &count); \ break; \ case 2: \ retcount = SNPRINTF (result + length, maxlen, buf, \ prefixes[0], prefixes[1], arg, \ &count); \ break; \ default: \ abort (); \ } #else # define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ count = sprintf (tmp, buf, arg); \ break; \ case 1: \ count = sprintf (tmp, buf, prefixes[0], arg); \ break; \ case 2: \ count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ arg); \ break; \ default: \ abort (); \ } #endif switch (type) { case TYPE_SCHAR: { int arg = a.arg[dp->arg_index].a.a_schar; SNPRINTF_BUF (arg); } break; case TYPE_UCHAR: { unsigned int arg = a.arg[dp->arg_index].a.a_uchar; SNPRINTF_BUF (arg); } break; case TYPE_SHORT: { int arg = a.arg[dp->arg_index].a.a_short; SNPRINTF_BUF (arg); } break; case TYPE_USHORT: { unsigned int arg = a.arg[dp->arg_index].a.a_ushort; SNPRINTF_BUF (arg); } break; case TYPE_INT: { int arg = a.arg[dp->arg_index].a.a_int; SNPRINTF_BUF (arg); } break; case TYPE_UINT: { unsigned int arg = a.arg[dp->arg_index].a.a_uint; SNPRINTF_BUF (arg); } break; case TYPE_LONGINT: { long int arg = a.arg[dp->arg_index].a.a_longint; SNPRINTF_BUF (arg); } break; case TYPE_ULONGINT: { unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; SNPRINTF_BUF (arg); } break; #ifdef HAVE_LONG_LONG case TYPE_LONGLONGINT: { long long int arg = a.arg[dp->arg_index].a.a_longlongint; SNPRINTF_BUF (arg); } break; case TYPE_ULONGLONGINT: { unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; SNPRINTF_BUF (arg); } break; #endif case TYPE_DOUBLE: { double arg = a.arg[dp->arg_index].a.a_double; SNPRINTF_BUF (arg); } break; #ifdef HAVE_LONG_DOUBLE case TYPE_LONGDOUBLE: { long double arg = a.arg[dp->arg_index].a.a_longdouble; SNPRINTF_BUF (arg); } break; #endif case TYPE_CHAR: { int arg = a.arg[dp->arg_index].a.a_char; SNPRINTF_BUF (arg); } break; #ifdef HAVE_WINT_T case TYPE_WIDE_CHAR: { wint_t arg = a.arg[dp->arg_index].a.a_wide_char; SNPRINTF_BUF (arg); } break; #endif case TYPE_STRING: { const char *arg = a.arg[dp->arg_index].a.a_string; SNPRINTF_BUF (arg); } break; #ifdef HAVE_WCHAR_T case TYPE_WIDE_STRING: { const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; SNPRINTF_BUF (arg); } break; #endif case TYPE_POINTER: { void *arg = a.arg[dp->arg_index].a.a_pointer; SNPRINTF_BUF (arg); } break; default: abort (); } #if USE_SNPRINTF /* Portability: Not all implementations of snprintf() are ISO C 99 compliant. Determine the number of bytes that snprintf() has produced or would have produced. */ if (count >= 0) { /* Verify that snprintf() has NUL-terminated its result. */ if (count < maxlen && result[length + count] != '\0') abort (); /* Portability hack. */ if (retcount > count) count = retcount; } else { /* snprintf() doesn't understand the '%n' directive. */ if (p[1] != '\0') { /* Don't use the '%n' directive; instead, look at the snprintf() return value. */ p[1] = '\0'; continue; } else { /* Look at the snprintf() return value. */ if (retcount < 0) { /* HP-UX 10.20 snprintf() is doubly deficient: It doesn't understand the '%n' directive, *and* it returns -1 (rather than the length that would have been required) when the buffer is too small. */ size_t bigger_need = xsum (xtimes (allocated, 2), 12); ENSURE_ALLOCATION (bigger_need); continue; } else count = retcount; } } #endif /* Attempt to handle failure. */ if (count < 0) { if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); errno = EINVAL; return NULL; } #if !USE_SNPRINTF if (count >= tmp_length) /* tmp_length was incorrectly calculated - fix the code above! */ abort (); #endif /* Make room for the result. */ if (count >= maxlen) { /* Need at least count bytes. But allocate proportionally, to avoid looping eternally if snprintf() reports a too small count. */ size_t n = xmax (xsum (length, count), xtimes (allocated, 2)); ENSURE_ALLOCATION (n); #if USE_SNPRINTF continue; #endif } #if USE_SNPRINTF /* The snprintf() result did fit. */ #else /* Append the sprintf() result. */ memcpy (result + length, tmp, count * sizeof (CHAR_T)); if (tmp != tmpbuf) free (tmp); #endif length += count; break; } } } } /* Add the final NUL. */ ENSURE_ALLOCATION (xsum (length, 1)); result[length] = '\0'; if (result != resultbuf && length + 1 < allocated) { /* Shrink the allocated memory if possible. */ CHAR_T *memory; memory = (CHAR_T *) realloc (result, (length + 1) * sizeof (CHAR_T)); if (memory != NULL) result = memory; } if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); *lengthp = length; if (length > INT_MAX) goto length_overflow; return result; length_overflow: /* We could produce such a big string, but its length doesn't fit into an 'int'. POSIX says that snprintf() fails with errno = EOVERFLOW in this case. */ if (result != resultbuf) free (result); errno = EOVERFLOW; return NULL; out_of_memory: if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); out_of_memory_1: CLEANUP (); errno = ENOMEM; return NULL; } } #undef SNPRINTF #undef USE_SNPRINTF #undef PRINTF_PARSE #undef DIRECTIVES #undef DIRECTIVE #undef CHAR_T #undef VASNPRINTF lightspeed-1.2a.debian.1/intl/vasnprintf.h000066400000000000000000000054431334064775200205570ustar00rootroot00000000000000/* vsprintf with automatic memory allocation. Copyright (C) 2002-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _VASNPRINTF_H #define _VASNPRINTF_H /* Get va_list. */ #include /* Get size_t. */ #include #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif /* The __-protected variants of `format' and `printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) # define __format__ format # define __printf__ printf # endif #endif #ifdef __cplusplus extern "C" { #endif /* Write formatted output to a string dynamically allocated with malloc(). You can pass a preallocated buffer for the result in RESULTBUF and its size in *LENGTHP; otherwise you pass RESULTBUF = NULL. If successful, return the address of the string (this may be = RESULTBUF if no dynamic memory allocation was necessary) and set *LENGTHP to the number of resulting bytes, excluding the trailing NUL. Upon error, set errno and return NULL. When dynamic memory allocation occurs, the preallocated buffer is left alone (with possibly modified contents). This makes it possible to use a statically allocated or stack-allocated buffer, like this: char buf[100]; size_t len = sizeof (buf); char *output = vasnprintf (buf, &len, format, args); if (output == NULL) ... error handling ...; else { ... use the output string ...; if (output != buf) free (output); } */ extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) __attribute__ ((__format__ (__printf__, 3, 0))); #ifdef __cplusplus } #endif #endif /* _VASNPRINTF_H */ lightspeed-1.2a.debian.1/intl/vasnwprintf.h000066400000000000000000000033061334064775200207420ustar00rootroot00000000000000/* vswprintf with automatic memory allocation. Copyright (C) 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _VASNWPRINTF_H #define _VASNWPRINTF_H /* Get va_list. */ #include /* Get wchar_t, size_t. */ #include #ifdef __cplusplus extern "C" { #endif /* Write formatted output to a string dynamically allocated with malloc(). You can pass a preallocated buffer for the result in RESULTBUF and its size in *LENGTHP; otherwise you pass RESULTBUF = NULL. If successful, return the address of the string (this may be = RESULTBUF if no dynamic memory allocation was necessary) and set *LENGTHP to the number of resulting bytes, excluding the trailing NUL. Upon error, set errno and return NULL. */ extern wchar_t * asnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, ...); extern wchar_t * vasnwprintf (wchar_t *resultbuf, size_t *lengthp, const wchar_t *format, va_list args); #ifdef __cplusplus } #endif #endif /* _VASNWPRINTF_H */ lightspeed-1.2a.debian.1/intl/wprintf-parse.h000066400000000000000000000042631334064775200211650ustar00rootroot00000000000000/* Parse printf format string. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _WPRINTF_PARSE_H #define _WPRINTF_PARSE_H #include "printf-args.h" /* Flags */ #define FLAG_GROUP 1 /* ' flag */ #define FLAG_LEFT 2 /* - flag */ #define FLAG_SHOWSIGN 4 /* + flag */ #define FLAG_SPACE 8 /* space flag */ #define FLAG_ALT 16 /* # flag */ #define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ #define ARG_NONE (~(size_t)0) /* A parsed directive. */ typedef struct { const wchar_t* dir_start; const wchar_t* dir_end; int flags; const wchar_t* width_start; const wchar_t* width_end; size_t width_arg_index; const wchar_t* precision_start; const wchar_t* precision_end; size_t precision_arg_index; wchar_t conversion; /* d i o u x X f e E g G c s p n U % but not C S */ size_t arg_index; } wchar_t_directive; /* A parsed format string. */ typedef struct { size_t count; wchar_t_directive *dir; size_t max_width_length; size_t max_precision_length; } wchar_t_directives; /* Parses the format string. Fills in the number N of directives, and fills in directives[0], ..., directives[N-1], and sets directives[N].dir_start to the end of the format string. Also fills in the arg_type fields of the arguments and the needed count of arguments. */ #ifdef STATIC STATIC #else extern #endif int wprintf_parse (const wchar_t *format, wchar_t_directives *d, arguments *a); #endif /* _WPRINTF_PARSE_H */ lightspeed-1.2a.debian.1/intl/xsize.h000066400000000000000000000067261334064775200175340ustar00rootroot00000000000000/* xsize.h -- Checked size_t computations. Copyright (C) 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _XSIZE_H #define _XSIZE_H /* Get size_t. */ #include /* Get SIZE_MAX. */ #include #if HAVE_STDINT_H # include #endif /* The size of memory objects is often computed through expressions of type size_t. Example: void* p = malloc (header_size + n * element_size). These computations can lead to overflow. When this happens, malloc() returns a piece of memory that is way too small, and the program then crashes while attempting to fill the memory. To avoid this, the functions and macros in this file check for overflow. The convention is that SIZE_MAX represents overflow. malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc implementation that uses mmap --, it's recommended to use size_overflow_p() or size_in_bounds_p() before invoking malloc(). The example thus becomes: size_t size = xsum (header_size, xtimes (n, element_size)); void *p = (size_in_bounds_p (size) ? malloc (size) : NULL); */ /* Convert an arbitrary value >= 0 to type size_t. */ #define xcast_size_t(N) \ ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX) /* Sum of two sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum (size_t size1, size_t size2) { size_t sum = size1 + size2; return (sum >= size1 ? sum : SIZE_MAX); } /* Sum of three sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum3 (size_t size1, size_t size2, size_t size3) { return xsum (xsum (size1, size2), size3); } /* Sum of four sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xsum4 (size_t size1, size_t size2, size_t size3, size_t size4) { return xsum (xsum (xsum (size1, size2), size3), size4); } /* Maximum of two sizes, with overflow check. */ static inline size_t #if __GNUC__ >= 3 __attribute__ ((__pure__)) #endif xmax (size_t size1, size_t size2) { /* No explicit check is needed here, because for any n: max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */ return (size1 >= size2 ? size1 : size2); } /* Multiplication of a count with an element size, with overflow check. The count must be >= 0 and the element size must be > 0. This is a macro, not an inline function, so that it works correctly even when N is of a wider tupe and N > SIZE_MAX. */ #define xtimes(N, ELSIZE) \ ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX) /* Check for overflow. */ #define size_overflow_p(SIZE) \ ((SIZE) == SIZE_MAX) /* Check against overflow. */ #define size_in_bounds_p(SIZE) \ ((SIZE) != SIZE_MAX) #endif /* _XSIZE_H */ lightspeed-1.2a.debian.1/lightspeed.spec000066400000000000000000000023711334064775200202470ustar00rootroot00000000000000%define ver 1.2a %define rel 1 %define prefix /usr/X11R6 Summary: Light Speed! - an interactive relativistic simulator Name: lightspeed Version: %ver Release: %rel Copyright: MozPL/GPL Group: X11/Amusements URL: http://lightspeed.sourceforge.net/ Requires: gtk+ >= 1.0.1 BuildRoot: /tmp/lightspeed-%ver-root %description Light Speed! is an OpenGL-based program which illustrates the effects of special relativity on the appearance of moving objects. When an object accelerates past a few million meters per second, these effects begin to grow noticeable, becoming more and more pronounced as the speed of light is approached. These relativistic effects are viewpoint-dependent, and include shifts in length, object hue, brightness and shape. The moving object is, by default, a geometric lattice. 3D Studio and LightWave 3D objects may be imported as well. Best of all, the simulator is completely interactive, rendering the distortions in real-time! %prep %setup %build ./configure --prefix=%{prefix} make CFLAGS="$RPM_OPT_FLAGS" %install rm -rf $RPM_BUILD_ROOT make prefix=$RPM_BUILD_ROOT%{prefix} install-strip %clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %doc AUTHORS CONTROLS COPYING ChangeLog MATH OVERVIEW README TODO %{prefix}/bin/lightspeed lightspeed-1.2a.debian.1/po/000077500000000000000000000000001334064775200156565ustar00rootroot00000000000000lightspeed-1.2a.debian.1/po/ChangeLog000066400000000000000000000011421334064775200174260ustar00rootroot000000000000002006-05-07 gettextize * Makefile.in.in: New file, from gettext-0.14.5. 2006-05-07 gettextize * Makefile.in.in: Upgrade to gettext-0.14.5. * boldquot.sed: New file, from gettext-0.14.5. * en@boldquot.header: New file, from gettext-0.14.5. * en@quot.header: New file, from gettext-0.14.5. * insert-header.sin: New file, from gettext-0.14.5. * quot.sed: New file, from gettext-0.14.5. * remove-potcdate.sin: New file, from gettext-0.14.5. * Rules-quot: New file, from gettext-0.14.5. * cat-id-tbl.c: Remove file. * stamp-cat-id: Remove file. lightspeed-1.2a.debian.1/po/LINGUAS000066400000000000000000000000031334064775200166740ustar00rootroot00000000000000es lightspeed-1.2a.debian.1/po/Makevars000066400000000000000000000034511334064775200173550ustar00rootroot00000000000000# Makefile variables for PO directory in any package using GNU gettext. # Usually the message domain is the same as the package name. DOMAIN = $(PACKAGE) # These two variables depend on the location of this directory. subdir = po top_builddir = .. # These options get passed to xgettext. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding # package. (Note that the msgstr strings, extracted from the package's # sources, belong to the copyright holder of the package.) Translators are # expected to transfer the copyright for their translations to this person # or entity, or to disclaim their copyright. The empty string stands for # the public domain; in this case the translators are expected to disclaim # their copyright. COPYRIGHT_HOLDER = Daniel Richard G. # This is the email address or URL to which the translators shall report # bugs in the untranslated strings: # - Strings which are not entire sentences, see the maintainer guidelines # in the GNU gettext documentation, section 'Preparing Strings'. # - Strings which use unclear terms or require additional context to be # understood. # - Strings which make invalid assumptions about notation of date, time or # money. # - Pluralisation problems. # - Incorrect English spelling. # - Incorrect formatting. # It can be your email address, or a mailing list address where translators # can write to without being subscribed, or the URL of a web page through # which the translators can contact you. MSGID_BUGS_ADDRESS = skunk@alum.mit.edu # This is the list of locale categories, beyond LC_MESSAGES, for which the # message catalogs shall be used. It is usually empty. EXTRA_LOCALE_CATEGORIES = lightspeed-1.2a.debian.1/po/Makevars.template000066400000000000000000000034161334064775200211700ustar00rootroot00000000000000# Makefile variables for PO directory in any package using GNU gettext. # Usually the message domain is the same as the package name. DOMAIN = $(PACKAGE) # These two variables depend on the location of this directory. subdir = po top_builddir = .. # These options get passed to xgettext. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding # package. (Note that the msgstr strings, extracted from the package's # sources, belong to the copyright holder of the package.) Translators are # expected to transfer the copyright for their translations to this person # or entity, or to disclaim their copyright. The empty string stands for # the public domain; in this case the translators are expected to disclaim # their copyright. COPYRIGHT_HOLDER = Free Software Foundation, Inc. # This is the email address or URL to which the translators shall report # bugs in the untranslated strings: # - Strings which are not entire sentences, see the maintainer guidelines # in the GNU gettext documentation, section 'Preparing Strings'. # - Strings which use unclear terms or require additional context to be # understood. # - Strings which make invalid assumptions about notation of date, time or # money. # - Pluralisation problems. # - Incorrect English spelling. # - Incorrect formatting. # It can be your email address, or a mailing list address where translators # can write to without being subscribed, or the URL of a web page through # which the translators can contact you. MSGID_BUGS_ADDRESS = # This is the list of locale categories, beyond LC_MESSAGES, for which the # message catalogs shall be used. It is usually empty. EXTRA_LOCALE_CATEGORIES = lightspeed-1.2a.debian.1/po/POTFILES.in000066400000000000000000000004621334064775200174350ustar00rootroot00000000000000src/animation.c src/auxobjects.c src/camera.c src/command.c src/geometry.c src/globals.c src/gtkwidgets.c src/importobjs.c src/infodisp.c src/lattice.c src/lightspeed.c src/lstrings.c src/mainwindow.c src/menu_cbs.c src/misc.c src/ogl.c src/read3ds.c src/readlwo.c src/snapshot.c src/trackmem.c src/warp.c lightspeed-1.2a.debian.1/po/boldquot.sed000066400000000000000000000003311334064775200202010ustar00rootroot00000000000000s/"\([^"]*\)"/“\1â€/g s/`\([^`']*\)'/‘\1’/g s/ '\([^`']*\)' / ‘\1’ /g s/ '\([^`']*\)'$/ ‘\1’/g s/^'\([^`']*\)' /‘\1’ /g s/“â€/""/g s/“/“/g s/â€/â€/g s/‘/‘/g s/’/’/g lightspeed-1.2a.debian.1/po/en@boldquot.header000066400000000000000000000024711334064775200213100ustar00rootroot00000000000000# All this catalog "translates" are quotation characters. # The msgids must be ASCII and therefore cannot contain real quotation # characters, only substitutes like grave accent (0x60), apostrophe (0x27) # and double quote (0x22). These substitutes look strange; see # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html # # This catalog translates grave accent (0x60) and apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019). # It also translates pairs of apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019) # and pairs of quotation mark (0x22) to # left double quotation mark (U+201C) and right double quotation mark (U+201D). # # When output to an UTF-8 terminal, the quotation characters appear perfectly. # When output to an ISO-8859-1 terminal, the single quotation marks are # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to # grave/acute accent (by libiconv), and the double quotation marks are # transliterated to 0x22. # When output to an ASCII terminal, the single quotation marks are # transliterated to apostrophes, and the double quotation marks are # transliterated to 0x22. # # This catalog furthermore displays the text between the quotation marks in # bold face, assuming the VT100/XTerm escape sequences. # lightspeed-1.2a.debian.1/po/en@quot.header000066400000000000000000000022631334064775200204460ustar00rootroot00000000000000# All this catalog "translates" are quotation characters. # The msgids must be ASCII and therefore cannot contain real quotation # characters, only substitutes like grave accent (0x60), apostrophe (0x27) # and double quote (0x22). These substitutes look strange; see # http://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html # # This catalog translates grave accent (0x60) and apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019). # It also translates pairs of apostrophe (0x27) to # left single quotation mark (U+2018) and right single quotation mark (U+2019) # and pairs of quotation mark (0x22) to # left double quotation mark (U+201C) and right double quotation mark (U+201D). # # When output to an UTF-8 terminal, the quotation characters appear perfectly. # When output to an ISO-8859-1 terminal, the single quotation marks are # transliterated to apostrophes (by iconv in glibc 2.2 or newer) or to # grave/acute accent (by libiconv), and the double quotation marks are # transliterated to 0x22. # When output to an ASCII terminal, the single quotation marks are # transliterated to apostrophes, and the double quotation marks are # transliterated to 0x22. # lightspeed-1.2a.debian.1/po/es.po000066400000000000000000000361371334064775200166370ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR Free Software Foundation, Inc. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: lightspeed\n" "Report-Msgid-Bugs-To: skunk@alum.mit.edu\n" "POT-Creation-Date: 2006-05-13 17:16+0200\n" "PO-Revision-Date: 2006-05-07 11:54+0200\n" "Last-Translator: unknown\n" "Language-Team: unknown\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ISO-8859-1\n" "Content-Transfer-Encoding: 8bit\n" #: src/lightspeed.c:161 #, c-format msgid "Light Speed! requires OpenGL support to run." msgstr "Light Speed! necesita oporte OpenGL para funcionar." #: src/lstrings.c:38 #, c-format msgid "Copyright (C) %d by %s" msgstr "Copyright (C) %d por %s" #: src/lstrings.c:43 #, c-format msgid "usage: %s [-hsa] [object]" msgstr "uso: %s [-hsa] [objeto]" #: src/lstrings.c:45 msgid "Print this help screen" msgstr "Muestra esta ayuda" #: src/lstrings.c:47 msgid "Use simplified interface" msgstr "Usar interfaz simplificada" #: src/lstrings.c:48 msgid "Use advanced interface (default)" msgstr "Usar interfaz avanzada (por omisión)" #: src/lstrings.c:50 msgid "Use simple interface (default)" msgstr "Usar interfaz simple (por omisión)" #: src/lstrings.c:51 msgid "Use more advanced interface" msgstr "Usar interfaz más avanzada" #: src/lstrings.c:53 src/lstrings.c:173 msgid "object" msgstr "objeto" #: src/lstrings.c:53 msgid "3D file to load on startup (.3DS or .LWO)" msgstr "Archivo 3D a cargar inicialmente (.3DS o .LWO)" #: src/lstrings.c:60 msgid "File" msgstr "Archivo" #: src/lstrings.c:61 msgid "Objects" msgstr "Objetos" #: src/lstrings.c:62 msgid "Warp" msgstr "" #: src/lstrings.c:63 src/lstrings.c:217 msgid "Camera" msgstr "Cámara" #: src/lstrings.c:64 msgid "Help" msgstr "Ayuda" #: src/lstrings.c:67 msgid "New lattice..." msgstr "Nuevo enrejado..." #: src/lstrings.c:68 msgid "Load object..." msgstr "Cargar objeto..." #: src/lstrings.c:69 msgid "Save snapshot..." msgstr "Guardar imagen..." #: src/lstrings.c:70 msgid "Export SRS..." msgstr "Exportar SRS..." #: src/lstrings.c:71 msgid "Exit" msgstr "Salir" #: src/lstrings.c:74 msgid "Coordinate axes" msgstr "Ejes de coordenadas" #: src/lstrings.c:75 msgid "Floating grid" msgstr "Grilla flotante" #: src/lstrings.c:76 msgid "Bounding box" msgstr "Caja contenedora" #: src/lstrings.c:77 msgid "Animation..." msgstr "Animación..." #: src/lstrings.c:80 msgid "Lorentz contraction" msgstr "Contracción de Lorentz" #: src/lstrings.c:81 msgid "Doppler red/blue shift" msgstr "Corrimiento al rojo Doppler" #: src/lstrings.c:82 msgid "Headlight effect" msgstr "Efecto headlight" #: src/lstrings.c:83 msgid "Optical aberration" msgstr "Aberración óptica" #: src/lstrings.c:86 msgid "Lens" msgstr "Lente" #: src/lstrings.c:87 msgid "Position..." msgstr "Posición..." #: src/lstrings.c:88 msgid "Reset view" msgstr "Restaurar vista" #: src/lstrings.c:89 msgid "Info display" msgstr "Mostrar información" #: src/lstrings.c:90 msgid "Background" msgstr "Fondo" #: src/lstrings.c:91 msgid "Graphics mode" msgstr "Modo gráfico" #: src/lstrings.c:92 msgid "Spawn camera" msgstr "Nueva cámara" #: src/lstrings.c:93 src/lstrings.c:145 msgid "Close" msgstr "Cerrar" #: src/lstrings.c:96 msgid "Custom" msgstr "Configurar" #: src/lstrings.c:99 msgid "Active" msgstr "Activar" #: src/lstrings.c:100 msgid "Velocity" msgstr "Velocidad" #: src/lstrings.c:101 msgid "Time t" msgstr "Tiempo t" #: src/lstrings.c:102 msgid "Gamma factor" msgstr "Factor gama" #: src/lstrings.c:103 msgid "Framerate" msgstr "Tasa de refresco" #: src/lstrings.c:107 msgid "Black" msgstr "Negro" #: src/lstrings.c:107 msgid "Grey" msgstr "Gris" #: src/lstrings.c:107 msgid "White" msgstr "Blanco" #: src/lstrings.c:107 msgid "Very white" msgstr "Muy blanco" #: src/lstrings.c:110 msgid "Wireframe" msgstr "Malla de alambre" #: src/lstrings.c:111 msgid "Shaded" msgstr "Sombreado" #: src/lstrings.c:114 src/lstrings.c:203 msgid "Overview" msgstr "Resumen" #: src/lstrings.c:115 src/lstrings.c:206 msgid "Controls" msgstr "Controles" #: src/lstrings.c:116 src/lstrings.c:209 msgid "About" msgstr "Acerca..." #: src/lstrings.c:122 #, c-format msgid "t = %ssec" msgstr "" #: src/lstrings.c:125 #, c-format msgid "%.1f fps" msgstr "%.1f cps" #: src/lstrings.c:129 #, c-format msgid "Velocity: %s" msgstr "Velocidad: %s" #: src/lstrings.c:132 #, c-format msgid "gamma = %.3f" msgstr "gama = %.3f" #: src/lstrings.c:135 msgid "LORENTZ CONTRACTION NOT SHOWN" msgstr "NO SE MUESTRA CONTRACCIÓN DE LORENTZ" #: src/lstrings.c:136 msgid "DOPPLER RED/BLUE SHIFT NOT SHOWN" msgstr "NO SE MUESTRA CORRIMIENTO AL ROJO DOPPLER" #: src/lstrings.c:137 msgid "HEADLIGHT EFFECT NOT SHOWN" msgstr "NO SE MUESTRA EFECTO HEADLIGHT" #: src/lstrings.c:138 msgid "OPTICAL ABERRATION NOT SHOWN" msgstr "NO SE MUESTRA ABERRACIÓN ÓPTICA" #: src/lstrings.c:139 msgid "NO RELATIVISTIC EFFECTS SHOWN!!!" msgstr "¡¡¡NO SE MUESTRAN EFECTOS RELATIVÍSTICOS!!!" #: src/lstrings.c:143 src/lstrings.c:266 msgid "OK" msgstr "" #: src/lstrings.c:144 msgid "Cancel" msgstr "Cancelar" #: src/lstrings.c:148 msgid "New lattice" msgstr "Nuevo enrejado" #: src/lstrings.c:149 msgid "Dimensions" msgstr "Dimensiones" #: src/lstrings.c:150 msgid "Smoothness" msgstr "Suavidad" #: src/lstrings.c:153 msgid "Load Object" msgstr "Cargar Objeto" #: src/lstrings.c:154 msgid "Recognized formats" msgstr "Formatos reconocidos" #: src/lstrings.c:155 msgid "" "3D Studio: *.3DS or *.PRJ\n" "LightWave 3D: *.LWO" msgstr "" "3D Studio: *.3DS o *.PRJ\n" "LightWave 3D: *.LWO" #: src/lstrings.c:158 msgid "Save Snapshot" msgstr "Guardar Imagen" #: src/lstrings.c:159 src/lstrings.c:167 msgid "Parameters" msgstr "Parámetros" #: src/lstrings.c:160 msgid "Size" msgstr "Tamaño" #: src/lstrings.c:161 msgid "Format" msgstr "Formato" #: src/lstrings.c:162 msgid "snapshot" msgstr "" #: src/lstrings.c:165 msgid "Export SRS" msgstr "Exportar SRS" #: src/lstrings.c:166 msgid "Special Relativity Scene (SRS)" msgstr "" #: src/lstrings.c:168 msgid "Rendered size" msgstr "" #: src/lstrings.c:169 msgid "Stereoscopic view" msgstr "Vista Estereoscópica" #: src/lstrings.c:170 msgid "Visible faces only" msgstr "Sólo caras visibles" #: src/lstrings.c:172 msgid "lattice" msgstr "" #: src/lstrings.c:176 msgid "Animation" msgstr "Animación" #: src/lstrings.c:177 msgid "Observed range of motion" msgstr "Rango de movimiento observado" #: src/lstrings.c:178 msgid "Starting X" msgstr "X inicial" #: src/lstrings.c:179 msgid "Ending X" msgstr "X final" #: src/lstrings.c:180 msgid "Loop time: " msgstr "" #: src/lstrings.c:181 msgid " seconds" msgstr " segundos" #: src/lstrings.c:182 msgid "Begin" msgstr "Comenzar" #: src/lstrings.c:183 msgid "Stop" msgstr "Detener" #: src/lstrings.c:186 msgid "Camera Position" msgstr "Posición de la Cámara" #: src/lstrings.c:187 msgid "Location" msgstr "Ubicación" #: src/lstrings.c:188 msgid "View target" msgstr "Ver objetivo" #: src/lstrings.c:189 msgid "Direction" msgstr "Dirección" #: src/lstrings.c:190 msgid "Phi [0, 360)" msgstr "Fi [0, 360)" #: src/lstrings.c:191 msgid "Theta [-90, 90]" msgstr "Teta [-90, 90]" #: src/lstrings.c:192 msgid "Specify phi/theta direction instead" msgstr "Especificar dirección fi/teta" #: src/lstrings.c:193 msgid "Specify (x,y,z) view target instead" msgstr "" #: src/lstrings.c:194 msgid "Reposition" msgstr "Reposicionar" #: src/lstrings.c:197 msgid "Custom Lens" msgstr "Configurar Lente" #: src/lstrings.c:198 msgid "Lens length" msgstr "Largo del lente" #: src/lstrings.c:199 msgid "Field of view" msgstr "Campo de visión" #: src/lstrings.c:200 msgid "deg" msgstr "°" #: src/lstrings.c:211 #, c-format msgid "Version %s" msgstr "Versión %s" #: src/lstrings.c:213 #, c-format msgid "A Theory Toy by %s" msgstr "Un Juguete Teórico por %s" #: src/lstrings.c:220 msgid "Warning" msgstr "Aviso" #: src/lstrings.c:221 msgid "Error" msgstr "" #: src/lstrings.c:225 msgid "" "Light Speed! is a simulator which can illustrate the effects of\n" "special relativity on the appearance of objects travelling at\n" "ultra-high speeds. Depending on the particular speed, and one's\n" "point of view, relativistic effects can cause the object to\n" "appear shorter, longer, brighter, darker, deformed and/or\n" "off-color.\n" "\n" "To adjust the velocity, use the slider along the right edge of\n" "the main window. You can also type in a value, using the entry\n" "at the top right (press once it is in). To change the\n" "units shown, press the button to the right of the entry, and it\n" "will cycle through a small list.\n" "\n" "The object travels in the positive-x direction, which can be\n" "visually checked by activating Objects -> Coordinate axes.\n" msgstr "" "Light Speed! es un simulador que puede ilustrar los efectos de\n" "la relatividad especial en la apariencia de objetos viajando a\n" "ultra-altas velocidades. Dependiendo de la velocidad particular,\n" "y del punto de vista, los efectos relativísticos pueden causar que\n" "el objeto se vea más corto, largo, brillante, oscuro, deformado\n" "o con los colores corridos.\n" "\n" "Para ajustar la velocidad, use la barra deslizante del borde\n" "derecho de la ventana principal. Usted puede también escribir\n" "un valor, usando el campo de texto en la esquina superior derecha\n" "(presione luego). Para cambiar las unidades mostradas,\n" "presione el botón a la derecha del campo, y ciclará a través de\n" "una pequeña lista.\n" "\n" "El objeto viaja en la dirección positiva del eje X, lo que puede\n" "ser visualmente comprobado activando la opción Objetos -> Ejes de\n" "coordenadas.\n" #: src/lstrings.c:245 msgid "" "Most interactive control is performed with the mouse. By holding\n" "down a particular button, and dragging the pointer around,\n" "various camera motions can be obtained:\n" "\n" " Left button: Revolve camera around view targetg\n" "\n" " Left button + Shift key: Revolve view target around camera\n" "\n" " Middle button: Translate camera left, right, up or down\n" "\n" " Right button: Dolly in or out\n" "\n" "The first and last motions are generally the most useful.\n" "Should the camera become difficult to control at any point, it\n" "may be re-initialized by selecting Camera -> Reset View.\n" msgstr "" "La mayor parte del control interactivo se realiza con el mouse.\n" "Manteniendo presionado un botón particular y arrastrando el\n" "puntero se pueden obtener varios movimientos de cámara:\n" "\n" " Botón izquierdo: Gira la cámara alrededor del objetivo\n" "\n" " Botón izquierdo + Shift: Gira el objetivo alrededor de la cámara\n" "\n" " Botón del medio: Traslación de la cámara hacia la izquierda,\n" " derecha, arriba o abajo\n" "\n" " Botón derecho: Acerca y aleja la cámara\n" "\n" "El primer y el último movmiento son generalmente los más útiles.\n" "Si llegado un punto el control de la cámara se volviera complicado,\n" "ésta se puede restaurar seleccionando Cámara -> Restaurar Vista.\n" #: src/lstrings.c:267 msgid "INVALID" msgstr "INVÁLIDO" #: src/lstrings.c:271 #, c-format msgid "" "The file \"%s\" already exists.\n" "Press OK to overwrite it." msgstr "" "El archivo \"%s\" ya existe.\n" "Presione OK para sobreescribirlo." #: src/lstrings.c:275 #, c-format msgid "" "The specified object file could not be opened.\n" "(%s)\n" "Import operation failed." msgstr "" "El archivo especificadono pudo ser abierto.\n" "(%s)\n" "Falló la importación." #: src/lstrings.c:276 msgid "" "The file lacks a valid 3DS signature.\n" "Import operation failed." msgstr "" "El archivo no tiene una firma 3DS válida.\n" "Falló la importación." #: src/lstrings.c:277 msgid "" "The file lacks a valid 3D Studio PRJ signature.\n" "Import operation failed." msgstr "" "El archivo no tiene una firma PRJ de 3D Studio válida.\n" "Falló la importación." #: src/lstrings.c:278 msgid "" "The file lacks a valid LWOB signature.\n" "Import operation failed." msgstr "" "El archivo no tiene una firma LWOB válida.\n" "Falló la importación." #: src/lstrings.c:279 msgid "" "The object must be in 3D Studio (3DS)\n" "or LightWave 3D (LWO) file format.\n" "Import operation failed." msgstr "" "El objeto debe estar en formato 3D Studio (3DS)\n" "o LightWave 3D (LWO).Falló la importación." #: src/lstrings.c:280 msgid "" "The 3D Studio file could not be properly read.\n" "Import operation failed." msgstr "" "El archivo de 3D Studio no pudo ser leido apropiadamente.\n" "Falló la importación." #: src/lstrings.c:281 msgid "" "The 3D Studio file has no valid geometry.\n" "Import operation failed." msgstr "" "El archivo de 3D Studio no tiene una geometría válida.\n" "Falló la importación." #: src/lstrings.c:282 msgid "" "The LightWave file could not be properly read.\n" "Import operation failed." msgstr "" "El archivo de LightWave no pudo ser leido apropiadamente.\n" "Falló la importación." #: src/lstrings.c:283 msgid "" "The LightWave file has no valid geometry.\n" "Import operation failed." msgstr "" "El archivo de LightWave no tiene una geometría válida.\n" "Falló la importación." #: src/lstrings.c:286 msgid "" "The system could not provide the required visual.\n" "Save operation failed." msgstr "" #: src/lstrings.c:288 #, c-format msgid "" "A %dx%d render buffer could not be allocated.\n" "Save operation failed." msgstr "" #: src/lstrings.c:289 msgid "" "The required OpenGL context was not available.\n" "Save operation failed." msgstr "" #: src/lstrings.c:290 msgid "" "An error occurred in creating the output file.\n" "Save operation failed." msgstr "" #: src/lstrings.c:293 msgid "GENERATING LATTICE . . ." msgstr "" #: src/lstrings.c:294 msgid "LOADING OBJECT . . ." msgstr "CARGANDO OBJETO . . ." #: src/lstrings.c:295 msgid "RENDERING . . ." msgstr "" #: src/lstrings.c:297 #, c-format msgid "" "SAVING SNAPSHOT . . .\n" "(%d%%)" msgstr "" #: src/snapshot.c:134 #, c-format msgid "" "%dx%dx%d lattice, travelling at %s in the +x direction.\n" "\n" msgstr "" "Enrejado %dx%dx%d, viajando a %s en la dirección +x.\n" "\n" #: src/snapshot.c:139 #, c-format msgid "" "Object travelling at %s in the +x direction.\n" "\n" msgstr "" "Objeto viajando a %s en la dirección +x.\n" "\n" #: src/snapshot.c:143 #, c-format msgid "Camera position: (%.3f, %.3f, %.3f)\n" msgstr "Posición de la cámara: (%.3f, %.3f, %.3f)\n" #: src/snapshot.c:148 #, c-format msgid "Camera target..: (%.3f, %.3f, %.3f)\n" msgstr "Objetivo de la cámara: (%.3f, %.3f, %.3f)\n" #: src/snapshot.c:150 #, c-format msgid "Camera FOV.....: %.2f degrees" msgstr "FOV de la cámara.....: %.2f grados" #: src/snapshot.c:153 #, c-format msgid "" " horizontally\n" "\n" msgstr "" " horizontalmente\n" "\n" #: src/snapshot.c:157 #, c-format msgid "Observed object is centered at the origin.\n" msgstr "El objeto observado está centrado en el origen.\n" #: src/snapshot.c:159 #, c-format msgid "Coordinate system is right-handed with +z up.\n" msgstr "" #: src/snapshot.c:161 #, c-format msgid "" "Above units are in meters, where unspecified.\n" "\n" msgstr "" #: src/snapshot.c:163 #, c-format msgid "This image was produced by the Light Speed! relativistic simulator.\n" msgstr "" "Esta imagen fue producida por el simulador relativístico Light Speed!.\n" #: src/snapshot.c:239 msgid "while writing the image to the file" msgstr "" #: src/snapshot.c:294 msgid "Light Speed! snapshot" msgstr "" lightspeed-1.2a.debian.1/po/insert-header.sin000066400000000000000000000012401334064775200211200ustar00rootroot00000000000000# Sed script that inserts the file called HEADER before the header entry. # # At each occurrence of a line starting with "msgid ", we execute the following # commands. At the first occurrence, insert the file. At the following # occurrences, do nothing. The distinction between the first and the following # occurrences is achieved by looking at the hold space. /^msgid /{ x # Test if the hold space is empty. s/m/m/ ta # Yes it was empty. First occurrence. Read the file. r HEADER # Output the file's contents by reading the next line. But don't lose the # current line while doing this. g N bb :a # The hold space was nonempty. Following occurrences. Do nothing. x :b } lightspeed-1.2a.debian.1/po/lightspeed.pot000066400000000000000000000260011334064775200205310ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR Daniel Richard G. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: skunk@alum.mit.edu\n" "POT-Creation-Date: 2006-05-13 17:16+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/lightspeed.c:161 #, c-format msgid "Light Speed! requires OpenGL support to run." msgstr "" #: src/lstrings.c:38 #, c-format msgid "Copyright (C) %d by %s" msgstr "" #: src/lstrings.c:43 #, c-format msgid "usage: %s [-hsa] [object]" msgstr "" #: src/lstrings.c:45 msgid "Print this help screen" msgstr "" #: src/lstrings.c:47 msgid "Use simplified interface" msgstr "" #: src/lstrings.c:48 msgid "Use advanced interface (default)" msgstr "" #: src/lstrings.c:50 msgid "Use simple interface (default)" msgstr "" #: src/lstrings.c:51 msgid "Use more advanced interface" msgstr "" #: src/lstrings.c:53 src/lstrings.c:173 msgid "object" msgstr "" #: src/lstrings.c:53 msgid "3D file to load on startup (.3DS or .LWO)" msgstr "" #: src/lstrings.c:60 msgid "File" msgstr "" #: src/lstrings.c:61 msgid "Objects" msgstr "" #: src/lstrings.c:62 msgid "Warp" msgstr "" #: src/lstrings.c:63 src/lstrings.c:217 msgid "Camera" msgstr "" #: src/lstrings.c:64 msgid "Help" msgstr "" #: src/lstrings.c:67 msgid "New lattice..." msgstr "" #: src/lstrings.c:68 msgid "Load object..." msgstr "" #: src/lstrings.c:69 msgid "Save snapshot..." msgstr "" #: src/lstrings.c:70 msgid "Export SRS..." msgstr "" #: src/lstrings.c:71 msgid "Exit" msgstr "" #: src/lstrings.c:74 msgid "Coordinate axes" msgstr "" #: src/lstrings.c:75 msgid "Floating grid" msgstr "" #: src/lstrings.c:76 msgid "Bounding box" msgstr "" #: src/lstrings.c:77 msgid "Animation..." msgstr "" #: src/lstrings.c:80 msgid "Lorentz contraction" msgstr "" #: src/lstrings.c:81 msgid "Doppler red/blue shift" msgstr "" #: src/lstrings.c:82 msgid "Headlight effect" msgstr "" #: src/lstrings.c:83 msgid "Optical aberration" msgstr "" #: src/lstrings.c:86 msgid "Lens" msgstr "" #: src/lstrings.c:87 msgid "Position..." msgstr "" #: src/lstrings.c:88 msgid "Reset view" msgstr "" #: src/lstrings.c:89 msgid "Info display" msgstr "" #: src/lstrings.c:90 msgid "Background" msgstr "" #: src/lstrings.c:91 msgid "Graphics mode" msgstr "" #: src/lstrings.c:92 msgid "Spawn camera" msgstr "" #: src/lstrings.c:93 src/lstrings.c:145 msgid "Close" msgstr "" #: src/lstrings.c:96 msgid "Custom" msgstr "" #: src/lstrings.c:99 msgid "Active" msgstr "" #: src/lstrings.c:100 msgid "Velocity" msgstr "" #: src/lstrings.c:101 msgid "Time t" msgstr "" #: src/lstrings.c:102 msgid "Gamma factor" msgstr "" #: src/lstrings.c:103 msgid "Framerate" msgstr "" #: src/lstrings.c:107 msgid "Black" msgstr "" #: src/lstrings.c:107 msgid "Grey" msgstr "" #: src/lstrings.c:107 msgid "White" msgstr "" #: src/lstrings.c:107 msgid "Very white" msgstr "" #: src/lstrings.c:110 msgid "Wireframe" msgstr "" #: src/lstrings.c:111 msgid "Shaded" msgstr "" #: src/lstrings.c:114 src/lstrings.c:203 msgid "Overview" msgstr "" #: src/lstrings.c:115 src/lstrings.c:206 msgid "Controls" msgstr "" #: src/lstrings.c:116 src/lstrings.c:209 msgid "About" msgstr "" #: src/lstrings.c:122 #, c-format msgid "t = %ssec" msgstr "" #: src/lstrings.c:125 #, c-format msgid "%.1f fps" msgstr "" #: src/lstrings.c:129 #, c-format msgid "Velocity: %s" msgstr "" #: src/lstrings.c:132 #, c-format msgid "gamma = %.3f" msgstr "" #: src/lstrings.c:135 msgid "LORENTZ CONTRACTION NOT SHOWN" msgstr "" #: src/lstrings.c:136 msgid "DOPPLER RED/BLUE SHIFT NOT SHOWN" msgstr "" #: src/lstrings.c:137 msgid "HEADLIGHT EFFECT NOT SHOWN" msgstr "" #: src/lstrings.c:138 msgid "OPTICAL ABERRATION NOT SHOWN" msgstr "" #: src/lstrings.c:139 msgid "NO RELATIVISTIC EFFECTS SHOWN!!!" msgstr "" #: src/lstrings.c:143 src/lstrings.c:266 msgid "OK" msgstr "" #: src/lstrings.c:144 msgid "Cancel" msgstr "" #: src/lstrings.c:148 msgid "New lattice" msgstr "" #: src/lstrings.c:149 msgid "Dimensions" msgstr "" #: src/lstrings.c:150 msgid "Smoothness" msgstr "" #: src/lstrings.c:153 msgid "Load Object" msgstr "" #: src/lstrings.c:154 msgid "Recognized formats" msgstr "" #: src/lstrings.c:155 msgid "" "3D Studio: *.3DS or *.PRJ\n" "LightWave 3D: *.LWO" msgstr "" #: src/lstrings.c:158 msgid "Save Snapshot" msgstr "" #: src/lstrings.c:159 src/lstrings.c:167 msgid "Parameters" msgstr "" #: src/lstrings.c:160 msgid "Size" msgstr "" #: src/lstrings.c:161 msgid "Format" msgstr "" #: src/lstrings.c:162 msgid "snapshot" msgstr "" #: src/lstrings.c:165 msgid "Export SRS" msgstr "" #: src/lstrings.c:166 msgid "Special Relativity Scene (SRS)" msgstr "" #: src/lstrings.c:168 msgid "Rendered size" msgstr "" #: src/lstrings.c:169 msgid "Stereoscopic view" msgstr "" #: src/lstrings.c:170 msgid "Visible faces only" msgstr "" #: src/lstrings.c:172 msgid "lattice" msgstr "" #: src/lstrings.c:176 msgid "Animation" msgstr "" #: src/lstrings.c:177 msgid "Observed range of motion" msgstr "" #: src/lstrings.c:178 msgid "Starting X" msgstr "" #: src/lstrings.c:179 msgid "Ending X" msgstr "" #: src/lstrings.c:180 msgid "Loop time: " msgstr "" #: src/lstrings.c:181 msgid " seconds" msgstr "" #: src/lstrings.c:182 msgid "Begin" msgstr "" #: src/lstrings.c:183 msgid "Stop" msgstr "" #: src/lstrings.c:186 msgid "Camera Position" msgstr "" #: src/lstrings.c:187 msgid "Location" msgstr "" #: src/lstrings.c:188 msgid "View target" msgstr "" #: src/lstrings.c:189 msgid "Direction" msgstr "" #: src/lstrings.c:190 msgid "Phi [0, 360)" msgstr "" #: src/lstrings.c:191 msgid "Theta [-90, 90]" msgstr "" #: src/lstrings.c:192 msgid "Specify phi/theta direction instead" msgstr "" #: src/lstrings.c:193 msgid "Specify (x,y,z) view target instead" msgstr "" #: src/lstrings.c:194 msgid "Reposition" msgstr "" #: src/lstrings.c:197 msgid "Custom Lens" msgstr "" #: src/lstrings.c:198 msgid "Lens length" msgstr "" #: src/lstrings.c:199 msgid "Field of view" msgstr "" #: src/lstrings.c:200 msgid "deg" msgstr "" #: src/lstrings.c:211 #, c-format msgid "Version %s" msgstr "" #: src/lstrings.c:213 #, c-format msgid "A Theory Toy by %s" msgstr "" #: src/lstrings.c:220 msgid "Warning" msgstr "" #: src/lstrings.c:221 msgid "Error" msgstr "" #: src/lstrings.c:225 msgid "" "Light Speed! is a simulator which can illustrate the effects of\n" "special relativity on the appearance of objects travelling at\n" "ultra-high speeds. Depending on the particular speed, and one's\n" "point of view, relativistic effects can cause the object to\n" "appear shorter, longer, brighter, darker, deformed and/or\n" "off-color.\n" "\n" "To adjust the velocity, use the slider along the right edge of\n" "the main window. You can also type in a value, using the entry\n" "at the top right (press once it is in). To change the\n" "units shown, press the button to the right of the entry, and it\n" "will cycle through a small list.\n" "\n" "The object travels in the positive-x direction, which can be\n" "visually checked by activating Objects -> Coordinate axes.\n" msgstr "" #: src/lstrings.c:245 msgid "" "Most interactive control is performed with the mouse. By holding\n" "down a particular button, and dragging the pointer around,\n" "various camera motions can be obtained:\n" "\n" " Left button: Revolve camera around view targetg\n" "\n" " Left button + Shift key: Revolve view target around camera\n" "\n" " Middle button: Translate camera left, right, up or down\n" "\n" " Right button: Dolly in or out\n" "\n" "The first and last motions are generally the most useful.\n" "Should the camera become difficult to control at any point, it\n" "may be re-initialized by selecting Camera -> Reset View.\n" msgstr "" #: src/lstrings.c:267 msgid "INVALID" msgstr "" #: src/lstrings.c:271 #, c-format msgid "" "The file \"%s\" already exists.\n" "Press OK to overwrite it." msgstr "" #: src/lstrings.c:275 #, c-format msgid "" "The specified object file could not be opened.\n" "(%s)\n" "Import operation failed." msgstr "" #: src/lstrings.c:276 msgid "" "The file lacks a valid 3DS signature.\n" "Import operation failed." msgstr "" #: src/lstrings.c:277 msgid "" "The file lacks a valid 3D Studio PRJ signature.\n" "Import operation failed." msgstr "" #: src/lstrings.c:278 msgid "" "The file lacks a valid LWOB signature.\n" "Import operation failed." msgstr "" #: src/lstrings.c:279 msgid "" "The object must be in 3D Studio (3DS)\n" "or LightWave 3D (LWO) file format.\n" "Import operation failed." msgstr "" #: src/lstrings.c:280 msgid "" "The 3D Studio file could not be properly read.\n" "Import operation failed." msgstr "" #: src/lstrings.c:281 msgid "" "The 3D Studio file has no valid geometry.\n" "Import operation failed." msgstr "" #: src/lstrings.c:282 msgid "" "The LightWave file could not be properly read.\n" "Import operation failed." msgstr "" #: src/lstrings.c:283 msgid "" "The LightWave file has no valid geometry.\n" "Import operation failed." msgstr "" #: src/lstrings.c:286 msgid "" "The system could not provide the required visual.\n" "Save operation failed." msgstr "" #: src/lstrings.c:288 #, c-format msgid "" "A %dx%d render buffer could not be allocated.\n" "Save operation failed." msgstr "" #: src/lstrings.c:289 msgid "" "The required OpenGL context was not available.\n" "Save operation failed." msgstr "" #: src/lstrings.c:290 msgid "" "An error occurred in creating the output file.\n" "Save operation failed." msgstr "" #: src/lstrings.c:293 msgid "GENERATING LATTICE . . ." msgstr "" #: src/lstrings.c:294 msgid "LOADING OBJECT . . ." msgstr "" #: src/lstrings.c:295 msgid "RENDERING . . ." msgstr "" #: src/lstrings.c:297 #, c-format msgid "" "SAVING SNAPSHOT . . .\n" "(%d%%)" msgstr "" #: src/snapshot.c:134 #, c-format msgid "" "%dx%dx%d lattice, travelling at %s in the +x direction.\n" "\n" msgstr "" #: src/snapshot.c:139 #, c-format msgid "" "Object travelling at %s in the +x direction.\n" "\n" msgstr "" #: src/snapshot.c:143 #, c-format msgid "Camera position: (%.3f, %.3f, %.3f)\n" msgstr "" #: src/snapshot.c:148 #, c-format msgid "Camera target..: (%.3f, %.3f, %.3f)\n" msgstr "" #: src/snapshot.c:150 #, c-format msgid "Camera FOV.....: %.2f degrees" msgstr "" #: src/snapshot.c:153 #, c-format msgid "" " horizontally\n" "\n" msgstr "" #: src/snapshot.c:157 #, c-format msgid "Observed object is centered at the origin.\n" msgstr "" #: src/snapshot.c:159 #, c-format msgid "Coordinate system is right-handed with +z up.\n" msgstr "" #: src/snapshot.c:161 #, c-format msgid "" "Above units are in meters, where unspecified.\n" "\n" msgstr "" #: src/snapshot.c:163 #, c-format msgid "This image was produced by the Light Speed! relativistic simulator.\n" msgstr "" #: src/snapshot.c:239 msgid "while writing the image to the file" msgstr "" #: src/snapshot.c:294 msgid "Light Speed! snapshot" msgstr "" lightspeed-1.2a.debian.1/po/quot.sed000066400000000000000000000002311334064775200173370ustar00rootroot00000000000000s/"\([^"]*\)"/“\1â€/g s/`\([^`']*\)'/‘\1’/g s/ '\([^`']*\)' / ‘\1’ /g s/ '\([^`']*\)'$/ ‘\1’/g s/^'\([^`']*\)' /‘\1’ /g s/“â€/""/g lightspeed-1.2a.debian.1/po/remove-potcdate.sin000066400000000000000000000006601334064775200214710ustar00rootroot00000000000000# Sed script that remove the POT-Creation-Date line in the header entry # from a POT file. # # The distinction between the first and the following occurrences of the # pattern is achieved by looking at the hold space. /^"POT-Creation-Date: .*"$/{ x # Test if the hold space is empty. s/P/P/ ta # Yes it was empty. First occurrence. Remove the line. g d bb :a # The hold space was nonempty. Following occurrences. Do nothing. x :b } lightspeed-1.2a.debian.1/src/000077500000000000000000000000001334064775200160275ustar00rootroot00000000000000lightspeed-1.2a.debian.1/src/Makefile.am000066400000000000000000000024201334064775200200610ustar00rootroot00000000000000## src/Makefile.am localedir = $(datadir)/locale #this is mandated by GNU standards # ( see 'info autoconf' at section 'Installation Directory Variables' ) lightspeed_CPPFLAGS=$(CPPFLAGS) -DLOCALEDIR=\"$(localedir)\" -DDATADIR=\"$(datadir)\" lightspeed_CFLAGS=$(GTK_CFLAGS) $(GL_CFLAGS) $(GTKGL_CFLAGS) lightspeed_CXXFLAGS=$(GTK_CFLAGS) $(GL_CFLAGS) $(GTKGL_CFLAGS) $(FTGL_CFLAGS) $(FC_CFLAGS) lightspeed_LDADD=$(GTKGL_LIBS) $(GTK_LIBS) $(GL_LIBS) $(FTGL_LIBS) $(FC_LIBS) $(IMG_LIBS) bin_PROGRAMS = lightspeed if COND_FTGL o=ogl-ftgl.cc else if COND_GTK1 o=ogl-gtk1.c else o=ogl-gtk2.c endif endif lightspeed_SOURCES = \ compat.h \ lightspeed.h \ lstrings.h \ read3ds.h \ readlwo.h \ settings.h \ trackmem.h \ animation.c \ auxobjects.c \ camera.c \ command.c \ geometry.c \ globals.c \ gtkwidgets.c \ importobjs.c \ infodisp.c \ lattice.c \ lightspeed.c \ lstrings.c \ mainwindow.c \ menu_cbs.c \ misc.c \ ogl.c $(o) \ read3ds.c \ readlwo.c \ snapshot.c \ trackmem.c \ warp.c EXTRA_DIST = gtkglext-workaround.c \ icon.xpm \ title.xpm ## end src/Makefile.am lightspeed-1.2a.debian.1/src/animation.c000066400000000000000000000307501334064775200201570ustar00rootroot00000000000000/* animation.c */ /* Main update loop + transition/animation handlers */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Forward declarations */ static int idle_loop( void ); static int transition_engine( trans_var *new_tvar ); /* Queue a redraw, i.e. flag a camera [viewport] as needing a redraw * Pass a value of -1 to redraw everything */ void queue_redraw( int cam_id ) { int i; if (cam_id < 0) { for (i = 0; i < num_cams; i++) usr_cams[i]->redraw = TRUE; } else usr_cams[cam_id]->redraw = TRUE; /* Idle loop will bring about the actual redraws */ update( ACTIVATE ); } /* This function keeps everything moving and up-to-date */ int update( int message ) { static int active = FALSE; int state_change; int redraw_occurred = FALSE; int redraw_deferred = FALSE; int i; switch( message ) { case ITERATION: /* we're being called from idle_loop( ) */ break; case ACTIVATE: if (active) return FALSE; /* already running */ active = TRUE; /* Hook our idle loop in */ gtk_idle_add( (GtkFunction)idle_loop, NULL ); return TRUE; default: #ifdef DEBUG crash( "update( ): invalid message" ); #endif return FALSE; } /* Begin timing */ profile( PROFILE_START_ITERATION ); profile( PROFILE_FRAME_BEGIN ); /* Update all variables in transitory status */ state_change = transition_engine( NULL ); /* Do pending redraws (if any) ONLY if event queue is empty */ #ifdef HAVE_GTK1 if (gtk_events_pending( ) == 0) /* in GTK2 this is always false */ #endif { for (i = 0; i < num_cams; i++) if (usr_cams[i]->redraw) { camera_calc_xyz( CAM_POSITION, usr_cams[i] ); ogl_draw( i ); redraw_occurred = TRUE; } #if VELOCITY_SLIDER /* Update velocity slider */ velocity_slider( NULL, MESG_(RESET) ); #endif } #ifdef HAVE_GTK1 else redraw_deferred = TRUE; #endif /* Semi-BUG: Framerate goes artificially high if only spawned cameras are moved * (remember that moving the primary camera updates *all* views) */ if (redraw_occurred) profile( PROFILE_FRAME_DONE ); if (!state_change && !redraw_deferred) { active = FALSE; /* no state change, no pending redraw */ profile( PROFILE_IDLE ); } return active; } /* "Lackey" idle loop for update( ) * Remember, returning TRUE makes loop run again, returning FALSE stops it... */ static int idle_loop( void ) { return update( ITERATION ); } /* Performance profiler, keeps track of framerate and other timely stats */ void profile( int message ) { static double main_t0; static double iteration_t0 = -1.0; static double active_total_t = 0.0; static double frame_t0; static double *frametimes = NULL; static double sum_frametimes; static double warp_t0; static double warp_total_t = 0.0; static double ogldraw_t0; static double ogldraw_total_t = 0.0; static int num_frametimes; static int frame_num = -1; double delta_t; double cur_t; double p; int i; cur_t = read_system_clock( ); switch (message) { case INITIALIZE: main_t0 = cur_t; break; case PROFILE_START_ITERATION: if (iteration_t0 > 0.0) { delta_t = cur_t - iteration_t0; active_total_t += delta_t; } iteration_t0 = cur_t; break; case PROFILE_IDLE: delta_t = cur_t - iteration_t0; active_total_t += delta_t; iteration_t0 = -1.0; break; case PROFILE_FRAME_BEGIN: frame_t0 = cur_t; break; case PROFILE_FRAME_DONE: delta_t = cur_t - frame_t0; if (frame_num == -1) { /* (Re)initialize frametime buffer */ num_frametimes = (int)((FRAMERATE_AVERAGE_TIME + 0.5) / delta_t); num_frametimes = MAX(4, num_frametimes); frametimes = xrealloc( frametimes, num_frametimes * sizeof(double) ); for (i = 0; i < num_frametimes; i++) frametimes[i] = delta_t; sum_frametimes = (double)num_frametimes * delta_t; frame_num = 0; } /* Calculate framerate */ sum_frametimes -= frametimes[frame_num]; frametimes[frame_num] = delta_t; sum_frametimes += delta_t; framerate = (double)num_frametimes / sum_frametimes; /* Adjust frametime buffer length (if necessary) */ while (sum_frametimes > (FRAMERATE_AVERAGE_TIME + 1.0)) { if (num_frametimes <= 4) break; /* Shrink frametime buffer (animation is slowing down) */ delta_t = sum_frametimes / (double)num_frametimes; --num_frametimes; frametimes = xrealloc( frametimes, num_frametimes * sizeof(double) ); for (i = 0; i < num_frametimes; i++) frametimes[i] = delta_t; sum_frametimes = (double)num_frametimes * delta_t; } while (sum_frametimes < FRAMERATE_AVERAGE_TIME) { /* Expand frametime buffer (animation is speeding up) */ delta_t = sum_frametimes / (double)num_frametimes; ++num_frametimes; frametimes = xrealloc( frametimes, num_frametimes * sizeof(double) ); for (i = 0; i < num_frametimes; i++) frametimes[i] = delta_t; sum_frametimes = (double)num_frametimes * delta_t; } frame_num = (frame_num + 1) % num_frametimes; break; case PROFILE_FRAMERATE_RESET: /* (Re)initialize frametime buffer on next completed frame */ frame_num = -1; break; case PROFILE_WARP_BEGIN: warp_t0 = cur_t; break; case PROFILE_WARP_DONE: delta_t = cur_t - warp_t0; warp_total_t += delta_t; break; case PROFILE_OGLDRAW_BEGIN: ogldraw_t0 = cur_t; break; case PROFILE_OGLDRAW_DONE: delta_t = cur_t - ogldraw_t0; ogldraw_total_t += delta_t; break; case PROFILE_SHOW_STATS: printf( "==== Light Speed! profiler stats ====\n" ); delta_t = cur_t - main_t0; printf( "Idle time..: %.3f sec\n", delta_t - active_total_t ); printf( "Active time: %.3f sec (100%%)\n", active_total_t ); p = 100.0 * warp_total_t / active_total_t; printf( "Warp engine: %.3f sec (%.2f%%)\n", warp_total_t, p ); p = 100.0 * ogldraw_total_t / active_total_t; printf( "OpenGL draw: %.3f sec (%.2f%%)\n", ogldraw_total_t, p ); printf( "Framerate..: %.3f fps\n", framerate ); printf( "=====================================\n" ); fflush( stdout ); break; default: #ifdef DEBUG crash( "profile( ): invalid message" ); #endif return; } } /* Convenience function to initiate a variable transition */ void transition( void *var, int is_double, int trans_type, double duration, double final, int cam_id ) { trans_var *tvar; double t; t = read_system_clock( ); tvar = xmalloc( sizeof(trans_var) ); tvar->var = var; tvar->is_double = is_double; tvar->looping = FALSE; tvar->type = trans_type; tvar->start_t = t; tvar->end_t = t + duration; tvar->cam_id = cam_id; if (is_double) tvar->initial = *((double *)var); else tvar->initial = *((float *)var); tvar->final = final; transition_engine( tvar ); } /* Same as earlier, only this starts a looping variable transition * (i.e. continuous, run-until-you-tell-it-to-stop animation) */ void animate( void *var, int is_double, int trans_type, double duration, double initial, double final, int cam_id ) { trans_var *tvar; double t, val; t = read_system_clock( ); tvar = xmalloc( sizeof(trans_var) ); tvar->var = var; tvar->is_double = is_double; tvar->looping = TRUE; tvar->type = trans_type; /* Define starting time so animation debuts at current value (*var) */ if (is_double) val = *((double *)var); else val = *((float *)var); tvar->start_t = t - duration * (val - initial) / (final - initial); tvar->end_t = tvar->start_t + duration; tvar->cam_id = cam_id; tvar->initial = initial; tvar->final = final; transition_engine( tvar ); } /* Stops an ongoing transition/animation * (does nothing if the specified variable isn't being transitioned) */ void break_transition( void *var ) { trans_var stop_tvar; stop_tvar.var = var; stop_tvar.type = TRANS_STOP; transition_engine( &stop_tvar ); } /* This function is what makes dynamic variable transitioning happen! * Return status indicates whether any state change occurred or not */ static int transition_engine( trans_var *new_tvar ) { static trans_var *trans_queue = NULL; trans_var *prev_tvar; trans_var *u; trans_var *next_tvar; double cur_t; double delta_t; double val; double percent; int redraw_all = FALSE; int i; if (new_tvar != NULL) { /* New transition variable is entering the queue */ /* Check to see if it's already in there */ prev_tvar = NULL; u = trans_queue; while (u != NULL) { if (new_tvar->var == u->var) { /* Whoa! This variable is already in transition * Change existing transition record */ if (new_tvar->type == TRANS_STOP) { /* Remove variable from queue */ next_tvar = u->next; if (prev_tvar == NULL) /* i.e. u is 1st in queue */ trans_queue = next_tvar; else prev_tvar->next = next_tvar; break; } /* Alter the existing transition */ u->type = new_tvar->type; u->start_t = new_tvar->start_t; u->end_t = new_tvar->end_t; if (u->is_double) u->initial = *((double *)u->var); else u->initial = *((float *)u->var); u->final = new_tvar->final; u->looping = new_tvar->looping; xfree( new_tvar ); /* Won't need this again */ break; } prev_tvar = u; u = u->next; /* cdr down the list */ } /* (u is NULL if no match occurred) */ if ((u == NULL) && (new_tvar->type != TRANS_STOP)) { /* All clear, add new_tvar to head of transition queue */ new_tvar->next = trans_queue; /* and fire up the idle loop if it's the first one */ if (trans_queue == NULL) update( ACTIVATE ); trans_queue = new_tvar; } /* Done for now, don't do actual state change in this iteration */ return FALSE; } /* Double-check that the inbox isn't empty */ if (trans_queue == NULL) return FALSE; cur_t = read_system_clock( ); /* Perform incremental update of all variables in the queue */ prev_tvar = NULL; u = trans_queue; while (u != NULL) { /* First, set camera update flag(s) as appropriate * (don't use queue_redraw( ) here! bad!) */ if (u->cam_id >= 0) usr_cams[u->cam_id]->redraw = TRUE; else redraw_all = TRUE; /* affects all views */ if (cur_t >= u->end_t) { if (u->looping) { /* start over */ delta_t = u->end_t - u->start_t; u->start_t += delta_t; u->end_t += delta_t; } else { /* Transition complete, remove tvar from queue */ if (u->is_double) *((double *)u->var) = u->final; else *((float *)u->var) = u->final; next_tvar = u->next; if (prev_tvar == NULL) /* i.e. u is 1st in queue */ trans_queue = next_tvar; else prev_tvar->next = next_tvar; xfree( u ); u = next_tvar; continue; } } /* Update variable value as per appropriate transition function */ percent = ((cur_t - u->start_t) / (u->end_t - u->start_t)); switch( u->type ) { case TRANS_LINEAR: /* No remapping */ break; case TRANS_QTR_SIN: /* 1/4 sine: starts fast, finishes slow */ percent = sin( PI * percent / 2 ); break; case TRANS_RAMP: /* Ramp: starts slow, finishes fast */ percent = 1 - cos( PI * percent / 2 ); break; case TRANS_SIGMOID: /* Sigmoidal (S-like) remapping */ percent = (1 - cos( PI * percent )) / 2; break; default: #ifdef DEBUG crash( "transition_engine( ): invalid transition type" ); #endif break; } val = u->initial + percent * (u->final - u->initial); if (u->is_double) *((double *)u->var) = val; else *((float *)u->var) = val; prev_tvar = u; u = u->next; } /* Don't use queue_redraw( ) here either */ if (redraw_all) { for (i = 0; i < num_cams; i++) usr_cams[i]->redraw = TRUE; } return TRUE; } /* Thoughts: The above system could be extended to allow chained transitions * (i.e. when a transition ends, another is automatically started). This * can be implemented by adding a "trans_var *chain_queue" field to the * trans_var structure, and amending the code that terminates transitions. * This would also allow for a somewhat clever way of specifying looping * animations-- have chain_queue point to the very structure it is in }:) */ /* end animation.c */ lightspeed-1.2a.debian.1/src/auxobjects.c000066400000000000000000000257641334064775200203600ustar00rootroot00000000000000/* auxobjects.c */ /* Auxiliary objects / reference geometry drawing routines */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Forward declarations */ static void draw_coord_axes( float percent, point *cam_pos ); static void draw_floating_grid( float percent ); static void draw_floating_grid_AUX( float unit_size, int i_min, int i_max, int j_min, int j_max, float vis, float side ); static void draw_bounding_box( float percent ); /* Auxiliary objects control */ void auxiliary_objects( int message1, int message2 ) { static float percent_axes = 0.0; static float percent_grid = 1.0; static float percent_bbox = 0.0; static int axes_active = FALSE; static int grid_active = TRUE; static int bbox_active = FALSE; camera *cam; switch (message1) { case AUXOBJS_DRAW: cam = usr_cams[message2]; break; case AUXOBJS_SET_AXES: axes_active = message2; if (axes_active) transition( &percent_axes, FALSE, TRANS_RAMP, 2, 1.0, -1 ); else transition( &percent_axes, FALSE, TRANS_QTR_SIN, 1, 0.0, -1 ); return; case AUXOBJS_SET_BBOX: bbox_active = message2; if (bbox_active) transition( &percent_bbox, FALSE, TRANS_RAMP, 2, 1.0, -1 ); else transition( &percent_bbox, FALSE, TRANS_QTR_SIN, 1, 0.0, -1 ); return; case AUXOBJS_SET_GRID: grid_active = message2; if (grid_active) transition( &percent_grid, FALSE, TRANS_QTR_SIN, 2, 1.0, -1 ); else { percent_grid = -1.0; transition( &percent_grid, FALSE, TRANS_RAMP, 1, 0.0, -1 ); } return; default: #ifdef DEBUG crash( "aux_objects( ): invalid message" ); #endif return; } glDisable( GL_LIGHTING ); if (percent_axes != 0.0) draw_coord_axes( percent_axes, &cam->pos ); if (percent_bbox != 0.0) draw_bounding_box( percent_bbox ); if (percent_grid != 0.0) draw_floating_grid( percent_grid ); glEnable( GL_LIGHTING ); } static void draw_coord_axes( float percent, point *cam_pos ) { float space, scale; float x_dist; float neg_x0, neg_y0, neg_z0; float neg_x1, neg_y1, neg_z1; float pos_x0, pos_y0, pos_z0; float pos_x1, pos_y1, pos_z1; float rot_x, rot_y, rot_z; float arrow1, arrow2; float label1, label2; float label2_x; /* These will be used to draw the axis arrowheads */ arrow1 = vehicle_extents.avg * percent / 8; arrow2 = arrow1 * SQR(MAGIC_NUMBER); /* These will be used to draw the X, Y and Z labels */ label1 = vehicle_extents.avg * percent / 8; label2 = label1 * MAGIC_NUMBER; if (percent > 0.01) space = vehicle_extents.avg / 4 / SQR(percent); else space = vehicle_extents.avg * 1000; scale = 1.0 + SQR(percent); x_dist = vehicle_extents.xmax + space; pos_x0 = x_dist; pos_x1 = x_dist * scale; x_dist = vehicle_extents.xmin - space; neg_x0 = x_dist; neg_x1 = x_dist * scale - arrow2 / 2.0; pos_y0 = vehicle_extents.ymax + space; pos_y1 = pos_y0 * scale; neg_y0 = vehicle_extents.ymin - space; neg_y1 = MIN(neg_y0 * scale, - pos_y1) - arrow2 / 2.0; pos_z0 = vehicle_extents.zmax + space; pos_z1 = pos_z0 * scale; neg_z0 = vehicle_extents.zmin - space; neg_z1 = MIN(neg_z0 * scale, - pos_z1) - arrow2 / 2.0; /* These will keep the arrowheads and labels facing the camera */ rot_x = DEG(atan2( cam_pos->z, cam_pos->y )); rot_y = DEG(atan2( cam_pos->z, cam_pos->x )); rot_z = DEG(atan2( cam_pos->y, cam_pos->x )); /* label2_x is used to flip the Y if x-pos. of camera is negative */ if (cam_pos->x < 0.0) label2_x = - label2; else label2_x = label2; /* Draw the terminating dots */ glPointSize( 8 ); glBegin( GL_POINTS ); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( neg_x0, 0, 0 ); glVertex3f( pos_x0, 0, 0 ); glColor3f( 1.0, 1.0, 0.0 ); glVertex3f( 0, neg_y0, 0 ); glVertex3f( 0, pos_y0, 0 ); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0, 0, neg_z0 ); glVertex3f( 0, 0, pos_z0 ); glEnd( ); /* Draw the axes */ glLineWidth( 5 ); glBegin( GL_LINES ); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( neg_x0, 0, 0 ); glVertex3f( neg_x1, 0, 0 ); glVertex3f( pos_x0, 0, 0 ); glVertex3f( pos_x1, 0, 0 ); glColor3f( 1.0, 1.0, 0.0 ); glVertex3f( 0, neg_y0, 0 ); glVertex3f( 0, neg_y1, 0 ); glVertex3f( 0, pos_y0, 0 ); glVertex3f( 0, pos_y1, 0 ); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0, 0, neg_z0 ); glVertex3f( 0, 0, neg_z1 ); glVertex3f( 0, 0, pos_z0 ); glVertex3f( 0, 0, pos_z1 ); glEnd( ); glPushMatrix( ); glRotatef( rot_x, 1.0, 0.0, 0.0 ); /* Draw the x-axis arrowhead */ glBegin( GL_TRIANGLE_FAN ); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( pos_x1, 0, 0 ); glVertex3f( pos_x1 - arrow1, 0, arrow1 / 2 ); glVertex3f( pos_x1 + arrow2, 0, 0 ); /* tip */ glVertex3f( pos_x1 - arrow1, 0, - arrow1 / 2 ); glEnd( ); /* Draw the X */ glBegin( GL_LINES ); glColor3f( 1.0, 0.0, 0.0 ); glVertex3f( neg_x1 - label2 - label1, 0, label2 ); /* top left */ glVertex3f( neg_x1 - label2 + label1, 0, - label2 ); /* bottom right */ glVertex3f( neg_x1 - label2 - label1, 0, - label2 ); /* bottom left */ glVertex3f( neg_x1 - label2 + label1, 0, label2 ); /* top right */ glEnd( ); glPopMatrix( ); glPushMatrix( ); glRotatef( rot_y, 0.0, -1.0, 0.0 ); /* Draw the y-axis arrowhead */ glBegin( GL_TRIANGLE_FAN ); glColor3f( 1.0, 1.0, 0.0 ); glVertex3f( 0, pos_y1, 0 ); glVertex3f( 0, pos_y1 - arrow1, - arrow1 / 2 ); glVertex3f( 0, pos_y1 + arrow2, 0 ); /* tip */ glVertex3f( 0, pos_y1 - arrow1, arrow1 / 2 ); glEnd( ); /* Draw the Y */ glBegin( GL_LINES ); glColor3f( 1.0, 1.0, 0.0 ); glVertex3f( 0, neg_y1 - label2 - label1, label2_x ); /* top left */ glVertex3f( 0, neg_y1 - label2, 0 ); /* middle */ glVertex3f( 0, neg_y1 - label2 + label1, label2_x ); /* top right */ glVertex3f( 0, neg_y1 - label2, 0 ); /* middle */ glVertex3f( 0, neg_y1 - label2, 0 ); /* middle */ glVertex3f( 0, neg_y1 - label2, - label2_x ); /* bottom */ glEnd( ); glPopMatrix( ); glPushMatrix( ); glRotatef( rot_z, 0.0, 0.0, 1.0 ); /* Draw the z-axis arrowhead */ glBegin( GL_TRIANGLE_FAN ); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0, 0, pos_z1 ); glVertex3f( 0, arrow1 / 2, pos_z1 - arrow1 ); glVertex3f( 0, 0, pos_z1 + arrow2 ); /* tip */ glVertex3f( 0, - arrow1 / 2, pos_z1 - arrow1 ); glEnd( ); /* Draw the Z */ glBegin( GL_LINE_STRIP ); glColor3f( 0.0, 0.0, 1.0 ); glVertex3f( 0, - label1, neg_z1 - label2 ); /* top left */ glVertex3f( 0, label1, neg_z1 - label2 ); glVertex3f( 0, - label1, neg_z1 - 3 * label2 ); glVertex3f( 0, label1, neg_z1 - 3 * label2 ); /* bottom right */ glEnd( ); glPopMatrix( ); } static void draw_floating_grid( float percent ) { float angle; float vis; float unit_size; float x_length, y_length; float y_dist; int i_min, j_min; int i_max, j_max; /* Deployment rotation */ angle = 180.0 * (percent - 1.0); /* Deployment visibility */ if (percent > 0.0) vis = percent; else vis = sqrt( - percent ); /* Determine unit_size suited to vehicle dimensions */ unit_size = pow( 10, floor( log10( vehicle_extents.avg ) ) ); /* and grid extents */ x_length = vehicle_extents.xmax - vehicle_extents.xmin; y_length = vehicle_extents.ymax - vehicle_extents.ymin; y_dist = MAX(vehicle_extents.ymax, - vehicle_extents.ymin); y_dist += y_length / 4; i_max = (int)(ceil( 4 * x_length / unit_size )) / 2; i_min = - i_max; j_max = (int)(ceil( 4 * y_dist / unit_size )); j_min = (int)(ceil( y_dist / unit_size )); glPushMatrix( ); glRotatef( angle, 0.0, 1.0, 0.0 ); glEnable( GL_BLEND ); /* for fadein/fadeout */ draw_floating_grid_AUX( unit_size, i_min, i_max, j_min, j_max, vis, 1.0 ); glPopMatrix( ); glPushMatrix( ); glRotatef( - angle, 0.0, 1.0, 0.0 ); draw_floating_grid_AUX( unit_size, i_min, i_max, j_min, j_max, vis, -1.0 ); glDisable( GL_BLEND ); glPopMatrix( ); } /* ThisIsAHelperFunction */ static void draw_floating_grid_AUX( float unit_size, int i_min, int i_max, int j_min, int j_max, float vis, float side ) { float x0, y0; float x1, y1; float x, y; int i, j; x0 = unit_size * (float)i_min; x1 = unit_size * (float)i_max; y0 = unit_size * (float)j_min; y1 = unit_size * (float)j_max; glLineWidth( 1 ); glBegin( GL_LINES ); glColor4f( 0.5, 0.5, 0.5, vis ); /* x grid lines */ for (j = j_min; j < j_max; j++) { y = unit_size * (float)j; glVertex3f( x0, side * y, 0 ); glVertex3f( x1, side * y, 0 ); } /* y grid lines */ for (i = i_min + 1; i < i_max; i++) { x = unit_size * (float)i; glVertex3f( x, side * y0, 0 ); glVertex3f( x, side * y1, 0 ); } glEnd( ); glLineWidth( 3 ); /* Outer boundaries */ glBegin( GL_LINE_STRIP ); glColor4f( 0.75, 0.75, 0.75, vis ); glVertex3f( x0, side * y0, 0 ); glVertex3f( x0, side * y1, 0 ); glVertex3f( x1, side * y1, 0 ); glVertex3f( x1, side * y0, 0 ); glEnd( ); /* Floating grid determines world extents */ world_extents.xmin = x0; world_extents.xmax = x1; } static void draw_bounding_box( float percent ) { static int b[] = { 1, -1, -1, 2 }; /* Elements 0 and 3 are important */ extents *exts; float bar_percent; float gamma; float xbar, ybar, zbar; /* Length of x, y, z bars */ float bb_x[4], bb_y[4], bb_z[4]; /* x, y, z coords. of box/bars */ int i, j, k; if (percent < 0.01) return; bar_percent = (0.25 / MAGIC_NUMBER) * percent; gamma = lorentz_factor( velocity ); exts = &vehicle_extents; /* abbreviation */ xbar = (exts->xmax - exts->xmin) * bar_percent; bb_x[0] = (exts->xmin / gamma + vehicle_real_x) / percent; bb_x[1] = ((exts->xmin + xbar) / gamma + vehicle_real_x) / percent; bb_x[2] = ((exts->xmax - xbar) / gamma + vehicle_real_x) / percent; bb_x[3] = (exts->xmax / gamma + vehicle_real_x) / percent; ybar = (exts->ymax - exts->ymin) * bar_percent; bb_y[0] = exts->ymin / percent; bb_y[1] = (exts->ymin + ybar) / percent; bb_y[2] = (exts->ymax - ybar) / percent; bb_y[3] = exts->ymax / percent; zbar = (exts->zmax - exts->zmin) * bar_percent; bb_z[0] = exts->zmin / percent; bb_z[1] = (exts->zmin + zbar) / percent; bb_z[2] = (exts->zmax - zbar) / percent; bb_z[3] = exts->zmax / percent; glLineWidth( 5 ); glBegin( GL_LINES ); glColor3f( 1.0, 1.0, 1.0 ); for (i = 0; i <= 3; i += 3) { for (j = 0; j <= 3; j += 3) { for (k = 0; k <= 3; k += 3) { glVertex3f( bb_x[i], bb_y[j], bb_z[k] ); glVertex3f( bb_x[b[i]], bb_y[j], bb_z[k] ); glVertex3f( bb_x[i], bb_y[j], bb_z[k] ); glVertex3f( bb_x[i], bb_y[b[j]], bb_z[k] ); glVertex3f( bb_x[i], bb_y[j], bb_z[k] ); glVertex3f( bb_x[i], bb_y[j], bb_z[b[k]] ); } } } glEnd( ); } /* end auxobjects.c */ lightspeed-1.2a.debian.1/src/camera.c000066400000000000000000000230211334064775200174210ustar00rootroot00000000000000/* camera.c */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" camera * new_camera( void ) { int new_cam_id; new_cam_id = num_cams; ++num_cams; usr_cams = xrealloc( usr_cams, num_cams * sizeof(camera *) ); usr_cams[new_cam_id] = xmalloc( sizeof(camera) ); cur_cam = new_cam_id; if (new_cam_id > 0) { /* Initialize camera with primary's state */ memcpy( usr_cams[new_cam_id], usr_cams[0], sizeof(camera) ); } else { /* This IS the primary */ camera_reset( 0 ); } /* Widget pointers will be assigned elsewhere * (in main_window( ) for primary, in menu_Camera_Spawn( ) for others) */ usr_cams[new_cam_id]->window_w = NULL; usr_cams[new_cam_id]->ogl_w = NULL; return usr_cams[new_cam_id]; } /* Gets rid of a camera, along with accompanying window and GL widgets */ void kill_camera( int cam_id ) { gtk_widget_destroy( usr_cams[cam_id]->ogl_w ); gtk_widget_destroy( usr_cams[cam_id]->window_w ); xfree( usr_cams[cam_id] ); --num_cams; if (cam_id != num_cams) /* Not last camera? */ memmove( &usr_cams[cam_id], &usr_cams[cam_id + 1], (num_cams - cam_id) * sizeof(camera *) ); usr_cams = xrealloc( usr_cams, num_cams * sizeof(camera *) ); cur_cam = 0; #ifdef DEBUG printf( "Killed camera %d\n", cam_id ); #endif } /* Initialize camera with default initial settings */ void camera_reset( int cam_id ) { camera *cam; cam = usr_cams[cam_id]; /* Convert user phi/theta to struct camera phi/theta values */ cam->phi = fmod( DEF_CAMERA_PHI + 180.0, 360.0) ; cam->theta = - DEF_CAMERA_THETA; cam->distance = 3 * vehicle_extents.avg; cam->target.x = 0; cam->target.y = 0; cam->target.z = 0; cam->fov = DEF_CAMERA_FOV; cam->near_clip = vehicle_extents.avg / 20; cam->far_clip = vehicle_extents.avg * 50; camera_calc_xyz( CAM_POSITION, cam ); /* Update Camera Position dialog if it is active */ dialog_Camera_Position( NULL, MESG_(RESET) ); queue_redraw( cam_id ); } /* This function returns the ID number of the camera associated * with the specified window or GL widget */ int assoc_cam_id( void *widget ) { camera *cam; int i; for (i = 0; i < num_cams; i++) { cam = usr_cams[i]; if ((widget == cam->window_w) || (widget == cam->ogl_w)) return i; } return -1; /* No camera associated with this widget */ } /* Focusing a window updates cur_cam */ int camera_set_current( GtkWidget *widget, GdkEventFocus *ev_focus, void *nothing ) { if (num_cams > 1) { cur_cam = assoc_cam_id( widget ); #ifdef DEBUG printf( "Current camera: %d\n", cur_cam ); fflush( stdout ); #endif } return FALSE; } /* Obtain a field of view (in degrees) from a lens length (in mm) */ float camera_calc_fov( float lens_length ) { return DEG(2 * atan( 21.6663 / (float)lens_length )); } /* Obtain a lens length (in mm) from a field of view (in degrees) */ float camera_calc_lens_length( float fov ) { return 21.6663 / tan( RAD(fov) / 2 ); } /* Calculates a camera's XYZ position or target, given that the other point * (target or position) and phi + theta + distance are defined */ void camera_calc_xyz( int point_type, camera *cam ) { float sin_phi, cos_phi, sin_theta, cos_theta; float dx, dy, dz; sin_phi = sin( RAD(cam->phi) ); cos_phi = cos( RAD(cam->phi) ); sin_theta = sin( RAD(cam->theta) ); cos_theta = cos( RAD(cam->theta) ); dx = cam->distance * cos_theta * cos_phi; dy = cam->distance * cos_theta * sin_phi; dz = cam->distance * sin_theta; switch (point_type) { case CAM_POSITION: cam->pos.x = cam->target.x + dx; cam->pos.y = cam->target.y + dy; cam->pos.z = cam->target.z + dz; break; case CAM_TARGET: cam->target.x = cam->pos.x - dx; cam->target.y = cam->pos.y - dy; cam->target.z = cam->pos.z - dz; break; default: #ifdef DEBUG crash( "camera_calc_xyz( ): invalid type" ); #endif return; } } /* Calculate a target/distance for a camera which only has a location and a * phi/theta direction. The target point should be chosen such that it lies on * the camera's view ray, and is as close to the origin as possible */ void camera_make_target( camera *cam ) { float sin_phi, sin_theta; float cos_phi, cos_theta; float ux, uy, uz; float dist; sin_phi = sin( RAD(cam->phi) ); cos_phi = cos( RAD(cam->phi) ); sin_theta = sin( RAD(cam->theta) ); cos_theta = cos( RAD(cam->theta) ); /* Calculate unit vector in direction of camera view */ ux = cos_phi * cos_theta; uy = sin_phi * cos_theta; uz = sin_theta; /* Calculate distance to point on ray nearest the origin */ dist = cam->pos.x * ux + cam->pos.y * uy + cam->pos.z * uz; /* If dist is negative, desired target is behind camera -- doh! */ cam->distance = MAX(dist, vehicle_extents.avg / 8.0); camera_calc_xyz( CAM_TARGET, cam ); } /* Read mouse input and move camera around accordingly */ /* Will be connected to mouse button & motion events */ int camera_move( GtkWidget *widget, GdkEventAny *event, void *nothing ) { static camera *cam; static float mouse_prev_x; static float mouse_prev_y; static int cam_id; static int over_foreign = FALSE; GdkEventButton *ev_button; GdkEventMotion *ev_motion; float mouse_x, mouse_y; float mouse_dx, mouse_dy; float sin_phi, cos_phi, sin_theta, cos_theta; float k; int mouse_btn1 = FALSE, mouse_btn2 = FALSE, mouse_btn3 = FALSE; int shift_key = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: cam_id = assoc_cam_id( widget ); cam = usr_cams[cam_id]; cur_cam = cam_id; ev_button = (GdkEventButton *)event; /* Note click coordinates (for dragging) */ mouse_prev_x = ev_button->x; mouse_prev_y = ev_button->y; /* Change cursor appropriately */ if (ev_button->button == 1) { if (ev_button->state & GDK_SHIFT_MASK) set_cursor_glyph( GDK_CIRCLE ); else set_cursor_glyph( GDK_FLEUR ); } if (ev_button->button == 2) set_cursor_glyph( GDK_FLEUR ); if (ev_button->button == 3) set_cursor_glyph( GDK_DOUBLE_ARROW ); /* Finally, clear out any stale text in velocity entry */ velocity_input( NULL, MESG_(RESET) ); return FALSE; /* Double-click -- where are these events coming from? */ case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: return FALSE; case GDK_BUTTON_RELEASE: set_cursor_glyph( GDK_LEFT_PTR ); over_foreign = FALSE; return FALSE; case GDK_MOTION_NOTIFY: ev_motion = (GdkEventMotion *)event; mouse_x = ev_motion->x; mouse_y = ev_motion->y; if ((cam_id != assoc_cam_id( widget )) != over_foreign) { /* Fix for when pointer is dragged over another GL widget * (x/y coords. jump to something else completely) */ mouse_prev_x = mouse_x; mouse_prev_y = mouse_y; over_foreign = !over_foreign; } mouse_dx = mouse_sens * ( mouse_x - mouse_prev_x ); mouse_dy = mouse_sens * ( mouse_y - mouse_prev_y ); mouse_prev_x = mouse_x; mouse_prev_y = mouse_y; /* Get status of Shift key and buttons */ shift_key = ev_motion->state & GDK_SHIFT_MASK; mouse_btn1 = ev_motion->state & GDK_BUTTON1_MASK; mouse_btn2 = ev_motion->state & GDK_BUTTON2_MASK; mouse_btn3 = ev_motion->state & GDK_BUTTON3_MASK; break; default: #ifdef DEBUG crash( "camera_move( ): invalid message" ); #endif return FALSE; } /* Make sure cam->pos is not stale (for Shift + LeftClick) */ camera_calc_xyz( CAM_POSITION, cam ); /* Button 1: Revolve view around target or camera (Shift for latter) */ if (mouse_btn1) { /* phi = heading, theta = elevation */ cam->phi -= mouse_dx; cam->theta += mouse_dy; /* Keep angles within proper bounds */ if (cam->phi < 0.0) cam->phi += 360.0; if (cam->phi > 360.0) cam->phi -= 360.0; if (cam->theta < -90.0) cam->theta = -90.0; if (cam->theta > 90.0) cam->theta = 90.0; } /* If Shift was pressed, need to update camera target */ if (shift_key) camera_calc_xyz( CAM_TARGET, cam ); sin_phi = sin( RAD(cam->phi) ); cos_phi = cos( RAD(cam->phi) ); sin_theta = sin( RAD(cam->theta) ); cos_theta = cos( RAD(cam->theta) ); /* Button 2: Dolly camera (up/down/left/right) */ if (mouse_btn2) { k = cam->distance / 128; /* Isn't trig fun? */ cam->target.x += k * ( mouse_dx * sin_phi - mouse_dy * sin_theta * cos_phi ); cam->target.y -= k * ( mouse_dx * cos_phi + mouse_dy * sin_theta * sin_phi ); cam->target.z += k * mouse_dy * cos_theta; } /* Button 3: Dolly camera (forward/backward) */ if (mouse_btn3) { cam->distance -= (mouse_dy * vehicle_extents.avg / 48); cam->distance = MAX(cam->distance, vehicle_extents.avg / 8.0); } /* Now recalculate camera's xyz-position */ camera_calc_xyz( CAM_POSITION, cam ); /* Real quick, update Camera Position dialog if it is active */ dialog_Camera_Position( NULL, MESG_(RESET) ); /* Finally, ask for a redraw. NOTE: primary camera motion causes all * cameras to be redrawn, as time t can vary with its position */ if (cam_id != 0) queue_redraw( cam_id ); else queue_redraw( -1 ); return FALSE; } /* end camera.c */ lightspeed-1.2a.debian.1/src/command.c000066400000000000000000000047351334064775200176220ustar00rootroot00000000000000/* command.c */ /* Type-in command handlers */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" int command( const char *input ) { static char *cmd_strs[] = { "ZROT_CCW", "ZROT_CW", "PERFSTATS", "GEOMSTATS", "MEMSTATS", "MEMBLOCKS", "DGAMMA=", "STRAKER", "SKUNK" }; const int num_cmd_strs = sizeof(cmd_strs) / sizeof(char *); const char *arg = NULL; float f; int cmd; int i; for (cmd = 0; cmd < num_cmd_strs; cmd++) { i = strlen( cmd_strs[cmd] ); if (!strncasecmp( input, cmd_strs[cmd], i )) { arg = &input[strlen( cmd_strs[cmd] )]; break; } } switch (cmd) { case 0: /* ZROT_CCW */ rotate_all_objects( Z_ROTATE_CCW ); return 0; case 1: /* ZROT_CW */ rotate_all_objects( Z_ROTATE_CW ); return 0; case 2: /* PERFSTATS */ profile( PROFILE_SHOW_STATS ); return 0; case 3: /* GEOMSTATS */ show_geometry_stats( ); return 0; case 4: /* MEMSTATS */ #ifdef WITH_TRACKMEM trackmem_show_stats( ); return 0; #else /* TRACKMEM was not compiled in */ return -1; #endif case 5: /* MEMBLOCKS */ #ifdef WITH_TRACKMEM trackmem_show_blocks( ); return 0; #else /* TRACKMEM was not compiled in */ return -1; #endif case 6: /* DGAMMA= */ /* Adjust display gamma correction */ if (!strcasecmp( arg, "OFF" )) { dgamma_correct = FALSE; queue_redraw( -1 ); return 0; } f = strtod( arg, NULL ); if ((f < 0.1) || (f > 8.0)) return -1; if (f == 1.0) dgamma_correct = FALSE; else { dgamma_correct = TRUE; calc_dgamma_lut( f ); } queue_redraw( -1 ); return 0; case 7: /* STRAKER */ case 8: /* SKUNK */ ss( ); /* // */ return 0; default: return -1; } } /* end command.c */ lightspeed-1.2a.debian.1/src/compat.h000066400000000000000000000030001334064775200174540ustar00rootroot00000000000000/* compat.h */ /* Compatibility hack for GTK+/glib/GtkGLArea 1.0 */ /* I'll spare you the boilerplate just this once :-) */ #ifdef HAVE_GTK1 #ifndef GTK_HAVE_FEATURES_1_1_0 /* ---- GTK+ 1.1 name ---- ---- GTK+ 1.0 name ---- */ #define gtk_container_set_border_width gtk_container_border_width #define gtk_window_set_position gtk_window_position #define gtk_toggle_button_set_active gtk_toggle_button_set_state #define gtk_check_menu_item_set_active gtk_check_menu_item_set_state #define gtk_label_set_text gtk_label_set /* GtkGLArea prior to 1.? uses a slightly different API */ #define GTKGL_TEMP_beginGL(A) gtk_gl_area_begingl(GTK_GL_AREA(A)) #define GTKGL_TEMP_endgl(A) gtk_gl_area_endgl(GTK_GL_AREA(A)) /* Neutralize accelerator code in keybind( ) */ #define GtkAccelGroup int #define gtk_accel_group_new NOP #define gtk_accel_group_attach(a,b) NOP( ) #define gtk_widget_add_accelerator(a,b,c,d,e,f) NOP( ) #else /* not GTK_HAVE_FEATURES_1_1_0 */ #define GTKGL_TEMP_begingl(A) gtk_gl_area_make_current(GTK_GL_AREA(A)) #define GTKGL_TEMP_endgl(A) NOP( ) #endif /* not GTK_HAVE_FEATURES_1_1_0 */ #else /* not HAVE_GTK1 */ #define GTKGL_TEMP_begingl(A) {GdkGLContext *glcontext = gtk_widget_get_gl_context (A); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(A);if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)){ g_critical("cannot gl_begin"); } } #define GTKGL_TEMP_endgl(A) { GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(A);gdk_gl_drawable_gl_end (gldrawable);} #endif /* end compat.h */ lightspeed-1.2a.debian.1/src/geometry.c000066400000000000000000000413411334064775200200310ustar00rootroot00000000000000/* geometry.c */ /* Various geometrical and geometry-related routines */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Allocates an ogl_object */ ogl_object * alloc_ogl_object( int num_vertices, int num_indices ) { ogl_object *new_obj; int i; new_obj = xmalloc( sizeof(ogl_object) ); new_obj->num_vertices = num_vertices; new_obj->vertices0 = xmalloc( num_vertices * sizeof(point) ); new_obj->normals0 = xmalloc( num_vertices * sizeof(point) ); new_obj->iarrays = xmalloc( num_vertices * sizeof(ogl_point) ); /* Initialize "a" fields in iarrays, since we don't really use them */ for (i = 0; i < num_vertices; i++) new_obj->iarrays[i].a = 1.0; new_obj->num_indices = num_indices; new_obj->indices = xmalloc( num_indices * sizeof(unsigned int) ); new_obj->pre_dlist = 0; /* null display list */ new_obj->post_dlist = 0; /* ditto */ return new_obj; } /* Returns the size in memory (bytes) used by an ogl_object having * so many vertices and so many indices */ int calc_ogl_object_memusage( int num_vertices, int num_indices ) { int num_bytes; /* The vertices0 and normals0 arrays */ num_bytes = 2 * num_vertices * sizeof(point); /* The C4F+N3F+V3F superarray */ num_bytes += num_vertices * sizeof(ogl_point); /* The indices array */ num_bytes += num_indices * sizeof(unsigned int); /* The ogl_object structure itself */ num_bytes += sizeof(ogl_object); return num_bytes; } /* Deallocates an ogl_object */ void free_ogl_object( ogl_object *obj ) { xfree( obj->vertices0 ); xfree( obj->normals0 ); xfree( obj->iarrays ); xfree( obj->indices ); if (obj->pre_dlist != 0) glDeleteLists( obj->pre_dlist, 1 ); if (obj->post_dlist != 0) glDeleteLists( obj->post_dlist, 1 ); xfree( obj ); } /* Gets rid of all current objects */ void clear_all_objects( void ) { int i; for (i = 0; i < num_vehicle_objs; i++) free_ogl_object( vehicle_objs[i] ); xfree( vehicle_objs ); num_vehicle_objs = 0; } void rotate_all_objects( int direction ) { ogl_object *obj; float x0,y0,z0; float x,y,z; float xmax = -1E6, ymax = -1E6, zmax = -1E6; float xmin = 1E6, ymin = 1E6, zmin = 1E6; int o, v; for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; for (v = 0; v < obj->num_vertices; v++) { /* Rotate vertex */ x0 = obj->vertices0[v].x; y0 = obj->vertices0[v].y; z0 = obj->vertices0[v].z; rotate_xyz( direction, &x, &y, &z, x0, y0, z0 ); obj->vertices0[v].x = x; obj->vertices0[v].y = y; obj->vertices0[v].z = z; /* Update vehicle extents */ xmin = MIN(x, xmin); xmax = MAX(x, xmax); ymin = MIN(y, ymin); ymax = MAX(y, ymax); zmin = MIN(z, zmin); zmax = MAX(z, zmax); /* Rotate normal too */ x0 = obj->normals0[v].x; y0 = obj->normals0[v].y; z0 = obj->normals0[v].z; rotate_xyz( direction, &x, &y, &z, x0, y0, z0 ); obj->normals0[v].x = x; obj->normals0[v].y = y; obj->normals0[v].z = z; } } /* Reset vehicle_extents */ vehicle_extents.xmin = xmin; vehicle_extents.xmax = xmax; vehicle_extents.ymin = ymin; vehicle_extents.ymax = ymax; vehicle_extents.zmin = zmin; vehicle_extents.zmax = zmax; vehicle_extents.avg = ((xmax - xmin) + (ymax - ymin) + (zmax - zmin)) / 3; queue_redraw( -1 ); } /* Rotates an XYZ triplet whichever way specified * The ?_ALIGN actions realign a point from the x-axis to the indicated axis */ void rotate_xyz( int action, float *x, float *y, float *z, float x0, float y0, float z0 ) { switch (action) { case X_ALIGN: *x = x0; *y = y0; *z = z0; break; case Y_ALIGN: *x = - y0; *y = x0; *z = z0; break; case Z_ALIGN: *x = - z0; *y = y0; *z = x0; break; case Z_ROTATE_CW: *x = y0; *y = - x0; *z = z0; break; case Z_ROTATE_CCW: *x = - y0; *y = x0; *z = z0; break; default: #ifdef DEBUG crash( "rotate_xyz( ): invalid action" ); #endif return; } } /* Calculate unit normal vector for a given triangle */ point * calc_tri_normal( point *a, point *b, point *c ) { static point normal; point vec_ab; point vec_ac; float d; /* Obtain A->B vector */ vec_ab.x = b->x - a->x; vec_ab.y = b->y - a->y; vec_ab.z = b->z - a->z; /* Obtain A->C vector */ vec_ac.x = c->x - a->x; vec_ac.y = c->y - a->y; vec_ac.z = c->z - a->z; /* Obtain cross product (A->B x A->C) to get normal vector */ normal.x = vec_ab.y * vec_ac.z - vec_ab.z * vec_ac.y; normal.y = vec_ab.z * vec_ac.x - vec_ab.x * vec_ac.z; normal.z = vec_ab.x * vec_ac.y - vec_ab.y * vec_ac.x; /* Scale it by own length to get unit normal vector */ d = sqrt( SQR(normal.x) + SQR(normal.y) + SQR(normal.z) ); if (d < 1E-6) d = 1.0; normal.x /= d; normal.y /= d; normal.z /= d; return &normal; } /* Calculate the centroid of a given triangle */ point * calc_tri_centroid( point *a, point *b, point *c ) { static point centroid; centroid.x = (a->x + b->x + c->x) / 3.0; centroid.y = (a->y + b->y + c->y) / 3.0; centroid.z = (a->z + b->z + c->z) / 3.0; return ¢roid; } /* Calculate area of a given triangle */ float calc_tri_area( point *a, point *b, point *c ) { point vec_ab, vec_ac; point xprod; /* Obtain A->B vector */ vec_ab.x = b->x - a->x; vec_ab.y = b->y - a->y; vec_ab.z = b->z - a->z; /* Obtain A->C vector */ vec_ac.x = c->x - a->x; vec_ac.y = c->y - a->y; vec_ac.z = c->z - a->z; /* Magnitude of cross product == 2 * area of ascribed triangle */ xprod.x = vec_ab.y * vec_ac.z - vec_ab.z * vec_ac.y; xprod.y = vec_ab.z * vec_ac.x - vec_ab.x * vec_ac.z; xprod.z = vec_ab.x * vec_ac.y - vec_ab.y * vec_ac.x; return sqrt( SQR(xprod.x) + SQR(xprod.y) + SQR(xprod.z) ) / 2.0; } void show_geometry_stats( void ) { ogl_object *obj; float r,g,b; float ex,ey,ez; int vnum, inum; int vnum_total = 0, inum_total = 0; int i; printf( "=========== Light Speed! geometry stats ===========\n" ); printf( "Object Vertices Indices RGB base color\n" ); printf( "------ -------- ------- ------------------\n" ); for (i = 0; i < num_vehicle_objs; i++) { obj = vehicle_objs[i]; vnum = obj->num_vertices; vnum_total += vnum; inum = obj->num_indices; inum_total += inum; r = obj->color0.r; g = obj->color0.g; b = obj->color0.b; printf( "%6d%12d%11d (%.2f, %.2f, %.2f)\n", i, vnum, inum, r, g, b ); } printf( "------ -------- ------- ------------------\n" ); printf( "Object Vertices Indices RGB base color\n" ); printf( "------ -------- -------\n" ); printf( " Total%12d%11d\n", vnum_total, inum_total ); ex = vehicle_extents.xmax - vehicle_extents.xmin; ey = vehicle_extents.ymax - vehicle_extents.ymin; ez = vehicle_extents.zmax - vehicle_extents.zmin; printf( " Size: %.3f x %.3f x %.3f\n", ex, ey, ez ); printf( "===================================================\n" ); fflush( stdout ); } #ifdef WITH_SRS_EXPORTER /* Write out an .srs (Special Relativity Scene) file, for use with the * BACKLIGHT relativistic raytracer */ int export_srs( const char *filename, int width, int height, int stereo_view, int visible_faces_only ) { FILE *srs; camera eye_cam; point p; rgb_color *bg; float dx,dy; float eye_dx, eye_dy; float t; int flag, i; srs = fopen( filename, "w" ); /* Initialize output camera */ memcpy( &out_cam, usr_cams[0], sizeof(camera) ); out_cam.width = width; out_cam.height = height; /* Header and global settings */ fprintf( srs, "// %s\n", file_basename( filename, NULL ) ); fprintf( srs, "// File generated by the Light Speed! SRS exporter\n" ); fprintf( srs, "// for use with the BACKLIGHT relativistic raytracer\n\n" ); fprintf( srs, "Width = %d\n", width ); fprintf( srs, "Height = %d\n\n", height ); fprintf( srs, "Antialias = 1\n" ); /* Doppler shift switch */ flag = warp( QUERY, MESG_(WARP_DOPPLER_SHIFT) ); i = flag ? 1 : 0; fprintf( srs, "Doppler = %d\n", i ); /* Headlight effect (intensity) switch */ flag = warp( QUERY, MESG_(WARP_HEADLIGHT_EFFECT) ); i = flag ? 1 : 0; fprintf( srs, "Intensity = %d\n\n", i ); fprintf( srs, "Output_File_Name = \"%s\"\n\n", file_basename( filename, ".srs" ) ); /* Background color */ fprintf( srs, "background { colour rgb " ); bg = &background; fprintf( srs, "< %.2f, %.2f, %.2f > }\n\n", bg->r, bg->g, bg->b ); /* Stationary (observer) frame */ fprintf( srs, "frame {\n" ); fprintf( srs, "\t// Observer frame (stationary)\n" ); /* Camera(s) */ t = C * cur_time_t; if (stereo_view) { /* Stereoscopic view */ dx = out_cam.target.x - out_cam.pos.x; dy = out_cam.target.y - out_cam.pos.y; eye_dx = (EYE_SPACING / 2.0) * dy / sqrt( SQR(dx) + SQR(dy) ); eye_dy = - (EYE_SPACING / 2.0) * dx / sqrt( SQR(dx) + SQR(dy) ); fprintf( srs, "\t// Left eye view\n" ); memcpy( &eye_cam, &out_cam, sizeof(camera) ); eye_cam.pos.x -= eye_dx; eye_cam.pos.y -= eye_dy; write_srs_camera( srs, &eye_cam, t ); fprintf( srs, "\t// Right eye view\n" ); memcpy( &eye_cam, &out_cam, sizeof(camera) ); eye_cam.pos.x += eye_dx; eye_cam.pos.y += eye_dy; write_srs_camera( srs, &eye_cam, t ); } else { /* Normal view */ write_srs_camera( srs, &out_cam, t ); } /* Light source */ fprintf( srs, "\tlight_source {\n" ); convert_to_srs_cs( &p, &out_cam.pos ); fprintf( srs, "\t\t< %.3f, %.3f, %.3f >\n", p.x, p.y, p.z ); fprintf( srs, "\t\tcolour rgb " ); fprintf( srs, "< 1, 1, 1 >\n" ); fprintf( srs, "\t}\n" ); fprintf( srs, "}\n\n" ); /* Moving (object) frame */ fprintf( srs, "frame {\n" ); fprintf( srs, "\t// Object frame (moving)\n" ); fprintf( srs, "\t// v = %s\n", velocity_string( velocity, TRUE ) ); fprintf( srs, "\tvelocity " ); fprintf( srs, "< %.6f, 0, 0 >\n", velocity / C ); /* Export lattice or arbitrary mesh geometry */ fprintf( srs, "\n" ); if (object_mode == MODE_LATTICE) write_srs_lattice( srs ); else write_srs_mesh( srs, &out_cam.pos, visible_faces_only ); fprintf( srs, "\n" ); fprintf( srs, "}\n" ); fclose( srs ); return 0; } void write_srs_mesh( FILE *srs, point *cam_pos, int visible_faces_only ) { ogl_object *obj; point *face_verts[4]; point *face_norms[4]; point *vert_a, *vert_b; point tri_verts[3]; point *norm, *cent; float dx,dy,dz; float fdir; int checks[6][2] = { {0,1}, {1,2}, {2,0}, {0,3}, {1,3}, {2,3} }; int face_size; int num_faces; int num_checks; int *face_flags; int base, ind, ind_a, ind_b; int bad_face, at_least_one_good_face; int o, f, i, a, b; fprintf( srs, "\t// **** Begin mesh definition ****\n" ); for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; switch (obj->type) { case GL_TRIANGLES: face_size = 3; num_checks = 3; break; case GL_QUADS: face_size = 4; num_checks = 6; break; default: #ifdef DEBUG crash( "write_srs_mesh( ): invalid object type" ); #endif return; } num_faces = obj->num_indices / face_size; face_flags = xmalloc( num_faces * sizeof(int) ); /* First, check for good faces in this object * (good = no coincident vertices, no zero normals) */ at_least_one_good_face = FALSE; for (f = 0; f < num_faces; f++) { base = f * face_size; bad_face = FALSE; /* benefit of the doubt */ for (i = 0; i < num_checks; i++) { /* Check between vertex pair */ a = checks[i][0]; b = checks[i][1]; ind_a = obj->indices[base + a]; ind_b = obj->indices[base + b]; vert_a = &obj->vertices0[ind_a]; vert_b = &obj->vertices0[ind_b]; dx = ABS(vert_a->x - vert_b->x); dy = ABS(vert_a->y - vert_b->y); dz = ABS(vert_a->z - vert_b->z); if ((dx < 1E-4) && (dy < 1E-4) && (dz < 1E-4)) bad_face = TRUE; } /* Check face normals */ for (i = 0; i < face_size; i++) { ind = obj->indices[base + i]; norm = &obj->normals0[ind]; dx = ABS(norm->x); dy = ABS(norm->y); dz = ABS(norm->z); if ((dx < 1E-2) && (dy < 1E-2) && (dz < 1E-2)) bad_face = TRUE; } /* If only visible faces are desired, check if face * is facing the camera (dropping it if not) */ if (visible_faces_only && !bad_face) { for (i = 0; i < 3; i++) { ind = obj->indices[base + i]; memcpy( &tri_verts[i], &obj->vertices0[ind], sizeof(point) ); warp_point( &tri_verts[i], NULL, cam_pos ); } /* Calculate (warped) flat triangle normal * (for quads: 4th vertex is coplanar anyway) */ norm = calc_tri_normal( &tri_verts[0], &tri_verts[1], &tri_verts[2] ); /* Calculate (warped) centroid and then the * triangle-to-camera (reverse view) vector */ cent = calc_tri_centroid( &tri_verts[0], &tri_verts[1], &tri_verts[2] ); dx = cam_pos->x - cent->x; dy = cam_pos->y - cent->y; dz = cam_pos->z - cent->z; /* Get dot product of normal and rview vectors */ fdir = (norm->x * dx) + (norm->y * dy) + (norm->z * dz); if (fdir < 0) bad_face = TRUE; /* not facing camera */ } if (bad_face) face_flags[f] = FALSE; else { face_flags[f] = TRUE; at_least_one_good_face = TRUE; } } if (!at_least_one_good_face) { xfree( face_flags ); continue; } /* Write out the good faces */ fprintf( srs, "\tunion {\n" ); for (f = 0; f < num_faces; f++) { if (!face_flags[f]) continue; /* skip bad face */ base = f * face_size; for (i = 0; i < face_size; i++) { ind = obj->indices[base + i]; face_verts[i] = &obj->vertices0[ind]; face_norms[i] = &obj->normals0[ind]; } write_srs_smooth_triangle( srs, face_verts, face_norms ); if (face_size == 4) { /* Output a 2nd triangle to make a quad * Shift 3rd and 4th vertices down */ face_verts[1] = face_verts[2]; face_norms[1] = face_norms[2]; face_verts[2] = face_verts[3]; face_norms[2] = face_norms[3]; write_srs_smooth_triangle( srs, face_verts, face_norms ); } } xfree( face_flags ); /* Write out face group color */ write_srs_pigment( srs, &obj->color0 ); fprintf( srs, "\t}\n" ); } fprintf( srs, "\t// **** End mesh definition ****\n" ); } void write_srs_camera( FILE *srs, camera *cam, float t ) { point p; float aspect_ratio; aspect_ratio = (float)cam->width / (float)cam->height; fprintf( srs, "\tcamera {\n" ); fprintf( srs, "\t\tlocation " ); convert_to_srs_cs( &p, &cam->pos ); fprintf( srs, "< %.3f, %.3f, %.3f >, %.3f\n", p.x, p.y, p.z, t ); fprintf( srs, "\t\tup < 0, 1, 0 >\n" ); fprintf( srs, "\t\tright " ); fprintf( srs, "< %.3f, 0, 0 >\n", - aspect_ratio ); fprintf( srs, "\t\tangle %.2f\n", cam->fov ); fprintf( srs, "\t\tlook_at " ); convert_to_srs_cs( &p, &cam->target ); fprintf( srs, "< %.3f, %.3f, %.3f >\n", p.x, p.y, p.z ); fprintf( srs, "\t}\n" ); } void write_srs_sphere( FILE *srs, point *center, float radius ) { fprintf( srs, "\t\tsphere {\n" ); fprintf( srs, "\t\t\t< %.3f, %.3f, %.3f >,\n", center->x, center->y, center->z ); fprintf( srs, "\t\t\t%.3f\n", radius ); fprintf( srs, "\t\t}\n" ); } void write_srs_cylinder( FILE *srs, point *p1, point *p2, float radius ) { fprintf( srs, "\t\tcylinder {\n" ); fprintf( srs, "\t\t\t< %.3f, %.3f, %.3f >,\n", p1->x, p1->y, p1->z ); fprintf( srs, "\t\t\t< %.3f, %.3f, %.3f >,\n", p2->x, p2->y, p2->z ); fprintf( srs, "\t\t\t%.3f\n", radius ); fprintf( srs, "\t\t}\n" ); } void write_srs_smooth_triangle( FILE *srs, point **vertices, point **normals ) { point vert_srs, norm_srs; int i; fprintf( srs, "\t\tsmooth_triangle {\n" ); for (i = 0; i < 3; i++) { convert_to_srs_cs( &vert_srs, vertices[i] ); fprintf( srs, "\t\t\t< %.4f, %.4f, %.4f >,\n", vert_srs.x, vert_srs.y, vert_srs.z ); convert_to_srs_cs( &norm_srs, normals[i] ); fprintf( srs, "\t\t\t < %.4f, %.4f, %.4f >", norm_srs.x, norm_srs.y, norm_srs.z ); if (i < 2) fprintf( srs, ",\n" ); else fprintf( srs, "\n" ); } fprintf( srs, "\t\t}\n" ); } void write_srs_pigment( FILE *srs, rgb_color *color ) { float r,g,b; fprintf( srs, "\t\tpigment {\n" ); fprintf( srs, "\t\t\tcolour rgb " ); r = color->r; g = color->g; b = color->b; fprintf( srs, "< %.3f, %.3f, %.3f >\n", r, g, b ); fprintf( srs, "\t\t}\n" ); } /* Converts a point from our coordinate system (right-handed, z-axis up) to the * BACKLIGHT/SRS coordinate system (right-handed, y-axis up) */ void convert_to_srs_cs( point *p_srs, point *p_ls ) { p_srs->x = p_ls->x; p_srs->y = p_ls->z; p_srs->z = - p_ls->y; } #endif /* WITH_SRS_EXPORTER */ /* end geometry.c */ lightspeed-1.2a.debian.1/src/globals.c000066400000000000000000000075621334064775200176300ustar00rootroot00000000000000/* globals.c */ /* Global variables */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Message value array (used in conjunction with the MESG_ macro) */ const int mesg_vals[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59, 60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79 }; /* Unit definitions */ const int num_unit_systems = 3; const char *unit_suffixes[] = { "c", "m/s", "Km/h" }; const double unit_conv_factors[] = { C, 1.0, (5.0/18.0) }; const int unit_num_decimals[] = { 6, 0, 0 }; int cur_unit_system = DEF_VELOCITY_UNITS; /* Background colors */ const int num_background_colors = 4; /* Background color names are defined in lstrings.c */ const rgb_color bkgd_colors[] = { { 0.0, 0.0, 0.0 }, { 0.25, 0.25, 0.25 }, { 0.85, 0.85, 0.85 }, { 1.0, 1.0, 1.0 } }; rgb_color background = { 0.0, 0.0, 0.0 }; /* Fonts for info display */ const int num_font_sizes = 4; const char *sys_font_names[] = { "-adobe-helvetica-bold-o-normal--*-120-*-*-*-*-*-*", "-adobe-helvetica-bold-o-normal--*-140-*-*-*-*-*-*", "-adobe-helvetica-bold-o-normal--*-180-*-*-*-*-*-*", "-adobe-helvetica-bold-o-normal--*-240-*-*-*-*-*-*" }; const int sys_font_sizes[] = { 120, 140, 180, 240 }; /* Character code for the "micro-" prefix glyph (looks similar to a u) * NOTE: revise ogl_draw_string( ) if >= 192 */ const int micro_glyph = 181; /* Stock camera lenses (specified in mm) */ const int num_stock_lenses = 6; const float stock_lenses[ ] = { 28, 35, 50, 85, 135, 200 }; /* Image format extensions * Order must match that of the IMAGE_FORMAT_??? symbols in lightspeed.h */ const char *image_format_exts[] = { ".png", ".tif" }; /* Vehicle velocity */ double velocity = 1.0; /* Current time t * (of simulation-- NOT system clock */ double cur_time_t; /* This is the "real" x-position of the vehicle */ float vehicle_real_x; /* Type of object(s) currently in the viewer */ int object_mode = MODE_LATTICE; /* Current lattice dimensions (in lattice units) */ int lattice_size_x = DEF_LATTICE_X; int lattice_size_y = DEF_LATTICE_Y; int lattice_size_z = DEF_LATTICE_Z; /* Graphical framerate (fps) * (don't worry, it gets better :-) */ float framerate = 0.0; /* Vehicle (moving) object(s) */ ogl_object **vehicle_objs; int num_vehicle_objs; extents vehicle_extents; /* World extents * Only xmin/xmax fields are significant, for now * (and are determined by size of floating grid) */ extents world_extents = { -10.0, 10.0, NIL, NIL, NIL, NIL, NIL }; /* Camera array. *usr_cam[0] is primary */ camera **usr_cams = NULL; int num_cams = 0; int cur_cam; /* Output camera (for snapshots and SRS scenes) */ camera out_cam; /* Advanced interface flag (controls presence of extra features) */ int advanced_interface = DEF_ADVANCED_INTERFACE; /* Gamma correction flag & lookup table * NOTE: This is display gamma, not Lorentz factor gamma! */ int dgamma_correct; float dgamma_lut[LUT_RES + 1]; /* Mouse sensitivity setting */ float mouse_sens = DEF_MOUSE_SENS; /* end globals.c */ lightspeed-1.2a.debian.1/src/gtkglext-workaround.c000066400000000000000000000101461334064775200222170ustar00rootroot00000000000000/* GdkGLExt - OpenGL Extension to GDK * Copyright (C) 2002-2004 Naofumi Yasufuku * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include #include #include "gdk/x11/gdkglx.h" //#include "gdkglprivate-x11.h" //#include "gdkglfont.h" static char * gdk_gl_font_charset_for_locale (void) { static char *charset_map[][2] = { { "ANSI_X3.4-1968", "iso8859-1" }, { "US-ASCII", "iso8859-1" }, { "ISO-8859-1", "iso8859-1" }, { "ISO-8859-2", "iso8859-2" }, { "ISO-8859-3", "iso8859-3" }, { "ISO-8859-4", "iso8859-4" }, { "ISO-8859-5", "iso8859-5" }, { "ISO-8859-6", "iso8859-6" }, { "ISO-8859-7", "iso8859-7" }, { "ISO-8859-8", "iso8859-8" }, { "ISO-8859-9", "iso8859-9" }, { "UTF-8", "iso8859-1" } }; const char *codeset; char *result = NULL; gsize i; g_get_charset (&codeset); for (i = 0; i < G_N_ELEMENTS (charset_map); i++) if (strcmp (charset_map[i][0], codeset) == 0) { result = charset_map[i][1]; break; } if (result != NULL) return g_strdup (result); else return g_strdup ("iso8859-1"); } /************* patched version for bug bugs.debian.org/366944 ********/ static PangoFont * gdk_gl_font_use_pango_font_common (PangoFontMap *font_map, const PangoFontDescription *font_desc, int first, int count, int list_base) { PangoFont *font = NULL; gchar *charset = NULL; PangoXSubfont subfont_id; gchar *xlfd = NULL; PangoXFontCache *font_cache; XFontStruct *fs; font = pango_font_map_load_font (font_map, NULL, font_desc); if (font == NULL) { g_warning ("cannot load PangoFont"); goto FAIL; } charset = gdk_gl_font_charset_for_locale (); if (!pango_x_find_first_subfont (font, &charset, 1, &subfont_id)) { g_warning ("cannot find PangoXSubfont"); font = NULL; goto FAIL; } xlfd = pango_x_font_subfont_xlfd (font, subfont_id); if (xlfd == NULL) { g_warning ("cannot get XLFD"); font = NULL; goto FAIL; } font_cache = pango_x_font_map_get_font_cache (font_map); fs = pango_x_font_cache_load (font_cache, xlfd); if( fs == NULL) { g_warning ("cannot get X font cache"); font = NULL; goto FAIL; } glXUseXFont (fs->fid, first, count, list_base); pango_x_font_cache_unload (font_cache, fs); FAIL: if (charset != NULL) g_free (charset); if (xlfd != NULL) g_free (xlfd); return font; } /**** end of patched version ******/ PangoFont * my_gdk_gl_font_use_pango_font (const PangoFontDescription *font_desc, int first, int count, int list_base) { PangoFontMap *font_map; g_return_val_if_fail (font_desc != NULL, NULL); #ifdef GDKGLEXT_MULTIHEAD_SUPPORT font_map = pango_x_font_map_for_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); #else /* GDKGLEXT_MULTIHEAD_SUPPORT */ font_map = pango_x_font_map_for_display (gdk_x11_get_default_xdisplay ()); #endif /* GDKGLEXT_MULTIHEAD_SUPPORT */ return gdk_gl_font_use_pango_font_common (font_map, font_desc, first, count, list_base); } lightspeed-1.2a.debian.1/src/gtkwidgets.c000066400000000000000000000527541334064775200203640ustar00rootroot00000000000000/* gtkwidgets.c */ /* GTK+ UI-building semi-abstractions * (Most of the drudge code is in here) */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Creates and installs an OpenGL widget into specified box */ GtkWidget * add_gl_area( GtkWidget *parent_box_w ) { GtkWidget *ogl_w; ogl_w = ogl_make_widget( ); gtk_box_pack_start( GTK_BOX(parent_box_w), ogl_w, TRUE, TRUE, 0 ); gtk_widget_show( ogl_w ); gtk_widget_set_events( GTK_WIDGET(ogl_w), GDK_EXPOSURE_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK ); /* Attach the signal handlers */ gtk_signal_connect( GTK_OBJECT(ogl_w), "realize", GTK_SIGNAL_FUNC(ogl_initialize), NULL ); gtk_signal_connect( GTK_OBJECT(ogl_w), "expose_event", GTK_SIGNAL_FUNC(ogl_refresh), NULL ); gtk_signal_connect( GTK_OBJECT(ogl_w), "configure_event", GTK_SIGNAL_FUNC(ogl_resize), NULL ); gtk_signal_connect( GTK_OBJECT(ogl_w), "button_press_event", GTK_SIGNAL_FUNC(camera_move), NULL ); gtk_signal_connect( GTK_OBJECT(ogl_w), "button_release_event", GTK_SIGNAL_FUNC(camera_move), NULL ); gtk_signal_connect( GTK_OBJECT(ogl_w), "motion_notify_event", GTK_SIGNAL_FUNC(camera_move), NULL ); return ogl_w; } /* Creates a base dialog window */ GtkWidget * make_dialog_window( const char *title, void *callback_close ) { GtkWidget *dialog_window_w; #ifdef HAVE_GTK1 dialog_window_w = gtk_window_new( GTK_WINDOW_DIALOG ); #else dialog_window_w = gtk_window_new(GTK_WINDOW_TOPLEVEL); //should use... gtk_dialog_new(); ... but it fails elsewhere #endif gtk_window_set_title( GTK_WINDOW(dialog_window_w), title ); gtk_container_set_border_width( GTK_CONTAINER(dialog_window_w), 0 ); if (callback_close != NULL) { gtk_signal_connect( GTK_OBJECT(dialog_window_w), "destroy", GTK_SIGNAL_FUNC(callback_close), MESG_(DIALOG_CLOSE) ); } /* Note, no gtk_widget_show( ) */ return dialog_window_w; } /* Creates a simple, click-away message dialog */ GtkWidget * message_window( const char *title, const char *message_text ) { GtkWidget *message_window_w; GtkWidget *vbox_w; GtkWidget *hbox_w; GtkWidget *frame_w; GtkWidget *button_w; message_window_w = make_dialog_window( title, NULL ); gtk_window_set_position( GTK_WINDOW(message_window_w), GTK_WIN_POS_MOUSE ); gtk_signal_connect( GTK_OBJECT(message_window_w), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), NULL ); vbox_w = add_vbox( message_window_w, FALSE, 10 ); frame_w = add_frame( vbox_w, NULL ); hbox_w = add_hbox( frame_w, FALSE, 10 ); add_label( hbox_w, message_text ); /* OK button */ button_w = gtk_button_new( ); add_label( button_w, "OK" ); gtk_box_pack_start( GTK_BOX(vbox_w), button_w, TRUE, TRUE, 0 ); gtk_signal_connect_object( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(message_window_w) ); gtk_widget_show( button_w ); gtk_widget_show( message_window_w ); return message_window_w; } /* Confirmation dialog */ GtkWidget * confirmation_dialog( const char *title, const char *message_text, void *callback ) { GtkWidget *confirm_window_w; GtkWidget *main_vbox_w; GtkWidget *hbox_w; GtkWidget *frame_w; GtkWidget *button_w; confirm_window_w = make_dialog_window( title, callback ); gtk_window_set_position( GTK_WINDOW(confirm_window_w), GTK_WIN_POS_MOUSE ); gtk_signal_connect( GTK_OBJECT(confirm_window_w), "delete_event", GTK_SIGNAL_FUNC(gtk_widget_destroy), NULL ); main_vbox_w = add_vbox( confirm_window_w, FALSE, 10 ); frame_w = add_frame( main_vbox_w, NULL ); hbox_w = add_hbox( frame_w, FALSE, 10 ); add_label( hbox_w, message_text ); hbox_w = add_hbox( main_vbox_w, TRUE, 0 ); /* OK button */ button_w = gtk_button_new( ); add_label( button_w, "OK" ); gtk_box_pack_start( GTK_BOX(hbox_w), button_w, TRUE, TRUE, 0 ); gtk_signal_connect_object( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(confirm_window_w) ); gtk_signal_connect( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(callback), MESG_(DIALOG_OK_CONFIRM) ); gtk_signal_connect_object( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(confirm_window_w) ); gtk_widget_show( button_w ); add_hbox( hbox_w, TRUE, 0 ); /* spacer */ /* Cancel button */ button_w = gtk_button_new( ); add_label( button_w, "Cancel" ); gtk_box_pack_start( GTK_BOX(hbox_w), button_w, TRUE, TRUE, 0 ); gtk_signal_connect_object( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(confirm_window_w) ); gtk_signal_connect( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(callback), MESG_(DIALOG_CLOSE) ); gtk_signal_connect_object( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(confirm_window_w) ); gtk_widget_show( button_w ); gtk_widget_show( confirm_window_w ); return confirm_window_w; } /* Creates a file selection dialog */ GtkWidget * make_filesel_window( const char *title, const char *init_filename, int show_fileops, void *callback_handler ) { GtkWidget *filesel_w; filesel_w = gtk_file_selection_new( title ); if (!show_fileops) gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION(filesel_w) ); if (init_filename != NULL) gtk_file_selection_set_filename( GTK_FILE_SELECTION(filesel_w), init_filename ); gtk_signal_connect( GTK_OBJECT(filesel_w), "destroy", GTK_SIGNAL_FUNC(callback_handler), MESG_(DIALOG_CLOSE) ); gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(filesel_w)->cancel_button), "clicked", GTK_SIGNAL_FUNC(callback_handler), MESG_(DIALOG_CLOSE) ); gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(filesel_w)->ok_button), "clicked", GTK_SIGNAL_FUNC(callback_handler), MESG_(DIALOG_OK) ); return filesel_w; } /* Add a menu to a menu bar (or a submenu to a menu) */ GtkWidget * add_menu( GtkWidget *parent_menu_w, const char *label ) { GtkWidget *menu_item_w; GtkWidget *menu_w; menu_item_w = gtk_menu_item_new_with_label( label ); /* parent_menu can be a menu bar or a regular menu */ if (GTK_IS_MENU_BAR(parent_menu_w)) gtk_menu_bar_append( GTK_MENU_BAR(parent_menu_w), menu_item_w ); else gtk_menu_append( GTK_MENU(parent_menu_w), menu_item_w ); gtk_widget_show( menu_item_w ); menu_w = gtk_menu_new( ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu_item_w), menu_w ); return menu_w; } /* Add a menu item to a menu */ GtkWidget * add_menu_item( GtkWidget *menu_w, const char *label, void *callback, void *callback_data ) { GtkWidget *menu_item_w; menu_item_w = gtk_menu_item_new_with_label( label ); gtk_menu_append( GTK_MENU(menu_w), menu_item_w ); if (callback != NULL) { gtk_signal_connect( GTK_OBJECT(menu_item_w), "activate", GTK_SIGNAL_FUNC(callback), callback_data ); } gtk_widget_show( menu_item_w ); return menu_item_w; } /* Add a check-button menu item to a menu */ GtkWidget * add_check_menu_item( GtkWidget *menu_w, const char *label, int init_state, void *callback, void *callback_data ) { GtkWidget *chkmenu_item_w; chkmenu_item_w = gtk_check_menu_item_new_with_label( label ); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(chkmenu_item_w), init_state ); gtk_check_menu_item_set_show_toggle( GTK_CHECK_MENU_ITEM(chkmenu_item_w), TRUE ); gtk_menu_append( GTK_MENU(menu_w), chkmenu_item_w ); gtk_signal_connect( GTK_OBJECT(chkmenu_item_w), "toggled", GTK_SIGNAL_FUNC(callback), callback_data ); gtk_widget_show( chkmenu_item_w ); return chkmenu_item_w; } /* Initiates the definition of a radio menu item group, having a specified * initially selected item (0 == first, 1 == second, etc.) */ void begin_radio_menu_group( int init_selected ) { add_radio_menu_item( NULL, (char *)&init_selected, NULL, NULL ); } /* Add a radio-button menu item to a menu * NOTE: Call begin_radio_menu_group( ) before defining the group! */ GtkWidget * add_radio_menu_item( GtkWidget *menu_w, const char *label, void *callback, void *callback_data ) { static GSList *radio_group; static int radmenu_item_num; static int init_selected; GtkWidget *radmenu_item_w = NULL; if (menu_w != NULL) { radmenu_item_w = gtk_radio_menu_item_new_with_label( radio_group, label ); radio_group = gtk_radio_menu_item_group( GTK_RADIO_MENU_ITEM(radmenu_item_w) ); gtk_menu_append( GTK_MENU(menu_w), radmenu_item_w ); if (radmenu_item_num == init_selected) gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(radmenu_item_w), TRUE ); gtk_signal_connect( GTK_OBJECT(radmenu_item_w), "toggled", GTK_SIGNAL_FUNC(callback), callback_data ); gtk_widget_show( radmenu_item_w ); ++radmenu_item_num; } else { /* we're being called from begin_radio_menu_group( ) */ radio_group = NULL; radmenu_item_num = 0; init_selected = *((int *)label); } return radmenu_item_w; } /* Option menu definiton * Call this however many times necessary, and then call add_option_menu( ) * to stick in the finished widget */ GtkWidget * option_menu_item( const char *label, void *callback, void *callback_data ) { GtkWidget *menu_item_w; menu_item_w = gtk_menu_item_new_with_label( label ); if (callback != NULL) { gtk_signal_connect( GTK_OBJECT(menu_item_w), "activate", GTK_SIGNAL_FUNC(callback), callback_data ); } add_option_menu( menu_item_w ); return menu_item_w; } /* Add the finished option menu into the specified box widget * (widget can only be a menu item when called from option_menu_item( )) */ GtkWidget * add_option_menu( GtkWidget *widget ) { static GtkWidget *menu_w = NULL; GtkWidget *optmenu_w; if (GTK_IS_MENU_ITEM(widget)) { if (menu_w == NULL) menu_w = gtk_menu_new( ); gtk_menu_append( GTK_MENU(menu_w), widget ); gtk_widget_show( widget ); return NULL; } /* widget is a Gtk?box */ optmenu_w = gtk_option_menu_new( ); gtk_option_menu_set_menu( GTK_OPTION_MENU(optmenu_w), menu_w ); gtk_box_pack_start( GTK_BOX(widget), optmenu_w, FALSE, FALSE, 0 ); gtk_widget_show( optmenu_w ); menu_w = NULL; return optmenu_w; } /* The ever-ubiquitous separator */ void add_separator( GtkWidget *parent_w ) { GtkWidget *separator_w; if (GTK_IS_MENU(parent_w)) { separator_w = gtk_menu_item_new( ); gtk_menu_append( GTK_MENU(parent_w), separator_w ); } else { separator_w = gtk_hseparator_new( ); gtk_box_pack_start( GTK_BOX(parent_w), separator_w, TRUE, TRUE, 0 ); } gtk_widget_show( separator_w ); } /* Sets up keybindings (accelerators) * Call first with widget == NULL, then with any number of widget/keystroke * pairs, and finally with the parent window. */ void keybind( GtkWidget *widget, char *keys ) { static GtkAccelGroup *accel_group; int mods; char k; if (widget == NULL) { accel_group = gtk_accel_group_new( ); return; } if (GTK_IS_WINDOW(widget)) { #ifdef HAVE_GTK1 gtk_accel_group_attach( accel_group, GTK_OBJECT(widget) ); #else gtk_window_add_accel_group (GTK_WINDOW (widget), accel_group); #endif return; } g_return_if_fail(keys); /* Parse keystroke string */ switch (keys[0]) { case '^': /* Ctrl- keystroke specified */ mods = GDK_CONTROL_MASK; k = keys[1]; break; default: /* Simple keypress */ mods = 0; k = keys[0]; break; } if (GTK_IS_MENU_ITEM(widget)) { gtk_widget_add_accelerator( widget, "activate", accel_group, k, mods, GTK_ACCEL_VISIBLE ); return; } if (GTK_IS_BUTTON(widget)) { gtk_widget_add_accelerator( widget, "clicked", accel_group, k, mods, GTK_ACCEL_VISIBLE ); return; } /* Default: make widget grab focus */ gtk_widget_add_accelerator( widget, "grab_focus", accel_group, k, mods, GTK_ACCEL_VISIBLE ); } /* The horizontal box widget */ GtkWidget * add_hbox( GtkWidget *parent_w, int homog, int spacing ) { GtkWidget *hbox_w; hbox_w = gtk_hbox_new( homog, spacing ); gtk_container_set_border_width( GTK_CONTAINER(hbox_w), spacing ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), hbox_w, FALSE, FALSE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), hbox_w ); gtk_widget_show( hbox_w ); return hbox_w; } /* The vertical box widget */ GtkWidget * add_vbox( GtkWidget *parent_w, int homog, int spacing ) { GtkWidget *vbox_w; vbox_w = gtk_vbox_new( homog, spacing ); gtk_container_set_border_width( GTK_CONTAINER(vbox_w), spacing ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), vbox_w, FALSE, FALSE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), vbox_w ); gtk_widget_show( vbox_w ); return vbox_w; } /* Frame widget */ GtkWidget * add_frame( GtkWidget *parent_w, const char *title ) { GtkWidget *frame_w; frame_w = gtk_frame_new( title ); if (parent_w != NULL) { if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), frame_w, FALSE, FALSE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), frame_w ); gtk_widget_show( frame_w ); } return frame_w; } /* The horizontal value slider widget */ GtkWidget * add_hscale( GtkWidget *parent_w, GtkObject *adjustment ) { GtkWidget *hscale_w; hscale_w = gtk_hscale_new( GTK_ADJUSTMENT(adjustment) ); gtk_scale_set_digits( GTK_SCALE(hscale_w), 0 ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), hscale_w, TRUE, TRUE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), hscale_w ); gtk_widget_show( hscale_w ); return hscale_w; } /* The vertical value slider widget */ GtkWidget * add_vscale( GtkWidget *parent_w, GtkObject *adjustment ) { GtkWidget *vscale_w; vscale_w = gtk_vscale_new( GTK_ADJUSTMENT(adjustment) ); gtk_scale_set_value_pos( GTK_SCALE(vscale_w), GTK_POS_RIGHT ); gtk_scale_set_digits( GTK_SCALE(vscale_w), 0 ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), vscale_w, TRUE, TRUE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), vscale_w ); gtk_widget_show( vscale_w ); return vscale_w; } /* The spin button widget */ GtkWidget * add_spin_button( GtkWidget *parent_w, GtkObject *adjustment ) { GtkWidget *spin_button_w; spin_button_w = gtk_spin_button_new( GTK_ADJUSTMENT(adjustment), 0.0, 0 ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), spin_button_w, TRUE, FALSE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), spin_button_w ); gtk_widget_show( spin_button_w ); return spin_button_w; } /* The check button widget */ GtkWidget * add_check_button( GtkWidget *parent_w, const char *label, int init_state, void *callback, void *callback_data ) { GtkWidget *chkbutton_w; chkbutton_w = gtk_check_button_new_with_label( label ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(chkbutton_w), init_state ); gtk_toggle_button_set_mode( GTK_TOGGLE_BUTTON(chkbutton_w), TRUE ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), chkbutton_w, TRUE, TRUE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), chkbutton_w ); if (callback != NULL) { gtk_signal_connect( GTK_OBJECT(chkbutton_w), "toggled", GTK_SIGNAL_FUNC(callback), callback_data ); } gtk_widget_show( chkbutton_w ); return chkbutton_w; } /* Text/data/number entry */ GtkWidget * add_entry( GtkWidget *parent_w, const char *init_str, void *callback, void *callback_data ) { GtkWidget *entry_w; entry_w = gtk_entry_new_with_max_length( 16 ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), entry_w, FALSE, FALSE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), entry_w ); gtk_entry_set_text( GTK_ENTRY(entry_w), init_str ); if (callback != NULL ) gtk_signal_connect( GTK_OBJECT(entry_w), "activate", GTK_SIGNAL_FUNC(callback), callback_data ); gtk_widget_show( entry_w ); return entry_w; } /* Sets an entry to the width of a specified string */ void set_entry_width( GtkWidget *entry_w, const char *span_str ) { GtkStyle *style; int width; style = gtk_widget_get_style( entry_w ); #ifdef HAVE_GTK1 width = gdk_string_width( style->font, span_str ); #else PangoFontDescription *font_desc=style->font_desc; #warning FIXME width=strlen(span_str) * 8 ; #endif gtk_widget_set_usize( entry_w, width, 0 ); } /* Resets the text in an entry to specified string */ void set_entry_text( GtkWidget *entry_w, const char *entry_text ) { gtk_entry_set_text( GTK_ENTRY(entry_w), entry_text ); } /* Returns the text in an entry */ char * read_entry( GtkWidget *entry_w ) { return gtk_entry_get_text( GTK_ENTRY(entry_w) ); } /* Highlights the text in an entry */ void highlight_entry( GtkWidget *entry_w ) { gtk_entry_select_region( GTK_ENTRY(entry_w), 0, GTK_ENTRY(entry_w)->text_length ); } GtkWidget * add_button( GtkWidget *parent_w, const char *label, void *callback, void *callback_data ) { GtkWidget *button_w; button_w = gtk_button_new( ); if (label != NULL) add_label( button_w, label ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), button_w, TRUE, TRUE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), button_w ); gtk_signal_connect( GTK_OBJECT(button_w), "clicked", GTK_SIGNAL_FUNC(callback), callback_data ); gtk_widget_show( button_w ); return button_w; } GtkWidget * add_label( GtkWidget *parent_w, const char *label_text ) { GtkWidget *label_w; GtkWidget *hbox_w; label_w = gtk_label_new( label_text ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), label_w, FALSE, FALSE, 0 ); else if (GTK_IS_BUTTON(parent_w)) { /* Labels are often too snug inside buttons */ hbox_w = add_hbox( parent_w, FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), label_w, TRUE, FALSE, 5 ); } else gtk_container_add( GTK_CONTAINER(parent_w), label_w ); gtk_widget_show( label_w ); return label_w; } /* Scrollable (but non-editing) text window * (I call it a "text area," as just "text" is ambiguous */ GtkWidget * add_text_area__UNUSED( GtkWidget *parent_w, const char *content ) { GtkWidget *text_w; GtkWidget *hbox_w; GtkWidget *vscrollbar_w; /* Horizontal box for text area + vertical scrollbar */ hbox_w = gtk_hbox_new( FALSE, 0 ); if (GTK_IS_BOX(parent_w)) gtk_box_pack_start( GTK_BOX(parent_w), hbox_w, TRUE, TRUE, 0 ); else gtk_container_add( GTK_CONTAINER(parent_w), hbox_w ); gtk_widget_show( hbox_w ); /* Text [area] widget */ #ifdef HAVE_GTK1 text_w = gtk_text_new( NULL, NULL ); /* Set properties suited for a text viewer */ gtk_text_set_editable( GTK_TEXT(text_w), FALSE ); gtk_text_set_word_wrap( GTK_TEXT(text_w), TRUE ); #else text_w = gtk_text_view_new(); #endif gtk_box_pack_start( GTK_BOX(hbox_w), text_w, TRUE, TRUE, 0 ); gtk_widget_show( text_w ); /* Vertical scroll bar */ #ifdef HAVE_GTK1 #warning FIXME vscrollbar_w = gtk_vscrollbar_new( GTK_TEXT(text_w)->vadj ); gtk_box_pack_start( GTK_BOX(hbox_w), vscrollbar_w, FALSE, FALSE, 0 ); gtk_widget_show( vscrollbar_w ); #endif /* Bring in the text */ gtk_widget_realize( text_w ); #ifdef HAVE_GTK1 gtk_text_insert( GTK_TEXT(text_w), NULL, NULL, NULL, content, -1 ); #else GtkTextBuffer* B = gtk_text_view_get_buffer(text_w); gtk_text_buffer_insert(B,//GtkTextBuffer *buffer, NULL,//GtkTextIter *iter, content,//const gchar *text, -1);//gint len); #endif return text_w; } void add_tooltip( GtkWidget *ambiguous_widget, const char *tip_text ) { static GtkTooltips *tooltips = NULL; if (tooltips == NULL) { tooltips = gtk_tooltips_new( ); gtk_tooltips_set_delay( tooltips, 2000 ); } gtk_tooltips_set_tip( tooltips, ambiguous_widget, tip_text, NULL ); } /* Adds an XPM */ GtkWidget * add_pixmap( GtkWidget *parent_w, GtkWidget *parent_window_w, char **xpm_data ) { GtkWidget *pixmap_w; GtkStyle *style; GdkPixmap *pixmap; GdkBitmap *mask; /* Realize the window to prevent a "NULL window" error */ gtk_widget_realize( parent_window_w ); style = gtk_widget_get_style( parent_window_w ); pixmap = gdk_pixmap_create_from_xpm_d( parent_window_w->window, &mask, &style->bg[GTK_STATE_NORMAL], xpm_data ); pixmap_w = gtk_pixmap_new( pixmap, mask ); gdk_pixmap_unref( pixmap ); gdk_bitmap_unref( mask ); gtk_box_pack_start( GTK_BOX(parent_w), pixmap_w, FALSE, FALSE, 0 ); gtk_widget_show( pixmap_w ); return pixmap_w; } /* Associates an XPM icon to a window */ void assign_icon( GtkWidget *window_w, char **xpm_data ) { GtkStyle *style; GdkPixmap *icon_pixmap; GdkBitmap *mask; gtk_widget_realize( window_w ); style = gtk_widget_get_style( window_w ); icon_pixmap = gdk_pixmap_create_from_xpm_d( window_w->window, &mask, &style->bg[GTK_STATE_NORMAL], xpm_data ); gdk_window_set_icon( window_w->window, NULL, icon_pixmap, mask ); } /* end gtkwidgets.c */ lightspeed-1.2a.debian.1/src/icon.xpm000066400000000000000000000114361334064775200175120ustar00rootroot00000000000000/* XPM */ static char * lightspeed_icon_xpm[] = { "64 64 32 1", " c None", ". c #020204", "+ c #474B58", "@ c #262627", "# c #2C2C2D", "$ c #101624", "% c #707070", "& c #606062", "* c #021965", "= c #22377B", "- c #2D3C6D", "; c #0F297D", "> c #505051", ", c #3C3C3D", "' c #1A2E70", ") c #0B2064", "! c #0F1012", "~ c #808080", "{ c #181818", "] c #485478", "^ c #32343A", "/ c #434448", "( c #1F2023", "_ c #787878", ": c #68686A", "< c #354370", "[ c #57585D", "} c #02103D", "| c #868685", "1 c #0C1A47", "2 c #022080", "3 c #202C51", "................................................................", "................................................................", "................................................................", "...........................}2*..................................", "..........................(<;;[/,^@(!!...}**....................", "..................*}..(^>::&''&%_~~~~~_%[;;2^#({!..........}}...", ".................*22)&%:[,{}=1...!{(#,+:&&<2_|||~~_%&[+,^(*22*..", "..............{^>:=2:_%%[/,#%,...}**}^[&[,;*$(#,/>&%~~|||:;<;2..", "....}.....!#>:%%%&'2->&%__~~~~_%[)222+[^.{%{..........!(#^+>'*..", "..*22*}#+:___%>^!.)=}....{(^::&%&[]2=~~_%:_>^@{!......}**3>-*...", ".}2222':__:/(.....^|{.......:+/&::+2;[:_~~|||||~~%&>/(2222-~{...", ".}222]%::&,#{!....(|@.}}..!^&:::/();}...!/_,+[%~~||||;;-;2'~....", "..*22-:%%%_%%%:>/##~-*22*3::::,{..:~.....,_.....!(#,>3>[=2'&....", "..}*2*}!(^+&%%_____&*2222):&&/....:~.....+%.........{>[+22:/....", "....[:{......{#/[:%[2222'_%&:[(!..:_.....>&........{>[[=)#|#....", "....[|^...........![*222=~~~~~~_%&%%@!...[[....}}}$>[>%|@/~!....", "....,|>............[<2222^/[%_~~~|~~~__:>:[{..}*22*)>(_~![_.....", "....(~%............+_}*;1...^&@,>:_~~|||||~~_<*2222*1!~_._[.....", "....._~!...........,~.:|,...221...::^/&%_~|||'222222}@|&!~,.....", ".....&|@...........#~!&|/.!/[2%_:>%%....!%>[%*222222*,|/@|(.....", "...../|/...........{~(>|>#:&^'!(^>__~%>,*-)..}222222}>|#,~!.....", ".....(|&...........!~#/|%:^.#%....::(,[&';;[,3*2222*.:~{[%......", ".....!~_...........!:3+|:!..@%....::...#:-)[%~[)**3$.__.%>......", "......:~{..........*22+~:...{_....:[..,:/[!..!#_~%||_~:*';......", "....../|^.........#:=;%~%/@!{_....:[.+:@(~....!_|+!(>~]''2}.....", "......#~>.......(&_[))#~_%~_%%#!..%[>:(.#_....(~~,..,~/[+2......", "......!~:.....!>_:@./%!~_!{^[_~~:*;;'{..^:....#~~#..[~>&/.......", ".......%~!...,%_,...^_._~{..!_(,+';2+>^{,&....,~~{..:~&:>.......", ".......>~(.#:_[{....@~!%~{..!_!.#%+2]~|~_:^{..+~_!.._%&_#.......", ".......3:;3_%#......{~{&~@...&$,%[<3..(,%~||_[&~%..{~:[~{.......", "......}222;^!.......!~([~#..);]%>._+....>+(/:~%~%&)2<'<_........", "......}22;_:+(......._#+~^.(::%&_:_>....[,...!%~:~)222=&........", ".......*22/:__%+(....:,/~,^%%%/.!#___[^!]^...!_~,!)[-2-/........", "........1[#.{/:__%>@.[/^~:%%%^...._/{,:'22@..{_~#./:-):#........", "........{~+....(/%_~%:>3~+-%#....._/...++;_~&>~_{(::+(~!........", ".........%:.......(+%~-2222(......_^..^:$..{,&~_>[:%/^%.........", ".........[_!........}-)222<[#!...._^.(%(...../~%&::~-=<.........", ".........,~(........^]*222&~~_[^!._^{:,......>~&&:&_';2}........", ".........(_,......./_^}}*)+___~~~&%,&>.......&~:%>[_^:2.........", ".........._[.....![%(...&%!#[___~||~%,!......:_::{:&[/..........", "..........&%....!::{....[_!..!^&_<:~||~&^!..!%_:+!_::{..........", "..........,_!..(%&!.....>_{.....!=;'__~||~:1)%_'!{_:>...........", "..........(_#.^_[......./_(.....@_-1,%~__~~)22;2}#_:(...........", "..........!_+^~/........,_@....{%>....{/_~[22222*/_[............", "..........}+=)#.........#_#...!:&........(,*2222*[:#............", "..........*22<^.........(_^...&%!..........}*22**=-}............", "..........}22:~%,!......{_,..>_@............,<1}2;2*............", "...........}}.#&~_>{....!%/.,_,.............&_@.>&2}............", "................([_~&@...%>#_>..............%%{!%+}.............", "..................{+_~:^!:&[:..............!%%!/%{..............", "....................!,_~']+)!..............{%:!%[...............", ".......................#222;(..............@%[/_(...............", "........................*22]~:#............^%>%&................", "........................}**([~|%,!.........,%:_#................", ".............................{>~|~>{.......+%%%.................", "...............................!,_|~&@.....[%%,.................", "..................................^%||%^...::%!.................", "....................................#:||_^):&^..................", "......................................([~<2]+*..................", "........................................!)2222..................", ".........................................}222*..................", "..........................................*2*}..................", "................................................................", "................................................................"}; lightspeed-1.2a.debian.1/src/importobjs.c000066400000000000000000000651501334064775200203720ustar00rootroot00000000000000/* importobjs.c */ /* Imports 3DS/LWO objects to our native format */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* 3D Studio reader routines */ #include "read3ds.h" /* LightWave reader routines */ #define lwPoint point #include "readlwo.h" /* Used by tessellate_object( ) */ struct face_info { int adj_faces[3]; int adj_face_edges[3]; int edgewise : 1; }; /* Forward declarations */ static int import_3ds_file( const char *filename ); static int import_3ds( r3ds_scene *scene ); static int import_lwo_file( const char *filename ); static void generate_normals( ogl_object *obj, int face_type ); static void tessellate_object( ogl_object *obj, int tess ); static unsigned int tessellate_face( ogl_object *obj, struct face_info **facei_list_ptr, int f, int e, unsigned int ind_mid ); static void triangulate_polygon( r3ds_triangle *out_tris, int num_edges, int *indices, point *vertices ); int import_objects( const char *filename ) { int rs = -1; int len; char *file_ext; char *error_str; /* Confirm that the file exists */ if (!file_exists( filename )) { len = strlen( STR_MSG_no_object_file_ARG ) + strlen( filename ) + 16; error_str = xmalloc( len * sizeof(char) ); sprintf( error_str, STR_MSG_no_object_file_ARG, filename ); message_window( STR_DLG_Error, error_str ); xfree( error_str ); return -1; } file_ext = strrchr( filename, '.' ); if (file_ext == NULL) file_ext = ""; /* Dispatch a file loader, based on the file's extension */ if (!strcasecmp( file_ext, ".3DS" )) { if (r3ds_file_is_3ds( filename )) rs = import_3ds_file( filename ); else { message_window( STR_DLG_Error, STR_MSG_not_3ds_file ); return -1; } } else if (!strcasecmp( file_ext, ".PRJ" )) { if (r3ds_file_is_prj( filename )) rs = import_3ds_file( filename ); else { message_window( STR_DLG_Error, STR_MSG_not_prj_file ); return -1; } } else if (!strcasecmp( file_ext, ".LWO" )) { if (lw_is_lwobject( filename )) rs = import_lwo_file( filename ); else { message_window( STR_DLG_Error, STR_MSG_not_lwo_file ); return -1; } } else { /* Looks like we don't have an extension to help us * Try file magic numbers */ if (r3ds_file_is_3ds( filename )) rs = import_3ds_file( filename ); else if (r3ds_file_is_prj( filename )) rs = import_3ds_file( filename ); else if (lw_is_lwobject( filename )) rs = import_lwo_file( filename ); else { /* Whatever it is, we can't read it */ message_window( STR_DLG_Error, STR_MSG_unknown_obj_format ); return -1; } } return rs; } static int import_3ds_file( const char *filename ) { r3ds_scene *scene; /* Load .3DS */ scene = read3ds( filename ); if (scene == NULL) { message_window( STR_DLG_Error, STR_MSG_bad_3ds_file ); return -1; } return import_3ds( scene ); } static int import_3ds( r3ds_scene *scene ) { r3ds_trimesh **trimeshes; r3ds_trimesh *tmesh; ogl_object *obj; point *vert_a, *vert_b, *vert_c; point *tri_cent; point centroid = { 0.0, 0.0, 0.0 }; r3ds_color24 *mat_color24; rgb_color color; float scale_factor; float x0,y0,z0; float x,y,z; float tri_area; float tris_total_area = 0.0; float xmax = -1E6, ymax = -1E6, zmax = -1E6; float xmin = 1E6, ymin = 1E6, zmin = 1E6; int num_trimeshes; int num_bad_trimeshes = 0; int num_vertices; int num_indices; int num_bad_tris; int cur_index; int a,b,c; int o, v, i, t; /* Mike, you have a call */ /* Break objects apart by material * (each ogl_object ultimately has one base color) */ r3ds_split_scene_trimeshes( scene, R3DS_SPLIT_BY_MATERIAL ); /* We can't really handle objects with >1 smoothing group, * so break those apart as necessary */ r3ds_split_scene_trimeshes( scene, R3DS_SPLIT_BY_SMGROUP ); trimeshes = scene->tmeshes; num_trimeshes = scene->num_tmeshes; vehicle_objs = xmalloc( num_trimeshes * sizeof(ogl_object *) ); /* Make model metric (from inches) */ scale_factor = scene->inches_per_unit * 0.0254; /* Now, convert each [good] r3ds_trimesh into an ogl_object */ for (o = 0; o < num_trimeshes; o++) { tmesh = trimeshes[o]; if ((tmesh->num_verts < 3) || (tmesh->num_tris < 1)) { ++num_bad_trimeshes; continue; } /* Material of 1st triangle == material of entire object */ i = tmesh->tris[0].mat_id; if (i >= 0) { mat_color24 = &scene->mats[i].diffuse; color.r = (float)(mat_color24->red) / 255.0; color.g = (float)(mat_color24->green) / 255.0; color.b = (float)(mat_color24->blue) / 255.0; } else { color.r = 0.5; color.g = 0.5; color.b = 0.5; } num_vertices = tmesh->num_verts; num_indices = 3 * tmesh->num_tris; obj = alloc_ogl_object( num_vertices, num_indices ); obj->type = GL_TRIANGLES; obj->color0.r = color.r; obj->color0.g = color.g; obj->color0.b = color.b; for (v = 0; v < num_vertices; v++) { x0 = tmesh->verts[v].x; y0 = tmesh->verts[v].y; z0 = tmesh->verts[v].z; /* Scale object, and rotate to x-axial alignment */ x = - y0 * scale_factor; y = x0 * scale_factor; z = z0 * scale_factor; obj->vertices0[v].x = x; obj->vertices0[v].y = y; obj->vertices0[v].z = z; /* Normals will be taken care of shortly... */ } /* Copy triangles, and at the same time sum up the weighed * triangle centroids to get an overall centroid later on */ cur_index = 0; num_bad_tris = 0; for (t = 0; t < tmesh->num_tris; t++) { a = tmesh->tris[t].a; b = tmesh->tris[t].b; c = tmesh->tris[t].c; vert_a = &obj->vertices0[a]; vert_b = &obj->vertices0[b]; vert_c = &obj->vertices0[c]; tri_cent = calc_tri_centroid( vert_a, vert_b, vert_c ); tri_area = calc_tri_area( vert_a, vert_b, vert_c ); centroid.x += tri_cent->x * tri_area; centroid.y += tri_cent->y * tri_area; centroid.z += tri_cent->z * tri_area; tris_total_area += tri_area; if (tri_area > 1E-8) { obj->indices[cur_index++] = a; obj->indices[cur_index++] = b; obj->indices[cur_index++] = c; } else ++num_bad_tris; /* very VERY tiny triangle */ } if (num_bad_tris > 0) { /* Readjust index array size */ obj->num_indices -= 3 * num_bad_tris; obj->indices = xrealloc( obj->indices, obj->num_indices * sizeof(int) ); } /* No longer need the trimesh * Partially free the big arrays to economize on memory * r3ds_free_scene( ) will finish off the rest, shortly */ tmesh->verts = xrealloc( tmesh->verts, sizeof(r3ds_point) ); if (tmesh->num_tris > 1) tmesh->tris = xrealloc( tmesh->tris, sizeof(r3ds_triangle) ); generate_normals( obj, GL_TRIANGLES ); /* This ogl_object is ready */ vehicle_objs[o - num_bad_trimeshes] = obj; } /* Deallocate scene */ r3ds_free_scene( scene ); num_vehicle_objs = num_trimeshes - num_bad_trimeshes; if (num_vehicle_objs == 0) { message_window( STR_DLG_Error, STR_MSG_empty_3ds_file ); return -1; } /* Calculate centroid */ centroid.x /= tris_total_area; centroid.y /= tris_total_area; centroid.z /= tris_total_area; /* Center the model (make world origin and centroid coincide) */ for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; for (v = 0; v < obj->num_vertices; v++) { obj->vertices0[v].x -= centroid.x; obj->vertices0[v].y -= centroid.y; obj->vertices0[v].z -= centroid.z; /* Update xyz extents */ x = obj->vertices0[v].x; y = obj->vertices0[v].y; z = obj->vertices0[v].z; xmin = MIN(x, xmin); xmax = MAX(x, xmax); ymin = MIN(y, ymin); ymax = MAX(y, ymax); zmin = MIN(z, zmin); zmax = MAX(z, zmax); } } vehicle_extents.xmin = xmin; vehicle_extents.xmax = xmax; vehicle_extents.ymin = ymin; vehicle_extents.ymax = ymax; vehicle_extents.zmin = zmin; vehicle_extents.zmax = zmax; vehicle_extents.avg = ((xmax - xmin) + (ymax - ymin) + (zmax - zmin)) / 3; /* Finally, tessellate the objects so that they deform nicely */ for (o = 0; o < num_vehicle_objs; o++) tessellate_object( vehicle_objs[o], 8 ); return 0; } /* This next importer basically converts a LightWave object into 3DS data using * the same r3ds_build( ) of read3ds. The only additional thing it needs is * a polygon triangulator, as LW objects can have arbitrary n-sided faces */ static int import_lwo_file( const char *filename ) { r3ds_scene *scene; lwObject *lwo; lwFace *face; r3ds_triangle poly_tris_buffer[256]; r3ds_triangle *poly_tris; r3ds_triangle *tri; int abcf[4]; int rgb[3]; float xyz[3]; int num_tris; int num_poly_tris; int mat_id = -1; int i, j; /* Read LWO file */ lwo = lw_object_read( filename ); if (lwo == NULL) { message_window( STR_DLG_Error, STR_MSG_bad_lwo_file ); return -1; } /* Initialize read3ds scene builder */ r3ds_build( R3DS_INITIALIZE, NULL ); /* Input materials */ for (i = 0; i < lwo->material_cnt; i++) { r3ds_build( R3DS_NEW_MATERIAL, lwo->materials[i].name ); r3ds_build( R3DS_MAT_DIFFUSE_COLOR, NULL ); rgb[0] = (int)(lwo->materials[i].r * 255.0); rgb[1] = (int)(lwo->materials[i].g * 255.0); rgb[2] = (int)(lwo->materials[i].b * 255.0); r3ds_build( R3DS_COLOR24, rgb ); } /* Input object mesh */ r3ds_build( R3DS_NEW_OBJECT, filename ); r3ds_build( R3DS_DEF_TRIMESH, NULL ); /* Input vertices */ r3ds_build( R3DS_NUM_VERTS, &lwo->vertex_cnt ); for (i = 0; i < lwo->vertex_cnt; i++) { /* Rotate coordinate system to 3DS standard */ xyz[0] = lwo->vertices[i].x; xyz[1] = - lwo->vertices[i].z; xyz[2] = lwo->vertices[i].y; r3ds_build( R3DS_VERT, xyz ); } /* Count how many triangles there will be */ num_tris = 0; for (i = 0; i < lwo->face_cnt; i++) { face = &lwo->faces[i]; /* (Quickly double-check that the indices are within bounds) */ for (j = 0; j < face->index_cnt; j++) if (face->indices[j] >= lwo->vertex_cnt) face->indices[j] = 0; /* Faces with <3 sides are not faces */ if (face->index_cnt < 3) continue; /* Otherwise, an n-sided polygon will become (n-2) triangles */ num_tris += (face->index_cnt - 2); } r3ds_build( R3DS_NUM_TRIS, &num_tris ); /* Process faces and input triangles */ num_tris = 0; for (i = 0; i < lwo->face_cnt; i++) { face = &lwo->faces[i]; if (face->index_cnt < 3) continue; if (mat_id != face->mat_id) { mat_id = face->mat_id; r3ds_build( R3DS_TRI_MATERIAL_CURRENT, lwo->materials[mat_id].name ); } if (face->index_cnt == 3) { abcf[0] = face->indices[0]; abcf[1] = face->indices[1]; abcf[2] = face->indices[2]; abcf[3] = 0x07; /* Flags: all edges visible */ r3ds_build( R3DS_TRI_FACE, abcf ); r3ds_build( R3DS_TRI_MATERIAL, &num_tris ); ++num_tris; } else { num_poly_tris = face->index_cnt - 2; /* Avoid small malloc()'s at all costs (well, almost) */ if (num_poly_tris <= 256) poly_tris = poly_tris_buffer; else poly_tris = xmalloc( num_poly_tris * sizeof(r3ds_triangle) ); triangulate_polygon( poly_tris, face->index_cnt, face->indices, lwo->vertices ); for (j = 0; j < num_poly_tris; j++) { tri = &poly_tris[j]; abcf[0] = tri->a; abcf[1] = tri->b; abcf[2] = tri->c; abcf[3] = 0x07; r3ds_build( R3DS_TRI_FACE, abcf ); r3ds_build( R3DS_TRI_MATERIAL, &num_tris ); ++num_tris; } if (poly_tris != poly_tris_buffer) xfree( poly_tris ); } } lw_object_free( lwo ); scene = xmalloc( sizeof(r3ds_scene) ); r3ds_build( R3DS_GET_SCENE, scene ); import_3ds( scene ); return 0; } /* Produce normals for an arbitrary triangle or quad mesh * (either is referred to as a generalized "face") */ static void generate_normals( ogl_object *obj, int face_type ) { struct obj_vertex { int num_faces; /* # of faces using this vertex */ point normal_sum; /* Vector sum of normals of said faces */ } *overtices, *overtex; point *plane[3]; point *normal; float x, y, z; float d; int face_size; int num_faces; int num_vertices; int base; int f, v, i; switch (face_type) { case GL_TRIANGLES: face_size = 3; break; case GL_QUADS: face_size = 4; break; default: #ifdef DEBUG crash( "generate_normals( ): invalid face type" ); #endif return; } num_faces = obj->num_indices / face_size; num_vertices = obj->num_vertices; overtices = xmalloc( num_vertices * sizeof(struct obj_vertex) ); /* Initialize vertex records */ for (v = 0; v < num_vertices; v++) { overtex = &overtices[v]; overtex->num_faces = 0; overtex->normal_sum.x = 0.0; overtex->normal_sum.y = 0.0; overtex->normal_sum.z = 0.0; } /* Step 1: Get vector sum of [face] normals for each vertex */ for (f = 0; f < num_faces; f++) { base = f * face_size; /* # of first index describing face */ /* Calculate face normal (need only 3 points for this) */ for (v = 0; v < 3; v++) { i = obj->indices[base + v]; plane[v] = &obj->vertices0[i]; } normal = calc_tri_normal( plane[0], plane[1], plane[2] ); /* Update the 3 or 4 involved vertices */ for (v = 0; v < face_size; v++) { i = obj->indices[base + v]; overtex = &overtices[i]; ++overtex->num_faces; overtex->normal_sum.x += normal->x; overtex->normal_sum.y += normal->y; overtex->normal_sum.z += normal->z; } } /* Step 2: Vertex normal = normalized sum of associated face normals */ for (v = 0; v < num_vertices; v++) { overtex = &overtices[v]; x = overtex->normal_sum.x; y = overtex->normal_sum.y; z = overtex->normal_sum.z; d = sqrt( SQR(x) + SQR(y) + SQR(z) ); if (d < 1E-6) d = 1.0; obj->normals0[v].x = x / d; obj->normals0[v].y = y / d; obj->normals0[v].z = z / d; } xfree( overtices ); } /* This reduces the face edge size (in the yz-plane) of a GL_TRIANGLES object * to below a certain threshold specified by tess (1/tess times the y- and * z-extents), with the exception that any edges shared between faces mostly * edgewise to the yz-plane are not split. This is what keeps, for example, * the tops and sides of a cube from being as heavily tessellated as the front * and back * NOTE: tess must be a power of 2 */ static void tessellate_object( ogl_object *obj, int tess ) { struct edge_info { /* Offset into edgei_list == ind_a */ unsigned int ind_b; int face; int edge; struct edge_info *next; } **edgei_list, *prev_edgei, *edgei; struct face_info *facei_list; struct face_info *facei, *facei_adj, *facei_new, *facei_adj_new; point *vert_a, *vert_b; point *p[3], *norm; float max_ylen, max_zlen; float long_ylen = 0.0, long_zlen = 0.0; float yzlen2, long_yzlen2; float dy, dz; unsigned int ind_a, ind_b, ind_c, ind_d, ind_mid; unsigned int a, b, i; int num_faces_orig; int num_faces; int tess_level; int base, base_adj; int f, f_adj, f_new, f_adj_new; int e, e_adj, e_long; int v; #ifdef DEBUG printf( "Tessellating object..." ); fflush( stdout ); #endif num_faces_orig = obj->num_indices / 3; num_faces = num_faces_orig; /* Initialize face info list */ facei_list = xmalloc( num_faces * sizeof(struct face_info) ); for (f = 0; f < num_faces; f++) { facei = &facei_list[f]; /* No adjacent faces (yet) */ for (e = 0; e < 3; e++) { facei->adj_faces[e] = -1; facei->adj_face_edges[e] = -1; } /* Check x-component of face normal to see if face is * edgewise to the yz-plane or not */ base = 3 * f; for (v = 0; v < 3; v++) { i = obj->indices[base + v]; p[v] = &obj->vertices0[i]; } norm = calc_tri_normal( p[0], p[1], p[2] ); if (ABS(norm->x) < 0.125) facei->edgewise = TRUE; /* Edgewise */ else facei->edgewise = FALSE; /* Not edgewise */ } /* Initialize edge info list */ edgei_list = xmalloc( obj->num_vertices * sizeof(struct edge_info *) ); for (e = 0; e < obj->num_vertices; e++) edgei_list[e] = NULL; /* Find all face adjacencies by searching for coincident edges */ for (f = 0; f < num_faces; f++) { base = 3 * f; for (e = 0; e < 3; e++) { a = obj->indices[base + e]; b = obj->indices[base + ((e + 1) % 3)]; ind_a = MIN(a, b); ind_b = MAX(a, b); /* Search for matching edge */ prev_edgei = NULL; edgei = edgei_list[ind_a]; while (edgei != NULL) { if (edgei->ind_b == ind_b) break; /* found */ else { prev_edgei = edgei; edgei = edgei->next; /* check next one */ } } if (edgei != NULL) { /* Coincident edge found; update adjacency info */ f_adj = edgei->face; e_adj = edgei->edge; /* First face */ facei = &facei_list[f]; facei->adj_faces[e] = f_adj; facei->adj_face_edges[e] = e_adj; /* Second face */ facei_adj = &facei_list[f_adj]; facei_adj->adj_faces[e_adj] = f; facei_adj->adj_face_edges[e_adj] = e; /* and free edge record * (b/c at most two faces can share an edge) * (barring bad geometry, anyway) */ if (prev_edgei != NULL) prev_edgei->next = edgei->next; else edgei_list[ind_a] = edgei->next; xfree( edgei ); } else { /* Add new edge record */ edgei = xmalloc( sizeof(struct edge_info) ); edgei->ind_b = ind_b; edgei->face = f; edgei->edge = e; edgei->next = NULL; if (prev_edgei != NULL) prev_edgei->next = edgei; else edgei_list[ind_a] = edgei; } } } /* Free the edge info list, no longer need it */ for (v = 0; v < obj->num_vertices; v++) { edgei = edgei_list[v]; while (edgei != NULL) { prev_edgei = edgei; edgei = edgei->next; xfree( prev_edgei ); } } xfree( edgei_list ); /* Perform tessellation incrementally, reducing threshold size * one step at a time (else we get non-clean results) */ for (tess_level = 2; tess_level <= tess; tess_level *= 2) { max_ylen = 1.01 * (vehicle_extents.ymax - vehicle_extents.ymin) / (float)tess_level; max_zlen = 1.01 * (vehicle_extents.zmax - vehicle_extents.zmin) / (float)tess_level; for (f = 0; f < num_faces; f++) { /* Find which edge is most eligible to be split. This * is the longest one, as measured in the yz-plane, * that is not shared between two edgewise faces */ facei = &facei_list[f]; base = 3 * f; e_long = -1; long_yzlen2 = -1.0; for (e = 0; e < 3; e++) { /* First, check for exception case */ f_adj = facei->adj_faces[e]; if (f_adj >= 0) { facei_adj = &facei_list[f_adj]; if (facei->edgewise && facei_adj->edgewise) { /* Both faces are edgewise * This edge must not be split */ continue; } } a = obj->indices[base + e]; b = obj->indices[base + ((e + 1) % 3)]; ind_a = MIN(a, b); ind_b = MAX(a, b); vert_a = &obj->vertices0[ind_a]; vert_b = &obj->vertices0[ind_b]; dy = ABS(vert_a->y - vert_b->y); dz = ABS(vert_a->z - vert_b->z); yzlen2 = SQR(dy) + SQR(dz); if (yzlen2 > long_yzlen2) { e_long = e; long_ylen = dy; long_zlen = dz; long_yzlen2 = yzlen2; } } if (e_long == -1) continue; /* Can't split this face */ /* See if long edge doesn't exceed split threshold */ if ((long_ylen <= max_ylen) && (long_zlen <= max_zlen)) continue; /* Tessellate the face and update face info */ ind_mid = tessellate_face( obj, &facei_list, f, e_long, 0 ); facei = &facei_list[f]; /* facei_list might have moved! */ f_new = num_faces; ++num_faces; /* If another face is sharing the same [long] edge, * tessellate it too */ f_adj = facei->adj_faces[e_long]; if (f_adj >= 0) { base_adj = 3 * f_adj; e_adj = facei->adj_face_edges[e_long]; tessellate_face( obj, &facei_list, f_adj, e_adj, ind_mid ); facei = &facei_list[f]; f_adj_new = num_faces; ++num_faces; /* Check for crossed adjacencies */ a = obj->indices[base + e_long]; b = obj->indices[base + ((e_long + 1) % 3)]; ind_a = MIN(a, b); ind_b = MAX(a, b); a = obj->indices[base_adj + e_adj]; b = obj->indices[base_adj + ((e_adj + 1) % 3)]; ind_c = MIN(a, b); ind_d = MAX(a, b); if ((ind_a == ind_c) && (ind_b == ind_d)) { /* The old faces are adjacent-- * this shouldn't happen! * (means the normals disagree, often * the case with sloppy geometry) */ facei_new = &facei_list[f_new]; facei_adj_new = &facei_list[f_adj_new]; /* Correct adjacencies of the new faces */ facei_new->adj_faces[e_long] = f_adj_new; facei_adj_new->adj_faces[e_adj] = f_new; } else { /* The old and new faces are staggered * (as they should be) */ facei_adj = &facei_list[f_adj]; /* Correct adjacencies of the old faces */ facei->adj_faces[e_long] = f_adj_new; facei_adj->adj_faces[e_adj] = f_new; } } /* Might have to split current face again */ --f; } } xfree( facei_list ); #ifdef DEBUG printf( "done. (%d face splits)\n", num_faces - num_faces_orig ); fflush( stdout ); #endif } /* Turns a specified face (f) in an object into two, bisecting the specified * edge (e), using the specified midpoint vertex (ind_mid) if it is >0 * Note: edges are numbered 0-2, *not* on basis of opposite vertex but in * same order as vertex enumeration */ static unsigned int tessellate_face( ogl_object *obj, struct face_info **facei_list_ptr, int f, int e, unsigned int ind_mid ) { struct face_info *facei, *facei_new; struct face_info *facei_other; point *vert_a, *vert_b; point *norm_a, *norm_b; point *vert_mid, *norm_mid; unsigned int ind_a, ind_b; unsigned int ind_split, ind_move; int num_faces0; int base, base_new; int v_split, v_move, v_third; int f_other, e_other; int n; num_faces0 = obj->num_indices / 3; /* this value will not be incremented */ base = 3 * f; /* A value of 0 for index_mid means no midpoint vertex exists * Thus we create it here */ if (ind_mid == 0) { /* Indices of endpoints and new midpoint vertex */ ind_a = obj->indices[base + e]; ind_b = obj->indices[base + ((e + 1) % 3)]; ind_mid = obj->num_vertices; /* Add new vertex and normal */ ++obj->num_vertices; n = obj->num_vertices; obj->vertices0 = xrealloc( obj->vertices0, n * sizeof(point) ); obj->normals0 = xrealloc( obj->normals0, n * sizeof(point) ); obj->iarrays = xrealloc( obj->iarrays, n * sizeof(ogl_point) ); /* New vertex location (midpoint of long edge) */ vert_a = &obj->vertices0[ind_a]; vert_b = &obj->vertices0[ind_b]; vert_mid = &obj->vertices0[ind_mid]; vert_mid->x = (vert_a->x + vert_b->x) / 2.0; vert_mid->y = (vert_a->y + vert_b->y) / 2.0; vert_mid->z = (vert_a->z + vert_b->z) / 2.0; /* New vertex normal (average of endpoint normals) */ norm_a = &obj->normals0[ind_a]; norm_b = &obj->normals0[ind_b]; norm_mid = &obj->normals0[ind_mid]; norm_mid->x = (norm_a->x + norm_b->x) / 2.0; norm_mid->y = (norm_a->y + norm_b->y) / 2.0; norm_mid->z = (norm_a->z + norm_b->z) / 2.0; } /* # and index of vertex from which split begins * (i.e. the vertex opposite the bisected edge) */ v_split = (e + 2) % 3; ind_split = obj->indices[base + v_split]; /* # and index of vertex to move to midpoint of long edge */ v_move = e; ind_move = obj->indices[base + v_move]; /* # of the other (third) vertex */ v_third = (e + 1) % 3; /* First triangle half (modify original face) */ obj->indices[base + v_move] = ind_mid; /* Second triangle half (create new face) */ base_new = obj->num_indices; obj->num_indices += 3; obj->indices = xrealloc( obj->indices, obj->num_indices * sizeof(unsigned int) ); obj->indices[base_new + v_split] = ind_split; obj->indices[base_new + v_move] = ind_move; obj->indices[base_new + v_third] = ind_mid; /* Make new entry in the face info list, and update the adjacencies */ *facei_list_ptr = xrealloc( *facei_list_ptr, (num_faces0 + 1) * sizeof(struct face_info) ); facei = &(*facei_list_ptr)[f]; facei_new = &(*facei_list_ptr)[num_faces0]; memcpy( facei_new, facei, sizeof(struct face_info) ); /* The old face is next to the new face... */ facei->adj_faces[v_split] = num_faces0; facei->adj_face_edges[v_split] = v_third; /* ...and the new face is next to the old face */ facei_new->adj_faces[v_third] = f; facei_new->adj_face_edges[v_third] = v_split; /* If the new face has a neighbor (that isn't sharing the splitted edge), * it will need updating too */ f_other = facei_new->adj_faces[v_split]; if (f_other >= 0) { e_other = facei_new->adj_face_edges[v_split]; facei_other = &(*facei_list_ptr)[f_other]; facei_other->adj_faces[e_other] = num_faces0; /* facei_other->adj_face_edges[e_other] = v_split; */ /* (last line unnecessary, by splitting convention used) */ } return ind_mid; } /* Simple polygon triangulator, should be able to handle anything save for * self-intersecting faces (garbage_in == garbage_out) */ /* TODO: Still buggy, FIX THIS!!! */ static void triangulate_polygon( r3ds_triangle *out_tris, int num_edges, int *indices, point *vertices ) { r3ds_triangle *tri; extents ext = { 1E6, -1E6, 1E6, -1E6, 1E6, -1E6, NIL }; float x, y, z; int indices2_buffer[256]; int *indices2; int index_xmax_num = 0, index_ymax_num = 0, index_zmax_num = 0; int ind, index_num; int i, j; /* Find face extents, and indices of extrema */ for (i = 0; i < num_edges; i++) { ind = indices[i]; x = vertices[ind].x; y = vertices[ind].y; z = vertices[ind].z; if (x < ext.xmin) ext.xmin = x; if (x > ext.xmax) { ext.xmax = x; index_xmax_num = i; } if (y < ext.ymin) ext.ymin = y; if (y > ext.ymax) { ext.ymax = y; index_ymax_num = i; } if (z < ext.zmin) ext.zmin = z; if (z > ext.zmax) { ext.zmax = z; index_zmax_num = i; } } /* Determine first vertex of triangle based on pricipal face alignment */ x = ext.xmax - ext.xmin; y = ext.ymax - ext.ymin; z = ext.zmax - ext.zmin; index_num = index_xmax_num; if (y > x) index_num = index_ymax_num; if ((z > x) && (z > y)) index_num = index_zmax_num; /* Create one output triangle, now knowing that index_num references * a convex vertex of the polygon */ tri = &out_tris[0]; tri->a = indices[index_num]; tri->b = indices[(index_num + 1) % num_edges]; tri->c = indices[(index_num - 1 + num_edges) % num_edges]; /* and recurse if there are more to do */ if (num_edges > 3) { if (num_edges <= 256) indices2 = indices2_buffer; else indices2 = xmalloc( (num_edges - 1) * sizeof(int) ); j = 0; for (i = 0; i < num_edges; i++) if (i != index_num) indices2[j++] = indices[i]; triangulate_polygon( &out_tris[1], num_edges - 1, indices2, vertices ); if (indices2 != indices2_buffer) xfree( indices2 ); } } /* end importobjs.c */ lightspeed-1.2a.debian.1/src/infodisp.c000066400000000000000000000071211334064775200200070ustar00rootroot00000000000000/* infodisp.c */ /* Graphical text information display ("HUD") */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Info display control */ void info_display( int message1, int message2 ) { static int disp_anything = DEF_INFODISP_ACTIVE; static int disp_velocity = DEF_INFODISP_SHOW_VELOCITY; static int disp_time_t = DEF_INFODISP_SHOW_TIME_T; static int disp_gamma = DEF_INFODISP_SHOW_GAMMA; static int disp_framerate = DEF_INFODISP_SHOW_FRAMERATE; int no_contract; int no_deform; int no_headlight; int no_doppler; char disp_str[64]; switch (message1) { case INFODISP_DRAW: if (disp_anything) break; else return; case INFODISP_ACTIVE: disp_anything = message2; queue_redraw( 0 ); return; case INFODISP_SHOW_VELOCITY: disp_velocity = message2; goto dd_redraw; case INFODISP_SHOW_TIME_T: disp_time_t = message2; goto dd_redraw; case INFODISP_SHOW_GAMMA: disp_gamma = message2; goto dd_redraw; case INFODISP_SHOW_FRAMERATE: disp_framerate = message2; goto dd_redraw; case RESET: dd_redraw: if (disp_anything) { /* Info in display has changed in some way */ queue_redraw( 0 ); } return; default: #ifdef DEBUG crash( "info_display( ): invalid message" ); #endif return; } /* Z-buffer no good for 2D drawing, lighting likewise */ glDisable( GL_DEPTH_TEST ); glDisable( GL_LIGHTING ); if (disp_velocity) { sprintf( disp_str, gettext(STR_INF_velocity_ARG), velocity_string( velocity, TRUE ) ); ogl_draw_string( disp_str, POS_BOTTOM_LEFT, 2 ); } if (disp_time_t) { sprintf( disp_str, gettext(STR_INF_time_ARG), time_string( ) ); ogl_draw_string( disp_str, POS_TOP_LEFT, 2 ); } if (disp_gamma) { sprintf( disp_str, gettext(STR_INF_gamma_ARG), lorentz_factor( velocity ) ); ogl_draw_string( disp_str, POS_BOTTOM_RIGHT, 1 ); } /* Get status of each of the warp transforms */ no_contract = !warp( QUERY, MESG_(WARP_LORENTZ_CONTRACTION) ); no_deform = !warp( QUERY, MESG_(WARP_OPTICAL_DEFORMATION) ); no_headlight = !warp( QUERY, MESG_(WARP_HEADLIGHT_EFFECT) ); no_doppler = !warp( QUERY, MESG_(WARP_DOPPLER_SHIFT) ); if (no_contract && no_doppler && no_headlight && no_deform) ogl_draw_string( gettext(STR_INF_no_relativity), POS_TOP_RIGHT, 1 ); else { if (no_contract) ogl_draw_string( gettext(STR_INF_no_contraction), POS_TOP_RIGHT, 0 ); if (no_doppler) ogl_draw_string( gettext(STR_INF_no_doppler_shift), POS_TOP_RIGHT, 0 ); if (no_headlight) ogl_draw_string( gettext(STR_INF_no_headlight_effect), POS_TOP_RIGHT, 0 ); if (no_deform) ogl_draw_string( gettext(STR_INF_no_deformation), POS_TOP_RIGHT, 0 ); } if (disp_framerate) { sprintf( disp_str, gettext(STR_INF_fps_ARG), framerate ); ogl_draw_string( disp_str, POS_TOP_RIGHT, 0 ); } glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); } /* end infodisp.c */ lightspeed-1.2a.debian.1/src/lattice.c000066400000000000000000000366741334064775200176400ustar00rootroot00000000000000/* lattice.c */ /* Lattice generator */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Forward declarations */ static void add_ball( ogl_object *parent_obj, float x0, float y0, float z0, int smoothness ); static void add_stick( ogl_object *parent_obj, float arg1, float arg2, float arg3, float arg4, int num_segs, int smoothness, int alignment ); static int add_point( ogl_object *obj, float x, float y, float z, float normal_x, float normal_y, float normal_z ); static void add_index( ogl_object *obj, int index ); /* Creates a 3D lattice of specified size, with sticks properly segmented * in the y and z directions for our purposes (i.e. these will be bent) */ void make_lattice( int size_x, int size_y, int size_z, int smoothness ) { ogl_object *lattice_balls; ogl_object *lattice_sticks; ogl_object dummy; float xc, yc, zc; float x, y, z; float sign = 1.0; int nodes_x, nodes_y, nodes_z; int num_balls, num_sticks; int segs_x, segs_y, segs_z; int num_vertices, num_indices; int i, j, k; int i_inc, j_inc, k_inc; #ifdef DEBUG printf( "Building %dx%dx%d/%d lattice...", size_x, size_y, size_z, smoothness ); fflush( stdout ); #endif nodes_x = size_x + 1; nodes_y = size_y + 1; nodes_z = size_z + 1; /* Half the size of each lattice dimension * (disregarding radii of sticks/balls) */ xc = LATTICE_UNIT_SIZE * (float)size_x / 2; yc = LATTICE_UNIT_SIZE * (float)size_y / 2; zc = LATTICE_UNIT_SIZE * (float)size_z / 2; /* NODE BALLS */ /* Determine how many vertices/indices the balls will need */ dummy.type = -1; dummy.num_vertices = 0; dummy.num_indices = 0; add_ball( &dummy, 0, 0, 0, smoothness ); num_balls = nodes_x * nodes_y * nodes_z; num_vertices = num_balls * dummy.num_vertices; num_indices = num_balls * dummy.num_indices; lattice_balls = alloc_ogl_object( num_vertices, num_indices ); lattice_balls->type = GL_QUAD_STRIP; lattice_balls->color0.r = BALL_R; lattice_balls->color0.g = BALL_G; lattice_balls->color0.b = BALL_B; lattice_balls->num_vertices = 0; lattice_balls->num_indices = 0; /* Make the balls */ /* j and k are in "ping-pong" loops */ j = 0; k = 0; j_inc = 1; k_inc = 1; for (i = 0; i < nodes_x; i++) { for (; (j < nodes_y) && (j >= 0); j += j_inc) { for (; (k < nodes_z) && (k >= 0); k += k_inc) { x = LATTICE_UNIT_SIZE * (float)i - xc; y = LATTICE_UNIT_SIZE * (float)j - yc; z = LATTICE_UNIT_SIZE * (float)k - zc; add_ball( lattice_balls, x, y, z, smoothness ); } k -= k_inc; k_inc = - k_inc; } j -= j_inc; j_inc = - j_inc; } #ifdef DEBUG if (lattice_balls->num_vertices != num_vertices) printf( "ERROR: Lattice balls vertices: %d expected, %d actual\n", num_vertices, lattice_balls->num_vertices ); if (lattice_balls->num_indices != num_indices) printf( "ERROR: Lattice balls indices: %d expected, %d actual\n", num_indices, lattice_balls->num_indices ); fflush( stdout ); #endif /* INTERCONNECTING STICKS */ /* Number of segments along segmented y- & z-axis-aligned sticks */ segs_x = size_x * 2; segs_y = size_y * smoothness; segs_z = size_z * smoothness; /* Determine how many vertices/indices the sticks will need */ num_vertices = 0; num_indices = 0; dummy.type = -1; /* x-aligned sticks */ dummy.num_vertices = 0; dummy.num_indices = 0; add_stick( &dummy, 0, 0, 0, 0, segs_x, smoothness, X_ALIGN ); num_sticks = nodes_y * nodes_z; num_vertices += num_sticks * dummy.num_vertices; num_indices += num_sticks * dummy.num_indices; /* y-aligned sticks */ dummy.num_vertices = 0; dummy.num_indices = 0; add_stick( &dummy, 0, 0, 0, 0, segs_y, smoothness, Y_ALIGN ); num_sticks = nodes_z * nodes_x; num_vertices += num_sticks * dummy.num_vertices; num_indices += num_sticks * dummy.num_indices; /* z-aligned sticks */ dummy.num_vertices = 0; dummy.num_indices = 0; add_stick( &dummy, 0, 0, 0, 0, segs_z, smoothness, Z_ALIGN ); num_sticks = nodes_x * nodes_y; num_vertices += num_sticks * dummy.num_vertices; num_indices += num_sticks * dummy.num_indices; lattice_sticks = alloc_ogl_object( num_vertices, num_indices ); lattice_sticks->type = GL_QUAD_STRIP; lattice_sticks->color0.r = STICK_R; lattice_sticks->color0.g = STICK_G; lattice_sticks->color0.b = STICK_B; lattice_sticks->num_vertices = 0; lattice_sticks->num_indices = 0; /* Make the sticks */ /* Make the x-aligned sticks */ k = 0; k_inc = 1; for (j = 0; j < nodes_y; j++) { y = LATTICE_UNIT_SIZE * (float)j - yc; for (; (k < nodes_z) && (k >= 0); k += k_inc) { z = LATTICE_UNIT_SIZE * (float)k - zc; add_stick( lattice_sticks, - sign * xc, sign * xc, y, z, segs_x, smoothness, X_ALIGN ); sign = - sign; } k -= k_inc; k_inc = - k_inc; } /* Make the y-aligned sticks */ if (sign < 0) { i = 0; i_inc = 1; } else { i = nodes_x - 1; i_inc = -1; } sign = -1.0; /* as j_inc == 1 */ for (; (k < nodes_z) && (k >= 0); k += k_inc) { z = LATTICE_UNIT_SIZE * (float)k - zc; for (; (i < nodes_x) && (i >= 0); i += i_inc) { x = LATTICE_UNIT_SIZE * (float)i - xc; add_stick( lattice_sticks, x, - sign * yc, sign * yc, z, segs_y, smoothness, Y_ALIGN ); sign = - sign; } i -= i_inc; i_inc = - i_inc; } /* Make the z-aligned sticks */ if (sign > 0) { j = 0; j_inc = 1; } else { j = nodes_y - 1; j_inc = -1; } sign = (float)k_inc; for (; (i < nodes_x) && (i >= 0); i += i_inc) { x = LATTICE_UNIT_SIZE * (float)i - xc; for (; (j < nodes_y) && (j >= 0); j += j_inc) { y = LATTICE_UNIT_SIZE * (float)j - yc; add_stick( lattice_sticks, x, y, - sign * zc, sign * zc, segs_z, smoothness, Z_ALIGN ); sign = - sign; } j -= j_inc; j_inc = - j_inc; } #ifdef DEBUG if (lattice_sticks->num_vertices != num_vertices) printf( "ERROR: Lattice sticks vertices: %d expected, %d actual\n", num_vertices, lattice_sticks->num_vertices ); if (lattice_sticks->num_indices != num_indices) printf( "ERROR: Lattice sticks indices: %d expected, %d actual\n", num_indices, lattice_sticks->num_indices ); fflush( stdout ); #endif vehicle_objs = xmalloc( 2 * sizeof(ogl_object *) ); vehicle_objs[0] = lattice_balls; vehicle_objs[1] = lattice_sticks; num_vehicle_objs = 2; /* Define dimensional extents */ xc += BALL_RADIUS; yc += BALL_RADIUS; zc += BALL_RADIUS; vehicle_extents.xmin = - xc; vehicle_extents.xmax = xc; vehicle_extents.ymin = - yc; vehicle_extents.ymax = yc; vehicle_extents.zmin = - zc; vehicle_extents.zmax = zc; vehicle_extents.avg = 2 * (xc + yc + zc) / 3; #ifdef DEBUG printf( "done (%db+%ds vertices, %db+%ds indices).\n", lattice_balls->num_vertices, lattice_sticks->num_vertices, lattice_balls->num_indices, lattice_sticks->num_indices ); fflush( stdout ); #endif } static void add_ball( ogl_object *parent_obj, float x0, float y0, float z0, int smoothness ) { float theta; float phi; float x, y, z; int p, t; int range_t, range_p; int center_v, pole_v, begin_v = 0; int obj_v; range_t = smoothness; range_p = 2 * smoothness; /* Center vertex */ center_v = add_point( parent_obj, x0, y0, z0, 0.0, 0.0, -1.0 ); add_index( parent_obj, center_v ); add_index( parent_obj, center_v ); /* Front of ball (North Pole to Arctic Circle) */ /* Pole vertex */ pole_v = add_point( parent_obj, x0 + BALL_RADIUS, y0, z0, 1.0, 0.0, 0.0 ); theta = RAD(90.0 - 180.0 / (float)range_t); x = BALL_RADIUS * sin( theta ); for (p = 0; p < range_p; p++) { phi = RAD(360.0 * (float)p / (float)range_p); y = BALL_RADIUS * cos( theta ) * cos( phi ); z = BALL_RADIUS * cos( theta ) * sin( phi ); obj_v = add_point( parent_obj, x0 + x, y0 + y, z0 + z, x, y, z ); add_index( parent_obj, pole_v ); add_index( parent_obj, obj_v ); if (p == 0) begin_v = obj_v; } /* Complete the circle */ add_index( parent_obj, pole_v ); add_index( parent_obj, begin_v ); /* Midsection of ball (Arctic Circle to Antarctic Circle) */ for (t = 2; t < range_t; t++) { theta = RAD(90.0 - 180.0 * (float)t / (float)range_t); x = BALL_RADIUS * sin( theta ); for (p = 0; p < range_p; p++) { phi = RAD(360.0 * (float)p / (float)range_p); y = BALL_RADIUS * cos( theta ) * cos( phi ); z = BALL_RADIUS * cos( theta ) * sin( phi ); obj_v = add_point( parent_obj, x0 + x, y0 + y, z0 + z, x, y, z ); add_index( parent_obj, obj_v - range_p ); add_index( parent_obj, obj_v ); if (p == 0) begin_v = obj_v; } /* Complete the circle */ add_index( parent_obj, begin_v - range_p ); add_index( parent_obj, begin_v ); } /* Back of ball (Antarctic Circle to South Pole) */ /* Pole vertex */ pole_v = add_point( parent_obj, x0 - BALL_RADIUS, y0, z0, -1.0, 0.0, 0.0 ); theta = RAD(180.0 / (float)range_t - 90.0); x = BALL_RADIUS * sin( theta ); for (p = 0; p < range_p; p++) { phi = RAD(360.0 * (float)p / (float)range_p); y = BALL_RADIUS * cos( theta ) * cos( phi ); z = BALL_RADIUS * cos( theta ) * sin( phi ); obj_v = add_point( parent_obj, x0 + x, y0 + y, z0 + z, x, y, z ); add_index( parent_obj, obj_v ); add_index( parent_obj, pole_v ); if (p == 0) begin_v = obj_v; } /* Once more, complete the circle */ add_index( parent_obj, begin_v ); add_index( parent_obj, pole_v ); /* and tie quad strip back to center */ add_index( parent_obj, center_v ); add_index( parent_obj, center_v ); } static void add_stick( ogl_object *parent_obj, float arg1, float arg2, float arg3, float arg4, int num_segs, int smoothness, int alignment ) { float phi; float a0, a1, b0, c0; float a, b, c; float x0, y0, z0; float xn, yn, zn; float x, y, z; int s, p; int range_p; int reverse = FALSE; int end_v, begin_v = 0; int obj_v; /* Interpret args differently depending on alignment */ switch (alignment) { case X_ALIGN: a0 = arg1; a1 = arg2; b0 = arg3; c0 = arg4; break; case Y_ALIGN: b0 = arg1; a0 = - arg2; a1 = - arg3; c0 = arg4; break; case Z_ALIGN: c0 = arg1; b0 = arg2; a0 = - arg3; a1 = - arg4; break; default: #ifdef DEBUG crash( "add_stick( ): invalid alignment" ); #endif return; } range_p = 2 * smoothness; if (a0 > a1) reverse = TRUE; /* to keep the normals right */ /* Endcap vertex (tie point) */ rotate_xyz( alignment, &x0, &y0, &z0, a0, b0, c0 ); end_v = add_point( parent_obj, x0, y0, z0, 0.0, 0.0, -1.0 ); add_index( parent_obj, end_v ); add_index( parent_obj, end_v ); for (s = 0; s <= num_segs; s++) { a = (a1 - a0) * (float)s / (float)num_segs; for (p = 0; p < range_p; p++) { phi = RAD(360.0 * (float)p / (float)range_p); b = STICK_RADIUS * cos( phi ); c = STICK_RADIUS * sin( phi ); rotate_xyz( alignment, &x, &y, &z, a, b, c ); rotate_xyz( alignment, &xn, &yn, &zn, 0, b, c ); obj_v = add_point( parent_obj, x0 + x, y0 + y, z0 + z, xn, yn, zn ); if (s > 0) { if (reverse) { add_index( parent_obj, obj_v - range_p ); add_index( parent_obj, obj_v ); } else { add_index( parent_obj, obj_v ); add_index( parent_obj, obj_v - range_p ); } } if (p == 0) begin_v = obj_v; } if (s == 0) continue; /* Complete the circle */ if (reverse) { add_index( parent_obj, begin_v - range_p ); add_index( parent_obj, begin_v ); } else { add_index( parent_obj, begin_v ); add_index( parent_obj, begin_v - range_p ); } } /* The other endcap vertex (tie point) */ rotate_xyz( alignment, &x, &y0, &z0, a1, b0, c0 ); end_v = add_point( parent_obj, x, y0, z0, 0.0, 0.0, -1.0 ); add_index( parent_obj, end_v ); add_index( parent_obj, end_v ); } static int add_point( ogl_object *obj, float x, float y, float z, float norm_x, float norm_y, float norm_z ) { float d; int v; v = obj->num_vertices; if (obj->type != -1) { /* Set vertex location */ obj->vertices0[v].x = x; obj->vertices0[v].y = y; obj->vertices0[v].z = z; /* Normalize and set vertex normal */ d = sqrt( SQR(norm_x) + SQR(norm_y) + SQR(norm_z) ); if (d < 1E-6) d = 1.0; obj->normals0[v].x = norm_x / d; obj->normals0[v].y = norm_y / d; obj->normals0[v].z = norm_z / d; } ++obj->num_vertices; return v; } static void add_index( ogl_object *obj, int index ) { int i; i = obj->num_indices++; if (obj->type != -1) obj->indices[i] = index; } #ifdef WITH_SRS_EXPORTER void write_srs_lattice( FILE *srs ) { point p1, p2; point p1_srs, p2_srs; rgb_color color; float xc,yc,zc; float x0,y0,z0; int i,j,k; /* Centering translation */ xc = (float)lattice_size_x * LATTICE_UNIT_SIZE / 2.0; yc = (float)lattice_size_y * LATTICE_UNIT_SIZE / 2.0; zc = (float)lattice_size_z * LATTICE_UNIT_SIZE / 2.0; i = lattice_size_x; j = lattice_size_y; k = lattice_size_z; fprintf( srs, "\t// **** Begin %dx%dx%d lattice definition ****\n", i, j, k ); fprintf( srs, "\tunion { // ** Balls **\n" ); /* Make the balls */ for (i = 0; i <= lattice_size_x; i++) { x0 = (float)i * LATTICE_UNIT_SIZE - xc; p1.x = x0; for (j = 0; j <= lattice_size_y; j++) { y0 = (float)j * LATTICE_UNIT_SIZE - yc; p1.y = y0; for (k = 0; k <= lattice_size_z; k++) { z0 = (float)k * LATTICE_UNIT_SIZE - zc; p1.z = z0; convert_to_srs_cs( &p1_srs, &p1 ); write_srs_sphere( srs, &p1_srs, BALL_RADIUS ); } } } /* Ball material */ color.r = BALL_R; color.g = BALL_G; color.b = BALL_B; write_srs_pigment( srs, &color ); fprintf( srs, "\t}\n" ); fprintf( srs, "\tunion { // ** Sticks **\n" ); /* Make x-sticks */ for (j = 0; j <= lattice_size_y; j++) { y0 = (float)j * LATTICE_UNIT_SIZE - yc; p1.y = y0; p2.y = y0; for (k = 0; k <= lattice_size_z; k++) { z0 = (float)k * LATTICE_UNIT_SIZE - zc; p1.x = xc; p1.z = z0; convert_to_srs_cs( &p1_srs, &p1 ); p2.x = - xc; p2.z = z0; convert_to_srs_cs( &p2_srs, &p2 ); write_srs_cylinder( srs, &p1_srs, &p2_srs, STICK_RADIUS ); } } /* Make y-sticks */ for (i = 0; i <= lattice_size_x; i++) { x0 = (float)i * LATTICE_UNIT_SIZE - xc; p1.x = x0; p2.x = x0; for (k = 0; k <= lattice_size_z; k++) { z0 = (float)k * LATTICE_UNIT_SIZE - zc; p1.y = yc; p1.z = z0; convert_to_srs_cs( &p1_srs, &p1 ); p2.y = - yc; p2.z = z0; convert_to_srs_cs( &p2_srs, &p2 ); write_srs_cylinder( srs, &p1_srs, &p2_srs, STICK_RADIUS ); } } /* Make z-sticks */ for (i = 0; i <= lattice_size_x; i++) { x0 = (float)i * LATTICE_UNIT_SIZE - xc; p1.x = x0; p2.x = x0; for (j = 0; j <= lattice_size_y; j++) { y0 = (float)j * LATTICE_UNIT_SIZE - yc; p1.y = y0; p1.z = zc; convert_to_srs_cs( &p1_srs, &p1 ); p2.y = y0; p2.z = - zc; convert_to_srs_cs( &p2_srs, &p2 ); write_srs_cylinder( srs, &p1_srs, &p2_srs, STICK_RADIUS ); } } /* Stick material */ color.r = STICK_R; color.g = STICK_G; color.b = STICK_B; write_srs_pigment( srs, &color ); fprintf( srs, "\t}\n" ); fprintf( srs, "\t// **** End lattice definition ****\n" ); } #endif /* WITH_SRS_EXPORTER */ /* end lattice.c */ lightspeed-1.2a.debian.1/src/lightspeed.c000066400000000000000000000130061334064775200203230ustar00rootroot00000000000000/* lightspeed.c */ /****************************** Light Speed! ****************************** Interactive visualization of relativistic distortion phenomena Written by Daniel Richard G., July 1998 - April 1999 Built on OpenGL, GTK+, and the GtkGLArea widget. **************************************************************************/ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" #ifdef ENABLE_NLS #include #endif #ifndef HAVE_GTK1 GdkGLConfig *glconfig=NULL; #endif static void cmdline_help( const char *execname ) { int i; char opt, *lopt, *desc; printf( "\n" ); printf( "%s %s\n", STR_Light_Speed, VERSION ); printf( gettext(STR_copyright_ARG), 1999, "Daniel Richard G. " ); printf( "\n\n" ); printf( gettext(STR_CLI_usage_ARG), execname ); printf( "\n" ); for (i = 0; i < 4; i++) { opt = STRS_CLI_options[i].opt; lopt = STRS_CLI_options[i].lopt; desc = STRS_CLI_options[i].desc; #ifdef HAVE_GETOPT_LONG if (opt != '\0') printf( " -%c --%-9s %s\n", opt, lopt, gettext(desc) ); else printf( " %-14s %s\n", gettext(lopt), gettext(desc) ); #else if (opt != '\0') printf( " -%-7c %s\n", opt, gettext(desc) ); else printf( " %-8s %s\n", gettext(lopt), gettext(desc) ); #endif /* not HAVE_GETOPT_LONG */ } printf( "\n" ); fflush( stdout ); } int main( int argc, char **argv ) { #ifdef HAVE_GETOPT_LONG struct option long_options[4]; #endif int opt, i; char *init_obj_file = NULL; #ifdef ENABLE_NLS /* Mennucc: set the locale for the help messages */ setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif #ifdef HAVE_GETOPT_LONG /* Initialize long-options array */ for (i = 0; i < 3; i++) { long_options[i].name = STRS_CLI_options[i].lopt; long_options[i].has_arg = no_argument; long_options[i].flag = NULL; long_options[i].val = STRS_CLI_options[i].opt; } long_options[3].name = 0; long_options[3].has_arg = 0; long_options[3].flag = 0; long_options[3].val = 0; #endif /* HAVE_GETOPT_LONG */ /* Parse command-line options */ while (TRUE) { #ifdef HAVE_GETOPT_LONG opt = getopt_long( argc, argv, STR_CLI_option_chars, long_options, NULL ); #else opt = getopt( argc, argv, STR_CLI_option_chars ); #endif /* not HAVE_GETOPT_LONG */ if (opt == -1) break; if (opt == STRS_CLI_options[0].opt) { /* -h --help */ cmdline_help( argv[0] ); return 0; } if (opt == STRS_CLI_options[1].opt) { /* -s --simple */ advanced_interface = FALSE; break; } if (opt == STRS_CLI_options[2].opt) { /* -a --advanced */ advanced_interface = TRUE; break; } } if (optind < argc) { /* object */ init_obj_file = argv[optind]; } /* Initialize profiling */ profile( INITIALIZE ); #ifdef ENABLE_NLS #ifndef HAVE_GTK1 /* Mennucc: from here on, all messages will be translated before they are passed to GTK2, that is, Pango, so they must be UTF-8. Thanks to Thomas Huriaux (see http://bugs.debian.org/361260 ) */ bind_textdomain_codeset(PACKAGE, "UTF-8"); /* note that this means that any translated message that may be written to the terminal will be UTF-8 as well! */ #endif #endif /* Initialize GTK+ */ gtk_init( &argc, &argv ); #ifdef HAVE_GTK1 /* Check for OpenGL support (GLX extension) */ if (gdk_gl_query( ) == FALSE) { fprintf( stderr, _("Light Speed! requires OpenGL support to run.") ); fflush( stderr ); return -1; } #else gtk_gl_init (&argc, &argv); /* Try double-buffered visual */ glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGBA |GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA); if (glconfig == NULL) { g_print ("*** Cannot find the rgba alpha double-buffered visual.\n"); g_print ("*** Trying rgb single-buffered visual.\n"); /* Try single-buffered visual */ glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH); if (glconfig == NULL) { g_print ("*** No appropriate OpenGL-capable visual found.\n"); exit (1); } } #endif /* Generate/load initial object */ if (init_obj_file == NULL) make_lattice( DEF_LATTICE_X, DEF_LATTICE_Y, DEF_LATTICE_Z, DEF_LATTICE_SMOOTH ); else { i = import_objects( init_obj_file ); if (i < 0) { gtk_timeout_add( 5000, (GtkFunction)gtk_main_quit, NULL ); gtk_main( ); return -1; } } /* Make primary camera */ new_camera( ); /* Construct main window */ main_window( ); /* Fire up the warp engine */ warp( INITIALIZE, NULL ); /* Initialize gamma correction if default says so */ if (DEF_DGAMMA_CORRECT != 1.0) { calc_dgamma_lut( DEF_DGAMMA_CORRECT ); dgamma_correct = TRUE; } else dgamma_correct = FALSE; /* Showtime! */ gtk_main( ); return 0; } /* That's all, folks! */ /* end lightspeed.c */ lightspeed-1.2a.debian.1/src/lightspeed.h000066400000000000000000000411441334064775200203340ustar00rootroot00000000000000/* lightspeed.h */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ /**** Includes ***********************************************************/ /* Autoconf stuff */ #ifdef HAVE_CONFIG_H #include "config.h" #endif /* HAVE_CONFIG_H */ /* The usual headers */ #include #include #ifdef HAVE_GETOPT_H #include #endif /* HAVE_GETOPT_H */ #include #include #include #ifdef HAVE_LOCALE_H #include #endif #ifdef ENABLE_NLS #endif #if ENABLE_NLS #include "../gettext.h" # define _(Text) gettext (Text) #else # define bindtextdomain(Domain, Directory) # define textdomain(Domain) # define _(Text) Text # define gettext(z) z #endif #define N_(Text) Text /* OpenGL */ #include #include /* GTK+ */ #include #ifdef HAVE_GTK1 #include #else #include extern GdkGLConfig *glconfig; #endif /* Compile-time settings */ #include "settings.h" /* For GTK+/glib 1.0 compatibility */ #include "compat.h" /* Optional memory allocation tracking */ #ifdef WITH_TRACKMEM #include "trackmem.h" #endif /**** Constants/macros ***************************************************/ /* We need >=1 image library to save snapshots */ #if (HAVE_LIBPNG || HAVE_LIBTIFF) #define CAN_SAVE_SNAPSHOT #else #undef CAN_SAVE_SNAPSHOT #endif /* C = speed of light in meters/sec */ #define C 299792458.0 /* MAX_VELOCITY < C */ #define MAX_VELOCITY (C - 1.0) /* MIN_VELOCITY > 0 */ #define MIN_VELOCITY 1.0 #define PI 3.14159265358979323846264338327 #define MAGIC_NUMBER 1.618033989 /* EM wavelengths (in nanometers) */ #define LAMBDA_UV 340.0 #define LAMBDA_BLUE 460.0 #define LAMBDA_GREEN 520.0 #define LAMBDA_RED 700.0 #define LAMBDA_IR 1000.0 /* Relative perceptual strengths of the RGB components */ #define RED_STRENGTH 0.3 #define GREEN_STRENGTH 0.59 #define BLUE_STRENGTH 0.11 /* Useful */ #define DEG(angleRad) ((angleRad) * 180 / PI) #define RAD(angle360) ((angle360) * PI / 180) #define SQR(x) ((x) * (x)) #define SIGN(x) (((x) >= 0) ? 1.0 : -1.0) #define C2 (C * C) /* a value counterpart to NULL */ #define NIL 0 /* Macro for message passing via pointer */ #define MESG_(m) ((int *)&mesg_vals[m]) /* Message constants: */ enum { /* Objects modes (for global variable "objects_mode") */ MODE_LATTICE, MODE_USER_GEOMETRY, /* transition types (trans_var->type field) */ TRANS_LINEAR, TRANS_QTR_SIN, TRANS_RAMP, TRANS_SIGMOID, TRANS_STOP, /* graphics mode control by menu_Camera_GraphicsMode_select( ) */ OGL_WIREFRAME_MODE, OGL_SHADED_MODE, /* auxiliary object control by aux_objs( ) */ AUXOBJS_DRAW, AUXOBJS_SET_AXES, AUXOBJS_SET_BBOX, AUXOBJS_SET_GRID, /* relativistic distortion control by warp( ) */ WARP_DISTORT, WARP_LORENTZ_CONTRACTION, WARP_OPTICAL_DEFORMATION, WARP_DOPPLER_SHIFT, WARP_HEADLIGHT_EFFECT, /* time and animation control by warp_time( ) */ WARP_UPDATE_TIME_T, WARP_BEGIN_ANIM, WARP_STOP_ANIM, /* performance profiling control by profile( ) */ PROFILE_START_ITERATION, PROFILE_FRAME_BEGIN, PROFILE_FRAME_DONE, PROFILE_FRAMERATE_RESET, PROFILE_WARP_BEGIN, PROFILE_WARP_DONE, PROFILE_OGLDRAW_BEGIN, PROFILE_OGLDRAW_DONE, PROFILE_IDLE, PROFILE_SHOW_STATS, /* info display control by info_display( ) */ INFODISP_DRAW, INFODISP_ACTIVE, INFODISP_SHOW_VELOCITY, INFODISP_SHOW_TIME_T, INFODISP_SHOW_GAMMA, INFODISP_SHOW_FRAMERATE, INFODISP_UPDATE, /* position codes for ogl_draw_string( ) */ POS_TOP_LEFT, POS_TOP_RIGHT, POS_BOTTOM_LEFT, POS_BOTTOM_RIGHT, POS_CENTER, /* dialog control */ DIALOG_OPEN, DIALOG_CLOSE, DIALOG_OK, DIALOG_OK_CONFIRM, /* for camera_calc_xyz( ) */ CAM_POSITION, CAM_TARGET, /* for velocity_input( ) et. al. */ VALUE_COMMITTED, VALUE_CHANGED, UNITS_CHANGED, /* generic OO */ ACTIVATE, DEACTIVATE, ITERATION, INITIALIZE, RESET, QUERY, /* for rotate_xyz( ), etc. */ X_ALIGN, Y_ALIGN, Z_ALIGN, Z_ROTATE_CW, Z_ROTATE_CCW, /* for image handling, esp. save_snapshot( ) */ IMAGE_FORMAT, IMAGE_FORMAT_PNG, IMAGE_FORMAT_TIFF, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_COMMENTS, IMAGE_FILENAME, IMAGE_PIXELROW, IMAGE_COMPLETE }; /**** Data structures ****************************************************/ /* Command-line option description */ struct option_desc { char opt; /* Short option */ char *lopt; /* Equivalent long option (GNU-style) */ char *desc; /* Description string */ }; /* Transitory variable state container * Keeps track of a float or double var as it goes from initial to final value * (see transition_engine( ) for the details) */ typedef struct trans_var_struct trans_var; struct trans_var_struct { void *var; int is_double : 1; int looping : 1; int type; double start_t; double end_t; int cam_id; /* = -1 if transition affects all camera views */ double initial; double final; trans_var *next; /* transition queue is a linked list.... */ }; /* Absolute coordinate extents info */ typedef struct extents_struct extents; struct extents_struct { float xmin; float xmax; float ymin; float ymax; float zmin; float zmax; float avg; /* = ((xmax-xmin)+(ymax-ymin)+(zmax-zmin))/3 */ }; /* RGB color definition */ typedef struct rgb_color_struct rgb_color; struct rgb_color_struct { float r; float g; float b; }; /* 3D point/vector definition */ typedef struct point_struct point; struct point_struct { float x; float y; float z; }; /* OpenGL point (color+normal+location) definition * (for use in interleaved arrays) */ typedef struct ogl_point_struct ogl_point; struct ogl_point_struct { /* RGBA color (C4F) */ float r; float g; float b; float a; /* Normal direction (N3F) */ float nx; float ny; float nz; /* Vertex location (V3F) */ float x; float y; float z; }; /* OpenGL object definition */ typedef struct ogl_object_struct ogl_object; struct ogl_object_struct { int type; int num_vertices; point *vertices0; /* Original, unwarped geometry */ point *normals0; rgb_color color0; ogl_point *iarrays; /* C4F+N3F+V3F interleaved arrays */ int num_indices; unsigned int *indices; int pre_dlist; /* OGL display list executed before... */ int post_dlist; /* ...and after drawing the object */ }; /* Camera state container */ typedef struct camera_struct camera; struct camera_struct { float phi; /* heading (in degres) */ float theta; /* elevation (in degrees) */ float distance; /* distance to target */ point target; point pos; /* Derived from phi/theta/distance/target */ float fov; /* field of view in degrees */ int width, height; /* of associated viewport */ float near_clip; /* Clipping plane distances */ float far_clip; GtkWidget *window_w; /* Associated window widget */ GtkWidget *ogl_w; /* Associated GL widget (viewport) */ int redraw : 1; /* Flag: does viewport want a redraw? */ }; /**** Global variables ***************************************************/ /* These are all in globals.c */ extern const int mesg_vals[]; extern const int num_unit_systems; extern const char *unit_suffixes[]; extern const double unit_conv_factors[]; extern const int unit_num_decimals[]; extern int cur_unit_system; extern const int num_background_colors; extern const rgb_color bkgd_colors[]; extern rgb_color background; extern const int num_font_sizes; extern const char *sys_font_names[]; extern const int sys_font_sizes[]; extern const int micro_glyph; extern const int num_stock_lenses; extern const float stock_lenses[]; extern const char *image_format_exts[]; extern double velocity; extern double cur_time_t; extern float vehicle_real_x; extern int object_mode; extern int lattice_size_x; extern int lattice_size_y; extern int lattice_size_z; extern float framerate; extern ogl_object **vehicle_objs; extern int num_vehicle_objs; extern extents vehicle_extents; extern extents world_extents; extern camera **usr_cams; extern int num_cams; extern int cur_cam; extern camera out_cam; extern int advanced_interface; extern int dgamma_correct; extern float dgamma_lut[]; extern float mouse_sens; /* Language-specific strings */ #include "lstrings.h" /**** Forward declarations ***********************************************/ /* animation.c */ void queue_redraw( int cam_id ); int update( int message ); void profile( int message ); void transition( void *var, int is_double, int trans_type, double duration, double final, int cam_id ); void animate( void *var, int is_double, int trans_type, double duration, double initial, double final, int cam_id ); void break_transition( void *var ); /* auxobjects.c */ void auxiliary_objects( int message1, int message2 ); /* camera.c */ camera *new_camera( void); void kill_camera( int cam_id ); void camera_reset( int cam_id ); int assoc_cam_id( void *widget ); int camera_set_current( GtkWidget *widget, GdkEventFocus *ev_focus, void *nothing ); float camera_calc_fov( float lens_length ); float camera_calc_lens_length( float fov ); void camera_calc_xyz( int point_type, camera *cam ); void camera_make_target( camera *cam ); int camera_move( GtkWidget *widget, GdkEventAny *event, void *nothing ); /* command.c */ int command( const char *input ); /* geometry.c */ ogl_object *alloc_ogl_object( int num_vertices, int num_indices ); int calc_ogl_object_memusage( int num_vertices, int num_indices ); void free_ogl_object( ogl_object *obj ); void clear_all_objects( void); void rotate_all_objects( int direction ); void rotate_xyz( int action, float *x, float *y, float *z, float x0, float y0, float z0 ); point *calc_tri_normal( point *a, point *b, point *c ); point *calc_tri_centroid( point *a, point *b, point *c ); float calc_tri_area( point *a, point *b, point *c ); void show_geometry_stats( void); #ifdef WITH_SRS_EXPORTER int export_srs( const char *filename, int width, int height, int stereo_view, int visible_faces_only ); void write_srs_mesh( FILE *srs, point *cam_pos, int visible_faces_only ); void write_srs_camera( FILE *srs, camera *cam, float t ); void write_srs_sphere( FILE *srs, point *center, float radius ); void write_srs_cylinder( FILE *srs, point *p1, point *p2, float radius ); void write_srs_smooth_triangle( FILE *srs, point **vertices, point **normals ); void write_srs_pigment( FILE *srs, rgb_color *color ); void convert_to_srs_cs( point *p_srs, point *p_ls ); #endif /* WITH_SRS_EXPORTER */ /* gtkwidgets.c */ GtkWidget *add_gl_area( GtkWidget *parent_box_w ); GtkWidget *make_dialog_window( const char *title, void *callback_close ); GtkWidget *message_window( const char *title, const char *message_text ); GtkWidget *confirmation_dialog( const char *title, const char *message_text, void *callback ); GtkWidget *make_filesel_window( const char *title, const char *init_filename, int show_fileops, void *callback_handler ); GtkWidget *add_menu( GtkWidget *parent_menu_w, const char *label ); GtkWidget *add_menu_item( GtkWidget *menu_w, const char *label, void *callback, void *callback_data ); GtkWidget *add_check_menu_item( GtkWidget *menu_w, const char *label, int init_state, void *callback, void *callback_data ); void begin_radio_menu_group( int init_selected ); GtkWidget *add_radio_menu_item( GtkWidget *menu_w, const char *label, void *callback, void *callback_data ); GtkWidget *option_menu_item( const char *label, void *callback, void *callback_data ); GtkWidget *add_option_menu( GtkWidget *widget ); void add_separator( GtkWidget *parent_w ); void keybind( GtkWidget *widget, char *keys ); GtkWidget *add_hbox( GtkWidget *parent_w, int homog, int spacing ); GtkWidget *add_vbox( GtkWidget *parent_w, int homog, int spacing ); GtkWidget *add_frame( GtkWidget *parent_w, const char *title ); GtkWidget *add_hscale( GtkWidget *parent_w, GtkObject *adjustment ); GtkWidget *add_vscale( GtkWidget *parent_w, GtkObject *adjustment ); GtkWidget *add_spin_button( GtkWidget *parent_w, GtkObject *adjustment ); GtkWidget *add_check_button( GtkWidget *parent_w, const char *label, int init_state, void *callback, void *callback_data ); GtkWidget *add_entry( GtkWidget *parent_w, const char *init_str, void *callback, void *callback_data ); void set_entry_width( GtkWidget *entry_w, const char *span_str ); void set_entry_text( GtkWidget *entry_w, const char *entry_text ); char *read_entry( GtkWidget *entry_w ); void highlight_entry( GtkWidget *entry_w ); GtkWidget *add_button( GtkWidget *parent_w, const char *label, void *callback, void *callback_data ); GtkWidget *add_label( GtkWidget *parent_w, const char *label_text ); GtkWidget *add_pixmap( GtkWidget *parent_w, GtkWidget *parent_window_w, char **xpm_data ); void assign_icon( GtkWidget *window_w, char **xpm_data ); /* importobjs.c */ int import_objects( const char *filename ); /* infodisp.c */ void info_display( int message1, int message2 ); /* lattice.c */ void make_lattice( int size_x, int size_y, int size_z, int smoothness ); #ifdef WITH_SRS_EXPORTER void write_srs_lattice( FILE *srs ); #endif /* WITH_SRS_EXPORTER */ /* mainwindow.c */ void main_window( void ); void add_Camera_menu( GtkWidget *menu_bar_w, GtkWidget *window_w ); /* menu_cbs.c */ void velocity_input( GtkWidget *widget, const int *message ); #ifdef VELOCITY_SLIDER void velocity_slider( GtkWidget *widget, const int *message ); #endif /* VELOCITY_SLIDER */ void dialog_File_NewLattice( GtkWidget *widget, const int *message ); #ifdef WITH_OBJECT_IMPORTER void dialog_File_ImportObject( GtkWidget *widget, const int *message ); #endif /* WITH_OBJECT_IMPORTER */ #ifdef CAN_SAVE_SNAPSHOT void dialog_File_SaveSnapshot( GtkWidget *widget, const int *message ); #endif /* CAN_SAVE_SNAPSHOT */ #ifdef WITH_SRS_EXPORTER void dialog_File_ExportSRS( GtkWidget *widget, const int *message ); #endif /* WITH_SRS_EXPORTER */ void menu_Objects_toggles( GtkWidget *widget, const int *message ); void dialog_Objects_Animation( GtkWidget *widget, const int *message ); void menu_Warp_toggles( GtkWidget *widget, const int *message ); void menu_Camera_Lens_select( GtkWidget *widget, const float *new_lens_length ); void dialog_Camera_Lens_Custom( GtkWidget *widget, const int *message ); void dialog_Camera_Position( GtkWidget *widget, const int *message ); void menu_Camera_ResetView( GtkWidget *widget, const int *cam_id ); void menu_Camera_InfoDisplay_toggles( GtkWidget *widget, const int *message ); void menu_Camera_Background_select( GtkWidget *widget, const int *color_id ); void menu_Camera_GraphicsMode_select( GtkWidget *widget, const int *message ); void menu_Camera_Spawn( GtkWidget *widget, void *dummy ); void menu_Camera_Close( GtkWidget *widget_to_kill, void *dummy ); void dialog_Help_Overview( GtkWidget *widget, int *message ); void dialog_Help_Controls( GtkWidget *widget, int *message ); void dialog_Help_About( GtkWidget *widget, int *message ); /* misc.c */ void *xmalloc( size_t size ); void *xrealloc( void *block, size_t size ); char *xstrdup( const char *str ); void xfree( void *block ); int file_exists( const char *filename ); char *file_basename( const char *name, const char *suffix ); char *swap_filename_ext( const char *filename, const char *old_ext, const char *new_ext ); double read_system_clock( void); void set_cursor_glyph( int glyph ); char *velocity_string( double v_ms, int fancy ); char *add_commas( const char *num_str ); char *clean_number( const char *num_str ); char *time_string( void ); void calc_dgamma_lut( float dgamma ); void crash( char *error_mesg ); void ss( void ); int *NOP( void ); /* ogl.c */ void ogl_initialize( GtkWidget *ogl_w, void *nothing ); int ogl_resize( GtkWidget *ogl_w, GdkEventConfigure *ev_config, void *nothing ); int ogl_refresh( GtkWidget *ogl_w, GdkEventExpose *ev_expose, void *nothing ); void ogl_draw( int cam_id ); void ogl_draw_string( const void *data, int message, int size ); void ogl_blank( int cam_id, const char *blank_message ); GtkWidget *ogl_make_widget( void); /* snapshot.c */ void save_snapshot( int width, int height, const char *filename, int format ); /* warp.c */ int warp( int message, void *data ); void warp_point( point *vertex, point *normal, point *cam_pos ); void warp_time( float x0, float x1, double value, int message ); double lorentz_factor( double v ); /* end lightspeed.h */ lightspeed-1.2a.debian.1/src/lstrings.c000066400000000000000000000302761334064775200200500ustar00rootroot00000000000000/* lstrings.c */ /* Language-specific strings (English) */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" #define N_(Text) Text /* All changes necessary to port Light Speed! to a new language should be * contained within this file. If modifications are necessary elsewhere in * the code, please let me know. There are surely a few odd English-specific * constructs not quite in here yet :-) */ const char *STR_Light_Speed = "Light Speed!"; /* %d = year, %s = author's name or author's name + e-mail address */ const char *STR_copyright_ARG = N_("Copyright (C) %d by %s"); /**** COMMAND-LINE INTERFACE ****/ /* %s = executable name */ const char *STR_CLI_usage_ARG = N_("usage: %s [-hsa] [object]"); struct option_desc STRS_CLI_options[] = { { 'h', "help", N_("Print this help screen") }, #ifdef DEF_ADVANCED_INTERFACE { 's', "simple", N_("Use simplified interface") }, { 'a', "advanced", N_("Use advanced interface (default)") }, #else { 's', "simple", N_("Use simple interface (default)") }, { 'a', "advanced", N_("Use more advanced interface") }, #endif /* not DEF_ADVANCED_INTERFACE */ { '\0', N_("object"), N_("3D file to load on startup (.3DS or .LWO)") } }; const char *STR_CLI_option_chars = "hsa"; /**** MENUS ****/ /* Menu bar headings */ const char *STR_MNU_File = N_("File"); const char *STR_MNU_Objects = N_("Objects"); const char *STR_MNU_Warp = N_("Warp"); const char *STR_MNU_Camera = N_("Camera"); const char *STR_MNU_Help = N_("Help"); /* File menu */ const char *STR_MNU_New_lattice = N_("New lattice..."); const char *STR_MNU_Load_object = N_("Load object..."); const char *STR_MNU_Save_snapshot = N_("Save snapshot..."); const char *STR_MNU_Export_srs = N_("Export SRS..."); const char *STR_MNU_Exit = N_("Exit"); /* Objects menu */ const char *STR_MNU_Coordinate_axes = N_("Coordinate axes"); const char *STR_MNU_Floating_grid = N_("Floating grid"); const char *STR_MNU_Bounding_box = N_("Bounding box"); const char *STR_MNU_Animation = N_("Animation..."); /* Warp menu */ const char *STR_MNU_Lorentz_contraction = N_("Lorentz contraction"); const char *STR_MNU_Doppler_shift = N_("Doppler red/blue shift"); const char *STR_MNU_Headlight_effect = N_("Headlight effect"); const char *STR_MNU_Optical_deformation = N_("Optical aberration"); /* Camera menu */ const char *STR_MNU_Lens = N_("Lens"); const char *STR_MNU_Position = N_("Position..."); const char *STR_MNU_Reset_view = N_("Reset view"); const char *STR_MNU_Info_display = N_("Info display"); const char *STR_MNU_Background = N_("Background"); const char *STR_MNU_Graphics_mode = N_("Graphics mode"); const char *STR_MNU_Spawn_camera = N_("Spawn camera"); const char *STR_MNU_Close = N_("Close"); /* Camera->Lens submenu */ const char *STR_MNU_Custom = N_("Custom"); /* Camera->Info_display submenu */ const char *STR_MNU_Active = N_("Active"); const char *STR_MNU_Velocity = N_("Velocity"); const char *STR_MNU_Time_t = N_("Time t"); const char *STR_MNU_Gamma_factor = N_("Gamma factor"); const char *STR_MNU_Framerate = N_("Framerate"); /* Camera->Background submenu colors * (corresponding color hues are defined in globals.c) */ const char *STRS_MNU_bkgd_color_names[] = { N_("Black"), N_("Grey"), N_("White"), N_("Very white") }; /* Camera->Graphics_mode submenu */ const char *STR_MNU_Wireframe = N_("Wireframe"); const char *STR_MNU_Shaded = N_("Shaded"); /* Help menu */ const char *STR_MNU_Overview = N_("Overview"); const char *STR_MNU_Controls = N_("Controls"); const char *STR_MNU_About = N_("About"); /**** INFO DISPLAY ****/ /* Time t * %s == time string as returned by time_string( ) */ const char *STR_INF_time_ARG = N_("t = %ssec"); /* Framerate */ const char *STR_INF_fps_ARG = N_("%.1f fps"); /* Velocity * %s == velocity strings as returned by velocity_string( ???, TRUE ) */ const char *STR_INF_velocity_ARG = N_("Velocity: %s"); /* Gamma factor */ const char *STR_INF_gamma_ARG = N_("gamma = %.3f"); /* Relativistic toggle messages */ const char *STR_INF_no_contraction = N_("LORENTZ CONTRACTION NOT SHOWN"); const char *STR_INF_no_doppler_shift = N_("DOPPLER RED/BLUE SHIFT NOT SHOWN"); const char *STR_INF_no_headlight_effect = N_("HEADLIGHT EFFECT NOT SHOWN"); const char *STR_INF_no_deformation = N_("OPTICAL ABERRATION NOT SHOWN"); const char *STR_INF_no_relativity = N_("NO RELATIVISTIC EFFECTS SHOWN!!!"); /**** DIALOGS ****/ const char *STR_DLG_Okay_btn = N_("OK"); const char *STR_DLG_Cancel_btn = N_("Cancel"); const char *STR_DLG_Close_btn = N_("Close"); /* New Lattice dialog */ const char *STR_DLG_New_lattice = N_("New lattice"); const char *STR_DLG_Dimensions = N_("Dimensions"); const char *STR_DLG_Smoothness = N_("Smoothness"); /* Load Object dialog */ const char *STR_DLG_Load_Object = N_("Load Object"); const char *STR_DLG_Recognized_formats = N_("Recognized formats"); const char *STR_DLG_3d_formats = N_("3D Studio: *.3DS or *.PRJ\nLightWave 3D: *.LWO"); /* Save snapshot dialog */ const char *STR_DLG_Save_Snapshot = N_("Save Snapshot"); const char *STR_DLG_snapshot_Parameters = N_("Parameters"); const char *STR_DLG_snapshot_Size = N_("Size"); const char *STR_DLG_snapshot_Format = N_("Format"); const char *STR_DLG_snapshot_basename = N_("snapshot"); /* Export SRS dialog */ const char *STR_DLG_Export_srs = N_("Export SRS"); const char *STR_DLG_srs = N_("Special Relativity Scene (SRS)"); const char *STR_DLG_srs_Parameters = N_("Parameters"); const char *STR_DLG_srs_Size = N_("Rendered size"); const char *STR_DLG_srs_Stereo_view = N_("Stereoscopic view"); const char *STR_DLG_srs_Vis_faces_only = N_("Visible faces only"); /* basename1 is for lattices, basename2 is for imported geometry */ const char *STR_DLG_srs_basename1 = N_("lattice"); const char *STR_DLG_srs_basename2 = N_("object"); /* Animation dialog */ const char *STR_DLG_Animation = N_("Animation"); const char *STR_DLG_Observed_range = N_("Observed range of motion"); const char *STR_DLG_Start_X = N_("Starting X"); const char *STR_DLG_End_X = N_("Ending X"); const char *STR_DLG_Loop_time = N_("Loop time: "); const char *STR_DLG_seconds = N_(" seconds"); const char *STR_DLG_Begin_btn = N_("Begin"); const char *STR_DLG_Stop_btn = N_("Stop"); /* Camera Position dialog */ const char *STR_DLG_Camera_Position = N_("Camera Position"); const char *STR_DLG_Location = N_("Location"); const char *STR_DLG_View_target = N_("View target"); const char *STR_DLG_Direction = N_("Direction"); const char *STR_DLG_Phi_label = N_("Phi [0, 360)"); const char *STR_DLG_Theta_label = N_("Theta [-90, 90]"); const char *STR_DLG_Angles_instead = N_("Specify phi/theta direction instead"); const char *STR_DLG_Xyz_instead = N_("Specify (x,y,z) view target instead"); const char *STR_DLG_Reposition_btn = N_("Reposition"); /* Custom Lens dialog */ const char *STR_DLG_Custom_Lens = N_("Custom Lens"); const char *STR_DLG_Lens_length = N_("Lens length"); const char *STR_DLG_Field_of_view = N_("Field of view"); const char *STR_DLG_degree_suffix = N_("deg"); /* Overview dialog */ const char *STR_DLG_Overview = N_("Overview"); /* Controls dialog */ const char *STR_DLG_Controls = N_("Controls"); /* About dialog */ const char *STR_DLG_About = N_("About"); /* %d == version major, %d == version minor */ const char *STR_DLG_Version_x_y_ARG = N_("Version %s"); /* %s == author's name */ const char *STR_DLG_authorship_ARG = N_("A Theory Toy by %s"); const char *STR_DLG_home_page_url = "http://lightspeed.sourceforge.net/"; /* Spawned camera window title */ const char *STR_DLG_Camera = N_("Camera"); /* Miscellaneous dialog titles */ const char *STR_DLG_Warning = N_("Warning"); const char *STR_DLG_Error = N_("Error"); /* Help->Overview text * (from the OVERVIEW file) */ const char *STR_DLG_Overview_TEXT = N_("\ Light Speed! is a simulator which can illustrate the effects of\n\ special relativity on the appearance of objects travelling at\n\ ultra-high speeds. Depending on the particular speed, and one's\n\ point of view, relativistic effects can cause the object to\n\ appear shorter, longer, brighter, darker, deformed and/or\n\ off-color.\n\ \n\ To adjust the velocity, use the slider along the right edge of\n\ the main window. You can also type in a value, using the entry\n\ at the top right (press once it is in). To change the\n\ units shown, press the button to the right of the entry, and it\n\ will cycle through a small list.\n\ \n\ The object travels in the positive-x direction, which can be\n\ visually checked by activating Objects -> Coordinate axes.\n\ "); /* Help->Controls text * (from the CONTROLS file) */ const char *STR_DLG_Controls_TEXT = N_("\ Most interactive control is performed with the mouse. By holding\n\ down a particular button, and dragging the pointer around,\n\ various camera motions can be obtained:\n\ \n\ Left button: Revolve camera around view targetg\n\ \n\ Left button + Shift key: Revolve view target around camera\n\ \n\ Middle button: Translate camera left, right, up or down\n\ \n\ Right button: Dolly in or out\n\ \n\ The first and last motions are generally the most useful.\n\ Should the camera become difficult to control at any point, it\n\ may be re-initialized by selecting Camera -> Reset View.\n\ "); /**** MESSAGES ****/ /* For quick-and-dirty command feedback */ const char *STR_MSG_Okay = N_("OK"); const char *STR_MSG_Invalid = N_("INVALID"); /* File overwrite warning * %s == filename (basename) of file at risk */ const char *STR_MSG_overwrite_warn_ARG = N_("The file \"%s\" already exists.\nPress OK to overwrite it."); /* Object importer error messages */ /* %s == (bogus) filename */ const char *STR_MSG_no_object_file_ARG = N_("The specified object file could not be opened.\n(%s)\nImport operation failed."); const char *STR_MSG_not_3ds_file = N_("The file lacks a valid 3DS signature.\nImport operation failed."); const char *STR_MSG_not_prj_file = N_("The file lacks a valid 3D Studio PRJ signature.\nImport operation failed."); const char *STR_MSG_not_lwo_file = N_("The file lacks a valid LWOB signature.\nImport operation failed."); const char *STR_MSG_unknown_obj_format = N_("The object must be in 3D Studio (3DS)\nor LightWave 3D (LWO) file format.\nImport operation failed."); const char *STR_MSG_bad_3ds_file = N_("The 3D Studio file could not be properly read.\nImport operation failed."); const char *STR_MSG_empty_3ds_file = N_("The 3D Studio file has no valid geometry.\nImport operation failed."); const char *STR_MSG_bad_lwo_file = N_("The LightWave file could not be properly read.\nImport operation failed."); const char *STR_MSG_empty_lwo_file = N_("The LightWave file has no valid geometry.\nImport operation failed."); /* Snapshot exporter error messages */ const char *STR_MSG_no_ogl_visual = N_("The system could not provide the required visual.\nSave operation failed."); /* %d == width, %d == height */ const char *STR_MSG_no_render_buf_ARG = N_("A %dx%d render buffer could not be allocated.\nSave operation failed."); const char *STR_MSG_no_ogl_context = N_("The required OpenGL context was not available.\nSave operation failed."); const char *STR_MSG_no_snapshot_output = N_("An error occurred in creating the output file.\nSave operation failed."); /* Viewport-centered messages */ const char *STR_MSG_Generating_lattice = N_("GENERATING LATTICE . . ."); const char *STR_MSG_Importing_object = N_("LOADING OBJECT . . ."); const char *STR_MSG_Rendering_snapshot = N_("RENDERING . . ."); /* %d == percent of snapshot written */ const char *STR_MSG_Saving_snapshot_ARG = N_("SAVING SNAPSHOT . . .\n(%d%%)"); /* end lstrings.c */ lightspeed-1.2a.debian.1/src/lstrings.h000066400000000000000000000135271334064775200200550ustar00rootroot00000000000000/* lstrings.h */ /* Language-specific strings */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ extern const char *STR_Light_Speed; extern const char *STR_copyright_ARG; extern const char *STR_CLI_usage_ARG; extern struct option_desc STRS_CLI_options[]; extern const char *STR_CLI_option_chars; extern const char *STR_MNU_File; extern const char *STR_MNU_Objects; extern const char *STR_MNU_Warp; extern const char *STR_MNU_Camera; extern const char *STR_MNU_Help; extern const char *STR_MNU_New_lattice; extern const char *STR_MNU_Load_object; extern const char *STR_MNU_Save_snapshot; extern const char *STR_MNU_Export_srs; extern const char *STR_MNU_Exit; extern const char *STR_MNU_Coordinate_axes; extern const char *STR_MNU_Floating_grid; extern const char *STR_MNU_Bounding_box; extern const char *STR_MNU_Animation; extern const char *STR_MNU_Lorentz_contraction; extern const char *STR_MNU_Doppler_shift; extern const char *STR_MNU_Headlight_effect; extern const char *STR_MNU_Optical_deformation; extern const char *STR_MNU_Lens; extern const char *STR_MNU_Position; extern const char *STR_MNU_Reset_view; extern const char *STR_MNU_Info_display; extern const char *STR_MNU_Background; extern const char *STR_MNU_Graphics_mode; extern const char *STR_MNU_Spawn_camera; extern const char *STR_MNU_Close; extern const char *STR_MNU_Custom; extern const char *STR_MNU_Active; extern const char *STR_MNU_Velocity; extern const char *STR_MNU_Time_t; extern const char *STR_MNU_Gamma_factor; extern const char *STR_MNU_Framerate; extern const char *STRS_MNU_bkgd_color_names[]; extern const char *STR_MNU_Wireframe; extern const char *STR_MNU_Shaded; extern const char *STR_MNU_Overview; extern const char *STR_MNU_Controls; extern const char *STR_MNU_About; extern const char *STR_INF_time_ARG; extern const char *STR_INF_fps_ARG; extern const char *STR_INF_velocity_ARG; extern const char *STR_INF_gamma_ARG; extern const char *STR_INF_no_contraction; extern const char *STR_INF_no_doppler_shift; extern const char *STR_INF_no_headlight_effect; extern const char *STR_INF_no_deformation; extern const char *STR_INF_no_relativity; extern const char *STR_DLG_Okay_btn; extern const char *STR_DLG_Cancel_btn; extern const char *STR_DLG_Close_btn; extern const char *STR_DLG_New_lattice; extern const char *STR_DLG_Dimensions; extern const char *STR_DLG_Smoothness; extern const char *STR_DLG_Load_Object; extern const char *STR_DLG_Recognized_formats; extern const char *STR_DLG_3d_formats; extern const char *STR_DLG_Save_Snapshot; extern const char *STR_DLG_snapshot_Parameters; extern const char *STR_DLG_snapshot_Size; extern const char *STR_DLG_snapshot_Format; extern const char *STR_DLG_snapshot_basename; extern const char *STR_DLG_Export_srs; extern const char *STR_DLG_srs; extern const char *STR_DLG_srs_Parameters; extern const char *STR_DLG_srs_Size; extern const char *STR_DLG_srs_Stereo_view; extern const char *STR_DLG_srs_Vis_faces_only; extern const char *STR_DLG_srs_basename1; extern const char *STR_DLG_srs_basename2; extern const char *STR_DLG_Animation; extern const char *STR_DLG_Observed_range; extern const char *STR_DLG_Start_X; extern const char *STR_DLG_End_X; extern const char *STR_DLG_Loop_time; extern const char *STR_DLG_seconds; extern const char *STR_DLG_Begin_btn; extern const char *STR_DLG_Stop_btn; extern const char *STR_DLG_Camera_Position; extern const char *STR_DLG_Location; extern const char *STR_DLG_View_target; extern const char *STR_DLG_Direction; extern const char *STR_DLG_Phi_label; extern const char *STR_DLG_Theta_label; extern const char *STR_DLG_Angles_instead; extern const char *STR_DLG_Xyz_instead; extern const char *STR_DLG_Reposition_btn; extern const char *STR_DLG_Custom_Lens; extern const char *STR_DLG_Lens_length; extern const char *STR_DLG_Field_of_view; extern const char *STR_DLG_degree_suffix; extern const char *STR_DLG_Overview; extern const char *STR_DLG_Controls; extern const char *STR_DLG_About; extern const char *STR_DLG_Version_x_y_ARG; extern const char *STR_DLG_authorship_ARG; extern const char *STR_DLG_home_page_url; extern const char *STR_DLG_Camera; extern const char *STR_DLG_Warning; extern const char *STR_DLG_Error; extern const char *STR_DLG_Overview_TEXT; extern const char *STR_DLG_Controls_TEXT; extern const char *STR_MSG_Okay; extern const char *STR_MSG_Invalid; extern const char *STR_MSG_overwrite_warn_ARG; extern const char *STR_MSG_no_object_file_ARG; extern const char *STR_MSG_not_3ds_file; extern const char *STR_MSG_not_prj_file; extern const char *STR_MSG_not_lwo_file; extern const char *STR_MSG_unknown_obj_format; extern const char *STR_MSG_bad_3ds_file; extern const char *STR_MSG_empty_3ds_file; extern const char *STR_MSG_bad_lwo_file; extern const char *STR_MSG_empty_lwo_file; extern const char *STR_MSG_no_ogl_visual; extern const char *STR_MSG_no_render_buf_ARG; extern const char *STR_MSG_no_ogl_context; extern const char *STR_MSG_no_snapshot_output; extern const char *STR_MSG_Generating_lattice; extern const char *STR_MSG_Importing_object; extern const char *STR_MSG_Rendering_snapshot; extern const char *STR_MSG_Saving_snapshot_ARG; /* end lstrings.h */ lightspeed-1.2a.debian.1/src/mainwindow.c000066400000000000000000000233431334064775200203540ustar00rootroot00000000000000/* mainwindow.c */ /* Constructs main window * (and menu of spawned windows) */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Icon for the main Light Speed! window */ #include "icon.xpm" /* Construct main window */ void main_window( void ) { GtkWidget *main_window_w; GtkWidget *main_vbox_w; GtkWidget *hbox_w; GtkWidget *menu_bar_w; GtkWidget *menu_w; GtkWidget *menu_item_w; /* Main window widget */ main_window_w = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_window_set_title( GTK_WINDOW(main_window_w), STR_Light_Speed ); gtk_widget_set_usize( main_window_w, 600, 450 ); gtk_container_set_border_width( GTK_CONTAINER(main_window_w), 0 ); gtk_signal_connect( GTK_OBJECT(main_window_w), "focus_in_event", GTK_SIGNAL_FUNC(camera_set_current), NULL ); /* Need to set this so assoc_cam_id( ) will work */ usr_cams[0]->window_w = main_window_w; usr_cams[0]->ogl_w = NULL; /* for ogl_make_widget( ) */ /* (and its obligatory kill buttons) */ gtk_signal_connect( GTK_OBJECT(main_window_w), "delete_event", GTK_SIGNAL_FUNC(gtk_main_quit), NULL ); /* Destroy window before exiting */ gtk_quit_add_destroy( 1, GTK_OBJECT(main_window_w) ); /* Main vertical box widget */ main_vbox_w = add_vbox( main_window_w, FALSE, 0 ); /* Horizontal box for menu bar + velocity entry */ hbox_w = add_hbox( main_vbox_w, FALSE, 0 ); /* Initialize keybinding */ keybind( NULL, NULL ); /* Build menu bar */ /* Root menu bar widget */ menu_bar_w = gtk_menu_bar_new( ); gtk_box_pack_start( GTK_BOX(hbox_w), menu_bar_w, TRUE, TRUE, 0 ); gtk_widget_show( menu_bar_w ); /* File menu */ menu_w = add_menu( menu_bar_w, gettext(STR_MNU_File) ); /* File menu items */ menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_New_lattice), dialog_File_NewLattice, MESG_(DIALOG_OPEN) ); keybind( menu_item_w, "^N" ); #ifdef WITH_OBJECT_IMPORTER menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Load_object), dialog_File_ImportObject, MESG_(DIALOG_OPEN) ); keybind( menu_item_w, "^O" ); #endif #ifdef CAN_SAVE_SNAPSHOT menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Save_snapshot), dialog_File_SaveSnapshot, MESG_(DIALOG_OPEN) ); keybind( menu_item_w, "^S" ); #endif #ifdef WITH_SRS_EXPORTER add_menu_item( menu_w, gettext(STR_MNU_Export_srs), dialog_File_ExportSRS, MESG_(DIALOG_OPEN) ); #endif add_separator( menu_w ); menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Exit), gtk_main_quit, NULL ); keybind( menu_item_w, "^Q" ); /* Objects menu */ menu_w = add_menu( menu_bar_w, gettext(STR_MNU_Objects) ); /* Objects menu items */ menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Coordinate_axes), FALSE, menu_Objects_toggles, MESG_(AUXOBJS_SET_AXES) ); keybind( menu_item_w, "C" ); menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Floating_grid), TRUE, menu_Objects_toggles, MESG_(AUXOBJS_SET_GRID) ); keybind( menu_item_w, "G" ); menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Bounding_box), FALSE, menu_Objects_toggles, MESG_(AUXOBJS_SET_BBOX) ); keybind( menu_item_w, "B" ); add_separator( menu_w ); menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Animation), dialog_Objects_Animation, MESG_(DIALOG_OPEN) ); keybind( menu_item_w, "A" ); /* Warp menu */ menu_w = add_menu( menu_bar_w, gettext(STR_MNU_Warp) ); /* Warp menu items */ menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Lorentz_contraction), TRUE, menu_Warp_toggles, MESG_(WARP_LORENTZ_CONTRACTION) ); keybind( menu_item_w, "L" ); menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Doppler_shift), TRUE, menu_Warp_toggles, MESG_(WARP_DOPPLER_SHIFT) ); keybind( menu_item_w, "D" ); menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Headlight_effect), TRUE, menu_Warp_toggles, MESG_(WARP_HEADLIGHT_EFFECT) ); keybind( menu_item_w, "H" ); menu_item_w = add_check_menu_item( menu_w, gettext(STR_MNU_Optical_deformation), TRUE, menu_Warp_toggles, MESG_(WARP_OPTICAL_DEFORMATION) ); keybind( menu_item_w, "O" ); /* Camera menu defined elsewhere */ add_Camera_menu( menu_bar_w, main_window_w ); /* Help menu */ menu_w = add_menu( menu_bar_w, gettext(STR_MNU_Help) ); /* Help menu items */ add_menu_item( menu_w, gettext(STR_MNU_Overview), dialog_Help_Overview, MESG_(DIALOG_OPEN) ); add_menu_item( menu_w, gettext(STR_MNU_Controls), dialog_Help_Controls, MESG_(DIALOG_OPEN) ); add_separator( menu_w ); add_menu_item( menu_w, gettext(STR_MNU_About), dialog_Help_About, MESG_(DIALOG_OPEN) ); /* Done with the menu bar */ /* Velocity entry/units select button */ velocity_input( hbox_w, MESG_(INITIALIZE) ); /* Horizontal box for viewport and velocity slider */ hbox_w = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(main_vbox_w), hbox_w, TRUE, TRUE, 0 ); gtk_widget_show( hbox_w ); #if (VELOCITY_SLIDER == 1) velocity_slider( hbox_w, MESG_(INITIALIZE) ); #endif /* OpenGL area widget */ usr_cams[0]->ogl_w = add_gl_area( hbox_w ); #if (VELOCITY_SLIDER == 2) velocity_slider( hbox_w, MESG_(INITIALIZE) ); #endif /* Attach keybindings */ keybind( main_window_w, NULL ); /* Give window a nifty icon */ assign_icon( main_window_w, lightspeed_icon_xpm ); gtk_widget_show( main_window_w ); } /* Camera menu is common to main and spawned windows, thus defined separately */ void add_Camera_menu( GtkWidget *menu_bar_w, GtkWidget *window_w ) { GtkWidget *menu_w; GtkWidget *menu_item_w; GtkWidget *submenu_w; char lens_name[16]; int cam_id; int spawned_camera = FALSE; int i; cam_id = assoc_cam_id( window_w ); if (cam_id > 0) spawned_camera = TRUE; /* Camera menu */ menu_w = add_menu( menu_bar_w, gettext(STR_MNU_Camera) ); /* Lens submenu */ submenu_w = add_menu( menu_w, gettext(STR_MNU_Lens) ); /* Lens submenu items */ begin_radio_menu_group( num_stock_lenses ); /* custom lens is default */ for (i = 0; i < num_stock_lenses; i++) { sprintf( lens_name, "%.0fmm", stock_lenses[i] ); add_radio_menu_item( submenu_w, lens_name, menu_Camera_Lens_select, (float *)(&stock_lenses[i]) ); } add_separator( submenu_w ); menu_item_w = add_radio_menu_item( submenu_w, gettext(STR_MNU_Custom), dialog_Camera_Lens_Custom, MESG_(DIALOG_OPEN) ); gtk_signal_connect( GTK_OBJECT(menu_item_w), "activate", GTK_SIGNAL_FUNC(dialog_Camera_Lens_Custom), MESG_(DIALOG_OPEN) ); /* Lens submenu finished */ if (advanced_interface) add_menu_item( menu_w, gettext(STR_MNU_Position), dialog_Camera_Position, MESG_(DIALOG_OPEN) ); menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Reset_view), menu_Camera_ResetView, MESG_(cam_id) ); keybind( menu_item_w, "R" ); add_separator( menu_w ); if (!spawned_camera) { /* For primary camera only */ /* Info display submenu */ submenu_w = add_menu( menu_w, gettext(STR_MNU_Info_display) ); /* Info display submenu items */ menu_item_w = add_check_menu_item( submenu_w, gettext(STR_MNU_Active), DEF_INFODISP_ACTIVE, menu_Camera_InfoDisplay_toggles, MESG_(INFODISP_ACTIVE) ); keybind( menu_item_w, "I" ); add_separator( submenu_w ); add_check_menu_item( submenu_w, gettext(STR_MNU_Velocity), DEF_INFODISP_SHOW_VELOCITY, menu_Camera_InfoDisplay_toggles, MESG_(INFODISP_SHOW_VELOCITY) ); add_check_menu_item( submenu_w, gettext(STR_MNU_Time_t), DEF_INFODISP_SHOW_TIME_T, menu_Camera_InfoDisplay_toggles, MESG_(INFODISP_SHOW_TIME_T) ); add_check_menu_item( submenu_w, gettext(STR_MNU_Gamma_factor), DEF_INFODISP_SHOW_GAMMA, menu_Camera_InfoDisplay_toggles, MESG_(INFODISP_SHOW_GAMMA) ); add_check_menu_item( submenu_w, gettext(STR_MNU_Framerate), DEF_INFODISP_SHOW_FRAMERATE, menu_Camera_InfoDisplay_toggles, MESG_(INFODISP_SHOW_FRAMERATE) ); /* Info display submenu finished */ /* Background submenu */ submenu_w = add_menu( menu_w, gettext(STR_MNU_Background) ); /* Background submenu items */ begin_radio_menu_group( 0 ); /* first one (black) is default */ for (i = 0; i < num_background_colors; i++) add_radio_menu_item( submenu_w, gettext(STRS_MNU_bkgd_color_names[i]), menu_Camera_Background_select, MESG_(i) ); /* Background submenu finished */ if (advanced_interface) { /* Graphics mode submenu */ submenu_w = add_menu( menu_w, gettext(STR_MNU_Graphics_mode) ); /* Graphics mode submenu items */ begin_radio_menu_group( 1 ); /* Shaded mode is default */ add_radio_menu_item( submenu_w, gettext(STR_MNU_Wireframe), menu_Camera_GraphicsMode_select, MESG_(OGL_WIREFRAME_MODE) ); add_radio_menu_item( submenu_w, gettext(STR_MNU_Shaded), menu_Camera_GraphicsMode_select, MESG_(OGL_SHADED_MODE) ); /* Graphics mode submenu finished */ add_separator( menu_w ); menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Spawn_camera), menu_Camera_Spawn, NULL ); keybind( menu_item_w, "S" ); } } else { /* For spawned cameras */ menu_item_w = add_menu_item( menu_w, gettext(STR_MNU_Close), NULL, GTK_OBJECT(window_w) ); gtk_signal_connect_object( GTK_OBJECT(menu_item_w), "activate", GTK_SIGNAL_FUNC(menu_Camera_Close), GTK_OBJECT(window_w) ); keybind( menu_item_w, "^X" ); } } /* end mainwindow.c */ lightspeed-1.2a.debian.1/src/menu_cbs.c000066400000000000000000001346371334064775200200040ustar00rootroot00000000000000/* menu_cbs.c */ /* Callbacks for menus, dialogs */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Light Speed! title graphic for Help->About */ #include "title.xpm" /* This services the entry and units button on the menu bar */ void velocity_input( GtkWidget *widget, const int *message ) { static GtkWidget *velocity_entry_w = NULL; static GtkWidget *unit_label_w; static double prev_input_val = 1.0; static int blocking_changed = FALSE; GtkWidget *vbox_w; GtkWidget *button_w; double input_val; char *init_str; char *input_str; char *fixed_str; int i; switch (*message) { case RESET: blocking_changed = TRUE; /* Clear out any stale text in entry */ init_str = add_commas( velocity_string( prev_input_val, FALSE ) ); set_entry_text( velocity_entry_w, init_str ); blocking_changed = FALSE; return; case VALUE_COMMITTED: /* keystroke received */ blocking_changed = TRUE; input_str = read_entry( velocity_entry_w ); if (input_str[0] == '>') { /* Command entered */ i = command( &input_str[1] ); if (i == 0) set_entry_text( velocity_entry_w, gettext(STR_MSG_Okay) ); else set_entry_text( velocity_entry_w, gettext(STR_MSG_Invalid) ); blocking_changed = FALSE; return; } /* Clean out junk from input string */ input_str = clean_number( input_str ); input_val = strtod( input_str, NULL ) * unit_conv_factors[cur_unit_system]; input_val = CLAMP(input_val, MIN_VELOCITY, MAX_VELOCITY); /* Start hitting the gas (or the brakes!) */ transition( &velocity, TRUE, TRANS_SIGMOID, 5.0, input_val, -1 ); init_str = add_commas( velocity_string( input_val, FALSE ) ); set_entry_text( velocity_entry_w, init_str ); /* TODO: Find out why the highlight_entry( ) here DOES NOT WORK */ highlight_entry( velocity_entry_w ); prev_input_val = input_val; blocking_changed = FALSE; return; case VALUE_CHANGED: /* Avoid infinite recursion on "changed" signal */ if (blocking_changed) return; blocking_changed = TRUE; input_str = read_entry( velocity_entry_w ); if (input_str[0] == '>') return; /* command escape */ /* Clean up numerical input and add commas for clarity */ fixed_str = add_commas( clean_number( input_str ) ); /* TODO: Find out why gtk_entry_set_position() here doesn't work */ /* set_entry_text( widget, fixed_str ); gtk_entry_set_position( GTK_ENTRY(widget), strlen( fixed_str ) ); */ blocking_changed = FALSE; return; case UNITS_CHANGED: blocking_changed = TRUE; cur_unit_system = (cur_unit_system + 1) % num_unit_systems; gtk_label_set_text( GTK_LABEL(unit_label_w), unit_suffixes[cur_unit_system] ); velocity_input( NULL, MESG_(RESET) ); /* Update info display if it is active */ info_display( RESET, NIL ); blocking_changed = FALSE; return; case INITIALIZE: if (velocity_entry_w != NULL) { prev_input_val = velocity; velocity_input( NULL, MESG_(RESET) ); return; } init_str = velocity_string( velocity, FALSE ); velocity_entry_w = add_entry( widget, init_str, velocity_input, MESG_(VALUE_COMMITTED) ); set_entry_width( velocity_entry_w, "000,000,000,000" ); gtk_signal_connect( GTK_OBJECT(velocity_entry_w), "changed", GTK_SIGNAL_FUNC(velocity_input), MESG_(VALUE_CHANGED) ); keybind( velocity_entry_w, "^V" ); vbox_w = add_vbox( widget, FALSE, 3 ); button_w = add_button( vbox_w, NULL, velocity_input, MESG_(UNITS_CHANGED) ); unit_label_w = add_label( button_w, unit_suffixes[cur_unit_system] ); keybind( button_w, "U" ); return; default: #ifdef DEBUG crash( "velocity_input( ): invalid_message" ); #endif return; } } /* Services the slider to the side of the viewport */ #if VELOCITY_SLIDER void velocity_slider( GtkWidget *widget, const int *message ) { static GtkObject *velocity_adj; static GtkWidget *velocity_vscale_w; static int blocking_changed = FALSE; GtkWidget *frame_w; double input_val; float adj_value; switch (*message) { case VALUE_CHANGED: if (blocking_changed) return; adj_value = GTK_ADJUSTMENT(velocity_adj)->value; input_val = C * (1.0 - adj_value / 65536.0); /* Halt any ongoing velocity transition */ break_transition( &velocity ); velocity = CLAMP(input_val, MIN_VELOCITY, MAX_VELOCITY); /* Update velocity entry */ velocity_input( NULL, MESG_(INITIALIZE) ); queue_redraw( -1 ); return; case RESET: /* Update slider if its value isn't up-to-date */ blocking_changed = TRUE; adj_value = rint( 65536.0 * (1.0 - velocity / C) ); if (GTK_ADJUSTMENT(velocity_adj)->value != adj_value) gtk_adjustment_set_value( GTK_ADJUSTMENT(velocity_adj), adj_value ); blocking_changed = FALSE; return; case INITIALIZE: /* Frame for slider (purely for aesthetics) */ frame_w = add_frame( widget, NULL ); /* Velocity adjustment and scale widget */ velocity_adj = gtk_adjustment_new( 65536.0, 0.0, 65536.0, 1.0, 2048.0, 0.0 ); gtk_signal_connect( GTK_OBJECT(velocity_adj), "value_changed", GTK_SIGNAL_FUNC(velocity_slider), MESG_(VALUE_CHANGED) ); velocity_vscale_w = gtk_vscale_new( GTK_ADJUSTMENT(velocity_adj) ); gtk_scale_set_draw_value( GTK_SCALE(velocity_vscale_w), FALSE ); /* gtk_box_pack_start( GTK_BOX(hbox_w), velocity_scale_w, FALSE, FALSE, 0 ); */ gtk_container_add( GTK_CONTAINER(frame_w), velocity_vscale_w ); keybind( velocity_vscale_w, "V" ); gtk_widget_show( velocity_vscale_w ); return; default: #ifdef DEBUG crash( "velocity_slider( ): invalid message" ); #endif return; } } #endif /* VELOCITY_SLIDER */ void dialog_File_NewLattice( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *dialog_window_w; static GtkObject *size_x_adj, *size_y_adj, *size_z_adj; static GtkObject *smoothness_adj; static int prev_smoothness = DEF_LATTICE_SMOOTH; static float dummy; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *vbox_w; int input_size_x, input_size_y, input_size_z; int input_smoothness; int i; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_OK: gtk_widget_hide( dialog_window_w ); /* TODO: Find out why window widget doesn't actually hide until too late */ input_size_x = (int)(GTK_ADJUSTMENT(size_x_adj)->value); input_size_y = (int)(GTK_ADJUSTMENT(size_y_adj)->value); input_size_z = (int)(GTK_ADJUSTMENT(size_z_adj)->value); if (advanced_interface) input_smoothness = (int)(GTK_ADJUSTMENT(smoothness_adj)->value); else input_smoothness = prev_smoothness; /* Redraw or blank the viewports first (do redraw(s) if it * won't take too long AND a lattice is already up) */ if ((framerate > ((float)num_cams * 5.0)) && (object_mode == MODE_LATTICE)) { for (i = 0; i < num_cams; i++) ogl_draw( i ); } else { for (i = 0; i < num_cams; i++) ogl_blank( i, gettext(STR_MSG_Generating_lattice) ); } clear_all_objects( ); make_lattice( input_size_x, input_size_y, input_size_z, input_smoothness ); /* Reset camera(s) if user geometry had been loaded */ if (object_mode == MODE_USER_GEOMETRY) { for (i = 0; i < num_cams; i++) camera_reset( i ); /* and HIT THE BRAKES! */ velocity = 1.0; velocity_input( NULL, MESG_(INITIALIZE) ); } object_mode = MODE_LATTICE; /* Now have to recalibrate framerate */ profile( PROFILE_FRAMERATE_RESET ); /* (the transition will take care of redraw(s), too) */ dummy = 1.0; transition( &dummy, FALSE, TRANS_LINEAR, 1.0, 0.0, -1 ); lattice_size_x = input_size_x; lattice_size_y = input_size_y; lattice_size_z = input_size_z; prev_smoothness = input_smoothness; /* no break/return here */ case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( dialog_window_w ); return; default: #ifdef DEBUG crash( "dialog_File_NewLattice( ): invalid message" ); #endif return; } /* Dialog window widget */ dialog_window_w = make_dialog_window( STR_DLG_New_lattice, dialog_File_NewLattice ); gtk_window_set_position( GTK_WINDOW(dialog_window_w), GTK_WIN_POS_MOUSE ); /* Main vertical box widget */ main_vbox_w = add_vbox( dialog_window_w, FALSE, 10 ); /* Dimensions title frame */ frame_w = add_frame( main_vbox_w, gettext(STR_DLG_Dimensions) ); hbox_w = add_hbox( frame_w, FALSE, 10 ); /* X spinbutton */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "X" ); size_x_adj = gtk_adjustment_new( (float)lattice_size_x, 1.0, 16.0, 1.0, 1.0, 0.0 ); add_spin_button( vbox_w, size_x_adj ); /* Y spinbutton */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "Y" ); size_y_adj = gtk_adjustment_new( (float)lattice_size_y, 1.0, 16.0, 1.0, 1.0, 0.0 ); add_spin_button( vbox_w, size_y_adj ); /* Z spinbutton */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "Z" ); size_z_adj = gtk_adjustment_new( (float)lattice_size_z, 1.0, 16.0, 1.0, 1.0, 0.0 ); add_spin_button( vbox_w, size_z_adj ); if (advanced_interface) { /* Smoothness title frame */ frame_w = add_frame( main_vbox_w, gettext(STR_DLG_Smoothness) ); hbox_w = add_hbox( frame_w, TRUE, 10 ); /* Smoothness slider */ smoothness_adj = gtk_adjustment_new( (float)prev_smoothness, 3.0, 16.0, 1.0, 1.0, 0.0 ); add_hscale( hbox_w, smoothness_adj ); } hbox_w = add_hbox( main_vbox_w, TRUE, 0 ); add_button( hbox_w, gettext(STR_DLG_Okay_btn), dialog_File_NewLattice, MESG_(DIALOG_OK) ); add_button( hbox_w, gettext(STR_DLG_Cancel_btn), dialog_File_NewLattice, MESG_(DIALOG_CLOSE) ); gtk_widget_show( dialog_window_w ); } #ifdef WITH_OBJECT_IMPORTER void dialog_File_ImportObject( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *filesel_w; static char *prev_filename = NULL; static float dummy; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *label_w; int i; char *filename; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_OK: filename = gtk_file_selection_get_filename( GTK_FILE_SELECTION(filesel_w) ); if (prev_filename != NULL) xfree( prev_filename ); prev_filename = xstrdup( filename ); gtk_widget_hide( filesel_w ); /* Blank the viewports for loading */ for (i = 0; i < num_cams; i++) ogl_blank( i, gettext(STR_MSG_Importing_object) ); /* Out with the existing objects... */ clear_all_objects( ); /* ...and in with the new ones */ i = import_objects( prev_filename ); if (i < 0) /* Error! */ make_lattice( 1, 1, 1, 3 ); /* A full view reset is (almost) certainly necessary */ for (i = 0; i < num_cams; i++) camera_reset( i ); /* Reset velocity too */ velocity = 1.0; velocity_input( NULL, MESG_(INITIALIZE) ); object_mode = MODE_USER_GEOMETRY; /* Reset and recalibrate framerate */ profile( PROFILE_FRAMERATE_RESET ); dummy = 1.0; transition( &dummy, FALSE, TRANS_LINEAR, 1.0, 0.0, -1 ); /* no break/return here */ case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( filesel_w ); return; default: #ifdef DEBUG crash( "dialog_File_ImportObject( ): invalid message" ); #endif return; } filesel_w = make_filesel_window( gettext(STR_DLG_Load_Object), prev_filename, FALSE, dialog_File_ImportObject ); frame_w = add_frame( GTK_FILE_SELECTION(filesel_w)->main_vbox, gettext(STR_DLG_Recognized_formats) ); hbox_w = add_hbox( frame_w, FALSE, 10 ); label_w = add_label( hbox_w, gettext(STR_DLG_3d_formats) ); gtk_label_set_justify( GTK_LABEL(label_w), GTK_JUSTIFY_LEFT ); gtk_widget_show( filesel_w ); } #endif /* WITH_OBJECT_IMPORTER */ #ifdef CAN_SAVE_SNAPSHOT void dialog_File_SaveSnapshot( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *filesel_w; static GtkWidget *size_entry_w; static int format = -1; static int width, height; static char *prev_filename = NULL; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *vbox_w; int f, f1, f2; char *filename; char *input_str; char init_str[256]; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_OK: /* Grab and save the specified filename */ filename = gtk_file_selection_get_filename( GTK_FILE_SELECTION(filesel_w) ); xfree( prev_filename ); prev_filename = xstrdup( filename ); /* Get snapshot dimensions */ input_str = read_entry( size_entry_w ); width = (int)strtod( input_str, NULL ); /* next part (height) */ input_str = strpbrk( input_str, "xX* " ); if (input_str != NULL) input_str = strpbrk( input_str, "0123456789" ); if (input_str != NULL) height = (int)strtod( input_str, NULL ); else height = (3 * width) / 4; if ((width < 100) || (height < 75)) { /* Dimensions are too small (or negative??) */ width = MAX(100, width); height = MAX(75, height); sprintf( init_str, "%d x %d", width, height ); set_entry_text( size_entry_w, init_str ); return; } gtk_widget_hide( filesel_w ); case DIALOG_OK_CONFIRM: if (file_exists( prev_filename ) && (*message != DIALOG_OK_CONFIRM)) { filename = file_basename( prev_filename, NULL ); sprintf( init_str, gettext(STR_MSG_overwrite_warn_ARG), filename ); confirmation_dialog( gettext(STR_DLG_Warning), init_str, dialog_File_SaveSnapshot ); return; } else { ogl_blank( 0, NULL ); save_snapshot( width, height, prev_filename, format ); ogl_draw( 0 ); } /* no break/return here */ case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( filesel_w ); return; case IMAGE_FORMAT_PNG: case IMAGE_FORMAT_TIFF: /* Note newly selected format and update filename extension * (the latter only if it matches previously selected format) */ f1 = format - IMAGE_FORMAT - 1; format = *message; f2 = format - IMAGE_FORMAT - 1; filename = gtk_file_selection_get_filename( GTK_FILE_SELECTION(filesel_w) ); filename = swap_filename_ext( filename, image_format_exts[f1], image_format_exts[f2] ); gtk_file_selection_set_filename( GTK_FILE_SELECTION(filesel_w), filename ); return; default: #ifdef DEBUG crash( "dialog_File_SaveSnapshot( ): invalid message" ); #endif return; } #ifdef HAVE_LIBPNG if (format == -1) format = IMAGE_FORMAT_PNG; #endif #ifdef HAVE_LIBTIFF if (format == -1) format = IMAGE_FORMAT_TIFF; #endif /* Set defaults */ if (prev_filename == NULL) { width = usr_cams[0]->ogl_w->allocation.width; height = usr_cams[0]->ogl_w->allocation.height; f = format - IMAGE_FORMAT - 1; sprintf( init_str, "%s%s", gettext(STR_DLG_snapshot_basename), image_format_exts[f] ); prev_filename = xstrdup( init_str ); } filesel_w = make_filesel_window( gettext(STR_DLG_Save_Snapshot), prev_filename, TRUE, dialog_File_SaveSnapshot ); /* Frame for image parameters */ frame_w = add_frame( GTK_FILE_SELECTION(filesel_w)->main_vbox, gettext(STR_DLG_snapshot_Parameters) ); /* hbox for image size/format inputs */ hbox_w = add_hbox( frame_w, FALSE, 10 ); /* Snapshot size label & entry */ vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox_w ); add_label( vbox_w, gettext(STR_DLG_snapshot_Size) ); sprintf( init_str, "%d x %d", width, height ); size_entry_w = add_entry( vbox_w, init_str, NULL, NULL ); /* Image format option menu */ vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox_w ); add_label( vbox_w, gettext(STR_DLG_snapshot_Format) ); #ifdef HAVE_LIBPNG option_menu_item( "PNG", dialog_File_SaveSnapshot, MESG_(IMAGE_FORMAT_PNG) ); #endif #ifdef HAVE_LIBTIFF option_menu_item( "TIFF", dialog_File_SaveSnapshot, MESG_(IMAGE_FORMAT_TIFF) ); #endif add_option_menu( vbox_w ); gtk_widget_show( filesel_w ); } #endif /* CAN_SAVE_SNAPSHOT */ #ifdef WITH_SRS_EXPORTER void dialog_File_ExportSRS( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *filesel_w; static GtkWidget *size_entry_w; static GtkWidget *stereo_chkbtn_w; static GtkWidget *visfaceonly_chkbtn_w; static int width, height; static int stereo_view = FALSE; static int visible_faces_only = TRUE; static char *prev_filename = NULL; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *vbox_w; char *filename; char *input_str; char init_str[256]; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_OK: /* Grab and save the specified filename */ filename = gtk_file_selection_get_filename( GTK_FILE_SELECTION(filesel_w) ); xfree( prev_filename ); prev_filename = xstrdup( filename ); /* Get rendering dimensions */ input_str = read_entry( size_entry_w ); width = (int)strtod( input_str, NULL ); /* next part (height) */ input_str = strpbrk( input_str, "xX* " ); if (input_str != NULL) input_str = strpbrk( input_str, "0123456789" ); if (input_str != NULL) height = (int)strtod( input_str, NULL ); else height = (3 * width) / 4; if ((width < 100) || (height < 75)) { /* Dimensions are too small (or negative??) */ width = MAX(100, width); height = MAX(75, height); sprintf( init_str, "%d x %d", width, height ); set_entry_text( size_entry_w, init_str ); return; } stereo_view = GTK_TOGGLE_BUTTON(stereo_chkbtn_w)->active; visible_faces_only = GTK_TOGGLE_BUTTON(visfaceonly_chkbtn_w)->active; gtk_widget_hide( filesel_w ); case DIALOG_OK_CONFIRM: if (file_exists( prev_filename ) && (*message != DIALOG_OK_CONFIRM)) { filename = file_basename( prev_filename, NULL ); sprintf( init_str, gettext(STR_MSG_overwrite_warn_ARG), filename ); confirmation_dialog( gettext(STR_DLG_Warning), init_str, dialog_File_ExportSRS ); return; } else { ogl_blank( 0, NULL ); export_srs( prev_filename, width, height, stereo_view, visible_faces_only ); ogl_draw( 0 ); } /* no break/return here */ case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( filesel_w ); return; default: #ifdef DEBUG crash( "dialog_File_ExportSRS( ): invalid message" ); #endif return; } if (prev_filename == NULL) { /* Set defaults */ width = usr_cams[0]->ogl_w->allocation.width; height = usr_cams[0]->ogl_w->allocation.height; if (object_mode == MODE_LATTICE) sprintf( init_str, "%s.srs", gettext(STR_DLG_srs_basename1) ); else sprintf( init_str, "%s.srs", gettext(STR_DLG_srs_basename2) ); prev_filename = xstrdup( init_str ); } filesel_w = make_filesel_window( gettext(STR_DLG_Export_srs), prev_filename, TRUE, dialog_File_ExportSRS ); /* Label and frame for SRS parameters */ add_label( GTK_FILE_SELECTION(filesel_w)->main_vbox, gettext(STR_DLG_srs) ); frame_w = add_frame( GTK_FILE_SELECTION(filesel_w)->main_vbox, gettext(STR_DLG_srs_Parameters) ); /* hbox for image size / misc. parameter input */ hbox_w = add_hbox( frame_w, FALSE, 10 ); /* Rendering size label & entry */ vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox_w ); add_label( vbox_w, gettext(STR_DLG_srs_Size) ); sprintf( init_str, "%d x %d", width, height ); size_entry_w = add_entry( vbox_w, init_str, NULL, NULL ); /* Misc. parameter check buttons */ vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox_w ); stereo_chkbtn_w = add_check_button( vbox_w, gettext(STR_DLG_srs_Stereo_view), stereo_view, NULL, NULL ); visfaceonly_chkbtn_w = add_check_button( vbox_w, gettext(STR_DLG_srs_Vis_faces_only), visible_faces_only, NULL, NULL ); if (object_mode != MODE_USER_GEOMETRY) gtk_widget_hide( visfaceonly_chkbtn_w ); gtk_widget_show( filesel_w ); } #endif /* WITH_SRS_EXPORTER */ void menu_Objects_toggles( GtkWidget *widget, const int *message ) { int flag; flag = GTK_CHECK_MENU_ITEM(widget)->active; auxiliary_objects( *message, flag ); } void dialog_Objects_Animation( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *dialog_window_w; static GtkWidget *x0_entry_w; static GtkWidget *x1_entry_w; static GtkWidget *action_label_w; static GtkObject *loop_time_adj; static float prev_recomm_x0 = 999.0; static float prev_recomm_x1 = -999.0; static float prev_x0; static float prev_x1; static float prev_loop_time = 10.0; static int in_motion = FALSE; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *hbox2_w; GtkWidget *vbox_w; GtkWidget *button_w; float recomm_x0; float recomm_x1; float input_x0; float input_x1; float input_loop_time; char *x_span_str = "0000000000"; char *input_str; char init_str[16]; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( dialog_window_w ); return; case DIALOG_OK: in_motion = !in_motion; if (in_motion) { /* Begin animation */ if (advanced_interface) { input_str = read_entry( x0_entry_w ); input_x0 = strtod( input_str, NULL ); input_str = read_entry( x1_entry_w ); input_x1 = strtod( input_str, NULL ); } else { input_x0 = prev_x0; input_x1 = prev_x1; } input_loop_time = GTK_ADJUSTMENT(loop_time_adj)->value; if (input_x0 > input_x1) return; if ((input_x1 - input_x0) < 0.5) return; warp_time( input_x0, input_x1, input_loop_time, WARP_BEGIN_ANIM ); gtk_label_set_text( GTK_LABEL(action_label_w), gettext(STR_DLG_Stop_btn) ); prev_x0 = input_x0; prev_x1 = input_x1; prev_loop_time = input_loop_time; } else { /* Stop animation */ warp_time( NIL, NIL, NIL, WARP_STOP_ANIM ); gtk_label_set_text( GTK_LABEL(action_label_w), gettext(STR_DLG_Begin_btn) ); } return; default: #ifdef DEBUG crash( "dialog_Objects_Animation( ): invalid message" ); #endif return; } /* Recommended values for x0 & x1 * All this prev_/recomm_/prev_recomm_ jockeying is to show recommended * values ONLY when they change, otherwise use previous user values */ recomm_x0 = world_extents.xmin - vehicle_extents.xmax; recomm_x1 = world_extents.xmax - vehicle_extents.xmin; if (recomm_x0 != prev_recomm_x0) { prev_x0 = recomm_x0; prev_x1 = recomm_x1; } prev_recomm_x0 = recomm_x0; prev_recomm_x1 = recomm_x1; /* Dialog window widget */ dialog_window_w = make_dialog_window( gettext(STR_DLG_Animation), dialog_Objects_Animation ); gtk_window_set_position( GTK_WINDOW(dialog_window_w), GTK_WIN_POS_MOUSE ); /* Main vertical box widget */ main_vbox_w = add_vbox( dialog_window_w, FALSE, 10 ); if (advanced_interface) { /* Title frame widget for range of motion entries */ frame_w = add_frame( main_vbox_w, gettext(STR_DLG_Observed_range) ); hbox_w = add_hbox( frame_w, FALSE, 10 ); /* x0 entry */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, gettext(STR_DLG_Start_X) ); sprintf( init_str, "%.2f", prev_x0 ); x0_entry_w = add_entry( vbox_w, init_str, NULL, NULL ); set_entry_width( x0_entry_w, x_span_str ); /* x1 entry */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, gettext(STR_DLG_End_X) ); sprintf( init_str, "%.2f", prev_x1 ); x1_entry_w = add_entry( vbox_w, init_str, NULL, NULL ); set_entry_width( x1_entry_w, x_span_str ); hbox_w = add_hbox( main_vbox_w, FALSE, 0 ); } else { frame_w = add_frame( main_vbox_w, NULL ); hbox_w = add_hbox( frame_w, FALSE, 10 ); } hbox2_w = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), hbox2_w, TRUE, FALSE, 0 ); gtk_widget_show( hbox2_w ); /* Loop time spin button */ add_label( hbox2_w, gettext(STR_DLG_Loop_time) ); loop_time_adj = gtk_adjustment_new( prev_loop_time, 1, 60, 1, 1, 0.0 ); add_spin_button( hbox2_w, loop_time_adj ); add_label( hbox2_w, gettext(STR_DLG_seconds) ); /* Begin/Stop and Close buttons */ hbox_w = add_hbox( main_vbox_w, TRUE, 0 ); button_w = add_button( hbox_w, NULL, dialog_Objects_Animation, MESG_(DIALOG_OK) ); action_label_w = add_label( button_w, gettext(STR_DLG_Begin_btn) ); if (in_motion) gtk_label_set_text( GTK_LABEL(action_label_w), gettext(STR_DLG_Stop_btn) ); add_button( hbox_w, gettext(STR_DLG_Close_btn), dialog_Objects_Animation, MESG_(DIALOG_CLOSE) ); gtk_widget_show( dialog_window_w ); } void menu_Warp_toggles( GtkWidget *widget, const int *message ) { if (GTK_CHECK_MENU_ITEM(widget)->active) warp( *message, MESG_(1) ); else warp( *message, MESG_(0) ); } /* Camera / Lens / (lens length) */ void menu_Camera_Lens_select( GtkWidget *widget, const float *new_lens_length ) { float new_fov; new_fov = camera_calc_fov( *new_lens_length ); if (GTK_CHECK_MENU_ITEM(widget)->active) transition( &usr_cams[cur_cam]->fov, FALSE, TRANS_QTR_SIN, 3.0, new_fov, cur_cam ); } /* Camera / Lens / Custom */ void dialog_Camera_Lens_Custom( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *dialog_window_w; static GtkWidget *entry_w; static GtkWidget *frame_w; static GtkWidget *button_label_w; static camera *cam; static int fov_mode = FALSE; GtkWidget *main_vbox_w; GtkWidget *hbox_w; GtkWidget *vbox_w; GtkWidget *button_w; float input_val; float init_val; char *input_str; char init_str[16]; switch (*message) { case DIALOG_OPEN: if (active || !GTK_CHECK_MENU_ITEM(widget)->active) return; active = TRUE; break; case DIALOG_OK: input_str = read_entry( entry_w ); input_val = strtod( input_str, NULL ); if (!fov_mode) input_val = camera_calc_fov( input_val ); if ((input_val < 1.0) || (input_val > 175.0)) { set_entry_text( entry_w, gettext(STR_MSG_Invalid) ); highlight_entry( entry_w ); return; } else transition( &cam->fov, FALSE, TRANS_SIGMOID, 3.0, input_val, cur_cam ); /* no break/return here */ case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( dialog_window_w ); return; case INITIALIZE: case UNITS_CHANGED: fov_mode = !fov_mode; if (fov_mode) { gtk_frame_set_label( GTK_FRAME(frame_w), gettext(STR_DLG_Field_of_view) ); gtk_label_set_text( GTK_LABEL(button_label_w), gettext(STR_DLG_degree_suffix) ); sprintf( init_str, "%.2f", cam->fov ); set_entry_text( entry_w, init_str ); } else { gtk_frame_set_label( GTK_FRAME(frame_w), gettext(STR_DLG_Lens_length) ); gtk_label_set_text( GTK_LABEL(button_label_w), "mm" ); init_val = camera_calc_lens_length( cam->fov ); sprintf( init_str, "%.2f", init_val ); set_entry_text( entry_w, init_str ); } return; default: #ifdef DEBUG crash( "dialog_Lens_Custom( ): invalid message" ); #endif return; } cam = usr_cams[cur_cam]; /* Dialog window widget */ dialog_window_w = make_dialog_window( STR_DLG_Custom_Lens, dialog_Camera_Lens_Custom ); gtk_window_set_position( GTK_WINDOW(dialog_window_w), GTK_WIN_POS_MOUSE ); /* Main vertical box widget */ main_vbox_w = add_vbox( dialog_window_w, FALSE, 10 ); /* Title frame widget */ frame_w = add_frame( main_vbox_w, "---" ); /* Vertical box for spacing purposes only */ vbox_w = add_vbox( frame_w, FALSE, 10 ); /* Horizontal box for entry widget, units button */ hbox_w = add_hbox( vbox_w, FALSE, 0 ); /* Entry widget for lens length/FOV value */ entry_w = add_entry( hbox_w, "---", dialog_Camera_Lens_Custom, MESG_(DIALOG_OK) ); set_entry_width( entry_w, "00000000" ); /* Vertical box to frane the button */ vbox_w = add_vbox( hbox_w, FALSE, 3 ); /* Units select button */ button_w = add_button( vbox_w, NULL, dialog_Camera_Lens_Custom, MESG_(UNITS_CHANGED) ); /* Label for units select button */ button_label_w = add_label( button_w, "---" ); /* Horizontal box widget for OK/Close */ hbox_w = add_hbox( main_vbox_w, TRUE, 0 ); /* OK button */ add_button( hbox_w, gettext(STR_DLG_Okay_btn), dialog_Camera_Lens_Custom, MESG_(DIALOG_OK) ); /* "Cancel" button */ add_button( hbox_w, gettext(STR_DLG_Cancel_btn), dialog_Camera_Lens_Custom, MESG_(DIALOG_CLOSE) ); /* Call ourselves to set all the "---"'s to something sensible */ fov_mode = !fov_mode; /* following call will flip this back */ dialog_Camera_Lens_Custom( NULL, MESG_(INITIALIZE) ); gtk_widget_show( dialog_window_w ); } /* Camera / Position dialog * NOTE: phi & theta as seen by the user are NOT those in struct cam! * cam->phi = user_phi + 180, cam->theta = - user_theta */ void dialog_Camera_Position( GtkWidget *widget, const int *message ) { static int active = FALSE; static GtkWidget *dialog_window_w; static GtkWidget *loc_x_entry_w; static GtkWidget *loc_y_entry_w; static GtkWidget *loc_z_entry_w; static GtkWidget *targ_frame_w; static GtkWidget *targ_1_entry_w; static GtkWidget *targ_2_entry_w; static GtkWidget *targ_z_entry_w; static GtkWidget *unit_label_w; static GtkWidget *targ_1_label_w; static GtkWidget *targ_2_label_w; static GtkWidget *targ_z_vbox_w; static GtkWidget *action_label_w; static camera *cam; static int cam_id; static int phi_theta_mode = FALSE; static int input_queued; static int blocking_changed = FALSE; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *hbox_w; GtkWidget *vbox_w; GtkWidget *vbox2_w; GtkWidget *button_w; camera input_cam; float dx, dy, dz, dxy; char *xyz_span_str = "0000000000"; char *phi_theta_span_str = "00000000000000"; char init_str[16]; char *input_str; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_OK: /* If user didn't enter new values, don't do anything, just close */ if (!input_queued) goto cam_pos_close; /* Suck in all the input text */ input_str = read_entry( loc_x_entry_w ); input_cam.pos.x = strtod( input_str, NULL ); input_str = read_entry( loc_y_entry_w ); input_cam.pos.y = strtod( input_str, NULL ); input_str = read_entry( loc_z_entry_w ); input_cam.pos.z = strtod( input_str, NULL ); if (phi_theta_mode) { input_str = read_entry( targ_1_entry_w ); input_cam.phi = fmod( strtod( input_str, NULL ) + 180.0, 360.0 ); input_str = read_entry( targ_2_entry_w ); input_cam.theta = - fmod( strtod( input_str, NULL ), 90.0 ); /* Grok a better target and distance */ camera_make_target( &input_cam ); } else { input_str = read_entry( targ_1_entry_w ); input_cam.target.x = strtod( input_str, NULL ); input_str = read_entry( targ_2_entry_w ); input_cam.target.y = strtod( input_str, NULL ); input_str = read_entry( targ_z_entry_w ); input_cam.target.z = strtod( input_str, NULL ); /* Need to get phi+theta+distance from XYZpos/XYZtarget */ dx = input_cam.target.x - input_cam.pos.x; dy = input_cam.target.y - input_cam.pos.y; dz = input_cam.target.z - input_cam.pos.z; dxy = sqrt( SQR(dx) + SQR(dy) ); input_cam.phi = fmod( DEG(atan2( dy, dx )) + 180.0, 360.0 ); input_cam.theta = DEG(atan2( - dz, dxy )); input_cam.distance = sqrt( SQR(dx) + SQR(dy) + SQR(dz) ); if (input_cam.distance < 0.01) /* not good */ return; } if (ABS(input_cam.phi - cam->phi) > 180.0) { /* e.g. don't do a 300deg turn, -60deg will do */ if (cam->phi > input_cam.phi) cam->phi -= 360.0; else cam->phi += 360.0; } /* And finally, get the camera moving! */ transition( &cam->phi, FALSE, TRANS_SIGMOID, 4.0, input_cam.phi, cam_id ); transition( &cam->theta, FALSE, TRANS_SIGMOID, 4.0, input_cam.theta, cam_id ); transition( &cam->distance, FALSE, TRANS_SIGMOID, 4.0, input_cam.distance, cam_id ); transition( &cam->target.x, FALSE, TRANS_SIGMOID, 4.0, input_cam.target.x, cam_id ); transition( &cam->target.y, FALSE, TRANS_SIGMOID, 4.0, input_cam.target.y, cam_id ); transition( &cam->target.z, FALSE, TRANS_SIGMOID, 4.0, input_cam.target.z, cam_id ); /* no break/return here */ case DIALOG_CLOSE: cam_pos_close: if (!active) return; active = FALSE; gtk_widget_destroy( dialog_window_w ); return; case INITIALIZE: input_queued = TRUE; /* will be set FALSE shortly */ case UNITS_CHANGED: /* Switch between XYZ target and phi/theta specifications */ phi_theta_mode = !phi_theta_mode; if (phi_theta_mode) { /* Set the labels for XYZ target mode */ gtk_label_set_text( GTK_LABEL(unit_label_w), STR_DLG_Xyz_instead ); gtk_label_set_text( GTK_LABEL(targ_1_label_w), STR_DLG_Phi_label ); gtk_label_set_text( GTK_LABEL(targ_2_label_w), STR_DLG_Theta_label ); gtk_widget_hide( targ_z_vbox_w ); gtk_frame_set_label( GTK_FRAME(targ_frame_w), STR_DLG_Direction ); } else { /* Set the labels for phi/theta mode */ gtk_label_set_text( GTK_LABEL(unit_label_w), STR_DLG_Angles_instead ); gtk_label_set_text( GTK_LABEL(targ_1_label_w), "X" ); gtk_label_set_text( GTK_LABEL(targ_2_label_w), "Y" ); gtk_widget_show( targ_z_vbox_w ); gtk_frame_set_label( GTK_FRAME(targ_frame_w), STR_DLG_View_target ); } /* no break/return here */ case RESET: if (!active) return; /* Do this because set_entry_text( ) emits "changed" signals */ blocking_changed = TRUE; /* Update stale text in entry widgets */ if (*message != UNITS_CHANGED) { /* Update location entries * (but not on phi/theta mode switch) */ sprintf( init_str, "%.3f", cam->pos.x ); set_entry_text( loc_x_entry_w, init_str ); sprintf( init_str, "%.3f", cam->pos.y ); set_entry_text( loc_y_entry_w, init_str ); sprintf( init_str, "%.3f", cam->pos.z ); set_entry_text( loc_z_entry_w, init_str ); /* Also note: entries do not contain user input (anymore) */ if (input_queued) gtk_label_set_text( GTK_LABEL(action_label_w), gettext(STR_DLG_Okay_btn) ); input_queued = FALSE; } if (phi_theta_mode) { /* Update phi+theta/target entries */ sprintf( init_str, "%.2f", fmod( cam->phi + 180.0, 360.0 ) ); set_entry_text( targ_1_entry_w, init_str ); set_entry_width( targ_1_entry_w, phi_theta_span_str ); sprintf( init_str, "%.2f", - cam->theta ); set_entry_text( targ_2_entry_w, init_str ); set_entry_width( targ_2_entry_w, phi_theta_span_str ); } else { /* Update XYZ target entries */ sprintf( init_str, "%.3f", cam->target.x ); set_entry_text( targ_1_entry_w, init_str ); set_entry_width( targ_1_entry_w, xyz_span_str ); sprintf( init_str, "%.3f", cam->target.y ); set_entry_text( targ_2_entry_w, init_str ); set_entry_width( targ_2_entry_w, xyz_span_str ); sprintf( init_str, "%.3f", cam->target.z ); set_entry_text( targ_z_entry_w, init_str ); set_entry_width( targ_z_entry_w, xyz_span_str ); } blocking_changed = FALSE; return; case VALUE_CHANGED: /* Don't catch signals from the set_entry_text( )'s above */ if (blocking_changed) return; /* Entries now contain user input */ if (!input_queued) gtk_label_set_text( GTK_LABEL(action_label_w), gettext(STR_DLG_Reposition_btn) ); input_queued = TRUE; return; default: #ifdef DEBUG crash( "dialog_Camera_Position( ): invalid message" ); #endif return; } cam_id = cur_cam; cam = usr_cams[cam_id]; /* New dialog window */ dialog_window_w = make_dialog_window( gettext(STR_DLG_Camera_Position), dialog_Camera_Position ); gtk_window_set_position( GTK_WINDOW(dialog_window_w), GTK_WIN_POS_MOUSE ); /* Main vertical box widget */ main_vbox_w = add_vbox( dialog_window_w, FALSE, 10 ); /* Title frame for location entries */ frame_w = add_frame( main_vbox_w, gettext(STR_DLG_Location) ); /* Horizontal box widget for location entries */ hbox_w = add_hbox( frame_w, TRUE, 10 ); /* The XYZ location entries */ vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "X" ); loc_x_entry_w = add_entry( vbox_w, "---", NULL, NULL ); set_entry_width( loc_x_entry_w, xyz_span_str ); gtk_signal_connect( GTK_OBJECT(loc_x_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "Y" ); loc_y_entry_w = add_entry( vbox_w, "---", NULL, NULL ); set_entry_width( loc_y_entry_w, xyz_span_str ); gtk_signal_connect( GTK_OBJECT(loc_y_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); vbox_w = add_vbox( hbox_w, FALSE, 0 ); add_label( vbox_w, "Z" ); loc_z_entry_w = add_entry( vbox_w, "---", NULL, NULL ); set_entry_width( loc_z_entry_w, xyz_span_str ); gtk_signal_connect( GTK_OBJECT(loc_z_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); /* Title frame for target entries */ targ_frame_w = add_frame( main_vbox_w, "---" ); /* Vertical box widget for target entries + entry mode button */ vbox_w = add_vbox( targ_frame_w, FALSE, 10 ); /* Horizontal box widget for target entries (custom) */ hbox_w = add_hbox( vbox_w, TRUE, 0 ); /* The XYZ-target/phi+theta-heading entries */ /* X or phi */ vbox2_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox2_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox2_w ); targ_1_label_w = add_label( vbox2_w, "---" ); targ_1_entry_w = add_entry( vbox2_w, "---", NULL, NULL ); gtk_signal_connect( GTK_OBJECT(targ_1_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); /* Y or theta */ vbox2_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), vbox2_w, TRUE, FALSE, 0 ); gtk_widget_show( vbox2_w ); targ_2_label_w = add_label( vbox2_w, "---" ); targ_2_entry_w = add_entry( vbox2_w, "---", NULL, NULL ); gtk_signal_connect( GTK_OBJECT(targ_2_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); /* Z */ targ_z_vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox_w), targ_z_vbox_w, TRUE, FALSE, 0 ); gtk_widget_show( targ_z_vbox_w ); add_label( targ_z_vbox_w, "Z" ); targ_z_entry_w = add_entry( targ_z_vbox_w, "---", NULL, NULL ); gtk_signal_connect( GTK_OBJECT(targ_z_entry_w), "changed", GTK_SIGNAL_FUNC(dialog_Camera_Position), MESG_(VALUE_CHANGED) ); /* Entry mode button */ button_w = add_button( vbox_w, NULL, dialog_Camera_Position, MESG_(UNITS_CHANGED) ); unit_label_w = add_label( button_w, "---" ); /* Horizontal box widget for OK/Cancel */ hbox_w = add_hbox( main_vbox_w, TRUE, 0 ); /* OK/Cancel buttons */ button_w = add_button( hbox_w, NULL, dialog_Camera_Position, MESG_(DIALOG_OK) ); action_label_w = add_label( button_w, "---" ); add_button( hbox_w, gettext(STR_DLG_Cancel_btn), dialog_Camera_Position, MESG_(DIALOG_CLOSE) ); /* Call ourselves to set all the "---"'s to something sensible */ phi_theta_mode = !phi_theta_mode; /* the next call will flip it back */ dialog_Camera_Position( NULL, MESG_(INITIALIZE) ); gtk_widget_show( dialog_window_w ); } void menu_Camera_ResetView( GtkWidget *widget, const int *cam_id ) { camera_reset( *cam_id ); } void menu_Camera_InfoDisplay_toggles( GtkWidget *widget, const int *message ) { int flag; flag = GTK_CHECK_MENU_ITEM(widget)->active; info_display( *message, flag ); } /* Set a new background color */ void menu_Camera_Background_select( GtkWidget *widget, const int *color_id ) { float new_r, new_g, new_b; if (!GTK_CHECK_MENU_ITEM(widget)->active) return; #ifdef DEBUG if (*color_id >= num_background_colors) crash( "menu_Camera_Background_select( ): invalid color" ); #endif new_r = bkgd_colors[*color_id].r; new_g = bkgd_colors[*color_id].g; new_b = bkgd_colors[*color_id].b; transition( &background.r, FALSE, TRANS_QTR_SIN, 2.0, new_r, -1 ); transition( &background.g, FALSE, TRANS_QTR_SIN, 2.0, new_g, -1 ); transition( &background.b, FALSE, TRANS_QTR_SIN, 2.0, new_b, -1 ); } /* Camera / Graphics mode * Switches between OpenGL's shaded and wireframe modes */ void menu_Camera_GraphicsMode_select( GtkWidget *widget, const int *message ) { int i; /* "toggled" signal also catches "toggle off" */ if (!GTK_CHECK_MENU_ITEM(widget)->active) return; for (i = 0; i < num_cams; i++) { GTKGL_TEMP_begingl(usr_cams[i]->ogl_w); switch (*message) { case OGL_WIREFRAME_MODE: glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); break; case OGL_SHADED_MODE: glPolygonMode( GL_FRONT, GL_FILL ); break; default: #ifdef DEBUG crash( "menu_Camera_GraphicsMode( ): invalid message" ); #endif break; } GTKGL_TEMP_endgl( usr_cams[i]->ogl_w); } /* Redraw everything */ queue_redraw( -1 ); } /* Camera / Spawn camera * Creates a new window, with a new, autonomous camera view */ void menu_Camera_Spawn( GtkWidget *widget, void *dummy ) { GtkWidget *cam_window_w; GtkWidget *main_vbox_w; GtkWidget *menu_bar_w; camera *new_cam; /* Create the camera */ new_cam = new_camera( ); /* New window widget */ cam_window_w = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_window_set_title( GTK_WINDOW(cam_window_w), gettext(STR_DLG_Camera) ); gtk_widget_set_usize( cam_window_w, 400, 300 ); gtk_container_set_border_width( GTK_CONTAINER(cam_window_w), 0 ); gtk_signal_connect( GTK_OBJECT(cam_window_w), "focus_in_event", GTK_SIGNAL_FUNC(camera_set_current), NULL ); gtk_signal_connect( GTK_OBJECT(cam_window_w), "delete_event", GTK_SIGNAL_FUNC(menu_Camera_Close), NULL ); /* Destroy window before exiting */ gtk_quit_add_destroy( 1, GTK_OBJECT(cam_window_w) ); /* Main vertical box widget */ main_vbox_w = gtk_vbox_new( FALSE, 0 ); gtk_container_set_border_width( GTK_CONTAINER(main_vbox_w), 0 ); gtk_container_add( GTK_CONTAINER(cam_window_w), main_vbox_w ); gtk_widget_show( main_vbox_w ); /* Initialize keybinding */ keybind( NULL, NULL ); /* Build minimal menu bar */ menu_bar_w = gtk_menu_bar_new( ); gtk_box_pack_start( GTK_BOX(main_vbox_w), menu_bar_w, FALSE, FALSE, 0 ); gtk_widget_show( menu_bar_w ); /* NOTE: add_Camera_menu( ) uses assoc_cam_id( ) */ new_cam->window_w = cam_window_w; /* Add a stripped-down Camera menu */ add_Camera_menu( menu_bar_w, cam_window_w ); /* Add viewport */ new_cam->ogl_w = add_gl_area( main_vbox_w ); /* Attach keybindings */ keybind( cam_window_w, NULL ); gtk_widget_show( cam_window_w ); /* Ready for action! */ } /* Camera / Close (appears only in spawned windows) * Gets rid of a spawned camera */ void menu_Camera_Close( GtkWidget *widget_to_kill, void *dummy ) { int cam_id; cam_id = assoc_cam_id( widget_to_kill ); kill_camera( cam_id ); } /* Help / Overview * Tell the user what's going on */ void dialog_Help_Overview( GtkWidget *widget, int *message ) { static int active = FALSE; static GtkWidget *help_window_w; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *help_label_w; GtkWidget *hbox_w; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( help_window_w ); return; default: #ifdef DEBUG crash( "dialog_Help_Overview( ): invalid message" ); #endif return; } help_window_w = make_dialog_window( gettext(STR_DLG_Overview), dialog_Help_Overview ); gtk_window_set_position( GTK_WINDOW(help_window_w), GTK_WIN_POS_CENTER ); main_vbox_w = add_vbox( help_window_w, FALSE, 10 ); frame_w = add_frame( main_vbox_w, NULL ); hbox_w = add_hbox( frame_w, FALSE, 10 ); help_label_w = add_label( hbox_w, gettext(STR_DLG_Overview_TEXT) ); gtk_label_set_justify( GTK_LABEL(help_label_w), GTK_JUSTIFY_LEFT ); /* OK button (hbox_w is to keep button from growing heightwise) */ hbox_w = add_hbox( main_vbox_w, FALSE, 0 ); add_button( hbox_w, gettext(STR_DLG_Okay_btn), dialog_Help_Overview, MESG_(DIALOG_CLOSE) ); gtk_widget_show( help_window_w ); } /* Help / Controls * Give a summary of mouse input syntax */ void dialog_Help_Controls( GtkWidget *widget, int *message ) { static int active = FALSE; static GtkWidget *help_window_w; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *help_label_w; GtkWidget *hbox_w; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( help_window_w ); return; default: #ifdef DEBUG crash( "dialog_Help_Controls( ): invalid message" ); #endif return; } help_window_w = make_dialog_window( gettext(STR_DLG_Controls), dialog_Help_Controls ); gtk_window_set_position( GTK_WINDOW(help_window_w), GTK_WIN_POS_CENTER ); main_vbox_w = add_vbox( help_window_w, FALSE, 10 ); frame_w = add_frame( main_vbox_w, NULL ); hbox_w = add_hbox( frame_w, FALSE, 10 ); help_label_w = add_label( hbox_w, gettext(STR_DLG_Controls_TEXT) ); gtk_label_set_justify( GTK_LABEL(help_label_w), GTK_JUSTIFY_LEFT ); /* OK button (hbox_w is to keep button from growing heightwise) */ hbox_w = add_hbox( main_vbox_w, FALSE, 0 ); add_button( hbox_w, gettext(STR_DLG_Okay_btn), dialog_Help_Controls, MESG_(DIALOG_CLOSE) ); gtk_widget_show( help_window_w ); } /* Help / About * Tell a little about ourselves */ void dialog_Help_About( GtkWidget *widget, int *message ) { static int active = FALSE; static GtkWidget *about_window_w; GtkWidget *main_vbox_w; GtkWidget *frame_w; GtkWidget *vbox_w; GtkWidget *entry_w; char info_str[256]; switch (*message) { case DIALOG_OPEN: if (active) return; active = TRUE; break; case DIALOG_CLOSE: if (!active) return; active = FALSE; gtk_widget_destroy( about_window_w ); return; default: #ifdef DEBUG crash( "dialog_Help_About( ): invalid message" ); #endif return; } about_window_w = make_dialog_window( gettext(STR_DLG_About), dialog_Help_About ); gtk_window_set_position( GTK_WINDOW(about_window_w), GTK_WIN_POS_CENTER ); main_vbox_w = add_vbox( about_window_w, FALSE, 10 ); frame_w = add_frame( main_vbox_w, NULL ); vbox_w = add_vbox( frame_w, FALSE, 15 ); /* Get the Light Speed! title up */ add_pixmap( vbox_w, about_window_w, lightspeed_title_xpm ); sprintf( info_str, STR_DLG_Version_x_y_ARG, VERSION ); add_label( vbox_w, info_str ); sprintf( info_str, gettext(STR_DLG_authorship_ARG), "Daniel Richard G." ); strcat( info_str, "\nskunk@mit.edu" ); add_label( vbox_w, info_str ); sprintf( info_str, gettext(STR_copyright_ARG), 1999, "DRG" ); add_label( vbox_w, info_str ); /* To allow easy cut-and-paste :-) */ entry_w = gtk_entry_new( ); gtk_entry_set_editable( GTK_ENTRY(entry_w), FALSE ); sprintf( info_str, "XXX%sXXX", STR_DLG_home_page_url ); set_entry_width( entry_w, info_str ); set_entry_text( entry_w, STR_DLG_home_page_url ); gtk_box_pack_start( GTK_BOX(vbox_w), entry_w, FALSE, FALSE, 0 ); gtk_widget_show( entry_w ); add_button( main_vbox_w, gettext(STR_DLG_Okay_btn), dialog_Help_About, MESG_(DIALOG_CLOSE) ); gtk_widget_show( about_window_w ); } /* end menu_cbs.c */ lightspeed-1.2a.debian.1/src/misc.c000066400000000000000000000241201334064775200171250ustar00rootroot00000000000000/* misc.c */ /* Random stuff */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" #ifdef ENABLE_NLS #include #endif /* A kinder, gentler malloc( ) */ void * xmalloc( size_t size ) { void *block; #ifdef DEBUG int i; #endif block = malloc( size ); if (block == NULL) crash( "Insufficient memory" ); #ifdef WITH_TRACKMEM trackmem_malloc( block, size ); #endif #ifdef DEBUG /* Fill memory block with random junk */ for (i = 0; i < size; i++) ((unsigned char *)block)[i] = (unsigned char)(rand( ) % 256); #endif return block; } /* ditto for realloc( ) */ void * xrealloc( void *block, size_t size ) { void *block2; block2 = realloc( block, size ); if ((block2 == NULL) && (size > 0)) crash( "Insufficient memory" ); #ifdef WITH_TRACKMEM trackmem_realloc( block, block2, size ); #endif return block2; } char * xstrdup( const char *str ) { char *new_str; new_str = strdup( str ); if (new_str == NULL) crash( "Insufficient memory" ); #ifdef WITH_TRACKMEM trackmem_strdup( new_str ); #endif return new_str; } void xfree( void *block ) { #ifdef WITH_TRACKMEM trackmem_free( block ); #endif free( block ); } /* Checks if a file already exists */ int file_exists( const char *filename ) { FILE *fp; fp = fopen( filename, "r" ); if (fp == NULL) return FALSE; fclose( fp ); return TRUE; } /* This is a functional equivalent of the UNIX "basename" command */ char * file_basename( const char *name, const char *suffix ) { static char basename_buf[256]; int blen, slen; char *base; base = strrchr( name, '/' ); if (base == NULL) base = (char *)name; else base = &base[1]; strcpy( basename_buf, base ); if (suffix != NULL) { blen = strlen( basename_buf ); slen = strlen( suffix ); if (!strcasecmp( &basename_buf[blen - slen], suffix )) basename_buf[blen - slen] = '\0'; } return basename_buf; } /* Swaps the extension of a filename to new_ext if it already ends in old_ext * (a NULL for old_exts means any period-demarcated extension) */ char * swap_filename_ext( const char *filename, const char *old_ext, const char *new_ext ) { static char filename_buf[256]; char *ext_begin; int i; strcpy( filename_buf, filename ); if (old_ext != NULL) { i = strlen( filename_buf ) - strlen( old_ext ); ext_begin = &filename_buf[i]; if (!strcasecmp( ext_begin, old_ext )) strcpy( ext_begin, new_ext ); } else { ext_begin = strrchr( filename_buf, '.' ); if (ext_begin != NULL) strcpy( ext_begin, new_ext ); } return filename_buf; } /* Wrapper for gettimeofday( ) */ double read_system_clock( void ) { struct timeval tv; double t; gettimeofday( &tv, NULL ); t = (double)tv.tv_sec; t += (double)tv.tv_usec / 1E6; return t; } /* Change cursor appearance */ void set_cursor_glyph( int glyph ) { static GdkCursor *cursor; static int prev_glyph = -1; if (prev_glyph != -1) gdk_cursor_destroy( cursor ); cursor = gdk_cursor_new( glyph ); gdk_window_set_cursor( usr_cams[cur_cam]->ogl_w->window, cursor ); prev_glyph = glyph; } /* Returns the specified velocity (in m/s) formatted to current unit system * "fancy" parameter adds commas and units suffix when TRUE */ char * velocity_string( double v_ms, int fancy ) { static char v_str[32]; const char *suffix; double v_conv; int num_decimals; char num_str[32]; v_conv = v_ms / unit_conv_factors[cur_unit_system]; num_decimals = unit_num_decimals[cur_unit_system]; suffix = unit_suffixes[cur_unit_system]; if (fancy) { sprintf( num_str, "%.*f", num_decimals, v_conv ); sprintf( v_str, "%s %s", add_commas( num_str ), suffix ); } else sprintf( v_str, "%.*f", num_decimals, v_conv ); return v_str; } /* Adds commas to a number string */ char * add_commas( const char *num_str ) { static char new_str[64]; int len; int decimal_reached = FALSE; int group_digits = 0; int n = 64; int i; char c; char thousands_sep,decimal_point; #if ENABLE_NLS thousands_sep=localeconv()->thousands_sep[0]; decimal_point=localeconv()->decimal_point[0]; if(thousands_sep==0) thousands_sep=(decimal_point==',')?'.':','; #else thousands_sep=','; decimal_point='.'; #endif if (strchr( num_str, decimal_point ) == NULL) decimal_reached = TRUE; /* no decimal point */ len = strlen( num_str ); new_str[--n] = '\0'; for (i = len - 1; i >= 0; i--) { c = num_str[i]; if (group_digits == 3) { new_str[--n] = thousands_sep; group_digits = 0; } new_str[--n] = c; if (decimal_reached) ++group_digits; if (c == decimal_point) decimal_reached = TRUE; } return &new_str[n]; } /* Removes commas and other junk from a number string */ char * clean_number( const char *num_str ) { static char new_str[64]; int start, len; int n = 64; int decimal_reached = FALSE; int i; char c; char decimal_point; #if ENABLE_NLS decimal_point=localeconv()->decimal_point[0]; #else decimal_point='.'; #endif start = strcspn( num_str, "123456789." ); len = strlen( num_str ); new_str[--n] = '\0'; for (i = len - 1; i >= start; i--) { c = num_str[i]; if (c == decimal_point) { /* Allow only one occurrence of decimal point */ if (decimal_reached) continue; else decimal_reached = TRUE; } else if ((c < '0') || (c > '9')) continue; new_str[--n] = c; } return &new_str[n]; } /* Returns current time, formatted nicely and to an appropriate precision */ char * time_string( void ) { static char t_str[64]; float abs_t, t_usec; abs_t = ABS(cur_time_t); if (abs_t >= 1E-2) sprintf( t_str, "%+.3f ", cur_time_t ); else if (abs_t >= 1E-4) sprintf( t_str, "%+.5f ", cur_time_t ); else { t_usec = 1E6 * cur_time_t; /* microseconds */ sprintf( t_str, "%+.3f %c", t_usec, micro_glyph ); } return t_str; } /* Generates display gamma correction color component lookup table */ void calc_dgamma_lut( float dgamma ) { float k, x; int i; k = 1.0 / dgamma; for (i = 0; i <= LUT_RES; i++) { x = (float)i / LUT_RES; dgamma_lut[i] = pow( x, k ); } } /* Hopefully this never gets called */ void crash( char *error_mesg ) { fprintf( stderr, "CRASH: %s\n", error_mesg ); fflush( stderr ); exit( -1 ); } /* ^_^ */ void ss( void ) { const float r1 = 0.0375749; const float r2 = 0.112725; const float r3 = 0.187875; const float r4 = 0.42485; const float r5 = 0.5; const float r6 = 0.518787; const float a1 = 20.7181; const float a2 = 25.7579; const float a3 = 26.8014; const float a4 = 45.0353; const float xd = 0.1161; const float yd = 0.1127; camera *cam; float x, y; float a; int i; cam = usr_cams[0]; GTKGL_TEMP_begingl(cam->ogl_w); glClearColor( 0.0, 0.0, 0.0, 0.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDisable( GL_DEPTH_TEST ); glDisable( GL_LIGHTING ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); x = (float)cam->width; y = (float)cam->height; if ((x / y) > 1.0 ) { x = 0.6 * x / y; y = 0.6; } else { y = 0.6 * y / x; x = 0.6; } glOrtho( - x, x, - y, y, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glBegin( GL_QUAD_STRIP ); glColor3f( 1.0, 1.0, 1.0 ); glVertex2f( - xd, yd + r1 ); glVertex2f( - xd, yd + r2 ); for (i = 0; i <= 32; i++) { a = RAD(90.0 + 180.0 * (float)i / 32.0); x = cos(a); y = sin(a); glVertex2f( - xd + r1 * x, yd + r1 * y ); glVertex2f( - xd + r2 * x, yd + r2 * y ); } for (i = 0; i <= 64; i++) { a = RAD(90.0 - 180.0 * (float)i / 64.0); x = cos(a); y = sin(a); glVertex2f( xd + r3 * x, - yd + r3 * y ); glVertex2f( xd + r2 * x, - yd + r2 * y ); } for (i = 0; i <= 128; i++) { a = RAD(180.0 + a4 + (a1 - a4 + 180.0) * (float)i / 128.0); glVertex2f( r4 * cos(a), r4 * sin(a) ); a = RAD(180.0 + a2 + 180.0 * (float)i / 128.0); glVertex2f( r6 * cos(a), r6 * sin(a) ); } glVertex2f( - xd, yd + r1 ); glVertex2f( - xd, yd + r2 ); glEnd( ); glBegin( GL_QUAD_STRIP ); glColor3f( 1.0, 1.0, 1.0 ); for (i = 0; i <= 128; i++) { a = RAD( a3 + 180.0 * (float)i / 128.0 ); glVertex2f( r5 * cos(a), r5 * sin(a) ); a = RAD( a2 + 180.0 * (float)i / 128.0 ); glVertex2f( r6 * cos(a), r6 * sin(a) ); } glEnd( ); glBegin( GL_TRIANGLE_FAN ); glColor3f( 1.0, 1.0, 1.0 ); glVertex2f( - xd, yd + r3 ); for (i = 0; i <= 32; i ++) { a = RAD( a4 + (90.0 - a4) * (float)i / 32.0 ); glVertex2f( r4 * cos(a), r4 * sin(a) ); } glEnd( ); glBegin( GL_QUAD_STRIP ); glColor3f( 1.0, 1.0, 1.0 ); for (i = 0; i <= 128; i++) { a = RAD( 90.0 + 180.0 * (float)i / 128.0 ); glVertex2f( - xd + r3 * cos(a), yd + r3 * sin(a) ); a = RAD( 90.0 + (a1 + 90.0) * (float)i / 128.0 ); glVertex2f( r4 * cos(a), r4 * sin(a) ); } glVertex2f( xd, - yd + r1 ); glVertex2f( xd, - yd - r1 ); glEnd( ); glBegin( GL_TRIANGLE_FAN ); glColor3f( 1.0, 1.0, 1.0 ); for (i = 0; i <= 16; i++) { a = RAD( -90.0 + 180.0 * (float)i / 16.0 ); glVertex2f( xd + r1 * cos(a), - yd + r1 * sin(a) ); } glEnd( ); glHint( GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE ); glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); #ifdef HAVE_GTK1 gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) ); #else GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(cam->ogl_w); if (gdk_gl_drawable_is_double_buffered (gldrawable)) gdk_gl_drawable_swap_buffers (gldrawable); else glFlush (); #endif GTKGL_TEMP_endgl(cam->ogl_w); } /* NOP is referenced in compat.h * When no one in the world is using GTK 1.0, I'll get rid of this */ int *NOP( void ) { while (FALSE); return NULL; } /* end misc.c */ lightspeed-1.2a.debian.1/src/ogl-ftgl.cc000066400000000000000000000112101334064775200200440ustar00rootroot00000000000000/* Mennucc: how do we use fonts in GL ? simple, we don't ! http://www.opengl.org/resources/features/fontsurvey/ shows a lot of examples who need extra libraries; this file contains code to use the FTGL library for truetype fonts ; this is the only way I know to really support UTF-8 encodings */ #include "FTGLPixmapFont.h" char* fallback_fontfile =DATADIR "/fonts/truetype/freefont/FreeSans.ttf"; extern "C" { #include #include "lightspeed.h" } #ifdef HAVE_FC extern "C" { #include } char * find_a_font() { FcChar8* file=NULL; char *ret=NULL; FcFontSet *fs=NULL; FcPattern *pat=NULL; FcResult result; if (!FcInit ()) { g_critical( "Can't init font config library\n"); return NULL ; } pat = FcNameParse ((FcChar8 *) "Sans"); //Mennucc : I tried to enforce to have // fontformat: "TrueType" // because I thought that that was required for FTGl library; // turns out that it is not; and that the following does not work // ( fontconfig is pooorly documented !!) const FcChar8 * value =(FcChar8 *)"TrueType"; if(FcTrue != FcPatternAddString (pat, FC_FONTFORMAT , value)) g_critical( "Can't use FcPatternAddString\n"); FcConfigSubstitute (0, pat, FcMatchPattern); FcDefaultSubstitute (pat); fs = FcFontSort (0, pat, FcTrue, 0, &result); if(fs==NULL) { FcPattern *match; fs = FcFontSetCreate (); match = FcFontMatch (0, pat, &result); if (match) FcFontSetAdd (fs, match); } if (pat) FcPatternDestroy (pat); if (fs){ int j; for (j = 0; j < fs->nfont && ret == NULL ; j++) { if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) { if(file && file[0] && ret == NULL) { #ifdef DEBUG FcChar8 * ff; FcPatternGetString (fs->fonts[j], FC_FONTFORMAT, 0, &ff); g_message(" font '%s' WILL be %s ",ff,file); #endif ret=g_strdup((char *)file); } } } FcFontSetDestroy (fs); } /* FcFini(); */ return ret; } #endif void ogl_draw_string_( const void *data, int message, int size ) { static camera *cam=NULL; static FTFont* font=NULL; char *file=NULL; switch (message) { case INITIALIZE: #ifdef HAVE_FC if(file==NULL) file=find_a_font(); #endif if(file==NULL) file=fallback_fontfile; if(font==NULL) { if (file) { font=new FTGLPixmapFont( file); if( font->Error()) { fprintf( stderr, "Failed to open font %s", file); return; } } else { fprintf( stderr, "Failed to find a font file! "); return; }} font->Depth(8+size); font->CharMap(ft_encoding_unicode); break; case RESET: cam = (camera *)data; break; default: { char *text = (char *)data; g_return_if_fail(text && font && cam); int width, height; width = cam->width; height = cam->height; if( !font->FaceSize( 10 + 2* size )) { g_critical( "Failed to set size to font"); return; } float x1, y1, z1, x2, y2, z2; font->BBox( text, x1, y1, z1, x2, y2, z2); const int text_width=x2-x1, text_height=y2-y1; int x=0, y=0; int edge_dx = 1, edge_dy = 1; const int pos_code = message; /* y coord. of base point */ switch (pos_code) { case POS_BOTTOM_LEFT: case POS_BOTTOM_RIGHT: y = height / 100; edge_dy = 1; break; case POS_TOP_LEFT: case POS_TOP_RIGHT: y = (99 * height) / 100; y -= text_height; edge_dy = -1; break; case POS_CENTER: y = height / 2; y -= text_height / 2; edge_dy = -1; break; } /* x coord. of base point */ switch (pos_code) { case POS_TOP_LEFT: case POS_BOTTOM_LEFT: x = width / 100; edge_dx = 1; break; case POS_TOP_RIGHT: case POS_BOTTOM_RIGHT: x = (width * 99) / 100; x -= text_width; edge_dx = -1; break; case POS_CENTER: x = width / 2; x -= text_width / 2; edge_dx = 0; break; default: #ifdef DEBUG crash( "ogl_draw_string( ): invalid position code" ); #endif return; } //glColor3f( 1.0, 1.0, 1.0); glPushMatrix(); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( 0.0, (double)width, 0.0, (double)height, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glRasterPos2f(x + edge_dx , y + edge_dy); glColor3f( INFODISP_TEXT_FRONT_R, INFODISP_TEXT_FRONT_G, INFODISP_TEXT_FRONT_B ); font->Render(text); glPopMatrix(); } } } extern "C" { void ogl_draw_string( const void *data, int message, int size ) { return ogl_draw_string_(data, message, size );} } lightspeed-1.2a.debian.1/src/ogl-gtk1.c000066400000000000000000000130371334064775200176240ustar00rootroot00000000000000/* ogl.c */ /* ogl_draw_string, in its original form for GTK1 using GtkGlArea */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Draws a string in the viewport * Meaning of args can vary, see initial switch statement * "size" specifies size of text: 0 (small), 1 (medium) or 2 (large) * NOTE: This function requires some pre-existing state; namely, the target * GL context must already be made current as well as properly initialized * (see ogl_blank( ) or info_display( ) to see what I mean) */ void ogl_draw_string( const void *data, int message, int size ) { static GdkFont **fonts; static unsigned int *font_dlist_bases; static int *font_heights; static int width, height; static int fn_big; static int num_tl_lines, num_tr_lines, num_bl_lines, num_br_lines; static int num_cen_lines; const char *test_str = "XXXX XXXX XXXX XXXX"; camera *cam; int pos_code; int edge_dx = 1, edge_dy = 1; int x = 0, y = 0; int fn; int i; char str_buf[256]; char *disp_str; char *next_disp_str; switch (message) { case INITIALIZE: /* First-time initialization */ fonts = xmalloc( num_font_sizes * sizeof(GdkFont *) ); font_dlist_bases = xmalloc( num_font_sizes * sizeof(unsigned int *) ); font_heights = xmalloc( num_font_sizes * sizeof(int *) ); for (i = 0; i < num_font_sizes; i++) { fonts[i] = gdk_font_load( sys_font_names[i] ); if (fonts[i] == NULL) { printf( "ERROR: Cannot load font: %s\n", sys_font_names[i] ); fflush( stdout ); continue; } font_heights[i] = fonts[i]->ascent + fonts[i]->descent; font_dlist_bases[i] = glGenLists( 192 ); gdk_gl_use_gdk_font( fonts[i], 0, 192, font_dlist_bases[i] ); } return; case RESET: /* Once-per-GL-redraw initialization */ cam = (camera *)data; /* Get GL widget dimensions */ width = cam->width; height = cam->height; /* Reset line counters */ num_tl_lines = 0; num_tr_lines = 0; num_bl_lines = 0; num_br_lines = 0; num_cen_lines = 0; /* Determine upper limit on the font sizes we should use */ for (i = 0; i < num_font_sizes; i++) { fn_big = i; /* font number of "big" (size 2) font */ /* Test string should be minimally 1/3 viewport width */ if (gdk_string_width( fonts[i], test_str ) > (width / 3)) break; } return; default: pos_code = message; disp_str = (char *)data; break; } /* Check string for newlines, and queue if necessary */ i = strcspn( disp_str, "\n" ); if (i < strlen( disp_str )) { strcpy( str_buf, disp_str ); str_buf[i] = '\0'; disp_str = str_buf; next_disp_str = &str_buf[i + 1]; } else next_disp_str = NULL; /* Determine which (proportional) font size to use */ fn = MIN(fn_big, MAX(0, fn_big - 2 + size)); /* 0 <= fn <= fn_big */ /* x coord. of base point */ switch (pos_code) { case POS_TOP_LEFT: case POS_BOTTOM_LEFT: x = width / 100; edge_dx = 1; break; case POS_TOP_RIGHT: case POS_BOTTOM_RIGHT: x = (width * 99) / 100; x -= gdk_string_width( fonts[fn], disp_str ); edge_dx = -1; break; case POS_CENTER: x = width / 2; x -= gdk_string_width( fonts[fn], disp_str ) / 2; edge_dx = 0; break; default: #ifdef DEBUG crash( "ogl_draw_string( ): invalid position code" ); #endif return; } /* y coord. of base point */ switch (pos_code) { case POS_BOTTOM_LEFT: case POS_BOTTOM_RIGHT: y = height / 100; edge_dy = 1; break; case POS_TOP_LEFT: case POS_TOP_RIGHT: y = (99 * height) / 100; y -= font_heights[fn]; edge_dy = -1; break; case POS_CENTER: y = height / 2; y -= font_heights[fn] / 2; edge_dy = -1; break; } /* This makes multi-line readouts possible */ switch (pos_code) { case POS_TOP_LEFT: y -= num_tl_lines * font_heights[fn]; ++num_tl_lines; break; case POS_TOP_RIGHT: y -= num_tr_lines * font_heights[fn]; ++num_tr_lines; break; case POS_BOTTOM_LEFT: y += num_bl_lines * font_heights[fn]; ++num_bl_lines; break; case POS_BOTTOM_RIGHT: y += num_br_lines * font_heights[fn]; ++num_br_lines; break; case POS_CENTER: y -= num_cen_lines * font_heights[fn]; ++num_cen_lines; break; } glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( 0.0, (double)width, 0.0, (double)height, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); /* Draw text backing */ glColor3f( INFODISP_TEXT_BACK_R, INFODISP_TEXT_BACK_G, INFODISP_TEXT_BACK_B ); glRasterPos2i( x + edge_dx, y + edge_dy ); glListBase( font_dlist_bases[fn] ); glCallLists( strlen(disp_str), GL_UNSIGNED_BYTE, disp_str ); /* Draw text face */ glColor3f( INFODISP_TEXT_FRONT_R, INFODISP_TEXT_FRONT_G, INFODISP_TEXT_FRONT_B ); glRasterPos2i( x, y ); glCallLists( strlen(disp_str), GL_UNSIGNED_BYTE, disp_str ); /* Finally, do next line if disp_str had newlines */ if (next_disp_str != NULL) ogl_draw_string( next_disp_str, pos_code, size ); } lightspeed-1.2a.debian.1/src/ogl-gtk2-ft.c000066400000000000000000000133711334064775200202350ustar00rootroot00000000000000#include /* Mennucc: how do we use fonts in GL ? simple, we don't ! this file contains code from gtkglext taken from: * example/font-pangoft2.c: * Simple example for text rendering with PangoFT2. * License: LGPL * Copyright: written by Naofumi Yasufuku this code is currently unused and is probably not working;but it would support UTF-8 */ static gboolean gl_tex_pango_ft2_render_layout (PangoLayout *layout, GLuint *texture, GLfloat *s0, GLfloat *s1, GLfloat *t0, GLfloat *t1) { PangoRectangle logical_rect; FT_Bitmap bitmap; guint32 *t; GLfloat color[4]; guint32 rgb; GLfloat a; guint8 *row, *row_end; int i; if (text_texture.size == 0) return FALSE; pango_layout_get_extents (layout, NULL, &logical_rect); if (logical_rect.width == 0 || logical_rect.height == 0) return FALSE; bitmap.rows = PANGO_PIXELS (logical_rect.height); bitmap.width = PANGO_PIXELS (logical_rect.width); /* Ad hoc :-p */ if (bitmap.width > text_texture.size || bitmap.rows > text_texture.size) return FALSE; bitmap.pitch = bitmap.width; bitmap.buffer = g_malloc (bitmap.rows * bitmap.width); bitmap.num_grays = 256; bitmap.pixel_mode = ft_pixel_mode_grays; memset (bitmap.buffer, 0, bitmap.rows * bitmap.width); pango_ft2_render_layout (&bitmap, layout, PANGO_PIXELS (-logical_rect.x), 0); glGetFloatv (GL_CURRENT_COLOR, color); #if !defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN rgb = ((guint32) (color[0] * 255.0)) | (((guint32) (color[1] * 255.0)) << 8) | (((guint32) (color[2] * 255.0)) << 16); #else rgb = (((guint32) (color[0] * 255.0)) << 24) | (((guint32) (color[1] * 255.0)) << 16) | (((guint32) (color[2] * 255.0)) << 8); #endif a = color[3]; row = bitmap.buffer + bitmap.rows * bitmap.width; /* past-the-end */ row_end = bitmap.buffer; /* beginning */ t = (guint32 *) text_texture.texels; if (a == 1.0) { do { row -= bitmap.width; for (i = 0; i < bitmap.width; i++) #if !defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN *t++ = rgb | (((guint32) row[i]) << 24); #else *t++ = rgb | ((guint32) row[i]); #endif } while (row != row_end); } else { do { row -= bitmap.width; for (i = 0; i < bitmap.width; i++) #if !defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN *t++ = rgb | (((guint32) (a * row[i])) << 24); #else *t++ = rgb | ((guint32) (a * row[i])); #endif } while (row != row_end); } glPixelStorei (GL_UNPACK_ALIGNMENT, 4); glBindTexture (GL_TEXTURE_2D, text_texture.name); #if !defined(GL_VERSION_1_2) glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, bitmap.width, bitmap.rows, GL_RGBA, GL_UNSIGNED_BYTE, text_texture.texels); #else glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, bitmap.width, bitmap.rows, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, text_texture.texels); #endif *texture = text_texture.name; *s0 = 0.0; *s1 = (GLfloat) bitmap.width / (GLfloat) text_texture.size; *t0 = 0.0; *t1 = (GLfloat) bitmap.rows / (GLfloat) text_texture.size; g_free (bitmap.buffer); return TRUE; } void ogl_draw_string_gtk2(const camera *cam, const gchar *text,int pos_code) { g_return_if_fail(cam && text && cam->ogl_w); g_return_if_fail(GDK_IS_DRAWABLE (cam->ogl_w->window)); //pixmap = gdk_pixmap_new( cam->ogl_w->window, width, height, -1); PangoLayout *layout = gtk_widget_create_pango_layout (cam->ogl_w->window, text); //PangoContext *context PangoFontDescription *fontdesc = pango_font_description_from_string ("Sans 12"); //gdk_draw_layout (..., layout); pango_layout_set_font_description (layout, fontdesc); //PangoLayout *layout = pango_layout_new (ft2_context); pango_layout_set_font_description (layout, fontdesc); pango_layout_set_width (layout, PANGO_SCALE * 200); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); gdk_draw_layout (cam->ogl_w , cam->ogl_w->style->fg_gc[0], cam->width/2, cam->height/2,layout); return; //pango_layout_set_text (layout, text, -1); GLuint texture; GLfloat s0, s1, t0, t1; gboolean ret = gl_tex_pango_ft2_render_layout (layout, &texture, &s0, &s1, &t0, &t1); if (ret) { glPushMatrix (); //glTranslatef (0.0, -text_z * TANGENT, text_z + 2.0); // glRotatef (ANGLE, 1.0, 0.0, 0.0); glEnable (GL_TEXTURE_2D); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture (GL_TEXTURE_2D, texture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBegin (GL_QUADS); glTexCoord2f (s0, t0); glVertex3f (-1.0, 0.0, 1.0); glTexCoord2f (s0, t1); glVertex3f (-1.0, 0.0, -1.0); glTexCoord2f (s1, t1); glVertex3f ( 1.0, 0.0, -1.0); glTexCoord2f (s1, t0); glVertex3f ( 1.0, 0.0, 1.0); glEnd (); glDisable (GL_BLEND); glDisable (GL_TEXTURE_2D); glPopMatrix (); } pango_font_description_free (fontdesc); g_object_unref (layout); } void ogl_draw_string( const void *data, int message, int size ) { static camera *cam=NULL; switch (message) { case INITIALIZE: break; case RESET: cam = (camera *)data; break; default: { char *text = (char *)data; ogl_draw_string_gtk2(cam, text, message); } } } lightspeed-1.2a.debian.1/src/ogl-gtk2.c000066400000000000000000000145711334064775200176310ustar00rootroot00000000000000 /* Mennucc: how do we use fonts in GL ? simple, we don't ! http://www.opengl.org/resources/features/fontsurvey/ shows a lot of examples who need extra libraries; this file contains code from gtkglext taken from: * example/font.c: * Simple example for text rendering with PangoFT2. * License: LGPL * Copyright: written by Naofumi Yasufuku this code does not work very well and it does not support UTF-8 */ #include "lightspeed.h" gint my_gdk_string_width(PangoFontDescription *fontdesc,const gchar *text) { gint width,height; g_return_val_if_fail(text,100); PangoLayout *layout = gtk_widget_create_pango_layout (usr_cams[0]->ogl_w, text); g_return_val_if_fail(layout,100); pango_layout_set_font_description (layout, fontdesc); pango_layout_get_pixel_size (layout, &width, &height); g_object_unref (layout); return width; } #include "gtkglext-workaround.c" /* Draws a string in the viewport * Meaning of args can vary, see initial switch statement * "size" specifies size of text: 0 (small), 1 (medium) or 2 (large) * NOTE: This function requires some pre-existing state; namely, the target * GL context must already be made current as well as properly initialized * (see ogl_blank( ) or info_display( ) to see what I mean) */ void ogl_draw_string( const void *data, int message, int size ) { static PangoFontDescription **fonts; static unsigned int *font_dlist_bases; static int *font_heights; static int width, height; static int fn_big; static int num_tl_lines, num_tr_lines, num_bl_lines, num_br_lines; static int num_cen_lines; const char *test_str = "XXXX XXXX XXXX XXXX"; camera *cam; int pos_code; int edge_dx = 1, edge_dy = 1; int x = 0, y = 0; int fn; int i; char str_buf[256]; char *disp_str; char *next_disp_str; switch (message) { case INITIALIZE: /* First-time initialization */ fonts = xmalloc( num_font_sizes * sizeof(PangoFontDescription *)); font_dlist_bases = xmalloc( num_font_sizes * sizeof(unsigned int *) ); font_heights = xmalloc( num_font_sizes * sizeof(int *) ); for (i = 0; i < num_font_sizes; i++) { PangoFontDescription *font_descr = fonts[i] = pango_font_description_new(); /* Mennucc: according to http://developer.gnome.org/dotplan/porting/ar01s10.html "Sans" is always guaranteed to exist */ pango_font_description_set_family(font_descr,"Sans"); pango_font_description_set_size(font_descr,(i+10)*PANGO_SCALE); font_dlist_bases[i] = glGenLists( 192 ); /* Mennucc: see in file gtkglext-workaround.c Also note that gdk_gl_font_use_pango_font relies on PangoX that is now deprecated. */ PangoFont *pango_font = my_gdk_gl_font_use_pango_font(font_descr, 0,192,font_dlist_bases[i]); if (pango_font == NULL) { printf( "ERROR: Cannot load font: %s\n", pango_font_description_to_string(font_descr)); fflush( stdout ); continue; } PangoFontMetrics *font_metrics = pango_font_get_metrics (pango_font, NULL); font_heights[i] = pango_font_metrics_get_ascent(font_metrics) + pango_font_metrics_get_descent(font_metrics); pango_font_metrics_unref(font_metrics); pango_font_description_free(font_descr); } return; case RESET: /* Once-per-GL-redraw initialization */ g_return_if_fail(cam); cam = (camera *)data; /* Get GL widget dimensions */ width = cam->width; height = cam->height; /* Reset line counters */ num_tl_lines = 0; num_tr_lines = 0; num_bl_lines = 0; num_br_lines = 0; num_cen_lines = 0; /* Determine upper limit on the font sizes we should use */ for (i = 0; i < num_font_sizes; i++) { fn_big = i; /* font number of "big" (size 2) font */ /* Test string should be minimally 1/3 viewport width */ if (my_gdk_string_width( fonts[i], test_str ) > (width / 3)) break; } return; default: pos_code = message; disp_str = (char *)data; break; } g_return_if_fail(disp_str); /* Check string for newlines, and queue if necessary */ i = strcspn( disp_str, "\n" ); if (i < strlen( disp_str )) { strcpy( str_buf, disp_str ); str_buf[i] = '\0'; disp_str = str_buf; next_disp_str = &str_buf[i + 1]; } else next_disp_str = NULL; /* Determine which (proportional) font size to use */ fn = MIN(fn_big, MAX(0, fn_big - 2 + size)); /* 0 <= fn <= fn_big */ /* x coord. of base point */ switch (pos_code) { case POS_TOP_LEFT: case POS_BOTTOM_LEFT: x = width / 100; edge_dx = 1; break; case POS_TOP_RIGHT: case POS_BOTTOM_RIGHT: x = (width * 99) / 100; x -= my_gdk_string_width( fonts[fn], disp_str ); edge_dx = -1; break; case POS_CENTER: x = width / 2; x -= my_gdk_string_width( fonts[fn], disp_str ) / 2; edge_dx = 0; break; default: #ifdef DEBUG crash( "ogl_draw_string( ): invalid position code" ); #endif return; } /* y coord. of base point */ switch (pos_code) { case POS_BOTTOM_LEFT: case POS_BOTTOM_RIGHT: y = height / 100; edge_dy = 1; break; case POS_TOP_LEFT: case POS_TOP_RIGHT: y = (99 * height) / 100; y -= font_heights[fn]; edge_dy = -1; break; case POS_CENTER: y = height / 2; y -= font_heights[fn] / 2; edge_dy = -1; break; } /* This makes multi-line readouts possible */ switch (pos_code) { case POS_TOP_LEFT: y -= num_tl_lines * font_heights[fn]; ++num_tl_lines; break; case POS_TOP_RIGHT: y -= num_tr_lines * font_heights[fn]; ++num_tr_lines; break; case POS_BOTTOM_LEFT: y += num_bl_lines * font_heights[fn]; ++num_bl_lines; break; case POS_BOTTOM_RIGHT: y += num_br_lines * font_heights[fn]; ++num_br_lines; break; case POS_CENTER: y -= num_cen_lines * font_heights[fn]; ++num_cen_lines; break; } glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( 0.0, (double)width, 0.0, (double)height, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); /* Draw text backing */ glColor3f( INFODISP_TEXT_BACK_R, INFODISP_TEXT_BACK_G, INFODISP_TEXT_BACK_B ); glRasterPos2i( x + edge_dx, y + edge_dy ); glListBase( font_dlist_bases[fn] ); glCallLists( strlen(disp_str), GL_UNSIGNED_BYTE, disp_str ); /* Draw text face */ glColor3f( INFODISP_TEXT_FRONT_R, INFODISP_TEXT_FRONT_G, INFODISP_TEXT_FRONT_B ); glRasterPos2i( x, y ); glCallLists( strlen(disp_str), GL_UNSIGNED_BYTE, disp_str ); /* Finally, do next line if disp_str had newlines */ if (next_disp_str != NULL) ogl_draw_string( next_disp_str, pos_code, size ); } lightspeed-1.2a.debian.1/src/ogl.c000066400000000000000000000263201334064775200167570ustar00rootroot00000000000000/* ogl.c */ /* Main OpenGL routines */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Initialize OpenGL state * (will be connected to the GL widget's "realize" signal) */ void ogl_initialize( GtkWidget *ogl_w, void *nothing ) { float light0_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; float light0_diffuse[] = { 0.625, 0.625, 0.625, 1.0 }; float light0_specular[] = { 1.0, 1.0, 1.0, 1.0 }; float light_model_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; float light_pos[] = { 0.0, 0.0, 0.0, 1.0 }; int on_screen = TRUE; if (ogl_w == NULL) on_screen = FALSE; if (on_screen) GTKGL_TEMP_begingl(ogl_w); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glLightfv( GL_LIGHT0, GL_AMBIENT, light0_ambient ); glLightfv( GL_LIGHT0, GL_DIFFUSE, light0_diffuse ); glLightfv( GL_LIGHT0, GL_SPECULAR, light0_specular ); glRotatef( -90.0, 1.0, 0.0, 0.0 ); glRotatef( -90.0, 0.0, 0.0, 1.0 ); glLightfv( GL_LIGHT0, GL_POSITION, light_pos ); glLightModelfv( GL_LIGHT_MODEL_AMBIENT, light_model_ambient ); glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE ); glEnable( GL_COLOR_MATERIAL ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LESS ); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glShadeModel( GL_SMOOTH ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); /* Initialize ogl_draw_string for primary viewport and pixmap buffers * (other viewports will get this via shared context) */ if ((assoc_cam_id( ogl_w ) == 0) || !on_screen) ogl_draw_string( NULL, INITIALIZE, NIL ); if (on_screen) { GTKGL_TEMP_endgl(ogl_w); /* Call ogl_resize( ) to finish viewport initialization */ ogl_resize( ogl_w, NULL, NULL ); } #ifdef DEBUG if (on_screen) printf( "Initialized viewport %d\n", assoc_cam_id( ogl_w ) ); else printf( "Initialized off-screen pixmap buffer\n" ); fflush( stdout ); #endif } /* Change viewport size (after whatever window size adjustment) * Will be connected to the "configure_event" signal * Note: For some reason, this gets called once before ogl_initialize( )... */ int ogl_resize( GtkWidget *ogl_w, GdkEventConfigure *ev_config, void *nothing ) { static float dummy; int width, height; int i; width = ogl_w->allocation.width; height = ogl_w->allocation.height; GTKGL_TEMP_begingl(ogl_w); glViewport( 0, 0, width, height ); GTKGL_TEMP_endgl(ogl_w); /* Update dimensions in camera struct */ i = assoc_cam_id( ogl_w ); usr_cams[i]->width = width; usr_cams[i]->height = height; /* Recalibrate framerate */ profile( PROFILE_FRAMERATE_RESET ); dummy = 1.0; transition( &dummy, FALSE, TRANS_LINEAR, 1.0, 0.0, -1 ); #ifdef DEBUG printf( "Resized camera %d to %dx%d\n", i, width, height ); fflush( stdout ); #endif return FALSE; } /* Refresh a viewport (static redraw) * Will be connected to the "expose_event" signal */ int ogl_refresh( GtkWidget *ogl_w, GdkEventExpose *ev_expose, void *nothing ) { int i; i = assoc_cam_id( ogl_w ); queue_redraw( i ); #ifdef SUPER_DEBUG printf( "Refresh camera %d\n", i ); fflush( stdout ); #endif return FALSE; } /* Redraws the viewport of the camera indicated by cam_id * A cam_id of -1 means we're drawing the primary view into a pixmap buffer */ void ogl_draw( int cam_id ) { camera *cam; ogl_object *obj; float r,g,b; float fr_x, fr_y; int drawing_to_screen = TRUE; int o, i, v; i = 0; /* Avoid pesky "unused variable..." warnings */ v = 0; /* (if they come up-- see the #ifdef's) */ #ifdef SUPER_DEBUG if (cam_id >= 0) printf( "Drawing camera %d...", cam_id ); else printf( "Drawing into off-screen pixmap..." ); fflush( stdout ); #endif if (cam_id < 0) { drawing_to_screen = FALSE; cam = &out_cam; cam_id = 0; } else cam = usr_cams[cam_id]; /* Apply relativistic distortions for this view */ if (drawing_to_screen) { profile( PROFILE_WARP_BEGIN ); warp( WARP_DISTORT, &cam->pos ); profile( PROFILE_WARP_DONE ); profile( PROFILE_OGLDRAW_BEGIN ); GTKGL_TEMP_begingl(cam->ogl_w); } else warp( WARP_DISTORT, &cam->pos ); r = background.r; g = background.g; b = background.b; if (dgamma_correct) { r = dgamma_lut[(int)(r * LUT_RES)]; g = dgamma_lut[(int)(g * LUT_RES)]; b = dgamma_lut[(int)(b * LUT_RES)]; } glClearColor( r, g, b, 0.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); /* Set view frustum (a.k.a. field of view) */ glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); fr_x = cam->near_clip * tan( RAD(cam->fov) / 2 ); fr_y = fr_x / ((float)cam->width / (float)cam->height); glFrustum( - fr_x, fr_x, - fr_y, fr_y, cam->near_clip, cam->far_clip ); /* (Re)initialize transformation matrix */ glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); /* Initialize the coordinate system to correct alignment */ glRotatef( -90.0, 1.0, 0.0, 0.0 ); glRotatef( -90.0, 0.0, 0.0, 1.0 ); /* Perform world transformations */ glTranslatef( - cam->distance, 0.0, 0.0 ); glRotatef( cam->theta, 0.0, 1.0, 0.0 ); glRotatef( - cam->phi, 0.0, 0.0, 1.0 ); glTranslatef( - cam->target.x, - cam->target.y, - cam->target.z ); /* For wireframe mode, if active */ glLineWidth( 2 ); /* Draw all vehicle objects */ for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; /* Execute "before" display list, if there is one */ if (obj->pre_dlist != 0) glCallList( obj->pre_dlist ); #ifdef GL_VERSION_1_1 glInterleavedArrays( GL_C4F_N3F_V3F, sizeof(ogl_point), obj->iarrays ); #ifdef GL_VERSION_1_2 glDrawRangeElements( obj->type, 0, obj->num_vertices - 1, obj->num_indices, GL_UNSIGNED_INT, obj->indices ); #else glDrawElements( obj->type, obj->num_indices, GL_UNSIGNED_INT, obj->indices ); #endif /* else GL_VERSION_1_2 */ #else /* Fine, we'll do this the old-fashioned way */ glBegin( obj->type ); for (i = 0; i < obj->num_indices; i++) { v = obj->indices[i]; glColor4fv( &obj->iarrays[v].r ); glNormal3fv( &obj->iarrays[v].nx ); glVertex3fv( &obj->iarrays[v].x ); } glEnd( ); #endif /* else GL_VERSION_1_1 */ /* Execute "after" display list if there is one */ if (obj->post_dlist != 0) glCallList( obj->post_dlist ); } /* Draw all active auxiliary objects */ auxiliary_objects( AUXOBJS_DRAW, cam_id ); #if 0 /* Draw normal lines (a.k.a. "hedgehogification") * (for debugging purposes) */ if (FALSE) { glLineWidth( 1 ); glBegin( GL_LINES ); for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; for (v = 0; v < obj->num_vertices; v++) { float x, y, z; x = obj->vertices[v].x; y = obj->vertices[v].y; z = obj->vertices[v].z; glVertex3f( x, y, z ); x += obj->normals[v].x; y += obj->normals[v].y; z += obj->normals[v].z; glVertex3f( x, y, z ); } } glEnd( ); } #endif /* 0 */ /* Initialize string drawer (i.e. inform of viewport dimensions) */ ogl_draw_string( cam, RESET, NIL ); /* Finally, draw info display (nothing if it's turned off) * Only the primary camera or an off-screen image gets this */ if ((cam_id == 0) || !drawing_to_screen) info_display( INFODISP_DRAW, NIL ); if (drawing_to_screen) { #ifdef HAVE_GTK1 gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) ); #else GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(cam->ogl_w); if (gdk_gl_drawable_is_double_buffered (gldrawable)) gdk_gl_drawable_swap_buffers (gldrawable); else glFlush (); #endif GTKGL_TEMP_endgl(cam->ogl_w); profile( PROFILE_OGLDRAW_DONE ); cam->redraw = FALSE; } #ifdef SUPER_DEBUG printf( "done.\n" ); fflush( stdout ); #endif } /* Blanks out a viewport, optionally displaying a [centered] message */ void ogl_blank( int cam_id, const char *blank_message ) { camera *cam; cam = usr_cams[cam_id]; GTKGL_TEMP_begingl((cam->ogl_w) ); glClearColor( background.r, background.g, background.b, 0.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); if (blank_message != NULL) { /* Tell ogl_draw_string( ) about GL widget dimensions */ ogl_draw_string( cam, RESET, NIL ); glDisable( GL_DEPTH_TEST ); glDisable( GL_LIGHTING ); ogl_draw_string( blank_message, POS_CENTER, 2 ); glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); } glFlush (); #ifdef HAVE_GTK1 gtk_gl_area_swapbuffers( GTK_GL_AREA(cam->ogl_w) ); #else GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(cam->ogl_w); if (gdk_gl_drawable_is_double_buffered (gldrawable)) gdk_gl_drawable_swap_buffers (gldrawable); #endif GTKGL_TEMP_endgl(cam->ogl_w); } /* The GL widget begins life here * If the primary GL widget (camera 0) has already been defined, create a * new one with shared context, to let ogl_draw_string( ) also work in the * new window, and simplify display list management a good bit */ GtkWidget * ogl_make_widget( void ) { GtkWidget *primary_ogl_w; #ifdef HAVE_GTK1 int gl_area_attributes[] = { GDK_GL_RGBA, GDK_GL_RED_SIZE, 1, GDK_GL_GREEN_SIZE, 1, GDK_GL_BLUE_SIZE, 1, GDK_GL_DEPTH_SIZE, 1, GDK_GL_DOUBLEBUFFER, GDK_GL_NONE }; #endif primary_ogl_w = usr_cams[0]->ogl_w; #ifdef HAVE_GTK1 if (primary_ogl_w == NULL) return gtk_gl_area_new( gl_area_attributes ); else return gtk_gl_area_share_new( gl_area_attributes, GTK_GL_AREA(primary_ogl_w) ); #else GtkWidget *drawingarea; drawingarea = gtk_drawing_area_new (); gtk_widget_set_name (drawingarea, "drawingarea"); gtk_widget_show (drawingarea); #ifdef MAYBE GTK_WIDGET_SET_FLAGS (drawingarea, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (drawingarea, GTK_CAN_DEFAULT); gtk_widget_set_events (drawingarea, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK); #endif g_assert(gtk_widget_set_gl_capability (drawingarea, glconfig, NULL,TRUE, GDK_GL_RGBA_TYPE)); return drawingarea; #endif } #ifdef SILLY_DEBUG /* Mennucc: a silly object to display, just to debug GL settings */ #include void ogl_spinner() { //static GLUquadricObj *qobj = NULL; if(!qobj) { qobj=gluNewQuadric (); qobj = gluNewQuadric (); gluQuadricDrawStyle (qobj, GLU_FILL); glNewList (1, GL_COMPILE); gluCylinder(qobj, 0.10,0.15, 0.40, 10,10); glEndList (); } static int r=0,s=0; s+=20; r+=10; glPushMatrix( ); glRotatef(r, 0.0, 1.0, 1.0 ); glRotatef(s, 1.0, 0.0, 1.0 ); glCallList (1); glPopMatrix(); } #endif /* end ogl.c */ lightspeed-1.2a.debian.1/src/read3ds.c000066400000000000000000001704771334064775200175400ustar00rootroot00000000000000/* read3ds.c */ /* Mini-library for loading .3DS files * 3D Studio loading code by Jare/Iguana et. al. (see further down for details) * API interface & portability mods by Straker Skunk * * I wrote this interface only as far as I needed it. Much is lacking; in * particular, material property loading and light definitions. * Anyone want a go at it? * * NOTE: This code is in NO WAY connected to AutoDesk Inc. or Kinetix Inc. * Jare expressed concern that he might have violated AutoDesk's * intellectual property in releasing this 3DS interpreter; however, he * reverse-engineered the format in perfectly legal manner, and made use * of equally legitimate documentation written by others on the Internet. * This library contains ABSOLUTELY NO CODE from AutoDesk's own 3DS File * Toolkit, which I believe was even released subsequent to the authoring * of this interpreter. * * THIS FILE IS IN THE PUBLIC DOMAIN */ #include "read3ds.h" int r3ds_read_uint8( uint8 *data, int count, FILE *f ) { int n; n = fread( data, sizeof(uint8), count, f ); if (n != count) return FALSE; /* failure */ return TRUE; /* success */ } int r3ds_read_uint16( uint16 *data, int count, FILE *f ) { uint8 bytes[2]; int i, rs = TRUE; /* rs == return status */ for (i = 0; i < count; i++) { rs = rs && r3ds_read_uint8( bytes, 2, f ); data[i] = ((uint16)bytes[1] << 8) | (uint16)bytes[0]; } return rs; } int r3ds_read_uint32( uint32 *data, int count, FILE *f ) { uint8 bytes[4]; int i, rs = TRUE; for (i = 0; i < count; i++) { rs = rs && r3ds_read_uint8( bytes, 4, f ); data[i] = ((uint32)bytes[3] << 24) | ((uint32)bytes[2] << 16) | ((uint32)bytes[1] << 8) | (uint32)bytes[0]; } return rs; } int r3ds_read_float( float *data, int count, FILE *f ) { uint32 fpdata; int i, rs = TRUE; for (i = 0; i < count; i++) { rs = rs && r3ds_read_uint32( &fpdata, 1, f ); data[i] = *((float *)&fpdata); } return rs; } int r3ds_file_is_3ds( const char *filename ) { FILE *file_3ds; int filesize; uint16 chunk_id; uint32 chunk_len; file_3ds = fopen( filename, "rb" ); if (file_3ds == NULL) return 0; /* Get file size */ fseek( file_3ds, 0, SEEK_END ); filesize = ftell( file_3ds ); fseek( file_3ds, 0, SEEK_SET ); /* Read in main chunk header */ r3ds_read_uint16( &chunk_id, 1, file_3ds ); r3ds_read_uint32( &chunk_len, 1, file_3ds ); fclose( file_3ds ); if (chunk_id != 0x4D4D) return 0; /* Check that file size is *around* what it should be */ if (ABS(filesize - (int)chunk_len) > 16) return 0; /* Yes, this *does* appear to be a valid 3D Studio file */ return 1; } int r3ds_file_is_prj( const char *filename ) { FILE *file_prj; int filesize; uint16 chunk_id; uint32 chunk_len; file_prj = fopen( filename, "rb" ); if (file_prj == NULL) return 0; /* Get file size */ fseek( file_prj, 0, SEEK_END ); filesize = ftell( file_prj ); fseek( file_prj, 0, SEEK_SET ); /* Read in main chunk header */ r3ds_read_uint16( &chunk_id, 1, file_prj ); r3ds_read_uint32( &chunk_len, 1, file_prj ); fclose( file_prj ); if (chunk_id != 0xC23D) return 0; /* Check that file size is *around* what it should be */ if (ABS(filesize - (int)chunk_len) > 16) return 0; /* Yes, this does appear to be a valid 3D Studio project file */ return 1; } void r3ds_build( int data_id, const void *data ) { static r3ds_object **objects; static r3ds_light **lights; static r3ds_camera **cameras; static r3ds_trimesh **trimeshes; static r3ds_material *materials; static r3ds_object *obj; static r3ds_light *lite; /* A better abbreviation, anyone? */ static r3ds_camera *cam; static r3ds_trimesh *tmesh; static r3ds_material *mat; static r3ds_color24 *color24; static r3ds_color24 default_color24 = { 128, 128, 128 }; static float inches_per_unit; static int num_objects; static int num_lights; static int num_cameras; static int num_trimeshes; static int num_materials; static int vert_alloc = 0; static int tri_alloc = 0; static int cur_vert = 0; static int cur_tri = 0; static int cur_mat; r3ds_scene *scene; r3ds_triangle *tri; r3ds_point *vert; uint32 *dwordp; float *floatp; int *intp; int i; char *name; switch (data_id) { case R3DS_INITIALIZE: inches_per_unit = 1.0; objects = NULL; lights = NULL; cameras = NULL; trimeshes = NULL; materials = NULL; color24 = NULL; num_objects = 0; num_lights = 0; num_cameras = 0; num_trimeshes = 0; num_materials = 0; break; case R3DS_PROJECT_SCALE: floatp = (float *)data; inches_per_unit = *floatp; break; /* Object definition input * (to be followed by light/camera/trimesh def. input */ case R3DS_NEW_OBJECT: name = (char *)data; ++num_objects; objects = xrealloc( objects, num_objects * sizeof(r3ds_object *) ); obj = xmalloc( sizeof(r3ds_object) ); obj->type = R3DS_OBJ_UNDEFINED; obj->name = xstrdup( name ); objects[num_objects - 1] = obj; #ifdef R3DS_VERBOSE printf( "\n\nNew object: \"%s\"\n", name ); #endif break; /* Light definition input */ /* INCOMPLETE */ case R3DS_DEF_LIGHT: ++num_lights; lights = xrealloc( lights, num_lights * sizeof(r3ds_light *) ); lite = xrealloc( obj, sizeof(r3ds_light) ); lite->type = R3DS_OBJ_LIGHT; objects[num_objects - 1] = R3DS_OBJECT(lite); lights[num_lights - 1] = lite; #ifdef R3DS_VERBOSE printf( "Light\n" ); #endif break; /* Camera definiton input */ case R3DS_DEF_CAMERA: floatp = (float *)data; ++num_cameras; cameras = xrealloc( cameras, num_cameras * sizeof(r3ds_camera *) ); cam = xrealloc( obj, sizeof(r3ds_camera) ); cam->type = R3DS_OBJ_CAMERA; cam->x = floatp[0]; cam->y = floatp[1]; cam->z = floatp[2]; cam->targ_x = floatp[3]; cam->targ_y = floatp[4]; cam->targ_z = floatp[5]; cam->bank = floatp[6]; cam->lens = floatp[7]; objects[num_objects - 1] = R3DS_OBJECT(cam); cameras[num_cameras - 1] = cam; #ifdef R3DS_VERBOSE printf( "Camera\n" ); #endif break; /* Triangle mesh definition input */ case R3DS_DEF_TRIMESH: ++num_trimeshes; trimeshes = xrealloc( trimeshes, num_trimeshes * sizeof(r3ds_trimesh *) ); tmesh = xrealloc( obj, sizeof(r3ds_trimesh) ); tmesh->type = R3DS_OBJ_TRIMESH; tmesh->num_verts = 0; tmesh->num_tris = 0; objects[num_objects - 1] = R3DS_OBJECT(tmesh); trimeshes[num_trimeshes - 1] = tmesh; vert_alloc = 0; cur_vert = 0; tri_alloc = 0; cur_tri = 0; cur_mat = -1; #ifdef R3DS_VERBOSE printf( "Triangle mesh\n" ); #endif break; case R3DS_NUM_VERTS: i = *((int *)data); vert_alloc = i; tmesh->num_verts = i; if (i > 0) tmesh->verts = xmalloc( i * sizeof(r3ds_point) ); for (i = 0; i < tmesh->num_verts; i++) { vert = &tmesh->verts[i]; vert->x = 0.0; vert->y = 0.0; vert->z = 0.0; vert->u = 0.0; vert->v = 0.0; } #ifdef R3DS_VERBOSE printf( "\tBegin %d vertices\n", tmesh->num_verts ); #endif break; case R3DS_VERT: floatp = (float *)data; if (cur_vert >= vert_alloc) break; vert = &tmesh->verts[cur_vert]; vert->x = floatp[0]; vert->y = floatp[1]; vert->z = floatp[2]; #ifdef R3DS_VERBOSE printf( "\t\tVertex %d: (%.2f, %.2f, %.2f)\n", cur_vert, floatp[0], floatp[1], floatp[2] ); #endif ++cur_vert; break; case R3DS_NUM_VERT_MAPPINGS: cur_vert = 0; #ifdef R3DS_VERBOSE printf( "\n" ); #endif break; case R3DS_VERT_MAPPING: floatp = (float *)data; if (cur_vert >= vert_alloc) break; vert = &tmesh->verts[cur_vert]; vert->u = floatp[0]; vert->v = floatp[1]; #ifdef R3DS_VERBOSE printf( "\t\tMapping %d: (%.2f, %.2f)\n", cur_vert, floatp[0], floatp[1] ); #endif ++cur_vert; break; case R3DS_NUM_TRIS: i = *((int *)data); tri_alloc = i; tmesh->num_tris = i; if (i > 0) tmesh->tris = xmalloc( i * sizeof(r3ds_triangle) ); for (i = 0; i < tmesh->num_tris; i++) { tri = &tmesh->tris[i]; tri->a = 0.0; tri->b = 0.0; tri->c = 0.0; tri->flags = 0; tri->mat_id = -1; tri->smgroups = 0; } #ifdef R3DS_VERBOSE printf( "\tBegin %d triangles\n", tmesh->num_tris ); #endif break; case R3DS_TRI_FACE: intp = (int *)data; if (cur_tri >= tri_alloc) break; tri = &tmesh->tris[cur_tri]; tri->a = CLAMP(intp[0], 0, vert_alloc - 1); tri->b = CLAMP(intp[1], 0, vert_alloc - 1); tri->c = CLAMP(intp[2], 0, vert_alloc - 1); tri->flags = (uint16)intp[3]; #ifdef R3DS_VERBOSE printf( "\t\tTriangle %d: %d--%d--%d Flags=0x%X\n", cur_tri, wordp[0], wordp[1], wordp[2], wordp[3] ); #endif ++cur_tri; break; case R3DS_TRI_MATERIAL_CURRENT: name = (char *)data; cur_mat = -1; /* default material */ /* Find material index */ for (i = 0; i < num_materials; i++) if (!strcmp( name, materials[i].name )) { cur_mat = i; break; } #ifdef R3DS_VERBOSE printf( "\tBegin triangles with material: \"%s\" (%d)\n", name, cur_mat ); #endif break; case R3DS_TRI_MATERIAL: i = *((int *)data); if ((i < 0) || (i >= tri_alloc)) break; tmesh->tris[i].mat_id = cur_mat; #ifdef R3DS_VERBOSE printf( "\t\tTriangle %d\n", i ); #endif break; case R3DS_BEGIN_TRI_SMOOTH: cur_tri = 0; #ifdef R3DS_VERBOSE printf( "\tBegin smoothing group definitions\n" ); #endif break; case R3DS_TRI_SMOOTH: dwordp = (uint32 *)data; if (cur_tri >= tri_alloc) break; tmesh->tris[cur_tri].smgroups = *dwordp; #ifdef R3DS_VERBOSE printf( "\t\tTriangle %d:", cur_tri ); if (R3DS_TRI_IN_SMGROUP(&tmesh->tris[cur_tri],0)) printf( " none" ); else for (i = 1; i <= 32; i++) if (R3DS_TRI_IN_SMGROUP(&tmesh->tris[cur_tri],i)) printf( " %d", i ); printf( "\n" ); #endif ++cur_tri; break; case R3DS_ROT_MATRIX: floatp = (float *)data; for (i = 0; i < 9; i++) tmesh->rot_matrix[i] = floatp[i]; break; case R3DS_TRANS_MATRIX: floatp = (float *)data; for (i = 0; i < 3; i++) tmesh->trans_matrix[i] = floatp[i]; break; /* Material definition input */ case R3DS_NEW_MATERIAL: name = (char *)data; ++num_materials; materials = xrealloc( materials, num_materials * sizeof(r3ds_material) ); mat = &materials[num_materials - 1]; mat->name = xstrdup( name ); memcpy( &mat->ambient, &default_color24, sizeof(r3ds_color24) ); memcpy( &mat->diffuse, &default_color24, sizeof(r3ds_color24) ); memcpy( &mat->specular, &default_color24, sizeof(r3ds_color24) ); mat->two_sided = 0; mat->texmap_file = NULL; mat->refmap_file = NULL; #ifdef R3DS_VERBOSE printf( "\nNew material: \"%s\" (%d)\n", name, num_materials - 1 ); #endif break; case R3DS_MAT_AMBIENT_COLOR: color24 = &mat->ambient; #ifdef R3DS_VERBOSE printf( "\tAmbient color: " ); #endif break; case R3DS_MAT_DIFFUSE_COLOR: color24 = &mat->diffuse; #ifdef R3DS_VERBOSE printf( "\tDiffuse color: " ); #endif break; case R3DS_MAT_SPECULAR_COLOR: color24 = &mat->specular; #ifdef R3DS_VERBOSE printf( "\tSpecular color: " ); #endif break; case R3DS_MAT_2SIDED: mat->two_sided = 1; #ifdef R3DS_VERBOSE printf( "\tMaterial is 2-sided\n" ); #endif break; case R3DS_COLOR24: intp = (int *)data; if (color24 != NULL) { color24->red = CLAMP(intp[0], 0, 255); color24->green = CLAMP(intp[1], 0, 255); color24->blue = CLAMP(intp[2], 0, 255); #ifdef R3DS_VERBOSE printf( "(%d, %d, %d)\n", color24->red, color24->green, color24->blue ); #endif } color24 = NULL; break; /* Output */ case R3DS_GET_SCENE: scene = (r3ds_scene *)data; scene->inches_per_unit = inches_per_unit; scene->num_objs = num_objects; scene->objs = objects; scene->num_lites = num_lights; scene->lites = lights; scene->num_cams = num_cameras; scene->cams = cameras; scene->num_tmeshes = num_trimeshes; scene->tmeshes = trimeshes; scene->num_mats = num_materials; scene->mats = materials; break; } #ifdef R3DS_VERBOSE fflush( stdout ); #endif } r3ds_scene * read3ds( const char *filename ) { r3ds_scene *scene; FILE *file_3ds; int filesize; file_3ds = fopen( filename, "rb" ); if (file_3ds == NULL) return NULL; /* Get file size */ fseek( file_3ds, 0, SEEK_END ); filesize = ftell( file_3ds ); fseek( file_3ds, 0, SEEK_SET ); /* Read file */ r3ds_build( R3DS_INITIALIZE, NULL ); r3ds_ChunkReader( file_3ds, 0, filesize ); fclose( file_3ds ); scene = xmalloc( sizeof(r3ds_scene) ); r3ds_build( R3DS_GET_SCENE, scene ); return scene; } /* Verbosely describe a light */ void r3ds_dump_light( r3ds_light *light ) { printf( "Light \"%s\"\n", light->name ); } /* Verbosely describe a camera */ void r3ds_dump_camera( r3ds_camera *cam ) { printf( "Camera \"%s\"\n", cam->name ); printf( " Location: (%.3f, %.3f, %.3f)\n", cam->x, cam->y, cam->z ); printf( " Target: (%.3f, %.3f, %.3f)\n", cam->targ_x, cam->targ_y, cam->targ_z ); printf( " Bank: %.2f Lens: %.2f\n", cam->bank, cam->lens ); } /* Verbosely describe a triangle mesh */ void r3ds_dump_trimesh( r3ds_trimesh *trimesh ) { r3ds_point *vert; r3ds_triangle *tri; int i, g; printf( "Triangle mesh \"%s\"\n", trimesh->name ); /* Vertices */ printf( " %d vertices\n", trimesh->num_verts ); for (i = 0; i < trimesh->num_verts; i++) { vert = &trimesh->verts[i]; printf( "\tVert #%d: XYZ=(%.3f, %.3f, %.3f)", i, vert->x, vert->y, vert->z ); printf( " UV=(%.3f, %.3f)\n", vert->u, vert->v ); } /* Triangles */ printf( " %d triangles\n", trimesh->num_tris ); for (i = 0; i < trimesh->num_tris; i++) { tri = &trimesh->tris[i]; printf( "\tTri #%d: %d ", i, tri->a ); if (R3DS_TRI_AB_VIS(tri)) printf( "+" ); else printf( "-" ); printf( " %d ", tri->b ); if (R3DS_TRI_BC_VIS(tri)) printf( "+" ); else printf( "-" ); printf( " %d ", tri->c ); if (R3DS_TRI_CA_VIS(tri)) printf( "+" ); else printf( "-" ); if (R3DS_TRI_U_WRAP(tri)) printf( " Uwrap" ); if (R3DS_TRI_V_WRAP(tri)) printf( " Vwrap" ); /* Smoothing groups */ printf( " SmGrps:" ); if (R3DS_TRI_IN_SMGROUP(tri,0)) printf( " none" ); else { for (g = 1; g <= 32; g++) if (R3DS_TRI_IN_SMGROUP(tri,g)) printf( " %d", g ); } printf( "\n" ); } /* Rotation matrix */ printf( " Coordinate system alignment" ); for (i = 0; i < 9; i++) { if ((i % 3) == 0) printf( "\n\t" ); printf( "% .6f ", trimesh->rot_matrix[i] ); } /* Translation matrix */ printf( "\n Coordinate system origin\n\t" ); for (i = 0; i < 3; i++) printf( "% .6f ", trimesh->trans_matrix[i] ); printf( "\n" ); fflush( stdout ); } /* Verbosely describe an object, whatever it may be */ void r3ds_dump_object( r3ds_object *obj ) { printf( "\n" ); switch (obj->type) { case R3DS_OBJ_LIGHT: r3ds_dump_light( R3DS_LIGHT(obj) ); break; case R3DS_OBJ_CAMERA: r3ds_dump_camera( R3DS_CAMERA(obj) ); break; case R3DS_OBJ_TRIMESH: r3ds_dump_trimesh( R3DS_TRIMESH(obj) ); break; case R3DS_OBJ_UNDEFINED: printf( "Object \"%s\" - undefined\n", obj->name ); break; default: printf( "Error: invalid r3ds_object\n" ); break; } } /* Deallocates an object */ void r3ds_free_object( r3ds_object *obj ) { r3ds_light *light; r3ds_camera *cam; r3ds_trimesh *tmesh; switch (obj->type) { case R3DS_OBJ_LIGHT: light = R3DS_LIGHT(obj); xfree( light->name ); xfree( light ); break; case R3DS_OBJ_CAMERA: cam = R3DS_CAMERA(obj); xfree( cam->name ); xfree( cam ); break; case R3DS_OBJ_TRIMESH: tmesh = R3DS_TRIMESH(obj); xfree( tmesh->name ); if (tmesh->num_verts > 0) xfree( tmesh->verts ); if (tmesh->num_tris > 0) xfree( tmesh->tris ); xfree( tmesh ); break; case R3DS_OBJ_UNDEFINED: xfree( obj->name ); xfree( obj ); break; #ifdef R3DS_DEBUG default: printf( "ERROR: attempted to free invalid r3ds_object\n" ); fflush( stdout ); break; #endif } } /* Deallocates a material */ void r3ds_free_material( r3ds_material *mat ) { xfree( mat->name ); if (mat->texmap_file != NULL) xfree( mat->texmap_file ); if (mat->refmap_file != NULL) xfree( mat->refmap_file ); } /* Deallocates an entire scene-- i.e. EVERYTHING */ void r3ds_free_scene( r3ds_scene *scene ) { int i; /* Free scene objects */ for (i = 0; i < scene->num_objs; i++) r3ds_free_object( scene->objs[i] ); /* Free scene materials */ for (i = 0; i < scene->num_mats; i++) r3ds_free_material( &scene->mats[i] ); /* Free pointer arrays */ if (scene->num_objs > 0) xfree( scene->objs ); if (scene->num_lites > 0) xfree( scene->lites ); if (scene->num_cams > 0) xfree( scene->cams ); if (scene->num_tmeshes > 0) xfree( scene->tmeshes ); if (scene->num_mats > 0) xfree( scene->mats ); /* Free scene itself */ xfree( scene ); } /* Pass this a triangle, and it will return the number of the FIRST smoothing * group that triangle is in (0 if not in any group) */ int r3ds_first_smgroup( r3ds_triangle *tri ) { int g; for (g = 1; g <= 32; g++) if (R3DS_TRI_IN_SMGROUP(tri,g)) return g; return 0; } /* Internal function-- rebuilds the r3ds_scene->objs array from the * separate ->lites, ->cams and ->tmeshes arrays */ void r3ds_rebuild_scene_objs( r3ds_scene *scene ) { int n,o; n = scene->num_lites + scene->num_cams + scene->num_tmeshes; scene->num_objs = n; scene->objs = xrealloc( scene->objs, n * sizeof(r3ds_object *) ); n = 0; for (o = 0; o < scene->num_lites; o++) scene->objs[n++] = R3DS_OBJECT(scene->lites[o]); for (o = 0; o < scene->num_cams; o++) scene->objs[n++] = R3DS_OBJECT(scene->cams[o]); for (o = 0; o < scene->num_tmeshes; o++) scene->objs[n++] = R3DS_OBJECT(scene->tmeshes[o]); } /* This function is mostly meant for use by r3ds_split_trimeshes( ); it takes a * pointer to an array of one trimesh, splits up the trimesh by smoothing groups * (message == -1) or materials (message == num_mats), places all the new * trimeshes into the array and returns the quantity created (or -1 on error) * Note: original trimesh always gets freed */ int r3ds_split_trimesh( r3ds_trimesh ***trimeshes_ptr, int message ) { r3ds_trimesh **group_tmeshes; r3ds_trimesh *orig_tmesh, *tmesh; r3ds_triangle *orig_tri, *tri; int num_groups; int num_new_tmeshes = 0; int *tri_counts; int *index_remap; int *vertex_remap; char name_suffix[16]; int len; int g, t, v, n; /* Create group array, triangle counters */ if (message == -1) /* R3DS_SPLIT_BY_SMGROUP */ num_groups = 33; /* Null group + smoothing groups 1-32 */ else num_groups = message + 1; /* # of materials + default finish */ group_tmeshes = xmalloc( num_groups * sizeof(r3ds_trimesh *) ); tri_counts = xmalloc( num_groups * sizeof(int) ); orig_tmesh = *trimeshes_ptr[0]; /* See how many triangles are in each potential sub-trimesh group */ for (g = 0; g < num_groups; g++) tri_counts[g] = 0; /* initialize counters first */ for (t = 0; t < orig_tmesh->num_tris; t++) { orig_tri = &orig_tmesh->tris[t]; if (message == -1) /* R3DS_SPLIT_BY_SMGROUP */ g = r3ds_first_smgroup( orig_tri ); else { g = orig_tri->mat_id; if (g == -1) /* default material */ g += num_groups; } ++tri_counts[g]; } /* For each non-empty group, create a new sub-trimesh */ for (g = 0; g < num_groups; g++) { n = tri_counts[g]; if (n == 0) { group_tmeshes[g] = NULL; continue; } ++num_new_tmeshes; /* tmesh = new sub-trimesh */ tmesh = xmalloc( sizeof(r3ds_trimesh) ); if (message == -1) /* R3DS_SPLIT_BY_SMGROUP */ sprintf( name_suffix, " (smgrp %d)", g ); else { if (g < (num_groups - 1)) sprintf( name_suffix, " (mat=%d)", g ); else sprintf( name_suffix, " (mat=default)" ); } len = strlen( orig_tmesh->name ) + strlen( name_suffix ) + 1; tmesh->name = xmalloc( len * sizeof(char) ); strcpy( tmesh->name, orig_tmesh->name ); strcat( tmesh->name, name_suffix ); tmesh->type = R3DS_OBJ_TRIMESH; tmesh->num_tris = n; tmesh->tris = xmalloc( n * sizeof(r3ds_triangle) ); group_tmeshes[g] = tmesh; } /* Re-init triangle counters, need them for something else now */ for (g = 0; g < num_groups; g++) tri_counts[g] = 0; /* Copy each triangle into the appropriate sub-trimesh */ for (t = 0; t < orig_tmesh->num_tris; t++) { orig_tri = &orig_tmesh->tris[t]; if (message == -1) /* R3DS_SPLIT_BY_SMGROUP */ g = r3ds_first_smgroup( orig_tri ); else { g = orig_tri->mat_id; if (g == -1) /* default material */ g += num_groups; } tmesh = group_tmeshes[g]; n = tri_counts[g]++; tri = &tmesh->tris[n]; memcpy( tri, orig_tri, sizeof(r3ds_triangle) ); if (message == -1) { /* R3DS_SPLIT_BY_SMGROUP */ /* Set new smoothing groups property */ if (g == 0) tri->smgroups = 0; else tri->smgroups = (uint32)1 << (g - 1); } } /* Done with triangle counters */ xfree( tri_counts ); /* Allocate vertex/index remapping tables (pseudo-functions, * each the inverse of the other) */ n = orig_tmesh->num_verts; if (n > 0) { vertex_remap = xmalloc( n * sizeof(int) ); index_remap = xmalloc( n * sizeof(int) ); } else { vertex_remap = NULL; index_remap = NULL; } /* Get vertices and remapped indices into each sub-trimesh */ for (g = 0; g < num_groups; g++) { tmesh = group_tmeshes[g]; if (tmesh == NULL) continue; /* Initialize index remap table for this object * (vertex_remap doesn't need this) */ for (v = 0; v < orig_tmesh->num_verts; v++) index_remap[v] = -1; /* Build tables */ v = 0; for (t = 0; t < tmesh->num_tris; t++) { tri = &tmesh->tris[t]; if (index_remap[tri->a] == -1) { vertex_remap[v] = tri->a; index_remap[tri->a] = v++; } if (index_remap[tri->b] == -1) { vertex_remap[v] = tri->b; index_remap[tri->b] = v++; } if (index_remap[tri->c] == -1) { vertex_remap[v] = tri->c; index_remap[tri->c] = v++; } } tmesh->num_verts = v; if (v > 0) tmesh->verts = xmalloc( v * sizeof(r3ds_point) ); /* Copy the vertices needed */ for (v = 0; v < tmesh->num_verts; v++) { n = vertex_remap[v]; memcpy( &tmesh->verts[v], &orig_tmesh->verts[n], sizeof(r3ds_point) ); } /* And lastly, remap the indices */ for (t = 0; t < tmesh->num_tris; t++) { tri = &tmesh->tris[t]; tri->a = index_remap[tri->a]; tri->b = index_remap[tri->b]; tri->c = index_remap[tri->c]; } } /* Done with these */ if (vertex_remap != NULL) { xfree( vertex_remap ); xfree( index_remap ); } r3ds_free_object( R3DS_OBJECT(orig_tmesh) ); /* Place the new sub-trimeshes in the original array */ n = num_new_tmeshes; if (n > 1) *trimeshes_ptr = xrealloc( *trimeshes_ptr, n * sizeof(r3ds_trimesh *) ); if (n == 0) xfree( *trimeshes_ptr ); /* orig_tmesh was a dud :( */ n = 0; for (g = 0; g < num_groups; g++) { tmesh = group_tmeshes[g]; if (tmesh != NULL) { (*trimeshes_ptr)[n++] = tmesh; } } xfree( group_tmeshes ); return num_new_tmeshes; } /* This runs through all the r3ds_trimeshes in the given scene and breaks each * down into smaller trimeshes, either on the basis of material (message == * R3DS_SPLIT_BY_MATERIAL) or lowest-numbered smoothing group (message == * R3DS_SPLIT_BY_SMGROUP) * Useful if you want to import 3DS geometry into a property-per-vertex 3D * system like OpenGL (which is exactly the reason I wrote this :) */ int r3ds_split_scene_trimeshes( r3ds_scene *scene, int message ) { r3ds_trimesh **new_tmeshes = NULL; r3ds_trimesh **tmeshes; int num_new_tmeshes = 0; int n, o; for (o = 0; o < scene->num_tmeshes; o++) { tmeshes = xmalloc( sizeof(r3ds_trimesh *) ); tmeshes[0] = scene->tmeshes[o]; switch (message) { case R3DS_SPLIT_BY_MATERIAL: n = r3ds_split_trimesh( &tmeshes, scene->num_mats ); break; case R3DS_SPLIT_BY_SMGROUP: n = r3ds_split_trimesh( &tmeshes, -1 ); break; default: return -1; } num_new_tmeshes += n; if (n > 0) { new_tmeshes = xrealloc( new_tmeshes, num_new_tmeshes * sizeof(r3ds_trimesh *) ); memcpy( &new_tmeshes[num_new_tmeshes - n], tmeshes, n * sizeof(r3ds_trimesh *) ); xfree( tmeshes ); } } xfree( scene->tmeshes ); scene->num_tmeshes = num_new_tmeshes; scene->tmeshes = new_tmeshes; r3ds_rebuild_scene_objs( scene ); return num_new_tmeshes; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* This next part is what does the down and dirty file reading. It is a modified * version of the 3DS reader by Jare/Iguana et. al. (see below for details). * * Main changes: * * 1) Replaced all the fread()'s with read_uintXX()/read_float() calls, to * allow explicit little-endian byte ordering. Meaning that file I/O is now * pretty much endian-agnostic. * * 2) Got rid of the #pragma pack directive, and changed the code to read in * the chunk header fields separately instead of the whole thing at once * (the unaligned double word TChunkHeader->len was giving bus errors when * accessed on MIPS hardware) * * 3) Added hooks for the r3ds_build() state machine all over the place. * This required adding a few extra XXXXXXReader() routines to generate some * additional control signals, but no big deal. * * 4) Enclosed all the printf()'s with #ifdef's, so they can be compiled out. * However, they can just as easily be compiled in, and their output compared * to that of the original reference code. As far as I've seen, the outputs * from both the modified and unmodified readers are identical. (yes!) * * 5) Formatting: Changed all the C++ //-style comments to slash-star C kind * (cc complains about the former) and ran the code through astyle as the * 4-space indents were getting on my nerves :-) * * 6) Oh, and added the all-important project scale chunk (CHUNK_SCALE). * * The code below has been successfully tested on SGI MIPS, Sun Sparc, * and Intel x86 hardware. (Alpha anyone?) * * Any further potential portability issues should be resolvable in the * uintXX typedefs, I think. BTW, if you're using libtiff, you'll have to get * rid of said declarations, else namespaces will collide. * * Because Jare and company have generously donated their code to the public * domain, so do I, in the hope that it will be useful to others. (Disclaimer: * There is no warranty, I assume no liability, use at your own risk, etc.) * Other than that, enjoy, and happy parsing! * * * --Straker * * * */ /* --------------------------- 3DSRDR.C ------------------------------- .3DS file format exerciser v1.4 by Bezzegh D‚nes, aka. DiVeR e-mail: diver@inf.bme.hu http://www.inf.bme.hu/~diver If you are not interested in materials, then there is not much new for you. :-( Changes since v1.3: - Fixed SmooListReader's bug when group>15. - New data-chunk type: WORD /CHUNK_WRD/ - New Material chunks: CHUNK_REFMAP CHUNK_REFMASK CHUNK_SHININESS CHUNK_SPECULARMAP CHUNK_SPECULARMASK CHUNK_SHSTRENGTH CHUNK_OPACITYMAP CHUNK_OPACITYMASK CHUNK_TRANSP CHUNK_TEXTURE2 CHUNK_TEXTURE2MASK CHUNK_TRFALLOFF CHUNK_SHININESSMAP CHUNK_SHININESSMASK CHUNK_REFLECTBL CHUNK_SELFILLUMMAP CHUNK_SELFILLUMMASK CHUNK_SELFILLUM CHUNK_TEXTUREMASK CHUNK_BLUR CHUNK_SHADETYPE CHUNK_BUMPMASK CHUNK_TROTATION CHUNK_FLAG2SIDE CHUNK_USCALE CHUNK_VSCALE CHUNK_TFLAGS CHUNK_UOFFSET CHUNK_VOFFSET CHUNK_BLACKTINT CHUNK_WHITETINT CHUNK_RTINT CHUNK_GTINT CHUNK_BTINT - New "not so useful" Material chunks: CHUNK_FACEMAP CHUNK_WIREFRAME CHUNK_WIRETHICK CHUNK_SOFTEN CHUNK_FLAGIN CHUNK_FLAGUNIT CHUNK_FLAGADD - New Light chunks: CHUNK_LIGHTR1 CHUNK_LIGHTR2 CHUNK_LIGHTMUL - Added CHUNK_SHP and CHUNK_LFT. Why not? - That's all! Did I leave something from material out? ------------------------------ v1.3 -------------------------------- .3DS file format exerciser v1.3. by Mats Byggmastar, aka. MRI/Doomsday e-mail: mri@penti.sit.fi All credits goes to Jare/Iguana as this is just a modified version of v1.2 he released. You can use the following method to dig up new data: - Make a simple .3ds file and convert it with this reader using -dump mode. - Go back into 3D Studio and add that little feature to the scene and convert the .3ds file again using -dump mode. - Compare the output from both conversions and you'll find the chunk where the data was modified or added. "The Unofficial 3dStudio 3DS File Format v1.0" by Jeff Lewis is also a great help. I found that file at: www.viewpoint.com/avalon/format_specs.html .Mats Byggmastar 15.2.1997 Jakobstad, Finland --------------------------- 3DSRDR.C ------------------------------- .3DS file format exerciser v1.2. Written by Javier Arevalo, AKA Jare/Iguana. I compile this with Watcom/32, but I guess it should work with any compiler and OS combination for which the typedefs are valid i.e. any that I know for PCs... Try it and see. Oh, and also check the #pragma pack() thing. - DISCLAIMER - I hope I have not broken any patents or trade secrets by releasing this info. This is purely a mind exercise to break into a file format that is quite useful to know. As far as I have been told a file format is not subject to anything such as copyright or patent, so I have done this because I believe I'm allowed to. I PLACE THIS FILE IN THE PUBLIC DOMAIN, SO EVERYTHING CONTAINED HERE IS TOTALLY FREE FOR YOU TO EXPLORE AND USE. I DISCLAIM ANY AND ALL EVENTS COMING OUT OF ANY POSSIBLE USE (OR LACK OF USE) OR EXISTANCE OF THIS FILE. I WON'T BE LIABLE FOR ANYTHING RELATED TO THIS FILE, OR ANY PRIOR OR FUTURE VERSION OF IT. All trademarks mentioned are property of their respective holders. - Merits - Heavily based on info on the file 3DS_08.TXT by Jim Pitts (jp5@ukc.ac.uk) Basic material-related stuff digged up by Jare. Track info stuff too. Thanks to the Egerter brothers of WGT fame and to Walken/Impact studios for extra info, Rex Deathstar for support. And definitely to Xanthome/Darkzone for you know why. And of course, respect to Avatar/Legend Design for being here before all of us. For a cool example of actual reading of 3DS files, look no further than 3DSCO20.ZIP by Mats Byggmastar aka. MRI. I personally prefer using a table-driven modification of this code, but both approaches are quite ok and his is much faster to write and follow. Now only lack is someone to explain how to make use of all this stuff i.e. how exactly is data stored, how spline interpolations are performed, what are those things called quaternions, etc. And also, maybe, dig the rest of the chunks until we are actually able to write 3DS files instead of just being bored reading. There's lots to do. If you decide to work on this further, please make your findings public like we have already done, ok? Upload it to x2ftp.oulu.fi, THE place for programming info, and/or to ftp.cdrom.com. But please PUBLISH it! - Change log - V 1.2: - Added change log to have some idea what's going on. - Added pivot point reading inside tracks stuff. - Info about spline flags on keyframes. - Added face edge visibility info. - Finally!! Those flags that mark when the texture is wrapping around inside a face. This happens when you apply spherical or cylindrical coordinates, the faces along the 0§ axis don't get proper mapping coords. Someone describe how to fix this? - Added -quiet parm, only displays minimal chunk info. - Object parent number is stored in CHUNK_TRACKOBJNAME. This makes reference to the node number in CHUNK_OBJNUMBER. - Object number changed to unsigned. Parent 65535 means none. - Added CHUNK_PRJ and CHUNK_MLI to allow inspecting .PRJ and .MLI files (they're basically the same chunks as .3DS). - Added banner to identify myself, and disclaimer for "just in case" possibilities. - Corrected possible bug when chunklen == 0 (it was not a chunk). - Added several name descriptions of chunks. Use diff to find all the new chunks. */ #ifndef PI #define PI 3.14159265358979323846264338327 #endif typedef struct { uint16 id; uint32 len; } TChunkHeader; enum { CHUNK_RGBF = 0x0010, CHUNK_RGBB = 0x0011, /* CHUNK_RBGB2 = 0x0012, ?? NOT HLS */ CHUNK_WRD = 0x0030, CHUNK_PRJ = 0xC23D, CHUNK_MLI = 0x3DAA, CHUNK_SHP = 0x2D2D, CHUNK_LFT = 0x2D3D, CHUNK_MAIN = 0x4D4D, CHUNK_SCALE = 0xC420, CHUNK_OBJMESH = 0x3D3D, CHUNK_BKGCOLOR = 0x1200, CHUNK_AMBCOLOR = 0x2100, CHUNK_OBJBLOCK = 0x4000, CHUNK_TRIMESH = 0x4100, CHUNK_VERTLIST = 0x4110, CHUNK_VERTFLAGS = 0x4111, CHUNK_FACELIST = 0x4120, CHUNK_FACEMAT = 0x4130, CHUNK_MAPLIST = 0x4140, CHUNK_SMOOLIST = 0x4150, CHUNK_TRMATRIX = 0x4160, CHUNK_MESHCOLOR = 0x4165, CHUNK_TXTINFO = 0x4170, CHUNK_LIGHT = 0x4600, CHUNK_LIGHTR1 = 0x4659, CHUNK_LIGHTR2 = 0x465A, CHUNK_LIGHTMUL = 0x465B, CHUNK_SPOTLIGHT = 0x4610, CHUNK_CAMERA = 0x4700, CHUNK_HIERARCHY = 0x4F00, CHUNK_VIEWPORT = 0x7001, CHUNK_MATERIAL = 0xAFFF, CHUNK_MATNAME = 0xA000, CHUNK_AMBIENT = 0xA010, CHUNK_DIFFUSE = 0xA020, CHUNK_SPECULAR = 0xA030, CHUNK_SHININESS = 0xA040, CHUNK_SHSTRENGTH = 0xA041, CHUNK_TRANSP = 0xA050, CHUNK_TRFALLOFF = 0xA052, CHUNK_REFLECTBL = 0xA053, CHUNK_FLAG2SIDE = 0xA081, CHUNK_FLAGADD = 0xA083, CHUNK_SELFILLUM = 0xA084, CHUNK_WIREFRAME = 0xA085, /* Flag */ CHUNK_WIRETHICK = 0xA087, /* Float */ CHUNK_FACEMAP = 0xA088, /* Flag */ CHUNK_FLAGIN = 0xA08A, CHUNK_SOFTEN = 0xA08C, /* Flag */ CHUNK_FLAGUNIT = 0xA08E, /* Very useless */ CHUNK_SHADETYPE = 0xA100, CHUNK_TEXTURE = 0xA200, CHUNK_TEXTUREMASK = 0xA33E, CHUNK_TEXTURE2 = 0xA33A, CHUNK_TEXTUREMASK2 = 0xA340, CHUNK_REFMAP = 0xA220, CHUNK_REFMASK = 0xA34C, CHUNK_OPACITYMAP = 0xA210, CHUNK_OPACITYMASK = 0xA342, CHUNK_SPECULARMAP = 0xA204, CHUNK_SPECULARMASK = 0xA348, CHUNK_SHININESSMAP = 0xA33C, CHUNK_SHININESSMASK= 0xA346, CHUNK_SELFILLUMMAP = 0xA33D, CHUNK_SELFILLUMMASK= 0xA34A, CHUNK_BUMPMAP = 0xA230, CHUNK_BUMPMASK = 0xA344, CHUNK_MAPFILE = 0xA300, CHUNK_TFLAGS = 0xA351, /* Flags */ CHUNK_BLUR = 0xA353, /* Float */ CHUNK_USCALE = 0xA354, /* Float */ CHUNK_VSCALE = 0xA356, /* Float */ CHUNK_UOFFSET = 0xA358, /* Float */ CHUNK_VOFFSET = 0xA35A, /* Float */ CHUNK_TROTATION = 0xA35C, /* Float */ CHUNK_BLACKTINT = 0xA360, /* Float */ CHUNK_WHITETINT = 0xA362, /* Float */ CHUNK_RTINT = 0xA364, /* Float */ CHUNK_GTINT = 0xA366, /* Float */ CHUNK_BTINT = 0xA368, /* Float */ CHUNK_KEYFRAMER = 0xB000, CHUNK_AMBIENTKEY = 0xB001, CHUNK_TRACKINFO = 0xB002, CHUNK_TRACKOBJNAME = 0xB010, CHUNK_TRACKPIVOT = 0xB013, CHUNK_TRACKPOS = 0xB020, CHUNK_TRACKROTATE = 0xB021, CHUNK_TRACKSCALE = 0xB022, CHUNK_TRACKMORPH = 0xB026, CHUNK_TRACKHIDE = 0xB029, CHUNK_OBJNUMBER = 0xB030, CHUNK_TRACKCAMERA = 0xB003, CHUNK_TRACKFOV = 0xB023, CHUNK_TRACKROLL = 0xB024, CHUNK_TRACKCAMTGT = 0xB004, CHUNK_TRACKLIGHT = 0xB005, CHUNK_TRACKLIGTGT = 0xB006, CHUNK_TRACKSPOTL = 0xB007, CHUNK_FRAMES = 0xB008 }; /* ------------------------------------ */ static void SkipReader( FILE *f, int ind, int p ) { /* Do nothing! */ } static void RGBFReader (FILE *f, int ind, int p) { float c[3]; if (!r3ds_read_float( c, 3, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Red: %f, Green: %f, Blue: %f\n", ind, "", c[0], c[1], c[2]); #endif } static void RGBBReader (FILE *f, int ind, int p) { uint8 c[3]; int rgb[3]; int i; if (!r3ds_read_uint8( c, 3, f )) return; for (i = 0; i < 3; i++) rgb[i] = c[i]; r3ds_build( R3DS_COLOR24, rgb ); #ifdef R3DS_ORIG_CODE printf("%*s Red: %d, Green: %d, Blue: %d\n", ind, "", c[0], c[1], c[2]); #endif } static void WRDReader (FILE *f, int ind, int p) { uint16 value; if (!r3ds_read_uint16( &value, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Value: %d\n", ind, "", value); #endif } static void FloatReader (FILE *f, int ind, int p) { float value; if (!r3ds_read_float( &value, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Value: %f\n", ind, "", value); #endif } static void TextFlagReader (FILE *f, int ind, int p) { uint8 flag1, flag2; #ifdef R3DS_ORIG_CODE printf("%*s ", ind, ""); #endif if (!r3ds_read_uint8( &flag1, 1, f )) return; if (!r3ds_read_uint8( &flag2, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("Source:"); if ((flag1 & 0xc0)==0x80) printf("RGB luma tint\n"); else { if ((flag1 & 0xc0)==0xc0) printf("Alpha tint\n"); else { if ((flag2 & 0x02)==0x02) printf("RGB tint\n"); else printf("RGB\n"); } } printf("%*s ", ind, ""); printf("Filtering:"); if (flag1 & 0x40) printf("Summed arial\n"); else printf("Pyramidal\n"); printf("%*s ", ind, ""); printf("Other parameters:"); switch (flag1 & 0x11) { case 0x11: printf("Decal"); break; case 0x00: printf("Tile"); break; case 0x10: case 0x01: printf("Tile & Decal"); } if (flag2 & 1) printf(" - Ignoge map alpha"); if (flag1 & 8) printf(" - Negative"); if (flag1 & 2) printf(" - Mirror"); printf("\n%*s ", ind, ""); printf("%02X ", flag1); printf("%02X ", flag2); printf("\n"); #endif } static void SHTReader (FILE *f, int ind, int p) { uint16 value; if (!r3ds_read_uint16( &value, 1, f )) return; #ifdef R3DS_ORIG_CODE switch (value) { case 1: printf("%*s Flat\n", ind, ""); break; case 2: printf("%*s Gouraud\n", ind, ""); break; case 3: printf("%*s Phong\n", ind, ""); break; case 4: printf("%*s Metal\n", ind, ""); break; } #endif } static char *ASCIIZReader (FILE *f, int ind, int p) { static char inbuf[256]; int c; int i = 0; /* Read ASCIIZ name */ while (((c = fgetc(f)) != EOF) && (c != '\0')) { if (i < 255) inbuf[i++] = c; #ifdef R3DS_ORIG_CODE putchar(c); #endif } #ifdef R3DS_ORIG_CODE printf("\"\n"); #endif inbuf[i] = '\0'; return inbuf; } static void ProjScaleReader( FILE *f, int ind, int p ) { float unit_size; float inches_per_unit; uint16 unknown; if (!r3ds_read_float( &unit_size, 1, f )) return; if (!r3ds_read_float( &inches_per_unit, 1, f )) return; r3ds_build( R3DS_PROJECT_SCALE, &inches_per_unit ); if (!r3ds_read_uint16( &unknown, 1, f )) return; #if 0 printf( "%*sProject scale: 1 unit == %.3f real units (unknown)\n", ind, "", unit_size ); printf( "%*s == %.3f inches\n", ind, "", inches_per_unit ); #endif } static void ObjBlockReader (FILE *f, int ind, int p) { char *name; /* Read ASCIIZ object name */ #ifdef R3DS_ORIG_CODE printf("%*sObject name \"", ind, ""); #endif name = ASCIIZReader(f, ind, p); r3ds_build( R3DS_NEW_OBJECT, name ); /* Read rest of chunks inside this one */ r3ds_ChunkReader(f, ind, p); } static void TriMeshReader( FILE *f, int ind, int p) { r3ds_build( R3DS_DEF_TRIMESH, NULL ); r3ds_ChunkReader( f, ind, p ); } static void VertListReader (FILE *f, int ind, int p) { uint16 nv; float c[3]; int num_verts; if (!r3ds_read_uint16( &nv, 1, f )) return; num_verts = nv; r3ds_build( R3DS_NUM_VERTS, &num_verts ); #ifdef R3DS_ORIG_CODE printf("%*sVertices: %d\n", ind, "", nv); #endif while (nv-- > 0) { if (!r3ds_read_float( c, 3, f )) return; r3ds_build( R3DS_VERT, c ); #ifdef R3DS_ORIG_CODE printf("%*s X: %f, Y: %f, Z: %f\n", ind, "", c[0], c[1], c[2]); #endif } } static void FaceListReader (FILE *f, int ind, int p) { uint16 nv; uint16 c[3]; uint16 flags; int tri_def[4]; int num_tris; int i; if (!r3ds_read_uint16( &nv, 1, f )) return; num_tris = nv; r3ds_build( R3DS_NUM_TRIS, &num_tris ); #ifdef R3DS_ORIG_CODE printf("%*sFaces: %d\n", ind, "", nv); #endif while (nv-- > 0) { if (!r3ds_read_uint16( c, 3, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; for (i = 0; i < 3; i++) tri_def[i] = c[i]; tri_def[3] = flags; r3ds_build( R3DS_TRI_FACE, tri_def ); #ifdef R3DS_ORIG_CODE printf("%*s A %d, B %d, C %d, 0x%X:", ind, "", c[0], c[1], c[2], flags); printf(" AB %d BC %d CA %d UWrap %d VWrap %d\n", (flags & 0x04) != 0, (flags & 0x02) != 0, (flags & 0x01) != 0, (flags & 0x08) != 0, (flags & 0x10) != 0); #endif } /* Read rest of chunks inside this one */ r3ds_ChunkReader(f, ind, p); } static void FaceMatReader (FILE *f, int ind, int p) { uint16 n, nf; int tri_num; char *mat_name; /* Read ASCIIZ material name */ #ifdef R3DS_ORIG_CODE printf("%*sMaterial name for faces: \"", ind, ""); #endif mat_name = ASCIIZReader(f, ind, p); r3ds_build( R3DS_TRI_MATERIAL_CURRENT, mat_name ); if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sFaces with this material: %d\n", ind, "", n); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; tri_num = nf; r3ds_build( R3DS_TRI_MATERIAL, &tri_num ); #ifdef R3DS_ORIG_CODE printf("%*s Face %d\n", ind, "", nf); #endif } } static void MapListReader (FILE *f, int ind, int p) { uint16 nv; float c[2]; if (!r3ds_read_uint16( &nv, 1, f )) return; r3ds_build( R3DS_NUM_VERT_MAPPINGS, &nv ); #ifdef R3DS_ORIG_CODE printf("%*sVertices: %d\n", ind, "", nv); #endif while (nv-- > 0) { if (!r3ds_read_float( c, 2, f )) return; r3ds_build( R3DS_VERT_MAPPING, c ); #ifdef R3DS_ORIG_CODE printf("%*s U: %f, V: %f\n", ind, "", c[0], c[1]); #endif } } static void SmooListReader (FILE *f, int ind, int p) { uint32 s; int i; r3ds_build( R3DS_BEGIN_TRI_SMOOTH, NULL ); while (ftell(f) < p) { if (!r3ds_read_uint32( &s, 1, f )) return; r3ds_build( R3DS_TRI_SMOOTH, &s ); #ifdef R3DS_ORIG_CODE printf("%*sSmoothing groups: ", ind, ""); #endif for (i = 0; i < 32; i++) if (s & ((uint32)1 << i)) { #ifdef R3DS_ORIG_CODE printf("%d, ", i + 1); #endif } #ifdef R3DS_ORIG_CODE printf("\n"); #endif } } static void TrMatrixReader(FILE *f, int ind, int p) { float rot[9]; float trans[3]; if (!r3ds_read_float( rot, 9, f )) return; r3ds_build( R3DS_ROT_MATRIX, rot ); #ifdef R3DS_ORIG_CODE printf("%*sRotation matrix:\n", ind, ""); printf("%*s %f, %f, %f\n", ind, "", rot[0], rot[1], rot[2]); printf("%*s %f, %f, %f\n", ind, "", rot[3], rot[4], rot[5]); printf("%*s %f, %f, %f\n", ind, "", rot[6], rot[7], rot[8]); #endif if (!r3ds_read_float( trans, 3, f )) return; r3ds_build( R3DS_TRANS_MATRIX, trans ); #ifdef R3DS_ORIG_CODE printf("%*sTranslation matrix: %f, %f, %f\n", ind, "", trans[0], trans[1], trans[2]); #endif } static void LightReader(FILE *f, int ind, int p) { float c[3]; if (!r3ds_read_float( c, 3, f )) return; r3ds_build( R3DS_DEF_LIGHT, c ); #ifdef R3DS_ORIG_CODE printf("%*s X: %f, Y: %f, Z: %f\n", ind, "", c[0], c[1], c[2]); #endif /* Read rest of chunks inside this one */ r3ds_ChunkReader(f, ind, p); } static void SpotLightReader(FILE *f, int ind, int p) { float c[5]; if (!r3ds_read_float( c, 5, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Target X: %f, Y: %f, Z: %f; Hotspot %f, Falloff %f\n", ind, "", c[0], c[1], c[2], c[3], c[4]); #endif } static void CameraReader(FILE *f, int ind, int p) { float c[8]; if (!r3ds_read_float( c, 8, f )) return; r3ds_build( R3DS_DEF_CAMERA, c ); #ifdef R3DS_ORIG_CODE printf("%*s Position: X: %f, Y: %f, Z: %f\n", ind, "", c[0], c[1], c[2]); printf("%*s Target: X: %f, Y: %f, Z: %f\n", ind, "", c[3], c[4], c[5]); printf("%*s Bank: %f, Lens: %f\n", ind, "", c[6], c[7]); #endif } static void MatNameReader (FILE *f, int ind, int p) { char *matname; /* Read ASCIIZ object name */ #ifdef R3DS_ORIG_CODE printf("%*sMaterial name \"", ind, ""); #endif matname = ASCIIZReader(f, ind, p); r3ds_build( R3DS_NEW_MATERIAL, matname ); } static void MatAmbColorReader( FILE *f, int ind, int p ) { r3ds_build( R3DS_MAT_AMBIENT_COLOR, NULL ); r3ds_ChunkReader( f, ind, p ); } static void MatDiffColorReader( FILE *f, int ind, int p ) { r3ds_build( R3DS_MAT_DIFFUSE_COLOR, NULL ); r3ds_ChunkReader( f, ind, p ); } static void MatSpecColorReader( FILE *f, int ind, int p ) { r3ds_build( R3DS_MAT_SPECULAR_COLOR, NULL ); r3ds_ChunkReader( f, ind, p ); } static void TwoSidedFlagReader( FILE *f, int ind, int p ) { r3ds_build( R3DS_MAT_2SIDED, NULL ); } static void MapFileReader(FILE *f, int ind, int p) { /* Read ASCIIZ filename */ #ifdef R3DS_ORIG_CODE printf("%*sMap filename \"", ind, ""); #endif ASCIIZReader(f, ind, p); } static void FramesReader(FILE *f, int ind, int p) { uint32 c[2]; if (!r3ds_read_uint32( c, 2, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Start: %d, End: %d\n", ind, "", c[0], c[1]); #endif } static void TrackObjNameReader(FILE *f, int ind, int p) { uint16 w[2]; uint16 parent; /* Read ASCIIZ name */ #ifdef R3DS_ORIG_CODE printf("%*sTrack object name \"", ind, ""); #endif ASCIIZReader(f, ind, p); if (!r3ds_read_uint16( w, 2, f )) return; if (!r3ds_read_uint16( &parent, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sObject name data: Flags 0x%X, 0x%X, Parent %d\n", ind, "", w[0], w[1], parent); #endif } static void PivotPointReader(FILE *f, int ind, int p) { float pos[3]; if (!r3ds_read_float( pos, 3, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Pivot at X: %f, Y: %f, Z: %f\n", ind, "", pos[0], pos[1], pos[2]); #endif } /* Key info flags for position, rotation and scaling: Until I know the meaning of each bit in flags I assume all mean a following float data. */ /* NOTE THIS IS NOT A CHUNK, but A PART OF SEVERAL CHUNKS */ static void SplineFlagsReader(FILE *f, int ind, uint16 flags) { int i; float dat; #ifdef R3DS_ORIG_CODE static const char *flagnames[] = { "Tension", "Continuity", "Bias", "Ease To", "Ease From", }; #endif for (i = 0; i < 16; i++) { if (flags & (1 << i)) { if (!r3ds_read_float( &dat, 1, f )) return; #ifdef R3DS_ORIG_CODE if (i < sizeof(flagnames)/sizeof(*flagnames)) { printf("%*s %-15s = %f\n", ind, "", flagnames[i], dat); } else { printf("%*s %-15s = %f\n", ind, "", "Unknown", dat); } #endif } } } static void TrackPosReader(FILE *f, int ind, int p) { uint16 n, nf; float pos[3]; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sPosition keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); if (!r3ds_read_float( pos, 3, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s X: %f, Y: %f, Z: %f\n", ind, "", pos[0], pos[1], pos[2]); #endif } } static void TrackRotReader(FILE *f, int ind, int p) { uint16 n, nf; float pos[4]; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sRotation keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); if (!r3ds_read_float( pos, 4, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Angle: %f§, X: %f, Y: %f, Z: %f\n", ind, "", pos[0]*180.0/PI, pos[1], pos[2], pos[3]); #endif } } static void TrackScaleReader(FILE *f, int ind, int p) { uint16 n, nf; float pos[3]; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sScale keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); if (!r3ds_read_float( pos, 3, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s X: %f, Y: %f, Z: %f\n", ind, "", pos[0], pos[1], pos[2]); #endif } } static void TrackFovReader(FILE *f, int ind, int p) { uint16 n, nf; float fov; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sFOV keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); if (!r3ds_read_float( &fov, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s FOV: %f\n", ind, "", fov); #endif } } static void TrackRollReader(FILE *f, int ind, int p) { uint16 n, nf; float roll; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sRoll keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); if (!r3ds_read_float( &roll, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Roll: %f\n", ind, "", roll); #endif } } static void TrackMorphReader(FILE *f, int ind, int p) { uint16 n, nf; uint16 unkown; uint16 flags; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sMorph keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif while (n-- > 0) { if (!r3ds_read_uint16( &nf, 1, f )) return; if (!r3ds_read_uint16( &unkown, 1, f )) return; if (!r3ds_read_uint16( &flags, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Frame %3d: Flags 0x%X\n", ind, "", nf, flags); #endif SplineFlagsReader(f, ind, flags); #ifdef R3DS_ORIG_CODE printf("%*s Object name: \"", ind, ""); #endif ASCIIZReader(f, ind, p); } } static void TrackHideReader(FILE *f, int ind, int p) { uint16 n; uint16 frame; uint16 unkown; int i; for(i=0; i<5; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown #%d: 0x%x\n", ind, "", i, unkown); #endif } if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sHide keys: %d\n", ind, "", n); #endif if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sUnknown: 0x%x\n", ind, "", unkown); #endif ind += 2; while (n-- > 0) { if (!r3ds_read_uint16( &frame, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sFrame: %d\n", ind, "", (uint32) frame); #endif for(i=0; i<2; i++) { if (!r3ds_read_uint16( &unkown, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*s Unknown #%d: 0x%x\n", ind, "", i, unkown); #endif } } } static void ObjNumberReader(FILE *f, int ind, int p) { uint16 n; if (!r3ds_read_uint16( &n, 1, f )) return; #ifdef R3DS_ORIG_CODE printf("%*sObject number: %d\n", ind, "", n); #endif } /* ------------------------------------ */ struct { uint16 id; const char *name; void (*func)(FILE *f, int ind, int p); } ChunkNames[] = { {CHUNK_RGBF, "RGB float", RGBFReader}, {CHUNK_RGBB, "RGB byte", RGBBReader}, {CHUNK_WRD, "WORD", WRDReader}, {CHUNK_PRJ, "Project", NULL}, {CHUNK_MLI, "Material Library", NULL}, {CHUNK_SHP, "Shape file", NULL}, {CHUNK_LFT, "Loft file", NULL}, {CHUNK_MAIN, "Main", NULL}, {CHUNK_SCALE, "Project scale", ProjScaleReader}, {CHUNK_OBJMESH, "Object Mesh", NULL}, {CHUNK_BKGCOLOR, "Background color", NULL}, {CHUNK_AMBCOLOR, "Ambient color", NULL}, {CHUNK_OBJBLOCK, "Object Block", ObjBlockReader}, {CHUNK_TRIMESH, "Tri-Mesh", TriMeshReader}, {CHUNK_VERTLIST, "Vertex list", VertListReader}, {CHUNK_VERTFLAGS, "Vertex flag list", SkipReader}, {CHUNK_FACELIST, "Face list", FaceListReader}, {CHUNK_MESHCOLOR, "Mesh color", SkipReader}, {CHUNK_FACEMAT, "Face material", FaceMatReader}, {CHUNK_MAPLIST, "Mappings list", MapListReader}, {CHUNK_TXTINFO, "Texture info", SkipReader}, {CHUNK_SMOOLIST, "Smoothings", SmooListReader}, {CHUNK_TRMATRIX, "Matrix", TrMatrixReader}, {CHUNK_LIGHT, "Light", LightReader}, {CHUNK_LIGHTR1, "Light Range radius1", FloatReader}, {CHUNK_LIGHTR2, "Light Range radius2", FloatReader}, {CHUNK_LIGHTMUL, "Light Multyplity", FloatReader}, {CHUNK_SPOTLIGHT, "Spotlight", SpotLightReader}, {CHUNK_CAMERA, "Camera", CameraReader}, {CHUNK_HIERARCHY, "Hierarchy", NULL}, {CHUNK_VIEWPORT, "Viewport info", SkipReader}, {CHUNK_MATERIAL, "Material", NULL}, {CHUNK_MATNAME, "Material name", MatNameReader}, {CHUNK_AMBIENT, "Ambient color", MatAmbColorReader}, {CHUNK_DIFFUSE, "Diffuse color", MatDiffColorReader}, {CHUNK_SPECULAR, "Specular color", MatSpecColorReader}, {CHUNK_SHININESS, "Shininess", NULL}, {CHUNK_SHSTRENGTH, "Shininess strength", NULL}, {CHUNK_TRANSP, "Transparency", NULL}, {CHUNK_TRFALLOFF, "Transparency falloff", NULL}, {CHUNK_REFLECTBL, "Reflection blur", NULL}, {CHUNK_SELFILLUM, "Self Illumination", NULL}, {CHUNK_FLAG2SIDE, "2Side: ON /flag/", TwoSidedFlagReader}, {CHUNK_FLAGADD, "Transparency: Add /flag/", SkipReader}, {CHUNK_WIREFRAME, "WireFrame: ON /flag/", SkipReader}, {CHUNK_WIRETHICK, "WireFrame thickness", FloatReader}, {CHUNK_FLAGIN, "Transparency falloff: In /flag/", SkipReader}, {CHUNK_FLAGUNIT, "WireFrame thickness: Unit /flag/", SkipReader}, {CHUNK_FACEMAP, "Self Illumination: FaceMap /flag/", SkipReader}, {CHUNK_SOFTEN, "Shininess: Soften /flag/", SkipReader}, {CHUNK_SHADETYPE, "Shadeing type", SHTReader}, {CHUNK_TEXTURE, "Texture map", NULL}, {CHUNK_SPECULARMAP, "Specular map", NULL}, {CHUNK_OPACITYMAP, "Opacity map", NULL}, {CHUNK_TEXTURE2, "Texture map 2", NULL}, {CHUNK_SHININESSMAP, "Shininess map", NULL}, {CHUNK_SELFILLUMMAP, "Self Illumination map", NULL}, {CHUNK_REFMAP, "Reflection map", NULL}, {CHUNK_BUMPMAP, "Bump map", NULL}, {CHUNK_TEXTUREMASK, "Texture mask", NULL}, {CHUNK_SPECULARMASK, "Specular mask", NULL}, {CHUNK_OPACITYMASK, "Opacity mask", NULL}, {CHUNK_TEXTUREMASK2, "Texture2 mask", NULL}, {CHUNK_SHININESSMASK,"Shininess mask", NULL}, {CHUNK_SELFILLUMMASK,"Self Illumination mask", NULL}, {CHUNK_REFMASK, "Reflection mask", NULL}, {CHUNK_BUMPMASK, "Bump mask", NULL}, {CHUNK_TFLAGS, "Texture flags", TextFlagReader}, {CHUNK_BLUR, "Texture Blur", FloatReader}, {CHUNK_USCALE, "U scale (1/x)", FloatReader}, {CHUNK_VSCALE, "V scale (1/x)", FloatReader}, {CHUNK_UOFFSET, "U offset", FloatReader}, {CHUNK_VOFFSET, "V offset", FloatReader}, {CHUNK_TROTATION, "Texture Rotation angle", FloatReader}, {CHUNK_BLACKTINT, "Black Tint", RGBBReader}, {CHUNK_WHITETINT, "White Tint", RGBBReader}, {CHUNK_RTINT, "Red Tint", RGBBReader}, {CHUNK_GTINT, "Green Tint", RGBBReader}, {CHUNK_BTINT, "Blue Tint", RGBBReader}, {CHUNK_MAPFILE, "Map filename", MapFileReader}, {CHUNK_KEYFRAMER, "Keyframer data", NULL}, {CHUNK_AMBIENTKEY, "Ambient key", NULL}, {CHUNK_TRACKINFO, "Track info", NULL}, {CHUNK_FRAMES, "Frames", FramesReader}, {CHUNK_TRACKOBJNAME,"Track Obj. Name", TrackObjNameReader}, {CHUNK_TRACKPIVOT, "Pivot point", PivotPointReader}, {CHUNK_TRACKPOS, "Position keys", TrackPosReader}, {CHUNK_TRACKROTATE, "Rotation keys", TrackRotReader}, {CHUNK_TRACKSCALE, "Scale keys", TrackScaleReader}, {CHUNK_TRACKMORPH, "Morph keys", TrackMorphReader}, {CHUNK_TRACKHIDE, "Hide keys", TrackHideReader}, {CHUNK_OBJNUMBER, "Object number", ObjNumberReader}, {CHUNK_TRACKCAMERA, "Camera track", NULL}, {CHUNK_TRACKCAMTGT, "Camera target track", NULL}, {CHUNK_TRACKLIGHT, "Pointlight track", NULL}, {CHUNK_TRACKLIGTGT, "Pointlight target track", NULL}, {CHUNK_TRACKSPOTL, "Spotlight track", NULL}, {CHUNK_TRACKFOV, "FOV track", TrackFovReader}, {CHUNK_TRACKROLL, "Roll track", TrackRollReader}, }; static int FindChunk(uint16 id) { int i; for (i = 0; i < sizeof(ChunkNames)/sizeof(ChunkNames[0]); i++) if (id == ChunkNames[i].id) return i; return -1; } /* ------------------------------------ */ #ifdef R3DS_ORIG_CODE int Verbose = 1; int Quiet = 0; int Dump = 1; #endif void r3ds_ChunkReader(FILE *f, int ind, int p) { TChunkHeader h; int n; #ifdef R3DS_ORIG_CODE int i; uint8 d; #endif int pc; while (ftell(f) < p) { pc = ftell(f); if (!r3ds_read_uint16( &h.id, 1, f )) return; if (!r3ds_read_uint32( &h.len, 1, f )) return; if (h.len == 0) return; n = FindChunk(h.id); if (n < 0) { #ifdef R3DS_ORIG_CODE if (Verbose) { printf("%*sUnknown chunk: 0x%04X, offset 0x%X, size: %d bytes.", ind, "", h.id, pc, h.len); if (!Dump) printf("\n"); } if (Dump) { fseek(f, pc + 6, SEEK_SET); for (i=0; i 2 && strcmp(argv[2], "-quiet") == 0) Quiet = 1; if (argc > 2 && strcmp(argv[2], "-verbose") == 0) Verbose = 1; if (argc > 2 && strcmp(argv[2], "-dump") == 0) { Verbose = 1; Dump = 1; } if (!Quiet) Banner(); /* Find file size */ fseek(f, 0, SEEK_END); p = ftell(f); fseek(f, 0, SEEK_SET); /* Go! */ r3ds_ChunkReader(f, 0, p); return 0; } #endif /* 0 */ /* end read3ds.c */ lightspeed-1.2a.debian.1/src/read3ds.h000066400000000000000000000163141334064775200175320ustar00rootroot00000000000000/* read3ds.h */ /* Mini-library for loading .3DS files * 3D Studio loading code by Jare/Iguana et. al. (see read3ds.c) * API interface & portability mods by Straker Skunk * * THIS FILE IS IN THE PUBLIC DOMAIN */ #include #include #include typedef unsigned char uint8; /* "byte" == 8 bits */ typedef unsigned short uint16; /* "word" == 16 bits */ typedef unsigned int uint32; /* "double word" == 32 bits */ /**** Defines, macros, enums, etc. ****************************/ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef ABS #define ABS(a) (((a) < 0) ? -(a) : (a)) #endif #ifndef CLAMP #define CLAMP(x,low,high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) #endif /* Type conversion macros */ #define R3DS_OBJECT(x) ((r3ds_object *)(x)) #define R3DS_LIGHT(x) ((r3ds_light *)(x)) #define R3DS_CAMERA(x) ((r3ds_camera *)(x)) #define R3DS_TRIMESH(x) ((r3ds_trimesh *)(x)) /* Use to access r3ds_triangle->flags bitfield (each returns TRUE/FALSE) */ #define R3DS_TRI_AB_VIS(tri) (((tri)->flags & 0x04) != 0) #define R3DS_TRI_BC_VIS(tri) (((tri)->flags & 0x02) != 0) #define R3DS_TRI_CA_VIS(tri) (((tri)->flags & 0x01) != 0) #define R3DS_TRI_U_WRAP(tri) (((tri)->flags & 0x08) != 0) #define R3DS_TRI_V_WRAP(tri) (((tri)->flags & 0x10) != 0) /* Use to access r3ds_triangle->smgroups bitfield. Returns TRUE if triangle is * in the smoothing group specified (1-32), FALSE if otherwise. If 0 is passed, * return TRUE if triangle is not in ANY smoothing group, FALSE otherwise */ #define R3DS_TRI_IN_SMGROUP(tri,g) \ (((g) <= 0) ? ((tri)->smgroups == 0) : (((tri)->smgroups & ((uint32)1 << ((g) - 1))) != 0)) /* Messages for the r3ds_build() state machine */ enum { R3DS_INITIALIZE, R3DS_PROJECT_SCALE, R3DS_NEW_OBJECT, R3DS_DEF_LIGHT, R3DS_DEF_CAMERA, R3DS_DEF_TRIMESH, R3DS_NUM_VERTS, R3DS_VERT, R3DS_NUM_VERT_MAPPINGS, R3DS_VERT_MAPPING, R3DS_NUM_TRIS, R3DS_TRI_FACE, R3DS_TRI_MATERIAL_CURRENT, R3DS_TRI_MATERIAL, R3DS_BEGIN_TRI_SMOOTH, R3DS_TRI_SMOOTH, R3DS_ROT_MATRIX, R3DS_TRANS_MATRIX, R3DS_NEW_MATERIAL, R3DS_MAT_AMBIENT_COLOR, R3DS_MAT_DIFFUSE_COLOR, R3DS_MAT_SPECULAR_COLOR, R3DS_MAT_2SIDED, R3DS_COLOR24, R3DS_GET_SCENE }; /* Messages for r3ds_split_trimeshes( ) */ enum { R3DS_SPLIT_BY_MATERIAL, R3DS_SPLIT_BY_SMGROUP }; /* Object types * (for r3ds_object->type field) */ typedef enum { R3DS_OBJ_LIGHT, R3DS_OBJ_CAMERA, R3DS_OBJ_TRIMESH, R3DS_OBJ_UNDEFINED } R3dsObjType; /* Light types * (for r3ds_light->ltype field) */ typedef enum { R3DS_LIGHT_POINT, R3DS_LIGHT_SPOT } R3dsLightType; /* Shading types * (for r3ds_material->shading_type field) */ typedef enum { R3DS_SHADE_FLAT, R3DS_SHADE_GOURAUD, R3DS_SHADE_PHONG, R3DS_SHADE_METAL } R3dsShadeType; /**** Data structures *****************************************/ /** Elements **/ /* 24-bit RGB color */ typedef struct r3ds_color24_struct r3ds_color24; struct r3ds_color24_struct { /* Each component has a range of 0-255 */ int red; int green; int blue; }; /* Floating-point RGB color */ typedef struct r3ds_colorF_struct r3ds_colorF; struct r3ds_colorF_struct { float red; float green; float blue; }; /* Trimesh vertex */ typedef struct r3ds_point_struct r3ds_point; struct r3ds_point_struct { /* Location coords. */ float x; float y; float z; /* Texture mapping coords. */ float u; float v; }; /* Trimesh triangle */ typedef struct r3ds_triangle_struct r3ds_triangle; struct r3ds_triangle_struct { int a, b, c; /* Vertex indices (into r3ds_trimesh->verts) */ uint16 flags; /* Edge visibility & texture wrap flags */ int mat_id; /* Material index (into r3ds_scene->mats) */ uint32 smgroups; /* Bitfield: smoothing group(s) membership */ }; /* Material */ /* INCOMPLETE */ typedef struct r3ds_material_struct r3ds_material; struct r3ds_material_struct { char *name; r3ds_color24 ambient; r3ds_color24 diffuse; r3ds_color24 specular; R3dsShadeType shading; /* Flat, Gouraud, Phong, or Metal */ int two_sided : 1; /* 2-sided material (flag) */ int shine; /* Shininess % */ int shine_st; /* Shininess strength % */ int transp; /* Transparency % */ int transp_fo; /* Transparency falloff % */ int ref_blur; /* Reflection blur % */ int self_illum; /* Self-illumination % */ int wireframe_th; /* Wireframe thickness */ int texmap; /* Texture map % */ char *texmap_file; /* Filename of texture map */ int refmap; /* Reflection map % */ char *refmap_file; /* Filename of reflection map */ }; /** Objects **/ /* Light object */ /* INCOMPLETE */ typedef struct r3ds_light_struct r3ds_light; struct r3ds_light_struct { R3dsObjType type; /* = R3DS_OBJ_LIGHT */ char *name; R3dsLightType ltype; float x; float y; float z; r3ds_colorF color; /* Light color */ float radius1; /* Inner radius */ float radius2; /* Outer radius */ float mult; /* Multiplier */ }; /* Camera object */ typedef struct r3ds_camera_struct r3ds_camera; struct r3ds_camera_struct { R3dsObjType type; /* = R3DS_OBJ_CAMERA */ char *name; float x; float y; /* Position */ float z; float targ_x; float targ_y; /* Target */ float targ_z; float bank; float lens; /* Lens length in mm */ }; /* Triangle mesh object */ typedef struct r3ds_trimesh_struct r3ds_trimesh; struct r3ds_trimesh_struct { R3dsObjType type; /* = R3DS_OBJ_TRIMESH */ char *name; int num_verts; r3ds_point *verts; int num_tris; r3ds_triangle *tris; float rot_matrix[9]; float trans_matrix[3]; }; /* Generalized object */ typedef struct r3ds_object_struct r3ds_object; struct r3ds_object_struct { R3dsObjType type; char *name; }; /** Scene **/ typedef struct r3ds_scene_struct r3ds_scene; struct r3ds_scene_struct { float inches_per_unit; int num_objs; r3ds_object **objs; /* Note: The array above and the 3 below point to the SAME objects */ int num_lites; r3ds_light **lites; int num_cams; r3ds_camera **cams; int num_tmeshes; r3ds_trimesh **tmeshes; int num_mats; r3ds_material *mats; }; /**** Forward declarations ************************************/ /* Wrappers for the system memory management functions */ extern void *xmalloc( size_t size ); extern void *xrealloc( void *block, size_t size ); extern char *xstrdup( const char *str ); extern void xfree( void *ptr ); int r3ds_read_uint32( uint32 *data, int count, FILE *f ); int r3ds_read_uint16( uint16 *data, int count, FILE *f ); int r3ds_read_uint8( uint8 *data, int count, FILE *f ); int r3ds_read_float( float *data, int count, FILE *f ); int r3ds_file_is_3ds( const char *filename ); int r3ds_file_is_prj( const char *filename ); void r3ds_build( int data_id, const void *data ); r3ds_scene *read3ds( const char *filename ); void r3ds_dump_light( r3ds_light *light ); void r3ds_dump_camera( r3ds_camera *cam ); void r3ds_dump_trimesh( r3ds_trimesh *trimesh ); void r3ds_dump_object( r3ds_object *obj ); void r3ds_free_object( r3ds_object *obj ); void r3ds_free_material( r3ds_material *mat ); void r3ds_free_scene( r3ds_scene *scene ); int r3ds_first_smgroup( r3ds_triangle *tri ); void r3ds_rebuild_scene_objs( r3ds_scene *scene ); int r3ds_split_trimesh( r3ds_trimesh ***trimeshes_ptr, int message ); int r3ds_split_scene_trimeshes( r3ds_scene *scene, int message ); void r3ds_ChunkReader( FILE *f, int ind, int p ); /* end read3ds.h */ lightspeed-1.2a.debian.1/src/readlwo.c000066400000000000000000000230241334064775200176310ustar00rootroot00000000000000/* readlwo.c */ /* * Copyright (C) 1998 Janne Löf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * This is a heavily modified version of Janne's LWO reader library, as * included in the GtkGLArea distribution (gtkglarea-1.0/examples/lw.c) */ #include #include #include "readlwo.h" #define MK_ID(a,b,c,d) ((((guint32)(a))<<24)| \ (((guint32)(b))<<16)| \ (((guint32)(c))<< 8)| \ (((guint32)(d)) )) #define ID_FORM MK_ID('F','O','R','M') #define ID_LWOB MK_ID('L','W','O','B') #define ID_PNTS MK_ID('P','N','T','S') #define ID_SRFS MK_ID('S','R','F','S') #define ID_SURF MK_ID('S','U','R','F') #define ID_POLS MK_ID('P','O','L','S') #define ID_COLR MK_ID('C','O','L','R') static gint32 read_char(FILE *f) { gint32 c; c = fgetc(f); g_return_val_if_fail(c != EOF, 0); return c; } static gint32 read_short(FILE *f) { guint8 bytes[2]; bytes[0] = read_char(f); bytes[1] = read_char(f); return (bytes[0] << 8) | bytes[1]; } static gint32 read_long(FILE *f) { guint8 bytes[4]; bytes[0] = read_char(f); bytes[1] = read_char(f); bytes[2] = read_char(f); bytes[3] = read_char(f); return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]; } static float read_float(FILE *f) { gint32 x; x = read_long(f); return *(float *)&x; } static gint read_string(FILE *f, char *str) { gint c; gint cnt = 0; do { c = read_char(f); if (cnt < LW_MAX_NAME_LEN) str[cnt] = c; else str[LW_MAX_NAME_LEN - 1] = 0; cnt++; } while (c != 0); /* if length of string (including \0) is odd skip another byte */ if (cnt % 2) { read_char(f); cnt++; } return cnt; } static void read_srfs(FILE *f, gint nbytes, lwObject *lwo) { int guess_cnt = lwo->material_cnt; while (nbytes > 0) { lwMaterial *material; /* allocate more memory for materials if needed */ if (guess_cnt <= lwo->material_cnt) { guess_cnt += guess_cnt / 2 + 4; lwo->materials = xrealloc(lwo->materials, sizeof(lwMaterial) * guess_cnt); } material = lwo->materials + lwo->material_cnt++; /* read name */ nbytes -= read_string(f, material->name); /* defaults */ material->r = 0.5; material->g = 0.5; material->b = 0.5; } lwo->materials = xrealloc(lwo->materials, sizeof(lwMaterial) * lwo->material_cnt); } static void read_surf(FILE *f, gint nbytes, lwObject *lwo) { int i; char name[LW_MAX_NAME_LEN]; lwMaterial *material = NULL; /* read surface name */ nbytes -= read_string(f, name); /* find material */ for (i = 0; i < lwo->material_cnt; i++) { if (strcmp(lwo->materials[i].name, name) == 0) { material = &lwo->materials[i]; break; } } g_return_if_fail(material != NULL); /* read values */ while (nbytes > 0) { gint id = read_long(f); gint len = read_short(f); nbytes -= 6 + len + (len % 2); switch (id) { case ID_COLR: material->r = read_char(f) / 255.0; material->g = read_char(f) / 255.0; material->b = read_char(f) / 255.0; read_char(f); /* dummy */ break; default: fseek(f, len + (len % 2), SEEK_CUR); } } } static void read_pols(FILE *f, int nbytes, lwObject *lwo) { int guess_cnt = lwo->face_cnt; size_t n; while (nbytes > 0) { lwFace *face; int i; /* allocate more memory for polygons if necessary */ if (guess_cnt <= lwo->face_cnt) { guess_cnt += guess_cnt + 4; lwo->faces = xrealloc(lwo->faces, sizeof(lwFace) * guess_cnt); } face = lwo->faces + lwo->face_cnt++; /* number of points in this face */ face->index_cnt = read_short(f); nbytes -= 2; /* allocate space for points */ n = sizeof(int) * face->index_cnt; face->indices = xmalloc(n); /* read points in */ for (i = 0; i < face->index_cnt; i++) { face->indices[i] = read_short(f); nbytes -= 2; } /* read surface material */ face->mat_id = read_short(f); nbytes -= 2; /* skip over detail polygons */ if (face->mat_id < 0) { int det_cnt; face->mat_id = - face->mat_id; det_cnt = read_short(f); nbytes -= 2; while (det_cnt-- > 0) { int cnt = read_short(f); fseek(f, cnt * 2 + 2, SEEK_CUR); nbytes -= cnt * 2 + 2; } } face->mat_id -= 1; } /* readjust to true size */ lwo->faces = xrealloc(lwo->faces, sizeof(lwFace) * lwo->face_cnt); } static void read_pnts(FILE *f, gint nbytes, lwObject *lwo) { int i; lwo->vertex_cnt = nbytes / 12; lwo->vertices = xmalloc( lwo->vertex_cnt * sizeof(lwPoint) ); for (i = 0; i < lwo->vertex_cnt; i++) { lwo->vertices[i].x = read_float(f); lwo->vertices[i].y = read_float(f); lwo->vertices[i].z = read_float(f); } } gint lw_is_lwobject(const char *lw_file) { FILE *f = fopen(lw_file, "rb"); if (f) { gint32 form = read_long(f); gint32 nlen = read_long(f); gint32 lwob = read_long(f); fclose(f); if ((form == ID_FORM) && (nlen != 0) && (lwob == ID_LWOB)) return TRUE; } return FALSE; } lwObject * lw_object_read(const char *lw_file) { FILE *f = NULL; lwObject *lw_object = NULL; size_t n; gint32 form_bytes = 0; gint32 read_bytes = 0; /* open file */ f = fopen(lw_file, "rb"); if (f == NULL) { /* g_warning("can't open file %s", lw_file); */ return NULL; } /* check for headers */ if (read_long(f) != ID_FORM) { /* g_warning("file %s is not an IFF file", lw_file); */ fclose(f); return NULL; } form_bytes = read_long(f); read_bytes += 4; if (read_long(f) != ID_LWOB) { /* g_warning("file %s is not a LWOB file", lw_file); */ fclose(f); return NULL; } /* create new lwObject */ n = sizeof(lwObject); lw_object = xmalloc(n); memset(lw_object, 0, n); /* read chunks */ while (read_bytes < form_bytes) { gint32 id = read_long(f); gint32 nbytes = read_long(f); read_bytes += 8 + nbytes + (nbytes % 2); switch (id) { case ID_PNTS: read_pnts(f, nbytes, lw_object); break; case ID_POLS: read_pols(f, nbytes, lw_object); break; case ID_SRFS: read_srfs(f, nbytes, lw_object); break; case ID_SURF: read_surf(f, nbytes, lw_object); break; default: fseek(f, nbytes + (nbytes % 2), SEEK_CUR); } } fclose(f); return lw_object; } void lw_object_free(lwObject *lw_object) { g_return_if_fail(lw_object != NULL); if (lw_object->faces != NULL) { int i; for (i = 0; i < lw_object->face_cnt; i++) xfree(lw_object->faces[i].indices); xfree(lw_object->faces); } xfree(lw_object->materials); xfree(lw_object->vertices); xfree(lw_object); } #if 0 /* don't need this next bit */ #define PX(i) (lw_object->vertices[face->indices[i]].x) #define PY(i) (lw_object->vertices[face->indices[i]].y) #define PZ(i) (lw_object->vertices[face->indices[i]].z) void lw_object_show(const lwObject *lw_object) { int i, j; int prev_index_cnt = -1; int prev_material = -1; float prev_nx = 0; float prev_ny = 0; float prev_nz = 0; g_return_if_fail(lw_object != NULL); for (i = 0; i < lw_object->face_cnt; i++) { float ax, ay, az, bx, by, bz, nx, ny, nz, r; const lwFace *face = lw_object->faces + i; /* ignore faces with less than 3 points */ if (face->index_cnt < 3) continue; /* calculate normal */ ax = PX(1) - PX(0); ay = PY(1) - PY(0); az = PZ(1) - PZ(0); bx = PX(face->index_cnt - 1) - PX(0); by = PY(face->index_cnt - 1) - PY(0); bz = PZ(face->index_cnt - 1) - PZ(0); nx = ay * bz - az * by; ny = az * bx - ax * bz; nz = ax * by - ay * bx; r = sqrt(nx * nx + ny * ny + nz * nz); if (r < 0.000001) /* avoid division by zero */ continue; nx /= r; ny /= r; nz /= r; /* glBegin/glEnd */ if (prev_index_cnt != face->index_cnt || prev_index_cnt > 4) { if (prev_index_cnt > 0) glEnd(); prev_index_cnt = face->index_cnt; switch (face->index_cnt) { case 3: glBegin(GL_TRIANGLES); break; case 4: glBegin(GL_QUADS); break; default: glBegin(GL_POLYGON); } } /* update material if necessary */ if (prev_material != face->mat_id) { prev_material = face->mat_id; glColor3f(lw_object->materials[face->mat_id].r, lw_object->materials[face->mat_id].g, lw_object->materials[face->mat_id].b); } /* update normal if necessary */ if (nx != prev_nx || ny != prev_ny || nz != prev_nz) { prev_nx = nx; prev_ny = ny; prev_nz = nz; glNormal3f(nx, ny, nz); } /* draw polygon/triangle/quad */ for (j = 0; j < face->index_cnt; j++) glVertex3f(PX(j), PY(j), PZ(j)); } /* if glBegin was called call glEnd */ if (prev_index_cnt > 0) glEnd(); } float lw_object_radius(const lwObject *lwo) { int i; double max_radius = 0.0; g_return_val_if_fail(lwo != NULL, 0.0); for (i = 0; i < lwo->vertex_cnt; i++) { point *v = &lwo->vertices[i]; double r = (v->x * v->x) + (v->y * v->y) + (v->z * v->z); if (r > max_radius) max_radius = r; } return sqrt(max_radius); } void lw_object_scale(lwObject *lwo, float scale) { int i; g_return_if_fail(lwo != NULL); for (i = 0; i < lwo->vertex_cnt; i++) { lwo->vertices[i].x *= scale; lwo->vertices[i].y *= scale; lwo->vertices[i].z *= scale; } } #endif /* 0 */ /* end readlwo.c */ lightspeed-1.2a.debian.1/src/readlwo.h000066400000000000000000000040471334064775200176420ustar00rootroot00000000000000/* readlwo.h */ /* * Copyright (C) 1998 Janne Löf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * This is a heavily modified version of Janne's LWO reader library, as * included in the GtkGLArea distribution (gtkglarea-1.0/examples/lw.h) */ #include #include #define LW_MAX_NAME_LEN 64 typedef struct { char name[LW_MAX_NAME_LEN]; float r, g, b; } lwMaterial; #ifndef lwPoint typedef struct { float x; float y; float z; } lwPoint; #endif typedef struct { int mat_id; /* material of this face */ int index_cnt; /* number of vertices */ int *indices; /* index to vertex */ float *texcoords; /* u,v texture coordinates (not used) */ } lwFace; typedef struct { int face_cnt; lwFace *faces; int material_cnt; lwMaterial *materials; int vertex_cnt; lwPoint *vertices; } lwObject; /* Wrappers for the system memory management functions */ extern void *xmalloc( size_t size ); extern void *xrealloc( void *block, size_t size ); extern char *xstrdup( const char *str ); extern void xfree( void *ptr ); gint lw_is_lwobject(const char *lw_file); lwObject *lw_object_read(const char *lw_file); void lw_object_free(lwObject *lw_object); void lw_object_show(const lwObject *lw_object); float lw_object_radius(const lwObject *lw_object); void lw_object_scale (lwObject *lw_object, float scale); /* end readlwo.h */ lightspeed-1.2a.debian.1/src/settings.h000066400000000000000000000070071334064775200200440ustar00rootroot00000000000000/* settings.h */ /* Compile-time settings */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ /**** Feature switches ***************************************************/ /** Comment any of these out and they will not be compiled in **/ /* Allows importing of 3D Studio and Lightwave objects */ #define WITH_OBJECT_IMPORTER /* Allows exporting to the SRS (Special Relativity Scene) format used * by Antony Searle's BACKLIGHT relativistic raytracer */ #define WITH_SRS_EXPORTER /**** Completely arbitrary defaults **************************************/ /* Set advanced interface as default */ #define DEF_ADVANCED_INTERFACE TRUE /* Initial lattice dimensions and smoothness factor */ #define DEF_LATTICE_X 1 #define DEF_LATTICE_Y 1 #define DEF_LATTICE_Z 1 #define DEF_LATTICE_SMOOTH 6 /* 0 == decimal of c, 1 == meters/sec, 2 == kilometers/hour */ #define DEF_VELOCITY_UNITS 1 /* Initial/resetted camera view. Angles are in degrees */ #define DEF_CAMERA_PHI 195.0 #define DEF_CAMERA_THETA -10.0 #define DEF_CAMERA_FOV 60.0 /* Initial info display configuration */ #define DEF_INFODISP_ACTIVE TRUE #define DEF_INFODISP_SHOW_VELOCITY TRUE #define DEF_INFODISP_SHOW_TIME_T TRUE #define DEF_INFODISP_SHOW_GAMMA FALSE #define DEF_INFODISP_SHOW_FRAMERATE FALSE /* Display gamma correction (1.0 == none) * e.g. 1.5 for a dark monitor, 0.5 for a bright one */ #define DEF_DGAMMA_CORRECT 1.0 /* Mouse sensitivity (mostly a trial & error constant) */ #define DEF_MOUSE_SENS 0.5 /**** Less arbitrary defaults ********************************************/ /* Velocity slider position * 0 == no slider, 1 == at left of viewport, 2 == at right * NOTE: Text for Overview dialog will need updating if this is not 2 ! */ #define VELOCITY_SLIDER 2 /* Look-up tables speed up the warp( ) engine at the expense of a small * margin of precision */ #define USE_LOOKUP_TABLES TRUE /* Table resolution (each will have LUT_RES+1 entries) */ #define LUT_RES 1023 /* Lattice geometry (in meters) */ #define LATTICE_UNIT_SIZE 1.0 #define BALL_RADIUS 0.125 #define STICK_RADIUS (0.125 / SQR(MAGIC_NUMBER)) /* Lattice colors (RGB) */ #define BALL_R 0.01 #define BALL_G 0.125 #define BALL_B 0.5 #define STICK_R 0.5 #define STICK_G 0.5 #define STICK_B 0.5 /* Info display text colors (RGB) */ #define INFODISP_TEXT_FRONT_R 0.0 #define INFODISP_TEXT_FRONT_G 0.75 #define INFODISP_TEXT_FRONT_B 0.0 #define INFODISP_TEXT_BACK_R 0.0 #define INFODISP_TEXT_BACK_G 0.25 #define INFODISP_TEXT_BACK_B 0.0 /* Eye spacing for stereographic SRS output (in meters) */ #define EYE_SPACING 0.064 /* Framerate is a rolling average calculated over roughly this many seconds * (minimum n, maximum n+1 seconds) */ #define FRAMERATE_AVERAGE_TIME 4 /* end settings.h */ lightspeed-1.2a.debian.1/src/snapshot.c000066400000000000000000000266771334064775200200540ustar00rootroot00000000000000/* snapshot.c */ /* Image exporter */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" #ifdef HAVE_LIBPNG #include static int write_png( int message, const void *data ); #include #endif #ifdef HAVE_LIBTIFF #include static int write_tiff( int message, const void *data ); #endif /* [Other] forward declarations */ static int write_image( int format, int message, const void *data ); void save_snapshot( int width, int height, const char *filename, int format ) { GdkGLContext *context; GdkPixmap *pixmap; GLubyte *scanline; float x,y,z; #ifdef HAVE_GTK1 GdkGLPixmap *glpixmap; GdkVisual *visual; int visual_attributes[] = { GDK_GL_RGBA, GDK_GL_RED_SIZE, 8, GDK_GL_GREEN_SIZE, 8, GDK_GL_BLUE_SIZE, 8, GDK_GL_DEPTH_SIZE, 1, GDK_GL_NONE }; #else GdkGLDrawable *gldrawable; #endif int ogl_y; int err; int percent, prev_percent = -1; char comments[1024]; char one_line[256]; /* Initialize output camera */ memcpy( &out_cam, usr_cams[0], sizeof(camera) ); out_cam.width = width; out_cam.height = height; /* Create off-screen rendering buffer (i.e. pixmap) */ #ifdef HAVE_GTK1 visual = gdk_gl_choose_visual( visual_attributes ); if (visual == NULL) { message_window( gettext(STR_DLG_Error), gettext(STR_MSG_no_ogl_visual) ); return -1; } pixmap = gdk_pixmap_new( NULL, width, height, visual->depth ); #else g_return_if_fail(usr_cams[0] || usr_cams[0]->ogl_w || usr_cams[0]->ogl_w->window ); pixmap = gdk_pixmap_new( usr_cams[0]->ogl_w->window, width, height, -1); #endif if (pixmap == NULL) { sprintf( one_line, gettext(STR_MSG_no_render_buf_ARG), width, height ); message_window( STR_DLG_Error, one_line ); return ; } #ifdef HAVE_GTK1 glpixmap = gdk_gl_pixmap_new( visual, pixmap ); context = gdk_gl_context_new( visual ); err = !gdk_gl_pixmap_make_current( glpixmap, context ); if (err) { message_window( gettext(STR_DLG_Error), gettext(STR_MSG_no_ogl_context) ); gdk_gl_context_unref( context ); gdk_gl_pixmap_unref( glpixmap ); gdk_pixmap_unref( pixmap ); return ; } #else /* inspired by example/pixmap.c in gtkglext1 */ gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (pixmap, glconfig, NULL)); context = gdk_gl_context_new (gldrawable,NULL, FALSE,GDK_GL_RGBA_TYPE); if (context == NULL) { g_critical("Cannot create the OpenGL rendering context\n"); return ; } if (!gdk_gl_drawable_gl_begin (gldrawable, context)) { g_critical("Cannot draw to the OpenGL pixmap\n"); return ; } #endif /* Basic setup. Mennucc: this does not interfere with the above gl_begin */ ogl_initialize( NULL, NULL ); /* For extra-high quality output */ glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); glHint( GL_POINT_SMOOTH_HINT, GL_NICEST ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); /* GL_LINE_SMOOTH looks crummy */ /* glEnable( GL_LINE_SMOOTH ); */ /* Produce image description (comments) */ if (object_mode == MODE_LATTICE) { sprintf( comments, _("%dx%dx%d lattice, travelling at %s in the +x direction.\n\n"), lattice_size_x, lattice_size_y, lattice_size_z, velocity_string( velocity, TRUE ) ); } else sprintf( comments, _("Object travelling at %s in the +x direction.\n\n"), velocity_string( velocity, TRUE ) ); x = out_cam.pos.x; y = out_cam.pos.y; z = out_cam.pos.z; sprintf( one_line, _("Camera position: (%.3f, %.3f, %.3f)\n"), x, y, z ); strcat( comments, one_line ); x = out_cam.target.x; y = out_cam.target.y; z = out_cam.target.z; sprintf( one_line, _("Camera target..: (%.3f, %.3f, %.3f)\n"), x, y, z ); strcat( comments, one_line ); sprintf( one_line, _("Camera FOV.....: %.2f degrees"), out_cam.fov ); strcat( comments, one_line ); if (width != height) sprintf( one_line, _(" horizontally\n\n") ); else sprintf( one_line, "\n\n" ); strcat( comments, one_line ); sprintf( one_line, _("Observed object is centered at the origin.\n") ); strcat( comments, one_line ); sprintf( one_line, _("Coordinate system is right-handed with +z up.\n") ); strcat( comments, one_line ); sprintf( one_line, _("Above units are in meters, where unspecified.\n\n") ); strcat( comments, one_line ); sprintf( one_line, _("This image was produced by the Light Speed! relativistic simulator.\n") ); strcat( comments, one_line ); /* TODO: Fix description...? it's inaccurate if an animation is ongoing, or * if any of the relativistic transforms are switched off */ /* Initialize output file */ err = FALSE; err = err || write_image( format, IMAGE_WIDTH, &width ); err = err || write_image( format, IMAGE_HEIGHT, &height ); err = err || write_image( format, IMAGE_COMMENTS, comments ); err = err || write_image( format, IMAGE_FILENAME, filename ); if (err) { message_window( gettext(STR_DLG_Error), gettext(STR_MSG_no_snapshot_output) ); return ; } /* Mennucc: this does interfere with the above gl_begin and is useless */ #ifndef HAVE_GTK1 gdk_gl_drawable_gl_end(gldrawable); #endif ogl_blank( 0, STR_MSG_Rendering_snapshot ); #ifdef HAVE_GTK1 gdk_gl_pixmap_make_current( glpixmap, context );/* switch back */ #else gdk_gl_drawable_gl_begin(gldrawable,context); #endif /* Draw! */ /* Mennucc: this does not interfere with the above gl_begin*/ ogl_draw( -1 ); /* Read and export rows of pixels, one by one */ scanline = xmalloc( width * 3 * sizeof(GLubyte) ); glPixelStorei( GL_PACK_ALIGNMENT, 4 ); for (ogl_y = height - 1; ogl_y >= 0; ogl_y--) { glReadPixels( 0, ogl_y, width, 1, GL_RGB, GL_UNSIGNED_BYTE, scanline ); err = write_image( format, IMAGE_PIXELROW, scanline ); if (err) break; percent = (100 * (height - ogl_y)) / height; if (percent != prev_percent) { #ifndef HAVE_GTK1 gdk_gl_drawable_gl_end(gldrawable); #endif sprintf( one_line, gettext(STR_MSG_Saving_snapshot_ARG), percent ); ogl_blank( 0, one_line ); /* switch back to pixmap GL context */ #ifdef HAVE_GTK1 gdk_gl_pixmap_make_current( glpixmap, context ); #else /* Mennucc: FIXME: for some obscure reason, the counter for saving the image is not shown... even tried this... while (gtk_events_pending ()) gtk_main_iteration (); and this gdk_flush(); */ gdk_gl_drawable_gl_begin(gldrawable,context); #endif prev_percent = percent; } } xfree( scanline ); #ifndef HAVE_GTK1 gdk_gl_drawable_gl_end(gldrawable); #endif /* Close up output file */ write_image( format, IMAGE_COMPLETE, NULL ); #ifdef HAVE_GTK1 gdk_gl_context_unref( context ); gdk_gl_pixmap_unref( glpixmap ); #else gdk_gl_context_destroy( context ); #endif gdk_pixmap_unref( pixmap ); if(err) message_window( gettext(STR_DLG_Error), _("while writing the image to the file") ); return ; } /* Dispatcher for the various file format handlers */ static int write_image( int format, int message, const void *data ) { switch (format) { #ifdef HAVE_LIBPNG case IMAGE_FORMAT_PNG: return write_png( message, data ); #endif #ifdef HAVE_LIBTIFF case IMAGE_FORMAT_TIFF: return write_tiff( message, data ); #endif default: break; } return -1; } /* PNG output */ #ifdef HAVE_LIBPNG static int write_png( int message, const void *data ) { static FILE *png_fp; static png_structp png_write_s; static png_infop png_info_s; static png_text comments[2]; static int width, height; GLubyte *pixelrow; char *filename; char *text; switch (message) { case IMAGE_WIDTH: width = *((int *)data); break; case IMAGE_HEIGHT: height = *((int *)data); break; case IMAGE_COMMENTS: text = (char *)data; comments[0].key = "Title"; comments[0].text = N_("Light Speed! snapshot"); comments[0].compression = PNG_TEXT_COMPRESSION_NONE; comments[1].key = "Description"; comments[1].text = text; comments[1].compression = PNG_TEXT_COMPRESSION_NONE; break; case IMAGE_FILENAME: filename = (char *)data; png_fp = fopen( filename, "wb" ); if (png_fp == NULL) return -1; png_write_s = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL ); png_info_s = png_create_info_struct( png_write_s ); #if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4 if (setjmp(png_jmpbuf(png_write_s))) { #else if (setjmp( png_write_s->jmpbuf )) { #endif /* Error writing file */ png_destroy_write_struct( &png_write_s, &png_info_s ); fclose( png_fp ); return -1; } png_init_io( png_write_s, png_fp ); png_set_IHDR( png_write_s, png_info_s, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT ); /* png_set_gAMA( png_write_s, png_info_s, dgamma ); */ png_set_compression_level( png_write_s, Z_BEST_COMPRESSION ); png_set_text( png_write_s, png_info_s, comments, 2 ); png_write_info( png_write_s, png_info_s ); break; case IMAGE_PIXELROW: pixelrow = (GLubyte *)data; png_write_row( png_write_s, pixelrow ); break; case IMAGE_COMPLETE: png_write_end( png_write_s, NULL ); png_destroy_write_struct( &png_write_s, &png_info_s ); fclose( png_fp ); break; } return 0; } #endif /* HAVE_LIBPNG */ /* TIFF output */ #ifdef HAVE_LIBTIFF static int write_tiff( int message, const void *data ) { static TIFF *tiff; static FILE *tiff_fp; static int width, height; static char *text = NULL; static int img_y = 0; GLubyte *scanline; int rows_per_strip; int rv; char *filename; switch (message) { case IMAGE_WIDTH: width = *((int *)data); break; case IMAGE_HEIGHT: height = *((int *)data); break; case IMAGE_COMMENTS: text = (char *)data; break; case IMAGE_FILENAME: filename = (char *)data; tiff_fp = fopen( filename, "w" ); if (tiff_fp == NULL) return -1; tiff = TIFFFdOpen( fileno( tiff_fp ), "output file", "w" ); if (tiff == NULL) return -1; TIFFSetField( tiff, TIFFTAG_IMAGEWIDTH, width ); TIFFSetField( tiff, TIFFTAG_IMAGELENGTH, height ); TIFFSetField( tiff, TIFFTAG_BITSPERSAMPLE, 8 ); TIFFSetField( tiff, TIFFTAG_COMPRESSION, COMPRESSION_LZW ); TIFFSetField( tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB ); TIFFSetField( tiff, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB ); TIFFSetField( tiff, TIFFTAG_DOCUMENTNAME, "Light Speed! snapshot" ); TIFFSetField( tiff, TIFFTAG_IMAGEDESCRIPTION, text ); TIFFSetField( tiff, TIFFTAG_SAMPLESPERPIXEL, 3 ); rows_per_strip = MAX(1, 8192 / (3 * width)); TIFFSetField( tiff, TIFFTAG_ROWSPERSTRIP, rows_per_strip ); TIFFSetField( tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG ); break; case IMAGE_PIXELROW: scanline = (GLubyte *)data; rv = TIFFWriteScanline( tiff, scanline, img_y++, 0 ); if (rv < 0) return -1; break; case IMAGE_COMPLETE: TIFFFlushData( tiff ); TIFFClose( tiff ); fclose( tiff_fp ); break; } return 0; } #endif /* HAVE_LIBTIFF */ /* end snapshot.c */ lightspeed-1.2a.debian.1/src/title.xpm000066400000000000000000000445401334064775200177050ustar00rootroot00000000000000/* XPM */ static char * lightspeed_title_xpm[] = { "300 60 32 1", " c None", ". c #020204", "+ c #024287", "@ c #022245", "# c #0262C6", "$ c #021225", "% c #0252A6", "& c #023265", "* c #0274E8", "= c #020A15", "- c #024A95", "; c #022A55", "> c #026AD4", ", c #021A35", "' c #025AB7", ") c #023A76", "! c #027AF4", "~ c #02060D", "{ c #02468E", "] c #02264D", "^ c #0266CC", "/ c #02162D", "( c #0256AE", "_ c #02366D", ": c #020E1D", "< c #024E9D", "[ c #022E5E", "} c #026EDC", "| c #021E3D", "1 c #025EBC", "2 c #023E7D", "3 c #027EFC", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "...............................~....................~~..........~~~~~~~~~~~~~~~~~.........~~..............~~~........~~~~~~~~~~~~~~............................~~~~~~~~~~...............~~~~~~~~~~~~~...........~~~~~~~~~~~~~.........~~~~~~~~~~~~~........~~~~~~~~~~~~~~~~.................................", "..........................~~======~~~...........~~======~~~~~~======================~~~=======~~~.....~~=======~~~===================~~...................~~~==============~~.......~~=================~~~~~~~==================~~~==================~~~=====================~~~....~~======~~..............", "........................~~=:$$$$$$::=~~.......~=::$$$$$$$:::::$$$///////////////$$$$::$$$$$$$$::=~~~~==:$$$/$$$$$$$$$$/////////////$$:==~...............~==:$$$//////////$$:==~~.~~=::$$/////////////$$:::==::$$$////////////$$$$$$$$$////////////$$$$$$$$$$///////////////$$::=~~~==:$$$$$$:=~~............", ".......................~=:$/,|||||,/$:~~.....~=:/,||||||,,//,,|||@@@@@@@@@@@@@@@@||,,,,,||||||,/$:==::/,,||@|||,,,,|||@@@@@@@@@@@@||,,$:=~............~~=:$/,||@@@@@@@@@||,,$:==~==:/,,|@@@@@@@@@@@@@||,//$//,,||@@@@@@@@@@@@|||,,,|||@@@@@@@@@@@@|||,,,,|||@@@@@@@@@@@@@@@||,/$:::$$/,||||,/$:=~...........", "......................~=:/|@;;[[[;]@,$:~~..~~:$,|];[[[[;;]]]]];[[[[&&&&&&&&&&&&[[[;;;;;;;[[[[;]@,/$$/,|];[[[[[;;;;;;[[[[&&&&&&&&&[[[;]|/:=~..........~=:$,|@;;[[[&&&&&&[[[;]|/$:::$,|];[[[&&&&&&&&&[[[;]]@@@@];[[[[&&&&&&&&[[[[;;;;;[[[[&&&&&&&&[[[[;;;;;;[[[[&&&&&&&&&&&[[[;]@|,//,|@;;[[;;@|/:=~..........", ".....................~=:/|;[_))))_&;@,$=~.~~=$,@;&_)))))__&&&_))22222222222222222))_____)))))_&;]|,,|];&_))2)))____))22222222222222)_&]|/:~.........~=:/|@;&_))2222222222)_&;@,/$/|@;&_)2222222222222))_&[[[[&_))222222222222)))___)))2222222222222))____))2222222222222222)_&[;@@@];&_))))_[]|/:~..........", ".....................~:/@;_)+{--{+2_[@/:=~~=$,][_2+{--{{{+++++{{------------------{{++{{{---{+2_[;]];[_2+{---{{{++{{{--------------{+)&]|$=~.......~=:/|]&)2+{-----------{+)&;@|,|][_2+{-------------{{+22))2++{--------------{{{+{{{--------------{{{++{{{----------------{{+)_&[[&)2+{{{{+)&],$=~.........", "....................~=$|;&2%##^^##1{&],$===:/@[){1##^^^#1<--<(1^^^^^^^^^^^^^^^^^^^#'<<<1#^^^##1+_&[[&)+'##^^^^#%<<%#^^^^^^^^^^^^^^^##()[@/:~......~=:/|;&)+-(1^^^^^^^^^^^##()&;@@][)+'##^^^^^^^^^^^^^^#'-{{{-(##^^^^^^^^^^^^^^^'<<<#^^^^^^^^^^^^^^^^#%<<(#^^^^^^^^^^^^^^^^^^#1{+2))2+%##^###%);|/=~.........", "....................=:,]&2-*333333*{_;|$:=:/|;_+'3333333>(%(}33333333333333333333331(('3333333*{2)__2+%!333333*(((}33333333333333333312&@/:~......~:/|;&2->333333333333333312_[;;&)+(3333333333333333333*'%%%*33333333333333333#((#33333333333333333*(((*333333333333333333333><-{{-<*3333331)[@/:~.........", "...................~:/|;)+13333333#+_;|$::$,]&2-*33333331''}3333333333333333333333*'''>33333331-+2)2+-^3333333^'''333333333333333333!<2&@/:~.....~=$,]&2<*3333333333333333!<+_&[&_2{}33333333333333333333}((#33333333333333333!'''*33333333333333333^''13333333333333333333333*%%<<%13333333-2[@/:~.........", "...................=:,]&2-*3333333<+&],$::/|;_+(3333333}''^33333333333333333333333^1'1!333333*<-+22+-%!333333!1''>333333333333333333>{)[@/=~.....~:/@[){*33333333333333333^-2_&&_2{%333333333333333333333>''*33333333333333333>11#33333333333333333!111*3333333333333333333333*'((((*333333^{)[|$=~.........", "..................~=/|[){'3333333>-2[@/$::/@[2-}3333333^11*3333333333333333333333!111>3333333^<-+++{<13333333>''1!333333333333333333%+_;,$=~....~=$|;_+1333333333333333333%{)_&&_+-^33333333333333333333!11#333333333333333333111*33333333333333333}11#33333333333333333333333>''''13333333(+_;|$=..........", "..................~:,]&2-}3333333({);|/::$,]_+(3333333*11#33333333333333333333333>111*333333!(<{++{-%*333333!1''>333333333333333333}{)[@/:~.....~:/@[2-*33333333333333333}{2_&[&)+%!33333333333333333333}11}33333333333333333}11#333333333333333333#11}33333333333333333333333111'1}333333}-2&@/:~..........", ".................~=$|;){(3333333*-2&],$::$|;_{^3333333^11>3333333333333333333333!111^3333333}%<{++{-'!333333}(((*333333333333333333(2_]|$=~.....~:,]_+%!33333333333333333(+)&[[&){#333333333333333333333#1#!3333333333333333!#11>33333333333333333*111!3333333333333333333333*11111!333333'{)[|/=~..........", ".................~:/]&2->3333333'{)[@/:::/@[){%('1111111111111111111111111111111''''111111''(%<-{{-<%('''''(%%<%%(''111111''((%%<-{2_;|/:~......=$,;_+'33333333}#11''(%<-+)&;;[&2{%('111111111#*3333333*111111111111111111111111111111111111111111111111111'''''''1^!33333333#1111>333333*-+&],:=...........", "................~=$|;_+%3333333*-+_],$::$,]&2-%''111111111111111111111111111111'''''111111''(%<---<%('''''(%<---<%(''1111''(%<--+2)&;@/:=~......=$|;){#3333333!#111'((<-+)&;]][_+-%('1111111111*3333333^11111111111111111111111111111111111111111111111111''((((((''}3333333*11111!3333331{)[@/:~...........", "................~:/@&2-^3333333#{)[@/$::/|[){<(''111111111111111111111111111111'''''1111111''(%<<<%((''''(%<{++{-<(''111''(%<{+2_&[]|/$=~.......=$|;){#3333333*111''(%-+)&;]];[)+<(''111111111#3333333*11111111111111111111111111111111111111111111111111''((%%%%(''*3333333^1111^333333*<+_],$=............", "................=$,]_+<*333333!%+_;|$::$,]&2-%('1111111111111111111111111111111'''''1111111'''((%%(('''''(%-+222{<%''111''(<-+_&;]@,/:=~........=$|;_{#33333333^11''(<{2_[]@];_2-<('1111111111}3333333^11111111111111111111111111111111111111111111111111''(%<<<<%('3333333!11111*333333^-2&@/:~............", "...............~:/@[){#3333333^-2&@,$:$,@[){('1#####111########1111###########11''############11111#####11<{2))2{-%1#####1'-+_[]|,/$:=~.........~:,]_+(333333333*^1'%<{2&;]];&){%'1#######^#^}3333333!11#^^#^^#^^#^^#######111##################111#######1(<---<%(>3333333>1111^3333333%+_;|$=~............", "...............=$,]&+-*3333333%{_;|/$$/|;_+(3333333*11^3333333*1111!3333333333^111!3333333333333333333333!<{2))2{<13333333^{)&]|/$:=~~..........~:/@&2'<{2_[;;&_+11*33333333333333333>11#33333333333333333!111*33333331<-{-<%(!333333!#1111*333333>-2&]/:~.............", "..............~=/|[){'3333333}-2&],$$$,]&2-}3333333^11*3333333#111>3333333333!111>33333333333333333333333^-+2))2{<*3333333%+_;|/:=~~............~=$|;_+#3333333333333^-+)_&&_2-#33333333333333333333!#1#333333333333333333111}33333333333333333}11#!333333*%<-{-<%#3333333}1111#3333333({);|$=~.............", "..............~:,]&2-}3333333'{)[@/$$/|;_+%!333333*11#3333333*1111!3333333333}111*3333333333333333333333!(-+2)2+-(3333333}-2&@/:=~...............~:/@[){}3333333333333#-+2))+{%!33333333333333333333}11}33333333333333333*11#!33333333333333333#11}3333333#<-{{-<%*333333311111}333333*-2&],:~..............", ".............~=$|;){(3333333*<+_]|/$$,]&2->3333333^11}3333333^111^3333333333!#11^33333333333333333333333><{+22+{<}3333333({);|$=~................~=$|]&){#!33333333333!(-{{{-<#333333333333333333333#1#!33333333333333333#11>33333333333333333*111!333333!%<----%13333333*1'''1!333333'{);|/=~..............", ".............~:/@&2->33333331-2&],$$/|;_+33333333333333333*111!33333333333333333#11>3333333>%<---<%}3333333#''''>333333*-2&],:=...............", "............~=$|;_+%3333333*<{)[@,//|]&2-#3333333>11>3333333>1''#!3333333333#11#33333333333333333333333*<-+22+{<>33333331{)[|/=~..............~~~=:$/|][)+-<(^333333333}(%%%(#3333333333333333333!}111!33333333333333333^11>33333333333333333*111*333333!'%<--<<'3333333*''(''*3333331+_;|$=~...............", "............~:/@[2-^3333333^<{)&]|,|@[_+<*333333!#11!33333331'''1#^33333333*111}3333333>####^^^*33333331-{222+-%!333333*<+_],$=.............~~==:$$/,|][_2{<%(^33333333*''(''*3333333^#11111111111''1^3333333*^^^^^^^^^^111*333333!^^^^^^^^^^#11^3333333}(%<-<<%>3333333#'((((11111'%{)[@/:=................", "............=$,;_+%!333333!'<{2_[]]][_2-13333333}11^3333333}''''''1*3333333^11#3333333*'''''''1!333333*%-+22+{<^3333333#{2[@/:~............~=:$/,,||@];[_2{-%('*3333333*''''#3333333*(%<<-----<<%(''1*3333333#111111111111^3333333*1111111111111*33333331(%<<<%(3333333!'((%(((''(%<{)&],$=~................", "...........~:/@[){13333333>(%-+)_&[&_2{<*3333333#11*3333333#''''''1!333333*111}3333333^(((((''>3333333^<{+22+-%*333333!%+_;|$=~...........~=:/,@]];;[[&_)+{<%('*3333333}1111*33333331%-{+2222++{<%('#3333333*1111111111111*3333333#111111111111#3333333*'((%%%(^3333333>'((%(((''(%-2_;|$:~.................", "...........=$,]_+<*33333331'(<-{2222+{<'3333333*11^3333333*1''''''>3333333>111!3333333(%%%%(('!333333!%-+222{-13333333>-2&@/:~...........~=$,|][&__)))22+{<%('1!3333333>11113333333*%-+)_&&[&&)2{<%(*3333333^111111111111#3333333*1111111111111*3333333#''(((('!333333!1'(((((('((<{)[@/:=..................", "..........~=/|[){'3333333*''((%<-{{--<%}3333333^11*3333333}1'''''1!3333333111>3333333>%<<<<%(^3333333><{+22+-<*3333333%{);|$=~..........~=$,@;&)2++{{{{--<%%('>33333333#111}3333333#-+)&;]@@];[_+-%'3333333*1111111111111}3333333^111111111111#3333333*1''''''>3333333}'''((('''(%-+_;,$=~..................", "..........~:,]&2-*3333333^#111''(((%%(13333333*11#33333333!^####^*3333333}111*3333333'<---<%(*333333!(-{222{-'3333333}-2&],:~...........~:/@;_+<%%((((((''1#>*33333333*1111!333333!%{)[]|,//,@;&2-%>3333333>#########111#!333333!##########111}3333333>##111#>333333331'''''11111'<+&],:~...................", ".........~=$|;){(33333333333333333*'('}3333333^11}33333333333333333333333#11^3333333}%<-{-<%13333333}<{+22+{<}3333333'{)[|$=~..........~=$|;_2'33333333333333333333333#111>3333333^-2&]|/$:$/,]&2-(!3333333333333333!#11}33333333333333333}111!3333333333333333333333*11''1*333333(2&@/:~...................", ".........~:/@&2->33333333333333333}''13333333!11#!3333333333333333333333*111*3333333'<-{{-<%*3333333'-{222{-(3333333*<+_],:=...........~:,]&2{*3333333333333333333333}1111*3333333%{_;|/:===$,]&2-^33333333333333333*111!33333333333333333#11>33333333333333333333333#1111>333333*-2[@/=~...................", ".........=$,;_+3333333>11>33333333333333333333333#11#3333333*%-{{{-<(3333333*<{+22+{<>33333331{)[@/:~..........~=$|;_+(3333333333333333333333*1''1^3333333}-2&],$=~~=$,;_+<*33333333333333333^11>33333333333333333*111*3333333333333333333333*1''11*333333#{);|$=~...................", "........~=/|[){^33333333333333333*111*333333!1''*3333333333333333333333*''1}33333331<{++{-<>33333331-+2)2+-%3333333!<+_],$=~..........~:/@&2-*333333333333333333333*'''''*3333333(+);|$=~~~=$|[){133333333333333333*111*33333333333333333^11^33333333333333333333333#''''^333333!<+_],:=....................", "........~:/@&2<*33333333333333333^''^3333333}'''*3333333333333333333333#''1!333333*<{+22+-%!333333*<{2)))+-#3333333^{)[@/:~...........=:,]_+(333333333333333333333}(%%((#3333333}-2&],:=~~~:/@[)-*33333333333333333>''#33333333333333333!1''*3333333333333333333333>(((('*333333^{)[@/:~....................", "........~:/@&2'33333333333333333*'('*3333333'%%(*33333333333333333333!1(((>3333333#{+)))2{#3333333#{2_&&_2-*333333!<2&],$=~...........=$,]_+}3333333333333333333*1<--<<%}3333333'+_;|$=~..~:/@[)(33333333333333333!'('*33333333333333333>((13333333333333333333333^<<<<%13333333<+_;,$=~....................", "........~:/@[)}!!!!!!!!!!!!!!!!!#%%'!!!!!!!}<<-<1*!!!!!!!!!!!!!!!!!*^(<<<<*!!!!!!*-2_&&_)+*!!!!!!*-2_&[[&)%*!!!!!!^+_;|/:~............=:,]&{*!!!!!!!!!!!!!!!**^'-{++++{<*!!!!!!*+)[@/:~...~:/@[)^!!!!!!!!!!!!!!!!!>%%'!!!!!!!!!!!!!!!!!*(%%>!!!!!!!!!!!!!!!!!!!*>(-{++{-^!!!!!!>+)[@/:~.....................", "........~=/|;_2{-<<<<<<<<<<<<<--------<<<--{++++{{--<<<<<<<<<<<<<<--{++++{{-----{+)_[;;;&)+{----{+)_[]]];&)+{----{2_[@/:=~............~:/@[)+{-<<<<<<<<<<<<<--{+2)_&&_)+{-----{+)[],$=~...~=$|;&2{-<<<<<<<<<<<<<--------<<<<<<<<<<<<<<--------<<<<<<<<<<<<<<<<--{+2)__)2+{----{+_[@,$=~.....................", "........~=$,@[_)2++++++++++++++222222++++22)____))2+++++++++++++++22)_____)2+++2)_&;@||@;[_)2++22_&;@|,|@;&)2+++2)&[@,$=~.............~=$|][_2+++++++++++++++2)_&[;]];[_)2+++2)_[],$=~....~=:,@;_)2++++++++++++++222222+++++++++++++++2222222++++++++++++++++++2)_[[;;[&_)2++2)_[],$=~......................", ".........~:$,@;[&&___________&&&[[[[&&&&&&[;;]]];[&&&____________&&[;;]]];[[&&&&[;@|,//,|@;[&&&&[;]|/$$/,|];[&&&&[]@,$=~..............~=:/|];[&&___________&&[[;@|,,,|@];[&&&&[;@,$:~......~=$,@;[&&___________&&&[[[[&&&____________&&&[[[[&&&______________&&[;]@|||@];[&&&&[;@,$:~.......................", "..........~:$/|@@]]]]]]]]]]]]]]@@@@@@]]]]@@|,,,,|@@]]]]]]]]]]]]]]]@@||,,,||@]]]@@|,$:::$/,|@@]]@@|,/::=:$/,|@]]]@|,/$=~................~=:/,|@]]]]]]]]]]]]]]@@|,//$$$$/,|@]]]@@|/$:~~.......~=$/|@@]]]]]]]]]]]]]]@@@@@@]]]]]]]]]]]]]]]@@@@@@@]]]]]]]]]]]]]]]]]]@|,//$$/,|@@]]@@,/$=~~.......................", "..........~~=:$///,,,,,,,,,,,////$$////,///$$:::$$//,,,,,,,,,,,,,///$$:::$$//////$:==~~==:$//////$:==~~~=:$$/////$$:=~..................~=::$//,,,,,,,,,,,,///$$:=====::$//////$:=~..........~=:$///,,,,,,,,,,,////$$////,,,,,,,,,,,,////$$///,,,,,,,,,,,,,,,///$::===::$//////$:=~.........................", "............~~==::::::::::::::::====::::::===~~===:::::::::::::::::===~~===:::::==~~~..~~===::::===~~...~~==:::::==~~....................~~==::::::::::::::::===~~~..~~===::::==~~............~~==::::::::::::::::====:::::::::::::::::=====:::::::::::::::::::===~~~~~===::::==~~..........................", "..............~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.....~~~~~~~~~~~~~~~~~~~~.....~~~~~~~~........~~~~~~~~.........~~~~~~~..........................~~~~~~~~~~~~~~~~~~~.........~~~~~~~.................~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~........~~~~~~.............................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................", "............................................................................................................................................................................................................................................................................................................"}; lightspeed-1.2a.debian.1/src/trackmem.c000066400000000000000000000156441334064775200200100ustar00rootroot00000000000000/* trackmem.h */ /* Memory allocation accounting utilities * This is what I used to nail down memory leaks :) */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "trackmem.h" #ifdef TRACKMEM_VERBOSE static int trackmem_verbose = TRUE; #else static int trackmem_verbose = FALSE; #endif #ifdef MALLOC_HOOKS /* Use this if you want to track memory use via malloc() hooks * (you might not want to have TRACKMEM_VERBOSE set... it gets awful spammy) */ void trackmem_init( void ) { fprintf( stderr, "trackmem_init() says hello\n" ); prev_malloc_hook = __malloc_hook; __malloc_hook = trackmem_malloc_hook; prev_realloc_hook = __realloc_hook; __realloc_hook = trackmem_realloc_hook; prev_free_hook = __free_hook; __free_hook = trackmem_free_hook; fprintf( stderr, "malloc() hooks are in place\n" ); fflush( stderr ); } static void * trackmem_malloc_hook( size_t size ) { void *block; __malloc_hook = prev_malloc_hook; __realloc_hook = prev_realloc_hook; __free_hook = prev_free_hook; block = malloc( size ); trackmem( TRACKMEM_MALLOC, block, NULL, size ); __free_hook = trackmem_free_hook; __realloc_hook = trackmem_realloc_hook; __malloc_hook = trackmem_malloc_hook; return block; } static void * trackmem_realloc_hook( void *block, size_t size ) { void *block2; __malloc_hook = prev_malloc_hook; __realloc_hook = prev_realloc_hook; __free_hook = prev_free_hook; block2 = realloc( block, size ); trackmem( TRACKMEM_REALLOC, block, block2, size ); __free_hook = trackmem_free_hook; __realloc_hook = trackmem_realloc_hook; __malloc_hook = trackmem_malloc_hook; return block; } static void trackmem_free_hook( void *block ) { __malloc_hook = prev_malloc_hook; __realloc_hook = prev_realloc_hook; __free_hook = prev_free_hook; trackmem( TRACKMEM_FREE, block, NULL, 0 ); free( block ); __free_hook = trackmem_free_hook; __realloc_hook = trackmem_realloc_hook; __malloc_hook = trackmem_malloc_hook; } void trackmem_stop( void ) { __malloc_hook = prev_malloc_hook; __realloc_hook = prev_realloc_hook; __free_hook = prev_free_hook; trackmem( TRACKMEM_QUIT, NULL, NULL, 0 ); } #endif /* MALLOC_HOOKS */ void trackmem_show_stats( void ) { trackmem( TRACKMEM_SHOW_STATS, NULL, NULL, 0 ); } void trackmem_show_blocks( void ) { trackmem( TRACKMEM_SHOW_BLOCKS, NULL, NULL, 0 ); } void trackmem( int message, void *block, void *block2, size_t size ) { static void **allblocks = NULL; static int *allsizes = NULL; static int num_blocks = 0; static int total_size = 0; int verbose = trackmem_verbose; int block_id; switch (message) { case TRACKMEM_MALLOC: if (verbose) fprintf( stderr, "%p ALLOC: +%d ", block, size ); case TRACKMEM_MALLOC_EQUIV: if (size == 0) fprintf( stderr, "[BUG! Allocating zero-size block]" ); ++num_blocks; allblocks = realloc( allblocks, num_blocks * sizeof(void *) ); allblocks[num_blocks - 1] = block; allsizes = realloc( allsizes, num_blocks * sizeof(int) ); allsizes[num_blocks - 1] = (int)size; total_size += (int)size; if (message == TRACKMEM_MALLOC_EQUIV) return; break; case TRACKMEM_REALLOC: if (verbose) fprintf( stderr, "%p REALLOC: ", block2 ); if (block == NULL) { if (verbose) fprintf( stderr, "+%d (from NULL)", size ); trackmem( TRACKMEM_MALLOC_EQUIV, block2, NULL, size ); } else { block_id = trackmem_search_for_block( block, allblocks, num_blocks ); if (block_id == -1) { fprintf( stderr, "+%d [BUG! Reallocating unknown block]\n", size ); fflush( stderr ); return; } else { if (verbose) fprintf( stderr, "%+d (from %p)", size - allsizes[block_id], block ); allblocks[block_id] = block2; total_size += (size - allsizes[block_id]); allsizes[block_id] = (int)size; } } break; case TRACKMEM_STRDUP: size = strlen( (char *)block ) + 1; if (verbose) fprintf( stderr, "%p STRDUP: +%d", block, size ); trackmem( TRACKMEM_MALLOC_EQUIV, block, NULL, size ); break; case TRACKMEM_FREE: if (verbose) fprintf( stderr, "%p FREE: ", block ); block_id = trackmem_search_for_block( block, allblocks, num_blocks ); if (block == NULL) { fprintf( stderr, "[BUG! Attempting to free null block]\n" ); fflush( stderr ); return; } else if (block_id == -1) { fprintf( stderr, "[BUG! Attempting to free unknown block]\n" ); fflush( stderr ); return; } else { total_size -= allsizes[block_id]; if (verbose) fprintf( stderr, "-%d", allsizes[block_id] ); --num_blocks; if (block_id != num_blocks) { memmove( &allblocks[block_id], &allblocks[block_id + 1], (num_blocks - block_id) * sizeof(void *) ); memmove( &allsizes[block_id], &allsizes[block_id + 1], (num_blocks - block_id) * sizeof(int) ); } allblocks = realloc( allblocks, num_blocks * sizeof(void *) ); allsizes = realloc( allsizes, num_blocks * sizeof(int) ); } break; case TRACKMEM_SHOW_STATS: fprintf( stderr, "Total: %d blocks (%d bytes)\n", num_blocks, total_size ); fflush( stdout ); return; case TRACKMEM_SHOW_BLOCKS: fprintf( stderr, "==== Current TRACKMEM database ====\n" ); for (block_id = 0; block_id < num_blocks; block_id++) fprintf( stderr, " %p: %d bytes\n", allblocks[block_id], allsizes[block_id] ); trackmem( TRACKMEM_SHOW_STATS, NULL, NULL, 0 ); fprintf( stderr, "===================================\n" ); fflush( stdout ); return; case TRACKMEM_QUIT: free( allblocks ); free( allsizes ); num_blocks = 0; total_size = 0; return; } if (verbose) { fprintf( stderr, " " ); trackmem( TRACKMEM_SHOW_STATS, NULL, NULL, 0 ); } } int trackmem_search_for_block( void *block, void **allblocks, int num_blocks ) { int i; for (i = 0; i < num_blocks; i++) if (block == allblocks[i]) return i; return -1; } /* Alternate interface-- use inside malloc()/realloc()/etc. wrappers */ void trackmem_malloc( void *block, size_t size ) { trackmem( TRACKMEM_MALLOC, block, NULL, size ); } void trackmem_realloc( void *block, void *block2, size_t size ) { trackmem( TRACKMEM_REALLOC, block, block2, size ); } void trackmem_strdup( char *string ) { trackmem( TRACKMEM_STRDUP, (void *)string, NULL, 0 ); } void trackmem_free( void *block ) { trackmem( TRACKMEM_FREE, block, NULL, 0 ); } /* end trackmem.h */ lightspeed-1.2a.debian.1/src/trackmem.h000066400000000000000000000040371334064775200200070ustar00rootroot00000000000000/* trackmem.h */ /* Memory allocation accounting utility */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include #include #include enum { TRACKMEM_MALLOC, TRACKMEM_MALLOC_EQUIV, TRACKMEM_REALLOC, TRACKMEM_STRDUP, TRACKMEM_FREE, TRACKMEM_SHOW_STATS, TRACKMEM_SHOW_BLOCKS, TRACKMEM_QUIT }; #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif /* Some systems don't support malloc() hooks */ #ifdef MALLOC_HOOKS static void *(*prev_malloc_hook)( size_t size ); static void *(*prev_realloc_hook)( void *block, size_t size ); static void (*prev_free_hook)( void *block ); static void *trackmem_malloc_hook( size_t size ); static void *trackmem_realloc_hook( void *block, size_t size ); static void trackmem_free_hook( void *block ); #endif void trackmem_init( void ); void trackmem_stop( void ); void trackmem_show_stats( void ); void trackmem_show_blocks( void ); void trackmem( int message, void *block, void *block2, size_t size ); int trackmem_search_for_block( void *block, void **allblocks, int num_blocks ); void trackmem_malloc( void *block, size_t size ); void trackmem_realloc( void *block, void *block2, size_t size ); void trackmem_strdup( char *string ); void trackmem_free( void *block ); /* end trackmem.h */ lightspeed-1.2a.debian.1/src/warp.c000066400000000000000000000453171334064775200171560ustar00rootroot00000000000000/* warp.c */ /* Relativistic distortion engine */ /* * ``The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * The Original Code is the "Light Speed!" relativistic simulator. * * The Initial Developer of the Original Code is Daniel Richard G. * Portions created by the Initial Developer are Copyright (C) 1999 * Daniel Richard G. All Rights Reserved. * * Contributor(s): ______________________________________.'' */ #include "lightspeed.h" /* Forward declarations */ static void doppler_shift( rgb_color *color, float freq_ratio ); static void doppler_shift_ref( rgb_color *color, float freq_ratio ); /* This is where it all happens! */ int warp( int message, void *data ) { static int do_lorentz_contraction = TRUE; static int do_optical_deformation = TRUE; static int do_headlight_effect = TRUE; static int do_doppler_shift = TRUE; static float percent_contraction = 1.0; static float percent_deformation = 1.0; static float percent_dopplershift = 1.0; static float percent_headlight = 1.0; #if USE_LOOKUP_TABLES static float sqrt01_lut[LUT_RES + 1]; static float normal_interp_lut1[LUT_RES + 1]; static float normal_interp_lut2[LUT_RES + 1]; #endif ogl_object *obj; ogl_point *pnt; point *cam_pos; point vertex; point normal; rgb_color color; rgb_color in_ray; double LC_gamma; double OD_v, OD_v2, OD_v2_min_C2; double DS_v_over_C, DS_gamma; double HE_v_over_C, HE_gamma; double d_vertex_x; double dx,dy,dz; double dyz2, dist2; double t; float cos_alpha_n, cos_alpha_c; float freq_ratio; float inten_ratio; float intensity; float len2, len; float k; int message2 = 0; int o, vn, i; if ((message != WARP_DISTORT) && (message != INITIALIZE)) message2 = *((int *)data); /* several methods use this value */ switch (message) { case WARP_DISTORT: cam_pos = (point *)data; break; case WARP_LORENTZ_CONTRACTION: do_lorentz_contraction = message2; if (do_lorentz_contraction) transition( &percent_contraction, FALSE, TRANS_SIGMOID, 4.0, 1.0, -1 ); else transition( &percent_contraction, FALSE, TRANS_SIGMOID, 4.0, 0.0, -1 ); return 0; case WARP_OPTICAL_DEFORMATION: do_optical_deformation = message2; if (do_optical_deformation) transition( &percent_deformation, FALSE, TRANS_SIGMOID, 4.0, 1.0, -1 ); else transition( &percent_deformation, FALSE, TRANS_SIGMOID, 4.0, 0.0, -1 ); return 0; case WARP_HEADLIGHT_EFFECT: do_headlight_effect = message2; if (do_headlight_effect) transition( &percent_headlight, FALSE, TRANS_SIGMOID, 4.0, 1.0, -1 ); else transition( &percent_headlight, FALSE, TRANS_SIGMOID, 4.0, 0.0, -1 ); return 0; case WARP_DOPPLER_SHIFT: do_doppler_shift = message2; if (do_doppler_shift) transition( &percent_dopplershift, FALSE, TRANS_SIGMOID, 4.0, 1.0, -1 ); else transition( &percent_dopplershift, FALSE, TRANS_SIGMOID, 4.0, 0.0, -1 ); return 0; case QUERY: switch (message2) { case WARP_LORENTZ_CONTRACTION: return do_lorentz_contraction; case WARP_OPTICAL_DEFORMATION: return do_optical_deformation; case WARP_HEADLIGHT_EFFECT: return do_headlight_effect; case WARP_DOPPLER_SHIFT: return do_doppler_shift; } return 0; case INITIALIZE: #if USE_LOOKUP_TABLES /* Initialize look-up tables */ for (i = 0; i <= LUT_RES; i++) { /* Normal interpolation factor tables * Table 1 handles [0, 1] input range */ normal_interp_lut1[i] = DEG(atan( (double)i / LUT_RES )) / 90.0; /* Table 2 handles (1, inf.) (via reciprocal) */ if (i > 0) normal_interp_lut2[i] = DEG(atan( LUT_RES / (double)i )) / 90.0; /* Square root table for [0, 1] range */ sqrt01_lut[i] = sqrt( (double)i / LUT_RES ); } normal_interp_lut2[0] = 1.0; #endif /* USE_LOOKUP_TABLES */ return 0; default: #ifdef DEBUG crash( "warp( ): invalid message" ); #endif return 0; } /* Variables for Lorentz contraction */ LC_gamma = lorentz_factor( velocity * percent_contraction ); /* Variables for optical deformation */ OD_v = MAX(1.0, velocity * percent_deformation); OD_v2 = SQR(OD_v); OD_v2_min_C2 = OD_v2 - C2; /* Simulation time (and x-location) depend on effective velocity * used for optical deformation */ warp_time( NIL, NIL, OD_v, WARP_UPDATE_TIME_T ); vehicle_real_x = OD_v * cur_time_t; /* Variables for Doppler shift */ DS_v_over_C = velocity * percent_dopplershift / C; DS_gamma = lorentz_factor( velocity * percent_dopplershift ); /* Variables for headlight effect */ HE_v_over_C = velocity * percent_headlight / C; HE_gamma = lorentz_factor( velocity * percent_headlight ); for (o = 0; o < num_vehicle_objs; o++) { obj = vehicle_objs[o]; /* "vn" is the counter instead of "v", to avoid * possible confusion with velocity variables */ for (vn = 0; vn < obj->num_vertices; vn++) { /* Load vertex location */ vertex.x = obj->vertices0[vn].x; vertex.y = obj->vertices0[vn].y; vertex.z = obj->vertices0[vn].z; /* Load vertex normal direction */ normal.x = obj->normals0[vn].x; normal.y = obj->normals0[vn].y; normal.z = obj->normals0[vn].z; /* (Re)load base RGB color */ color.r = obj->color0.r; color.g = obj->color0.g; color.b = obj->color0.b; /**** RELATIVISTIC GEOMETRY TRANSFORMS ****/ /* Do x-coordinate work in double precision */ d_vertex_x = vertex.x; /** Lorentz contraction **/ d_vertex_x /= LC_gamma; /* Adjust normal accordingly */ dx = normal.x; dy = normal.y / LC_gamma; dz = normal.z / LC_gamma; /* Renormalize the normal */ len2 = SQR(dx) + SQR(dy) + SQR(dz); #if USE_LOOKUP_TABLES #ifdef DEBUG if (len2 > 1.001) { printf( "ERROR: warp( ): normal length > 1.0 !!!\n" ); fflush( stdout ); len2 = 1.0; } #endif /* DEBUG */ len = sqrt01_lut[(int)(len2 * LUT_RES)]; #else len = sqrt( len2 ); #endif /* not USE_LOOKUP_TABLES */ if (len < 1E-6) len = 1.0; normal.x = dx / len; normal.y = dy / len; normal.z = dz / len; /* Move object to its "real" x-position */ d_vertex_x += vehicle_real_x; /** Optical deformation **/ /* Obtain xyz deltas (camera to vertex) */ dx = d_vertex_x - cam_pos->x; dy = vertex.y - cam_pos->y; dz = vertex.z - cam_pos->z; /* square, add */ dyz2 = SQR(dy) + SQR(dz); /* lump y & z together */ dist2 = SQR(dx) + dyz2; /* Calculate t and adjust vertex accordingly */ t = (dx*OD_v - sqrt( C2*dist2 - dyz2*OD_v2 )) / OD_v2_min_C2; d_vertex_x -= OD_v * t; /* done with double-precision math */ vertex.x = d_vertex_x; /* Note: dx and dist2 do NOT get updated! * alpha_c below is calculated w.r.t. the * vertex's "actual" position */ /* Need two angles for the color transforms: * alpha_n = angle between direction of * travel and vertex normal; * alpha_c = angle between direction of * travel and vertex-to-camera vector */ cos_alpha_n = normal.x; if (dist2 > 1E-6) cos_alpha_c = - dx / sqrt( dist2 ); else cos_alpha_c = 0.0; /**** RELATIVISTIC COLOR/INTENSITY TRANSFORMS ****/ /* Incoming light ray */ /* in_ray.r = 1.0; */ /* in_ray.g = 1.0; */ /* in_ray.b = 1.0; */ /** Doppler frequency shift (incoming light) **/ k = 1.0 + (HE_v_over_C * cos_alpha_n); inten_ratio = SQR(k) * HE_gamma; /* in_ray.r *= inten_ratio; */ /* in_ray.g *= inten_ratio; */ /* in_ray.b *= inten_ratio; */ in_ray.r = inten_ratio; in_ray.g = inten_ratio; in_ray.b = inten_ratio; /** Headlight effect (incoming light) **/ freq_ratio = (1.0 + (DS_v_over_C * cos_alpha_n)) * DS_gamma; doppler_shift( &in_ray, freq_ratio ); /* Illuminative color interaction */ color.r *= SQR(in_ray.r); color.g *= SQR(in_ray.g); color.b *= SQR(in_ray.b); /** Doppler frequency shift (outgoing light) **/ freq_ratio = (1.0 + (DS_v_over_C * cos_alpha_c)) * DS_gamma; doppler_shift_ref( &color, freq_ratio ); /** Headlight effect (outgoing light) **/ k = 1.0 + (HE_v_over_C * cos_alpha_c); inten_ratio = SQR(k) * HE_gamma; color.r *= inten_ratio; color.g *= inten_ratio; color.b *= inten_ratio; /* If intensity exceeds I(1,1,1), * rotate normal toward camera */ intensity = (color.r * RED_STRENGTH) + (color.g * GREEN_STRENGTH) + (color.b * BLUE_STRENGTH); if (intensity > 1.0) { /* Normal interpolation factor, range [0, 1) * 0 == unchanged, 1 == pointing toward camera */ #if USE_LOOKUP_TABLES if (intensity <= 2.0) { i = (int)((intensity - 1.0) * LUT_RES); k = normal_interp_lut1[i]; } else { i = (int)(LUT_RES / (intensity - 1.0)); k = normal_interp_lut2[i]; } #else k = DEG(atan( intensity - 1.0 )) / 90.0; #endif /* not USE_LOOKUP_TABLES */ /* Interpolate between normal vector and * vertex-to-camera vector */ normal.x -= k * (dx + normal.x); normal.y -= k * (dy + normal.y); normal.z -= k * (dz + normal.z); /* Renormalize */ len = sqrt( SQR(normal.x) + SQR(normal.y) + SQR(normal.z) ); if (len < 1E-6) len = 1.0; normal.x /= len; normal.y /= len; normal.z /= len; } /* Done with relativistic transforms */ /* Clamp color components to legal range */ color.r = MIN(1.0, color.r); color.g = MIN(1.0, color.g); color.b = MIN(1.0, color.b); /* Lastly, perform display gamma correction if needed */ if (dgamma_correct) { color.r = dgamma_lut[(int)(color.r * LUT_RES)]; color.g = dgamma_lut[(int)(color.g * LUT_RES)]; color.b = dgamma_lut[(int)(color.b * LUT_RES)]; } pnt = &obj->iarrays[vn]; /* Store processed vertex location */ pnt->x = vertex.x; pnt->y = vertex.y; pnt->z = vertex.z; /* Store processed vertex normal */ pnt->nx = normal.x; pnt->ny = normal.y; pnt->nz = normal.z; /* Store processed vertex color */ pnt->r = color.r; pnt->g = color.g; pnt->b = color.b; } } return 0; } /* This performs the relativistic geometrical transform, but for a single point, * with the camera at the specified location */ void warp_point( point *vertex, point *normal, point *cam_pos ) { double gamma; double d_vertex_x; double dx,dy,dz; double len; double dyz2, dist2; double v, v2, t; gamma = lorentz_factor( velocity ); /* Perform calculations in double precision */ d_vertex_x = vertex->x; /** Lorentz contraction **/ d_vertex_x /= gamma; /* Adjust normal, if we have a normal to adjust */ if (normal != NULL) { dx = normal->x; dy = normal->y / gamma; dz = normal->z / gamma; /* Renormalize */ len = sqrt( SQR(dx) + SQR(dy) + SQR(dz) ); if (len < 1E-6) len = 1.0; normal->x = dx / len; normal->y = dy / len; normal->z = dz / len; } /* Move object to its "real" x-position */ d_vertex_x += velocity * cur_time_t; dx = d_vertex_x - cam_pos->x; dy = vertex->y - cam_pos->y; dz = vertex->z - cam_pos->z; dyz2 = SQR(dy) + SQR(dz); dist2 = SQR(dx) + SQR(dy) + SQR(dz); v = velocity; v2 = SQR(velocity); /* Calculate t and adjust vertex accordingly */ t = (dx*v - sqrt( C2*dist2 - dyz2*v2 )) / (v2 - C2); d_vertex_x -= velocity * t; vertex->x = d_vertex_x; } /* Doppler frequency shift color transform * My deepest appreciation to Antony Searle for letting me use his code :-) */ static void doppler_shift( rgb_color *color, float freq_ratio ) { float r0,g0,b0; float k; r0 = color->r; g0 = color->g; b0 = color->b; /* Convert frequency ratio into wavelength ratio */ k = 1.0 / freq_ratio; /* Calculate red component */ if (LAMBDA_RED < (k * LAMBDA_UV)) color->r = LAMBDA_RED * ((0.5 * b0) + (0.25 * g0) + (0.125 * r0))/ (k * LAMBDA_UV); else if (LAMBDA_RED < (k * LAMBDA_BLUE)) color->r = ((0.5 * b0) + (0.25 * g0) + (0.125 * r0)) + ((LAMBDA_RED - (k * LAMBDA_UV)) / ((k * LAMBDA_BLUE) - (k * LAMBDA_UV))) * ((0.5 * b0) - (0.25 * g0) - (0.125 * r0)); else if (LAMBDA_RED < (k * LAMBDA_GREEN)) color->r = b0 + ((LAMBDA_RED - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_RED < (k * LAMBDA_RED)) color->r = g0 + ((LAMBDA_RED - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else if (LAMBDA_RED < (k * LAMBDA_IR)) color->r = r0 + ((LAMBDA_RED - (k * LAMBDA_RED)) / ((k * LAMBDA_IR) - (k * LAMBDA_RED))) * ((0.125 * b0) + (0.25 * g0) - (0.5 * r0)); else color->r = ((0.125 * b0) + (0.25 * g0) + (0.5 * r0)) * ((k * LAMBDA_IR) / LAMBDA_RED); /* Calculate green component */ if (LAMBDA_GREEN < (k * LAMBDA_UV)) color->g = LAMBDA_GREEN * ((0.5 * b0) + (0.25 * g0) + (0.125 * r0))/ (k * LAMBDA_UV); else if (LAMBDA_GREEN < (k * LAMBDA_BLUE)) color->g = ((0.5 * b0) + (0.25 * g0) + (0.125 * r0)) + ((LAMBDA_GREEN - (k * LAMBDA_UV)) / ((k * LAMBDA_BLUE) - (k * LAMBDA_UV))) * ((0.5 * b0) - (0.25 * g0) - (0.125 * r0)); else if (LAMBDA_GREEN < (k * LAMBDA_GREEN)) color->g = b0 + ((LAMBDA_GREEN - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_GREEN < (k * LAMBDA_RED)) color->g = g0 + ((LAMBDA_GREEN - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else if (LAMBDA_GREEN < (k * LAMBDA_IR)) color->g = r0 + ((LAMBDA_GREEN - (k * LAMBDA_RED)) / ((k * LAMBDA_IR) - (k * LAMBDA_RED))) * ((0.125 * b0) + (0.25 * g0) - (0.5 * r0)); else color->g = ((0.125 * b0) + (0.25 * g0) + (0.5 * r0)) * ((k * LAMBDA_IR) / LAMBDA_GREEN); /* Calculate blue component */ if (LAMBDA_BLUE < (k * LAMBDA_UV)) color->b = LAMBDA_BLUE * ((0.5 * b0) + (0.25 * g0) + (0.125 * r0))/ (k * LAMBDA_UV); else if (LAMBDA_BLUE < (k * LAMBDA_BLUE)) color->b = ((0.5 * b0) + (0.25 * g0) + (0.125 * r0)) + ((LAMBDA_BLUE - (k * LAMBDA_UV)) / ((k * LAMBDA_BLUE) - (k * LAMBDA_UV))) * ((0.5 * b0) - (0.25 * g0) - (0.125 * r0)); else if (LAMBDA_BLUE < (k * LAMBDA_GREEN)) color->b = b0 + ((LAMBDA_BLUE - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_BLUE < (k * LAMBDA_RED)) color->b = g0 + ((LAMBDA_BLUE - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else if (LAMBDA_BLUE < (k * LAMBDA_IR)) color->b = r0 + ((LAMBDA_BLUE - (k * LAMBDA_RED)) / ((k * LAMBDA_IR) - (k * LAMBDA_RED))) * ((0.125 * b0) + (0.25 * g0) - (0.5 * r0)); else color->b = ((0.125 * b0) + (0.25 * g0) + (0.5 * r0)) * ((k * LAMBDA_IR) / LAMBDA_BLUE); } /* Doppler frequency shift, for reflected light rays * Again, this is straight from BACKLIGHT */ static void doppler_shift_ref( rgb_color *color, float freq_ratio ) { float r0,g0,b0; float k; r0 = color->r; g0 = color->g; b0 = color->b; /* Convert frequency ratio into wavelength ratio */ k = 1.0 / freq_ratio; /* Calculate red component */ if (LAMBDA_RED < (k * LAMBDA_BLUE)) color->r = b0; else if (LAMBDA_RED < (k * LAMBDA_GREEN)) color->r = b0 + ((LAMBDA_RED - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_RED < (k * LAMBDA_RED)) color->r = g0 + ((LAMBDA_RED - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else color->r = r0; /* Calculate green component */ if (LAMBDA_GREEN < (k * LAMBDA_BLUE)) color->g = b0; else if (LAMBDA_GREEN < (k * LAMBDA_GREEN)) color->g = b0 + ((LAMBDA_GREEN - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_GREEN < (k * LAMBDA_RED)) color->g = g0 + ((LAMBDA_GREEN - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else color->g = r0; /* Calculate blue component */ if (LAMBDA_BLUE < (k * LAMBDA_BLUE)) color->b = b0; else if (LAMBDA_BLUE < (k * LAMBDA_GREEN)) color->b = b0 + ((LAMBDA_BLUE - (k * LAMBDA_BLUE)) / ((k * LAMBDA_GREEN) - (k * LAMBDA_BLUE))) * (- b0 + g0); else if (LAMBDA_BLUE < (k * LAMBDA_RED)) color->b = g0 + ((LAMBDA_BLUE - (k * LAMBDA_GREEN)) / ((k * LAMBDA_RED) - (k * LAMBDA_GREEN))) * (- g0 + r0); else color->b = r0; } /* This next function takes care of determining simulation time (cur_time_t). * If the vehicle is not being animated, warp_time( ) sets time t to keep the * image centered on the origin. If animation is active, time t is returned as * a percent between starting times t0 and t1, the times when the image appears * at the starting and ending x-positions x0 and x1, respectively (note that * while x0 and x1 stay constant, t0 and t1 will vary with camera position) */ void warp_time( float x0, float x1, double value, int message ) { static float anim_x0 = 0.0; static float anim_x1 = 0.0; static float anim_percent = 0.0; camera *cam; double dx,dy,dz; double anim_t0; double anim_t1; double v, t; float loop_time = 0.0; /* Preliminary */ if (message == WARP_BEGIN_ANIM) { anim_x0 = x0; anim_x1 = x1; /* Make SURE these two are not still in transition queue * (i.e. if user hits Begin suddenly after Stop) */ break_transition( &anim_x0 ); break_transition( &anim_x1 ); loop_time = value; v = velocity; } else v = value; /* effective velocity for calculations */ /* BUG (sort of): Actual velocity (not effective velocity) is used when * beginning an animation. This means that if the user begins an animation * while optical deformation is disabled, the object will leap back a small * distance before moving forward */ /* Everything is done w.r.t. the primary camera */ cam = usr_cams[0]; /* Recalculate starting time t (image at x=x0) */ dx = cam->pos.x - anim_x0; dy = cam->pos.y; dz = cam->pos.z; t = anim_x0 / v; anim_t0 = t + sqrt( SQR(dx) + SQR(dy) + SQR(dz) ) / C; /* Recalculate ending time t (image at x=x1) */ dx = cam->pos.x - anim_x1; t = anim_x1 / v; anim_t1 = t + sqrt( SQR(dx) + SQR(dy) + SQR(dz) ) / C; switch (message) { case WARP_UPDATE_TIME_T: break; case WARP_BEGIN_ANIM: /* Set anim_percent so object doesn't initially JUMP to x0 */ anim_percent = (cur_time_t - anim_t0) / (anim_t1 - anim_t0); animate( &anim_percent, FALSE, TRANS_LINEAR, loop_time, 0.0, 1.0, -1 ); return; case WARP_STOP_ANIM: /* Move image back to origin */ transition( &anim_x0, FALSE, TRANS_SIGMOID, 2.0, 0.0, -1 ); transition( &anim_x1, FALSE, TRANS_SIGMOID, 2.0, 0.0, -1 ); /* Get anim_percent out of the transition queue */ transition( &anim_percent, FALSE, TRANS_LINEAR, 0.0, anim_percent, -1 ); return; default: #ifdef DEBUG crash( "warp_time( ): invalid message" ); #endif return; } /* Update current time t */ cur_time_t = anim_t0 + anim_percent * (anim_t1 - anim_t0); } /* The Lorentz factor, a.k.a. the gamma factor * Dependent on velocity, with range [1, infinity) */ double lorentz_factor( double v ) { return 1 / sqrt( 1 - SQR(v) / C2 ); } /* end warp.c */ lightspeed-1.2a.debian.1/stamp-h.in000066400000000000000000000000001334064775200171270ustar00rootroot00000000000000