precision formatting in grub_printf
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;
}Quoted 4 lines · Deepak Vankadaru
Hi
I have implemented precision formatting support in
grub_printf. Following is the diff (ofkern/misc.c)
Thanks!
Could you please send this in unified diff format? ('diff -u', or just 'svn diff')
Also, are there any places in the code where this could be used, or where you intend to use it? We are careful when adding new code in the kernel, because of size constraints.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Attached the same in unified diff format.
This is listed in known bugs (http://grub.enbug.org/KnownBugs)
Quoted 221 lines · Deepak Vankadaru
Hi
I have implemented precision formatting support in
grub_printf. Following is the diff (ofkern/misc.c)Thanks
Deepak###############start of diff
***kern/misc.c2008-08-18 04:46:36.000000000 +0530
---/home/deepakv/orig/grub2-1.96+20080724/kern/misc.c2008-06-16
06:12:48.000000000 +0530
***************
*** 565,572 *****p++ = (d > 9) ? d + 'a' - 10 : d + '0'; } while (n /= base);(quoted diff) +0
-3- if ( p == str) - *p++ = '0'; *p = 0; grub_reverse (str); --- 565,570 ----***************
*** 682,693 ****write_char (*s++); }(quoted diff) +0
-7- 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; }(quoted diff) +0
-4- 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
intmain(){ 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");
Quoted 9 lines
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;
}misc.c renamed from home/deepakv/orig/grub2-1.96+20080724/kern/misc.c +52 -12
@@ -565,6 +565,8 @@ *p++ = (d >9 ) ? d +'a' -10 : d +'0' ; }while (n /= base); +if ( p == str) + *p++ ='0' ; *p =0 ;grub_reverse (str);
@@ -680,6 +682,12 @@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;
@@ -696,7 +704,8 @@char tmp[32 ];char *p;unsigned int format1 =0 ; -unsigned int format2 =3 ; +unsigned int format2 =1 ; +grub_bool_t format2_default = TRUE;char zerofill =' ' ;int rightfill =0 ;int n;
@@ -714,14 +723,15 @@while (*p &&grub_isdigit (*p)) p++; -if (p > fmt) +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' ; - format1 =grub_strtoul (s,0 ,10 ); +if (p - fmt) + format1 =grub_strtoul (s,0 ,10 ); fmt = p;if (*p && *p =='.' ) {
@@ -737,6 +747,9 @@ format2 =grub_strtoul (fstr,0 ,10 ); fmt = p; } +else + format2 =0 ; + format2_default = FALSE; } }
@@ -777,11 +790,17 @@ n =va_arg (args, int);grub_itoa (tmp, c, n); } -if (! rightfill &&grub_strlen (tmp) < format1) -write_fill (zerofill, format1 -grub_strlen (tmp)); +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 &&grub_strlen (tmp) < format1) -write_fill (zerofill, format1 -grub_strlen (tmp)); +if (rightfill && format2 < format1) +write_fill (zerofill, format1 - format2);break ;case 'c' :
@@ -843,13 +862,34 @@ p = va_arg (args, char *);if (p) { -if (!rightfill &&grub_strlen (p) < format1) -write_fill (zerofill, format1 -grub_strlen (p)); +if ( format2_default ) + { +if (!rightfill &&grub_strlen (p) < format1) +write_fill (' ' , format1 -grub_strlen (p)); -write_str (p); +write_str (p); -if (rightfill &&grub_strlen (p) < format1) -write_fill (zerofill, format1 -grub_strlen (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)" );
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
Quoted 240 lines · Deepak Vankadaru
Attached the same in unified diff format.
This is listed in known bugs (http://grub.enbug.org/KnownBugs)
Quoted 230 lines · Deepak Vankadaru
Hi
I have implemented precision formatting support in
grub_printf. Following is the diff (ofkern/misc.c)Thanks
Deepak###############start of diff
***kern/misc.c2008-08-18 04:46:36.000000000 +0530
---/home/deepakv/orig/grub2-1.96+20080724/kern/misc.c2008-06-16
06:12:48.000000000 +0530
***************
*** 565,572 *****p++ = (d > 9) ? d + 'a' - 10 : d + '0'; } while (n /= base);misc.c renamed from home/deepakv/orig/grub2-1.96+20080724/kern/misc.c +0
-3-if ( p == str) - *p++ ='0' ; *p =0 ;grub_reverse (str); ---565 ,570 ----***************
*** 682,693 ****write_char (*s++); }(quoted diff) +0
-7- 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; }(quoted diff) +0
-4- 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
intmain(){ 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; }
Hi
I have completed the copyright assignment procedure. Just a reminder.
Thanks
Deepak
Quoted 254 lines · Deepak Vankadaru
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
DeepakQuoted 240 lines · Deepak Vankadaru
Attached the same in unified diff format.
This is listed in known bugs (http://grub.enbug.org/KnownBugs)
Quoted 230 lines · Deepak Vankadaru
Hi
I have implemented precision formatting support in
grub_printf. Following is the diff (ofkern/misc.c)Thanks
Deepak###############start of diff
***kern/misc.c2008-08-18 04:46:36.000000000 +0530
---/home/deepakv/orig/grub2-1.96+20080724/kern/misc.c2008-06-16
06:12:48.000000000 +0530
***************
*** 565,572 *****p++ = (d > 9) ? d + 'a' - 10 : d + '0'; } while (n /= base);misc.c renamed from home/deepakv/orig/grub2-1.96+20080724/kern/misc.c +0
-3-if ( p == str) - *p++ ='0' ; *p =0 ;grub_reverse (str); ---565 ,570 ----***************
*** 682,693 ****write_char (*s++); }(quoted diff) +0
-7- 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; }(quoted diff) +0
-4- 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
intmain(){ 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; }
Quoted 3 lines · Deepak Vankadaru
Hi
I have completed the copyright assignment procedure. Just a reminder.
Hi Deepak,
Thanks for the reminder. Could you please include a ChangeLog entry?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Hi,
There was a redundant piece of code in the diff file I sent earlier. I have removed it and prepared another patch file. I am attaching the same. Please use this one instead.
Following is the changelog.
Changelog:
2008-08-17 Deepak Vankadaru <[email protected]>
Support for precision formatting in grub_printf
* kern/misc.c: modified grub_vsprintf to parse and handle precision
formatting
Thanks
Deepak
Quoted 17 lines · Robert Millan
Quoted 3 lines · Deepak Vankadaru
Hi
I have completed the copyright assignment procedure. Just a reminder.
Hi Deepak,
Thanks for the reminder. Could you please include a ChangeLog entry?
--
Robert MillanThe DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 5 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
*** kern/misc.c.org 2009-03-16 04:14:32.466999000 -0700
--- kern/misc.c 2009-03-16 04:36:57.679110000 -0700
***************
*** 691,696 ****
--- 691,702 ----
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;***************
*** 707,713 ****
char tmp[32];
char *p;
unsigned int format1 = 0;
! unsigned int format2 = 3;
char zerofill = ' ';
int rightfill = 0;
int n;
--- 713,720 ----
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;
***************
*** 725,738 ****
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 == '.')
{
--- 732,746 ----
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 == '.')
{
***************
*** 748,753 ****
--- 756,764 ----
format2 = grub_strtoul (fstr, 0, 10); fmt = p;
}
+ else
+ format2 = 0;
+ format2_default = FALSE;
}
}
***************
*** 788,798 ****
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':
--- 799,815 ----
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':
***************
*** 867,879 ****
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)");
--- 884,917 ----
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)");
Quoted 8 lines · Deepak Vankadaru
Hi,
There was a redundant piece of code in the diff file I sent earlier. I have removed it and prepared another patch file. I am attaching the same. Please use this one instead.
Following is the changelog.
Quoted 7 lines
Changelog:
2008-08-17 Deepak Vankadaru <[email protected]>Support for precision formatting in
grub_printf*
kern/misc.c: modifiedgrub_vsprintfto parse and handle precision
formatting
Thanks. Please could you provide this in unified diff format? (diff -u)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 11 lines · Robert Millan
Quoted 8 lines
Changelog:
2008-08-17 Deepak Vankadaru <[email protected]>Support for precision formatting in
grub_printf*
kern/misc.c: modifiedgrub_vsprintfto parse and handle precision formattingThanks. Please could you provide this in unified diff format? (diff -u)
I already added (fixed) the precision parsing and added handling of '%s' precision (truncation):
http://svn.savannah.gnu.org/viewvc/trunk/grub2/kern/misc.c?root=grub&r1=1936&r2=1954
The parsing part of this new patch might conflict with this change.
Signature · 1 line
Christian Franke
Quoted 6 lines · Deepak Vankadaru
Hi,
There was a redundant piece of code in the diff file I sent earlier. I have removed it and prepared another patch file. I am attaching the same. Please use this one instead.
Following is the changelog.
Quoted 8 lines
Changelog:
2008-08-17 Deepak Vankadaru <[email protected] <mailto:[email protected]>>Support for precision formatting in
grub_printf*
kern/misc.c: modifiedgrub_vsprintfto parse and handle
precision formatting
Thanks.
Unfortunately, the patch can no longer be applied to current svn without a conflict. The precision parsing and '%s' precision (truncation) handling is already implemented.
But the '%d' precision (zero fill) handling part of your patch is still missing in the code.
Could you please repost an updated patch in diff -u format?
Note that the current code does not use a format2_default flag buts sets format2 to ~0U ('infinite' :-) if no precision is specified.
Thanks
Signature · 1 line
Christian Franke