From 796b3ef2d579d3364ae91e53ee4ad641bf21454e Mon Sep 17 00:00:00 2001
From: Alexey Matveichev <github@matveichev.com>
Date: Sun, 13 Nov 2016 16:17:35 +0100
Subject: [PATCH] Colon alignment

Align colon in silent rules according to WM_SILENT_LEFT_COLUMN_WIDTH
environment variable or use default value of 10.

1. rightAlign function in wmkdep.
2. RIGHT_ALIGN function in transform.
3. printf for alignment in wmakeLnInclude.
---
 wmake/rules/General/transform |  6 +++++-
 wmake/src/wmkdep.l            | 41 +++++++++++++++++++++++++++++++++++++++--
 wmake/wmakeLnInclude          | 10 ++++++++--
 3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/wmake/rules/General/transform b/wmake/rules/General/transform
index 427cc25..fa4f3a5 100644
--- a/wmake/rules/General/transform
+++ b/wmake/rules/General/transform
@@ -1,9 +1,13 @@
 #-------------------------------*- makefile -*---------------------------------
 
+WM_SILENT_LEFT_COLUMNT_DEFAULT_WIDTH := 10
+
+RIGHT_ALIGN = $(shell printf "%*s" $(if $(WM_SILENT_LEFT_COLUMN_WIDTH),$(WM_SILENT_LEFT_COLUMN_WIDTH),$(WM_SILENT_LEFT_COLUMNT_DEFAULT_WIDTH)) $(1))
+
 ifneq ("$(WM_QUIET)","")
     E=@
     define QUIET_MESSAGE
-        @echo "    $1: $2";
+        @echo "$(call RIGHT_ALIGN,$1): $2";
     endef
     QUIET_OP=-s
 else
diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l
index 81bede8..78e83c5 100644
--- a/wmake/src/wmkdep.l
+++ b/wmake/src/wmkdep.l
@@ -41,6 +41,7 @@ Usage
 
 #define FILE_STACK_SIZE 300
 #define HASH_TABLE_SIZE 500
+#define DEFAULT_LEFT_COLUMN_WIDTH 10
 
 #include <stdlib.h>
 #include <string.h>
@@ -52,6 +53,7 @@ Usage
 void nextFile(const char* fileName);
 void importFile(const char* fileName);
 void importDir(const char* dirName);
+char* rightAlign(const char* str);
 
 #undef yywrap        /* sometimes a macro by default */
 
@@ -145,7 +147,7 @@ const char* bufferPaths[FILE_STACK_SIZE];
 
 int main(int argc, char* argv[])
 {
-    char *basePos, *dotPos;
+    char *basePos, *dotPos, *leftColumn = NULL;
     int i, silent;
 
     if (argc == 1)
@@ -158,7 +160,10 @@ int main(int argc, char* argv[])
     silent = (strncmp(argv[1], "-s", 2) == 0);
     if (silent)
     {
-        fprintf(stderr, "    wmkdep: %s\n", basename(sourceFile));
+        leftColumn = rightAlign("wmkdep");
+        fprintf(stderr, "%s: %s\n", leftColumn, basename(sourceFile));
+        if (leftColumn != NULL)
+            free(leftColumn);
     }
     else
     {
@@ -270,6 +275,38 @@ int main(int argc, char* argv[])
 
 
 /*
+ * Write right-aligned str to dst
+ */
+char* rightAlign(const char* str)
+{
+    char *dst;
+    int columnWidth = DEFAULT_LEFT_COLUMN_WIDTH;
+    int len = strlen(str);
+    int didx, sidx;
+    char *lcw = getenv("WM_SILENT_LEFT_COLUMN_WIDTH");
+    if (lcw != NULL)
+    {
+        columnWidth = atoi(lcw);
+    }
+    if (len > columnWidth)
+    {
+        columnWidth = strlen(str);
+    }
+    dst = (char*) calloc(columnWidth, sizeof(char));
+    memset(dst, 32, columnWidth - 1);
+    didx = columnWidth - 1;
+    sidx = len - 1;
+    while (sidx >= 0)
+    {
+        dst[didx] = str[sidx];
+        didx--;
+        sidx--;
+    }
+    return dst;
+}
+
+
+/*
  * Add a directory name to the file name
  */
 char* addDirectoryName(const char* dirName, const char* fileName)
diff --git a/wmake/wmakeLnInclude b/wmake/wmakeLnInclude
index 3db3802..fd06a14 100755
--- a/wmake/wmakeLnInclude
+++ b/wmake/wmakeLnInclude
@@ -40,6 +40,8 @@
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
+WM_SILENT_LEFT_COLUMN_DEFAULT_WIDTH=10
+
 usage() {
     exec 1>&2
     while [ "$#" -ge 1 ]; do echo "$1"; shift; done
@@ -140,7 +142,11 @@ cd $incDir || exit 1
 
 if [ "$silentOpt" = true -o -n "$WM_QUIET" ]
 then
-    echo "    ln: $incDir" 1>&2
+    lnStr=$(printf "%*s" $WM_SILENT_LEFT_COLUMN_DEFAULT_WIDTH "ln")
+    [ -n "$WM_SILENT_LEFT_COLUMN_WIDTH" ] && {
+    lnStr=$(printf "%*s" $WM_SILENT_LEFT_COLUMN_WIDTH "ln")
+    }
+    echo "${lnStr}: $incDir" 1>&2
 else
     echo "$Script: linking include files to $incDir" 1>&2
 fi
@@ -172,7 +178,7 @@ find .. $findOpt \
 # Cleanup local variables and functions
 #------------------------------------------------------------------------------
 
-unset Script usage
+unset Script usage WM_SILENT_LEFT_COLUMN_DEFAULT_WIDTH
 
 
 #------------------------------------------------------------------------------
-- 
2.7.4

