Skip to content
Snippets Groups Projects
Select Git revision
  • b57d3b923cdbe9a01f5f01147fa5d08aa2fee3c0
  • master default
  • test
  • rahix/hw-lock-new-mutex
  • dx/somewhat-more-dynamic-config
  • schneider/sdk-0.2.1-7
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

gen-qstr.sh

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    fix-multi-decl.py 1.33 KiB
    #!/usr/bin/env python3
    #
    # I prefer to have the closing brace of a multi-line declaration or function call on its
    # own line.  This is unfortunately not yet supported by clang-format.  This script is
    # a hack to manually introduce my style.
    #
    # Tracking for this style in clang-format: https://reviews.llvm.org/D33029
    #
    # Example
    # =======
    # This is the style I want:
    #
    #     printf(
    #         "Hello %s %d\n",
    #         "World",
    #         123
    #     );
    import re
    import sys
    
    EXPR = r"""                         # Indentation is saved to <ws>
    ^(?P<ws>[ \t]*)(?P<decl>.*\(\n      # Opening line, ending with (\n
        (?:.*,\n)*                      # Lines with arguments, all ending with ,\n
        .*)\)(?P<final>[); \t]*)\n      # Last line with closing brace & optional following characters
    (?![ \t]*\).*)                      # Don't match an already expanded decl
    """
    
    
    def main():
        with open(sys.argv[1], "r") as f:
            source = f.read()
    
        fixed = re.sub(
            EXPR,
            r"\g<ws>\g<decl>\n\g<ws>)\g<final>\n",
            source,
            flags=re.MULTILINE | re.VERBOSE,
        )
    
        # Fix function definitions that can now be pulled into one line
        fixed = re.sub(
            r"^\)\n{$",
            r") {",
            fixed,
            flags=re.MULTILINE,
        )
    
        with open(sys.argv[1], "w") as f:
            f.write(fixed)
    
    
    if __name__ == "__main__":
        main()