From patchwork Wed Mar 25 18:06:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 454642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 66D8A14012C for ; Thu, 26 Mar 2015 05:06:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932793AbbCYSGY (ORCPT ); Wed, 25 Mar 2015 14:06:24 -0400 Received: from avon.wwwdotorg.org ([70.85.31.133]:38116 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932159AbbCYSGX (ORCPT ); Wed, 25 Mar 2015 14:06:23 -0400 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 179126352; Wed, 25 Mar 2015 12:06:23 -0600 (MDT) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id 27E6EE4647; Wed, 25 Mar 2015 12:06:22 -0600 (MDT) From: Stephen Warren To: swarren@wwwdotorg.org Cc: linux-tegra@vger.kernel.org, Stephen Warren Subject: [pinmux scripts PATCH 2/5] Fix some TAB alignment issues Date: Wed, 25 Mar 2015 12:06:14 -0600 Message-Id: <1427306777-17669-2-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427306777-17669-1-git-send-email-swarren@wwwdotorg.org> References: <1427306777-17669-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.98.6 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Stephen Warren 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 --- board-to-uboot.py | 2 +- soc-to-kernel-pinctrl-driver.py | 4 ++-- tegra_pmx_utils.py | 26 ++++++++++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/board-to-uboot.py b/board-to-uboot.py index f337b6371955..8c5f11f076f7 100755 --- a/board-to-uboot.py +++ b/board-to-uboot.py @@ -117,7 +117,7 @@ if board.soc.soc_pins_have_ior: .ioreset = PMUX_PIN_IO_RESET_DEFAULT, ''' -s = append_aligned_tabs_indent_with_tabs(s) +s = append_aligned_tabs_indent_with_tabs(s, 0) print(s) print('''\ diff --git a/soc-to-kernel-pinctrl-driver.py b/soc-to-kernel-pinctrl-driver.py index f7743e0d4097..46547b194d33 100755 --- a/soc-to-kernel-pinctrl-driver.py +++ b/soc-to-kernel-pinctrl-driver.py @@ -302,7 +302,7 @@ else: .drv_reg = -1, ''' -s = append_aligned_tabs_indent_with_tabs(s) +s = append_aligned_tabs_indent_with_tabs(s, 72) print(s) print('''\ @@ -372,7 +372,7 @@ s += '''\ .drvtype_bit = %(drvtype_bit_val)s ''' % globals() -s = append_aligned_tabs_indent_with_tabs(s) +s = append_aligned_tabs_indent_with_tabs(s, 72) print(s) print('''\ diff --git a/tegra_pmx_utils.py b/tegra_pmx_utils.py index ece3c1606dc0..2551282963a9 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):