Script cadaver

Henrik Holst henrik at witsbits.com
Tue Oct 21 17:02:19 EDT 2008


On Tue, Oct 21, 2008 at 8:19 PM, Leo <lbermude at gmail.com> wrote:
> Would it be possible to get cadaver to read any script file other than
> the .cadaverrc? As a general usability issue. (nice to have)
>
> Thanks
>
> Leonardo.
>
> _______________________________________________
> cadaver mailing list
> cadaver at lists.manyfish.co.uk
> http://lists.manyfish.co.uk/mailman/listinfo/cadaver
>

The attached patch should do the trick, I also noticed that the
-p/--proxy option was missing from the help screen so I added that one
too, perhaps I should send that as a separate patch instead?

--- cadaver-0.23.2/src/cadaver.c	2007-08-22 14:17:27.000000000 +0200
+++ cadaver-0.23.x/src/cadaver.c	2008-10-21 22:57:21.000000000 +0200
@@ -90,6 +90,8 @@
 int proxy_port;
 char *server_username = NULL, *server_password = NULL;

+char *rcfile;
+
 /* Current session state. */
 struct session session;

@@ -128,9 +130,11 @@
 "Usage: %s [OPTIONS] http://hostname[:port]/path\n"
 "  Port defaults to 80, path defaults to '/'\n"
 "Options:\n"
-"  -t, --tolerant   Allow cd/open into non-WebDAV enabled collection.\n"
-"  -V, --version    Display version information.\n"
-"  -h, --help       Display this help message.\n"
+"  -t, --tolerant            Allow cd/open into non-WebDAV enabled
collection.\n"
+"  -r, --rcfile=FILE         Read script from FILE instead of ~/.cadaverrc.\n"
+"  -p, --proxy=PROXY[:PORT]  Use proxy host PROXY and optional proxy
port PORT.\n"
+"  -V, --version             Display version information.\n"
+"  -h, --help                Display this help message.\n"
 "Please send bug reports and feature requests to
<cadaver at webdav.org>\n"), progname);
 }

@@ -435,15 +439,17 @@
 	{ "help", no_argument, NULL, 'h' },
 	{ "proxy", required_argument, NULL, 'p' },
 	{ "tolerant", no_argument, NULL, 't' },
+	{ "rcfile", required_argument, NULL, 'r' },
 	{ 0, 0, 0, 0 }
     };
     int optc;
-    while ((optc = getopt_long(argc, argv, "ehtp:V", opts, NULL)) != -1) {
+    while ((optc = getopt_long(argc, argv, "ehtp:r:V", opts, NULL)) != -1) {
 	switch (optc) {
 	case 'h': usage(); exit(-1);
 	case 'V': execute_about(); exit(-1);
 	case 'p': set_proxy(optarg); break;
 	case 't': tolerant = 1; break;
+	case 'r': rcfile = strdup(optarg); break;
 	case '?':
 	default:
 	    printf(_("Try `%s --help' for more information.\n"), progname);
@@ -588,27 +594,33 @@

 static void init_rcfile(void)
 {
-    char *rcfile, buf[BUFSIZ];
+    char buf[BUFSIZ];
     struct stat st;
     FILE *f;
-    rcfile = ne_concat(getenv("HOME"), "/.cadaverrc", NULL);
-    if (stat(rcfile, &st) != 0) {
-	NE_DEBUG(DEBUG_FILES, "No rcfile.\n");
+
+    if (rcfile == NULL) {
+	rcfile = ne_concat(getenv("HOME"), "/.cadaverrc", NULL);
+
+	if (stat(rcfile, &st) != 0) {
+	    NE_DEBUG(DEBUG_FILES, "No rcfile\n");
+	    free(rcfile);
+	    return;
+	}
+    }
+
+    f = fopen(rcfile, "r");
+    if (f == NULL) {
+        printf(_("Could not read rcfile %s: %s\n"), rcfile,
+	   strerror(errno));
     } else {
-	f = fopen(rcfile, "r");
-	if (f == NULL) {
-	    printf(_("Could not read rcfile %s: %s\n"), rcfile,
-		   strerror(errno));
-	} else {
-	    for (;;) {
-		if (fgets(buf, BUFSIZ, f) != NULL) {
-		    execute_command(ne_shave(buf, "\r\n"));
-		} else {
-		    break;
-		}
+	for (;;) {
+	    if (fgets(buf, BUFSIZ, f) != NULL) {
+		execute_command(ne_shave(buf, "\r\n"));
+	    } else {
+		break;
 	    }
-	    fclose(f);
 	}
+	fclose(f);
     }
     free(rcfile);
 }
@@ -867,9 +879,9 @@

     init_signals();
     init_locking();
-    init_rcfile();

     parse_args(argc, argv);
+    init_rcfile();

     init_readline();


/Henrik Holst
Witsbits AB - The Digital Utility
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cadaver.c.diff
Type: text/x-diff
Size: 3047 bytes
Desc: not available
Url : http://lists.manyfish.co.uk/pipermail/cadaver/attachments/20081021/3759047a/attachment-0007.bin 


More information about the cadaver mailing list