From ec7ff5ba272b565ed093a98dc13dd5cd26aeac92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 12 Feb 2012 15:16:20 +0100 Subject: make lineno_width() from blame reusable for others MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit builtin/blame.c has a helper function to compute how many columns we need to show a line-number, whose implementation is reusable as a more generic helper function to count the number of columns necessary to show any cardinal number. Rename it to decimal_width(), move it to pager.c and export it for use by future callers. Signed-off-by: Zbigniew Jędrzejewski-Szmek Signed-off-by: Junio C Hamano --- pager.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pager.c') diff --git a/pager.c b/pager.c index 975955ba8..96c07babb 100644 --- a/pager.c +++ b/pager.c @@ -110,3 +110,15 @@ int pager_in_use(void) env = getenv("GIT_PAGER_IN_USE"); return env ? git_config_bool("GIT_PAGER_IN_USE", env) : 0; } + +/* + * How many columns do we need to show this number in decimal? + */ +int decimal_width(int number) +{ + int i, width; + + for (width = 1, i = 10; i <= number; width++) + i *= 10; + return width; +} -- cgit v1.2.1