diff options
author | Ollivier Robert <roberto@FreeBSD.org> | 2013-12-04 21:33:17 +0000 |
---|---|---|
committer | Ollivier Robert <roberto@FreeBSD.org> | 2013-12-04 21:33:17 +0000 |
commit | 2b45e011ca352ce509bc83ae148230aeee0c7e0d (patch) | |
tree | a618007bb41d13153794a598e3d904ace2976324 /sntp/libopts | |
parent | 9b5bd0a264b0a21eefac2b929b574c73bd601507 (diff) | |
download | src-5592cd9e3002995d676cc186b0362f891fead9fc.tar.gz src-5592cd9e3002995d676cc186b0362f891fead9fc.zip |
Virgin import of ntpd 4.2.6p5.vendor/ntp/4.2.6p5
When the series of commits is complete, things like
https://cert.litnet.lt/en/docs/ntp-distributed-reflection-dos-attacks
should be fixed.
PR: bin/148836 (except that we import a newer version)
Asked by: Too many
MFC after: 2 weeks
Diffstat (limited to 'sntp/libopts')
50 files changed, 7725 insertions, 4636 deletions
diff --git a/sntp/libopts/COPYING.gplv3 b/sntp/libopts/COPYING.gplv3 new file mode 100644 index 000000000000..6c1b848d6b28 --- /dev/null +++ b/sntp/libopts/COPYING.gplv3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + copyright (c) by Bruce Korb - all rights reserved + + 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 3 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, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> copyright (c) by Bruce Korb - all rights reserved + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU 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 Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/sntp/libopts/COPYING.lgpl b/sntp/libopts/COPYING.lgpl deleted file mode 100644 index 129c5de4fb4a..000000000000 --- a/sntp/libopts/COPYING.lgpl +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - <one line to give the library's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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. - - <signature of Ty Coon>, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/sntp/libopts/COPYING.lgplv3 b/sntp/libopts/COPYING.lgplv3 new file mode 100644 index 000000000000..c7759a01b2c8 --- /dev/null +++ b/sntp/libopts/COPYING.lgplv3 @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + 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 that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/sntp/libopts/Makefile.am b/sntp/libopts/Makefile.am index 5f1386144221..a94972e05771 100644 --- a/sntp/libopts/Makefile.am +++ b/sntp/libopts/Makefile.am @@ -7,18 +7,22 @@ noinst_LTLIBRARIES = libopts.la endif libopts_la_SOURCES = libopts.c libopts_la_CPPFLAGS = -I$(top_srcdir) -libopts_la_LDFLAGS = -version-info 29:0:4 +libopts_la_LDFLAGS = -version-info 35:0:10 EXTRA_DIST = \ - COPYING.lgpl COPYING.mbsd MakeDefs.inc \ - README autoopts/options.h autoopts/usage-txt.h \ + COPYING.gplv3 COPYING.lgplv3 COPYING.mbsd \ + MakeDefs.inc README ag-char-map.h \ + autoopts/usage-txt.h autoopts/options.h autoopts/project.h \ autoopts.c autoopts.h boolean.c \ - compat/windows-config.h compat/compat.h compat/pathfind.c \ - compat/snprintf.c compat/strdup.c compat/strchr.c \ + compat/strdup.c compat/compat.h compat/windows-config.h \ + compat/snprintf.c compat/strchr.c compat/pathfind.c \ configfile.c cook.c enumeration.c \ - environment.c genshell.c genshell.h \ - load.c m4/libopts.m4 m4/liboptschk.m4 \ - makeshell.c nested.c numeric.c \ + environment.c file.c genshell.c \ + genshell.h load.c m4/liboptschk.m4 \ + m4/libopts.m4 makeshell.c nested.c \ + numeric.c parse-duration.c parse-duration.h \ pgusage.c proto.h putshell.c \ - restore.c save.c sort.c \ - stack.c streqvcmp.c text_mmap.c \ - tokenize.c usage.c version.c + reset.c restore.c save.c \ + sort.c stack.c streqvcmp.c \ + text_mmap.c time.c tokenize.c \ + usage.c value-type.c value-type.h \ + version.c xat-attribute.c xat-attribute.h diff --git a/sntp/libopts/Makefile.in b/sntp/libopts/Makefile.in index b5f27c67bb3e..024399d014ed 100644 --- a/sntp/libopts/Makefile.in +++ b/sntp/libopts/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -38,6 +38,15 @@ subdir = libopts DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \ + $(top_srcdir)/../m4/libtool.m4 \ + $(top_srcdir)/../m4/ltoptions.m4 \ + $(top_srcdir)/../m4/ltsugar.m4 \ + $(top_srcdir)/../m4/ltversion.m4 \ + $(top_srcdir)/../m4/lt~obsolete.m4 \ + $(top_srcdir)/../m4/ntp_cacheversion.m4 \ + $(top_srcdir)/../m4/ntp_dir_sep.m4 \ + $(top_srcdir)/../m4/ntp_lib_m.m4 \ + $(top_srcdir)/../m4/ntp_openssl.m4 $(top_srcdir)/../version.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -110,12 +119,15 @@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ -ECHO = @ECHO@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ +FGREP = @FGREP@ GREP = @GREP@ HAVE_INLINE = @HAVE_INLINE@ INSTALL = @INSTALL@ @@ -123,18 +135,31 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LCRYPTO = @LCRYPTO@ +LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ LIBOPTS_DIR = @LIBOPTS_DIR@ LIBOPTS_LDADD = @LIBOPTS_LDADD@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OPENSSL = @OPENSSL@ +OPENSSL_INC = @OPENSSL_INC@ +OPENSSL_LIB = @OPENSSL_LIB@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ @@ -143,7 +168,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +POSIX_SHELL = @POSIX_SHELL@ RANLIB = @RANLIB@ +SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ @@ -152,7 +179,9 @@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ @@ -203,21 +232,25 @@ MAINTAINERCLEANFILES = Makefile.in @INSTALL_LIBOPTS_FALSE@noinst_LTLIBRARIES = libopts.la libopts_la_SOURCES = libopts.c libopts_la_CPPFLAGS = -I$(top_srcdir) -libopts_la_LDFLAGS = -version-info 29:0:4 +libopts_la_LDFLAGS = -version-info 35:0:10 EXTRA_DIST = \ - COPYING.lgpl COPYING.mbsd MakeDefs.inc \ - README autoopts/options.h autoopts/usage-txt.h \ + COPYING.gplv3 COPYING.lgplv3 COPYING.mbsd \ + MakeDefs.inc README ag-char-map.h \ + autoopts/usage-txt.h autoopts/options.h autoopts/project.h \ autoopts.c autoopts.h boolean.c \ - compat/windows-config.h compat/compat.h compat/pathfind.c \ - compat/snprintf.c compat/strdup.c compat/strchr.c \ + compat/strdup.c compat/compat.h compat/windows-config.h \ + compat/snprintf.c compat/strchr.c compat/pathfind.c \ configfile.c cook.c enumeration.c \ - environment.c genshell.c genshell.h \ - load.c m4/libopts.m4 m4/liboptschk.m4 \ - makeshell.c nested.c numeric.c \ + environment.c file.c genshell.c \ + genshell.h load.c m4/liboptschk.m4 \ + m4/libopts.m4 makeshell.c nested.c \ + numeric.c parse-duration.c parse-duration.h \ pgusage.c proto.h putshell.c \ - restore.c save.c sort.c \ - stack.c streqvcmp.c text_mmap.c \ - tokenize.c usage.c version.c + reset.c restore.c save.c \ + sort.c stack.c streqvcmp.c \ + text_mmap.c time.c tokenize.c \ + usage.c value-type.c value-type.h \ + version.c xat-attribute.c xat-attribute.h all: all-am @@ -232,9 +265,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libopts/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libopts/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu libopts/Makefile + $(AUTOMAKE) --foreign libopts/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/sntp/libopts/README b/sntp/libopts/README index 7cbe0b044feb..afa540987412 100644 --- a/sntp/libopts/README +++ b/sntp/libopts/README @@ -1,11 +1,11 @@ THIS TARBALL IS NOT A FULL DISTRIBUTION. The contents of this tarball is designed to be incorporated into -software packages that utilize the AutoOpts option automation -package and are intended to be installed on systems that may not -have libopts installed. It is redistributable under the terms -of either the LGPL (see COPYING.lgpl) or under the terms of -the advertising clause free BSD license (see COPYING.mbsd). +software packages that utilize the AutoOpts option automation package +and are intended to be installed on systems that may not have libopts +installed. It is redistributable under the terms of either the LGPL +(see COPYING.lgpl) or under the terms of the advertising clause free BSD +license (see COPYING.mbsd). Usage Instructions for autoconf/automake/libtoolized projects: @@ -28,20 +28,8 @@ Usage Instructions for autoconf/automake/libtoolized projects: This is one macro where you *MUST* remember to *NOT* quote the argument. If you do, automake will get lost. -2. Add the following to your ``configure.ac'' file: - - LIBOPTS_CHECK - - or: - - LIBOPTS_CHECK([relative/path/to/libopts]) - - This macro will automatically invoke - - AC_CONFIG_FILES( [relative/path/to/libopts/Makefile] ) - - The default ``relative/path/to/libopts'' is simply - ``libopts''. +2. Add an invocation of either LIBOPTS_CHECK or LIBOPTS_CHECK_NOBUILD + to your configure.ac file. See LIBOPTS_CHECK: below for details. 3. Add the following to your top level ``Makefile.am'' file: @@ -49,13 +37,13 @@ Usage Instructions for autoconf/automake/libtoolized projects: SUBDIRS += $(LIBOPTS_DIR) endif - where ``<...>'' can be whatever other files or directories - you may need. The SUBDIRS must be properly ordered. - *PLEASE NOTE* it is crucial that the SUBDIRS be set under the - control of an automake conditional. To work correctly, - automake has to know the range of possible values of SUBDIRS. - It's a magical name with magical properties. ``NEED_LIBOPTS'' - will be correctly set by the ``LIBOPTS_CHECK'' macro, above. + where ``<...>'' can be whatever other files or directories you may + need. The SUBDIRS must be properly ordered. *PLEASE NOTE* it is + crucial that the SUBDIRS be set under the control of an automake + conditional. To work correctly, automake has to know the range of + possible values of SUBDIRS. It's a magical name with magical + properties. ``NEED_LIBOPTS'' will be correctly set by the + ``LIBOPTS_CHECK'' macro, above. 4. Add ``$(LIBOPTS_CFLAGS)'' to relevant compiler flags and ``$(LIBOPTS_LDADD)'' to relevant link options whereever @@ -75,19 +63,60 @@ Usage Instructions for autoconf/automake/libtoolized projects: man_MANS = prog.1 prog.1 : prog-opts.def - autogen -Tagman1.tpl -bprog prog-opts.def + autogen -Tagman-cmd.tpl -bprog prog-opts.def - prog-invoke.texi : prog-opts.def - autogen -Taginfo.tpl -bprog-invoke prog-opts.def + invoke-prog.texi : prog-opts.def + autogen -Tagtexi-cmd.tpl prog-opts.def If your package does not utilize the auto* tools, then you will need to hand craft the rules for building the library. +LIBOPTS_CHECK: + +The arguments to both macro are a relative path to the directory with +the libopts source code. It is optional and defaults to "libopts". +These macros work as follows: + +1. LIBOPTS_CHECK([libopts/rel/path/optional]) + + Adds two command-line options to the generated configure script, + --enable-local-libopts and --disable-libopts-install. AC_SUBST's + LIBOPTS_CFLAGS, LIBOPTS_LDADD, and LIBOPTS_DIR for use in + Makefile.am files. Adds Automake conditional NEED_LIBOPTS which + will be true when the local copy of libopts should be built. Uses + AC_CONFIG_FILES([$libopts-dir/Makefile]) to cause the local libopts + into the package build. If the optional relative path to libopts is + not provided, it defaults to simply "libopts". + +2. LIBOPTS_CHECK_NOBUILD([libopts/rel/path/optional]) + + This variant of LIBOPTS_CHECK is useful when multiple configure.ac + files in a package make use of a single libopts tearoff. In that + case, only one of the configure.ac files should build libopts and + others should simply use it. Consider this package arrangment: + + all-tools/ + configure.ac + common-tools/ + configure.ac + libopts/ + + The parent package all-tools contains a subpackage common-tools + which can be torn off and used independently. Programs configured + by both configure.ac files link against the common-tools/libopts + tearoff, when not using the system's libopts. The top-level + configure.ac uses LIBOPTS_CHECK_NOBUILD([common-tools/libopts]), + while common-tools/configure.ac uses LIBOPTS_CHECK. The difference + is LIBOPTS_CHECK_NOBUILD will never build the libopts tearoff, + leaving that to the subpackage configure.ac's LIBOPTS_CHECK. + Specifically, LIBOPTS_CHECK_NOBUILD always results in the + NEED_LIBOPTS Automake conditional being false, and does not invoke + AC_CONFIG_FILES(path-to-libopts/Makefile). + LICENSING: -This material is copyright 1993-2007 by Bruce Korb. -You are licensed to use this under the terms of either -the GNU Lesser General Public License (see: COPYING.lgpl), or, -at your option, the modified Berkeley Software Distribution -License (see: COPYING.mbsd). Both of these files should be -included with this tarball. +This material is Copyright (c) 1992-2011 by Bruce Korb. You are +licensed to use this under the terms of either the GNU Lesser General +Public License (see: COPYING.lgpl), or, at your option, the modified +Berkeley Software Distribution License (see: COPYING.mbsd). Both of +these files should be included with this tarball. diff --git a/sntp/libopts/ag-char-map.h b/sntp/libopts/ag-char-map.h new file mode 100644 index 000000000000..b4f088ef3a4b --- /dev/null +++ b/sntp/libopts/ag-char-map.h @@ -0,0 +1,192 @@ +/* + * Character mapping generated 04/29/11 15:43:58 + * + * This file contains the character classifications + * used by AutoGen and AutoOpts for identifying tokens. + * This file is part of AutoGen. + * AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * AutoGen 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 3 of the License, or (at your option) any later + * version. + * AutoGen 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, see <http://www.gnu.org/licenses/>. + */ +#ifndef AG_CHAR_MAP_H_GUARD +#define AG_CHAR_MAP_H_GUARD 1 + +#ifdef HAVE_CONFIG_H +# if defined(HAVE_INTTYPES_H) +# include <inttypes.h> +# elif defined(HAVE_STDINT_H) +# include <stdint.h> + +# else +# ifndef HAVE_INT8_T + typedef signed char int8_t; +# endif +# ifndef HAVE_UINT8_T + typedef unsigned char uint8_t; +# endif +# ifndef HAVE_INT16_T + typedef signed short int16_t; +# endif +# ifndef HAVE_UINT16_T + typedef unsigned short uint16_t; +# endif +# ifndef HAVE_UINT_T + typedef unsigned int uint_t; +# endif + +# ifndef HAVE_INT32_T +# if SIZEOF_INT == 4 + typedef signed int int32_t; +# elif SIZEOF_LONG == 4 + typedef signed long int32_t; +# endif +# endif + +# ifndef HAVE_UINT32_T +# if SIZEOF_INT == 4 + typedef unsigned int uint32_t; +# elif SIZEOF_LONG == 4 + typedef unsigned long uint32_t; +# endif +# endif +# endif /* HAVE_*INT*_H header */ + +#else /* not HAVE_CONFIG_H -- */ +# ifdef __sun +# include <inttypes.h> +# else +# include <stdint.h> +# endif +#endif /* HAVE_CONFIG_H */ + +#if 0 /* mapping specification source (from autogen.map) */ +// +// %guard autoopts_internal +// %file ag-char-map.h +// %static-table option-char-category +// +// %comment +// This file contains the character classifications +// used by AutoGen and AutoOpts for identifying tokens. +// +// This file is part of AutoGen. +// AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved +// +// AutoGen 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 3 of the License, or (at your option) any later +// version. +// +// AutoGen 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, see <http://www.gnu.org/licenses/>. +// % +// +// lower-case "a-z" +// upper-case "A-Z" +// alphabetic +lower-case +upper-case +// oct-digit "0-7" +// dec-digit "89" +oct-digit +// hex-digit "a-fA-F" +dec-digit +// alphanumeric +alphabetic +dec-digit +// var-first "_" +alphabetic +// variable-name +var-first +dec-digit +// option-name "^-" +variable-name +// value-name ":" +option-name +// horiz-white "\t " +// compound-name "[.]" +value-name +horiz-white +// whitespace "\v\f\r\n\b" +horiz-white +// unquotable "!-~" -"\"#(),;<=>[\\]`{}?*'" +// end-xml-token "/>" +whitespace +// graphic "!-~" +// plus-n-space "+" +whitespace +// punctuation "!-~" -alphanumeric -"_" +// suffix "-._" +alphanumeric +// suffix-fmt "%/" +suffix +// false-type "nNfF0\x00" +// file-name "/" +suffix +// end-token "\x00" +whitespace +// end-list-entry "," +end-token +// +#endif /* 0 -- mapping spec. source */ + +typedef uint32_t option_char_category_mask_t; +static option_char_category_mask_t const option_char_category[128]; + +static inline int is_option_char_category_char(char ch, option_char_category_mask_t mask) { + unsigned int ix = (unsigned char)ch; + return ((ix < 128) && ((option_char_category[ix] & mask) != 0)); } + +#define IS_LOWER_CASE_CHAR(_c) is_option_char_category_char((_c), 0x000001) +#define IS_UPPER_CASE_CHAR(_c) is_option_char_category_char((_c), 0x000002) +#define IS_ALPHABETIC_CHAR(_c) is_option_char_category_char((_c), 0x000003) +#define IS_OCT_DIGIT_CHAR(_c) is_option_char_category_char((_c), 0x000004) +#define IS_DEC_DIGIT_CHAR(_c) is_option_char_category_char((_c), 0x00000C) +#define IS_HEX_DIGIT_CHAR(_c) is_option_char_category_char((_c), 0x00001C) +#define IS_ALPHANUMERIC_CHAR(_c) is_option_char_category_char((_c), 0x00000F) +#define IS_VAR_FIRST_CHAR(_c) is_option_char_category_char((_c), 0x000023) +#define IS_VARIABLE_NAME_CHAR(_c) is_option_char_category_char((_c), 0x00002F) +#define IS_OPTION_NAME_CHAR(_c) is_option_char_category_char((_c), 0x00006F) +#define IS_VALUE_NAME_CHAR(_c) is_option_char_category_char((_c), 0x0000EF) +#define IS_HORIZ_WHITE_CHAR(_c) is_option_char_category_char((_c), 0x000100) +#define IS_COMPOUND_NAME_CHAR(_c) is_option_char_category_char((_c), 0x0003EF) +#define IS_WHITESPACE_CHAR(_c) is_option_char_category_char((_c), 0x000500) +#define IS_UNQUOTABLE_CHAR(_c) is_option_char_category_char((_c), 0x000800) +#define IS_END_XML_TOKEN_CHAR(_c) is_option_char_category_char((_c), 0x001500) +#define IS_GRAPHIC_CHAR(_c) is_option_char_category_char((_c), 0x002000) +#define IS_PLUS_N_SPACE_CHAR(_c) is_option_char_category_char((_c), 0x004500) +#define IS_PUNCTUATION_CHAR(_c) is_option_char_category_char((_c), 0x008000) +#define IS_SUFFIX_CHAR(_c) is_option_char_category_char((_c), 0x01000F) +#define IS_SUFFIX_FMT_CHAR(_c) is_option_char_category_char((_c), 0x03000F) +#define IS_FALSE_TYPE_CHAR(_c) is_option_char_category_char((_c), 0x040000) +#define IS_FILE_NAME_CHAR(_c) is_option_char_category_char((_c), 0x09000F) +#define IS_END_TOKEN_CHAR(_c) is_option_char_category_char((_c), 0x100500) +#define IS_END_LIST_ENTRY_CHAR(_c) is_option_char_category_char((_c), 0x300500) + +#if 1 /* def AUTOOPTS_INTERNAL */ +static option_char_category_mask_t const option_char_category[128] = { + /*x00*/ 0x140000, /*x01*/ 0x000000, /*x02*/ 0x000000, /*x03*/ 0x000000, + /*x04*/ 0x000000, /*x05*/ 0x000000, /*x06*/ 0x000000, /*\a */ 0x000000, + /*\b */ 0x000400, /*\t */ 0x000100, /*\n */ 0x000400, /*\v */ 0x000400, + /*\f */ 0x000400, /*\r */ 0x000400, /*x0E*/ 0x000000, /*x0F*/ 0x000000, + /*x10*/ 0x000000, /*x11*/ 0x000000, /*x12*/ 0x000000, /*x13*/ 0x000000, + /*x14*/ 0x000000, /*x15*/ 0x000000, /*x16*/ 0x000000, /*x17*/ 0x000000, + /*x18*/ 0x000000, /*x19*/ 0x000000, /*x1A*/ 0x000000, /*x1B*/ 0x000000, + /*x1C*/ 0x000000, /*x1D*/ 0x000000, /*x1E*/ 0x000000, /*x1F*/ 0x000000, + /* */ 0x000100, /* ! */ 0x00A800, /* " */ 0x00A000, /* # */ 0x00A000, + /* $ */ 0x00A800, /* % */ 0x02A800, /* & */ 0x00A800, /* ' */ 0x00A000, + /* ( */ 0x00A000, /* ) */ 0x00A000, /* * */ 0x00A000, /* + */ 0x00E800, + /* , */ 0x20A000, /* - */ 0x01A840, /* . */ 0x01AA00, /* / */ 0x0AB800, + /* 0 */ 0x042804, /* 1 */ 0x002804, /* 2 */ 0x002804, /* 3 */ 0x002804, + /* 4 */ 0x002804, /* 5 */ 0x002804, /* 6 */ 0x002804, /* 7 */ 0x002804, + /* 8 */ 0x002808, /* 9 */ 0x002808, /* : */ 0x00A880, /* ; */ 0x00A000, + /* < */ 0x00A000, /* = */ 0x00A000, /* > */ 0x00B000, /* ? */ 0x00A000, + /* @ */ 0x00A800, /* A */ 0x002812, /* B */ 0x002812, /* C */ 0x002812, + /* D */ 0x002812, /* E */ 0x002812, /* F */ 0x042812, /* G */ 0x002802, + /* H */ 0x002802, /* I */ 0x002802, /* J */ 0x002802, /* K */ 0x002802, + /* L */ 0x002802, /* M */ 0x002802, /* N */ 0x042802, /* O */ 0x002802, + /* P */ 0x002802, /* Q */ 0x002802, /* R */ 0x002802, /* S */ 0x002802, + /* T */ 0x002802, /* U */ 0x002802, /* V */ 0x002802, /* W */ 0x002802, + /* X */ 0x002802, /* Y */ 0x002802, /* Z */ 0x002802, /* [ */ 0x00A200, + /* \ */ 0x00A000, /* ] */ 0x00A200, /* ^ */ 0x00A840, /* _ */ 0x012820, + /* ` */ 0x00A000, /* a */ 0x002811, /* b */ 0x002811, /* c */ 0x002811, + /* d */ 0x002811, /* e */ 0x002811, /* f */ 0x042811, /* g */ 0x002801, + /* h */ 0x002801, /* i */ 0x002801, /* j */ 0x002801, /* k */ 0x002801, + /* l */ 0x002801, /* m */ 0x002801, /* n */ 0x042801, /* o */ 0x002801, + /* p */ 0x002801, /* q */ 0x002801, /* r */ 0x002801, /* s */ 0x002801, + /* t */ 0x002801, /* u */ 0x002801, /* v */ 0x002801, /* w */ 0x002801, + /* x */ 0x002801, /* y */ 0x002801, /* z */ 0x002801, /* { */ 0x00A000, + /* | */ 0x00A800, /* } */ 0x00A000, /* ~ */ 0x00A800, /*x7F*/ 0x000000 +}; +#endif /* AUTOOPTS_INTERNAL */ +#endif /* AG_CHAR_MAP_H_GUARD */ diff --git a/sntp/libopts/autoopts.c b/sntp/libopts/autoopts.c index 139841bbb2a1..657818181b82 100644 --- a/sntp/libopts/autoopts.c +++ b/sntp/libopts/autoopts.c @@ -1,81 +1,80 @@ -/* - * $Id: autoopts.c,v 4.25 2007/04/15 19:01:18 bkorb Exp $ - * Time-stamp: "2007-04-15 11:10:40 bkorb" +/** + * \file autoopts.c + * + * Time-stamp: "2011-03-25 17:55:07 bkorb" * * This file contains all of the routines that must be linked into * an executable to use the generated option processing. The optional * routines are in separately compiled modules so that they will not * necessarily be linked in. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -static char const zNil[] = ""; +#ifndef PKGDATADIR +# define PKGDATADIR "" +#endif + +static char const zNil[] = ""; +static arg_types_t argTypes = { NULL }; +static char zOptFmtLine[16] = { NUL }; +static ag_bool displayEnum = AG_FALSE; +static char const pkgdatadir_default[] = PKGDATADIR; +static char const * program_pkgdatadir = pkgdatadir_default; +static tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED; +static tePagerState pagerState = PAGER_STATE_INITIAL; + + FILE * option_usage_fp = NULL; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static tSuccess -findOptDesc( tOptions* pOpts, tOptState* pOptState ); +findOptDesc(tOptions* pOpts, tOptState* pOptState); static tSuccess -nextOption( tOptions* pOpts, tOptState* pOptState ); +next_opt_arg_must(tOptions* pOpts, tOptState* pOptState); static tSuccess -doPresets( tOptions* pOpts ); +next_opt_arg_may(tOptions* pOpts, tOptState* pOptState); + +static tSuccess +next_opt_arg_none(tOptions* pOpts, tOptState* pOptState); + +static tSuccess +nextOption(tOptions* pOpts, tOptState* pOptState); + +static tSuccess +doPresets(tOptions* pOpts); static int -checkConsistency( tOptions* pOpts ); +checkConsistency(tOptions* pOpts); /* = = = END-STATIC-FORWARD = = = */ LOCAL void * -ao_malloc( size_t sz ) +ao_malloc(size_t sz) { void * res = malloc(sz); if (res == NULL) { - fprintf( stderr, "malloc of %d bytes failed\n", (int)sz ); - exit( EXIT_FAILURE ); + fprintf(stderr, zAO_Alloc, (int)sz); + exit(EXIT_FAILURE); } return res; } @@ -83,36 +82,25 @@ ao_malloc( size_t sz ) #define malloc(_s) ao_malloc(_s) LOCAL void * -ao_realloc( void *p, size_t sz ) +ao_realloc(void *p, size_t sz) { - void * res = realloc(p, sz); + void * res = (p == NULL) ? malloc(sz) : realloc(p, sz); if (res == NULL) { - fprintf( stderr, "realloc of %d bytes at 0x%p failed\n", (int)sz, p ); - exit( EXIT_FAILURE ); + fprintf(stderr, zAO_Realloc, (int)sz, p); + exit(EXIT_FAILURE); } return res; } #undef realloc #define realloc(_p,_s) ao_realloc(_p,_s) - -LOCAL void -ao_free( void *p ) -{ - if (p != NULL) - free(p); -} -#undef free -#define free(_p) ao_free(_p) - - LOCAL char * -ao_strdup( char const *str ) +ao_strdup(char const *str) { char * res = strdup(str); if (res == NULL) { - fprintf( stderr, "strdup of %d byte string failed\n", (int)strlen(str) ); - exit( EXIT_FAILURE ); + fprintf(stderr, zAO_Strdup, (int)strlen(str)); + exit(EXIT_FAILURE); } return res; } @@ -136,13 +124,13 @@ ao_strdup( char const *str ) #endif /* - * handleOption + * handle_opt * * This routine handles equivalencing, sets the option state flags and * invokes the handler procedure, if any. */ LOCAL tSuccess -handleOption( tOptions* pOpts, tOptState* pOptState ) +handle_opt(tOptions* pOpts, tOptState* pOptState) { /* * Save a copy of the option procedure pointer. @@ -190,8 +178,8 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) * THEN we have a usage problem. */ if (p->optActualIndex != pOD->optIndex) { - fprintf( stderr, (char*)zMultiEquiv, p->pz_Name, pOD->pz_Name, - (pOpts->pOptDesc + p->optActualIndex)->pz_Name); + fprintf(stderr, (char*)zMultiEquiv, p->pz_Name, pOD->pz_Name, + (pOpts->pOptDesc + p->optActualIndex)->pz_Name); return FAILURE; } } else { @@ -240,7 +228,7 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) char const * pzEqv = (pOD->optEquivIndex != NO_EQUIVALENT) ? zEquiv : zNil; - fputs( zErrOnly, stderr ); + fputs(zErrOnly, stderr); if (pOD->optMaxCt > 1) fprintf(stderr, zAtMost, pOD->optMaxCt, pOD->pz_Name, pzEqv); @@ -254,8 +242,8 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) /* * If provided a procedure to call, call it */ - if (pOP != (tpOptProc)NULL) - (*pOP)( pOpts, pOD ); + if (pOP != NULL) + (*pOP)(pOpts, pOD); return SUCCESS; } @@ -274,32 +262,45 @@ handleOption( tOptions* pOpts, tOptState* pOptState ) * Find the long option descriptor for the current option */ LOCAL tSuccess -longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) +longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState) { ag_bool disable = AG_FALSE; - char* pzEq = strchr( pzOptName, '=' ); + char* pzEq = strchr(pzOptName, '='); tOptDesc* pOD = pOpts->pOptDesc; int idx = 0; int idxLim = pOpts->optCt; int matchCt = 0; int matchIdx = 0; int nameLen; + char opt_name_buf[128]; /* * IF the value is attached to the name, - * THEN clip it off. - * Either way, figure out how long our name is + * copy it off so we can NUL terminate. */ if (pzEq != NULL) { nameLen = (int)(pzEq - pzOptName); - *pzEq = NUL; - } else nameLen = strlen( pzOptName ); + if (nameLen >= sizeof(opt_name_buf)) + return FAILURE; + memcpy(opt_name_buf, pzOptName, nameLen); + opt_name_buf[nameLen] = NUL; + pzOptName = opt_name_buf; + pzEq++; + + } else nameLen = strlen(pzOptName); do { - if (SKIP_OPT(pOD)) + /* + * If option disabled or a doc option, skip to next + */ + if (pOD->pz_Name == NULL) continue; - if (strneqvcmp( pzOptName, pOD->pz_Name, nameLen ) == 0) { + if ( SKIP_OPT(pOD) + && (pOD->fOptState != (OPTST_OMITTED | OPTST_NO_INIT))) + continue; + + if (strneqvcmp(pzOptName, pOD->pz_Name, nameLen) == 0) { /* * IF we have a complete match * THEN it takes priority over any already located partial @@ -348,13 +349,21 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) } while (pOD++, (++idx < idxLim)); - if (pzEq != NULL) - *(pzEq++) = '='; - /* * Make sure we either found an exact match or found only one partial */ if (matchCt == 1) { + pOD = pOpts->pOptDesc + matchIdx; + + if (SKIP_OPT(pOD)) { + fprintf(stderr, zDisabledErr, pOpts->pzProgName, pOD->pz_Name); + if (pOD->pzText != NULL) + fprintf(stderr, " -- %s", pOD->pzText); + fputc('\n', stderr); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + /* * IF we found a disablement name, * THEN set the bit in the callers' flag word @@ -362,7 +371,7 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) if (disable) pOptState->flags |= OPTST_DISABLED; - pOptState->pOD = pOpts->pOptDesc + matchIdx; + pOptState->pOD = pOD; pOptState->pzOptArg = pzEq; pOptState->optType = TOPT_LONG; return SUCCESS; @@ -389,9 +398,9 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) * THEN call the usage procedure. */ if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) { - fprintf( stderr, zIllOptStr, pOpts->pzProgPath, - (matchCt == 0) ? zIllegal : zAmbiguous, pzOptName ); - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + fprintf(stderr, (matchCt == 0) ? zIllOptStr : zAmbigOptStr, + pOpts->pzProgPath, pzOptName); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); } return FAILURE; @@ -404,7 +413,7 @@ longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ) * Find the short option descriptor for the current option */ LOCAL tSuccess -shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) +shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState) { tOptDesc* pRes = pOpts->pOptDesc; int ct = pOpts->optCt; @@ -412,28 +421,28 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) /* * Search the option list */ - for (;;) { - /* - * IF the values match, - * THEN we stop here - */ - if ((! SKIP_OPT(pRes)) && (optValue == pRes->optValue)) { - pOptState->pOD = pRes; - pOptState->optType = TOPT_SHORT; - return SUCCESS; + do { + if (optValue != pRes->optValue) + continue; + + if (SKIP_OPT(pRes)) { + if ( (pRes->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) + && (pRes->pz_Name != NULL)) { + fprintf(stderr, zDisabledErr, pOpts->pzProgPath, pRes->pz_Name); + if (pRes->pzText != NULL) + fprintf(stderr, " -- %s", pRes->pzText); + fputc('\n', stderr); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + goto short_opt_error; } - /* - * Advance to next option description - */ - pRes++; + pOptState->pOD = pRes; + pOptState->optType = TOPT_SHORT; + return SUCCESS; - /* - * IF we have searched everything, ... - */ - if (--ct <= 0) - break; - } + } while (pRes++, --ct > 0); /* * IF the character value is a digit @@ -441,7 +450,7 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) * THEN the result is the "option" itself and the * option is the specially marked "number" option. */ - if ( isdigit( optValue ) + if ( IS_DEC_DIGIT_CHAR(optValue) && (pOpts->specOptIdx.number_option != NO_EQUIVALENT) ) { pOptState->pOD = \ pRes = pOpts->pOptDesc + pOpts->specOptIdx.number_option; @@ -450,13 +459,15 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) return SUCCESS; } +short_opt_error: + /* * IF we are to stop on errors (the default, actually) * THEN call the usage procedure. */ if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) { - fprintf( stderr, zIllOptChr, pOpts->pzProgPath, optValue ); - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + fprintf(stderr, zIllOptChr, pOpts->pzProgPath, optValue); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); } return FAILURE; @@ -469,7 +480,7 @@ shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ) * Find the option descriptor for the current option */ static tSuccess -findOptDesc( tOptions* pOpts, tOptState* pOptState ) +findOptDesc(tOptions* pOpts, tOptState* pOptState) { /* * IF we are continuing a short option list (e.g. -xyz...) @@ -477,7 +488,7 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * OTHERWISE see if there is room to advance and then do so. */ if ((pOpts->pzCurOpt != NULL) && (*pOpts->pzCurOpt != NUL)) - return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState ); + return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState); if (pOpts->curOptIdx >= pOpts->origArgCt) return PROBLEM; /* NORMAL COMPLETION */ @@ -488,16 +499,28 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * IF all arguments must be named options, ... */ if (NAMED_OPTS(pOpts)) { - char* pz = pOpts->pzCurOpt; + char * pz = pOpts->pzCurOpt; + int def; + tSuccess res; + tAoUS * def_opt; + pOpts->curOptIdx++; + if (*pz != '-') + return longOptionFind(pOpts, pz, pOptState); + /* - * Skip over any flag/option markers. - * In this mode, they are not required. + * The name is prefixed with one or more hyphens. Strip them off + * and disable the "default_opt" setting. Use heavy recasting to + * strip off the "const" quality of the "default_opt" field. */ - while (*pz == '-') pz++; - - return longOptionFind( pOpts, pz, pOptState ); + while (*(++pz) == '-') ; + def_opt = (void *)&(pOpts->specOptIdx.default_opt); + def = *def_opt; + *def_opt = NO_EQUIVALENT; + res = longOptionFind(pOpts, pz, pOptState); + *def_opt = def; + return res; } /* @@ -533,12 +556,12 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * Therefore, if long options are not to be accepted, we punt. */ if ((pOpts->fOptSet & OPTPROC_LONGOPT) == 0) { - fprintf( stderr, zIllOptStr, pOpts->pzProgPath, - zIllegal, pOpts->pzCurOpt-2 ); + fprintf(stderr, zIllOptStr, pOpts->pzProgPath, + zIllegal, pOpts->pzCurOpt-2); return FAILURE; } - return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState ); + return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState); } /* @@ -547,193 +570,218 @@ findOptDesc( tOptions* pOpts, tOptState* pOptState ) * short (i.e. single character) option. */ if ((pOpts->fOptSet & OPTPROC_SHORTOPT) != 0) - return shortOptionFind( pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState ); + return shortOptionFind(pOpts, (tAoUC)*(pOpts->pzCurOpt), pOptState); - return longOptionFind( pOpts, pOpts->pzCurOpt, pOptState ); + return longOptionFind(pOpts, pOpts->pzCurOpt, pOptState); } -/* - * nextOption - * - * Find the option descriptor and option argument (if any) for the - * next command line argument. DO NOT modify the descriptor. Put - * all the state in the state argument so that the option can be skipped - * without consequence (side effect). - */ static tSuccess -nextOption( tOptions* pOpts, tOptState* pOptState ) +next_opt_arg_must(tOptions* pOpts, tOptState* pOptState) { - tSuccess res; - enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE; - teOptArgType at; - - res = findOptDesc( pOpts, pOptState ); - if (! SUCCESSFUL( res )) - return res; - pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK); - at = OPTST_GET_ARGTYPE(pOptState->flags); - /* - * Figure out what to do about option arguments. An argument may be - * required, not associated with the option, or be optional. We detect the - * latter by examining for an option marker on the next possible argument. - * Disabled mode option selection also disables option arguments. + * An option argument is required. Long options can either have + * a separate command line argument, or an argument attached by + * the '=' character. Figure out which. */ - if ((pOptState->flags & OPTST_DISABLED) != 0) - arg_type = ARG_NONE; - else if (at == OPARG_TYPE_NONE) - arg_type = ARG_NONE; - else if (pOptState->flags & OPTST_ARG_OPTIONAL) - arg_type = ARG_MAY; - else - arg_type = ARG_MUST; - - switch (arg_type) { - case ARG_MUST: + switch (pOptState->optType) { + case TOPT_SHORT: /* - * An option argument is required. Long options can either have - * a separate command line argument, or an argument attached by - * the '=' character. Figure out which. + * See if an arg string follows the flag character */ - switch (pOptState->optType) { - case TOPT_SHORT: - /* - * See if an arg string follows the flag character - */ - if (*++(pOpts->pzCurOpt) == NUL) - pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx++ ]; - pOptState->pzOptArg = pOpts->pzCurOpt; - break; + if (*++(pOpts->pzCurOpt) == NUL) + pOpts->pzCurOpt = pOpts->origArgVect[ pOpts->curOptIdx++ ]; + pOptState->pzOptArg = pOpts->pzCurOpt; + break; - case TOPT_LONG: - /* - * See if an arg string has already been assigned (glued on - * with an `=' character) - */ - if (pOptState->pzOptArg == NULL) - pOptState->pzOptArg = pOpts->origArgVect[ pOpts->curOptIdx++ ]; - break; + case TOPT_LONG: + /* + * See if an arg string has already been assigned (glued on + * with an `=' character) + */ + if (pOptState->pzOptArg == NULL) + pOptState->pzOptArg = pOpts->origArgVect[ pOpts->curOptIdx++ ]; + break; - default: + default: #ifdef DEBUG - fputs( "AutoOpts lib error: option type not selected\n", - stderr ); - exit( EXIT_FAILURE ); + fputs("AutoOpts lib error: option type not selected\n", stderr); + exit(EXIT_FAILURE); #endif - case TOPT_DEFAULT: - /* - * The option was selected by default. The current token is - * the option argument. - */ - break; - } - + case TOPT_DEFAULT: /* - * Make sure we did not overflow the argument list. + * The option was selected by default. The current token is + * the option argument. */ - if (pOpts->curOptIdx > pOpts->origArgCt) { - fprintf( stderr, zMisArg, pOpts->pzProgPath, - pOptState->pOD->pz_Name ); - return FAILURE; - } - - pOpts->pzCurOpt = NULL; /* next time advance to next arg */ break; + } - case ARG_MAY: - /* - * An option argument is optional. - */ - switch (pOptState->optType) { - case TOPT_SHORT: - if (*++pOpts->pzCurOpt != NUL) - pOptState->pzOptArg = pOpts->pzCurOpt; - else { - char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ]; - - /* - * BECAUSE it is optional, we must make sure - * we did not find another flag and that there - * is such an argument. - */ - if ((pzLA == NULL) || (*pzLA == '-')) - pOptState->pzOptArg = NULL; - else { - pOpts->curOptIdx++; /* argument found */ - pOptState->pzOptArg = pzLA; - } - } - break; + /* + * Make sure we did not overflow the argument list. + */ + if (pOpts->curOptIdx > pOpts->origArgCt) { + fprintf(stderr, zMisArg, pOpts->pzProgPath, pOptState->pOD->pz_Name); + return FAILURE; + } + + pOpts->pzCurOpt = NULL; /* next time advance to next arg */ + return SUCCESS; +} + + +static tSuccess +next_opt_arg_may(tOptions* pOpts, tOptState* pOptState) +{ + /* + * An option argument is optional. + */ + switch (pOptState->optType) { + case TOPT_SHORT: + if (*++pOpts->pzCurOpt != NUL) + pOptState->pzOptArg = pOpts->pzCurOpt; + else { + char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ]; - case TOPT_LONG: /* - * Look for an argument if we don't already have one (glued on - * with a `=' character) *AND* we are not in named argument mode + * BECAUSE it is optional, we must make sure + * we did not find another flag and that there + * is such an argument. */ - if ( (pOptState->pzOptArg == NULL) - && (! NAMED_OPTS(pOpts))) { - char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ]; - - /* - * BECAUSE it is optional, we must make sure - * we did not find another flag and that there - * is such an argument. - */ - if ((pzLA == NULL) || (*pzLA == '-')) - pOptState->pzOptArg = NULL; - else { - pOpts->curOptIdx++; /* argument found */ - pOptState->pzOptArg = pzLA; - } + if ((pzLA == NULL) || (*pzLA == '-')) + pOptState->pzOptArg = NULL; + else { + pOpts->curOptIdx++; /* argument found */ + pOptState->pzOptArg = pzLA; } - break; - - default: - case TOPT_DEFAULT: - fputs( "AutoOpts lib error: defaulted to option with optional arg\n", - stderr ); - exit( EX_SOFTWARE ); } - - /* - * After an option with an optional argument, we will - * *always* start with the next option because if there - * were any characters following the option name/flag, - * they would be interpreted as the argument. - */ - pOpts->pzCurOpt = NULL; break; - default: /* CANNOT */ + case TOPT_LONG: /* - * No option argument. Make sure next time around we find - * the correct option flag character for short options + * Look for an argument if we don't already have one (glued on + * with a `=' character) *AND* we are not in named argument mode */ - if (pOptState->optType == TOPT_SHORT) - (pOpts->pzCurOpt)++; + if ( (pOptState->pzOptArg == NULL) + && (! NAMED_OPTS(pOpts))) { + char* pzLA = pOpts->origArgVect[ pOpts->curOptIdx ]; - /* - * It is a long option. Make sure there was no ``=xxx'' argument - */ - else if (pOptState->pzOptArg != NULL) { - fprintf( stderr, zNoArg, pOpts->pzProgPath, - pOptState->pOD->pz_Name ); - return FAILURE; + /* + * BECAUSE it is optional, we must make sure + * we did not find another flag and that there + * is such an argument. + */ + if ((pzLA == NULL) || (*pzLA == '-')) + pOptState->pzOptArg = NULL; + else { + pOpts->curOptIdx++; /* argument found */ + pOptState->pzOptArg = pzLA; + } } + break; - /* - * It is a long option. Advance to next command line argument. - */ - else - pOpts->pzCurOpt = NULL; + default: + case TOPT_DEFAULT: + fputs(zAO_Woops, stderr ); + exit(EX_SOFTWARE); } + /* + * After an option with an optional argument, we will + * *always* start with the next option because if there + * were any characters following the option name/flag, + * they would be interpreted as the argument. + */ + pOpts->pzCurOpt = NULL; return SUCCESS; } +static tSuccess +next_opt_arg_none(tOptions* pOpts, tOptState* pOptState) +{ + /* + * No option argument. Make sure next time around we find + * the correct option flag character for short options + */ + if (pOptState->optType == TOPT_SHORT) + (pOpts->pzCurOpt)++; + + /* + * It is a long option. Make sure there was no ``=xxx'' argument + */ + else if (pOptState->pzOptArg != NULL) { + fprintf(stderr, zNoArg, pOpts->pzProgPath, pOptState->pOD->pz_Name); + return FAILURE; + } + + /* + * It is a long option. Advance to next command line argument. + */ + else + pOpts->pzCurOpt = NULL; + return SUCCESS; +} + +/* + * nextOption + * + * Find the option descriptor and option argument (if any) for the + * next command line argument. DO NOT modify the descriptor. Put + * all the state in the state argument so that the option can be skipped + * without consequence (side effect). + */ +static tSuccess +nextOption(tOptions* pOpts, tOptState* pOptState) +{ + { + tSuccess res; + res = findOptDesc(pOpts, pOptState); + if (! SUCCESSFUL(res)) + return res; + } + + if ( ((pOptState->flags & OPTST_DEFINED) != 0) + && ((pOptState->pOD->fOptState & OPTST_NO_COMMAND) != 0)) { + fprintf(stderr, zNotCmdOpt, pOptState->pOD->pz_Name); + return FAILURE; + } + + pOptState->flags |= (pOptState->pOD->fOptState & OPTST_PERSISTENT_MASK); + + /* + * Figure out what to do about option arguments. An argument may be + * required, not associated with the option, or be optional. We detect the + * latter by examining for an option marker on the next possible argument. + * Disabled mode option selection also disables option arguments. + */ + { + enum { ARG_NONE, ARG_MAY, ARG_MUST } arg_type = ARG_NONE; + tSuccess res; + + if ((pOptState->flags & OPTST_DISABLED) != 0) + arg_type = ARG_NONE; + + else if (OPTST_GET_ARGTYPE(pOptState->flags) == OPARG_TYPE_NONE) + arg_type = ARG_NONE; + + else if (pOptState->flags & OPTST_ARG_OPTIONAL) + arg_type = ARG_MAY; + + else + arg_type = ARG_MUST; + + switch (arg_type) { + case ARG_MUST: res = next_opt_arg_must(pOpts, pOptState); break; + case ARG_MAY: res = next_opt_arg_may( pOpts, pOptState); break; + case ARG_NONE: res = next_opt_arg_none(pOpts, pOptState); break; + } + + return res; + } +} + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DO PRESETS @@ -747,11 +795,12 @@ nextOption( tOptions* pOpts, tOptState* pOptState ) * line arguments. */ -/* - * doImmediateOpts - scan the command line for immediate action options +/** + * scan the command line for immediate action options. + * This is only called the first time through. */ LOCAL tSuccess -doImmediateOpts( tOptions* pOpts ) +doImmediateOpts(tOptions* pOpts) { pOpts->curOptIdx = 1; /* start by skipping program name */ pOpts->pzCurOpt = NULL; @@ -763,73 +812,76 @@ doImmediateOpts( tOptions* pOpts ) for (;;) { tOptState optState = OPTSTATE_INITIALIZER(PRESET); - switch (nextOption( pOpts, &optState )) { - case FAILURE: goto optionsDone; + switch (nextOption(pOpts, &optState)) { + case FAILURE: goto failed_option; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; } /* - * IF this *is* an immediate-attribute option, then do it. + * IF this is an immediate-attribute option, then do it. */ if (! DO_IMMEDIATELY(optState.flags)) continue; - if (! SUCCESSFUL( handleOption( pOpts, &optState ))) + if (! SUCCESSFUL(handle_opt(pOpts, &optState))) break; - } optionsDone:; + } failed_option:; if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); + return FAILURE; } - +/** + * Process all the options from our current position onward. (This allows + * interspersed options and arguments for the few non-standard programs that + * require it.) Thus, do not rewind option indexes because some programs + * choose to re-invoke after a non-option. + */ LOCAL tSuccess -doRegularOpts( tOptions* pOpts ) +doRegularOpts(tOptions* pOpts) { - /* - * Now, process all the options from our current position onward. - * (This allows interspersed options and arguments for the few - * non-standard programs that require it.) - */ for (;;) { tOptState optState = OPTSTATE_INITIALIZER(DEFINED); - switch (nextOption( pOpts, &optState )) { - case FAILURE: goto optionsDone; + switch (nextOption(pOpts, &optState)) { + case FAILURE: goto failed_option; case PROBLEM: return SUCCESS; /* no more args */ case SUCCESS: break; } /* - * IF this is not being processed normally (i.e. is immediate action) + * IF this is an immediate action option, * THEN skip it (unless we are supposed to do it a second time). */ if (! DO_NORMALLY(optState.flags)) { if (! DO_SECOND_TIME(optState.flags)) continue; - optState.pOD->optOccCt--; /* don't count last time */ + optState.pOD->optOccCt--; /* don't count this repetition */ } - if (! SUCCESSFUL( handleOption( pOpts, &optState ))) + if (! SUCCESSFUL(handle_opt(pOpts, &optState))) break; - } optionsDone:; + } failed_option:; + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); + return FAILURE; } -/* - * doPresets - check for preset values from a config file or the envrionment +/** + * check for preset values from a config files or envrionment variables */ static tSuccess -doPresets( tOptions* pOpts ) +doPresets(tOptions* pOpts) { tOptDesc * pOD = NULL; - if (! SUCCESSFUL( doImmediateOpts( pOpts ))) + if (! SUCCESSFUL(doImmediateOpts(pOpts))) return FAILURE; /* @@ -837,7 +889,8 @@ doPresets( tOptions* pOpts ) * has a --load-opts option. See if a command line option has disabled * option presetting. */ - if (pOpts->specOptIdx.save_opts != 0) { + if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT) + && (pOpts->specOptIdx.save_opts != 0)) { pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1; if (DISABLED_OPT(pOD)) return SUCCESS; @@ -852,22 +905,22 @@ doPresets( tOptions* pOpts ) * THEN do any environment presets and leave. */ if (pOpts->papzHomeList == NULL) { - doEnvPresets( pOpts, ENV_ALL ); + doEnvPresets(pOpts, ENV_ALL); } else { - doEnvPresets( pOpts, ENV_IMM ); + doEnvPresets(pOpts, ENV_IMM); /* * Check to see if environment variables have disabled presetting. */ if ((pOD != NULL) && ! DISABLED_OPT(pOD)) - internalFileLoad( pOpts ); + internalFileLoad(pOpts); /* * ${PROGRAM_LOAD_OPTS} value of "no" cannot disable other environment * variable options. Only the loading of .rc files. */ - doEnvPresets( pOpts, ENV_NON_IMM ); + doEnvPresets(pOpts, ENV_NON_IMM); } pOpts->fOptSet &= ~OPTPROC_PRESETTING; @@ -882,7 +935,7 @@ doPresets( tOptions* pOpts ) * Make sure that the argument list passes our consistency tests. */ static int -checkConsistency( tOptions* pOpts ) +checkConsistency(tOptions* pOpts) { int errCt = 0; tOptDesc* pOD = pOpts->pOptDesc; @@ -907,7 +960,7 @@ checkConsistency( tOptions* pOpts ) if (UNUSED_OPT(p)) { const tOptDesc* pN = pOpts->pOptDesc + pMust[-1]; errCt++; - fprintf( stderr, zReqFmt, pOD->pz_Name, pN->pz_Name ); + fprintf(stderr, zReqFmt, pOD->pz_Name, pN->pz_Name); } if (*pMust == NO_EQUIVALENT) @@ -919,7 +972,7 @@ checkConsistency( tOptions* pOpts ) if (SELECTED_OPT(p)) { const tOptDesc* pN = pOpts->pOptDesc + pCant[-1]; errCt++; - fprintf( stderr, zCantFmt, pOD->pz_Name, pN->pz_Name ); + fprintf(stderr, zCantFmt, pOD->pz_Name, pN->pz_Name); } if (*pCant == NO_EQUIVALENT) @@ -951,8 +1004,8 @@ checkConsistency( tOptions* pOpts ) errCt++; if (pOD->optMinCt > 1) - fprintf( stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt ); - else fprintf( stderr, zNeedOne, pOD->pz_Name ); + fprintf(stderr, zNotEnough, pOD->pz_Name, pOD->optMinCt); + else fprintf(stderr, zNeedOne, pOD->pz_Name); } while (0); if (--oCt <= 0) @@ -971,7 +1024,7 @@ checkConsistency( tOptions* pOpts ) */ if ((pOpts->fOptSet & OPTPROC_NO_ARGS) != 0) { if (pOpts->origArgCt > pOpts->curOptIdx) { - fprintf( stderr, zNoArgs, pOpts->pzProgName ); + fprintf(stderr, zNoArgs, pOpts->pzProgName); ++errCt; } } @@ -981,7 +1034,7 @@ checkConsistency( tOptions* pOpts ) */ else if ((pOpts->fOptSet & OPTPROC_ARGS_REQ) != 0) { if (pOpts->origArgCt <= pOpts->curOptIdx) { - fprintf( stderr, zArgsMust, pOpts->pzProgName ); + fprintf(stderr, zArgsMust, pOpts->pzProgName); ++errCt; } } @@ -1044,13 +1097,10 @@ checkConsistency( tOptions* pOpts ) * ERRSKIP_OPTERR or ERRSTOP_OPTERR macros were invoked. =*/ int -optionProcess( - tOptions* pOpts, - int argCt, - char** argVect ) +optionProcess(tOptions * pOpts, int argCt, char ** argVect) { - if (! SUCCESSFUL( validateOptionsStruct( pOpts, argVect[0] ))) - exit( EX_SOFTWARE ); + if (! SUCCESSFUL(validateOptionsStruct(pOpts, argVect[0]))) + exit(EX_SOFTWARE); /* * Establish the real program name, the program full path, @@ -1060,12 +1110,28 @@ optionProcess( pOpts->origArgCt = argCt; pOpts->origArgVect = argVect; pOpts->fOptSet |= OPTPROC_INITDONE; + if (HAS_pzPkgDataDir(pOpts)) + program_pkgdatadir = pOpts->pzPkgDataDir; - if (! SUCCESSFUL( doPresets( pOpts ))) + if (! SUCCESSFUL(doPresets(pOpts))) return 0; + /* + * IF option name conversion was suppressed but it is not suppressed + * for the command line, then it's time to translate option names. + * Usage text will not get retranslated. + */ + if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0) + && (pOpts->pTransProc != NULL) + && ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK) + == OPTPROC_NXLAT_OPT_CFG) ) { + + pOpts->fOptSet &= ~OPTPROC_NXLAT_OPT_CFG; + (*pOpts->pTransProc)(); + } + if ((pOpts->fOptSet & OPTPROC_REORDER) != 0) - optionSort( pOpts ); + optionSort(pOpts); pOpts->curOptIdx = 1; pOpts->pzCurOpt = NULL; @@ -1080,7 +1146,7 @@ optionProcess( pOpts->pzCurOpt = NULL; } - if (! SUCCESSFUL( doRegularOpts( pOpts ))) + if (! SUCCESSFUL(doRegularOpts(pOpts))) return pOpts->origArgCt; /* @@ -1090,12 +1156,13 @@ optionProcess( * THEN do that now before testing for conflicts. * (conflicts are ignored in preset options) */ - if (pOpts->specOptIdx.save_opts != 0) { + if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT) + && (pOpts->specOptIdx.save_opts != 0)) { tOptDesc* pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts; - if (SELECTED_OPT( pOD )) { - optionSaveFile( pOpts ); - exit( EXIT_SUCCESS ); + if (SELECTED_OPT(pOD)) { + optionSaveFile(pOpts); + exit(EXIT_SUCCESS); } } @@ -1104,8 +1171,8 @@ optionProcess( * THEN look for too few occurrences of required options */ if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) { - if (checkConsistency( pOpts ) != 0) - (*pOpts->pUsageProc)( pOpts, EXIT_FAILURE ); + if (checkConsistency(pOpts) != 0) + (*pOpts->pUsageProc)(pOpts, EXIT_FAILURE); } return pOpts->curOptIdx; diff --git a/sntp/libopts/autoopts.h b/sntp/libopts/autoopts.h index 2645757eaa14..831a52b18808 100644 --- a/sntp/libopts/autoopts.h +++ b/sntp/libopts/autoopts.h @@ -1,61 +1,38 @@ /* - * Time-stamp: "2007-04-15 09:59:39 bkorb" + * \file autoopts.h * - * autoopts.h $Id: autoopts.h,v 4.23 2007/04/15 19:01:18 bkorb Exp $ - * Time-stamp: "2005-02-14 05:59:50 bkorb" + * Time-stamp: "2011-03-25 17:51:34 bkorb" * * This file defines all the global structures and special values * used in the automated option processing library. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. * - * Automated Options 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. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * These files have the following md5sums: * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ #ifndef AUTOGEN_AUTOOPTS_H #define AUTOGEN_AUTOOPTS_H #include "compat/compat.h" +#include "ag-char-map.h" #define AO_NAME_LIMIT 127 #define AO_NAME_SIZE ((size_t)(AO_NAME_LIMIT + 1)) @@ -110,36 +87,6 @@ typedef int tDirection; #define PROCESSING(d) ((d)>0) #define PRESETTING(d) ((d)<0) -#define ISNAMECHAR( c ) (isalnum(c) || ((c) == '_') || ((c) == '-')) - -/* - * Procedure success codes - * - * USAGE: define procedures to return "tSuccess". Test their results - * with the SUCCEEDED, FAILED and HADGLITCH macros. - * - * Microsoft sticks its nose into user space here, so for Windows' sake, - * make sure all of these are undefined. - */ -#undef SUCCESS -#undef FAILURE -#undef PROBLEM -#undef SUCCEEDED -#undef SUCCESSFUL -#undef FAILED -#undef HADGLITCH - -#define SUCCESS ((tSuccess) 0) -#define FAILURE ((tSuccess)-1) -#define PROBLEM ((tSuccess) 1) - -typedef int tSuccess; - -#define SUCCEEDED( p ) ((p) == SUCCESS) -#define SUCCESSFUL( p ) SUCCEEDED( p ) -#define FAILED( p ) ((p) < SUCCESS) -#define HADGLITCH( p ) ((p) > SUCCESS) - /* * When loading a line (or block) of text as an option, the value can * be processed in any of several modes: @@ -167,7 +114,7 @@ typedef enum { OPTION_LOAD_KEEP } tOptionLoadMode; -extern tOptionLoadMode option_load_mode; +static tOptionLoadMode option_load_mode; /* * The pager state is used by optionPagedUsage() procedure. @@ -183,8 +130,6 @@ typedef enum { PAGER_STATE_CHILD } tePagerState; -extern tePagerState pagerState; - typedef enum { ENV_ALL, ENV_IMM, @@ -208,9 +153,9 @@ typedef struct { { NULL, NULL, OPTST_ ## st, TOPT_UNDEFINED } #define TEXTTO_TABLE \ - _TT_( LONGUSAGE ) \ - _TT_( USAGE ) \ - _TT_( VERSION ) + _TT_(LONGUSAGE) \ + _TT_(USAGE) \ + _TT_(VERSION) #define _TT_(n) \ TT_ ## n , @@ -219,39 +164,40 @@ typedef enum { TEXTTO_TABLE COUNT_TT } teTextTo; #undef _TT_ typedef struct { - tCC* pzStr; - tCC* pzReq; - tCC* pzNum; - tCC* pzKey; - tCC* pzKeyL; - tCC* pzBool; - tCC* pzNest; - tCC* pzOpt; - tCC* pzNo; - tCC* pzBrk; - tCC* pzNoF; - tCC* pzSpc; - tCC* pzOptFmt; + char const * pzStr; + char const * pzReq; + char const * pzNum; + char const * pzFile; + char const * pzKey; + char const * pzKeyL; + char const * pzBool; + char const * pzNest; + char const * pzOpt; + char const * pzNo; + char const * pzBrk; + char const * pzNoF; + char const * pzSpc; + char const * pzOptFmt; + char const * pzTime; } arg_types_t; -#define AGALOC( c, w ) ao_malloc((size_t)c) -#define AGREALOC( p, c, w ) ao_realloc((void*)p, (size_t)c) -#define AGFREE( p ) ao_free((void*)p) -#define AGDUPSTR( p, s, w ) (p = ao_strdup(s)) +#define AGALOC(c, w) ao_malloc((size_t)c) +#define AGREALOC(p, c, w) ao_realloc((void*)p, (size_t)c) +#define AGFREE(_p) free((void *)_p) +#define AGDUPSTR(p, s, w) (p = ao_strdup(s)) static void * -ao_malloc( size_t sz ); +ao_malloc(size_t sz); static void * -ao_realloc( void *p, size_t sz ); +ao_realloc(void *p, size_t sz); -static void -ao_free( void *p ); +#define ao_free(_p) free((void *)_p) static char * -ao_strdup( char const *str ); +ao_strdup(char const *str); -#define TAGMEM( m, t ) +#define TAGMEM(m, t) /* * DO option handling? @@ -358,8 +304,8 @@ ao_strdup( char const *str ); #endif #ifndef HAVE_STRCHR -extern char* strchr( char const *s, int c); -extern char* strrchr( char const *s, int c); +extern char* strchr(char const *s, int c); +extern char* strrchr(char const *s, int c); #endif /* @@ -373,7 +319,8 @@ extern char* strrchr( char const *s, int c); /* * File pointer for usage output */ -extern FILE* option_usage_fp; +FILE * option_usage_fp; +static char const * program_pkgdatadir; extern tOptProc optionPrintVersion, optionPagedUsage, optionLoadOpt; diff --git a/sntp/libopts/autoopts/options.h b/sntp/libopts/autoopts/options.h index c2ceeb3dbb13..c2925e7999bf 100644 --- a/sntp/libopts/autoopts/options.h +++ b/sntp/libopts/autoopts/options.h @@ -2,34 +2,33 @@ * * DO NOT EDIT THIS FILE (options.h) * - * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:34 PM PDT + * It has been AutoGen-ed April 29, 2011 at 03:44:02 PM by AutoGen 5.11.9 * From the definitions funcs.def * and the template file options_h * * This file defines all the global structures and special values * used in the automated option processing library. * - * Automated Options copyright 1992-Y Bruce Korb + * Automated Options Copyright (C) 1992-2011 by Bruce Korb * - * AutoOpts is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * AutoOpts 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 3 of the License, or + * (at your option) any later version. * - * AutoOpts 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. + * AutoOpts 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 AutoOpts. If not, write to: - * The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>."; + */ #ifndef AUTOOPTS_OPTIONS_H_GUARD -#define AUTOOPTS_OPTIONS_H_GUARD +#define AUTOOPTS_OPTIONS_H_GUARD 1 #include <sys/types.h> +#include <stdio.h> #if defined(HAVE_STDINT_H) # include <stdint.h> @@ -59,28 +58,33 @@ * to an option descriptor must be obtained. There are two ways: * * 1. inside an option processing procedure, it is the second argument, - * conventionally "tOptDesc* pOD". + * conventionally "tOptDesc* pOD". * - * 2. Outside of an option procedure (or to reference a different option - * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )". + * 2. Outside of an option procedure (or to reference a different option + * descriptor), use either "&DESC( opt_name )" or "&pfx_DESC( opt_name )". * * See the relevant generated header file to determine which and what * values for "opt_name" are available. */ - -#define OPTIONS_STRUCT_VERSION 118784 -#define OPTIONS_VERSION_STRING "29:0:4" +#define OPTIONS_STRUCT_VERSION 143360 +#define OPTIONS_VERSION_STRING "35:0:10" #define OPTIONS_MINIMUM_VERSION 102400 #define OPTIONS_MIN_VER_STRING "25:0:0" typedef enum { - OPARG_TYPE_NONE = 0, - OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ - OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ - OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ - OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ - OPARG_TYPE_NUMERIC = 5, /* opt arg has numeric value */ - OPARG_TYPE_HIERARCHY = 6 /* option arg is hierarchical value */ + OPARG_TYPE_NONE = 0, + OPARG_TYPE_STRING = 1, /* default type/ vanilla string */ + OPARG_TYPE_ENUMERATION = 2, /* opt arg is an enum (keyword list) */ + OPARG_TYPE_BOOLEAN = 3, /* opt arg is boolean-valued */ + OPARG_TYPE_MEMBERSHIP = 4, /* opt arg sets set membership bits */ + OPARG_TYPE_NUMERIC = 5, /* opt arg is a long int */ + OPARG_TYPE_HIERARCHY = 6, /* option arg is hierarchical value */ + OPARG_TYPE_FILE = 7, /* option arg names a file */ + OPARG_TYPE_TIME = 8, /* opt arg is a time duration */ + OPARG_TYPE_FLOAT = 9, /* opt arg is a floating point num */ + OPARG_TYPE_DOUBLE = 10, /* opt arg is a double prec. float */ + OPARG_TYPE_LONG_DOUBLE = 11, /* opt arg is a long double prec. */ + OPARG_TYPE_LONG_LONG = 12 /* opt arg is a long long int */ } teOptArgType; typedef struct optionValue { @@ -96,6 +100,31 @@ typedef struct optionValue { } v; } tOptionValue; +typedef enum { + FTYPE_MODE_MAY_EXIST = 0x00, + FTYPE_MODE_MUST_EXIST = 0x01, + FTYPE_MODE_MUST_NOT_EXIST = 0x02, + FTYPE_MODE_EXIST_MASK = 0x03, + FTYPE_MODE_NO_OPEN = 0x00, + FTYPE_MODE_OPEN_FD = 0x10, + FTYPE_MODE_FOPEN_FP = 0x20, + FTYPE_MODE_OPEN_MASK = 0x30 +} teOptFileType; + +typedef union { + int file_flags; + char const * file_mode; +} tuFileMode; + +typedef struct argList tArgList; +#define MIN_ARG_ALLOC_CT 6 +#define INCR_ARG_ALLOC_CT 8 +struct argList { + int useCt; + int allocCt; + char const * apzArgs[MIN_ARG_ALLOC_CT]; +}; + /* * Bits in the fOptState option descriptor field. */ @@ -103,6 +132,7 @@ typedef enum { OPTST_SET_ID = 0, /* Set via the "SET_OPT()" macro */ OPTST_PRESET_ID = 1, /* Set via an RC/INI file */ OPTST_DEFINED_ID = 2, /* Set via a command line option */ + OPTST_RESET_ID = 3, /* Reset via command line option */ OPTST_EQUIVALENCE_ID = 4, /* selected by equiv'ed option */ OPTST_DISABLED_ID = 5, /* option is in disabled state */ OPTST_ALLOC_ARG_ID = 6, /* pzOptArg was allocated */ @@ -121,13 +151,17 @@ typedef enum { OPTST_MUST_SET_ID = 20, /* must be set or pre-set */ OPTST_DOCUMENT_ID = 21, /* opt is for doc only */ OPTST_TWICE_ID = 22, /* process opt twice - imm + reg */ - OPTST_DISABLE_TWICE_ID = 23 /* process disabled option twice */ + OPTST_DISABLE_TWICE_ID = 23, /* process disabled option twice */ + OPTST_SCALED_NUM_ID = 24, /* scaled integer value */ + OPTST_NO_COMMAND_ID = 25, /* disable from cmd line */ + OPTST_DEPRECATED_ID = 26 /* support is being removed */ } opt_state_enum_t; -#define OPTST_INIT 0U +#define OPTST_INIT 0U #define OPTST_SET (1U << OPTST_SET_ID) #define OPTST_PRESET (1U << OPTST_PRESET_ID) #define OPTST_DEFINED (1U << OPTST_DEFINED_ID) +#define OPTST_RESET (1U << OPTST_RESET_ID) #define OPTST_EQUIVALENCE (1U << OPTST_EQUIVALENCE_ID) #define OPTST_DISABLED (1U << OPTST_DISABLED_ID) #define OPTST_ALLOC_ARG (1U << OPTST_ALLOC_ARG_ID) @@ -147,30 +181,39 @@ typedef enum { #define OPTST_DOCUMENT (1U << OPTST_DOCUMENT_ID) #define OPTST_TWICE (1U << OPTST_TWICE_ID) #define OPTST_DISABLE_TWICE (1U << OPTST_DISABLE_TWICE_ID) -#define OPT_STATE_MASK 0x00FFFF77U - -#define OPTST_SET_MASK ( \ - OPTST_SET | \ - OPTST_PRESET | \ - OPTST_DEFINED ) - -#define OPTST_MUTABLE_MASK ( \ - OPTST_SET | \ - OPTST_PRESET | \ - OPTST_DEFINED | \ - OPTST_EQUIVALENCE | \ - OPTST_DISABLED | \ - OPTST_ALLOC_ARG ) - -#define OPTST_SELECTED_MASK ( \ - OPTST_SET | \ - OPTST_DEFINED ) - -#define OPTST_ARG_TYPE_MASK ( \ - OPTST_ARG_TYPE_1 | \ - OPTST_ARG_TYPE_2 | \ - OPTST_ARG_TYPE_3 | \ - OPTST_ARG_TYPE_4 ) +#define OPTST_SCALED_NUM (1U << OPTST_SCALED_NUM_ID) +#define OPTST_NO_COMMAND (1U << OPTST_NO_COMMAND_ID) +#define OPTST_DEPRECATED (1U << OPTST_DEPRECATED_ID) +#define OPT_STATE_MASK 0x07FFFF7FU + +#define OPTST_SET_MASK ( \ + OPTST_DEFINED | OPTST_PRESET | OPTST_RESET | \ + OPTST_SET \ + /* 0x0000000FU */ ) + +#define OPTST_MUTABLE_MASK ( \ + OPTST_ALLOC_ARG | OPTST_DEFINED | \ + OPTST_DISABLED | OPTST_EQUIVALENCE | \ + OPTST_PRESET | OPTST_RESET | \ + OPTST_SET \ + /* 0x0000007FU */ ) + +#define OPTST_SELECTED_MASK ( \ + OPTST_DEFINED | OPTST_SET \ + /* 0x00000005U */ ) + +#define OPTST_ARG_TYPE_MASK ( \ + OPTST_ARG_TYPE_1 | OPTST_ARG_TYPE_2 | OPTST_ARG_TYPE_3 | \ + OPTST_ARG_TYPE_4 \ + /* 0x0000F000U */ ) + +#define OPTST_DO_NOT_SAVE_MASK ( \ + OPTST_DOCUMENT | OPTST_NO_INIT | OPTST_OMITTED \ + /* 0x00280100U */ ) + +#define OPTST_NO_USAGE_MASK ( \ + OPTST_DEPRECATED | OPTST_NO_COMMAND | OPTST_OMITTED \ + /* 0x06080000U */ ) #ifdef NO_OPTIONAL_OPT_ARGS # undef OPTST_ARG_OPTIONAL @@ -179,13 +222,12 @@ typedef enum { #define OPTST_PERSISTENT_MASK (~OPTST_MUTABLE_MASK) -#define SELECTED_OPT( pod ) ((pod)->fOptState & OPTST_SELECTED_MASK) -#define UNUSED_OPT( pod ) (((pod)->fOptState & OPTST_SET_MASK) == 0) -#define DISABLED_OPT( pod ) ((pod)->fOptState & OPTST_DISABLED) -#define OPTION_STATE( pod ) ((pod)->fOptState) - -#define OPTST_SET_ARGTYPE(n) ((n) << OPTST_ARG_TYPE_1_ID) -#define OPTST_GET_ARGTYPE(f) (((f) & OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID) +#define SELECTED_OPT(_od) ((_od)->fOptState & OPTST_SELECTED_MASK) +#define UNUSED_OPT( _od) (((_od)->fOptState & OPTST_SET_MASK) == 0) +#define DISABLED_OPT(_od) ((_od)->fOptState & OPTST_DISABLED) +#define OPTION_STATE(_od) ((_od)->fOptState) +#define OPTST_SET_ARGTYPE(_n) ((_n) << OPTST_ARG_TYPE_1_ID) +#define OPTST_GET_ARGTYPE(_f) (((_f)&OPTST_ARG_TYPE_MASK)>>OPTST_ARG_TYPE_1_ID) /* * PRIVATE INTERFACES @@ -199,42 +241,50 @@ typedef enum { * Define the processing state flags */ typedef enum { - OPTPROC_LONGOPT_ID = 0, /* Process long style options */ - OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */ - OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */ - OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */ - OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */ - OPTPROC_NUM_OPT_ID = 5, /* there is a number option */ - OPTPROC_INITDONE_ID = 6, /* have initializations been done? */ - OPTPROC_NEGATIONS_ID = 7, /* any negation options? */ - OPTPROC_ENVIRON_ID = 8, /* check environment? */ - OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */ - OPTPROC_ARGS_REQ_ID = 10, /* Require arguments after options */ - OPTPROC_REORDER_ID = 11, /* reorder operands after options */ - OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */ - OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */ - OPTPROC_HAS_IMMED_ID = 14, /* program defines immed options */ - OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */ + OPTPROC_LONGOPT_ID = 0, /* Process long style options */ + OPTPROC_SHORTOPT_ID = 1, /* Process short style "flags" */ + OPTPROC_ERRSTOP_ID = 2, /* Stop on argument errors */ + OPTPROC_DISABLEDOPT_ID = 3, /* Current option is disabled */ + OPTPROC_NO_REQ_OPT_ID = 4, /* no options are required */ + OPTPROC_NUM_OPT_ID = 5, /* there is a number option */ + OPTPROC_INITDONE_ID = 6, /* have inits been done? */ + OPTPROC_NEGATIONS_ID = 7, /* any negation options? */ + OPTPROC_ENVIRON_ID = 8, /* check environment? */ + OPTPROC_NO_ARGS_ID = 9, /* Disallow remaining arguments */ + OPTPROC_ARGS_REQ_ID = 10, /* Require args after options */ + OPTPROC_REORDER_ID = 11, /* reorder operands after opts */ + OPTPROC_GNUUSAGE_ID = 12, /* emit usage in GNU style */ + OPTPROC_TRANSLATE_ID = 13, /* Translate strings in tOptions */ + OPTPROC_MISUSE_ID = 14, /* no usage on usage error */ + OPTPROC_NXLAT_OPT_CFG_ID = 16, /* suppress for config only */ + OPTPROC_NXLAT_OPT_ID = 17, /* suppress xlation always */ + OPTPROC_PRESETTING_ID = 19 /* opt processing in preset state */ } optproc_state_enum_t; -#define OPTPROC_NONE 0U -#define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID) -#define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID) -#define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID) -#define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID) -#define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID) -#define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID) -#define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID) -#define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID) -#define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID) -#define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID) -#define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID) -#define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID) -#define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID) -#define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID) -#define OPTPROC_HAS_IMMED (1U << OPTPROC_HAS_IMMED_ID) -#define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID) -#define OPTPROC_STATE_MASK 0x00087FFFU +#define OPTPROC_NONE 0U +#define OPTPROC_LONGOPT (1U << OPTPROC_LONGOPT_ID) +#define OPTPROC_SHORTOPT (1U << OPTPROC_SHORTOPT_ID) +#define OPTPROC_ERRSTOP (1U << OPTPROC_ERRSTOP_ID) +#define OPTPROC_DISABLEDOPT (1U << OPTPROC_DISABLEDOPT_ID) +#define OPTPROC_NO_REQ_OPT (1U << OPTPROC_NO_REQ_OPT_ID) +#define OPTPROC_NUM_OPT (1U << OPTPROC_NUM_OPT_ID) +#define OPTPROC_INITDONE (1U << OPTPROC_INITDONE_ID) +#define OPTPROC_NEGATIONS (1U << OPTPROC_NEGATIONS_ID) +#define OPTPROC_ENVIRON (1U << OPTPROC_ENVIRON_ID) +#define OPTPROC_NO_ARGS (1U << OPTPROC_NO_ARGS_ID) +#define OPTPROC_ARGS_REQ (1U << OPTPROC_ARGS_REQ_ID) +#define OPTPROC_REORDER (1U << OPTPROC_REORDER_ID) +#define OPTPROC_GNUUSAGE (1U << OPTPROC_GNUUSAGE_ID) +#define OPTPROC_TRANSLATE (1U << OPTPROC_TRANSLATE_ID) +#define OPTPROC_MISUSE (1U << OPTPROC_MISUSE_ID) +#define OPTPROC_NXLAT_OPT_CFG (1U << OPTPROC_NXLAT_OPT_CFG_ID) +#define OPTPROC_NXLAT_OPT (1U << OPTPROC_NXLAT_OPT_ID) +#define OPTPROC_PRESETTING (1U << OPTPROC_PRESETTING_ID) +#define OPTPROC_STATE_MASK 0x000B7FFFU + +#define OPTPROC_NO_XLAT_MASK ( \ + OPTPROC_NXLAT_OPT | OPTPROC_NXLAT_OPT_CFG \ + /* 0x00030000U */ ) #define STMTS(s) do { s; } while (0) @@ -265,19 +315,24 @@ typedef enum { AG_FALSE = 0, AG_TRUE } ag_bool; typedef struct options tOptions; typedef struct optDesc tOptDesc; typedef struct optNames tOptNames; +#define OPTPROC_EMIT_USAGE ((tOptions *)0x01UL) +#define OPTPROC_EMIT_SHELL ((tOptions *)0x02UL) +#define OPTPROC_RETURN_VALNAME ((tOptions *)0x03UL) +#define OPTPROC_EMIT_LIMIT ((tOptions *)0x0FUL) /* * The option procedures do the special processing for each * option flag that needs it. */ -typedef void (tOptProc)( tOptions* pOpts, tOptDesc* pOptDesc ); +typedef void (tOptProc)(tOptions* pOpts, tOptDesc* pOptDesc); typedef tOptProc* tpOptProc; /* * The usage procedure will never return. It calls "exit(2)" * with the "exitCode" argument passed to it. */ -typedef void (tUsageProc)( tOptions* pOpts, int exitCode ); +// coverity[+kill] +typedef void (tUsageProc)(tOptions* pOpts, int exitCode); typedef tUsageProc* tpUsageProc; /* @@ -289,21 +344,6 @@ typedef tUsageProc* tpUsageProc; #define OPTION_LIMIT SHRT_MAX #define NO_EQUIVALENT (OPTION_LIMIT+1) -/* - * Special values for optValue. It must not be generatable from the - * computation "optIndex +96". Since "optIndex" is limited to 100, ... - */ -#define NUMBER_OPTION '#' - -typedef struct argList tArgList; -#define MIN_ARG_ALLOC_CT 6 -#define INCR_ARG_ALLOC_CT 8 -struct argList { - int useCt; - int allocCt; - tCC* apzArgs[ MIN_ARG_ALLOC_CT ]; -}; - typedef union { char const * argString; uintptr_t argEnum; @@ -311,8 +351,12 @@ typedef union { long argInt; unsigned long argUint; unsigned int argBool; + FILE * argFp; + int argFd; } optArgBucket_t; +#define pzLastArg optArg.argString + /* * Descriptor structure for each option. * Only the fields marked "PUBLIC" are for public use. @@ -331,18 +375,17 @@ struct optDesc { tAoUI fOptState; /* PUBLIC */ tAoUI reserved; optArgBucket_t optArg; /* PUBLIC */ -# define pzLastArg optArg.argString void* optCookie; /* PUBLIC */ - const int * pOptMust; - const int * pOptCant; - tpOptProc pOptProc; - char const* pzText; + int const * const pOptMust; + int const * const pOptCant; + tpOptProc const pOptProc; + char const* const pzText; - char const* pz_NAME; - char const* pz_Name; - char const* pz_DisableName; - char const* pz_DisablePfx; + char const* const pz_NAME; + char const* const pz_Name; + char const* const pz_DisableName; + char const* const pz_DisablePfx; }; /* @@ -362,6 +405,13 @@ struct optSpecIndex { */ typedef void (tOptionXlateProc)(void); +/* + * Everything marked "PUBLIC" is also marked "const". + * Public access is not a license to modify. Other fields + * are used and modified by the library. They are also + * subject to change without any notice. Do not even + * look at these outside of libopts. + */ struct options { int const structVersion; int origArgCt; @@ -370,32 +420,52 @@ struct options { unsigned int curOptIdx; char* pzCurOpt; - char const* pzProgPath; - char const* pzProgName; - char const* const pzPROGNAME; - char const* const pzRcName; - char const* const pzCopyright; - char const* const pzCopyNotice; - char const* const pzFullVersion; + char const* const pzProgPath; /* PUBLIC */ + char const* const pzProgName; /* PUBLIC */ + char const* const pzPROGNAME; /* PUBLIC */ + char const* const pzRcName; /* PUBLIC */ + char const* const pzCopyright; /* PUBLIC */ + char const* const pzCopyNotice; /* PUBLIC */ + char const* const pzFullVersion; /* PUBLIC */ char const* const* const papzHomeList; char const* const pzUsageTitle; char const* const pzExplain; char const* const pzDetail; - tOptDesc* const pOptDesc; - char const* const pzBugAddr; + tOptDesc* const pOptDesc; /* PUBLIC */ + char const* const pzBugAddr; /* PUBLIC */ void* pExtensions; void* pSavedState; + // coverity[+kill] tpUsageProc pUsageProc; tOptionXlateProc* pTransProc; tOptSpecIndex specOptIdx; int const optCt; int const presetOptCt; + char const * pzFullUsage; + char const * pzShortUsage; + /* PUBLIC: */ + optArgBucket_t const * const originalOptArgArray; + void * const * const originalOptArgCookie; + char const * const pzPkgDataDir; + char const * const pzPackager; }; /* + * Versions where in various fields first appear: + * ($AO_CURRENT * 4096 + $AO_REVISION, but $AO_REVISION must be zero) + */ +#define originalOptArgArray_STRUCT_VERSION 131072 /* AO_CURRENT = 32 */ +#define HAS_originalOptArgArray(_opt) \ + ((_opt)->structVersion >= originalOptArgArray_STRUCT_VERSION) + +#define pzPkgDataDir_STRUCT_VERSION 139264 /* AO_CURRENT = 34 */ +#define HAS_pzPkgDataDir(_opt) \ + ((_opt)->structVersion >= pzPkgDataDir_STRUCT_VERSION) + +/* * "token list" structure returned by "string_tokenize()" */ typedef struct { @@ -437,7 +507,8 @@ typedef struct { #define TEXT_MMAP_FAILED_ADDR(a) ((void*)(a) == (void*)MAP_FAILED) #ifdef __cplusplus -extern "C" { +#define CPLUSPLUS_OPENER extern "C" { +CPLUSPLUS_OPENER #define CPLUSPLUS_CLOSER } #else #define CPLUSPLUS_CLOSER @@ -447,7 +518,7 @@ extern "C" { * The following routines may be coded into AutoOpts client code: */ -/* From: tokenize.c line 115 +/* From: tokenize.c line 166 * * ao_string_tokenize - tokenize an input string * @@ -488,10 +559,10 @@ extern "C" { * Double quote strings are formed according to the rules of string * constants in ANSI-C programs. */ -extern token_list_t* ao_string_tokenize( char const* ); +extern token_list_t* ao_string_tokenize(char const*); -/* From: configfile.c line 113 +/* From: configfile.c line 80 * * configFileLoad - parse a configuration file * @@ -508,10 +579,10 @@ extern token_list_t* ao_string_tokenize( char const* ); * @code{optionGetValue()}, @code{optionNextValue()} and * @code{optionUnloadNested()}. */ -extern const tOptionValue* configFileLoad( char const* ); +extern const tOptionValue* configFileLoad(char const*); -/* From: configfile.c line 883 +/* From: configfile.c line 1059 * * optionFileLoad - Load the locatable config files, in order * @@ -538,10 +609,10 @@ extern const tOptionValue* configFileLoad( char const* ); * * Configuration files not found or not decipherable are simply ignored. */ -extern int optionFileLoad( tOptions*, char const* ); +extern int optionFileLoad(tOptions*, char const*); -/* From: configfile.c line 245 +/* From: configfile.c line 212 * * optionFindNextValue - find a hierarcicaly valued option instance * @@ -557,10 +628,10 @@ extern int optionFileLoad( tOptions*, char const* ); * configurable. It will search through the list and return the next entry * that matches the criteria. */ -extern const tOptionValue* optionFindNextValue( const tOptDesc*, const tOptionValue*, char const*, char const* ); +extern const tOptionValue* optionFindNextValue(const tOptDesc*, const tOptionValue*, char const*, char const*); -/* From: configfile.c line 171 +/* From: configfile.c line 138 * * optionFindValue - find a hierarcicaly valued option instance * @@ -574,10 +645,10 @@ extern const tOptionValue* optionFindNextValue( const tOptDesc*, const tOptionVa * This routine will find an entry in a nested value option or configurable. * It will search through the list and return a matching entry. */ -extern const tOptionValue* optionFindValue( const tOptDesc*, char const*, char const* ); +extern const tOptionValue* optionFindValue(const tOptDesc*, char const*, char const*); -/* From: restore.c line 188 +/* From: restore.c line 166 * * optionFree - free allocated option processing memory * @@ -587,10 +658,10 @@ extern const tOptionValue* optionFindValue( const tOptDesc*, char const*, char c * AutoOpts sometimes allocates memory and puts pointers to it in the * option state structures. This routine deallocates all such memory. */ -extern void optionFree( tOptions* ); +extern void optionFree(tOptions*); -/* From: configfile.c line 314 +/* From: configfile.c line 281 * * optionGetValue - get a specific value from a hierarcical list * @@ -605,10 +676,10 @@ extern void optionFree( tOptions* ); * the first entry with a name that exactly matches the argument will be * returned. */ -extern const tOptionValue* optionGetValue( const tOptionValue*, char const* ); +extern const tOptionValue* optionGetValue(const tOptionValue*, char const*); -/* From: load.c line 521 +/* From: load.c line 478 * * optionLoadLine - process a string for an option name and value * @@ -629,10 +700,10 @@ extern const tOptionValue* optionGetValue( const tOptionValue*, char const* ); * formation used in AutoGen definition files (@pxref{basic expression}), * except that you may not use backquotes. */ -extern void optionLoadLine( tOptions*, char const* ); +extern void optionLoadLine(tOptions*, char const*); -/* From: configfile.c line 373 +/* From: configfile.c line 340 * * optionNextValue - get the next value from a hierarchical list * @@ -648,10 +719,10 @@ extern void optionLoadLine( tOptions*, char const* ); * The "@var{pOldValue}" must have been gotten from a prior call to this * routine or to "@code{opitonGetValue()}". */ -extern const tOptionValue* optionNextValue( const tOptionValue*, const tOptionValue* ); +extern const tOptionValue* optionNextValue(const tOptionValue*, const tOptionValue*); -/* From: usage.c line 128 +/* From: usage.c line 195 * * optionOnlyUsage - Print usage text for just the options * @@ -663,10 +734,10 @@ extern const tOptionValue* optionNextValue( const tOptionValue*, const tOptionVa * This function may be used when the emitted usage must incorporate * information not available to AutoOpts. */ -extern void optionOnlyUsage( tOptions*, int ); +extern void optionOnlyUsage(tOptions*, int); -/* From: autoopts.c line 1012 +/* From: autoopts.c line 1065 * * optionProcess - this is the main option processing routine * @@ -693,10 +764,10 @@ extern void optionOnlyUsage( tOptions*, int ); * is treated as an operand. Encountering an operand stops option * processing. */ -extern int optionProcess( tOptions*, int, char** ); +extern int optionProcess(tOptions*, int, char**); -/* From: restore.c line 145 +/* From: restore.c line 123 * * optionRestore - restore option state from memory copy * @@ -710,10 +781,10 @@ extern int optionProcess( tOptions*, int, char** ); * to optionProcess(3AO), then you may change the contents of the * argc/argv parameters to optionProcess. */ -extern void optionRestore( tOptions* ); +extern void optionRestore(tOptions*); -/* From: save.c line 334 +/* From: save.c line 664 * * optionSaveFile - saves the option state to a file * @@ -725,12 +796,20 @@ extern void optionRestore( tOptions* ); * option, or by appending the @code{rcfile} attribute to the last * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it * will default to @code{.@i{programname}rc}. If you wish to specify another - * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro. + * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro. + * + * The recommend usage is as follows: + * @example + * optionProcess(&progOptions, argc, argv); + * if (i_want_a_non_standard_place_for_this) + * SET_OPT_SAVE_OPTS("myfilename"); + * optionSaveFile(&progOptions); + * @end example */ -extern void optionSaveFile( tOptions* ); +extern void optionSaveFile(tOptions*); -/* From: restore.c line 93 +/* From: restore.c line 71 * * optionSaveState - saves the option state to memory * @@ -749,10 +828,10 @@ extern void optionSaveFile( tOptions* ); * restoring of stacked string arguments and hierarchical values is * disabled. The values are not saved. */ -extern void optionSaveState( tOptions* ); +extern void optionSaveState(tOptions*); -/* From: nested.c line 559 +/* From: nested.c line 551 * * optionUnloadNested - Deallocate the memory for a nested value * @@ -763,10 +842,10 @@ extern void optionSaveState( tOptions* ); * have been gotten from a call to @code{configFileLoad()} (See * @pxref{libopts-configFileLoad}). */ -extern void optionUnloadNested( tOptionValue const * ); +extern void optionUnloadNested(tOptionValue const *); -/* From: version.c line 58 +/* From: version.c line 31 * * optionVersion - return the compiled AutoOpts version number * @@ -775,10 +854,10 @@ extern void optionUnloadNested( tOptionValue const * ); * Returns the full version string compiled into the library. * The returned string cannot be modified. */ -extern char const* optionVersion( void ); +extern char const* optionVersion(void); -/* From: ../compat/pathfind.c line 34 +/* From: ../compat/pathfind.c line 29 * * pathfind - fild a file in a list of directories * @@ -818,11 +897,11 @@ extern char const* optionVersion( void ); * @end example */ #ifndef HAVE_PATHFIND -extern char* pathfind( char const*, char const*, char const* ); +extern char* pathfind(char const*, char const*, char const*); #endif /* HAVE_PATHFIND */ -/* From: streqvcmp.c line 233 +/* From: streqvcmp.c line 209 * * strequate - map a list of characters to the same value * @@ -834,10 +913,10 @@ extern char* pathfind( char const*, char const*, char const* ); * This function name is mapped to option_strequate so as to not conflict * with the POSIX name space. */ -extern void strequate( char const* ); +extern void strequate(char const*); -/* From: streqvcmp.c line 143 +/* From: streqvcmp.c line 119 * * streqvcmp - compare two strings with an equivalence mapping * @@ -853,10 +932,10 @@ extern void strequate( char const* ); * This function name is mapped to option_streqvcmp so as to not conflict * with the POSIX name space. */ -extern int streqvcmp( char const*, char const* ); +extern int streqvcmp(char const*, char const*); -/* From: streqvcmp.c line 180 +/* From: streqvcmp.c line 156 * * streqvmap - Set the character mappings for the streqv functions * @@ -872,7 +951,7 @@ extern int streqvcmp( char const*, char const* ); * are incremented and the process repeated until @code{ct} entries have been * set. For example, * @example - * streqvmap( 'a', 'A', 26 ); + * streqvmap('a', 'A', 26); * @end example * @noindent * will alter the mapping so that all English lower case letters @@ -881,10 +960,10 @@ extern int streqvcmp( char const*, char const* ); * This function name is mapped to option_streqvmap so as to not conflict * with the POSIX name space. */ -extern void streqvmap( char, char, int ); +extern void streqvmap(char, char, int); -/* From: streqvcmp.c line 102 +/* From: streqvcmp.c line 78 * * strneqvcmp - compare two strings with an equivalence mapping * @@ -902,10 +981,10 @@ extern void streqvmap( char, char, int ); * This function name is mapped to option_strneqvcmp so as to not conflict * with the POSIX name space. */ -extern int strneqvcmp( char const*, char const*, int ); +extern int strneqvcmp(char const*, char const*, int); -/* From: streqvcmp.c line 259 +/* From: streqvcmp.c line 235 * * strtransform - convert a string into its mapped-to value * @@ -917,55 +996,65 @@ extern int strneqvcmp( char const*, char const*, int ); * character is put into the output. * This function name is mapped to option_strtransform so as to not conflict * with the POSIX name space. + * + * The source and destination may be the same. */ -extern void strtransform( char*, char const* ); +extern void strtransform(char*, char const*); /* AutoOpts PRIVATE FUNCTIONS: */ tOptProc optionStackArg, optionUnstackArg, optionBooleanVal, optionNumericVal; -extern char* ao_string_cook( char*, int* ); +extern char* ao_string_cook(char*, int*); + +extern unsigned int ao_string_cook_escape_char(char const*, char*, unsigned int); + +extern void genshelloptUsage(tOptions*, int); + +extern void optionBooleanVal(tOptions*, tOptDesc*); + +extern uintptr_t optionEnumerationVal(tOptions*, tOptDesc*, char const * const *, unsigned int); -extern unsigned int ao_string_cook_escape_char( char const*, char*, unsigned int ); +extern void optionFileCheck(tOptions*, tOptDesc*, teOptFileType, tuFileMode); -extern void export_options_to_guile( tOptions* ); +extern char const * optionKeywordName(tOptDesc*, unsigned int); -extern void genshelloptUsage( tOptions*, int ); +extern void optionLoadOpt(tOptions*, tOptDesc*); -extern void optionBooleanVal( tOptions*, tOptDesc* ); +extern ag_bool optionMakePath(char*, int, char const*, char const*); -extern uintptr_t optionEnumerationVal( tOptions*, tOptDesc*, char const * const *, unsigned int ); +extern void optionNestedVal(tOptions*, tOptDesc*); -extern char const* optionKeywordName( tOptDesc*, unsigned int ); +extern void optionNumericVal(tOptions*, tOptDesc*); -extern void optionLoadOpt( tOptions*, tOptDesc* ); +extern void optionPagedUsage(tOptions*, tOptDesc*); -extern ag_bool optionMakePath( char*, int, char const*, char const* ); +extern void optionParseShell(tOptions*); -extern void optionNestedVal( tOptions*, tOptDesc* ); +extern void optionPrintVersion(tOptions*, tOptDesc*); -extern void optionNumericVal( tOptions*, tOptDesc* ); +extern void optionPutShell(tOptions*); -extern void optionPagedUsage( tOptions*, tOptDesc* ); +extern void optionResetOpt(tOptions*, tOptDesc*); -extern void optionParseShell( tOptions* ); +extern void optionSetMembers(tOptions*, tOptDesc*, char const * const *, unsigned int); -extern void optionPrintVersion( tOptions*, tOptDesc* ); +extern void optionShowRange(tOptions*, tOptDesc*, void *, int); -extern void optionPutShell( tOptions* ); +extern void optionStackArg(tOptions*, tOptDesc*); -extern void optionSetMembers( tOptions*, tOptDesc*, char const * const *, unsigned int ); +extern void optionTimeDate(tOptions*, tOptDesc*); -extern void optionStackArg( tOptions*, tOptDesc* ); +extern void optionTimeVal(tOptions*, tOptDesc*); -extern void optionUnstackArg( tOptions*, tOptDesc* ); +extern void optionUnstackArg(tOptions*, tOptDesc*); -extern void optionUsage( tOptions*, int ); +extern void optionUsage(tOptions*, int); -extern void optionVersionStderr( tOptions*, tOptDesc* ); +extern void optionVersionStderr(tOptions*, tOptDesc*); -extern void* text_mmap( char const*, int, int, tmap_info_t* ); +extern void* text_mmap(char const*, int, int, tmap_info_t*); -extern int text_munmap( tmap_info_t* ); +extern int text_munmap(tmap_info_t*); CPLUSPLUS_CLOSER #endif /* AUTOOPTS_OPTIONS_H_GUARD */ diff --git a/sntp/libopts/autoopts/project.h b/sntp/libopts/autoopts/project.h new file mode 100644 index 000000000000..b01affbc19e2 --- /dev/null +++ b/sntp/libopts/autoopts/project.h @@ -0,0 +1,50 @@ + +#ifndef AUTOGEN_PROJECT_H +#define AUTOGEN_PROJECT_H + +#include "config.h" + +/* + * Procedure success codes + * + * USAGE: define procedures to return "tSuccess". Test their results + * with the SUCCEEDED, FAILED and HADGLITCH macros. + * + * Microsoft sticks its nose into user space here, so for Windows' sake, + * make sure all of these are undefined. + */ +#undef SUCCESS +#undef FAILURE +#undef PROBLEM +#undef SUCCEEDED +#undef SUCCESSFUL +#undef FAILED +#undef HADGLITCH + +#define SUCCESS ((tSuccess) 0) +#define FAILURE ((tSuccess)-1) +#define PROBLEM ((tSuccess) 1) + +typedef int tSuccess; + +#define SUCCEEDED(p) ((p) == SUCCESS) +#define SUCCESSFUL(p) SUCCEEDED(p) +#define FAILED(p) ((p) < SUCCESS) +#define HADGLITCH(p) ((p) > SUCCESS) + +#ifndef STR +# define __STR(s) #s +# define STR(s) __STR(s) +#endif + +#define STRSIZE(s) (sizeof(s)-1) + +#ifdef DEFINING +# define VALUE(s) = s +# define MODE +#else +# define VALUE(s) +# define MODE extern +#endif + +#endif /* AUTOGEN_PROJECT_H */ diff --git a/sntp/libopts/autoopts/usage-txt.h b/sntp/libopts/autoopts/usage-txt.h index 5aaaa01a66ff..de92663424b9 100644 --- a/sntp/libopts/autoopts/usage-txt.h +++ b/sntp/libopts/autoopts/usage-txt.h @@ -2,35 +2,33 @@ * * DO NOT EDIT THIS FILE (usage-txt.h) * - * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:33 PM PDT + * It has been AutoGen-ed April 29, 2011 at 03:44:00 PM by AutoGen 5.11.9 * From the definitions usage-txt.def * and the template file usage-txt.tpl * * This file handles all the bookkeeping required for tracking all the little - * tiny strings used by the AutoOpts library. There are 113 + * tiny strings used by the AutoOpts library. There are 142 * of them. This is not versioned because it is entirely internal to the * library and accessed by client code only in a very well-controlled way: * they may substitute translated strings using a procedure that steps through * all the string pointers. * - * AutoOpts is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * AutoOpts 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 3 of the License, or + * (at your option) any later version. * - * AutoOpts 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. + * AutoOpts 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 AutoOpts. If not, write to: - * The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>."; + */ #ifndef AUTOOPTS_USAGE_TXT_H_GUARD -#define AUTOOPTS_USAGE_TXT_H_GUARD +#define AUTOOPTS_USAGE_TXT_H_GUARD 1 #undef cch_t #define cch_t char const @@ -42,10 +40,12 @@ typedef struct { int field_ct; char* utpz_GnuBoolArg; char* utpz_GnuKeyArg; + char* utpz_GnuFileArg; char* utpz_GnuKeyLArg; + char* utpz_GnuTimeArg; char* utpz_GnuNumArg; char* utpz_GnuStrArg; - cch_t* apz_str[ 108 ]; + cch_t* apz_str[ 135 ]; } usage_text_t; /* @@ -58,119 +58,148 @@ extern usage_text_t option_usage_text; /* * Provide a mapping from a short name to fields in this structure. */ -#define zAO_Bad (option_usage_text.apz_str[ 0]) -#define zAO_Big (option_usage_text.apz_str[ 1]) -#define zAO_Err (option_usage_text.apz_str[ 2]) -#define zAO_Sml (option_usage_text.apz_str[ 3]) -#define zAll (option_usage_text.apz_str[ 4]) -#define zAlt (option_usage_text.apz_str[ 5]) -#define zAmbigKey (option_usage_text.apz_str[ 6]) -#define zAmbiguous (option_usage_text.apz_str[ 7]) -#define zArgsMust (option_usage_text.apz_str[ 8]) -#define zAtMost (option_usage_text.apz_str[ 9]) -#define zAuto (option_usage_text.apz_str[ 10]) -#define zBadPipe (option_usage_text.apz_str[ 11]) -#define zBadVerArg (option_usage_text.apz_str[ 12]) -#define zCantFmt (option_usage_text.apz_str[ 13]) -#define zCantSave (option_usage_text.apz_str[ 14]) -#define zDefaultOpt (option_usage_text.apz_str[ 15]) -#define zDis (option_usage_text.apz_str[ 16]) -#define zEnab (option_usage_text.apz_str[ 17]) -#define zEquiv (option_usage_text.apz_str[ 18]) -#define zErrOnly (option_usage_text.apz_str[ 19]) -#define zExamineFmt (option_usage_text.apz_str[ 20]) -#define zFiveSpaces (option_usage_text.apz_str[ 21]) -#define zFlagOkay (option_usage_text.apz_str[ 22]) -#define zFmtFmt (option_usage_text.apz_str[ 23]) -#define zForkFail (option_usage_text.apz_str[ 24]) -#define zFSErrOptLoad (option_usage_text.apz_str[ 25]) -#define zFSErrReadFile (option_usage_text.apz_str[ 26]) -#define zGenshell (option_usage_text.apz_str[ 27]) +#define zAO_Alloc (option_usage_text.apz_str[ 0]) +#define zAO_Bad (option_usage_text.apz_str[ 1]) +#define zAO_Big (option_usage_text.apz_str[ 2]) +#define zAO_Err (option_usage_text.apz_str[ 3]) +#define zAO_Realloc (option_usage_text.apz_str[ 4]) +#define zAO_Sml (option_usage_text.apz_str[ 5]) +#define zAO_Strdup (option_usage_text.apz_str[ 6]) +#define zAO_Ver (option_usage_text.apz_str[ 7]) +#define zAO_Woops (option_usage_text.apz_str[ 8]) +#define zAliasRange (option_usage_text.apz_str[ 9]) +#define zAll (option_usage_text.apz_str[ 10]) +#define zAlt (option_usage_text.apz_str[ 11]) +#define zAmbigKey (option_usage_text.apz_str[ 12]) +#define zAmbigOptStr (option_usage_text.apz_str[ 13]) +#define zArgsMust (option_usage_text.apz_str[ 14]) +#define zAtMost (option_usage_text.apz_str[ 15]) +#define zAuto (option_usage_text.apz_str[ 16]) +#define zBadPipe (option_usage_text.apz_str[ 17]) +#define zBadVerArg (option_usage_text.apz_str[ 18]) +#define zCantFmt (option_usage_text.apz_str[ 19]) +#define zCantSave (option_usage_text.apz_str[ 20]) +#define zCfgAO_Flags (option_usage_text.apz_str[ 21]) +#define zCfgProg (option_usage_text.apz_str[ 22]) +#define zDefaultOpt (option_usage_text.apz_str[ 23]) +#define zDis (option_usage_text.apz_str[ 24]) +#define zDisabledErr (option_usage_text.apz_str[ 25]) +#define zDisabledOpt (option_usage_text.apz_str[ 26]) +#define zDisabledWhy (option_usage_text.apz_str[ 27]) +#define zEnab (option_usage_text.apz_str[ 28]) +#define zEquiv (option_usage_text.apz_str[ 29]) +#define zErrOnly (option_usage_text.apz_str[ 30]) +#define zExamineFmt (option_usage_text.apz_str[ 31]) +#define zFiveSpaces (option_usage_text.apz_str[ 32]) +#define zFlagOkay (option_usage_text.apz_str[ 33]) +#define zFmtFmt (option_usage_text.apz_str[ 34]) +#define zForkFail (option_usage_text.apz_str[ 35]) +#define zFreopenFail (option_usage_text.apz_str[ 36]) +#define zFSErrOptLoad (option_usage_text.apz_str[ 37]) +#define zFSErrReadFile (option_usage_text.apz_str[ 38]) +#define zFSOptError (option_usage_text.apz_str[ 39]) +#define zFSOptErrMayExist (option_usage_text.apz_str[ 40]) +#define zFSOptErrMustExist (option_usage_text.apz_str[ 41]) +#define zFSOptErrNoExist (option_usage_text.apz_str[ 42]) +#define zFSOptErrOpen (option_usage_text.apz_str[ 43]) +#define zFSOptErrFopen (option_usage_text.apz_str[ 44]) +#define zFileCannotExist (option_usage_text.apz_str[ 45]) +#define zFileMustExist (option_usage_text.apz_str[ 46]) +#define zGenshell (option_usage_text.apz_str[ 47]) #define zGnuBoolArg (option_usage_text.utpz_GnuBoolArg) -#define zGnuBreak (option_usage_text.apz_str[ 28]) +#define zGnuBreak (option_usage_text.apz_str[ 48]) #define zGnuKeyArg (option_usage_text.utpz_GnuKeyArg) +#define zGnuFileArg (option_usage_text.utpz_GnuFileArg) #define zGnuKeyLArg (option_usage_text.utpz_GnuKeyLArg) -#define zGnuNestArg (option_usage_text.apz_str[ 29]) +#define zGnuTimeArg (option_usage_text.utpz_GnuTimeArg) +#define zGnuNestArg (option_usage_text.apz_str[ 49]) #define zGnuNumArg (option_usage_text.utpz_GnuNumArg) -#define zGnuOptArg (option_usage_text.apz_str[ 30]) -#define zGnuOptFmt (option_usage_text.apz_str[ 31]) +#define zGnuOptArg (option_usage_text.apz_str[ 50]) +#define zGnuOptFmt (option_usage_text.apz_str[ 51]) #define zGnuStrArg (option_usage_text.utpz_GnuStrArg) -#define zIllOptChr (option_usage_text.apz_str[ 32]) -#define zIllOptStr (option_usage_text.apz_str[ 33]) -#define zIllegal (option_usage_text.apz_str[ 34]) -#define zInvalOptDesc (option_usage_text.apz_str[ 35]) -#define zKeyWords (option_usage_text.apz_str[ 36]) -#define zLoadCooked (option_usage_text.apz_str[ 37]) -#define zLoadKeep (option_usage_text.apz_str[ 38]) -#define zLoadType (option_usage_text.apz_str[ 39]) -#define zLoadUncooked (option_usage_text.apz_str[ 40]) -#define zLtypeInteger (option_usage_text.apz_str[ 41]) -#define zLtypeNest (option_usage_text.apz_str[ 42]) -#define zLtypeString (option_usage_text.apz_str[ 43]) -#define zLtypeBool (option_usage_text.apz_str[ 44]) -#define zLtypeKeyword (option_usage_text.apz_str[ 45]) -#define zLtypeSetMembership (option_usage_text.apz_str[ 46]) -#define zMembers (option_usage_text.apz_str[ 47]) -#define zMisArg (option_usage_text.apz_str[ 48]) -#define zMultiEquiv (option_usage_text.apz_str[ 49]) -#define zMust (option_usage_text.apz_str[ 50]) -#define zNeedOne (option_usage_text.apz_str[ 51]) -#define zNoArg (option_usage_text.apz_str[ 52]) -#define zNoArgs (option_usage_text.apz_str[ 53]) -#define zNoCreat (option_usage_text.apz_str[ 54]) -#define zNoFlags (option_usage_text.apz_str[ 55]) -#define zNoKey (option_usage_text.apz_str[ 56]) -#define zNoLim (option_usage_text.apz_str[ 57]) -#define zNoPreset (option_usage_text.apz_str[ 58]) -#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 59]) -#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 60]) -#define zNoStat (option_usage_text.apz_str[ 61]) -#define zNoState (option_usage_text.apz_str[ 62]) -#define zNone (option_usage_text.apz_str[ 63]) -#define zNotDef (option_usage_text.apz_str[ 64]) -#define zNotEnough (option_usage_text.apz_str[ 65]) -#define zNotFile (option_usage_text.apz_str[ 66]) -#define zNotNumber (option_usage_text.apz_str[ 67]) -#define zNrmOptFmt (option_usage_text.apz_str[ 68]) -#define zNumberOpt (option_usage_text.apz_str[ 69]) -#define zOneSpace (option_usage_text.apz_str[ 70]) -#define zOnlyOne (option_usage_text.apz_str[ 71]) -#define zOptsOnly (option_usage_text.apz_str[ 72]) -#define zPathFmt (option_usage_text.apz_str[ 73]) -#define zPlsSendBugs (option_usage_text.apz_str[ 74]) -#define zPreset (option_usage_text.apz_str[ 75]) -#define zPresetFile (option_usage_text.apz_str[ 76]) -#define zPresetIntro (option_usage_text.apz_str[ 77]) -#define zProg (option_usage_text.apz_str[ 78]) -#define zProhib (option_usage_text.apz_str[ 79]) -#define zReorder (option_usage_text.apz_str[ 80]) -#define zReqFmt (option_usage_text.apz_str[ 81]) -#define zReqOptFmt (option_usage_text.apz_str[ 82]) -#define zReqThese (option_usage_text.apz_str[ 83]) -#define zReq_NoShrtTtl (option_usage_text.apz_str[ 84]) -#define zReq_ShrtTtl (option_usage_text.apz_str[ 85]) -#define zSepChars (option_usage_text.apz_str[ 86]) -#define zSetMembers (option_usage_text.apz_str[ 87]) -#define zSetMemberSettings (option_usage_text.apz_str[ 88]) -#define zShrtGnuOptFmt (option_usage_text.apz_str[ 89]) -#define zSixSpaces (option_usage_text.apz_str[ 90]) -#define zStdBoolArg (option_usage_text.apz_str[ 91]) -#define zStdBreak (option_usage_text.apz_str[ 92]) -#define zStdKeyArg (option_usage_text.apz_str[ 93]) -#define zStdKeyLArg (option_usage_text.apz_str[ 94]) -#define zStdNestArg (option_usage_text.apz_str[ 95]) -#define zStdNoArg (option_usage_text.apz_str[ 96]) -#define zStdNumArg (option_usage_text.apz_str[ 97]) -#define zStdOptArg (option_usage_text.apz_str[ 98]) -#define zStdReqArg (option_usage_text.apz_str[ 99]) -#define zStdStrArg (option_usage_text.apz_str[100]) -#define zTabHyp (option_usage_text.apz_str[101]) -#define zTabHypAnd (option_usage_text.apz_str[102]) -#define zTabout (option_usage_text.apz_str[103]) -#define zThreeSpaces (option_usage_text.apz_str[104]) -#define zTwoSpaces (option_usage_text.apz_str[105]) -#define zUpTo (option_usage_text.apz_str[106]) -#define zValidKeys (option_usage_text.apz_str[107]) +#define zIllOptChr (option_usage_text.apz_str[ 52]) +#define zIllOptStr (option_usage_text.apz_str[ 53]) +#define zIllegal (option_usage_text.apz_str[ 54]) +#define zIntRange (option_usage_text.apz_str[ 55]) +#define zInvalOptDesc (option_usage_text.apz_str[ 56]) +#define zLowerBits (option_usage_text.apz_str[ 57]) +#define zMembers (option_usage_text.apz_str[ 58]) +#define zMisArg (option_usage_text.apz_str[ 59]) +#define zMultiEquiv (option_usage_text.apz_str[ 60]) +#define zMust (option_usage_text.apz_str[ 61]) +#define zNeedOne (option_usage_text.apz_str[ 62]) +#define zNoArg (option_usage_text.apz_str[ 63]) +#define zNoArgv (option_usage_text.apz_str[ 64]) +#define zNoArgs (option_usage_text.apz_str[ 65]) +#define zNoCreat (option_usage_text.apz_str[ 66]) +#define zNoFlags (option_usage_text.apz_str[ 67]) +#define zNoKey (option_usage_text.apz_str[ 68]) +#define zNoLim (option_usage_text.apz_str[ 69]) +#define zNoPreset (option_usage_text.apz_str[ 70]) +#define zNoResetArg (option_usage_text.apz_str[ 71]) +#define zNoRq_NoShrtTtl (option_usage_text.apz_str[ 72]) +#define zNoRq_ShrtTtl (option_usage_text.apz_str[ 73]) +#define zNoStat (option_usage_text.apz_str[ 74]) +#define zNoState (option_usage_text.apz_str[ 75]) +#define zNone (option_usage_text.apz_str[ 76]) +#define zNotDef (option_usage_text.apz_str[ 77]) +#define zNotCmdOpt (option_usage_text.apz_str[ 78]) +#define zNotEnough (option_usage_text.apz_str[ 79]) +#define zNotFile (option_usage_text.apz_str[ 80]) +#define zNotNumber (option_usage_text.apz_str[ 81]) +#define zNotDate (option_usage_text.apz_str[ 82]) +#define zNotDuration (option_usage_text.apz_str[ 83]) +#define zNrmOptFmt (option_usage_text.apz_str[ 84]) +#define zNumberOpt (option_usage_text.apz_str[ 85]) +#define zOneSpace (option_usage_text.apz_str[ 86]) +#define zOnlyOne (option_usage_text.apz_str[ 87]) +#define zOptsOnly (option_usage_text.apz_str[ 88]) +#define zOutputFail (option_usage_text.apz_str[ 89]) +#define zPathFmt (option_usage_text.apz_str[ 90]) +#define zPlsSendBugs (option_usage_text.apz_str[ 91]) +#define zPreset (option_usage_text.apz_str[ 92]) +#define zPresetFile (option_usage_text.apz_str[ 93]) +#define zPresetIntro (option_usage_text.apz_str[ 94]) +#define zProhib (option_usage_text.apz_str[ 95]) +#define zReorder (option_usage_text.apz_str[ 96]) +#define zRange (option_usage_text.apz_str[ 97]) +#define zRangeAbove (option_usage_text.apz_str[ 98]) +#define zRangeLie (option_usage_text.apz_str[ 99]) +#define zRangeOnly (option_usage_text.apz_str[100]) +#define zRangeOr (option_usage_text.apz_str[101]) +#define zRangeErr (option_usage_text.apz_str[102]) +#define zRangeExact (option_usage_text.apz_str[103]) +#define zRangeScaled (option_usage_text.apz_str[104]) +#define zRangeUpto (option_usage_text.apz_str[105]) +#define zResetNotConfig (option_usage_text.apz_str[106]) +#define zReqFmt (option_usage_text.apz_str[107]) +#define zReqOptFmt (option_usage_text.apz_str[108]) +#define zReqThese (option_usage_text.apz_str[109]) +#define zReq_NoShrtTtl (option_usage_text.apz_str[110]) +#define zReq_ShrtTtl (option_usage_text.apz_str[111]) +#define zSepChars (option_usage_text.apz_str[112]) +#define zSetMemberSettings (option_usage_text.apz_str[113]) +#define zShrtGnuOptFmt (option_usage_text.apz_str[114]) +#define zSixSpaces (option_usage_text.apz_str[115]) +#define zStdBoolArg (option_usage_text.apz_str[116]) +#define zStdBreak (option_usage_text.apz_str[117]) +#define zStdFileArg (option_usage_text.apz_str[118]) +#define zStdKeyArg (option_usage_text.apz_str[119]) +#define zStdKeyLArg (option_usage_text.apz_str[120]) +#define zStdTimeArg (option_usage_text.apz_str[121]) +#define zStdNestArg (option_usage_text.apz_str[122]) +#define zStdNoArg (option_usage_text.apz_str[123]) +#define zStdNumArg (option_usage_text.apz_str[124]) +#define zStdOptArg (option_usage_text.apz_str[125]) +#define zStdReqArg (option_usage_text.apz_str[126]) +#define zStdStrArg (option_usage_text.apz_str[127]) +#define zTabHyp (option_usage_text.apz_str[128]) +#define zTabHypAnd (option_usage_text.apz_str[129]) +#define zTabout (option_usage_text.apz_str[130]) +#define zThreeSpaces (option_usage_text.apz_str[131]) +#define zTwoSpaces (option_usage_text.apz_str[132]) +#define zUpTo (option_usage_text.apz_str[133]) +#define zValidKeys (option_usage_text.apz_str[134]) /* * First, set up the strings. Some of these are writable. These are all in @@ -180,19 +209,28 @@ extern usage_text_t option_usage_text; static char eng_zGnuBoolArg[] = "=T/F"; static char eng_zGnuKeyArg[] = "=KWd"; + static char eng_zGnuFileArg[] = "=file"; static char eng_zGnuKeyLArg[] = "=Mbr"; + static char eng_zGnuTimeArg[] = "=Tim"; static char eng_zGnuNumArg[] = "=num"; static char eng_zGnuStrArg[] = "=str"; -static char const usage_txt[3208] = +static char const usage_txt[4435] = + "malloc of %d bytes failed\n\0" "AutoOpts function called without option descriptor\n\0" "\tThis exceeds the compiled library version: \0" "Automated Options Processing Error!\n" "\t%s called AutoOpts function with structure version %d:%d:%d.\n\0" + "realloc of %d bytes at 0x%p failed\n\0" "\tThis is less than the minimum library version: \0" + "strdup of %d byte string failed\n\0" + "Automated Options version %s\n" + "\tcopyright (c) 1999-2011 by Bruce Korb - all rights reserved\n\0" + "AutoOpts lib error: defaulted to option with optional arg\n\0" + "(AutoOpts bug): Aliasing option is out of range.\0" "all\0" "\t\t\t\t- an alternate for %s\n\0" "%s error: the keyword `%s' is ambiguous for %s\n\0" - "ambiguous\0" + "%s: ambiguous option -- %s\n\0" "%s: Command line arguments required\n\0" "%d %s%s options allowed\n\0" "version and help options:\0" @@ -203,19 +241,33 @@ static char const usage_txt[3208] = "\t'n' - version and copyright notice\n\0" "ERROR: %s option conflicts with the %s option\n\0" "%s(optionSaveState): error: cannot allocate %d bytes\n\0" + "auto-options\0" + "program\0" "\t\t\t\t- default option for unnamed options\n\0" "\t\t\t\t- disabled as --%s\n\0" + "%s: The ``%s'' option has been disabled\0" + " --- %-14s %s\n\0" + "This option has been disabled\0" "\t\t\t\t- enabled by default\n\0" "-equivalence\0" "ERROR: only \0" " - examining environment variables named %s_*\n\0" " \0" - "Options are specified by doubled hyphens and their name\n" - "or by a single hyphen and the flag character.\n\0" + "Options are specified by doubled hyphens and their name or by a single\n" + "hyphen and the flag character.\n\0" "%%-%ds %%s\n\0" "fs error %d (%s) on fork - cannot obtain %s usage\n\0" + "fs error %d (%s) on freopen\n\0" "File error %d (%s) opening %s for loading options\n\0" "fs error %d (%s) reading file %s\n\0" + "fs error %d (%s) on %s %s for option %s\n\0" + "stat-ing for directory\0" + "stat-ing for regular file\0" + "stat-ing for non-existant file\0" + "open-ing file\0" + "fopen-ing file\0" + "\t\t\t\t- file must not pre-exist\n\0" + "\t\t\t\t- file must pre-exist\n\0" "\n" "= = = = = = = =\n\n" "This incarnation of genshell will produce\n" @@ -226,20 +278,11 @@ static char const usage_txt[3208] = "[=arg]\0" "--%2$s%1$s\0" "%s: illegal option -- %c\n\0" - "%s: %s option -- %s\n\0" + "%s: illegal option -- %s\n\0" "illegal\0" + " or an integer from %d through %d\n\0" "AutoOpts ERROR: invalid option descriptor for %s\n\0" - "words=\0" - "cooked\0" - "keep\0" - "type=\0" - "uncooked\0" - "integer\0" - "nested\0" - "string\0" - "bool\0" - "keyword\0" - "set\0" + " or an integer mask with any of the lower %d bits set\n\0" "\t\t\t\t- is a set membership option\n\0" "%s: option `%s' requires an argument\n\0" "Equivalenced option '%s' was equivalenced to both\n" @@ -247,26 +290,32 @@ static char const usage_txt[3208] = "\t\t\t\t- must appear between %d and %d times\n\0" "ERROR: The %s option is required\n\0" "%s: option `%s' cannot have an argument\n\0" + "%s: cannot allocate new argument vector\n\0" "%s: Command line arguments not allowed\n\0" "error %d (%s) creating %s\n\0" "Options are specified by single or double hyphens and their name.\n\0" "%s error: `%s' does not match any %s keywords\n\0" "\t\t\t\t- may appear multiple times\n\0" "\t\t\t\t- may not be preset\n\0" + "The 'reset-option' option requires an argument\n\0" " Arg Option-Name Description\n\0" " Flg Arg Option-Name Description\n\0" "error %d (%s) stat-ing %s\n\0" "%s(optionRestore): error: no saved option state\n\0" "none\0" "'%s' not defined\n\0" + "'%s' is not a command line option\n\0" "ERROR: The %s option must appear %d times\n\0" "error: cannot load options from non-regular file %s\n\0" "%s error: `%s' is not a recognizable number\n\0" + "%s error: `%s' is not a recognizable date/time\n\0" + "%s error: `%s' is not a recognizable time duration\n\0" " %3s %s\0" "The '-#<number>' option may omit the hash char\n\0" " \0" "one %s%s option allowed\n\0" "All arguments are named options.\n\0" + "Write failure to output file\0" " - reading file %s\0" "\n" "please send bug reports to: %s\n\0" @@ -275,16 +324,24 @@ static char const usage_txt[3208] = "# %s#\n\0" "\n" "The following option preset mechanisms are supported:\n\0" - "program\0" "prohibits these options:\n\0" "Operands and options may be intermixed. They will be reordered.\n\0" + "%s%ld to %ld\0" + "%sgreater than or equal to %ld\0" + "%sIt must lie in one of the ranges:\n\0" + "%sIt must be in the range:\n\0" + ", or\n\0" + "%s error: %s option value ``%s'' is out of range.\n\0" + "%s%ld exactly\0" + "%sis scalable with a suffix: k/K/m/M/g/G/t/T\n\0" + "%sless than or equal to %ld\0" + "The --reset-option has not been configured.\n\0" "ERROR: %s option requires the %s option\n\0" " %3s %-14s %s\0" "requires these options:\n\0" " Arg Option-Name Req? Description\n\0" " Flg Arg Option-Name Req? Description\n\0" "-_^\0" - "members=\0" "or you may use a numeric representation. Preceding these with a '!' will\n" "clear the bits, specifying 'none' will clear all bits, and 'all' will set them\n" "all. Multiple entries may be passed as an option argument list.\n\0" @@ -294,8 +351,10 @@ static char const usage_txt[3208] = "\n" "%s\n\n" "%s\0" + "Fil\0" "KWd\0" "Mbr\0" + "Tim\0" "Cpx\0" "no \0" "Num\0" @@ -317,37 +376,44 @@ static char const usage_txt[3208] = * Aren't you glad you don't maintain this by hand? */ usage_text_t option_usage_text = { - 113, - eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuKeyLArg, eng_zGnuNumArg, - eng_zGnuStrArg, + 142, + eng_zGnuBoolArg, eng_zGnuKeyArg, eng_zGnuFileArg, eng_zGnuKeyLArg, + eng_zGnuTimeArg, eng_zGnuNumArg, eng_zGnuStrArg, { - usage_txt + 0, usage_txt + 52, usage_txt + 98, usage_txt + 197, - usage_txt + 247, usage_txt + 251, usage_txt + 278, usage_txt + 327, - usage_txt + 337, usage_txt + 374, usage_txt + 399, usage_txt + 425, - usage_txt + 465, usage_txt + 602, usage_txt + 650, usage_txt + 704, - usage_txt + 746, usage_txt + 770, usage_txt + 796, usage_txt + 809, - usage_txt + 823, usage_txt + 870, usage_txt + 876, usage_txt + 979, - usage_txt + 991, usage_txt +1042, usage_txt +1093, usage_txt +1127, - usage_txt +1233, usage_txt +1239, usage_txt +1245, usage_txt +1252, - usage_txt +1263, usage_txt +1289, usage_txt +1310, usage_txt +1318, - usage_txt +1369, usage_txt +1376, usage_txt +1383, usage_txt +1388, - usage_txt +1394, usage_txt +1403, usage_txt +1411, usage_txt +1418, - usage_txt +1425, usage_txt +1430, usage_txt +1438, usage_txt +1442, - usage_txt +1476, usage_txt +1514, usage_txt +1579, usage_txt +1622, - usage_txt +1657, usage_txt +1698, usage_txt +1738, usage_txt +1765, - usage_txt +1832, usage_txt +1880, usage_txt +1913, usage_txt +1938, - usage_txt +1973, usage_txt +2011, usage_txt +2038, usage_txt +2087, - usage_txt +2092, usage_txt +2110, usage_txt +2154, usage_txt +2208, - usage_txt +2254, usage_txt +2262, usage_txt +2310, usage_txt +2312, - usage_txt +2337, usage_txt +2371, usage_txt +2390, usage_txt +2424, - usage_txt +2460, usage_txt +2498, usage_txt +2554, usage_txt +2562, - usage_txt +2588, usage_txt +2654, usage_txt +2696, usage_txt +2710, - usage_txt +2735, usage_txt +2775, usage_txt +2818, usage_txt +2822, - usage_txt +2831, usage_txt +3050, usage_txt +3053, usage_txt +3060, - usage_txt +3064, usage_txt +3072, usage_txt +3076, usage_txt +3080, - usage_txt +3084, usage_txt +3088, usage_txt +3092, usage_txt +3096, - usage_txt +3100, usage_txt +3104, usage_txt +3111, usage_txt +3123, - usage_txt +3131, usage_txt +3135, usage_txt +3138, usage_txt +3171 + usage_txt + 0, usage_txt + 27, usage_txt + 79, usage_txt + 125, + usage_txt + 224, usage_txt + 260, usage_txt + 310, usage_txt + 343, + usage_txt + 434, usage_txt + 493, usage_txt + 543, usage_txt + 547, + usage_txt + 574, usage_txt + 623, usage_txt + 651, usage_txt + 688, + usage_txt + 713, usage_txt + 739, usage_txt + 779, usage_txt + 916, + usage_txt + 964, usage_txt +1018, usage_txt +1031, usage_txt +1039, + usage_txt +1081, usage_txt +1105, usage_txt +1145, usage_txt +1160, + usage_txt +1190, usage_txt +1216, usage_txt +1229, usage_txt +1243, + usage_txt +1290, usage_txt +1296, usage_txt +1399, usage_txt +1411, + usage_txt +1462, usage_txt +1491, usage_txt +1542, usage_txt +1576, + usage_txt +1617, usage_txt +1640, usage_txt +1666, usage_txt +1697, + usage_txt +1711, usage_txt +1726, usage_txt +1757, usage_txt +1784, + usage_txt +1890, usage_txt +1896, usage_txt +1902, usage_txt +1909, + usage_txt +1920, usage_txt +1946, usage_txt +1972, usage_txt +1980, + usage_txt +2016, usage_txt +2067, usage_txt +2123, usage_txt +2157, + usage_txt +2195, usage_txt +2260, usage_txt +2303, usage_txt +2338, + usage_txt +2379, usage_txt +2420, usage_txt +2460, usage_txt +2487, + usage_txt +2554, usage_txt +2602, usage_txt +2635, usage_txt +2660, + usage_txt +2708, usage_txt +2743, usage_txt +2781, usage_txt +2808, + usage_txt +2857, usage_txt +2862, usage_txt +2880, usage_txt +2915, + usage_txt +2959, usage_txt +3013, usage_txt +3059, usage_txt +3108, + usage_txt +3161, usage_txt +3169, usage_txt +3217, usage_txt +3219, + usage_txt +3244, usage_txt +3278, usage_txt +3307, usage_txt +3326, + usage_txt +3360, usage_txt +3396, usage_txt +3434, usage_txt +3490, + usage_txt +3516, usage_txt +3582, usage_txt +3595, usage_txt +3626, + usage_txt +3663, usage_txt +3691, usage_txt +3697, usage_txt +3749, + usage_txt +3763, usage_txt +3809, usage_txt +3837, usage_txt +3882, + usage_txt +3924, usage_txt +3938, usage_txt +3963, usage_txt +4003, + usage_txt +4046, usage_txt +4050, usage_txt +4269, usage_txt +4272, + usage_txt +4279, usage_txt +4283, usage_txt +4291, usage_txt +4295, + usage_txt +4299, usage_txt +4303, usage_txt +4307, usage_txt +4311, + usage_txt +4315, usage_txt +4319, usage_txt +4323, usage_txt +4327, + usage_txt +4331, usage_txt +4338, usage_txt +4350, usage_txt +4358, + usage_txt +4362, usage_txt +4365, usage_txt +4398 } }; diff --git a/sntp/libopts/boolean.c b/sntp/libopts/boolean.c index 37148a9cc3ba..8079231105d8 100644 --- a/sntp/libopts/boolean.c +++ b/sntp/libopts/boolean.c @@ -1,55 +1,33 @@ -/* - * $Id: boolean.c,v 4.10 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 10:10:39 bkorb" +/** + * \file boolean.c + * + * Time-stamp: "2010-07-10 11:02:10 bkorb" * * Automated Options Paged Usage module. * * This routine will run run-on options through a pager so the * user may examine, print or edit them at their leisure. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ /*=export_func optionBooleanVal @@ -70,6 +48,14 @@ optionBooleanVal( tOptions* pOpts, tOptDesc* pOD ) char* pz; ag_bool res = AG_TRUE; + if ((pOD->fOptState & OPTST_RESET) != 0) + return; + + if (pOD->optArg.argString == NULL) { + pOD->optArg.argBool = AG_FALSE; + return; + } + switch (*(pOD->optArg.argString)) { case '0': { diff --git a/sntp/libopts/compat/compat.h b/sntp/libopts/compat/compat.h index b3bd58ff4253..230aef9cb352 100644 --- a/sntp/libopts/compat/compat.h +++ b/sntp/libopts/compat/compat.h @@ -1,13 +1,50 @@ /* -*- Mode: C -*- */ -/* --- fake the preprocessor into handlng portability */ -/* - * Time-stamp: "2007-02-03 17:41:06 bkorb" +/** + * \file compat.h --- fake the preprocessor into handlng portability + * + * Time-stamp: "2010-07-16 15:11:57 bkorb" + * + * compat.h is free software. + * This file is part of AutoGen. + * + * AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoGen 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 3 of the License, or + * (at your option) any later version. + * + * AutoGen 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. * - * Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk> - * Created: Mon Jun 30 15:54:46 1997 + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. * - * $Id: compat.h,v 4.16 2007/04/27 01:10:47 bkorb Exp $ + * As a special exception, Bruce Korb gives permission for additional + * uses of the text contained in the release of compat.h. + * + * The exception is that, if you link the compat.h library with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the compat.h library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by Bruce Korb under + * the name compat.h. If you copy code from other sources under the + * General Public License into a copy of compat.h, as the General Public + * License permits, the exception does not apply to the code that you add + * in this way. To avoid misleading anyone as to the status of such + * modified files, you must delete this exception notice from them. + * + * If you write modifications of your own for compat.h, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. */ #ifndef COMPAT_H_GUARD #define COMPAT_H_GUARD 1 @@ -221,57 +258,89 @@ #endif #ifndef SHORT_MAX -# define SHORT_MAX ~(1 << (8*sizeof(short) -1)) +# define SHORT_MAX ~(1 << (8*sizeof(short) - 1)) #else # define USHORT_MAX ~(OUS) #endif #ifndef HAVE_INT8_T - typedef signed char int8_t; + typedef signed char int8_t; +# define HAVE_INT8_T 1 #endif #ifndef HAVE_UINT8_T - typedef unsigned char uint8_t; + typedef unsigned char uint8_t; +# define HAVE_UINT8_T 1 #endif #ifndef HAVE_INT16_T - typedef signed short int16_t; + typedef signed short int16_t; +# define HAVE_INT16_T 1 #endif #ifndef HAVE_UINT16_T - typedef unsigned short uint16_t; -#endif -#ifndef HAVE_UINT_T - typedef unsigned int uint_t; + typedef unsigned short uint16_t; +# define HAVE_UINT16_T 1 #endif #ifndef HAVE_INT32_T -# if SIZEOF_INT == 4 - typedef signed int int32_t; -# elif SIZEOF_LONG == 4 - typedef signed long int32_t; +# if SIZEOF_INT == 4 + typedef signed int int32_t; +# elif SIZEOF_LONG == 4 + typedef signed long int32_t; # endif +# define HAVE_INT32_T 1 #endif #ifndef HAVE_UINT32_T -# if SIZEOF_INT == 4 - typedef unsigned int uint32_t; -# elif SIZEOF_LONG == 4 - typedef unsigned long uint32_t; +# if SIZEOF_INT == 4 + typedef unsigned int uint32_t; +# elif SIZEOF_LONG == 4 + typedef unsigned long uint32_t; # else # error Cannot create a uint32_t type. Choke Me. # endif +# define HAVE_UINT32_T 1 #endif #ifndef HAVE_INTPTR_T - typedef signed long intptr_t; +# if SIZEOF_CHARP == SIZEOF_LONG + typedef signed long intptr_t; +# else + typedef signed int intptr_t; +# endif +# define HAVE_INTPTR_T 1 #endif + #ifndef HAVE_UINTPTR_T - typedef unsigned long uintptr_t; +# if SIZEOF_CHARP == SIZEOF_LONG + typedef unsigned long intptr_t; +# else + typedef unsigned int intptr_t; +# endif +# define HAVE_INTPTR_T 1 +#endif + +#ifndef HAVE_UINT_T + typedef unsigned int uint_t; +# define HAVE_UINT_T 1 +#endif + +#ifndef HAVE_SIZE_T + typedef unsigned int size_t; +# define HAVE_SIZE_T 1 +#endif +#ifndef HAVE_WINT_T + typedef unsigned int wint_t; +# define HAVE_WINT_T 1 +#endif +#ifndef HAVE_PID_T + typedef signed int pid_t; +# define HAVE_PID_T 1 #endif /* redefine these for BSD style string libraries */ #ifndef HAVE_STRCHR -# define strchr index -# define strrchr rindex +# define strchr index +# define strrchr rindex #endif #ifdef USE_FOPEN_BINARY diff --git a/sntp/libopts/compat/pathfind.c b/sntp/libopts/compat/pathfind.c index 96eb77129dad..2d5b27d913cc 100644 --- a/sntp/libopts/compat/pathfind.c +++ b/sntp/libopts/compat/pathfind.c @@ -4,12 +4,7 @@ /* * Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk> - * Time-stamp: "2006-09-23 19:46:16 bkorb" - * Created: Tue Jun 24 15:07:31 1997 - * Last Modified: $Date: 2006/11/27 01:52:23 $ - * by: bkorb - * - * $Id: pathfind.c,v 4.10 2006/11/27 01:52:23 bkorb Exp $ + * Time-stamp: "2010-07-17 09:50:32 bkorb" */ /* Code: */ diff --git a/sntp/libopts/compat/windows-config.h b/sntp/libopts/compat/windows-config.h index 2612980bf5a0..360af1098cd0 100644 --- a/sntp/libopts/compat/windows-config.h +++ b/sntp/libopts/compat/windows-config.h @@ -1,8 +1,23 @@ /* - * Time-stamp: "2006-10-14 14:55:09 bkorb" - * by: bkorb - * Last Committed: $Date: 2007/04/28 22:19:23 $ + * Time-stamp: "2010-02-24 08:39:04 bkorb" + * + * This file is part of AutoGen. + * + * AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoGen 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 3 of the License, or + * (at your option) any later version. + * + * AutoGen 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, see <http://www.gnu.org/licenses/>. */ #ifndef WINDOWS_CONFIG_HACKERY #define WINDOWS_CONFIG_HACKERY 1 diff --git a/sntp/libopts/configfile.c b/sntp/libopts/configfile.c index e0b8a7487aa3..35e82d591f9f 100644 --- a/sntp/libopts/configfile.c +++ b/sntp/libopts/configfile.c @@ -1,112 +1,79 @@ -/* - * $Id: configfile.c,v 1.21 2007/04/15 19:01:18 bkorb Exp $ - * Time-stamp: "2007-04-15 11:22:46 bkorb" - * - * configuration/rc/ini file handling. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb +/** + * \file configfile.c * - * Automated Options is free software. - * You may 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. + * Time-stamp: "2011-04-06 09:31:24 bkorb" * - * Automated Options 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. + * configuration/rc/ini file handling. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ +static void +set_usage_flags(tOptions * opts, char const * flg_txt); + /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -filePreset( - tOptions* pOpts, - char const* pzFileName, - int direction ); +file_preset(tOptions * opts, char const * fname, int dir); static char* -handleComment( char* pzText ); +handle_comment(char* pzText); -static char* -handleConfig( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ); +static char * +handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); -static char* -handleDirective( - tOptions* pOpts, - char* pzText ); +static char * +handle_directive(tOptions * pOpts, char * pzText); -static char* -handleProgramSection( - tOptions* pOpts, - char* pzText ); +static char * +aoflags_directive(tOptions * pOpts, char * pzText); -static char* -handleStructure( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ); +static char * +program_directive(tOptions * pOpts, char * pzText); -static char* -parseKeyWordType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ); +static char * +handle_section(tOptions * pOpts, char * pzText); -static char* -parseLoadMode( - char* pzText, - tOptionLoadMode* pMode ); +static int +parse_xml_encoding(char ** ppz); -static char* -parseSetMemType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ); +static char * +trim_xml_text(char * pztxt, char const * pznm, tOptionLoadMode mode); + +static void +cook_xml_text(char * pzData); + +static char * +handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir); static char* -parseValueType( - char* pzText, - tOptionValue* pType ); +parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType); static char* -skipUnknown( char* pzText ); +parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType); + +static char * +parse_value(char * pzText, tOptionValue * pType); + +static char * +skip_unkn(char* pzText); /* = = = END-STATIC-FORWARD = = = */ @@ -141,14 +108,14 @@ skipUnknown( char* pzText ); * @end itemize =*/ const tOptionValue* -configFileLoad( char const* pzFile ) +configFileLoad(char const* pzFile) { tmap_info_t cfgfile; tOptionValue* pRes = NULL; tOptionLoadMode save_mode = option_load_mode; char* pzText = - text_mmap( pzFile, PROT_READ, MAP_PRIVATE, &cfgfile ); + text_mmap(pzFile, PROT_READ, MAP_PRIVATE, &cfgfile); if (TEXT_MMAP_FAILED_ADDR(pzText)) return NULL; /* errno is set */ @@ -158,10 +125,10 @@ configFileLoad( char const* pzFile ) if (pRes == NULL) { int err = errno; - text_munmap( &cfgfile ); + text_munmap(&cfgfile); errno = err; } else - text_munmap( &cfgfile ); + text_munmap(&cfgfile); option_load_mode = save_mode; return pRes; @@ -193,8 +160,8 @@ configFileLoad( char const* pzFile ) * @end itemize =*/ const tOptionValue* -optionFindValue( const tOptDesc* pOptDesc, - char const* pzName, char const* pzVal ) +optionFindValue(const tOptDesc* pOptDesc, char const* pzName, + char const* pzVal) { const tOptionValue* pRes = NULL; @@ -224,7 +191,7 @@ optionFindValue( const tOptDesc* pOptDesc, while (--ct >= 0) { const tOptionValue* pOV = *(ppOV++); - const tOptionValue* pRV = optionGetValue( pOV, pzName ); + const tOptionValue* pRV = optionGetValue(pOV, pzName); if (pRV == NULL) continue; @@ -268,9 +235,9 @@ optionFindValue( const tOptDesc* pOptDesc, * @code{ENOENT} - no entry matched the given name. * @end itemize =*/ -const tOptionValue* -optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal, - char const* pzName, char const* pzVal ) +tOptionValue const * +optionFindNextValue(const tOptDesc * pOptDesc, const tOptionValue * pPrevVal, + char const * pzName, char const * pzVal) { int foundOldVal = 0; tOptionValue* pRes = NULL; @@ -337,7 +304,7 @@ optionFindNextValue( const tOptDesc* pOptDesc, const tOptionValue* pPrevVal, * @end itemize =*/ const tOptionValue* -optionGetValue( const tOptionValue* pOld, char const* pzValName ) +optionGetValue(const tOptionValue* pOld, char const* pzValName) { tArgList* pAL; tOptionValue* pRes = NULL; @@ -358,7 +325,7 @@ optionGetValue( const tOptionValue* pOld, char const* pzValName ) else do { tOptionValue* pOV = *(papOV++); - if (strcmp( pOV->pzName, pzValName ) == 0) { + if (strcmp(pOV->pzName, pzValName) == 0) { pRes = pOV; break; } @@ -433,27 +400,24 @@ optionNextValue(tOptionValue const * pOVList,tOptionValue const * pOldOV ) } -/* filePreset - * +/** * Load a file containing presetting information (a configuration file). */ static void -filePreset( - tOptions* pOpts, - char const* pzFileName, - int direction ) +file_preset(tOptions * opts, char const * fname, int dir) { tmap_info_t cfgfile; - tOptState st = OPTSTATE_INITIALIZER(PRESET); - char* pzFileText = - text_mmap( pzFileName, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile ); + tOptState optst = OPTSTATE_INITIALIZER(PRESET); + tAoUL st_flags = optst.flags; + char * ftext = + text_mmap(fname, PROT_READ|PROT_WRITE, MAP_PRIVATE, &cfgfile); - if (TEXT_MMAP_FAILED_ADDR(pzFileText)) + if (TEXT_MMAP_FAILED_ADDR(ftext)) return; - if (direction == DIRECTION_CALLED) { - st.flags = OPTST_DEFINED; - direction = DIRECTION_PROCESS; + if (dir == DIRECTION_CALLED) { + st_flags = OPTST_DEFINED; + dir = DIRECTION_PROCESS; } /* @@ -462,32 +426,33 @@ filePreset( * If this is called via "optionFileLoad", then the bit is not set * and we consider stuff set herein to be "set" by the client program. */ - if ((pOpts->fOptSet & OPTPROC_PRESETTING) == 0) - st.flags = OPTST_SET; + if ((opts->fOptSet & OPTPROC_PRESETTING) == 0) + st_flags = OPTST_SET; do { - while (isspace( (int)*pzFileText )) pzFileText++; + optst.flags = st_flags; + while (IS_WHITESPACE_CHAR(*ftext)) ftext++; - if (isalpha( (int)*pzFileText )) { - pzFileText = handleConfig( pOpts, &st, pzFileText, direction ); + if (IS_VAR_FIRST_CHAR(*ftext)) { + ftext = handle_cfg(opts, &optst, ftext, dir); - } else switch (*pzFileText) { + } else switch (*ftext) { case '<': - if (isalpha( (int)pzFileText[1] )) - pzFileText = handleStructure(pOpts, &st, pzFileText, direction); + if (IS_VAR_FIRST_CHAR(ftext[1])) + ftext = handle_struct(opts, &optst, ftext, dir); - else switch (pzFileText[1]) { + else switch (ftext[1]) { case '?': - pzFileText = handleDirective( pOpts, pzFileText ); + ftext = handle_directive(opts, ftext); break; case '!': - pzFileText = handleComment( pzFileText ); + ftext = handle_comment(ftext); break; case '/': - pzFileText = strchr( pzFileText+2, '>' ); - if (pzFileText++ != NULL) + ftext = strchr(ftext + 2, '>'); + if (ftext++ != NULL) break; default: @@ -496,65 +461,59 @@ filePreset( break; case '[': - pzFileText = handleProgramSection( pOpts, pzFileText ); + ftext = handle_section(opts, ftext); break; case '#': - pzFileText = strchr( pzFileText+1, '\n' ); + ftext = strchr(ftext + 1, '\n'); break; default: goto all_done; /* invalid format */ } - } while (pzFileText != NULL); + } while (ftext != NULL); - all_done: - text_munmap( &cfgfile ); +all_done: + text_munmap(&cfgfile); } -/* handleComment - * +/** * "pzText" points to a "<!" sequence. * Theoretically, we should ensure that it begins with "<!--", * but actually I don't care that much. It ends with "-->". */ static char* -handleComment( char* pzText ) +handle_comment(char* pzText) { - char* pz = strstr( pzText, "-->" ); + char* pz = strstr(pzText, "-->"); if (pz != NULL) pz += 3; return pz; } -/* handleConfig - * +/** * "pzText" points to the start of some value name. * The end of the entry is the end of the line that is not preceded by * a backslash escape character. The string value is always processed * in "cooked" mode. */ -static char* -handleConfig( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ) +static char * +handle_cfg(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) { char* pzName = pzText++; - char* pzEnd = strchr( pzText, '\n' ); + char* pzEnd = strchr(pzText, '\n'); if (pzEnd == NULL) return pzText + strlen(pzText); - while (ISNAMECHAR( (int)*pzText )) pzText++; - while (isspace( (int)*pzText )) pzText++; + while (IS_VALUE_NAME_CHAR(*pzText)) pzText++; + while (IS_WHITESPACE_CHAR(*pzText)) pzText++; if (pzText > pzEnd) { name_only: *pzEnd++ = NUL; - loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED ); + loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } @@ -564,10 +523,10 @@ handleConfig( * is an invalid format and we give up parsing the text. */ if ((*pzText == '=') || (*pzText == ':')) { - while (isspace( (int)*++pzText )) ; + while (IS_WHITESPACE_CHAR(*++pzText)) ; if (pzText > pzEnd) goto name_only; - } else if (! isspace((int)pzText[-1])) + } else if (! IS_WHITESPACE_CHAR(pzText[-1])) return NULL; /* @@ -610,116 +569,334 @@ handleConfig( * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine( pOpts, pOS, pzName, direction, OPTION_LOAD_UNCOOKED ); + loadOptionLine(pOpts, pOS, pzName, dir, OPTION_LOAD_UNCOOKED); return pzEnd; } -/* handleDirective - * +/** * "pzText" points to a "<?" sequence. - * For the moment, we only handle "<?program" directives. + * We handle "<?program" and "<?auto-options" directives. + * All others are treated as comments. */ -static char* -handleDirective( - tOptions* pOpts, - char* pzText ) +static char * +handle_directive(tOptions * pOpts, char * pzText) { - char ztitle[32] = "<?"; - size_t title_len = strlen( zProg ); - size_t name_len; +# define DIRECTIVE_TABLE \ + _dt_(zCfgProg, program_directive) \ + _dt_(zCfgAO_Flags, aoflags_directive) + + typedef char * (directive_func_t)(tOptions *, char *); +# define _dt_(_s, _fn) _fn, + static directive_func_t * dir_disp[] = { + DIRECTIVE_TABLE + }; +# undef _dt_ + +# define _dt_(_s, _fn) 1 + + static int const dir_ct = DIRECTIVE_TABLE 0; + static char const * dir_names[DIRECTIVE_TABLE 0]; +# undef _dt_ + + int ix; + + if (dir_names[0] == NULL) { + ix = 0; +# define _dt_(_s, _fn) dir_names[ix++] = _s; + DIRECTIVE_TABLE; +# undef _dt_ + } - if ( (strncmp( pzText+2, zProg, title_len ) != 0) - || (! isspace( (int)pzText[title_len+2] )) ) { - pzText = strchr( pzText+2, '>' ); - if (pzText != NULL) - pzText++; - return pzText; + for (ix = 0; ix < dir_ct; ix++) { + size_t len = strlen(dir_names[ix]); + if ( (strncmp(pzText + 2, dir_names[ix], len) == 0) + && (! IS_VALUE_NAME_CHAR(pzText[len+2])) ) + return dir_disp[ix](pOpts, pzText + len + 2); } - name_len = strlen( pOpts->pzProgName ); - strcpy( ztitle+2, zProg ); - title_len += 2; + /* + * We don't know what this is. Skip it. + */ + pzText = strchr(pzText+2, '>'); + if (pzText != NULL) + pzText++; + return pzText; +} + +/** + * handle AutoOpts mode flags + */ +static char * +aoflags_directive(tOptions * pOpts, char * pzText) +{ + char * pz = pzText; + + while (IS_WHITESPACE_CHAR(*++pz)) ; + pzText = strchr(pz, '>'); + if (pzText != NULL) { + + size_t len = pzText - pz; + char * ftxt = AGALOC(len + 1, "aoflags"); + + memcpy(ftxt, pz, len); + ftxt[len] = NUL; + set_usage_flags(pOpts, ftxt); + AGFREE(ftxt); + + pzText++; + } + + return pzText; +} + +/** + * handle program segmentation of config file. + */ +static char * +program_directive(tOptions * pOpts, char * pzText) +{ + static char const ttlfmt[] = "<?"; + size_t ttl_len = sizeof(ttlfmt) + strlen(zCfgProg); + char * ttl = AGALOC(ttl_len, "prog title"); + size_t name_len = strlen(pOpts->pzProgName); + + memcpy(ttl, ttlfmt, sizeof(ttlfmt) - 1); + memcpy(ttl + sizeof(ttlfmt) - 1, zCfgProg, ttl_len - (sizeof(ttlfmt) - 1)); do { - pzText += title_len; + while (IS_WHITESPACE_CHAR(*++pzText)) ; - if (isspace((int)*pzText)) { - while (isspace((int)*pzText)) pzText++; - if ( (strneqvcmp( pzText, pOpts->pzProgName, (int)name_len) == 0) - && (pzText[name_len] == '>')) { - pzText += name_len + 1; - break; - } + if ( (strneqvcmp(pzText, pOpts->pzProgName, (int)name_len) == 0) + && (IS_END_XML_TOKEN_CHAR(pzText[name_len])) ) { + pzText += name_len; + break; } - pzText = strstr( pzText, ztitle ); + pzText = strstr(pzText, ttl); } while (pzText != NULL); + AGFREE(ttl); + if (pzText != NULL) + for (;;) { + if (*pzText == NUL) { + pzText = NULL; + break; + } + if (*(pzText++) == '>') + break; + } + return pzText; } -/* handleProgramSection - * +/** * "pzText" points to a '[' character. * The "traditional" [PROG_NAME] segmentation of the config file. * Do not ever mix with the "<?program prog-name>" variation. */ -static char* -handleProgramSection( - tOptions* pOpts, - char* pzText ) +static char * +handle_section(tOptions * pOpts, char * pzText) { - size_t len = strlen( pOpts->pzPROGNAME ); - if ( (strncmp( pzText+1, pOpts->pzPROGNAME, len ) == 0) + size_t len = strlen(pOpts->pzPROGNAME); + if ( (strncmp(pzText+1, pOpts->pzPROGNAME, len) == 0) && (pzText[len+1] == ']')) - return strchr( pzText + len + 2, '\n' ); + return strchr(pzText + len + 2, '\n'); if (len > 16) return NULL; { char z[24]; - sprintf( z, "[%s]", pOpts->pzPROGNAME ); - pzText = strstr( pzText, z ); + sprintf(z, "[%s]", pOpts->pzPROGNAME); + pzText = strstr(pzText, z); } if (pzText != NULL) - pzText = strchr( pzText, '\n' ); + pzText = strchr(pzText, '\n'); return pzText; } +/** + * parse XML encodings + */ +static int +parse_xml_encoding(char ** ppz) +{ +# define XMLTABLE \ + _xmlNm_(amp, '&') \ + _xmlNm_(lt, '<') \ + _xmlNm_(gt, '>') \ + _xmlNm_(ff, '\f') \ + _xmlNm_(ht, '\t') \ + _xmlNm_(cr, '\r') \ + _xmlNm_(vt, '\v') \ + _xmlNm_(bel, '\a') \ + _xmlNm_(nl, '\n') \ + _xmlNm_(space, ' ') \ + _xmlNm_(quot, '"') \ + _xmlNm_(apos, '\'') + + static struct { + char const * const nm_str; + unsigned short nm_len; + short nm_val; + } const xml_names[] = { +# define _xmlNm_(_n, _v) { #_n ";", sizeof(#_n), _v }, + XMLTABLE +# undef _xmlNm_ +# undef XMLTABLE + }; + + static int const nm_ct = sizeof(xml_names) / sizeof(xml_names[0]); + int base = 10; + + char * pz = *ppz; + + if (*pz == '#') { + pz++; + goto parse_number; + } + + if (IS_DEC_DIGIT_CHAR(*pz)) { + unsigned long v; + + parse_number: + switch (*pz) { + case 'x': case 'X': + /* + * Some forms specify hex with: &#xNN; + */ + base = 16; + pz++; + break; -/* handleStructure - * + case '0': + /* + *  is hex and  is decimal. Cool. + * Ya gotta love it. + */ + if (pz[1] == '0') + base = 16; + break; + } + + v = strtoul(pz, &pz, base); + if ((*pz != ';') || (v > 0x7F)) + return NUL; + *ppz = pz + 1; + return (int)v; + } + + { + int ix = 0; + do { + if (strncmp(pz, xml_names[ix].nm_str, xml_names[ix].nm_len) + == 0) { + *ppz = pz + xml_names[ix].nm_len; + return xml_names[ix].nm_val; + } + } while (++ix < nm_ct); + } + + return NUL; +} + +/** + * Find the end marker for the named section of XML. + * Trim that text there, trimming trailing white space for all modes + * except for OPTION_LOAD_UNCOOKED. + */ +static char * +trim_xml_text(char * pztxt, char const * pznm, tOptionLoadMode mode) +{ + static char const fmt[] = "</%s>"; + char z[64], *pz = z; + size_t len = strlen(pznm) + sizeof(fmt) - 2 /* for %s */; + + if (len > sizeof(z)) + pz = AGALOC(len, "scan name"); + + sprintf(pz, fmt, pznm); + *pztxt = ' '; + pztxt = strstr(pztxt, pz); + if (pz != z) AGFREE(pz); + + if (pztxt == NULL) + return pztxt; + + if (mode != OPTION_LOAD_UNCOOKED) + while (IS_WHITESPACE_CHAR(pztxt[-1])) len++, pztxt--; + + *pztxt = NUL; + return pztxt + len - 1 /* for NUL byte */; +} + +/** + */ +static void +cook_xml_text(char * pzData) +{ + char * pzs = pzData; + char * pzd = pzData; + char bf[4]; + bf[2] = NUL; + + for (;;) { + int ch = ((int)*(pzs++)) & 0xFF; + switch (ch) { + case NUL: + *pzd = NUL; + return; + + case '&': + *(pzd++) = \ + ch = parse_xml_encoding(&pzs); + if (ch == NUL) + return; + break; + + case '%': + bf[0] = *(pzs++); + bf[1] = *(pzs++); + if ((bf[0] == NUL) || (bf[1] == NUL)) { + *pzd = NUL; + return; + } + + ch = strtoul(bf, NULL, 16); + /* FALLTHROUGH */ + + default: + *(pzd++) = ch; + } + } +} + +/** * "pzText" points to a '<' character, followed by an alpha. * The end of the entry is either the "/>" following the name, or else a * "</name>" string. */ -static char* -handleStructure( - tOptions* pOpts, - tOptState* pOS, - char* pzText, - int direction ) +static char * +handle_struct(tOptions * pOpts, tOptState * pOS, char * pzText, int dir) { tOptionLoadMode mode = option_load_mode; - tOptionValue valu; + tOptionValue valu; char* pzName = ++pzText; char* pzData; char* pcNulPoint; - while (ISNAMECHAR( *pzText )) pzText++; + while (IS_VALUE_NAME_CHAR(*pzText)) pzText++; pcNulPoint = pzText; valu.valType = OPARG_TYPE_STRING; switch (*pzText) { case ' ': case '\t': - pzText = parseAttributes( pOpts, pzText, &mode, &valu ); + pzText = parseAttributes(pOpts, pzText, &mode, &valu); if (*pzText == '>') break; if (*pzText != '/') @@ -731,14 +908,14 @@ handleStructure( return NULL; *pzText = NUL; pzText += 2; - loadOptionLine( pOpts, pOS, pzName, direction, mode ); + loadOptionLine(pOpts, pOS, pzName, dir, mode); return pzText; case '>': break; default: - pzText = strchr( pzText, '>'); + pzText = strchr(pzText, '>'); if (pzText != NULL) pzText++; return pzText; @@ -750,28 +927,9 @@ handleStructure( */ *pcNulPoint = NUL; pzData = ++pzText; - - /* - * Find the end of the option text and NUL terminate it - */ - { - char z[64], *pz = z; - size_t len = strlen(pzName) + 4; - if (len > sizeof(z)) - pz = AGALOC(len, "scan name"); - - sprintf( pz, "</%s>", pzName ); - *pzText = ' '; - pzText = strstr( pzText, pz ); - if (pz != z) AGFREE(pz); - - if (pzText == NULL) - return pzText; - - *pzText = NUL; - - pzText += len-1; - } + pzText = trim_xml_text(pzText, pzName, mode); + if (pzText == NULL) + return pzText; /* * Rejoin the name and value for parsing by "loadOptionLine()". @@ -780,31 +938,47 @@ handleStructure( memset(pcNulPoint, ' ', pzData - pcNulPoint); /* + * If we are getting a "string" value that is to be cooked, + * then process the XML-ish &xx; XML-ish and %XX hex characters. + */ + if ( (valu.valType == OPARG_TYPE_STRING) + && (mode == OPTION_LOAD_COOKED)) + cook_xml_text(pzData); + + /* * "pzName" points to what looks like text for one option/configurable. * It is NUL terminated. Process it. */ - loadOptionLine( pOpts, pOS, pzName, direction, mode ); + loadOptionLine(pOpts, pOS, pzName, dir, mode); return pzText; } -/* internalFileLoad - * +/** * Load a configuration file. This may be invoked either from * scanning the "homerc" list, or from a specific file request. * (see "optionFileLoad()", the implementation for --load-opts) */ LOCAL void -internalFileLoad( tOptions* pOpts ) +internalFileLoad(tOptions* pOpts) { - int idx; - int inc = DIRECTION_PRESET; - char zFileName[ AG_PATH_MAX+1 ]; + uint32_t svfl; + int idx; + int inc; + char zFileName[ AG_PATH_MAX+1 ]; if (pOpts->papzHomeList == NULL) return; + svfl = pOpts->fOptSet; + inc = DIRECTION_PRESET; + + /* + * Never stop on errors in config files. + */ + pOpts->fOptSet &= ~OPTPROC_ERRSTOP; + /* * Find the last RC entry (highest priority entry) */ @@ -838,8 +1012,8 @@ internalFileLoad( tOptions* pOpts ) idx += inc; - if (! optionMakePath( zFileName, (int)sizeof(zFileName), - pzPath, pOpts->pzProgPath )) + if (! optionMakePath(zFileName, (int)sizeof(zFileName), + pzPath, pOpts->pzProgPath)) continue; /* @@ -847,23 +1021,23 @@ internalFileLoad( tOptions* pOpts ) * THEN append the Resource Configuration file name * ELSE we must have the complete file name */ - if (stat( zFileName, &StatBuf ) != 0) + if (stat(zFileName, &StatBuf) != 0) continue; /* bogus name - skip the home list entry */ - if (S_ISDIR( StatBuf.st_mode )) { - size_t len = strlen( zFileName ); - char* pz; + if (S_ISDIR(StatBuf.st_mode)) { + size_t len = strlen(zFileName); + size_t nln = strlen(pOpts->pzRcName) + 1; + char * pz = zFileName + len; - if (len + 1 + strlen( pOpts->pzRcName ) >= sizeof( zFileName )) + if (len + 1 + nln >= sizeof(zFileName)) continue; - pz = zFileName + len; if (pz[-1] != DIRCH) *(pz++) = DIRCH; - strcpy( pz, pOpts->pzRcName ); + memcpy(pz, pOpts->pzRcName, nln); } - filePreset( pOpts, zFileName, inc ); + file_preset(pOpts, zFileName, inc); /* * IF we are now to skip config files AND we are presetting, @@ -877,6 +1051,8 @@ internalFileLoad( tOptions* pOpts ) } } } /* twice for every path in the home list, ... */ + + pOpts->fOptSet = svfl; } @@ -914,13 +1090,18 @@ internalFileLoad( tOptions* pOpts ) * always be returned. =*/ int -optionFileLoad( tOptions* pOpts, char const* pzProgram ) +optionFileLoad(tOptions* pOpts, char const* pzProgram) { - if (! SUCCESSFUL( validateOptionsStruct( pOpts, pzProgram ))) + if (! SUCCESSFUL(validateOptionsStruct(pOpts, pzProgram))) return -1; - pOpts->pzProgName = pzProgram; - internalFileLoad( pOpts ); + { + char const ** pp = + (char const **)(void *)&(pOpts->pzProgName); + *pp = pzProgram; + } + + internalFileLoad(pOpts); return 0; } @@ -937,42 +1118,44 @@ optionFileLoad( tOptions* pOpts, char const* pzProgram ) * pOptDesc->optArg.argString. =*/ void -optionLoadOpt( tOptions* pOpts, tOptDesc* pOptDesc ) +optionLoadOpt(tOptions* pOpts, tOptDesc* pOptDesc) { + struct stat sb; + /* * IF the option is not being disabled, THEN load the file. There must * be a file. (If it is being disabled, then the disablement processing * already took place. It must be done to suppress preloading of ini/rc * files.) */ - if (! DISABLED_OPT( pOptDesc )) { - struct stat sb; - if (stat( pOptDesc->optArg.argString, &sb ) != 0) { - if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) - return; + if ( DISABLED_OPT(pOptDesc) + || ((pOptDesc->fOptState & OPTST_RESET) != 0)) + return; - fprintf( stderr, zFSErrOptLoad, errno, strerror( errno ), - pOptDesc->optArg.argString ); - exit(EX_NOINPUT); - /* NOT REACHED */ - } + if (stat(pOptDesc->optArg.argString, &sb) != 0) { + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) + return; - if (! S_ISREG( sb.st_mode )) { - if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) - return; + fprintf(stderr, zFSErrOptLoad, errno, strerror(errno), + pOptDesc->optArg.argString); + exit(EX_NOINPUT); + /* NOT REACHED */ + } - fprintf( stderr, zNotFile, pOptDesc->optArg.argString ); - exit(EX_NOINPUT); - /* NOT REACHED */ - } + if (! S_ISREG(sb.st_mode)) { + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) == 0) + return; - filePreset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED); + fprintf(stderr, zNotFile, pOptDesc->optArg.argString); + exit(EX_NOINPUT); + /* NOT REACHED */ } + + file_preset(pOpts, pOptDesc->optArg.argString, DIRECTION_CALLED); } -/* parseAttributes - * +/** * Parse the various attributes of an XML-styled config file entry */ LOCAL char* @@ -982,238 +1165,163 @@ parseAttributes( tOptionLoadMode* pMode, tOptionValue* pType ) { - size_t lenLoadType = strlen( zLoadType ); - size_t lenKeyWords = strlen( zKeyWords ); - size_t lenSetMem = strlen( zSetMembers ); + size_t len; do { - switch (*pzText) { - case '/': pType->valType = OPARG_TYPE_NONE; - case '>': return pzText; + if (! IS_WHITESPACE_CHAR(*pzText)) + switch (*pzText) { + case '/': pType->valType = OPARG_TYPE_NONE; + case '>': return pzText; - default: - case NUL: return NULL; - - case ' ': - case '\t': - case '\n': - case '\f': - case '\r': - case '\v': + default: + case NUL: return NULL; + } + + while (IS_WHITESPACE_CHAR(*++pzText)) ; + len = 0; + while (IS_LOWER_CASE_CHAR(pzText[len])) len++; + + switch (find_xat_attribute_id(pzText, len)) { + case XAT_KWD_TYPE: + pzText = parse_value(pzText+len, pType); break; - } - while (isspace( (int)*++pzText )) ; + case XAT_KWD_WORDS: + pzText = parse_keyword(pOpts, pzText+len, pType); + break; - if (strncmp( pzText, zLoadType, lenLoadType ) == 0) { - pzText = parseValueType( pzText+lenLoadType, pType ); - continue; - } + case XAT_KWD_MEMBERS: + pzText = parse_set_mem(pOpts, pzText+len, pType); + break; - if (strncmp( pzText, zKeyWords, lenKeyWords ) == 0) { - pzText = parseKeyWordType( pOpts, pzText+lenKeyWords, pType ); - continue; - } + case XAT_KWD_COOKED: + pzText += len; + if (! IS_END_XML_TOKEN_CHAR(*pzText)) + goto invalid_kwd; - if (strncmp( pzText, zSetMembers, lenSetMem ) == 0) { - pzText = parseSetMemType( pOpts, pzText+lenSetMem, pType ); - continue; - } + *pMode = OPTION_LOAD_COOKED; + break; + + case XAT_KWD_UNCOOKED: + pzText += len; + if (! IS_END_XML_TOKEN_CHAR(*pzText)) + goto invalid_kwd; + + *pMode = OPTION_LOAD_UNCOOKED; + break; + + case XAT_KWD_KEEP: + pzText += len; + if (! IS_END_XML_TOKEN_CHAR(*pzText)) + goto invalid_kwd; - pzText = parseLoadMode( pzText, pMode ); + *pMode = OPTION_LOAD_KEEP; + break; + + default: + case XAT_KWD_INVALID: + invalid_kwd: + pType->valType = OPARG_TYPE_NONE; + return skip_unkn(pzText); + } } while (pzText != NULL); return pzText; } -/* parseKeyWordType - * +/** * "pzText" points to the character after "words=". * What should follow is a name of a keyword (enumeration) list. */ static char* -parseKeyWordType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ) +parse_keyword(tOptions * pOpts, char * pzText, tOptionValue * pType) { - return skipUnknown( pzText ); + return skip_unkn(pzText); } -/* parseLoadMode - * - * "pzText" points to some name character. We check for "cooked" or - * "uncooked" or "keep". This function should handle any attribute - * that does not have an associated value. - */ -static char* -parseLoadMode( - char* pzText, - tOptionLoadMode* pMode ) -{ - { - size_t len = strlen(zLoadCooked); - if (strncmp( pzText, zLoadCooked, len ) == 0) { - if ( (pzText[len] == '>') - || (pzText[len] == '/') - || isspace((int)pzText[len])) { - *pMode = OPTION_LOAD_COOKED; - return pzText + len; - } - goto unknown; - } - } - - { - size_t len = strlen(zLoadUncooked); - if (strncmp( pzText, zLoadUncooked, len ) == 0) { - if ( (pzText[len] == '>') - || (pzText[len] == '/') - || isspace((int)pzText[len])) { - *pMode = OPTION_LOAD_UNCOOKED; - return pzText + len; - } - goto unknown; - } - } - - { - size_t len = strlen(zLoadKeep); - if (strncmp( pzText, zLoadKeep, len ) == 0) { - if ( (pzText[len] == '>') - || (pzText[len] == '/') - || isspace((int)pzText[len])) { - *pMode = OPTION_LOAD_KEEP; - return pzText + len; - } - goto unknown; - } - } - - unknown: - return skipUnknown( pzText ); -} - - -/* parseSetMemType - * +/** * "pzText" points to the character after "members=" * What should follow is a name of a "set membership". * A collection of bit flags. */ static char* -parseSetMemType( - tOptions* pOpts, - char* pzText, - tOptionValue* pType ) +parse_set_mem(tOptions * pOpts, char * pzText, tOptionValue * pType) { - return skipUnknown( pzText ); + return skip_unkn(pzText); } -/* parseValueType - * +/** * "pzText" points to the character after "type=" */ -static char* -parseValueType( - char* pzText, - tOptionValue* pType ) +static char * +parse_value(char * pzText, tOptionValue * pType) { - { - size_t len = strlen(zLtypeString); - if (strncmp( pzText, zLtypeString, len ) == 0) { - if ((pzText[len] == '>') || isspace((int)pzText[len])) { - pType->valType = OPARG_TYPE_STRING; - return pzText + len; - } - goto unknown; - } - } + size_t len = 0; - { - size_t len = strlen(zLtypeInteger); - if (strncmp( pzText, zLtypeInteger, len ) == 0) { - if ((pzText[len] == '>') || isspace((int)pzText[len])) { - pType->valType = OPARG_TYPE_NUMERIC; - return pzText + len; - } - goto unknown; - } - } + if (*(pzText++) != '=') + goto woops; - { - size_t len = strlen(zLtypeBool); - if (strncmp( pzText, zLtypeBool, len ) == 0) { - if ((pzText[len] == '>') || isspace(pzText[len])) { - pType->valType = OPARG_TYPE_BOOLEAN; - return pzText + len; - } - goto unknown; - } - } + while (IS_OPTION_NAME_CHAR(pzText[len])) len++; + pzText += len; - { - size_t len = strlen(zLtypeKeyword); - if (strncmp( pzText, zLtypeKeyword, len ) == 0) { - if ((pzText[len] == '>') || isspace((int)pzText[len])) { - pType->valType = OPARG_TYPE_ENUMERATION; - return pzText + len; - } - goto unknown; - } + if ((len == 0) || (! IS_END_XML_TOKEN_CHAR(*pzText))) { + woops: + pType->valType = OPARG_TYPE_NONE; + return skip_unkn(pzText); } - { - size_t len = strlen(zLtypeSetMembership); - if (strncmp( pzText, zLtypeSetMembership, len ) == 0) { - if ((pzText[len] == '>') || isspace((int)pzText[len])) { - pType->valType = OPARG_TYPE_MEMBERSHIP; - return pzText + len; - } - goto unknown; - } - } + switch (find_value_type_id(pzText - len, len)) { + default: + case VTP_KWD_INVALID: goto woops; - { - size_t len = strlen(zLtypeNest); - if (strncmp( pzText, zLtypeNest, len ) == 0) { - if ((pzText[len] == '>') || isspace((int)pzText[len])) { - pType->valType = OPARG_TYPE_HIERARCHY; - return pzText + len; - } - goto unknown; - } + case VTP_KWD_STRING: + pType->valType = OPARG_TYPE_STRING; + break; + + case VTP_KWD_INTEGER: + pType->valType = OPARG_TYPE_NUMERIC; + break; + + case VTP_KWD_BOOL: + case VTP_KWD_BOOLEAN: + pType->valType = OPARG_TYPE_BOOLEAN; + break; + + case VTP_KWD_KEYWORD: + pType->valType = OPARG_TYPE_ENUMERATION; + break; + + case VTP_KWD_SET: + case VTP_KWD_SET_MEMBERSHIP: + pType->valType = OPARG_TYPE_MEMBERSHIP; + break; + + case VTP_KWD_NESTED: + case VTP_KWD_HIERARCHY: + pType->valType = OPARG_TYPE_HIERARCHY; } - unknown: - pType->valType = OPARG_TYPE_NONE; - return skipUnknown( pzText ); + return pzText; } -/* skipUnknown - * +/** * Skip over some unknown attribute */ -static char* -skipUnknown( char* pzText ) +static char * +skip_unkn(char* pzText) { for (;; pzText++) { - if (isspace( (int)*pzText )) return pzText; - switch (*pzText) { - case NUL: return NULL; - case '/': - case '>': return pzText; - } + if (IS_END_XML_TOKEN_CHAR(*pzText)) return pzText; + if (*pzText == NUL) return NULL; } } -/* validateOptionsStruct - * +/** * Make sure the option descriptor is there and that we understand it. * This should be called from any user entry point where one needs to * worry about validity. (Some entry points are free to assume that @@ -1221,11 +1329,11 @@ skipUnknown( char* pzText ) * already been called.) */ LOCAL tSuccess -validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) +validateOptionsStruct(tOptions* pOpts, char const* pzProgram) { if (pOpts == NULL) { - fputs( zAO_Bad, stderr ); - exit( EX_CONFIG ); + fputs(zAO_Bad, stderr); + exit(EX_CONFIG); } /* @@ -1233,7 +1341,14 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) * is available, then go do it. */ if ( ((pOpts->fOptSet & OPTPROC_TRANSLATE) != 0) - && (pOpts->pTransProc != 0) ) { + && (pOpts->pTransProc != NULL) ) { + /* + * If option names are not to be translated at all, then do not do + * it for configuration parsing either. (That is the bit that really + * gets tested anyway.) + */ + if ((pOpts->fOptSet & OPTPROC_NO_XLAT_MASK) == OPTPROC_NXLAT_OPT) + pOpts->fOptSet |= OPTPROC_NXLAT_OPT_CFG; (*pOpts->pTransProc)(); pOpts->fOptSet &= ~OPTPROC_TRANSLATE; } @@ -1247,14 +1362,16 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) && ( (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) || (pOpts->structVersion < OPTIONS_MINIMUM_VERSION ) ) ) { + static char const aover[] = + __STR(AO_CURRENT)":"__STR(AO_REVISION)":"__STR(AO_AGE)"\n"; - fprintf( stderr, zAO_Err, pOpts->origArgVect[0], - NUM_TO_VER( pOpts->structVersion )); + fprintf(stderr, zAO_Err, pzProgram, NUM_TO_VER(pOpts->structVersion)); if (pOpts->structVersion > OPTIONS_STRUCT_VERSION ) - fputs( zAO_Big, stderr ); + fputs(zAO_Big, stderr); else - fputs( zAO_Sml, stderr ); + fputs(zAO_Sml, stderr); + fwrite(aover, sizeof(aover) - 1, 1, stderr); return FAILURE; } @@ -1263,18 +1380,20 @@ validateOptionsStruct( tOptions* pOpts, char const* pzProgram ) * and the set of equivalent characters. */ if (pOpts->pzProgName == NULL) { - char const* pz = strrchr( pzProgram, DIRCH ); - + char const * pz = strrchr(pzProgram, DIRCH); + char const ** pp = + (char const **)(void **)&(pOpts->pzProgName); if (pz == NULL) - pOpts->pzProgName = pzProgram; - else pOpts->pzProgName = pz+1; + *pp = pzProgram; + else *pp = pz+1; - pOpts->pzProgPath = pzProgram; + pp = (char const **)(void **)&(pOpts->pzProgPath); + *pp = pzProgram; /* * when comparing long names, these are equivalent */ - strequate( zSepChars ); + strequate(zSepChars); } return SUCCESS; diff --git a/sntp/libopts/cook.c b/sntp/libopts/cook.c index bebd123fca5b..811ce593080a 100644 --- a/sntp/libopts/cook.c +++ b/sntp/libopts/cook.c @@ -1,57 +1,35 @@ - -/* - * $Id: cook.c,v 4.10 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2006-09-24 15:21:02 bkorb" +/** + * \file cook.c + * + * Time-stamp: "2011-03-12 15:05:26 bkorb" * * This file contains the routines that deal with processing quoted strings * into an internal format. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ +static ag_bool +contiguous_quote(char ** pps, char * pq, int * lnct_p); /* = = = END-STATIC-FORWARD = = = */ /*=export_func ao_string_cook_escape_char @@ -105,96 +83,132 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl ) case 't': *pRes = '\t'; break; case 'v': *pRes = '\v'; break; - case 'x': /* HEX Escape */ - if (isxdigit( (int)*pzIn )) { - unsigned int val; - unsigned char ch = *pzIn++; - - if ((ch >= 'A') && (ch <= 'F')) - val = 10 + (ch - 'A'); - else if ((ch >= 'a') && (ch <= 'f')) - val = 10 + (ch - 'a'); - else val = ch - '0'; - - ch = *pzIn; + case 'x': + case 'X': /* HEX Escape */ + if (IS_HEX_DIGIT_CHAR(*pzIn)) { + char z[4], *pz = z; - if (! isxdigit( ch )) { - *pRes = val; - res = 2; - break; - } - val <<= 4; - if ((ch >= 'A') && (ch <= 'F')) - val += 10 + (ch - 'A'); - else if ((ch >= 'a') && (ch <= 'f')) - val += 10 + (ch - 'a'); - else val += ch - '0'; - - res = 3; - *pRes = val; + do *(pz++) = *(pzIn++); + while (IS_HEX_DIGIT_CHAR(*pzIn) && (pz < z + 2)); + *pz = NUL; + *pRes = (unsigned char)strtoul(z, NULL, 16); + res += pz - z; } break; - default: + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { /* * IF the character copied was an octal digit, * THEN set the output character to an octal value */ - if (isdigit( (int)*pRes ) && (*pRes < '8')) { - unsigned int val = *pRes - '0'; - unsigned char ch = *pzIn++; + char z[4], *pz = z + 1; + unsigned long val; + z[0] = *pRes; + + while (IS_OCT_DIGIT_CHAR(*pzIn) && (pz < z + 3)) + *(pz++) = *(pzIn++); + *pz = NUL; + val = strtoul(z, NULL, 8); + if (val > 0xFF) + val = 0xFF; + *pRes = (unsigned char)val; + res = pz - z; + break; + } - /* - * IF the second character is *not* an octal digit, - * THEN save the value and bail - */ - if ((ch < '0') || (ch > '7')) { - *pRes = val; - break; - } + default: ; + } - val = (val<<3) + (ch - '0'); - ch = *pzIn; - res = 2; + return res; +} + + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * A quoted string has been found. + * Find the end of it and compress any escape sequences. + */ +static ag_bool +contiguous_quote(char ** pps, char * pq, int * lnct_p) +{ + char * ps = *pps + 1; + for (;;) { + while (IS_WHITESPACE_CHAR(*ps)) + if (*(ps++) == '\n') + (*lnct_p)++; + + /* + * IF the next character is a quote character, + * THEN we will concatenate the strings. + */ + switch (*ps) { + case '"': + case '\'': + *pq = *(ps++); /* assign new quote character and return */ + *pps = ps; + return AG_TRUE; + + case '/': /* - * IF the THIRD character is *not* an octal digit, - * THEN save the value and bail + * Allow for a comment embedded in the concatenated string. */ - if ((ch < '0') || (ch > '7')) { - *pRes = val; + switch (ps[1]) { + default: + *pps = NULL; + return AG_FALSE; + + case '/': + /* + * Skip to end of line + */ + ps = strchr(ps, '\n'); + if (ps == NULL) { + *pps = NULL; + return AG_FALSE; + } break; + + case '*': + { + char* p = strstr( ps+2, "*/" ); + /* + * Skip to terminating star slash + */ + if (p == NULL) { + *pps = NULL; + return AG_FALSE; + } + + while (ps < p) { + if (*(ps++) == '\n') + (*lnct_p)++; + } + + ps = p + 2; + } } + continue; + default: /* - * IF the new value would not be too large, - * THEN add on the third and last character value + * The next non-whitespace character is not a quote. + * The series of quoted strings has come to an end. */ - if ((val<<3) < 0xFF) { - val = (val<<3) + (ch - '0'); - res = 3; - } - - *pRes = val; - break; + *pps = ps; + return AG_FALSE; } } - - return res; } - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * - * A quoted string has been found. - * Find the end of it and compress any escape sequences. - */ /*=export_func ao_string_cook * private: * * what: concatenate and escape-process strings - * arg: + char* + pzScan + The *MODIFIABLE* input buffer + - * arg: + int* + pLineCt + The (possibly NULL) pointer to a line count + + * arg: + char* + pzScan + The *MODIFIABLE* input buffer + + * arg: + int* + lnct_p + The (possibly NULL) pointer to a line count + * * ret-type: char* * ret-desc: The address of the text following the processed strings. @@ -210,8 +224,8 @@ ao_string_cook_escape_char( char const* pzIn, char* pRes, u_int nl ) * * err: @code{NULL} is returned if the string(s) is/are mal-formed. =*/ -char* -ao_string_cook( char* pzScan, int* pLineCt ) +char * +ao_string_cook(char * pzScan, int * lnct_p) { int l = 0; char q = *pzScan; @@ -223,8 +237,8 @@ ao_string_cook( char* pzScan, int* pLineCt ) char* pzD = pzScan++; char* pzS = pzScan; - if (pLineCt == NULL) - pLineCt = &l; + if (lnct_p == NULL) + lnct_p = &l; for (;;) { /* @@ -236,65 +250,8 @@ ao_string_cook( char* pzScan, int* pLineCt ) */ while (*pzS == q) { *pzD = NUL; /* This is probably the end of the line */ - pzS++; - - scan_for_quote: - while (isspace((int)*pzS)) - if (*(pzS++) == '\n') - (*pLineCt)++; - - /* - * IF the next character is a quote character, - * THEN we will concatenate the strings. - */ - switch (*pzS) { - case '"': - case '\'': - break; - - case '/': - /* - * Allow for a comment embedded in the concatenated string. - */ - switch (pzS[1]) { - default: return NULL; - case '/': - /* - * Skip to end of line - */ - pzS = strchr( pzS, '\n' ); - if (pzS == NULL) - return NULL; - (*pLineCt)++; - break; - - case '*': - { - char* p = strstr( pzS+2, "*/" ); - /* - * Skip to terminating star slash - */ - if (p == NULL) - return NULL; - while (pzS < p) { - if (*(pzS++) == '\n') - (*pLineCt)++; - } - - pzS = p + 2; - } - } - goto scan_for_quote; - - default: - /* - * The next non-whitespace character is not a quote. - * The series of quoted strings has come to an end. - */ + if (! contiguous_quote(&pzS, &q, lnct_p)) return pzS; - } - - q = *(pzS++); /* assign new quote character and advance scan */ } /* @@ -305,7 +262,7 @@ ao_string_cook( char* pzScan, int* pLineCt ) return NULL; case '\n': - (*pLineCt)++; + (*lnct_p)++; break; case '\\': @@ -317,7 +274,7 @@ ao_string_cook( char* pzScan, int* pLineCt ) if (*pzS == '\n') { pzS++; pzD--; - (*pLineCt)++; + (*lnct_p)++; } /* diff --git a/sntp/libopts/enumeration.c b/sntp/libopts/enumeration.c index 67dd4f47e429..a79a32e5d31c 100644 --- a/sntp/libopts/enumeration.c +++ b/sntp/libopts/enumeration.c @@ -1,96 +1,86 @@ -/* - * $Id: enumeration.c,v 4.17 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 10:22:35 bkorb" +/** + * \file enumeration.c + * + * Time-stamp: "2011-04-06 10:48:22 bkorb" * * Automated Options Paged Usage module. * * This routine will run run-on options through a pager so the * user may examine, print or edit them at their leisure. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. * - * Automated Options 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. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * These files have the following md5sums: * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -tSCC* pz_enum_err_fmt; +static char const * pz_enum_err_fmt; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -enumError( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - int name_ct ); +enum_err(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, int name_ct); static uintptr_t -findName( - tCC* pzName, - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ); +find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct); + +static void +set_memb_usage(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); + +static void +set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); + +static void +set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct); /* = = = END-STATIC-FORWARD = = = */ static void -enumError( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - int name_ct ) +enum_err(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, int name_ct) { size_t max_len = 0; size_t ttl_len = 0; + int ct_down = name_ct; + int hidden = 0; - if (pOpts != NULL) - fprintf( option_usage_fp, pz_enum_err_fmt, pOpts->pzProgName, - pOD->optArg.argString, pOD->pz_Name ); + /* + * A real "pOpts" pointer means someone messed up. Give a real error. + */ + if (pOpts > OPTPROC_EMIT_LIMIT) + fprintf(option_usage_fp, pz_enum_err_fmt, pOpts->pzProgName, + pOD->optArg.argString, pOD->pz_Name); - fprintf( option_usage_fp, zValidKeys, pOD->pz_Name ); + fprintf(option_usage_fp, zValidKeys, pOD->pz_Name); + /* + * If the first name starts with this funny character, then we have + * a first value with an unspellable name. You cannot specify it. + * So, we don't list it either. + */ if (**paz_names == 0x7F) { paz_names++; - name_ct--; + hidden = 1; + ct_down = --name_ct; } /* @@ -98,15 +88,16 @@ enumError( * of all the names. */ { - tCC * const * paz = paz_names; - int ct = name_ct; + char const * const * paz = paz_names; do { - size_t len = strlen( *(paz++) ) + 1; + size_t len = strlen(*(paz++)) + 1; if (len > max_len) max_len = len; ttl_len += len; - } while (--ct > 0); + } while (--ct_down > 0); + + ct_down = name_ct; } /* @@ -114,20 +105,20 @@ enumError( */ if (max_len > 35) { do { - fprintf( option_usage_fp, " %s\n", *(paz_names++) ); - } while (--name_ct > 0); + fprintf(option_usage_fp, " %s\n", *(paz_names++)); + } while (--ct_down > 0); } /* * ELSE IF they all fit on one line, then do so. */ else if (ttl_len < 76) { - fputc( ' ', option_usage_fp ); + fputc(' ', option_usage_fp); do { - fputc( ' ', option_usage_fp ); - fputs( *(paz_names++), option_usage_fp ); - } while (--name_ct > 0); - fputc( '\n', option_usage_fp ); + fputc(' ', option_usage_fp); + fputs(*(paz_names++), option_usage_fp); + } while (--ct_down > 0); + fputc('\n', option_usage_fp); } /* @@ -137,82 +128,86 @@ enumError( int ent_no = 0; char zFmt[16]; /* format for all-but-last entries on a line */ - sprintf( zFmt, "%%-%ds", (int)max_len ); + sprintf(zFmt, "%%-%ds", (int)max_len); max_len = 78 / max_len; /* max_len is now max entries on a line */ - fputs( " ", option_usage_fp ); + fputs(" ", option_usage_fp); /* * Loop through all but the last entry */ - while (--name_ct > 0) { + ct_down = name_ct; + while (--ct_down > 0) { if (++ent_no == max_len) { /* * Last entry on a line. Start next line, too. */ - fprintf( option_usage_fp, "%s\n ", *(paz_names++) ); + fprintf(option_usage_fp, "%s\n ", *(paz_names++)); ent_no = 0; } else - fprintf( option_usage_fp, zFmt, *(paz_names++) ); + fprintf(option_usage_fp, zFmt, *(paz_names++) ); } - fprintf( option_usage_fp, "%s\n", *paz_names ); + fprintf(option_usage_fp, "%s\n", *paz_names); } - /* - * IF we do not have a pOpts pointer, then this output is being requested - * by the usage procedure. Let's not re-invoke it recursively. - */ - if (pOpts != NULL) - (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE ); - if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) - fputs( zSetMemberSettings, option_usage_fp ); + if (pOpts > OPTPROC_EMIT_LIMIT) { + fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden); + + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) { + fprintf(option_usage_fp, zLowerBits, name_ct); + fputs(zSetMemberSettings, option_usage_fp); + } else { + fprintf(option_usage_fp, zIntRange, hidden, name_ct - 1 + hidden); + } } static uintptr_t -findName( - tCC* pzName, - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ) +find_name(char const * pzName, tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct) { - uintptr_t res = name_ct; - size_t len = strlen( (char*)pzName ); - uintptr_t idx; + /* + * Return the matching index as a pointer sized integer. + * The result gets stashed in a char* pointer. + */ + uintptr_t res = name_ct; + size_t len = strlen((char*)pzName); + uintptr_t idx; + + if (IS_DEC_DIGIT_CHAR(*pzName)) { + char * pz = (char *)(void *)pzName; + unsigned long val = strtoul(pz, &pz, 0); + if ((*pz == NUL) && (val < name_ct)) + return (uintptr_t)val; + enum_err(pOpts, pOD, paz_names, (int)name_ct); + return name_ct; + } + /* * Look for an exact match, but remember any partial matches. * Multiple partial matches means we have an ambiguous match. */ for (idx = 0; idx < name_ct; idx++) { - if (strncmp( (char*)paz_names[idx], (char*)pzName, len) == 0) { + if (strncmp((char*)paz_names[idx], (char*)pzName, len) == 0) { if (paz_names[idx][len] == NUL) return idx; /* full match */ - if (res != name_ct) { - pz_enum_err_fmt = zAmbigKey; - option_usage_fp = stderr; - enumError( pOpts, pOD, paz_names, (int)name_ct ); - } - res = idx; /* save partial match */ + res = (res != name_ct) ? ~0 : idx; /* save partial match */ } } - /* - * no partial match -> error - */ - if (res == name_ct) { - pz_enum_err_fmt = zNoKey; - option_usage_fp = stderr; - enumError( pOpts, pOD, paz_names, (int)name_ct ); - } + if (res < name_ct) + return res; /* partial match */ - /* - * Return the matching index as a char* pointer. - * The result gets stashed in a char* pointer, so it will have to fit. - */ - return res; + pz_enum_err_fmt = (res == name_ct) ? zNoKey : zAmbigKey; + option_usage_fp = stderr; + enum_err(pOpts, pOD, paz_names, (int)name_ct); + return name_ct; } @@ -223,20 +218,18 @@ findName( * arg: tOptDesc*, pOD, enumeration option description * arg: unsigned int, enum_val, the enumeration value to map * - * ret_type: char const* + * ret_type: char const * * ret_desc: the enumeration name from const memory * * doc: This converts an enumeration value into the matching string. =*/ -char const* -optionKeywordName( - tOptDesc* pOD, - unsigned int enum_val ) +char const * +optionKeywordName(tOptDesc * pOD, unsigned int enum_val) { tOptDesc od; od.optArg.argEnum = enum_val; - (*(pOD->pOptProc))( (void*)(2UL), &od ); + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od ); return od.optArg.argString; } @@ -260,11 +253,8 @@ optionKeywordName( * if there is only one partial match. =*/ uintptr_t -optionEnumerationVal( - tOptions* pOpts, - tOptDesc* pOD, - tCC * const * paz_names, - unsigned int name_ct ) +optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD, + char const * const * paz_names, unsigned int name_ct) { uintptr_t res = 0UL; @@ -273,28 +263,28 @@ optionEnumerationVal( * then it is some sort of special request. */ switch ((uintptr_t)pOpts) { - case 0UL: + case (uintptr_t)OPTPROC_EMIT_USAGE: /* * print the list of enumeration names. */ - enumError( pOpts, pOD, paz_names, (int)name_ct ); + enum_err(pOpts, pOD, paz_names, (int)name_ct); break; - case 1UL: + case (uintptr_t)OPTPROC_EMIT_SHELL: { unsigned int ix = pOD->optArg.argEnum; /* * print the name string. */ if (ix >= name_ct) - printf( "INVALID-%d", ix ); + printf("INVALID-%d", ix); else - fputs( paz_names[ ix ], stdout ); + fputs(paz_names[ ix ], stdout); break; } - case 2UL: + case (uintptr_t)OPTPROC_RETURN_VALNAME: { tSCC zInval[] = "*INVALID*"; unsigned int ix = pOD->optArg.argEnum; @@ -304,12 +294,12 @@ optionEnumerationVal( if (ix >= name_ct) return (uintptr_t)zInval; - res = (uintptr_t)paz_names[ ix ]; + pOD->optArg.argString = paz_names[ix]; break; } default: - res = findName( pOD->optArg.argString, pOpts, pOD, paz_names, name_ct ); + res = find_name(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct); if (pOD->fOptState & OPTST_ALLOC_ARG) { AGFREE(pOD->optArg.argString); @@ -321,6 +311,89 @@ optionEnumerationVal( return res; } +static void +set_memb_usage(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + /* + * print the list of enumeration names. + */ + enum_err(OPTPROC_EMIT_USAGE, pOD, paz_names, (int)name_ct ); +} + +static void +set_memb_shell(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + /* + * print the name string. + */ + int ix = 0; + uintptr_t bits = (uintptr_t)pOD->optCookie; + size_t len = 0; + + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + + while (bits != 0) { + if (bits & 1) { + if (len++ > 0) fputs(" | ", stdout); + fputs(paz_names[ix], stdout); + } + if (++ix >= name_ct) break; + bits >>= 1; + } +} + +static void +set_memb_names(tOptions * pOpts, tOptDesc * pOD, char const * const * paz_names, + unsigned int name_ct) +{ + static char const none[] = "none"; + static char const plus[3] = " + "; + + char * pz; + uintptr_t bits = (uintptr_t)pOD->optCookie; + int ix = 0; + size_t len = sizeof(none); + + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + + /* + * Replace the enumeration value with the name string. + * First, determine the needed length, then allocate and fill in. + */ + while (bits != 0) { + if (bits & 1) + len += strlen(paz_names[ix]) + sizeof(plus); + if (++ix >= name_ct) break; + bits >>= 1; + } + + pOD->optArg.argString = pz = AGALOC(len, "enum name"); + + /* + * Start by clearing all the bits. We want to turn off any defaults + * because we will be restoring to current state, not adding to + * the default set of bits. + */ + memcpy(pz, none, sizeof(none)-1); + pz += sizeof(none)-1; + bits = (uintptr_t)pOD->optCookie; + bits &= ((uintptr_t)1 << (uintptr_t)name_ct) - (uintptr_t)1; + ix = 0; + + while (bits != 0) { + if (bits & 1) { + size_t nln = strlen(paz_names[ix]); + memcpy(pz, plus, sizeof(plus)); + memcpy(pz+sizeof(plus), paz_names[ix], nln); + pz += strlen(paz_names[ix]) + 3; + } + if (++ix >= name_ct) break; + bits >>= 1; + } + *pz = NUL; +} /*=export_func optionSetMembers * what: Convert between bit flag values and strings @@ -339,91 +412,35 @@ optionEnumerationVal( * if there is only one partial match. =*/ void -optionSetMembers( - tOptions* pOpts, - tOptDesc* pOD, - tCC* const * paz_names, - unsigned int name_ct ) +optionSetMembers(tOptions * pOpts, tOptDesc * pOD, + char const* const * paz_names, unsigned int name_ct) { /* * IF the program option descriptor pointer is invalid, * then it is some sort of special request. */ switch ((uintptr_t)pOpts) { - case 0UL: - /* - * print the list of enumeration names. - */ - enumError( pOpts, pOD, paz_names, (int)name_ct ); + case (uintptr_t)OPTPROC_EMIT_USAGE: + set_memb_usage(pOpts, pOD, paz_names, name_ct); return; - case 1UL: - { - /* - * print the name string. - */ - uintptr_t bits = (uintptr_t)pOD->optCookie; - uintptr_t res = 0; - size_t len = 0; - - while (bits != 0) { - if (bits & 1) { - if (len++ > 0) fputs( " | ", stdout ); - fputs( paz_names[ res ], stdout ); - } - if (++res >= name_ct) break; - bits >>= 1; - } + case (uintptr_t)OPTPROC_EMIT_SHELL: + set_memb_shell(pOpts, pOD, paz_names, name_ct); return; - } - case 2UL: - { - char* pz; - uintptr_t bits = (uintptr_t)pOD->optCookie; - uintptr_t res = 0; - size_t len = 0; - - /* - * Replace the enumeration value with the name string. - * First, determine the needed length, then allocate and fill in. - */ - while (bits != 0) { - if (bits & 1) - len += strlen( paz_names[ res ]) + 8; - if (++res >= name_ct) break; - bits >>= 1; - } - - pOD->optArg.argString = pz = AGALOC( len, "enum name" ); - - /* - * Start by clearing all the bits. We want to turn off any defaults - * because we will be restoring to current state, not adding to - * the default set of bits. - */ - strcpy( pz, "none" ); - pz += 4; - bits = (uintptr_t)pOD->optCookie; - res = 0; - while (bits != 0) { - if (bits & 1) { - strcpy( pz, " + " ); - strcpy( pz+3, paz_names[ res ]); - pz += strlen( paz_names[ res ]) + 3; - } - if (++res >= name_ct) break; - bits >>= 1; - } + case (uintptr_t)OPTPROC_RETURN_VALNAME: + set_memb_names(pOpts, pOD, paz_names, name_ct); return; - } default: break; } + if ((pOD->fOptState & OPTST_RESET) != 0) + return; + { - tCC* pzArg = pOD->optArg.argString; + char const* pzArg = pOD->optArg.argString; uintptr_t res; if ((pzArg == NULL) || (*pzArg == NUL)) { pOD->optCookie = (void*)0; @@ -435,42 +452,49 @@ optionSetMembers( tSCC zSpn[] = " ,|+\t\r\f\n"; int iv, len; - pzArg += strspn( pzArg, zSpn ); + pzArg += strspn(pzArg, zSpn); iv = (*pzArg == '!'); if (iv) - pzArg += strspn( pzArg+1, zSpn ) + 1; + pzArg += strspn(pzArg+1, zSpn) + 1; - len = strcspn( pzArg, zSpn ); + len = strcspn(pzArg, zSpn); if (len == 0) break; - if ((len == 3) && (strncmp(pzArg, zAll, (size_t)3) == 0)) { + if ((len == 3) && (strncmp(pzArg, zAll, 3) == 0)) { if (iv) res = 0; else res = ~0UL; } - else if ((len == 4) && (strncmp(pzArg, zNone, (size_t)4) == 0)) { + else if ((len == 4) && (strncmp(pzArg, zNone, 4) == 0)) { if (! iv) res = 0; } else do { char* pz; - uintptr_t bit = strtoul( pzArg, &pz, 0 ); + uintptr_t bit = strtoul(pzArg, &pz, 0); if (pz != pzArg + len) { char z[ AO_NAME_SIZE ]; - tCC* p; + char const* p; + int shift_ct; + if (*pz != NUL) { if (len >= AO_NAME_LIMIT) break; - strncpy( z, pzArg, (size_t)len ); + memcpy(z, pzArg, (size_t)len); z[len] = NUL; p = z; } else { p = pzArg; } - bit = 1UL << findName(p, pOpts, pOD, paz_names, name_ct); + shift_ct = find_name(p, pOpts, pOD, paz_names, name_ct); + if (shift_ct >= name_ct) { + pOD->optCookie = (void*)0; + return; + } + bit = 1UL << shift_ct; } if (iv) res &= ~bit; @@ -481,7 +505,7 @@ optionSetMembers( break; pzArg += len + 1; } - if (name_ct < (8 * sizeof( uintptr_t ))) { + if (name_ct < (8 * sizeof(uintptr_t))) { res &= (1UL << name_ct) - 1UL; } diff --git a/sntp/libopts/environment.c b/sntp/libopts/environment.c index 9fb155011216..8530230ea7e6 100644 --- a/sntp/libopts/environment.c +++ b/sntp/libopts/environment.c @@ -1,61 +1,38 @@ -/* - * $Id: environment.c,v 4.13 2007/04/15 19:01:18 bkorb Exp $ - * Time-stamp: "2007-04-15 11:50:35 bkorb" +/** + * \file environment.c + * + * Time-stamp: "2011-04-06 09:35:55 bkorb" * * This file contains all of the routines that must be linked into * an executable to use the generated option processing. The optional * routines are in separately compiled modules so that they will not * necessarily be linked in. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -checkEnvOpt(tOptState * os, char * env_name, +do_env_opt(tOptState * os, char * env_name, tOptions* pOpts, teEnvPresetType type); /* = = = END-STATIC-FORWARD = = = */ @@ -66,31 +43,25 @@ checkEnvOpt(tOptState * os, char * env_name, * doImmediateOpts and/or doRegularOpts. */ LOCAL void -doPrognameEnv( tOptions* pOpts, teEnvPresetType type ) +doPrognameEnv(tOptions* pOpts, teEnvPresetType type) { - char const* pczOptStr = getenv( pOpts->pzPROGNAME ); + char const* pczOptStr = getenv(pOpts->pzPROGNAME); token_list_t* pTL; int sv_argc; tAoUI sv_flag; char** sv_argv; /* - * IF there is no such environment variable - * *or* there is, but we are doing immediate opts and there are - * no immediate opts to do (--help inside $PROGNAME is silly, - * but --no-load-defs is not, so that is marked) - * THEN bail out now. ( + * No such beast? Then bail now. */ - if ( (pczOptStr == NULL) - || ( (type == ENV_IMM) - && ((pOpts->fOptSet & OPTPROC_HAS_IMMED) == 0) ) ) + if (pczOptStr == NULL) return; /* * Tokenize the string. If there's nothing of interest, we'll bail * here immediately. */ - pTL = ao_string_tokenize( pczOptStr ); + pTL = ao_string_tokenize(pczOptStr); if (pTL == NULL) return; @@ -116,51 +87,41 @@ doPrognameEnv( tOptions* pOpts, teEnvPresetType type ) switch (type) { case ENV_IMM: - /* - * We know the OPTPROC_HAS_IMMED bit is set. - */ - (void)doImmediateOpts( pOpts ); + (void)doImmediateOpts(pOpts); break; - case ENV_NON_IMM: - (void)doRegularOpts( pOpts ); - break; + case ENV_ALL: + (void)doImmediateOpts(pOpts); + pOpts->curOptIdx = 1; + pOpts->pzCurOpt = NULL; + /* FALLTHROUGH */ - default: - /* - * Only to immediate opts if the OPTPROC_HAS_IMMED bit is set. - */ - if (pOpts->fOptSet & OPTPROC_HAS_IMMED) { - (void)doImmediateOpts( pOpts ); - pOpts->curOptIdx = 1; - pOpts->pzCurOpt = NULL; - } - (void)doRegularOpts( pOpts ); - break; + case ENV_NON_IMM: + (void)doRegularOpts(pOpts); } /* * Free up the temporary arg vector and restore the original program args. */ - free( pTL ); + free(pTL); pOpts->origArgVect = sv_argv; pOpts->origArgCt = sv_argc; pOpts->fOptSet = sv_flag; } static void -checkEnvOpt(tOptState * os, char * env_name, +do_env_opt(tOptState * os, char * env_name, tOptions* pOpts, teEnvPresetType type) { - os->pzOptArg = getenv( env_name ); + os->pzOptArg = getenv(env_name); if (os->pzOptArg == NULL) return; - os->flags = OPTST_PRESET | OPTST_ALLOC_ARG | os->pOD->fOptState; - os->optType = TOPT_UNDEFINED; + os->flags = OPTST_PRESET | OPTST_ALLOC_ARG | os->pOD->fOptState; + os->optType = TOPT_UNDEFINED; if ( (os->pOD->pz_DisablePfx != NULL) - && (streqvcmp( os->pzOptArg, os->pOD->pz_DisablePfx ) == 0)) { + && (streqvcmp(os->pzOptArg, os->pOD->pz_DisablePfx) == 0)) { os->flags |= OPTST_DISABLED; os->pzOptArg = NULL; } @@ -192,21 +153,27 @@ checkEnvOpt(tOptState * os, char * env_name, * The interpretation of the option value depends * on the type of value argument the option takes */ - if (os->pzOptArg != NULL) { - if (OPTST_GET_ARGTYPE(os->pOD->fOptState) == OPARG_TYPE_NONE) { - os->pzOptArg = NULL; - } else if ( (os->pOD->fOptState & OPTST_ARG_OPTIONAL) - && (*os->pzOptArg == NUL)) { - os->pzOptArg = NULL; - } else if (*os->pzOptArg == NUL) { - os->pzOptArg = zNil; - } else { - AGDUPSTR( os->pzOptArg, os->pzOptArg, "option argument" ); - os->flags |= OPTST_ALLOC_ARG; - } + if (OPTST_GET_ARGTYPE(os->pOD->fOptState) == OPARG_TYPE_NONE) { + /* + * Ignore any value. + */ + os->pzOptArg = NULL; + + } else if (os->pzOptArg[0] == NUL) { + /* + * If the argument is the empty string and the argument is + * optional, then treat it as if the option was not specified. + */ + if ((os->pOD->fOptState & OPTST_ARG_OPTIONAL) == 0) + return; + os->pzOptArg = NULL; + + } else { + AGDUPSTR(os->pzOptArg, os->pzOptArg, "option argument"); + os->flags |= OPTST_ALLOC_ARG; } - handleOption( pOpts, os ); + handle_opt(pOpts, os); } /* @@ -214,7 +181,7 @@ checkEnvOpt(tOptState * os, char * env_name, * This routine should process in all, immediate or normal modes.... */ LOCAL void -doEnvPresets( tOptions* pOpts, teEnvPresetType type ) +doEnvPresets(tOptions* pOpts, teEnvPresetType type) { int ct; tOptState st; @@ -229,16 +196,18 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type ) if ((pOpts->fOptSet & OPTPROC_ENVIRON) == 0) return; - doPrognameEnv( pOpts, type ); + doPrognameEnv(pOpts, type); ct = pOpts->presetOptCt; st.pOD = pOpts->pOptDesc; pzFlagName = zEnvName - + snprintf( zEnvName, sizeof( zEnvName ), "%s_", pOpts->pzPROGNAME ); + + snprintf(zEnvName, sizeof(zEnvName), "%s_", pOpts->pzPROGNAME); spaceLeft = AO_NAME_SIZE - (pzFlagName - zEnvName) - 1; for (;ct-- > 0; st.pOD++) { + size_t nln; + /* * If presetting is disallowed, then skip this entry */ @@ -250,23 +219,34 @@ doEnvPresets( tOptions* pOpts, teEnvPresetType type ) * IF there is no such environment variable, * THEN skip this entry, too. */ - if (strlen( st.pOD->pz_NAME ) >= spaceLeft) - continue; - - /* - * Set up the option state - */ - strcpy( pzFlagName, st.pOD->pz_NAME ); - checkEnvOpt(&st, zEnvName, pOpts, type); + nln = strlen(st.pOD->pz_NAME) + 1; + if (nln <= spaceLeft) { + /* + * Set up the option state + */ + memcpy(pzFlagName, st.pOD->pz_NAME, nln); + do_env_opt(&st, zEnvName, pOpts, type); + } } /* * Special handling for ${PROGNAME_LOAD_OPTS} */ - if (pOpts->specOptIdx.save_opts != 0) { + if ( (pOpts->specOptIdx.save_opts != NO_EQUIVALENT) + && (pOpts->specOptIdx.save_opts != 0)) { + size_t nln; st.pOD = pOpts->pOptDesc + pOpts->specOptIdx.save_opts + 1; - strcpy( pzFlagName, st.pOD->pz_NAME ); - checkEnvOpt(&st, zEnvName, pOpts, type); + + if (st.pOD->pz_NAME == NULL) + return; + + nln = strlen(st.pOD->pz_NAME) + 1; + + if (nln > spaceLeft) + return; + + memcpy(pzFlagName, st.pOD->pz_NAME, nln); + do_env_opt(&st, zEnvName, pOpts, type); } } diff --git a/sntp/libopts/file.c b/sntp/libopts/file.c new file mode 100644 index 000000000000..bb6adf63bc0f --- /dev/null +++ b/sntp/libopts/file.c @@ -0,0 +1,173 @@ + +/** + * \file file.c + * + * Time-stamp: "2010-07-10 11:00:59 bkorb" + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd + */ + +/*=export_func optionFileCheck + * private: + * + * what: Decipher a boolean value + * arg: + tOptions* + pOpts + program options descriptor + + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * arg: + teOptFileType + ftype + File handling type + + * arg: + tuFileMode + mode + file open mode (if needed) + + * + * doc: + * Make sure the named file conforms with the file type mode. + * The mode specifies if the file must exist, must not exist or may + * (or may not) exist. The mode may also specify opening the + * file: don't, open just the descriptor (fd), or open as a stream + * (FILE* pointer). +=*/ +void +optionFileCheck(tOptions* pOpts, tOptDesc* pOD, + teOptFileType ftype, tuFileMode mode) +{ + if (pOpts <= OPTPROC_EMIT_LIMIT) { + if (pOpts != OPTPROC_EMIT_USAGE) + return; + + switch (ftype & FTYPE_MODE_EXIST_MASK) { + case FTYPE_MODE_MUST_NOT_EXIST: + fputs(zFileCannotExist, option_usage_fp); + break; + + case FTYPE_MODE_MUST_EXIST: + fputs(zFileMustExist, option_usage_fp); + break; + } + return; + } + + if ((pOD->fOptState & OPTST_RESET) != 0) { + if (pOD->optCookie != NULL) + AGFREE(pOD->optCookie); + return; + } + + { + struct stat sb; + + errno = 0; + + switch (ftype & FTYPE_MODE_EXIST_MASK) { + case FTYPE_MODE_MUST_NOT_EXIST: + if ( (stat(pOD->optArg.argString, &sb) == 0) + || (errno != ENOENT) ){ + if (errno == 0) + errno = EINVAL; + fprintf(stderr, zFSOptError, errno, strerror(errno), + zFSOptErrNoExist, pOD->optArg.argString, pOD->pz_Name); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + /* FALLTHROUGH */ + + default: + case FTYPE_MODE_MAY_EXIST: + { + char * p = strrchr(pOD->optArg.argString, DIRCH); + if (p == NULL) + break; /* assume "." always exists. */ + + *p = NUL; + if ( (stat(pOD->optArg.argString, &sb) != 0) + || (errno = EINVAL, ! S_ISDIR(sb.st_mode)) ){ + fprintf(stderr, zFSOptError, errno, strerror(errno), + zFSOptErrMayExist, pOD->optArg.argString, pOD->pz_Name); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + if (p != NULL) + *p = DIRCH; + break; + } + + case FTYPE_MODE_MUST_EXIST: + if ( (stat(pOD->optArg.argString, &sb) != 0) + || (errno = EINVAL, ! S_ISREG(sb.st_mode)) ){ + fprintf(stderr, zFSOptError, errno, strerror(errno), + zFSOptErrMustExist, pOD->optArg.argString, + pOD->pz_Name); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + break; + } + } + + switch (ftype & FTYPE_MODE_OPEN_MASK) { + default: + case FTYPE_MODE_NO_OPEN: + break; + + case FTYPE_MODE_OPEN_FD: + { + int fd = open(pOD->optArg.argString, mode.file_flags); + if (fd < 0) { + fprintf(stderr, zFSOptError, errno, strerror(errno), + zFSOptErrOpen, pOD->optArg.argString, pOD->pz_Name); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + + if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0) + pOD->optCookie = (void *)pOD->optArg.argString; + else + AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name"); + + pOD->optArg.argFd = fd; + pOD->fOptState &= ~OPTST_ALLOC_ARG; + break; + } + + case FTYPE_MODE_FOPEN_FP: + { + FILE* fp = fopen(pOD->optArg.argString, mode.file_mode); + if (fp == NULL) { + fprintf(stderr, zFSOptError, errno, strerror(errno), + zFSOptErrFopen, pOD->optArg.argString, pOD->pz_Name); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + } + + if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0) + pOD->optCookie = (void *)pOD->optArg.argString; + else + AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name"); + + pOD->optArg.argFp = fp; + pOD->fOptState &= ~OPTST_ALLOC_ARG; + break; + } + } +} +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of autoopts/file.c */ diff --git a/sntp/libopts/genshell.c b/sntp/libopts/genshell.c index de098a565ac5..05f2f1da46bb 100644 --- a/sntp/libopts/genshell.c +++ b/sntp/libopts/genshell.c @@ -2,45 +2,44 @@ * * DO NOT EDIT THIS FILE (genshell.c) * - * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:35 PM PDT + * It has been AutoGen-ed April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts 29:0:4 templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This source file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * genshellopt author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 35:0:10 templates. + * + * AutoOpts is a copyrighted work. This source file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the genshellopt author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * * This source file is copyrighted and licensed under the following terms: * - * genshellopt copyright 1999-2007 Bruce Korb - all rights reserved + * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved * - * genshellopt is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * genshellopt 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 3 of the License, or + * (at your option) any later version. * - * genshellopt 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. + * genshellopt 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 Lesser General Public - * License along with genshellopt. If not, write to: - * The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include <sys/types.h> #include <limits.h> +#include <stdio.h> +#include <stdlib.h> #define OPTION_CODE_COMPILE 1 #include "genshell.h" @@ -48,51 +47,53 @@ #ifdef __cplusplus extern "C" { #endif -tSCC zCopyright[] = - "genshellopt copyright (c) 1999-2007 Bruce Korb, all rights reserved"; -tSCC zCopyrightNotice[] = - "genshellopt is free software; you can redistribute it and/or\n\ -modify it under the terms of the GNU Lesser General Public\n\ -License as published by the Free Software Foundation; either\n\ -version 2.1 of the License, or (at your option) any later version.\n\n\ -genshellopt is distributed in the hope that it will be useful,\n\ -but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\ -Lesser General Public License for more details.\n\n\ -You should have received a copy of the GNU Lesser General Public\n\ -License along with genshellopt. If not, write to:\n\ -\tThe Free Software Foundation, Inc.,\n\ -\t51 Franklin Street, Fifth Floor\n\ -\tBoston, MA 02110-1301, USA."; +extern FILE * option_usage_fp; + +/* TRANSLATORS: choose the translation for option names wisely because you + cannot ever change your mind. */ +static char const zCopyright[260] = +"genshellopt 1\n\ +Copyright (C) 1999-2011 Bruce Korb, all rights reserved.\n\ +This is free software. It is licensed for use, modification and\n\ +redistribution under the terms of the\n\ +GNU General Public License, version 3 or later\n\ + <http://gnu.org/licenses/gpl.html>\n"; +static char const zCopyrightNotice[611] = +"genshellopt is free software: you can redistribute it and/or modify it\n\ +under the terms of the GNU General Public License as published by the\n\ +Free Software Foundation, either version 3 of the License, or (at your\n\ +option) any later version.\n\n\ +genshellopt is distributed in the hope that it will be useful, but WITHOUT\n\ +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n\ +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n\ +for more details.\n\n\ +You should have received a copy of the GNU General Public License along\n\ +with this program. If not, see <http://www.gnu.org/licenses/>.\n"; + extern tUsageProc genshelloptUsage; #ifndef NULL # define NULL 0 #endif -#ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -#endif -#ifndef EXIT_FAILURE -# define EXIT_FAILURE 1 -#endif + /* * Script option description: */ -tSCC zScriptText[] = +static char const zScriptText[] = "Output Script File"; -tSCC zScript_NAME[] = "SCRIPT"; -tSCC zScript_Name[] = "script"; +static char const zScript_NAME[] = "SCRIPT"; +static char const zScript_Name[] = "script"; #define SCRIPT_FLAGS (OPTST_DISABLED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) /* * Shell option description: */ -tSCC zShellText[] = +static char const zShellText[] = "Shell name (follows \"#!\" magic)"; -tSCC zShell_NAME[] = "SHELL"; -tSCC zNotShell_Name[] = "no-shell"; -tSCC zNotShell_Pfx[] = "no"; +static char const zShell_NAME[] = "SHELL"; +static char const zNotShell_Name[] = "no-shell"; +static char const zNotShell_Pfx[] = "no"; #define zShell_Name (zNotShell_Name + 3) #define SHELL_FLAGS (OPTST_INITENABLED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) @@ -100,19 +101,34 @@ tSCC zNotShell_Pfx[] = "no"; /* * Help/More_Help/Version option descriptions: */ -tSCC zHelpText[] = "Display usage information and exit"; -tSCC zHelp_Name[] = "help"; - -tSCC zMore_HelpText[] = "Extended usage information passed thru pager"; -tSCC zMore_Help_Name[] = "more-help"; +static char const zHelpText[] = "Display extended usage information and exit"; +static char const zHelp_Name[] = "help"; +#ifdef HAVE_WORKING_FORK +#define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) +static char const zMore_Help_Name[] = "more-help"; +static char const zMore_HelpText[] = "Extended usage information passed thru pager"; +#else +#define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) +#define zMore_Help_Name NULL +#define zMore_HelpText NULL +#endif +#ifdef NO_OPTIONAL_OPT_ARGS +# define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT +#else +# define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ + OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT +#endif -tSCC zVersionText[] = "Output version information and exit"; -tSCC zVersion_Name[] = "version"; +static char const zVersionText[] = "Output version information and exit"; +static char const zVersion_Name[] = "version"; /* * Declare option callback procedures */ extern tOptProc - optionPagedUsage, optionPrintVersion; + optionBooleanVal, optionNestedVal, optionNumericVal, + optionPagedUsage, optionPrintVersion, optionResetOpt, + optionStackArg, optionTimeDate, optionTimeVal, + optionUnstackArg, optionVersionStderr; static tOptProc doUsageOpt; @@ -120,9 +136,9 @@ static tOptProc * * Define the Genshellopt Option Descriptions. */ -static tOptDesc optDesc[ OPTION_CT ] = { - { /* entry idx, value */ 0, VALUE_OPT_SCRIPT, - /* equiv idx, value */ 0, VALUE_OPT_SCRIPT, +static tOptDesc optDesc[GENSHELL_OPTION_CT] = { + { /* entry idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT, + /* equiv idx, value */ 0, VALUE_GENSHELL_OPT_SCRIPT, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, /* opt state flags */ SCRIPT_FLAGS, 0, @@ -133,8 +149,8 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zScriptText, zScript_NAME, zScript_Name, /* disablement strs */ NULL, NULL }, - { /* entry idx, value */ 1, VALUE_OPT_SHELL, - /* equiv idx, value */ 1, VALUE_OPT_SHELL, + { /* entry idx, value */ 1, VALUE_GENSHELL_OPT_SHELL, + /* equiv idx, value */ 1, VALUE_GENSHELL_OPT_SHELL, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, /* opt state flags */ SHELL_FLAGS, 0, @@ -145,18 +161,11 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zShellText, zShell_NAME, zShell_Name, /* disablement strs */ zNotShell_Name, zNotShell_Pfx }, -#ifdef NO_OPTIONAL_OPT_ARGS -# define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT -#else -# define VERSION_OPT_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ - OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT -#endif - - { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION, + { /* entry idx, value */ INDEX_GENSHELL_OPT_VERSION, VALUE_GENSHELL_OPT_VERSION, /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, - /* opt state flags */ VERSION_OPT_FLAGS, 0, + /* opt state flags */ OPTST_VERSION_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, /* must/cannot opts */ NULL, NULL, @@ -164,10 +173,9 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zVersionText, NULL, zVersion_Name, /* disablement strs */ NULL, NULL }, -#undef VERSION_OPT_FLAGS - { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, + { /* entry idx, value */ INDEX_GENSHELL_OPT_HELP, VALUE_GENSHELL_OPT_HELP, /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, @@ -179,11 +187,11 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zHelpText, NULL, zHelp_Name, /* disablement strs */ NULL, NULL }, - { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP, + { /* entry idx, value */ INDEX_GENSHELL_OPT_MORE_HELP, VALUE_GENSHELL_OPT_MORE_HELP, /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, - /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0, + /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, /* must/cannot opts */ NULL, NULL, @@ -196,24 +204,24 @@ static tOptDesc optDesc[ OPTION_CT ] = { * * Define the Genshellopt Option Environment */ -tSCC zPROGNAME[] = "GENSHELLOPT"; -tSCC zUsageTitle[] = +static char const zPROGNAME[12] = "GENSHELLOPT"; +static char const zUsageTitle[121] = "genshellopt - Generate Shell Option Processing Script - Ver. 1\n\ USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n"; #define zRcName NULL #define apzHomeList NULL -tSCC zBugsAddr[] = "autogen-users@lists.sourceforge.net"; -tSCC zExplain[] = "\n\ -Note that `shell' is only useful if the output file does not already\n\ -exist. If it does, then the shell name and optional first argument\n\ -will be extracted from the script file.\n"; -tSCC zDetail[] = "\n\ +static char const zBugsAddr[36] = "autogen-users@lists.sourceforge.net"; +static char const zExplain[] = "\n\ +Note that ``shell'' is only useful if the output file does not already\n\ +exist. If it does, then the shell name and optional first argument will\n\ +be extracted from the script file.\n"; +static char const zDetail[237] = "\n\ If the script file already exists and contains Automated Option Processing\n\ text, the second line of the file through the ending tag will be replaced\n\ -by the newly generated text. The first `#!' line will be regenerated.\n"; -tSCC zFullVersion[] = GENSHELLOPT_FULL_VERSION; -/* extracted from optcode.tpl near line 408 */ +by the newly generated text. The first ``#!'' line will be regenerated.\n"; +static char const zFullVersion[] = GENSHELLOPT_FULL_VERSION; +/* extracted from optcode.tlib near line 515 */ #if defined(ENABLE_NLS) # define OPTPROC_BASE OPTPROC_TRANSLATE @@ -223,6 +231,29 @@ tSCC zFullVersion[] = GENSHELLOPT_FULL_VERSION; # define translate_option_strings NULL #endif /* ENABLE_NLS */ + +#define genshellopt_full_usage NULL +#define genshellopt_short_usage NULL +#ifndef PKGDATADIR +# define PKGDATADIR "" +#endif + +#ifndef WITH_PACKAGER +# define genshellopt_packager_info NULL +#else +static char const genshellopt_packager_info[] = + "Packaged by " WITH_PACKAGER + +# ifdef WITH_PACKAGER_VERSION + " ("WITH_PACKAGER_VERSION")" +# endif + +# ifdef WITH_PACKAGER_BUG_REPORTS + "\nReport genshellopt bugs to " WITH_PACKAGER_BUG_REPORTS +# endif + "\n"; +#endif + tOptions genshelloptOptions = { OPTIONS_STRUCT_VERSION, 0, NULL, /* original argc + argv */ @@ -240,30 +271,32 @@ tOptions genshelloptOptions = { zExplain, zDetail, optDesc, zBugsAddr, /* address to send bugs to */ NULL, NULL, /* extensions/saved state */ - genshelloptUsage, /* usage procedure */ + genshelloptUsage, /* usage procedure */ translate_option_strings, /* translation procedure */ /* * Indexes to special options */ - { INDEX_OPT_MORE_HELP, - 0 /* no option state saving */, - NO_EQUIVALENT /* index of '-#' option */, + { INDEX_GENSHELL_OPT_MORE_HELP, /* more-help option index */ + NO_EQUIVALENT, /* save option index */ + NO_EQUIVALENT, /* '-#' option index */ NO_EQUIVALENT /* index of default opt */ }, - 5 /* full option count */, 2 /* user option count */ + 5 /* full option count */, 2 /* user option count */, + genshellopt_full_usage, genshellopt_short_usage, + NULL, NULL, + PKGDATADIR, genshellopt_packager_info }; /* * Create the static procedure(s) declared above. */ static void -doUsageOpt( - tOptions* pOptions, - tOptDesc* pOptDesc ) +doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) { - USAGE( EXIT_SUCCESS ); + (void)pOptions; + GENSHELL_USAGE(GENSHELLOPT_EXIT_SUCCESS); } -/* extracted from optcode.tpl near line 514 */ +/* extracted from optcode.tlib near line 666 */ #if ENABLE_NLS #include <stdio.h> @@ -272,11 +305,11 @@ doUsageOpt( #include <unistd.h> #include <autoopts/usage-txt.h> -static char* AO_gettext( char const* pz ); +static char* AO_gettext(char const* pz); static void coerce_it(void** s); static char* -AO_gettext( char const* pz ) +AO_gettext(char const* pz) { char* pzRes; if (pz == NULL) @@ -284,66 +317,68 @@ AO_gettext( char const* pz ) pzRes = _(pz); if (pzRes == pz) return pzRes; - pzRes = strdup( pzRes ); + pzRes = strdup(pzRes); if (pzRes == NULL) { - fputs( _("No memory for duping translated strings\n"), stderr ); - exit( EXIT_FAILURE ); + fputs(_("No memory for duping translated strings\n"), stderr); + exit(GENSHELLOPT_EXIT_FAILURE); } return pzRes; } -static void coerce_it(void** s) { *s = AO_gettext(*s); } -#define COERSION(_f) \ - coerce_it((void*)&(genshelloptOptions._f)) +static void coerce_it(void** s) { *s = AO_gettext(*s); +} /* * This invokes the translation code (e.g. gettext(3)). */ static void -translate_option_strings( void ) +translate_option_strings(void) { + tOptions * const pOpt = &genshelloptOptions; + /* * Guard against re-translation. It won't work. The strings will have * been changed by the first pass through this code. One shot only. */ - if (option_usage_text.field_ct == 0) - return; - /* - * Do the translations. The first pointer follows the field count field. - * The field count field is the size of a pointer. - */ - { - char** ppz = (char**)(void*)&(option_usage_text); - int ix = option_usage_text.field_ct; + if (option_usage_text.field_ct != 0) { + /* + * Do the translations. The first pointer follows the field count + * field. The field count field is the size of a pointer. + */ + tOptDesc * pOD = pOpt->pOptDesc; + char ** ppz = (char**)(void*)&(option_usage_text); + int ix = option_usage_text.field_ct; do { ppz++; *ppz = AO_gettext(*ppz); } while (--ix > 0); + + coerce_it((void*)&(pOpt->pzCopyright)); + coerce_it((void*)&(pOpt->pzCopyNotice)); + coerce_it((void*)&(pOpt->pzFullVersion)); + coerce_it((void*)&(pOpt->pzUsageTitle)); + coerce_it((void*)&(pOpt->pzExplain)); + coerce_it((void*)&(pOpt->pzDetail)); + coerce_it((void*)&(pOpt->pzPackager)); + option_usage_text.field_ct = 0; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) + coerce_it((void*)&(pOD->pzText)); } - option_usage_text.field_ct = 0; - - { - tOptDesc* pOD = genshelloptOptions.pOptDesc; - int ix = genshelloptOptions.optCt; - - for (;;) { - pOD->pzText = AO_gettext(pOD->pzText); - pOD->pz_NAME = AO_gettext(pOD->pz_NAME); - pOD->pz_Name = AO_gettext(pOD->pz_Name); - pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName); - pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx); - if (--ix <= 0) - break; - pOD++; + + if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) { + tOptDesc * pOD = pOpt->pOptDesc; + int ix; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) { + coerce_it((void*)&(pOD->pz_Name)); + coerce_it((void*)&(pOD->pz_DisableName)); + coerce_it((void*)&(pOD->pz_DisablePfx)); } + /* prevent re-translation */ + genshelloptOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT; } - COERSION(pzCopyright); - COERSION(pzCopyNotice); - COERSION(pzFullVersion); - COERSION(pzUsageTitle); - COERSION(pzExplain); - COERSION(pzDetail); } #endif /* ENABLE_NLS */ diff --git a/sntp/libopts/genshell.h b/sntp/libopts/genshell.h index b57677dce59f..e5457a764090 100644 --- a/sntp/libopts/genshell.h +++ b/sntp/libopts/genshell.h @@ -2,41 +2,37 @@ * * DO NOT EDIT THIS FILE (genshell.h) * - * It has been AutoGen-ed Saturday May 5, 2007 at 12:02:35 PM PDT + * It has been AutoGen-ed April 29, 2011 at 03:43:59 PM by AutoGen 5.11.9 * From the definitions genshell.def * and the template file options * - * Generated from AutoOpts 29:0:4 templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This header file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * genshellopt author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 35:0:10 templates. + * + * AutoOpts is a copyrighted work. This header file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the genshellopt author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * * This source file is copyrighted and licensed under the following terms: * - * genshellopt copyright 1999-2007 Bruce Korb - all rights reserved + * genshellopt copyright (c) 1999-2011 Bruce Korb - all rights reserved * - * genshellopt is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * genshellopt 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 3 of the License, or + * (at your option) any later version. * - * genshellopt 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. + * genshellopt 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 Lesser General Public - * License along with genshellopt. If not, write to: - * The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ /* * This file contains the programmatic interface to the Automated @@ -45,7 +41,7 @@ * "AutoOpts" chapter. Please refer to that doc for usage help. */ #ifndef AUTOOPTS_GENSHELL_H_GUARD -#define AUTOOPTS_GENSHELL_H_GUARD +#define AUTOOPTS_GENSHELL_H_GUARD 1 #include <autoopts/options.h> /* @@ -55,7 +51,7 @@ * tolerable version is at least as old as what was current when the header * template was released. */ -#define AO_TEMPLATE_VERSION 118784 +#define AO_TEMPLATE_VERSION 143360 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) # error option template version mismatches autoopts/options.h header @@ -66,81 +62,108 @@ * Enumeration of each option: */ typedef enum { - INDEX_OPT_SCRIPT = 0, - INDEX_OPT_SHELL = 1, - INDEX_OPT_VERSION = 2, - INDEX_OPT_HELP = 3, - INDEX_OPT_MORE_HELP = 4 -} teOptIndex; + INDEX_GENSHELL_OPT_SCRIPT = 0, + INDEX_GENSHELL_OPT_SHELL = 1, + INDEX_GENSHELL_OPT_VERSION = 2, + INDEX_GENSHELL_OPT_HELP = 3, + INDEX_GENSHELL_OPT_MORE_HELP = 4 +} teGenshell_OptIndex; -#define OPTION_CT 5 +#define GENSHELL_OPTION_CT 5 #define GENSHELLOPT_VERSION "1" -#define GENSHELLOPT_FULL_VERSION "genshellopt - Generate Shell Option Processing Script - Ver. 1" +#define GENSHELLOPT_FULL_VERSION "genshellopt 1" /* * Interface defines for all options. Replace "n" with the UPPER_CASED - * option name (as in the teOptIndex enumeration above). - * e.g. HAVE_OPT( SCRIPT ) + * option name (as in the teGenshell_OptIndex enumeration above). + * e.g. HAVE_GENSHELL_OPT(SCRIPT) */ -#define DESC(n) (genshelloptOptions.pOptDesc[INDEX_OPT_## n]) -#define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n))) -#define OPT_ARG(n) (DESC(n).optArg.argString) -#define STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK) -#define COUNT_OPT(n) (DESC(n).optOccCt) -#define ISSEL_OPT(n) (SELECTED_OPT(&DESC(n))) -#define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n))) -#define ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n))) -#define STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt) -#define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs) -#define CLEAR_OPT(n) STMTS( \ - DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \ - if ( (DESC(n).fOptState & OPTST_INITENABLED) == 0) \ - DESC(n).fOptState |= OPTST_DISABLED; \ - DESC(n).optCookie = NULL ) +#define GENSHELL_DESC(n) (genshelloptOptions.pOptDesc[INDEX_GENSHELL_OPT_## n]) +#define HAVE_GENSHELL_OPT(n) (! UNUSED_OPT(& GENSHELL_DESC(n))) +#define GENSHELL_OPT_ARG(n) (GENSHELL_DESC(n).optArg.argString) +#define STATE_GENSHELL_OPT(n) (GENSHELL_DESC(n).fOptState & OPTST_SET_MASK) +#define COUNT_GENSHELL_OPT(n) (GENSHELL_DESC(n).optOccCt) +#define ISSEL_GENSHELL_OPT(n) (SELECTED_OPT(&GENSHELL_DESC(n))) +#define ISUNUSED_GENSHELL_OPT(n) (UNUSED_OPT(& GENSHELL_DESC(n))) +#define ENABLED_GENSHELL_OPT(n) (! DISABLED_OPT(& GENSHELL_DESC(n))) +#define STACKCT_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->useCt) +#define STACKLST_GENSHELL_OPT(n) (((tArgList*)(GENSHELL_DESC(n).optCookie))->apzArgs) +#define CLEAR_GENSHELL_OPT(n) STMTS( \ + GENSHELL_DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \ + if ((GENSHELL_DESC(n).fOptState & OPTST_INITENABLED) == 0) \ + GENSHELL_DESC(n).fOptState |= OPTST_DISABLED; \ + GENSHELL_DESC(n).optCookie = NULL ) -/* +/* * * * * * + * + * Enumeration of genshellopt exit codes + */ +typedef enum { + GENSHELLOPT_EXIT_SUCCESS = 0, + GENSHELLOPT_EXIT_FAILURE = 1 +} genshellopt_exit_code_t; +/* * * * * * + * * Interface defines for specific options. */ -#define VALUE_OPT_SCRIPT 'o' -#define VALUE_OPT_SHELL 's' - -#define VALUE_OPT_VERSION 'v' -#define VALUE_OPT_HELP '?' -#define VALUE_OPT_MORE_HELP '!' +#define VALUE_GENSHELL_OPT_SCRIPT 'o' +#define VALUE_GENSHELL_OPT_SHELL 's' +#define VALUE_GENSHELL_OPT_HELP '?' +#define VALUE_GENSHELL_OPT_MORE_HELP '!' +#define VALUE_GENSHELL_OPT_VERSION 'v' /* * Interface defines not associated with particular options */ -#define ERRSKIP_OPTERR STMTS( genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP ) -#define ERRSTOP_OPTERR STMTS( genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP ) -#define RESTART_OPT(n) STMTS( \ +#define ERRSKIP_GENSHELL_OPTERR STMTS(genshelloptOptions.fOptSet &= ~OPTPROC_ERRSTOP) +#define ERRSTOP_GENSHELL_OPTERR STMTS(genshelloptOptions.fOptSet |= OPTPROC_ERRSTOP) +#define RESTART_GENSHELL_OPT(n) STMTS( \ genshelloptOptions.curOptIdx = (n); \ genshelloptOptions.pzCurOpt = NULL ) -#define START_OPT RESTART_OPT(1) -#define USAGE(c) (*genshelloptOptions.pUsageProc)( &genshelloptOptions, c ) -/* extracted from opthead.tpl near line 360 */ +#define START_GENSHELL_OPT RESTART_GENSHELL_OPT(1) +#define GENSHELL_USAGE(c) (*genshelloptOptions.pUsageProc)(&genshelloptOptions, c) +/* extracted from opthead.tlib near line 451 */ + +#ifdef __cplusplus +extern "C" { +#endif /* * * * * * * * Declare the genshellopt option descriptor. */ -#ifdef __cplusplus -extern "C" { -#endif +extern tOptions genshelloptOptions; -extern tOptions genshelloptOptions; +#if defined(ENABLE_NLS) +# ifndef _ +# include <stdio.h> + static inline char* aoGetsText(char const* pz) { + if (pz == NULL) return NULL; + return (char*)gettext(pz); + } +# define _(s) aoGetsText(s) +# endif /* _() */ -#ifndef _ -# if ENABLE_NLS -# include <stdio.h> - static inline char* aoGetsText( char const* pz ) { - if (pz == NULL) return NULL; - return (char*)gettext( pz ); - } -# define _(s) aoGetsText(s) -# else /* ENABLE_NLS */ -# define _(s) s -# endif /* ENABLE_NLS */ -#endif +# define OPT_NO_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT_CFG;) +# define OPT_NO_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;) + +# define OPT_XLAT_CFG_NAMES STMTS(genshelloptOptions.fOptSet &= \ + ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);) +# define OPT_XLAT_OPT_NAMES STMTS(genshelloptOptions.fOptSet &= \ + ~OPTPROC_NXLAT_OPT;) + +#else /* ENABLE_NLS */ +# define OPT_NO_XLAT_CFG_NAMES +# define OPT_NO_XLAT_OPT_NAMES + +# define OPT_XLAT_CFG_NAMES +# define OPT_XLAT_OPT_NAMES + +# ifndef _ +# define _(_s) _s +# endif +#endif /* ENABLE_NLS */ #ifdef __cplusplus } diff --git a/sntp/libopts/libopts.c b/sntp/libopts/libopts.c index feb7557dc711..15a070d928c5 100644 --- a/sntp/libopts/libopts.c +++ b/sntp/libopts/libopts.c @@ -1,17 +1,26 @@ -#define AUTOOPTS_INTERNAL +#include "autoopts/project.h" +#define AUTOOPTS_INTERNAL 1 #include "compat/compat.h" -#define LOCAL static +#define LOCAL static #include "autoopts/options.h" #include "autoopts/usage-txt.h" #include "genshell.h" +#include "xat-attribute.h" +#include "value-type.h" +#include "ag-char-map.h" #include "autoopts.h" #include "proto.h" +#include "parse-duration.h" +#include "parse-duration.c" +#include "value-type.c" +#include "xat-attribute.c" #include "autoopts.c" #include "boolean.c" #include "configfile.c" #include "cook.c" #include "enumeration.c" #include "environment.c" +#include "file.c" #include "genshell.c" #include "load.c" #include "makeshell.c" @@ -19,6 +28,7 @@ #include "numeric.c" #include "pgusage.c" #include "putshell.c" +#include "reset.c" #include "restore.c" #include "save.c" #include "sort.c" @@ -26,5 +36,6 @@ #include "streqvcmp.c" #include "text_mmap.c" #include "tokenize.c" +#include "time.c" #include "usage.c" #include "version.c" diff --git a/sntp/libopts/load.c b/sntp/libopts/load.c index eeeb125cc51e..024dce9301a8 100644 --- a/sntp/libopts/load.c +++ b/sntp/libopts/load.c @@ -1,76 +1,44 @@ -/* - * $Id: load.c,v 4.20 2007/02/04 22:17:39 bkorb Exp $ - * Time-stamp: "2007-02-04 11:54:57 bkorb" +/** + * \file load.c + * Time-stamp: "2010-12-18 11:46:07 bkorb" * * This file contains the routines that deal with processing text strings * for options, either from a NUL-terminated string passed in or from an * rc/ini file. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -tOptionLoadMode option_load_mode = OPTION_LOAD_UNCOOKED; - /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static ag_bool -insertProgramPath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ); +insertProgramPath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath); static ag_bool -insertEnvVal( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ); +insertEnvVal(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath); static char* -assembleArgValue( char* pzTxt, tOptionLoadMode mode ); +assembleArgValue(char* pzTxt, tOptionLoadMode mode); /* = = = END-STATIC-FORWARD = = = */ /*=export_func optionMakePath @@ -86,13 +54,13 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode ); * ret-desc: AG_TRUE if the name was handled, otherwise AG_FALSE. * If the name does not start with ``$'', then it is handled * simply by copying the input name to the output buffer and - * resolving the name with either @code{canonicalize_file_name(3GLIBC)} - * or @code{realpath(3C)}. + * resolving the name with either + * @code{canonicalize_file_name(3GLIBC)} or @code{realpath(3C)}. * * doc: * - * This routine will copy the @code{pzName} input name into the @code{pzBuf} - * output buffer, carefully not exceeding @code{bufSize} bytes. If the + * This routine will copy the @code{pzName} input name into the + * @code{pzBuf} output buffer, not exceeding @code{bufSize} bytes. If the * first character of the input name is a @code{'$'} character, then there * is special handling: * @* @@ -125,30 +93,19 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode ); * errors (cannot resolve the resulting path). =*/ ag_bool -optionMakePath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +optionMakePath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { - size_t name_len = strlen( pzName ); - -# ifndef PKGDATADIR -# define PKGDATADIR "" -# endif - - tSCC pkgdatadir[] = PKGDATADIR; + size_t name_len = strlen(pzName); - ag_bool res = AG_TRUE; - - if (bufSize <= name_len) + if ((bufSize <= name_len) || (name_len == 0)) return AG_FALSE; /* * IF not an environment variable, just copy the data */ if (*pzName != '$') { - tCC* pzS = pzName; + char const* pzS = pzName; char* pzD = pzBuf; int ct = bufSize; @@ -170,46 +127,52 @@ optionMakePath( return AG_FALSE; case '$': - res = insertProgramPath( pzBuf, bufSize, pzName, pzProgPath ); + if (! insertProgramPath(pzBuf, bufSize, pzName, pzProgPath)) + return AG_FALSE; break; case '@': - if (pkgdatadir[0] == NUL) + if (program_pkgdatadir[0] == NUL) return AG_FALSE; - if (name_len + sizeof (pkgdatadir) > bufSize) + if (snprintf(pzBuf, bufSize, "%s%s", program_pkgdatadir, pzName + 2) + >= bufSize) return AG_FALSE; - - strcpy(pzBuf, pkgdatadir); - strcpy(pzBuf + sizeof(pkgdatadir) - 1, pzName + 2); break; default: - res = insertEnvVal( pzBuf, bufSize, pzName, pzProgPath ); + if (! insertEnvVal(pzBuf, bufSize, pzName, pzProgPath)) + return AG_FALSE; } - if (! res) - return AG_FALSE; - #if defined(HAVE_CANONICALIZE_FILE_NAME) { - char* pz = canonicalize_file_name(pzBuf); + char * pz = canonicalize_file_name(pzBuf); if (pz == NULL) return AG_FALSE; - if (strlen(pz) < bufSize) - strcpy(pzBuf, pz); + + name_len = strlen(pz); + if (name_len >= bufSize) { + free(pz); + return AG_FALSE; + } + + memcpy(pzBuf, pz, name_len + 1); free(pz); } #elif defined(HAVE_REALPATH) { - char z[ PATH_MAX+1 ]; + char z[PATH_MAX+1]; + + if (realpath(pzBuf, z) == NULL) + return AG_FALSE; - if (realpath( pzBuf, z ) == NULL) + name_len = strlen(z); + if (name_len >= bufSize) return AG_FALSE; - if (strlen(z) < bufSize) - strcpy( pzBuf, z ); + memcpy(pzBuf, z, name_len + 1); } #endif @@ -218,14 +181,11 @@ optionMakePath( static ag_bool -insertProgramPath( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +insertProgramPath(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { - tCC* pzPath; - tCC* pz; + char const* pzPath; + char const* pz; int skip = 2; switch (pzName[2]) { @@ -242,16 +202,16 @@ insertProgramPath( * If it is, we're done. Otherwise, we have to hunt * for the program using "pathfind". */ - if (strchr( pzProgPath, DIRCH ) != NULL) + if (strchr(pzProgPath, DIRCH) != NULL) pzPath = pzProgPath; else { - pzPath = pathfind( getenv( "PATH" ), (char*)pzProgPath, "rx" ); + pzPath = pathfind(getenv("PATH"), (char*)pzProgPath, "rx"); if (pzPath == NULL) return AG_FALSE; } - pz = strrchr( pzPath, DIRCH ); + pz = strrchr(pzPath, DIRCH); /* * IF we cannot find a directory name separator, @@ -269,31 +229,28 @@ insertProgramPath( if ((pz - pzPath)+1 + strlen(pzName) >= bufSize) return AG_FALSE; - memcpy( pzBuf, pzPath, (size_t)((pz - pzPath)+1) ); - strcpy( pzBuf + (pz - pzPath) + 1, pzName ); + memcpy(pzBuf, pzPath, (size_t)((pz - pzPath)+1)); + strcpy(pzBuf + (pz - pzPath) + 1, pzName); /* * If the "pzPath" path was gotten from "pathfind()", then it was * allocated and we need to deallocate it. */ if (pzPath != pzProgPath) - free( (void*)pzPath ); + AGFREE(pzPath); return AG_TRUE; } static ag_bool -insertEnvVal( - char* pzBuf, - int bufSize, - tCC* pzName, - tCC* pzProgPath ) +insertEnvVal(char * pzBuf, int bufSize, char const * pzName, + char const * pzProgPath) { char* pzDir = pzBuf; for (;;) { int ch = (int)*++pzName; - if (! ISNAMECHAR( ch )) + if (! IS_VALUE_NAME_CHAR(ch)) break; *(pzDir++) = (char)ch; } @@ -303,7 +260,7 @@ insertEnvVal( *pzDir = NUL; - pzDir = getenv( pzBuf ); + pzDir = getenv(pzBuf); /* * Environment value not found -- skip the home list entry @@ -311,32 +268,32 @@ insertEnvVal( if (pzDir == NULL) return AG_FALSE; - if (strlen( pzDir ) + 1 + strlen( pzName ) >= bufSize) + if (strlen(pzDir) + 1 + strlen(pzName) >= bufSize) return AG_FALSE; - sprintf( pzBuf, "%s%s", pzDir, pzName ); + sprintf(pzBuf, "%s%s", pzDir, pzName); return AG_TRUE; } LOCAL void -mungeString( char* pzTxt, tOptionLoadMode mode ) +mungeString(char* pzTxt, tOptionLoadMode mode) { char* pzE; if (mode == OPTION_LOAD_KEEP) return; - if (isspace( (int)*pzTxt )) { + if (IS_WHITESPACE_CHAR(*pzTxt)) { char* pzS = pzTxt; char* pzD = pzTxt; - while (isspace( (int)*++pzS )) ; + while (IS_WHITESPACE_CHAR(*++pzS)) ; while ((*(pzD++) = *(pzS++)) != NUL) ; pzE = pzD-1; } else - pzE = pzTxt + strlen( pzTxt ); + pzE = pzTxt + strlen(pzTxt); - while ((pzE > pzTxt) && isspace( (int)pzE[-1] )) pzE--; + while ((pzE > pzTxt) && IS_WHITESPACE_CHAR(pzE[-1])) pzE--; *pzE = NUL; if (mode == OPTION_LOAD_UNCOOKED) @@ -354,15 +311,15 @@ mungeString( char* pzTxt, tOptionLoadMode mode ) case '\'': break; } - (void)ao_string_cook( pzTxt, NULL ); + (void)ao_string_cook(pzTxt, NULL); } static char* -assembleArgValue( char* pzTxt, tOptionLoadMode mode ) +assembleArgValue(char* pzTxt, tOptionLoadMode mode) { - tSCC zBrk[] = " \t:="; - char* pzEnd = strpbrk( pzTxt, zBrk ); + static char const zBrk[] = " \t\n:="; + char* pzEnd = strpbrk(pzTxt, zBrk); int space_break; /* @@ -386,11 +343,11 @@ assembleArgValue( char* pzTxt, tOptionLoadMode mode ) * because we'll have to skip over an immediately following ':' or '=' * (and the white space following *that*). */ - space_break = isspace((int)*pzEnd); + space_break = IS_WHITESPACE_CHAR(*pzEnd); *(pzEnd++) = NUL; - while (isspace((int)*pzEnd)) pzEnd++; + while (IS_WHITESPACE_CHAR(*pzEnd)) pzEnd++; if (space_break && ((*pzEnd == ':') || (*pzEnd == '='))) - while (isspace((int)*++pzEnd)) ; + while (IS_WHITESPACE_CHAR(*++pzEnd)) ; return pzEnd; } @@ -410,12 +367,12 @@ loadOptionLine( tDirection direction, tOptionLoadMode load_mode ) { - while (isspace( (int)*pzLine )) pzLine++; + while (IS_WHITESPACE_CHAR(*pzLine)) pzLine++; { - char* pzArg = assembleArgValue( pzLine, load_mode ); + char* pzArg = assembleArgValue(pzLine, load_mode); - if (! SUCCESSFUL( longOptionFind( pOpts, pzLine, pOS ))) + if (! SUCCESSFUL(longOptionFind(pOpts, pzLine, pOS))) return; if (pOS->flags & OPTST_NO_INIT) return; @@ -496,7 +453,7 @@ loadOptionLine( if (*pOS->pzOptArg == NUL) pOS->pzOptArg = NULL; else { - AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" ); + AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument"); pOS->flags |= OPTST_ALLOC_ARG; } @@ -504,7 +461,7 @@ loadOptionLine( if (*pOS->pzOptArg == NUL) pOS->pzOptArg = zNil; else { - AGDUPSTR( pOS->pzOptArg, pOS->pzOptArg, "option argument" ); + AGDUPSTR(pOS->pzOptArg, pOS->pzOptArg, "option argument"); pOS->flags |= OPTST_ALLOC_ARG; } } @@ -512,7 +469,7 @@ loadOptionLine( { tOptionLoadMode sv = option_load_mode; option_load_mode = load_mode; - handleOption( pOpts, pOS ); + handle_opt(pOpts, pOS); option_load_mode = sv; } } @@ -544,15 +501,13 @@ loadOptionLine( * will cause a warning to print, but the function should return. =*/ void -optionLoadLine( - tOptions* pOpts, - tCC* pzLine ) +optionLoadLine(tOptions * pOpts, char const * pzLine) { tOptState st = OPTSTATE_INITIALIZER(SET); char* pz; - AGDUPSTR( pz, pzLine, "user option line" ); - loadOptionLine( pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED ); - AGFREE( pz ); + AGDUPSTR(pz, pzLine, "user option line"); + loadOptionLine(pOpts, &st, pz, DIRECTION_PROCESS, OPTION_LOAD_COOKED); + AGFREE(pz); } /* * Local Variables: diff --git a/sntp/libopts/m4/libopts.m4 b/sntp/libopts/m4/libopts.m4 index adc3235d25d3..7a52b5e33dbd 100644 --- a/sntp/libopts/m4/libopts.m4 +++ b/sntp/libopts/m4/libopts.m4 @@ -2,30 +2,52 @@ dnl -*- buffer-read-only: t -*- vi: set ro: dnl dnl DO NOT EDIT THIS FILE (libopts.m4) dnl -dnl It has been AutoGen-ed Saturday May 5, 2007 at 12:02:37 PM PDT +dnl It has been AutoGen-ed April 29, 2011 at 03:43:56 PM by AutoGen 5.11.9 dnl From the definitions libopts.def dnl and the template file conftest.tpl dnl dnl do always before generated macros: dnl AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ -[if test X${INVOKE_LIBOPTS_MACROS_FIRST_done} != Xyes ; then] - # ================= - # AC_HEADER_STDC - # ================= - AC_HEADER_STDC - # ================= - # AC_HEADER_DIRENT - # ================= + AC_REQUIRE([AC_HEADER_STDC]) AC_HEADER_DIRENT # ================= # AC_CHECK_HEADERS # ================= - AC_CHECK_HEADERS(dlfcn.h errno.h fcntl.h libgen.h memory.h netinet/in.h \ - setjmp.h sys/mman.h sys/param.h sys/poll.h sys/procset.h sys/select.h \ - sys/socket.h sys/stropts.h sys/time.h sys/un.h sys/wait.h unistd.h \ - utime.h sysexits.h) + AC_CHECK_HEADERS([ \ + dlfcn.h errno.h fcntl.h libgen.h \ + memory.h netinet/in.h setjmp.h sys/mman.h \ + sys/param.h sys/poll.h sys/procset.h sys/select.h \ + sys/socket.h sys/stropts.h sys/time.h sys/un.h \ + sys/wait.h unistd.h utime.h sysexits.h ]) + + AC_CHECK_HEADERS([stdarg.h varargs.h], + [lo_have_arg_hdr=true;break], + [lo_have_arg_hdr=false]) + + AC_CHECK_HEADERS([string.h strings.h], + [lo_have_str_hdr=true;break], + [lo_have_str_hdr=false]) + + AC_CHECK_HEADERS([limits.h sys/limits.h values.h], + [lo_have_lim_hdr=true;break], + [lo_have_lim_hdr=false]) + + AC_CHECK_HEADERS([inttypes.h stdint.h], + [lo_have_typ_hdr=true;break], + [lo_have_typ_hdr=false]) + + # ---------------------------------------------------------------------- + # check for various programs used during the build. + # On OS/X, "wchar.h" needs "runetype.h" to work properly. + # ---------------------------------------------------------------------- + AC_CHECK_HEADERS([runetype.h wchar.h], [], [],[ + AC_INCLUDES_DEFAULT + #if HAVE_RUNETYPE_H + # include <runetype.h> + #endif + ]) # -------------------------------------------- # Verify certain entries from AC_CHECK_HEADERS @@ -33,51 +55,46 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ [for f in sys_types sys_mman sys_param sys_stat sys_wait \ string errno stdlib memory setjmp do eval as_ac_var=\${ac_cv_header_${f}_h+set} - test "${as_ac_var}" = set] || \ - AC_MSG_ERROR([You must have ${f}.h on your system]) + test "${as_ac_var}" = set || { + ]AC_MSG_ERROR([You must have ${f}.h on your system])[ + } done - # ================================================ - # AC_CHECK_HEADERS: stdarg.h is present define HAVE_STDARG_H, otherwise - # if varargs.h is present define HAVE_VARARGS_H. - # ================================================ - AC_CHECK_HEADERS(stdarg.h varargs.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have stdarg.h or varargs.h on your system]) - fi + ${lo_have_arg_hdr} || \ + ]AC_MSG_ERROR([You must have stdarg.h or varargs.h on your system])[ - # ================================================ - # Similarly for the string.h and strings.h headers - # ================================================ - AC_CHECK_HEADERS(string.h strings.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have string.h or strings.h on your system]) - fi + ${lo_have_str_hdr} || \ + ]AC_MSG_ERROR([You must have string.h or strings.h on your system])[ - # ===================== - # ...and limits headers - # ===================== - AC_CHECK_HEADERS(limits.h sys/limits.h values.h, break) - [if test `eval echo '${'$as_ac_Header'}'` != yes; then] - AC_MSG_ERROR([You must have one of limits.h, sys/limits.h or values.h]) - fi + ${lo_have_lim_hdr} || \ + ]AC_MSG_ERROR( + [You must have one of limits.h, sys/limits.h or values.h])[ - # ======================== - # ...and int types headers - # ======================== - AC_CHECK_HEADERS(stdint.h inttypes.h, break) + ${lo_have_typ_hdr} || \ + ]AC_MSG_ERROR([You must have inttypes.h or stdint.h on your system]) + + # ---------------------------------------------------------------------- + # Checks for typedefs + # ---------------------------------------------------------------------- + AC_CHECK_TYPES(wchar_t) + AC_CHECK_TYPES(wint_t, [], [], [ + AC_INCLUDES_DEFAULT + #if HAVE_RUNETYPE_H + # include <runetype.h> + #endif + #if HAVE_WCHAR_H + # include <wchar.h> + #endif + ]) AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, - intptr_t, uint_t]) + intptr_t, uintptr_t, uint_t, pid_t, size_t]) - # ==================== - # uintptr type & sizes - # ==================== - AC_CHECK_TYPES([uintptr_t], , - [AC_DEFINE([uintptr_t], unsigned long, - [Alternate uintptr_t for systems without it.])]) - AC_CHECK_SIZEOF(char*, 4) + # ===== + # sizes + # ===== + AC_CHECK_SIZEOF(char*, 8) AC_CHECK_SIZEOF(int, 4) - AC_CHECK_SIZEOF(long, 4) + AC_CHECK_SIZEOF(long, 8) AC_CHECK_SIZEOF(short, 2) # ---------------------------------------------------------------------- @@ -85,9 +102,29 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS_FIRST],[ # ---------------------------------------------------------------------- AC_CHECK_LIB(gen, pathfind) AC_FUNC_VPRINTF - AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr strrchr]) -[ INVOKE_LIBOPTS_MACROS_FIRST_done=yes -fi]]) + AC_FUNC_FORK + AC_CHECK_FUNCS([mmap canonicalize_file_name snprintf strdup strchr \ + strrchr strsignal]) + AC_PROG_SED + [while : + do + POSIX_SHELL=`which bash` + test -x "$POSIX_SHELL" && break + POSIX_SHELL=`which dash` + test -x "$POSIX_SHELL" && break + POSIX_SHELL=/usr/xpg4/bin/sh + test -x "$POSIX_SHELL" && break + POSIX_SHELL=`/bin/sh -c ' + exec 2>/dev/null + if ! true ; then exit 1 ; fi + echo /bin/sh'` + test -x "$POSIX_SHELL" && break + ]AC_ERROR([Cannot locate a working POSIX shell])[ + done] + AC_DEFINE_UNQUOTED([POSIX_SHELL], ["${POSIX_SHELL}"], + [define to a working POSIX compliant shell]) + AC_SUBST([POSIX_SHELL]) +]) dnl dnl @synopsis INVOKE_LIBOPTS_MACROS @@ -97,12 +134,11 @@ dnl that have not been disabled with "omit-invocation". dnl AC_DEFUN([LIBOPTS_WITH_REGEX_HEADER],[ AC_ARG_WITH([regex-header], - AC_HELP_STRING([--with-regex-header], [a reg expr header is specified]), + AS_HELP_STRING([--with-regex-header], [a reg expr header is specified]), [libopts_cv_with_regex_header=${with_regex_header}], AC_CACHE_CHECK([whether a reg expr header is specified], libopts_cv_with_regex_header, libopts_cv_with_regex_header=no) ) # end of AC_ARG_WITH - if test "X${libopts_cv_with_regex_header}" != Xno then AC_DEFINE_UNQUOTED([REGEX_HEADER],[<${libopts_cv_with_regex_header}>]) @@ -115,13 +151,13 @@ AC_DEFUN([LIBOPTS_WITH_REGEX_HEADER],[ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[ AC_ARG_WITH([libregex], - AC_HELP_STRING([--with-libregex], [libregex installation prefix]), + AS_HELP_STRING([--with-libregex], [libregex installation prefix]), [libopts_cv_with_libregex_root=${with_libregex}], AC_CACHE_CHECK([whether with-libregex was specified], libopts_cv_with_libregex_root, libopts_cv_with_libregex_root=no) ) # end of AC_ARG_WITH libregex - if test "${with_libguile+set}" = set && \ + if test "${with_libregex+set}" = set && \ test "${withval}" = no then ## disabled by request libopts_cv_with_libregex_root=no @@ -130,14 +166,14 @@ AC_DEFUN([LIBOPTS_WITHLIB_REGEX],[ else AC_ARG_WITH([libregex-cflags], - AC_HELP_STRING([--with-libregex-cflags], [libregex compile flags]), + AS_HELP_STRING([--with-libregex-cflags], [libregex compile flags]), [libopts_cv_with_libregex_cflags=${with_regex_cflags}], AC_CACHE_CHECK([whether with-libregex-cflags was specified], libopts_cv_with_libregex_cflags, libopts_cv_with_libregex_cflags=no) ) # end of AC_ARG_WITH libregex-cflags AC_ARG_WITH([libregex-libs], - AC_HELP_STRING([--with-libregex-libs], [libregex link command arguments]), + AS_HELP_STRING([--with-libregex-libs], [libregex link command arguments]), [libopts_cv_with_libregex_libs=${with_regex_libs}], AC_CACHE_CHECK([whether with-libregex-libs was specified], libopts_cv_with_libregex_libs, libopts_cv_with_libregex_libs=no) @@ -200,7 +236,6 @@ int main() { [libopts_cv_with_libregex=no]) # end of AC_TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_with_libregex AC_MSG_RESULT([${libopts_cv_with_libregex}]) - if test "X${libopts_cv_with_libregex}" != Xno then AC_DEFINE([WITH_LIBREGEX],[1], @@ -226,7 +261,6 @@ int main (int argc, char** argv) { ) # end of TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_run_pathfind AC_MSG_RESULT([${libopts_cv_run_pathfind}]) - if test "X${libopts_cv_run_pathfind}" != Xno then AC_DEFINE([HAVE_PATHFIND],[1], @@ -243,14 +277,11 @@ AC_DEFUN([LIBOPTS_TEST_DEV_ZERO],[ dzero=\`ls -lL /dev/zero | egrep ^c......r\` test -z "${dzero}" && exit 1 echo ${dzero}` - if test $? -ne 0 - then libopts_cv_test_dev_zero=no - elif test -z "$libopts_cv_test_dev_zero" + if test $? -ne 0 || test -z "$libopts_cv_test_dev_zero" then libopts_cv_test_dev_zero=no fi ]) # end of CACHE_VAL of libopts_cv_test_dev_zero AC_MSG_RESULT([${libopts_cv_test_dev_zero}]) - if test "X${libopts_cv_test_dev_zero}" != Xno then AC_DEFINE([HAVE_DEV_ZERO],[1], @@ -278,7 +309,6 @@ choke me!! ) # end of TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_run_realpath AC_MSG_RESULT([${libopts_cv_run_realpath}]) - if test "X${libopts_cv_run_realpath}" != Xno then AC_DEFINE([HAVE_REALPATH],[1], @@ -312,7 +342,6 @@ int main() { ) # end of TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_run_strftime AC_MSG_RESULT([${libopts_cv_run_strftime}]) - if test "X${libopts_cv_run_strftime}" != Xno then AC_DEFINE([HAVE_STRFTIME],[1], @@ -333,7 +362,6 @@ return (fp == NULL) ? 1 : fclose(fp); }], ) # end of TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_binary AC_MSG_RESULT([${libopts_cv_run_fopen_binary}]) - if test "X${libopts_cv_run_fopen_binary}" != Xno then AC_DEFINE([FOPEN_BINARY_FLAG],"b", @@ -357,7 +385,6 @@ return (fp == NULL) ? 1 : fclose(fp); }], ) # end of TRY_RUN ]) # end of AC_CACHE_VAL for libopts_cv_run_fopen_text AC_MSG_RESULT([${libopts_cv_run_fopen_text}]) - if test "X${libopts_cv_run_fopen_text}" != Xno then AC_DEFINE([FOPEN_TEXT_FLAG],"t", @@ -372,12 +399,11 @@ return (fp == NULL) ? 1 : fclose(fp); }], AC_DEFUN([LIBOPTS_DISABLE_OPTIONAL_ARGS],[ AC_ARG_ENABLE([optional-args], - AC_HELP_STRING([--disable-optional-args], [not wanting optional option args]), + AS_HELP_STRING([--disable-optional-args], [not wanting optional option args]), [libopts_cv_enable_optional_args=${enable_optional_args}], AC_CACHE_CHECK([whether not wanting optional option args], libopts_cv_enable_optional_args, libopts_cv_enable_optional_args=yes) ) # end of AC_ARG_ENABLE - if test "X${libopts_cv_enable_optional_args}" = Xno then AC_DEFINE([NO_OPTIONAL_OPT_ARGS], [1], @@ -388,7 +414,7 @@ AC_DEFUN([LIBOPTS_DISABLE_OPTIONAL_ARGS],[ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[ - INVOKE_LIBOPTS_MACROS_FIRST + AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST]) # Check to see if a reg expr header is specified. LIBOPTS_WITH_REGEX_HEADER @@ -420,21 +446,36 @@ AC_DEFUN([INVOKE_LIBOPTS_MACROS],[ dnl @synopsis LIBOPTS_CHECK dnl -dnl Time-stamp: "2006-09-23 19:36:24 bkorb" -dnl Last Committed: $Date: 2006/09/24 02:59:00 $ +dnl Time-stamp: "2010-11-29 15:45:54 bkorb" dnl dnl If autoopts-config works, add the linking information to LIBS. dnl Otherwise, add ``libopts-${ao_rev}'' to SUBDIRS and run all dnl the config tests that the library needs. Invoke the dnl "INVOKE_LIBOPTS_MACROS" macro iff we are building libopts. dnl +dnl This file is part of AutoGen. +dnl AutoGen Copyright (c) 1992-2011 by Bruce Korb - all rights reserved +dnl +dnl AutoGen is free software: you can redistribute it and/or modify it +dnl under the terms of the GNU General Public License as published by the +dnl Free Software Foundation, either version 3 of the License, or +dnl (at your option) any later version. +dnl +dnl AutoGen is distributed in the hope that it will be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl See the GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License along +dnl with this program. If not, see <http://www.gnu.org/licenses/>. +dnl dnl Default to system libopts dnl -AC_DEFUN([LIBOPTS_CHECK],[ +AC_DEFUN([LIBOPTS_CHECK_COMMON],[ + AC_REQUIRE([INVOKE_LIBOPTS_MACROS_FIRST]) [NEED_LIBOPTS_DIR=''] m4_pushdef([AO_Libopts_Dir], [ifelse($1, , [libopts], [$1])]) - AC_SUBST(LIBOPTS_DIR, AO_Libopts_Dir) AC_ARG_ENABLE([local-libopts], AC_HELP_STRING([--enable-local-libopts], [Force using the supplied libopts tearoff code]),[ @@ -491,19 +532,51 @@ AC_DEFUN([LIBOPTS_CHECK],[ LIBOPTS_CFLAGS='-I$(top_srcdir)/]AO_Libopts_Dir[' NEED_LIBOPTS_DIR=true fi - fi # end of if test -z "${NEED_LIBOPTS_DIR}"] - + fi # end of if test -z "${NEED_LIBOPTS_DIR}" + if test -n "${LIBOPTS_BUILD_BLOCKED}" ; then + NEED_LIBOPTS_DIR='' + fi] AM_CONDITIONAL([NEED_LIBOPTS], [test -n "${NEED_LIBOPTS_DIR}"]) AC_SUBST(LIBOPTS_LDADD) AC_SUBST(LIBOPTS_CFLAGS) AC_SUBST(LIBOPTS_DIR, AO_Libopts_Dir) - AC_CONFIG_FILES(AO_Libopts_Dir/Makefile) m4_popdef([AO_Libopts_Dir]) - - [if test -n "${NEED_LIBOPTS_DIR}" ; then] +[# end of AC_DEFUN of LIBOPTS_CHECK_COMMON] +]) +dnl AC_CONFIG_FILES conditionalization requires using AM_COND_IF, however +dnl AM_COND_IF is new to Automake 1.11. To use it on new Automake without +dnl requiring same, a fallback implementation for older Automake is provided. +dnl Note that disabling of AC_CONFIG_FILES requires Automake 1.11, this code +dnl is correct only in terms of m4sh generated script. +m4_ifndef([AM_COND_IF], [AC_DEFUN([AM_COND_IF], [ +if test -z "$$1_TRUE"; then : + m4_n([$2])[]dnl +m4_ifval([$3], +[else + $3 +])dnl +fi[]dnl +])]) +dnl +AC_DEFUN([LIBOPTS_CHECK_NOBUILD], [ + m4_pushdef([AO_Libopts_Dir], + [ifelse($1, , [libopts], [$1])]) + LIBOPTS_BUILD_BLOCKED=true + LIBOPTS_CHECK_COMMON(AO_Libopts_Dir) + m4_popdef([AO_Libopts_Dir])dnl +# end of AC_DEFUN of LIBOPTS_CHECK_NOBUILD +]) +dnl +AC_DEFUN([LIBOPTS_CHECK], [ + m4_pushdef([AO_Libopts_Dir], + [ifelse($1, , [libopts], [$1])]) + LIBOPTS_BUILD_BLOCKED='' + LIBOPTS_CHECK_COMMON(AO_Libopts_Dir) + AM_COND_IF([NEED_LIBOPTS], [ INVOKE_LIBOPTS_MACROS - else - INVOKE_LIBOPTS_MACROS_FIRST - [fi -# end of AC_DEFUN of LIBOPTS_CHECK] + AC_CONFIG_FILES(AO_Libopts_Dir/Makefile) + ])dnl + m4_popdef([AO_Libopts_Dir])dnl +# end of AC_DEFUN of LIBOPTS_CHECK ]) + diff --git a/sntp/libopts/m4/liboptschk.m4 b/sntp/libopts/m4/liboptschk.m4 index 14e7f27c8198..48e4ceb7a108 100644 --- a/sntp/libopts/m4/liboptschk.m4 +++ b/sntp/libopts/m4/liboptschk.m4 @@ -1,42 +1,29 @@ -# liboptschk.m4 serial 1 (autogen - 5.7.3) -dnl Copyright (C) 2005 Free Software Foundation, Inc. +# liboptschk.m4 serial 2 (autogen - 5.11.4) +dnl Copyright (c) 2005-2011 by Bruce Korb - all rights reserved +dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. - -dnl Time-stamp: "2006-09-23 19:42:31 bkorb" -dnl Last Committed: $Date: 2006/09/24 02:59:00 $ - -dnl This file can can be used in projects which are not available under -dnl the GNU General Public License or the GNU Library General Public -dnl License but which still want to provide support for the GNU gettext -dnl functionality. -dnl Please note that the actual code of the GNU gettext library is covered -dnl by the GNU Library General Public License, and the rest of the GNU -dnl gettext package package is covered by the GNU General Public License. -dnl They are *not* in the public domain. - -dnl Authors: -dnl Ulrich Drepper <drepper@cygnus.com>, 1995-2000. -dnl Bruno Haible <haible@clisp.cons.org>, 2000-2003. - -AC_PREREQ(2.50) - +dnl +dnl Time-stamp: "2010-12-07 12:57:56 bkorb" +dnl AC_DEFUN([ag_FIND_LIBOPTS], - [if test "X${ac_cv_header_autoopts_options_h}" == Xno + [if test "X${ac_cv_header_autoopts_options_h}" = Xno + then : + else + f=`autoopts-config cflags` 2>/dev/null + if test X"${f}" = X then : else - f=`autoopts-config cflags` 2>/dev/null - test X"${f}" = X && f=`libopts-config cflags` 2>/dev/null - if test X"${f}" = X - then - : - else - AC_DEFINE([HAVE_LIBOPTS],[1],[define if we can find libopts]) - CFLAGS="${CFLAGS} ${f}" - f=`autoopts-config ldflags` 2>/dev/null - test X"${f}" = X && f=`libopts-config ldflags` 2>/dev/null - LIBS="${LIBS} ${f}" - fi - fi]) + AC_DEFINE([HAVE_LIBOPTS],[1],[define if we can find libopts]) + CFLAGS="${CFLAGS} ${f}" + ao_CFLAGS="${f}" + AC_SUBST(ao_CFLAGS) + + f=`autoopts-config ldflags` 2>/dev/null + LIBS="${LIBS} ${f}" + ao_LIBS="${f}" + AC_SUBST(ao_LIBS) + fi + fi]) diff --git a/sntp/libopts/makeshell.c b/sntp/libopts/makeshell.c index 8447d454b083..7b9b6cdde179 100644 --- a/sntp/libopts/makeshell.c +++ b/sntp/libopts/makeshell.c @@ -1,74 +1,52 @@ -/* - * $Id: makeshell.c,v 4.20 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-27 06:05:45 bkorb" +/** + * \file makeshell.c + * + * Time-stamp: "2011-04-20 11:06:57 bkorb" * * This module will interpret the options set in the tOptions * structure and create a Bourne shell script capable of parsing them. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -tOptions* pShellParseOptions = NULL; +tOptions * optionParseShellOptions = NULL; /* * * * * * * * * * * * * * * * * * * * * * * Setup Format Strings */ -tSCC zStartMarker[] = +static char const zStartMarker[] = "# # # # # # # # # # -- do not modify this marker --\n#\n" "# DO NOT EDIT THIS SECTION"; -tSCC zPreamble[] = +static char const zPreamble[] = "%s OF %s\n#\n" "# From here to the next `-- do not modify this marker --',\n" "# the text has been generated %s\n"; -tSCC zEndPreamble[] = +static char const zEndPreamble[] = "# From the %s option definitions\n#\n"; -tSCC zMultiDef[] = "\n" +static char const zMultiDef[] = "\n" "if test -z \"${%1$s_%2$s}\"\n" "then\n" " %1$s_%2$s_CT=0\n" @@ -78,12 +56,12 @@ tSCC zMultiDef[] = "\n" "fi\n" "export %1$s_%2$s_CT"; -tSCC zSingleDef[] = "\n" +static char const zSingleDef[] = "\n" "%1$s_%2$s=\"${%1$s_%2$s-'%3$s'}\"\n" "%1$s_%2$s_set=false\n" "export %1$s_%2$s\n"; -tSCC zSingleNoDef[] = "\n" +static char const zSingleNoDef[] = "\n" "%1$s_%2$s=\"${%1$s_%2$s}\"\n" "%1$s_%2$s_set=false\n" "export %1$s_%2$s\n"; @@ -96,7 +74,7 @@ tSCC zSingleNoDef[] = "\n" * all options are named options (loop only) * regular, marked option processing. */ -tSCC zLoopCase[] = "\n" +static char const zLoopCase[] = "\n" "OPT_PROCESS=true\n" "OPT_ARG=\"$1\"\n\n" "while ${OPT_PROCESS} && [ $# -gt 0 ]\ndo\n" @@ -111,7 +89,7 @@ tSCC zLoopCase[] = "\n" " shift\n" " ;;\n\n"; -tSCC zLoopOnly[] = "\n" +static char const zLoopOnly[] = "\n" "OPT_ARG=\"$1\"\n\n" "while [ $# -gt 0 ]\ndo\n" " OPT_ELEMENT=''\n" @@ -126,16 +104,16 @@ tSCC zLoopOnly[] = "\n" * then we must have selectors for each acceptable option * type (long option, flag character and non-option) */ -tSCC zLongSelection[] = +static char const zLongSelection[] = " --* )\n"; -tSCC zFlagSelection[] = +static char const zFlagSelection[] = " -* )\n"; -tSCC zEndSelection[] = +static char const zEndSelection[] = " ;;\n\n"; -tSCC zNoSelection[] = +static char const zNoSelection[] = " * )\n" " OPT_PROCESS=false\n" " ;;\n" @@ -145,7 +123,7 @@ tSCC zNoSelection[] = * * LOOP END */ -tSCC zLoopEnd[] = +static char const zLoopEnd[] = " if [ -n \"${OPT_ARG_VAL}\" ]\n" " then\n" " eval %1$s_${OPT_NAME}${OPT_ELEMENT}=\"'${OPT_ARG_VAL}'\"\n" @@ -160,7 +138,7 @@ tSCC zLoopEnd[] = "unset OPT_CODE || :\n" "unset OPT_ARG_VAL || :\n%2$s"; -tSCC zTrailerMarker[] = "\n" +static char const zTrailerMarker[] = "\n" "# # # # # # # # # #\n#\n" "# END OF AUTOMATED OPTION PROCESSING\n" "#\n# # # # # # # # # # -- do not modify this marker --\n"; @@ -169,22 +147,22 @@ tSCC zTrailerMarker[] = "\n" * * OPTION SELECTION */ -tSCC zOptionCase[] = +static char const zOptionCase[] = " case \"${OPT_CODE}\" in\n"; -tSCC zOptionPartName[] = +static char const zOptionPartName[] = " '%s' | \\\n"; -tSCC zOptionFullName[] = +static char const zOptionFullName[] = " '%s' )\n"; -tSCC zOptionFlag[] = +static char const zOptionFlag[] = " '%c' )\n"; -tSCC zOptionEndSelect[] = +static char const zOptionEndSelect[] = " ;;\n\n"; -tSCC zOptionUnknown[] = +static char const zOptionUnknown[] = " * )\n" " echo Unknown %s: \"${OPT_CODE}\" >&2\n" " echo \"$%s_USAGE_TEXT\"\n" @@ -198,29 +176,29 @@ tSCC zOptionUnknown[] = * * Formats for emitting the text for handling particular options */ -tSCC zTextExit[] = +static char const zTextExit[] = " echo \"$%s_%s_TEXT\"\n" " exit 0\n"; -tSCC zPagedUsageExit[] = +static char const zPagedUsageExit[] = " echo \"$%s_LONGUSAGE_TEXT\" | ${PAGER-more}\n" " exit 0\n"; -tSCC zCmdFmt[] = +static char const zCmdFmt[] = " %s\n"; -tSCC zCountTest[] = +static char const zCountTest[] = " if [ $%1$s_%2$s_CT -ge %3$d ] ; then\n" " echo Error: more than %3$d %2$s options >&2\n" " echo \"$%1$s_USAGE_TEXT\"\n" " exit 1 ; fi\n"; -tSCC zMultiArg[] = +static char const zMultiArg[] = " %1$s_%2$s_CT=`expr ${%1$s_%2$s_CT} + 1`\n" " OPT_ELEMENT=\"_${%1$s_%2$s_CT}\"\n" " OPT_NAME='%2$s'\n"; -tSCC zSingleArg[] = +static char const zSingleArg[] = " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n" " echo Error: duplicate %2$s option >&2\n" " echo \"$%1$s_USAGE_TEXT\"\n" @@ -228,14 +206,14 @@ tSCC zSingleArg[] = " %1$s_%2$s_set=true\n" " OPT_NAME='%2$s'\n"; -tSCC zNoMultiArg[] = +static char const zNoMultiArg[] = " %1$s_%2$s_CT=0\n" " OPT_ELEMENT=''\n" " %1$s_%2$s='%3$s'\n" " export %1$s_%2$s\n" " OPT_NAME='%2$s'\n"; -tSCC zNoSingleArg[] = +static char const zNoSingleArg[] = " if [ -n \"${%1$s_%2$s}\" ] && ${%1$s_%2$s_set} ; then\n" " echo Error: duplicate %2$s option >&2\n" " echo \"$%1$s_USAGE_TEXT\"\n" @@ -245,15 +223,15 @@ tSCC zNoSingleArg[] = " export %1$s_%2$s\n" " OPT_NAME='%2$s'\n"; -tSCC zMayArg[] = +static char const zMayArg[] = " eval %1$s_%2$s${OPT_ELEMENT}=true\n" " export %1$s_%2$s${OPT_ELEMENT}\n" " OPT_ARG_NEEDED=OK\n"; -tSCC zMustArg[] = +static char const zMustArg[] = " OPT_ARG_NEEDED=YES\n"; -tSCC zCantArg[] = +static char const zCantArg[] = " eval %1$s_%2$s${OPT_ELEMENT}=true\n" " export %1$s_%2$s${OPT_ELEMENT}\n" " OPT_ARG_NEEDED=NO\n"; @@ -264,7 +242,7 @@ tSCC zCantArg[] = * * Formats for emitting the text for handling long option types */ -tSCC zLongOptInit[] = +static char const zLongOptInit[] = " OPT_CODE=`echo \"X${OPT_ARG}\"|sed 's/^X-*//'`\n" " shift\n" " OPT_ARG=\"$1\"\n\n" @@ -272,7 +250,7 @@ tSCC zLongOptInit[] = " OPT_ARG_VAL=`echo \"${OPT_CODE}\"|sed 's/^[^=]*=//'`\n" " OPT_CODE=`echo \"${OPT_CODE}\"|sed 's/=.*$//'` ;; esac\n\n"; -tSCC zLongOptArg[] = +static char const zLongOptArg[] = " case \"${OPT_ARG_NEEDED}\" in\n" " NO )\n" " OPT_ARG_VAL=''\n" @@ -308,11 +286,11 @@ tSCC zLongOptArg[] = * * Formats for emitting the text for handling flag option types */ -tSCC zFlagOptInit[] = +static char const zFlagOptInit[] = " OPT_CODE=`echo \"X${OPT_ARG}\" | sed 's/X-\\(.\\).*/\\1/'`\n" " OPT_ARG=` echo \"X${OPT_ARG}\" | sed 's/X-.//'`\n\n"; -tSCC zFlagOptArg[] = +static char const zFlagOptArg[] = " case \"${OPT_ARG_NEEDED}\" in\n" " NO )\n" " if [ -n \"${OPT_ARG}\" ]\n" @@ -364,33 +342,35 @@ static char* pzLeader = NULL; static char* pzTrailer = NULL; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ); +emit_var_text(char const * prog, char const * var, int fdin); + +static void +textToVariable(tOptions * pOpts, teTextTo whichVar, tOptDesc * pOD); static void -emitUsage( tOptions* pOpts ); +emitUsage(tOptions* pOpts); static void -emitSetup( tOptions* pOpts ); +emitSetup(tOptions* pOpts); static void -printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc ); +printOptionAction(tOptions* pOpts, tOptDesc* pOptDesc); static void -printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc ); +printOptionInaction(tOptions* pOpts, tOptDesc* pOptDesc); static void -emitFlag( tOptions* pOpts ); +emitFlag(tOptions* pOpts); static void -emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ); +emitMatchExpr(tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts); static void -emitLong( tOptions* pOpts ); +emitLong(tOptions* pOpts); static void -openOutput( char const* pzFile ); +openOutput(char const* pzFile); /* = = = END-STATIC-FORWARD = = = */ /*=export_func optionParseShell @@ -403,146 +383,205 @@ openOutput( char const* pzFile ); * Emit a shell script that will parse the command line options. =*/ void -optionParseShell( tOptions* pOpts ) +optionParseShell(tOptions* pOpts) { /* * Check for our SHELL option now. * IF the output file contains the "#!" magic marker, * it will override anything we do here. */ - if (HAVE_OPT( SHELL )) - pzShell = OPT_ARG( SHELL ); + if (HAVE_GENSHELL_OPT(SHELL)) + pzShell = GENSHELL_OPT_ARG(SHELL); - else if (! ENABLED_OPT( SHELL )) + else if (! ENABLED_GENSHELL_OPT(SHELL)) pzShell = NULL; - else if ((pzShell = getenv( "SHELL" )), + else if ((pzShell = getenv("SHELL")), pzShell == NULL) - pzShell = "/bin/sh"; + pzShell = POSIX_SHELL; /* * Check for a specified output file */ - if (HAVE_OPT( SCRIPT )) - openOutput( OPT_ARG( SCRIPT )); + if (HAVE_GENSHELL_OPT(SCRIPT)) + openOutput(GENSHELL_OPT_ARG(SCRIPT)); - emitUsage( pOpts ); - emitSetup( pOpts ); + emitUsage(pOpts); + emitSetup(pOpts); /* * There are four modes of option processing. */ switch (pOpts->fOptSet & (OPTPROC_LONGOPT|OPTPROC_SHORTOPT)) { case OPTPROC_LONGOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zLongSelection, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zLongSelection, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; case 0: - fputs( zLoopOnly, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); + fputs(zLoopOnly, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); break; case OPTPROC_SHORTOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zFlagSelection, stdout ); - fputs( zFlagOptInit, stdout ); - emitFlag( pOpts ); - printf( zFlagOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zFlagSelection, stdout); + fputs(zFlagOptInit, stdout); + emitFlag(pOpts); + printf(zFlagOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; case OPTPROC_LONGOPT|OPTPROC_SHORTOPT: - fputs( zLoopCase, stdout ); + fputs(zLoopCase, stdout); - fputs( zLongSelection, stdout ); - fputs( zLongOptInit, stdout ); - emitLong( pOpts ); - printf( zLongOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zLongSelection, stdout); + fputs(zLongOptInit, stdout); + emitLong(pOpts); + printf(zLongOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zFlagSelection, stdout ); - fputs( zFlagOptInit, stdout ); - emitFlag( pOpts ); - printf( zFlagOptArg, pOpts->pzPROGNAME ); - fputs( zEndSelection, stdout ); + fputs(zFlagSelection, stdout); + fputs(zFlagOptInit, stdout); + emitFlag(pOpts); + printf(zFlagOptArg, pOpts->pzPROGNAME); + fputs(zEndSelection, stdout); - fputs( zNoSelection, stdout ); + fputs(zNoSelection, stdout); break; } - printf( zLoopEnd, pOpts->pzPROGNAME, zTrailerMarker ); + printf(zLoopEnd, pOpts->pzPROGNAME, zTrailerMarker); if ((pzTrailer != NULL) && (*pzTrailer != '\0')) - fputs( pzTrailer, stdout ); - else if (ENABLED_OPT( SHELL )) - printf( "\nenv | grep '^%s_'\n", pOpts->pzPROGNAME ); + fputs(pzTrailer, stdout); + else if (ENABLED_GENSHELL_OPT(SHELL)) + printf("\nenv | grep '^%s_'\n", pOpts->pzPROGNAME); + + fflush(stdout); + fchmod(STDOUT_FILENO, 0755); + fclose(stdout); + if (ferror(stdout)) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } +} + +#ifdef HAVE_WORKING_FORK +static void +emit_var_text(char const * prog, char const * var, int fdin) +{ + FILE * fp = fdopen(fdin, "r" FOPEN_BINARY_FLAG); + int nlct = 0; /* defer newlines and skip trailing ones */ + + printf("%s_%s_TEXT='", prog, var); + if (fp == NULL) + goto skip_text; + + for (;;) { + int ch = fgetc(fp); + switch (ch) { + + case '\n': + nlct++; + break; + + case '\'': + while (nlct > 0) { + fputc('\n', stdout); + nlct--; + } + fputs("'\\''", stdout); + break; + + case EOF: + goto endCharLoop; + + default: + while (nlct > 0) { + fputc('\n', stdout); + nlct--; + } + fputc(ch, stdout); + break; + } + } endCharLoop:; - fflush( stdout ); - fchmod( STDOUT_FILENO, 0755 ); - fclose( stdout ); + fclose(fp); + +skip_text: + + fputs("'\n\n", stdout); } +#endif +/* + * The purpose of this function is to assign "long usage", short usage + * and version information to a shell variable. Rather than wind our + * way through all the logic necessary to emit the text directly, we + * fork(), have our child process emit the text the normal way and + * capture the output in the parent process. + */ static void -textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) +textToVariable(tOptions * pOpts, teTextTo whichVar, tOptDesc * pOD) { -# define _TT_(n) tSCC z ## n [] = #n; +# define _TT_(n) static char const z ## n [] = #n; TEXTTO_TABLE # undef _TT_ # define _TT_(n) z ## n , - static char const* apzTTNames[] = { TEXTTO_TABLE }; + static char const * apzTTNames[] = { TEXTTO_TABLE }; # undef _TT_ -#if defined(__windows__) && !defined(__CYGWIN__) - printf( "%1$s_%2$s_TEXT='no %2$s text'\n", - pOpts->pzPROGNAME, apzTTNames[ whichVar ]); +#if ! defined(HAVE_WORKING_FORK) + printf("%1$s_%2$s_TEXT='no %2$s text'\n", + pOpts->pzPROGNAME, apzTTNames[ whichVar ]); #else - int nlHoldCt = 0; int pipeFd[2]; - FILE* fp; - printf( "%s_%s_TEXT='", pOpts->pzPROGNAME, apzTTNames[ whichVar ]); - fflush( stdout ); + fflush(stdout); + fflush(stderr); - if (pipe( pipeFd ) != 0) { - fprintf( stderr, zBadPipe, errno, strerror( errno )); - exit( EXIT_FAILURE ); + if (pipe(pipeFd) != 0) { + fprintf(stderr, zBadPipe, errno, strerror(errno)); + exit(EXIT_FAILURE); } switch (fork()) { case -1: - fprintf( stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName); - exit( EXIT_FAILURE ); + fprintf(stderr, zForkFail, errno, strerror(errno), pOpts->pzProgName); + exit(EXIT_FAILURE); break; case 0: - dup2( pipeFd[1], STDERR_FILENO ); - dup2( pipeFd[1], STDOUT_FILENO ); - close( pipeFd[0] ); + /* + * Send both stderr and stdout to the pipe. No matter which + * descriptor is used, we capture the output on the read end. + */ + dup2(pipeFd[1], STDERR_FILENO); + dup2(pipeFd[1], STDOUT_FILENO); + close(pipeFd[0]); switch (whichVar) { case TT_LONGUSAGE: - (*(pOpts->pUsageProc))( pOpts, EXIT_SUCCESS ); + (*(pOpts->pUsageProc))(pOpts, EXIT_SUCCESS); /* NOTREACHED */ - exit( EXIT_FAILURE ); case TT_USAGE: - (*(pOpts->pUsageProc))( pOpts, EXIT_FAILURE ); + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); /* NOTREACHED */ - exit( EXIT_FAILURE ); case TT_VERSION: if (pOD->fOptState & OPTST_ALLOC_ARG) { @@ -550,57 +589,26 @@ textToVariable( tOptions* pOpts, teTextTo whichVar, tOptDesc* pOD ) pOD->fOptState &= ~OPTST_ALLOC_ARG; } pOD->optArg.argString = "c"; - optionPrintVersion( pOpts, pOD ); + optionPrintVersion(pOpts, pOD); /* NOTREACHED */ default: - exit( EXIT_FAILURE ); + exit(EXIT_FAILURE); } default: - close( pipeFd[1] ); - fp = fdopen( pipeFd[0], "r" FOPEN_BINARY_FLAG ); + close(pipeFd[1]); } - for (;;) { - int ch = fgetc( fp ); - switch (ch) { - - case '\n': - nlHoldCt++; - break; - - case '\'': - while (nlHoldCt > 0) { - fputc( '\n', stdout ); - nlHoldCt--; - } - fputs( "'\\''", stdout ); - break; - - case EOF: - goto endCharLoop; - - default: - while (nlHoldCt > 0) { - fputc( '\n', stdout ); - nlHoldCt--; - } - fputc( ch, stdout ); - break; - } - } endCharLoop:; - - fputs( "'\n\n", stdout ); - close( pipeFd[0] ); + emit_var_text(pOpts->pzPROGNAME, apzTTNames[whichVar], pipeFd[0]); #endif } static void -emitUsage( tOptions* pOpts ) +emitUsage(tOptions* pOpts) { - char zTimeBuf[ AO_NAME_SIZE ]; + char zTimeBuf[AO_NAME_SIZE]; /* * First, switch stdout to the output file name. @@ -609,45 +617,52 @@ emitUsage( tOptions* pOpts ) * executable name). Down case the upper cased name. */ if (pzLeader != NULL) - fputs( pzLeader, stdout ); + fputs(pzLeader, stdout); { tSCC zStdout[] = "stdout"; tCC* pzOutName; { - time_t curTime = time( NULL ); - struct tm* pTime = localtime( &curTime ); + time_t curTime = time(NULL); + struct tm* pTime = localtime(&curTime); strftime(zTimeBuf, AO_NAME_SIZE, "%A %B %e, %Y at %r %Z", pTime ); } - if (HAVE_OPT( SCRIPT )) - pzOutName = OPT_ARG( SCRIPT ); + if (HAVE_GENSHELL_OPT(SCRIPT)) + pzOutName = GENSHELL_OPT_ARG(SCRIPT); else pzOutName = zStdout; if ((pzLeader == NULL) && (pzShell != NULL)) - printf( "#! %s\n", pzShell ); + printf("#! %s\n", pzShell); - printf( zPreamble, zStartMarker, pzOutName, zTimeBuf ); + printf(zPreamble, zStartMarker, pzOutName, zTimeBuf); } + printf(zEndPreamble, pOpts->pzPROGNAME); + /* - * Get a copy of the original program name in lower case + * Get a copy of the original program name in lower case and + * fill in an approximation of the program name from it. */ { - char* pzPN = zTimeBuf; - tCC* pz = pOpts->pzPROGNAME; + char * pzPN = zTimeBuf; + char const * pz = pOpts->pzPROGNAME; + char ** pp; + for (;;) { - if ((*pzPN++ = tolower( *pz++ )) == '\0') + if ((*pzPN++ = tolower(*pz++)) == '\0') break; } - } - printf( zEndPreamble, pOpts->pzPROGNAME ); + pp = (char **)(void *)&(pOpts->pzProgPath); + *pp = zTimeBuf; + pp = (char **)(void *)&(pOpts->pzProgName); + *pp = zTimeBuf; + } - pOpts->pzProgPath = pOpts->pzProgName = zTimeBuf; - textToVariable( pOpts, TT_LONGUSAGE, NULL ); - textToVariable( pOpts, TT_USAGE, NULL ); + textToVariable(pOpts, TT_LONGUSAGE, NULL); + textToVariable(pOpts, TT_USAGE, NULL); { tOptDesc* pOptDesc = pOpts->pOptDesc; @@ -655,7 +670,7 @@ emitUsage( tOptions* pOpts ) for (;;) { if (pOptDesc->pOptProc == optionPrintVersion) { - textToVariable( pOpts, TT_VERSION, pOptDesc ); + textToVariable(pOpts, TT_VERSION, pOptDesc); break; } @@ -668,7 +683,7 @@ emitUsage( tOptions* pOpts ) static void -emitSetup( tOptions* pOpts ) +emitSetup(tOptions* pOpts) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->presetOptCt; @@ -695,7 +710,7 @@ emitSetup( tOptions* pOpts ) */ switch (OPTST_GET_ARGTYPE(pOptDesc->fOptState)) { case OPARG_TYPE_ENUMERATION: - (*(pOptDesc->pOptProc))( (tOptions*)2UL, pOptDesc ); + (*(pOptDesc->pOptProc))(OPTPROC_EMIT_SHELL, pOptDesc ); pzDefault = pOptDesc->optArg.argString; break; @@ -703,14 +718,14 @@ emitSetup( tOptions* pOpts ) * Numeric and membership bit options are just printed as a number. */ case OPARG_TYPE_NUMERIC: - snprintf( zVal, sizeof( zVal ), "%d", - (int)pOptDesc->optArg.argInt ); + snprintf(zVal, sizeof(zVal), "%d", + (int)pOptDesc->optArg.argInt); pzDefault = zVal; break; case OPARG_TYPE_MEMBERSHIP: - snprintf( zVal, sizeof( zVal ), "%lu", - (unsigned long)pOptDesc->optArg.argIntptr ); + snprintf(zVal, sizeof(zVal), "%lu", + (unsigned long)pOptDesc->optArg.argIntptr); pzDefault = zVal; break; @@ -728,99 +743,99 @@ emitSetup( tOptions* pOpts ) pzDefault = pOptDesc->optArg.argString; } - printf( pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault ); + printf(pzFmt, pOpts->pzPROGNAME, pOptDesc->pz_NAME, pzDefault); } } static void -printOptionAction( tOptions* pOpts, tOptDesc* pOptDesc ) +printOptionAction(tOptions* pOpts, tOptDesc* pOptDesc) { if (pOptDesc->pOptProc == optionPrintVersion) - printf( zTextExit, pOpts->pzPROGNAME, "VERSION" ); + printf(zTextExit, pOpts->pzPROGNAME, "VERSION"); else if (pOptDesc->pOptProc == optionPagedUsage) - printf( zPagedUsageExit, pOpts->pzPROGNAME ); + printf(zPagedUsageExit, pOpts->pzPROGNAME); else if (pOptDesc->pOptProc == optionLoadOpt) { - printf( zCmdFmt, "echo 'Warning: Cannot load options files' >&2" ); - printf( zCmdFmt, "OPT_ARG_NEEDED=YES" ); + printf(zCmdFmt, "echo 'Warning: Cannot load options files' >&2"); + printf(zCmdFmt, "OPT_ARG_NEEDED=YES"); } else if (pOptDesc->pz_NAME == NULL) { if (pOptDesc->pOptProc == NULL) { - printf( zCmdFmt, "echo 'Warning: Cannot save options files' " - ">&2" ); - printf( zCmdFmt, "OPT_ARG_NEEDED=OK" ); + printf(zCmdFmt, "echo 'Warning: Cannot save options files' " + ">&2"); + printf(zCmdFmt, "OPT_ARG_NEEDED=OK"); } else - printf( zTextExit, pOpts->pzPROGNAME, "LONGUSAGE" ); + printf(zTextExit, pOpts->pzPROGNAME, "LONGUSAGE"); } else { if (pOptDesc->optMaxCt == 1) - printf( zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zSingleArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); else { if ((unsigned)pOptDesc->optMaxCt < NOLIMIT) - printf( zCountTest, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->optMaxCt ); + printf(zCountTest, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->optMaxCt); - printf( zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zMultiArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } /* * Fix up the args. */ if (OPTST_GET_ARGTYPE(pOptDesc->fOptState) == OPARG_TYPE_NONE) { - printf( zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zCantArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } else if (pOptDesc->fOptState & OPTST_ARG_OPTIONAL) { - printf( zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME ); + printf(zMayArg, pOpts->pzPROGNAME, pOptDesc->pz_NAME); } else { - fputs( zMustArg, stdout ); + fputs(zMustArg, stdout); } } - fputs( zOptionEndSelect, stdout ); + fputs(zOptionEndSelect, stdout); } static void -printOptionInaction( tOptions* pOpts, tOptDesc* pOptDesc ) +printOptionInaction(tOptions* pOpts, tOptDesc* pOptDesc) { if (pOptDesc->pOptProc == optionLoadOpt) { - printf( zCmdFmt, "echo 'Warning: Cannot suppress the loading of " - "options files' >&2" ); + printf(zCmdFmt, "echo 'Warning: Cannot suppress the loading of " + "options files' >&2"); } else if (pOptDesc->optMaxCt == 1) - printf( zNoSingleArg, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx ); + printf(zNoSingleArg, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); else - printf( zNoMultiArg, pOpts->pzPROGNAME, - pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx ); + printf(zNoMultiArg, pOpts->pzPROGNAME, + pOptDesc->pz_NAME, pOptDesc->pz_DisablePfx); - printf( zCmdFmt, "OPT_ARG_NEEDED=NO" ); - fputs( zOptionEndSelect, stdout ); + printf(zCmdFmt, "OPT_ARG_NEEDED=NO"); + fputs(zOptionEndSelect, stdout); } static void -emitFlag( tOptions* pOpts ) +emitFlag(tOptions* pOpts) { tOptDesc* pOptDesc = pOpts->pOptDesc; int optionCt = pOpts->optCt; - fputs( zOptionCase, stdout ); + fputs(zOptionCase, stdout); for (;optionCt > 0; pOptDesc++, --optionCt) { if (SKIP_OPT(pOptDesc)) continue; - if (isprint( pOptDesc->optValue )) { - printf( zOptionFlag, pOptDesc->optValue ); - printOptionAction( pOpts, pOptDesc ); + if (IS_GRAPHIC_CHAR(pOptDesc->optValue)) { + printf(zOptionFlag, pOptDesc->optValue); + printOptionAction(pOpts, pOptDesc); } } - printf( zOptionUnknown, "flag", pOpts->pzPROGNAME ); + printf(zOptionUnknown, "flag", pOpts->pzPROGNAME); } @@ -828,7 +843,7 @@ emitFlag( tOptions* pOpts ) * Emit the match text for a long option */ static void -emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) +emitMatchExpr(tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts) { tOptDesc* pOD = pOpts->pOptDesc; int oCt = pOpts->optCt; @@ -854,8 +869,8 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) * They must not be the same. They cannot be, because it would * not compile correctly if they were. */ - while ( toupper( pOD->pz_Name[matchCt] ) - == toupper( pzMatchName[matchCt] )) + while ( toupper(pOD->pz_Name[matchCt]) + == toupper(pzMatchName[matchCt])) matchCt++; if (matchCt > min) @@ -866,8 +881,8 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) */ if (pOD->pz_DisableName != NULL) { matchCt = 0; - while ( toupper( pOD->pz_DisableName[matchCt] ) - == toupper( pzMatchName[matchCt] )) + while ( toupper(pOD->pz_DisableName[matchCt]) + == toupper(pzMatchName[matchCt])) matchCt++; if (matchCt > min) min = matchCt; @@ -883,7 +898,7 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) */ if ( (pzMatchName[min ] == NUL) || (pzMatchName[min+1] == NUL) ) - printf( zOptionFullName, pzMatchName ); + printf(zOptionFullName, pzMatchName); else { int matchCt = 0; @@ -892,11 +907,11 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) for (;;) { *pz = NUL; - printf( zOptionPartName, zName ); + printf(zOptionPartName, zName); *pz++ = pzMatchName[matchCt++]; if (pzMatchName[matchCt] == NUL) { *pz = NUL; - printf( zOptionFullName, zName ); + printf(zOptionFullName, zName); break; } } @@ -908,12 +923,12 @@ emitMatchExpr( tCC* pzMatchName, tOptDesc* pCurOpt, tOptions* pOpts ) * Emit GNU-standard long option handling code */ static void -emitLong( tOptions* pOpts ) +emitLong(tOptions* pOpts) { tOptDesc* pOD = pOpts->pOptDesc; int ct = pOpts->optCt; - fputs( zOptionCase, stdout ); + fputs(zOptionCase, stdout); /* * do each option, ... @@ -925,24 +940,24 @@ emitLong( tOptions* pOpts ) if (SKIP_OPT(pOD)) continue; - emitMatchExpr( pOD->pz_Name, pOD, pOpts ); - printOptionAction( pOpts, pOD ); + emitMatchExpr(pOD->pz_Name, pOD, pOpts); + printOptionAction(pOpts, pOD); /* * Now, do the same thing for the disablement version of the option. */ if (pOD->pz_DisableName != NULL) { - emitMatchExpr( pOD->pz_DisableName, pOD, pOpts ); - printOptionInaction( pOpts, pOD ); + emitMatchExpr(pOD->pz_DisableName, pOD, pOpts); + printOptionInaction(pOpts, pOD); } } while (pOD++, --ct > 0); - printf( zOptionUnknown, "option", pOpts->pzPROGNAME ); + printf(zOptionUnknown, "option", pOpts->pzPROGNAME); } static void -openOutput( char const* pzFile ) +openOutput(char const* pzFile) { FILE* fp; char* pzData = NULL; @@ -957,19 +972,19 @@ openOutput( char const* pzFile ) * THEN assume we are creating a new file. * Skip the loading of the old data. */ - if (stat( pzFile, &stbf ) != 0) + if (stat(pzFile, &stbf) != 0) break; /* * The file must be a regular file */ - if (! S_ISREG( stbf.st_mode )) { - fprintf( stderr, zNotFile, pzFile ); - exit( EXIT_FAILURE ); + if (! S_ISREG(stbf.st_mode)) { + fprintf(stderr, zNotFile, pzFile); + exit(EXIT_FAILURE); } pzData = AGALOC(stbf.st_size + 1, "file data"); - fp = fopen( pzFile, "r" FOPEN_BINARY_FLAG ); + fp = fopen(pzFile, "r" FOPEN_BINARY_FLAG); sizeLeft = (unsigned)stbf.st_size; pzScan = pzData; @@ -978,7 +993,7 @@ openOutput( char const* pzFile ) * Read in all the data as fast as our OS will let us. */ for (;;) { - int inct = fread( (void*)pzScan, (size_t)1, sizeLeft, fp); + int inct = fread((void*)pzScan, (size_t)1, sizeLeft, fp); if (inct == 0) break; @@ -993,29 +1008,32 @@ openOutput( char const* pzFile ) * NUL-terminate the leader and look for the trailer */ *pzScan = '\0'; - fclose( fp ); - pzScan = strstr( pzData, zStartMarker ); + fclose(fp); + pzScan = strstr(pzData, zStartMarker); if (pzScan == NULL) { pzTrailer = pzData; break; } *(pzScan++) = NUL; - pzScan = strstr( pzScan, zTrailerMarker ); + pzScan = strstr(pzScan, zTrailerMarker); if (pzScan == NULL) { pzTrailer = pzData; break; } /* - * Check to see if the data contains - * our marker. If it does, then we will skip over it + * Check to see if the data contains our marker. + * If it does, then we will skip over it */ - pzTrailer = pzScan + sizeof( zTrailerMarker ) - 1; + pzTrailer = pzScan + sizeof(zTrailerMarker) - 1; pzLeader = pzData; } while (AG_FALSE); - freopen( pzFile, "w" FOPEN_BINARY_FLAG, stdout ); + if (freopen(pzFile, "w" FOPEN_BINARY_FLAG, stdout) != stdout) { + fprintf(stderr, zFreopenFail, errno, strerror(errno)); + exit(EXIT_FAILURE); + } } @@ -1034,19 +1052,21 @@ openOutput( char const* pzFile ) * and create shell script variables containing the two types of text. =*/ void -genshelloptUsage( tOptions* pOpts, int exitCode ) +genshelloptUsage(tOptions * pOpts, int exitCode) { -#if defined(__windows__) && !defined(__CYGWIN__) - optionUsage( pOpts, exitCode ); +#if ! defined(HAVE_WORKING_FORK) + optionUsage(pOpts, exitCode); #else /* * IF not EXIT_SUCCESS, * THEN emit the short form of usage. */ if (exitCode != EXIT_SUCCESS) - optionUsage( pOpts, exitCode ); - fflush( stderr ); - fflush( stdout ); + optionUsage(pOpts, exitCode); + fflush(stderr); + fflush(stdout); + if (ferror(stdout) || ferror(stderr)) + exit(EXIT_FAILURE); option_usage_fp = stdout; @@ -1055,20 +1075,19 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) */ switch (fork()) { case -1: - optionUsage( pOpts, EXIT_FAILURE ); - /*NOTREACHED*/ - _exit( EXIT_FAILURE ); + optionUsage(pOpts, EXIT_FAILURE); + /* NOTREACHED */ case 0: pagerState = PAGER_STATE_CHILD; - optionUsage( pOpts, EXIT_SUCCESS ); - /*NOTREACHED*/ - _exit( EXIT_FAILURE ); + optionUsage(pOpts, EXIT_SUCCESS); + /* NOTREACHED */ + _exit(EXIT_FAILURE); default: { int sts; - wait( &sts ); + wait(&sts); } } @@ -1077,11 +1096,12 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) * gets it from the command line */ { - char* pz; - AGDUPSTR( pz, pShellParseOptions->pzPROGNAME, "program name" ); - pShellParseOptions->pzProgName = pz; + char * pz; + char ** pp = (char **)(void *)&(optionParseShellOptions->pzProgName); + AGDUPSTR(pz, optionParseShellOptions->pzPROGNAME, "program name"); + *pp = pz; while (*pz != NUL) { - *pz = tolower( *pz ); + *pz = tolower(*pz); pz++; } } @@ -1089,8 +1109,8 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) /* * Separate the makeshell usage from the client usage */ - fprintf( option_usage_fp, zGenshell, pShellParseOptions->pzProgName ); - fflush( option_usage_fp ); + fprintf(option_usage_fp, zGenshell, optionParseShellOptions->pzProgName); + fflush(option_usage_fp); /* * Now, print the client usage. @@ -1100,16 +1120,22 @@ genshelloptUsage( tOptions* pOpts, int exitCode ) pagerState = PAGER_STATE_CHILD; /*FALLTHROUGH*/ case -1: - optionUsage( pShellParseOptions, EXIT_FAILURE ); + optionUsage(optionParseShellOptions, EXIT_FAILURE); default: { int sts; - wait( &sts ); + wait(&sts); } } - exit( EXIT_SUCCESS ); + fflush(stdout); + if (ferror(stdout)) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } + + exit(EXIT_SUCCESS); #endif } diff --git a/sntp/libopts/nested.c b/sntp/libopts/nested.c index b39f8d1faddb..f9f7e7ae7b80 100644 --- a/sntp/libopts/nested.c +++ b/sntp/libopts/nested.c @@ -1,122 +1,123 @@ -/* - * $Id: nested.c,v 4.14 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-26 11:04:35 bkorb" +/** + * \file nested.c * - * Automated Options Nested Values module. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. + * Time-stamp: "2010-08-22 11:17:56 bkorb" * - * Automated Options 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. + * Automated Options Nested Values module. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ + +typedef struct { + int xml_ch; + int xml_len; + char xml_txt[8]; +} xml_xlate_t; + +static xml_xlate_t const xml_xlate[] = { + { '&', 4, "amp;" }, + { '<', 3, "lt;" }, + { '>', 3, "gt;" }, + { '"', 5, "quot;" }, + { '\'',5, "apos;" } +}; + /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -removeBackslashes( char* pzSrc ); +remove_continuation(char* pzSrc); static char const* -scanQuotedString( char const* pzTxt ); +scan_q_str(char const* pzTxt); static tOptionValue* -addStringValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_string(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addBoolValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_bool(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addNumberValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ); +add_number(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen); static tOptionValue* -addNestedValue( void** pp, char const* pzName, size_t nameLen, - char* pzValue, size_t dataLen ); +add_nested(void** pp, char const* pzName, size_t nameLen, + char* pzValue, size_t dataLen); -static char const* -scanNameEntry(char const* pzName, tOptionValue* pRes); +static char const * +scan_name(char const* pzName, tOptionValue* pRes); static char const* -scanXmlEntry( char const* pzName, tOptionValue* pRes ); - -static void -unloadNestedArglist( tArgList* pAL ); +scan_xml(char const* pzName, tOptionValue* pRes); static void -sortNestedList( tArgList* pAL ); +sort_list(tArgList* pAL); /* = = = END-STATIC-FORWARD = = = */ -/* removeBackslashes - * - * This function assumes that all newline characters were preceeded by - * backslashes that need removal. +/** + * Backslashes are used for line continuations. We keep the newline + * characters, but trim out the backslash: */ static void -removeBackslashes( char* pzSrc ) +remove_continuation(char* pzSrc) { - char* pzD = strchr(pzSrc, '\n'); + char* pzD; - if (pzD == NULL) - return; - *--pzD = '\n'; + do { + while (*pzSrc == '\n') pzSrc++; + pzD = strchr(pzSrc, '\n'); + if (pzD == NULL) + return; + /* + * pzD has skipped at least one non-newline character and now + * points to a newline character. It now becomes the source and + * pzD goes to the previous character. + */ + pzSrc = pzD--; + if (*pzD != '\\') + pzD++; + } while (pzD == pzSrc); + + /* + * Start shifting text. + */ for (;;) { char ch = ((*pzD++) = *(pzSrc++)); switch (ch) { - case '\n': *--pzD = ch; break; case NUL: return; - default: - ; + case '\\': + if (*pzSrc == '\n') + --pzD; /* rewrite on next iteration */ } } } - -/* scanQuotedString - * +/** * Find the end of a quoted string, skipping escaped quote characters. */ static char const* -scanQuotedString( char const* pzTxt ) +scan_q_str(char const* pzTxt) { char q = *(pzTxt++); /* remember the type of quote */ @@ -149,18 +150,17 @@ scanQuotedString( char const* pzTxt ) } -/* addStringValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addStringValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_string(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + dataLen + sizeof(*pNV); - pNV = AGALOC( sz, "option name/str value pair" ); + pNV = AGALOC(sz, "option name/str value pair"); if (pNV == NULL) return NULL; @@ -170,178 +170,173 @@ addStringValue( void** pp, char const* pzName, size_t nameLen, } else { pNV->valType = OPARG_TYPE_STRING; - if (dataLen > 0) - memcpy( pNV->v.strVal, pzValue, dataLen ); - pNV->v.strVal[dataLen] = NUL; + if (dataLen > 0) { + char const * pzSrc = pzValue; + char * pzDst = pNV->v.strVal; + int ct = dataLen; + do { + int ch = *(pzSrc++) & 0xFF; + if (ch == NUL) goto data_copy_done; + if (ch == '&') + ch = get_special_char(&pzSrc, &ct); + *(pzDst++) = ch; + } while (--ct > 0); + data_copy_done: + *pzDst = NUL; + + } else { + pNV->v.strVal[0] = NUL; + } + pNV->pzName = pNV->v.strVal + dataLen + 1; } - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addBoolValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addBoolValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_bool(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "option name/bool value pair" ); + pNV = AGALOC(sz, "option name/bool value pair"); if (pNV == NULL) return NULL; - while (isspace( (int)*pzValue ) && (dataLen > 0)) { + while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) { dataLen--; pzValue++; } if (dataLen == 0) pNV->v.boolVal = 0; - else if (isdigit( (int)*pzValue )) - pNV->v.boolVal = atoi( pzValue ); - else switch (*pzValue) { - case 'f': - case 'F': - case 'n': - case 'N': - pNV->v.boolVal = 0; break; - default: - pNV->v.boolVal = 1; - } + + else if (IS_DEC_DIGIT_CHAR(*pzValue)) + pNV->v.boolVal = atoi(pzValue); + + else pNV->v.boolVal = ! IS_FALSE_TYPE_CHAR(*pzValue); pNV->valType = OPARG_TYPE_BOOLEAN; pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addNumberValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addNumberValue( void** pp, char const* pzName, size_t nameLen, - char const* pzValue, size_t dataLen ) +add_number(void** pp, char const* pzName, size_t nameLen, + char const* pzValue, size_t dataLen) { tOptionValue* pNV; size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "option name/bool value pair" ); + pNV = AGALOC(sz, "option name/bool value pair"); if (pNV == NULL) return NULL; - while (isspace( (int)*pzValue ) && (dataLen > 0)) { + while (IS_WHITESPACE_CHAR(*pzValue) && (dataLen > 0)) { dataLen--; pzValue++; } if (dataLen == 0) - pNV->v.boolVal = 0; + pNV->v.longVal = 0; else - pNV->v.boolVal = atoi( pzValue ); + pNV->v.longVal = strtol(pzValue, 0, 0); pNV->valType = OPARG_TYPE_NUMERIC; - pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + pNV->pzName = (char*)(pNV + 1); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* addNestedValue - * +/** * Associate a name with either a string or no value. */ static tOptionValue* -addNestedValue( void** pp, char const* pzName, size_t nameLen, - char* pzValue, size_t dataLen ) +add_nested(void** pp, char const* pzName, size_t nameLen, + char* pzValue, size_t dataLen) { tOptionValue* pNV; if (dataLen == 0) { size_t sz = nameLen + sizeof(*pNV) + 1; - pNV = AGALOC( sz, "empty nested value pair" ); + pNV = AGALOC(sz, "empty nested value pair"); if (pNV == NULL) return NULL; pNV->v.nestVal = NULL; pNV->valType = OPARG_TYPE_HIERARCHY; pNV->pzName = (char*)(pNV + 1); - memcpy( pNV->pzName, pzName, nameLen ); + memcpy(pNV->pzName, pzName, nameLen); pNV->pzName[ nameLen ] = NUL; } else { - pNV = optionLoadNested( pzValue, pzName, nameLen ); + pNV = optionLoadNested(pzValue, pzName, nameLen); } if (pNV != NULL) - addArgListEntry( pp, pNV ); + addArgListEntry(pp, pNV); return pNV; } - -/* scanNameEntry - * +/** * We have an entry that starts with a name. Find the end of it, cook it * (if called for) and create the name/value association. */ -static char const* -scanNameEntry(char const* pzName, tOptionValue* pRes) +static char const * +scan_name(char const* pzName, tOptionValue* pRes) { tOptionValue* pNV; - char const * pzScan = pzName+1; + char const * pzScan = pzName+1; /* we know first char is a name char */ char const * pzVal; size_t nameLen = 1; size_t dataLen = 0; - while (ISNAMECHAR( (int)*pzScan )) { pzScan++; nameLen++; } + /* + * Scan over characters that name a value. These names may not end + * with a colon, but they may contain colons. + */ + while (IS_VALUE_NAME_CHAR(*pzScan)) { pzScan++; nameLen++; } + if (pzScan[-1] == ':') { pzScan--; nameLen--; } + while (IS_HORIZ_WHITE_CHAR(*pzScan)) pzScan++; - while (isspace( (int)*pzScan )) { - char ch = *(pzScan++); - if ((ch == '\n') || (ch == ',')) { - addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL,(size_t)0); - return pzScan - 1; - } - } + re_switch: switch (*pzScan) { case '=': case ':': - while (isspace( (int)*++pzScan )) ; - switch (*pzScan) { - case ',': goto comma_char; - case '"': - case '\'': goto quote_char; - case NUL: goto nul_byte; - default: goto default_char; - } + while (IS_HORIZ_WHITE_CHAR((int)*++pzScan)) ; + if ((*pzScan == '=') || (*pzScan == ':')) + goto default_char; + goto re_switch; + case '\n': case ',': - comma_char: pzScan++; /* FALLTHROUGH */ case NUL: - nul_byte: - addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); break; case '"': case '\'': - quote_char: pzVal = pzScan; - pzScan = scanQuotedString( pzScan ); + pzScan = scan_q_str(pzScan); dataLen = pzScan - pzVal; - pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, - dataLen ); + pNV = add_string(&(pRes->v.nestVal), pzName, nameLen, pzVal, + dataLen); if ((pNV != NULL) && (option_load_mode == OPTION_LOAD_COOKED)) - ao_string_cook( pNV->v.strVal, NULL ); + ao_string_cook(pNV->v.strVal, NULL); break; default: @@ -370,10 +365,10 @@ scanNameEntry(char const* pzName, tOptionValue* pRes) case ',': dataLen = (pzScan - pzVal) - 1; string_done: - pNV = addStringValue( &(pRes->v.nestVal), pzName, nameLen, - pzVal, dataLen ); + pNV = add_string(&(pRes->v.nestVal), pzName, nameLen, + pzVal, dataLen); if (pNV != NULL) - removeBackslashes( pNV->v.strVal ); + remove_continuation(pNV->v.strVal); goto leave_scan_name; } } @@ -383,15 +378,13 @@ scanNameEntry(char const* pzName, tOptionValue* pRes) return pzScan; } - -/* scanXmlEntry - * +/** * We've found a '<' character. We ignore this if it is a comment or a * directive. If it is something else, then whatever it is we are looking * at is bogus. Returning NULL stops processing. */ static char const* -scanXmlEntry( char const* pzName, tOptionValue* pRes ) +scan_xml(char const* pzName, tOptionValue* pRes) { size_t nameLen = 1, valLen = 0; char const* pzScan = ++pzName; @@ -400,20 +393,20 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) tOptionValue* pNewVal; tOptionLoadMode save_mode = option_load_mode; - if (! isalpha((int)*pzName)) { + if (! IS_VAR_FIRST_CHAR(*pzName)) { switch (*pzName) { default: pzName = NULL; break; case '!': - pzName = strstr( pzName, "-->" ); + pzName = strstr(pzName, "-->"); if (pzName != NULL) pzName += 3; break; case '?': - pzName = strchr( pzName, '>' ); + pzName = strchr(pzName, '>'); if (pzName != NULL) pzName++; break; @@ -421,7 +414,8 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) return pzName; } - while (isalpha( (int)*++pzScan )) nameLen++; + pzScan++; + while (IS_VALUE_NAME_CHAR((int)*pzScan)) { pzScan++; nameLen++; } if (nameLen > 64) return NULL; valu.valType = OPARG_TYPE_STRING; @@ -447,9 +441,9 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) option_load_mode = save_mode; return NULL; } - addStringValue(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); option_load_mode = save_mode; - return pzScan+2; + return pzScan+1; default: option_load_mode = save_mode; @@ -477,46 +471,46 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) *(pzD++) = '>'; *pzD = NUL; - pzScan = strstr( pzScan, z ); + pzScan = strstr(pzScan, z); if (pzScan == NULL) { option_load_mode = save_mode; return NULL; } valLen = (pzScan - pzVal); pzScan += nameLen + 3; - while (isspace( (int)*pzScan )) pzScan++; + while (IS_WHITESPACE_CHAR(*pzScan)) pzScan++; } switch (valu.valType) { case OPARG_TYPE_NONE: - addStringValue( &(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); + add_string(&(pRes->v.nestVal), pzName, nameLen, NULL, (size_t)0); break; case OPARG_TYPE_STRING: - pNewVal = addStringValue( + pNewVal = add_string( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); if (option_load_mode == OPTION_LOAD_KEEP) break; - mungeString( pNewVal->v.strVal, option_load_mode ); + mungeString(pNewVal->v.strVal, option_load_mode); break; case OPARG_TYPE_BOOLEAN: - addBoolValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen ); + add_bool(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); break; case OPARG_TYPE_NUMERIC: - addNumberValue( &(pRes->v.nestVal), pzName, nameLen, pzVal, valLen ); + add_number(&(pRes->v.nestVal), pzName, nameLen, pzVal, valLen); break; case OPARG_TYPE_HIERARCHY: { - char* pz = AGALOC( valLen+1, "hierarchical scan" ); + char* pz = AGALOC(valLen+1, "hierarchical scan"); if (pz == NULL) break; - memcpy( pz, pzVal, valLen ); + memcpy(pz, pzVal, valLen); pz[valLen] = NUL; - addNestedValue( &(pRes->v.nestVal), pzName, nameLen, pz, valLen ); + add_nested(&(pRes->v.nestVal), pzName, nameLen, pz, valLen); AGFREE(pz); break; } @@ -532,15 +526,14 @@ scanXmlEntry( char const* pzName, tOptionValue* pRes ) } -/* unloadNestedArglist - * +/** * Deallocate a list of option arguments. This must have been gotten from * a hierarchical option argument, not a stacked list of strings. It is * an internal call, so it is not validated. The caller is responsible for * knowing what they are doing. */ -static void -unloadNestedArglist( tArgList* pAL ) +LOCAL void +unload_arg_list(tArgList* pAL) { int ct = pAL->useCt; tCC** ppNV = pAL->apzArgs; @@ -548,14 +541,13 @@ unloadNestedArglist( tArgList* pAL ) while (ct-- > 0) { tOptionValue* pNV = (tOptionValue*)(void*)*(ppNV++); if (pNV->valType == OPARG_TYPE_HIERARCHY) - unloadNestedArglist( pNV->v.nestVal ); - AGFREE( pNV ); + unload_arg_list(pNV->v.nestVal); + AGFREE(pNV); } - AGFREE( (void*)pAL ); + AGFREE((void*)pAL); } - /*=export_func optionUnloadNested * * what: Deallocate the memory for a nested value @@ -567,7 +559,7 @@ unloadNestedArglist( tArgList* pAL ) * @pxref{libopts-configFileLoad}). =*/ void -optionUnloadNested( tOptionValue const * pOV ) +optionUnloadNested(tOptionValue const * pOV) { if (pOV == NULL) return; if (pOV->valType != OPARG_TYPE_HIERARCHY) { @@ -575,20 +567,18 @@ optionUnloadNested( tOptionValue const * pOV ) return; } - unloadNestedArglist( pOV->v.nestVal ); + unload_arg_list(pOV->v.nestVal); - AGFREE( (void*)pOV ); + AGFREE((void*)pOV); } - -/* sortNestedList - * +/** * This is a _stable_ sort. The entries are sorted alphabetically, * but within entries of the same name the ordering is unchanged. * Typically, we also hope the input is sorted. */ static void -sortNestedList( tArgList* pAL ) +sort_list(tArgList* pAL) { int ix; int lm = pAL->useCt; @@ -606,7 +596,7 @@ sortNestedList( tArgList* pAL ) * move the old pointer. Stop before trying to extract the * "-1" entry. */ - while (strcmp( pOldNV->pzName, pNewNV->pzName ) > 0) { + while (strcmp(pOldNV->pzName, pNewNV->pzName) > 0) { pAL->apzArgs[iy+1] = (void*)pOldNV; pOldNV = (tOptionValue*)(void*)(pAL->apzArgs[--iy]); if (iy < 0) @@ -621,7 +611,6 @@ sortNestedList( tArgList* pAL ) } } - /* optionLoadNested * private: * @@ -642,7 +631,6 @@ LOCAL tOptionValue* optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen) { tOptionValue* pRes; - tArgList* pAL; /* * Make sure we have some data and we have space to put what we find. @@ -651,60 +639,65 @@ optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen) errno = EINVAL; return NULL; } - while (isspace( (int)*pzTxt )) pzTxt++; + while (IS_WHITESPACE_CHAR(*pzTxt)) pzTxt++; if (*pzTxt == NUL) { errno = ENOENT; return NULL; } - pRes = AGALOC( sizeof(*pRes) + nameLen + 1, "nested args" ); + pRes = AGALOC(sizeof(*pRes) + nameLen + 1, "nested args"); if (pRes == NULL) { errno = ENOMEM; return NULL; } pRes->valType = OPARG_TYPE_HIERARCHY; pRes->pzName = (char*)(pRes + 1); - memcpy( pRes->pzName, pzName, nameLen ); - pRes->pzName[ nameLen ] = NUL; + memcpy(pRes->pzName, pzName, nameLen); + pRes->pzName[nameLen] = NUL; - pAL = AGALOC( sizeof(*pAL), "nested arg list" ); - if (pAL == NULL) { - AGFREE( pRes ); - return NULL; + { + tArgList * pAL = AGALOC(sizeof(*pAL), "nested arg list"); + if (pAL == NULL) { + AGFREE(pRes); + return NULL; + } + + pRes->v.nestVal = pAL; + pAL->useCt = 0; + pAL->allocCt = MIN_ARG_ALLOC_CT; } - pRes->v.nestVal = pAL; - pAL->useCt = 0; - pAL->allocCt = MIN_ARG_ALLOC_CT; /* * Scan until we hit a NUL. */ do { - while (isspace( (int)*pzTxt )) pzTxt++; - if (isalpha( (int)*pzTxt )) { - pzTxt = scanNameEntry( pzTxt, pRes ); + while (IS_WHITESPACE_CHAR((int)*pzTxt)) pzTxt++; + if (IS_VAR_FIRST_CHAR((int)*pzTxt)) { + pzTxt = scan_name(pzTxt, pRes); } else switch (*pzTxt) { case NUL: goto scan_done; - case '<': pzTxt = scanXmlEntry( pzTxt, pRes ); + case '<': pzTxt = scan_xml(pzTxt, pRes); + if (pzTxt == NULL) goto woops; if (*pzTxt == ',') pzTxt++; break; - case '#': pzTxt = strchr( pzTxt, '\n' ); break; + case '#': pzTxt = strchr(pzTxt, '\n'); break; default: goto woops; } } while (pzTxt != NULL); scan_done:; - pAL = pRes->v.nestVal; - if (pAL->useCt != 0) { - sortNestedList( pAL ); - return pRes; + { + tArgList * al = pRes->v.nestVal; + if (al->useCt != 0) + sort_list(al); } + return pRes; + woops: - AGFREE( pRes->v.nestVal ); - AGFREE( pRes ); + AGFREE(pRes->v.nestVal); + AGFREE(pRes); return NULL; } - /*=export_func optionNestedVal * private: * @@ -716,14 +709,111 @@ optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen) * Nested value was found on the command line =*/ void -optionNestedVal( tOptions* pOpts, tOptDesc* pOD ) +optionNestedVal(tOptions* pOpts, tOptDesc* pOD) { - tOptionValue* pOV = optionLoadNested( - pOD->optArg.argString, pOD->pz_Name, strlen(pOD->pz_Name)); + if (pOpts < OPTPROC_EMIT_LIMIT) + return; - if (pOV != NULL) - addArgListEntry( &(pOD->optCookie), (void*)pOV ); + if (pOD->fOptState & OPTST_RESET) { + tArgList* pAL = pOD->optCookie; + int ct; + tCC ** av; + + if (pAL == NULL) + return; + ct = pAL->useCt; + av = pAL->apzArgs; + + while (--ct >= 0) { + void * p = (void *)*(av++); + optionUnloadNested((tOptionValue const *)p); + } + + AGFREE(pOD->optCookie); + + } else { + tOptionValue* pOV = optionLoadNested( + pOD->optArg.argString, pOD->pz_Name, strlen(pOD->pz_Name)); + + if (pOV != NULL) + addArgListEntry(&(pOD->optCookie), (void*)pOV); + } } + +/* + * get_special_char + */ +LOCAL int +get_special_char(char const ** ppz, int * ct) +{ + char const * pz = *ppz; + + if (*ct < 3) + return '&'; + + if (*pz == '#') { + int base = 10; + int retch; + + pz++; + if (*pz == 'x') { + base = 16; + pz++; + } + retch = (int)strtoul(pz, (char **)&pz, base); + if (*pz != ';') + return '&'; + base = ++pz - *ppz; + if (base > *ct) + return '&'; + + *ct -= base; + *ppz = pz; + return retch; + } + + { + int ctr = sizeof(xml_xlate) / sizeof(xml_xlate[0]); + xml_xlate_t const * xlatp = xml_xlate; + + for (;;) { + if ( (*ct >= xlatp->xml_len) + && (strncmp(pz, xlatp->xml_txt, xlatp->xml_len) == 0)) { + *ppz += xlatp->xml_len; + *ct -= xlatp->xml_len; + return xlatp->xml_ch; + } + + if (--ctr <= 0) + break; + xlatp++; + } + } + return '&'; +} + +/* + * emit_special_char + */ +LOCAL void +emit_special_char(FILE * fp, int ch) +{ + int ctr = sizeof(xml_xlate) / sizeof(xml_xlate[0]); + xml_xlate_t const * xlatp = xml_xlate; + + putc('&', fp); + for (;;) { + if (ch == xlatp->xml_ch) { + fputs(xlatp->xml_txt, fp); + return; + } + if (--ctr <= 0) + break; + xlatp++; + } + fprintf(fp, "#x%02X;", (ch & 0xFF)); +} + /* * Local Variables: * mode: C diff --git a/sntp/libopts/numeric.c b/sntp/libopts/numeric.c index 05ee9b573e57..ff6b2a50f279 100644 --- a/sntp/libopts/numeric.c +++ b/sntp/libopts/numeric.c @@ -1,56 +1,100 @@ -/* - * $Id: numeric.c,v 4.11 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 10:28:20 bkorb" - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. +/** + * \file numeric.c * - * Automated Options 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. + * Time-stamp: "2011-03-25 16:26:10 bkorb" * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ +/*=export_func optionShowRange + * private: + * + * what: + * arg: + tOptions* + pOpts + program options descriptor + + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * arg: + void * + rng_table + the value range tables + + * arg: + int + rng_count + the number of entries + + * + * doc: + * Show information about a numeric option with range constraints. +=*/ +void +optionShowRange(tOptions* pOpts, tOptDesc* pOD, void * rng_table, int rng_ct) +{ + static char const bullet[] = "\t\t\t\t- "; + static char const deepin[] = "\t\t\t\t "; + static char const onetab[] = "\t"; + + const struct {long const rmin, rmax;} * rng = rng_table; + + char const * pz_indent = bullet; + + /* + * The range is shown only for full usage requests and an error + * in this particular option. + */ + if (pOpts != OPTPROC_EMIT_USAGE) { + if (pOpts <= OPTPROC_EMIT_LIMIT) + return; + pz_indent = onetab; + + fprintf(option_usage_fp, zRangeErr, pOpts->pzProgName, + pOD->pz_Name, pOD->optArg.argString); + pz_indent = ""; + } + + if (pOD->fOptState & OPTST_SCALED_NUM) + fprintf(option_usage_fp, zRangeScaled, pz_indent); + + fprintf(option_usage_fp, (rng_ct > 1) ? zRangeLie : zRangeOnly, pz_indent); + pz_indent = (pOpts != OPTPROC_EMIT_USAGE) ? onetab : deepin; + + for (;;) { + if (rng->rmax == LONG_MIN) + fprintf(option_usage_fp, zRangeExact, pz_indent, rng->rmin); + else if (rng->rmin == LONG_MIN) + fprintf(option_usage_fp, zRangeUpto, pz_indent, rng->rmax); + else if (rng->rmax == LONG_MAX) + fprintf(option_usage_fp, zRangeAbove, pz_indent, rng->rmin); + else + fprintf(option_usage_fp, zRange, pz_indent, rng->rmin, + rng->rmax); + + if (--rng_ct <= 0) { + fputc('\n', option_usage_fp); + break; + } + fputs(zRangeOr, option_usage_fp); + rng++; + } + + if (pOpts > OPTPROC_EMIT_LIMIT) + pOpts->pUsageProc(pOpts, EXIT_FAILURE); +} + /*=export_func optionNumericVal * private: * - * what: Decipher a boolean value + * what: process an option with a numeric value. * arg: + tOptions* + pOpts + program options descriptor + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + * @@ -58,7 +102,7 @@ * Decipher a numeric value. =*/ void -optionNumericVal( tOptions* pOpts, tOptDesc* pOD ) +optionNumericVal(tOptions* pOpts, tOptDesc* pOD ) { char* pz; long val; @@ -66,16 +110,37 @@ optionNumericVal( tOptions* pOpts, tOptDesc* pOD ) /* * Numeric options may have a range associated with it. * If it does, the usage procedure requests that it be - * emitted by passing a NULL pOD pointer. + * emitted by passing a NULL pOD pointer. Also bail out + * if there is no option argument or if we are being reset. */ - if ((pOD == NULL) || (pOD->optArg.argString == NULL)) + if ( (pOD == NULL) + || (pOD->optArg.argString == NULL) + || ((pOD->fOptState & OPTST_RESET) != 0)) return; - val = strtol( pOD->optArg.argString, &pz, 0 ); - if (*pz != NUL) { - fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString ); - (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); - } + errno = 0; + val = strtol(pOD->optArg.argString, &pz, 0); + if ((pz == pOD->optArg.argString) || (errno != 0)) + goto bad_number; + + if ((pOD->fOptState & OPTST_SCALED_NUM) != 0) + switch (*(pz++)) { + case '\0': pz--; break; + case 't': val *= 1000; + case 'g': val *= 1000; + case 'm': val *= 1000; + case 'k': val *= 1000; break; + + case 'T': val *= 1024; + case 'G': val *= 1024; + case 'M': val *= 1024; + case 'K': val *= 1024; break; + + default: goto bad_number; + } + + if (*pz != NUL) + goto bad_number; if (pOD->fOptState & OPTST_ALLOC_ARG) { AGFREE(pOD->optArg.argString); @@ -83,7 +148,18 @@ optionNumericVal( tOptions* pOpts, tOptDesc* pOD ) } pOD->optArg.argInt = val; + return; + + bad_number: + + fprintf( stderr, zNotNumber, pOpts->pzProgName, pOD->optArg.argString ); + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); + + errno = EINVAL; + pOD->optArg.argInt = ~0; } + /* * Local Variables: * mode: C diff --git a/sntp/libopts/parse-duration.c b/sntp/libopts/parse-duration.c new file mode 100644 index 000000000000..0a8c4ada8408 --- /dev/null +++ b/sntp/libopts/parse-duration.c @@ -0,0 +1,601 @@ +/* Parse a time duration and return a seconds count + Copyright (C) 2008-2011 Free Software Foundation, Inc. + Written by Bruce Korb <bkorb@gnu.org>, 2008. + + 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 3 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, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "parse-duration.h" + +#include <ctype.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef NUL +#define NUL '\0' +#endif + +#define cch_t char const + +typedef enum { + NOTHING_IS_DONE, + YEAR_IS_DONE, + MONTH_IS_DONE, + WEEK_IS_DONE, + DAY_IS_DONE, + HOUR_IS_DONE, + MINUTE_IS_DONE, + SECOND_IS_DONE +} whats_done_t; + +#define SEC_PER_MIN 60 +#define SEC_PER_HR (SEC_PER_MIN * 60) +#define SEC_PER_DAY (SEC_PER_HR * 24) +#define SEC_PER_WEEK (SEC_PER_DAY * 7) +#define SEC_PER_MONTH (SEC_PER_DAY * 30) +#define SEC_PER_YEAR (SEC_PER_DAY * 365) + +#define TIME_MAX 0x7FFFFFFF + +/* Wrapper around strtoul that does not require a cast. */ +static unsigned long inline +str_const_to_ul (cch_t * str, cch_t ** ppz, int base) +{ + return strtoul (str, (char **)ppz, base); +} + +/* Wrapper around strtol that does not require a cast. */ +static long inline +str_const_to_l (cch_t * str, cch_t ** ppz, int base) +{ + return strtol (str, (char **)ppz, base); +} + +/* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME + with errno set as an error situation, and returning BAD_TIME + with errno set in an error situation. */ +static time_t inline +scale_n_add (time_t base, time_t val, int scale) +{ + if (base == BAD_TIME) + { + if (errno == 0) + errno = EINVAL; + return BAD_TIME; + } + + if (val > TIME_MAX / scale) + { + errno = ERANGE; + return BAD_TIME; + } + + val *= scale; + if (base > TIME_MAX - val) + { + errno = ERANGE; + return BAD_TIME; + } + + return base + val; +} + +/* After a number HH has been parsed, parse subsequent :MM or :MM:SS. */ +static time_t +parse_hr_min_sec (time_t start, cch_t * pz) +{ + int lpct = 0; + + errno = 0; + + /* For as long as our scanner pointer points to a colon *AND* + we've not looped before, then keep looping. (two iterations max) */ + while ((*pz == ':') && (lpct++ <= 1)) + { + unsigned long v = str_const_to_ul (pz+1, &pz, 10); + + if (errno != 0) + return BAD_TIME; + + start = scale_n_add (v, start, 60); + + if (errno != 0) + return BAD_TIME; + } + + /* allow for trailing spaces */ + while (isspace ((unsigned char)*pz)) + pz++; + if (*pz != NUL) + { + errno = EINVAL; + return BAD_TIME; + } + + return start; +} + +/* Parses a value and returns BASE + value * SCALE, interpreting + BASE = BAD_TIME with errno set as an error situation, and returning + BAD_TIME with errno set in an error situation. */ +static time_t +parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale) +{ + cch_t * pz = *ppz; + time_t val; + + if (base == BAD_TIME) + return base; + + errno = 0; + val = str_const_to_ul (pz, &pz, 10); + if (errno != 0) + return BAD_TIME; + while (isspace ((unsigned char)*pz)) + pz++; + if (pz != endp) + { + errno = EINVAL; + return BAD_TIME; + } + + *ppz = pz; + return scale_n_add (base, val, scale); +} + +/* Parses the syntax YEAR-MONTH-DAY. + PS points into the string, after "YEAR", before "-MONTH-DAY". */ +static time_t +parse_year_month_day (cch_t * pz, cch_t * ps) +{ + time_t res = 0; + + res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR); + + pz++; /* over the first '-' */ + ps = strchr (pz, '-'); + if (ps == NULL) + { + errno = EINVAL; + return BAD_TIME; + } + res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH); + + pz++; /* over the second '-' */ + ps = pz + strlen (pz); + return parse_scaled_value (res, &pz, ps, SEC_PER_DAY); +} + +/* Parses the syntax YYYYMMDD. */ +static time_t +parse_yearmonthday (cch_t * in_pz) +{ + time_t res = 0; + char buf[8]; + cch_t * pz; + + if (strlen (in_pz) != 8) + { + errno = EINVAL; + return BAD_TIME; + } + + memcpy (buf, in_pz, 4); + buf[4] = NUL; + pz = buf; + res = parse_scaled_value (0, &pz, buf + 4, SEC_PER_YEAR); + + memcpy (buf, in_pz + 4, 2); + buf[2] = NUL; + pz = buf; + res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MONTH); + + memcpy (buf, in_pz + 6, 2); + buf[2] = NUL; + pz = buf; + return parse_scaled_value (res, &pz, buf + 2, SEC_PER_DAY); +} + +/* Parses the syntax yy Y mm M ww W dd D. */ +static time_t +parse_YMWD (cch_t * pz) +{ + time_t res = 0; + cch_t * ps = strchr (pz, 'Y'); + if (ps != NULL) + { + res = parse_scaled_value (0, &pz, ps, SEC_PER_YEAR); + pz++; + } + + ps = strchr (pz, 'M'); + if (ps != NULL) + { + res = parse_scaled_value (res, &pz, ps, SEC_PER_MONTH); + pz++; + } + + ps = strchr (pz, 'W'); + if (ps != NULL) + { + res = parse_scaled_value (res, &pz, ps, SEC_PER_WEEK); + pz++; + } + + ps = strchr (pz, 'D'); + if (ps != NULL) + { + res = parse_scaled_value (res, &pz, ps, SEC_PER_DAY); + pz++; + } + + while (isspace ((unsigned char)*pz)) + pz++; + if (*pz != NUL) + { + errno = EINVAL; + return BAD_TIME; + } + + return res; +} + +/* Parses the syntax HH:MM:SS. + PS points into the string, after "HH", before ":MM:SS". */ +static time_t +parse_hour_minute_second (cch_t * pz, cch_t * ps) +{ + time_t res = 0; + + res = parse_scaled_value (0, &pz, ps, SEC_PER_HR); + + pz++; + ps = strchr (pz, ':'); + if (ps == NULL) + { + errno = EINVAL; + return BAD_TIME; + } + + res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN); + + pz++; + ps = pz + strlen (pz); + return parse_scaled_value (res, &pz, ps, 1); +} + +/* Parses the syntax HHMMSS. */ +static time_t +parse_hourminutesecond (cch_t * in_pz) +{ + time_t res = 0; + char buf[4]; + cch_t * pz; + + if (strlen (in_pz) != 6) + { + errno = EINVAL; + return BAD_TIME; + } + + memcpy (buf, in_pz, 2); + buf[2] = NUL; + pz = buf; + res = parse_scaled_value (0, &pz, buf + 2, SEC_PER_HR); + + memcpy (buf, in_pz + 2, 2); + buf[2] = NUL; + pz = buf; + res = parse_scaled_value (res, &pz, buf + 2, SEC_PER_MIN); + + memcpy (buf, in_pz + 4, 2); + buf[2] = NUL; + pz = buf; + return parse_scaled_value (res, &pz, buf + 2, 1); +} + +/* Parses the syntax hh H mm M ss S. */ +static time_t +parse_HMS (cch_t * pz) +{ + time_t res = 0; + cch_t * ps = strchr (pz, 'H'); + if (ps != NULL) + { + res = parse_scaled_value (0, &pz, ps, SEC_PER_HR); + pz++; + } + + ps = strchr (pz, 'M'); + if (ps != NULL) + { + res = parse_scaled_value (res, &pz, ps, SEC_PER_MIN); + pz++; + } + + ps = strchr (pz, 'S'); + if (ps != NULL) + { + res = parse_scaled_value (res, &pz, ps, 1); + pz++; + } + + while (isspace ((unsigned char)*pz)) + pz++; + if (*pz != NUL) + { + errno = EINVAL; + return BAD_TIME; + } + + return res; +} + +/* Parses a time (hours, minutes, seconds) specification in either syntax. */ +static time_t +parse_time (cch_t * pz) +{ + cch_t * ps; + time_t res = 0; + + /* + * Scan for a hyphen + */ + ps = strchr (pz, ':'); + if (ps != NULL) + { + res = parse_hour_minute_second (pz, ps); + } + + /* + * Try for a 'H', 'M' or 'S' suffix + */ + else if (ps = strpbrk (pz, "HMS"), + ps == NULL) + { + /* Its a YYYYMMDD format: */ + res = parse_hourminutesecond (pz); + } + + else + res = parse_HMS (pz); + + return res; +} + +/* Returns a substring of the given string, with spaces at the beginning and at + the end destructively removed, per SNOBOL. */ +static char * +trim (char * pz) +{ + /* trim leading white space */ + while (isspace ((unsigned char)*pz)) + pz++; + + /* trim trailing white space */ + { + char * pe = pz + strlen (pz); + while ((pe > pz) && isspace ((unsigned char)pe[-1])) + pe--; + *pe = NUL; + } + + return pz; +} + +/* + * Parse the year/months/days of a time period + */ +static time_t +parse_period (cch_t * in_pz) +{ + char * pT; + char * ps; + char * pz = strdup (in_pz); + void * fptr = pz; + time_t res = 0; + + if (pz == NULL) + { + errno = ENOMEM; + return BAD_TIME; + } + + pT = strchr (pz, 'T'); + if (pT != NULL) + { + *(pT++) = NUL; + pz = trim (pz); + pT = trim (pT); + } + + /* + * Scan for a hyphen + */ + ps = strchr (pz, '-'); + if (ps != NULL) + { + res = parse_year_month_day (pz, ps); + } + + /* + * Try for a 'Y', 'M' or 'D' suffix + */ + else if (ps = strpbrk (pz, "YMWD"), + ps == NULL) + { + /* Its a YYYYMMDD format: */ + res = parse_yearmonthday (pz); + } + + else + res = parse_YMWD (pz); + + if ((errno == 0) && (pT != NULL)) + { + time_t val = parse_time (pT); + res = scale_n_add (res, val, 1); + } + + free (fptr); + return res; +} + +static time_t +parse_non_iso8601 (cch_t * pz) +{ + whats_done_t whatd_we_do = NOTHING_IS_DONE; + + time_t res = 0; + + do { + time_t val; + + errno = 0; + val = str_const_to_l (pz, &pz, 10); + if (errno != 0) + goto bad_time; + + /* IF we find a colon, then we're going to have a seconds value. + We will not loop here any more. We cannot already have parsed + a minute value and if we've parsed an hour value, then the result + value has to be less than an hour. */ + if (*pz == ':') + { + if (whatd_we_do >= MINUTE_IS_DONE) + break; + + val = parse_hr_min_sec (val, pz); + + if ((whatd_we_do == HOUR_IS_DONE) && (val >= SEC_PER_HR)) + break; + + return scale_n_add (res, val, 1); + } + + { + unsigned int mult; + + /* Skip over white space following the number we just parsed. */ + while (isspace ((unsigned char)*pz)) + pz++; + + switch (*pz) + { + default: goto bad_time; + case NUL: + return scale_n_add (res, val, 1); + + case 'y': case 'Y': + if (whatd_we_do >= YEAR_IS_DONE) + goto bad_time; + mult = SEC_PER_YEAR; + whatd_we_do = YEAR_IS_DONE; + break; + + case 'M': + if (whatd_we_do >= MONTH_IS_DONE) + goto bad_time; + mult = SEC_PER_MONTH; + whatd_we_do = MONTH_IS_DONE; + break; + + case 'W': + if (whatd_we_do >= WEEK_IS_DONE) + goto bad_time; + mult = SEC_PER_WEEK; + whatd_we_do = WEEK_IS_DONE; + break; + + case 'd': case 'D': + if (whatd_we_do >= DAY_IS_DONE) + goto bad_time; + mult = SEC_PER_DAY; + whatd_we_do = DAY_IS_DONE; + break; + + case 'h': + if (whatd_we_do >= HOUR_IS_DONE) + goto bad_time; + mult = SEC_PER_HR; + whatd_we_do = HOUR_IS_DONE; + break; + + case 'm': + if (whatd_we_do >= MINUTE_IS_DONE) + goto bad_time; + mult = SEC_PER_MIN; + whatd_we_do = MINUTE_IS_DONE; + break; + + case 's': + mult = 1; + whatd_we_do = SECOND_IS_DONE; + break; + } + + res = scale_n_add (res, val, mult); + + pz++; + while (isspace ((unsigned char)*pz)) + pz++; + if (*pz == NUL) + return res; + + if (! isdigit ((unsigned char)*pz)) + break; + } + + } while (whatd_we_do < SECOND_IS_DONE); + + bad_time: + errno = EINVAL; + return BAD_TIME; +} + +time_t +parse_duration (char const * pz) +{ + while (isspace ((unsigned char)*pz)) + pz++; + + switch (*pz) + { + case 'P': + return parse_period (pz + 1); + + case 'T': + return parse_time (pz + 1); + + default: + if (isdigit ((unsigned char)*pz)) + return parse_non_iso8601 (pz); + + errno = EINVAL; + return BAD_TIME; + } +} + +/* + * Local Variables: + * mode: C + * c-file-style: "gnu" + * indent-tabs-mode: nil + * End: + * end of parse-duration.c */ diff --git a/sntp/libopts/parse-duration.h b/sntp/libopts/parse-duration.h new file mode 100644 index 000000000000..9fd2a364cdb1 --- /dev/null +++ b/sntp/libopts/parse-duration.h @@ -0,0 +1,90 @@ +/* Parse a time duration and return a seconds count + Copyright (C) 2008-2011 Free Software Foundation, Inc. + Written by Bruce Korb <bkorb@gnu.org>, 2008. + + 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 3 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, see <http://www.gnu.org/licenses/>. */ + +/* + + Readers and users of this function are referred to the ISO-8601 + specification, with particular attention to "Durations". + + At the time of writing, this worked: + + http://en.wikipedia.org/wiki/ISO_8601#Durations + + The string must start with a 'P', 'T' or a digit. + + ==== if it is a digit + + the string may contain: NNN Y NNN M NNN W NNN d NNN h NNN m NNN s + This represents NNN years, NNN months, NNN weeks, NNN days, NNN hours, + NNN minutes and NNN seconds. + The embeded white space is optional. + These terms must appear in this order. + Case is significant: 'M' is months and 'm' is minutes. + The final "s" is optional. + All of the terms ("NNN" plus designator) are optional. + Minutes and seconds may optionally be represented as NNN:NNN. + Also, hours, minute and seconds may be represented as NNN:NNN:NNN. + There is no limitation on the value of any of the terms, except + that the final result must fit in a time_t value. + + ==== if it is a 'P' or 'T', please see ISO-8601 for a rigorous definition. + + The 'P' term may be followed by any of three formats: + yyyymmdd + yy-mm-dd + yy Y mm M ww W dd D + + or it may be empty and followed by a 'T'. The "yyyymmdd" must be eight + digits long. + + NOTE! Months are always 30 days and years are always 365 days long. + 5 years is always 1825 days, not 1826 or 1827 depending on leap year + considerations. 3 months is always 90 days. There is no consideration + for how many days are in the current, next or previous months. + + For the final format: + * Embedded white space is allowed, but it is optional. + * All of the terms are optional. Any or all-but-one may be omitted. + * The meanings are yy years, mm months, ww weeks and dd days. + * The terms must appear in this order. + + ==== The 'T' term may be followed by any of these formats: + + hhmmss + hh:mm:ss + hh H mm M ss S + + For the final format: + * Embedded white space is allowed, but it is optional. + * All of the terms are optional. Any or all-but-one may be omitted. + * The terms must appear in this order. + + */ +#ifndef GNULIB_PARSE_DURATION_H +#define GNULIB_PARSE_DURATION_H + +#include <time.h> + +/* Return value when a valid duration cannot be parsed. */ +#define BAD_TIME ((time_t)~0) + +/* Parses the given string. If it has the syntax of a valid duration, + this duration is returned. Otherwise, the return value is BAD_TIME, + and errno is set to either EINVAL (bad syntax) or ERANGE (out of range). */ +extern time_t parse_duration (char const * in_pz); + +#endif /* GNULIB_PARSE_DURATION_H */ diff --git a/sntp/libopts/pgusage.c b/sntp/libopts/pgusage.c index c417c63d5c5f..2e2194867e38 100644 --- a/sntp/libopts/pgusage.c +++ b/sntp/libopts/pgusage.c @@ -1,59 +1,35 @@ -/* - * $Id: pgusage.c,v 4.12 2007/04/28 22:19:23 bkorb Exp $ - * Time-stamp: "2006-07-16 08:13:26 bkorb" +/** + * \file pgusage.c + * + * Time-stamp: "2011-03-25 17:54:41 bkorb" * * Automated Options Paged Usage module. * * This routine will run run-on options through a pager so the * user may examine, print or edit them at their leisure. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -tePagerState pagerState = PAGER_STATE_INITIAL; - /*=export_func optionPagedUsage * private: * @@ -64,12 +40,16 @@ tePagerState pagerState = PAGER_STATE_INITIAL; * doc: * Run the usage output through a pager. * This is very handy if it is very long. + * This is disabled on platforms without a working fork() function. =*/ void -optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) +optionPagedUsage(tOptions* pOptions, tOptDesc* pOD) { -#if defined(__windows__) && !defined(__CYGWIN__) - (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS ); +#if ! defined(HAVE_WORKING_FORK) + if ((pOD->fOptState & OPTST_RESET) != 0) + return; + + (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS); #else static pid_t my_pid; char zPageUsage[ 1024 ]; @@ -82,42 +62,45 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) switch (pagerState) { case PAGER_STATE_INITIAL: { + if ((pOD->fOptState & OPTST_RESET) != 0) + return; + my_pid = getpid(); #ifdef HAVE_SNPRINTF snprintf(zPageUsage, sizeof(zPageUsage), "/tmp/use.%lu", (tAoUL)my_pid); #else - sprintf( zPageUsage, "/tmp/use.%lu", (tAoUL)my_pid ); + sprintf(zPageUsage, "/tmp/use.%lu", (tAoUL)my_pid); #endif - unlink( zPageUsage ); + unlink(zPageUsage); /* * Set usage output to this temporary file */ - option_usage_fp = fopen( zPageUsage, "w" FOPEN_BINARY_FLAG ); + option_usage_fp = fopen(zPageUsage, "w" FOPEN_BINARY_FLAG); if (option_usage_fp == NULL) - _exit( EXIT_FAILURE ); + _exit(EXIT_FAILURE); pagerState = PAGER_STATE_READY; /* * Set up so this routine gets called during the exit logic */ - atexit( (void(*)(void))optionPagedUsage ); + atexit((void(*)(void))optionPagedUsage); /* * The usage procedure will now put the usage information into * the temporary file we created above. */ - (*pOptions->pUsageProc)( pOptions, EXIT_SUCCESS ); + (*pOptions->pUsageProc)(pOptions, EXIT_SUCCESS); - /*NOTREACHED*/ - _exit( EXIT_FAILURE ); + /* NOTREACHED */ + _exit(EXIT_FAILURE); } case PAGER_STATE_READY: { tSCC zPage[] = "%1$s /tmp/use.%2$lu ; rm -f /tmp/use.%2$lu"; - tCC* pzPager = (tCC*)getenv( "PAGER" ); + tCC* pzPager = (tCC*)getenv("PAGER"); /* * Use the "more(1)" program if "PAGER" has not been defined @@ -131,12 +114,12 @@ optionPagedUsage( tOptions* pOptions, tOptDesc* pOD ) #ifdef HAVE_SNPRINTF snprintf(zPageUsage, sizeof(zPageUsage), zPage, pzPager, (tAoUL)my_pid); #else - sprintf( zPageUsage, zPage, pzPager, (tAoUL)my_pid ); + sprintf(zPageUsage, zPage, pzPager, (tAoUL)my_pid); #endif - fclose( stderr ); - dup2( STDOUT_FILENO, STDERR_FILENO ); + fclose(stderr); + dup2(STDOUT_FILENO, STDERR_FILENO); - (void)system( zPageUsage ); + (void)system(zPageUsage); } case PAGER_STATE_CHILD: diff --git a/sntp/libopts/proto.h b/sntp/libopts/proto.h index e87ab87bd089..13843c8b620c 100644 --- a/sntp/libopts/proto.h +++ b/sntp/libopts/proto.h @@ -1,47 +1,49 @@ /* -*- buffer-read-only: t -*- vi: set ro: * * Prototypes for autoopts - * Generated Sat May 5 12:02:36 PDT 2007 + * Generated Fri Apr 29 15:44:06 PDT 2011 */ #ifndef AUTOOPTS_PROTO_H_GUARD #define AUTOOPTS_PROTO_H_GUARD 1 + #ifndef LOCAL # define LOCAL extern # define REDEF_LOCAL 1 #else # undef REDEF_LOCAL #endif -/*\n * Extracted from autoopts.c\n */ +/* + * Extracted from autoopts.c + */ LOCAL void * -ao_malloc( size_t sz ); +ao_malloc(size_t sz); LOCAL void * -ao_realloc( void *p, size_t sz ); - -LOCAL void -ao_free( void *p ); +ao_realloc(void *p, size_t sz); LOCAL char * -ao_strdup( char const *str ); +ao_strdup(char const *str); LOCAL tSuccess -handleOption( tOptions* pOpts, tOptState* pOptState ); +handle_opt(tOptions* pOpts, tOptState* pOptState); LOCAL tSuccess -longOptionFind( tOptions* pOpts, char* pzOptName, tOptState* pOptState ); +longOptionFind(tOptions* pOpts, char* pzOptName, tOptState* pOptState); LOCAL tSuccess -shortOptionFind( tOptions* pOpts, uint_t optValue, tOptState* pOptState ); +shortOptionFind(tOptions* pOpts, uint_t optValue, tOptState* pOptState); LOCAL tSuccess -doImmediateOpts( tOptions* pOpts ); +doImmediateOpts(tOptions* pOpts); LOCAL tSuccess -doRegularOpts( tOptions* pOpts ); +doRegularOpts(tOptions* pOpts); -/*\n * Extracted from configfile.c\n */ +/* + * Extracted from configfile.c + */ LOCAL void -internalFileLoad( tOptions* pOpts ); +internalFileLoad(tOptions* pOpts); LOCAL char* parseAttributes( @@ -51,18 +53,22 @@ parseAttributes( tOptionValue* pType ); LOCAL tSuccess -validateOptionsStruct( tOptions* pOpts, char const* pzProgram ); +validateOptionsStruct(tOptions* pOpts, char const* pzProgram); -/*\n * Extracted from environment.c\n */ +/* + * Extracted from environment.c + */ LOCAL void -doPrognameEnv( tOptions* pOpts, teEnvPresetType type ); +doPrognameEnv(tOptions* pOpts, teEnvPresetType type); LOCAL void -doEnvPresets( tOptions* pOpts, teEnvPresetType type ); +doEnvPresets(tOptions* pOpts, teEnvPresetType type); -/*\n * Extracted from load.c\n */ +/* + * Extracted from load.c + */ LOCAL void -mungeString( char* pzTxt, tOptionLoadMode mode ); +mungeString(char* pzTxt, tOptionLoadMode mode); LOCAL void loadOptionLine( @@ -72,17 +78,32 @@ loadOptionLine( tDirection direction, tOptionLoadMode load_mode ); -/*\n * Extracted from nested.c\n */ +/* + * Extracted from nested.c + */ +LOCAL void +unload_arg_list(tArgList* pAL); + LOCAL tOptionValue* optionLoadNested(char const* pzTxt, char const* pzName, size_t nameLen); -/*\n * Extracted from sort.c\n */ +LOCAL int +get_special_char(char const ** ppz, int * ct); + LOCAL void -optionSort( tOptions* pOpts ); +emit_special_char(FILE * fp, int ch); -/*\n * Extracted from stack.c\n */ +/* + * Extracted from sort.c + */ +LOCAL void +optionSort(tOptions* pOpts); + +/* + * Extracted from stack.c + */ LOCAL void -addArgListEntry( void** ppAL, void* entry ); +addArgListEntry(void** ppAL, void* entry); #ifdef REDEF_LOCAL # undef LOCAL diff --git a/sntp/libopts/putshell.c b/sntp/libopts/putshell.c index 93d9ef5f1e00..f15284f6b996 100644 --- a/sntp/libopts/putshell.c +++ b/sntp/libopts/putshell.c @@ -1,60 +1,52 @@ -/* - * $Id: putshell.c,v 4.18 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 10:29:39 bkorb" +/** + * \file putshell.c + * + * Time-stamp: "2010-09-05 06:10:56 bkorb" * * This module will interpret the options set in the tOptions * structure and print them to standard out in a fashion that * will allow them to be interpreted by the Bourne or Korn shells. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ +static char const zOptValFmt[] = "%s_%s="; +static char const zOptEnd[] = "\nexport %s_%s\n"; +static char const zOptNumFmt[] = "%1$s_%2$s=%3$d # 0x%3$X\nexport %1$s_%2$s\n"; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -putQuotedStr( tCC* pzStr ); +print_quot_str(tCC* pzStr); + +static void +print_enumeration(tOptions * pOpts, tOptDesc * pOD); + +static void +print_membership(tOptions * pOpts, tOptDesc * pOD); + +static void +print_stacked_arg(tOptions * pOpts, tOptDesc * pOD); + +static void +print_reordering(tOptions * pOpts); /* = = = END-STATIC-FORWARD = = = */ /* @@ -62,13 +54,13 @@ putQuotedStr( tCC* pzStr ); * been emitted and the closing quote will be upon return. */ static void -putQuotedStr( tCC* pzStr ) +print_quot_str(tCC* pzStr) { /* * Handle empty strings to make the rest of the logic simpler. */ if ((pzStr == NULL) || (*pzStr == NUL)) { - fputs( "''", stdout ); + fputs("''", stdout); return; } @@ -77,7 +69,7 @@ putQuotedStr( tCC* pzStr ) * bail if that is all we need to do. */ while (*pzStr == '\'') { - fputs( "\\'", stdout ); + fputs("\\'", stdout); pzStr++; } if (*pzStr == NUL) @@ -86,38 +78,144 @@ putQuotedStr( tCC* pzStr ) /* * Start the single quote string */ - fputc( '\'', stdout ); + fputc('\'', stdout); for (;;) { - tCC* pz = strchr( pzStr, '\'' ); + tCC* pz = strchr(pzStr, '\''); if (pz == NULL) break; /* * Emit the string up to the single quote (apostrophe) we just found. */ - (void)fwrite( pzStr, (size_t)(pz - pzStr), (size_t)1, stdout ); - fputc( '\'', stdout ); + (void)fwrite(pzStr, (size_t)(pz - pzStr), (size_t)1, stdout); + fputc('\'', stdout); pzStr = pz; /* * Emit an escaped apostrophe for every one we find. * If that ends the string, do not re-open the single quotes. */ - while (*++pzStr == '\'') fputs( "\\'", stdout ); + while (*++pzStr == '\'') fputs("\\'", stdout); if (*pzStr == NUL) return; - fputc( '\'', stdout ); + fputc('\'', stdout); } /* * If we broke out of the loop, we must still emit the remaining text * and then close the single quote string. */ - fputs( pzStr, stdout ); - fputc( '\'', stdout ); + fputs(pzStr, stdout); + fputc('\'', stdout); } +static void +print_enumeration(tOptions * pOpts, tOptDesc * pOD) +{ + uintptr_t e_val = pOD->optArg.argEnum; + printf(zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME); + + /* + * Convert value to string, print that and restore numeric value. + */ + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + printf("'%s'", pOD->optArg.argString); + if (pOD->fOptState & OPTST_ALLOC_ARG) + AGFREE(pOD->optArg.argString); + pOD->optArg.argEnum = e_val; + + printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME); +} + +static void +print_membership(tOptions * pOpts, tOptDesc * pOD) +{ + char const * pz; + uintptr_t val = 1; + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (int)(uintptr_t)(pOD->optCookie)); + pOD->optCookie = (void*)(uintptr_t)~0UL; + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + + /* + * We are building the typeset list. The list returned starts with + * 'none + ' for use by option saving stuff. We must ignore that. + */ + pz = pOD->optArg.argString + 7; + while (*pz != NUL) { + printf("typeset -x -i %s_", pOD->pz_NAME); + while (IS_PLUS_N_SPACE_CHAR(*pz)) pz++; + + for (;;) { + int ch = *(pz++); + if (IS_LOWER_CASE_CHAR(ch)) fputc(toupper(ch), stdout); + else if (IS_UPPER_CASE_CHAR(ch)) fputc(ch, stdout); + else if (IS_PLUS_N_SPACE_CHAR(ch)) goto name_done; + else if (ch == NUL) { pz--; goto name_done; } + else fputc('_', stdout); + } name_done:; + printf("=%1$lu # 0x%1$lX\n", (unsigned long)val); + val <<= 1; + } + + AGFREE(pOD->optArg.argString); + pOD->optArg.argString = NULL; + pOD->fOptState &= ~OPTST_ALLOC_ARG; +} + +static void +print_stacked_arg(tOptions * pOpts, tOptDesc * pOD) +{ + tSCC zOptCookieCt[] = "%1$s_%2$s_CT=%3$d\nexport %1$s_%2$s_CT\n"; + + tArgList* pAL = (tArgList*)pOD->optCookie; + tCC** ppz = pAL->apzArgs; + int ct = pAL->useCt; + + printf(zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct); + + while (--ct >= 0) { + tSCC numarg_z[] = "%s_%s_%d="; + tSCC end_z[] = "\nexport %s_%s_%d\n"; + + printf(numarg_z, pOpts->pzPROGNAME, pOD->pz_NAME, + pAL->useCt - ct); + print_quot_str(*(ppz++)); + printf(end_z, pOpts->pzPROGNAME, pOD->pz_NAME, + pAL->useCt - ct); + } +} + +static void +print_reordering(tOptions * pOpts) +{ + int optIx; + + fputs("set --", stdout); + + for (optIx = pOpts->curOptIdx; optIx < pOpts->origArgCt; optIx++) { + + char* pzArg = pOpts->origArgVect[ optIx ]; + + if (strchr(pzArg, '\'') == NULL) + printf(" '%s'", pzArg); + + else { + fputs(" '", stdout); + for (;;) { + char ch = *(pzArg++); + switch (ch) { + case '\'': fputs("'\\''", stdout); break; + case NUL: goto arg_done; + default: fputc(ch, stdout); break; + } + } arg_done:; + fputc('\'', stdout); + } + } + fputs("\nOPTION_CT=0\n", stdout); +} /*=export_func optionPutShell * what: write a portable shell script to parse options @@ -127,18 +225,15 @@ putQuotedStr( tCC* pzStr ) * the options described in the option definitions. =*/ void -optionPutShell( tOptions* pOpts ) +optionPutShell(tOptions* pOpts) { int optIx = 0; tSCC zOptCtFmt[] = "OPTION_CT=%d\nexport OPTION_CT\n"; - tSCC zOptNumFmt[] = "%1$s_%2$s=%3$d # 0x%3$X\nexport %1$s_%2$s\n"; tSCC zOptDisabl[] = "%1$s_%2$s=%3$s\nexport %1$s_%2$s\n"; - tSCC zOptValFmt[] = "%s_%s="; - tSCC zOptEnd[] = "\nexport %s_%s\n"; tSCC zFullOptFmt[]= "%1$s_%2$s='%3$s'\nexport %1$s_%2$s\n"; tSCC zEquivMode[] = "%1$s_%2$s_MODE='%3$s'\nexport %1$s_%2$s_MODE\n"; - printf( zOptCtFmt, pOpts->curOptIdx-1 ); + printf(zOptCtFmt, pOpts->curOptIdx-1); do { tOptDesc* pOD = pOpts->pOptDesc + optIx; @@ -166,7 +261,7 @@ optionPutShell( tOptions* pOpts ) p->optArg = pOD->optArg; p->fOptState &= OPTST_PERSISTENT_MASK; p->fOptState |= pOD->fOptState & ~OPTST_PERSISTENT_MASK; - printf( zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME ); + printf(zEquivMode, pOpts->pzPROGNAME, pOD->pz_NAME, p->pz_NAME); pOD = p; } @@ -176,37 +271,7 @@ optionPutShell( tOptions* pOpts ) * of bitmask value and we need to emit the bit values. */ if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) { - char const * pz; - uintptr_t val = 1; - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (int)(uintptr_t)(pOD->optCookie) ); - pOD->optCookie = (void*)(uintptr_t)~0UL; - (*(pOD->pOptProc))( (tOptions*)2UL, pOD ); - - /* - * We are building the typeset list. The list returned starts with - * 'none + ' for use by option saving stuff. We must ignore that. - */ - pz = pOD->optArg.argString + 7; - while (*pz != NUL) { - printf( "typeset -x -i %s_", pOD->pz_NAME ); - pz += strspn( pz, " +\t\n\f" ); - for (;;) { - int ch = *(pz++); - if (islower( ch )) fputc( toupper( ch ), stdout ); - else if (isalnum( ch )) fputc( ch, stdout ); - else if (isspace( ch ) - || (ch == '+')) goto name_done; - else if (ch == NUL) { pz--; goto name_done; } - else fputc( '_', stdout ); - } name_done:; - printf( "=%1$lu # 0x%1$lX\n", (unsigned long)val ); - val <<= 1; - } - - AGFREE(pOD->optArg.argString); - pOD->optArg.argString = NULL; - pOD->fOptState &= ~OPTST_ALLOC_ARG; + print_membership(pOpts, pOD); continue; } @@ -216,114 +281,86 @@ optionPutShell( tOptions* pOpts ) * The idea is that if someone defines an option to initialize * enabled, we should tell our shell script that it is enabled. */ - if (UNUSED_OPT( pOD ) && DISABLED_OPT( pOD )) + if (UNUSED_OPT(pOD) && DISABLED_OPT(pOD)) { continue; + } /* * Handle stacked arguments */ if ( (pOD->fOptState & OPTST_STACKED) && (pOD->optCookie != NULL) ) { - tSCC zOptCookieCt[] = "%1$s_%2$s_CT=%3$d\nexport %1$s_%2$s_CT\n"; - - tArgList* pAL = (tArgList*)pOD->optCookie; - tCC** ppz = pAL->apzArgs; - int ct = pAL->useCt; - - printf( zOptCookieCt, pOpts->pzPROGNAME, pOD->pz_NAME, ct ); - - while (--ct >= 0) { - tSCC numarg_z[] = "%s_%s_%d="; - tSCC end_z[] = "\nexport %s_%s_%d\n"; - - printf( numarg_z, pOpts->pzPROGNAME, pOD->pz_NAME, - pAL->useCt - ct ); - putQuotedStr( *(ppz++) ); - printf( end_z, pOpts->pzPROGNAME, pOD->pz_NAME, - pAL->useCt - ct ); - } + print_stacked_arg(pOpts, pOD); + continue; } /* * If the argument has been disabled, * Then set its value to the disablement string */ - else if ((pOD->fOptState & OPTST_DISABLED) != 0) - printf( zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME, - (pOD->pz_DisablePfx != NULL) - ? pOD->pz_DisablePfx : "false" ); + if ((pOD->fOptState & OPTST_DISABLED) != 0) { + printf(zOptDisabl, pOpts->pzPROGNAME, pOD->pz_NAME, + (pOD->pz_DisablePfx != NULL) + ? pOD->pz_DisablePfx : "false"); + continue; + } /* * If the argument type is numeric, the last arg pointer * is really the VALUE of the string that was pointed to. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (int)pOD->optArg.argInt ); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) { + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (int)pOD->optArg.argInt); + continue; + } /* * If the argument type is an enumeration, then it is much * like a text value, except we call the callback function * to emit the value corresponding to the "optArg" number. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) { - printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME ); - fputc( '\'', stdout ); - (*(pOD->pOptProc))( (tOptions*)1UL, pOD ); - fputc( '\'', stdout ); - printf( zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME ); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_ENUMERATION) { + print_enumeration(pOpts, pOD); + continue; } /* * If the argument type is numeric, the last arg pointer * is really the VALUE of the string that was pointed to. */ - else if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN) - printf( zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - (pOD->optArg.argBool == 0) ? "false" : "true" ); + if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_BOOLEAN) { + printf(zFullOptFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + (pOD->optArg.argBool == 0) ? "false" : "true"); + continue; + } /* * IF the option has an empty value, * THEN we set the argument to the occurrence count. */ - else if ( (pOD->optArg.argString == NULL) - || (pOD->optArg.argString[0] == NUL) ) + if ( (pOD->optArg.argString == NULL) + || (pOD->optArg.argString[0] == NUL) ) { - printf( zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, - pOD->optOccCt ); + printf(zOptNumFmt, pOpts->pzPROGNAME, pOD->pz_NAME, + pOD->optOccCt); + continue; + } /* * This option has a text value */ - else { - printf( zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME ); - putQuotedStr( pOD->optArg.argString ); - printf( zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME ); - } + printf(zOptValFmt, pOpts->pzPROGNAME, pOD->pz_NAME); + print_quot_str(pOD->optArg.argString); + printf(zOptEnd, pOpts->pzPROGNAME, pOD->pz_NAME); + } while (++optIx < pOpts->presetOptCt ); if ( ((pOpts->fOptSet & OPTPROC_REORDER) != 0) - && (pOpts->curOptIdx < pOpts->origArgCt)) { - fputs( "set --", stdout ); - for (optIx = pOpts->curOptIdx; optIx < pOpts->origArgCt; optIx++) { - char* pzArg = pOpts->origArgVect[ optIx ]; - if (strchr( pzArg, '\'' ) == NULL) - printf( " '%s'", pzArg ); - else { - fputs( " '", stdout ); - for (;;) { - char ch = *(pzArg++); - switch (ch) { - case '\'': fputs( "'\\''", stdout ); break; - case NUL: goto arg_done; - default: fputc( ch, stdout ); break; - } - } arg_done:; - fputc( '\'', stdout ); - } - } - fputs( "\nOPTION_CT=0\n", stdout ); - } + && (pOpts->curOptIdx < pOpts->origArgCt)) + print_reordering(pOpts); + + fflush(stdout); } /* diff --git a/sntp/libopts/reset.c b/sntp/libopts/reset.c new file mode 100644 index 000000000000..2959db664c3a --- /dev/null +++ b/sntp/libopts/reset.c @@ -0,0 +1,135 @@ + +/** + * \file reset.c + * + * Time-stamp: "2010-07-10 10:56:34 bkorb" + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd + */ + +static void +optionReset( tOptions* pOpts, tOptDesc* pOD ) +{ + pOD->fOptState &= OPTST_PERSISTENT_MASK; + pOD->fOptState |= OPTST_RESET; + if (pOD->pOptProc != NULL) + pOD->pOptProc(pOpts, pOD); + pOD->optArg.argString = + pOpts->originalOptArgArray[ pOD->optIndex ].argString; + pOD->optCookie = pOpts->originalOptArgCookie[ pOD->optIndex ]; + pOD->fOptState &= OPTST_PERSISTENT_MASK; +} + + +static void +optionResetEverything(tOptions * pOpts) +{ + tOptDesc * pOD = pOpts->pOptDesc; + int ct = pOpts->presetOptCt; + + for (;;) { + optionReset(pOpts, pOD); + + if (--ct <= 0) + break; + pOD++; + } +} + + +/*=export_func optionResetOpt + * private: + * + * what: Reset the value of an option + * arg: + tOptions* + pOpts + program options descriptor + + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * + * doc: + * This code will cause another option to be reset to its initial state. + * For example, --reset=foo will cause the --foo option to be reset. +=*/ +void +optionResetOpt( tOptions* pOpts, tOptDesc* pOD ) +{ + static ag_bool reset_active = AG_FALSE; + + tOptState opt_state = OPTSTATE_INITIALIZER(DEFINED); + char const * pzArg = pOD->optArg.argString; + tSuccess succ; + + if (reset_active) + return; + + if ( (! HAS_originalOptArgArray(pOpts)) + || (pOpts->originalOptArgCookie == NULL)) { + fputs(zResetNotConfig, stderr); + _exit(EX_SOFTWARE); + } + + if ((pzArg == NULL) || (*pzArg == NUL)) { + fputs(zNoResetArg, stderr); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + assert(0 == 1); + } + + reset_active = AG_TRUE; + + if (pzArg[1] == NUL) { + if (*pzArg == '*') { + optionResetEverything(pOpts); + reset_active = AG_FALSE; + return; + } + + succ = shortOptionFind(pOpts, (tAoUC)*pzArg, &opt_state); + if (! SUCCESSFUL(succ)) { + fprintf(stderr, zIllOptChr, pOpts->pzProgPath, *pzArg); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + assert(0 == 1); + } + } else { + succ = longOptionFind(pOpts, (char *)pzArg, &opt_state); + if (! SUCCESSFUL(succ)) { + fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg); + pOpts->pUsageProc(pOpts, EXIT_FAILURE); + /* NOTREACHED */ + assert(0 == 1); + } + } + + /* + * We've found the indicated option. Turn off all non-persistent + * flags because we're forcing the option back to its initialized state. + * Call any callout procedure to handle whatever it needs to. + * Finally, clear the reset flag, too. + */ + optionReset(pOpts, opt_state.pOD); + reset_active = AG_FALSE; +} +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of autoopts/reset.c */ diff --git a/sntp/libopts/restore.c b/sntp/libopts/restore.c index 91eac080425b..f55f3d2499d1 100644 --- a/sntp/libopts/restore.c +++ b/sntp/libopts/restore.c @@ -1,54 +1,32 @@ /* - * restore.c $Id: restore.c,v 4.10 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 14:13:17 bkorb" + * \file restore.c + * + * Time-stamp: "2010-08-22 11:04:00 bkorb" * * This module's routines will save the current option state to memory * and restore it. If saved prior to the initial optionProcess call, * then the initial state will be restored. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. - * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ /* @@ -119,8 +97,8 @@ optionSaveState(tOptions* pOpts) tOptions* p = (tOptions*)pOpts->pSavedState; if (p == NULL) { - size_t sz = sizeof( *pOpts ) + (pOpts->optCt * sizeof( tOptDesc )); - p = AGALOC( sz, "saved option state" ); + size_t sz = sizeof(*pOpts) + (pOpts->optCt * sizeof(tOptDesc)); + p = AGALOC(sz, "saved option state"); if (p == NULL) { tCC* pzName = pOpts->pzProgName; if (pzName == NULL) { @@ -128,15 +106,15 @@ optionSaveState(tOptions* pOpts) if (pzName == NULL) pzName = zNil; } - fprintf( stderr, zCantSave, pzName, sz ); - exit( EXIT_FAILURE ); + fprintf(stderr, zCantSave, pzName, sz); + exit(EXIT_FAILURE); } pOpts->pSavedState = p; } - memcpy( p, pOpts, sizeof( *p )); - memcpy( p + 1, pOpts->pOptDesc, p->optCt * sizeof( tOptDesc )); + memcpy(p, pOpts, sizeof(*p)); + memcpy(p + 1, pOpts->pOptDesc, p->optCt * sizeof(tOptDesc)); fixupSavedOptionArgs(pOpts); } @@ -158,7 +136,7 @@ optionSaveState(tOptions* pOpts) * printed to @code{stderr} and exit is called. =*/ void -optionRestore( tOptions* pOpts ) +optionRestore(tOptions* pOpts) { tOptions* p = (tOptions*)pOpts->pSavedState; @@ -169,15 +147,15 @@ optionRestore( tOptions* pOpts ) if (pzName == NULL) pzName = zNil; } - fprintf( stderr, zNoState, pzName ); - exit( EXIT_FAILURE ); + fprintf(stderr, zNoState, pzName); + exit(EXIT_FAILURE); } pOpts->pSavedState = NULL; optionFree(pOpts); - memcpy( pOpts, p, sizeof( *p )); - memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc )); + memcpy(pOpts, p, sizeof(*p)); + memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc)); pOpts->pSavedState = p; fixupSavedOptionArgs(pOpts); @@ -197,7 +175,7 @@ optionRestore( tOptions* pOpts ) * this routine is always successful. =*/ void -optionFree( tOptions* pOpts ) +optionFree(tOptions* pOpts) { free_saved_state: { @@ -225,7 +203,7 @@ optionFree( tOptions* pOpts ) case OPARG_TYPE_HIERARCHY: if (p->optCookie != NULL) - unloadNestedArglist(p->optCookie); + unload_arg_list(p->optCookie); break; } @@ -234,9 +212,9 @@ optionFree( tOptions* pOpts ) } if (pOpts->pSavedState != NULL) { tOptions * p = (tOptions*)pOpts->pSavedState; - memcpy( pOpts, p, sizeof( *p )); - memcpy( pOpts->pOptDesc, p+1, p->optCt * sizeof( tOptDesc )); - AGFREE( pOpts->pSavedState ); + memcpy(pOpts, p, sizeof(*p)); + memcpy(pOpts->pOptDesc, p+1, p->optCt * sizeof(tOptDesc)); + AGFREE(pOpts->pSavedState); pOpts->pSavedState = NULL; goto free_saved_state; } diff --git a/sntp/libopts/save.c b/sntp/libopts/save.c index c889520752f5..9c36bc83fdbf 100644 --- a/sntp/libopts/save.c +++ b/sntp/libopts/save.c @@ -1,79 +1,88 @@ /* - * save.c $Id: save.c,v 4.18 2007/04/15 19:01:18 bkorb Exp $ - * Time-stamp: "2007-04-15 11:11:10 bkorb" + * \file save.c + * + * Time-stamp: "2011-04-06 09:21:44 bkorb" * * This module's routines will take the currently set options and * store them into an ".rc" file for re-interpretation the next * time the invoking program is run. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -tSCC zWarn[] = "%s WARNING: cannot save options - "; +static char const zWarn[] = "%s WARNING: cannot save options - "; +static char const close_xml[] = "</%s>\n"; /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static tCC* -findDirName( tOptions* pOpts, int* p_free ); +findDirName(tOptions* pOpts, int* p_free); -static tCC* -findFileName( tOptions* pOpts, int* p_free_name ); +static char const * +findFileName(tOptions * pOpts, int * p_free_name); static void printEntry( FILE * fp, tOptDesc * p, tCC* pzLA ); + +static void +print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp); + +static void +print_a_string(FILE * fp, char const * name, char const * pz); + +static void +printValueList(FILE * fp, char const * name, tArgList * al); + +static void +printHierarchy(FILE * fp, tOptDesc * p); + +static FILE * +openSaveFile(tOptions* pOpts); + +static void +printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD); + +static void +printStringArg(FILE * fp, tOptDesc * pOD); + +static void +printEnumArg(FILE * fp, tOptDesc * pOD); + +static void +printSetMemberArg(FILE * fp, tOptDesc * pOD); + +static void +printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts); /* = = = END-STATIC-FORWARD = = = */ static tCC* -findDirName( tOptions* pOpts, int* p_free ) +findDirName(tOptions* pOpts, int* p_free) { tCC* pzDir; - if (pOpts->specOptIdx.save_opts == 0) + if ( (pOpts->specOptIdx.save_opts == NO_EQUIVALENT) + || (pOpts->specOptIdx.save_opts == 0)) return NULL; pzDir = pOpts->pOptDesc[ pOpts->specOptIdx.save_opts ].optArg.argString; @@ -100,7 +109,7 @@ findDirName( tOptions* pOpts, int* p_free ) return pzDir; { - tCC* pzEndDir = strchr( ++pzDir, DIRCH ); + tCC* pzEndDir = strchr(++pzDir, DIRCH); char* pzFileName; char* pzEnv; @@ -108,21 +117,21 @@ findDirName( tOptions* pOpts, int* p_free ) char z[ AO_NAME_SIZE ]; if ((pzEndDir - pzDir) > AO_NAME_LIMIT ) return NULL; - strncpy( z, pzDir, (size_t)(pzEndDir - pzDir) ); - z[ (pzEndDir - pzDir) ] = NUL; - pzEnv = getenv( z ); + memcpy(z, pzDir, (size_t)(pzEndDir - pzDir)); + z[pzEndDir - pzDir] = NUL; + pzEnv = getenv(z); } else { /* * Make sure we can get the env value (after stripping off * any trailing directory or file names) */ - pzEnv = getenv( pzDir ); + pzEnv = getenv(pzDir); } if (pzEnv == NULL) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNotDef, pzDir ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNotDef, pzDir); return NULL; } @@ -130,8 +139,8 @@ findDirName( tOptions* pOpts, int* p_free ) return pzEnv; { - size_t sz = strlen( pzEnv ) + strlen( pzEndDir ) + 2; - pzFileName = (char*)AGALOC( sz, "dir name" ); + size_t sz = strlen(pzEnv) + strlen(pzEndDir) + 2; + pzFileName = (char*)AGALOC(sz, "dir name"); } if (pzFileName == NULL) @@ -142,20 +151,19 @@ findDirName( tOptions* pOpts, int* p_free ) * Glue together the full name into the allocated memory. * FIXME: We lose track of this memory. */ - sprintf( pzFileName, "%s/%s", pzEnv, pzEndDir ); + sprintf(pzFileName, "%s/%s", pzEnv, pzEndDir); return pzFileName; } } -static tCC* -findFileName( tOptions* pOpts, int* p_free_name ) +static char const * +findFileName(tOptions * pOpts, int * p_free_name) { - tCC* pzDir; struct stat stBuf; int free_dir_name = 0; - pzDir = findDirName( pOpts, &free_dir_name ); + char const * pzDir = findDirName(pOpts, &free_dir_name); if (pzDir == NULL) return NULL; @@ -163,66 +171,60 @@ findFileName( tOptions* pOpts, int* p_free_name ) * See if we can find the specified directory. We use a once-only loop * structure so we can bail out early. */ - if (stat( pzDir, &stBuf ) != 0) do { + if (stat(pzDir, &stBuf) != 0) do { + char z[AG_PATH_MAX]; + char * dirchp; /* * IF we could not, check to see if we got a full * path to a file name that has not been created yet. */ - if (errno == ENOENT) { - char z[AG_PATH_MAX]; - - /* - * Strip off the last component, stat the remaining string and - * that string must name a directory - */ - char* pzDirCh = strrchr( pzDir, DIRCH ); - if (pzDirCh == NULL) { - stBuf.st_mode = S_IFREG; - continue; /* bail out of error condition */ - } - - strncpy( z, pzDir, (size_t)(pzDirCh - pzDir)); - z[ pzDirCh - pzDir ] = NUL; - - if ( (stat( z, &stBuf ) == 0) - && S_ISDIR( stBuf.st_mode )) { - - /* - * We found the directory. Restore the file name and - * mark the full name as a regular file - */ - stBuf.st_mode = S_IFREG; - continue; /* bail out of error condition */ - } + if (errno != ENOENT) { + bogus_name: + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoStat, errno, strerror(errno), pzDir); + if (free_dir_name) + AGFREE((void*)pzDir); + return NULL; } /* - * We got a bogus name. + * Strip off the last component, stat the remaining string and + * that string must name a directory */ - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoStat, errno, strerror( errno ), pzDir ); - if (free_dir_name) - AGFREE( (void*)pzDir ); - return NULL; + dirchp = strrchr(pzDir, DIRCH); + if (dirchp == NULL) { + stBuf.st_mode = S_IFREG; + break; /* found directory -- viz., "." */ + } + + if ((dirchp - pzDir) >= sizeof(z)) + goto bogus_name; + + memcpy(z, pzDir, (size_t)(dirchp - pzDir)); + z[dirchp - pzDir] = NUL; + + if ((stat(z, &stBuf) != 0) || ! S_ISDIR(stBuf.st_mode)) + goto bogus_name; + stBuf.st_mode = S_IFREG; /* file within this directory */ } while (0); /* * IF what we found was a directory, * THEN tack on the config file name */ - if (S_ISDIR( stBuf.st_mode )) { - size_t sz = strlen( pzDir ) + strlen( pOpts->pzRcName ) + 2; + if (S_ISDIR(stBuf.st_mode)) { + size_t sz = strlen(pzDir) + strlen(pOpts->pzRcName) + 2; { - char* pzPath = (char*)AGALOC( sz, "file name" ); + char* pzPath = (char*)AGALOC(sz, "file name"); #ifdef HAVE_SNPRINTF - snprintf( pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName ); + snprintf(pzPath, sz, "%s/%s", pzDir, pOpts->pzRcName); #else - sprintf( pzPath, "%s/%s", pzDir, pOpts->pzRcName ); + sprintf(pzPath, "%s/%s", pzDir, pOpts->pzRcName); #endif if (free_dir_name) - AGFREE( (void*)pzDir ); + AGFREE((void*)pzDir); pzDir = pzPath; free_dir_name = 1; } @@ -231,12 +233,12 @@ findFileName( tOptions* pOpts, int* p_free_name ) * IF we cannot stat the object for any reason other than * it does not exist, then we bail out */ - if (stat( pzDir, &stBuf ) != 0) { + if (stat(pzDir, &stBuf) != 0) { if (errno != ENOENT) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoStat, errno, strerror( errno ), - pzDir ); - AGFREE( (void*)pzDir ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoStat, errno, strerror(errno), + pzDir); + AGFREE((void*)pzDir); return NULL; } @@ -251,18 +253,18 @@ findFileName( tOptions* pOpts, int* p_free_name ) * Make sure that whatever we ultimately found, that it either is * or will soon be a file. */ - if (! S_ISREG( stBuf.st_mode )) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNotFile, pzDir ); + if (! S_ISREG(stBuf.st_mode)) { + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNotFile, pzDir); if (free_dir_name) - AGFREE( (void*)pzDir ); + AGFREE((void*)pzDir); return NULL; } /* * Get rid of the old file */ - unlink( pzDir ); + unlink(pzDir); *p_free_name = free_dir_name; return pzDir; } @@ -294,18 +296,18 @@ printEntry( * THEN the char pointer is really the number */ if (OPTST_GET_ARGTYPE(p->fOptState) == OPARG_TYPE_NUMERIC) - fprintf( fp, " %d\n", (int)(t_word)pzLA ); + fprintf(fp, " %d\n", (int)(t_word)pzLA); /* * OTHERWISE, FOR each line of the value text, ... */ else if (pzLA == NULL) - fputc( '\n', fp ); + fputc('\n', fp); else { - fputc( ' ', fp ); fputc( ' ', fp ); + fputc(' ', fp); fputc(' ', fp); for (;;) { - tCC* pzNl = strchr( pzLA, '\n' ); + tCC* pzNl = strchr(pzLA, '\n'); /* * IF this is the last line @@ -317,95 +319,393 @@ printEntry( /* * Print the continuation and the text from the current line */ - (void)fwrite( pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp ); + (void)fwrite(pzLA, (size_t)(pzNl - pzLA), (size_t)1, fp); pzLA = pzNl+1; /* advance the Last Arg pointer */ - fputs( "\\\n", fp ); + fputs("\\\n", fp); } /* * Terminate the entry */ - fputs( pzLA, fp ); - fputc( '\n', fp ); + fputs(pzLA, fp); + fputc('\n', fp); } } -/*=export_func optionSaveFile - * - * what: saves the option state to a file - * - * arg: tOptions*, pOpts, program options descriptor - * - * doc: - * - * This routine will save the state of option processing to a file. The name - * of that file can be specified with the argument to the @code{--save-opts} - * option, or by appending the @code{rcfile} attribute to the last - * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it - * will default to @code{.@i{programname}rc}. If you wish to specify another - * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro. - * - * err: - * - * If no @code{homerc} file was specified, this routine will silently return - * and do nothing. If the output file cannot be created or updated, a message - * will be printed to @code{stderr} and the routine will return. -=*/ -void -optionSaveFile( tOptions* pOpts ) +static void +print_a_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp) +{ + static char const bool_atr[] = "<%1$s type=boolean>%2$s</%1$s>\n"; + static char const numb_atr[] = "<%1$s type=integer>0x%2$lX</%1$s>\n"; + static char const type_atr[] = "<%s type=%s>"; + static char const null_atr[] = "<%s/>\n"; + + while (--depth >= 0) + putc(' ', fp), putc(' ', fp); + + switch (ovp->valType) { + default: + case OPARG_TYPE_NONE: + fprintf(fp, null_atr, ovp->pzName); + break; + + case OPARG_TYPE_STRING: + print_a_string(fp, ovp->pzName, ovp->v.strVal); + break; + + case OPARG_TYPE_ENUMERATION: + case OPARG_TYPE_MEMBERSHIP: + if (pOD != NULL) { + tAoUI opt_state = pOD->fOptState; + uintptr_t val = pOD->optArg.argEnum; + char const * typ = (ovp->valType == OPARG_TYPE_ENUMERATION) + ? "keyword" : "set-membership"; + + fprintf(fp, type_atr, ovp->pzName, typ); + + /* + * This is a magic incantation that will convert the + * bit flag values back into a string suitable for printing. + */ + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD ); + if (pOD->optArg.argString != NULL) { + fputs(pOD->optArg.argString, fp); + + if (ovp->valType != OPARG_TYPE_ENUMERATION) { + /* + * set membership strings get allocated + */ + AGFREE((void*)pOD->optArg.argString); + } + } + + pOD->optArg.argEnum = val; + pOD->fOptState = opt_state; + fprintf(fp, close_xml, ovp->pzName); + break; + } + /* FALLTHROUGH */ + + case OPARG_TYPE_NUMERIC: + fprintf(fp, numb_atr, ovp->pzName, ovp->v.longVal); + break; + + case OPARG_TYPE_BOOLEAN: + fprintf(fp, bool_atr, ovp->pzName, + ovp->v.boolVal ? "true" : "false"); + break; + + case OPARG_TYPE_HIERARCHY: + printValueList(fp, ovp->pzName, ovp->v.nestVal); + break; + } +} + + +static void +print_a_string(FILE * fp, char const * name, char const * pz) +{ + static char const open_atr[] = "<%s>"; + + fprintf(fp, open_atr, name); + for (;;) { + int ch = ((int)*(pz++)) & 0xFF; + + switch (ch) { + case NUL: goto string_done; + + case '&': + case '<': + case '>': +#if __GNUC__ >= 4 + case 1 ... (' ' - 1): + case ('~' + 1) ... 0xFF: +#endif + emit_special_char(fp, ch); + break; + + default: +#if __GNUC__ < 4 + if ( ((ch >= 1) && (ch <= (' ' - 1))) + || ((ch >= ('~' + 1)) && (ch <= 0xFF)) ) { + emit_special_char(fp, ch); + break; + } +#endif + putc(ch, fp); + } + } string_done:; + fprintf(fp, close_xml, name); +} + + +static void +printValueList(FILE * fp, char const * name, tArgList * al) +{ + static int depth = 1; + + int sp_ct; + int opt_ct; + void ** opt_list; + + if (al == NULL) + return; + opt_ct = al->useCt; + opt_list = (void **)al->apzArgs; + + if (opt_ct <= 0) { + fprintf(fp, "<%s/>\n", name); + return; + } + + fprintf(fp, "<%s type=nested>\n", name); + + depth++; + while (--opt_ct >= 0) { + tOptionValue const * ovp = *(opt_list++); + + print_a_value(fp, depth, NULL, ovp); + } + depth--; + + for (sp_ct = depth; --sp_ct >= 0;) + putc(' ', fp), putc(' ', fp); + fprintf(fp, "</%s>\n", name); +} + + +static void +printHierarchy(FILE * fp, tOptDesc * p) +{ + int opt_ct; + tArgList * al = p->optCookie; + void ** opt_list; + + if (al == NULL) + return; + + opt_ct = al->useCt; + opt_list = (void **)al->apzArgs; + + if (opt_ct <= 0) + return; + + do { + tOptionValue const * base = *(opt_list++); + tOptionValue const * ovp = optionGetValue(base, NULL); + + if (ovp == NULL) + continue; + + fprintf(fp, "<%s type=nested>\n", p->pz_Name); + + do { + print_a_value(fp, 1, p, ovp); + + } while (ovp = optionNextValue(base, ovp), + ovp != NULL); + + fprintf(fp, "</%s>\n", p->pz_Name); + } while (--opt_ct > 0); +} + + +static FILE * +openSaveFile(tOptions* pOpts) { - tOptDesc* pOD; - int ct; FILE* fp; { int free_name = 0; - tCC* pzFName = findFileName( pOpts, &free_name ); + tCC* pzFName = findFileName(pOpts, &free_name); if (pzFName == NULL) - return; + return NULL; - fp = fopen( pzFName, "w" FOPEN_BINARY_FLAG ); + fp = fopen(pzFName, "w" FOPEN_BINARY_FLAG); if (fp == NULL) { - fprintf( stderr, zWarn, pOpts->pzProgName ); - fprintf( stderr, zNoCreat, errno, strerror( errno ), pzFName ); + fprintf(stderr, zWarn, pOpts->pzProgName); + fprintf(stderr, zNoCreat, errno, strerror(errno), pzFName); if (free_name) AGFREE((void*) pzFName ); - return; + return fp; } if (free_name) - AGFREE( (void*)pzFName ); + AGFREE((void*)pzFName); } { char const* pz = pOpts->pzUsageTitle; - fputs( "# ", fp ); - do { fputc( *pz, fp ); } while (*(pz++) != '\n'); + fputs("# ", fp); + do { fputc(*pz, fp); } while (*(pz++) != '\n'); } { - time_t timeVal = time( NULL ); - char* pzTime = ctime( &timeVal ); + time_t timeVal = time(NULL); + char* pzTime = ctime(&timeVal); - fprintf( fp, zPresetFile, pzTime ); + fprintf(fp, zPresetFile, pzTime); #ifdef HAVE_ALLOCATED_CTIME /* * The return values for ctime(), localtime(), and gmtime() * normally point to static data that is overwritten by each call. * The test to detect allocated ctime, so we leak the memory. */ - AGFREE( (void*)pzTime ); + AGFREE((void*)pzTime); #endif } + return fp; +} + +static void +printNoArgOpt(FILE * fp, tOptDesc * p, tOptDesc * pOD) +{ + /* + * The aliased to argument indicates whether or not the option + * is "disabled". However, the original option has the name + * string, so we get that there, not with "p". + */ + char const * pznm = + (DISABLED_OPT(p)) ? pOD->pz_DisableName : pOD->pz_Name; + /* + * If the option was disabled and the disablement name is NULL, + * then the disablement was caused by aliasing. + * Use the name as the string to emit. + */ + if (pznm == NULL) + pznm = pOD->pz_Name; + + fprintf(fp, "%s\n", pznm); +} + +static void +printStringArg(FILE * fp, tOptDesc * pOD) +{ + if (pOD->fOptState & OPTST_STACKED) { + tArgList* pAL = (tArgList*)pOD->optCookie; + int uct = pAL->useCt; + tCC** ppz = pAL->apzArgs; + + /* + * un-disable multiple copies of disabled options. + */ + if (uct > 1) + pOD->fOptState &= ~OPTST_DISABLED; + + while (uct-- > 0) + printEntry(fp, pOD, *(ppz++)); + } else { + printEntry(fp, pOD, pOD->optArg.argString); + } +} + +static void +printEnumArg(FILE * fp, tOptDesc * pOD) +{ + uintptr_t val = pOD->optArg.argEnum; + + /* + * This is a magic incantation that will convert the + * bit flag values back into a string suitable for printing. + */ + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + printEntry(fp, pOD, (void*)(pOD->optArg.argString)); + + pOD->optArg.argEnum = val; +} + +static void +printSetMemberArg(FILE * fp, tOptDesc * pOD) +{ + uintptr_t val = pOD->optArg.argEnum; + + /* + * This is a magic incantation that will convert the + * bit flag values back into a string suitable for printing. + */ + (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, pOD); + printEntry(fp, pOD, (void*)(pOD->optArg.argString)); + + if (pOD->optArg.argString != NULL) { + /* + * set membership strings get allocated + */ + AGFREE((void*)pOD->optArg.argString); + pOD->fOptState &= ~OPTST_ALLOC_ARG; + } + + pOD->optArg.argEnum = val; +} + +static void +printFileArg(FILE * fp, tOptDesc * pOD, tOptions* pOpts) +{ + /* + * If the cookie is not NULL, then it has the file name, period. + * Otherwise, if we have a non-NULL string argument, then.... + */ + if (pOD->optCookie != NULL) + printEntry(fp, pOD, pOD->optCookie); + + else if (HAS_originalOptArgArray(pOpts)) { + char const * orig = + pOpts->originalOptArgArray[pOD->optIndex].argString; + + if (pOD->optArg.argString == orig) + return; + + printEntry(fp, pOD, pOD->optArg.argString); + } +} + + +/*=export_func optionSaveFile + * + * what: saves the option state to a file + * + * arg: tOptions*, pOpts, program options descriptor + * + * doc: + * + * This routine will save the state of option processing to a file. The name + * of that file can be specified with the argument to the @code{--save-opts} + * option, or by appending the @code{rcfile} attribute to the last + * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it + * will default to @code{.@i{programname}rc}. If you wish to specify another + * file, you should invoke the @code{SET_OPT_SAVE_OPTS(@i{filename})} macro. + * + * The recommend usage is as follows: + * @example + * optionProcess(&progOptions, argc, argv); + * if (i_want_a_non_standard_place_for_this) + * SET_OPT_SAVE_OPTS("myfilename"); + * optionSaveFile(&progOptions); + * @end example + * + * err: + * + * If no @code{homerc} file was specified, this routine will silently return + * and do nothing. If the output file cannot be created or updated, a message + * will be printed to @code{stderr} and the routine will return. +=*/ +void +optionSaveFile(tOptions* pOpts) +{ + tOptDesc* pOD; + int ct; + FILE* fp = openSaveFile(pOpts); + + if (fp == NULL) + return; + /* * FOR each of the defined options, ... */ ct = pOpts->presetOptCt; pOD = pOpts->pOptDesc; do { - int arg_state; tOptDesc* p; /* @@ -413,104 +713,67 @@ optionSaveFile( tOptions* pOpts ) * OR it does not take an initialization value * OR it is equivalenced to another option * THEN continue (ignore it) + * + * Equivalenced options get picked up when the equivalenced-to + * option is processed. */ - if (UNUSED_OPT( pOD )) + if (UNUSED_OPT(pOD)) continue; - if ((pOD->fOptState & (OPTST_NO_INIT|OPTST_DOCUMENT|OPTST_OMITTED)) - != 0) + if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0) continue; if ( (pOD->optEquivIndex != NO_EQUIVALENT) - && (pOD->optEquivIndex != pOD->optIndex)) + && (pOD->optEquivIndex != pOD->optIndex)) continue; /* - * Set a temporary pointer to the real option description - * (i.e. account for equivalencing) + * The option argument data are found at the equivalenced-to option, + * but the actual option argument type comes from the original + * option descriptor. Be careful! */ p = ((pOD->fOptState & OPTST_EQUIVALENCE) != 0) ? (pOpts->pOptDesc + pOD->optActualIndex) : pOD; - /* - * IF no arguments are allowed - * THEN just print the name and continue - */ - if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NONE) { - char const * pznm = - (DISABLED_OPT( p )) ? p->pz_DisableName : p->pz_Name; - /* - * If the option was disabled and the disablement name is NULL, - * then the disablement was caused by aliasing. - * Use the name as the string to emit. - */ - if (pznm == NULL) - pznm = p->pz_Name; - - fprintf(fp, "%s\n", pznm); - continue; - } + switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + case OPARG_TYPE_NONE: + printNoArgOpt(fp, p, pOD); + break; - arg_state = OPTST_GET_ARGTYPE(p->fOptState); - switch (arg_state) { - case 0: case OPARG_TYPE_NUMERIC: - printEntry( fp, p, (void*)(p->optArg.argInt)); + printEntry(fp, p, (void*)(p->optArg.argInt)); break; case OPARG_TYPE_STRING: - if (p->fOptState & OPTST_STACKED) { - tArgList* pAL = (tArgList*)p->optCookie; - int uct = pAL->useCt; - tCC** ppz = pAL->apzArgs; - - /* - * Disallow multiple copies of disabled options. - */ - if (uct > 1) - p->fOptState &= ~OPTST_DISABLED; - - while (uct-- > 0) - printEntry( fp, p, *(ppz++) ); - } else { - printEntry( fp, p, p->optArg.argString ); - } + printStringArg(fp, p); break; case OPARG_TYPE_ENUMERATION: - case OPARG_TYPE_MEMBERSHIP: - { - uintptr_t val = p->optArg.argEnum; - /* - * This is a magic incantation that will convert the - * bit flag values back into a string suitable for printing. - */ - (*(p->pOptProc))( (tOptions*)2UL, p ); - printEntry( fp, p, (void*)(p->optArg.argString)); - - if ( (p->optArg.argString != NULL) - && (arg_state != OPARG_TYPE_ENUMERATION)) { - /* - * set membership strings get allocated - */ - AGFREE( (void*)p->optArg.argString ); - p->fOptState &= ~OPTST_ALLOC_ARG; - } + printEnumArg(fp, p); + break; - p->optArg.argEnum = val; + case OPARG_TYPE_MEMBERSHIP: + printSetMemberArg(fp, p); break; - } case OPARG_TYPE_BOOLEAN: - printEntry( fp, p, p->optArg.argBool ? "true" : "false" ); + printEntry(fp, p, p->optArg.argBool ? "true" : "false"); + break; + + case OPARG_TYPE_HIERARCHY: + printHierarchy(fp, p); + break; + + case OPARG_TYPE_FILE: + printFileArg(fp, p, pOpts); break; default: break; /* cannot handle - skip it */ } - } while ( (pOD++), (--ct > 0)); + } while (pOD++, (--ct > 0)); - fclose( fp ); + fclose(fp); } /* * Local Variables: diff --git a/sntp/libopts/sort.c b/sntp/libopts/sort.c index ead71337276e..6291db1cc6ca 100644 --- a/sntp/libopts/sort.c +++ b/sntp/libopts/sort.c @@ -1,67 +1,44 @@ /* - * sort.c $Id: sort.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $ - * Time-stamp: "2006-10-18 11:29:04 bkorb" + * \file sort.c * - * This module implements argument sorting. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. + * Time-stamp: "2010-07-17 10:34:15 bkorb" * - * Automated Options 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. + * This module implements argument sorting. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static tSuccess -mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); static tSuccess -mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); static tSuccess -checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ); +checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx); /* = = = END-STATIC-FORWARD = = = */ /* @@ -70,8 +47,8 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, * does not start with a hyphen and "must" will consume it, hyphen or not. */ static tSuccess -mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +mustHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { /* * An option argument is required. Long options can either have @@ -108,8 +85,8 @@ mustHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, } static tSuccess -mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +mayHandleArg(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { /* * An option argument is optional. @@ -151,11 +128,11 @@ mayHandleArg( tOptions* pOpts, char* pzArg, tOptState* pOS, * does or may take an argument, the do the argument processing and leave. */ static tSuccess -checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, - char** ppzOpts, int* pOptsIdx ) +checkShortOpts(tOptions* pOpts, char* pzArg, tOptState* pOS, + char** ppzOpts, int* pOptsIdx) { while (*pzArg != NUL) { - if (FAILED( shortOptionFind( pOpts, (tAoUC)*pzArg, pOS ))) + if (FAILED(shortOptionFind(pOpts, (tAoUC)*pzArg, pOS))) return FAILURE; /* @@ -200,7 +177,7 @@ checkShortOpts( tOptions* pOpts, char* pzArg, tOptState* pOS, * then this routine will to the trick. */ LOCAL void -optionSort( tOptions* pOpts ) +optionSort(tOptions* pOpts) { char** ppzOpts; char** ppzOpds; @@ -212,20 +189,20 @@ optionSort( tOptions* pOpts ) /* * Disable for POSIX conformance, or if there are no operands. */ - if ( (getenv( "POSIXLY_CORRECT" ) != NULL) + if ( (getenv("POSIXLY_CORRECT") != NULL) || NAMED_OPTS(pOpts)) return; /* * Make sure we can allocate two full-sized arg vectors. */ - ppzOpts = malloc( pOpts->origArgCt * sizeof( char* )); + ppzOpts = malloc(pOpts->origArgCt * sizeof(char*)); if (ppzOpts == NULL) goto exit_no_mem; - ppzOpds = malloc( pOpts->origArgCt * sizeof( char* )); + ppzOpds = malloc(pOpts->origArgCt * sizeof(char*)); if (ppzOpds == NULL) { - free( ppzOpts ); + free(ppzOpts); goto exit_no_mem; } @@ -274,7 +251,7 @@ optionSort( tOptions* pOpts ) pOpts->origArgVect[ (pOpts->curOptIdx)++ ]; goto restOperands; } - res = longOptionFind( pOpts, pzArg+2, &os ); + res = longOptionFind(pOpts, pzArg+2, &os); break; default: @@ -284,13 +261,13 @@ optionSort( tOptions* pOpts ) * short (i.e. single character) option. */ if ((pOpts->fOptSet & OPTPROC_SHORTOPT) == 0) { - res = longOptionFind( pOpts, pzArg+1, &os ); + res = longOptionFind(pOpts, pzArg+1, &os); } else { - res = shortOptionFind( pOpts, (tAoUC)pzArg[1], &os ); + res = shortOptionFind(pOpts, (tAoUC)pzArg[1], &os); } break; } - if (FAILED( res )) { + if (FAILED(res)) { errno = EINVAL; goto freeTemps; } @@ -309,20 +286,20 @@ optionSort( tOptions* pOpts ) * of the argument string. */ if ( (os.optType == TOPT_SHORT) - && FAILED( checkShortOpts( pOpts, pzArg+2, &os, - ppzOpts, &optsIdx )) ) { + && FAILED(checkShortOpts(pOpts, pzArg+2, &os, ppzOpts, + &optsIdx)) ) { errno = EINVAL; goto freeTemps; } } else if (os.pOD->fOptState & OPTST_ARG_OPTIONAL) { - switch (mayHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) { + switch (mayHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) { case FAILURE: errno = EIO; goto freeTemps; case PROBLEM: errno = 0; goto joinLists; } } else { - switch (mustHandleArg( pOpts, pzArg+2, &os, ppzOpts, &optsIdx )) { + switch (mustHandleArg(pOpts, pzArg+2, &os, ppzOpts, &optsIdx)) { case PROBLEM: case FAILURE: errno = EIO; goto freeTemps; } @@ -335,14 +312,14 @@ optionSort( tOptions* pOpts ) joinLists: if (optsIdx > 0) - memcpy( pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof( char* )); + memcpy(pOpts->origArgVect + 1, ppzOpts, optsIdx * sizeof(char*)); if (opdsIdx > 0) - memcpy( pOpts->origArgVect + 1 + optsIdx, - ppzOpds, opdsIdx * sizeof( char* )); + memcpy(pOpts->origArgVect + 1 + optsIdx, ppzOpds, + opdsIdx * sizeof(char*)); freeTemps: - free( ppzOpts ); - free( ppzOpds ); + free(ppzOpts); + free(ppzOpds); return; exit_no_mem: diff --git a/sntp/libopts/stack.c b/sntp/libopts/stack.c index 6d77f72e585c..d930772b7dd6 100644 --- a/sntp/libopts/stack.c +++ b/sntp/libopts/stack.c @@ -1,54 +1,31 @@ -/* - * stack.c - * $Id: stack.c,v 4.13 2007/02/04 17:44:12 bkorb Exp $ - * Time-stamp: "2007-01-13 10:43:21 bkorb" +/** + * \file stack.c + * + * Time-stamp: "2010-07-17 10:42:27 bkorb" * * This is a special option processing routine that will save the * argument to an option in a FIFO queue. - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb * - * Automated Options is free software. - * You may 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 file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * Automated Options 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. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * These files have the following md5sums: * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ #ifdef WITH_LIBREGEX @@ -72,14 +49,19 @@ optionUnstackArg( { int res; - tArgList* pAL = (tArgList*)pOptDesc->optCookie; + tArgList* pAL; + + if ((pOptDesc->fOptState & OPTST_RESET) != 0) + return; + pAL = (tArgList*)pOptDesc->optCookie; + /* * IF we don't have any stacked options, * THEN indicate that we don't have any of these options */ if (pAL == NULL) { pOptDesc->fOptState &= OPTST_PERSISTENT_MASK; - if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0) + if ((pOptDesc->fOptState & OPTST_INITENABLED) == 0) pOptDesc->fOptState |= OPTST_DISABLED; return; } @@ -89,7 +71,7 @@ optionUnstackArg( regex_t re; int i, ct, dIdx; - if (regcomp( &re, pOptDesc->optArg.argString, REG_NOSUB ) != 0) + if (regcomp(&re, pOptDesc->optArg.argString, REG_NOSUB) != 0) return; /* @@ -100,12 +82,12 @@ optionUnstackArg( */ for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) { tCC* pzSrc = pAL->apzArgs[ i ]; - char* pzEq = strchr( pzSrc, '=' ); + char* pzEq = strchr(pzSrc, '='); if (pzEq != NULL) *pzEq = NUL; - res = regexec( &re, pzSrc, (size_t)0, NULL, 0 ); + res = regexec(&re, pzSrc, (size_t)0, NULL, 0); switch (res) { case 0: /* @@ -132,7 +114,7 @@ optionUnstackArg( } } - regfree( &re ); + regfree(&re); } #else /* not WITH_LIBREGEX */ { @@ -146,12 +128,12 @@ optionUnstackArg( */ for (i = 0, dIdx = 0, ct = pAL->useCt; --ct >= 0; i++) { tCC* pzSrc = pAL->apzArgs[ i ]; - char* pzEq = strchr( pzSrc, '=' ); + char* pzEq = strchr(pzSrc, '='); if (pzEq != NULL) *pzEq = NUL; - if (strcmp( pzSrc, pOptDesc->optArg.argString ) == 0) { + if (strcmp(pzSrc, pOptDesc->optArg.argString) == 0) { /* * Remove this entry by reducing the in-use count * and *not* putting the string pointer back into @@ -180,9 +162,9 @@ optionUnstackArg( */ if (pAL->useCt == 0) { pOptDesc->fOptState &= OPTST_PERSISTENT_MASK; - if ( (pOptDesc->fOptState & OPTST_INITENABLED) == 0) + if ((pOptDesc->fOptState & OPTST_INITENABLED) == 0) pOptDesc->fOptState |= OPTST_DISABLED; - AGFREE( (void*)pAL ); + AGFREE((void*)pAL); pOptDesc->optCookie = NULL; } } @@ -194,7 +176,7 @@ optionUnstackArg( * as an opaque address. */ LOCAL void -addArgListEntry( void** ppAL, void* entry ) +addArgListEntry(void** ppAL, void* entry) { tArgList* pAL = *(void**)ppAL; @@ -203,7 +185,7 @@ addArgListEntry( void** ppAL, void* entry ) * THEN allocate one now */ if (pAL == NULL) { - pAL = (tArgList*)AGALOC( sizeof( *pAL ), "new option arg stack" ); + pAL = (tArgList*)AGALOC(sizeof(*pAL), "new option arg stack"); if (pAL == NULL) return; pAL->useCt = 0; @@ -216,7 +198,7 @@ addArgListEntry( void** ppAL, void* entry ) * THEN make it bigger */ else if (pAL->useCt >= pAL->allocCt) { - size_t sz = sizeof( *pAL ); + size_t sz = sizeof(*pAL); pAL->allocCt += INCR_ARG_ALLOC_CT; /* @@ -224,7 +206,7 @@ addArgListEntry( void** ppAL, void* entry ) * pointers. We subtract it off to find our augment size. */ sz += sizeof(char*) * (pAL->allocCt - MIN_ARG_ALLOC_CT); - pAL = (tArgList*)AGREALOC( (void*)pAL, sz, "expanded opt arg stack" ); + pAL = (tArgList*)AGREALOC((void*)pAL, sz, "expanded opt arg stack"); if (pAL == NULL) return; *ppAL = (void*)pAL; @@ -254,11 +236,24 @@ optionStackArg( { char * pz; - if (pOD->optArg.argString == NULL) - return; + if ((pOD->fOptState & OPTST_RESET) != 0) { + tArgList* pAL = (void*)pOD->optCookie; + int ix; + if (pAL == NULL) + return; - AGDUPSTR(pz, pOD->optArg.argString, "stack arg"); - addArgListEntry( &(pOD->optCookie), (void*)pz ); + ix = pAL->useCt; + while (--ix >= 0) + AGFREE(pAL->apzArgs[ix]); + AGFREE(pAL); + + } else { + if (pOD->optArg.argString == NULL) + return; + + AGDUPSTR(pz, pOD->optArg.argString, "stack arg"); + addArgListEntry(&(pOD->optCookie), (void*)pz); + } } /* * Local Variables: diff --git a/sntp/libopts/streqvcmp.c b/sntp/libopts/streqvcmp.c index 8249794e0e00..d2cb65de6346 100644 --- a/sntp/libopts/streqvcmp.c +++ b/sntp/libopts/streqvcmp.c @@ -1,7 +1,8 @@ -/* - * $Id: streqvcmp.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $ - * Time-stamp: "2006-07-26 18:25:53 bkorb" +/** + * \file streqvcmp.c + * + * Time-stamp: "2010-07-17 10:16:24 bkorb" * * String Equivalence Comparison * @@ -9,52 +10,27 @@ * character before comparison. In processing long option names, * the characters "-", "_" and "^" all need to be equivalent * (because they are treated so by different development environments). - */ - -/* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. - * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - */ - -/* + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd + * * This array is designed for mapping upper and lower case letter * together for a case independent comparison. The mappings are * based upon ascii character sequences. @@ -122,7 +98,7 @@ static unsigned char charmap[] = { * err: none checked. Caller responsible for seg faults. =*/ int -strneqvcmp( tCC* s1, tCC* s2, int ct ) +strneqvcmp(tCC* s1, tCC* s2, int ct) { for (; ct > 0; --ct) { unsigned char u1 = (unsigned char) *s1++; @@ -161,7 +137,7 @@ strneqvcmp( tCC* s1, tCC* s2, int ct ) * err: none checked. Caller responsible for seg faults. =*/ int -streqvcmp( tCC* s1, tCC* s2 ) +streqvcmp(tCC* s1, tCC* s2) { for (;;) { unsigned char u1 = (unsigned char) *s1++; @@ -194,7 +170,7 @@ streqvcmp( tCC* s1, tCC* s2 ) * are incremented and the process repeated until @code{ct} entries have been * set. For example, * @example - * streqvmap( 'a', 'A', 26 ); + * streqvmap('a', 'A', 26); * @end example * @noindent * will alter the mapping so that all English lower case letters @@ -206,10 +182,10 @@ streqvcmp( tCC* s1, tCC* s2 ) * err: none. =*/ void -streqvmap( char From, char To, int ct ) +streqvmap(char From, char To, int ct) { if (ct == 0) { - ct = sizeof( charmap ) - 1; + ct = sizeof(charmap) - 1; do { charmap[ ct ] = ct; } while (--ct >= 0); @@ -223,7 +199,7 @@ streqvmap( char From, char To, int ct ) charmap[ chFrom ] = (unsigned)chTo; chFrom++; chTo++; - if ((chFrom >= sizeof( charmap )) || (chTo >= sizeof( charmap ))) + if ((chFrom >= sizeof(charmap)) || (chTo >= sizeof(charmap))) break; } while (--ct > 0); } @@ -246,7 +222,7 @@ streqvmap( char From, char To, int ct ) * err: none. =*/ void -strequate( char const* s ) +strequate(char const* s) { if ((s != NULL) && (*s != NUL)) { unsigned char equiv = (unsigned)*s; @@ -270,10 +246,12 @@ strequate( char const* s ) * This function name is mapped to option_strtransform so as to not conflict * with the POSIX name space. * + * The source and destination may be the same. + * * err: none. =*/ void -strtransform( char* d, char const* s ) +strtransform(char* d, char const* s) { do { *(d++) = (char)charmap[ (unsigned)*s ]; diff --git a/sntp/libopts/text_mmap.c b/sntp/libopts/text_mmap.c index ced2977c5b79..01aa7d821255 100644 --- a/sntp/libopts/text_mmap.c +++ b/sntp/libopts/text_mmap.c @@ -1,7 +1,27 @@ -/* - * $Id: text_mmap.c,v 4.15 2006/11/27 01:52:23 bkorb Exp $ +/** + * \file text_mmap.c + * + * Time-stamp: "2010-07-17 10:15:32 bkorb" + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: * - * Time-stamp: "2006-09-10 14:50:04 bkorb" + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ #ifndef MAP_ANONYMOUS @@ -70,16 +90,16 @@ * #include <mylib.h> * tmap_info_t mi; * int no_nul; - * void* data = text_mmap( "file", PROT_WRITE, MAP_PRIVATE, &mi ); + * void* data = text_mmap("file", PROT_WRITE, MAP_PRIVATE, &mi); * if (data == MAP_FAILED) return; * no_nul = (mi.txt_size == mi.txt_full_size); * << use the data >> - * text_munmap( &mi ); + * text_munmap(&mi); =*/ void* -text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) +text_mmap(char const* pzFile, int prot, int flags, tmap_info_t* pMI) { - memset( pMI, 0, sizeof(*pMI) ); + memset(pMI, 0, sizeof(*pMI)); #ifdef HAVE_MMAP pMI->txt_zero_fd = -1; #endif @@ -90,12 +110,12 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) */ { struct stat sb; - if (stat( pzFile, &sb ) != 0) { + if (stat(pzFile, &sb) != 0) { pMI->txt_errno = errno; return MAP_FAILED_PTR; } - if (! S_ISREG( sb.st_mode )) { + if (! S_ISREG(sb.st_mode)) { pMI->txt_errno = errno = EINVAL; return MAP_FAILED_PTR; } @@ -126,7 +146,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) if (((flags & MAP_SHARED) == 0) && (prot & PROT_WRITE)) o_flag |= O_EXCL; - pMI->txt_fd = open( pzFile, o_flag ); + pMI->txt_fd = open(pzFile, o_flag); } if (pMI->txt_fd == AO_INVALID_FD) { @@ -187,7 +207,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) pMI->txt_errno = errno; #elif defined(HAVE_DEV_ZERO) - pMI->txt_zero_fd = open( "/dev/zero", O_RDONLY ); + pMI->txt_zero_fd = open("/dev/zero", O_RDONLY); if (pMI->txt_zero_fd == AO_INVALID_FD) { pMI->txt_errno = errno; @@ -202,7 +222,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) return pMI->txt_data; pMI->txt_errno = errno; - close( pMI->txt_zero_fd ); + close(pMI->txt_zero_fd); pMI->txt_zero_fd = -1; } #endif @@ -211,8 +231,8 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) } { - void* p = AGALOC( pMI->txt_size+1, "file text" ); - memcpy( p, pMI->txt_data, pMI->txt_size ); + void* p = AGALOC(pMI->txt_size+1, "file text"); + memcpy(p, pMI->txt_data, pMI->txt_size); ((char*)p)[pMI->txt_size] = NUL; munmap(pMI->txt_data, pMI->txt_size ); pMI->txt_data = p; @@ -222,7 +242,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) #else /* * * * * * no HAVE_MMAP * * * * * */ - pMI->txt_data = AGALOC( pMI->txt_size+1, "file text" ); + pMI->txt_data = AGALOC(pMI->txt_size+1, "file text"); if (pMI->txt_data == NULL) { pMI->txt_errno = ENOMEM; goto fail_return; @@ -233,12 +253,12 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) char* pz = pMI->txt_data; while (sz > 0) { - ssize_t rdct = read( pMI->txt_fd, pz, sz ); + ssize_t rdct = read(pMI->txt_fd, pz, sz); if (rdct <= 0) { pMI->txt_errno = errno; - fprintf( stderr, zFSErrReadFile, - errno, strerror( errno ), pzFile ); - free( pMI->txt_data ); + fprintf(stderr, zFSErrReadFile, + errno, strerror(errno), pzFile); + free(pMI->txt_data); goto fail_return; } @@ -261,7 +281,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) fail_return: if (pMI->txt_fd >= 0) { - close( pMI->txt_fd ); + close(pMI->txt_fd); pMI->txt_fd = -1; } errno = pMI->txt_errno; @@ -290,7 +310,7 @@ text_mmap( char const* pzFile, int prot, int flags, tmap_info_t* pMI ) * err: Any error code issued by munmap(2) or close(2) is possible. =*/ int -text_munmap( tmap_info_t* pMI ) +text_munmap(tmap_info_t* pMI) { #ifdef HAVE_MMAP int res = 0; @@ -306,26 +326,26 @@ text_munmap( tmap_info_t* pMI ) if (lseek(pMI->txt_fd, (size_t)0, SEEK_SET) != 0) goto error_return; - res = (write( pMI->txt_fd, pMI->txt_data, pMI->txt_size ) < 0) + res = (write(pMI->txt_fd, pMI->txt_data, pMI->txt_size) < 0) ? errno : 0; } - AGFREE( pMI->txt_data ); + AGFREE(pMI->txt_data); errno = res; } else { - res = munmap( pMI->txt_data, pMI->txt_full_size ); + res = munmap(pMI->txt_data, pMI->txt_full_size); } if (res != 0) goto error_return; - res = close( pMI->txt_fd ); + res = close(pMI->txt_fd); if (res != 0) goto error_return; pMI->txt_fd = -1; errno = 0; if (pMI->txt_zero_fd != -1) { - res = close( pMI->txt_zero_fd ); + res = close(pMI->txt_zero_fd); pMI->txt_zero_fd = -1; } @@ -341,14 +361,14 @@ text_munmap( tmap_info_t* pMI ) * THEN rewrite the data. */ if ( FILE_WRITABLE(pMI->txt_prot, pMI->txt_flags) - && (lseek( pMI->txt_fd, 0, SEEK_SET ) >= 0) ) { - write( pMI->txt_fd, pMI->txt_data, pMI->txt_size ); + && (lseek(pMI->txt_fd, 0, SEEK_SET) >= 0) ) { + write(pMI->txt_fd, pMI->txt_data, pMI->txt_size); } - close( pMI->txt_fd ); + close(pMI->txt_fd); pMI->txt_fd = -1; pMI->txt_errno = errno; - free( pMI->txt_data ); + free(pMI->txt_data); return pMI->txt_errno; #endif /* HAVE_MMAP */ diff --git a/sntp/libopts/time.c b/sntp/libopts/time.c new file mode 100644 index 000000000000..656c78d60130 --- /dev/null +++ b/sntp/libopts/time.c @@ -0,0 +1,137 @@ + +/** + * \file time.c + * + * Time-stamp: "2011-03-06 11:52:23 bkorb" + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd + */ + +/*=export_func optionTimeVal + * private: + * + * what: process an option with a time duration. + * arg: + tOptions* + pOpts + program options descriptor + + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * + * doc: + * Decipher a time duration value. +=*/ +void +optionTimeVal(tOptions * pOpts, tOptDesc * pOD) +{ + time_t val; + + if ((pOD->fOptState & OPTST_RESET) != 0) + return; + + val = parse_duration(pOD->optArg.argString); + if (val == BAD_TIME) { + fprintf(stderr, zNotDuration, pOpts->pzProgName, pOD->optArg.argString); + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); + } + + if (pOD->fOptState & OPTST_ALLOC_ARG) { + AGFREE(pOD->optArg.argString); + pOD->fOptState &= ~OPTST_ALLOC_ARG; + } + + pOD->optArg.argInt = val; +} + +/*=export_func optionTimeDate + * private: + * + * what: process an option with a time and date. + * arg: + tOptions* + pOpts + program options descriptor + + * arg: + tOptDesc* + pOptDesc + the descriptor for this arg + + * + * doc: + * Decipher a time and date value. +=*/ +void +optionTimeDate(tOptions * pOpts, tOptDesc * pOD) +{ +#if defined(HAVE_GETDATE_R) && defined(HAVE_PUTENV) + if ((! HAS_pzPkgDataDir(pOpts)) || (pOpts->pzPkgDataDir == NULL)) + goto default_action; + + /* + * Export the DATEMSK environment variable. getdate_r() uses it to + * find the file with the strptime formats. If we cannot find the file + * we need ($PKGDATADIR/datemsk), then fall back to just a time duration. + */ + { + static char * envptr = NULL; + + if (envptr == NULL) { + static char const fmt[] = "DATEMSK=%s/datemsk"; + envptr = AGALOC(sizeof(fmt) + strlen(pOpts->pzPkgDataDir), fmt); + sprintf(envptr, fmt, pOpts->pzPkgDataDir); + + putenv(envptr); + } + + if (access(envptr+8, R_OK) != 0) + goto default_action; + } + + /* + * Convert the date to a time since the epoch and stash it in a long int. + */ + { + struct tm stm; + time_t tm; + + if (getdate_r(pOD->optArg.argString, &stm) != 0) { + fprintf(stderr, zNotDate, pOpts->pzProgName, + pOD->optArg.argString); + if ((pOpts->fOptSet & OPTPROC_ERRSTOP) != 0) + (*(pOpts->pUsageProc))(pOpts, EXIT_FAILURE); + return; + } + + tm = mktime(&stm); + + if (pOD->fOptState & OPTST_ALLOC_ARG) { + AGFREE(pOD->optArg.argString); + pOD->fOptState &= ~OPTST_ALLOC_ARG; + } + + pOD->optArg.argInt = tm; + } + return; + +default_action: + +#endif + optionTimeVal(pOpts, pOD); + if (pOD->optArg.argInt != BAD_TIME) + pOD->optArg.argInt += (unsigned long)time(NULL); +} +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of autoopts/time.c */ diff --git a/sntp/libopts/tokenize.c b/sntp/libopts/tokenize.c index 0e576ce26d0a..4ca1245cf066 100644 --- a/sntp/libopts/tokenize.c +++ b/sntp/libopts/tokenize.c @@ -1,26 +1,28 @@ /* * This file defines the string_tokenize interface - * Time-stamp: "2006-06-24 15:27:49 bkorb" + * Time-stamp: "2010-07-17 10:40:26 bkorb" * - * string_tokenize copyright 2005 Bruce Korb + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * string_tokenize is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * string_tokenize 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. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * You should have received a copy of the GNU Lesser General Public - * License along with string_tokenize; if not, write to: - * The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -#include <ctype.h> + #include <errno.h> #include <stdlib.h> @@ -28,16 +30,18 @@ #define ch_t unsigned char /* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ static void -copy_cooked( ch_t** ppDest, char const ** ppSrc ); +copy_cooked(ch_t** ppDest, char const ** ppSrc); static void -copy_raw( ch_t** ppDest, char const ** ppSrc ); +copy_raw(ch_t** ppDest, char const ** ppSrc); + +static token_list_t * +alloc_token_list(char const * str); /* = = = END-STATIC-FORWARD = = = */ static void -copy_cooked( ch_t** ppDest, char const ** ppSrc ) +copy_cooked(ch_t** ppDest, char const ** ppSrc) { ch_t* pDest = (ch_t*)*ppDest; const ch_t* pSrc = (const ch_t*)(*ppSrc + 1); @@ -48,7 +52,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc ) case NUL: *ppSrc = NULL; return; case '"': goto done; case '\\': - pSrc += ao_string_cook_escape_char( (char*)pSrc, (char*)&ch, 0x7F ); + pSrc += ao_string_cook_escape_char((char*)pSrc, (char*)&ch, 0x7F); if (ch == 0x7F) break; /* FALLTHROUGH */ @@ -65,7 +69,7 @@ copy_cooked( ch_t** ppDest, char const ** ppSrc ) static void -copy_raw( ch_t** ppDest, char const ** ppSrc ) +copy_raw(ch_t** ppDest, char const ** ppSrc) { ch_t* pDest = *ppDest; cc_t* pSrc = (cc_t*) (*ppSrc + 1); @@ -111,6 +115,53 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) *ppSrc = (char const *) pSrc; /* char following closing quote */ } +static token_list_t * +alloc_token_list(char const * str) +{ + token_list_t * res; + + int max_token_ct = 2; /* allow for trailing NULL pointer & NUL on string */ + + if (str == NULL) goto enoent_res; + + /* + * Trim leading white space. Use "ENOENT" and a NULL return to indicate + * an empty string was passed. + */ + while (IS_WHITESPACE_CHAR(*str)) str++; + if (*str == NUL) goto enoent_res; + + /* + * Take an approximate count of tokens. If no quoted strings are used, + * it will be accurate. If quoted strings are used, it will be a little + * high and we'll squander the space for a few extra pointers. + */ + { + cc_t* pz = (cc_t*)str; + + do { + max_token_ct++; + while (! IS_WHITESPACE_CHAR(*++pz)) + if (*pz == NUL) goto found_nul; + while (IS_WHITESPACE_CHAR(*pz)) pz++; + } while (*pz != NUL); + + found_nul: + res = malloc(sizeof(*res) + (pz - (cc_t*)str) + + (max_token_ct * sizeof(ch_t*))); + } + + if (res == NULL) + errno = ENOMEM; + else res->tkn_list[0] = (ch_t*)(res->tkn_list + (max_token_ct - 1)); + + return res; + + enoent_res: + + errno = ENOENT; + return NULL; +} /*=export_func ao_string_tokenize * @@ -159,10 +210,10 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) * @example * #include <stdlib.h> * int ix; - * token_list_t* ptl = ao_string_tokenize( some_string ) + * token_list_t* ptl = ao_string_tokenize(some_string) * for (ix = 0; ix < ptl->tkn_ct; ix++) - * do_something_with_tkn( ptl->tkn_list[ix] ); - * free( ptl ); + * do_something_with_tkn(ptl->tkn_list[ix]); + * free(ptl); * @end example * Note that everything is freed with the one call to @code{free(3C)}. * @@ -178,106 +229,69 @@ copy_raw( ch_t** ppDest, char const ** ppSrc ) * @end itemize =*/ token_list_t* -ao_string_tokenize( char const* str ) +ao_string_tokenize(char const* str) { - int max_token_ct = 1; /* allow for trailing NUL on string */ - token_list_t* res; - - if (str == NULL) goto bogus_str; - - /* - * Trim leading white space. Use "ENOENT" and a NULL return to indicate - * an empty string was passed. - */ - while (isspace( (ch_t)*str )) str++; - if (*str == NUL) { - bogus_str: - errno = ENOENT; - return NULL; - } + token_list_t* res = alloc_token_list(str); + ch_t* pzDest; /* - * Take an approximate count of tokens. If no quoted strings are used, - * it will be accurate. If quoted strings are used, it will be a little - * high and we'll squander the space for a few extra pointers. + * Now copy each token into the output buffer. */ - { - cc_t* pz = (cc_t*)str; - - do { - max_token_ct++; - while (! isspace( *++pz )) - if (*pz == NUL) goto found_nul; - while (isspace( *pz )) pz++; - } while (*pz != NUL); + if (res == NULL) + return res; - found_nul: - ; - } + pzDest = (ch_t*)(res->tkn_list[0]); + res->tkn_ct = 0; - res = malloc( sizeof(*res) + strlen(str) + (max_token_ct * sizeof(ch_t*)) ); - if (res == NULL) { - errno = ENOMEM; - return res; - } + do { + res->tkn_list[ res->tkn_ct++ ] = pzDest; + for (;;) { + int ch = (ch_t)*str; + if (IS_WHITESPACE_CHAR(ch)) { + found_white_space: + while (IS_WHITESPACE_CHAR(*++str)) ; + break; + } - /* - * Now copy each token into the output buffer. - */ - { - ch_t* pzDest = (ch_t*)(res->tkn_list + (max_token_ct + 1)); - res->tkn_ct = 0; - - do { - res->tkn_list[ res->tkn_ct++ ] = pzDest; - for (;;) { - int ch = (ch_t)*str; - if (isspace( ch )) { - found_white_space: - while (isspace( (ch_t)*++str )) ; - break; + switch (ch) { + case '"': + copy_cooked(&pzDest, &str); + if (str == NULL) { + free(res); + errno = EINVAL; + return NULL; } + if (IS_WHITESPACE_CHAR(*str)) + goto found_white_space; + break; - switch (ch) { - case '"': - copy_cooked( &pzDest, &str ); - if (str == NULL) { - free(res); - errno = EINVAL; - return NULL; - } - if (isspace( (ch_t)*str )) - goto found_white_space; - break; - - case '\'': - copy_raw( &pzDest, &str ); - if (str == NULL) { - free(res); - errno = EINVAL; - return NULL; - } - if (isspace( (ch_t)*str )) - goto found_white_space; - break; - - case NUL: - goto copy_done; - - default: - str++; - *(pzDest++) = ch; + case '\'': + copy_raw(&pzDest, &str); + if (str == NULL) { + free(res); + errno = EINVAL; + return NULL; } - } copy_done:; + if (IS_WHITESPACE_CHAR(*str)) + goto found_white_space; + break; - /* - * NUL terminate the last token and see if we have any more tokens. - */ - *(pzDest++) = NUL; - } while (*str != NUL); + case NUL: + goto copy_done; - res->tkn_list[ res->tkn_ct ] = NULL; - } + default: + str++; + *(pzDest++) = ch; + } + } copy_done:; + + /* + * NUL terminate the last token and see if we have any more tokens. + */ + *(pzDest++) = NUL; + } while (*str != NUL); + + res->tkn_list[ res->tkn_ct ] = NULL; return res; } @@ -287,7 +301,7 @@ ao_string_tokenize( char const* str ) #include <string.h> int -main( int argc, char** argv ) +main(int argc, char** argv) { if (argc == 1) { printf("USAGE: %s arg [ ... ]\n", *argv); @@ -295,15 +309,15 @@ main( int argc, char** argv ) } while (--argc > 0) { char* arg = *(++argv); - token_list_t* p = ao_string_tokenize( arg ); + token_list_t* p = ao_string_tokenize(arg); if (p == NULL) { - printf( "Parsing string ``%s'' failed:\n\terrno %d (%s)\n", - arg, errno, strerror( errno )); + printf("Parsing string ``%s'' failed:\n\terrno %d (%s)\n", + arg, errno, strerror(errno)); } else { int ix = 0; - printf( "Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct ); + printf("Parsed string ``%s''\ninto %d tokens:\n", arg, p->tkn_ct); do { - printf( " %3d: ``%s''\n", ix+1, p->tkn_list[ix] ); + printf(" %3d: ``%s''\n", ix+1, p->tkn_list[ix]); } while (++ix < p->tkn_ct); free(p); } diff --git a/sntp/libopts/usage.c b/sntp/libopts/usage.c index 960339b63cbc..4d106675c304 100644 --- a/sntp/libopts/usage.c +++ b/sntp/libopts/usage.c @@ -1,7 +1,8 @@ /* - * usage.c $Id: usage.c,v 4.15 2007/04/28 22:19:23 bkorb Exp $ - * Time-stamp: "2007-04-15 11:02:46 bkorb" + * \file usage.c + * + * Time-stamp: "2011-02-01 14:42:37 bkorb" * * This module implements the default usage procedure for * Automated Options. It may be overridden, of course. @@ -13,117 +14,183 @@ */ /* - * Automated Options copyright 1992-2007 Bruce Korb - * - * Automated Options is free software. - * You may 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. - * - * Automated Options 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. + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * You should have received a copy of the GNU General Public License - * along with Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * These files have the following md5sums: * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. - * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ #define OPTPROC_L_N_S (OPTPROC_LONGOPT | OPTPROC_SHORTOPT) -static arg_types_t argTypes; +/* = = = START-STATIC-FORWARD = = = */ +static void +set_usage_flags(tOptions * opts, char const * flg_txt); + +static inline ag_bool +do_gnu_usage(tOptions * pOpts); -FILE* option_usage_fp = NULL; -static char zOptFmtLine[ 16 ]; -static ag_bool displayEnum; +static inline ag_bool +skip_misuse_usage(tOptions * pOpts); -/* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ -static ag_bool -checkGNUUsage( tOptions* pOpts ); +static void +print_usage_details(tOptions * opts, int exit_code); + +static void +prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printExtendedUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ); +prt_ini_list(char const * const * papz, ag_bool * pInitIntro, + char const * pzRc, char const * pzPN); static void -printInitList( - tCC* const* papz, - ag_bool* pInitIntro, - tCC* pzRc, - tCC* pzPN ); +prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printOneUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ); +prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT); static void -printOptionUsage( - tOptions* pOpts, - int ex_code, - tCC* pOptTitle ); +prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle); static void -printProgramDetails( tOptions* pOptions ); +prt_prog_detail(tOptions* pOptions); static int -setGnuOptFmts( tOptions* pOpts, tCC** ppT ); +setGnuOptFmts(tOptions* pOpts, tCC** ppT); static int -setStdOptFmts( tOptions* pOpts, tCC** ppT ); +setStdOptFmts(tOptions* pOpts, tCC** ppT); /* = = = END-STATIC-FORWARD = = = */ - /* - * Figure out if we should try to format usage text sort-of like - * the way many GNU programs do. + * NB: no entry may be a prefix of another entry */ -static ag_bool -checkGNUUsage( tOptions* pOpts ) +#define AOFLAG_TABLE \ + _aof_(gnu, OPTPROC_GNUUSAGE ) \ + _aof_(autoopts, ~OPTPROC_GNUUSAGE) \ + _aof_(no_misuse_usage, OPTPROC_MISUSE ) \ + _aof_(misuse_usage, ~OPTPROC_MISUSE ) + +static void +set_usage_flags(tOptions * opts, char const * flg_txt) { - char* pz = getenv( "AUTOOPTS_USAGE" ); - if (pz == NULL) - ; + typedef struct { + size_t fnm_len; + uint32_t fnm_mask; + char const * fnm_name; + } ao_flag_names_t; + +# define _aof_(_n, _f) AOUF_ ## _n ## _ID, + typedef enum { AOFLAG_TABLE AOUF_COUNT } ao_flag_id_t; +# undef _aof_ + +# define _aof_(_n, _f) AOUF_ ## _n = (1 << AOUF_ ## _n ## _ID), + typedef enum { AOFLAG_TABLE } ao_flags_t; +# undef _aof_ + +# define _aof_(_n, _f) { sizeof(#_n)-1, _f, #_n }, + static ao_flag_names_t const fn_table[AOUF_COUNT] = { + AOFLAG_TABLE + }; +# undef _aof_ + + ao_flags_t flg = 0; + + if (flg_txt == NULL) { + flg_txt = getenv("AUTOOPTS_USAGE"); + if (flg_txt == NULL) + return; + } - else if (streqvcmp( pz, "gnu" ) == 0) - pOpts->fOptSet |= OPTPROC_GNUUSAGE; + while (IS_WHITESPACE_CHAR(*flg_txt)) flg_txt++; + if (*flg_txt == NUL) + return; - else if (streqvcmp( pz, "autoopts" ) == 0) - pOpts->fOptSet &= ~OPTPROC_GNUUSAGE; + for (;;) { + int ix = 0; + ao_flag_names_t const * fnt = fn_table; + + for (;;) { + if (strneqvcmp(flg_txt, fnt->fnm_name, fnt->fnm_len) == 0) + break; + if (++ix >= AOUF_COUNT) + return; + fnt++; + } + /* + * Make sure we have a full match. Look for whitespace, + * a comma, or a NUL byte. + */ + if (! IS_END_LIST_ENTRY_CHAR(flg_txt[fnt->fnm_len])) + return; + + flg |= 1 << ix; + flg_txt += fnt->fnm_len; + while (IS_WHITESPACE_CHAR(*flg_txt)) flg_txt++; + + if (*flg_txt == NUL) + break; + + if (*flg_txt == ',') { + /* + * skip the comma and following white space + */ + while (IS_WHITESPACE_CHAR(*++flg_txt)) ; + if (*flg_txt == NUL) + break; + } + } + + { + ao_flag_names_t const * fnm = fn_table; + + while (flg != 0) { + if ((flg & 1) != 0) { + if ((fnm->fnm_mask & OPTPROC_LONGOPT) != 0) + opts->fOptSet &= fnm->fnm_mask; + else opts->fOptSet |= fnm->fnm_mask; + } + flg >>= 1; + fnm++; + } + } +} + +/* + * Figure out if we should try to format usage text sort-of like + * the way many GNU programs do. + */ +static inline ag_bool +do_gnu_usage(tOptions * pOpts) +{ return (pOpts->fOptSet & OPTPROC_GNUUSAGE) ? AG_TRUE : AG_FALSE; } +/* + * Figure out if we should try to format usage text sort-of like + * the way many GNU programs do. + */ +static inline ag_bool +skip_misuse_usage(tOptions * pOpts) +{ + return (pOpts->fOptSet & OPTPROC_MISUSE) ? AG_TRUE : AG_FALSE; +} + /*=export_func optionOnlyUsage * @@ -137,23 +204,107 @@ checkGNUUsage( tOptions* pOpts ) * information not available to AutoOpts. =*/ void -optionOnlyUsage( - tOptions* pOpts, - int ex_code ) +optionOnlyUsage(tOptions * pOpts, int ex_code) { - tCC* pOptTitle = NULL; + char const * pOptTitle = NULL; + + set_usage_flags(pOpts, NULL); + if ((ex_code != EXIT_SUCCESS) && + skip_misuse_usage(pOpts)) + return; /* * Determine which header and which option formatting strings to use */ - if (checkGNUUsage(pOpts)) { - (void)setGnuOptFmts( pOpts, &pOptTitle ); + if (do_gnu_usage(pOpts)) { + (void)setGnuOptFmts(pOpts, &pOptTitle); } else { - (void)setStdOptFmts( pOpts, &pOptTitle ); + (void)setStdOptFmts(pOpts, &pOptTitle); + } + + prt_opt_usage(pOpts, ex_code, pOptTitle); + + fflush(option_usage_fp); + if (ferror(option_usage_fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } +} + +static void +print_usage_details(tOptions * opts, int exit_code) +{ + { + char const * pOptTitle = NULL; + + /* + * Determine which header and which option formatting strings to use + */ + if (do_gnu_usage(opts)) { + int flen = setGnuOptFmts(opts, &pOptTitle); + sprintf(zOptFmtLine, zFmtFmt, flen); + fputc('\n', option_usage_fp); + } + else { + int flen = setStdOptFmts(opts, &pOptTitle); + sprintf(zOptFmtLine, zFmtFmt, flen); + + /* + * When we exit with EXIT_SUCCESS and the first option is a doc + * option, we do *NOT* want to emit the column headers. + * Otherwise, we do. + */ + if ( (exit_code != EXIT_SUCCESS) + || ((opts->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) ) + + fputs(pOptTitle, option_usage_fp); + } + + prt_opt_usage(opts, exit_code, pOptTitle); + } + + /* + * Describe the mechanics of denoting the options + */ + switch (opts->fOptSet & OPTPROC_L_N_S) { + case OPTPROC_L_N_S: fputs(zFlagOkay, option_usage_fp); break; + case OPTPROC_SHORTOPT: break; + case OPTPROC_LONGOPT: fputs(zNoFlags, option_usage_fp); break; + case 0: fputs(zOptsOnly, option_usage_fp); break; } - printOptionUsage( pOpts, ex_code, pOptTitle ); + if ((opts->fOptSet & OPTPROC_NUM_OPT) != 0) + fputs(zNumberOpt, option_usage_fp); + + if ((opts->fOptSet & OPTPROC_REORDER) != 0) + fputs(zReorder, option_usage_fp); + + if (opts->pzExplain != NULL) + fputs(opts->pzExplain, option_usage_fp); + + /* + * IF the user is asking for help (thus exiting with SUCCESS), + * THEN see what additional information we can provide. + */ + if (exit_code == EXIT_SUCCESS) + prt_prog_detail(opts); + + /* + * Give bug notification preference to the packager information + */ + if (HAS_pzPkgDataDir(opts) && (opts->pzPackager != NULL)) + fputs(opts->pzPackager, option_usage_fp); + + else if (opts->pzBugAddr != NULL) + fprintf(option_usage_fp, zPlsSendBugs, opts->pzBugAddr); + + fflush(option_usage_fp); + + if (ferror(option_usage_fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } } @@ -174,11 +325,9 @@ optionOnlyUsage( * and the actual exit code will be "EXIT_SUCCESS". =*/ void -optionUsage( - tOptions* pOptions, - int usage_exit_code ) +optionUsage(tOptions * pOptions, int usage_exit_code) { - int actual_exit_code = + int exit_code = (usage_exit_code == EX_USAGE) ? EXIT_SUCCESS : usage_exit_code; displayEnum = AG_FALSE; @@ -187,74 +336,42 @@ optionUsage( * Paged usage will preset option_usage_fp to an output file. * If it hasn't already been set, then set it to standard output * on successful exit (help was requested), otherwise error out. + * + * Test the version before obtaining pzFullUsage or pzShortUsage. + * These fields do not exist before revision 30. */ - if (option_usage_fp == NULL) - option_usage_fp = (actual_exit_code != EXIT_SUCCESS) ? stderr : stdout; - - fprintf( option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName ); - { - tCC* pOptTitle = NULL; + char const * pz; - /* - * Determine which header and which option formatting strings to use - */ - if (checkGNUUsage(pOptions)) { - int flen = setGnuOptFmts( pOptions, &pOptTitle ); - sprintf( zOptFmtLine, zFmtFmt, flen ); - fputc( '\n', option_usage_fp ); - } - else { - int flen = setStdOptFmts( pOptions, &pOptTitle ); - sprintf( zOptFmtLine, zFmtFmt, flen ); + if (exit_code == EXIT_SUCCESS) { + pz = (pOptions->structVersion >= 30 * 4096) + ? pOptions->pzFullUsage : NULL; - /* - * When we exit with EXIT_SUCCESS and the first option is a doc - * option, we do *NOT* want to emit the column headers. - * Otherwise, we do. - */ - if ( (usage_exit_code != EXIT_SUCCESS) - || ((pOptions->pOptDesc->fOptState & OPTST_DOCUMENT) == 0) ) + if (option_usage_fp == NULL) + option_usage_fp = stdout; + } else { + pz = (pOptions->structVersion >= 30 * 4096) + ? pOptions->pzShortUsage : NULL; - fputs( pOptTitle, option_usage_fp ); + if (option_usage_fp == NULL) + option_usage_fp = stderr; } - printOptionUsage( pOptions, usage_exit_code, pOptTitle ); - } - - /* - * Describe the mechanics of denoting the options - */ - switch (pOptions->fOptSet & OPTPROC_L_N_S) { - case OPTPROC_L_N_S: fputs( zFlagOkay, option_usage_fp ); break; - case OPTPROC_SHORTOPT: break; - case OPTPROC_LONGOPT: fputs( zNoFlags, option_usage_fp ); break; - case 0: fputs( zOptsOnly, option_usage_fp ); break; - } - - if ((pOptions->fOptSet & OPTPROC_NUM_OPT) != 0) { - fputs( zNumberOpt, option_usage_fp ); - } - - if ((pOptions->fOptSet & OPTPROC_REORDER) != 0) { - fputs( zReorder, option_usage_fp ); + if (pz != NULL) { + fputs(pz, option_usage_fp); + exit(exit_code); + } } - if (pOptions->pzExplain != NULL) - fputs( pOptions->pzExplain, option_usage_fp ); + fprintf(option_usage_fp, pOptions->pzUsageTitle, pOptions->pzProgName); + set_usage_flags(pOptions, NULL); - /* - * IF the user is asking for help (thus exiting with SUCCESS), - * THEN see what additional information we can provide. - */ - if (usage_exit_code == EXIT_SUCCESS) - printProgramDetails( pOptions ); + if ((exit_code == EXIT_SUCCESS) || + (! skip_misuse_usage(pOptions))) - if (pOptions->pzBugAddr != NULL) - fprintf( option_usage_fp, zPlsSendBugs, pOptions->pzBugAddr ); - fflush( option_usage_fp ); + print_usage_details(pOptions, usage_exit_code); - exit( actual_exit_code ); + exit(exit_code); } @@ -263,10 +380,7 @@ optionUsage( * PER OPTION TYPE USAGE INFORMATION */ static void -printExtendedUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ) +prt_extd_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) { /* * IF there are option conflicts or dependencies, @@ -275,7 +389,7 @@ printExtendedUsage( if ( (pOD->pOptMust != NULL) || (pOD->pOptCant != NULL) ) { - fputs( zTabHyp, option_usage_fp ); + fputs(zTabHyp, option_usage_fp); /* * DEPENDENCIES: @@ -283,16 +397,16 @@ printExtendedUsage( if (pOD->pOptMust != NULL) { const int* pOptNo = pOD->pOptMust; - fputs( zReqThese, option_usage_fp ); + fputs(zReqThese, option_usage_fp); for (;;) { - fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[ - *pOptNo ].pz_Name ); + fprintf(option_usage_fp, zTabout, + pOptions->pOptDesc[*pOptNo].pz_Name); if (*++pOptNo == NO_EQUIVALENT) break; } if (pOD->pOptCant != NULL) - fputs( zTabHypAnd, option_usage_fp ); + fputs(zTabHypAnd, option_usage_fp); } /* @@ -301,10 +415,10 @@ printExtendedUsage( if (pOD->pOptCant != NULL) { const int* pOptNo = pOD->pOptCant; - fputs( zProhib, option_usage_fp ); + fputs(zProhib, option_usage_fp); for (;;) { - fprintf( option_usage_fp, zTabout, pOptions->pOptDesc[ - *pOptNo ].pz_Name ); + fprintf(option_usage_fp, zTabout, + pOptions->pOptDesc[*pOptNo].pz_Name); if (*++pOptNo == NO_EQUIVALENT) break; } @@ -316,16 +430,26 @@ printExtendedUsage( * THEN print the disablement info */ if (pOD->pz_DisableName != NULL ) - fprintf( option_usage_fp, zDis, pOD->pz_DisableName ); + fprintf(option_usage_fp, zDis, pOD->pz_DisableName); /* - * IF the numeric option has a special callback, - * THEN call it, requesting the range or other special info + * Check for argument types that have callbacks with magical properties */ - if ( (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NUMERIC) - && (pOD->pOptProc != NULL) - && (pOD->pOptProc != optionNumericVal) ) { - (*(pOD->pOptProc))( pOptions, NULL ); + switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + case OPARG_TYPE_NUMERIC: + /* + * IF the numeric option has a special callback, + * THEN call it, requesting the range or other special info + */ + if ( (pOD->pOptProc != NULL) + && (pOD->pOptProc != optionNumericVal) ) { + (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); + } + break; + + case OPARG_TYPE_FILE: + (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); + break; } /* @@ -333,7 +457,7 @@ printExtendedUsage( * THEN print that out */ if (pOD->fOptState & OPTST_INITENABLED) - fputs( zEnab, option_usage_fp ); + fputs(zEnab, option_usage_fp); /* * IF the option is in an equivalence class @@ -342,8 +466,8 @@ printExtendedUsage( */ if ( (pOD->optEquivIndex != NO_EQUIVALENT) && (pOD->optEquivIndex != pOD->optActualIndex ) ) { - fprintf( option_usage_fp, zAlt, - pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name ); + fprintf(option_usage_fp, zAlt, + pOptions->pOptDesc[ pOD->optEquivIndex ].pz_Name); return; } @@ -360,25 +484,25 @@ printExtendedUsage( && (pOD->optIndex < pOptions->presetOptCt) ) - fputs( zNoPreset, option_usage_fp ); + fputs(zNoPreset, option_usage_fp); /* * Print the appearance requirements. */ if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_MEMBERSHIP) - fputs( zMembers, option_usage_fp ); + fputs(zMembers, option_usage_fp); else switch (pOD->optMinCt) { case 1: case 0: switch (pOD->optMaxCt) { - case 0: fputs( zPreset, option_usage_fp ); break; - case NOLIMIT: fputs( zNoLim, option_usage_fp ); break; + case 0: fputs(zPreset, option_usage_fp); break; + case NOLIMIT: fputs(zNoLim, option_usage_fp); break; case 1: break; /* * IF the max is more than one but limited, print "UP TO" message */ - default: fprintf( option_usage_fp, zUpTo, pOD->optMaxCt ); break; + default: fprintf(option_usage_fp, zUpTo, pOD->optMaxCt); break; } break; @@ -386,12 +510,12 @@ printExtendedUsage( /* * More than one is required. Print the range. */ - fprintf( option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt ); + fprintf(option_usage_fp, zMust, pOD->optMinCt, pOD->optMaxCt); } - if ( NAMED_OPTS( pOptions ) + if ( NAMED_OPTS(pOptions) && (pOptions->specOptIdx.default_opt == pOD->optIndex)) - fputs( zDefaultOpt, option_usage_fp ); + fputs(zDefaultOpt, option_usage_fp); } @@ -403,34 +527,43 @@ printExtendedUsage( * squishy, but important to tell users how to find these files. */ static void -printInitList( - tCC* const* papz, - ag_bool* pInitIntro, - tCC* pzRc, - tCC* pzPN ) +prt_ini_list(char const * const * papz, ag_bool * pInitIntro, + char const * pzRc, char const * pzPN) { - char zPath[ AG_PATH_MAX+1 ]; + char zPath[AG_PATH_MAX+1]; if (papz == NULL) return; - fputs( zPresetIntro, option_usage_fp ); + fputs(zPresetIntro, option_usage_fp); *pInitIntro = AG_FALSE; for (;;) { - char const* pzPath = *(papz++); + char const * pzPath = *(papz++); + char const * pzReal = zPath; if (pzPath == NULL) break; - if (optionMakePath(zPath, (int)sizeof( zPath ), pzPath, pzPN)) - pzPath = zPath; + /* + * Ignore any invalid paths + */ + if (! optionMakePath(zPath, (int)sizeof(zPath), pzPath, pzPN)) + pzReal = pzPath; + + /* + * Expand paths that are relative to the executable or installation + * directories. Leave alone paths that use environment variables. + */ + else if ((*pzPath == '$') + && ((pzPath[1] == '$') || (pzPath[1] == '@'))) + pzPath = pzReal; /* * Print the name of the "homerc" file. If the "rcfile" name is * not empty, we may or may not print that, too... */ - fprintf( option_usage_fp, zPathFmt, pzPath ); + fprintf(option_usage_fp, zPathFmt, pzPath); if (*pzRc != NUL) { struct stat sb; @@ -438,26 +571,19 @@ printInitList( * IF the "homerc" file is a directory, * then append the "rcfile" name. */ - if ( (stat( pzPath, &sb ) == 0) - && S_ISDIR( sb.st_mode ) ) { - fputc( DIRCH, option_usage_fp ); - fputs( pzRc, option_usage_fp ); + if ((stat(pzReal, &sb) == 0) && S_ISDIR(sb.st_mode)) { + fputc(DIRCH, option_usage_fp); + fputs(pzRc, option_usage_fp); } } - fputc( '\n', option_usage_fp ); + fputc('\n', option_usage_fp); } } -/* - * Print the usage information for a single option. - */ static void -printOneUsage( - tOptions* pOptions, - tOptDesc* pOD, - arg_types_t* pAT ) +prt_preamble(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) { /* * Flag prefix: IF no flags at all, then omit it. If not printable @@ -466,47 +592,59 @@ printOneUsage( * opts are to be printed too. */ if ((pOptions->fOptSet & OPTPROC_SHORTOPT) == 0) - fputs( pAT->pzSpc, option_usage_fp ); - else if (! isgraph( pOD->optValue)) { + fputs(pAT->pzSpc, option_usage_fp); + + else if (! IS_GRAPHIC_CHAR(pOD->optValue)) { if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) - fputc( ' ', option_usage_fp ); - fputs( pAT->pzNoF, option_usage_fp ); + fputc(' ', option_usage_fp); + fputs(pAT->pzNoF, option_usage_fp); + } else { - fprintf( option_usage_fp, " -%c", pOD->optValue ); + fprintf(option_usage_fp, " -%c", pOD->optValue); if ( (pOptions->fOptSet & (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) == (OPTPROC_GNUUSAGE|OPTPROC_LONGOPT)) - fputs( ", ", option_usage_fp ); + fputs(", ", option_usage_fp); } +} + +/* + * Print the usage information for a single option. + */ +static void +prt_one_usage(tOptions * pOptions, tOptDesc * pOD, arg_types_t * pAT) +{ + prt_preamble(pOptions, pOD, pAT); { - char z[ 80 ]; - tCC* pzArgType; + char z[ 80 ]; + char const * pzArgType; + /* * Determine the argument type string first on its usage, then, * when the option argument is required, base the type string on the * argument type. */ - if (OPTST_GET_ARGTYPE(pOD->fOptState) == OPARG_TYPE_NONE) { - pzArgType = pAT->pzNo; - - } else if (pOD->fOptState & OPTST_ARG_OPTIONAL) { + if (pOD->fOptState & OPTST_ARG_OPTIONAL) { pzArgType = pAT->pzOpt; } else switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { + case OPARG_TYPE_NONE: pzArgType = pAT->pzNo; break; case OPARG_TYPE_ENUMERATION: pzArgType = pAT->pzKey; break; + case OPARG_TYPE_FILE: pzArgType = pAT->pzFile; break; case OPARG_TYPE_MEMBERSHIP: pzArgType = pAT->pzKeyL; break; case OPARG_TYPE_BOOLEAN: pzArgType = pAT->pzBool; break; case OPARG_TYPE_NUMERIC: pzArgType = pAT->pzNum; break; case OPARG_TYPE_HIERARCHY: pzArgType = pAT->pzNest; break; case OPARG_TYPE_STRING: pzArgType = pAT->pzStr; break; - default: goto bogus_desc; break; + case OPARG_TYPE_TIME: pzArgType = pAT->pzTime; break; + default: goto bogus_desc; } - snprintf( z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name, - (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt ); + snprintf(z, sizeof(z), pAT->pzOptFmt, pzArgType, pOD->pz_Name, + (pOD->optMinCt != 0) ? pAT->pzReq : pAT->pzOpt); - fprintf( option_usage_fp, zOptFmtLine, z, pOD->pzText ); + fprintf(option_usage_fp, zOptFmtLine, z, pOD->pzText); switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_ENUMERATION: @@ -517,8 +655,8 @@ printOneUsage( return; bogus_desc: - fprintf( stderr, zInvalOptDesc, pOD->pz_Name ); - exit( EX_SOFTWARE ); + fprintf(stderr, zInvalOptDesc, pOD->pz_Name); + exit(EX_SOFTWARE); } @@ -526,19 +664,34 @@ printOneUsage( * Print out the usage information for just the options. */ static void -printOptionUsage( - tOptions* pOpts, - int ex_code, - tCC* pOptTitle ) +prt_opt_usage(tOptions * pOpts, int ex_code, char const * pOptTitle) { - int ct = pOpts->optCt; - int optNo = 0; - tOptDesc* pOD = pOpts->pOptDesc; - int docCt = 0; + int ct = pOpts->optCt; + int optNo = 0; + tOptDesc * pOD = pOpts->pOptDesc; + int docCt = 0; do { - if ((pOD->fOptState & OPTST_OMITTED) != 0) + if ((pOD->fOptState & OPTST_NO_USAGE_MASK) != 0) { + + /* + * IF this is a compiled-out option + * *AND* usage was requested with "omitted-usage" + * *AND* this is NOT abbreviated usage + * THEN display this option. + */ + if ( (pOD->fOptState == (OPTST_OMITTED | OPTST_NO_INIT)) + && (pOD->pz_Name != NULL) + && (ex_code == EXIT_SUCCESS)) { + + char const * why_pz = + (pOD->pzText == NULL) ? zDisabledWhy : pOD->pzText; + prt_preamble(pOpts, pOD, &argTypes); + fprintf(option_usage_fp, zDisabledOpt, pOD->pz_Name, why_pz); + } + continue; + } if ((pOD->fOptState & OPTST_DOCUMENT) != 0) { if (ex_code == EXIT_SUCCESS) { @@ -558,23 +711,23 @@ printOptionUsage( * THEN document that the remaining options are not user opts */ if ( (pOpts->presetOptCt == optNo) - && (ex_code == EXIT_SUCCESS) - && (docCt > 0) - && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) ) - fprintf( option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle ); + && (ex_code == EXIT_SUCCESS) + && (docCt > 0) + && ((pOD[-1].fOptState & OPTST_DOCUMENT) == 0) ) + fprintf(option_usage_fp, argTypes.pzBrk, zAuto, pOptTitle); - printOneUsage( pOpts, pOD, &argTypes ); + prt_one_usage(pOpts, pOD, &argTypes); /* * IF we were invoked because of the --help option, * THEN print all the extra info */ if (ex_code == EXIT_SUCCESS) - printExtendedUsage( pOpts, pOD, &argTypes ); + prt_extd_usage(pOpts, pOD, &argTypes); } while (pOD++, optNo++, (--ct > 0)); - fputc( '\n', option_usage_fp ); + fputc('\n', option_usage_fp); } @@ -583,24 +736,24 @@ printOptionUsage( * PROGRAM DETAILS */ static void -printProgramDetails( tOptions* pOptions ) +prt_prog_detail(tOptions* pOptions) { ag_bool initIntro = AG_TRUE; /* * Display all the places we look for config files */ - printInitList( pOptions->papzHomeList, &initIntro, - pOptions->pzRcName, pOptions->pzProgPath ); + prt_ini_list(pOptions->papzHomeList, &initIntro, + pOptions->pzRcName, pOptions->pzProgPath); /* * Let the user know about environment variable settings */ if ((pOptions->fOptSet & OPTPROC_ENVIRON) != 0) { if (initIntro) - fputs( zPresetIntro, option_usage_fp ); + fputs(zPresetIntro, option_usage_fp); - fprintf( option_usage_fp, zExamineFmt, pOptions->pzPROGNAME ); + fprintf(option_usage_fp, zExamineFmt, pOptions->pzPROGNAME); } /* @@ -613,13 +766,13 @@ printProgramDetails( tOptions* pOptions ) int optNo = 0; tOptDesc* pOD = pOptions->pOptDesc; - fputc( '\n', option_usage_fp ); - fflush( option_usage_fp ); + fputc('\n', option_usage_fp); + fflush(option_usage_fp); do { switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_ENUMERATION: case OPARG_TYPE_MEMBERSHIP: - (*(pOD->pOptProc))( NULL, pOD ); + (*(pOD->pOptProc))(OPTPROC_EMIT_USAGE, pOD); } } while (pOD++, optNo++, (--ct > 0)); } @@ -628,7 +781,7 @@ printProgramDetails( tOptions* pOptions ) * If there is a detail string, now is the time for that. */ if (pOptions->pzDetail != NULL) - fputs( pOptions->pzDetail, option_usage_fp ); + fputs(pOptions->pzDetail, option_usage_fp); } @@ -647,7 +800,7 @@ printProgramDetails( tOptions* pOptions ) * Set up the formatting for GNU-style output */ static int -setGnuOptFmts( tOptions* pOpts, tCC** ppT ) +setGnuOptFmts(tOptions* pOpts, tCC** ppT) { int flen = 22; *ppT = zNoRq_ShrtTtl; @@ -657,6 +810,8 @@ setGnuOptFmts( tOptions* pOpts, tCC** ppT ) argTypes.pzNum = zGnuNumArg; argTypes.pzKey = zGnuKeyArg; argTypes.pzKeyL = zGnuKeyLArg; + argTypes.pzTime = zGnuTimeArg; + argTypes.pzFile = zGnuFileArg; argTypes.pzBool = zGnuBoolArg; argTypes.pzNest = zGnuNestArg; argTypes.pzOpt = zGnuOptArg; @@ -685,7 +840,7 @@ setGnuOptFmts( tOptions* pOpts, tCC** ppT ) * Standard (AutoOpts normal) option line formatting */ static int -setStdOptFmts( tOptions* pOpts, tCC** ppT ) +setStdOptFmts(tOptions* pOpts, tCC** ppT) { int flen = 0; @@ -694,6 +849,8 @@ setStdOptFmts( tOptions* pOpts, tCC** ppT ) argTypes.pzNum = zStdNumArg; argTypes.pzKey = zStdKeyArg; argTypes.pzKeyL = zStdKeyLArg; + argTypes.pzTime = zStdTimeArg; + argTypes.pzFile = zStdFileArg; argTypes.pzBool = zStdBoolArg; argTypes.pzNest = zStdNestArg; argTypes.pzOpt = zStdOptArg; diff --git a/sntp/libopts/value-type.c b/sntp/libopts/value-type.c new file mode 100644 index 000000000000..ff98c0a1ede1 --- /dev/null +++ b/sntp/libopts/value-type.c @@ -0,0 +1,123 @@ +/* ANSI-C code produced by gperf version 3.0.4 */ + + +#if 0 /* gperf build options: */ +// %struct-type +// %language=ANSI-C +// %includes +// %global-table +// %omit-struct-type +// %readonly-tables +// %compare-strncmp +// +// %define slot-name vtp_name +// %define hash-function-name value_type_hash +// %define lookup-function-name find_value_type_name +// %define word-array-name value_type_table +// %define initializer-suffix ,VTP_COUNT_KWD +#endif /* gperf build options: */ + +#include "value-type.h" + +typedef struct { + char const * vtp_name; + value_type_enum_t vtp_id; +} value_type_map_t; +#include <string.h> + +/* maximum key range = 20, duplicates = 0 */ + +#ifdef __GNUC__ +#else +#ifdef __cplusplus +#endif +#endif +inline static unsigned int +value_type_hash (register const char *str, register unsigned int len) +{ + static const unsigned char asso_values[] = + { + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 10, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 5, 23, 23, 5, 0, 0, 23, 15, 23, + 23, 10, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23 + }; + return len + asso_values[(unsigned char)str[2]]; +} + +static const value_type_map_t value_type_table[] = + { + {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD}, + {"",VTP_COUNT_KWD}, + {"set", VTP_KWD_SET}, + {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD}, + {"nested", VTP_KWD_NESTED}, + {"integer", VTP_KWD_INTEGER}, + {"",VTP_COUNT_KWD}, + {"bool", VTP_KWD_BOOL}, + {"",VTP_COUNT_KWD}, + {"string", VTP_KWD_STRING}, + {"boolean", VTP_KWD_BOOLEAN}, + {"",VTP_COUNT_KWD}, + {"set-membership", VTP_KWD_SET_MEMBERSHIP}, + {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD}, + {"keyword", VTP_KWD_KEYWORD}, + {"",VTP_COUNT_KWD}, + {"hierarchy", VTP_KWD_HIERARCHY}, + {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD}, + {"invalid", VTP_KWD_INVALID} + }; + +#ifdef __GNUC__ +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif +#endif +static inline const value_type_map_t * +find_value_type_name (register const char *str, register unsigned int len) +{ + if (len <= 14 && len >= 3) + { + register int key = value_type_hash (str, len); + + if (key <= 22 && key >= 0) + { + register const char *s = value_type_table[key].vtp_name; + + if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') + return &value_type_table[key]; + } + } + return 0; +} + + +value_type_enum_t +find_value_type_id(char const * str, unsigned int len) +{ + const value_type_map_t * p = + find_value_type_name(str, len); + return (p == 0) ? VTP_KWD_INVALID : p->vtp_id; +} diff --git a/sntp/libopts/value-type.h b/sntp/libopts/value-type.h new file mode 100644 index 000000000000..5ff917cb9e7c --- /dev/null +++ b/sntp/libopts/value-type.h @@ -0,0 +1,25 @@ +/* + * Generated header for gperf generated source Fri Apr 29 15:43:59 PDT 2011 + * This file enumerates the list of names and declares the + * procedure for mapping string names to the enum value. + */ +#ifndef AUTOOPTS_VALUE_TYPE_H_GUARD +#define AUTOOPTS_VALUE_TYPE_H_GUARD 1 + +typedef enum { + VTP_KWD_INVALID, + VTP_KWD_STRING, + VTP_KWD_INTEGER, + VTP_KWD_BOOLEAN, + VTP_KWD_BOOL, + VTP_KWD_KEYWORD, + VTP_KWD_SET, + VTP_KWD_SET_MEMBERSHIP, + VTP_KWD_NESTED, + VTP_KWD_HIERARCHY, + VTP_COUNT_KWD +} value_type_enum_t; + +extern value_type_enum_t +find_value_type_id(char const * str, unsigned int len); +#endif /* AUTOOPTS_VALUE_TYPE_H_GUARD */ diff --git a/sntp/libopts/version.c b/sntp/libopts/version.c index 85949d5d3f3b..aae1b87485c8 100644 --- a/sntp/libopts/version.c +++ b/sntp/libopts/version.c @@ -1,60 +1,33 @@ -/* $Id: version.c,v 4.10 2007/04/28 22:19:23 bkorb Exp $ - * Time-stamp: "2007-04-28 10:08:34 bkorb" +/* + * Time-stamp: "2011-04-22 12:54:28 bkorb" * * This module implements the default usage procedure for * Automated Options. It may be overridden, of course. */ -static char const zAOV[] = - "Automated Options version %s, copyright (c) 1999-2007 Bruce Korb\n"; - -/* Automated Options is free software. - * You may 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. - * - * Automated Options 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 Automated Options. See the file "COPYING". If not, - * write to: The Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. +/* + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2011 by Bruce Korb - all rights reserved * - * As a special exception, Bruce Korb gives permission for additional - * uses of the text contained in his release of AutoOpts. + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. * - * The exception is that, if you link the AutoOpts library with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the AutoOpts library code into it. + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" * - * This exception applies only to the code released by Bruce Korb under - * the name AutoOpts. If you copy code from other sources under the - * General Public License into a copy of AutoOpts, as the General Public - * License permits, the exception does not apply to the code that you add - * in this way. To avoid misleading anyone as to the status of such - * modified files, you must delete this exception notice from them. + * These files have the following md5sums: * - * If you write modifications of your own for AutoOpts, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd */ -/* = = = START-STATIC-FORWARD = = = */ -/* static forward declarations maintained by :mkfwd */ -static void -printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ); -/* = = = END-STATIC-FORWARD = = = */ - /*=export_func optionVersion * * what: return the compiled AutoOpts version number @@ -65,76 +38,114 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ); * The returned string cannot be modified. =*/ char const* -optionVersion( void ) +optionVersion(void) { static char const zVersion[] = - STR( AO_CURRENT.AO_REVISION ); + STR(AO_CURRENT.AO_REVISION); return zVersion; } +static void +emit_simple_ver(tOptions * pOpts, FILE * fp) +{ + if (pOpts->pzFullVersion != NULL) + fputs(pOpts->pzFullVersion, fp); + + else if (pOpts->pzCopyright != NULL) { + char const * pe = strchr(pOpts->pzCopyright, '\n'); + if (pe == NULL) + pe = pOpts->pzCopyright + strlen(pOpts->pzCopyright); + fwrite(pOpts->pzCopyright, 1, pe - pOpts->pzCopyright, fp); + } + + else { + char const * pe = strchr(pOpts->pzUsageTitle, '\n'); + if (pe == NULL) + pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle); + fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp); + } + fputc('\n', fp); +} static void -printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) +emit_copy_ver(tOptions * pOpts, FILE * fp) { - char swCh; + if (pOpts->pzCopyright != NULL) + fputs(pOpts->pzCopyright, fp); + + else if (pOpts->pzFullVersion != NULL) + fputs(pOpts->pzFullVersion, fp); + + else { + char const * pe = strchr(pOpts->pzUsageTitle, '\n'); + if (pe == NULL) + pe = pOpts->pzUsageTitle + strlen(pOpts->pzUsageTitle); + fwrite(pOpts->pzUsageTitle, 1, pe - pOpts->pzCopyright, fp); + } + + fputc('\n', fp); + + if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL)) + fputs(pOpts->pzPackager, fp); + + else if (pOpts->pzBugAddr != NULL) + fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr); +} + +static void +emit_copy_note(tOptions * pOpts, FILE * fp) +{ + if (pOpts->pzCopyright != NULL) { + fputs(pOpts->pzCopyright, fp); + fputc('\n', fp); + } + + if (pOpts->pzCopyNotice != NULL) { + fputs(pOpts->pzCopyNotice, fp); + fputc('\n', fp); + } + + fprintf(fp, zAO_Ver, optionVersion()); + + if (HAS_pzPkgDataDir(pOpts) && (pOpts->pzPackager != NULL)) + fputs(pOpts->pzPackager, fp); + + else if (pOpts->pzBugAddr != NULL) + fprintf(fp, zPlsSendBugs, pOpts->pzBugAddr); +} + +static void +print_ver(tOptions * pOpts, tOptDesc * pOD, FILE * fp) +{ + char ch; /* - * IF the optional argument flag is off, or the argument is not provided, - * then just print the version. + * IF the optional argument flag is off, or the argument + * is not provided, then just print the version. */ if ( ((pOD->fOptState & OPTST_ARG_OPTIONAL) == 0) || (pOD->optArg.argString == NULL)) - swCh = 'v'; - else swCh = tolower(pOD->optArg.argString[0]); + ch = 'v'; + else ch = pOD->optArg.argString[0]; - if (pOpts->pzFullVersion != NULL) { - fputs( pOpts->pzFullVersion, fp ); - fputc( '\n', fp ); - - } else { - char const *pz = pOpts->pzUsageTitle; - do { fputc(*pz, fp); } while (*(pz++) != '\n'); - } - - switch (swCh) { + switch (ch) { case NUL: /* arg provided, but empty */ - case 'v': - break; - - case 'c': - if (pOpts->pzCopyright != NULL) { - fputs( pOpts->pzCopyright, fp ); - fputc( '\n', fp ); - } - fprintf( fp, zAOV, optionVersion() ); - if (pOpts->pzBugAddr != NULL) - fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr ); - break; - - case 'n': - if (pOpts->pzCopyright != NULL) { - fputs( pOpts->pzCopyright, fp ); - fputc( '\n', fp ); - fputc( '\n', fp ); - } - - if (pOpts->pzCopyNotice != NULL) { - fputs( pOpts->pzCopyNotice, fp ); - fputc( '\n', fp ); - } - - fprintf( fp, zAOV, optionVersion() ); - if (pOpts->pzBugAddr != NULL) - fprintf( fp, zPlsSendBugs, pOpts->pzBugAddr ); - break; + case 'v': case 'V': emit_simple_ver(pOpts, fp); break; + case 'c': case 'C': emit_copy_ver(pOpts, fp); break; + case 'n': case 'N': emit_copy_note(pOpts, fp); break; default: - fprintf( stderr, zBadVerArg, swCh ); - exit( EXIT_FAILURE ); + fprintf(stderr, zBadVerArg, ch); + exit(EXIT_FAILURE); } - exit( EXIT_SUCCESS ); + fflush(fp); + if (ferror(fp) != 0) { + fputs(zOutputFail, stderr); + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); } /*=export_func optionPrintVersion @@ -148,9 +159,9 @@ printVersion( tOptions* pOpts, tOptDesc* pOD, FILE* fp ) * This routine will print the version to stdout. =*/ void -optionPrintVersion( tOptions* pOpts, tOptDesc* pOD ) +optionPrintVersion(tOptions * pOpts, tOptDesc * pOD) { - printVersion( pOpts, pOD, stdout ); + print_ver(pOpts, pOD, stdout); } /*=export_func optionVersionStderr @@ -164,9 +175,9 @@ optionPrintVersion( tOptions* pOpts, tOptDesc* pOD ) * This routine will print the version to stderr. =*/ void -optionVersionStderr( tOptions* pOpts, tOptDesc* pOD ) +optionVersionStderr(tOptions * pOpts, tOptDesc * pOD) { - printVersion( pOpts, pOD, stderr ); + print_ver(pOpts, pOD, stderr); } /* diff --git a/sntp/libopts/xat-attribute.c b/sntp/libopts/xat-attribute.c new file mode 100644 index 000000000000..db4753124082 --- /dev/null +++ b/sntp/libopts/xat-attribute.c @@ -0,0 +1,114 @@ +/* ANSI-C code produced by gperf version 3.0.4 */ + + +#if 0 /* gperf build options: */ +// %struct-type +// %language=ANSI-C +// %includes +// %global-table +// %omit-struct-type +// %readonly-tables +// %compare-strncmp +// +// %define slot-name xat_name +// %define hash-function-name xat_attribute_hash +// %define lookup-function-name find_xat_attribute_name +// %define word-array-name xat_attribute_table +// %define initializer-suffix ,XAT_COUNT_KWD +#endif /* gperf build options: */ + +#include "xat-attribute.h" + +typedef struct { + char const * xat_name; + xat_attribute_enum_t xat_id; +} xat_attribute_map_t; +#include <string.h> + +/* maximum key range = 9, duplicates = 0 */ + +#ifdef __GNUC__ +#else +#ifdef __cplusplus +#endif +#endif +inline static unsigned int +xat_attribute_hash (register const char *str, register unsigned int len) +{ + static const unsigned char asso_values[] = + { + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 0, + 13, 13, 13, 13, 13, 5, 13, 5, 13, 0, + 13, 13, 13, 13, 13, 13, 0, 0, 13, 0, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13 + }; + return len + asso_values[(unsigned char)str[0]]; +} + +static const xat_attribute_map_t xat_attribute_table[] = + { + {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD}, + {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD}, + {"type", XAT_KWD_TYPE}, + {"words", XAT_KWD_WORDS}, + {"cooked", XAT_KWD_COOKED}, + {"members", XAT_KWD_MEMBERS}, + {"uncooked", XAT_KWD_UNCOOKED}, + {"keep", XAT_KWD_KEEP}, + {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD}, + {"invalid", XAT_KWD_INVALID} + }; + +#ifdef __GNUC__ +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif +#endif +static inline const xat_attribute_map_t * +find_xat_attribute_name (register const char *str, register unsigned int len) +{ + if (len <= 8 && len >= 4) + { + register int key = xat_attribute_hash (str, len); + + if (key <= 12 && key >= 0) + { + register const char *s = xat_attribute_table[key].xat_name; + + if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') + return &xat_attribute_table[key]; + } + } + return 0; +} + + +xat_attribute_enum_t +find_xat_attribute_id(char const * str, unsigned int len) +{ + const xat_attribute_map_t * p = + find_xat_attribute_name(str, len); + return (p == 0) ? XAT_KWD_INVALID : p->xat_id; +} diff --git a/sntp/libopts/xat-attribute.h b/sntp/libopts/xat-attribute.h new file mode 100644 index 000000000000..079c59a3d0ac --- /dev/null +++ b/sntp/libopts/xat-attribute.h @@ -0,0 +1,22 @@ +/* + * Generated header for gperf generated source Fri Apr 29 15:43:59 PDT 2011 + * This file enumerates the list of names and declares the + * procedure for mapping string names to the enum value. + */ +#ifndef AUTOOPTS_XAT_ATTRIBUTE_H_GUARD +#define AUTOOPTS_XAT_ATTRIBUTE_H_GUARD 1 + +typedef enum { + XAT_KWD_INVALID, + XAT_KWD_TYPE, + XAT_KWD_WORDS, + XAT_KWD_MEMBERS, + XAT_KWD_COOKED, + XAT_KWD_UNCOOKED, + XAT_KWD_KEEP, + XAT_COUNT_KWD +} xat_attribute_enum_t; + +extern xat_attribute_enum_t +find_xat_attribute_id(char const * str, unsigned int len); +#endif /* AUTOOPTS_XAT_ATTRIBUTE_H_GUARD */ |