From: Steven Schubiger Date: Mon, 13 Apr 2009 20:19:13 +0000 (+0200) Subject: Move duplicated code to a function. X-Git-Tag: v1.13~361^2 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=116b261a9f1ccd945c16e9ad3afc2e85f1fb95b1 Move duplicated code to a function. --- diff --git a/src/ChangeLog b/src/ChangeLog index ca245088..37d39d80 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2009-04-13 Steven Schubiger + + * ftp.c (ftp_retrieve_list): Move the duplicated code that + determines the local file to a function. + + * http.c (http_loop): Likewise. + + * retr.c (set_local_file): New function. + 2009-04-11 Steven Schubiger * init.c (initialize): Run a custom SYSTEM_WGETRC when diff --git a/src/ftp.c b/src/ftp.c index 7c509377..fe6ecd0a 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -1590,16 +1590,8 @@ Already have correct symlink %s -> %s\n\n"), && dlthis && file_exists_p (con->target)) { - /* #### This code repeats in http.c and ftp.c. Move it to a - function! */ const char *fl = NULL; - if (opt.output_document) - { - if (output_stream_regular) - fl = opt.output_document; - } - else - fl = con->target; + set_local_file (&fl, con->target); if (fl) touch (fl, f->tstamp); } diff --git a/src/http.c b/src/http.c index e0e1e013..c3adbf40 100644 --- a/src/http.c +++ b/src/http.c @@ -2723,16 +2723,8 @@ Remote file exists.\n\n")); && ((hstat.len == hstat.contlen) || ((hstat.res == 0) && (hstat.contlen == -1)))) { - /* #### This code repeats in http.c and ftp.c. Move it to a - function! */ const char *fl = NULL; - if (opt.output_document) - { - if (output_stream_regular) - fl = opt.output_document; - } - else - fl = hstat.local_file; + set_local_file (&fl, hstat.local_file); if (fl) { time_t newtmr = -1; diff --git a/src/retr.c b/src/retr.c index 21c9002e..f081d831 100644 --- a/src/retr.c +++ b/src/retr.c @@ -1070,3 +1070,16 @@ no_proxy_match (const char *host, const char **no_proxy) else return sufmatch (no_proxy, host); } + +/* Set the file parameter to point to the local file string. */ +void +set_local_file (const char **file, const char *default_file) +{ + if (opt.output_document) + { + if (output_stream_regular) + *file = opt.output_document; + } + else + *file = default_file; +}