File 0001-Add-content-of-the-SUSE-lftp-vi-1.1-archive.patch of Package lftp.37702
From c12b66f8f09070758419cd2ef1f23c47cf0587f3 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tomas.chvatal@gmail.com>
Date: Wed, 28 Feb 2018 19:06:37 +0100
Subject: [PATCH 1/5] Add content of the SUSE lftp-vi-1.1 archive
---
src/cmd-edit.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 src/cmd-edit.cc
diff --git a/src/cmd-edit.cc b/src/cmd-edit.cc
new file mode 100644
index 00000000..93230905
--- /dev/null
+++ b/src/cmd-edit.cc
@@ -0,0 +1,45 @@
+#include <config.h>
+#include "CmdExec.h"
+
+const char *extractFilename(const char *path) {
+ // Calculate memory address
+ char *pnt = (char*)path + (strlen(path) * sizeof(char));
+
+ // Go from back to beginning and check for (back)slashes
+ for (pnt--; pnt > path; pnt--)
+ if (*pnt == '/' || *pnt == '\\')
+ return ++pnt;
+
+ return pnt;
+}
+
+Job *cmd_edit(CmdExec *parent)
+{
+ if (parent->args->count() < 2) {
+ printf("Missing filename.\n");
+ return 0;
+ }
+ const char *filename = parent->args->getarg(1);
+ const char *baseFilename = extractFilename(filename);
+
+ // Allocate enough bytes for the new commandline, but without format strings
+ char *commandline = (char*)xmalloc(52 + strlen(filename));
+ sprintf(commandline, "shell \"/bin/sh -c 'exec ${EDITOR:-vi} /tmp/lftp.%s'\"\n", baseFilename);
+
+ char *getcommandline = (char*)xmalloc(22 + (2 * strlen(filename)));
+ sprintf(getcommandline, "get %s -o /tmp/lftp.%s\n", filename, baseFilename);
+
+ char *putcommandline = (char*)xmalloc(22 + (2 * strlen(filename)));
+ sprintf(putcommandline, "put /tmp/lftp.%s -o %s\n", baseFilename, filename);
+
+ parent->FeedCmd(getcommandline);
+ parent->FeedCmd(commandline);
+ parent->FeedCmd(putcommandline);
+
+ return 0;
+}
+
+CDECL void module_init(int argc, const char * const *argv)
+{
+ CmdExec::RegisterCommand("edit", cmd_edit, "edit <filename>", "Edit the file in your EDITOR\n");
+}
--
2.16.2