cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] curl tool: add filename_effective token for --write-out

From: Dave Reisner <d_at_falconindy.com>
Date: Mon, 5 Mar 2012 08:23:29 -0500

By modifying the parameter list for ourWriteOut() and passing the
OutStruct that collects data in tool_operate, we get access to the
remote name that we're writing to. Shell scripters should find this
useful when used in conjuntion with the --remote-header-name option.

---
 docs/curl.1         |    5 +++++
 src/tool_operate.c  |    2 +-
 src/tool_writeout.c |    8 +++++++-
 src/tool_writeout.h |    2 +-
 4 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/docs/curl.1 b/docs/curl.1
index 995f5de..c8843e5 100644
--- a/docs/curl.1
+++ b/docs/curl.1
@@ -1485,6 +1485,11 @@ The variables available at this point are:
 The URL that was fetched last. This is most meaningful if you've told curl
 to follow location: headers.
 .TP
+.B filename_effective
+The ultimate filename that curl writes out to. This is only meaningful if curl
+is told to write to a file with the --remote-name or --output option. It's most
+useful in combination with the --remote-header-name option. (Added in 7.25.0)
+.TP
 .B http_code
 The numerical response code that was found in the last retrieved HTTP(S) or
 FTP(s) transfer. In 7.18.2 the alias \fBresponse_code\fP was added to show the
diff --git a/src/tool_operate.c b/src/tool_operate.c
index d070ea6..04d1589 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1391,7 +1391,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
           fputs("\n", progressbar.out);
 
         if(config->writeout)
-          ourWriteOut(curl, config->writeout);
+          ourWriteOut(curl, &outs, config->writeout);
 
         if(config->writeenv)
           ourWriteEnv(curl);
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
index 1ea1c98..c87abb5 100644
--- a/src/tool_writeout.c
+++ b/src/tool_writeout.c
@@ -26,6 +26,7 @@
 #define _MPRINTF_REPLACE /* we want curl-functions instead of native ones */
 #include <curl/mprintf.h>
 
+#include "tool_cfgable.h"
 #include "tool_writeout.h"
 
 #include "memdebug.h" /* keep this as LAST include */
@@ -54,6 +55,7 @@ typedef enum {
   VAR_FTP_ENTRY_PATH,
   VAR_REDIRECT_URL,
   VAR_SSL_VERIFY_RESULT,
+  VAR_EFFECTIVE_FILENAME,
   VAR_NUM_OF_VARS /* must be the last */
 } replaceid;
 
@@ -87,10 +89,11 @@ static const struct variable replacements[]={
   {"ftp_entry_path", VAR_FTP_ENTRY_PATH},
   {"redirect_url", VAR_REDIRECT_URL},
   {"ssl_verify_result", VAR_SSL_VERIFY_RESULT},
+  {"filename_effective", VAR_EFFECTIVE_FILENAME},
   {NULL, VAR_NONE}
 };
 
-void ourWriteOut(CURL *curl, const char *writeinfo)
+void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo)
 {
   FILE *stream = stdout;
   const char *ptr = writeinfo;
@@ -242,6 +245,9 @@ void ourWriteOut(CURL *curl, const char *writeinfo)
                                      &longinfo))
                   fprintf(stream, "%ld", longinfo);
                 break;
+              case VAR_EFFECTIVE_FILENAME:
+                if(outs->filename)
+                  fprintf(stream, "%s", outs->filename);
               default:
                 break;
               }
diff --git a/src/tool_writeout.h b/src/tool_writeout.h
index 815cfcf..2344749 100644
--- a/src/tool_writeout.h
+++ b/src/tool_writeout.h
@@ -23,6 +23,6 @@
  ***************************************************************************/
 #include "setup.h"
 
-void ourWriteOut(CURL *curl, const char *out);
+void ourWriteOut(CURL *curl, struct OutStruct *outs, const char *writeinfo);
 
 #endif /* HEADER_CURL_TOOL_WRITEOUT_H */
-- 
1.7.9.2
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-03-05