[
  {
    "path": ".github/workflows/python-package-develop.yml",
    "content": "# This workflow will install Python dependencies, run tests and lint with a variety of Python versions\n# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions\n\nname: CI-Dev\n\non:\n  push:\n    branches: [ develop ]\n    paths-ignore:\n    - 'License'\n    - 'README.md'\n  pull_request:\n    branches: [ develop ]\n    paths-ignore:\n    - 'License'\n    - 'README.md'\n\njobs:\n  build:\n\n    runs-on: ${{ matrix.os }}\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest]\n        python-version: [\"3.7\", \"3.8\", \"3.9\", \"3.10\", \"3.11\", \"3.12\"]\n\n\n    steps:\n    - uses: actions/checkout@v2\n    - name: Set up Python ${{ matrix.python-version }}\n      uses: actions/setup-python@v2\n      with:\n        python-version: ${{ matrix.python-version }}\n    - name: Install dependencies\n      run: |\n        python -m pip install --upgrade pip\n        python -m pip install -r requirements-dev.txt\n        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi\n        python -m pip install -e .\n    - name: Check formatted with black\n      run: |\n        black --check c_formatter_42 tests\n    - name: Lint with flake8\n      run: |\n        flake8 c_formatter_42\n        flake8 --extend-ignore=W191,E101,E501 tests\n    - name: Test with pytest\n      run: |\n        pytest -vvv\n    - name: Static type checking with mypy\n      run: |\n        mypy c_formatter_42\n"
  },
  {
    "path": ".github/workflows/python-package.yml",
    "content": "# This workflow will install Python dependencies, run tests and lint with a variety of Python versions\n# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions\n\nname: CI\n\non:\n  push:\n    branches: [ master ]\n    paths-ignore:\n      - 'setup.py'\n      - 'setup.cfg'\n      - 'requirements-dev.txt'\n      - 'MANIFEST.in'\n      - 'Img/'\n      - 'License'\n      - 'README.md'\n  pull_request:\n    branches: [ master ]\n    paths-ignore:\n      - 'License'\n      - 'README.md'\n\njobs:\n  build:\n\n    runs-on: ${{ matrix.os }}\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest] # , macos-11]\n        python-version: [\"3.8\", \"3.9\", \"3.10\", \"3.11\", \"3.12\"]\n\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Set up Python ${{ matrix.python-version }}\n        uses: actions/setup-python@v2\n        with:\n          python-version: ${{ matrix.python-version }}\n      - name: Install dependencies\n        run: |\n          python -m pip install --upgrade pip\n          python -m pip install -r requirements-dev.txt\n          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi\n          python -m pip install -e .\n      - name: Check formatted with black\n        run: |\n          black --check c_formatter_42 tests\n      - name: Lint with flake8\n        run: |\n          flake8 c_formatter_42\n          flake8 --extend-ignore=W191,E101,E501 tests\n      - name: Test with pytest\n        run: |\n          pytest -vvv\n      - name: Static type checking with mypy\n        run: |\n          mypy c_formatter_42\n"
  },
  {
    "path": ".github/workflows/python-publish.yml",
    "content": "# This workflow will upload a Python Package using Twine when a release is created\n# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries\n\n# This workflow uses actions that are not certified by GitHub.\n# They are provided by a third-party and are governed by\n# separate terms of service, privacy policy, and support\n# documentation.\n\nname: CD\n\non:\n  release:\n    types: [published]\n\njobs:\n  deploy:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v2\n    - name: Set up Python\n      uses: actions/setup-python@v2\n      with:\n        python-version: '3.x'\n    - name: Install dependencies\n      run: |\n        python -m pip install --upgrade pip\n        pip install build\n    - name: Build package\n      run: python -m build\n    - name: Publish package\n      uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29\n      with:\n        user: __token__\n        password: ${{ secrets.PYPI_API_TOKEN }}\n"
  },
  {
    "path": ".gitignore",
    "content": "__pycache__\ntags\n.tox/\n*egg-info\ndist/\nbuild/\ndocs/build/\n.coverage\n/.venv\n/debug\n/.vimspector.json\n\n.vscode\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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<https://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<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\">\n  <a style=\"text-decoration:none\" href=\"https://badge.fury.io/py/c-formatter-42\"><img src=\"https://badge.fury.io/py/c-formatter-42.svg\" alt=\"PyPI version\" height=\"20\"></a>\n  <a style=\"text-decoration:none\" href=\"https://github.com/dawnbeen/c_formatter_42/actions\"><img src=\"https://github.com/cacharle/c_formatter_42/actions/workflows/python-package.yml/badge.svg\" height=\"20\"></a>\n  <a style=\"text-decoration:none\" href=\"https://github.com/dawnbeen/c_formatter_42/actions\"><img src=\"https://github.com/cacharle/c_formatter_42/actions/workflows/python-publish.yml/badge.svg\" height=\"20\"></a>\n  <a style=\"text-decoration:none\" href=\"https://pypi.org/project/c-formatter-42/\"><img src=\"https://img.shields.io/pypi/pyversions/c-formatter-42\" height=\"20\"></a>\n</p>\n\n<br />\n\n<p align=\"center\">\n  <img width=\"65%\" align=\"center\" src=\"./img/final_back.png\">\n</p>\n\n# c_formatter_42\n\nC language prettier that conforms to 42 norm v3.\nI know you are already a good human norm.\nIt's just for convenience.\n\n## Installation\n\nRequires Python3.8+ (3.9, 3.10, 3.11, 3.12)\n\n### With pipx (recommanded)\n\n```sh\npipx run c-formatter-42\n```\n\n### With pip\n\n```sh\npip3 install c-formatter-42\npip3 install --user c-formatter-42  # If you don't have root privileges\n```\n\nIf you're on Ubuntu 22.04 or newer (or any Debian-based system with PEP 668 enabled), you might see an error like:\n\n`error: externally-managed-environment`\n\nTo fix this, add the `--break-system-packages` flag:\n\n```sh\npip3 install --break-system-packages c-formatter-42\n```\n\n### From source\n\n```sh\ngit clone https://github.com/cacharle/c_formatter_42\ncd c_formatter_42\npip3 install -e .\n```\n\n## Usage\n\n### Command line\n\n```sh\nc_formatter_42 < file.c\npython3 -m c_formatter_42 < file.c  # If you get 'command not found' with the previous one\n\nc_formatter_42 --help\nusage: c_formatter_42 [-h] [-c] [FILE [FILE ...]]\n\nFormat C source according to the norm\n\npositional arguments:\n  FILE           File to format inplace, if no file is provided read STDIN\n\noptional arguments:\n  -h, --help     show this help message and exit\n  -c, --confirm  Ask confirmation before overwriting any file\n```\n\n## Plugins / Extensions\n\n### Vim\n\nCheck out the [`c_formatter_42.vim`](https://github.com/cacharle/c_formatter_42.vim) plugin. This plugin automatically installs the `c_formatter_42` package using pip.\n\n### Visual Studio Code\n\n1. Install `c_formatter_42`\n1. Install the [`keyhr.42-c-format`](https://marketplace.visualstudio.com/items?itemName=keyhr.42-c-format) extension\n1. Set `keyhr.42-c-format` as the default formatter for C files in `.vscode/settings.json`\n\n```json\n{\n  \"[c]\": {\n    \"editor.defaultFormatter\": \"keyhr.42-c-format\"\n  }\n}\n```\n\n## Contributing\n\nFeel free to report issues or contribute. :)\n\n### Run the tests\n\n```sh\npip3 install tox\ntox\ntox -e py311  # for a specific python version\n```\n\n### Deploy a new version\n\n```sh\npip3 install bumpversion\nbumpversion [major|minor|patch]\ngit push\ngit push --tags\n```\n\nGo to: <https://github.com/dawnbeen/c_formatter_42/tags> and click on the tag you just created.\nThen click on `Create release from tag`, the pipeline will build and deploy that version for you.\n"
  },
  {
    "path": "c_formatter_42/__init__.py",
    "content": "__version__ = \"0.2.8\"\n"
  },
  {
    "path": "c_formatter_42/__main__.py",
    "content": "#!/usr/bin/env python3\n\n# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    main.py                                            :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 09:53:21 by cacharle          #+#    #+#              #\n#    Updated: 2020/10/04 09:53:21 by cacharle         ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport argparse\nimport sys\n\nfrom c_formatter_42.run import run_all\n\n\ndef main() -> int:\n    arg_parser = argparse.ArgumentParser(\n        prog=\"c_formatter_42\",\n        description=\"Format C source according to the norm\",\n        formatter_class=argparse.RawTextHelpFormatter,\n    )\n    arg_parser.add_argument(\n        \"-c\",\n        \"--confirm\",\n        action=\"store_true\",\n        help=\"Ask confirmation before overwriting any file\",\n    )\n    arg_parser.add_argument(\n        \"filepaths\",\n        metavar=\"FILE\",\n        nargs=\"*\",\n        help=\"File to format inplace, if no file is provided read STDIN\",\n    )\n    args = arg_parser.parse_args()\n\n    if len(args.filepaths) == 0:\n        content = sys.stdin.read()\n        print(run_all(content), end=\"\")\n        return 0\n\n    for filepath in args.filepaths:\n        try:\n            with open(filepath, \"r\") as file:\n                content = file.read()\n            if args.confirm:\n                result = input(f\"Are you sure you want to overwrite {filepath}?[y/N]\")\n                if result != \"y\":\n                    continue\n            print(f\"Writing to {filepath}\")\n            with open(filepath, \"w\") as file:\n                file.write(run_all(content))\n        except OSError as e:\n            print(f\"Error: {e.filename}: {e.strerror}\", file=sys.stderr)\n            return 1\n    return 0\n\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n"
  },
  {
    "path": "c_formatter_42/data/.clang-format",
    "content": "---\n# BasedOnStyle: LLVM\n---\n\n# Language (LanguageKind)\n# Language, this format style is targeted at.\n#\tLK_Cpp (in configuration: Cpp) Should be used for C, C++, ObjectiveC, ObjectiveC++.\nLanguage: Cpp\n\n\n# TabWidth (unsigned)\n# The number of columns used for tab stops.\nTabWidth: 4\n\n\n# IndentWidth (unsigned)\n# The number of columns to use for indentation.\nIndentWidth: 4\n\n\n# TODO: If it can be enabled with tabs instead of spaces, it can fit 42 norm.\n# AlignConsecutiveDeclarations (bool)\n# If true, aligns consecutive declarations.\n# Ex)\n# int         aaaa = 12;\n# float       b = 23;\n# std::string ccc = 23;\n# AlignConsecutiveDeclarations: false\n\n\n# UseTab (UseTabStyle)\n# The way to use tab characters in the resulting file.\n# UT_ForContinuationAndIndentation (in configuration: ForContinuationAndIndentation) Use tabs only for line continuation and indentation.\n# UT_Always (in configuration: Always) Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.\nUseTab: ForContinuationAndIndentation\n\n\n# SpaceBeforeParens (SpaceBeforeParensOptions)\n# Defines in which cases to put a space before opening parentheses.\n# SBPO_ControlStatements (in configuration: ControlStatements) Put a space before opening parentheses only after control statement keywords (for/if/while...).\nSpaceBeforeParens: ControlStatements\n\n\n# AllowShortFunctionsOnASingleLine (ShortFunctionStyle)\n# Dependent on the value, int f() { return 0; } can be put on a single line.\n# SFS_None (in configuration: None) Never merge functions into a single line.\nAllowShortFunctionsOnASingleLine: None\n\n\n# Options for aligning backslashes in escaped newlines.\n# ENAS_Left (in configuration: Left) Align escaped newlines as far left as possible.\nAlignEscapedNewlines: Left\n\n\n# Dependent on the value, while (true) { continue; } can be put on a single line.\n# SBS_Never (in configuration: Never) Never merge blocks into a single line.\nAllowShortBlocksOnASingleLine: Never\n\n\n# If true, if (a) return; can be put on a single line.\n# SIS_Never (in configuration: Never) Never put short ifs on the same line.\nAllowShortIfStatementsOnASingleLine: Never\n\n# AlwaysBreakAfterDefinitionReturnType (DefinitionReturnTypeBreakingStyle)\n# The function definition return type breaking style to use. This option is deprecated and is retained for backwards compatibility.\n# DRTBS_None (in configuration: None) Break after return type automatically. PenaltyReturnTypeOnItsOwnLine is taken into account.\nAlwaysBreakAfterReturnType: None\n\n# AlwaysBreakBeforeMultilineStrings (bool)\n# If true, always break before multiline string literals.\nAlwaysBreakBeforeMultilineStrings: false\n\n\n# BinPackArguments (bool)\n# If false, a function call’s arguments will either be all on the same line or will have one line each.\nBinPackArguments: false\n\n\n# BinPackParameters (bool)\n# If false, a function declaration’s or function definition’s parameters will either all be on the same line or will have one line each.\nBinPackParameters: false\n\n# BreakBeforeBraces (BraceBreakingStyle)\n# The brace breaking style to use.\n# BS_Allman (in configuration: Allman) Always break before braces.\nBreakBeforeBraces: Allman\n\n# BreakBeforeTernaryOperators (bool)\n# If true, ternary operators will be placed after line breaks.\nBreakBeforeTernaryOperators: true\n\n\n# ColumnLimit (unsigned)\n# The column limit.\nColumnLimit: 1024\n\n\n# FixNamespaceComments (bool)\n# If true, clang-format adds missing namespace end comments and fixes invalid existing ones.\n# FixNamespaceComments: false\n\n\n# IncludeBlocks (IncludeBlocksStyle)\n# Dependent on the value, multiple #include blocks can be sorted as one and divided based on category.\n# IBS_Merge (in configuration: Merge) Merge multiple #include blocks together and sort as one.\nIncludeBlocks: Merge\n\n\n# KeepEmptyLinesAtTheStartOfBlocks (bool)\n# If true, the empty line at the start of blocks is kept.\nKeepEmptyLinesAtTheStartOfBlocks: false\n\n\n# MaxEmptyLinesToKeep (unsigned)\n# The maximum number of consecutive empty lines to keep.\nMaxEmptyLinesToKeep: 1\n\n\n# PointerAlignment (PointerAlignmentStyle)\n# Pointer and reference alignment style.\n# PAS_Right (in configuration: Right) Align pointer to the right.\nPointerAlignment: Right\n\n\n# PenaltyBreakBeforeFirstCallParameter (unsigned)\n# The penalty for breaking a function call after call(.\nPenaltyBreakBeforeFirstCallParameter: 1\n\n\n# PenaltyBreakString (unsigned)\n# The penalty for each line break introduced inside a string literal.\nPenaltyBreakString: 1\n\n\n# PenaltyExcessCharacter (unsigned)\n# The penalty for each character outside of the column limit.\nPenaltyExcessCharacter: 10\n\nPenaltyReturnTypeOnItsOwnLine: 100\n\n# SpaceAfterCStyleCast (bool)\n# If true, a space is inserted after C style casts.\nSpaceAfterCStyleCast: false\n\n# SpaceBeforeAssignmentOperators (bool)\n# If false, spaces will be removed before assignment operators.\nSpaceBeforeAssignmentOperators: true\n\n\n# SpaceBeforeSquareBrackets (bool)\n# If true, spaces will be before [. Lambdas will not be affected. Only the first [ will get a space added.\nSpaceBeforeSquareBrackets: false\n\n\n# SpaceInEmptyParentheses (bool)\n# If true, spaces may be inserted into ().\nSpaceInEmptyParentheses: false\n\n\n# SpacesInCStyleCastParentheses (bool)\n# If true, spaces may be inserted into C style casts.\nSpacesInCStyleCastParentheses: false\n\n\n# SpacesInParentheses (bool)\n# If true, spaces will be inserted after ( and before ).\nSpacesInParentheses: false\n\n\n# SpacesInSquareBrackets (bool)\n# If true, spaces will be inserted after [ and before ]. Lambdas without arguments or unspecified size array declarations will not be affected.\nSpacesInSquareBrackets: false\n\nAlignOperands: false\n\nCpp11BracedListStyle: true\n\n#InsertTrailingCommas: Wrapped\n\n# vim:ft=yaml\n"
  },
  {
    "path": "c_formatter_42/data/__init__.py",
    "content": ""
  },
  {
    "path": "c_formatter_42/formatters/__init__.py",
    "content": ""
  },
  {
    "path": "c_formatter_42/formatters/align.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    align.py                                           :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 09:56:31 by cacharle          #+#    #+#              #\n#    Updated: 2021/02/11 20:13:11 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nfrom __future__ import annotations\n\nimport re\nimport typing\n\nif typing.TYPE_CHECKING:\n    from typing import Literal\n\nfrom c_formatter_42.formatters import helper\n\nTYPEDECL_OPEN_REGEX = re.compile(\n    r\"\"\"^(?P<prefix>\\s*(typedef\\s+)?   # Maybe a typedef\n        (struct|enum|union))           # Followed by a struct, enum or union\n        \\s*(?P<suffix>[a-zA-Z_]\\w+)?$  # Name of the type declaration\n    \"\"\",\n    re.X,\n)\nTYPEDECL_CLOSE_REGEX = re.compile(\n    r\"\"\"^(?P<prefix>\\})\\s*             # Closing } followed by any amount of spaces\n        (?P<suffix>([a-zA-Z_]\\w+)?;)$  # Name of the type (if typedef used)\n    \"\"\",\n    re.X,\n)\n\n\ndef align_scope(content: str, scope: Literal[\"local\", \"global\"]) -> str:\n    \"\"\"Align content\n    scope can be either local or global\n      local:  for variable declarations in function\n      global: for function prototypes\n    \"\"\"\n\n    lines = content.split(\"\\n\")\n    # select regex according to scope\n    if scope == \"local\":\n        align_regex = \"^\\t\" r\"(?P<prefix>{type})\\s+\" r\"(?P<suffix>\\**{decl};)$\"\n    elif scope == \"global\":\n        align_regex = (\n            r\"^(?P<prefix>{type})\\s+\"\n            r\"(?P<suffix>({name}\\(.*\\)?;?)|({decl}(;|(\\s+=\\s+.*))))$\"\n        )\n    align_regex = align_regex.format(\n        type=helper.REGEX_TYPE, name=helper.REGEX_NAME, decl=helper.REGEX_DECL_NAME\n    )\n    lines_to_be_aligned = [re.match(align_regex, line) for line in lines]\n    aligned = [\n        (i, match.group(\"prefix\"), match.group(\"suffix\"))\n        for i, match in enumerate(lines_to_be_aligned)\n        if match is not None\n        and match.group(\"prefix\") not in [\"struct\", \"union\", \"enum\"]\n    ]\n\n    # Global type declaration (struct/union/enum)\n    if scope == \"global\":\n        in_type_scope = False\n        for i, line in enumerate(lines):\n            m = TYPEDECL_OPEN_REGEX.match(line)\n            if m is not None:\n                in_type_scope = True\n                if m.group(\"suffix\") is not None and \"typedef\" not in m.group(\"prefix\"):\n                    aligned.append((i, m.group(\"prefix\"), m.group(\"suffix\")))\n                continue\n            m = TYPEDECL_CLOSE_REGEX.match(line)\n            if m is not None:\n                in_type_scope = False\n                if line != \"};\":\n                    aligned.append((i, m.group(\"prefix\"), m.group(\"suffix\")))\n                continue\n            if in_type_scope:\n                m = re.match(\n                    r\"^(?P<prefix>\\s+{type})\\s+\"\n                    r\"(?P<suffix>\\**{decl};)$\".format(\n                        type=helper.REGEX_TYPE, decl=helper.REGEX_DECL_NAME\n                    ),\n                    line,\n                )\n                if m is not None:\n                    aligned.append((i, m.group(\"prefix\"), m.group(\"suffix\")))\n\n    # Minimum alignment required for each line\n    min_alignment = max(\n        (len(prefix.expandtabs(4)) // 4 + 1 for _, prefix, _ in aligned), default=1\n    )\n    for i, prefix, suffix in aligned:\n        alignment = len(prefix.expandtabs(4)) // 4\n        lines[i] = prefix + \"\\t\" * (min_alignment - alignment) + suffix\n        if scope == \"local\":\n            lines[i] = (\n                \"\\t\" + lines[i]\n            )  # Adding one more indent for inside the type declaration\n    return \"\\n\".join(lines)\n\n\n@helper.locally_scoped\ndef align_local(content: str) -> str:\n    \"\"\"Wrapper for align_scope to use local_scope decorator\"\"\"\n    return align_scope(content, scope=\"local\")\n\n\ndef align(content: str) -> str:\n    \"\"\"Align the content in global and local scopes\"\"\"\n    content = align_scope(content, scope=\"global\")\n    content = align_local(content)\n    return content\n"
  },
  {
    "path": "c_formatter_42/formatters/clang_format.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    clang_format.py                                    :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 10:40:07 by cacharle          #+#    #+#              #\n#    Updated: 2021/02/25 20:46:18 by cacharle         ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport contextlib\nimport platform\nimport subprocess\nimport sys\nfrom pathlib import Path\n\nimport c_formatter_42.data\n\nCONFIG_FILENAME = Path(\".clang-format\")\nDATA_DIR = Path(c_formatter_42.data.__file__).parent\n\n\n@contextlib.contextmanager\ndef _config_context():\n    \"\"\"Temporarly place .clang-format config file in the current directory\n    If there already is a config in the current directory, it's backed up\n    then put back in place after clang-format is done running\n    \"\"\"\n    config_path = DATA_DIR / CONFIG_FILENAME\n    previous_config = None\n    try:\n        CONFIG_FILENAME.symlink_to(config_path)\n    except FileExistsError:\n        if not CONFIG_FILENAME.is_symlink():\n            previous_config = CONFIG_FILENAME.read_text()\n        CONFIG_FILENAME.unlink()\n        CONFIG_FILENAME.symlink_to(config_path)\n    try:\n        yield\n    finally:\n        CONFIG_FILENAME.unlink()\n        if previous_config is not None:\n            CONFIG_FILENAME.write_text(previous_config)\n\n\nif sys.platform == \"linux\":\n    CLANG_FORMAT_EXEC = DATA_DIR / \"clang-format-linux\"\nelif sys.platform == \"darwin\":\n    if platform.machine() == \"arm64\":\n        # macOS M1 or Apple Silicon\n        CLANG_FORMAT_EXEC = DATA_DIR / \"clang-format-darwin-arm64\"\n    elif platform.machine() == \"x86_64\":\n        # macOS Intel\n        CLANG_FORMAT_EXEC = DATA_DIR / \"clang-format-darwin\"\nelif sys.platform == \"win32\":\n    CLANG_FORMAT_EXEC = DATA_DIR / \"clang-format-win32.exe\"\nelse:\n    raise NotImplementedError(\"Your platform is not supported\")\n\n\ndef clang_format(content: str) -> str:\n    \"\"\"Wrapper around clang-format\n\n    Pass content on stdin and return stdout.\n    The clang-format executable is selected according to the platform,\n    this is to keep the same version of clang-format accross all setup.\n    \"\"\"\n    with _config_context():\n        process = subprocess.Popen(\n            [CLANG_FORMAT_EXEC, \"-style=file\"],\n            stdin=subprocess.PIPE,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n        )\n        out, err = process.communicate(input=content.encode())\n        if process.returncode != 0:  # pragma: no cover\n            raise RuntimeError(f\"clang-format error: {err.decode()}\")\n        return out.decode()\n"
  },
  {
    "path": "c_formatter_42/formatters/helper.py",
    "content": "# **************************************************************************** #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    helper.py                                          :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: leo <leo@student.42.fr>                    +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 11:38:00 by cacharle          #+#    #+#              #\n#    Updated: 2023/09/22 15:21:49 by leo              ###   ########.fr        #\n#                                                                              #\n# **************************************************************************** #\n\nfrom __future__ import annotations\n\nimport re\nimport typing\n\nif typing.TYPE_CHECKING:\n    from typing import Callable\n\n# regex for a type\nREGEX_TYPE = r\"(?!return|goto)([a-z]+\\s+)*[a-zA-Z_]\\w*\"\n# regex for a c variable/function name\nREGEX_NAME = r\"\\**[a-zA-Z_*()]\\w*\"\n# regex for a name in a declaration context (with array and function ptr)\nREGEX_DECL_NAME = r\"\\(?{name}(\\[.*\\])*(\\s\\=\\s.*)?(\\)\\(.*\\))?\".format(name=REGEX_NAME)\n\n\ndef locally_scoped(func: Callable[[str], str]) -> Callable[[str], str]:\n    \"\"\"Apply the formatter on every local scopes of the content\"\"\"\n\n    def wrapper(content: str) -> str:\n        def replacement_func(match: re.Match) -> str:\n            result = func(match.group(\"body\").strip(\"\\n\"))\n            # Edge case for functions with empty bodies (See PR#31)\n            if result.strip() == \"\":\n                return \")\\n{\\n}\\n\"\n            return \")\\n{\\n\" + result + \"\\n}\\n\"\n\n        return re.sub(\n            # `*?` is the non greedy version of `*`\n            # https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy\n            r\"\\)\\n\\{(?P<body>.*?)\\n\\}\\n\".replace(r\"\\n\", \"\\n\"),\n            replacement_func,\n            content,\n            flags=re.DOTALL,\n        )\n\n    return wrapper\n"
  },
  {
    "path": "c_formatter_42/formatters/hoist.py",
    "content": "# **************************************************************************** #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    hoist.py                                           :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: leo <leo@student.42.fr>                    +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 11:16:28 by cacharle          #+#    #+#              #\n#    Updated: 2023/09/22 16:16:01 by leo              ###   ########.fr        #\n#                                                                              #\n# **************************************************************************** #\n\nimport re\n\nimport c_formatter_42.formatters.helper as helper\n\nDECLARATION_REGEX = re.compile(\n    r\"^\\s*{t}\\s+{d};$\".format(t=helper.REGEX_TYPE, d=helper.REGEX_DECL_NAME)\n)\n\n\n@helper.locally_scoped\ndef hoist(content: str) -> str:\n    r\"\"\"Hoist local variable and split assigned declaration\n\n    Assignment splitting:\n    {                   {\n        int a = 1;  =>      int a;\n                            a = 1;\n    }                   }\n\n    Variable hoisting:\n    {                         {\n        puts(\"bonjour\");          int a;\n        int a;            =>      char b;\n        char b;                   puts(\"bonjour\");\n    }                         }\n\n    Only one empty line after declarations\n    {                         {\n                                  int a;\n        int a;                    char b;\n        puts(\"bonjour\");  ->\n                                  puts(\"bonjour\");\n        char b;               }\n    }\n    \"\"\"\n    input_lines = content.split(\"\\n\")\n    lines = []\n    # Split assignment\n    for line in input_lines:\n        m = re.match(\n            r\"^(?P<indent>\\s+)\"\n            r\"(?P<type>{t})\\s+\"\n            r\"(?P<name>{d})\\s+=\\s+\"\n            r\"(?P<value>.+);$\".format(t=helper.REGEX_TYPE, d=helper.REGEX_DECL_NAME),\n            line,\n        )\n        # If line is a declaration + assignment on the same line,\n        # create 2 new lines, one for the declaration and one for the assignment\n        # NOTE: edge case for array declarations which can't be hoisted (See #56)\n        if (\n            m is not None\n            and re.match(r\".*\\[.*\\].*\", m.group(\"name\")) is None\n            and re.match(r\"\\s*(const|static)\\s.*\", line) is None\n        ):\n            lines.append(f\"\\t{m.group('type')}\\t{m.group('name')};\")\n            lines.append(\n                \"{}{} = {};\".format(\n                    m.group(\"indent\"),\n                    m.group(\"name\").replace(\"*\", \"\"),  # replace '*' for pointers\n                    m.group(\"value\"),\n                )\n            )\n        else:\n            lines.append(line)\n\n    # Split declarations from body and remove empty lines\n    declarations = [line for line in lines if DECLARATION_REGEX.match(line) is not None]\n    body = [line for line in lines if line not in declarations and line != \"\"]\n    lines = declarations\n    if len(declarations) != 0:\n        lines.append(\"\")\n    lines.extend(body)\n    return \"\\n\".join(lines)\n"
  },
  {
    "path": "c_formatter_42/formatters/line_breaker.py",
    "content": "import re\n\nfrom c_formatter_42.formatters import helper\n\n\ndef line_breaker(content: str, column_limit: int = 80) -> str:\n    lines = content.split(\"\\n\")\n    lines = [insert_break(line, column_limit) for line in lines]\n    return \"\\n\".join(lines)\n\n\ndef insert_break(line: str, column_limit: int) -> str:\n    if line_length(line) <= column_limit:\n        return line\n\n    # Break at all breakable spaces (space after comma or space before binary\n    # operators or logical AND or OR)\n    breakable_space_pattern = r\"((?<=,) | (?=[+\\-*/%]|\\|\\||&&)(?!\\*+\\S|\\+\\+|\\-\\-))\"\n    line = re.sub(breakable_space_pattern, \"\\n\", line)\n    segments = line.split(\"\\n\")\n\n    line_indent_level = indent_level(line)\n    nest_indent_level = additional_nest_indent_level(line)\n\n    # Join as many segments as it doesn't exceed line length limit\n    line = segments[0]\n    current_line_length = line_length(segments[0])\n    for segment in segments[1:]:\n        current_line_length += line_length(segment) + 1\n        if current_line_length > column_limit:\n            tabulation = \"\\t\" * (\n                line_indent_level + additional_indent_level(line, nest_indent_level)\n            )\n            line = (\"\\n\" + tabulation).join([line, segment])\n            current_line_length = line_length(tabulation + segment)\n        else:\n            line = \" \".join([line, segment])\n\n    return line\n\n\ndef parenthesis_depth(s: str) -> int:\n    paren_depth = 0\n    # sq == single quote\n    # dq == double quote\n    is_surrounded_sq = False\n    is_surrounded_dq = False\n    for c in s:\n        if c == \"'\" and not is_surrounded_dq:\n            is_surrounded_sq = not is_surrounded_sq\n        elif c == '\"' and not is_surrounded_sq:\n            is_surrounded_dq = not is_surrounded_dq\n        elif c == \"(\" and not is_surrounded_sq and not is_surrounded_dq:\n            paren_depth += 1\n        elif c == \")\" and not is_surrounded_sq and not is_surrounded_dq:\n            paren_depth -= 1\n    return paren_depth\n\n\n# The additional indent level increases in proportion to the corresponding parentheses depth\n#\n# Examples:\n#   -----------------------------------------------------------------------------------\n#   foo() * bar() * baz()\n#   ~~~~~~~~~~~~~^~~~~~~~   When line breaks here,\n#   foo() * bar()\n#   >   * baz()             Next line should be indented with 1 tab (default)\n#   -----------------------------------------------------------------------------------\n#   foo(bar() * baz())\n#   ~~~~~~~~~^~~~~~~~~      When line breaks here,\n#   foo(bar()\n#   >   * baz())            Next line should be indented with 1 tab (paren depth is 1)\n#   -----------------------------------------------------------------------------------\n#   (foo(bar() * baz()))\n#   ~~~~~~~~~~^~~~~~~~~~    When line breaks here,\n#   (foo(bar()\n#   >   >   * baz()))       Next line should be indented with 2 tabs (paren depth is 2)\n#   -----------------------------------------------------------------------------------\ndef additional_indent_level(s: str, nest_indent_level: int = 0) -> int:\n    paren_depth = parenthesis_depth(s)\n    return nest_indent_level + paren_depth if paren_depth > 0 else 1\n\n\ndef additional_nest_indent_level(line: str) -> int:\n    # An exceptional rule for variable assignment\n    # https://github.com/42School/norminette/blob/921b5e22d991591f385e1920f7e7ee5dcf71f3d5/norminette/rules/check_assignation_indent.py#L59\n    is_assignation = False\n    is_surrounded_sq = False\n    is_surrounded_dq = False\n    for index, c in enumerate(line):\n        if c == \"'\" and not is_surrounded_dq:\n            is_surrounded_sq = not is_surrounded_sq\n        elif c == '\"' and not is_surrounded_sq:\n            is_surrounded_dq = not is_surrounded_dq\n        is_assignation = (\n            c == \"=\"\n            and not is_surrounded_sq\n            and not is_surrounded_dq\n            and parenthesis_depth(line[:index]) == 0\n        )\n        if is_assignation:\n            break\n    return 1 if is_assignation else 0\n\n\ndef line_length(line: str) -> int:\n    return len(line.expandtabs(4))\n\n\ndef indent_level(line: str) -> int:\n    # An exceptional rule for function declaration\n    # https://github.com/42School/norminette/blob/921b5e22d991591f385e1920f7e7ee5dcf71f3d5/norminette/rules/check_assignation_indent.py#L61\n    align_pattern = r\"^(static\\s+)?{type}\\s+{name}\\((.|\\n)*?\\);$\"\n    align_pattern = align_pattern.format(type=helper.REGEX_TYPE, name=helper.REGEX_NAME)\n    if re.match(align_pattern, line):\n        last_tab_index = line.rfind(\"\\t\")\n        if last_tab_index == -1:\n            return 0\n        return line_length(line[: last_tab_index + 1]) // 4\n    return line.count(\"\\t\")\n"
  },
  {
    "path": "c_formatter_42/formatters/misc.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    misc.py                                            :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: charles <me@cacharle.xyz>                  +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2021/02/07 14:39:26 by charles           #+#    #+#              #\n#    Updated: 2021/02/07 21:16:03 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport re\n\n\ndef parenthesize_return(content: str) -> str:\n    return re.sub(\n        r\"return\\s+(?!;)(?!\\(.*\\);)(?P<value>\\(?.*?)\\s*;\",\n        lambda match: f\"return ({match.group('value').strip()});\",\n        content,\n        re.DOTALL,\n    )\n\n\ndef space_before_semi_colon(content: str) -> str:\n    return re.sub(\n        r\"(?P<keyword>return|break|continue);\",\n        lambda match: match.group(\"keyword\") + \" ;\",\n        content,\n    )\n\n\ndef remove_multiline_condition_space(content: str) -> str:\n    return re.sub(\n        r\"(?P<tabs>\\t+) {1,3}(?P<rest>.*)\",\n        lambda match: f\"{match.group('tabs')}\\t{match.group('rest')}\",\n        content,\n    )\n\n\ndef insert_void(content: str) -> str:\n    return re.sub(\n        r\"(?P<funcdef>[0-9a-zA-Z_]+\\t+\\**[0-9a-zA-Z_]*\\s*)\\(\\s*\\)\",\n        lambda match: f\"{match.group('funcdef')}(void)\",\n        content,\n    )\n"
  },
  {
    "path": "c_formatter_42/formatters/preprocessor_directive.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    preprocessor_directive.py                          :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: charles <me@cacharle.xyz>                  +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2021/02/07 15:40:37 by charles           #+#    #+#              #\n#    Updated: 2021/02/07 16:21:25 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport re\n\n\ndef preprocessor_directive(content: str) -> str:\n    lines = content.split(\"\\n\")\n    directive_regex = r\"^\\#\\s*(?P<name>[a-z]+)\\s?(?P<rest>.*)$\"\n    directive_lines = [re.match(directive_regex, line) for line in lines]\n    idented = [\n        (i, match.group(\"name\"), match.group(\"rest\"))\n        for i, match in enumerate(directive_lines)\n        if match is not None\n    ]\n    indent = 0\n    for i, directive_name, directive_rest in idented:\n        if directive_name in [\"elif\", \"else\", \"endif\"]:\n            indent -= 1\n        lines[i] = \"#\" + (\" \" * indent) + directive_name + \" \" + directive_rest\n        lines[i] = lines[i].strip()\n        if directive_name in [\"if\", \"ifdef\", \"ifndef\", \"elif\", \"else\", \"endif\"]:\n            indent += 1\n        if directive_name == \"endif\":\n            indent -= 1\n\n    # If newline doesn't follows preprocessor part, insert one (See PR#44)\n    try:\n        lastline_index = idented[-1][0]\n        if lines[lastline_index + 1] != \"\":\n            lines.insert(lastline_index + 1, \"\")\n    except IndexError:\n        pass\n    return \"\\n\".join(lines)\n"
  },
  {
    "path": "c_formatter_42/formatters/return_type_single_tab.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    return_type_single_tab.py                          :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: charles <me@cacharle.xyz>                  +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2022/01/09 10:28:30 by charles           #+#    #+#              #\n#    Updated: 2022/01/09 10:28:30 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\n\nimport re\n\nfrom c_formatter_42.formatters import helper\n\n\ndef return_type_single_tab(content: str) -> str:\n    lines = content.split(\"\\n\")\n    aligned = []\n    align_regex = r\"^(?P<prefix>{type})\\s+\" r\"(?P<suffix>{name}\\(.*\\)?[^;])$\"\n    align_regex = align_regex.format(\n        type=helper.REGEX_TYPE, name=helper.REGEX_NAME, decl=helper.REGEX_DECL_NAME\n    )\n    matches = [re.match(align_regex, line) for line in lines]\n    aligned = [\n        (i, match.group(\"prefix\"), match.group(\"suffix\"))\n        for i, match in enumerate(matches)\n        if match is not None\n        and match.group(\"prefix\") not in [\"struct\", \"union\", \"enum\"]\n    ]\n    for i, prefix, suffix in aligned:\n        lines[i] = f\"{prefix}\\t{suffix}\"\n    return \"\\n\".join(lines)\n"
  },
  {
    "path": "c_formatter_42/run.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    run.py                                             :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/09 18:15:09 by cacharle          #+#    #+#              #\n#    Updated: 2021/02/11 20:12:15 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nfrom c_formatter_42.formatters.align import align\nfrom c_formatter_42.formatters.clang_format import clang_format\nfrom c_formatter_42.formatters.hoist import hoist\nfrom c_formatter_42.formatters.line_breaker import line_breaker\nfrom c_formatter_42.formatters.misc import (\n    insert_void,\n    parenthesize_return,\n    remove_multiline_condition_space,\n    space_before_semi_colon,\n)\nfrom c_formatter_42.formatters.preprocessor_directive import preprocessor_directive\nfrom c_formatter_42.formatters.return_type_single_tab import return_type_single_tab\n\n\ndef run_all(content: str) -> str:\n    \"\"\"Run all formatters\"\"\"\n    content = clang_format(content)\n    content = preprocessor_directive(content)\n    content = remove_multiline_condition_space(content)\n    content = parenthesize_return(content)\n    content = space_before_semi_colon(content)\n    content = hoist(content)\n    content = align(content)\n    content = return_type_single_tab(content)\n    content = insert_void(content)\n    content = line_breaker(content)\n    return content\n"
  },
  {
    "path": "docs/Makefile",
    "content": "# Minimal makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line, and also\n# from the environment for the first two.\nSPHINXOPTS    ?=\nSPHINXBUILD   ?= sphinx-build\nSOURCEDIR     = source\nBUILDDIR      = build\n\n# Put it first so that \"make\" without argument is like \"make help\".\nhelp:\n\t@$(SPHINXBUILD) -M help \"$(SOURCEDIR)\" \"$(BUILDDIR)\" $(SPHINXOPTS) $(O)\n\n.PHONY: help Makefile\n\n# Catch-all target: route all unknown targets to Sphinx using the new\n# \"make mode\" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).\n%: Makefile\n\t@$(SPHINXBUILD) -M $@ \"$(SOURCEDIR)\" \"$(BUILDDIR)\" $(SPHINXOPTS) $(O)\n"
  },
  {
    "path": "docs/make.bat",
    "content": "@ECHO OFF\r\n\r\npushd %~dp0\r\n\r\nREM Command file for Sphinx documentation\r\n\r\nif \"%SPHINXBUILD%\" == \"\" (\r\n\tset SPHINXBUILD=sphinx-build\r\n)\r\nset SOURCEDIR=source\r\nset BUILDDIR=build\r\n\r\nif \"%1\" == \"\" goto help\r\n\r\n%SPHINXBUILD% >NUL 2>NUL\r\nif errorlevel 9009 (\r\n\techo.\r\n\techo.The 'sphinx-build' command was not found. Make sure you have Sphinx\r\n\techo.installed, then set the SPHINXBUILD environment variable to point\r\n\techo.to the full path of the 'sphinx-build' executable. Alternatively you\r\n\techo.may add the Sphinx directory to PATH.\r\n\techo.\r\n\techo.If you don't have Sphinx installed, grab it from\r\n\techo.http://sphinx-doc.org/\r\n\texit /b 1\r\n)\r\n\r\n%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%\r\ngoto end\r\n\r\n:help\r\n%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%\r\n\r\n:end\r\npopd\r\n"
  },
  {
    "path": "docs/source/conf.py",
    "content": "# Configuration file for the Sphinx documentation builder.\n#\n# This file only contains a selection of the most common options. For a full\n# list see the documentation:\n# https://www.sphinx-doc.org/en/master/usage/configuration.html\n\n# -- Path setup --------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#\n# import os\n# import sys\n# sys.path.insert(0, os.path.abspath('.'))\n\n\n# -- Project information -----------------------------------------------------\n\nproject = \"c_formatter_42\"\ncopyright = \"2021, dawnbeen\"\nauthor = \"dawnbeen\"\n\n# The full version, including alpha/beta/rc tags\nrelease = \"1.0\"\n\n\n# -- General configuration ---------------------------------------------------\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = []\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#\n# This is also used if you do content translation via gettext catalogs.\n# Usually you set \"language\" from the command line for these cases.\nlanguage = \"python\"\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path.\nexclude_patterns = []\n\n\n# -- Options for HTML output -------------------------------------------------\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for\n# a list of builtin themes.\n#\nhtml_theme = \"alabaster\"\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = [\"_static\"]\n"
  },
  {
    "path": "docs/source/index.rst",
    "content": ".. c_formatter_42 documentation master file, created by\n   sphinx-quickstart on Sat Feb 27 19:28:53 2021.\n   You can adapt this file completely to your liking, but it should at least\n   contain the root `toctree` directive.\n\nWelcome to c_formatter_42's documentation!\n==========================================\n\n.. toctree::\n   :maxdepth: 2\n   :caption: Contents:\n\n\n\nIndices and tables\n==================\n\n* :ref:`genindex`\n* :ref:`modindex`\n* :ref:`search`\n"
  },
  {
    "path": "requirements-dev.txt",
    "content": "pytest\npytest-clarity\npytest-cov\npytest-timeout\npytest-cov\npytest-timeout\nsix\npytest-clarity\nmypy\nmypy-extensions\nflake8\nflake8-comprehensions\ntox\nblack\nisort\n"
  },
  {
    "path": "setup.cfg",
    "content": "[bumpversion]\ncurrent_version = 0.2.8\ntag = true\ncommit = true\n\n[bumpversion:file:setup.cfg]\n\n[bumpversion:file:c_formatter_42/__init__.py]\nparse = __version__ = (?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)\n\n[metadata]\nname = c_formatter_42\nversion = 0.2.8\ndescription = formatting tool complient with 42 school's norm\nlong_description = file: README.md\nlong_description_content_type = text/markdown\nurl = https://github.com/dawnbeen/c_formatter_42\nproject_urls =\n\tTracker = https://github.com/dawnbeen/c_formatter_42/issues\nclassifiers =\n\tProgramming Language :: Python :: 3.7\n\tProgramming Language :: Python :: 3.8\n\tProgramming Language :: Python :: 3.9\n\tProgramming Language :: Python :: 3.10\n\tProgramming Language :: Python :: 3.11\n\tProgramming Language :: Python :: 3.12\n\tProgramming Language :: C\n\tIntended Audience :: Developers\n\tEnvironment :: Console\n\tOperating System :: Microsoft :: Windows\n\tOperating System :: MacOS\n\tOperating System :: POSIX :: Linux\n\n[options]\npackages = find:\npython_requires = >=3.7\n\n[options.package_data]\n* =\n\tdata/*\n\tdata/.*\n\n[options.exclude_package_data]\nc_formatter_42 = test_*\n\n[options.entry_points]\nconsole_scripts =\n\tc_formatter_42 = c_formatter_42.__main__:main\n\n[flake8]\nignore = E221,W503,E241\nselect = E,F,W,C4,N\nmax-line-length = 100\n\n[mypy]\ncheck_untyped_defs = true\ndisallow_incomplete_defs = true\n\n[tool:pytest]\ntestpaths = tests\naddopts = --cov=c_formatter_42 --cov-report=term-missing\n\n[coverage:run]\nsource = c_formatter_42\n\n[coverage:report]\nexclude_lines =\n\tpragma: no cover\n\tsys.platform\n\tNotImplementedError\n\n[tool:isort]\nprofile = black\n"
  },
  {
    "path": "setup.py",
    "content": "# -*- coding: utf-8 -*-\nimport os\nimport sys\n\nimport setuptools\n\nsys.path.insert(0, os.path.join(os.path.dirname(__file__), \"c_formatter_42\"))  # noqa\n\nsetuptools.setup()\n"
  },
  {
    "path": "tests/formatters/test_align.py",
    "content": "# **************************************************************************** #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_align.py                                      :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: leo <leo@student.42.fr>                    +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 12:19:45 by cacharle          #+#    #+#              #\n#    Updated: 2023/09/23 11:06:39 by leo              ###   ########.fr        #\n#                                                                              #\n# **************************************************************************** #\n\nimport pytest\n\nfrom c_formatter_42.formatters.align import align, align_local, align_scope\n\n\ndef test_align_global_basic():\n    output = \"\"\"\\\nint\\t\\tfoo();\nchar\\tbar();\n\"\"\"\n    assert output == align_scope(\n        \"\"\"\\\nint foo();\nchar   bar();\n\"\"\",\n        scope=\"global\",\n    )\n    assert output == align_scope(\n        \"\"\"\\\nint\\t\\t\\t\\t\\t\\tfoo();\nchar   bar();\n\"\"\",\n        scope=\"global\",\n    )\n    assert output == align_scope(\n        \"\"\"\\\nint\\t\\t\\t         \\t\\t\\tfoo();\nchar  \\t bar();\n\"\"\",\n        scope=\"global\",\n    )\n    assert output == align_scope(\n        \"\"\"\\\nint\\t\\t\\t         \\t\\t\\tfoo();\nchar  \\t bar();\n\"\"\",\n        scope=\"global\",\n    )\n\n\ndef test_align_local_basic():\n    output = \"\"\"\nint foo()\n{\n\\tint\\t\\tfoo;\n\\tchar\\tbar;\n}\n\"\"\"\n\n    assert output == align_local(\n        \"\"\"\nint foo()\n{\n\\tint foo;\n\\tchar   bar;\n}\n\"\"\"\n    )\n    assert output == align_local(\n        \"\"\"\nint foo()\n{\n\\tint\\t\\t\\t\\t\\t\\tfoo;\n\\tchar   bar;\n}\n\"\"\"\n    )\n    assert output == align_local(\n        \"\"\"\nint foo()\n{\n\\tint\\t\\t\\t         \\t\\t\\tfoo;\n\\tchar  \\t bar;\n}\n\"\"\"\n    )\n    assert output == align_local(\n        \"\"\"\nint foo()\n{\n\\tint\\t\\t\\t         \\t\\t\\tfoo;\n\\tchar  \\t bar;\n}\n\"\"\"\n    )\n\n\ndef test_align_global_prototypes_basic():\n    input = \"\"\"\nint                      a();\nint   b();\nint \\t\\t\\t\\tc();\nint\\t\\t\\t\\t d();\nint   e();\nint \\t\\t\\t\\t\\t\\tf();\nint \\t\\tg();\nchar    a();\nchar          b();\nchar    c();\nchar d();\nchar\\t\\t\\t\\te();\nchar\\tf();\nchar\\t\\t\\t\\t\\t\\t\\tg();\nuint64_t\\t\\t\\t\\t\\ta();\nuint64_t  b();\nuint64_t c();\nuint64_t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\td();\nuint64_t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\te();\nuint64_t                  f();\nuint64_t\\tg();\n\"\"\"\n    output = \"\"\"\nint\\t\\t\\ta();\nint\\t\\t\\tb();\nint\\t\\t\\tc();\nint\\t\\t\\td();\nint\\t\\t\\te();\nint\\t\\t\\tf();\nint\\t\\t\\tg();\nchar\\t\\ta();\nchar\\t\\tb();\nchar\\t\\tc();\nchar\\t\\td();\nchar\\t\\te();\nchar\\t\\tf();\nchar\\t\\tg();\nuint64_t\\ta();\nuint64_t\\tb();\nuint64_t\\tc();\nuint64_t\\td();\nuint64_t\\te();\nuint64_t\\tf();\nuint64_t\\tg();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_local_multiple_functions():\n    input = \"\"\"\nint\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tf()\n{\n\\tint a = 0;\n}\nint\\t\\t\\t              g()\n{\n\\tint a;\n\\tint    b;\n\\tint           a;\n\\tint                a;\n\\tchar   a;\n}\nchar\\t\\t\\t\\t\\t\\t\\t\\t\\ta()\n{\n\\tint                                                        a;\n\\tint    b;\n\\tint           a;\n\\tint                a;\n\\tchar   a;\n\\tuint64_t              a;\n}\nchar\\t\\t\\t\\tf()\n{\n\\tt_very_looooooooooooooooooooooooooooooooooooooooooooooong yo;\n\\tint i;\n}\nchar g()\n{\n}\nuint64_t   a()\n{\n}\nuint64_t\\t\\t\\tb()\n{\n}\n\"\"\"\n    output = \"\"\"\nint\\t\\t\\tf()\n{\n\\tint\\ta = 0;\n}\nint\\t\\t\\tg()\n{\n\\tint\\t\\ta;\n\\tint\\t\\tb;\n\\tint\\t\\ta;\n\\tint\\t\\ta;\n\\tchar\\ta;\n}\nchar\\t\\ta()\n{\n\\tint\\t\\t\\ta;\n\\tint\\t\\t\\tb;\n\\tint\\t\\t\\ta;\n\\tint\\t\\t\\ta;\n\\tchar\\t\\ta;\n\\tuint64_t\\ta;\n}\nchar\\t\\tf()\n{\n\\tt_very_looooooooooooooooooooooooooooooooooooooooooooooong\\tyo;\n\\tint\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\ti;\n}\nchar\\t\\tg()\n{\n}\nuint64_t\\ta()\n{\n}\nuint64_t\\tb()\n{\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_prototypes_type_spaces():\n    input = \"\"\"\nunsigned foo();\nunsigned int foo();\nlong foo();\nlong long foo();\nlong long int foo();\nstatic long long int foo();\nstatic short short int foo();\nstatic short int foo();\n\"\"\"\n    output = \"\"\"\nunsigned\\t\\t\\t\\tfoo();\nunsigned int\\t\\t\\tfoo();\nlong\\t\\t\\t\\t\\tfoo();\nlong long\\t\\t\\t\\tfoo();\nlong long int\\t\\t\\tfoo();\nstatic long long int\\tfoo();\nstatic short short int\\tfoo();\nstatic short int\\t\\tfoo();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_local_type_spaces():\n    input = \"\"\"\nint qq()\n{\n\\tunsigned foo;\n\\tunsigned int foo;\n\\tlong foo;\n\\tlong long foo;\n\\tlong long int foo;\n\\tstatic long long int foo;\n\\tstatic short short int foo;\n\\tstatic short int foo;\n\\tregister long long int foo;\n\\tvolatile short short int foo;\n}\n\"\"\"\n    output = \"\"\"\nint\\tqq()\n{\n\\tunsigned\\t\\t\\t\\t\\tfoo;\n\\tunsigned int\\t\\t\\t\\tfoo;\n\\tlong\\t\\t\\t\\t\\t\\tfoo;\n\\tlong long\\t\\t\\t\\t\\tfoo;\n\\tlong long int\\t\\t\\t\\tfoo;\n\\tstatic long long int\\t\\tfoo;\n\\tstatic short short int\\t\\tfoo;\n\\tstatic short int\\t\\t\\tfoo;\n\\tregister long long int\\t\\tfoo;\n\\tvolatile short short int\\tfoo;\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_local_type_array():\n    input = \"\"\"\nint qq()\n{\n\\tunsigned foo[2];\n\\tunsigned int foo[2][2];\n\\tlong foo[BUFFER_SIZE];\n\\tlong long foo[A][B][C];\n\\tlong long int foo[A][B][C];\n\\tstatic long long int foo[A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B];\n\\tstatic short short int foo[1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1];\n\\tregister long long int foo[10000000000000000000000000000000000000000];\n\\tvolatile short short int foo[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA];\n\\tvolatile short short int foo[TEST + 1];\n\\tvolatile short short int foo[TEST - 1];\n\\tvolatile short short int foo[TEST * 1];\n\\tvolatile short short int foo[TEST / 1];\n\\tvolatile short short int foo[TEST == 0 ? 1 : 0];\n}\n\"\"\"\n    output = \"\"\"\nint\\tqq()\n{\n\\tunsigned\\t\\t\\t\\t\\tfoo[2];\n\\tunsigned int\\t\\t\\t\\tfoo[2][2];\n\\tlong\\t\\t\\t\\t\\t\\tfoo[BUFFER_SIZE];\n\\tlong long\\t\\t\\t\\t\\tfoo[A][B][C];\n\\tlong long int\\t\\t\\t\\tfoo[A][B][C];\n\\tstatic long long int\\t\\tfoo[A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B][C][A][B];\n\\tstatic short short int\\t\\tfoo[1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1][2][3][1];\n\\tregister long long int\\t\\tfoo[10000000000000000000000000000000000000000];\n\\tvolatile short short int\\tfoo[AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA];\n\\tvolatile short short int\\tfoo[TEST + 1];\n\\tvolatile short short int\\tfoo[TEST - 1];\n\\tvolatile short short int\\tfoo[TEST * 1];\n\\tvolatile short short int\\tfoo[TEST / 1];\n\\tvolatile short short int\\tfoo[TEST == 0 ? 1 : 0];\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_ptr_type():\n    input = \"\"\"\nint *ptr()\n{\n\\tint *a;\n\\tint ******a;\n\\tint *****************a;\n\\tchar *****************a;\n}\nint ***********ptr();\nchar ***********ptr(char ********************a);\nuint64_t ***********ptr(char ********************a);\n\"\"\"\n    output = \"\"\"\nint\\t\\t\\t*ptr()\n{\n\\tint\\t\\t*a;\n\\tint\\t\\t******a;\n\\tint\\t\\t*****************a;\n\\tchar\\t*****************a;\n}\nint\\t\\t\\t***********ptr();\nchar\\t\\t***********ptr(char ********************a);\nuint64_t\\t***********ptr(char ********************a);\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_function_ptr():\n    input = \"\"\"\nint qa()\n{\n\\tint *(*func)(int a, int b);\n\\tint (*func2)(int, int);\n\\tvoid (*func2)(int, int);\n\\tunsigned long long int (*func2)();\n\\tunsigned long long int (*func2)(void*);\n\\tunsigned long long int (*func2)(void**********);\n}\n\"\"\"\n    output = \"\"\"\nint\\tqa()\n{\n\\tint\\t\\t\\t\\t\\t\\t*(*func)(int a, int b);\n\\tint\\t\\t\\t\\t\\t\\t(*func2)(int, int);\n\\tvoid\\t\\t\\t\\t\\t(*func2)(int, int);\n\\tunsigned long long int\\t(*func2)();\n\\tunsigned long long int\\t(*func2)(void*);\n\\tunsigned long long int\\t(*func2)(void**********);\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_function_ptr_array():\n    input = \"\"\"\nint qa()\n{\n\\tint *(*func[2])(int a, int b);\n\\tint (*func2[A])(int, int);\n\\tvoid (*func2[11111111111110000000000000000000])(int, int);\n\\tunsigned long long int (*func2[aaaaaaaaaaaaaaaaaaaaaaaaaa])();\n}\n\"\"\"\n    output = \"\"\"\nint\\tqa()\n{\n\\tint\\t\\t\\t\\t\\t\\t*(*func[2])(int a, int b);\n\\tint\\t\\t\\t\\t\\t\\t(*func2[A])(int, int);\n\\tvoid\\t\\t\\t\\t\\t(*func2[11111111111110000000000000000000])(int, int);\n\\tunsigned long long int\\t(*func2[aaaaaaaaaaaaaaaaaaaaaaaaaa])();\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_global_variable():\n    input = \"\"\"\nint g_a = 1;\nchar f();\n\"\"\"\n    output = \"\"\"\nint\\t\\tg_a = 1;\nchar\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_number_label():\n    input = \"\"\"\nuint64_t foo64()\n{\n\\tuint64_t foo64;\n\\tc5 foo65;\n}\n\"\"\"\n    output = \"\"\"\nuint64_t\\tfoo64()\n{\n\\tuint64_t\\tfoo64;\n\\tc5\\t\\t\\tfoo65;\n}\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_underscore():\n    input = \"\"\"\n____ ___()\n{\n\\t______ __fgffd234__;\n\\t_ ____;\n}\n\"\"\"\n    output = \"\"\"\n____\\t___()\n{\n\\t______\\t__fgffd234__;\n\\t_\\t\\t____;\n}\n\"\"\"\n    print(align(input))\n    assert output == align(input)\n\n\ndef test_align_struct():\n    input = \"\"\"\nstruct s_bonjour\n{\n\\tint a;\n\\tchar b;\n};\nint f();\n\"\"\"\n    output = \"\"\"\nstruct\\t\\ts_bonjour\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n};\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_enum():\n    input = \"\"\"\nenum e_bonjour\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n};\nint f();\n\"\"\"\n    output = \"\"\"\nenum\\te_bonjour\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n};\nint\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_union():\n    input = \"\"\"\nunion u_bonjour\n{\n\\tint a;\n\\tchar b;\n};\nint f();\n\"\"\"\n    output = \"\"\"\nunion\\t\\tu_bonjour\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n};\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_typedef():\n    input = \"\"\"\ntypedef struct s_bonjour\n{\n\\tint a;\n\\tchar b;\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef struct s_bonjour\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n}\\t\\t\\tt_bonjour;\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n    input = \"\"\"\ntypedef enum e_bonjour\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef enum e_bonjour\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n}\\tt_bonjour;\nint\\tf();\n\"\"\"\n    assert output == align(input)\n    input = \"\"\"\ntypedef union u_bonjour\n{\n\\tint a;\n\\tchar b;\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef union u_bonjour\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n}\\t\\t\\tt_bonjour;\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_typedef_anonymous():\n    input = \"\"\"\ntypedef struct\n{\n\\tint a;\n\\tchar b;\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef struct\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n}\\t\\t\\tt_bonjour;\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n    input = \"\"\"\ntypedef enum\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef enum\n{\n\\tBONJOUR_A,\n\\tBONJOUR_B,\n}\\tt_bonjour;\nint\\tf();\n\"\"\"\n    assert output == align(input)\n    input = \"\"\"\ntypedef union\n{\n\\tint a;\n\\tchar b;\n} t_bonjour;\nint f();\n\"\"\"\n    output = \"\"\"\ntypedef union\n{\n\\tint\\t\\ta;\n\\tchar\\tb;\n}\\t\\t\\tt_bonjour;\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\n@pytest.mark.skip()\ndef test_align_nested_typedecl():\n    input = \"\"\"\nstruct s_bonjour\n{\n\\tint a;\n\\tchar b;\n\\tunion\n\\t{\n\\t\\tint a;\n\\t\\tchar b;\n\\t} u;\n};\nint f();\n\"\"\"\n    output = \"\"\"\nstruct\\t\\t\\ts_bonjour\n{\n\\tint\\t\\t\\ta;\n\\tchar\\t\\tb;\n\\tunion\n\\t{\n\\t\\tint\\t\\ta;\n\\t\\tchar\\tb;\n\\t}\\t\\t\\tu;\n};\nint\\t\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_struct_field_array():\n    input = \"\"\"\nstruct s_bonjour\n{\n\\tint a[1];\n\\tchar b[0][1][2][ASDF + 1];\n};\nint f();\n\"\"\"\n    output = \"\"\"\nstruct\\t\\ts_bonjour\n{\n\\tint\\t\\ta[1];\n\\tchar\\tb[0][1][2][ASDF + 1];\n};\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_struct_field_func_ptr():\n    input = \"\"\"\nstruct s_bonjour\n{\n\\tint *(*a[1])(int);\n\\tchar (*b[0][1][2][ASDF])(int a, char buf[2048], t_type);\n};\nint f();\n\"\"\"\n    output = \"\"\"\nstruct\\t\\ts_bonjour\n{\n\\tint\\t\\t*(*a[1])(int);\n\\tchar\\t(*b[0][1][2][ASDF])(int a, char buf[2048], t_type);\n};\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_struct_field_array_func_ptr():\n    input = \"\"\"\nstruct s_bonjour\n{\n\\tint *(*a[1])(int);\n\\tchar (*b[0][1][2][ASDF])(int a, char buf[2048], t_type);\n};\nint f();\n\"\"\"\n    output = \"\"\"\nstruct\\t\\ts_bonjour\n{\n\\tint\\t\\t*(*a[1])(int);\n\\tchar\\t(*b[0][1][2][ASDF])(int a, char buf[2048], t_type);\n};\nint\\t\\t\\tf();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_struct_singleton():\n    input = \"\"\"\nstruct s_bonjour;\nint f();\nchar f2();\n\"\"\"\n    output = \"\"\"\nstruct s_bonjour;\nint\\t\\tf();\nchar\\tf2();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_union_singleton():\n    input = \"\"\"\nunion s_bonjour;\nint f();\nchar f2();\n\"\"\"\n    output = \"\"\"\nunion s_bonjour;\nint\\t\\tf();\nchar\\tf2();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_enum_singleton():\n    input = \"\"\"\nenum s_bonjour;\nint f();\nchar f2();\n\"\"\"\n    output = \"\"\"\nenum s_bonjour;\nint\\t\\tf();\nchar\\tf2();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_multiline_func_decl():\n    input = \"\"\"\nt_parsed *parse_pipeline(t_tok_lst *input)\nstatic t_parsed *st_parse_op_build(\n\\t\\t\\tt_parsed *left, t_parsed *right, enum e_tok sep_tag)\n\"\"\"\n    output = \"\"\"\nt_parsed\\t\\t*parse_pipeline(t_tok_lst *input)\nstatic t_parsed\\t*st_parse_op_build(\n\\t\\t\\tt_parsed *left, t_parsed *right, enum e_tok sep_tag)\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_global_array():\n    input = \"\"\"\nstatic char *g_sep_str_lookup[] = {};\nstatic t_parsed *st_parse_op_build(t_parsed *left)\n\"\"\"\n    output = \"\"\"\nstatic char\\t\\t*g_sep_str_lookup[] = {};\nstatic t_parsed\\t*st_parse_op_build(t_parsed *left)\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_func_typedef():\n    input = \"\"\"\ntypedef void *(*t_routine)(void *arg);\n\nunsigned long long int foo();\nint bar();\n\"\"\"\n    output = \"\"\"\ntypedef void\\t\\t\\t*(*t_routine)(void *arg);\n\nunsigned long long int\\tfoo();\nint\\t\\t\\t\\t\\t\\tbar();\n\"\"\"\n    assert output == align(input)\n\n\ndef test_align_array_initialization():\n    input = \"\"\"\nint\\ta;\nstatic int\\txs[4] = {1, 2, 3, 4};\n\"\"\"\n    output = \"\"\"\nint\\t\\t\\ta;\nstatic int\\txs[4] = {1, 2, 3, 4};\n\"\"\"\n    assert output == align(input)\n"
  },
  {
    "path": "tests/formatters/test_clang_format.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_clang_format.py                               :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/05 07:37:20 by cacharle          #+#    #+#              #\n#    Updated: 2021/02/25 19:10:23 by cacharle         ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport os\nimport tempfile\nfrom contextlib import contextmanager\nfrom pathlib import Path\n\nimport pytest\n\nfrom c_formatter_42.formatters.clang_format import clang_format\n\n\ndef test_clang_format_missing_closing_delimiter():\n    assert clang_format(\"int main() {\") == \"int main()\\n{\"\n    assert clang_format(\"int main() { int fd[2; }\") == \"int main()\\n{ int fd[2;\\n}\"\n\n\ndef test_clang_format_gibberish():\n    assert (\n        clang_format(\"qwasfjkahskluhiouhcjkvzhxcklhvklxzhv\")\n        == \"qwasfjkahskluhiouhcjkvzhxcklhvklxzhv\"\n    )\n    assert (\n        clang_format(\"qwa()sfahskl{}[]uhcjkvzhxcklhv[]xzhv\")\n        == \"qwa() sfahskl{}[] uhcjkvzhxcklhv[] xzhv\"\n    )\n\n\ndef test_clang_format_empty():\n    assert clang_format(\"\") == \"\"\n\n\n# def test_clang_format_dont_join_lines():\n#     input = \"\"\"\n# if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n# \\t|| bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n# \\t|| cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)\n# \"\"\"\n#     output = \"\"\"\n# if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n# \\tbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||\n# \\tcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)\n# \"\"\"\n#     assert clang_format(input) == output\n#\n#     input = \"\"\"\n# if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n# \\tbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||\n# \\tcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)\n# \"\"\"\n#     assert clang_format(input) == input\n#\n\n\ndef test_clang_format_non_array_assignment_packing():\n    input = \"\"\"\nstatic char *g_sep_str_lookup[] = {\n\\t[TAG_END] = \";\",\n\\t[TAG_OR] = \"||\",\n\\t[TAG_REDIR_IN] = \"<\",\n\\t[TAG_REDIR_APPEND] = \">>\",\n\\t[TAG_PARENT_CLOSE] = \")\",\n\\t[TAG_AND] = \"&&\",\n\\t[TAG_PIPE] = \"|\",\n\\t[TAG_REDIR_OUT] = \">\",\n\\t[TAG_PARENT_OPEN] = \"(\",\n};\n\"\"\"\n    assert clang_format(input) == input\n\n\n@contextmanager\ndef change_temp_dir_context():\n    tempdir = tempfile.mkdtemp(\"c_formatter_42\")\n    current = Path.cwd()\n    os.chdir(tempdir)\n    yield\n    os.chdir(current)\n\n\n@pytest.fixture\ndef clang_format_config_path():\n    return Path(\".clang-format\")\n\n\ndef test_clang_format_config_file_no_existing_config(\n    tmp_path, clang_format_config_path\n):\n    os.chdir(tmp_path)\n    assert not clang_format_config_path.exists()\n    assert clang_format(\"int main() { return 0; }\") == \"int main()\\n{\\n\\treturn 0;\\n}\"\n    assert not clang_format_config_path.exists()\n\n\ndef test_clang_format_config_file_existing_config(tmp_path, clang_format_config_path):\n    os.chdir(tmp_path)\n    clang_format_config_path.write_text(\"bonjour\")\n    assert clang_format(\"int main() { return 0; }\") == \"int main()\\n{\\n\\treturn 0;\\n}\"\n    assert clang_format_config_path.exists()\n    assert clang_format_config_path.read_text() == \"bonjour\"\n"
  },
  {
    "path": "tests/formatters/test_hoist.py",
    "content": "# **************************************************************************** #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_hoist.py                                      :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: leo <leo@student.42.fr>                    +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/04 12:29:07 by cacharle          #+#    #+#              #\n#    Updated: 2023/09/23 10:55:14 by leo              ###   ########.fr        #\n#                                                                              #\n# **************************************************************************** #\n\nimport pytest\n\nfrom c_formatter_42.formatters.hoist import hoist\n\n\ndef scoped(s):\n    return \"int foo()\\n{\\n\" + s + \"\\n}\\n\"\n\n\ndef test_assignment_splitting():\n    output = scoped(\"\\tint\\ta;\\n\\n\\ta = 1;\")\n    assert output == hoist(scoped(\"\\tint a = 1;\"))\n    assert output == hoist(scoped(\"\\tint a                = 1;\"))\n    assert output == hoist(scoped(\"\\tint a =                1;\"))\n    assert output == hoist(scoped(\"\\tint a\\t\\t\\t\\t\\t\\t\\t\\t= 1;\"))\n    assert output == hoist(scoped(\"\\tint a =\\t\\t\\t\\t\\t\\t\\t\\t1;\"))\n    assert output == hoist(scoped(\"\\tint a\\t\\t    \\t\\t\\t\\t= 1;\"))\n    assert output == hoist(scoped(\"\\tint a =\\t\\t\\t    \\t\\t\\t1;\"))\n\n\ndef test_hoist():\n    output = scoped(\"int a;\\n\\nfoo();\\nbar();\")\n    assert output == hoist(scoped(\"foo();\\nbar();\\nint a;\"))\n    assert output == hoist(scoped(\"foo();\\nint a;\\nbar();\"))\n\n\ndef test_remove_empty_line():\n    input = \"\"\"\nint foo()\n{\n\\tint\\ta;\n\n\\ta = 1;\n\n\\tputs(\"bonjour\");\n\n}\n\"\"\"\n    output = \"\"\"\nint foo()\n{\n\\tint\\ta;\n\n\\ta = 1;\n\\tputs(\"bonjour\");\n}\n\"\"\"\n    assert output == hoist(input)\n\n    input = \"\"\"\nint foo()\n{\n\n\\tputs(\"bonjour\");\n\n}\n\"\"\"\n    output = \"\"\"\nint foo()\n{\n\\tputs(\"bonjour\");\n}\n\"\"\"\n    assert output == hoist(input)\n\n    input = \"\"\"\nint foo()\n{\n\\tint a = 1;\n\n\\tputs(\"bonjour\");\n\n}\n\"\"\"\n    output = \"\"\"\nint foo()\n{\n\\tint\\ta;\n\n\\ta = 1;\n\\tputs(\"bonjour\");\n}\n\"\"\"\n    assert output == hoist(input)\n\n\ndef test_hoist_pointer():\n    input = \"\"\"\nint foo()\n{\n\\tint *a = 1;\n}\n\"\"\"\n    output = \"\"\"\nint foo()\n{\n\\tint\\t*a;\n\n\\ta = 1;\n}\n\"\"\"\n    assert output == hoist(input)\n\n\ndef test_hoist_ex():\n    output = \"\"\"\\\nvoid\t*foo()\n{\n\tif ()\n\t\treturn NULL;\n}\n\"\"\"\n    assert output == hoist(\n        \"\"\"\\\nvoid\t*foo()\n{\n\tif ()\n\t\treturn NULL;\n}\n\"\"\"\n    )\n\n    # TODO test on weird types\n    output = \"\"\"\\\nvoid foo()\n{\n\\tt_list\\t*bar;\n\n\\tbar = (t_list *)malloc(sizeof(t_list) * (count_elements(baz) + 1));\n}\n\"\"\"\n    assert output == hoist(\n        \"\"\"\\\nvoid foo()\n{\n\\tt_list\\t*bar = (t_list *)malloc(sizeof(t_list) * (count_elements(baz) + 1));\n}\n\"\"\"\n    )\n\n\ndef test_hoist_empty_function():\n    input = \"\"\"\nvoid empty_function(void)\n{\n}\n\nint **function()\n{\n\\tint **tab = malloc(4 * sizeof(int *));\n\\tint i = -1;\n\\twhile (++i < 4)\n\\t{\n\\t\\ttab[i] = malloc(4 * sizeof(int));\n\\t\\tint j = -1;\n\\t\\twhile (++j < 4)\n\\t\\t\\ttab[i][j] = i * j;\n\\t}\n\\treturn (tab);\n}\n\"\"\"\n    output = \"\"\"\nvoid empty_function(void)\n{\n}\n\nint **function()\n{\n\\tint\\t**tab;\n\\tint\\ti;\n\\tint\\tj;\n\n\\ttab = malloc(4 * sizeof(int *));\n\\ti = -1;\n\\twhile (++i < 4)\n\\t{\n\\t\\ttab[i] = malloc(4 * sizeof(int));\n\\t\\tj = -1;\n\\t\\twhile (++j < 4)\n\\t\\t\\ttab[i][j] = i * j;\n\\t}\n\\treturn (tab);\n}\n\"\"\"\n    assert output == hoist(input)\n\n\ndef test_hoist_initializations():\n    input = \"\"\"\nvoid foo(void)\n{\n\\tint a = 2;\n\\tstatic int\\txs[4] = {1, 2, 3, 4};\n\\tconst int\\tb = 2;\n\\tlong int\\tc = 2;\n}\n\"\"\"\n    output = \"\"\"\nvoid foo(void)\n{\n\\tint\\ta;\n\\tstatic int\\txs[4] = {1, 2, 3, 4};\n\\tconst int\\tb = 2;\n\\tlong int\\tc;\n\n\\ta = 2;\n\\tc = 2;\n}\n\"\"\"\n    assert output == hoist(input)\n\n\n@pytest.mark.skip()\ndef test_hoist_array():\n    pass\n\n\n@pytest.mark.skip()\ndef test_hoist_func_ptr():\n    pass\n"
  },
  {
    "path": "tests/formatters/test_line_breaker.py",
    "content": "from c_formatter_42.formatters.line_breaker import (\n    additional_indent_level,\n    indent_level,\n    line_breaker,\n)\n\n\ndef test_line_indent_depth_basic_1():\n    input = \"\"\"\\\n\\t\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\"\"\"\n    assert 3 == indent_level(input)\n\n\ndef test_line_indent_depth_basic_2():\n    input = \"\"\"\\\nlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\"\"\"\n    assert 0 == indent_level(input)\n\n\ndef test_line_indent_depth_basic_3():\n    input = \"\"\"\\\n\\t\\t\\t + 2 + 2 + 2\\t\n\"\"\"\n    assert 4 == indent_level(input)\n\n\ndef test_line_indent_depth_basic_4():\n    input = \"\"\"\\\nstatic\\tint\\t\\ttest();\n\"\"\"\n    assert 4 == indent_level(input)\n\n\ndef test_line_indent_depth_basic_5():\n    input = \"\"\"\\\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr, t_tok_lst *fields);\n\"\"\"\n    assert 3 == indent_level(input)\n\n\ndef test_additional_indent_level_1():\n    input = \"\"\"\\\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr, t_tok_lst *fields);\n\"\"\"\n    assert 1 == additional_indent_level(input)\n\n\ndef test_insert_line_break_basic_1():\n    output = \"\"\"\\\n\\t\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\\t\\t\\t\\t+ 2 + 2 + 2;\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\n\\t\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_2():\n    output = \"\"\"\\\nlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_3():\n    output = \"\"\"\\\n\\t\\t\\t\\treturn (fooooooooooooooooooooooooo(a, b, cccccccccccc,\n\\t\\t\\t\\t\\t\\tddddddddddddd, eeeeeeeeeeeeeeee, fffffffffffffff,\n\\t\\t\\t\\t\\t\\tgggggggggggg, hhhhhhhhhhhhhhhhhh));\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\n\\t\\t\\t\\treturn (fooooooooooooooooooooooooo(a, b, cccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, fffffffffffffff, gggggggggggg, hhhhhhhhhhhhhhhhhh));\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_4():\n    output = \"\"\"\\\nvoid\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\\t\\t\\t+ 2 + 2 + 2;\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nvoid\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_5():\n    output = \"\"\"\\\nint\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\\t\\t\\t+ 2 + 2;\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nint\\t\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_6():\n    output = \"\"\"\\\nint\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2\n\\t\\t+ 2 + 2;\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nint\\tlooooooooooooooooooooooong = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2;\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_7():\n    output = \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhh\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhh\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_8():\n    output = \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhh\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhh\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_9():\n    output = \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n\\t+ hhhhhhhhhhhhhh\n\"\"\"\n    assert output == line_breaker(\n        \"\"\"\\\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh + hhhhhhhhhhhhhh\n\"\"\"\n    )\n\n\ndef test_insert_line_break_basic_10():\n    output = \"aaaa\\n\\t+ b\"\n    assert output == line_breaker(\"aaaa + b\", 7)\n\n\ndef test_insert_line_break_basic_11():\n    output = \"aaaa\\n\\t- b\"\n    assert output == line_breaker(\"aaaa - b\", 7)\n\n\ndef test_insert_line_break_basic_12():\n    output = \"aaaa\\n\\t* b\"\n    assert output == line_breaker(\"aaaa * b\", 7)\n\n\ndef test_insert_line_break_basic_13():\n    output = \"aaaa\\n\\t/ b\"\n    assert output == line_breaker(\"aaaa / b\", 7)\n\n\ndef test_insert_line_break_basic_14():\n    output = \"aaaa\\n\\t% b\"\n    assert output == line_breaker(\"aaaa % b\", 7)\n\n\ndef test_insert_line_break_basic_15():\n    output = \"aaaa\\n\\t+ *b\"\n    assert output == line_breaker(\"aaaa + *b\", 7)\n\n\ndef test_insert_line_break_basic_16():\n    output = \"aaaa\\n\\t+ b*\"\n    assert output == line_breaker(\"aaaa + b*\", 7)\n\n\ndef test_insert_line_break_basic_17():\n    output = \"aaaa\\n\\t* *b\"\n    assert output == line_breaker(\"aaaa * *b\", 7)\n\n\ndef test_insert_line_break_basic_18():\n    output = \"aaaa\\n\\t* b*\"\n    assert output == line_breaker(\"aaaa * b*\", 7)\n\n\ndef test_insert_line_break_basic_19():\n    output = \"aaaa*\\n\\t* b\"\n    assert output == line_breaker(\"aaaa* * b\", 7)\n\n\ndef test_insert_line_break_basic_20():\n    output = \"*aaaa\\n\\t* b\"\n    assert output == line_breaker(\"*aaaa * b\", 7)\n\n\ndef test_insert_line_break_basic_21():\n    output = \",\\n\\taaaa *b\"\n    assert output == line_breaker(\", aaaa *b\", 7)\n\n\ndef test_insert_line_break_basic_22():\n    output = \",\\n\\taaaa* b\"\n    assert output == line_breaker(\", aaaa* b\", 7)\n\n\ndef test_insert_line_break_basic_23():\n    output = \"foooooo(bar\\n\\t* baz)\"\n    assert output == line_breaker(\"foooooo(bar * baz)\", 7)\n\n\ndef test_insert_line_break_basic_24():\n    output = \"foo = foooooo(bar\\n\\t\\t* baz);\"\n    assert output == line_breaker(\"foo = foooooo(bar * baz);\", 18)\n\n\ndef test_insert_line_break_basic_25():\n    output = \"foo[i] = foooooo(bar\\n\\t\\t* baz);\"\n    assert output == line_breaker(\"foo[i] = foooooo(bar * baz);\", 21)\n\n\ndef test_insert_line_break_basic_26():\n    output = '\"EXT = TXT\" + foooooo(bar\\n\\t* baz);'\n    assert output == line_breaker('\"EXT = TXT\" + foooooo(bar * baz);', 27)\n\n\ndef test_insert_line_break_basic_27():\n    input = (\n        '((t_cast *)it->content)->name = get_name((t_cast *)it->content, \"EXT=TXT\");'\n    )\n    output = \"\"\"((t_cast *)it->content)->name = get_name((t_cast *)it->content,\n\\t\\t\\\"EXT=TXT\\\");\"\"\"\n    assert output == line_breaker(input, 64)\n\n\ndef test_insert_line_break_long_function_declaration():\n    input = \"\"\"\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr, t_tok_lst *fields);\n\"\"\"\n    output = \"\"\"\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr,\n\\t\\t\\t\\tt_tok_lst *fields);\n\"\"\"\n    assert line_breaker(input) == output\n\n\ndef test_insert_line_break_long_function_declaration_with_parens():\n    input = \"\"\"\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr, void (*del)(void *));\n\"\"\"\n    output = \"\"\"\nstatic void\\tst_merge_fields_in_curr(char *strs[3], t_tok_lst **curr,\n\\t\\t\\t\\tvoid (*del)(void *));\n\"\"\"\n    assert line_breaker(input) == output\n\n\ndef test_insert_line_break_control_statement_1():\n    input = \"\"\"\\\n\\twhile (true + false)\n\"\"\"\n    output = \"\"\"\\\n\\twhile (true\n\\t\\t+ false)\n\"\"\"\n    assert line_breaker(input, 7) == output\n\n\ndef test_insert_line_break_control_statement_2():\n    input = \"\"\"\\\n\\tif (true + false)\n\"\"\"\n    output = \"\"\"\\\n\\tif (true\n\\t\\t+ false)\n\"\"\"\n    assert line_breaker(input, 5) == output\n"
  },
  {
    "path": "tests/formatters/test_misc.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_misc.py                                       :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2020/10/05 14:53:05 by cacharle          #+#    #+#              #\n#    Updated: 2021/02/11 20:27:44 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nfrom c_formatter_42.formatters.misc import (\n    insert_void,\n    parenthesize_return,\n    remove_multiline_condition_space,\n    space_before_semi_colon,\n)\n\n\ndef test_run_space_before_semi_colon():\n    assert \"return ;\" == space_before_semi_colon(\"return ;\")\n    assert \"break ;\" == space_before_semi_colon(\"break ;\")\n    assert \"continue ;\" == space_before_semi_colon(\"continue ;\")\n\n\ndef test_run_parenthesize_return_1():\n    assert \"return (a);\" == parenthesize_return(\"return a;\")\n    assert \"return (a);\" == parenthesize_return(\"return \\n\\na;\")\n    assert \"return (a);\" == parenthesize_return(\"return a\\n\\n;\")\n    assert \"return (a);\" == parenthesize_return(\"return \\na\\n;\")\n    assert \"return (a);\" == parenthesize_return(\"return    a   ;\")\n    assert \"return (a);\" == parenthesize_return(\"return \\t\\ta\\t  ;\")\n    assert \"return (a);\" == parenthesize_return(\"return  a\\n\\t\\n ;\")\n    assert \"return (foo());\" == parenthesize_return(\"return foo();\")\n    assert \"return (foo());\" == parenthesize_return(\"return \\n\\nfoo();\")\n    assert \"return (foo());\" == parenthesize_return(\"return foo()\\n\\n;\")\n    assert \"return (foo());\" == parenthesize_return(\"return \\nfoo()\\n;\")\n    assert \"return;\" == parenthesize_return(\"return;\")\n    assert \"return ;\" == parenthesize_return(\"return ;\")\n    assert \"return ();\" == parenthesize_return(\"return ();\")\n    assert \"return (bar(a++ + ++b[34]);\" == parenthesize_return(\n        \"return bar(a++ + ++b[34];\"\n    )\n    assert \"return (func(a, b));\" == parenthesize_return(\"return func(a, b);\")\n    assert \"return ((void *)p);\" == parenthesize_return(\"return (void *)p;\")\n    assert \"\\t\\treturn (NULL);\" == parenthesize_return(\"\\t\\treturn NULL;\")\n\n\ndef test_run_parenthesize_return_2():\n    output = \"\"\"\\\nreturn ;\nreturn (NULL);\n\"\"\"\n    assert output == parenthesize_return(\n        \"\"\"\\\nreturn ;\nreturn NULL;\n\"\"\"\n    )\n\n\ndef test_run_space_in_condition():\n    input = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t   input->tag & TAG_STICK &&\n\\t   input->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    output = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t\\tinput->tag & TAG_STICK &&\n\\t\\tinput->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    assert output == remove_multiline_condition_space(input)\n\n    input = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t  input->tag & TAG_STICK &&\n\\t  input->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    output = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t\\tinput->tag & TAG_STICK &&\n\\t\\tinput->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    assert output == remove_multiline_condition_space(input)\n    input = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t input->tag & TAG_STICK &&\n\\t input->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    output = \"\"\"\nwhile (input != NULL && input->tag & TAG_IS_STR &&\n\\t\\tinput->tag & TAG_STICK &&\n\\t\\tinput->next != NULL && input->next->tag & TAG_IS_STR)\n    \"\"\"\n    assert output == remove_multiline_condition_space(input)\n\n\ndef test_insert_void():\n    assert \"int main()\" == insert_void(\"int main()\")\n    assert \"void func  ( )\" == insert_void(\"void func  ( )\")\n    assert \"int\\tmain(void)\" == insert_void(\"int\\tmain()\")\n    assert \"void\\tfunc  (void)\" == insert_void(\"void\\tfunc  ( )\")\n    assert \"void\\t\\tfunc  (void)\" == insert_void(\"void\\t\\tfunc  ( )\")\n    assert \"void\\t\\t*func  (void)\" == insert_void(\"void\\t\\t*func  ( )\")\n    assert \"\\t(void *)foo()\" == insert_void(\"\\t(void *)foo()\")\n    assert \"\\tfoo()\" == insert_void(\"\\tfoo()\")\n"
  },
  {
    "path": "tests/formatters/test_preprocessor_directive.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_preprocessor_directive.py                     :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: charles <me@cacharle.xyz>                  +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2021/02/07 15:52:25 by charles           #+#    #+#              #\n#    Updated: 2021/02/11 20:27:53 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nfrom c_formatter_42.formatters.preprocessor_directive import preprocessor_directive\n\n\ndef test_preprocessor_directive_ifdef():\n    input = \"\"\"\n#ifdef foo\n#define foo 1\n#endif\n\"\"\"\n    output = \"\"\"\n#ifdef foo\n# define foo 1\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_ifndef():\n    input = \"\"\"\n#ifndef foo\n#define foo 1\n#endif\n\"\"\"\n    output = \"\"\"\n#ifndef foo\n# define foo 1\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_if():\n    input = \"\"\"\n#if foo\n#define foo 1\n#endif\n\"\"\"\n    output = \"\"\"\n#if foo\n# define foo 1\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_if_else():\n    input = \"\"\"\n#if foo\n#define foo 1\n#else\n#define foo 2\n#endif\n\"\"\"\n    output = \"\"\"\n#if foo\n# define foo 1\n#else\n# define foo 2\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_if_elif_else():\n    input = \"\"\"\n#if foo\n#define foo 1\n#elif t1\n#define foo 2\n#elif t2\n#define foo 3\n#elif t3\n#define foo 4\n#else\n#define foo 5\n#endif\n\"\"\"\n    output = \"\"\"\n#if foo\n# define foo 1\n#elif t1\n# define foo 2\n#elif t2\n# define foo 3\n#elif t3\n# define foo 4\n#else\n# define foo 5\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_random_indent():\n    input = \"\"\"\n#                if foo\n#define foo 1\n#         elif t1\n#   define foo 2\n#     elif t2\n#  define foo 3\n#                elif t3\n#     define foo 4\n#       else\n#define foo 5\n#           endif\n\"\"\"\n    output = \"\"\"\n#if foo\n# define foo 1\n#elif t1\n# define foo 2\n#elif t2\n# define foo 3\n#elif t3\n# define foo 4\n#else\n# define foo 5\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_nested():\n    input = \"\"\"\n#if foo\n#define a 1\n#if bar\n#define b 2\n#else\n#define c 3\n#endif\n#elif baz\n#define d 4\n#elif baz\n#define e 5\n#else\n#define f 6\n#endif\n\"\"\"\n    output = \"\"\"\n#if foo\n# define a 1\n# if bar\n#  define b 2\n# else\n#  define c 3\n# endif\n#elif baz\n# define d 4\n#elif baz\n# define e 5\n#else\n# define f 6\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_directive_nested_10():\n    input = \"\"\"\n#if a\n#if b\n#if c\n#if d\n#if e\n#if f\n#if g\n#if h\n#if i\n#if j\n#define foo 1\n#endif\n#endif\n#endif\n#endif\n#endif\n#endif\n#endif\n#endif\n#endif\n#endif\n\"\"\"\n    output = \"\"\"\n#if a\n# if b\n#  if c\n#   if d\n#    if e\n#     if f\n#      if g\n#       if h\n#        if i\n#         if j\n#          define foo 1\n#         endif\n#        endif\n#       endif\n#      endif\n#     endif\n#    endif\n#   endif\n#  endif\n# endif\n#endif\n\"\"\"\n    assert output == preprocessor_directive(input)\n\n\ndef test_preprocessor_1():\n    input = \"\"\"\n#include \"libft.h\"\nvoid *ft_function(char c)\n\"\"\"\n    output = \"\"\"\n#include \"libft.h\"\n\nvoid *ft_function(char c)\n\"\"\"\n    assert output == preprocessor_directive(input)\n    assert output == preprocessor_directive(preprocessor_directive(input))\n"
  },
  {
    "path": "tests/formatters/test_return_type_single_tab.py",
    "content": "# ############################################################################ #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_return_type_single_tab.py                     :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: charles <me@cacharle.xyz>                  +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2022/01/09 10:28:30 by charles           #+#    #+#              #\n#    Updated: 2022/01/09 10:28:30 by charles          ###   ########.fr        #\n#                                                                              #\n# ############################################################################ #\n\nimport pytest\n\nfrom c_formatter_42.formatters.return_type_single_tab import return_type_single_tab\n\n\ndef test_return_type_single_tab_basic():\n    output = \"\"\"\\\nint\\tfoo()\nchar\\tbar()\n\"\"\"\n    assert output == return_type_single_tab(\n        \"\"\"\\\nint foo()\nchar   bar()\n\"\"\"\n    )\n    assert output == return_type_single_tab(\n        \"\"\"\\\nint\\t\\t\\t\\t\\t\\tfoo()\nchar   bar()\n\"\"\"\n    )\n    assert output == return_type_single_tab(\n        \"\"\"\\\nint\\t\\t\\t         \\t\\t\\tfoo()\nchar  \\t bar()\n\"\"\"\n    )\n    assert output == return_type_single_tab(\n        \"\"\"\\\nint\\t\\t\\t         \\t\\t\\tfoo()\nchar  \\t bar()\n\"\"\"\n    )\n\n\n@pytest.mark.parametrize(\n    \"content\",\n    [\n        \"\"\"\nint foo();\nchar   bar();\n        \"\"\",\n        \"\"\"\nint\\t\\t\\t\\t\\t\\tfoo();\nchar   bar();\n        \"\"\",\n        \"\"\"\nint\\t\\t\\t         \\t\\t\\tfoo();\nchar  \\t bar();\n        \"\"\",\n        \"\"\"\nint\\t\\t\\t         \\t\\t\\tfoo();\nchar  \\t bar();\n        \"\"\",\n    ],\n)\ndef test_return_type_single_tab_no_prototype(content):\n    assert content == return_type_single_tab(content)\n\n\ndef test_return_type_single_tab_no_func_typedef():\n    input = \"\"\"\ntypedef void\\t\\t\\t\\t\\t*(*t_routine)(void *arg);\n\nunsigned long long int foo();\nint foo();\n\"\"\"\n    assert input == return_type_single_tab(input)\n"
  },
  {
    "path": "tests/test_run.py",
    "content": "# **************************************************************************** #\n#                                                                              #\n#                                                         :::      ::::::::    #\n#    test_run.py                                        :+:      :+:    :+:    #\n#                                                     +:+ +:+         +:+      #\n#    By: yaassila <yaassila@student.42.fr>          +#+  +:+       +#+         #\n#                                                 +#+#+#+#+#+   +#+            #\n#    Created: 2021/02/08 19:56:48 by charles           #+#    #+#              #\n#    Updated: 2023/08/31 14:00:00 by yaassila         ###   ########.fr        #\n#                                                                              #\n# **************************************************************************** #\n\nimport pytest\n\nfrom c_formatter_42.run import run_all\n\n\n@pytest.mark.skip()\ndef test_run_align_break_column_max():\n    input = \"\"\"\ntypedef struct\\t\\t\\ts_tok_lst\n{\n\\tchar\\t\\t\\t\\t*content;\n\\tstruct s_tok_lst\\t*next;\n\\tenum e_tok\\t\\t\\ttag;\n}\\t\\t\\t\\t\\t\\tt_tok_lst;\n\nt_tok_lst\\t\\t\\t\\t*tok_lst_new(enum e_tok tag, char *content);\nt_tok_lst\\t\\t\\t\\t*tok_lst_new_until(\n\\t\\t\\t\\t\\t\\t\\tenum e_tok tag, char *content, size_t n);\nt_tok_lst\\t\\t\\t\\t*tok_lst_push_front(\n\\t\\t\\t\\t\\t\\t\\tt_tok_lst **tokens, t_tok_lst *pushed);\nt_tok_lst\\t\\t\\t\\t*tok_lst_uncons(t_tok_lst **tokens);\n\"\"\"\n    output = \"\"\"\ntypedef struct\\t\\t\\ts_tok_lst\n{\n\\tchar\\t\\t\\t\\t*content;\n\\tstruct s_tok_lst\\t*next;\n\\tenum e_tok\\t\\t\\ttag;\n}\\t\\t\\t\\t\\t\\tt_tok_lst;\n\nt_tok_lst\\t\\t\\t\\t*tok_lst_new(enum e_tok tag, char *content);\nt_tok_lst\\t\\t\\t\\t*tok_lst_new_until(enum e_tok tag,\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tchar *content,\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tsize_t n);\nt_tok_lst\\t\\t\\t\\t*tok_lst_push_front(t_tok_lst **tokens,\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tt_tok_lst *pushed);\nt_tok_lst\\t\\t\\t\\t*tok_lst_uncons(t_tok_lst **tokens);\n\"\"\"\n    assert output == run_all(input)\n\n\ndef test_run_func_decl_single_tab_and_global_aligned():\n    pass\n\n\ndef test_run_long_aligned_func_decl():\n    # This function declaration is already aligned and should not be modified\n    input = \"\"\"\ntypedef struct s_foo\n{\n\\tlong int\\tbar;\n}\\t\\t\\t\\tt_foo;\n\nlong int\\t\\tfoooooooooooooooooooooooooooooo(t_foo *foooooooo1,\n\\t\\t\\t\\t\\tt_foo *foooooooo2, int barrrrrrrr1, int barrrrrrrr2);\n\"\"\"\n    assert input == run_all(input)\n\n\ndef test_basic():\n    input = \"\"\"\nint main(int argc, char*argv[]){\n\treturn 0;\n}\n\"\"\"\n    output = \"\"\"\nint\\tmain(int argc, char *argv[])\n{\n\treturn (0);\n}\n\"\"\"\n    assert output == run_all(input)\n\n\n@pytest.mark.timeout(15)\ndef test_function_call_in_comment():\n    input = \"\"\"\n#include \"libft.h\"\n\n/*\nThe  bzero()  function  erases  the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\\\\0') to that area.\n\nThe explicit_bzero() function performs the same task as bzero().  It differs from bzero() in  that  it  guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is \"un-necessary\".\n*/\nvoid\tbzero(void *s, size_t n)\n{\n                    unsigned char *ptr_s;\n}\n\"\"\"\n    run_all(input)\n"
  },
  {
    "path": "tox.ini",
    "content": "[tox]\nenvlist = python3.8,python3.9,python3.10,python3.11,python3.12\ndistshare = {env:XDG_CACHE_HOME}/tox/distshare\n\n[testenv]\ndeps =\n    flake8\n    mypy\n    pytest\n    isort\n\ncommands_pre =\n    pip install -e .\n    pip install -r requirements-dev.txt\n\ncommands =\n    black --check c_formatter_42 tests\n    isort --check c_formatter_42 tests\n    flake8 c_formatter_42\n    mypy c_formatter_42\n    pytest -vvv\n"
  }
]