Commit:    a0622d7c68f3b55068053aaa089f854ec59cb698
Author:    Anatol Belski <a...@php.net>         Thu, 5 Dec 2013 12:05:46 +0100
Parents:   42b122275475b2dee809aeb0205340c3df3d4b42
Branches:  str_size_and_int64

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=a0622d7c68f3b55068053aaa089f854ec59cb698

Log:
implemented %pd format for snprintf and spprintf

php_int_t var = 42;
php_printf("%pd", var);

Changed paths:
  M  main/snprintf.c
  M  main/snprintf.h
  M  main/spprintf.c


Diff:
diff --git a/main/snprintf.c b/main/snprintf.c
index 26f66ca..2deb9a5 100644
--- a/main/snprintf.c
+++ b/main/snprintf.c
@@ -759,6 +759,10 @@ static int format_converter(register buffy * odp, const 
char *fmt, va_list ap) /
                                        modifier = LM_SIZE_T;
 #endif
                                        break;
+                               case 'p':
+                                       fmt++;
+                                       modifier = LM_PHP_INT_T;
+                                       break;
                                case 'h':
                                        fmt++;
                                        if (*fmt == 'h') {
@@ -822,6 +826,9 @@ static int format_converter(register buffy * odp, const 
char *fmt, va_list ap) /
                                                        i_num = (wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       i_num = (wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        /*
                                         * The rest also applies to other 
integer formats, so fall
@@ -864,6 +871,9 @@ static int format_converter(register buffy * odp, const 
char *fmt, va_list ap) /
                                                                i_num = 
(wide_int) va_arg(ap, ptrdiff_t);
                                                                break;
 #endif
+                                                       case LM_PHP_INT_T:
+                                                               i_num = 
(wide_int) va_arg(ap, php_int_t);
+                                                               break;
                                                }
                                        }
                                        s = ap_php_conv_10(i_num, (*fmt) == 
'u', &is_negative,
@@ -910,6 +920,9 @@ static int format_converter(register buffy * odp, const 
char *fmt, va_list ap) /
                                                        ui_num = (u_wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       ui_num = (u_wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        s = ap_php_conv_p2(ui_num, 3, *fmt, 
&num_buf[NUM_BUF_SIZE], &s_len);
                                        FIX_PRECISION(adjust_precision, 
precision, s, s_len);
@@ -949,6 +962,9 @@ static int format_converter(register buffy * odp, const 
char *fmt, va_list ap) /
                                                        ui_num = (u_wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       ui_num = (u_wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        s = ap_php_conv_p2(ui_num, 4, *fmt, 
&num_buf[NUM_BUF_SIZE], &s_len);
                                        FIX_PRECISION(adjust_precision, 
precision, s, s_len);
diff --git a/main/snprintf.h b/main/snprintf.h
index 88dbdf8..d63ddaf 100644
--- a/main/snprintf.h
+++ b/main/snprintf.h
@@ -137,7 +137,8 @@ typedef enum {
 #endif
        LM_SIZE_T,
        LM_LONG,
-       LM_LONG_DOUBLE
+       LM_LONG_DOUBLE,
+       LM_PHP_INT_T
 } length_modifier_e;
 
 #ifdef PHP_WIN32
diff --git a/main/spprintf.c b/main/spprintf.c
index db77cc8..3273a31 100644
--- a/main/spprintf.c
+++ b/main/spprintf.c
@@ -367,6 +367,10 @@ static void xbuf_format_converter(smart_str *xbuf, const 
char *fmt, va_list ap)
                                        modifier = LM_SIZE_T;
 #endif
                                        break;
+                               case 'p':
+                                       fmt++;
+                                       modifier = LM_PHP_INT_T;
+                                       break;
                                case 'h':
                                        fmt++;
                                        if (*fmt == 'h') {
@@ -430,6 +434,9 @@ static void xbuf_format_converter(smart_str *xbuf, const 
char *fmt, va_list ap)
                                                        i_num = (wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       i_num = (wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        /*
                                         * The rest also applies to other 
integer formats, so fall
@@ -472,6 +479,9 @@ static void xbuf_format_converter(smart_str *xbuf, const 
char *fmt, va_list ap)
                                                                i_num = 
(wide_int) va_arg(ap, ptrdiff_t);
                                                                break;
 #endif
+                                                       case LM_PHP_INT_T:
+                                                               i_num = 
(wide_int) va_arg(ap, php_int_t);
+                                                               break;
                                                }
                                        }
                                        s = ap_php_conv_10(i_num, (*fmt) == 
'u', &is_negative,
@@ -517,6 +527,9 @@ static void xbuf_format_converter(smart_str *xbuf, const 
char *fmt, va_list ap)
                                                        ui_num = (u_wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       ui_num = (u_wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        s = ap_php_conv_p2(ui_num, 3, *fmt,
                                                                
&num_buf[NUM_BUF_SIZE], &s_len);
@@ -557,6 +570,9 @@ static void xbuf_format_converter(smart_str *xbuf, const 
char *fmt, va_list ap)
                                                        ui_num = (u_wide_int) 
va_arg(ap, ptrdiff_t);
                                                        break;
 #endif
+                                               case LM_PHP_INT_T:
+                                                       ui_num = (u_wide_int) 
va_arg(ap, php_uint_t);
+                                                       break;
                                        }
                                        s = ap_php_conv_p2(ui_num, 4, *fmt,
                                                                
&num_buf[NUM_BUF_SIZE], &s_len);


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to