summaryrefslogtreecommitdiff
path: root/tegra_pmx_utils.py
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2015-03-25 11:51:56 -0600
committerStephen Warren <swarren@nvidia.com>2015-03-25 12:02:51 -0600
commitf69acc27558b8104cf17baa0799cb4447d6d6df8 (patch)
tree6bfb32175c6ef8a0092ee6426ac26aa2816dacd6 /tegra_pmx_utils.py
parent64444eff656e0efc3a5cbce1bd853a79727e4d16 (diff)
downloadtegra-pinmux-scripts-f69acc27558b8104cf17baa0799cb4447d6d6df8.tar.gz
Fix some TAB alignment issues
append_aligned_tabs_indent_with_tabs() was converting TABs to spaces to simplify calculation of line length, assuming the only TABs were at the beginning of the line, and hence were all exactly 8 characters wide. In some scenarios, TABs were also embedded within the line, which caused incorrect calculations. Solve this by explicitly evaluating TAB widths character by character, rather than taking shortcuts. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'tegra_pmx_utils.py')
-rw-r--r--tegra_pmx_utils.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/tegra_pmx_utils.py b/tegra_pmx_utils.py
index ece3c16..2551282 100644
--- a/tegra_pmx_utils.py
+++ b/tegra_pmx_utils.py
@@ -74,21 +74,31 @@ def gen_wrapped_c_macro_header(macro, params):
s += '\n'
return s
-def append_aligned_tabs_indent_with_tabs(s):
+def len_evaluating_tabs(s):
+ l = 0
+ for c in s:
+ if c == '\t':
+ l = (l + 8) & ~7
+ else:
+ l += 1
+ return l
+
+def append_aligned_tabs_indent_with_tabs(s, min_slashpos):
lines = s.split('\n')
if lines[-1].strip() == '':
del lines[-1]
+ # This is intended to translate leading spaces to TABs, so that callers
+ # don't have to work out the right number of TABs to use. It also would
+ # affect intra-line space, but there is none in practice so far.
for i, l in enumerate(lines):
- lines[i] = l.replace('\t', ' ')
+ lines[i] = l.replace(' ', '\t')
max_len = 0
for l in lines:
- max_len = max(max_len, len(l))
- tabpos = (max_len + 7) // 8
+ max_len = max(max_len, len_evaluating_tabs(l))
+ max_len = max(max_len, min_slashpos)
+ tabpos = (max_len + 7) & ~7
for i, l in enumerate(lines):
- remaining = 72 - len(l)
- lines[i] += gen_tab_padding_to(len(l) + 1, 73) + '\\'
- for i, l in enumerate(lines):
- lines[i] = l.replace(' ', '\t')
+ lines[i] += gen_tab_padding_to(len_evaluating_tabs(l) + 1, tabpos + 1) + '\\'
return '\n'.join(lines)
def yn_to_boolean(s):