Index: ext/libicpf/AUTHORS =================================================================== diff -u -N --- ext/libicpf/AUTHORS (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/AUTHORS (revision 0) @@ -1 +0,0 @@ -Józef Starosczyk Index: ext/libicpf/COPYING =================================================================== diff -u -N --- ext/libicpf/COPYING (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/COPYING (revision 0) @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 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. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, 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 or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -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 give any other recipients of the Program a copy of this License -along with the Program. - -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 Program or any portion -of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -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 Program, 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 Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) 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; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, 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 executable. However, as a -special exception, the source code 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. - -If distribution of executable or 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 counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program 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. - - 5. 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 Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program 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 to -this License. - - 7. 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 Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program 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 Program. - -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. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program 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. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 Program -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 Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, 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 - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), 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 Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. 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 program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. Index: ext/libicpf/COPYING.LIB =================================================================== diff -u -N --- ext/libicpf/COPYING.LIB (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/COPYING.LIB (revision 0) @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 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 library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - 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 Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, 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 or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the 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 a program 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. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - 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, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -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 compile 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) 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. - - c) 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. - - d) 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 source code 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 to -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 Library 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! Index: ext/libicpf/ChangeLog =================================================================== diff -u -N --- ext/libicpf/ChangeLog (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/ChangeLog (revision 0) @@ -1 +0,0 @@ \ No newline at end of file Index: ext/libicpf/Doxyfile =================================================================== diff -u -N --- ext/libicpf/Doxyfile (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/Doxyfile (revision 0) @@ -1,275 +0,0 @@ -# Doxyfile 1.4.1-KDevelop - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = libicpf -PROJECT_NUMBER = 0.1 -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -USE_WINDOWS_ENCODING = NO -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = YES -STRIP_FROM_PATH = /home/ixen/ -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = YES -INHERIT_DOCS = YES -DISTRIBUTE_GROUP_DOC = NO -TAB_SIZE = 8 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -EXTRACT_PRIVATE = NO -EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = YES -FILE_VERSION_FILTER = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = src -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.idl \ - *.odl \ - *.cs \ - *.php \ - *.php3 \ - *.inc \ - *.m \ - *.mm \ - *.C \ - *.CC \ - *.C++ \ - *.II \ - *.I++ \ - *.H \ - *.HH \ - *.H++ \ - *.CS \ - *.PHP \ - *.PHP3 \ - *.M \ - *.MM \ - *.C \ - *.H \ - *.tlh \ - *.diff \ - *.patch \ - *.moc \ - *.xpm \ - *.dox -RECURSIVE = YES -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = YES -REFERENCES_RELATION = YES -VERBATIM_HEADERS = YES -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = NO -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = NO -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = libicpf.tag -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -TEMPLATE_RELATIONS = YES -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = /usr/bin -DOTFILE_DIRS = /usr/share/graphviz/graphs/directed/ \ - /usr/share/graphviz/graphs/undirected/ -MAX_DOT_GRAPH_WIDTH = 1024 -MAX_DOT_GRAPH_HEIGHT = 1024 -MAX_DOT_GRAPH_DEPTH = 1000 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = NO Index: ext/libicpf/INSTALL =================================================================== diff -u -N --- ext/libicpf/INSTALL (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/INSTALL (revision 0) @@ -1,167 +0,0 @@ -Basic Installation -================== - - These are generic installation instructions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. - - The file `configure.in' is used to create `configure' by a program -called `autoconf'. You only need `configure.in' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. - -The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. - - Running `configure' takes a while. While running, it prints some - messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Type `make install' to install the programs and any data files and - documentation. - - 4. You can remove the program binaries and object files from the - source code directory by typing `make clean'. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure - -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. - - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. - -Installation Names -================== - - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - -Optional Features -================= - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - -Specifying the System Type -========================== - - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: - CPU-COMPANY-SYSTEM - -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. - - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Operation Controls -================== - - `configure' recognizes the following options to control how it -operates. - -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - -`--help' - Print a summary of the options to `configure', and exit. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`configure' also accepts some other, not widely useful, options. - Index: ext/libicpf/Makefile.am =================================================================== diff -u -N --- ext/libicpf/Makefile.am (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/Makefile.am (revision 0) @@ -1,5 +0,0 @@ -# not a GNU package. You can remove this line, if -# have all needed files, that a GNU package needs -AUTOMAKE_OPTIONS = foreign 1.4 - -SUBDIRS = src Index: ext/libicpf/Makefile.cvs =================================================================== diff -u -N --- ext/libicpf/Makefile.cvs (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/Makefile.cvs (revision 0) @@ -1,8 +0,0 @@ -default: all - -all: - aclocal - autoheader - automake - autoconf - Index: ext/libicpf/NEWS =================================================================== diff -u -N --- ext/libicpf/NEWS (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/NEWS (revision 0) @@ -1 +0,0 @@ - \ No newline at end of file Index: ext/libicpf/README =================================================================== diff -u -N --- ext/libicpf/README (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/README (revision 0) @@ -1 +0,0 @@ - Index: ext/libicpf/TODO =================================================================== diff -u -N --- ext/libicpf/TODO (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/TODO (revision 0) @@ -1 +0,0 @@ \ No newline at end of file Index: ext/libicpf/config.guess =================================================================== diff -u -N --- ext/libicpf/config.guess (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/config.guess (revision 0) @@ -1,1363 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002 Free Software Foundation, Inc. - -timestamp='2002-10-21' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; - --version | -v ) - echo "$version" ; exit 0 ;; - --help | --h* | -h ) - echo "$usage"; exit 0 ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# This shell variable is my proudest work .. or something. --bje - -set_cc_for_build='tmpdir=${TMPDIR-/tmp}/config-guess-$$ ; -(old=`umask` && umask 077 && mkdir $tmpdir && umask $old && unset old) - || (echo "$me: cannot create $tmpdir" >&2 && exit 1) ; -dummy=$tmpdir/dummy ; -files="$dummy.c $dummy.o $dummy.rel $dummy" ; -trap '"'"'rm -f $files; rmdir $tmpdir; exit 1'"'"' 1 2 15 ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - rm -f $files ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; -unset files' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit 0 ;; - amiga:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - arc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - hp300:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mac68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - macppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme68k:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvme88k:OpenBSD:*:*) - echo m88k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - mvmeppc:OpenBSD:*:*) - echo powerpc-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - pmax:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sgi:OpenBSD:*:*) - echo mipseb-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - sun3:OpenBSD:*:*) - echo m68k-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - wgrisc:OpenBSD:*:*) - echo mipsel-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - *:OpenBSD:*:*) - echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} - exit 0 ;; - alpha:OSF1:*:*) - if test $UNAME_RELEASE = "V4.0"; then - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - fi - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - eval $set_cc_for_build - cat <$dummy.s - .data -\$Lformat: - .byte 37,100,45,37,120,10,0 # "%d-%x\n" - - .text - .globl main - .align 4 - .ent main -main: - .frame \$30,16,\$26,0 - ldgp \$29,0(\$27) - .prologue 1 - .long 0x47e03d80 # implver \$0 - lda \$2,-1 - .long 0x47e20c21 # amask \$2,\$1 - lda \$16,\$Lformat - mov \$0,\$17 - not \$1,\$18 - jsr \$26,printf - ldgp \$29,0(\$26) - mov 0,\$16 - jsr \$26,exit - .end main -EOF - $CC_FOR_BUILD -o $dummy $dummy.s 2>/dev/null - if test "$?" = 0 ; then - case `$dummy` in - 0-0) - UNAME_MACHINE="alpha" - ;; - 1-0) - UNAME_MACHINE="alphaev5" - ;; - 1-1) - UNAME_MACHINE="alphaev56" - ;; - 1-101) - UNAME_MACHINE="alphapca56" - ;; - 2-303) - UNAME_MACHINE="alphaev6" - ;; - 2-307) - UNAME_MACHINE="alphaev67" - ;; - 2-1307) - UNAME_MACHINE="alphaev68" - ;; - 3-1307) - UNAME_MACHINE="alphaev7" - ;; - esac - fi - rm -f $dummy.s $dummy && rmdir $tmpdir - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit 0 ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit 0 ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit 0 ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit 0;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit 0 ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit 0 ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit 0 ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit 0;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit 0;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit 0 ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit 0 ;; - DRS?6000:UNIX_SV:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7 && exit 0 ;; - esac ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - i86pc:SunOS:5.*:*) - echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit 0 ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit 0 ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit 0 ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit 0 ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit 0 ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit 0 ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit 0 ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit 0 ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit 0 ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit 0 ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit 0 ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit 0 ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit 0 ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c \ - && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ - && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 - rm -f $dummy.c $dummy && rmdir $tmpdir - echo mips-mips-riscos${UNAME_RELEASE} - exit 0 ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit 0 ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit 0 ;; - Night_Hawk:*:*:PowerMAX_OS) - echo powerpc-harris-powermax - exit 0 ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit 0 ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit 0 ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit 0 ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit 0 ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit 0 ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit 0 ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit 0 ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit 0 ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit 0 ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit 0 ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit 0 ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit 0 ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 - rm -f $dummy.c $dummy && rmdir $tmpdir - echo rs6000-ibm-aix3.2.5 - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit 0 ;; - *:AIX:*:[45]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit 0 ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit 0 ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit 0 ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit 0 ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit 0 ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit 0 ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit 0 ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit 0 ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi - rm -f $dummy.c $dummy && rmdir $tmpdir - fi ;; - esac - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit 0 ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit 0 ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 - rm -f $dummy.c $dummy && rmdir $tmpdir - echo unknown-hitachi-hiuxwe2 - exit 0 ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit 0 ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit 0 ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit 0 ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit 0 ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit 0 ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit 0 ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit 0 ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit 0 ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit 0 ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit 0 ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit 0 ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit 0 ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit 0 ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; - CRAY*T3D:*:*:*) - echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit 0 ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit 0 ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit 0 ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit 0 ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit 0 ;; - *:FreeBSD:*:*) - # Determine whether the default compiler uses glibc. - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #if __GLIBC__ >= 2 - LIBC=gnu - #else - LIBC= - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - rm -f $dummy.c && rmdir $tmpdir - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} - exit 0 ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit 0 ;; - i*:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit 0 ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit 0 ;; - x86:Interix*:3*) - echo i386-pc-interix3 - exit 0 ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i386-pc-interix - exit 0 ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit 0 ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit 0 ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit 0 ;; - *:GNU:*:*) - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit 0 ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit 0 ;; - arm*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - rm -f $dummy.c && rmdir $tmpdir - test x"${CPU}" != x && echo "${CPU}-pc-linux-gnu" && exit 0 - ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit 0 ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit 0 ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit 0 ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit 0 ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit 0 ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit 0 ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit 0 ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit 0 ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit 0 ;; - coff-i386) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit 0 ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit 0 ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #ifdef __INTEL_COMPILER - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - rm -f $dummy.c && rmdir $tmpdir - test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 - test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit 0 ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit 0 ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit 0 ;; - i*86:*:5:[78]*) - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit 0 ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit 0 ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit 0 ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i386. - echo i386-pc-msdosdjgpp - exit 0 ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit 0 ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit 0 ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit 0 ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit 0 ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit 0 ;; - M68*:*:R3V[567]*:*) - test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; - 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4.3${OS_REL} && exit 0 - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && echo i486-ncr-sysv4 && exit 0 ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit 0 ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit 0 ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit 0 ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit 0 ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit 0 ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit 0 ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit 0 ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit 0 ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit 0 ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit 0 ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit 0 ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit 0 ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit 0 ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit 0 ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit 0 ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit 0 ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit 0 ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit 0 ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit 0 ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; - *:Darwin:*:*) - echo `uname -p`-apple-darwin${UNAME_RELEASE} - exit 0 ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit 0 ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit 0 ;; - NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit 0 ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit 0 ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit 0 ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit 0 ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit 0 ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit 0 ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit 0 ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit 0 ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit 0 ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit 0 ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit 0 ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit 0 ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit 0 ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit 0 ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 -rm -f $dummy.c $dummy && rmdir $tmpdir - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit 0 ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit 0 ;; - c34*) - echo c34-convex-bsd - exit 0 ;; - c38*) - echo c38-convex-bsd - exit 0 ;; - c4*) - echo c4-convex-bsd - exit 0 ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: Index: ext/libicpf/config.sub =================================================================== diff -u -N --- ext/libicpf/config.sub (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/config.sub (revision 0) @@ -1,1470 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002 Free Software Foundation, Inc. - -timestamp='2002-09-05' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit 0 ;; - --version | -v ) - echo "$version" ; exit 0 ;; - --help | --h* | -h ) - echo "$usage"; exit 0 ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit 0;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | freebsd*-gnu* | storm-chaos* | os2-emx* | windows32-* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ - | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k \ - | m32r | m68000 | m68k | m88k | mcore \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64vr | mips64vrel \ - | mips64orion | mips64orionel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mipsisa32 | mipsisa32el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | ns16k | ns32k \ - | openrisc | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | sh | sh[1234] | sh3e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ - | strongarm \ - | tahoe | thumb | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xscale | xstormy16 | xtensa \ - | z8k) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* \ - | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* \ - | clipper-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* \ - | m32r-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | mcore-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39 | mipstx39el \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh3e-* | sh[34]eb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* | tic30-* | tic4x-* | tic54x-* | tic80-* | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ - | xtensa-* \ - | ymp-* \ - | z8k-*) - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - crds | unos) - basic_machine=m68k-crds - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - mmix*) - basic_machine=mmix-knuth - os=-mmixware - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - or32 | or32-*) - basic_machine=or32-unknown - os=-coff - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2) - basic_machine=i686-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3d) - basic_machine=alpha-cray - os=-unicos - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic4x | c4x*) - basic_machine=tic4x-unknown - os=-coff - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - windows32) - basic_machine=i386-pc - os=-windows32-msvcrt - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh3 | sh4 | sh3eb | sh4eb | sh[1234]le | sh3ele) - basic_machine=sh-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparc | sparcv9 | sparcv9b) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ - | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* | -powermax*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto*) - os=-nto-qnx - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-ibm) - os=-aix - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit 0 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: Index: ext/libicpf/configure.ac =================================================================== diff -u -N --- ext/libicpf/configure.ac (revision fd1f0cf4d6ad9ff63fd9252a3f2f31c992431842) +++ ext/libicpf/configure.ac (revision 0) @@ -1,46 +0,0 @@ -AC_INIT(libicpf, 0.1alpha, ixen2@o2.pl) -AC_CONFIG_SRCDIR([config.h.in]) -AC_CONFIG_HEADER([config.h]) -AM_INIT_AUTOMAKE(libicpf, 2.0alpha) - -# Programs -AC_PROG_CXX -AC_PROG_CC -AC_PROG_CPP -AC_PROG_AWK -AC_PROG_INSTALL -AC_PROG_LN_S -AC_PROG_MAKE_SET -AC_PROG_RANLIB -AC_PROG_LIBTOOL - -# libraries -AC_CHECK_LIB([dl], [dlopen]) -AC_CHECK_LIB([pthread], [pthread_mutex_init]) - -# header files -AC_HEADER_DIRENT -AC_HEADER_STDC -AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h utime.h wchar.h pthread.h]) - -# typedefs, structs, ... -AC_HEADER_STDBOOL -AC_C_CONST -AC_TYPE_UID_T -AC_C_INLINE -AC_TYPE_OFF_T -AC_TYPE_SIZE_T - -# library functions -AC_FUNC_CHOWN -AC_FUNC_CLOSEDIR_VOID -AC_FUNC_LSTAT -AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK -AC_FUNC_UTIME_NULL -AC_FUNC_VPRINTF -AC_CHECK_FUNCS([ftruncate memmove memset strchr strtoul utime]) - -AC_CONFIG_FILES([Makefile - src/Makefile]) - -AC_OUTPUT Index: ext/libicpf/depcomp =================================================================== diff -u -N --- ext/libicpf/depcomp (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/depcomp (revision 0) @@ -1,441 +0,0 @@ -#! /bin/sh - -# depcomp - compile a program generating dependencies as side-effects -# Copyright 1999, 2000 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 to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# Originally written by Alexandre Oliva . - -if test -z "$depmode" || test -z "$source" || test -z "$object"; then - echo "depcomp: Variables source, object and depmode must be set" 1>&2 - exit 1 -fi -# `libtool' can also be set to `yes' or `no'. - -depfile=${depfile-`echo "$object" | sed 's,\([^/]*\)$,.deps/\1,;s/\.\([^.]*\)$/.P\1/'`} -tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} - -rm -f "$tmpdepfile" - -# Some modes work just like other modes, but use different flags. We -# parameterize here, but still list the modes in the big case below, -# to make depend.m4 easier to write. Note that we *cannot* use a case -# here, because this file can only contain one case statement. -if test "$depmode" = hp; then - # HP compiler uses -M and no extra arg. - gccflag=-M - depmode=gcc -fi - -if test "$depmode" = dashXmstdout; then - # This is just like dashmstdout with a different argument. - dashmflag=-xM - depmode=dashmstdout -fi - -case "$depmode" in -gcc3) -## gcc 3 implements dependency tracking that does exactly what -## we want. Yay! Note: for some reason libtool 1.4 doesn't like -## it if -MD -MP comes after the -MF stuff. Hmm. - "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile" - exit $stat - fi - mv "$tmpdepfile" "$depfile" - ;; - -gcc) -## There are various ways to get dependency output from gcc. Here's -## why we pick this rather obscure method: -## - Don't want to use -MD because we'd like the dependencies to end -## up in a subdir. Having to rename by hand is ugly. -## (We might end up doing this anyway to support other compilers.) -## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like -## -MM, not -M (despite what the docs say). -## - Using -M directly means running the compiler twice (even worse -## than renaming). - if test -z "$gccflag"; then - gccflag=-MD, - fi - "$@" -Wp,"$gccflag$tmpdepfile" - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile" - exit $stat - fi - rm -f "$depfile" - echo "$object : \\" > "$depfile" - alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -## The second -e expression handles DOS-style file names with drive letters. - sed -e 's/^[^:]*: / /' \ - -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" -## This next piece of magic avoids the `deleted header file' problem. -## The problem is that when a header file which appears in a .P file -## is deleted, the dependency causes make to die (because there is -## typically no way to rebuild the header). We avoid this by adding -## dummy dependencies for each header file. Too bad gcc doesn't do -## this for us directly. - tr ' ' ' -' < "$tmpdepfile" | -## Some versions of gcc put a space before the `:'. On the theory -## that the space means something, we add a space to the output as -## well. -## Some versions of the HPUX 10.20 sed can't process this invocation -## correctly. Breaking it into two sed invocations is a workaround. - sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" - rm -f "$tmpdepfile" - ;; - -hp) - # This case exists only to let depend.m4 do its work. It works by - # looking at the text of this script. This case will never be run, - # since it is checked for above. - exit 1 - ;; - -sgi) - if test "$libtool" = yes; then - "$@" "-Wp,-MDupdate,$tmpdepfile" - else - "$@" -MDupdate "$tmpdepfile" - fi - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile" - exit $stat - fi - rm -f "$depfile" - - if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files - echo "$object : \\" > "$depfile" - - # Clip off the initial element (the dependent). Don't try to be - # clever and replace this with sed code, as IRIX sed won't handle - # lines with more than a fixed number of characters (4096 in - # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; - # the IRIX cc adds comments like `#:fec' to the end of the - # dependency line. - tr ' ' ' -' < "$tmpdepfile" \ - | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ - tr ' -' ' ' >> $depfile - echo >> $depfile - - # The second pass generates a dummy entry for each header file. - tr ' ' ' -' < "$tmpdepfile" \ - | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ - >> $depfile - else - # The sourcefile does not contain any dependencies, so just - # store a dummy comment line, to avoid errors with the Makefile - # "include basename.Plo" scheme. - echo "#dummy" > "$depfile" - fi - rm -f "$tmpdepfile" - ;; - -aix) - # The C for AIX Compiler uses -M and outputs the dependencies - # in a .u file. This file always lives in the current directory. - # Also, the AIX compiler puts `$object:' at the start of each line; - # $object doesn't have directory information. - stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` - tmpdepfile="$stripped.u" - outname="$stripped.o" - if test "$libtool" = yes; then - "$@" -Wc,-M - else - "$@" -M - fi - - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile" - exit $stat - fi - - if test -f "$tmpdepfile"; then - # Each line is of the form `foo.o: dependent.h'. - # Do two passes, one to just change these to - # `$object: dependent.h' and one to simply `dependent.h:'. - sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" - sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" - else - # The sourcefile does not contain any dependencies, so just - # store a dummy comment line, to avoid errors with the Makefile - # "include basename.Plo" scheme. - echo "#dummy" > "$depfile" - fi - rm -f "$tmpdepfile" - ;; - -icc) - # Must come before tru64. - - # Intel's C compiler understands `-MD -MF file'. However - # icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c - # will fill foo.d with something like - # foo.o: sub/foo.c - # foo.o: sub/foo.h - # which is wrong. We want: - # sub/foo.o: sub/foo.c - # sub/foo.o: sub/foo.h - # sub/foo.c: - # sub/foo.h: - - "$@" -MD -MF "$tmpdepfile" - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile" - exit $stat - fi - rm -f "$depfile" - # Each line is of the form `foo.o: dependent.h'. - # Do two passes, one to just change these to - # `$object: dependent.h' and one to simply `dependent.h:'. - sed -e "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" - sed -e "s,^[^:]*: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" - rm -f "$tmpdepfile" - ;; - -tru64) - # The Tru64 AIX compiler uses -MD to generate dependencies as a side - # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. - # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put - # dependencies in `foo.d' instead, so we check for that too. - # Subdirectories are respected. - - tmpdepfile1="$object.d" - tmpdepfile2=`echo "$object" | sed -e 's/.o$/.d/'` - if test "$libtool" = yes; then - "$@" -Wc,-MD - else - "$@" -MD - fi - - stat=$? - if test $stat -eq 0; then : - else - rm -f "$tmpdepfile1" "$tmpdepfile2" - exit $stat - fi - - if test -f "$tmpdepfile1"; then - tmpdepfile="$tmpdepfile1" - else - tmpdepfile="$tmpdepfile2" - fi - if test -f "$tmpdepfile"; then - sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" - # That's a space and a tab in the []. - sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" - else - echo "#dummy" > "$depfile" - fi - rm -f "$tmpdepfile" - ;; - -#nosideeffect) - # This comment above is used by automake to tell side-effect - # dependency tracking mechanisms from slower ones. - -dashmstdout) - # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout, regardless of -o, - # because we must use -o when running libtool. - test -z "$dashmflag" && dashmflag=-M - ( IFS=" " - case " $* " in - *" --mode=compile "*) # this is libtool, let us make it quiet - for arg - do # cycle over the arguments - case "$arg" in - "--mode=compile") - # insert --quiet before "--mode=compile" - set fnord "$@" --quiet - shift # fnord - ;; - esac - set fnord "$@" "$arg" - shift # fnord - shift # "$arg" - done - ;; - esac - "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" - ) & - proc=$! - "$@" - stat=$? - wait "$proc" - if test "$stat" != 0; then exit $stat; fi - rm -f "$depfile" - cat < "$tmpdepfile" > "$depfile" - tr ' ' ' -' < "$tmpdepfile" | \ -## Some versions of the HPUX 10.20 sed can't process this invocation -## correctly. Breaking it into two sed invocations is a workaround. - sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" - rm -f "$tmpdepfile" - ;; - -dashXmstdout) - # This case only exists to satisfy depend.m4. It is never actually - # run, as this mode is specially recognized in the preamble. - exit 1 - ;; - -makedepend) - # X makedepend - ( - shift - cleared=no - for arg in "$@"; do - case $cleared in no) - set ""; shift - cleared=yes - esac - case "$arg" in - -D*|-I*) - set fnord "$@" "$arg"; shift;; - -*) - ;; - *) - set fnord "$@" "$arg"; shift;; - esac - done - obj_suffix="`echo $object | sed 's/^.*\././'`" - touch "$tmpdepfile" - ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@" - ) & - proc=$! - "$@" - stat=$? - wait "$proc" - if test "$stat" != 0; then exit $stat; fi - rm -f "$depfile" - cat < "$tmpdepfile" > "$depfile" - tail +3 "$tmpdepfile" | tr ' ' ' -' | \ -## Some versions of the HPUX 10.20 sed can't process this invocation -## correctly. Breaking it into two sed invocations is a workaround. - sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" - rm -f "$tmpdepfile" "$tmpdepfile".bak - ;; - -cpp) - # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout, regardless of -o, - # because we must use -o when running libtool. - ( IFS=" " - case " $* " in - *" --mode=compile "*) - for arg - do # cycle over the arguments - case $arg in - "--mode=compile") - # insert --quiet before "--mode=compile" - set fnord "$@" --quiet - shift # fnord - ;; - esac - set fnord "$@" "$arg" - shift # fnord - shift # "$arg" - done - ;; - esac - "$@" -E | - sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | - sed '$ s: \\$::' > "$tmpdepfile" - ) & - proc=$! - "$@" - stat=$? - wait "$proc" - if test "$stat" != 0; then exit $stat; fi - rm -f "$depfile" - echo "$object : \\" > "$depfile" - cat < "$tmpdepfile" >> "$depfile" - sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" - rm -f "$tmpdepfile" - ;; - -msvisualcpp) - # Important note: in order to support this mode, a compiler *must* - # always write the proprocessed file to stdout, regardless of -o, - # because we must use -o when running libtool. - ( IFS=" " - case " $* " in - *" --mode=compile "*) - for arg - do # cycle over the arguments - case $arg in - "--mode=compile") - # insert --quiet before "--mode=compile" - set fnord "$@" --quiet - shift # fnord - ;; - esac - set fnord "$@" "$arg" - shift # fnord - shift # "$arg" - done - ;; - esac - "$@" -E | - sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" - ) & - proc=$! - "$@" - stat=$? - wait "$proc" - if test "$stat" != 0; then exit $stat; fi - rm -f "$depfile" - echo "$object : \\" > "$depfile" - . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" - echo " " >> "$depfile" - . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" - rm -f "$tmpdepfile" - ;; - -none) - exec "$@" - ;; - -*) - echo "Unknown depmode $depmode" 1>&2 - exit 1 - ;; -esac - -exit 0 Index: ext/libicpf/install-sh =================================================================== diff -u -N --- ext/libicpf/install-sh (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/install-sh (revision 0) @@ -1,276 +0,0 @@ -#!/bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5 (mit/util/scripts/install.sh). -# -# Copyright 1991 by the Massachusetts Institute of Technology -# -# Permission to use, copy, modify, distribute, and sell this software and its -# documentation for any purpose is hereby granted without fee, provided that -# the above copyright notice appear in all copies and that both that -# copyright notice and this permission notice appear in supporting -# documentation, and that the name of M.I.T. not be used in advertising or -# publicity pertaining to distribution of the software without specific, -# written prior permission. M.I.T. makes no representations about the -# suitability of this software for any purpose. It is provided "as is" -# without express or implied warranty. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. It can only install one file at a time, a restriction -# shared with many OS's install programs. - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd=$cpprog - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd=$stripprog - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "$0: no input file specified" >&2 - exit 1 -else - : -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d "$dst" ]; then - instcmd=: - chmodcmd="" - else - instcmd=$mkdirprog - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f "$src" ] || [ -d "$src" ] - then - : - else - echo "$0: $src does not exist" >&2 - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "$0: no destination specified" >&2 - exit 1 - else - : - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d "$dst" ] - then - dst=$dst/`basename "$src"` - else - : - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' - ' -IFS="${IFS-$defaultIFS}" - -oIFS=$IFS -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS=$oIFS - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp=$pathcomp$1 - shift - - if [ ! -d "$pathcomp" ] ; - then - $mkdirprog "$pathcomp" - else - : - fi - - pathcomp=$pathcomp/ -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd "$dst" && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename "$dst"` - else - dstfile=`basename "$dst" $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename "$dst"` - else - : - fi - -# Make a couple of temp file names in the proper directory. - - dsttmp=$dstdir/#inst.$$# - rmtmp=$dstdir/#rm.$$# - -# Trap to clean up temp files at exit. - - trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0 - trap '(exit $?); exit' 1 2 13 15 - -# Move or copy the file name to the temp name - - $doit $instcmd "$src" "$dsttmp" && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi && - -# Now remove or move aside any old file at destination location. We try this -# two ways since rm can't unlink itself on some systems and the destination -# file might be busy for other reasons. In this case, the final cleanup -# might fail but the new file should still install successfully. - -{ - if [ -f "$dstdir/$dstfile" ] - then - $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null || - $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null || - { - echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 - (exit 1); exit - } - else - : - fi -} && - -# Now rename the file to the real destination. - - $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" - -fi && - -# The final little trick to "correctly" pass the exit status to the exit trap. - -{ - (exit 0); exit -} Index: ext/libicpf/libicpf.kdevelop =================================================================== diff -u -N --- ext/libicpf/libicpf.kdevelop (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/libicpf.kdevelop (revision 0) @@ -1,213 +0,0 @@ - - - - Józef Starosczyk - ixen2@o2.pl - 0.1 - KDevAutoProject - C++ - - C++ - Code - - . - false - - - kdevrbdebugger - kdevfilelist - kdevfileselector - kdevbookmarks - - - kdevcvsservice - - - - src/libicpf.la - debug - - - - true - executable - - - - - / - - true - - - - - optimized - kdevgccoptions - kdevgppoptions - kdevg77options - -O2 -g0 - - - --enable-debug=full - debug - kdevgccoptions - kdevgppoptions - kdevg77options - -O0 -g3 - - - - - - - - - false - 1 - false - - 0 - - - - - ada - ada_bugs_gcc - bash - bash_bugs - clanlib - w3c-dom-level2-html - fortran_bugs_gcc - gnome1 - gnustep - gtk - gtk_bugs - haskell - haskell_bugs_ghc - java_bugs_gcc - java_bugs_sun - kde2book - opengl - pascal_bugs_fp - php - php_bugs - perl - perl_bugs - python - python_bugs - qt-kdev3 - ruby - ruby_bugs - sdl - w3c-svg - sw - w3c-uaag10 - wxwidgets_bugs - - - Guide to the Qt Translation Tools - Qt Assistant Manual - Qt Designer Manual - Qt Reference Documentation - qmake User Guide - - - KDE Libraries (Doxygen) - - - - - - - - - - - - - - false - false - - - *.o,*.lo,CVS - true - false - - - - true - true - true - true - -C - - - - - true - true - true - false - true - true - true - 50 - 50 - 250 - - - - set - m_,_ - theValue - true - true - - - - - .h - .cpp - - - - - - - - - - - true - true - false - - - true - true - 10 - - - - - Kolekcja dokumentacji programu Doxygen - html/index.html - - - - - - - - - VisualBoyAdvance - - - false - false - -f0 - -1 - - Index: ext/libicpf/libicpf.vc90.sln =================================================================== diff -u -N --- ext/libicpf/libicpf.vc90.sln (revision 3e456be345c9b341a4411091589ddd43e7afd114) +++ ext/libicpf/libicpf.vc90.sln (revision 0) @@ -1,40 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf", "src\libicpf\libicpf.vc90.vcproj", "{5510B933-046F-4F75-8B46-5E8279C8CCDE}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf-tests", "src\libicpf-tests\libicpf-tests.vc90.vcproj", "{AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}" - ProjectSection(ProjectDependencies) = postProject - {5510B933-046F-4F75-8B46-5E8279C8CCDE} = {5510B933-046F-4F75-8B46-5E8279C8CCDE} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.ActiveCfg = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.Build.0 = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.ActiveCfg = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.Build.0 = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.ActiveCfg = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.Build.0 = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.ActiveCfg = Release|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.Build.0 = Release|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.ActiveCfg = Debug|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.Build.0 = Debug|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.ActiveCfg = Debug|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.Build.0 = Debug|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|Win32.ActiveCfg = Release|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.ActiveCfg = Release|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal Index: ext/libicpf/ltmain.sh =================================================================== diff -u -N --- ext/libicpf/ltmain.sh (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/ltmain.sh (revision 0) @@ -1,6343 +0,0 @@ -# ltmain.sh - Provide generalized library-building support services. -# NOTE: Changing this file will not affect anything until you rerun configure. -# -# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003 -# Free Software Foundation, Inc. -# Originally by Gordon Matzigkeit , 1996 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# Check that we have a working $echo. -if test "X$1" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift -elif test "X$1" = X--fallback-echo; then - # Avoid inline document here, it may be left over - : -elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then - # Yippee, $echo works! - : -else - # Restart under the correct shell, and then maybe $echo will work. - exec $SHELL "$0" --no-reexec ${1+"$@"} -fi - -if test "X$1" = X--fallback-echo; then - # used as fallback echo - shift - cat <&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit 1 -fi - -# Global variables. -mode=$default_mode -nonopt= -prev= -prevopt= -run= -show="$echo" -show_help= -execute_dlfiles= -lo2o="s/\\.lo\$/.${objext}/" -o2lo="s/\\.${objext}\$/.lo/" - -##################################### -# Shell function definitions: -# This seems to be the best place for them - -# Need a lot of goo to handle *both* DLLs and import libs -# Has to be a shell function in order to 'eat' the argument -# that is supplied when $file_magic_command is called. -win32_libid () { - win32_libid_type="unknown" - win32_fileres=`file -L $1 2>/dev/null` - case $win32_fileres in - *ar\ archive\ import\ library*) # definitely import - win32_libid_type="x86 archive import" - ;; - *ar\ archive*) # could be an import, or static - if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \ - grep -E 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then - win32_nmres=`eval $NM -f posix -A $1 | \ - sed -n -e '1,100{/ I /{x;/import/!{s/^/import/;h;p;};x;};}'` - if test "X$win32_nmres" = "Ximport" ; then - win32_libid_type="x86 archive import" - else - win32_libid_type="x86 archive static" - fi - fi - ;; - *DLL*) - win32_libid_type="x86 DLL" - ;; - *executable*) # but shell scripts are "executable" too... - case $win32_fileres in - *MS\ Windows\ PE\ Intel*) - win32_libid_type="x86 DLL" - ;; - esac - ;; - esac - $echo $win32_libid_type -} - -# End of Shell function definitions -##################################### - -# Parse our command line options once, thoroughly. -while test "$#" -gt 0 -do - arg="$1" - shift - - case $arg in - -*=*) optarg=`$echo "X$arg" | $Xsed -e 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - execute_dlfiles) - execute_dlfiles="$execute_dlfiles $arg" - ;; - tag) - tagname="$arg" - - # Check whether tagname contains only valid characters - case $tagname in - *[!-_A-Za-z0-9,/]*) - $echo "$progname: invalid tag name: $tagname" 1>&2 - exit 1 - ;; - esac - - case $tagname in - CC) - # Don't test for the "default" C tag, as we know, it's there, but - # not specially marked. - ;; - *) - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$0" > /dev/null; then - taglist="$taglist $tagname" - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $0`" - else - $echo "$progname: ignoring unknown tag $tagname" 1>&2 - fi - ;; - esac - ;; - *) - eval "$prev=\$arg" - ;; - esac - - prev= - prevopt= - continue - fi - - # Have we seen a non-optional argument yet? - case $arg in - --help) - show_help=yes - ;; - - --version) - $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP" - $echo - $echo "Copyright (C) 2003 Free Software Foundation, Inc." - $echo "This is free software; see the source for copying conditions. There is NO" - $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - exit 0 - ;; - - --config) - ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $0 - # Now print the configurations for the tags. - for tagname in $taglist; do - ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$0" - done - exit 0 - ;; - - --debug) - $echo "$progname: enabling shell trace mode" - set -x - ;; - - --dry-run | -n) - run=: - ;; - - --features) - $echo "host: $host" - if test "$build_libtool_libs" = yes; then - $echo "enable shared libraries" - else - $echo "disable shared libraries" - fi - if test "$build_old_libs" = yes; then - $echo "enable static libraries" - else - $echo "disable static libraries" - fi - exit 0 - ;; - - --finish) mode="finish" ;; - - --mode) prevopt="--mode" prev=mode ;; - --mode=*) mode="$optarg" ;; - - --preserve-dup-deps) duplicate_deps="yes" ;; - - --quiet | --silent) - show=: - ;; - - --tag) prevopt="--tag" prev=tag ;; - --tag=*) - set tag "$optarg" ${1+"$@"} - shift - prev=tag - ;; - - -dlopen) - prevopt="-dlopen" - prev=execute_dlfiles - ;; - - -*) - $echo "$modename: unrecognized option \`$arg'" 1>&2 - $echo "$help" 1>&2 - exit 1 - ;; - - *) - nonopt="$arg" - break - ;; - esac -done - -if test -n "$prevopt"; then - $echo "$modename: option \`$prevopt' requires an argument" 1>&2 - $echo "$help" 1>&2 - exit 1 -fi - -# If this variable is set in any of the actions, the command in it -# will be execed at the end. This prevents here-documents from being -# left over by shells. -exec_cmd= - -if test -z "$show_help"; then - - # Infer the operation mode. - if test -z "$mode"; then - $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2 - $echo "*** Future versions of Libtool will require -mode=MODE be specified." 1>&2 - case $nonopt in - *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc*) - mode=link - for arg - do - case $arg in - -c) - mode=compile - break - ;; - esac - done - ;; - *db | *dbx | *strace | *truss) - mode=execute - ;; - *install*|cp|mv) - mode=install - ;; - *rm) - mode=uninstall - ;; - *) - # If we have no mode, but dlfiles were specified, then do execute mode. - test -n "$execute_dlfiles" && mode=execute - - # Just use the default operation mode. - if test -z "$mode"; then - if test -n "$nonopt"; then - $echo "$modename: warning: cannot infer operation mode from \`$nonopt'" 1>&2 - else - $echo "$modename: warning: cannot infer operation mode without MODE-ARGS" 1>&2 - fi - fi - ;; - esac - fi - - # Only execute mode is allowed to have -dlopen flags. - if test -n "$execute_dlfiles" && test "$mode" != execute; then - $echo "$modename: unrecognized option \`-dlopen'" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - # Change the help message to a mode-specific one. - generic_help="$help" - help="Try \`$modename --help --mode=$mode' for more information." - - # These modes are in order of execution frequency so that they run quickly. - case $mode in - # libtool compile mode - compile) - modename="$modename: compile" - # Get the compilation command and the source file. - base_compile= - srcfile="$nonopt" # always keep a non-empty value in "srcfile" - suppress_output= - arg_mode=normal - libobj= - - for arg - do - case "$arg_mode" in - arg ) - # do not "continue". Instead, add this to base_compile - lastarg="$arg" - arg_mode=normal - ;; - - target ) - libobj="$arg" - arg_mode=normal - continue - ;; - - normal ) - # Accept any command-line options. - case $arg in - -o) - if test -n "$libobj" ; then - $echo "$modename: you cannot specify \`-o' more than once" 1>&2 - exit 1 - fi - arg_mode=target - continue - ;; - - -static) - build_old_libs=yes - continue - ;; - - -prefer-pic) - pic_mode=yes - continue - ;; - - -prefer-non-pic) - pic_mode=no - continue - ;; - - -Xcompiler) - arg_mode=arg # the next one goes into the "base_compile" arg list - continue # The current "srcfile" will either be retained or - ;; # replaced later. I would guess that would be a bug. - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"` - lastarg= - save_ifs="$IFS"; IFS=',' - for arg in $args; do - IFS="$save_ifs" - - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - lastarg="$lastarg $arg" - done - IFS="$save_ifs" - lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"` - - # Add the arguments to base_compile. - base_compile="$base_compile $lastarg" - continue - ;; - - * ) - # Accept the current argument as the source file. - # The previous "srcfile" becomes the current argument. - # - lastarg="$srcfile" - srcfile="$arg" - ;; - esac # case $arg - ;; - esac # case $arg_mode - - # Aesthetically quote the previous argument. - lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"` - - case $lastarg in - # Double-quote args containing other shell metacharacters. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - lastarg="\"$lastarg\"" - ;; - esac - - base_compile="$base_compile $lastarg" - done # for arg - - case $arg_mode in - arg) - $echo "$modename: you must specify an argument for -Xcompile" - exit 1 - ;; - target) - $echo "$modename: you must specify a target with \`-o'" 1>&2 - exit 1 - ;; - *) - # Get the name of the library object. - [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'` - ;; - esac - - # Recognize several different file suffixes. - # If the user specifies -o file.o, it is replaced with file.lo - xform='[cCFSifmso]' - case $libobj in - *.ada) xform=ada ;; - *.adb) xform=adb ;; - *.ads) xform=ads ;; - *.asm) xform=asm ;; - *.c++) xform=c++ ;; - *.cc) xform=cc ;; - *.ii) xform=ii ;; - *.class) xform=class ;; - *.cpp) xform=cpp ;; - *.cxx) xform=cxx ;; - *.f90) xform=f90 ;; - *.for) xform=for ;; - *.java) xform=java ;; - esac - - libobj=`$echo "X$libobj" | $Xsed -e "s/\.$xform$/.lo/"` - - case $libobj in - *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;; - *) - $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2 - exit 1 - ;; - esac - - # Infer tagged configuration to use if any are available and - # if one wasn't chosen via the "--tag" command line option. - # Only attempt this if the compiler in the base compile - # command doesn't match the default compiler. - if test -n "$available_tags" && test -z "$tagname"; then - case $base_compile in - # Blanks in the command may have been stripped by the calling shell, - # but not from the CC environment variable when configure was run. - " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "*) ;; - # Blanks at the start of $base_compile will cause this to fail - # if we don't check for them as well. - *) - for z in $available_tags; do - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; then - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`" - case "$base_compile " in - "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*) - # The compiler in the base compile command matches - # the one in the tagged configuration. - # Assume this is the tagged configuration we want. - tagname=$z - break - ;; - esac - fi - done - # If $tagname still isn't set, then no tagged configuration - # was found and let the user know that the "--tag" command - # line option must be used. - if test -z "$tagname"; then - $echo "$modename: unable to infer tagged configuration" - $echo "$modename: specify a tag with \`--tag'" 1>&2 - exit 1 -# else -# $echo "$modename: using $tagname tagged configuration" - fi - ;; - esac - fi - - objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'` - xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$obj"; then - xdir= - else - xdir=$xdir/ - fi - lobj=${xdir}$objdir/$objname - - if test -z "$base_compile"; then - $echo "$modename: you must specify a compilation command" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - # Delete any leftover library objects. - if test "$build_old_libs" = yes; then - removelist="$obj $lobj $libobj ${libobj}T" - else - removelist="$lobj $libobj ${libobj}T" - fi - - $run $rm $removelist - trap "$run $rm $removelist; exit 1" 1 2 15 - - # On Cygwin there's no "real" PIC flag so we must build both object types - case $host_os in - cygwin* | mingw* | pw32* | os2*) - pic_mode=default - ;; - esac - if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then - # non-PIC code in shared libraries is not supported - pic_mode=default - fi - - # Calculate the filename of the output object if compiler does - # not support -o with -c - if test "$compiler_c_o" = no; then - output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext} - lockfile="$output_obj.lock" - removelist="$removelist $output_obj $lockfile" - trap "$run $rm $removelist; exit 1" 1 2 15 - else - output_obj= - need_locks=no - lockfile= - fi - - # Lock this critical section if it is needed - # We use this script file to make the link, it avoids creating a new file - if test "$need_locks" = yes; then - until $run ln "$0" "$lockfile" 2>/dev/null; do - $show "Waiting for $lockfile to be removed" - sleep 2 - done - elif test "$need_locks" = warn; then - if test -f "$lockfile"; then - $echo "\ -*** ERROR, $lockfile exists and contains: -`cat $lockfile 2>/dev/null` - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit 1 - fi - $echo $srcfile > "$lockfile" - fi - - if test -n "$fix_srcfile_path"; then - eval srcfile=\"$fix_srcfile_path\" - fi - - $run $rm "$libobj" "${libobj}T" - - # Create a libtool object file (analogous to a ".la" file), - # but don't create it if we're doing a dry run. - test -z "$run" && cat > ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit 1 - fi - - # Just move the object if needed, then go on to compile the next one - if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then - $show "$mv $output_obj $lobj" - if $run $mv $output_obj $lobj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the PIC object to the libtool object file. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T </dev/null`" != "X$srcfile"; then - $echo "\ -*** ERROR, $lockfile contains: -`cat $lockfile 2>/dev/null` - -but it should contain: -$srcfile - -This indicates that another process is trying to use the same -temporary object file, and libtool could not work around it because -your compiler does not support \`-c' and \`-o' together. If you -repeat this compilation, it may succeed, by chance, but you had better -avoid parallel builds (make -j) in this platform, or get a better -compiler." - - $run $rm $removelist - exit 1 - fi - - # Just move the object if needed - if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then - $show "$mv $output_obj $obj" - if $run $mv $output_obj $obj; then : - else - error=$? - $run $rm $removelist - exit $error - fi - fi - - # Append the name of the non-PIC object the libtool object file. - # Only append if the libtool object file exists. - test -z "$run" && cat >> ${libobj}T <> ${libobj}T <&2 - fi - if test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - else - if test -z "$pic_flag" && test -n "$link_static_flag"; then - dlopen_self=$dlopen_self_static - fi - fi - build_libtool_libs=no - build_old_libs=yes - prefer_static_libs=yes - break - ;; - esac - done - - # See if our shared archives depend on static archives. - test -n "$old_archive_from_new_cmds" && build_old_libs=yes - - # Go through the arguments, transforming them on the way. - while test "$#" -gt 0; do - arg="$1" - base_compile="$base_compile $arg" - shift - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - qarg=\"`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`\" ### testsuite: skip nested quoting test - ;; - *) qarg=$arg ;; - esac - libtool_args="$libtool_args $qarg" - - # If the previous option needs an argument, assign it. - if test -n "$prev"; then - case $prev in - output) - compile_command="$compile_command @OUTPUT@" - finalize_command="$finalize_command @OUTPUT@" - ;; - esac - - case $prev in - dlfiles|dlprefiles) - if test "$preload" = no; then - # Add the symbol object into the linking commands. - compile_command="$compile_command @SYMFILE@" - finalize_command="$finalize_command @SYMFILE@" - preload=yes - fi - case $arg in - *.la | *.lo) ;; # We handle these cases below. - force) - if test "$dlself" = no; then - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - self) - if test "$prev" = dlprefiles; then - dlself=yes - elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then - dlself=yes - else - dlself=needless - export_dynamic=yes - fi - prev= - continue - ;; - *) - if test "$prev" = dlfiles; then - dlfiles="$dlfiles $arg" - else - dlprefiles="$dlprefiles $arg" - fi - prev= - continue - ;; - esac - ;; - expsyms) - export_symbols="$arg" - if test ! -f "$arg"; then - $echo "$modename: symbol file \`$arg' does not exist" - exit 1 - fi - prev= - continue - ;; - expsyms_regex) - export_symbols_regex="$arg" - prev= - continue - ;; - inst_prefix) - inst_prefix_dir="$arg" - prev= - continue - ;; - release) - release="-$arg" - prev= - continue - ;; - objectlist) - if test -f "$arg"; then - save_arg=$arg - moreargs= - for fil in `cat $save_arg` - do -# moreargs="$moreargs $fil" - arg=$fil - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit 1 - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit 1 - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - done - else - $echo "$modename: link input file \`$save_arg' does not exist" - exit 1 - fi - arg=$save_arg - prev= - continue - ;; - rpath | xrpath) - # We need an absolute path. - case $arg in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit 1 - ;; - esac - if test "$prev" = rpath; then - case "$rpath " in - *" $arg "*) ;; - *) rpath="$rpath $arg" ;; - esac - else - case "$xrpath " in - *" $arg "*) ;; - *) xrpath="$xrpath $arg" ;; - esac - fi - prev= - continue - ;; - xcompiler) - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - xlinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $wl$qarg" - prev= - compile_command="$compile_command $wl$qarg" - finalize_command="$finalize_command $wl$qarg" - continue - ;; - xcclinker) - linker_flags="$linker_flags $qarg" - compiler_flags="$compiler_flags $qarg" - prev= - compile_command="$compile_command $qarg" - finalize_command="$finalize_command $qarg" - continue - ;; - *) - eval "$prev=\"\$arg\"" - prev= - continue - ;; - esac - fi # test -n "$prev" - - prevarg="$arg" - - case $arg in - -all-static) - if test -n "$link_static_flag"; then - compile_command="$compile_command $link_static_flag" - finalize_command="$finalize_command $link_static_flag" - fi - continue - ;; - - -allow-undefined) - # FIXME: remove this flag sometime in the future. - $echo "$modename: \`-allow-undefined' is deprecated because it is the default" 1>&2 - continue - ;; - - -avoid-version) - avoid_version=yes - continue - ;; - - -dlopen) - prev=dlfiles - continue - ;; - - -dlpreopen) - prev=dlprefiles - continue - ;; - - -export-dynamic) - export_dynamic=yes - continue - ;; - - -export-symbols | -export-symbols-regex) - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: more than one -exported-symbols argument is not allowed" - exit 1 - fi - if test "X$arg" = "X-export-symbols"; then - prev=expsyms - else - prev=expsyms_regex - fi - continue - ;; - - -inst-prefix-dir) - prev=inst_prefix - continue - ;; - - # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* - # so, if we see these flags be careful not to treat them like -L - -L[A-Z][A-Z]*:*) - case $with_gcc/$host in - no/*-*-irix* | /*-*-irix*) - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - ;; - esac - continue - ;; - - -L*) - dir=`$echo "X$arg" | $Xsed -e 's/^-L//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2 - exit 1 - fi - dir="$absdir" - ;; - esac - case "$deplibs " in - *" -L$dir "*) ;; - *) - deplibs="$deplibs -L$dir" - lib_search_path="$lib_search_path $dir" - ;; - esac - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - case :$dllsearchpath: in - *":$dir:"*) ;; - *) dllsearchpath="$dllsearchpath:$dir";; - esac - ;; - esac - continue - ;; - - -l*) - if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then - case $host in - *-*-cygwin* | *-*-pw32* | *-*-beos*) - # These systems don't actually have a C or math library (as such) - continue - ;; - *-*-freebsd*-gnu*) - # prevent being parsed by the freebsd regexp below - ;; - *-*-mingw* | *-*-os2*) - # These systems don't actually have a C library (as such) - test "X$arg" = "X-lc" && continue - ;; - *-*-openbsd* | *-*-freebsd*) - # Do not include libc due to us having libc/libc_r. - test "X$arg" = "X-lc" && continue - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C and math libraries are in the System framework - deplibs="$deplibs -framework System" - continue - esac - elif test "X$arg" = "X-lc_r"; then - case $host in - *-*-freebsd*-gnu*) - # prevent being parsed by the freebsd regexp below - ;; - *-*-openbsd*) - # Do not include libc_r directly, use -pthread flag. - continue - ;; - esac - fi - deplibs="$deplibs $arg" - continue - ;; - - -module) - module=yes - continue - ;; - - # gcc -m* arguments should be passed to the linker via $compiler_flags - # in order to pass architecture information to the linker - # (e.g. 32 vs 64-bit). This may also be accomplished via -Wl,-mfoo - # but this is not reliable with gcc because gcc may use -mfoo to - # select a different linker, different libraries, etc, while - # -Wl,-mfoo simply passes -mfoo to the linker. - -m*) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - if test "$with_gcc" = "yes" ; then - compiler_flags="$compiler_flags $arg" - fi - continue - ;; - - -shrext) - prev=shrext - continue - ;; - - -no-fast-install) - fast_install=no - continue - ;; - - -no-install) - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - # The PATH hackery in wrapper scripts is required on Windows - # in order for the loader to find any dlls it needs. - $echo "$modename: warning: \`-no-install' is ignored for $host" 1>&2 - $echo "$modename: warning: assuming \`-no-fast-install' instead" 1>&2 - fast_install=no - ;; - *) no_install=yes ;; - esac - continue - ;; - - -no-undefined) - allow_undefined=no - continue - ;; - - -objectlist) - prev=objectlist - continue - ;; - - -o) prev=output ;; - - -release) - prev=release - continue - ;; - - -rpath) - prev=rpath - continue - ;; - - -R) - prev=xrpath - continue - ;; - - -R*) - dir=`$echo "X$arg" | $Xsed -e 's/^-R//'` - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - $echo "$modename: only absolute run-paths are allowed" 1>&2 - exit 1 - ;; - esac - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - continue - ;; - - -static) - # The effects of -static are defined in a previous loop. - # We used to do the same as -all-static on platforms that - # didn't have a PIC flag, but the assumption that the effects - # would be equivalent was wrong. It would break on at least - # Digital Unix and AIX. - continue - ;; - - -thread-safe) - thread_safe=yes - continue - ;; - - -version-info) - prev=vinfo - continue - ;; - -version-number) - prev=vinfo - vinfo_number=yes - continue - ;; - - -Wc,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Wl,*) - args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'` - arg= - save_ifs="$IFS"; IFS=',' - for flag in $args; do - IFS="$save_ifs" - case $flag in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - flag="\"$flag\"" - ;; - esac - arg="$arg $wl$flag" - compiler_flags="$compiler_flags $wl$flag" - linker_flags="$linker_flags $flag" - done - IFS="$save_ifs" - arg=`$echo "X$arg" | $Xsed -e "s/^ //"` - ;; - - -Xcompiler) - prev=xcompiler - continue - ;; - - -Xlinker) - prev=xlinker - continue - ;; - - -XCClinker) - prev=xcclinker - continue - ;; - - # Some other compiler flag. - -* | +*) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - add_flags="$add_flags $arg" - ;; - - *.$objext) - # A standard object. - objs="$objs $arg" - ;; - - *.lo) - # A libtool-controlled object. - - # Check to see that this really is a libtool object. - if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - pic_object= - non_pic_object= - - # Read the .lo file - # If there is no directory component, then add one. - case $arg in - */* | *\\*) . $arg ;; - *) . ./$arg ;; - esac - - if test -z "$pic_object" || \ - test -z "$non_pic_object" || - test "$pic_object" = none && \ - test "$non_pic_object" = none; then - $echo "$modename: cannot find name of object for \`$arg'" 1>&2 - exit 1 - fi - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - if test "$pic_object" != none; then - # Prepend the subdirectory the object is found in. - pic_object="$xdir$pic_object" - - if test "$prev" = dlfiles; then - if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then - dlfiles="$dlfiles $pic_object" - prev= - continue - else - # If libtool objects are unsupported, then we need to preload. - prev=dlprefiles - fi - fi - - # CHECK ME: I think I busted this. -Ossama - if test "$prev" = dlprefiles; then - # Preload the old-style object. - dlprefiles="$dlprefiles $pic_object" - prev= - fi - - # A PIC object. - libobjs="$libobjs $pic_object" - arg="$pic_object" - fi - - # Non-PIC object. - if test "$non_pic_object" != none; then - # Prepend the subdirectory the object is found in. - non_pic_object="$xdir$non_pic_object" - - # A standard non-PIC object - non_pic_objects="$non_pic_objects $non_pic_object" - if test -z "$pic_object" || test "$pic_object" = none ; then - arg="$non_pic_object" - fi - fi - else - # Only an error if not doing a dry-run. - if test -z "$run"; then - $echo "$modename: \`$arg' is not a valid libtool object" 1>&2 - exit 1 - else - # Dry-run case. - - # Extract subdirectory from the argument. - xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'` - if test "X$xdir" = "X$arg"; then - xdir= - else - xdir="$xdir/" - fi - - pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"` - non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"` - libobjs="$libobjs $pic_object" - non_pic_objects="$non_pic_objects $non_pic_object" - fi - fi - ;; - - *.$libext) - # An archive. - deplibs="$deplibs $arg" - old_deplibs="$old_deplibs $arg" - continue - ;; - - *.la) - # A libtool-controlled library. - - if test "$prev" = dlfiles; then - # This library was specified with -dlopen. - dlfiles="$dlfiles $arg" - prev= - elif test "$prev" = dlprefiles; then - # The library was specified with -dlpreopen. - dlprefiles="$dlprefiles $arg" - prev= - else - deplibs="$deplibs $arg" - fi - continue - ;; - - # Some other compiler argument. - *) - # Unknown arguments in both finalize_command and compile_command need - # to be aesthetically quoted because they are evaled later. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - arg="\"$arg\"" - ;; - esac - add_flags="$add_flags $arg" - ;; - esac # arg - - # Now actually substitute the argument into the commands. - if test -n "$arg"; then - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - done # argument parsing loop - - if test -n "$prev"; then - $echo "$modename: the \`$prevarg' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - # Infer tagged configuration to use if any are available and - # if one wasn't chosen via the "--tag" command line option. - # Only attempt this if the compiler in the base link - # command doesn't match the default compiler. - if test -n "$available_tags" && test -z "$tagname"; then - case $base_compile in - # Blanks in the command may have been stripped by the calling shell, - # but not from the CC environment variable when configure was run. - "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*) ;; - # Blanks at the start of $base_compile will cause this to fail - # if we don't check for them as well. - *) - for z in $available_tags; do - if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; then - # Evaluate the configuration. - eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`" - case $base_compile in - "$CC "* | " $CC "* | "`$echo $CC` "* | " `$echo $CC` "*) - # The compiler in $compile_command matches - # the one in the tagged configuration. - # Assume this is the tagged configuration we want. - tagname=$z - break - ;; - esac - fi - done - # If $tagname still isn't set, then no tagged configuration - # was found and let the user know that the "--tag" command - # line option must be used. - if test -z "$tagname"; then - $echo "$modename: unable to infer tagged configuration" - $echo "$modename: specify a tag with \`--tag'" 1>&2 - exit 1 -# else -# $echo "$modename: using $tagname tagged configuration" - fi - ;; - esac - fi - - if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then - eval arg=\"$export_dynamic_flag_spec\" - compile_command="$compile_command $arg" - finalize_command="$finalize_command $arg" - fi - - oldlibs= - # calculate the name of the file, without its directory - outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'` - libobjs_save="$libobjs" - - if test -n "$shlibpath_var"; then - # get the directories listed in $shlibpath_var - eval shlib_search_path=\`\$echo \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\` - else - shlib_search_path= - fi - eval sys_lib_search_path=\"$sys_lib_search_path_spec\" - eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" - - output_objdir=`$echo "X$output" | $Xsed -e 's%/[^/]*$%%'` - if test "X$output_objdir" = "X$output"; then - output_objdir="$objdir" - else - output_objdir="$output_objdir/$objdir" - fi - # Create the object directory. - if test ! -d "$output_objdir"; then - $show "$mkdir $output_objdir" - $run $mkdir $output_objdir - status=$? - if test "$status" -ne 0 && test ! -d "$output_objdir"; then - exit $status - fi - fi - - # Determine the type of output - case $output in - "") - $echo "$modename: you must specify an output file" 1>&2 - $echo "$help" 1>&2 - exit 1 - ;; - *.$libext) linkmode=oldlib ;; - *.lo | *.$objext) linkmode=obj ;; - *.la) linkmode=lib ;; - *) linkmode=prog ;; # Anything else should be a program. - esac - - case $host in - *cygwin* | *mingw* | *pw32*) - # don't eliminate duplcations in $postdeps and $predeps - duplicate_compiler_generated_deps=yes - ;; - *) - duplicate_compiler_generated_deps=$duplicate_deps - ;; - esac - specialdeplibs= - - libs= - # Find all interdependent deplibs by searching for libraries - # that are linked more than once (e.g. -la -lb -la) - for deplib in $deplibs; do - if test "X$duplicate_deps" = "Xyes" ; then - case "$libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - libs="$libs $deplib" - done - - if test "$linkmode" = lib; then - libs="$predeps $libs $compiler_lib_search_path $postdeps" - - # Compute libraries that are listed more than once in $predeps - # $postdeps and mark them as special (i.e., whose duplicates are - # not to be eliminated). - pre_post_deps= - if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then - for pre_post_dep in $predeps $postdeps; do - case "$pre_post_deps " in - *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;; - esac - pre_post_deps="$pre_post_deps $pre_post_dep" - done - fi - pre_post_deps= - fi - - deplibs= - newdependency_libs= - newlib_search_path= - need_relink=no # whether we're linking any uninstalled libtool libraries - notinst_deplibs= # not-installed libtool libraries - notinst_path= # paths that contain not-installed libtool libraries - case $linkmode in - lib) - passes="conv link" - for file in $dlfiles $dlprefiles; do - case $file in - *.la) ;; - *) - $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2 - exit 1 - ;; - esac - done - ;; - prog) - compile_deplibs= - finalize_deplibs= - alldeplibs=no - newdlfiles= - newdlprefiles= - passes="conv scan dlopen dlpreopen link" - ;; - *) passes="conv" - ;; - esac - for pass in $passes; do - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan"; then - libs="$deplibs" - deplibs= - fi - if test "$linkmode" = prog; then - case $pass in - dlopen) libs="$dlfiles" ;; - dlpreopen) libs="$dlprefiles" ;; - link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; - esac - fi - if test "$pass" = dlopen; then - # Collect dlpreopened libraries - save_deplibs="$deplibs" - deplibs= - fi - for deplib in $libs; do - lib= - found=no - case $deplib in - -l*) - if test "$linkmode" != lib && test "$linkmode" != prog; then - $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2 - continue - fi - if test "$pass" = conv && test "$allow_undefined" = yes; then - deplibs="$deplib $deplibs" - continue - fi - name=`$echo "X$deplib" | $Xsed -e 's/^-l//'` - for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do - for search_ext in .la $shrext .so .a; do - # Search the libtool library - lib="$searchdir/lib${name}${search_ext}" - if test -f "$lib"; then - if test "$search_ext" = ".la"; then - found=yes - else - found=no - fi - break 2 - fi - done - done - if test "$found" != yes; then - # deplib doesn't seem to be a libtool library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - else # deplib is a libtool library - # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, - # We need to do some special things here, and not later. - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $deplib "*) - if (${SED} -e '2q' $lib | - grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - library_names= - old_library= - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - for l in $old_library $library_names; do - ll="$l" - done - if test "X$ll" = "X$old_library" ; then # only static version available - found=no - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - lib=$ladir/$old_library - if test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - deplibs="$deplib $deplibs" - test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" - fi - continue - fi - fi - ;; - *) ;; - esac - fi - fi - ;; # -l - -L*) - case $linkmode in - lib) - deplibs="$deplib $deplibs" - test "$pass" = conv && continue - newdependency_libs="$deplib $newdependency_libs" - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - ;; - prog) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - if test "$pass" = scan; then - deplibs="$deplib $deplibs" - newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'` - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - ;; - *) - $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2 - ;; - esac # linkmode - continue - ;; # -L - -R*) - if test "$pass" = link; then - dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'` - # Make sure the xrpath contains only unique directories. - case "$xrpath " in - *" $dir "*) ;; - *) xrpath="$xrpath $dir" ;; - esac - fi - deplibs="$deplib $deplibs" - continue - ;; - *.la) lib="$deplib" ;; - *.$libext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - continue - fi - case $linkmode in - lib) - if test "$deplibs_check_method" != pass_all; then - $echo - $echo "*** Warning: Trying to link with static lib archive $deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because the file extensions .$libext of this argument makes me believe" - $echo "*** that it is just a static archive that I should not used here." - else - $echo - $echo "*** Warning: Linking the shared library $output against the" - $echo "*** static library $deplib is not portable!" - deplibs="$deplib $deplibs" - fi - continue - ;; - prog) - if test "$pass" != link; then - deplibs="$deplib $deplibs" - else - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - fi - continue - ;; - esac # linkmode - ;; # *.$libext - *.lo | *.$objext) - if test "$pass" = conv; then - deplibs="$deplib $deplibs" - elif test "$linkmode" = prog; then - if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then - # If there is no dlopen support or we're linking statically, - # we need to preload. - newdlprefiles="$newdlprefiles $deplib" - compile_deplibs="$deplib $compile_deplibs" - finalize_deplibs="$deplib $finalize_deplibs" - else - newdlfiles="$newdlfiles $deplib" - fi - fi - continue - ;; - %DEPLIBS%) - alldeplibs=yes - continue - ;; - esac # case $deplib - if test "$found" = yes || test -f "$lib"; then : - else - $echo "$modename: cannot find the library \`$lib'" 1>&2 - exit 1 - fi - - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit 1 - fi - - ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'` - test "X$ladir" = "X$lib" && ladir="." - - dlname= - dlopen= - dlpreopen= - libdir= - library_names= - old_library= - # If the library was installed with an old release of libtool, - # it will not redefine variables installed, or shouldnotlink - installed=yes - shouldnotlink=no - - # Read the .la file - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - - if test "$linkmode,$pass" = "lib,link" || - test "$linkmode,$pass" = "prog,scan" || - { test "$linkmode" != prog && test "$linkmode" != lib; }; then - test -n "$dlopen" && dlfiles="$dlfiles $dlopen" - test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen" - fi - - if test "$pass" = conv; then - # Only check for convenience libraries - deplibs="$lib $deplibs" - tmp_libs= - for deplib in $dependency_libs; do - #echo "Adding $deplib to \$deplibs" - deplibs="$deplib $deplibs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - if test -z "$libdir"; then - if test -z "$old_library"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit 1 - fi - # It is a libtool convenience library, so add in its objects. - convenience="$convenience $ladir/$objdir/$old_library" - old_convenience="$old_convenience $ladir/$objdir/$old_library" - elif test "$linkmode" != prog && test "$linkmode" != lib; then - $echo "$modename: \`$lib' is not a convenience library" 1>&2 - exit 1 - fi - continue - fi # $pass = conv - - - # Get the name of the library we link against. - linklib= - for l in $old_library $library_names; do - linklib="$l" - done - if test -z "$linklib"; then - $echo "$modename: cannot find name of link library for \`$lib'" 1>&2 - exit 1 - fi - - # This library was specified with -dlopen. - if test "$pass" = dlopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2 - exit 1 - fi - if test -z "$dlname" || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then - # If there is no dlname, no dlopen support or we're linking - # statically, we need to preload. We also need to preload any - # dependent libraries so libltdl's deplib preloader doesn't - # bomb out in the load deplibs phase. - dlprefiles="$dlprefiles $lib $dependency_libs" - else - newdlfiles="$newdlfiles $lib" - fi - continue - fi # $pass = dlopen - - # We need an absolute path. - case $ladir in - [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; - *) - abs_ladir=`cd "$ladir" && pwd` - if test -z "$abs_ladir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$ladir'" 1>&2 - $echo "$modename: passing it literally to the linker, although it might fail" 1>&2 - abs_ladir="$ladir" - fi - ;; - esac - laname=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - - # Find the relevant object directory and library name. - if test "X$installed" = Xyes; then - if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then - $echo "$modename: warning: library \`$lib' was moved." 1>&2 - dir="$ladir" - absdir="$abs_ladir" - libdir="$abs_ladir" - else - dir="$libdir" - absdir="$libdir" - fi - else - dir="$ladir/$objdir" - absdir="$abs_ladir/$objdir" - # Remove this search path later - notinst_path="$notinst_path $abs_ladir" - fi # $installed = yes - name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - - # This library was specified with -dlpreopen. - if test "$pass" = dlpreopen; then - if test -z "$libdir"; then - $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2 - exit 1 - fi - # Prefer using a static library (so that no silly _DYNAMIC symbols - # are required to link). - if test -n "$old_library"; then - newdlprefiles="$newdlprefiles $dir/$old_library" - # Otherwise, use the dlname, so that lt_dlopen finds it. - elif test -n "$dlname"; then - newdlprefiles="$newdlprefiles $dir/$dlname" - else - newdlprefiles="$newdlprefiles $dir/$linklib" - fi - fi # $pass = dlpreopen - - if test -z "$libdir"; then - # Link the convenience library - if test "$linkmode" = lib; then - deplibs="$dir/$old_library $deplibs" - elif test "$linkmode,$pass" = "prog,link"; then - compile_deplibs="$dir/$old_library $compile_deplibs" - finalize_deplibs="$dir/$old_library $finalize_deplibs" - else - deplibs="$lib $deplibs" # used for prog,scan pass - fi - continue - fi - - - if test "$linkmode" = prog && test "$pass" != link; then - newlib_search_path="$newlib_search_path $ladir" - deplibs="$lib $deplibs" - - linkalldeplibs=no - if test "$link_all_deplibs" != no || test -z "$library_names" || - test "$build_libtool_libs" = no; then - linkalldeplibs=yes - fi - - tmp_libs= - for deplib in $dependency_libs; do - case $deplib in - -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test - esac - # Need to link against all dependency_libs? - if test "$linkalldeplibs" = yes; then - deplibs="$deplib $deplibs" - else - # Need to hardcode shared library paths - # or/and link against static libraries - newdependency_libs="$deplib $newdependency_libs" - fi - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done # for deplib - continue - fi # $linkmode = prog... - - if test "$linkmode,$pass" = "prog,link"; then - if test -n "$library_names" && - { test "$prefer_static_libs" = no || test -z "$old_library"; }; then - # We need to hardcode the library path - if test -n "$shlibpath_var"; then - # Make sure the rpath contains only unique directories. - case "$temp_rpath " in - *" $dir "*) ;; - *" $absdir "*) ;; - *) temp_rpath="$temp_rpath $dir" ;; - esac - fi - - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi # $linkmode,$pass = prog,link... - - if test "$alldeplibs" = yes && - { test "$deplibs_check_method" = pass_all || - { test "$build_libtool_libs" = yes && - test -n "$library_names"; }; }; then - # We only need to search for static libraries - continue - fi - fi - - link_static=no # Whether the deplib will be linked statically - if test -n "$library_names" && - { test "$prefer_static_libs" = no || test -z "$old_library"; }; then - if test "$installed" = no; then - notinst_deplibs="$notinst_deplibs $lib" - need_relink=yes - fi - # This is a shared library - - # Warn about portability, can't link against -module's on some systems (darwin) - if test "$shouldnotlink" = yes && test "$pass" = link ; then - $echo - if test "$linkmode" = prog; then - $echo "*** Warning: Linking the executable $output against the loadable module" - else - $echo "*** Warning: Linking the shared library $output against the loadable module" - fi - $echo "*** $linklib is not portable!" - fi - if test "$linkmode" = lib && - test "$hardcode_into_libs" = yes; then - # Hardcode the library path. - # Skip directories that are in the system default run-time - # search path. - case " $sys_lib_dlsearch_path " in - *" $absdir "*) ;; - *) - case "$compile_rpath " in - *" $absdir "*) ;; - *) compile_rpath="$compile_rpath $absdir" - esac - ;; - esac - case " $sys_lib_dlsearch_path " in - *" $libdir "*) ;; - *) - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" - esac - ;; - esac - fi - - if test -n "$old_archive_from_expsyms_cmds"; then - # figure out the soname - set dummy $library_names - realname="$2" - shift; shift - libname=`eval \\$echo \"$libname_spec\"` - # use dlname if we got it. it's perfectly good, no? - if test -n "$dlname"; then - soname="$dlname" - elif test -n "$soname_spec"; then - # bleh windows - case $host in - *cygwin* | mingw*) - major=`expr $current - $age` - versuffix="-$major" - ;; - esac - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - - # Make a new name for the extract_expsyms_cmds to use - soroot="$soname" - soname=`$echo $soroot | ${SED} -e 's/^.*\///'` - newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a" - - # If the library has no export list, then create one now - if test -f "$output_objdir/$soname-def"; then : - else - $show "extracting exported symbol list from \`$soname'" - save_ifs="$IFS"; IFS='~' - eval cmds=\"$extract_expsyms_cmds\" - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - # Create $newlib - if test -f "$output_objdir/$newlib"; then :; else - $show "generating import library for \`$soname'" - save_ifs="$IFS"; IFS='~' - eval cmds=\"$old_archive_from_expsyms_cmds\" - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - # make sure the library variables are pointing to the new library - dir=$output_objdir - linklib=$newlib - fi # test -n "$old_archive_from_expsyms_cmds" - - if test "$linkmode" = prog || test "$mode" != relink; then - add_shlibpath= - add_dir= - add= - lib_linked=yes - case $hardcode_action in - immediate | unsupported) - if test "$hardcode_direct" = no; then - add="$dir/$linklib" - case $host in - *-*-sco3.2v5* ) add_dir="-L$dir" ;; - *-*-darwin* ) - # if the lib is a module then we can not link against it, someone - # is ignoring the new warnings I added - if /usr/bin/file -L $add 2> /dev/null | grep "bundle" >/dev/null ; then - $echo "** Warning, lib $linklib is a module, not a shared library" - if test -z "$old_library" ; then - $echo - $echo "** And there doesn't seem to be a static archive available" - $echo "** The link will probably fail, sorry" - else - add="$dir/$old_library" - fi - fi - esac - elif test "$hardcode_minus_L" = no; then - case $host in - *-*-sunos*) add_shlibpath="$dir" ;; - esac - add_dir="-L$dir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = no; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - relink) - if test "$hardcode_direct" = yes; then - add="$dir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$dir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case "$libdir" in - [\\/]*) - add_dir="-L$inst_prefix_dir$libdir $add_dir" - ;; - esac - fi - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - add_shlibpath="$dir" - add="-l$name" - else - lib_linked=no - fi - ;; - *) lib_linked=no ;; - esac - - if test "$lib_linked" != yes; then - $echo "$modename: configuration error: unsupported hardcode properties" - exit 1 - fi - - if test -n "$add_shlibpath"; then - case :$compile_shlibpath: in - *":$add_shlibpath:"*) ;; - *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;; - esac - fi - if test "$linkmode" = prog; then - test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" - test -n "$add" && compile_deplibs="$add $compile_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - if test "$hardcode_direct" != yes && \ - test "$hardcode_minus_L" != yes && \ - test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - fi - fi - fi - - if test "$linkmode" = prog || test "$mode" = relink; then - add_shlibpath= - add_dir= - add= - # Finalize command for both is simple: just hardcode it. - if test "$hardcode_direct" = yes; then - add="$libdir/$linklib" - elif test "$hardcode_minus_L" = yes; then - add_dir="-L$libdir" - add="-l$name" - elif test "$hardcode_shlibpath_var" = yes; then - case :$finalize_shlibpath: in - *":$libdir:"*) ;; - *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;; - esac - add="-l$name" - elif test "$hardcode_automatic" = yes; then - if test -n "$inst_prefix_dir" && test -f "$inst_prefix_dir$libdir/$linklib" ; then - add="$inst_prefix_dir$libdir/$linklib" - else - add="$libdir/$linklib" - fi - else - # We cannot seem to hardcode it, guess we'll fake it. - add_dir="-L$libdir" - # Try looking first in the location we're being installed to. - if test -n "$inst_prefix_dir"; then - case "$libdir" in - [\\/]*) - add_dir="-L$inst_prefix_dir$libdir $add_dir" - ;; - esac - fi - add="-l$name" - fi - - if test "$linkmode" = prog; then - test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" - test -n "$add" && finalize_deplibs="$add $finalize_deplibs" - else - test -n "$add_dir" && deplibs="$add_dir $deplibs" - test -n "$add" && deplibs="$add $deplibs" - fi - fi - elif test "$linkmode" = prog; then - # Here we assume that one of hardcode_direct or hardcode_minus_L - # is not unsupported. This is valid on all known static and - # shared platforms. - if test "$hardcode_direct" != unsupported; then - test -n "$old_library" && linklib="$old_library" - compile_deplibs="$dir/$linklib $compile_deplibs" - finalize_deplibs="$dir/$linklib $finalize_deplibs" - else - compile_deplibs="-l$name -L$dir $compile_deplibs" - finalize_deplibs="-l$name -L$dir $finalize_deplibs" - fi - elif test "$build_libtool_libs" = yes; then - # Not a shared library - if test "$deplibs_check_method" != pass_all; then - # We're trying link a shared library against a static one - # but the system doesn't support it. - - # Just print a warning and add the library to dependency_libs so - # that the program can be linked against the static library. - $echo - $echo "*** Warning: This system can not link to static lib archive $lib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have." - if test "$module" = yes; then - $echo "*** But as you try to build a module library, libtool will still create " - $echo "*** a static module, that should work as long as the dlopening application" - $echo "*** is linked with the -dlopen flag to resolve symbols at runtime." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - else - convenience="$convenience $dir/$old_library" - old_convenience="$old_convenience $dir/$old_library" - deplibs="$dir/$old_library $deplibs" - link_static=yes - fi - fi # link shared/static library? - - if test "$linkmode" = lib; then - #if test -n "$dependency_libs" && - # { test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes || - # test "$link_static" = yes; }; then - # Extract -R from dependency_libs - temp_deplibs= - for libdir in $dependency_libs; do - case $libdir in - -R*) temp_xrpath=`$echo "X$libdir" | $Xsed -e 's/^-R//'` - case " $xrpath " in - *" $temp_xrpath "*) ;; - *) xrpath="$xrpath $temp_xrpath";; - esac;; - *) temp_deplibs="$temp_deplibs $libdir";; - esac - done - dependency_libs="$temp_deplibs" - #fi - - newlib_search_path="$newlib_search_path $absdir" - # Link against this library - test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" - # ... and its dependency_libs - tmp_libs= - for deplib in $dependency_libs; do - newdependency_libs="$deplib $newdependency_libs" - if test "X$duplicate_deps" = "Xyes" ; then - case "$tmp_libs " in - *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;; - esac - fi - tmp_libs="$tmp_libs $deplib" - done - - if test "$link_all_deplibs" != no; then - # Add the search paths of all dependency libraries - for deplib in $dependency_libs; do - case $deplib in - -L*) path="$deplib" ;; - *.la) - dir=`$echo "X$deplib" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$deplib" && dir="." - # We need an absolute path. - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; - *) - absdir=`cd "$dir" && pwd` - if test -z "$absdir"; then - $echo "$modename: warning: cannot determine absolute directory name of \`$dir'" 1>&2 - absdir="$dir" - fi - ;; - esac - if grep "^installed=no" $deplib > /dev/null; then - path="$absdir/$objdir" - else - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit 1 - fi - if test "$absdir" != "$libdir"; then - # Sure, some shells/systems don't implement the -ef. - # Those will have to live with the warning. - test "$absdir" -ef "$libdir" > /dev/null 2>&1 || - $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2 - fi - path="$absdir" - fi - depdepl= - case $host in - *-*-darwin*) - # we do not want to link against static libs, but need to link against shared - eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` - if test -n "$deplibrary_names" ; then - for tmp in $deplibrary_names ; do - depdepl=$tmp - done - if test -f "$path/$depdepl" ; then - depdepl="$path/$depdepl" - fi - # do not add paths which are already there - case " $newlib_search_path " in - *" $path "*) ;; - *) newlib_search_path="$newlib_search_path $path";; - esac - path="" - fi - ;; - *) - path="-L$path" - ;; - esac - - ;; - -l*) - case $host in - *-*-darwin*) - # Again, we only want to link against shared libraries - eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"` - for tmp in $newlib_search_path ; do - if test -f "$tmp/lib$tmp_libs.dylib" ; then - eval depdepl="$tmp/lib$tmp_libs.dylib" - break - fi - done - path="" - ;; - *) continue ;; - esac - ;; - *) continue ;; - esac - case " $deplibs " in - *" $depdepl "*) ;; - *) deplibs="$deplibs $depdepl" ;; - esac - case " $deplibs " in - *" $path "*) ;; - *) deplibs="$deplibs $path" ;; - esac - done - fi # link_all_deplibs != no - fi # linkmode = lib - done # for deplib in $libs - dependency_libs="$newdependency_libs" - if test "$pass" = dlpreopen; then - # Link the dlpreopened libraries before other libraries - for deplib in $save_deplibs; do - deplibs="$deplib $deplibs" - done - fi - if test "$pass" != dlopen; then - if test "$pass" != conv; then - # Make sure lib_search_path contains only unique directories. - lib_search_path= - for dir in $newlib_search_path; do - case "$lib_search_path " in - *" $dir "*) ;; - *) lib_search_path="$lib_search_path $dir" ;; - esac - done - newlib_search_path= - fi - - if test "$linkmode,$pass" != "prog,link"; then - vars="deplibs" - else - vars="compile_deplibs finalize_deplibs" - fi - for var in $vars dependency_libs; do - # Add libraries to $var in reverse order - eval tmp_libs=\"\$$var\" - new_libs= - for deplib in $tmp_libs; do - # FIXME: Pedantically, this is the right thing to do, so - # that some nasty dependency loop isn't accidentally - # broken: - #new_libs="$deplib $new_libs" - # Pragmatically, this seems to cause very few problems in - # practice: - case $deplib in - -L*) new_libs="$deplib $new_libs" ;; - -R*) ;; - *) - # And here is the reason: when a library appears more - # than once as an explicit dependence of a library, or - # is implicitly linked in more than once by the - # compiler, it is considered special, and multiple - # occurrences thereof are not removed. Compare this - # with having the same library being listed as a - # dependency of multiple other libraries: in this case, - # we know (pedantically, we assume) the library does not - # need to be listed more than once, so we keep only the - # last copy. This is not always right, but it is rare - # enough that we require users that really mean to play - # such unportable linking tricks to link the library - # using -Wl,-lname, so that libtool does not consider it - # for duplicate removal. - case " $specialdeplibs " in - *" $deplib "*) new_libs="$deplib $new_libs" ;; - *) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$deplib $new_libs" ;; - esac - ;; - esac - ;; - esac - done - tmp_libs= - for deplib in $new_libs; do - case $deplib in - -L*) - case " $tmp_libs " in - *" $deplib "*) ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - ;; - *) tmp_libs="$tmp_libs $deplib" ;; - esac - done - eval $var=\"$tmp_libs\" - done # for var - fi - # Last step: remove runtime libs from dependency_libs (they stay in deplibs) - tmp_libs= - for i in $dependency_libs ; do - case " $predeps $postdeps $compiler_lib_search_path " in - *" $i "*) - i="" - ;; - esac - if test -n "$i" ; then - tmp_libs="$tmp_libs $i" - fi - done - dependency_libs=$tmp_libs - done # for pass - if test "$linkmode" = prog; then - dlfiles="$newdlfiles" - dlprefiles="$newdlprefiles" - fi - - case $linkmode in - oldlib) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2 - fi - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for archives" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for archives" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for archives" 1>&2 - fi - - if test -n "$export_symbols" || test -n "$export_symbols_regex"; then - $echo "$modename: warning: \`-export-symbols' is ignored for archives" 1>&2 - fi - - # Now set the variables for building old libraries. - build_libtool_libs=no - oldlibs="$output" - objs="$objs$old_deplibs" - ;; - - lib) - # Make sure we only generate libraries of the form `libNAME.la'. - case $outputname in - lib*) - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - eval shared_ext=\"$shrext\" - eval libname=\"$libname_spec\" - ;; - *) - if test "$module" = no; then - $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - if test "$need_lib_prefix" != no; then - # Add the "lib" prefix for modules if required - name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - eval shared_ext=\"$shrext\" - eval libname=\"$libname_spec\" - else - libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'` - fi - ;; - esac - - if test -n "$objs"; then - if test "$deplibs_check_method" != pass_all; then - $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1 - exit 1 - else - $echo - $echo "*** Warning: Linking the shared library $output against the non-libtool" - $echo "*** objects $objs is not portable!" - libobjs="$libobjs $objs" - fi - fi - - if test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen self' is ignored for libtool libraries" 1>&2 - fi - - set dummy $rpath - if test "$#" -gt 2; then - $echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2 - fi - install_libdir="$2" - - oldlibs= - if test -z "$rpath"; then - if test "$build_libtool_libs" = yes; then - # Building a libtool convenience library. - # Some compilers have problems with a `.al' extension so - # convenience libraries should have the same extension an - # archive normally would. - oldlibs="$output_objdir/$libname.$libext $oldlibs" - build_libtool_libs=convenience - build_old_libs=yes - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for convenience libraries" 1>&2 - fi - else - - # Parse the version information argument. - save_ifs="$IFS"; IFS=':' - set dummy $vinfo 0 0 0 - IFS="$save_ifs" - - if test -n "$8"; then - $echo "$modename: too many parameters to \`-version-info'" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - # convert absolute version numbers to libtool ages - # this retains compatibility with .la files and attempts - # to make the code below a bit more comprehensible - - case $vinfo_number in - yes) - number_major="$2" - number_minor="$3" - number_revision="$4" - # - # There are really only two kinds -- those that - # use the current revision as the major version - # and those that subtract age and use age as - # a minor version. But, then there is irix - # which has an extra 1 added just for fun - # - case $version_type in - darwin|linux|osf|windows) - current=`expr $number_major + $number_minor` - age="$number_minor" - revision="$number_revision" - ;; - freebsd-aout|freebsd-elf|sunos) - current="$number_major" - revision="$number_minor" - age="0" - ;; - irix|nonstopux) - current=`expr $number_major + $number_minor - 1` - age="$number_minor" - revision="$number_minor" - ;; - esac - ;; - no) - current="$2" - revision="$3" - age="$4" - ;; - esac - - # Check that each of the things are valid numbers. - case $current in - 0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;; - *) - $echo "$modename: CURRENT \`$current' is not a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit 1 - ;; - esac - - case $revision in - 0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;; - *) - $echo "$modename: REVISION \`$revision' is not a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit 1 - ;; - esac - - case $age in - 0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;; - *) - $echo "$modename: AGE \`$age' is not a nonnegative integer" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit 1 - ;; - esac - - if test "$age" -gt "$current"; then - $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2 - $echo "$modename: \`$vinfo' is not valid version information" 1>&2 - exit 1 - fi - - # Calculate the version variables. - major= - versuffix= - verstring= - case $version_type in - none) ;; - - darwin) - # Like Linux, but with the current version available in - # verstring for coding it into the library header - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - # Darwin ld doesn't like 0 for these options... - minor_current=`expr $current + 1` - verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" - ;; - - freebsd-aout) - major=".$current" - versuffix=".$current.$revision"; - ;; - - freebsd-elf) - major=".$current" - versuffix=".$current"; - ;; - - irix | nonstopux) - major=`expr $current - $age + 1` - - case $version_type in - nonstopux) verstring_prefix=nonstopux ;; - *) verstring_prefix=sgi ;; - esac - verstring="$verstring_prefix$major.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$revision - while test "$loop" -ne 0; do - iface=`expr $revision - $loop` - loop=`expr $loop - 1` - verstring="$verstring_prefix$major.$iface:$verstring" - done - - # Before this point, $major must not contain `.'. - major=.$major - versuffix="$major.$revision" - ;; - - linux) - major=.`expr $current - $age` - versuffix="$major.$age.$revision" - ;; - - osf) - major=.`expr $current - $age` - versuffix=".$current.$age.$revision" - verstring="$current.$age.$revision" - - # Add in all the interfaces that we are compatible with. - loop=$age - while test "$loop" -ne 0; do - iface=`expr $current - $loop` - loop=`expr $loop - 1` - verstring="$verstring:${iface}.0" - done - - # Make executables depend on our current version. - verstring="$verstring:${current}.0" - ;; - - sunos) - major=".$current" - versuffix=".$current.$revision" - ;; - - windows) - # Use '-' rather than '.', since we only want one - # extension on DOS 8.3 filesystems. - major=`expr $current - $age` - versuffix="-$major" - ;; - - *) - $echo "$modename: unknown library version type \`$version_type'" 1>&2 - $echo "Fatal configuration error. See the $PACKAGE docs for more information." 1>&2 - exit 1 - ;; - esac - - # Clear the version info if we defaulted, and they specified a release. - if test -z "$vinfo" && test -n "$release"; then - major= - case $version_type in - darwin) - # we can't check for "0.0" in archive_cmds due to quoting - # problems, so we reset it completely - verstring= - ;; - *) - verstring="0.0" - ;; - esac - if test "$need_version" = no; then - versuffix= - else - versuffix=".0.0" - fi - fi - - # Remove version info from name if versioning should be avoided - if test "$avoid_version" = yes && test "$need_version" = no; then - major= - versuffix= - verstring="" - fi - - # Check to see if the archive will have undefined symbols. - if test "$allow_undefined" = yes; then - if test "$allow_undefined_flag" = unsupported; then - $echo "$modename: warning: undefined symbols not allowed in $host shared libraries" 1>&2 - build_libtool_libs=no - build_old_libs=yes - fi - else - # Don't allow undefined symbols. - allow_undefined_flag="$no_undefined_flag" - fi - fi - - if test "$mode" != relink; then - # Remove our outputs, but don't remove object files since they - # may have been created when compiling PIC objects. - removelist= - tempremovelist=`$echo "$output_objdir/*"` - for p in $tempremovelist; do - case $p in - *.$objext) - ;; - $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) - removelist="$removelist $p" - ;; - *) ;; - esac - done - if test -n "$removelist"; then - $show "${rm}r $removelist" - $run ${rm}r $removelist - fi - fi - - # Now set the variables for building old libraries. - if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then - oldlibs="$oldlibs $output_objdir/$libname.$libext" - - # Transform .lo files to .o files. - oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP` - fi - - # Eliminate all temporary directories. - for path in $notinst_path; do - lib_search_path=`$echo "$lib_search_path " | ${SED} -e 's% $path % %g'` - deplibs=`$echo "$deplibs " | ${SED} -e 's% -L$path % %g'` - dependency_libs=`$echo "$dependency_libs " | ${SED} -e 's% -L$path % %g'` - done - - if test -n "$xrpath"; then - # If the user specified any rpath flags, then add them. - temp_xrpath= - for libdir in $xrpath; do - temp_xrpath="$temp_xrpath -R$libdir" - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - if true || test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then - dependency_libs="$temp_xrpath $dependency_libs" - fi - fi - - # Make sure dlfiles contains only unique files that won't be dlpreopened - old_dlfiles="$dlfiles" - dlfiles= - for lib in $old_dlfiles; do - case " $dlprefiles $dlfiles " in - *" $lib "*) ;; - *) dlfiles="$dlfiles $lib" ;; - esac - done - - # Make sure dlprefiles contains only unique files - old_dlprefiles="$dlprefiles" - dlprefiles= - for lib in $old_dlprefiles; do - case "$dlprefiles " in - *" $lib "*) ;; - *) dlprefiles="$dlprefiles $lib" ;; - esac - done - - if test "$build_libtool_libs" = yes; then - if test -n "$rpath"; then - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos*) - # these systems don't actually have a c library (as such)! - ;; - *-*-rhapsody* | *-*-darwin1.[012]) - # Rhapsody C library is in the System framework - deplibs="$deplibs -framework System" - ;; - *-*-netbsd*) - # Don't link with libc until the a.out ld.so is fixed. - ;; - *-*-freebsd*-gnu*) - # Prevent $arg from being parsed by the freebsd regexp below. - if test "$build_libtool_need_lc" = "yes"; then - deplibs="$deplibs -lc" - fi - ;; - *-*-openbsd* | *-*-freebsd*) - # Do not include libc due to us having libc/libc_r. - test "X$arg" = "X-lc" && continue - ;; - *) - # Add libc to deplibs on all other systems if necessary. - if test "$build_libtool_need_lc" = "yes"; then - deplibs="$deplibs -lc" - fi - ;; - esac - fi - - # Transform deplibs into only deplibs that can be linked in shared. - name_save=$name - libname_save=$libname - release_save=$release - versuffix_save=$versuffix - major_save=$major - # I'm not sure if I'm treating the release correctly. I think - # release should show up in the -l (ie -lgmp5) so we don't want to - # add it in twice. Is that correct? - release="" - versuffix="" - major="" - newdeplibs= - droppeddeps=no - case $deplibs_check_method in - pass_all) - # Don't check for shared/static. Everything works. - # This might be a little naive. We might want to check - # whether the library exists or not. But this is on - # osf3 & osf4 and I'm not really sure... Just - # implementing what was already the behavior. - newdeplibs=$deplibs - ;; - test_compile) - # This code stresses the "libraries are programs" paradigm to its - # limits. Maybe even breaks it. We compile a program, linking it - # against the deplibs as a proxy for the library. Then we can check - # whether they linked in statically or dynamically with ldd. - $rm conftest.c - cat > conftest.c </dev/null` - for potent_lib in $potential_libs; do - # Follow soft links. - if ls -lLd "$potent_lib" 2>/dev/null \ - | grep " -> " >/dev/null; then - continue - fi - # The statement above tries to avoid entering an - # endless loop below, in case of cyclic links. - # We might still enter an endless loop, since a link - # loop can be closed while we follow links, - # but so what? - potlib="$potent_lib" - while test -h "$potlib" 2>/dev/null; do - potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` - case $potliblink in - [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; - *) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";; - esac - done - if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$file_magic_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for file magic test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a file magic. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - match_pattern*) - set dummy $deplibs_check_method - match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"` - for a_deplib in $deplibs; do - name="`expr $a_deplib : '-l\(.*\)'`" - # If $name is empty we are operating on a -L argument. - if test -n "$name" && test "$name" != "0"; then - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - case " $predeps $postdeps " in - *" $a_deplib "*) - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - ;; - esac - fi - if test -n "$a_deplib" ; then - libname=`eval \\$echo \"$libname_spec\"` - for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do - potential_libs=`ls $i/$libname[.-]* 2>/dev/null` - for potent_lib in $potential_libs; do - potlib="$potent_lib" # see symlink-check above in file_magic test - if eval $echo \"$potent_lib\" 2>/dev/null \ - | ${SED} 10q \ - | $EGREP "$match_pattern_regex" > /dev/null; then - newdeplibs="$newdeplibs $a_deplib" - a_deplib="" - break 2 - fi - done - done - fi - if test -n "$a_deplib" ; then - droppeddeps=yes - $echo - $echo "*** Warning: linker path does not have real file for library $a_deplib." - $echo "*** I have the capability to make that library automatically link in when" - $echo "*** you link to this library. But I can only do this if you have a" - $echo "*** shared version of the library, which you do not appear to have" - $echo "*** because I did check the linker path looking for a file starting" - if test -z "$potlib" ; then - $echo "*** with $libname but no candidates were found. (...for regex pattern test)" - else - $echo "*** with $libname and none of the candidates passed a file format test" - $echo "*** using a regex pattern. Last file checked: $potlib" - fi - fi - else - # Add a -L argument. - newdeplibs="$newdeplibs $a_deplib" - fi - done # Gone through all deplibs. - ;; - none | unknown | *) - newdeplibs="" - tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \ - -e 's/ -[LR][^ ]*//g'` - if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then - for i in $predeps $postdeps ; do - # can't use Xsed below, because $i might contain '/' - tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"` - done - fi - if $echo "X $tmp_deplibs" | $Xsed -e 's/[ ]//g' \ - | grep . >/dev/null; then - $echo - if test "X$deplibs_check_method" = "Xnone"; then - $echo "*** Warning: inter-library dependencies are not supported in this platform." - else - $echo "*** Warning: inter-library dependencies are not known to be supported." - fi - $echo "*** All declared inter-library dependencies are being dropped." - droppeddeps=yes - fi - ;; - esac - versuffix=$versuffix_save - major=$major_save - release=$release_save - libname=$libname_save - name=$name_save - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - newdeplibs=`$echo "X $newdeplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - if test "$droppeddeps" = yes; then - if test "$module" = yes; then - $echo - $echo "*** Warning: libtool could not satisfy all declared inter-library" - $echo "*** dependencies of module $libname. Therefore, libtool will create" - $echo "*** a static module, that should work as long as the dlopening" - $echo "*** application is linked with the -dlopen flag." - if test -z "$global_symbol_pipe"; then - $echo - $echo "*** However, this would only work if libtool was able to extract symbol" - $echo "*** lists from a program, using \`nm' or equivalent, but libtool could" - $echo "*** not find such a program. So, this module is probably useless." - $echo "*** \`nm' from GNU binutils and a full rebuild may help." - fi - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - else - $echo "*** The inter-library dependencies that have been dropped here will be" - $echo "*** automatically added whenever a program is linked with this library" - $echo "*** or is declared to -dlopen it." - - if test "$allow_undefined" = no; then - $echo - $echo "*** Since this library must not contain undefined symbols," - $echo "*** because either the platform does not support them or" - $echo "*** it was explicitly requested with -no-undefined," - $echo "*** libtool will only create a static version of it." - if test "$build_old_libs" = no; then - oldlibs="$output_objdir/$libname.$libext" - build_libtool_libs=module - build_old_libs=yes - else - build_libtool_libs=no - fi - fi - fi - fi - # Done checking deplibs! - deplibs=$newdeplibs - fi - - # All the library-specific variables (install_libdir is set above). - library_names= - old_library= - dlname= - - # Test again, we may have decided not to build it any more - if test "$build_libtool_libs" = yes; then - if test "$hardcode_into_libs" = yes; then - # Hardcode the library paths - hardcode_libdirs= - dep_rpath= - rpath="$finalize_rpath" - test "$mode" != relink && test "$fast_install" = no && rpath="$compile_rpath$rpath" - for libdir in $rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - dep_rpath="$dep_rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - if test -n "$hardcode_libdir_flag_spec_ld"; then - eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\" - else - eval dep_rpath=\"$hardcode_libdir_flag_spec\" - fi - fi - if test -n "$runpath_var" && test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" - fi - test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" - fi - - shlibpath="$finalize_shlibpath" - test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath" - if test -n "$shlibpath"; then - eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" - fi - - # Get the real and link names of the library. - eval shared_ext=\"$shrext\" - eval library_names=\"$library_names_spec\" - set dummy $library_names - realname="$2" - shift; shift - - if test -n "$soname_spec"; then - eval soname=\"$soname_spec\" - else - soname="$realname" - fi - if test -z "$dlname"; then - dlname=$soname - fi - - lib="$output_objdir/$realname" - for link - do - linknames="$linknames $link" - done - - # Use standard objects if they are pic - test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - eval cmds=\"$export_symbols_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - if len=`expr "X$cmd" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - $show "$cmd" - $run eval "$cmd" || exit $? - skipped_export=false - else - # The command line is too long to execute in one step. - $show "using reloadable object file for export list..." - skipped_export=: - fi - done - IFS="$save_ifs" - if test -n "$export_symbols_regex"; then - $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"" - $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' - $show "$mv \"${export_symbols}T\" \"$export_symbols\"" - $run eval '$mv "${export_symbols}T" "$export_symbols"' - fi - fi - fi - - if test -n "$export_symbols" && test -n "$include_expsyms"; then - $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"' - fi - - tmp_deplibs= - for test_deplib in $deplibs; do - case " $convenience " in - *" $test_deplib "*) ;; - *) - tmp_deplibs="$tmp_deplibs $test_deplib" - ;; - esac - done - deplibs="$tmp_deplibs" - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - else - gentop="$output_objdir/${outputname}x" - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - $show "$mkdir $gentop" - $run $mkdir "$gentop" - status=$? - if test "$status" -ne 0 && test ! -d "$gentop"; then - exit $status - fi - generated="$generated $gentop" - - for xlib in $convenience; do - # Extract the objects. - case $xlib in - [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;; - *) xabs=`pwd`"/$xlib" ;; - esac - xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'` - xdir="$gentop/$xlib" - - $show "${rm}r $xdir" - $run ${rm}r "$xdir" - $show "$mkdir $xdir" - $run $mkdir "$xdir" - status=$? - if test "$status" -ne 0 && test ! -d "$xdir"; then - exit $status - fi - # We will extract separately just the conflicting names and we will no - # longer touch any unique names. It is faster to leave these extract - # automatically by $AR in one run. - $show "(cd $xdir && $AR x $xabs)" - $run eval "(cd \$xdir && $AR x \$xabs)" || exit $? - if ($AR t "$xabs" | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: warning: object name conflicts; renaming object files" 1>&2 - $echo "$modename: warning: to ensure that they will not overwrite" 1>&2 - $AR t "$xabs" | sort | uniq -cd | while read -r count name - do - i=1 - while test "$i" -le "$count" - do - # Put our $i before any first dot (extension) - # Never overwrite any file - name_to="$name" - while test "X$name_to" = "X$name" || test -f "$xdir/$name_to" - do - name_to=`$echo "X$name_to" | $Xsed -e "s/\([^.]*\)/\1-$i/"` - done - $show "(cd $xdir && $AR xN $i $xabs '$name' && $mv '$name' '$name_to')" - $run eval "(cd \$xdir && $AR xN $i \$xabs '$name' && $mv '$name' '$name_to')" || exit $? - i=`expr $i + 1` - done - done - fi - - libobjs="$libobjs "`find $xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` - done - fi - fi - - if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then - eval flag=\"$thread_safe_flag_spec\" - linker_flags="$linker_flags $flag" - fi - - # Make a backup of the uninstalled library when relinking - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}U && $mv $realname ${realname}U)' || exit $? - fi - - # Add all flags from the command line. We here create a library, - # but those flags were only added to compile_command and - # finalize_command, which are only used when creating executables. - # So do it by hand here. - compiler_flags="$compiler_flags $add_flags" - # Only add it to commands which use CC, instead of LD, i.e. - # only to $compiler_flags - #linker_flags="$linker_flags $add_flags" - - # Do each of the archive commands. - if test "$module" = yes && test -n "$module_cmds" ; then - if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then - eval cmds=\"$module_expsym_cmds\" - else - eval cmds=\"$module_cmds\" - fi - else - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - eval cmds=\"$archive_expsym_cmds\" - else - eval cmds=\"$archive_cmds\" - fi - fi - - if test "X$skipped_export" != "X:" && len=`expr "X$cmds" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - : - else - # The command line is too long to link in one step, link piecewise. - $echo "creating reloadable object files..." - - # Save the value of $output and $libobjs because we want to - # use them later. If we have whole_archive_flag_spec, we - # want to use save_libobjs as it was before - # whole_archive_flag_spec was expanded, because we can't - # assume the linker understands whole_archive_flag_spec. - # This may have to be revisited, in case too many - # convenience libraries get linked in and end up exceeding - # the spec. - if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then - save_libobjs=$libobjs - fi - save_output=$output - - # Clear the reloadable object creation command queue and - # initialize k to one. - test_cmds= - concat_cmds= - objlist= - delfiles= - last_robj= - k=1 - output=$output_objdir/$save_output-${k}.$objext - # Loop over the list of objects to be linked. - for obj in $save_libobjs - do - eval test_cmds=\"$reload_cmds $objlist $last_robj\" - if test "X$objlist" = X || - { len=`expr "X$test_cmds" : ".*"` && - test "$len" -le "$max_cmd_len"; }; then - objlist="$objlist $obj" - else - # The command $test_cmds is almost too long, add a - # command to the queue. - if test "$k" -eq 1 ; then - # The first file doesn't have a previous command to add. - eval concat_cmds=\"$reload_cmds $objlist $last_robj\" - else - # All subsequent reloadable object files will link in - # the last one created. - eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\" - fi - last_robj=$output_objdir/$save_output-${k}.$objext - k=`expr $k + 1` - output=$output_objdir/$save_output-${k}.$objext - objlist=$obj - len=1 - fi - done - # Handle the remaining objects by creating one last - # reloadable object file. All subsequent reloadable object - # files will link in the last one created. - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\" - - if ${skipped_export-false}; then - $show "generating symbol list for \`$libname.la'" - export_symbols="$output_objdir/$libname.exp" - $run $rm $export_symbols - libobjs=$output - # Append the command to create the export file. - eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\" - fi - - # Set up a command to remove the reloadale object files - # after they are used. - i=0 - while test "$i" -lt "$k" - do - i=`expr $i + 1` - delfiles="$delfiles $output_objdir/$save_output-${i}.$objext" - done - - $echo "creating a temporary reloadable object file: $output" - - # Loop through the commands generated above and execute them. - save_ifs="$IFS"; IFS='~' - for cmd in $concat_cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - libobjs=$output - # Restore the value of output. - output=$save_output - - if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then - eval libobjs=\"\$libobjs $whole_archive_flag_spec\" - fi - # Expand the library linking commands again to reset the - # value of $libobjs for piecewise linking. - - # Do each of the archive commands. - if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then - eval cmds=\"$archive_expsym_cmds\" - else - eval cmds=\"$archive_cmds\" - fi - - # Append the command to remove the reloadable object files - # to the just-reset $cmds. - eval cmds=\"\$cmds~$rm $delfiles\" - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - # Restore the uninstalled library and exit - if test "$mode" = relink; then - $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $? - exit 0 - fi - - # Create links to the real library. - for linkname in $linknames; do - if test "$realname" != "$linkname"; then - $show "(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)" - $run eval '(cd $output_objdir && $rm $linkname && $LN_S $realname $linkname)' || exit $? - fi - done - - # If -module or -export-dynamic was specified, set the dlname. - if test "$module" = yes || test "$export_dynamic" = yes; then - # On all known operating systems, these are identical. - dlname="$soname" - fi - fi - ;; - - obj) - if test -n "$deplibs"; then - $echo "$modename: warning: \`-l' and \`-L' are ignored for objects" 1>&2 - fi - - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - $echo "$modename: warning: \`-dlopen' is ignored for objects" 1>&2 - fi - - if test -n "$rpath"; then - $echo "$modename: warning: \`-rpath' is ignored for objects" 1>&2 - fi - - if test -n "$xrpath"; then - $echo "$modename: warning: \`-R' is ignored for objects" 1>&2 - fi - - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for objects" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for objects" 1>&2 - fi - - case $output in - *.lo) - if test -n "$objs$old_deplibs"; then - $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2 - exit 1 - fi - libobj="$output" - obj=`$echo "X$output" | $Xsed -e "$lo2o"` - ;; - *) - libobj= - obj="$output" - ;; - esac - - # Delete the old objects. - $run $rm $obj $libobj - - # Objects from convenience libraries. This assumes - # single-version convenience libraries. Whenever we create - # different ones for PIC/non-PIC, this we'll have to duplicate - # the extraction. - reload_conv_objs= - gentop= - # reload_cmds runs $LD directly, so let us get rid of - # -Wl from whole_archive_flag_spec - wl= - - if test -n "$convenience"; then - if test -n "$whole_archive_flag_spec"; then - eval reload_conv_objs=\"\$reload_objs $whole_archive_flag_spec\" - else - gentop="$output_objdir/${obj}x" - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - $show "$mkdir $gentop" - $run $mkdir "$gentop" - status=$? - if test "$status" -ne 0 && test ! -d "$gentop"; then - exit $status - fi - generated="$generated $gentop" - - for xlib in $convenience; do - # Extract the objects. - case $xlib in - [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;; - *) xabs=`pwd`"/$xlib" ;; - esac - xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'` - xdir="$gentop/$xlib" - - $show "${rm}r $xdir" - $run ${rm}r "$xdir" - $show "$mkdir $xdir" - $run $mkdir "$xdir" - status=$? - if test "$status" -ne 0 && test ! -d "$xdir"; then - exit $status - fi - # We will extract separately just the conflicting names and we will no - # longer touch any unique names. It is faster to leave these extract - # automatically by $AR in one run. - $show "(cd $xdir && $AR x $xabs)" - $run eval "(cd \$xdir && $AR x \$xabs)" || exit $? - if ($AR t "$xabs" | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: warning: object name conflicts; renaming object files" 1>&2 - $echo "$modename: warning: to ensure that they will not overwrite" 1>&2 - $AR t "$xabs" | sort | uniq -cd | while read -r count name - do - i=1 - while test "$i" -le "$count" - do - # Put our $i before any first dot (extension) - # Never overwrite any file - name_to="$name" - while test "X$name_to" = "X$name" || test -f "$xdir/$name_to" - do - name_to=`$echo "X$name_to" | $Xsed -e "s/\([^.]*\)/\1-$i/"` - done - $show "(cd $xdir && $AR xN $i $xabs '$name' && $mv '$name' '$name_to')" - $run eval "(cd \$xdir && $AR xN $i \$xabs '$name' && $mv '$name' '$name_to')" || exit $? - i=`expr $i + 1` - done - done - fi - - reload_conv_objs="$reload_objs "`find $xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP` - done - fi - fi - - # Create the old-style object. - reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test - - output="$obj" - eval cmds=\"$reload_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - - # Exit if we aren't doing a library object file. - if test -z "$libobj"; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit 0 - fi - - if test "$build_libtool_libs" != yes; then - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - # Create an invalid libtool object if no PIC, so that we don't - # accidentally link it into a program. - # $show "echo timestamp > $libobj" - # $run eval "echo timestamp > $libobj" || exit $? - exit 0 - fi - - if test -n "$pic_flag" || test "$pic_mode" != default; then - # Only do commands if we really have different PIC objects. - reload_objs="$libobjs $reload_conv_objs" - output="$libobj" - eval cmds=\"$reload_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - if test -n "$gentop"; then - $show "${rm}r $gentop" - $run ${rm}r $gentop - fi - - exit 0 - ;; - - prog) - case $host in - *cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;; - esac - if test -n "$vinfo"; then - $echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2 - fi - - if test -n "$release"; then - $echo "$modename: warning: \`-release' is ignored for programs" 1>&2 - fi - - if test "$preload" = yes; then - if test "$dlopen_support" = unknown && test "$dlopen_self" = unknown && - test "$dlopen_self_static" = unknown; then - $echo "$modename: warning: \`AC_LIBTOOL_DLOPEN' not used. Assuming no dlopen support." - fi - fi - - case $host in - *-*-rhapsody* | *-*-darwin1.[012]) - # On Rhapsody replace the C library is the System framework - compile_deplibs=`$echo "X $compile_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - finalize_deplibs=`$echo "X $finalize_deplibs" | $Xsed -e 's/ -lc / -framework System /'` - ;; - esac - - case $host in - *darwin*) - # Don't allow lazy linking, it breaks C++ global constructors - if test "$tagname" = CXX ; then - compile_command="$compile_command ${wl}-bind_at_load" - finalize_command="$finalize_command ${wl}-bind_at_load" - fi - ;; - esac - - compile_command="$compile_command $compile_deplibs" - finalize_command="$finalize_command $finalize_deplibs" - - if test -n "$rpath$xrpath"; then - # If the user specified any rpath flags, then add them. - for libdir in $rpath $xrpath; do - # This is the magic to use -rpath. - case "$finalize_rpath " in - *" $libdir "*) ;; - *) finalize_rpath="$finalize_rpath $libdir" ;; - esac - done - fi - - # Now hardcode the library paths - rpath= - hardcode_libdirs= - for libdir in $compile_rpath $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$perm_rpath " in - *" $libdir "*) ;; - *) perm_rpath="$perm_rpath $libdir" ;; - esac - fi - case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*) - case :$dllsearchpath: in - *":$libdir:"*) ;; - *) dllsearchpath="$dllsearchpath:$libdir";; - esac - ;; - esac - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - compile_rpath="$rpath" - - rpath= - hardcode_libdirs= - for libdir in $finalize_rpath; do - if test -n "$hardcode_libdir_flag_spec"; then - if test -n "$hardcode_libdir_separator"; then - if test -z "$hardcode_libdirs"; then - hardcode_libdirs="$libdir" - else - # Just accumulate the unique libdirs. - case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in - *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) - ;; - *) - hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir" - ;; - esac - fi - else - eval flag=\"$hardcode_libdir_flag_spec\" - rpath="$rpath $flag" - fi - elif test -n "$runpath_var"; then - case "$finalize_perm_rpath " in - *" $libdir "*) ;; - *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;; - esac - fi - done - # Substitute the hardcoded libdirs into the rpath. - if test -n "$hardcode_libdir_separator" && - test -n "$hardcode_libdirs"; then - libdir="$hardcode_libdirs" - eval rpath=\" $hardcode_libdir_flag_spec\" - fi - finalize_rpath="$rpath" - - if test -n "$libobjs" && test "$build_old_libs" = yes; then - # Transform all the library objects into standard objects. - compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - fi - - dlsyms= - if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then - if test -n "$NM" && test -n "$global_symbol_pipe"; then - dlsyms="${outputname}S.c" - else - $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2 - fi - fi - - if test -n "$dlsyms"; then - case $dlsyms in - "") ;; - *.c) - # Discover the nlist of each of the dlfiles. - nlist="$output_objdir/${outputname}.nm" - - $show "$rm $nlist ${nlist}S ${nlist}T" - $run $rm "$nlist" "${nlist}S" "${nlist}T" - - # Parse the name list into a source file. - $show "creating $output_objdir/$dlsyms" - - test -z "$run" && $echo > "$output_objdir/$dlsyms" "\ -/* $dlsyms - symbol resolution table for \`$outputname' dlsym emulation. */ -/* Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP */ - -#ifdef __cplusplus -extern \"C\" { -#endif - -/* Prevent the only kind of declaration conflicts we can make. */ -#define lt_preloaded_symbols some_other_symbol - -/* External symbol declarations for the compiler. */\ -" - - if test "$dlself" = yes; then - $show "generating symbol list for \`$output'" - - test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist" - - # Add our own program objects to the symbol list. - progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP` - for arg in $progfiles; do - $show "extracting global C symbols from \`$arg'" - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -n "$exclude_expsyms"; then - $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - if test -n "$export_symbols_regex"; then - $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' - $run eval '$mv "$nlist"T "$nlist"' - fi - - # Prepare the list of exported symbols - if test -z "$export_symbols"; then - export_symbols="$output_objdir/$output.exp" - $run $rm $export_symbols - $run eval "${SED} -n -e '/^: @PROGRAM@$/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' - else - $run eval "${SED} -e 's/\([][.*^$]\)/\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$output.exp"' - $run eval 'grep -f "$output_objdir/$output.exp" < "$nlist" > "$nlist"T' - $run eval 'mv "$nlist"T "$nlist"' - fi - fi - - for arg in $dlprefiles; do - $show "extracting global C symbols from \`$arg'" - name=`$echo "$arg" | ${SED} -e 's%^.*/%%'` - $run eval '$echo ": $name " >> "$nlist"' - $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'" - done - - if test -z "$run"; then - # Make sure we have at least an empty file. - test -f "$nlist" || : > "$nlist" - - if test -n "$exclude_expsyms"; then - $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T - $mv "$nlist"T "$nlist" - fi - - # Try sorting and uniquifying the output. - if grep -v "^: " < "$nlist" | - if sort -k 3 /dev/null 2>&1; then - sort -k 3 - else - sort +2 - fi | - uniq > "$nlist"S; then - : - else - grep -v "^: " < "$nlist" > "$nlist"S - fi - - if test -f "$nlist"S; then - eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"' - else - $echo '/* NONE */' >> "$output_objdir/$dlsyms" - fi - - $echo >> "$output_objdir/$dlsyms" "\ - -#undef lt_preloaded_symbols - -#if defined (__STDC__) && __STDC__ -# define lt_ptr void * -#else -# define lt_ptr char * -# define const -#endif - -/* The mapping between symbol names and symbols. */ -const struct { - const char *name; - lt_ptr address; -} -lt_preloaded_symbols[] = -{\ -" - - eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms" - - $echo >> "$output_objdir/$dlsyms" "\ - {0, (lt_ptr) 0} -}; - -/* This works around a problem in FreeBSD linker */ -#ifdef FREEBSD_WORKAROUND -static const void *lt_preloaded_setup() { - return lt_preloaded_symbols; -} -#endif - -#ifdef __cplusplus -} -#endif\ -" - fi - - pic_flag_for_symtable= - case $host in - # compiling the symbol table file with pic_flag works around - # a FreeBSD bug that causes programs to crash when -lm is - # linked before any other PIC object. But we must not use - # pic_flag when linking with -static. The problem exists in - # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. - *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND";; - esac;; - *-*-hpux*) - case "$compile_command " in - *" -static "*) ;; - *) pic_flag_for_symtable=" $pic_flag";; - esac - esac - - # Now compile the dynamic symbol file. - $show "(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")" - $run eval '(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $? - - # Clean up the generated files. - $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T" - $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T" - - # Transform the symbol file into the correct name. - compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"` - finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"` - ;; - *) - $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2 - exit 1 - ;; - esac - else - # We keep going just in case the user didn't refer to - # lt_preloaded_symbols. The linker will fail if global_symbol_pipe - # really was required. - - # Nullify the symbol file. - compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"` - finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"` - fi - - # AIX runtime linking requires linking programs with -Wl,-brtl and libs with -Wl,-G - # Also add -bnolibpath to the beginning of the link line, to clear the hardcoded runpath. - # Otherwise, things like the -L path to libgcc.a are accidentally hardcoded by ld. - # This does not apply on AIX for ia64, which uses a SysV linker. - case "$host" in - ia64-*-aix5*) ;; - *-*-aix4* | *-*-aix5*) - compile_command=`$echo "X$compile_command $wl-brtl" | $Xsed -e "s/\$CC/\$CC $wl-bnolibpath/1"` - finalize_command=`$echo "X$finalize_command $wl-brtl" | $Xsed -e "s/\$CC/\$CC $wl-bnolibpath/1"` ;; - esac - - if test "$need_relink" = no || test "$build_libtool_libs" != yes; then - # Replace the output file specification. - compile_command=`$echo "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` - link_command="$compile_command$compile_rpath" - - # We have no uninstalled library dependencies, so finalize right now. - $show "$link_command" - $run eval "$link_command" - status=$? - - # Delete the generated files. - if test -n "$dlsyms"; then - $show "$rm $output_objdir/${outputname}S.${objext}" - $run $rm "$output_objdir/${outputname}S.${objext}" - fi - - exit $status - fi - - if test -n "$shlibpath_var"; then - # We should set the shlibpath_var - rpath= - for dir in $temp_rpath; do - case $dir in - [\\/]* | [A-Za-z]:[\\/]*) - # Absolute path. - rpath="$rpath$dir:" - ;; - *) - # Relative path: add a thisdir entry. - rpath="$rpath\$thisdir/$dir:" - ;; - esac - done - temp_rpath="$rpath" - fi - - if test -n "$compile_shlibpath$finalize_shlibpath"; then - compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" - fi - if test -n "$finalize_shlibpath"; then - finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" - fi - - compile_var= - finalize_var= - if test -n "$runpath_var"; then - if test -n "$perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $perm_rpath; do - rpath="$rpath$dir:" - done - compile_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - if test -n "$finalize_perm_rpath"; then - # We should set the runpath_var. - rpath= - for dir in $finalize_perm_rpath; do - rpath="$rpath$dir:" - done - finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " - fi - fi - - if test "$no_install" = yes; then - # We don't need to create a wrapper script. - link_command="$compile_var$compile_command$compile_rpath" - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'` - # Delete the old output file. - $run $rm $output - # Link the executable and exit - $show "$link_command" - $run eval "$link_command" || exit $? - exit 0 - fi - - if test "$hardcode_action" = relink; then - # Fast installation is not supported - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - - $echo "$modename: warning: this platform does not like uninstalled shared libraries" 1>&2 - $echo "$modename: \`$output' will be relinked during installation" 1>&2 - else - if test "$fast_install" != no; then - link_command="$finalize_var$compile_command$finalize_rpath" - if test "$fast_install" = yes; then - relink_command=`$echo "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'` - else - # fast_install is set to needless - relink_command= - fi - else - link_command="$compile_var$compile_command$compile_rpath" - relink_command="$finalize_var$finalize_command$finalize_rpath" - fi - fi - - # Replace the output file specification. - link_command=`$echo "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` - - # Delete the old output files. - $run $rm $output $output_objdir/$outputname $output_objdir/lt-$outputname - - $show "$link_command" - $run eval "$link_command" || exit $? - - # Now create the wrapper script. - $show "creating $output" - - # Quote the relink command for shipping. - if test -n "$relink_command"; then - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - relink_command="(cd `pwd`; $relink_command)" - relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"` - fi - - # Quote $echo for shipping. - if test "X$echo" = "X$SHELL $0 --fallback-echo"; then - case $0 in - [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $0 --fallback-echo";; - *) qecho="$SHELL `pwd`/$0 --fallback-echo";; - esac - qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"` - else - qecho=`$echo "X$echo" | $Xsed -e "$sed_quote_subst"` - fi - - # Only actually do things if our run command is non-null. - if test -z "$run"; then - # win32 will think the script is a binary if it has - # a .exe suffix, so we strip it off here. - case $output in - *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;; - esac - # test for cygwin because mv fails w/o .exe extensions - case $host in - *cygwin*) - exeext=.exe - outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;; - *) exeext= ;; - esac - case $host in - *cygwin* | *mingw* ) - cwrappersource=`$echo ${objdir}/lt-${output}.c` - cwrapper=`$echo ${output}.exe` - $rm $cwrappersource $cwrapper - trap "$rm $cwrappersource $cwrapper; exit 1" 1 2 15 - - cat > $cwrappersource <> $cwrappersource<<"EOF" -#include -#include -#include -#include -#include -#include - -#if defined(PATH_MAX) -# define LT_PATHMAX PATH_MAX -#elif defined(MAXPATHLEN) -# define LT_PATHMAX MAXPATHLEN -#else -# define LT_PATHMAX 1024 -#endif - -#ifndef DIR_SEPARATOR -#define DIR_SEPARATOR '/' -#endif - -#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ - defined (__OS2__) -#define HAVE_DOS_BASED_FILE_SYSTEM -#ifndef DIR_SEPARATOR_2 -#define DIR_SEPARATOR_2 '\\' -#endif -#endif - -#ifndef DIR_SEPARATOR_2 -# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) -#else /* DIR_SEPARATOR_2 */ -# define IS_DIR_SEPARATOR(ch) \ - (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) -#endif /* DIR_SEPARATOR_2 */ - -#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) -#define XFREE(stale) do { \ - if (stale) { free ((void *) stale); stale = 0; } \ -} while (0) - -const char *program_name = NULL; - -void * xmalloc (size_t num); -char * xstrdup (const char *string); -char * basename (const char *name); -char * fnqualify(const char *path); -char * strendzap(char *str, const char *pat); -void lt_fatal (const char *message, ...); - -int -main (int argc, char *argv[]) -{ - char **newargz; - int i; - - program_name = (char *) xstrdup ((char *) basename (argv[0])); - newargz = XMALLOC(char *, argc+2); -EOF - - cat >> $cwrappersource <> $cwrappersource <<"EOF" - newargz[1] = fnqualify(argv[0]); - /* we know the script has the same name, without the .exe */ - /* so make sure newargz[1] doesn't end in .exe */ - strendzap(newargz[1],".exe"); - for (i = 1; i < argc; i++) - newargz[i+1] = xstrdup(argv[i]); - newargz[argc+1] = NULL; -EOF - - cat >> $cwrappersource <> $cwrappersource <<"EOF" -} - -void * -xmalloc (size_t num) -{ - void * p = (void *) malloc (num); - if (!p) - lt_fatal ("Memory exhausted"); - - return p; -} - -char * -xstrdup (const char *string) -{ - return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL -; -} - -char * -basename (const char *name) -{ - const char *base; - -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - /* Skip over the disk name in MSDOS pathnames. */ - if (isalpha (name[0]) && name[1] == ':') - name += 2; -#endif - - for (base = name; *name; name++) - if (IS_DIR_SEPARATOR (*name)) - base = name + 1; - return (char *) base; -} - -char * -fnqualify(const char *path) -{ - size_t size; - char *p; - char tmp[LT_PATHMAX + 1]; - - assert(path != NULL); - - /* Is it qualified already? */ -#if defined (HAVE_DOS_BASED_FILE_SYSTEM) - if (isalpha (path[0]) && path[1] == ':') - return xstrdup (path); -#endif - if (IS_DIR_SEPARATOR (path[0])) - return xstrdup (path); - - /* prepend the current directory */ - /* doesn't handle '~' */ - if (getcwd (tmp, LT_PATHMAX) == NULL) - lt_fatal ("getcwd failed"); - size = strlen(tmp) + 1 + strlen(path) + 1; /* +2 for '/' and '\0' */ - p = XMALLOC(char, size); - sprintf(p, "%s%c%s", tmp, DIR_SEPARATOR, path); - return p; -} - -char * -strendzap(char *str, const char *pat) -{ - size_t len, patlen; - - assert(str != NULL); - assert(pat != NULL); - - len = strlen(str); - patlen = strlen(pat); - - if (patlen <= len) - { - str += len - patlen; - if (strcmp(str, pat) == 0) - *str = '\0'; - } - return str; -} - -static void -lt_error_core (int exit_status, const char * mode, - const char * message, va_list ap) -{ - fprintf (stderr, "%s: %s: ", program_name, mode); - vfprintf (stderr, message, ap); - fprintf (stderr, ".\n"); - - if (exit_status >= 0) - exit (exit_status); -} - -void -lt_fatal (const char *message, ...) -{ - va_list ap; - va_start (ap, message); - lt_error_core (EXIT_FAILURE, "FATAL", message, ap); - va_end (ap); -} -EOF - # we should really use a build-platform specific compiler - # here, but OTOH, the wrappers (shell script and this C one) - # are only useful if you want to execute the "real" binary. - # Since the "real" binary is built for $host, then this - # wrapper might as well be built for $host, too. - $run $LTCC -s -o $cwrapper $cwrappersource - ;; - esac - $rm $output - trap "$rm $output; exit 1" 1 2 15 - - $echo > $output "\ -#! $SHELL - -# $output - temporary wrapper script for $objdir/$outputname -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# The $output program cannot be directly executed until all the libtool -# libraries that it depends on are installed. -# -# This wrapper script should never be moved out of the build directory. -# If it is, it will not operate correctly. - -# Sed substitution that helps us do robust quoting. It backslashifies -# metacharacters that are still active within double-quoted strings. -Xsed='${SED} -e 1s/^X//' -sed_quote_subst='$sed_quote_subst' - -# The HP-UX ksh and POSIX shell print the target directory to stdout -# if CDPATH is set. -if test \"\${CDPATH+set}\" = set; then CDPATH=:; export CDPATH; fi - -relink_command=\"$relink_command\" - -# This environment variable determines our operation mode. -if test \"\$libtool_install_magic\" = \"$magic\"; then - # install mode needs the following variable: - notinst_deplibs='$notinst_deplibs' -else - # When we are sourced in execute mode, \$file and \$echo are already set. - if test \"\$libtool_execute_magic\" != \"$magic\"; then - echo=\"$qecho\" - file=\"\$0\" - # Make sure echo works. - if test \"X\$1\" = X--no-reexec; then - # Discard the --no-reexec flag, and continue. - shift - elif test \"X\`(\$echo '\t') 2>/dev/null\`\" = 'X\t'; then - # Yippee, \$echo works! - : - else - # Restart under the correct shell, and then maybe \$echo will work. - exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"} - fi - fi\ -" - $echo >> $output "\ - - # Find the directory that this script lives in. - thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` - test \"x\$thisdir\" = \"x\$file\" && thisdir=. - - # Follow symbolic links until we get to the real thisdir. - file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\` - while test -n \"\$file\"; do - destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\` - - # If there was a directory component, then change thisdir. - if test \"x\$destdir\" != \"x\$file\"; then - case \"\$destdir\" in - [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; - *) thisdir=\"\$thisdir/\$destdir\" ;; - esac - fi - - file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\` - file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\` - done - - # Try to get the absolute directory name. - absdir=\`cd \"\$thisdir\" && pwd\` - test -n \"\$absdir\" && thisdir=\"\$absdir\" -" - - if test "$fast_install" = yes; then - $echo >> $output "\ - program=lt-'$outputname'$exeext - progdir=\"\$thisdir/$objdir\" - - if test ! -f \"\$progdir/\$program\" || \\ - { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ - test \"X\$file\" != \"X\$progdir/\$program\"; }; then - - file=\"\$\$-\$program\" - - if test ! -d \"\$progdir\"; then - $mkdir \"\$progdir\" - else - $rm \"\$progdir/\$file\" - fi" - - $echo >> $output "\ - - # relink executable if necessary - if test -n \"\$relink_command\"; then - if relink_command_output=\`eval \$relink_command 2>&1\`; then : - else - $echo \"\$relink_command_output\" >&2 - $rm \"\$progdir/\$file\" - exit 1 - fi - fi - - $mv \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || - { $rm \"\$progdir/\$program\"; - $mv \"\$progdir/\$file\" \"\$progdir/\$program\"; } - $rm \"\$progdir/\$file\" - fi" - else - $echo >> $output "\ - program='$outputname' - progdir=\"\$thisdir/$objdir\" -" - fi - - $echo >> $output "\ - - if test -f \"\$progdir/\$program\"; then" - - # Export our shlibpath_var if we have one. - if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then - $echo >> $output "\ - # Add our own library path to $shlibpath_var - $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" - - # Some systems cannot cope with colon-terminated $shlibpath_var - # The second colon is a workaround for a bug in BeOS R4 sed - $shlibpath_var=\`\$echo \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\` - - export $shlibpath_var -" - fi - - # fixup the dll searchpath if we need to. - if test -n "$dllsearchpath"; then - $echo >> $output "\ - # Add the dll search path components to the executable PATH - PATH=$dllsearchpath:\$PATH -" - fi - - $echo >> $output "\ - if test \"\$libtool_execute_magic\" != \"$magic\"; then - # Run the actual program with our arguments. -" - case $host in - # Backslashes separate directories on plain windows - *-*-mingw | *-*-os2*) - $echo >> $output "\ - exec \$progdir\\\\\$program \${1+\"\$@\"} -" - ;; - - *) - $echo >> $output "\ - exec \$progdir/\$program \${1+\"\$@\"} -" - ;; - esac - $echo >> $output "\ - \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\" - exit 1 - fi - else - # The program doesn't exist. - \$echo \"\$0: error: \$progdir/\$program does not exist\" 1>&2 - \$echo \"This script is just a wrapper for \$program.\" 1>&2 - $echo \"See the $PACKAGE documentation for more information.\" 1>&2 - exit 1 - fi -fi\ -" - chmod +x $output - fi - exit 0 - ;; - esac - - # See if we need to build an old-fashioned archive. - for oldlib in $oldlibs; do - - if test "$build_libtool_libs" = convenience; then - oldobjs="$libobjs_save" - addlibs="$convenience" - build_libtool_libs=no - else - if test "$build_libtool_libs" = module; then - oldobjs="$libobjs_save" - build_libtool_libs=no - else - oldobjs="$old_deplibs $non_pic_objects" - fi - addlibs="$old_convenience" - fi - - if test -n "$addlibs"; then - gentop="$output_objdir/${outputname}x" - $show "${rm}r $gentop" - $run ${rm}r "$gentop" - $show "$mkdir $gentop" - $run $mkdir "$gentop" - status=$? - if test "$status" -ne 0 && test ! -d "$gentop"; then - exit $status - fi - generated="$generated $gentop" - - # Add in members from convenience archives. - for xlib in $addlibs; do - # Extract the objects. - case $xlib in - [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;; - *) xabs=`pwd`"/$xlib" ;; - esac - xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'` - xdir="$gentop/$xlib" - - $show "${rm}r $xdir" - $run ${rm}r "$xdir" - $show "$mkdir $xdir" - $run $mkdir "$xdir" - status=$? - if test "$status" -ne 0 && test ! -d "$xdir"; then - exit $status - fi - # We will extract separately just the conflicting names and we will no - # longer touch any unique names. It is faster to leave these extract - # automatically by $AR in one run. - $show "(cd $xdir && $AR x $xabs)" - $run eval "(cd \$xdir && $AR x \$xabs)" || exit $? - if ($AR t "$xabs" | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: warning: object name conflicts; renaming object files" 1>&2 - $echo "$modename: warning: to ensure that they will not overwrite" 1>&2 - $AR t "$xabs" | sort | uniq -cd | while read -r count name - do - i=1 - while test "$i" -le "$count" - do - # Put our $i before any first dot (extension) - # Never overwrite any file - name_to="$name" - while test "X$name_to" = "X$name" || test -f "$xdir/$name_to" - do - name_to=`$echo "X$name_to" | $Xsed -e "s/\([^.]*\)/\1-$i/"` - done - $show "(cd $xdir && $AR xN $i $xabs '$name' && $mv '$name' '$name_to')" - $run eval "(cd \$xdir && $AR xN $i \$xabs '$name' && $mv '$name' '$name_to')" || exit $? - i=`expr $i + 1` - done - done - fi - - oldobjs="$oldobjs "`find $xdir -name \*.${objext} -print -o -name \*.lo -print | $NL2SP` - done - fi - - compiler_flags="$compiler_flags $add_flags" - - # Do each command in the archive commands. - if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then - eval cmds=\"$old_archive_from_new_cmds\" - else - eval cmds=\"$old_archive_cmds\" - - if len=`expr "X$cmds" : ".*"` && - test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then - : - else - # the command line is too long to link in one step, link in parts - $echo "using piecewise archive linking..." - save_RANLIB=$RANLIB - RANLIB=: - objlist= - concat_cmds= - save_oldobjs=$oldobjs - # GNU ar 2.10+ was changed to match POSIX; thus no paths are - # encoded into archives. This makes 'ar r' malfunction in - # this piecewise linking case whenever conflicting object - # names appear in distinct ar calls; check, warn and compensate. - if (for obj in $save_oldobjs - do - $echo "X$obj" | $Xsed -e 's%^.*/%%' - done | sort | sort -uc >/dev/null 2>&1); then - : - else - $echo "$modename: warning: object name conflicts; overriding AR_FLAGS to 'cq'" 1>&2 - $echo "$modename: warning: to ensure that POSIX-compatible ar will work" 1>&2 - AR_FLAGS=cq - fi - # Is there a better way of finding the last object in the list? - for obj in $save_oldobjs - do - last_oldobj=$obj - done - for obj in $save_oldobjs - do - oldobjs="$objlist $obj" - objlist="$objlist $obj" - eval test_cmds=\"$old_archive_cmds\" - if len=`expr "X$test_cmds" : ".*"` && - test "$len" -le "$max_cmd_len"; then - : - else - # the above command should be used before it gets too long - oldobjs=$objlist - if test "$obj" = "$last_oldobj" ; then - RANLIB=$save_RANLIB - fi - test -z "$concat_cmds" || concat_cmds=$concat_cmds~ - eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" - objlist= - fi - done - RANLIB=$save_RANLIB - oldobjs=$objlist - if test "X$oldobjs" = "X" ; then - eval cmds=\"\$concat_cmds\" - else - eval cmds=\"\$concat_cmds~$old_archive_cmds\" - fi - fi - fi - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$generated"; then - $show "${rm}r$generated" - $run ${rm}r$generated - fi - - # Now create the libtool archive. - case $output in - *.la) - old_library= - test "$build_old_libs" = yes && old_library="$libname.$libext" - $show "creating $output" - - # Preserve any variables that may affect compiler behavior - for var in $variables_saved_for_relink; do - if eval test -z \"\${$var+set}\"; then - relink_command="{ test -z \"\${$var+set}\" || unset $var || { $var=; export $var; }; }; $relink_command" - elif eval var_value=\$$var; test -z "$var_value"; then - relink_command="$var=; export $var; $relink_command" - else - var_value=`$echo "X$var_value" | $Xsed -e "$sed_quote_subst"` - relink_command="$var=\"$var_value\"; export $var; $relink_command" - fi - done - # Quote the link command for shipping. - relink_command="(cd `pwd`; $SHELL $0 --mode=relink $libtool_args @inst_prefix_dir@)" - relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"` - if test "$hardcode_automatic" = yes ; then - relink_command= - fi - # Only create the output if not a dry run. - if test -z "$run"; then - for installed in no yes; do - if test "$installed" = yes; then - if test -z "$install_libdir"; then - break - fi - output="$output_objdir/$outputname"i - # Replace all uninstalled libtool libraries with the installed ones - newdependency_libs= - for deplib in $dependency_libs; do - case $deplib in - *.la) - name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` - if test -z "$libdir"; then - $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2 - exit 1 - fi - newdependency_libs="$newdependency_libs $libdir/$name" - ;; - *) newdependency_libs="$newdependency_libs $deplib" ;; - esac - done - dependency_libs="$newdependency_libs" - newdlfiles= - for lib in $dlfiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit 1 - fi - newdlfiles="$newdlfiles $libdir/$name" - done - dlfiles="$newdlfiles" - newdlprefiles= - for lib in $dlprefiles; do - name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'` - eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` - if test -z "$libdir"; then - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - exit 1 - fi - newdlprefiles="$newdlprefiles $libdir/$name" - done - dlprefiles="$newdlprefiles" - fi - $rm $output - # place dlname in correct position for cygwin - tdlname=$dlname - case $host,$output,$installed,$module,$dlname in - *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;; - esac - $echo > $output "\ -# $outputname - a libtool library file -# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP -# -# Please DO NOT delete this file! -# It is necessary for linking the library. - -# The name that we can dlopen(3). -dlname='$tdlname' - -# Names of this library. -library_names='$library_names' - -# The name of the static archive. -old_library='$old_library' - -# Libraries that this one depends upon. -dependency_libs='$dependency_libs' - -# Version information for $libname. -current=$current -age=$age -revision=$revision - -# Is this an already installed library? -installed=$installed - -# Should we warn about portability when linking against -modules? -shouldnotlink=$module - -# Files to dlopen/dlpreopen -dlopen='$dlfiles' -dlpreopen='$dlprefiles' - -# Directory that this library needs to be installed in: -libdir='$install_libdir'" - if test "$installed" = no && test "$need_relink" = yes && test "$fast_install" = no; then - $echo >> $output "\ -relink_command=\"$relink_command\"" - fi - done - fi - - # Do a symbolic link so that the libtool archive can be found in - # LD_LIBRARY_PATH before the program is installed. - $show "(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)" - $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $? - ;; - esac - exit 0 - ;; - - # libtool install mode - install) - modename="$modename: install" - - # There may be an optional sh(1) argument at the beginning of - # install_prog (especially on Windows NT). - if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || - # Allow the use of GNU shtool's install command. - $echo "X$nonopt" | $Xsed | grep shtool > /dev/null; then - # Aesthetically quote it. - arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*) - arg="\"$arg\"" - ;; - esac - install_prog="$arg " - arg="$1" - shift - else - install_prog= - arg="$nonopt" - fi - - # The real first argument should be the name of the installation program. - # Aesthetically quote it. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*) - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog$arg" - - # We need to accept at least all the BSD install flags. - dest= - files= - opts= - prev= - install_type= - isdir=no - stripme= - for arg - do - if test -n "$dest"; then - files="$files $dest" - dest="$arg" - continue - fi - - case $arg in - -d) isdir=yes ;; - -f) prev="-f" ;; - -g) prev="-g" ;; - -m) prev="-m" ;; - -o) prev="-o" ;; - -s) - stripme=" -s" - continue - ;; - -*) ;; - - *) - # If the previous option needed an argument, then skip it. - if test -n "$prev"; then - prev= - else - dest="$arg" - continue - fi - ;; - esac - - # Aesthetically quote the argument. - arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"` - case $arg in - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*) - arg="\"$arg\"" - ;; - esac - install_prog="$install_prog $arg" - done - - if test -z "$install_prog"; then - $echo "$modename: you must specify an install program" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - if test -n "$prev"; then - $echo "$modename: the \`$prev' option requires an argument" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - if test -z "$files"; then - if test -z "$dest"; then - $echo "$modename: no file or destination specified" 1>&2 - else - $echo "$modename: you must specify a destination" 1>&2 - fi - $echo "$help" 1>&2 - exit 1 - fi - - # Strip any trailing slash from the destination. - dest=`$echo "X$dest" | $Xsed -e 's%/$%%'` - - # Check to see that the destination is a directory. - test -d "$dest" && isdir=yes - if test "$isdir" = yes; then - destdir="$dest" - destname= - else - destdir=`$echo "X$dest" | $Xsed -e 's%/[^/]*$%%'` - test "X$destdir" = "X$dest" && destdir=. - destname=`$echo "X$dest" | $Xsed -e 's%^.*/%%'` - - # Not a directory, so check to see that there is only one file specified. - set dummy $files - if test "$#" -gt 2; then - $echo "$modename: \`$dest' is not a directory" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - fi - case $destdir in - [\\/]* | [A-Za-z]:[\\/]*) ;; - *) - for file in $files; do - case $file in - *.lo) ;; - *) - $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2 - $echo "$help" 1>&2 - exit 1 - ;; - esac - done - ;; - esac - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - staticlibs= - future_libdirs= - current_libdirs= - for file in $files; do - - # Do each installation. - case $file in - *.$libext) - # Do the static libraries later. - staticlibs="$staticlibs $file" - ;; - - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$file' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - library_names= - old_library= - relink_command= - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Add the libdir to current_libdirs if it is the destination. - if test "X$destdir" = "X$libdir"; then - case "$current_libdirs " in - *" $libdir "*) ;; - *) current_libdirs="$current_libdirs $libdir" ;; - esac - else - # Note the libdir as a future libdir. - case "$future_libdirs " in - *" $libdir "*) ;; - *) future_libdirs="$future_libdirs $libdir" ;; - esac - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`/ - test "X$dir" = "X$file/" && dir= - dir="$dir$objdir" - - if test -n "$relink_command"; then - # Determine the prefix the user has applied to our future dir. - inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"` - - # Don't allow the user to place us outside of our expected - # location b/c this prevents finding dependent libraries that - # are installed to the same prefix. - # At present, this check doesn't affect windows .dll's that - # are installed into $libdir/../bin (currently, that works fine) - # but it's something to keep an eye on. - if test "$inst_prefix_dir" = "$destdir"; then - $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2 - exit 1 - fi - - if test -n "$inst_prefix_dir"; then - # Stick the inst_prefix_dir data into the link command. - relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` - else - relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%%"` - fi - - $echo "$modename: warning: relinking \`$file'" 1>&2 - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - exit 1 - fi - fi - - # See the names of the shared library. - set dummy $library_names - if test -n "$2"; then - realname="$2" - shift - shift - - srcname="$realname" - test -n "$relink_command" && srcname="$realname"T - - # Install the shared library and build the symlinks. - $show "$install_prog $dir/$srcname $destdir/$realname" - $run eval "$install_prog $dir/$srcname $destdir/$realname" || exit $? - if test -n "$stripme" && test -n "$striplib"; then - $show "$striplib $destdir/$realname" - $run eval "$striplib $destdir/$realname" || exit $? - fi - - if test "$#" -gt 0; then - # Delete the old symlinks, and create new ones. - for linkname - do - if test "$linkname" != "$realname"; then - $show "(cd $destdir && $rm $linkname && $LN_S $realname $linkname)" - $run eval "(cd $destdir && $rm $linkname && $LN_S $realname $linkname)" - fi - done - fi - - # Do each command in the postinstall commands. - lib="$destdir/$realname" - eval cmds=\"$postinstall_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - fi - - # Install the pseudo-library for information purposes. - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - instname="$dir/$name"i - $show "$install_prog $instname $destdir/$name" - $run eval "$install_prog $instname $destdir/$name" || exit $? - - # Maybe install the static library, too. - test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library" - ;; - - *.lo) - # Install (i.e. copy) a libtool object. - - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # Deduce the name of the destination old-style object file. - case $destfile in - *.lo) - staticdest=`$echo "X$destfile" | $Xsed -e "$lo2o"` - ;; - *.$objext) - staticdest="$destfile" - destfile= - ;; - *) - $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2 - $echo "$help" 1>&2 - exit 1 - ;; - esac - - # Install the libtool object if requested. - if test -n "$destfile"; then - $show "$install_prog $file $destfile" - $run eval "$install_prog $file $destfile" || exit $? - fi - - # Install the old object if enabled. - if test "$build_old_libs" = yes; then - # Deduce the name of the old-style object file. - staticobj=`$echo "X$file" | $Xsed -e "$lo2o"` - - $show "$install_prog $staticobj $staticdest" - $run eval "$install_prog \$staticobj \$staticdest" || exit $? - fi - exit 0 - ;; - - *) - # Figure out destination file name, if it wasn't already specified. - if test -n "$destname"; then - destfile="$destdir/$destname" - else - destfile=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - destfile="$destdir/$destfile" - fi - - # If the file is missing, and there is a .exe on the end, strip it - # because it is most likely a libtool script we actually want to - # install - stripped_ext="" - case $file in - *.exe) - if test ! -f "$file"; then - file=`$echo $file|${SED} 's,.exe$,,'` - stripped_ext=".exe" - fi - ;; - esac - - # Do a test to see if this is really a libtool program. - case $host in - *cygwin*|*mingw*) - wrapper=`$echo $file | ${SED} -e 's,.exe$,,'` - ;; - *) - wrapper=$file - ;; - esac - if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then - notinst_deplibs= - relink_command= - - # To insure that "foo" is sourced, and not "foo.exe", - # finese the cygwin/MSYS system by explicitly sourcing "foo." - # which disallows the automatic-append-.exe behavior. - case $build in - *cygwin* | *mingw*) wrapperdot=${wrapper}. ;; - *) wrapperdot=${wrapper} ;; - esac - # If there is no directory component, then add one. - case $file in - */* | *\\*) . ${wrapperdot} ;; - *) . ./${wrapperdot} ;; - esac - - # Check the variables that should have been set. - if test -z "$notinst_deplibs"; then - $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2 - exit 1 - fi - - finalize=yes - for lib in $notinst_deplibs; do - # Check to see that each library is installed. - libdir= - if test -f "$lib"; then - # If there is no directory component, then add one. - case $lib in - */* | *\\*) . $lib ;; - *) . ./$lib ;; - esac - fi - libfile="$libdir/"`$echo "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test - if test -n "$libdir" && test ! -f "$libfile"; then - $echo "$modename: warning: \`$lib' has not been installed in \`$libdir'" 1>&2 - finalize=no - fi - done - - relink_command= - # To insure that "foo" is sourced, and not "foo.exe", - # finese the cygwin/MSYS system by explicitly sourcing "foo." - # which disallows the automatic-append-.exe behavior. - case $build in - *cygwin* | *mingw*) wrapperdot=${wrapper}. ;; - *) wrapperdot=${wrapper} ;; - esac - # If there is no directory component, then add one. - case $file in - */* | *\\*) . ${wrapperdot} ;; - *) . ./${wrapperdot} ;; - esac - - outputname= - if test "$fast_install" = no && test -n "$relink_command"; then - if test "$finalize" = yes && test -z "$run"; then - tmpdir="/tmp" - test -n "$TMPDIR" && tmpdir="$TMPDIR" - tmpdir="$tmpdir/libtool-$$" - if $mkdir -p "$tmpdir" && chmod 700 "$tmpdir"; then : - else - $echo "$modename: error: cannot create temporary directory \`$tmpdir'" 1>&2 - continue - fi - file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'` - outputname="$tmpdir/$file" - # Replace the output file specification. - relink_command=`$echo "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'` - - $show "$relink_command" - if $run eval "$relink_command"; then : - else - $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2 - ${rm}r "$tmpdir" - continue - fi - file="$outputname" - else - $echo "$modename: warning: cannot relink \`$file'" 1>&2 - fi - else - # Install the binary that we compiled earlier. - file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"` - fi - fi - - # remove .exe since cygwin /usr/bin/install will append another - # one anyways - case $install_prog,$host in - */usr/bin/install*,*cygwin*) - case $file:$destfile in - *.exe:*.exe) - # this is ok - ;; - *.exe:*) - destfile=$destfile.exe - ;; - *:*.exe) - destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'` - ;; - esac - ;; - esac - $show "$install_prog$stripme $file $destfile" - $run eval "$install_prog\$stripme \$file \$destfile" || exit $? - test -n "$outputname" && ${rm}r "$tmpdir" - ;; - esac - done - - for file in $staticlibs; do - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - - # Set up the ranlib parameters. - oldlib="$destdir/$name" - - $show "$install_prog $file $oldlib" - $run eval "$install_prog \$file \$oldlib" || exit $? - - if test -n "$stripme" && test -n "$striplib"; then - $show "$old_striplib $oldlib" - $run eval "$old_striplib $oldlib" || exit $? - fi - - # Do each command in the postinstall commands. - eval cmds=\"$old_postinstall_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || exit $? - done - IFS="$save_ifs" - done - - if test -n "$future_libdirs"; then - $echo "$modename: warning: remember to run \`$progname --finish$future_libdirs'" 1>&2 - fi - - if test -n "$current_libdirs"; then - # Maybe just do a dry run. - test -n "$run" && current_libdirs=" -n$current_libdirs" - exec_cmd='$SHELL $0 --finish$current_libdirs' - else - exit 0 - fi - ;; - - # libtool finish mode - finish) - modename="$modename: finish" - libdirs="$nonopt" - admincmds= - - if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then - for dir - do - libdirs="$libdirs $dir" - done - - for libdir in $libdirs; do - if test -n "$finish_cmds"; then - # Do each command in the finish commands. - eval cmds=\"$finish_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" || admincmds="$admincmds - $cmd" - done - IFS="$save_ifs" - fi - if test -n "$finish_eval"; then - # Do the single finish_eval. - eval cmds=\"$finish_eval\" - $run eval "$cmds" || admincmds="$admincmds - $cmds" - fi - done - fi - - # Exit here if they wanted silent mode. - exit 0 - - $echo "----------------------------------------------------------------------" - $echo "Libraries have been installed in:" - for libdir in $libdirs; do - $echo " $libdir" - done - $echo - $echo "If you ever happen to want to link against installed libraries" - $echo "in a given directory, LIBDIR, you must either use libtool, and" - $echo "specify the full pathname of the library, or use the \`-LLIBDIR'" - $echo "flag during linking and do at least one of the following:" - if test -n "$shlibpath_var"; then - $echo " - add LIBDIR to the \`$shlibpath_var' environment variable" - $echo " during execution" - fi - if test -n "$runpath_var"; then - $echo " - add LIBDIR to the \`$runpath_var' environment variable" - $echo " during linking" - fi - if test -n "$hardcode_libdir_flag_spec"; then - libdir=LIBDIR - eval flag=\"$hardcode_libdir_flag_spec\" - - $echo " - use the \`$flag' linker flag" - fi - if test -n "$admincmds"; then - $echo " - have your system administrator run these commands:$admincmds" - fi - if test -f /etc/ld.so.conf; then - $echo " - have your system administrator add LIBDIR to \`/etc/ld.so.conf'" - fi - $echo - $echo "See any operating system documentation about shared libraries for" - $echo "more information, such as the ld(1) and ld.so(8) manual pages." - $echo "----------------------------------------------------------------------" - exit 0 - ;; - - # libtool execute mode - execute) - modename="$modename: execute" - - # The first argument is the command name. - cmd="$nonopt" - if test -z "$cmd"; then - $echo "$modename: you must specify a COMMAND" 1>&2 - $echo "$help" - exit 1 - fi - - # Handle -dlopen flags immediately. - for file in $execute_dlfiles; do - if test ! -f "$file"; then - $echo "$modename: \`$file' is not a file" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - dir= - case $file in - *.la) - # Check to see that this really is a libtool archive. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then : - else - $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - # Read the libtool library. - dlname= - library_names= - - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Skip this library if it cannot be dlopened. - if test -z "$dlname"; then - # Warn if it was a shared library. - test -n "$library_names" && $echo "$modename: warning: \`$file' was not linked with \`-export-dynamic'" - continue - fi - - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - - if test -f "$dir/$objdir/$dlname"; then - dir="$dir/$objdir" - else - $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2 - exit 1 - fi - ;; - - *.lo) - # Just add the directory containing the .lo file. - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - test "X$dir" = "X$file" && dir=. - ;; - - *) - $echo "$modename: warning \`-dlopen' is ignored for non-libtool libraries and objects" 1>&2 - continue - ;; - esac - - # Get the absolute pathname. - absdir=`cd "$dir" && pwd` - test -n "$absdir" && dir="$absdir" - - # Now add the directory to shlibpath_var. - if eval "test -z \"\$$shlibpath_var\""; then - eval "$shlibpath_var=\"\$dir\"" - else - eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" - fi - done - - # This variable tells wrapper scripts just to set shlibpath_var - # rather than running their programs. - libtool_execute_magic="$magic" - - # Check if any of the arguments is a wrapper script. - args= - for file - do - case $file in - -*) ;; - *) - # Do a test to see if this is really a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - # If there is no directory component, then add one. - case $file in - */* | *\\*) . $file ;; - *) . ./$file ;; - esac - - # Transform arg to wrapped name. - file="$progdir/$program" - fi - ;; - esac - # Quote arguments (to preserve shell metacharacters). - file=`$echo "X$file" | $Xsed -e "$sed_quote_subst"` - args="$args \"$file\"" - done - - if test -z "$run"; then - if test -n "$shlibpath_var"; then - # Export the shlibpath_var. - eval "export $shlibpath_var" - fi - - # Restore saved environment variables - if test "${save_LC_ALL+set}" = set; then - LC_ALL="$save_LC_ALL"; export LC_ALL - fi - if test "${save_LANG+set}" = set; then - LANG="$save_LANG"; export LANG - fi - - # Now prepare to actually exec the command. - exec_cmd="\$cmd$args" - else - # Display what would be done. - if test -n "$shlibpath_var"; then - eval "\$echo \"\$shlibpath_var=\$$shlibpath_var\"" - $echo "export $shlibpath_var" - fi - $echo "$cmd$args" - exit 0 - fi - ;; - - # libtool clean and uninstall mode - clean | uninstall) - modename="$modename: $mode" - rm="$nonopt" - files= - rmforce= - exit_status=0 - - # This variable tells wrapper scripts just to set variables rather - # than running their programs. - libtool_install_magic="$magic" - - for arg - do - case $arg in - -f) rm="$rm $arg"; rmforce=yes ;; - -*) rm="$rm $arg" ;; - *) files="$files $arg" ;; - esac - done - - if test -z "$rm"; then - $echo "$modename: you must specify an RM program" 1>&2 - $echo "$help" 1>&2 - exit 1 - fi - - rmdirs= - - origobjdir="$objdir" - for file in $files; do - dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'` - if test "X$dir" = "X$file"; then - dir=. - objdir="$origobjdir" - else - objdir="$dir/$origobjdir" - fi - name=`$echo "X$file" | $Xsed -e 's%^.*/%%'` - test "$mode" = uninstall && objdir="$dir" - - # Remember objdir for removal later, being careful to avoid duplicates - if test "$mode" = clean; then - case " $rmdirs " in - *" $objdir "*) ;; - *) rmdirs="$rmdirs $objdir" ;; - esac - fi - - # Don't error if the file doesn't exist and rm -f was used. - if (test -L "$file") >/dev/null 2>&1 \ - || (test -h "$file") >/dev/null 2>&1 \ - || test -f "$file"; then - : - elif test -d "$file"; then - exit_status=1 - continue - elif test "$rmforce" = yes; then - continue - fi - - rmfiles="$file" - - case $name in - *.la) - # Possibly a libtool archive, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - . $dir/$name - - # Delete the libtool libraries and symlinks. - for n in $library_names; do - rmfiles="$rmfiles $objdir/$n" - done - test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library" - test "$mode" = clean && rmfiles="$rmfiles $objdir/$name $objdir/${name}i" - - if test "$mode" = uninstall; then - if test -n "$library_names"; then - # Do each command in the postuninstall commands. - eval cmds=\"$postuninstall_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - - if test -n "$old_library"; then - # Do each command in the old_postuninstall commands. - eval cmds=\"$old_postuninstall_cmds\" - save_ifs="$IFS"; IFS='~' - for cmd in $cmds; do - IFS="$save_ifs" - $show "$cmd" - $run eval "$cmd" - if test "$?" -ne 0 && test "$rmforce" != yes; then - exit_status=1 - fi - done - IFS="$save_ifs" - fi - # FIXME: should reinstall the best remaining shared library. - fi - fi - ;; - - *.lo) - # Possibly a libtool object, so verify it. - if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - - # Read the .lo file - . $dir/$name - - # Add PIC object to the list of files to remove. - if test -n "$pic_object" \ - && test "$pic_object" != none; then - rmfiles="$rmfiles $dir/$pic_object" - fi - - # Add non-PIC object to the list of files to remove. - if test -n "$non_pic_object" \ - && test "$non_pic_object" != none; then - rmfiles="$rmfiles $dir/$non_pic_object" - fi - fi - ;; - - *) - if test "$mode" = clean ; then - noexename=$name - case $file in - *.exe) - file=`$echo $file|${SED} 's,.exe$,,'` - noexename=`$echo $name|${SED} 's,.exe$,,'` - # $file with .exe has already been added to rmfiles, - # add $file without .exe - rmfiles="$rmfiles $file" - ;; - esac - # Do a test to see if this is a libtool program. - if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then - relink_command= - . $dir/$noexename - - # note $name still contains .exe if it was in $file originally - # as does the version of $file that was added into $rmfiles - rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}" - if test "$fast_install" = yes && test -n "$relink_command"; then - rmfiles="$rmfiles $objdir/lt-$name" - fi - if test "X$noexename" != "X$name" ; then - rmfiles="$rmfiles $objdir/lt-${noexename}.c" - fi - fi - fi - ;; - esac - $show "$rm $rmfiles" - $run $rm $rmfiles || exit_status=1 - done - objdir="$origobjdir" - - # Try to remove the ${objdir}s in the directories where we deleted files - for dir in $rmdirs; do - if test -d "$dir"; then - $show "rmdir $dir" - $run rmdir $dir >/dev/null 2>&1 - fi - done - - exit $exit_status - ;; - - "") - $echo "$modename: you must specify a MODE" 1>&2 - $echo "$generic_help" 1>&2 - exit 1 - ;; - esac - - if test -z "$exec_cmd"; then - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$generic_help" 1>&2 - exit 1 - fi -fi # test -z "$show_help" - -if test -n "$exec_cmd"; then - eval exec $exec_cmd - exit 1 -fi - -# We need to display help for each of the modes. -case $mode in -"") $echo \ -"Usage: $modename [OPTION]... [MODE-ARG]... - -Provide generalized library-building support services. - - --config show all configuration variables - --debug enable verbose shell tracing --n, --dry-run display commands without modifying any files - --features display basic configuration information and exit - --finish same as \`--mode=finish' - --help display this help message and exit - --mode=MODE use operation mode MODE [default=inferred from MODE-ARGS] - --quiet same as \`--silent' - --silent don't print informational messages - --tag=TAG use configuration variables from tag TAG - --version print version information - -MODE must be one of the following: - - clean remove files from the build directory - compile compile a source file into a libtool object - execute automatically set library path, then run a program - finish complete the installation of libtool libraries - install install libraries or executables - link create a library or an executable - uninstall remove libraries from an installed directory - -MODE-ARGS vary depending on the MODE. Try \`$modename --help --mode=MODE' for -a more detailed description of MODE. - -Report bugs to ." - exit 0 - ;; - -clean) - $echo \ -"Usage: $modename [OPTION]... --mode=clean RM [RM-OPTION]... FILE... - -Remove files from the build directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, object or program, all the files associated -with it are deleted. Otherwise, only FILE itself is deleted using RM." - ;; - -compile) - $echo \ -"Usage: $modename [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE - -Compile a source file into a libtool library object. - -This mode accepts the following additional options: - - -o OUTPUT-FILE set the output file name to OUTPUT-FILE - -prefer-pic try to building PIC objects only - -prefer-non-pic try to building non-PIC objects only - -static always build a \`.o' file suitable for static linking - -COMPILE-COMMAND is a command to be used in creating a \`standard' object file -from the given SOURCEFILE. - -The output file name is determined by removing the directory component from -SOURCEFILE, then substituting the C source code suffix \`.c' with the -library object suffix, \`.lo'." - ;; - -execute) - $echo \ -"Usage: $modename [OPTION]... --mode=execute COMMAND [ARGS]... - -Automatically set library path, then run a program. - -This mode accepts the following additional options: - - -dlopen FILE add the directory containing FILE to the library path - -This mode sets the library path environment variable according to \`-dlopen' -flags. - -If any of the ARGS are libtool executable wrappers, then they are translated -into their corresponding uninstalled binary, and any of their required library -directories are added to the library path. - -Then, COMMAND is executed, with ARGS as arguments." - ;; - -finish) - $echo \ -"Usage: $modename [OPTION]... --mode=finish [LIBDIR]... - -Complete the installation of libtool libraries. - -Each LIBDIR is a directory that contains libtool libraries. - -The commands that this mode executes may require superuser privileges. Use -the \`--dry-run' option if you just want to see what would be executed." - ;; - -install) - $echo \ -"Usage: $modename [OPTION]... --mode=install INSTALL-COMMAND... - -Install executables or libraries. - -INSTALL-COMMAND is the installation command. The first component should be -either the \`install' or \`cp' program. - -The rest of the components are interpreted as arguments to that command (only -BSD-compatible install options are recognized)." - ;; - -link) - $echo \ -"Usage: $modename [OPTION]... --mode=link LINK-COMMAND... - -Link object files or libraries together to form another library, or to -create an executable program. - -LINK-COMMAND is a command using the C compiler that you would use to create -a program from several object files. - -The following components of LINK-COMMAND are treated specially: - - -all-static do not do any dynamic linking at all - -avoid-version do not add a version suffix if possible - -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime - -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols - -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) - -export-symbols SYMFILE - try to export only the symbols listed in SYMFILE - -export-symbols-regex REGEX - try to export only the symbols matching REGEX - -LLIBDIR search LIBDIR for required installed libraries - -lNAME OUTPUT-FILE requires the installed library libNAME - -module build a library that can dlopened - -no-fast-install disable the fast-install mode - -no-install link a not-installable executable - -no-undefined declare that a library does not refer to external symbols - -o OUTPUT-FILE create OUTPUT-FILE from the specified objects - -objectlist FILE Use a list of object files found in FILE to specify objects - -release RELEASE specify package release information - -rpath LIBDIR the created library will eventually be installed in LIBDIR - -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries - -static do not do any dynamic linking of libtool libraries - -version-info CURRENT[:REVISION[:AGE]] - specify library version info [each variable defaults to 0] - -All other options (arguments beginning with \`-') are ignored. - -Every other argument is treated as a filename. Files ending in \`.la' are -treated as uninstalled libtool libraries, other files are standard or library -object files. - -If the OUTPUT-FILE ends in \`.la', then a libtool library is created, -only library objects (\`.lo' files) may be specified, and \`-rpath' is -required, except when creating a convenience library. - -If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created -using \`ar' and \`ranlib', or on Windows using \`lib'. - -If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file -is created, otherwise an executable program is created." - ;; - -uninstall) - $echo \ -"Usage: $modename [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... - -Remove libraries from an installation directory. - -RM is the name of the program to use to delete files associated with each FILE -(typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed -to RM. - -If FILE is a libtool library, all the files associated with it are deleted. -Otherwise, only FILE itself is deleted using RM." - ;; - -*) - $echo "$modename: invalid operation mode \`$mode'" 1>&2 - $echo "$help" 1>&2 - exit 1 - ;; -esac - -$echo -$echo "Try \`$modename --help' for more information about other modes." - -exit 0 - -# The TAGs below are defined such that we never get into a situation -# in which we disable both kinds of libraries. Given conflicting -# choices, we go for a static library, that is the most portable, -# since we can't tell whether shared libraries were disabled because -# the user asked for that or because the platform doesn't support -# them. This is particularly important on AIX, because we don't -# support having both static and shared libraries enabled at the same -# time on that platform, so we default to a shared-only configuration. -# If a disable-shared tag is given, we'll fallback to a static-only -# configuration. But we'll never go from static-only to shared-only. - -# ### BEGIN LIBTOOL TAG CONFIG: disable-shared -build_libtool_libs=no -build_old_libs=yes -# ### END LIBTOOL TAG CONFIG: disable-shared - -# ### BEGIN LIBTOOL TAG CONFIG: disable-static -build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac` -# ### END LIBTOOL TAG CONFIG: disable-static - -# Local Variables: -# mode:shell-script -# sh-indentation:2 -# End: Index: ext/libicpf/missing =================================================================== diff -u -N --- ext/libicpf/missing (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/missing (revision 0) @@ -1,336 +0,0 @@ -#! /bin/sh -# Common stub for a few missing GNU programs while installing. -# Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. -# Originally by Fran,cois Pinard , 1996. - -# 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 to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -if test $# -eq 0; then - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 -fi - -run=: - -# In the cases where this matters, `missing' is being run in the -# srcdir already. -if test -f configure.ac; then - configure_ac=configure.ac -else - configure_ac=configure.in -fi - -case "$1" in ---run) - # Try to run requested program, and just exit if it succeeds. - run= - shift - "$@" && exit 0 - ;; -esac - -# If it does not exist, or fails to run (possibly an outdated version), -# try to emulate it. -case "$1" in - - -h|--h|--he|--hel|--help) - echo "\ -$0 [OPTION]... PROGRAM [ARGUMENT]... - -Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an -error status if there is no known handling for PROGRAM. - -Options: - -h, --help display this help and exit - -v, --version output version information and exit - --run try to run the given command, and emulate it if it fails - -Supported PROGRAM values: - aclocal touch file \`aclocal.m4' - autoconf touch file \`configure' - autoheader touch file \`config.h.in' - automake touch all \`Makefile.in' files - bison create \`y.tab.[ch]', if possible, from existing .[ch] - flex create \`lex.yy.c', if possible, from existing .c - help2man touch the output file - lex create \`lex.yy.c', if possible, from existing .c - makeinfo touch the output file - tar try tar, gnutar, gtar, then tar without non-portable flags - yacc create \`y.tab.[ch]', if possible, from existing .[ch]" - ;; - - -v|--v|--ve|--ver|--vers|--versi|--versio|--version) - echo "missing 0.4 - GNU automake" - ;; - - -*) - echo 1>&2 "$0: Unknown \`$1' option" - echo 1>&2 "Try \`$0 --help' for more information" - exit 1 - ;; - - aclocal*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acinclude.m4' or \`${configure_ac}'. You might want - to install the \`Automake' and \`Perl' packages. Grab them from - any GNU archive site." - touch aclocal.m4 - ;; - - autoconf) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`${configure_ac}'. You might want to install the - \`Autoconf' and \`GNU m4' packages. Grab them from any GNU - archive site." - touch configure - ;; - - autoheader) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`acconfig.h' or \`${configure_ac}'. You might want - to install the \`Autoconf' and \`GNU m4' packages. Grab them - from any GNU archive site." - files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` - test -z "$files" && files="config.h" - touch_files= - for f in $files; do - case "$f" in - *:*) touch_files="$touch_files "`echo "$f" | - sed -e 's/^[^:]*://' -e 's/:.*//'`;; - *) touch_files="$touch_files $f.in";; - esac - done - touch $touch_files - ;; - - automake*) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. - You might want to install the \`Automake' and \`Perl' packages. - Grab them from any GNU archive site." - find . -type f -name Makefile.am -print | - sed 's/\.am$/.in/' | - while read f; do touch "$f"; done - ;; - - autom4te) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the - proper tools for further handling them. - You can get \`$1Help2man' as part of \`Autoconf' from any GNU - archive site." - - file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` - test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` - if test -f "$file"; then - touch $file - else - test -z "$file" || exec >$file - echo "#! /bin/sh" - echo "# Created by GNU Automake missing as a replacement of" - echo "# $ $@" - echo "exit 0" - chmod +x $file - exit 1 - fi - ;; - - bison|yacc) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.y' file. You may need the \`Bison' package - in order for those modifications to take effect. You can get - \`Bison' from any GNU archive site." - rm -f y.tab.c y.tab.h - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.y) - SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.c - fi - SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" y.tab.h - fi - ;; - esac - fi - if [ ! -f y.tab.h ]; then - echo >y.tab.h - fi - if [ ! -f y.tab.c ]; then - echo 'main() { return 0; }' >y.tab.c - fi - ;; - - lex|flex) - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.l' file. You may need the \`Flex' package - in order for those modifications to take effect. You can get - \`Flex' from any GNU archive site." - rm -f lex.yy.c - if [ $# -ne 1 ]; then - eval LASTARG="\${$#}" - case "$LASTARG" in - *.l) - SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` - if [ -f "$SRCFILE" ]; then - cp "$SRCFILE" lex.yy.c - fi - ;; - esac - fi - if [ ! -f lex.yy.c ]; then - echo 'main() { return 0; }' >lex.yy.c - fi - ;; - - help2man) - if test -z "$run" && ($1 --version) > /dev/null 2>&1; then - # We have it, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a dependency of a manual page. You may need the - \`Help2man' package in order for those modifications to take - effect. You can get \`Help2man' from any GNU archive site." - - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` - fi - if [ -f "$file" ]; then - touch $file - else - test -z "$file" || exec >$file - echo ".ab help2man is required to generate this page" - exit 1 - fi - ;; - - makeinfo) - if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then - # We have makeinfo, but it failed. - exit 1 - fi - - echo 1>&2 "\ -WARNING: \`$1' is missing on your system. You should only need it if - you modified a \`.texi' or \`.texinfo' file, or any other file - indirectly affecting the aspect of the manual. The spurious - call might also be the consequence of using a buggy \`make' (AIX, - DU, IRIX). You might want to install the \`Texinfo' package or - the \`GNU make' package. Grab either from any GNU archive site." - file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` - if test -z "$file"; then - file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` - file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` - fi - touch $file - ;; - - tar) - shift - if test -n "$run"; then - echo 1>&2 "ERROR: \`tar' requires --run" - exit 1 - fi - - # We have already tried tar in the generic part. - # Look for gnutar/gtar before invocation to avoid ugly error - # messages. - if (gnutar --version > /dev/null 2>&1); then - gnutar "$@" && exit 0 - fi - if (gtar --version > /dev/null 2>&1); then - gtar "$@" && exit 0 - fi - firstarg="$1" - if shift; then - case "$firstarg" in - *o*) - firstarg=`echo "$firstarg" | sed s/o//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - case "$firstarg" in - *h*) - firstarg=`echo "$firstarg" | sed s/h//` - tar "$firstarg" "$@" && exit 0 - ;; - esac - fi - - echo 1>&2 "\ -WARNING: I can't seem to be able to run \`tar' with the given arguments. - You may want to install GNU tar or Free paxutils, or check the - command line arguments." - exit 1 - ;; - - *) - echo 1>&2 "\ -WARNING: \`$1' is needed, and you do not seem to have it handy on your - system. You might have modified some files without having the - proper tools for further handling them. Check the \`README' file, - it often tells you about the needed prerequirements for installing - this package. You may also peek at any GNU archive site, in case - some other package would contain this missing \`$1' program." - exit 1 - ;; -esac - -exit 0 Index: ext/libicpf/mkinstalldirs =================================================================== diff -u -N --- ext/libicpf/mkinstalldirs (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/mkinstalldirs (revision 0) @@ -1,111 +0,0 @@ -#! /bin/sh -# mkinstalldirs --- make directory hierarchy -# Author: Noah Friedman -# Created: 1993-05-16 -# Public domain - -errstatus=0 -dirmode="" - -usage="\ -Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." - -# process command line arguments -while test $# -gt 0 ; do - case $1 in - -h | --help | --h*) # -h for help - echo "$usage" 1>&2 - exit 0 - ;; - -m) # -m PERM arg - shift - test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } - dirmode=$1 - shift - ;; - --) # stop option processing - shift - break - ;; - -*) # unknown option - echo "$usage" 1>&2 - exit 1 - ;; - *) # first non-opt arg - break - ;; - esac -done - -for file -do - if test -d "$file"; then - shift - else - break - fi -done - -case $# in - 0) exit 0 ;; -esac - -case $dirmode in - '') - if mkdir -p -- . 2>/dev/null; then - echo "mkdir -p -- $*" - exec mkdir -p -- "$@" - fi - ;; - *) - if mkdir -m "$dirmode" -p -- . 2>/dev/null; then - echo "mkdir -m $dirmode -p -- $*" - exec mkdir -m "$dirmode" -p -- "$@" - fi - ;; -esac - -for file -do - set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` - shift - - pathcomp= - for d - do - pathcomp="$pathcomp$d" - case $pathcomp in - -*) pathcomp=./$pathcomp ;; - esac - - if test ! -d "$pathcomp"; then - echo "mkdir $pathcomp" - - mkdir "$pathcomp" || lasterr=$? - - if test ! -d "$pathcomp"; then - errstatus=$lasterr - else - if test ! -z "$dirmode"; then - echo "chmod $dirmode $pathcomp" - lasterr="" - chmod "$dirmode" "$pathcomp" || lasterr=$? - - if test ! -z "$lasterr"; then - errstatus=$lasterr - fi - fi - fi - fi - - pathcomp="$pathcomp/" - done -done - -exit $errstatus - -# Local Variables: -# mode: shell-script -# sh-indentation: 2 -# End: -# mkinstalldirs ends here Index: ext/libicpf/scripts/check_icpf.m4 =================================================================== diff -u -N --- ext/libicpf/scripts/check_icpf.m4 (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/scripts/check_icpf.m4 (revision 0) @@ -1,74 +0,0 @@ -dnl @synopsis CT_CHECK_ICPF -dnl -dnl This macro tries to find the headers and libraries for the -dnl icpf library. -dnl -dnl If includes are found, the variable ICPFINCPATH will be set. If -dnl librarys are found, the variable ICPFLIBPATH will be set. if no check -dnl was successful, the script exits with a error message. -dnl -dnl @category InstalledPackages -dnl @author Ixen Gerthannes, heavily based on CT_CHECK_POSTGRES_DB by Christian Toepp -dnl @version 2005-07-25 -dnl @license AllPermissive - -AC_DEFUN([CT_CHECK_ICPF], [ - -AC_ARG_WITH(libicpf, - [ --with-libicpf=PREFIX Prefix of your libicpf installation], - [icpf_prefix=$withval], [icpf_prefix=]) -AC_ARG_WITH(libicpf-inc, - [ --with-libicpf-inc=PATH Path to the include directory of libicpf], - [icpf_inc=$withval], [icpf_inc=]) -AC_ARG_WITH(libicpf-lib, - [ --with-libicpf-lib=PATH Path to the library of libicpf], - [icpf_lib=$withval], [icpf_lib=]) - - -AC_SUBST(ICPFINCPATH) -AC_SUBST(ICPFLIBPATH) - -if test "$icpf_prefix" != ""; then - AC_MSG_CHECKING([for libicpf includes in $icpf_prefix/include]) - if test -f "$icpf_prefix/include/libicpf.h" ; then - ICPFINCPATH="-I$icpf_prefix/include" - AC_MSG_RESULT([yes]) - else - AC_MSG_ERROR(libicpf.h not found) - fi - AC_MSG_CHECKING([for libicpf library in $icpf_prefix/lib]) - if test -f "$icpf_prefix/lib/libicpf.a" ; then - ICPFLIBPATH="-L$icpf_prefix/lib" - AC_MSG_RESULT([yes]) - else - AC_MSG_ERROR(libicpf.a not found) - fi -else - if test "$icpf_inc" != ""; then - AC_MSG_CHECKING([for libicpf includes in $icpf_inc]) - if test -f "$icpf_inc/libicpf.h" ; then - ICPFINCPATH="-I$icpf_inc" - AC_MSG_RESULT([yes]) - else - AC_MSG_ERROR(libicpf.h not found) - fi - fi - if test "$icpf_lib" != ""; then - AC_MSG_CHECKING([for libicpf library in $icpf_lib]) - if test -f "$icpf_lib/libicpf.a" ; then - ICPFLIBPATH="-L$icpf_lib" - AC_MSG_RESULT([yes]) - else - AC_MSG_ERROR(libicpf.a not found) - fi - fi -fi - -if test "$ICPFINCPATH" = "" ; then - AC_CHECK_HEADER([libicpf.h], [], AC_MSG_ERROR(libicpf.h not found)) -fi -if test "$ICPFLIBPATH" = "" ; then - AC_MSG_ERROR(libicpf.a not found) -fi - -]) Index: ext/libicpf/src/Makefile.am =================================================================== diff -u -N --- ext/libicpf/src/Makefile.am (revision b337c059691a6940b52a86388ff427c734be8eb6) +++ ext/libicpf/src/Makefile.am (revision 0) @@ -1,5 +0,0 @@ -# not a GNU package. You can remove this line, if -# have all needed files, that a GNU package needs -AUTOMAKE_OPTIONS = foreign 1.4 - -SUBDIRS = libicpf libicpf-tests Index: ext/libicpf/src/libicpf-tests/config-test.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/config-test.cpp (revision 3e456be345c9b341a4411091589ddd43e7afd114) +++ ext/libicpf/src/libicpf-tests/config-test.cpp (revision 0) @@ -1,72 +0,0 @@ -#include "config-test.h" -#include "cfg.h" -#include "cfg_xml.h" -#include "exception.h" -#include - -void ConfigTest::Run() -{ - const ll_t llVal=-23524; - const ull_t ullVal=3445; - const bool bVal=true; - const tchar_t* pszVal=_t("��ka �wieci jak mo�e"); - - // generate temporary file name - tchar_t* pszName=_ttmpnam(NULL); - if (!pszName) - THROW(_t("Cannot generate the temporary file name"), 0, 0, 0); - tstring_t strPath(_t(".")); - strPath+=pszName; - strPath+=_t("cfg"); - - // start with testing cfg class -/* - icpf::xml_cfg cfgXml; - icpf::config cfg(&cfgXml); - - ReportS(_t("Registering properties...\n")); - - uint_t auiID[4]; - auiID[0]=cfg.register_signed_num(_t("test/TestSignedNum00"), 320, -23524, 640); - auiID[1]=cfg.register_unsigned_num(_t("test/moo/TestUnsignedNum01"), 0, 0, 9999999); - auiID[2]=cfg.register_bool(_t("test/TestBool02"), false); - auiID[3]=cfg.register_string(_t("test/TestString03"), _t("none")); - - ReportS(_t("Setting values...\n")); - - cfg.set_signed_num(auiID[0], llVal); - cfg.set_unsigned_num(auiID[1], ullVal); - cfg.set_bool(auiID[2], bVal); - cfg.set_string(auiID[3], pszVal); - - ReportS(_t("Retrieving and comparing values...\n")); - if (cfg.get_signed_num(auiID[0]) != llVal) - THROW(_t("Comparing signed number values failed"), 0, 0, 0); - if (cfg.get_unsigned_num(auiID[1]) != ullVal) - THROW(_t("Comparing unsigned number values failed"), 0, 0, 0); - if (cfg.get_bool(auiID[2]) != bVal) - THROW(_t("Comparing bool values failed"), 0, 0, 0); - if (tstring_t(cfg.get_string(auiID[3])) != tstring_t(pszVal)) - THROW(_t("Comparing string values failed"), 0, 0, 0); - - // store values in the file - Report(_t("Storing properties in the file '") TSTRFMT _t("'\n"), strPath.c_str()); - cfg.write(strPath.c_str()); - - // read stored values - Report(_t("Reading properties from the file '") TSTRFMT _t("'\n"), strPath.c_str()); - cfg.read(strPath.c_str()); - - tstring_t strFile2; - pszName=_ttmpnam(NULL); - if(!pszName) - THROW(_t("Cannot generate the temporary file name"), 0, 0, 0); - tstring_t strPath2(_t(".")); - strPath2 += pszName; - strPath += _t("cfg"); - - Report(_t("Storing properties in the file '") TSTRFMT _t("'\n"), strPath2.c_str()); - cfg.write(strPath2.c_str());*/ - - ReportS(_t("Test finished.\n")); -} Index: ext/libicpf/src/libicpf-tests/config-test.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/config-test.h (revision 1504b5e9af0cbbc688765c3530ee3443cb04fc01) +++ ext/libicpf/src/libicpf-tests/config-test.h (revision 0) @@ -1,14 +0,0 @@ -#ifndef __CONFIGTEST_H__ -#define __CONFIGTEST_H__ - -#include "test-base.h" - -class ConfigTest : public TestBase -{ -public: - ConfigTest() : TestBase() { }; - - virtual void Run(); -}; - -#endif Index: ext/libicpf/src/libicpf-tests/libicpf-tests.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/libicpf-tests.cpp (revision e457fa3cf2f23299155e396ac509048463930b9a) +++ ext/libicpf/src/libicpf-tests/libicpf-tests.cpp (revision 0) @@ -1,33 +0,0 @@ -// libicpf-tests.cpp : Defines the entry point for the console application. -// -#if defined(_WIN32) || defined(_WIN64) - #include -#endif - -#include -#include "gen_types.h" -#include "config-test.h" -#include "exception.h" - -#if defined(_WIN32) || defined(_WIN64) -int_t _tmain(int_t /*argc*/, tchar_t* /*argv*/[]) -#else -int main(int /*argc*/, char_t* /*argv*/[]) -#endif -{ - ConfigTest ct; - - try - { - ct.Run(); - } - catch(icpf::exception& e) - { - tchar_t szData[4096]; - e.get_info(szData, 4096); - _tprintf(TSTRFMT, szData); - } - - _getch(); - return 0; -} Index: ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj (revision 10b5d11e8ddbcb85eeb7b6063238001c67d5cc1e) +++ ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj (revision 0) @@ -1,256 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - libicpf-tests - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B} - libicpf-tests - Win32Proj - - - - Application - v120 - Unicode - - - Application - v120 - Unicode - - - Application - v120 - Unicode - - - Application - v120 - Unicode - - - v120 - Unicode - - - v120 - Unicode - - - v120 - Unicode - - - v120 - Unicode - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>11.0.51106.1 - - - $(SolutionDir)bin\debug\ - $(SolutionDir)intermediate\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)32ud - - - $(SolutionDir)bin\debug\ - $(SolutionDir)intermediate\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)64ud - - - $(SolutionDir)bin\release\ - $(SolutionDir)intermediate\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)32u - - - $(SolutionDir)bin\release\ - $(SolutionDir)intermediate\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)64u - - - - Disabled - ..\libicpf;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - Level4 - EditAndContinue - - - $(SolutionDir)bin\debug;%(AdditionalLibraryDirectories) - true - Console - true - true - MachineX86 - false - - - - - X64 - - - Disabled - ..\libicpf;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - - Level4 - ProgramDatabase - - - $(SolutionDir)bin\debug;%(AdditionalLibraryDirectories) - true - Console - true - true - MachineX64 - false - - - - - ..\libicpf;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - MultiThreadedDLL - - Level4 - ProgramDatabase - - - $(SolutionDir)bin\release;%(AdditionalLibraryDirectories) - true - Console - true - true - true - true - MachineX86 - false - - - - - X64 - - - ..\libicpf;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) - MultiThreadedDLL - - Level4 - ProgramDatabase - - - $(SolutionDir)bin\release;%(AdditionalLibraryDirectories) - true - Console - true - true - true - true - MachineX64 - false - - - - - ../libicpf - true - - - %(AdditionalDependencies) - - - - - ../libicpf - true - - - %(AdditionalDependencies) - - - - - ../libicpf - true - - - %(AdditionalDependencies) - - - - - ../libicpf - true - - - %(AdditionalDependencies) - - - - - - - - - - - - - - {5510b933-046f-4f75-8b46-5e8279c8ccde} - - - - - - \ No newline at end of file Index: ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj.filters =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj.filters (revision 10b5d11e8ddbcb85eeb7b6063238001c67d5cc1e) +++ ext/libicpf/src/libicpf-tests/libicpf-tests.vc120.vcxproj.filters (revision 0) @@ -1,32 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {00ca5694-b4da-4c22-8c2c-fcc557b5d5bd} - h;hpp;hxx;hm;inl;inc;xsd - - - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - \ No newline at end of file Index: ext/libicpf/src/libicpf-tests/libicpf-tests.vc90.vcproj =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/libicpf-tests.vc90.vcproj (revision 3e456be345c9b341a4411091589ddd43e7afd114) +++ ext/libicpf/src/libicpf-tests/libicpf-tests.vc90.vcproj (revision 0) @@ -1,347 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: ext/libicpf/src/libicpf-tests/libicpf-tests.vcproj =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/libicpf-tests.vcproj (revision 0d52c50b401d5028f92b03dd12d43eb9c0f800c4) +++ ext/libicpf/src/libicpf-tests/libicpf-tests.vcproj (revision 0) @@ -1,197 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: ext/libicpf/src/libicpf-tests/test-base.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/test-base.cpp (revision 1504b5e9af0cbbc688765c3530ee3443cb04fc01) +++ ext/libicpf/src/libicpf-tests/test-base.cpp (revision 0) @@ -1,35 +0,0 @@ -#include "test-base.h" -#include -#include - -#define MAX_BUF 4096 - -TestBase::TestBase() -{ -} - -TestBase::~TestBase() -{ -} - -void TestBase::Run() -{ - assert(false); -} - -void TestBase::Report(const tchar_t* pszFmt, ...) -{ - va_list va; - va_start(va, pszFmt); - - tchar_t szBuf[MAX_BUF]; - _vsntprintf(szBuf, MAX_BUF, pszFmt, va); // user passed stuff - ReportS(szBuf); - - va_end(va); -} - -void TestBase::ReportS(const tchar_t* pszStr) -{ - _tprintf(TSTRFMT, pszStr); -} Index: ext/libicpf/src/libicpf-tests/test-base.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf-tests/test-base.h (revision 1504b5e9af0cbbc688765c3530ee3443cb04fc01) +++ ext/libicpf/src/libicpf-tests/test-base.h (revision 0) @@ -1,19 +0,0 @@ -#ifndef __TESTBASE_H__ -#define __TESTBASE_H__ - -#include -#include "gen_types.h" - -class TestBase -{ -public: - TestBase(); - virtual ~TestBase(); - - virtual void Run(); - - void Report(const tchar_t* pszFmt, ...); - void ReportS(const tchar_t* pszFmt); -}; - -#endif Index: ictranslate.vc90.sln =================================================================== diff -u -N --- ictranslate.vc90.sln (revision 710aaca4fab0258780b0ab86a2c0be97073eab24) +++ ictranslate.vc90.sln (revision 0) @@ -1,66 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rc2lng", "src\rc2lng\rc2lng.vc90.vcproj", "{10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}" - ProjectSection(ProjectDependencies) = postProject - {5510B933-046F-4F75-8B46-5E8279C8CCDE} = {5510B933-046F-4F75-8B46-5E8279C8CCDE} - {DD1F3242-7EE4-4F41-8B8D-D833300C445F} = {DD1F3242-7EE4-4F41-8B8D-D833300C445F} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ictranslate", "src\ictranslate\ictranslate.vc90.vcproj", "{B0292250-B70C-4395-9859-F181FB113DA8}" - ProjectSection(ProjectDependencies) = postProject - {5510B933-046F-4F75-8B46-5E8279C8CCDE} = {5510B933-046F-4F75-8B46-5E8279C8CCDE} - {DD1F3242-7EE4-4F41-8B8D-D833300C445F} = {DD1F3242-7EE4-4F41-8B8D-D833300C445F} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libictranslate", "src\libictranslate\libictranslate.vc90.vcproj", "{DD1F3242-7EE4-4F41-8B8D-D833300C445F}" - ProjectSection(ProjectDependencies) = postProject - {5510B933-046F-4F75-8B46-5E8279C8CCDE} = {5510B933-046F-4F75-8B46-5E8279C8CCDE} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf", "src\libicpf\libicpf.vc90.vcproj", "{5510B933-046F-4F75-8B46-5E8279C8CCDE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Debug|Win32.ActiveCfg = Debug|Win32 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Debug|Win32.Build.0 = Debug|Win32 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Debug|x64.ActiveCfg = Debug|x64 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Debug|x64.Build.0 = Debug|x64 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Release|Win32.ActiveCfg = Release|Win32 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Release|Win32.Build.0 = Release|Win32 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Release|x64.ActiveCfg = Release|x64 - {10FB6B7E-81A1-47F9-BC6F-7017E5695D3A}.Release|x64.Build.0 = Release|x64 - {B0292250-B70C-4395-9859-F181FB113DA8}.Debug|Win32.ActiveCfg = Debug|Win32 - {B0292250-B70C-4395-9859-F181FB113DA8}.Debug|Win32.Build.0 = Debug|Win32 - {B0292250-B70C-4395-9859-F181FB113DA8}.Debug|x64.ActiveCfg = Debug|x64 - {B0292250-B70C-4395-9859-F181FB113DA8}.Debug|x64.Build.0 = Debug|x64 - {B0292250-B70C-4395-9859-F181FB113DA8}.Release|Win32.ActiveCfg = Release|Win32 - {B0292250-B70C-4395-9859-F181FB113DA8}.Release|Win32.Build.0 = Release|Win32 - {B0292250-B70C-4395-9859-F181FB113DA8}.Release|x64.ActiveCfg = Release|x64 - {B0292250-B70C-4395-9859-F181FB113DA8}.Release|x64.Build.0 = Release|x64 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Debug|Win32.ActiveCfg = Debug|Win32 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Debug|Win32.Build.0 = Debug|Win32 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Debug|x64.ActiveCfg = Debug|x64 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Debug|x64.Build.0 = Debug|x64 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Release|Win32.ActiveCfg = Release|Win32 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Release|Win32.Build.0 = Release|Win32 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Release|x64.ActiveCfg = Release|x64 - {DD1F3242-7EE4-4F41-8B8D-D833300C445F}.Release|x64.Build.0 = Release|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.ActiveCfg = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.Build.0 = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.ActiveCfg = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.Build.0 = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.ActiveCfg = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.Build.0 = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.ActiveCfg = Release|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal Index: libicpf.vc120.sln =================================================================== diff -u -N --- libicpf.vc120.sln (revision 0) +++ libicpf.vc120.sln (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,38 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf", "src\libicpf\libicpf.vc120.vcxproj", "{5510B933-046F-4F75-8B46-5E8279C8CCDE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf-tests", "src\libicpf-tests\libicpf-tests.vc120.vcxproj", "{AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.ActiveCfg = Debug|Win32 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.Build.0 = Debug|Win32 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.ActiveCfg = Debug|x64 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.Build.0 = Debug|x64 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.ActiveCfg = Release|Win32 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.Build.0 = Release|Win32 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.ActiveCfg = Release|x64 + {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.Build.0 = Release|x64 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.ActiveCfg = Debug|Win32 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.Build.0 = Debug|Win32 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.ActiveCfg = Debug|x64 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.Build.0 = Debug|x64 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|Win32.ActiveCfg = Release|Win32 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|Win32.Build.0 = Release|Win32 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.ActiveCfg = Release|x64 + {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection +EndGlobal Index: ext/libicpf/libicpf.vc120.sln =================================================================== diff -u -N --- ext/libicpf/libicpf.vc120.sln (revision 10b5d11e8ddbcb85eeb7b6063238001c67d5cc1e) +++ ext/libicpf/libicpf.vc120.sln (revision 0) @@ -1,38 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf", "src\libicpf\libicpf.vc120.vcxproj", "{5510B933-046F-4F75-8B46-5E8279C8CCDE}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libicpf-tests", "src\libicpf-tests\libicpf-tests.vc120.vcxproj", "{AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.ActiveCfg = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|Win32.Build.0 = Debug|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.ActiveCfg = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Debug|x64.Build.0 = Debug|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.ActiveCfg = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|Win32.Build.0 = Release|Win32 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.ActiveCfg = Release|x64 - {5510B933-046F-4F75-8B46-5E8279C8CCDE}.Release|x64.Build.0 = Release|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.ActiveCfg = Debug|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|Win32.Build.0 = Debug|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.ActiveCfg = Debug|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Debug|x64.Build.0 = Debug|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|Win32.ActiveCfg = Release|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|Win32.Build.0 = Release|Win32 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.ActiveCfg = Release|x64 - {AF4412FA-0CFB-47C1-A688-3E7875FE8A5B}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal Index: src/libicpf/Makefile.am =================================================================== diff -u -N --- src/libicpf/Makefile.am (revision 0) +++ src/libicpf/Makefile.am (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,16 @@ +lib_LTLIBRARIES = libicpf.la +libicpf_la_SOURCES = callback.cpp exception.cpp circ_buffer.cpp \ + log.cpp dumpctx.cpp cfg.cpp cfg_xml.cpp config_property.cpp str_help.cpp \ + crc32.cpp file.cpp module.cpp conv.cpp mutex.cpp + +# set the include path found by configure +INCLUDES = $(all_includes) + +# the library search path. +#libicpf_la_LDFLAGS = $(all_libraries) +libicpf_la_LIBADD = -ldl -lpthread +dist_include_HEADERS = callback.h exception.h dumpctx.h cfg.h circ_buffer.h module.h \ + file.h log.h cfg.h config_base.h config_property.h str_help.h crc32.h libicpf.h gen_types.h \ + conv.h err_codes.h gen_types.h macros.h mutex.h +AM_CFLAGS = -Wall -Wshadow -DLIBICPF_EXPORTS +AM_CXXFLAGS = -Wall -Wshadow -DLIBICPF_EXPORTS Index: ext/libicpf/src/libicpf/Makefile.am =================================================================== diff -u -N --- ext/libicpf/src/libicpf/Makefile.am (revision b337c059691a6940b52a86388ff427c734be8eb6) +++ ext/libicpf/src/libicpf/Makefile.am (revision 0) @@ -1,16 +0,0 @@ -lib_LTLIBRARIES = libicpf.la -libicpf_la_SOURCES = callback.cpp exception.cpp circ_buffer.cpp \ - log.cpp dumpctx.cpp cfg.cpp cfg_xml.cpp config_property.cpp str_help.cpp \ - crc32.cpp file.cpp module.cpp conv.cpp mutex.cpp - -# set the include path found by configure -INCLUDES = $(all_includes) - -# the library search path. -#libicpf_la_LDFLAGS = $(all_libraries) -libicpf_la_LIBADD = -ldl -lpthread -dist_include_HEADERS = callback.h exception.h dumpctx.h cfg.h circ_buffer.h module.h \ - file.h log.h cfg.h config_base.h config_property.h str_help.h crc32.h libicpf.h gen_types.h \ - conv.h err_codes.h gen_types.h macros.h mutex.h -AM_CFLAGS = -Wall -Wshadow -DLIBICPF_EXPORTS -AM_CXXFLAGS = -Wall -Wshadow -DLIBICPF_EXPORTS Index: src/libicpf/buffer.h =================================================================== diff -u -N --- src/libicpf/buffer.h (revision 0) +++ src/libicpf/buffer.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,127 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __BUFFER_H__ +#define __BUFFER_H__ + +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +template +class buffer +{ +public: +/** \name Construction/destruction/operators */ +/**@{*/ + buffer(); + buffer(const T* pData, size_t stCount); + buffer(const buffer& rSrc); + ~buffer(); + + buffer& operator=(const buffer& rSrc); + const T* operator T*() const; { return m_pData; }; +/**@}*/ + + size_t get_size() const { return m_stBufSize; }; + void resize(size_t stNewSize); + + size_t get_block_size() const { return m_stBlockSize; }; + void set_block_size(size_t stBlockSize); + + size_t get_max_unused() const { return m_stMaxUnused; }; + size_t set_max_unused(); + +protected: + T* m_pData; ///< Pointer to the data + size_t m_stBufSize; ///< Current buffer size + size_t m_stBlockSize; ///< Block size + size_t m_stMaxUnused; ///< Max count of unused items allowed +}; + +template +buffer::buffer() : + m_pData(NULL), + m_stBufSize(0), + m_stBlockSize(1024), + m_stMaxUnused(1024) +{ +} + +template +buffer::buffer(const T* pData, size_t stCount) : + m_pData(NULL), + m_stBufSize(0), + m_stBlockSize(1024), + m_stMaxUnused(1024) +{ + resize(stCount); + memcpy(m_pData, pData, stCount*sizeof(T)); +} + +template +buffer::buffer(const buffer& rSrc) : + m_pData((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL), + m_stBufSize(rSrc.m_stBufSize), + m_stBlockSize(rSrc.m_stBlockSize), + m_stMaxUnused(rSrc.m_stMaxUnused) +{ + assert(m_stBlockSize > 0); + if (m_pData) + memcpy(m_pData, pData, stCount*sizeof(T)); +} + +template +buffer::~buffer() +{ + delete [] m_pData; +} + +template +buffer& buffer::operator=(const buffer& rSrc) +{ + if (this != &rSrc) + { + delete [] m_pData; + + m_pData=((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL); + m_stBufSize=rSrc.m_stBufSize; + m_stBlockSize=rSrc.m_stBlockSize; + m_stMaxUnused=rSrc.m_stMaxUnused; + + } + + return *this; +} + +template +const T* operator T*() const; { return m_pData; }; + +template +void resize(size_t stNewSize); + +template +void set_block_size(size_t stBlockSize); + +template +size_t set_max_unused(); + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/buffer.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/buffer.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/buffer.h (revision 0) @@ -1,127 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __BUFFER_H__ -#define __BUFFER_H__ - -#include "libicpf.h" -#include "gen_types.h" - -BEGIN_ICPF_NAMESPACE - -template -class buffer -{ -public: -/** \name Construction/destruction/operators */ -/**@{*/ - buffer(); - buffer(const T* pData, size_t stCount); - buffer(const buffer& rSrc); - ~buffer(); - - buffer& operator=(const buffer& rSrc); - const T* operator T*() const; { return m_pData; }; -/**@}*/ - - size_t get_size() const { return m_stBufSize; }; - void resize(size_t stNewSize); - - size_t get_block_size() const { return m_stBlockSize; }; - void set_block_size(size_t stBlockSize); - - size_t get_max_unused() const { return m_stMaxUnused; }; - size_t set_max_unused(); - -protected: - T* m_pData; ///< Pointer to the data - size_t m_stBufSize; ///< Current buffer size - size_t m_stBlockSize; ///< Block size - size_t m_stMaxUnused; ///< Max count of unused items allowed -}; - -template -buffer::buffer() : - m_pData(NULL), - m_stBufSize(0), - m_stBlockSize(1024), - m_stMaxUnused(1024) -{ -} - -template -buffer::buffer(const T* pData, size_t stCount) : - m_pData(NULL), - m_stBufSize(0), - m_stBlockSize(1024), - m_stMaxUnused(1024) -{ - resize(stCount); - memcpy(m_pData, pData, stCount*sizeof(T)); -} - -template -buffer::buffer(const buffer& rSrc) : - m_pData((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL), - m_stBufSize(rSrc.m_stBufSize), - m_stBlockSize(rSrc.m_stBlockSize), - m_stMaxUnused(rSrc.m_stMaxUnused) -{ - assert(m_stBlockSize > 0); - if (m_pData) - memcpy(m_pData, pData, stCount*sizeof(T)); -} - -template -buffer::~buffer() -{ - delete [] m_pData; -} - -template -buffer& buffer::operator=(const buffer& rSrc) -{ - if (this != &rSrc) - { - delete [] m_pData; - - m_pData=((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL); - m_stBufSize=rSrc.m_stBufSize; - m_stBlockSize=rSrc.m_stBlockSize; - m_stMaxUnused=rSrc.m_stMaxUnused; - - } - - return *this; -} - -template -const T* operator T*() const; { return m_pData; }; - -template -void resize(size_t stNewSize); - -template -void set_block_size(size_t stBlockSize); - -template -size_t set_max_unused(); - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/callback.cpp =================================================================== diff -u -N --- src/libicpf/callback.cpp (revision 0) +++ src/libicpf/callback.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,132 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ + /** \file callback.cpp + * \brief File provides the implementation of callback classes. + */ +#include "callback.h" +#include +#include + +BEGIN_ICPF_NAMESPACE + +#define STORAGE ((std::vector*)m_pStorage) + +callback_list::callback_list() : + m_lock(), + m_pStorage((void*)new std::vector) +{ +} + +callback_list::callback_list(const callback_list& rSrc) : + m_lock(), + m_pStorage((void*)new std::vector) +{ + STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); + assert(false); // we should not use the copy constructor at all !!! +} + +callback_list::~callback_list() +{ + try + { + delete STORAGE; + } + catch(...) + { + + } +} + +const callback_list& callback_list::operator=(const callback_list& rSrc) +{ + assert(false); // we shouldn't use the assignment operator at all!!! + if (this != &rSrc) + { + delete STORAGE; + m_pStorage=(void*)new std::vector; + STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); + } + + return *this; +} + +void callback_list::add(PFNFUNC pfn, ptr_t param) +{ + m_lock.lock(); + CLBDATA clb = { pfn, param }; + STORAGE->push_back(clb); + m_lock.unlock(); +} + +bool callback_list::remove(PFNFUNC pfn) +{ + m_lock.lock(); + for (std::vector::iterator it=STORAGE->begin();it != STORAGE->end();it++) + { + if ((*it).pfn == pfn) + { + STORAGE->erase(it); + m_lock.unlock(); + return true; + } + } + + m_lock.unlock(); + return false; +} + +void callback_list::clear() +{ + m_lock.lock(); + STORAGE->clear(); + m_lock.unlock(); +} + +size_t callback_list::size() +{ + m_lock.lock(); + size_t tSize=STORAGE->size(); + m_lock.unlock(); + + return tSize; +} + +CLBDATA* callback_list::at(size_t tIndex) +{ + CLBDATA* pData=NULL; + m_lock.lock(); + if (tIndex < STORAGE->size()) + pData=&(STORAGE->at(tIndex)); + m_lock.unlock(); + + return pData; +} + +void callback_list::lock() +{ + m_lock.lock(); +} + +void callback_list::unlock() +{ + m_lock.unlock(); +} + + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/callback.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/callback.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/callback.cpp (revision 0) @@ -1,132 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ - /** \file callback.cpp - * \brief File provides the implementation of callback classes. - */ -#include "callback.h" -#include -#include - -BEGIN_ICPF_NAMESPACE - -#define STORAGE ((std::vector*)m_pStorage) - -callback_list::callback_list() : - m_lock(), - m_pStorage((void*)new std::vector) -{ -} - -callback_list::callback_list(const callback_list& rSrc) : - m_lock(), - m_pStorage((void*)new std::vector) -{ - STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); - assert(false); // we should not use the copy constructor at all !!! -} - -callback_list::~callback_list() -{ - try - { - delete STORAGE; - } - catch(...) - { - - } -} - -const callback_list& callback_list::operator=(const callback_list& rSrc) -{ - assert(false); // we shouldn't use the assignment operator at all!!! - if (this != &rSrc) - { - delete STORAGE; - m_pStorage=(void*)new std::vector; - STORAGE->assign(((std::vector*)rSrc.m_pStorage)->begin(), ((std::vector*)rSrc.m_pStorage)->end()); - } - - return *this; -} - -void callback_list::add(PFNFUNC pfn, ptr_t param) -{ - m_lock.lock(); - CLBDATA clb = { pfn, param }; - STORAGE->push_back(clb); - m_lock.unlock(); -} - -bool callback_list::remove(PFNFUNC pfn) -{ - m_lock.lock(); - for (std::vector::iterator it=STORAGE->begin();it != STORAGE->end();it++) - { - if ((*it).pfn == pfn) - { - STORAGE->erase(it); - m_lock.unlock(); - return true; - } - } - - m_lock.unlock(); - return false; -} - -void callback_list::clear() -{ - m_lock.lock(); - STORAGE->clear(); - m_lock.unlock(); -} - -size_t callback_list::size() -{ - m_lock.lock(); - size_t tSize=STORAGE->size(); - m_lock.unlock(); - - return tSize; -} - -CLBDATA* callback_list::at(size_t tIndex) -{ - CLBDATA* pData=NULL; - m_lock.lock(); - if (tIndex < STORAGE->size()) - pData=&(STORAGE->at(tIndex)); - m_lock.unlock(); - - return pData; -} - -void callback_list::lock() -{ - m_lock.lock(); -} - -void callback_list::unlock() -{ - m_lock.unlock(); -} - - -END_ICPF_NAMESPACE Index: src/libicpf/callback.h =================================================================== diff -u -N --- src/libicpf/callback.h (revision 0) +++ src/libicpf/callback.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,263 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CALLBACK_H__ +#define __CALLBACK_H__ + +/** \file callback.h + * \brief Provides callback classes + */ + +#include "libicpf.h" +#include "gen_types.h" +#include +#include "mutex.h" + +BEGIN_ICPF_NAMESPACE + +/// General function definition +#ifdef _WIN32 + typedef void(__stdcall *PFNFUNC)(void); +#else + typedef void(*PFNFUNC)(void); +#endif + +/// Helper structure for callback class +struct LIBICPF_API CLBDATA +{ + PFNFUNC pfn; ///< General function definition + ptr_t param; +}; + +class LIBICPF_API callback_list +{ +public: +/** \name Construction/destruction */ +/**@{*/ + callback_list(); + callback_list(const callback_list& rSrc); + virtual ~callback_list(); +/**@}*/ + + void add(PFNFUNC pfn, ptr_t param); + bool remove(PFNFUNC pfn); + void clear(); + size_t size(); + CLBDATA* at(size_t tIndex); + + void lock(); + void unlock(); + + const callback_list& operator=(const callback_list& rSrc); + +protected: + icpf::mutex m_lock; ///< A locking mechanism for the storage area + +private: + void* m_pStorage; ///< A pointer to a storage struct (a std::list probably), but must be inaccessible from outside +}; + +/** \brief Callback class with one parameter. + * + * Class provides a simple interface for user to call a specific callback + * function(s) registered by the user. Good for notifying user that something + * had happened. + */ +template +class /*LIBICPF_API*/ callback1 : public callback_list +{ +protected: + /// Callback1-type callback function +#ifdef _WIN32 + typedef R(__stdcall *PFNCALLBACKPROC1)(ptr_t, P1); +#else + typedef R(*PFNCALLBACKPROC1)(ptr_t, P1); +#endif + +public: +/** \name Construction/destruction */ +/**@{*/ + callback1() : callback_list() { }; ///< Standard constructor + virtual ~callback1() { }; ///< Standard destructor +/**@}*/ + +/** \name User interface */ +/**@{*/ + /** Executes a callback list associated with this object. + * \param[in] data - parameter that will be passed to a user callback function + */ + void exec(P1 data) + { + m_lock.lock(); + CLBDATA* pData; + for (size_t i=0;i != size();i++) + { + pData=at(i); + if (pData) + (*(PFNCALLBACKPROC1)(pData->pfn))(pData->param, data); + } + m_lock.unlock(); + } + + /** Connects a user callback function to this object. + * \param[in] pfn - user callback function address + * \param[in] appParam - user parameter to pass to the callback function when executing + */ + void connect(PFNCALLBACKPROC1 pfn, ptr_t appParam) + { + add((PFNFUNC)pfn, appParam); + } + + /** Disconnects the user callback function if connected earlier. + * \param[in] pfn - address of a function to remove + */ + void disconnect(PFNCALLBACKPROC1 pfn) + { + remove((PFNFUNC)pfn); + } +/**@}*/ +}; + +/** \brief Callback class with two parameters. + * + * Class provides a simple interface for user to call a specific callback + * function(s) registered by the user. Good for notifying user that something + * had happened. + */ +template +class /*LIBICPF_API*/ callback2 : public callback_list +{ +protected: + /// Callback2-type callback function +#ifdef _WIN32 + typedef R(__stdcall *PFNCALLBACKPROC2)(ptr_t, P1, P2); +#else + typedef R(*PFNCALLBACKPROC2)(ptr_t, P1, P2); +#endif + +public: +/** \name Construction/destruction */ +/**@{*/ + callback2() : callback_list() { }; ///< Standard constructor + virtual ~callback2() { }; ///< Standard destructor +/**@}*/ + +/** \name User interface */ +/**@{*/ + /** Executes a callback list associated with this object. + * \param[in] data1 - parameter that will be passed to a user callback function + * \param[in] data2 - parameter that will be passed to a user callback function + */ + void exec(P1 data1, P2 data2) + { + m_lock.lock(); + CLBDATA* pData; + for (size_t i=0;i != size();i++) + { + pData=at(i); + if (pData) + (*(PFNCALLBACKPROC2)(pData->pfn))(pData->param, data1, data2); + } + m_lock.unlock(); + } + + /** Connects a user callback function to this object. + * \param[in] pfn - user callback function address + * \param[in] appParam - user parameter to pass to the callback function when executing + */ + void connect(PFNCALLBACKPROC2 pfn, ptr_t appParam) + { + add((PFNFUNC)pfn, appParam); + } + + /** Disconnects the user callback function if connected earlier. + * \param[in] pfn - address of a function to remove + */ + void disconnect(PFNCALLBACKPROC2 pfn) + { + remove((PFNFUNC)pfn); + } +/**@}*/ +}; + +/** \brief Callback class with three parameters. + * + * Class provides a simple interface for user to call a specific callback + * function(s) registered by the user. Good for notifying user that something + * had happened. + */ +template +class /*LIBICPF_API*/ callback3 : public callback_list +{ +protected: + /// Callback2-type callback function +#ifdef _WIN32 + typedef R(__stdcall *PFNCALLBACKPROC3)(ptr_t, P1, P2, P3); +#else + typedef R(*PFNCALLBACKPROC3)(ptr_t, P1, P2, P3); +#endif + +public: +/** \name Construction/destruction */ +/**@{*/ + callback3() : callback_list() { }; ///< Standard constructor + virtual ~callback3() { }; ///< Standard destructor +/**@}*/ + +/** \name User interface */ +/**@{*/ + /** Executes a callback list associated with this object. + * \param[in] data1 - parameter that will be passed to a user callback function + * \param[in] data2 - parameter that will be passed to a user callback function + * \param[in] data3 - parameter that will be passed to a user callback function + */ + void exec(P1 data1, P2 data2, P3 data3) + { + m_lock.lock(); + CLBDATA* pData; + for (size_t i=0;i != size();i++) + { + pData=at(i); + if (pData) + (*(PFNCALLBACKPROC3)(pData->pfn))(pData->param, data1, data2, data3); + } + m_lock.unlock(); + } + + /** Connects a user callback function to this object. + * \param[in] pfn - user callback function address + * \param[in] appParam - user parameter to pass to the callback function when executing + */ + void connect(PFNCALLBACKPROC3 pfn, ptr_t appParam) + { + add((PFNFUNC)pfn, appParam); + } + + /** Disconnects the user callback function if connected earlier. + * \param[in] pfn - address of a function to remove + */ + void disconnect(PFNCALLBACKPROC3 pfn) + { + remove((PFNFUNC)pfn); + } +/**@}*/ +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/callback.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/callback.h (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/callback.h (revision 0) @@ -1,263 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CALLBACK_H__ -#define __CALLBACK_H__ - -/** \file callback.h - * \brief Provides callback classes - */ - -#include "libicpf.h" -#include "gen_types.h" -#include -#include "mutex.h" - -BEGIN_ICPF_NAMESPACE - -/// General function definition -#ifdef _WIN32 - typedef void(__stdcall *PFNFUNC)(void); -#else - typedef void(*PFNFUNC)(void); -#endif - -/// Helper structure for callback class -struct LIBICPF_API CLBDATA -{ - PFNFUNC pfn; ///< General function definition - ptr_t param; -}; - -class LIBICPF_API callback_list -{ -public: -/** \name Construction/destruction */ -/**@{*/ - callback_list(); - callback_list(const callback_list& rSrc); - virtual ~callback_list(); -/**@}*/ - - void add(PFNFUNC pfn, ptr_t param); - bool remove(PFNFUNC pfn); - void clear(); - size_t size(); - CLBDATA* at(size_t tIndex); - - void lock(); - void unlock(); - - const callback_list& operator=(const callback_list& rSrc); - -protected: - icpf::mutex m_lock; ///< A locking mechanism for the storage area - -private: - void* m_pStorage; ///< A pointer to a storage struct (a std::list probably), but must be inaccessible from outside -}; - -/** \brief Callback class with one parameter. - * - * Class provides a simple interface for user to call a specific callback - * function(s) registered by the user. Good for notifying user that something - * had happened. - */ -template -class /*LIBICPF_API*/ callback1 : public callback_list -{ -protected: - /// Callback1-type callback function -#ifdef _WIN32 - typedef R(__stdcall *PFNCALLBACKPROC1)(ptr_t, P1); -#else - typedef R(*PFNCALLBACKPROC1)(ptr_t, P1); -#endif - -public: -/** \name Construction/destruction */ -/**@{*/ - callback1() : callback_list() { }; ///< Standard constructor - virtual ~callback1() { }; ///< Standard destructor -/**@}*/ - -/** \name User interface */ -/**@{*/ - /** Executes a callback list associated with this object. - * \param[in] data - parameter that will be passed to a user callback function - */ - void exec(P1 data) - { - m_lock.lock(); - CLBDATA* pData; - for (size_t i=0;i != size();i++) - { - pData=at(i); - if (pData) - (*(PFNCALLBACKPROC1)(pData->pfn))(pData->param, data); - } - m_lock.unlock(); - } - - /** Connects a user callback function to this object. - * \param[in] pfn - user callback function address - * \param[in] appParam - user parameter to pass to the callback function when executing - */ - void connect(PFNCALLBACKPROC1 pfn, ptr_t appParam) - { - add((PFNFUNC)pfn, appParam); - } - - /** Disconnects the user callback function if connected earlier. - * \param[in] pfn - address of a function to remove - */ - void disconnect(PFNCALLBACKPROC1 pfn) - { - remove((PFNFUNC)pfn); - } -/**@}*/ -}; - -/** \brief Callback class with two parameters. - * - * Class provides a simple interface for user to call a specific callback - * function(s) registered by the user. Good for notifying user that something - * had happened. - */ -template -class /*LIBICPF_API*/ callback2 : public callback_list -{ -protected: - /// Callback2-type callback function -#ifdef _WIN32 - typedef R(__stdcall *PFNCALLBACKPROC2)(ptr_t, P1, P2); -#else - typedef R(*PFNCALLBACKPROC2)(ptr_t, P1, P2); -#endif - -public: -/** \name Construction/destruction */ -/**@{*/ - callback2() : callback_list() { }; ///< Standard constructor - virtual ~callback2() { }; ///< Standard destructor -/**@}*/ - -/** \name User interface */ -/**@{*/ - /** Executes a callback list associated with this object. - * \param[in] data1 - parameter that will be passed to a user callback function - * \param[in] data2 - parameter that will be passed to a user callback function - */ - void exec(P1 data1, P2 data2) - { - m_lock.lock(); - CLBDATA* pData; - for (size_t i=0;i != size();i++) - { - pData=at(i); - if (pData) - (*(PFNCALLBACKPROC2)(pData->pfn))(pData->param, data1, data2); - } - m_lock.unlock(); - } - - /** Connects a user callback function to this object. - * \param[in] pfn - user callback function address - * \param[in] appParam - user parameter to pass to the callback function when executing - */ - void connect(PFNCALLBACKPROC2 pfn, ptr_t appParam) - { - add((PFNFUNC)pfn, appParam); - } - - /** Disconnects the user callback function if connected earlier. - * \param[in] pfn - address of a function to remove - */ - void disconnect(PFNCALLBACKPROC2 pfn) - { - remove((PFNFUNC)pfn); - } -/**@}*/ -}; - -/** \brief Callback class with three parameters. - * - * Class provides a simple interface for user to call a specific callback - * function(s) registered by the user. Good for notifying user that something - * had happened. - */ -template -class /*LIBICPF_API*/ callback3 : public callback_list -{ -protected: - /// Callback2-type callback function -#ifdef _WIN32 - typedef R(__stdcall *PFNCALLBACKPROC3)(ptr_t, P1, P2, P3); -#else - typedef R(*PFNCALLBACKPROC3)(ptr_t, P1, P2, P3); -#endif - -public: -/** \name Construction/destruction */ -/**@{*/ - callback3() : callback_list() { }; ///< Standard constructor - virtual ~callback3() { }; ///< Standard destructor -/**@}*/ - -/** \name User interface */ -/**@{*/ - /** Executes a callback list associated with this object. - * \param[in] data1 - parameter that will be passed to a user callback function - * \param[in] data2 - parameter that will be passed to a user callback function - * \param[in] data3 - parameter that will be passed to a user callback function - */ - void exec(P1 data1, P2 data2, P3 data3) - { - m_lock.lock(); - CLBDATA* pData; - for (size_t i=0;i != size();i++) - { - pData=at(i); - if (pData) - (*(PFNCALLBACKPROC3)(pData->pfn))(pData->param, data1, data2, data3); - } - m_lock.unlock(); - } - - /** Connects a user callback function to this object. - * \param[in] pfn - user callback function address - * \param[in] appParam - user parameter to pass to the callback function when executing - */ - void connect(PFNCALLBACKPROC3 pfn, ptr_t appParam) - { - add((PFNFUNC)pfn, appParam); - } - - /** Disconnects the user callback function if connected earlier. - * \param[in] pfn - address of a function to remove - */ - void disconnect(PFNCALLBACKPROC3 pfn) - { - remove((PFNFUNC)pfn); - } -/**@}*/ -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/cfg.cpp =================================================================== diff -u -N --- src/libicpf/cfg.cpp (revision 0) +++ src/libicpf/cfg.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,844 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file cfg.cpp + * \brief A placeholder for config class definitions. + * \todo Modify the class to use file class as a file access layer. + */ + +#include "cfg.h" +#include +#include "exception.h" +#include +#include +#include "err_codes.h" +#include "cfg_xml.h" +#include "cfg_ini.h" + +BEGIN_ICPF_NAMESPACE + +////////////////////////////////////////////////////////////////////////////////// +// property_tracker class +#define m_psProperties ((std::set*)m_hProperties) + +/** Constructs the property_tracker object. + */ +property_tracker::property_tracker() : + m_hProperties((ptr_t)new std::set) +{ +} + +/** Constructs the property_tracker by copying data from source object. + * + * \param[in] rSrc - source property tracker + */ +property_tracker::property_tracker(const property_tracker& rSrc) : + m_hProperties((ptr_t)new std::set(*(std::set*)rSrc.m_hProperties)) +{ +} + +/** Destructs the property tracker object. + */ +property_tracker::~property_tracker() +{ + delete m_psProperties; +} + +/** Function adds a new property id to the group. + * + * \param[in] uiProp - id of a property to add + */ +void property_tracker::add(uint_t uiProp) +{ + m_psProperties->insert(uiProp); +} + +/** Function searches for a specific property id inside the list. + * + * \param[in] uiProp - property id to check for + * \return True if the property has been found, false if not. + */ +bool property_tracker::is_set(uint_t uiProp) +{ + return m_psProperties->find(uiProp) != m_psProperties->end(); +} + +/** Function returns a count of properties contained in the list. + * + * \return A count of id's. + */ +size_t property_tracker::count() const +{ + return m_psProperties->size(); +} + +/** Function retrieves the id's contained in this tracker by copying + * them to the given array. + * + * \param[out] puiProps - pointer to the array of uint's to receive id's + * \param[in] stMaxCount - size of the array (max count of elements to retrieve) + */ +size_t property_tracker::get_ids(uint_t* puiProps, size_t stMaxCount) +{ + size_t tIndex=0; + for (std::set::iterator it=m_psProperties->begin();it != m_psProperties->end();it++) + { + puiProps[tIndex++]=(*it); + if(tIndex >= stMaxCount) + break; + } + + return tIndex; +} + +/** Function enumerates id's contained in this property_tracker using + * a callback function. + * + * \param[in] pfn - function to be called + * \param[in] pParam - parameter to pass to the callback + */ +void property_tracker::enum_ids(bool(*pfn)(uint_t uiProp, ptr_t pParam), ptr_t pParam) +{ + for (std::set::iterator it=m_psProperties->begin();it != m_psProperties->end();it++) + { + if(!(*pfn)((*it), pParam)) + break; + } +} + +///////////////////////////////////////////////////////////////////////////////////// +// config class + +#define m_pvProps ((std::vector*)m_hProps) + +/** Constructs a config object. + * \param[in] pCfgBase - pointer to a base handler of the configuration strings + * cound be pointer to xml handler, ini handler or any other + */ +config::config(config_base_types eCfgType) : + m_lock(), + m_hProps((ptr_t)new std::vector), + m_pszCurrentPath(NULL) +{ + switch(eCfgType) + { + //case eXml: + // m_pCfgBase = new xml_cfg; + // break; + case eIni: + m_pCfgBase = new ini_cfg; + break; + default: + THROW(_t("Undefined config base type"), 0, 0, 0); + } +} + +/** Destructs the config class. + */ +config::~config() +{ + delete m_pvProps; + delete [] m_pszCurrentPath; + delete m_pCfgBase; +} + +/** Function opens the specified file using the underlying config base + * and converts the values read to a list of properties registered + * earlier. + * + * \param[in] pszPath - path to a file to be read + */ +void config::read(const tchar_t* pszPath) +{ + assert(pszPath); + if(!pszPath) + THROW(_T("Path to the file not provided."), FERR_OPEN, 0, 0); + + // remembering path before operation and not freeing it on fail is done on purpose here + // (to support future write() to this file in case file does not exist yet) + size_t stLen = _tcslen(pszPath); + if(stLen) + { + delete [] m_pszCurrentPath; + m_pszCurrentPath = new tchar_t[stLen + 1]; + _tcscpy(m_pszCurrentPath, pszPath); + m_pszCurrentPath[stLen] = _t('\0'); + } + + m_lock.lock(); + try + { + // read the data using underlying object + m_pCfgBase->read(pszPath); + + // and transform it to eatable form using registered properties + load_registered(); + } + catch(...) + { + m_lock.unlock(); + throw; + } + m_lock.unlock(); +} + +/** Reads the configuration data from the provided buffer. + * + * \param[in] pszData - pointer to the buffer with data + * \param[in] stSize - size of the data in buffer + */ +void config::read_from_buffer(const tchar_t* pszData, size_t stSize) +{ + m_lock.lock(); + try + { + m_pCfgBase->read_from_buffer(pszData, stSize); + + // and transform it to eatable form using registered properties + load_registered(); + } + catch(...) + { + m_lock.unlock(); + throw; + } + m_lock.unlock(); +} + +/** Writes all the registered properties into the given file using + * the underlying config base to do this. + * + * \param[in] pszPath - path to a file to write the properties to + */ +void config::write(const tchar_t* pszPath) +{ + if(!m_pszCurrentPath && !pszPath) + THROW(_T("No path specified"), FERR_OPEN, 0, 0); + m_lock.lock(); + + try + { + // store current properties to the underlying object + store_registered(); + + if(pszPath) + { + size_t stLen = _tcslen(pszPath); + if(stLen) + { + delete [] m_pszCurrentPath; + m_pszCurrentPath = new tchar_t[stLen + 1]; + _tcscpy(m_pszCurrentPath, pszPath); + m_pszCurrentPath[stLen] = _t('\0'); + } + } + + // and save + m_pCfgBase->save(m_pszCurrentPath); + } + catch(...) + { + m_lock.unlock(); + throw; + } + + m_lock.unlock(); +} + +/** Function returns a property type for a given property id. + * + * \param[in] uiProp - property id to get info about + * \return The property type along with its flags. + */ +uint_t config::get_type(uint_t uiProp) +{ + m_lock.lock(); + uint_t uiRet=m_pvProps->at(uiProp).get_type(); + m_lock.unlock(); + + return uiRet; +} + +/** Retrieves the count of values in the specified property. + * + * \param[in] uiProp - property id to retrieve information about + * \return Count of values. + */ +size_t config::get_value_count(uint_t uiProp) +{ + m_lock.lock(); + size_t stRet=m_pvProps->at(uiProp).get_count(); + m_lock.unlock(); + + return stRet; +} + +/** Removes an array value at a given index. + * + * \param[in] uiProp - property id to have the value removed + * \param[in] stIndex - index of the value to remove + */ +void config::remove_array_value(uint_t uiProp, size_t stIndex) +{ + m_lock.lock(); + m_pvProps->at(uiProp).remove(stIndex); + m_lock.unlock(); +} + +/** Clears the list of values in the given property. + * + * \param[in] uiProp - property id to have the values cleared + */ +void config::clear_array_values(uint_t uiProp) +{ + m_lock.lock(); + m_pvProps->at(uiProp).clear_array(); + m_lock.unlock(); +} + +/** Retrieves the count of registered properties contained in this config. + * + * \return Count of properties. + */ +size_t config::count() +{ + return m_pvProps->size(); +} + +/** Function registers the signed number property. If the underlying base object + * contains a string with a specified key - the value is being translated to + * the value of this property. + * + * \param[in] pszName - name of the property + * \param[in] llDef - default value for the property + * \param[in] llLo - the lower bound of the allowable value range + * \param[in] llHi - the higher bound of the allowable value range + * \param[in] uiFlags - additional flags that should be associated with property + * \return Property ID of the newly registered property. + */ +uint_t config::register_signed_num(const tchar_t* pszName, ll_t llDef, ll_t llLo, ll_t llHi, uint_t uiFlags) +{ + // prepare the property to insert + property prop(pszName, property::type_signed_num | (uiFlags & property::mask_flags)); + prop.set_signed_range(llLo, llHi); + + // and operate inside the internals + m_lock.lock(); + + // get the value for the property name + ptr_t hFind=NULL; + if( (hFind=m_pCfgBase->find(pszName)) != NULL ) + { + PROPINFO pi; + while(m_pCfgBase->find_next(hFind, pi)) + { + assert(!pi.bGroup); + prop.set_value(pi.pszValue, property::action_add); + } + + m_pCfgBase->find_close(hFind); + } + else if(!(uiFlags & property::flag_array)) + prop.set_signed_num(llDef); + + // add to the vector + m_pvProps->push_back(prop); + uint_t uiProp=(uint_t)(m_pvProps->size()-1); + + m_lock.unlock(); + + return uiProp; +} + +/** Function registers the unsigned number property. If the underlying base object + * contains a string with a specified key - the value is being translated to + * the value of this property. + * + * \param[in] pszName - name of the property + * \param[in] ullDef - default value for the property + * \param[in] ullLo - the lower bound of the allowable value range + * \param[in] ullHi - the higher bound of the allowable value range + * \param[in] uiFlags - additional flags that should be associated with property + * \return Property ID of the newly registered property. + */ +uint_t config::register_unsigned_num(const tchar_t* pszName, ull_t ullDef, ull_t ullLo, ull_t ullHi, uint_t uiFlags) +{ + // prepare the property to insert + property prop(pszName, property::type_unsigned_num | (uiFlags & property::mask_flags)); + prop.set_unsigned_range(ullLo, ullHi); + + // and operate inside the internals + m_lock.lock(); + + // get the value for the property name + ptr_t hFind=NULL; + if( (hFind=m_pCfgBase->find(pszName)) != NULL ) + { + PROPINFO pi; + while(m_pCfgBase->find_next(hFind, pi)) + { + assert(!pi.bGroup); + prop.set_value(pi.pszValue, property::action_add); + } + + m_pCfgBase->find_close(hFind); + } + else if(!(uiFlags & property::flag_array)) + prop.set_unsigned_num(ullDef); + + // add to the vector + m_pvProps->push_back(prop); + uint_t uiProp=(uint_t)(m_pvProps->size()-1); + + m_lock.unlock(); + + return uiProp; +} + +/** Function registers the boolean property. If the underlying base object + * contains a string with a specified key - the value is being translated to + * the value of this property. + * + * \param[in] pszName - name of the property + * \param[in] bDef - default value for the property + * \param[in] uiFlags - additional flags that should be associated with property + * \return Property ID of the newly registered property. + */ +uint_t config::register_bool(const tchar_t* pszName, bool bDef, uint_t uiFlags) +{ + // prepare the property to insert + property prop(pszName, property::type_bool | (uiFlags & property::mask_flags)); + + // and operate inside the internals + m_lock.lock(); + + // get the value for the property name + ptr_t hFind=NULL; + if( (hFind=m_pCfgBase->find(pszName)) != NULL ) + { + PROPINFO pi; + while(m_pCfgBase->find_next(hFind, pi)) + { + assert(!pi.bGroup); + prop.set_value(pi.pszValue, property::action_add); + } + + m_pCfgBase->find_close(hFind); + } + else if(!(uiFlags & property::flag_array)) + prop.set_bool(bDef); + + // add to the vector + m_pvProps->push_back(prop); + uint_t uiProp=(uint_t)(m_pvProps->size()-1); + + m_lock.unlock(); + + return uiProp; +} + +/** Function registers the string property. If the underlying base object + * contains a string with a specified key - the value is being translated to + * the value of this property. + * + * \param[in] pszName - name of the property + * \param[in] pszDef - default value for the property + * \param[in] uiFlags - additional flags that should be associated with property + * \return Property ID of the newly registered property. + */ +uint_t config::register_string(const tchar_t* pszName, const tchar_t* pszDef, uint_t uiFlags) +{ + // prepare the property to insert + property prop(pszName, property::type_string | (uiFlags & property::mask_flags)); + + // and operate inside the internals + m_lock.lock(); + + // get the value for the property name + ptr_t hFind=NULL; + if( (hFind=m_pCfgBase->find(pszName)) != NULL ) + { + PROPINFO pi; + while(m_pCfgBase->find_next(hFind, pi)) + { + assert(!pi.bGroup); + prop.set_value(pi.pszValue, property::action_add); + } + + m_pCfgBase->find_close(hFind); + } + else if(!(uiFlags & property::flag_array)) + prop.set_string(pszDef); + + // add to the vector + m_pvProps->push_back(prop); + uint_t uiProp=(uint_t)(m_pvProps->size()-1); + + m_lock.unlock(); + + return uiProp; +} + +/** Function retrieves the value as string. + * + * \param[in] uiProp - property to retrieve the value of + * \param[out] pszBuffer - pointer to a buffer to receive the string (unused + * if retrieving a string value) + * \param[in] stMaxSize - size of the buffer + * \param[in] stIndex - index of the value to retrieve (meaningful only for + * array-based properties) + * \return Pointer to the string. + * + * \note Always use the returned value instead of the buffer contents. Returned + * value may point to some other memory location instead of pszBuffer. + */ +const tchar_t* config::get_value(uint_t uiProp, tchar_t* pszBuffer, size_t stMaxSize, size_t stIndex) +{ + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + const tchar_t* psz=m_pvProps->at(uiProp).get_value(pszBuffer, stMaxSize, stIndex); + m_lock.unlock(); + + return psz; +} + +/** Function retrieves the signed number value. + * + * \param[in] uiProp - property to retrieve the value of + * \param[in] stIndex - index of the value to retrieve (meaningful only for + * array-based properties) + * \return Property value. + */ +ll_t config::get_signed_num(uint_t uiProp, size_t stIndex) +{ + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + ll_t ll=m_pvProps->at(uiProp).get_signed_num(stIndex); + m_lock.unlock(); + return ll; +} + +/** Function retrieves the unsigned number value. + * + * \param[in] uiProp - property to retrieve the value of + * \param[in] stIndex - index of the value to retrieve (meaningful only for + * array-based properties) + * \return Property value. + */ +ull_t config::get_unsigned_num(uint_t uiProp, size_t stIndex) +{ + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + ull_t ull=m_pvProps->at(uiProp).get_unsigned_num(stIndex); + m_lock.unlock(); + return ull; +} + +/** Function retrieves the bool value. + * + * \param[in] uiProp - property to retrieve the value of + * \param[in] stIndex - index of the value to retrieve (meaningful only for + * array-based properties) + * \return Property value. + */ +bool config::get_bool(uint_t uiProp, size_t stIndex) +{ + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + bool b=m_pvProps->at(uiProp).get_bool(stIndex); + m_lock.unlock(); + return b; +} + +/** Function retrieves the string value. + * + * \param[in] uiProp - property to retrieve the value of + * \param[in] stIndex - index of the value to retrieve (meaningful only for + * array-based properties) + * \return Property value. + */ +const tchar_t* config::get_string(uint_t uiProp, size_t stIndex) +{ + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + const tchar_t* psz=m_pvProps->at(uiProp).get_string(stIndex); + m_lock.unlock(); + + return psz; +} + +/** Function retrieves the string value. +* +* \param[in] uiProp - property to retrieve the value of +* \param[in] stIndex - index of the value to retrieve (meaningful only for +* array-based properties) +* \return Property value. +*/ +const tchar_t* config::get_string(uint_t uiProp, tchar_t* pszBuffer, size_t stBufferSize, size_t stIndex) +{ + if(!pszBuffer || stBufferSize < 1) + return NULL; + + m_lock.lock(); + if(uiProp >= m_pvProps->size()) + { + m_lock.unlock(); + THROW(_t("Index out of range"), 0, 0, 0); + } + size_t stLen = 0; + const tchar_t* psz=m_pvProps->at(uiProp).get_string(stIndex); + if(psz) + { + stLen = _tcslen(psz); + if(stLen >= stBufferSize) + stLen = stBufferSize - 1; + + _tcsncpy(pszBuffer, psz, stLen); + } + pszBuffer[stLen] = _t('\0'); + m_lock.unlock(); + return pszBuffer; +} + +bool config::enum_properties(const tchar_t* pszName, PFNCFGENUMCALLBACK pfn, ptr_t pParam) +{ + ptr_t pFind = m_pCfgBase->find(pszName); + if(pFind) + { + PROPINFO pi; + while(m_pCfgBase->find_next(pFind, pi)) + { + (*pfn)(pi.bGroup, pi.pszName, pi.pszValue, pParam); + } + + m_pCfgBase->find_close(pFind); + return true; + } + else + return false; +} + +/** Function sets the property value from string. + * + * \param[in] uiProp - property id to set the value for + * \param[in] pszVal - string with property value + * \param[in] a - action to take if the property is array based + * \param[in] tIndex - index of a value to set at (for action action_setat) + * \param[out] pTracker - property tracker that collects the property ID's + */ +void config::set_value(uint_t uiProp, const tchar_t* pszVal, property::actions a, size_t tIndex, property_tracker* pTracker) +{ + m_lock.lock(); + m_pvProps->at(uiProp).set_value(pszVal, a, tIndex); + if(pTracker) + pTracker->add(uiProp); + m_lock.unlock(); + property_changed_notify(uiProp); +} + +/** Function sets the signed number property value. + * + * \param[in] uiProp - property id to set the value for + * \param[in] llVal - property value to set + * \param[in] a - action to take if the property is array based + * \param[in] tIndex - index of a value to set at (for action action_setat) + * \param[out] pTracker - property tracker that collects the property ID's + */ +void config::set_signed_num(uint_t uiProp, ll_t llVal, property::actions a, size_t tIndex, property_tracker* pTracker) +{ + m_lock.lock(); + m_pvProps->at(uiProp).set_signed_num(llVal, a, tIndex); + if(pTracker) + pTracker->add(uiProp); + m_lock.unlock(); + property_changed_notify(uiProp); +} + +/** Function sets the unsigned number property value. + * + * \param[in] uiProp - property id to set the value for + * \param[in] llVal - property value to set + * \param[in] a - action to take if the property is array based + * \param[in] tIndex - index of a value to set at (for action action_setat) + * \param[out] pTracker - property tracker that collects the property ID's + */ +void config::set_unsigned_num(uint_t uiProp, ull_t ullVal, property::actions a, size_t tIndex, property_tracker* pTracker) +{ + m_lock.lock(); + m_pvProps->at(uiProp).set_unsigned_num(ullVal, a, tIndex); + if(pTracker) + pTracker->add(uiProp); + m_lock.unlock(); + property_changed_notify(uiProp); +} + +/** Function sets the bool property value. + * + * \param[in] uiProp - property id to set the value for + * \param[in] llVal - property value to set + * \param[in] a - action to take if the property is array based + * \param[in] tIndex - index of a value to set at (for action action_setat) + * \param[out] pTracker - property tracker that collects the property ID's + */ +void config::set_bool(uint_t uiProp, bool bVal, property::actions a, size_t tIndex, property_tracker* pTracker) +{ + m_lock.lock(); + m_pvProps->at(uiProp).set_bool(bVal, a, tIndex); + if(pTracker) + pTracker->add(uiProp); + m_lock.unlock(); + property_changed_notify(uiProp); +} + +/** Function sets the string property value. + * + * \param[in] uiProp - property id to set the value for + * \param[in] llVal - property value to set + * \param[in] a - action to take if the property is array based + * \param[in] tIndex - index of a value to set at (for action action_setat) + * \param[out] pTracker - property tracker that collects the property ID's + */ +void config::set_string(uint_t uiProp, const tchar_t* pszVal, property::actions a, size_t tIndex, property_tracker* pTracker) +{ + m_lock.lock(); + m_pvProps->at(uiProp).set_string(pszVal, a, tIndex); + if(pTracker) + pTracker->add(uiProp); + m_lock.unlock(); + property_changed_notify(uiProp); +} + +/** Sets the string manually, without using registered properties; does not notify about change. +* +* \param[in] pszName - name of the property +* \param[in] pszVal - value of the property +* \param[in] a - action to take if the property is array based +* \param[in] tIndex - index of a value to set at (for action action_setat) +*/ +void config::set_string(const tchar_t* pszName, const tchar_t* pszVal, property::actions a) +{ + config_base::actions action; + switch(a) + { + case property::action_add: + action = config_base::action_add; + break; + case property::action_replace: + action = config_base::action_replace; + break; + default: + THROW(_t("Undefined or unsupported action."), 0, 0, 0); + } + m_pCfgBase->set_value(pszName, pszVal, action); +} + +/** Function sets the callback function to be called on property change. + * \param[in] pfnCallback - pointer to the function + * \param[in] pParam - user defined parameter to pass to the callback + */ +void config::set_callback(PFNPROPERTYCHANGED pfnCallback, ptr_t pParam) +{ + m_pfnNotifyCallback = pfnCallback; + m_pCallbackParam = pParam; +} + +/** Function reads the values for the registered properties from the underlying + * base config object. + */ +void config::load_registered() +{ + m_lock.lock(); + + ptr_t hFind=NULL; + for (std::vector::iterator it=m_pvProps->begin();it != m_pvProps->end();it++) + { + // is this an array property ? + if((*it).is_array()) + (*it).clear_array(); + + // and fill with value(s) + if( (hFind=m_pCfgBase->find((*it).get_name())) != NULL) + { + PROPINFO pi; + while(m_pCfgBase->find_next(hFind, pi)) + { + assert(!pi.bGroup); + (*it).set_value(pi.pszValue, property::action_add); + } + } + + m_pCfgBase->find_close(hFind); + } + + m_lock.unlock(); +} + +/** Function stores the values of a registered properties to the underlying + * base config object. + */ +void config::store_registered() +{ + m_lock.lock(); + + tchar_t szBuffer[128]; + for (std::vector::iterator it=m_pvProps->begin();it != m_pvProps->end();it++) + { + // clear the current attributes for the property + m_pCfgBase->clear((*it).get_name()); + + // and fill with value(s) + size_t tCount=(*it).get_count(); + for (size_t t=0;t != tCount;t++) + { + m_pCfgBase->set_value((*it).get_name(), (*it).get_value(szBuffer, 128, t)); + } + } + + m_lock.unlock(); +} + +/** Function executes the callback to notify about property value change. + * \param[in] uiPropID - property ID that changed + */ +void config::property_changed_notify(uint_t uiPropID) +{ + if(m_pfnNotifyCallback) + (*m_pfnNotifyCallback)(uiPropID, m_pCallbackParam); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/cfg.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/cfg.cpp (revision 0) @@ -1,844 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file cfg.cpp - * \brief A placeholder for config class definitions. - * \todo Modify the class to use file class as a file access layer. - */ - -#include "cfg.h" -#include -#include "exception.h" -#include -#include -#include "err_codes.h" -#include "cfg_xml.h" -#include "cfg_ini.h" - -BEGIN_ICPF_NAMESPACE - -////////////////////////////////////////////////////////////////////////////////// -// property_tracker class -#define m_psProperties ((std::set*)m_hProperties) - -/** Constructs the property_tracker object. - */ -property_tracker::property_tracker() : - m_hProperties((ptr_t)new std::set) -{ -} - -/** Constructs the property_tracker by copying data from source object. - * - * \param[in] rSrc - source property tracker - */ -property_tracker::property_tracker(const property_tracker& rSrc) : - m_hProperties((ptr_t)new std::set(*(std::set*)rSrc.m_hProperties)) -{ -} - -/** Destructs the property tracker object. - */ -property_tracker::~property_tracker() -{ - delete m_psProperties; -} - -/** Function adds a new property id to the group. - * - * \param[in] uiProp - id of a property to add - */ -void property_tracker::add(uint_t uiProp) -{ - m_psProperties->insert(uiProp); -} - -/** Function searches for a specific property id inside the list. - * - * \param[in] uiProp - property id to check for - * \return True if the property has been found, false if not. - */ -bool property_tracker::is_set(uint_t uiProp) -{ - return m_psProperties->find(uiProp) != m_psProperties->end(); -} - -/** Function returns a count of properties contained in the list. - * - * \return A count of id's. - */ -size_t property_tracker::count() const -{ - return m_psProperties->size(); -} - -/** Function retrieves the id's contained in this tracker by copying - * them to the given array. - * - * \param[out] puiProps - pointer to the array of uint's to receive id's - * \param[in] stMaxCount - size of the array (max count of elements to retrieve) - */ -size_t property_tracker::get_ids(uint_t* puiProps, size_t stMaxCount) -{ - size_t tIndex=0; - for (std::set::iterator it=m_psProperties->begin();it != m_psProperties->end();it++) - { - puiProps[tIndex++]=(*it); - if(tIndex >= stMaxCount) - break; - } - - return tIndex; -} - -/** Function enumerates id's contained in this property_tracker using - * a callback function. - * - * \param[in] pfn - function to be called - * \param[in] pParam - parameter to pass to the callback - */ -void property_tracker::enum_ids(bool(*pfn)(uint_t uiProp, ptr_t pParam), ptr_t pParam) -{ - for (std::set::iterator it=m_psProperties->begin();it != m_psProperties->end();it++) - { - if(!(*pfn)((*it), pParam)) - break; - } -} - -///////////////////////////////////////////////////////////////////////////////////// -// config class - -#define m_pvProps ((std::vector*)m_hProps) - -/** Constructs a config object. - * \param[in] pCfgBase - pointer to a base handler of the configuration strings - * cound be pointer to xml handler, ini handler or any other - */ -config::config(config_base_types eCfgType) : - m_lock(), - m_hProps((ptr_t)new std::vector), - m_pszCurrentPath(NULL) -{ - switch(eCfgType) - { - //case eXml: - // m_pCfgBase = new xml_cfg; - // break; - case eIni: - m_pCfgBase = new ini_cfg; - break; - default: - THROW(_t("Undefined config base type"), 0, 0, 0); - } -} - -/** Destructs the config class. - */ -config::~config() -{ - delete m_pvProps; - delete [] m_pszCurrentPath; - delete m_pCfgBase; -} - -/** Function opens the specified file using the underlying config base - * and converts the values read to a list of properties registered - * earlier. - * - * \param[in] pszPath - path to a file to be read - */ -void config::read(const tchar_t* pszPath) -{ - assert(pszPath); - if(!pszPath) - THROW(_T("Path to the file not provided."), FERR_OPEN, 0, 0); - - // remembering path before operation and not freeing it on fail is done on purpose here - // (to support future write() to this file in case file does not exist yet) - size_t stLen = _tcslen(pszPath); - if(stLen) - { - delete [] m_pszCurrentPath; - m_pszCurrentPath = new tchar_t[stLen + 1]; - _tcscpy(m_pszCurrentPath, pszPath); - m_pszCurrentPath[stLen] = _t('\0'); - } - - m_lock.lock(); - try - { - // read the data using underlying object - m_pCfgBase->read(pszPath); - - // and transform it to eatable form using registered properties - load_registered(); - } - catch(...) - { - m_lock.unlock(); - throw; - } - m_lock.unlock(); -} - -/** Reads the configuration data from the provided buffer. - * - * \param[in] pszData - pointer to the buffer with data - * \param[in] stSize - size of the data in buffer - */ -void config::read_from_buffer(const tchar_t* pszData, size_t stSize) -{ - m_lock.lock(); - try - { - m_pCfgBase->read_from_buffer(pszData, stSize); - - // and transform it to eatable form using registered properties - load_registered(); - } - catch(...) - { - m_lock.unlock(); - throw; - } - m_lock.unlock(); -} - -/** Writes all the registered properties into the given file using - * the underlying config base to do this. - * - * \param[in] pszPath - path to a file to write the properties to - */ -void config::write(const tchar_t* pszPath) -{ - if(!m_pszCurrentPath && !pszPath) - THROW(_T("No path specified"), FERR_OPEN, 0, 0); - m_lock.lock(); - - try - { - // store current properties to the underlying object - store_registered(); - - if(pszPath) - { - size_t stLen = _tcslen(pszPath); - if(stLen) - { - delete [] m_pszCurrentPath; - m_pszCurrentPath = new tchar_t[stLen + 1]; - _tcscpy(m_pszCurrentPath, pszPath); - m_pszCurrentPath[stLen] = _t('\0'); - } - } - - // and save - m_pCfgBase->save(m_pszCurrentPath); - } - catch(...) - { - m_lock.unlock(); - throw; - } - - m_lock.unlock(); -} - -/** Function returns a property type for a given property id. - * - * \param[in] uiProp - property id to get info about - * \return The property type along with its flags. - */ -uint_t config::get_type(uint_t uiProp) -{ - m_lock.lock(); - uint_t uiRet=m_pvProps->at(uiProp).get_type(); - m_lock.unlock(); - - return uiRet; -} - -/** Retrieves the count of values in the specified property. - * - * \param[in] uiProp - property id to retrieve information about - * \return Count of values. - */ -size_t config::get_value_count(uint_t uiProp) -{ - m_lock.lock(); - size_t stRet=m_pvProps->at(uiProp).get_count(); - m_lock.unlock(); - - return stRet; -} - -/** Removes an array value at a given index. - * - * \param[in] uiProp - property id to have the value removed - * \param[in] stIndex - index of the value to remove - */ -void config::remove_array_value(uint_t uiProp, size_t stIndex) -{ - m_lock.lock(); - m_pvProps->at(uiProp).remove(stIndex); - m_lock.unlock(); -} - -/** Clears the list of values in the given property. - * - * \param[in] uiProp - property id to have the values cleared - */ -void config::clear_array_values(uint_t uiProp) -{ - m_lock.lock(); - m_pvProps->at(uiProp).clear_array(); - m_lock.unlock(); -} - -/** Retrieves the count of registered properties contained in this config. - * - * \return Count of properties. - */ -size_t config::count() -{ - return m_pvProps->size(); -} - -/** Function registers the signed number property. If the underlying base object - * contains a string with a specified key - the value is being translated to - * the value of this property. - * - * \param[in] pszName - name of the property - * \param[in] llDef - default value for the property - * \param[in] llLo - the lower bound of the allowable value range - * \param[in] llHi - the higher bound of the allowable value range - * \param[in] uiFlags - additional flags that should be associated with property - * \return Property ID of the newly registered property. - */ -uint_t config::register_signed_num(const tchar_t* pszName, ll_t llDef, ll_t llLo, ll_t llHi, uint_t uiFlags) -{ - // prepare the property to insert - property prop(pszName, property::type_signed_num | (uiFlags & property::mask_flags)); - prop.set_signed_range(llLo, llHi); - - // and operate inside the internals - m_lock.lock(); - - // get the value for the property name - ptr_t hFind=NULL; - if( (hFind=m_pCfgBase->find(pszName)) != NULL ) - { - PROPINFO pi; - while(m_pCfgBase->find_next(hFind, pi)) - { - assert(!pi.bGroup); - prop.set_value(pi.pszValue, property::action_add); - } - - m_pCfgBase->find_close(hFind); - } - else if(!(uiFlags & property::flag_array)) - prop.set_signed_num(llDef); - - // add to the vector - m_pvProps->push_back(prop); - uint_t uiProp=(uint_t)(m_pvProps->size()-1); - - m_lock.unlock(); - - return uiProp; -} - -/** Function registers the unsigned number property. If the underlying base object - * contains a string with a specified key - the value is being translated to - * the value of this property. - * - * \param[in] pszName - name of the property - * \param[in] ullDef - default value for the property - * \param[in] ullLo - the lower bound of the allowable value range - * \param[in] ullHi - the higher bound of the allowable value range - * \param[in] uiFlags - additional flags that should be associated with property - * \return Property ID of the newly registered property. - */ -uint_t config::register_unsigned_num(const tchar_t* pszName, ull_t ullDef, ull_t ullLo, ull_t ullHi, uint_t uiFlags) -{ - // prepare the property to insert - property prop(pszName, property::type_unsigned_num | (uiFlags & property::mask_flags)); - prop.set_unsigned_range(ullLo, ullHi); - - // and operate inside the internals - m_lock.lock(); - - // get the value for the property name - ptr_t hFind=NULL; - if( (hFind=m_pCfgBase->find(pszName)) != NULL ) - { - PROPINFO pi; - while(m_pCfgBase->find_next(hFind, pi)) - { - assert(!pi.bGroup); - prop.set_value(pi.pszValue, property::action_add); - } - - m_pCfgBase->find_close(hFind); - } - else if(!(uiFlags & property::flag_array)) - prop.set_unsigned_num(ullDef); - - // add to the vector - m_pvProps->push_back(prop); - uint_t uiProp=(uint_t)(m_pvProps->size()-1); - - m_lock.unlock(); - - return uiProp; -} - -/** Function registers the boolean property. If the underlying base object - * contains a string with a specified key - the value is being translated to - * the value of this property. - * - * \param[in] pszName - name of the property - * \param[in] bDef - default value for the property - * \param[in] uiFlags - additional flags that should be associated with property - * \return Property ID of the newly registered property. - */ -uint_t config::register_bool(const tchar_t* pszName, bool bDef, uint_t uiFlags) -{ - // prepare the property to insert - property prop(pszName, property::type_bool | (uiFlags & property::mask_flags)); - - // and operate inside the internals - m_lock.lock(); - - // get the value for the property name - ptr_t hFind=NULL; - if( (hFind=m_pCfgBase->find(pszName)) != NULL ) - { - PROPINFO pi; - while(m_pCfgBase->find_next(hFind, pi)) - { - assert(!pi.bGroup); - prop.set_value(pi.pszValue, property::action_add); - } - - m_pCfgBase->find_close(hFind); - } - else if(!(uiFlags & property::flag_array)) - prop.set_bool(bDef); - - // add to the vector - m_pvProps->push_back(prop); - uint_t uiProp=(uint_t)(m_pvProps->size()-1); - - m_lock.unlock(); - - return uiProp; -} - -/** Function registers the string property. If the underlying base object - * contains a string with a specified key - the value is being translated to - * the value of this property. - * - * \param[in] pszName - name of the property - * \param[in] pszDef - default value for the property - * \param[in] uiFlags - additional flags that should be associated with property - * \return Property ID of the newly registered property. - */ -uint_t config::register_string(const tchar_t* pszName, const tchar_t* pszDef, uint_t uiFlags) -{ - // prepare the property to insert - property prop(pszName, property::type_string | (uiFlags & property::mask_flags)); - - // and operate inside the internals - m_lock.lock(); - - // get the value for the property name - ptr_t hFind=NULL; - if( (hFind=m_pCfgBase->find(pszName)) != NULL ) - { - PROPINFO pi; - while(m_pCfgBase->find_next(hFind, pi)) - { - assert(!pi.bGroup); - prop.set_value(pi.pszValue, property::action_add); - } - - m_pCfgBase->find_close(hFind); - } - else if(!(uiFlags & property::flag_array)) - prop.set_string(pszDef); - - // add to the vector - m_pvProps->push_back(prop); - uint_t uiProp=(uint_t)(m_pvProps->size()-1); - - m_lock.unlock(); - - return uiProp; -} - -/** Function retrieves the value as string. - * - * \param[in] uiProp - property to retrieve the value of - * \param[out] pszBuffer - pointer to a buffer to receive the string (unused - * if retrieving a string value) - * \param[in] stMaxSize - size of the buffer - * \param[in] stIndex - index of the value to retrieve (meaningful only for - * array-based properties) - * \return Pointer to the string. - * - * \note Always use the returned value instead of the buffer contents. Returned - * value may point to some other memory location instead of pszBuffer. - */ -const tchar_t* config::get_value(uint_t uiProp, tchar_t* pszBuffer, size_t stMaxSize, size_t stIndex) -{ - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - const tchar_t* psz=m_pvProps->at(uiProp).get_value(pszBuffer, stMaxSize, stIndex); - m_lock.unlock(); - - return psz; -} - -/** Function retrieves the signed number value. - * - * \param[in] uiProp - property to retrieve the value of - * \param[in] stIndex - index of the value to retrieve (meaningful only for - * array-based properties) - * \return Property value. - */ -ll_t config::get_signed_num(uint_t uiProp, size_t stIndex) -{ - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - ll_t ll=m_pvProps->at(uiProp).get_signed_num(stIndex); - m_lock.unlock(); - return ll; -} - -/** Function retrieves the unsigned number value. - * - * \param[in] uiProp - property to retrieve the value of - * \param[in] stIndex - index of the value to retrieve (meaningful only for - * array-based properties) - * \return Property value. - */ -ull_t config::get_unsigned_num(uint_t uiProp, size_t stIndex) -{ - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - ull_t ull=m_pvProps->at(uiProp).get_unsigned_num(stIndex); - m_lock.unlock(); - return ull; -} - -/** Function retrieves the bool value. - * - * \param[in] uiProp - property to retrieve the value of - * \param[in] stIndex - index of the value to retrieve (meaningful only for - * array-based properties) - * \return Property value. - */ -bool config::get_bool(uint_t uiProp, size_t stIndex) -{ - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - bool b=m_pvProps->at(uiProp).get_bool(stIndex); - m_lock.unlock(); - return b; -} - -/** Function retrieves the string value. - * - * \param[in] uiProp - property to retrieve the value of - * \param[in] stIndex - index of the value to retrieve (meaningful only for - * array-based properties) - * \return Property value. - */ -const tchar_t* config::get_string(uint_t uiProp, size_t stIndex) -{ - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - const tchar_t* psz=m_pvProps->at(uiProp).get_string(stIndex); - m_lock.unlock(); - - return psz; -} - -/** Function retrieves the string value. -* -* \param[in] uiProp - property to retrieve the value of -* \param[in] stIndex - index of the value to retrieve (meaningful only for -* array-based properties) -* \return Property value. -*/ -const tchar_t* config::get_string(uint_t uiProp, tchar_t* pszBuffer, size_t stBufferSize, size_t stIndex) -{ - if(!pszBuffer || stBufferSize < 1) - return NULL; - - m_lock.lock(); - if(uiProp >= m_pvProps->size()) - { - m_lock.unlock(); - THROW(_t("Index out of range"), 0, 0, 0); - } - size_t stLen = 0; - const tchar_t* psz=m_pvProps->at(uiProp).get_string(stIndex); - if(psz) - { - stLen = _tcslen(psz); - if(stLen >= stBufferSize) - stLen = stBufferSize - 1; - - _tcsncpy(pszBuffer, psz, stLen); - } - pszBuffer[stLen] = _t('\0'); - m_lock.unlock(); - return pszBuffer; -} - -bool config::enum_properties(const tchar_t* pszName, PFNCFGENUMCALLBACK pfn, ptr_t pParam) -{ - ptr_t pFind = m_pCfgBase->find(pszName); - if(pFind) - { - PROPINFO pi; - while(m_pCfgBase->find_next(pFind, pi)) - { - (*pfn)(pi.bGroup, pi.pszName, pi.pszValue, pParam); - } - - m_pCfgBase->find_close(pFind); - return true; - } - else - return false; -} - -/** Function sets the property value from string. - * - * \param[in] uiProp - property id to set the value for - * \param[in] pszVal - string with property value - * \param[in] a - action to take if the property is array based - * \param[in] tIndex - index of a value to set at (for action action_setat) - * \param[out] pTracker - property tracker that collects the property ID's - */ -void config::set_value(uint_t uiProp, const tchar_t* pszVal, property::actions a, size_t tIndex, property_tracker* pTracker) -{ - m_lock.lock(); - m_pvProps->at(uiProp).set_value(pszVal, a, tIndex); - if(pTracker) - pTracker->add(uiProp); - m_lock.unlock(); - property_changed_notify(uiProp); -} - -/** Function sets the signed number property value. - * - * \param[in] uiProp - property id to set the value for - * \param[in] llVal - property value to set - * \param[in] a - action to take if the property is array based - * \param[in] tIndex - index of a value to set at (for action action_setat) - * \param[out] pTracker - property tracker that collects the property ID's - */ -void config::set_signed_num(uint_t uiProp, ll_t llVal, property::actions a, size_t tIndex, property_tracker* pTracker) -{ - m_lock.lock(); - m_pvProps->at(uiProp).set_signed_num(llVal, a, tIndex); - if(pTracker) - pTracker->add(uiProp); - m_lock.unlock(); - property_changed_notify(uiProp); -} - -/** Function sets the unsigned number property value. - * - * \param[in] uiProp - property id to set the value for - * \param[in] llVal - property value to set - * \param[in] a - action to take if the property is array based - * \param[in] tIndex - index of a value to set at (for action action_setat) - * \param[out] pTracker - property tracker that collects the property ID's - */ -void config::set_unsigned_num(uint_t uiProp, ull_t ullVal, property::actions a, size_t tIndex, property_tracker* pTracker) -{ - m_lock.lock(); - m_pvProps->at(uiProp).set_unsigned_num(ullVal, a, tIndex); - if(pTracker) - pTracker->add(uiProp); - m_lock.unlock(); - property_changed_notify(uiProp); -} - -/** Function sets the bool property value. - * - * \param[in] uiProp - property id to set the value for - * \param[in] llVal - property value to set - * \param[in] a - action to take if the property is array based - * \param[in] tIndex - index of a value to set at (for action action_setat) - * \param[out] pTracker - property tracker that collects the property ID's - */ -void config::set_bool(uint_t uiProp, bool bVal, property::actions a, size_t tIndex, property_tracker* pTracker) -{ - m_lock.lock(); - m_pvProps->at(uiProp).set_bool(bVal, a, tIndex); - if(pTracker) - pTracker->add(uiProp); - m_lock.unlock(); - property_changed_notify(uiProp); -} - -/** Function sets the string property value. - * - * \param[in] uiProp - property id to set the value for - * \param[in] llVal - property value to set - * \param[in] a - action to take if the property is array based - * \param[in] tIndex - index of a value to set at (for action action_setat) - * \param[out] pTracker - property tracker that collects the property ID's - */ -void config::set_string(uint_t uiProp, const tchar_t* pszVal, property::actions a, size_t tIndex, property_tracker* pTracker) -{ - m_lock.lock(); - m_pvProps->at(uiProp).set_string(pszVal, a, tIndex); - if(pTracker) - pTracker->add(uiProp); - m_lock.unlock(); - property_changed_notify(uiProp); -} - -/** Sets the string manually, without using registered properties; does not notify about change. -* -* \param[in] pszName - name of the property -* \param[in] pszVal - value of the property -* \param[in] a - action to take if the property is array based -* \param[in] tIndex - index of a value to set at (for action action_setat) -*/ -void config::set_string(const tchar_t* pszName, const tchar_t* pszVal, property::actions a) -{ - config_base::actions action; - switch(a) - { - case property::action_add: - action = config_base::action_add; - break; - case property::action_replace: - action = config_base::action_replace; - break; - default: - THROW(_t("Undefined or unsupported action."), 0, 0, 0); - } - m_pCfgBase->set_value(pszName, pszVal, action); -} - -/** Function sets the callback function to be called on property change. - * \param[in] pfnCallback - pointer to the function - * \param[in] pParam - user defined parameter to pass to the callback - */ -void config::set_callback(PFNPROPERTYCHANGED pfnCallback, ptr_t pParam) -{ - m_pfnNotifyCallback = pfnCallback; - m_pCallbackParam = pParam; -} - -/** Function reads the values for the registered properties from the underlying - * base config object. - */ -void config::load_registered() -{ - m_lock.lock(); - - ptr_t hFind=NULL; - for (std::vector::iterator it=m_pvProps->begin();it != m_pvProps->end();it++) - { - // is this an array property ? - if((*it).is_array()) - (*it).clear_array(); - - // and fill with value(s) - if( (hFind=m_pCfgBase->find((*it).get_name())) != NULL) - { - PROPINFO pi; - while(m_pCfgBase->find_next(hFind, pi)) - { - assert(!pi.bGroup); - (*it).set_value(pi.pszValue, property::action_add); - } - } - - m_pCfgBase->find_close(hFind); - } - - m_lock.unlock(); -} - -/** Function stores the values of a registered properties to the underlying - * base config object. - */ -void config::store_registered() -{ - m_lock.lock(); - - tchar_t szBuffer[128]; - for (std::vector::iterator it=m_pvProps->begin();it != m_pvProps->end();it++) - { - // clear the current attributes for the property - m_pCfgBase->clear((*it).get_name()); - - // and fill with value(s) - size_t tCount=(*it).get_count(); - for (size_t t=0;t != tCount;t++) - { - m_pCfgBase->set_value((*it).get_name(), (*it).get_value(szBuffer, 128, t)); - } - } - - m_lock.unlock(); -} - -/** Function executes the callback to notify about property value change. - * \param[in] uiPropID - property ID that changed - */ -void config::property_changed_notify(uint_t uiPropID) -{ - if(m_pfnNotifyCallback) - (*m_pfnNotifyCallback)(uiPropID, m_pCallbackParam); -} - -END_ICPF_NAMESPACE Index: src/libicpf/cfg.h =================================================================== diff -u -N --- src/libicpf/cfg.h (revision 0) +++ src/libicpf/cfg.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,186 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CFG_H__ +#define __CFG_H__ + +/** \file cfg.h + * \brief A placeholder for config class. + */ +#include "mutex.h" +#include "libicpf.h" +#include "gen_types.h" +#include "config_base.h" +#include "config_property.h" + +BEGIN_ICPF_NAMESPACE + +/// Callback function definition +typedef void(*PFNPROPERTYCHANGED)(uint_t, ptr_t); +/// Enumeration callback +typedef void(*PFNCFGENUMCALLBACK)(bool, const tchar_t*, const tchar_t*, ptr_t); + +/** \brief Property group handling class + * + * Class is being used to manipulate the property groups (in connection with config::begin_group() and + * config::end_group(). + */ +class LIBICPF_API property_tracker +{ +public: +/** \name Construction/destruction/operators */ +/**@{*/ + property_tracker(); ///< Standard constructor + property_tracker(const property_tracker& rSrc); ///< Copy constructor + ~property_tracker(); ///< Standard destructor + + property_tracker& operator=(const property_tracker& rSrc); ///< Assignment operator +/**@}*/ + +/** \name Operations */ +/**@{*/ + void add(uint_t uiProp); ///< Adds a new property id to the list + bool is_set(uint_t uiProp); ///< Checks if a property id is set inside this list + size_t count() const; ///< Returns a count of properties in a list + + /// Retrieves the list of ID's + size_t get_ids(uint_t* puiProps, size_t stMaxCount); + /// Retrieves the list of ID's using an enumeration function + void enum_ids(bool(*pfn)(uint_t uiProp, ptr_t pParam), ptr_t pParam); +/**@}*/ + +protected: + ptr_t m_hProperties; ///< Internal member. Pointer to a storage structure with an int_t. +}; + +/** \brief Configuration management class. + * + * Class allows user to read and write configuration file in standard unix + * format (comments, empty lines and key=value strings). Class is fully thread-safe. + * Access to the properties is done by registering one and then getting or setting + * a value using the property identifier. + */ +class LIBICPF_API config +{ +public: + enum config_base_types + { + eXml, + eIni + }; +public: +/** \name Construction/destruction */ +/**@{*/ + config(config_base_types eCfgType); ///< Standard constructor + virtual ~config(); ///< Standard destructor +/**@}*/ + +/** \name Reading and writing to the external medium */ +/**@{*/ + void read(const tchar_t *pszPath); ///< Reads the properties from the source file + void read_from_buffer(const tchar_t* pszData, size_t stSize); + void write(const tchar_t* pszPath); ///< Saves the properties to the file +/**@}*/ + +/** \name Class lock/unlock functions */ +/**@{*/ + /// Locks the config class for one thread + void lock() { m_lock.lock(); }; + /// Unlocks the class + void unlock() { m_lock.unlock(); }; +/**@}*/ + + // property type management +/** Property types */ +/**@{*/ + uint_t get_type(uint_t uiProp); ///< Retrieves the property type + size_t get_value_count(uint_t uiProp); ///< Retrieves the count of values for array-based property types + void remove_array_value(uint_t uiProp, size_t stIndex); ///< Removes a value at a specified index in array-based property type + void clear_array_values(uint_t uiProp); ///< Removes all values in array-based property + size_t count(); ///< Retrieves the count of properties contained in this config +/**@}*/ + + // registering the properties +/** \name Properties registration functions */ +/**@{*/ + /// Registers signed number-type property + uint_t register_signed_num(const tchar_t* pszName, ll_t llDef, ll_t llLo, ll_t llHi, uint_t uiFlags=property::flag_none); + /// Registers unsigned number-type property + uint_t register_unsigned_num(const tchar_t* pszName, ull_t ullDef, ull_t ullLo, ull_t ullHi, uint_t uiFlags=property::flag_none); + /// Registers bool-type property + uint_t register_bool(const tchar_t* pszName, bool bDef, uint_t uiFlags=property::flag_none); + /// Registers string-type property + uint_t register_string(const tchar_t* pszName, const tchar_t* pszDef, uint_t uiFlags=property::flag_none); +/**@}*/ + + // getting property data +/** \name Getting and setting values */ +/**@{*/ + /// Gets the value of string-type property + const tchar_t* get_value(uint_t uiProp, tchar_t* pszBuffer, size_t stMaxSize, size_t stIndex=0); + /// Gets the value of longlong_t-type property + ll_t get_signed_num(uint_t uiProp, size_t stIndex=0); + /// Gets the value of ulonglong_t-type property + ull_t get_unsigned_num(uint_t uiProp, size_t stIndex=0); + /// Gets the value of bool-type property + bool get_bool(uint_t uiProp, size_t stIndex=0); + /// Gets the value of string-type property + const tchar_t* get_string(uint_t uiProp, size_t stIndex=0); + /// Retrieves the copy of the string + const tchar_t* get_string(uint_t uiProp, tchar_t* pszBuffer, size_t stBufferSize, size_t stIndex=0); + + /// Enumerates attributes (and groups) + bool enum_properties(const tchar_t* pszName, PFNCFGENUMCALLBACK pfn, ptr_t pParam); + + // setting property data + /// Sets the value from the string + void set_value(uint_t uiProp, const tchar_t* pszVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); + /// Sets the value of longlong_t-type property + void set_signed_num(uint_t uiProp, ll_t llVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); + /// Sets the value of ulonglong_t-type property + void set_unsigned_num(uint_t uiProp, ull_t ullVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); + /// Sets the value of bool-type property + void set_bool(uint_t uiProp, bool bVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); + /// Sets the value of string-type property + void set_string(uint_t uiProp, const tchar_t* pszVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); + /// Sets the string manually, without using registered properties; does not notify about change. + void set_string(const tchar_t* pszName, const tchar_t* pszVal, property::actions a=property::action_replace); +/**@}*/ + +/** \name Notifications */ +/**@{*/ + void set_callback(PFNPROPERTYCHANGED pfnCallback, ptr_t pParam); +/**@}*/ + +protected: + void load_registered(); ///< Loads the registered property values from the underlying config base + void store_registered(); ///< Stores the registered property values to the underlying config base + + void property_changed_notify(uint_t uiPropID); ///< Calls the callback function to notify about the property value change +protected: + mutex m_lock; ///< Lock for the multi-threaded access to the properties + ptr_t m_hProps; ///< Handle to the registered property storage + config_base* m_pCfgBase; ///< Underlying base for this class + tchar_t* m_pszCurrentPath; ///< Current path (one specified when reading the file) + PFNPROPERTYCHANGED m_pfnNotifyCallback; ///< Function to be called when property changes + ptr_t m_pCallbackParam; ///< User-defined parameter to pass to the callback function +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/cfg.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/cfg.h (revision 0) @@ -1,186 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CFG_H__ -#define __CFG_H__ - -/** \file cfg.h - * \brief A placeholder for config class. - */ -#include "mutex.h" -#include "libicpf.h" -#include "gen_types.h" -#include "config_base.h" -#include "config_property.h" - -BEGIN_ICPF_NAMESPACE - -/// Callback function definition -typedef void(*PFNPROPERTYCHANGED)(uint_t, ptr_t); -/// Enumeration callback -typedef void(*PFNCFGENUMCALLBACK)(bool, const tchar_t*, const tchar_t*, ptr_t); - -/** \brief Property group handling class - * - * Class is being used to manipulate the property groups (in connection with config::begin_group() and - * config::end_group(). - */ -class LIBICPF_API property_tracker -{ -public: -/** \name Construction/destruction/operators */ -/**@{*/ - property_tracker(); ///< Standard constructor - property_tracker(const property_tracker& rSrc); ///< Copy constructor - ~property_tracker(); ///< Standard destructor - - property_tracker& operator=(const property_tracker& rSrc); ///< Assignment operator -/**@}*/ - -/** \name Operations */ -/**@{*/ - void add(uint_t uiProp); ///< Adds a new property id to the list - bool is_set(uint_t uiProp); ///< Checks if a property id is set inside this list - size_t count() const; ///< Returns a count of properties in a list - - /// Retrieves the list of ID's - size_t get_ids(uint_t* puiProps, size_t stMaxCount); - /// Retrieves the list of ID's using an enumeration function - void enum_ids(bool(*pfn)(uint_t uiProp, ptr_t pParam), ptr_t pParam); -/**@}*/ - -protected: - ptr_t m_hProperties; ///< Internal member. Pointer to a storage structure with an int_t. -}; - -/** \brief Configuration management class. - * - * Class allows user to read and write configuration file in standard unix - * format (comments, empty lines and key=value strings). Class is fully thread-safe. - * Access to the properties is done by registering one and then getting or setting - * a value using the property identifier. - */ -class LIBICPF_API config -{ -public: - enum config_base_types - { - eXml, - eIni - }; -public: -/** \name Construction/destruction */ -/**@{*/ - config(config_base_types eCfgType); ///< Standard constructor - virtual ~config(); ///< Standard destructor -/**@}*/ - -/** \name Reading and writing to the external medium */ -/**@{*/ - void read(const tchar_t *pszPath); ///< Reads the properties from the source file - void read_from_buffer(const tchar_t* pszData, size_t stSize); - void write(const tchar_t* pszPath); ///< Saves the properties to the file -/**@}*/ - -/** \name Class lock/unlock functions */ -/**@{*/ - /// Locks the config class for one thread - void lock() { m_lock.lock(); }; - /// Unlocks the class - void unlock() { m_lock.unlock(); }; -/**@}*/ - - // property type management -/** Property types */ -/**@{*/ - uint_t get_type(uint_t uiProp); ///< Retrieves the property type - size_t get_value_count(uint_t uiProp); ///< Retrieves the count of values for array-based property types - void remove_array_value(uint_t uiProp, size_t stIndex); ///< Removes a value at a specified index in array-based property type - void clear_array_values(uint_t uiProp); ///< Removes all values in array-based property - size_t count(); ///< Retrieves the count of properties contained in this config -/**@}*/ - - // registering the properties -/** \name Properties registration functions */ -/**@{*/ - /// Registers signed number-type property - uint_t register_signed_num(const tchar_t* pszName, ll_t llDef, ll_t llLo, ll_t llHi, uint_t uiFlags=property::flag_none); - /// Registers unsigned number-type property - uint_t register_unsigned_num(const tchar_t* pszName, ull_t ullDef, ull_t ullLo, ull_t ullHi, uint_t uiFlags=property::flag_none); - /// Registers bool-type property - uint_t register_bool(const tchar_t* pszName, bool bDef, uint_t uiFlags=property::flag_none); - /// Registers string-type property - uint_t register_string(const tchar_t* pszName, const tchar_t* pszDef, uint_t uiFlags=property::flag_none); -/**@}*/ - - // getting property data -/** \name Getting and setting values */ -/**@{*/ - /// Gets the value of string-type property - const tchar_t* get_value(uint_t uiProp, tchar_t* pszBuffer, size_t stMaxSize, size_t stIndex=0); - /// Gets the value of longlong_t-type property - ll_t get_signed_num(uint_t uiProp, size_t stIndex=0); - /// Gets the value of ulonglong_t-type property - ull_t get_unsigned_num(uint_t uiProp, size_t stIndex=0); - /// Gets the value of bool-type property - bool get_bool(uint_t uiProp, size_t stIndex=0); - /// Gets the value of string-type property - const tchar_t* get_string(uint_t uiProp, size_t stIndex=0); - /// Retrieves the copy of the string - const tchar_t* get_string(uint_t uiProp, tchar_t* pszBuffer, size_t stBufferSize, size_t stIndex=0); - - /// Enumerates attributes (and groups) - bool enum_properties(const tchar_t* pszName, PFNCFGENUMCALLBACK pfn, ptr_t pParam); - - // setting property data - /// Sets the value from the string - void set_value(uint_t uiProp, const tchar_t* pszVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); - /// Sets the value of longlong_t-type property - void set_signed_num(uint_t uiProp, ll_t llVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); - /// Sets the value of ulonglong_t-type property - void set_unsigned_num(uint_t uiProp, ull_t ullVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); - /// Sets the value of bool-type property - void set_bool(uint_t uiProp, bool bVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); - /// Sets the value of string-type property - void set_string(uint_t uiProp, const tchar_t* pszVal, property::actions a=property::action_replace, size_t tIndex=0, property_tracker* pTracker=NULL); - /// Sets the string manually, without using registered properties; does not notify about change. - void set_string(const tchar_t* pszName, const tchar_t* pszVal, property::actions a=property::action_replace); -/**@}*/ - -/** \name Notifications */ -/**@{*/ - void set_callback(PFNPROPERTYCHANGED pfnCallback, ptr_t pParam); -/**@}*/ - -protected: - void load_registered(); ///< Loads the registered property values from the underlying config base - void store_registered(); ///< Stores the registered property values to the underlying config base - - void property_changed_notify(uint_t uiPropID); ///< Calls the callback function to notify about the property value change -protected: - mutex m_lock; ///< Lock for the multi-threaded access to the properties - ptr_t m_hProps; ///< Handle to the registered property storage - config_base* m_pCfgBase; ///< Underlying base for this class - tchar_t* m_pszCurrentPath; ///< Current path (one specified when reading the file) - PFNPROPERTYCHANGED m_pfnNotifyCallback; ///< Function to be called when property changes - ptr_t m_pCallbackParam; ///< User-defined parameter to pass to the callback function -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/cfg_ini.cpp =================================================================== diff -u -N --- src/libicpf/cfg_ini.cpp (revision 0) +++ src/libicpf/cfg_ini.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,558 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "cfg_ini.h" +#include "exception.h" +#include +#include +#include +#include "str_help.h" + +BEGIN_ICPF_NAMESPACE + +/// Buffer size for reading xml data from a file +#define INI_BUFFER 65536 + +// definition of line ending - system dependent +#if defined(_WIN32) || defined(_WIN64) +#define ENDL _t("\r\n") +#else +#define ENDL _t("\n") +#endif + +#ifdef _UNICODE + #define TEOF WEOF +#else + #define TEOF EOF +#endif + +/// String storage (key(s)=>value(s)) +typedef std::multimap attr_storage; +/// Ini node storage +typedef std::map ini_storage; + +/** Xml find handle structure - used for searching. +*/ +struct INIFINDHANDLE +{ + attr_storage::iterator itAttr; ///< Iterator of currently retrieved string + attr_storage::iterator itAttrEnd; ///< Iterator of a last string matching the criteria + + ini_storage::iterator itSection; ///< Section iterator + ini_storage::iterator itSectionEnd; ///< End of section enumeration + + bool bOnlyAttributes; ///< Enumeration type - true = only attributes (does not use section iterators), false = sections + all attributes inside + bool bSection; ///< Is section to be enumerated first ? +}; + +/// Macro for faster access to the xml storage +#define m_pMainNode ((ini_storage*)m_hMainNode) + +/** Constructs the ini_cfg object. +*/ +ini_cfg::ini_cfg() : + m_hMainNode((ptr_t)new ini_storage) +{ + +} + +/** Destructs the xml config object. +*/ +ini_cfg::~ini_cfg() +{ + delete m_pMainNode; +} + +/** Function reads the contents of the xml file, parses itAttr using expat parser +* and then creates xml nodes in memory that could be read using find functions. +* +* \param[in] pszPath - path to the file to be read +*/ +void ini_cfg::read(const tchar_t* pszPath) +{ + // clear current contents + clear(); + + // read the data from file +#if defined(_UNICODE) && (defined(_WIN32) || defined(_WIN64)) + FILE* pFile=_tfopen(pszPath, _t("rb")); +#else + FILE* pFile=_tfopen(pszPath, _t("rt")); +#endif + + if(pFile == NULL) + THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for reading."), pszPath), 0, errno, 0); + + // prepare buffer for data + tchar_t* pszBuffer = new tchar_t[INI_BUFFER]; + tchar_t* pszLine = NULL; + bool bFirstLine = true; + + while((pszLine = _fgetts(pszBuffer, INI_BUFFER, pFile)) != NULL) + { + if(bFirstLine) + { + bFirstLine = false; + // check BOM + if(pszBuffer[0] != _t('\0') && *(ushort_t*)pszBuffer == 0xfeff) + parse_line(pszBuffer + 1); + else + parse_line(pszBuffer); + } + else + parse_line(pszBuffer); + } + + delete [] pszBuffer; + + // check if that was eof or error + if(feof(pFile) == 0) + { + fclose(pFile); + // error while reading file + THROW(_T("Error while reading ini file."), 0, errno, 0); + } + + // close the file + fclose(pFile); +} + +/// Processes the data from a given buffer +void ini_cfg::read_from_buffer(const tchar_t* pszBuffer, size_t stLen) +{ + // clear current contents + clear(); + + tchar_t* pszLine = new tchar_t[INI_BUFFER]; + size_t stLineLen = 0; + const tchar_t* pszCurrent = pszBuffer; + const tchar_t* pszLast = pszBuffer; + bool bFirstLine = true; + while(stLen--) + { + if(*pszCurrent == _t('\n')) + { + // there is a line [pszLast, pszCurrent) + stLineLen = pszCurrent - pszLast; + if(stLineLen) + { + if(stLineLen >= INI_BUFFER) + stLineLen = INI_BUFFER - 1; + _tcsncpy(pszLine, pszLast, stLineLen); + pszLine[stLineLen] = _t('\0'); + + if(bFirstLine) + { + bFirstLine = false; + // check BOM + if(pszLine[0] != _t('\0') && *(ushort_t*)pszLine == 0xfeff) + parse_line(pszLine + 1); + else + parse_line(pszLine); + } + else + { + // process the line + parse_line(pszLine); + } + } + pszLast = pszCurrent + 1; + } + ++pszCurrent; + } + if(pszCurrent != pszLast) + { + // there is a line [pszLast, pszCurrent) + stLineLen = pszCurrent - pszLast; + if(stLineLen) + { + if(stLineLen >= INI_BUFFER) + stLineLen = INI_BUFFER - 1; + + _tcsncpy(pszLine, pszLast, stLineLen); + pszLine[stLineLen] = _t('\0'); + + // process the line + parse_line(pszLine); + } + } + + delete [] pszLine; +} + +/** Saves the internal xml nodes to the specified xml file. +* +* \param[in] pszPath - path to the file the data should be written to +* +* \note Function overwrites the contents of a file +*/ +void ini_cfg::save(const tchar_t* pszPath) +{ + FILE* pFile=_tfopen(pszPath, _t("wb")); + if(pFile == NULL) + THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for writing."), pszPath), 0, errno, 0); + + // put BOM into the file + +#if(defined(_WIN32) || defined(_WIN64)) + // utf-16le + const uint_t uiBOM=0x0000feff; + const uint_t uiCount=2; +#else + // utf-8 + const uint_t uiBOM=0x00bfbbef; + const uint_t uiCount=3; +#endif + + + try + { + // write bom, check if itAttr succeeded + if(fwrite(&uiBOM, 1, uiCount, pFile) != uiCount) + THROW(_t("Cannot write the BOM to the file '") TSTRFMT _t("'"), 0, errno, 0); + + // and write + tstring_t strLine; + for(ini_storage::iterator iterSections = m_pMainNode->begin(); iterSections != m_pMainNode->end(); iterSections++) + { + strLine = _t("[") + (*iterSections).first + _t("]") + ENDL; + if(_fputts(strLine.c_str(), pFile) == TEOF) + THROW(_t("Cannot put section name"), 0, errno, 0); + for(attr_storage::iterator iterAttribute = (*iterSections).second.begin(); iterAttribute != (*iterSections).second.end(); iterAttribute++) + { + strLine = (*iterAttribute).first + _t("=") + (*iterAttribute).second + ENDL; + if(_fputts(strLine.c_str(), pFile) == TEOF) + THROW(_t("Cannot put attribute"), 0, errno, 0); + } + + if(_fputts(ENDL, pFile) == TEOF) + THROW(_t("Cannot put end-of-line marker into the file"), 0, errno, 0); + } + } + catch(...) + { + fclose(pFile); + throw; + } + + // close the file + fclose(pFile); +} + +/** Function starts a search operation. Given the name of the property +* to be searched for(ie. "ch/program/startup"), funtion searches for +* itAttr and returns a handle that can be used by subsequent calls to the +* find_next(). Free the handle using find_close() after finish. +* +* \param[in] pszName - name of the property to search for(in the form of +* "ch/program/startup" +* \return Handle to the search (NULL if not found). +*/ +ptr_t ini_cfg::find(const tchar_t* pszName) +{ + if(pszName == NULL || pszName[0] == _t('*')) + { + INIFINDHANDLE* pHandle = new INIFINDHANDLE; + pHandle->bOnlyAttributes = false; + pHandle->bSection = true; + pHandle->itSection = m_pMainNode->begin(); + pHandle->itSectionEnd = m_pMainNode->end(); + + return pHandle; + } + else + { + // parse the path + tstring_t strSection; + tstring_t strAttr; + if(!parse_property_name(pszName, strSection, strAttr)) + return NULL; + + ini_storage::iterator iterSection = m_pMainNode->find(strSection); + if(iterSection == m_pMainNode->end()) + return NULL; + + std::pair pairRange; + if(strAttr == _t("*")) + { + pairRange.first = (*iterSection).second.begin(); + pairRange.second = (*iterSection).second.end(); + } + else + pairRange = (*iterSection).second.equal_range(strAttr); + if(pairRange.first != (*iterSection).second.end() && pairRange.first != pairRange.second) + { + INIFINDHANDLE* pHandle = new INIFINDHANDLE; + pHandle->bSection = false; + pHandle->bOnlyAttributes = true; + pHandle->itAttr = pairRange.first; + pHandle->itAttrEnd = pairRange.second; + + return pHandle; + } + } + + return NULL; +} + +/** Finds the next string that belong to a specific key (as defined in +* a call to find() function. +* +* \param[in] pFindHandle - handle to the search (as returned from find()) +* \return Pointer to a next string found, NULL if none. +*/ +bool ini_cfg::find_next(ptr_t pFindHandle, PROPINFO& pi) +{ + assert(pFindHandle); + if(!pFindHandle) + return NULL; + INIFINDHANDLE* pfh=(INIFINDHANDLE*)pFindHandle; + + if(pfh->bOnlyAttributes) + { + if(pfh->itAttr != pfh->itAttrEnd) + { + pi.pszName = (*pfh->itAttr).first.c_str(); + pi.pszValue = (*pfh->itAttr).second.c_str(); + pi.bGroup = false; + pfh->itAttr++; + return true; + } + else + return false; + } + else + { + if(pfh->bSection) + { + if(pfh->itSection == pfh->itSectionEnd) + return false; + pfh->bSection = false; + pfh->itAttr = (*pfh->itSection).second.begin(); + pfh->itAttrEnd = (*pfh->itSection).second.end(); + + // section name + pi.bGroup = true; + pi.pszName = (*pfh->itSection++).first.c_str(); + pi.pszValue = NULL; + return true; + } + else + { + if(pfh->itAttr != pfh->itAttrEnd) + { + pi.bGroup = false; + pi.pszName = (*pfh->itAttr).first.c_str(); + pi.pszValue = (*pfh->itAttr).second.c_str(); + + pfh->itAttr++; + if(pfh->itAttr == pfh->itAttrEnd) + pfh->bSection = true; + return true; + + } + else + { + // should not happen + assert(false); + return false; + } + } + } +} + +/** Closes the find handle. +* +* \param[in] pFindHandle - handle to the search (as returned from find()) +*/ +void ini_cfg::find_close(ptr_t pFindHandle) +{ + delete ((INIFINDHANDLE*)pFindHandle); +} + +/** Sets the specified value in the given key name. Value can be either added to +* the current ones (multi-string support) or replace them completely. +* +* \param[in] pszName - key name for which the string should be set at +* \param[in] pszValue - value to set +* \param[in] a - action to take while setting +*/ +void ini_cfg::set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a) +{ + // parse the path + tstring_t strSection; + tstring_t strAttr; + if(!parse_property_name(pszName, strSection, strAttr)) + THROW(_t("Property not found"), 0, 0, 0); + + if(strAttr == _t("*")) + THROW(_t("Wildcards not available in set_value mode"), 0, 0, 0); + + // search + ini_storage::iterator iterSection = m_pMainNode->find(strSection.c_str()); + if(iterSection == m_pMainNode->end()) + { + std::pair pairSection = m_pMainNode->insert(ini_storage::value_type(strSection, attr_storage())); + iterSection = pairSection.first; + if(iterSection == m_pMainNode->end()) + THROW(_t("Problem with creating section"), 0, 0, 0); + } + + attr_storage& rAttrs = (*iterSection).second; + + // clear if we're replacing + switch(a) + { + case config_base::action_replace: + { + std::pair pairRange = (*iterSection).second.equal_range(strAttr); + rAttrs.erase(pairRange.first, pairRange.second); + // do not break here - we are about to insert the data + } + case config_base::action_add: + { + rAttrs.insert(attr_storage::value_type(strAttr, pszValue ? pszValue : tstring_t(_t("")))); + break; + } + default: + assert(false); + } +} + +/** Clears the contents of this class +* +* \param[in] pszName - name of the property to clear the values for +*/ +void ini_cfg::clear() +{ + m_pMainNode->clear(); +} + +/** Recursive clear function - searches recursively for a proper node +* and finally clears the string map. +* +* \param[in] pNodePtr - pointer to a node to be processed +* \param[in] pszName - name of the property to search for in the given node +*/ +void ini_cfg::clear(const tchar_t* pszName) +{ + if(pszName == NULL || pszName[0] == _t('*')) + m_pMainNode->clear(); + else + { + tstring_t strSection; + tstring_t strAttr; + if(!parse_property_name(pszName, strSection, strAttr)) + THROW(_t("Invalid name"), 0, 0, 0); + + ini_storage::iterator iterSection = m_pMainNode->find(strSection); + if(iterSection != m_pMainNode->end()) + { + attr_storage& rAttrs = (*iterSection).second; + std::pair pairRange; + + if(strAttr == _t("*")) + { + pairRange.first = rAttrs.begin(); + pairRange.second = rAttrs.end(); + } + else + pairRange = (*iterSection).second.equal_range(strAttr); + rAttrs.erase(pairRange.first, pairRange.second); + } + } +} + +void ini_cfg::parse_line(const tchar_t* pszLine) +{ + assert(pszLine); + if(!pszLine) + THROW(_t("Invalid parameter"), 0, 0, 0); + + tstring_t strLine = pszLine; + + // trim whitespaces on the left + while(strLine.begin() != strLine.end() && string_tool::is_whitespace(*strLine.begin())) + { + strLine.erase(strLine.begin()); + } + + while(strLine.rbegin() != strLine.rend() && (*strLine.rbegin() == _t('\r') || *strLine.rbegin() == _t('\n'))) + { + strLine.erase(strLine.end() - 1); + } + + + // detect line type + if(strLine.begin() == strLine.end()) // empty line + return; + if(strLine[0] == _t('#') || strLine[0] == _t(';')) // comment + return; + if(strLine[0] == _t('[')) + { + // trim whitespaces and ']' on the right + while(strLine.rbegin() != strLine.rend() && (string_tool::is_whitespace(*strLine.rbegin()) || *strLine.rbegin() == _t(']'))) + { + strLine.erase(strLine.end() - 1); + } + // trim [ + strLine.erase(strLine.begin()); + + // a new section + m_strCurrentSection = strLine; + m_pMainNode->insert(ini_storage::value_type(strLine, attr_storage())); + } + else + { + // do not trim whitespaces on the right - the spaces may be meaningful + // key=value + tstring_t::size_type stPos = strLine.find_first_of(_t('=')); + if(stPos != tstring_t::npos) + { + ini_storage::iterator iterSection = m_pMainNode->find(m_strCurrentSection); + if(iterSection == m_pMainNode->end()) + THROW(_t("Internal processing error. Section should already be included."), 0, 0, 0); + tstring_t strLeft, strRight; + strLeft.insert(strLeft.begin(), strLine.begin(), strLine.begin() + stPos); + strRight.insert(strRight.begin(), strLine.begin() + stPos + 1, strLine.end()); + (*iterSection).second.insert(attr_storage::value_type(strLeft, strRight)); + } + } +} + +bool ini_cfg::parse_property_name(const tchar_t* pszName, tstring_t& rstrSection, tstring_t& rstrName) +{ + // parse the path + tstring_t strPath = pszName; + tstring_t::size_type stPos = strPath.find_first_of(_t('/')); + if(stPos == tstring_t::npos) + return false; + tstring_t::size_type stPos2 = strPath.find_first_of(_t('/'), stPos + 1); + if(stPos2 != tstring_t::npos && stPos2 != stPos) + return false; // paths with two or more '/' are not supported + + rstrName.clear(); + rstrName.clear(); + rstrSection.insert(rstrSection.begin(), strPath.begin(), strPath.begin() + stPos); + rstrName.insert(rstrName.begin(), strPath.begin() + stPos + 1, strPath.end()); + + return true; +} + +END_ICPF_NAMESPACE + Index: ext/libicpf/src/libicpf/cfg_ini.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg_ini.cpp (revision bc4cf2a3f3ee521a89da79084168a666704920f1) +++ ext/libicpf/src/libicpf/cfg_ini.cpp (revision 0) @@ -1,558 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#include "cfg_ini.h" -#include "exception.h" -#include -#include -#include -#include "str_help.h" - -BEGIN_ICPF_NAMESPACE - -/// Buffer size for reading xml data from a file -#define INI_BUFFER 65536 - -// definition of line ending - system dependent -#if defined(_WIN32) || defined(_WIN64) -#define ENDL _t("\r\n") -#else -#define ENDL _t("\n") -#endif - -#ifdef _UNICODE - #define TEOF WEOF -#else - #define TEOF EOF -#endif - -/// String storage (key(s)=>value(s)) -typedef std::multimap attr_storage; -/// Ini node storage -typedef std::map ini_storage; - -/** Xml find handle structure - used for searching. -*/ -struct INIFINDHANDLE -{ - attr_storage::iterator itAttr; ///< Iterator of currently retrieved string - attr_storage::iterator itAttrEnd; ///< Iterator of a last string matching the criteria - - ini_storage::iterator itSection; ///< Section iterator - ini_storage::iterator itSectionEnd; ///< End of section enumeration - - bool bOnlyAttributes; ///< Enumeration type - true = only attributes (does not use section iterators), false = sections + all attributes inside - bool bSection; ///< Is section to be enumerated first ? -}; - -/// Macro for faster access to the xml storage -#define m_pMainNode ((ini_storage*)m_hMainNode) - -/** Constructs the ini_cfg object. -*/ -ini_cfg::ini_cfg() : - m_hMainNode((ptr_t)new ini_storage) -{ - -} - -/** Destructs the xml config object. -*/ -ini_cfg::~ini_cfg() -{ - delete m_pMainNode; -} - -/** Function reads the contents of the xml file, parses itAttr using expat parser -* and then creates xml nodes in memory that could be read using find functions. -* -* \param[in] pszPath - path to the file to be read -*/ -void ini_cfg::read(const tchar_t* pszPath) -{ - // clear current contents - clear(); - - // read the data from file -#if defined(_UNICODE) && (defined(_WIN32) || defined(_WIN64)) - FILE* pFile=_tfopen(pszPath, _t("rb")); -#else - FILE* pFile=_tfopen(pszPath, _t("rt")); -#endif - - if(pFile == NULL) - THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for reading."), pszPath), 0, errno, 0); - - // prepare buffer for data - tchar_t* pszBuffer = new tchar_t[INI_BUFFER]; - tchar_t* pszLine = NULL; - bool bFirstLine = true; - - while((pszLine = _fgetts(pszBuffer, INI_BUFFER, pFile)) != NULL) - { - if(bFirstLine) - { - bFirstLine = false; - // check BOM - if(pszBuffer[0] != _t('\0') && *(ushort_t*)pszBuffer == 0xfeff) - parse_line(pszBuffer + 1); - else - parse_line(pszBuffer); - } - else - parse_line(pszBuffer); - } - - delete [] pszBuffer; - - // check if that was eof or error - if(feof(pFile) == 0) - { - fclose(pFile); - // error while reading file - THROW(_T("Error while reading ini file."), 0, errno, 0); - } - - // close the file - fclose(pFile); -} - -/// Processes the data from a given buffer -void ini_cfg::read_from_buffer(const tchar_t* pszBuffer, size_t stLen) -{ - // clear current contents - clear(); - - tchar_t* pszLine = new tchar_t[INI_BUFFER]; - size_t stLineLen = 0; - const tchar_t* pszCurrent = pszBuffer; - const tchar_t* pszLast = pszBuffer; - bool bFirstLine = true; - while(stLen--) - { - if(*pszCurrent == _t('\n')) - { - // there is a line [pszLast, pszCurrent) - stLineLen = pszCurrent - pszLast; - if(stLineLen) - { - if(stLineLen >= INI_BUFFER) - stLineLen = INI_BUFFER - 1; - _tcsncpy(pszLine, pszLast, stLineLen); - pszLine[stLineLen] = _t('\0'); - - if(bFirstLine) - { - bFirstLine = false; - // check BOM - if(pszLine[0] != _t('\0') && *(ushort_t*)pszLine == 0xfeff) - parse_line(pszLine + 1); - else - parse_line(pszLine); - } - else - { - // process the line - parse_line(pszLine); - } - } - pszLast = pszCurrent + 1; - } - ++pszCurrent; - } - if(pszCurrent != pszLast) - { - // there is a line [pszLast, pszCurrent) - stLineLen = pszCurrent - pszLast; - if(stLineLen) - { - if(stLineLen >= INI_BUFFER) - stLineLen = INI_BUFFER - 1; - - _tcsncpy(pszLine, pszLast, stLineLen); - pszLine[stLineLen] = _t('\0'); - - // process the line - parse_line(pszLine); - } - } - - delete [] pszLine; -} - -/** Saves the internal xml nodes to the specified xml file. -* -* \param[in] pszPath - path to the file the data should be written to -* -* \note Function overwrites the contents of a file -*/ -void ini_cfg::save(const tchar_t* pszPath) -{ - FILE* pFile=_tfopen(pszPath, _t("wb")); - if(pFile == NULL) - THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for writing."), pszPath), 0, errno, 0); - - // put BOM into the file - -#if(defined(_WIN32) || defined(_WIN64)) - // utf-16le - const uint_t uiBOM=0x0000feff; - const uint_t uiCount=2; -#else - // utf-8 - const uint_t uiBOM=0x00bfbbef; - const uint_t uiCount=3; -#endif - - - try - { - // write bom, check if itAttr succeeded - if(fwrite(&uiBOM, 1, uiCount, pFile) != uiCount) - THROW(_t("Cannot write the BOM to the file '") TSTRFMT _t("'"), 0, errno, 0); - - // and write - tstring_t strLine; - for(ini_storage::iterator iterSections = m_pMainNode->begin(); iterSections != m_pMainNode->end(); iterSections++) - { - strLine = _t("[") + (*iterSections).first + _t("]") + ENDL; - if(_fputts(strLine.c_str(), pFile) == TEOF) - THROW(_t("Cannot put section name"), 0, errno, 0); - for(attr_storage::iterator iterAttribute = (*iterSections).second.begin(); iterAttribute != (*iterSections).second.end(); iterAttribute++) - { - strLine = (*iterAttribute).first + _t("=") + (*iterAttribute).second + ENDL; - if(_fputts(strLine.c_str(), pFile) == TEOF) - THROW(_t("Cannot put attribute"), 0, errno, 0); - } - - if(_fputts(ENDL, pFile) == TEOF) - THROW(_t("Cannot put end-of-line marker into the file"), 0, errno, 0); - } - } - catch(...) - { - fclose(pFile); - throw; - } - - // close the file - fclose(pFile); -} - -/** Function starts a search operation. Given the name of the property -* to be searched for(ie. "ch/program/startup"), funtion searches for -* itAttr and returns a handle that can be used by subsequent calls to the -* find_next(). Free the handle using find_close() after finish. -* -* \param[in] pszName - name of the property to search for(in the form of -* "ch/program/startup" -* \return Handle to the search (NULL if not found). -*/ -ptr_t ini_cfg::find(const tchar_t* pszName) -{ - if(pszName == NULL || pszName[0] == _t('*')) - { - INIFINDHANDLE* pHandle = new INIFINDHANDLE; - pHandle->bOnlyAttributes = false; - pHandle->bSection = true; - pHandle->itSection = m_pMainNode->begin(); - pHandle->itSectionEnd = m_pMainNode->end(); - - return pHandle; - } - else - { - // parse the path - tstring_t strSection; - tstring_t strAttr; - if(!parse_property_name(pszName, strSection, strAttr)) - return NULL; - - ini_storage::iterator iterSection = m_pMainNode->find(strSection); - if(iterSection == m_pMainNode->end()) - return NULL; - - std::pair pairRange; - if(strAttr == _t("*")) - { - pairRange.first = (*iterSection).second.begin(); - pairRange.second = (*iterSection).second.end(); - } - else - pairRange = (*iterSection).second.equal_range(strAttr); - if(pairRange.first != (*iterSection).second.end() && pairRange.first != pairRange.second) - { - INIFINDHANDLE* pHandle = new INIFINDHANDLE; - pHandle->bSection = false; - pHandle->bOnlyAttributes = true; - pHandle->itAttr = pairRange.first; - pHandle->itAttrEnd = pairRange.second; - - return pHandle; - } - } - - return NULL; -} - -/** Finds the next string that belong to a specific key (as defined in -* a call to find() function. -* -* \param[in] pFindHandle - handle to the search (as returned from find()) -* \return Pointer to a next string found, NULL if none. -*/ -bool ini_cfg::find_next(ptr_t pFindHandle, PROPINFO& pi) -{ - assert(pFindHandle); - if(!pFindHandle) - return NULL; - INIFINDHANDLE* pfh=(INIFINDHANDLE*)pFindHandle; - - if(pfh->bOnlyAttributes) - { - if(pfh->itAttr != pfh->itAttrEnd) - { - pi.pszName = (*pfh->itAttr).first.c_str(); - pi.pszValue = (*pfh->itAttr).second.c_str(); - pi.bGroup = false; - pfh->itAttr++; - return true; - } - else - return false; - } - else - { - if(pfh->bSection) - { - if(pfh->itSection == pfh->itSectionEnd) - return false; - pfh->bSection = false; - pfh->itAttr = (*pfh->itSection).second.begin(); - pfh->itAttrEnd = (*pfh->itSection).second.end(); - - // section name - pi.bGroup = true; - pi.pszName = (*pfh->itSection++).first.c_str(); - pi.pszValue = NULL; - return true; - } - else - { - if(pfh->itAttr != pfh->itAttrEnd) - { - pi.bGroup = false; - pi.pszName = (*pfh->itAttr).first.c_str(); - pi.pszValue = (*pfh->itAttr).second.c_str(); - - pfh->itAttr++; - if(pfh->itAttr == pfh->itAttrEnd) - pfh->bSection = true; - return true; - - } - else - { - // should not happen - assert(false); - return false; - } - } - } -} - -/** Closes the find handle. -* -* \param[in] pFindHandle - handle to the search (as returned from find()) -*/ -void ini_cfg::find_close(ptr_t pFindHandle) -{ - delete ((INIFINDHANDLE*)pFindHandle); -} - -/** Sets the specified value in the given key name. Value can be either added to -* the current ones (multi-string support) or replace them completely. -* -* \param[in] pszName - key name for which the string should be set at -* \param[in] pszValue - value to set -* \param[in] a - action to take while setting -*/ -void ini_cfg::set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a) -{ - // parse the path - tstring_t strSection; - tstring_t strAttr; - if(!parse_property_name(pszName, strSection, strAttr)) - THROW(_t("Property not found"), 0, 0, 0); - - if(strAttr == _t("*")) - THROW(_t("Wildcards not available in set_value mode"), 0, 0, 0); - - // search - ini_storage::iterator iterSection = m_pMainNode->find(strSection.c_str()); - if(iterSection == m_pMainNode->end()) - { - std::pair pairSection = m_pMainNode->insert(ini_storage::value_type(strSection, attr_storage())); - iterSection = pairSection.first; - if(iterSection == m_pMainNode->end()) - THROW(_t("Problem with creating section"), 0, 0, 0); - } - - attr_storage& rAttrs = (*iterSection).second; - - // clear if we're replacing - switch(a) - { - case config_base::action_replace: - { - std::pair pairRange = (*iterSection).second.equal_range(strAttr); - rAttrs.erase(pairRange.first, pairRange.second); - // do not break here - we are about to insert the data - } - case config_base::action_add: - { - rAttrs.insert(attr_storage::value_type(strAttr, pszValue ? pszValue : tstring_t(_t("")))); - break; - } - default: - assert(false); - } -} - -/** Clears the contents of this class -* -* \param[in] pszName - name of the property to clear the values for -*/ -void ini_cfg::clear() -{ - m_pMainNode->clear(); -} - -/** Recursive clear function - searches recursively for a proper node -* and finally clears the string map. -* -* \param[in] pNodePtr - pointer to a node to be processed -* \param[in] pszName - name of the property to search for in the given node -*/ -void ini_cfg::clear(const tchar_t* pszName) -{ - if(pszName == NULL || pszName[0] == _t('*')) - m_pMainNode->clear(); - else - { - tstring_t strSection; - tstring_t strAttr; - if(!parse_property_name(pszName, strSection, strAttr)) - THROW(_t("Invalid name"), 0, 0, 0); - - ini_storage::iterator iterSection = m_pMainNode->find(strSection); - if(iterSection != m_pMainNode->end()) - { - attr_storage& rAttrs = (*iterSection).second; - std::pair pairRange; - - if(strAttr == _t("*")) - { - pairRange.first = rAttrs.begin(); - pairRange.second = rAttrs.end(); - } - else - pairRange = (*iterSection).second.equal_range(strAttr); - rAttrs.erase(pairRange.first, pairRange.second); - } - } -} - -void ini_cfg::parse_line(const tchar_t* pszLine) -{ - assert(pszLine); - if(!pszLine) - THROW(_t("Invalid parameter"), 0, 0, 0); - - tstring_t strLine = pszLine; - - // trim whitespaces on the left - while(strLine.begin() != strLine.end() && string_tool::is_whitespace(*strLine.begin())) - { - strLine.erase(strLine.begin()); - } - - while(strLine.rbegin() != strLine.rend() && (*strLine.rbegin() == _t('\r') || *strLine.rbegin() == _t('\n'))) - { - strLine.erase(strLine.end() - 1); - } - - - // detect line type - if(strLine.begin() == strLine.end()) // empty line - return; - if(strLine[0] == _t('#') || strLine[0] == _t(';')) // comment - return; - if(strLine[0] == _t('[')) - { - // trim whitespaces and ']' on the right - while(strLine.rbegin() != strLine.rend() && (string_tool::is_whitespace(*strLine.rbegin()) || *strLine.rbegin() == _t(']'))) - { - strLine.erase(strLine.end() - 1); - } - // trim [ - strLine.erase(strLine.begin()); - - // a new section - m_strCurrentSection = strLine; - m_pMainNode->insert(ini_storage::value_type(strLine, attr_storage())); - } - else - { - // do not trim whitespaces on the right - the spaces may be meaningful - // key=value - tstring_t::size_type stPos = strLine.find_first_of(_t('=')); - if(stPos != tstring_t::npos) - { - ini_storage::iterator iterSection = m_pMainNode->find(m_strCurrentSection); - if(iterSection == m_pMainNode->end()) - THROW(_t("Internal processing error. Section should already be included."), 0, 0, 0); - tstring_t strLeft, strRight; - strLeft.insert(strLeft.begin(), strLine.begin(), strLine.begin() + stPos); - strRight.insert(strRight.begin(), strLine.begin() + stPos + 1, strLine.end()); - (*iterSection).second.insert(attr_storage::value_type(strLeft, strRight)); - } - } -} - -bool ini_cfg::parse_property_name(const tchar_t* pszName, tstring_t& rstrSection, tstring_t& rstrName) -{ - // parse the path - tstring_t strPath = pszName; - tstring_t::size_type stPos = strPath.find_first_of(_t('/')); - if(stPos == tstring_t::npos) - return false; - tstring_t::size_type stPos2 = strPath.find_first_of(_t('/'), stPos + 1); - if(stPos2 != tstring_t::npos && stPos2 != stPos) - return false; // paths with two or more '/' are not supported - - rstrName.clear(); - rstrName.clear(); - rstrSection.insert(rstrSection.begin(), strPath.begin(), strPath.begin() + stPos); - rstrName.insert(rstrName.begin(), strPath.begin() + stPos + 1, strPath.end()); - - return true; -} - -END_ICPF_NAMESPACE - Index: src/libicpf/cfg_ini.h =================================================================== diff -u -N --- src/libicpf/cfg_ini.h (revision 0) +++ src/libicpf/cfg_ini.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,82 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CFGINI_H__ +#define __CFGINI_H__ + +#include "gen_types.h" +#include "libicpf.h" +#include "config_base.h" + +BEGIN_ICPF_NAMESPACE + +/** Class provides the necessary base handlers for config class. +* It handles the ini data streams contained in the files, providing +* a way to set and retrieve data contained in the ini document. +*/ +class ini_cfg : public config_base +{ +public: + /** \name Construction/destruction/operators */ + /**@{*/ + ini_cfg(); ///< Standard constructor + ini_cfg(const ini_cfg& rSrc); ///< Copy constructor + virtual ~ini_cfg(); ///< Standard destructor + /**@}*/ + + /** \name File operations */ + /**@{*/ + /// Reads the xml document from the specified file + virtual void read(const tchar_t* pszPath); + /// Processes the data from a given buffer + virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen); + /// Saves the internal data to a specified file as the xml document + virtual void save(const tchar_t* pszPath); + /**@}*/ + + /** \name Key and value handling */ + /**@{*/ + /// Searches for a specified key (given all the path to a specific string) + virtual ptr_t find(const tchar_t* pszName); + /// Searches for the next string + virtual bool find_next(ptr_t pFindHandle, PROPINFO& pi); + /// Closes the search operation + virtual void find_close(ptr_t pFindHandle); + + /// Sets a value for a given key + virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); + /// Clear values for a given property name + virtual void clear(const tchar_t* pszName); + /// Clears all entries + virtual void clear(); + /**@}*/ + +private: + /// Parses a single line of the ini file + void parse_line(const tchar_t* pszLine); + + /// Parses the name of the property + bool parse_property_name(const tchar_t* pszName, tstring_t& rstrSection, tstring_t& rstrName); +protected: + ptr_t m_hMainNode; ///< Handle to the internal ini storage + tstring_t m_strCurrentSection; ///< Current section of the config file +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/cfg_ini.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg_ini.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/cfg_ini.h (revision 0) @@ -1,82 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CFGINI_H__ -#define __CFGINI_H__ - -#include "gen_types.h" -#include "libicpf.h" -#include "config_base.h" - -BEGIN_ICPF_NAMESPACE - -/** Class provides the necessary base handlers for config class. -* It handles the ini data streams contained in the files, providing -* a way to set and retrieve data contained in the ini document. -*/ -class ini_cfg : public config_base -{ -public: - /** \name Construction/destruction/operators */ - /**@{*/ - ini_cfg(); ///< Standard constructor - ini_cfg(const ini_cfg& rSrc); ///< Copy constructor - virtual ~ini_cfg(); ///< Standard destructor - /**@}*/ - - /** \name File operations */ - /**@{*/ - /// Reads the xml document from the specified file - virtual void read(const tchar_t* pszPath); - /// Processes the data from a given buffer - virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen); - /// Saves the internal data to a specified file as the xml document - virtual void save(const tchar_t* pszPath); - /**@}*/ - - /** \name Key and value handling */ - /**@{*/ - /// Searches for a specified key (given all the path to a specific string) - virtual ptr_t find(const tchar_t* pszName); - /// Searches for the next string - virtual bool find_next(ptr_t pFindHandle, PROPINFO& pi); - /// Closes the search operation - virtual void find_close(ptr_t pFindHandle); - - /// Sets a value for a given key - virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); - /// Clear values for a given property name - virtual void clear(const tchar_t* pszName); - /// Clears all entries - virtual void clear(); - /**@}*/ - -private: - /// Parses a single line of the ini file - void parse_line(const tchar_t* pszLine); - - /// Parses the name of the property - bool parse_property_name(const tchar_t* pszName, tstring_t& rstrSection, tstring_t& rstrName); -protected: - ptr_t m_hMainNode; ///< Handle to the internal ini storage - tstring_t m_strCurrentSection; ///< Current section of the config file -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/cfg_xml.cpp =================================================================== diff -u -N --- src/libicpf/cfg_xml.cpp (revision 0) +++ src/libicpf/cfg_xml.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,515 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "cfg_xml.h" +//#include +#include "exception.h" +#include +#include +#include + +//BEGIN_ICPF_NAMESPACE +// +///// Buffer size for reading xml data from a file +//#define XML_BUFFER 65536 +// +//// definition of line ending - system dependent +//#if defined(_WIN32) || defined(_WIN64) +// #define ENDL _t("\r\n") +//#else +// #define ENDL _t("\n") +//#endif +// +//// forward declaration +//class xml_node; +// +///// Xml node storage +//typedef std::map xml_storage; +///// String storage (key(s)=>value(s)) +//typedef std::multimap attr_storage; +// +///** Class manages a single xml node. +// */ +//class xml_node +//{ +//public: +///** \name Construction/destruction */ +///**@{*/ +// /// Standard constructor +// xml_node() : m_mNodes(), m_mAttr(), m_pParentNode(NULL) { }; +// /// Constructor defining the parent node +// xml_node(xml_node* pParentNode) : m_mNodes(), m_mAttr(), m_pParentNode(pParentNode) { }; +///**@}*/ +// +// /// Clears the node +// void clear(bool bClearParent = false) +// { +// m_mNodes.clear(); +// m_mAttr.clear(); +// if(bClearParent) +// m_pParentNode = NULL; +// } +// +//public: +// xml_storage m_mNodes; ///< Additional nodes inside of this one +// attr_storage m_mAttr; ///< String pairs belonging to this node +// xml_node* m_pParentNode; ///< Parent node +//}; +// +///** State structure - used by expat notifications. +// */ +//struct XMLSTATE +//{ +// xml_cfg* pCfg; +// xml_node* pNode; +//}; +// +///** Xml find handle structure - used for searching. +// */ +//struct XMLFINDHANDLE +//{ +// attr_storage::iterator it; ///< Iterator of currently retrieved string +// attr_storage::iterator itEnd; ///< Iterator of a last string matching the criteria +//}; +// +///// Macro for faster access to the xml storage +//#define m_pMainNode ((xml_node*)m_hMainNode) +// +///** Constructs the xml_cfg object. +// */ +//xml_cfg::xml_cfg() : +// m_hMainNode((ptr_t)new xml_node) +//{ +// +//} +// +///** Destructs the xml config object. +// */ +//xml_cfg::~xml_cfg() +//{ +// delete m_pMainNode; +//} +// +///** Expat start element handler. +// * +// * \param[in] userData - pointer to user defined parameters +// * \param[in] name - name of the tag being processed +// * \param[in] attrs - array of pointers to strings with attributes and their values +// */ +//void xml_cfg::element_start(void *userData, const tchar_t *name, const tchar_t **attrs) +//{ +// XMLSTATE* pState=(XMLSTATE*)userData; +// assert(pState); +// assert(pState->pNode); +// +// // temp +// tchar_t szData[512]; +// _sntprintf(szData, 512, _t("Opening Name: %s\n"), name); +// OutputDebugString(szData); +// // /temp +// +// // parse node attributes +// for(size_t t=0;attrs[t] != NULL;t+=2) +// { +// if(_tcscmp(attrs[t], _t("value")) == 0) +// { +// // this is the value type tag +// pState->pNode->m_mAttr.insert(attr_storage::value_type(tstring_t(name), tstring_t(attrs[t+1]))); +// } +// } +// +// std::pair pr; +// pr=pState->pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(name), xml_node(pState->pNode))); +// pState->pNode=&((*pr.first).second); +//} +// +///** Expat handler for closing tag. +// * +// * \param[in] userData - user defined parameter +// * \param[in] name - name of the tag being closed +// */ +//void xml_cfg::element_end(void *userData, const tchar_t* name) +//{ +// XMLSTATE* pState=(XMLSTATE*)userData; +// assert(pState); +// +// // temp +// tchar_t szData[512]; +// _sntprintf(szData, 512, _t("Closing Name: %s\n"), name); +// OutputDebugString(szData); +// // /temp +// +// // go up one level +// if(pState->pNode) +// pState->pNode=pState->pNode->m_pParentNode; +// else +// THROW(_t("Trying to close non-existent tag."), 0, 0, 0); +//} +// +///*void XMLCALL element_content(void *userData, const XML_Char *s, int len) +//{ +// XMLSTATE* pState=(XMLSTATE*)userData; +// +//}*/ +// +///** Function reads the contents of the xml file, parses it using expat parser +// * and then creates xml nodes in memory that could be read using find functions. +// * +// * \param[in] pszPath - path to the file to be read +// */ +//void xml_cfg::read(const tchar_t* pszPath) +//{ +// // clear current contents +// clear(); +// +// // read the data from file in 64kB portions and feed it to the expat xml parser +// FILE* pFile=_tfopen(pszPath, _t("rb")); +// if(pFile == NULL) +// THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for reading."), pszPath), 0, errno, 0); +// +// // create the parser +// XML_Parser parser=XML_ParserCreate(NULL); +// XML_SetElementHandler(parser, element_start, element_end); +//// XML_SetCharacterDataHandler(parser, element_content); +// +// XMLSTATE xs = { this, m_pMainNode }; +// XML_SetUserData(parser, &xs); +// +// for(;;) +// { +// bool bLast=false; +// +// // get xml buffer +// void* pBuffer=XML_GetBuffer(parser, XML_BUFFER); +// +// // read some data to it +// size_t tSize=fread(pBuffer, 1, XML_BUFFER, pFile); +// if(tSize < XML_BUFFER) +// { +// // check for errors +// int iErr=0; +// if( (iErr=ferror(pFile)) != 0) +// THROW(icpf::exception::format(_t("Error reading from the file ") TSTRFMT _t("."), pszPath), 0, iErr, 0); +// else +// bLast=true; +// } +// +// // parse +// if(!XML_ParseBuffer(parser, (int)tSize, bLast)) +// { +// // parser error +// THROW(icpf::exception::format(_t("Error encountered while parsing the xml file ") STRFMT _t(" - ") STRFMT _t("."), pszPath, XML_ErrorString(XML_GetErrorCode(parser))), 0, 0, 0); +// } +// +// // end of processing ? +// if(bLast) +// break; +// } +// +// // free parser +// XML_ParserFree(parser); +// +// // close the file +// fclose(pFile); +//} +// +///** Saves the internal xml nodes to the specified xml file. +// * +// * \param[in] pszPath - path to the file the data should be written to +// * +// * \note Function overwrites the contents of a file +// */ +//void xml_cfg::save(const tchar_t* pszPath) +//{ +// FILE* pFile=_tfopen(pszPath, _t("wb")); +// if(pFile == NULL) +// THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for writing."), pszPath), 0, errno, 0); +// +// // put BOM into the file +//#if(defined(_WIN32) || defined(_WIN64)) +// // utf-16le +// const uint_t uiBOM=0x0000feff; +// const uint_t uiCount=2; +//#else +// // utf-8 +// const uint_t uiBOM=0x00bfbbef; +// const uint_t uiCount=3; +//#endif +// +// try +// { +// // write bom, check if it succeeded +// if(fwrite(&uiBOM, 1, uiCount, pFile) != uiCount) +// THROW(_t("Cannot write the BOM to the file '") TSTRFMT _t("'"), 0, errno, 0); +// +// // and write +// save_node(pFile, m_pMainNode); +// } +// catch(...) +// { +// fclose(pFile); +// throw; +// } +// +// // close the file +// fclose(pFile); +//} +// +//void xml_cfg::save_node(FILE* pFile, ptr_t pNodePtr) +//{ +// xml_node* pNode=(xml_node*)pNodePtr; +// +// // attributes first +// const tchar_t *pszFmt = _t("<") TSTRFMT _t(" value=\"") TSTRFMT _t("\"/>") ENDL; +// for(attr_storage::iterator it=pNode->m_mAttr.begin();it != pNode->m_mAttr.end();it++) +// { +// fprintf_encoded(pFile, pszFmt, (*it).first.c_str(), (*it).second.c_str()); +// } +// +// // sub-nodes +// for(xml_storage::iterator it=pNode->m_mNodes.begin();it != pNode->m_mNodes.end();it++) +// { +// xml_node& rNode = (*it).second; +// if(!rNode.m_mNodes.empty() || !rNode.m_mAttr.empty()) +// { +// // opening tag +// fprintf_encoded(pFile, _t("<") TSTRFMT _t(">") ENDL, (*it).first.c_str()); +// +// save_node(pFile, &(*it).second); +// +// // closing tag +// fprintf_encoded(pFile, _t("") ENDL, (*it).first.c_str()); +// } +// } +//} +// +//void xml_cfg::fprintf_encoded(FILE* pFile, const tchar_t* pszFmt, ...) +//{ +// va_list va; +// va_start(va, pszFmt); +// +// // get count of characters in the string +// int_t iCount=_vsctprintf(pszFmt, va); +// tchar_t* pszFormatted=new tchar_t[iCount+1]; +// +// // make a formatted string +// va_start(va, pszFmt); +// _vsntprintf(pszFormatted, iCount + 1, pszFmt, va); +// +//#if(!defined(UNICODE) && (defined(_WIN32) || defined(_WIN64))) +// // convert to unicode +// iCount = lstrlen(pszFormatted); +// int iWideCount = MultiByteToWideChar(CP_ACP, 0, pszFormatted, iCount, NULL, 0); +// if(iWideCount) +// { +// wchar_t* pszWideString = new wchar_t[iWideCount]; +// iWideCount = MultiByteToWideChar(CP_ACP, 0, pszFormatted, iCount, pszWideString, iWideCount); +// fwrite(pszWideString, 1, iWideCount*sizeof(wchar_t), pFile); +// +// delete [] pszWideString; +// } +// else +// THROW(_t("Cannot convert string to wide characters."), 0, GetLastError(), 0); +//#else +// fwrite(pszFormatted, sizeof(tchar_t), iCount, pFile); +//#endif +// +// delete [] pszFormatted; +// +// va_end(va); +//} +// +///** Function starts a search operation. Given the name of the property +// * to be searched for(ie. "ch/program/startup"), funtion searches for +// * it and returns a handle that can be used by subsequent calls to the +// * find_next(). Free the handle using find_close() after finish. +// * +// * \param[in] pszName - name of the property to search for(in the form of +// * "ch/program/startup" for xml such as this: +// * +// * +// * +// * +// * +// * +// * \return Handle to the search (NULL if not found). +// */ +//ptr_t xml_cfg::find(const tchar_t* pszName) +//{ +// return find(m_pMainNode, pszName); +//} +// +///** A find() helper function - recursively searches a specific node +// * for a given name. +// * +// * \param[in] pNodePtr - pointer to a node to search in +// * \param[in] pszName - name of the property to search for +// * \return Handle to the node or NULL if none. +// */ +//ptr_t xml_cfg::find(ptr_t pNodePtr, const tchar_t* pszName) +//{ +// xml_node* pNode=(xml_node*)pNodePtr; +// +// // parse the name +// const tchar_t* pSign=_tcschr(pszName, _t('/')); +// if(pSign) +// { +// // locate the xml_node associated with the name +// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pSign-pszName)); +// if(it != pNode->m_mNodes.end()) +// return find(&(*it).second, pSign+1); +// else +// return NULL; +// } +// else +// { +// std::pair pr=pNode->m_mAttr.equal_range(pszName); +// if(pr.first != pNode->m_mAttr.end() && pr.second != pNode->m_mAttr.end()) +// { +// XMLFINDHANDLE* pfh=new XMLFINDHANDLE; +// pfh->it=pr.first; +// pfh->itEnd=pr.second; +// +// return pfh; +// } +// else +// return NULL; +// } +//} +// +///** Finds the next string that belong to a specific key (as defined in +// * a call to find() function. +// * +// * \param[in] pFindHandle - handle to the search (as returned from find()) +// * \return Pointer to a next string found, NULL if none. +// */ +//const tchar_t* xml_cfg::find_next(ptr_t pFindHandle) +//{ +// XMLFINDHANDLE* pfh=(XMLFINDHANDLE*)pFindHandle; +// if(pfh->it != pfh->itEnd) +// return (*pfh->it++).second.c_str(); +// else +// return NULL; +//} +// +///** Closes the find handle. +// * +// * \param[in] pFindHandle - handle to the search (as returned from find()) +// */ +//void xml_cfg::find_close(ptr_t pFindHandle) +//{ +// delete ((XMLFINDHANDLE*)pFindHandle); +//} +// +///** Sets the specified value in the given key name. Value can be either added to +// * the current ones (multi-string support) or replace them completely. +// * +// * \param[in] pszName - key name for which the string should be set at +// * \param[in] pszValue - value to set +// * \param[in] a - action to take while setting +// */ +//void xml_cfg::set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a) +//{ +// // traverse the current tag tree +// set_value(m_pMainNode, pszName, pszValue, a); +//} +// +///** Sets the specified value in the given key name - recursive helper function. +// * +// * \param[in] pNodePtr - pointer to the xml node to process +// * \param[in] pszName - key name for which the string should be set at +// * \param[in] pszValue - value to set +// * \param[in] a - action to take while setting +// */ +//void xml_cfg::set_value(ptr_t pNodePtr, const tchar_t* pszName, const tchar_t* pszValue, actions a) +//{ +// xml_node* pNode=(xml_node*)pNodePtr; +// +// const tchar_t* pszSign=_tcschr(pszName, _t('/')); +// if(pszSign != NULL) +// { +// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pszSign-pszName)); +// if(it != pNode->m_mNodes.end()) +// set_value(&(*it).second, pszSign+1, pszValue, a); +// else +// { +// std::pair pr=pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(pszName, pszSign-pszName), xml_node(pNode))); +// set_value(&(*pr.first).second, pszSign+1, pszValue, a); +// } +// } +// else +// { +// // clear if we're replacing +// switch(a) +// { +// case config_base::action_replace: +// pNode->m_mAttr.clear(); +// case config_base::action_add: +// pNode->m_mAttr.insert(attr_storage::value_type(tstring_t(pszName), tstring_t(pszValue))); +// break; +// default: +// assert(false); +// } +// } +//} +// +///** Clear values for a given property name. +// * +// * \param[in] pszName - name of the property to clear the values for +// */ +//void xml_cfg::clear(const tchar_t* pszName) +//{ +// clear(m_pMainNode, pszName); +//} +// +///** Clears the contents of this class +//* +//* \param[in] pszName - name of the property to clear the values for +//*/ +//void xml_cfg::clear() +//{ +// m_pMainNode->clear(true); +//} +// +///** Recursive clear function - searches recursively for a proper node +// * and finally clears the string map. +// * +// * \param[in] pNodePtr - pointer to a node to be processed +// * \param[in] pszName - name of the property to search for in the given node +// */ +//void xml_cfg::clear(ptr_t pNodePtr, const tchar_t* pszName) +//{ +// xml_node* pNode=(xml_node*)pNodePtr; +// +// // parse the name +// const tchar_t* pSign=_tcschr(pszName, _t('/')); +// if(pSign) +// { +// // locate the xml_node associated with the name +// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pSign-pszName)); +// if(it != pNode->m_mNodes.end()) +// clear(&(*it).second, pSign+1); +// } +// else +// { +// std::pair pr=pNode->m_mAttr.equal_range(tstring_t(pszName)); +// pNode->m_mAttr.erase(pr.first, pr.second); +// } +//} +// +//END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/cfg_xml.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg_xml.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/cfg_xml.cpp (revision 0) @@ -1,515 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#include "cfg_xml.h" -//#include -#include "exception.h" -#include -#include -#include - -//BEGIN_ICPF_NAMESPACE -// -///// Buffer size for reading xml data from a file -//#define XML_BUFFER 65536 -// -//// definition of line ending - system dependent -//#if defined(_WIN32) || defined(_WIN64) -// #define ENDL _t("\r\n") -//#else -// #define ENDL _t("\n") -//#endif -// -//// forward declaration -//class xml_node; -// -///// Xml node storage -//typedef std::map xml_storage; -///// String storage (key(s)=>value(s)) -//typedef std::multimap attr_storage; -// -///** Class manages a single xml node. -// */ -//class xml_node -//{ -//public: -///** \name Construction/destruction */ -///**@{*/ -// /// Standard constructor -// xml_node() : m_mNodes(), m_mAttr(), m_pParentNode(NULL) { }; -// /// Constructor defining the parent node -// xml_node(xml_node* pParentNode) : m_mNodes(), m_mAttr(), m_pParentNode(pParentNode) { }; -///**@}*/ -// -// /// Clears the node -// void clear(bool bClearParent = false) -// { -// m_mNodes.clear(); -// m_mAttr.clear(); -// if(bClearParent) -// m_pParentNode = NULL; -// } -// -//public: -// xml_storage m_mNodes; ///< Additional nodes inside of this one -// attr_storage m_mAttr; ///< String pairs belonging to this node -// xml_node* m_pParentNode; ///< Parent node -//}; -// -///** State structure - used by expat notifications. -// */ -//struct XMLSTATE -//{ -// xml_cfg* pCfg; -// xml_node* pNode; -//}; -// -///** Xml find handle structure - used for searching. -// */ -//struct XMLFINDHANDLE -//{ -// attr_storage::iterator it; ///< Iterator of currently retrieved string -// attr_storage::iterator itEnd; ///< Iterator of a last string matching the criteria -//}; -// -///// Macro for faster access to the xml storage -//#define m_pMainNode ((xml_node*)m_hMainNode) -// -///** Constructs the xml_cfg object. -// */ -//xml_cfg::xml_cfg() : -// m_hMainNode((ptr_t)new xml_node) -//{ -// -//} -// -///** Destructs the xml config object. -// */ -//xml_cfg::~xml_cfg() -//{ -// delete m_pMainNode; -//} -// -///** Expat start element handler. -// * -// * \param[in] userData - pointer to user defined parameters -// * \param[in] name - name of the tag being processed -// * \param[in] attrs - array of pointers to strings with attributes and their values -// */ -//void xml_cfg::element_start(void *userData, const tchar_t *name, const tchar_t **attrs) -//{ -// XMLSTATE* pState=(XMLSTATE*)userData; -// assert(pState); -// assert(pState->pNode); -// -// // temp -// tchar_t szData[512]; -// _sntprintf(szData, 512, _t("Opening Name: %s\n"), name); -// OutputDebugString(szData); -// // /temp -// -// // parse node attributes -// for(size_t t=0;attrs[t] != NULL;t+=2) -// { -// if(_tcscmp(attrs[t], _t("value")) == 0) -// { -// // this is the value type tag -// pState->pNode->m_mAttr.insert(attr_storage::value_type(tstring_t(name), tstring_t(attrs[t+1]))); -// } -// } -// -// std::pair pr; -// pr=pState->pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(name), xml_node(pState->pNode))); -// pState->pNode=&((*pr.first).second); -//} -// -///** Expat handler for closing tag. -// * -// * \param[in] userData - user defined parameter -// * \param[in] name - name of the tag being closed -// */ -//void xml_cfg::element_end(void *userData, const tchar_t* name) -//{ -// XMLSTATE* pState=(XMLSTATE*)userData; -// assert(pState); -// -// // temp -// tchar_t szData[512]; -// _sntprintf(szData, 512, _t("Closing Name: %s\n"), name); -// OutputDebugString(szData); -// // /temp -// -// // go up one level -// if(pState->pNode) -// pState->pNode=pState->pNode->m_pParentNode; -// else -// THROW(_t("Trying to close non-existent tag."), 0, 0, 0); -//} -// -///*void XMLCALL element_content(void *userData, const XML_Char *s, int len) -//{ -// XMLSTATE* pState=(XMLSTATE*)userData; -// -//}*/ -// -///** Function reads the contents of the xml file, parses it using expat parser -// * and then creates xml nodes in memory that could be read using find functions. -// * -// * \param[in] pszPath - path to the file to be read -// */ -//void xml_cfg::read(const tchar_t* pszPath) -//{ -// // clear current contents -// clear(); -// -// // read the data from file in 64kB portions and feed it to the expat xml parser -// FILE* pFile=_tfopen(pszPath, _t("rb")); -// if(pFile == NULL) -// THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for reading."), pszPath), 0, errno, 0); -// -// // create the parser -// XML_Parser parser=XML_ParserCreate(NULL); -// XML_SetElementHandler(parser, element_start, element_end); -//// XML_SetCharacterDataHandler(parser, element_content); -// -// XMLSTATE xs = { this, m_pMainNode }; -// XML_SetUserData(parser, &xs); -// -// for(;;) -// { -// bool bLast=false; -// -// // get xml buffer -// void* pBuffer=XML_GetBuffer(parser, XML_BUFFER); -// -// // read some data to it -// size_t tSize=fread(pBuffer, 1, XML_BUFFER, pFile); -// if(tSize < XML_BUFFER) -// { -// // check for errors -// int iErr=0; -// if( (iErr=ferror(pFile)) != 0) -// THROW(icpf::exception::format(_t("Error reading from the file ") TSTRFMT _t("."), pszPath), 0, iErr, 0); -// else -// bLast=true; -// } -// -// // parse -// if(!XML_ParseBuffer(parser, (int)tSize, bLast)) -// { -// // parser error -// THROW(icpf::exception::format(_t("Error encountered while parsing the xml file ") STRFMT _t(" - ") STRFMT _t("."), pszPath, XML_ErrorString(XML_GetErrorCode(parser))), 0, 0, 0); -// } -// -// // end of processing ? -// if(bLast) -// break; -// } -// -// // free parser -// XML_ParserFree(parser); -// -// // close the file -// fclose(pFile); -//} -// -///** Saves the internal xml nodes to the specified xml file. -// * -// * \param[in] pszPath - path to the file the data should be written to -// * -// * \note Function overwrites the contents of a file -// */ -//void xml_cfg::save(const tchar_t* pszPath) -//{ -// FILE* pFile=_tfopen(pszPath, _t("wb")); -// if(pFile == NULL) -// THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for writing."), pszPath), 0, errno, 0); -// -// // put BOM into the file -//#if(defined(_WIN32) || defined(_WIN64)) -// // utf-16le -// const uint_t uiBOM=0x0000feff; -// const uint_t uiCount=2; -//#else -// // utf-8 -// const uint_t uiBOM=0x00bfbbef; -// const uint_t uiCount=3; -//#endif -// -// try -// { -// // write bom, check if it succeeded -// if(fwrite(&uiBOM, 1, uiCount, pFile) != uiCount) -// THROW(_t("Cannot write the BOM to the file '") TSTRFMT _t("'"), 0, errno, 0); -// -// // and write -// save_node(pFile, m_pMainNode); -// } -// catch(...) -// { -// fclose(pFile); -// throw; -// } -// -// // close the file -// fclose(pFile); -//} -// -//void xml_cfg::save_node(FILE* pFile, ptr_t pNodePtr) -//{ -// xml_node* pNode=(xml_node*)pNodePtr; -// -// // attributes first -// const tchar_t *pszFmt = _t("<") TSTRFMT _t(" value=\"") TSTRFMT _t("\"/>") ENDL; -// for(attr_storage::iterator it=pNode->m_mAttr.begin();it != pNode->m_mAttr.end();it++) -// { -// fprintf_encoded(pFile, pszFmt, (*it).first.c_str(), (*it).second.c_str()); -// } -// -// // sub-nodes -// for(xml_storage::iterator it=pNode->m_mNodes.begin();it != pNode->m_mNodes.end();it++) -// { -// xml_node& rNode = (*it).second; -// if(!rNode.m_mNodes.empty() || !rNode.m_mAttr.empty()) -// { -// // opening tag -// fprintf_encoded(pFile, _t("<") TSTRFMT _t(">") ENDL, (*it).first.c_str()); -// -// save_node(pFile, &(*it).second); -// -// // closing tag -// fprintf_encoded(pFile, _t("") ENDL, (*it).first.c_str()); -// } -// } -//} -// -//void xml_cfg::fprintf_encoded(FILE* pFile, const tchar_t* pszFmt, ...) -//{ -// va_list va; -// va_start(va, pszFmt); -// -// // get count of characters in the string -// int_t iCount=_vsctprintf(pszFmt, va); -// tchar_t* pszFormatted=new tchar_t[iCount+1]; -// -// // make a formatted string -// va_start(va, pszFmt); -// _vsntprintf(pszFormatted, iCount + 1, pszFmt, va); -// -//#if(!defined(UNICODE) && (defined(_WIN32) || defined(_WIN64))) -// // convert to unicode -// iCount = lstrlen(pszFormatted); -// int iWideCount = MultiByteToWideChar(CP_ACP, 0, pszFormatted, iCount, NULL, 0); -// if(iWideCount) -// { -// wchar_t* pszWideString = new wchar_t[iWideCount]; -// iWideCount = MultiByteToWideChar(CP_ACP, 0, pszFormatted, iCount, pszWideString, iWideCount); -// fwrite(pszWideString, 1, iWideCount*sizeof(wchar_t), pFile); -// -// delete [] pszWideString; -// } -// else -// THROW(_t("Cannot convert string to wide characters."), 0, GetLastError(), 0); -//#else -// fwrite(pszFormatted, sizeof(tchar_t), iCount, pFile); -//#endif -// -// delete [] pszFormatted; -// -// va_end(va); -//} -// -///** Function starts a search operation. Given the name of the property -// * to be searched for(ie. "ch/program/startup"), funtion searches for -// * it and returns a handle that can be used by subsequent calls to the -// * find_next(). Free the handle using find_close() after finish. -// * -// * \param[in] pszName - name of the property to search for(in the form of -// * "ch/program/startup" for xml such as this: -// * -// * -// * -// * -// * -// * -// * \return Handle to the search (NULL if not found). -// */ -//ptr_t xml_cfg::find(const tchar_t* pszName) -//{ -// return find(m_pMainNode, pszName); -//} -// -///** A find() helper function - recursively searches a specific node -// * for a given name. -// * -// * \param[in] pNodePtr - pointer to a node to search in -// * \param[in] pszName - name of the property to search for -// * \return Handle to the node or NULL if none. -// */ -//ptr_t xml_cfg::find(ptr_t pNodePtr, const tchar_t* pszName) -//{ -// xml_node* pNode=(xml_node*)pNodePtr; -// -// // parse the name -// const tchar_t* pSign=_tcschr(pszName, _t('/')); -// if(pSign) -// { -// // locate the xml_node associated with the name -// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pSign-pszName)); -// if(it != pNode->m_mNodes.end()) -// return find(&(*it).second, pSign+1); -// else -// return NULL; -// } -// else -// { -// std::pair pr=pNode->m_mAttr.equal_range(pszName); -// if(pr.first != pNode->m_mAttr.end() && pr.second != pNode->m_mAttr.end()) -// { -// XMLFINDHANDLE* pfh=new XMLFINDHANDLE; -// pfh->it=pr.first; -// pfh->itEnd=pr.second; -// -// return pfh; -// } -// else -// return NULL; -// } -//} -// -///** Finds the next string that belong to a specific key (as defined in -// * a call to find() function. -// * -// * \param[in] pFindHandle - handle to the search (as returned from find()) -// * \return Pointer to a next string found, NULL if none. -// */ -//const tchar_t* xml_cfg::find_next(ptr_t pFindHandle) -//{ -// XMLFINDHANDLE* pfh=(XMLFINDHANDLE*)pFindHandle; -// if(pfh->it != pfh->itEnd) -// return (*pfh->it++).second.c_str(); -// else -// return NULL; -//} -// -///** Closes the find handle. -// * -// * \param[in] pFindHandle - handle to the search (as returned from find()) -// */ -//void xml_cfg::find_close(ptr_t pFindHandle) -//{ -// delete ((XMLFINDHANDLE*)pFindHandle); -//} -// -///** Sets the specified value in the given key name. Value can be either added to -// * the current ones (multi-string support) or replace them completely. -// * -// * \param[in] pszName - key name for which the string should be set at -// * \param[in] pszValue - value to set -// * \param[in] a - action to take while setting -// */ -//void xml_cfg::set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a) -//{ -// // traverse the current tag tree -// set_value(m_pMainNode, pszName, pszValue, a); -//} -// -///** Sets the specified value in the given key name - recursive helper function. -// * -// * \param[in] pNodePtr - pointer to the xml node to process -// * \param[in] pszName - key name for which the string should be set at -// * \param[in] pszValue - value to set -// * \param[in] a - action to take while setting -// */ -//void xml_cfg::set_value(ptr_t pNodePtr, const tchar_t* pszName, const tchar_t* pszValue, actions a) -//{ -// xml_node* pNode=(xml_node*)pNodePtr; -// -// const tchar_t* pszSign=_tcschr(pszName, _t('/')); -// if(pszSign != NULL) -// { -// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pszSign-pszName)); -// if(it != pNode->m_mNodes.end()) -// set_value(&(*it).second, pszSign+1, pszValue, a); -// else -// { -// std::pair pr=pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(pszName, pszSign-pszName), xml_node(pNode))); -// set_value(&(*pr.first).second, pszSign+1, pszValue, a); -// } -// } -// else -// { -// // clear if we're replacing -// switch(a) -// { -// case config_base::action_replace: -// pNode->m_mAttr.clear(); -// case config_base::action_add: -// pNode->m_mAttr.insert(attr_storage::value_type(tstring_t(pszName), tstring_t(pszValue))); -// break; -// default: -// assert(false); -// } -// } -//} -// -///** Clear values for a given property name. -// * -// * \param[in] pszName - name of the property to clear the values for -// */ -//void xml_cfg::clear(const tchar_t* pszName) -//{ -// clear(m_pMainNode, pszName); -//} -// -///** Clears the contents of this class -//* -//* \param[in] pszName - name of the property to clear the values for -//*/ -//void xml_cfg::clear() -//{ -// m_pMainNode->clear(true); -//} -// -///** Recursive clear function - searches recursively for a proper node -// * and finally clears the string map. -// * -// * \param[in] pNodePtr - pointer to a node to be processed -// * \param[in] pszName - name of the property to search for in the given node -// */ -//void xml_cfg::clear(ptr_t pNodePtr, const tchar_t* pszName) -//{ -// xml_node* pNode=(xml_node*)pNodePtr; -// -// // parse the name -// const tchar_t* pSign=_tcschr(pszName, _t('/')); -// if(pSign) -// { -// // locate the xml_node associated with the name -// xml_storage::iterator it=pNode->m_mNodes.find(tstring_t(pszName, pSign-pszName)); -// if(it != pNode->m_mNodes.end()) -// clear(&(*it).second, pSign+1); -// } -// else -// { -// std::pair pr=pNode->m_mAttr.equal_range(tstring_t(pszName)); -// pNode->m_mAttr.erase(pr.first, pr.second); -// } -//} -// -//END_ICPF_NAMESPACE Index: src/libicpf/cfg_xml.h =================================================================== diff -u -N --- src/libicpf/cfg_xml.h (revision 0) +++ src/libicpf/cfg_xml.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,90 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CFGXML_H__ +#define __CFGXML_H__ + +//#include "gen_types.h" +//#include "libicpf.h" +//#include "config_base.h" +// +//BEGIN_ICPF_NAMESPACE +// +///** Class provides the necessary base handlers for config class. +// * It handles the xml data streams contained in the files, providing +// * a way to set and retrieve data contained in the xml document. +// */ +//class LIBICPF_API xml_cfg : public config_base +//{ +//public: +///** \name Construction/destruction/operators */ +///**@{*/ +// xml_cfg(); ///< Standard constructor +// xml_cfg(const xml_cfg& rSrc); ///< Copy constructor +// virtual ~xml_cfg(); ///< Standard destructor +///**@}*/ +// +///** \name File operations */ +///**@{*/ +// /// Reads the xml document from the specified file +// virtual void read(const tchar_t* pszPath); +// /// Saves the internal data to a specified file as the xml document +// virtual void save(const tchar_t* pszPath); +///**@}*/ +// +///** \name Key and value handling */ +///**@{*/ +// /// Searches for a specified key (given all the path to a specific string) +// virtual ptr_t find(const tchar_t* pszName); +// /// Searches for the next string +// virtual const tchar_t* find_next(ptr_t pFindHandle); +// /// Closes the search operation +// virtual void find_close(ptr_t pFindHandle); +// +// /// Sets a value for a given key +// virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); +// /// Clear values for a given property name +// virtual void clear(const tchar_t* pszName); +// /// Clears all entries +// virtual void clear(); +///**@}*/ +// +//private: +// /// Find helper - recursively searches for a specific key node +// ptr_t find(ptr_t pNodePtr, const tchar_t* pszName); +// /// Set value helper - searches for a specific node and sets the value +// void set_value(ptr_t pNodePtr, const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); +// /// Clear helper - clears the appropriate attributes +// void clear(ptr_t pNodePtr, const tchar_t* pszName); +// +// /// Saves the specific node into the file +// void save_node(FILE* pFile, ptr_t pNodePtr); +// +// /// Stores the string to the file converted to utf8 +// void fprintf_encoded(FILE* pFile, const tchar_t* pszFmt, ...); +// +// static void element_start(void *userData, const tchar_t *name, const tchar_t **attrs); +// static void element_end(void *userData, const tchar_t* name); +// +//protected: +// ptr_t m_hMainNode; ///< Handle to the internal xml storage +//}; +// +//END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/cfg_xml.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/cfg_xml.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/cfg_xml.h (revision 0) @@ -1,90 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CFGXML_H__ -#define __CFGXML_H__ - -//#include "gen_types.h" -//#include "libicpf.h" -//#include "config_base.h" -// -//BEGIN_ICPF_NAMESPACE -// -///** Class provides the necessary base handlers for config class. -// * It handles the xml data streams contained in the files, providing -// * a way to set and retrieve data contained in the xml document. -// */ -//class LIBICPF_API xml_cfg : public config_base -//{ -//public: -///** \name Construction/destruction/operators */ -///**@{*/ -// xml_cfg(); ///< Standard constructor -// xml_cfg(const xml_cfg& rSrc); ///< Copy constructor -// virtual ~xml_cfg(); ///< Standard destructor -///**@}*/ -// -///** \name File operations */ -///**@{*/ -// /// Reads the xml document from the specified file -// virtual void read(const tchar_t* pszPath); -// /// Saves the internal data to a specified file as the xml document -// virtual void save(const tchar_t* pszPath); -///**@}*/ -// -///** \name Key and value handling */ -///**@{*/ -// /// Searches for a specified key (given all the path to a specific string) -// virtual ptr_t find(const tchar_t* pszName); -// /// Searches for the next string -// virtual const tchar_t* find_next(ptr_t pFindHandle); -// /// Closes the search operation -// virtual void find_close(ptr_t pFindHandle); -// -// /// Sets a value for a given key -// virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); -// /// Clear values for a given property name -// virtual void clear(const tchar_t* pszName); -// /// Clears all entries -// virtual void clear(); -///**@}*/ -// -//private: -// /// Find helper - recursively searches for a specific key node -// ptr_t find(ptr_t pNodePtr, const tchar_t* pszName); -// /// Set value helper - searches for a specific node and sets the value -// void set_value(ptr_t pNodePtr, const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add); -// /// Clear helper - clears the appropriate attributes -// void clear(ptr_t pNodePtr, const tchar_t* pszName); -// -// /// Saves the specific node into the file -// void save_node(FILE* pFile, ptr_t pNodePtr); -// -// /// Stores the string to the file converted to utf8 -// void fprintf_encoded(FILE* pFile, const tchar_t* pszFmt, ...); -// -// static void element_start(void *userData, const tchar_t *name, const tchar_t **attrs); -// static void element_end(void *userData, const tchar_t* name); -// -//protected: -// ptr_t m_hMainNode; ///< Handle to the internal xml storage -//}; -// -//END_ICPF_NAMESPACE - -#endif Index: src/libicpf/circ_buffer.cpp =================================================================== diff -u -N --- src/libicpf/circ_buffer.cpp (revision 0) +++ src/libicpf/circ_buffer.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,554 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "circ_buffer.h" +#include +#include +#include +#include "err_codes.h" +#include "exception.h" + +BEGIN_ICPF_NAMESPACE + +// amount of bytes by which the buffer size will be incremented +// if there is one byte to be put in a full buffer +#define _BUFFER_INC (size_t)512ULL + +// if there is at least _BUFFER_DEC free space in the buffer then the buffer +// will be shrank (shrinked?) +#define _BUFFER_DEC (size_t)4096ULL + +// specifies if circular buffer should shrink the buffer size if there is too much free +// space in the buffer +#define _USE_SHRINKING 1 + +// if defined to 1 then function ForwardSeek will empty the whole +// internal buffer if it does not find the specified value inside of it +#define _FAILSEEK_TRUNCATES 1 + +circular_buffer::circular_buffer() : + m_pbyBuffer(NULL), + m_tSize(0), + m_tDataSize(0), + m_tBitsAtEndCount(0) +{ +} + +circular_buffer::circular_buffer(const circular_buffer& rSrc) : + m_pbyBuffer(NULL), + m_tSize(0), + m_tDataSize(0), + m_tBitsAtEndCount(0) +{ + copy_from(rSrc); +} + +circular_buffer::~circular_buffer() +{ + try + { + destroy(); + } + catch(...) + { + } +} + +circular_buffer& circular_buffer::operator=(const circular_buffer& rSrc) +{ + if (this == &rSrc) + { + // delete the old stuff + destroy(); + copy_from(rSrc); + } + + return *this; +} + +void circular_buffer::copy_from(const circular_buffer& rSrc) +{ + if (rSrc.m_pbyBuffer && rSrc.m_tSize > 0) + { + // copy the old stuff + m_pbyBuffer=new byte_t[rSrc.m_tSize]; + memcpy(m_pbyBuffer, rSrc.m_pbyBuffer, rSrc.m_tDataSize); + m_tSize=rSrc.m_tSize; + m_tDataSize=rSrc.m_tDataSize; + } + else + { + m_pbyBuffer=NULL; + m_tSize=0; + m_tDataSize=0; + } +} + +void circular_buffer::destroy() +{ + delete [] m_pbyBuffer; + m_pbyBuffer=NULL; + m_tSize=0; + m_tDataSize=0; +} + +void circular_buffer::push_data(const byte_t* pbyBuffer, size_t tCount) +{ + // check if there is enough space + if (m_tDataSize+tCount > m_tSize) + resize_buffer(m_tDataSize+tCount); + + // check for buffer + assert(m_pbyBuffer); + + // now there is enough space - fill it + memcpy(m_pbyBuffer+m_tDataSize, pbyBuffer, tCount); + + // increase the counters + m_tDataSize+=tCount; +} + +void circular_buffer::push_data(circular_buffer& rcb) +{ + if (rcb.m_pbyBuffer && rcb.m_tDataSize) + push_data(rcb.m_pbyBuffer, rcb.m_tDataSize); +} + +// pushes length and a string +void circular_buffer::push_string(const char_t* pszString) +{ + if (pszString) + { + ulong_t ulLen=(ulong_t)(strlen(pszString)+1); + push_ulong(ulLen); + push_data((const uchar_t*)pszString, ulLen); + } + else + { + push_ulong(0); + } +} + +void circular_buffer::push_ulonglong(ull_t ull) +{ + push_data((uchar_t*)&ull, sizeof(ull_t)); +} + +// pushes an unsigned long value +void circular_buffer::push_ulong(ulong_t ulData) +{ + push_data((uchar_t*)&ulData, sizeof(ulong_t)); +} + +void circular_buffer::push_ushort(ushort_t wData) +{ + push_data((uchar_t*)&wData, sizeof(ushort_t)); +} + +void circular_buffer::push_uchar(uchar_t byData) +{ + push_data(&byData, 1); +} + +size_t circular_buffer::pop_data(byte_t* pbyBuffer, size_t tCount) +{ + if (m_pbyBuffer == NULL || m_tDataSize == 0) + return 0; + + // how much data we are going to spare + size_t tRealCount=tCount; + if (m_tDataSize < tRealCount) + tRealCount=m_tDataSize; + + // copy the data + memcpy(pbyBuffer, m_pbyBuffer, tRealCount); + + // now move the data to beginning + skip_bytes(tRealCount); +#if _USE_SHRINKING == 1 + shrink_buffer(); +#endif + return tRealCount; +} + +bool circular_buffer::pop_ulonglong(ull_t* pull) +{ + return (pop_data((byte_t*)pull, sizeof(ull_t)) == sizeof(ull_t)); +} + +bool circular_buffer::pop_ulong(ulong_t* pul) +{ + return (pop_data((byte_t*)pul, sizeof(ulong_t)) == sizeof(ulong_t)); +} + +bool circular_buffer::pop_ushort(ushort_t* pw) +{ + return (pop_data((byte_t*)pw, sizeof(ushort_t)) == sizeof(ushort_t)); +} + +bool circular_buffer::pop_uchar(uchar_t* pby) +{ + return (pop_data((byte_t*)pby, 1) == 1); +} + +ulong_t circular_buffer::pop_string(char_t** pszString) +{ + ulong_t ul; + if (!pop_ulong(&ul)) + { + *pszString=NULL; + return (ulong_t)-1; + } + + if (ul == 0) + { + *pszString = NULL; + return 0; + } + else + { + // check if there is enough data + if (m_tDataSize < ul) + return (ulong_t)-1; + + // alloc buffer for a string + (*pszString)=new char_t[ul]; + if (pop_data((byte_t*)(*pszString), ul) != ul) + { + delete [] (*pszString); + *pszString=NULL; + return (ulong_t)-1; + } + else + { + (*pszString)[ul-1]='\0'; // just in case + return ul-1; // without the '\0' + } + } +} + +void circular_buffer::free_string(char_t* pszString) +{ + delete [] pszString; +} + +size_t circular_buffer::find(size_t tStartAt, ulong_t ulFnd) const +{ + assert(m_pbyBuffer); +// printf("searching for %lu from %lu\n", ulFnd, ulStartAt); +// printf("internal structures: buf: 0x%lx, data size: %lu, buf size: %lu\n", m_pbyBuffer, m_tDataSize, m_tSize); + for (size_t i=tStartAt;i m_tDataSize) + m_tDataSize=0; + else + { + memmove(m_pbyBuffer, m_pbyBuffer+tCount, m_tDataSize-tCount); + m_tDataSize-=tCount; + } +} + +void circular_buffer::resize_buffer(size_t tNewSize) +{ + // modify the new length & alloc the new buffer + tNewSize=(tNewSize & ~(_BUFFER_INC-1)) + _BUFFER_INC; + if (tNewSize < m_tSize) + return; + + byte_t *pszBuf=new byte_t[tNewSize]; + + if (m_pbyBuffer && m_tDataSize > 0) + { + // copy the old buffer to the new one + memcpy(pszBuf, m_pbyBuffer, m_tDataSize); + } + + // destroy the old buffer + delete [] m_pbyBuffer; + + // update data + m_pbyBuffer=pszBuf; + m_tSize=tNewSize; +} + +void circular_buffer::shrink_buffer() +{ +#if _USE_SHRINKING == 1 + assert(m_pbyBuffer); + + // check the current size of the data + size_t tNewSize=(m_tDataSize & ~(_BUFFER_INC-1)) + _BUFFER_INC; + if (m_tSize-tNewSize > _BUFFER_DEC) + { + // we must shrink the buffer + byte_t *pszBuf=new byte_t[tNewSize]; + memcpy(pszBuf, m_pbyBuffer, m_tDataSize); + delete [] m_pbyBuffer; + + m_pbyBuffer=pszBuf; + m_tSize=tNewSize; + } +#endif +} + +void circular_buffer::flush(size_t tToLeave) +{ + if (m_tDataSize > tToLeave) + skip_bytes(m_tDataSize-tToLeave); +} + +void circular_buffer::clear() +{ + m_tDataSize=0; +} + +size_t circular_buffer::get_datasize() const +{ + return m_tDataSize; +} + +bool circular_buffer::is_empty() const +{ + return m_tDataSize == 0; +} + +circular_buffer::operator const byte_t*() const +{ + return m_pbyBuffer; +} + +const byte_t* circular_buffer::get_buffer() const +{ + return m_pbyBuffer; +} + +void circular_buffer::push_bits(ulong_t ulBits, byte_t byCount) +{ +// assert(m_pbyBuffer); + assert(byCount <= 32 && byCount >= 1); // count of bits must be a sane value + assert(m_tBitsAtEndCount <= 7); // the internal bits count must be from the range [0..7]. For 8 bits in a buffer + // there is value of 0. + + do + { + // check if we have to add the bits to the last byte of a buffer + if (m_tBitsAtEndCount != 0) + { + // count of bits to copy into the last byte of the internal buffer + ulong_t ulCopy=(ulong_t)((byCount < 8-m_tBitsAtEndCount) ? byCount : 8-m_tBitsAtEndCount); + + // make some space for the incoming data + m_pbyBuffer[m_tDataSize-1] >>= ulCopy; + + // get the full byte from the in + byte_t uc=(byte_t)(ulBits & 0x000000ff); + + // we are getting from it only ulCopy lowest bits, so shift if a bit + uc <<= (8-ulCopy); + + // and apply + m_pbyBuffer[m_tDataSize-1] |= uc; + + // a bit of corrections + ulBits >>= ulCopy; + byCount-=(byte_t)ulCopy; + m_tBitsAtEndCount+=ulCopy; + if (m_tBitsAtEndCount == 8) + m_tBitsAtEndCount = 0; + } + else + { + // now there is something to add at the beginning of a next byte + // if there are some full bytes to add then simply add it through the + // PushData. + if (byCount >= 8) + { + // push the whole 8 bits as a byte into the buffer. Operation safe only + // on the little endian machines. + ulong_t ulCount=byCount/8; + push_data(((const byte_t*)&ulBits), ulCount); + + // corrections + ulBits >>= ulCount*8; + byCount-=(byte_t)(ulCount*8); + } + else + { + // we are about to add <8 bits of data into the last byte of a buffer which does not exist yet + // get the full byte from the input ulong + byte_t uc=(byte_t)(ulBits & 0x000000ff); + + // shift it a bit + uc <<= 8-byCount; + + // and add as a next byte + push_data(&uc, 1); + +// Dump(); + + // corrections + m_tBitsAtEndCount = byCount; + ulBits = 0; // since there are no data left + byCount = 0; // no data left + } + } + } + while(byCount > 0); +} + +// finished the operation of pushing bits, so we could use normal Push/PopData +/*void circular_buffer::PushBitsFinish() +{ + // check if there is unfinished byte at the end + if (m_tBitsAtEndCount != 0) + { + m_pbyBuffer[m_tDataSize-1] >>= 8-m_tBitsAtEndCount; + m_tBitsAtEndCount=0; + } +}*/ + +// enumerates all the bit-packs that exists in a buffer. If there were any bits operations performed +// on a buffer - they must be finished by the PushBitsFinish. +void circular_buffer::enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const +{ + assert(m_pbyBuffer); + assert(ulBitsCount >= 1 && ulBitsCount <=8); + assert(pfn); + if(!pfn || ! m_pbyBuffer || ulBitsCount < 1 || ulBitsCount > 8) + THROW(_t("Invalid member or argument"), GE_INVALIDARG, 0, 0); + + ushort_t w=0; // internal buffer for the next data from the class's buffer + ulong_t ulBits=0; // count of bits that was left in w + + size_t tIndex=0; // current index in the class's buffer + for (;;) + { + // make sure there is enough data in w so the next operation can succeed + // if there is less data in w than requested + if (ulBits < ulBitsCount) + { + // is there something left to read from the internal buffer + if (tIndex < m_tDataSize) + { + // append some bits into the buffer. + // NOTE: we are sure that there are at least 8 bits space in w + if (tIndex == m_tDataSize && m_tBitsAtEndCount != 0) + { + // there are less than 8 bits left. add only the part that exists + byte_t uc=(byte_t)(m_pbyBuffer[tIndex++] >> (8-m_tBitsAtEndCount)); + w |= (ushort_t)(uc) << ulBits; + } + else + { + w |= (ushort_t)(m_pbyBuffer[tIndex++]) << ulBits; + ulBits+=8; + } + } + else + { + // are there any bits left in the w ? + if (ulBits > 0) + { + // there are some bits left, so we should add a bit or two to make sure nothing is lost +// printf("$$$ Some (%lu) bits left. Current cache=%u\n", ulBits, w); + ulBits=ulBitsCount; + } + else + { + // there are no data left in the internal buffer, so finish the operation +// printf("&&& Leaving with %lu bits left\n", ulBits); + return; + } + } + } + else + { + // call the callback function with the ucData as a param + byte_t uc=(byte_t)((w & 0xff) << (8-ulBitsCount)); + uc >>= 8-ulBitsCount; + + (*pfn)(uc, pParam); + + // update variables + ulBits-=ulBitsCount; + w >>= ulBitsCount; + } + } +} + +/*void circular_buffer::dump() +{ + printf("circular_buffer::Dump()\n\tsize of data: %lu\n\tsizeof the buffer: %lu\n\tbits at end: %lu", m_tDataSize, m_tSize, m_tBitsAtEndCount); + for (unsigned long i=0;i -#include -#include -#include "err_codes.h" -#include "exception.h" - -BEGIN_ICPF_NAMESPACE - -// amount of bytes by which the buffer size will be incremented -// if there is one byte to be put in a full buffer -#define _BUFFER_INC (size_t)512ULL - -// if there is at least _BUFFER_DEC free space in the buffer then the buffer -// will be shrank (shrinked?) -#define _BUFFER_DEC (size_t)4096ULL - -// specifies if circular buffer should shrink the buffer size if there is too much free -// space in the buffer -#define _USE_SHRINKING 1 - -// if defined to 1 then function ForwardSeek will empty the whole -// internal buffer if it does not find the specified value inside of it -#define _FAILSEEK_TRUNCATES 1 - -circular_buffer::circular_buffer() : - m_pbyBuffer(NULL), - m_tSize(0), - m_tDataSize(0), - m_tBitsAtEndCount(0) -{ -} - -circular_buffer::circular_buffer(const circular_buffer& rSrc) : - m_pbyBuffer(NULL), - m_tSize(0), - m_tDataSize(0), - m_tBitsAtEndCount(0) -{ - copy_from(rSrc); -} - -circular_buffer::~circular_buffer() -{ - try - { - destroy(); - } - catch(...) - { - } -} - -circular_buffer& circular_buffer::operator=(const circular_buffer& rSrc) -{ - if (this == &rSrc) - { - // delete the old stuff - destroy(); - copy_from(rSrc); - } - - return *this; -} - -void circular_buffer::copy_from(const circular_buffer& rSrc) -{ - if (rSrc.m_pbyBuffer && rSrc.m_tSize > 0) - { - // copy the old stuff - m_pbyBuffer=new byte_t[rSrc.m_tSize]; - memcpy(m_pbyBuffer, rSrc.m_pbyBuffer, rSrc.m_tDataSize); - m_tSize=rSrc.m_tSize; - m_tDataSize=rSrc.m_tDataSize; - } - else - { - m_pbyBuffer=NULL; - m_tSize=0; - m_tDataSize=0; - } -} - -void circular_buffer::destroy() -{ - delete [] m_pbyBuffer; - m_pbyBuffer=NULL; - m_tSize=0; - m_tDataSize=0; -} - -void circular_buffer::push_data(const byte_t* pbyBuffer, size_t tCount) -{ - // check if there is enough space - if (m_tDataSize+tCount > m_tSize) - resize_buffer(m_tDataSize+tCount); - - // check for buffer - assert(m_pbyBuffer); - - // now there is enough space - fill it - memcpy(m_pbyBuffer+m_tDataSize, pbyBuffer, tCount); - - // increase the counters - m_tDataSize+=tCount; -} - -void circular_buffer::push_data(circular_buffer& rcb) -{ - if (rcb.m_pbyBuffer && rcb.m_tDataSize) - push_data(rcb.m_pbyBuffer, rcb.m_tDataSize); -} - -// pushes length and a string -void circular_buffer::push_string(const char_t* pszString) -{ - if (pszString) - { - ulong_t ulLen=(ulong_t)(strlen(pszString)+1); - push_ulong(ulLen); - push_data((const uchar_t*)pszString, ulLen); - } - else - { - push_ulong(0); - } -} - -void circular_buffer::push_ulonglong(ull_t ull) -{ - push_data((uchar_t*)&ull, sizeof(ull_t)); -} - -// pushes an unsigned long value -void circular_buffer::push_ulong(ulong_t ulData) -{ - push_data((uchar_t*)&ulData, sizeof(ulong_t)); -} - -void circular_buffer::push_ushort(ushort_t wData) -{ - push_data((uchar_t*)&wData, sizeof(ushort_t)); -} - -void circular_buffer::push_uchar(uchar_t byData) -{ - push_data(&byData, 1); -} - -size_t circular_buffer::pop_data(byte_t* pbyBuffer, size_t tCount) -{ - if (m_pbyBuffer == NULL || m_tDataSize == 0) - return 0; - - // how much data we are going to spare - size_t tRealCount=tCount; - if (m_tDataSize < tRealCount) - tRealCount=m_tDataSize; - - // copy the data - memcpy(pbyBuffer, m_pbyBuffer, tRealCount); - - // now move the data to beginning - skip_bytes(tRealCount); -#if _USE_SHRINKING == 1 - shrink_buffer(); -#endif - return tRealCount; -} - -bool circular_buffer::pop_ulonglong(ull_t* pull) -{ - return (pop_data((byte_t*)pull, sizeof(ull_t)) == sizeof(ull_t)); -} - -bool circular_buffer::pop_ulong(ulong_t* pul) -{ - return (pop_data((byte_t*)pul, sizeof(ulong_t)) == sizeof(ulong_t)); -} - -bool circular_buffer::pop_ushort(ushort_t* pw) -{ - return (pop_data((byte_t*)pw, sizeof(ushort_t)) == sizeof(ushort_t)); -} - -bool circular_buffer::pop_uchar(uchar_t* pby) -{ - return (pop_data((byte_t*)pby, 1) == 1); -} - -ulong_t circular_buffer::pop_string(char_t** pszString) -{ - ulong_t ul; - if (!pop_ulong(&ul)) - { - *pszString=NULL; - return (ulong_t)-1; - } - - if (ul == 0) - { - *pszString = NULL; - return 0; - } - else - { - // check if there is enough data - if (m_tDataSize < ul) - return (ulong_t)-1; - - // alloc buffer for a string - (*pszString)=new char_t[ul]; - if (pop_data((byte_t*)(*pszString), ul) != ul) - { - delete [] (*pszString); - *pszString=NULL; - return (ulong_t)-1; - } - else - { - (*pszString)[ul-1]='\0'; // just in case - return ul-1; // without the '\0' - } - } -} - -void circular_buffer::free_string(char_t* pszString) -{ - delete [] pszString; -} - -size_t circular_buffer::find(size_t tStartAt, ulong_t ulFnd) const -{ - assert(m_pbyBuffer); -// printf("searching for %lu from %lu\n", ulFnd, ulStartAt); -// printf("internal structures: buf: 0x%lx, data size: %lu, buf size: %lu\n", m_pbyBuffer, m_tDataSize, m_tSize); - for (size_t i=tStartAt;i m_tDataSize) - m_tDataSize=0; - else - { - memmove(m_pbyBuffer, m_pbyBuffer+tCount, m_tDataSize-tCount); - m_tDataSize-=tCount; - } -} - -void circular_buffer::resize_buffer(size_t tNewSize) -{ - // modify the new length & alloc the new buffer - tNewSize=(tNewSize & ~(_BUFFER_INC-1)) + _BUFFER_INC; - if (tNewSize < m_tSize) - return; - - byte_t *pszBuf=new byte_t[tNewSize]; - - if (m_pbyBuffer && m_tDataSize > 0) - { - // copy the old buffer to the new one - memcpy(pszBuf, m_pbyBuffer, m_tDataSize); - } - - // destroy the old buffer - delete [] m_pbyBuffer; - - // update data - m_pbyBuffer=pszBuf; - m_tSize=tNewSize; -} - -void circular_buffer::shrink_buffer() -{ -#if _USE_SHRINKING == 1 - assert(m_pbyBuffer); - - // check the current size of the data - size_t tNewSize=(m_tDataSize & ~(_BUFFER_INC-1)) + _BUFFER_INC; - if (m_tSize-tNewSize > _BUFFER_DEC) - { - // we must shrink the buffer - byte_t *pszBuf=new byte_t[tNewSize]; - memcpy(pszBuf, m_pbyBuffer, m_tDataSize); - delete [] m_pbyBuffer; - - m_pbyBuffer=pszBuf; - m_tSize=tNewSize; - } -#endif -} - -void circular_buffer::flush(size_t tToLeave) -{ - if (m_tDataSize > tToLeave) - skip_bytes(m_tDataSize-tToLeave); -} - -void circular_buffer::clear() -{ - m_tDataSize=0; -} - -size_t circular_buffer::get_datasize() const -{ - return m_tDataSize; -} - -bool circular_buffer::is_empty() const -{ - return m_tDataSize == 0; -} - -circular_buffer::operator const byte_t*() const -{ - return m_pbyBuffer; -} - -const byte_t* circular_buffer::get_buffer() const -{ - return m_pbyBuffer; -} - -void circular_buffer::push_bits(ulong_t ulBits, byte_t byCount) -{ -// assert(m_pbyBuffer); - assert(byCount <= 32 && byCount >= 1); // count of bits must be a sane value - assert(m_tBitsAtEndCount <= 7); // the internal bits count must be from the range [0..7]. For 8 bits in a buffer - // there is value of 0. - - do - { - // check if we have to add the bits to the last byte of a buffer - if (m_tBitsAtEndCount != 0) - { - // count of bits to copy into the last byte of the internal buffer - ulong_t ulCopy=(ulong_t)((byCount < 8-m_tBitsAtEndCount) ? byCount : 8-m_tBitsAtEndCount); - - // make some space for the incoming data - m_pbyBuffer[m_tDataSize-1] >>= ulCopy; - - // get the full byte from the in - byte_t uc=(byte_t)(ulBits & 0x000000ff); - - // we are getting from it only ulCopy lowest bits, so shift if a bit - uc <<= (8-ulCopy); - - // and apply - m_pbyBuffer[m_tDataSize-1] |= uc; - - // a bit of corrections - ulBits >>= ulCopy; - byCount-=(byte_t)ulCopy; - m_tBitsAtEndCount+=ulCopy; - if (m_tBitsAtEndCount == 8) - m_tBitsAtEndCount = 0; - } - else - { - // now there is something to add at the beginning of a next byte - // if there are some full bytes to add then simply add it through the - // PushData. - if (byCount >= 8) - { - // push the whole 8 bits as a byte into the buffer. Operation safe only - // on the little endian machines. - ulong_t ulCount=byCount/8; - push_data(((const byte_t*)&ulBits), ulCount); - - // corrections - ulBits >>= ulCount*8; - byCount-=(byte_t)(ulCount*8); - } - else - { - // we are about to add <8 bits of data into the last byte of a buffer which does not exist yet - // get the full byte from the input ulong - byte_t uc=(byte_t)(ulBits & 0x000000ff); - - // shift it a bit - uc <<= 8-byCount; - - // and add as a next byte - push_data(&uc, 1); - -// Dump(); - - // corrections - m_tBitsAtEndCount = byCount; - ulBits = 0; // since there are no data left - byCount = 0; // no data left - } - } - } - while(byCount > 0); -} - -// finished the operation of pushing bits, so we could use normal Push/PopData -/*void circular_buffer::PushBitsFinish() -{ - // check if there is unfinished byte at the end - if (m_tBitsAtEndCount != 0) - { - m_pbyBuffer[m_tDataSize-1] >>= 8-m_tBitsAtEndCount; - m_tBitsAtEndCount=0; - } -}*/ - -// enumerates all the bit-packs that exists in a buffer. If there were any bits operations performed -// on a buffer - they must be finished by the PushBitsFinish. -void circular_buffer::enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const -{ - assert(m_pbyBuffer); - assert(ulBitsCount >= 1 && ulBitsCount <=8); - assert(pfn); - if(!pfn || ! m_pbyBuffer || ulBitsCount < 1 || ulBitsCount > 8) - THROW(_t("Invalid member or argument"), GE_INVALIDARG, 0, 0); - - ushort_t w=0; // internal buffer for the next data from the class's buffer - ulong_t ulBits=0; // count of bits that was left in w - - size_t tIndex=0; // current index in the class's buffer - for (;;) - { - // make sure there is enough data in w so the next operation can succeed - // if there is less data in w than requested - if (ulBits < ulBitsCount) - { - // is there something left to read from the internal buffer - if (tIndex < m_tDataSize) - { - // append some bits into the buffer. - // NOTE: we are sure that there are at least 8 bits space in w - if (tIndex == m_tDataSize && m_tBitsAtEndCount != 0) - { - // there are less than 8 bits left. add only the part that exists - byte_t uc=(byte_t)(m_pbyBuffer[tIndex++] >> (8-m_tBitsAtEndCount)); - w |= (ushort_t)(uc) << ulBits; - } - else - { - w |= (ushort_t)(m_pbyBuffer[tIndex++]) << ulBits; - ulBits+=8; - } - } - else - { - // are there any bits left in the w ? - if (ulBits > 0) - { - // there are some bits left, so we should add a bit or two to make sure nothing is lost -// printf("$$$ Some (%lu) bits left. Current cache=%u\n", ulBits, w); - ulBits=ulBitsCount; - } - else - { - // there are no data left in the internal buffer, so finish the operation -// printf("&&& Leaving with %lu bits left\n", ulBits); - return; - } - } - } - else - { - // call the callback function with the ucData as a param - byte_t uc=(byte_t)((w & 0xff) << (8-ulBitsCount)); - uc >>= 8-ulBitsCount; - - (*pfn)(uc, pParam); - - // update variables - ulBits-=ulBitsCount; - w >>= ulBitsCount; - } - } -} - -/*void circular_buffer::dump() -{ - printf("circular_buffer::Dump()\n\tsize of data: %lu\n\tsizeof the buffer: %lu\n\tbits at end: %lu", m_tDataSize, m_tSize, m_tBitsAtEndCount); - for (unsigned long i=0;i +#endif + +BEGIN_ICPF_NAMESPACE + +// forward_seek() results +#define FS_NOTFOUND -1 +#define FS_PARTIAL 0 +#define FS_FOUND 1 + +typedef void(*PFNBITSCALLBACK)(unsigned char uc, void* pParam); + +class LIBICPF_API circular_buffer +{ +public: + // construction/destruction + circular_buffer(); + circular_buffer(const circular_buffer& rSrc); + ~circular_buffer(); + + circular_buffer& operator=(const circular_buffer& rSrc); + + void destroy(); // destroys the contents of this class + + // operations + void push_data(const byte_t* pbyBuffer, size_t tCount); + void push_data(circular_buffer& rcb); + + void push_string(const char_t* pszString); // pushes length and a string + void push_ulonglong(ull_t ull); + void push_ulong(ulong_t ulData); // pushes an unsigned long value + void push_ushort(ushort_t wData); + void push_uchar(uchar_t byData); + + size_t pop_data(byte_t* pbyBuffer, size_t tCount); + bool pop_ulonglong(ull_t* pull); + bool pop_ulong(ulong_t* pul); + bool pop_ushort(ushort_t* pw); + bool pop_uchar(uchar_t* pby); + ulong_t pop_string(char_t** pszString); // returns the length of alloc string (-1 for error) + static void free_string(char_t* pszString); // frees the string allocated with pop_string + + // operation on single bits + void push_bits(ulong_t ulBits, byte_t byCount); +// void PushBitsFinish(); // finishes the operation of pushing bits, so we could use normal Push/PopData + void enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const; + size_t get_bits_at_end() const { return m_tBitsAtEndCount; }; + + // searching + int forward_seek(ulong_t ulFnd); // seeks for the value and skips the bytes previous to it + size_t find(size_t tStartAt, ulong_t ulFnd) const; // searches for the specified value in the buffer, returns an index + // (size_t)-1 if not found + + void skip_bytes(size_t tCount); // skips some bytes from the beginning of a buffer + void flush(size_t ulToLeave); // removes (almost) all the data from a buffer + void clear(); + + size_t get_datasize() const; + bool is_empty() const; + + operator const byte_t*() const; + const byte_t* get_buffer() const; + +// void dump(); + +protected: + void copy_from(const circular_buffer& rSrc); + void resize_buffer(size_t tNewSize); // enlarges buffer + void shrink_buffer(); + +protected: + byte_t *m_pbyBuffer; // internal buffer + size_t m_tSize; // size of the buffer + size_t m_tDataSize; // data size inside the buffer (the last byte could be partially filled with data + // so when using PopData instead of PopBitsX make sure you understand it). + size_t m_tBitsAtEndCount; // count of bits in the last byte of the buffer. 0 if the last byte is full of data +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/circ_buffer.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/circ_buffer.h (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/circ_buffer.h (revision 0) @@ -1,105 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CIRCULARBUFFER_H__ -#define __CIRCULARBUFFER_H__ - -#include "libicpf.h" -#include "gen_types.h" -#ifndef _WIN32 - #include -#endif - -BEGIN_ICPF_NAMESPACE - -// forward_seek() results -#define FS_NOTFOUND -1 -#define FS_PARTIAL 0 -#define FS_FOUND 1 - -typedef void(*PFNBITSCALLBACK)(unsigned char uc, void* pParam); - -class LIBICPF_API circular_buffer -{ -public: - // construction/destruction - circular_buffer(); - circular_buffer(const circular_buffer& rSrc); - ~circular_buffer(); - - circular_buffer& operator=(const circular_buffer& rSrc); - - void destroy(); // destroys the contents of this class - - // operations - void push_data(const byte_t* pbyBuffer, size_t tCount); - void push_data(circular_buffer& rcb); - - void push_string(const char_t* pszString); // pushes length and a string - void push_ulonglong(ull_t ull); - void push_ulong(ulong_t ulData); // pushes an unsigned long value - void push_ushort(ushort_t wData); - void push_uchar(uchar_t byData); - - size_t pop_data(byte_t* pbyBuffer, size_t tCount); - bool pop_ulonglong(ull_t* pull); - bool pop_ulong(ulong_t* pul); - bool pop_ushort(ushort_t* pw); - bool pop_uchar(uchar_t* pby); - ulong_t pop_string(char_t** pszString); // returns the length of alloc string (-1 for error) - static void free_string(char_t* pszString); // frees the string allocated with pop_string - - // operation on single bits - void push_bits(ulong_t ulBits, byte_t byCount); -// void PushBitsFinish(); // finishes the operation of pushing bits, so we could use normal Push/PopData - void enum_bit_packets(ulong_t ulBitsCount, PFNBITSCALLBACK pfn, void* pParam) const; - size_t get_bits_at_end() const { return m_tBitsAtEndCount; }; - - // searching - int forward_seek(ulong_t ulFnd); // seeks for the value and skips the bytes previous to it - size_t find(size_t tStartAt, ulong_t ulFnd) const; // searches for the specified value in the buffer, returns an index - // (size_t)-1 if not found - - void skip_bytes(size_t tCount); // skips some bytes from the beginning of a buffer - void flush(size_t ulToLeave); // removes (almost) all the data from a buffer - void clear(); - - size_t get_datasize() const; - bool is_empty() const; - - operator const byte_t*() const; - const byte_t* get_buffer() const; - -// void dump(); - -protected: - void copy_from(const circular_buffer& rSrc); - void resize_buffer(size_t tNewSize); // enlarges buffer - void shrink_buffer(); - -protected: - byte_t *m_pbyBuffer; // internal buffer - size_t m_tSize; // size of the buffer - size_t m_tDataSize; // data size inside the buffer (the last byte could be partially filled with data - // so when using PopData instead of PopBitsX make sure you understand it). - size_t m_tBitsAtEndCount; // count of bits in the last byte of the buffer. 0 if the last byte is full of data -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/config_base.h =================================================================== diff -u -N --- src/libicpf/config_base.h (revision 0) +++ src/libicpf/config_base.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,79 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CONFIG_BASE_H__ +#define __CONFIG_BASE_H__ + +#include "gen_types.h" +#include "libicpf.h" + +BEGIN_ICPF_NAMESPACE + +struct LIBICPF_API PROPINFO +{ + const tchar_t* pszName; ///< Property name + const tchar_t* pszValue; ///< String value of the property (only for attribute-level property) + bool bGroup; ///< Group-level property (true) or attribute (false) +}; + +/** Base config class. Manages the data that can be directly + * read or written to the storage medium (xml file, ini file, + * registry, ...). + */ +class LIBICPF_API config_base +{ +public: + /// Actions used when setting value + enum actions + { + action_add, + action_replace + }; + +public: + virtual ~config_base() {} + +/** \name File operations */ +/**@{*/ + /// Reads the xml document from the specified file + virtual void read(const tchar_t* pszPath) = 0; + /// Processes the data from a given buffer + virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen) = 0; + /// Saves the internal data to a specified file as the xml document + virtual void save(const tchar_t* pszPath) = 0; +/**@}*/ + +/** \name Key and value handling */ +/**@{*/ + /// Searches for a specified key (given all the path to a specific string) + virtual ptr_t find(const tchar_t* pszName) = 0; + /// Searches for the next string + virtual bool find_next(ptr_t pFindHandle, PROPINFO& pi) = 0; + /// Closes the search operation + virtual void find_close(ptr_t pFindHandle) = 0; + + /// Sets a value for a given key + virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add) = 0; + /// Clear values for a given property name + virtual void clear(const tchar_t* pszName) = 0; +/**@}*/ +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/config_base.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/config_base.h (revision 2d8fffbc4670dcd33dd391e61c0f3ef507307bfa) +++ ext/libicpf/src/libicpf/config_base.h (revision 0) @@ -1,79 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CONFIG_BASE_H__ -#define __CONFIG_BASE_H__ - -#include "gen_types.h" -#include "libicpf.h" - -BEGIN_ICPF_NAMESPACE - -struct LIBICPF_API PROPINFO -{ - const tchar_t* pszName; ///< Property name - const tchar_t* pszValue; ///< String value of the property (only for attribute-level property) - bool bGroup; ///< Group-level property (true) or attribute (false) -}; - -/** Base config class. Manages the data that can be directly - * read or written to the storage medium (xml file, ini file, - * registry, ...). - */ -class LIBICPF_API config_base -{ -public: - /// Actions used when setting value - enum actions - { - action_add, - action_replace - }; - -public: - virtual ~config_base() {} - -/** \name File operations */ -/**@{*/ - /// Reads the xml document from the specified file - virtual void read(const tchar_t* pszPath) = 0; - /// Processes the data from a given buffer - virtual void read_from_buffer(const tchar_t* pszBuffer, size_t stLen) = 0; - /// Saves the internal data to a specified file as the xml document - virtual void save(const tchar_t* pszPath) = 0; -/**@}*/ - -/** \name Key and value handling */ -/**@{*/ - /// Searches for a specified key (given all the path to a specific string) - virtual ptr_t find(const tchar_t* pszName) = 0; - /// Searches for the next string - virtual bool find_next(ptr_t pFindHandle, PROPINFO& pi) = 0; - /// Closes the search operation - virtual void find_close(ptr_t pFindHandle) = 0; - - /// Sets a value for a given key - virtual void set_value(const tchar_t* pszName, const tchar_t* pszValue, actions a=action_add) = 0; - /// Clear values for a given property name - virtual void clear(const tchar_t* pszName) = 0; -/**@}*/ -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/config_property.cpp =================================================================== diff -u -N --- src/libicpf/config_property.cpp (revision 0) +++ src/libicpf/config_property.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,1013 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "config_property.h" +#include "exception.h" +#include "err_codes.h" +#include +#include + +BEGIN_ICPF_NAMESPACE + +////////////////////////////////////////////////////////////////////////////////// +// property class +// fast access to the array property types +#define m_paStrings ((std::vector*)m_val.hArray) +#define m_paSigneds ((std::vector*)m_val.hArray) +#define m_paUnsigneds ((std::vector*)m_val.hArray) +#define m_paBools ((std::vector*)m_val.hArray) + +/** Constructs a property object. + */ +property::property() : + m_uiPropType(type_unknown | flag_none), + m_pszName(NULL) +{ + memset(&m_val, 0, sizeof(_VALUE)); + memset(&m_range, 0, sizeof(_RANGE)); +} + +/** Constructs a property object with type initializer. + * + * \param[in] uiType - type and flags to set the property to + */ +property::property(const tchar_t* pszName, uint_t uiType) : + m_uiPropType(uiType), + m_pszName(NULL) +{ + memset(&m_val, 0, sizeof(_VALUE)); + memset(&m_range, 0, sizeof(_RANGE)); + + // init + init(pszName, uiType, false); +} + +/** Constructs a property object based on some other property object. + * + * \param[in] src - a source property object + */ +property::property(const property& src) +{ + copy_from(src, false); +} + +/** Destructs the property object. + */ +property::~property() +{ + clear(); +} + +/** Assigns one property to another. + * + * \param[in] rSrc - a source property to copy + * \return Reference to this object. + */ +property& property::operator=(const property& rSrc) +{ + if (this != &rSrc) + copy_from(rSrc, true); + + return *this; +} + +/** Clears all the internal members. + */ +void property::clear() +{ + // delete the property name + delete [] m_pszName; + m_pszName=NULL; + + clear_value(); + + // reset other members + m_uiPropType=type_unknown | flag_none; +} + +/** Initializes the property for storaging of the specific property + * type. Also sets the property name. + * The current property contents are being cleared before setting + * the new type. + * + * \param[in] uiType - the new property type + */ +void property::init(const tchar_t* pszName, uint_t uiType, bool bClear) +{ + // clear the current stuff + if (bClear) + clear(); + + // standard members + m_pszName=copy_string(pszName); + m_uiPropType=uiType; + + // and alloc memory for the array property types + if (uiType & flag_array) + { + switch(uiType & mask_type) + { + case type_string: + m_val.hArray=(ptr_t)new std::vector; + break; + case type_signed_num: + m_val.hArray=(ptr_t)new std::vector; + m_range.ll.llLo=_I64_MIN; + m_range.ll.llHi=_I64_MAX; + break; + case type_unsigned_num: + m_val.hArray=(ptr_t)new std::vector; + m_range.ull.ullLo=0; + m_range.ull.ullHi=_UI64_MAX; + break; + case type_bool: + m_val.hArray=(ptr_t)new std::vector; + break; + default: + assert(false); // unhandled property type + } + } + else + { + switch(uiType & mask_type) + { + case type_string: + case type_bool: + break; + case type_signed_num: + m_range.ll.llLo=_I64_MIN; + m_range.ll.llHi=_I64_MAX; + break; + case type_unsigned_num: + m_range.ull.ullLo=0; + m_range.ull.ullHi=_UI64_MAX; + break; + default: + assert(false); // unhandled property type + } + } +} + +/** Sets a property value from a given string. If this is the array property + * type, than the operation is defined by a given action - it either replaces + * all the previous values, or adds at the end or replaces value at a specific + * index. + * + * \param[in] pszValue - value to set (stored in a string) + * \param[in] a - action to take when the property is array-based + * \param[in] tIndex - an index at which to place the value (only meaningful + * for array property type). + */ +void property::set_value(const tchar_t* pszValue, actions a, size_t tIndex) +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + { + switch(a) + { + case action_replace: + { + m_paStrings->clear(); + m_paStrings->push_back(tstring(pszValue)); + break; + } + case action_add: + { + m_paStrings->push_back(tstring(pszValue)); + break; + } + case action_setat: + { + assert(tIndex < m_paStrings->size()); + + tstring& str=m_paStrings->at(tIndex); + str=pszValue; + break; + } + default: + assert(false); // unhandled action type + } + break; + } + case type_bool: + { + switch(a) + { + case action_replace: + { + m_paBools->clear(); + m_paBools->push_back(bool_from_string(pszValue)); + break; + } + case action_add: + { + m_paBools->push_back(bool_from_string(pszValue)); + break; + } + case action_setat: + { + assert(tIndex < m_paBools->size()); + + std::vector::iterator it=m_paBools->begin()+tIndex; + (*it)=bool_from_string(pszValue); + break; + } + default: + assert(false); // unhandled action type + } + break; + } + case type_signed_num: + { + switch(a) + { + case action_replace: + { + m_paSigneds->clear(); + m_paSigneds->push_back(signed_from_string(pszValue)); + break; + } + case action_add: + { + m_paSigneds->push_back(signed_from_string(pszValue)); + break; + } + case action_setat: + { + assert(tIndex < m_paSigneds->size()); + + ll_t& ll=m_paSigneds->at(tIndex); + ll=signed_from_string(pszValue); + break; + } + default: + assert(false); // unhandled action type + } + break; + } + case type_unsigned_num: + { + switch(a) + { + case action_replace: + { + m_paUnsigneds->clear(); + m_paUnsigneds->push_back(unsigned_from_string(pszValue)); + break; + } + case action_add: + { + m_paUnsigneds->push_back(unsigned_from_string(pszValue)); + break; + } + case action_setat: + { + assert(tIndex < m_paUnsigneds->size()); + + ull_t& ull=m_paUnsigneds->at(tIndex); + ull=unsigned_from_string(pszValue); + break; + } + default: + assert(false); // unhandled action type + } + break; + } + } + } + else + { + switch(m_uiPropType & mask_type) + { + case type_string: + { + delete [] m_val.pszVal; + m_val.pszVal=copy_string(pszValue); + break; + } + case type_signed_num: + { + m_val.llVal=signed_from_string(pszValue); + break; + } + case type_unsigned_num: + { + m_val.ullVal=unsigned_from_string(pszValue); + break; + } + case type_bool: + { + m_val.bVal=bool_from_string(pszValue); + break; + } + default: + assert(false); // not implemented? + } + } +} + +/** Retrieves the value as a string. + * + * \param[out] pszString - pointer to a string that will receive the value (could + * be NULL when retrieving string value type) + * \param[in] stMaxSize - size of the buffer (could be 0 for string value retrieval) + * \param[in] stIndex - an index at which to get the value (only meaningful + * for array property type). + * \return Pointer to the string with value. + * \note Always use the returned value as a string pointer - it could be different + * than the one provided as a buffer (in case of retrieving string value). + */ +const tchar_t* property::get_value(tchar_t* pszString, size_t stMaxSize, size_t stIndex) +{ + assert(pszString); + if(!pszString) + THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); + + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + assert(stIndex < m_paStrings->size()); + return m_paStrings->at(stIndex).c_str(); + break; + case type_signed_num: + assert(stIndex < m_paSigneds->size()); + _sntprintf(pszString, stMaxSize, LLFMT, m_paSigneds->at(stIndex)); + break; + case type_unsigned_num: + assert(stIndex < m_paUnsigneds->size()); + _sntprintf(pszString, stMaxSize, ULLFMT, m_paUnsigneds->at(stIndex)); + break; + case type_bool: + assert(stIndex < m_paBools->size()); + _sntprintf(pszString, stMaxSize, USFMT, (ushort_t)m_paBools->at(stIndex)); + break; + default: + assert(false); + } + } + else + { + switch(m_uiPropType & mask_type) + { + case type_string: + return m_val.pszVal; + break; + case type_signed_num: + _sntprintf(pszString, stMaxSize, LLFMT, m_val.llVal); + break; + case type_unsigned_num: + _sntprintf(pszString, stMaxSize, ULLFMT, m_val.ullVal); + break; + case type_bool: + _sntprintf(pszString, stMaxSize, USFMT, (ushort_t)m_val.bVal); + break; + default: + assert(false); + } + } + + return pszString; +} + +/** Sets the string value for this property. + * + * \param[in] pszValue - string to set + * \param[in] a - action to take when property is array-based + * \param[in] tIndex - index at which to replace value in case of item + * replace action (for array-based property types) + */ +void property::set_string(const tchar_t* pszValue, actions a, size_t tIndex) +{ + assert((m_uiPropType & mask_type) == type_string); + + if (m_uiPropType & flag_array) + { + switch(a) + { + case action_replace: + { + m_paStrings->clear(); + m_paStrings->push_back(tstring(pszValue)); + break; + } + case action_add: + { + m_paStrings->push_back(tstring(pszValue)); + break; + } + case action_setat: + { + assert(tIndex < m_paStrings->size()); + tstring& str=m_paStrings->at(tIndex); + str=pszValue; + break; + } + default: + assert(false); // unhandled action type + } + } + else + { + delete [] m_val.pszVal; + m_val.pszVal=copy_string(pszValue); + } +} + +/** Retrieves the string value type. + * + * \param[in] stIndex - index at which to retrieve value (meaningful only + * for array property type) + * \return Pointer to the string. + */ +const tchar_t* property::get_string(size_t stIndex) const +{ + assert((m_uiPropType & mask_type) == type_string); + + if (m_uiPropType & flag_array) + { + assert(stIndex < m_paStrings->size()); + return m_paStrings->at(stIndex).c_str(); + } + else + return m_val.pszVal; +} + +/** Sets a signed number property value. + * + * \param[in] llValue - signed number value to set + * \param[in] a - action to take when property is array-based + * \param[in] tIndex - index at which to replace value in case of item + * replace action (for array-based property types) + */ +void property::set_signed_num(ll_t llValue, actions a, size_t tIndex) +{ + assert((m_uiPropType & mask_type) == type_signed_num); + + if (m_uiPropType & flag_array) + { + switch(a) + { + case action_replace: + { + m_paSigneds->clear(); + m_paSigneds->push_back(llValue); + break; + } + case action_add: + { + m_paSigneds->push_back(llValue); + break; + } + case action_setat: + { + assert(tIndex < m_paSigneds->size()); + ll_t& ll=m_paSigneds->at(tIndex); + ll=llValue; + break; + } + default: + assert(false); // unhandled action type + } + } + else + m_val.llVal=llValue; + + check_range(); +} + +/** Sets the range of the signed number property value. + * + * \param[in] llMin - minimum acceptable value of the property + * \param[in] llMax - maximum acceptable value of the property + */ +void property::set_signed_range(ll_t llMin, ll_t llMax) +{ + assert((m_uiPropType & mask_type) == type_signed_num); + + // set new range + m_range.ll.llLo=llMin; + m_range.ll.llHi=llMax; + + // check range + check_range(); +} + +/** Retrieves the signed number value. + * + * \param[in] stIndex - index at which to retrieve value (array-based + * property types) + * \return Signed number value. + */ +ll_t property::get_signed_num(size_t stIndex) const +{ + assert((m_uiPropType & mask_type) == type_signed_num); + + if (m_uiPropType & flag_array) + { + assert(stIndex < m_paSigneds->size()); + return m_paSigneds->at(stIndex); + } + else + return m_val.llVal; +} + +/** Sets an unsigned number property value. + * + * \param[in] ullValue - unsigned number value to set + * \param[in] a - action to take when property is array-based + * \param[in] tIndex - index at which to replace value in case of item + * replace action (for array-based property types) + */ +void property::set_unsigned_num(ull_t ullValue, actions a, size_t tIndex) +{ + assert((m_uiPropType & mask_type) == type_unsigned_num); + + if (m_uiPropType & flag_array) + { + switch(a) + { + case action_replace: + { + m_paUnsigneds->clear(); + m_paUnsigneds->push_back(ullValue); + break; + } + case action_add: + { + m_paUnsigneds->push_back(ullValue); + break; + } + case action_setat: + { + assert(tIndex < m_paUnsigneds->size()); + ull_t& ull=m_paUnsigneds->at(tIndex); + ull=ullValue; + break; + } + default: + assert(false); // unhandled action type + } + } + else + m_val.ullVal=ullValue; + + check_range(); +} + +/** Sets the range of the unsigned number property value. + * + * \param[in] ullMin - minimum acceptable value of the property + * \param[in] ullMax - maximum acceptable value of the property + */ +void property::set_unsigned_range(ull_t ullMin, ull_t ullMax) +{ + assert((m_uiPropType & mask_type) == type_unsigned_num); + + // set new range + m_range.ull.ullLo=ullMin; + m_range.ull.ullHi=ullMax; + + // check range + check_range(); +} + +/** Retrieves the unsigned number value. + * + * \param[in] stIndex - index at which to retrieve value (array-based + * property types) + * \return Unsigned number value. + */ +ull_t property::get_unsigned_num(size_t stIndex) const +{ + assert((m_uiPropType & mask_type) == type_unsigned_num); + + if (m_uiPropType & flag_array) + { + assert(stIndex < m_paUnsigneds->size()); + return m_paUnsigneds->at(stIndex); + } + else + return m_val.ullVal; +} + +/** Sets a bool property value. + * + * \param[in] bValue - bool value to set + * \param[in] a - action to take when property is array-based + * \param[in] tIndex - index at which to replace value in case of item + * replace action (for array-based property types) + */ +void property::set_bool(bool bValue, actions a, size_t tIndex) +{ + assert((m_uiPropType & mask_type) == type_bool); + + if (m_uiPropType & flag_array) + { + switch(a) + { + case action_replace: + { + m_paBools->clear(); + m_paBools->push_back(bValue); + break; + } + case action_add: + { + m_paBools->push_back(bValue); + break; + } + case action_setat: + { + assert(tIndex < m_paBools->size()); + std::vector::iterator it=m_paBools->begin()+tIndex; + (*it)=bValue; + break; + } + default: + assert(false); // unhandled action type + } + } + else + m_val.bVal=bValue; +} + +/** Retrieves the bool value. + * + * \param[in] stIndex - index at which to retrieve value (array-based + * property types) + * \return Bool value. + */ +bool property::get_bool(size_t stIndex) const +{ + assert((m_uiPropType & mask_type) == type_bool); + + if (m_uiPropType & flag_array) + { + assert(stIndex < m_paBools->size()); + return m_paBools->at(stIndex); + } + else + return m_val.bVal; +} + +/** Retrieves the property count for this property. + * + * \return Property count. + */ +size_t property::get_count() const +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + return m_paStrings->size(); + case type_signed_num: + return m_paSigneds->size(); + case type_unsigned_num: + return m_paUnsigneds->size(); + case type_bool: + return m_paBools->size(); + default: + assert(false); // unhandled property type + return 0; + } + } + else + return 1; +} + +/** Removes a property value at a given index. + * + * \param[in] stIndex - index of value to remove + */ +void property::remove(size_t stIndex) +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + { + assert(stIndex < m_paStrings->size()); + m_paStrings->erase(m_paStrings->begin()+stIndex); + break; + } + case type_signed_num: + { + assert(stIndex < m_paSigneds->size()); + m_paSigneds->erase(m_paSigneds->begin()+stIndex); + break; + } + case type_unsigned_num: + { + assert(stIndex < m_paUnsigneds->size()); + m_paUnsigneds->erase(m_paUnsigneds->begin()+stIndex); + break; + } + case type_bool: + { + assert(stIndex < m_paBools->size()); + m_paBools->erase(m_paBools->begin()+stIndex); + break; + } + default: + assert(false); // unhandled property type + } + } + else + assert(false); +} + +/** Clears the array property value. + */ +void property::clear_array() +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + m_paStrings->clear(); + break; + case type_signed_num: + m_paSigneds->clear(); + break; + case type_unsigned_num: + m_paUnsigneds->clear(); + break; + case type_bool: + m_paBools->clear(); + break; + default: + assert(false); // unhandled property type + } + } +} + +/** Completely clears the value part internal members. + * Unallocates all the memory associated with values and sets + * those members to NULL. + */ +void property::clear_value() +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_string: + delete m_paStrings; + break; + case type_signed_num: + delete m_paSigneds; + break; + case type_unsigned_num: + delete m_paUnsigneds; + break; + case type_bool: + delete m_paBools; + break; + default: + assert(false); // unhandled property type + } + + m_val.hArray=NULL; + } + else + { + switch(m_uiPropType & mask_type) + { + case type_string: + delete [] m_val.pszVal; + m_val.pszVal=NULL; + break; + case type_signed_num: + m_val.llVal=0LL; + break; + case type_unsigned_num: + m_val.ullVal=0ULL; + break; + case type_bool: + m_val.bVal=false; + break; + default: + assert(false); // not implemented? + } + } +} + +/** Function corrects the property value(s) based on the provided + * property value range. + */ +void property::check_range() +{ + if (m_uiPropType & flag_array) + { + switch(m_uiPropType & mask_type) + { + case type_signed_num: + { + for (std::vector::iterator it=m_paSigneds->begin();it != m_paSigneds->end();it++) + { + if ((*it) < m_range.ll.llLo) + (*it)=m_range.ll.llLo; + else if ((*it) > m_range.ll.llHi) + (*it)=m_range.ll.llHi; + } + break; + } + case type_unsigned_num: + { + for (std::vector::iterator it=m_paUnsigneds->begin();it != m_paUnsigneds->end();it++) + { + if ((*it) < m_range.ull.ullLo) + (*it)=m_range.ull.ullLo; + else if ((*it) > m_range.ull.ullHi) + (*it)=m_range.ull.ullHi; + } + break; + } + } + } + else + { + switch(m_uiPropType & mask_type) + { + case type_signed_num: + { + // check range + if (m_val.llVal < m_range.ll.llLo) + m_val.llVal=m_range.ll.llLo; + else if (m_val.llVal > m_range.ll.llHi) + m_val.llVal=m_range.ll.llHi; + break; + } + case type_unsigned_num: + { + // check range + if (m_val.ullVal < m_range.ull.ullLo) + m_val.ullVal=m_range.ull.ullLo; + else if (m_val.ullVal > m_range.ull.ullHi) + m_val.ullVal=m_range.ull.ullHi; + break; + } + default: + assert(false); // need to be implemented + } + } +} + +/** Makes a copy of a given string with allocating the necessary memory. + * + * \param[in] pszSrc - a source string + * \return Pointer to a newly allocated memory with new string + */ +tchar_t* property::copy_string(const tchar_t* pszSrc) +{ + if (pszSrc) + { + tchar_t *psz=new tchar_t[_tcslen(pszSrc)+1]; + _tcscpy(psz, pszSrc); + return psz; + } + else + return NULL; +} + +/** Converts a string to a boolean value. + * + * \param[in] pszSrc - string to convert + * \return Converted value. + */ +bool property::bool_from_string(const tchar_t* pszSrc) +{ + assert(pszSrc); + if(!pszSrc) + THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); + + return pszSrc[0] != _t('0'); +} + +/** Converts a string to a signed number value. + * + * \param[in] pszSrc - string to convert + * \return Converted value. + */ +ll_t property::signed_from_string(const tchar_t* pszSrc) +{ +#if defined(_WIN32) || defined(_WIN64) + return _ttoi64(pszSrc); +#else + return atoll(pszSrc); +#endif +} + +/** Converts a string to an unsigned number value. + * + * \param[in] pszSrc - string to convert + * \return Converted value. + */ +ull_t property::unsigned_from_string(const tchar_t* pszSrc) +{ + // currently does not support full range of unsigned long long + // since there are no (?) function to convert string to ull_t +#if defined(_WIN32) || defined(_WIN64) + return _ttoi64(pszSrc); +#else + return atoll(pszSrc); +#endif +} + +/** Function makes a copy of a given property storing it in this one. + * + * \param[in] rSrc - property to copy from + * \param[in] bClear - should we cleat current contents first + */ +void property::copy_from(const property& rSrc, bool bClear) +{ + // clear values in this class + if (bClear) + clear_value(); + + // copy the value(s) + if (rSrc.m_uiPropType & flag_array) + { + // source property is an array + switch(rSrc.m_uiPropType & mask_type) + { + case type_string: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_signed_num: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_unsigned_num: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_bool: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + default: + assert(false); // unknown property type + } + } + else + { + // source property is normal value + switch(rSrc.m_uiPropType & mask_type) + { + case type_string: + { + m_val.pszVal=copy_string(rSrc.m_val.pszVal); + break; + } + case type_signed_num: + { + m_val.llVal=rSrc.m_val.llVal; + m_range.ll.llHi=rSrc.m_range.ll.llHi; + m_range.ll.llLo=rSrc.m_range.ll.llLo; + break; + } + case type_unsigned_num: + { + m_val.ullVal=rSrc.m_val.ullVal; + m_range.ull.ullHi=rSrc.m_range.ull.ullHi; + m_range.ull.ullLo=rSrc.m_range.ull.ullLo; + break; + } + case type_bool: + { + m_val.bVal=rSrc.m_val.bVal; + break; + } + default: + assert(false); // property type not implemented? + } + } + + // copy values + m_uiPropType=rSrc.m_uiPropType; + m_pszName=copy_string(rSrc.m_pszName); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/config_property.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/config_property.cpp (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/config_property.cpp (revision 0) @@ -1,1013 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#include "config_property.h" -#include "exception.h" -#include "err_codes.h" -#include -#include - -BEGIN_ICPF_NAMESPACE - -////////////////////////////////////////////////////////////////////////////////// -// property class -// fast access to the array property types -#define m_paStrings ((std::vector*)m_val.hArray) -#define m_paSigneds ((std::vector*)m_val.hArray) -#define m_paUnsigneds ((std::vector*)m_val.hArray) -#define m_paBools ((std::vector*)m_val.hArray) - -/** Constructs a property object. - */ -property::property() : - m_uiPropType(type_unknown | flag_none), - m_pszName(NULL) -{ - memset(&m_val, 0, sizeof(_VALUE)); - memset(&m_range, 0, sizeof(_RANGE)); -} - -/** Constructs a property object with type initializer. - * - * \param[in] uiType - type and flags to set the property to - */ -property::property(const tchar_t* pszName, uint_t uiType) : - m_uiPropType(uiType), - m_pszName(NULL) -{ - memset(&m_val, 0, sizeof(_VALUE)); - memset(&m_range, 0, sizeof(_RANGE)); - - // init - init(pszName, uiType, false); -} - -/** Constructs a property object based on some other property object. - * - * \param[in] src - a source property object - */ -property::property(const property& src) -{ - copy_from(src, false); -} - -/** Destructs the property object. - */ -property::~property() -{ - clear(); -} - -/** Assigns one property to another. - * - * \param[in] rSrc - a source property to copy - * \return Reference to this object. - */ -property& property::operator=(const property& rSrc) -{ - if (this != &rSrc) - copy_from(rSrc, true); - - return *this; -} - -/** Clears all the internal members. - */ -void property::clear() -{ - // delete the property name - delete [] m_pszName; - m_pszName=NULL; - - clear_value(); - - // reset other members - m_uiPropType=type_unknown | flag_none; -} - -/** Initializes the property for storaging of the specific property - * type. Also sets the property name. - * The current property contents are being cleared before setting - * the new type. - * - * \param[in] uiType - the new property type - */ -void property::init(const tchar_t* pszName, uint_t uiType, bool bClear) -{ - // clear the current stuff - if (bClear) - clear(); - - // standard members - m_pszName=copy_string(pszName); - m_uiPropType=uiType; - - // and alloc memory for the array property types - if (uiType & flag_array) - { - switch(uiType & mask_type) - { - case type_string: - m_val.hArray=(ptr_t)new std::vector; - break; - case type_signed_num: - m_val.hArray=(ptr_t)new std::vector; - m_range.ll.llLo=_I64_MIN; - m_range.ll.llHi=_I64_MAX; - break; - case type_unsigned_num: - m_val.hArray=(ptr_t)new std::vector; - m_range.ull.ullLo=0; - m_range.ull.ullHi=_UI64_MAX; - break; - case type_bool: - m_val.hArray=(ptr_t)new std::vector; - break; - default: - assert(false); // unhandled property type - } - } - else - { - switch(uiType & mask_type) - { - case type_string: - case type_bool: - break; - case type_signed_num: - m_range.ll.llLo=_I64_MIN; - m_range.ll.llHi=_I64_MAX; - break; - case type_unsigned_num: - m_range.ull.ullLo=0; - m_range.ull.ullHi=_UI64_MAX; - break; - default: - assert(false); // unhandled property type - } - } -} - -/** Sets a property value from a given string. If this is the array property - * type, than the operation is defined by a given action - it either replaces - * all the previous values, or adds at the end or replaces value at a specific - * index. - * - * \param[in] pszValue - value to set (stored in a string) - * \param[in] a - action to take when the property is array-based - * \param[in] tIndex - an index at which to place the value (only meaningful - * for array property type). - */ -void property::set_value(const tchar_t* pszValue, actions a, size_t tIndex) -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - { - switch(a) - { - case action_replace: - { - m_paStrings->clear(); - m_paStrings->push_back(tstring(pszValue)); - break; - } - case action_add: - { - m_paStrings->push_back(tstring(pszValue)); - break; - } - case action_setat: - { - assert(tIndex < m_paStrings->size()); - - tstring& str=m_paStrings->at(tIndex); - str=pszValue; - break; - } - default: - assert(false); // unhandled action type - } - break; - } - case type_bool: - { - switch(a) - { - case action_replace: - { - m_paBools->clear(); - m_paBools->push_back(bool_from_string(pszValue)); - break; - } - case action_add: - { - m_paBools->push_back(bool_from_string(pszValue)); - break; - } - case action_setat: - { - assert(tIndex < m_paBools->size()); - - std::vector::iterator it=m_paBools->begin()+tIndex; - (*it)=bool_from_string(pszValue); - break; - } - default: - assert(false); // unhandled action type - } - break; - } - case type_signed_num: - { - switch(a) - { - case action_replace: - { - m_paSigneds->clear(); - m_paSigneds->push_back(signed_from_string(pszValue)); - break; - } - case action_add: - { - m_paSigneds->push_back(signed_from_string(pszValue)); - break; - } - case action_setat: - { - assert(tIndex < m_paSigneds->size()); - - ll_t& ll=m_paSigneds->at(tIndex); - ll=signed_from_string(pszValue); - break; - } - default: - assert(false); // unhandled action type - } - break; - } - case type_unsigned_num: - { - switch(a) - { - case action_replace: - { - m_paUnsigneds->clear(); - m_paUnsigneds->push_back(unsigned_from_string(pszValue)); - break; - } - case action_add: - { - m_paUnsigneds->push_back(unsigned_from_string(pszValue)); - break; - } - case action_setat: - { - assert(tIndex < m_paUnsigneds->size()); - - ull_t& ull=m_paUnsigneds->at(tIndex); - ull=unsigned_from_string(pszValue); - break; - } - default: - assert(false); // unhandled action type - } - break; - } - } - } - else - { - switch(m_uiPropType & mask_type) - { - case type_string: - { - delete [] m_val.pszVal; - m_val.pszVal=copy_string(pszValue); - break; - } - case type_signed_num: - { - m_val.llVal=signed_from_string(pszValue); - break; - } - case type_unsigned_num: - { - m_val.ullVal=unsigned_from_string(pszValue); - break; - } - case type_bool: - { - m_val.bVal=bool_from_string(pszValue); - break; - } - default: - assert(false); // not implemented? - } - } -} - -/** Retrieves the value as a string. - * - * \param[out] pszString - pointer to a string that will receive the value (could - * be NULL when retrieving string value type) - * \param[in] stMaxSize - size of the buffer (could be 0 for string value retrieval) - * \param[in] stIndex - an index at which to get the value (only meaningful - * for array property type). - * \return Pointer to the string with value. - * \note Always use the returned value as a string pointer - it could be different - * than the one provided as a buffer (in case of retrieving string value). - */ -const tchar_t* property::get_value(tchar_t* pszString, size_t stMaxSize, size_t stIndex) -{ - assert(pszString); - if(!pszString) - THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); - - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - assert(stIndex < m_paStrings->size()); - return m_paStrings->at(stIndex).c_str(); - break; - case type_signed_num: - assert(stIndex < m_paSigneds->size()); - _sntprintf(pszString, stMaxSize, LLFMT, m_paSigneds->at(stIndex)); - break; - case type_unsigned_num: - assert(stIndex < m_paUnsigneds->size()); - _sntprintf(pszString, stMaxSize, ULLFMT, m_paUnsigneds->at(stIndex)); - break; - case type_bool: - assert(stIndex < m_paBools->size()); - _sntprintf(pszString, stMaxSize, USFMT, (ushort_t)m_paBools->at(stIndex)); - break; - default: - assert(false); - } - } - else - { - switch(m_uiPropType & mask_type) - { - case type_string: - return m_val.pszVal; - break; - case type_signed_num: - _sntprintf(pszString, stMaxSize, LLFMT, m_val.llVal); - break; - case type_unsigned_num: - _sntprintf(pszString, stMaxSize, ULLFMT, m_val.ullVal); - break; - case type_bool: - _sntprintf(pszString, stMaxSize, USFMT, (ushort_t)m_val.bVal); - break; - default: - assert(false); - } - } - - return pszString; -} - -/** Sets the string value for this property. - * - * \param[in] pszValue - string to set - * \param[in] a - action to take when property is array-based - * \param[in] tIndex - index at which to replace value in case of item - * replace action (for array-based property types) - */ -void property::set_string(const tchar_t* pszValue, actions a, size_t tIndex) -{ - assert((m_uiPropType & mask_type) == type_string); - - if (m_uiPropType & flag_array) - { - switch(a) - { - case action_replace: - { - m_paStrings->clear(); - m_paStrings->push_back(tstring(pszValue)); - break; - } - case action_add: - { - m_paStrings->push_back(tstring(pszValue)); - break; - } - case action_setat: - { - assert(tIndex < m_paStrings->size()); - tstring& str=m_paStrings->at(tIndex); - str=pszValue; - break; - } - default: - assert(false); // unhandled action type - } - } - else - { - delete [] m_val.pszVal; - m_val.pszVal=copy_string(pszValue); - } -} - -/** Retrieves the string value type. - * - * \param[in] stIndex - index at which to retrieve value (meaningful only - * for array property type) - * \return Pointer to the string. - */ -const tchar_t* property::get_string(size_t stIndex) const -{ - assert((m_uiPropType & mask_type) == type_string); - - if (m_uiPropType & flag_array) - { - assert(stIndex < m_paStrings->size()); - return m_paStrings->at(stIndex).c_str(); - } - else - return m_val.pszVal; -} - -/** Sets a signed number property value. - * - * \param[in] llValue - signed number value to set - * \param[in] a - action to take when property is array-based - * \param[in] tIndex - index at which to replace value in case of item - * replace action (for array-based property types) - */ -void property::set_signed_num(ll_t llValue, actions a, size_t tIndex) -{ - assert((m_uiPropType & mask_type) == type_signed_num); - - if (m_uiPropType & flag_array) - { - switch(a) - { - case action_replace: - { - m_paSigneds->clear(); - m_paSigneds->push_back(llValue); - break; - } - case action_add: - { - m_paSigneds->push_back(llValue); - break; - } - case action_setat: - { - assert(tIndex < m_paSigneds->size()); - ll_t& ll=m_paSigneds->at(tIndex); - ll=llValue; - break; - } - default: - assert(false); // unhandled action type - } - } - else - m_val.llVal=llValue; - - check_range(); -} - -/** Sets the range of the signed number property value. - * - * \param[in] llMin - minimum acceptable value of the property - * \param[in] llMax - maximum acceptable value of the property - */ -void property::set_signed_range(ll_t llMin, ll_t llMax) -{ - assert((m_uiPropType & mask_type) == type_signed_num); - - // set new range - m_range.ll.llLo=llMin; - m_range.ll.llHi=llMax; - - // check range - check_range(); -} - -/** Retrieves the signed number value. - * - * \param[in] stIndex - index at which to retrieve value (array-based - * property types) - * \return Signed number value. - */ -ll_t property::get_signed_num(size_t stIndex) const -{ - assert((m_uiPropType & mask_type) == type_signed_num); - - if (m_uiPropType & flag_array) - { - assert(stIndex < m_paSigneds->size()); - return m_paSigneds->at(stIndex); - } - else - return m_val.llVal; -} - -/** Sets an unsigned number property value. - * - * \param[in] ullValue - unsigned number value to set - * \param[in] a - action to take when property is array-based - * \param[in] tIndex - index at which to replace value in case of item - * replace action (for array-based property types) - */ -void property::set_unsigned_num(ull_t ullValue, actions a, size_t tIndex) -{ - assert((m_uiPropType & mask_type) == type_unsigned_num); - - if (m_uiPropType & flag_array) - { - switch(a) - { - case action_replace: - { - m_paUnsigneds->clear(); - m_paUnsigneds->push_back(ullValue); - break; - } - case action_add: - { - m_paUnsigneds->push_back(ullValue); - break; - } - case action_setat: - { - assert(tIndex < m_paUnsigneds->size()); - ull_t& ull=m_paUnsigneds->at(tIndex); - ull=ullValue; - break; - } - default: - assert(false); // unhandled action type - } - } - else - m_val.ullVal=ullValue; - - check_range(); -} - -/** Sets the range of the unsigned number property value. - * - * \param[in] ullMin - minimum acceptable value of the property - * \param[in] ullMax - maximum acceptable value of the property - */ -void property::set_unsigned_range(ull_t ullMin, ull_t ullMax) -{ - assert((m_uiPropType & mask_type) == type_unsigned_num); - - // set new range - m_range.ull.ullLo=ullMin; - m_range.ull.ullHi=ullMax; - - // check range - check_range(); -} - -/** Retrieves the unsigned number value. - * - * \param[in] stIndex - index at which to retrieve value (array-based - * property types) - * \return Unsigned number value. - */ -ull_t property::get_unsigned_num(size_t stIndex) const -{ - assert((m_uiPropType & mask_type) == type_unsigned_num); - - if (m_uiPropType & flag_array) - { - assert(stIndex < m_paUnsigneds->size()); - return m_paUnsigneds->at(stIndex); - } - else - return m_val.ullVal; -} - -/** Sets a bool property value. - * - * \param[in] bValue - bool value to set - * \param[in] a - action to take when property is array-based - * \param[in] tIndex - index at which to replace value in case of item - * replace action (for array-based property types) - */ -void property::set_bool(bool bValue, actions a, size_t tIndex) -{ - assert((m_uiPropType & mask_type) == type_bool); - - if (m_uiPropType & flag_array) - { - switch(a) - { - case action_replace: - { - m_paBools->clear(); - m_paBools->push_back(bValue); - break; - } - case action_add: - { - m_paBools->push_back(bValue); - break; - } - case action_setat: - { - assert(tIndex < m_paBools->size()); - std::vector::iterator it=m_paBools->begin()+tIndex; - (*it)=bValue; - break; - } - default: - assert(false); // unhandled action type - } - } - else - m_val.bVal=bValue; -} - -/** Retrieves the bool value. - * - * \param[in] stIndex - index at which to retrieve value (array-based - * property types) - * \return Bool value. - */ -bool property::get_bool(size_t stIndex) const -{ - assert((m_uiPropType & mask_type) == type_bool); - - if (m_uiPropType & flag_array) - { - assert(stIndex < m_paBools->size()); - return m_paBools->at(stIndex); - } - else - return m_val.bVal; -} - -/** Retrieves the property count for this property. - * - * \return Property count. - */ -size_t property::get_count() const -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - return m_paStrings->size(); - case type_signed_num: - return m_paSigneds->size(); - case type_unsigned_num: - return m_paUnsigneds->size(); - case type_bool: - return m_paBools->size(); - default: - assert(false); // unhandled property type - return 0; - } - } - else - return 1; -} - -/** Removes a property value at a given index. - * - * \param[in] stIndex - index of value to remove - */ -void property::remove(size_t stIndex) -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - { - assert(stIndex < m_paStrings->size()); - m_paStrings->erase(m_paStrings->begin()+stIndex); - break; - } - case type_signed_num: - { - assert(stIndex < m_paSigneds->size()); - m_paSigneds->erase(m_paSigneds->begin()+stIndex); - break; - } - case type_unsigned_num: - { - assert(stIndex < m_paUnsigneds->size()); - m_paUnsigneds->erase(m_paUnsigneds->begin()+stIndex); - break; - } - case type_bool: - { - assert(stIndex < m_paBools->size()); - m_paBools->erase(m_paBools->begin()+stIndex); - break; - } - default: - assert(false); // unhandled property type - } - } - else - assert(false); -} - -/** Clears the array property value. - */ -void property::clear_array() -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - m_paStrings->clear(); - break; - case type_signed_num: - m_paSigneds->clear(); - break; - case type_unsigned_num: - m_paUnsigneds->clear(); - break; - case type_bool: - m_paBools->clear(); - break; - default: - assert(false); // unhandled property type - } - } -} - -/** Completely clears the value part internal members. - * Unallocates all the memory associated with values and sets - * those members to NULL. - */ -void property::clear_value() -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_string: - delete m_paStrings; - break; - case type_signed_num: - delete m_paSigneds; - break; - case type_unsigned_num: - delete m_paUnsigneds; - break; - case type_bool: - delete m_paBools; - break; - default: - assert(false); // unhandled property type - } - - m_val.hArray=NULL; - } - else - { - switch(m_uiPropType & mask_type) - { - case type_string: - delete [] m_val.pszVal; - m_val.pszVal=NULL; - break; - case type_signed_num: - m_val.llVal=0LL; - break; - case type_unsigned_num: - m_val.ullVal=0ULL; - break; - case type_bool: - m_val.bVal=false; - break; - default: - assert(false); // not implemented? - } - } -} - -/** Function corrects the property value(s) based on the provided - * property value range. - */ -void property::check_range() -{ - if (m_uiPropType & flag_array) - { - switch(m_uiPropType & mask_type) - { - case type_signed_num: - { - for (std::vector::iterator it=m_paSigneds->begin();it != m_paSigneds->end();it++) - { - if ((*it) < m_range.ll.llLo) - (*it)=m_range.ll.llLo; - else if ((*it) > m_range.ll.llHi) - (*it)=m_range.ll.llHi; - } - break; - } - case type_unsigned_num: - { - for (std::vector::iterator it=m_paUnsigneds->begin();it != m_paUnsigneds->end();it++) - { - if ((*it) < m_range.ull.ullLo) - (*it)=m_range.ull.ullLo; - else if ((*it) > m_range.ull.ullHi) - (*it)=m_range.ull.ullHi; - } - break; - } - } - } - else - { - switch(m_uiPropType & mask_type) - { - case type_signed_num: - { - // check range - if (m_val.llVal < m_range.ll.llLo) - m_val.llVal=m_range.ll.llLo; - else if (m_val.llVal > m_range.ll.llHi) - m_val.llVal=m_range.ll.llHi; - break; - } - case type_unsigned_num: - { - // check range - if (m_val.ullVal < m_range.ull.ullLo) - m_val.ullVal=m_range.ull.ullLo; - else if (m_val.ullVal > m_range.ull.ullHi) - m_val.ullVal=m_range.ull.ullHi; - break; - } - default: - assert(false); // need to be implemented - } - } -} - -/** Makes a copy of a given string with allocating the necessary memory. - * - * \param[in] pszSrc - a source string - * \return Pointer to a newly allocated memory with new string - */ -tchar_t* property::copy_string(const tchar_t* pszSrc) -{ - if (pszSrc) - { - tchar_t *psz=new tchar_t[_tcslen(pszSrc)+1]; - _tcscpy(psz, pszSrc); - return psz; - } - else - return NULL; -} - -/** Converts a string to a boolean value. - * - * \param[in] pszSrc - string to convert - * \return Converted value. - */ -bool property::bool_from_string(const tchar_t* pszSrc) -{ - assert(pszSrc); - if(!pszSrc) - THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); - - return pszSrc[0] != _t('0'); -} - -/** Converts a string to a signed number value. - * - * \param[in] pszSrc - string to convert - * \return Converted value. - */ -ll_t property::signed_from_string(const tchar_t* pszSrc) -{ -#if defined(_WIN32) || defined(_WIN64) - return _ttoi64(pszSrc); -#else - return atoll(pszSrc); -#endif -} - -/** Converts a string to an unsigned number value. - * - * \param[in] pszSrc - string to convert - * \return Converted value. - */ -ull_t property::unsigned_from_string(const tchar_t* pszSrc) -{ - // currently does not support full range of unsigned long long - // since there are no (?) function to convert string to ull_t -#if defined(_WIN32) || defined(_WIN64) - return _ttoi64(pszSrc); -#else - return atoll(pszSrc); -#endif -} - -/** Function makes a copy of a given property storing it in this one. - * - * \param[in] rSrc - property to copy from - * \param[in] bClear - should we cleat current contents first - */ -void property::copy_from(const property& rSrc, bool bClear) -{ - // clear values in this class - if (bClear) - clear_value(); - - // copy the value(s) - if (rSrc.m_uiPropType & flag_array) - { - // source property is an array - switch(rSrc.m_uiPropType & mask_type) - { - case type_string: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_signed_num: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_unsigned_num: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_bool: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - default: - assert(false); // unknown property type - } - } - else - { - // source property is normal value - switch(rSrc.m_uiPropType & mask_type) - { - case type_string: - { - m_val.pszVal=copy_string(rSrc.m_val.pszVal); - break; - } - case type_signed_num: - { - m_val.llVal=rSrc.m_val.llVal; - m_range.ll.llHi=rSrc.m_range.ll.llHi; - m_range.ll.llLo=rSrc.m_range.ll.llLo; - break; - } - case type_unsigned_num: - { - m_val.ullVal=rSrc.m_val.ullVal; - m_range.ull.ullHi=rSrc.m_range.ull.ullHi; - m_range.ull.ullLo=rSrc.m_range.ull.ullLo; - break; - } - case type_bool: - { - m_val.bVal=rSrc.m_val.bVal; - break; - } - default: - assert(false); // property type not implemented? - } - } - - // copy values - m_uiPropType=rSrc.m_uiPropType; - m_pszName=copy_string(rSrc.m_pszName); -} - -END_ICPF_NAMESPACE Index: src/libicpf/config_property.h =================================================================== diff -u -N --- src/libicpf/config_property.h (revision 0) +++ src/libicpf/config_property.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,183 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CONFIGPROPERTY_H__ +#define __CONFIGPROPERTY_H__ + +#include "gen_types.h" +#include "libicpf.h" + +BEGIN_ICPF_NAMESPACE + +/** \brief Basic property description class. + */ +class LIBICPF_API property +{ +public: + /// Masks identifiers for property type + enum prop_mask + { + mask_type=0x0000ffff, ///< Property type mask + mask_flags=0xffff0000 ///< Property flags mask + }; + + /// Property type definitions + enum prop_type + { + type_unknown=0x00000001, /// Unknown type (partial synonym of PT_STRING) + type_signed_num=0x00000002, /// Signed 64-bit type property + type_unsigned_num=0x00000003, /// Unsigned 64-bit type property + type_bool=0x00000004, /// Bool type property + type_string=0x00000005 /// String type property + }; + + /// Property flags definitions + enum prop_flags + { + flag_none=0x00000000, /// Standard property flag + flag_path=0x00010000, /// The string specifies a pathname flag + flag_encrypt=0x00040000, /// This flag indicates that the property has been encrypted with a password (only string values) + flag_decoded=0x00080000, /// The property is currently in decrypted state (but should be encrypted when saving) + flag_array=0x00100000, /// Array property type + flag_modified=0x00200000 /// Modification flag + }; + + // actions used by set_xxx() + enum actions + { + action_add, ///< Value should be added + action_replace, ///< Value should replace all previous values + action_setat ///< Value should replace only a specific value + }; +public: +/** \brief Construction/destruction/operators */ +/**@{*/ + property(); ///< Standard constructor + property(const tchar_t* pszName, uint_t uiType); ///< Constructor with initializer + property(const property& src); ///< Copy constructor + ~property(); ///< Standard destructor + + property& operator=(const property& rSrc); ///< Assignment operator +/**@}*/ + +/** \brief Property settings/operations */ +/**@{*/ + /// Resets the internal members + void clear(); + + /// Sets a property type + void init(const tchar_t* pszName, uint_t uiType, bool bClear=true); + /// Retrieves a property type (with flags) + uint_t get_type() const { return m_uiPropType; }; + /// Checks if the property is array-based + bool is_array() const { return (m_uiPropType & flag_array) != false; }; + + /// Sets a property name + void set_name(const tchar_t* pszName) { m_pszName=copy_string(pszName); }; + /// Gets a property name + const tchar_t* get_name() const { return m_pszName; }; + + /// Sets the modified flag + void set_modified(bool bModified) { if (bModified) m_uiPropType |= flag_modified; else m_uiPropType &= ~flag_modified; }; + /// Gets the modified flag + bool is_modified() const { return (m_uiPropType & flag_modified) != false; }; +/**@}*/ + +/** \brief Property values */ +/**@{*/ + /// Sets a value from string + void set_value(const tchar_t* pszValue, actions a=action_replace, size_t tIndex=0); + /// Gets the value as string + const tchar_t* get_value(tchar_t* pszString, size_t stMaxSize, size_t stIndex=0); + + /// Sets the string value + void set_string(const tchar_t* pszValue, actions a=action_replace, size_t tIndex=0); + /// Gets the string value + const tchar_t* get_string(size_t stIndex=0) const; + + /// Sets the signed number value + void set_signed_num(ll_t llValue, actions a=action_replace, size_t tIndex=0); + /// Sets the signed number range + void set_signed_range(ll_t llMin, ll_t llMax); + /// Gets the signed number value + ll_t get_signed_num(size_t stIndex=0) const; + + /// Sets the unsigned number value + void set_unsigned_num(ull_t ullValue, actions a=action_replace, size_t tIndex=0); + /// Sets the unsigned number range + void set_unsigned_range(ull_t ullMin, ull_t ullMax); + /// Gets the unsigned number value + ull_t get_unsigned_num(size_t stIndex=0) const; + + /// Sets the bool value + void set_bool(bool bValue, actions a=action_replace, size_t tIndex=0); + /// Gets the bool value + bool get_bool(size_t stIndex=0) const; + + /// Gets the property count for an array property type + size_t get_count() const; + /// Removes a property at a given index + void remove(size_t stIndex); + /// Clears the array + void clear_array(); +/**@}*/ + +protected: + void clear_value(); ///< Clears the current value (frees any allocated memory) + void check_range(); ///< Performs a range check on the property value + + tchar_t* copy_string(const tchar_t* pszSrc); ///< Makes a copy of a given string + bool bool_from_string(const tchar_t* pszSrc); ///< Retrieves a bool value from a string + ll_t signed_from_string(const tchar_t* pszSrc); ///< Retrieves a signed number from a string + ull_t unsigned_from_string(const tchar_t* pszSrc); ///< Retrieves an unsigned number from a string + + void copy_from(const property& rSrc, bool bClear); ///< Makes a copy of a given property + +protected: + // basic, common property description + uint_t m_uiPropType; ///< Property type and flags + tchar_t* m_pszName; ///< Name of the property + + // values + union _VALUE /// Union with different types of properties + { + ll_t llVal; ///< Signed number value + ull_t ullVal; ///< Unsigned number value + bool bVal; ///< A bool-type value + tchar_t* pszVal; ///< A string-type value + ptr_t hArray; ///< An array-type value + } m_val; + + union _RANGE /// Union with numeric properties ranges + { + struct LLRANGE + { + ll_t llLo; ///< Minimum allowed value for the longlong_t property + ll_t llHi; ///< Maximum allowed value for the longlong_t property + } ll; + struct ULLRANGE + { + ull_t ullLo; ///< Minimum allowed value for the ull_t property + ull_t ullHi; ///< Maximum allowed value for the ull_t property + } ull; + } m_range; +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/config_property.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/config_property.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/config_property.h (revision 0) @@ -1,183 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CONFIGPROPERTY_H__ -#define __CONFIGPROPERTY_H__ - -#include "gen_types.h" -#include "libicpf.h" - -BEGIN_ICPF_NAMESPACE - -/** \brief Basic property description class. - */ -class LIBICPF_API property -{ -public: - /// Masks identifiers for property type - enum prop_mask - { - mask_type=0x0000ffff, ///< Property type mask - mask_flags=0xffff0000 ///< Property flags mask - }; - - /// Property type definitions - enum prop_type - { - type_unknown=0x00000001, /// Unknown type (partial synonym of PT_STRING) - type_signed_num=0x00000002, /// Signed 64-bit type property - type_unsigned_num=0x00000003, /// Unsigned 64-bit type property - type_bool=0x00000004, /// Bool type property - type_string=0x00000005 /// String type property - }; - - /// Property flags definitions - enum prop_flags - { - flag_none=0x00000000, /// Standard property flag - flag_path=0x00010000, /// The string specifies a pathname flag - flag_encrypt=0x00040000, /// This flag indicates that the property has been encrypted with a password (only string values) - flag_decoded=0x00080000, /// The property is currently in decrypted state (but should be encrypted when saving) - flag_array=0x00100000, /// Array property type - flag_modified=0x00200000 /// Modification flag - }; - - // actions used by set_xxx() - enum actions - { - action_add, ///< Value should be added - action_replace, ///< Value should replace all previous values - action_setat ///< Value should replace only a specific value - }; -public: -/** \brief Construction/destruction/operators */ -/**@{*/ - property(); ///< Standard constructor - property(const tchar_t* pszName, uint_t uiType); ///< Constructor with initializer - property(const property& src); ///< Copy constructor - ~property(); ///< Standard destructor - - property& operator=(const property& rSrc); ///< Assignment operator -/**@}*/ - -/** \brief Property settings/operations */ -/**@{*/ - /// Resets the internal members - void clear(); - - /// Sets a property type - void init(const tchar_t* pszName, uint_t uiType, bool bClear=true); - /// Retrieves a property type (with flags) - uint_t get_type() const { return m_uiPropType; }; - /// Checks if the property is array-based - bool is_array() const { return (m_uiPropType & flag_array) != false; }; - - /// Sets a property name - void set_name(const tchar_t* pszName) { m_pszName=copy_string(pszName); }; - /// Gets a property name - const tchar_t* get_name() const { return m_pszName; }; - - /// Sets the modified flag - void set_modified(bool bModified) { if (bModified) m_uiPropType |= flag_modified; else m_uiPropType &= ~flag_modified; }; - /// Gets the modified flag - bool is_modified() const { return (m_uiPropType & flag_modified) != false; }; -/**@}*/ - -/** \brief Property values */ -/**@{*/ - /// Sets a value from string - void set_value(const tchar_t* pszValue, actions a=action_replace, size_t tIndex=0); - /// Gets the value as string - const tchar_t* get_value(tchar_t* pszString, size_t stMaxSize, size_t stIndex=0); - - /// Sets the string value - void set_string(const tchar_t* pszValue, actions a=action_replace, size_t tIndex=0); - /// Gets the string value - const tchar_t* get_string(size_t stIndex=0) const; - - /// Sets the signed number value - void set_signed_num(ll_t llValue, actions a=action_replace, size_t tIndex=0); - /// Sets the signed number range - void set_signed_range(ll_t llMin, ll_t llMax); - /// Gets the signed number value - ll_t get_signed_num(size_t stIndex=0) const; - - /// Sets the unsigned number value - void set_unsigned_num(ull_t ullValue, actions a=action_replace, size_t tIndex=0); - /// Sets the unsigned number range - void set_unsigned_range(ull_t ullMin, ull_t ullMax); - /// Gets the unsigned number value - ull_t get_unsigned_num(size_t stIndex=0) const; - - /// Sets the bool value - void set_bool(bool bValue, actions a=action_replace, size_t tIndex=0); - /// Gets the bool value - bool get_bool(size_t stIndex=0) const; - - /// Gets the property count for an array property type - size_t get_count() const; - /// Removes a property at a given index - void remove(size_t stIndex); - /// Clears the array - void clear_array(); -/**@}*/ - -protected: - void clear_value(); ///< Clears the current value (frees any allocated memory) - void check_range(); ///< Performs a range check on the property value - - tchar_t* copy_string(const tchar_t* pszSrc); ///< Makes a copy of a given string - bool bool_from_string(const tchar_t* pszSrc); ///< Retrieves a bool value from a string - ll_t signed_from_string(const tchar_t* pszSrc); ///< Retrieves a signed number from a string - ull_t unsigned_from_string(const tchar_t* pszSrc); ///< Retrieves an unsigned number from a string - - void copy_from(const property& rSrc, bool bClear); ///< Makes a copy of a given property - -protected: - // basic, common property description - uint_t m_uiPropType; ///< Property type and flags - tchar_t* m_pszName; ///< Name of the property - - // values - union _VALUE /// Union with different types of properties - { - ll_t llVal; ///< Signed number value - ull_t ullVal; ///< Unsigned number value - bool bVal; ///< A bool-type value - tchar_t* pszVal; ///< A string-type value - ptr_t hArray; ///< An array-type value - } m_val; - - union _RANGE /// Union with numeric properties ranges - { - struct LLRANGE - { - ll_t llLo; ///< Minimum allowed value for the longlong_t property - ll_t llHi; ///< Maximum allowed value for the longlong_t property - } ll; - struct ULLRANGE - { - ull_t ullLo; ///< Minimum allowed value for the ull_t property - ull_t ullHi; ///< Maximum allowed value for the ull_t property - } ull; - } m_range; -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/conv.cpp =================================================================== diff -u -N --- src/libicpf/conv.cpp (revision 0) +++ src/libicpf/conv.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,74 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "conv.h" +#include + +BEGIN_ICPF_NAMESPACE + +char_t __hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + +LIBICPF_API void bin2hex(const uchar_t* pbyIn, uint_t tInCount, char_t *pszOut) +{ + for (uint_t i=0;i> 4) & 0x0f]; + *pszOut++=__hex[pbyIn[i] & 0x0f]; + } +} + +LIBICPF_API bool hex2bin(const char_t* pszIn, uint_t tInCount, uchar_t *pbyOut) +{ + // we can pass -1 as in size - count it then + if (tInCount == (uint_t)-1) + tInCount=(uint_t)strlen(pszIn); + + // make sure the tInCount is even + tInCount &= ~((size_t)1); + byte_t by; + for (size_t i=0;i= '0' && *pszIn <= '9') + by=(byte_t)(*pszIn - '0') << 4; + else if (*pszIn >= 'a' && *pszIn <= 'f') + by=(byte_t)(*pszIn - 'a' + 10) << 4; + else if (*pszIn >= 'A' && *pszIn <= 'F') + by=(byte_t)(*pszIn - 'A' + 10) << 4; + else + return false; + + // lsb 4bits + pszIn++; + if (*pszIn >= '0' && *pszIn <= '9') + by|=(*pszIn - '0'); + else if (*pszIn >= 'a' && *pszIn <= 'f') + by|=(*pszIn - 'a' + 10); + else if (*pszIn >= 'A' && *pszIn <= 'F') + by|=(*pszIn - 'A' + 10); + else + return false; + + pszIn++; + *pbyOut++=by; + } + + return true; +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/conv.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/conv.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/conv.cpp (revision 0) @@ -1,74 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#include "conv.h" -#include - -BEGIN_ICPF_NAMESPACE - -char_t __hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - -LIBICPF_API void bin2hex(const uchar_t* pbyIn, uint_t tInCount, char_t *pszOut) -{ - for (uint_t i=0;i> 4) & 0x0f]; - *pszOut++=__hex[pbyIn[i] & 0x0f]; - } -} - -LIBICPF_API bool hex2bin(const char_t* pszIn, uint_t tInCount, uchar_t *pbyOut) -{ - // we can pass -1 as in size - count it then - if (tInCount == (uint_t)-1) - tInCount=(uint_t)strlen(pszIn); - - // make sure the tInCount is even - tInCount &= ~((size_t)1); - byte_t by; - for (size_t i=0;i= '0' && *pszIn <= '9') - by=(byte_t)(*pszIn - '0') << 4; - else if (*pszIn >= 'a' && *pszIn <= 'f') - by=(byte_t)(*pszIn - 'a' + 10) << 4; - else if (*pszIn >= 'A' && *pszIn <= 'F') - by=(byte_t)(*pszIn - 'A' + 10) << 4; - else - return false; - - // lsb 4bits - pszIn++; - if (*pszIn >= '0' && *pszIn <= '9') - by|=(*pszIn - '0'); - else if (*pszIn >= 'a' && *pszIn <= 'f') - by|=(*pszIn - 'a' + 10); - else if (*pszIn >= 'A' && *pszIn <= 'F') - by|=(*pszIn - 'A' + 10); - else - return false; - - pszIn++; - *pbyOut++=by; - } - - return true; -} - -END_ICPF_NAMESPACE Index: src/libicpf/conv.h =================================================================== diff -u -N --- src/libicpf/conv.h (revision 0) +++ src/libicpf/conv.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,33 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __CONV_H__ +#define __CONV_H__ + +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +LIBICPF_API void bin2hex(const uchar_t *pbyIn, uint_t tInCount, char_t *pszOut); +LIBICPF_API bool hex2bin(const char_t* pszIn, uint_t tInCount, uchar_t* pbyOut); + +END_ICPF_NAMESPACE + +#endif + Index: ext/libicpf/src/libicpf/conv.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/conv.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/conv.h (revision 0) @@ -1,33 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __CONV_H__ -#define __CONV_H__ - -#include "libicpf.h" -#include "gen_types.h" - -BEGIN_ICPF_NAMESPACE - -LIBICPF_API void bin2hex(const uchar_t *pbyIn, uint_t tInCount, char_t *pszOut); -LIBICPF_API bool hex2bin(const char_t* pszIn, uint_t tInCount, uchar_t* pbyOut); - -END_ICPF_NAMESPACE - -#endif - Index: src/libicpf/crc32.cpp =================================================================== diff -u -N --- src/libicpf/crc32.cpp (revision 0) +++ src/libicpf/crc32.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,167 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file crc32.cpp + * \brief Contain implementation of a function counting crc32 checksum + */ + +#include "crc32.h" +#include "err_codes.h" +#include "exception.h" +#include +#ifndef _WIN32 + #include +#endif + +BEGIN_ICPF_NAMESPACE + +/// Helper data for calculating crc32 values +uint_t __crc32data__[256] = +{ + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, +}; + +/** \brief Updates the partial crc32 checksum with an additional byte. + * \param[in] byte - next byte of a buffer to process + * \param[in,out] pdwCrc32 - ptr to a current crc32 checksum + */ +inline void __crc32partial(byte_t byte, uint_t *pdwCrc32) +{ +// assert(pdwCrc32 != NULL); + *pdwCrc32 = ((*pdwCrc32) >> 8) ^ __crc32data__[byte ^ ((*pdwCrc32) & 0x000000FF)]; +} + +/** Function calculates the crc32 checksum for the given data buffer. + * \param[in] pbyData - pointer to a buffer with data which checksum is to be calculated + * \param[in] tLen - length of the data in a buffer + * \return Calculated crc32 checksum. + */ +uint_t crc32(const byte_t* pbyData, size_t tLen) +{ + uint_t dwCRC=0xffffffff; + for (size_t i=0;i -#ifndef _WIN32 - #include -#endif - -BEGIN_ICPF_NAMESPACE - -/// Helper data for calculating crc32 values -uint_t __crc32data__[256] = -{ - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, - 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, - 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, - 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, - 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, - 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, - 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, - 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, - 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, - 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, - 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, - 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, - 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, - 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, - 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, - 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, - 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, - 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, - 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, - 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, - 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, - 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, - 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, - 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, - 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, - 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, - 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, - 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, - 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, - 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, - 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, - 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, - 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, -}; - -/** \brief Updates the partial crc32 checksum with an additional byte. - * \param[in] byte - next byte of a buffer to process - * \param[in,out] pdwCrc32 - ptr to a current crc32 checksum - */ -inline void __crc32partial(byte_t byte, uint_t *pdwCrc32) -{ -// assert(pdwCrc32 != NULL); - *pdwCrc32 = ((*pdwCrc32) >> 8) ^ __crc32data__[byte ^ ((*pdwCrc32) & 0x000000FF)]; -} - -/** Function calculates the crc32 checksum for the given data buffer. - * \param[in] pbyData - pointer to a buffer with data which checksum is to be calculated - * \param[in] tLen - length of the data in a buffer - * \return Calculated crc32 checksum. - */ -uint_t crc32(const byte_t* pbyData, size_t tLen) -{ - uint_t dwCRC=0xffffffff; - for (size_t i=0;i + +BEGIN_ICPF_NAMESPACE + +/// Calculates crc32 checksum for a given data +LIBICPF_API uint_t crc32(const byte_t* pbyData, size_t tLen); + +LIBICPF_API void crc32_begin(uint_t *puiValue); +LIBICPF_API void crc32_partial(uint_t *puiPrev, const byte_t *pbyData, size_t tLen); +LIBICPF_API void crc32_finish(const uint_t* puiValue); + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/crc32.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/crc32.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/crc32.h (revision 0) @@ -1,42 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ - -/** \file crc32.h - * \brief Contain function counting crc32 checksum - */ - -#ifndef __CRC32_H__ -#define __CRC32_H__ - -#include "libicpf.h" -#include "gen_types.h" -#include - -BEGIN_ICPF_NAMESPACE - -/// Calculates crc32 checksum for a given data -LIBICPF_API uint_t crc32(const byte_t* pbyData, size_t tLen); - -LIBICPF_API void crc32_begin(uint_t *puiValue); -LIBICPF_API void crc32_partial(uint_t *puiPrev, const byte_t *pbyData, size_t tLen); -LIBICPF_API void crc32_finish(const uint_t* puiValue); - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/dmutex.cpp =================================================================== diff -u -N --- src/libicpf/dmutex.cpp (revision 0) +++ src/libicpf/dmutex.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,188 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file dmutex.cpp + * \brief Contains mutex class for thread safe access with debugging capabilities (implementation). + * \see The mutex class. + */ +#include "dmutex.h" + +#ifdef ENABLE_MUTEX_DEBUGGING + +#include +#include + +#ifdef _WIN32 + #include +#endif + +BEGIN_ICPF_NAMESPACE + +/////////////////////////////////////////////////////////////// +// debuggable mutex + +/** \brief Static dump context. + * + * Must be initialized before using this class. + */ +dumpctx* d_mutex::m_pContext=NULL; + +/** Constructs an unnamed mutex with a given dump context which will receive + * notifications about locking and unlocking of this mutex. + */ +d_mutex::d_mutex() : + mutex(), + m_ulLockCount(0) +{ + const char_t* psz="Unnamed"; + m_pszName=new char_t[strlen(psz)+1]; + strcpy(m_pszName, psz); + + m_ulLockCount=0; +} + +/** Constructs a named mutex with a given dump context which will receive + * notifications about locking and unlocking of this mutex. + * + * \param[in] pszStr - name of this mutex (will be used for logging purposes) + */ +d_mutex::d_mutex(const char_t* pszStr) : + mutex(pszStr), + m_ulLockCount(0) +{ + m_pszName=new char_t[strlen(pszStr)+1]; + strcpy(m_pszName, pszStr); +} + +/** Destructs the object + */ +d_mutex::~d_mutex() +{ + delete [] m_pszName; +} + +/** Locks this mutex. Takes some parameters that should identify the place in code which + * at which the locking occurs. + * + * \param[in] pszFile - name of the source file in which the locking was requested + * \param[in] ulLine - line of code in the file at which the locking was requested + * \param[in] pszFunction - name of the function in which the locking was requested + */ +void d_mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + assert(m_pContext); + char_t sz[512]; + + // pre-lock notification + if (m_pContext) + { +#ifdef _WIN32 + uint_t uiThread=GetCurrentThreadId(); + uint_t uiTime=GetTickCount(); +#else + // TODO: linux version of thread id must be put here sometime in the future + assert(false); + uint_t uiThread=0; + uint_t uiTime=time(NULL); +#endif + _snprintf(sz, 512, "[%lu][%lu][%s] Lock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + m_pContext->open(sz); + m_pContext->close(); + } + + // this is the real locking + ((mutex*)this)->lock(); + m_ulLockCount++; + + // post-lock information + if (m_pContext) + { +#ifdef _WIN32 + uint_t uiThread=GetCurrentThreadId(); + uint_t uiTime=GetTickCount(); +#else + // TODO: linux version of thread id must be put here sometime in the future + assert(false); + uint_t uiThread=0; + uint_t uiTime=time(NULL); +#endif + _snprintf(sz, 512, "[%lu][%lu][%s] LOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + m_pContext->open(sz); + m_pContext->close(); + } +} + +/** Unlocks this mutex. Takes some parameters that should identify the place in code which + * at which the unlocking occurs. + * + * \param[in] pszFile - name of the source file in which the unlocking was requested + * \param[in] ulLine - line of code in the file at which the unlocking was requested + * \param[in] pszFunction - name of the function in which the unlocking was requested + */ +void d_mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + assert(m_pContext); + char_t sz[512]; + + // pre-lock notification + if (m_pContext) + { +#ifdef _WIN32 + uint_t uiThread=GetCurrentThreadId(); + uint_t uiTime=GetTickCount(); +#else + // TODO: linux version of thread id must be put here sometime in the future + assert(false); + uint_t uiThread=0; + uint_t uiTime=time(NULL); +#endif + _snprintf(sz, 512, "[%lu][%lu][%s] Unlock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + m_pContext->open(sz); + m_pContext->close(); + } + + // log the attempt and lock it + m_ulLockCount--; + ((mutex*)this)->unlock(); + + // post-unlock notification + // NOTE: code here is quite dangerous - and could CRASH the application; + // we have just unlocked the real mutex, so anyone has access to the object protected + // by this d_mutex. If the object being protected is removed - the internal members + // would be invalid. It especially have some meaning for the sprintf function + // probably because of the m_pszName member + if (m_pContext) + { +#ifdef _WIN32 + uint_t uiThread=GetCurrentThreadId(); + uint_t uiTime=GetTickCount(); +#else + // TODO: linux version of thread id must be put here sometime in the future + assert(false); + uint_t uiThread=0; + uint_t uiTime=time(NULL); +#endif + _snprintf(sz, 512, "[%lu][%lu][%s] UNLOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + m_pContext->open(sz); + m_pContext->close(); + } +} + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/dmutex.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/dmutex.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/dmutex.cpp (revision 0) @@ -1,188 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file dmutex.cpp - * \brief Contains mutex class for thread safe access with debugging capabilities (implementation). - * \see The mutex class. - */ -#include "dmutex.h" - -#ifdef ENABLE_MUTEX_DEBUGGING - -#include -#include - -#ifdef _WIN32 - #include -#endif - -BEGIN_ICPF_NAMESPACE - -/////////////////////////////////////////////////////////////// -// debuggable mutex - -/** \brief Static dump context. - * - * Must be initialized before using this class. - */ -dumpctx* d_mutex::m_pContext=NULL; - -/** Constructs an unnamed mutex with a given dump context which will receive - * notifications about locking and unlocking of this mutex. - */ -d_mutex::d_mutex() : - mutex(), - m_ulLockCount(0) -{ - const char_t* psz="Unnamed"; - m_pszName=new char_t[strlen(psz)+1]; - strcpy(m_pszName, psz); - - m_ulLockCount=0; -} - -/** Constructs a named mutex with a given dump context which will receive - * notifications about locking and unlocking of this mutex. - * - * \param[in] pszStr - name of this mutex (will be used for logging purposes) - */ -d_mutex::d_mutex(const char_t* pszStr) : - mutex(pszStr), - m_ulLockCount(0) -{ - m_pszName=new char_t[strlen(pszStr)+1]; - strcpy(m_pszName, pszStr); -} - -/** Destructs the object - */ -d_mutex::~d_mutex() -{ - delete [] m_pszName; -} - -/** Locks this mutex. Takes some parameters that should identify the place in code which - * at which the locking occurs. - * - * \param[in] pszFile - name of the source file in which the locking was requested - * \param[in] ulLine - line of code in the file at which the locking was requested - * \param[in] pszFunction - name of the function in which the locking was requested - */ -void d_mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) -{ - assert(m_pContext); - char_t sz[512]; - - // pre-lock notification - if (m_pContext) - { -#ifdef _WIN32 - uint_t uiThread=GetCurrentThreadId(); - uint_t uiTime=GetTickCount(); -#else - // TODO: linux version of thread id must be put here sometime in the future - assert(false); - uint_t uiThread=0; - uint_t uiTime=time(NULL); -#endif - _snprintf(sz, 512, "[%lu][%lu][%s] Lock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); - m_pContext->open(sz); - m_pContext->close(); - } - - // this is the real locking - ((mutex*)this)->lock(); - m_ulLockCount++; - - // post-lock information - if (m_pContext) - { -#ifdef _WIN32 - uint_t uiThread=GetCurrentThreadId(); - uint_t uiTime=GetTickCount(); -#else - // TODO: linux version of thread id must be put here sometime in the future - assert(false); - uint_t uiThread=0; - uint_t uiTime=time(NULL); -#endif - _snprintf(sz, 512, "[%lu][%lu][%s] LOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); - m_pContext->open(sz); - m_pContext->close(); - } -} - -/** Unlocks this mutex. Takes some parameters that should identify the place in code which - * at which the unlocking occurs. - * - * \param[in] pszFile - name of the source file in which the unlocking was requested - * \param[in] ulLine - line of code in the file at which the unlocking was requested - * \param[in] pszFunction - name of the function in which the unlocking was requested - */ -void d_mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) -{ - assert(m_pContext); - char_t sz[512]; - - // pre-lock notification - if (m_pContext) - { -#ifdef _WIN32 - uint_t uiThread=GetCurrentThreadId(); - uint_t uiTime=GetTickCount(); -#else - // TODO: linux version of thread id must be put here sometime in the future - assert(false); - uint_t uiThread=0; - uint_t uiTime=time(NULL); -#endif - _snprintf(sz, 512, "[%lu][%lu][%s] Unlock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); - m_pContext->open(sz); - m_pContext->close(); - } - - // log the attempt and lock it - m_ulLockCount--; - ((mutex*)this)->unlock(); - - // post-unlock notification - // NOTE: code here is quite dangerous - and could CRASH the application; - // we have just unlocked the real mutex, so anyone has access to the object protected - // by this d_mutex. If the object being protected is removed - the internal members - // would be invalid. It especially have some meaning for the sprintf function - // probably because of the m_pszName member - if (m_pContext) - { -#ifdef _WIN32 - uint_t uiThread=GetCurrentThreadId(); - uint_t uiTime=GetTickCount(); -#else - // TODO: linux version of thread id must be put here sometime in the future - assert(false); - uint_t uiThread=0; - uint_t uiTime=time(NULL); -#endif - _snprintf(sz, 512, "[%lu][%lu][%s] UNLOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); - m_pContext->open(sz); - m_pContext->close(); - } -} - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/dmutex.h =================================================================== diff -u -N --- src/libicpf/dmutex.h (revision 0) +++ src/libicpf/dmutex.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,75 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file dmutex.h + * \brief Contains mutex class for thread safe access with debugging capabilities. + * \see The mutex class. + */ +#ifndef __DMUTEX_H__ +#define __DMUTEX_H__ + +#include "libicpf.h" +#include "gen_types.h" +#include "dumpctx.h" +#include "mutex.h" + +#ifdef ENABLE_MUTEX_DEBUGGING + +BEGIN_ICPF_NAMESPACE + +/** \brief Class provides the locking and unlocking capabilities for use with threads. + * + * Class is a simple wrapper over the system related thread locking functions. In linux + * those functions are pthread_mutex_* and in windoze the functions related to CRITICAL_SECTION + * structure. + * This class is very similar to the mutex class, with the difference that it allows logging + * of the locking/unlocking allowing easier debugging of the mutexes. Interface is almost + * out-of-the-box replaceable with standard mutex class. + * To use this class properly - the icpf::d_mutex::m_pContext static member has to be initialized + * to a pointer to a dumpctx class that will receive notifications. + */ +class LIBICPF_API d_mutex : public mutex +{ +public: +/** \name Construction/destruction */ +/**@{*/ + d_mutex(); ///< Constructs an unnamed mutex + d_mutex(const char_t* pszStr); ///< Constructs a named mutex + virtual ~d_mutex(); ///< Standard destructor +/**@}*/ + + // standard locking +/** \name Locking/unlocking */ +/**@{*/ + void lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); ///< Locking with logging + void unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); ///< Unlocking with logging +/**@}*/ + +public: + static dumpctx* m_pContext; ///< Dump context that will receive informations about locking/unlocking + +private: + char* m_pszName; ///< Name of the mutex + ulong_t m_ulLockCount; ///< Current lock count +}; + +END_ICPF_NAMESPACE + +#endif + +#endif Index: ext/libicpf/src/libicpf/dmutex.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/dmutex.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/dmutex.h (revision 0) @@ -1,75 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file dmutex.h - * \brief Contains mutex class for thread safe access with debugging capabilities. - * \see The mutex class. - */ -#ifndef __DMUTEX_H__ -#define __DMUTEX_H__ - -#include "libicpf.h" -#include "gen_types.h" -#include "dumpctx.h" -#include "mutex.h" - -#ifdef ENABLE_MUTEX_DEBUGGING - -BEGIN_ICPF_NAMESPACE - -/** \brief Class provides the locking and unlocking capabilities for use with threads. - * - * Class is a simple wrapper over the system related thread locking functions. In linux - * those functions are pthread_mutex_* and in windoze the functions related to CRITICAL_SECTION - * structure. - * This class is very similar to the mutex class, with the difference that it allows logging - * of the locking/unlocking allowing easier debugging of the mutexes. Interface is almost - * out-of-the-box replaceable with standard mutex class. - * To use this class properly - the icpf::d_mutex::m_pContext static member has to be initialized - * to a pointer to a dumpctx class that will receive notifications. - */ -class LIBICPF_API d_mutex : public mutex -{ -public: -/** \name Construction/destruction */ -/**@{*/ - d_mutex(); ///< Constructs an unnamed mutex - d_mutex(const char_t* pszStr); ///< Constructs a named mutex - virtual ~d_mutex(); ///< Standard destructor -/**@}*/ - - // standard locking -/** \name Locking/unlocking */ -/**@{*/ - void lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); ///< Locking with logging - void unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); ///< Unlocking with logging -/**@}*/ - -public: - static dumpctx* m_pContext; ///< Dump context that will receive informations about locking/unlocking - -private: - char* m_pszName; ///< Name of the mutex - ulong_t m_ulLockCount; ///< Current lock count -}; - -END_ICPF_NAMESPACE - -#endif - -#endif Index: src/libicpf/dumpctx.cpp =================================================================== diff -u -N --- src/libicpf/dumpctx.cpp (revision 0) +++ src/libicpf/dumpctx.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,264 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file dumpctx.cpp + * \brief Contain implementation of class dumpctx - a debug helper class. + */ +#include "dumpctx.h" +#include +#include "log.h" + +BEGIN_ICPF_NAMESPACE + +/// Helper definition for faster access +#define m_pBuffer ((tstring_t*)m_hBuffer) + +/** Constructor stores the passed data in the internal members. + * \param[in] uiType - type of dump (one of the DCX_*) + * \param[in] pParam - additional param - the type of theis param depends on the ulType + */ +dumpctx::dumpctx(uint_t uiType, ptr_t pParam) : + m_lock(), + m_hBuffer((ptr_t)new tstring_t), + m_uiType(uiType), + m_pParam(pParam) +{ + m_uiType=uiType; + if (uiType == type_file) + { + size_t tLen=_tcslen((const tchar_t*)pParam); + m_pParam=(ptr_t)new tchar_t[tLen+1]; + _tcscpy((tchar_t*)m_pParam, (const tchar_t*)pParam); + } + else + m_pParam=pParam; + m_szBuffer[0]=_t('\0'); +} + +/** Destructor frees the internal data if needed + */ +dumpctx::~dumpctx() +{ + if (m_uiType == type_file) + delete [] (tchar_t*)m_pParam; + else + m_pParam=NULL; // we won't have a leak here, since we don't alloc memory for case m_uiType != type_file +} + +/** Function opens the dump. It means initializing the internal string + * that will contain the dump result and locking the class (using mutex). + * \note Always call the close() member if you have opened the dump. + */ +void dumpctx::open(const tchar_t* pszObject) +{ + MLOCK(m_lock); + *m_pBuffer=pszObject; + *m_pBuffer+=_t("\n"); +} + +/** Closes the dump. Depending on the type specified in the constructor the + * function outputs the dump to the specified location. Also the internal + * buffer is cleared. + */ +void dumpctx::close() +{ + // perform a dump - depending on the type of a dest object + switch(m_uiType) + { + case type_std: + { + _tprintf(TSTRFMT, m_pBuffer->c_str()); + break; + } + case type_file: + { + FILE* pFile=_tfopen((const tchar_t*)m_pParam, _t("a")); + if (pFile != NULL) + { + _ftprintf(pFile, TSTRFMT, m_pBuffer->c_str()); + fclose(pFile); + } + + break; + } + case type_filehandle: + { + _ftprintf((FILE*)m_pParam, TSTRFMT, m_pBuffer->c_str()); + break; + } + case type_log: + { + ((log_file*)m_pParam)->logdv(TSTRFMT, m_pBuffer->c_str()); + break; + } + default: + break; + } + + // clean the internal buffer + m_pBuffer->clear(); + + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given ansi string. + * Strings longer than max_dump characters will be truncated. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] pszValue - an ansi string - the value of a given member + */ +void dumpctx::dump(const tchar_t* pszName, const tchar_t* pszValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (tstring):\n\t") PTRFMT _t(" (\"") TSTRFMT _t("\")\n"), pszName, pszValue, pszValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given unicode string. + * Strings longer than max_dump characters will be truncated. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] pszValue - an unicode string - the value of a given member + */ +/*void dumpctx::dump(const tchar_t* pszName, const wchar_t* pszValue) +{ + _sntprintf(m_szBuffer, max_dump, STRFMT _t(" (wide string):\n\t") PTRFMT _t(" (\"") WSTRFMT _t("\")\n"), pszName, pszValue, pszValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +}*/ + +/** Function dumps (stores in the internal string object) the given character. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] cValue - a character (signed tchar_t) value + */ +void dumpctx::dump(const tchar_t* pszName, const tchar_t cValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (tchar_t):\n\t'") TCHRFMT _t("' (hex: ") CXFMT _t(" / dec: ") CFMT _t(")\n"), pszName, cValue, (short_t)cValue, (short_t)cValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given short_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] sValue - a short_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const short_t sValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (short_t):\n\t") SFMT _t(" (hex: ") SXFMT _t(")\n"), pszName, sValue, sValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given int_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] iValue - a int_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const int_t iValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (int_t):\n\t") LFMT _t(" (hex: ") LXFMT _t(")\n"), pszName, iValue, iValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given uchar_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] ucValue - an uchar_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const uchar_t ucValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uchar_t):\n\t'") UCHARFMT _t("' (hex: ") UCXFMT _t(" / dec: ") UCFMT _t(")\n"), pszName, ucValue, (ushort_t)ucValue, (ushort_t)ucValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given ushort_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] usValue - an ushort_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const ushort_t usValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ushort_t):\n\t") USFMT _t(" (hex: ") USXFMT _t(")\n"), pszName, usValue, usValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the given uint_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] uiValue - an uint_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const uint_t uiValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uint_t):\n\t") ULFMT _t(" (hex: ") ULXFMT _t(")\n"), pszName, uiValue, uiValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the longlong_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] llValue - a longlong_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const longlong_t llValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (longlong_t):\n\t") LLFMT _t(" (hex: ") LLXFMT _t(")\n"), pszName, llValue, llValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the ulonglong_t. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] ullValue - an ulonglong_t value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const ulonglong_t ullValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ulonglong_t):\n\t") ULLFMT _t(" (hex: ") ULLXFMT _t(")\n"), pszName, ullValue, ullValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +/** Function dumps (stores in the internal string object) the untyped pointer. + * \param[in] pszName - name of the member variable of the dumped object + * \param[in] pValue - an untyped pointer value to dump + */ +void dumpctx::dump(const tchar_t* pszName, const ptr_t pValue) +{ + _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ptr_t):\n\t") PTRFMT _t("\n"), pszName, pValue); + m_szBuffer[max_dump-1]=_t('\0'); + MLOCK(m_lock); + *m_pBuffer+=m_szBuffer; + MUNLOCK(m_lock); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/dumpctx.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/dumpctx.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/dumpctx.cpp (revision 0) @@ -1,264 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file dumpctx.cpp - * \brief Contain implementation of class dumpctx - a debug helper class. - */ -#include "dumpctx.h" -#include -#include "log.h" - -BEGIN_ICPF_NAMESPACE - -/// Helper definition for faster access -#define m_pBuffer ((tstring_t*)m_hBuffer) - -/** Constructor stores the passed data in the internal members. - * \param[in] uiType - type of dump (one of the DCX_*) - * \param[in] pParam - additional param - the type of theis param depends on the ulType - */ -dumpctx::dumpctx(uint_t uiType, ptr_t pParam) : - m_lock(), - m_hBuffer((ptr_t)new tstring_t), - m_uiType(uiType), - m_pParam(pParam) -{ - m_uiType=uiType; - if (uiType == type_file) - { - size_t tLen=_tcslen((const tchar_t*)pParam); - m_pParam=(ptr_t)new tchar_t[tLen+1]; - _tcscpy((tchar_t*)m_pParam, (const tchar_t*)pParam); - } - else - m_pParam=pParam; - m_szBuffer[0]=_t('\0'); -} - -/** Destructor frees the internal data if needed - */ -dumpctx::~dumpctx() -{ - if (m_uiType == type_file) - delete [] (tchar_t*)m_pParam; - else - m_pParam=NULL; // we won't have a leak here, since we don't alloc memory for case m_uiType != type_file -} - -/** Function opens the dump. It means initializing the internal string - * that will contain the dump result and locking the class (using mutex). - * \note Always call the close() member if you have opened the dump. - */ -void dumpctx::open(const tchar_t* pszObject) -{ - MLOCK(m_lock); - *m_pBuffer=pszObject; - *m_pBuffer+=_t("\n"); -} - -/** Closes the dump. Depending on the type specified in the constructor the - * function outputs the dump to the specified location. Also the internal - * buffer is cleared. - */ -void dumpctx::close() -{ - // perform a dump - depending on the type of a dest object - switch(m_uiType) - { - case type_std: - { - _tprintf(TSTRFMT, m_pBuffer->c_str()); - break; - } - case type_file: - { - FILE* pFile=_tfopen((const tchar_t*)m_pParam, _t("a")); - if (pFile != NULL) - { - _ftprintf(pFile, TSTRFMT, m_pBuffer->c_str()); - fclose(pFile); - } - - break; - } - case type_filehandle: - { - _ftprintf((FILE*)m_pParam, TSTRFMT, m_pBuffer->c_str()); - break; - } - case type_log: - { - ((log_file*)m_pParam)->logdv(TSTRFMT, m_pBuffer->c_str()); - break; - } - default: - break; - } - - // clean the internal buffer - m_pBuffer->clear(); - - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given ansi string. - * Strings longer than max_dump characters will be truncated. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] pszValue - an ansi string - the value of a given member - */ -void dumpctx::dump(const tchar_t* pszName, const tchar_t* pszValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (tstring):\n\t") PTRFMT _t(" (\"") TSTRFMT _t("\")\n"), pszName, pszValue, pszValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given unicode string. - * Strings longer than max_dump characters will be truncated. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] pszValue - an unicode string - the value of a given member - */ -/*void dumpctx::dump(const tchar_t* pszName, const wchar_t* pszValue) -{ - _sntprintf(m_szBuffer, max_dump, STRFMT _t(" (wide string):\n\t") PTRFMT _t(" (\"") WSTRFMT _t("\")\n"), pszName, pszValue, pszValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -}*/ - -/** Function dumps (stores in the internal string object) the given character. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] cValue - a character (signed tchar_t) value - */ -void dumpctx::dump(const tchar_t* pszName, const tchar_t cValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (tchar_t):\n\t'") TCHRFMT _t("' (hex: ") CXFMT _t(" / dec: ") CFMT _t(")\n"), pszName, cValue, (short_t)cValue, (short_t)cValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given short_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] sValue - a short_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const short_t sValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (short_t):\n\t") SFMT _t(" (hex: ") SXFMT _t(")\n"), pszName, sValue, sValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given int_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] iValue - a int_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const int_t iValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (int_t):\n\t") LFMT _t(" (hex: ") LXFMT _t(")\n"), pszName, iValue, iValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given uchar_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] ucValue - an uchar_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const uchar_t ucValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uchar_t):\n\t'") UCHARFMT _t("' (hex: ") UCXFMT _t(" / dec: ") UCFMT _t(")\n"), pszName, ucValue, (ushort_t)ucValue, (ushort_t)ucValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given ushort_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] usValue - an ushort_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const ushort_t usValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ushort_t):\n\t") USFMT _t(" (hex: ") USXFMT _t(")\n"), pszName, usValue, usValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the given uint_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] uiValue - an uint_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const uint_t uiValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (uint_t):\n\t") ULFMT _t(" (hex: ") ULXFMT _t(")\n"), pszName, uiValue, uiValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the longlong_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] llValue - a longlong_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const longlong_t llValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (longlong_t):\n\t") LLFMT _t(" (hex: ") LLXFMT _t(")\n"), pszName, llValue, llValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the ulonglong_t. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] ullValue - an ulonglong_t value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const ulonglong_t ullValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ulonglong_t):\n\t") ULLFMT _t(" (hex: ") ULLXFMT _t(")\n"), pszName, ullValue, ullValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -/** Function dumps (stores in the internal string object) the untyped pointer. - * \param[in] pszName - name of the member variable of the dumped object - * \param[in] pValue - an untyped pointer value to dump - */ -void dumpctx::dump(const tchar_t* pszName, const ptr_t pValue) -{ - _sntprintf(m_szBuffer, max_dump, TSTRFMT _t(" (ptr_t):\n\t") PTRFMT _t("\n"), pszName, pValue); - m_szBuffer[max_dump-1]=_t('\0'); - MLOCK(m_lock); - *m_pBuffer+=m_szBuffer; - MUNLOCK(m_lock); -} - -END_ICPF_NAMESPACE Index: src/libicpf/dumpctx.h =================================================================== diff -u -N --- src/libicpf/dumpctx.h (revision 0) +++ src/libicpf/dumpctx.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,108 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file dumpctx.h + * \brief Contain class dumpctx - a debug helper class. + */ + +#ifndef __DUMPCONTEXT_H__ +#define __DUMPCONTEXT_H__ + +#include "mutex.h" +#include "gen_types.h" +//#include "str.h" + +BEGIN_ICPF_NAMESPACE + +/// Maximum size of a single variable dump (ie. string) +//#define MAX_DUMP 4096 + +// dump type flags +/// Std out; pParam is NULL +/*#define DCX_STD 0x00000000 +/// File object; pParam is const tchar_t* with file path +#define DCX_FILE 0x00000001 +/// File object; pParam is FILE* - handle to a file opened in write mode +#define DCX_FILEHANDLE 0x00000002 +/// Log file; pParam is log_file* with the given log (dump's will be logged as LT_DEBUG) +#define DCX_LOG 0x00000003 +*/ + +/** \brief Class used as dump context (debugging purposes). + * + * Class should be used to perform dump's of any object's internal state. + * Any class could (should?) use this class as a param to the dump member. + * Usage is quite simple - construct an object with needed flags and when + * need to dump an object - call open with an object name, dump what's needed + * and then close. + * Class is thread safe. + */ +class LIBICPF_API dumpctx +{ + /// Dump types available + enum dump_types + { + type_std, /// Reporting to the console + type_file, /// Reporting to the file + type_filehandle, /// Reporting to the file handle + type_log /// Reporting to a log file + }; + + /// Internal buffer size to use + enum buf_sizes { max_dump=4096 }; +public: +/** \name Construction/destruction */ +/**@{*/ + explicit dumpctx(uint_t uiType, ptr_t pParam=NULL); ///< Standard constructor + ~dumpctx(); ///< Standard destructor +/**@}*/ + +/** \name Opening/closing dump process */ +/**@{*/ + void open(const tchar_t* pszObject); ///< Begins the specified object dump + void close(); ///< Ends the object dump +/**@}*/ + +/** \name Dumping functions + * Operations to be executed between calls to open() and close() + */ +/**@{*/ + void dump(const tchar_t* pszName, const tchar_t* pszValue); ///< Ansi string dump +// void dump(const tchar_t* pszName, const wchar_t* pszValue); ///< Unicode string dump + void dump(const tchar_t* pszName, const tchar_t cValue); ///< tchar_t dump + void dump(const tchar_t* pszName, const short_t sValue); ///< short_t dump + void dump(const tchar_t* pszName, const int_t iValue); ///< int_t dump + void dump(const tchar_t* pszName, const uchar_t ucValue); ///< uchar_t dump + void dump(const tchar_t* pszName, const ushort_t usValue); ///< ushort_t dump + void dump(const tchar_t* pszName, const uint_t uiValue); ///< uint_t dump + void dump(const tchar_t* pszName, const longlong_t llValue); ///< longlong_t dump + void dump(const tchar_t* pszName, const ulonglong_t ullValue); ///< ulonglong_t dump + void dump(const tchar_t* pszName, const ptr_t pValue); ///< pointer dump +/**@}*/ +protected: + mutex m_lock; ///< A mutex or d_mutex class cast to void* because of the circular dependencies problem +// string m_strBuffer; ///< String object that will gather information about dump + ptr_t m_hBuffer; ///< Internal buffer handle + tchar_t m_szBuffer[max_dump]; ///< Buffer used in formatting output data + uint_t m_uiType; ///< Type of dump (as passed to constructor) + ptr_t m_pParam; ///< Parameter - the real type depends on the m_ulType field +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/dumpctx.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/dumpctx.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/dumpctx.h (revision 0) @@ -1,108 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file dumpctx.h - * \brief Contain class dumpctx - a debug helper class. - */ - -#ifndef __DUMPCONTEXT_H__ -#define __DUMPCONTEXT_H__ - -#include "mutex.h" -#include "gen_types.h" -//#include "str.h" - -BEGIN_ICPF_NAMESPACE - -/// Maximum size of a single variable dump (ie. string) -//#define MAX_DUMP 4096 - -// dump type flags -/// Std out; pParam is NULL -/*#define DCX_STD 0x00000000 -/// File object; pParam is const tchar_t* with file path -#define DCX_FILE 0x00000001 -/// File object; pParam is FILE* - handle to a file opened in write mode -#define DCX_FILEHANDLE 0x00000002 -/// Log file; pParam is log_file* with the given log (dump's will be logged as LT_DEBUG) -#define DCX_LOG 0x00000003 -*/ - -/** \brief Class used as dump context (debugging purposes). - * - * Class should be used to perform dump's of any object's internal state. - * Any class could (should?) use this class as a param to the dump member. - * Usage is quite simple - construct an object with needed flags and when - * need to dump an object - call open with an object name, dump what's needed - * and then close. - * Class is thread safe. - */ -class LIBICPF_API dumpctx -{ - /// Dump types available - enum dump_types - { - type_std, /// Reporting to the console - type_file, /// Reporting to the file - type_filehandle, /// Reporting to the file handle - type_log /// Reporting to a log file - }; - - /// Internal buffer size to use - enum buf_sizes { max_dump=4096 }; -public: -/** \name Construction/destruction */ -/**@{*/ - explicit dumpctx(uint_t uiType, ptr_t pParam=NULL); ///< Standard constructor - ~dumpctx(); ///< Standard destructor -/**@}*/ - -/** \name Opening/closing dump process */ -/**@{*/ - void open(const tchar_t* pszObject); ///< Begins the specified object dump - void close(); ///< Ends the object dump -/**@}*/ - -/** \name Dumping functions - * Operations to be executed between calls to open() and close() - */ -/**@{*/ - void dump(const tchar_t* pszName, const tchar_t* pszValue); ///< Ansi string dump -// void dump(const tchar_t* pszName, const wchar_t* pszValue); ///< Unicode string dump - void dump(const tchar_t* pszName, const tchar_t cValue); ///< tchar_t dump - void dump(const tchar_t* pszName, const short_t sValue); ///< short_t dump - void dump(const tchar_t* pszName, const int_t iValue); ///< int_t dump - void dump(const tchar_t* pszName, const uchar_t ucValue); ///< uchar_t dump - void dump(const tchar_t* pszName, const ushort_t usValue); ///< ushort_t dump - void dump(const tchar_t* pszName, const uint_t uiValue); ///< uint_t dump - void dump(const tchar_t* pszName, const longlong_t llValue); ///< longlong_t dump - void dump(const tchar_t* pszName, const ulonglong_t ullValue); ///< ulonglong_t dump - void dump(const tchar_t* pszName, const ptr_t pValue); ///< pointer dump -/**@}*/ -protected: - mutex m_lock; ///< A mutex or d_mutex class cast to void* because of the circular dependencies problem -// string m_strBuffer; ///< String object that will gather information about dump - ptr_t m_hBuffer; ///< Internal buffer handle - tchar_t m_szBuffer[max_dump]; ///< Buffer used in formatting output data - uint_t m_uiType; ///< Type of dump (as passed to constructor) - ptr_t m_pParam; ///< Parameter - the real type depends on the m_ulType field -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/err_codes.h =================================================================== diff -u -N --- src/libicpf/err_codes.h (revision 0) +++ src/libicpf/err_codes.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,104 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __ERR_CODES_H__ +#define __ERR_CODES_H__ + +//////////////////////////////////////////////////////////////// +// file related +/// Base define for file related errors +#define FE_BASE 0x00010000 + +/// Unknown error +#define FERR_UNKNOWN (FE_BASE+0x0000) +/// Error while opening file +#define FERR_OPEN (FE_BASE+0x0001) +/// Error while closing file +#define FERR_CLOSE (FE_BASE+0x0002) +/// Error reading data from file +#define FERR_READ (FE_BASE+0x0003) +/// Error writing data to a file +#define FERR_WRITE (FE_BASE+0x0004) +/// Error setting file pointer position +#define FERR_SEEK (FE_BASE+0x0005) +/// eof encountered - currently unused +#define FERR_EOF (FE_BASE+0x0006) +/// error while setting an eof in file +#define FERR_SETEOF (FE_BASE+0x0007) +/// error getting file size +#define FERR_GETSIZE (FE_BASE+0x0008) +/// serialization error +#define FERR_SERIALIZE (FE_BASE+0x0009) +/// trying to read the data beyond the index +#define FERR_MEMORY (FE_BASE+0x000a) +/// encryption/decryption error +#define FERR_CRYPT (FE_BASE+0x000b) +/// search error +#define FERR_SEARCH (FE_BASE+0x000c) +/// set/get attrib error +#define FERR_FINFO (FE_BASE+0x000d) +/// fast-move/rename error +#define FERR_MOVE (FE_BASE+0x000e) +/// Unicode strings not supported in this build of library +#define FERR_UNICODE (FE_BASE+0x000f) + +//////////////////////////////////////////////////////////////////// +// module-related +/// Base define for module related errors +#define PE_BASE 0x00000000 + +/// plugin found with the id equal to one of the loaded plugins +#define PE_DUPLICATEPLUG (PE_BASE+0x0000) +/// the module does not implement a mandatory function (or other words - cannot load an export from a module) +#define PE_CALLNOTIMPLEMENTED (PE_BASE+0x0001) +/// the search error +#define PE_SEARCHERROR (PE_BASE+0x0002) +/// Cannot load an external module +#define PE_CANNOTLOAD (PE_BASE+0x0003) +/// Cannot unload the external module +#define PE_CANNOTUNLOAD (PE_BASE+0x0004) +/// Module not found +#define PE_NOTFOUND (PE_BASE+0x0005) + +///////////////////////////////////////////////////////////////////// +// encryption related + +/// Base define for encryption related error codes +#define EE_BASE 0x00020000 + +/// Initialization of the cipher failed +#define EE_INIT (EE_BASE+0x0000) +/// Encryption failed +#define EE_CRYPT (EE_BASE+0x0001) +/// Decryption failed +#define EE_DECRYPT (EE_BASE+0x0002) + +///////////////////////////////////////////////////////////////////// +// conversion related +/// Base define for conversion errors +#define CE_BASE 0x00030000 +/// Error in converting a hex string to the binary data +#define CE_HEX2BIN (CE_BASE+0x0000) + +//////////////////////////////////////////////////////////////////// +// general +#define GE_BASE 0x00040000 +/// Invalid argument passed to the function +#define GE_INVALIDARG (GE_BASE + 0x0000) + +#endif Index: ext/libicpf/src/libicpf/err_codes.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/err_codes.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/err_codes.h (revision 0) @@ -1,104 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __ERR_CODES_H__ -#define __ERR_CODES_H__ - -//////////////////////////////////////////////////////////////// -// file related -/// Base define for file related errors -#define FE_BASE 0x00010000 - -/// Unknown error -#define FERR_UNKNOWN (FE_BASE+0x0000) -/// Error while opening file -#define FERR_OPEN (FE_BASE+0x0001) -/// Error while closing file -#define FERR_CLOSE (FE_BASE+0x0002) -/// Error reading data from file -#define FERR_READ (FE_BASE+0x0003) -/// Error writing data to a file -#define FERR_WRITE (FE_BASE+0x0004) -/// Error setting file pointer position -#define FERR_SEEK (FE_BASE+0x0005) -/// eof encountered - currently unused -#define FERR_EOF (FE_BASE+0x0006) -/// error while setting an eof in file -#define FERR_SETEOF (FE_BASE+0x0007) -/// error getting file size -#define FERR_GETSIZE (FE_BASE+0x0008) -/// serialization error -#define FERR_SERIALIZE (FE_BASE+0x0009) -/// trying to read the data beyond the index -#define FERR_MEMORY (FE_BASE+0x000a) -/// encryption/decryption error -#define FERR_CRYPT (FE_BASE+0x000b) -/// search error -#define FERR_SEARCH (FE_BASE+0x000c) -/// set/get attrib error -#define FERR_FINFO (FE_BASE+0x000d) -/// fast-move/rename error -#define FERR_MOVE (FE_BASE+0x000e) -/// Unicode strings not supported in this build of library -#define FERR_UNICODE (FE_BASE+0x000f) - -//////////////////////////////////////////////////////////////////// -// module-related -/// Base define for module related errors -#define PE_BASE 0x00000000 - -/// plugin found with the id equal to one of the loaded plugins -#define PE_DUPLICATEPLUG (PE_BASE+0x0000) -/// the module does not implement a mandatory function (or other words - cannot load an export from a module) -#define PE_CALLNOTIMPLEMENTED (PE_BASE+0x0001) -/// the search error -#define PE_SEARCHERROR (PE_BASE+0x0002) -/// Cannot load an external module -#define PE_CANNOTLOAD (PE_BASE+0x0003) -/// Cannot unload the external module -#define PE_CANNOTUNLOAD (PE_BASE+0x0004) -/// Module not found -#define PE_NOTFOUND (PE_BASE+0x0005) - -///////////////////////////////////////////////////////////////////// -// encryption related - -/// Base define for encryption related error codes -#define EE_BASE 0x00020000 - -/// Initialization of the cipher failed -#define EE_INIT (EE_BASE+0x0000) -/// Encryption failed -#define EE_CRYPT (EE_BASE+0x0001) -/// Decryption failed -#define EE_DECRYPT (EE_BASE+0x0002) - -///////////////////////////////////////////////////////////////////// -// conversion related -/// Base define for conversion errors -#define CE_BASE 0x00030000 -/// Error in converting a hex string to the binary data -#define CE_HEX2BIN (CE_BASE+0x0000) - -//////////////////////////////////////////////////////////////////// -// general -#define GE_BASE 0x00040000 -/// Invalid argument passed to the function -#define GE_INVALIDARG (GE_BASE + 0x0000) - -#endif Index: src/libicpf/exception.cpp =================================================================== diff -u -N --- src/libicpf/exception.cpp (revision 0) +++ src/libicpf/exception.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,213 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file exception.cpp + * \brief Contain an implementation of an exception handling class. + */ +#include "exception.h" +#include +#include + +BEGIN_ICPF_NAMESPACE + +/// Defines max length of the exception description +#define MAX_EXCEPTION 4096 + +/** Constructor that takes the const description. The description (along with other tchar_t* parameters) + * are copied to the internal members (so there is some memory allocation). + * + * \param[in] pszDesc - exception description (currently should be in english) + * \param[in] pszFilename - source file name from which the exception is thrown + * \param[in] pszFunction - function name from which the exception is thrown + * \param[in] uiLine - line in the source file from which the exception is thrown + * \param[in] uiAppCode - application defined error code + * \param[in] uiSystemCode - system error code (platform dependent) + * \param[in] uiReserved - currently unused; must be 0 + */ +exception::exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : + std::exception(), + m_pszDesc(NULL), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(uiLine), + m_uiAppCode(uiAppCode), + m_uiSystemCode(uiSystemCode), + m_uiReserved(uiReserved) +{ + set_string(&m_pszDesc, pszDesc); + set_string(&m_pszFilename, pszFilename); + set_string(&m_pszFunction, pszFunction); +#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) + tchar_t szInfo[MAX_EXCEPTION]; + OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); +#endif +} + +/** Constructor that takes the ptr to a buffer as a description. The pointer to a buffer is + * stored in the internal member and will be deleted in the destructor. Other tchar_t* parameters + * are copied to the internal members (so there is some memory allocated). + * + * \param[in] pszDesc - ptr to exception description (currently should be in english) allocated with new operator + * \param[in] pszFilename - source file name from which the exception is thrown + * \param[in] pszFunction - function name from which the exception is thrown + * \param[in] uiLine - line in the source file from which the exception is thrown + * \param[in] uiAppCode - application defined error code + * \param[in] uiSystemCode - system error code (platform dependent) + * \param[in] uiReserved - currently unused; must be 0 + */ +exception::exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : + std::exception(), + m_pszDesc(pszDesc), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(uiLine), + m_uiAppCode(uiAppCode), + m_uiSystemCode(uiSystemCode), + m_uiReserved(uiReserved) +{ + set_string(&m_pszFilename, pszFilename); + set_string(&m_pszFunction, pszFunction); +#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) + tchar_t szInfo[MAX_EXCEPTION]; + OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); +#endif +} + +/** Copy constructor for the exception class. + * + * \param[in] rSrc - source exception to copy data from + */ +exception::exception(const exception& rSrc) : + std::exception(rSrc), + m_pszDesc(NULL), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(rSrc.m_uiLine), + m_uiAppCode(rSrc.m_uiAppCode), + m_uiSystemCode(rSrc.m_uiSystemCode), + m_uiReserved(rSrc.m_uiReserved) +{ + set_string(&m_pszDesc, rSrc.m_pszDesc); + set_string(&m_pszFilename, rSrc.m_pszFilename); + set_string(&m_pszFunction, rSrc.m_pszFunction); +} + +/** Destructor deletes all the allocated memory for the exception object + */ +exception::~exception() +{ + delete [] m_pszDesc; + delete [] m_pszFilename; + delete [] m_pszFunction; +} + +/** Assigns another exception data to this object. + * + * \param[in] e - source exception to copy from. + * \return Reference to this object. + */ +exception& exception::operator=(const exception& eSrc) +{ + if (this != &eSrc) + { + delete [] m_pszDesc; + delete [] m_pszFilename; + delete [] m_pszFunction; + + set_string(&m_pszDesc, eSrc.m_pszDesc); + set_string(&m_pszFilename, eSrc.m_pszFilename); + set_string(&m_pszFunction, eSrc.m_pszFunction); + m_uiLine=eSrc.m_uiLine; + m_uiAppCode=eSrc.m_uiAppCode; + m_uiSystemCode=eSrc.m_uiSystemCode; + m_uiReserved=eSrc.m_uiReserved; + } + + return *this; +} + +/** Function retrieves the full information about the exception into + * the string buffer specified by user. + * \param[out] pszInfo - buffer fot the full exception description + * \param[in] tMaxLen - size of the specified buffer + * \return Pointer to the exception description (to the pszInfo to be specific) + */ +const tchar_t* exception::get_info(tchar_t* pszInfo, size_t stMaxLen) +{ + _sntprintf(pszInfo, stMaxLen, _t("description: ") TSTRFMT _t("\nfile: ") TSTRFMT _t("\nfunction: ") TSTRFMT _t("\nline: ") ULFMT _t("\napp code: ") ULFMT _t("\nsys code: ") ULFMT _t("\nreserved: ") ULFMT _t("\n"), + m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); + pszInfo[stMaxLen-1]=_t('\0'); + + return pszInfo; +} + +/** Function logs the full information about an exception to the specified log file. + * \param[in] pszDesc - additional description of the exception object + * \param[in] plog - pointer to a log file to log the exception to + */ +void exception::log(const tchar_t* pszDesc, log_file* plog) +{ + plog->logev(TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), + pszDesc, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); +} + +/** Function logs the full information about an exception to the specified log file. + * Function takes two additional descriptions - will be logged as separated by space one description. + * \param[in] pszDesc - additional description of the exception object + * \param[in] pszDesc2 - the second part of an additional description + * \param[in] plog - pointer to a log file to log the exception to + */ +void exception::log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog) +{ + plog->logev(TSTRFMT _t(" ") TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), + pszDesc, pszDesc2, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); +} + +/** Exception's description formatting routine. Acts just as normal sprintf + * function, but allocates a buffer for the output result and returns a pointer + * to it. Used for formatting the exception description - usage: + * THROW(exception::format(_t("test ") TSTRFMT , _t("abc")), ...). + * It will enforce compiler to use the second constructor (non-const description). + * And the allocated buffer (result of this func) will be freed. + * \param[in] pszFormat - format string followed by some additional data (as in printf) + * \return Pointer to the newly allocated buffer with formatted output. + */ +tchar_t* exception::format(const tchar_t* pszFormat, ...) +{ + va_list vl; + va_start(vl, pszFormat); + + // alloc some space - no more than MAX_EXCEPTION chracters + tchar_t* psz=new tchar_t[(size_t)MAX_EXCEPTION]; + _vsntprintf(psz, (size_t)MAX_EXCEPTION, pszFormat, vl); + psz[MAX_EXCEPTION-1]=_t('\0'); + return psz; +} + +/** Allocates a string buffer and makes a copy of an input data. Used to + * make a copy of the constructor string parameteres. + * \param[out] pszOut - pointer to tchar_t* which will receive the new buffer address + * \param[in] pszIn - string to make a copy of + */ +void exception::set_string(tchar_t** pszOut, const tchar_t* pszIn) const +{ + *pszOut=new tchar_t[_tcslen(pszIn)+(uint_t)1]; + _tcscpy(*pszOut, pszIn); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/exception.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/exception.cpp (revision 0185dd929933bee0f578d6ca52aaa605a48c9f89) +++ ext/libicpf/src/libicpf/exception.cpp (revision 0) @@ -1,213 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file exception.cpp - * \brief Contain an implementation of an exception handling class. - */ -#include "exception.h" -#include -#include - -BEGIN_ICPF_NAMESPACE - -/// Defines max length of the exception description -#define MAX_EXCEPTION 4096 - -/** Constructor that takes the const description. The description (along with other tchar_t* parameters) - * are copied to the internal members (so there is some memory allocation). - * - * \param[in] pszDesc - exception description (currently should be in english) - * \param[in] pszFilename - source file name from which the exception is thrown - * \param[in] pszFunction - function name from which the exception is thrown - * \param[in] uiLine - line in the source file from which the exception is thrown - * \param[in] uiAppCode - application defined error code - * \param[in] uiSystemCode - system error code (platform dependent) - * \param[in] uiReserved - currently unused; must be 0 - */ -exception::exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : - std::exception(), - m_pszDesc(NULL), - m_pszFilename(NULL), - m_pszFunction(NULL), - m_uiLine(uiLine), - m_uiAppCode(uiAppCode), - m_uiSystemCode(uiSystemCode), - m_uiReserved(uiReserved) -{ - set_string(&m_pszDesc, pszDesc); - set_string(&m_pszFilename, pszFilename); - set_string(&m_pszFunction, pszFunction); -#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) - tchar_t szInfo[MAX_EXCEPTION]; - OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); -#endif -} - -/** Constructor that takes the ptr to a buffer as a description. The pointer to a buffer is - * stored in the internal member and will be deleted in the destructor. Other tchar_t* parameters - * are copied to the internal members (so there is some memory allocated). - * - * \param[in] pszDesc - ptr to exception description (currently should be in english) allocated with new operator - * \param[in] pszFilename - source file name from which the exception is thrown - * \param[in] pszFunction - function name from which the exception is thrown - * \param[in] uiLine - line in the source file from which the exception is thrown - * \param[in] uiAppCode - application defined error code - * \param[in] uiSystemCode - system error code (platform dependent) - * \param[in] uiReserved - currently unused; must be 0 - */ -exception::exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved) : - std::exception(), - m_pszDesc(pszDesc), - m_pszFilename(NULL), - m_pszFunction(NULL), - m_uiLine(uiLine), - m_uiAppCode(uiAppCode), - m_uiSystemCode(uiSystemCode), - m_uiReserved(uiReserved) -{ - set_string(&m_pszFilename, pszFilename); - set_string(&m_pszFunction, pszFunction); -#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) - tchar_t szInfo[MAX_EXCEPTION]; - OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); -#endif -} - -/** Copy constructor for the exception class. - * - * \param[in] rSrc - source exception to copy data from - */ -exception::exception(const exception& rSrc) : - std::exception(rSrc), - m_pszDesc(NULL), - m_pszFilename(NULL), - m_pszFunction(NULL), - m_uiLine(rSrc.m_uiLine), - m_uiAppCode(rSrc.m_uiAppCode), - m_uiSystemCode(rSrc.m_uiSystemCode), - m_uiReserved(rSrc.m_uiReserved) -{ - set_string(&m_pszDesc, rSrc.m_pszDesc); - set_string(&m_pszFilename, rSrc.m_pszFilename); - set_string(&m_pszFunction, rSrc.m_pszFunction); -} - -/** Destructor deletes all the allocated memory for the exception object - */ -exception::~exception() -{ - delete [] m_pszDesc; - delete [] m_pszFilename; - delete [] m_pszFunction; -} - -/** Assigns another exception data to this object. - * - * \param[in] e - source exception to copy from. - * \return Reference to this object. - */ -exception& exception::operator=(const exception& eSrc) -{ - if (this != &eSrc) - { - delete [] m_pszDesc; - delete [] m_pszFilename; - delete [] m_pszFunction; - - set_string(&m_pszDesc, eSrc.m_pszDesc); - set_string(&m_pszFilename, eSrc.m_pszFilename); - set_string(&m_pszFunction, eSrc.m_pszFunction); - m_uiLine=eSrc.m_uiLine; - m_uiAppCode=eSrc.m_uiAppCode; - m_uiSystemCode=eSrc.m_uiSystemCode; - m_uiReserved=eSrc.m_uiReserved; - } - - return *this; -} - -/** Function retrieves the full information about the exception into - * the string buffer specified by user. - * \param[out] pszInfo - buffer fot the full exception description - * \param[in] tMaxLen - size of the specified buffer - * \return Pointer to the exception description (to the pszInfo to be specific) - */ -const tchar_t* exception::get_info(tchar_t* pszInfo, size_t stMaxLen) -{ - _sntprintf(pszInfo, stMaxLen, _t("description: ") TSTRFMT _t("\nfile: ") TSTRFMT _t("\nfunction: ") TSTRFMT _t("\nline: ") ULFMT _t("\napp code: ") ULFMT _t("\nsys code: ") ULFMT _t("\nreserved: ") ULFMT _t("\n"), - m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); - pszInfo[stMaxLen-1]=_t('\0'); - - return pszInfo; -} - -/** Function logs the full information about an exception to the specified log file. - * \param[in] pszDesc - additional description of the exception object - * \param[in] plog - pointer to a log file to log the exception to - */ -void exception::log(const tchar_t* pszDesc, log_file* plog) -{ - plog->logev(TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), - pszDesc, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); -} - -/** Function logs the full information about an exception to the specified log file. - * Function takes two additional descriptions - will be logged as separated by space one description. - * \param[in] pszDesc - additional description of the exception object - * \param[in] pszDesc2 - the second part of an additional description - * \param[in] plog - pointer to a log file to log the exception to - */ -void exception::log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog) -{ - plog->logev(TSTRFMT _t(" ") TSTRFMT _t("\n\tdesc: ") TSTRFMT _t("\n\tfile: ") TSTRFMT _t("\n\tfunc: ") TSTRFMT _t("\n\tline: ") ULFMT _t("\n\tapp code: ") ULFMT _t("\n\tsys code: ") ULFMT _t("\n\treserved: ") ULFMT _t("\n"), - pszDesc, pszDesc2, m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); -} - -/** Exception's description formatting routine. Acts just as normal sprintf - * function, but allocates a buffer for the output result and returns a pointer - * to it. Used for formatting the exception description - usage: - * THROW(exception::format(_t("test ") TSTRFMT , _t("abc")), ...). - * It will enforce compiler to use the second constructor (non-const description). - * And the allocated buffer (result of this func) will be freed. - * \param[in] pszFormat - format string followed by some additional data (as in printf) - * \return Pointer to the newly allocated buffer with formatted output. - */ -tchar_t* exception::format(const tchar_t* pszFormat, ...) -{ - va_list vl; - va_start(vl, pszFormat); - - // alloc some space - no more than MAX_EXCEPTION chracters - tchar_t* psz=new tchar_t[(size_t)MAX_EXCEPTION]; - _vsntprintf(psz, (size_t)MAX_EXCEPTION, pszFormat, vl); - psz[MAX_EXCEPTION-1]=_t('\0'); - return psz; -} - -/** Allocates a string buffer and makes a copy of an input data. Used to - * make a copy of the constructor string parameteres. - * \param[out] pszOut - pointer to tchar_t* which will receive the new buffer address - * \param[in] pszIn - string to make a copy of - */ -void exception::set_string(tchar_t** pszOut, const tchar_t* pszIn) const -{ - *pszOut=new tchar_t[_tcslen(pszIn)+(uint_t)1]; - _tcscpy(*pszOut, pszIn); -} - -END_ICPF_NAMESPACE Index: src/libicpf/exception.h =================================================================== diff -u -N --- src/libicpf/exception.h (revision 0) +++ src/libicpf/exception.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,110 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file exception.h + * \brief Contain an exception handling class. + */ + +#ifndef __EXCEPTION_H__ +#define __EXCEPTION_H__ + +#include "log.h" +#include "libicpf.h" +#include "gen_types.h" + +#undef THROW +/** \brief Macro used for throwing an exception the easy way. + * + * Macro throws an exception specified by the parameters. Other params needed by + * the exception class are taken indirectly from the position of a macro in the + * source file. + * \param[in] desc - error description; if any formatting should be used use exception::format() function + * \param[in] app_code - application error code (definitions are in engine_defs.h) + * \param[in] sys_code - system error code (platform specific) + * \param[in] reserved_code - currently unused; must be 0 + */ +#define THROW(desc,app_code,sys_code,reserved_code) throw icpf::exception(desc, _t(__FILE__), _t(__FUNCTION__), __LINE__, app_code, sys_code, reserved_code) +/// Logs an exception in a log file +#define LOG_EXCEPTION(except, ptr_log) (except)->log(_t("Caught an exception in "), _t(__FUNCTION__), ptr_log) +/// Logs an unknown exception in a log file +#define LOG_UEXCEPTION(ptr_log) (ptr_log)->loge(_t("Caught an unknown exception in ") TSTRFMT, _t(__FUNCTION__)) + +BEGIN_ICPF_NAMESPACE + +/** \brief Exception class used by most of the engine. + * + * Exception class thrown by most of the engine functions. Provides user + * with an additional formatting and outputting capabilities. + */ +#pragma warning(push) +#pragma warning(disable: 4275) +class LIBICPF_API exception : public virtual std::exception +{ +public: +/** \name Construction/destruction */ +/**@{*/ + /// Standard constructor that takes the const description + exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); + /// Standard constructor that takes non-const ptr to a buffer as the description + exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); + /// Copy constructor + exception(const exception& rSrc); + /// Standard destructor + ~exception(); + + /// Assignment operator + exception& operator=(const exception& eSrc); +/**@}*/ + +/** \name Outputting */ +/**@{*/ + const tchar_t* get_info(tchar_t* pszInfo, size_t stMaxLen); ///< Retrieves the exception information to a specified string buffer + const tchar_t* get_desc() const { return m_pszDesc; }; + const tchar_t* get_filename() const { return m_pszFilename; }; + const tchar_t* get_function() const { return m_pszFunction; }; + uint_t get_line() const { return m_uiLine; }; + uint_t get_appcode() const { return m_uiAppCode; }; + uint_t get_syscode() const { return m_uiSystemCode; }; + + void log(const tchar_t* pszDesc, log_file* plog); ///< Logs the exception information to the log file + void log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog); ///< Logs the exception to the log file with an additional description +/**@}*/ + +/** \name Formatting */ +/**@{*/ + static tchar_t* format(const tchar_t* pszFormat, ...); ///< Description formatting function +/**@}*/ + +protected: + void set_string(tchar_t** pszOut, const tchar_t* pszIn) const; ///< Makes a copy of an input string + +protected: + tchar_t* m_pszDesc; ///< Exception description + tchar_t* m_pszFilename; ///< Source file in which the exception has been thrown + tchar_t* m_pszFunction; ///< Function name in the source file in which the exception has been thrown + uint_t m_uiLine; ///< Line in the source file in which the exception has been thrown + uint_t m_uiAppCode; ///< Application error code + uint_t m_uiSystemCode; ///< System error code (platform dependent) + uint_t m_uiReserved; ///< Reserved code - currently unused and should be 0 +}; + +#pragma warning(pop) + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/exception.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/exception.h (revision d25e295cbabb9a85970a2ad5ec5de76bea1e404a) +++ ext/libicpf/src/libicpf/exception.h (revision 0) @@ -1,110 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file exception.h - * \brief Contain an exception handling class. - */ - -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ - -#include "log.h" -#include "libicpf.h" -#include "gen_types.h" - -#undef THROW -/** \brief Macro used for throwing an exception the easy way. - * - * Macro throws an exception specified by the parameters. Other params needed by - * the exception class are taken indirectly from the position of a macro in the - * source file. - * \param[in] desc - error description; if any formatting should be used use exception::format() function - * \param[in] app_code - application error code (definitions are in engine_defs.h) - * \param[in] sys_code - system error code (platform specific) - * \param[in] reserved_code - currently unused; must be 0 - */ -#define THROW(desc,app_code,sys_code,reserved_code) throw icpf::exception(desc, _t(__FILE__), _t(__FUNCTION__), __LINE__, app_code, sys_code, reserved_code) -/// Logs an exception in a log file -#define LOG_EXCEPTION(except, ptr_log) (except)->log(_t("Caught an exception in "), _t(__FUNCTION__), ptr_log) -/// Logs an unknown exception in a log file -#define LOG_UEXCEPTION(ptr_log) (ptr_log)->loge(_t("Caught an unknown exception in ") TSTRFMT, _t(__FUNCTION__)) - -BEGIN_ICPF_NAMESPACE - -/** \brief Exception class used by most of the engine. - * - * Exception class thrown by most of the engine functions. Provides user - * with an additional formatting and outputting capabilities. - */ -#pragma warning(push) -#pragma warning(disable: 4275) -class LIBICPF_API exception : public virtual std::exception -{ -public: -/** \name Construction/destruction */ -/**@{*/ - /// Standard constructor that takes the const description - exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); - /// Standard constructor that takes non-const ptr to a buffer as the description - exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); - /// Copy constructor - exception(const exception& rSrc); - /// Standard destructor - ~exception(); - - /// Assignment operator - exception& operator=(const exception& eSrc); -/**@}*/ - -/** \name Outputting */ -/**@{*/ - const tchar_t* get_info(tchar_t* pszInfo, size_t stMaxLen); ///< Retrieves the exception information to a specified string buffer - const tchar_t* get_desc() const { return m_pszDesc; }; - const tchar_t* get_filename() const { return m_pszFilename; }; - const tchar_t* get_function() const { return m_pszFunction; }; - uint_t get_line() const { return m_uiLine; }; - uint_t get_appcode() const { return m_uiAppCode; }; - uint_t get_syscode() const { return m_uiSystemCode; }; - - void log(const tchar_t* pszDesc, log_file* plog); ///< Logs the exception information to the log file - void log(const tchar_t* pszDesc, const tchar_t* pszDesc2, log_file* plog); ///< Logs the exception to the log file with an additional description -/**@}*/ - -/** \name Formatting */ -/**@{*/ - static tchar_t* format(const tchar_t* pszFormat, ...); ///< Description formatting function -/**@}*/ - -protected: - void set_string(tchar_t** pszOut, const tchar_t* pszIn) const; ///< Makes a copy of an input string - -protected: - tchar_t* m_pszDesc; ///< Exception description - tchar_t* m_pszFilename; ///< Source file in which the exception has been thrown - tchar_t* m_pszFunction; ///< Function name in the source file in which the exception has been thrown - uint_t m_uiLine; ///< Line in the source file in which the exception has been thrown - uint_t m_uiAppCode; ///< Application error code - uint_t m_uiSystemCode; ///< System error code (platform dependent) - uint_t m_uiReserved; ///< Reserved code - currently unused and should be 0 -}; - -#pragma warning(pop) - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/file.cpp =================================================================== diff -u -N --- src/libicpf/file.cpp (revision 0) +++ src/libicpf/file.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,977 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file file.cpp + * \brief Contains file/serializer class */ + +#include "file.h" +#include "crc32.h" +#include +#include "macros.h" +#include "err_codes.h" + +#ifndef _WIN32 + #include + #include + #include + #include +#endif + +BEGIN_ICPF_NAMESPACE + +#include + +/// Serialization buffer increment value +#define SERIALBUFFER_DELTA 4096UL + +// for making life easier +#ifdef _WIN32 + /// Macro representing the current value of last encountered error + #define CURRENT_LAST_ERROR GetLastError() + /// Null value for a file handle - platform compatibility helper + #define FNULL NULL +#else + /// Windoze compatibility macro - value returned from erroneous call to ::open() system call + #define INVALID_HANDLE_VALUE -1 + /// Macro representing the current value of last encountered error + #define CURRENT_LAST_ERROR errno + /// Null value for a file handle - platform compatibility helper + #define FNULL 0 +#endif + + +/** Standard constructor - nullifies all member variables. + */ +file::file() : + m_hFile(FNULL), + m_pszPath(NULL), + m_uiFlags(0), + m_bLastOperation(false), + m_bBuffered(false), + m_uiBufferSize(0), + m_pbyBuffer(NULL), + m_uiCurrentPos(0), + m_uiDataCount(0), + m_bRememberedState(false), + m_bSerializing(0), + m_pbySerialBuffer(NULL), + m_uiSerialBufferSize(0), + m_uiSerialBufferPos(0), + m_uiDataBlockFlags(BF_NONE) +{ +} + +/** Standard destructor - tries to close a file, but catches any exception thrown + * and does not throw it again. + */ +file::~file() +{ + // close all the stuff, but make sure no exception is thrown + try + { + close(); + } + catch(exception&) + { + } +} + +/** Opens a filesystem object (a file) with a given flags and (if needed) with + * some buffer size used in internal buffering. In case of error throws an icpf::exception + * with the error description. + * \param[in] pszPath - path to a file to open + * \param[in] uiFlags - flags that determine the type of access to a file (FA_*) + * \param[in] uiBufSize - buffer size that will be used for internal buffering (if enabled) + */ +void file::open(const tchar_t* pszPath, uint_t uiFlags, uint_t uiBufSize) +{ + // check if this object is ready to open a file + if (m_hFile) + close(); + + // check for the flags completion +#ifdef _WIN32 + uint_t mode=0, flags=OPEN_EXISTING; +#else + int_t mode=0; +#endif + + // read flag + if (uiFlags & FA_READ) +#ifdef _WIN32 + mode |= GENERIC_READ; +#else + mode |= O_RDONLY; +#endif + + // write flag + if (uiFlags & FA_WRITE) +#ifdef _WIN32 + mode |= GENERIC_WRITE; +#else + mode |= O_WRONLY; +#endif + + // creation flag + if (uiFlags & FA_CREATE) +#ifdef _WIN32 + { + if (uiFlags & FA_TRUNCATE) + flags = CREATE_ALWAYS; + else + flags = OPEN_ALWAYS; + } +#else + mode |= O_CREAT; +#endif + + // truncation + if (uiFlags & FA_TRUNCATE) +#ifdef _WIN32 + { + if (!(uiFlags & FA_CREATE)) + flags = TRUNCATE_EXISTING; + } +#else + mode |= O_TRUNC; +#endif + + // make a system call +#ifdef _WIN32 + m_hFile=::CreateFile(pszPath, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, flags, FILE_ATTRIBUTE_NORMAL, NULL); +#else + m_hFile=::open(pszPath, mode); +#endif + + if (m_hFile == INVALID_HANDLE_VALUE) + { + m_hFile=FNULL; + THROW(exception::format(_t("[file] Cannot open the file ") STRFMT _t(" with flags ") ULXFMT, pszPath, uiFlags), FERR_OPEN, CURRENT_LAST_ERROR, 0); + } + else + { + // remember the path of this file + m_pszPath=new tchar_t[_tcslen(pszPath)+1]; + _tcscpy(m_pszPath, pszPath); + + // remember the mode + m_uiFlags=uiFlags; + + // is this buffered ? + set_buffering((uiFlags & FA_BUFFERED) != 0, uiBufSize); + } +} + +/** Tries to save the data contained in internal buffer (if any) and frees all the + * resources used by this class. Can be used on closed files. In case of error the + * ch::exception is thrown. + */ +void file::close() +{ + // only if the file has been opened + if (m_hFile != FNULL) + { + // flush all data + flush(); + + // free strings and other data (at first, because of the destruction call) + delete [] m_pszPath; + m_pszPath=NULL; + delete [] m_pbyBuffer; + m_pbyBuffer=NULL; + + delete [] m_pbySerialBuffer; + m_pbySerialBuffer=NULL; + + m_uiFlags=0; + m_bLastOperation=false; + + m_bBuffered=false; + m_uiBufferSize=0; + m_uiCurrentPos=0; + m_uiDataCount=0; + + m_bSerializing=false; + m_uiSerialBufferSize=0; + m_uiSerialBufferPos=0; + m_uiDataBlockFlags=0; + + m_bRememberedState=false; + + // close the file +#ifdef _WIN32 + if (!::CloseHandle(m_hFile)) +#else + if (::close(m_hFile) == -1) +#endif + THROW(exception::format(_t("[file] Cannot close the handle associated with a file ") STRFMT, m_pszPath), FERR_CLOSE, CURRENT_LAST_ERROR, 0); + else + m_hFile=FNULL; + } +} + +/** Does anything only if the file is opened, the operation is being buffered and the data + * count contained in the internal buffer is >0. If the last operation performed was + * storing data then the function tries to store a packet of data to the file. If the data + * has been read lately then only the file pointer will be repositioned. Also the internal buffer + * will be made empty. Function can throw an ch::exception in case of error. + */ +void file::flush() +{ + if (m_hFile && m_bBuffered && m_uiDataCount > 0) + { + if (m_bLastOperation) + { + // last operation - storing data + _write_packet(); + } + else + { + // last - reading data + // set file pointer to position current-(m_uiDataCount-m_uiCurrentPos) + _seek(-(longlong_t)(m_uiDataCount-m_uiCurrentPos), FS_CURRENT); + m_uiCurrentPos=0; + m_uiDataCount=0; + } + } +} + +/** Tries to read a specified count of bytes from a file to the specified buffer. + * If the is currently in buffered state the reading is being done with internal + * buffering. It could be helpful when reading small amounts of data. + * \param[out] pBuffer - ptr to a buffer that is about to receive data + * \param[in] iSize - count of bytes to read + * \return Count of bytes that has been read (could be less than iSize) + */ +ulong_t file::read(ptr_t pBuffer, ulong_t ulSize) +{ + assert(m_hFile); // forgot to open the file ? + + // flush if needed + if (m_bLastOperation) + { + flush(); + m_bLastOperation=false; + } + + if (!m_bBuffered) + { + // unbuffered operation (read what is needed) +#ifdef _WIN32 + DWORD rd=0; + if (!ReadFile(m_hFile, pBuffer, ulSize, &rd, NULL)) +#else + int_t rd=0; + if ((rd=::read(m_hFile, pBuffer, ulSize)) < 0) +#endif + THROW(exception::format(_t("Cannot read data from file ") STRFMT, m_pszPath), FERR_READ, CURRENT_LAST_ERROR, 0); + + return rd; // if 0 - eof (not treated as exception) + } + else + { + // reads must be done by packets + uint_t uiCurrPos=0; // position in external buffer + while (uiCurrPos < ulSize) + { + // are there any data left ? + if (m_uiDataCount == 0 || m_uiCurrentPos == m_uiDataCount) + { + if (_read_packet() == 0) + return uiCurrPos; // return what was read 'til now + } + + // copy data into external buffer + uint_t uiCount=minval(m_uiDataCount-m_uiCurrentPos, ulSize-uiCurrPos); + memcpy(((byte_t*)pBuffer)+uiCurrPos, m_pbyBuffer+m_uiCurrentPos, uiCount); + + // update positions + uiCurrPos+=uiCount; + m_uiCurrentPos+=uiCount; + } + + return uiCurrPos; + } +} + +/** Tries to write a specified amount of data from a buffer to a file. If the buffered + * operations are enabled then this operation could store data in the internal buffer + * instead of a file. + * \param[in] pBuffer - ptr to a buffer with data to store + * \param[in] iSize - count of data to store + * \return Count of data that has been stored + */ +ulong_t file::write(ptr_t pBuffer, ulong_t ulSize) +{ + assert(m_hFile); + + if (!m_bLastOperation) + { + flush(); + m_bLastOperation=true; + } + + if (!m_bBuffered) + { + // standard write +#ifdef _WIN32 + DWORD wr=0; + if (!WriteFile(m_hFile, pBuffer, ulSize, &wr, NULL)) +#else + int_t wr; + if ((wr=::write(m_hFile, pBuffer, ulSize) == -1)) +#endif + THROW(exception::format(_t("[file] Cannot write data to a file"), m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); + + return (ulong_t)wr; + } + else + { + uint_t uiPos=0; + + while (uiPos < ulSize) + { + // check if buffer need storing + if (m_uiCurrentPos == m_uiBufferSize) + _write_packet(); + + // now add to internal buffer some data + uint_t uiCount=minval(m_uiBufferSize-m_uiCurrentPos, ulSize-uiPos); + + memcpy(m_pbyBuffer+m_uiCurrentPos, ((byte_t*)pBuffer)+uiPos, uiCount); + + // update + m_uiCurrentPos+=uiCount; + m_uiDataCount+=uiCount; + uiPos+=uiCount; + } + + return uiPos; + } +} + +/** Tries to read a string from a file. Uses a buffering to achieve it. If the + * current file mode is unbuffered then this function enables buffering, makes + * requested operation and disables buffering. If the buffer is too small to + * contain all the line read then the rest of line is lost. + * \param[out] pszStr - ptr to a buffer to receive a string + * \param[in] uiMaxLen - size of the string buffer + * \return If the line has been succesfully read. + */ +bool file::read_line(tchar_t* pszStr, uint_t uiMaxLen) +{ + // for unbuffered operations enable buffering for this op + if (m_bBuffered) + return _read_string(pszStr, uiMaxLen); + else + { + uint_t uiSize=m_uiBufferSize; + set_buffering(true, 4096); + + bool bRet=_read_string(pszStr, uiMaxLen); + + set_buffering(false, uiSize); + return bRet; + } +} + +/** Tries to write some text into a file. Function allocates a buffer for the string + * copy and appends a \\r\\n to this text. + * \param[in] pszString - string to store + */ +void file::write_line(tchar_t* pszString) +{ + assert(m_hFile); + + if (!m_bLastOperation) + { + flush(); + m_bLastOperation=true; + } + + // make new string with \r\n at the end - cannot use old buffer - unknown size + // NOTE: \r\n added for windoze compat; when reading file function properly handles unix style line endings + uint_t uiLen=(uint_t)_tcslen(pszString); + + tchar_t *pszData=new tchar_t[uiLen+3]; + _tcscpy(pszData, pszString); + pszData[uiLen]=_t('\r'); + pszData[uiLen+1]=_t('\n'); + pszData[uiLen+2]=_t('\0'); + + try + { + if (m_bBuffered) + { + uint_t uiStrPos=0; // current index in pszString + uint_t uiMin=0; // helper + uint_t uiSize=uiLen+2; + + // processing whole string + while (uiStrPos < uiSize) + { + if (m_uiCurrentPos == m_uiBufferSize) + _write_packet(); + + // count of chars to be copied + uiMin=minval(uiSize-uiStrPos, m_uiBufferSize-m_uiCurrentPos); + + // copy data from pszString into internal buffer (maybe part of it) + memcpy(m_pbyBuffer+m_uiCurrentPos, pszData+uiStrPos, uiMin); + + // move offsets + m_uiCurrentPos+=uiMin; + m_uiDataCount+=uiMin; + uiStrPos+=uiMin; + } + } + else + { + // standard write +#ifdef _WIN32 + DWORD wr=0; + if (!WriteFile(m_hFile, pszData, uiLen+2, &wr, NULL)) +#else + int_t wr; + if ((wr=::write(m_hFile, pszData, uiLen+2)) == -1) +#endif + THROW(exception::format(_t("Cannot write data to a file ") STRFMT, m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); + } + } + catch(...) + { + delete [] pszData; + throw; + } + + delete [] pszData; +} + +/** Moves the file pointer to some place in the file. If the file is in buffered + * state, then the data is flushed and then the real seek takes place. + * \param[in] llOffset - offset of the new file pointer position + * \param[in] uiFrom - specifies the relative point (FS_*) from which the llOffset will be counted + */ +void file::seek(longlong_t llOffset, uint_t uiFrom) +{ + // flush buffer + flush(); + + // seek + _seek(llOffset, uiFrom); +} + +/** Retrieves the current file pointer position (corrected by the content of + * internal buffer if buffered mode enabled). + * \return Current file position. + */ +longlong_t file::getpos() +{ + // return corrected by internal members current file position + return _seek(0, FS_CURRENT)-m_uiDataCount+m_uiCurrentPos; +} + +/** Tries to set end-of-file marker on the current file pointer position. The internal buffer + * is flushed before truncating (or extending). + */ +void file::seteof() +{ + assert(m_hFile); + + // flush da buffers + flush(); + + // now set the end of file +#ifdef _WIN32 + if (!::SetEndOfFile(m_hFile)) +#else + if (::ftruncate(m_hFile, getpos()) == -1) +#endif + THROW(exception::format(_t("[file] Cannot truncate the file ") STRFMT, m_pszPath), FERR_SETEOF, CURRENT_LAST_ERROR, 0); +} + +/** Returns a size of the file. + * \return Size of the file. + */ +longlong_t file::get_size() +{ + flush(); + +#ifdef _WIN32 + ULARGE_INTEGER li; + li.LowPart=GetFileSize(m_hFile, &li.HighPart); + if (li.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) +#else + // NOTE: a strange way to check the file size... + struct stat st; + if (fstat(m_hFile, &st) == -1) +#endif + THROW(exception::format(_t("[file] Cannot get the size of the file ") STRFMT, m_pszPath), FERR_GETSIZE, CURRENT_LAST_ERROR, 0); + +#ifdef _WIN32 + return li.QuadPart; +#else + return st.st_size; +#endif +} + +/** Changes the buffering state (or internal buffer length). The internal buffer + * is always flushed before making any changes. + * \param[in] bEnable - specifies if the buffering is about to be enabled + * \param[in] uiSize - the new size of the internal buffer + */ +void file::set_buffering(bool bEnable, uint_t uiSize) +{ + assert(uiSize > 0); // couldn't use 0-sized internal buffer + + // flush + flush(); + + // delete old buffer + if (m_bBuffered && (!bEnable || uiSize != m_uiBufferSize)) + { + delete [] m_pbyBuffer; + m_pbyBuffer=NULL; + } + + // alloc new buffer if needed + if (bEnable && (!m_bBuffered || uiSize != m_uiBufferSize)) + m_pbyBuffer=new byte_t[uiSize]; + + m_bBuffered=bEnable; + m_uiBufferSize=uiSize; +} + +/** Switches access mode to unbuffered one and remembers the last state. If already + * in unbuffered mode the function does nothing. + */ +void file::switch_unbuffered() +{ + if (!m_bBuffered) + return; // it's already unbuffered - leave it as is + else + { + m_bRememberedState=true; // mark that we change state to a different one + set_buffering(false, m_uiBufferSize); // do no change internal buffer size + } +} + +/** Switches access mode to buffered one and remembers the last state. If already + * in buffered mode the function does nothing. + */ +void file::switch_buffered() +{ + if (m_bBuffered) + return; // already buffered + else + { + m_bRememberedState=true; + set_buffering(true, m_uiBufferSize); + } +} + +/** Restores the buffered/unbuffered access mode if stored with switch_* functions. + */ +void file::restore_state() +{ + // restore state only if changed + if (m_bRememberedState) + { + set_buffering(!m_bBuffered, m_uiBufferSize); + m_bRememberedState=false; + } +} + +/** Begins the serialization data block. Each block can have it's + * own flags. Each block have to be ended with datablock_end before + * beginning another one. If the access is read then function tries to read + * the data block from a file and checks the crc checksums. If writing - only + * the buffer is allocated and initialized. + * Blocks cannot be nested. + * \param[in] uiFlags - block flags - look at BF_* macros + */ +void file::datablock_begin(uint_t uiFlags) +{ + // do not call begin data block within another data block + assert(!m_bSerializing && m_pbySerialBuffer == NULL); + + // alloc the new buffer and insert there a header (a few unsigned chars) + m_pbySerialBuffer=new byte_t[SERIALBUFFER_DELTA]; + m_uiSerialBufferSize=SERIALBUFFER_DELTA; + + // check flags + if ((m_uiFlags & FA_READ) && (m_uiFlags & FA_WRITE)) + THROW(exception::format(_t("[file] Tried to begin a data block with file ") STRFMT _t(" opened for both read and write."), m_pszPath), FERR_SERIALIZE, 0, 0); + + // action + if (m_uiFlags & FA_WRITE) + { + // reserve some space for a header + m_uiSerialBufferPos=sizeof(SERIALIZEINFOHEADER); + } + else + { + // we need to read the block from a file + if (read(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)) != sizeof(SERIALIZEINFOHEADER)) + { + _clear_serialization(); + THROW(exception::format(_t("[file] Cannot read the specified amount of data from a file (reading serialization header)."), m_pszPath), FERR_SERIALIZE, CURRENT_LAST_ERROR, 0); + } + + // move forward + m_uiSerialBufferPos=sizeof(SERIALIZEINFOHEADER); + + // determine the size of the remaining data in file + SERIALIZEINFOHEADER* psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + uint_t uiSize=(uint_t)(psih->iRealSize-sizeof(SERIALIZEINFOHEADER)); + + // check the header crc + uint_t uihc=crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(uint_t)); + if (uihc != psih->uiHeaderCRC32) + { + _clear_serialization(); + THROW(exception::format(_t("[file] Block contained in file ") STRFMT _t(" is corrupted. Header CRC check failed."), m_pszPath), FERR_SERIALIZE, 0, 0); + } + + // resize the buffer + _sbuf_resize((uint_t)psih->iRealSize); + + // refresh the psih + psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + + // read the remaining data + if (read(m_pbySerialBuffer+m_uiSerialBufferPos, uiSize) != (int_t)uiSize) + { + _clear_serialization(); + THROW(exception::format(_t("Cannot read specified amount of data from a file ") STRFMT _t(" (reading the after-header data)."), m_pszPath), FERR_SERIALIZE, CURRENT_LAST_ERROR, 0); + } + + // NOTE: do not update the position - we need ptr at the beginning of data + // now we are almost ready to retrieve data - only the crc check for the data + uint_t uiCRC=crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), psih->iDataSize-sizeof(SERIALIZEINFOHEADER)); + if (psih->uiCRC32 != uiCRC) + { + _clear_serialization(); + THROW(exception::format(_t("CRC check of the data read from file ") STRFMT _t(" failed."), m_pszPath), FERR_SERIALIZE, 0, 0); + } + } + + // make a mark + m_uiDataBlockFlags=uiFlags; + m_bSerializing=true; +} + +/** Ends the data block opened previously with datablock_begin. If the access is writing + * then the function updates the crc checksums in the buffer and tries to write the block + * of data to the file. If reading - only the serialization is cancelled. + */ +void file::datablock_end() +{ + // make sure everything is ok + assert(m_bSerializing && m_pbySerialBuffer != NULL); + if(!m_pbySerialBuffer) + THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); + + // check the operation type + if ((m_uiFlags & FA_READ) && (m_uiFlags & FA_WRITE)) + THROW(exception::format(_t("[file] Tried to end a data block with file ") STRFMT _t(" opened for both read and write."), m_pszPath), FERR_SERIALIZE, 0, 0); + + // when writing - make a header, ...; when reading - do nothing important + if (m_uiFlags & FA_WRITE) + { + // check if there is any data + if (m_uiSerialBufferPos == sizeof(SERIALIZEINFOHEADER)) + return; // no data has been serialized + + // fill the header (real data information) + SERIALIZEINFOHEADER *psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; + psih->iDataSize=m_uiSerialBufferPos; + psih->uiCRC32=crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_uiSerialBufferPos-sizeof(SERIALIZEINFOHEADER)); + + // the rest of header + psih->iRealSize=m_uiSerialBufferPos; + + // calc the header crc + psih->uiHeaderCRC32=crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(uint_t)); + + // write the buffer + write(m_pbySerialBuffer, psih->iRealSize); + } + + // remove all the traces of serializing + _clear_serialization(); +} + +/** Writes some bytes of data to a serialization buffer opened + * with the datablock_begin. Causes the class to reallocate an internal + * buffer(if needed) to make all the data fit into the buffer. + * NOTE: do not use too large data blocks because of the buffer reallocation. + * \param[in] pData - buffer address with some data + * \param[in] uiSize - count of bytes to write + */ +void file::swrite(ptr_t pData, uint_t uiSize) +{ + _sbuf_append(pData, uiSize); +} + +/** Reads some bytes of data from a serialization buffer opened by + * datablock_end call. + * \param[out] pData - buffer for the received data + * \param[in] uiSize - count of data to read; if user requests more data than available then an exception will be thrown + */ +void file::sread(ptr_t pData, uint_t uiSize) +{ + _sbuf_read(pData, uiSize); +} + +/** Cancels the serialization process and removes all the traces of data being serialized + * (it includes deleting the serialization buffer). + */ +void file::_clear_serialization() +{ + // remove all the traces of serializing + delete [] m_pbySerialBuffer; + m_pbySerialBuffer=NULL; + m_uiSerialBufferSize=0; + m_uiSerialBufferPos=0; + m_bSerializing=false; +} + +/** Used to read the next packet of data into the internal buffer (used for + * buffering). + * \return Count of bytes that has been read from a file. + */ +uint_t file::_read_packet() +{ + assert(m_hFile); + if(!m_hFile || !m_pbyBuffer) + THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); + + // read data +#ifdef _WIN32 + DWORD rd=0; + if (!ReadFile(m_hFile, m_pbyBuffer, m_uiBufferSize, &rd, NULL)) +#else + int_t rd; + if ((rd=::read(m_hFile, m_pbyBuffer, m_uiBufferSize)) == -1) +#endif + THROW(exception::format(_t("[file] Cannot read data from a file ") STRFMT _t("."), m_pszPath), FERR_READ, CURRENT_LAST_ERROR, 0); + + // reset internal members + m_uiDataCount=rd; + m_uiCurrentPos=0; + + return rd; +} + +/** Used to write the next packet of data from an internal buffer (buffering + * related) to a file. + * \return Count of bytes written. + */ +uint_t file::_write_packet() +{ + assert(m_hFile); + if(!m_hFile || !m_pbyBuffer) + THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); + +#ifdef _WIN32 + DWORD wr=0; + if (!WriteFile(m_hFile, m_pbyBuffer, m_uiDataCount, &wr, NULL)) +#else + int_t wr; + if ((wr=::write(m_hFile, m_pbyBuffer, m_uiDataCount)) == -1) +#endif + { + THROW(exception::format(_t("Cannot write data to a file ") STRFMT _t("."), m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); + } + + // reset internal members + m_uiDataCount=0; + m_uiCurrentPos=0; + + return wr; +} + +/** Reads some data from the internal serialization buffer. + * \param[out] pData - ptr to a buffer that is about to receive data + * \param[in] uiLen - count of data to be read + */ +void file::_sbuf_read(ptr_t pData, uint_t uiLen) +{ + // check if we are reading + assert(m_uiFlags & FA_READ); + + // check the ranges + if (m_uiSerialBufferPos+uiLen > m_uiSerialBufferSize) + { + // throw an exception - read beyond the data range in a given object + THROW(exception::format(_t("[file] Trying to read the serialization data beyond the range (file ") TSTRFMT _t(")."), m_pszPath), FERR_MEMORY, CURRENT_LAST_ERROR, 0); + } + + // read the data + memcpy(pData, m_pbySerialBuffer+m_uiSerialBufferPos, uiLen); + m_uiSerialBufferPos+=uiLen; +} + +/** Appends some bytes to the internal serialization buffer (data block). + * \param[in] pData - ptr to a data buffer + * \param[in] uiCount - count of data to store + */ +void file::_sbuf_append(ptr_t pData, uint_t uiCount) +{ + // check if we are writing + assert(m_uiFlags & FA_WRITE); + + // check serial buffer size (if there is enough room for the data) + if (m_uiSerialBufferPos+uiCount > m_uiSerialBufferSize) + { + // we need a buffer reallocation + uint_t uiDelta=((uiCount/SERIALBUFFER_DELTA)+1)*SERIALBUFFER_DELTA; + + // alloc the new buffer + _sbuf_resize(m_uiSerialBufferSize+uiDelta); + } + + assert(m_pbySerialBuffer); + if(!m_pbySerialBuffer) + THROW(_t("Invalid buffer."), 0, 0, 0); + // real storage of the data + if (uiCount > 0) + { + memcpy(m_pbySerialBuffer+m_uiSerialBufferPos, pData, uiCount); + m_uiSerialBufferPos+=uiCount; + } +} + +/** Resizes the internal serialization buffer to the new length. + * Also does copy the old data to the new buffer. + * \param[in] uiNewLen - new buffer length + */ +void file::_sbuf_resize(uint_t uiNewLen) +{ + // alloc the new buffer + byte_t* pbyNewBuffer=new byte_t[uiNewLen]; + + // copy the old data into the new one + uint_t uiCount=minval(m_uiSerialBufferPos, uiNewLen); + if (m_uiSerialBufferPos > 0) + memcpy(pbyNewBuffer, m_pbySerialBuffer, uiCount); + + // delete the old buffer + delete [] m_pbySerialBuffer; + + // set the new buffer inplace and update the internal size + m_pbySerialBuffer=pbyNewBuffer; + m_uiSerialBufferSize=uiNewLen; +} + + +/** Reads a line of text from text file - only for buffered operations. + * Properly interpretes the windoze and unix line endings. + * \param[out] pszStr - buffer for the string that is about to be read + * \param[in] uiMaxLen - size of the string buffer + * \return Bool value that states if the string has been read. + */ +bool file::_read_string(tchar_t* pszStr, uint_t uiMaxLen) +{ + assert(m_hFile); // file wasn_t('t opened - error opening or you')ve forgotten to do so ? + assert(m_pbyBuffer != NULL); + + // last time was writing - free buffer + if (m_bLastOperation) + { + flush(); + m_bLastOperation=false; + } + + // zero all the string + memset(pszStr, 0, uiMaxLen*sizeof(tchar_t)); + + // additional vars + uint_t uiStrPos=0; // current pos in external buffer + bool bSecondPass=false; // if there is need to check data for 0x0a tchar_t + + // copy each tchar_t into pszString + for (;;) + { + // if buffer is empty - fill it + if (m_uiDataCount == 0 || m_uiCurrentPos == m_uiDataCount) + { + if (_read_packet() == 0) + return _tcslen(pszStr) != 0; + } + + // skipping 0x0a in second pass + if (bSecondPass) + { + if (m_pbyBuffer[m_uiCurrentPos] == 0x0a) + m_uiCurrentPos++; + return true; + } + + // now process chars + while (m_uiCurrentPos < m_uiDataCount) + { + if (m_pbyBuffer[m_uiCurrentPos] == 0x0d) + { + bSecondPass=true; + m_uiCurrentPos++; + break; + } + else if (m_pbyBuffer[m_uiCurrentPos] == 0x0a) + { + m_uiCurrentPos++; + return true; + } + else + { + if (uiStrPos < uiMaxLen-1) + pszStr[uiStrPos++]=m_pbyBuffer[m_uiCurrentPos]; + m_uiCurrentPos++; + } + } + } +} + +/** Sets file pointer in a file. + * \param[in] llOffset - position to move the file pointer to + * \param[in] uiFrom - the relative position of a base position (FS_*) + * \return The new file pointer position. + */ +longlong_t file::_seek(longlong_t llOffset, uint_t uiFrom) +{ +#ifdef _WIN32 + LARGE_INTEGER li; + li.QuadPart = llOffset; + li.LowPart = SetFilePointer (m_hFile, li.LowPart, &li.HighPart, uiFrom); + + if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) +#else + int_t lRes; + if ((lRes=lseek(m_hFile, llOffset, uiFrom)) == -1) +#endif + THROW(exception::format(_t("Seek error in file ") STRFMT _t("."), m_pszPath), FERR_SEEK, CURRENT_LAST_ERROR, 0); + +#ifdef _WIN32 + return li.QuadPart; +#else + return lRes; +#endif +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/file.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/file.cpp (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/file.cpp (revision 0) @@ -1,977 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file file.cpp - * \brief Contains file/serializer class */ - -#include "file.h" -#include "crc32.h" -#include -#include "macros.h" -#include "err_codes.h" - -#ifndef _WIN32 - #include - #include - #include - #include -#endif - -BEGIN_ICPF_NAMESPACE - -#include - -/// Serialization buffer increment value -#define SERIALBUFFER_DELTA 4096UL - -// for making life easier -#ifdef _WIN32 - /// Macro representing the current value of last encountered error - #define CURRENT_LAST_ERROR GetLastError() - /// Null value for a file handle - platform compatibility helper - #define FNULL NULL -#else - /// Windoze compatibility macro - value returned from erroneous call to ::open() system call - #define INVALID_HANDLE_VALUE -1 - /// Macro representing the current value of last encountered error - #define CURRENT_LAST_ERROR errno - /// Null value for a file handle - platform compatibility helper - #define FNULL 0 -#endif - - -/** Standard constructor - nullifies all member variables. - */ -file::file() : - m_hFile(FNULL), - m_pszPath(NULL), - m_uiFlags(0), - m_bLastOperation(false), - m_bBuffered(false), - m_uiBufferSize(0), - m_pbyBuffer(NULL), - m_uiCurrentPos(0), - m_uiDataCount(0), - m_bRememberedState(false), - m_bSerializing(0), - m_pbySerialBuffer(NULL), - m_uiSerialBufferSize(0), - m_uiSerialBufferPos(0), - m_uiDataBlockFlags(BF_NONE) -{ -} - -/** Standard destructor - tries to close a file, but catches any exception thrown - * and does not throw it again. - */ -file::~file() -{ - // close all the stuff, but make sure no exception is thrown - try - { - close(); - } - catch(exception&) - { - } -} - -/** Opens a filesystem object (a file) with a given flags and (if needed) with - * some buffer size used in internal buffering. In case of error throws an icpf::exception - * with the error description. - * \param[in] pszPath - path to a file to open - * \param[in] uiFlags - flags that determine the type of access to a file (FA_*) - * \param[in] uiBufSize - buffer size that will be used for internal buffering (if enabled) - */ -void file::open(const tchar_t* pszPath, uint_t uiFlags, uint_t uiBufSize) -{ - // check if this object is ready to open a file - if (m_hFile) - close(); - - // check for the flags completion -#ifdef _WIN32 - uint_t mode=0, flags=OPEN_EXISTING; -#else - int_t mode=0; -#endif - - // read flag - if (uiFlags & FA_READ) -#ifdef _WIN32 - mode |= GENERIC_READ; -#else - mode |= O_RDONLY; -#endif - - // write flag - if (uiFlags & FA_WRITE) -#ifdef _WIN32 - mode |= GENERIC_WRITE; -#else - mode |= O_WRONLY; -#endif - - // creation flag - if (uiFlags & FA_CREATE) -#ifdef _WIN32 - { - if (uiFlags & FA_TRUNCATE) - flags = CREATE_ALWAYS; - else - flags = OPEN_ALWAYS; - } -#else - mode |= O_CREAT; -#endif - - // truncation - if (uiFlags & FA_TRUNCATE) -#ifdef _WIN32 - { - if (!(uiFlags & FA_CREATE)) - flags = TRUNCATE_EXISTING; - } -#else - mode |= O_TRUNC; -#endif - - // make a system call -#ifdef _WIN32 - m_hFile=::CreateFile(pszPath, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, flags, FILE_ATTRIBUTE_NORMAL, NULL); -#else - m_hFile=::open(pszPath, mode); -#endif - - if (m_hFile == INVALID_HANDLE_VALUE) - { - m_hFile=FNULL; - THROW(exception::format(_t("[file] Cannot open the file ") STRFMT _t(" with flags ") ULXFMT, pszPath, uiFlags), FERR_OPEN, CURRENT_LAST_ERROR, 0); - } - else - { - // remember the path of this file - m_pszPath=new tchar_t[_tcslen(pszPath)+1]; - _tcscpy(m_pszPath, pszPath); - - // remember the mode - m_uiFlags=uiFlags; - - // is this buffered ? - set_buffering((uiFlags & FA_BUFFERED) != 0, uiBufSize); - } -} - -/** Tries to save the data contained in internal buffer (if any) and frees all the - * resources used by this class. Can be used on closed files. In case of error the - * ch::exception is thrown. - */ -void file::close() -{ - // only if the file has been opened - if (m_hFile != FNULL) - { - // flush all data - flush(); - - // free strings and other data (at first, because of the destruction call) - delete [] m_pszPath; - m_pszPath=NULL; - delete [] m_pbyBuffer; - m_pbyBuffer=NULL; - - delete [] m_pbySerialBuffer; - m_pbySerialBuffer=NULL; - - m_uiFlags=0; - m_bLastOperation=false; - - m_bBuffered=false; - m_uiBufferSize=0; - m_uiCurrentPos=0; - m_uiDataCount=0; - - m_bSerializing=false; - m_uiSerialBufferSize=0; - m_uiSerialBufferPos=0; - m_uiDataBlockFlags=0; - - m_bRememberedState=false; - - // close the file -#ifdef _WIN32 - if (!::CloseHandle(m_hFile)) -#else - if (::close(m_hFile) == -1) -#endif - THROW(exception::format(_t("[file] Cannot close the handle associated with a file ") STRFMT, m_pszPath), FERR_CLOSE, CURRENT_LAST_ERROR, 0); - else - m_hFile=FNULL; - } -} - -/** Does anything only if the file is opened, the operation is being buffered and the data - * count contained in the internal buffer is >0. If the last operation performed was - * storing data then the function tries to store a packet of data to the file. If the data - * has been read lately then only the file pointer will be repositioned. Also the internal buffer - * will be made empty. Function can throw an ch::exception in case of error. - */ -void file::flush() -{ - if (m_hFile && m_bBuffered && m_uiDataCount > 0) - { - if (m_bLastOperation) - { - // last operation - storing data - _write_packet(); - } - else - { - // last - reading data - // set file pointer to position current-(m_uiDataCount-m_uiCurrentPos) - _seek(-(longlong_t)(m_uiDataCount-m_uiCurrentPos), FS_CURRENT); - m_uiCurrentPos=0; - m_uiDataCount=0; - } - } -} - -/** Tries to read a specified count of bytes from a file to the specified buffer. - * If the is currently in buffered state the reading is being done with internal - * buffering. It could be helpful when reading small amounts of data. - * \param[out] pBuffer - ptr to a buffer that is about to receive data - * \param[in] iSize - count of bytes to read - * \return Count of bytes that has been read (could be less than iSize) - */ -ulong_t file::read(ptr_t pBuffer, ulong_t ulSize) -{ - assert(m_hFile); // forgot to open the file ? - - // flush if needed - if (m_bLastOperation) - { - flush(); - m_bLastOperation=false; - } - - if (!m_bBuffered) - { - // unbuffered operation (read what is needed) -#ifdef _WIN32 - DWORD rd=0; - if (!ReadFile(m_hFile, pBuffer, ulSize, &rd, NULL)) -#else - int_t rd=0; - if ((rd=::read(m_hFile, pBuffer, ulSize)) < 0) -#endif - THROW(exception::format(_t("Cannot read data from file ") STRFMT, m_pszPath), FERR_READ, CURRENT_LAST_ERROR, 0); - - return rd; // if 0 - eof (not treated as exception) - } - else - { - // reads must be done by packets - uint_t uiCurrPos=0; // position in external buffer - while (uiCurrPos < ulSize) - { - // are there any data left ? - if (m_uiDataCount == 0 || m_uiCurrentPos == m_uiDataCount) - { - if (_read_packet() == 0) - return uiCurrPos; // return what was read 'til now - } - - // copy data into external buffer - uint_t uiCount=minval(m_uiDataCount-m_uiCurrentPos, ulSize-uiCurrPos); - memcpy(((byte_t*)pBuffer)+uiCurrPos, m_pbyBuffer+m_uiCurrentPos, uiCount); - - // update positions - uiCurrPos+=uiCount; - m_uiCurrentPos+=uiCount; - } - - return uiCurrPos; - } -} - -/** Tries to write a specified amount of data from a buffer to a file. If the buffered - * operations are enabled then this operation could store data in the internal buffer - * instead of a file. - * \param[in] pBuffer - ptr to a buffer with data to store - * \param[in] iSize - count of data to store - * \return Count of data that has been stored - */ -ulong_t file::write(ptr_t pBuffer, ulong_t ulSize) -{ - assert(m_hFile); - - if (!m_bLastOperation) - { - flush(); - m_bLastOperation=true; - } - - if (!m_bBuffered) - { - // standard write -#ifdef _WIN32 - DWORD wr=0; - if (!WriteFile(m_hFile, pBuffer, ulSize, &wr, NULL)) -#else - int_t wr; - if ((wr=::write(m_hFile, pBuffer, ulSize) == -1)) -#endif - THROW(exception::format(_t("[file] Cannot write data to a file"), m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); - - return (ulong_t)wr; - } - else - { - uint_t uiPos=0; - - while (uiPos < ulSize) - { - // check if buffer need storing - if (m_uiCurrentPos == m_uiBufferSize) - _write_packet(); - - // now add to internal buffer some data - uint_t uiCount=minval(m_uiBufferSize-m_uiCurrentPos, ulSize-uiPos); - - memcpy(m_pbyBuffer+m_uiCurrentPos, ((byte_t*)pBuffer)+uiPos, uiCount); - - // update - m_uiCurrentPos+=uiCount; - m_uiDataCount+=uiCount; - uiPos+=uiCount; - } - - return uiPos; - } -} - -/** Tries to read a string from a file. Uses a buffering to achieve it. If the - * current file mode is unbuffered then this function enables buffering, makes - * requested operation and disables buffering. If the buffer is too small to - * contain all the line read then the rest of line is lost. - * \param[out] pszStr - ptr to a buffer to receive a string - * \param[in] uiMaxLen - size of the string buffer - * \return If the line has been succesfully read. - */ -bool file::read_line(tchar_t* pszStr, uint_t uiMaxLen) -{ - // for unbuffered operations enable buffering for this op - if (m_bBuffered) - return _read_string(pszStr, uiMaxLen); - else - { - uint_t uiSize=m_uiBufferSize; - set_buffering(true, 4096); - - bool bRet=_read_string(pszStr, uiMaxLen); - - set_buffering(false, uiSize); - return bRet; - } -} - -/** Tries to write some text into a file. Function allocates a buffer for the string - * copy and appends a \\r\\n to this text. - * \param[in] pszString - string to store - */ -void file::write_line(tchar_t* pszString) -{ - assert(m_hFile); - - if (!m_bLastOperation) - { - flush(); - m_bLastOperation=true; - } - - // make new string with \r\n at the end - cannot use old buffer - unknown size - // NOTE: \r\n added for windoze compat; when reading file function properly handles unix style line endings - uint_t uiLen=(uint_t)_tcslen(pszString); - - tchar_t *pszData=new tchar_t[uiLen+3]; - _tcscpy(pszData, pszString); - pszData[uiLen]=_t('\r'); - pszData[uiLen+1]=_t('\n'); - pszData[uiLen+2]=_t('\0'); - - try - { - if (m_bBuffered) - { - uint_t uiStrPos=0; // current index in pszString - uint_t uiMin=0; // helper - uint_t uiSize=uiLen+2; - - // processing whole string - while (uiStrPos < uiSize) - { - if (m_uiCurrentPos == m_uiBufferSize) - _write_packet(); - - // count of chars to be copied - uiMin=minval(uiSize-uiStrPos, m_uiBufferSize-m_uiCurrentPos); - - // copy data from pszString into internal buffer (maybe part of it) - memcpy(m_pbyBuffer+m_uiCurrentPos, pszData+uiStrPos, uiMin); - - // move offsets - m_uiCurrentPos+=uiMin; - m_uiDataCount+=uiMin; - uiStrPos+=uiMin; - } - } - else - { - // standard write -#ifdef _WIN32 - DWORD wr=0; - if (!WriteFile(m_hFile, pszData, uiLen+2, &wr, NULL)) -#else - int_t wr; - if ((wr=::write(m_hFile, pszData, uiLen+2)) == -1) -#endif - THROW(exception::format(_t("Cannot write data to a file ") STRFMT, m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); - } - } - catch(...) - { - delete [] pszData; - throw; - } - - delete [] pszData; -} - -/** Moves the file pointer to some place in the file. If the file is in buffered - * state, then the data is flushed and then the real seek takes place. - * \param[in] llOffset - offset of the new file pointer position - * \param[in] uiFrom - specifies the relative point (FS_*) from which the llOffset will be counted - */ -void file::seek(longlong_t llOffset, uint_t uiFrom) -{ - // flush buffer - flush(); - - // seek - _seek(llOffset, uiFrom); -} - -/** Retrieves the current file pointer position (corrected by the content of - * internal buffer if buffered mode enabled). - * \return Current file position. - */ -longlong_t file::getpos() -{ - // return corrected by internal members current file position - return _seek(0, FS_CURRENT)-m_uiDataCount+m_uiCurrentPos; -} - -/** Tries to set end-of-file marker on the current file pointer position. The internal buffer - * is flushed before truncating (or extending). - */ -void file::seteof() -{ - assert(m_hFile); - - // flush da buffers - flush(); - - // now set the end of file -#ifdef _WIN32 - if (!::SetEndOfFile(m_hFile)) -#else - if (::ftruncate(m_hFile, getpos()) == -1) -#endif - THROW(exception::format(_t("[file] Cannot truncate the file ") STRFMT, m_pszPath), FERR_SETEOF, CURRENT_LAST_ERROR, 0); -} - -/** Returns a size of the file. - * \return Size of the file. - */ -longlong_t file::get_size() -{ - flush(); - -#ifdef _WIN32 - ULARGE_INTEGER li; - li.LowPart=GetFileSize(m_hFile, &li.HighPart); - if (li.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) -#else - // NOTE: a strange way to check the file size... - struct stat st; - if (fstat(m_hFile, &st) == -1) -#endif - THROW(exception::format(_t("[file] Cannot get the size of the file ") STRFMT, m_pszPath), FERR_GETSIZE, CURRENT_LAST_ERROR, 0); - -#ifdef _WIN32 - return li.QuadPart; -#else - return st.st_size; -#endif -} - -/** Changes the buffering state (or internal buffer length). The internal buffer - * is always flushed before making any changes. - * \param[in] bEnable - specifies if the buffering is about to be enabled - * \param[in] uiSize - the new size of the internal buffer - */ -void file::set_buffering(bool bEnable, uint_t uiSize) -{ - assert(uiSize > 0); // couldn't use 0-sized internal buffer - - // flush - flush(); - - // delete old buffer - if (m_bBuffered && (!bEnable || uiSize != m_uiBufferSize)) - { - delete [] m_pbyBuffer; - m_pbyBuffer=NULL; - } - - // alloc new buffer if needed - if (bEnable && (!m_bBuffered || uiSize != m_uiBufferSize)) - m_pbyBuffer=new byte_t[uiSize]; - - m_bBuffered=bEnable; - m_uiBufferSize=uiSize; -} - -/** Switches access mode to unbuffered one and remembers the last state. If already - * in unbuffered mode the function does nothing. - */ -void file::switch_unbuffered() -{ - if (!m_bBuffered) - return; // it's already unbuffered - leave it as is - else - { - m_bRememberedState=true; // mark that we change state to a different one - set_buffering(false, m_uiBufferSize); // do no change internal buffer size - } -} - -/** Switches access mode to buffered one and remembers the last state. If already - * in buffered mode the function does nothing. - */ -void file::switch_buffered() -{ - if (m_bBuffered) - return; // already buffered - else - { - m_bRememberedState=true; - set_buffering(true, m_uiBufferSize); - } -} - -/** Restores the buffered/unbuffered access mode if stored with switch_* functions. - */ -void file::restore_state() -{ - // restore state only if changed - if (m_bRememberedState) - { - set_buffering(!m_bBuffered, m_uiBufferSize); - m_bRememberedState=false; - } -} - -/** Begins the serialization data block. Each block can have it's - * own flags. Each block have to be ended with datablock_end before - * beginning another one. If the access is read then function tries to read - * the data block from a file and checks the crc checksums. If writing - only - * the buffer is allocated and initialized. - * Blocks cannot be nested. - * \param[in] uiFlags - block flags - look at BF_* macros - */ -void file::datablock_begin(uint_t uiFlags) -{ - // do not call begin data block within another data block - assert(!m_bSerializing && m_pbySerialBuffer == NULL); - - // alloc the new buffer and insert there a header (a few unsigned chars) - m_pbySerialBuffer=new byte_t[SERIALBUFFER_DELTA]; - m_uiSerialBufferSize=SERIALBUFFER_DELTA; - - // check flags - if ((m_uiFlags & FA_READ) && (m_uiFlags & FA_WRITE)) - THROW(exception::format(_t("[file] Tried to begin a data block with file ") STRFMT _t(" opened for both read and write."), m_pszPath), FERR_SERIALIZE, 0, 0); - - // action - if (m_uiFlags & FA_WRITE) - { - // reserve some space for a header - m_uiSerialBufferPos=sizeof(SERIALIZEINFOHEADER); - } - else - { - // we need to read the block from a file - if (read(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)) != sizeof(SERIALIZEINFOHEADER)) - { - _clear_serialization(); - THROW(exception::format(_t("[file] Cannot read the specified amount of data from a file (reading serialization header)."), m_pszPath), FERR_SERIALIZE, CURRENT_LAST_ERROR, 0); - } - - // move forward - m_uiSerialBufferPos=sizeof(SERIALIZEINFOHEADER); - - // determine the size of the remaining data in file - SERIALIZEINFOHEADER* psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - uint_t uiSize=(uint_t)(psih->iRealSize-sizeof(SERIALIZEINFOHEADER)); - - // check the header crc - uint_t uihc=crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(uint_t)); - if (uihc != psih->uiHeaderCRC32) - { - _clear_serialization(); - THROW(exception::format(_t("[file] Block contained in file ") STRFMT _t(" is corrupted. Header CRC check failed."), m_pszPath), FERR_SERIALIZE, 0, 0); - } - - // resize the buffer - _sbuf_resize((uint_t)psih->iRealSize); - - // refresh the psih - psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - - // read the remaining data - if (read(m_pbySerialBuffer+m_uiSerialBufferPos, uiSize) != (int_t)uiSize) - { - _clear_serialization(); - THROW(exception::format(_t("Cannot read specified amount of data from a file ") STRFMT _t(" (reading the after-header data)."), m_pszPath), FERR_SERIALIZE, CURRENT_LAST_ERROR, 0); - } - - // NOTE: do not update the position - we need ptr at the beginning of data - // now we are almost ready to retrieve data - only the crc check for the data - uint_t uiCRC=crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), psih->iDataSize-sizeof(SERIALIZEINFOHEADER)); - if (psih->uiCRC32 != uiCRC) - { - _clear_serialization(); - THROW(exception::format(_t("CRC check of the data read from file ") STRFMT _t(" failed."), m_pszPath), FERR_SERIALIZE, 0, 0); - } - } - - // make a mark - m_uiDataBlockFlags=uiFlags; - m_bSerializing=true; -} - -/** Ends the data block opened previously with datablock_begin. If the access is writing - * then the function updates the crc checksums in the buffer and tries to write the block - * of data to the file. If reading - only the serialization is cancelled. - */ -void file::datablock_end() -{ - // make sure everything is ok - assert(m_bSerializing && m_pbySerialBuffer != NULL); - if(!m_pbySerialBuffer) - THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); - - // check the operation type - if ((m_uiFlags & FA_READ) && (m_uiFlags & FA_WRITE)) - THROW(exception::format(_t("[file] Tried to end a data block with file ") STRFMT _t(" opened for both read and write."), m_pszPath), FERR_SERIALIZE, 0, 0); - - // when writing - make a header, ...; when reading - do nothing important - if (m_uiFlags & FA_WRITE) - { - // check if there is any data - if (m_uiSerialBufferPos == sizeof(SERIALIZEINFOHEADER)) - return; // no data has been serialized - - // fill the header (real data information) - SERIALIZEINFOHEADER *psih=(SERIALIZEINFOHEADER*)m_pbySerialBuffer; - psih->iDataSize=m_uiSerialBufferPos; - psih->uiCRC32=crc32(m_pbySerialBuffer+sizeof(SERIALIZEINFOHEADER), m_uiSerialBufferPos-sizeof(SERIALIZEINFOHEADER)); - - // the rest of header - psih->iRealSize=m_uiSerialBufferPos; - - // calc the header crc - psih->uiHeaderCRC32=crc32(m_pbySerialBuffer, sizeof(SERIALIZEINFOHEADER)-sizeof(uint_t)); - - // write the buffer - write(m_pbySerialBuffer, psih->iRealSize); - } - - // remove all the traces of serializing - _clear_serialization(); -} - -/** Writes some bytes of data to a serialization buffer opened - * with the datablock_begin. Causes the class to reallocate an internal - * buffer(if needed) to make all the data fit into the buffer. - * NOTE: do not use too large data blocks because of the buffer reallocation. - * \param[in] pData - buffer address with some data - * \param[in] uiSize - count of bytes to write - */ -void file::swrite(ptr_t pData, uint_t uiSize) -{ - _sbuf_append(pData, uiSize); -} - -/** Reads some bytes of data from a serialization buffer opened by - * datablock_end call. - * \param[out] pData - buffer for the received data - * \param[in] uiSize - count of data to read; if user requests more data than available then an exception will be thrown - */ -void file::sread(ptr_t pData, uint_t uiSize) -{ - _sbuf_read(pData, uiSize); -} - -/** Cancels the serialization process and removes all the traces of data being serialized - * (it includes deleting the serialization buffer). - */ -void file::_clear_serialization() -{ - // remove all the traces of serializing - delete [] m_pbySerialBuffer; - m_pbySerialBuffer=NULL; - m_uiSerialBufferSize=0; - m_uiSerialBufferPos=0; - m_bSerializing=false; -} - -/** Used to read the next packet of data into the internal buffer (used for - * buffering). - * \return Count of bytes that has been read from a file. - */ -uint_t file::_read_packet() -{ - assert(m_hFile); - if(!m_hFile || !m_pbyBuffer) - THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); - - // read data -#ifdef _WIN32 - DWORD rd=0; - if (!ReadFile(m_hFile, m_pbyBuffer, m_uiBufferSize, &rd, NULL)) -#else - int_t rd; - if ((rd=::read(m_hFile, m_pbyBuffer, m_uiBufferSize)) == -1) -#endif - THROW(exception::format(_t("[file] Cannot read data from a file ") STRFMT _t("."), m_pszPath), FERR_READ, CURRENT_LAST_ERROR, 0); - - // reset internal members - m_uiDataCount=rd; - m_uiCurrentPos=0; - - return rd; -} - -/** Used to write the next packet of data from an internal buffer (buffering - * related) to a file. - * \return Count of bytes written. - */ -uint_t file::_write_packet() -{ - assert(m_hFile); - if(!m_hFile || !m_pbyBuffer) - THROW(_t("Invalid argument"), GE_INVALIDARG, 0, 0); - -#ifdef _WIN32 - DWORD wr=0; - if (!WriteFile(m_hFile, m_pbyBuffer, m_uiDataCount, &wr, NULL)) -#else - int_t wr; - if ((wr=::write(m_hFile, m_pbyBuffer, m_uiDataCount)) == -1) -#endif - { - THROW(exception::format(_t("Cannot write data to a file ") STRFMT _t("."), m_pszPath), FERR_WRITE, CURRENT_LAST_ERROR, 0); - } - - // reset internal members - m_uiDataCount=0; - m_uiCurrentPos=0; - - return wr; -} - -/** Reads some data from the internal serialization buffer. - * \param[out] pData - ptr to a buffer that is about to receive data - * \param[in] uiLen - count of data to be read - */ -void file::_sbuf_read(ptr_t pData, uint_t uiLen) -{ - // check if we are reading - assert(m_uiFlags & FA_READ); - - // check the ranges - if (m_uiSerialBufferPos+uiLen > m_uiSerialBufferSize) - { - // throw an exception - read beyond the data range in a given object - THROW(exception::format(_t("[file] Trying to read the serialization data beyond the range (file ") TSTRFMT _t(")."), m_pszPath), FERR_MEMORY, CURRENT_LAST_ERROR, 0); - } - - // read the data - memcpy(pData, m_pbySerialBuffer+m_uiSerialBufferPos, uiLen); - m_uiSerialBufferPos+=uiLen; -} - -/** Appends some bytes to the internal serialization buffer (data block). - * \param[in] pData - ptr to a data buffer - * \param[in] uiCount - count of data to store - */ -void file::_sbuf_append(ptr_t pData, uint_t uiCount) -{ - // check if we are writing - assert(m_uiFlags & FA_WRITE); - - // check serial buffer size (if there is enough room for the data) - if (m_uiSerialBufferPos+uiCount > m_uiSerialBufferSize) - { - // we need a buffer reallocation - uint_t uiDelta=((uiCount/SERIALBUFFER_DELTA)+1)*SERIALBUFFER_DELTA; - - // alloc the new buffer - _sbuf_resize(m_uiSerialBufferSize+uiDelta); - } - - assert(m_pbySerialBuffer); - if(!m_pbySerialBuffer) - THROW(_t("Invalid buffer."), 0, 0, 0); - // real storage of the data - if (uiCount > 0) - { - memcpy(m_pbySerialBuffer+m_uiSerialBufferPos, pData, uiCount); - m_uiSerialBufferPos+=uiCount; - } -} - -/** Resizes the internal serialization buffer to the new length. - * Also does copy the old data to the new buffer. - * \param[in] uiNewLen - new buffer length - */ -void file::_sbuf_resize(uint_t uiNewLen) -{ - // alloc the new buffer - byte_t* pbyNewBuffer=new byte_t[uiNewLen]; - - // copy the old data into the new one - uint_t uiCount=minval(m_uiSerialBufferPos, uiNewLen); - if (m_uiSerialBufferPos > 0) - memcpy(pbyNewBuffer, m_pbySerialBuffer, uiCount); - - // delete the old buffer - delete [] m_pbySerialBuffer; - - // set the new buffer inplace and update the internal size - m_pbySerialBuffer=pbyNewBuffer; - m_uiSerialBufferSize=uiNewLen; -} - - -/** Reads a line of text from text file - only for buffered operations. - * Properly interpretes the windoze and unix line endings. - * \param[out] pszStr - buffer for the string that is about to be read - * \param[in] uiMaxLen - size of the string buffer - * \return Bool value that states if the string has been read. - */ -bool file::_read_string(tchar_t* pszStr, uint_t uiMaxLen) -{ - assert(m_hFile); // file wasn_t('t opened - error opening or you')ve forgotten to do so ? - assert(m_pbyBuffer != NULL); - - // last time was writing - free buffer - if (m_bLastOperation) - { - flush(); - m_bLastOperation=false; - } - - // zero all the string - memset(pszStr, 0, uiMaxLen*sizeof(tchar_t)); - - // additional vars - uint_t uiStrPos=0; // current pos in external buffer - bool bSecondPass=false; // if there is need to check data for 0x0a tchar_t - - // copy each tchar_t into pszString - for (;;) - { - // if buffer is empty - fill it - if (m_uiDataCount == 0 || m_uiCurrentPos == m_uiDataCount) - { - if (_read_packet() == 0) - return _tcslen(pszStr) != 0; - } - - // skipping 0x0a in second pass - if (bSecondPass) - { - if (m_pbyBuffer[m_uiCurrentPos] == 0x0a) - m_uiCurrentPos++; - return true; - } - - // now process chars - while (m_uiCurrentPos < m_uiDataCount) - { - if (m_pbyBuffer[m_uiCurrentPos] == 0x0d) - { - bSecondPass=true; - m_uiCurrentPos++; - break; - } - else if (m_pbyBuffer[m_uiCurrentPos] == 0x0a) - { - m_uiCurrentPos++; - return true; - } - else - { - if (uiStrPos < uiMaxLen-1) - pszStr[uiStrPos++]=m_pbyBuffer[m_uiCurrentPos]; - m_uiCurrentPos++; - } - } - } -} - -/** Sets file pointer in a file. - * \param[in] llOffset - position to move the file pointer to - * \param[in] uiFrom - the relative position of a base position (FS_*) - * \return The new file pointer position. - */ -longlong_t file::_seek(longlong_t llOffset, uint_t uiFrom) -{ -#ifdef _WIN32 - LARGE_INTEGER li; - li.QuadPart = llOffset; - li.LowPart = SetFilePointer (m_hFile, li.LowPart, &li.HighPart, uiFrom); - - if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) -#else - int_t lRes; - if ((lRes=lseek(m_hFile, llOffset, uiFrom)) == -1) -#endif - THROW(exception::format(_t("Seek error in file ") STRFMT _t("."), m_pszPath), FERR_SEEK, CURRENT_LAST_ERROR, 0); - -#ifdef _WIN32 - return li.QuadPart; -#else - return lRes; -#endif -} - -END_ICPF_NAMESPACE Index: src/libicpf/file.h =================================================================== diff -u -N --- src/libicpf/file.h (revision 0) +++ src/libicpf/file.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,346 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file file.h + * \brief Contains system independent file/serializer class + * \todo Apply properly handling of the encryption/decryption stuff. + * \todo Modify the class so it could handle full 64bit files. + * \todo Correct the file creation flags under linux (wrong umask value?). + */ + +#ifndef __FILE_H__ +#define __FILE_H__ + +#include "exception.h" +#include "libicpf.h" +#include +//#include "str.h" +#ifdef _WIN32 + #include "windows.h" +#endif + +// file access modes +/// Read access to the file +#define FA_READ 0x0001 +/// Write access to the file +#define FA_WRITE 0x0002 +/// Create file if does not exist +#define FA_CREATE 0x0004 +/// Truncate file if not empty +#define FA_TRUNCATE 0x0008 + +// additional mode mods +/// Enable buffered access +#define FA_BUFFERED 0x8000 + +// begin data block flags +/// Standard flag - cannot be combined with others +#define BF_NONE 0x00 + +// seek constants +#ifdef _WIN32 + /// Seeks from the current file pointer position + #define FS_CURRENT FILE_CURRENT + /// Seeks from the beginning of the file + #define FS_SET FILE_BEGIN + /// Seeks from the end of file + #define FS_END FILE_END +#else + /// Seeks from the current file pointer position + #define FS_CURRENT SEEK_CUR + /// Seeks from the beginning of the file + #define FS_SET SEEK_SET + /// Seeks from the end of file + #define FS_END SEEK_END +#endif + +BEGIN_ICPF_NAMESPACE + +/** \brief Structure describes the data inside a data block + * + * Structure contain crc fields to make sure data block is consistent. + * Also the real data size and stored data size are included */ +struct SERIALIZEINFOHEADER +{ + // main header + int_t iDataSize; ///< Size of the meaningful data (including this header) + int_t iRealSize; ///< Size of the data stored in file (may differ from ulDataSize ie. when encrypting) + uint_t uiCRC32; ///< Crc32 of the data (only the data part) + + // helper + uint_t uiHeaderCRC32; ///< Header's crc32 (without this field) +}; + +/** \brief Platform independent file and serialization class + * + * Class allows to access file objects using system dependent functions. Allow + * to use internal buffering for faster reading small amounts of data. + * Also allows to serialize data in blocks (with crc checksums). + */ +class LIBICPF_API file +{ +public: + // construction/destruction +/** \name Construction/destruction +@{*/ + file(); ///< Constructs a file object + ~file(); ///< Destructs a file object +/**@}*/ + +/** \name Standard operations + * Standard file operations that works both in buffered and unbuffered mode. + */ +/**@{*/ + // open/close the file + void open(const tchar_t* pszPath, uint_t uiFlags, uint_t uiBufSize=4096); ///< Opens a file with a given path + void close(); ///< Closes the currently opened file + + // reads or writes the data from/to a file (uses buffering for these operations if enabled) + ulong_t read(ptr_t pBuffer, ulong_t ulSize); ///< Reads some data from a file + ulong_t write(ptr_t pBuffer, ulong_t ulSize); ///< Writes some data to a file + + // handling the lines of text in a file (autodetecting the windows/unix style of line ending) + bool read_line(tchar_t* pszStr, uint_t uiMaxLen); ///< Reads a line of text from a file + void write_line(tchar_t* pszString); ///< Writes a line of text to a file + + // position related functions + void seek(longlong_t llOffset, uint_t uiFrom); ///< Moves a file pointer in a file + longlong_t getpos(); ///< Gets the current position of a file pointer + + // size related functions + void seteof(); ///< Sets the end of file in the current file pointer place + longlong_t get_size(); ///< Retrieves the size of a file + + void flush(); ///< Flushes the internal buffers +/**@}*/ + + +/** \name Buffering state functions + * Operations that allow manipulating the file buffering state. + */ +/**@{*/ + // buffered/unbuffered state management + /// Enables or disables the buffering + void set_buffering(bool bEnable=true, uint_t dwSize=4096); + /// Returns the buffering state + bool is_buffered() const { return m_bBuffered; }; + /// Returns the current buffer size (for buffered operations) + uint_t get_buffersize() const { return m_uiBufferSize; }; + + void switch_unbuffered(); ///< Stores current buffered/unbuffered state and switches to unbuffered + void switch_buffered(); ///< Stores current buffered/unbuffered state and switches to buffered + void restore_state(); ///< Restores (un)buffered last state +/**@}*/ + +/** \name Serialization functions + * Operations that allow manipulating the file buffering state. + */ +/**@{*/ + // serialization (block operation) + void datablock_begin(uint_t dwFlags=BF_NONE); ///< Begins the serialization data block + void datablock_end(); ///< Ends the serialization data block + + // serialization stuff + void swrite(ptr_t pData, uint_t dwSize); ///< Appends some data to the serialialization buffer + void sread(ptr_t pData, uint_t dwSize); ///< Reads some data from serialization buffer + + // state checking + /// Checks if the class is performing write-type serialization + bool is_storing() const { return (m_uiFlags & FA_WRITE) != 0; }; + /// Checks if the class is performing read-type serialization + bool is_loading() const { return (m_uiFlags & FA_READ) != 0; }; + + // storing&reading data + /// Stores some integral type as a part of serialization data block + + // specialized serialization stuff +// file& operator<<(icpf::string& str); ///< Stores a CString object in this file (only usable when used in an MFC program) +// file& operator>>(icpf::string& str); ///< Reads a CString object from this file (only usable when used in an mfc program) +/**@}*/ + +protected: + // serialization related internal functions + void _sbuf_append(ptr_t pData, uint_t dwCount); ///< Adds some data to the end of serialization buffer + void _sbuf_resize(uint_t dwNewLen); ///< Resizes the serialization buffer to make some more additional space + void _sbuf_read(ptr_t pData, uint_t dwLen); ///< Gets some data from the serialization buffer + void _clear_serialization(); ///< Cancels the serialization + + // file-buffering related operations + uint_t _read_packet(); ///< Reads next packet of data into the internal buffer + uint_t _write_packet(); ///< Writes next packet of data into a file + + bool _read_string(tchar_t* pszStr, uint_t dwMaxLen); ///< Reads a string from an internal buffer + longlong_t _seek(longlong_t llOffset, uint_t uiFrom); ///< A standard seek command done wo any flushing + +protected: +#ifdef _WIN32 + HANDLE m_hFile; ///< Handle to a real file +#else + intptr_t m_hFile; ///< Handle to a real file +#endif + tchar_t* m_pszPath; ///< Path to the opened file as passed to file::open() + uint_t m_uiFlags; ///< File flags as passed to file::open() + + bool m_bLastOperation; ///< States the last operation performed - false=>READ, true=>WRITE + + // read/write buffering + bool m_bBuffered; ///< States if the file is currently in buffered state + uint_t m_uiBufferSize; ///< Internal buffer size for buffering + byte_t* m_pbyBuffer; ///< Ptr to the internal buffer + uint_t m_uiCurrentPos; ///< Current position in the internal buffer + uint_t m_uiDataCount; ///< Count of data in the internal buffer (counting from beginning) + + // state + bool m_bRememberedState; ///< Specifies if the buffering state was saved + + // serialization stuff + bool m_bSerializing; ///< States if the serialization is in progress + byte_t* m_pbySerialBuffer; ///< Serialization buffer + uint_t m_uiSerialBufferSize; ///< Current size of the serialization buffer + uint_t m_uiSerialBufferPos; ///< Current position in the serialization buffer + uint_t m_uiDataBlockFlags; ///< Flags of the current serialization block +}; + +// An alias class +typedef file archive; + +template +inline file& operator<<(file& rFile, const T& tData) +{ + rFile.swrite((ptr_t)&tData, sizeof(T)); + return rFile; +} + +template<> +inline file& operator<<(file& rFile, const tchar_t *const &pszText) +{ + size_t stLen = _tcslen(pszText); + rFile << stLen; + rFile.swrite((ptr_t)pszText, (uint_t)stLen*sizeof(tchar_t)); + return rFile; +} + +#ifdef _MFC_VER +template<> +inline file& operator<<(file& rFile, const CString &strText) +{ + return rFile<<(const tchar_t*)strText; +} + +template<> +inline file& operator<<(file& rFile, const CStringArray& arrStr) +{ + size_t stCount = arrStr.GetCount(); + rFile.swrite(&stCount, sizeof(stCount)); + + for(size_t stIndex = 0; stIndex != stCount; ++stIndex) + { + rFile<<((const tchar_t*)arrStr.GetAt(stIndex)); + } + return rFile; +} + +template<> +inline file& operator<<(file& rFile, const std::vector& arrStr) +{ + size_t stCount = arrStr.size(); + rFile.swrite(&stCount, sizeof(stCount)); + + for(std::vector::const_iterator iterEntry = arrStr.begin(); iterEntry != arrStr.end(); ++iterEntry) + { + rFile<<((const tchar_t*)*iterEntry); + } + return rFile; +} +#endif + +/// Reads some integral type from a serialization data block +template +inline file& operator>>(file& rFile, T& tData) +{ + rFile.sread(&tData, sizeof(T)); + return rFile; +} + +#ifdef _MFC_VER +template<> +inline file& operator>>(file& rFile, CString& str) +{ + str.Empty(); + + size_t stCount = 0; + rFile >> stCount; + if(stCount) + { + try + { + PTSTR pszBuffer = str.GetBufferSetLength((int)(stCount + 1)); + rFile.sread((ptr_t)pszBuffer, (uint_t)stCount * sizeof(tchar_t)); + pszBuffer[stCount] = _T('\0'); + str.ReleaseBuffer(); + } + catch(CMemoryException* e) + { + e->Delete(); + THROW(_T("Memory exception intercepted"), 0, ERROR_READ_FAULT, 0); + } + catch(COleException* e) + { + e->Delete(); + THROW(_T("Ole exception intercepted"), 0, ERROR_READ_FAULT, 0); + } + } + return rFile; +} + +template<> +inline file& operator>>(file& rFile, CStringArray& arrStrings) +{ + arrStrings.RemoveAll(); + size_t stCount = 0; + rFile>>(stCount); + + CString str; + for(size_t stIndex = 0; stIndex != stCount; ++stIndex) + { + rFile >> (str); + arrStrings.Add(str); + } + return rFile; +} + +template<> +inline file& operator>>(file& rFile, std::vector& arrStrings) +{ + arrStrings.clear(); + size_t stCount = 0; + rFile>>(stCount); + + CString str; + for(size_t stIndex = 0; stIndex != stCount; ++stIndex) + { + rFile >> (str); + arrStrings.push_back(str); + } + return rFile; +} +#endif + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/file.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/file.h (revision ef6c75aa057c06ecd065137ee9e459c431806e8a) +++ ext/libicpf/src/libicpf/file.h (revision 0) @@ -1,346 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file file.h - * \brief Contains system independent file/serializer class - * \todo Apply properly handling of the encryption/decryption stuff. - * \todo Modify the class so it could handle full 64bit files. - * \todo Correct the file creation flags under linux (wrong umask value?). - */ - -#ifndef __FILE_H__ -#define __FILE_H__ - -#include "exception.h" -#include "libicpf.h" -#include -//#include "str.h" -#ifdef _WIN32 - #include "windows.h" -#endif - -// file access modes -/// Read access to the file -#define FA_READ 0x0001 -/// Write access to the file -#define FA_WRITE 0x0002 -/// Create file if does not exist -#define FA_CREATE 0x0004 -/// Truncate file if not empty -#define FA_TRUNCATE 0x0008 - -// additional mode mods -/// Enable buffered access -#define FA_BUFFERED 0x8000 - -// begin data block flags -/// Standard flag - cannot be combined with others -#define BF_NONE 0x00 - -// seek constants -#ifdef _WIN32 - /// Seeks from the current file pointer position - #define FS_CURRENT FILE_CURRENT - /// Seeks from the beginning of the file - #define FS_SET FILE_BEGIN - /// Seeks from the end of file - #define FS_END FILE_END -#else - /// Seeks from the current file pointer position - #define FS_CURRENT SEEK_CUR - /// Seeks from the beginning of the file - #define FS_SET SEEK_SET - /// Seeks from the end of file - #define FS_END SEEK_END -#endif - -BEGIN_ICPF_NAMESPACE - -/** \brief Structure describes the data inside a data block - * - * Structure contain crc fields to make sure data block is consistent. - * Also the real data size and stored data size are included */ -struct SERIALIZEINFOHEADER -{ - // main header - int_t iDataSize; ///< Size of the meaningful data (including this header) - int_t iRealSize; ///< Size of the data stored in file (may differ from ulDataSize ie. when encrypting) - uint_t uiCRC32; ///< Crc32 of the data (only the data part) - - // helper - uint_t uiHeaderCRC32; ///< Header's crc32 (without this field) -}; - -/** \brief Platform independent file and serialization class - * - * Class allows to access file objects using system dependent functions. Allow - * to use internal buffering for faster reading small amounts of data. - * Also allows to serialize data in blocks (with crc checksums). - */ -class LIBICPF_API file -{ -public: - // construction/destruction -/** \name Construction/destruction -@{*/ - file(); ///< Constructs a file object - ~file(); ///< Destructs a file object -/**@}*/ - -/** \name Standard operations - * Standard file operations that works both in buffered and unbuffered mode. - */ -/**@{*/ - // open/close the file - void open(const tchar_t* pszPath, uint_t uiFlags, uint_t uiBufSize=4096); ///< Opens a file with a given path - void close(); ///< Closes the currently opened file - - // reads or writes the data from/to a file (uses buffering for these operations if enabled) - ulong_t read(ptr_t pBuffer, ulong_t ulSize); ///< Reads some data from a file - ulong_t write(ptr_t pBuffer, ulong_t ulSize); ///< Writes some data to a file - - // handling the lines of text in a file (autodetecting the windows/unix style of line ending) - bool read_line(tchar_t* pszStr, uint_t uiMaxLen); ///< Reads a line of text from a file - void write_line(tchar_t* pszString); ///< Writes a line of text to a file - - // position related functions - void seek(longlong_t llOffset, uint_t uiFrom); ///< Moves a file pointer in a file - longlong_t getpos(); ///< Gets the current position of a file pointer - - // size related functions - void seteof(); ///< Sets the end of file in the current file pointer place - longlong_t get_size(); ///< Retrieves the size of a file - - void flush(); ///< Flushes the internal buffers -/**@}*/ - - -/** \name Buffering state functions - * Operations that allow manipulating the file buffering state. - */ -/**@{*/ - // buffered/unbuffered state management - /// Enables or disables the buffering - void set_buffering(bool bEnable=true, uint_t dwSize=4096); - /// Returns the buffering state - bool is_buffered() const { return m_bBuffered; }; - /// Returns the current buffer size (for buffered operations) - uint_t get_buffersize() const { return m_uiBufferSize; }; - - void switch_unbuffered(); ///< Stores current buffered/unbuffered state and switches to unbuffered - void switch_buffered(); ///< Stores current buffered/unbuffered state and switches to buffered - void restore_state(); ///< Restores (un)buffered last state -/**@}*/ - -/** \name Serialization functions - * Operations that allow manipulating the file buffering state. - */ -/**@{*/ - // serialization (block operation) - void datablock_begin(uint_t dwFlags=BF_NONE); ///< Begins the serialization data block - void datablock_end(); ///< Ends the serialization data block - - // serialization stuff - void swrite(ptr_t pData, uint_t dwSize); ///< Appends some data to the serialialization buffer - void sread(ptr_t pData, uint_t dwSize); ///< Reads some data from serialization buffer - - // state checking - /// Checks if the class is performing write-type serialization - bool is_storing() const { return (m_uiFlags & FA_WRITE) != 0; }; - /// Checks if the class is performing read-type serialization - bool is_loading() const { return (m_uiFlags & FA_READ) != 0; }; - - // storing&reading data - /// Stores some integral type as a part of serialization data block - - // specialized serialization stuff -// file& operator<<(icpf::string& str); ///< Stores a CString object in this file (only usable when used in an MFC program) -// file& operator>>(icpf::string& str); ///< Reads a CString object from this file (only usable when used in an mfc program) -/**@}*/ - -protected: - // serialization related internal functions - void _sbuf_append(ptr_t pData, uint_t dwCount); ///< Adds some data to the end of serialization buffer - void _sbuf_resize(uint_t dwNewLen); ///< Resizes the serialization buffer to make some more additional space - void _sbuf_read(ptr_t pData, uint_t dwLen); ///< Gets some data from the serialization buffer - void _clear_serialization(); ///< Cancels the serialization - - // file-buffering related operations - uint_t _read_packet(); ///< Reads next packet of data into the internal buffer - uint_t _write_packet(); ///< Writes next packet of data into a file - - bool _read_string(tchar_t* pszStr, uint_t dwMaxLen); ///< Reads a string from an internal buffer - longlong_t _seek(longlong_t llOffset, uint_t uiFrom); ///< A standard seek command done wo any flushing - -protected: -#ifdef _WIN32 - HANDLE m_hFile; ///< Handle to a real file -#else - intptr_t m_hFile; ///< Handle to a real file -#endif - tchar_t* m_pszPath; ///< Path to the opened file as passed to file::open() - uint_t m_uiFlags; ///< File flags as passed to file::open() - - bool m_bLastOperation; ///< States the last operation performed - false=>READ, true=>WRITE - - // read/write buffering - bool m_bBuffered; ///< States if the file is currently in buffered state - uint_t m_uiBufferSize; ///< Internal buffer size for buffering - byte_t* m_pbyBuffer; ///< Ptr to the internal buffer - uint_t m_uiCurrentPos; ///< Current position in the internal buffer - uint_t m_uiDataCount; ///< Count of data in the internal buffer (counting from beginning) - - // state - bool m_bRememberedState; ///< Specifies if the buffering state was saved - - // serialization stuff - bool m_bSerializing; ///< States if the serialization is in progress - byte_t* m_pbySerialBuffer; ///< Serialization buffer - uint_t m_uiSerialBufferSize; ///< Current size of the serialization buffer - uint_t m_uiSerialBufferPos; ///< Current position in the serialization buffer - uint_t m_uiDataBlockFlags; ///< Flags of the current serialization block -}; - -// An alias class -typedef file archive; - -template -inline file& operator<<(file& rFile, const T& tData) -{ - rFile.swrite((ptr_t)&tData, sizeof(T)); - return rFile; -} - -template<> -inline file& operator<<(file& rFile, const tchar_t *const &pszText) -{ - size_t stLen = _tcslen(pszText); - rFile << stLen; - rFile.swrite((ptr_t)pszText, (uint_t)stLen*sizeof(tchar_t)); - return rFile; -} - -#ifdef _MFC_VER -template<> -inline file& operator<<(file& rFile, const CString &strText) -{ - return rFile<<(const tchar_t*)strText; -} - -template<> -inline file& operator<<(file& rFile, const CStringArray& arrStr) -{ - size_t stCount = arrStr.GetCount(); - rFile.swrite(&stCount, sizeof(stCount)); - - for(size_t stIndex = 0; stIndex != stCount; ++stIndex) - { - rFile<<((const tchar_t*)arrStr.GetAt(stIndex)); - } - return rFile; -} - -template<> -inline file& operator<<(file& rFile, const std::vector& arrStr) -{ - size_t stCount = arrStr.size(); - rFile.swrite(&stCount, sizeof(stCount)); - - for(std::vector::const_iterator iterEntry = arrStr.begin(); iterEntry != arrStr.end(); ++iterEntry) - { - rFile<<((const tchar_t*)*iterEntry); - } - return rFile; -} -#endif - -/// Reads some integral type from a serialization data block -template -inline file& operator>>(file& rFile, T& tData) -{ - rFile.sread(&tData, sizeof(T)); - return rFile; -} - -#ifdef _MFC_VER -template<> -inline file& operator>>(file& rFile, CString& str) -{ - str.Empty(); - - size_t stCount = 0; - rFile >> stCount; - if(stCount) - { - try - { - PTSTR pszBuffer = str.GetBufferSetLength((int)(stCount + 1)); - rFile.sread((ptr_t)pszBuffer, (uint_t)stCount * sizeof(tchar_t)); - pszBuffer[stCount] = _T('\0'); - str.ReleaseBuffer(); - } - catch(CMemoryException* e) - { - e->Delete(); - THROW(_T("Memory exception intercepted"), 0, ERROR_READ_FAULT, 0); - } - catch(COleException* e) - { - e->Delete(); - THROW(_T("Ole exception intercepted"), 0, ERROR_READ_FAULT, 0); - } - } - return rFile; -} - -template<> -inline file& operator>>(file& rFile, CStringArray& arrStrings) -{ - arrStrings.RemoveAll(); - size_t stCount = 0; - rFile>>(stCount); - - CString str; - for(size_t stIndex = 0; stIndex != stCount; ++stIndex) - { - rFile >> (str); - arrStrings.Add(str); - } - return rFile; -} - -template<> -inline file& operator>>(file& rFile, std::vector& arrStrings) -{ - arrStrings.clear(); - size_t stCount = 0; - rFile>>(stCount); - - CString str; - for(size_t stIndex = 0; stIndex != stCount; ++stIndex) - { - rFile >> (str); - arrStrings.push_back(str); - } - return rFile; -} -#endif - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/gen_types.h =================================================================== diff -u -N --- src/libicpf/gen_types.h (revision 0) +++ src/libicpf/gen_types.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,341 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file gen_types.h + * \brief Contains some compile-time settings for the whole engine. + */ +#ifndef __GENTYPES_H__ +#define __GENTYPES_H__ + +#if defined(HAVE_CONFIG_H) + #include "config.h" +#endif + +#ifdef HAVE_INTTYPES_H + #include +#else + #include +#endif + +#if defined (_WIN32) || defined (_WIN64) + #include +#endif + +#include + +// standard types and formats used throughout the library +// exactly 1 byte +/// Byte type (8bit unsigned int) +typedef unsigned char byte_t; + +// chars +/// 8bit signed char +typedef char char_t; +/// 8bit unsigned char +typedef unsigned char uchar_t; + +// system/configuration dependent chars +#if (defined(_WIN32) || defined(_WIN64)) && defined(_UNICODE) + /// System/configuration dependent character (either wide char or normal one) + typedef wchar_t tchar_t; + typedef std::wstring tstring_t; + /// Macro to be appended to each text in code to be either composed of wide characters or normal ones + #define __t(text) L##text + #define _t(text) __t(text) + /// String formatting string - depending on configuration could display wide char string or normal one. + #define TSTRFMT WSTRFMT + #define TCHRFMT CHRFMT +#else + // description as above + typedef char_t tchar_t; + typedef std::string tstring_t; + #define _t(text) text + #define TSTRFMT STRFMT + #define TCHRFMT CHRFMT +#endif + +// 16-bit integers +/// 16bit short integer +typedef short short_t; +/// 16bit unsigned short integer +typedef unsigned short ushort_t; + +// 32-bit integers +#ifdef _WIN32 + #ifdef _WIN64 + /// 32bit integer + typedef int int_t; + /// 32bit integer + typedef long long_t; + /// 32bit unsigned integer + typedef unsigned int uint_t; + /// 32bit unsigned long + typedef unsigned long ulong_t; + #else + /// 32bit integer + typedef int int_t; + /// 32bit integer + typedef long long_t; + /// 32bit unsigned integer + typedef unsigned int uint_t; + /// 32bit unsigned integer + typedef unsigned long ulong_t; + #endif +#else + /// 32bit integer + typedef int int_t; + /// 32bit integer + typedef int long_t; + /// 32bit unsigned integer + typedef unsigned int uint_t; + /// 32bit unsigned integer + typedef unsigned int ulong_t; +#endif + +// 64-bit integers; +/// 64bit; +typedef long long longlong_t; +/// 64bit unsigned long long +typedef unsigned long long ulonglong_t; +/// 64bit long long +typedef longlong_t ll_t; +/// 64bit unsigned long long +typedef ulonglong_t ull_t; + +// double and float +/// Float type +typedef float float_t; +/// Double type +typedef double double_t; + +// platform dependent integers (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) +#ifdef _WIN32 + /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) +// typedef int intptr_t; + /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) + typedef intptr_t longptr_t; + /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) +// typedef unsigned int uintptr_t; + /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) + typedef uintptr_t ulongptr_t; +#else + // linux and other + /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) +// typedef long intptr_t; + /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) + typedef intptr_t longptr_t; + /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) +// typedef unsigned long uintptr_t; + /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) + typedef uintptr_t ulongptr_t; +#endif + +// pointer +/// untyped pointer +typedef void* ptr_t; + +/// std::string or std::wstring dependent on _UNICODE macro +#ifdef _UNICODE + #define tstring std::wstring +#else + #define tstring std::string +#endif + +// formatting-related macros +// chars +/// Printf-style format string for displaying char_t value (as char) +#define CHARFMT _t("%c") +/// Printf-style format string for displaying uchar_t value (as char) +#define UCHARFMT CHARFMT + +// char related numbers (workaround for (u)chars - values are(should be) converted to (u)short_t) +/// Printf-style format string for displaying char_t as a number (the number has to be converted to short_t) +#define CFMT _t("%hd") +/// Printf-style format string for displaying char_t as a hexadecimal number (the number has to be converted to short_t) +#define CXFMT _t("0x%.2hx") +/// Printf-style format string for displaying uchar_t as a number (the number has to be converted to ushort_t) +#define UCFMT _t("%hu") +/// Printf-style format string for displaying uchar_t as a hexadecimal number (the number has to be converted to ushort_t) +#define UCXFMT CXFMT + +// numbers +// 16-bit +/// Printf-style format string for displaying short_t as a number +#define SFMT _t("%hd") +/// Printf-style format string for displaying short_t as a hex number +#define SXFMT _t("0x%.4hx") +/// Printf-style format string for displaying ushort_t as a number +#define USFMT _t("%hu") +/// Printf-style format string for displaying ushort_t as a hex number +#define USXFMT SXFMT + +// 32-bit +#ifdef _WIN32 + /// Printf-style format string for displaying long_t + #define LFMT _t("%ld") + /// Printf-style format string for displaying long_t as a hex number + #define LXFMT _t("0x%.8lx") + /// Printf-style format string for displaying ulong_t + #define ULFMT _t("%lu") +#else + /// Printf-style format string for displaying long_t + #define LFMT _t("%d") + /// Printf-style format string for displaying long_t as a hex number + #define LXFMT _t("0x%.8x") + /// Printf-style format string for displaying ulong_t + #define ULFMT _t("%u") +#endif + +/// Printf-style format string for displaying int_t +#define IFMT LFMT +/// Printf-style format string for displaying int_t as a hex number +#define IXFMT LXFMT +/// Printf-style format string for displaying uint_t +#define UIFMT ULFMT +/// Printf-style format string for displaying ulong_t as a hex number +#define ULXFMT LXFMT +/// Printf-style format string for displaying uint_t as a hex number +#define UIXFMT ULXFMT + +// 64-bit & system dependent +#ifdef _WIN32 + /// Printf-style format string for displaying ulonglong_t as a number + #define ULLFMT _t("%I64u") + /// Printf-style format string for displaying ulonglong_t as a hex number + #define ULLXFMT _t("0x%.16I64x") + /// Printf-style format string for displaying longlong_t + #define LLFMT _t("%I64d") + /// Printf-style format string for displaying longlong_t as a hex number + #define LLXFMT ULLXFMT + + #ifdef _WIN64 + /// Printf-style format string for displaying intptr_t + #define IPTRFMT LLFMT + /// Printf-style format string for displaying longptr_t + #define LPTRFMT LLFMT + /// Printf-style format string for displaying intptr_t as a hex number + #define IPTRXFMT LLXFMT + /// Printf-style format string for displaying longptr_t as a hex number + #define LPTRXFMT LLXFMT + /// Printf-style format string for displaying uintptr_t + #define UIPTRFMT ULLFMT + /// Printf-style format string for displaying ulongptr_t + #define ULPTRFMT ULLFMT + /// Printf-style format string for displaying uintptr_t as a hex number + #define UIPTRXFMT ULLXFMT + /// Printf-style format string for displaying ulongptr_t as a hex number + #define ULPTRXFMT ULLXFMT + #else + /// Printf-style format string for displaying intptr_t + #define IPTRFMT LFMT + /// Printf-style format string for displaying longptr_t + #define LPTRFMT LFMT + /// Printf-style format string for displaying intptr_t as a hex number + #define IPTRXFMT LXFMT + /// Printf-style format string for displaying longptr_t as a hex number + #define LPTRXFMT LXFMT + /// Printf-style format string for displaying uintptr_t + #define UIPTRFMT ULFMT + /// Printf-style format string for displaying ulongptr_t + #define ULPTRFMT ULFMT + /// Printf-style format string for displaying uintptr_t as a hex number + #define UIPTRXFMT ULXFMT + /// Printf-style format string for displaying ulongptr_t as a hex number + #define ULPTRXFMT ULXFMT + #endif +#else + /// Printf-style format string for displaying ulonglong_t as a number + #define ULLFMT _t("%llu") + /// Printf-style format string for displaying ulonglong_t as a hex number + #define ULLXFMT _t("0x%.16llx") + /// Printf-style format string for displaying longlong_t + #define LLFMT _t("%lld") + /// Printf-style format string for displaying longlong_t as a hex number + #define LLXFMT ULLXFMT + + // FIXME: distinguish between linux 32-bit architecture and 64-bit architecture here + /// Printf-style format string for displaying intptr_t + #define IPTRFMT _t("%ld") + /// Printf-style format string for displaying longptr_t + #define LPTRFMT IPTRFMT + /// Printf-style format string for displaying intptr_t as a hex number + #define IPTRXFMT _t("0x%.8lx") + /// Printf-style format string for displaying longptr_t as a hex number + #define LPTRXFMT IPTRXFMT + /// Printf-style format string for displaying uintptr_t + #define UIPTRFMT _t("%lu") + /// Printf-style format string for displaying ulongptr_t + #define ULPTRFMT UIPTRFMT + /// Printf-style format string for displaying uintptr_t as a hex number + #define UIPTRXFMT _t("0x%.8lx") + /// Printf-style format string for displaying ulongptr_t as a hex number + #define ULPTRXFMT UIPTRXFMT +#endif + +// double (not checked for linux) +/// Printf-style format string for displaying float_t +#define FLOATFMT _t("%.2f") +/// Printf-style format string for displaying double_t +#define DOUBLEFMT _t("%.2f") + +// strings + +// NOTE: below are the specifications for strings, however win32/64 specified the +// formatting strings to be dependent on the function used - %s used in printf +// formats an ascii string, while the same %s used in wprintf gives a wide string. +// So, basically, those macros should be modified in some way - either by making +// a dependence on _UNICODE define or by creating additional set of macros to be used +// with wprintf() and use the current ones for printf(). +#if defined(_WIN32) || defined(_WIN64) + #ifdef _UNICODE + /// Printf-style format string for displaying ansi strings (char_t based strings) + #define STRFMT _t("%S") + /// Printf-style format string for displaying ascii char + #define CHRFMT _t("%C") + /// Printf-style format string for displaying wide strings (wchar_t based strings) + #define WSTRFMT _t("%s") + /// Printf-style format string for displaying wide char + #define WCHRFMT _t("%c") + #else + /// Printf-style format string for displaying ansi strings (char_t based strings) + #define STRFMT _t("%s") + /// Printf-style format string for displaying ascii char + #define CHRFMT _t("%c") + /// Printf-style format string for displaying wide strings (wchar_t based strings) + #define WSTRFMT _t("%S") + /// Printf-style format string for displaying wide char + #define WCHRFMT _t("%C") + #endif +#else + /// Printf-style format string for displaying ansi strings (char_t based strings) + #define STRFMT _t("%s") + /// Printf-style format string for displaying ascii char + #define CHRFMT _t("%c") + /// Printf-style format string for displaying wide strings (wchar_t based strings) + #define WSTRFMT _t("%ls") + /// Printf-style format string for displaying wide char (WARNING: untested) + #define WCHRFMT _t("%lc") +#endif + +// pointer +/// Printf-style format string for displaying pointers +#define PTRFMT _t("%p") +/// Printf-style format string for displaying pointers (with 0x prefix) +#define PTRXFMT _t("0x%p") + +#endif Index: ext/libicpf/src/libicpf/gen_types.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/gen_types.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/gen_types.h (revision 0) @@ -1,341 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file gen_types.h - * \brief Contains some compile-time settings for the whole engine. - */ -#ifndef __GENTYPES_H__ -#define __GENTYPES_H__ - -#if defined(HAVE_CONFIG_H) - #include "config.h" -#endif - -#ifdef HAVE_INTTYPES_H - #include -#else - #include -#endif - -#if defined (_WIN32) || defined (_WIN64) - #include -#endif - -#include - -// standard types and formats used throughout the library -// exactly 1 byte -/// Byte type (8bit unsigned int) -typedef unsigned char byte_t; - -// chars -/// 8bit signed char -typedef char char_t; -/// 8bit unsigned char -typedef unsigned char uchar_t; - -// system/configuration dependent chars -#if (defined(_WIN32) || defined(_WIN64)) && defined(_UNICODE) - /// System/configuration dependent character (either wide char or normal one) - typedef wchar_t tchar_t; - typedef std::wstring tstring_t; - /// Macro to be appended to each text in code to be either composed of wide characters or normal ones - #define __t(text) L##text - #define _t(text) __t(text) - /// String formatting string - depending on configuration could display wide char string or normal one. - #define TSTRFMT WSTRFMT - #define TCHRFMT CHRFMT -#else - // description as above - typedef char_t tchar_t; - typedef std::string tstring_t; - #define _t(text) text - #define TSTRFMT STRFMT - #define TCHRFMT CHRFMT -#endif - -// 16-bit integers -/// 16bit short integer -typedef short short_t; -/// 16bit unsigned short integer -typedef unsigned short ushort_t; - -// 32-bit integers -#ifdef _WIN32 - #ifdef _WIN64 - /// 32bit integer - typedef int int_t; - /// 32bit integer - typedef long long_t; - /// 32bit unsigned integer - typedef unsigned int uint_t; - /// 32bit unsigned long - typedef unsigned long ulong_t; - #else - /// 32bit integer - typedef int int_t; - /// 32bit integer - typedef long long_t; - /// 32bit unsigned integer - typedef unsigned int uint_t; - /// 32bit unsigned integer - typedef unsigned long ulong_t; - #endif -#else - /// 32bit integer - typedef int int_t; - /// 32bit integer - typedef int long_t; - /// 32bit unsigned integer - typedef unsigned int uint_t; - /// 32bit unsigned integer - typedef unsigned int ulong_t; -#endif - -// 64-bit integers; -/// 64bit; -typedef long long longlong_t; -/// 64bit unsigned long long -typedef unsigned long long ulonglong_t; -/// 64bit long long -typedef longlong_t ll_t; -/// 64bit unsigned long long -typedef ulonglong_t ull_t; - -// double and float -/// Float type -typedef float float_t; -/// Double type -typedef double double_t; - -// platform dependent integers (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) -#ifdef _WIN32 - /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) -// typedef int intptr_t; - /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) - typedef intptr_t longptr_t; - /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) -// typedef unsigned int uintptr_t; - /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) - typedef uintptr_t ulongptr_t; -#else - // linux and other - /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) -// typedef long intptr_t; - /// platform-dependent size signed integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) - typedef intptr_t longptr_t; - /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) -// typedef unsigned long uintptr_t; - /// platform-dependent size unsigned integer (32-bit on 32-bit platforms, 64-bit on 64-bit platforms) - typedef uintptr_t ulongptr_t; -#endif - -// pointer -/// untyped pointer -typedef void* ptr_t; - -/// std::string or std::wstring dependent on _UNICODE macro -#ifdef _UNICODE - #define tstring std::wstring -#else - #define tstring std::string -#endif - -// formatting-related macros -// chars -/// Printf-style format string for displaying char_t value (as char) -#define CHARFMT _t("%c") -/// Printf-style format string for displaying uchar_t value (as char) -#define UCHARFMT CHARFMT - -// char related numbers (workaround for (u)chars - values are(should be) converted to (u)short_t) -/// Printf-style format string for displaying char_t as a number (the number has to be converted to short_t) -#define CFMT _t("%hd") -/// Printf-style format string for displaying char_t as a hexadecimal number (the number has to be converted to short_t) -#define CXFMT _t("0x%.2hx") -/// Printf-style format string for displaying uchar_t as a number (the number has to be converted to ushort_t) -#define UCFMT _t("%hu") -/// Printf-style format string for displaying uchar_t as a hexadecimal number (the number has to be converted to ushort_t) -#define UCXFMT CXFMT - -// numbers -// 16-bit -/// Printf-style format string for displaying short_t as a number -#define SFMT _t("%hd") -/// Printf-style format string for displaying short_t as a hex number -#define SXFMT _t("0x%.4hx") -/// Printf-style format string for displaying ushort_t as a number -#define USFMT _t("%hu") -/// Printf-style format string for displaying ushort_t as a hex number -#define USXFMT SXFMT - -// 32-bit -#ifdef _WIN32 - /// Printf-style format string for displaying long_t - #define LFMT _t("%ld") - /// Printf-style format string for displaying long_t as a hex number - #define LXFMT _t("0x%.8lx") - /// Printf-style format string for displaying ulong_t - #define ULFMT _t("%lu") -#else - /// Printf-style format string for displaying long_t - #define LFMT _t("%d") - /// Printf-style format string for displaying long_t as a hex number - #define LXFMT _t("0x%.8x") - /// Printf-style format string for displaying ulong_t - #define ULFMT _t("%u") -#endif - -/// Printf-style format string for displaying int_t -#define IFMT LFMT -/// Printf-style format string for displaying int_t as a hex number -#define IXFMT LXFMT -/// Printf-style format string for displaying uint_t -#define UIFMT ULFMT -/// Printf-style format string for displaying ulong_t as a hex number -#define ULXFMT LXFMT -/// Printf-style format string for displaying uint_t as a hex number -#define UIXFMT ULXFMT - -// 64-bit & system dependent -#ifdef _WIN32 - /// Printf-style format string for displaying ulonglong_t as a number - #define ULLFMT _t("%I64u") - /// Printf-style format string for displaying ulonglong_t as a hex number - #define ULLXFMT _t("0x%.16I64x") - /// Printf-style format string for displaying longlong_t - #define LLFMT _t("%I64d") - /// Printf-style format string for displaying longlong_t as a hex number - #define LLXFMT ULLXFMT - - #ifdef _WIN64 - /// Printf-style format string for displaying intptr_t - #define IPTRFMT LLFMT - /// Printf-style format string for displaying longptr_t - #define LPTRFMT LLFMT - /// Printf-style format string for displaying intptr_t as a hex number - #define IPTRXFMT LLXFMT - /// Printf-style format string for displaying longptr_t as a hex number - #define LPTRXFMT LLXFMT - /// Printf-style format string for displaying uintptr_t - #define UIPTRFMT ULLFMT - /// Printf-style format string for displaying ulongptr_t - #define ULPTRFMT ULLFMT - /// Printf-style format string for displaying uintptr_t as a hex number - #define UIPTRXFMT ULLXFMT - /// Printf-style format string for displaying ulongptr_t as a hex number - #define ULPTRXFMT ULLXFMT - #else - /// Printf-style format string for displaying intptr_t - #define IPTRFMT LFMT - /// Printf-style format string for displaying longptr_t - #define LPTRFMT LFMT - /// Printf-style format string for displaying intptr_t as a hex number - #define IPTRXFMT LXFMT - /// Printf-style format string for displaying longptr_t as a hex number - #define LPTRXFMT LXFMT - /// Printf-style format string for displaying uintptr_t - #define UIPTRFMT ULFMT - /// Printf-style format string for displaying ulongptr_t - #define ULPTRFMT ULFMT - /// Printf-style format string for displaying uintptr_t as a hex number - #define UIPTRXFMT ULXFMT - /// Printf-style format string for displaying ulongptr_t as a hex number - #define ULPTRXFMT ULXFMT - #endif -#else - /// Printf-style format string for displaying ulonglong_t as a number - #define ULLFMT _t("%llu") - /// Printf-style format string for displaying ulonglong_t as a hex number - #define ULLXFMT _t("0x%.16llx") - /// Printf-style format string for displaying longlong_t - #define LLFMT _t("%lld") - /// Printf-style format string for displaying longlong_t as a hex number - #define LLXFMT ULLXFMT - - // FIXME: distinguish between linux 32-bit architecture and 64-bit architecture here - /// Printf-style format string for displaying intptr_t - #define IPTRFMT _t("%ld") - /// Printf-style format string for displaying longptr_t - #define LPTRFMT IPTRFMT - /// Printf-style format string for displaying intptr_t as a hex number - #define IPTRXFMT _t("0x%.8lx") - /// Printf-style format string for displaying longptr_t as a hex number - #define LPTRXFMT IPTRXFMT - /// Printf-style format string for displaying uintptr_t - #define UIPTRFMT _t("%lu") - /// Printf-style format string for displaying ulongptr_t - #define ULPTRFMT UIPTRFMT - /// Printf-style format string for displaying uintptr_t as a hex number - #define UIPTRXFMT _t("0x%.8lx") - /// Printf-style format string for displaying ulongptr_t as a hex number - #define ULPTRXFMT UIPTRXFMT -#endif - -// double (not checked for linux) -/// Printf-style format string for displaying float_t -#define FLOATFMT _t("%.2f") -/// Printf-style format string for displaying double_t -#define DOUBLEFMT _t("%.2f") - -// strings - -// NOTE: below are the specifications for strings, however win32/64 specified the -// formatting strings to be dependent on the function used - %s used in printf -// formats an ascii string, while the same %s used in wprintf gives a wide string. -// So, basically, those macros should be modified in some way - either by making -// a dependence on _UNICODE define or by creating additional set of macros to be used -// with wprintf() and use the current ones for printf(). -#if defined(_WIN32) || defined(_WIN64) - #ifdef _UNICODE - /// Printf-style format string for displaying ansi strings (char_t based strings) - #define STRFMT _t("%S") - /// Printf-style format string for displaying ascii char - #define CHRFMT _t("%C") - /// Printf-style format string for displaying wide strings (wchar_t based strings) - #define WSTRFMT _t("%s") - /// Printf-style format string for displaying wide char - #define WCHRFMT _t("%c") - #else - /// Printf-style format string for displaying ansi strings (char_t based strings) - #define STRFMT _t("%s") - /// Printf-style format string for displaying ascii char - #define CHRFMT _t("%c") - /// Printf-style format string for displaying wide strings (wchar_t based strings) - #define WSTRFMT _t("%S") - /// Printf-style format string for displaying wide char - #define WCHRFMT _t("%C") - #endif -#else - /// Printf-style format string for displaying ansi strings (char_t based strings) - #define STRFMT _t("%s") - /// Printf-style format string for displaying ascii char - #define CHRFMT _t("%c") - /// Printf-style format string for displaying wide strings (wchar_t based strings) - #define WSTRFMT _t("%ls") - /// Printf-style format string for displaying wide char (WARNING: untested) - #define WCHRFMT _t("%lc") -#endif - -// pointer -/// Printf-style format string for displaying pointers -#define PTRFMT _t("%p") -/// Printf-style format string for displaying pointers (with 0x prefix) -#define PTRXFMT _t("0x%p") - -#endif Index: src/libicpf/interface.h =================================================================== diff -u -N --- src/libicpf/interface.h (revision 0) +++ src/libicpf/interface.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * 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 Library 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. * + ***************************************************************************/ +#ifndef __INTERFACE_H__ +#define __INTERFACE_H__ + +#include "libicpf.h" + +BEGIN_ICPF_NAMESPACE + +class IInterface +{ +public: + virtual void Delete() = 0; +}; + +END_ICPF_NAMESPACE + +#endif \ No newline at end of file Index: ext/libicpf/src/libicpf/interface.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/interface.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/interface.h (revision 0) @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * 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 Library 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. * - ***************************************************************************/ -#ifndef __INTERFACE_H__ -#define __INTERFACE_H__ - -#include "libicpf.h" - -BEGIN_ICPF_NAMESPACE - -class IInterface -{ -public: - virtual void Delete() = 0; -}; - -END_ICPF_NAMESPACE - -#endif \ No newline at end of file Index: src/libicpf/libicpf.cpp =================================================================== diff -u -N --- src/libicpf/libicpf.cpp (revision 0) +++ src/libicpf/libicpf.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,40 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +// libicpf.cpp : Defines the entry point for the DLL application. +// + +#ifdef _WIN32 +#include + +BOOL APIENTRY DllMain( HANDLE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + default: + break; + } + return TRUE; +} + +#endif Index: ext/libicpf/src/libicpf/libicpf.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/libicpf.cpp (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/libicpf.cpp (revision 0) @@ -1,40 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -// libicpf.cpp : Defines the entry point for the DLL application. -// - -#ifdef _WIN32 -#include - -BOOL APIENTRY DllMain( HANDLE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - default: - break; - } - return TRUE; -} - -#endif Index: src/libicpf/libicpf.h =================================================================== diff -u -N --- src/libicpf/libicpf.h (revision 0) +++ src/libicpf/libicpf.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,87 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __LIBICPF_H__ +#define __LIBICPF_H__ + +/** \brief Allows unicode handling throughout the files + * + * It means that the engine would process fs object's paths + * in the better standard - if possible then with current ANSI code page (one-byte + * chars) or with UNICODE strings (with 2-byte per char strings). + * \note if this is disabled (#undef) then the data saved by ie. unicode windows + * system may not be readable (because we won't use the iconv package on linux + * systems nor use any of the unicode functions in windows systems). + * Recommended setting is 'defined'. + */ +#define ALLOW_UNICODE + +/** \brief Enables the mutex debugging code throughout this library. + * + * Enables compiling the d_mutex class, so external or internal code could use mutex + * debugging. + */ +//#define ENABLE_MUTEX_DEBUGGING + +/** \brief Enables mutex debugging/tracking in the internal and external code. + */ +//#define DEBUG_MUTEX + +/** \brief Enables use of encryption throughout this library. + * + * Enabling this macro enables usage of the encryption in some modules. + */ +#define USE_ENCRYPTION + +// import/export macros +#ifdef _WIN32 +#ifdef LIBICPF_EXPORTS + /** \brief Import/export macros + * + * These macros are being used throughout the whole code. They are meant to + * export symbols (if the LIBICPF_EXPORTS is defined) from this library + * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). + */ + #define LIBICPF_API __declspec(dllexport) + #define ICPFTEMPL_EXTERN +#else + /** \brief Import/export macros + * + * These macros are being used throughout the whole code. They are meant to + * export symbols (if the LIBICPF_EXPORTS is defined) from this library + * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). + */ + #define LIBICPF_API __declspec(dllimport) + #define ICPFTEMPL_EXTERN extern +#endif +#else + /** \brief Import/export macros + * + * These macros are being used throughout the whole code. They are meant to + * export symbols (if the LIBICPF_EXPORTS is defined) from this library + * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). + */ + #define LIBICPF_API +#endif + +/// Begins ch namespace +#define BEGIN_ICPF_NAMESPACE namespace icpf { +/// Ends ch namespace +#define END_ICPF_NAMESPACE } + +#endif Index: ext/libicpf/src/libicpf/libicpf.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/libicpf.h (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/libicpf.h (revision 0) @@ -1,87 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __LIBICPF_H__ -#define __LIBICPF_H__ - -/** \brief Allows unicode handling throughout the files - * - * It means that the engine would process fs object's paths - * in the better standard - if possible then with current ANSI code page (one-byte - * chars) or with UNICODE strings (with 2-byte per char strings). - * \note if this is disabled (#undef) then the data saved by ie. unicode windows - * system may not be readable (because we won't use the iconv package on linux - * systems nor use any of the unicode functions in windows systems). - * Recommended setting is 'defined'. - */ -#define ALLOW_UNICODE - -/** \brief Enables the mutex debugging code throughout this library. - * - * Enables compiling the d_mutex class, so external or internal code could use mutex - * debugging. - */ -//#define ENABLE_MUTEX_DEBUGGING - -/** \brief Enables mutex debugging/tracking in the internal and external code. - */ -//#define DEBUG_MUTEX - -/** \brief Enables use of encryption throughout this library. - * - * Enabling this macro enables usage of the encryption in some modules. - */ -#define USE_ENCRYPTION - -// import/export macros -#ifdef _WIN32 -#ifdef LIBICPF_EXPORTS - /** \brief Import/export macros - * - * These macros are being used throughout the whole code. They are meant to - * export symbols (if the LIBICPF_EXPORTS is defined) from this library - * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). - */ - #define LIBICPF_API __declspec(dllexport) - #define ICPFTEMPL_EXTERN -#else - /** \brief Import/export macros - * - * These macros are being used throughout the whole code. They are meant to - * export symbols (if the LIBICPF_EXPORTS is defined) from this library - * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). - */ - #define LIBICPF_API __declspec(dllimport) - #define ICPFTEMPL_EXTERN extern -#endif -#else - /** \brief Import/export macros - * - * These macros are being used throughout the whole code. They are meant to - * export symbols (if the LIBICPF_EXPORTS is defined) from this library - * (also for importing (when LIBICPF_EXPORTS macro is undefined) in other apps). - */ - #define LIBICPF_API -#endif - -/// Begins ch namespace -#define BEGIN_ICPF_NAMESPACE namespace icpf { -/// Ends ch namespace -#define END_ICPF_NAMESPACE } - -#endif Index: src/libicpf/libicpf.vc140.vcxproj =================================================================== diff -u -N --- src/libicpf/libicpf.vc140.vcxproj (revision 0) +++ src/libicpf/libicpf.vc140.vcxproj (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,552 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + Testing Debug + Win32 + + + Testing Debug + x64 + + + Testing Release + Win32 + + + Testing Release + x64 + + + + libicpf + {5510B933-046F-4F75-8B46-5E8279C8CCDE} + libicpf + Win32Proj + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + DynamicLibrary + v120_xp + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.51106.1 + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + true + $(ProjectName)32ud + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + true + $(ProjectName)32ud + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + true + $(ProjectName)64ud + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + true + $(ProjectName)64ud + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + false + $(ProjectName)32u + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + false + $(ProjectName)32u + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + false + $(ProjectName)64u + + + $(SolutionDir)bin\$(Configuration)\ + $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ + false + $(ProjectName)64u + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + + Level4 + true + EditAndContinue + true + + + true + Windows + MachineX86 + false + "$(OutDir)" + + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + + + Level4 + true + EditAndContinue + true + ..\..\ext\gmock\include + + + true + Windows + MachineX86 + false + gmock32d.lib;%(AdditionalDependencies) + "$(OutDir)" + + + cd "$(TargetDir)" + +if "$(PlatformName)" EQU "x64" goto x64 + +if "$(Configuration)" EQU "Testing Release" goto x32rel + +:x32dbg +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x32rel +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x64 +if "$(Configuration)" EQU "Testing Release" goto x64rel + +:x64dbg +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:x64rel +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:end + + + + + + X64 + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + + Level4 + true + ProgramDatabase + true + + + true + Windows + MachineX64 + false + "$(OutDir)" + + + + + X64 + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + true + true + + + Level4 + true + ProgramDatabase + true + ..\..\ext\gmock\include + + + true + Windows + MachineX64 + false + gmock64d.lib;%(AdditionalDependencies) + "$(OutDir)" + + + cd "$(TargetDir)" + +if "$(PlatformName)" EQU "x64" goto x64 + +if "$(Configuration)" EQU "Testing Release" goto x32rel + +:x32dbg +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x32rel +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x64 +if "$(Configuration)" EQU "Testing Release" goto x64rel + +:x64dbg +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:x64rel +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:end + + + + + + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) + MultiThreadedDLL + true + true + + Level4 + true + ProgramDatabase + true + + + true + Windows + true + true + MachineX86 + false + "$(OutDir)" + + + + + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) + MultiThreadedDLL + true + true + + + Level4 + true + ProgramDatabase + true + ..\..\ext\gmock\include + + + true + Windows + true + true + MachineX86 + false + gmock32.lib;%(AdditionalDependencies) + "$(OutDir)" + + + cd "$(TargetDir)" + +if "$(PlatformName)" EQU "x64" goto x64 + +if "$(Configuration)" EQU "Testing Release" goto x32rel + +:x32dbg +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x32rel +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x64 +if "$(Configuration)" EQU "Testing Release" goto x64rel + +:x64dbg +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:x64rel +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:end + + + + + + X64 + + + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) + MultiThreadedDLL + true + true + + Level4 + true + ProgramDatabase + true + + + true + Windows + true + true + MachineX64 + false + "$(OutDir)" + + + + + X64 + + + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) + MultiThreadedDLL + true + true + + + Level4 + true + ProgramDatabase + true + ..\..\ext\gmock\include + + + true + Windows + true + true + MachineX64 + false + gmock64.lib;%(AdditionalDependencies) + "$(OutDir)" + + + cd "$(TargetDir)" + +if "$(PlatformName)" EQU "x64" goto x64 + +if "$(Configuration)" EQU "Testing Release" goto x32rel + +:x32dbg +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x32rel +"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" +goto end + +:x64 +if "$(Configuration)" EQU "Testing Release" goto x64rel + +:x64dbg +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:x64rel +"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" +goto end + +:end + + + + + + true + true + true + true + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: ext/libicpf/src/libicpf/libicpf.vc140.vcxproj =================================================================== diff -u -N --- ext/libicpf/src/libicpf/libicpf.vc140.vcxproj (revision cd028982a09295817777ee479e4b2161b02b953a) +++ ext/libicpf/src/libicpf/libicpf.vc140.vcxproj (revision 0) @@ -1,552 +0,0 @@ - - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - Testing Debug - Win32 - - - Testing Debug - x64 - - - Testing Release - Win32 - - - Testing Release - x64 - - - - libicpf - {5510B933-046F-4F75-8B46-5E8279C8CCDE} - libicpf - Win32Proj - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - DynamicLibrary - v120_xp - Unicode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>11.0.51106.1 - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)32ud - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)32ud - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)64ud - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - true - $(ProjectName)64ud - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)32u - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)32u - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)64u - - - $(SolutionDir)bin\$(Configuration)\ - $(SolutionDir)intermediate\$(PlatformToolset)\$(Platform)\$(ProjectName)_$(Configuration)\ - false - $(ProjectName)64u - - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - - Level4 - true - EditAndContinue - true - - - true - Windows - MachineX86 - false - "$(OutDir)" - - - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - - - Level4 - true - EditAndContinue - true - ..\..\ext\gmock\include - - - true - Windows - MachineX86 - false - gmock32d.lib;%(AdditionalDependencies) - "$(OutDir)" - - - cd "$(TargetDir)" - -if "$(PlatformName)" EQU "x64" goto x64 - -if "$(Configuration)" EQU "Testing Release" goto x32rel - -:x32dbg -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x32rel -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x64 -if "$(Configuration)" EQU "Testing Release" goto x64rel - -:x64dbg -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:x64rel -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:end - - - - - - X64 - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - - Level4 - true - ProgramDatabase - true - - - true - Windows - MachineX64 - false - "$(OutDir)" - - - - - X64 - - - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - true - true - - - Level4 - true - ProgramDatabase - true - ..\..\ext\gmock\include - - - true - Windows - MachineX64 - false - gmock64d.lib;%(AdditionalDependencies) - "$(OutDir)" - - - cd "$(TargetDir)" - -if "$(PlatformName)" EQU "x64" goto x64 - -if "$(Configuration)" EQU "Testing Release" goto x32rel - -:x32dbg -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x32rel -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x64 -if "$(Configuration)" EQU "Testing Release" goto x64rel - -:x64dbg -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:x64rel -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:end - - - - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - MultiThreadedDLL - true - true - - Level4 - true - ProgramDatabase - true - - - true - Windows - true - true - MachineX86 - false - "$(OutDir)" - - - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) - MultiThreadedDLL - true - true - - - Level4 - true - ProgramDatabase - true - ..\..\ext\gmock\include - - - true - Windows - true - true - MachineX86 - false - gmock32.lib;%(AdditionalDependencies) - "$(OutDir)" - - - cd "$(TargetDir)" - -if "$(PlatformName)" EQU "x64" goto x64 - -if "$(Configuration)" EQU "Testing Release" goto x32rel - -:x32dbg -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x32rel -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x64 -if "$(Configuration)" EQU "Testing Release" goto x64rel - -:x64dbg -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:x64rel -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:end - - - - - - X64 - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;%(PreprocessorDefinitions) - MultiThreadedDLL - true - true - - Level4 - true - ProgramDatabase - true - - - true - Windows - true - true - MachineX64 - false - "$(OutDir)" - - - - - X64 - - - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBICPF_EXPORTS;XML_UNICODE_WCHAR_T;_CRT_SECURE_NO_DEPRECATE;_BIND_TO_CURRENT_VCLIBS_VERSION=1;TESTING;%(PreprocessorDefinitions) - MultiThreadedDLL - true - true - - - Level4 - true - ProgramDatabase - true - ..\..\ext\gmock\include - - - true - Windows - true - true - MachineX64 - false - gmock64.lib;%(AdditionalDependencies) - "$(OutDir)" - - - cd "$(TargetDir)" - -if "$(PlatformName)" EQU "x64" goto x64 - -if "$(Configuration)" EQU "Testing Release" goto x32rel - -:x32dbg -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x32rel -"$(SolutionDir)tools\test_runner32.exe" "$(TargetPath)" -goto end - -:x64 -if "$(Configuration)" EQU "Testing Release" goto x64rel - -:x64dbg -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:x64rel -"$(SolutionDir)tools\test_runner64.exe" "$(TargetPath)" -goto end - -:end - - - - - - true - true - true - true - NotUsing - NotUsing - NotUsing - NotUsing - NotUsing - NotUsing - NotUsing - NotUsing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file Index: src/libicpf/libicpf.vc140.vcxproj.filters =================================================================== diff -u -N --- src/libicpf/libicpf.vc140.vcxproj.filters (revision 0) +++ src/libicpf/libicpf.vc140.vcxproj.filters (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,147 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx + + + {1aeeb066-f476-4523-998a-99f735525d2f} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Tests + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file Index: ext/libicpf/src/libicpf/libicpf.vc140.vcxproj.filters =================================================================== diff -u -N --- ext/libicpf/src/libicpf/libicpf.vc140.vcxproj.filters (revision d25e295cbabb9a85970a2ad5ec5de76bea1e404a) +++ ext/libicpf/src/libicpf/libicpf.vc140.vcxproj.filters (revision 0) @@ -1,147 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx - - - {1aeeb066-f476-4523-998a-99f735525d2f} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Tests - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file Index: src/libicpf/log.cpp =================================================================== diff -u -N --- src/libicpf/log.cpp (revision 0) +++ src/libicpf/log.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,685 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file log.cpp + * \brief Contains the implamentation of a log class. + */ +#include "log.h" +#include +#include "exception.h" +#include +#include +#include +#include +#include "macros.h" + +#if defined(_WIN32) || defined(_WIN64) + #include + #include + #include +#else + #include +#endif + +#if defined(_WIN32) || defined(_WIN64) + #define ENDL _t("\r\n") +#else + #define ENDL _t("\n") +#endif + +BEGIN_ICPF_NAMESPACE + +/// Table of strings representing the log message types +const tchar_t* __logtype_str[] = { _t("debug"), _t("info"), _t("warning"), _t("error") }; + +/** Constructs a log_file object. + * \param[in] bGlobal - states if this should be treates as a global instance of the log_file. + * Only one global log_file instance could exist in the application. + */ +log_file::log_file() : + m_pszPath(NULL), + m_iMaxSize(262144), + m_bLogStd(false), + m_iLogLevel(level_debug), + m_lock() +{ +#ifdef WIN32 + _fmode=_O_BINARY; +#endif +} + +/** Standard destructor + */ +log_file::~log_file() +{ + delete [] m_pszPath; +} + +/** Initializes the constructed log file. + * \param[in] pszPath - path to a log file to write to + * \param[in] iMaxSize - maximum size of a log file + * \param[in] iLogLevel - minimum log level of the messages to log + * \param[in] bLogStd - log the messages also to stdout/stderr + * \param[in] bClean - cleans the log file upon opening + */ +void log_file::init(const tchar_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean) +{ + // store the path and other params + delete [] m_pszPath; + m_pszPath=new tchar_t[_tcslen(pszPath)+1]; + _tcscpy(m_pszPath, pszPath); + + m_iMaxSize=iMaxSize; + m_bLogStd=bLogStd; + m_iLogLevel=iLogLevel; + + // try to open a file + FILE* pFile=_tfopen(pszPath, bClean ? _t("w") : _t("a")); + if (pFile == NULL) + THROW(exception::format(_t("[log_file::init()] Could not open the specified file (") TSTRFMT _t(")")), 0, 0, 0); + + fclose(pFile); +} + +// ============================================================================ +/// icpf::log_file::is_initialized +/// @date 2009/05/19 +/// +/// @brief Checks is the log_file object has been initialized. +/// @return True if it has been initialized, false otherwise. +// ============================================================================ +bool log_file::is_initialized() const throw() +{ + return m_pszPath != 0; +} + +// ============================================================================ +/// icpf::log_file::set_log_level +/// @date 2009/05/23 +/// +/// @brief Changes the log level for this class. +/// @param[in] iLogLevel New log level. +// ============================================================================ +void log_file::set_log_level(int_t iLogLevel) throw() +{ + m_iLogLevel = iLogLevel; +} + +// ============================================================================ +/// icpf::log_file::set_max_size +/// @date 2009/05/23 +/// +/// @brief Sets the max size of the log file. +/// @param[in] iMaxSize Max size of the log file. +// ============================================================================ +void log_file::set_max_size(int_t iMaxSize) throw() +{ + BOOST_ASSERT(iMaxSize > 0); + if(iMaxSize > 0) + m_iMaxSize = iMaxSize; +} + +/** Retrieves the current size of a log file. + * Quite slow function - have to access the file by opening and closing it. + * \return Current file size. + */ +int_t log_file::size() const +{ + assert(m_pszPath); + if(!m_pszPath) + return -1; + + int_t iSize=-1; + FILE* pFile=_tfopen(m_pszPath, _t("r")); + if (pFile != NULL) + { + if (fseek(pFile, 0, SEEK_END) == 0) + iSize=ftell(pFile); + + fclose(pFile); + } + + return iSize; +} + +/** Truncates the current log file content so when adding some new text the + * file size won't exceed the maximum size specified in init(). + * \param[in] iAdd - size of the new string to be added to the log file + * \return True if truncate succeeded or false if not. + */ +bool log_file::truncate(int_t iAdd) const +{ + assert(m_pszPath); + if(!m_pszPath) + return false; + + // if we doesn't need to truncate anything + if (m_iMaxSize <= 0) + return true; + + // make some checks + int_t iSize=size(); + if (iSize <= 0 || iSize+iAdd < m_iMaxSize) + return false; + + // establish the new file size (1/3rd of the current size or max_size-add_size) + int_t iNewSize=minval((int_t)(iSize*0.66), m_iMaxSize-iAdd) & ~1; + +#ifdef _WIN32 + // win32 does not have the ftruncate function, so we have to make some API calls + HANDLE hFile=CreateFile(m_pszPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + // seek + if (SetFilePointer(hFile, iSize-iNewSize, NULL, FILE_BEGIN) != INVALID_SET_FILE_POINTER) + { + // read the string to the eol + DWORD dwRD; + tchar_t szBuffer[4096/sizeof(tchar_t)]; + if (ReadFile(hFile, szBuffer, 4096, &dwRD, NULL)) + { + dwRD/=sizeof(tchar_t); + szBuffer[(dwRD > 0) ? dwRD-1 : 0]=_t('\0'); + + // replace the /r and /n in the log to the \0 + for (DWORD i=0;i 0) + { + // seek to the dst + fseek(pFile, iDst, SEEK_SET); + + fflush(pFile); + // write the buffer to the dest offset + tWR=fwrite(szBuffer, 1, tRD, pFile); + iDst+=tWR; + } + + iSrc+=tRD; + } + while(tRD != 0); + + // now truncate the file to the needed size + ftruncate(fileno(pFile), iDst); + + fclose(pFile); + return true; + } + + fclose(pFile); + } +#endif + + return false; +} + +/** Logs a formatted message to a log file. + * \param[in] iType - type of the log message (LT_*) + * \param[in] bStd - log also to stdout/stderr if true + * \param[in] pszStr - format string for the following parameters + */ +void log_file::log(int_t iType, bool bStd, const tchar_t* pszStr, ...) +{ + if (iType < m_iLogLevel) + return; + + va_list va; + va_start(va, pszStr); + logv(iType, bStd, pszStr, va); + va_end(va); +} + +/** Logs a formatted message to a log file. + * \param[in] iType - type of the log message (LT_*) + * \param[in] bStd - log also to stdout/stderr if true + * \param[in] pszStr - format string for the following parameters + * \param[in] va - variable argument list + */ +void log_file::logv(int_t iType, bool bStd, const tchar_t* pszStr, va_list va) +{ + if (iType < m_iLogLevel) + return; + + tchar_t szBuf1[2048]; + _vsntprintf(szBuf1, 2048, pszStr, va); // user passed stuff + + logs(iType, bStd, szBuf1); +} + +/** Logs an unformatted message to a log file. + * \param[in] iType - type of the log message (LT_*) + * \param[in] bStd - log also to stdout/stderr if true + * \param[in] pszStr - message string + */ +void log_file::logs(int_t iType, bool bStd, const tchar_t* pszStr) +{ + assert(m_pszPath); + if(!m_pszPath) + return; + + if (iType < m_iLogLevel || iType < 0 || iType >= sizeof(__logtype_str)) + return; + + // log time + time_t t=time(NULL); + tchar_t szData[128]; + _tcscpy(szData, _tctime(&t)); + size_t tLen=_tcslen(szData)-1; + while(szData[tLen] == _t('\n')) + szData[tLen--]=_t('\0'); + + m_lock.lock(); + + // check the size constraints + truncate((int_t)(_tcslen(pszStr)+1)); +#if defined(UNICODE) && (defined(_WIN32) || defined(_WIN64)) + FILE* pFile=_tfopen(m_pszPath, _t("ab")); +#else + FILE* pFile=_tfopen(m_pszPath, _t("at")); +#endif + bool bFailed=false; + if (pFile) + { + if (_ftprintf(pFile, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr) < 0) + bFailed=true; + fclose(pFile); + } + else + bFailed=true; + if (bFailed || (m_bLogStd && !bStd)) + { + switch(iType) + { + case level_error: + _ftprintf(stderr, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr); + break; + default: + _ftprintf(stdout, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr); + } + } + else if (bStd) + { + switch(iType) + { + case level_error: + _ftprintf(stderr, TSTRFMT _t(": ") TSTRFMT ENDL, __logtype_str[iType], pszStr); + break; + case level_info: + _ftprintf(stdout, TSTRFMT ENDL, pszStr); + break; + default: + _ftprintf(stdout, TSTRFMT _t(": ") TSTRFMT ENDL, __logtype_str[iType], pszStr); + } + } + + m_lock.unlock(); +} + +#ifndef SKIP_LEVEL_DEBUG +/** Logs a formatted debug message to a log file. + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logd(const tchar_t* pszStr) +{ + if (m_iLogLevel > level_debug) + return; + + logs(level_debug, false, pszStr); +} + +/** Logs a formatted debug message to a log file. +* \param[in] pszStr - format string for the given parameters +*/ +void log_file::logdv(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_debug) + return; + + va_list va; + va_start(va, pszStr); + logv(level_debug, false, pszStr, va); + va_end(va); +} + +/** Logs a formatted debug message to a log file(also outputs to stdout). + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logds(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_debug) + return; + + va_list va; + va_start(va, pszStr); + logv(level_debug, true, pszStr, va); + va_end(va); +} + +#else +void log_file::logd(const tchar_t* /*pszStr*/) +{ +} + +void log_file::logdv(const tchar_t* /*pszStr*/, ...) +{ +} + +void log_file::logds(const tchar_t* /*pszStr*/, ...) +{ +} +#endif + +#ifndef SKIP_LEVEL_INFO +/** Logs a formatted informational message to a log file. + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logi(const tchar_t* pszStr) +{ + if (m_iLogLevel > level_info) + return; + + logs(level_info, false, pszStr); +} + +/** Logs a formatted informational message to a log file. +* \param[in] pszStr - format string for the given parameters +*/ +void log_file::logiv(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_info) + return; + + va_list va; + va_start(va, pszStr); + logv(level_info, false, pszStr, va); + va_end(va); +} + +/** Logs a formatted informational message to a log file(also outputs to stdout). + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logis(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_info) + return; + + va_list va; + va_start(va, pszStr); + logv(level_info, true, pszStr, va); + va_end(va); +} +#else +void log_file::logi(const tchar_t* /*pszStr*/) +{ +} + +void log_file::logiv(const tchar_t* /*pszStr*/, ...) +{ +} + +void log_file::logis(const tchar_t* /*pszStr*/, ...) +{ +} + +#endif + +#ifndef SKIP_LEVEL_WARNING +/** Logs a formatted warning message to a log file. + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logw(const tchar_t* pszStr) +{ + if (m_iLogLevel > level_warning) + return; + + logs(level_warning, false, pszStr); +} + +/** Logs a formatted warning message to a log file. +* \param[in] pszStr - format string for the given parameters +*/ +void log_file::logwv(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_warning) + return; + + va_list va; + va_start(va, pszStr); + logv(level_warning, false, pszStr, va); + va_end(va); +} + +/** Logs a formatted warning message to a log file(also outputs to stdout). + * \param[in] pszStr - format string for the given parameters + */ +void log_file::logws(const tchar_t* pszStr, ...) +{ + if (m_iLogLevel > level_warning) + return; + va_list va; + va_start(va, pszStr); + logv(level_warning, true, pszStr, va); + va_end(va); +} + +#else +void log_file::logw(const tchar_t* /*pszStr*/) +{ +} + +void log_file::logwv(const tchar_t* /*pszStr*/, ...) +{ +} + +void log_file::logws(const tchar_t* /*pszStr*/, ...) +{ +} + +#endif + +/** Logs a formatted error message to a log file. + * \param[in] pszStr - format string for the given parameters + */ +void log_file::loge(const tchar_t* pszStr) +{ + logs(level_error, false, pszStr); +} + +/** Logs a formatted error message to a log file. +* \param[in] pszStr - format string for the given parameters +*/ +void log_file::logev(const tchar_t* pszStr, ...) +{ + va_list va; + va_start(va, pszStr); + logv(level_error, false, pszStr, va); + va_end(va); +} + +/** Logs a formatted error message to a log file(also outputs to stderr). + * \param[in] pszStr - format string for the given parameters + */ +void log_file::loges(const tchar_t* pszStr, ...) +{ + va_list va; + va_start(va, pszStr); + logv(level_error, true, pszStr, va); + va_end(va); +} + +/** Logs a formatted error message to a log file(also outputs to stderr). + * As an addition the first string %err is replaced with a given error + * followed by the error description (system-based). + * \param[in] pszStr - format string for the given parameters + * \param[in] iSysErr - system error to be shown + */ +void log_file::logerr(const tchar_t* pszStr, int_t iSysErr, ...) +{ + tchar_t szNewFmt[2048]; + if (prepare_fmt(pszStr, iSysErr, szNewFmt)) + { + va_list va; + va_start(va, iSysErr); + logv(level_error, false, szNewFmt, va); + va_end(va); + } + else + { + va_list va; + va_start(va, iSysErr); + logv(level_error, false, pszStr, va); + va_end(va); + } +} + +/** Logs a formatted error message to a log file(also outputs to stderr). + * As an addition the first string %err is replaced with a given error + * followed by the error description (system-based). + * This function differ from logerr() with logging the output string + * also to the stderr. + * \param[in] pszStr - format string for the given parameters + * \param[in] iSysErr - system error to be shown + */ +void log_file::logerrs(const tchar_t* pszStr, int_t iSysErr, ...) +{ + tchar_t szNewFmt[2048]; + if (prepare_fmt(pszStr, iSysErr, szNewFmt)) + { + va_list va; + va_start(va, iSysErr); + logv(level_error, true, szNewFmt, va); + va_end(va); + } + else + { + va_list va; + va_start(va, iSysErr); + logv(level_error, true, pszStr, va); + va_end(va); + } +} + +/** Function prepares a format string with error number and an error message + * for use with logerr() and logerrs() functions. + * \param[in] pszStr - input format string (%err will be replaced with a 0x%lx (error message) + * \param[in] iSysError - system error to parse + * \param[out] pszOut - pointer to a buffer that will receive the data (must be 2048 bytes in size) + * \return If the %err string was found and replaced within a given format string. + */ +bool log_file::prepare_fmt(const tchar_t* pszStr, int_t iSysErr, tchar_t* pszOut) const +{ + // find the %err in pszStr + const tchar_t* pszFnd=_tcsstr(pszStr, _t("%err")); + if (pszFnd) + { + // find an error description for the error + tchar_t* pszErrDesc=NULL; +#ifdef _WIN32 + tchar_t szErrDesc[512]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD)iSysErr, 0, szErrDesc, 512, NULL); + pszErrDesc=szErrDesc; +#else + pszErrDesc=strerror(iSysErr); +#endif + + // format a string with err no and desc + tchar_t szError[1024]; + _sntprintf(szError, 1023, _t("0x%lx (%s)"), iSysErr, pszErrDesc); + szError[1023] = _T('\0'); + + // replace %err with the new data + pszOut[0]=_t('\0'); + _tcsncat(pszOut, pszStr, (size_t)(pszFnd-pszStr)); + _tcscat(pszOut, szError); + _tcscat(pszOut, pszFnd+4); + + return true; + } + else + return false; +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/log.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/log.cpp (revision 9c8dee07d9aecabc260a856da2b2dc350b7098a2) +++ ext/libicpf/src/libicpf/log.cpp (revision 0) @@ -1,685 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file log.cpp - * \brief Contains the implamentation of a log class. - */ -#include "log.h" -#include -#include "exception.h" -#include -#include -#include -#include -#include "macros.h" - -#if defined(_WIN32) || defined(_WIN64) - #include - #include - #include -#else - #include -#endif - -#if defined(_WIN32) || defined(_WIN64) - #define ENDL _t("\r\n") -#else - #define ENDL _t("\n") -#endif - -BEGIN_ICPF_NAMESPACE - -/// Table of strings representing the log message types -const tchar_t* __logtype_str[] = { _t("debug"), _t("info"), _t("warning"), _t("error") }; - -/** Constructs a log_file object. - * \param[in] bGlobal - states if this should be treates as a global instance of the log_file. - * Only one global log_file instance could exist in the application. - */ -log_file::log_file() : - m_pszPath(NULL), - m_iMaxSize(262144), - m_bLogStd(false), - m_iLogLevel(level_debug), - m_lock() -{ -#ifdef WIN32 - _fmode=_O_BINARY; -#endif -} - -/** Standard destructor - */ -log_file::~log_file() -{ - delete [] m_pszPath; -} - -/** Initializes the constructed log file. - * \param[in] pszPath - path to a log file to write to - * \param[in] iMaxSize - maximum size of a log file - * \param[in] iLogLevel - minimum log level of the messages to log - * \param[in] bLogStd - log the messages also to stdout/stderr - * \param[in] bClean - cleans the log file upon opening - */ -void log_file::init(const tchar_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean) -{ - // store the path and other params - delete [] m_pszPath; - m_pszPath=new tchar_t[_tcslen(pszPath)+1]; - _tcscpy(m_pszPath, pszPath); - - m_iMaxSize=iMaxSize; - m_bLogStd=bLogStd; - m_iLogLevel=iLogLevel; - - // try to open a file - FILE* pFile=_tfopen(pszPath, bClean ? _t("w") : _t("a")); - if (pFile == NULL) - THROW(exception::format(_t("[log_file::init()] Could not open the specified file (") TSTRFMT _t(")")), 0, 0, 0); - - fclose(pFile); -} - -// ============================================================================ -/// icpf::log_file::is_initialized -/// @date 2009/05/19 -/// -/// @brief Checks is the log_file object has been initialized. -/// @return True if it has been initialized, false otherwise. -// ============================================================================ -bool log_file::is_initialized() const throw() -{ - return m_pszPath != 0; -} - -// ============================================================================ -/// icpf::log_file::set_log_level -/// @date 2009/05/23 -/// -/// @brief Changes the log level for this class. -/// @param[in] iLogLevel New log level. -// ============================================================================ -void log_file::set_log_level(int_t iLogLevel) throw() -{ - m_iLogLevel = iLogLevel; -} - -// ============================================================================ -/// icpf::log_file::set_max_size -/// @date 2009/05/23 -/// -/// @brief Sets the max size of the log file. -/// @param[in] iMaxSize Max size of the log file. -// ============================================================================ -void log_file::set_max_size(int_t iMaxSize) throw() -{ - BOOST_ASSERT(iMaxSize > 0); - if(iMaxSize > 0) - m_iMaxSize = iMaxSize; -} - -/** Retrieves the current size of a log file. - * Quite slow function - have to access the file by opening and closing it. - * \return Current file size. - */ -int_t log_file::size() const -{ - assert(m_pszPath); - if(!m_pszPath) - return -1; - - int_t iSize=-1; - FILE* pFile=_tfopen(m_pszPath, _t("r")); - if (pFile != NULL) - { - if (fseek(pFile, 0, SEEK_END) == 0) - iSize=ftell(pFile); - - fclose(pFile); - } - - return iSize; -} - -/** Truncates the current log file content so when adding some new text the - * file size won't exceed the maximum size specified in init(). - * \param[in] iAdd - size of the new string to be added to the log file - * \return True if truncate succeeded or false if not. - */ -bool log_file::truncate(int_t iAdd) const -{ - assert(m_pszPath); - if(!m_pszPath) - return false; - - // if we doesn't need to truncate anything - if (m_iMaxSize <= 0) - return true; - - // make some checks - int_t iSize=size(); - if (iSize <= 0 || iSize+iAdd < m_iMaxSize) - return false; - - // establish the new file size (1/3rd of the current size or max_size-add_size) - int_t iNewSize=minval((int_t)(iSize*0.66), m_iMaxSize-iAdd) & ~1; - -#ifdef _WIN32 - // win32 does not have the ftruncate function, so we have to make some API calls - HANDLE hFile=CreateFile(m_pszPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile != INVALID_HANDLE_VALUE) - { - // seek - if (SetFilePointer(hFile, iSize-iNewSize, NULL, FILE_BEGIN) != INVALID_SET_FILE_POINTER) - { - // read the string to the eol - DWORD dwRD; - tchar_t szBuffer[4096/sizeof(tchar_t)]; - if (ReadFile(hFile, szBuffer, 4096, &dwRD, NULL)) - { - dwRD/=sizeof(tchar_t); - szBuffer[(dwRD > 0) ? dwRD-1 : 0]=_t('\0'); - - // replace the /r and /n in the log to the \0 - for (DWORD i=0;i 0) - { - // seek to the dst - fseek(pFile, iDst, SEEK_SET); - - fflush(pFile); - // write the buffer to the dest offset - tWR=fwrite(szBuffer, 1, tRD, pFile); - iDst+=tWR; - } - - iSrc+=tRD; - } - while(tRD != 0); - - // now truncate the file to the needed size - ftruncate(fileno(pFile), iDst); - - fclose(pFile); - return true; - } - - fclose(pFile); - } -#endif - - return false; -} - -/** Logs a formatted message to a log file. - * \param[in] iType - type of the log message (LT_*) - * \param[in] bStd - log also to stdout/stderr if true - * \param[in] pszStr - format string for the following parameters - */ -void log_file::log(int_t iType, bool bStd, const tchar_t* pszStr, ...) -{ - if (iType < m_iLogLevel) - return; - - va_list va; - va_start(va, pszStr); - logv(iType, bStd, pszStr, va); - va_end(va); -} - -/** Logs a formatted message to a log file. - * \param[in] iType - type of the log message (LT_*) - * \param[in] bStd - log also to stdout/stderr if true - * \param[in] pszStr - format string for the following parameters - * \param[in] va - variable argument list - */ -void log_file::logv(int_t iType, bool bStd, const tchar_t* pszStr, va_list va) -{ - if (iType < m_iLogLevel) - return; - - tchar_t szBuf1[2048]; - _vsntprintf(szBuf1, 2048, pszStr, va); // user passed stuff - - logs(iType, bStd, szBuf1); -} - -/** Logs an unformatted message to a log file. - * \param[in] iType - type of the log message (LT_*) - * \param[in] bStd - log also to stdout/stderr if true - * \param[in] pszStr - message string - */ -void log_file::logs(int_t iType, bool bStd, const tchar_t* pszStr) -{ - assert(m_pszPath); - if(!m_pszPath) - return; - - if (iType < m_iLogLevel || iType < 0 || iType >= sizeof(__logtype_str)) - return; - - // log time - time_t t=time(NULL); - tchar_t szData[128]; - _tcscpy(szData, _tctime(&t)); - size_t tLen=_tcslen(szData)-1; - while(szData[tLen] == _t('\n')) - szData[tLen--]=_t('\0'); - - m_lock.lock(); - - // check the size constraints - truncate((int_t)(_tcslen(pszStr)+1)); -#if defined(UNICODE) && (defined(_WIN32) || defined(_WIN64)) - FILE* pFile=_tfopen(m_pszPath, _t("ab")); -#else - FILE* pFile=_tfopen(m_pszPath, _t("at")); -#endif - bool bFailed=false; - if (pFile) - { - if (_ftprintf(pFile, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr) < 0) - bFailed=true; - fclose(pFile); - } - else - bFailed=true; - if (bFailed || (m_bLogStd && !bStd)) - { - switch(iType) - { - case level_error: - _ftprintf(stderr, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr); - break; - default: - _ftprintf(stdout, _t("[") TSTRFMT _t("] [") TSTRFMT _t("] ") TSTRFMT ENDL, szData, __logtype_str[iType], pszStr); - } - } - else if (bStd) - { - switch(iType) - { - case level_error: - _ftprintf(stderr, TSTRFMT _t(": ") TSTRFMT ENDL, __logtype_str[iType], pszStr); - break; - case level_info: - _ftprintf(stdout, TSTRFMT ENDL, pszStr); - break; - default: - _ftprintf(stdout, TSTRFMT _t(": ") TSTRFMT ENDL, __logtype_str[iType], pszStr); - } - } - - m_lock.unlock(); -} - -#ifndef SKIP_LEVEL_DEBUG -/** Logs a formatted debug message to a log file. - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logd(const tchar_t* pszStr) -{ - if (m_iLogLevel > level_debug) - return; - - logs(level_debug, false, pszStr); -} - -/** Logs a formatted debug message to a log file. -* \param[in] pszStr - format string for the given parameters -*/ -void log_file::logdv(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_debug) - return; - - va_list va; - va_start(va, pszStr); - logv(level_debug, false, pszStr, va); - va_end(va); -} - -/** Logs a formatted debug message to a log file(also outputs to stdout). - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logds(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_debug) - return; - - va_list va; - va_start(va, pszStr); - logv(level_debug, true, pszStr, va); - va_end(va); -} - -#else -void log_file::logd(const tchar_t* /*pszStr*/) -{ -} - -void log_file::logdv(const tchar_t* /*pszStr*/, ...) -{ -} - -void log_file::logds(const tchar_t* /*pszStr*/, ...) -{ -} -#endif - -#ifndef SKIP_LEVEL_INFO -/** Logs a formatted informational message to a log file. - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logi(const tchar_t* pszStr) -{ - if (m_iLogLevel > level_info) - return; - - logs(level_info, false, pszStr); -} - -/** Logs a formatted informational message to a log file. -* \param[in] pszStr - format string for the given parameters -*/ -void log_file::logiv(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_info) - return; - - va_list va; - va_start(va, pszStr); - logv(level_info, false, pszStr, va); - va_end(va); -} - -/** Logs a formatted informational message to a log file(also outputs to stdout). - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logis(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_info) - return; - - va_list va; - va_start(va, pszStr); - logv(level_info, true, pszStr, va); - va_end(va); -} -#else -void log_file::logi(const tchar_t* /*pszStr*/) -{ -} - -void log_file::logiv(const tchar_t* /*pszStr*/, ...) -{ -} - -void log_file::logis(const tchar_t* /*pszStr*/, ...) -{ -} - -#endif - -#ifndef SKIP_LEVEL_WARNING -/** Logs a formatted warning message to a log file. - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logw(const tchar_t* pszStr) -{ - if (m_iLogLevel > level_warning) - return; - - logs(level_warning, false, pszStr); -} - -/** Logs a formatted warning message to a log file. -* \param[in] pszStr - format string for the given parameters -*/ -void log_file::logwv(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_warning) - return; - - va_list va; - va_start(va, pszStr); - logv(level_warning, false, pszStr, va); - va_end(va); -} - -/** Logs a formatted warning message to a log file(also outputs to stdout). - * \param[in] pszStr - format string for the given parameters - */ -void log_file::logws(const tchar_t* pszStr, ...) -{ - if (m_iLogLevel > level_warning) - return; - va_list va; - va_start(va, pszStr); - logv(level_warning, true, pszStr, va); - va_end(va); -} - -#else -void log_file::logw(const tchar_t* /*pszStr*/) -{ -} - -void log_file::logwv(const tchar_t* /*pszStr*/, ...) -{ -} - -void log_file::logws(const tchar_t* /*pszStr*/, ...) -{ -} - -#endif - -/** Logs a formatted error message to a log file. - * \param[in] pszStr - format string for the given parameters - */ -void log_file::loge(const tchar_t* pszStr) -{ - logs(level_error, false, pszStr); -} - -/** Logs a formatted error message to a log file. -* \param[in] pszStr - format string for the given parameters -*/ -void log_file::logev(const tchar_t* pszStr, ...) -{ - va_list va; - va_start(va, pszStr); - logv(level_error, false, pszStr, va); - va_end(va); -} - -/** Logs a formatted error message to a log file(also outputs to stderr). - * \param[in] pszStr - format string for the given parameters - */ -void log_file::loges(const tchar_t* pszStr, ...) -{ - va_list va; - va_start(va, pszStr); - logv(level_error, true, pszStr, va); - va_end(va); -} - -/** Logs a formatted error message to a log file(also outputs to stderr). - * As an addition the first string %err is replaced with a given error - * followed by the error description (system-based). - * \param[in] pszStr - format string for the given parameters - * \param[in] iSysErr - system error to be shown - */ -void log_file::logerr(const tchar_t* pszStr, int_t iSysErr, ...) -{ - tchar_t szNewFmt[2048]; - if (prepare_fmt(pszStr, iSysErr, szNewFmt)) - { - va_list va; - va_start(va, iSysErr); - logv(level_error, false, szNewFmt, va); - va_end(va); - } - else - { - va_list va; - va_start(va, iSysErr); - logv(level_error, false, pszStr, va); - va_end(va); - } -} - -/** Logs a formatted error message to a log file(also outputs to stderr). - * As an addition the first string %err is replaced with a given error - * followed by the error description (system-based). - * This function differ from logerr() with logging the output string - * also to the stderr. - * \param[in] pszStr - format string for the given parameters - * \param[in] iSysErr - system error to be shown - */ -void log_file::logerrs(const tchar_t* pszStr, int_t iSysErr, ...) -{ - tchar_t szNewFmt[2048]; - if (prepare_fmt(pszStr, iSysErr, szNewFmt)) - { - va_list va; - va_start(va, iSysErr); - logv(level_error, true, szNewFmt, va); - va_end(va); - } - else - { - va_list va; - va_start(va, iSysErr); - logv(level_error, true, pszStr, va); - va_end(va); - } -} - -/** Function prepares a format string with error number and an error message - * for use with logerr() and logerrs() functions. - * \param[in] pszStr - input format string (%err will be replaced with a 0x%lx (error message) - * \param[in] iSysError - system error to parse - * \param[out] pszOut - pointer to a buffer that will receive the data (must be 2048 bytes in size) - * \return If the %err string was found and replaced within a given format string. - */ -bool log_file::prepare_fmt(const tchar_t* pszStr, int_t iSysErr, tchar_t* pszOut) const -{ - // find the %err in pszStr - const tchar_t* pszFnd=_tcsstr(pszStr, _t("%err")); - if (pszFnd) - { - // find an error description for the error - tchar_t* pszErrDesc=NULL; -#ifdef _WIN32 - tchar_t szErrDesc[512]; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD)iSysErr, 0, szErrDesc, 512, NULL); - pszErrDesc=szErrDesc; -#else - pszErrDesc=strerror(iSysErr); -#endif - - // format a string with err no and desc - tchar_t szError[1024]; - _sntprintf(szError, 1023, _t("0x%lx (%s)"), iSysErr, pszErrDesc); - szError[1023] = _T('\0'); - - // replace %err with the new data - pszOut[0]=_t('\0'); - _tcsncat(pszOut, pszStr, (size_t)(pszFnd-pszStr)); - _tcscat(pszOut, szError); - _tcscat(pszOut, pszFnd+4); - - return true; - } - else - return false; -} - -END_ICPF_NAMESPACE Index: src/libicpf/log.h =================================================================== diff -u -N --- src/libicpf/log.h (revision 0) +++ src/libicpf/log.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,116 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file log.h + * \brief Contains the log class. + */ +#ifndef __LOG_H__ +#define __LOG_H__ + +#include +#include "mutex.h" +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +/** \brief Class provides the message logging capability. + * + * Class used to perform message logging to the external file. Provides a possibility + * of limiting the max size of a file and to cut the log message types below a specific + * level. + * Class is thread safe (is it? most of the methods does not seem to be thread safe). + */ +class LIBICPF_API log_file +{ +public: + /// Supported log levels + enum log_levels + { + level_debug, /// Debug level (the most detailed one) + level_info, /// Informational level + level_warning, /// Warning level + level_error /// Error level (the least detailed one) + }; + +public: +/** \name Construction/destruction */ +/**@{*/ + explicit log_file(); ///< Standard constructor + ~log_file(); ///< Standard destructor +/**@}*/ + +/** \name Initialization */ +/**@{*/ + void init(const tchar_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean); ///< Initializes the logging object + bool is_initialized() const throw(); + + void set_log_level(int_t iLogLevel) throw(); ///< Sets the log level + void set_max_size(int_t iMaxSize) throw(); ///< Sets the max size + +/**@}*/ + +/** \name Logging functions */ +/**@{*/ + void logs(int_t iType, bool bStd, const tchar_t* pszStr); ///< Logs a string without formatting + void log(int_t iType, bool bStd, const tchar_t* pszStr, ...); ///< Logs a string with formatting + void logv(int_t iType, bool bStd, const tchar_t* pszStr, va_list va); ///< Logs a string using va_list + + void logd(const tchar_t* pszStr); ///< Logs a debug message with formatting + void logdv(const tchar_t* pszStr, ...); ///< Logs a debug message with formatting + void logds(const tchar_t* pszStr, ...); ///< Logs a debug message with formatting (also prints to stdout) + + void logi(const tchar_t* pszStr); ///< Logs an informational message with formatting + void logiv(const tchar_t* pszStr, ...); ///< Logs an informational message with formatting + void logis(const tchar_t* pszStr, ...); ///< Logs an informational message with formatting(also prints to stdout) + + void logw(const tchar_t* pszStr); ///< Logs a warning message with formatting + void logwv(const tchar_t* pszStr, ...); ///< Logs a warning message with formatting + void logws(const tchar_t* pszStr, ...); ///< Logs a warning message with formatting(also prints to stdout) + + void loge(const tchar_t* pszStr); ///< Logs an error message with formatting + void logev(const tchar_t* pszStr, ...); ///< Logs an error message with formatting + void loges(const tchar_t* pszStr, ...); ///< Logs an error message with formatting(also prints to stderr) + + void logerr(const tchar_t* pszStr, int_t iSysErr, ...); ///< Logs an error message with system error number and error description + void logerrs(const tchar_t* pszStr, int_t iSysErr, ...); ///< Logs an error message with system error number and error description (also prints to stderr) +/**@}*/ + +protected: + /// Truncates a log file not to exceed the max file size + bool truncate(int_t iAdd) const; + /// Returns the size of a log file + int_t size() const; + +private: + /// Prepares a new format string for logerr(s) functions + bool prepare_fmt(const tchar_t* pszStr, int_t iSysErr, tchar_t* pszOut) const; + +protected: + tchar_t* m_pszPath; ///< Path to the log file + int_t m_iMaxSize; ///< Maximum size of the log file + bool m_bLogStd; ///< Log also to stdout/stderr + int_t m_iLogLevel; ///< Log level (similar to the _LOG_LEVEL, but change'able after compilation) + +protected: + mutex m_lock; ///< Lock for making the class thread safe +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/log.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/log.h (revision 9c8dee07d9aecabc260a856da2b2dc350b7098a2) +++ ext/libicpf/src/libicpf/log.h (revision 0) @@ -1,116 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file log.h - * \brief Contains the log class. - */ -#ifndef __LOG_H__ -#define __LOG_H__ - -#include -#include "mutex.h" -#include "libicpf.h" -#include "gen_types.h" - -BEGIN_ICPF_NAMESPACE - -/** \brief Class provides the message logging capability. - * - * Class used to perform message logging to the external file. Provides a possibility - * of limiting the max size of a file and to cut the log message types below a specific - * level. - * Class is thread safe (is it? most of the methods does not seem to be thread safe). - */ -class LIBICPF_API log_file -{ -public: - /// Supported log levels - enum log_levels - { - level_debug, /// Debug level (the most detailed one) - level_info, /// Informational level - level_warning, /// Warning level - level_error /// Error level (the least detailed one) - }; - -public: -/** \name Construction/destruction */ -/**@{*/ - explicit log_file(); ///< Standard constructor - ~log_file(); ///< Standard destructor -/**@}*/ - -/** \name Initialization */ -/**@{*/ - void init(const tchar_t* pszPath, int_t iMaxSize, int_t iLogLevel, bool bLogStd, bool bClean); ///< Initializes the logging object - bool is_initialized() const throw(); - - void set_log_level(int_t iLogLevel) throw(); ///< Sets the log level - void set_max_size(int_t iMaxSize) throw(); ///< Sets the max size - -/**@}*/ - -/** \name Logging functions */ -/**@{*/ - void logs(int_t iType, bool bStd, const tchar_t* pszStr); ///< Logs a string without formatting - void log(int_t iType, bool bStd, const tchar_t* pszStr, ...); ///< Logs a string with formatting - void logv(int_t iType, bool bStd, const tchar_t* pszStr, va_list va); ///< Logs a string using va_list - - void logd(const tchar_t* pszStr); ///< Logs a debug message with formatting - void logdv(const tchar_t* pszStr, ...); ///< Logs a debug message with formatting - void logds(const tchar_t* pszStr, ...); ///< Logs a debug message with formatting (also prints to stdout) - - void logi(const tchar_t* pszStr); ///< Logs an informational message with formatting - void logiv(const tchar_t* pszStr, ...); ///< Logs an informational message with formatting - void logis(const tchar_t* pszStr, ...); ///< Logs an informational message with formatting(also prints to stdout) - - void logw(const tchar_t* pszStr); ///< Logs a warning message with formatting - void logwv(const tchar_t* pszStr, ...); ///< Logs a warning message with formatting - void logws(const tchar_t* pszStr, ...); ///< Logs a warning message with formatting(also prints to stdout) - - void loge(const tchar_t* pszStr); ///< Logs an error message with formatting - void logev(const tchar_t* pszStr, ...); ///< Logs an error message with formatting - void loges(const tchar_t* pszStr, ...); ///< Logs an error message with formatting(also prints to stderr) - - void logerr(const tchar_t* pszStr, int_t iSysErr, ...); ///< Logs an error message with system error number and error description - void logerrs(const tchar_t* pszStr, int_t iSysErr, ...); ///< Logs an error message with system error number and error description (also prints to stderr) -/**@}*/ - -protected: - /// Truncates a log file not to exceed the max file size - bool truncate(int_t iAdd) const; - /// Returns the size of a log file - int_t size() const; - -private: - /// Prepares a new format string for logerr(s) functions - bool prepare_fmt(const tchar_t* pszStr, int_t iSysErr, tchar_t* pszOut) const; - -protected: - tchar_t* m_pszPath; ///< Path to the log file - int_t m_iMaxSize; ///< Maximum size of the log file - bool m_bLogStd; ///< Log also to stdout/stderr - int_t m_iLogLevel; ///< Log level (similar to the _LOG_LEVEL, but change'able after compilation) - -protected: - mutex m_lock; ///< Lock for making the class thread safe -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/macros.h =================================================================== diff -u -N --- src/libicpf/macros.h (revision 0) +++ src/libicpf/macros.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,44 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#ifndef __MACROS_H__ +#define __MACROS_H__ + +/** \file macros.h + * \brief Contains some helper macros used throughout other files + */ + +// macros for rounding up and down some values to the nearest ?*chunk +/// Rounding up value to the nearest chunk multiplicity +#define ROUNDUP(val,chunk) ((val + chunk - 1) & ~(chunk-1)) +/// Rounding down value to the nearest chunk multiplicity +#define ROUNDDOWN(val,chunk) (val & ~(chunk-1)) + +// cross-platform __FUNCTION__ macro +#ifndef _WIN32 + /// Some helper for non-windoze systems (unified cross-platform __FUNCTION__ macro) + #define __FUNCTION__ __PRETTY_FUNCTION__ +#endif + +// minimum/maximum macros +/// Returns the lesser value from two given as params +#define minval(a,b) ((a) < (b) ? (a) : (b)) +/// Returns the greater value from two given as params +#define maxval(a,b) ((a) > (b) ? (a) : (b)) + +#endif Index: ext/libicpf/src/libicpf/macros.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/macros.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/macros.h (revision 0) @@ -1,44 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#ifndef __MACROS_H__ -#define __MACROS_H__ - -/** \file macros.h - * \brief Contains some helper macros used throughout other files - */ - -// macros for rounding up and down some values to the nearest ?*chunk -/// Rounding up value to the nearest chunk multiplicity -#define ROUNDUP(val,chunk) ((val + chunk - 1) & ~(chunk-1)) -/// Rounding down value to the nearest chunk multiplicity -#define ROUNDDOWN(val,chunk) (val & ~(chunk-1)) - -// cross-platform __FUNCTION__ macro -#ifndef _WIN32 - /// Some helper for non-windoze systems (unified cross-platform __FUNCTION__ macro) - #define __FUNCTION__ __PRETTY_FUNCTION__ -#endif - -// minimum/maximum macros -/// Returns the lesser value from two given as params -#define minval(a,b) ((a) < (b) ? (a) : (b)) -/// Returns the greater value from two given as params -#define maxval(a,b) ((a) > (b) ? (a) : (b)) - -#endif Index: src/libicpf/module.cpp =================================================================== diff -u -N --- src/libicpf/module.cpp (revision 0) +++ src/libicpf/module.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,1185 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +///** \file module.cpp +// * \brief File contain an implementation of the module (and related) classes. +// */ +// +#include "module.h" +//#include +//#include "err_codes.h" +// +//#ifndef _WIN32 +// #include +//#endif +// +BEGIN_ICPF_NAMESPACE +// +//#define m_pmMods ((std::map*)m_pMods) +// +///** Constructs a module_param class and initializes all the internal members +// * to their initial values. +// */ +//module_param::module_param() +//{ +// m_midModuleID=NULL_MODULE; +// m_uiPropStart=0; +//} +// +///** Destructs the module_param class. +// */ +//module_param::~module_param() +//{ +//} +// +///** Locks the class (multi-threaded access). +// */ +//void module_param::lock() +//{ +// m_lock.lock(); +//} +// +///** Unlocks the class (multi-threaded access). +// */ +//void module_param::unlock() +//{ +// m_lock.unlock(); +//} +// +///** Returns a module id associated with this class. +// * \return Module ID +// * \note The usage of mutex inside of this function is unnecessary, because +// * the module id is not supposed to change. +// */ +//moduleid_t module_param::get_moduleid() const +//{ +// return m_midModuleID; +//} +// +///** Reads the properties from the configuration object (config class). Function +// * implemented as virtual - it does not do anything in this (base) class. Should +// * be implemented in the derived classes. Function should read the properties registered +// * earlier with register_properties() from a given config object and initialize +// * the internal structure data (m_pParams). The given structure should be allocated +// * earlier (ie. in the constructor of the derived class). +// * Calling this function should be the first operation done in the derived class' function. +// * \param[in] pcfg - pointer to the config object to read the properties from +// */ +//void module_param::read_config(config* /*pcfg*/) +//{ +//} +// +///** Function writes the internal configuration options to the given configuration +// * object (config class). Declared virtual and the base implementation does not +// * do anything. Should be implemented in the derived classes. The purpose of this +// * function is to write data from the internal data structure (m_pParams) to the +// * given config class. The structure should be allocated and initialized earlier. +// * Calling this function should be the first operation done in the derived class' function. +// * \param[in] pcfg - pointer to the config object to write the properties to +// */ +//void module_param::write_config(config* /*pcfg*/) +//{ +//} +// +///** Function registers the properties used in the internal data structure (m_pParams) +// * to the given configuration object (config class). Function declared as virtual and +// * the base implementation does not do anything. In derived classes this function should +// * register the properties with the config object and store the first returned property ID +// * in the m_ulPropStart internal member. +// * Calling this function should be the first operation done in the derived class' function. +// * \note When registering properties user should lock the config object to make sure +// * the ID's will be the subsequent numbers and not pseudo-random ones. +// * \param[in] pcfg - pointer to the configuration object with which the props should be registered. +// */ +//void module_param::register_properties(config* /*pcfg*/) +//{ +//} +// +//// store/restore from/to a file (serializer) +///** Function stores the internal data structure settings to the external file (file class). +// * Declared as virtual - base implementation does not do anything. In derived classes this +// * function should store the members of the internal structure (m_pParams) in the given +// * file object in some order (that must be used also in load() function). +// * Calling this function should be the first operation done in the derived class' function. +// * \param[in] ser - serialization object to write the data to +// */ +//void module_param::store(file& /*ser*/) +//{ +//} +// +///** Function loads the internal data structure from a file (file class). Declared as +// * virtual - base implementation does not do anything. In derived classes function +// * should read the properties from a given file object (in the order used in store() function). +// * Calling this function should be the first operation done in the derived class' function. +// * \param[in] ser - serialization object that contains the data to be read +// */ +//void module_param::load(file& /*ser*/) +//{ +//} +// +///** Standard constructor - does nothing currently. +// */ +//modparam_list::modparam_list() +//{ +// m_pMods=new std::map; +//} +// +///** Standard destructor - clears the internal list of module_params. Also, each entry +// * is being deleted before clearing. If you want to preserve the elements from being deleted - +// * use the clear(false) method before destrying this object. +// */ +//modparam_list::~modparam_list() +//{ +// clear(true); +// delete m_pmMods; +//} +// +///** Inserts a module_param to this list. +// * \param[in] pEntry - address of a module_param class to be inserted. It should be allocated by +// * the 'new' operator if you would like to use bDelete parameter set in other +// * methods. +// */ +//void modparam_list::insert(module_param* pEntry) +//{ +// assert(pEntry); +// m_lock.lock(); +// m_pmMods->insert(std::pair(pEntry->get_moduleid(), pEntry)); +// m_lock.unlock(); +//} +// +///** Removes a module from the list. Also delete a module_param if specified. +// * \param[in] tEntry - module id associated with an entry to remove +// * \param[in] bDelete - specifies, if the delete operator should be called on an entry +// * before removing it from the list. +// * \return If the entry was successfully removed (true) or not (false). +// */ +//bool modparam_list::remove(moduleid_t tEntry, bool bDelete) +//{ +// m_lock.lock(); +// std::map::iterator it = m_pmMods->find(tEntry); +// if (it != m_pmMods->end()) +// { +// // delete if needed +// if (bDelete) +// delete it->second; +// m_pmMods->erase(it); +// m_lock.unlock(); +// return true; +// } +// else +// { +// m_lock.unlock(); +// return false; +// } +//} +// +///** Removes all the items from this list. +// * \param[in] bDelete - if true, then all the items will be 'delete''d before removing. +// */ +//void modparam_list::clear(bool bDelete) +//{ +// m_lock.lock(); +// if (bDelete) +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// delete it->second; +// } +// } +// +// m_pmMods->clear(); +// m_lock.unlock(); +//} +// +///** Searches for a module_param associated with a given module id. +// * \param[in] mid - module id to search for +// * \return Pointer to a module_param class, or NULL if not found. +// */ +//module_param* modparam_list::find(moduleid_t mid) +//{ +// m_lock.lock(); +// std::map::iterator it = m_pmMods->find(mid); +// if (it != m_pmMods->end()) +// { +// m_lock.unlock(); +// return it->second; +// } +// else +// { +// m_lock.unlock(); +// return NULL; +// } +//} +// +///** A group wrapper over the module_param::read_config(). Calls the method for each of the module_param's. +// * \param[in] pcfg - pointer to a configuration object to read the data from. +// */ +//void modparam_list::read_config(config* pcfg) +//{ +// // read the config for all entries +// m_lock.lock(); +// try +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// it->second->read_config(pcfg); +// } +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// m_lock.unlock(); +//} +// +///** A group wrapper over the module_param::write_config(). Calls the method for each of the module_param's. +// * \param[in] pcfg - pointer to a configuration object to write the data to. +// */ +//void modparam_list::write_config(config* pcfg) +//{ +// m_lock.lock(); +// try +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// it->second->write_config(pcfg); +// } +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// m_lock.unlock(); +//} +// +///** A group wrapper over the module_param::register_properties(). Calls the method for each of the module_param's. +// * \param[in] pcfg - pointer to a configuration object to register the properties with. +// */ +//void modparam_list::register_properties(config* pcfg) +//{ +// m_lock.lock(); +// try +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// it->second->register_properties(pcfg); +// } +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// m_lock.unlock(); +//} +// +///** A group wrapper over the module_param::store(). Calls the method for each of the module_param's. +// * \param[in] ser - a serialization object to write the data to +// */ +//void modparam_list::store(file& ser) +//{ +// m_lock.lock(); +// try +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// it->second->store(ser); +// } +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// m_lock.unlock(); +//} +// +///** A group wrapper over the module_param::load(). Calls the method for each of the module_param's. +// * \param[in] ser - a serialization object to read the data from +// */ +//void modparam_list::load(file& ser) +//{ +// m_lock.lock(); +// try +// { +// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) +// { +// it->second->load(ser); +// } +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// m_lock.unlock(); +//} +// +///////////////////////////////////////////////////////////////////////////// +///** Constructor - makes a copy of the MODULE_INITDATA passed as the parameter +// * and stores the given flags in the internal member. Also nullifies all the other class +// * members. The module information is initialized with NULL values and for internal +// * modules this should be corrected in the constructor of the derived class. +// * \param[in] pData - pointer to the structure with some parameters (the copy of it +// * will be stored in the internal member - not the pointer itself). +// * \param[in] uiFlags - module flags that are about to be stored in the internal member (MF_*) +// */ +//module::module(const MODULE_INITDATA* pData, uint_t uiFlags) +//{ +// m_pmp=NULL; +// m_pmid=pData; +// m_ulFlags=uiFlags; +// m_lRefCount=0; +// +// // module information +// m_mi.uiInfoLen=sizeof(MODULE_INFO); +// m_mi.midID=NULL_MODULE; +// m_mi.szAuthor[0]='\0'; +// m_mi.szName[0]='\0'; +// m_mi.szVersion[0]='\0'; +// m_mi.uiType=MT_NONE; +// +// m_hModule=NULL; +// m_pszPath=NULL; +// m_pfnGetInfo=NULL; +// m_pfnInit=NULL; +// m_pfnUninit=NULL; +// m_pfnAllocModparam=NULL; +//} +// +///** Destructor. Tries to close the module (close(true) function). If the closing +// * function throws an exception it is caught, logged to the log file (MODULE_INITDATA) +// * and the exception is removed. +// */ +//module::~module() +//{ +// try +// { +// close(true); +// } +// catch(exception* e) +// { +// LOG_EXCEPTION(e, m_pmid->plog); +// e->del(); +// } +//} +// +//// external modules support (called only for the external modules) +///** Function opens the external file as the program module. After successful +// * file opening this function loads all exports from the module (using load_exports() +// * function) and caches the module information in the internal member if all goes ok. +// * If something goes wrong the exception is thrown. All information (excluding exceptions +// * are logged to the log file (MODULE_INITDATA)). +// * \param[in] pszPath - full path to the module that is about to be loaded +// */ +//void module::open(const char_t* pszPath) +//{ +// assert(m_ulFlags & MF_EXTERNAL); // only for the external modules +// +// m_pmid->plog->logi("[module] Loading external module " STRFMT, pszPath); +// +// // try to load external library +//#ifdef _WIN32 +// if ( (m_hModule=::LoadLibrary(pszPath)) == NULL) +// THROW(exception::format("Cannot load external module " STRFMT, pszPath), PE_CANNOTLOAD, GetLastError(), 0); +//#else +// if ( (m_hModule=dlopen(pszPath, RTLD_LAZY)) == NULL) +// THROW(exception::format("Cannot load external module " STRFMT " (" STRFMT ")", pszPath, dlerror()), PE_CANNOTLOAD, 0, 0); +//#endif +// +// m_pmid->plog->logi("[module] External module loaded successfully (handle " PTRFMT ")", m_hModule); +// +// // load all needed exports (function must throw if export does not exist) +// m_pmid->plog->logd("[module] Loading exports for the module (handle " PTRFMT ")", m_hModule); +// load_exports(); +// m_pmid->plog->logd("[module] Exports loaded for the module (handle " PTRFMT ")", m_hModule); +// +// // cache the module information +// m_pmid->plog->logd("[module] Caching module (handle " PTRFMT ") information", m_hModule); +// (*m_pfnGetInfo)(&m_mi); +// m_pmid->plog->logd("[module] Cached module (handle " PTRFMT ") information - id: " MODIDFMT ", type: " ULFMT ", name: " STRFMT ", version: " STRFMT ", author: " STRFMT "", m_hModule, m_mi.midID, m_mi.uiType, m_mi.szName, m_mi.szVersion, m_mi.szAuthor); +// +// // store the path +// m_pszPath=new char_t[strlen(pszPath)+1]; +// strcpy(m_pszPath, pszPath); +//} +// +//// close the module - it's safe to call it more than once +///** Closes the external module. At first it uninitializes the module that is about to +// * be unloaded and then closes the module and resets all(except the module info) the +// * internal data. Function is safe to be called more than once. If any problem occur +// * there is the exception thrown. +// * \param[in] bFullDestruct - should be true only in destructor. Means deleting the path string +// * before uninitialization (and not after as with false). +// */ +//void module::close(bool bFullDestruct) +//{ +// // if called from a destructor - release some of the memory allocated +// if (bFullDestruct) +// { +// // delete the path allocated earlier +// delete [] m_pszPath; +// m_pszPath=NULL; +// } +// +// // uninit the module if wasn't already +// uninit(); +// +// // release stuff related to external module +// if (m_hModule != NULL) +// { +// m_pmid->plog->logd("[module] Unloading an external module (handle " PTRFMT ")", m_hModule); +// +//#ifdef _WIN32 +// if (!::FreeLibrary(m_hModule)) +// THROW(exception::format("Cannot unload the external module (handle " PTRFMT ")", m_hModule), PE_CANNOTUNLOAD, GetLastError(), 0); +//#else +// if (dlclose(m_hModule) != 0) +// THROW(exception::format("Cannot unload the external module - " STRFMT " (handle " PTRFMT ")", dlerror(), m_hModule), PE_CANNOTUNLOAD, 0, 0); +//#endif +// m_pmid->plog->logd("[module] ...external module unloaded (handle " PTRFMT ")", m_hModule); +// } +// +// m_hModule=NULL; +// m_pfnGetInfo=NULL; +// m_pfnInit=NULL; +// m_pfnUninit=NULL; +// +// // release a memory when sure the module has been succesfully freed +// if (!bFullDestruct) +// { +// delete [] m_pszPath; +// m_pszPath=NULL; +// } +//} +// +///** Retrieves the module information (author, ... as in MODULE_INFO struct). This function +// * does not use the internal cache for external modules - there is always a call made to the +// * module. Internal modules always use caching (it's their only info source). +// * \param[out] pInfo - receives the module information +// */ +//void module::get_info(MODULE_INFO* pInfo) +//{ +// if (m_ulFlags & MF_EXTERNAL) +// { +// assert(m_hModule); +// +// (*m_pfnGetInfo)(pInfo); +// } +// else +// *pInfo=m_mi; +//} +// +///** Function initializes the module. For external modules the module's init() function will be +// * called. For internal modules this should be the first function called from within the init() +// * function of the derived class. If the function fails it can return false or throw an exception. +// * Function is safe to be called multiple times - the real init() functions will be called +// * only once. +// * \note In the internal modules the init() function in the derived classes should check for +// * the MF_INITIALIZED flag and do not perform any initialization if flag is set to 0. +// * \param[in] pData - module initialization data - should be the same as in constructor +// * \return True if the function succeeds, false otherwise. +// */ +//bool module::init(const MODULE_INITDATA* pData) +//{ +// // return if already initialized +// if (m_ulFlags & MF_INITIALIZED) +// return true; +// +// if (m_ulFlags & MF_EXTERNAL) +// { +// m_pmid->plog->logi("[module] Making external module initialization (id=" MODIDXFMT ")...", get_id()); +// if ((*m_pfnInit)(pData, &m_pmp)) +// { +// m_pmid->plog->logi("[module] ...external module initialized successfully (id=" MODIDXFMT ").", get_id()); +// m_ulFlags |= MF_INITIALIZED; +// return true; +// } +// else +// { +// m_pmid->plog->logi("[module] ...external module initialization failed (id=" MODIDXFMT ").", get_id()); +// return false; +// } +// } +// else +// { +// m_ulFlags |= MF_INITIALIZED; +// return true; +// } +//} +// +//// uninitializes a module +//// safe to call multiple times (ext module uninit() func will be called only once) +///** Uninitializes a module. This is the first function to be called in uninit() function +// * of the derived classes (internal modules). For external modules this function calls the +// * module's init() function. This function is safe to be called multiple times - the real +// * initialization functions will be called only once. On error either false value can be returned +// * or exception will be thrown. +// * \note For internal modules - this function at first should check if the module has been +// * initialized (by checking the MF_INITIALIZED flag - it must be set). If it is not then +// * no uninitialization should be done. +// * \return True if all went ok, false otherwise. +// */ +//bool module::uninit() +//{ +// if (m_ulFlags & MF_INITIALIZED) +// { +// if (m_ulFlags & MF_EXTERNAL) +// { +// m_pmid->plog->logi("[module] Making external module uninitialization (id=" MODIDXFMT ")...", get_id()); +// if ((*m_pfnUninit)(&m_pmp)) +// { +// m_pmid->plog->logi("[module] ...external module uninitialization succeeded (id=" MODIDXFMT ").", get_id()); +// +// // delete the module parameters/informations if allocated +// cleanup(); +// +// return true; +// } +// else +// { +// m_pmid->plog->logi("[module] ...external module uninitialization failed (id=" MODIDXFMT ").", get_id()); +// return false; +// } +// } +// else +// { +// // delete the module parameters/informations if allocated +// cleanup(); +// +// return true; +// } +// } +// else +// return true; // already uninitialized +//} +// +///** Allocates a module_param for this module. External modules should allocate the needed class +// * and return it in the alloc_modparam(). Internal modules do not need to call this function. +// * And overloaded function should just alloc the class and return it. +// * \return Allocated class. Note that the returned pointer is being cast to module_param, but most +// * likely this will be another class that has module_param as a base class. +// */ +//module_param* module::alloc_modparam() +//{ +// assert(m_ulFlags & MF_INITIALIZED); +// if (m_ulFlags & MF_EXTERNAL) +// return (*m_pfnAllocModparam)(); +// else +// return NULL; +//} +// +//// called to load all exported functions (must be called for any derived load_exports()) +///** Loads the exports associated with a given type of module. This should be the first function +// * to be called in load_exports() of derived classes. If a specified exports does not +// * exist in a module an exception is thrown. +// * \note Use the MAP_EXPORT macro here to assign together the function name to the +// * function address. +// */ +//void module::load_exports() +//{ +// MAP_EXPORT(m_hModule, m_pfnGetInfo, "get_info"); +// MAP_EXPORT(m_hModule, m_pfnInit, "init"); +// MAP_EXPORT(m_hModule, m_pfnUninit, "uninit"); +// MAP_EXPORT(m_hModule, m_pfnAllocModparam, "alloc_modparam"); +//} +// +///** Cleanup function used in uninit() to make sure the module_param stuff +// * is freed if needed. Also resets the MF_INITIALIZED flag. +// */ +//void module::cleanup() +//{ +// // delete the module parameters/informations if allocated +// if (m_pmp) +// { +// m_pmp->write_config(m_pmid->pcfg); +// delete m_pmp; +// m_pmp=NULL; +// } +// +// m_ulFlags &= ~MF_INITIALIZED; +//} +// +/////////////////////////////////////////////////////////////////// +//#define m_pvModules ((std::vector*)m_vModules) +//#define m_pmModules ((std::map*)m_mModules) +// +///** Constructor - makes a copy of the MODULE_INITDATA structure and +// * stores it in the internal member. +// */ +//module_list::module_list(const MODULE_INITDATA* pData) +//{ +// m_pmid=pData; +// m_vModules=(void*)new std::vector; +// m_mModules=(void*)new std::map; +//} +// +///** Destructor - calls the remove_all(true) to get rid of all modules before +// * class is destroyed. Any exception thrown in the remove_all() function is being +// * logged to a log file (MODULE_INITDATA) and the exception is deleted. +// */ +//module_list::~module_list() +//{ +// try +// { +// remove_all(true); +// } +// catch(exception& e) +// { +// LOG_EXCEPTION(e, m_pmid->plog); +// e->del(); +// } +// +// delete m_pvModules; +// delete m_pmModules; +//} +// +//#ifndef _WIN32 +///** Helper function for filtering filesystem entries. It allows selecting only the +// * filesystem entries that appears to be the proper modules. Function used in linux. +// * \param[in] pent - directory entry to process +// * \return >0 for the entry to be accepted, 0 if not. +// */ +//int_t module_list::mod_filter(const struct dirent *pent) +//{ +// size_t tLen=strlen(pent->d_name), tExtLen=strlen(MODULE_EXT); +// if (tLen >= tExtLen && strcmp(pent->d_name+tLen-tExtLen, MODULE_EXT) == 0) +// return 1; +// else +// return 0; +//} +//#endif +// +///** Function scans a specified directory for the files that looks like modules. +// * Macro MODULE_EXT specifies the file extension (in format ".ext") used in modules. +// * Only modules that types matches (even partially) the specified type are added to +// * the list. All the performed operations are logged into the log file. +// * There are no exception throws or return values. +// * \param[in] pszPath - path to the directory with modules (must be trailed with '\\' or '/' - system dependent) +// * \param[in] uiType - types of modules to be added to the list +// */ +//void module_list::scan(const char_t* pszPath, uint_t uiType) +//{ +// m_pmid->plog->logi("[module_list] Scanning directory " STRFMT " for external modules of type " ULFMT, pszPath, uiType); +// uint_t uiCount=0; // count of modules found +// +//#ifdef _WIN32 +// // create full search path +// char_t sz[_MAX_PATH]; +// _snprintf(sz, _MAX_PATH, STRFMT "*" STRFMT, pszPath, MODULE_EXT); +// size_t tLen=strlen(pszPath); +// +// WIN32_FIND_DATA wfd; +// HANDLE hFind=::FindFirstFile(sz, &wfd); +// if (hFind != INVALID_HANDLE_VALUE) +// { +// BOOL bFound=TRUE; +// while (bFound) +// { +// // append a name to the input path (NOTE: it's a small optimization so it looks like there's something's missing). +// strcpy(sz+tLen, wfd.cFileName); +//#else +// dirent **ppde; +// char_t sz[PATH_MAX]; +// strcpy(sz, pszPath); +// size_t tLen=strlen(pszPath); +// +// int_t iCnt=scandir(pszPath, &ppde, mod_filter, NULL); +// while (iCnt--) +// { +// strcpy(sz+tLen, ppde[iCnt]->d_name); +//#endif +// module* pmod=new module(m_pmid, true); +// try +// { +// pmod->open(sz); +// +// if (pmod->get_type() & uiType) +// { +// push_back(pmod); +// uiCount++; +// } +// else +// delete pmod; // also calls module::close(), but does not throw an exception +// } +// catch(exception e) +// { +// m_pmid->plog->logw("[module_list] Caught an exception while trying to open a module (path=" STRFMT ").Ignoring module.", sz); +// LOG_EXCEPTION(e, m_pmid->plog); +// +// e->del(); +// delete pmod; +// } +//#ifdef _WIN32 +// bFound=::FindNextFile(hFind, &wfd); +// } +// +// if (!::FindClose(hFind)) +// m_pmid->plog->logd("[module_list] Cannot close a find handle in module::open(), system error " ULFMT ". Ignoring.", GetLastError()); +// } +// +//#else +// free(ppde[iCnt]); +// } +// free(ppde); +//#endif +// m_pmid->plog->logi("[module_list] Completed scanning for external modules in directory " STRFMT ". Found " ULFMT " modules with type matching " ULFMT, pszPath, uiCount, uiType); +//} +// +//// getting a module from a vector +///** Searches for a module in a list given it's ID. When using this function +// * user should fully lock the module_list and before releasing the lock he should +// * use module::acquire() to make sure the module won't be unloaded when being used. +// * \param[in] mid - module ID to find in the list +// * \return Pointer to the module or NULL if module not found. +// */ +//module* module_list::find(moduleid_t mid) +//{ +// module* mod; +// +// m_lock.lock(); +// std::map::iterator it=m_pmModules->find(mid); +// if (it != m_pmModules->end()) +// mod=(*it).second; +// else +// mod=NULL; +// m_lock.unlock(); +// +// return mod; +//} +// +///** Function returns a module at a specified position. When using this function +// * user should lock the entire module_list and before releasing lock he should +// * use module::acquire() function to ensure the module to remain loaded. +// * \param[in] tPos - index of the module to return address of; the position must +// * be in range. The debug version of program asserts if range exceeded. +// * \return Address of a module. +// */ +//module* module_list::at(size_t tPos) +//{ +// assert(tPos < m_pvModules->size()); +// +// m_lock.lock(); +// module* mod=m_pvModules->at(tPos); +// m_lock.unlock(); +// +// return mod; +//} +// +//// adding a new items (modules) +///** Function inserts a module into the list at the specified position. Module is being +// * initialized before insertion (if not already initialized). An exception* is thrown +// * if any error occurs. +// * \param[in] tPos - position in the list to insert the module at (-1 = at the end) +// * \param[in] tModule - address of a module to be inserted into the list +// */ +//void module_list::insert(size_t tPos, module* tModule) +//{ +// m_pmid->plog->logd("[module_list] Initializing the module (id=" MODIDXFMT ")", tModule->get_id()); +// tModule->init(m_pmid); // can throw an exception +// +// m_pmid->plog->logd("[module_list] Inserting the module (id=" MODIDXFMT ") to the module list at the position " ULPTRXFMT, tModule->get_id(), tPos); +// +// m_lock.lock(); +// +// try +// { +// std::map::iterator it=m_pmModules->find(tModule->get_id()); +// if (it != m_pmModules->end()) +// { +// THROW(exception::format("Module with a specified id=" MODIDXFMT " (name: " STRFMT ", version: " STRFMT ", author: " STRFMT ") already exists (name: " STRFMT ", version: " STRFMT ", author: " STRFMT ")", +// tModule->get_id(), tModule->get_name(), tModule->get_version(), tModule->get_author(), +// (*it).second->get_name(), (*it).second->get_version(), (*it).second->get_author()), +// PE_DUPLICATEPLUG, 0, 0); +// } +// else +// { +// if (tPos != (size_t)-1) +// { +// assert(tPos <= m_pvModules->size()); +// m_pvModules->insert(m_pvModules->begin()+tPos, tModule); +// } +// else +// m_pvModules->push_back(tModule); +// +// m_pmModules->insert(std::pair(tModule->get_id(), tModule)); +// } +// +// m_lock.unlock(); +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +//} +// +///** Adds a module at the beginning of the list. Function uses the insert() function. +// * \param[in] tModule - address of the module to add +// */ +//void module_list::push_front(module* tModule) +//{ +// insert(0, tModule); +//} +// +///** Adds a module at the end of a list. Function uses the insert() function to perform +// * the requested operation. +// * \param[in] tModule - address of a module to add +// */ +//void module_list::push_back(module* tModule) +//{ +// insert((size_t)-1, tModule); +//} +// +//// repositioning modules in a vector +///** Changes the positions of the 2 modules (given by their ID's) - swaps them. +// * \param[in] t1, t2 - module ID's of the modules to be swapped +// */ +//void module_list::swap(moduleid_t t1, moduleid_t t2) +//{ +// m_lock.lock(); +// std::vector::iterator it1, it2, it; +// +// // enum through the all modules +// if (find_module(t1, t2, &it1, &it2)) +// swap(it1, it2); +// else +// m_pmid->plog->logd("[module_list] Swapping modules failed - one of the modules not found (id1=" MODIDXFMT ", id2=" MODIDXFMT ")", t1, t2); +// +// m_lock.unlock(); +//} +// +///** Changes the positions of the 2 modules (given by their positions) - swaps them. +// * \param[in] tPos1, tPos2 - positions of the modules to be swapped +// */ +//void module_list::swap(size_t tPos1, size_t tPos2) +//{ +// assert(tPos1 <= m_pvModules->size() && tPos2 <= m_pvModules->size()); +// +// m_lock.lock(); +// swap(m_pvModules->begin()+tPos1, m_pvModules->begin()+tPos2); +// m_lock.unlock(); +//} +// +///** Moves the module (given by it's ID) to the position given as a second parameter. +// * \param[in] tID - ID of a module to move +// * \param[in] tNewPos - new position at which the module should appear +// */ +//void module_list::move(moduleid_t tID, size_t tNewPos) +//{ +// assert(tNewPos < m_pvModules->size()); +// +// m_lock.lock(); +// +// std::vector::iterator it; +// if (find_module(tID, &it)) +// { +// module* mod=(*it); +// m_pvModules->erase(it); +// m_pvModules->insert(m_pvModules->begin()+tNewPos, mod); +// } +// +// m_lock.unlock(); +//} +// +///** Sorts the modules in order given by the vector passed as the parameter. +// * \param[in] vIDs - address of a vector that contains sorted (in the requested way) +// * module ID's. +// */ +//void module_list::sort(std::vector* vIDs) +//{ +// m_lock.lock(); +// +// // clear the vector +// m_pvModules->clear(); +// +// // and now process the data from map +// module* mod; +// for (std::vector::iterator it=vIDs->begin();it != vIDs->end();it++) +// { +// if ( (mod=find(*it)) != NULL_MODULE ) +// m_pvModules->push_back(mod); +// } +// +// m_lock.unlock(); +//} +// +///** Function fills the vector given as the parameter with the modules ID's +// * with the order as in the current list. +// * \param[in] vIDs - address of a vector that will receive the module ID's. +// */ +//void module_list::get_positions(std::vector* vIDs) +//{ +// m_lock.lock(); +// +// for (std::vector::iterator it=m_pvModules->begin();it != m_pvModules->end();it++) +// { +// vIDs->push_back((*it)->get_id()); +// } +// +// m_lock.unlock(); +//} +// +///** Returns the current count of modules contained in the list. +// * \return Count of modules. +// */ +//size_t module_list::size() +//{ +// m_lock.lock(); +// size_t tLen=m_pvModules->size(); +// m_lock.unlock(); +// +// return tLen; +//} +// +//// removing +///** Removes a module from a list (given it's ID). It means uninitializing the module +// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) +// * then it is not removed (except when the bForce flag is specified). In case of error +// * the exception is thrown or false is returned. +// * \param[in] tID - id of a module to remove +// * \param[in] bForce - if true then the module reference count >0 does not block removing. +// * \return True if everything went ok, false otherwise. +// */ +//bool module_list::remove(moduleid_t tID, bool bForce) +//{ +// // find the tID module iterator +// bool bRes; +// +// m_lock.lock(); +// +// try +// { +// std::vector::iterator it; +// if (find_module(tID, &it)) +// bRes=remove(it, bForce); +// else +// { +// m_pmid->plog->logd("[module_list] Cannot remove module (id=" MODIDXFMT ") - it does not exist", tID); +// bRes=false; +// } +// +// m_lock.unlock(); +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// +// return bRes; +//} +// +///** Removes a module from a list (given it's position). It means uninitializing the module +// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) +// * then it is not removed (except when the bForce flag is specified). In case of error +// * the exception is thrown or false is returned. +// * \param[in] tPos - position of a module to remove +// * \param[in] bForce - if true then the module reference count >0 does not block removing. +// * \return True if everything went ok, false otherwise. +// */ +//bool module_list::remove(size_t tPos, bool bForce) +//{ +// assert(tPos <= m_pvModules->size()); +// +// m_lock.lock(); +// +// bool bRes; +// try +// { +// bRes=remove(m_pvModules->begin()+tPos, bForce); +// m_lock.unlock(); +// } +// catch(...) +// { +// m_lock.unlock(); +// throw; +// } +// +// return bRes; +//} +// +///** Removes all the modules from a list. Depending the bForce parameter either all +// * modules are removed or only the unused ones. When error is encountered while removing +// * individual modules then it is logged to the log file and removed. +// * \param[in] bForce - specifies if the modules should be removed only if they are unused (false) +// * or always (true). +// */ +//void module_list::remove_all(bool bForce) +//{ +// m_lock.lock(); +// std::vector::iterator it=m_pvModules->end(); +// while (it != m_pvModules->begin()) +// { +// try +// { +// remove(--it, bForce); +// } +// catch(exception& e) +// { +// m_pmid->plog->logd("[module_list] Caught an exception in module_list::remove_all() while removing module from a list.Ignoring."); +// LOG_EXCEPTION(e, m_pmid->plog); +// e->del(); +// } +// } +// m_lock.unlock(); +//} +// +//////////////////////////////////////// +///** Removes a module from a list (given it's internal iterator). It means uninitializing the module +// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) +// * then it is not removed (except when the bForce flag is specified). In case of error +// * the exception is thrown or false is returned. +// * \param[in] it - iterator that specifies position of a module in the internal vector +// * \param[in] bForce - if true then the module reference count >0 does not block removing +// * \return True if everything went ok, false otherwise. +// */ +//bool module_list::remove(std::vector::iterator it, bool bForce) +//{ +// module* mod=(*it); +// moduleid_t tid=mod->get_id(); +// +// m_pmid->plog->logi("[module_list] Trying to remove module (id=" MODIDXFMT ")", tid); +// +// if (mod->get_refcount() != 0) +// { +// if (!bForce) +// { +// m_pmid->plog->logw("[module_list] Cannot remove module (id=" MODIDXFMT ") due to module's reference count=" LFMT, tid, mod->get_refcount()); +// return false; // cannot unload +// } +// else +// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") with reference count=" LFMT, tid, mod->get_refcount()); +// } +// +// // uninit&close the module - both can throw an exception +// try +// { +// if (!mod->uninit()) +// { +// // cannot uninit module +// if (!bForce) +// { +// m_pmid->plog->logw("[module_list] Cannot remove module (id=" MODIDXFMT ") due to uninit problems", tid); +// return false; +// } +// else +// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module uninit proc failed", tid); +// } +// } +// catch(exception& e) +// { +// if (!bForce) +// throw; // rethrow the exception - will be reported by some other func +// else +// { +// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module uninit proc had thrown an exception", tid); +// LOG_EXCEPTION(e, m_pmid->plog); +// e->del(); +// } +// } +// +// // try to close module +// try +// { +// mod->close(); +// } +// catch(exception& e) +// { +// if (!bForce) +// throw; +// else +// { +// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module close proc had thrown an exception", tid); +// LOG_EXCEPTION(e, m_pmid->plog); +// e->del(); +// } +// } +// +// // remove the module from the list +// m_pvModules->erase(it); +// std::map::iterator mit=m_pmModules->find(tid); +// if (mit != m_pmModules->end()) +// m_pmModules->erase(mit); +// +// m_pmid->plog->logi("[module_list] Module (id=" MODIDXFMT ") removed successfully", tid); +// return true; +//} +// +///** Changes the placement of the two modules (given by their iterators in the internal vector). +// * \param[in] it1, it2 - positions of the modules in the internal vector +// */ +//void module_list::swap(std::vector::iterator it1, std::vector::iterator it2) +//{ +// module* mod=(*it1); +// (*it1)=(*it2); +// (*it2)=mod; +//} +// +///** Searches for a specified module (by it's ID) and stores the iterator in the iterator +// * passed as the parameter. +// * \param[in] tID - ID of the module to search for +// * \param[out] pit - address of an iterator that is about to receive the module position +// * \return True if the module was found, false otherwise. +// */ +//bool module_list::find_module(moduleid_t tID, std::vector::iterator* pit) +//{ +// // find the requested module +// std::vector::iterator it; +// (*pit)=m_pvModules->end(); +// +// for (it=m_pvModules->begin();it != m_pvModules->end();it++) +// { +// // check if this is one of the requested modules +// if ((*it)->get_id() == tID) +// { +// (*pit)=it; +// break; +// } +// } +// +// return ((*pit) != m_pvModules->end()); +//} +// +///** Searches for a specified modules (by their ID's) and stores the iterators in the iterators +// * passed as the parameters. +// * \param[in] tID1, tID2 - ID's of the modules to search for +// * \param[out] pit1, pit2 - address of an iterators that are about to receive the module positions +// * \return True if the module was found, false otherwise. +// */ +//bool module_list::find_module(moduleid_t tID1, moduleid_t tID2, std::vector::iterator* pit1, std::vector::iterator* pit2) +//{ +// // find the requested module +// std::vector::iterator it; +// (*pit1)=(*pit2)=m_pvModules->end(); +// +// for (it=m_pvModules->begin();it != m_pvModules->end();it++) +// { +// // check if this is one of the requested modules +// if ((*it)->get_id() == tID1) +// (*pit1)=it; +// else if ((*it)->get_id() == tID2) +// (*pit2)=it; +// } +// +// return ((*pit1) != m_pvModules->end() && (*pit2) != m_pvModules->end()); +//} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/module.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/module.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/module.cpp (revision 0) @@ -1,1185 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -///** \file module.cpp -// * \brief File contain an implementation of the module (and related) classes. -// */ -// -#include "module.h" -//#include -//#include "err_codes.h" -// -//#ifndef _WIN32 -// #include -//#endif -// -BEGIN_ICPF_NAMESPACE -// -//#define m_pmMods ((std::map*)m_pMods) -// -///** Constructs a module_param class and initializes all the internal members -// * to their initial values. -// */ -//module_param::module_param() -//{ -// m_midModuleID=NULL_MODULE; -// m_uiPropStart=0; -//} -// -///** Destructs the module_param class. -// */ -//module_param::~module_param() -//{ -//} -// -///** Locks the class (multi-threaded access). -// */ -//void module_param::lock() -//{ -// m_lock.lock(); -//} -// -///** Unlocks the class (multi-threaded access). -// */ -//void module_param::unlock() -//{ -// m_lock.unlock(); -//} -// -///** Returns a module id associated with this class. -// * \return Module ID -// * \note The usage of mutex inside of this function is unnecessary, because -// * the module id is not supposed to change. -// */ -//moduleid_t module_param::get_moduleid() const -//{ -// return m_midModuleID; -//} -// -///** Reads the properties from the configuration object (config class). Function -// * implemented as virtual - it does not do anything in this (base) class. Should -// * be implemented in the derived classes. Function should read the properties registered -// * earlier with register_properties() from a given config object and initialize -// * the internal structure data (m_pParams). The given structure should be allocated -// * earlier (ie. in the constructor of the derived class). -// * Calling this function should be the first operation done in the derived class' function. -// * \param[in] pcfg - pointer to the config object to read the properties from -// */ -//void module_param::read_config(config* /*pcfg*/) -//{ -//} -// -///** Function writes the internal configuration options to the given configuration -// * object (config class). Declared virtual and the base implementation does not -// * do anything. Should be implemented in the derived classes. The purpose of this -// * function is to write data from the internal data structure (m_pParams) to the -// * given config class. The structure should be allocated and initialized earlier. -// * Calling this function should be the first operation done in the derived class' function. -// * \param[in] pcfg - pointer to the config object to write the properties to -// */ -//void module_param::write_config(config* /*pcfg*/) -//{ -//} -// -///** Function registers the properties used in the internal data structure (m_pParams) -// * to the given configuration object (config class). Function declared as virtual and -// * the base implementation does not do anything. In derived classes this function should -// * register the properties with the config object and store the first returned property ID -// * in the m_ulPropStart internal member. -// * Calling this function should be the first operation done in the derived class' function. -// * \note When registering properties user should lock the config object to make sure -// * the ID's will be the subsequent numbers and not pseudo-random ones. -// * \param[in] pcfg - pointer to the configuration object with which the props should be registered. -// */ -//void module_param::register_properties(config* /*pcfg*/) -//{ -//} -// -//// store/restore from/to a file (serializer) -///** Function stores the internal data structure settings to the external file (file class). -// * Declared as virtual - base implementation does not do anything. In derived classes this -// * function should store the members of the internal structure (m_pParams) in the given -// * file object in some order (that must be used also in load() function). -// * Calling this function should be the first operation done in the derived class' function. -// * \param[in] ser - serialization object to write the data to -// */ -//void module_param::store(file& /*ser*/) -//{ -//} -// -///** Function loads the internal data structure from a file (file class). Declared as -// * virtual - base implementation does not do anything. In derived classes function -// * should read the properties from a given file object (in the order used in store() function). -// * Calling this function should be the first operation done in the derived class' function. -// * \param[in] ser - serialization object that contains the data to be read -// */ -//void module_param::load(file& /*ser*/) -//{ -//} -// -///** Standard constructor - does nothing currently. -// */ -//modparam_list::modparam_list() -//{ -// m_pMods=new std::map; -//} -// -///** Standard destructor - clears the internal list of module_params. Also, each entry -// * is being deleted before clearing. If you want to preserve the elements from being deleted - -// * use the clear(false) method before destrying this object. -// */ -//modparam_list::~modparam_list() -//{ -// clear(true); -// delete m_pmMods; -//} -// -///** Inserts a module_param to this list. -// * \param[in] pEntry - address of a module_param class to be inserted. It should be allocated by -// * the 'new' operator if you would like to use bDelete parameter set in other -// * methods. -// */ -//void modparam_list::insert(module_param* pEntry) -//{ -// assert(pEntry); -// m_lock.lock(); -// m_pmMods->insert(std::pair(pEntry->get_moduleid(), pEntry)); -// m_lock.unlock(); -//} -// -///** Removes a module from the list. Also delete a module_param if specified. -// * \param[in] tEntry - module id associated with an entry to remove -// * \param[in] bDelete - specifies, if the delete operator should be called on an entry -// * before removing it from the list. -// * \return If the entry was successfully removed (true) or not (false). -// */ -//bool modparam_list::remove(moduleid_t tEntry, bool bDelete) -//{ -// m_lock.lock(); -// std::map::iterator it = m_pmMods->find(tEntry); -// if (it != m_pmMods->end()) -// { -// // delete if needed -// if (bDelete) -// delete it->second; -// m_pmMods->erase(it); -// m_lock.unlock(); -// return true; -// } -// else -// { -// m_lock.unlock(); -// return false; -// } -//} -// -///** Removes all the items from this list. -// * \param[in] bDelete - if true, then all the items will be 'delete''d before removing. -// */ -//void modparam_list::clear(bool bDelete) -//{ -// m_lock.lock(); -// if (bDelete) -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// delete it->second; -// } -// } -// -// m_pmMods->clear(); -// m_lock.unlock(); -//} -// -///** Searches for a module_param associated with a given module id. -// * \param[in] mid - module id to search for -// * \return Pointer to a module_param class, or NULL if not found. -// */ -//module_param* modparam_list::find(moduleid_t mid) -//{ -// m_lock.lock(); -// std::map::iterator it = m_pmMods->find(mid); -// if (it != m_pmMods->end()) -// { -// m_lock.unlock(); -// return it->second; -// } -// else -// { -// m_lock.unlock(); -// return NULL; -// } -//} -// -///** A group wrapper over the module_param::read_config(). Calls the method for each of the module_param's. -// * \param[in] pcfg - pointer to a configuration object to read the data from. -// */ -//void modparam_list::read_config(config* pcfg) -//{ -// // read the config for all entries -// m_lock.lock(); -// try -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// it->second->read_config(pcfg); -// } -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// m_lock.unlock(); -//} -// -///** A group wrapper over the module_param::write_config(). Calls the method for each of the module_param's. -// * \param[in] pcfg - pointer to a configuration object to write the data to. -// */ -//void modparam_list::write_config(config* pcfg) -//{ -// m_lock.lock(); -// try -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// it->second->write_config(pcfg); -// } -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// m_lock.unlock(); -//} -// -///** A group wrapper over the module_param::register_properties(). Calls the method for each of the module_param's. -// * \param[in] pcfg - pointer to a configuration object to register the properties with. -// */ -//void modparam_list::register_properties(config* pcfg) -//{ -// m_lock.lock(); -// try -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// it->second->register_properties(pcfg); -// } -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// m_lock.unlock(); -//} -// -///** A group wrapper over the module_param::store(). Calls the method for each of the module_param's. -// * \param[in] ser - a serialization object to write the data to -// */ -//void modparam_list::store(file& ser) -//{ -// m_lock.lock(); -// try -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// it->second->store(ser); -// } -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// m_lock.unlock(); -//} -// -///** A group wrapper over the module_param::load(). Calls the method for each of the module_param's. -// * \param[in] ser - a serialization object to read the data from -// */ -//void modparam_list::load(file& ser) -//{ -// m_lock.lock(); -// try -// { -// for (std::map::iterator it=m_pmMods->begin();it != m_pmMods->end();it++) -// { -// it->second->load(ser); -// } -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// m_lock.unlock(); -//} -// -///////////////////////////////////////////////////////////////////////////// -///** Constructor - makes a copy of the MODULE_INITDATA passed as the parameter -// * and stores the given flags in the internal member. Also nullifies all the other class -// * members. The module information is initialized with NULL values and for internal -// * modules this should be corrected in the constructor of the derived class. -// * \param[in] pData - pointer to the structure with some parameters (the copy of it -// * will be stored in the internal member - not the pointer itself). -// * \param[in] uiFlags - module flags that are about to be stored in the internal member (MF_*) -// */ -//module::module(const MODULE_INITDATA* pData, uint_t uiFlags) -//{ -// m_pmp=NULL; -// m_pmid=pData; -// m_ulFlags=uiFlags; -// m_lRefCount=0; -// -// // module information -// m_mi.uiInfoLen=sizeof(MODULE_INFO); -// m_mi.midID=NULL_MODULE; -// m_mi.szAuthor[0]='\0'; -// m_mi.szName[0]='\0'; -// m_mi.szVersion[0]='\0'; -// m_mi.uiType=MT_NONE; -// -// m_hModule=NULL; -// m_pszPath=NULL; -// m_pfnGetInfo=NULL; -// m_pfnInit=NULL; -// m_pfnUninit=NULL; -// m_pfnAllocModparam=NULL; -//} -// -///** Destructor. Tries to close the module (close(true) function). If the closing -// * function throws an exception it is caught, logged to the log file (MODULE_INITDATA) -// * and the exception is removed. -// */ -//module::~module() -//{ -// try -// { -// close(true); -// } -// catch(exception* e) -// { -// LOG_EXCEPTION(e, m_pmid->plog); -// e->del(); -// } -//} -// -//// external modules support (called only for the external modules) -///** Function opens the external file as the program module. After successful -// * file opening this function loads all exports from the module (using load_exports() -// * function) and caches the module information in the internal member if all goes ok. -// * If something goes wrong the exception is thrown. All information (excluding exceptions -// * are logged to the log file (MODULE_INITDATA)). -// * \param[in] pszPath - full path to the module that is about to be loaded -// */ -//void module::open(const char_t* pszPath) -//{ -// assert(m_ulFlags & MF_EXTERNAL); // only for the external modules -// -// m_pmid->plog->logi("[module] Loading external module " STRFMT, pszPath); -// -// // try to load external library -//#ifdef _WIN32 -// if ( (m_hModule=::LoadLibrary(pszPath)) == NULL) -// THROW(exception::format("Cannot load external module " STRFMT, pszPath), PE_CANNOTLOAD, GetLastError(), 0); -//#else -// if ( (m_hModule=dlopen(pszPath, RTLD_LAZY)) == NULL) -// THROW(exception::format("Cannot load external module " STRFMT " (" STRFMT ")", pszPath, dlerror()), PE_CANNOTLOAD, 0, 0); -//#endif -// -// m_pmid->plog->logi("[module] External module loaded successfully (handle " PTRFMT ")", m_hModule); -// -// // load all needed exports (function must throw if export does not exist) -// m_pmid->plog->logd("[module] Loading exports for the module (handle " PTRFMT ")", m_hModule); -// load_exports(); -// m_pmid->plog->logd("[module] Exports loaded for the module (handle " PTRFMT ")", m_hModule); -// -// // cache the module information -// m_pmid->plog->logd("[module] Caching module (handle " PTRFMT ") information", m_hModule); -// (*m_pfnGetInfo)(&m_mi); -// m_pmid->plog->logd("[module] Cached module (handle " PTRFMT ") information - id: " MODIDFMT ", type: " ULFMT ", name: " STRFMT ", version: " STRFMT ", author: " STRFMT "", m_hModule, m_mi.midID, m_mi.uiType, m_mi.szName, m_mi.szVersion, m_mi.szAuthor); -// -// // store the path -// m_pszPath=new char_t[strlen(pszPath)+1]; -// strcpy(m_pszPath, pszPath); -//} -// -//// close the module - it's safe to call it more than once -///** Closes the external module. At first it uninitializes the module that is about to -// * be unloaded and then closes the module and resets all(except the module info) the -// * internal data. Function is safe to be called more than once. If any problem occur -// * there is the exception thrown. -// * \param[in] bFullDestruct - should be true only in destructor. Means deleting the path string -// * before uninitialization (and not after as with false). -// */ -//void module::close(bool bFullDestruct) -//{ -// // if called from a destructor - release some of the memory allocated -// if (bFullDestruct) -// { -// // delete the path allocated earlier -// delete [] m_pszPath; -// m_pszPath=NULL; -// } -// -// // uninit the module if wasn't already -// uninit(); -// -// // release stuff related to external module -// if (m_hModule != NULL) -// { -// m_pmid->plog->logd("[module] Unloading an external module (handle " PTRFMT ")", m_hModule); -// -//#ifdef _WIN32 -// if (!::FreeLibrary(m_hModule)) -// THROW(exception::format("Cannot unload the external module (handle " PTRFMT ")", m_hModule), PE_CANNOTUNLOAD, GetLastError(), 0); -//#else -// if (dlclose(m_hModule) != 0) -// THROW(exception::format("Cannot unload the external module - " STRFMT " (handle " PTRFMT ")", dlerror(), m_hModule), PE_CANNOTUNLOAD, 0, 0); -//#endif -// m_pmid->plog->logd("[module] ...external module unloaded (handle " PTRFMT ")", m_hModule); -// } -// -// m_hModule=NULL; -// m_pfnGetInfo=NULL; -// m_pfnInit=NULL; -// m_pfnUninit=NULL; -// -// // release a memory when sure the module has been succesfully freed -// if (!bFullDestruct) -// { -// delete [] m_pszPath; -// m_pszPath=NULL; -// } -//} -// -///** Retrieves the module information (author, ... as in MODULE_INFO struct). This function -// * does not use the internal cache for external modules - there is always a call made to the -// * module. Internal modules always use caching (it's their only info source). -// * \param[out] pInfo - receives the module information -// */ -//void module::get_info(MODULE_INFO* pInfo) -//{ -// if (m_ulFlags & MF_EXTERNAL) -// { -// assert(m_hModule); -// -// (*m_pfnGetInfo)(pInfo); -// } -// else -// *pInfo=m_mi; -//} -// -///** Function initializes the module. For external modules the module's init() function will be -// * called. For internal modules this should be the first function called from within the init() -// * function of the derived class. If the function fails it can return false or throw an exception. -// * Function is safe to be called multiple times - the real init() functions will be called -// * only once. -// * \note In the internal modules the init() function in the derived classes should check for -// * the MF_INITIALIZED flag and do not perform any initialization if flag is set to 0. -// * \param[in] pData - module initialization data - should be the same as in constructor -// * \return True if the function succeeds, false otherwise. -// */ -//bool module::init(const MODULE_INITDATA* pData) -//{ -// // return if already initialized -// if (m_ulFlags & MF_INITIALIZED) -// return true; -// -// if (m_ulFlags & MF_EXTERNAL) -// { -// m_pmid->plog->logi("[module] Making external module initialization (id=" MODIDXFMT ")...", get_id()); -// if ((*m_pfnInit)(pData, &m_pmp)) -// { -// m_pmid->plog->logi("[module] ...external module initialized successfully (id=" MODIDXFMT ").", get_id()); -// m_ulFlags |= MF_INITIALIZED; -// return true; -// } -// else -// { -// m_pmid->plog->logi("[module] ...external module initialization failed (id=" MODIDXFMT ").", get_id()); -// return false; -// } -// } -// else -// { -// m_ulFlags |= MF_INITIALIZED; -// return true; -// } -//} -// -//// uninitializes a module -//// safe to call multiple times (ext module uninit() func will be called only once) -///** Uninitializes a module. This is the first function to be called in uninit() function -// * of the derived classes (internal modules). For external modules this function calls the -// * module's init() function. This function is safe to be called multiple times - the real -// * initialization functions will be called only once. On error either false value can be returned -// * or exception will be thrown. -// * \note For internal modules - this function at first should check if the module has been -// * initialized (by checking the MF_INITIALIZED flag - it must be set). If it is not then -// * no uninitialization should be done. -// * \return True if all went ok, false otherwise. -// */ -//bool module::uninit() -//{ -// if (m_ulFlags & MF_INITIALIZED) -// { -// if (m_ulFlags & MF_EXTERNAL) -// { -// m_pmid->plog->logi("[module] Making external module uninitialization (id=" MODIDXFMT ")...", get_id()); -// if ((*m_pfnUninit)(&m_pmp)) -// { -// m_pmid->plog->logi("[module] ...external module uninitialization succeeded (id=" MODIDXFMT ").", get_id()); -// -// // delete the module parameters/informations if allocated -// cleanup(); -// -// return true; -// } -// else -// { -// m_pmid->plog->logi("[module] ...external module uninitialization failed (id=" MODIDXFMT ").", get_id()); -// return false; -// } -// } -// else -// { -// // delete the module parameters/informations if allocated -// cleanup(); -// -// return true; -// } -// } -// else -// return true; // already uninitialized -//} -// -///** Allocates a module_param for this module. External modules should allocate the needed class -// * and return it in the alloc_modparam(). Internal modules do not need to call this function. -// * And overloaded function should just alloc the class and return it. -// * \return Allocated class. Note that the returned pointer is being cast to module_param, but most -// * likely this will be another class that has module_param as a base class. -// */ -//module_param* module::alloc_modparam() -//{ -// assert(m_ulFlags & MF_INITIALIZED); -// if (m_ulFlags & MF_EXTERNAL) -// return (*m_pfnAllocModparam)(); -// else -// return NULL; -//} -// -//// called to load all exported functions (must be called for any derived load_exports()) -///** Loads the exports associated with a given type of module. This should be the first function -// * to be called in load_exports() of derived classes. If a specified exports does not -// * exist in a module an exception is thrown. -// * \note Use the MAP_EXPORT macro here to assign together the function name to the -// * function address. -// */ -//void module::load_exports() -//{ -// MAP_EXPORT(m_hModule, m_pfnGetInfo, "get_info"); -// MAP_EXPORT(m_hModule, m_pfnInit, "init"); -// MAP_EXPORT(m_hModule, m_pfnUninit, "uninit"); -// MAP_EXPORT(m_hModule, m_pfnAllocModparam, "alloc_modparam"); -//} -// -///** Cleanup function used in uninit() to make sure the module_param stuff -// * is freed if needed. Also resets the MF_INITIALIZED flag. -// */ -//void module::cleanup() -//{ -// // delete the module parameters/informations if allocated -// if (m_pmp) -// { -// m_pmp->write_config(m_pmid->pcfg); -// delete m_pmp; -// m_pmp=NULL; -// } -// -// m_ulFlags &= ~MF_INITIALIZED; -//} -// -/////////////////////////////////////////////////////////////////// -//#define m_pvModules ((std::vector*)m_vModules) -//#define m_pmModules ((std::map*)m_mModules) -// -///** Constructor - makes a copy of the MODULE_INITDATA structure and -// * stores it in the internal member. -// */ -//module_list::module_list(const MODULE_INITDATA* pData) -//{ -// m_pmid=pData; -// m_vModules=(void*)new std::vector; -// m_mModules=(void*)new std::map; -//} -// -///** Destructor - calls the remove_all(true) to get rid of all modules before -// * class is destroyed. Any exception thrown in the remove_all() function is being -// * logged to a log file (MODULE_INITDATA) and the exception is deleted. -// */ -//module_list::~module_list() -//{ -// try -// { -// remove_all(true); -// } -// catch(exception& e) -// { -// LOG_EXCEPTION(e, m_pmid->plog); -// e->del(); -// } -// -// delete m_pvModules; -// delete m_pmModules; -//} -// -//#ifndef _WIN32 -///** Helper function for filtering filesystem entries. It allows selecting only the -// * filesystem entries that appears to be the proper modules. Function used in linux. -// * \param[in] pent - directory entry to process -// * \return >0 for the entry to be accepted, 0 if not. -// */ -//int_t module_list::mod_filter(const struct dirent *pent) -//{ -// size_t tLen=strlen(pent->d_name), tExtLen=strlen(MODULE_EXT); -// if (tLen >= tExtLen && strcmp(pent->d_name+tLen-tExtLen, MODULE_EXT) == 0) -// return 1; -// else -// return 0; -//} -//#endif -// -///** Function scans a specified directory for the files that looks like modules. -// * Macro MODULE_EXT specifies the file extension (in format ".ext") used in modules. -// * Only modules that types matches (even partially) the specified type are added to -// * the list. All the performed operations are logged into the log file. -// * There are no exception throws or return values. -// * \param[in] pszPath - path to the directory with modules (must be trailed with '\\' or '/' - system dependent) -// * \param[in] uiType - types of modules to be added to the list -// */ -//void module_list::scan(const char_t* pszPath, uint_t uiType) -//{ -// m_pmid->plog->logi("[module_list] Scanning directory " STRFMT " for external modules of type " ULFMT, pszPath, uiType); -// uint_t uiCount=0; // count of modules found -// -//#ifdef _WIN32 -// // create full search path -// char_t sz[_MAX_PATH]; -// _snprintf(sz, _MAX_PATH, STRFMT "*" STRFMT, pszPath, MODULE_EXT); -// size_t tLen=strlen(pszPath); -// -// WIN32_FIND_DATA wfd; -// HANDLE hFind=::FindFirstFile(sz, &wfd); -// if (hFind != INVALID_HANDLE_VALUE) -// { -// BOOL bFound=TRUE; -// while (bFound) -// { -// // append a name to the input path (NOTE: it's a small optimization so it looks like there's something's missing). -// strcpy(sz+tLen, wfd.cFileName); -//#else -// dirent **ppde; -// char_t sz[PATH_MAX]; -// strcpy(sz, pszPath); -// size_t tLen=strlen(pszPath); -// -// int_t iCnt=scandir(pszPath, &ppde, mod_filter, NULL); -// while (iCnt--) -// { -// strcpy(sz+tLen, ppde[iCnt]->d_name); -//#endif -// module* pmod=new module(m_pmid, true); -// try -// { -// pmod->open(sz); -// -// if (pmod->get_type() & uiType) -// { -// push_back(pmod); -// uiCount++; -// } -// else -// delete pmod; // also calls module::close(), but does not throw an exception -// } -// catch(exception e) -// { -// m_pmid->plog->logw("[module_list] Caught an exception while trying to open a module (path=" STRFMT ").Ignoring module.", sz); -// LOG_EXCEPTION(e, m_pmid->plog); -// -// e->del(); -// delete pmod; -// } -//#ifdef _WIN32 -// bFound=::FindNextFile(hFind, &wfd); -// } -// -// if (!::FindClose(hFind)) -// m_pmid->plog->logd("[module_list] Cannot close a find handle in module::open(), system error " ULFMT ". Ignoring.", GetLastError()); -// } -// -//#else -// free(ppde[iCnt]); -// } -// free(ppde); -//#endif -// m_pmid->plog->logi("[module_list] Completed scanning for external modules in directory " STRFMT ". Found " ULFMT " modules with type matching " ULFMT, pszPath, uiCount, uiType); -//} -// -//// getting a module from a vector -///** Searches for a module in a list given it's ID. When using this function -// * user should fully lock the module_list and before releasing the lock he should -// * use module::acquire() to make sure the module won't be unloaded when being used. -// * \param[in] mid - module ID to find in the list -// * \return Pointer to the module or NULL if module not found. -// */ -//module* module_list::find(moduleid_t mid) -//{ -// module* mod; -// -// m_lock.lock(); -// std::map::iterator it=m_pmModules->find(mid); -// if (it != m_pmModules->end()) -// mod=(*it).second; -// else -// mod=NULL; -// m_lock.unlock(); -// -// return mod; -//} -// -///** Function returns a module at a specified position. When using this function -// * user should lock the entire module_list and before releasing lock he should -// * use module::acquire() function to ensure the module to remain loaded. -// * \param[in] tPos - index of the module to return address of; the position must -// * be in range. The debug version of program asserts if range exceeded. -// * \return Address of a module. -// */ -//module* module_list::at(size_t tPos) -//{ -// assert(tPos < m_pvModules->size()); -// -// m_lock.lock(); -// module* mod=m_pvModules->at(tPos); -// m_lock.unlock(); -// -// return mod; -//} -// -//// adding a new items (modules) -///** Function inserts a module into the list at the specified position. Module is being -// * initialized before insertion (if not already initialized). An exception* is thrown -// * if any error occurs. -// * \param[in] tPos - position in the list to insert the module at (-1 = at the end) -// * \param[in] tModule - address of a module to be inserted into the list -// */ -//void module_list::insert(size_t tPos, module* tModule) -//{ -// m_pmid->plog->logd("[module_list] Initializing the module (id=" MODIDXFMT ")", tModule->get_id()); -// tModule->init(m_pmid); // can throw an exception -// -// m_pmid->plog->logd("[module_list] Inserting the module (id=" MODIDXFMT ") to the module list at the position " ULPTRXFMT, tModule->get_id(), tPos); -// -// m_lock.lock(); -// -// try -// { -// std::map::iterator it=m_pmModules->find(tModule->get_id()); -// if (it != m_pmModules->end()) -// { -// THROW(exception::format("Module with a specified id=" MODIDXFMT " (name: " STRFMT ", version: " STRFMT ", author: " STRFMT ") already exists (name: " STRFMT ", version: " STRFMT ", author: " STRFMT ")", -// tModule->get_id(), tModule->get_name(), tModule->get_version(), tModule->get_author(), -// (*it).second->get_name(), (*it).second->get_version(), (*it).second->get_author()), -// PE_DUPLICATEPLUG, 0, 0); -// } -// else -// { -// if (tPos != (size_t)-1) -// { -// assert(tPos <= m_pvModules->size()); -// m_pvModules->insert(m_pvModules->begin()+tPos, tModule); -// } -// else -// m_pvModules->push_back(tModule); -// -// m_pmModules->insert(std::pair(tModule->get_id(), tModule)); -// } -// -// m_lock.unlock(); -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -//} -// -///** Adds a module at the beginning of the list. Function uses the insert() function. -// * \param[in] tModule - address of the module to add -// */ -//void module_list::push_front(module* tModule) -//{ -// insert(0, tModule); -//} -// -///** Adds a module at the end of a list. Function uses the insert() function to perform -// * the requested operation. -// * \param[in] tModule - address of a module to add -// */ -//void module_list::push_back(module* tModule) -//{ -// insert((size_t)-1, tModule); -//} -// -//// repositioning modules in a vector -///** Changes the positions of the 2 modules (given by their ID's) - swaps them. -// * \param[in] t1, t2 - module ID's of the modules to be swapped -// */ -//void module_list::swap(moduleid_t t1, moduleid_t t2) -//{ -// m_lock.lock(); -// std::vector::iterator it1, it2, it; -// -// // enum through the all modules -// if (find_module(t1, t2, &it1, &it2)) -// swap(it1, it2); -// else -// m_pmid->plog->logd("[module_list] Swapping modules failed - one of the modules not found (id1=" MODIDXFMT ", id2=" MODIDXFMT ")", t1, t2); -// -// m_lock.unlock(); -//} -// -///** Changes the positions of the 2 modules (given by their positions) - swaps them. -// * \param[in] tPos1, tPos2 - positions of the modules to be swapped -// */ -//void module_list::swap(size_t tPos1, size_t tPos2) -//{ -// assert(tPos1 <= m_pvModules->size() && tPos2 <= m_pvModules->size()); -// -// m_lock.lock(); -// swap(m_pvModules->begin()+tPos1, m_pvModules->begin()+tPos2); -// m_lock.unlock(); -//} -// -///** Moves the module (given by it's ID) to the position given as a second parameter. -// * \param[in] tID - ID of a module to move -// * \param[in] tNewPos - new position at which the module should appear -// */ -//void module_list::move(moduleid_t tID, size_t tNewPos) -//{ -// assert(tNewPos < m_pvModules->size()); -// -// m_lock.lock(); -// -// std::vector::iterator it; -// if (find_module(tID, &it)) -// { -// module* mod=(*it); -// m_pvModules->erase(it); -// m_pvModules->insert(m_pvModules->begin()+tNewPos, mod); -// } -// -// m_lock.unlock(); -//} -// -///** Sorts the modules in order given by the vector passed as the parameter. -// * \param[in] vIDs - address of a vector that contains sorted (in the requested way) -// * module ID's. -// */ -//void module_list::sort(std::vector* vIDs) -//{ -// m_lock.lock(); -// -// // clear the vector -// m_pvModules->clear(); -// -// // and now process the data from map -// module* mod; -// for (std::vector::iterator it=vIDs->begin();it != vIDs->end();it++) -// { -// if ( (mod=find(*it)) != NULL_MODULE ) -// m_pvModules->push_back(mod); -// } -// -// m_lock.unlock(); -//} -// -///** Function fills the vector given as the parameter with the modules ID's -// * with the order as in the current list. -// * \param[in] vIDs - address of a vector that will receive the module ID's. -// */ -//void module_list::get_positions(std::vector* vIDs) -//{ -// m_lock.lock(); -// -// for (std::vector::iterator it=m_pvModules->begin();it != m_pvModules->end();it++) -// { -// vIDs->push_back((*it)->get_id()); -// } -// -// m_lock.unlock(); -//} -// -///** Returns the current count of modules contained in the list. -// * \return Count of modules. -// */ -//size_t module_list::size() -//{ -// m_lock.lock(); -// size_t tLen=m_pvModules->size(); -// m_lock.unlock(); -// -// return tLen; -//} -// -//// removing -///** Removes a module from a list (given it's ID). It means uninitializing the module -// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) -// * then it is not removed (except when the bForce flag is specified). In case of error -// * the exception is thrown or false is returned. -// * \param[in] tID - id of a module to remove -// * \param[in] bForce - if true then the module reference count >0 does not block removing. -// * \return True if everything went ok, false otherwise. -// */ -//bool module_list::remove(moduleid_t tID, bool bForce) -//{ -// // find the tID module iterator -// bool bRes; -// -// m_lock.lock(); -// -// try -// { -// std::vector::iterator it; -// if (find_module(tID, &it)) -// bRes=remove(it, bForce); -// else -// { -// m_pmid->plog->logd("[module_list] Cannot remove module (id=" MODIDXFMT ") - it does not exist", tID); -// bRes=false; -// } -// -// m_lock.unlock(); -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// -// return bRes; -//} -// -///** Removes a module from a list (given it's position). It means uninitializing the module -// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) -// * then it is not removed (except when the bForce flag is specified). In case of error -// * the exception is thrown or false is returned. -// * \param[in] tPos - position of a module to remove -// * \param[in] bForce - if true then the module reference count >0 does not block removing. -// * \return True if everything went ok, false otherwise. -// */ -//bool module_list::remove(size_t tPos, bool bForce) -//{ -// assert(tPos <= m_pvModules->size()); -// -// m_lock.lock(); -// -// bool bRes; -// try -// { -// bRes=remove(m_pvModules->begin()+tPos, bForce); -// m_lock.unlock(); -// } -// catch(...) -// { -// m_lock.unlock(); -// throw; -// } -// -// return bRes; -//} -// -///** Removes all the modules from a list. Depending the bForce parameter either all -// * modules are removed or only the unused ones. When error is encountered while removing -// * individual modules then it is logged to the log file and removed. -// * \param[in] bForce - specifies if the modules should be removed only if they are unused (false) -// * or always (true). -// */ -//void module_list::remove_all(bool bForce) -//{ -// m_lock.lock(); -// std::vector::iterator it=m_pvModules->end(); -// while (it != m_pvModules->begin()) -// { -// try -// { -// remove(--it, bForce); -// } -// catch(exception& e) -// { -// m_pmid->plog->logd("[module_list] Caught an exception in module_list::remove_all() while removing module from a list.Ignoring."); -// LOG_EXCEPTION(e, m_pmid->plog); -// e->del(); -// } -// } -// m_lock.unlock(); -//} -// -//////////////////////////////////////// -///** Removes a module from a list (given it's internal iterator). It means uninitializing the module -// * and then closing it. If the module is being currently used (see module::acquire() and module::release()) -// * then it is not removed (except when the bForce flag is specified). In case of error -// * the exception is thrown or false is returned. -// * \param[in] it - iterator that specifies position of a module in the internal vector -// * \param[in] bForce - if true then the module reference count >0 does not block removing -// * \return True if everything went ok, false otherwise. -// */ -//bool module_list::remove(std::vector::iterator it, bool bForce) -//{ -// module* mod=(*it); -// moduleid_t tid=mod->get_id(); -// -// m_pmid->plog->logi("[module_list] Trying to remove module (id=" MODIDXFMT ")", tid); -// -// if (mod->get_refcount() != 0) -// { -// if (!bForce) -// { -// m_pmid->plog->logw("[module_list] Cannot remove module (id=" MODIDXFMT ") due to module's reference count=" LFMT, tid, mod->get_refcount()); -// return false; // cannot unload -// } -// else -// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") with reference count=" LFMT, tid, mod->get_refcount()); -// } -// -// // uninit&close the module - both can throw an exception -// try -// { -// if (!mod->uninit()) -// { -// // cannot uninit module -// if (!bForce) -// { -// m_pmid->plog->logw("[module_list] Cannot remove module (id=" MODIDXFMT ") due to uninit problems", tid); -// return false; -// } -// else -// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module uninit proc failed", tid); -// } -// } -// catch(exception& e) -// { -// if (!bForce) -// throw; // rethrow the exception - will be reported by some other func -// else -// { -// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module uninit proc had thrown an exception", tid); -// LOG_EXCEPTION(e, m_pmid->plog); -// e->del(); -// } -// } -// -// // try to close module -// try -// { -// mod->close(); -// } -// catch(exception& e) -// { -// if (!bForce) -// throw; -// else -// { -// m_pmid->plog->logw("[module_list] Removing module (id=" MODIDXFMT ") knowing that module close proc had thrown an exception", tid); -// LOG_EXCEPTION(e, m_pmid->plog); -// e->del(); -// } -// } -// -// // remove the module from the list -// m_pvModules->erase(it); -// std::map::iterator mit=m_pmModules->find(tid); -// if (mit != m_pmModules->end()) -// m_pmModules->erase(mit); -// -// m_pmid->plog->logi("[module_list] Module (id=" MODIDXFMT ") removed successfully", tid); -// return true; -//} -// -///** Changes the placement of the two modules (given by their iterators in the internal vector). -// * \param[in] it1, it2 - positions of the modules in the internal vector -// */ -//void module_list::swap(std::vector::iterator it1, std::vector::iterator it2) -//{ -// module* mod=(*it1); -// (*it1)=(*it2); -// (*it2)=mod; -//} -// -///** Searches for a specified module (by it's ID) and stores the iterator in the iterator -// * passed as the parameter. -// * \param[in] tID - ID of the module to search for -// * \param[out] pit - address of an iterator that is about to receive the module position -// * \return True if the module was found, false otherwise. -// */ -//bool module_list::find_module(moduleid_t tID, std::vector::iterator* pit) -//{ -// // find the requested module -// std::vector::iterator it; -// (*pit)=m_pvModules->end(); -// -// for (it=m_pvModules->begin();it != m_pvModules->end();it++) -// { -// // check if this is one of the requested modules -// if ((*it)->get_id() == tID) -// { -// (*pit)=it; -// break; -// } -// } -// -// return ((*pit) != m_pvModules->end()); -//} -// -///** Searches for a specified modules (by their ID's) and stores the iterators in the iterators -// * passed as the parameters. -// * \param[in] tID1, tID2 - ID's of the modules to search for -// * \param[out] pit1, pit2 - address of an iterators that are about to receive the module positions -// * \return True if the module was found, false otherwise. -// */ -//bool module_list::find_module(moduleid_t tID1, moduleid_t tID2, std::vector::iterator* pit1, std::vector::iterator* pit2) -//{ -// // find the requested module -// std::vector::iterator it; -// (*pit1)=(*pit2)=m_pvModules->end(); -// -// for (it=m_pvModules->begin();it != m_pvModules->end();it++) -// { -// // check if this is one of the requested modules -// if ((*it)->get_id() == tID1) -// (*pit1)=it; -// else if ((*it)->get_id() == tID2) -// (*pit2)=it; -// } -// -// return ((*pit1) != m_pvModules->end() && (*pit2) != m_pvModules->end()); -//} - -END_ICPF_NAMESPACE Index: src/libicpf/module.h =================================================================== diff -u -N --- src/libicpf/module.h (revision 0) +++ src/libicpf/module.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,418 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file module.h + * \brief File contain declaration of the module (and related) classes. + */ + +#ifndef __MODULE_H__ +#define __MODULE_H__ + +#include "libicpf.h" +#include "gen_types.h" +/*#include "mutex.h" +#include "cfg.h" +#include "log.h" +#include "file.h" +#include +#include + +// inclusion of dirent.h +#if HAVE_DIRENT_H + #include + #define NAMLEN(dirent) strlen((dirent)->d_name) +#else + #define dirent direct + #define NAMLEN(dirent) (dirent)->d_namlen + #if HAVE_SYS_NDIR_H + #include + #endif + #if HAVE_SYS_DIR_H + #include + #endif + #if HAVE_NDIR_H + #include + #endif +#endif + +#ifndef MODULE_EXT + /// File extension to use with modules + #define MODULE_EXT "" +#endif +*/ +BEGIN_ICPF_NAMESPACE +/* +/// NULL module ID +#define NULL_MODULE 0x00000000 + +// module types +/// Module type NONE +#define MT_NONE 0x00000000 +/// Module type ALL +#define MT_ALL 0xffffffff + +// module flags +/// Module flag NONE +#define MF_NONE 0x00000000 +/// The module is an external one +#define MF_EXTERNAL 0x00000001 + +/** \brief States that the init() func for the module has been successfully called. + * + * If the flag is set it means that the module function init() has been called succesfully + * and the uninit() call may be executed. Flag used to make sure there will be only one + * subsequent call to init() and uninit() functions in the external module even if they + * will be called more than once in a program. + */ +/*#define MF_INITIALIZED 0x00000002 + +/// Type describes the module id. +typedef ulonglong_t moduleid_t; +/// Module ID formatting text to be used in formatting routines +#define MODIDFMT ULLFMT +/// Module ID (hex) formatting text to be used in formatting routines +#define MODIDXFMT ULLXFMT + +/** Makes a module ID from a given parameters. + * \param[in] internal - bool that specifies if this is the internal module + * \param[in] type - module type(could be a bitmask) - only the lower 28 bits will be used + * \param[in] unique_id - 32-bit unique id (should be randomly generated) + */ +/*#define MAKE_MODID(internal,type,unique_id)\ + ((internal ? 0ULL : 0x8000000000000000ULL) | (((ulonglong_t)type & 0x0fffffff) << 32) | unique_id) + +/** \brief Class for managing the parameters of a module. + * + * Class provides support for a module parameters. It could be used outside the module (ie. after + * module destruction) to store module settings to a file or to configuration. + * \todo This class needs some more clarification - how to use it, the purpose, ... + */ +/*class LIBICPF_API module_param +{ +public: +/** \name Construction/destruction */ +/**@{*/ +/* module_param(); ///< Standard constructor + virtual ~module_param(); ///< Standard destructor +/**@}*/ + +/** \name Locking/unlocking */ +/**@{*/ +/* void lock(); ///< Locks the class (gets exclusive ownership of this object) + void unlock(); ///< Unlocks the class (releases the ownership) +/**@}*/ + +/** \name Informations */ +/**@*/ +/* moduleid_t get_moduleid() const; ///< Returns a module id associated with this class +/**@}*/ + +/** \name Configuration support */ +/**@{*/ +/* virtual void read_config(config* pcfg); ///< Reads the configuration properties from a config object + virtual void write_config(config* pcfg); ///< Writes the internal properties to the config object + virtual void register_properties(config* pcfg); ///< Registers properties for use with the config object +/**@}*/ + +/** \name Serialization support */ +/**@{*/ +/* virtual void store(file& ser); ///< Stores the internal properties in the serialization object (file) + virtual void load(file& ser); ///< Loads the internal properties from a serialization object (file) +/**@}*/ +/* +protected: + moduleid_t m_midModuleID; ///< ID of a module that owns this parameters + uint_t m_uiPropStart; ///< ID of the first registered property (see register_properties()) + mutex m_lock; ///< Access lock for performing safe multi-threaded operations +}; + +/** \brief Class handling lists of module_param's. + * + * Class handles the management of lists of module_param classes. One module can have only + * one module_param (or derived) class associated with it. + */ +/*class LIBICPF_API modparam_list +{ +public: +/** \name Construction/destruction */ +/**@{*/ +/* modparam_list(); ///< Standard constructor + ~modparam_list(); ///< Standard destructor +/**@}*/ + +/** \name Standard operations */ +/**@{*/ +/* void insert(module_param* pEntry); ///< Inserts a new module_param to this container + bool remove(moduleid_t tEntry, bool bDelete=true); ///< Removes a module_param associated with a given module id + void clear(bool bDelete=true); ///< Removes all the entries from the list + module_param* find(moduleid_t mid); ///< Searches for a module_param associated with a given module id +/**@}*/ + +/** \name Configuration support */ +/**@{*/ +/* void read_config(config* pcfg); ///< Reads the configuration properties from a config object + void write_config(config* pcfg); ///< Writes the internal properties to the config object + void register_properties(config* pcfg); ///< Registers properties for use with the config object +/**@}*/ + +/** \name Serialization support */ +/**@{*/ +/* void store(file& ser); ///< Stores the internal properties in the serialization object (file) + void load(file& ser); ///< Loads the internal properties from a serialization object (file) +/**@}*/ +/* +protected: + void* m_pMods; ///< Internal map of module parameters +// std::map m_mMods; + mutex m_lock; ///< A locking mutex +}; + +/** \brief Module information struct + * + * Structure contains some fields used to identify a module (module name, + * id, type, author information and so on). + */ +/*struct MODULE_INFO +{ + uint_t uiInfoLen; ///< Count of bytes contained in this struct (filled by plugin) + char_t szAuthor[128]; ///< Author's full name + char_t szName[128]; ///< Plugin name + char_t szVersion[32]; ///< Version string + moduleid_t midID; ///< 64-bit module ID + uint_t uiType; ///< Type of a module (app-dependent) +}; + +/** \brief Structure with initialization data for a module + * + * Structure contains init parameters passed into the constructor and + * the init() function of a module and module_list class. + */ +/*struct MODULE_INITDATA +{ + config *pcfg; ///< Global configuration object + log_file *plog; ///< Log file object to perform logging to +}; + +// external functions typedefs +/// Prototype of the external module get_info() function +typedef void(*PFNMGETINFO)(MODULE_INFO*); +/// Prototype of the external module init() function +typedef bool(*PFNMINIT)(const MODULE_INITDATA*, module_param**); +/// Prototype of the external module uninit() function +typedef bool(*PFNMUNINIT)(module_param**); +/// Allocates a new module_param-derived parameter +typedef module_param*(*PFNALLOCMODPARAM)(); + +// module handle definition +#ifdef _WIN32 + /// System dependent module handle definition + #define MHANDLE HMODULE +#else + /// System dependent module handle definition + #define MHANDLE ptr_t +#endif + +// helper for loading exports +#ifdef _WIN32 + /** \brief Maps a module exported function to some class member + * + * Macro used to simplify loading function exported from an external + * modules (see module::load_exports()). + * \param[in] module - external module handle + * \param[in] var - variable that will receive the function address + * \param[in] fn_name - string with the function name to get addres of + * \note Macro throws an exception if the export cannot be loaded. + */ +/* #define MAP_EXPORT(module,var,fn_name)\ + (FARPROC&)var=::GetProcAddress(module, fn_name);\ + if (var == NULL)\ + THROW(exception::format("Cannot load an export " STRFMT " from the external module (handle " PTRFMT ")", fn_name, module), PE_CALLNOTIMPLEMENTED, GetLastError(), 0); +#else + /** \brief Maps a module exported function to some class member + * + * Macro used to simplify loading function exported from an external + * modules (see module::load_exports()). + * \param[in] module - external module handle + * \param[in] var - variable that will receive the function address + * \param[in] fn_name - string with the function name to get addres of + * \note Macro throws an exception if the export cannot be loaded. + */ +/* #define MAP_EXPORT(module,var,fn_name)\ + *((ptr_t*)&var)=dlsym(module, fn_name);\ + if (var == NULL)\ + THROW(exception::format("Cannot load an export " STRFMT " from the external module - " STRFMT " (handle " PTRFMT ")", fn_name, dlerror(), module), PE_CALLNOTIMPLEMENTED, 0, 0); +#endif + +/** \brief Module handling class + * + * This class allows handling of the internal and external modules. This is a base class + * from which should be derived any other module classes that handle different types + * of modules. + */ +/*class LIBICPF_API module +{ +public: +/** \name Construction/destruction */ +/**@{*/ +/* module(const MODULE_INITDATA* pData, uint_t uiFlags=MF_EXTERNAL); ///< Standard constructor + virtual ~module(); ///< Standard destructor +/**@}*/ + +/** \name External modules support */ +/**@{*/ +/* void open(const char_t* pszPath); ///< Opens an external module (file) + void close(bool bFullDestruct=false); ///< Closes an external module (uninitializes if needed) +/**@}*/ + +/** \name Module information */ +/**@{*/ +/* /// Retrieves the module information directly from the module + void get_info(MODULE_INFO* pInfo); + /// Returns an address of the cached module information structure + const MODULE_INFO* get_info() { return &m_mi; }; + /// Returns module ID from the cached information struct + moduleid_t get_id() const { return m_mi.midID; }; + /// Returns author string address from the cached information struct + const char_t* get_author() const { return m_mi.szAuthor; }; + /// Returns version string address from the cached information struct + const char_t* get_version() const { return m_mi.szVersion; }; + /// Returns module name string address from the cached information struct + const char_t* get_name() const { return m_mi.szName; }; + /// Returns module type from the cached information struct + uint_t get_type() const { return m_mi.uiType; }; +/**@}*/ + +/** \name Module parameters */ +/**@{*/ +/* virtual module_param* alloc_modparam(); ///< Allocates a module_param (or derived) class - should be overloaded. +/**@}*/ + +/** \name Initialization/uninitialization */ +/**@{*/ +/* virtual bool init(const MODULE_INITDATA* pData); ///< Initializes the module (if not initialized yet) + virtual bool uninit(); ///< Uninitializes the module (if not uninitialized yet) +/**@}*/ + +/** \name Reference counting */ +/**@{*/ +/* /// Retrieves the current reference count + int_t get_refcount() const { return m_lRefCount; }; + /// Increases the reference count + void acquire() { ++m_lRefCount; }; + /// Decreases the reference count + int_t release() { return --m_lRefCount; }; +/**@}*/ + +//protected: +/* /// Loads all needed exports from an external module + virtual void load_exports(); + + /// Cleans up the internal stuff + void cleanup(); + +protected: + const MODULE_INITDATA* m_pmid; ///< Module data struct ptr passed in the constructor + module_param* m_pmp; ///< Pointer to a module parameters class (managed by a module). + + MODULE_INFO m_mi; ///< Module information struct (cached for external modules, filled in constructor for internal) + + int_t m_lRefCount; ///< Current reference count + + // external stuff + uint_t m_ulFlags; ///< Module flags (MF_*) + char_t* m_pszPath; ///< Full file path for an external module + MHANDLE m_hModule; ///< Handle to the loaded external module (NULL_MODULE if not loaded) + PFNMGETINFO m_pfnGetInfo; ///< Pointer to the module's get_info() function + PFNMINIT m_pfnInit; ///< Pointer to the module's init() function + PFNMUNINIT m_pfnUninit; ///< Pointer to the module's uninit() function + PFNALLOCMODPARAM m_pfnAllocModparam; ///< Pointer to the module's alloc_modparam() function +}; + +/** \brief Module management class + * + * Class was designed to allow easier handling of a module lists. Provides + * a basic operations on a list of modules (searching, inserting, removing, ...). + * Should be a base for any module management class. + */ +/*class LIBICPF_API module_list +{ +public: +/** \name Construction/destruction */ +/**@{*/ +/* module_list(const MODULE_INITDATA* pData); ///< Standard constructor + ~module_list(); ///< Standard destructor +/**@}*/ + +/** \name Adding/removing */ +/**@{*/ +/* void scan(const char_t* pszPath, uint_t uiType=MT_ALL); ///< Scans a directory for some modules + + // adding a new items (modules) + void insert(size_t tPos, module* tModule); ///< Inserts a module at a specified position + void push_front(module* tModule); ///< Adds a module at the beginning of a list + void push_back(module* tModule); ///< Adds a module at the end of a list + + // removing + bool remove(moduleid_t tID, bool bForce=false); ///< Removes a module from the list by its ID + bool remove(size_t tPos, bool bForce=false); ///< Removes a module from the list by its position + void remove_all(bool bForce=false); ///< Removes all the modules from the list +/**@}*/ + +/** \name Searching */ +/**@{*/ +/* module* find(moduleid_t mid); ///< Searches a list for the module with the specified ID + module* at(size_t tPos); ///< Gets the module at a specified position on the list +/**@}*/ + +/** \name Module repositioning */ +/**@{*/ +/* void swap(moduleid_t t1, moduleid_t t2); ///< Swaps two modules positions by their ID's + void swap(size_t tPos1, size_t tPos2); ///< Swaps two modules positions by their positions + void move(moduleid_t tID, size_t tNewPos); ///< Moves the specified module to a new position + void sort(std::vector* vIDs); ///< Sorts the modules using a module id vector + void get_positions(std::vector* vIDs); ///< Retrieves the current modules positions +/**@}*/ + +/** \name Other */ +/**@{*/ +/* size_t size(); ///< Retrieves a count of modules in a list +/**@}*/ +/* +protected: + void swap(std::vector::iterator it1, std::vector::iterator it2); ///< Swaps two modules positions by their vector iterators + bool find_module(moduleid_t tID, std::vector::iterator* pit); ///< Searches for the module by it's ID and returns an iterator + bool find_module(moduleid_t tID1, moduleid_t tID2, std::vector::iterator* pit1, std::vector::iterator* pit2); ///< Searches for two modules by their ID's - returns iterators + bool remove(std::vector::iterator it, bool bForce=false); ///< Removes a module from this list given the vector iterator + +#ifndef _WIN32 + static int_t mod_filter(const struct dirent *pent); ///< Helper function to filter directory entries under linux +#endif + +protected: +// std::vector m_vModules; +// std::map m_mModules; + void* m_vModules; ///< Array of modules (used to make this class preserve the module positions) - internal. + void* m_mModules; ///< Mapping module id->module pointer (internal) + const MODULE_INITDATA* m_pmid; ///< Module initialization data (used for module::init() functions and/or constructors) + + mutex m_lock; ///< Thread-safe access guarantee +}; +*/ +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/module.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/module.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/module.h (revision 0) @@ -1,418 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file module.h - * \brief File contain declaration of the module (and related) classes. - */ - -#ifndef __MODULE_H__ -#define __MODULE_H__ - -#include "libicpf.h" -#include "gen_types.h" -/*#include "mutex.h" -#include "cfg.h" -#include "log.h" -#include "file.h" -#include -#include - -// inclusion of dirent.h -#if HAVE_DIRENT_H - #include - #define NAMLEN(dirent) strlen((dirent)->d_name) -#else - #define dirent direct - #define NAMLEN(dirent) (dirent)->d_namlen - #if HAVE_SYS_NDIR_H - #include - #endif - #if HAVE_SYS_DIR_H - #include - #endif - #if HAVE_NDIR_H - #include - #endif -#endif - -#ifndef MODULE_EXT - /// File extension to use with modules - #define MODULE_EXT "" -#endif -*/ -BEGIN_ICPF_NAMESPACE -/* -/// NULL module ID -#define NULL_MODULE 0x00000000 - -// module types -/// Module type NONE -#define MT_NONE 0x00000000 -/// Module type ALL -#define MT_ALL 0xffffffff - -// module flags -/// Module flag NONE -#define MF_NONE 0x00000000 -/// The module is an external one -#define MF_EXTERNAL 0x00000001 - -/** \brief States that the init() func for the module has been successfully called. - * - * If the flag is set it means that the module function init() has been called succesfully - * and the uninit() call may be executed. Flag used to make sure there will be only one - * subsequent call to init() and uninit() functions in the external module even if they - * will be called more than once in a program. - */ -/*#define MF_INITIALIZED 0x00000002 - -/// Type describes the module id. -typedef ulonglong_t moduleid_t; -/// Module ID formatting text to be used in formatting routines -#define MODIDFMT ULLFMT -/// Module ID (hex) formatting text to be used in formatting routines -#define MODIDXFMT ULLXFMT - -/** Makes a module ID from a given parameters. - * \param[in] internal - bool that specifies if this is the internal module - * \param[in] type - module type(could be a bitmask) - only the lower 28 bits will be used - * \param[in] unique_id - 32-bit unique id (should be randomly generated) - */ -/*#define MAKE_MODID(internal,type,unique_id)\ - ((internal ? 0ULL : 0x8000000000000000ULL) | (((ulonglong_t)type & 0x0fffffff) << 32) | unique_id) - -/** \brief Class for managing the parameters of a module. - * - * Class provides support for a module parameters. It could be used outside the module (ie. after - * module destruction) to store module settings to a file or to configuration. - * \todo This class needs some more clarification - how to use it, the purpose, ... - */ -/*class LIBICPF_API module_param -{ -public: -/** \name Construction/destruction */ -/**@{*/ -/* module_param(); ///< Standard constructor - virtual ~module_param(); ///< Standard destructor -/**@}*/ - -/** \name Locking/unlocking */ -/**@{*/ -/* void lock(); ///< Locks the class (gets exclusive ownership of this object) - void unlock(); ///< Unlocks the class (releases the ownership) -/**@}*/ - -/** \name Informations */ -/**@*/ -/* moduleid_t get_moduleid() const; ///< Returns a module id associated with this class -/**@}*/ - -/** \name Configuration support */ -/**@{*/ -/* virtual void read_config(config* pcfg); ///< Reads the configuration properties from a config object - virtual void write_config(config* pcfg); ///< Writes the internal properties to the config object - virtual void register_properties(config* pcfg); ///< Registers properties for use with the config object -/**@}*/ - -/** \name Serialization support */ -/**@{*/ -/* virtual void store(file& ser); ///< Stores the internal properties in the serialization object (file) - virtual void load(file& ser); ///< Loads the internal properties from a serialization object (file) -/**@}*/ -/* -protected: - moduleid_t m_midModuleID; ///< ID of a module that owns this parameters - uint_t m_uiPropStart; ///< ID of the first registered property (see register_properties()) - mutex m_lock; ///< Access lock for performing safe multi-threaded operations -}; - -/** \brief Class handling lists of module_param's. - * - * Class handles the management of lists of module_param classes. One module can have only - * one module_param (or derived) class associated with it. - */ -/*class LIBICPF_API modparam_list -{ -public: -/** \name Construction/destruction */ -/**@{*/ -/* modparam_list(); ///< Standard constructor - ~modparam_list(); ///< Standard destructor -/**@}*/ - -/** \name Standard operations */ -/**@{*/ -/* void insert(module_param* pEntry); ///< Inserts a new module_param to this container - bool remove(moduleid_t tEntry, bool bDelete=true); ///< Removes a module_param associated with a given module id - void clear(bool bDelete=true); ///< Removes all the entries from the list - module_param* find(moduleid_t mid); ///< Searches for a module_param associated with a given module id -/**@}*/ - -/** \name Configuration support */ -/**@{*/ -/* void read_config(config* pcfg); ///< Reads the configuration properties from a config object - void write_config(config* pcfg); ///< Writes the internal properties to the config object - void register_properties(config* pcfg); ///< Registers properties for use with the config object -/**@}*/ - -/** \name Serialization support */ -/**@{*/ -/* void store(file& ser); ///< Stores the internal properties in the serialization object (file) - void load(file& ser); ///< Loads the internal properties from a serialization object (file) -/**@}*/ -/* -protected: - void* m_pMods; ///< Internal map of module parameters -// std::map m_mMods; - mutex m_lock; ///< A locking mutex -}; - -/** \brief Module information struct - * - * Structure contains some fields used to identify a module (module name, - * id, type, author information and so on). - */ -/*struct MODULE_INFO -{ - uint_t uiInfoLen; ///< Count of bytes contained in this struct (filled by plugin) - char_t szAuthor[128]; ///< Author's full name - char_t szName[128]; ///< Plugin name - char_t szVersion[32]; ///< Version string - moduleid_t midID; ///< 64-bit module ID - uint_t uiType; ///< Type of a module (app-dependent) -}; - -/** \brief Structure with initialization data for a module - * - * Structure contains init parameters passed into the constructor and - * the init() function of a module and module_list class. - */ -/*struct MODULE_INITDATA -{ - config *pcfg; ///< Global configuration object - log_file *plog; ///< Log file object to perform logging to -}; - -// external functions typedefs -/// Prototype of the external module get_info() function -typedef void(*PFNMGETINFO)(MODULE_INFO*); -/// Prototype of the external module init() function -typedef bool(*PFNMINIT)(const MODULE_INITDATA*, module_param**); -/// Prototype of the external module uninit() function -typedef bool(*PFNMUNINIT)(module_param**); -/// Allocates a new module_param-derived parameter -typedef module_param*(*PFNALLOCMODPARAM)(); - -// module handle definition -#ifdef _WIN32 - /// System dependent module handle definition - #define MHANDLE HMODULE -#else - /// System dependent module handle definition - #define MHANDLE ptr_t -#endif - -// helper for loading exports -#ifdef _WIN32 - /** \brief Maps a module exported function to some class member - * - * Macro used to simplify loading function exported from an external - * modules (see module::load_exports()). - * \param[in] module - external module handle - * \param[in] var - variable that will receive the function address - * \param[in] fn_name - string with the function name to get addres of - * \note Macro throws an exception if the export cannot be loaded. - */ -/* #define MAP_EXPORT(module,var,fn_name)\ - (FARPROC&)var=::GetProcAddress(module, fn_name);\ - if (var == NULL)\ - THROW(exception::format("Cannot load an export " STRFMT " from the external module (handle " PTRFMT ")", fn_name, module), PE_CALLNOTIMPLEMENTED, GetLastError(), 0); -#else - /** \brief Maps a module exported function to some class member - * - * Macro used to simplify loading function exported from an external - * modules (see module::load_exports()). - * \param[in] module - external module handle - * \param[in] var - variable that will receive the function address - * \param[in] fn_name - string with the function name to get addres of - * \note Macro throws an exception if the export cannot be loaded. - */ -/* #define MAP_EXPORT(module,var,fn_name)\ - *((ptr_t*)&var)=dlsym(module, fn_name);\ - if (var == NULL)\ - THROW(exception::format("Cannot load an export " STRFMT " from the external module - " STRFMT " (handle " PTRFMT ")", fn_name, dlerror(), module), PE_CALLNOTIMPLEMENTED, 0, 0); -#endif - -/** \brief Module handling class - * - * This class allows handling of the internal and external modules. This is a base class - * from which should be derived any other module classes that handle different types - * of modules. - */ -/*class LIBICPF_API module -{ -public: -/** \name Construction/destruction */ -/**@{*/ -/* module(const MODULE_INITDATA* pData, uint_t uiFlags=MF_EXTERNAL); ///< Standard constructor - virtual ~module(); ///< Standard destructor -/**@}*/ - -/** \name External modules support */ -/**@{*/ -/* void open(const char_t* pszPath); ///< Opens an external module (file) - void close(bool bFullDestruct=false); ///< Closes an external module (uninitializes if needed) -/**@}*/ - -/** \name Module information */ -/**@{*/ -/* /// Retrieves the module information directly from the module - void get_info(MODULE_INFO* pInfo); - /// Returns an address of the cached module information structure - const MODULE_INFO* get_info() { return &m_mi; }; - /// Returns module ID from the cached information struct - moduleid_t get_id() const { return m_mi.midID; }; - /// Returns author string address from the cached information struct - const char_t* get_author() const { return m_mi.szAuthor; }; - /// Returns version string address from the cached information struct - const char_t* get_version() const { return m_mi.szVersion; }; - /// Returns module name string address from the cached information struct - const char_t* get_name() const { return m_mi.szName; }; - /// Returns module type from the cached information struct - uint_t get_type() const { return m_mi.uiType; }; -/**@}*/ - -/** \name Module parameters */ -/**@{*/ -/* virtual module_param* alloc_modparam(); ///< Allocates a module_param (or derived) class - should be overloaded. -/**@}*/ - -/** \name Initialization/uninitialization */ -/**@{*/ -/* virtual bool init(const MODULE_INITDATA* pData); ///< Initializes the module (if not initialized yet) - virtual bool uninit(); ///< Uninitializes the module (if not uninitialized yet) -/**@}*/ - -/** \name Reference counting */ -/**@{*/ -/* /// Retrieves the current reference count - int_t get_refcount() const { return m_lRefCount; }; - /// Increases the reference count - void acquire() { ++m_lRefCount; }; - /// Decreases the reference count - int_t release() { return --m_lRefCount; }; -/**@}*/ - -//protected: -/* /// Loads all needed exports from an external module - virtual void load_exports(); - - /// Cleans up the internal stuff - void cleanup(); - -protected: - const MODULE_INITDATA* m_pmid; ///< Module data struct ptr passed in the constructor - module_param* m_pmp; ///< Pointer to a module parameters class (managed by a module). - - MODULE_INFO m_mi; ///< Module information struct (cached for external modules, filled in constructor for internal) - - int_t m_lRefCount; ///< Current reference count - - // external stuff - uint_t m_ulFlags; ///< Module flags (MF_*) - char_t* m_pszPath; ///< Full file path for an external module - MHANDLE m_hModule; ///< Handle to the loaded external module (NULL_MODULE if not loaded) - PFNMGETINFO m_pfnGetInfo; ///< Pointer to the module's get_info() function - PFNMINIT m_pfnInit; ///< Pointer to the module's init() function - PFNMUNINIT m_pfnUninit; ///< Pointer to the module's uninit() function - PFNALLOCMODPARAM m_pfnAllocModparam; ///< Pointer to the module's alloc_modparam() function -}; - -/** \brief Module management class - * - * Class was designed to allow easier handling of a module lists. Provides - * a basic operations on a list of modules (searching, inserting, removing, ...). - * Should be a base for any module management class. - */ -/*class LIBICPF_API module_list -{ -public: -/** \name Construction/destruction */ -/**@{*/ -/* module_list(const MODULE_INITDATA* pData); ///< Standard constructor - ~module_list(); ///< Standard destructor -/**@}*/ - -/** \name Adding/removing */ -/**@{*/ -/* void scan(const char_t* pszPath, uint_t uiType=MT_ALL); ///< Scans a directory for some modules - - // adding a new items (modules) - void insert(size_t tPos, module* tModule); ///< Inserts a module at a specified position - void push_front(module* tModule); ///< Adds a module at the beginning of a list - void push_back(module* tModule); ///< Adds a module at the end of a list - - // removing - bool remove(moduleid_t tID, bool bForce=false); ///< Removes a module from the list by its ID - bool remove(size_t tPos, bool bForce=false); ///< Removes a module from the list by its position - void remove_all(bool bForce=false); ///< Removes all the modules from the list -/**@}*/ - -/** \name Searching */ -/**@{*/ -/* module* find(moduleid_t mid); ///< Searches a list for the module with the specified ID - module* at(size_t tPos); ///< Gets the module at a specified position on the list -/**@}*/ - -/** \name Module repositioning */ -/**@{*/ -/* void swap(moduleid_t t1, moduleid_t t2); ///< Swaps two modules positions by their ID's - void swap(size_t tPos1, size_t tPos2); ///< Swaps two modules positions by their positions - void move(moduleid_t tID, size_t tNewPos); ///< Moves the specified module to a new position - void sort(std::vector* vIDs); ///< Sorts the modules using a module id vector - void get_positions(std::vector* vIDs); ///< Retrieves the current modules positions -/**@}*/ - -/** \name Other */ -/**@{*/ -/* size_t size(); ///< Retrieves a count of modules in a list -/**@}*/ -/* -protected: - void swap(std::vector::iterator it1, std::vector::iterator it2); ///< Swaps two modules positions by their vector iterators - bool find_module(moduleid_t tID, std::vector::iterator* pit); ///< Searches for the module by it's ID and returns an iterator - bool find_module(moduleid_t tID1, moduleid_t tID2, std::vector::iterator* pit1, std::vector::iterator* pit2); ///< Searches for two modules by their ID's - returns iterators - bool remove(std::vector::iterator it, bool bForce=false); ///< Removes a module from this list given the vector iterator - -#ifndef _WIN32 - static int_t mod_filter(const struct dirent *pent); ///< Helper function to filter directory entries under linux -#endif - -protected: -// std::vector m_vModules; -// std::map m_mModules; - void* m_vModules; ///< Array of modules (used to make this class preserve the module positions) - internal. - void* m_mModules; ///< Mapping module id->module pointer (internal) - const MODULE_INITDATA* m_pmid; ///< Module initialization data (used for module::init() functions and/or constructors) - - mutex m_lock; ///< Thread-safe access guarantee -}; -*/ -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/mutex.cpp =================================================================== diff -u -N --- src/libicpf/mutex.cpp (revision 0) +++ src/libicpf/mutex.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,74 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +#include "mutex.h" + +BEGIN_ICPF_NAMESPACE + +mutex::mutex() +{ +#ifdef _WIN32 + ::InitializeCriticalSection(&m_cs); +#else + pthread_mutexattr_t mta; + pthread_mutexattr_init(&mta); +//#warning Recursive mutexes are disabled; Make sure you use them the right way. + pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&m_mutex, &mta); + + pthread_mutexattr_destroy(&mta); +#endif +} + +mutex::mutex(const char_t* /*pszStr*/) +{ +#ifdef _WIN32 + ::InitializeCriticalSection(&m_cs); +#else + pthread_mutexattr_t mta; + pthread_mutexattr_init(&mta); +//#warning Recursive mutexes are disabled; Make sure you use them the right way. + pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&m_mutex, &mta); + + pthread_mutexattr_destroy(&mta); +#endif +} + +mutex::~mutex() +{ +#ifdef _WIN32 + ::DeleteCriticalSection(&m_cs); +#else + pthread_mutex_destroy(&m_mutex); +#endif +} + +#ifdef ENABLE_MUTEX_DEBUGGING +void mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + lock(); +} + +void mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) +{ + unlock(); +} +#endif + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/mutex.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/mutex.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/mutex.cpp (revision 0) @@ -1,74 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -#include "mutex.h" - -BEGIN_ICPF_NAMESPACE - -mutex::mutex() -{ -#ifdef _WIN32 - ::InitializeCriticalSection(&m_cs); -#else - pthread_mutexattr_t mta; - pthread_mutexattr_init(&mta); -//#warning Recursive mutexes are disabled; Make sure you use them the right way. - pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutex_init(&m_mutex, &mta); - - pthread_mutexattr_destroy(&mta); -#endif -} - -mutex::mutex(const char_t* /*pszStr*/) -{ -#ifdef _WIN32 - ::InitializeCriticalSection(&m_cs); -#else - pthread_mutexattr_t mta; - pthread_mutexattr_init(&mta); -//#warning Recursive mutexes are disabled; Make sure you use them the right way. - pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE_NP); - pthread_mutex_init(&m_mutex, &mta); - - pthread_mutexattr_destroy(&mta); -#endif -} - -mutex::~mutex() -{ -#ifdef _WIN32 - ::DeleteCriticalSection(&m_cs); -#else - pthread_mutex_destroy(&m_mutex); -#endif -} - -#ifdef ENABLE_MUTEX_DEBUGGING -void mutex::lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) -{ - lock(); -} - -void mutex::unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction) -{ - unlock(); -} -#endif - -END_ICPF_NAMESPACE Index: src/libicpf/mutex.h =================================================================== diff -u -N --- src/libicpf/mutex.h (revision 0) +++ src/libicpf/mutex.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,118 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file mutex.h + * \brief Contains mutex class for thread safe access. + */ +#ifndef __MUTEX_H__ +#define __MUTEX_H__ + +#ifdef _WIN32 + #include +#else + #include +#endif + +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +#if defined(ENABLE_MUTEX_DEBUGGING) && defined(DEBUG_MUTEX) + #define MLOCK(mutex) (mutex).lock(__FILE__, __LINE__, __FUNCTION__) + #define MUNLOCK(mutex) (mutex).unlock(__FILE__, __LINE__, __FUNCTION__) +#else + #define MLOCK(mutex) (mutex).lock() + #define MUNLOCK(mutex) (mutex).unlock() +#endif + +/** \brief Class provides the locking and unlocking capabilities for use with threads. + * + * Class is a simple wrapper over the system related thread locking functions. In linux + * those functions are pthread_mutex_* and in windoze the functions related to CRITICAL_SECTION + * structure. + */ +class LIBICPF_API mutex +{ +public: +/** \name Construction/destruction */ +/**@{*/ + /** \brief Standard constructor + */ + mutex(); + explicit mutex(const char_t* pszStr); + + /** \brief Standard destructor + */ + ~mutex(); +/**@}*/ + + // standard locking +/** \name Locking/unlocking */ +/**@{*/ + + /** \brief Locks access to some part of code for the current thread + * + * Locks access to some code using the platform specific functions. + * \return True if succeeded or false if not. + * \note The call under windows always return true. + */ + inline void lock() + { +#ifdef _WIN32 + ::EnterCriticalSection(&m_cs); +#else + pthread_mutex_lock(&m_mutex); +#endif + } + + + /** \brief Unlock access to some locked part of code + * + * Unlocks access to some code using the platform specific functions. + * \return True if succeeded or false if not. + * \note The call under windows always return true. + */ + inline void unlock() + { +#ifdef _WIN32 + ::LeaveCriticalSection(&m_cs); +#else + pthread_mutex_unlock(&m_mutex); // return 0 on success +#endif + } + +/**@}*/ + +#ifdef ENABLE_MUTEX_DEBUGGING + void lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); + void unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); +#endif +private: +#ifdef _WIN32 + /// Underlying windows locking structure + CRITICAL_SECTION m_cs; +#else + /// Underlying linux locking structure/handle + pthread_mutex_t m_mutex; +#endif +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/mutex.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/mutex.h (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/mutex.h (revision 0) @@ -1,118 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file mutex.h - * \brief Contains mutex class for thread safe access. - */ -#ifndef __MUTEX_H__ -#define __MUTEX_H__ - -#ifdef _WIN32 - #include -#else - #include -#endif - -#include "libicpf.h" -#include "gen_types.h" - -BEGIN_ICPF_NAMESPACE - -#if defined(ENABLE_MUTEX_DEBUGGING) && defined(DEBUG_MUTEX) - #define MLOCK(mutex) (mutex).lock(__FILE__, __LINE__, __FUNCTION__) - #define MUNLOCK(mutex) (mutex).unlock(__FILE__, __LINE__, __FUNCTION__) -#else - #define MLOCK(mutex) (mutex).lock() - #define MUNLOCK(mutex) (mutex).unlock() -#endif - -/** \brief Class provides the locking and unlocking capabilities for use with threads. - * - * Class is a simple wrapper over the system related thread locking functions. In linux - * those functions are pthread_mutex_* and in windoze the functions related to CRITICAL_SECTION - * structure. - */ -class LIBICPF_API mutex -{ -public: -/** \name Construction/destruction */ -/**@{*/ - /** \brief Standard constructor - */ - mutex(); - explicit mutex(const char_t* pszStr); - - /** \brief Standard destructor - */ - ~mutex(); -/**@}*/ - - // standard locking -/** \name Locking/unlocking */ -/**@{*/ - - /** \brief Locks access to some part of code for the current thread - * - * Locks access to some code using the platform specific functions. - * \return True if succeeded or false if not. - * \note The call under windows always return true. - */ - inline void lock() - { -#ifdef _WIN32 - ::EnterCriticalSection(&m_cs); -#else - pthread_mutex_lock(&m_mutex); -#endif - } - - - /** \brief Unlock access to some locked part of code - * - * Unlocks access to some code using the platform specific functions. - * \return True if succeeded or false if not. - * \note The call under windows always return true. - */ - inline void unlock() - { -#ifdef _WIN32 - ::LeaveCriticalSection(&m_cs); -#else - pthread_mutex_unlock(&m_mutex); // return 0 on success -#endif - } - -/**@}*/ - -#ifdef ENABLE_MUTEX_DEBUGGING - void lock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); - void unlock(const char_t* pszFile, ulong_t ulLine, const char_t* pszFunction); -#endif -private: -#ifdef _WIN32 - /// Underlying windows locking structure - CRITICAL_SECTION m_cs; -#else - /// Underlying linux locking structure/handle - pthread_mutex_t m_mutex; -#endif -}; - -END_ICPF_NAMESPACE - -#endif Index: src/libicpf/str_help.cpp =================================================================== diff -u -N --- src/libicpf/str_help.cpp (revision 0) +++ src/libicpf/str_help.cpp (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,35 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file str_help.cpp + * \brief Contain implementation of some string helper functions. + */ +#include "str_help.h" + +BEGIN_ICPF_NAMESPACE + +/** Checks if the character is a whitespace. + * \param[in] ch - character to check + * \return True if the character is a whitespace one, false otherwise. + */ +bool string_tool::is_whitespace(tchar_t ch) +{ + return ((ch >= 0x09) && (ch <= 0x0d)) || (ch == 0x20); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/libicpf/str_help.cpp =================================================================== diff -u -N --- ext/libicpf/src/libicpf/str_help.cpp (revision e31dc31ccf2010abee81ddc399d65b57e4803278) +++ ext/libicpf/src/libicpf/str_help.cpp (revision 0) @@ -1,35 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file str_help.cpp - * \brief Contain implementation of some string helper functions. - */ -#include "str_help.h" - -BEGIN_ICPF_NAMESPACE - -/** Checks if the character is a whitespace. - * \param[in] ch - character to check - * \return True if the character is a whitespace one, false otherwise. - */ -bool string_tool::is_whitespace(tchar_t ch) -{ - return ((ch >= 0x09) && (ch <= 0x0d)) || (ch == 0x20); -} - -END_ICPF_NAMESPACE Index: src/libicpf/str_help.h =================================================================== diff -u -N --- src/libicpf/str_help.h (revision 0) +++ src/libicpf/str_help.h (revision b5982438edac1abb34f8f5013ba073fd01523afc) @@ -0,0 +1,47 @@ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* 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 Library 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. * +***************************************************************************/ +/** \file str_help.h + * \brief Contain some string helper functions. + */ +#ifndef __STRHELP_H__ +#define __STRHELP_H__ + +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +// some cross-platform compatibility macros +#ifndef _WIN32 + #define stricmp strcasecmp + #define wcsicmp wcscasecmp + #define strnicmp strncasecmp + #define wcsnicmp wcsncasecmp +#endif + +class LIBICPF_API string_tool +{ +public: + /// Checks if a given character is a whitespace character + static bool is_whitespace(tchar_t ch); +}; + +END_ICPF_NAMESPACE + +#endif Index: ext/libicpf/src/libicpf/str_help.h =================================================================== diff -u -N --- ext/libicpf/src/libicpf/str_help.h (revision e23fa343ecbb7479eff916bd2e52086864499b6c) +++ ext/libicpf/src/libicpf/str_help.h (revision 0) @@ -1,47 +0,0 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* 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 Library 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. * -***************************************************************************/ -/** \file str_help.h - * \brief Contain some string helper functions. - */ -#ifndef __STRHELP_H__ -#define __STRHELP_H__ - -#include "libicpf.h" -#include "gen_types.h" - -BEGIN_ICPF_NAMESPACE - -// some cross-platform compatibility macros -#ifndef _WIN32 - #define stricmp strcasecmp - #define wcsicmp wcscasecmp - #define strnicmp strncasecmp - #define wcsnicmp wcsncasecmp -#endif - -class LIBICPF_API string_tool -{ -public: - /// Checks if a given character is a whitespace character - static bool is_whitespace(tchar_t ch); -}; - -END_ICPF_NAMESPACE - -#endif