b1f7e58e1cef188ba1dc58881d23e201c318a6d2
galt
  Wed Mar 30 01:10:26 2011 -0700
allowing last parameter to be optional, i.e. derived from url if unspecified, as requested by a user
diff --git src/utils/paraFetch/paraFetch.c src/utils/paraFetch/paraFetch.c
index ec534b1..5a5808a 100644
--- src/utils/paraFetch/paraFetch.c
+++ src/utils/paraFetch/paraFetch.c
@@ -1,43 +1,63 @@
 /* paraFetch - fetch URL with multiple parallel connections. */
 #include "common.h"
 #include "options.h"
 #include "dystring.h"
 #include "obscure.h"
 #include "net.h"
 
 void usage()
 /* Explain usage and exit */
 {
 errAbort(
     "paraFetch - try to fetch url with multiple connections\n"
     "usage:\n"
-    "   paraFetch N R URL outPath\n"
+    "   paraFetch N R URL {outPath}\n"
     "   where N is the number of connections to use\n"
     "         R is the number of retries\n"
+    "   outPath is optional. If not specified, it will attempt to parse URL to discover output filename.\n"
     "options:\n"
     "   -newer  only download a file if it is newer than the version we already have.\n"
     );
 }
 
 static struct optionSpec options[] = {
    {"newer", OPTION_BOOLEAN},
    {NULL, 0},
 };
 
 boolean paraFetch(int numConnections, int numRetries, char *url, char *outPath, boolean newer)
 /* Fetch given URL, send to stdout. */
 {
 return parallelFetch(url, outPath, numConnections, numRetries, newer);
 }
 
+char *parseUrlForName(char *url)
+/* parse the name from the full url.  Free after using */
+{
+char *s = url;
+char *e = url+strlen(url);
+char *temp = strrchr(url, '/');
+if (temp)
+    s = temp+1;
+temp = strchr(s, '?');
+if (temp)
+    e = temp;
+return cloneStringZ(s, e-s);
+}
+
 int main(int argc, char *argv[])
 /* Process command line. */
 {
+char *outName = NULL;
 optionInit(&argc, argv, options);
-if (argc != 5)
+if (argc != 5 && argc != 4)
     usage();
-if (!paraFetch(atoi(argv[1]), atoi(argv[2]), argv[3], argv[4], optionExists("newer")))
+if (argc == 4)
+    outName = parseUrlForName(argv[3]);	
+else
+    outName = argv[4];
+if (!paraFetch(atoi(argv[1]), atoi(argv[2]), argv[3], outName, optionExists("newer")))
     exit(1);
 return 0;
 }