Revision: 57310
          http://sourceforge.net/p/brlcad/code/57310
Author:   brlcad
Date:     2013-08-30 07:37:39 +0000 (Fri, 30 Aug 2013)
Log Message:
-----------
address the additional test cases that were not being handled where the %s 
format specifier had precision and/or field lengths specified for left/right 
padded alignment.  the code was written to account for the padding, but it 
wasn't actually being called because the lengths weren't captured.  we don't 
want to capture them in the earlier loop because it screws up assumptions for 
some of the other specifier cases.  this fixes sf bug #347 reported by lee 
butler (bu_log does not honor string field widths).

Modified Paths:
--------------
    brlcad/trunk/src/libbu/vls_vprintf.c

Modified: brlcad/trunk/src/libbu/vls_vprintf.c
===================================================================
--- brlcad/trunk/src/libbu/vls_vprintf.c        2013-08-30 06:54:15 UTC (rev 
57309)
+++ brlcad/trunk/src/libbu/vls_vprintf.c        2013-08-30 07:37:39 UTC (rev 
57310)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <assert.h>
+#include <math.h>
 
 #ifdef HAVE_STDINT_H
 #   include <stdint.h>
@@ -64,8 +65,6 @@
 
 /* private functions */
 
-/* decls */
-static void reset_vflags(vflags_t *f);
 
 /* defs */
 static void
@@ -341,8 +340,8 @@
     return status;
 }
 
+
 /*
-
 The bu_vls_vprintf function aims to adhere to the following
 specifications:
 
@@ -376,7 +375,6 @@
       "unknown" part to one of the categories described in [4].
 
 */
-
 void
 bu_vls_vprintf(struct bu_vls *vls, const char *fmt, va_list ap)
 {
@@ -425,17 +423,14 @@
            if (c == ' '
                || c == '#'
                || c == '+'
-               || c == '.'
                || c == '\''
-               || isdigit(c)) {
-               /* need to set flags for some of these */
-               if (c == '.') {
-                   f.have_dot = 1;
-               } else if (isdigit(c)) {
-                   /* set flag for later error checks */
-                   f.have_digit = 1;
-               }
-               continue;
+               )
+           {
+               /* skip */
+           } else if (c == '.') {
+               f.have_dot = 1;
+           } else if (isdigit(c)) {
+               /* skip */
            } else if (c == '-') {
                /* the first occurrence before a dot is the
                 left-justify flag, but the occurrence AFTER a dot is
@@ -459,8 +454,7 @@
                if (!f.have_dot) {
                    f.fieldlen = va_arg(ap, int);
                    f.flags |= FIELDLEN;
-               }
-               else {
+               } else {
                    f.precision = va_arg(ap, int);
                    f.flags |= PRECISION;
                }
@@ -492,6 +486,8 @@
        bu_vls_strncpy(&fbuf, sp, (size_t)len);
        fbufp = bu_vls_addr(&fbuf);
 
+       /*!!!*/ fprintf(stderr, "FBUF[%s]\n", fbufp);
+
 #ifndef HAVE_C99_FORMAT_SPECIFIERS
        /* if the format string uses the %z or %t width specifier, we need to
         * replace it with something more palatable to this busted compiler.
@@ -548,16 +544,54 @@
                    int maxstrlen = -1;
 
                    char *str = va_arg(ap, char *);
+                   const char *fp = fbufp;
 
+                   f.left_justify = 0;
+                   f.have_dot = 0;
+                   while (*fp) {
+                       if (isdigit(*fp)) {
+
+                           if (!f.have_dot) {
+                               if (*fp == '0') {
+                                   bu_sscanf(fp, "%o", &f.fieldlen);
+                               } else {
+                                   f.fieldlen = atoi(fp);
+                               }
+                               f.flags |= FIELDLEN;
+                           } else {
+                               if (*fp == '0') {
+                                   bu_sscanf(fp, "%o", &f.precision);
+                               } else {
+                                   f.precision = atoi(fp);
+                               }
+                               f.flags |= PRECISION;
+                           }
+
+                           while (isdigit(*(fp+1)))
+                               fp++;
+
+                           if (*fp == '\0') {
+                               break;
+                           }
+                       } else if (*fp == '.') {
+                           f.have_dot = 1;
+                       } else if (*fp == '-') {
+                           f.left_justify = 1;
+                       }
+                       fp++;
+                   }
+
                    /* for strings only */
                    /* field length is a minimum size and precision is
-                      max length of string to be printed */
+                    * max length of string to be printed.
+                    */
                    if (f.flags & FIELDLEN) {
                        minfldwid = f.fieldlen;
                    }
                    if (f.flags & PRECISION) {
                        maxstrlen = f.precision;
                    }
+
                    if (str) {
                        int stringlen = (int)strlen(str);
                        struct bu_vls tmpstr = BU_VLS_INIT_ZERO;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to