[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: bartobri\n"
  },
  {
    "path": ".gitignore",
    "content": "bin/*\nobj/*\n.vs\nnotes.txt\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program 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\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "Makefile",
    "content": "# Installation directories following GNU conventions\nprefix ?= /usr/local\nexec_prefix = $(prefix)\nbindir = $(exec_prefix)/bin\nsbindir = $(exec_prefix)/sbin\ndatarootdir = $(prefix)/share\ndatadir = $(datarootdir)\nincludedir = $(prefix)/include\nmandir = $(datarootdir)/man\n\nBIN=bin\nOBJ=obj\nSRC=src\n\nCC ?= gcc\nCFLAGS ?= -Wextra -Wall -O2\n\n.PHONY: all install uninstall clean\n\nnms: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)\n\t$(CC) $(CFLAGS) -o $(BIN)/$@ $^\n\nsneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)\n\t$(CC) $(CFLAGS) -o $(BIN)/$@ $^\n\nall: nms sneakers\n\nall-ncurses: nms-ncurses sneakers-ncurses\n\nnms-ncurses: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)\n\t$(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncursesw\n\nsneakers-ncurses: $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)\n\t$(CC) $(CFLAGS) -o $(BIN)/sneakers $^ -lncursesw\n\n$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)\n\t$(CC) $(CFLAGS) -o $@ -c $<\n\n$(BIN):\n\tmkdir $(BIN)\n\n$(OBJ):\n\tmkdir $(OBJ)\n\nclean:\n\trm -rf $(BIN)\n\trm -rf $(OBJ)\n\ninstall:\n\tinstall -d $(DESTDIR)$(mandir)/man6\n\tinstall -m644 nms.6 sneakers.6 $(DESTDIR)$(mandir)/man6 \n\tinstall -d $(DESTDIR)$(bindir)\n\tcd $(BIN) && install * $(DESTDIR)$(bindir)\n\nuninstall:\n\trm -f $(DESTDIR)$(bindir)/nms;\n\trm -f $(DESTDIR)$(bindir)/sneakers;\n\trm -f $(DESTDIR)$(mandir)/man6/nms.6\n\trm -f $(DESTDIR)$(mandir)/man6/sneakers.6\n"
  },
  {
    "path": "NCURSES.md",
    "content": "NCURSES Install\n===============\n\nBelow are instructions for installing ncurses on various Linux and Unix\noperating systems.\n\n#### Ubuntu/Debian/Mint Linux\n\n```\nsudo apt-get update\nsudo apt-get install lib32ncursesw5-dev\n```\n\n#### Fedora Linux\n\n```\nsudo dnf update --refresh\nsudo dnf install ncurses-devel\n```\n\n#### Redhat/Cent OS Linux\n\n```\nsudo yum update\nsudo yum install ncurses-devel\n```\n\n#### Arch Linux\n\n```\nsudo pacman -Sy\nsudo pacman -S ncurses\n```\n\n#### openSUSE\n\n```\nsudo zypper ref\nsudo zypper in ncurses-devel\n```\n\n#### Mac OSX\n\nInstall the Homebrew package manager by following the instructions on the\nwebsite: http://brew.sh/. Once Homebrew is installed, you can install ncurses.\n\n```\nbrew install ncurses\n```\n\n\n"
  },
  {
    "path": "README.md",
    "content": "![Version](https://img.shields.io/badge/Version-1.0.2-green.svg)\n\nLike this project? Consider tipping me: [https://github.com/sponsors/bartobri](https://github.com/sponsors/bartobri)\n\nNo More Secrets\n===============\n\nThis project provides a command line tool called `nms` that recreates the\nfamous data decryption effect seen on screen in the 1992 hacker movie Sneakers.\nFor reference, you can see this effect at 0:35 in [this movie clip](https://www.youtube.com/watch?v=F5bAa6gFvLs&t=35).\n\nThis command works on piped data. Pipe any ASCII or UTF-8 text to `nms`,\nand it will apply the Hollywood effect, initially showing encrypted data,\nthen starting a decryption sequence to reveal the original plain-text characters.\n\n![Screenshot](http://www.brianbarto.info/static/nms/nms.gif)\n\nAlso included in this project is a program called `sneakers` that recreates\nwhat we see in the above movie clip. Note that this program requires the\nuser to select one of the menu options before it terminates.\n\n![Screenshot](http://www.brianbarto.info/static/nms/sneakers.gif)\n\nBy default, this project has no dependencies, but it does rely on ANSI/VT100\nterminal escape sequences to recreate the effect. Most modern terminal\nprograms support these sequences so this should not be an issue for most\nusers. If yours does not, this project also provides a ncurses implementation\nwhich supports non-ANSI terminals, but at the expense of losing the inline\nfunctionality (ncurses will always clear the screen prior to displaying output).\n\nTable of Contents\n-----------------\n\n1. [Download and Install](#download-and-install)\n2. [Usage](#usage)\n3. [The NMS Library](#the-nms-library)\n4. [License](#license)\n\nDownload and Install\n--------------------\n\nMore and more Unix/Linux platforms are including this project in their\npackage manager. You may wish to search your package manager to see if it\nis an installation option. If you install from a package manager, please\ncheck that you have the latest version (`nms -v`). If not, I suggest\ninstalling from source by following the instructions below.\n\nTo install this project from source, you will need to have the tools `git`,\n`gcc`, and `make` to download and build it. Install them from your package\nmanager if they are not already installed.\n\nOnce you have the necessary tools installed, follow these instructions:\n\n#### Install:\n```\n$ git clone https://github.com/bartobri/no-more-secrets.git\n$ cd ./no-more-secrets\n$ make nms\n$ make sneakers             ## Optional\n$ sudo make install\n```\n\n#### Uninstall:\n\n```\n$ sudo make uninstall\n```\n\n#### Install with Ncurses Support\n\nIf your terminal does not support ANSI/VT100 escape sequences, the effect\nmay not render properly. This project provides a ncurses implementation\nfor such cases. You will need the ncurses library installed. [Install this\nlibrary from your package manager](NCURSES.md). Next, follow these instructions:\n\n```\n$ git clone https://github.com/bartobri/no-more-secrets.git\n$ cd ./no-more-secrets\n$ make nms-ncurses\n$ make sneakers-ncurses     ## Optional\n$ sudo make install\n```\n\nUsage\n-----\n\n`nms` works on piped data. Pipe any ASCII or UTF-8 characters to it and\nenjoy the magic. In the below examples, I use a simple directory listing.\n\n```\n$ ls -l | nms\n$ ls -l | nms -a           // Set auto-decrypt flag\n$ ls -l | nms -s           // Set flag to mask space characters\n$ ls -l | nms -f green     // Set foreground color to green\n$ ls -l | nms -c           // Clear screen\n$ nms -v                   // Display version\n```\n\nNote that by default, after the initial encrypted characters are displayed,\n`nms` will wait for the user to press a key before initiating the decryption\nsequence. This is how the it is depicted in the movie.\n\n#### Command Line Options\n\n`-a`\n\nSet the auto-decrypt flag. This will automatically start the\ndecryption sequence without requiring a key press.\n\n`-s`\n\nSet a flag to mask space characters. This will only mask single blank space\ncharacters. Other space characters such as tabs and newlines will not be masked.\n\n`-f <color>`\n\nSet the foreground color of the decrypted text to the color\nspecified. Valid options are white, yellow, black, magenta, blue, green,\nred, cyan, or any color value in hex string format (i.e. #FF1234).\nThis is blue by default.\n\n`-c`\n\nClear the screen prior to printing any output. Specifically,\nit saves the state of the terminal (all current output), and restores it\nonce the effect is completed. Note that when using this option, `nms` requires\nthe user to press a key before restoring the terminal.\n\n`-v`\n\nDisplay version info.\n\nThe NMS Library\n---------------\n\nFor those who would like to use this effect in their own projects, I have\ncreated a C library that provides simple interface and can easily be used\nfor any program that runs from the command line.\n\nSee [LibNMS](https://github.com/bartobri/libnms) for more info.\n\nLicense\n-------\n\nThis program is free software; you can redistribute it and/or modify it\nunder the terms of the GNU General Public License. See [LICENSE](LICENSE) for\nmore details.\n"
  },
  {
    "path": "nms.6",
    "content": ".\\\" Manpage for nms.\n.\\\" Author of this manpage is Ferdinand Thiessen <rpm@fthiessen>, contact him to correct errors or typos.\n.\\\" This man page is released into the public domain, see also https://creativecommons.org/publicdomain/zero/1.0/\n.TH nms 6 \"17 February 2017\" \"1.0\" \"nms User Manual\"\n.SH NAME\nnms \\- No More Secrets\n.SH SYNOPSIS\nnms [options]\n.SH OPTIONS\n.TP\n.B -a\nsets the auto-decrypt flag, decryption sequence starts without requiring a key press.\n.TP\n.B -s\nsets the mask blanks flag. Blank spaces will be encrypted and decrypted.\n.TP\n.B -c\nclear the screen prior to printing any output\n.TP\n.B -v\ndisplay version info\n.TP\n.BI -f <COLOR>\nset the foreground color of the decrypted text to the color specified.\nValid options are white, black, yellow, magenta, cyan, blue (default), green, or red.\n.SH DESCRIPTION\nThis command works on piped data. Pipe any ASCII or UTF-8 text to nms,\nand it will apply the hollywood effect, seen on screen in the 1992 hacker movie Sneakers.\n.PP\nInitially showing encrypted data, then starting a decryption sequence to reveal the original plaintext characters.\n.SH \"SEE ALSO\"\nsneakers(6)\n.SH AUTHOR\nBrian Barto ( https://github.com/bartobri )\n.SH COPYRIGHT\nnms is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n"
  },
  {
    "path": "no-more-secrets.spec",
    "content": "Name:           no-more-secrets\nVersion:        0.3.1\nRelease:        1%{?dist}\nSummary:        A recreation of the \"decrypting text\" effect from the 1992 movie Sneakers\nGroup:          Amusements/Games\nLicense:        GPL-3.0+\nURL:            https://github.com/bartobri/no-more-secrets\nSource0: \thttps://github.com/bartobri/no-more-secrets/archive/v%{version}.tar.gz\nBuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)\nBuildRequires:  ncurses-devel\n\n%description\nA tool set to recreate the famous \"decrypting text\" effect as seen in the 1992 movie Sneakers.\n\n%prep\n%setup -q -n %{name}-%{version}\n\n%build\nmake nms sneakers-ncurses\n\n%install\ninstall -d m0755 %{buildroot}%{_bindir}\nmake install prefix=%{buildroot}/usr\n\n%clean\nrm -rf %{buildroot}\n\n%files\n%defattr(-,root,root,-)\n%{_bindir}/nms\n%{_bindir}/sneakers\n%{_mandir}/man6/nms.6%{ext_man}\n%{_mandir}/man6/sneakers.6%{ext_man}\n\n%changelog\n* Sat Feb 17 2017 Ferdinand Thiessen <rpm@fthiessen.de> - 0.3.1\n- Update to 0.3.1\n- Added manpages\n\n* Fri May 20 2016 Thomas Guthmann <tguthmann@iseek.com.au> - 0.2\n- Already a new version!\n\n* Wed May 18 2016 Thomas Guthmann <tguthmann@iseek.com.au> - 0.1\n- Initial release\n\n"
  },
  {
    "path": "sneakers.6",
    "content": ".\\\" Manpage for sneakers.\n.\\\" Author of this manpage is Ferdinand Thiessen <rpm@fthiessen>, contact him to correct errors or typos.\n.\\\" This man page is released into the public domain, see also https://creativecommons.org/publicdomain/zero/1.0/\n.TH sneakers 6 \"17 February 2017\" \"1.0\" \"sneakers User Manual\"\n.SH NAME\nsneakers\n.SH SYNOPSIS\nsneakers\n.SH DESCRIPTION\nsneakers recreates the famous data decryption effect with\nthe same content seen on screen in the 1992 hacker movie Sneakers.\n.SH \"SEE ALSO\"\nnms(6)\n.SH AUTHOR\nBrian Barto ( https://github.com/bartobri )\n.SH COPYRIGHT\nsneakers is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n"
  },
  {
    "path": "src/error.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#include <stdio.h>\n#include <stddef.h>\n#include <stdarg.h>\n\n#define ERROR_LIST_MAX\t\t20\n#define ERROR_LENGTH_MAX\t100\n\nstatic char error_stack[ERROR_LIST_MAX][ERROR_LENGTH_MAX];\nstatic int N = 0;\n\nvoid error_log(char *error, ...)\n{\n\tva_list argList;\n\n\tif (N < ERROR_LIST_MAX)\n\t{\n\t\tva_start(argList, error);\n\t\tvsnprintf(error_stack[N++], ERROR_LENGTH_MAX - 1, error, argList);\n\t\tva_end(argList);\n\t}\n}\n\nvoid error_print(void)\n{\n\tint i;\n\n\tfor (i = N-1; i >= 0; --i)\n\t{\n\t\tfprintf(stderr, \"%s \", error_stack[i]);\n\t}\n\tfprintf(stderr, \"\\n\");\n}\n\nchar *error_get(void)\n{\n\tif (N > 0)\n\t{\n\t\treturn error_stack[--N];\n\t}\n\telse\n\t{\n\t\treturn NULL;\n\t}\n}\n\nvoid error_clear(void)\n{\n\tN = 0;\n}"
  },
  {
    "path": "src/error.h",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#ifndef ERROR_H\n#define ERROR_H 1\n\nvoid error_log(char *, ...);\nvoid error_print(void);\nchar *error_get(void);\nvoid error_clear(void);\n\n#endif"
  },
  {
    "path": "src/input.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <ctype.h>\n#include <string.h>\n#include <sys/ioctl.h>\n#include <sys/select.h>\n#include <time.h>\n#include <errno.h>\n#include \"input.h\"\n#include \"error.h\"\n\nint input_get(unsigned char** dest, char *prompt)\n{\n\tint r, input_len;\n\tfd_set input_stream;\n\tstruct timeval timeout;\n\tvoid *timeout_p;\n\n\tFD_ZERO(&input_stream);\n\tinput_len = 0;\n\n\ttimeout.tv_sec  = 10;\n\ttimeout.tv_usec = 0;\n\n\tif (isatty(STDIN_FILENO))\n\t{\n\t\ttimeout_p = NULL;\n\t\tif (prompt != NULL)\n\t\t{\n\t\t\tprintf(\"%s\", prompt);\n\t\t\tfflush(stdout);\n\t\t}\n\t}\n\telse\n\t{\n\t\ttimeout_p = &timeout;\n\t}\n\n\tFD_SET(STDIN_FILENO, &input_stream);\n\tr = select(FD_SETSIZE, &input_stream, NULL, NULL, timeout_p);\n\tif (r < 0)\n\t{\n\t\terror_log(\"Error while waiting for input data. Errno: %i\", errno);\n\t\treturn -1;\n\t}\n\tif (r > 0)\n\t{\n\t\tr = ioctl(STDIN_FILENO, FIONREAD, &input_len);\n\t\tif (r < 0)\n\t\t{\n\t\t\terror_log(\"Could not determine length of input. Errno: %i\", errno);\n\t\t\treturn -1;\n\t\t}\n\t\tif (input_len > 0)\n\t\t{\n\t\t\t*dest = malloc(input_len);\n\t\t\tif (*dest == NULL)\n\t\t\t{\n\t\t\t\terror_log(\"Memory allocation error.\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tr = read(STDIN_FILENO, *dest, input_len);\n\t\t\tif (r < 0)\n\t\t\t{\n\t\t\t\terror_log(\"Input read error. Errno: %i\", errno);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t}\n\n\tFD_CLR(STDIN_FILENO, &input_stream);\n\n\treturn input_len;\n}\n\nint input_get_str(char** dest, char *prompt)\n{\n\tint r, i, input_len;\n\tunsigned char *input;\n\n\tr = input_get(&input, prompt);\n\tif (r < 0)\n\t{\n\t\terror_log(\"Could not get input.\");\n\t\treturn -1;\n\t}\n\n\tif (r > 0)\n\t{\n\t\tif (input[r - 1] == '\\n')\n\t\t{\n\t\t\t--r;\n\t\t\tif (r > 0 && input[r - 1] == '\\r')\n\t\t\t{\n\t\t\t\t--r;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (r == 0)\n\t{\n\t\terror_log(\"No input provided.\");\n\t\treturn -1;\n\t}\n\n\tinput_len = r;\n\n\t*dest = malloc(input_len + 1);\n\tif (*dest == NULL)\n\t{\n\t\terror_log(\"Memory allocation error.\");\n\t\treturn -1;\n\t}\n\n\tmemset(*dest, 0, input_len + 1);\n\n\tfor (i = 0; i < input_len; ++i)\n\t{\n\t\tif (isascii(input[i]))\n\t\t{\n\t\t\t(*dest)[i] = input[i];\n\t\t}\n\t\telse\n\t\t{\n\t\t\terror_log(\"Input contains non-ascii characters.\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tfree(input);\n\n\treturn input_len;\n}\n\nint input_get_from_pipe(unsigned char** dest)\n{\n\tint r;\n\n\tif (isatty(STDIN_FILENO))\n\t{\n\t\terror_log(\"Input data from a piped or redirected source is required.\");\n\t\treturn -1;\n\t}\n\n\tr = input_get(dest, NULL);\n\tif (r < 0)\n\t{\n\t\terror_log(\"Could not get input.\");\n\t\treturn -1;\n\t}\n\tif (r == 0)\n\t{\n\t\terror_log(\"No input provided.\");\n\t\treturn -1;\n\t}\n\n\treturn r;\n}"
  },
  {
    "path": "src/input.h",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#ifndef INPUT_H\n#define INPUT_H 1\n\nint input_get(unsigned char** dest, char *prompt);\nint input_get_str(char** dest, char *prompt);\nint input_get_from_pipe(unsigned char** dest);\n\n#endif"
  },
  {
    "path": "src/nms.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <ctype.h>\n#include \"nmseffect.h\"\n#include \"input.h\"\n#include \"error.h\"\n\n#define VERSION \"1.0.2\"\n\nint main(int argc, char *argv[])\n{\n\tint r, o;\n\tunsigned char *input;\n\n\tinput = NULL;\n\n\twhile ((o = getopt(argc, argv, \"f:ascv\")) != -1)\n\t{\n\t\tswitch (o)\n\t\t{\n\t\t\tcase 'f':\n\t\t\t\tnmseffect_set_foregroundcolor(optarg);\n\t\t\t\tbreak;\n\t\t\tcase 'a':\n\t\t\t\tnmseffect_set_autodecrypt(1);\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\tnmseffect_set_maskblank(1);\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\tnmseffect_set_clearscr(1);\n\t\t\t\tbreak;\n\t\t\tcase 'v':\n\t\t\t\tprintf(\"nms version \" VERSION \"\\n\");\n\t\t\t\treturn EXIT_SUCCESS;\n\t\t\tcase '?':\n\t\t\t\tif (isprint(optopt))\n\t\t\t\t{\n\t\t\t\t\terror_log(\"Unknown option '-%c'.\", optopt);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terror_log(\"Unknown option character '\\\\x%x'.\", optopt);\n\t\t\t\t}\n\t\t\t\terror_print();\n\t\t\t\treturn EXIT_FAILURE;\n\t\t}\n\t}\n\n\tr = input_get(&input, \"Enter input: \");\n\tif (r < 0)\n\t{\n\t\terror_log(\"Could not get input.\");\n\t\terror_print();\n\t\treturn EXIT_FAILURE;\n\t}\n\telse if (r == 0)\n\t{\n\t\terror_log(\"Input is empty.\");\n\t\terror_print();\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tr = nmseffect_exec(input, r);\n\n\tfree(input);\n\n\treturn EXIT_SUCCESS;\n}\n"
  },
  {
    "path": "src/nmscharset.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n/*\n * The nmscharset module defines the character set that is used to\n * represent encryption.\n */\n \n#include <stdlib.h>\n\n// Total characters in charTable[] array.\n#define CHAR_COUNT 218\n\n// Character table representing the character set know as CP437 used by\n// the original IBM PC - https://en.wikipedia.org/wiki/Code_page_437\nstatic char *charTable[] = {\n\t\"!\", \"\\\"\", \"#\", \"$\", \"%\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \"-\", \"~\",\n\t\".\", \"/\", \":\", \";\", \"<\", \"=\", \">\", \"?\", \"[\", \"\\\\\", \"]\", \"_\", \"{\", \"}\",\n\t\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\",\n\t\"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\",\n\t\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\",\n\t\"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\",\n\t\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\",\n\t\"\\xc3\\x87\", \"\\xc3\\xbc\", \"\\xc3\\xa9\", \"\\xc3\\xa2\", \"\\xc3\\xa4\", \"\\xc3\\xa0\",\n\t\"\\xc3\\xa5\", \"\\xc3\\xa7\", \"\\xc3\\xaa\", \"\\xc3\\xab\", \"\\xc3\\xa8\", \"\\xc3\\xaf\",\n\t\"\\xc3\\xae\", \"\\xc3\\xac\", \"\\xc3\\x84\", \"\\xc3\\x85\", \"\\xc3\\x89\", \"\\xc3\\xa6\",\n\t\"\\xc3\\x86\", \"\\xc3\\xb4\", \"\\xc3\\xb6\", \"\\xc3\\xb2\", \"\\xc3\\xbb\", \"\\xc3\\xb9\",\n\t\"\\xc3\\xbf\", \"\\xc3\\x96\", \"\\xc3\\x9c\", \"\\xc2\\xa2\", \"\\xc2\\xa3\", \"\\xc2\\xa5\",\n\t\"\\xc6\\x92\", \"\\xc3\\xa1\", \"\\xc3\\xad\", \"\\xc3\\xb3\", \"\\xc3\\xba\", \"\\xc3\\xb1\",\n\t\"\\xc3\\x91\", \"\\xc2\\xaa\", \"\\xc2\\xba\", \"\\xc2\\xbf\", \"\\xc2\\xac\", \"\\xc2\\xbd\",\n\t\"\\xc2\\xbc\", \"\\xc2\\xa1\", \"\\xc2\\xab\", \"\\xc2\\xbb\", \"\\xce\\xb1\", \"\\xc3\\x9f\",\n\t\"\\xce\\x93\", \"\\xcf\\x80\", \"\\xce\\xa3\", \"\\xcf\\x83\", \"\\xc2\\xb5\", \"\\xcf\\x84\",\n\t\"\\xce\\xa6\", \"\\xce\\x98\", \"\\xce\\xa9\", \"\\xce\\xb4\", \"\\xcf\\x86\", \"\\xce\\xb5\",\n\t\"\\xc2\\xb1\", \"\\xc3\\xb7\", \"\\xc2\\xb0\", \"\\xc2\\xb7\", \"\\xc2\\xb2\", \"\\xc2\\xb6\",\n\t\"\\xe2\\x8c\\x90\", \"\\xe2\\x82\\xa7\", \"\\xe2\\x96\\x91\", \"\\xe2\\x96\\x92\",\n\t\"\\xe2\\x96\\x93\", \"\\xe2\\x94\\x82\", \"\\xe2\\x94\\xa4\", \"\\xe2\\x95\\xa1\",\n\t\"\\xe2\\x95\\xa2\", \"\\xe2\\x95\\x96\", \"\\xe2\\x95\\x95\", \"\\xe2\\x95\\xa3\",\n\t\"\\xe2\\x95\\x91\", \"\\xe2\\x95\\x97\", \"\\xe2\\x95\\x9d\", \"\\xe2\\x95\\x9c\",\n\t\"\\xe2\\x95\\x9b\", \"\\xe2\\x94\\x90\", \"\\xe2\\x94\\x94\", \"\\xe2\\x94\\xb4\",\n\t\"\\xe2\\x94\\xac\", \"\\xe2\\x94\\x9c\", \"\\xe2\\x94\\x80\", \"\\xe2\\x94\\xbc\",\n\t\"\\xe2\\x95\\x9e\", \"\\xe2\\x95\\x9f\", \"\\xe2\\x95\\x9a\", \"\\xe2\\x95\\x94\",\n\t\"\\xe2\\x95\\xa9\", \"\\xe2\\x95\\xa6\", \"\\xe2\\x95\\xa0\", \"\\xe2\\x95\\x90\",\n\t\"\\xe2\\x95\\xac\", \"\\xe2\\x95\\xa7\", \"\\xe2\\x95\\xa8\", \"\\xe2\\x95\\xa4\",\n\t\"\\xe2\\x95\\xa7\", \"\\xe2\\x95\\x99\", \"\\xe2\\x95\\x98\", \"\\xe2\\x95\\x92\",\n\t\"\\xe2\\x95\\x93\", \"\\xe2\\x95\\xab\", \"\\xe2\\x95\\xaa\", \"\\xe2\\x94\\x98\",\n\t\"\\xe2\\x94\\x8c\", \"\\xe2\\x96\\x88\", \"\\xe2\\x96\\x84\", \"\\xe2\\x96\\x8c\",\n\t\"\\xe2\\x96\\x90\", \"\\xe2\\x96\\x80\", \"\\xe2\\x88\\x9e\", \"\\xe2\\x88\\xa9\",\n\t\"\\xe2\\x89\\xa1\", \"\\xe2\\x89\\xa5\", \"\\xe2\\x89\\xa4\", \"\\xe2\\x8c\\xa0\",\n\t\"\\xe2\\x8c\\xa1\", \"\\xe2\\x89\\x88\", \"\\xe2\\x88\\x99\", \"\\xe2\\x88\\x9a\",\n\t\"\\xe2\\x81\\xbf\", \"\\xe2\\x96\\xa0\"\n};\n\n/*\n * Return a random character from charTable[].\n */\nchar *nmscharset_get_random(void) {\n\treturn charTable[rand() % CHAR_COUNT];\n}\n"
  },
  {
    "path": "src/nmscharset.h",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#ifndef NMSCHARSET_H\n#define NMSCHARSET_H 1\n\n// Function prototypes\nchar *nmscharset_get_random(void);\n\n#endif\n"
  },
  {
    "path": "src/nmseffect.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n \n/*\n * The nmseffect module is the primary module that drives the effect\n * execution. Most attributes, settings, and code that define the behavior\n * is implemented here.\n */\n\n#define _XOPEN_SOURCE 700\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <ctype.h>\n#include <time.h>\n#include <locale.h>\n#include <wchar.h>\n#include \"nmseffect.h\"\n#include \"nmstermio.h\"\n#include \"nmscharset.h\"\n\n// Speed settings\n#define TYPE_EFFECT_SPEED    4     // miliseconds per char\n#define JUMBLE_SECONDS       2     // number of seconds for jumble effect\n#define JUMBLE_LOOP_SPEED    35    // miliseconds between each jumble\n#define REVEAL_LOOP_SPEED    50    // miliseconds between each reveal loop\n\n// Behavior settings\nstatic int autoDecrypt      = 0;            // Auto-decrypt flag\nstatic int maskBlank        = 0;            // Mask blank spaces\nstatic int colorOn          = 1;            // Terminal color flag\n\n// Character attribute structure, linked list. Keeps track of every\n// character's attributes required for rendering and decryption effect.\nstruct charAttr {\n\tchar *source;\n\tchar *mask;\n\tint width;\n\tint is_space;\n\tint time;\n\tstruct charAttr *next;\n};\n\n// Static function prototypes\nstatic void nmseffect_sleep(int);\n\n/*\n * This function applies the data decryption effect to the character\n * string that is provided as an argument. It returns the last character\n * pressed by the user.\n */\nchar nmseffect_exec(unsigned char *string, int string_len) {\n\tstruct charAttr *list_pointer = NULL;\n\tstruct charAttr *list_head    = NULL;\n\tstruct charAttr *list_temp    = NULL;\n\tint i, l, revealed = 0;\n\tint maxRows, maxCols, curRow, curCol, origRow = 0, origCol = 0;\n\tchar ret = 0;\n\t\n\t// Needed for UTF-8 support\n\tsetlocale(LC_ALL, \"\");\n\t\n\t// Seed my random number generator with the current time\n\tsrand(time(NULL));\n\t\n\t// Initialize terminal\n\tnmstermio_init_terminal();\n\t\n\tif (!nmstermio_get_clearscr()) {\n\t\t// Get current row position\n\t\torigRow = nmstermio_get_cursor_row();\n\t\t\n\t\t// nmstermio_get_cursor_row() may display output in some terminals. So\n\t\t// we need to reposition the cursor to the start of the row, print\n\t\t// some blank spaces, and the reposition again.\n\t\tnmstermio_move_cursor(origRow, 0);\n\t\tnmstermio_print_string(\"    \");\n\t\tnmstermio_move_cursor(origRow, 0);\n\t}\n\n\t// Get terminal window rows/cols\n\tmaxRows = nmstermio_get_rows();\n\tmaxCols = nmstermio_get_cols();\n\n\t// Assign current row/col positions\n\tcurRow = origRow;\n\tcurCol = origCol;\n\n\t// Processing input\n\tfor (i = 0; i < string_len; ++i) {\n\n\t\t// Don't go beyond maxRows\n\t\tif (curRow - origRow >= maxRows - 1) {\n\t\t\tbreak;\n\t\t}\n\n\t\t// Allocate memory for next list link\n\t\tif (list_pointer == NULL) {\n\t\t\tlist_pointer = malloc(sizeof(struct charAttr));\n\t\t\tlist_head = list_pointer;\n\t\t} else {\n\t\t\tlist_pointer->next = malloc(sizeof(struct charAttr));\n\t\t\tlist_pointer = list_pointer->next;\n\t\t}\n\n\t\t// Get character's byte-length and store character.\n\t\tl = mblen((char *)&string[i], 4);\n\t\tif (l > 0) {\n\t\t\tlist_pointer->source = malloc(l + 1);\n\t\t\tmemcpy(list_pointer->source, &string[i], l);\n\t\t\tlist_pointer->source[l] = '\\0';\n\t\t\ti += (l - 1);\n\t\t} else {\n\t\t\tfprintf(stderr, \"Unknown character encountered. Quitting.\\n\");\n\t\t\tnmstermio_restore_terminal();\n\t\t\treturn 0;\n\t\t}\n\n\t\t// Set flag if we have a whitespace character\n\t\tif (strlen(list_pointer->source) == 1 && isspace(list_pointer->source[0])) {\n\n\t\t\t// If flag is enabled, mask blank spaces as well\n\t\t\tif (maskBlank && (list_pointer->source[0] == ' ')) {\n\t\t\t\tlist_pointer->is_space = 0;\n\t\t\t} else {\n\t\t\t\tlist_pointer->is_space = 1;\n\t\t\t}\n\n\t\t} else {\n\t\t\tlist_pointer->is_space = 0;\n\t\t}\n\n\t\t// Set initial mask chharacter\n\t\tlist_pointer->mask = nmscharset_get_random();\n\n\t\t// Set reveal time\n\t\tlist_pointer->time = rand() % 5000;\n\n\t\t// Set character column width\n\t\twchar_t widec[sizeof(list_pointer->source)] = {};\n\t\tmbstowcs(widec, list_pointer->source, sizeof(list_pointer->source));\n\t\tlist_pointer->width = wcwidth(*widec);\n\t\t\n\t\t// Set next node to null\n\t\tlist_pointer->next = NULL;\n\n\t\t// Track row count\n\t\tif (string[i] == '\\n' || (curCol += list_pointer->width) > maxCols) {\n\t\t\tcurCol = 0;\n\t\t\tcurRow++;\n\t\t\tif (curRow == maxRows + 1 && origRow > 0) {\n\t\t\t\torigRow--;\n\t\t\t\tcurRow--;\n\t\t\t}\n\t\t}\n\t}\n\t\n\t// Print mask characters with 'type effect'\n\tfor (list_pointer = list_head; list_pointer != NULL; list_pointer = list_pointer->next) {\n\n\t\t// Print mask character (or space)\n\t\tif (list_pointer->is_space) {\n\t\t\tnmstermio_print_string(list_pointer->source);\n\t\t\tcontinue;\n\t\t}\n\t\t\n\t\t// print mask character\n\t\tnmstermio_print_string(list_pointer->mask);\n\t\tif (list_pointer->width == 2) {\n\t\t\tnmstermio_print_string(nmscharset_get_random());\n\t\t}\n\t\t\n\t\t// flush output and sleep\n\t\tnmstermio_refresh();\n\t\tnmseffect_sleep(TYPE_EFFECT_SPEED);\n\t}\n\n\t// Flush any input up to this point\n\tnmstermio_clear_input();\n\n\t// If autoDecrypt flag is set, we sleep. Otherwise require user to\n\t// press a key to continue.\n\tif (autoDecrypt)\n\t\tsleep(1);\n\telse\n\t\tnmstermio_get_char();\n\n\t// Jumble loop\n\tfor (i = 0; i < (JUMBLE_SECONDS * 1000) / JUMBLE_LOOP_SPEED; ++i) {\n\t\t\n\t\t// Move cursor to start position\n\t\tnmstermio_move_cursor(origRow, origCol);\n\t\t\n\t\t// Print new mask for all characters\n\t\tfor (list_pointer = list_head; list_pointer != NULL; list_pointer = list_pointer->next) {\n\t\n\t\t\t// Print mask character (or space)\n\t\t\tif (list_pointer->is_space) {\n\t\t\t\tnmstermio_print_string(list_pointer->source);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t// print new mask character\n\t\t\tnmstermio_print_string(nmscharset_get_random());\n\t\t\tif (list_pointer->width == 2) {\n\t\t\t\tnmstermio_print_string(nmscharset_get_random());\n\t\t\t}\n\t\t}\n\t\t\n\t\t// flush output and sleep\n\t\tnmstermio_refresh();\n\t\tnmseffect_sleep(JUMBLE_LOOP_SPEED);\n\t}\n\n\t// Reveal loop\n\twhile (!revealed) {\n\t\t\n\t\t// Move cursor to start position\n\t\tnmstermio_move_cursor(origRow, origCol);\n\t\t\n\t\t// Set revealed flag\n\t\trevealed = 1;\n\t\t\n\t\tfor (list_pointer = list_head; list_pointer != NULL; list_pointer = list_pointer->next) {\n\t\n\t\t\t// Print mask character (or space)\n\t\t\tif (list_pointer->is_space) {\n\t\t\t\tnmstermio_print_string(list_pointer->source);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t// If we still have time before the char is revealed, display the mask\n\t\t\tif (list_pointer->time > 0) {\n\t\t\t\t\n\t\t\t\t// Change the mask randomly\n\t\t\t\tif (list_pointer->time < 500) {\n\t\t\t\t\tif (rand() % 3 == 0) {\n\t\t\t\t\t\tlist_pointer->mask = nmscharset_get_random();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (rand() % 10 == 0) {\n\t\t\t\t\t\tlist_pointer->mask = nmscharset_get_random();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Print mask\n\t\t\t\tnmstermio_print_string(list_pointer->mask);\n\t\t\t\t\n\t\t\t\t// Decrement reveal time\n\t\t\t\tlist_pointer->time -= REVEAL_LOOP_SPEED;\n\t\t\t\t\n\t\t\t\t// Unset revealed flag\n\t\t\t\trevealed = 0;\n\t\t\t} else {\n\t\t\t\t\n\t\t\t\t// print source character\n\t\t\t\tnmstermio_print_reveal_string(list_pointer->source, colorOn);\n\t\t\t}\n\t\t}\n\n\t\t// flush output and sleep\n\t\tnmstermio_refresh();\n\t\tnmseffect_sleep(REVEAL_LOOP_SPEED);\n\t}\n\n\tnmstermio_clear_input();\n\t\n\tif (nmstermio_get_clearscr()) {\n\t\tnmstermio_get_char();\n\t}\n\t\n\t// Restore terminal\n\tnmstermio_restore_terminal();\n\n\t// Freeing the list. \n\tlist_pointer = list_head;\n\twhile (list_pointer != NULL) {\n\t\tlist_temp = list_pointer;\n\t\tlist_pointer = list_pointer->next;\n\t\tfree(list_temp->source);\n\t\tfree(list_temp);\n\t}\n\n\treturn ret;\n}\n\n/*\n * Pass the 'color' argument to the nmstermio module where it will set the\n * foreground color of the unencrypted characters as they are\n * revealed. Valid arguments are \"white\", \"yellow\", \"magenta\", \"blue\",\n * \"green\", \"red\", and \"cyan\".\n */\nvoid nmseffect_set_foregroundcolor(char *color) {\n\tnmstermio_set_foregroundcolor(color);\n}\n\n/*\n * Set the autoDecrypt flag according to the true/false value of the\n * 'setting' argument. When set to true, nmseffect_exec() will not\n * require a key press to start the decryption effect.\n */\nvoid nmseffect_set_autodecrypt(int setting) {\n\tif (setting)\n\t\tautoDecrypt = 1;\n\telse\n\t\tautoDecrypt = 0;\n}\n\n/*\n * Set the maskBlank flag according to the true/false value of the\n * 'setting' argument. When set to true, blank spaces characters\n * will be masked as well.\n */\nvoid nmseffect_set_maskblank(int setting) {\n    if (setting)\n        maskBlank = 1;\n    else\n        maskBlank = 0;\n}\n\n/*\n * Pass the 'setting' argument to the nmstermio module where it will set\n * the clearScr flag according to the true/false value. When set to true,\n * nmseffect_exec() will clear the screen before displaying any characters.\n */\nvoid nmseffect_set_clearscr(int setting) {\n\tnmstermio_set_clearscr(setting);\n}\n\n/*\n * Set the 'colorOn' flag according to the true/false value of the 'setting'\n * argument. This flag tells nmseffect_exec() to use colors in it's output.\n * This is true by default, and meant to be used only for terminals that\n * do not support color. Though, compiling with ncurses support is perhaps\n * a better option, as it will detect color capabilities automatically.\n */\nvoid nmseffect_set_color(int setting) {\n\tif (setting)\n\t\tcolorOn = 1;\n\telse\n\t\tcolorOn = 0;\n}\n\n/*\n * Sleep for the number of milliseconds indicated by argument 't'.\n */\nstatic void nmseffect_sleep(int t) {\n\tstruct timespec ts;\n\t\n\tts.tv_sec = t / 1000;\n\tts.tv_nsec = (t % 1000) * 1000000;\n\t\n\tnanosleep(&ts, NULL);\n}\n"
  },
  {
    "path": "src/nmseffect.h",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#ifndef NMSEFFECT_H\n#define NMSEFFECT_H 1\n\n// Function prototypes\nchar nmseffect_exec(unsigned char *, int string_len);\nvoid nmseffect_set_foregroundcolor(char *);\nvoid nmseffect_set_returnopts(char *);\nvoid nmseffect_set_autodecrypt(int);\nvoid nmseffect_set_maskblank(int);\nvoid nmseffect_set_clearscr(int);\nvoid nmseffect_use_color(int);\nvoid nmseffect_set_input_position(int, int);\n\n#endif\n"
  },
  {
    "path": "src/nmstermio.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n/*\n * The nmstermio modules implements the terminal interface used by the\n * nmseffect module. All terminal IO functionality is defined and\n * implemented here.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <time.h>\n#include <termios.h>\n#include <unistd.h>\n#include <sys/ioctl.h>\n\n// Support for MinGW on Windows\n#ifndef FIONREAD\n#include <sys/socket.h>\n#endif\n\n// Macros for VT100 codes\n#define CLEAR_SCR()             printf(\"\\033[2J\")           // Clear Screen\n#define CURSOR_HOME()           printf(\"\\033[H\")            // Move cursor to home position (0,0)\n#define CURSOR_MOVE(y,x)        printf(\"\\033[%i;%iH\", y, x) // Move cursor to x,y\n#define BEEP()                  printf(\"\\a\");               // terminal bell\n#define BOLD()                  printf(\"\\033[1m\")           // Cursor bold\n#define FOREGROUND_COLOR(r,g,b) printf(\"\\033[38;2;%d;%d;%dm\", r, g, b) // Set foreground color (24-bit RGB)\n#define CLEAR_ATTR()            printf(\"\\033[0m\")           // Clear bold/color attributes\n#define SCREEN_SAVE()           printf(\"\\033[?47h\")         // Save screen display\n#define SCREEN_RESTORE()        printf(\"\\033[?47l\")         // Restore screen to previously saved state\n#define CURSOR_SAVE()           printf(\"\\033[s\")            // Save cursor position\n#define CURSOR_RESTORE()        printf(\"\\033[u\")            // Restore cursor position\n#define CURSOR_HIDE()           printf(\"\\033[?25l\")         // Hide cursor\n#define CURSOR_SHOW()           printf(\"\\033[?25h\")         // Unhide cursor\n\n// Color hex values (approximations of ANSI colors)\n#define COLOR_BLACK   \"#000000\"\n#define COLOR_RED     \"#ff0000\"\n#define COLOR_GREEN   \"#00ff00\"\n#define COLOR_YELLOW  \"#ffff00\"\n#define COLOR_BLUE    \"#0000ff\"\n#define COLOR_MAGENTA \"#ff00ff\"\n#define COLOR_CYAN    \"#00ffff\"\n#define COLOR_WHITE   \"#ffffff\"\n\n// Terminal IO settings\nstatic int clearScr              = 0;                     // clearScr flag\nstatic char foregroundColor[8]   = COLOR_BLUE;            // Foreground color setting\n\n// Function prototypes\nstatic void nmstermio_set_terminal(int);\n\n/*\n * Initialize and configure the terminal for output. This usually means\n * just turning off terminal echo and line buffering. If the clearScr\n * flag is set, it will also save the state of the cursor and screen (so\n * it can be restored) and then clear it.\n */\nvoid nmstermio_init_terminal(void) {\n\n\t// Turn off line buffering and echo\n\tnmstermio_set_terminal(0);\n\t\n\t// Save terminal state, clear screen, and home/hide the cursor\n\tif (clearScr) {\n\t\tCURSOR_SAVE();\n\t\tSCREEN_SAVE();\n\t\tCLEAR_SCR();\n\t\tCURSOR_HOME();\n\t\tCURSOR_HIDE();\n\t}\n}\n\n/*\n * Restore the state of the terminal to the state prior to executing\n * nmstermio_init_terminal(). This usually means turning on line buffering\n * and echo. If the clearScr flag is set, it will also restore the\n * terminal content and cursor position.\n */\nvoid nmstermio_restore_terminal(void) {\n\t\n\t// Restore screen and cursor is clearSrc is set\n\tif (clearScr) {\n\t\tSCREEN_RESTORE();\n\t\tCURSOR_SHOW();\n\t\tCURSOR_RESTORE();\n\t}\n\t\n\t// Turn on line buffering and echo\n\tnmstermio_set_terminal(1);\n}\n\n/*\n * Get and return the number of rows in the current terminal window.\n */\nint nmstermio_get_rows(void) {\n\tstruct winsize w;\n\tioctl(STDOUT_FILENO, TIOCGWINSZ, &w);\n    \n\treturn w.ws_row;\n}\n\n/*\n * Get and return the number of cols in the current terminal window.\n */\nint nmstermio_get_cols(void) {\n\tstruct winsize w;\n\tioctl(STDOUT_FILENO, TIOCGWINSZ, &w);\n    \n\treturn w.ws_col;\n}\n\n/*\n * Move terminal cursor to the given x/y coordinates.\n */\nvoid nmstermio_move_cursor(int y, int x) {\n\tCURSOR_MOVE(y, x);\n}\n\n/*\n * Print the given character string to the terminal output.\n */\nvoid nmstermio_print_string(char *s) {\n\tprintf(\"%s\", s);\n}\n\n/*\n * Refresh the screen. Display all pending output that has not been\n * displayed yet.\n */\nvoid nmstermio_refresh(void) {\n\tfflush(stdout);\n}\n\n/*\n * Clear all input pending in STDIN. This is used prior to getting user\n * input to clear the input queue in case of any prior errant keystrokes.\n */\nvoid nmstermio_clear_input(void) {\n\tint i;\n\t\n\tioctl(STDIN_FILENO, FIONREAD, &i);\n\n\twhile (i-- > 0) {\n\t\tgetchar();\n\t}\n}\n\n/*\n * Get a single character of input from the user. Given that line buffering\n * is turned off, we must constantly loop until we get a character other\n * than EOF.\n */\nchar nmstermio_get_char(void) {\n\tstruct timespec ts;\n\tint t = 50;\n\tint c;\n\t\n\tts.tv_sec = t / 1000;\n\tts.tv_nsec = (t % 1000) * 1000000;\n\n\twhile ((c = getchar()) == EOF) {\n\t\tnanosleep(&ts, NULL);\n\t}\n\t\n\treturn (char)c;\n}\n\n/*\n * Print the character string that represents the decrypted data. We\n * apply the bold and color attributes (if colorOn flag is set) to this\n * string.\n */\nvoid nmstermio_print_reveal_string(char *s, int colorOn) {\n\tint r, g, b;\n\t\n\t// Set bold and foreground color\n\tBOLD();\n\tif (colorOn) {\n\t\tsscanf(foregroundColor + 1, \"%02x%02x%02x\", &r, &g, &b);\n\t\tFOREGROUND_COLOR(r, g, b);\n\t}\n\t\n\t// print string\n\tprintf(\"%s\", s);\n\t\n\t// Unset bold and foreground color\n\tCLEAR_ATTR();\n}\n\n/*\n * Display the cursor that have been turned off by nmstermio_init_terminal().\n */\nvoid nmstermio_show_cursor(void) {\n\tCURSOR_SHOW();\n}\n\n/*\n * Make the terminal beep. Used when the returnOpts setting is set in the\n * nmseffect module.\n */\nvoid nmstermio_beep(void) {\n\tBEEP();\n}\n\n/*\n * Return the status of the clearScr flag. This is used by the nmseffect\n * module to make certain decisions based on its value.\n */\nint nmstermio_get_clearscr(void) {\n\treturn clearScr;\n}\n\n/*\n * Sets the clearScr flag according to the true/false value of the 's' argument.\n */\nvoid nmstermio_set_clearscr(int s) {\n\tif (s)\n\t\tclearScr = 1;\n\telse\n\t\tclearScr = 0;\n}\n\n/*\n * Set the desired foreground color of the unencrypted characters as they\n * are revealed by nmstermio_print_reveal_string(). Valid arguments are\n * \"white\", \"yellow\", \"magenta\", \"blue\", \"green\", \"red\", \"cyan\", or \"#XXXXXX\".\n */\nvoid nmstermio_set_foregroundcolor(char *c) {\n\n\tif (strlen(c) == 7 && strspn(c+1, \"0123456789abcdefABCDEF\") == 6)\n    \tstrcpy(foregroundColor, c);\n\telse if(strcmp(\"white\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_WHITE);\n\telse if(strcmp(\"yellow\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_YELLOW);\n\telse if(strcmp(\"black\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_BLACK);\n\telse if(strcmp(\"magenta\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_MAGENTA);\n\telse if(strcmp(\"blue\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_BLUE);\n\telse if(strcmp(\"green\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_GREEN);\n\telse if(strcmp(\"red\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_RED);\n\telse if(strcmp(\"cyan\", c) == 0)\n\t\tstrcpy(foregroundColor, COLOR_CYAN);\n\telse\n\t\tstrcpy(foregroundColor, COLOR_BLUE);\n}\n\n/*\n * Get and returns the current row position of the cursor. This involves\n * sending the appropriate ANSI escape code to the terminal and\n * reading/parsing its response.\n */\nint nmstermio_get_cursor_row(void) {\n\tint i, r;\n\tint row = 0;\n\tchar buf[10];\n\tchar *cmd = \"\\033[6n\";\n\n\tmemset(buf, 0, sizeof(buf));\n\n\tr = write(STDOUT_FILENO, cmd, strlen(cmd));\n\n\tr = read(STDIN_FILENO, buf, sizeof(buf));\n\n\tfor (i = 0; i < r; ++i) {\n\t\tif (buf[i] == 27 || buf[i] == '[') {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (buf[i] >= '0' && buf[i] <= '9') {\n\t\t\trow = (row * 10) + (buf[i] - '0');\n\t\t}\n\t\t\n\t\tif (buf[i] == ';' || buf[i] == 'R' || buf[i] == 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\treturn row;\n}\n\n/*\n * Turn off terminal echo and line buffering when passed an integer value\n * that evaluates to true. Restore the original terminal values when passed\n * an integer value that evaluates to false.\n */\nstatic void nmstermio_set_terminal(int s) {\n\tstruct termios tp;\n\tstatic struct termios save;\n\tstatic int state = 1;\n\n\tif (!isatty(STDIN_FILENO)) {\n\t\tstdin = freopen(\"/dev/tty\", \"r\", stdin);\n\t}\n\t\n\tif (s == 0) {\n\t\tif (tcgetattr(STDIN_FILENO, &tp) == -1) {\n\t\t\treturn;\n\t\t}\n\n\t\tsave = tp;\n\t\t\n\t\ttp.c_lflag &=(~ICANON & ~ECHO);\n\t\t\n\t\tif (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) == -1) {\n\t\t\treturn;\n\t\t}\n\t} else {\n\t\tif (state == 0 && tcsetattr(STDIN_FILENO, TCSANOW, &save) == -1)\n\t\t\treturn;\n\t}\n\t\n\tstate = s;\n}\n"
  },
  {
    "path": "src/nmstermio.h",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#ifndef NMSTERMIO_H\n#define NMSTERMIO_H 1\n\n// Function prototypes\nvoid nmstermio_init_terminal(void);\nvoid nmstermio_restore_terminal(void);\nint nmstermio_get_rows(void);\nint nmstermio_get_cols(void);\nint nmstermio_get_cursor_row(void);\nvoid nmstermio_move_cursor(int, int);\nvoid nmstermio_print_string(char *);\nvoid nmstermio_refresh(void);\nvoid nmstermio_clear_input(void);\nchar nmstermio_get_char(void);\nvoid nmstermio_print_reveal_string(char *, int);\nvoid nmstermio_show_cursor(void);\nvoid nmstermio_beep(void);\nint nmstermio_get_clearscr(void);\nvoid nmstermio_set_clearscr(int);\nvoid nmstermio_set_foregroundcolor(char *);\nint nmstermio_get_cursor_row(void);\n\n\n#endif\n"
  },
  {
    "path": "src/nmstermio_ncurses.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n/*\n * The nmstermio_ncurses modules implements the terminal interface, with\n * ncurses support, used by the nmseffect module. All terminal IO\n * functionality is defined and implemented here.\n */\n\n#include <stdio.h>\n#include <unistd.h>\n#include <string.h>\n#include <ncurses.h>\n\n// Static settings\nstatic int clearScr          = 1;                     // clearScr flag\nstatic int foregroundColor   = COLOR_BLUE;            // Foreground color setting\n\n/*\n * Initialize and configure the terminal for output. This usually means\n * just turning off terminal echo, line buffering, and clearing the screen.\n * Note that ncurses always clears the screen, so there is no option to do\n * otherwise.\n */\nvoid nmstermio_init_terminal(void) {\n\tif (!isatty(STDIN_FILENO)) {\n\t\tfreopen(\"/dev/tty\", \"r\", stdin);\n\t}\n\tinitscr();\n\tcbreak();\n\tnoecho();\n\tcurs_set(0);\n\tmove(0, 0);\n\tif (has_colors()) {\n\t\tstart_color();\n\t\tinit_pair(1, foregroundColor, COLOR_BLACK);\n\t}\n}\n\n/*\n * Restore the state of the terminal to the state prior to executing\n * nmstermio_init_terminal(). This usually means turning on line buffering,\n * echo, and terminal contents. \n */\nvoid nmstermio_restore_terminal(void) {\n\tendwin();\n}\n\n/*\n * Get and return the number of rows in the current terminal window.\n */\nint nmstermio_get_rows(void) {\n\treturn getmaxy(stdscr);\n}\n\n/*\n * Get and return the number of cols in the current terminal window.\n */\nint nmstermio_get_cols(void) {\n\treturn getmaxx(stdscr);\n}\n\n/*\n * Move terminal cursor to the given x/y coordinates.\n */\nvoid nmstermio_move_cursor(int y, int x) {\n\tmove(y, x);\n}\n\n/*\n * Print the given character string to the terminal output.\n */\nvoid nmstermio_print_string(char *s) {\n\taddstr(s);\n}\n\n/*\n * Refresh the screen. Display all pending output that has not been\n * displayed yet.\n */\nvoid nmstermio_refresh(void) {\n\trefresh();\n}\n\n/*\n * Clear all input pending in STDIN. This is used prior to getting user\n * input to clear the input queue in case of any prior errant keystrokes.\n */\nvoid nmstermio_clear_input(void) {\n\tflushinp();\n}\n\n/*\n * Get a single character of input from the user.\n */\nvoid nmstermio_get_char(void) {\n\tgetch();\n}\n\n/*\n * Print the character string that represents the decrypted data. We\n * apply the bold and color attributes (if the terminal supports color)\n * to this string.\n */\nvoid nmstermio_print_reveal_string(char *s, int colorOn) {\n\t(void) colorOn;\n\t(void) foregroundColor;\n\n\t// Set bold and foreground color for character reveal\n\tattron(A_BOLD);\n\tif (has_colors())\n\t\tattron(COLOR_PAIR(1));\n\t\n\t// print source character\n\taddstr(s);\n\t\n\t// Unset foreground color\n\tif (has_colors())\n\t\tattroff(COLOR_PAIR(1));\n\tattroff(A_BOLD);\n}\n\n/*\n * Display the cursor that have been turned off by nmstermio_init_terminal().\n */\nvoid nmstermio_show_cursor(void) {\n\tcurs_set(1);\n\trefresh();\n}\n\n/*\n * Make the terminal beep. Used when the returnOpts setting is set in the\n * nmseffect module.\n */\nvoid nmstermio_beep(void) {\n\tbeep();\n}\n\n/*\n * Return the status of the clearScr flag. This is used by the nmseffect\n * module to make certain decisions based on its value.\n */\nint nmstermio_get_clearscr(void) {\n\treturn clearScr;\n}\n\n/*\n * Sets the clearScr flag according to the true/false value of the 's' argument.\n */\nvoid nmstermio_set_clearscr(int s) {\n\tif (s)\n\t\tclearScr = 1;\n\telse\n\t\tclearScr = 0;\n}\n\n/*\n * Set the desired foreground color of the unencrypted characters as they\n * are revealed by nmstermio_print_reveal_string(). Valid arguments are\n * \"white\", \"yellow\", \"magenta\", \"blue\", \"green\", \"red\", and \"cyan\".\n */\nvoid nmstermio_set_foregroundcolor(char *c) {\n\n\tif(strcmp(\"white\", c) == 0)\n\t\tforegroundColor =  COLOR_WHITE;\n\telse if(strcmp(\"yellow\", c) == 0)\n\t\tforegroundColor = COLOR_YELLOW;\n\telse if(strcmp(\"black\", c) == 0)\n\t\tforegroundColor = COLOR_BLACK;\n\telse if(strcmp(\"magenta\", c) == 0)\n\t\tforegroundColor = COLOR_MAGENTA;\n\telse if(strcmp(\"blue\", c) == 0)\n\t\tforegroundColor = COLOR_BLUE;\n\telse if(strcmp(\"green\", c) == 0)\n\t\tforegroundColor = COLOR_GREEN;\n\telse if(strcmp(\"red\", c) == 0)\n\t\tforegroundColor = COLOR_RED;\n\telse if(strcmp(\"cyan\", c) == 0)\n\t\tforegroundColor = COLOR_CYAN;\n\telse\n\t\tforegroundColor = COLOR_BLUE;\n}\n\n/*\n * Get and returns the current row position of the cursor.\n */\nint nmstermio_get_cursor_row(void) {\n\treturn getcury(stdscr);\n}\n"
  },
  {
    "path": "src/sneakers.c",
    "content": "/*\n * Copyright (c) 2017 Brian Barto\n * \n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GPL License. See LICENSE for more details.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/ioctl.h>\n#include \"nmseffect.h\"\n\nint main(void) {\n\tint termCols, spaces = 0;\n\tunsigned char *display_uc = NULL;\n\tchar *display        = NULL;\n\tchar *head1Left      = \"DATANET PROC RECORD:  45-3456-W-3452\";\n\tchar *head1Right     = \"Transnet on/xc-3\";\n\tchar *head2Center    = \"FEDERAL RESERVE TRANSFER NODE\";\n\tchar *head3Center    = \"National Headquarters\";\n\tchar *head4Center    = \"************  Remote Systems Network Input Station  ************\";\n\tchar *head5Center    = \"================================================================\";\n\tchar *menu1          = \"[1] Interbank Funds Transfer  (Code Prog: 485-GWU)\";\n\tchar *menu2          = \"[2] International Telelink Access  (Code Lim: XRP-262)\";\n\tchar *menu3          = \"[3] Remote Facsimile Send/Receive  (Code Tran:  2LZP-517)\";\n\tchar *menu4          = \"[4] Regional Bank Interconnect  (Security Code:  47-B34)\";\n\tchar *menu5          = \"[5] Update System Parameters  (Entry Auth. Req.)\";\n\tchar *menu6          = \"[6] Remote Operator Logon/Logoff\";\n\tchar *foot1Center    = \"================================================================\";\n\tchar *foot2Center    = \"[ ] Select Option or ESC to Abort\";\n\n\t// Get terminal dimentions (needed for centering)\n\tstruct winsize w;\n    // if not an interactive tty, w is not populated, resulting in UB\n\tif (ioctl(0, TIOCGWINSZ, &w) == -1) {\n        perror(\"Input not from an interactive terminal\");\n        return 1;\n    }\n\ttermCols = w.ws_col;\n\n\t// Allocate space for our display string\n\tif ((display = malloc(20 * termCols)) == NULL)\n\t{\n\t\tfprintf(stderr, \"Memory Allocation Error. Quitting!\\n\");\r\n\t\treturn 1;\r\n\t}\n\n\t// Allocate space for our display string\n\tif ((display_uc = malloc(20 * termCols)) == NULL)\n\t{\n        free(display);\n\t\tfprintf(stderr, \"Memory Allocation Error. Quitting!\\n\");\r\n\t\treturn 1;\r\n\t}\n\n\tmemset(display, 0, 20 * termCols);\n\tmemset(display_uc, 0, 20 * termCols);\n\n\t// Start building the display string\n\tstrcpy(display, head1Left);\n\n\tspaces = termCols - strlen(head1Left) - strlen(head1Right);\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, head1Right);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(head2Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, head2Center);\n\n\tstrcat(display, \"\\n\");\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(head3Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, head3Center);\n\n\tstrcat(display, \"\\n\");\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(head4Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, head4Center);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(head5Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, head5Center);\n\n\tstrcat(display, \"\\n\");\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu1);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu2);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu3);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu4);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu5);\n\n\tstrcat(display, \"\\n\");\n\n\tspaces = ((termCols - strlen(head5Center)) / 2) + 3;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, menu6);\n\n\tstrcat(display, \"\\n\");\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(foot1Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, foot1Center);\n\n\tstrcat(display, \"\\n\");\n\tstrcat(display, \"\\n\");\n\n\tspaces = (termCols - strlen(foot2Center)) / 2;\n\twhile (spaces > 0) {\n\t\tstrcat(display, \" \");\n\t\t--spaces;\n\t}\n\tstrcat(display, foot2Center);\n\n\tnmseffect_set_clearscr(1);\n\n\tmemcpy(display_uc, display, 20 * termCols);\n\n\t// Execute effect\n\tnmseffect_exec(display_uc, strlen(display));\n\n\tfree(display);\n\tfree(display_uc);\n\n\treturn 0;\n}\n"
  }
]