From: Jacob Lifshay Date: Thu, 28 Jul 2022 08:47:29 +0000 (-0700) Subject: add handy re-indenting script X-Git-Tag: sv_maxu_works-initial~207 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=355fad2b3a63bec30e43e8034062027aba3b9799;p=openpower-isa.git add handy re-indenting script --- diff --git a/reindent.py b/reindent.py new file mode 100755 index 00000000..85a426ad --- /dev/null +++ b/reindent.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +""" handy script for re-indenting text to be in multiples of ` `""" +import sys + +indent_unit = " " + + +def ind_print(v): + print(indent_unit * (len(indent_stack) - 1) + v) + + +with open(sys.argv[1]) as f: + indent_stack = [""] + for line in f: + line = line.rstrip().expandtabs() + indent = line[:-len(line.lstrip())] + unindented = line[len(indent):] + if unindented == '': + print() + continue + while len(indent_stack[-1]) > len(indent): + indent_stack.pop() + assert len(indent_stack[-1]) >= len(indent), \ + "popped intermediate indentation" + if len(indent_stack[-1]) < len(indent): + indent_stack.append(indent) + ind_print(unindented)