]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Log field width polishing
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 13 Oct 2011 17:05:25 +0000 (20:05 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 13 Oct 2011 17:05:25 +0000 (20:05 +0300)
This patch:
 - converts type of the Token::[width|precision]  members from "unsigned int" to "int"
 - renames the Token::[width|precision] members to Token::[widthMin/widthMax]
 - removes unneeded typecastings

This is a Measurement Factory project

src/format/Format.cc
src/format/Tokens.cc
src/format/Tokens.h

index 1f5b2676c0e2614e92af607c0a4a6bb0410d3cac..62063bb9bfea927277638f20446802fe2bf48f4c 100644 (file)
@@ -219,11 +219,11 @@ Format::Format::dump(StoreEntry * entry, const char *name)
                 if (t->zero)
                     entry->append("0", 1);
 
-                if (t->width)
-                    storeAppendPrintf(entry, "%d", (int) t->width);
+                if (t->widthMin >= 0)
+                    storeAppendPrintf(entry, "%d", t->widthMin);
 
-                if (t->precision)
-                    storeAppendPrintf(entry, ".%d", (int) t->precision);
+                if (t->widthMax >= 0)
+                    storeAppendPrintf(entry, ".%d", t->widthMax);
 
                 if (arg)
                     storeAppendPrintf(entry, "{%s}", arg);
@@ -999,11 +999,11 @@ Format::Format::assemble(MemBuf &mb, AccessLogEntry *al, int logSequenceNumber)
         }
 
         if (dooff) {
-            snprintf(tmp, sizeof(tmp), "%0*" PRId64, fmt->zero ? (int) fmt->width : 0, outoff);
+            snprintf(tmp, sizeof(tmp), "%0*" PRId64, fmt->zero && fmt->widthMin >= 0 ? fmt->widthMin : 0, outoff);
             out = tmp;
 
         } else if (doint) {
-            snprintf(tmp, sizeof(tmp), "%0*ld", fmt->zero ? (int) fmt->width : 0, outint);
+            snprintf(tmp, sizeof(tmp), "%0*ld", fmt->zero && fmt->widthMin >= 0 ? fmt->widthMin : 0, outint);
             out = tmp;
         }
 
@@ -1053,12 +1053,12 @@ Format::Format::assemble(MemBuf &mb, AccessLogEntry *al, int logSequenceNumber)
             }
 
             // enforce width limits if configured
-            const bool haveMaxWidth = fmt->precision && !doint && !dooff;
-            if (haveMaxWidth || fmt->width) {
-                const int minWidth = fmt->width ?
-                                     static_cast<int>(fmt->width) : 0;
+            const bool haveMaxWidth = fmt->widthMax >=0 && !doint && !dooff;
+            if (haveMaxWidth || fmt->widthMin) {
+                const int minWidth = fmt->widthMin >= 0 ?
+                                     fmt->widthMin : 0;
                 const int maxWidth = haveMaxWidth ?
-                                     static_cast<int>(fmt->precision) : strlen(out);
+                                     fmt->widthMax : strlen(out);
 
                 if (fmt->left)
                     mb.Printf("%-*.*s", minWidth, maxWidth, out);
index 0a4f1b0aebf890ad3445e07719b4ac542e16130c..f27203e9e5358b9662ddc657e71db7764eebc5c9 100644 (file)
@@ -302,10 +302,10 @@ Format::Token::parse(char *def, Quoting *quoting)
     }
 
     if (xisdigit(*cur))
-        width = strtol(cur, &cur, 10);
+        widthMin = strtol(cur, &cur, 10);
 
-    if (*cur == '.')
-        precision = strtol(cur + 1, &cur, 10);
+    if (*cur == '.' && xisdigit(*(++cur)))
+        widthMax = strtol(cur, &cur, 10);
 
     if (*cur == '{') {
         char *cp;
@@ -479,11 +479,11 @@ done:
     case LFT_TIME_SUBSECOND:
         divisor = 1000;
 
-        if (precision) {
+        if (widthMax > 0) {
             int i;
             divisor = 1000000;
 
-            for (i = precision; i > 1; i--)
+            for (i = widthMax; i > 1; i--)
                 divisor /= 10;
 
             if (!divisor)
index fefe2e059cf808d8215fdb71dcca6f30e711707b..507badffe41ab7fddf31b79fa4317aef06a66296 100644 (file)
@@ -186,8 +186,8 @@ class Token
 public:
     Token() : type(LFT_NONE),
             label(NULL),
-            width(0),
-            precision(0),
+            widthMin(-1),
+            widthMax(-1),
             quote(LOG_QUOTE_NONE),
             left(0),
             space(0),
@@ -215,8 +215,8 @@ public:
         } header;
         char *timespec;
     } data;
-    unsigned int width;
-    unsigned int precision;
+    int widthMin; ///< minimum field width
+    int widthMax; ///< maximum field width
     enum Quoting quote;
     unsigned int left:1;
     unsigned int space:1;