Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KWVio-0007Vy-UH for mharc-grub-devel@gnu.org; Fri, 22 Aug 2008 08:26:31 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KWVim-0007Ut-Li for grub-devel@gnu.org; Fri, 22 Aug 2008 08:26:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KWVil-0007U4-Q3 for grub-devel@gnu.org; Fri, 22 Aug 2008 08:26:28 -0400 Received: from [199.232.76.173] (port=58994 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KWVil-0007U1-NE for grub-devel@gnu.org; Fri, 22 Aug 2008 08:26:27 -0400 Received: from ti-out-0910.google.com ([209.85.142.189]:55565) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KWVic-0005RA-Mo for grub-devel@gnu.org; Fri, 22 Aug 2008 08:26:27 -0400 Received: by ti-out-0910.google.com with SMTP id u5so277140tia.10 for ; Fri, 22 Aug 2008 05:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=xuIAT9IPl3TaXSlovmWh/obqRilgl7F/sv2AJyvHPCQ=; b=K0DeL4iZojS/Opm9MMn9AmTyk2tDsWiWlaO4HlSr1JskG9saftk2ok/GNWVyP5E4cK QbYTUFNxWTMmgXD1Srj4EJ02We8/ujLiJz8Ov9uo/DP3lJLW9vZTBKfLDkIKlwxKYzoy saPINEGU9yB86intmJGrb9ykVdDSBRgBxKvyU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=WtQ/4JEyOav+ejEGjkHqsVSUrIJbH0RMharHfBfthVDK+pvTlxeyvDZhmLk4Y4WtHu 7cTrp1V7PqnnvoqrHg8i0iRoKzoSh+oVTBGYXUaYLiQLWo8HShG7tdLnhtf3Lsw9vraa sJZVdiiN9tgd/uG+fzB3z0mNjS9gqHPMhmMGw= Received: by 10.110.41.17 with SMTP id o17mr1216608tio.18.1219407964123; Fri, 22 Aug 2008 05:26:04 -0700 (PDT) Received: by 10.110.26.19 with HTTP; Fri, 22 Aug 2008 05:26:03 -0700 (PDT) Message-ID: Date: Fri, 22 Aug 2008 17:56:03 +0530 From: "Deepak Vankadaru" To: grub-devel@gnu.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_154168_7511058.1219407963919" References: X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: precision formatting in grub_printf X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Aug 2008 12:26:28 -0000 ------=_Part_154168_7511058.1219407963919 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Does this patch look okay? Or do I need to give any more information? By the way, this is my first patch submission to GNU :) Thanks Deepak On Mon, Aug 18, 2008 at 10:52 AM, Deepak Vankadaru < deepak.vankadaru@gmail.com> wrote: > Attached the same in unified diff format. > > This is listed in known bugs (http://grub.enbug.org/KnownBugs) > > > On Sun, Aug 17, 2008 at 11:28 PM, Deepak Vankadaru < > deepak.vankadaru@gmail.com> wrote: > >> Hi >> >> I have implemented precision formatting support in grub_printf. Following >> is the diff (of kern/misc.c) >> >> Thanks >> Deepak >> >> ###############start of diff >> *** kern/misc.c 2008-08-18 04:46:36.000000000 +0530 >> --- /home/deepakv/orig/grub2-1.96+20080724/kern/misc.c 2008-06-16 >> 06:12:48.000000000 +0530 >> *************** >> *** 565,572 **** >> *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; >> } >> while (n /= base); >> - if ( p == str) >> - *p++ = '0'; >> *p = 0; >> >> grub_reverse (str); >> --- 565,570 ---- >> *************** >> *** 682,693 **** >> write_char (*s++); >> } >> >> - void write_str_limit (const char *s, int count) >> - { >> - while (*s && count--) >> - write_char (*s++); >> - } >> - >> void write_fill (const char ch, int n) >> { >> int i; >> --- 680,685 ---- >> *************** >> *** 704,711 **** >> char tmp[32]; >> char *p; >> unsigned int format1 = 0; >> ! unsigned int format2 = 1; >> ! grub_bool_t format2_default = TRUE; >> char zerofill = ' '; >> int rightfill = 0; >> int n; >> --- 696,702 ---- >> char tmp[32]; >> char *p; >> unsigned int format1 = 0; >> ! unsigned int format2 = 3; >> char zerofill = ' '; >> int rightfill = 0; >> int n; >> *************** >> *** 723,737 **** >> while (*p && grub_isdigit (*p)) >> p++; >> >> ! if (p > fmt || *p == '.') >> { >> char s[p - fmt + 1]; >> grub_strncpy (s, fmt, p - fmt); >> s[p - fmt] = 0; >> if (s[0] == '0') >> zerofill = '0'; >> ! if (p - fmt) >> ! format1 = grub_strtoul (s, 0, 10); >> fmt = p; >> if (*p && *p == '.') >> { >> --- 714,727 ---- >> while (*p && grub_isdigit (*p)) >> p++; >> >> ! if (p > fmt) >> { >> char s[p - fmt + 1]; >> grub_strncpy (s, fmt, p - fmt); >> s[p - fmt] = 0; >> if (s[0] == '0') >> zerofill = '0'; >> ! format1 = grub_strtoul (s, 0, 10); >> fmt = p; >> if (*p && *p == '.') >> { >> *************** >> *** 747,755 **** >> format2 = grub_strtoul (fstr, 0, 10); >> fmt = p; >> } >> - else >> - format2 = 0; >> - format2_default = FALSE; >> } >> } >> >> --- 737,742 ---- >> *************** >> *** 790,806 **** >> n = va_arg (args, int); >> grub_itoa (tmp, c, n); >> } >> ! if ( format2 == 0 && grub_strcmp (tmp, "0") == 0) >> ! break; >> ! if ( grub_strlen (tmp) > format2) >> ! format2 = grub_strlen (tmp); >> ! if (! rightfill && format2 < format1) >> ! write_fill (zerofill, format1 - format2); >> ! if ( grub_strlen (tmp) < format2) >> ! write_fill ('0', format2 - grub_strlen (tmp)); >> write_str (tmp); >> ! if (rightfill && format2 < format1) >> ! write_fill (zerofill, format1 - format2); >> break; >> >> case 'c': >> --- 777,787 ---- >> n = va_arg (args, int); >> grub_itoa (tmp, c, n); >> } >> ! if (! rightfill && grub_strlen (tmp) < format1) >> ! write_fill (zerofill, format1 - grub_strlen (tmp)); >> write_str (tmp); >> ! if (rightfill && grub_strlen (tmp) < format1) >> ! write_fill (zerofill, format1 - grub_strlen (tmp)); >> break; >> >> case 'c': >> *************** >> *** 862,895 **** >> p = va_arg (args, char *); >> if (p) >> { >> ! if ( format2_default ) >> ! { >> ! if (!rightfill && grub_strlen (p) < format1) >> ! write_fill (' ', format1 - grub_strlen (p)); >> >> ! write_str (p); >> >> ! if (rightfill && grub_strlen (p) < format1) >> ! write_fill (' ', format1 - grub_strlen (p)); >> ! } >> ! else >> ! { >> ! if (!rightfill && format2 < format1) >> ! write_fill (' ', format1 - format2); >> ! >> ! if ( grub_strlen (p) < format2) >> ! { >> ! if ( format2 <= format1) >> ! write_fill (' ', format2 - grub_strlen (p)); >> ! else >> ! write_fill (' ', format1 - grub_strlen (p)); >> ! } >> ! >> ! write_str_limit (p, format2); >> ! >> ! if (rightfill && format2 < format1) >> ! write_fill (' ', format1 - format2); >> ! } >> } >> else >> write_str ("(null)"); >> --- 843,855 ---- >> p = va_arg (args, char *); >> if (p) >> { >> ! if (!rightfill && grub_strlen (p) < format1) >> ! write_fill (zerofill, format1 - grub_strlen (p)); >> >> ! write_str (p); >> >> ! if (rightfill && grub_strlen (p) < format1) >> ! write_fill (zerofill, format1 - grub_strlen (p)); >> } >> else >> write_str ("(null)"); >> >> ###############end of diff >> >> ######start of test case >> int main() >> { >> typedef int (*printf_ptr)(char const *str, ...); >> printf_ptr p; >> if(getenv("GRUB_PRINTF")) >> { >> printf("using grub_printf\n"); >> p = grub_printf; >> } >> else >> { >> printf("using printf\n"); >> p = printf; >> } >> p("##%4.2d##\n",1); >> p("##%4.2d##\n",12); >> p("##%4.2d##\n",123); >> p("##%4.2d##\n",1234); >> p("##%4.2d##\n",12345); >> p("##%3.3d##\n",12); >> p("##%3.3d##\n",123); >> p("##%3.3d##\n",1234); >> p("##%2.4d##\n",12345); >> p("##%2.4d##\n",1234); >> p("##%2.4d##\n",123); >> p("##%2.4d##\n",12); >> p("##%2.4d##\n",1); >> p("##%.0d##\n",0); >> p("##%.0d##\n",1); >> p("##%4.2s##\n","1"); >> p("##%4.2s##\n","12"); >> p("##%4.2s##\n","123"); >> p("##%4.2s##\n","1234"); >> p("##%4.2s##\n","12345"); >> p("##%3.3s##\n","12"); >> p("##%3.3s##\n","123"); >> p("##%3.3s##\n","1234"); >> p("##%2.4s##\n","12345"); >> p("##%2.4s##\n","1234"); >> p("##%2.4s##\n","123"); >> p("##%2.4s##\n","12"); >> p("##%2.4s##\n","1"); >> return 0; >> } >> > > ------=_Part_154168_7511058.1219407963919 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi,

Does this patch look okay? Or do I need to give any more information?

By the way, this is my first patch submission to GNU :)

Thanks
Deepak

On Mon, Aug 18, 2008 at 10:52 AM, Deepak Vankadaru <deepak.vankadaru@gmail.com> wrote:
Attached the same in unified diff format.

This is listed in known bugs (http://grub.enbug.org/KnownBugs)


On Sun, Aug 17, 2008 at 11:28 PM, Deepak Vankadaru <deepak.vankadaru@gmail.com> wrote:
Hi

I have implemented precision formatting support in grub_printf. Following is the diff (of kern/misc.c)

Thanks
Deepak

###############start of diff
*** kern/misc.c    2008-08-18 04:46:36.000000000 +0530
--- /home/deepakv/orig/grub2-1.96+20080724/kern/misc.c    2008-06-16 06:12:48.000000000 +0530
***************
*** 565,572 ****
        *p++ = (d > 9) ? d + 'a' - 10 : d + '0';
      }
    while (n /= base);
-   if ( p == str)
-     *p++ = '0';
    *p = 0;
 
    grub_reverse (str);
--- 565,570 ----
***************
*** 682,693 ****
      write_char (*s++);
      }
 
-   void write_str_limit (const char *s, int count)
-     {
-       while (*s && count--)
-     write_char (*s++);
-     }
-
    void write_fill (const char ch, int n)
      {
        int i;
--- 680,685 ----
***************
*** 704,711 ****
        char tmp[32];
        char *p;
        unsigned int format1 = 0;
!       unsigned int format2 = 1;
!       grub_bool_t format2_default = TRUE;
        char zerofill = ' ';
        int rightfill = 0;
        int n;
--- 696,702 ----
        char tmp[32];
        char *p;
        unsigned int format1 = 0;
!       unsigned int format2 = 3;
        char zerofill = ' ';
        int rightfill = 0;
        int n;
***************
*** 723,737 ****
        while (*p && grub_isdigit (*p))
          p++;
 
!       if (p > fmt || *p == '.')
          {
            char s[p - fmt + 1];
            grub_strncpy (s, fmt, p - fmt);
            s[p - fmt] = 0;
            if (s[0] == '0')
          zerofill = '0';
!           if (p - fmt)
!             format1 = grub_strtoul (s, 0, 10);
            fmt = p;
            if (*p && *p == '.')
          {
--- 714,727 ----
        while (*p && grub_isdigit (*p))
          p++;
 
!       if (p > fmt)
          {
            char s[p - fmt + 1];
            grub_strncpy (s, fmt, p - fmt);
            s[p - fmt] = 0;
            if (s[0] == '0')
          zerofill = '0';
!           format1 = grub_strtoul (s, 0, 10);
            fmt = p;
            if (*p && *p == '.')
          {
***************
*** 747,755 ****
                format2 = grub_strtoul (fstr, 0, 10);
                fmt = p;
              }
-           else
-             format2 = 0;
-           format2_default = FALSE;
          }
          }
 
--- 737,742 ----
***************
*** 790,806 ****
              n = va_arg (args, int);
            grub_itoa (tmp, c, n);
          }
!           if ( format2 == 0 && grub_strcmp (tmp, "0") == 0)
!         break;
!           if ( grub_strlen (tmp) > format2)
!             format2 = grub_strlen (tmp);
!           if (! rightfill && format2 < format1)
!         write_fill (zerofill, format1 - format2);
!           if ( grub_strlen (tmp) < format2)
!         write_fill ('0', format2 - grub_strlen (tmp));
            write_str (tmp);
!           if (rightfill && format2 < format1)
!         write_fill (zerofill, format1 - format2);
            break;
           
          case 'c':
--- 777,787 ----
              n = va_arg (args, int);
            grub_itoa (tmp, c, n);
          }
!           if (! rightfill && grub_strlen (tmp) < format1)
!         write_fill (zerofill, format1 - grub_strlen (tmp));
            write_str (tmp);
!           if (rightfill && grub_strlen (tmp) < format1)
!         write_fill (zerofill, format1 - grub_strlen (tmp));
            break;
           
          case 'c':
***************
*** 862,895 ****
            p = va_arg (args, char *);
            if (p)
          {
!           if ( format2_default )
!             {
!               if (!rightfill && grub_strlen (p) < format1)
!                 write_fill (' ', format1 - grub_strlen (p));
           
!               write_str (p);
           
!               if (rightfill && grub_strlen (p) < format1)
!                 write_fill (' ', format1 - grub_strlen (p));
!             }
!             else
!             {
!               if (!rightfill && format2 < format1)
!                 write_fill (' ', format1 - format2);
!          
!               if ( grub_strlen (p) < format2)
!                 {
!                   if ( format2 <= format1)
!                     write_fill (' ', format2 - grub_strlen (p));
!                   else
!                     write_fill (' ', format1 - grub_strlen (p));
!                 }
!
!               write_str_limit (p, format2);
!          
!               if (rightfill && format2 < format1)
!                 write_fill (' ', format1 - format2);
!             }
          }
            else
          write_str ("(null)");
--- 843,855 ----
            p = va_arg (args, char *);
            if (p)
          {
!           if (!rightfill && grub_strlen (p) < format1)
!             write_fill (zerofill, format1 - grub_strlen (p));
           
!           write_str (p);
           
!           if (rightfill && grub_strlen (p) < format1)
!             write_fill (zerofill, format1 - grub_strlen (p));
          }
            else
          write_str ("(null)");

###############end of diff

######start of test case
int main()
{
    typedef int (*printf_ptr)(char const *str, ...);
    printf_ptr p;
    if(getenv("GRUB_PRINTF"))
    {
        printf("using grub_printf\n");
        p = grub_printf;
    }
    else
    {
        printf("using printf\n");
        p = printf;
    }
    p("##%4.2d##\n",1);
    p("##%4.2d##\n",12);
    p("##%4.2d##\n",123);
    p("##%4.2d##\n",1234);
    p("##%4.2d##\n",12345);
    p("##%3.3d##\n",12);
    p("##%3.3d##\n",123);
    p("##%3.3d##\n",1234);
    p("##%2.4d##\n",12345);
    p("##%2.4d##\n",1234);
    p("##%2.4d##\n",123);
    p("##%2.4d##\n",12);
    p("##%2.4d##\n",1);
    p("##%.0d##\n",0);
    p("##%.0d##\n",1);
    p("##%4.2s##\n","1");
    p("##%4.2s##\n","12");
    p("##%4.2s##\n","123");
    p("##%4.2s##\n","1234");
    p("##%4.2s##\n","12345");
    p("##%3.3s##\n","12");
    p("##%3.3s##\n","123");
    p("##%3.3s##\n","1234");
    p("##%2.4s##\n","12345");
    p("##%2.4s##\n","1234");
    p("##%2.4s##\n","123");
    p("##%2.4s##\n","12");
    p("##%2.4s##\n","1");
    return 0;
}


------=_Part_154168_7511058.1219407963919--