Index: lib/mprintf.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/mprintf.c,v
retrieving revision 1.60
diff -u -r1.60 mprintf.c
--- lib/mprintf.c	5 Nov 2007 09:45:09 -0000	1.60
+++ lib/mprintf.c	19 Nov 2007 10:43:08 -0000
@@ -686,8 +686,11 @@
       width = p->width;
 
     /* pick up the specified precision */
-    if(p->flags & FLAGS_PRECPARAM)
+    if(p->flags & FLAGS_PRECPARAM) {
       prec = vto[p->precision].data.num;
+      param_num++; /* since the precision is extraced from a parameter, we
+                      must skip that to get to the next one properly */
+    }
     else if(p->flags & FLAGS_PREC)
       prec = p->precision;
     else
Index: src/main.c
===================================================================
RCS file: /cvsroot/curl/curl/src/main.c,v
retrieving revision 1.430
diff -u -r1.430 main.c
--- src/main.c	15 Nov 2007 13:12:35 -0000	1.430
+++ src/main.c	19 Nov 2007 10:43:10 -0000
@@ -357,6 +357,7 @@
 };
 
 struct Configurable {
+  CURL *easy; /* once we have one, we keep it here */
   bool remote_time;
   char *random_file;
   char *egd_file;
@@ -1532,6 +1533,7 @@
     {"d", "data",        TRUE},
     {"da", "data-ascii", TRUE},
     {"db", "data-binary", TRUE},
+    {"de", "data-urlencode", TRUE},
     {"D", "dump-header", TRUE},
     {"e", "referer",     TRUE},
     {"E", "cert",        TRUE},
@@ -2045,12 +2047,83 @@
       /* postfield data */
       {
         char *postdata=NULL;
+        FILE *file;
+
+        if(subletter == 'e') { /* --data-urlencode*/
+          /* [name]=[content], we encode the content part only
+           * [name]@[file name]
+           *
+           * Case 2: we first load the file using that name and then encode
+           * the content.
+           */
+          char *p = strchr(nextarg, '=');
+          long size = 0;
+          size_t nlen;
+          if(!p)
+            p = strchr(nextarg, '@');
+          if(!p) {
+            warnf(config, "bad use of --data-urlencode\n");
+            return PARAM_BAD_USE;
+          }
+          nlen = p - nextarg; /* length of the name part */
+          if('@' == *p) {
+            /* a '@' letter, it means that a file name or - (stdin) follows */
+
+            p++; /* pass the separator */
 
-        if('@' == *nextarg) {
+            if(curlx_strequal("-", p)) {
+              file = stdin;
+              SET_BINMODE(stdin);
+            }
+            else {
+              file = fopen(p, "rb");
+              if(!file)
+                warnf(config,
+                      "Couldn't read data from file \"%s\", this makes "
+                      "an empty POST.\n", nextarg);
+            }
+
+            postdata = file2memory(file, &size);
+
+            if(file && (file != stdin))
+              fclose(file);
+          }
+          else {
+            GetStr(&postdata, ++p);
+            size = strlen(postdata);
+          }
+
+          if(!postdata) {
+            /* no data from the file, point to a zero byte string to make this
+               get sent as a POST anyway */
+            postdata=strdup("");
+          }
+          else {
+            char *enc = curl_easy_escape(config->easy, postdata, size);
+            if(enc) {
+              /* now make a string with the name from above and append the
+                 encoded string */
+              size_t outlen = nlen + strlen(enc) + 2;
+              char *n = malloc(outlen);
+              if(!n)
+                return PARAM_NO_MEM;
+
+              snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
+              curl_free(enc);
+              free(postdata);
+              if(n) {
+                postdata = n;
+              }
+              else
+                return PARAM_NO_MEM;
+            }
+            else
+              return PARAM_NO_MEM;
+          }
+        }
+        else if('@' == *nextarg) {
           /* the data begins with a '@' letter, it means that a file name
              or - (stdin) follows */
-          FILE *file;
-
           nextarg++; /* pass the @ */
 
           if(curlx_strequal("-", nextarg)) {
@@ -3334,6 +3407,9 @@
   curl_slist_free_all(config->postquote);
   curl_slist_free_all(config->headers);
   curl_slist_free_all(config->telnet_options);
+
+  if(config->easy)
+    curl_easy_cleanup(config->easy);
 }
 
 #ifdef WIN32
@@ -3443,9 +3519,9 @@
   if(config->libcurl) {
     /* we only use this for real if --libcurl was used */
 
-    bufp = curl_maprintf("%scurl_easy_setopt(hnd, %s, %s);%s",
-                         remark?"/* ":"", name, value,
-                         remark?" [REMARK] */":"");
+    bufp = curlx_maprintf("%scurl_easy_setopt(hnd, %s, %s);%s",
+                          remark?"/* ":"", name, value,
+                          remark?" [REMARK] */":"");
 
     if (!bufp || !curl_slist_append(easycode, bufp))
       ret = CURLE_OUT_OF_MEMORY;
@@ -3577,6 +3653,17 @@
   }
 #endif
 
+  /*
+   * Get a curl handle to use for all forthcoming curl transfers.  Cleanup
+   * when all transfers are done.
+   */
+  curl = curl_easy_init();
+  if(!curl) {
+    clean_getout(config);
+    return CURLE_FAILED_INIT;
+  }
+  config->easy = curl;
+
   memset(&outs,0,sizeof(outs));
 
   config->outs = &outs;
@@ -3733,16 +3820,6 @@
     }
   }
 
-  /*
-   * Get a curl handle to use for all forthcoming curl transfers.  Cleanup
-   * when all transfers are done.
-   */
-  curl = curl_easy_init();
-  if(!curl) {
-    clean_getout(config);
-    return CURLE_FAILED_INIT;
-  }
-
   /* This is the first entry added to easycode and it initializes the slist */
   easycode = curl_slist_append(easycode, "CURL *hnd = curl_easy_init();");
   if(!easycode) {
@@ -4663,6 +4740,7 @@
 
   /* cleanup the curl handle! */
   curl_easy_cleanup(curl);
+  config->easy = NULL; /* cleanup now */
   if (easycode)
     curl_slist_append(easycode, "curl_easy_cleanup(hnd);");
 
