Hi guys,

I needed to customize the vpopmail table structure for my needs and
because of this I needed a different order of the arguments in the MySQL
queries. I tried to use the %2$s in a query and noticed I can't do that.
That's why I've made this little patch to make possible use this style
for arguments.

Stoyan

-- 
Stoyan Marinov <[EMAIL PROTECTED]>
--- vpopmail.c  2005-07-08 19:42:35.000000000 +0300
+++ ../vpopmail-5.4.11/vpopmail.c       2005-07-08 19:29:12.000000000 +0300
@@ -3206,6 +3206,9 @@
        const char *f; /* current position in format string */
        char *b;       /* current position in output buffer */
        char n[20];    /* buffer to hold string representation of number */
+
+       int argn = 0;  /* used for numbered arguments */
+       char argstr[10];

        char *s;       /* pointer to string to insert */

@@ -3255,9 +3258,40 @@
                                case 's':
                                        s = va_arg (ap, char *);
                                        break;
-
+
                                default:
-                                       strcpy (n, "*");
+                                       argn = 0;
+                                       while ((*f >= '0') && (*f <= '9')) {
+                                         argn = argn * 10 + atoi(f);
+                                         f++;
+                                       }
+                                       if ((argn > 0) && (*f == '$')) {
+                                         f++;
+                                         if (*f == 'l') {
+                                           f++;
+                                           switch (*f) {
+                                             case 'i':
+                                               snprintf(argstr, sizeof(argstr), "%%%d$ld", argn);
+                                               break;
+
+                                             case 'u':
+                                               snprintf(argstr, sizeof(argstr), "%%%d$lu", argn);
+                                               break;
+
+                                             default:
+                                               snprintf(argstr, sizeof(argstr), "%%%d$l%c", argn, *f);
+                                           }
+                                         } else {
+                                           snprintf(argstr, sizeof(argstr), "%%%d$%c", argn, *f);
+                                         }
+                                         vsprintf(s, argstr, ap);
+                                       } else if(argn > 0) {
+                                         while (argn > 10) {
+                                           argn = argn / 10;
+                                           f--;
+                                         }
+                                         strcpy (n, "*");
+                                       }
                        }
                        while (*s != '\0') {
                                if (strchr (ESCAPE_CHARS, *s) != NULL) {

Reply via email to