]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_scan.c
Increment VERSION on the head to 1.7+dev.
[nmh] / sbr / fmt_scan.c
index 9b84861..c8cdece 100644 (file)
@@ -47,7 +47,6 @@ match (char *str, char *sub)
     int c1, c2;
     char *s1, *s2;
 
-#ifdef LOCALE
     while ((c1 = *sub)) {
        c1 = (isascii((unsigned char) c1) && isalpha((unsigned char) c1) &&
              isupper((unsigned char) c1)) ? tolower((unsigned char) c1) : c1;
@@ -71,19 +70,6 @@ match (char *str, char *sub)
        if (! c1)
            return 1;
     }
-#else
-    while ((c1 = *sub)) {
-       while ((c2 = *str++) && (c1 | 040) != (c2 | 040))
-           ;
-       if (! c2)
-           return 0;
-       s1 = sub + 1; s2 = str;
-       while ((c1 = *s1++) && (c1 | 040) == (*s2++ | 040))
-           ;
-       if (! c1)
-           return 1;
-    }
-#endif
     return 1;
 }
 
@@ -504,6 +490,41 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat,
                    cp += n;
            }
            break;
+       case FT_LS_UNITS:
+           {
+               char *unitcp;
+               unsigned int whole, tenths;
+
+               if (value < 1000) {
+                   snprintf(buffer, sizeof(buffer), "%u", value);
+               } else {
+
+                   /* find correct scale for size (Kilo/Mega/Giga/Tera) */
+                   for (unitcp = "KMGT"; value > 999999; value /= 1000) {
+                       if (!*++unitcp)
+                           break;
+                   }
+
+                   if (!*unitcp) {
+                       strcpy(buffer, "huge");
+                   } else {
+                       /* round up to next higer tenth of kilo-/mega-/giga- */
+                       value += 99; value /= 100;
+
+                       /* want one digit after decimal, avoid float */
+                       whole = value / 10;
+                       tenths = value - (whole * 10);
+
+                       if (tenths) {
+                           snprintf(buffer, sizeof(buffer), "%u.%u%c", whole, tenths, *unitcp);
+                       } else {
+                           snprintf(buffer, sizeof(buffer), "%u%c", whole, *unitcp);
+                       }
+                   }
+               }
+               str = buffer;
+           }
+           break;
        case FT_NUMF:
            cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp);
            break;